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.

252132 lines
6.3MB

  1. #ifdef __JUCE_JUCEHEADER__
  2. #error
  3. #endif
  4. /********* Start of inlined file: juce_TargetPlatform.h *********/
  5. #ifndef __JUCE_TARGETPLATFORM_JUCEHEADER__
  6. #define __JUCE_TARGETPLATFORM_JUCEHEADER__
  7. #if (defined (_WIN32) || defined (_WIN64))
  8. #define JUCE_WIN32 1
  9. #define JUCE_WINDOWS 1
  10. #elif defined (LINUX) || defined (__linux__)
  11. #define JUCE_LINUX 1
  12. #elif defined(__APPLE_CPP__) || defined(__APPLE_CC__)
  13. #include <CoreFoundation/CoreFoundation.h> // (needed to find out what platform we're using)
  14. #if TARGET_OS_IPHONE || TARGET_IPHONE_SIMULATOR
  15. #define JUCE_IPHONE 1
  16. #else
  17. #define JUCE_MAC 1
  18. #endif
  19. #else
  20. #error "Unknown platform!"
  21. #endif
  22. #if JUCE_WINDOWS
  23. #ifdef _MSC_VER
  24. #ifdef _WIN64
  25. #define JUCE_64BIT 1
  26. #else
  27. #define JUCE_32BIT 1
  28. #endif
  29. #endif
  30. #ifdef _DEBUG
  31. #define JUCE_DEBUG 1
  32. #endif
  33. #ifdef __MINGW32__
  34. #define JUCE_MINGW 1
  35. #endif
  36. #define JUCE_LITTLE_ENDIAN 1
  37. #define JUCE_INTEL 1
  38. #endif
  39. #if JUCE_MAC
  40. #ifndef NDEBUG
  41. #define JUCE_DEBUG 1
  42. #endif
  43. #ifdef __LITTLE_ENDIAN__
  44. #define JUCE_LITTLE_ENDIAN 1
  45. #else
  46. #define JUCE_BIG_ENDIAN 1
  47. #endif
  48. #if defined (__ppc__) || defined (__ppc64__)
  49. #define JUCE_PPC 1
  50. #else
  51. #define JUCE_INTEL 1
  52. #endif
  53. #ifdef __LP64__
  54. #define JUCE_64BIT 1
  55. #else
  56. #define JUCE_32BIT 1
  57. #endif
  58. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_4
  59. #error "Building for OSX 10.3 is no longer supported!"
  60. #endif
  61. #ifndef MAC_OS_X_VERSION_10_5
  62. #error "To build with 10.4 compatibility, use a 10.5 or 10.6 SDK and set the deployment target to 10.4"
  63. #endif
  64. #endif
  65. #if JUCE_IPHONE
  66. #ifndef NDEBUG
  67. #define JUCE_DEBUG 1
  68. #endif
  69. #ifdef __LITTLE_ENDIAN__
  70. #define JUCE_LITTLE_ENDIAN 1
  71. #else
  72. #define JUCE_BIG_ENDIAN 1
  73. #endif
  74. #endif
  75. #if JUCE_LINUX
  76. #ifdef _DEBUG
  77. #define JUCE_DEBUG 1
  78. #endif
  79. // Allow override for big-endian Linux platforms
  80. #ifndef JUCE_BIG_ENDIAN
  81. #define JUCE_LITTLE_ENDIAN 1
  82. #endif
  83. #if defined (__LP64__) || defined (_LP64)
  84. #define JUCE_64BIT 1
  85. #else
  86. #define JUCE_32BIT 1
  87. #endif
  88. #define JUCE_INTEL 1
  89. #endif
  90. // Compiler type macros.
  91. #ifdef __GNUC__
  92. #define JUCE_GCC 1
  93. #elif defined (_MSC_VER)
  94. #define JUCE_MSVC 1
  95. #if _MSC_VER >= 1400
  96. #define JUCE_USE_INTRINSICS 1
  97. #endif
  98. #else
  99. #error unknown compiler
  100. #endif
  101. #endif // __JUCE_TARGETPLATFORM_JUCEHEADER__
  102. /********* End of inlined file: juce_TargetPlatform.h *********/
  103. // FORCE_AMALGAMATOR_INCLUDE
  104. /********* Start of inlined file: juce_Config.h *********/
  105. #ifndef __JUCE_CONFIG_JUCEHEADER__
  106. #define __JUCE_CONFIG_JUCEHEADER__
  107. #ifndef JUCE_NAMESPACE
  108. #define JUCE_NAMESPACE juce
  109. #endif
  110. #ifndef JUCE_FORCE_DEBUG
  111. //#define JUCE_FORCE_DEBUG 1
  112. #endif
  113. #ifndef JUCE_LOG_ASSERTIONS
  114. // #define JUCE_LOG_ASSERTIONS 1
  115. #endif
  116. #ifndef JUCE_ASIO
  117. #define JUCE_ASIO 1
  118. #endif
  119. #ifndef JUCE_WASAPI
  120. // #define JUCE_WASAPI 1
  121. #endif
  122. #ifndef JUCE_DIRECTSOUND
  123. #define JUCE_DIRECTSOUND 1
  124. #endif
  125. #ifndef JUCE_ALSA
  126. #define JUCE_ALSA 1
  127. #endif
  128. #ifndef JUCE_JACK
  129. #define JUCE_JACK 1
  130. #endif
  131. #if ! (defined (JUCE_QUICKTIME) || JUCE_LINUX || JUCE_IPHONE || (JUCE_WINDOWS && ! JUCE_MSVC))
  132. #define JUCE_QUICKTIME 1
  133. #endif
  134. #ifndef JUCE_OPENGL
  135. #define JUCE_OPENGL 1
  136. #endif
  137. #ifndef JUCE_USE_FLAC
  138. #define JUCE_USE_FLAC 1
  139. #endif
  140. #ifndef JUCE_USE_OGGVORBIS
  141. #define JUCE_USE_OGGVORBIS 1
  142. #endif
  143. #if (! defined (JUCE_USE_CDBURNER)) && ! (JUCE_WINDOWS && ! JUCE_MSVC)
  144. #define JUCE_USE_CDBURNER 1
  145. #endif
  146. #ifndef JUCE_USE_CDREADER
  147. #define JUCE_USE_CDREADER 1
  148. #endif
  149. #if JUCE_QUICKTIME && ! defined (JUCE_USE_CAMERA)
  150. // #define JUCE_USE_CAMERA 1
  151. #endif
  152. #ifndef JUCE_ENABLE_REPAINT_DEBUGGING
  153. // #define JUCE_ENABLE_REPAINT_DEBUGGING 1
  154. #endif
  155. #ifndef JUCE_USE_XINERAMA
  156. #define JUCE_USE_XINERAMA 1
  157. #endif
  158. #ifndef JUCE_USE_XSHM
  159. #define JUCE_USE_XSHM 1
  160. #endif
  161. #ifndef JUCE_PLUGINHOST_VST
  162. // #define JUCE_PLUGINHOST_VST 1
  163. #endif
  164. #ifndef JUCE_PLUGINHOST_AU
  165. // #define JUCE_PLUGINHOST_AU 1
  166. #endif
  167. #ifndef JUCE_ONLY_BUILD_CORE_LIBRARY
  168. //#define JUCE_ONLY_BUILD_CORE_LIBRARY 1
  169. #endif
  170. #ifndef JUCE_WEB_BROWSER
  171. #define JUCE_WEB_BROWSER 1
  172. #endif
  173. #ifndef JUCE_SUPPORT_CARBON
  174. #define JUCE_SUPPORT_CARBON 1
  175. #endif
  176. #ifndef JUCE_INCLUDE_ZLIB_CODE
  177. #define JUCE_INCLUDE_ZLIB_CODE 1
  178. #endif
  179. #ifndef JUCE_INCLUDE_FLAC_CODE
  180. #define JUCE_INCLUDE_FLAC_CODE 1
  181. #endif
  182. #ifndef JUCE_INCLUDE_OGGVORBIS_CODE
  183. #define JUCE_INCLUDE_OGGVORBIS_CODE 1
  184. #endif
  185. #ifndef JUCE_INCLUDE_PNGLIB_CODE
  186. #define JUCE_INCLUDE_PNGLIB_CODE 1
  187. #endif
  188. #ifndef JUCE_INCLUDE_JPEGLIB_CODE
  189. #define JUCE_INCLUDE_JPEGLIB_CODE 1
  190. #endif
  191. #ifndef JUCE_CHECK_MEMORY_LEAKS
  192. #define JUCE_CHECK_MEMORY_LEAKS 1
  193. #endif
  194. #ifndef JUCE_CATCH_UNHANDLED_EXCEPTIONS
  195. #define JUCE_CATCH_UNHANDLED_EXCEPTIONS 1
  196. #endif
  197. #ifndef JUCE_STRINGS_ARE_UNICODE
  198. #define JUCE_STRINGS_ARE_UNICODE 1
  199. #endif
  200. // If only building the core classes, we can explicitly turn off some features to avoid including them:
  201. #if JUCE_ONLY_BUILD_CORE_LIBRARY
  202. #undef JUCE_QUICKTIME
  203. #define JUCE_QUICKTIME 0
  204. #undef JUCE_OPENGL
  205. #define JUCE_OPENGL 0
  206. #undef JUCE_USE_CDBURNER
  207. #define JUCE_USE_CDBURNER 0
  208. #undef JUCE_USE_CDREADER
  209. #define JUCE_USE_CDREADER 0
  210. #undef JUCE_WEB_BROWSER
  211. #define JUCE_WEB_BROWSER 0
  212. #undef JUCE_PLUGINHOST_AU
  213. #define JUCE_PLUGINHOST_AU 0
  214. #undef JUCE_PLUGINHOST_VST
  215. #define JUCE_PLUGINHOST_VST 0
  216. #endif
  217. #endif
  218. /********* End of inlined file: juce_Config.h *********/
  219. // FORCE_AMALGAMATOR_INCLUDE
  220. //==============================================================================
  221. #if JUCE_WINDOWS
  222. /********* Start of inlined file: juce_win32_NativeIncludes.h *********/
  223. #ifndef __JUCE_WIN32_NATIVEINCLUDES_JUCEHEADER__
  224. #define __JUCE_WIN32_NATIVEINCLUDES_JUCEHEADER__
  225. #ifndef STRICT
  226. #define STRICT 1
  227. #endif
  228. #undef WIN32_LEAN_AND_MEAN
  229. #define WIN32_LEAN_AND_MEAN 1
  230. #ifdef _MSC_VER
  231. #pragma warning (push)
  232. #pragma warning (disable : 4100 4201 4514 4312 4995)
  233. #endif
  234. #define _WIN32_WINNT 0x0500
  235. #define _UNICODE 1
  236. #define UNICODE 1
  237. #ifndef _WIN32_IE
  238. #define _WIN32_IE 0x0400
  239. #endif
  240. #include <windows.h>
  241. #include <windowsx.h>
  242. #include <commdlg.h>
  243. #include <shellapi.h>
  244. #include <mmsystem.h>
  245. #include <vfw.h>
  246. #include <tchar.h>
  247. #include <stddef.h>
  248. #include <ctime>
  249. #include <wininet.h>
  250. #include <nb30.h>
  251. #include <iphlpapi.h>
  252. #include <mapi.h>
  253. #include <float.h>
  254. #include <process.h>
  255. #include <Exdisp.h>
  256. #include <exdispid.h>
  257. #include <shlobj.h>
  258. #if ! JUCE_MINGW
  259. #include <crtdbg.h>
  260. #include <comutil.h>
  261. #endif
  262. #if JUCE_OPENGL
  263. #include <gl/gl.h>
  264. #endif
  265. #undef PACKED
  266. #if JUCE_ASIO
  267. #include "iasiodrv.h"
  268. #endif
  269. #if JUCE_USE_CDBURNER
  270. #include <imapi.h>
  271. #include <imapierror.h>
  272. #endif
  273. #if JUCE_USE_CAMERA
  274. #include <dshow.h>
  275. #include <qedit.h>
  276. #endif
  277. #if JUCE_WASAPI
  278. #include <MMReg.h>
  279. #include <mmdeviceapi.h>
  280. #include <Audioclient.h>
  281. #include <Avrt.h>
  282. #include <functiondiscoverykeys.h>
  283. #endif
  284. #if JUCE_QUICKTIME
  285. #include <Movies.h>
  286. #include <QTML.h>
  287. #include <QuickTimeComponents.h>
  288. #include <MediaHandlers.h>
  289. #include <ImageCodec.h>
  290. #import <QTOLibrary.dll>
  291. #import <QTOControl.dll>
  292. #endif
  293. #ifdef _MSC_VER
  294. #pragma warning (pop)
  295. #endif
  296. template <class T>
  297. class ComSmartPtr
  298. {
  299. public:
  300. ComSmartPtr() throw() : p (0) {}
  301. ComSmartPtr (T* const p_) : p (p_) { if (p_ != 0) p_->AddRef(); }
  302. ComSmartPtr (const ComSmartPtr<T>& p_) : p (p_.p) { if (p != 0) p->AddRef(); }
  303. ~ComSmartPtr() { if (p != 0) p->Release(); }
  304. operator T*() const throw() { return p; }
  305. T& operator*() const throw() { return *p; }
  306. T** operator&() throw() { return &p; }
  307. T* operator->() const throw() { return p; }
  308. T* operator= (T* const newP)
  309. {
  310. if (newP != 0)
  311. newP->AddRef();
  312. if (p != 0)
  313. p->Release();
  314. p = newP;
  315. return newP;
  316. }
  317. T* operator= (const ComSmartPtr<T>& newP) { return operator= (newP.p); }
  318. HRESULT CoCreateInstance (REFCLSID rclsid, DWORD dwClsContext)
  319. {
  320. #ifndef __MINGW32__
  321. operator= (0);
  322. return ::CoCreateInstance (rclsid, 0, dwClsContext, __uuidof(T), (void**) &p);
  323. #else
  324. return S_FALSE;
  325. #endif
  326. }
  327. T* p;
  328. };
  329. #endif // __JUCE_WIN32_NATIVEINCLUDES_JUCEHEADER__
  330. /********* End of inlined file: juce_win32_NativeIncludes.h *********/
  331. #elif JUCE_LINUX
  332. /********* Start of inlined file: juce_linux_NativeIncludes.h *********/
  333. #ifndef __JUCE_LINUX_NATIVEINCLUDES_JUCEHEADER__
  334. #define __JUCE_LINUX_NATIVEINCLUDES_JUCEHEADER__
  335. #include <sched.h>
  336. #include <pthread.h>
  337. #include <sys/time.h>
  338. #include <errno.h>
  339. #include <sys/stat.h>
  340. #include <sys/dir.h>
  341. #include <sys/ptrace.h>
  342. #include <sys/vfs.h>
  343. #include <sys/wait.h>
  344. #include <fnmatch.h>
  345. #include <utime.h>
  346. #include <pwd.h>
  347. #include <fcntl.h>
  348. #include <dlfcn.h>
  349. #include <netdb.h>
  350. #include <arpa/inet.h>
  351. #include <netinet/in.h>
  352. #include <sys/types.h>
  353. #include <sys/ioctl.h>
  354. #include <sys/socket.h>
  355. #include <linux/if.h>
  356. #include <sys/sysinfo.h>
  357. #include <sys/file.h>
  358. #include <signal.h>
  359. #include <ft2build.h>
  360. #include FT_FREETYPE_H
  361. #include <X11/Xlib.h>
  362. #include <X11/Xatom.h>
  363. #include <X11/Xresource.h>
  364. #include <X11/Xutil.h>
  365. #include <X11/Xmd.h>
  366. #include <X11/keysym.h>
  367. #include <X11/cursorfont.h>
  368. #if JUCE_USE_XINERAMA
  369. #include <X11/extensions/Xinerama.h>
  370. #endif
  371. #if JUCE_USE_XSHM
  372. #include <X11/extensions/XShm.h>
  373. #include <sys/shm.h>
  374. #include <sys/ipc.h>
  375. #endif
  376. #if JUCE_OPENGL
  377. #include <GL/glx.h>
  378. #endif
  379. #undef KeyPress
  380. #if JUCE_ALSA
  381. #include <alsa/asoundlib.h>
  382. #endif
  383. #if JUCE_JACK
  384. #include <jack/jack.h>
  385. //#include <jack/transport.h>
  386. #endif
  387. #undef SIZEOF
  388. #endif // __JUCE_LINUX_NATIVEINCLUDES_JUCEHEADER__
  389. /********* End of inlined file: juce_linux_NativeIncludes.h *********/
  390. #elif JUCE_MAC || JUCE_IPHONE
  391. /********* Start of inlined file: juce_mac_NativeIncludes.h *********/
  392. #ifndef __JUCE_MAC_NATIVEINCLUDES_JUCEHEADER__
  393. #define __JUCE_MAC_NATIVEINCLUDES_JUCEHEADER__
  394. #define USE_COREGRAPHICS_RENDERING 1
  395. #if JUCE_IPHONE
  396. #import <Foundation/Foundation.h>
  397. #import <UIKit/UIKit.h>
  398. #import <AudioToolbox/AudioToolbox.h>
  399. #import <AVFoundation/AVFoundation.h>
  400. #import <CoreData/CoreData.h>
  401. #import <MobileCoreServices/MobileCoreServices.h>
  402. #include <sys/fcntl.h>
  403. #else
  404. #import <Cocoa/Cocoa.h>
  405. #import <CoreAudio/HostTime.h>
  406. #import <CoreAudio/AudioHardware.h>
  407. #import <CoreMIDI/MIDIServices.h>
  408. #import <QTKit/QTKit.h>
  409. #import <WebKit/WebKit.h>
  410. #import <DiscRecording/DiscRecording.h>
  411. #import <IOKit/IOKitLib.h>
  412. #import <IOKit/IOCFPlugIn.h>
  413. #import <IOKit/hid/IOHIDLib.h>
  414. #import <IOKit/hid/IOHIDKeys.h>
  415. #import <IOKit/pwr_mgt/IOPMLib.h>
  416. #include <Carbon/Carbon.h>
  417. #include <sys/dir.h>
  418. #include <sys/socket.h>
  419. #endif
  420. #include <sys/sysctl.h>
  421. #include <sys/stat.h>
  422. #include <sys/param.h>
  423. #include <sys/mount.h>
  424. #include <fnmatch.h>
  425. #include <utime.h>
  426. #include <dlfcn.h>
  427. #include <ifaddrs.h>
  428. #include <net/if_dl.h>
  429. #include <mach/mach_time.h>
  430. #if MACOS_10_4_OR_EARLIER
  431. #include <GLUT/glut.h>
  432. #endif
  433. #if ! CGFLOAT_DEFINED
  434. #define CGFloat float
  435. #endif
  436. #endif // __JUCE_MAC_NATIVEINCLUDES_JUCEHEADER__
  437. /********* End of inlined file: juce_mac_NativeIncludes.h *********/
  438. #else
  439. #error "Unknown platform!"
  440. #endif
  441. //==============================================================================
  442. #define DONT_SET_USING_JUCE_NAMESPACE 1
  443. #include "juce_amalgamated.h"
  444. #define NO_DUMMY_DECL
  445. #if (defined(_MSC_VER) && (_MSC_VER <= 1200))
  446. #pragma warning (disable: 4309 4305)
  447. #endif
  448. #if JUCE_MAC && JUCE_32BIT && JUCE_SUPPORT_CARBON && ! JUCE_ONLY_BUILD_CORE_LIBRARY
  449. BEGIN_JUCE_NAMESPACE
  450. /********* Start of inlined file: juce_mac_CarbonViewWrapperComponent.h *********/
  451. #ifndef __JUCE_MAC_CARBONVIEWWRAPPERCOMPONENT_JUCEHEADER__
  452. #define __JUCE_MAC_CARBONVIEWWRAPPERCOMPONENT_JUCEHEADER__
  453. class CarbonViewWrapperComponent : public Component,
  454. public ComponentMovementWatcher,
  455. public Timer
  456. {
  457. public:
  458. CarbonViewWrapperComponent()
  459. : ComponentMovementWatcher (this),
  460. wrapperWindow (0),
  461. embeddedView (0),
  462. recursiveResize (false)
  463. {
  464. }
  465. virtual ~CarbonViewWrapperComponent()
  466. {
  467. jassert (embeddedView == 0); // must call deleteWindow() in the subclass's destructor!
  468. }
  469. virtual HIViewRef attachView (WindowRef windowRef, HIViewRef rootView) = 0;
  470. virtual void removeView (HIViewRef embeddedView) = 0;
  471. virtual void mouseDown (int x, int y) {}
  472. virtual void paint() {}
  473. virtual bool getEmbeddedViewSize (int& w, int& h)
  474. {
  475. if (embeddedView == 0)
  476. return false;
  477. HIRect bounds;
  478. HIViewGetBounds (embeddedView, &bounds);
  479. w = jmax (1, roundToInt (bounds.size.width));
  480. h = jmax (1, roundToInt (bounds.size.height));
  481. return true;
  482. }
  483. void createWindow()
  484. {
  485. if (wrapperWindow == 0)
  486. {
  487. Rect r;
  488. r.left = getScreenX();
  489. r.top = getScreenY();
  490. r.right = r.left + getWidth();
  491. r.bottom = r.top + getHeight();
  492. CreateNewWindow (kDocumentWindowClass,
  493. (WindowAttributes) (kWindowStandardHandlerAttribute | kWindowCompositingAttribute
  494. | kWindowNoShadowAttribute | kWindowNoTitleBarAttribute),
  495. &r, &wrapperWindow);
  496. jassert (wrapperWindow != 0);
  497. if (wrapperWindow == 0)
  498. return;
  499. NSWindow* carbonWindow = [[NSWindow alloc] initWithWindowRef: wrapperWindow];
  500. NSWindow* ownerWindow = [((NSView*) getWindowHandle()) window];
  501. [ownerWindow addChildWindow: carbonWindow
  502. ordered: NSWindowAbove];
  503. embeddedView = attachView (wrapperWindow, HIViewGetRoot (wrapperWindow));
  504. EventTypeSpec windowEventTypes[] = { { kEventClassWindow, kEventWindowGetClickActivation },
  505. { kEventClassWindow, kEventWindowHandleDeactivate } };
  506. EventHandlerUPP upp = NewEventHandlerUPP (carbonEventCallback);
  507. InstallWindowEventHandler (wrapperWindow, upp,
  508. sizeof (windowEventTypes) / sizeof (EventTypeSpec),
  509. windowEventTypes, this, &eventHandlerRef);
  510. setOurSizeToEmbeddedViewSize();
  511. setEmbeddedWindowToOurSize();
  512. creationTime = Time::getCurrentTime();
  513. }
  514. }
  515. void deleteWindow()
  516. {
  517. removeView (embeddedView);
  518. embeddedView = 0;
  519. if (wrapperWindow != 0)
  520. {
  521. RemoveEventHandler (eventHandlerRef);
  522. DisposeWindow (wrapperWindow);
  523. wrapperWindow = 0;
  524. }
  525. }
  526. void setOurSizeToEmbeddedViewSize()
  527. {
  528. int w, h;
  529. if (getEmbeddedViewSize (w, h))
  530. {
  531. if (w != getWidth() || h != getHeight())
  532. {
  533. startTimer (50);
  534. setSize (w, h);
  535. if (getParentComponent() != 0)
  536. getParentComponent()->setSize (w, h);
  537. }
  538. else
  539. {
  540. startTimer (jlimit (50, 500, getTimerInterval() + 20));
  541. }
  542. }
  543. else
  544. {
  545. stopTimer();
  546. }
  547. }
  548. void setEmbeddedWindowToOurSize()
  549. {
  550. if (! recursiveResize)
  551. {
  552. recursiveResize = true;
  553. if (embeddedView != 0)
  554. {
  555. HIRect r;
  556. r.origin.x = 0;
  557. r.origin.y = 0;
  558. r.size.width = (float) getWidth();
  559. r.size.height = (float) getHeight();
  560. HIViewSetFrame (embeddedView, &r);
  561. }
  562. if (wrapperWindow != 0)
  563. {
  564. Rect wr;
  565. wr.left = getScreenX();
  566. wr.top = getScreenY();
  567. wr.right = wr.left + getWidth();
  568. wr.bottom = wr.top + getHeight();
  569. SetWindowBounds (wrapperWindow, kWindowContentRgn, &wr);
  570. ShowWindow (wrapperWindow);
  571. }
  572. recursiveResize = false;
  573. }
  574. }
  575. void componentMovedOrResized (bool /*wasMoved*/, bool /*wasResized*/)
  576. {
  577. setEmbeddedWindowToOurSize();
  578. }
  579. void componentPeerChanged()
  580. {
  581. deleteWindow();
  582. createWindow();
  583. }
  584. void componentVisibilityChanged (Component&)
  585. {
  586. if (isShowing())
  587. createWindow();
  588. else
  589. deleteWindow();
  590. setEmbeddedWindowToOurSize();
  591. }
  592. static void recursiveHIViewRepaint (HIViewRef view)
  593. {
  594. HIViewSetNeedsDisplay (view, true);
  595. HIViewRef child = HIViewGetFirstSubview (view);
  596. while (child != 0)
  597. {
  598. recursiveHIViewRepaint (child);
  599. child = HIViewGetNextView (child);
  600. }
  601. }
  602. void timerCallback()
  603. {
  604. setOurSizeToEmbeddedViewSize();
  605. // To avoid strange overpainting problems when the UI is first opened, we'll
  606. // repaint it a few times during the first second that it's on-screen..
  607. if ((Time::getCurrentTime() - creationTime).inMilliseconds() < 1000)
  608. recursiveHIViewRepaint (HIViewGetRoot (wrapperWindow));
  609. }
  610. OSStatus carbonEventHandler (EventHandlerCallRef nextHandlerRef,
  611. EventRef event)
  612. {
  613. switch (GetEventKind (event))
  614. {
  615. case kEventWindowHandleDeactivate:
  616. ActivateWindow (wrapperWindow, TRUE);
  617. break;
  618. case kEventWindowGetClickActivation:
  619. {
  620. getTopLevelComponent()->toFront (false);
  621. ClickActivationResult howToHandleClick = kActivateAndHandleClick;
  622. SetEventParameter (event, kEventParamClickActivation, typeClickActivationResult,
  623. sizeof (ClickActivationResult), &howToHandleClick);
  624. HIViewSetNeedsDisplay (embeddedView, true);
  625. }
  626. break;
  627. }
  628. return noErr;
  629. }
  630. static pascal OSStatus carbonEventCallback (EventHandlerCallRef nextHandlerRef,
  631. EventRef event, void* userData)
  632. {
  633. return ((CarbonViewWrapperComponent*) userData)->carbonEventHandler (nextHandlerRef, event);
  634. }
  635. protected:
  636. WindowRef wrapperWindow;
  637. HIViewRef embeddedView;
  638. bool recursiveResize;
  639. Time creationTime;
  640. EventHandlerRef eventHandlerRef;
  641. };
  642. #endif // __JUCE_MAC_CARBONVIEWWRAPPERCOMPONENT_JUCEHEADER__
  643. /********* End of inlined file: juce_mac_CarbonViewWrapperComponent.h *********/
  644. END_JUCE_NAMESPACE
  645. #endif
  646. #define JUCE_AMALGAMATED_TEMPLATE 1
  647. //==============================================================================
  648. /********* Start of inlined file: juce_FileLogger.cpp *********/
  649. BEGIN_JUCE_NAMESPACE
  650. FileLogger::FileLogger (const File& logFile_,
  651. const String& welcomeMessage,
  652. const int maxInitialFileSizeBytes)
  653. : logFile (logFile_)
  654. {
  655. if (maxInitialFileSizeBytes >= 0)
  656. trimFileSize (maxInitialFileSizeBytes);
  657. if (! logFile_.exists())
  658. {
  659. // do this so that the parent directories get created..
  660. logFile_.create();
  661. }
  662. logStream = logFile_.createOutputStream (256);
  663. jassert (logStream != 0);
  664. String welcome;
  665. welcome << "\r\n**********************************************************\r\n"
  666. << welcomeMessage
  667. << "\r\nLog started: " << Time::getCurrentTime().toString (true, true)
  668. << "\r\n";
  669. logMessage (welcome);
  670. }
  671. FileLogger::~FileLogger()
  672. {
  673. }
  674. void FileLogger::logMessage (const String& message)
  675. {
  676. if (logStream != 0)
  677. {
  678. Logger::outputDebugString (message);
  679. const ScopedLock sl (logLock);
  680. (*logStream) << message << T("\r\n");
  681. logStream->flush();
  682. }
  683. }
  684. void FileLogger::trimFileSize (int maxFileSizeBytes) const
  685. {
  686. if (maxFileSizeBytes <= 0)
  687. {
  688. logFile.deleteFile();
  689. }
  690. else
  691. {
  692. const int64 fileSize = logFile.getSize();
  693. if (fileSize > maxFileSizeBytes)
  694. {
  695. ScopedPointer <FileInputStream> in (logFile.createInputStream());
  696. jassert (in != 0);
  697. if (in != 0)
  698. {
  699. in->setPosition (fileSize - maxFileSizeBytes);
  700. String content;
  701. {
  702. MemoryBlock contentToSave;
  703. contentToSave.setSize (maxFileSizeBytes + 4);
  704. contentToSave.fillWith (0);
  705. in->read (contentToSave.getData(), maxFileSizeBytes);
  706. in = 0;
  707. content = contentToSave.toString();
  708. }
  709. int newStart = 0;
  710. while (newStart < fileSize
  711. && content[newStart] != '\n'
  712. && content[newStart] != '\r')
  713. ++newStart;
  714. logFile.deleteFile();
  715. logFile.appendText (content.substring (newStart), false, false);
  716. }
  717. }
  718. }
  719. }
  720. FileLogger* FileLogger::createDefaultAppLogger (const String& logFileSubDirectoryName,
  721. const String& logFileName,
  722. const String& welcomeMessage,
  723. const int maxInitialFileSizeBytes)
  724. {
  725. #if JUCE_MAC
  726. File logFile ("~/Library/Logs");
  727. logFile = logFile.getChildFile (logFileSubDirectoryName)
  728. .getChildFile (logFileName);
  729. #else
  730. File logFile (File::getSpecialLocation (File::userApplicationDataDirectory));
  731. if (logFile.isDirectory())
  732. {
  733. logFile = logFile.getChildFile (logFileSubDirectoryName)
  734. .getChildFile (logFileName);
  735. }
  736. #endif
  737. return new FileLogger (logFile, welcomeMessage, maxInitialFileSizeBytes);
  738. }
  739. END_JUCE_NAMESPACE
  740. /********* End of inlined file: juce_FileLogger.cpp *********/
  741. /********* Start of inlined file: juce_Logger.cpp *********/
  742. BEGIN_JUCE_NAMESPACE
  743. Logger::Logger()
  744. {
  745. }
  746. Logger::~Logger()
  747. {
  748. }
  749. static Logger* currentLogger = 0;
  750. void Logger::setCurrentLogger (Logger* const newLogger,
  751. const bool deleteOldLogger)
  752. {
  753. Logger* const oldLogger = currentLogger;
  754. currentLogger = newLogger;
  755. if (deleteOldLogger)
  756. delete oldLogger;
  757. }
  758. void Logger::writeToLog (const String& message)
  759. {
  760. if (currentLogger != 0)
  761. currentLogger->logMessage (message);
  762. else
  763. outputDebugString (message);
  764. }
  765. #if JUCE_LOG_ASSERTIONS
  766. void JUCE_API juce_LogAssertion (const char* filename, const int lineNum) throw()
  767. {
  768. String m ("JUCE Assertion failure in ");
  769. m << filename << ", line " << lineNum;
  770. Logger::writeToLog (m);
  771. }
  772. #endif
  773. END_JUCE_NAMESPACE
  774. /********* End of inlined file: juce_Logger.cpp *********/
  775. /********* Start of inlined file: juce_Random.cpp *********/
  776. BEGIN_JUCE_NAMESPACE
  777. Random::Random (const int64 seedValue) throw()
  778. : seed (seedValue)
  779. {
  780. }
  781. Random::~Random() throw()
  782. {
  783. }
  784. void Random::setSeed (const int64 newSeed) throw()
  785. {
  786. seed = newSeed;
  787. }
  788. void Random::setSeedRandomly()
  789. {
  790. seed ^= (int64) (pointer_sized_int) this;
  791. seed ^= nextInt64() ^ Time::getMillisecondCounter();
  792. seed ^= nextInt64() ^ Time::getHighResolutionTicks();
  793. seed ^= nextInt64() ^ Time::getHighResolutionTicksPerSecond();
  794. seed ^= nextInt64() ^ Time::currentTimeMillis();
  795. }
  796. int Random::nextInt() throw()
  797. {
  798. seed = (seed * literal64bit (0x5deece66d) + 11) & literal64bit (0xffffffffffff);
  799. return (int) (seed >> 16);
  800. }
  801. int Random::nextInt (const int maxValue) throw()
  802. {
  803. jassert (maxValue > 0);
  804. return (nextInt() & 0x7fffffff) % maxValue;
  805. }
  806. int64 Random::nextInt64() throw()
  807. {
  808. return (((int64) nextInt()) << 32) | (int64) (uint64) (uint32) nextInt();
  809. }
  810. bool Random::nextBool() throw()
  811. {
  812. return (nextInt() & 0x80000000) != 0;
  813. }
  814. float Random::nextFloat() throw()
  815. {
  816. return ((uint32) nextInt()) / (float) 0xffffffff;
  817. }
  818. double Random::nextDouble() throw()
  819. {
  820. return ((uint32) nextInt()) / (double) 0xffffffff;
  821. }
  822. const BitArray Random::nextLargeNumber (const BitArray& maximumValue) throw()
  823. {
  824. BitArray n;
  825. do
  826. {
  827. fillBitsRandomly (n, 0, maximumValue.getHighestBit() + 1);
  828. }
  829. while (n.compare (maximumValue) >= 0);
  830. return n;
  831. }
  832. void Random::fillBitsRandomly (BitArray& arrayToChange, int startBit, int numBits) throw()
  833. {
  834. arrayToChange.setBit (startBit + numBits - 1, true); // to force the array to pre-allocate space
  835. while ((startBit & 31) != 0 && numBits > 0)
  836. {
  837. arrayToChange.setBit (startBit++, nextBool());
  838. --numBits;
  839. }
  840. while (numBits >= 32)
  841. {
  842. arrayToChange.setBitRangeAsInt (startBit, 32, (unsigned int) nextInt());
  843. startBit += 32;
  844. numBits -= 32;
  845. }
  846. while (--numBits >= 0)
  847. arrayToChange.setBit (startBit + numBits, nextBool());
  848. }
  849. Random& Random::getSystemRandom() throw()
  850. {
  851. static Random sysRand (1);
  852. return sysRand;
  853. }
  854. END_JUCE_NAMESPACE
  855. /********* End of inlined file: juce_Random.cpp *********/
  856. /********* Start of inlined file: juce_RelativeTime.cpp *********/
  857. BEGIN_JUCE_NAMESPACE
  858. RelativeTime::RelativeTime (const double seconds_) throw()
  859. : seconds (seconds_)
  860. {
  861. }
  862. RelativeTime::RelativeTime (const RelativeTime& other) throw()
  863. : seconds (other.seconds)
  864. {
  865. }
  866. RelativeTime::~RelativeTime() throw()
  867. {
  868. }
  869. const RelativeTime RelativeTime::milliseconds (const int milliseconds) throw()
  870. {
  871. return RelativeTime (milliseconds * 0.001);
  872. }
  873. const RelativeTime RelativeTime::milliseconds (const int64 milliseconds) throw()
  874. {
  875. return RelativeTime (milliseconds * 0.001);
  876. }
  877. const RelativeTime RelativeTime::minutes (const double numberOfMinutes) throw()
  878. {
  879. return RelativeTime (numberOfMinutes * 60.0);
  880. }
  881. const RelativeTime RelativeTime::hours (const double numberOfHours) throw()
  882. {
  883. return RelativeTime (numberOfHours * (60.0 * 60.0));
  884. }
  885. const RelativeTime RelativeTime::days (const double numberOfDays) throw()
  886. {
  887. return RelativeTime (numberOfDays * (60.0 * 60.0 * 24.0));
  888. }
  889. const RelativeTime RelativeTime::weeks (const double numberOfWeeks) throw()
  890. {
  891. return RelativeTime (numberOfWeeks * (60.0 * 60.0 * 24.0 * 7.0));
  892. }
  893. int64 RelativeTime::inMilliseconds() const throw()
  894. {
  895. return (int64)(seconds * 1000.0);
  896. }
  897. double RelativeTime::inMinutes() const throw()
  898. {
  899. return seconds / 60.0;
  900. }
  901. double RelativeTime::inHours() const throw()
  902. {
  903. return seconds / (60.0 * 60.0);
  904. }
  905. double RelativeTime::inDays() const throw()
  906. {
  907. return seconds / (60.0 * 60.0 * 24.0);
  908. }
  909. double RelativeTime::inWeeks() const throw()
  910. {
  911. return seconds / (60.0 * 60.0 * 24.0 * 7.0);
  912. }
  913. const String RelativeTime::getDescription (const String& returnValueForZeroTime) const throw()
  914. {
  915. if (seconds < 0.001 && seconds > -0.001)
  916. return returnValueForZeroTime;
  917. String result;
  918. if (seconds < 0)
  919. result = T("-");
  920. int fieldsShown = 0;
  921. int n = abs ((int) inWeeks());
  922. if (n > 0)
  923. {
  924. result << n << ((n == 1) ? TRANS(" week ")
  925. : TRANS(" weeks "));
  926. ++fieldsShown;
  927. }
  928. n = abs ((int) inDays()) % 7;
  929. if (n > 0)
  930. {
  931. result << n << ((n == 1) ? TRANS(" day ")
  932. : TRANS(" days "));
  933. ++fieldsShown;
  934. }
  935. if (fieldsShown < 2)
  936. {
  937. n = abs ((int) inHours()) % 24;
  938. if (n > 0)
  939. {
  940. result << n << ((n == 1) ? TRANS(" hr ")
  941. : TRANS(" hrs "));
  942. ++fieldsShown;
  943. }
  944. if (fieldsShown < 2)
  945. {
  946. n = abs ((int) inMinutes()) % 60;
  947. if (n > 0)
  948. {
  949. result << n << ((n == 1) ? TRANS(" min ")
  950. : TRANS(" mins "));
  951. ++fieldsShown;
  952. }
  953. if (fieldsShown < 2)
  954. {
  955. n = abs ((int) inSeconds()) % 60;
  956. if (n > 0)
  957. {
  958. result << n << ((n == 1) ? TRANS(" sec ")
  959. : TRANS(" secs "));
  960. ++fieldsShown;
  961. }
  962. if (fieldsShown < 1)
  963. {
  964. n = abs ((int) inMilliseconds()) % 1000;
  965. if (n > 0)
  966. {
  967. result << n << TRANS(" ms");
  968. ++fieldsShown;
  969. }
  970. }
  971. }
  972. }
  973. }
  974. return result.trimEnd();
  975. }
  976. const RelativeTime& RelativeTime::operator= (const RelativeTime& other) throw()
  977. {
  978. seconds = other.seconds;
  979. return *this;
  980. }
  981. bool RelativeTime::operator== (const RelativeTime& other) const throw()
  982. {
  983. return seconds == other.seconds;
  984. }
  985. bool RelativeTime::operator!= (const RelativeTime& other) const throw()
  986. {
  987. return seconds != other.seconds;
  988. }
  989. bool RelativeTime::operator> (const RelativeTime& other) const throw()
  990. {
  991. return seconds > other.seconds;
  992. }
  993. bool RelativeTime::operator< (const RelativeTime& other) const throw()
  994. {
  995. return seconds < other.seconds;
  996. }
  997. bool RelativeTime::operator>= (const RelativeTime& other) const throw()
  998. {
  999. return seconds >= other.seconds;
  1000. }
  1001. bool RelativeTime::operator<= (const RelativeTime& other) const throw()
  1002. {
  1003. return seconds <= other.seconds;
  1004. }
  1005. const RelativeTime RelativeTime::operator+ (const RelativeTime& timeToAdd) const throw()
  1006. {
  1007. return RelativeTime (seconds + timeToAdd.seconds);
  1008. }
  1009. const RelativeTime RelativeTime::operator- (const RelativeTime& timeToSubtract) const throw()
  1010. {
  1011. return RelativeTime (seconds - timeToSubtract.seconds);
  1012. }
  1013. const RelativeTime RelativeTime::operator+ (const double secondsToAdd) const throw()
  1014. {
  1015. return RelativeTime (seconds + secondsToAdd);
  1016. }
  1017. const RelativeTime RelativeTime::operator- (const double secondsToSubtract) const throw()
  1018. {
  1019. return RelativeTime (seconds - secondsToSubtract);
  1020. }
  1021. const RelativeTime& RelativeTime::operator+= (const RelativeTime& timeToAdd) throw()
  1022. {
  1023. seconds += timeToAdd.seconds;
  1024. return *this;
  1025. }
  1026. const RelativeTime& RelativeTime::operator-= (const RelativeTime& timeToSubtract) throw()
  1027. {
  1028. seconds -= timeToSubtract.seconds;
  1029. return *this;
  1030. }
  1031. const RelativeTime& RelativeTime::operator+= (const double secondsToAdd) throw()
  1032. {
  1033. seconds += secondsToAdd;
  1034. return *this;
  1035. }
  1036. const RelativeTime& RelativeTime::operator-= (const double secondsToSubtract) throw()
  1037. {
  1038. seconds -= secondsToSubtract;
  1039. return *this;
  1040. }
  1041. END_JUCE_NAMESPACE
  1042. /********* End of inlined file: juce_RelativeTime.cpp *********/
  1043. /********* Start of inlined file: juce_SystemStats.cpp *********/
  1044. BEGIN_JUCE_NAMESPACE
  1045. void juce_initialiseStrings();
  1046. const String SystemStats::getJUCEVersion() throw()
  1047. {
  1048. return "JUCE v" + String (JUCE_MAJOR_VERSION) + "." + String (JUCE_MINOR_VERSION);
  1049. }
  1050. static bool juceInitialisedNonGUI = false;
  1051. void JUCE_PUBLIC_FUNCTION initialiseJuce_NonGUI()
  1052. {
  1053. if (! juceInitialisedNonGUI)
  1054. {
  1055. #if JUCE_MAC || JUCE_IPHONE
  1056. const ScopedAutoReleasePool pool;
  1057. #endif
  1058. #ifdef JUCE_DEBUG
  1059. {
  1060. // Some simple test code to keep an eye on things and make sure these functions
  1061. // work ok on all platforms. Let me know if any of these assertions fail!
  1062. static_jassert (sizeof (pointer_sized_int) == sizeof (void*));
  1063. char a1[7];
  1064. jassert (numElementsInArray(a1) == 7);
  1065. int a2[3];
  1066. jassert (numElementsInArray(a2) == 3);
  1067. int n = 1;
  1068. Atomic::increment (n);
  1069. jassert (Atomic::incrementAndReturn (n) == 3);
  1070. Atomic::decrement (n);
  1071. jassert (Atomic::decrementAndReturn (n) == 1);
  1072. jassert (ByteOrder::swap ((uint16) 0x1122) == 0x2211);
  1073. jassert (ByteOrder::swap ((uint32) 0x11223344) == 0x44332211);
  1074. // Some quick stream tests..
  1075. int randomInt = Random::getSystemRandom().nextInt();
  1076. int64 randomInt64 = Random::getSystemRandom().nextInt64();
  1077. double randomDouble = Random::getSystemRandom().nextDouble();
  1078. String randomString;
  1079. for (int i = 50; --i >= 0;)
  1080. randomString << (juce_wchar) (Random::getSystemRandom().nextInt() & 0xffff);
  1081. MemoryOutputStream mo;
  1082. mo.writeInt (randomInt);
  1083. mo.writeIntBigEndian (randomInt);
  1084. mo.writeCompressedInt (randomInt);
  1085. mo.writeString (randomString);
  1086. mo.writeInt64 (randomInt64);
  1087. mo.writeInt64BigEndian (randomInt64);
  1088. mo.writeDouble (randomDouble);
  1089. mo.writeDoubleBigEndian (randomDouble);
  1090. MemoryInputStream mi (mo.getData(), mo.getDataSize(), false);
  1091. jassert (mi.readInt() == randomInt);
  1092. jassert (mi.readIntBigEndian() == randomInt);
  1093. jassert (mi.readCompressedInt() == randomInt);
  1094. jassert (mi.readString() == randomString);
  1095. jassert (mi.readInt64() == randomInt64);
  1096. jassert (mi.readInt64BigEndian() == randomInt64);
  1097. jassert (mi.readDouble() == randomDouble);
  1098. jassert (mi.readDoubleBigEndian() == randomDouble);
  1099. }
  1100. #endif
  1101. // Now the real initialisation..
  1102. juceInitialisedNonGUI = true;
  1103. DBG (SystemStats::getJUCEVersion());
  1104. juce_initialiseStrings();
  1105. SystemStats::initialiseStats();
  1106. Random::getSystemRandom().setSeedRandomly(); // (mustn't call this before initialiseStats() because it relies on the time being set up)
  1107. }
  1108. }
  1109. #if JUCE_WINDOWS
  1110. // This is imported from the sockets code..
  1111. typedef int (__stdcall juce_CloseWin32SocketLibCall) (void);
  1112. extern juce_CloseWin32SocketLibCall* juce_CloseWin32SocketLib;
  1113. #endif
  1114. #if JUCE_DEBUG
  1115. extern void juce_CheckForDanglingStreams();
  1116. #endif
  1117. void JUCE_PUBLIC_FUNCTION shutdownJuce_NonGUI()
  1118. {
  1119. if (juceInitialisedNonGUI)
  1120. {
  1121. #if JUCE_MAC || JUCE_IPHONE
  1122. const ScopedAutoReleasePool pool;
  1123. #endif
  1124. #if JUCE_WINDOWS
  1125. // need to shut down sockets if they were used..
  1126. if (juce_CloseWin32SocketLib != 0)
  1127. (*juce_CloseWin32SocketLib)();
  1128. #endif
  1129. LocalisedStrings::setCurrentMappings (0);
  1130. Thread::stopAllThreads (3000);
  1131. #if JUCE_DEBUG
  1132. juce_CheckForDanglingStreams();
  1133. #endif
  1134. juceInitialisedNonGUI = false;
  1135. }
  1136. }
  1137. #ifdef JUCE_DLL
  1138. void* juce_Malloc (const int size)
  1139. {
  1140. return malloc (size);
  1141. }
  1142. void* juce_Calloc (const int size)
  1143. {
  1144. return calloc (1, size);
  1145. }
  1146. void* juce_Realloc (void* const block, const int size)
  1147. {
  1148. return realloc (block, size);
  1149. }
  1150. void juce_Free (void* const block)
  1151. {
  1152. free (block);
  1153. }
  1154. #if defined (JUCE_DEBUG) && JUCE_MSVC && JUCE_CHECK_MEMORY_LEAKS
  1155. void* juce_DebugMalloc (const int size, const char* file, const int line)
  1156. {
  1157. return _malloc_dbg (size, _NORMAL_BLOCK, file, line);
  1158. }
  1159. void* juce_DebugCalloc (const int size, const char* file, const int line)
  1160. {
  1161. return _calloc_dbg (1, size, _NORMAL_BLOCK, file, line);
  1162. }
  1163. void* juce_DebugRealloc (void* const block, const int size, const char* file, const int line)
  1164. {
  1165. return _realloc_dbg (block, size, _NORMAL_BLOCK, file, line);
  1166. }
  1167. void juce_DebugFree (void* const block)
  1168. {
  1169. _free_dbg (block, _NORMAL_BLOCK);
  1170. }
  1171. #endif
  1172. #endif
  1173. END_JUCE_NAMESPACE
  1174. /********* End of inlined file: juce_SystemStats.cpp *********/
  1175. /********* Start of inlined file: juce_Time.cpp *********/
  1176. #ifdef _MSC_VER
  1177. #pragma warning (disable: 4514)
  1178. #pragma warning (push)
  1179. #endif
  1180. #ifndef JUCE_WINDOWS
  1181. #include <sys/time.h>
  1182. #else
  1183. #include <ctime>
  1184. #endif
  1185. #include <sys/timeb.h>
  1186. BEGIN_JUCE_NAMESPACE
  1187. #ifdef _MSC_VER
  1188. #pragma warning (pop)
  1189. #ifdef _INC_TIME_INL
  1190. #define USE_NEW_SECURE_TIME_FNS
  1191. #endif
  1192. #endif
  1193. static void millisToLocal (const int64 millis, struct tm& result) throw()
  1194. {
  1195. const int64 seconds = millis / 1000;
  1196. if (seconds < literal64bit (86400) || seconds >= literal64bit (2145916800))
  1197. {
  1198. // use extended maths for dates beyond 1970 to 2037..
  1199. const int timeZoneAdjustment = 31536000 - (int) (Time (1971, 0, 1, 0, 0).toMilliseconds() / 1000);
  1200. const int64 jdm = seconds + timeZoneAdjustment + literal64bit (210866803200);
  1201. const int days = (int) (jdm / literal64bit (86400));
  1202. const int a = 32044 + days;
  1203. const int b = (4 * a + 3) / 146097;
  1204. const int c = a - (b * 146097) / 4;
  1205. const int d = (4 * c + 3) / 1461;
  1206. const int e = c - (d * 1461) / 4;
  1207. const int m = (5 * e + 2) / 153;
  1208. result.tm_mday = e - (153 * m + 2) / 5 + 1;
  1209. result.tm_mon = m + 2 - 12 * (m / 10);
  1210. result.tm_year = b * 100 + d - 6700 + (m / 10);
  1211. result.tm_wday = (days + 1) % 7;
  1212. result.tm_yday = -1;
  1213. int t = (int) (jdm % literal64bit (86400));
  1214. result.tm_hour = t / 3600;
  1215. t %= 3600;
  1216. result.tm_min = t / 60;
  1217. result.tm_sec = t % 60;
  1218. result.tm_isdst = -1;
  1219. }
  1220. else
  1221. {
  1222. time_t now = (time_t) (seconds);
  1223. #if JUCE_WINDOWS
  1224. #ifdef USE_NEW_SECURE_TIME_FNS
  1225. if (now >= 0 && now <= 0x793406fff)
  1226. localtime_s (&result, &now);
  1227. else
  1228. zeromem (&result, sizeof (result));
  1229. #else
  1230. result = *localtime (&now);
  1231. #endif
  1232. #else
  1233. // more thread-safe
  1234. localtime_r (&now, &result);
  1235. #endif
  1236. }
  1237. }
  1238. Time::Time() throw()
  1239. : millisSinceEpoch (0)
  1240. {
  1241. }
  1242. Time::Time (const Time& other) throw()
  1243. : millisSinceEpoch (other.millisSinceEpoch)
  1244. {
  1245. }
  1246. Time::Time (const int64 ms) throw()
  1247. : millisSinceEpoch (ms)
  1248. {
  1249. }
  1250. Time::Time (const int year,
  1251. const int month,
  1252. const int day,
  1253. const int hours,
  1254. const int minutes,
  1255. const int seconds,
  1256. const int milliseconds,
  1257. const bool useLocalTime) throw()
  1258. {
  1259. jassert (year > 100); // year must be a 4-digit version
  1260. if (year < 1971 || year >= 2038 || ! useLocalTime)
  1261. {
  1262. // use extended maths for dates beyond 1970 to 2037..
  1263. const int timeZoneAdjustment = useLocalTime ? (31536000 - (int) (Time (1971, 0, 1, 0, 0).toMilliseconds() / 1000))
  1264. : 0;
  1265. const int a = (13 - month) / 12;
  1266. const int y = year + 4800 - a;
  1267. const int jd = day + (153 * (month + 12 * a - 2) + 2) / 5
  1268. + (y * 365) + (y / 4) - (y / 100) + (y / 400)
  1269. - 32045;
  1270. const int64 s = ((int64) jd) * literal64bit (86400) - literal64bit (210866803200);
  1271. millisSinceEpoch = 1000 * (s + (hours * 3600 + minutes * 60 + seconds - timeZoneAdjustment))
  1272. + milliseconds;
  1273. }
  1274. else
  1275. {
  1276. struct tm t;
  1277. t.tm_year = year - 1900;
  1278. t.tm_mon = month;
  1279. t.tm_mday = day;
  1280. t.tm_hour = hours;
  1281. t.tm_min = minutes;
  1282. t.tm_sec = seconds;
  1283. t.tm_isdst = -1;
  1284. millisSinceEpoch = 1000 * (int64) mktime (&t);
  1285. if (millisSinceEpoch < 0)
  1286. millisSinceEpoch = 0;
  1287. else
  1288. millisSinceEpoch += milliseconds;
  1289. }
  1290. }
  1291. Time::~Time() throw()
  1292. {
  1293. }
  1294. const Time& Time::operator= (const Time& other) throw()
  1295. {
  1296. millisSinceEpoch = other.millisSinceEpoch;
  1297. return *this;
  1298. }
  1299. int64 Time::currentTimeMillis() throw()
  1300. {
  1301. static uint32 lastCounterResult = 0xffffffff;
  1302. static int64 correction = 0;
  1303. const uint32 now = getMillisecondCounter();
  1304. // check the counter hasn't wrapped (also triggered the first time this function is called)
  1305. if (now < lastCounterResult)
  1306. {
  1307. // double-check it's actually wrapped, in case multi-cpu machines have timers that drift a bit.
  1308. if (lastCounterResult == 0xffffffff || now < lastCounterResult - 10)
  1309. {
  1310. // get the time once using normal library calls, and store the difference needed to
  1311. // turn the millisecond counter into a real time.
  1312. #if JUCE_WINDOWS
  1313. struct _timeb t;
  1314. #ifdef USE_NEW_SECURE_TIME_FNS
  1315. _ftime_s (&t);
  1316. #else
  1317. _ftime (&t);
  1318. #endif
  1319. correction = (((int64) t.time) * 1000 + t.millitm) - now;
  1320. #else
  1321. struct timeval tv;
  1322. struct timezone tz;
  1323. gettimeofday (&tv, &tz);
  1324. correction = (((int64) tv.tv_sec) * 1000 + tv.tv_usec / 1000) - now;
  1325. #endif
  1326. }
  1327. }
  1328. lastCounterResult = now;
  1329. return correction + now;
  1330. }
  1331. uint32 juce_millisecondsSinceStartup() throw();
  1332. static uint32 lastMSCounterValue = 0;
  1333. uint32 Time::getMillisecondCounter() throw()
  1334. {
  1335. const uint32 now = juce_millisecondsSinceStartup();
  1336. if (now < lastMSCounterValue)
  1337. {
  1338. // in multi-threaded apps this might be called concurrently, so
  1339. // make sure that our last counter value only increases and doesn't
  1340. // go backwards..
  1341. if (now < lastMSCounterValue - 1000)
  1342. lastMSCounterValue = now;
  1343. }
  1344. else
  1345. {
  1346. lastMSCounterValue = now;
  1347. }
  1348. return now;
  1349. }
  1350. uint32 Time::getApproximateMillisecondCounter() throw()
  1351. {
  1352. jassert (lastMSCounterValue != 0);
  1353. return lastMSCounterValue;
  1354. }
  1355. void Time::waitForMillisecondCounter (const uint32 targetTime) throw()
  1356. {
  1357. for (;;)
  1358. {
  1359. const uint32 now = getMillisecondCounter();
  1360. if (now >= targetTime)
  1361. break;
  1362. const int toWait = targetTime - now;
  1363. if (toWait > 2)
  1364. {
  1365. Thread::sleep (jmin (20, toWait >> 1));
  1366. }
  1367. else
  1368. {
  1369. // xxx should consider using mutex_pause on the mac as it apparently
  1370. // makes it seem less like a spinlock and avoids lowering the thread pri.
  1371. for (int i = 10; --i >= 0;)
  1372. Thread::yield();
  1373. }
  1374. }
  1375. }
  1376. double Time::highResolutionTicksToSeconds (const int64 ticks) throw()
  1377. {
  1378. return ticks / (double) getHighResolutionTicksPerSecond();
  1379. }
  1380. int64 Time::secondsToHighResolutionTicks (const double seconds) throw()
  1381. {
  1382. return (int64) (seconds * (double) getHighResolutionTicksPerSecond());
  1383. }
  1384. const Time JUCE_CALLTYPE Time::getCurrentTime() throw()
  1385. {
  1386. return Time (currentTimeMillis());
  1387. }
  1388. const String Time::toString (const bool includeDate,
  1389. const bool includeTime,
  1390. const bool includeSeconds,
  1391. const bool use24HourClock) const throw()
  1392. {
  1393. String result;
  1394. if (includeDate)
  1395. {
  1396. result << getDayOfMonth() << ' '
  1397. << getMonthName (true) << ' '
  1398. << getYear();
  1399. if (includeTime)
  1400. result << ' ';
  1401. }
  1402. if (includeTime)
  1403. {
  1404. if (includeSeconds)
  1405. {
  1406. result += String::formatted (T("%d:%02d:%02d "),
  1407. (use24HourClock) ? getHours()
  1408. : getHoursInAmPmFormat(),
  1409. getMinutes(),
  1410. getSeconds());
  1411. }
  1412. else
  1413. {
  1414. result += String::formatted (T("%d.%02d"),
  1415. (use24HourClock) ? getHours()
  1416. : getHoursInAmPmFormat(),
  1417. getMinutes());
  1418. }
  1419. if (! use24HourClock)
  1420. result << (isAfternoon() ? "pm" : "am");
  1421. }
  1422. return result.trimEnd();
  1423. }
  1424. const String Time::formatted (const tchar* const format) const throw()
  1425. {
  1426. String buffer;
  1427. int bufferSize = 128;
  1428. buffer.preallocateStorage (bufferSize);
  1429. struct tm t;
  1430. millisToLocal (millisSinceEpoch, t);
  1431. while (CharacterFunctions::ftime ((tchar*) (const tchar*) buffer, bufferSize, format, &t) <= 0)
  1432. {
  1433. bufferSize += 128;
  1434. buffer.preallocateStorage (bufferSize);
  1435. }
  1436. return buffer;
  1437. }
  1438. int Time::getYear() const throw()
  1439. {
  1440. struct tm t;
  1441. millisToLocal (millisSinceEpoch, t);
  1442. return t.tm_year + 1900;
  1443. }
  1444. int Time::getMonth() const throw()
  1445. {
  1446. struct tm t;
  1447. millisToLocal (millisSinceEpoch, t);
  1448. return t.tm_mon;
  1449. }
  1450. int Time::getDayOfMonth() const throw()
  1451. {
  1452. struct tm t;
  1453. millisToLocal (millisSinceEpoch, t);
  1454. return t.tm_mday;
  1455. }
  1456. int Time::getDayOfWeek() const throw()
  1457. {
  1458. struct tm t;
  1459. millisToLocal (millisSinceEpoch, t);
  1460. return t.tm_wday;
  1461. }
  1462. int Time::getHours() const throw()
  1463. {
  1464. struct tm t;
  1465. millisToLocal (millisSinceEpoch, t);
  1466. return t.tm_hour;
  1467. }
  1468. int Time::getHoursInAmPmFormat() const throw()
  1469. {
  1470. const int hours = getHours();
  1471. if (hours == 0)
  1472. return 12;
  1473. else if (hours <= 12)
  1474. return hours;
  1475. else
  1476. return hours - 12;
  1477. }
  1478. bool Time::isAfternoon() const throw()
  1479. {
  1480. return getHours() >= 12;
  1481. }
  1482. static int extendedModulo (const int64 value, const int modulo) throw()
  1483. {
  1484. return (int) (value >= 0 ? (value % modulo)
  1485. : (value - ((value / modulo) + 1) * modulo));
  1486. }
  1487. int Time::getMinutes() const throw()
  1488. {
  1489. struct tm t;
  1490. millisToLocal (millisSinceEpoch, t);
  1491. return t.tm_min;
  1492. }
  1493. int Time::getSeconds() const throw()
  1494. {
  1495. return extendedModulo (millisSinceEpoch / 1000, 60);
  1496. }
  1497. int Time::getMilliseconds() const throw()
  1498. {
  1499. return extendedModulo (millisSinceEpoch, 1000);
  1500. }
  1501. bool Time::isDaylightSavingTime() const throw()
  1502. {
  1503. struct tm t;
  1504. millisToLocal (millisSinceEpoch, t);
  1505. return t.tm_isdst != 0;
  1506. }
  1507. const String Time::getTimeZone() const throw()
  1508. {
  1509. String zone[2];
  1510. #if JUCE_WINDOWS
  1511. _tzset();
  1512. #ifdef USE_NEW_SECURE_TIME_FNS
  1513. {
  1514. char name [128];
  1515. size_t length;
  1516. for (int i = 0; i < 2; ++i)
  1517. {
  1518. zeromem (name, sizeof (name));
  1519. _get_tzname (&length, name, 127, i);
  1520. zone[i] = name;
  1521. }
  1522. }
  1523. #else
  1524. const char** const zonePtr = (const char**) _tzname;
  1525. zone[0] = zonePtr[0];
  1526. zone[1] = zonePtr[1];
  1527. #endif
  1528. #else
  1529. tzset();
  1530. const char** const zonePtr = (const char**) tzname;
  1531. zone[0] = zonePtr[0];
  1532. zone[1] = zonePtr[1];
  1533. #endif
  1534. if (isDaylightSavingTime())
  1535. {
  1536. zone[0] = zone[1];
  1537. if (zone[0].length() > 3
  1538. && zone[0].containsIgnoreCase (T("daylight"))
  1539. && zone[0].contains (T("GMT")))
  1540. zone[0] = "BST";
  1541. }
  1542. return zone[0].substring (0, 3);
  1543. }
  1544. const String Time::getMonthName (const bool threeLetterVersion) const throw()
  1545. {
  1546. return getMonthName (getMonth(), threeLetterVersion);
  1547. }
  1548. const String Time::getWeekdayName (const bool threeLetterVersion) const throw()
  1549. {
  1550. return getWeekdayName (getDayOfWeek(), threeLetterVersion);
  1551. }
  1552. const String Time::getMonthName (int monthNumber,
  1553. const bool threeLetterVersion) throw()
  1554. {
  1555. const char* const shortMonthNames[] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" };
  1556. const char* const longMonthNames[] = { "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" };
  1557. monthNumber %= 12;
  1558. return TRANS (threeLetterVersion ? shortMonthNames [monthNumber]
  1559. : longMonthNames [monthNumber]);
  1560. }
  1561. const String Time::getWeekdayName (int day,
  1562. const bool threeLetterVersion) throw()
  1563. {
  1564. const char* const shortDayNames[] = { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" };
  1565. const char* const longDayNames[] = { "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" };
  1566. day %= 7;
  1567. return TRANS (threeLetterVersion ? shortDayNames [day]
  1568. : longDayNames [day]);
  1569. }
  1570. END_JUCE_NAMESPACE
  1571. /********* End of inlined file: juce_Time.cpp *********/
  1572. /********* Start of inlined file: juce_BitArray.cpp *********/
  1573. BEGIN_JUCE_NAMESPACE
  1574. BitArray::BitArray() throw()
  1575. : numValues (4),
  1576. highestBit (-1),
  1577. negative (false)
  1578. {
  1579. values.calloc (numValues + 1);
  1580. }
  1581. BitArray::BitArray (const int value) throw()
  1582. : numValues (4),
  1583. highestBit (31),
  1584. negative (value < 0)
  1585. {
  1586. values.calloc (numValues + 1);
  1587. values[0] = abs (value);
  1588. highestBit = getHighestBit();
  1589. }
  1590. BitArray::BitArray (int64 value) throw()
  1591. : numValues (4),
  1592. highestBit (63),
  1593. negative (value < 0)
  1594. {
  1595. values.calloc (numValues + 1);
  1596. if (value < 0)
  1597. value = -value;
  1598. values[0] = (unsigned int) value;
  1599. values[1] = (unsigned int) (value >> 32);
  1600. highestBit = getHighestBit();
  1601. }
  1602. BitArray::BitArray (const unsigned int value) throw()
  1603. : numValues (4),
  1604. highestBit (31),
  1605. negative (false)
  1606. {
  1607. values.calloc (numValues + 1);
  1608. values[0] = value;
  1609. highestBit = getHighestBit();
  1610. }
  1611. BitArray::BitArray (const BitArray& other) throw()
  1612. : numValues (jmax (4, (other.highestBit >> 5) + 1)),
  1613. highestBit (other.getHighestBit()),
  1614. negative (other.negative)
  1615. {
  1616. values.malloc (numValues + 1);
  1617. memcpy (values, other.values, sizeof (unsigned int) * (numValues + 1));
  1618. }
  1619. BitArray::~BitArray() throw()
  1620. {
  1621. }
  1622. BitArray& BitArray::operator= (const BitArray& other) throw()
  1623. {
  1624. if (this != &other)
  1625. {
  1626. highestBit = other.getHighestBit();
  1627. numValues = jmax (4, (highestBit >> 5) + 1);
  1628. negative = other.negative;
  1629. values.malloc (numValues + 1);
  1630. memcpy (values, other.values, sizeof (unsigned int) * (numValues + 1));
  1631. }
  1632. return *this;
  1633. }
  1634. // result == 0 = the same
  1635. // result < 0 = this number is smaller
  1636. // result > 0 = this number is bigger
  1637. int BitArray::compare (const BitArray& other) const throw()
  1638. {
  1639. if (isNegative() == other.isNegative())
  1640. {
  1641. const int absComp = compareAbsolute (other);
  1642. return isNegative() ? -absComp : absComp;
  1643. }
  1644. else
  1645. {
  1646. return isNegative() ? -1 : 1;
  1647. }
  1648. }
  1649. int BitArray::compareAbsolute (const BitArray& other) const throw()
  1650. {
  1651. const int h1 = getHighestBit();
  1652. const int h2 = other.getHighestBit();
  1653. if (h1 > h2)
  1654. return 1;
  1655. else if (h1 < h2)
  1656. return -1;
  1657. for (int i = (h1 >> 5) + 1; --i >= 0;)
  1658. if (values[i] != other.values[i])
  1659. return (values[i] > other.values[i]) ? 1 : -1;
  1660. return 0;
  1661. }
  1662. bool BitArray::operator== (const BitArray& other) const throw()
  1663. {
  1664. return compare (other) == 0;
  1665. }
  1666. bool BitArray::operator!= (const BitArray& other) const throw()
  1667. {
  1668. return compare (other) != 0;
  1669. }
  1670. bool BitArray::operator[] (const int bit) const throw()
  1671. {
  1672. return bit >= 0 && bit <= highestBit
  1673. && ((values [bit >> 5] & (1 << (bit & 31))) != 0);
  1674. }
  1675. bool BitArray::isEmpty() const throw()
  1676. {
  1677. return getHighestBit() < 0;
  1678. }
  1679. void BitArray::clear() throw()
  1680. {
  1681. if (numValues > 16)
  1682. {
  1683. numValues = 4;
  1684. values.calloc (numValues + 1);
  1685. }
  1686. else
  1687. {
  1688. zeromem (values, sizeof (unsigned int) * (numValues + 1));
  1689. }
  1690. highestBit = -1;
  1691. negative = false;
  1692. }
  1693. void BitArray::setBit (const int bit) throw()
  1694. {
  1695. if (bit >= 0)
  1696. {
  1697. if (bit > highestBit)
  1698. {
  1699. ensureSize (bit >> 5);
  1700. highestBit = bit;
  1701. }
  1702. values [bit >> 5] |= (1 << (bit & 31));
  1703. }
  1704. }
  1705. void BitArray::setBit (const int bit,
  1706. const bool shouldBeSet) throw()
  1707. {
  1708. if (shouldBeSet)
  1709. setBit (bit);
  1710. else
  1711. clearBit (bit);
  1712. }
  1713. void BitArray::clearBit (const int bit) throw()
  1714. {
  1715. if (bit >= 0 && bit <= highestBit)
  1716. values [bit >> 5] &= ~(1 << (bit & 31));
  1717. }
  1718. void BitArray::setRange (int startBit,
  1719. int numBits,
  1720. const bool shouldBeSet) throw()
  1721. {
  1722. while (--numBits >= 0)
  1723. setBit (startBit++, shouldBeSet);
  1724. }
  1725. void BitArray::insertBit (const int bit,
  1726. const bool shouldBeSet) throw()
  1727. {
  1728. if (bit >= 0)
  1729. shiftBits (1, bit);
  1730. setBit (bit, shouldBeSet);
  1731. }
  1732. void BitArray::andWith (const BitArray& other) throw()
  1733. {
  1734. // this operation will only work with the absolute values
  1735. jassert (isNegative() == other.isNegative());
  1736. int n = numValues;
  1737. while (n > other.numValues)
  1738. values[--n] = 0;
  1739. while (--n >= 0)
  1740. values[n] &= other.values[n];
  1741. if (other.highestBit < highestBit)
  1742. highestBit = other.highestBit;
  1743. highestBit = getHighestBit();
  1744. }
  1745. void BitArray::orWith (const BitArray& other) throw()
  1746. {
  1747. if (other.highestBit < 0)
  1748. return;
  1749. // this operation will only work with the absolute values
  1750. jassert (isNegative() == other.isNegative());
  1751. ensureSize (other.highestBit >> 5);
  1752. int n = (other.highestBit >> 5) + 1;
  1753. while (--n >= 0)
  1754. values[n] |= other.values[n];
  1755. if (other.highestBit > highestBit)
  1756. highestBit = other.highestBit;
  1757. highestBit = getHighestBit();
  1758. }
  1759. void BitArray::xorWith (const BitArray& other) throw()
  1760. {
  1761. if (other.highestBit < 0)
  1762. return;
  1763. // this operation will only work with the absolute values
  1764. jassert (isNegative() == other.isNegative());
  1765. ensureSize (other.highestBit >> 5);
  1766. int n = (other.highestBit >> 5) + 1;
  1767. while (--n >= 0)
  1768. values[n] ^= other.values[n];
  1769. if (other.highestBit > highestBit)
  1770. highestBit = other.highestBit;
  1771. highestBit = getHighestBit();
  1772. }
  1773. void BitArray::add (const BitArray& other) throw()
  1774. {
  1775. if (other.isNegative())
  1776. {
  1777. BitArray o (other);
  1778. o.negate();
  1779. subtract (o);
  1780. return;
  1781. }
  1782. if (isNegative())
  1783. {
  1784. if (compareAbsolute (other) < 0)
  1785. {
  1786. BitArray temp (*this);
  1787. temp.negate();
  1788. *this = other;
  1789. subtract (temp);
  1790. }
  1791. else
  1792. {
  1793. negate();
  1794. subtract (other);
  1795. negate();
  1796. }
  1797. return;
  1798. }
  1799. if (other.highestBit > highestBit)
  1800. highestBit = other.highestBit;
  1801. ++highestBit;
  1802. const int numInts = (highestBit >> 5) + 1;
  1803. ensureSize (numInts);
  1804. int64 remainder = 0;
  1805. for (int i = 0; i <= numInts; ++i)
  1806. {
  1807. if (i < numValues)
  1808. remainder += values[i];
  1809. if (i < other.numValues)
  1810. remainder += other.values[i];
  1811. values[i] = (unsigned int) remainder;
  1812. remainder >>= 32;
  1813. }
  1814. jassert (remainder == 0);
  1815. highestBit = getHighestBit();
  1816. }
  1817. void BitArray::subtract (const BitArray& other) throw()
  1818. {
  1819. if (other.isNegative())
  1820. {
  1821. BitArray o (other);
  1822. o.negate();
  1823. add (o);
  1824. return;
  1825. }
  1826. if (! isNegative())
  1827. {
  1828. if (compareAbsolute (other) < 0)
  1829. {
  1830. BitArray temp (*this);
  1831. *this = other;
  1832. subtract (temp);
  1833. negate();
  1834. return;
  1835. }
  1836. }
  1837. else
  1838. {
  1839. negate();
  1840. add (other);
  1841. negate();
  1842. return;
  1843. }
  1844. const int numInts = (highestBit >> 5) + 1;
  1845. const int maxOtherInts = (other.highestBit >> 5) + 1;
  1846. int64 amountToSubtract = 0;
  1847. for (int i = 0; i <= numInts; ++i)
  1848. {
  1849. if (i <= maxOtherInts)
  1850. amountToSubtract += (int64)other.values[i];
  1851. if (values[i] >= amountToSubtract)
  1852. {
  1853. values[i] = (unsigned int) (values[i] - amountToSubtract);
  1854. amountToSubtract = 0;
  1855. }
  1856. else
  1857. {
  1858. const int64 n = ((int64) values[i] + (((int64) 1) << 32)) - amountToSubtract;
  1859. values[i] = (unsigned int) n;
  1860. amountToSubtract = 1;
  1861. }
  1862. }
  1863. }
  1864. void BitArray::multiplyBy (const BitArray& other) throw()
  1865. {
  1866. BitArray total;
  1867. highestBit = getHighestBit();
  1868. const bool wasNegative = isNegative();
  1869. setNegative (false);
  1870. for (int i = 0; i <= highestBit; ++i)
  1871. {
  1872. if (operator[](i))
  1873. {
  1874. BitArray n (other);
  1875. n.setNegative (false);
  1876. n.shiftBits (i);
  1877. total.add (n);
  1878. }
  1879. }
  1880. *this = total;
  1881. negative = wasNegative ^ other.isNegative();
  1882. }
  1883. void BitArray::divideBy (const BitArray& divisor, BitArray& remainder) throw()
  1884. {
  1885. jassert (this != &remainder); // (can't handle passing itself in to get the remainder)
  1886. const int divHB = divisor.getHighestBit();
  1887. const int ourHB = getHighestBit();
  1888. if (divHB < 0 || ourHB < 0)
  1889. {
  1890. // division by zero
  1891. remainder.clear();
  1892. clear();
  1893. }
  1894. else
  1895. {
  1896. remainder = *this;
  1897. remainder.setNegative (false);
  1898. const bool wasNegative = isNegative();
  1899. clear();
  1900. BitArray temp (divisor);
  1901. temp.setNegative (false);
  1902. int leftShift = ourHB - divHB;
  1903. temp.shiftBits (leftShift);
  1904. while (leftShift >= 0)
  1905. {
  1906. if (remainder.compareAbsolute (temp) >= 0)
  1907. {
  1908. remainder.subtract (temp);
  1909. setBit (leftShift);
  1910. }
  1911. if (--leftShift >= 0)
  1912. temp.shiftBits (-1);
  1913. }
  1914. negative = wasNegative ^ divisor.isNegative();
  1915. remainder.setNegative (wasNegative);
  1916. }
  1917. }
  1918. void BitArray::modulo (const BitArray& divisor) throw()
  1919. {
  1920. BitArray remainder;
  1921. divideBy (divisor, remainder);
  1922. *this = remainder;
  1923. }
  1924. static const BitArray simpleGCD (BitArray* m, BitArray* n) throw()
  1925. {
  1926. while (! m->isEmpty())
  1927. {
  1928. if (n->compareAbsolute (*m) > 0)
  1929. swapVariables (m, n);
  1930. m->subtract (*n);
  1931. }
  1932. return *n;
  1933. }
  1934. const BitArray BitArray::findGreatestCommonDivisor (BitArray n) const throw()
  1935. {
  1936. BitArray m (*this);
  1937. while (! n.isEmpty())
  1938. {
  1939. if (abs (m.getHighestBit() - n.getHighestBit()) <= 16)
  1940. return simpleGCD (&m, &n);
  1941. BitArray temp1 (m), temp2;
  1942. temp1.divideBy (n, temp2);
  1943. m = n;
  1944. n = temp2;
  1945. }
  1946. return m;
  1947. }
  1948. void BitArray::exponentModulo (const BitArray& exponent,
  1949. const BitArray& modulus) throw()
  1950. {
  1951. BitArray exp (exponent);
  1952. exp.modulo (modulus);
  1953. BitArray value (*this);
  1954. value.modulo (modulus);
  1955. clear();
  1956. setBit (0);
  1957. while (! exp.isEmpty())
  1958. {
  1959. if (exp [0])
  1960. {
  1961. multiplyBy (value);
  1962. this->modulo (modulus);
  1963. }
  1964. value.multiplyBy (value);
  1965. value.modulo (modulus);
  1966. exp.shiftBits (-1);
  1967. }
  1968. }
  1969. void BitArray::inverseModulo (const BitArray& modulus) throw()
  1970. {
  1971. const BitArray one (1);
  1972. if (modulus == one || modulus.isNegative())
  1973. {
  1974. clear();
  1975. return;
  1976. }
  1977. if (isNegative() || compareAbsolute (modulus) >= 0)
  1978. this->modulo (modulus);
  1979. if (*this == one)
  1980. return;
  1981. if (! (*this)[0])
  1982. {
  1983. // not invertible
  1984. clear();
  1985. return;
  1986. }
  1987. BitArray a1 (modulus);
  1988. BitArray a2 (*this);
  1989. BitArray b1 (modulus);
  1990. BitArray b2 (1);
  1991. while (a2 != one)
  1992. {
  1993. BitArray temp1, temp2, multiplier (a1);
  1994. multiplier.divideBy (a2, temp1);
  1995. temp1 = a2;
  1996. temp1.multiplyBy (multiplier);
  1997. temp2 = a1;
  1998. temp2.subtract (temp1);
  1999. a1 = a2;
  2000. a2 = temp2;
  2001. temp1 = b2;
  2002. temp1.multiplyBy (multiplier);
  2003. temp2 = b1;
  2004. temp2.subtract (temp1);
  2005. b1 = b2;
  2006. b2 = temp2;
  2007. }
  2008. while (b2.isNegative())
  2009. b2.add (modulus);
  2010. b2.modulo (modulus);
  2011. *this = b2;
  2012. }
  2013. void BitArray::shiftBits (int bits, const int startBit) throw()
  2014. {
  2015. if (highestBit < 0)
  2016. return;
  2017. if (startBit > 0)
  2018. {
  2019. if (bits < 0)
  2020. {
  2021. // right shift
  2022. for (int i = startBit; i <= highestBit; ++i)
  2023. setBit (i, operator[] (i - bits));
  2024. highestBit = getHighestBit();
  2025. }
  2026. else if (bits > 0)
  2027. {
  2028. // left shift
  2029. for (int i = highestBit + 1; --i >= startBit;)
  2030. setBit (i + bits, operator[] (i));
  2031. while (--bits >= 0)
  2032. clearBit (bits + startBit);
  2033. }
  2034. }
  2035. else
  2036. {
  2037. if (bits < 0)
  2038. {
  2039. // right shift
  2040. bits = -bits;
  2041. if (bits > highestBit)
  2042. {
  2043. clear();
  2044. }
  2045. else
  2046. {
  2047. const int wordsToMove = bits >> 5;
  2048. int top = 1 + (highestBit >> 5) - wordsToMove;
  2049. highestBit -= bits;
  2050. if (wordsToMove > 0)
  2051. {
  2052. int i;
  2053. for (i = 0; i < top; ++i)
  2054. values [i] = values [i + wordsToMove];
  2055. for (i = 0; i < wordsToMove; ++i)
  2056. values [top + i] = 0;
  2057. bits &= 31;
  2058. }
  2059. if (bits != 0)
  2060. {
  2061. const int invBits = 32 - bits;
  2062. --top;
  2063. for (int i = 0; i < top; ++i)
  2064. values[i] = (values[i] >> bits) | (values [i + 1] << invBits);
  2065. values[top] = (values[top] >> bits);
  2066. }
  2067. highestBit = getHighestBit();
  2068. }
  2069. }
  2070. else if (bits > 0)
  2071. {
  2072. // left shift
  2073. ensureSize (((highestBit + bits) >> 5) + 1);
  2074. const int wordsToMove = bits >> 5;
  2075. int top = 1 + (highestBit >> 5);
  2076. highestBit += bits;
  2077. if (wordsToMove > 0)
  2078. {
  2079. int i;
  2080. for (i = top; --i >= 0;)
  2081. values [i + wordsToMove] = values [i];
  2082. for (i = 0; i < wordsToMove; ++i)
  2083. values [i] = 0;
  2084. bits &= 31;
  2085. }
  2086. if (bits != 0)
  2087. {
  2088. const int invBits = 32 - bits;
  2089. for (int i = top + 1 + wordsToMove; --i > wordsToMove;)
  2090. values[i] = (values[i] << bits) | (values [i - 1] >> invBits);
  2091. values [wordsToMove] = values [wordsToMove] << bits;
  2092. }
  2093. highestBit = getHighestBit();
  2094. }
  2095. }
  2096. }
  2097. const BitArray BitArray::getBitRange (int startBit, int numBits) const throw()
  2098. {
  2099. BitArray r;
  2100. numBits = jmin (numBits, getHighestBit() + 1 - startBit);
  2101. r.ensureSize (numBits >> 5);
  2102. r.highestBit = numBits;
  2103. int i = 0;
  2104. while (numBits > 0)
  2105. {
  2106. r.values[i++] = getBitRangeAsInt (startBit, jmin (32, numBits));
  2107. numBits -= 32;
  2108. startBit += 32;
  2109. }
  2110. r.highestBit = r.getHighestBit();
  2111. return r;
  2112. }
  2113. int BitArray::getBitRangeAsInt (const int startBit, int numBits) const throw()
  2114. {
  2115. if (numBits > 32)
  2116. {
  2117. jassertfalse // use getBitRange() if you need more than 32 bits..
  2118. numBits = 32;
  2119. }
  2120. numBits = jmin (numBits, highestBit + 1 - startBit);
  2121. if (numBits <= 0)
  2122. return 0;
  2123. const int pos = startBit >> 5;
  2124. const int offset = startBit & 31;
  2125. const int endSpace = 32 - numBits;
  2126. uint32 n = ((uint32) values [pos]) >> offset;
  2127. if (offset > endSpace)
  2128. n |= ((uint32) values [pos + 1]) << (32 - offset);
  2129. return (int) (n & (((uint32) 0xffffffff) >> endSpace));
  2130. }
  2131. void BitArray::setBitRangeAsInt (const int startBit, int numBits, unsigned int valueToSet) throw()
  2132. {
  2133. if (numBits > 32)
  2134. {
  2135. jassertfalse
  2136. numBits = 32;
  2137. }
  2138. for (int i = 0; i < numBits; ++i)
  2139. {
  2140. setBit (startBit + i, (valueToSet & 1) != 0);
  2141. valueToSet >>= 1;
  2142. }
  2143. }
  2144. bool BitArray::isNegative() const throw()
  2145. {
  2146. return negative && ! isEmpty();
  2147. }
  2148. void BitArray::setNegative (const bool neg) throw()
  2149. {
  2150. negative = neg;
  2151. }
  2152. void BitArray::negate() throw()
  2153. {
  2154. negative = (! negative) && ! isEmpty();
  2155. }
  2156. int BitArray::countNumberOfSetBits() const throw()
  2157. {
  2158. int total = 0;
  2159. for (int i = (highestBit >> 5) + 1; --i >= 0;)
  2160. {
  2161. unsigned int n = values[i];
  2162. if (n == 0xffffffff)
  2163. {
  2164. total += 32;
  2165. }
  2166. else
  2167. {
  2168. while (n != 0)
  2169. {
  2170. total += (n & 1);
  2171. n >>= 1;
  2172. }
  2173. }
  2174. }
  2175. return total;
  2176. }
  2177. int BitArray::getHighestBit() const throw()
  2178. {
  2179. for (int i = highestBit + 1; --i >= 0;)
  2180. if ((values [i >> 5] & (1 << (i & 31))) != 0)
  2181. return i;
  2182. return -1;
  2183. }
  2184. int BitArray::findNextSetBit (int i) const throw()
  2185. {
  2186. for (; i <= highestBit; ++i)
  2187. if ((values [i >> 5] & (1 << (i & 31))) != 0)
  2188. return i;
  2189. return -1;
  2190. }
  2191. int BitArray::findNextClearBit (int i) const throw()
  2192. {
  2193. for (; i <= highestBit; ++i)
  2194. if ((values [i >> 5] & (1 << (i & 31))) == 0)
  2195. break;
  2196. return i;
  2197. }
  2198. void BitArray::ensureSize (const int numVals) throw()
  2199. {
  2200. if (numVals + 2 >= numValues)
  2201. {
  2202. int oldSize = numValues;
  2203. numValues = ((numVals + 2) * 3) / 2;
  2204. values.realloc (numValues + 1);
  2205. while (oldSize < numValues)
  2206. values [oldSize++] = 0;
  2207. }
  2208. }
  2209. const String BitArray::toString (const int base, const int minimumNumCharacters) const throw()
  2210. {
  2211. String s;
  2212. BitArray v (*this);
  2213. if (base == 2 || base == 8 || base == 16)
  2214. {
  2215. const int bits = (base == 2) ? 1 : (base == 8 ? 3 : 4);
  2216. static const tchar* const hexDigits = T("0123456789abcdef");
  2217. for (;;)
  2218. {
  2219. const int remainder = v.getBitRangeAsInt (0, bits);
  2220. v.shiftBits (-bits);
  2221. if (remainder == 0 && v.isEmpty())
  2222. break;
  2223. s = String::charToString (hexDigits [remainder]) + s;
  2224. }
  2225. }
  2226. else if (base == 10)
  2227. {
  2228. const BitArray ten (10);
  2229. BitArray remainder;
  2230. for (;;)
  2231. {
  2232. v.divideBy (ten, remainder);
  2233. if (remainder.isEmpty() && v.isEmpty())
  2234. break;
  2235. s = String (remainder.getBitRangeAsInt (0, 8)) + s;
  2236. }
  2237. }
  2238. else
  2239. {
  2240. jassertfalse // can't do the specified base
  2241. return String::empty;
  2242. }
  2243. const int length = s.length();
  2244. if (length < minimumNumCharacters)
  2245. s = String::repeatedString (T("0"), minimumNumCharacters - length) + s;
  2246. return isNegative() ? T("-") + s : s;
  2247. }
  2248. void BitArray::parseString (const String& text,
  2249. const int base) throw()
  2250. {
  2251. clear();
  2252. const tchar* t = (const tchar*) text;
  2253. if (base == 2 || base == 8 || base == 16)
  2254. {
  2255. const int bits = (base == 2) ? 1 : (base == 8 ? 3 : 4);
  2256. for (;;)
  2257. {
  2258. const tchar c = *t++;
  2259. const int digit = CharacterFunctions::getHexDigitValue (c);
  2260. if (((unsigned int) digit) < (unsigned int) base)
  2261. {
  2262. shiftBits (bits);
  2263. add (digit);
  2264. }
  2265. else if (c == 0)
  2266. {
  2267. break;
  2268. }
  2269. }
  2270. }
  2271. else if (base == 10)
  2272. {
  2273. const BitArray ten ((unsigned int) 10);
  2274. for (;;)
  2275. {
  2276. const tchar c = *t++;
  2277. if (c >= T('0') && c <= T('9'))
  2278. {
  2279. multiplyBy (ten);
  2280. add ((int) (c - T('0')));
  2281. }
  2282. else if (c == 0)
  2283. {
  2284. break;
  2285. }
  2286. }
  2287. }
  2288. setNegative (text.trimStart().startsWithChar (T('-')));
  2289. }
  2290. const MemoryBlock BitArray::toMemoryBlock() const throw()
  2291. {
  2292. const int numBytes = (getHighestBit() + 8) >> 3;
  2293. MemoryBlock mb ((size_t) numBytes);
  2294. for (int i = 0; i < numBytes; ++i)
  2295. mb[i] = (uint8) getBitRangeAsInt (i << 3, 8);
  2296. return mb;
  2297. }
  2298. void BitArray::loadFromMemoryBlock (const MemoryBlock& data) throw()
  2299. {
  2300. clear();
  2301. for (int i = (int) data.getSize(); --i >= 0;)
  2302. this->setBitRangeAsInt ((int) (i << 3), 8, data [i]);
  2303. }
  2304. END_JUCE_NAMESPACE
  2305. /********* End of inlined file: juce_BitArray.cpp *********/
  2306. /********* Start of inlined file: juce_MemoryBlock.cpp *********/
  2307. BEGIN_JUCE_NAMESPACE
  2308. MemoryBlock::MemoryBlock() throw()
  2309. : size (0)
  2310. {
  2311. }
  2312. MemoryBlock::MemoryBlock (const size_t initialSize,
  2313. const bool initialiseToZero) throw()
  2314. {
  2315. if (initialSize > 0)
  2316. {
  2317. size = initialSize;
  2318. data.allocate (initialSize, initialiseToZero);
  2319. }
  2320. else
  2321. {
  2322. size = 0;
  2323. }
  2324. }
  2325. MemoryBlock::MemoryBlock (const MemoryBlock& other) throw()
  2326. : size (other.size)
  2327. {
  2328. if (size > 0)
  2329. {
  2330. jassert (other.data != 0);
  2331. data.malloc (size);
  2332. memcpy (data, other.data, size);
  2333. }
  2334. }
  2335. MemoryBlock::MemoryBlock (const void* const dataToInitialiseFrom,
  2336. const size_t sizeInBytes) throw()
  2337. : size (jmax ((size_t) 0, sizeInBytes))
  2338. {
  2339. jassert (sizeInBytes >= 0);
  2340. if (size > 0)
  2341. {
  2342. jassert (dataToInitialiseFrom != 0); // non-zero size, but a zero pointer passed-in?
  2343. data.malloc (size);
  2344. if (dataToInitialiseFrom != 0)
  2345. memcpy (data, dataToInitialiseFrom, size);
  2346. }
  2347. }
  2348. MemoryBlock::~MemoryBlock() throw()
  2349. {
  2350. jassert (size >= 0); // should never happen
  2351. jassert (size == 0 || data != 0); // non-zero size but no data allocated?
  2352. }
  2353. MemoryBlock& MemoryBlock::operator= (const MemoryBlock& other) throw()
  2354. {
  2355. if (this != &other)
  2356. {
  2357. setSize (other.size, false);
  2358. memcpy (data, other.data, size);
  2359. }
  2360. return *this;
  2361. }
  2362. bool MemoryBlock::operator== (const MemoryBlock& other) const throw()
  2363. {
  2364. return matches (other.data, other.size);
  2365. }
  2366. bool MemoryBlock::operator!= (const MemoryBlock& other) const throw()
  2367. {
  2368. return ! operator== (other);
  2369. }
  2370. bool MemoryBlock::matches (const void* dataToCompare, size_t dataSize) const throw()
  2371. {
  2372. return size == dataSize
  2373. && memcmp (data, dataToCompare, size) == 0;
  2374. }
  2375. // this will resize the block to this size
  2376. void MemoryBlock::setSize (const size_t newSize,
  2377. const bool initialiseToZero) throw()
  2378. {
  2379. if (size != newSize)
  2380. {
  2381. if (newSize <= 0)
  2382. {
  2383. data.free();
  2384. size = 0;
  2385. }
  2386. else
  2387. {
  2388. if (data != 0)
  2389. {
  2390. data.realloc (newSize);
  2391. if (initialiseToZero && (newSize > size))
  2392. zeromem (data + size, newSize - size);
  2393. }
  2394. else
  2395. {
  2396. data.allocate (newSize, initialiseToZero);
  2397. }
  2398. size = newSize;
  2399. }
  2400. }
  2401. }
  2402. void MemoryBlock::ensureSize (const size_t minimumSize,
  2403. const bool initialiseToZero) throw()
  2404. {
  2405. if (size < minimumSize)
  2406. setSize (minimumSize, initialiseToZero);
  2407. }
  2408. void MemoryBlock::swapWith (MemoryBlock& other) throw()
  2409. {
  2410. swapVariables (size, other.size);
  2411. data.swapWith (other.data);
  2412. }
  2413. void MemoryBlock::fillWith (const uint8 value) throw()
  2414. {
  2415. memset (data, (int) value, size);
  2416. }
  2417. void MemoryBlock::append (const void* const srcData,
  2418. const size_t numBytes) throw()
  2419. {
  2420. if (numBytes > 0)
  2421. {
  2422. const size_t oldSize = size;
  2423. setSize (size + numBytes);
  2424. memcpy (data + oldSize, srcData, numBytes);
  2425. }
  2426. }
  2427. void MemoryBlock::copyFrom (const void* const src, int offset, size_t num) throw()
  2428. {
  2429. const char* d = (const char*) src;
  2430. if (offset < 0)
  2431. {
  2432. d -= offset;
  2433. num -= offset;
  2434. offset = 0;
  2435. }
  2436. if (offset + num > size)
  2437. num = size - offset;
  2438. if (num > 0)
  2439. memcpy (data + offset, d, num);
  2440. }
  2441. void MemoryBlock::copyTo (void* const dst, int offset, size_t num) const throw()
  2442. {
  2443. char* d = (char*) dst;
  2444. if (offset < 0)
  2445. {
  2446. zeromem (d, -offset);
  2447. d -= offset;
  2448. num += offset;
  2449. offset = 0;
  2450. }
  2451. if (offset + num > size)
  2452. {
  2453. const size_t newNum = size - offset;
  2454. zeromem (d + newNum, num - newNum);
  2455. num = newNum;
  2456. }
  2457. if (num > 0)
  2458. memcpy (d, data + offset, num);
  2459. }
  2460. void MemoryBlock::removeSection (size_t startByte, size_t numBytesToRemove) throw()
  2461. {
  2462. if (startByte < 0)
  2463. {
  2464. numBytesToRemove += startByte;
  2465. startByte = 0;
  2466. }
  2467. if (startByte + numBytesToRemove >= size)
  2468. {
  2469. setSize (startByte);
  2470. }
  2471. else if (numBytesToRemove > 0)
  2472. {
  2473. memmove (data + startByte,
  2474. data + startByte + numBytesToRemove,
  2475. size - (startByte + numBytesToRemove));
  2476. setSize (size - numBytesToRemove);
  2477. }
  2478. }
  2479. const String MemoryBlock::toString() const throw()
  2480. {
  2481. return String ((const char*) data, size);
  2482. }
  2483. int MemoryBlock::getBitRange (const size_t bitRangeStart, size_t numBits) const throw()
  2484. {
  2485. int res = 0;
  2486. size_t byte = bitRangeStart >> 3;
  2487. int offsetInByte = bitRangeStart & 7;
  2488. size_t bitsSoFar = 0;
  2489. while (numBits > 0 && (size_t) byte < size)
  2490. {
  2491. const int bitsThisTime = jmin ((int) numBits, 8 - offsetInByte);
  2492. const int mask = (0xff >> (8 - bitsThisTime)) << offsetInByte;
  2493. res |= (((data[byte] & mask) >> offsetInByte) << bitsSoFar);
  2494. bitsSoFar += bitsThisTime;
  2495. numBits -= bitsThisTime;
  2496. ++byte;
  2497. offsetInByte = 0;
  2498. }
  2499. return res;
  2500. }
  2501. void MemoryBlock::setBitRange (const size_t bitRangeStart, size_t numBits, int bitsToSet) throw()
  2502. {
  2503. size_t byte = bitRangeStart >> 3;
  2504. int offsetInByte = bitRangeStart & 7;
  2505. unsigned int mask = ~((((unsigned int)0xffffffff) << (32 - numBits)) >> (32 - numBits));
  2506. while (numBits > 0 && (size_t) byte < size)
  2507. {
  2508. const int bitsThisTime = jmin ((int) numBits, 8 - offsetInByte);
  2509. const unsigned int tempMask = (mask << offsetInByte) | ~((((unsigned int)0xffffffff) >> offsetInByte) << offsetInByte);
  2510. const unsigned int tempBits = bitsToSet << offsetInByte;
  2511. data[byte] = (char)((data[byte] & tempMask) | tempBits);
  2512. ++byte;
  2513. numBits -= bitsThisTime;
  2514. bitsToSet >>= bitsThisTime;
  2515. mask >>= bitsThisTime;
  2516. offsetInByte = 0;
  2517. }
  2518. }
  2519. void MemoryBlock::loadFromHexString (const String& hex) throw()
  2520. {
  2521. ensureSize (hex.length() >> 1);
  2522. char* dest = data;
  2523. int i = 0;
  2524. for (;;)
  2525. {
  2526. int byte = 0;
  2527. for (int loop = 2; --loop >= 0;)
  2528. {
  2529. byte <<= 4;
  2530. for (;;)
  2531. {
  2532. const tchar c = hex [i++];
  2533. if (c >= T('0') && c <= T('9'))
  2534. {
  2535. byte |= c - T('0');
  2536. break;
  2537. }
  2538. else if (c >= T('a') && c <= T('z'))
  2539. {
  2540. byte |= c - (T('a') - 10);
  2541. break;
  2542. }
  2543. else if (c >= T('A') && c <= T('Z'))
  2544. {
  2545. byte |= c - (T('A') - 10);
  2546. break;
  2547. }
  2548. else if (c == 0)
  2549. {
  2550. setSize ((int) (dest - data));
  2551. return;
  2552. }
  2553. }
  2554. }
  2555. *dest++ = (char) byte;
  2556. }
  2557. }
  2558. static const char* const encodingTable
  2559. = ".ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+";
  2560. const String MemoryBlock::toBase64Encoding() const throw()
  2561. {
  2562. const size_t numChars = ((size << 3) + 5) / 6;
  2563. String destString ((unsigned int) size); // store the length, followed by a '.', and then the data.
  2564. const int initialLen = destString.length();
  2565. destString.preallocateStorage (initialLen + 2 + numChars);
  2566. tchar* d = const_cast <tchar*> (((const tchar*) destString) + initialLen);
  2567. *d++ = T('.');
  2568. for (size_t i = 0; i < numChars; ++i)
  2569. *d++ = encodingTable [getBitRange (i * 6, 6)];
  2570. *d++ = 0;
  2571. return destString;
  2572. }
  2573. bool MemoryBlock::fromBase64Encoding (const String& s) throw()
  2574. {
  2575. const int startPos = s.indexOfChar (T('.')) + 1;
  2576. if (startPos <= 0)
  2577. return false;
  2578. const int numBytesNeeded = s.substring (0, startPos - 1).getIntValue();
  2579. setSize (numBytesNeeded, true);
  2580. const int numChars = s.length() - startPos;
  2581. const tchar* const srcChars = ((const tchar*) s) + startPos;
  2582. int pos = 0;
  2583. for (int i = 0; i < numChars; ++i)
  2584. {
  2585. const char c = (char) srcChars[i];
  2586. for (int j = 0; j < 64; ++j)
  2587. {
  2588. if (encodingTable[j] == c)
  2589. {
  2590. setBitRange (pos, 6, j);
  2591. pos += 6;
  2592. break;
  2593. }
  2594. }
  2595. }
  2596. return true;
  2597. }
  2598. END_JUCE_NAMESPACE
  2599. /********* End of inlined file: juce_MemoryBlock.cpp *********/
  2600. /********* Start of inlined file: juce_PropertySet.cpp *********/
  2601. BEGIN_JUCE_NAMESPACE
  2602. PropertySet::PropertySet (const bool ignoreCaseOfKeyNames) throw()
  2603. : properties (ignoreCaseOfKeyNames),
  2604. fallbackProperties (0),
  2605. ignoreCaseOfKeys (ignoreCaseOfKeyNames)
  2606. {
  2607. }
  2608. PropertySet::PropertySet (const PropertySet& other) throw()
  2609. : properties (other.properties),
  2610. fallbackProperties (other.fallbackProperties),
  2611. ignoreCaseOfKeys (other.ignoreCaseOfKeys)
  2612. {
  2613. }
  2614. const PropertySet& PropertySet::operator= (const PropertySet& other) throw()
  2615. {
  2616. properties = other.properties;
  2617. fallbackProperties = other.fallbackProperties;
  2618. ignoreCaseOfKeys = other.ignoreCaseOfKeys;
  2619. propertyChanged();
  2620. return *this;
  2621. }
  2622. PropertySet::~PropertySet()
  2623. {
  2624. }
  2625. void PropertySet::clear()
  2626. {
  2627. const ScopedLock sl (lock);
  2628. if (properties.size() > 0)
  2629. {
  2630. properties.clear();
  2631. propertyChanged();
  2632. }
  2633. }
  2634. const String PropertySet::getValue (const String& keyName,
  2635. const String& defaultValue) const throw()
  2636. {
  2637. const ScopedLock sl (lock);
  2638. const int index = properties.getAllKeys().indexOf (keyName, ignoreCaseOfKeys);
  2639. if (index >= 0)
  2640. return properties.getAllValues() [index];
  2641. return fallbackProperties != 0 ? fallbackProperties->getValue (keyName, defaultValue)
  2642. : defaultValue;
  2643. }
  2644. int PropertySet::getIntValue (const String& keyName,
  2645. const int defaultValue) const throw()
  2646. {
  2647. const ScopedLock sl (lock);
  2648. const int index = properties.getAllKeys().indexOf (keyName, ignoreCaseOfKeys);
  2649. if (index >= 0)
  2650. return properties.getAllValues() [index].getIntValue();
  2651. return fallbackProperties != 0 ? fallbackProperties->getIntValue (keyName, defaultValue)
  2652. : defaultValue;
  2653. }
  2654. double PropertySet::getDoubleValue (const String& keyName,
  2655. const double defaultValue) const throw()
  2656. {
  2657. const ScopedLock sl (lock);
  2658. const int index = properties.getAllKeys().indexOf (keyName, ignoreCaseOfKeys);
  2659. if (index >= 0)
  2660. return properties.getAllValues()[index].getDoubleValue();
  2661. return fallbackProperties != 0 ? fallbackProperties->getDoubleValue (keyName, defaultValue)
  2662. : defaultValue;
  2663. }
  2664. bool PropertySet::getBoolValue (const String& keyName,
  2665. const bool defaultValue) const throw()
  2666. {
  2667. const ScopedLock sl (lock);
  2668. const int index = properties.getAllKeys().indexOf (keyName, ignoreCaseOfKeys);
  2669. if (index >= 0)
  2670. return properties.getAllValues() [index].getIntValue() != 0;
  2671. return fallbackProperties != 0 ? fallbackProperties->getBoolValue (keyName, defaultValue)
  2672. : defaultValue;
  2673. }
  2674. XmlElement* PropertySet::getXmlValue (const String& keyName) const
  2675. {
  2676. XmlDocument doc (getValue (keyName));
  2677. return doc.getDocumentElement();
  2678. }
  2679. void PropertySet::setValue (const String& keyName,
  2680. const String& value) throw()
  2681. {
  2682. jassert (keyName.isNotEmpty()); // shouldn't use an empty key name!
  2683. if (keyName.isNotEmpty())
  2684. {
  2685. const ScopedLock sl (lock);
  2686. const int index = properties.getAllKeys().indexOf (keyName, ignoreCaseOfKeys);
  2687. if (index < 0 || properties.getAllValues() [index] != value)
  2688. {
  2689. properties.set (keyName, value);
  2690. propertyChanged();
  2691. }
  2692. }
  2693. }
  2694. void PropertySet::removeValue (const String& keyName) throw()
  2695. {
  2696. if (keyName.isNotEmpty())
  2697. {
  2698. const ScopedLock sl (lock);
  2699. const int index = properties.getAllKeys().indexOf (keyName, ignoreCaseOfKeys);
  2700. if (index >= 0)
  2701. {
  2702. properties.remove (keyName);
  2703. propertyChanged();
  2704. }
  2705. }
  2706. }
  2707. void PropertySet::setValue (const String& keyName, const tchar* const value) throw()
  2708. {
  2709. setValue (keyName, String (value));
  2710. }
  2711. void PropertySet::setValue (const String& keyName, const int value) throw()
  2712. {
  2713. setValue (keyName, String (value));
  2714. }
  2715. void PropertySet::setValue (const String& keyName, const double value) throw()
  2716. {
  2717. setValue (keyName, String (value));
  2718. }
  2719. void PropertySet::setValue (const String& keyName, const bool value) throw()
  2720. {
  2721. setValue (keyName, String ((value) ? T("1") : T("0")));
  2722. }
  2723. void PropertySet::setValue (const String& keyName, const XmlElement* const xml)
  2724. {
  2725. setValue (keyName, (xml == 0) ? String::empty
  2726. : xml->createDocument (String::empty, true));
  2727. }
  2728. bool PropertySet::containsKey (const String& keyName) const throw()
  2729. {
  2730. const ScopedLock sl (lock);
  2731. return properties.getAllKeys().contains (keyName, ignoreCaseOfKeys);
  2732. }
  2733. void PropertySet::setFallbackPropertySet (PropertySet* fallbackProperties_) throw()
  2734. {
  2735. const ScopedLock sl (lock);
  2736. fallbackProperties = fallbackProperties_;
  2737. }
  2738. XmlElement* PropertySet::createXml (const String& nodeName) const throw()
  2739. {
  2740. const ScopedLock sl (lock);
  2741. XmlElement* const xml = new XmlElement (nodeName);
  2742. for (int i = 0; i < properties.getAllKeys().size(); ++i)
  2743. {
  2744. XmlElement* const e = new XmlElement (T("VALUE"));
  2745. e->setAttribute (T("name"), properties.getAllKeys()[i]);
  2746. e->setAttribute (T("val"), properties.getAllValues()[i]);
  2747. xml->addChildElement (e);
  2748. }
  2749. return xml;
  2750. }
  2751. void PropertySet::restoreFromXml (const XmlElement& xml) throw()
  2752. {
  2753. const ScopedLock sl (lock);
  2754. clear();
  2755. forEachXmlChildElementWithTagName (xml, e, T("VALUE"))
  2756. {
  2757. if (e->hasAttribute (T("name"))
  2758. && e->hasAttribute (T("val")))
  2759. {
  2760. properties.set (e->getStringAttribute (T("name")),
  2761. e->getStringAttribute (T("val")));
  2762. }
  2763. }
  2764. if (properties.size() > 0)
  2765. propertyChanged();
  2766. }
  2767. void PropertySet::propertyChanged()
  2768. {
  2769. }
  2770. END_JUCE_NAMESPACE
  2771. /********* End of inlined file: juce_PropertySet.cpp *********/
  2772. /********* Start of inlined file: juce_Variant.cpp *********/
  2773. BEGIN_JUCE_NAMESPACE
  2774. var::var() throw()
  2775. : type (voidType)
  2776. {
  2777. value.doubleValue = 0;
  2778. }
  2779. var::~var()
  2780. {
  2781. if (type == stringType)
  2782. delete value.stringValue;
  2783. else if (type == objectType && value.objectValue != 0)
  2784. value.objectValue->decReferenceCount();
  2785. }
  2786. var::var (const var& valueToCopy)
  2787. : type (valueToCopy.type),
  2788. value (valueToCopy.value)
  2789. {
  2790. if (type == stringType)
  2791. value.stringValue = new String (*(value.stringValue));
  2792. else if (type == objectType && value.objectValue != 0)
  2793. value.objectValue->incReferenceCount();
  2794. }
  2795. var::var (const int value_) throw()
  2796. : type (intType)
  2797. {
  2798. value.intValue = value_;
  2799. }
  2800. var::var (const bool value_) throw()
  2801. : type (boolType)
  2802. {
  2803. value.boolValue = value_;
  2804. }
  2805. var::var (const double value_) throw()
  2806. : type (doubleType)
  2807. {
  2808. value.doubleValue = value_;
  2809. }
  2810. var::var (const String& value_)
  2811. : type (stringType)
  2812. {
  2813. value.stringValue = new String (value_);
  2814. }
  2815. var::var (const char* const value_)
  2816. : type (stringType)
  2817. {
  2818. value.stringValue = new String (value_);
  2819. }
  2820. var::var (const juce_wchar* const value_)
  2821. : type (stringType)
  2822. {
  2823. value.stringValue = new String (value_);
  2824. }
  2825. var::var (DynamicObject* const object)
  2826. : type (objectType)
  2827. {
  2828. value.objectValue = object;
  2829. if (object != 0)
  2830. object->incReferenceCount();
  2831. }
  2832. var::var (MethodFunction method_) throw()
  2833. : type (methodType)
  2834. {
  2835. value.methodValue = method_;
  2836. }
  2837. void var::swapWith (var& other) throw()
  2838. {
  2839. swapVariables (type, other.type);
  2840. swapVariables (value, other.value);
  2841. }
  2842. var& var::operator= (const var& value_) { var newValue (value_); swapWith (newValue); return *this; }
  2843. var& var::operator= (int value_) { var newValue (value_); swapWith (newValue); return *this; }
  2844. var& var::operator= (bool value_) { var newValue (value_); swapWith (newValue); return *this; }
  2845. var& var::operator= (double value_) { var newValue (value_); swapWith (newValue); return *this; }
  2846. var& var::operator= (const char* value_) { var newValue (value_); swapWith (newValue); return *this; }
  2847. var& var::operator= (const juce_wchar* value_) { var newValue (value_); swapWith (newValue); return *this; }
  2848. var& var::operator= (const String& value_) { var newValue (value_); swapWith (newValue); return *this; }
  2849. var& var::operator= (DynamicObject* value_) { var newValue (value_); swapWith (newValue); return *this; }
  2850. var& var::operator= (MethodFunction value_) { var newValue (value_); swapWith (newValue); return *this; }
  2851. var::operator int() const
  2852. {
  2853. switch (type)
  2854. {
  2855. case voidType: break;
  2856. case intType: return value.intValue;
  2857. case boolType: return value.boolValue ? 1 : 0;
  2858. case doubleType: return (int) value.doubleValue;
  2859. case stringType: return value.stringValue->getIntValue();
  2860. case objectType: break;
  2861. default: jassertfalse; break;
  2862. }
  2863. return 0;
  2864. }
  2865. var::operator bool() const
  2866. {
  2867. switch (type)
  2868. {
  2869. case voidType: break;
  2870. case intType: return value.intValue != 0;
  2871. case boolType: return value.boolValue;
  2872. case doubleType: return value.doubleValue != 0;
  2873. case stringType: return value.stringValue->getIntValue() != 0
  2874. || value.stringValue->trim().equalsIgnoreCase (T("true"))
  2875. || value.stringValue->trim().equalsIgnoreCase (T("yes"));
  2876. case objectType: return value.objectValue != 0;
  2877. default: jassertfalse; break;
  2878. }
  2879. return false;
  2880. }
  2881. var::operator float() const
  2882. {
  2883. return (float) operator double();
  2884. }
  2885. var::operator double() const
  2886. {
  2887. switch (type)
  2888. {
  2889. case voidType: break;
  2890. case intType: return value.intValue;
  2891. case boolType: return value.boolValue ? 1.0 : 0.0;
  2892. case doubleType: return value.doubleValue;
  2893. case stringType: return value.stringValue->getDoubleValue();
  2894. case objectType: break;
  2895. default: jassertfalse; break;
  2896. }
  2897. return 0.0;
  2898. }
  2899. const String var::toString() const
  2900. {
  2901. switch (type)
  2902. {
  2903. case voidType: return String::empty;
  2904. case intType: return String (value.intValue);
  2905. case boolType: return value.boolValue ? T("1") : T("0");
  2906. case doubleType: return String (value.doubleValue);
  2907. case stringType: return *(value.stringValue);
  2908. case objectType: return "Object 0x" + String::toHexString ((int) (pointer_sized_int) value.objectValue);
  2909. default: jassertfalse; break;
  2910. }
  2911. return String::empty;
  2912. }
  2913. var::operator const String() const
  2914. {
  2915. return toString();
  2916. }
  2917. DynamicObject* var::getObject() const
  2918. {
  2919. return type == objectType ? value.objectValue : 0;
  2920. }
  2921. bool var::operator== (const var& other) const throw()
  2922. {
  2923. switch (type)
  2924. {
  2925. case voidType: return other.isVoid();
  2926. case intType: return value.intValue == (int) other;
  2927. case boolType: return value.boolValue == (bool) other;
  2928. case doubleType: return value.doubleValue == (double) other;
  2929. case stringType: return (*(value.stringValue)) == other.toString();
  2930. case objectType: return value.objectValue == other.getObject();
  2931. default: jassertfalse; break;
  2932. }
  2933. return false;
  2934. }
  2935. bool var::operator!= (const var& other) const throw()
  2936. {
  2937. return ! operator== (other);
  2938. }
  2939. void var::writeToStream (OutputStream& output) const
  2940. {
  2941. switch (type)
  2942. {
  2943. case voidType: output.writeCompressedInt (0); break;
  2944. case intType: output.writeCompressedInt (5); output.writeByte (1); output.writeInt (value.intValue); break;
  2945. case boolType: output.writeCompressedInt (1); output.writeByte (value.boolValue ? 2 : 3); break;
  2946. case doubleType: output.writeCompressedInt (9); output.writeByte (4); output.writeDouble (value.doubleValue); break;
  2947. case stringType:
  2948. {
  2949. const int len = value.stringValue->copyToUTF8 (0);
  2950. output.writeCompressedInt (len + 1);
  2951. output.writeByte (5);
  2952. HeapBlock <uint8> temp (len);
  2953. value.stringValue->copyToUTF8 (temp);
  2954. output.write (temp, len);
  2955. break;
  2956. }
  2957. case objectType: output.writeCompressedInt (0); jassertfalse; break; // Can't write an object to a stream!
  2958. default: jassertfalse; break; // Is this a corrupted object?
  2959. }
  2960. }
  2961. const var var::readFromStream (InputStream& input)
  2962. {
  2963. const int numBytes = input.readCompressedInt();
  2964. if (numBytes > 0)
  2965. {
  2966. switch (input.readByte())
  2967. {
  2968. case 1: return var (input.readInt());
  2969. case 2: return var (true);
  2970. case 3: return var (false);
  2971. case 4: return var (input.readDouble());
  2972. case 5:
  2973. {
  2974. MemoryBlock mb;
  2975. input.readIntoMemoryBlock (mb, numBytes - 1);
  2976. return var (String::fromUTF8 ((const uint8*) mb.getData(), (int) mb.getSize()));
  2977. }
  2978. default: input.skipNextBytes (numBytes - 1); break;
  2979. }
  2980. }
  2981. return var();
  2982. }
  2983. const var var::operator[] (const var::identifier& propertyName) const
  2984. {
  2985. if (type == objectType && value.objectValue != 0)
  2986. return value.objectValue->getProperty (propertyName);
  2987. return var();
  2988. }
  2989. const var var::invoke (const var::identifier& method, const var* arguments, int numArguments) const
  2990. {
  2991. if (type == objectType && value.objectValue != 0)
  2992. return value.objectValue->invokeMethod (method, arguments, numArguments);
  2993. return var();
  2994. }
  2995. const var var::invoke (const var& targetObject, const var* arguments, int numArguments) const
  2996. {
  2997. if (isMethod())
  2998. {
  2999. DynamicObject* const target = targetObject.getObject();
  3000. if (target != 0)
  3001. return (target->*(value.methodValue)) (arguments, numArguments);
  3002. }
  3003. return var();
  3004. }
  3005. const var var::call (const var::identifier& method) const
  3006. {
  3007. return invoke (method, 0, 0);
  3008. }
  3009. const var var::call (const var::identifier& method, const var& arg1) const
  3010. {
  3011. return invoke (method, &arg1, 1);
  3012. }
  3013. const var var::call (const var::identifier& method, const var& arg1, const var& arg2) const
  3014. {
  3015. var args[] = { arg1, arg2 };
  3016. return invoke (method, args, 2);
  3017. }
  3018. const var var::call (const var::identifier& method, const var& arg1, const var& arg2, const var& arg3)
  3019. {
  3020. var args[] = { arg1, arg2, arg3 };
  3021. return invoke (method, args, 3);
  3022. }
  3023. const var var::call (const var::identifier& method, const var& arg1, const var& arg2, const var& arg3, const var& arg4) const
  3024. {
  3025. var args[] = { arg1, arg2, arg3, arg4 };
  3026. return invoke (method, args, 4);
  3027. }
  3028. const var var::call (const var::identifier& method, const var& arg1, const var& arg2, const var& arg3, const var& arg4, const var& arg5) const
  3029. {
  3030. var args[] = { arg1, arg2, arg3, arg4, arg5 };
  3031. return invoke (method, args, 5);
  3032. }
  3033. var::identifier::identifier (const String& name_)
  3034. : name (name_),
  3035. hashCode (name_.hashCode())
  3036. {
  3037. jassert (name_.isNotEmpty());
  3038. }
  3039. var::identifier::identifier (const char* const name_)
  3040. : name (name_),
  3041. hashCode (name.hashCode())
  3042. {
  3043. jassert (name.isNotEmpty());
  3044. }
  3045. var::identifier::~identifier()
  3046. {
  3047. }
  3048. DynamicObject::DynamicObject()
  3049. {
  3050. }
  3051. DynamicObject::~DynamicObject()
  3052. {
  3053. }
  3054. bool DynamicObject::hasProperty (const var::identifier& propertyName) const
  3055. {
  3056. const int index = propertyIds.indexOf (propertyName.hashCode);
  3057. return index >= 0 && ! propertyValues.getUnchecked (index)->isMethod();
  3058. }
  3059. const var DynamicObject::getProperty (const var::identifier& propertyName) const
  3060. {
  3061. const int index = propertyIds.indexOf (propertyName.hashCode);
  3062. if (index >= 0)
  3063. return *propertyValues.getUnchecked (index);
  3064. return var();
  3065. }
  3066. void DynamicObject::setProperty (const var::identifier& propertyName, const var& newValue)
  3067. {
  3068. const int index = propertyIds.indexOf (propertyName.hashCode);
  3069. if (index >= 0)
  3070. {
  3071. propertyValues.set (index, new var (newValue));
  3072. }
  3073. else
  3074. {
  3075. propertyIds.add (propertyName.hashCode);
  3076. propertyValues.add (new var (newValue));
  3077. }
  3078. }
  3079. void DynamicObject::removeProperty (const var::identifier& propertyName)
  3080. {
  3081. const int index = propertyIds.indexOf (propertyName.hashCode);
  3082. if (index >= 0)
  3083. {
  3084. propertyIds.remove (index);
  3085. propertyValues.remove (index);
  3086. }
  3087. }
  3088. bool DynamicObject::hasMethod (const var::identifier& methodName) const
  3089. {
  3090. return getProperty (methodName).isMethod();
  3091. }
  3092. const var DynamicObject::invokeMethod (const var::identifier& methodName,
  3093. const var* parameters,
  3094. int numParameters)
  3095. {
  3096. return getProperty (methodName).invoke (var (this), parameters, numParameters);
  3097. }
  3098. void DynamicObject::setMethod (const var::identifier& name,
  3099. var::MethodFunction methodFunction)
  3100. {
  3101. setProperty (name, var (methodFunction));
  3102. }
  3103. void DynamicObject::clear()
  3104. {
  3105. propertyIds.clear();
  3106. propertyValues.clear();
  3107. }
  3108. END_JUCE_NAMESPACE
  3109. /********* End of inlined file: juce_Variant.cpp *********/
  3110. /********* Start of inlined file: juce_BlowFish.cpp *********/
  3111. BEGIN_JUCE_NAMESPACE
  3112. static const uint32 initialPValues [18] =
  3113. {
  3114. 0x243f6a88, 0x85a308d3, 0x13198a2e, 0x03707344,
  3115. 0xa4093822, 0x299f31d0, 0x082efa98, 0xec4e6c89,
  3116. 0x452821e6, 0x38d01377, 0xbe5466cf, 0x34e90c6c,
  3117. 0xc0ac29b7, 0xc97c50dd, 0x3f84d5b5, 0xb5470917,
  3118. 0x9216d5d9, 0x8979fb1b
  3119. };
  3120. static const uint32 initialSValues [4 * 256] =
  3121. {
  3122. 0xd1310ba6, 0x98dfb5ac, 0x2ffd72db, 0xd01adfb7,
  3123. 0xb8e1afed, 0x6a267e96, 0xba7c9045, 0xf12c7f99,
  3124. 0x24a19947, 0xb3916cf7, 0x0801f2e2, 0x858efc16,
  3125. 0x636920d8, 0x71574e69, 0xa458fea3, 0xf4933d7e,
  3126. 0x0d95748f, 0x728eb658, 0x718bcd58, 0x82154aee,
  3127. 0x7b54a41d, 0xc25a59b5, 0x9c30d539, 0x2af26013,
  3128. 0xc5d1b023, 0x286085f0, 0xca417918, 0xb8db38ef,
  3129. 0x8e79dcb0, 0x603a180e, 0x6c9e0e8b, 0xb01e8a3e,
  3130. 0xd71577c1, 0xbd314b27, 0x78af2fda, 0x55605c60,
  3131. 0xe65525f3, 0xaa55ab94, 0x57489862, 0x63e81440,
  3132. 0x55ca396a, 0x2aab10b6, 0xb4cc5c34, 0x1141e8ce,
  3133. 0xa15486af, 0x7c72e993, 0xb3ee1411, 0x636fbc2a,
  3134. 0x2ba9c55d, 0x741831f6, 0xce5c3e16, 0x9b87931e,
  3135. 0xafd6ba33, 0x6c24cf5c, 0x7a325381, 0x28958677,
  3136. 0x3b8f4898, 0x6b4bb9af, 0xc4bfe81b, 0x66282193,
  3137. 0x61d809cc, 0xfb21a991, 0x487cac60, 0x5dec8032,
  3138. 0xef845d5d, 0xe98575b1, 0xdc262302, 0xeb651b88,
  3139. 0x23893e81, 0xd396acc5, 0x0f6d6ff3, 0x83f44239,
  3140. 0x2e0b4482, 0xa4842004, 0x69c8f04a, 0x9e1f9b5e,
  3141. 0x21c66842, 0xf6e96c9a, 0x670c9c61, 0xabd388f0,
  3142. 0x6a51a0d2, 0xd8542f68, 0x960fa728, 0xab5133a3,
  3143. 0x6eef0b6c, 0x137a3be4, 0xba3bf050, 0x7efb2a98,
  3144. 0xa1f1651d, 0x39af0176, 0x66ca593e, 0x82430e88,
  3145. 0x8cee8619, 0x456f9fb4, 0x7d84a5c3, 0x3b8b5ebe,
  3146. 0xe06f75d8, 0x85c12073, 0x401a449f, 0x56c16aa6,
  3147. 0x4ed3aa62, 0x363f7706, 0x1bfedf72, 0x429b023d,
  3148. 0x37d0d724, 0xd00a1248, 0xdb0fead3, 0x49f1c09b,
  3149. 0x075372c9, 0x80991b7b, 0x25d479d8, 0xf6e8def7,
  3150. 0xe3fe501a, 0xb6794c3b, 0x976ce0bd, 0x04c006ba,
  3151. 0xc1a94fb6, 0x409f60c4, 0x5e5c9ec2, 0x196a2463,
  3152. 0x68fb6faf, 0x3e6c53b5, 0x1339b2eb, 0x3b52ec6f,
  3153. 0x6dfc511f, 0x9b30952c, 0xcc814544, 0xaf5ebd09,
  3154. 0xbee3d004, 0xde334afd, 0x660f2807, 0x192e4bb3,
  3155. 0xc0cba857, 0x45c8740f, 0xd20b5f39, 0xb9d3fbdb,
  3156. 0x5579c0bd, 0x1a60320a, 0xd6a100c6, 0x402c7279,
  3157. 0x679f25fe, 0xfb1fa3cc, 0x8ea5e9f8, 0xdb3222f8,
  3158. 0x3c7516df, 0xfd616b15, 0x2f501ec8, 0xad0552ab,
  3159. 0x323db5fa, 0xfd238760, 0x53317b48, 0x3e00df82,
  3160. 0x9e5c57bb, 0xca6f8ca0, 0x1a87562e, 0xdf1769db,
  3161. 0xd542a8f6, 0x287effc3, 0xac6732c6, 0x8c4f5573,
  3162. 0x695b27b0, 0xbbca58c8, 0xe1ffa35d, 0xb8f011a0,
  3163. 0x10fa3d98, 0xfd2183b8, 0x4afcb56c, 0x2dd1d35b,
  3164. 0x9a53e479, 0xb6f84565, 0xd28e49bc, 0x4bfb9790,
  3165. 0xe1ddf2da, 0xa4cb7e33, 0x62fb1341, 0xcee4c6e8,
  3166. 0xef20cada, 0x36774c01, 0xd07e9efe, 0x2bf11fb4,
  3167. 0x95dbda4d, 0xae909198, 0xeaad8e71, 0x6b93d5a0,
  3168. 0xd08ed1d0, 0xafc725e0, 0x8e3c5b2f, 0x8e7594b7,
  3169. 0x8ff6e2fb, 0xf2122b64, 0x8888b812, 0x900df01c,
  3170. 0x4fad5ea0, 0x688fc31c, 0xd1cff191, 0xb3a8c1ad,
  3171. 0x2f2f2218, 0xbe0e1777, 0xea752dfe, 0x8b021fa1,
  3172. 0xe5a0cc0f, 0xb56f74e8, 0x18acf3d6, 0xce89e299,
  3173. 0xb4a84fe0, 0xfd13e0b7, 0x7cc43b81, 0xd2ada8d9,
  3174. 0x165fa266, 0x80957705, 0x93cc7314, 0x211a1477,
  3175. 0xe6ad2065, 0x77b5fa86, 0xc75442f5, 0xfb9d35cf,
  3176. 0xebcdaf0c, 0x7b3e89a0, 0xd6411bd3, 0xae1e7e49,
  3177. 0x00250e2d, 0x2071b35e, 0x226800bb, 0x57b8e0af,
  3178. 0x2464369b, 0xf009b91e, 0x5563911d, 0x59dfa6aa,
  3179. 0x78c14389, 0xd95a537f, 0x207d5ba2, 0x02e5b9c5,
  3180. 0x83260376, 0x6295cfa9, 0x11c81968, 0x4e734a41,
  3181. 0xb3472dca, 0x7b14a94a, 0x1b510052, 0x9a532915,
  3182. 0xd60f573f, 0xbc9bc6e4, 0x2b60a476, 0x81e67400,
  3183. 0x08ba6fb5, 0x571be91f, 0xf296ec6b, 0x2a0dd915,
  3184. 0xb6636521, 0xe7b9f9b6, 0xff34052e, 0xc5855664,
  3185. 0x53b02d5d, 0xa99f8fa1, 0x08ba4799, 0x6e85076a,
  3186. 0x4b7a70e9, 0xb5b32944, 0xdb75092e, 0xc4192623,
  3187. 0xad6ea6b0, 0x49a7df7d, 0x9cee60b8, 0x8fedb266,
  3188. 0xecaa8c71, 0x699a17ff, 0x5664526c, 0xc2b19ee1,
  3189. 0x193602a5, 0x75094c29, 0xa0591340, 0xe4183a3e,
  3190. 0x3f54989a, 0x5b429d65, 0x6b8fe4d6, 0x99f73fd6,
  3191. 0xa1d29c07, 0xefe830f5, 0x4d2d38e6, 0xf0255dc1,
  3192. 0x4cdd2086, 0x8470eb26, 0x6382e9c6, 0x021ecc5e,
  3193. 0x09686b3f, 0x3ebaefc9, 0x3c971814, 0x6b6a70a1,
  3194. 0x687f3584, 0x52a0e286, 0xb79c5305, 0xaa500737,
  3195. 0x3e07841c, 0x7fdeae5c, 0x8e7d44ec, 0x5716f2b8,
  3196. 0xb03ada37, 0xf0500c0d, 0xf01c1f04, 0x0200b3ff,
  3197. 0xae0cf51a, 0x3cb574b2, 0x25837a58, 0xdc0921bd,
  3198. 0xd19113f9, 0x7ca92ff6, 0x94324773, 0x22f54701,
  3199. 0x3ae5e581, 0x37c2dadc, 0xc8b57634, 0x9af3dda7,
  3200. 0xa9446146, 0x0fd0030e, 0xecc8c73e, 0xa4751e41,
  3201. 0xe238cd99, 0x3bea0e2f, 0x3280bba1, 0x183eb331,
  3202. 0x4e548b38, 0x4f6db908, 0x6f420d03, 0xf60a04bf,
  3203. 0x2cb81290, 0x24977c79, 0x5679b072, 0xbcaf89af,
  3204. 0xde9a771f, 0xd9930810, 0xb38bae12, 0xdccf3f2e,
  3205. 0x5512721f, 0x2e6b7124, 0x501adde6, 0x9f84cd87,
  3206. 0x7a584718, 0x7408da17, 0xbc9f9abc, 0xe94b7d8c,
  3207. 0xec7aec3a, 0xdb851dfa, 0x63094366, 0xc464c3d2,
  3208. 0xef1c1847, 0x3215d908, 0xdd433b37, 0x24c2ba16,
  3209. 0x12a14d43, 0x2a65c451, 0x50940002, 0x133ae4dd,
  3210. 0x71dff89e, 0x10314e55, 0x81ac77d6, 0x5f11199b,
  3211. 0x043556f1, 0xd7a3c76b, 0x3c11183b, 0x5924a509,
  3212. 0xf28fe6ed, 0x97f1fbfa, 0x9ebabf2c, 0x1e153c6e,
  3213. 0x86e34570, 0xeae96fb1, 0x860e5e0a, 0x5a3e2ab3,
  3214. 0x771fe71c, 0x4e3d06fa, 0x2965dcb9, 0x99e71d0f,
  3215. 0x803e89d6, 0x5266c825, 0x2e4cc978, 0x9c10b36a,
  3216. 0xc6150eba, 0x94e2ea78, 0xa5fc3c53, 0x1e0a2df4,
  3217. 0xf2f74ea7, 0x361d2b3d, 0x1939260f, 0x19c27960,
  3218. 0x5223a708, 0xf71312b6, 0xebadfe6e, 0xeac31f66,
  3219. 0xe3bc4595, 0xa67bc883, 0xb17f37d1, 0x018cff28,
  3220. 0xc332ddef, 0xbe6c5aa5, 0x65582185, 0x68ab9802,
  3221. 0xeecea50f, 0xdb2f953b, 0x2aef7dad, 0x5b6e2f84,
  3222. 0x1521b628, 0x29076170, 0xecdd4775, 0x619f1510,
  3223. 0x13cca830, 0xeb61bd96, 0x0334fe1e, 0xaa0363cf,
  3224. 0xb5735c90, 0x4c70a239, 0xd59e9e0b, 0xcbaade14,
  3225. 0xeecc86bc, 0x60622ca7, 0x9cab5cab, 0xb2f3846e,
  3226. 0x648b1eaf, 0x19bdf0ca, 0xa02369b9, 0x655abb50,
  3227. 0x40685a32, 0x3c2ab4b3, 0x319ee9d5, 0xc021b8f7,
  3228. 0x9b540b19, 0x875fa099, 0x95f7997e, 0x623d7da8,
  3229. 0xf837889a, 0x97e32d77, 0x11ed935f, 0x16681281,
  3230. 0x0e358829, 0xc7e61fd6, 0x96dedfa1, 0x7858ba99,
  3231. 0x57f584a5, 0x1b227263, 0x9b83c3ff, 0x1ac24696,
  3232. 0xcdb30aeb, 0x532e3054, 0x8fd948e4, 0x6dbc3128,
  3233. 0x58ebf2ef, 0x34c6ffea, 0xfe28ed61, 0xee7c3c73,
  3234. 0x5d4a14d9, 0xe864b7e3, 0x42105d14, 0x203e13e0,
  3235. 0x45eee2b6, 0xa3aaabea, 0xdb6c4f15, 0xfacb4fd0,
  3236. 0xc742f442, 0xef6abbb5, 0x654f3b1d, 0x41cd2105,
  3237. 0xd81e799e, 0x86854dc7, 0xe44b476a, 0x3d816250,
  3238. 0xcf62a1f2, 0x5b8d2646, 0xfc8883a0, 0xc1c7b6a3,
  3239. 0x7f1524c3, 0x69cb7492, 0x47848a0b, 0x5692b285,
  3240. 0x095bbf00, 0xad19489d, 0x1462b174, 0x23820e00,
  3241. 0x58428d2a, 0x0c55f5ea, 0x1dadf43e, 0x233f7061,
  3242. 0x3372f092, 0x8d937e41, 0xd65fecf1, 0x6c223bdb,
  3243. 0x7cde3759, 0xcbee7460, 0x4085f2a7, 0xce77326e,
  3244. 0xa6078084, 0x19f8509e, 0xe8efd855, 0x61d99735,
  3245. 0xa969a7aa, 0xc50c06c2, 0x5a04abfc, 0x800bcadc,
  3246. 0x9e447a2e, 0xc3453484, 0xfdd56705, 0x0e1e9ec9,
  3247. 0xdb73dbd3, 0x105588cd, 0x675fda79, 0xe3674340,
  3248. 0xc5c43465, 0x713e38d8, 0x3d28f89e, 0xf16dff20,
  3249. 0x153e21e7, 0x8fb03d4a, 0xe6e39f2b, 0xdb83adf7,
  3250. 0xe93d5a68, 0x948140f7, 0xf64c261c, 0x94692934,
  3251. 0x411520f7, 0x7602d4f7, 0xbcf46b2e, 0xd4a20068,
  3252. 0xd4082471, 0x3320f46a, 0x43b7d4b7, 0x500061af,
  3253. 0x1e39f62e, 0x97244546, 0x14214f74, 0xbf8b8840,
  3254. 0x4d95fc1d, 0x96b591af, 0x70f4ddd3, 0x66a02f45,
  3255. 0xbfbc09ec, 0x03bd9785, 0x7fac6dd0, 0x31cb8504,
  3256. 0x96eb27b3, 0x55fd3941, 0xda2547e6, 0xabca0a9a,
  3257. 0x28507825, 0x530429f4, 0x0a2c86da, 0xe9b66dfb,
  3258. 0x68dc1462, 0xd7486900, 0x680ec0a4, 0x27a18dee,
  3259. 0x4f3ffea2, 0xe887ad8c, 0xb58ce006, 0x7af4d6b6,
  3260. 0xaace1e7c, 0xd3375fec, 0xce78a399, 0x406b2a42,
  3261. 0x20fe9e35, 0xd9f385b9, 0xee39d7ab, 0x3b124e8b,
  3262. 0x1dc9faf7, 0x4b6d1856, 0x26a36631, 0xeae397b2,
  3263. 0x3a6efa74, 0xdd5b4332, 0x6841e7f7, 0xca7820fb,
  3264. 0xfb0af54e, 0xd8feb397, 0x454056ac, 0xba489527,
  3265. 0x55533a3a, 0x20838d87, 0xfe6ba9b7, 0xd096954b,
  3266. 0x55a867bc, 0xa1159a58, 0xcca92963, 0x99e1db33,
  3267. 0xa62a4a56, 0x3f3125f9, 0x5ef47e1c, 0x9029317c,
  3268. 0xfdf8e802, 0x04272f70, 0x80bb155c, 0x05282ce3,
  3269. 0x95c11548, 0xe4c66d22, 0x48c1133f, 0xc70f86dc,
  3270. 0x07f9c9ee, 0x41041f0f, 0x404779a4, 0x5d886e17,
  3271. 0x325f51eb, 0xd59bc0d1, 0xf2bcc18f, 0x41113564,
  3272. 0x257b7834, 0x602a9c60, 0xdff8e8a3, 0x1f636c1b,
  3273. 0x0e12b4c2, 0x02e1329e, 0xaf664fd1, 0xcad18115,
  3274. 0x6b2395e0, 0x333e92e1, 0x3b240b62, 0xeebeb922,
  3275. 0x85b2a20e, 0xe6ba0d99, 0xde720c8c, 0x2da2f728,
  3276. 0xd0127845, 0x95b794fd, 0x647d0862, 0xe7ccf5f0,
  3277. 0x5449a36f, 0x877d48fa, 0xc39dfd27, 0xf33e8d1e,
  3278. 0x0a476341, 0x992eff74, 0x3a6f6eab, 0xf4f8fd37,
  3279. 0xa812dc60, 0xa1ebddf8, 0x991be14c, 0xdb6e6b0d,
  3280. 0xc67b5510, 0x6d672c37, 0x2765d43b, 0xdcd0e804,
  3281. 0xf1290dc7, 0xcc00ffa3, 0xb5390f92, 0x690fed0b,
  3282. 0x667b9ffb, 0xcedb7d9c, 0xa091cf0b, 0xd9155ea3,
  3283. 0xbb132f88, 0x515bad24, 0x7b9479bf, 0x763bd6eb,
  3284. 0x37392eb3, 0xcc115979, 0x8026e297, 0xf42e312d,
  3285. 0x6842ada7, 0xc66a2b3b, 0x12754ccc, 0x782ef11c,
  3286. 0x6a124237, 0xb79251e7, 0x06a1bbe6, 0x4bfb6350,
  3287. 0x1a6b1018, 0x11caedfa, 0x3d25bdd8, 0xe2e1c3c9,
  3288. 0x44421659, 0x0a121386, 0xd90cec6e, 0xd5abea2a,
  3289. 0x64af674e, 0xda86a85f, 0xbebfe988, 0x64e4c3fe,
  3290. 0x9dbc8057, 0xf0f7c086, 0x60787bf8, 0x6003604d,
  3291. 0xd1fd8346, 0xf6381fb0, 0x7745ae04, 0xd736fccc,
  3292. 0x83426b33, 0xf01eab71, 0xb0804187, 0x3c005e5f,
  3293. 0x77a057be, 0xbde8ae24, 0x55464299, 0xbf582e61,
  3294. 0x4e58f48f, 0xf2ddfda2, 0xf474ef38, 0x8789bdc2,
  3295. 0x5366f9c3, 0xc8b38e74, 0xb475f255, 0x46fcd9b9,
  3296. 0x7aeb2661, 0x8b1ddf84, 0x846a0e79, 0x915f95e2,
  3297. 0x466e598e, 0x20b45770, 0x8cd55591, 0xc902de4c,
  3298. 0xb90bace1, 0xbb8205d0, 0x11a86248, 0x7574a99e,
  3299. 0xb77f19b6, 0xe0a9dc09, 0x662d09a1, 0xc4324633,
  3300. 0xe85a1f02, 0x09f0be8c, 0x4a99a025, 0x1d6efe10,
  3301. 0x1ab93d1d, 0x0ba5a4df, 0xa186f20f, 0x2868f169,
  3302. 0xdcb7da83, 0x573906fe, 0xa1e2ce9b, 0x4fcd7f52,
  3303. 0x50115e01, 0xa70683fa, 0xa002b5c4, 0x0de6d027,
  3304. 0x9af88c27, 0x773f8641, 0xc3604c06, 0x61a806b5,
  3305. 0xf0177a28, 0xc0f586e0, 0x006058aa, 0x30dc7d62,
  3306. 0x11e69ed7, 0x2338ea63, 0x53c2dd94, 0xc2c21634,
  3307. 0xbbcbee56, 0x90bcb6de, 0xebfc7da1, 0xce591d76,
  3308. 0x6f05e409, 0x4b7c0188, 0x39720a3d, 0x7c927c24,
  3309. 0x86e3725f, 0x724d9db9, 0x1ac15bb4, 0xd39eb8fc,
  3310. 0xed545578, 0x08fca5b5, 0xd83d7cd3, 0x4dad0fc4,
  3311. 0x1e50ef5e, 0xb161e6f8, 0xa28514d9, 0x6c51133c,
  3312. 0x6fd5c7e7, 0x56e14ec4, 0x362abfce, 0xddc6c837,
  3313. 0xd79a3234, 0x92638212, 0x670efa8e, 0x406000e0,
  3314. 0x3a39ce37, 0xd3faf5cf, 0xabc27737, 0x5ac52d1b,
  3315. 0x5cb0679e, 0x4fa33742, 0xd3822740, 0x99bc9bbe,
  3316. 0xd5118e9d, 0xbf0f7315, 0xd62d1c7e, 0xc700c47b,
  3317. 0xb78c1b6b, 0x21a19045, 0xb26eb1be, 0x6a366eb4,
  3318. 0x5748ab2f, 0xbc946e79, 0xc6a376d2, 0x6549c2c8,
  3319. 0x530ff8ee, 0x468dde7d, 0xd5730a1d, 0x4cd04dc6,
  3320. 0x2939bbdb, 0xa9ba4650, 0xac9526e8, 0xbe5ee304,
  3321. 0xa1fad5f0, 0x6a2d519a, 0x63ef8ce2, 0x9a86ee22,
  3322. 0xc089c2b8, 0x43242ef6, 0xa51e03aa, 0x9cf2d0a4,
  3323. 0x83c061ba, 0x9be96a4d, 0x8fe51550, 0xba645bd6,
  3324. 0x2826a2f9, 0xa73a3ae1, 0x4ba99586, 0xef5562e9,
  3325. 0xc72fefd3, 0xf752f7da, 0x3f046f69, 0x77fa0a59,
  3326. 0x80e4a915, 0x87b08601, 0x9b09e6ad, 0x3b3ee593,
  3327. 0xe990fd5a, 0x9e34d797, 0x2cf0b7d9, 0x022b8b51,
  3328. 0x96d5ac3a, 0x017da67d, 0xd1cf3ed6, 0x7c7d2d28,
  3329. 0x1f9f25cf, 0xadf2b89b, 0x5ad6b472, 0x5a88f54c,
  3330. 0xe029ac71, 0xe019a5e6, 0x47b0acfd, 0xed93fa9b,
  3331. 0xe8d3c48d, 0x283b57cc, 0xf8d56629, 0x79132e28,
  3332. 0x785f0191, 0xed756055, 0xf7960e44, 0xe3d35e8c,
  3333. 0x15056dd4, 0x88f46dba, 0x03a16125, 0x0564f0bd,
  3334. 0xc3eb9e15, 0x3c9057a2, 0x97271aec, 0xa93a072a,
  3335. 0x1b3f6d9b, 0x1e6321f5, 0xf59c66fb, 0x26dcf319,
  3336. 0x7533d928, 0xb155fdf5, 0x03563482, 0x8aba3cbb,
  3337. 0x28517711, 0xc20ad9f8, 0xabcc5167, 0xccad925f,
  3338. 0x4de81751, 0x3830dc8e, 0x379d5862, 0x9320f991,
  3339. 0xea7a90c2, 0xfb3e7bce, 0x5121ce64, 0x774fbe32,
  3340. 0xa8b6e37e, 0xc3293d46, 0x48de5369, 0x6413e680,
  3341. 0xa2ae0810, 0xdd6db224, 0x69852dfd, 0x09072166,
  3342. 0xb39a460a, 0x6445c0dd, 0x586cdecf, 0x1c20c8ae,
  3343. 0x5bbef7dd, 0x1b588d40, 0xccd2017f, 0x6bb4e3bb,
  3344. 0xdda26a7e, 0x3a59ff45, 0x3e350a44, 0xbcb4cdd5,
  3345. 0x72eacea8, 0xfa6484bb, 0x8d6612ae, 0xbf3c6f47,
  3346. 0xd29be463, 0x542f5d9e, 0xaec2771b, 0xf64e6370,
  3347. 0x740e0d8d, 0xe75b1357, 0xf8721671, 0xaf537d5d,
  3348. 0x4040cb08, 0x4eb4e2cc, 0x34d2466a, 0x0115af84,
  3349. 0xe1b00428, 0x95983a1d, 0x06b89fb4, 0xce6ea048,
  3350. 0x6f3f3b82, 0x3520ab82, 0x011a1d4b, 0x277227f8,
  3351. 0x611560b1, 0xe7933fdc, 0xbb3a792b, 0x344525bd,
  3352. 0xa08839e1, 0x51ce794b, 0x2f32c9b7, 0xa01fbac9,
  3353. 0xe01cc87e, 0xbcc7d1f6, 0xcf0111c3, 0xa1e8aac7,
  3354. 0x1a908749, 0xd44fbd9a, 0xd0dadecb, 0xd50ada38,
  3355. 0x0339c32a, 0xc6913667, 0x8df9317c, 0xe0b12b4f,
  3356. 0xf79e59b7, 0x43f5bb3a, 0xf2d519ff, 0x27d9459c,
  3357. 0xbf97222c, 0x15e6fc2a, 0x0f91fc71, 0x9b941525,
  3358. 0xfae59361, 0xceb69ceb, 0xc2a86459, 0x12baa8d1,
  3359. 0xb6c1075e, 0xe3056a0c, 0x10d25065, 0xcb03a442,
  3360. 0xe0ec6e0e, 0x1698db3b, 0x4c98a0be, 0x3278e964,
  3361. 0x9f1f9532, 0xe0d392df, 0xd3a0342b, 0x8971f21e,
  3362. 0x1b0a7441, 0x4ba3348c, 0xc5be7120, 0xc37632d8,
  3363. 0xdf359f8d, 0x9b992f2e, 0xe60b6f47, 0x0fe3f11d,
  3364. 0xe54cda54, 0x1edad891, 0xce6279cf, 0xcd3e7e6f,
  3365. 0x1618b166, 0xfd2c1d05, 0x848fd2c5, 0xf6fb2299,
  3366. 0xf523f357, 0xa6327623, 0x93a83531, 0x56cccd02,
  3367. 0xacf08162, 0x5a75ebb5, 0x6e163697, 0x88d273cc,
  3368. 0xde966292, 0x81b949d0, 0x4c50901b, 0x71c65614,
  3369. 0xe6c6c7bd, 0x327a140a, 0x45e1d006, 0xc3f27b9a,
  3370. 0xc9aa53fd, 0x62a80f00, 0xbb25bfe2, 0x35bdd2f6,
  3371. 0x71126905, 0xb2040222, 0xb6cbcf7c, 0xcd769c2b,
  3372. 0x53113ec0, 0x1640e3d3, 0x38abbd60, 0x2547adf0,
  3373. 0xba38209c, 0xf746ce76, 0x77afa1c5, 0x20756060,
  3374. 0x85cbfe4e, 0x8ae88dd8, 0x7aaaf9b0, 0x4cf9aa7e,
  3375. 0x1948c25c, 0x02fb8a8c, 0x01c36ae4, 0xd6ebe1f9,
  3376. 0x90d4f869, 0xa65cdea0, 0x3f09252d, 0xc208e69f,
  3377. 0xb74e6132, 0xce77e25b, 0x578fdfe3, 0x3ac372e6
  3378. };
  3379. BlowFish::BlowFish (const uint8* keyData, int keyBytes)
  3380. {
  3381. memcpy (p, initialPValues, sizeof (p));
  3382. int i, j;
  3383. for (i = 4; --i >= 0;)
  3384. {
  3385. s[i].malloc (256);
  3386. memcpy (s[i], initialSValues + i * 256, 256 * sizeof (uint32));
  3387. }
  3388. j = 0;
  3389. for (i = 0; i < 18; ++i)
  3390. {
  3391. uint32 d = 0;
  3392. for (int k = 0; k < 4; ++k)
  3393. {
  3394. d = (d << 8) | keyData[j];
  3395. if (++j >= keyBytes)
  3396. j = 0;
  3397. }
  3398. p[i] = initialPValues[i] ^ d;
  3399. }
  3400. uint32 l = 0, r = 0;
  3401. for (i = 0; i < 18; i += 2)
  3402. {
  3403. encrypt (l, r);
  3404. p[i] = l;
  3405. p[i + 1] = r;
  3406. }
  3407. for (i = 0; i < 4; ++i)
  3408. {
  3409. for (j = 0; j < 256; j += 2)
  3410. {
  3411. encrypt (l, r);
  3412. s[i][j] = l;
  3413. s[i][j + 1] = r;
  3414. }
  3415. }
  3416. }
  3417. BlowFish::BlowFish (const BlowFish& other)
  3418. {
  3419. for (int i = 4; --i >= 0;)
  3420. s[i].malloc (256);
  3421. operator= (other);
  3422. }
  3423. const BlowFish& BlowFish::operator= (const BlowFish& other)
  3424. {
  3425. memcpy (p, other.p, sizeof (p));
  3426. for (int i = 4; --i >= 0;)
  3427. memcpy (s[i], other.s[i], 256 * sizeof (uint32));
  3428. return *this;
  3429. }
  3430. BlowFish::~BlowFish()
  3431. {
  3432. }
  3433. uint32 BlowFish::F (uint32 x) const
  3434. {
  3435. uint16 a, b, c, d;
  3436. uint32 y;
  3437. d = (uint16) (x & 0xff);
  3438. x >>= 8;
  3439. c = (uint16) (x & 0xff);
  3440. x >>= 8;
  3441. b = (uint16) (x & 0xff);
  3442. x >>= 8;
  3443. a = (uint16) (x & 0xff);
  3444. y = s[0][a] + s[1][b];
  3445. y = y ^ s[2][c];
  3446. y = y + s[3][d];
  3447. return y;
  3448. }
  3449. void BlowFish::encrypt (uint32& data1,
  3450. uint32& data2) const
  3451. {
  3452. uint32 l = data1;
  3453. uint32 r = data2;
  3454. for (int i = 0; i < 16; ++i)
  3455. {
  3456. l = l ^ p[i];
  3457. r = F (l) ^ r;
  3458. const uint32 temp = l;
  3459. l = r;
  3460. r = temp;
  3461. }
  3462. const uint32 temp = l;
  3463. l = r;
  3464. r = temp;
  3465. r = r ^ p[16];
  3466. l = l ^ p[17];
  3467. data1 = l;
  3468. data2 = r;
  3469. }
  3470. void BlowFish::decrypt (uint32& data1,
  3471. uint32& data2) const
  3472. {
  3473. uint32 l = data1;
  3474. uint32 r = data2;
  3475. for (int i = 17; i > 1; --i)
  3476. {
  3477. l =l ^ p[i];
  3478. r = F (l) ^ r;
  3479. const uint32 temp = l;
  3480. l = r;
  3481. r = temp;
  3482. }
  3483. const uint32 temp = l;
  3484. l = r;
  3485. r = temp;
  3486. r = r ^ p[1];
  3487. l = l ^ p[0];
  3488. data1 = l;
  3489. data2 = r;
  3490. }
  3491. END_JUCE_NAMESPACE
  3492. /********* End of inlined file: juce_BlowFish.cpp *********/
  3493. /********* Start of inlined file: juce_MD5.cpp *********/
  3494. BEGIN_JUCE_NAMESPACE
  3495. MD5::MD5()
  3496. {
  3497. zeromem (result, sizeof (result));
  3498. }
  3499. MD5::MD5 (const MD5& other)
  3500. {
  3501. memcpy (result, other.result, sizeof (result));
  3502. }
  3503. const MD5& MD5::operator= (const MD5& other)
  3504. {
  3505. memcpy (result, other.result, sizeof (result));
  3506. return *this;
  3507. }
  3508. MD5::MD5 (const MemoryBlock& data)
  3509. {
  3510. ProcessContext context;
  3511. context.processBlock ((const uint8*) data.getData(), data.getSize());
  3512. context.finish (result);
  3513. }
  3514. MD5::MD5 (const char* data, const size_t numBytes)
  3515. {
  3516. ProcessContext context;
  3517. context.processBlock ((const uint8*) data, numBytes);
  3518. context.finish (result);
  3519. }
  3520. MD5::MD5 (const String& text)
  3521. {
  3522. ProcessContext context;
  3523. const int len = text.length();
  3524. const juce_wchar* const t = text;
  3525. for (int i = 0; i < len; ++i)
  3526. {
  3527. // force the string into integer-sized unicode characters, to try to make it
  3528. // get the same results on all platforms + compilers.
  3529. uint32 unicodeChar = (uint32) t[i];
  3530. ByteOrder::swapIfBigEndian (unicodeChar);
  3531. context.processBlock ((const uint8*) &unicodeChar,
  3532. sizeof (unicodeChar));
  3533. }
  3534. context.finish (result);
  3535. }
  3536. void MD5::processStream (InputStream& input, int64 numBytesToRead)
  3537. {
  3538. ProcessContext context;
  3539. if (numBytesToRead < 0)
  3540. numBytesToRead = INT_MAX;
  3541. while (numBytesToRead > 0)
  3542. {
  3543. char tempBuffer [512];
  3544. const int bytesRead = input.read (tempBuffer, (int) jmin (numBytesToRead, (int64) sizeof (tempBuffer)));
  3545. if (bytesRead <= 0)
  3546. break;
  3547. numBytesToRead -= bytesRead;
  3548. context.processBlock ((const uint8*) tempBuffer, bytesRead);
  3549. }
  3550. context.finish (result);
  3551. }
  3552. MD5::MD5 (InputStream& input, int64 numBytesToRead)
  3553. {
  3554. processStream (input, numBytesToRead);
  3555. }
  3556. MD5::MD5 (const File& file)
  3557. {
  3558. const ScopedPointer <FileInputStream> fin (file.createInputStream());
  3559. if (fin != 0)
  3560. processStream (*fin, -1);
  3561. else
  3562. zeromem (result, sizeof (result));
  3563. }
  3564. MD5::~MD5()
  3565. {
  3566. }
  3567. MD5::ProcessContext::ProcessContext()
  3568. {
  3569. state[0] = 0x67452301;
  3570. state[1] = 0xefcdab89;
  3571. state[2] = 0x98badcfe;
  3572. state[3] = 0x10325476;
  3573. count[0] = 0;
  3574. count[1] = 0;
  3575. }
  3576. void MD5::ProcessContext::processBlock (const uint8* const data, size_t dataSize)
  3577. {
  3578. int bufferPos = ((count[0] >> 3) & 0x3F);
  3579. count[0] += (uint32) (dataSize << 3);
  3580. if (count[0] < ((uint32) dataSize << 3))
  3581. count[1]++;
  3582. count[1] += (uint32) (dataSize >> 29);
  3583. const size_t spaceLeft = 64 - bufferPos;
  3584. size_t i = 0;
  3585. if (dataSize >= spaceLeft)
  3586. {
  3587. memcpy (buffer + bufferPos, data, spaceLeft);
  3588. transform (buffer);
  3589. i = spaceLeft;
  3590. while (i + 64 <= dataSize)
  3591. {
  3592. transform (data + i);
  3593. i += 64;
  3594. }
  3595. bufferPos = 0;
  3596. }
  3597. memcpy (buffer + bufferPos, data + i, dataSize - i);
  3598. }
  3599. static void encode (uint8* const output,
  3600. const uint32* const input,
  3601. const int numBytes)
  3602. {
  3603. uint32* const o = (uint32*) output;
  3604. for (int i = 0; i < (numBytes >> 2); ++i)
  3605. o[i] = ByteOrder::swapIfBigEndian (input [i]);
  3606. }
  3607. static void decode (uint32* const output,
  3608. const uint8* const input,
  3609. const int numBytes)
  3610. {
  3611. for (int i = 0; i < (numBytes >> 2); ++i)
  3612. output[i] = ByteOrder::littleEndianInt ((const char*) input + (i << 2));
  3613. }
  3614. void MD5::ProcessContext::finish (uint8* const result)
  3615. {
  3616. unsigned char encodedLength[8];
  3617. encode (encodedLength, count, 8);
  3618. // Pad out to 56 mod 64.
  3619. const int index = (uint32) ((count[0] >> 3) & 0x3f);
  3620. const int paddingLength = (index < 56) ? (56 - index)
  3621. : (120 - index);
  3622. uint8 paddingBuffer [64];
  3623. zeromem (paddingBuffer, paddingLength);
  3624. paddingBuffer [0] = 0x80;
  3625. processBlock (paddingBuffer, paddingLength);
  3626. processBlock (encodedLength, 8);
  3627. encode (result, state, 16);
  3628. zeromem (buffer, sizeof (buffer));
  3629. }
  3630. #define S11 7
  3631. #define S12 12
  3632. #define S13 17
  3633. #define S14 22
  3634. #define S21 5
  3635. #define S22 9
  3636. #define S23 14
  3637. #define S24 20
  3638. #define S31 4
  3639. #define S32 11
  3640. #define S33 16
  3641. #define S34 23
  3642. #define S41 6
  3643. #define S42 10
  3644. #define S43 15
  3645. #define S44 21
  3646. static inline uint32 F (const uint32 x, const uint32 y, const uint32 z) { return (x & y) | (~x & z); }
  3647. static inline uint32 G (const uint32 x, const uint32 y, const uint32 z) { return (x & z) | (y & ~z); }
  3648. static inline uint32 H (const uint32 x, const uint32 y, const uint32 z) { return x ^ y ^ z; }
  3649. static inline uint32 I (const uint32 x, const uint32 y, const uint32 z) { return y ^ (x | ~z); }
  3650. static inline uint32 rotateLeft (const uint32 x, const uint32 n) { return (x << n) | (x >> (32 - n)); }
  3651. static inline void FF (uint32& a, const uint32 b, const uint32 c, const uint32 d, const uint32 x, const uint32 s, const uint32 ac)
  3652. {
  3653. a += F (b, c, d) + x + ac;
  3654. a = rotateLeft (a, s) + b;
  3655. }
  3656. static inline void GG (uint32& a, const uint32 b, const uint32 c, const uint32 d, const uint32 x, const uint32 s, const uint32 ac)
  3657. {
  3658. a += G (b, c, d) + x + ac;
  3659. a = rotateLeft (a, s) + b;
  3660. }
  3661. static inline void HH (uint32& a, const uint32 b, const uint32 c, const uint32 d, const uint32 x, const uint32 s, const uint32 ac)
  3662. {
  3663. a += H (b, c, d) + x + ac;
  3664. a = rotateLeft (a, s) + b;
  3665. }
  3666. static inline void II (uint32& a, const uint32 b, const uint32 c, const uint32 d, const uint32 x, const uint32 s, const uint32 ac)
  3667. {
  3668. a += I (b, c, d) + x + ac;
  3669. a = rotateLeft (a, s) + b;
  3670. }
  3671. void MD5::ProcessContext::transform (const uint8* const bufferToTransform)
  3672. {
  3673. uint32 a = state[0];
  3674. uint32 b = state[1];
  3675. uint32 c = state[2];
  3676. uint32 d = state[3];
  3677. uint32 x[16];
  3678. decode (x, bufferToTransform, 64);
  3679. FF (a, b, c, d, x[ 0], S11, 0xd76aa478); /* 1 */
  3680. FF (d, a, b, c, x[ 1], S12, 0xe8c7b756); /* 2 */
  3681. FF (c, d, a, b, x[ 2], S13, 0x242070db); /* 3 */
  3682. FF (b, c, d, a, x[ 3], S14, 0xc1bdceee); /* 4 */
  3683. FF (a, b, c, d, x[ 4], S11, 0xf57c0faf); /* 5 */
  3684. FF (d, a, b, c, x[ 5], S12, 0x4787c62a); /* 6 */
  3685. FF (c, d, a, b, x[ 6], S13, 0xa8304613); /* 7 */
  3686. FF (b, c, d, a, x[ 7], S14, 0xfd469501); /* 8 */
  3687. FF (a, b, c, d, x[ 8], S11, 0x698098d8); /* 9 */
  3688. FF (d, a, b, c, x[ 9], S12, 0x8b44f7af); /* 10 */
  3689. FF (c, d, a, b, x[10], S13, 0xffff5bb1); /* 11 */
  3690. FF (b, c, d, a, x[11], S14, 0x895cd7be); /* 12 */
  3691. FF (a, b, c, d, x[12], S11, 0x6b901122); /* 13 */
  3692. FF (d, a, b, c, x[13], S12, 0xfd987193); /* 14 */
  3693. FF (c, d, a, b, x[14], S13, 0xa679438e); /* 15 */
  3694. FF (b, c, d, a, x[15], S14, 0x49b40821); /* 16 */
  3695. GG (a, b, c, d, x[ 1], S21, 0xf61e2562); /* 17 */
  3696. GG (d, a, b, c, x[ 6], S22, 0xc040b340); /* 18 */
  3697. GG (c, d, a, b, x[11], S23, 0x265e5a51); /* 19 */
  3698. GG (b, c, d, a, x[ 0], S24, 0xe9b6c7aa); /* 20 */
  3699. GG (a, b, c, d, x[ 5], S21, 0xd62f105d); /* 21 */
  3700. GG (d, a, b, c, x[10], S22, 0x2441453); /* 22 */
  3701. GG (c, d, a, b, x[15], S23, 0xd8a1e681); /* 23 */
  3702. GG (b, c, d, a, x[ 4], S24, 0xe7d3fbc8); /* 24 */
  3703. GG (a, b, c, d, x[ 9], S21, 0x21e1cde6); /* 25 */
  3704. GG (d, a, b, c, x[14], S22, 0xc33707d6); /* 26 */
  3705. GG (c, d, a, b, x[ 3], S23, 0xf4d50d87); /* 27 */
  3706. GG (b, c, d, a, x[ 8], S24, 0x455a14ed); /* 28 */
  3707. GG (a, b, c, d, x[13], S21, 0xa9e3e905); /* 29 */
  3708. GG (d, a, b, c, x[ 2], S22, 0xfcefa3f8); /* 30 */
  3709. GG (c, d, a, b, x[ 7], S23, 0x676f02d9); /* 31 */
  3710. GG (b, c, d, a, x[12], S24, 0x8d2a4c8a); /* 32 */
  3711. HH (a, b, c, d, x[ 5], S31, 0xfffa3942); /* 33 */
  3712. HH (d, a, b, c, x[ 8], S32, 0x8771f681); /* 34 */
  3713. HH (c, d, a, b, x[11], S33, 0x6d9d6122); /* 35 */
  3714. HH (b, c, d, a, x[14], S34, 0xfde5380c); /* 36 */
  3715. HH (a, b, c, d, x[ 1], S31, 0xa4beea44); /* 37 */
  3716. HH (d, a, b, c, x[ 4], S32, 0x4bdecfa9); /* 38 */
  3717. HH (c, d, a, b, x[ 7], S33, 0xf6bb4b60); /* 39 */
  3718. HH (b, c, d, a, x[10], S34, 0xbebfbc70); /* 40 */
  3719. HH (a, b, c, d, x[13], S31, 0x289b7ec6); /* 41 */
  3720. HH (d, a, b, c, x[ 0], S32, 0xeaa127fa); /* 42 */
  3721. HH (c, d, a, b, x[ 3], S33, 0xd4ef3085); /* 43 */
  3722. HH (b, c, d, a, x[ 6], S34, 0x4881d05); /* 44 */
  3723. HH (a, b, c, d, x[ 9], S31, 0xd9d4d039); /* 45 */
  3724. HH (d, a, b, c, x[12], S32, 0xe6db99e5); /* 46 */
  3725. HH (c, d, a, b, x[15], S33, 0x1fa27cf8); /* 47 */
  3726. HH (b, c, d, a, x[ 2], S34, 0xc4ac5665); /* 48 */
  3727. II (a, b, c, d, x[ 0], S41, 0xf4292244); /* 49 */
  3728. II (d, a, b, c, x[ 7], S42, 0x432aff97); /* 50 */
  3729. II (c, d, a, b, x[14], S43, 0xab9423a7); /* 51 */
  3730. II (b, c, d, a, x[ 5], S44, 0xfc93a039); /* 52 */
  3731. II (a, b, c, d, x[12], S41, 0x655b59c3); /* 53 */
  3732. II (d, a, b, c, x[ 3], S42, 0x8f0ccc92); /* 54 */
  3733. II (c, d, a, b, x[10], S43, 0xffeff47d); /* 55 */
  3734. II (b, c, d, a, x[ 1], S44, 0x85845dd1); /* 56 */
  3735. II (a, b, c, d, x[ 8], S41, 0x6fa87e4f); /* 57 */
  3736. II (d, a, b, c, x[15], S42, 0xfe2ce6e0); /* 58 */
  3737. II (c, d, a, b, x[ 6], S43, 0xa3014314); /* 59 */
  3738. II (b, c, d, a, x[13], S44, 0x4e0811a1); /* 60 */
  3739. II (a, b, c, d, x[ 4], S41, 0xf7537e82); /* 61 */
  3740. II (d, a, b, c, x[11], S42, 0xbd3af235); /* 62 */
  3741. II (c, d, a, b, x[ 2], S43, 0x2ad7d2bb); /* 63 */
  3742. II (b, c, d, a, x[ 9], S44, 0xeb86d391); /* 64 */
  3743. state[0] += a;
  3744. state[1] += b;
  3745. state[2] += c;
  3746. state[3] += d;
  3747. zeromem (x, sizeof (x));
  3748. }
  3749. const MemoryBlock MD5::getRawChecksumData() const
  3750. {
  3751. return MemoryBlock (result, 16);
  3752. }
  3753. const String MD5::toHexString() const
  3754. {
  3755. return String::toHexString (result, 16, 0);
  3756. }
  3757. bool MD5::operator== (const MD5& other) const
  3758. {
  3759. return memcmp (result, other.result, 16) == 0;
  3760. }
  3761. bool MD5::operator!= (const MD5& other) const
  3762. {
  3763. return ! operator== (other);
  3764. }
  3765. END_JUCE_NAMESPACE
  3766. /********* End of inlined file: juce_MD5.cpp *********/
  3767. /********* Start of inlined file: juce_Primes.cpp *********/
  3768. BEGIN_JUCE_NAMESPACE
  3769. static void createSmallSieve (const int numBits, BitArray& result) throw()
  3770. {
  3771. result.setBit (numBits);
  3772. result.clearBit (numBits); // to enlarge the array
  3773. result.setBit (0);
  3774. int n = 2;
  3775. do
  3776. {
  3777. for (int i = n + n; i < numBits; i += n)
  3778. result.setBit (i);
  3779. n = result.findNextClearBit (n + 1);
  3780. }
  3781. while (n <= (numBits >> 1));
  3782. }
  3783. static void bigSieve (const BitArray& base,
  3784. const int numBits,
  3785. BitArray& result,
  3786. const BitArray& smallSieve,
  3787. const int smallSieveSize) throw()
  3788. {
  3789. jassert (! base[0]); // must be even!
  3790. result.setBit (numBits);
  3791. result.clearBit (numBits); // to enlarge the array
  3792. int index = smallSieve.findNextClearBit (0);
  3793. do
  3794. {
  3795. const int prime = (index << 1) + 1;
  3796. BitArray r (base);
  3797. BitArray remainder;
  3798. r.divideBy (prime, remainder);
  3799. int i = prime - remainder.getBitRangeAsInt (0, 32);
  3800. if (r.isEmpty())
  3801. i += prime;
  3802. if ((i & 1) == 0)
  3803. i += prime;
  3804. i = (i - 1) >> 1;
  3805. while (i < numBits)
  3806. {
  3807. result.setBit (i);
  3808. i += prime;
  3809. }
  3810. index = smallSieve.findNextClearBit (index + 1);
  3811. }
  3812. while (index < smallSieveSize);
  3813. }
  3814. static bool findCandidate (const BitArray& base,
  3815. const BitArray& sieve,
  3816. const int numBits,
  3817. BitArray& result,
  3818. const int certainty) throw()
  3819. {
  3820. for (int i = 0; i < numBits; ++i)
  3821. {
  3822. if (! sieve[i])
  3823. {
  3824. result = base;
  3825. result.add (BitArray ((unsigned int) ((i << 1) + 1)));
  3826. if (Primes::isProbablyPrime (result, certainty))
  3827. return true;
  3828. }
  3829. }
  3830. return false;
  3831. }
  3832. const BitArray Primes::createProbablePrime (const int bitLength,
  3833. const int certainty,
  3834. const int* randomSeeds,
  3835. int numRandomSeeds) throw()
  3836. {
  3837. int defaultSeeds [16];
  3838. if (numRandomSeeds <= 0)
  3839. {
  3840. randomSeeds = defaultSeeds;
  3841. numRandomSeeds = numElementsInArray (defaultSeeds);
  3842. Random r (0);
  3843. for (int j = 10; --j >= 0;)
  3844. {
  3845. r.setSeedRandomly();
  3846. for (int i = numRandomSeeds; --i >= 0;)
  3847. defaultSeeds[i] ^= r.nextInt() ^ Random::getSystemRandom().nextInt();
  3848. }
  3849. }
  3850. BitArray smallSieve;
  3851. const int smallSieveSize = 15000;
  3852. createSmallSieve (smallSieveSize, smallSieve);
  3853. BitArray p;
  3854. for (int i = numRandomSeeds; --i >= 0;)
  3855. {
  3856. BitArray p2;
  3857. Random r (randomSeeds[i]);
  3858. r.fillBitsRandomly (p2, 0, bitLength);
  3859. p.xorWith (p2);
  3860. }
  3861. p.setBit (bitLength - 1);
  3862. p.clearBit (0);
  3863. const int searchLen = jmax (1024, (bitLength / 20) * 64);
  3864. while (p.getHighestBit() < bitLength)
  3865. {
  3866. p.add (2 * searchLen);
  3867. BitArray sieve;
  3868. bigSieve (p, searchLen, sieve,
  3869. smallSieve, smallSieveSize);
  3870. BitArray candidate;
  3871. if (findCandidate (p, sieve, searchLen, candidate, certainty))
  3872. return candidate;
  3873. }
  3874. jassertfalse
  3875. return BitArray();
  3876. }
  3877. static bool passesMillerRabin (const BitArray& n, int iterations) throw()
  3878. {
  3879. const BitArray one (1);
  3880. const BitArray two (2);
  3881. BitArray nMinusOne (n);
  3882. nMinusOne.subtract (one);
  3883. BitArray d (nMinusOne);
  3884. const int s = d.findNextSetBit (0);
  3885. d.shiftBits (-s);
  3886. BitArray smallPrimes;
  3887. int numBitsInSmallPrimes = 0;
  3888. for (;;)
  3889. {
  3890. numBitsInSmallPrimes += 256;
  3891. createSmallSieve (numBitsInSmallPrimes, smallPrimes);
  3892. const int numPrimesFound = numBitsInSmallPrimes - smallPrimes.countNumberOfSetBits();
  3893. if (numPrimesFound > iterations + 1)
  3894. break;
  3895. }
  3896. int smallPrime = 2;
  3897. while (--iterations >= 0)
  3898. {
  3899. smallPrime = smallPrimes.findNextClearBit (smallPrime + 1);
  3900. BitArray r (smallPrime);
  3901. //r.createRandomNumber (nMinusOne);
  3902. r.exponentModulo (d, n);
  3903. if (! (r == one || r == nMinusOne))
  3904. {
  3905. for (int j = 0; j < s; ++j)
  3906. {
  3907. r.exponentModulo (two, n);
  3908. if (r == nMinusOne)
  3909. break;
  3910. }
  3911. if (r != nMinusOne)
  3912. return false;
  3913. }
  3914. }
  3915. return true;
  3916. }
  3917. bool Primes::isProbablyPrime (const BitArray& number,
  3918. const int certainty) throw()
  3919. {
  3920. if (! number[0])
  3921. return false;
  3922. if (number.getHighestBit() <= 10)
  3923. {
  3924. const int num = number.getBitRangeAsInt (0, 10);
  3925. for (int i = num / 2; --i > 1;)
  3926. if (num % i == 0)
  3927. return false;
  3928. return true;
  3929. }
  3930. else
  3931. {
  3932. const BitArray screen (2 * 3 * 5 * 7 * 11 * 13 * 17 * 19 * 23);
  3933. if (number.findGreatestCommonDivisor (screen) != BitArray (1))
  3934. return false;
  3935. return passesMillerRabin (number, certainty);
  3936. }
  3937. }
  3938. END_JUCE_NAMESPACE
  3939. /********* End of inlined file: juce_Primes.cpp *********/
  3940. /********* Start of inlined file: juce_RSAKey.cpp *********/
  3941. BEGIN_JUCE_NAMESPACE
  3942. RSAKey::RSAKey() throw()
  3943. {
  3944. }
  3945. RSAKey::RSAKey (const String& s) throw()
  3946. {
  3947. if (s.containsChar (T(',')))
  3948. {
  3949. part1.parseString (s.upToFirstOccurrenceOf (T(","), false, false), 16);
  3950. part2.parseString (s.fromFirstOccurrenceOf (T(","), false, false), 16);
  3951. }
  3952. else
  3953. {
  3954. // the string needs to be two hex numbers, comma-separated..
  3955. jassertfalse;
  3956. }
  3957. }
  3958. RSAKey::~RSAKey() throw()
  3959. {
  3960. }
  3961. const String RSAKey::toString() const throw()
  3962. {
  3963. return part1.toString (16) + T(",") + part2.toString (16);
  3964. }
  3965. bool RSAKey::applyToValue (BitArray& value) const throw()
  3966. {
  3967. if (part1.isEmpty() || part2.isEmpty()
  3968. || value.compare (0) <= 0)
  3969. {
  3970. jassertfalse // using an uninitialised key
  3971. value.clear();
  3972. return false;
  3973. }
  3974. BitArray result;
  3975. while (! value.isEmpty())
  3976. {
  3977. result.multiplyBy (part2);
  3978. BitArray remainder;
  3979. value.divideBy (part2, remainder);
  3980. remainder.exponentModulo (part1, part2);
  3981. result.add (remainder);
  3982. }
  3983. value = result;
  3984. return true;
  3985. }
  3986. static const BitArray findBestCommonDivisor (const BitArray& p,
  3987. const BitArray& q) throw()
  3988. {
  3989. const BitArray one (1);
  3990. // try 3, 5, 9, 17, etc first because these only contain 2 bits and so
  3991. // are fast to divide + multiply
  3992. for (int i = 2; i <= 65536; i *= 2)
  3993. {
  3994. const BitArray e (1 + i);
  3995. if (e.findGreatestCommonDivisor (p) == one
  3996. && e.findGreatestCommonDivisor (q) == one)
  3997. {
  3998. return e;
  3999. }
  4000. }
  4001. BitArray e (4);
  4002. while (! (e.findGreatestCommonDivisor (p) == one
  4003. && e.findGreatestCommonDivisor (q) == one))
  4004. {
  4005. e.add (one);
  4006. }
  4007. return e;
  4008. }
  4009. void RSAKey::createKeyPair (RSAKey& publicKey,
  4010. RSAKey& privateKey,
  4011. const int numBits,
  4012. const int* randomSeeds,
  4013. const int numRandomSeeds) throw()
  4014. {
  4015. jassert (numBits > 16); // not much point using less than this..
  4016. BitArray p (Primes::createProbablePrime (numBits / 2, 30, randomSeeds, numRandomSeeds));
  4017. BitArray q (Primes::createProbablePrime (numBits - numBits / 2, 30, randomSeeds, numRandomSeeds));
  4018. BitArray n (p);
  4019. n.multiplyBy (q); // n = pq
  4020. const BitArray one (1);
  4021. p.subtract (one);
  4022. q.subtract (one);
  4023. BitArray m (p);
  4024. m.multiplyBy (q); // m = (p - 1)(q - 1)
  4025. const BitArray e (findBestCommonDivisor (p, q));
  4026. BitArray d (e);
  4027. d.inverseModulo (m);
  4028. publicKey.part1 = e;
  4029. publicKey.part2 = n;
  4030. privateKey.part1 = d;
  4031. privateKey.part2 = n;
  4032. }
  4033. END_JUCE_NAMESPACE
  4034. /********* End of inlined file: juce_RSAKey.cpp *********/
  4035. /********* Start of inlined file: juce_InputStream.cpp *********/
  4036. BEGIN_JUCE_NAMESPACE
  4037. char InputStream::readByte()
  4038. {
  4039. char temp = 0;
  4040. read (&temp, 1);
  4041. return temp;
  4042. }
  4043. bool InputStream::readBool()
  4044. {
  4045. return readByte() != 0;
  4046. }
  4047. short InputStream::readShort()
  4048. {
  4049. char temp [2];
  4050. if (read (temp, 2) == 2)
  4051. return (short) ByteOrder::littleEndianShort (temp);
  4052. else
  4053. return 0;
  4054. }
  4055. short InputStream::readShortBigEndian()
  4056. {
  4057. char temp [2];
  4058. if (read (temp, 2) == 2)
  4059. return (short) ByteOrder::bigEndianShort (temp);
  4060. else
  4061. return 0;
  4062. }
  4063. int InputStream::readInt()
  4064. {
  4065. char temp [4];
  4066. if (read (temp, 4) == 4)
  4067. return (int) ByteOrder::littleEndianInt (temp);
  4068. else
  4069. return 0;
  4070. }
  4071. int InputStream::readIntBigEndian()
  4072. {
  4073. char temp [4];
  4074. if (read (temp, 4) == 4)
  4075. return (int) ByteOrder::bigEndianInt (temp);
  4076. else
  4077. return 0;
  4078. }
  4079. int InputStream::readCompressedInt()
  4080. {
  4081. const unsigned char sizeByte = readByte();
  4082. if (sizeByte == 0)
  4083. return 0;
  4084. const int numBytes = (sizeByte & 0x7f);
  4085. if (numBytes > 4)
  4086. {
  4087. jassertfalse // trying to read corrupt data - this method must only be used
  4088. // to read data that was written by OutputStream::writeCompressedInt()
  4089. return 0;
  4090. }
  4091. char bytes[4] = { 0, 0, 0, 0 };
  4092. if (read (bytes, numBytes) != numBytes)
  4093. return 0;
  4094. const int num = (int) ByteOrder::littleEndianInt (bytes);
  4095. return (sizeByte >> 7) ? -num : num;
  4096. }
  4097. int64 InputStream::readInt64()
  4098. {
  4099. char temp [8];
  4100. if (read (temp, 8) == 8)
  4101. return (int64) ByteOrder::swapIfBigEndian (*(uint64*) temp);
  4102. else
  4103. return 0;
  4104. }
  4105. int64 InputStream::readInt64BigEndian()
  4106. {
  4107. char temp [8];
  4108. if (read (temp, 8) == 8)
  4109. return (int64) ByteOrder::swapIfLittleEndian (*(uint64*) temp);
  4110. else
  4111. return 0;
  4112. }
  4113. float InputStream::readFloat()
  4114. {
  4115. union { int asInt; float asFloat; } n;
  4116. n.asInt = readInt();
  4117. return n.asFloat;
  4118. }
  4119. float InputStream::readFloatBigEndian()
  4120. {
  4121. union { int asInt; float asFloat; } n;
  4122. n.asInt = readIntBigEndian();
  4123. return n.asFloat;
  4124. }
  4125. double InputStream::readDouble()
  4126. {
  4127. union { int64 asInt; double asDouble; } n;
  4128. n.asInt = readInt64();
  4129. return n.asDouble;
  4130. }
  4131. double InputStream::readDoubleBigEndian()
  4132. {
  4133. union { int64 asInt; double asDouble; } n;
  4134. n.asInt = readInt64BigEndian();
  4135. return n.asDouble;
  4136. }
  4137. const String InputStream::readString()
  4138. {
  4139. MemoryBlock buffer (256);
  4140. uint8* data = (uint8*) buffer.getData();
  4141. size_t i = 0;
  4142. while ((data[i] = readByte()) != 0)
  4143. {
  4144. if (++i >= buffer.getSize())
  4145. {
  4146. buffer.setSize (buffer.getSize() + 512);
  4147. data = (uint8*) buffer.getData();
  4148. }
  4149. }
  4150. return String::fromUTF8 (data, (int) i);
  4151. }
  4152. const String InputStream::readNextLine()
  4153. {
  4154. MemoryBlock buffer (256);
  4155. uint8* data = (uint8*) buffer.getData();
  4156. size_t i = 0;
  4157. while ((data[i] = readByte()) != 0)
  4158. {
  4159. if (data[i] == '\n')
  4160. break;
  4161. if (data[i] == '\r')
  4162. {
  4163. const int64 lastPos = getPosition();
  4164. if (readByte() != '\n')
  4165. setPosition (lastPos);
  4166. break;
  4167. }
  4168. if (++i >= buffer.getSize())
  4169. {
  4170. buffer.setSize (buffer.getSize() + 512);
  4171. data = (uint8*) buffer.getData();
  4172. }
  4173. }
  4174. return String::fromUTF8 (data, (int) i);
  4175. }
  4176. int InputStream::readIntoMemoryBlock (MemoryBlock& block,
  4177. int numBytes)
  4178. {
  4179. const int64 totalLength = getTotalLength();
  4180. if (totalLength >= 0)
  4181. {
  4182. const int totalBytesRemaining = (int) jmin ((int64) 0x7fffffff,
  4183. totalLength - getPosition());
  4184. if (numBytes < 0)
  4185. numBytes = totalBytesRemaining;
  4186. else if (numBytes > 0)
  4187. numBytes = jmin (numBytes, totalBytesRemaining);
  4188. else
  4189. return 0;
  4190. }
  4191. const size_t originalBlockSize = block.getSize();
  4192. int totalBytesRead = 0;
  4193. if (numBytes > 0)
  4194. {
  4195. // know how many bytes we want, so we can resize the block first..
  4196. block.setSize (originalBlockSize + numBytes, false);
  4197. totalBytesRead = read (((char*) block.getData()) + originalBlockSize, numBytes);
  4198. }
  4199. else
  4200. {
  4201. // read until end of stram..
  4202. const int chunkSize = 32768;
  4203. for (;;)
  4204. {
  4205. block.ensureSize (originalBlockSize + totalBytesRead + chunkSize, false);
  4206. const int bytesJustIn = read (((char*) block.getData())
  4207. + originalBlockSize
  4208. + totalBytesRead,
  4209. chunkSize);
  4210. if (bytesJustIn == 0)
  4211. break;
  4212. totalBytesRead += bytesJustIn;
  4213. }
  4214. }
  4215. // trim off any excess left at the end
  4216. block.setSize (originalBlockSize + totalBytesRead, false);
  4217. return totalBytesRead;
  4218. }
  4219. const String InputStream::readEntireStreamAsString()
  4220. {
  4221. MemoryBlock mb;
  4222. const int size = readIntoMemoryBlock (mb);
  4223. return String::createStringFromData ((const char*) mb.getData(), size);
  4224. }
  4225. void InputStream::skipNextBytes (int64 numBytesToSkip)
  4226. {
  4227. if (numBytesToSkip > 0)
  4228. {
  4229. const int skipBufferSize = (int) jmin (numBytesToSkip, (int64) 16384);
  4230. HeapBlock <char> temp (skipBufferSize);
  4231. while (numBytesToSkip > 0 && ! isExhausted())
  4232. numBytesToSkip -= read (temp, (int) jmin (numBytesToSkip, (int64) skipBufferSize));
  4233. }
  4234. }
  4235. END_JUCE_NAMESPACE
  4236. /********* End of inlined file: juce_InputStream.cpp *********/
  4237. /********* Start of inlined file: juce_OutputStream.cpp *********/
  4238. BEGIN_JUCE_NAMESPACE
  4239. #if JUCE_DEBUG
  4240. static CriticalSection activeStreamLock;
  4241. static VoidArray activeStreams;
  4242. void juce_CheckForDanglingStreams()
  4243. {
  4244. /*
  4245. It's always a bad idea to leak any object, but if you're leaking output
  4246. streams, then there's a good chance that you're failing to flush a file
  4247. to disk properly, which could result in corrupted data and other similar
  4248. nastiness..
  4249. */
  4250. jassert (activeStreams.size() == 0);
  4251. };
  4252. #endif
  4253. OutputStream::OutputStream() throw()
  4254. {
  4255. #if JUCE_DEBUG
  4256. activeStreamLock.enter();
  4257. activeStreams.add (this);
  4258. activeStreamLock.exit();
  4259. #endif
  4260. }
  4261. OutputStream::~OutputStream()
  4262. {
  4263. #if JUCE_DEBUG
  4264. activeStreamLock.enter();
  4265. activeStreams.removeValue (this);
  4266. activeStreamLock.exit();
  4267. #endif
  4268. }
  4269. void OutputStream::writeBool (bool b)
  4270. {
  4271. writeByte ((b) ? (char) 1
  4272. : (char) 0);
  4273. }
  4274. void OutputStream::writeByte (char byte)
  4275. {
  4276. write (&byte, 1);
  4277. }
  4278. void OutputStream::writeShort (short value)
  4279. {
  4280. const unsigned short v = ByteOrder::swapIfBigEndian ((unsigned short) value);
  4281. write (&v, 2);
  4282. }
  4283. void OutputStream::writeShortBigEndian (short value)
  4284. {
  4285. const unsigned short v = ByteOrder::swapIfLittleEndian ((unsigned short) value);
  4286. write (&v, 2);
  4287. }
  4288. void OutputStream::writeInt (int value)
  4289. {
  4290. const unsigned int v = ByteOrder::swapIfBigEndian ((unsigned int) value);
  4291. write (&v, 4);
  4292. }
  4293. void OutputStream::writeIntBigEndian (int value)
  4294. {
  4295. const unsigned int v = ByteOrder::swapIfLittleEndian ((unsigned int) value);
  4296. write (&v, 4);
  4297. }
  4298. void OutputStream::writeCompressedInt (int value)
  4299. {
  4300. unsigned int un = (value < 0) ? (unsigned int) -value
  4301. : (unsigned int) value;
  4302. uint8 data[5];
  4303. int num = 0;
  4304. while (un > 0)
  4305. {
  4306. data[++num] = (uint8) un;
  4307. un >>= 8;
  4308. }
  4309. data[0] = (uint8) num;
  4310. if (value < 0)
  4311. data[0] |= 0x80;
  4312. write (data, num + 1);
  4313. }
  4314. void OutputStream::writeInt64 (int64 value)
  4315. {
  4316. const uint64 v = ByteOrder::swapIfBigEndian ((uint64) value);
  4317. write (&v, 8);
  4318. }
  4319. void OutputStream::writeInt64BigEndian (int64 value)
  4320. {
  4321. const uint64 v = ByteOrder::swapIfLittleEndian ((uint64) value);
  4322. write (&v, 8);
  4323. }
  4324. void OutputStream::writeFloat (float value)
  4325. {
  4326. union { int asInt; float asFloat; } n;
  4327. n.asFloat = value;
  4328. writeInt (n.asInt);
  4329. }
  4330. void OutputStream::writeFloatBigEndian (float value)
  4331. {
  4332. union { int asInt; float asFloat; } n;
  4333. n.asFloat = value;
  4334. writeIntBigEndian (n.asInt);
  4335. }
  4336. void OutputStream::writeDouble (double value)
  4337. {
  4338. union { int64 asInt; double asDouble; } n;
  4339. n.asDouble = value;
  4340. writeInt64 (n.asInt);
  4341. }
  4342. void OutputStream::writeDoubleBigEndian (double value)
  4343. {
  4344. union { int64 asInt; double asDouble; } n;
  4345. n.asDouble = value;
  4346. writeInt64BigEndian (n.asInt);
  4347. }
  4348. void OutputStream::writeString (const String& text)
  4349. {
  4350. const int numBytes = text.copyToUTF8 (0);
  4351. HeapBlock <uint8> temp (numBytes);
  4352. text.copyToUTF8 (temp);
  4353. write (temp, numBytes); // (numBytes includes the terminating null).
  4354. }
  4355. void OutputStream::printf (const char* pf, ...)
  4356. {
  4357. unsigned int bufSize = 256;
  4358. HeapBlock <char> buf (bufSize);
  4359. for (;;)
  4360. {
  4361. va_list list;
  4362. va_start (list, pf);
  4363. const int num = CharacterFunctions::vprintf (buf, bufSize, pf, list);
  4364. va_end (list);
  4365. if (num > 0)
  4366. {
  4367. write (buf, num);
  4368. break;
  4369. }
  4370. else if (num == 0)
  4371. {
  4372. break;
  4373. }
  4374. bufSize += 256;
  4375. buf.malloc (bufSize);
  4376. }
  4377. }
  4378. OutputStream& OutputStream::operator<< (const int number)
  4379. {
  4380. const String s (number);
  4381. write ((const char*) s, s.length());
  4382. return *this;
  4383. }
  4384. OutputStream& OutputStream::operator<< (const double number)
  4385. {
  4386. const String s (number);
  4387. write ((const char*) s, s.length());
  4388. return *this;
  4389. }
  4390. OutputStream& OutputStream::operator<< (const char character)
  4391. {
  4392. writeByte (character);
  4393. return *this;
  4394. }
  4395. OutputStream& OutputStream::operator<< (const char* const text)
  4396. {
  4397. write (text, (int) strlen (text));
  4398. return *this;
  4399. }
  4400. OutputStream& OutputStream::operator<< (const juce_wchar* const text)
  4401. {
  4402. const String s (text);
  4403. write ((const char*) s, s.length());
  4404. return *this;
  4405. }
  4406. OutputStream& OutputStream::operator<< (const String& text)
  4407. {
  4408. write ((const char*) text,
  4409. text.length());
  4410. return *this;
  4411. }
  4412. void OutputStream::writeText (const String& text,
  4413. const bool asUnicode,
  4414. const bool writeUnicodeHeaderBytes)
  4415. {
  4416. if (asUnicode)
  4417. {
  4418. if (writeUnicodeHeaderBytes)
  4419. write ("\x0ff\x0fe", 2);
  4420. const juce_wchar* src = (const juce_wchar*) text;
  4421. bool lastCharWasReturn = false;
  4422. while (*src != 0)
  4423. {
  4424. if (*src == L'\n' && ! lastCharWasReturn)
  4425. writeShort ((short) L'\r');
  4426. lastCharWasReturn = (*src == L'\r');
  4427. writeShort ((short) *src++);
  4428. }
  4429. }
  4430. else
  4431. {
  4432. const char* src = (const char*) text;
  4433. const char* t = src;
  4434. for (;;)
  4435. {
  4436. if (*t == '\n')
  4437. {
  4438. if (t > src)
  4439. write (src, (int) (t - src));
  4440. write ("\r\n", 2);
  4441. src = t + 1;
  4442. }
  4443. else if (*t == '\r')
  4444. {
  4445. if (t[1] == '\n')
  4446. ++t;
  4447. }
  4448. else if (*t == 0)
  4449. {
  4450. if (t > src)
  4451. write (src, (int) (t - src));
  4452. break;
  4453. }
  4454. ++t;
  4455. }
  4456. }
  4457. }
  4458. int OutputStream::writeFromInputStream (InputStream& source,
  4459. int numBytesToWrite)
  4460. {
  4461. if (numBytesToWrite < 0)
  4462. numBytesToWrite = 0x7fffffff;
  4463. int numWritten = 0;
  4464. while (numBytesToWrite > 0 && ! source.isExhausted())
  4465. {
  4466. char buffer [8192];
  4467. const int num = source.read (buffer, (int) jmin ((size_t) numBytesToWrite, sizeof (buffer)));
  4468. if (num == 0)
  4469. break;
  4470. write (buffer, num);
  4471. numBytesToWrite -= num;
  4472. numWritten += num;
  4473. }
  4474. return numWritten;
  4475. }
  4476. END_JUCE_NAMESPACE
  4477. /********* End of inlined file: juce_OutputStream.cpp *********/
  4478. /********* Start of inlined file: juce_DirectoryIterator.cpp *********/
  4479. BEGIN_JUCE_NAMESPACE
  4480. void* juce_findFileStart (const String& directory, const String& wildCard, String& firstResultFile,
  4481. bool* isDirectory, bool* isHidden, int64* fileSize,
  4482. Time* modTime, Time* creationTime, bool* isReadOnly);
  4483. bool juce_findFileNext (void* handle, String& resultFile,
  4484. bool* isDirectory, bool* isHidden, int64* fileSize,
  4485. Time* modTime, Time* creationTime, bool* isReadOnly);
  4486. void juce_findFileClose (void* handle);
  4487. DirectoryIterator::DirectoryIterator (const File& directory,
  4488. bool isRecursive,
  4489. const String& wc,
  4490. const int whatToLookFor_)
  4491. : wildCard (wc),
  4492. index (-1),
  4493. whatToLookFor (whatToLookFor_)
  4494. {
  4495. // you have to specify the type of files you're looking for!
  4496. jassert ((whatToLookFor_ & (File::findFiles | File::findDirectories)) != 0);
  4497. jassert (whatToLookFor_ > 0 && whatToLookFor_ <= 7);
  4498. String path (directory.getFullPathName());
  4499. if (! path.endsWithChar (File::separator))
  4500. path += File::separator;
  4501. String filename;
  4502. bool isDirectory, isHidden;
  4503. void* const handle = juce_findFileStart (path,
  4504. isRecursive ? T("*") : wc,
  4505. filename, &isDirectory, &isHidden, 0, 0, 0, 0);
  4506. if (handle != 0)
  4507. {
  4508. do
  4509. {
  4510. if (! filename.containsOnly (T(".")))
  4511. {
  4512. bool addToList = false;
  4513. if (isDirectory)
  4514. {
  4515. if (isRecursive
  4516. && ((whatToLookFor_ & File::ignoreHiddenFiles) == 0
  4517. || ! isHidden))
  4518. {
  4519. dirsFound.add (File (path + filename, 0));
  4520. }
  4521. addToList = (whatToLookFor_ & File::findDirectories) != 0;
  4522. }
  4523. else
  4524. {
  4525. addToList = (whatToLookFor_ & File::findFiles) != 0;
  4526. }
  4527. // if it's recursive, we're not relying on the OS iterator
  4528. // to do the wildcard match, so do it now..
  4529. if (isRecursive && addToList)
  4530. addToList = filename.matchesWildcard (wc, true);
  4531. if (addToList && (whatToLookFor_ & File::ignoreHiddenFiles) != 0)
  4532. addToList = ! isHidden;
  4533. if (addToList)
  4534. filesFound.add (File (path + filename, 0));
  4535. }
  4536. } while (juce_findFileNext (handle, filename, &isDirectory, &isHidden, 0, 0, 0, 0));
  4537. juce_findFileClose (handle);
  4538. }
  4539. }
  4540. DirectoryIterator::~DirectoryIterator()
  4541. {
  4542. }
  4543. bool DirectoryIterator::next()
  4544. {
  4545. if (subIterator != 0)
  4546. {
  4547. if (subIterator->next())
  4548. return true;
  4549. subIterator = 0;
  4550. }
  4551. if (index >= filesFound.size() + dirsFound.size() - 1)
  4552. return false;
  4553. ++index;
  4554. if (index >= filesFound.size())
  4555. {
  4556. subIterator = new DirectoryIterator (dirsFound.getReference (index - filesFound.size()),
  4557. true, wildCard, whatToLookFor);
  4558. return next();
  4559. }
  4560. return true;
  4561. }
  4562. const File DirectoryIterator::getFile() const
  4563. {
  4564. if (subIterator != 0)
  4565. return subIterator->getFile();
  4566. return filesFound [index];
  4567. }
  4568. float DirectoryIterator::getEstimatedProgress() const
  4569. {
  4570. if (filesFound.size() + dirsFound.size() == 0)
  4571. {
  4572. return 0.0f;
  4573. }
  4574. else
  4575. {
  4576. const float detailedIndex = (subIterator != 0) ? index + subIterator->getEstimatedProgress()
  4577. : (float) index;
  4578. return detailedIndex / (filesFound.size() + dirsFound.size());
  4579. }
  4580. }
  4581. END_JUCE_NAMESPACE
  4582. /********* End of inlined file: juce_DirectoryIterator.cpp *********/
  4583. /********* Start of inlined file: juce_File.cpp *********/
  4584. #ifdef _MSC_VER
  4585. #pragma warning (disable: 4514)
  4586. #pragma warning (push)
  4587. #endif
  4588. #if ! JUCE_WINDOWS
  4589. #include <pwd.h>
  4590. #endif
  4591. BEGIN_JUCE_NAMESPACE
  4592. #ifdef _MSC_VER
  4593. #pragma warning (pop)
  4594. #endif
  4595. void* juce_fileOpen (const String& path, bool forWriting);
  4596. void juce_fileClose (void* handle);
  4597. int juce_fileWrite (void* handle, const void* buffer, int size);
  4598. int64 juce_fileGetPosition (void* handle);
  4599. int64 juce_fileSetPosition (void* handle, int64 pos);
  4600. void juce_fileFlush (void* handle);
  4601. bool juce_fileExists (const String& fileName, const bool dontCountDirectories);
  4602. bool juce_isDirectory (const String& fileName);
  4603. int64 juce_getFileSize (const String& fileName);
  4604. bool juce_canWriteToFile (const String& fileName);
  4605. bool juce_setFileReadOnly (const String& fileName, bool isReadOnly);
  4606. void juce_getFileTimes (const String& fileName, int64& modificationTime, int64& accessTime, int64& creationTime);
  4607. bool juce_setFileTimes (const String& fileName, int64 modificationTime, int64 accessTime, int64 creationTime);
  4608. bool juce_deleteFile (const String& fileName);
  4609. bool juce_copyFile (const String& source, const String& dest);
  4610. bool juce_moveFile (const String& source, const String& dest);
  4611. // this must also create all paths involved in the directory.
  4612. void juce_createDirectory (const String& fileName);
  4613. bool juce_launchFile (const String& fileName, const String& parameters);
  4614. const StringArray juce_getFileSystemRoots();
  4615. const String juce_getVolumeLabel (const String& filenameOnVolume, int& volumeSerialNumber);
  4616. // starts a directory search operation with a wildcard, returning a handle for
  4617. // use in calls to juce_findFileNext.
  4618. // juce_firstResultFile gets the name of the file (not the whole pathname) and
  4619. // the other pointers, if non-null, are set based on the properties of the file.
  4620. void* juce_findFileStart (const String& directory, const String& wildCard, String& firstResultFile,
  4621. bool* isDirectory, bool* isHidden, int64* fileSize, Time* modTime,
  4622. Time* creationTime, bool* isReadOnly);
  4623. // returns false when no more files are found
  4624. bool juce_findFileNext (void* handle, String& resultFile,
  4625. bool* isDirectory, bool* isHidden, int64* fileSize,
  4626. Time* modTime, Time* creationTime, bool* isReadOnly);
  4627. void juce_findFileClose (void* handle);
  4628. static const String juce_addTrailingSeparator (const String& path)
  4629. {
  4630. return path.endsWithChar (File::separator) ? path
  4631. : path + File::separator;
  4632. }
  4633. static const String parseAbsolutePath (String path)
  4634. {
  4635. if (path.isEmpty())
  4636. return String::empty;
  4637. #if JUCE_WINDOWS
  4638. // Windows..
  4639. path = path.replaceCharacter (T('/'), T('\\'));
  4640. if (path.startsWithChar (File::separator))
  4641. {
  4642. if (path[1] != File::separator)
  4643. {
  4644. jassertfalse // using a filename that starts with a slash is a bit dodgy on
  4645. // Windows, because it needs a drive letter, which in this case
  4646. // we'll take from the CWD.. but this is a bit of an assumption that
  4647. // could be wrong..
  4648. path = File::getCurrentWorkingDirectory().getFullPathName().substring (0, 2) + path;
  4649. }
  4650. }
  4651. else if (path.indexOfChar (T(':')) < 0)
  4652. {
  4653. if (path.isEmpty())
  4654. return String::empty;
  4655. jassertfalse // using a partial filename is a bad way to initialise a file, because
  4656. // we don't know what directory to put it in.
  4657. // Here we'll assume it's in the CWD, but this might not be what was
  4658. // intended..
  4659. return File::getCurrentWorkingDirectory().getChildFile (path).getFullPathName();
  4660. }
  4661. #else
  4662. // Mac or Linux..
  4663. path = path.replaceCharacter (T('\\'), T('/'));
  4664. if (path.startsWithChar (T('~')))
  4665. {
  4666. const char* homeDir = 0;
  4667. if (path[1] == File::separator || path[1] == 0)
  4668. {
  4669. // expand a name of the form "~/abc"
  4670. path = File::getSpecialLocation (File::userHomeDirectory).getFullPathName()
  4671. + path.substring (1);
  4672. }
  4673. else
  4674. {
  4675. // expand a name of type "~dave/abc"
  4676. const String userName (path.substring (1)
  4677. .upToFirstOccurrenceOf (T("/"), false, false));
  4678. struct passwd* const pw = getpwnam (userName);
  4679. if (pw != 0)
  4680. {
  4681. String home (homeDir);
  4682. if (home.endsWithChar (File::separator))
  4683. home [home.length() - 1] = 0;
  4684. path = String (pw->pw_dir)
  4685. + path.substring (userName.length());
  4686. }
  4687. }
  4688. }
  4689. else if (! path.startsWithChar (File::separator))
  4690. {
  4691. while (path.startsWith (T("./")))
  4692. path = path.substring (2);
  4693. if (path.isEmpty())
  4694. return String::empty;
  4695. jassertfalse // using a partial filename is a bad way to initialise a file, because
  4696. // we don't know what directory to put it in.
  4697. // Here we'll assume it's in the CWD, but this might not be what was
  4698. // intended..
  4699. return File::getCurrentWorkingDirectory().getChildFile (path).getFullPathName();
  4700. }
  4701. #endif
  4702. int len = path.length();
  4703. while (--len > 0 && path [len] == File::separator)
  4704. path [len] = 0;
  4705. return path;
  4706. }
  4707. const File File::nonexistent;
  4708. File::File (const String& fullPathName)
  4709. : fullPath (parseAbsolutePath (fullPathName))
  4710. {
  4711. }
  4712. File::File (const String& path, int)
  4713. : fullPath (path)
  4714. {
  4715. }
  4716. File::File (const File& other)
  4717. : fullPath (other.fullPath)
  4718. {
  4719. }
  4720. const File& File::operator= (const String& newPath)
  4721. {
  4722. fullPath = parseAbsolutePath (newPath);
  4723. return *this;
  4724. }
  4725. const File& File::operator= (const File& other)
  4726. {
  4727. fullPath = other.fullPath;
  4728. return *this;
  4729. }
  4730. #if JUCE_LINUX
  4731. #define NAMES_ARE_CASE_SENSITIVE 1
  4732. #endif
  4733. bool File::areFileNamesCaseSensitive()
  4734. {
  4735. #if NAMES_ARE_CASE_SENSITIVE
  4736. return true;
  4737. #else
  4738. return false;
  4739. #endif
  4740. }
  4741. bool File::operator== (const File& other) const
  4742. {
  4743. // case-insensitive on Windows, but not on linux.
  4744. #if NAMES_ARE_CASE_SENSITIVE
  4745. return fullPath == other.fullPath;
  4746. #else
  4747. return fullPath.equalsIgnoreCase (other.fullPath);
  4748. #endif
  4749. }
  4750. bool File::operator!= (const File& other) const
  4751. {
  4752. return ! operator== (other);
  4753. }
  4754. bool File::exists() const
  4755. {
  4756. return juce_fileExists (fullPath, false);
  4757. }
  4758. bool File::existsAsFile() const
  4759. {
  4760. return juce_fileExists (fullPath, true);
  4761. }
  4762. bool File::isDirectory() const
  4763. {
  4764. return juce_isDirectory (fullPath);
  4765. }
  4766. bool File::hasWriteAccess() const
  4767. {
  4768. if (exists())
  4769. return juce_canWriteToFile (fullPath);
  4770. #if ! JUCE_WINDOWS
  4771. else if ((! isDirectory()) && fullPath.containsChar (separator))
  4772. return getParentDirectory().hasWriteAccess();
  4773. else
  4774. return false;
  4775. #else
  4776. // on windows, it seems that even read-only directories can still be written into,
  4777. // so checking the parent directory's permissions would return the wrong result..
  4778. else
  4779. return true;
  4780. #endif
  4781. }
  4782. bool File::setReadOnly (const bool shouldBeReadOnly,
  4783. const bool applyRecursively) const
  4784. {
  4785. bool worked = true;
  4786. if (applyRecursively && isDirectory())
  4787. {
  4788. Array <File> subFiles;
  4789. findChildFiles (subFiles, File::findFilesAndDirectories, false);
  4790. for (int i = subFiles.size(); --i >= 0;)
  4791. worked = subFiles.getReference(i).setReadOnly (shouldBeReadOnly, true) && worked;
  4792. }
  4793. return juce_setFileReadOnly (fullPath, shouldBeReadOnly) && worked;
  4794. }
  4795. bool File::deleteFile() const
  4796. {
  4797. return (! exists())
  4798. || juce_deleteFile (fullPath);
  4799. }
  4800. bool File::deleteRecursively() const
  4801. {
  4802. bool worked = true;
  4803. if (isDirectory())
  4804. {
  4805. Array<File> subFiles;
  4806. findChildFiles (subFiles, File::findFilesAndDirectories, false);
  4807. for (int i = subFiles.size(); --i >= 0;)
  4808. worked = subFiles.getReference(i).deleteRecursively() && worked;
  4809. }
  4810. return deleteFile() && worked;
  4811. }
  4812. bool File::moveFileTo (const File& newFile) const
  4813. {
  4814. if (newFile.fullPath == fullPath)
  4815. return true;
  4816. #if ! NAMES_ARE_CASE_SENSITIVE
  4817. if (*this != newFile)
  4818. #endif
  4819. if (! newFile.deleteFile())
  4820. return false;
  4821. return juce_moveFile (fullPath, newFile.fullPath);
  4822. }
  4823. bool File::copyFileTo (const File& newFile) const
  4824. {
  4825. if (*this == newFile)
  4826. return true;
  4827. if (! newFile.deleteFile())
  4828. return false;
  4829. return juce_copyFile (fullPath, newFile.fullPath);
  4830. }
  4831. bool File::copyDirectoryTo (const File& newDirectory) const
  4832. {
  4833. if (isDirectory() && newDirectory.createDirectory())
  4834. {
  4835. Array<File> subFiles;
  4836. findChildFiles (subFiles, File::findFiles, false);
  4837. int i;
  4838. for (i = 0; i < subFiles.size(); ++i)
  4839. if (! subFiles.getReference(i).copyFileTo (newDirectory.getChildFile (subFiles.getReference(i).getFileName())))
  4840. return false;
  4841. subFiles.clear();
  4842. findChildFiles (subFiles, File::findDirectories, false);
  4843. for (i = 0; i < subFiles.size(); ++i)
  4844. if (! subFiles.getReference(i).copyDirectoryTo (newDirectory.getChildFile (subFiles.getReference(i).getFileName())))
  4845. return false;
  4846. return true;
  4847. }
  4848. return false;
  4849. }
  4850. const String File::getPathUpToLastSlash() const
  4851. {
  4852. const int lastSlash = fullPath.lastIndexOfChar (separator);
  4853. if (lastSlash > 0)
  4854. return fullPath.substring (0, lastSlash);
  4855. else if (lastSlash == 0)
  4856. return separatorString;
  4857. else
  4858. return fullPath;
  4859. }
  4860. const File File::getParentDirectory() const
  4861. {
  4862. return File (getPathUpToLastSlash());
  4863. }
  4864. const String File::getFileName() const
  4865. {
  4866. return fullPath.substring (fullPath.lastIndexOfChar (separator) + 1);
  4867. }
  4868. int File::hashCode() const
  4869. {
  4870. return fullPath.hashCode();
  4871. }
  4872. int64 File::hashCode64() const
  4873. {
  4874. return fullPath.hashCode64();
  4875. }
  4876. const String File::getFileNameWithoutExtension() const
  4877. {
  4878. const int lastSlash = fullPath.lastIndexOfChar (separator) + 1;
  4879. const int lastDot = fullPath.lastIndexOfChar (T('.'));
  4880. if (lastDot > lastSlash)
  4881. return fullPath.substring (lastSlash, lastDot);
  4882. else
  4883. return fullPath.substring (lastSlash);
  4884. }
  4885. bool File::isAChildOf (const File& potentialParent) const
  4886. {
  4887. const String ourPath (getPathUpToLastSlash());
  4888. #if NAMES_ARE_CASE_SENSITIVE
  4889. if (potentialParent.fullPath == ourPath)
  4890. #else
  4891. if (potentialParent.fullPath.equalsIgnoreCase (ourPath))
  4892. #endif
  4893. {
  4894. return true;
  4895. }
  4896. else if (potentialParent.fullPath.length() >= ourPath.length())
  4897. {
  4898. return false;
  4899. }
  4900. else
  4901. {
  4902. return getParentDirectory().isAChildOf (potentialParent);
  4903. }
  4904. }
  4905. bool File::isAbsolutePath (const String& path)
  4906. {
  4907. return path.startsWithChar (T('/')) || path.startsWithChar (T('\\'))
  4908. #if JUCE_WINDOWS
  4909. || (path.isNotEmpty() && ((const String&) path)[1] == T(':'));
  4910. #else
  4911. || path.startsWithChar (T('~'));
  4912. #endif
  4913. }
  4914. const File File::getChildFile (String relativePath) const
  4915. {
  4916. if (isAbsolutePath (relativePath))
  4917. {
  4918. // the path is really absolute..
  4919. return File (relativePath);
  4920. }
  4921. else
  4922. {
  4923. // it's relative, so remove any ../ or ./ bits at the start.
  4924. String path (fullPath);
  4925. if (relativePath[0] == T('.'))
  4926. {
  4927. #if JUCE_WINDOWS
  4928. relativePath = relativePath.replaceCharacter (T('/'), T('\\')).trimStart();
  4929. #else
  4930. relativePath = relativePath.replaceCharacter (T('\\'), T('/')).trimStart();
  4931. #endif
  4932. while (relativePath[0] == T('.'))
  4933. {
  4934. if (relativePath[1] == T('.'))
  4935. {
  4936. if (relativePath [2] == 0 || relativePath[2] == separator)
  4937. {
  4938. const int lastSlash = path.lastIndexOfChar (separator);
  4939. if (lastSlash >= 0)
  4940. path = path.substring (0, lastSlash);
  4941. relativePath = relativePath.substring (3);
  4942. }
  4943. else
  4944. {
  4945. break;
  4946. }
  4947. }
  4948. else if (relativePath[1] == separator)
  4949. {
  4950. relativePath = relativePath.substring (2);
  4951. }
  4952. else
  4953. {
  4954. break;
  4955. }
  4956. }
  4957. }
  4958. return File (juce_addTrailingSeparator (path) + relativePath);
  4959. }
  4960. }
  4961. const File File::getSiblingFile (const String& fileName) const
  4962. {
  4963. return getParentDirectory().getChildFile (fileName);
  4964. }
  4965. int64 File::getSize() const
  4966. {
  4967. return juce_getFileSize (fullPath);
  4968. }
  4969. const String File::descriptionOfSizeInBytes (const int64 bytes)
  4970. {
  4971. if (bytes == 1)
  4972. {
  4973. return "1 byte";
  4974. }
  4975. else if (bytes < 1024)
  4976. {
  4977. return String ((int) bytes) + " bytes";
  4978. }
  4979. else if (bytes < 1024 * 1024)
  4980. {
  4981. return String (bytes / 1024.0, 1) + " KB";
  4982. }
  4983. else if (bytes < 1024 * 1024 * 1024)
  4984. {
  4985. return String (bytes / (1024.0 * 1024.0), 1) + " MB";
  4986. }
  4987. else
  4988. {
  4989. return String (bytes / (1024.0 * 1024.0 * 1024.0), 1) + " GB";
  4990. }
  4991. }
  4992. bool File::create() const
  4993. {
  4994. if (! exists())
  4995. {
  4996. const File parentDir (getParentDirectory());
  4997. if (parentDir == *this || ! parentDir.createDirectory())
  4998. return false;
  4999. void* const fh = juce_fileOpen (fullPath, true);
  5000. if (fh == 0)
  5001. return false;
  5002. juce_fileClose (fh);
  5003. }
  5004. return true;
  5005. }
  5006. bool File::createDirectory() const
  5007. {
  5008. if (! isDirectory())
  5009. {
  5010. const File parentDir (getParentDirectory());
  5011. if (parentDir == *this || ! parentDir.createDirectory())
  5012. return false;
  5013. String dir (fullPath);
  5014. while (dir.endsWithChar (separator))
  5015. dir [dir.length() - 1] = 0;
  5016. juce_createDirectory (dir);
  5017. return isDirectory();
  5018. }
  5019. return true;
  5020. }
  5021. const Time File::getCreationTime() const
  5022. {
  5023. int64 m, a, c;
  5024. juce_getFileTimes (fullPath, m, a, c);
  5025. return Time (c);
  5026. }
  5027. bool File::setCreationTime (const Time& t) const
  5028. {
  5029. return juce_setFileTimes (fullPath, 0, 0, t.toMilliseconds());
  5030. }
  5031. const Time File::getLastModificationTime() const
  5032. {
  5033. int64 m, a, c;
  5034. juce_getFileTimes (fullPath, m, a, c);
  5035. return Time (m);
  5036. }
  5037. bool File::setLastModificationTime (const Time& t) const
  5038. {
  5039. return juce_setFileTimes (fullPath, t.toMilliseconds(), 0, 0);
  5040. }
  5041. const Time File::getLastAccessTime() const
  5042. {
  5043. int64 m, a, c;
  5044. juce_getFileTimes (fullPath, m, a, c);
  5045. return Time (a);
  5046. }
  5047. bool File::setLastAccessTime (const Time& t) const
  5048. {
  5049. return juce_setFileTimes (fullPath, 0, t.toMilliseconds(), 0);
  5050. }
  5051. bool File::loadFileAsData (MemoryBlock& destBlock) const
  5052. {
  5053. if (! existsAsFile())
  5054. return false;
  5055. FileInputStream in (*this);
  5056. return getSize() == in.readIntoMemoryBlock (destBlock);
  5057. }
  5058. const String File::loadFileAsString() const
  5059. {
  5060. if (! existsAsFile())
  5061. return String::empty;
  5062. FileInputStream in (*this);
  5063. return in.readEntireStreamAsString();
  5064. }
  5065. static inline bool fileTypeMatches (const int whatToLookFor,
  5066. const bool isDir,
  5067. const bool isHidden)
  5068. {
  5069. return (whatToLookFor & (isDir ? File::findDirectories
  5070. : File::findFiles)) != 0
  5071. && ((! isHidden)
  5072. || (whatToLookFor & File::ignoreHiddenFiles) == 0);
  5073. }
  5074. int File::findChildFiles (Array<File>& results,
  5075. const int whatToLookFor,
  5076. const bool searchRecursively,
  5077. const String& wildCardPattern) const
  5078. {
  5079. // you have to specify the type of files you're looking for!
  5080. jassert ((whatToLookFor & (findFiles | findDirectories)) != 0);
  5081. int total = 0;
  5082. // find child files or directories in this directory first..
  5083. if (isDirectory())
  5084. {
  5085. const String path (juce_addTrailingSeparator (fullPath));
  5086. String filename;
  5087. bool itemIsDirectory, itemIsHidden;
  5088. void* const handle = juce_findFileStart (path, wildCardPattern, filename,
  5089. &itemIsDirectory, &itemIsHidden,
  5090. 0, 0, 0, 0);
  5091. if (handle != 0)
  5092. {
  5093. do
  5094. {
  5095. if (fileTypeMatches (whatToLookFor, itemIsDirectory, itemIsHidden)
  5096. && ! filename.containsOnly (T(".")))
  5097. {
  5098. results.add (File (path + filename, 0));
  5099. ++total;
  5100. }
  5101. } while (juce_findFileNext (handle, filename, &itemIsDirectory, &itemIsHidden, 0, 0, 0, 0));
  5102. juce_findFileClose (handle);
  5103. }
  5104. }
  5105. else
  5106. {
  5107. // trying to search for files inside a non-directory?
  5108. //jassertfalse
  5109. }
  5110. // and recurse down if required.
  5111. if (searchRecursively)
  5112. {
  5113. Array<File> subDirectories;
  5114. findChildFiles (subDirectories, File::findDirectories, false);
  5115. for (int i = 0; i < subDirectories.size(); ++i)
  5116. {
  5117. total += subDirectories.getReference(i).findChildFiles (results, whatToLookFor,
  5118. true, wildCardPattern);
  5119. }
  5120. }
  5121. return total;
  5122. }
  5123. int File::getNumberOfChildFiles (const int whatToLookFor,
  5124. const String& wildCardPattern) const
  5125. {
  5126. // you have to specify the type of files you're looking for!
  5127. jassert (whatToLookFor > 0 && whatToLookFor <= 3);
  5128. int count = 0;
  5129. if (isDirectory())
  5130. {
  5131. String filename;
  5132. bool itemIsDirectory, itemIsHidden;
  5133. void* const handle = juce_findFileStart (fullPath, wildCardPattern, filename,
  5134. &itemIsDirectory, &itemIsHidden,
  5135. 0, 0, 0, 0);
  5136. if (handle != 0)
  5137. {
  5138. do
  5139. {
  5140. if (fileTypeMatches (whatToLookFor, itemIsDirectory, itemIsHidden)
  5141. && ! filename.containsOnly (T(".")))
  5142. {
  5143. ++count;
  5144. }
  5145. } while (juce_findFileNext (handle, filename, &itemIsDirectory, &itemIsHidden, 0, 0, 0, 0));
  5146. juce_findFileClose (handle);
  5147. }
  5148. }
  5149. else
  5150. {
  5151. // trying to search for files inside a non-directory?
  5152. jassertfalse
  5153. }
  5154. return count;
  5155. }
  5156. bool File::containsSubDirectories() const
  5157. {
  5158. bool result = false;
  5159. if (isDirectory())
  5160. {
  5161. String filename;
  5162. bool itemIsDirectory, itemIsHidden;
  5163. void* const handle = juce_findFileStart (juce_addTrailingSeparator (fullPath),
  5164. T("*"), filename,
  5165. &itemIsDirectory, &itemIsHidden, 0, 0, 0, 0);
  5166. if (handle != 0)
  5167. {
  5168. do
  5169. {
  5170. if (itemIsDirectory)
  5171. {
  5172. result = true;
  5173. break;
  5174. }
  5175. } while (juce_findFileNext (handle, filename, &itemIsDirectory, &itemIsHidden, 0, 0, 0, 0));
  5176. juce_findFileClose (handle);
  5177. }
  5178. }
  5179. return result;
  5180. }
  5181. const File File::getNonexistentChildFile (const String& prefix_,
  5182. const String& suffix,
  5183. bool putNumbersInBrackets) const
  5184. {
  5185. File f (getChildFile (prefix_ + suffix));
  5186. if (f.exists())
  5187. {
  5188. int num = 2;
  5189. String prefix (prefix_);
  5190. // remove any bracketed numbers that may already be on the end..
  5191. if (prefix.trim().endsWithChar (T(')')))
  5192. {
  5193. putNumbersInBrackets = true;
  5194. const int openBracks = prefix.lastIndexOfChar (T('('));
  5195. const int closeBracks = prefix.lastIndexOfChar (T(')'));
  5196. if (openBracks > 0
  5197. && closeBracks > openBracks
  5198. && prefix.substring (openBracks + 1, closeBracks).containsOnly (T("0123456789")))
  5199. {
  5200. num = prefix.substring (openBracks + 1, closeBracks).getIntValue() + 1;
  5201. prefix = prefix.substring (0, openBracks);
  5202. }
  5203. }
  5204. // also use brackets if it ends in a digit.
  5205. putNumbersInBrackets = putNumbersInBrackets
  5206. || CharacterFunctions::isDigit (prefix.getLastCharacter());
  5207. do
  5208. {
  5209. if (putNumbersInBrackets)
  5210. f = getChildFile (prefix + T('(') + String (num++) + T(')') + suffix);
  5211. else
  5212. f = getChildFile (prefix + String (num++) + suffix);
  5213. } while (f.exists());
  5214. }
  5215. return f;
  5216. }
  5217. const File File::getNonexistentSibling (const bool putNumbersInBrackets) const
  5218. {
  5219. if (exists())
  5220. {
  5221. return getParentDirectory()
  5222. .getNonexistentChildFile (getFileNameWithoutExtension(),
  5223. getFileExtension(),
  5224. putNumbersInBrackets);
  5225. }
  5226. else
  5227. {
  5228. return *this;
  5229. }
  5230. }
  5231. const String File::getFileExtension() const
  5232. {
  5233. String ext;
  5234. if (! isDirectory())
  5235. {
  5236. const int indexOfDot = fullPath.lastIndexOfChar (T('.'));
  5237. if (indexOfDot > fullPath.lastIndexOfChar (separator))
  5238. ext = fullPath.substring (indexOfDot);
  5239. }
  5240. return ext;
  5241. }
  5242. bool File::hasFileExtension (const String& possibleSuffix) const
  5243. {
  5244. if (possibleSuffix.isEmpty())
  5245. return fullPath.lastIndexOfChar (T('.')) <= fullPath.lastIndexOfChar (separator);
  5246. const int semicolon = possibleSuffix.indexOfChar (0, T(';'));
  5247. if (semicolon >= 0)
  5248. {
  5249. return hasFileExtension (possibleSuffix.substring (0, semicolon).trimEnd())
  5250. || hasFileExtension (possibleSuffix.substring (semicolon + 1).trimStart());
  5251. }
  5252. else
  5253. {
  5254. if (fullPath.endsWithIgnoreCase (possibleSuffix))
  5255. {
  5256. if (possibleSuffix.startsWithChar (T('.')))
  5257. return true;
  5258. const int dotPos = fullPath.length() - possibleSuffix.length() - 1;
  5259. if (dotPos >= 0)
  5260. return fullPath [dotPos] == T('.');
  5261. }
  5262. }
  5263. return false;
  5264. }
  5265. const File File::withFileExtension (const String& newExtension) const
  5266. {
  5267. if (fullPath.isEmpty())
  5268. return File::nonexistent;
  5269. String filePart (getFileName());
  5270. int i = filePart.lastIndexOfChar (T('.'));
  5271. if (i < 0)
  5272. i = filePart.length();
  5273. String newExt (newExtension);
  5274. if (newExt.isNotEmpty() && ! newExt.startsWithChar (T('.')))
  5275. newExt = T(".") + newExt;
  5276. return getSiblingFile (filePart.substring (0, i) + newExt);
  5277. }
  5278. bool File::startAsProcess (const String& parameters) const
  5279. {
  5280. return exists()
  5281. && juce_launchFile (fullPath, parameters);
  5282. }
  5283. FileInputStream* File::createInputStream() const
  5284. {
  5285. if (existsAsFile())
  5286. return new FileInputStream (*this);
  5287. else
  5288. return 0;
  5289. }
  5290. FileOutputStream* File::createOutputStream (const int bufferSize) const
  5291. {
  5292. ScopedPointer <FileOutputStream> out (new FileOutputStream (*this, bufferSize));
  5293. if (out->failedToOpen())
  5294. return 0;
  5295. return out.release();
  5296. }
  5297. bool File::appendData (const void* const dataToAppend,
  5298. const int numberOfBytes) const
  5299. {
  5300. if (numberOfBytes > 0)
  5301. {
  5302. const ScopedPointer <FileOutputStream> out (createOutputStream());
  5303. if (out == 0)
  5304. return false;
  5305. out->write (dataToAppend, numberOfBytes);
  5306. }
  5307. return true;
  5308. }
  5309. bool File::replaceWithData (const void* const dataToWrite,
  5310. const int numberOfBytes) const
  5311. {
  5312. jassert (numberOfBytes >= 0); // a negative number of bytes??
  5313. if (numberOfBytes <= 0)
  5314. return deleteFile();
  5315. TemporaryFile tempFile (*this, TemporaryFile::useHiddenFile);
  5316. tempFile.getFile().appendData (dataToWrite, numberOfBytes);
  5317. return tempFile.overwriteTargetFileWithTemporary();
  5318. }
  5319. bool File::appendText (const String& text,
  5320. const bool asUnicode,
  5321. const bool writeUnicodeHeaderBytes) const
  5322. {
  5323. const ScopedPointer <FileOutputStream> out (createOutputStream());
  5324. if (out != 0)
  5325. {
  5326. out->writeText (text, asUnicode, writeUnicodeHeaderBytes);
  5327. return true;
  5328. }
  5329. return false;
  5330. }
  5331. bool File::replaceWithText (const String& textToWrite,
  5332. const bool asUnicode,
  5333. const bool writeUnicodeHeaderBytes) const
  5334. {
  5335. TemporaryFile tempFile (*this, TemporaryFile::useHiddenFile);
  5336. tempFile.getFile().appendText (textToWrite, asUnicode, writeUnicodeHeaderBytes);
  5337. return tempFile.overwriteTargetFileWithTemporary();
  5338. }
  5339. const String File::createLegalPathName (const String& original)
  5340. {
  5341. String s (original);
  5342. String start;
  5343. if (s[1] == T(':'))
  5344. {
  5345. start = s.substring (0, 2);
  5346. s = s.substring (2);
  5347. }
  5348. return start + s.removeCharacters (T("\"#@,;:<>*^|?"))
  5349. .substring (0, 1024);
  5350. }
  5351. const String File::createLegalFileName (const String& original)
  5352. {
  5353. String s (original.removeCharacters (T("\"#@,;:<>*^|?\\/")));
  5354. const int maxLength = 128; // only the length of the filename, not the whole path
  5355. const int len = s.length();
  5356. if (len > maxLength)
  5357. {
  5358. const int lastDot = s.lastIndexOfChar (T('.'));
  5359. if (lastDot > jmax (0, len - 12))
  5360. {
  5361. s = s.substring (0, maxLength - (len - lastDot))
  5362. + s.substring (lastDot);
  5363. }
  5364. else
  5365. {
  5366. s = s.substring (0, maxLength);
  5367. }
  5368. }
  5369. return s;
  5370. }
  5371. const String File::getRelativePathFrom (const File& dir) const
  5372. {
  5373. String thisPath (fullPath);
  5374. {
  5375. int len = thisPath.length();
  5376. while (--len >= 0 && thisPath [len] == File::separator)
  5377. thisPath [len] = 0;
  5378. }
  5379. String dirPath (juce_addTrailingSeparator ((dir.existsAsFile()) ? dir.getParentDirectory().getFullPathName()
  5380. : dir.fullPath));
  5381. const int len = jmin (thisPath.length(), dirPath.length());
  5382. int commonBitLength = 0;
  5383. for (int i = 0; i < len; ++i)
  5384. {
  5385. #if NAMES_ARE_CASE_SENSITIVE
  5386. if (thisPath[i] != dirPath[i])
  5387. #else
  5388. if (CharacterFunctions::toLowerCase (thisPath[i])
  5389. != CharacterFunctions::toLowerCase (dirPath[i]))
  5390. #endif
  5391. {
  5392. break;
  5393. }
  5394. ++commonBitLength;
  5395. }
  5396. while (commonBitLength > 0 && thisPath [commonBitLength - 1] != File::separator)
  5397. --commonBitLength;
  5398. // if the only common bit is the root, then just return the full path..
  5399. if (commonBitLength <= 0
  5400. || (commonBitLength == 1 && thisPath [1] == File::separator))
  5401. return fullPath;
  5402. thisPath = thisPath.substring (commonBitLength);
  5403. dirPath = dirPath.substring (commonBitLength);
  5404. while (dirPath.isNotEmpty())
  5405. {
  5406. #if JUCE_WINDOWS
  5407. thisPath = T("..\\") + thisPath;
  5408. #else
  5409. thisPath = T("../") + thisPath;
  5410. #endif
  5411. const int sep = dirPath.indexOfChar (separator);
  5412. if (sep >= 0)
  5413. dirPath = dirPath.substring (sep + 1);
  5414. else
  5415. dirPath = String::empty;
  5416. }
  5417. return thisPath;
  5418. }
  5419. void File::findFileSystemRoots (Array<File>& destArray)
  5420. {
  5421. const StringArray roots (juce_getFileSystemRoots());
  5422. for (int i = 0; i < roots.size(); ++i)
  5423. destArray.add (File (roots[i]));
  5424. }
  5425. const String File::getVolumeLabel() const
  5426. {
  5427. int serialNum;
  5428. return juce_getVolumeLabel (fullPath, serialNum);
  5429. }
  5430. int File::getVolumeSerialNumber() const
  5431. {
  5432. int serialNum;
  5433. juce_getVolumeLabel (fullPath, serialNum);
  5434. return serialNum;
  5435. }
  5436. const File File::createTempFile (const String& fileNameEnding)
  5437. {
  5438. const File tempFile (getSpecialLocation (tempDirectory)
  5439. .getChildFile (T("temp_") + String (Random::getSystemRandom().nextInt()))
  5440. .withFileExtension (fileNameEnding));
  5441. if (tempFile.exists())
  5442. return createTempFile (fileNameEnding);
  5443. else
  5444. return tempFile;
  5445. }
  5446. END_JUCE_NAMESPACE
  5447. /********* End of inlined file: juce_File.cpp *********/
  5448. /********* Start of inlined file: juce_FileInputStream.cpp *********/
  5449. BEGIN_JUCE_NAMESPACE
  5450. void* juce_fileOpen (const String& path, bool forWriting);
  5451. void juce_fileClose (void* handle);
  5452. int juce_fileRead (void* handle, void* buffer, int size);
  5453. int64 juce_fileSetPosition (void* handle, int64 pos);
  5454. FileInputStream::FileInputStream (const File& f)
  5455. : file (f),
  5456. currentPosition (0),
  5457. needToSeek (true)
  5458. {
  5459. totalSize = f.getSize();
  5460. fileHandle = juce_fileOpen (f.getFullPathName(), false);
  5461. }
  5462. FileInputStream::~FileInputStream()
  5463. {
  5464. juce_fileClose (fileHandle);
  5465. }
  5466. int64 FileInputStream::getTotalLength()
  5467. {
  5468. return totalSize;
  5469. }
  5470. int FileInputStream::read (void* buffer, int bytesToRead)
  5471. {
  5472. int num = 0;
  5473. if (needToSeek)
  5474. {
  5475. if (juce_fileSetPosition (fileHandle, currentPosition) < 0)
  5476. return 0;
  5477. needToSeek = false;
  5478. }
  5479. num = juce_fileRead (fileHandle, buffer, bytesToRead);
  5480. currentPosition += num;
  5481. return num;
  5482. }
  5483. bool FileInputStream::isExhausted()
  5484. {
  5485. return currentPosition >= totalSize;
  5486. }
  5487. int64 FileInputStream::getPosition()
  5488. {
  5489. return currentPosition;
  5490. }
  5491. bool FileInputStream::setPosition (int64 pos)
  5492. {
  5493. pos = jlimit ((int64) 0, totalSize, pos);
  5494. needToSeek |= (currentPosition != pos);
  5495. currentPosition = pos;
  5496. return true;
  5497. }
  5498. END_JUCE_NAMESPACE
  5499. /********* End of inlined file: juce_FileInputStream.cpp *********/
  5500. /********* Start of inlined file: juce_FileOutputStream.cpp *********/
  5501. BEGIN_JUCE_NAMESPACE
  5502. void* juce_fileOpen (const String& path, bool forWriting);
  5503. void juce_fileClose (void* handle);
  5504. int juce_fileWrite (void* handle, const void* buffer, int size);
  5505. void juce_fileFlush (void* handle);
  5506. int64 juce_fileGetPosition (void* handle);
  5507. int64 juce_fileSetPosition (void* handle, int64 pos);
  5508. FileOutputStream::FileOutputStream (const File& f,
  5509. const int bufferSize_)
  5510. : file (f),
  5511. bufferSize (bufferSize_),
  5512. bytesInBuffer (0)
  5513. {
  5514. fileHandle = juce_fileOpen (f.getFullPathName(), true);
  5515. if (fileHandle != 0)
  5516. {
  5517. currentPosition = juce_fileGetPosition (fileHandle);
  5518. if (currentPosition < 0)
  5519. {
  5520. jassertfalse
  5521. juce_fileClose (fileHandle);
  5522. fileHandle = 0;
  5523. }
  5524. }
  5525. buffer.malloc (jmax (bufferSize_, 16));
  5526. }
  5527. FileOutputStream::~FileOutputStream()
  5528. {
  5529. flush();
  5530. juce_fileClose (fileHandle);
  5531. }
  5532. int64 FileOutputStream::getPosition()
  5533. {
  5534. return currentPosition;
  5535. }
  5536. bool FileOutputStream::setPosition (int64 newPosition)
  5537. {
  5538. if (newPosition != currentPosition)
  5539. {
  5540. flush();
  5541. currentPosition = juce_fileSetPosition (fileHandle, newPosition);
  5542. }
  5543. return newPosition == currentPosition;
  5544. }
  5545. void FileOutputStream::flush()
  5546. {
  5547. if (bytesInBuffer > 0)
  5548. {
  5549. juce_fileWrite (fileHandle, buffer, bytesInBuffer);
  5550. bytesInBuffer = 0;
  5551. }
  5552. juce_fileFlush (fileHandle);
  5553. }
  5554. bool FileOutputStream::write (const void* const src, const int numBytes)
  5555. {
  5556. if (bytesInBuffer + numBytes < bufferSize)
  5557. {
  5558. memcpy (buffer + bytesInBuffer, src, numBytes);
  5559. bytesInBuffer += numBytes;
  5560. currentPosition += numBytes;
  5561. }
  5562. else
  5563. {
  5564. if (bytesInBuffer > 0)
  5565. {
  5566. // flush the reservoir
  5567. const bool wroteOk = (juce_fileWrite (fileHandle, buffer, bytesInBuffer) == bytesInBuffer);
  5568. bytesInBuffer = 0;
  5569. if (! wroteOk)
  5570. return false;
  5571. }
  5572. if (numBytes < bufferSize)
  5573. {
  5574. memcpy (buffer + bytesInBuffer, src, numBytes);
  5575. bytesInBuffer += numBytes;
  5576. currentPosition += numBytes;
  5577. }
  5578. else
  5579. {
  5580. const int bytesWritten = juce_fileWrite (fileHandle, src, numBytes);
  5581. currentPosition += bytesWritten;
  5582. return bytesWritten == numBytes;
  5583. }
  5584. }
  5585. return true;
  5586. }
  5587. END_JUCE_NAMESPACE
  5588. /********* End of inlined file: juce_FileOutputStream.cpp *********/
  5589. /********* Start of inlined file: juce_FileSearchPath.cpp *********/
  5590. BEGIN_JUCE_NAMESPACE
  5591. FileSearchPath::FileSearchPath()
  5592. {
  5593. }
  5594. FileSearchPath::FileSearchPath (const String& path)
  5595. {
  5596. init (path);
  5597. }
  5598. FileSearchPath::FileSearchPath (const FileSearchPath& other)
  5599. : directories (other.directories)
  5600. {
  5601. }
  5602. FileSearchPath::~FileSearchPath()
  5603. {
  5604. }
  5605. const FileSearchPath& FileSearchPath::operator= (const String& path)
  5606. {
  5607. init (path);
  5608. return *this;
  5609. }
  5610. void FileSearchPath::init (const String& path)
  5611. {
  5612. directories.clear();
  5613. directories.addTokens (path, T(";"), T("\""));
  5614. directories.trim();
  5615. directories.removeEmptyStrings();
  5616. for (int i = directories.size(); --i >= 0;)
  5617. directories.set (i, directories[i].unquoted());
  5618. }
  5619. int FileSearchPath::getNumPaths() const
  5620. {
  5621. return directories.size();
  5622. }
  5623. const File FileSearchPath::operator[] (const int index) const
  5624. {
  5625. return File (directories [index]);
  5626. }
  5627. const String FileSearchPath::toString() const
  5628. {
  5629. StringArray directories2 (directories);
  5630. for (int i = directories2.size(); --i >= 0;)
  5631. if (directories2[i].containsChar (T(';')))
  5632. directories2.set (i, directories2[i].quoted());
  5633. return directories2.joinIntoString (T(";"));
  5634. }
  5635. void FileSearchPath::add (const File& dir, const int insertIndex)
  5636. {
  5637. directories.insert (insertIndex, dir.getFullPathName());
  5638. }
  5639. void FileSearchPath::addIfNotAlreadyThere (const File& dir)
  5640. {
  5641. for (int i = 0; i < directories.size(); ++i)
  5642. if (File (directories[i]) == dir)
  5643. return;
  5644. add (dir);
  5645. }
  5646. void FileSearchPath::remove (const int index)
  5647. {
  5648. directories.remove (index);
  5649. }
  5650. void FileSearchPath::addPath (const FileSearchPath& other)
  5651. {
  5652. for (int i = 0; i < other.getNumPaths(); ++i)
  5653. addIfNotAlreadyThere (other[i]);
  5654. }
  5655. void FileSearchPath::removeRedundantPaths()
  5656. {
  5657. for (int i = directories.size(); --i >= 0;)
  5658. {
  5659. const File d1 (directories[i]);
  5660. for (int j = directories.size(); --j >= 0;)
  5661. {
  5662. const File d2 (directories[j]);
  5663. if ((i != j) && (d1.isAChildOf (d2) || d1 == d2))
  5664. {
  5665. directories.remove (i);
  5666. break;
  5667. }
  5668. }
  5669. }
  5670. }
  5671. void FileSearchPath::removeNonExistentPaths()
  5672. {
  5673. for (int i = directories.size(); --i >= 0;)
  5674. if (! File (directories[i]).isDirectory())
  5675. directories.remove (i);
  5676. }
  5677. int FileSearchPath::findChildFiles (Array<File>& results,
  5678. const int whatToLookFor,
  5679. const bool searchRecursively,
  5680. const String& wildCardPattern) const
  5681. {
  5682. int total = 0;
  5683. for (int i = 0; i < directories.size(); ++i)
  5684. total += operator[] (i).findChildFiles (results,
  5685. whatToLookFor,
  5686. searchRecursively,
  5687. wildCardPattern);
  5688. return total;
  5689. }
  5690. bool FileSearchPath::isFileInPath (const File& fileToCheck,
  5691. const bool checkRecursively) const
  5692. {
  5693. for (int i = directories.size(); --i >= 0;)
  5694. {
  5695. const File d (directories[i]);
  5696. if (checkRecursively)
  5697. {
  5698. if (fileToCheck.isAChildOf (d))
  5699. return true;
  5700. }
  5701. else
  5702. {
  5703. if (fileToCheck.getParentDirectory() == d)
  5704. return true;
  5705. }
  5706. }
  5707. return false;
  5708. }
  5709. END_JUCE_NAMESPACE
  5710. /********* End of inlined file: juce_FileSearchPath.cpp *********/
  5711. /********* Start of inlined file: juce_NamedPipe.cpp *********/
  5712. BEGIN_JUCE_NAMESPACE
  5713. NamedPipe::NamedPipe()
  5714. : internal (0)
  5715. {
  5716. }
  5717. NamedPipe::~NamedPipe()
  5718. {
  5719. close();
  5720. }
  5721. bool NamedPipe::openExisting (const String& pipeName)
  5722. {
  5723. currentPipeName = pipeName;
  5724. return openInternal (pipeName, false);
  5725. }
  5726. bool NamedPipe::createNewPipe (const String& pipeName)
  5727. {
  5728. currentPipeName = pipeName;
  5729. return openInternal (pipeName, true);
  5730. }
  5731. bool NamedPipe::isOpen() const
  5732. {
  5733. return internal != 0;
  5734. }
  5735. const String NamedPipe::getName() const
  5736. {
  5737. return currentPipeName;
  5738. }
  5739. // other methods for this class are implemented in the platform-specific files
  5740. END_JUCE_NAMESPACE
  5741. /********* End of inlined file: juce_NamedPipe.cpp *********/
  5742. /********* Start of inlined file: juce_TemporaryFile.cpp *********/
  5743. BEGIN_JUCE_NAMESPACE
  5744. TemporaryFile::TemporaryFile (const String& suffix, const int optionFlags)
  5745. {
  5746. createTempFile (File::getSpecialLocation (File::tempDirectory),
  5747. T("temp_") + String (Random::getSystemRandom().nextInt()),
  5748. suffix,
  5749. optionFlags);
  5750. }
  5751. TemporaryFile::TemporaryFile (const File& targetFile_, const int optionFlags)
  5752. : targetFile (targetFile_)
  5753. {
  5754. // If you use this constructor, you need to give it a valid target file!
  5755. jassert (targetFile != File::nonexistent);
  5756. createTempFile (targetFile.getParentDirectory(),
  5757. targetFile.getFileNameWithoutExtension() + T("_temp") + String (Random::getSystemRandom().nextInt()),
  5758. targetFile.getFileExtension(),
  5759. optionFlags);
  5760. }
  5761. void TemporaryFile::createTempFile (const File& parentDirectory, String name,
  5762. const String& suffix, const int optionFlags)
  5763. {
  5764. if ((optionFlags & useHiddenFile) != 0)
  5765. name = T(".") + name;
  5766. temporaryFile = parentDirectory.getNonexistentChildFile (name, suffix, (optionFlags & putNumbersInBrackets) != 0);
  5767. }
  5768. TemporaryFile::~TemporaryFile()
  5769. {
  5770. // Have a few attempts at deleting the file before giving up..
  5771. for (int i = 5; --i >= 0;)
  5772. {
  5773. if (temporaryFile.deleteFile())
  5774. return;
  5775. Thread::sleep (50);
  5776. }
  5777. // Failed to delete our temporary file! Check that you've deleted all the
  5778. // file output streams that were using it!
  5779. jassertfalse;
  5780. }
  5781. bool TemporaryFile::overwriteTargetFileWithTemporary() const
  5782. {
  5783. // This method only works if you created this object with the constructor
  5784. // that takes a target file!
  5785. jassert (targetFile != File::nonexistent);
  5786. if (temporaryFile.exists())
  5787. {
  5788. // Have a few attempts at overwriting the file before giving up..
  5789. for (int i = 5; --i >= 0;)
  5790. {
  5791. if (temporaryFile.moveFileTo (targetFile))
  5792. return true;
  5793. Thread::sleep (100);
  5794. }
  5795. // Failed to overwrite the new file! Make sure you've not left any
  5796. // file streams hanging around when you call this method!
  5797. jassertfalse
  5798. }
  5799. else
  5800. {
  5801. // There's no temporary file to use. If your write failed, you should
  5802. // probably check, and not bother calling this method.
  5803. jassertfalse
  5804. }
  5805. return false;
  5806. }
  5807. END_JUCE_NAMESPACE
  5808. /********* End of inlined file: juce_TemporaryFile.cpp *********/
  5809. /********* Start of inlined file: juce_Socket.cpp *********/
  5810. #if JUCE_WINDOWS
  5811. #include <winsock2.h>
  5812. #ifdef _MSC_VER
  5813. #pragma warning (disable : 4127 4389 4018)
  5814. #endif
  5815. #else
  5816. #if JUCE_LINUX
  5817. #include <sys/types.h>
  5818. #include <sys/socket.h>
  5819. #include <sys/errno.h>
  5820. #include <unistd.h>
  5821. #include <netinet/in.h>
  5822. #elif (MACOSX_DEPLOYMENT_TARGET <= MAC_OS_X_VERSION_10_4) && ! JUCE_IPHONE
  5823. #include <CoreServices/CoreServices.h>
  5824. #endif
  5825. #include <fcntl.h>
  5826. #include <netdb.h>
  5827. #include <arpa/inet.h>
  5828. #include <netinet/tcp.h>
  5829. #endif
  5830. BEGIN_JUCE_NAMESPACE
  5831. #if defined (JUCE_LINUX) || defined (JUCE_MAC) || defined (JUCE_IPHONE)
  5832. typedef socklen_t juce_socklen_t;
  5833. #else
  5834. typedef int juce_socklen_t;
  5835. #endif
  5836. #if JUCE_WINDOWS
  5837. typedef int (__stdcall juce_CloseWin32SocketLibCall) (void);
  5838. juce_CloseWin32SocketLibCall* juce_CloseWin32SocketLib = 0;
  5839. static void initWin32Sockets()
  5840. {
  5841. static CriticalSection lock;
  5842. const ScopedLock sl (lock);
  5843. if (juce_CloseWin32SocketLib == 0)
  5844. {
  5845. WSADATA wsaData;
  5846. const WORD wVersionRequested = MAKEWORD (1, 1);
  5847. WSAStartup (wVersionRequested, &wsaData);
  5848. juce_CloseWin32SocketLib = &WSACleanup;
  5849. }
  5850. }
  5851. #endif
  5852. static bool resetSocketOptions (const int handle, const bool isDatagram, const bool allowBroadcast) throw()
  5853. {
  5854. const int sndBufSize = 65536;
  5855. const int rcvBufSize = 65536;
  5856. const int one = 1;
  5857. return handle > 0
  5858. && setsockopt (handle, SOL_SOCKET, SO_RCVBUF, (const char*) &rcvBufSize, sizeof (rcvBufSize)) == 0
  5859. && setsockopt (handle, SOL_SOCKET, SO_SNDBUF, (const char*) &sndBufSize, sizeof (sndBufSize)) == 0
  5860. && (isDatagram ? ((! allowBroadcast) || setsockopt (handle, SOL_SOCKET, SO_BROADCAST, (const char*) &one, sizeof (one)) == 0)
  5861. : (setsockopt (handle, IPPROTO_TCP, TCP_NODELAY, (const char*) &one, sizeof (one)) == 0));
  5862. }
  5863. static bool bindSocketToPort (const int handle, const int port) throw()
  5864. {
  5865. if (handle <= 0 || port <= 0)
  5866. return false;
  5867. struct sockaddr_in servTmpAddr;
  5868. zerostruct (servTmpAddr);
  5869. servTmpAddr.sin_family = PF_INET;
  5870. servTmpAddr.sin_addr.s_addr = htonl (INADDR_ANY);
  5871. servTmpAddr.sin_port = htons ((uint16) port);
  5872. return bind (handle, (struct sockaddr*) &servTmpAddr, sizeof (struct sockaddr_in)) >= 0;
  5873. }
  5874. static int readSocket (const int handle,
  5875. void* const destBuffer, const int maxBytesToRead,
  5876. bool volatile& connected,
  5877. const bool blockUntilSpecifiedAmountHasArrived) throw()
  5878. {
  5879. int bytesRead = 0;
  5880. while (bytesRead < maxBytesToRead)
  5881. {
  5882. int bytesThisTime;
  5883. #if JUCE_WINDOWS
  5884. bytesThisTime = recv (handle, ((char*) destBuffer) + bytesRead, maxBytesToRead - bytesRead, 0);
  5885. #else
  5886. while ((bytesThisTime = (int) ::read (handle, ((char*) destBuffer) + bytesRead, maxBytesToRead - bytesRead)) < 0
  5887. && errno == EINTR
  5888. && connected)
  5889. {
  5890. }
  5891. #endif
  5892. if (bytesThisTime <= 0 || ! connected)
  5893. {
  5894. if (bytesRead == 0)
  5895. bytesRead = -1;
  5896. break;
  5897. }
  5898. bytesRead += bytesThisTime;
  5899. if (! blockUntilSpecifiedAmountHasArrived)
  5900. break;
  5901. }
  5902. return bytesRead;
  5903. }
  5904. static int waitForReadiness (const int handle, const bool forReading,
  5905. const int timeoutMsecs) throw()
  5906. {
  5907. struct timeval timeout;
  5908. struct timeval* timeoutp;
  5909. if (timeoutMsecs >= 0)
  5910. {
  5911. timeout.tv_sec = timeoutMsecs / 1000;
  5912. timeout.tv_usec = (timeoutMsecs % 1000) * 1000;
  5913. timeoutp = &timeout;
  5914. }
  5915. else
  5916. {
  5917. timeoutp = 0;
  5918. }
  5919. fd_set rset, wset;
  5920. FD_ZERO (&rset);
  5921. FD_SET (handle, &rset);
  5922. FD_ZERO (&wset);
  5923. FD_SET (handle, &wset);
  5924. fd_set* const prset = forReading ? &rset : 0;
  5925. fd_set* const pwset = forReading ? 0 : &wset;
  5926. #if JUCE_WINDOWS
  5927. if (select (handle + 1, prset, pwset, 0, timeoutp) < 0)
  5928. return -1;
  5929. #else
  5930. {
  5931. int result;
  5932. while ((result = select (handle + 1, prset, pwset, 0, timeoutp)) < 0
  5933. && errno == EINTR)
  5934. {
  5935. }
  5936. if (result < 0)
  5937. return -1;
  5938. }
  5939. #endif
  5940. {
  5941. int opt;
  5942. juce_socklen_t len = sizeof (opt);
  5943. if (getsockopt (handle, SOL_SOCKET, SO_ERROR, (char*) &opt, &len) < 0
  5944. || opt != 0)
  5945. return -1;
  5946. }
  5947. if ((forReading && FD_ISSET (handle, &rset))
  5948. || ((! forReading) && FD_ISSET (handle, &wset)))
  5949. return 1;
  5950. return 0;
  5951. }
  5952. static bool setSocketBlockingState (const int handle, const bool shouldBlock) throw()
  5953. {
  5954. #if JUCE_WINDOWS
  5955. u_long nonBlocking = shouldBlock ? 0 : 1;
  5956. if (ioctlsocket (handle, FIONBIO, &nonBlocking) != 0)
  5957. return false;
  5958. #else
  5959. int socketFlags = fcntl (handle, F_GETFL, 0);
  5960. if (socketFlags == -1)
  5961. return false;
  5962. if (shouldBlock)
  5963. socketFlags &= ~O_NONBLOCK;
  5964. else
  5965. socketFlags |= O_NONBLOCK;
  5966. if (fcntl (handle, F_SETFL, socketFlags) != 0)
  5967. return false;
  5968. #endif
  5969. return true;
  5970. }
  5971. static bool connectSocket (int volatile& handle,
  5972. const bool isDatagram,
  5973. void** serverAddress,
  5974. const String& hostName,
  5975. const int portNumber,
  5976. const int timeOutMillisecs) throw()
  5977. {
  5978. struct hostent* const hostEnt = gethostbyname (hostName);
  5979. if (hostEnt == 0)
  5980. return false;
  5981. struct in_addr targetAddress;
  5982. memcpy (&targetAddress.s_addr,
  5983. *(hostEnt->h_addr_list),
  5984. sizeof (targetAddress.s_addr));
  5985. struct sockaddr_in servTmpAddr;
  5986. zerostruct (servTmpAddr);
  5987. servTmpAddr.sin_family = PF_INET;
  5988. servTmpAddr.sin_addr = targetAddress;
  5989. servTmpAddr.sin_port = htons ((uint16) portNumber);
  5990. if (handle < 0)
  5991. handle = (int) socket (AF_INET, isDatagram ? SOCK_DGRAM : SOCK_STREAM, 0);
  5992. if (handle < 0)
  5993. return false;
  5994. if (isDatagram)
  5995. {
  5996. *serverAddress = new struct sockaddr_in();
  5997. *((struct sockaddr_in*) *serverAddress) = servTmpAddr;
  5998. return true;
  5999. }
  6000. setSocketBlockingState (handle, false);
  6001. const int result = ::connect (handle, (struct sockaddr*) &servTmpAddr, sizeof (struct sockaddr_in));
  6002. if (result < 0)
  6003. {
  6004. #if JUCE_WINDOWS
  6005. if (result == SOCKET_ERROR && WSAGetLastError() == WSAEWOULDBLOCK)
  6006. #else
  6007. if (errno == EINPROGRESS)
  6008. #endif
  6009. {
  6010. if (waitForReadiness (handle, false, timeOutMillisecs) != 1)
  6011. {
  6012. setSocketBlockingState (handle, true);
  6013. return false;
  6014. }
  6015. }
  6016. }
  6017. setSocketBlockingState (handle, true);
  6018. resetSocketOptions (handle, false, false);
  6019. return true;
  6020. }
  6021. StreamingSocket::StreamingSocket()
  6022. : portNumber (0),
  6023. handle (-1),
  6024. connected (false),
  6025. isListener (false)
  6026. {
  6027. #if JUCE_WINDOWS
  6028. initWin32Sockets();
  6029. #endif
  6030. }
  6031. StreamingSocket::StreamingSocket (const String& hostName_,
  6032. const int portNumber_,
  6033. const int handle_)
  6034. : hostName (hostName_),
  6035. portNumber (portNumber_),
  6036. handle (handle_),
  6037. connected (true),
  6038. isListener (false)
  6039. {
  6040. #if JUCE_WINDOWS
  6041. initWin32Sockets();
  6042. #endif
  6043. resetSocketOptions (handle_, false, false);
  6044. }
  6045. StreamingSocket::~StreamingSocket()
  6046. {
  6047. close();
  6048. }
  6049. int StreamingSocket::read (void* destBuffer, const int maxBytesToRead, const bool blockUntilSpecifiedAmountHasArrived)
  6050. {
  6051. return (connected && ! isListener) ? readSocket (handle, destBuffer, maxBytesToRead, connected, blockUntilSpecifiedAmountHasArrived)
  6052. : -1;
  6053. }
  6054. int StreamingSocket::write (const void* sourceBuffer, const int numBytesToWrite)
  6055. {
  6056. if (isListener || ! connected)
  6057. return -1;
  6058. #if JUCE_WINDOWS
  6059. return send (handle, (const char*) sourceBuffer, numBytesToWrite, 0);
  6060. #else
  6061. int result;
  6062. while ((result = (int) ::write (handle, sourceBuffer, numBytesToWrite)) < 0
  6063. && errno == EINTR)
  6064. {
  6065. }
  6066. return result;
  6067. #endif
  6068. }
  6069. int StreamingSocket::waitUntilReady (const bool readyForReading,
  6070. const int timeoutMsecs) const
  6071. {
  6072. return connected ? waitForReadiness (handle, readyForReading, timeoutMsecs)
  6073. : -1;
  6074. }
  6075. bool StreamingSocket::bindToPort (const int port)
  6076. {
  6077. return bindSocketToPort (handle, port);
  6078. }
  6079. bool StreamingSocket::connect (const String& remoteHostName,
  6080. const int remotePortNumber,
  6081. const int timeOutMillisecs)
  6082. {
  6083. if (isListener)
  6084. {
  6085. jassertfalse // a listener socket can't connect to another one!
  6086. return false;
  6087. }
  6088. if (connected)
  6089. close();
  6090. hostName = remoteHostName;
  6091. portNumber = remotePortNumber;
  6092. isListener = false;
  6093. connected = connectSocket (handle, false, 0, remoteHostName,
  6094. remotePortNumber, timeOutMillisecs);
  6095. if (! (connected && resetSocketOptions (handle, false, false)))
  6096. {
  6097. close();
  6098. return false;
  6099. }
  6100. return true;
  6101. }
  6102. void StreamingSocket::close()
  6103. {
  6104. #if JUCE_WINDOWS
  6105. closesocket (handle);
  6106. connected = false;
  6107. #else
  6108. if (connected)
  6109. {
  6110. connected = false;
  6111. if (isListener)
  6112. {
  6113. // need to do this to interrupt the accept() function..
  6114. StreamingSocket temp;
  6115. temp.connect ("localhost", portNumber, 1000);
  6116. }
  6117. }
  6118. ::close (handle);
  6119. #endif
  6120. hostName = String::empty;
  6121. portNumber = 0;
  6122. handle = -1;
  6123. isListener = false;
  6124. }
  6125. bool StreamingSocket::createListener (const int newPortNumber, const String& localHostName)
  6126. {
  6127. if (connected)
  6128. close();
  6129. hostName = "listener";
  6130. portNumber = newPortNumber;
  6131. isListener = true;
  6132. struct sockaddr_in servTmpAddr;
  6133. zerostruct (servTmpAddr);
  6134. servTmpAddr.sin_family = PF_INET;
  6135. servTmpAddr.sin_addr.s_addr = htonl (INADDR_ANY);
  6136. if (localHostName.isNotEmpty())
  6137. servTmpAddr.sin_addr.s_addr = ::inet_addr (localHostName.toUTF8());
  6138. servTmpAddr.sin_port = htons ((uint16) portNumber);
  6139. handle = (int) socket (AF_INET, SOCK_STREAM, 0);
  6140. if (handle < 0)
  6141. return false;
  6142. const int reuse = 1;
  6143. setsockopt (handle, SOL_SOCKET, SO_REUSEADDR, (const char*) &reuse, sizeof (reuse));
  6144. if (bind (handle, (struct sockaddr*) &servTmpAddr, sizeof (struct sockaddr_in)) < 0
  6145. || listen (handle, SOMAXCONN) < 0)
  6146. {
  6147. close();
  6148. return false;
  6149. }
  6150. connected = true;
  6151. return true;
  6152. }
  6153. StreamingSocket* StreamingSocket::waitForNextConnection() const
  6154. {
  6155. jassert (isListener || ! connected); // to call this method, you first have to use createListener() to
  6156. // prepare this socket as a listener.
  6157. if (connected && isListener)
  6158. {
  6159. struct sockaddr address;
  6160. juce_socklen_t len = sizeof (sockaddr);
  6161. const int newSocket = (int) accept (handle, &address, &len);
  6162. if (newSocket >= 0 && connected)
  6163. return new StreamingSocket (inet_ntoa (((struct sockaddr_in*) &address)->sin_addr),
  6164. portNumber, newSocket);
  6165. }
  6166. return 0;
  6167. }
  6168. bool StreamingSocket::isLocal() const throw()
  6169. {
  6170. return hostName == T("127.0.0.1");
  6171. }
  6172. DatagramSocket::DatagramSocket (const int localPortNumber, const bool allowBroadcast_)
  6173. : portNumber (0),
  6174. handle (-1),
  6175. connected (true),
  6176. allowBroadcast (allowBroadcast_),
  6177. serverAddress (0)
  6178. {
  6179. #if JUCE_WINDOWS
  6180. initWin32Sockets();
  6181. #endif
  6182. handle = (int) socket (AF_INET, SOCK_DGRAM, 0);
  6183. bindToPort (localPortNumber);
  6184. }
  6185. DatagramSocket::DatagramSocket (const String& hostName_, const int portNumber_,
  6186. const int handle_, const int localPortNumber)
  6187. : hostName (hostName_),
  6188. portNumber (portNumber_),
  6189. handle (handle_),
  6190. connected (true),
  6191. allowBroadcast (false),
  6192. serverAddress (0)
  6193. {
  6194. #if JUCE_WINDOWS
  6195. initWin32Sockets();
  6196. #endif
  6197. resetSocketOptions (handle_, true, allowBroadcast);
  6198. bindToPort (localPortNumber);
  6199. }
  6200. DatagramSocket::~DatagramSocket()
  6201. {
  6202. close();
  6203. delete ((struct sockaddr_in*) serverAddress);
  6204. serverAddress = 0;
  6205. }
  6206. void DatagramSocket::close()
  6207. {
  6208. #if JUCE_WINDOWS
  6209. closesocket (handle);
  6210. connected = false;
  6211. #else
  6212. connected = false;
  6213. ::close (handle);
  6214. #endif
  6215. hostName = String::empty;
  6216. portNumber = 0;
  6217. handle = -1;
  6218. }
  6219. bool DatagramSocket::bindToPort (const int port)
  6220. {
  6221. return bindSocketToPort (handle, port);
  6222. }
  6223. bool DatagramSocket::connect (const String& remoteHostName,
  6224. const int remotePortNumber,
  6225. const int timeOutMillisecs)
  6226. {
  6227. if (connected)
  6228. close();
  6229. hostName = remoteHostName;
  6230. portNumber = remotePortNumber;
  6231. connected = connectSocket (handle, true, &serverAddress,
  6232. remoteHostName, remotePortNumber,
  6233. timeOutMillisecs);
  6234. if (! (connected && resetSocketOptions (handle, true, allowBroadcast)))
  6235. {
  6236. close();
  6237. return false;
  6238. }
  6239. return true;
  6240. }
  6241. DatagramSocket* DatagramSocket::waitForNextConnection() const
  6242. {
  6243. struct sockaddr address;
  6244. juce_socklen_t len = sizeof (sockaddr);
  6245. while (waitUntilReady (true, -1) == 1)
  6246. {
  6247. char buf[1];
  6248. if (recvfrom (handle, buf, 0, 0, &address, &len) > 0)
  6249. {
  6250. return new DatagramSocket (inet_ntoa (((struct sockaddr_in*) &address)->sin_addr),
  6251. ntohs (((struct sockaddr_in*) &address)->sin_port),
  6252. -1, -1);
  6253. }
  6254. }
  6255. return 0;
  6256. }
  6257. int DatagramSocket::waitUntilReady (const bool readyForReading,
  6258. const int timeoutMsecs) const
  6259. {
  6260. return connected ? waitForReadiness (handle, readyForReading, timeoutMsecs)
  6261. : -1;
  6262. }
  6263. int DatagramSocket::read (void* destBuffer, const int maxBytesToRead, const bool blockUntilSpecifiedAmountHasArrived)
  6264. {
  6265. return connected ? readSocket (handle, destBuffer, maxBytesToRead, connected, blockUntilSpecifiedAmountHasArrived)
  6266. : -1;
  6267. }
  6268. int DatagramSocket::write (const void* sourceBuffer, const int numBytesToWrite)
  6269. {
  6270. // You need to call connect() first to set the server address..
  6271. jassert (serverAddress != 0 && connected);
  6272. return connected ? (int) sendto (handle, (const char*) sourceBuffer,
  6273. numBytesToWrite, 0,
  6274. (const struct sockaddr*) serverAddress,
  6275. sizeof (struct sockaddr_in))
  6276. : -1;
  6277. }
  6278. bool DatagramSocket::isLocal() const throw()
  6279. {
  6280. return hostName == T("127.0.0.1");
  6281. }
  6282. END_JUCE_NAMESPACE
  6283. /********* End of inlined file: juce_Socket.cpp *********/
  6284. /********* Start of inlined file: juce_URL.cpp *********/
  6285. BEGIN_JUCE_NAMESPACE
  6286. URL::URL()
  6287. {
  6288. }
  6289. URL::URL (const String& url_)
  6290. : url (url_)
  6291. {
  6292. int i = url.indexOfChar (T('?'));
  6293. if (i >= 0)
  6294. {
  6295. do
  6296. {
  6297. const int nextAmp = url.indexOfChar (i + 1, T('&'));
  6298. const int equalsPos = url.indexOfChar (i + 1, T('='));
  6299. if (equalsPos > i + 1)
  6300. {
  6301. if (nextAmp < 0)
  6302. {
  6303. parameters.set (removeEscapeChars (url.substring (i + 1, equalsPos)),
  6304. removeEscapeChars (url.substring (equalsPos + 1)));
  6305. }
  6306. else if (nextAmp > 0 && equalsPos < nextAmp)
  6307. {
  6308. parameters.set (removeEscapeChars (url.substring (i + 1, equalsPos)),
  6309. removeEscapeChars (url.substring (equalsPos + 1, nextAmp)));
  6310. }
  6311. }
  6312. i = nextAmp;
  6313. }
  6314. while (i >= 0);
  6315. url = url.upToFirstOccurrenceOf (T("?"), false, false);
  6316. }
  6317. }
  6318. URL::URL (const URL& other)
  6319. : url (other.url),
  6320. postData (other.postData),
  6321. parameters (other.parameters),
  6322. filesToUpload (other.filesToUpload),
  6323. mimeTypes (other.mimeTypes)
  6324. {
  6325. }
  6326. const URL& URL::operator= (const URL& other)
  6327. {
  6328. url = other.url;
  6329. postData = other.postData;
  6330. parameters = other.parameters;
  6331. filesToUpload = other.filesToUpload;
  6332. mimeTypes = other.mimeTypes;
  6333. return *this;
  6334. }
  6335. URL::~URL()
  6336. {
  6337. }
  6338. static const String getMangledParameters (const StringPairArray& parameters)
  6339. {
  6340. String p;
  6341. for (int i = 0; i < parameters.size(); ++i)
  6342. {
  6343. if (i > 0)
  6344. p += T("&");
  6345. p << URL::addEscapeChars (parameters.getAllKeys() [i], true)
  6346. << T("=")
  6347. << URL::addEscapeChars (parameters.getAllValues() [i], true);
  6348. }
  6349. return p;
  6350. }
  6351. const String URL::toString (const bool includeGetParameters) const
  6352. {
  6353. if (includeGetParameters && parameters.size() > 0)
  6354. return url + T("?") + getMangledParameters (parameters);
  6355. else
  6356. return url;
  6357. }
  6358. bool URL::isWellFormed() const
  6359. {
  6360. //xxx TODO
  6361. return url.isNotEmpty();
  6362. }
  6363. static int findStartOfDomain (const String& url)
  6364. {
  6365. int i = 0;
  6366. while (CharacterFunctions::isLetterOrDigit (url[i])
  6367. || CharacterFunctions::indexOfChar (T("+-."), url[i], false) >= 0)
  6368. ++i;
  6369. return url[i] == T(':') ? i + 1 : 0;
  6370. }
  6371. const String URL::getDomain() const
  6372. {
  6373. int start = findStartOfDomain (url);
  6374. while (url[start] == T('/'))
  6375. ++start;
  6376. const int end1 = url.indexOfChar (start, T('/'));
  6377. const int end2 = url.indexOfChar (start, T(':'));
  6378. const int end = (end1 < 0 || end2 < 0) ? jmax (end1, end2)
  6379. : jmin (end1, end2);
  6380. return url.substring (start, end);
  6381. }
  6382. const String URL::getSubPath() const
  6383. {
  6384. int start = findStartOfDomain (url);
  6385. while (url[start] == T('/'))
  6386. ++start;
  6387. const int startOfPath = url.indexOfChar (start, T('/')) + 1;
  6388. return startOfPath <= 0 ? String::empty
  6389. : url.substring (startOfPath);
  6390. }
  6391. const String URL::getScheme() const
  6392. {
  6393. return url.substring (0, findStartOfDomain (url) - 1);
  6394. }
  6395. const URL URL::withNewSubPath (const String& newPath) const
  6396. {
  6397. int start = findStartOfDomain (url);
  6398. while (url[start] == T('/'))
  6399. ++start;
  6400. const int startOfPath = url.indexOfChar (start, T('/')) + 1;
  6401. URL u (*this);
  6402. if (startOfPath > 0)
  6403. u.url = url.substring (0, startOfPath);
  6404. if (! u.url.endsWithChar (T('/')))
  6405. u.url << '/';
  6406. if (newPath.startsWithChar (T('/')))
  6407. u.url << newPath.substring (1);
  6408. else
  6409. u.url << newPath;
  6410. return u;
  6411. }
  6412. bool URL::isProbablyAWebsiteURL (const String& possibleURL)
  6413. {
  6414. if (possibleURL.startsWithIgnoreCase (T("http:"))
  6415. || possibleURL.startsWithIgnoreCase (T("ftp:")))
  6416. return true;
  6417. if (possibleURL.startsWithIgnoreCase (T("file:"))
  6418. || possibleURL.containsChar (T('@'))
  6419. || possibleURL.endsWithChar (T('.'))
  6420. || (! possibleURL.containsChar (T('.'))))
  6421. return false;
  6422. if (possibleURL.startsWithIgnoreCase (T("www."))
  6423. && possibleURL.substring (5).containsChar (T('.')))
  6424. return true;
  6425. const char* commonTLDs[] = { "com", "net", "org", "uk", "de", "fr", "jp" };
  6426. for (int i = 0; i < numElementsInArray (commonTLDs); ++i)
  6427. if ((possibleURL + T("/")).containsIgnoreCase (T(".") + String (commonTLDs[i]) + T("/")))
  6428. return true;
  6429. return false;
  6430. }
  6431. bool URL::isProbablyAnEmailAddress (const String& possibleEmailAddress)
  6432. {
  6433. const int atSign = possibleEmailAddress.indexOfChar (T('@'));
  6434. return atSign > 0
  6435. && possibleEmailAddress.lastIndexOfChar (T('.')) > (atSign + 1)
  6436. && (! possibleEmailAddress.endsWithChar (T('.')));
  6437. }
  6438. void* juce_openInternetFile (const String& url,
  6439. const String& headers,
  6440. const MemoryBlock& optionalPostData,
  6441. const bool isPost,
  6442. URL::OpenStreamProgressCallback* callback,
  6443. void* callbackContext,
  6444. int timeOutMs);
  6445. void juce_closeInternetFile (void* handle);
  6446. int juce_readFromInternetFile (void* handle, void* dest, int bytesToRead);
  6447. int juce_seekInInternetFile (void* handle, int newPosition);
  6448. int64 juce_getInternetFileContentLength (void* handle);
  6449. class WebInputStream : public InputStream
  6450. {
  6451. public:
  6452. WebInputStream (const URL& url,
  6453. const bool isPost_,
  6454. URL::OpenStreamProgressCallback* const progressCallback_,
  6455. void* const progressCallbackContext_,
  6456. const String& extraHeaders,
  6457. int timeOutMs_)
  6458. : position (0),
  6459. finished (false),
  6460. isPost (isPost_),
  6461. progressCallback (progressCallback_),
  6462. progressCallbackContext (progressCallbackContext_),
  6463. timeOutMs (timeOutMs_)
  6464. {
  6465. server = url.toString (! isPost);
  6466. if (isPost_)
  6467. createHeadersAndPostData (url);
  6468. headers += extraHeaders;
  6469. if (! headers.endsWithChar (T('\n')))
  6470. headers << "\r\n";
  6471. handle = juce_openInternetFile (server, headers, postData, isPost,
  6472. progressCallback_, progressCallbackContext_,
  6473. timeOutMs);
  6474. }
  6475. ~WebInputStream()
  6476. {
  6477. juce_closeInternetFile (handle);
  6478. }
  6479. bool isError() const
  6480. {
  6481. return handle == 0;
  6482. }
  6483. int64 getTotalLength()
  6484. {
  6485. return juce_getInternetFileContentLength (handle);
  6486. }
  6487. bool isExhausted()
  6488. {
  6489. return finished;
  6490. }
  6491. int read (void* dest, int bytes)
  6492. {
  6493. if (finished || isError())
  6494. {
  6495. return 0;
  6496. }
  6497. else
  6498. {
  6499. const int bytesRead = juce_readFromInternetFile (handle, dest, bytes);
  6500. position += bytesRead;
  6501. if (bytesRead == 0)
  6502. finished = true;
  6503. return bytesRead;
  6504. }
  6505. }
  6506. int64 getPosition()
  6507. {
  6508. return position;
  6509. }
  6510. bool setPosition (int64 wantedPos)
  6511. {
  6512. if (wantedPos != position)
  6513. {
  6514. finished = false;
  6515. const int actualPos = juce_seekInInternetFile (handle, (int) wantedPos);
  6516. if (actualPos == wantedPos)
  6517. {
  6518. position = wantedPos;
  6519. }
  6520. else
  6521. {
  6522. if (wantedPos < position)
  6523. {
  6524. juce_closeInternetFile (handle);
  6525. position = 0;
  6526. finished = false;
  6527. handle = juce_openInternetFile (server, headers, postData, isPost,
  6528. progressCallback, progressCallbackContext,
  6529. timeOutMs);
  6530. }
  6531. skipNextBytes (wantedPos - position);
  6532. }
  6533. }
  6534. return true;
  6535. }
  6536. juce_UseDebuggingNewOperator
  6537. private:
  6538. String server, headers;
  6539. MemoryBlock postData;
  6540. int64 position;
  6541. bool finished;
  6542. const bool isPost;
  6543. void* handle;
  6544. URL::OpenStreamProgressCallback* const progressCallback;
  6545. void* const progressCallbackContext;
  6546. const int timeOutMs;
  6547. void createHeadersAndPostData (const URL& url)
  6548. {
  6549. if (url.getFilesToUpload().size() > 0)
  6550. {
  6551. // need to upload some files, so do it as multi-part...
  6552. String boundary (String::toHexString (Random::getSystemRandom().nextInt64()));
  6553. headers << "Content-Type: multipart/form-data; boundary=" << boundary << "\r\n";
  6554. appendUTF8ToPostData ("--" + boundary);
  6555. int i;
  6556. for (i = 0; i < url.getParameters().size(); ++i)
  6557. {
  6558. String s;
  6559. s << "\r\nContent-Disposition: form-data; name=\""
  6560. << url.getParameters().getAllKeys() [i]
  6561. << "\"\r\n\r\n"
  6562. << url.getParameters().getAllValues() [i]
  6563. << "\r\n--"
  6564. << boundary;
  6565. appendUTF8ToPostData (s);
  6566. }
  6567. for (i = 0; i < url.getFilesToUpload().size(); ++i)
  6568. {
  6569. const File f (url.getFilesToUpload().getAllValues() [i]);
  6570. const String paramName (url.getFilesToUpload().getAllKeys() [i]);
  6571. String s;
  6572. s << "\r\nContent-Disposition: form-data; name=\""
  6573. << paramName
  6574. << "\"; filename=\""
  6575. << f.getFileName()
  6576. << "\"\r\n";
  6577. const String mimeType (url.getMimeTypesOfUploadFiles()
  6578. .getValue (paramName, String::empty));
  6579. if (mimeType.isNotEmpty())
  6580. s << "Content-Type: " << mimeType << "\r\n";
  6581. s << "Content-Transfer-Encoding: binary\r\n\r\n";
  6582. appendUTF8ToPostData (s);
  6583. f.loadFileAsData (postData);
  6584. s = "\r\n--" + boundary;
  6585. appendUTF8ToPostData (s);
  6586. }
  6587. appendUTF8ToPostData ("--\r\n");
  6588. }
  6589. else
  6590. {
  6591. appendUTF8ToPostData (getMangledParameters (url.getParameters()));
  6592. appendUTF8ToPostData (url.getPostData());
  6593. // just a short text attachment, so use simple url encoding..
  6594. headers = "Content-Type: application/x-www-form-urlencoded\r\nContent-length: "
  6595. + String ((unsigned int) postData.getSize())
  6596. + "\r\n";
  6597. }
  6598. }
  6599. void appendUTF8ToPostData (const String& text)
  6600. {
  6601. postData.append (text.toUTF8(),
  6602. (int) strlen (text.toUTF8()));
  6603. }
  6604. WebInputStream (const WebInputStream&);
  6605. const WebInputStream& operator= (const WebInputStream&);
  6606. };
  6607. InputStream* URL::createInputStream (const bool usePostCommand,
  6608. OpenStreamProgressCallback* const progressCallback,
  6609. void* const progressCallbackContext,
  6610. const String& extraHeaders,
  6611. const int timeOutMs) const
  6612. {
  6613. ScopedPointer <WebInputStream> wi (new WebInputStream (*this, usePostCommand,
  6614. progressCallback, progressCallbackContext,
  6615. extraHeaders,
  6616. timeOutMs));
  6617. return wi->isError() ? 0 : wi.release();
  6618. }
  6619. bool URL::readEntireBinaryStream (MemoryBlock& destData,
  6620. const bool usePostCommand) const
  6621. {
  6622. const ScopedPointer <InputStream> in (createInputStream (usePostCommand));
  6623. if (in != 0)
  6624. {
  6625. in->readIntoMemoryBlock (destData, -1);
  6626. return true;
  6627. }
  6628. return false;
  6629. }
  6630. const String URL::readEntireTextStream (const bool usePostCommand) const
  6631. {
  6632. const ScopedPointer <InputStream> in (createInputStream (usePostCommand));
  6633. if (in != 0)
  6634. return in->readEntireStreamAsString();
  6635. return String::empty;
  6636. }
  6637. XmlElement* URL::readEntireXmlStream (const bool usePostCommand) const
  6638. {
  6639. XmlDocument doc (readEntireTextStream (usePostCommand));
  6640. return doc.getDocumentElement();
  6641. }
  6642. const URL URL::withParameter (const String& parameterName,
  6643. const String& parameterValue) const
  6644. {
  6645. URL u (*this);
  6646. u.parameters.set (parameterName, parameterValue);
  6647. return u;
  6648. }
  6649. const URL URL::withFileToUpload (const String& parameterName,
  6650. const File& fileToUpload,
  6651. const String& mimeType) const
  6652. {
  6653. jassert (mimeType.isNotEmpty()); // You need to supply a mime type!
  6654. URL u (*this);
  6655. u.filesToUpload.set (parameterName, fileToUpload.getFullPathName());
  6656. u.mimeTypes.set (parameterName, mimeType);
  6657. return u;
  6658. }
  6659. const URL URL::withPOSTData (const String& postData_) const
  6660. {
  6661. URL u (*this);
  6662. u.postData = postData_;
  6663. return u;
  6664. }
  6665. const StringPairArray& URL::getParameters() const
  6666. {
  6667. return parameters;
  6668. }
  6669. const StringPairArray& URL::getFilesToUpload() const
  6670. {
  6671. return filesToUpload;
  6672. }
  6673. const StringPairArray& URL::getMimeTypesOfUploadFiles() const
  6674. {
  6675. return mimeTypes;
  6676. }
  6677. const String URL::removeEscapeChars (const String& s)
  6678. {
  6679. const int len = s.length();
  6680. HeapBlock <uint8> resultUTF8 (len * 4);
  6681. uint8* r = resultUTF8;
  6682. for (int i = 0; i < len; ++i)
  6683. {
  6684. char c = (char) s[i];
  6685. if (c == 0)
  6686. break;
  6687. if (c == '+')
  6688. {
  6689. c = ' ';
  6690. }
  6691. else if (c == '%')
  6692. {
  6693. c = (char) s.substring (i + 1, i + 3).getHexValue32();
  6694. i += 2;
  6695. }
  6696. *r++ = c;
  6697. }
  6698. return String::fromUTF8 (resultUTF8);
  6699. }
  6700. const String URL::addEscapeChars (const String& s, const bool isParameter)
  6701. {
  6702. String result;
  6703. result.preallocateStorage (s.length() + 8);
  6704. const char* utf8 = s.toUTF8();
  6705. const char* legalChars = isParameter ? "_-.*!'()"
  6706. : "_-$.*!'(),";
  6707. while (*utf8 != 0)
  6708. {
  6709. const char c = *utf8++;
  6710. if (CharacterFunctions::isLetterOrDigit (c)
  6711. || CharacterFunctions::indexOfChar (legalChars, c, false) >= 0)
  6712. {
  6713. result << c;
  6714. }
  6715. else
  6716. {
  6717. const int v = (int) (uint8) c;
  6718. if (v < 0x10)
  6719. result << T("%0");
  6720. else
  6721. result << T('%');
  6722. result << String::toHexString (v);
  6723. }
  6724. }
  6725. return result;
  6726. }
  6727. extern bool juce_launchFile (const String& fileName, const String& parameters);
  6728. bool URL::launchInDefaultBrowser() const
  6729. {
  6730. String u (toString (true));
  6731. if (u.contains (T("@")) && ! u.contains (T(":")))
  6732. u = "mailto:" + u;
  6733. return juce_launchFile (u, String::empty);
  6734. }
  6735. END_JUCE_NAMESPACE
  6736. /********* End of inlined file: juce_URL.cpp *********/
  6737. /********* Start of inlined file: juce_BufferedInputStream.cpp *********/
  6738. BEGIN_JUCE_NAMESPACE
  6739. BufferedInputStream::BufferedInputStream (InputStream* const source_,
  6740. const int bufferSize_,
  6741. const bool deleteSourceWhenDestroyed)
  6742. : source (source_),
  6743. sourceToDelete (deleteSourceWhenDestroyed ? source_ : 0),
  6744. bufferSize (jmax (256, bufferSize_)),
  6745. position (source_->getPosition()),
  6746. lastReadPos (0),
  6747. bufferOverlap (128)
  6748. {
  6749. const int sourceSize = (int) source_->getTotalLength();
  6750. if (sourceSize >= 0)
  6751. bufferSize = jmin (jmax (32, sourceSize), bufferSize);
  6752. bufferStart = position;
  6753. buffer.malloc (bufferSize);
  6754. }
  6755. BufferedInputStream::~BufferedInputStream()
  6756. {
  6757. }
  6758. int64 BufferedInputStream::getTotalLength()
  6759. {
  6760. return source->getTotalLength();
  6761. }
  6762. int64 BufferedInputStream::getPosition()
  6763. {
  6764. return position;
  6765. }
  6766. bool BufferedInputStream::setPosition (int64 newPosition)
  6767. {
  6768. position = jmax ((int64) 0, newPosition);
  6769. return true;
  6770. }
  6771. bool BufferedInputStream::isExhausted()
  6772. {
  6773. return (position >= lastReadPos)
  6774. && source->isExhausted();
  6775. }
  6776. void BufferedInputStream::ensureBuffered()
  6777. {
  6778. const int64 bufferEndOverlap = lastReadPos - bufferOverlap;
  6779. if (position < bufferStart || position >= bufferEndOverlap)
  6780. {
  6781. int bytesRead;
  6782. if (position < lastReadPos
  6783. && position >= bufferEndOverlap
  6784. && position >= bufferStart)
  6785. {
  6786. const int bytesToKeep = (int) (lastReadPos - position);
  6787. memmove (buffer, buffer + (int) (position - bufferStart), bytesToKeep);
  6788. bufferStart = position;
  6789. bytesRead = source->read (buffer + bytesToKeep,
  6790. bufferSize - bytesToKeep);
  6791. lastReadPos += bytesRead;
  6792. bytesRead += bytesToKeep;
  6793. }
  6794. else
  6795. {
  6796. bufferStart = position;
  6797. source->setPosition (bufferStart);
  6798. bytesRead = source->read (buffer, bufferSize);
  6799. lastReadPos = bufferStart + bytesRead;
  6800. }
  6801. while (bytesRead < bufferSize)
  6802. buffer [bytesRead++] = 0;
  6803. }
  6804. }
  6805. int BufferedInputStream::read (void* destBuffer, int maxBytesToRead)
  6806. {
  6807. if (position >= bufferStart
  6808. && position + maxBytesToRead <= lastReadPos)
  6809. {
  6810. memcpy (destBuffer, buffer + (int) (position - bufferStart), maxBytesToRead);
  6811. position += maxBytesToRead;
  6812. return maxBytesToRead;
  6813. }
  6814. else
  6815. {
  6816. if (position < bufferStart || position >= lastReadPos)
  6817. ensureBuffered();
  6818. int bytesRead = 0;
  6819. while (maxBytesToRead > 0)
  6820. {
  6821. const int bytesAvailable = jmin (maxBytesToRead, (int) (lastReadPos - position));
  6822. if (bytesAvailable > 0)
  6823. {
  6824. memcpy (destBuffer, buffer + (int) (position - bufferStart), bytesAvailable);
  6825. maxBytesToRead -= bytesAvailable;
  6826. bytesRead += bytesAvailable;
  6827. position += bytesAvailable;
  6828. destBuffer = (void*) (((char*) destBuffer) + bytesAvailable);
  6829. }
  6830. const int64 oldLastReadPos = lastReadPos;
  6831. ensureBuffered();
  6832. if (oldLastReadPos == lastReadPos)
  6833. break; // if ensureBuffered() failed to read any more data, bail out
  6834. if (isExhausted())
  6835. break;
  6836. }
  6837. return bytesRead;
  6838. }
  6839. }
  6840. const String BufferedInputStream::readString()
  6841. {
  6842. if (position >= bufferStart
  6843. && position < lastReadPos)
  6844. {
  6845. const int maxChars = (int) (lastReadPos - position);
  6846. const char* const src = buffer + (int) (position - bufferStart);
  6847. for (int i = 0; i < maxChars; ++i)
  6848. {
  6849. if (src[i] == 0)
  6850. {
  6851. position += i + 1;
  6852. return String::fromUTF8 ((const uint8*) src, i);
  6853. }
  6854. }
  6855. }
  6856. return InputStream::readString();
  6857. }
  6858. END_JUCE_NAMESPACE
  6859. /********* End of inlined file: juce_BufferedInputStream.cpp *********/
  6860. /********* Start of inlined file: juce_FileInputSource.cpp *********/
  6861. BEGIN_JUCE_NAMESPACE
  6862. FileInputSource::FileInputSource (const File& file_)
  6863. : file (file_)
  6864. {
  6865. }
  6866. FileInputSource::~FileInputSource()
  6867. {
  6868. }
  6869. InputStream* FileInputSource::createInputStream()
  6870. {
  6871. return file.createInputStream();
  6872. }
  6873. InputStream* FileInputSource::createInputStreamFor (const String& relatedItemPath)
  6874. {
  6875. return file.getSiblingFile (relatedItemPath).createInputStream();
  6876. }
  6877. int64 FileInputSource::hashCode() const
  6878. {
  6879. return file.hashCode();
  6880. }
  6881. END_JUCE_NAMESPACE
  6882. /********* End of inlined file: juce_FileInputSource.cpp *********/
  6883. /********* Start of inlined file: juce_MemoryInputStream.cpp *********/
  6884. BEGIN_JUCE_NAMESPACE
  6885. MemoryInputStream::MemoryInputStream (const void* const sourceData,
  6886. const size_t sourceDataSize,
  6887. const bool keepInternalCopy)
  6888. : data ((const char*) sourceData),
  6889. dataSize (sourceDataSize),
  6890. position (0)
  6891. {
  6892. if (keepInternalCopy)
  6893. {
  6894. internalCopy.append (data, sourceDataSize);
  6895. data = (const char*) internalCopy.getData();
  6896. }
  6897. }
  6898. MemoryInputStream::~MemoryInputStream()
  6899. {
  6900. }
  6901. int64 MemoryInputStream::getTotalLength()
  6902. {
  6903. return dataSize;
  6904. }
  6905. int MemoryInputStream::read (void* buffer, int howMany)
  6906. {
  6907. jassert (howMany >= 0);
  6908. const int num = jmin (howMany, (int) (dataSize - position));
  6909. memcpy (buffer, data + position, num);
  6910. position += num;
  6911. return (int) num;
  6912. }
  6913. bool MemoryInputStream::isExhausted()
  6914. {
  6915. return (position >= dataSize);
  6916. }
  6917. bool MemoryInputStream::setPosition (int64 pos)
  6918. {
  6919. position = (int) jlimit ((int64) 0, (int64) dataSize, pos);
  6920. return true;
  6921. }
  6922. int64 MemoryInputStream::getPosition()
  6923. {
  6924. return position;
  6925. }
  6926. END_JUCE_NAMESPACE
  6927. /********* End of inlined file: juce_MemoryInputStream.cpp *********/
  6928. /********* Start of inlined file: juce_MemoryOutputStream.cpp *********/
  6929. BEGIN_JUCE_NAMESPACE
  6930. MemoryOutputStream::MemoryOutputStream (const size_t initialSize,
  6931. const size_t blockSizeToIncreaseBy,
  6932. MemoryBlock* const memoryBlockToWriteTo) throw()
  6933. : data (memoryBlockToWriteTo),
  6934. position (0),
  6935. size (0),
  6936. blockSize (jmax ((size_t) 16, blockSizeToIncreaseBy))
  6937. {
  6938. if (data == 0)
  6939. dataToDelete = data = new MemoryBlock (initialSize);
  6940. else
  6941. data->setSize (initialSize, false);
  6942. }
  6943. MemoryOutputStream::~MemoryOutputStream() throw()
  6944. {
  6945. flush();
  6946. }
  6947. void MemoryOutputStream::flush()
  6948. {
  6949. if (dataToDelete == 0)
  6950. data->setSize (size, false);
  6951. }
  6952. void MemoryOutputStream::reset() throw()
  6953. {
  6954. position = 0;
  6955. size = 0;
  6956. }
  6957. bool MemoryOutputStream::write (const void* buffer, int howMany)
  6958. {
  6959. if (howMany > 0)
  6960. {
  6961. size_t storageNeeded = position + howMany;
  6962. if (storageNeeded >= data->getSize())
  6963. {
  6964. // if we need more space, increase the block by at least 10%..
  6965. storageNeeded += jmax (blockSize, storageNeeded / 10);
  6966. storageNeeded = storageNeeded - (storageNeeded % blockSize) + blockSize;
  6967. data->ensureSize (storageNeeded);
  6968. }
  6969. data->copyFrom (buffer, (int) position, howMany);
  6970. position += howMany;
  6971. size = jmax (size, position);
  6972. }
  6973. return true;
  6974. }
  6975. const char* MemoryOutputStream::getData() throw()
  6976. {
  6977. if (data->getSize() > size)
  6978. ((char*) data->getData()) [size] = 0;
  6979. return (const char*) data->getData();
  6980. }
  6981. size_t MemoryOutputStream::getDataSize() const throw()
  6982. {
  6983. return size;
  6984. }
  6985. int64 MemoryOutputStream::getPosition()
  6986. {
  6987. return position;
  6988. }
  6989. bool MemoryOutputStream::setPosition (int64 newPosition)
  6990. {
  6991. if (newPosition <= (int64) size)
  6992. {
  6993. // ok to seek backwards
  6994. position = jlimit ((size_t) 0, size, (size_t) newPosition);
  6995. return true;
  6996. }
  6997. else
  6998. {
  6999. // trying to make it bigger isn't a good thing to do..
  7000. return false;
  7001. }
  7002. }
  7003. END_JUCE_NAMESPACE
  7004. /********* End of inlined file: juce_MemoryOutputStream.cpp *********/
  7005. /********* Start of inlined file: juce_SubregionStream.cpp *********/
  7006. BEGIN_JUCE_NAMESPACE
  7007. SubregionStream::SubregionStream (InputStream* const sourceStream,
  7008. const int64 startPositionInSourceStream_,
  7009. const int64 lengthOfSourceStream_,
  7010. const bool deleteSourceWhenDestroyed) throw()
  7011. : source (sourceStream),
  7012. startPositionInSourceStream (startPositionInSourceStream_),
  7013. lengthOfSourceStream (lengthOfSourceStream_)
  7014. {
  7015. if (deleteSourceWhenDestroyed)
  7016. sourceToDelete = source;
  7017. setPosition (0);
  7018. }
  7019. SubregionStream::~SubregionStream() throw()
  7020. {
  7021. }
  7022. int64 SubregionStream::getTotalLength()
  7023. {
  7024. const int64 srcLen = source->getTotalLength() - startPositionInSourceStream;
  7025. return (lengthOfSourceStream >= 0) ? jmin (lengthOfSourceStream, srcLen)
  7026. : srcLen;
  7027. }
  7028. int64 SubregionStream::getPosition()
  7029. {
  7030. return source->getPosition() - startPositionInSourceStream;
  7031. }
  7032. bool SubregionStream::setPosition (int64 newPosition)
  7033. {
  7034. return source->setPosition (jmax ((int64) 0, newPosition + startPositionInSourceStream));
  7035. }
  7036. int SubregionStream::read (void* destBuffer, int maxBytesToRead)
  7037. {
  7038. if (lengthOfSourceStream < 0)
  7039. {
  7040. return source->read (destBuffer, maxBytesToRead);
  7041. }
  7042. else
  7043. {
  7044. maxBytesToRead = (int) jmin ((int64) maxBytesToRead, lengthOfSourceStream - getPosition());
  7045. if (maxBytesToRead <= 0)
  7046. return 0;
  7047. return source->read (destBuffer, maxBytesToRead);
  7048. }
  7049. }
  7050. bool SubregionStream::isExhausted()
  7051. {
  7052. if (lengthOfSourceStream >= 0)
  7053. return (getPosition() >= lengthOfSourceStream) || source->isExhausted();
  7054. else
  7055. return source->isExhausted();
  7056. }
  7057. END_JUCE_NAMESPACE
  7058. /********* End of inlined file: juce_SubregionStream.cpp *********/
  7059. /********* Start of inlined file: juce_PerformanceCounter.cpp *********/
  7060. BEGIN_JUCE_NAMESPACE
  7061. PerformanceCounter::PerformanceCounter (const String& name_,
  7062. int runsPerPrintout,
  7063. const File& loggingFile)
  7064. : name (name_),
  7065. numRuns (0),
  7066. runsPerPrint (runsPerPrintout),
  7067. totalTime (0),
  7068. outputFile (loggingFile)
  7069. {
  7070. if (outputFile != File::nonexistent)
  7071. {
  7072. String s ("**** Counter for \"");
  7073. s << name_ << "\" started at: "
  7074. << Time::getCurrentTime().toString (true, true)
  7075. << "\r\n";
  7076. outputFile.appendText (s, false, false);
  7077. }
  7078. }
  7079. PerformanceCounter::~PerformanceCounter()
  7080. {
  7081. printStatistics();
  7082. }
  7083. void PerformanceCounter::start()
  7084. {
  7085. started = Time::getHighResolutionTicks();
  7086. }
  7087. void PerformanceCounter::stop()
  7088. {
  7089. const int64 now = Time::getHighResolutionTicks();
  7090. totalTime += 1000.0 * Time::highResolutionTicksToSeconds (now - started);
  7091. if (++numRuns == runsPerPrint)
  7092. printStatistics();
  7093. }
  7094. void PerformanceCounter::printStatistics()
  7095. {
  7096. if (numRuns > 0)
  7097. {
  7098. String s ("Performance count for \"");
  7099. s << name << "\" - average over " << numRuns << " run(s) = ";
  7100. const int micros = (int) (totalTime * (1000.0 / numRuns));
  7101. if (micros > 10000)
  7102. s << (micros/1000) << " millisecs";
  7103. else
  7104. s << micros << " microsecs";
  7105. s << ", total = " << String (totalTime / 1000, 5) << " seconds";
  7106. Logger::outputDebugString (s);
  7107. s << "\r\n";
  7108. if (outputFile != File::nonexistent)
  7109. outputFile.appendText (s, false, false);
  7110. numRuns = 0;
  7111. totalTime = 0;
  7112. }
  7113. }
  7114. END_JUCE_NAMESPACE
  7115. /********* End of inlined file: juce_PerformanceCounter.cpp *********/
  7116. /********* Start of inlined file: juce_Uuid.cpp *********/
  7117. BEGIN_JUCE_NAMESPACE
  7118. Uuid::Uuid()
  7119. {
  7120. // Mix up any available MAC addresses with some time-based pseudo-random numbers
  7121. // to make it very very unlikely that two UUIDs will ever be the same..
  7122. static int64 macAddresses[2];
  7123. static bool hasCheckedMacAddresses = false;
  7124. if (! hasCheckedMacAddresses)
  7125. {
  7126. hasCheckedMacAddresses = true;
  7127. SystemStats::getMACAddresses (macAddresses, 2);
  7128. }
  7129. value.asInt64[0] = macAddresses[0];
  7130. value.asInt64[1] = macAddresses[1];
  7131. // We'll use both a local RNG that is re-seeded, plus the shared RNG,
  7132. // whose seed will carry over between calls to this method.
  7133. Random r (macAddresses[0] ^ macAddresses[1]
  7134. ^ Random::getSystemRandom().nextInt64());
  7135. for (int i = 4; --i >= 0;)
  7136. {
  7137. r.setSeedRandomly(); // calling this repeatedly improves randomness
  7138. value.asInt[i] ^= r.nextInt();
  7139. value.asInt[i] ^= Random::getSystemRandom().nextInt();
  7140. }
  7141. }
  7142. Uuid::~Uuid() throw()
  7143. {
  7144. }
  7145. Uuid::Uuid (const Uuid& other)
  7146. : value (other.value)
  7147. {
  7148. }
  7149. Uuid& Uuid::operator= (const Uuid& other)
  7150. {
  7151. value = other.value;
  7152. return *this;
  7153. }
  7154. bool Uuid::operator== (const Uuid& other) const
  7155. {
  7156. return memcmp (value.asBytes, other.value.asBytes, 16) == 0;
  7157. }
  7158. bool Uuid::operator!= (const Uuid& other) const
  7159. {
  7160. return ! operator== (other);
  7161. }
  7162. bool Uuid::isNull() const throw()
  7163. {
  7164. return (value.asInt64 [0] == 0) && (value.asInt64 [1] == 0);
  7165. }
  7166. const String Uuid::toString() const
  7167. {
  7168. return String::toHexString (value.asBytes, 16, 0);
  7169. }
  7170. Uuid::Uuid (const String& uuidString)
  7171. {
  7172. operator= (uuidString);
  7173. }
  7174. Uuid& Uuid::operator= (const String& uuidString)
  7175. {
  7176. int destIndex = 0;
  7177. int i = 0;
  7178. for (;;)
  7179. {
  7180. int byte = 0;
  7181. for (int loop = 2; --loop >= 0;)
  7182. {
  7183. byte <<= 4;
  7184. for (;;)
  7185. {
  7186. const tchar c = uuidString [i++];
  7187. if (c >= T('0') && c <= T('9'))
  7188. {
  7189. byte |= c - T('0');
  7190. break;
  7191. }
  7192. else if (c >= T('a') && c <= T('z'))
  7193. {
  7194. byte |= c - (T('a') - 10);
  7195. break;
  7196. }
  7197. else if (c >= T('A') && c <= T('Z'))
  7198. {
  7199. byte |= c - (T('A') - 10);
  7200. break;
  7201. }
  7202. else if (c == 0)
  7203. {
  7204. while (destIndex < 16)
  7205. value.asBytes [destIndex++] = 0;
  7206. return *this;
  7207. }
  7208. }
  7209. }
  7210. value.asBytes [destIndex++] = (uint8) byte;
  7211. }
  7212. }
  7213. Uuid::Uuid (const uint8* const rawData)
  7214. {
  7215. operator= (rawData);
  7216. }
  7217. Uuid& Uuid::operator= (const uint8* const rawData)
  7218. {
  7219. if (rawData != 0)
  7220. memcpy (value.asBytes, rawData, 16);
  7221. else
  7222. zeromem (value.asBytes, 16);
  7223. return *this;
  7224. }
  7225. END_JUCE_NAMESPACE
  7226. /********* End of inlined file: juce_Uuid.cpp *********/
  7227. /********* Start of inlined file: juce_ZipFile.cpp *********/
  7228. BEGIN_JUCE_NAMESPACE
  7229. class ZipFile::ZipEntryInfo
  7230. {
  7231. public:
  7232. ZipFile::ZipEntry entry;
  7233. int streamOffset;
  7234. int compressedSize;
  7235. bool compressed;
  7236. };
  7237. class ZipFile::ZipInputStream : public InputStream
  7238. {
  7239. public:
  7240. ZipInputStream (ZipFile& file_, ZipFile::ZipEntryInfo& zei)
  7241. : file (file_),
  7242. zipEntryInfo (zei),
  7243. pos (0),
  7244. headerSize (0),
  7245. inputStream (0)
  7246. {
  7247. inputStream = file_.inputStream;
  7248. if (file_.inputSource != 0)
  7249. {
  7250. inputStream = file.inputSource->createInputStream();
  7251. }
  7252. else
  7253. {
  7254. #ifdef JUCE_DEBUG
  7255. file_.numOpenStreams++;
  7256. #endif
  7257. }
  7258. char buffer [30];
  7259. if (inputStream != 0
  7260. && inputStream->setPosition (zei.streamOffset)
  7261. && inputStream->read (buffer, 30) == 30
  7262. && ByteOrder::littleEndianInt (buffer) == 0x04034b50)
  7263. {
  7264. headerSize = 30 + ByteOrder::littleEndianShort (buffer + 26)
  7265. + ByteOrder::littleEndianShort (buffer + 28);
  7266. }
  7267. }
  7268. ~ZipInputStream() throw()
  7269. {
  7270. #ifdef JUCE_DEBUG
  7271. if (inputStream != 0 && inputStream == file.inputStream)
  7272. file.numOpenStreams--;
  7273. #endif
  7274. if (inputStream != file.inputStream)
  7275. delete inputStream;
  7276. }
  7277. int64 getTotalLength() throw()
  7278. {
  7279. return zipEntryInfo.compressedSize;
  7280. }
  7281. int read (void* buffer, int howMany) throw()
  7282. {
  7283. if (headerSize <= 0)
  7284. return 0;
  7285. howMany = (int) jmin ((int64) howMany, zipEntryInfo.compressedSize - pos);
  7286. if (inputStream == 0)
  7287. return 0;
  7288. int num;
  7289. if (inputStream == file.inputStream)
  7290. {
  7291. const ScopedLock sl (file.lock);
  7292. inputStream->setPosition (pos + zipEntryInfo.streamOffset + headerSize);
  7293. num = inputStream->read (buffer, howMany);
  7294. }
  7295. else
  7296. {
  7297. inputStream->setPosition (pos + zipEntryInfo.streamOffset + headerSize);
  7298. num = inputStream->read (buffer, howMany);
  7299. }
  7300. pos += num;
  7301. return num;
  7302. }
  7303. bool isExhausted() throw()
  7304. {
  7305. return headerSize <= 0 || pos >= zipEntryInfo.compressedSize;
  7306. }
  7307. int64 getPosition() throw()
  7308. {
  7309. return pos;
  7310. }
  7311. bool setPosition (int64 newPos) throw()
  7312. {
  7313. pos = jlimit ((int64) 0, (int64) zipEntryInfo.compressedSize, newPos);
  7314. return true;
  7315. }
  7316. private:
  7317. ZipFile& file;
  7318. ZipEntryInfo zipEntryInfo;
  7319. int64 pos;
  7320. int headerSize;
  7321. InputStream* inputStream;
  7322. ZipInputStream (const ZipInputStream&);
  7323. const ZipInputStream& operator= (const ZipInputStream&);
  7324. };
  7325. ZipFile::ZipFile (InputStream* const source_,
  7326. const bool deleteStreamWhenDestroyed) throw()
  7327. : inputStream (source_)
  7328. #ifdef JUCE_DEBUG
  7329. , numOpenStreams (0)
  7330. #endif
  7331. {
  7332. if (deleteStreamWhenDestroyed)
  7333. streamToDelete = inputStream;
  7334. init();
  7335. }
  7336. ZipFile::ZipFile (const File& file)
  7337. : inputStream (0)
  7338. #ifdef JUCE_DEBUG
  7339. , numOpenStreams (0)
  7340. #endif
  7341. {
  7342. inputSource = new FileInputSource (file);
  7343. init();
  7344. }
  7345. ZipFile::ZipFile (InputSource* const inputSource_)
  7346. : inputStream (0),
  7347. inputSource (inputSource_)
  7348. #ifdef JUCE_DEBUG
  7349. , numOpenStreams (0)
  7350. #endif
  7351. {
  7352. init();
  7353. }
  7354. ZipFile::~ZipFile() throw()
  7355. {
  7356. #ifdef JUCE_DEBUG
  7357. entries.clear();
  7358. // If you hit this assertion, it means you've created a stream to read
  7359. // one of the items in the zipfile, but you've forgotten to delete that
  7360. // stream object before deleting the file.. Streams can't be kept open
  7361. // after the file is deleted because they need to share the input
  7362. // stream that the file uses to read itself.
  7363. jassert (numOpenStreams == 0);
  7364. #endif
  7365. }
  7366. int ZipFile::getNumEntries() const throw()
  7367. {
  7368. return entries.size();
  7369. }
  7370. const ZipFile::ZipEntry* ZipFile::getEntry (const int index) const throw()
  7371. {
  7372. ZipEntryInfo* const zei = (ZipEntryInfo*) entries [index];
  7373. return (zei != 0) ? &(zei->entry)
  7374. : 0;
  7375. }
  7376. int ZipFile::getIndexOfFileName (const String& fileName) const throw()
  7377. {
  7378. for (int i = 0; i < entries.size(); ++i)
  7379. if (entries.getUnchecked (i)->entry.filename == fileName)
  7380. return i;
  7381. return -1;
  7382. }
  7383. const ZipFile::ZipEntry* ZipFile::getEntry (const String& fileName) const throw()
  7384. {
  7385. return getEntry (getIndexOfFileName (fileName));
  7386. }
  7387. InputStream* ZipFile::createStreamForEntry (const int index)
  7388. {
  7389. ZipEntryInfo* const zei = entries[index];
  7390. InputStream* stream = 0;
  7391. if (zei != 0)
  7392. {
  7393. stream = new ZipInputStream (*this, *zei);
  7394. if (zei->compressed)
  7395. {
  7396. stream = new GZIPDecompressorInputStream (stream, true, true,
  7397. zei->entry.uncompressedSize);
  7398. // (much faster to unzip in big blocks using a buffer..)
  7399. stream = new BufferedInputStream (stream, 32768, true);
  7400. }
  7401. }
  7402. return stream;
  7403. }
  7404. class ZipFile::ZipFilenameComparator
  7405. {
  7406. public:
  7407. int compareElements (const ZipFile::ZipEntryInfo* first, const ZipFile::ZipEntryInfo* second)
  7408. {
  7409. return first->entry.filename.compare (second->entry.filename);
  7410. }
  7411. };
  7412. void ZipFile::sortEntriesByFilename()
  7413. {
  7414. ZipFilenameComparator sorter;
  7415. entries.sort (sorter);
  7416. }
  7417. void ZipFile::init()
  7418. {
  7419. ScopedPointer <InputStream> toDelete;
  7420. InputStream* in = inputStream;
  7421. if (inputSource != 0)
  7422. {
  7423. in = inputSource->createInputStream();
  7424. toDelete = in;
  7425. }
  7426. if (in != 0)
  7427. {
  7428. int numEntries = 0;
  7429. int pos = findEndOfZipEntryTable (in, numEntries);
  7430. if (pos >= 0 && pos < in->getTotalLength())
  7431. {
  7432. const int size = (int) (in->getTotalLength() - pos);
  7433. in->setPosition (pos);
  7434. MemoryBlock headerData;
  7435. if (in->readIntoMemoryBlock (headerData, size) == size)
  7436. {
  7437. pos = 0;
  7438. for (int i = 0; i < numEntries; ++i)
  7439. {
  7440. if (pos + 46 > size)
  7441. break;
  7442. const char* const buffer = ((const char*) headerData.getData()) + pos;
  7443. const int fileNameLen = ByteOrder::littleEndianShort (buffer + 28);
  7444. if (pos + 46 + fileNameLen > size)
  7445. break;
  7446. ZipEntryInfo* const zei = new ZipEntryInfo();
  7447. zei->entry.filename = String::fromUTF8 ((const uint8*) buffer + 46, fileNameLen);
  7448. const int time = ByteOrder::littleEndianShort (buffer + 12);
  7449. const int date = ByteOrder::littleEndianShort (buffer + 14);
  7450. const int year = 1980 + (date >> 9);
  7451. const int month = ((date >> 5) & 15) - 1;
  7452. const int day = date & 31;
  7453. const int hours = time >> 11;
  7454. const int minutes = (time >> 5) & 63;
  7455. const int seconds = (time & 31) << 1;
  7456. zei->entry.fileTime = Time (year, month, day, hours, minutes, seconds);
  7457. zei->compressed = ByteOrder::littleEndianShort (buffer + 10) != 0;
  7458. zei->compressedSize = ByteOrder::littleEndianInt (buffer + 20);
  7459. zei->entry.uncompressedSize = ByteOrder::littleEndianInt (buffer + 24);
  7460. zei->streamOffset = ByteOrder::littleEndianInt (buffer + 42);
  7461. entries.add (zei);
  7462. pos += 46 + fileNameLen
  7463. + ByteOrder::littleEndianShort (buffer + 30)
  7464. + ByteOrder::littleEndianShort (buffer + 32);
  7465. }
  7466. }
  7467. }
  7468. }
  7469. }
  7470. int ZipFile::findEndOfZipEntryTable (InputStream* input, int& numEntries)
  7471. {
  7472. BufferedInputStream in (input, 8192, false);
  7473. in.setPosition (in.getTotalLength());
  7474. int64 pos = in.getPosition();
  7475. const int64 lowestPos = jmax ((int64) 0, pos - 1024);
  7476. char buffer [32];
  7477. zeromem (buffer, sizeof (buffer));
  7478. while (pos > lowestPos)
  7479. {
  7480. in.setPosition (pos - 22);
  7481. pos = in.getPosition();
  7482. memcpy (buffer + 22, buffer, 4);
  7483. if (in.read (buffer, 22) != 22)
  7484. return 0;
  7485. for (int i = 0; i < 22; ++i)
  7486. {
  7487. if (ByteOrder::littleEndianInt (buffer + i) == 0x06054b50)
  7488. {
  7489. in.setPosition (pos + i);
  7490. in.read (buffer, 22);
  7491. numEntries = ByteOrder::littleEndianShort (buffer + 10);
  7492. return ByteOrder::littleEndianInt (buffer + 16);
  7493. }
  7494. }
  7495. }
  7496. return 0;
  7497. }
  7498. void ZipFile::uncompressTo (const File& targetDirectory,
  7499. const bool shouldOverwriteFiles)
  7500. {
  7501. for (int i = 0; i < entries.size(); ++i)
  7502. {
  7503. const ZipEntry& zei = entries.getUnchecked(i)->entry;
  7504. const File targetFile (targetDirectory.getChildFile (zei.filename));
  7505. if (zei.filename.endsWithChar (T('/')))
  7506. {
  7507. targetFile.createDirectory(); // (entry is a directory, not a file)
  7508. }
  7509. else
  7510. {
  7511. ScopedPointer <InputStream> in (createStreamForEntry (i));
  7512. if (in != 0)
  7513. {
  7514. if (shouldOverwriteFiles)
  7515. targetFile.deleteFile();
  7516. if ((! targetFile.exists())
  7517. && targetFile.getParentDirectory().createDirectory())
  7518. {
  7519. ScopedPointer <FileOutputStream> out (targetFile.createOutputStream());
  7520. if (out != 0)
  7521. {
  7522. out->writeFromInputStream (*in, -1);
  7523. out = 0;
  7524. targetFile.setCreationTime (zei.fileTime);
  7525. targetFile.setLastModificationTime (zei.fileTime);
  7526. targetFile.setLastAccessTime (zei.fileTime);
  7527. }
  7528. }
  7529. }
  7530. }
  7531. }
  7532. }
  7533. END_JUCE_NAMESPACE
  7534. /********* End of inlined file: juce_ZipFile.cpp *********/
  7535. /********* Start of inlined file: juce_CharacterFunctions.cpp *********/
  7536. #ifdef _MSC_VER
  7537. #pragma warning (disable: 4514 4996)
  7538. #pragma warning (push)
  7539. #endif
  7540. #include <cwctype>
  7541. #include <cctype>
  7542. #include <ctime>
  7543. #ifdef _MSC_VER
  7544. #pragma warning (pop)
  7545. #endif
  7546. BEGIN_JUCE_NAMESPACE
  7547. int CharacterFunctions::length (const char* const s) throw()
  7548. {
  7549. return (int) strlen (s);
  7550. }
  7551. int CharacterFunctions::length (const juce_wchar* const s) throw()
  7552. {
  7553. return (int) wcslen (s);
  7554. }
  7555. void CharacterFunctions::copy (char* dest, const char* src, const int maxChars) throw()
  7556. {
  7557. strncpy (dest, src, maxChars);
  7558. }
  7559. void CharacterFunctions::copy (juce_wchar* dest, const juce_wchar* src, int maxChars) throw()
  7560. {
  7561. wcsncpy (dest, src, maxChars);
  7562. }
  7563. void CharacterFunctions::copy (juce_wchar* dest, const char* src, const int maxChars) throw()
  7564. {
  7565. mbstowcs (dest, src, maxChars);
  7566. }
  7567. void CharacterFunctions::copy (char* dest, const juce_wchar* src, const int maxChars) throw()
  7568. {
  7569. wcstombs (dest, src, maxChars);
  7570. }
  7571. int CharacterFunctions::bytesRequiredForCopy (const juce_wchar* src) throw()
  7572. {
  7573. return (int) wcstombs (0, src, 0);
  7574. }
  7575. void CharacterFunctions::append (char* dest, const char* src) throw()
  7576. {
  7577. strcat (dest, src);
  7578. }
  7579. void CharacterFunctions::append (juce_wchar* dest, const juce_wchar* src) throw()
  7580. {
  7581. wcscat (dest, src);
  7582. }
  7583. int CharacterFunctions::compare (const char* const s1, const char* const s2) throw()
  7584. {
  7585. return strcmp (s1, s2);
  7586. }
  7587. int CharacterFunctions::compare (const juce_wchar* s1, const juce_wchar* s2) throw()
  7588. {
  7589. jassert (s1 != 0 && s2 != 0);
  7590. return wcscmp (s1, s2);
  7591. }
  7592. int CharacterFunctions::compare (const char* const s1, const char* const s2, const int maxChars) throw()
  7593. {
  7594. jassert (s1 != 0 && s2 != 0);
  7595. return strncmp (s1, s2, maxChars);
  7596. }
  7597. int CharacterFunctions::compare (const juce_wchar* s1, const juce_wchar* s2, int maxChars) throw()
  7598. {
  7599. jassert (s1 != 0 && s2 != 0);
  7600. return wcsncmp (s1, s2, maxChars);
  7601. }
  7602. int CharacterFunctions::compareIgnoreCase (const char* const s1, const char* const s2) throw()
  7603. {
  7604. jassert (s1 != 0 && s2 != 0);
  7605. #if JUCE_WIN32
  7606. return stricmp (s1, s2);
  7607. #else
  7608. return strcasecmp (s1, s2);
  7609. #endif
  7610. }
  7611. int CharacterFunctions::compareIgnoreCase (const juce_wchar* s1, const juce_wchar* s2) throw()
  7612. {
  7613. jassert (s1 != 0 && s2 != 0);
  7614. #if JUCE_WIN32
  7615. return _wcsicmp (s1, s2);
  7616. #else
  7617. for (;;)
  7618. {
  7619. if (*s1 != *s2)
  7620. {
  7621. const int diff = toUpperCase (*s1) - toUpperCase (*s2);
  7622. if (diff != 0)
  7623. return diff < 0 ? -1 : 1;
  7624. }
  7625. else if (*s1 == 0)
  7626. break;
  7627. ++s1;
  7628. ++s2;
  7629. }
  7630. return 0;
  7631. #endif
  7632. }
  7633. int CharacterFunctions::compareIgnoreCase (const char* const s1, const char* const s2, const int maxChars) throw()
  7634. {
  7635. jassert (s1 != 0 && s2 != 0);
  7636. #if JUCE_WIN32
  7637. return strnicmp (s1, s2, maxChars);
  7638. #else
  7639. return strncasecmp (s1, s2, maxChars);
  7640. #endif
  7641. }
  7642. int CharacterFunctions::compareIgnoreCase (const juce_wchar* s1, const juce_wchar* s2, int maxChars) throw()
  7643. {
  7644. jassert (s1 != 0 && s2 != 0);
  7645. #if JUCE_WIN32
  7646. return _wcsnicmp (s1, s2, maxChars);
  7647. #else
  7648. while (--maxChars >= 0)
  7649. {
  7650. if (*s1 != *s2)
  7651. {
  7652. const int diff = toUpperCase (*s1) - toUpperCase (*s2);
  7653. if (diff != 0)
  7654. return diff < 0 ? -1 : 1;
  7655. }
  7656. else if (*s1 == 0)
  7657. break;
  7658. ++s1;
  7659. ++s2;
  7660. }
  7661. return 0;
  7662. #endif
  7663. }
  7664. const char* CharacterFunctions::find (const char* const haystack, const char* const needle) throw()
  7665. {
  7666. return strstr (haystack, needle);
  7667. }
  7668. const juce_wchar* CharacterFunctions::find (const juce_wchar* haystack, const juce_wchar* const needle) throw()
  7669. {
  7670. return wcsstr (haystack, needle);
  7671. }
  7672. int CharacterFunctions::indexOfChar (const char* const haystack, const char needle, const bool ignoreCase) throw()
  7673. {
  7674. if (haystack != 0)
  7675. {
  7676. int i = 0;
  7677. if (ignoreCase)
  7678. {
  7679. const char n1 = toLowerCase (needle);
  7680. const char n2 = toUpperCase (needle);
  7681. if (n1 != n2) // if the char is the same in upper/lower case, fall through to the normal search
  7682. {
  7683. while (haystack[i] != 0)
  7684. {
  7685. if (haystack[i] == n1 || haystack[i] == n2)
  7686. return i;
  7687. ++i;
  7688. }
  7689. return -1;
  7690. }
  7691. jassert (n1 == needle);
  7692. }
  7693. while (haystack[i] != 0)
  7694. {
  7695. if (haystack[i] == needle)
  7696. return i;
  7697. ++i;
  7698. }
  7699. }
  7700. return -1;
  7701. }
  7702. int CharacterFunctions::indexOfChar (const juce_wchar* const haystack, const juce_wchar needle, const bool ignoreCase) throw()
  7703. {
  7704. if (haystack != 0)
  7705. {
  7706. int i = 0;
  7707. if (ignoreCase)
  7708. {
  7709. const juce_wchar n1 = toLowerCase (needle);
  7710. const juce_wchar n2 = toUpperCase (needle);
  7711. if (n1 != n2) // if the char is the same in upper/lower case, fall through to the normal search
  7712. {
  7713. while (haystack[i] != 0)
  7714. {
  7715. if (haystack[i] == n1 || haystack[i] == n2)
  7716. return i;
  7717. ++i;
  7718. }
  7719. return -1;
  7720. }
  7721. jassert (n1 == needle);
  7722. }
  7723. while (haystack[i] != 0)
  7724. {
  7725. if (haystack[i] == needle)
  7726. return i;
  7727. ++i;
  7728. }
  7729. }
  7730. return -1;
  7731. }
  7732. int CharacterFunctions::indexOfCharFast (const char* const haystack, const char needle) throw()
  7733. {
  7734. jassert (haystack != 0);
  7735. int i = 0;
  7736. while (haystack[i] != 0)
  7737. {
  7738. if (haystack[i] == needle)
  7739. return i;
  7740. ++i;
  7741. }
  7742. return -1;
  7743. }
  7744. int CharacterFunctions::indexOfCharFast (const juce_wchar* const haystack, const juce_wchar needle) throw()
  7745. {
  7746. jassert (haystack != 0);
  7747. int i = 0;
  7748. while (haystack[i] != 0)
  7749. {
  7750. if (haystack[i] == needle)
  7751. return i;
  7752. ++i;
  7753. }
  7754. return -1;
  7755. }
  7756. int CharacterFunctions::getIntialSectionContainingOnly (const char* const text, const char* const allowedChars) throw()
  7757. {
  7758. return allowedChars == 0 ? 0 : (int) strspn (text, allowedChars);
  7759. }
  7760. int CharacterFunctions::getIntialSectionContainingOnly (const juce_wchar* const text, const juce_wchar* const allowedChars) throw()
  7761. {
  7762. if (allowedChars == 0)
  7763. return 0;
  7764. int i = 0;
  7765. for (;;)
  7766. {
  7767. if (indexOfCharFast (allowedChars, text[i]) < 0)
  7768. break;
  7769. ++i;
  7770. }
  7771. return i;
  7772. }
  7773. int CharacterFunctions::ftime (char* const dest, const int maxChars, const char* const format, const struct tm* const tm) throw()
  7774. {
  7775. return (int) strftime (dest, maxChars, format, tm);
  7776. }
  7777. int CharacterFunctions::ftime (juce_wchar* const dest, const int maxChars, const juce_wchar* const format, const struct tm* const tm) throw()
  7778. {
  7779. return (int) wcsftime (dest, maxChars, format, tm);
  7780. }
  7781. int CharacterFunctions::getIntValue (const char* const s) throw()
  7782. {
  7783. return atoi (s);
  7784. }
  7785. int CharacterFunctions::getIntValue (const juce_wchar* s) throw()
  7786. {
  7787. #if JUCE_WIN32
  7788. return _wtoi (s);
  7789. #else
  7790. int v = 0;
  7791. while (isWhitespace (*s))
  7792. ++s;
  7793. const bool isNeg = *s == T('-');
  7794. if (isNeg)
  7795. ++s;
  7796. for (;;)
  7797. {
  7798. const wchar_t c = *s++;
  7799. if (c >= T('0') && c <= T('9'))
  7800. v = v * 10 + (int) (c - T('0'));
  7801. else
  7802. break;
  7803. }
  7804. return isNeg ? -v : v;
  7805. #endif
  7806. }
  7807. int64 CharacterFunctions::getInt64Value (const char* s) throw()
  7808. {
  7809. #if JUCE_LINUX
  7810. return atoll (s);
  7811. #elif defined (JUCE_WIN32)
  7812. return _atoi64 (s);
  7813. #else
  7814. int64 v = 0;
  7815. while (isWhitespace (*s))
  7816. ++s;
  7817. const bool isNeg = *s == T('-');
  7818. if (isNeg)
  7819. ++s;
  7820. for (;;)
  7821. {
  7822. const char c = *s++;
  7823. if (c >= '0' && c <= '9')
  7824. v = v * 10 + (int64) (c - '0');
  7825. else
  7826. break;
  7827. }
  7828. return isNeg ? -v : v;
  7829. #endif
  7830. }
  7831. int64 CharacterFunctions::getInt64Value (const juce_wchar* s) throw()
  7832. {
  7833. #if JUCE_WIN32
  7834. return _wtoi64 (s);
  7835. #else
  7836. int64 v = 0;
  7837. while (isWhitespace (*s))
  7838. ++s;
  7839. const bool isNeg = *s == T('-');
  7840. if (isNeg)
  7841. ++s;
  7842. for (;;)
  7843. {
  7844. const juce_wchar c = *s++;
  7845. if (c >= T('0') && c <= T('9'))
  7846. v = v * 10 + (int64) (c - T('0'));
  7847. else
  7848. break;
  7849. }
  7850. return isNeg ? -v : v;
  7851. #endif
  7852. }
  7853. static double juce_mulexp10 (const double value, int exponent) throw()
  7854. {
  7855. if (exponent == 0)
  7856. return value;
  7857. if (value == 0)
  7858. return 0;
  7859. const bool negative = (exponent < 0);
  7860. if (negative)
  7861. exponent = -exponent;
  7862. double result = 1.0, power = 10.0;
  7863. for (int bit = 1; exponent != 0; bit <<= 1)
  7864. {
  7865. if ((exponent & bit) != 0)
  7866. {
  7867. exponent ^= bit;
  7868. result *= power;
  7869. if (exponent == 0)
  7870. break;
  7871. }
  7872. power *= power;
  7873. }
  7874. return negative ? (value / result) : (value * result);
  7875. }
  7876. template <class CharType>
  7877. double juce_atof (const CharType* const original) throw()
  7878. {
  7879. double result[3] = { 0, 0, 0 }, accumulator[2] = { 0, 0 };
  7880. int exponentAdjustment[2] = { 0, 0 }, exponentAccumulator[2] = { -1, -1 };
  7881. int exponent = 0, decPointIndex = 0, digit = 0;
  7882. int lastDigit = 0, numSignificantDigits = 0;
  7883. bool isNegative = false, digitsFound = false;
  7884. const int maxSignificantDigits = 15 + 2;
  7885. const CharType* s = original;
  7886. while (CharacterFunctions::isWhitespace (*s))
  7887. ++s;
  7888. switch (*s)
  7889. {
  7890. case '-': isNegative = true; // fall-through..
  7891. case '+': ++s;
  7892. }
  7893. if (*s == 'n' || *s == 'N' || *s == 'i' || *s == 'I')
  7894. return atof (String (original)); // Let the c library deal with NAN and INF
  7895. for (;;)
  7896. {
  7897. if (CharacterFunctions::isDigit (*s))
  7898. {
  7899. lastDigit = digit;
  7900. digit = *s++ - '0';
  7901. digitsFound = true;
  7902. if (decPointIndex != 0)
  7903. exponentAdjustment[1]++;
  7904. if (numSignificantDigits == 0 && digit == 0)
  7905. continue;
  7906. if (++numSignificantDigits > maxSignificantDigits)
  7907. {
  7908. if (digit > 5)
  7909. ++accumulator [decPointIndex];
  7910. else if (digit == 5 && (lastDigit & 1) != 0)
  7911. ++accumulator [decPointIndex];
  7912. if (decPointIndex > 0)
  7913. exponentAdjustment[1]--;
  7914. else
  7915. exponentAdjustment[0]++;
  7916. while (CharacterFunctions::isDigit (*s))
  7917. {
  7918. ++s;
  7919. if (decPointIndex == 0)
  7920. exponentAdjustment[0]++;
  7921. }
  7922. }
  7923. else
  7924. {
  7925. const double maxAccumulatorValue = (double) ((UINT_MAX - 9) / 10);
  7926. if (accumulator [decPointIndex] > maxAccumulatorValue)
  7927. {
  7928. result [decPointIndex] = juce_mulexp10 (result [decPointIndex], exponentAccumulator [decPointIndex])
  7929. + accumulator [decPointIndex];
  7930. accumulator [decPointIndex] = 0;
  7931. exponentAccumulator [decPointIndex] = 0;
  7932. }
  7933. accumulator [decPointIndex] = accumulator[decPointIndex] * 10 + digit;
  7934. exponentAccumulator [decPointIndex]++;
  7935. }
  7936. }
  7937. else if (decPointIndex == 0 && *s == '.')
  7938. {
  7939. ++s;
  7940. decPointIndex = 1;
  7941. if (numSignificantDigits > maxSignificantDigits)
  7942. {
  7943. while (CharacterFunctions::isDigit (*s))
  7944. ++s;
  7945. break;
  7946. }
  7947. }
  7948. else
  7949. {
  7950. break;
  7951. }
  7952. }
  7953. result[0] = juce_mulexp10 (result[0], exponentAccumulator[0]) + accumulator[0];
  7954. if (decPointIndex != 0)
  7955. result[1] = juce_mulexp10 (result[1], exponentAccumulator[1]) + accumulator[1];
  7956. if ((*s == 'e' || *s == 'E') && digitsFound)
  7957. {
  7958. bool negativeExponent = false;
  7959. switch (*++s)
  7960. {
  7961. case '-': negativeExponent = true; // fall-through..
  7962. case '+': ++s;
  7963. }
  7964. while (CharacterFunctions::isDigit (*s))
  7965. exponent = (exponent * 10) + (*s++ - '0');
  7966. if (negativeExponent)
  7967. exponent = -exponent;
  7968. }
  7969. double r = juce_mulexp10 (result[0], exponent + exponentAdjustment[0]);
  7970. if (decPointIndex != 0)
  7971. r += juce_mulexp10 (result[1], exponent - exponentAdjustment[1]);
  7972. return isNegative ? -r : r;
  7973. }
  7974. double CharacterFunctions::getDoubleValue (const char* const s) throw()
  7975. {
  7976. return juce_atof <char> (s);
  7977. }
  7978. double CharacterFunctions::getDoubleValue (const juce_wchar* const s) throw()
  7979. {
  7980. return juce_atof <juce_wchar> (s);
  7981. }
  7982. char CharacterFunctions::toUpperCase (const char character) throw()
  7983. {
  7984. return (char) toupper (character);
  7985. }
  7986. juce_wchar CharacterFunctions::toUpperCase (const juce_wchar character) throw()
  7987. {
  7988. return towupper (character);
  7989. }
  7990. void CharacterFunctions::toUpperCase (char* s) throw()
  7991. {
  7992. #if JUCE_WIN32
  7993. strupr (s);
  7994. #else
  7995. while (*s != 0)
  7996. {
  7997. *s = toUpperCase (*s);
  7998. ++s;
  7999. }
  8000. #endif
  8001. }
  8002. void CharacterFunctions::toUpperCase (juce_wchar* s) throw()
  8003. {
  8004. #if JUCE_WIN32
  8005. _wcsupr (s);
  8006. #else
  8007. while (*s != 0)
  8008. {
  8009. *s = toUpperCase (*s);
  8010. ++s;
  8011. }
  8012. #endif
  8013. }
  8014. bool CharacterFunctions::isUpperCase (const char character) throw()
  8015. {
  8016. return isupper (character) != 0;
  8017. }
  8018. bool CharacterFunctions::isUpperCase (const juce_wchar character) throw()
  8019. {
  8020. #if JUCE_WIN32
  8021. return iswupper (character) != 0;
  8022. #else
  8023. return toLowerCase (character) != character;
  8024. #endif
  8025. }
  8026. char CharacterFunctions::toLowerCase (const char character) throw()
  8027. {
  8028. return (char) tolower (character);
  8029. }
  8030. juce_wchar CharacterFunctions::toLowerCase (const juce_wchar character) throw()
  8031. {
  8032. return towlower (character);
  8033. }
  8034. void CharacterFunctions::toLowerCase (char* s) throw()
  8035. {
  8036. #if JUCE_WIN32
  8037. strlwr (s);
  8038. #else
  8039. while (*s != 0)
  8040. {
  8041. *s = toLowerCase (*s);
  8042. ++s;
  8043. }
  8044. #endif
  8045. }
  8046. void CharacterFunctions::toLowerCase (juce_wchar* s) throw()
  8047. {
  8048. #if JUCE_WIN32
  8049. _wcslwr (s);
  8050. #else
  8051. while (*s != 0)
  8052. {
  8053. *s = toLowerCase (*s);
  8054. ++s;
  8055. }
  8056. #endif
  8057. }
  8058. bool CharacterFunctions::isLowerCase (const char character) throw()
  8059. {
  8060. return islower (character) != 0;
  8061. }
  8062. bool CharacterFunctions::isLowerCase (const juce_wchar character) throw()
  8063. {
  8064. #if JUCE_WIN32
  8065. return iswlower (character) != 0;
  8066. #else
  8067. return toUpperCase (character) != character;
  8068. #endif
  8069. }
  8070. bool CharacterFunctions::isWhitespace (const char character) throw()
  8071. {
  8072. return character == T(' ') || (character <= 13 && character >= 9);
  8073. }
  8074. bool CharacterFunctions::isWhitespace (const juce_wchar character) throw()
  8075. {
  8076. return iswspace (character) != 0;
  8077. }
  8078. bool CharacterFunctions::isDigit (const char character) throw()
  8079. {
  8080. return (character >= '0' && character <= '9');
  8081. }
  8082. bool CharacterFunctions::isDigit (const juce_wchar character) throw()
  8083. {
  8084. return iswdigit (character) != 0;
  8085. }
  8086. bool CharacterFunctions::isLetter (const char character) throw()
  8087. {
  8088. return (character >= 'a' && character <= 'z')
  8089. || (character >= 'A' && character <= 'Z');
  8090. }
  8091. bool CharacterFunctions::isLetter (const juce_wchar character) throw()
  8092. {
  8093. return iswalpha (character) != 0;
  8094. }
  8095. bool CharacterFunctions::isLetterOrDigit (const char character) throw()
  8096. {
  8097. return (character >= 'a' && character <= 'z')
  8098. || (character >= 'A' && character <= 'Z')
  8099. || (character >= '0' && character <= '9');
  8100. }
  8101. bool CharacterFunctions::isLetterOrDigit (const juce_wchar character) throw()
  8102. {
  8103. return iswalnum (character) != 0;
  8104. }
  8105. int CharacterFunctions::getHexDigitValue (const tchar digit) throw()
  8106. {
  8107. if (digit >= T('0') && digit <= T('9'))
  8108. return digit - T('0');
  8109. else if (digit >= T('a') && digit <= T('f'))
  8110. return digit - (T('a') - 10);
  8111. else if (digit >= T('A') && digit <= T('F'))
  8112. return digit - (T('A') - 10);
  8113. return -1;
  8114. }
  8115. int CharacterFunctions::printf (char* const dest, const int maxLength, const char* const format, ...) throw()
  8116. {
  8117. va_list list;
  8118. va_start (list, format);
  8119. return vprintf (dest, maxLength, format, list);
  8120. }
  8121. int CharacterFunctions::printf (juce_wchar* const dest, const int maxLength, const juce_wchar* const format, ...) throw()
  8122. {
  8123. va_list list;
  8124. va_start (list, format);
  8125. return vprintf (dest, maxLength, format, list);
  8126. }
  8127. int CharacterFunctions::vprintf (char* const dest, const int maxLength, const char* const format, va_list& args) throw()
  8128. {
  8129. #if JUCE_WIN32
  8130. return (int) _vsnprintf (dest, maxLength, format, args);
  8131. #else
  8132. return (int) vsnprintf (dest, maxLength, format, args);
  8133. #endif
  8134. }
  8135. int CharacterFunctions::vprintf (juce_wchar* const dest, const int maxLength, const juce_wchar* const format, va_list& args) throw()
  8136. {
  8137. #if defined (JUCE_WIN32)
  8138. return (int) _vsnwprintf (dest, maxLength, format, args);
  8139. #else
  8140. return (int) vswprintf (dest, maxLength, format, args);
  8141. #endif
  8142. }
  8143. END_JUCE_NAMESPACE
  8144. /********* End of inlined file: juce_CharacterFunctions.cpp *********/
  8145. /********* Start of inlined file: juce_LocalisedStrings.cpp *********/
  8146. BEGIN_JUCE_NAMESPACE
  8147. LocalisedStrings::LocalisedStrings (const String& fileContents)
  8148. {
  8149. loadFromText (fileContents);
  8150. }
  8151. LocalisedStrings::LocalisedStrings (const File& fileToLoad)
  8152. {
  8153. loadFromText (fileToLoad.loadFileAsString());
  8154. }
  8155. LocalisedStrings::~LocalisedStrings()
  8156. {
  8157. }
  8158. const String LocalisedStrings::translate (const String& text) const
  8159. {
  8160. return translations.getValue (text, text);
  8161. }
  8162. static int findCloseQuote (const String& text, int startPos)
  8163. {
  8164. tchar lastChar = 0;
  8165. for (;;)
  8166. {
  8167. const tchar c = text [startPos];
  8168. if (c == 0 || (c == T('"') && lastChar != T('\\')))
  8169. break;
  8170. lastChar = c;
  8171. ++startPos;
  8172. }
  8173. return startPos;
  8174. }
  8175. static const String unescapeString (const String& s)
  8176. {
  8177. return s.replace (T("\\\""), T("\""))
  8178. .replace (T("\\\'"), T("\'"))
  8179. .replace (T("\\t"), T("\t"))
  8180. .replace (T("\\r"), T("\r"))
  8181. .replace (T("\\n"), T("\n"));
  8182. }
  8183. void LocalisedStrings::loadFromText (const String& fileContents)
  8184. {
  8185. StringArray lines;
  8186. lines.addLines (fileContents);
  8187. for (int i = 0; i < lines.size(); ++i)
  8188. {
  8189. String line (lines[i].trim());
  8190. if (line.startsWithChar (T('"')))
  8191. {
  8192. int closeQuote = findCloseQuote (line, 1);
  8193. const String originalText (unescapeString (line.substring (1, closeQuote)));
  8194. if (originalText.isNotEmpty())
  8195. {
  8196. const int openingQuote = findCloseQuote (line, closeQuote + 1);
  8197. closeQuote = findCloseQuote (line, openingQuote + 1);
  8198. const String newText (unescapeString (line.substring (openingQuote + 1, closeQuote)));
  8199. if (newText.isNotEmpty())
  8200. translations.set (originalText, newText);
  8201. }
  8202. }
  8203. else if (line.startsWithIgnoreCase (T("language:")))
  8204. {
  8205. languageName = line.substring (9).trim();
  8206. }
  8207. else if (line.startsWithIgnoreCase (T("countries:")))
  8208. {
  8209. countryCodes.addTokens (line.substring (10).trim(), true);
  8210. countryCodes.trim();
  8211. countryCodes.removeEmptyStrings();
  8212. }
  8213. }
  8214. }
  8215. void LocalisedStrings::setIgnoresCase (const bool shouldIgnoreCase)
  8216. {
  8217. translations.setIgnoresCase (shouldIgnoreCase);
  8218. }
  8219. static CriticalSection currentMappingsLock;
  8220. static LocalisedStrings* currentMappings = 0;
  8221. void LocalisedStrings::setCurrentMappings (LocalisedStrings* newTranslations)
  8222. {
  8223. const ScopedLock sl (currentMappingsLock);
  8224. delete currentMappings;
  8225. currentMappings = newTranslations;
  8226. }
  8227. LocalisedStrings* LocalisedStrings::getCurrentMappings()
  8228. {
  8229. return currentMappings;
  8230. }
  8231. const String LocalisedStrings::translateWithCurrentMappings (const String& text)
  8232. {
  8233. const ScopedLock sl (currentMappingsLock);
  8234. if (currentMappings != 0)
  8235. return currentMappings->translate (text);
  8236. return text;
  8237. }
  8238. const String LocalisedStrings::translateWithCurrentMappings (const char* text)
  8239. {
  8240. return translateWithCurrentMappings (String (text));
  8241. }
  8242. END_JUCE_NAMESPACE
  8243. /********* End of inlined file: juce_LocalisedStrings.cpp *********/
  8244. /********* Start of inlined file: juce_String.cpp *********/
  8245. #ifdef _MSC_VER
  8246. #pragma warning (disable: 4514)
  8247. #pragma warning (push)
  8248. #endif
  8249. #include <locale>
  8250. #if JUCE_MSVC
  8251. #include <float.h>
  8252. #endif
  8253. BEGIN_JUCE_NAMESPACE
  8254. #ifdef _MSC_VER
  8255. #pragma warning (pop)
  8256. #endif
  8257. static const char* const emptyCharString = "\0\0\0\0JUCE";
  8258. static const int safeEmptyStringRefCount = 0x3fffffff;
  8259. String::InternalRefCountedStringHolder String::emptyString = { safeEmptyStringRefCount, 0, { 0 } };
  8260. static tchar decimalPoint = T('.');
  8261. void juce_initialiseStrings()
  8262. {
  8263. decimalPoint = String::fromUTF8 ((const uint8*) localeconv()->decimal_point) [0];
  8264. }
  8265. void String::deleteInternal() throw()
  8266. {
  8267. if (Atomic::decrementAndReturn (text->refCount) == 0)
  8268. juce_free (text);
  8269. }
  8270. void String::createInternal (const int numChars) throw()
  8271. {
  8272. jassert (numChars > 0);
  8273. text = (InternalRefCountedStringHolder*) juce_malloc (sizeof (InternalRefCountedStringHolder)
  8274. + numChars * sizeof (tchar));
  8275. text->refCount = 1;
  8276. text->allocatedNumChars = numChars;
  8277. text->text[0] = 0;
  8278. }
  8279. void String::createInternal (const tchar* const t, const tchar* const textEnd) throw()
  8280. {
  8281. jassert (*(textEnd - 1) == 0); // must have a null terminator
  8282. const int numChars = (int) (textEnd - t);
  8283. createInternal (numChars - 1);
  8284. memcpy (text->text, t, numChars * sizeof (tchar));
  8285. }
  8286. void String::appendInternal (const tchar* const newText,
  8287. const int numExtraChars) throw()
  8288. {
  8289. if (numExtraChars > 0)
  8290. {
  8291. const int oldLen = CharacterFunctions::length (text->text);
  8292. const int newTotalLen = oldLen + numExtraChars;
  8293. if (text->refCount > 1)
  8294. {
  8295. // it's in use by other strings as well, so we need to make a private copy before messing with it..
  8296. InternalRefCountedStringHolder* const newTextHolder
  8297. = (InternalRefCountedStringHolder*) juce_malloc (sizeof (InternalRefCountedStringHolder)
  8298. + newTotalLen * sizeof (tchar));
  8299. newTextHolder->refCount = 1;
  8300. newTextHolder->allocatedNumChars = newTotalLen;
  8301. memcpy (newTextHolder->text, text->text, oldLen * sizeof (tchar));
  8302. memcpy (newTextHolder->text + oldLen, newText, numExtraChars * sizeof (tchar));
  8303. InternalRefCountedStringHolder* const old = text;
  8304. text = newTextHolder;
  8305. if (Atomic::decrementAndReturn (old->refCount) == 0)
  8306. juce_free (old);
  8307. }
  8308. else
  8309. {
  8310. // no other strings using it, so just expand it if needed..
  8311. if (newTotalLen > text->allocatedNumChars)
  8312. {
  8313. text = (InternalRefCountedStringHolder*)
  8314. juce_realloc (text, sizeof (InternalRefCountedStringHolder)
  8315. + newTotalLen * sizeof (tchar));
  8316. text->allocatedNumChars = newTotalLen;
  8317. }
  8318. memcpy (text->text + oldLen, newText, numExtraChars * sizeof (tchar));
  8319. }
  8320. text->text [newTotalLen] = 0;
  8321. }
  8322. }
  8323. void String::dupeInternalIfMultiplyReferenced() throw()
  8324. {
  8325. if (text->refCount > 1)
  8326. {
  8327. InternalRefCountedStringHolder* const old = text;
  8328. const int len = old->allocatedNumChars;
  8329. InternalRefCountedStringHolder* const newTextHolder
  8330. = (InternalRefCountedStringHolder*) juce_malloc (sizeof (InternalRefCountedStringHolder)
  8331. + len * sizeof (tchar));
  8332. newTextHolder->refCount = 1;
  8333. newTextHolder->allocatedNumChars = len;
  8334. memcpy (newTextHolder->text, old->text, (len + 1) * sizeof (tchar));
  8335. text = newTextHolder;
  8336. if (Atomic::decrementAndReturn (old->refCount) == 0)
  8337. juce_free (old);
  8338. }
  8339. }
  8340. const String String::empty;
  8341. String::String() throw()
  8342. : text (&emptyString)
  8343. {
  8344. }
  8345. String::String (const String& other) throw()
  8346. : text (other.text)
  8347. {
  8348. Atomic::increment (text->refCount);
  8349. }
  8350. String::String (const int numChars,
  8351. const int /*dummyVariable*/) throw()
  8352. {
  8353. createInternal (numChars);
  8354. }
  8355. String::String (const char* const t) throw()
  8356. {
  8357. if (t != 0 && *t != 0)
  8358. {
  8359. const int len = CharacterFunctions::length (t);
  8360. createInternal (len);
  8361. #if JUCE_STRINGS_ARE_UNICODE
  8362. CharacterFunctions::copy (text->text, t, len + 1);
  8363. #else
  8364. memcpy (text->text, t, len + 1);
  8365. #endif
  8366. }
  8367. else
  8368. {
  8369. text = &emptyString;
  8370. emptyString.refCount = safeEmptyStringRefCount;
  8371. }
  8372. }
  8373. String::String (const juce_wchar* const t) throw()
  8374. {
  8375. if (t != 0 && *t != 0)
  8376. {
  8377. #if JUCE_STRINGS_ARE_UNICODE
  8378. const int len = CharacterFunctions::length (t);
  8379. createInternal (len);
  8380. memcpy (text->text, t, (len + 1) * sizeof (tchar));
  8381. #else
  8382. const int len = CharacterFunctions::bytesRequiredForCopy (t);
  8383. createInternal (len);
  8384. CharacterFunctions::copy (text->text, t, len + 1);
  8385. #endif
  8386. }
  8387. else
  8388. {
  8389. text = &emptyString;
  8390. emptyString.refCount = safeEmptyStringRefCount;
  8391. }
  8392. }
  8393. String::String (const char* const t,
  8394. const size_t maxChars) throw()
  8395. {
  8396. int i;
  8397. for (i = 0; (size_t) i < maxChars; ++i)
  8398. if (t[i] == 0)
  8399. break;
  8400. if (i > 0)
  8401. {
  8402. createInternal (i);
  8403. #if JUCE_STRINGS_ARE_UNICODE
  8404. CharacterFunctions::copy (text->text, t, i);
  8405. #else
  8406. memcpy (text->text, t, i);
  8407. #endif
  8408. text->text [i] = 0;
  8409. }
  8410. else
  8411. {
  8412. text = &emptyString;
  8413. emptyString.refCount = safeEmptyStringRefCount;
  8414. }
  8415. }
  8416. String::String (const juce_wchar* const t,
  8417. const size_t maxChars) throw()
  8418. {
  8419. int i;
  8420. for (i = 0; (size_t) i < maxChars; ++i)
  8421. if (t[i] == 0)
  8422. break;
  8423. if (i > 0)
  8424. {
  8425. createInternal (i);
  8426. #if JUCE_STRINGS_ARE_UNICODE
  8427. memcpy (text->text, t, i * sizeof (tchar));
  8428. #else
  8429. CharacterFunctions::copy (text->text, t, i);
  8430. #endif
  8431. text->text [i] = 0;
  8432. }
  8433. else
  8434. {
  8435. text = &emptyString;
  8436. emptyString.refCount = safeEmptyStringRefCount;
  8437. }
  8438. }
  8439. const String String::charToString (const tchar character) throw()
  8440. {
  8441. tchar temp[2];
  8442. temp[0] = character;
  8443. temp[1] = 0;
  8444. return String (temp);
  8445. }
  8446. // pass in a pointer to the END of a buffer..
  8447. static tchar* int64ToCharString (tchar* t, const int64 n) throw()
  8448. {
  8449. *--t = 0;
  8450. int64 v = (n >= 0) ? n : -n;
  8451. do
  8452. {
  8453. *--t = (tchar) (T('0') + (int) (v % 10));
  8454. v /= 10;
  8455. } while (v > 0);
  8456. if (n < 0)
  8457. *--t = T('-');
  8458. return t;
  8459. }
  8460. static tchar* intToCharString (tchar* t, const int n) throw()
  8461. {
  8462. if (n == (int) 0x80000000) // (would cause an overflow)
  8463. return int64ToCharString (t, n);
  8464. *--t = 0;
  8465. int v = abs (n);
  8466. do
  8467. {
  8468. *--t = (tchar) (T('0') + (v % 10));
  8469. v /= 10;
  8470. } while (v > 0);
  8471. if (n < 0)
  8472. *--t = T('-');
  8473. return t;
  8474. }
  8475. static tchar* uintToCharString (tchar* t, unsigned int v) throw()
  8476. {
  8477. *--t = 0;
  8478. do
  8479. {
  8480. *--t = (tchar) (T('0') + (v % 10));
  8481. v /= 10;
  8482. } while (v > 0);
  8483. return t;
  8484. }
  8485. String::String (const int number) throw()
  8486. {
  8487. tchar buffer [16];
  8488. tchar* const end = buffer + 16;
  8489. createInternal (intToCharString (end, number), end);
  8490. }
  8491. String::String (const unsigned int number) throw()
  8492. {
  8493. tchar buffer [16];
  8494. tchar* const end = buffer + 16;
  8495. createInternal (uintToCharString (end, number), end);
  8496. }
  8497. String::String (const short number) throw()
  8498. {
  8499. tchar buffer [16];
  8500. tchar* const end = buffer + 16;
  8501. createInternal (intToCharString (end, (int) number), end);
  8502. }
  8503. String::String (const unsigned short number) throw()
  8504. {
  8505. tchar buffer [16];
  8506. tchar* const end = buffer + 16;
  8507. createInternal (uintToCharString (end, (unsigned int) number), end);
  8508. }
  8509. String::String (const int64 number) throw()
  8510. {
  8511. tchar buffer [32];
  8512. tchar* const end = buffer + 32;
  8513. createInternal (int64ToCharString (end, number), end);
  8514. }
  8515. String::String (const uint64 number) throw()
  8516. {
  8517. tchar buffer [32];
  8518. tchar* const end = buffer + 32;
  8519. tchar* t = end;
  8520. *--t = 0;
  8521. int64 v = number;
  8522. do
  8523. {
  8524. *--t = (tchar) (T('0') + (int) (v % 10));
  8525. v /= 10;
  8526. } while (v > 0);
  8527. createInternal (t, end);
  8528. }
  8529. // a double-to-string routine that actually uses the number of dec. places you asked for
  8530. // without resorting to exponent notation if the number's too big or small (which is what printf does).
  8531. void String::doubleToStringWithDecPlaces (double n, int numDecPlaces) throw()
  8532. {
  8533. const int bufSize = 80;
  8534. tchar buffer [bufSize];
  8535. int len;
  8536. tchar* t;
  8537. if (numDecPlaces > 0 && n > -1.0e20 && n < 1.0e20)
  8538. {
  8539. int64 v = (int64) (pow (10.0, numDecPlaces) * fabs (n) + 0.5);
  8540. t = buffer + bufSize;
  8541. *--t = (tchar) 0;
  8542. while (numDecPlaces >= 0 || v > 0)
  8543. {
  8544. if (numDecPlaces == 0)
  8545. *--t = decimalPoint;
  8546. *--t = (tchar) (T('0') + (v % 10));
  8547. v /= 10;
  8548. --numDecPlaces;
  8549. }
  8550. if (n < 0)
  8551. *--t = T('-');
  8552. len = (int) ((buffer + bufSize) - t);
  8553. }
  8554. else
  8555. {
  8556. len = CharacterFunctions::printf (buffer, bufSize, T("%.9g"), n) + 1;
  8557. t = buffer;
  8558. }
  8559. if (len > 1)
  8560. {
  8561. jassert (len < numElementsInArray (buffer));
  8562. createInternal (len - 1);
  8563. memcpy (text->text, t, len * sizeof (tchar));
  8564. }
  8565. else
  8566. {
  8567. jassert (*t == 0);
  8568. text = &emptyString;
  8569. emptyString.refCount = safeEmptyStringRefCount;
  8570. }
  8571. }
  8572. String::String (const float number,
  8573. const int numberOfDecimalPlaces) throw()
  8574. {
  8575. doubleToStringWithDecPlaces ((double) number,
  8576. numberOfDecimalPlaces);
  8577. }
  8578. String::String (const double number,
  8579. const int numberOfDecimalPlaces) throw()
  8580. {
  8581. doubleToStringWithDecPlaces (number,
  8582. numberOfDecimalPlaces);
  8583. }
  8584. String::~String() throw()
  8585. {
  8586. emptyString.refCount = safeEmptyStringRefCount;
  8587. if (Atomic::decrementAndReturn (text->refCount) == 0)
  8588. juce_free (text);
  8589. }
  8590. void String::preallocateStorage (const size_t numChars) throw()
  8591. {
  8592. if (numChars > (size_t) text->allocatedNumChars)
  8593. {
  8594. dupeInternalIfMultiplyReferenced();
  8595. text = (InternalRefCountedStringHolder*) juce_realloc (text, sizeof (InternalRefCountedStringHolder)
  8596. + numChars * sizeof (tchar));
  8597. text->allocatedNumChars = (int) numChars;
  8598. }
  8599. }
  8600. #if JUCE_STRINGS_ARE_UNICODE
  8601. String::operator const char*() const throw()
  8602. {
  8603. if (isEmpty())
  8604. {
  8605. return (const char*) emptyCharString;
  8606. }
  8607. else
  8608. {
  8609. String* const mutableThis = const_cast <String*> (this);
  8610. mutableThis->dupeInternalIfMultiplyReferenced();
  8611. int len = CharacterFunctions::bytesRequiredForCopy (text->text) + 1;
  8612. mutableThis->text = (InternalRefCountedStringHolder*)
  8613. juce_realloc (text, sizeof (InternalRefCountedStringHolder)
  8614. + (len * sizeof (juce_wchar) + len));
  8615. char* otherCopy = (char*) (text->text + len);
  8616. --len;
  8617. CharacterFunctions::copy (otherCopy, text->text, len);
  8618. otherCopy [len] = 0;
  8619. return otherCopy;
  8620. }
  8621. }
  8622. #else
  8623. String::operator const juce_wchar*() const throw()
  8624. {
  8625. if (isEmpty())
  8626. {
  8627. return (const juce_wchar*) emptyCharString;
  8628. }
  8629. else
  8630. {
  8631. String* const mutableThis = const_cast <String*> (this);
  8632. mutableThis->dupeInternalIfMultiplyReferenced();
  8633. int len = CharacterFunctions::length (text->text) + 1;
  8634. mutableThis->text = (InternalRefCountedStringHolder*)
  8635. juce_realloc (text, sizeof (InternalRefCountedStringHolder)
  8636. + (len * sizeof (juce_wchar) + len));
  8637. juce_wchar* otherCopy = (juce_wchar*) (text->text + len);
  8638. --len;
  8639. CharacterFunctions::copy (otherCopy, text->text, len);
  8640. otherCopy [len] = 0;
  8641. return otherCopy;
  8642. }
  8643. }
  8644. #endif
  8645. void String::copyToBuffer (char* const destBuffer,
  8646. const int bufferSizeBytes) const throw()
  8647. {
  8648. #if JUCE_STRINGS_ARE_UNICODE
  8649. const int len = jmin (bufferSizeBytes, CharacterFunctions::bytesRequiredForCopy (text->text));
  8650. CharacterFunctions::copy (destBuffer, text->text, len);
  8651. #else
  8652. const int len = jmin (bufferSizeBytes, length());
  8653. memcpy (destBuffer, text->text, len * sizeof (tchar));
  8654. #endif
  8655. destBuffer [len] = 0;
  8656. }
  8657. void String::copyToBuffer (juce_wchar* const destBuffer,
  8658. const int maxCharsToCopy) const throw()
  8659. {
  8660. const int len = jmin (maxCharsToCopy, length());
  8661. #if JUCE_STRINGS_ARE_UNICODE
  8662. memcpy (destBuffer, text->text, len * sizeof (juce_wchar));
  8663. #else
  8664. CharacterFunctions::copy (destBuffer, text->text, len);
  8665. #endif
  8666. destBuffer [len] = 0;
  8667. }
  8668. int String::length() const throw()
  8669. {
  8670. return CharacterFunctions::length (text->text);
  8671. }
  8672. int String::hashCode() const throw()
  8673. {
  8674. const tchar* t = text->text;
  8675. int result = 0;
  8676. while (*t != (tchar) 0)
  8677. result = 31 * result + *t++;
  8678. return result;
  8679. }
  8680. int64 String::hashCode64() const throw()
  8681. {
  8682. const tchar* t = text->text;
  8683. int64 result = 0;
  8684. while (*t != (tchar) 0)
  8685. result = 101 * result + *t++;
  8686. return result;
  8687. }
  8688. const String& String::operator= (const tchar* const otherText) throw()
  8689. {
  8690. if (otherText != 0 && *otherText != 0)
  8691. {
  8692. const int otherLen = CharacterFunctions::length (otherText);
  8693. if (otherLen > 0)
  8694. {
  8695. // avoid resizing the memory block if the string is
  8696. // shrinking..
  8697. if (text->refCount > 1
  8698. || otherLen > text->allocatedNumChars
  8699. || otherLen <= (text->allocatedNumChars >> 1))
  8700. {
  8701. deleteInternal();
  8702. createInternal (otherLen);
  8703. }
  8704. memcpy (text->text, otherText, (otherLen + 1) * sizeof (tchar));
  8705. return *this;
  8706. }
  8707. }
  8708. deleteInternal();
  8709. text = &emptyString;
  8710. emptyString.refCount = safeEmptyStringRefCount;
  8711. return *this;
  8712. }
  8713. const String& String::operator= (const String& other) throw()
  8714. {
  8715. if (this != &other)
  8716. {
  8717. Atomic::increment (other.text->refCount);
  8718. if (Atomic::decrementAndReturn (text->refCount) == 0)
  8719. juce_free (text);
  8720. text = other.text;
  8721. }
  8722. return *this;
  8723. }
  8724. bool String::operator== (const String& other) const throw()
  8725. {
  8726. return text == other.text
  8727. || CharacterFunctions::compare (text->text, other.text->text) == 0;
  8728. }
  8729. bool String::operator== (const tchar* const t) const throw()
  8730. {
  8731. return t != 0 ? CharacterFunctions::compare (text->text, t) == 0
  8732. : isEmpty();
  8733. }
  8734. bool String::equalsIgnoreCase (const tchar* t) const throw()
  8735. {
  8736. return t != 0 ? CharacterFunctions::compareIgnoreCase (text->text, t) == 0
  8737. : isEmpty();
  8738. }
  8739. bool String::equalsIgnoreCase (const String& other) const throw()
  8740. {
  8741. return text == other.text
  8742. || CharacterFunctions::compareIgnoreCase (text->text, other.text->text) == 0;
  8743. }
  8744. bool String::operator!= (const String& other) const throw()
  8745. {
  8746. return text != other.text
  8747. && CharacterFunctions::compare (text->text, other.text->text) != 0;
  8748. }
  8749. bool String::operator!= (const tchar* const t) const throw()
  8750. {
  8751. return t != 0 ? (CharacterFunctions::compare (text->text, t) != 0)
  8752. : isNotEmpty();
  8753. }
  8754. bool String::operator> (const String& other) const throw()
  8755. {
  8756. return compare (other) > 0;
  8757. }
  8758. bool String::operator< (const tchar* const other) const throw()
  8759. {
  8760. return compare (other) < 0;
  8761. }
  8762. bool String::operator>= (const String& other) const throw()
  8763. {
  8764. return compare (other) >= 0;
  8765. }
  8766. bool String::operator<= (const tchar* const other) const throw()
  8767. {
  8768. return compare (other) <= 0;
  8769. }
  8770. int String::compare (const tchar* const other) const throw()
  8771. {
  8772. return other != 0 ? CharacterFunctions::compare (text->text, other)
  8773. : isEmpty();
  8774. }
  8775. int String::compareIgnoreCase (const tchar* const other) const throw()
  8776. {
  8777. return other != 0 ? CharacterFunctions::compareIgnoreCase (text->text, other)
  8778. : isEmpty();
  8779. }
  8780. int String::compareLexicographically (const tchar* other) const throw()
  8781. {
  8782. if (other == 0)
  8783. return isEmpty();
  8784. const tchar* s1 = text->text;
  8785. while (*s1 != 0 && ! CharacterFunctions::isLetterOrDigit (*s1))
  8786. ++s1;
  8787. while (*other != 0 && ! CharacterFunctions::isLetterOrDigit (*other))
  8788. ++other;
  8789. return CharacterFunctions::compareIgnoreCase (s1, other);
  8790. }
  8791. const String String::operator+ (const String& other) const throw()
  8792. {
  8793. if (*(other.text->text) == 0)
  8794. return *this;
  8795. if (isEmpty())
  8796. return other;
  8797. const int len = CharacterFunctions::length (text->text);
  8798. const int otherLen = CharacterFunctions::length (other.text->text);
  8799. String result (len + otherLen, (int) 0);
  8800. memcpy (result.text->text, text->text, len * sizeof (tchar));
  8801. memcpy (result.text->text + len, other.text->text, otherLen * sizeof (tchar));
  8802. result.text->text [len + otherLen] = 0;
  8803. return result;
  8804. }
  8805. const String String::operator+ (const tchar* const textToAppend) const throw()
  8806. {
  8807. if (textToAppend == 0 || *textToAppend == 0)
  8808. return *this;
  8809. const int len = CharacterFunctions::length (text->text);
  8810. const int otherLen = CharacterFunctions::length (textToAppend);
  8811. String result (len + otherLen, (int) 0);
  8812. memcpy (result.text->text, text->text, len * sizeof (tchar));
  8813. memcpy (result.text->text + len, textToAppend, otherLen * sizeof (tchar));
  8814. result.text->text [len + otherLen] = 0;
  8815. return result;
  8816. }
  8817. const String String::operator+ (const tchar characterToAppend) const throw()
  8818. {
  8819. if (characterToAppend == 0)
  8820. return *this;
  8821. const int len = CharacterFunctions::length (text->text);
  8822. String result ((int) (len + 1), (int) 0);
  8823. memcpy (result.text->text, text->text, len * sizeof (tchar));
  8824. result.text->text[len] = characterToAppend;
  8825. result.text->text[len + 1] = 0;
  8826. return result;
  8827. }
  8828. const String JUCE_PUBLIC_FUNCTION operator+ (const char* const string1,
  8829. const String& string2) throw()
  8830. {
  8831. String s (string1);
  8832. s += string2;
  8833. return s;
  8834. }
  8835. const String JUCE_PUBLIC_FUNCTION operator+ (const juce_wchar* const string1,
  8836. const String& string2) throw()
  8837. {
  8838. String s (string1);
  8839. s += string2;
  8840. return s;
  8841. }
  8842. const String& String::operator+= (const tchar* const t) throw()
  8843. {
  8844. if (t != 0)
  8845. appendInternal (t, CharacterFunctions::length (t));
  8846. return *this;
  8847. }
  8848. const String& String::operator+= (const String& other) throw()
  8849. {
  8850. if (isEmpty())
  8851. operator= (other);
  8852. else
  8853. appendInternal (other.text->text,
  8854. CharacterFunctions::length (other.text->text));
  8855. return *this;
  8856. }
  8857. const String& String::operator+= (const char ch) throw()
  8858. {
  8859. char asString[2];
  8860. asString[0] = ch;
  8861. asString[1] = 0;
  8862. #if JUCE_STRINGS_ARE_UNICODE
  8863. operator+= (String (asString));
  8864. #else
  8865. appendInternal (asString, 1);
  8866. #endif
  8867. return *this;
  8868. }
  8869. const String& String::operator+= (const juce_wchar ch) throw()
  8870. {
  8871. juce_wchar asString[2];
  8872. asString[0] = ch;
  8873. asString[1] = 0;
  8874. #if JUCE_STRINGS_ARE_UNICODE
  8875. appendInternal (asString, 1);
  8876. #else
  8877. operator+= (String (asString));
  8878. #endif
  8879. return *this;
  8880. }
  8881. void String::append (const tchar* const other,
  8882. const int howMany) throw()
  8883. {
  8884. if (howMany > 0)
  8885. {
  8886. int i;
  8887. for (i = 0; i < howMany; ++i)
  8888. if (other[i] == 0)
  8889. break;
  8890. appendInternal (other, i);
  8891. }
  8892. }
  8893. String& String::operator<< (const int number) throw()
  8894. {
  8895. tchar buffer [64];
  8896. tchar* const end = buffer + 64;
  8897. const tchar* const t = intToCharString (end, number);
  8898. appendInternal (t, (int) (end - t) - 1);
  8899. return *this;
  8900. }
  8901. String& String::operator<< (const unsigned int number) throw()
  8902. {
  8903. tchar buffer [64];
  8904. tchar* const end = buffer + 64;
  8905. const tchar* const t = uintToCharString (end, number);
  8906. appendInternal (t, (int) (end - t) - 1);
  8907. return *this;
  8908. }
  8909. String& String::operator<< (const short number) throw()
  8910. {
  8911. tchar buffer [64];
  8912. tchar* const end = buffer + 64;
  8913. const tchar* const t = intToCharString (end, (int) number);
  8914. appendInternal (t, (int) (end - t) - 1);
  8915. return *this;
  8916. }
  8917. String& String::operator<< (const long number) throw()
  8918. {
  8919. return operator<< ((int) number);
  8920. }
  8921. String& String::operator<< (const unsigned long number) throw()
  8922. {
  8923. return operator<< ((unsigned int) number);
  8924. }
  8925. String& String::operator<< (const double number) throw()
  8926. {
  8927. operator+= (String (number));
  8928. return *this;
  8929. }
  8930. String& String::operator<< (const float number) throw()
  8931. {
  8932. operator+= (String (number));
  8933. return *this;
  8934. }
  8935. String& String::operator<< (const char character) throw()
  8936. {
  8937. operator+= (character);
  8938. return *this;
  8939. }
  8940. String& String::operator<< (const juce_wchar character) throw()
  8941. {
  8942. operator+= (character);
  8943. return *this;
  8944. }
  8945. String& String::operator<< (const char* const t) throw()
  8946. {
  8947. #if JUCE_STRINGS_ARE_UNICODE
  8948. operator+= (String (t));
  8949. #else
  8950. operator+= (t);
  8951. #endif
  8952. return *this;
  8953. }
  8954. String& String::operator<< (const juce_wchar* const t) throw()
  8955. {
  8956. #if JUCE_STRINGS_ARE_UNICODE
  8957. operator+= (t);
  8958. #else
  8959. operator+= (String (t));
  8960. #endif
  8961. return *this;
  8962. }
  8963. String& String::operator<< (const String& t) throw()
  8964. {
  8965. operator+= (t);
  8966. return *this;
  8967. }
  8968. int String::indexOfChar (const tchar character) const throw()
  8969. {
  8970. const tchar* t = text->text;
  8971. for (;;)
  8972. {
  8973. if (*t == character)
  8974. return (int) (t - text->text);
  8975. if (*t++ == 0)
  8976. return -1;
  8977. }
  8978. }
  8979. int String::lastIndexOfChar (const tchar character) const throw()
  8980. {
  8981. for (int i = CharacterFunctions::length (text->text); --i >= 0;)
  8982. if (text->text[i] == character)
  8983. return i;
  8984. return -1;
  8985. }
  8986. int String::indexOf (const tchar* const t) const throw()
  8987. {
  8988. const tchar* const r = CharacterFunctions::find (text->text, t);
  8989. return (r == 0) ? -1
  8990. : (int) (r - text->text);
  8991. }
  8992. int String::indexOfChar (const int startIndex,
  8993. const tchar character) const throw()
  8994. {
  8995. if (startIndex >= 0 && startIndex >= CharacterFunctions::length (text->text))
  8996. return -1;
  8997. const tchar* t = text->text + jmax (0, startIndex);
  8998. for (;;)
  8999. {
  9000. if (*t == character)
  9001. return (int) (t - text->text);
  9002. if (*t++ == 0)
  9003. return -1;
  9004. }
  9005. }
  9006. int String::indexOfAnyOf (const tchar* const charactersToLookFor,
  9007. const int startIndex,
  9008. const bool ignoreCase) const throw()
  9009. {
  9010. if (charactersToLookFor == 0
  9011. || (startIndex >= 0 && startIndex >= CharacterFunctions::length (text->text)))
  9012. return -1;
  9013. const tchar* t = text->text + jmax (0, startIndex);
  9014. while (*t != 0)
  9015. {
  9016. if (CharacterFunctions::indexOfChar (charactersToLookFor, *t, ignoreCase) >= 0)
  9017. return (int) (t - text->text);
  9018. ++t;
  9019. }
  9020. return -1;
  9021. }
  9022. int String::indexOf (const int startIndex,
  9023. const tchar* const other) const throw()
  9024. {
  9025. if (other == 0 || startIndex >= CharacterFunctions::length (text->text))
  9026. return -1;
  9027. const tchar* const found = CharacterFunctions::find (text->text + jmax (0, startIndex),
  9028. other);
  9029. return (found == 0) ? -1
  9030. : (int) (found - text->text);
  9031. }
  9032. int String::indexOfIgnoreCase (const tchar* const other) const throw()
  9033. {
  9034. if (other != 0 && *other != 0)
  9035. {
  9036. const int len = CharacterFunctions::length (other);
  9037. const int end = CharacterFunctions::length (text->text) - len;
  9038. for (int i = 0; i <= end; ++i)
  9039. if (CharacterFunctions::compareIgnoreCase (text->text + i, other, len) == 0)
  9040. return i;
  9041. }
  9042. return -1;
  9043. }
  9044. int String::indexOfIgnoreCase (const int startIndex,
  9045. const tchar* const other) const throw()
  9046. {
  9047. if (other != 0 && *other != 0)
  9048. {
  9049. const int len = CharacterFunctions::length (other);
  9050. const int end = length() - len;
  9051. for (int i = jmax (0, startIndex); i <= end; ++i)
  9052. if (CharacterFunctions::compareIgnoreCase (text->text + i, other, len) == 0)
  9053. return i;
  9054. }
  9055. return -1;
  9056. }
  9057. int String::lastIndexOf (const tchar* const other) const throw()
  9058. {
  9059. if (other != 0 && *other != 0)
  9060. {
  9061. const int len = CharacterFunctions::length (other);
  9062. int i = length() - len;
  9063. if (i >= 0)
  9064. {
  9065. const tchar* n = text->text + i;
  9066. while (i >= 0)
  9067. {
  9068. if (CharacterFunctions::compare (n--, other, len) == 0)
  9069. return i;
  9070. --i;
  9071. }
  9072. }
  9073. }
  9074. return -1;
  9075. }
  9076. int String::lastIndexOfIgnoreCase (const tchar* const other) const throw()
  9077. {
  9078. if (other != 0 && *other != 0)
  9079. {
  9080. const int len = CharacterFunctions::length (other);
  9081. int i = length() - len;
  9082. if (i >= 0)
  9083. {
  9084. const tchar* n = text->text + i;
  9085. while (i >= 0)
  9086. {
  9087. if (CharacterFunctions::compareIgnoreCase (n--, other, len) == 0)
  9088. return i;
  9089. --i;
  9090. }
  9091. }
  9092. }
  9093. return -1;
  9094. }
  9095. int String::lastIndexOfAnyOf (const tchar* const charactersToLookFor,
  9096. const bool ignoreCase) const throw()
  9097. {
  9098. for (int i = CharacterFunctions::length (text->text); --i >= 0;)
  9099. if (CharacterFunctions::indexOfChar (charactersToLookFor, text->text [i], ignoreCase) >= 0)
  9100. return i;
  9101. return -1;
  9102. }
  9103. bool String::contains (const tchar* const other) const throw()
  9104. {
  9105. return indexOf (other) >= 0;
  9106. }
  9107. bool String::containsChar (const tchar character) const throw()
  9108. {
  9109. return indexOfChar (character) >= 0;
  9110. }
  9111. bool String::containsIgnoreCase (const tchar* const t) const throw()
  9112. {
  9113. return indexOfIgnoreCase (t) >= 0;
  9114. }
  9115. int String::indexOfWholeWord (const tchar* const word) const throw()
  9116. {
  9117. if (word != 0 && *word != 0)
  9118. {
  9119. const int wordLen = CharacterFunctions::length (word);
  9120. const int end = length() - wordLen;
  9121. const tchar* t = text->text;
  9122. for (int i = 0; i <= end; ++i)
  9123. {
  9124. if (CharacterFunctions::compare (t, word, wordLen) == 0
  9125. && (i == 0 || ! CharacterFunctions::isLetterOrDigit (* (t - 1)))
  9126. && ! CharacterFunctions::isLetterOrDigit (t [wordLen]))
  9127. {
  9128. return i;
  9129. }
  9130. ++t;
  9131. }
  9132. }
  9133. return -1;
  9134. }
  9135. int String::indexOfWholeWordIgnoreCase (const tchar* const word) const throw()
  9136. {
  9137. if (word != 0 && *word != 0)
  9138. {
  9139. const int wordLen = CharacterFunctions::length (word);
  9140. const int end = length() - wordLen;
  9141. const tchar* t = text->text;
  9142. for (int i = 0; i <= end; ++i)
  9143. {
  9144. if (CharacterFunctions::compareIgnoreCase (t, word, wordLen) == 0
  9145. && (i == 0 || ! CharacterFunctions::isLetterOrDigit (* (t - 1)))
  9146. && ! CharacterFunctions::isLetterOrDigit (t [wordLen]))
  9147. {
  9148. return i;
  9149. }
  9150. ++t;
  9151. }
  9152. }
  9153. return -1;
  9154. }
  9155. bool String::containsWholeWord (const tchar* const wordToLookFor) const throw()
  9156. {
  9157. return indexOfWholeWord (wordToLookFor) >= 0;
  9158. }
  9159. bool String::containsWholeWordIgnoreCase (const tchar* const wordToLookFor) const throw()
  9160. {
  9161. return indexOfWholeWordIgnoreCase (wordToLookFor) >= 0;
  9162. }
  9163. static int indexOfMatch (const tchar* const wildcard,
  9164. const tchar* const test,
  9165. const bool ignoreCase) throw()
  9166. {
  9167. int start = 0;
  9168. while (test [start] != 0)
  9169. {
  9170. int i = 0;
  9171. for (;;)
  9172. {
  9173. const tchar wc = wildcard [i];
  9174. const tchar c = test [i + start];
  9175. if (wc == c
  9176. || (ignoreCase && CharacterFunctions::toLowerCase (wc) == CharacterFunctions::toLowerCase (c))
  9177. || (wc == T('?') && c != 0))
  9178. {
  9179. if (wc == 0)
  9180. return start;
  9181. ++i;
  9182. }
  9183. else
  9184. {
  9185. if (wc == T('*') && (wildcard [i + 1] == 0
  9186. || indexOfMatch (wildcard + i + 1,
  9187. test + start + i,
  9188. ignoreCase) >= 0))
  9189. {
  9190. return start;
  9191. }
  9192. break;
  9193. }
  9194. }
  9195. ++start;
  9196. }
  9197. return -1;
  9198. }
  9199. bool String::matchesWildcard (const tchar* wildcard, const bool ignoreCase) const throw()
  9200. {
  9201. int i = 0;
  9202. for (;;)
  9203. {
  9204. const tchar wc = wildcard [i];
  9205. const tchar c = text->text [i];
  9206. if (wc == c
  9207. || (ignoreCase && CharacterFunctions::toLowerCase (wc) == CharacterFunctions::toLowerCase (c))
  9208. || (wc == T('?') && c != 0))
  9209. {
  9210. if (wc == 0)
  9211. return true;
  9212. ++i;
  9213. }
  9214. else
  9215. {
  9216. return wc == T('*') && (wildcard [i + 1] == 0
  9217. || indexOfMatch (wildcard + i + 1,
  9218. text->text + i,
  9219. ignoreCase) >= 0);
  9220. }
  9221. }
  9222. }
  9223. void String::printf (const tchar* const pf, ...) throw()
  9224. {
  9225. va_list list;
  9226. va_start (list, pf);
  9227. vprintf (pf, list);
  9228. }
  9229. const String String::formatted (const tchar* const pf, ...) throw()
  9230. {
  9231. va_list list;
  9232. va_start (list, pf);
  9233. String result;
  9234. result.vprintf (pf, list);
  9235. return result;
  9236. }
  9237. void String::vprintf (const tchar* const pf, va_list& args) throw()
  9238. {
  9239. tchar stackBuf [256];
  9240. unsigned int bufSize = 256;
  9241. tchar* buf = stackBuf;
  9242. deleteInternal();
  9243. do
  9244. {
  9245. #if JUCE_LINUX && JUCE_64BIT
  9246. va_list tempArgs;
  9247. va_copy (tempArgs, args);
  9248. const int num = CharacterFunctions::vprintf (buf, bufSize - 1, pf, tempArgs);
  9249. va_end (tempArgs);
  9250. #else
  9251. const int num = CharacterFunctions::vprintf (buf, bufSize - 1, pf, args);
  9252. #endif
  9253. if (num > 0)
  9254. {
  9255. createInternal (num);
  9256. memcpy (text->text, buf, (num + 1) * sizeof (tchar));
  9257. break;
  9258. }
  9259. else if (num == 0)
  9260. {
  9261. text = &emptyString;
  9262. emptyString.refCount = safeEmptyStringRefCount;
  9263. break;
  9264. }
  9265. if (buf != stackBuf)
  9266. juce_free (buf);
  9267. bufSize += 256;
  9268. buf = (tchar*) juce_malloc (bufSize * sizeof (tchar));
  9269. }
  9270. while (bufSize < 65536); // this is a sanity check to avoid situations where vprintf repeatedly
  9271. // returns -1 because of an error rather than because it needs more space.
  9272. if (buf != stackBuf)
  9273. juce_free (buf);
  9274. }
  9275. const String String::repeatedString (const tchar* const stringToRepeat,
  9276. int numberOfTimesToRepeat) throw()
  9277. {
  9278. const int len = CharacterFunctions::length (stringToRepeat);
  9279. String result ((int) (len * numberOfTimesToRepeat + 1), (int) 0);
  9280. tchar* n = result.text->text;
  9281. n[0] = 0;
  9282. while (--numberOfTimesToRepeat >= 0)
  9283. {
  9284. CharacterFunctions::append (n, stringToRepeat);
  9285. n += len;
  9286. }
  9287. return result;
  9288. }
  9289. const String String::replaceSection (int index,
  9290. int numCharsToReplace,
  9291. const tchar* const stringToInsert) const throw()
  9292. {
  9293. if (index < 0)
  9294. {
  9295. // a negative index to replace from?
  9296. jassertfalse
  9297. index = 0;
  9298. }
  9299. if (numCharsToReplace < 0)
  9300. {
  9301. // replacing a negative number of characters?
  9302. numCharsToReplace = 0;
  9303. jassertfalse;
  9304. }
  9305. const int len = length();
  9306. if (index + numCharsToReplace > len)
  9307. {
  9308. if (index > len)
  9309. {
  9310. // replacing beyond the end of the string?
  9311. index = len;
  9312. jassertfalse
  9313. }
  9314. numCharsToReplace = len - index;
  9315. }
  9316. const int newStringLen = (stringToInsert != 0) ? CharacterFunctions::length (stringToInsert) : 0;
  9317. const int newTotalLen = len + newStringLen - numCharsToReplace;
  9318. if (newTotalLen <= 0)
  9319. return String::empty;
  9320. String result (newTotalLen, (int) 0);
  9321. memcpy (result.text->text,
  9322. text->text,
  9323. index * sizeof (tchar));
  9324. if (newStringLen > 0)
  9325. memcpy (result.text->text + index,
  9326. stringToInsert,
  9327. newStringLen * sizeof (tchar));
  9328. const int endStringLen = newTotalLen - (index + newStringLen);
  9329. if (endStringLen > 0)
  9330. memcpy (result.text->text + (index + newStringLen),
  9331. text->text + (index + numCharsToReplace),
  9332. endStringLen * sizeof (tchar));
  9333. result.text->text [newTotalLen] = 0;
  9334. return result;
  9335. }
  9336. const String String::replace (const tchar* const stringToReplace,
  9337. const tchar* const stringToInsert,
  9338. const bool ignoreCase) const throw()
  9339. {
  9340. const int stringToReplaceLen = CharacterFunctions::length (stringToReplace);
  9341. const int stringToInsertLen = CharacterFunctions::length (stringToInsert);
  9342. int i = 0;
  9343. String result (*this);
  9344. while ((i = (ignoreCase ? result.indexOfIgnoreCase (i, stringToReplace)
  9345. : result.indexOf (i, stringToReplace))) >= 0)
  9346. {
  9347. result = result.replaceSection (i, stringToReplaceLen, stringToInsert);
  9348. i += stringToInsertLen;
  9349. }
  9350. return result;
  9351. }
  9352. const String String::replaceCharacter (const tchar charToReplace,
  9353. const tchar charToInsert) const throw()
  9354. {
  9355. const int index = indexOfChar (charToReplace);
  9356. if (index < 0)
  9357. return *this;
  9358. String result (*this);
  9359. result.dupeInternalIfMultiplyReferenced();
  9360. tchar* t = result.text->text + index;
  9361. while (*t != 0)
  9362. {
  9363. if (*t == charToReplace)
  9364. *t = charToInsert;
  9365. ++t;
  9366. }
  9367. return result;
  9368. }
  9369. const String String::replaceCharacters (const String& charactersToReplace,
  9370. const tchar* const charactersToInsertInstead) const throw()
  9371. {
  9372. String result (*this);
  9373. result.dupeInternalIfMultiplyReferenced();
  9374. tchar* t = result.text->text;
  9375. const int len2 = CharacterFunctions::length (charactersToInsertInstead);
  9376. // the two strings passed in are supposed to be the same length!
  9377. jassert (len2 == charactersToReplace.length());
  9378. while (*t != 0)
  9379. {
  9380. const int index = charactersToReplace.indexOfChar (*t);
  9381. if (((unsigned int) index) < (unsigned int) len2)
  9382. *t = charactersToInsertInstead [index];
  9383. ++t;
  9384. }
  9385. return result;
  9386. }
  9387. bool String::startsWith (const tchar* const other) const throw()
  9388. {
  9389. return other != 0
  9390. && CharacterFunctions::compare (text->text, other, CharacterFunctions::length (other)) == 0;
  9391. }
  9392. bool String::startsWithIgnoreCase (const tchar* const other) const throw()
  9393. {
  9394. return other != 0
  9395. && CharacterFunctions::compareIgnoreCase (text->text, other, CharacterFunctions::length (other)) == 0;
  9396. }
  9397. bool String::startsWithChar (const tchar character) const throw()
  9398. {
  9399. jassert (character != 0); // strings can't contain a null character!
  9400. return text->text[0] == character;
  9401. }
  9402. bool String::endsWithChar (const tchar character) const throw()
  9403. {
  9404. jassert (character != 0); // strings can't contain a null character!
  9405. return text->text[0] != 0
  9406. && text->text [length() - 1] == character;
  9407. }
  9408. bool String::endsWith (const tchar* const other) const throw()
  9409. {
  9410. if (other == 0)
  9411. return false;
  9412. const int thisLen = length();
  9413. const int otherLen = CharacterFunctions::length (other);
  9414. return thisLen >= otherLen
  9415. && CharacterFunctions::compare (text->text + thisLen - otherLen, other) == 0;
  9416. }
  9417. bool String::endsWithIgnoreCase (const tchar* const other) const throw()
  9418. {
  9419. if (other == 0)
  9420. return false;
  9421. const int thisLen = length();
  9422. const int otherLen = CharacterFunctions::length (other);
  9423. return thisLen >= otherLen
  9424. && CharacterFunctions::compareIgnoreCase (text->text + thisLen - otherLen, other) == 0;
  9425. }
  9426. const String String::toUpperCase() const throw()
  9427. {
  9428. String result (*this);
  9429. result.dupeInternalIfMultiplyReferenced();
  9430. CharacterFunctions::toUpperCase (result.text->text);
  9431. return result;
  9432. }
  9433. const String String::toLowerCase() const throw()
  9434. {
  9435. String result (*this);
  9436. result.dupeInternalIfMultiplyReferenced();
  9437. CharacterFunctions::toLowerCase (result.text->text);
  9438. return result;
  9439. }
  9440. tchar& String::operator[] (const int index) throw()
  9441. {
  9442. jassert (((unsigned int) index) <= (unsigned int) length());
  9443. dupeInternalIfMultiplyReferenced();
  9444. return text->text [index];
  9445. }
  9446. tchar String::getLastCharacter() const throw()
  9447. {
  9448. return (isEmpty()) ? ((tchar) 0)
  9449. : text->text [CharacterFunctions::length (text->text) - 1];
  9450. }
  9451. const String String::substring (int start, int end) const throw()
  9452. {
  9453. if (start < 0)
  9454. start = 0;
  9455. else if (end <= start)
  9456. return empty;
  9457. int len = 0;
  9458. const tchar* const t = text->text;
  9459. while (len <= end && t [len] != 0)
  9460. ++len;
  9461. if (end >= len)
  9462. {
  9463. if (start == 0)
  9464. return *this;
  9465. end = len;
  9466. }
  9467. return String (text->text + start,
  9468. end - start);
  9469. }
  9470. const String String::substring (const int start) const throw()
  9471. {
  9472. if (start <= 0)
  9473. return *this;
  9474. const int len = CharacterFunctions::length (text->text);
  9475. if (start >= len)
  9476. return empty;
  9477. else
  9478. return String (text->text + start,
  9479. len - start);
  9480. }
  9481. const String String::dropLastCharacters (const int numberToDrop) const throw()
  9482. {
  9483. return String (text->text,
  9484. jmax (0, CharacterFunctions::length (text->text) - numberToDrop));
  9485. }
  9486. const String String::getLastCharacters (const int numCharacters) const throw()
  9487. {
  9488. return String (text->text + jmax (0, CharacterFunctions::length (text->text) - jmax (0, numCharacters)));
  9489. }
  9490. const String String::fromFirstOccurrenceOf (const tchar* const sub,
  9491. const bool includeSubString,
  9492. const bool ignoreCase) const throw()
  9493. {
  9494. const int i = ignoreCase ? indexOfIgnoreCase (sub)
  9495. : indexOf (sub);
  9496. if (i < 0)
  9497. return empty;
  9498. else
  9499. return substring (includeSubString ? i : i + CharacterFunctions::length (sub));
  9500. }
  9501. const String String::fromLastOccurrenceOf (const tchar* const sub,
  9502. const bool includeSubString,
  9503. const bool ignoreCase) const throw()
  9504. {
  9505. const int i = ignoreCase ? lastIndexOfIgnoreCase (sub)
  9506. : lastIndexOf (sub);
  9507. if (i < 0)
  9508. return *this;
  9509. else
  9510. return substring (includeSubString ? i : i + CharacterFunctions::length (sub));
  9511. }
  9512. const String String::upToFirstOccurrenceOf (const tchar* const sub,
  9513. const bool includeSubString,
  9514. const bool ignoreCase) const throw()
  9515. {
  9516. const int i = ignoreCase ? indexOfIgnoreCase (sub)
  9517. : indexOf (sub);
  9518. if (i < 0)
  9519. return *this;
  9520. else
  9521. return substring (0, includeSubString ? i + CharacterFunctions::length (sub) : i);
  9522. }
  9523. const String String::upToLastOccurrenceOf (const tchar* const sub,
  9524. const bool includeSubString,
  9525. const bool ignoreCase) const throw()
  9526. {
  9527. const int i = ignoreCase ? lastIndexOfIgnoreCase (sub)
  9528. : lastIndexOf (sub);
  9529. if (i < 0)
  9530. return *this;
  9531. return substring (0, includeSubString ? i + CharacterFunctions::length (sub) : i);
  9532. }
  9533. bool String::isQuotedString() const throw()
  9534. {
  9535. const String trimmed (trimStart());
  9536. return trimmed[0] == T('"')
  9537. || trimmed[0] == T('\'');
  9538. }
  9539. const String String::unquoted() const throw()
  9540. {
  9541. String s (*this);
  9542. if (s[0] == T('"') || s[0] == T('\''))
  9543. s = s.substring (1);
  9544. const int lastCharIndex = s.length() - 1;
  9545. if (lastCharIndex >= 0
  9546. && (s [lastCharIndex] == T('"') || s[lastCharIndex] == T('\'')))
  9547. s [lastCharIndex] = 0;
  9548. return s;
  9549. }
  9550. const String String::quoted (const tchar quoteCharacter) const throw()
  9551. {
  9552. if (isEmpty())
  9553. return charToString (quoteCharacter) + quoteCharacter;
  9554. String t (*this);
  9555. if (! t.startsWithChar (quoteCharacter))
  9556. t = charToString (quoteCharacter) + t;
  9557. if (! t.endsWithChar (quoteCharacter))
  9558. t += quoteCharacter;
  9559. return t;
  9560. }
  9561. const String String::trim() const throw()
  9562. {
  9563. if (isEmpty())
  9564. return empty;
  9565. int start = 0;
  9566. while (CharacterFunctions::isWhitespace (text->text [start]))
  9567. ++start;
  9568. const int len = CharacterFunctions::length (text->text);
  9569. int end = len - 1;
  9570. while ((end >= start) && CharacterFunctions::isWhitespace (text->text [end]))
  9571. --end;
  9572. ++end;
  9573. if (end <= start)
  9574. return empty;
  9575. else if (start > 0 || end < len)
  9576. return String (text->text + start, end - start);
  9577. else
  9578. return *this;
  9579. }
  9580. const String String::trimStart() const throw()
  9581. {
  9582. if (isEmpty())
  9583. return empty;
  9584. const tchar* t = text->text;
  9585. while (CharacterFunctions::isWhitespace (*t))
  9586. ++t;
  9587. if (t == text->text)
  9588. return *this;
  9589. else
  9590. return String (t);
  9591. }
  9592. const String String::trimEnd() const throw()
  9593. {
  9594. if (isEmpty())
  9595. return empty;
  9596. const tchar* endT = text->text + (CharacterFunctions::length (text->text) - 1);
  9597. while ((endT >= text->text) && CharacterFunctions::isWhitespace (*endT))
  9598. --endT;
  9599. return String (text->text, (int) (++endT - text->text));
  9600. }
  9601. const String String::trimCharactersAtStart (const tchar* charactersToTrim) const throw()
  9602. {
  9603. jassert (charactersToTrim != 0);
  9604. if (isEmpty())
  9605. return empty;
  9606. const tchar* t = text->text;
  9607. while (CharacterFunctions::indexOfCharFast (charactersToTrim, *t) >= 0)
  9608. ++t;
  9609. if (t == text->text)
  9610. return *this;
  9611. else
  9612. return String (t);
  9613. }
  9614. const String String::trimCharactersAtEnd (const tchar* charactersToTrim) const throw()
  9615. {
  9616. jassert (charactersToTrim != 0);
  9617. if (isEmpty())
  9618. return empty;
  9619. const tchar* endT = text->text + (CharacterFunctions::length (text->text) - 1);
  9620. while ((endT >= text->text) && CharacterFunctions::indexOfCharFast (charactersToTrim, *endT) >= 0)
  9621. --endT;
  9622. return String (text->text, (int) (++endT - text->text));
  9623. }
  9624. const String String::retainCharacters (const tchar* const charactersToRetain) const throw()
  9625. {
  9626. jassert (charactersToRetain != 0);
  9627. if (isEmpty())
  9628. return empty;
  9629. String result (text->allocatedNumChars, (int) 0);
  9630. tchar* dst = result.text->text;
  9631. const tchar* src = text->text;
  9632. while (*src != 0)
  9633. {
  9634. if (CharacterFunctions::indexOfCharFast (charactersToRetain, *src) >= 0)
  9635. *dst++ = *src;
  9636. ++src;
  9637. }
  9638. *dst = 0;
  9639. return result;
  9640. }
  9641. const String String::removeCharacters (const tchar* const charactersToRemove) const throw()
  9642. {
  9643. jassert (charactersToRemove != 0);
  9644. if (isEmpty())
  9645. return empty;
  9646. String result (text->allocatedNumChars, (int) 0);
  9647. tchar* dst = result.text->text;
  9648. const tchar* src = text->text;
  9649. while (*src != 0)
  9650. {
  9651. if (CharacterFunctions::indexOfCharFast (charactersToRemove, *src) < 0)
  9652. *dst++ = *src;
  9653. ++src;
  9654. }
  9655. *dst = 0;
  9656. return result;
  9657. }
  9658. const String String::initialSectionContainingOnly (const tchar* const permittedCharacters) const throw()
  9659. {
  9660. return substring (0, CharacterFunctions::getIntialSectionContainingOnly (text->text, permittedCharacters));
  9661. }
  9662. const String String::initialSectionNotContaining (const tchar* const charactersToStopAt) const throw()
  9663. {
  9664. jassert (charactersToStopAt != 0);
  9665. const tchar* const t = text->text;
  9666. int i = 0;
  9667. while (t[i] != 0)
  9668. {
  9669. if (CharacterFunctions::indexOfCharFast (charactersToStopAt, t[i]) >= 0)
  9670. return String (text->text, i);
  9671. ++i;
  9672. }
  9673. return empty;
  9674. }
  9675. bool String::containsOnly (const tchar* const chars) const throw()
  9676. {
  9677. jassert (chars != 0);
  9678. const tchar* t = text->text;
  9679. while (*t != 0)
  9680. if (CharacterFunctions::indexOfCharFast (chars, *t++) < 0)
  9681. return false;
  9682. return true;
  9683. }
  9684. bool String::containsAnyOf (const tchar* const chars) const throw()
  9685. {
  9686. jassert (chars != 0);
  9687. const tchar* t = text->text;
  9688. while (*t != 0)
  9689. if (CharacterFunctions::indexOfCharFast (chars, *t++) >= 0)
  9690. return true;
  9691. return false;
  9692. }
  9693. bool String::containsNonWhitespaceChars() const throw()
  9694. {
  9695. const tchar* t = text->text;
  9696. while (*t != 0)
  9697. if (! CharacterFunctions::isWhitespace (*t++))
  9698. return true;
  9699. return false;
  9700. }
  9701. int String::getIntValue() const throw()
  9702. {
  9703. return CharacterFunctions::getIntValue (text->text);
  9704. }
  9705. int String::getTrailingIntValue() const throw()
  9706. {
  9707. int n = 0;
  9708. int mult = 1;
  9709. const tchar* t = text->text + length();
  9710. while (--t >= text->text)
  9711. {
  9712. const tchar c = *t;
  9713. if (! CharacterFunctions::isDigit (c))
  9714. {
  9715. if (c == T('-'))
  9716. n = -n;
  9717. break;
  9718. }
  9719. n += mult * (c - T('0'));
  9720. mult *= 10;
  9721. }
  9722. return n;
  9723. }
  9724. int64 String::getLargeIntValue() const throw()
  9725. {
  9726. return CharacterFunctions::getInt64Value (text->text);
  9727. }
  9728. float String::getFloatValue() const throw()
  9729. {
  9730. return (float) CharacterFunctions::getDoubleValue (text->text);
  9731. }
  9732. double String::getDoubleValue() const throw()
  9733. {
  9734. return CharacterFunctions::getDoubleValue (text->text);
  9735. }
  9736. static const tchar* const hexDigits = T("0123456789abcdef");
  9737. const String String::toHexString (const int number) throw()
  9738. {
  9739. tchar buffer[32];
  9740. tchar* const end = buffer + 32;
  9741. tchar* t = end;
  9742. *--t = 0;
  9743. unsigned int v = (unsigned int) number;
  9744. do
  9745. {
  9746. *--t = hexDigits [v & 15];
  9747. v >>= 4;
  9748. } while (v != 0);
  9749. return String (t, (int) (((char*) end) - (char*) t) - 1);
  9750. }
  9751. const String String::toHexString (const int64 number) throw()
  9752. {
  9753. tchar buffer[32];
  9754. tchar* const end = buffer + 32;
  9755. tchar* t = end;
  9756. *--t = 0;
  9757. uint64 v = (uint64) number;
  9758. do
  9759. {
  9760. *--t = hexDigits [(int) (v & 15)];
  9761. v >>= 4;
  9762. } while (v != 0);
  9763. return String (t, (int) (((char*) end) - (char*) t));
  9764. }
  9765. const String String::toHexString (const short number) throw()
  9766. {
  9767. return toHexString ((int) (unsigned short) number);
  9768. }
  9769. const String String::toHexString (const unsigned char* data,
  9770. const int size,
  9771. const int groupSize) throw()
  9772. {
  9773. if (size <= 0)
  9774. return empty;
  9775. int numChars = (size * 2) + 2;
  9776. if (groupSize > 0)
  9777. numChars += size / groupSize;
  9778. String s (numChars, (int) 0);
  9779. tchar* d = s.text->text;
  9780. for (int i = 0; i < size; ++i)
  9781. {
  9782. *d++ = hexDigits [(*data) >> 4];
  9783. *d++ = hexDigits [(*data) & 0xf];
  9784. ++data;
  9785. if (groupSize > 0 && (i % groupSize) == (groupSize - 1) && i < (size - 1))
  9786. *d++ = T(' ');
  9787. }
  9788. *d = 0;
  9789. return s;
  9790. }
  9791. int String::getHexValue32() const throw()
  9792. {
  9793. int result = 0;
  9794. const tchar* c = text->text;
  9795. for (;;)
  9796. {
  9797. const int hexValue = CharacterFunctions::getHexDigitValue (*c);
  9798. if (hexValue >= 0)
  9799. result = (result << 4) | hexValue;
  9800. else if (*c == 0)
  9801. break;
  9802. ++c;
  9803. }
  9804. return result;
  9805. }
  9806. int64 String::getHexValue64() const throw()
  9807. {
  9808. int64 result = 0;
  9809. const tchar* c = text->text;
  9810. for (;;)
  9811. {
  9812. const int hexValue = CharacterFunctions::getHexDigitValue (*c);
  9813. if (hexValue >= 0)
  9814. result = (result << 4) | hexValue;
  9815. else if (*c == 0)
  9816. break;
  9817. ++c;
  9818. }
  9819. return result;
  9820. }
  9821. const String String::createStringFromData (const void* const data_,
  9822. const int size) throw()
  9823. {
  9824. const char* const data = (const char*) data_;
  9825. if (size <= 0 || data == 0)
  9826. {
  9827. return empty;
  9828. }
  9829. else if (size < 2)
  9830. {
  9831. return charToString (data[0]);
  9832. }
  9833. else if ((data[0] == (char)-2 && data[1] == (char)-1)
  9834. || (data[0] == (char)-1 && data[1] == (char)-2))
  9835. {
  9836. // assume it's 16-bit unicode
  9837. const bool bigEndian = (data[0] == (char)-2);
  9838. const int numChars = size / 2 - 1;
  9839. String result;
  9840. result.preallocateStorage (numChars + 2);
  9841. const uint16* const src = (const uint16*) (data + 2);
  9842. tchar* const dst = const_cast <tchar*> ((const tchar*) result);
  9843. if (bigEndian)
  9844. {
  9845. for (int i = 0; i < numChars; ++i)
  9846. dst[i] = (tchar) ByteOrder::swapIfLittleEndian (src[i]);
  9847. }
  9848. else
  9849. {
  9850. for (int i = 0; i < numChars; ++i)
  9851. dst[i] = (tchar) ByteOrder::swapIfBigEndian (src[i]);
  9852. }
  9853. dst [numChars] = 0;
  9854. return result;
  9855. }
  9856. else
  9857. {
  9858. return String::fromUTF8 ((const uint8*) data, size);
  9859. }
  9860. }
  9861. const char* String::toUTF8() const throw()
  9862. {
  9863. if (isEmpty())
  9864. {
  9865. return (const char*) emptyCharString;
  9866. }
  9867. else
  9868. {
  9869. String* const mutableThis = const_cast <String*> (this);
  9870. mutableThis->dupeInternalIfMultiplyReferenced();
  9871. const int currentLen = CharacterFunctions::length (text->text) + 1;
  9872. const int utf8BytesNeeded = copyToUTF8 (0);
  9873. mutableThis->text = (InternalRefCountedStringHolder*)
  9874. juce_realloc (text, sizeof (InternalRefCountedStringHolder)
  9875. + (currentLen * sizeof (juce_wchar) + utf8BytesNeeded));
  9876. char* const otherCopy = (char*) (text->text + currentLen);
  9877. copyToUTF8 ((uint8*) otherCopy);
  9878. return otherCopy;
  9879. }
  9880. }
  9881. int String::copyToUTF8 (uint8* const buffer, const int maxBufferSizeBytes) const throw()
  9882. {
  9883. jassert (maxBufferSizeBytes >= 0); // keep this value positive, or no characters will be copied!
  9884. #if JUCE_STRINGS_ARE_UNICODE
  9885. int num = 0, index = 0;
  9886. for (;;)
  9887. {
  9888. const uint32 c = (uint32) text->text [index++];
  9889. if (c >= 0x80)
  9890. {
  9891. int numExtraBytes = 1;
  9892. if (c >= 0x800)
  9893. {
  9894. ++numExtraBytes;
  9895. if (c >= 0x10000)
  9896. {
  9897. ++numExtraBytes;
  9898. if (c >= 0x200000)
  9899. {
  9900. ++numExtraBytes;
  9901. if (c >= 0x4000000)
  9902. ++numExtraBytes;
  9903. }
  9904. }
  9905. }
  9906. if (buffer != 0)
  9907. {
  9908. if (num + numExtraBytes >= maxBufferSizeBytes)
  9909. {
  9910. buffer [num++] = 0;
  9911. break;
  9912. }
  9913. else
  9914. {
  9915. buffer [num++] = (uint8) ((0xff << (7 - numExtraBytes)) | (c >> (numExtraBytes * 6)));
  9916. while (--numExtraBytes >= 0)
  9917. buffer [num++] = (uint8) (0x80 | (0x3f & (c >> (numExtraBytes * 6))));
  9918. }
  9919. }
  9920. else
  9921. {
  9922. num += numExtraBytes + 1;
  9923. }
  9924. }
  9925. else
  9926. {
  9927. if (buffer != 0)
  9928. {
  9929. if (num + 1 >= maxBufferSizeBytes)
  9930. {
  9931. buffer [num++] = 0;
  9932. break;
  9933. }
  9934. buffer [num] = (uint8) c;
  9935. }
  9936. ++num;
  9937. }
  9938. if (c == 0)
  9939. break;
  9940. }
  9941. return num;
  9942. #else
  9943. const int numBytes = jmin (maxBufferSizeBytes, length() + 1);
  9944. if (buffer != 0)
  9945. copyToBuffer ((char*) buffer, maxBufferSizeBytes);
  9946. return numBytes;
  9947. #endif
  9948. }
  9949. const String String::fromUTF8 (const uint8* const buffer, int bufferSizeBytes) throw()
  9950. {
  9951. if (buffer == 0)
  9952. return empty;
  9953. if (bufferSizeBytes < 0)
  9954. bufferSizeBytes = INT_MAX;
  9955. size_t numBytes;
  9956. for (numBytes = 0; numBytes < (size_t) bufferSizeBytes; ++numBytes)
  9957. if (buffer [numBytes] == 0)
  9958. break;
  9959. String result ((int) numBytes + 1, 0);
  9960. tchar* dest = result.text->text;
  9961. size_t i = 0;
  9962. while (i < numBytes)
  9963. {
  9964. const uint8 c = buffer [i++];
  9965. if ((c & 0x80) != 0)
  9966. {
  9967. int mask = 0x7f;
  9968. int bit = 0x40;
  9969. int numExtraValues = 0;
  9970. while (bit != 0 && (c & bit) != 0)
  9971. {
  9972. bit >>= 1;
  9973. mask >>= 1;
  9974. ++numExtraValues;
  9975. }
  9976. int n = (c & mask);
  9977. while (--numExtraValues >= 0 && i < (size_t) bufferSizeBytes)
  9978. {
  9979. const uint8 nextByte = buffer[i];
  9980. if ((nextByte & 0xc0) != 0x80)
  9981. break;
  9982. n <<= 6;
  9983. n |= (nextByte & 0x3f);
  9984. ++i;
  9985. }
  9986. *dest++ = (tchar) n;
  9987. }
  9988. else
  9989. {
  9990. *dest++ = (tchar) c;
  9991. }
  9992. }
  9993. *dest = 0;
  9994. return result;
  9995. }
  9996. String::Concatenator::Concatenator (String& stringToAppendTo)
  9997. : result (stringToAppendTo),
  9998. nextIndex (stringToAppendTo.length())
  9999. {
  10000. }
  10001. String::Concatenator::~Concatenator()
  10002. {
  10003. }
  10004. void String::Concatenator::append (const String& s)
  10005. {
  10006. const int len = s.length();
  10007. if (len > 0)
  10008. {
  10009. result.preallocateStorage (nextIndex + len);
  10010. s.copyToBuffer (const_cast <tchar*> ((const tchar*) result) + nextIndex, len);
  10011. nextIndex += len;
  10012. }
  10013. }
  10014. END_JUCE_NAMESPACE
  10015. /********* End of inlined file: juce_String.cpp *********/
  10016. /********* Start of inlined file: juce_StringArray.cpp *********/
  10017. BEGIN_JUCE_NAMESPACE
  10018. StringArray::StringArray() throw()
  10019. {
  10020. }
  10021. StringArray::StringArray (const StringArray& other)
  10022. : strings (other.strings)
  10023. {
  10024. }
  10025. StringArray::StringArray (const juce_wchar** const initialStrings,
  10026. const int numberOfStrings)
  10027. {
  10028. for (int i = 0; i < numberOfStrings; ++i)
  10029. add (initialStrings [i]);
  10030. }
  10031. StringArray::StringArray (const char** const initialStrings,
  10032. const int numberOfStrings)
  10033. {
  10034. for (int i = 0; i < numberOfStrings; ++i)
  10035. add (initialStrings [i]);
  10036. }
  10037. StringArray::StringArray (const juce_wchar** const initialStrings)
  10038. {
  10039. int i = 0;
  10040. while (initialStrings[i] != 0)
  10041. add (initialStrings [i++]);
  10042. }
  10043. StringArray::StringArray (const char** const initialStrings)
  10044. {
  10045. int i = 0;
  10046. while (initialStrings[i] != 0)
  10047. add (initialStrings [i++]);
  10048. }
  10049. const StringArray& StringArray::operator= (const StringArray& other)
  10050. {
  10051. strings = other.strings;
  10052. return *this;
  10053. }
  10054. StringArray::~StringArray()
  10055. {
  10056. }
  10057. bool StringArray::operator== (const StringArray& other) const
  10058. {
  10059. if (other.size() != size())
  10060. return false;
  10061. for (int i = size(); --i >= 0;)
  10062. if (other.strings.getReference(i) != strings.getReference(i))
  10063. return false;
  10064. return true;
  10065. }
  10066. bool StringArray::operator!= (const StringArray& other) const
  10067. {
  10068. return ! operator== (other);
  10069. }
  10070. void StringArray::clear()
  10071. {
  10072. strings.clear();
  10073. }
  10074. const String& StringArray::operator[] (const int index) const throw()
  10075. {
  10076. if (((unsigned int) index) < (unsigned int) strings.size())
  10077. return strings.getReference (index);
  10078. return String::empty;
  10079. }
  10080. void StringArray::add (const String& newString)
  10081. {
  10082. strings.add (newString);
  10083. }
  10084. void StringArray::insert (const int index, const String& newString)
  10085. {
  10086. strings.insert (index, newString);
  10087. }
  10088. void StringArray::addIfNotAlreadyThere (const String& newString, const bool ignoreCase)
  10089. {
  10090. if (! contains (newString, ignoreCase))
  10091. add (newString);
  10092. }
  10093. void StringArray::addArray (const StringArray& otherArray, int startIndex, int numElementsToAdd)
  10094. {
  10095. if (startIndex < 0)
  10096. {
  10097. jassertfalse
  10098. startIndex = 0;
  10099. }
  10100. if (numElementsToAdd < 0 || startIndex + numElementsToAdd > otherArray.size())
  10101. numElementsToAdd = otherArray.size() - startIndex;
  10102. while (--numElementsToAdd >= 0)
  10103. strings.add (otherArray.strings.getReference (startIndex++));
  10104. }
  10105. void StringArray::set (const int index, const String& newString)
  10106. {
  10107. strings.set (index, newString);
  10108. }
  10109. bool StringArray::contains (const String& stringToLookFor, const bool ignoreCase) const
  10110. {
  10111. if (ignoreCase)
  10112. {
  10113. for (int i = size(); --i >= 0;)
  10114. if (strings.getReference(i).equalsIgnoreCase (stringToLookFor))
  10115. return true;
  10116. }
  10117. else
  10118. {
  10119. for (int i = size(); --i >= 0;)
  10120. if (stringToLookFor == strings.getReference(i))
  10121. return true;
  10122. }
  10123. return false;
  10124. }
  10125. int StringArray::indexOf (const String& stringToLookFor, const bool ignoreCase, int i) const
  10126. {
  10127. if (i < 0)
  10128. i = 0;
  10129. const int numElements = size();
  10130. if (ignoreCase)
  10131. {
  10132. while (i < numElements)
  10133. {
  10134. if (strings.getReference(i).equalsIgnoreCase (stringToLookFor))
  10135. return i;
  10136. ++i;
  10137. }
  10138. }
  10139. else
  10140. {
  10141. while (i < numElements)
  10142. {
  10143. if (stringToLookFor == strings.getReference (i))
  10144. return i;
  10145. ++i;
  10146. }
  10147. }
  10148. return -1;
  10149. }
  10150. void StringArray::remove (const int index)
  10151. {
  10152. strings.remove (index);
  10153. }
  10154. void StringArray::removeString (const String& stringToRemove,
  10155. const bool ignoreCase)
  10156. {
  10157. if (ignoreCase)
  10158. {
  10159. for (int i = size(); --i >= 0;)
  10160. if (strings.getReference(i).equalsIgnoreCase (stringToRemove))
  10161. strings.remove (i);
  10162. }
  10163. else
  10164. {
  10165. for (int i = size(); --i >= 0;)
  10166. if (stringToRemove == strings.getReference (i))
  10167. strings.remove (i);
  10168. }
  10169. }
  10170. void StringArray::removeEmptyStrings (const bool removeWhitespaceStrings)
  10171. {
  10172. if (removeWhitespaceStrings)
  10173. {
  10174. for (int i = size(); --i >= 0;)
  10175. if (! strings.getReference(i).containsNonWhitespaceChars())
  10176. strings.remove (i);
  10177. }
  10178. else
  10179. {
  10180. for (int i = size(); --i >= 0;)
  10181. if (strings.getReference(i).isEmpty())
  10182. strings.remove (i);
  10183. }
  10184. }
  10185. void StringArray::trim()
  10186. {
  10187. for (int i = size(); --i >= 0;)
  10188. {
  10189. String& s = strings.getReference(i);
  10190. s = s.trim();
  10191. }
  10192. }
  10193. class InternalStringArrayComparator_CaseSensitive
  10194. {
  10195. public:
  10196. static int compareElements (String& first, String& second) { return first.compare (second); }
  10197. };
  10198. class InternalStringArrayComparator_CaseInsensitive
  10199. {
  10200. public:
  10201. static int compareElements (String& first, String& second) { return first.compareIgnoreCase (second); }
  10202. };
  10203. void StringArray::sort (const bool ignoreCase)
  10204. {
  10205. if (ignoreCase)
  10206. {
  10207. InternalStringArrayComparator_CaseInsensitive comp;
  10208. strings.sort (comp);
  10209. }
  10210. else
  10211. {
  10212. InternalStringArrayComparator_CaseSensitive comp;
  10213. strings.sort (comp);
  10214. }
  10215. }
  10216. void StringArray::move (const int currentIndex, int newIndex) throw()
  10217. {
  10218. strings.move (currentIndex, newIndex);
  10219. }
  10220. const String StringArray::joinIntoString (const String& separator, int start, int numberToJoin) const
  10221. {
  10222. const int last = (numberToJoin < 0) ? size()
  10223. : jmin (size(), start + numberToJoin);
  10224. if (start < 0)
  10225. start = 0;
  10226. if (start >= last)
  10227. return String::empty;
  10228. if (start == last - 1)
  10229. return strings.getReference (start);
  10230. const int separatorLen = separator.length();
  10231. int charsNeeded = separatorLen * (last - start - 1);
  10232. for (int i = start; i < last; ++i)
  10233. charsNeeded += strings.getReference(i).length();
  10234. String result;
  10235. result.preallocateStorage (charsNeeded);
  10236. tchar* dest = (tchar*) (const tchar*) result;
  10237. while (start < last)
  10238. {
  10239. const String& s = strings.getReference (start);
  10240. const int len = s.length();
  10241. if (len > 0)
  10242. {
  10243. s.copyToBuffer (dest, len);
  10244. dest += len;
  10245. }
  10246. if (++start < last && separatorLen > 0)
  10247. {
  10248. separator.copyToBuffer (dest, separatorLen);
  10249. dest += separatorLen;
  10250. }
  10251. }
  10252. *dest = 0;
  10253. return result;
  10254. }
  10255. int StringArray::addTokens (const tchar* const text, const bool preserveQuotedStrings)
  10256. {
  10257. return addTokens (text,
  10258. T(" \n\r\t"),
  10259. preserveQuotedStrings ? T("\"") : 0);
  10260. }
  10261. int StringArray::addTokens (const tchar* const text, const tchar* breakCharacters, const tchar* quoteCharacters)
  10262. {
  10263. int num = 0;
  10264. if (text != 0 && *text != 0)
  10265. {
  10266. if (breakCharacters == 0)
  10267. breakCharacters = T("");
  10268. if (quoteCharacters == 0)
  10269. quoteCharacters = T("");
  10270. bool insideQuotes = false;
  10271. tchar currentQuoteChar = 0;
  10272. int i = 0;
  10273. int tokenStart = 0;
  10274. for (;;)
  10275. {
  10276. const tchar c = text[i];
  10277. bool isBreak = (c == 0);
  10278. if (! (insideQuotes || isBreak))
  10279. {
  10280. const tchar* b = breakCharacters;
  10281. while (*b != 0)
  10282. {
  10283. if (*b++ == c)
  10284. {
  10285. isBreak = true;
  10286. break;
  10287. }
  10288. }
  10289. }
  10290. if (! isBreak)
  10291. {
  10292. bool isQuote = false;
  10293. const tchar* q = quoteCharacters;
  10294. while (*q != 0)
  10295. {
  10296. if (*q++ == c)
  10297. {
  10298. isQuote = true;
  10299. break;
  10300. }
  10301. }
  10302. if (isQuote)
  10303. {
  10304. if (insideQuotes)
  10305. {
  10306. // only break out of quotes-mode if we find a matching quote to the
  10307. // one that we opened with..
  10308. if (currentQuoteChar == c)
  10309. insideQuotes = false;
  10310. }
  10311. else
  10312. {
  10313. insideQuotes = true;
  10314. currentQuoteChar = c;
  10315. }
  10316. }
  10317. }
  10318. else
  10319. {
  10320. add (String (text + tokenStart, i - tokenStart));
  10321. ++num;
  10322. tokenStart = i + 1;
  10323. }
  10324. if (c == 0)
  10325. break;
  10326. ++i;
  10327. }
  10328. }
  10329. return num;
  10330. }
  10331. int StringArray::addLines (const tchar* text)
  10332. {
  10333. int numLines = 0;
  10334. if (text != 0)
  10335. {
  10336. while (*text != 0)
  10337. {
  10338. const tchar* const startOfLine = text;
  10339. while (*text != 0)
  10340. {
  10341. if (*text == T('\r'))
  10342. {
  10343. ++text;
  10344. if (*text == T('\n'))
  10345. ++text;
  10346. break;
  10347. }
  10348. if (*text == T('\n'))
  10349. {
  10350. ++text;
  10351. break;
  10352. }
  10353. ++text;
  10354. }
  10355. const tchar* endOfLine = text;
  10356. if (endOfLine > startOfLine && (*(endOfLine - 1) == T('\r') || *(endOfLine - 1) == T('\n')))
  10357. --endOfLine;
  10358. if (endOfLine > startOfLine && (*(endOfLine - 1) == T('\r') || *(endOfLine - 1) == T('\n')))
  10359. --endOfLine;
  10360. add (String (startOfLine, jmax (0, (int) (endOfLine - startOfLine))));
  10361. ++numLines;
  10362. }
  10363. }
  10364. return numLines;
  10365. }
  10366. void StringArray::removeDuplicates (const bool ignoreCase)
  10367. {
  10368. for (int i = 0; i < size() - 1; ++i)
  10369. {
  10370. const String s (strings.getReference(i));
  10371. int nextIndex = i + 1;
  10372. for (;;)
  10373. {
  10374. nextIndex = indexOf (s, ignoreCase, nextIndex);
  10375. if (nextIndex < 0)
  10376. break;
  10377. strings.remove (nextIndex);
  10378. }
  10379. }
  10380. }
  10381. void StringArray::appendNumbersToDuplicates (const bool ignoreCase,
  10382. const bool appendNumberToFirstInstance,
  10383. const tchar* const preNumberString,
  10384. const tchar* const postNumberString)
  10385. {
  10386. for (int i = 0; i < size() - 1; ++i)
  10387. {
  10388. String& s = strings.getReference(i);
  10389. int nextIndex = indexOf (s, ignoreCase, i + 1);
  10390. if (nextIndex >= 0)
  10391. {
  10392. const String original (s);
  10393. int number = 0;
  10394. if (appendNumberToFirstInstance)
  10395. s = original + preNumberString + String (++number) + postNumberString;
  10396. else
  10397. ++number;
  10398. while (nextIndex >= 0)
  10399. {
  10400. set (nextIndex, (*this)[nextIndex] + preNumberString + String (++number) + postNumberString);
  10401. nextIndex = indexOf (original, ignoreCase, nextIndex + 1);
  10402. }
  10403. }
  10404. }
  10405. }
  10406. void StringArray::minimiseStorageOverheads()
  10407. {
  10408. strings.minimiseStorageOverheads();
  10409. }
  10410. END_JUCE_NAMESPACE
  10411. /********* End of inlined file: juce_StringArray.cpp *********/
  10412. /********* Start of inlined file: juce_StringPairArray.cpp *********/
  10413. BEGIN_JUCE_NAMESPACE
  10414. StringPairArray::StringPairArray (const bool ignoreCase_) throw()
  10415. : ignoreCase (ignoreCase_)
  10416. {
  10417. }
  10418. StringPairArray::StringPairArray (const StringPairArray& other) throw()
  10419. : keys (other.keys),
  10420. values (other.values),
  10421. ignoreCase (other.ignoreCase)
  10422. {
  10423. }
  10424. StringPairArray::~StringPairArray() throw()
  10425. {
  10426. }
  10427. const StringPairArray& StringPairArray::operator= (const StringPairArray& other) throw()
  10428. {
  10429. keys = other.keys;
  10430. values = other.values;
  10431. return *this;
  10432. }
  10433. bool StringPairArray::operator== (const StringPairArray& other) const throw()
  10434. {
  10435. for (int i = keys.size(); --i >= 0;)
  10436. if (other [keys[i]] != values[i])
  10437. return false;
  10438. return true;
  10439. }
  10440. bool StringPairArray::operator!= (const StringPairArray& other) const throw()
  10441. {
  10442. return ! operator== (other);
  10443. }
  10444. const String& StringPairArray::operator[] (const String& key) const throw()
  10445. {
  10446. return values [keys.indexOf (key, ignoreCase)];
  10447. }
  10448. const String StringPairArray::getValue (const String& key, const String& defaultReturnValue) const
  10449. {
  10450. const int i = keys.indexOf (key, ignoreCase);
  10451. if (i >= 0)
  10452. return values[i];
  10453. return defaultReturnValue;
  10454. }
  10455. void StringPairArray::set (const String& key,
  10456. const String& value) throw()
  10457. {
  10458. const int i = keys.indexOf (key, ignoreCase);
  10459. if (i >= 0)
  10460. {
  10461. values.set (i, value);
  10462. }
  10463. else
  10464. {
  10465. keys.add (key);
  10466. values.add (value);
  10467. }
  10468. }
  10469. void StringPairArray::addArray (const StringPairArray& other)
  10470. {
  10471. for (int i = 0; i < other.size(); ++i)
  10472. set (other.keys[i], other.values[i]);
  10473. }
  10474. void StringPairArray::clear() throw()
  10475. {
  10476. keys.clear();
  10477. values.clear();
  10478. }
  10479. void StringPairArray::remove (const String& key) throw()
  10480. {
  10481. remove (keys.indexOf (key, ignoreCase));
  10482. }
  10483. void StringPairArray::remove (const int index) throw()
  10484. {
  10485. keys.remove (index);
  10486. values.remove (index);
  10487. }
  10488. void StringPairArray::setIgnoresCase (const bool shouldIgnoreCase) throw()
  10489. {
  10490. ignoreCase = shouldIgnoreCase;
  10491. }
  10492. const String StringPairArray::getDescription() const
  10493. {
  10494. String s;
  10495. for (int i = 0; i < keys.size(); ++i)
  10496. {
  10497. s << keys[i] << T(" = ") << values[i];
  10498. if (i < keys.size())
  10499. s << T(", ");
  10500. }
  10501. return s;
  10502. }
  10503. void StringPairArray::minimiseStorageOverheads() throw()
  10504. {
  10505. keys.minimiseStorageOverheads();
  10506. values.minimiseStorageOverheads();
  10507. }
  10508. END_JUCE_NAMESPACE
  10509. /********* End of inlined file: juce_StringPairArray.cpp *********/
  10510. /********* Start of inlined file: juce_XmlDocument.cpp *********/
  10511. BEGIN_JUCE_NAMESPACE
  10512. XmlDocument::XmlDocument (const String& documentText) throw()
  10513. : originalText (documentText),
  10514. ignoreEmptyTextElements (true)
  10515. {
  10516. }
  10517. XmlDocument::XmlDocument (const File& file)
  10518. {
  10519. inputSource = new FileInputSource (file);
  10520. }
  10521. XmlDocument::~XmlDocument() throw()
  10522. {
  10523. }
  10524. void XmlDocument::setInputSource (InputSource* const newSource) throw()
  10525. {
  10526. inputSource = newSource;
  10527. }
  10528. void XmlDocument::setEmptyTextElementsIgnored (const bool shouldBeIgnored) throw()
  10529. {
  10530. ignoreEmptyTextElements = shouldBeIgnored;
  10531. }
  10532. bool XmlDocument::isXmlIdentifierCharSlow (const tchar c) throw()
  10533. {
  10534. return CharacterFunctions::isLetterOrDigit (c)
  10535. || c == T('_')
  10536. || c == T('-')
  10537. || c == T(':')
  10538. || c == T('.');
  10539. }
  10540. inline bool XmlDocument::isXmlIdentifierChar (const tchar c) const throw()
  10541. {
  10542. return (c > 0 && c <= 127) ? identifierLookupTable [(int) c]
  10543. : isXmlIdentifierCharSlow (c);
  10544. }
  10545. XmlElement* XmlDocument::getDocumentElement (const bool onlyReadOuterDocumentElement)
  10546. {
  10547. String textToParse (originalText);
  10548. if (textToParse.isEmpty() && inputSource != 0)
  10549. {
  10550. ScopedPointer <InputStream> in (inputSource->createInputStream());
  10551. if (in != 0)
  10552. {
  10553. MemoryBlock data;
  10554. in->readIntoMemoryBlock (data, onlyReadOuterDocumentElement ? 8192 : -1);
  10555. if (data.getSize() >= 2
  10556. && ((data[0] == (char)-2 && data[1] == (char)-1)
  10557. || (data[0] == (char)-1 && data[1] == (char)-2)))
  10558. {
  10559. textToParse = String::createStringFromData ((const char*) data.getData(), (int) data.getSize());
  10560. }
  10561. else
  10562. {
  10563. textToParse = String::fromUTF8 ((const uint8*) data.getData(), (int) data.getSize());
  10564. }
  10565. if (! onlyReadOuterDocumentElement)
  10566. originalText = textToParse;
  10567. }
  10568. }
  10569. input = textToParse;
  10570. lastError = String::empty;
  10571. errorOccurred = false;
  10572. outOfData = false;
  10573. needToLoadDTD = true;
  10574. for (int i = 0; i < 128; ++i)
  10575. identifierLookupTable[i] = isXmlIdentifierCharSlow ((tchar) i);
  10576. if (textToParse.isEmpty())
  10577. {
  10578. lastError = "not enough input";
  10579. }
  10580. else
  10581. {
  10582. skipHeader();
  10583. if (input != 0)
  10584. {
  10585. ScopedPointer <XmlElement> result (readNextElement (! onlyReadOuterDocumentElement));
  10586. if (! errorOccurred)
  10587. return result.release();
  10588. }
  10589. else
  10590. {
  10591. lastError = "incorrect xml header";
  10592. }
  10593. }
  10594. return 0;
  10595. }
  10596. const String& XmlDocument::getLastParseError() const throw()
  10597. {
  10598. return lastError;
  10599. }
  10600. void XmlDocument::setLastError (const String& desc, const bool carryOn) throw()
  10601. {
  10602. lastError = desc;
  10603. errorOccurred = ! carryOn;
  10604. }
  10605. const String XmlDocument::getFileContents (const String& filename) const
  10606. {
  10607. if (inputSource != 0)
  10608. {
  10609. const ScopedPointer <InputStream> in (inputSource->createInputStreamFor (filename.trim().unquoted()));
  10610. if (in != 0)
  10611. return in->readEntireStreamAsString();
  10612. }
  10613. return String::empty;
  10614. }
  10615. tchar XmlDocument::readNextChar() throw()
  10616. {
  10617. if (*input != 0)
  10618. {
  10619. return *input++;
  10620. }
  10621. else
  10622. {
  10623. outOfData = true;
  10624. return 0;
  10625. }
  10626. }
  10627. int XmlDocument::findNextTokenLength() throw()
  10628. {
  10629. int len = 0;
  10630. tchar c = *input;
  10631. while (isXmlIdentifierChar (c))
  10632. c = input [++len];
  10633. return len;
  10634. }
  10635. void XmlDocument::skipHeader() throw()
  10636. {
  10637. const tchar* const found = CharacterFunctions::find (input, T("<?xml"));
  10638. if (found != 0)
  10639. {
  10640. input = found;
  10641. input = CharacterFunctions::find (input, T("?>"));
  10642. if (input == 0)
  10643. return;
  10644. input += 2;
  10645. }
  10646. skipNextWhiteSpace();
  10647. const tchar* docType = CharacterFunctions::find (input, T("<!DOCTYPE"));
  10648. if (docType == 0)
  10649. return;
  10650. input = docType + 9;
  10651. int n = 1;
  10652. while (n > 0)
  10653. {
  10654. const tchar c = readNextChar();
  10655. if (outOfData)
  10656. return;
  10657. if (c == T('<'))
  10658. ++n;
  10659. else if (c == T('>'))
  10660. --n;
  10661. }
  10662. docType += 9;
  10663. dtdText = String (docType, (int) (input - (docType + 1))).trim();
  10664. }
  10665. void XmlDocument::skipNextWhiteSpace() throw()
  10666. {
  10667. for (;;)
  10668. {
  10669. tchar c = *input;
  10670. while (CharacterFunctions::isWhitespace (c))
  10671. c = *++input;
  10672. if (c == 0)
  10673. {
  10674. outOfData = true;
  10675. break;
  10676. }
  10677. else if (c == T('<'))
  10678. {
  10679. if (input[1] == T('!')
  10680. && input[2] == T('-')
  10681. && input[3] == T('-'))
  10682. {
  10683. const tchar* const closeComment = CharacterFunctions::find (input, T("-->"));
  10684. if (closeComment == 0)
  10685. {
  10686. outOfData = true;
  10687. break;
  10688. }
  10689. input = closeComment + 3;
  10690. continue;
  10691. }
  10692. else if (input[1] == T('?'))
  10693. {
  10694. const tchar* const closeBracket = CharacterFunctions::find (input, T("?>"));
  10695. if (closeBracket == 0)
  10696. {
  10697. outOfData = true;
  10698. break;
  10699. }
  10700. input = closeBracket + 2;
  10701. continue;
  10702. }
  10703. }
  10704. break;
  10705. }
  10706. }
  10707. void XmlDocument::readQuotedString (String& result) throw()
  10708. {
  10709. const tchar quote = readNextChar();
  10710. while (! outOfData)
  10711. {
  10712. const tchar c = readNextChar();
  10713. if (c == quote)
  10714. break;
  10715. if (c == T('&'))
  10716. {
  10717. --input;
  10718. readEntity (result);
  10719. }
  10720. else
  10721. {
  10722. --input;
  10723. const tchar* const start = input;
  10724. for (;;)
  10725. {
  10726. const tchar character = *input;
  10727. if (character == quote)
  10728. {
  10729. result.append (start, (int) (input - start));
  10730. ++input;
  10731. return;
  10732. }
  10733. else if (character == T('&'))
  10734. {
  10735. result.append (start, (int) (input - start));
  10736. break;
  10737. }
  10738. else if (character == 0)
  10739. {
  10740. outOfData = true;
  10741. setLastError ("unmatched quotes", false);
  10742. break;
  10743. }
  10744. ++input;
  10745. }
  10746. }
  10747. }
  10748. }
  10749. XmlElement* XmlDocument::readNextElement (const bool alsoParseSubElements) throw()
  10750. {
  10751. XmlElement* node = 0;
  10752. skipNextWhiteSpace();
  10753. if (outOfData)
  10754. return 0;
  10755. input = CharacterFunctions::find (input, T("<"));
  10756. if (input != 0)
  10757. {
  10758. ++input;
  10759. int tagLen = findNextTokenLength();
  10760. if (tagLen == 0)
  10761. {
  10762. // no tag name - but allow for a gap after the '<' before giving an error
  10763. skipNextWhiteSpace();
  10764. tagLen = findNextTokenLength();
  10765. if (tagLen == 0)
  10766. {
  10767. setLastError ("tag name missing", false);
  10768. return node;
  10769. }
  10770. }
  10771. node = new XmlElement (input, tagLen);
  10772. input += tagLen;
  10773. XmlElement::XmlAttributeNode* lastAttribute = 0;
  10774. // look for attributes
  10775. for (;;)
  10776. {
  10777. skipNextWhiteSpace();
  10778. const tchar c = *input;
  10779. // empty tag..
  10780. if (c == T('/') && input[1] == T('>'))
  10781. {
  10782. input += 2;
  10783. break;
  10784. }
  10785. // parse the guts of the element..
  10786. if (c == T('>'))
  10787. {
  10788. ++input;
  10789. skipNextWhiteSpace();
  10790. if (alsoParseSubElements)
  10791. readChildElements (node);
  10792. break;
  10793. }
  10794. // get an attribute..
  10795. if (isXmlIdentifierChar (c))
  10796. {
  10797. const int attNameLen = findNextTokenLength();
  10798. if (attNameLen > 0)
  10799. {
  10800. const tchar* attNameStart = input;
  10801. input += attNameLen;
  10802. skipNextWhiteSpace();
  10803. if (readNextChar() == T('='))
  10804. {
  10805. skipNextWhiteSpace();
  10806. const tchar nextChar = *input;
  10807. if (nextChar == T('"') || nextChar == T('\''))
  10808. {
  10809. XmlElement::XmlAttributeNode* const newAtt
  10810. = new XmlElement::XmlAttributeNode (String (attNameStart, attNameLen),
  10811. String::empty);
  10812. readQuotedString (newAtt->value);
  10813. if (lastAttribute == 0)
  10814. node->attributes = newAtt;
  10815. else
  10816. lastAttribute->next = newAtt;
  10817. lastAttribute = newAtt;
  10818. continue;
  10819. }
  10820. }
  10821. }
  10822. }
  10823. else
  10824. {
  10825. if (! outOfData)
  10826. setLastError ("illegal character found in " + node->getTagName() + ": '" + c + "'", false);
  10827. }
  10828. break;
  10829. }
  10830. }
  10831. return node;
  10832. }
  10833. void XmlDocument::readChildElements (XmlElement* parent) throw()
  10834. {
  10835. XmlElement* lastChildNode = 0;
  10836. for (;;)
  10837. {
  10838. skipNextWhiteSpace();
  10839. if (outOfData)
  10840. {
  10841. setLastError ("unmatched tags", false);
  10842. break;
  10843. }
  10844. if (*input == T('<'))
  10845. {
  10846. if (input[1] == T('/'))
  10847. {
  10848. // our close tag..
  10849. input = CharacterFunctions::find (input, T(">"));
  10850. ++input;
  10851. break;
  10852. }
  10853. else if (input[1] == T('!')
  10854. && input[2] == T('[')
  10855. && input[3] == T('C')
  10856. && input[4] == T('D')
  10857. && input[5] == T('A')
  10858. && input[6] == T('T')
  10859. && input[7] == T('A')
  10860. && input[8] == T('['))
  10861. {
  10862. input += 9;
  10863. const tchar* const inputStart = input;
  10864. int len = 0;
  10865. for (;;)
  10866. {
  10867. if (*input == 0)
  10868. {
  10869. setLastError ("unterminated CDATA section", false);
  10870. outOfData = true;
  10871. break;
  10872. }
  10873. else if (input[0] == T(']')
  10874. && input[1] == T(']')
  10875. && input[2] == T('>'))
  10876. {
  10877. input += 3;
  10878. break;
  10879. }
  10880. ++input;
  10881. ++len;
  10882. }
  10883. XmlElement* const e = new XmlElement ((int) 0);
  10884. e->setText (String (inputStart, len));
  10885. if (lastChildNode != 0)
  10886. lastChildNode->nextElement = e;
  10887. else
  10888. parent->addChildElement (e);
  10889. lastChildNode = e;
  10890. }
  10891. else
  10892. {
  10893. // this is some other element, so parse and add it..
  10894. XmlElement* const n = readNextElement (true);
  10895. if (n != 0)
  10896. {
  10897. if (lastChildNode == 0)
  10898. parent->addChildElement (n);
  10899. else
  10900. lastChildNode->nextElement = n;
  10901. lastChildNode = n;
  10902. }
  10903. else
  10904. {
  10905. return;
  10906. }
  10907. }
  10908. }
  10909. else
  10910. {
  10911. // read character block..
  10912. XmlElement* const e = new XmlElement ((int)0);
  10913. if (lastChildNode != 0)
  10914. lastChildNode->nextElement = e;
  10915. else
  10916. parent->addChildElement (e);
  10917. lastChildNode = e;
  10918. String textElementContent;
  10919. for (;;)
  10920. {
  10921. const tchar c = *input;
  10922. if (c == T('<'))
  10923. break;
  10924. if (c == 0)
  10925. {
  10926. setLastError ("unmatched tags", false);
  10927. outOfData = true;
  10928. return;
  10929. }
  10930. if (c == T('&'))
  10931. {
  10932. String entity;
  10933. readEntity (entity);
  10934. if (entity.startsWithChar (T('<')) && entity [1] != 0)
  10935. {
  10936. const tchar* const oldInput = input;
  10937. const bool oldOutOfData = outOfData;
  10938. input = (const tchar*) entity;
  10939. outOfData = false;
  10940. for (;;)
  10941. {
  10942. XmlElement* const n = readNextElement (true);
  10943. if (n == 0)
  10944. break;
  10945. if (lastChildNode == 0)
  10946. parent->addChildElement (n);
  10947. else
  10948. lastChildNode->nextElement = n;
  10949. lastChildNode = n;
  10950. }
  10951. input = oldInput;
  10952. outOfData = oldOutOfData;
  10953. }
  10954. else
  10955. {
  10956. textElementContent += entity;
  10957. }
  10958. }
  10959. else
  10960. {
  10961. const tchar* start = input;
  10962. int len = 0;
  10963. for (;;)
  10964. {
  10965. const tchar nextChar = *input;
  10966. if (nextChar == T('<') || nextChar == T('&'))
  10967. {
  10968. break;
  10969. }
  10970. else if (nextChar == 0)
  10971. {
  10972. setLastError ("unmatched tags", false);
  10973. outOfData = true;
  10974. return;
  10975. }
  10976. ++input;
  10977. ++len;
  10978. }
  10979. textElementContent.append (start, len);
  10980. }
  10981. }
  10982. if (ignoreEmptyTextElements ? textElementContent.containsNonWhitespaceChars()
  10983. : textElementContent.isNotEmpty())
  10984. e->setText (textElementContent);
  10985. }
  10986. }
  10987. }
  10988. void XmlDocument::readEntity (String& result) throw()
  10989. {
  10990. // skip over the ampersand
  10991. ++input;
  10992. if (CharacterFunctions::compareIgnoreCase (input, T("amp;"), 4) == 0)
  10993. {
  10994. input += 4;
  10995. result += T("&");
  10996. }
  10997. else if (CharacterFunctions::compareIgnoreCase (input, T("quot;"), 5) == 0)
  10998. {
  10999. input += 5;
  11000. result += T("\"");
  11001. }
  11002. else if (CharacterFunctions::compareIgnoreCase (input, T("apos;"), 5) == 0)
  11003. {
  11004. input += 5;
  11005. result += T("\'");
  11006. }
  11007. else if (CharacterFunctions::compareIgnoreCase (input, T("lt;"), 3) == 0)
  11008. {
  11009. input += 3;
  11010. result += T("<");
  11011. }
  11012. else if (CharacterFunctions::compareIgnoreCase (input, T("gt;"), 3) == 0)
  11013. {
  11014. input += 3;
  11015. result += T(">");
  11016. }
  11017. else if (*input == T('#'))
  11018. {
  11019. int charCode = 0;
  11020. ++input;
  11021. if (*input == T('x') || *input == T('X'))
  11022. {
  11023. ++input;
  11024. int numChars = 0;
  11025. while (input[0] != T(';'))
  11026. {
  11027. const int hexValue = CharacterFunctions::getHexDigitValue (input[0]);
  11028. if (hexValue < 0 || ++numChars > 8)
  11029. {
  11030. setLastError ("illegal escape sequence", true);
  11031. break;
  11032. }
  11033. charCode = (charCode << 4) | hexValue;
  11034. ++input;
  11035. }
  11036. ++input;
  11037. }
  11038. else if (input[0] >= T('0') && input[0] <= T('9'))
  11039. {
  11040. int numChars = 0;
  11041. while (input[0] != T(';'))
  11042. {
  11043. if (++numChars > 12)
  11044. {
  11045. setLastError ("illegal escape sequence", true);
  11046. break;
  11047. }
  11048. charCode = charCode * 10 + (input[0] - T('0'));
  11049. ++input;
  11050. }
  11051. ++input;
  11052. }
  11053. else
  11054. {
  11055. setLastError ("illegal escape sequence", true);
  11056. result += T("&");
  11057. return;
  11058. }
  11059. result << (tchar) charCode;
  11060. }
  11061. else
  11062. {
  11063. const tchar* const entityNameStart = input;
  11064. const tchar* const closingSemiColon = CharacterFunctions::find (input, T(";"));
  11065. if (closingSemiColon == 0)
  11066. {
  11067. outOfData = true;
  11068. result += T("&");
  11069. }
  11070. else
  11071. {
  11072. input = closingSemiColon + 1;
  11073. result += expandExternalEntity (String (entityNameStart,
  11074. (int) (closingSemiColon - entityNameStart)));
  11075. }
  11076. }
  11077. }
  11078. const String XmlDocument::expandEntity (const String& ent)
  11079. {
  11080. if (ent.equalsIgnoreCase (T("amp")))
  11081. {
  11082. return T("&");
  11083. }
  11084. else if (ent.equalsIgnoreCase (T("quot")))
  11085. {
  11086. return T("\"");
  11087. }
  11088. else if (ent.equalsIgnoreCase (T("apos")))
  11089. {
  11090. return T("\'");
  11091. }
  11092. else if (ent.equalsIgnoreCase (T("lt")))
  11093. {
  11094. return T("<");
  11095. }
  11096. else if (ent.equalsIgnoreCase (T("gt")))
  11097. {
  11098. return T(">");
  11099. }
  11100. else if (ent[0] == T('#'))
  11101. {
  11102. if (ent[1] == T('x') || ent[1] == T('X'))
  11103. {
  11104. return String::charToString ((tchar) ent.substring (2).getHexValue32());
  11105. }
  11106. else if (ent[1] >= T('0') && ent[1] <= T('9'))
  11107. {
  11108. return String::charToString ((tchar) ent.substring (1).getIntValue());
  11109. }
  11110. setLastError ("illegal escape sequence", false);
  11111. return T("&");
  11112. }
  11113. else
  11114. {
  11115. return expandExternalEntity (ent);
  11116. }
  11117. }
  11118. const String XmlDocument::expandExternalEntity (const String& entity)
  11119. {
  11120. if (needToLoadDTD)
  11121. {
  11122. if (dtdText.isNotEmpty())
  11123. {
  11124. while (dtdText.endsWithChar (T('>')))
  11125. dtdText = dtdText.dropLastCharacters (1);
  11126. tokenisedDTD.addTokens (dtdText, true);
  11127. if (tokenisedDTD [tokenisedDTD.size() - 2].equalsIgnoreCase (T("system"))
  11128. && tokenisedDTD [tokenisedDTD.size() - 1].isQuotedString())
  11129. {
  11130. const String fn (tokenisedDTD [tokenisedDTD.size() - 1]);
  11131. tokenisedDTD.clear();
  11132. tokenisedDTD.addTokens (getFileContents (fn), true);
  11133. }
  11134. else
  11135. {
  11136. tokenisedDTD.clear();
  11137. const int openBracket = dtdText.indexOfChar (T('['));
  11138. if (openBracket > 0)
  11139. {
  11140. const int closeBracket = dtdText.lastIndexOfChar (T(']'));
  11141. if (closeBracket > openBracket)
  11142. tokenisedDTD.addTokens (dtdText.substring (openBracket + 1,
  11143. closeBracket), true);
  11144. }
  11145. }
  11146. for (int i = tokenisedDTD.size(); --i >= 0;)
  11147. {
  11148. if (tokenisedDTD[i].startsWithChar (T('%'))
  11149. && tokenisedDTD[i].endsWithChar (T(';')))
  11150. {
  11151. const String parsed (getParameterEntity (tokenisedDTD[i].substring (1, tokenisedDTD[i].length() - 1)));
  11152. StringArray newToks;
  11153. newToks.addTokens (parsed, true);
  11154. tokenisedDTD.remove (i);
  11155. for (int j = newToks.size(); --j >= 0;)
  11156. tokenisedDTD.insert (i, newToks[j]);
  11157. }
  11158. }
  11159. }
  11160. needToLoadDTD = false;
  11161. }
  11162. for (int i = 0; i < tokenisedDTD.size(); ++i)
  11163. {
  11164. if (tokenisedDTD[i] == entity)
  11165. {
  11166. if (tokenisedDTD[i - 1].equalsIgnoreCase (T("<!entity")))
  11167. {
  11168. String ent (tokenisedDTD [i + 1]);
  11169. while (ent.endsWithChar (T('>')))
  11170. ent = ent.dropLastCharacters (1);
  11171. ent = ent.trim().unquoted();
  11172. // check for sub-entities..
  11173. int ampersand = ent.indexOfChar (T('&'));
  11174. while (ampersand >= 0)
  11175. {
  11176. const int semiColon = ent.indexOf (i + 1, T(";"));
  11177. if (semiColon < 0)
  11178. {
  11179. setLastError ("entity without terminating semi-colon", false);
  11180. break;
  11181. }
  11182. const String resolved (expandEntity (ent.substring (i + 1, semiColon)));
  11183. ent = ent.substring (0, ampersand)
  11184. + resolved
  11185. + ent.substring (semiColon + 1);
  11186. ampersand = ent.indexOfChar (semiColon + 1, T('&'));
  11187. }
  11188. return ent;
  11189. }
  11190. }
  11191. }
  11192. setLastError ("unknown entity", true);
  11193. return entity;
  11194. }
  11195. const String XmlDocument::getParameterEntity (const String& entity)
  11196. {
  11197. for (int i = 0; i < tokenisedDTD.size(); ++i)
  11198. {
  11199. if (tokenisedDTD[i] == entity)
  11200. {
  11201. if (tokenisedDTD [i - 1] == T("%")
  11202. && tokenisedDTD [i - 2].equalsIgnoreCase (T("<!entity")))
  11203. {
  11204. String ent (tokenisedDTD [i + 1]);
  11205. while (ent.endsWithChar (T('>')))
  11206. ent = ent.dropLastCharacters (1);
  11207. if (ent.equalsIgnoreCase (T("system")))
  11208. {
  11209. String filename (tokenisedDTD [i + 2]);
  11210. while (filename.endsWithChar (T('>')))
  11211. filename = filename.dropLastCharacters (1);
  11212. return getFileContents (filename);
  11213. }
  11214. else
  11215. {
  11216. return ent.trim().unquoted();
  11217. }
  11218. }
  11219. }
  11220. }
  11221. return entity;
  11222. }
  11223. END_JUCE_NAMESPACE
  11224. /********* End of inlined file: juce_XmlDocument.cpp *********/
  11225. /********* Start of inlined file: juce_XmlElement.cpp *********/
  11226. BEGIN_JUCE_NAMESPACE
  11227. XmlElement::XmlAttributeNode::XmlAttributeNode (const XmlAttributeNode& other) throw()
  11228. : name (other.name),
  11229. value (other.value),
  11230. next (0)
  11231. {
  11232. }
  11233. XmlElement::XmlAttributeNode::XmlAttributeNode (const String& name_,
  11234. const String& value_) throw()
  11235. : name (name_),
  11236. value (value_),
  11237. next (0)
  11238. {
  11239. }
  11240. XmlElement::XmlElement (const String& tagName_) throw()
  11241. : tagName (tagName_),
  11242. firstChildElement (0),
  11243. nextElement (0),
  11244. attributes (0)
  11245. {
  11246. // the tag name mustn't be empty, or it'll look like a text element!
  11247. jassert (tagName_.containsNonWhitespaceChars())
  11248. }
  11249. XmlElement::XmlElement (int /*dummy*/) throw()
  11250. : firstChildElement (0),
  11251. nextElement (0),
  11252. attributes (0)
  11253. {
  11254. }
  11255. XmlElement::XmlElement (const tchar* const tagName_,
  11256. const int nameLen) throw()
  11257. : tagName (tagName_, nameLen),
  11258. firstChildElement (0),
  11259. nextElement (0),
  11260. attributes (0)
  11261. {
  11262. }
  11263. XmlElement::XmlElement (const XmlElement& other) throw()
  11264. : tagName (other.tagName),
  11265. firstChildElement (0),
  11266. nextElement (0),
  11267. attributes (0)
  11268. {
  11269. copyChildrenAndAttributesFrom (other);
  11270. }
  11271. const XmlElement& XmlElement::operator= (const XmlElement& other) throw()
  11272. {
  11273. if (this != &other)
  11274. {
  11275. removeAllAttributes();
  11276. deleteAllChildElements();
  11277. tagName = other.tagName;
  11278. copyChildrenAndAttributesFrom (other);
  11279. }
  11280. return *this;
  11281. }
  11282. void XmlElement::copyChildrenAndAttributesFrom (const XmlElement& other) throw()
  11283. {
  11284. XmlElement* child = other.firstChildElement;
  11285. XmlElement* lastChild = 0;
  11286. while (child != 0)
  11287. {
  11288. XmlElement* const copiedChild = new XmlElement (*child);
  11289. if (lastChild != 0)
  11290. lastChild->nextElement = copiedChild;
  11291. else
  11292. firstChildElement = copiedChild;
  11293. lastChild = copiedChild;
  11294. child = child->nextElement;
  11295. }
  11296. const XmlAttributeNode* att = other.attributes;
  11297. XmlAttributeNode* lastAtt = 0;
  11298. while (att != 0)
  11299. {
  11300. XmlAttributeNode* const newAtt = new XmlAttributeNode (*att);
  11301. if (lastAtt != 0)
  11302. lastAtt->next = newAtt;
  11303. else
  11304. attributes = newAtt;
  11305. lastAtt = newAtt;
  11306. att = att->next;
  11307. }
  11308. }
  11309. XmlElement::~XmlElement() throw()
  11310. {
  11311. XmlElement* child = firstChildElement;
  11312. while (child != 0)
  11313. {
  11314. XmlElement* const nextChild = child->nextElement;
  11315. delete child;
  11316. child = nextChild;
  11317. }
  11318. XmlAttributeNode* att = attributes;
  11319. while (att != 0)
  11320. {
  11321. XmlAttributeNode* const nextAtt = att->next;
  11322. delete att;
  11323. att = nextAtt;
  11324. }
  11325. }
  11326. static bool isLegalXmlChar (const juce_wchar character)
  11327. {
  11328. if ((character >= 'a' && character <= 'z')
  11329. || (character >= 'A' && character <= 'Z')
  11330. || (character >= '0' && character <= '9'))
  11331. return true;
  11332. const char* t = " .,;:-()_+=?!'#@[]/\\*%~{}";
  11333. do
  11334. {
  11335. if (((juce_wchar) (uint8) *t) == character)
  11336. return true;
  11337. }
  11338. while (*++t != 0);
  11339. return false;
  11340. }
  11341. static void escapeIllegalXmlChars (OutputStream& outputStream,
  11342. const String& text,
  11343. const bool changeNewLines) throw()
  11344. {
  11345. const juce_wchar* t = (const juce_wchar*) text;
  11346. for (;;)
  11347. {
  11348. const juce_wchar character = *t++;
  11349. if (character == 0)
  11350. {
  11351. break;
  11352. }
  11353. else if (isLegalXmlChar (character))
  11354. {
  11355. outputStream.writeByte ((char) character);
  11356. }
  11357. else
  11358. {
  11359. switch (character)
  11360. {
  11361. case '&':
  11362. outputStream.write ("&amp;", 5);
  11363. break;
  11364. case '"':
  11365. outputStream.write ("&quot;", 6);
  11366. break;
  11367. case '>':
  11368. outputStream.write ("&gt;", 4);
  11369. break;
  11370. case '<':
  11371. outputStream.write ("&lt;", 4);
  11372. break;
  11373. case '\n':
  11374. if (changeNewLines)
  11375. outputStream.write ("&#10;", 5);
  11376. else
  11377. outputStream.writeByte ((char) character);
  11378. break;
  11379. case '\r':
  11380. if (changeNewLines)
  11381. outputStream.write ("&#13;", 5);
  11382. else
  11383. outputStream.writeByte ((char) character);
  11384. break;
  11385. default:
  11386. {
  11387. String encoded (T("&#"));
  11388. encoded << String ((int) (unsigned int) character).trim()
  11389. << T(';');
  11390. outputStream.write ((const char*) encoded, encoded.length());
  11391. }
  11392. }
  11393. }
  11394. }
  11395. }
  11396. static void writeSpaces (OutputStream& out, int numSpaces) throw()
  11397. {
  11398. if (numSpaces > 0)
  11399. {
  11400. const char* const blanks = " ";
  11401. const int blankSize = (int) sizeof (blanks) - 1;
  11402. while (numSpaces > blankSize)
  11403. {
  11404. out.write (blanks, blankSize);
  11405. numSpaces -= blankSize;
  11406. }
  11407. out.write (blanks, numSpaces);
  11408. }
  11409. }
  11410. void XmlElement::writeElementAsText (OutputStream& outputStream,
  11411. const int indentationLevel,
  11412. const int lineWrapLength) const throw()
  11413. {
  11414. writeSpaces (outputStream, indentationLevel);
  11415. if (! isTextElement())
  11416. {
  11417. outputStream.writeByte ('<');
  11418. const int nameLen = tagName.length();
  11419. outputStream.write ((const char*) tagName, nameLen);
  11420. const int attIndent = indentationLevel + nameLen + 1;
  11421. int lineLen = 0;
  11422. const XmlAttributeNode* att = attributes;
  11423. while (att != 0)
  11424. {
  11425. if (lineLen > lineWrapLength && indentationLevel >= 0)
  11426. {
  11427. outputStream.write ("\r\n", 2);
  11428. writeSpaces (outputStream, attIndent);
  11429. lineLen = 0;
  11430. }
  11431. const int attNameLen = att->name.length();
  11432. outputStream.writeByte (' ');
  11433. outputStream.write ((const char*) (att->name), attNameLen);
  11434. outputStream.write ("=\"", 2);
  11435. escapeIllegalXmlChars (outputStream, att->value, true);
  11436. outputStream.writeByte ('"');
  11437. lineLen += 4 + attNameLen + att->value.length();
  11438. att = att->next;
  11439. }
  11440. if (firstChildElement != 0)
  11441. {
  11442. XmlElement* child = firstChildElement;
  11443. if (child->nextElement == 0 && child->isTextElement())
  11444. {
  11445. outputStream.writeByte ('>');
  11446. escapeIllegalXmlChars (outputStream, child->getText(), false);
  11447. }
  11448. else
  11449. {
  11450. if (indentationLevel >= 0)
  11451. outputStream.write (">\r\n", 3);
  11452. else
  11453. outputStream.writeByte ('>');
  11454. bool lastWasTextNode = false;
  11455. while (child != 0)
  11456. {
  11457. if (child->isTextElement())
  11458. {
  11459. if ((! lastWasTextNode) && (indentationLevel >= 0))
  11460. writeSpaces (outputStream, indentationLevel + 2);
  11461. escapeIllegalXmlChars (outputStream, child->getText(), false);
  11462. lastWasTextNode = true;
  11463. }
  11464. else
  11465. {
  11466. if (indentationLevel >= 0)
  11467. {
  11468. if (lastWasTextNode)
  11469. outputStream.write ("\r\n", 2);
  11470. child->writeElementAsText (outputStream, indentationLevel + 2, lineWrapLength);
  11471. }
  11472. else
  11473. {
  11474. child->writeElementAsText (outputStream, indentationLevel, lineWrapLength);
  11475. }
  11476. lastWasTextNode = false;
  11477. }
  11478. child = child->nextElement;
  11479. }
  11480. if (indentationLevel >= 0)
  11481. {
  11482. if (lastWasTextNode)
  11483. outputStream.write ("\r\n", 2);
  11484. writeSpaces (outputStream, indentationLevel);
  11485. }
  11486. }
  11487. outputStream.write ("</", 2);
  11488. outputStream.write ((const char*) tagName, nameLen);
  11489. if (indentationLevel >= 0)
  11490. outputStream.write (">\r\n", 3);
  11491. else
  11492. outputStream.writeByte ('>');
  11493. }
  11494. else
  11495. {
  11496. if (indentationLevel >= 0)
  11497. outputStream.write ("/>\r\n", 4);
  11498. else
  11499. outputStream.write ("/>", 2);
  11500. }
  11501. }
  11502. else
  11503. {
  11504. if (indentationLevel >= 0)
  11505. writeSpaces (outputStream, indentationLevel + 2);
  11506. escapeIllegalXmlChars (outputStream, getText(), false);
  11507. }
  11508. }
  11509. const String XmlElement::createDocument (const String& dtdToUse,
  11510. const bool allOnOneLine,
  11511. const bool includeXmlHeader,
  11512. const tchar* const encodingType,
  11513. const int lineWrapLength) const throw()
  11514. {
  11515. MemoryOutputStream mem (2048, 4096);
  11516. writeToStream (mem, dtdToUse, allOnOneLine, includeXmlHeader, encodingType, lineWrapLength);
  11517. return String (mem.getData(), mem.getDataSize());
  11518. }
  11519. void XmlElement::writeToStream (OutputStream& output,
  11520. const String& dtdToUse,
  11521. const bool allOnOneLine,
  11522. const bool includeXmlHeader,
  11523. const tchar* const encodingType,
  11524. const int lineWrapLength) const throw()
  11525. {
  11526. if (includeXmlHeader)
  11527. {
  11528. output << "<?xml version=\"1.0\" encoding=\"" << encodingType;
  11529. if (allOnOneLine)
  11530. output << "\"?> ";
  11531. else
  11532. output << "\"?>\r\n\r\n";
  11533. }
  11534. if (dtdToUse.isNotEmpty())
  11535. {
  11536. output << dtdToUse;
  11537. if (allOnOneLine)
  11538. output << " ";
  11539. else
  11540. output << "\r\n";
  11541. }
  11542. writeElementAsText (output, allOnOneLine ? -1 : 0, lineWrapLength);
  11543. }
  11544. bool XmlElement::writeToFile (const File& file,
  11545. const String& dtdToUse,
  11546. const tchar* const encodingType,
  11547. const int lineWrapLength) const throw()
  11548. {
  11549. if (file.hasWriteAccess())
  11550. {
  11551. TemporaryFile tempFile (file);
  11552. ScopedPointer <FileOutputStream> out (tempFile.getFile().createOutputStream());
  11553. if (out != 0)
  11554. {
  11555. writeToStream (*out, dtdToUse, false, true, encodingType, lineWrapLength);
  11556. out = 0;
  11557. return tempFile.overwriteTargetFileWithTemporary();
  11558. }
  11559. }
  11560. return false;
  11561. }
  11562. bool XmlElement::hasTagName (const tchar* const tagNameWanted) const throw()
  11563. {
  11564. #ifdef JUCE_DEBUG
  11565. // if debugging, check that the case is actually the same, because
  11566. // valid xml is case-sensitive, and although this lets it pass, it's
  11567. // better not to..
  11568. if (tagName.equalsIgnoreCase (tagNameWanted))
  11569. {
  11570. jassert (tagName == tagNameWanted);
  11571. return true;
  11572. }
  11573. else
  11574. {
  11575. return false;
  11576. }
  11577. #else
  11578. return tagName.equalsIgnoreCase (tagNameWanted);
  11579. #endif
  11580. }
  11581. XmlElement* XmlElement::getNextElementWithTagName (const tchar* const requiredTagName) const
  11582. {
  11583. XmlElement* e = nextElement;
  11584. while (e != 0 && ! e->hasTagName (requiredTagName))
  11585. e = e->nextElement;
  11586. return e;
  11587. }
  11588. int XmlElement::getNumAttributes() const throw()
  11589. {
  11590. const XmlAttributeNode* att = attributes;
  11591. int count = 0;
  11592. while (att != 0)
  11593. {
  11594. att = att->next;
  11595. ++count;
  11596. }
  11597. return count;
  11598. }
  11599. const String& XmlElement::getAttributeName (const int index) const throw()
  11600. {
  11601. const XmlAttributeNode* att = attributes;
  11602. int count = 0;
  11603. while (att != 0)
  11604. {
  11605. if (count == index)
  11606. return att->name;
  11607. att = att->next;
  11608. ++count;
  11609. }
  11610. return String::empty;
  11611. }
  11612. const String& XmlElement::getAttributeValue (const int index) const throw()
  11613. {
  11614. const XmlAttributeNode* att = attributes;
  11615. int count = 0;
  11616. while (att != 0)
  11617. {
  11618. if (count == index)
  11619. return att->value;
  11620. att = att->next;
  11621. ++count;
  11622. }
  11623. return String::empty;
  11624. }
  11625. bool XmlElement::hasAttribute (const tchar* const attributeName) const throw()
  11626. {
  11627. const XmlAttributeNode* att = attributes;
  11628. while (att != 0)
  11629. {
  11630. if (att->name.equalsIgnoreCase (attributeName))
  11631. return true;
  11632. att = att->next;
  11633. }
  11634. return false;
  11635. }
  11636. const String XmlElement::getStringAttribute (const tchar* const attributeName,
  11637. const tchar* const defaultReturnValue) const throw()
  11638. {
  11639. const XmlAttributeNode* att = attributes;
  11640. while (att != 0)
  11641. {
  11642. if (att->name.equalsIgnoreCase (attributeName))
  11643. return att->value;
  11644. att = att->next;
  11645. }
  11646. return defaultReturnValue;
  11647. }
  11648. int XmlElement::getIntAttribute (const tchar* const attributeName,
  11649. const int defaultReturnValue) const throw()
  11650. {
  11651. const XmlAttributeNode* att = attributes;
  11652. while (att != 0)
  11653. {
  11654. if (att->name.equalsIgnoreCase (attributeName))
  11655. return att->value.getIntValue();
  11656. att = att->next;
  11657. }
  11658. return defaultReturnValue;
  11659. }
  11660. double XmlElement::getDoubleAttribute (const tchar* const attributeName,
  11661. const double defaultReturnValue) const throw()
  11662. {
  11663. const XmlAttributeNode* att = attributes;
  11664. while (att != 0)
  11665. {
  11666. if (att->name.equalsIgnoreCase (attributeName))
  11667. return att->value.getDoubleValue();
  11668. att = att->next;
  11669. }
  11670. return defaultReturnValue;
  11671. }
  11672. bool XmlElement::getBoolAttribute (const tchar* const attributeName,
  11673. const bool defaultReturnValue) const throw()
  11674. {
  11675. const XmlAttributeNode* att = attributes;
  11676. while (att != 0)
  11677. {
  11678. if (att->name.equalsIgnoreCase (attributeName))
  11679. {
  11680. tchar firstChar = att->value[0];
  11681. if (CharacterFunctions::isWhitespace (firstChar))
  11682. firstChar = att->value.trimStart() [0];
  11683. return firstChar == T('1')
  11684. || firstChar == T('t')
  11685. || firstChar == T('y')
  11686. || firstChar == T('T')
  11687. || firstChar == T('Y');
  11688. }
  11689. att = att->next;
  11690. }
  11691. return defaultReturnValue;
  11692. }
  11693. bool XmlElement::compareAttribute (const tchar* const attributeName,
  11694. const tchar* const stringToCompareAgainst,
  11695. const bool ignoreCase) const throw()
  11696. {
  11697. const XmlAttributeNode* att = attributes;
  11698. while (att != 0)
  11699. {
  11700. if (att->name.equalsIgnoreCase (attributeName))
  11701. {
  11702. if (ignoreCase)
  11703. return att->value.equalsIgnoreCase (stringToCompareAgainst);
  11704. else
  11705. return att->value == stringToCompareAgainst;
  11706. }
  11707. att = att->next;
  11708. }
  11709. return false;
  11710. }
  11711. void XmlElement::setAttribute (const tchar* const attributeName,
  11712. const String& value) throw()
  11713. {
  11714. #ifdef JUCE_DEBUG
  11715. // check the identifier being passed in is legal..
  11716. const tchar* t = attributeName;
  11717. while (*t != 0)
  11718. {
  11719. jassert (CharacterFunctions::isLetterOrDigit (*t)
  11720. || *t == T('_')
  11721. || *t == T('-')
  11722. || *t == T(':'));
  11723. ++t;
  11724. }
  11725. #endif
  11726. if (attributes == 0)
  11727. {
  11728. attributes = new XmlAttributeNode (attributeName, value);
  11729. }
  11730. else
  11731. {
  11732. XmlAttributeNode* att = attributes;
  11733. for (;;)
  11734. {
  11735. if (att->name.equalsIgnoreCase (attributeName))
  11736. {
  11737. att->value = value;
  11738. break;
  11739. }
  11740. else if (att->next == 0)
  11741. {
  11742. att->next = new XmlAttributeNode (attributeName, value);
  11743. break;
  11744. }
  11745. att = att->next;
  11746. }
  11747. }
  11748. }
  11749. void XmlElement::setAttribute (const tchar* const attributeName,
  11750. const tchar* const text) throw()
  11751. {
  11752. setAttribute (attributeName, String (text));
  11753. }
  11754. void XmlElement::setAttribute (const tchar* const attributeName,
  11755. const int number) throw()
  11756. {
  11757. setAttribute (attributeName, String (number));
  11758. }
  11759. void XmlElement::setAttribute (const tchar* const attributeName,
  11760. const double number) throw()
  11761. {
  11762. setAttribute (attributeName, String (number));
  11763. }
  11764. void XmlElement::removeAttribute (const tchar* const attributeName) throw()
  11765. {
  11766. XmlAttributeNode* att = attributes;
  11767. XmlAttributeNode* lastAtt = 0;
  11768. while (att != 0)
  11769. {
  11770. if (att->name.equalsIgnoreCase (attributeName))
  11771. {
  11772. if (lastAtt == 0)
  11773. attributes = att->next;
  11774. else
  11775. lastAtt->next = att->next;
  11776. delete att;
  11777. break;
  11778. }
  11779. lastAtt = att;
  11780. att = att->next;
  11781. }
  11782. }
  11783. void XmlElement::removeAllAttributes() throw()
  11784. {
  11785. while (attributes != 0)
  11786. {
  11787. XmlAttributeNode* const nextAtt = attributes->next;
  11788. delete attributes;
  11789. attributes = nextAtt;
  11790. }
  11791. }
  11792. int XmlElement::getNumChildElements() const throw()
  11793. {
  11794. int count = 0;
  11795. const XmlElement* child = firstChildElement;
  11796. while (child != 0)
  11797. {
  11798. ++count;
  11799. child = child->nextElement;
  11800. }
  11801. return count;
  11802. }
  11803. XmlElement* XmlElement::getChildElement (const int index) const throw()
  11804. {
  11805. int count = 0;
  11806. XmlElement* child = firstChildElement;
  11807. while (child != 0 && count < index)
  11808. {
  11809. child = child->nextElement;
  11810. ++count;
  11811. }
  11812. return child;
  11813. }
  11814. XmlElement* XmlElement::getChildByName (const tchar* const childName) const throw()
  11815. {
  11816. XmlElement* child = firstChildElement;
  11817. while (child != 0)
  11818. {
  11819. if (child->hasTagName (childName))
  11820. break;
  11821. child = child->nextElement;
  11822. }
  11823. return child;
  11824. }
  11825. void XmlElement::addChildElement (XmlElement* const newNode) throw()
  11826. {
  11827. if (newNode != 0)
  11828. {
  11829. if (firstChildElement == 0)
  11830. {
  11831. firstChildElement = newNode;
  11832. }
  11833. else
  11834. {
  11835. XmlElement* child = firstChildElement;
  11836. while (child->nextElement != 0)
  11837. child = child->nextElement;
  11838. child->nextElement = newNode;
  11839. // if this is non-zero, then something's probably
  11840. // gone wrong..
  11841. jassert (newNode->nextElement == 0);
  11842. }
  11843. }
  11844. }
  11845. void XmlElement::insertChildElement (XmlElement* const newNode,
  11846. int indexToInsertAt) throw()
  11847. {
  11848. if (newNode != 0)
  11849. {
  11850. removeChildElement (newNode, false);
  11851. if (indexToInsertAt == 0)
  11852. {
  11853. newNode->nextElement = firstChildElement;
  11854. firstChildElement = newNode;
  11855. }
  11856. else
  11857. {
  11858. if (firstChildElement == 0)
  11859. {
  11860. firstChildElement = newNode;
  11861. }
  11862. else
  11863. {
  11864. if (indexToInsertAt < 0)
  11865. indexToInsertAt = INT_MAX;
  11866. XmlElement* child = firstChildElement;
  11867. while (child->nextElement != 0 && --indexToInsertAt > 0)
  11868. child = child->nextElement;
  11869. newNode->nextElement = child->nextElement;
  11870. child->nextElement = newNode;
  11871. }
  11872. }
  11873. }
  11874. }
  11875. bool XmlElement::replaceChildElement (XmlElement* const currentChildElement,
  11876. XmlElement* const newNode) throw()
  11877. {
  11878. if (newNode != 0)
  11879. {
  11880. XmlElement* child = firstChildElement;
  11881. XmlElement* previousNode = 0;
  11882. while (child != 0)
  11883. {
  11884. if (child == currentChildElement)
  11885. {
  11886. if (child != newNode)
  11887. {
  11888. if (previousNode == 0)
  11889. firstChildElement = newNode;
  11890. else
  11891. previousNode->nextElement = newNode;
  11892. newNode->nextElement = child->nextElement;
  11893. delete child;
  11894. }
  11895. return true;
  11896. }
  11897. previousNode = child;
  11898. child = child->nextElement;
  11899. }
  11900. }
  11901. return false;
  11902. }
  11903. void XmlElement::removeChildElement (XmlElement* const childToRemove,
  11904. const bool shouldDeleteTheChild) throw()
  11905. {
  11906. if (childToRemove != 0)
  11907. {
  11908. if (firstChildElement == childToRemove)
  11909. {
  11910. firstChildElement = childToRemove->nextElement;
  11911. childToRemove->nextElement = 0;
  11912. }
  11913. else
  11914. {
  11915. XmlElement* child = firstChildElement;
  11916. XmlElement* last = 0;
  11917. while (child != 0)
  11918. {
  11919. if (child == childToRemove)
  11920. {
  11921. if (last == 0)
  11922. firstChildElement = child->nextElement;
  11923. else
  11924. last->nextElement = child->nextElement;
  11925. childToRemove->nextElement = 0;
  11926. break;
  11927. }
  11928. last = child;
  11929. child = child->nextElement;
  11930. }
  11931. }
  11932. if (shouldDeleteTheChild)
  11933. delete childToRemove;
  11934. }
  11935. }
  11936. bool XmlElement::isEquivalentTo (const XmlElement* const other,
  11937. const bool ignoreOrderOfAttributes) const throw()
  11938. {
  11939. if (this != other)
  11940. {
  11941. if (other == 0 || tagName != other->tagName)
  11942. {
  11943. return false;
  11944. }
  11945. if (ignoreOrderOfAttributes)
  11946. {
  11947. int totalAtts = 0;
  11948. const XmlAttributeNode* att = attributes;
  11949. while (att != 0)
  11950. {
  11951. if (! other->compareAttribute (att->name, att->value))
  11952. return false;
  11953. att = att->next;
  11954. ++totalAtts;
  11955. }
  11956. if (totalAtts != other->getNumAttributes())
  11957. return false;
  11958. }
  11959. else
  11960. {
  11961. const XmlAttributeNode* thisAtt = attributes;
  11962. const XmlAttributeNode* otherAtt = other->attributes;
  11963. for (;;)
  11964. {
  11965. if (thisAtt == 0 || otherAtt == 0)
  11966. {
  11967. if (thisAtt == otherAtt) // both 0, so it's a match
  11968. break;
  11969. return false;
  11970. }
  11971. if (thisAtt->name != otherAtt->name
  11972. || thisAtt->value != otherAtt->value)
  11973. {
  11974. return false;
  11975. }
  11976. thisAtt = thisAtt->next;
  11977. otherAtt = otherAtt->next;
  11978. }
  11979. }
  11980. const XmlElement* thisChild = firstChildElement;
  11981. const XmlElement* otherChild = other->firstChildElement;
  11982. for (;;)
  11983. {
  11984. if (thisChild == 0 || otherChild == 0)
  11985. {
  11986. if (thisChild == otherChild) // both 0, so it's a match
  11987. break;
  11988. return false;
  11989. }
  11990. if (! thisChild->isEquivalentTo (otherChild, ignoreOrderOfAttributes))
  11991. return false;
  11992. thisChild = thisChild->nextElement;
  11993. otherChild = otherChild->nextElement;
  11994. }
  11995. }
  11996. return true;
  11997. }
  11998. void XmlElement::deleteAllChildElements() throw()
  11999. {
  12000. while (firstChildElement != 0)
  12001. {
  12002. XmlElement* const nextChild = firstChildElement->nextElement;
  12003. delete firstChildElement;
  12004. firstChildElement = nextChild;
  12005. }
  12006. }
  12007. void XmlElement::deleteAllChildElementsWithTagName (const tchar* const name) throw()
  12008. {
  12009. XmlElement* child = firstChildElement;
  12010. while (child != 0)
  12011. {
  12012. if (child->hasTagName (name))
  12013. {
  12014. XmlElement* const nextChild = child->nextElement;
  12015. removeChildElement (child, true);
  12016. child = nextChild;
  12017. }
  12018. else
  12019. {
  12020. child = child->nextElement;
  12021. }
  12022. }
  12023. }
  12024. bool XmlElement::containsChildElement (const XmlElement* const possibleChild) const throw()
  12025. {
  12026. const XmlElement* child = firstChildElement;
  12027. while (child != 0)
  12028. {
  12029. if (child == possibleChild)
  12030. return true;
  12031. child = child->nextElement;
  12032. }
  12033. return false;
  12034. }
  12035. XmlElement* XmlElement::findParentElementOf (const XmlElement* const elementToLookFor) throw()
  12036. {
  12037. if (this == elementToLookFor || elementToLookFor == 0)
  12038. return 0;
  12039. XmlElement* child = firstChildElement;
  12040. while (child != 0)
  12041. {
  12042. if (elementToLookFor == child)
  12043. return this;
  12044. XmlElement* const found = child->findParentElementOf (elementToLookFor);
  12045. if (found != 0)
  12046. return found;
  12047. child = child->nextElement;
  12048. }
  12049. return 0;
  12050. }
  12051. void XmlElement::getChildElementsAsArray (XmlElement** elems) const throw()
  12052. {
  12053. XmlElement* e = firstChildElement;
  12054. while (e != 0)
  12055. {
  12056. *elems++ = e;
  12057. e = e->nextElement;
  12058. }
  12059. }
  12060. void XmlElement::reorderChildElements (XmlElement** const elems, const int num) throw()
  12061. {
  12062. XmlElement* e = firstChildElement = elems[0];
  12063. for (int i = 1; i < num; ++i)
  12064. {
  12065. e->nextElement = elems[i];
  12066. e = e->nextElement;
  12067. }
  12068. e->nextElement = 0;
  12069. }
  12070. bool XmlElement::isTextElement() const throw()
  12071. {
  12072. return tagName.isEmpty();
  12073. }
  12074. static const tchar* const juce_xmltextContentAttributeName = T("text");
  12075. const String XmlElement::getText() const throw()
  12076. {
  12077. jassert (isTextElement()); // you're trying to get the text from an element that
  12078. // isn't actually a text element.. If this contains text sub-nodes, you
  12079. // probably want to use getAllSubText instead.
  12080. return getStringAttribute (juce_xmltextContentAttributeName);
  12081. }
  12082. void XmlElement::setText (const String& newText) throw()
  12083. {
  12084. if (isTextElement())
  12085. {
  12086. setAttribute (juce_xmltextContentAttributeName, newText);
  12087. }
  12088. else
  12089. {
  12090. jassertfalse // you can only change the text in a text element, not a normal one.
  12091. }
  12092. }
  12093. const String XmlElement::getAllSubText() const throw()
  12094. {
  12095. String result;
  12096. String::Concatenator concatenator (result);
  12097. const XmlElement* child = firstChildElement;
  12098. while (child != 0)
  12099. {
  12100. if (child->isTextElement())
  12101. concatenator.append (child->getText());
  12102. child = child->nextElement;
  12103. }
  12104. return result;
  12105. }
  12106. const String XmlElement::getChildElementAllSubText (const tchar* const childTagName,
  12107. const String& defaultReturnValue) const throw()
  12108. {
  12109. const XmlElement* const child = getChildByName (childTagName);
  12110. if (child != 0)
  12111. return child->getAllSubText();
  12112. return defaultReturnValue;
  12113. }
  12114. XmlElement* XmlElement::createTextElement (const String& text) throw()
  12115. {
  12116. XmlElement* const e = new XmlElement ((int) 0);
  12117. e->setAttribute (juce_xmltextContentAttributeName, text);
  12118. return e;
  12119. }
  12120. void XmlElement::addTextElement (const String& text) throw()
  12121. {
  12122. addChildElement (createTextElement (text));
  12123. }
  12124. void XmlElement::deleteAllTextElements() throw()
  12125. {
  12126. XmlElement* child = firstChildElement;
  12127. while (child != 0)
  12128. {
  12129. XmlElement* const next = child->nextElement;
  12130. if (child->isTextElement())
  12131. removeChildElement (child, true);
  12132. child = next;
  12133. }
  12134. }
  12135. END_JUCE_NAMESPACE
  12136. /********* End of inlined file: juce_XmlElement.cpp *********/
  12137. /********* Start of inlined file: juce_InterProcessLock.cpp *********/
  12138. BEGIN_JUCE_NAMESPACE
  12139. // (implemented in the platform-specific code files)
  12140. END_JUCE_NAMESPACE
  12141. /********* End of inlined file: juce_InterProcessLock.cpp *********/
  12142. /********* Start of inlined file: juce_ReadWriteLock.cpp *********/
  12143. BEGIN_JUCE_NAMESPACE
  12144. ReadWriteLock::ReadWriteLock() throw()
  12145. : numWaitingWriters (0),
  12146. numWriters (0),
  12147. writerThreadId (0)
  12148. {
  12149. }
  12150. ReadWriteLock::~ReadWriteLock() throw()
  12151. {
  12152. jassert (readerThreads.size() == 0);
  12153. jassert (numWriters == 0);
  12154. }
  12155. void ReadWriteLock::enterRead() const throw()
  12156. {
  12157. const Thread::ThreadID threadId = Thread::getCurrentThreadId();
  12158. const ScopedLock sl (accessLock);
  12159. for (;;)
  12160. {
  12161. jassert (readerThreads.size() % 2 == 0);
  12162. int i;
  12163. for (i = 0; i < readerThreads.size(); i += 2)
  12164. if (readerThreads.getUnchecked(i) == threadId)
  12165. break;
  12166. if (i < readerThreads.size()
  12167. || numWriters + numWaitingWriters == 0
  12168. || (threadId == writerThreadId && numWriters > 0))
  12169. {
  12170. if (i < readerThreads.size())
  12171. {
  12172. readerThreads.set (i + 1, (Thread::ThreadID) (1 + (pointer_sized_int) readerThreads.getUnchecked (i + 1)));
  12173. }
  12174. else
  12175. {
  12176. readerThreads.add (threadId);
  12177. readerThreads.add ((Thread::ThreadID) 1);
  12178. }
  12179. return;
  12180. }
  12181. const ScopedUnlock ul (accessLock);
  12182. waitEvent.wait (100);
  12183. }
  12184. }
  12185. void ReadWriteLock::exitRead() const throw()
  12186. {
  12187. const Thread::ThreadID threadId = Thread::getCurrentThreadId();
  12188. const ScopedLock sl (accessLock);
  12189. for (int i = 0; i < readerThreads.size(); i += 2)
  12190. {
  12191. if (readerThreads.getUnchecked(i) == threadId)
  12192. {
  12193. const pointer_sized_int newCount = ((pointer_sized_int) readerThreads.getUnchecked (i + 1)) - 1;
  12194. if (newCount == 0)
  12195. {
  12196. readerThreads.removeRange (i, 2);
  12197. waitEvent.signal();
  12198. }
  12199. else
  12200. {
  12201. readerThreads.set (i + 1, (Thread::ThreadID) newCount);
  12202. }
  12203. return;
  12204. }
  12205. }
  12206. jassertfalse // unlocking a lock that wasn't locked..
  12207. }
  12208. void ReadWriteLock::enterWrite() const throw()
  12209. {
  12210. const Thread::ThreadID threadId = Thread::getCurrentThreadId();
  12211. const ScopedLock sl (accessLock);
  12212. for (;;)
  12213. {
  12214. if (readerThreads.size() + numWriters == 0
  12215. || threadId == writerThreadId
  12216. || (readerThreads.size() == 2
  12217. && readerThreads.getUnchecked(0) == threadId))
  12218. {
  12219. writerThreadId = threadId;
  12220. ++numWriters;
  12221. break;
  12222. }
  12223. ++numWaitingWriters;
  12224. accessLock.exit();
  12225. waitEvent.wait (100);
  12226. accessLock.enter();
  12227. --numWaitingWriters;
  12228. }
  12229. }
  12230. bool ReadWriteLock::tryEnterWrite() const throw()
  12231. {
  12232. const Thread::ThreadID threadId = Thread::getCurrentThreadId();
  12233. const ScopedLock sl (accessLock);
  12234. if (readerThreads.size() + numWriters == 0
  12235. || threadId == writerThreadId
  12236. || (readerThreads.size() == 2
  12237. && readerThreads.getUnchecked(0) == threadId))
  12238. {
  12239. writerThreadId = threadId;
  12240. ++numWriters;
  12241. return true;
  12242. }
  12243. return false;
  12244. }
  12245. void ReadWriteLock::exitWrite() const throw()
  12246. {
  12247. const ScopedLock sl (accessLock);
  12248. // check this thread actually had the lock..
  12249. jassert (numWriters > 0 && writerThreadId == Thread::getCurrentThreadId());
  12250. if (--numWriters == 0)
  12251. {
  12252. writerThreadId = 0;
  12253. waitEvent.signal();
  12254. }
  12255. }
  12256. END_JUCE_NAMESPACE
  12257. /********* End of inlined file: juce_ReadWriteLock.cpp *********/
  12258. /********* Start of inlined file: juce_Thread.cpp *********/
  12259. BEGIN_JUCE_NAMESPACE
  12260. // these functions are implemented in the platform-specific code.
  12261. void* juce_createThread (void* userData);
  12262. void juce_killThread (void* handle);
  12263. bool juce_setThreadPriority (void* handle, int priority);
  12264. void juce_setCurrentThreadName (const String& name);
  12265. #if JUCE_WIN32
  12266. void juce_CloseThreadHandle (void* handle);
  12267. #endif
  12268. static VoidArray runningThreads;
  12269. static CriticalSection runningThreadsLock;
  12270. void Thread::threadEntryPoint (Thread* const thread)
  12271. {
  12272. {
  12273. const ScopedLock sl (runningThreadsLock);
  12274. runningThreads.add (thread);
  12275. }
  12276. JUCE_TRY
  12277. {
  12278. thread->threadId_ = Thread::getCurrentThreadId();
  12279. if (thread->threadName_.isNotEmpty())
  12280. juce_setCurrentThreadName (thread->threadName_);
  12281. if (thread->startSuspensionEvent_.wait (10000))
  12282. {
  12283. if (thread->affinityMask_ != 0)
  12284. setCurrentThreadAffinityMask (thread->affinityMask_);
  12285. thread->run();
  12286. }
  12287. }
  12288. JUCE_CATCH_ALL_ASSERT
  12289. {
  12290. const ScopedLock sl (runningThreadsLock);
  12291. jassert (runningThreads.contains (thread));
  12292. runningThreads.removeValue (thread);
  12293. }
  12294. #if JUCE_WIN32
  12295. juce_CloseThreadHandle (thread->threadHandle_);
  12296. #endif
  12297. thread->threadHandle_ = 0;
  12298. thread->threadId_ = 0;
  12299. }
  12300. // used to wrap the incoming call from the platform-specific code
  12301. void JUCE_API juce_threadEntryPoint (void* userData)
  12302. {
  12303. Thread::threadEntryPoint ((Thread*) userData);
  12304. }
  12305. Thread::Thread (const String& threadName)
  12306. : threadName_ (threadName),
  12307. threadHandle_ (0),
  12308. threadPriority_ (5),
  12309. threadId_ (0),
  12310. affinityMask_ (0),
  12311. threadShouldExit_ (false)
  12312. {
  12313. }
  12314. Thread::~Thread()
  12315. {
  12316. stopThread (100);
  12317. }
  12318. void Thread::startThread()
  12319. {
  12320. const ScopedLock sl (startStopLock);
  12321. threadShouldExit_ = false;
  12322. if (threadHandle_ == 0)
  12323. {
  12324. threadHandle_ = juce_createThread ((void*) this);
  12325. juce_setThreadPriority (threadHandle_, threadPriority_);
  12326. startSuspensionEvent_.signal();
  12327. }
  12328. }
  12329. void Thread::startThread (const int priority)
  12330. {
  12331. const ScopedLock sl (startStopLock);
  12332. if (threadHandle_ == 0)
  12333. {
  12334. threadPriority_ = priority;
  12335. startThread();
  12336. }
  12337. else
  12338. {
  12339. setPriority (priority);
  12340. }
  12341. }
  12342. bool Thread::isThreadRunning() const
  12343. {
  12344. return threadHandle_ != 0;
  12345. }
  12346. void Thread::signalThreadShouldExit()
  12347. {
  12348. threadShouldExit_ = true;
  12349. }
  12350. bool Thread::waitForThreadToExit (const int timeOutMilliseconds) const
  12351. {
  12352. // Doh! So how exactly do you expect this thread to wait for itself to stop??
  12353. jassert (getThreadId() != getCurrentThreadId());
  12354. const int sleepMsPerIteration = 5;
  12355. int count = timeOutMilliseconds / sleepMsPerIteration;
  12356. while (isThreadRunning())
  12357. {
  12358. if (timeOutMilliseconds > 0 && --count < 0)
  12359. return false;
  12360. sleep (sleepMsPerIteration);
  12361. }
  12362. return true;
  12363. }
  12364. void Thread::stopThread (const int timeOutMilliseconds)
  12365. {
  12366. // agh! You can't stop the thread that's calling this method! How on earth
  12367. // would that work??
  12368. jassert (getCurrentThreadId() != getThreadId());
  12369. const ScopedLock sl (startStopLock);
  12370. if (isThreadRunning())
  12371. {
  12372. signalThreadShouldExit();
  12373. notify();
  12374. if (timeOutMilliseconds != 0)
  12375. waitForThreadToExit (timeOutMilliseconds);
  12376. if (isThreadRunning())
  12377. {
  12378. // very bad karma if this point is reached, as
  12379. // there are bound to be locks and events left in
  12380. // silly states when a thread is killed by force..
  12381. jassertfalse
  12382. Logger::writeToLog ("!! killing thread by force !!");
  12383. juce_killThread (threadHandle_);
  12384. threadHandle_ = 0;
  12385. threadId_ = 0;
  12386. const ScopedLock sl2 (runningThreadsLock);
  12387. runningThreads.removeValue (this);
  12388. }
  12389. }
  12390. }
  12391. bool Thread::setPriority (const int priority)
  12392. {
  12393. const ScopedLock sl (startStopLock);
  12394. const bool worked = juce_setThreadPriority (threadHandle_, priority);
  12395. if (worked)
  12396. threadPriority_ = priority;
  12397. return worked;
  12398. }
  12399. bool Thread::setCurrentThreadPriority (const int priority)
  12400. {
  12401. return juce_setThreadPriority (0, priority);
  12402. }
  12403. void Thread::setAffinityMask (const uint32 affinityMask)
  12404. {
  12405. affinityMask_ = affinityMask;
  12406. }
  12407. bool Thread::wait (const int timeOutMilliseconds) const
  12408. {
  12409. return defaultEvent_.wait (timeOutMilliseconds);
  12410. }
  12411. void Thread::notify() const
  12412. {
  12413. defaultEvent_.signal();
  12414. }
  12415. int Thread::getNumRunningThreads()
  12416. {
  12417. return runningThreads.size();
  12418. }
  12419. Thread* Thread::getCurrentThread()
  12420. {
  12421. const ThreadID thisId = getCurrentThreadId();
  12422. const ScopedLock sl (runningThreadsLock);
  12423. for (int i = runningThreads.size(); --i >= 0;)
  12424. {
  12425. Thread* const t = (Thread*) runningThreads.getUnchecked(i);
  12426. if (t->threadId_ == thisId)
  12427. return t;
  12428. }
  12429. return 0;
  12430. }
  12431. void Thread::stopAllThreads (const int timeOutMilliseconds)
  12432. {
  12433. {
  12434. const ScopedLock sl (runningThreadsLock);
  12435. for (int i = runningThreads.size(); --i >= 0;)
  12436. ((Thread*) runningThreads.getUnchecked(i))->signalThreadShouldExit();
  12437. }
  12438. for (;;)
  12439. {
  12440. runningThreadsLock.enter();
  12441. Thread* const t = (Thread*) runningThreads[0];
  12442. runningThreadsLock.exit();
  12443. if (t == 0)
  12444. break;
  12445. t->stopThread (timeOutMilliseconds);
  12446. }
  12447. }
  12448. END_JUCE_NAMESPACE
  12449. /********* End of inlined file: juce_Thread.cpp *********/
  12450. /********* Start of inlined file: juce_ThreadPool.cpp *********/
  12451. BEGIN_JUCE_NAMESPACE
  12452. ThreadPoolJob::ThreadPoolJob (const String& name)
  12453. : jobName (name),
  12454. pool (0),
  12455. shouldStop (false),
  12456. isActive (false),
  12457. shouldBeDeleted (false)
  12458. {
  12459. }
  12460. ThreadPoolJob::~ThreadPoolJob()
  12461. {
  12462. // you mustn't delete a job while it's still in a pool! Use ThreadPool::removeJob()
  12463. // to remove it first!
  12464. jassert (pool == 0 || ! pool->contains (this));
  12465. }
  12466. const String ThreadPoolJob::getJobName() const
  12467. {
  12468. return jobName;
  12469. }
  12470. void ThreadPoolJob::setJobName (const String& newName)
  12471. {
  12472. jobName = newName;
  12473. }
  12474. void ThreadPoolJob::signalJobShouldExit()
  12475. {
  12476. shouldStop = true;
  12477. }
  12478. class ThreadPool::ThreadPoolThread : public Thread
  12479. {
  12480. public:
  12481. ThreadPoolThread (ThreadPool& pool_)
  12482. : Thread (T("Pool")),
  12483. pool (pool_),
  12484. busy (false)
  12485. {
  12486. }
  12487. ~ThreadPoolThread()
  12488. {
  12489. }
  12490. void run()
  12491. {
  12492. while (! threadShouldExit())
  12493. {
  12494. if (! pool.runNextJob())
  12495. wait (500);
  12496. }
  12497. }
  12498. private:
  12499. ThreadPool& pool;
  12500. bool volatile busy;
  12501. ThreadPoolThread (const ThreadPoolThread&);
  12502. ThreadPoolThread& operator= (const ThreadPoolThread&);
  12503. };
  12504. ThreadPool::ThreadPool (const int numThreads,
  12505. const bool startThreadsOnlyWhenNeeded,
  12506. const int stopThreadsWhenNotUsedTimeoutMs)
  12507. : threadStopTimeout (stopThreadsWhenNotUsedTimeoutMs),
  12508. priority (5)
  12509. {
  12510. jassert (numThreads > 0); // not much point having one of these with no threads in it.
  12511. for (int i = jmax (1, numThreads); --i >= 0;)
  12512. threads.add (new ThreadPoolThread (*this));
  12513. if (! startThreadsOnlyWhenNeeded)
  12514. for (int i = threads.size(); --i >= 0;)
  12515. threads.getUnchecked(i)->startThread (priority);
  12516. }
  12517. ThreadPool::~ThreadPool()
  12518. {
  12519. removeAllJobs (true, 4000);
  12520. int i;
  12521. for (i = threads.size(); --i >= 0;)
  12522. threads.getUnchecked(i)->signalThreadShouldExit();
  12523. for (i = threads.size(); --i >= 0;)
  12524. threads.getUnchecked(i)->stopThread (500);
  12525. }
  12526. void ThreadPool::addJob (ThreadPoolJob* const job)
  12527. {
  12528. jassert (job != 0);
  12529. jassert (job->pool == 0);
  12530. if (job->pool == 0)
  12531. {
  12532. job->pool = this;
  12533. job->shouldStop = false;
  12534. job->isActive = false;
  12535. {
  12536. const ScopedLock sl (lock);
  12537. jobs.add (job);
  12538. int numRunning = 0;
  12539. for (int i = threads.size(); --i >= 0;)
  12540. if (threads.getUnchecked(i)->isThreadRunning() && ! threads.getUnchecked(i)->threadShouldExit())
  12541. ++numRunning;
  12542. if (numRunning < threads.size())
  12543. {
  12544. bool startedOne = false;
  12545. int n = 1000;
  12546. while (--n >= 0 && ! startedOne)
  12547. {
  12548. for (int i = threads.size(); --i >= 0;)
  12549. {
  12550. if (! threads.getUnchecked(i)->isThreadRunning())
  12551. {
  12552. threads.getUnchecked(i)->startThread (priority);
  12553. startedOne = true;
  12554. break;
  12555. }
  12556. }
  12557. if (! startedOne)
  12558. Thread::sleep (2);
  12559. }
  12560. }
  12561. }
  12562. for (int i = threads.size(); --i >= 0;)
  12563. threads.getUnchecked(i)->notify();
  12564. }
  12565. }
  12566. int ThreadPool::getNumJobs() const
  12567. {
  12568. return jobs.size();
  12569. }
  12570. ThreadPoolJob* ThreadPool::getJob (const int index) const
  12571. {
  12572. const ScopedLock sl (lock);
  12573. return (ThreadPoolJob*) jobs [index];
  12574. }
  12575. bool ThreadPool::contains (const ThreadPoolJob* const job) const
  12576. {
  12577. const ScopedLock sl (lock);
  12578. return jobs.contains (const_cast <ThreadPoolJob*> (job));
  12579. }
  12580. bool ThreadPool::isJobRunning (const ThreadPoolJob* const job) const
  12581. {
  12582. const ScopedLock sl (lock);
  12583. return jobs.contains (const_cast <ThreadPoolJob*> (job)) && job->isActive;
  12584. }
  12585. bool ThreadPool::waitForJobToFinish (const ThreadPoolJob* const job,
  12586. const int timeOutMs) const
  12587. {
  12588. if (job != 0)
  12589. {
  12590. const uint32 start = Time::getMillisecondCounter();
  12591. while (contains (job))
  12592. {
  12593. if (timeOutMs >= 0 && Time::getMillisecondCounter() >= start + timeOutMs)
  12594. return false;
  12595. jobFinishedSignal.wait (2);
  12596. }
  12597. }
  12598. return true;
  12599. }
  12600. bool ThreadPool::removeJob (ThreadPoolJob* const job,
  12601. const bool interruptIfRunning,
  12602. const int timeOutMs)
  12603. {
  12604. if (job != 0)
  12605. {
  12606. lock.enter();
  12607. if (jobs.contains (job))
  12608. {
  12609. if (job->isActive)
  12610. {
  12611. if (interruptIfRunning)
  12612. job->signalJobShouldExit();
  12613. lock.exit();
  12614. return waitForJobToFinish (job, timeOutMs);
  12615. }
  12616. else
  12617. {
  12618. jobs.removeValue (job);
  12619. }
  12620. }
  12621. lock.exit();
  12622. }
  12623. return true;
  12624. }
  12625. bool ThreadPool::removeAllJobs (const bool interruptRunningJobs,
  12626. const int timeOutMs,
  12627. const bool deleteInactiveJobs,
  12628. ThreadPool::JobSelector* selectedJobsToRemove)
  12629. {
  12630. Array <ThreadPoolJob*> jobsToWaitFor;
  12631. {
  12632. const ScopedLock sl (lock);
  12633. for (int i = jobs.size(); --i >= 0;)
  12634. {
  12635. ThreadPoolJob* const job = jobs.getUnchecked(i);
  12636. if (selectedJobsToRemove == 0 || selectedJobsToRemove->isJobSuitable (job))
  12637. {
  12638. if (job->isActive)
  12639. {
  12640. jobsToWaitFor.add (job);
  12641. if (interruptRunningJobs)
  12642. job->signalJobShouldExit();
  12643. }
  12644. else
  12645. {
  12646. jobs.remove (i);
  12647. if (deleteInactiveJobs)
  12648. delete job;
  12649. }
  12650. }
  12651. }
  12652. }
  12653. const uint32 start = Time::getMillisecondCounter();
  12654. for (;;)
  12655. {
  12656. for (int i = jobsToWaitFor.size(); --i >= 0;)
  12657. if (! isJobRunning (jobsToWaitFor.getUnchecked (i)))
  12658. jobsToWaitFor.remove (i);
  12659. if (jobsToWaitFor.size() == 0)
  12660. break;
  12661. if (timeOutMs >= 0 && Time::getMillisecondCounter() >= start + timeOutMs)
  12662. return false;
  12663. jobFinishedSignal.wait (20);
  12664. }
  12665. return true;
  12666. }
  12667. const StringArray ThreadPool::getNamesOfAllJobs (const bool onlyReturnActiveJobs) const
  12668. {
  12669. StringArray s;
  12670. const ScopedLock sl (lock);
  12671. for (int i = 0; i < jobs.size(); ++i)
  12672. {
  12673. const ThreadPoolJob* const job = jobs.getUnchecked(i);
  12674. if (job->isActive || ! onlyReturnActiveJobs)
  12675. s.add (job->getJobName());
  12676. }
  12677. return s;
  12678. }
  12679. bool ThreadPool::setThreadPriorities (const int newPriority)
  12680. {
  12681. bool ok = true;
  12682. if (priority != newPriority)
  12683. {
  12684. priority = newPriority;
  12685. for (int i = threads.size(); --i >= 0;)
  12686. if (! threads.getUnchecked(i)->setPriority (newPriority))
  12687. ok = false;
  12688. }
  12689. return ok;
  12690. }
  12691. bool ThreadPool::runNextJob()
  12692. {
  12693. ThreadPoolJob* job = 0;
  12694. {
  12695. const ScopedLock sl (lock);
  12696. for (int i = 0; i < jobs.size(); ++i)
  12697. {
  12698. job = jobs[i];
  12699. if (job != 0 && ! (job->isActive || job->shouldStop))
  12700. break;
  12701. job = 0;
  12702. }
  12703. if (job != 0)
  12704. job->isActive = true;
  12705. }
  12706. if (job != 0)
  12707. {
  12708. JUCE_TRY
  12709. {
  12710. ThreadPoolJob::JobStatus result = job->runJob();
  12711. lastJobEndTime = Time::getApproximateMillisecondCounter();
  12712. const ScopedLock sl (lock);
  12713. if (jobs.contains (job))
  12714. {
  12715. job->isActive = false;
  12716. if (result != ThreadPoolJob::jobNeedsRunningAgain || job->shouldStop)
  12717. {
  12718. job->pool = 0;
  12719. job->shouldStop = true;
  12720. jobs.removeValue (job);
  12721. if (result == ThreadPoolJob::jobHasFinishedAndShouldBeDeleted)
  12722. delete job;
  12723. jobFinishedSignal.signal();
  12724. }
  12725. else
  12726. {
  12727. // move the job to the end of the queue if it wants another go
  12728. jobs.move (jobs.indexOf (job), -1);
  12729. }
  12730. }
  12731. }
  12732. #if JUCE_CATCH_UNHANDLED_EXCEPTIONS
  12733. catch (...)
  12734. {
  12735. const ScopedLock sl (lock);
  12736. jobs.removeValue (job);
  12737. }
  12738. #endif
  12739. }
  12740. else
  12741. {
  12742. if (threadStopTimeout > 0
  12743. && Time::getApproximateMillisecondCounter() > lastJobEndTime + threadStopTimeout)
  12744. {
  12745. const ScopedLock sl (lock);
  12746. if (jobs.size() == 0)
  12747. for (int i = threads.size(); --i >= 0;)
  12748. threads.getUnchecked(i)->signalThreadShouldExit();
  12749. }
  12750. else
  12751. {
  12752. return false;
  12753. }
  12754. }
  12755. return true;
  12756. }
  12757. END_JUCE_NAMESPACE
  12758. /********* End of inlined file: juce_ThreadPool.cpp *********/
  12759. /********* Start of inlined file: juce_TimeSliceThread.cpp *********/
  12760. BEGIN_JUCE_NAMESPACE
  12761. TimeSliceThread::TimeSliceThread (const String& threadName)
  12762. : Thread (threadName),
  12763. index (0),
  12764. clientBeingCalled (0),
  12765. clientsChanged (false)
  12766. {
  12767. }
  12768. TimeSliceThread::~TimeSliceThread()
  12769. {
  12770. stopThread (2000);
  12771. }
  12772. void TimeSliceThread::addTimeSliceClient (TimeSliceClient* const client)
  12773. {
  12774. const ScopedLock sl (listLock);
  12775. clients.addIfNotAlreadyThere (client);
  12776. clientsChanged = true;
  12777. notify();
  12778. }
  12779. void TimeSliceThread::removeTimeSliceClient (TimeSliceClient* const client)
  12780. {
  12781. const ScopedLock sl1 (listLock);
  12782. clientsChanged = true;
  12783. // if there's a chance we're in the middle of calling this client, we need to
  12784. // also lock the outer lock..
  12785. if (clientBeingCalled == client)
  12786. {
  12787. const ScopedUnlock ul (listLock); // unlock first to get the order right..
  12788. const ScopedLock sl2 (callbackLock);
  12789. const ScopedLock sl3 (listLock);
  12790. clients.removeValue (client);
  12791. }
  12792. else
  12793. {
  12794. clients.removeValue (client);
  12795. }
  12796. }
  12797. int TimeSliceThread::getNumClients() const
  12798. {
  12799. return clients.size();
  12800. }
  12801. TimeSliceClient* TimeSliceThread::getClient (const int i) const
  12802. {
  12803. const ScopedLock sl (listLock);
  12804. return clients [i];
  12805. }
  12806. void TimeSliceThread::run()
  12807. {
  12808. int numCallsSinceBusy = 0;
  12809. while (! threadShouldExit())
  12810. {
  12811. int timeToWait = 500;
  12812. {
  12813. const ScopedLock sl (callbackLock);
  12814. {
  12815. const ScopedLock sl2 (listLock);
  12816. if (clients.size() > 0)
  12817. {
  12818. index = (index + 1) % clients.size();
  12819. clientBeingCalled = clients [index];
  12820. }
  12821. else
  12822. {
  12823. index = 0;
  12824. clientBeingCalled = 0;
  12825. }
  12826. if (clientsChanged)
  12827. {
  12828. clientsChanged = false;
  12829. numCallsSinceBusy = 0;
  12830. }
  12831. }
  12832. if (clientBeingCalled != 0)
  12833. {
  12834. if (clientBeingCalled->useTimeSlice())
  12835. numCallsSinceBusy = 0;
  12836. else
  12837. ++numCallsSinceBusy;
  12838. if (numCallsSinceBusy >= clients.size())
  12839. timeToWait = 500;
  12840. else if (index == 0)
  12841. timeToWait = 1; // throw in an occasional pause, to stop everything locking up
  12842. else
  12843. timeToWait = 0;
  12844. }
  12845. }
  12846. if (timeToWait > 0)
  12847. wait (timeToWait);
  12848. }
  12849. }
  12850. END_JUCE_NAMESPACE
  12851. /********* End of inlined file: juce_TimeSliceThread.cpp *********/
  12852. #if ! JUCE_ONLY_BUILD_CORE_LIBRARY
  12853. /********* Start of inlined file: juce_ValueTree.cpp *********/
  12854. BEGIN_JUCE_NAMESPACE
  12855. class ValueTreeSetPropertyAction : public UndoableAction
  12856. {
  12857. public:
  12858. ValueTreeSetPropertyAction (const ValueTree::SharedObjectPtr& target_, const var::identifier& name_,
  12859. const var& newValue_, const bool isAddingNewProperty_, const bool isDeletingProperty_)
  12860. : target (target_), name (name_), newValue (newValue_),
  12861. isAddingNewProperty (isAddingNewProperty_),
  12862. isDeletingProperty (isDeletingProperty_)
  12863. {
  12864. if (! isAddingNewProperty)
  12865. oldValue = target_->getProperty (name_);
  12866. }
  12867. ~ValueTreeSetPropertyAction() {}
  12868. bool perform()
  12869. {
  12870. jassert (! (isAddingNewProperty && target->hasProperty (name)));
  12871. if (isDeletingProperty)
  12872. target->removeProperty (name, 0);
  12873. else
  12874. target->setProperty (name, newValue, 0);
  12875. return true;
  12876. }
  12877. bool undo()
  12878. {
  12879. if (isAddingNewProperty)
  12880. target->removeProperty (name, 0);
  12881. else
  12882. target->setProperty (name, oldValue, 0);
  12883. return true;
  12884. }
  12885. int getSizeInUnits()
  12886. {
  12887. return (int) sizeof (*this); //xxx should be more accurate
  12888. }
  12889. private:
  12890. const ValueTree::SharedObjectPtr target;
  12891. const var::identifier name;
  12892. const var newValue;
  12893. var oldValue;
  12894. const bool isAddingNewProperty, isDeletingProperty;
  12895. ValueTreeSetPropertyAction (const ValueTreeSetPropertyAction&);
  12896. const ValueTreeSetPropertyAction& operator= (const ValueTreeSetPropertyAction&);
  12897. };
  12898. class ValueTreeChildChangeAction : public UndoableAction
  12899. {
  12900. public:
  12901. ValueTreeChildChangeAction (const ValueTree::SharedObjectPtr& target_, const int childIndex_,
  12902. const ValueTree::SharedObjectPtr& newChild_)
  12903. : target (target_),
  12904. child (newChild_ != 0 ? newChild_ : target_->children [childIndex_]),
  12905. childIndex (childIndex_),
  12906. isDeleting (newChild_ == 0)
  12907. {
  12908. jassert (child != 0);
  12909. }
  12910. ~ValueTreeChildChangeAction() {}
  12911. bool perform()
  12912. {
  12913. if (isDeleting)
  12914. target->removeChild (childIndex, 0);
  12915. else
  12916. target->addChild (child, childIndex, 0);
  12917. return true;
  12918. }
  12919. bool undo()
  12920. {
  12921. if (isDeleting)
  12922. target->addChild (child, childIndex, 0);
  12923. else
  12924. target->removeChild (childIndex, 0);
  12925. return true;
  12926. }
  12927. int getSizeInUnits()
  12928. {
  12929. return (int) sizeof (*this); //xxx should be more accurate
  12930. }
  12931. private:
  12932. const ValueTree::SharedObjectPtr target, child;
  12933. const int childIndex;
  12934. const bool isDeleting;
  12935. ValueTreeChildChangeAction (const ValueTreeChildChangeAction&);
  12936. const ValueTreeChildChangeAction& operator= (const ValueTreeChildChangeAction&);
  12937. };
  12938. ValueTree::SharedObject::SharedObject (const String& type_)
  12939. : type (type_), parent (0)
  12940. {
  12941. }
  12942. ValueTree::SharedObject::SharedObject (const SharedObject& other)
  12943. : type (other.type), parent (0)
  12944. {
  12945. int i;
  12946. for (i = 0; i < other.properties.size(); ++i)
  12947. {
  12948. const Property* const p = other.properties.getUnchecked(i);
  12949. properties.add (new Property (p->name, p->value));
  12950. }
  12951. for (i = 0; i < other.children.size(); ++i)
  12952. children.add (new SharedObject (*other.children.getUnchecked(i)));
  12953. }
  12954. ValueTree::SharedObject::~SharedObject()
  12955. {
  12956. jassert (parent == 0); // this should never happen unless something isn't obeying the ref-counting!
  12957. for (int i = children.size(); --i >= 0;)
  12958. {
  12959. const SharedObjectPtr c (children.getUnchecked(i));
  12960. c->parent = 0;
  12961. children.remove (i);
  12962. c->sendParentChangeMessage();
  12963. }
  12964. }
  12965. ValueTree::SharedObject::Property::Property (const var::identifier& name_, const var& value_)
  12966. : name (name_), value (value_)
  12967. {
  12968. }
  12969. void ValueTree::deliverPropertyChangeMessage (ValueTree& tree, const var::identifier& property)
  12970. {
  12971. for (int i = listeners.size(); --i >= 0;)
  12972. {
  12973. ValueTree::Listener* const l = listeners[i];
  12974. if (l != 0)
  12975. l->valueTreePropertyChanged (tree, property);
  12976. }
  12977. }
  12978. void ValueTree::SharedObject::sendPropertyChangeMessage (ValueTree& tree, const var::identifier& property)
  12979. {
  12980. for (int i = valueTreesWithListeners.size(); --i >= 0;)
  12981. {
  12982. ValueTree* const v = valueTreesWithListeners[i];
  12983. if (v != 0)
  12984. v->deliverPropertyChangeMessage (tree, property);
  12985. }
  12986. }
  12987. void ValueTree::SharedObject::sendPropertyChangeMessage (const var::identifier& property)
  12988. {
  12989. ValueTree tree (this);
  12990. ValueTree::SharedObject* t = this;
  12991. while (t != 0)
  12992. {
  12993. t->sendPropertyChangeMessage (tree, property);
  12994. t = t->parent;
  12995. }
  12996. }
  12997. void ValueTree::deliverChildChangeMessage (ValueTree& tree)
  12998. {
  12999. for (int i = listeners.size(); --i >= 0;)
  13000. {
  13001. ValueTree::Listener* const l = listeners[i];
  13002. if (l != 0)
  13003. l->valueTreeChildrenChanged (tree);
  13004. }
  13005. }
  13006. void ValueTree::SharedObject::sendChildChangeMessage (ValueTree& tree)
  13007. {
  13008. for (int i = valueTreesWithListeners.size(); --i >= 0;)
  13009. {
  13010. ValueTree* const v = valueTreesWithListeners[i];
  13011. if (v != 0)
  13012. v->deliverChildChangeMessage (tree);
  13013. }
  13014. }
  13015. void ValueTree::SharedObject::sendChildChangeMessage()
  13016. {
  13017. ValueTree tree (this);
  13018. ValueTree::SharedObject* t = this;
  13019. while (t != 0)
  13020. {
  13021. t->sendChildChangeMessage (tree);
  13022. t = t->parent;
  13023. }
  13024. }
  13025. void ValueTree::deliverParentChangeMessage (ValueTree& tree)
  13026. {
  13027. for (int i = listeners.size(); --i >= 0;)
  13028. {
  13029. ValueTree::Listener* const l = listeners[i];
  13030. if (l != 0)
  13031. l->valueTreeParentChanged (tree);
  13032. }
  13033. }
  13034. void ValueTree::SharedObject::sendParentChangeMessage()
  13035. {
  13036. ValueTree tree (this);
  13037. int i;
  13038. for (i = children.size(); --i >= 0;)
  13039. {
  13040. SharedObject* const t = children[i];
  13041. if (t != 0)
  13042. t->sendParentChangeMessage();
  13043. }
  13044. for (i = valueTreesWithListeners.size(); --i >= 0;)
  13045. {
  13046. ValueTree* const v = valueTreesWithListeners[i];
  13047. if (v != 0)
  13048. v->deliverParentChangeMessage (tree);
  13049. }
  13050. }
  13051. const var ValueTree::SharedObject::getProperty (const var::identifier& name) const
  13052. {
  13053. for (int i = properties.size(); --i >= 0;)
  13054. {
  13055. const Property* const p = properties.getUnchecked(i);
  13056. if (p->name == name)
  13057. return p->value;
  13058. }
  13059. return var();
  13060. }
  13061. void ValueTree::SharedObject::setProperty (const var::identifier& name, const var& newValue, UndoManager* const undoManager)
  13062. {
  13063. for (int i = properties.size(); --i >= 0;)
  13064. {
  13065. Property* const p = properties.getUnchecked(i);
  13066. if (p->name == name)
  13067. {
  13068. if (p->value != newValue)
  13069. {
  13070. if (undoManager == 0)
  13071. {
  13072. p->value = newValue;
  13073. sendPropertyChangeMessage (name);
  13074. }
  13075. else
  13076. {
  13077. undoManager->perform (new ValueTreeSetPropertyAction (this, name, newValue, false, false));
  13078. }
  13079. }
  13080. return;
  13081. }
  13082. }
  13083. if (undoManager == 0)
  13084. {
  13085. properties.add (new Property (name, newValue));
  13086. sendPropertyChangeMessage (name);
  13087. }
  13088. else
  13089. {
  13090. undoManager->perform (new ValueTreeSetPropertyAction (this, name, newValue, true, false));
  13091. }
  13092. }
  13093. bool ValueTree::SharedObject::hasProperty (const var::identifier& name) const
  13094. {
  13095. for (int i = properties.size(); --i >= 0;)
  13096. if (properties.getUnchecked(i)->name == name)
  13097. return true;
  13098. return false;
  13099. }
  13100. void ValueTree::SharedObject::removeProperty (const var::identifier& name, UndoManager* const undoManager)
  13101. {
  13102. for (int i = properties.size(); --i >= 0;)
  13103. {
  13104. Property* const p = properties.getUnchecked(i);
  13105. if (p->name == name)
  13106. {
  13107. if (undoManager == 0)
  13108. {
  13109. properties.remove (i);
  13110. sendPropertyChangeMessage (name);
  13111. }
  13112. else
  13113. {
  13114. undoManager->perform (new ValueTreeSetPropertyAction (this, name, var(), false, true));
  13115. }
  13116. break;
  13117. }
  13118. }
  13119. }
  13120. void ValueTree::SharedObject::removeAllProperties (UndoManager* const undoManager)
  13121. {
  13122. if (undoManager == 0)
  13123. {
  13124. while (properties.size() > 0)
  13125. {
  13126. const var::identifier name (properties.getLast()->name);
  13127. properties.removeLast();
  13128. sendPropertyChangeMessage (name);
  13129. }
  13130. }
  13131. else
  13132. {
  13133. for (int i = properties.size(); --i >= 0;)
  13134. undoManager->perform (new ValueTreeSetPropertyAction (this, properties.getUnchecked(i)->name, var(), false, true));
  13135. }
  13136. }
  13137. ValueTree ValueTree::SharedObject::getChildWithName (const String& typeToMatch) const
  13138. {
  13139. for (int i = 0; i < children.size(); ++i)
  13140. if (children.getUnchecked(i)->type == typeToMatch)
  13141. return (SharedObject*) children.getUnchecked(i);
  13142. return (SharedObject*) 0;
  13143. }
  13144. ValueTree ValueTree::SharedObject::getChildWithProperty (const var::identifier& propertyName, const var& propertyValue) const
  13145. {
  13146. for (int i = 0; i < children.size(); ++i)
  13147. if (children.getUnchecked(i)->getProperty (propertyName) == propertyValue)
  13148. return (SharedObject*) children.getUnchecked(i);
  13149. return (SharedObject*) 0;
  13150. }
  13151. bool ValueTree::SharedObject::isAChildOf (const SharedObject* const possibleParent) const
  13152. {
  13153. const SharedObject* p = parent;
  13154. while (p != 0)
  13155. {
  13156. if (p == possibleParent)
  13157. return true;
  13158. p = p->parent;
  13159. }
  13160. return false;
  13161. }
  13162. void ValueTree::SharedObject::addChild (SharedObject* child, int index, UndoManager* const undoManager)
  13163. {
  13164. if (child != 0 && child->parent != this)
  13165. {
  13166. if (child != this && ! isAChildOf (child))
  13167. {
  13168. // You should always make sure that a child is removed from its previous parent before
  13169. // adding it somewhere else - otherwise, it's ambiguous as to whether a different
  13170. // undomanager should be used when removing it from its current parent..
  13171. jassert (child->parent == 0);
  13172. if (child->parent != 0)
  13173. {
  13174. jassert (child->parent->children.indexOf (child) >= 0);
  13175. child->parent->removeChild (child->parent->children.indexOf (child), undoManager);
  13176. }
  13177. if (undoManager == 0)
  13178. {
  13179. children.insert (index, child);
  13180. child->parent = this;
  13181. sendChildChangeMessage();
  13182. child->sendParentChangeMessage();
  13183. }
  13184. else
  13185. {
  13186. undoManager->perform (new ValueTreeChildChangeAction (this, index, child));
  13187. }
  13188. }
  13189. else
  13190. {
  13191. // You're attempting to create a recursive loop! A node
  13192. // can't be a child of one of its own children!
  13193. jassertfalse
  13194. }
  13195. }
  13196. }
  13197. void ValueTree::SharedObject::removeChild (const int childIndex, UndoManager* const undoManager)
  13198. {
  13199. const SharedObjectPtr child (children [childIndex]);
  13200. if (child != 0)
  13201. {
  13202. if (undoManager == 0)
  13203. {
  13204. children.remove (childIndex);
  13205. child->parent = 0;
  13206. sendChildChangeMessage();
  13207. child->sendParentChangeMessage();
  13208. }
  13209. else
  13210. {
  13211. undoManager->perform (new ValueTreeChildChangeAction (this, childIndex, 0));
  13212. }
  13213. }
  13214. }
  13215. void ValueTree::SharedObject::removeAllChildren (UndoManager* const undoManager)
  13216. {
  13217. while (children.size() > 0)
  13218. removeChild (children.size() - 1, undoManager);
  13219. }
  13220. ValueTree::ValueTree (const String& type_)
  13221. : object (new ValueTree::SharedObject (type_))
  13222. {
  13223. jassert (type_.isNotEmpty()); // All objects should be given a sensible type name!
  13224. }
  13225. ValueTree::ValueTree (SharedObject* const object_)
  13226. : object (object_)
  13227. {
  13228. }
  13229. ValueTree::ValueTree (const ValueTree& other)
  13230. : object (other.object)
  13231. {
  13232. }
  13233. const ValueTree& ValueTree::operator= (const ValueTree& other)
  13234. {
  13235. if (listeners.size() > 0)
  13236. {
  13237. if (object != 0)
  13238. object->valueTreesWithListeners.removeValue (this);
  13239. if (other.object != 0)
  13240. other.object->valueTreesWithListeners.add (this);
  13241. }
  13242. object = other.object;
  13243. return *this;
  13244. }
  13245. ValueTree::~ValueTree()
  13246. {
  13247. if (listeners.size() > 0 && object != 0)
  13248. object->valueTreesWithListeners.removeValue (this);
  13249. }
  13250. bool ValueTree::operator== (const ValueTree& other) const
  13251. {
  13252. return object == other.object;
  13253. }
  13254. bool ValueTree::operator!= (const ValueTree& other) const
  13255. {
  13256. return object != other.object;
  13257. }
  13258. ValueTree ValueTree::createCopy() const
  13259. {
  13260. return ValueTree (object != 0 ? new SharedObject (*object) : 0);
  13261. }
  13262. bool ValueTree::hasType (const String& typeName) const
  13263. {
  13264. return object != 0 && object->type == typeName;
  13265. }
  13266. const String ValueTree::getType() const
  13267. {
  13268. return object != 0 ? object->type : String::empty;
  13269. }
  13270. ValueTree ValueTree::getParent() const
  13271. {
  13272. return object != 0 ? ValueTree (object->parent) : ValueTree ((SharedObject*) 0);
  13273. }
  13274. const var ValueTree::operator[] (const var::identifier& name) const
  13275. {
  13276. return object == 0 ? var() : object->getProperty (name);
  13277. }
  13278. const var ValueTree::getProperty (const var::identifier& name) const
  13279. {
  13280. return object == 0 ? var() : object->getProperty (name);
  13281. }
  13282. void ValueTree::setProperty (const var::identifier& name, const var& newValue, UndoManager* const undoManager)
  13283. {
  13284. jassert (name.name.isNotEmpty());
  13285. if (object != 0 && name.name.isNotEmpty())
  13286. object->setProperty (name, newValue, undoManager);
  13287. }
  13288. bool ValueTree::hasProperty (const var::identifier& name) const
  13289. {
  13290. return object != 0 && object->hasProperty (name);
  13291. }
  13292. void ValueTree::removeProperty (const var::identifier& name, UndoManager* const undoManager)
  13293. {
  13294. if (object != 0)
  13295. object->removeProperty (name, undoManager);
  13296. }
  13297. void ValueTree::removeAllProperties (UndoManager* const undoManager)
  13298. {
  13299. if (object != 0)
  13300. object->removeAllProperties (undoManager);
  13301. }
  13302. int ValueTree::getNumProperties() const
  13303. {
  13304. return object == 0 ? 0 : object->properties.size();
  13305. }
  13306. const var::identifier ValueTree::getPropertyName (int index) const
  13307. {
  13308. const SharedObject::Property* const p = (object == 0) ? 0 : object->properties [index];
  13309. return p != 0 ? p->name : var::identifier (String::empty);
  13310. }
  13311. class ValueTreePropertyValueSource : public Value::ValueSource,
  13312. public ValueTree::Listener
  13313. {
  13314. public:
  13315. ValueTreePropertyValueSource (const ValueTree& tree_,
  13316. const var::identifier& property_,
  13317. UndoManager* const undoManager_)
  13318. : tree (tree_),
  13319. property (property_),
  13320. undoManager (undoManager_)
  13321. {
  13322. tree.addListener (this);
  13323. }
  13324. ~ValueTreePropertyValueSource()
  13325. {
  13326. tree.removeListener (this);
  13327. }
  13328. const var getValue() const
  13329. {
  13330. return tree [property];
  13331. }
  13332. void setValue (const var& newValue)
  13333. {
  13334. tree.setProperty (property, newValue, undoManager);
  13335. }
  13336. void valueTreePropertyChanged (ValueTree& treeWhosePropertyHasChanged, const var::identifier& changedProperty)
  13337. {
  13338. if (tree == treeWhosePropertyHasChanged && property == changedProperty)
  13339. sendChangeMessage (false);
  13340. }
  13341. void valueTreeChildrenChanged (ValueTree&) {}
  13342. void valueTreeParentChanged (ValueTree&) {}
  13343. private:
  13344. ValueTree tree;
  13345. const var::identifier property;
  13346. UndoManager* const undoManager;
  13347. const ValueTreePropertyValueSource& operator= (const ValueTreePropertyValueSource&);
  13348. };
  13349. Value ValueTree::getPropertyAsValue (const var::identifier& name, UndoManager* const undoManager) const
  13350. {
  13351. return Value (new ValueTreePropertyValueSource (*this, name, undoManager));
  13352. }
  13353. int ValueTree::getNumChildren() const
  13354. {
  13355. return object == 0 ? 0 : object->children.size();
  13356. }
  13357. ValueTree ValueTree::getChild (int index) const
  13358. {
  13359. return object != 0 ? (SharedObject*) object->children [index] : ValueTree ((SharedObject*) 0);
  13360. }
  13361. ValueTree ValueTree::getChildWithName (const String& type) const
  13362. {
  13363. return object != 0 ? object->getChildWithName (type) : ValueTree ((SharedObject*) 0);
  13364. }
  13365. ValueTree ValueTree::getChildWithProperty (const var::identifier& propertyName, const var& propertyValue) const
  13366. {
  13367. return object != 0 ? object->getChildWithProperty (propertyName, propertyValue) : ValueTree ((SharedObject*) 0);
  13368. }
  13369. bool ValueTree::isAChildOf (const ValueTree& possibleParent) const
  13370. {
  13371. return object != 0 && object->isAChildOf (possibleParent.object);
  13372. }
  13373. void ValueTree::addChild (ValueTree child, int index, UndoManager* const undoManager)
  13374. {
  13375. if (object != 0)
  13376. object->addChild (child.object, index, undoManager);
  13377. }
  13378. void ValueTree::removeChild (const int childIndex, UndoManager* const undoManager)
  13379. {
  13380. if (object != 0)
  13381. object->removeChild (childIndex, undoManager);
  13382. }
  13383. void ValueTree::removeChild (ValueTree& child, UndoManager* const undoManager)
  13384. {
  13385. if (object != 0)
  13386. object->removeChild (object->children.indexOf (child.object), undoManager);
  13387. }
  13388. void ValueTree::removeAllChildren (UndoManager* const undoManager)
  13389. {
  13390. if (object != 0)
  13391. object->removeAllChildren (undoManager);
  13392. }
  13393. void ValueTree::addListener (Listener* listener)
  13394. {
  13395. if (listener != 0)
  13396. {
  13397. if (listeners.size() == 0 && object != 0)
  13398. object->valueTreesWithListeners.add (this);
  13399. listeners.add (listener);
  13400. }
  13401. }
  13402. void ValueTree::removeListener (Listener* listener)
  13403. {
  13404. listeners.removeValue (listener);
  13405. if (listeners.size() == 0 && object != 0)
  13406. object->valueTreesWithListeners.removeValue (this);
  13407. }
  13408. XmlElement* ValueTree::SharedObject::createXml() const
  13409. {
  13410. XmlElement* xml = new XmlElement (type);
  13411. int i;
  13412. for (i = 0; i < properties.size(); ++i)
  13413. {
  13414. const Property* const p = properties.getUnchecked(i);
  13415. jassert (! p->value.isObject()); // DynamicObjects can't be stored as XML!
  13416. xml->setAttribute (p->name.name, p->value.toString());
  13417. }
  13418. for (i = 0; i < children.size(); ++i)
  13419. xml->addChildElement (children.getUnchecked(i)->createXml());
  13420. return xml;
  13421. }
  13422. XmlElement* ValueTree::createXml() const
  13423. {
  13424. return object != 0 ? object->createXml() : 0;
  13425. }
  13426. ValueTree ValueTree::fromXml (const XmlElement& xml)
  13427. {
  13428. ValueTree v (xml.getTagName());
  13429. const int numAtts = xml.getNumAttributes(); // xxx inefficient - should write an att iterator..
  13430. for (int i = 0; i < numAtts; ++i)
  13431. v.setProperty (xml.getAttributeName (i), var (xml.getAttributeValue (i)), 0);
  13432. forEachXmlChildElement (xml, e)
  13433. {
  13434. v.addChild (fromXml (*e), -1, 0);
  13435. }
  13436. return v;
  13437. }
  13438. void ValueTree::writeToStream (OutputStream& output)
  13439. {
  13440. output.writeString (getType());
  13441. const int numProps = getNumProperties();
  13442. output.writeCompressedInt (numProps);
  13443. int i;
  13444. for (i = 0; i < numProps; ++i)
  13445. {
  13446. const var::identifier name (getPropertyName(i));
  13447. output.writeString (name.name);
  13448. getProperty(name).writeToStream (output);
  13449. }
  13450. const int numChildren = getNumChildren();
  13451. output.writeCompressedInt (numChildren);
  13452. for (i = 0; i < numChildren; ++i)
  13453. getChild (i).writeToStream (output);
  13454. }
  13455. ValueTree ValueTree::readFromStream (InputStream& input)
  13456. {
  13457. String type (input.readString());
  13458. if (type.isEmpty())
  13459. return ValueTree ((SharedObject*) 0);
  13460. ValueTree v (type);
  13461. const int numProps = input.readCompressedInt();
  13462. if (numProps < 0)
  13463. {
  13464. jassertfalse // trying to read corrupted data!
  13465. return v;
  13466. }
  13467. int i;
  13468. for (i = 0; i < numProps; ++i)
  13469. {
  13470. const String name (input.readString());
  13471. jassert (name.isNotEmpty());
  13472. const var value (var::readFromStream (input));
  13473. v.setProperty (name, value, 0);
  13474. }
  13475. const int numChildren = input.readCompressedInt();
  13476. for (i = 0; i < numChildren; ++i)
  13477. v.addChild (readFromStream (input), -1, 0);
  13478. return v;
  13479. }
  13480. END_JUCE_NAMESPACE
  13481. /********* End of inlined file: juce_ValueTree.cpp *********/
  13482. /********* Start of inlined file: juce_Value.cpp *********/
  13483. BEGIN_JUCE_NAMESPACE
  13484. Value::ValueSource::ValueSource()
  13485. {
  13486. }
  13487. Value::ValueSource::~ValueSource()
  13488. {
  13489. }
  13490. void Value::ValueSource::sendChangeMessage (const bool synchronous)
  13491. {
  13492. if (synchronous)
  13493. {
  13494. for (int i = valuesWithListeners.size(); --i >= 0;)
  13495. {
  13496. Value* const v = valuesWithListeners[i];
  13497. if (v != 0)
  13498. v->callListeners();
  13499. }
  13500. }
  13501. else
  13502. {
  13503. triggerAsyncUpdate();
  13504. }
  13505. }
  13506. void Value::ValueSource::handleAsyncUpdate()
  13507. {
  13508. sendChangeMessage (true);
  13509. }
  13510. class SimpleValueSource : public Value::ValueSource
  13511. {
  13512. public:
  13513. SimpleValueSource()
  13514. {
  13515. }
  13516. SimpleValueSource (const var& initialValue)
  13517. : value (initialValue)
  13518. {
  13519. }
  13520. ~SimpleValueSource()
  13521. {
  13522. }
  13523. const var getValue() const
  13524. {
  13525. return value;
  13526. }
  13527. void setValue (const var& newValue)
  13528. {
  13529. if (newValue != value)
  13530. {
  13531. value = newValue;
  13532. sendChangeMessage (false);
  13533. }
  13534. }
  13535. private:
  13536. var value;
  13537. SimpleValueSource (const SimpleValueSource&);
  13538. const SimpleValueSource& operator= (const SimpleValueSource&);
  13539. };
  13540. Value::Value()
  13541. : value (new SimpleValueSource())
  13542. {
  13543. }
  13544. Value::Value (ValueSource* const value_)
  13545. : value (value_)
  13546. {
  13547. jassert (value_ != 0);
  13548. }
  13549. Value::Value (const var& initialValue)
  13550. : value (new SimpleValueSource (initialValue))
  13551. {
  13552. }
  13553. Value::Value (const Value& other)
  13554. : value (other.value)
  13555. {
  13556. }
  13557. const Value& Value::operator= (const Value& other)
  13558. {
  13559. value = other.value;
  13560. return *this;
  13561. }
  13562. Value::~Value()
  13563. {
  13564. if (listeners.size() > 0)
  13565. value->valuesWithListeners.removeValue (this);
  13566. }
  13567. const var Value::getValue() const
  13568. {
  13569. return value->getValue();
  13570. }
  13571. void Value::setValue (const var& newValue)
  13572. {
  13573. value->setValue (newValue);
  13574. }
  13575. const String Value::toString() const
  13576. {
  13577. return value->getValue().toString();
  13578. }
  13579. const Value& Value::operator= (const var& newValue)
  13580. {
  13581. value->setValue (newValue);
  13582. return *this;
  13583. }
  13584. void Value::referTo (const Value& valueToReferTo)
  13585. {
  13586. if (valueToReferTo.value != value)
  13587. {
  13588. if (listeners.size() > 0)
  13589. {
  13590. value->valuesWithListeners.removeValue (this);
  13591. valueToReferTo.value->valuesWithListeners.add (this);
  13592. }
  13593. value = valueToReferTo.value;
  13594. callListeners();
  13595. }
  13596. }
  13597. bool Value::refersToSameSourceAs (const Value& other) const
  13598. {
  13599. return value == other.value;
  13600. }
  13601. bool Value::operator== (const Value& other) const
  13602. {
  13603. return value == other.value || value->getValue() == other.getValue();
  13604. }
  13605. bool Value::operator!= (const Value& other) const
  13606. {
  13607. return value != other.value && value->getValue() != other.getValue();
  13608. }
  13609. void Value::addListener (Listener* const listener)
  13610. {
  13611. if (listener != 0)
  13612. {
  13613. if (listeners.size() == 0)
  13614. value->valuesWithListeners.add (this);
  13615. listeners.add (listener);
  13616. }
  13617. }
  13618. void Value::removeListener (Listener* const listener)
  13619. {
  13620. listeners.removeValue (listener);
  13621. if (listeners.size() == 0)
  13622. value->valuesWithListeners.removeValue (this);
  13623. }
  13624. void Value::callListeners()
  13625. {
  13626. Value valueCopy (*this); // Use a copy in case this object gets deleted by a callback
  13627. for (int i = listeners.size(); --i >= 0;)
  13628. {
  13629. Listener* const l = listeners[i];
  13630. if (l != 0)
  13631. l->valueChanged (valueCopy);
  13632. }
  13633. }
  13634. END_JUCE_NAMESPACE
  13635. /********* End of inlined file: juce_Value.cpp *********/
  13636. /********* Start of inlined file: juce_Application.cpp *********/
  13637. #if JUCE_MSVC
  13638. #pragma warning (push)
  13639. #pragma warning (disable: 4245 4514 4100)
  13640. #include <crtdbg.h>
  13641. #pragma warning (pop)
  13642. #endif
  13643. BEGIN_JUCE_NAMESPACE
  13644. void juce_setCurrentThreadName (const String& name);
  13645. static JUCEApplication* appInstance = 0;
  13646. JUCEApplication::JUCEApplication()
  13647. : appReturnValue (0),
  13648. stillInitialising (true),
  13649. appLock (0)
  13650. {
  13651. }
  13652. JUCEApplication::~JUCEApplication()
  13653. {
  13654. if (appLock != 0)
  13655. {
  13656. appLock->exit();
  13657. delete appLock;
  13658. }
  13659. }
  13660. JUCEApplication* JUCEApplication::getInstance() throw()
  13661. {
  13662. return appInstance;
  13663. }
  13664. bool JUCEApplication::isInitialising() const throw()
  13665. {
  13666. return stillInitialising;
  13667. }
  13668. const String JUCEApplication::getApplicationVersion()
  13669. {
  13670. return String::empty;
  13671. }
  13672. bool JUCEApplication::moreThanOneInstanceAllowed()
  13673. {
  13674. return true;
  13675. }
  13676. void JUCEApplication::anotherInstanceStarted (const String&)
  13677. {
  13678. }
  13679. void JUCEApplication::systemRequestedQuit()
  13680. {
  13681. quit();
  13682. }
  13683. void JUCEApplication::quit()
  13684. {
  13685. MessageManager::getInstance()->stopDispatchLoop();
  13686. }
  13687. void JUCEApplication::setApplicationReturnValue (const int newReturnValue) throw()
  13688. {
  13689. appReturnValue = newReturnValue;
  13690. }
  13691. void JUCEApplication::unhandledException (const std::exception*,
  13692. const String&,
  13693. const int)
  13694. {
  13695. jassertfalse
  13696. }
  13697. void JUCEApplication::sendUnhandledException (const std::exception* const e,
  13698. const char* const sourceFile,
  13699. const int lineNumber)
  13700. {
  13701. if (appInstance != 0)
  13702. appInstance->unhandledException (e, sourceFile, lineNumber);
  13703. }
  13704. ApplicationCommandTarget* JUCEApplication::getNextCommandTarget()
  13705. {
  13706. return 0;
  13707. }
  13708. void JUCEApplication::getAllCommands (Array <CommandID>& commands)
  13709. {
  13710. commands.add (StandardApplicationCommandIDs::quit);
  13711. }
  13712. void JUCEApplication::getCommandInfo (const CommandID commandID, ApplicationCommandInfo& result)
  13713. {
  13714. if (commandID == StandardApplicationCommandIDs::quit)
  13715. {
  13716. result.setInfo (TRANS("Quit"),
  13717. TRANS("Quits the application"),
  13718. "Application",
  13719. 0);
  13720. result.defaultKeypresses.add (KeyPress (T('q'), ModifierKeys::commandModifier, 0));
  13721. }
  13722. }
  13723. bool JUCEApplication::perform (const InvocationInfo& info)
  13724. {
  13725. if (info.commandID == StandardApplicationCommandIDs::quit)
  13726. {
  13727. systemRequestedQuit();
  13728. return true;
  13729. }
  13730. return false;
  13731. }
  13732. int JUCEApplication::main (String& commandLine, JUCEApplication* const app)
  13733. {
  13734. if (! app->initialiseApp (commandLine))
  13735. return 0;
  13736. // now loop until a quit message is received..
  13737. JUCE_TRY
  13738. {
  13739. MessageManager::getInstance()->runDispatchLoop();
  13740. }
  13741. #if JUCE_CATCH_UNHANDLED_EXCEPTIONS
  13742. catch (const std::exception& e)
  13743. {
  13744. app->unhandledException (&e, __FILE__, __LINE__);
  13745. }
  13746. catch (...)
  13747. {
  13748. app->unhandledException (0, __FILE__, __LINE__);
  13749. }
  13750. #endif
  13751. return shutdownAppAndClearUp();
  13752. }
  13753. bool JUCEApplication::initialiseApp (String& commandLine)
  13754. {
  13755. jassert (appInstance == 0);
  13756. appInstance = this;
  13757. commandLineParameters = commandLine.trim();
  13758. commandLine = String::empty;
  13759. initialiseJuce_GUI();
  13760. #if ! JUCE_IPHONE
  13761. jassert (appLock == 0); // initialiseApp must only be called once!
  13762. if (! moreThanOneInstanceAllowed())
  13763. {
  13764. appLock = new InterProcessLock ("juceAppLock_" + getApplicationName());
  13765. if (! appLock->enter(0))
  13766. {
  13767. MessageManager::broadcastMessage (getApplicationName() + "/" + commandLineParameters);
  13768. delete appInstance;
  13769. appInstance = 0;
  13770. DBG ("Another instance is running - quitting...");
  13771. return false;
  13772. }
  13773. }
  13774. #endif
  13775. // let the app do its setting-up..
  13776. initialise (commandLineParameters);
  13777. // register for broadcast new app messages
  13778. MessageManager::getInstance()->registerBroadcastListener (this);
  13779. stillInitialising = false;
  13780. return true;
  13781. }
  13782. int JUCEApplication::shutdownAppAndClearUp()
  13783. {
  13784. jassert (appInstance != 0);
  13785. JUCEApplication* const app = appInstance;
  13786. int returnValue = 0;
  13787. MessageManager::getInstance()->deregisterBroadcastListener (app);
  13788. static bool reentrancyCheck = false;
  13789. if (! reentrancyCheck)
  13790. {
  13791. reentrancyCheck = true;
  13792. JUCE_TRY
  13793. {
  13794. // give the app a chance to clean up..
  13795. app->shutdown();
  13796. }
  13797. #if JUCE_CATCH_UNHANDLED_EXCEPTIONS
  13798. catch (const std::exception& e)
  13799. {
  13800. app->unhandledException (&e, __FILE__, __LINE__);
  13801. }
  13802. catch (...)
  13803. {
  13804. app->unhandledException (0, __FILE__, __LINE__);
  13805. }
  13806. #endif
  13807. JUCE_TRY
  13808. {
  13809. shutdownJuce_GUI();
  13810. returnValue = app->getApplicationReturnValue();
  13811. appInstance = 0;
  13812. delete app;
  13813. }
  13814. JUCE_CATCH_ALL_ASSERT
  13815. reentrancyCheck = false;
  13816. }
  13817. return returnValue;
  13818. }
  13819. #if JUCE_IPHONE
  13820. extern int juce_IPhoneMain (int argc, char* argv[], JUCEApplication* app);
  13821. #endif
  13822. #if ! JUCE_WINDOWS
  13823. extern const char* juce_Argv0;
  13824. #endif
  13825. int JUCEApplication::main (int argc, char* argv[],
  13826. JUCEApplication* const newApp)
  13827. {
  13828. #if ! JUCE_WINDOWS
  13829. juce_Argv0 = argv[0];
  13830. #endif
  13831. #if JUCE_IPHONE
  13832. const ScopedAutoReleasePool pool;
  13833. return juce_IPhoneMain (argc, argv, newApp);
  13834. #else
  13835. #if JUCE_MAC
  13836. const ScopedAutoReleasePool pool;
  13837. #endif
  13838. String cmd;
  13839. for (int i = 1; i < argc; ++i)
  13840. cmd << String::fromUTF8 ((const uint8*) argv[i]) << T(' ');
  13841. return JUCEApplication::main (cmd, newApp);
  13842. #endif
  13843. }
  13844. void JUCEApplication::actionListenerCallback (const String& message)
  13845. {
  13846. if (message.startsWith (getApplicationName() + "/"))
  13847. anotherInstanceStarted (message.substring (getApplicationName().length() + 1));
  13848. }
  13849. static bool juceInitialisedGUI = false;
  13850. void JUCE_PUBLIC_FUNCTION initialiseJuce_GUI()
  13851. {
  13852. if (! juceInitialisedGUI)
  13853. {
  13854. #if JUCE_MAC || JUCE_IPHONE
  13855. const ScopedAutoReleasePool pool;
  13856. #endif
  13857. juceInitialisedGUI = true;
  13858. initialiseJuce_NonGUI();
  13859. MessageManager::getInstance();
  13860. LookAndFeel::setDefaultLookAndFeel (0);
  13861. juce_setCurrentThreadName ("Juce Message Thread");
  13862. #if JUCE_WINDOWS && JUCE_DEBUG
  13863. // This section is just for catching people who mess up their project settings and
  13864. // turn RTTI off..
  13865. try
  13866. {
  13867. TextButton tb (String::empty);
  13868. Component* c = &tb;
  13869. // Got an exception here? Then TURN ON RTTI in your compiler settings!!
  13870. c = dynamic_cast <Button*> (c);
  13871. }
  13872. catch (...)
  13873. {
  13874. // Ended up here? If so, TURN ON RTTI in your compiler settings!! And if you
  13875. // got as far as this catch statement, then why haven't you got exception catching
  13876. // turned on in the debugger???
  13877. jassertfalse
  13878. }
  13879. #endif
  13880. }
  13881. }
  13882. void JUCE_PUBLIC_FUNCTION shutdownJuce_GUI()
  13883. {
  13884. if (juceInitialisedGUI)
  13885. {
  13886. #if JUCE_MAC
  13887. const ScopedAutoReleasePool pool;
  13888. #endif
  13889. {
  13890. DeletedAtShutdown::deleteAll();
  13891. LookAndFeel::clearDefaultLookAndFeel();
  13892. }
  13893. delete MessageManager::getInstance();
  13894. shutdownJuce_NonGUI();
  13895. juceInitialisedGUI = false;
  13896. }
  13897. }
  13898. END_JUCE_NAMESPACE
  13899. /********* End of inlined file: juce_Application.cpp *********/
  13900. /********* Start of inlined file: juce_ApplicationCommandInfo.cpp *********/
  13901. BEGIN_JUCE_NAMESPACE
  13902. ApplicationCommandInfo::ApplicationCommandInfo (const CommandID commandID_) throw()
  13903. : commandID (commandID_),
  13904. flags (0)
  13905. {
  13906. }
  13907. void ApplicationCommandInfo::setInfo (const String& shortName_,
  13908. const String& description_,
  13909. const String& categoryName_,
  13910. const int flags_) throw()
  13911. {
  13912. shortName = shortName_;
  13913. description = description_;
  13914. categoryName = categoryName_;
  13915. flags = flags_;
  13916. }
  13917. void ApplicationCommandInfo::setActive (const bool b) throw()
  13918. {
  13919. if (b)
  13920. flags &= ~isDisabled;
  13921. else
  13922. flags |= isDisabled;
  13923. }
  13924. void ApplicationCommandInfo::setTicked (const bool b) throw()
  13925. {
  13926. if (b)
  13927. flags |= isTicked;
  13928. else
  13929. flags &= ~isTicked;
  13930. }
  13931. void ApplicationCommandInfo::addDefaultKeypress (const int keyCode, const ModifierKeys& modifiers) throw()
  13932. {
  13933. defaultKeypresses.add (KeyPress (keyCode, modifiers, 0));
  13934. }
  13935. END_JUCE_NAMESPACE
  13936. /********* End of inlined file: juce_ApplicationCommandInfo.cpp *********/
  13937. /********* Start of inlined file: juce_ApplicationCommandManager.cpp *********/
  13938. BEGIN_JUCE_NAMESPACE
  13939. ApplicationCommandManager::ApplicationCommandManager()
  13940. : firstTarget (0)
  13941. {
  13942. keyMappings = new KeyPressMappingSet (this);
  13943. Desktop::getInstance().addFocusChangeListener (this);
  13944. }
  13945. ApplicationCommandManager::~ApplicationCommandManager()
  13946. {
  13947. Desktop::getInstance().removeFocusChangeListener (this);
  13948. keyMappings = 0;
  13949. }
  13950. void ApplicationCommandManager::clearCommands()
  13951. {
  13952. commands.clear();
  13953. keyMappings->clearAllKeyPresses();
  13954. triggerAsyncUpdate();
  13955. }
  13956. void ApplicationCommandManager::registerCommand (const ApplicationCommandInfo& newCommand)
  13957. {
  13958. // zero isn't a valid command ID!
  13959. jassert (newCommand.commandID != 0);
  13960. // the name isn't optional!
  13961. jassert (newCommand.shortName.isNotEmpty());
  13962. if (getCommandForID (newCommand.commandID) == 0)
  13963. {
  13964. ApplicationCommandInfo* const newInfo = new ApplicationCommandInfo (newCommand);
  13965. newInfo->flags &= ~ApplicationCommandInfo::isTicked;
  13966. commands.add (newInfo);
  13967. keyMappings->resetToDefaultMapping (newCommand.commandID);
  13968. triggerAsyncUpdate();
  13969. }
  13970. else
  13971. {
  13972. // trying to re-register the same command with different parameters?
  13973. jassert (newCommand.shortName == getCommandForID (newCommand.commandID)->shortName
  13974. && (newCommand.description == getCommandForID (newCommand.commandID)->description || newCommand.description.isEmpty())
  13975. && newCommand.categoryName == getCommandForID (newCommand.commandID)->categoryName
  13976. && newCommand.defaultKeypresses == getCommandForID (newCommand.commandID)->defaultKeypresses
  13977. && (newCommand.flags & (ApplicationCommandInfo::wantsKeyUpDownCallbacks | ApplicationCommandInfo::hiddenFromKeyEditor | ApplicationCommandInfo::readOnlyInKeyEditor))
  13978. == (getCommandForID (newCommand.commandID)->flags & (ApplicationCommandInfo::wantsKeyUpDownCallbacks | ApplicationCommandInfo::hiddenFromKeyEditor | ApplicationCommandInfo::readOnlyInKeyEditor)));
  13979. }
  13980. }
  13981. void ApplicationCommandManager::registerAllCommandsForTarget (ApplicationCommandTarget* target)
  13982. {
  13983. if (target != 0)
  13984. {
  13985. Array <CommandID> commandIDs;
  13986. target->getAllCommands (commandIDs);
  13987. for (int i = 0; i < commandIDs.size(); ++i)
  13988. {
  13989. ApplicationCommandInfo info (commandIDs.getUnchecked(i));
  13990. target->getCommandInfo (info.commandID, info);
  13991. registerCommand (info);
  13992. }
  13993. }
  13994. }
  13995. void ApplicationCommandManager::removeCommand (const CommandID commandID)
  13996. {
  13997. for (int i = commands.size(); --i >= 0;)
  13998. {
  13999. if (commands.getUnchecked (i)->commandID == commandID)
  14000. {
  14001. commands.remove (i);
  14002. triggerAsyncUpdate();
  14003. const Array <KeyPress> keys (keyMappings->getKeyPressesAssignedToCommand (commandID));
  14004. for (int j = keys.size(); --j >= 0;)
  14005. keyMappings->removeKeyPress (keys.getReference (j));
  14006. }
  14007. }
  14008. }
  14009. void ApplicationCommandManager::commandStatusChanged()
  14010. {
  14011. triggerAsyncUpdate();
  14012. }
  14013. const ApplicationCommandInfo* ApplicationCommandManager::getCommandForID (const CommandID commandID) const throw()
  14014. {
  14015. for (int i = commands.size(); --i >= 0;)
  14016. if (commands.getUnchecked(i)->commandID == commandID)
  14017. return commands.getUnchecked(i);
  14018. return 0;
  14019. }
  14020. const String ApplicationCommandManager::getNameOfCommand (const CommandID commandID) const throw()
  14021. {
  14022. const ApplicationCommandInfo* const ci = getCommandForID (commandID);
  14023. return (ci != 0) ? ci->shortName : String::empty;
  14024. }
  14025. const String ApplicationCommandManager::getDescriptionOfCommand (const CommandID commandID) const throw()
  14026. {
  14027. const ApplicationCommandInfo* const ci = getCommandForID (commandID);
  14028. return (ci != 0) ? (ci->description.isNotEmpty() ? ci->description : ci->shortName)
  14029. : String::empty;
  14030. }
  14031. const StringArray ApplicationCommandManager::getCommandCategories() const throw()
  14032. {
  14033. StringArray s;
  14034. for (int i = 0; i < commands.size(); ++i)
  14035. s.addIfNotAlreadyThere (commands.getUnchecked(i)->categoryName, false);
  14036. return s;
  14037. }
  14038. const Array <CommandID> ApplicationCommandManager::getCommandsInCategory (const String& categoryName) const throw()
  14039. {
  14040. Array <CommandID> results;
  14041. for (int i = 0; i < commands.size(); ++i)
  14042. if (commands.getUnchecked(i)->categoryName == categoryName)
  14043. results.add (commands.getUnchecked(i)->commandID);
  14044. return results;
  14045. }
  14046. bool ApplicationCommandManager::invokeDirectly (const CommandID commandID, const bool asynchronously)
  14047. {
  14048. ApplicationCommandTarget::InvocationInfo info (commandID);
  14049. info.invocationMethod = ApplicationCommandTarget::InvocationInfo::direct;
  14050. return invoke (info, asynchronously);
  14051. }
  14052. bool ApplicationCommandManager::invoke (const ApplicationCommandTarget::InvocationInfo& info_, const bool asynchronously)
  14053. {
  14054. // This call isn't thread-safe for use from a non-UI thread without locking the message
  14055. // manager first..
  14056. jassert (MessageManager::getInstance()->currentThreadHasLockedMessageManager());
  14057. ApplicationCommandTarget* const target = getFirstCommandTarget (info_.commandID);
  14058. if (target == 0)
  14059. return false;
  14060. ApplicationCommandInfo commandInfo (0);
  14061. target->getCommandInfo (info_.commandID, commandInfo);
  14062. ApplicationCommandTarget::InvocationInfo info (info_);
  14063. info.commandFlags = commandInfo.flags;
  14064. sendListenerInvokeCallback (info);
  14065. const bool ok = target->invoke (info, asynchronously);
  14066. commandStatusChanged();
  14067. return ok;
  14068. }
  14069. ApplicationCommandTarget* ApplicationCommandManager::getFirstCommandTarget (const CommandID)
  14070. {
  14071. return firstTarget != 0 ? firstTarget
  14072. : findDefaultComponentTarget();
  14073. }
  14074. void ApplicationCommandManager::setFirstCommandTarget (ApplicationCommandTarget* const newTarget) throw()
  14075. {
  14076. firstTarget = newTarget;
  14077. }
  14078. ApplicationCommandTarget* ApplicationCommandManager::getTargetForCommand (const CommandID commandID,
  14079. ApplicationCommandInfo& upToDateInfo)
  14080. {
  14081. ApplicationCommandTarget* target = getFirstCommandTarget (commandID);
  14082. if (target == 0)
  14083. target = JUCEApplication::getInstance();
  14084. if (target != 0)
  14085. target = target->getTargetForCommand (commandID);
  14086. if (target != 0)
  14087. target->getCommandInfo (commandID, upToDateInfo);
  14088. return target;
  14089. }
  14090. ApplicationCommandTarget* ApplicationCommandManager::findTargetForComponent (Component* c)
  14091. {
  14092. ApplicationCommandTarget* target = dynamic_cast <ApplicationCommandTarget*> (c);
  14093. if (target == 0 && c != 0)
  14094. // (unable to use the syntax findParentComponentOfClass <ApplicationCommandTarget> () because of a VC6 compiler bug)
  14095. target = c->findParentComponentOfClass ((ApplicationCommandTarget*) 0);
  14096. return target;
  14097. }
  14098. ApplicationCommandTarget* ApplicationCommandManager::findDefaultComponentTarget()
  14099. {
  14100. Component* c = Component::getCurrentlyFocusedComponent();
  14101. if (c == 0)
  14102. {
  14103. TopLevelWindow* const activeWindow = TopLevelWindow::getActiveTopLevelWindow();
  14104. if (activeWindow != 0)
  14105. {
  14106. c = activeWindow->getPeer()->getLastFocusedSubcomponent();
  14107. if (c == 0)
  14108. c = activeWindow;
  14109. }
  14110. }
  14111. if (c == 0 && Process::isForegroundProcess())
  14112. {
  14113. // getting a bit desperate now - try all desktop comps..
  14114. for (int i = Desktop::getInstance().getNumComponents(); --i >= 0;)
  14115. {
  14116. ApplicationCommandTarget* const target
  14117. = findTargetForComponent (Desktop::getInstance().getComponent (i)
  14118. ->getPeer()->getLastFocusedSubcomponent());
  14119. if (target != 0)
  14120. return target;
  14121. }
  14122. }
  14123. if (c != 0)
  14124. {
  14125. ResizableWindow* const resizableWindow = dynamic_cast <ResizableWindow*> (c);
  14126. // if we're focused on a ResizableWindow, chances are that it's the content
  14127. // component that really should get the event. And if not, the event will
  14128. // still be passed up to the top level window anyway, so let's send it to the
  14129. // content comp.
  14130. if (resizableWindow != 0 && resizableWindow->getContentComponent() != 0)
  14131. c = resizableWindow->getContentComponent();
  14132. ApplicationCommandTarget* const target = findTargetForComponent (c);
  14133. if (target != 0)
  14134. return target;
  14135. }
  14136. return JUCEApplication::getInstance();
  14137. }
  14138. void ApplicationCommandManager::addListener (ApplicationCommandManagerListener* const listener) throw()
  14139. {
  14140. jassert (listener != 0);
  14141. if (listener != 0)
  14142. listeners.add (listener);
  14143. }
  14144. void ApplicationCommandManager::removeListener (ApplicationCommandManagerListener* const listener) throw()
  14145. {
  14146. listeners.removeValue (listener);
  14147. }
  14148. void ApplicationCommandManager::sendListenerInvokeCallback (const ApplicationCommandTarget::InvocationInfo& info) const
  14149. {
  14150. for (int i = listeners.size(); --i >= 0;)
  14151. {
  14152. ((ApplicationCommandManagerListener*) listeners.getUnchecked (i))->applicationCommandInvoked (info);
  14153. i = jmin (i, listeners.size());
  14154. }
  14155. }
  14156. void ApplicationCommandManager::handleAsyncUpdate()
  14157. {
  14158. for (int i = listeners.size(); --i >= 0;)
  14159. {
  14160. ((ApplicationCommandManagerListener*) listeners.getUnchecked (i))->applicationCommandListChanged();
  14161. i = jmin (i, listeners.size());
  14162. }
  14163. }
  14164. void ApplicationCommandManager::globalFocusChanged (Component*)
  14165. {
  14166. commandStatusChanged();
  14167. }
  14168. END_JUCE_NAMESPACE
  14169. /********* End of inlined file: juce_ApplicationCommandManager.cpp *********/
  14170. /********* Start of inlined file: juce_ApplicationCommandTarget.cpp *********/
  14171. BEGIN_JUCE_NAMESPACE
  14172. ApplicationCommandTarget::ApplicationCommandTarget()
  14173. {
  14174. }
  14175. ApplicationCommandTarget::~ApplicationCommandTarget()
  14176. {
  14177. messageInvoker = 0;
  14178. }
  14179. bool ApplicationCommandTarget::tryToInvoke (const InvocationInfo& info, const bool async)
  14180. {
  14181. if (isCommandActive (info.commandID))
  14182. {
  14183. if (async)
  14184. {
  14185. if (messageInvoker == 0)
  14186. messageInvoker = new CommandTargetMessageInvoker (this);
  14187. messageInvoker->postMessage (new Message (0, 0, 0, new ApplicationCommandTarget::InvocationInfo (info)));
  14188. return true;
  14189. }
  14190. else
  14191. {
  14192. const bool success = perform (info);
  14193. jassert (success); // hmm - your target should have been able to perform this command. If it can't
  14194. // do it at the moment for some reason, it should clear the 'isActive' flag when it
  14195. // returns the command's info.
  14196. return success;
  14197. }
  14198. }
  14199. return false;
  14200. }
  14201. ApplicationCommandTarget* ApplicationCommandTarget::findFirstTargetParentComponent()
  14202. {
  14203. Component* c = dynamic_cast <Component*> (this);
  14204. if (c != 0)
  14205. // (unable to use the syntax findParentComponentOfClass <ApplicationCommandTarget> () because of a VC6 compiler bug)
  14206. return c->findParentComponentOfClass ((ApplicationCommandTarget*) 0);
  14207. return 0;
  14208. }
  14209. ApplicationCommandTarget* ApplicationCommandTarget::getTargetForCommand (const CommandID commandID)
  14210. {
  14211. ApplicationCommandTarget* target = this;
  14212. int depth = 0;
  14213. while (target != 0)
  14214. {
  14215. Array <CommandID> commandIDs;
  14216. target->getAllCommands (commandIDs);
  14217. if (commandIDs.contains (commandID))
  14218. return target;
  14219. target = target->getNextCommandTarget();
  14220. ++depth;
  14221. jassert (depth < 100); // could be a recursive command chain??
  14222. jassert (target != this); // definitely a recursive command chain!
  14223. if (depth > 100 || target == this)
  14224. break;
  14225. }
  14226. if (target == 0)
  14227. {
  14228. target = JUCEApplication::getInstance();
  14229. if (target != 0)
  14230. {
  14231. Array <CommandID> commandIDs;
  14232. target->getAllCommands (commandIDs);
  14233. if (commandIDs.contains (commandID))
  14234. return target;
  14235. }
  14236. }
  14237. return 0;
  14238. }
  14239. bool ApplicationCommandTarget::isCommandActive (const CommandID commandID)
  14240. {
  14241. ApplicationCommandInfo info (commandID);
  14242. info.flags = ApplicationCommandInfo::isDisabled;
  14243. getCommandInfo (commandID, info);
  14244. return (info.flags & ApplicationCommandInfo::isDisabled) == 0;
  14245. }
  14246. bool ApplicationCommandTarget::invoke (const InvocationInfo& info, const bool async)
  14247. {
  14248. ApplicationCommandTarget* target = this;
  14249. int depth = 0;
  14250. while (target != 0)
  14251. {
  14252. if (target->tryToInvoke (info, async))
  14253. return true;
  14254. target = target->getNextCommandTarget();
  14255. ++depth;
  14256. jassert (depth < 100); // could be a recursive command chain??
  14257. jassert (target != this); // definitely a recursive command chain!
  14258. if (depth > 100 || target == this)
  14259. break;
  14260. }
  14261. if (target == 0)
  14262. {
  14263. target = JUCEApplication::getInstance();
  14264. if (target != 0)
  14265. return target->tryToInvoke (info, async);
  14266. }
  14267. return false;
  14268. }
  14269. bool ApplicationCommandTarget::invokeDirectly (const CommandID commandID, const bool asynchronously)
  14270. {
  14271. ApplicationCommandTarget::InvocationInfo info (commandID);
  14272. info.invocationMethod = ApplicationCommandTarget::InvocationInfo::direct;
  14273. return invoke (info, asynchronously);
  14274. }
  14275. ApplicationCommandTarget::InvocationInfo::InvocationInfo (const CommandID commandID_) throw()
  14276. : commandID (commandID_),
  14277. commandFlags (0),
  14278. invocationMethod (direct),
  14279. originatingComponent (0),
  14280. isKeyDown (false),
  14281. millisecsSinceKeyPressed (0)
  14282. {
  14283. }
  14284. ApplicationCommandTarget::CommandTargetMessageInvoker::CommandTargetMessageInvoker (ApplicationCommandTarget* const owner_)
  14285. : owner (owner_)
  14286. {
  14287. }
  14288. ApplicationCommandTarget::CommandTargetMessageInvoker::~CommandTargetMessageInvoker()
  14289. {
  14290. }
  14291. void ApplicationCommandTarget::CommandTargetMessageInvoker::handleMessage (const Message& message)
  14292. {
  14293. const ScopedPointer <InvocationInfo> info ((InvocationInfo*) message.pointerParameter);
  14294. owner->tryToInvoke (*info, false);
  14295. }
  14296. END_JUCE_NAMESPACE
  14297. /********* End of inlined file: juce_ApplicationCommandTarget.cpp *********/
  14298. /********* Start of inlined file: juce_ApplicationProperties.cpp *********/
  14299. BEGIN_JUCE_NAMESPACE
  14300. juce_ImplementSingleton (ApplicationProperties)
  14301. ApplicationProperties::ApplicationProperties() throw()
  14302. : msBeforeSaving (3000),
  14303. options (PropertiesFile::storeAsBinary),
  14304. commonSettingsAreReadOnly (0)
  14305. {
  14306. }
  14307. ApplicationProperties::~ApplicationProperties()
  14308. {
  14309. closeFiles();
  14310. clearSingletonInstance();
  14311. }
  14312. void ApplicationProperties::setStorageParameters (const String& applicationName,
  14313. const String& fileNameSuffix,
  14314. const String& folderName_,
  14315. const int millisecondsBeforeSaving,
  14316. const int propertiesFileOptions) throw()
  14317. {
  14318. appName = applicationName;
  14319. fileSuffix = fileNameSuffix;
  14320. folderName = folderName_;
  14321. msBeforeSaving = millisecondsBeforeSaving;
  14322. options = propertiesFileOptions;
  14323. }
  14324. bool ApplicationProperties::testWriteAccess (const bool testUserSettings,
  14325. const bool testCommonSettings,
  14326. const bool showWarningDialogOnFailure)
  14327. {
  14328. const bool userOk = (! testUserSettings) || getUserSettings()->save();
  14329. const bool commonOk = (! testCommonSettings) || getCommonSettings (false)->save();
  14330. if (! (userOk && commonOk))
  14331. {
  14332. if (showWarningDialogOnFailure)
  14333. {
  14334. String filenames;
  14335. if (userProps != 0 && ! userOk)
  14336. filenames << '\n' << userProps->getFile().getFullPathName();
  14337. if (commonProps != 0 && ! commonOk)
  14338. filenames << '\n' << commonProps->getFile().getFullPathName();
  14339. AlertWindow::showMessageBox (AlertWindow::WarningIcon,
  14340. appName + TRANS(" - Unable to save settings"),
  14341. TRANS("An error occurred when trying to save the application's settings file...\n\nIn order to save and restore its settings, ")
  14342. + appName + TRANS(" needs to be able to write to the following files:\n")
  14343. + filenames
  14344. + TRANS("\n\nMake sure that these files aren't read-only, and that the disk isn't full."));
  14345. }
  14346. return false;
  14347. }
  14348. return true;
  14349. }
  14350. void ApplicationProperties::openFiles() throw()
  14351. {
  14352. // You need to call setStorageParameters() before trying to get hold of the
  14353. // properties!
  14354. jassert (appName.isNotEmpty());
  14355. if (appName.isNotEmpty())
  14356. {
  14357. if (userProps == 0)
  14358. userProps = PropertiesFile::createDefaultAppPropertiesFile (appName, fileSuffix, folderName,
  14359. false, msBeforeSaving, options);
  14360. if (commonProps == 0)
  14361. commonProps = PropertiesFile::createDefaultAppPropertiesFile (appName, fileSuffix, folderName,
  14362. true, msBeforeSaving, options);
  14363. userProps->setFallbackPropertySet (commonProps);
  14364. }
  14365. }
  14366. PropertiesFile* ApplicationProperties::getUserSettings() throw()
  14367. {
  14368. if (userProps == 0)
  14369. openFiles();
  14370. return userProps;
  14371. }
  14372. PropertiesFile* ApplicationProperties::getCommonSettings (const bool returnUserPropsIfReadOnly) throw()
  14373. {
  14374. if (commonProps == 0)
  14375. openFiles();
  14376. if (returnUserPropsIfReadOnly)
  14377. {
  14378. if (commonSettingsAreReadOnly == 0)
  14379. commonSettingsAreReadOnly = commonProps->save() ? -1 : 1;
  14380. if (commonSettingsAreReadOnly > 0)
  14381. return userProps;
  14382. }
  14383. return commonProps;
  14384. }
  14385. bool ApplicationProperties::saveIfNeeded()
  14386. {
  14387. return (userProps == 0 || userProps->saveIfNeeded())
  14388. && (commonProps == 0 || commonProps->saveIfNeeded());
  14389. }
  14390. void ApplicationProperties::closeFiles()
  14391. {
  14392. userProps = 0;
  14393. commonProps = 0;
  14394. }
  14395. END_JUCE_NAMESPACE
  14396. /********* End of inlined file: juce_ApplicationProperties.cpp *********/
  14397. /********* Start of inlined file: juce_DeletedAtShutdown.cpp *********/
  14398. BEGIN_JUCE_NAMESPACE
  14399. static VoidArray objectsToDelete;
  14400. static CriticalSection lock;
  14401. DeletedAtShutdown::DeletedAtShutdown()
  14402. {
  14403. const ScopedLock sl (lock);
  14404. objectsToDelete.add (this);
  14405. }
  14406. DeletedAtShutdown::~DeletedAtShutdown()
  14407. {
  14408. const ScopedLock sl (lock);
  14409. objectsToDelete.removeValue (this);
  14410. }
  14411. void DeletedAtShutdown::deleteAll()
  14412. {
  14413. // make a local copy of the array, so it can't get into a loop if something
  14414. // creates another DeletedAtShutdown object during its destructor.
  14415. lock.enter();
  14416. const VoidArray localCopy (objectsToDelete);
  14417. lock.exit();
  14418. for (int i = localCopy.size(); --i >= 0;)
  14419. {
  14420. JUCE_TRY
  14421. {
  14422. DeletedAtShutdown* deletee = (DeletedAtShutdown*) localCopy.getUnchecked(i);
  14423. // double-check that it's not already been deleted during another object's destructor.
  14424. {
  14425. const ScopedLock sl (lock);
  14426. if (! objectsToDelete.contains (deletee))
  14427. deletee = 0;
  14428. }
  14429. delete deletee;
  14430. }
  14431. JUCE_CATCH_EXCEPTION
  14432. }
  14433. // if no objects got re-created during shutdown, this should have been emptied by their
  14434. // destructors
  14435. jassert (objectsToDelete.size() == 0);
  14436. objectsToDelete.clear(); // just to make sure the array doesn't have any memory still allocated
  14437. }
  14438. END_JUCE_NAMESPACE
  14439. /********* End of inlined file: juce_DeletedAtShutdown.cpp *********/
  14440. /********* Start of inlined file: juce_PropertiesFile.cpp *********/
  14441. BEGIN_JUCE_NAMESPACE
  14442. static const int propFileMagicNumber = ((int) ByteOrder::littleEndianInt ("PROP"));
  14443. static const int propFileMagicNumberCompressed = ((int) ByteOrder::littleEndianInt ("CPRP"));
  14444. static const tchar* const propertyFileXmlTag = T("PROPERTIES");
  14445. static const tchar* const propertyTagName = T("VALUE");
  14446. PropertiesFile::PropertiesFile (const File& f,
  14447. const int millisecondsBeforeSaving,
  14448. const int options_)
  14449. : PropertySet (ignoreCaseOfKeyNames),
  14450. file (f),
  14451. timerInterval (millisecondsBeforeSaving),
  14452. options (options_),
  14453. needsWriting (false)
  14454. {
  14455. // You need to correctly specify just one storage format for the file
  14456. jassert ((options_ & (storeAsBinary | storeAsCompressedBinary | storeAsXML)) == storeAsBinary
  14457. || (options_ & (storeAsBinary | storeAsCompressedBinary | storeAsXML)) == storeAsCompressedBinary
  14458. || (options_ & (storeAsBinary | storeAsCompressedBinary | storeAsXML)) == storeAsXML);
  14459. ScopedPointer <InputStream> fileStream (f.createInputStream());
  14460. if (fileStream != 0)
  14461. {
  14462. int magicNumber = fileStream->readInt();
  14463. if (magicNumber == propFileMagicNumberCompressed)
  14464. {
  14465. fileStream = new GZIPDecompressorInputStream (new SubregionStream (fileStream.release(), 4, -1, true),
  14466. true);
  14467. magicNumber = propFileMagicNumber;
  14468. }
  14469. if (magicNumber == propFileMagicNumber)
  14470. {
  14471. BufferedInputStream in (fileStream.release(), 2048, true);
  14472. int numValues = in.readInt();
  14473. while (--numValues >= 0 && ! in.isExhausted())
  14474. {
  14475. const String key (in.readString());
  14476. const String value (in.readString());
  14477. jassert (key.isNotEmpty());
  14478. if (key.isNotEmpty())
  14479. getAllProperties().set (key, value);
  14480. }
  14481. }
  14482. else
  14483. {
  14484. // Not a binary props file - let's see if it's XML..
  14485. fileStream = 0;
  14486. XmlDocument parser (f);
  14487. ScopedPointer <XmlElement> doc (parser.getDocumentElement (true));
  14488. if (doc != 0 && doc->hasTagName (propertyFileXmlTag))
  14489. {
  14490. doc = parser.getDocumentElement();
  14491. if (doc != 0)
  14492. {
  14493. forEachXmlChildElementWithTagName (*doc, e, propertyTagName)
  14494. {
  14495. const String name (e->getStringAttribute (T("name")));
  14496. if (name.isNotEmpty())
  14497. {
  14498. getAllProperties().set (name,
  14499. e->getFirstChildElement() != 0
  14500. ? e->getFirstChildElement()->createDocument (String::empty, true)
  14501. : e->getStringAttribute (T("val")));
  14502. }
  14503. }
  14504. }
  14505. else
  14506. {
  14507. // must be a pretty broken XML file we're trying to parse here!
  14508. jassertfalse
  14509. }
  14510. }
  14511. }
  14512. }
  14513. }
  14514. PropertiesFile::~PropertiesFile()
  14515. {
  14516. saveIfNeeded();
  14517. }
  14518. bool PropertiesFile::saveIfNeeded()
  14519. {
  14520. const ScopedLock sl (getLock());
  14521. return (! needsWriting) || save();
  14522. }
  14523. bool PropertiesFile::needsToBeSaved() const
  14524. {
  14525. const ScopedLock sl (getLock());
  14526. return needsWriting;
  14527. }
  14528. bool PropertiesFile::save()
  14529. {
  14530. const ScopedLock sl (getLock());
  14531. stopTimer();
  14532. if (file == File::nonexistent
  14533. || file.isDirectory()
  14534. || ! file.getParentDirectory().createDirectory())
  14535. return false;
  14536. if ((options & storeAsXML) != 0)
  14537. {
  14538. XmlElement doc (propertyFileXmlTag);
  14539. for (int i = 0; i < getAllProperties().size(); ++i)
  14540. {
  14541. XmlElement* const e = new XmlElement (propertyTagName);
  14542. e->setAttribute (T("name"), getAllProperties().getAllKeys() [i]);
  14543. // if the value seems to contain xml, store it as such..
  14544. XmlDocument xmlContent (getAllProperties().getAllValues() [i]);
  14545. XmlElement* const childElement = xmlContent.getDocumentElement();
  14546. if (childElement != 0)
  14547. e->addChildElement (childElement);
  14548. else
  14549. e->setAttribute (T("val"), getAllProperties().getAllValues() [i]);
  14550. doc.addChildElement (e);
  14551. }
  14552. return doc.writeToFile (file, String::empty);
  14553. }
  14554. else
  14555. {
  14556. TemporaryFile tempFile (file);
  14557. ScopedPointer <OutputStream> out (tempFile.getFile().createOutputStream());
  14558. if (out != 0)
  14559. {
  14560. if ((options & storeAsCompressedBinary) != 0)
  14561. {
  14562. out->writeInt (propFileMagicNumberCompressed);
  14563. out->flush();
  14564. out = new GZIPCompressorOutputStream (out.release(), 9, true);
  14565. }
  14566. else
  14567. {
  14568. // have you set up the storage option flags correctly?
  14569. jassert ((options & storeAsBinary) != 0);
  14570. out->writeInt (propFileMagicNumber);
  14571. }
  14572. const int numProperties = getAllProperties().size();
  14573. out->writeInt (numProperties);
  14574. for (int i = 0; i < numProperties; ++i)
  14575. {
  14576. out->writeString (getAllProperties().getAllKeys() [i]);
  14577. out->writeString (getAllProperties().getAllValues() [i]);
  14578. }
  14579. out = 0;
  14580. if (tempFile.overwriteTargetFileWithTemporary())
  14581. {
  14582. needsWriting = false;
  14583. return true;
  14584. }
  14585. }
  14586. }
  14587. return false;
  14588. }
  14589. void PropertiesFile::timerCallback()
  14590. {
  14591. saveIfNeeded();
  14592. }
  14593. void PropertiesFile::propertyChanged()
  14594. {
  14595. sendChangeMessage (this);
  14596. needsWriting = true;
  14597. if (timerInterval > 0)
  14598. startTimer (timerInterval);
  14599. else if (timerInterval == 0)
  14600. saveIfNeeded();
  14601. }
  14602. const File PropertiesFile::getDefaultAppSettingsFile (const String& applicationName,
  14603. const String& fileNameSuffix,
  14604. const String& folderName,
  14605. const bool commonToAllUsers)
  14606. {
  14607. // mustn't have illegal characters in this name..
  14608. jassert (applicationName == File::createLegalFileName (applicationName));
  14609. #if JUCE_MAC || JUCE_IPHONE
  14610. File dir (commonToAllUsers ? "/Library/Preferences"
  14611. : "~/Library/Preferences");
  14612. if (folderName.isNotEmpty())
  14613. dir = dir.getChildFile (folderName);
  14614. #endif
  14615. #ifdef JUCE_LINUX
  14616. const File dir ((commonToAllUsers ? T("/var/") : T("~/"))
  14617. + (folderName.isNotEmpty() ? folderName
  14618. : (T(".") + applicationName)));
  14619. #endif
  14620. #if JUCE_WIN32
  14621. File dir (File::getSpecialLocation (commonToAllUsers ? File::commonApplicationDataDirectory
  14622. : File::userApplicationDataDirectory));
  14623. if (dir == File::nonexistent)
  14624. return File::nonexistent;
  14625. dir = dir.getChildFile (folderName.isNotEmpty() ? folderName
  14626. : applicationName);
  14627. #endif
  14628. return dir.getChildFile (applicationName)
  14629. .withFileExtension (fileNameSuffix);
  14630. }
  14631. PropertiesFile* PropertiesFile::createDefaultAppPropertiesFile (const String& applicationName,
  14632. const String& fileNameSuffix,
  14633. const String& folderName,
  14634. const bool commonToAllUsers,
  14635. const int millisecondsBeforeSaving,
  14636. const int propertiesFileOptions)
  14637. {
  14638. const File file (getDefaultAppSettingsFile (applicationName,
  14639. fileNameSuffix,
  14640. folderName,
  14641. commonToAllUsers));
  14642. jassert (file != File::nonexistent);
  14643. if (file == File::nonexistent)
  14644. return 0;
  14645. return new PropertiesFile (file, millisecondsBeforeSaving, propertiesFileOptions);
  14646. }
  14647. END_JUCE_NAMESPACE
  14648. /********* End of inlined file: juce_PropertiesFile.cpp *********/
  14649. /********* Start of inlined file: juce_FileBasedDocument.cpp *********/
  14650. BEGIN_JUCE_NAMESPACE
  14651. FileBasedDocument::FileBasedDocument (const String& fileExtension_,
  14652. const String& fileWildcard_,
  14653. const String& openFileDialogTitle_,
  14654. const String& saveFileDialogTitle_)
  14655. : changedSinceSave (false),
  14656. fileExtension (fileExtension_),
  14657. fileWildcard (fileWildcard_),
  14658. openFileDialogTitle (openFileDialogTitle_),
  14659. saveFileDialogTitle (saveFileDialogTitle_)
  14660. {
  14661. }
  14662. FileBasedDocument::~FileBasedDocument()
  14663. {
  14664. }
  14665. void FileBasedDocument::setChangedFlag (const bool hasChanged)
  14666. {
  14667. changedSinceSave = hasChanged;
  14668. }
  14669. void FileBasedDocument::changed()
  14670. {
  14671. changedSinceSave = true;
  14672. sendChangeMessage (this);
  14673. }
  14674. void FileBasedDocument::setFile (const File& newFile)
  14675. {
  14676. if (documentFile != newFile)
  14677. {
  14678. documentFile = newFile;
  14679. changedSinceSave = true;
  14680. }
  14681. }
  14682. bool FileBasedDocument::loadFrom (const File& newFile,
  14683. const bool showMessageOnFailure)
  14684. {
  14685. MouseCursor::showWaitCursor();
  14686. const File oldFile (documentFile);
  14687. documentFile = newFile;
  14688. String error;
  14689. if (newFile.existsAsFile())
  14690. {
  14691. error = loadDocument (newFile);
  14692. if (error.isEmpty())
  14693. {
  14694. setChangedFlag (false);
  14695. MouseCursor::hideWaitCursor();
  14696. setLastDocumentOpened (newFile);
  14697. return true;
  14698. }
  14699. }
  14700. else
  14701. {
  14702. error = "The file doesn't exist";
  14703. }
  14704. documentFile = oldFile;
  14705. MouseCursor::hideWaitCursor();
  14706. if (showMessageOnFailure)
  14707. {
  14708. AlertWindow::showMessageBox (AlertWindow::WarningIcon,
  14709. TRANS("Failed to open file..."),
  14710. TRANS("There was an error while trying to load the file:\n\n")
  14711. + newFile.getFullPathName()
  14712. + T("\n\n")
  14713. + error);
  14714. }
  14715. return false;
  14716. }
  14717. bool FileBasedDocument::loadFromUserSpecifiedFile (const bool showMessageOnFailure)
  14718. {
  14719. FileChooser fc (openFileDialogTitle,
  14720. getLastDocumentOpened(),
  14721. fileWildcard);
  14722. if (fc.browseForFileToOpen())
  14723. return loadFrom (fc.getResult(), showMessageOnFailure);
  14724. return false;
  14725. }
  14726. FileBasedDocument::SaveResult FileBasedDocument::save (const bool askUserForFileIfNotSpecified,
  14727. const bool showMessageOnFailure)
  14728. {
  14729. return saveAs (documentFile,
  14730. false,
  14731. askUserForFileIfNotSpecified,
  14732. showMessageOnFailure);
  14733. }
  14734. FileBasedDocument::SaveResult FileBasedDocument::saveAs (const File& newFile,
  14735. const bool warnAboutOverwritingExistingFiles,
  14736. const bool askUserForFileIfNotSpecified,
  14737. const bool showMessageOnFailure)
  14738. {
  14739. if (newFile == File::nonexistent)
  14740. {
  14741. if (askUserForFileIfNotSpecified)
  14742. {
  14743. return saveAsInteractive (true);
  14744. }
  14745. else
  14746. {
  14747. // can't save to an unspecified file
  14748. jassertfalse
  14749. return failedToWriteToFile;
  14750. }
  14751. }
  14752. if (warnAboutOverwritingExistingFiles && newFile.exists())
  14753. {
  14754. if (! AlertWindow::showOkCancelBox (AlertWindow::WarningIcon,
  14755. TRANS("File already exists"),
  14756. TRANS("There's already a file called:\n\n")
  14757. + newFile.getFullPathName()
  14758. + TRANS("\n\nAre you sure you want to overwrite it?"),
  14759. TRANS("overwrite"),
  14760. TRANS("cancel")))
  14761. {
  14762. return userCancelledSave;
  14763. }
  14764. }
  14765. MouseCursor::showWaitCursor();
  14766. const File oldFile (documentFile);
  14767. documentFile = newFile;
  14768. String error (saveDocument (newFile));
  14769. if (error.isEmpty())
  14770. {
  14771. setChangedFlag (false);
  14772. MouseCursor::hideWaitCursor();
  14773. return savedOk;
  14774. }
  14775. documentFile = oldFile;
  14776. MouseCursor::hideWaitCursor();
  14777. if (showMessageOnFailure)
  14778. {
  14779. AlertWindow::showMessageBox (AlertWindow::WarningIcon,
  14780. TRANS("Error writing to file..."),
  14781. TRANS("An error occurred while trying to save \"")
  14782. + getDocumentTitle()
  14783. + TRANS("\" to the file:\n\n")
  14784. + newFile.getFullPathName()
  14785. + T("\n\n")
  14786. + error);
  14787. }
  14788. return failedToWriteToFile;
  14789. }
  14790. FileBasedDocument::SaveResult FileBasedDocument::saveIfNeededAndUserAgrees()
  14791. {
  14792. if (! hasChangedSinceSaved())
  14793. return savedOk;
  14794. const int r = AlertWindow::showYesNoCancelBox (AlertWindow::QuestionIcon,
  14795. TRANS("Closing document..."),
  14796. TRANS("Do you want to save the changes to \"")
  14797. + getDocumentTitle() + T("\"?"),
  14798. TRANS("save"),
  14799. TRANS("discard changes"),
  14800. TRANS("cancel"));
  14801. if (r == 1)
  14802. {
  14803. // save changes
  14804. return save (true, true);
  14805. }
  14806. else if (r == 2)
  14807. {
  14808. // discard changes
  14809. return savedOk;
  14810. }
  14811. return userCancelledSave;
  14812. }
  14813. FileBasedDocument::SaveResult FileBasedDocument::saveAsInteractive (const bool warnAboutOverwritingExistingFiles)
  14814. {
  14815. File f;
  14816. if (documentFile.existsAsFile())
  14817. f = documentFile;
  14818. else
  14819. f = getLastDocumentOpened();
  14820. String legalFilename (File::createLegalFileName (getDocumentTitle()));
  14821. if (legalFilename.isEmpty())
  14822. legalFilename = "unnamed";
  14823. if (f.existsAsFile() || f.getParentDirectory().isDirectory())
  14824. f = f.getSiblingFile (legalFilename);
  14825. else
  14826. f = File::getSpecialLocation (File::userDocumentsDirectory).getChildFile (legalFilename);
  14827. f = f.withFileExtension (fileExtension)
  14828. .getNonexistentSibling (true);
  14829. FileChooser fc (saveFileDialogTitle, f, fileWildcard);
  14830. if (fc.browseForFileToSave (warnAboutOverwritingExistingFiles))
  14831. {
  14832. setLastDocumentOpened (fc.getResult());
  14833. File chosen (fc.getResult());
  14834. if (chosen.getFileExtension().isEmpty())
  14835. {
  14836. chosen = chosen.withFileExtension (fileExtension);
  14837. if (chosen.exists())
  14838. {
  14839. if (! AlertWindow::showOkCancelBox (AlertWindow::WarningIcon,
  14840. TRANS("File already exists"),
  14841. TRANS("There's already a file called:\n\n")
  14842. + chosen.getFullPathName()
  14843. + T("\n\nAre you sure you want to overwrite it?"),
  14844. TRANS("overwrite"),
  14845. TRANS("cancel")))
  14846. {
  14847. return userCancelledSave;
  14848. }
  14849. }
  14850. }
  14851. return saveAs (chosen, false, false, true);
  14852. }
  14853. return userCancelledSave;
  14854. }
  14855. END_JUCE_NAMESPACE
  14856. /********* End of inlined file: juce_FileBasedDocument.cpp *********/
  14857. /********* Start of inlined file: juce_RecentlyOpenedFilesList.cpp *********/
  14858. BEGIN_JUCE_NAMESPACE
  14859. RecentlyOpenedFilesList::RecentlyOpenedFilesList()
  14860. : maxNumberOfItems (10)
  14861. {
  14862. }
  14863. RecentlyOpenedFilesList::~RecentlyOpenedFilesList()
  14864. {
  14865. }
  14866. void RecentlyOpenedFilesList::setMaxNumberOfItems (const int newMaxNumber)
  14867. {
  14868. maxNumberOfItems = jmax (1, newMaxNumber);
  14869. while (getNumFiles() > maxNumberOfItems)
  14870. files.remove (getNumFiles() - 1);
  14871. }
  14872. int RecentlyOpenedFilesList::getNumFiles() const
  14873. {
  14874. return files.size();
  14875. }
  14876. const File RecentlyOpenedFilesList::getFile (const int index) const
  14877. {
  14878. return File (files [index]);
  14879. }
  14880. void RecentlyOpenedFilesList::clear()
  14881. {
  14882. files.clear();
  14883. }
  14884. void RecentlyOpenedFilesList::addFile (const File& file)
  14885. {
  14886. const String path (file.getFullPathName());
  14887. files.removeString (path, true);
  14888. files.insert (0, path);
  14889. setMaxNumberOfItems (maxNumberOfItems);
  14890. }
  14891. void RecentlyOpenedFilesList::removeNonExistentFiles()
  14892. {
  14893. for (int i = getNumFiles(); --i >= 0;)
  14894. if (! getFile(i).exists())
  14895. files.remove (i);
  14896. }
  14897. int RecentlyOpenedFilesList::createPopupMenuItems (PopupMenu& menuToAddTo,
  14898. const int baseItemId,
  14899. const bool showFullPaths,
  14900. const bool dontAddNonExistentFiles,
  14901. const File** filesToAvoid)
  14902. {
  14903. int num = 0;
  14904. for (int i = 0; i < getNumFiles(); ++i)
  14905. {
  14906. const File f (getFile(i));
  14907. if ((! dontAddNonExistentFiles) || f.exists())
  14908. {
  14909. bool needsAvoiding = false;
  14910. if (filesToAvoid != 0)
  14911. {
  14912. const File** avoid = filesToAvoid;
  14913. while (*avoid != 0)
  14914. {
  14915. if (f == **avoid)
  14916. {
  14917. needsAvoiding = true;
  14918. break;
  14919. }
  14920. ++avoid;
  14921. }
  14922. }
  14923. if (! needsAvoiding)
  14924. {
  14925. menuToAddTo.addItem (baseItemId + i,
  14926. showFullPaths ? f.getFullPathName()
  14927. : f.getFileName());
  14928. ++num;
  14929. }
  14930. }
  14931. }
  14932. return num;
  14933. }
  14934. const String RecentlyOpenedFilesList::toString() const
  14935. {
  14936. return files.joinIntoString (T("\n"));
  14937. }
  14938. void RecentlyOpenedFilesList::restoreFromString (const String& stringifiedVersion)
  14939. {
  14940. clear();
  14941. files.addLines (stringifiedVersion);
  14942. setMaxNumberOfItems (maxNumberOfItems);
  14943. }
  14944. END_JUCE_NAMESPACE
  14945. /********* End of inlined file: juce_RecentlyOpenedFilesList.cpp *********/
  14946. /********* Start of inlined file: juce_UndoManager.cpp *********/
  14947. BEGIN_JUCE_NAMESPACE
  14948. UndoManager::UndoManager (const int maxNumberOfUnitsToKeep,
  14949. const int minimumTransactions)
  14950. : totalUnitsStored (0),
  14951. nextIndex (0),
  14952. newTransaction (true),
  14953. reentrancyCheck (false)
  14954. {
  14955. setMaxNumberOfStoredUnits (maxNumberOfUnitsToKeep,
  14956. minimumTransactions);
  14957. }
  14958. UndoManager::~UndoManager()
  14959. {
  14960. clearUndoHistory();
  14961. }
  14962. void UndoManager::clearUndoHistory()
  14963. {
  14964. transactions.clear();
  14965. transactionNames.clear();
  14966. totalUnitsStored = 0;
  14967. nextIndex = 0;
  14968. sendChangeMessage (this);
  14969. }
  14970. int UndoManager::getNumberOfUnitsTakenUpByStoredCommands() const
  14971. {
  14972. return totalUnitsStored;
  14973. }
  14974. void UndoManager::setMaxNumberOfStoredUnits (const int maxNumberOfUnitsToKeep,
  14975. const int minimumTransactions)
  14976. {
  14977. maxNumUnitsToKeep = jmax (1, maxNumberOfUnitsToKeep);
  14978. minimumTransactionsToKeep = jmax (1, minimumTransactions);
  14979. }
  14980. bool UndoManager::perform (UndoableAction* const command, const String& actionName)
  14981. {
  14982. if (command != 0)
  14983. {
  14984. if (actionName.isNotEmpty())
  14985. currentTransactionName = actionName;
  14986. if (reentrancyCheck)
  14987. {
  14988. jassertfalse // don't call perform() recursively from the UndoableAction::perform() or
  14989. // undo() methods, or else these actions won't actually get done.
  14990. return false;
  14991. }
  14992. else
  14993. {
  14994. bool success = false;
  14995. JUCE_TRY
  14996. {
  14997. success = command->perform();
  14998. }
  14999. JUCE_CATCH_EXCEPTION
  15000. jassert (success);
  15001. if (success)
  15002. {
  15003. if (nextIndex > 0 && ! newTransaction)
  15004. {
  15005. OwnedArray<UndoableAction>* commandSet = transactions [nextIndex - 1];
  15006. jassert (commandSet != 0);
  15007. if (commandSet == 0)
  15008. return false;
  15009. commandSet->add (command);
  15010. }
  15011. else
  15012. {
  15013. OwnedArray<UndoableAction>* commandSet = new OwnedArray<UndoableAction>();
  15014. commandSet->add (command);
  15015. transactions.insert (nextIndex, commandSet);
  15016. transactionNames.insert (nextIndex, currentTransactionName);
  15017. ++nextIndex;
  15018. }
  15019. totalUnitsStored += command->getSizeInUnits();
  15020. newTransaction = false;
  15021. }
  15022. while (nextIndex < transactions.size())
  15023. {
  15024. const OwnedArray <UndoableAction>* const lastSet = transactions.getLast();
  15025. for (int i = lastSet->size(); --i >= 0;)
  15026. totalUnitsStored -= lastSet->getUnchecked (i)->getSizeInUnits();
  15027. transactions.removeLast();
  15028. transactionNames.remove (transactionNames.size() - 1);
  15029. }
  15030. while (nextIndex > 0
  15031. && totalUnitsStored > maxNumUnitsToKeep
  15032. && transactions.size() > minimumTransactionsToKeep)
  15033. {
  15034. const OwnedArray <UndoableAction>* const firstSet = transactions.getFirst();
  15035. for (int i = firstSet->size(); --i >= 0;)
  15036. totalUnitsStored -= firstSet->getUnchecked (i)->getSizeInUnits();
  15037. jassert (totalUnitsStored >= 0); // something fishy going on if this fails!
  15038. transactions.remove (0);
  15039. transactionNames.remove (0);
  15040. --nextIndex;
  15041. }
  15042. sendChangeMessage (this);
  15043. return success;
  15044. }
  15045. }
  15046. return false;
  15047. }
  15048. void UndoManager::beginNewTransaction (const String& actionName)
  15049. {
  15050. newTransaction = true;
  15051. currentTransactionName = actionName;
  15052. }
  15053. void UndoManager::setCurrentTransactionName (const String& newName)
  15054. {
  15055. currentTransactionName = newName;
  15056. }
  15057. bool UndoManager::canUndo() const
  15058. {
  15059. return nextIndex > 0;
  15060. }
  15061. bool UndoManager::canRedo() const
  15062. {
  15063. return nextIndex < transactions.size();
  15064. }
  15065. const String UndoManager::getUndoDescription() const
  15066. {
  15067. return transactionNames [nextIndex - 1];
  15068. }
  15069. const String UndoManager::getRedoDescription() const
  15070. {
  15071. return transactionNames [nextIndex];
  15072. }
  15073. bool UndoManager::undo()
  15074. {
  15075. const OwnedArray<UndoableAction>* const commandSet = transactions [nextIndex - 1];
  15076. if (commandSet == 0)
  15077. return false;
  15078. reentrancyCheck = true;
  15079. bool failed = false;
  15080. for (int i = commandSet->size(); --i >= 0;)
  15081. {
  15082. if (! commandSet->getUnchecked(i)->undo())
  15083. {
  15084. jassertfalse
  15085. failed = true;
  15086. break;
  15087. }
  15088. }
  15089. reentrancyCheck = false;
  15090. if (failed)
  15091. {
  15092. clearUndoHistory();
  15093. }
  15094. else
  15095. {
  15096. --nextIndex;
  15097. }
  15098. beginNewTransaction();
  15099. sendChangeMessage (this);
  15100. return true;
  15101. }
  15102. bool UndoManager::redo()
  15103. {
  15104. const OwnedArray<UndoableAction>* const commandSet = transactions [nextIndex];
  15105. if (commandSet == 0)
  15106. return false;
  15107. reentrancyCheck = true;
  15108. bool failed = false;
  15109. for (int i = 0; i < commandSet->size(); ++i)
  15110. {
  15111. if (! commandSet->getUnchecked(i)->perform())
  15112. {
  15113. jassertfalse
  15114. failed = true;
  15115. break;
  15116. }
  15117. }
  15118. reentrancyCheck = false;
  15119. if (failed)
  15120. {
  15121. clearUndoHistory();
  15122. }
  15123. else
  15124. {
  15125. ++nextIndex;
  15126. }
  15127. beginNewTransaction();
  15128. sendChangeMessage (this);
  15129. return true;
  15130. }
  15131. bool UndoManager::undoCurrentTransactionOnly()
  15132. {
  15133. return newTransaction ? false
  15134. : undo();
  15135. }
  15136. void UndoManager::getActionsInCurrentTransaction (Array <const UndoableAction*>& actionsFound) const
  15137. {
  15138. const OwnedArray <UndoableAction>* const commandSet = transactions [nextIndex - 1];
  15139. if (commandSet != 0 && ! newTransaction)
  15140. {
  15141. for (int i = 0; i < commandSet->size(); ++i)
  15142. actionsFound.add (commandSet->getUnchecked(i));
  15143. }
  15144. }
  15145. int UndoManager::getNumActionsInCurrentTransaction() const
  15146. {
  15147. const OwnedArray <UndoableAction>* const commandSet = transactions [nextIndex - 1];
  15148. if (commandSet != 0 && ! newTransaction)
  15149. return commandSet->size();
  15150. return 0;
  15151. }
  15152. END_JUCE_NAMESPACE
  15153. /********* End of inlined file: juce_UndoManager.cpp *********/
  15154. /********* Start of inlined file: juce_AiffAudioFormat.cpp *********/
  15155. BEGIN_JUCE_NAMESPACE
  15156. static const char* const aiffFormatName = "AIFF file";
  15157. static const tchar* const aiffExtensions[] = { T(".aiff"), T(".aif"), 0 };
  15158. class AiffAudioFormatReader : public AudioFormatReader
  15159. {
  15160. public:
  15161. int bytesPerFrame;
  15162. int64 dataChunkStart;
  15163. bool littleEndian;
  15164. AiffAudioFormatReader (InputStream* in)
  15165. : AudioFormatReader (in, TRANS (aiffFormatName))
  15166. {
  15167. if (input->readInt() == chunkName ("FORM"))
  15168. {
  15169. const int len = input->readIntBigEndian();
  15170. const int64 end = input->getPosition() + len;
  15171. const int nextType = input->readInt();
  15172. if (nextType == chunkName ("AIFF") || nextType == chunkName ("AIFC"))
  15173. {
  15174. bool hasGotVer = false;
  15175. bool hasGotData = false;
  15176. bool hasGotType = false;
  15177. while (input->getPosition() < end)
  15178. {
  15179. const int type = input->readInt();
  15180. const uint32 length = (uint32) input->readIntBigEndian();
  15181. const int64 chunkEnd = input->getPosition() + length;
  15182. if (type == chunkName ("FVER"))
  15183. {
  15184. hasGotVer = true;
  15185. const int ver = input->readIntBigEndian();
  15186. if (ver != 0 && ver != (int)0xa2805140)
  15187. break;
  15188. }
  15189. else if (type == chunkName ("COMM"))
  15190. {
  15191. hasGotType = true;
  15192. numChannels = (unsigned int)input->readShortBigEndian();
  15193. lengthInSamples = input->readIntBigEndian();
  15194. bitsPerSample = input->readShortBigEndian();
  15195. bytesPerFrame = (numChannels * bitsPerSample) >> 3;
  15196. unsigned char sampleRateBytes[10];
  15197. input->read (sampleRateBytes, 10);
  15198. const int byte0 = sampleRateBytes[0];
  15199. if ((byte0 & 0x80) != 0
  15200. || byte0 <= 0x3F || byte0 > 0x40
  15201. || (byte0 == 0x40 && sampleRateBytes[1] > 0x1C))
  15202. break;
  15203. unsigned int sampRate = ByteOrder::bigEndianInt ((char*) sampleRateBytes + 2);
  15204. sampRate >>= (16414 - ByteOrder::bigEndianShort ((char*) sampleRateBytes));
  15205. sampleRate = (int) sampRate;
  15206. if (length <= 18)
  15207. {
  15208. // some types don't have a chunk large enough to include a compression
  15209. // type, so assume it's just big-endian pcm
  15210. littleEndian = false;
  15211. }
  15212. else
  15213. {
  15214. const int compType = input->readInt();
  15215. if (compType == chunkName ("NONE") || compType == chunkName ("twos"))
  15216. {
  15217. littleEndian = false;
  15218. }
  15219. else if (compType == chunkName ("sowt"))
  15220. {
  15221. littleEndian = true;
  15222. }
  15223. else
  15224. {
  15225. sampleRate = 0;
  15226. break;
  15227. }
  15228. }
  15229. }
  15230. else if (type == chunkName ("SSND"))
  15231. {
  15232. hasGotData = true;
  15233. const int offset = input->readIntBigEndian();
  15234. dataChunkStart = input->getPosition() + 4 + offset;
  15235. lengthInSamples = (bytesPerFrame > 0) ? jmin (lengthInSamples, (int64) (length / bytesPerFrame)) : 0;
  15236. }
  15237. else if ((hasGotVer && hasGotData && hasGotType)
  15238. || chunkEnd < input->getPosition()
  15239. || input->isExhausted())
  15240. {
  15241. break;
  15242. }
  15243. input->setPosition (chunkEnd);
  15244. }
  15245. }
  15246. }
  15247. }
  15248. ~AiffAudioFormatReader()
  15249. {
  15250. }
  15251. bool readSamples (int** destSamples, int numDestChannels, int startOffsetInDestBuffer,
  15252. int64 startSampleInFile, int numSamples)
  15253. {
  15254. const int64 samplesAvailable = lengthInSamples - startSampleInFile;
  15255. if (samplesAvailable < numSamples)
  15256. {
  15257. for (int i = numDestChannels; --i >= 0;)
  15258. if (destSamples[i] != 0)
  15259. zeromem (destSamples[i] + startOffsetInDestBuffer, sizeof (int) * numSamples);
  15260. numSamples = (int) samplesAvailable;
  15261. }
  15262. if (numSamples <= 0)
  15263. return true;
  15264. input->setPosition (dataChunkStart + startSampleInFile * bytesPerFrame);
  15265. const int tempBufSize = 480 * 3 * 4; // (keep this a multiple of 3)
  15266. char tempBuffer [tempBufSize];
  15267. while (numSamples > 0)
  15268. {
  15269. int* left = destSamples[0];
  15270. if (left != 0)
  15271. left += startOffsetInDestBuffer;
  15272. int* right = numDestChannels > 1 ? destSamples[1] : 0;
  15273. if (right != 0)
  15274. right += startOffsetInDestBuffer;
  15275. const int numThisTime = jmin (tempBufSize / bytesPerFrame, numSamples);
  15276. const int bytesRead = input->read (tempBuffer, numThisTime * bytesPerFrame);
  15277. if (bytesRead < numThisTime * bytesPerFrame)
  15278. zeromem (tempBuffer + bytesRead, numThisTime * bytesPerFrame - bytesRead);
  15279. if (bitsPerSample == 16)
  15280. {
  15281. if (littleEndian)
  15282. {
  15283. const short* src = (const short*) tempBuffer;
  15284. if (numChannels > 1)
  15285. {
  15286. if (left == 0)
  15287. {
  15288. for (int i = numThisTime; --i >= 0;)
  15289. {
  15290. *right++ = (int) ByteOrder::swapIfBigEndian ((unsigned short) *src++) << 16;
  15291. ++src;
  15292. }
  15293. }
  15294. else if (right == 0)
  15295. {
  15296. for (int i = numThisTime; --i >= 0;)
  15297. {
  15298. ++src;
  15299. *left++ = (int) ByteOrder::swapIfBigEndian ((unsigned short) *src++) << 16;
  15300. }
  15301. }
  15302. else
  15303. {
  15304. for (int i = numThisTime; --i >= 0;)
  15305. {
  15306. *left++ = (int) ByteOrder::swapIfBigEndian ((unsigned short) *src++) << 16;
  15307. *right++ = (int) ByteOrder::swapIfBigEndian ((unsigned short) *src++) << 16;
  15308. }
  15309. }
  15310. }
  15311. else
  15312. {
  15313. for (int i = numThisTime; --i >= 0;)
  15314. {
  15315. *left++ = (int) ByteOrder::swapIfBigEndian ((unsigned short) *src++) << 16;
  15316. }
  15317. }
  15318. }
  15319. else
  15320. {
  15321. const char* src = (const char*) tempBuffer;
  15322. if (numChannels > 1)
  15323. {
  15324. if (left == 0)
  15325. {
  15326. for (int i = numThisTime; --i >= 0;)
  15327. {
  15328. *right++ = ByteOrder::bigEndianShort (src) << 16;
  15329. src += 4;
  15330. }
  15331. }
  15332. else if (right == 0)
  15333. {
  15334. for (int i = numThisTime; --i >= 0;)
  15335. {
  15336. src += 2;
  15337. *left++ = ByteOrder::bigEndianShort (src) << 16;
  15338. src += 2;
  15339. }
  15340. }
  15341. else
  15342. {
  15343. for (int i = numThisTime; --i >= 0;)
  15344. {
  15345. *left++ = ByteOrder::bigEndianShort (src) << 16;
  15346. src += 2;
  15347. *right++ = ByteOrder::bigEndianShort (src) << 16;
  15348. src += 2;
  15349. }
  15350. }
  15351. }
  15352. else
  15353. {
  15354. for (int i = numThisTime; --i >= 0;)
  15355. {
  15356. *left++ = ByteOrder::bigEndianShort (src) << 16;
  15357. src += 2;
  15358. }
  15359. }
  15360. }
  15361. }
  15362. else if (bitsPerSample == 24)
  15363. {
  15364. const char* src = (const char*)tempBuffer;
  15365. if (littleEndian)
  15366. {
  15367. if (numChannels > 1)
  15368. {
  15369. if (left == 0)
  15370. {
  15371. for (int i = numThisTime; --i >= 0;)
  15372. {
  15373. *right++ = ByteOrder::littleEndian24Bit (src) << 8;
  15374. src += 6;
  15375. }
  15376. }
  15377. else if (right == 0)
  15378. {
  15379. for (int i = numThisTime; --i >= 0;)
  15380. {
  15381. src += 3;
  15382. *left++ = ByteOrder::littleEndian24Bit (src) << 8;
  15383. src += 3;
  15384. }
  15385. }
  15386. else
  15387. {
  15388. for (int i = numThisTime; --i >= 0;)
  15389. {
  15390. *left++ = ByteOrder::littleEndian24Bit (src) << 8;
  15391. src += 3;
  15392. *right++ = ByteOrder::littleEndian24Bit (src) << 8;
  15393. src += 3;
  15394. }
  15395. }
  15396. }
  15397. else
  15398. {
  15399. for (int i = numThisTime; --i >= 0;)
  15400. {
  15401. *left++ = ByteOrder::littleEndian24Bit (src) << 8;
  15402. src += 3;
  15403. }
  15404. }
  15405. }
  15406. else
  15407. {
  15408. if (numChannels > 1)
  15409. {
  15410. if (left == 0)
  15411. {
  15412. for (int i = numThisTime; --i >= 0;)
  15413. {
  15414. *right++ = ByteOrder::bigEndian24Bit (src) << 8;
  15415. src += 6;
  15416. }
  15417. }
  15418. else if (right == 0)
  15419. {
  15420. for (int i = numThisTime; --i >= 0;)
  15421. {
  15422. src += 3;
  15423. *left++ = ByteOrder::bigEndian24Bit (src) << 8;
  15424. src += 3;
  15425. }
  15426. }
  15427. else
  15428. {
  15429. for (int i = numThisTime; --i >= 0;)
  15430. {
  15431. *left++ = ByteOrder::bigEndian24Bit (src) << 8;
  15432. src += 3;
  15433. *right++ = ByteOrder::bigEndian24Bit (src) << 8;
  15434. src += 3;
  15435. }
  15436. }
  15437. }
  15438. else
  15439. {
  15440. for (int i = numThisTime; --i >= 0;)
  15441. {
  15442. *left++ = ByteOrder::bigEndian24Bit (src) << 8;
  15443. src += 3;
  15444. }
  15445. }
  15446. }
  15447. }
  15448. else if (bitsPerSample == 32)
  15449. {
  15450. const unsigned int* src = (const unsigned int*) tempBuffer;
  15451. unsigned int* l = (unsigned int*) left;
  15452. unsigned int* r = (unsigned int*) right;
  15453. if (littleEndian)
  15454. {
  15455. if (numChannels > 1)
  15456. {
  15457. if (l == 0)
  15458. {
  15459. for (int i = numThisTime; --i >= 0;)
  15460. {
  15461. ++src;
  15462. *r++ = ByteOrder::swapIfBigEndian (*src++);
  15463. }
  15464. }
  15465. else if (r == 0)
  15466. {
  15467. for (int i = numThisTime; --i >= 0;)
  15468. {
  15469. *l++ = ByteOrder::swapIfBigEndian (*src++);
  15470. ++src;
  15471. }
  15472. }
  15473. else
  15474. {
  15475. for (int i = numThisTime; --i >= 0;)
  15476. {
  15477. *l++ = ByteOrder::swapIfBigEndian (*src++);
  15478. *r++ = ByteOrder::swapIfBigEndian (*src++);
  15479. }
  15480. }
  15481. }
  15482. else
  15483. {
  15484. for (int i = numThisTime; --i >= 0;)
  15485. {
  15486. *l++ = ByteOrder::swapIfBigEndian (*src++);
  15487. }
  15488. }
  15489. }
  15490. else
  15491. {
  15492. if (numChannels > 1)
  15493. {
  15494. if (l == 0)
  15495. {
  15496. for (int i = numThisTime; --i >= 0;)
  15497. {
  15498. ++src;
  15499. *r++ = ByteOrder::swapIfLittleEndian (*src++);
  15500. }
  15501. }
  15502. else if (r == 0)
  15503. {
  15504. for (int i = numThisTime; --i >= 0;)
  15505. {
  15506. *l++ = ByteOrder::swapIfLittleEndian (*src++);
  15507. ++src;
  15508. }
  15509. }
  15510. else
  15511. {
  15512. for (int i = numThisTime; --i >= 0;)
  15513. {
  15514. *l++ = ByteOrder::swapIfLittleEndian (*src++);
  15515. *r++ = ByteOrder::swapIfLittleEndian (*src++);
  15516. }
  15517. }
  15518. }
  15519. else
  15520. {
  15521. for (int i = numThisTime; --i >= 0;)
  15522. {
  15523. *l++ = ByteOrder::swapIfLittleEndian (*src++);
  15524. }
  15525. }
  15526. }
  15527. left = (int*) l;
  15528. right = (int*) r;
  15529. }
  15530. else if (bitsPerSample == 8)
  15531. {
  15532. const char* src = (const char*) tempBuffer;
  15533. if (numChannels > 1)
  15534. {
  15535. if (left == 0)
  15536. {
  15537. for (int i = numThisTime; --i >= 0;)
  15538. {
  15539. *right++ = ((int) *src++) << 24;
  15540. ++src;
  15541. }
  15542. }
  15543. else if (right == 0)
  15544. {
  15545. for (int i = numThisTime; --i >= 0;)
  15546. {
  15547. ++src;
  15548. *left++ = ((int) *src++) << 24;
  15549. }
  15550. }
  15551. else
  15552. {
  15553. for (int i = numThisTime; --i >= 0;)
  15554. {
  15555. *left++ = ((int) *src++) << 24;
  15556. *right++ = ((int) *src++) << 24;
  15557. }
  15558. }
  15559. }
  15560. else
  15561. {
  15562. for (int i = numThisTime; --i >= 0;)
  15563. {
  15564. *left++ = ((int) *src++) << 24;
  15565. }
  15566. }
  15567. }
  15568. startOffsetInDestBuffer += numThisTime;
  15569. numSamples -= numThisTime;
  15570. }
  15571. if (numSamples > 0)
  15572. {
  15573. for (int i = numDestChannels; --i >= 0;)
  15574. if (destSamples[i] != 0)
  15575. zeromem (destSamples[i] + startOffsetInDestBuffer,
  15576. sizeof (int) * numSamples);
  15577. }
  15578. return true;
  15579. }
  15580. juce_UseDebuggingNewOperator
  15581. private:
  15582. AiffAudioFormatReader (const AiffAudioFormatReader&);
  15583. const AiffAudioFormatReader& operator= (const AiffAudioFormatReader&);
  15584. static inline int chunkName (const char* const name) { return (int) ByteOrder::littleEndianInt (name); }
  15585. };
  15586. class AiffAudioFormatWriter : public AudioFormatWriter
  15587. {
  15588. MemoryBlock tempBlock;
  15589. uint32 lengthInSamples, bytesWritten;
  15590. int64 headerPosition;
  15591. bool writeFailed;
  15592. static inline int chunkName (const char* const name) { return (int) ByteOrder::littleEndianInt (name); }
  15593. AiffAudioFormatWriter (const AiffAudioFormatWriter&);
  15594. const AiffAudioFormatWriter& operator= (const AiffAudioFormatWriter&);
  15595. void writeHeader()
  15596. {
  15597. const bool couldSeekOk = output->setPosition (headerPosition);
  15598. (void) couldSeekOk;
  15599. // if this fails, you've given it an output stream that can't seek! It needs
  15600. // to be able to seek back to write the header
  15601. jassert (couldSeekOk);
  15602. const int headerLen = 54;
  15603. int audioBytes = lengthInSamples * ((bitsPerSample * numChannels) / 8);
  15604. audioBytes += (audioBytes & 1);
  15605. output->writeInt (chunkName ("FORM"));
  15606. output->writeIntBigEndian (headerLen + audioBytes - 8);
  15607. output->writeInt (chunkName ("AIFF"));
  15608. output->writeInt (chunkName ("COMM"));
  15609. output->writeIntBigEndian (18);
  15610. output->writeShortBigEndian ((short) numChannels);
  15611. output->writeIntBigEndian (lengthInSamples);
  15612. output->writeShortBigEndian ((short) bitsPerSample);
  15613. uint8 sampleRateBytes[10];
  15614. zeromem (sampleRateBytes, 10);
  15615. if (sampleRate <= 1)
  15616. {
  15617. sampleRateBytes[0] = 0x3f;
  15618. sampleRateBytes[1] = 0xff;
  15619. sampleRateBytes[2] = 0x80;
  15620. }
  15621. else
  15622. {
  15623. int mask = 0x40000000;
  15624. sampleRateBytes[0] = 0x40;
  15625. if (sampleRate >= mask)
  15626. {
  15627. jassertfalse
  15628. sampleRateBytes[1] = 0x1d;
  15629. }
  15630. else
  15631. {
  15632. int n = (int) sampleRate;
  15633. int i;
  15634. for (i = 0; i <= 32 ; ++i)
  15635. {
  15636. if ((n & mask) != 0)
  15637. break;
  15638. mask >>= 1;
  15639. }
  15640. n = n << (i + 1);
  15641. sampleRateBytes[1] = (uint8) (29 - i);
  15642. sampleRateBytes[2] = (uint8) ((n >> 24) & 0xff);
  15643. sampleRateBytes[3] = (uint8) ((n >> 16) & 0xff);
  15644. sampleRateBytes[4] = (uint8) ((n >> 8) & 0xff);
  15645. sampleRateBytes[5] = (uint8) (n & 0xff);
  15646. }
  15647. }
  15648. output->write (sampleRateBytes, 10);
  15649. output->writeInt (chunkName ("SSND"));
  15650. output->writeIntBigEndian (audioBytes + 8);
  15651. output->writeInt (0);
  15652. output->writeInt (0);
  15653. jassert (output->getPosition() == headerLen);
  15654. }
  15655. public:
  15656. AiffAudioFormatWriter (OutputStream* out,
  15657. const double sampleRate_,
  15658. const unsigned int chans,
  15659. const int bits)
  15660. : AudioFormatWriter (out,
  15661. TRANS (aiffFormatName),
  15662. sampleRate_,
  15663. chans,
  15664. bits),
  15665. lengthInSamples (0),
  15666. bytesWritten (0),
  15667. writeFailed (false)
  15668. {
  15669. headerPosition = out->getPosition();
  15670. writeHeader();
  15671. }
  15672. ~AiffAudioFormatWriter()
  15673. {
  15674. if ((bytesWritten & 1) != 0)
  15675. output->writeByte (0);
  15676. writeHeader();
  15677. }
  15678. bool write (const int** data, int numSamples)
  15679. {
  15680. if (writeFailed)
  15681. return false;
  15682. const int bytes = numChannels * numSamples * bitsPerSample / 8;
  15683. tempBlock.ensureSize (bytes, false);
  15684. char* buffer = (char*) tempBlock.getData();
  15685. const int* left = data[0];
  15686. const int* right = data[1];
  15687. if (right == 0)
  15688. right = left;
  15689. if (bitsPerSample == 16)
  15690. {
  15691. short* b = (short*) buffer;
  15692. if (numChannels > 1)
  15693. {
  15694. for (int i = numSamples; --i >= 0;)
  15695. {
  15696. *b++ = (short) ByteOrder::swapIfLittleEndian ((uint16) (*left++ >> 16));
  15697. *b++ = (short) ByteOrder::swapIfLittleEndian ((uint16) (*right++ >> 16));
  15698. }
  15699. }
  15700. else
  15701. {
  15702. for (int i = numSamples; --i >= 0;)
  15703. {
  15704. *b++ = (short) ByteOrder::swapIfLittleEndian ((uint16) (*left++ >> 16));
  15705. }
  15706. }
  15707. }
  15708. else if (bitsPerSample == 24)
  15709. {
  15710. char* b = (char*) buffer;
  15711. if (numChannels > 1)
  15712. {
  15713. for (int i = numSamples; --i >= 0;)
  15714. {
  15715. ByteOrder::bigEndian24BitToChars (*left++ >> 8, b);
  15716. b += 3;
  15717. ByteOrder::bigEndian24BitToChars (*right++ >> 8, b);
  15718. b += 3;
  15719. }
  15720. }
  15721. else
  15722. {
  15723. for (int i = numSamples; --i >= 0;)
  15724. {
  15725. ByteOrder::bigEndian24BitToChars (*left++ >> 8, b);
  15726. b += 3;
  15727. }
  15728. }
  15729. }
  15730. else if (bitsPerSample == 32)
  15731. {
  15732. uint32* b = (uint32*) buffer;
  15733. if (numChannels > 1)
  15734. {
  15735. for (int i = numSamples; --i >= 0;)
  15736. {
  15737. *b++ = ByteOrder::swapIfLittleEndian ((uint32) *left++);
  15738. *b++ = ByteOrder::swapIfLittleEndian ((uint32) *right++);
  15739. }
  15740. }
  15741. else
  15742. {
  15743. for (int i = numSamples; --i >= 0;)
  15744. {
  15745. *b++ = ByteOrder::swapIfLittleEndian ((uint32) *left++);
  15746. }
  15747. }
  15748. }
  15749. else if (bitsPerSample == 8)
  15750. {
  15751. char* b = (char*) buffer;
  15752. if (numChannels > 1)
  15753. {
  15754. for (int i = numSamples; --i >= 0;)
  15755. {
  15756. *b++ = (char) (*left++ >> 24);
  15757. *b++ = (char) (*right++ >> 24);
  15758. }
  15759. }
  15760. else
  15761. {
  15762. for (int i = numSamples; --i >= 0;)
  15763. {
  15764. *b++ = (char) (*left++ >> 24);
  15765. }
  15766. }
  15767. }
  15768. if (bytesWritten + bytes >= (uint32) 0xfff00000
  15769. || ! output->write (buffer, bytes))
  15770. {
  15771. // failed to write to disk, so let's try writing the header.
  15772. // If it's just run out of disk space, then if it does manage
  15773. // to write the header, we'll still have a useable file..
  15774. writeHeader();
  15775. writeFailed = true;
  15776. return false;
  15777. }
  15778. else
  15779. {
  15780. bytesWritten += bytes;
  15781. lengthInSamples += numSamples;
  15782. return true;
  15783. }
  15784. }
  15785. juce_UseDebuggingNewOperator
  15786. };
  15787. AiffAudioFormat::AiffAudioFormat()
  15788. : AudioFormat (TRANS (aiffFormatName), (const tchar**) aiffExtensions)
  15789. {
  15790. }
  15791. AiffAudioFormat::~AiffAudioFormat()
  15792. {
  15793. }
  15794. const Array <int> AiffAudioFormat::getPossibleSampleRates()
  15795. {
  15796. const int rates[] = { 22050, 32000, 44100, 48000, 88200, 96000, 176400, 192000, 0 };
  15797. return Array <int> (rates);
  15798. }
  15799. const Array <int> AiffAudioFormat::getPossibleBitDepths()
  15800. {
  15801. const int depths[] = { 8, 16, 24, 0 };
  15802. return Array <int> (depths);
  15803. }
  15804. bool AiffAudioFormat::canDoStereo()
  15805. {
  15806. return true;
  15807. }
  15808. bool AiffAudioFormat::canDoMono()
  15809. {
  15810. return true;
  15811. }
  15812. #if JUCE_MAC
  15813. bool AiffAudioFormat::canHandleFile (const File& f)
  15814. {
  15815. if (AudioFormat::canHandleFile (f))
  15816. return true;
  15817. const OSType type = PlatformUtilities::getTypeOfFile (f.getFullPathName());
  15818. return type == 'AIFF' || type == 'AIFC'
  15819. || type == 'aiff' || type == 'aifc';
  15820. }
  15821. #endif
  15822. AudioFormatReader* AiffAudioFormat::createReaderFor (InputStream* sourceStream,
  15823. const bool deleteStreamIfOpeningFails)
  15824. {
  15825. ScopedPointer <AiffAudioFormatReader> w (new AiffAudioFormatReader (sourceStream));
  15826. if (w->sampleRate != 0)
  15827. return w.release();
  15828. if (! deleteStreamIfOpeningFails)
  15829. w->input = 0;
  15830. return 0;
  15831. }
  15832. AudioFormatWriter* AiffAudioFormat::createWriterFor (OutputStream* out,
  15833. double sampleRate,
  15834. unsigned int chans,
  15835. int bitsPerSample,
  15836. const StringPairArray& /*metadataValues*/,
  15837. int /*qualityOptionIndex*/)
  15838. {
  15839. if (getPossibleBitDepths().contains (bitsPerSample))
  15840. {
  15841. return new AiffAudioFormatWriter (out,
  15842. sampleRate,
  15843. chans,
  15844. bitsPerSample);
  15845. }
  15846. return 0;
  15847. }
  15848. END_JUCE_NAMESPACE
  15849. /********* End of inlined file: juce_AiffAudioFormat.cpp *********/
  15850. /********* Start of inlined file: juce_AudioCDReader.cpp *********/
  15851. BEGIN_JUCE_NAMESPACE
  15852. #if JUCE_MAC && JUCE_USE_CDREADER
  15853. // Mac version doesn't need any native code because it's all done with files..
  15854. // Windows + Linux versions are in the platform-dependent code sections.
  15855. static void findCDs (Array<File>& cds)
  15856. {
  15857. File volumes ("/Volumes");
  15858. volumes.findChildFiles (cds, File::findDirectories, false);
  15859. for (int i = cds.size(); --i >= 0;)
  15860. if (! cds.getReference(i).getChildFile (".TOC.plist").exists())
  15861. cds.remove (i);
  15862. }
  15863. const StringArray AudioCDReader::getAvailableCDNames()
  15864. {
  15865. Array<File> cds;
  15866. findCDs (cds);
  15867. StringArray names;
  15868. for (int i = 0; i < cds.size(); ++i)
  15869. names.add (cds.getReference(i).getFileName());
  15870. return names;
  15871. }
  15872. AudioCDReader* AudioCDReader::createReaderForCD (const int index)
  15873. {
  15874. Array<File> cds;
  15875. findCDs (cds);
  15876. if (cds[index] != File::nonexistent)
  15877. return new AudioCDReader (cds[index]);
  15878. else
  15879. return 0;
  15880. }
  15881. AudioCDReader::AudioCDReader (const File& volume)
  15882. : AudioFormatReader (0, "CD Audio"),
  15883. volumeDir (volume),
  15884. currentReaderTrack (-1),
  15885. reader (0)
  15886. {
  15887. sampleRate = 44100.0;
  15888. bitsPerSample = 16;
  15889. numChannels = 2;
  15890. usesFloatingPointData = false;
  15891. refreshTrackLengths();
  15892. }
  15893. AudioCDReader::~AudioCDReader()
  15894. {
  15895. }
  15896. static int getTrackNumber (const File& file)
  15897. {
  15898. return file.getFileName()
  15899. .initialSectionContainingOnly (T("0123456789"))
  15900. .getIntValue();
  15901. }
  15902. int AudioCDReader::compareElements (const File& first, const File& second)
  15903. {
  15904. const int firstTrack = getTrackNumber (first);
  15905. const int secondTrack = getTrackNumber (second);
  15906. jassert (firstTrack > 0 && secondTrack > 0);
  15907. return firstTrack - secondTrack;
  15908. }
  15909. void AudioCDReader::refreshTrackLengths()
  15910. {
  15911. tracks.clear();
  15912. trackStartSamples.clear();
  15913. volumeDir.findChildFiles (tracks, File::findFiles | File::ignoreHiddenFiles, false, T("*.aiff"));
  15914. tracks.sort (*this);
  15915. AiffAudioFormat format;
  15916. int sample = 0;
  15917. for (int i = 0; i < tracks.size(); ++i)
  15918. {
  15919. trackStartSamples.add (sample);
  15920. FileInputStream* const in = tracks.getReference(i).createInputStream();
  15921. if (in != 0)
  15922. {
  15923. ScopedPointer <AudioFormatReader> r (format.createReaderFor (in, true));
  15924. if (r != 0)
  15925. sample += (int) r->lengthInSamples;
  15926. }
  15927. }
  15928. trackStartSamples.add (sample);
  15929. lengthInSamples = sample;
  15930. }
  15931. bool AudioCDReader::readSamples (int** destSamples, int numDestChannels, int startOffsetInDestBuffer,
  15932. int64 startSampleInFile, int numSamples)
  15933. {
  15934. while (numSamples > 0)
  15935. {
  15936. int track = -1;
  15937. for (int i = 0; i < trackStartSamples.size() - 1; ++i)
  15938. {
  15939. if (startSampleInFile < trackStartSamples.getUnchecked (i + 1))
  15940. {
  15941. track = i;
  15942. break;
  15943. }
  15944. }
  15945. if (track < 0)
  15946. return false;
  15947. if (track != currentReaderTrack)
  15948. {
  15949. reader = 0;
  15950. FileInputStream* const in = tracks [track].createInputStream();
  15951. if (in != 0)
  15952. {
  15953. BufferedInputStream* const bin = new BufferedInputStream (in, 65536, true);
  15954. AiffAudioFormat format;
  15955. reader = format.createReaderFor (bin, true);
  15956. if (reader == 0)
  15957. currentReaderTrack = -1;
  15958. else
  15959. currentReaderTrack = track;
  15960. }
  15961. }
  15962. if (reader == 0)
  15963. return false;
  15964. const int startPos = (int) (startSampleInFile - trackStartSamples.getUnchecked (track));
  15965. const int numAvailable = (int) jmin ((int64) numSamples, reader->lengthInSamples - startPos);
  15966. reader->readSamples (destSamples, numDestChannels, startOffsetInDestBuffer, startPos, numAvailable);
  15967. numSamples -= numAvailable;
  15968. startSampleInFile += numAvailable;
  15969. }
  15970. return true;
  15971. }
  15972. bool AudioCDReader::isCDStillPresent() const
  15973. {
  15974. return volumeDir.exists();
  15975. }
  15976. int AudioCDReader::getNumTracks() const
  15977. {
  15978. return tracks.size();
  15979. }
  15980. int AudioCDReader::getPositionOfTrackStart (int trackNum) const
  15981. {
  15982. return trackStartSamples [trackNum];
  15983. }
  15984. bool AudioCDReader::isTrackAudio (int trackNum) const
  15985. {
  15986. return tracks [trackNum] != File::nonexistent;
  15987. }
  15988. void AudioCDReader::enableIndexScanning (bool b)
  15989. {
  15990. // any way to do this on a Mac??
  15991. }
  15992. int AudioCDReader::getLastIndex() const
  15993. {
  15994. return 0;
  15995. }
  15996. const Array <int> AudioCDReader::findIndexesInTrack (const int trackNumber)
  15997. {
  15998. return Array <int>();
  15999. }
  16000. int AudioCDReader::getCDDBId()
  16001. {
  16002. return 0; //xxx
  16003. }
  16004. #endif
  16005. END_JUCE_NAMESPACE
  16006. /********* End of inlined file: juce_AudioCDReader.cpp *********/
  16007. /********* Start of inlined file: juce_AudioFormat.cpp *********/
  16008. BEGIN_JUCE_NAMESPACE
  16009. AudioFormatReader::AudioFormatReader (InputStream* const in,
  16010. const String& formatName_)
  16011. : sampleRate (0),
  16012. bitsPerSample (0),
  16013. lengthInSamples (0),
  16014. numChannels (0),
  16015. usesFloatingPointData (false),
  16016. input (in),
  16017. formatName (formatName_)
  16018. {
  16019. }
  16020. AudioFormatReader::~AudioFormatReader()
  16021. {
  16022. delete input;
  16023. }
  16024. bool AudioFormatReader::read (int** destSamples,
  16025. int numDestChannels,
  16026. int64 startSampleInSource,
  16027. int numSamplesToRead,
  16028. const bool fillLeftoverChannelsWithCopies)
  16029. {
  16030. jassert (numDestChannels > 0); // you have to actually give this some channels to work with!
  16031. int startOffsetInDestBuffer = 0;
  16032. if (startSampleInSource < 0)
  16033. {
  16034. const int silence = (int) jmin (-startSampleInSource, (int64) numSamplesToRead);
  16035. for (int i = numDestChannels; --i >= 0;)
  16036. if (destSamples[i] != 0)
  16037. zeromem (destSamples[i], sizeof (int) * silence);
  16038. startOffsetInDestBuffer += silence;
  16039. numSamplesToRead -= silence;
  16040. startSampleInSource = 0;
  16041. }
  16042. if (numSamplesToRead <= 0)
  16043. return true;
  16044. if (! readSamples (destSamples, jmin ((int) numChannels, numDestChannels), startOffsetInDestBuffer,
  16045. startSampleInSource, numSamplesToRead))
  16046. return false;
  16047. if (numDestChannels > (int) numChannels)
  16048. {
  16049. if (fillLeftoverChannelsWithCopies)
  16050. {
  16051. int* lastFullChannel = destSamples[0];
  16052. for (int i = numDestChannels; --i > 0;)
  16053. {
  16054. if (destSamples[i] != 0)
  16055. {
  16056. lastFullChannel = destSamples[i];
  16057. break;
  16058. }
  16059. }
  16060. if (lastFullChannel != 0)
  16061. for (int i = numChannels; i < numDestChannels; ++i)
  16062. if (destSamples[i] != 0)
  16063. memcpy (destSamples[i], lastFullChannel, sizeof (int) * numSamplesToRead);
  16064. }
  16065. else
  16066. {
  16067. for (int i = numChannels; i < numDestChannels; ++i)
  16068. if (destSamples[i] != 0)
  16069. zeromem (destSamples[i], sizeof (int) * numSamplesToRead);
  16070. }
  16071. }
  16072. return true;
  16073. }
  16074. static void findMaxMin (const float* src, const int num,
  16075. float& maxVal, float& minVal)
  16076. {
  16077. float mn = src[0];
  16078. float mx = mn;
  16079. for (int i = 1; i < num; ++i)
  16080. {
  16081. const float s = src[i];
  16082. if (s > mx)
  16083. mx = s;
  16084. if (s < mn)
  16085. mn = s;
  16086. }
  16087. maxVal = mx;
  16088. minVal = mn;
  16089. }
  16090. void AudioFormatReader::readMaxLevels (int64 startSampleInFile,
  16091. int64 numSamples,
  16092. float& lowestLeft, float& highestLeft,
  16093. float& lowestRight, float& highestRight)
  16094. {
  16095. if (numSamples <= 0)
  16096. {
  16097. lowestLeft = 0;
  16098. lowestRight = 0;
  16099. highestLeft = 0;
  16100. highestRight = 0;
  16101. return;
  16102. }
  16103. const int bufferSize = (int) jmin (numSamples, (int64) 4096);
  16104. MemoryBlock tempSpace (bufferSize * sizeof (int) * 2 + 64);
  16105. int* tempBuffer[3];
  16106. tempBuffer[0] = (int*) tempSpace.getData();
  16107. tempBuffer[1] = ((int*) tempSpace.getData()) + bufferSize;
  16108. tempBuffer[2] = 0;
  16109. if (usesFloatingPointData)
  16110. {
  16111. float lmin = 1.0e6f;
  16112. float lmax = -lmin;
  16113. float rmin = lmin;
  16114. float rmax = lmax;
  16115. while (numSamples > 0)
  16116. {
  16117. const int numToDo = (int) jmin (numSamples, (int64) bufferSize);
  16118. read ((int**) tempBuffer, 2, startSampleInFile, numToDo, false);
  16119. numSamples -= numToDo;
  16120. startSampleInFile += numToDo;
  16121. float bufmin, bufmax;
  16122. findMaxMin ((float*) tempBuffer[0], numToDo, bufmax, bufmin);
  16123. lmin = jmin (lmin, bufmin);
  16124. lmax = jmax (lmax, bufmax);
  16125. if (numChannels > 1)
  16126. {
  16127. findMaxMin ((float*) tempBuffer[1], numToDo, bufmax, bufmin);
  16128. rmin = jmin (rmin, bufmin);
  16129. rmax = jmax (rmax, bufmax);
  16130. }
  16131. }
  16132. if (numChannels <= 1)
  16133. {
  16134. rmax = lmax;
  16135. rmin = lmin;
  16136. }
  16137. lowestLeft = lmin;
  16138. highestLeft = lmax;
  16139. lowestRight = rmin;
  16140. highestRight = rmax;
  16141. }
  16142. else
  16143. {
  16144. int lmax = INT_MIN;
  16145. int lmin = INT_MAX;
  16146. int rmax = INT_MIN;
  16147. int rmin = INT_MAX;
  16148. while (numSamples > 0)
  16149. {
  16150. const int numToDo = (int) jmin (numSamples, (int64) bufferSize);
  16151. read ((int**) tempBuffer, 2, startSampleInFile, numToDo, false);
  16152. numSamples -= numToDo;
  16153. startSampleInFile += numToDo;
  16154. for (int j = numChannels; --j >= 0;)
  16155. {
  16156. int bufMax = INT_MIN;
  16157. int bufMin = INT_MAX;
  16158. const int* const b = tempBuffer[j];
  16159. for (int i = 0; i < numToDo; ++i)
  16160. {
  16161. const int samp = b[i];
  16162. if (samp < bufMin)
  16163. bufMin = samp;
  16164. if (samp > bufMax)
  16165. bufMax = samp;
  16166. }
  16167. if (j == 0)
  16168. {
  16169. lmax = jmax (lmax, bufMax);
  16170. lmin = jmin (lmin, bufMin);
  16171. }
  16172. else
  16173. {
  16174. rmax = jmax (rmax, bufMax);
  16175. rmin = jmin (rmin, bufMin);
  16176. }
  16177. }
  16178. }
  16179. if (numChannels <= 1)
  16180. {
  16181. rmax = lmax;
  16182. rmin = lmin;
  16183. }
  16184. lowestLeft = lmin / (float)INT_MAX;
  16185. highestLeft = lmax / (float)INT_MAX;
  16186. lowestRight = rmin / (float)INT_MAX;
  16187. highestRight = rmax / (float)INT_MAX;
  16188. }
  16189. }
  16190. int64 AudioFormatReader::searchForLevel (int64 startSample,
  16191. int64 numSamplesToSearch,
  16192. const double magnitudeRangeMinimum,
  16193. const double magnitudeRangeMaximum,
  16194. const int minimumConsecutiveSamples)
  16195. {
  16196. if (numSamplesToSearch == 0)
  16197. return -1;
  16198. const int bufferSize = 4096;
  16199. MemoryBlock tempSpace (bufferSize * sizeof (int) * 2 + 64);
  16200. int* tempBuffer[3];
  16201. tempBuffer[0] = (int*) tempSpace.getData();
  16202. tempBuffer[1] = ((int*) tempSpace.getData()) + bufferSize;
  16203. tempBuffer[2] = 0;
  16204. int consecutive = 0;
  16205. int64 firstMatchPos = -1;
  16206. jassert (magnitudeRangeMaximum > magnitudeRangeMinimum);
  16207. const double doubleMin = jlimit (0.0, (double) INT_MAX, magnitudeRangeMinimum * INT_MAX);
  16208. const double doubleMax = jlimit (doubleMin, (double) INT_MAX, magnitudeRangeMaximum * INT_MAX);
  16209. const int intMagnitudeRangeMinimum = roundToInt (doubleMin);
  16210. const int intMagnitudeRangeMaximum = roundToInt (doubleMax);
  16211. while (numSamplesToSearch != 0)
  16212. {
  16213. const int numThisTime = (int) jmin (abs64 (numSamplesToSearch), (int64) bufferSize);
  16214. int64 bufferStart = startSample;
  16215. if (numSamplesToSearch < 0)
  16216. bufferStart -= numThisTime;
  16217. if (bufferStart >= (int) lengthInSamples)
  16218. break;
  16219. read ((int**) tempBuffer, 2, bufferStart, numThisTime, false);
  16220. int num = numThisTime;
  16221. while (--num >= 0)
  16222. {
  16223. if (numSamplesToSearch < 0)
  16224. --startSample;
  16225. bool matches = false;
  16226. const int index = (int) (startSample - bufferStart);
  16227. if (usesFloatingPointData)
  16228. {
  16229. const float sample1 = fabsf (((float*) tempBuffer[0]) [index]);
  16230. if (sample1 >= magnitudeRangeMinimum
  16231. && sample1 <= magnitudeRangeMaximum)
  16232. {
  16233. matches = true;
  16234. }
  16235. else if (numChannels > 1)
  16236. {
  16237. const float sample2 = fabsf (((float*) tempBuffer[1]) [index]);
  16238. matches = (sample2 >= magnitudeRangeMinimum
  16239. && sample2 <= magnitudeRangeMaximum);
  16240. }
  16241. }
  16242. else
  16243. {
  16244. const int sample1 = abs (tempBuffer[0] [index]);
  16245. if (sample1 >= intMagnitudeRangeMinimum
  16246. && sample1 <= intMagnitudeRangeMaximum)
  16247. {
  16248. matches = true;
  16249. }
  16250. else if (numChannels > 1)
  16251. {
  16252. const int sample2 = abs (tempBuffer[1][index]);
  16253. matches = (sample2 >= intMagnitudeRangeMinimum
  16254. && sample2 <= intMagnitudeRangeMaximum);
  16255. }
  16256. }
  16257. if (matches)
  16258. {
  16259. if (firstMatchPos < 0)
  16260. firstMatchPos = startSample;
  16261. if (++consecutive >= minimumConsecutiveSamples)
  16262. {
  16263. if (firstMatchPos < 0 || firstMatchPos >= lengthInSamples)
  16264. return -1;
  16265. return firstMatchPos;
  16266. }
  16267. }
  16268. else
  16269. {
  16270. consecutive = 0;
  16271. firstMatchPos = -1;
  16272. }
  16273. if (numSamplesToSearch > 0)
  16274. ++startSample;
  16275. }
  16276. if (numSamplesToSearch > 0)
  16277. numSamplesToSearch -= numThisTime;
  16278. else
  16279. numSamplesToSearch += numThisTime;
  16280. }
  16281. return -1;
  16282. }
  16283. AudioFormatWriter::AudioFormatWriter (OutputStream* const out,
  16284. const String& formatName_,
  16285. const double rate,
  16286. const unsigned int numChannels_,
  16287. const unsigned int bitsPerSample_)
  16288. : sampleRate (rate),
  16289. numChannels (numChannels_),
  16290. bitsPerSample (bitsPerSample_),
  16291. usesFloatingPointData (false),
  16292. output (out),
  16293. formatName (formatName_)
  16294. {
  16295. }
  16296. AudioFormatWriter::~AudioFormatWriter()
  16297. {
  16298. delete output;
  16299. }
  16300. bool AudioFormatWriter::writeFromAudioReader (AudioFormatReader& reader,
  16301. int64 startSample,
  16302. int64 numSamplesToRead)
  16303. {
  16304. const int bufferSize = 16384;
  16305. const int maxChans = 128;
  16306. AudioSampleBuffer tempBuffer (reader.numChannels, bufferSize);
  16307. int* buffers [maxChans];
  16308. for (int i = maxChans; --i >= 0;)
  16309. buffers[i] = 0;
  16310. if (numSamplesToRead < 0)
  16311. numSamplesToRead = reader.lengthInSamples;
  16312. while (numSamplesToRead > 0)
  16313. {
  16314. const int numToDo = (int) jmin (numSamplesToRead, (int64) bufferSize);
  16315. for (int i = tempBuffer.getNumChannels(); --i >= 0;)
  16316. buffers[i] = (int*) tempBuffer.getSampleData (i, 0);
  16317. if (! reader.read (buffers, maxChans, startSample, numToDo, false))
  16318. return false;
  16319. if (reader.usesFloatingPointData != isFloatingPoint())
  16320. {
  16321. int** bufferChan = buffers;
  16322. while (*bufferChan != 0)
  16323. {
  16324. int* b = *bufferChan++;
  16325. if (isFloatingPoint())
  16326. {
  16327. // int -> float
  16328. const double factor = 1.0 / INT_MAX;
  16329. for (int i = 0; i < numToDo; ++i)
  16330. ((float*)b)[i] = (float) (factor * b[i]);
  16331. }
  16332. else
  16333. {
  16334. // float -> int
  16335. for (int i = 0; i < numToDo; ++i)
  16336. {
  16337. const double samp = *(const float*) b;
  16338. if (samp <= -1.0)
  16339. *b++ = INT_MIN;
  16340. else if (samp >= 1.0)
  16341. *b++ = INT_MAX;
  16342. else
  16343. *b++ = roundToInt (INT_MAX * samp);
  16344. }
  16345. }
  16346. }
  16347. }
  16348. if (! write ((const int**) buffers, numToDo))
  16349. return false;
  16350. numSamplesToRead -= numToDo;
  16351. startSample += numToDo;
  16352. }
  16353. return true;
  16354. }
  16355. bool AudioFormatWriter::writeFromAudioSource (AudioSource& source,
  16356. int numSamplesToRead,
  16357. const int samplesPerBlock)
  16358. {
  16359. const int maxChans = 128;
  16360. AudioSampleBuffer tempBuffer (getNumChannels(), samplesPerBlock);
  16361. int* buffers [maxChans];
  16362. while (numSamplesToRead > 0)
  16363. {
  16364. const int numToDo = jmin (numSamplesToRead, samplesPerBlock);
  16365. AudioSourceChannelInfo info;
  16366. info.buffer = &tempBuffer;
  16367. info.startSample = 0;
  16368. info.numSamples = numToDo;
  16369. info.clearActiveBufferRegion();
  16370. source.getNextAudioBlock (info);
  16371. int i;
  16372. for (i = maxChans; --i >= 0;)
  16373. buffers[i] = 0;
  16374. for (i = tempBuffer.getNumChannels(); --i >= 0;)
  16375. buffers[i] = (int*) tempBuffer.getSampleData (i, 0);
  16376. if (! isFloatingPoint())
  16377. {
  16378. int** bufferChan = buffers;
  16379. while (*bufferChan != 0)
  16380. {
  16381. int* b = *bufferChan++;
  16382. // float -> int
  16383. for (int j = numToDo; --j >= 0;)
  16384. {
  16385. const double samp = *(const float*) b;
  16386. if (samp <= -1.0)
  16387. *b++ = INT_MIN;
  16388. else if (samp >= 1.0)
  16389. *b++ = INT_MAX;
  16390. else
  16391. *b++ = roundToInt (INT_MAX * samp);
  16392. }
  16393. }
  16394. }
  16395. if (! write ((const int**) buffers, numToDo))
  16396. return false;
  16397. numSamplesToRead -= numToDo;
  16398. }
  16399. return true;
  16400. }
  16401. AudioFormat::AudioFormat (const String& name,
  16402. const tchar** const extensions)
  16403. : formatName (name),
  16404. fileExtensions (extensions)
  16405. {
  16406. }
  16407. AudioFormat::~AudioFormat()
  16408. {
  16409. }
  16410. const String& AudioFormat::getFormatName() const
  16411. {
  16412. return formatName;
  16413. }
  16414. const StringArray& AudioFormat::getFileExtensions() const
  16415. {
  16416. return fileExtensions;
  16417. }
  16418. bool AudioFormat::canHandleFile (const File& f)
  16419. {
  16420. for (int i = 0; i < fileExtensions.size(); ++i)
  16421. if (f.hasFileExtension (fileExtensions[i]))
  16422. return true;
  16423. return false;
  16424. }
  16425. bool AudioFormat::isCompressed()
  16426. {
  16427. return false;
  16428. }
  16429. const StringArray AudioFormat::getQualityOptions()
  16430. {
  16431. return StringArray();
  16432. }
  16433. END_JUCE_NAMESPACE
  16434. /********* End of inlined file: juce_AudioFormat.cpp *********/
  16435. /********* Start of inlined file: juce_AudioFormatManager.cpp *********/
  16436. BEGIN_JUCE_NAMESPACE
  16437. AudioFormatManager::AudioFormatManager()
  16438. : defaultFormatIndex (0)
  16439. {
  16440. }
  16441. AudioFormatManager::~AudioFormatManager()
  16442. {
  16443. clearFormats();
  16444. clearSingletonInstance();
  16445. }
  16446. juce_ImplementSingleton (AudioFormatManager);
  16447. void AudioFormatManager::registerFormat (AudioFormat* newFormat,
  16448. const bool makeThisTheDefaultFormat)
  16449. {
  16450. jassert (newFormat != 0);
  16451. if (newFormat != 0)
  16452. {
  16453. #ifdef JUCE_DEBUG
  16454. for (int i = getNumKnownFormats(); --i >= 0;)
  16455. {
  16456. if (getKnownFormat (i)->getFormatName() == newFormat->getFormatName())
  16457. {
  16458. jassertfalse // trying to add the same format twice!
  16459. }
  16460. }
  16461. #endif
  16462. if (makeThisTheDefaultFormat)
  16463. defaultFormatIndex = knownFormats.size();
  16464. knownFormats.add (newFormat);
  16465. }
  16466. }
  16467. void AudioFormatManager::registerBasicFormats()
  16468. {
  16469. #if JUCE_MAC
  16470. registerFormat (new AiffAudioFormat(), true);
  16471. registerFormat (new WavAudioFormat(), false);
  16472. #else
  16473. registerFormat (new WavAudioFormat(), true);
  16474. registerFormat (new AiffAudioFormat(), false);
  16475. #endif
  16476. #if JUCE_USE_FLAC
  16477. registerFormat (new FlacAudioFormat(), false);
  16478. #endif
  16479. #if JUCE_USE_OGGVORBIS
  16480. registerFormat (new OggVorbisAudioFormat(), false);
  16481. #endif
  16482. }
  16483. void AudioFormatManager::clearFormats()
  16484. {
  16485. for (int i = getNumKnownFormats(); --i >= 0;)
  16486. delete getKnownFormat(i);
  16487. knownFormats.clear();
  16488. defaultFormatIndex = 0;
  16489. }
  16490. int AudioFormatManager::getNumKnownFormats() const
  16491. {
  16492. return knownFormats.size();
  16493. }
  16494. AudioFormat* AudioFormatManager::getKnownFormat (const int index) const
  16495. {
  16496. return (AudioFormat*) knownFormats [index];
  16497. }
  16498. AudioFormat* AudioFormatManager::getDefaultFormat() const
  16499. {
  16500. return getKnownFormat (defaultFormatIndex);
  16501. }
  16502. AudioFormat* AudioFormatManager::findFormatForFileExtension (const String& fileExtension) const
  16503. {
  16504. String e (fileExtension);
  16505. if (! e.startsWithChar (T('.')))
  16506. e = T(".") + e;
  16507. for (int i = 0; i < getNumKnownFormats(); ++i)
  16508. if (getKnownFormat(i)->getFileExtensions().contains (e, true))
  16509. return getKnownFormat(i);
  16510. return 0;
  16511. }
  16512. const String AudioFormatManager::getWildcardForAllFormats() const
  16513. {
  16514. StringArray allExtensions;
  16515. int i;
  16516. for (i = 0; i < getNumKnownFormats(); ++i)
  16517. allExtensions.addArray (getKnownFormat (i)->getFileExtensions());
  16518. allExtensions.trim();
  16519. allExtensions.removeEmptyStrings();
  16520. String s;
  16521. for (i = 0; i < allExtensions.size(); ++i)
  16522. {
  16523. s << T('*');
  16524. if (! allExtensions[i].startsWithChar (T('.')))
  16525. s << T('.');
  16526. s << allExtensions[i];
  16527. if (i < allExtensions.size() - 1)
  16528. s << T(';');
  16529. }
  16530. return s;
  16531. }
  16532. AudioFormatReader* AudioFormatManager::createReaderFor (const File& file)
  16533. {
  16534. // you need to actually register some formats before the manager can
  16535. // use them to open a file!
  16536. jassert (knownFormats.size() > 0);
  16537. for (int i = 0; i < getNumKnownFormats(); ++i)
  16538. {
  16539. AudioFormat* const af = getKnownFormat(i);
  16540. if (af->canHandleFile (file))
  16541. {
  16542. InputStream* const in = file.createInputStream();
  16543. if (in != 0)
  16544. {
  16545. AudioFormatReader* const r = af->createReaderFor (in, true);
  16546. if (r != 0)
  16547. return r;
  16548. }
  16549. }
  16550. }
  16551. return 0;
  16552. }
  16553. AudioFormatReader* AudioFormatManager::createReaderFor (InputStream* audioFileStream)
  16554. {
  16555. // you need to actually register some formats before the manager can
  16556. // use them to open a file!
  16557. jassert (knownFormats.size() > 0);
  16558. ScopedPointer <InputStream> in (audioFileStream);
  16559. if (in != 0)
  16560. {
  16561. const int64 originalStreamPos = in->getPosition();
  16562. for (int i = 0; i < getNumKnownFormats(); ++i)
  16563. {
  16564. AudioFormatReader* const r = getKnownFormat(i)->createReaderFor (in, false);
  16565. if (r != 0)
  16566. {
  16567. in.release();
  16568. return r;
  16569. }
  16570. in->setPosition (originalStreamPos);
  16571. // the stream that is passed-in must be capable of being repositioned so
  16572. // that all the formats can have a go at opening it.
  16573. jassert (in->getPosition() == originalStreamPos);
  16574. }
  16575. }
  16576. return 0;
  16577. }
  16578. END_JUCE_NAMESPACE
  16579. /********* End of inlined file: juce_AudioFormatManager.cpp *********/
  16580. /********* Start of inlined file: juce_AudioSubsectionReader.cpp *********/
  16581. BEGIN_JUCE_NAMESPACE
  16582. AudioSubsectionReader::AudioSubsectionReader (AudioFormatReader* const source_,
  16583. const int64 startSample_,
  16584. const int64 length_,
  16585. const bool deleteSourceWhenDeleted_)
  16586. : AudioFormatReader (0, source_->getFormatName()),
  16587. source (source_),
  16588. startSample (startSample_),
  16589. deleteSourceWhenDeleted (deleteSourceWhenDeleted_)
  16590. {
  16591. length = jmin (jmax ((int64) 0, source->lengthInSamples - startSample), length_);
  16592. sampleRate = source->sampleRate;
  16593. bitsPerSample = source->bitsPerSample;
  16594. lengthInSamples = length;
  16595. numChannels = source->numChannels;
  16596. usesFloatingPointData = source->usesFloatingPointData;
  16597. }
  16598. AudioSubsectionReader::~AudioSubsectionReader()
  16599. {
  16600. if (deleteSourceWhenDeleted)
  16601. delete source;
  16602. }
  16603. bool AudioSubsectionReader::readSamples (int** destSamples, int numDestChannels, int startOffsetInDestBuffer,
  16604. int64 startSampleInFile, int numSamples)
  16605. {
  16606. if (startSampleInFile + numSamples > length)
  16607. {
  16608. for (int i = numDestChannels; --i >= 0;)
  16609. if (destSamples[i] != 0)
  16610. zeromem (destSamples[i], sizeof (int) * numSamples);
  16611. numSamples = jmin (numSamples, (int) (length - startSampleInFile));
  16612. if (numSamples <= 0)
  16613. return true;
  16614. }
  16615. return source->readSamples (destSamples, numDestChannels, startOffsetInDestBuffer,
  16616. startSampleInFile + startSample, numSamples);
  16617. }
  16618. void AudioSubsectionReader::readMaxLevels (int64 startSampleInFile,
  16619. int64 numSamples,
  16620. float& lowestLeft,
  16621. float& highestLeft,
  16622. float& lowestRight,
  16623. float& highestRight)
  16624. {
  16625. startSampleInFile = jmax ((int64) 0, startSampleInFile);
  16626. numSamples = jmax ((int64) 0, jmin (numSamples, length - startSampleInFile));
  16627. source->readMaxLevels (startSampleInFile + startSample,
  16628. numSamples,
  16629. lowestLeft,
  16630. highestLeft,
  16631. lowestRight,
  16632. highestRight);
  16633. }
  16634. END_JUCE_NAMESPACE
  16635. /********* End of inlined file: juce_AudioSubsectionReader.cpp *********/
  16636. /********* Start of inlined file: juce_AudioThumbnail.cpp *********/
  16637. BEGIN_JUCE_NAMESPACE
  16638. const int timeBeforeDeletingReader = 2000;
  16639. struct AudioThumbnailDataFormat
  16640. {
  16641. char thumbnailMagic[4];
  16642. int samplesPerThumbSample;
  16643. int64 totalSamples; // source samples
  16644. int64 numFinishedSamples; // source samples
  16645. int numThumbnailSamples;
  16646. int numChannels;
  16647. int sampleRate;
  16648. char future[16];
  16649. char data[1];
  16650. };
  16651. #if JUCE_BIG_ENDIAN
  16652. static void swap (int& n) { n = (int) ByteOrder::swap ((uint32) n); }
  16653. static void swap (int64& n) { n = (int64) ByteOrder::swap ((uint64) n); }
  16654. #endif
  16655. static void swapEndiannessIfNeeded (AudioThumbnailDataFormat* const d)
  16656. {
  16657. (void) d;
  16658. #if JUCE_BIG_ENDIAN
  16659. swap (d->samplesPerThumbSample);
  16660. swap (d->totalSamples);
  16661. swap (d->numFinishedSamples);
  16662. swap (d->numThumbnailSamples);
  16663. swap (d->numChannels);
  16664. swap (d->sampleRate);
  16665. #endif
  16666. }
  16667. AudioThumbnail::AudioThumbnail (const int orginalSamplesPerThumbnailSample_,
  16668. AudioFormatManager& formatManagerToUse_,
  16669. AudioThumbnailCache& cacheToUse)
  16670. : formatManagerToUse (formatManagerToUse_),
  16671. cache (cacheToUse),
  16672. orginalSamplesPerThumbnailSample (orginalSamplesPerThumbnailSample_)
  16673. {
  16674. clear();
  16675. }
  16676. AudioThumbnail::~AudioThumbnail()
  16677. {
  16678. cache.removeThumbnail (this);
  16679. const ScopedLock sl (readerLock);
  16680. reader = 0;
  16681. }
  16682. void AudioThumbnail::setSource (InputSource* const newSource)
  16683. {
  16684. cache.removeThumbnail (this);
  16685. timerCallback(); // stops the timer and deletes the reader
  16686. source = newSource;
  16687. clear();
  16688. if (newSource != 0
  16689. && ! (cache.loadThumb (*this, newSource->hashCode())
  16690. && isFullyLoaded()))
  16691. {
  16692. {
  16693. const ScopedLock sl (readerLock);
  16694. reader = createReader();
  16695. }
  16696. if (reader != 0)
  16697. {
  16698. initialiseFromAudioFile (*reader);
  16699. cache.addThumbnail (this);
  16700. }
  16701. }
  16702. sendChangeMessage (this);
  16703. }
  16704. bool AudioThumbnail::useTimeSlice()
  16705. {
  16706. const ScopedLock sl (readerLock);
  16707. if (isFullyLoaded())
  16708. {
  16709. if (reader != 0)
  16710. startTimer (timeBeforeDeletingReader);
  16711. cache.removeThumbnail (this);
  16712. return false;
  16713. }
  16714. if (reader == 0)
  16715. reader = createReader();
  16716. if (reader != 0)
  16717. {
  16718. readNextBlockFromAudioFile (*reader);
  16719. stopTimer();
  16720. sendChangeMessage (this);
  16721. const bool justFinished = isFullyLoaded();
  16722. if (justFinished)
  16723. cache.storeThumb (*this, source->hashCode());
  16724. return ! justFinished;
  16725. }
  16726. return false;
  16727. }
  16728. AudioFormatReader* AudioThumbnail::createReader() const
  16729. {
  16730. if (source != 0)
  16731. {
  16732. InputStream* const audioFileStream = source->createInputStream();
  16733. if (audioFileStream != 0)
  16734. return formatManagerToUse.createReaderFor (audioFileStream);
  16735. }
  16736. return 0;
  16737. }
  16738. void AudioThumbnail::timerCallback()
  16739. {
  16740. stopTimer();
  16741. const ScopedLock sl (readerLock);
  16742. reader = 0;
  16743. }
  16744. void AudioThumbnail::clear()
  16745. {
  16746. data.setSize (sizeof (AudioThumbnailDataFormat) + 3);
  16747. AudioThumbnailDataFormat* const d = (AudioThumbnailDataFormat*) data.getData();
  16748. d->thumbnailMagic[0] = 'j';
  16749. d->thumbnailMagic[1] = 'a';
  16750. d->thumbnailMagic[2] = 't';
  16751. d->thumbnailMagic[3] = 'm';
  16752. d->samplesPerThumbSample = orginalSamplesPerThumbnailSample;
  16753. d->totalSamples = 0;
  16754. d->numFinishedSamples = 0;
  16755. d->numThumbnailSamples = 0;
  16756. d->numChannels = 0;
  16757. d->sampleRate = 0;
  16758. numSamplesCached = 0;
  16759. cacheNeedsRefilling = true;
  16760. }
  16761. void AudioThumbnail::loadFrom (InputStream& input)
  16762. {
  16763. const ScopedLock sl (readerLock);
  16764. data.setSize (0);
  16765. input.readIntoMemoryBlock (data);
  16766. AudioThumbnailDataFormat* const d = (AudioThumbnailDataFormat*) data.getData();
  16767. swapEndiannessIfNeeded (d);
  16768. if (! (d->thumbnailMagic[0] == 'j'
  16769. && d->thumbnailMagic[1] == 'a'
  16770. && d->thumbnailMagic[2] == 't'
  16771. && d->thumbnailMagic[3] == 'm'))
  16772. {
  16773. clear();
  16774. }
  16775. numSamplesCached = 0;
  16776. cacheNeedsRefilling = true;
  16777. }
  16778. void AudioThumbnail::saveTo (OutputStream& output) const
  16779. {
  16780. AudioThumbnailDataFormat* const d = (AudioThumbnailDataFormat*) data.getData();
  16781. swapEndiannessIfNeeded (d);
  16782. output.write (data.getData(), (int) data.getSize());
  16783. swapEndiannessIfNeeded (d);
  16784. }
  16785. bool AudioThumbnail::initialiseFromAudioFile (AudioFormatReader& fileReader)
  16786. {
  16787. AudioThumbnailDataFormat* d = (AudioThumbnailDataFormat*) data.getData();
  16788. d->totalSamples = fileReader.lengthInSamples;
  16789. d->numChannels = jmin ((uint32) 2, fileReader.numChannels);
  16790. d->numFinishedSamples = 0;
  16791. d->sampleRate = roundToInt (fileReader.sampleRate);
  16792. d->numThumbnailSamples = (int) (d->totalSamples / d->samplesPerThumbSample) + 1;
  16793. data.setSize (sizeof (AudioThumbnailDataFormat) + 3 + d->numThumbnailSamples * d->numChannels * 2);
  16794. d = (AudioThumbnailDataFormat*) data.getData();
  16795. zeromem (&(d->data[0]), d->numThumbnailSamples * d->numChannels * 2);
  16796. return d->totalSamples > 0;
  16797. }
  16798. bool AudioThumbnail::readNextBlockFromAudioFile (AudioFormatReader& fileReader)
  16799. {
  16800. AudioThumbnailDataFormat* const d = (AudioThumbnailDataFormat*) data.getData();
  16801. if (d->numFinishedSamples < d->totalSamples)
  16802. {
  16803. const int numToDo = (int) jmin ((int64) 65536, d->totalSamples - d->numFinishedSamples);
  16804. generateSection (fileReader,
  16805. d->numFinishedSamples,
  16806. numToDo);
  16807. d->numFinishedSamples += numToDo;
  16808. }
  16809. cacheNeedsRefilling = true;
  16810. return (d->numFinishedSamples < d->totalSamples);
  16811. }
  16812. int AudioThumbnail::getNumChannels() const throw()
  16813. {
  16814. const AudioThumbnailDataFormat* const d = (const AudioThumbnailDataFormat*) data.getData();
  16815. jassert (d != 0);
  16816. return d->numChannels;
  16817. }
  16818. double AudioThumbnail::getTotalLength() const throw()
  16819. {
  16820. const AudioThumbnailDataFormat* const d = (const AudioThumbnailDataFormat*) data.getData();
  16821. jassert (d != 0);
  16822. if (d->sampleRate > 0)
  16823. return d->totalSamples / (double)d->sampleRate;
  16824. else
  16825. return 0.0;
  16826. }
  16827. void AudioThumbnail::generateSection (AudioFormatReader& fileReader,
  16828. int64 startSample,
  16829. int numSamples)
  16830. {
  16831. AudioThumbnailDataFormat* const d = (AudioThumbnailDataFormat*) data.getData();
  16832. jassert (d != 0);
  16833. int firstDataPos = (int) (startSample / d->samplesPerThumbSample);
  16834. int lastDataPos = (int) ((startSample + numSamples) / d->samplesPerThumbSample);
  16835. char* l = getChannelData (0);
  16836. char* r = getChannelData (1);
  16837. for (int i = firstDataPos; i < lastDataPos; ++i)
  16838. {
  16839. const int sourceStart = i * d->samplesPerThumbSample;
  16840. const int sourceEnd = sourceStart + d->samplesPerThumbSample;
  16841. float lowestLeft, highestLeft, lowestRight, highestRight;
  16842. fileReader.readMaxLevels (sourceStart,
  16843. sourceEnd - sourceStart,
  16844. lowestLeft,
  16845. highestLeft,
  16846. lowestRight,
  16847. highestRight);
  16848. int n = i * 2;
  16849. if (r != 0)
  16850. {
  16851. l [n] = (char) jlimit (-128.0f, 127.0f, lowestLeft * 127.0f);
  16852. r [n++] = (char) jlimit (-128.0f, 127.0f, lowestRight * 127.0f);
  16853. l [n] = (char) jlimit (-128.0f, 127.0f, highestLeft * 127.0f);
  16854. r [n++] = (char) jlimit (-128.0f, 127.0f, highestRight * 127.0f);
  16855. }
  16856. else
  16857. {
  16858. l [n++] = (char) jlimit (-128.0f, 127.0f, lowestLeft * 127.0f);
  16859. l [n++] = (char) jlimit (-128.0f, 127.0f, highestLeft * 127.0f);
  16860. }
  16861. }
  16862. }
  16863. char* AudioThumbnail::getChannelData (int channel) const
  16864. {
  16865. AudioThumbnailDataFormat* const d = (AudioThumbnailDataFormat*) data.getData();
  16866. jassert (d != 0);
  16867. if (channel >= 0 && channel < d->numChannels)
  16868. return d->data + (channel * 2 * d->numThumbnailSamples);
  16869. return 0;
  16870. }
  16871. bool AudioThumbnail::isFullyLoaded() const throw()
  16872. {
  16873. const AudioThumbnailDataFormat* const d = (const AudioThumbnailDataFormat*) data.getData();
  16874. jassert (d != 0);
  16875. return d->numFinishedSamples >= d->totalSamples;
  16876. }
  16877. void AudioThumbnail::refillCache (const int numSamples,
  16878. double startTime,
  16879. const double timePerPixel)
  16880. {
  16881. const AudioThumbnailDataFormat* const d = (const AudioThumbnailDataFormat*) data.getData();
  16882. jassert (d != 0);
  16883. if (numSamples <= 0
  16884. || timePerPixel <= 0.0
  16885. || d->sampleRate <= 0)
  16886. {
  16887. numSamplesCached = 0;
  16888. cacheNeedsRefilling = true;
  16889. return;
  16890. }
  16891. if (numSamples == numSamplesCached
  16892. && numChannelsCached == d->numChannels
  16893. && startTime == cachedStart
  16894. && timePerPixel == cachedTimePerPixel
  16895. && ! cacheNeedsRefilling)
  16896. {
  16897. return;
  16898. }
  16899. numSamplesCached = numSamples;
  16900. numChannelsCached = d->numChannels;
  16901. cachedStart = startTime;
  16902. cachedTimePerPixel = timePerPixel;
  16903. cachedLevels.ensureSize (2 * numChannelsCached * numSamples);
  16904. const bool needExtraDetail = (timePerPixel * d->sampleRate <= d->samplesPerThumbSample);
  16905. const ScopedLock sl (readerLock);
  16906. cacheNeedsRefilling = false;
  16907. if (needExtraDetail && reader == 0)
  16908. reader = createReader();
  16909. if (reader != 0 && timePerPixel * d->sampleRate <= d->samplesPerThumbSample)
  16910. {
  16911. startTimer (timeBeforeDeletingReader);
  16912. char* cacheData = (char*) cachedLevels.getData();
  16913. int sample = roundToInt (startTime * d->sampleRate);
  16914. for (int i = numSamples; --i >= 0;)
  16915. {
  16916. const int nextSample = roundToInt ((startTime + timePerPixel) * d->sampleRate);
  16917. if (sample >= 0)
  16918. {
  16919. if (sample >= reader->lengthInSamples)
  16920. break;
  16921. float lmin, lmax, rmin, rmax;
  16922. reader->readMaxLevels (sample,
  16923. jmax (1, nextSample - sample),
  16924. lmin, lmax, rmin, rmax);
  16925. cacheData[0] = (char) jlimit (-128, 127, roundFloatToInt (lmin * 127.0f));
  16926. cacheData[1] = (char) jlimit (-128, 127, roundFloatToInt (lmax * 127.0f));
  16927. if (numChannelsCached > 1)
  16928. {
  16929. cacheData[2] = (char) jlimit (-128, 127, roundFloatToInt (rmin * 127.0f));
  16930. cacheData[3] = (char) jlimit (-128, 127, roundFloatToInt (rmax * 127.0f));
  16931. }
  16932. cacheData += 2 * numChannelsCached;
  16933. }
  16934. startTime += timePerPixel;
  16935. sample = nextSample;
  16936. }
  16937. }
  16938. else
  16939. {
  16940. for (int channelNum = 0; channelNum < numChannelsCached; ++channelNum)
  16941. {
  16942. char* const channelData = getChannelData (channelNum);
  16943. char* cacheData = ((char*) cachedLevels.getData()) + channelNum * 2;
  16944. const double timeToThumbSampleFactor = d->sampleRate / (double) d->samplesPerThumbSample;
  16945. startTime = cachedStart;
  16946. int sample = roundToInt (startTime * timeToThumbSampleFactor);
  16947. const int numFinished = (int) (d->numFinishedSamples / d->samplesPerThumbSample);
  16948. for (int i = numSamples; --i >= 0;)
  16949. {
  16950. const int nextSample = roundToInt ((startTime + timePerPixel) * timeToThumbSampleFactor);
  16951. if (sample >= 0 && channelData != 0)
  16952. {
  16953. char mx = -128;
  16954. char mn = 127;
  16955. while (sample <= nextSample)
  16956. {
  16957. if (sample >= numFinished)
  16958. break;
  16959. const int n = sample << 1;
  16960. const char sampMin = channelData [n];
  16961. const char sampMax = channelData [n + 1];
  16962. if (sampMin < mn)
  16963. mn = sampMin;
  16964. if (sampMax > mx)
  16965. mx = sampMax;
  16966. ++sample;
  16967. }
  16968. if (mn <= mx)
  16969. {
  16970. cacheData[0] = mn;
  16971. cacheData[1] = mx;
  16972. }
  16973. else
  16974. {
  16975. cacheData[0] = 1;
  16976. cacheData[1] = 0;
  16977. }
  16978. }
  16979. else
  16980. {
  16981. cacheData[0] = 1;
  16982. cacheData[1] = 0;
  16983. }
  16984. cacheData += numChannelsCached * 2;
  16985. startTime += timePerPixel;
  16986. sample = nextSample;
  16987. }
  16988. }
  16989. }
  16990. }
  16991. void AudioThumbnail::drawChannel (Graphics& g,
  16992. int x, int y, int w, int h,
  16993. double startTime,
  16994. double endTime,
  16995. int channelNum,
  16996. const float verticalZoomFactor)
  16997. {
  16998. refillCache (w, startTime, (endTime - startTime) / w);
  16999. if (numSamplesCached >= w
  17000. && channelNum >= 0
  17001. && channelNum < numChannelsCached)
  17002. {
  17003. const float topY = (float) y;
  17004. const float bottomY = topY + h;
  17005. const float midY = topY + h * 0.5f;
  17006. const float vscale = verticalZoomFactor * h / 256.0f;
  17007. const Rectangle clip (g.getClipBounds());
  17008. const int skipLeft = jlimit (0, w, clip.getX() - x);
  17009. w -= skipLeft;
  17010. x += skipLeft;
  17011. const char* cacheData = ((const char*) cachedLevels.getData())
  17012. + (channelNum << 1)
  17013. + skipLeft * (numChannelsCached << 1);
  17014. while (--w >= 0)
  17015. {
  17016. const char mn = cacheData[0];
  17017. const char mx = cacheData[1];
  17018. cacheData += numChannelsCached << 1;
  17019. if (mn <= mx) // if the wrong way round, signifies that the sample's not yet known
  17020. g.drawLine ((float) x, jmax (midY - mx * vscale - 0.3f, topY),
  17021. (float) x, jmin (midY - mn * vscale + 0.3f, bottomY));
  17022. ++x;
  17023. if (x >= clip.getRight())
  17024. break;
  17025. }
  17026. }
  17027. }
  17028. END_JUCE_NAMESPACE
  17029. /********* End of inlined file: juce_AudioThumbnail.cpp *********/
  17030. /********* Start of inlined file: juce_AudioThumbnailCache.cpp *********/
  17031. BEGIN_JUCE_NAMESPACE
  17032. struct ThumbnailCacheEntry
  17033. {
  17034. int64 hash;
  17035. uint32 lastUsed;
  17036. MemoryBlock data;
  17037. juce_UseDebuggingNewOperator
  17038. };
  17039. AudioThumbnailCache::AudioThumbnailCache (const int maxNumThumbsToStore_)
  17040. : TimeSliceThread (T("thumb cache")),
  17041. maxNumThumbsToStore (maxNumThumbsToStore_)
  17042. {
  17043. startThread (2);
  17044. }
  17045. AudioThumbnailCache::~AudioThumbnailCache()
  17046. {
  17047. }
  17048. bool AudioThumbnailCache::loadThumb (AudioThumbnail& thumb, const int64 hashCode)
  17049. {
  17050. for (int i = thumbs.size(); --i >= 0;)
  17051. {
  17052. if (thumbs[i]->hash == hashCode)
  17053. {
  17054. MemoryInputStream in ((const char*) thumbs[i]->data.getData(),
  17055. thumbs[i]->data.getSize(),
  17056. false);
  17057. thumb.loadFrom (in);
  17058. thumbs[i]->lastUsed = Time::getMillisecondCounter();
  17059. return true;
  17060. }
  17061. }
  17062. return false;
  17063. }
  17064. void AudioThumbnailCache::storeThumb (const AudioThumbnail& thumb,
  17065. const int64 hashCode)
  17066. {
  17067. MemoryOutputStream out;
  17068. thumb.saveTo (out);
  17069. ThumbnailCacheEntry* te = 0;
  17070. for (int i = thumbs.size(); --i >= 0;)
  17071. {
  17072. if (thumbs[i]->hash == hashCode)
  17073. {
  17074. te = thumbs[i];
  17075. break;
  17076. }
  17077. }
  17078. if (te == 0)
  17079. {
  17080. te = new ThumbnailCacheEntry();
  17081. te->hash = hashCode;
  17082. if (thumbs.size() < maxNumThumbsToStore)
  17083. {
  17084. thumbs.add (te);
  17085. }
  17086. else
  17087. {
  17088. int oldest = 0;
  17089. unsigned int oldestTime = Time::getMillisecondCounter() + 1;
  17090. int i;
  17091. for (i = thumbs.size(); --i >= 0;)
  17092. if (thumbs[i]->lastUsed < oldestTime)
  17093. oldest = i;
  17094. thumbs.set (i, te);
  17095. }
  17096. }
  17097. te->lastUsed = Time::getMillisecondCounter();
  17098. te->data.setSize (0);
  17099. te->data.append (out.getData(), out.getDataSize());
  17100. }
  17101. void AudioThumbnailCache::clear()
  17102. {
  17103. thumbs.clear();
  17104. }
  17105. void AudioThumbnailCache::addThumbnail (AudioThumbnail* const thumb)
  17106. {
  17107. addTimeSliceClient (thumb);
  17108. }
  17109. void AudioThumbnailCache::removeThumbnail (AudioThumbnail* const thumb)
  17110. {
  17111. removeTimeSliceClient (thumb);
  17112. }
  17113. END_JUCE_NAMESPACE
  17114. /********* End of inlined file: juce_AudioThumbnailCache.cpp *********/
  17115. /********* Start of inlined file: juce_QuickTimeAudioFormat.cpp *********/
  17116. #if JUCE_QUICKTIME && ! (JUCE_64BIT || JUCE_IPHONE)
  17117. #if ! JUCE_WINDOWS
  17118. #include <QuickTime/Movies.h>
  17119. #include <QuickTime/QTML.h>
  17120. #include <QuickTime/QuickTimeComponents.h>
  17121. #include <QuickTime/MediaHandlers.h>
  17122. #include <QuickTime/ImageCodec.h>
  17123. #else
  17124. #if JUCE_MSVC
  17125. #pragma warning (push)
  17126. #pragma warning (disable : 4100)
  17127. #endif
  17128. #include <Movies.h>
  17129. #include <QTML.h>
  17130. #include <QuickTimeComponents.h>
  17131. #include <MediaHandlers.h>
  17132. #include <ImageCodec.h>
  17133. #if JUCE_MSVC
  17134. #pragma warning (pop)
  17135. #endif
  17136. #endif
  17137. BEGIN_JUCE_NAMESPACE
  17138. bool juce_OpenQuickTimeMovieFromStream (InputStream* input, Movie& movie, Handle& dataHandle);
  17139. static const char* const quickTimeFormatName = "QuickTime file";
  17140. static const tchar* const quickTimeExtensions[] = { T(".mov"), T(".mp3"), T(".mp4"), 0 };
  17141. class QTAudioReader : public AudioFormatReader
  17142. {
  17143. public:
  17144. QTAudioReader (InputStream* const input_, const int trackNum_)
  17145. : AudioFormatReader (input_, TRANS (quickTimeFormatName)),
  17146. ok (false),
  17147. movie (0),
  17148. trackNum (trackNum_),
  17149. extractor (0),
  17150. lastSampleRead (0),
  17151. lastThreadId (0),
  17152. dataHandle (0)
  17153. {
  17154. bufferList.calloc (256, 1);
  17155. #ifdef WIN32
  17156. if (InitializeQTML (0) != noErr)
  17157. return;
  17158. #endif
  17159. if (EnterMovies() != noErr)
  17160. return;
  17161. bool opened = juce_OpenQuickTimeMovieFromStream (input_, movie, dataHandle);
  17162. if (! opened)
  17163. return;
  17164. {
  17165. const int numTracks = GetMovieTrackCount (movie);
  17166. int trackCount = 0;
  17167. for (int i = 1; i <= numTracks; ++i)
  17168. {
  17169. track = GetMovieIndTrack (movie, i);
  17170. media = GetTrackMedia (track);
  17171. OSType mediaType;
  17172. GetMediaHandlerDescription (media, &mediaType, 0, 0);
  17173. if (mediaType == SoundMediaType
  17174. && trackCount++ == trackNum_)
  17175. {
  17176. ok = true;
  17177. break;
  17178. }
  17179. }
  17180. }
  17181. if (! ok)
  17182. return;
  17183. ok = false;
  17184. lengthInSamples = GetMediaDecodeDuration (media);
  17185. usesFloatingPointData = false;
  17186. samplesPerFrame = (int) (GetMediaDecodeDuration (media) / GetMediaSampleCount (media));
  17187. trackUnitsPerFrame = GetMovieTimeScale (movie) * samplesPerFrame
  17188. / GetMediaTimeScale (media);
  17189. OSStatus err = MovieAudioExtractionBegin (movie, 0, &extractor);
  17190. unsigned long output_layout_size;
  17191. err = MovieAudioExtractionGetPropertyInfo (extractor,
  17192. kQTPropertyClass_MovieAudioExtraction_Audio,
  17193. kQTMovieAudioExtractionAudioPropertyID_AudioChannelLayout,
  17194. 0, &output_layout_size, 0);
  17195. if (err != noErr)
  17196. return;
  17197. HeapBlock <AudioChannelLayout> qt_audio_channel_layout;
  17198. qt_audio_channel_layout.calloc (output_layout_size, 1);
  17199. err = MovieAudioExtractionGetProperty (extractor,
  17200. kQTPropertyClass_MovieAudioExtraction_Audio,
  17201. kQTMovieAudioExtractionAudioPropertyID_AudioChannelLayout,
  17202. output_layout_size, qt_audio_channel_layout, 0);
  17203. qt_audio_channel_layout[0].mChannelLayoutTag = kAudioChannelLayoutTag_Stereo;
  17204. err = MovieAudioExtractionSetProperty (extractor,
  17205. kQTPropertyClass_MovieAudioExtraction_Audio,
  17206. kQTMovieAudioExtractionAudioPropertyID_AudioChannelLayout,
  17207. output_layout_size,
  17208. qt_audio_channel_layout);
  17209. err = MovieAudioExtractionGetProperty (extractor,
  17210. kQTPropertyClass_MovieAudioExtraction_Audio,
  17211. kQTMovieAudioExtractionAudioPropertyID_AudioStreamBasicDescription,
  17212. sizeof (inputStreamDesc),
  17213. &inputStreamDesc, 0);
  17214. if (err != noErr)
  17215. return;
  17216. inputStreamDesc.mFormatFlags = kAudioFormatFlagIsSignedInteger
  17217. | kAudioFormatFlagIsPacked
  17218. | kAudioFormatFlagsNativeEndian;
  17219. inputStreamDesc.mBitsPerChannel = sizeof (SInt16) * 8;
  17220. inputStreamDesc.mChannelsPerFrame = jmin ((UInt32) 2, inputStreamDesc.mChannelsPerFrame);
  17221. inputStreamDesc.mBytesPerFrame = sizeof (SInt16) * inputStreamDesc.mChannelsPerFrame;
  17222. inputStreamDesc.mBytesPerPacket = inputStreamDesc.mBytesPerFrame;
  17223. err = MovieAudioExtractionSetProperty (extractor,
  17224. kQTPropertyClass_MovieAudioExtraction_Audio,
  17225. kQTMovieAudioExtractionAudioPropertyID_AudioStreamBasicDescription,
  17226. sizeof (inputStreamDesc),
  17227. &inputStreamDesc);
  17228. if (err != noErr)
  17229. return;
  17230. Boolean allChannelsDiscrete = false;
  17231. err = MovieAudioExtractionSetProperty (extractor,
  17232. kQTPropertyClass_MovieAudioExtraction_Movie,
  17233. kQTMovieAudioExtractionMoviePropertyID_AllChannelsDiscrete,
  17234. sizeof (allChannelsDiscrete),
  17235. &allChannelsDiscrete);
  17236. if (err != noErr)
  17237. return;
  17238. bufferList->mNumberBuffers = 1;
  17239. bufferList->mBuffers[0].mNumberChannels = inputStreamDesc.mChannelsPerFrame;
  17240. bufferList->mBuffers[0].mDataByteSize = (UInt32) (samplesPerFrame * inputStreamDesc.mBytesPerFrame) + 16;
  17241. bufferList->mBuffers[0].mData = malloc (bufferList->mBuffers[0].mDataByteSize);
  17242. sampleRate = inputStreamDesc.mSampleRate;
  17243. bitsPerSample = 16;
  17244. numChannels = inputStreamDesc.mChannelsPerFrame;
  17245. detachThread();
  17246. ok = true;
  17247. }
  17248. ~QTAudioReader()
  17249. {
  17250. if (dataHandle != 0)
  17251. DisposeHandle (dataHandle);
  17252. if (extractor != 0)
  17253. {
  17254. MovieAudioExtractionEnd (extractor);
  17255. extractor = 0;
  17256. }
  17257. checkThreadIsAttached();
  17258. DisposeMovie (movie);
  17259. juce_free (bufferList->mBuffers[0].mData);
  17260. #if JUCE_MAC
  17261. ExitMoviesOnThread ();
  17262. #endif
  17263. }
  17264. bool readSamples (int** destSamples, int numDestChannels, int startOffsetInDestBuffer,
  17265. int64 startSampleInFile, int numSamples)
  17266. {
  17267. checkThreadIsAttached();
  17268. while (numSamples > 0)
  17269. {
  17270. if (! loadFrame ((int) startSampleInFile))
  17271. return false;
  17272. const int numToDo = jmin (numSamples, samplesPerFrame);
  17273. for (int j = numDestChannels; --j >= 0;)
  17274. {
  17275. if (destSamples[j] != 0)
  17276. {
  17277. const short* const src = ((const short*) bufferList->mBuffers[0].mData) + j;
  17278. for (int i = 0; i < numToDo; ++i)
  17279. destSamples[j][startOffsetInDestBuffer + i] = src [i << 1] << 16;
  17280. }
  17281. }
  17282. startOffsetInDestBuffer += numToDo;
  17283. startSampleInFile += numToDo;
  17284. numSamples -= numToDo;
  17285. }
  17286. detachThread();
  17287. return true;
  17288. }
  17289. bool loadFrame (const int sampleNum)
  17290. {
  17291. if (lastSampleRead != sampleNum)
  17292. {
  17293. TimeRecord time;
  17294. time.scale = (TimeScale) inputStreamDesc.mSampleRate;
  17295. time.base = 0;
  17296. time.value.hi = 0;
  17297. time.value.lo = (UInt32) sampleNum;
  17298. OSStatus err = MovieAudioExtractionSetProperty (extractor,
  17299. kQTPropertyClass_MovieAudioExtraction_Movie,
  17300. kQTMovieAudioExtractionMoviePropertyID_CurrentTime,
  17301. sizeof (time), &time);
  17302. if (err != noErr)
  17303. return false;
  17304. }
  17305. bufferList->mBuffers[0].mDataByteSize = inputStreamDesc.mBytesPerFrame * samplesPerFrame;
  17306. UInt32 outFlags = 0;
  17307. UInt32 actualNumSamples = samplesPerFrame;
  17308. OSStatus err = MovieAudioExtractionFillBuffer (extractor, &actualNumSamples,
  17309. bufferList, &outFlags);
  17310. lastSampleRead = sampleNum + samplesPerFrame;
  17311. return err == noErr;
  17312. }
  17313. juce_UseDebuggingNewOperator
  17314. bool ok;
  17315. private:
  17316. Movie movie;
  17317. Media media;
  17318. Track track;
  17319. const int trackNum;
  17320. double trackUnitsPerFrame;
  17321. int samplesPerFrame;
  17322. int lastSampleRead;
  17323. Thread::ThreadID lastThreadId;
  17324. MovieAudioExtractionRef extractor;
  17325. AudioStreamBasicDescription inputStreamDesc;
  17326. HeapBlock <AudioBufferList> bufferList;
  17327. Handle dataHandle;
  17328. void checkThreadIsAttached()
  17329. {
  17330. #if JUCE_MAC
  17331. if (Thread::getCurrentThreadId() != lastThreadId)
  17332. EnterMoviesOnThread (0);
  17333. AttachMovieToCurrentThread (movie);
  17334. #endif
  17335. }
  17336. void detachThread()
  17337. {
  17338. #if JUCE_MAC
  17339. DetachMovieFromCurrentThread (movie);
  17340. #endif
  17341. }
  17342. };
  17343. QuickTimeAudioFormat::QuickTimeAudioFormat()
  17344. : AudioFormat (TRANS (quickTimeFormatName), (const tchar**) quickTimeExtensions)
  17345. {
  17346. }
  17347. QuickTimeAudioFormat::~QuickTimeAudioFormat()
  17348. {
  17349. }
  17350. const Array <int> QuickTimeAudioFormat::getPossibleSampleRates()
  17351. {
  17352. return Array<int>();
  17353. }
  17354. const Array <int> QuickTimeAudioFormat::getPossibleBitDepths()
  17355. {
  17356. return Array<int>();
  17357. }
  17358. bool QuickTimeAudioFormat::canDoStereo()
  17359. {
  17360. return true;
  17361. }
  17362. bool QuickTimeAudioFormat::canDoMono()
  17363. {
  17364. return true;
  17365. }
  17366. AudioFormatReader* QuickTimeAudioFormat::createReaderFor (InputStream* sourceStream,
  17367. const bool deleteStreamIfOpeningFails)
  17368. {
  17369. ScopedPointer <QTAudioReader> r (new QTAudioReader (sourceStream, 0));
  17370. if (r->ok)
  17371. return r.release();
  17372. if (! deleteStreamIfOpeningFails)
  17373. r->input = 0;
  17374. return 0;
  17375. }
  17376. AudioFormatWriter* QuickTimeAudioFormat::createWriterFor (OutputStream* /*streamToWriteTo*/,
  17377. double /*sampleRateToUse*/,
  17378. unsigned int /*numberOfChannels*/,
  17379. int /*bitsPerSample*/,
  17380. const StringPairArray& /*metadataValues*/,
  17381. int /*qualityOptionIndex*/)
  17382. {
  17383. jassertfalse // not yet implemented!
  17384. return 0;
  17385. }
  17386. END_JUCE_NAMESPACE
  17387. #endif
  17388. /********* End of inlined file: juce_QuickTimeAudioFormat.cpp *********/
  17389. /********* Start of inlined file: juce_WavAudioFormat.cpp *********/
  17390. BEGIN_JUCE_NAMESPACE
  17391. static const char* const wavFormatName = "WAV file";
  17392. static const tchar* const wavExtensions[] = { T(".wav"), T(".bwf"), 0 };
  17393. const tchar* const WavAudioFormat::bwavDescription = T("bwav description");
  17394. const tchar* const WavAudioFormat::bwavOriginator = T("bwav originator");
  17395. const tchar* const WavAudioFormat::bwavOriginatorRef = T("bwav originator ref");
  17396. const tchar* const WavAudioFormat::bwavOriginationDate = T("bwav origination date");
  17397. const tchar* const WavAudioFormat::bwavOriginationTime = T("bwav origination time");
  17398. const tchar* const WavAudioFormat::bwavTimeReference = T("bwav time reference");
  17399. const tchar* const WavAudioFormat::bwavCodingHistory = T("bwav coding history");
  17400. const StringPairArray WavAudioFormat::createBWAVMetadata (const String& description,
  17401. const String& originator,
  17402. const String& originatorRef,
  17403. const Time& date,
  17404. const int64 timeReferenceSamples,
  17405. const String& codingHistory)
  17406. {
  17407. StringPairArray m;
  17408. m.set (bwavDescription, description);
  17409. m.set (bwavOriginator, originator);
  17410. m.set (bwavOriginatorRef, originatorRef);
  17411. m.set (bwavOriginationDate, date.formatted (T("%Y-%m-%d")));
  17412. m.set (bwavOriginationTime, date.formatted (T("%H:%M:%S")));
  17413. m.set (bwavTimeReference, String (timeReferenceSamples));
  17414. m.set (bwavCodingHistory, codingHistory);
  17415. return m;
  17416. }
  17417. #if JUCE_MSVC
  17418. #pragma pack (push, 1)
  17419. #define PACKED
  17420. #elif JUCE_GCC
  17421. #define PACKED __attribute__((packed))
  17422. #else
  17423. #define PACKED
  17424. #endif
  17425. struct BWAVChunk
  17426. {
  17427. uint8 description [256];
  17428. uint8 originator [32];
  17429. uint8 originatorRef [32];
  17430. uint8 originationDate [10];
  17431. uint8 originationTime [8];
  17432. uint32 timeRefLow;
  17433. uint32 timeRefHigh;
  17434. uint16 version;
  17435. uint8 umid[64];
  17436. uint8 reserved[190];
  17437. uint8 codingHistory[1];
  17438. void copyTo (StringPairArray& values) const
  17439. {
  17440. values.set (WavAudioFormat::bwavDescription, String::fromUTF8 (description, 256));
  17441. values.set (WavAudioFormat::bwavOriginator, String::fromUTF8 (originator, 32));
  17442. values.set (WavAudioFormat::bwavOriginatorRef, String::fromUTF8 (originatorRef, 32));
  17443. values.set (WavAudioFormat::bwavOriginationDate, String::fromUTF8 (originationDate, 10));
  17444. values.set (WavAudioFormat::bwavOriginationTime, String::fromUTF8 (originationTime, 8));
  17445. const uint32 timeLow = ByteOrder::swapIfBigEndian (timeRefLow);
  17446. const uint32 timeHigh = ByteOrder::swapIfBigEndian (timeRefHigh);
  17447. const int64 time = (((int64)timeHigh) << 32) + timeLow;
  17448. values.set (WavAudioFormat::bwavTimeReference, String (time));
  17449. values.set (WavAudioFormat::bwavCodingHistory, String::fromUTF8 (codingHistory));
  17450. }
  17451. static MemoryBlock createFrom (const StringPairArray& values)
  17452. {
  17453. const size_t sizeNeeded = sizeof (BWAVChunk) + values [WavAudioFormat::bwavCodingHistory].copyToUTF8 (0) - 1;
  17454. MemoryBlock data ((sizeNeeded + 3) & ~3);
  17455. data.fillWith (0);
  17456. BWAVChunk* b = (BWAVChunk*) data.getData();
  17457. // Allow these calls to overwrite an extra byte at the end, which is fine as long
  17458. // as they get called in the right order..
  17459. values [WavAudioFormat::bwavDescription].copyToUTF8 (b->description, 257);
  17460. values [WavAudioFormat::bwavOriginator].copyToUTF8 (b->originator, 33);
  17461. values [WavAudioFormat::bwavOriginatorRef].copyToUTF8 (b->originatorRef, 33);
  17462. values [WavAudioFormat::bwavOriginationDate].copyToUTF8 (b->originationDate, 11);
  17463. values [WavAudioFormat::bwavOriginationTime].copyToUTF8 (b->originationTime, 9);
  17464. const int64 time = values [WavAudioFormat::bwavTimeReference].getLargeIntValue();
  17465. b->timeRefLow = ByteOrder::swapIfBigEndian ((uint32) (time & 0xffffffff));
  17466. b->timeRefHigh = ByteOrder::swapIfBigEndian ((uint32) (time >> 32));
  17467. values [WavAudioFormat::bwavCodingHistory].copyToUTF8 (b->codingHistory);
  17468. if (b->description[0] != 0
  17469. || b->originator[0] != 0
  17470. || b->originationDate[0] != 0
  17471. || b->originationTime[0] != 0
  17472. || b->codingHistory[0] != 0
  17473. || time != 0)
  17474. {
  17475. return data;
  17476. }
  17477. return MemoryBlock();
  17478. }
  17479. } PACKED;
  17480. struct SMPLChunk
  17481. {
  17482. struct SampleLoop
  17483. {
  17484. uint32 identifier;
  17485. uint32 type;
  17486. uint32 start;
  17487. uint32 end;
  17488. uint32 fraction;
  17489. uint32 playCount;
  17490. } PACKED;
  17491. uint32 manufacturer;
  17492. uint32 product;
  17493. uint32 samplePeriod;
  17494. uint32 midiUnityNote;
  17495. uint32 midiPitchFraction;
  17496. uint32 smpteFormat;
  17497. uint32 smpteOffset;
  17498. uint32 numSampleLoops;
  17499. uint32 samplerData;
  17500. SampleLoop loops[1];
  17501. void copyTo (StringPairArray& values, const int totalSize) const
  17502. {
  17503. values.set (T("Manufacturer"), String (ByteOrder::swapIfBigEndian (manufacturer)));
  17504. values.set (T("Product"), String (ByteOrder::swapIfBigEndian (product)));
  17505. values.set (T("SamplePeriod"), String (ByteOrder::swapIfBigEndian (samplePeriod)));
  17506. values.set (T("MidiUnityNote"), String (ByteOrder::swapIfBigEndian (midiUnityNote)));
  17507. values.set (T("MidiPitchFraction"), String (ByteOrder::swapIfBigEndian (midiPitchFraction)));
  17508. values.set (T("SmpteFormat"), String (ByteOrder::swapIfBigEndian (smpteFormat)));
  17509. values.set (T("SmpteOffset"), String (ByteOrder::swapIfBigEndian (smpteOffset)));
  17510. values.set (T("NumSampleLoops"), String (ByteOrder::swapIfBigEndian (numSampleLoops)));
  17511. values.set (T("SamplerData"), String (ByteOrder::swapIfBigEndian (samplerData)));
  17512. for (uint32 i = 0; i < numSampleLoops; ++i)
  17513. {
  17514. if ((uint8*) (loops + (i + 1)) > ((uint8*) this) + totalSize)
  17515. break;
  17516. values.set (String::formatted (T("Loop%dIdentifier"), i), String (ByteOrder::swapIfBigEndian (loops[i].identifier)));
  17517. values.set (String::formatted (T("Loop%dType"), i), String (ByteOrder::swapIfBigEndian (loops[i].type)));
  17518. values.set (String::formatted (T("Loop%dStart"), i), String (ByteOrder::swapIfBigEndian (loops[i].start)));
  17519. values.set (String::formatted (T("Loop%dEnd"), i), String (ByteOrder::swapIfBigEndian (loops[i].end)));
  17520. values.set (String::formatted (T("Loop%dFraction"), i), String (ByteOrder::swapIfBigEndian (loops[i].fraction)));
  17521. values.set (String::formatted (T("Loop%dPlayCount"), i), String (ByteOrder::swapIfBigEndian (loops[i].playCount)));
  17522. }
  17523. }
  17524. } PACKED;
  17525. #if JUCE_MSVC
  17526. #pragma pack (pop)
  17527. #endif
  17528. #undef PACKED
  17529. class WavAudioFormatReader : public AudioFormatReader
  17530. {
  17531. int bytesPerFrame;
  17532. int64 dataChunkStart, dataLength;
  17533. static inline int chunkName (const char* const name) { return (int) ByteOrder::littleEndianInt (name); }
  17534. WavAudioFormatReader (const WavAudioFormatReader&);
  17535. const WavAudioFormatReader& operator= (const WavAudioFormatReader&);
  17536. public:
  17537. int64 bwavChunkStart, bwavSize;
  17538. WavAudioFormatReader (InputStream* const in)
  17539. : AudioFormatReader (in, TRANS (wavFormatName)),
  17540. dataLength (0),
  17541. bwavChunkStart (0),
  17542. bwavSize (0)
  17543. {
  17544. if (input->readInt() == chunkName ("RIFF"))
  17545. {
  17546. const uint32 len = (uint32) input->readInt();
  17547. const int64 end = input->getPosition() + len;
  17548. bool hasGotType = false;
  17549. bool hasGotData = false;
  17550. if (input->readInt() == chunkName ("WAVE"))
  17551. {
  17552. while (input->getPosition() < end
  17553. && ! input->isExhausted())
  17554. {
  17555. const int chunkType = input->readInt();
  17556. uint32 length = (uint32) input->readInt();
  17557. const int64 chunkEnd = input->getPosition() + length + (length & 1);
  17558. if (chunkType == chunkName ("fmt "))
  17559. {
  17560. // read the format chunk
  17561. const short format = input->readShort();
  17562. const short numChans = input->readShort();
  17563. sampleRate = input->readInt();
  17564. const int bytesPerSec = input->readInt();
  17565. numChannels = numChans;
  17566. bytesPerFrame = bytesPerSec / (int)sampleRate;
  17567. bitsPerSample = 8 * bytesPerFrame / numChans;
  17568. if (format == 3)
  17569. usesFloatingPointData = true;
  17570. else if (format != 1)
  17571. bytesPerFrame = 0;
  17572. hasGotType = true;
  17573. }
  17574. else if (chunkType == chunkName ("data"))
  17575. {
  17576. // get the data chunk's position
  17577. dataLength = length;
  17578. dataChunkStart = input->getPosition();
  17579. lengthInSamples = (bytesPerFrame > 0) ? (dataLength / bytesPerFrame) : 0;
  17580. hasGotData = true;
  17581. }
  17582. else if (chunkType == chunkName ("bext"))
  17583. {
  17584. bwavChunkStart = input->getPosition();
  17585. bwavSize = length;
  17586. // Broadcast-wav extension chunk..
  17587. HeapBlock <BWAVChunk> bwav;
  17588. bwav.calloc (jmax ((size_t) length + 1, sizeof (BWAVChunk)), 1);
  17589. input->read (bwav, length);
  17590. bwav->copyTo (metadataValues);
  17591. }
  17592. else if (chunkType == chunkName ("smpl"))
  17593. {
  17594. HeapBlock <SMPLChunk> smpl;
  17595. smpl.calloc (jmax ((size_t) length + 1, sizeof (SMPLChunk)), 1);
  17596. input->read (smpl, length);
  17597. smpl->copyTo (metadataValues, length);
  17598. }
  17599. else if (chunkEnd <= input->getPosition())
  17600. {
  17601. break;
  17602. }
  17603. input->setPosition (chunkEnd);
  17604. }
  17605. }
  17606. }
  17607. }
  17608. ~WavAudioFormatReader()
  17609. {
  17610. }
  17611. bool readSamples (int** destSamples, int numDestChannels, int startOffsetInDestBuffer,
  17612. int64 startSampleInFile, int numSamples)
  17613. {
  17614. const int64 samplesAvailable = lengthInSamples - startSampleInFile;
  17615. if (samplesAvailable < numSamples)
  17616. {
  17617. for (int i = numDestChannels; --i >= 0;)
  17618. if (destSamples[i] != 0)
  17619. zeromem (destSamples[i] + startOffsetInDestBuffer, sizeof (int) * numSamples);
  17620. numSamples = (int) samplesAvailable;
  17621. }
  17622. if (numSamples <= 0)
  17623. return true;
  17624. input->setPosition (dataChunkStart + startSampleInFile * bytesPerFrame);
  17625. const int tempBufSize = 480 * 3 * 4; // (keep this a multiple of 3)
  17626. char tempBuffer [tempBufSize];
  17627. while (numSamples > 0)
  17628. {
  17629. int* left = destSamples[0];
  17630. if (left != 0)
  17631. left += startOffsetInDestBuffer;
  17632. int* right = numDestChannels > 1 ? destSamples[1] : 0;
  17633. if (right != 0)
  17634. right += startOffsetInDestBuffer;
  17635. const int numThisTime = jmin (tempBufSize / bytesPerFrame, numSamples);
  17636. const int bytesRead = input->read (tempBuffer, numThisTime * bytesPerFrame);
  17637. if (bytesRead < numThisTime * bytesPerFrame)
  17638. zeromem (tempBuffer + bytesRead, numThisTime * bytesPerFrame - bytesRead);
  17639. if (bitsPerSample == 16)
  17640. {
  17641. const short* src = (const short*) tempBuffer;
  17642. if (numChannels > 1)
  17643. {
  17644. if (left == 0)
  17645. {
  17646. for (int i = numThisTime; --i >= 0;)
  17647. {
  17648. ++src;
  17649. *right++ = (int) ByteOrder::swapIfBigEndian ((unsigned short) *src++) << 16;
  17650. }
  17651. }
  17652. else if (right == 0)
  17653. {
  17654. for (int i = numThisTime; --i >= 0;)
  17655. {
  17656. *left++ = (int) ByteOrder::swapIfBigEndian ((unsigned short) *src++) << 16;
  17657. ++src;
  17658. }
  17659. }
  17660. else
  17661. {
  17662. for (int i = numThisTime; --i >= 0;)
  17663. {
  17664. *left++ = (int) ByteOrder::swapIfBigEndian ((unsigned short) *src++) << 16;
  17665. *right++ = (int) ByteOrder::swapIfBigEndian ((unsigned short) *src++) << 16;
  17666. }
  17667. }
  17668. }
  17669. else
  17670. {
  17671. for (int i = numThisTime; --i >= 0;)
  17672. {
  17673. *left++ = (int) ByteOrder::swapIfBigEndian ((unsigned short) *src++) << 16;
  17674. }
  17675. }
  17676. }
  17677. else if (bitsPerSample == 24)
  17678. {
  17679. const char* src = (const char*) tempBuffer;
  17680. if (numChannels > 1)
  17681. {
  17682. if (left == 0)
  17683. {
  17684. for (int i = numThisTime; --i >= 0;)
  17685. {
  17686. src += 3;
  17687. *right++ = ByteOrder::littleEndian24Bit (src) << 8;
  17688. src += 3;
  17689. }
  17690. }
  17691. else if (right == 0)
  17692. {
  17693. for (int i = numThisTime; --i >= 0;)
  17694. {
  17695. *left++ = ByteOrder::littleEndian24Bit (src) << 8;
  17696. src += 6;
  17697. }
  17698. }
  17699. else
  17700. {
  17701. for (int i = 0; i < numThisTime; ++i)
  17702. {
  17703. *left++ = ByteOrder::littleEndian24Bit (src) << 8;
  17704. src += 3;
  17705. *right++ = ByteOrder::littleEndian24Bit (src) << 8;
  17706. src += 3;
  17707. }
  17708. }
  17709. }
  17710. else
  17711. {
  17712. for (int i = 0; i < numThisTime; ++i)
  17713. {
  17714. *left++ = ByteOrder::littleEndian24Bit (src) << 8;
  17715. src += 3;
  17716. }
  17717. }
  17718. }
  17719. else if (bitsPerSample == 32)
  17720. {
  17721. const unsigned int* src = (const unsigned int*) tempBuffer;
  17722. unsigned int* l = (unsigned int*) left;
  17723. unsigned int* r = (unsigned int*) right;
  17724. if (numChannels > 1)
  17725. {
  17726. if (l == 0)
  17727. {
  17728. for (int i = numThisTime; --i >= 0;)
  17729. {
  17730. ++src;
  17731. *r++ = ByteOrder::swapIfBigEndian (*src++);
  17732. }
  17733. }
  17734. else if (r == 0)
  17735. {
  17736. for (int i = numThisTime; --i >= 0;)
  17737. {
  17738. *l++ = ByteOrder::swapIfBigEndian (*src++);
  17739. ++src;
  17740. }
  17741. }
  17742. else
  17743. {
  17744. for (int i = numThisTime; --i >= 0;)
  17745. {
  17746. *l++ = ByteOrder::swapIfBigEndian (*src++);
  17747. *r++ = ByteOrder::swapIfBigEndian (*src++);
  17748. }
  17749. }
  17750. }
  17751. else
  17752. {
  17753. for (int i = numThisTime; --i >= 0;)
  17754. {
  17755. *l++ = ByteOrder::swapIfBigEndian (*src++);
  17756. }
  17757. }
  17758. left = (int*)l;
  17759. right = (int*)r;
  17760. }
  17761. else if (bitsPerSample == 8)
  17762. {
  17763. const unsigned char* src = (const unsigned char*) tempBuffer;
  17764. if (numChannels > 1)
  17765. {
  17766. if (left == 0)
  17767. {
  17768. for (int i = numThisTime; --i >= 0;)
  17769. {
  17770. ++src;
  17771. *right++ = ((int) *src++ - 128) << 24;
  17772. }
  17773. }
  17774. else if (right == 0)
  17775. {
  17776. for (int i = numThisTime; --i >= 0;)
  17777. {
  17778. *left++ = ((int) *src++ - 128) << 24;
  17779. ++src;
  17780. }
  17781. }
  17782. else
  17783. {
  17784. for (int i = numThisTime; --i >= 0;)
  17785. {
  17786. *left++ = ((int) *src++ - 128) << 24;
  17787. *right++ = ((int) *src++ - 128) << 24;
  17788. }
  17789. }
  17790. }
  17791. else
  17792. {
  17793. for (int i = numThisTime; --i >= 0;)
  17794. {
  17795. *left++ = ((int)*src++ - 128) << 24;
  17796. }
  17797. }
  17798. }
  17799. startOffsetInDestBuffer += numThisTime;
  17800. numSamples -= numThisTime;
  17801. }
  17802. if (numSamples > 0)
  17803. {
  17804. for (int i = numDestChannels; --i >= 0;)
  17805. if (destSamples[i] != 0)
  17806. zeromem (destSamples[i] + startOffsetInDestBuffer,
  17807. sizeof (int) * numSamples);
  17808. }
  17809. return true;
  17810. }
  17811. juce_UseDebuggingNewOperator
  17812. };
  17813. class WavAudioFormatWriter : public AudioFormatWriter
  17814. {
  17815. MemoryBlock tempBlock, bwavChunk;
  17816. uint32 lengthInSamples, bytesWritten;
  17817. int64 headerPosition;
  17818. bool writeFailed;
  17819. static inline int chunkName (const char* const name) { return (int) ByteOrder::littleEndianInt (name); }
  17820. WavAudioFormatWriter (const WavAudioFormatWriter&);
  17821. const WavAudioFormatWriter& operator= (const WavAudioFormatWriter&);
  17822. void writeHeader()
  17823. {
  17824. const bool seekedOk = output->setPosition (headerPosition);
  17825. (void) seekedOk;
  17826. // if this fails, you've given it an output stream that can't seek! It needs
  17827. // to be able to seek back to write the header
  17828. jassert (seekedOk);
  17829. const int bytesPerFrame = numChannels * bitsPerSample / 8;
  17830. output->writeInt (chunkName ("RIFF"));
  17831. output->writeInt ((int) (lengthInSamples * bytesPerFrame
  17832. + ((bwavChunk.getSize() > 0) ? (44 + bwavChunk.getSize()) : 36)));
  17833. output->writeInt (chunkName ("WAVE"));
  17834. output->writeInt (chunkName ("fmt "));
  17835. output->writeInt (16);
  17836. output->writeShort ((bitsPerSample < 32) ? (short) 1 /*WAVE_FORMAT_PCM*/
  17837. : (short) 3 /*WAVE_FORMAT_IEEE_FLOAT*/);
  17838. output->writeShort ((short) numChannels);
  17839. output->writeInt ((int) sampleRate);
  17840. output->writeInt (bytesPerFrame * (int) sampleRate);
  17841. output->writeShort ((short) bytesPerFrame);
  17842. output->writeShort ((short) bitsPerSample);
  17843. if (bwavChunk.getSize() > 0)
  17844. {
  17845. output->writeInt (chunkName ("bext"));
  17846. output->writeInt ((int) bwavChunk.getSize());
  17847. output->write (bwavChunk.getData(), (int) bwavChunk.getSize());
  17848. }
  17849. output->writeInt (chunkName ("data"));
  17850. output->writeInt (lengthInSamples * bytesPerFrame);
  17851. usesFloatingPointData = (bitsPerSample == 32);
  17852. }
  17853. public:
  17854. WavAudioFormatWriter (OutputStream* const out,
  17855. const double sampleRate_,
  17856. const unsigned int numChannels_,
  17857. const int bits,
  17858. const StringPairArray& metadataValues)
  17859. : AudioFormatWriter (out,
  17860. TRANS (wavFormatName),
  17861. sampleRate_,
  17862. numChannels_,
  17863. bits),
  17864. lengthInSamples (0),
  17865. bytesWritten (0),
  17866. writeFailed (false)
  17867. {
  17868. if (metadataValues.size() > 0)
  17869. bwavChunk = BWAVChunk::createFrom (metadataValues);
  17870. headerPosition = out->getPosition();
  17871. writeHeader();
  17872. }
  17873. ~WavAudioFormatWriter()
  17874. {
  17875. writeHeader();
  17876. }
  17877. bool write (const int** data, int numSamples)
  17878. {
  17879. if (writeFailed)
  17880. return false;
  17881. const int bytes = numChannels * numSamples * bitsPerSample / 8;
  17882. tempBlock.ensureSize (bytes, false);
  17883. char* buffer = (char*) tempBlock.getData();
  17884. const int* left = data[0];
  17885. const int* right = data[1];
  17886. if (right == 0)
  17887. right = left;
  17888. if (bitsPerSample == 16)
  17889. {
  17890. short* b = (short*) buffer;
  17891. if (numChannels > 1)
  17892. {
  17893. for (int i = numSamples; --i >= 0;)
  17894. {
  17895. *b++ = (short) ByteOrder::swapIfBigEndian ((unsigned short) (*left++ >> 16));
  17896. *b++ = (short) ByteOrder::swapIfBigEndian ((unsigned short) (*right++ >> 16));
  17897. }
  17898. }
  17899. else
  17900. {
  17901. for (int i = numSamples; --i >= 0;)
  17902. {
  17903. *b++ = (short) ByteOrder::swapIfBigEndian ((unsigned short) (*left++ >> 16));
  17904. }
  17905. }
  17906. }
  17907. else if (bitsPerSample == 24)
  17908. {
  17909. char* b = (char*) buffer;
  17910. if (numChannels > 1)
  17911. {
  17912. for (int i = numSamples; --i >= 0;)
  17913. {
  17914. ByteOrder::littleEndian24BitToChars ((*left++) >> 8, b);
  17915. b += 3;
  17916. ByteOrder::littleEndian24BitToChars ((*right++) >> 8, b);
  17917. b += 3;
  17918. }
  17919. }
  17920. else
  17921. {
  17922. for (int i = numSamples; --i >= 0;)
  17923. {
  17924. ByteOrder::littleEndian24BitToChars ((*left++) >> 8, b);
  17925. b += 3;
  17926. }
  17927. }
  17928. }
  17929. else if (bitsPerSample == 32)
  17930. {
  17931. unsigned int* b = (unsigned int*) buffer;
  17932. if (numChannels > 1)
  17933. {
  17934. for (int i = numSamples; --i >= 0;)
  17935. {
  17936. *b++ = ByteOrder::swapIfBigEndian ((unsigned int) *left++);
  17937. *b++ = ByteOrder::swapIfBigEndian ((unsigned int) *right++);
  17938. }
  17939. }
  17940. else
  17941. {
  17942. for (int i = numSamples; --i >= 0;)
  17943. {
  17944. *b++ = ByteOrder::swapIfBigEndian ((unsigned int) *left++);
  17945. }
  17946. }
  17947. }
  17948. else if (bitsPerSample == 8)
  17949. {
  17950. unsigned char* b = (unsigned char*) buffer;
  17951. if (numChannels > 1)
  17952. {
  17953. for (int i = numSamples; --i >= 0;)
  17954. {
  17955. *b++ = (unsigned char) (128 + (*left++ >> 24));
  17956. *b++ = (unsigned char) (128 + (*right++ >> 24));
  17957. }
  17958. }
  17959. else
  17960. {
  17961. for (int i = numSamples; --i >= 0;)
  17962. {
  17963. *b++ = (unsigned char) (128 + (*left++ >> 24));
  17964. }
  17965. }
  17966. }
  17967. if (bytesWritten + bytes >= (uint32) 0xfff00000
  17968. || ! output->write (buffer, bytes))
  17969. {
  17970. // failed to write to disk, so let's try writing the header.
  17971. // If it's just run out of disk space, then if it does manage
  17972. // to write the header, we'll still have a useable file..
  17973. writeHeader();
  17974. writeFailed = true;
  17975. return false;
  17976. }
  17977. else
  17978. {
  17979. bytesWritten += bytes;
  17980. lengthInSamples += numSamples;
  17981. return true;
  17982. }
  17983. }
  17984. juce_UseDebuggingNewOperator
  17985. };
  17986. WavAudioFormat::WavAudioFormat()
  17987. : AudioFormat (TRANS (wavFormatName), (const tchar**) wavExtensions)
  17988. {
  17989. }
  17990. WavAudioFormat::~WavAudioFormat()
  17991. {
  17992. }
  17993. const Array <int> WavAudioFormat::getPossibleSampleRates()
  17994. {
  17995. const int rates[] = { 22050, 32000, 44100, 48000, 88200, 96000, 176400, 192000, 0 };
  17996. return Array <int> (rates);
  17997. }
  17998. const Array <int> WavAudioFormat::getPossibleBitDepths()
  17999. {
  18000. const int depths[] = { 8, 16, 24, 32, 0 };
  18001. return Array <int> (depths);
  18002. }
  18003. bool WavAudioFormat::canDoStereo()
  18004. {
  18005. return true;
  18006. }
  18007. bool WavAudioFormat::canDoMono()
  18008. {
  18009. return true;
  18010. }
  18011. AudioFormatReader* WavAudioFormat::createReaderFor (InputStream* sourceStream,
  18012. const bool deleteStreamIfOpeningFails)
  18013. {
  18014. ScopedPointer <WavAudioFormatReader> r (new WavAudioFormatReader (sourceStream));
  18015. if (r->sampleRate != 0)
  18016. return r.release();
  18017. if (! deleteStreamIfOpeningFails)
  18018. r->input = 0;
  18019. return 0;
  18020. }
  18021. AudioFormatWriter* WavAudioFormat::createWriterFor (OutputStream* out,
  18022. double sampleRate,
  18023. unsigned int numChannels,
  18024. int bitsPerSample,
  18025. const StringPairArray& metadataValues,
  18026. int /*qualityOptionIndex*/)
  18027. {
  18028. if (getPossibleBitDepths().contains (bitsPerSample))
  18029. {
  18030. return new WavAudioFormatWriter (out,
  18031. sampleRate,
  18032. numChannels,
  18033. bitsPerSample,
  18034. metadataValues);
  18035. }
  18036. return 0;
  18037. }
  18038. static bool juce_slowCopyOfWavFileWithNewMetadata (const File& file, const StringPairArray& metadata)
  18039. {
  18040. TemporaryFile tempFile (file);
  18041. WavAudioFormat wav;
  18042. ScopedPointer <AudioFormatReader> reader (wav.createReaderFor (file.createInputStream(), true));
  18043. if (reader != 0)
  18044. {
  18045. ScopedPointer <OutputStream> outStream (tempFile.getFile().createOutputStream());
  18046. if (outStream != 0)
  18047. {
  18048. ScopedPointer <AudioFormatWriter> writer (wav.createWriterFor (outStream, reader->sampleRate,
  18049. reader->numChannels, reader->bitsPerSample,
  18050. metadata, 0));
  18051. if (writer != 0)
  18052. {
  18053. outStream.release();
  18054. bool ok = writer->writeFromAudioReader (*reader, 0, -1);
  18055. writer = 0;
  18056. reader = 0;
  18057. return ok && tempFile.overwriteTargetFileWithTemporary();
  18058. }
  18059. }
  18060. }
  18061. return false;
  18062. }
  18063. bool WavAudioFormat::replaceMetadataInFile (const File& wavFile, const StringPairArray& newMetadata)
  18064. {
  18065. ScopedPointer <WavAudioFormatReader> reader ((WavAudioFormatReader*) createReaderFor (wavFile.createInputStream(), true));
  18066. if (reader != 0)
  18067. {
  18068. const int64 bwavPos = reader->bwavChunkStart;
  18069. const int64 bwavSize = reader->bwavSize;
  18070. reader = 0;
  18071. if (bwavSize > 0)
  18072. {
  18073. MemoryBlock chunk = BWAVChunk::createFrom (newMetadata);
  18074. if (chunk.getSize() <= (size_t) bwavSize)
  18075. {
  18076. // the new one will fit in the space available, so write it directly..
  18077. const int64 oldSize = wavFile.getSize();
  18078. {
  18079. ScopedPointer <FileOutputStream> out (wavFile.createOutputStream());
  18080. out->setPosition (bwavPos);
  18081. out->write (chunk.getData(), (int) chunk.getSize());
  18082. out->setPosition (oldSize);
  18083. }
  18084. jassert (wavFile.getSize() == oldSize);
  18085. return true;
  18086. }
  18087. }
  18088. }
  18089. return juce_slowCopyOfWavFileWithNewMetadata (wavFile, newMetadata);
  18090. }
  18091. END_JUCE_NAMESPACE
  18092. /********* End of inlined file: juce_WavAudioFormat.cpp *********/
  18093. /********* Start of inlined file: juce_AudioFormatReaderSource.cpp *********/
  18094. BEGIN_JUCE_NAMESPACE
  18095. AudioFormatReaderSource::AudioFormatReaderSource (AudioFormatReader* const reader_,
  18096. const bool deleteReaderWhenThisIsDeleted)
  18097. : reader (reader_),
  18098. deleteReader (deleteReaderWhenThisIsDeleted),
  18099. nextPlayPos (0),
  18100. looping (false)
  18101. {
  18102. jassert (reader != 0);
  18103. }
  18104. AudioFormatReaderSource::~AudioFormatReaderSource()
  18105. {
  18106. releaseResources();
  18107. if (deleteReader)
  18108. delete reader;
  18109. }
  18110. void AudioFormatReaderSource::setNextReadPosition (int newPosition)
  18111. {
  18112. nextPlayPos = newPosition;
  18113. }
  18114. void AudioFormatReaderSource::setLooping (const bool shouldLoop) throw()
  18115. {
  18116. looping = shouldLoop;
  18117. }
  18118. int AudioFormatReaderSource::getNextReadPosition() const
  18119. {
  18120. return (looping) ? (nextPlayPos % (int) reader->lengthInSamples)
  18121. : nextPlayPos;
  18122. }
  18123. int AudioFormatReaderSource::getTotalLength() const
  18124. {
  18125. return (int) reader->lengthInSamples;
  18126. }
  18127. void AudioFormatReaderSource::prepareToPlay (int /*samplesPerBlockExpected*/,
  18128. double /*sampleRate*/)
  18129. {
  18130. }
  18131. void AudioFormatReaderSource::releaseResources()
  18132. {
  18133. }
  18134. void AudioFormatReaderSource::getNextAudioBlock (const AudioSourceChannelInfo& info)
  18135. {
  18136. if (info.numSamples > 0)
  18137. {
  18138. const int start = nextPlayPos;
  18139. if (looping)
  18140. {
  18141. const int newStart = start % (int) reader->lengthInSamples;
  18142. const int newEnd = (start + info.numSamples) % (int) reader->lengthInSamples;
  18143. if (newEnd > newStart)
  18144. {
  18145. info.buffer->readFromAudioReader (reader,
  18146. info.startSample,
  18147. newEnd - newStart,
  18148. newStart,
  18149. true, true);
  18150. }
  18151. else
  18152. {
  18153. const int endSamps = (int) reader->lengthInSamples - newStart;
  18154. info.buffer->readFromAudioReader (reader,
  18155. info.startSample,
  18156. endSamps,
  18157. newStart,
  18158. true, true);
  18159. info.buffer->readFromAudioReader (reader,
  18160. info.startSample + endSamps,
  18161. newEnd,
  18162. 0,
  18163. true, true);
  18164. }
  18165. nextPlayPos = newEnd;
  18166. }
  18167. else
  18168. {
  18169. info.buffer->readFromAudioReader (reader,
  18170. info.startSample,
  18171. info.numSamples,
  18172. start,
  18173. true, true);
  18174. nextPlayPos += info.numSamples;
  18175. }
  18176. }
  18177. }
  18178. END_JUCE_NAMESPACE
  18179. /********* End of inlined file: juce_AudioFormatReaderSource.cpp *********/
  18180. /********* Start of inlined file: juce_AudioSourcePlayer.cpp *********/
  18181. BEGIN_JUCE_NAMESPACE
  18182. AudioSourcePlayer::AudioSourcePlayer()
  18183. : source (0),
  18184. sampleRate (0),
  18185. bufferSize (0),
  18186. tempBuffer (2, 8),
  18187. lastGain (1.0f),
  18188. gain (1.0f)
  18189. {
  18190. }
  18191. AudioSourcePlayer::~AudioSourcePlayer()
  18192. {
  18193. setSource (0);
  18194. }
  18195. void AudioSourcePlayer::setSource (AudioSource* newSource)
  18196. {
  18197. if (source != newSource)
  18198. {
  18199. AudioSource* const oldSource = source;
  18200. if (newSource != 0 && bufferSize > 0 && sampleRate > 0)
  18201. newSource->prepareToPlay (bufferSize, sampleRate);
  18202. {
  18203. const ScopedLock sl (readLock);
  18204. source = newSource;
  18205. }
  18206. if (oldSource != 0)
  18207. oldSource->releaseResources();
  18208. }
  18209. }
  18210. void AudioSourcePlayer::setGain (const float newGain) throw()
  18211. {
  18212. gain = newGain;
  18213. }
  18214. void AudioSourcePlayer::audioDeviceIOCallback (const float** inputChannelData,
  18215. int totalNumInputChannels,
  18216. float** outputChannelData,
  18217. int totalNumOutputChannels,
  18218. int numSamples)
  18219. {
  18220. // these should have been prepared by audioDeviceAboutToStart()...
  18221. jassert (sampleRate > 0 && bufferSize > 0);
  18222. const ScopedLock sl (readLock);
  18223. if (source != 0)
  18224. {
  18225. AudioSourceChannelInfo info;
  18226. int i, numActiveChans = 0, numInputs = 0, numOutputs = 0;
  18227. // messy stuff needed to compact the channels down into an array
  18228. // of non-zero pointers..
  18229. for (i = 0; i < totalNumInputChannels; ++i)
  18230. {
  18231. if (inputChannelData[i] != 0)
  18232. {
  18233. inputChans [numInputs++] = inputChannelData[i];
  18234. if (numInputs >= numElementsInArray (inputChans))
  18235. break;
  18236. }
  18237. }
  18238. for (i = 0; i < totalNumOutputChannels; ++i)
  18239. {
  18240. if (outputChannelData[i] != 0)
  18241. {
  18242. outputChans [numOutputs++] = outputChannelData[i];
  18243. if (numOutputs >= numElementsInArray (outputChans))
  18244. break;
  18245. }
  18246. }
  18247. if (numInputs > numOutputs)
  18248. {
  18249. // if there aren't enough output channels for the number of
  18250. // inputs, we need to create some temporary extra ones (can't
  18251. // use the input data in case it gets written to)
  18252. tempBuffer.setSize (numInputs - numOutputs, numSamples,
  18253. false, false, true);
  18254. for (i = 0; i < numOutputs; ++i)
  18255. {
  18256. channels[numActiveChans] = outputChans[i];
  18257. memcpy (channels[numActiveChans], inputChans[i], sizeof (float) * numSamples);
  18258. ++numActiveChans;
  18259. }
  18260. for (i = numOutputs; i < numInputs; ++i)
  18261. {
  18262. channels[numActiveChans] = tempBuffer.getSampleData (i - numOutputs, 0);
  18263. memcpy (channels[numActiveChans], inputChans[i], sizeof (float) * numSamples);
  18264. ++numActiveChans;
  18265. }
  18266. }
  18267. else
  18268. {
  18269. for (i = 0; i < numInputs; ++i)
  18270. {
  18271. channels[numActiveChans] = outputChans[i];
  18272. memcpy (channels[numActiveChans], inputChans[i], sizeof (float) * numSamples);
  18273. ++numActiveChans;
  18274. }
  18275. for (i = numInputs; i < numOutputs; ++i)
  18276. {
  18277. channels[numActiveChans] = outputChans[i];
  18278. zeromem (channels[numActiveChans], sizeof (float) * numSamples);
  18279. ++numActiveChans;
  18280. }
  18281. }
  18282. AudioSampleBuffer buffer (channels, numActiveChans, numSamples);
  18283. info.buffer = &buffer;
  18284. info.startSample = 0;
  18285. info.numSamples = numSamples;
  18286. source->getNextAudioBlock (info);
  18287. for (i = info.buffer->getNumChannels(); --i >= 0;)
  18288. info.buffer->applyGainRamp (i, info.startSample, info.numSamples, lastGain, gain);
  18289. lastGain = gain;
  18290. }
  18291. else
  18292. {
  18293. for (int i = 0; i < totalNumOutputChannels; ++i)
  18294. if (outputChannelData[i] != 0)
  18295. zeromem (outputChannelData[i], sizeof (float) * numSamples);
  18296. }
  18297. }
  18298. void AudioSourcePlayer::audioDeviceAboutToStart (AudioIODevice* device)
  18299. {
  18300. sampleRate = device->getCurrentSampleRate();
  18301. bufferSize = device->getCurrentBufferSizeSamples();
  18302. zeromem (channels, sizeof (channels));
  18303. if (source != 0)
  18304. source->prepareToPlay (bufferSize, sampleRate);
  18305. }
  18306. void AudioSourcePlayer::audioDeviceStopped()
  18307. {
  18308. if (source != 0)
  18309. source->releaseResources();
  18310. sampleRate = 0.0;
  18311. bufferSize = 0;
  18312. tempBuffer.setSize (2, 8);
  18313. }
  18314. END_JUCE_NAMESPACE
  18315. /********* End of inlined file: juce_AudioSourcePlayer.cpp *********/
  18316. /********* Start of inlined file: juce_AudioTransportSource.cpp *********/
  18317. BEGIN_JUCE_NAMESPACE
  18318. AudioTransportSource::AudioTransportSource()
  18319. : source (0),
  18320. resamplerSource (0),
  18321. bufferingSource (0),
  18322. positionableSource (0),
  18323. masterSource (0),
  18324. gain (1.0f),
  18325. lastGain (1.0f),
  18326. playing (false),
  18327. stopped (true),
  18328. sampleRate (44100.0),
  18329. sourceSampleRate (0.0),
  18330. blockSize (128),
  18331. readAheadBufferSize (0),
  18332. isPrepared (false),
  18333. inputStreamEOF (false)
  18334. {
  18335. }
  18336. AudioTransportSource::~AudioTransportSource()
  18337. {
  18338. setSource (0);
  18339. releaseResources();
  18340. }
  18341. void AudioTransportSource::setSource (PositionableAudioSource* const newSource,
  18342. int readAheadBufferSize_,
  18343. double sourceSampleRateToCorrectFor)
  18344. {
  18345. if (source == newSource)
  18346. {
  18347. if (source == 0)
  18348. return;
  18349. setSource (0, 0, 0); // deselect and reselect to avoid releasing resources wrongly
  18350. }
  18351. readAheadBufferSize = readAheadBufferSize_;
  18352. sourceSampleRate = sourceSampleRateToCorrectFor;
  18353. ResamplingAudioSource* newResamplerSource = 0;
  18354. BufferingAudioSource* newBufferingSource = 0;
  18355. PositionableAudioSource* newPositionableSource = 0;
  18356. AudioSource* newMasterSource = 0;
  18357. ScopedPointer <ResamplingAudioSource> oldResamplerSource (resamplerSource);
  18358. ScopedPointer <BufferingAudioSource> oldBufferingSource (bufferingSource);
  18359. AudioSource* oldMasterSource = masterSource;
  18360. if (newSource != 0)
  18361. {
  18362. newPositionableSource = newSource;
  18363. if (readAheadBufferSize_ > 0)
  18364. newPositionableSource = newBufferingSource
  18365. = new BufferingAudioSource (newPositionableSource, false, readAheadBufferSize_);
  18366. newPositionableSource->setNextReadPosition (0);
  18367. if (sourceSampleRateToCorrectFor != 0)
  18368. newMasterSource = newResamplerSource
  18369. = new ResamplingAudioSource (newPositionableSource, false);
  18370. else
  18371. newMasterSource = newPositionableSource;
  18372. if (isPrepared)
  18373. {
  18374. if (newResamplerSource != 0 && sourceSampleRate > 0 && sampleRate > 0)
  18375. newResamplerSource->setResamplingRatio (sourceSampleRate / sampleRate);
  18376. newMasterSource->prepareToPlay (blockSize, sampleRate);
  18377. }
  18378. }
  18379. {
  18380. const ScopedLock sl (callbackLock);
  18381. source = newSource;
  18382. resamplerSource = newResamplerSource;
  18383. bufferingSource = newBufferingSource;
  18384. masterSource = newMasterSource;
  18385. positionableSource = newPositionableSource;
  18386. playing = false;
  18387. }
  18388. if (oldMasterSource != 0)
  18389. oldMasterSource->releaseResources();
  18390. }
  18391. void AudioTransportSource::start()
  18392. {
  18393. if ((! playing) && masterSource != 0)
  18394. {
  18395. callbackLock.enter();
  18396. playing = true;
  18397. stopped = false;
  18398. inputStreamEOF = false;
  18399. callbackLock.exit();
  18400. sendChangeMessage (this);
  18401. }
  18402. }
  18403. void AudioTransportSource::stop()
  18404. {
  18405. if (playing)
  18406. {
  18407. callbackLock.enter();
  18408. playing = false;
  18409. callbackLock.exit();
  18410. int n = 500;
  18411. while (--n >= 0 && ! stopped)
  18412. Thread::sleep (2);
  18413. sendChangeMessage (this);
  18414. }
  18415. }
  18416. void AudioTransportSource::setPosition (double newPosition)
  18417. {
  18418. if (sampleRate > 0.0)
  18419. setNextReadPosition (roundToInt (newPosition * sampleRate));
  18420. }
  18421. double AudioTransportSource::getCurrentPosition() const
  18422. {
  18423. if (sampleRate > 0.0)
  18424. return getNextReadPosition() / sampleRate;
  18425. else
  18426. return 0.0;
  18427. }
  18428. void AudioTransportSource::setNextReadPosition (int newPosition)
  18429. {
  18430. if (positionableSource != 0)
  18431. {
  18432. if (sampleRate > 0 && sourceSampleRate > 0)
  18433. newPosition = roundToInt (newPosition * sourceSampleRate / sampleRate);
  18434. positionableSource->setNextReadPosition (newPosition);
  18435. }
  18436. }
  18437. int AudioTransportSource::getNextReadPosition() const
  18438. {
  18439. if (positionableSource != 0)
  18440. {
  18441. const double ratio = (sampleRate > 0 && sourceSampleRate > 0) ? sampleRate / sourceSampleRate : 1.0;
  18442. return roundToInt (positionableSource->getNextReadPosition() * ratio);
  18443. }
  18444. return 0;
  18445. }
  18446. int AudioTransportSource::getTotalLength() const
  18447. {
  18448. const ScopedLock sl (callbackLock);
  18449. if (positionableSource != 0)
  18450. {
  18451. const double ratio = (sampleRate > 0 && sourceSampleRate > 0) ? sampleRate / sourceSampleRate : 1.0;
  18452. return roundToInt (positionableSource->getTotalLength() * ratio);
  18453. }
  18454. return 0;
  18455. }
  18456. bool AudioTransportSource::isLooping() const
  18457. {
  18458. const ScopedLock sl (callbackLock);
  18459. return positionableSource != 0
  18460. && positionableSource->isLooping();
  18461. }
  18462. void AudioTransportSource::setGain (const float newGain) throw()
  18463. {
  18464. gain = newGain;
  18465. }
  18466. void AudioTransportSource::prepareToPlay (int samplesPerBlockExpected,
  18467. double sampleRate_)
  18468. {
  18469. const ScopedLock sl (callbackLock);
  18470. sampleRate = sampleRate_;
  18471. blockSize = samplesPerBlockExpected;
  18472. if (masterSource != 0)
  18473. masterSource->prepareToPlay (samplesPerBlockExpected, sampleRate);
  18474. if (resamplerSource != 0 && sourceSampleRate != 0)
  18475. resamplerSource->setResamplingRatio (sourceSampleRate / sampleRate);
  18476. isPrepared = true;
  18477. }
  18478. void AudioTransportSource::releaseResources()
  18479. {
  18480. const ScopedLock sl (callbackLock);
  18481. if (masterSource != 0)
  18482. masterSource->releaseResources();
  18483. isPrepared = false;
  18484. }
  18485. void AudioTransportSource::getNextAudioBlock (const AudioSourceChannelInfo& info)
  18486. {
  18487. const ScopedLock sl (callbackLock);
  18488. inputStreamEOF = false;
  18489. if (masterSource != 0 && ! stopped)
  18490. {
  18491. masterSource->getNextAudioBlock (info);
  18492. if (! playing)
  18493. {
  18494. // just stopped playing, so fade out the last block..
  18495. for (int i = info.buffer->getNumChannels(); --i >= 0;)
  18496. info.buffer->applyGainRamp (i, info.startSample, jmin (256, info.numSamples), 1.0f, 0.0f);
  18497. if (info.numSamples > 256)
  18498. info.buffer->clear (info.startSample + 256, info.numSamples - 256);
  18499. }
  18500. if (positionableSource->getNextReadPosition() > positionableSource->getTotalLength() + 1
  18501. && ! positionableSource->isLooping())
  18502. {
  18503. playing = false;
  18504. inputStreamEOF = true;
  18505. sendChangeMessage (this);
  18506. }
  18507. stopped = ! playing;
  18508. for (int i = info.buffer->getNumChannels(); --i >= 0;)
  18509. {
  18510. info.buffer->applyGainRamp (i, info.startSample, info.numSamples,
  18511. lastGain, gain);
  18512. }
  18513. }
  18514. else
  18515. {
  18516. info.clearActiveBufferRegion();
  18517. stopped = true;
  18518. }
  18519. lastGain = gain;
  18520. }
  18521. END_JUCE_NAMESPACE
  18522. /********* End of inlined file: juce_AudioTransportSource.cpp *********/
  18523. /********* Start of inlined file: juce_BufferingAudioSource.cpp *********/
  18524. BEGIN_JUCE_NAMESPACE
  18525. class SharedBufferingAudioSourceThread : public DeletedAtShutdown,
  18526. public Thread,
  18527. private Timer
  18528. {
  18529. public:
  18530. SharedBufferingAudioSourceThread()
  18531. : Thread ("Audio Buffer")
  18532. {
  18533. }
  18534. ~SharedBufferingAudioSourceThread()
  18535. {
  18536. stopThread (10000);
  18537. clearSingletonInstance();
  18538. }
  18539. juce_DeclareSingleton (SharedBufferingAudioSourceThread, false)
  18540. void addSource (BufferingAudioSource* source)
  18541. {
  18542. const ScopedLock sl (lock);
  18543. if (! sources.contains ((void*) source))
  18544. {
  18545. sources.add ((void*) source);
  18546. startThread();
  18547. stopTimer();
  18548. }
  18549. notify();
  18550. }
  18551. void removeSource (BufferingAudioSource* source)
  18552. {
  18553. const ScopedLock sl (lock);
  18554. sources.removeValue ((void*) source);
  18555. if (sources.size() == 0)
  18556. startTimer (5000);
  18557. }
  18558. private:
  18559. VoidArray sources;
  18560. CriticalSection lock;
  18561. void run()
  18562. {
  18563. while (! threadShouldExit())
  18564. {
  18565. bool busy = false;
  18566. for (int i = sources.size(); --i >= 0;)
  18567. {
  18568. if (threadShouldExit())
  18569. return;
  18570. const ScopedLock sl (lock);
  18571. BufferingAudioSource* const b = (BufferingAudioSource*) sources[i];
  18572. if (b != 0 && b->readNextBufferChunk())
  18573. busy = true;
  18574. }
  18575. if (! busy)
  18576. wait (500);
  18577. }
  18578. }
  18579. void timerCallback()
  18580. {
  18581. stopTimer();
  18582. if (sources.size() == 0)
  18583. deleteInstance();
  18584. }
  18585. SharedBufferingAudioSourceThread (const SharedBufferingAudioSourceThread&);
  18586. const SharedBufferingAudioSourceThread& operator= (const SharedBufferingAudioSourceThread&);
  18587. };
  18588. juce_ImplementSingleton (SharedBufferingAudioSourceThread)
  18589. BufferingAudioSource::BufferingAudioSource (PositionableAudioSource* source_,
  18590. const bool deleteSourceWhenDeleted_,
  18591. int numberOfSamplesToBuffer_)
  18592. : source (source_),
  18593. deleteSourceWhenDeleted (deleteSourceWhenDeleted_),
  18594. numberOfSamplesToBuffer (jmax (1024, numberOfSamplesToBuffer_)),
  18595. buffer (2, 0),
  18596. bufferValidStart (0),
  18597. bufferValidEnd (0),
  18598. nextPlayPos (0),
  18599. wasSourceLooping (false)
  18600. {
  18601. jassert (source_ != 0);
  18602. jassert (numberOfSamplesToBuffer_ > 1024); // not much point using this class if you're
  18603. // not using a larger buffer..
  18604. }
  18605. BufferingAudioSource::~BufferingAudioSource()
  18606. {
  18607. SharedBufferingAudioSourceThread* const thread = SharedBufferingAudioSourceThread::getInstanceWithoutCreating();
  18608. if (thread != 0)
  18609. thread->removeSource (this);
  18610. if (deleteSourceWhenDeleted)
  18611. delete source;
  18612. }
  18613. void BufferingAudioSource::prepareToPlay (int samplesPerBlockExpected, double sampleRate_)
  18614. {
  18615. source->prepareToPlay (samplesPerBlockExpected, sampleRate_);
  18616. sampleRate = sampleRate_;
  18617. buffer.setSize (2, jmax (samplesPerBlockExpected * 2, numberOfSamplesToBuffer));
  18618. buffer.clear();
  18619. bufferValidStart = 0;
  18620. bufferValidEnd = 0;
  18621. SharedBufferingAudioSourceThread::getInstance()->addSource (this);
  18622. while (bufferValidEnd - bufferValidStart < jmin (((int) sampleRate_) / 4,
  18623. buffer.getNumSamples() / 2))
  18624. {
  18625. SharedBufferingAudioSourceThread::getInstance()->notify();
  18626. Thread::sleep (5);
  18627. }
  18628. }
  18629. void BufferingAudioSource::releaseResources()
  18630. {
  18631. SharedBufferingAudioSourceThread* const thread = SharedBufferingAudioSourceThread::getInstanceWithoutCreating();
  18632. if (thread != 0)
  18633. thread->removeSource (this);
  18634. buffer.setSize (2, 0);
  18635. source->releaseResources();
  18636. }
  18637. void BufferingAudioSource::getNextAudioBlock (const AudioSourceChannelInfo& info)
  18638. {
  18639. const ScopedLock sl (bufferStartPosLock);
  18640. const int validStart = jlimit (bufferValidStart, bufferValidEnd, nextPlayPos) - nextPlayPos;
  18641. const int validEnd = jlimit (bufferValidStart, bufferValidEnd, nextPlayPos + info.numSamples) - nextPlayPos;
  18642. if (validStart == validEnd)
  18643. {
  18644. // total cache miss
  18645. info.clearActiveBufferRegion();
  18646. }
  18647. else
  18648. {
  18649. if (validStart > 0)
  18650. info.buffer->clear (info.startSample, validStart); // partial cache miss at start
  18651. if (validEnd < info.numSamples)
  18652. info.buffer->clear (info.startSample + validEnd,
  18653. info.numSamples - validEnd); // partial cache miss at end
  18654. if (validStart < validEnd)
  18655. {
  18656. for (int chan = jmin (2, info.buffer->getNumChannels()); --chan >= 0;)
  18657. {
  18658. const int startBufferIndex = (validStart + nextPlayPos) % buffer.getNumSamples();
  18659. const int endBufferIndex = (validEnd + nextPlayPos) % buffer.getNumSamples();
  18660. if (startBufferIndex < endBufferIndex)
  18661. {
  18662. info.buffer->copyFrom (chan, info.startSample + validStart,
  18663. buffer,
  18664. chan, startBufferIndex,
  18665. validEnd - validStart);
  18666. }
  18667. else
  18668. {
  18669. const int initialSize = buffer.getNumSamples() - startBufferIndex;
  18670. info.buffer->copyFrom (chan, info.startSample + validStart,
  18671. buffer,
  18672. chan, startBufferIndex,
  18673. initialSize);
  18674. info.buffer->copyFrom (chan, info.startSample + validStart + initialSize,
  18675. buffer,
  18676. chan, 0,
  18677. (validEnd - validStart) - initialSize);
  18678. }
  18679. }
  18680. }
  18681. nextPlayPos += info.numSamples;
  18682. if (source->isLooping() && nextPlayPos > 0)
  18683. nextPlayPos %= source->getTotalLength();
  18684. }
  18685. SharedBufferingAudioSourceThread* const thread = SharedBufferingAudioSourceThread::getInstanceWithoutCreating();
  18686. if (thread != 0)
  18687. thread->notify();
  18688. }
  18689. int BufferingAudioSource::getNextReadPosition() const
  18690. {
  18691. return (source->isLooping() && nextPlayPos > 0)
  18692. ? nextPlayPos % source->getTotalLength()
  18693. : nextPlayPos;
  18694. }
  18695. void BufferingAudioSource::setNextReadPosition (int newPosition)
  18696. {
  18697. const ScopedLock sl (bufferStartPosLock);
  18698. nextPlayPos = newPosition;
  18699. SharedBufferingAudioSourceThread* const thread = SharedBufferingAudioSourceThread::getInstanceWithoutCreating();
  18700. if (thread != 0)
  18701. thread->notify();
  18702. }
  18703. bool BufferingAudioSource::readNextBufferChunk()
  18704. {
  18705. bufferStartPosLock.enter();
  18706. if (wasSourceLooping != isLooping())
  18707. {
  18708. wasSourceLooping = isLooping();
  18709. bufferValidStart = 0;
  18710. bufferValidEnd = 0;
  18711. }
  18712. int newBVS = jmax (0, nextPlayPos);
  18713. int newBVE = newBVS + buffer.getNumSamples() - 4;
  18714. int sectionToReadStart = 0;
  18715. int sectionToReadEnd = 0;
  18716. const int maxChunkSize = 2048;
  18717. if (newBVS < bufferValidStart || newBVS >= bufferValidEnd)
  18718. {
  18719. newBVE = jmin (newBVE, newBVS + maxChunkSize);
  18720. sectionToReadStart = newBVS;
  18721. sectionToReadEnd = newBVE;
  18722. bufferValidStart = 0;
  18723. bufferValidEnd = 0;
  18724. }
  18725. else if (abs (newBVS - bufferValidStart) > 512
  18726. || abs (newBVE - bufferValidEnd) > 512)
  18727. {
  18728. newBVE = jmin (newBVE, bufferValidEnd + maxChunkSize);
  18729. sectionToReadStart = bufferValidEnd;
  18730. sectionToReadEnd = newBVE;
  18731. bufferValidStart = newBVS;
  18732. bufferValidEnd = jmin (bufferValidEnd, newBVE);
  18733. }
  18734. bufferStartPosLock.exit();
  18735. if (sectionToReadStart != sectionToReadEnd)
  18736. {
  18737. const int bufferIndexStart = sectionToReadStart % buffer.getNumSamples();
  18738. const int bufferIndexEnd = sectionToReadEnd % buffer.getNumSamples();
  18739. if (bufferIndexStart < bufferIndexEnd)
  18740. {
  18741. readBufferSection (sectionToReadStart,
  18742. sectionToReadEnd - sectionToReadStart,
  18743. bufferIndexStart);
  18744. }
  18745. else
  18746. {
  18747. const int initialSize = buffer.getNumSamples() - bufferIndexStart;
  18748. readBufferSection (sectionToReadStart,
  18749. initialSize,
  18750. bufferIndexStart);
  18751. readBufferSection (sectionToReadStart + initialSize,
  18752. (sectionToReadEnd - sectionToReadStart) - initialSize,
  18753. 0);
  18754. }
  18755. const ScopedLock sl2 (bufferStartPosLock);
  18756. bufferValidStart = newBVS;
  18757. bufferValidEnd = newBVE;
  18758. return true;
  18759. }
  18760. else
  18761. {
  18762. return false;
  18763. }
  18764. }
  18765. void BufferingAudioSource::readBufferSection (int start, int length, int bufferOffset)
  18766. {
  18767. if (source->getNextReadPosition() != start)
  18768. source->setNextReadPosition (start);
  18769. AudioSourceChannelInfo info;
  18770. info.buffer = &buffer;
  18771. info.startSample = bufferOffset;
  18772. info.numSamples = length;
  18773. source->getNextAudioBlock (info);
  18774. }
  18775. END_JUCE_NAMESPACE
  18776. /********* End of inlined file: juce_BufferingAudioSource.cpp *********/
  18777. /********* Start of inlined file: juce_ChannelRemappingAudioSource.cpp *********/
  18778. BEGIN_JUCE_NAMESPACE
  18779. ChannelRemappingAudioSource::ChannelRemappingAudioSource (AudioSource* const source_,
  18780. const bool deleteSourceWhenDeleted_)
  18781. : requiredNumberOfChannels (2),
  18782. source (source_),
  18783. deleteSourceWhenDeleted (deleteSourceWhenDeleted_),
  18784. buffer (2, 16)
  18785. {
  18786. remappedInfo.buffer = &buffer;
  18787. remappedInfo.startSample = 0;
  18788. }
  18789. ChannelRemappingAudioSource::~ChannelRemappingAudioSource()
  18790. {
  18791. if (deleteSourceWhenDeleted)
  18792. delete source;
  18793. }
  18794. void ChannelRemappingAudioSource::setNumberOfChannelsToProduce (const int requiredNumberOfChannels_) throw()
  18795. {
  18796. const ScopedLock sl (lock);
  18797. requiredNumberOfChannels = requiredNumberOfChannels_;
  18798. }
  18799. void ChannelRemappingAudioSource::clearAllMappings() throw()
  18800. {
  18801. const ScopedLock sl (lock);
  18802. remappedInputs.clear();
  18803. remappedOutputs.clear();
  18804. }
  18805. void ChannelRemappingAudioSource::setInputChannelMapping (const int destIndex, const int sourceIndex) throw()
  18806. {
  18807. const ScopedLock sl (lock);
  18808. while (remappedInputs.size() < destIndex)
  18809. remappedInputs.add (-1);
  18810. remappedInputs.set (destIndex, sourceIndex);
  18811. }
  18812. void ChannelRemappingAudioSource::setOutputChannelMapping (const int sourceIndex, const int destIndex) throw()
  18813. {
  18814. const ScopedLock sl (lock);
  18815. while (remappedOutputs.size() < sourceIndex)
  18816. remappedOutputs.add (-1);
  18817. remappedOutputs.set (sourceIndex, destIndex);
  18818. }
  18819. int ChannelRemappingAudioSource::getRemappedInputChannel (const int inputChannelIndex) const throw()
  18820. {
  18821. const ScopedLock sl (lock);
  18822. if (inputChannelIndex >= 0 && inputChannelIndex < remappedInputs.size())
  18823. return remappedInputs.getUnchecked (inputChannelIndex);
  18824. return -1;
  18825. }
  18826. int ChannelRemappingAudioSource::getRemappedOutputChannel (const int outputChannelIndex) const throw()
  18827. {
  18828. const ScopedLock sl (lock);
  18829. if (outputChannelIndex >= 0 && outputChannelIndex < remappedOutputs.size())
  18830. return remappedOutputs .getUnchecked (outputChannelIndex);
  18831. return -1;
  18832. }
  18833. void ChannelRemappingAudioSource::prepareToPlay (int samplesPerBlockExpected, double sampleRate)
  18834. {
  18835. source->prepareToPlay (samplesPerBlockExpected, sampleRate);
  18836. }
  18837. void ChannelRemappingAudioSource::releaseResources()
  18838. {
  18839. source->releaseResources();
  18840. }
  18841. void ChannelRemappingAudioSource::getNextAudioBlock (const AudioSourceChannelInfo& bufferToFill)
  18842. {
  18843. const ScopedLock sl (lock);
  18844. buffer.setSize (requiredNumberOfChannels, bufferToFill.numSamples, false, false, true);
  18845. const int numChans = bufferToFill.buffer->getNumChannels();
  18846. int i;
  18847. for (i = 0; i < buffer.getNumChannels(); ++i)
  18848. {
  18849. const int remappedChan = getRemappedInputChannel (i);
  18850. if (remappedChan >= 0 && remappedChan < numChans)
  18851. {
  18852. buffer.copyFrom (i, 0, *bufferToFill.buffer,
  18853. remappedChan,
  18854. bufferToFill.startSample,
  18855. bufferToFill.numSamples);
  18856. }
  18857. else
  18858. {
  18859. buffer.clear (i, 0, bufferToFill.numSamples);
  18860. }
  18861. }
  18862. remappedInfo.numSamples = bufferToFill.numSamples;
  18863. source->getNextAudioBlock (remappedInfo);
  18864. bufferToFill.clearActiveBufferRegion();
  18865. for (i = 0; i < requiredNumberOfChannels; ++i)
  18866. {
  18867. const int remappedChan = getRemappedOutputChannel (i);
  18868. if (remappedChan >= 0 && remappedChan < numChans)
  18869. {
  18870. bufferToFill.buffer->addFrom (remappedChan, bufferToFill.startSample,
  18871. buffer, i, 0, bufferToFill.numSamples);
  18872. }
  18873. }
  18874. }
  18875. XmlElement* ChannelRemappingAudioSource::createXml() const throw()
  18876. {
  18877. XmlElement* e = new XmlElement (T("MAPPINGS"));
  18878. String ins, outs;
  18879. int i;
  18880. const ScopedLock sl (lock);
  18881. for (i = 0; i < remappedInputs.size(); ++i)
  18882. ins << remappedInputs.getUnchecked(i) << T(' ');
  18883. for (i = 0; i < remappedOutputs.size(); ++i)
  18884. outs << remappedOutputs.getUnchecked(i) << T(' ');
  18885. e->setAttribute (T("inputs"), ins.trimEnd());
  18886. e->setAttribute (T("outputs"), outs.trimEnd());
  18887. return e;
  18888. }
  18889. void ChannelRemappingAudioSource::restoreFromXml (const XmlElement& e) throw()
  18890. {
  18891. if (e.hasTagName (T("MAPPINGS")))
  18892. {
  18893. const ScopedLock sl (lock);
  18894. clearAllMappings();
  18895. StringArray ins, outs;
  18896. ins.addTokens (e.getStringAttribute (T("inputs")), false);
  18897. outs.addTokens (e.getStringAttribute (T("outputs")), false);
  18898. int i;
  18899. for (i = 0; i < ins.size(); ++i)
  18900. remappedInputs.add (ins[i].getIntValue());
  18901. for (i = 0; i < outs.size(); ++i)
  18902. remappedOutputs.add (outs[i].getIntValue());
  18903. }
  18904. }
  18905. END_JUCE_NAMESPACE
  18906. /********* End of inlined file: juce_ChannelRemappingAudioSource.cpp *********/
  18907. /********* Start of inlined file: juce_IIRFilterAudioSource.cpp *********/
  18908. BEGIN_JUCE_NAMESPACE
  18909. IIRFilterAudioSource::IIRFilterAudioSource (AudioSource* const inputSource,
  18910. const bool deleteInputWhenDeleted_)
  18911. : input (inputSource),
  18912. deleteInputWhenDeleted (deleteInputWhenDeleted_)
  18913. {
  18914. jassert (inputSource != 0);
  18915. for (int i = 2; --i >= 0;)
  18916. iirFilters.add (new IIRFilter());
  18917. }
  18918. IIRFilterAudioSource::~IIRFilterAudioSource()
  18919. {
  18920. if (deleteInputWhenDeleted)
  18921. delete input;
  18922. }
  18923. void IIRFilterAudioSource::setFilterParameters (const IIRFilter& newSettings)
  18924. {
  18925. for (int i = iirFilters.size(); --i >= 0;)
  18926. iirFilters.getUnchecked(i)->copyCoefficientsFrom (newSettings);
  18927. }
  18928. void IIRFilterAudioSource::prepareToPlay (int samplesPerBlockExpected, double sampleRate)
  18929. {
  18930. input->prepareToPlay (samplesPerBlockExpected, sampleRate);
  18931. for (int i = iirFilters.size(); --i >= 0;)
  18932. iirFilters.getUnchecked(i)->reset();
  18933. }
  18934. void IIRFilterAudioSource::releaseResources()
  18935. {
  18936. input->releaseResources();
  18937. }
  18938. void IIRFilterAudioSource::getNextAudioBlock (const AudioSourceChannelInfo& bufferToFill)
  18939. {
  18940. input->getNextAudioBlock (bufferToFill);
  18941. const int numChannels = bufferToFill.buffer->getNumChannels();
  18942. while (numChannels > iirFilters.size())
  18943. iirFilters.add (new IIRFilter (*iirFilters.getUnchecked (0)));
  18944. for (int i = 0; i < numChannels; ++i)
  18945. iirFilters.getUnchecked(i)
  18946. ->processSamples (bufferToFill.buffer->getSampleData (i, bufferToFill.startSample),
  18947. bufferToFill.numSamples);
  18948. }
  18949. END_JUCE_NAMESPACE
  18950. /********* End of inlined file: juce_IIRFilterAudioSource.cpp *********/
  18951. /********* Start of inlined file: juce_MixerAudioSource.cpp *********/
  18952. BEGIN_JUCE_NAMESPACE
  18953. MixerAudioSource::MixerAudioSource()
  18954. : tempBuffer (2, 0),
  18955. currentSampleRate (0.0),
  18956. bufferSizeExpected (0)
  18957. {
  18958. }
  18959. MixerAudioSource::~MixerAudioSource()
  18960. {
  18961. removeAllInputs();
  18962. }
  18963. void MixerAudioSource::addInputSource (AudioSource* input, const bool deleteWhenRemoved)
  18964. {
  18965. if (input != 0 && ! inputs.contains (input))
  18966. {
  18967. lock.enter();
  18968. double localRate = currentSampleRate;
  18969. int localBufferSize = bufferSizeExpected;
  18970. lock.exit();
  18971. if (localRate != 0.0)
  18972. input->prepareToPlay (localBufferSize, localRate);
  18973. const ScopedLock sl (lock);
  18974. inputsToDelete.setBit (inputs.size(), deleteWhenRemoved);
  18975. inputs.add (input);
  18976. }
  18977. }
  18978. void MixerAudioSource::removeInputSource (AudioSource* input, const bool deleteInput)
  18979. {
  18980. if (input != 0)
  18981. {
  18982. lock.enter();
  18983. const int index = inputs.indexOf ((void*) input);
  18984. if (index >= 0)
  18985. {
  18986. inputsToDelete.shiftBits (index, 1);
  18987. inputs.remove (index);
  18988. }
  18989. lock.exit();
  18990. if (index >= 0)
  18991. {
  18992. input->releaseResources();
  18993. if (deleteInput)
  18994. delete input;
  18995. }
  18996. }
  18997. }
  18998. void MixerAudioSource::removeAllInputs()
  18999. {
  19000. lock.enter();
  19001. VoidArray inputsCopy (inputs);
  19002. BitArray inputsToDeleteCopy (inputsToDelete);
  19003. inputs.clear();
  19004. lock.exit();
  19005. for (int i = inputsCopy.size(); --i >= 0;)
  19006. if (inputsToDeleteCopy[i])
  19007. delete (AudioSource*) inputsCopy[i];
  19008. }
  19009. void MixerAudioSource::prepareToPlay (int samplesPerBlockExpected, double sampleRate)
  19010. {
  19011. tempBuffer.setSize (2, samplesPerBlockExpected);
  19012. const ScopedLock sl (lock);
  19013. currentSampleRate = sampleRate;
  19014. bufferSizeExpected = samplesPerBlockExpected;
  19015. for (int i = inputs.size(); --i >= 0;)
  19016. ((AudioSource*) inputs.getUnchecked(i))->prepareToPlay (samplesPerBlockExpected,
  19017. sampleRate);
  19018. }
  19019. void MixerAudioSource::releaseResources()
  19020. {
  19021. const ScopedLock sl (lock);
  19022. for (int i = inputs.size(); --i >= 0;)
  19023. ((AudioSource*) inputs.getUnchecked(i))->releaseResources();
  19024. tempBuffer.setSize (2, 0);
  19025. currentSampleRate = 0;
  19026. bufferSizeExpected = 0;
  19027. }
  19028. void MixerAudioSource::getNextAudioBlock (const AudioSourceChannelInfo& info)
  19029. {
  19030. const ScopedLock sl (lock);
  19031. if (inputs.size() > 0)
  19032. {
  19033. ((AudioSource*) inputs.getUnchecked(0))->getNextAudioBlock (info);
  19034. if (inputs.size() > 1)
  19035. {
  19036. tempBuffer.setSize (jmax (1, info.buffer->getNumChannels()),
  19037. info.buffer->getNumSamples());
  19038. AudioSourceChannelInfo info2;
  19039. info2.buffer = &tempBuffer;
  19040. info2.numSamples = info.numSamples;
  19041. info2.startSample = 0;
  19042. for (int i = 1; i < inputs.size(); ++i)
  19043. {
  19044. ((AudioSource*) inputs.getUnchecked(i))->getNextAudioBlock (info2);
  19045. for (int chan = 0; chan < info.buffer->getNumChannels(); ++chan)
  19046. info.buffer->addFrom (chan, info.startSample, tempBuffer, chan, 0, info.numSamples);
  19047. }
  19048. }
  19049. }
  19050. else
  19051. {
  19052. info.clearActiveBufferRegion();
  19053. }
  19054. }
  19055. END_JUCE_NAMESPACE
  19056. /********* End of inlined file: juce_MixerAudioSource.cpp *********/
  19057. /********* Start of inlined file: juce_ResamplingAudioSource.cpp *********/
  19058. BEGIN_JUCE_NAMESPACE
  19059. ResamplingAudioSource::ResamplingAudioSource (AudioSource* const inputSource,
  19060. const bool deleteInputWhenDeleted_)
  19061. : input (inputSource),
  19062. deleteInputWhenDeleted (deleteInputWhenDeleted_),
  19063. ratio (1.0),
  19064. lastRatio (1.0),
  19065. buffer (2, 0),
  19066. sampsInBuffer (0)
  19067. {
  19068. jassert (input != 0);
  19069. }
  19070. ResamplingAudioSource::~ResamplingAudioSource()
  19071. {
  19072. if (deleteInputWhenDeleted)
  19073. delete input;
  19074. }
  19075. void ResamplingAudioSource::setResamplingRatio (const double samplesInPerOutputSample)
  19076. {
  19077. jassert (samplesInPerOutputSample > 0);
  19078. const ScopedLock sl (ratioLock);
  19079. ratio = jmax (0.0, samplesInPerOutputSample);
  19080. }
  19081. void ResamplingAudioSource::prepareToPlay (int samplesPerBlockExpected,
  19082. double sampleRate)
  19083. {
  19084. const ScopedLock sl (ratioLock);
  19085. input->prepareToPlay (samplesPerBlockExpected, sampleRate);
  19086. buffer.setSize (2, roundToInt (samplesPerBlockExpected * ratio) + 32);
  19087. buffer.clear();
  19088. sampsInBuffer = 0;
  19089. bufferPos = 0;
  19090. subSampleOffset = 0.0;
  19091. createLowPass (ratio);
  19092. resetFilters();
  19093. }
  19094. void ResamplingAudioSource::releaseResources()
  19095. {
  19096. input->releaseResources();
  19097. buffer.setSize (2, 0);
  19098. }
  19099. void ResamplingAudioSource::getNextAudioBlock (const AudioSourceChannelInfo& info)
  19100. {
  19101. const ScopedLock sl (ratioLock);
  19102. if (lastRatio != ratio)
  19103. {
  19104. createLowPass (ratio);
  19105. lastRatio = ratio;
  19106. }
  19107. const int sampsNeeded = roundToInt (info.numSamples * ratio) + 2;
  19108. int bufferSize = buffer.getNumSamples();
  19109. if (bufferSize < sampsNeeded + 8)
  19110. {
  19111. bufferPos %= bufferSize;
  19112. bufferSize = sampsNeeded + 32;
  19113. buffer.setSize (buffer.getNumChannels(), bufferSize, true, true);
  19114. }
  19115. bufferPos %= bufferSize;
  19116. int endOfBufferPos = bufferPos + sampsInBuffer;
  19117. while (sampsNeeded > sampsInBuffer)
  19118. {
  19119. endOfBufferPos %= bufferSize;
  19120. int numToDo = jmin (sampsNeeded - sampsInBuffer,
  19121. bufferSize - endOfBufferPos);
  19122. AudioSourceChannelInfo readInfo;
  19123. readInfo.buffer = &buffer;
  19124. readInfo.numSamples = numToDo;
  19125. readInfo.startSample = endOfBufferPos;
  19126. input->getNextAudioBlock (readInfo);
  19127. if (ratio > 1.0001)
  19128. {
  19129. // for down-sampling, pre-apply the filter..
  19130. for (int i = jmin (2, info.buffer->getNumChannels()); --i >= 0;)
  19131. applyFilter (buffer.getSampleData (i, endOfBufferPos), numToDo, filterStates[i]);
  19132. }
  19133. sampsInBuffer += numToDo;
  19134. endOfBufferPos += numToDo;
  19135. }
  19136. float* dl = info.buffer->getSampleData (0, info.startSample);
  19137. float* dr = (info.buffer->getNumChannels() > 1) ? info.buffer->getSampleData (1, info.startSample) : 0;
  19138. const float* const bl = buffer.getSampleData (0, 0);
  19139. const float* const br = buffer.getSampleData (1, 0);
  19140. int nextPos = (bufferPos + 1) % bufferSize;
  19141. for (int m = info.numSamples; --m >= 0;)
  19142. {
  19143. const float alpha = (float) subSampleOffset;
  19144. const float invAlpha = 1.0f - alpha;
  19145. *dl++ = bl [bufferPos] * invAlpha + bl [nextPos] * alpha;
  19146. if (dr != 0)
  19147. *dr++ = br [bufferPos] * invAlpha + br [nextPos] * alpha;
  19148. subSampleOffset += ratio;
  19149. jassert (sampsInBuffer > 0);
  19150. while (subSampleOffset >= 1.0)
  19151. {
  19152. if (++bufferPos >= bufferSize)
  19153. bufferPos = 0;
  19154. --sampsInBuffer;
  19155. nextPos = (bufferPos + 1) % bufferSize;
  19156. subSampleOffset -= 1.0;
  19157. }
  19158. }
  19159. if (ratio < 0.9999)
  19160. {
  19161. // for up-sampling, apply the filter after transposing..
  19162. for (int i = jmin (2, info.buffer->getNumChannels()); --i >= 0;)
  19163. applyFilter (info.buffer->getSampleData (i, info.startSample), info.numSamples, filterStates[i]);
  19164. }
  19165. else if (ratio <= 1.0001)
  19166. {
  19167. // if the filter's not currently being applied, keep it stoked with the last couple of samples to avoid discontinuities
  19168. for (int i = jmin (2, info.buffer->getNumChannels()); --i >= 0;)
  19169. {
  19170. const float* const endOfBuffer = info.buffer->getSampleData (i, info.startSample + info.numSamples - 1);
  19171. FilterState& fs = filterStates[i];
  19172. if (info.numSamples > 1)
  19173. {
  19174. fs.y2 = fs.x2 = *(endOfBuffer - 1);
  19175. }
  19176. else
  19177. {
  19178. fs.y2 = fs.y1;
  19179. fs.x2 = fs.x1;
  19180. }
  19181. fs.y1 = fs.x1 = *endOfBuffer;
  19182. }
  19183. }
  19184. jassert (sampsInBuffer >= 0);
  19185. }
  19186. void ResamplingAudioSource::createLowPass (const double frequencyRatio)
  19187. {
  19188. const double proportionalRate = (frequencyRatio > 1.0) ? 0.5 / frequencyRatio
  19189. : 0.5 * frequencyRatio;
  19190. const double n = 1.0 / tan (double_Pi * jmax (0.001, proportionalRate));
  19191. const double nSquared = n * n;
  19192. const double c1 = 1.0 / (1.0 + sqrt (2.0) * n + nSquared);
  19193. setFilterCoefficients (c1,
  19194. c1 * 2.0f,
  19195. c1,
  19196. 1.0,
  19197. c1 * 2.0 * (1.0 - nSquared),
  19198. c1 * (1.0 - sqrt (2.0) * n + nSquared));
  19199. }
  19200. void ResamplingAudioSource::setFilterCoefficients (double c1, double c2, double c3, double c4, double c5, double c6)
  19201. {
  19202. const double a = 1.0 / c4;
  19203. c1 *= a;
  19204. c2 *= a;
  19205. c3 *= a;
  19206. c5 *= a;
  19207. c6 *= a;
  19208. coefficients[0] = c1;
  19209. coefficients[1] = c2;
  19210. coefficients[2] = c3;
  19211. coefficients[3] = c4;
  19212. coefficients[4] = c5;
  19213. coefficients[5] = c6;
  19214. }
  19215. void ResamplingAudioSource::resetFilters()
  19216. {
  19217. zeromem (filterStates, sizeof (filterStates));
  19218. }
  19219. void ResamplingAudioSource::applyFilter (float* samples, int num, FilterState& fs)
  19220. {
  19221. while (--num >= 0)
  19222. {
  19223. const double in = *samples;
  19224. double out = coefficients[0] * in
  19225. + coefficients[1] * fs.x1
  19226. + coefficients[2] * fs.x2
  19227. - coefficients[4] * fs.y1
  19228. - coefficients[5] * fs.y2;
  19229. #if JUCE_INTEL
  19230. if (! (out < -1.0e-8 || out > 1.0e-8))
  19231. out = 0;
  19232. #endif
  19233. fs.x2 = fs.x1;
  19234. fs.x1 = in;
  19235. fs.y2 = fs.y1;
  19236. fs.y1 = out;
  19237. *samples++ = (float) out;
  19238. }
  19239. }
  19240. END_JUCE_NAMESPACE
  19241. /********* End of inlined file: juce_ResamplingAudioSource.cpp *********/
  19242. /********* Start of inlined file: juce_ToneGeneratorAudioSource.cpp *********/
  19243. BEGIN_JUCE_NAMESPACE
  19244. ToneGeneratorAudioSource::ToneGeneratorAudioSource()
  19245. : frequency (1000.0),
  19246. sampleRate (44100.0),
  19247. currentPhase (0.0),
  19248. phasePerSample (0.0),
  19249. amplitude (0.5f)
  19250. {
  19251. }
  19252. ToneGeneratorAudioSource::~ToneGeneratorAudioSource()
  19253. {
  19254. }
  19255. void ToneGeneratorAudioSource::setAmplitude (const float newAmplitude)
  19256. {
  19257. amplitude = newAmplitude;
  19258. }
  19259. void ToneGeneratorAudioSource::setFrequency (const double newFrequencyHz)
  19260. {
  19261. frequency = newFrequencyHz;
  19262. phasePerSample = 0.0;
  19263. }
  19264. void ToneGeneratorAudioSource::prepareToPlay (int /*samplesPerBlockExpected*/,
  19265. double sampleRate_)
  19266. {
  19267. currentPhase = 0.0;
  19268. phasePerSample = 0.0;
  19269. sampleRate = sampleRate_;
  19270. }
  19271. void ToneGeneratorAudioSource::releaseResources()
  19272. {
  19273. }
  19274. void ToneGeneratorAudioSource::getNextAudioBlock (const AudioSourceChannelInfo& info)
  19275. {
  19276. if (phasePerSample == 0.0)
  19277. phasePerSample = double_Pi * 2.0 / (sampleRate / frequency);
  19278. for (int i = 0; i < info.numSamples; ++i)
  19279. {
  19280. const float sample = amplitude * (float) sin (currentPhase);
  19281. currentPhase += phasePerSample;
  19282. for (int j = info.buffer->getNumChannels(); --j >= 0;)
  19283. *info.buffer->getSampleData (j, info.startSample + i) = sample;
  19284. }
  19285. }
  19286. END_JUCE_NAMESPACE
  19287. /********* End of inlined file: juce_ToneGeneratorAudioSource.cpp *********/
  19288. /********* Start of inlined file: juce_AudioDeviceManager.cpp *********/
  19289. BEGIN_JUCE_NAMESPACE
  19290. AudioDeviceManager::AudioDeviceSetup::AudioDeviceSetup()
  19291. : sampleRate (0),
  19292. bufferSize (0),
  19293. useDefaultInputChannels (true),
  19294. useDefaultOutputChannels (true)
  19295. {
  19296. }
  19297. bool AudioDeviceManager::AudioDeviceSetup::operator== (const AudioDeviceManager::AudioDeviceSetup& other) const
  19298. {
  19299. return outputDeviceName == other.outputDeviceName
  19300. && inputDeviceName == other.inputDeviceName
  19301. && sampleRate == other.sampleRate
  19302. && bufferSize == other.bufferSize
  19303. && inputChannels == other.inputChannels
  19304. && useDefaultInputChannels == other.useDefaultInputChannels
  19305. && outputChannels == other.outputChannels
  19306. && useDefaultOutputChannels == other.useDefaultOutputChannels;
  19307. }
  19308. AudioDeviceManager::AudioDeviceManager()
  19309. : currentAudioDevice (0),
  19310. numInputChansNeeded (0),
  19311. numOutputChansNeeded (2),
  19312. listNeedsScanning (true),
  19313. useInputNames (false),
  19314. inputLevelMeasurementEnabledCount (0),
  19315. inputLevel (0),
  19316. tempBuffer (2, 2),
  19317. defaultMidiOutput (0),
  19318. cpuUsageMs (0),
  19319. timeToCpuScale (0)
  19320. {
  19321. callbackHandler.owner = this;
  19322. }
  19323. AudioDeviceManager::~AudioDeviceManager()
  19324. {
  19325. currentAudioDevice = 0;
  19326. defaultMidiOutput = 0;
  19327. }
  19328. void AudioDeviceManager::createDeviceTypesIfNeeded()
  19329. {
  19330. if (availableDeviceTypes.size() == 0)
  19331. {
  19332. createAudioDeviceTypes (availableDeviceTypes);
  19333. while (lastDeviceTypeConfigs.size() < availableDeviceTypes.size())
  19334. lastDeviceTypeConfigs.add (new AudioDeviceSetup());
  19335. if (availableDeviceTypes.size() > 0)
  19336. currentDeviceType = availableDeviceTypes.getUnchecked(0)->getTypeName();
  19337. }
  19338. }
  19339. const OwnedArray <AudioIODeviceType>& AudioDeviceManager::getAvailableDeviceTypes()
  19340. {
  19341. scanDevicesIfNeeded();
  19342. return availableDeviceTypes;
  19343. }
  19344. AudioIODeviceType* juce_createAudioIODeviceType_CoreAudio();
  19345. AudioIODeviceType* juce_createAudioIODeviceType_iPhoneAudio();
  19346. AudioIODeviceType* juce_createAudioIODeviceType_WASAPI();
  19347. AudioIODeviceType* juce_createAudioIODeviceType_DirectSound();
  19348. AudioIODeviceType* juce_createAudioIODeviceType_ASIO();
  19349. AudioIODeviceType* juce_createAudioIODeviceType_ALSA();
  19350. AudioIODeviceType* juce_createAudioIODeviceType_JACK();
  19351. void AudioDeviceManager::createAudioDeviceTypes (OwnedArray <AudioIODeviceType>& list)
  19352. {
  19353. #if JUCE_WINDOWS
  19354. #if JUCE_WASAPI
  19355. if (SystemStats::getOperatingSystemType() >= SystemStats::WinVista)
  19356. list.add (juce_createAudioIODeviceType_WASAPI());
  19357. #endif
  19358. #if JUCE_DIRECTSOUND
  19359. list.add (juce_createAudioIODeviceType_DirectSound());
  19360. #endif
  19361. #if JUCE_ASIO
  19362. list.add (juce_createAudioIODeviceType_ASIO());
  19363. #endif
  19364. #endif
  19365. #if JUCE_MAC
  19366. list.add (juce_createAudioIODeviceType_CoreAudio());
  19367. #endif
  19368. #if JUCE_IPHONE
  19369. list.add (juce_createAudioIODeviceType_iPhoneAudio());
  19370. #endif
  19371. #if JUCE_LINUX && JUCE_ALSA
  19372. list.add (juce_createAudioIODeviceType_ALSA());
  19373. #endif
  19374. #if JUCE_LINUX && JUCE_JACK
  19375. list.add (juce_createAudioIODeviceType_JACK());
  19376. #endif
  19377. }
  19378. const String AudioDeviceManager::initialise (const int numInputChannelsNeeded,
  19379. const int numOutputChannelsNeeded,
  19380. const XmlElement* const e,
  19381. const bool selectDefaultDeviceOnFailure,
  19382. const String& preferredDefaultDeviceName,
  19383. const AudioDeviceSetup* preferredSetupOptions)
  19384. {
  19385. scanDevicesIfNeeded();
  19386. numInputChansNeeded = numInputChannelsNeeded;
  19387. numOutputChansNeeded = numOutputChannelsNeeded;
  19388. if (e != 0 && e->hasTagName (T("DEVICESETUP")))
  19389. {
  19390. lastExplicitSettings = new XmlElement (*e);
  19391. String error;
  19392. AudioDeviceSetup setup;
  19393. if (preferredSetupOptions != 0)
  19394. setup = *preferredSetupOptions;
  19395. if (e->getStringAttribute (T("audioDeviceName")).isNotEmpty())
  19396. {
  19397. setup.inputDeviceName = setup.outputDeviceName
  19398. = e->getStringAttribute (T("audioDeviceName"));
  19399. }
  19400. else
  19401. {
  19402. setup.inputDeviceName = e->getStringAttribute (T("audioInputDeviceName"));
  19403. setup.outputDeviceName = e->getStringAttribute (T("audioOutputDeviceName"));
  19404. }
  19405. currentDeviceType = e->getStringAttribute (T("deviceType"));
  19406. if (currentDeviceType.isEmpty())
  19407. {
  19408. AudioIODeviceType* const type = findType (setup.inputDeviceName, setup.outputDeviceName);
  19409. if (type != 0)
  19410. currentDeviceType = type->getTypeName();
  19411. else if (availableDeviceTypes.size() > 0)
  19412. currentDeviceType = availableDeviceTypes[0]->getTypeName();
  19413. }
  19414. setup.bufferSize = e->getIntAttribute (T("audioDeviceBufferSize"));
  19415. setup.sampleRate = e->getDoubleAttribute (T("audioDeviceRate"));
  19416. setup.inputChannels.parseString (e->getStringAttribute (T("audioDeviceInChans"), T("11")), 2);
  19417. setup.outputChannels.parseString (e->getStringAttribute (T("audioDeviceOutChans"), T("11")), 2);
  19418. setup.useDefaultInputChannels = ! e->hasAttribute (T("audioDeviceInChans"));
  19419. setup.useDefaultOutputChannels = ! e->hasAttribute (T("audioDeviceOutChans"));
  19420. error = setAudioDeviceSetup (setup, true);
  19421. midiInsFromXml.clear();
  19422. forEachXmlChildElementWithTagName (*e, c, T("MIDIINPUT"))
  19423. midiInsFromXml.add (c->getStringAttribute (T("name")));
  19424. const StringArray allMidiIns (MidiInput::getDevices());
  19425. for (int i = allMidiIns.size(); --i >= 0;)
  19426. setMidiInputEnabled (allMidiIns[i], midiInsFromXml.contains (allMidiIns[i]));
  19427. if (error.isNotEmpty() && selectDefaultDeviceOnFailure)
  19428. error = initialise (numInputChannelsNeeded, numOutputChannelsNeeded, 0,
  19429. false, preferredDefaultDeviceName);
  19430. setDefaultMidiOutput (e->getStringAttribute (T("defaultMidiOutput")));
  19431. return error;
  19432. }
  19433. else
  19434. {
  19435. AudioDeviceSetup setup;
  19436. if (preferredSetupOptions != 0)
  19437. {
  19438. setup = *preferredSetupOptions;
  19439. }
  19440. else if (preferredDefaultDeviceName.isNotEmpty())
  19441. {
  19442. for (int j = availableDeviceTypes.size(); --j >= 0;)
  19443. {
  19444. AudioIODeviceType* const type = availableDeviceTypes.getUnchecked(j);
  19445. StringArray outs (type->getDeviceNames (false));
  19446. int i;
  19447. for (i = 0; i < outs.size(); ++i)
  19448. {
  19449. if (outs[i].matchesWildcard (preferredDefaultDeviceName, true))
  19450. {
  19451. setup.outputDeviceName = outs[i];
  19452. break;
  19453. }
  19454. }
  19455. StringArray ins (type->getDeviceNames (true));
  19456. for (i = 0; i < ins.size(); ++i)
  19457. {
  19458. if (ins[i].matchesWildcard (preferredDefaultDeviceName, true))
  19459. {
  19460. setup.inputDeviceName = ins[i];
  19461. break;
  19462. }
  19463. }
  19464. }
  19465. }
  19466. insertDefaultDeviceNames (setup);
  19467. return setAudioDeviceSetup (setup, false);
  19468. }
  19469. }
  19470. void AudioDeviceManager::insertDefaultDeviceNames (AudioDeviceSetup& setup) const
  19471. {
  19472. AudioIODeviceType* type = getCurrentDeviceTypeObject();
  19473. if (type != 0)
  19474. {
  19475. if (setup.outputDeviceName.isEmpty())
  19476. setup.outputDeviceName = type->getDeviceNames (false) [type->getDefaultDeviceIndex (false)];
  19477. if (setup.inputDeviceName.isEmpty())
  19478. setup.inputDeviceName = type->getDeviceNames (true) [type->getDefaultDeviceIndex (true)];
  19479. }
  19480. }
  19481. XmlElement* AudioDeviceManager::createStateXml() const
  19482. {
  19483. return lastExplicitSettings != 0 ? new XmlElement (*lastExplicitSettings) : 0;
  19484. }
  19485. void AudioDeviceManager::scanDevicesIfNeeded()
  19486. {
  19487. if (listNeedsScanning)
  19488. {
  19489. listNeedsScanning = false;
  19490. createDeviceTypesIfNeeded();
  19491. for (int i = availableDeviceTypes.size(); --i >= 0;)
  19492. availableDeviceTypes.getUnchecked(i)->scanForDevices();
  19493. }
  19494. }
  19495. AudioIODeviceType* AudioDeviceManager::findType (const String& inputName, const String& outputName)
  19496. {
  19497. scanDevicesIfNeeded();
  19498. for (int i = availableDeviceTypes.size(); --i >= 0;)
  19499. {
  19500. AudioIODeviceType* const type = availableDeviceTypes.getUnchecked(i);
  19501. if ((inputName.isNotEmpty() && type->getDeviceNames (true).contains (inputName, true))
  19502. || (outputName.isNotEmpty() && type->getDeviceNames (false).contains (outputName, true)))
  19503. {
  19504. return type;
  19505. }
  19506. }
  19507. return 0;
  19508. }
  19509. void AudioDeviceManager::getAudioDeviceSetup (AudioDeviceSetup& setup)
  19510. {
  19511. setup = currentSetup;
  19512. }
  19513. void AudioDeviceManager::deleteCurrentDevice()
  19514. {
  19515. currentAudioDevice = 0;
  19516. currentSetup.inputDeviceName = String::empty;
  19517. currentSetup.outputDeviceName = String::empty;
  19518. }
  19519. void AudioDeviceManager::setCurrentAudioDeviceType (const String& type,
  19520. const bool treatAsChosenDevice)
  19521. {
  19522. for (int i = 0; i < availableDeviceTypes.size(); ++i)
  19523. {
  19524. if (availableDeviceTypes.getUnchecked(i)->getTypeName() == type
  19525. && currentDeviceType != type)
  19526. {
  19527. currentDeviceType = type;
  19528. AudioDeviceSetup s (*lastDeviceTypeConfigs.getUnchecked(i));
  19529. insertDefaultDeviceNames (s);
  19530. setAudioDeviceSetup (s, treatAsChosenDevice);
  19531. sendChangeMessage (this);
  19532. break;
  19533. }
  19534. }
  19535. }
  19536. AudioIODeviceType* AudioDeviceManager::getCurrentDeviceTypeObject() const
  19537. {
  19538. for (int i = 0; i < availableDeviceTypes.size(); ++i)
  19539. if (availableDeviceTypes[i]->getTypeName() == currentDeviceType)
  19540. return availableDeviceTypes[i];
  19541. return availableDeviceTypes[0];
  19542. }
  19543. const String AudioDeviceManager::setAudioDeviceSetup (const AudioDeviceSetup& newSetup,
  19544. const bool treatAsChosenDevice)
  19545. {
  19546. jassert (&newSetup != &currentSetup); // this will have no effect
  19547. if (newSetup == currentSetup && currentAudioDevice != 0)
  19548. return String::empty;
  19549. if (! (newSetup == currentSetup))
  19550. sendChangeMessage (this);
  19551. stopDevice();
  19552. const String newInputDeviceName (numInputChansNeeded == 0 ? String::empty : newSetup.inputDeviceName);
  19553. const String newOutputDeviceName (numOutputChansNeeded == 0 ? String::empty : newSetup.outputDeviceName);
  19554. String error;
  19555. AudioIODeviceType* type = getCurrentDeviceTypeObject();
  19556. if (type == 0 || (newInputDeviceName.isEmpty() && newOutputDeviceName.isEmpty()))
  19557. {
  19558. deleteCurrentDevice();
  19559. if (treatAsChosenDevice)
  19560. updateXml();
  19561. return String::empty;
  19562. }
  19563. if (currentSetup.inputDeviceName != newInputDeviceName
  19564. || currentSetup.outputDeviceName != newOutputDeviceName
  19565. || currentAudioDevice == 0)
  19566. {
  19567. deleteCurrentDevice();
  19568. scanDevicesIfNeeded();
  19569. if (newOutputDeviceName.isNotEmpty()
  19570. && ! type->getDeviceNames (false).contains (newOutputDeviceName))
  19571. {
  19572. return "No such device: " + newOutputDeviceName;
  19573. }
  19574. if (newInputDeviceName.isNotEmpty()
  19575. && ! type->getDeviceNames (true).contains (newInputDeviceName))
  19576. {
  19577. return "No such device: " + newInputDeviceName;
  19578. }
  19579. currentAudioDevice = type->createDevice (newOutputDeviceName, newInputDeviceName);
  19580. if (currentAudioDevice == 0)
  19581. 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!";
  19582. else
  19583. error = currentAudioDevice->getLastError();
  19584. if (error.isNotEmpty())
  19585. {
  19586. deleteCurrentDevice();
  19587. return error;
  19588. }
  19589. if (newSetup.useDefaultInputChannels)
  19590. {
  19591. inputChannels.clear();
  19592. inputChannels.setRange (0, numInputChansNeeded, true);
  19593. }
  19594. if (newSetup.useDefaultOutputChannels)
  19595. {
  19596. outputChannels.clear();
  19597. outputChannels.setRange (0, numOutputChansNeeded, true);
  19598. }
  19599. if (newInputDeviceName.isEmpty())
  19600. inputChannels.clear();
  19601. if (newOutputDeviceName.isEmpty())
  19602. outputChannels.clear();
  19603. }
  19604. if (! newSetup.useDefaultInputChannels)
  19605. inputChannels = newSetup.inputChannels;
  19606. if (! newSetup.useDefaultOutputChannels)
  19607. outputChannels = newSetup.outputChannels;
  19608. currentSetup = newSetup;
  19609. currentSetup.sampleRate = chooseBestSampleRate (newSetup.sampleRate);
  19610. error = currentAudioDevice->open (inputChannels,
  19611. outputChannels,
  19612. currentSetup.sampleRate,
  19613. currentSetup.bufferSize);
  19614. if (error.isEmpty())
  19615. {
  19616. currentDeviceType = currentAudioDevice->getTypeName();
  19617. currentAudioDevice->start (&callbackHandler);
  19618. currentSetup.sampleRate = currentAudioDevice->getCurrentSampleRate();
  19619. currentSetup.bufferSize = currentAudioDevice->getCurrentBufferSizeSamples();
  19620. currentSetup.inputChannels = currentAudioDevice->getActiveInputChannels();
  19621. currentSetup.outputChannels = currentAudioDevice->getActiveOutputChannels();
  19622. for (int i = 0; i < availableDeviceTypes.size(); ++i)
  19623. if (availableDeviceTypes.getUnchecked (i)->getTypeName() == currentDeviceType)
  19624. *(lastDeviceTypeConfigs.getUnchecked (i)) = currentSetup;
  19625. if (treatAsChosenDevice)
  19626. updateXml();
  19627. }
  19628. else
  19629. {
  19630. deleteCurrentDevice();
  19631. }
  19632. return error;
  19633. }
  19634. double AudioDeviceManager::chooseBestSampleRate (double rate) const
  19635. {
  19636. jassert (currentAudioDevice != 0);
  19637. if (rate > 0)
  19638. {
  19639. bool ok = false;
  19640. for (int i = currentAudioDevice->getNumSampleRates(); --i >= 0;)
  19641. {
  19642. const double sr = currentAudioDevice->getSampleRate (i);
  19643. if (sr == rate)
  19644. ok = true;
  19645. }
  19646. if (! ok)
  19647. rate = 0;
  19648. }
  19649. if (rate == 0)
  19650. {
  19651. double lowestAbove44 = 0.0;
  19652. for (int i = currentAudioDevice->getNumSampleRates(); --i >= 0;)
  19653. {
  19654. const double sr = currentAudioDevice->getSampleRate (i);
  19655. if (sr >= 44100.0 && (lowestAbove44 == 0 || sr < lowestAbove44))
  19656. lowestAbove44 = sr;
  19657. }
  19658. if (lowestAbove44 == 0.0)
  19659. rate = currentAudioDevice->getSampleRate (0);
  19660. else
  19661. rate = lowestAbove44;
  19662. }
  19663. return rate;
  19664. }
  19665. void AudioDeviceManager::stopDevice()
  19666. {
  19667. if (currentAudioDevice != 0)
  19668. currentAudioDevice->stop();
  19669. testSound = 0;
  19670. }
  19671. void AudioDeviceManager::closeAudioDevice()
  19672. {
  19673. stopDevice();
  19674. currentAudioDevice = 0;
  19675. }
  19676. void AudioDeviceManager::restartLastAudioDevice()
  19677. {
  19678. if (currentAudioDevice == 0)
  19679. {
  19680. if (currentSetup.inputDeviceName.isEmpty()
  19681. && currentSetup.outputDeviceName.isEmpty())
  19682. {
  19683. // This method will only reload the last device that was running
  19684. // before closeAudioDevice() was called - you need to actually open
  19685. // one first, with setAudioDevice().
  19686. jassertfalse
  19687. return;
  19688. }
  19689. AudioDeviceSetup s (currentSetup);
  19690. setAudioDeviceSetup (s, false);
  19691. }
  19692. }
  19693. void AudioDeviceManager::updateXml()
  19694. {
  19695. lastExplicitSettings = new XmlElement (T("DEVICESETUP"));
  19696. lastExplicitSettings->setAttribute (T("deviceType"), currentDeviceType);
  19697. lastExplicitSettings->setAttribute (T("audioOutputDeviceName"), currentSetup.outputDeviceName);
  19698. lastExplicitSettings->setAttribute (T("audioInputDeviceName"), currentSetup.inputDeviceName);
  19699. if (currentAudioDevice != 0)
  19700. {
  19701. lastExplicitSettings->setAttribute (T("audioDeviceRate"), currentAudioDevice->getCurrentSampleRate());
  19702. if (currentAudioDevice->getDefaultBufferSize() != currentAudioDevice->getCurrentBufferSizeSamples())
  19703. lastExplicitSettings->setAttribute (T("audioDeviceBufferSize"), currentAudioDevice->getCurrentBufferSizeSamples());
  19704. if (! currentSetup.useDefaultInputChannels)
  19705. lastExplicitSettings->setAttribute (T("audioDeviceInChans"), currentSetup.inputChannels.toString (2));
  19706. if (! currentSetup.useDefaultOutputChannels)
  19707. lastExplicitSettings->setAttribute (T("audioDeviceOutChans"), currentSetup.outputChannels.toString (2));
  19708. }
  19709. for (int i = 0; i < enabledMidiInputs.size(); ++i)
  19710. {
  19711. XmlElement* const m = new XmlElement (T("MIDIINPUT"));
  19712. m->setAttribute (T("name"), enabledMidiInputs[i]->getName());
  19713. lastExplicitSettings->addChildElement (m);
  19714. }
  19715. if (midiInsFromXml.size() > 0)
  19716. {
  19717. // Add any midi devices that have been enabled before, but which aren't currently
  19718. // open because the device has been disconnected.
  19719. const StringArray availableMidiDevices (MidiInput::getDevices());
  19720. for (int i = 0; i < midiInsFromXml.size(); ++i)
  19721. {
  19722. if (! availableMidiDevices.contains (midiInsFromXml[i], true))
  19723. {
  19724. XmlElement* const m = new XmlElement (T("MIDIINPUT"));
  19725. m->setAttribute (T("name"), midiInsFromXml[i]);
  19726. lastExplicitSettings->addChildElement (m);
  19727. }
  19728. }
  19729. }
  19730. if (defaultMidiOutputName.isNotEmpty())
  19731. lastExplicitSettings->setAttribute (T("defaultMidiOutput"), defaultMidiOutputName);
  19732. }
  19733. void AudioDeviceManager::addAudioCallback (AudioIODeviceCallback* newCallback)
  19734. {
  19735. {
  19736. const ScopedLock sl (audioCallbackLock);
  19737. if (callbacks.contains (newCallback))
  19738. return;
  19739. }
  19740. if (currentAudioDevice != 0 && newCallback != 0)
  19741. newCallback->audioDeviceAboutToStart (currentAudioDevice);
  19742. const ScopedLock sl (audioCallbackLock);
  19743. callbacks.add (newCallback);
  19744. }
  19745. void AudioDeviceManager::removeAudioCallback (AudioIODeviceCallback* callback)
  19746. {
  19747. if (callback != 0)
  19748. {
  19749. bool needsDeinitialising = currentAudioDevice != 0;
  19750. {
  19751. const ScopedLock sl (audioCallbackLock);
  19752. needsDeinitialising = needsDeinitialising && callbacks.contains (callback);
  19753. callbacks.removeValue (callback);
  19754. }
  19755. if (needsDeinitialising)
  19756. callback->audioDeviceStopped();
  19757. }
  19758. }
  19759. void AudioDeviceManager::audioDeviceIOCallbackInt (const float** inputChannelData,
  19760. int numInputChannels,
  19761. float** outputChannelData,
  19762. int numOutputChannels,
  19763. int numSamples)
  19764. {
  19765. const ScopedLock sl (audioCallbackLock);
  19766. if (inputLevelMeasurementEnabledCount > 0)
  19767. {
  19768. for (int j = 0; j < numSamples; ++j)
  19769. {
  19770. float s = 0;
  19771. for (int i = 0; i < numInputChannels; ++i)
  19772. s += fabsf (inputChannelData[i][j]);
  19773. s /= numInputChannels;
  19774. const double decayFactor = 0.99992;
  19775. if (s > inputLevel)
  19776. inputLevel = s;
  19777. else if (inputLevel > 0.001f)
  19778. inputLevel *= decayFactor;
  19779. else
  19780. inputLevel = 0;
  19781. }
  19782. }
  19783. if (callbacks.size() > 0)
  19784. {
  19785. const double callbackStartTime = Time::getMillisecondCounterHiRes();
  19786. tempBuffer.setSize (jmax (1, numOutputChannels), jmax (1, numSamples), false, false, true);
  19787. callbacks.getUnchecked(0)->audioDeviceIOCallback (inputChannelData, numInputChannels,
  19788. outputChannelData, numOutputChannels, numSamples);
  19789. float** const tempChans = tempBuffer.getArrayOfChannels();
  19790. for (int i = callbacks.size(); --i > 0;)
  19791. {
  19792. callbacks.getUnchecked(i)->audioDeviceIOCallback (inputChannelData, numInputChannels,
  19793. tempChans, numOutputChannels, numSamples);
  19794. for (int chan = 0; chan < numOutputChannels; ++chan)
  19795. {
  19796. const float* const src = tempChans [chan];
  19797. float* const dst = outputChannelData [chan];
  19798. if (src != 0 && dst != 0)
  19799. for (int j = 0; j < numSamples; ++j)
  19800. dst[j] += src[j];
  19801. }
  19802. }
  19803. const double msTaken = Time::getMillisecondCounterHiRes() - callbackStartTime;
  19804. const double filterAmount = 0.2;
  19805. cpuUsageMs += filterAmount * (msTaken - cpuUsageMs);
  19806. }
  19807. else
  19808. {
  19809. for (int i = 0; i < numOutputChannels; ++i)
  19810. zeromem (outputChannelData[i], sizeof (float) * numSamples);
  19811. }
  19812. if (testSound != 0)
  19813. {
  19814. const int numSamps = jmin (numSamples, testSound->getNumSamples() - testSoundPosition);
  19815. const float* const src = testSound->getSampleData (0, testSoundPosition);
  19816. for (int i = 0; i < numOutputChannels; ++i)
  19817. for (int j = 0; j < numSamps; ++j)
  19818. outputChannelData [i][j] += src[j];
  19819. testSoundPosition += numSamps;
  19820. if (testSoundPosition >= testSound->getNumSamples())
  19821. testSound = 0;
  19822. }
  19823. }
  19824. void AudioDeviceManager::audioDeviceAboutToStartInt (AudioIODevice* const device)
  19825. {
  19826. cpuUsageMs = 0;
  19827. const double sampleRate = device->getCurrentSampleRate();
  19828. const int blockSize = device->getCurrentBufferSizeSamples();
  19829. if (sampleRate > 0.0 && blockSize > 0)
  19830. {
  19831. const double msPerBlock = 1000.0 * blockSize / sampleRate;
  19832. timeToCpuScale = (msPerBlock > 0.0) ? (1.0 / msPerBlock) : 0.0;
  19833. }
  19834. {
  19835. const ScopedLock sl (audioCallbackLock);
  19836. for (int i = callbacks.size(); --i >= 0;)
  19837. callbacks.getUnchecked(i)->audioDeviceAboutToStart (device);
  19838. }
  19839. sendChangeMessage (this);
  19840. }
  19841. void AudioDeviceManager::audioDeviceStoppedInt()
  19842. {
  19843. cpuUsageMs = 0;
  19844. timeToCpuScale = 0;
  19845. sendChangeMessage (this);
  19846. const ScopedLock sl (audioCallbackLock);
  19847. for (int i = callbacks.size(); --i >= 0;)
  19848. callbacks.getUnchecked(i)->audioDeviceStopped();
  19849. }
  19850. double AudioDeviceManager::getCpuUsage() const
  19851. {
  19852. return jlimit (0.0, 1.0, timeToCpuScale * cpuUsageMs);
  19853. }
  19854. void AudioDeviceManager::setMidiInputEnabled (const String& name,
  19855. const bool enabled)
  19856. {
  19857. if (enabled != isMidiInputEnabled (name))
  19858. {
  19859. if (enabled)
  19860. {
  19861. const int index = MidiInput::getDevices().indexOf (name);
  19862. if (index >= 0)
  19863. {
  19864. MidiInput* const min = MidiInput::openDevice (index, &callbackHandler);
  19865. if (min != 0)
  19866. {
  19867. enabledMidiInputs.add (min);
  19868. min->start();
  19869. }
  19870. }
  19871. }
  19872. else
  19873. {
  19874. for (int i = enabledMidiInputs.size(); --i >= 0;)
  19875. if (enabledMidiInputs[i]->getName() == name)
  19876. enabledMidiInputs.remove (i);
  19877. }
  19878. updateXml();
  19879. sendChangeMessage (this);
  19880. }
  19881. }
  19882. bool AudioDeviceManager::isMidiInputEnabled (const String& name) const
  19883. {
  19884. for (int i = enabledMidiInputs.size(); --i >= 0;)
  19885. if (enabledMidiInputs[i]->getName() == name)
  19886. return true;
  19887. return false;
  19888. }
  19889. void AudioDeviceManager::addMidiInputCallback (const String& name,
  19890. MidiInputCallback* callback)
  19891. {
  19892. removeMidiInputCallback (name, callback);
  19893. if (name.isEmpty())
  19894. {
  19895. midiCallbacks.add (callback);
  19896. midiCallbackDevices.add (0);
  19897. }
  19898. else
  19899. {
  19900. for (int i = enabledMidiInputs.size(); --i >= 0;)
  19901. {
  19902. if (enabledMidiInputs[i]->getName() == name)
  19903. {
  19904. const ScopedLock sl (midiCallbackLock);
  19905. midiCallbacks.add (callback);
  19906. midiCallbackDevices.add (enabledMidiInputs[i]);
  19907. break;
  19908. }
  19909. }
  19910. }
  19911. }
  19912. void AudioDeviceManager::removeMidiInputCallback (const String& name,
  19913. MidiInputCallback* /*callback*/)
  19914. {
  19915. const ScopedLock sl (midiCallbackLock);
  19916. for (int i = midiCallbacks.size(); --i >= 0;)
  19917. {
  19918. String devName;
  19919. if (midiCallbackDevices.getUnchecked(i) != 0)
  19920. devName = midiCallbackDevices.getUnchecked(i)->getName();
  19921. if (devName == name)
  19922. {
  19923. midiCallbacks.remove (i);
  19924. midiCallbackDevices.remove (i);
  19925. }
  19926. }
  19927. }
  19928. void AudioDeviceManager::handleIncomingMidiMessageInt (MidiInput* source,
  19929. const MidiMessage& message)
  19930. {
  19931. if (! message.isActiveSense())
  19932. {
  19933. const bool isDefaultSource = (source == 0 || source == enabledMidiInputs.getFirst());
  19934. const ScopedLock sl (midiCallbackLock);
  19935. for (int i = midiCallbackDevices.size(); --i >= 0;)
  19936. {
  19937. MidiInput* const md = midiCallbackDevices.getUnchecked(i);
  19938. if (md == source || (md == 0 && isDefaultSource))
  19939. midiCallbacks.getUnchecked(i)->handleIncomingMidiMessage (source, message);
  19940. }
  19941. }
  19942. }
  19943. void AudioDeviceManager::setDefaultMidiOutput (const String& deviceName)
  19944. {
  19945. if (defaultMidiOutputName != deviceName)
  19946. {
  19947. SortedSet <AudioIODeviceCallback*> oldCallbacks;
  19948. {
  19949. const ScopedLock sl (audioCallbackLock);
  19950. oldCallbacks = callbacks;
  19951. callbacks.clear();
  19952. }
  19953. if (currentAudioDevice != 0)
  19954. for (int i = oldCallbacks.size(); --i >= 0;)
  19955. oldCallbacks.getUnchecked(i)->audioDeviceStopped();
  19956. defaultMidiOutput = 0;
  19957. defaultMidiOutputName = deviceName;
  19958. if (deviceName.isNotEmpty())
  19959. defaultMidiOutput = MidiOutput::openDevice (MidiOutput::getDevices().indexOf (deviceName));
  19960. if (currentAudioDevice != 0)
  19961. for (int i = oldCallbacks.size(); --i >= 0;)
  19962. oldCallbacks.getUnchecked(i)->audioDeviceAboutToStart (currentAudioDevice);
  19963. {
  19964. const ScopedLock sl (audioCallbackLock);
  19965. callbacks = oldCallbacks;
  19966. }
  19967. updateXml();
  19968. sendChangeMessage (this);
  19969. }
  19970. }
  19971. void AudioDeviceManager::CallbackHandler::audioDeviceIOCallback (const float** inputChannelData,
  19972. int numInputChannels,
  19973. float** outputChannelData,
  19974. int numOutputChannels,
  19975. int numSamples)
  19976. {
  19977. owner->audioDeviceIOCallbackInt (inputChannelData, numInputChannels, outputChannelData, numOutputChannels, numSamples);
  19978. }
  19979. void AudioDeviceManager::CallbackHandler::audioDeviceAboutToStart (AudioIODevice* device)
  19980. {
  19981. owner->audioDeviceAboutToStartInt (device);
  19982. }
  19983. void AudioDeviceManager::CallbackHandler::audioDeviceStopped()
  19984. {
  19985. owner->audioDeviceStoppedInt();
  19986. }
  19987. void AudioDeviceManager::CallbackHandler::handleIncomingMidiMessage (MidiInput* source, const MidiMessage& message)
  19988. {
  19989. owner->handleIncomingMidiMessageInt (source, message);
  19990. }
  19991. void AudioDeviceManager::playTestSound()
  19992. {
  19993. {
  19994. audioCallbackLock.enter();
  19995. ScopedPointer <AudioSampleBuffer> oldSound (testSound);
  19996. audioCallbackLock.exit();
  19997. }
  19998. testSoundPosition = 0;
  19999. if (currentAudioDevice != 0)
  20000. {
  20001. const double sampleRate = currentAudioDevice->getCurrentSampleRate();
  20002. const int soundLength = (int) sampleRate;
  20003. AudioSampleBuffer* const newSound = new AudioSampleBuffer (1, soundLength);
  20004. float* samples = newSound->getSampleData (0);
  20005. const double frequency = MidiMessage::getMidiNoteInHertz (80);
  20006. const float amplitude = 0.5f;
  20007. const double phasePerSample = double_Pi * 2.0 / (sampleRate / frequency);
  20008. for (int i = 0; i < soundLength; ++i)
  20009. samples[i] = amplitude * (float) sin (i * phasePerSample);
  20010. newSound->applyGainRamp (0, 0, soundLength / 10, 0.0f, 1.0f);
  20011. newSound->applyGainRamp (0, soundLength - soundLength / 4, soundLength / 4, 1.0f, 0.0f);
  20012. const ScopedLock sl (audioCallbackLock);
  20013. testSound = newSound;
  20014. }
  20015. }
  20016. void AudioDeviceManager::enableInputLevelMeasurement (const bool enableMeasurement)
  20017. {
  20018. const ScopedLock sl (audioCallbackLock);
  20019. if (enableMeasurement)
  20020. ++inputLevelMeasurementEnabledCount;
  20021. else
  20022. --inputLevelMeasurementEnabledCount;
  20023. inputLevel = 0;
  20024. }
  20025. double AudioDeviceManager::getCurrentInputLevel() const
  20026. {
  20027. jassert (inputLevelMeasurementEnabledCount > 0); // you need to call enableInputLevelMeasurement() before using this!
  20028. return inputLevel;
  20029. }
  20030. END_JUCE_NAMESPACE
  20031. /********* End of inlined file: juce_AudioDeviceManager.cpp *********/
  20032. /********* Start of inlined file: juce_AudioIODevice.cpp *********/
  20033. BEGIN_JUCE_NAMESPACE
  20034. AudioIODevice::AudioIODevice (const String& deviceName, const String& typeName_)
  20035. : name (deviceName),
  20036. typeName (typeName_)
  20037. {
  20038. }
  20039. AudioIODevice::~AudioIODevice()
  20040. {
  20041. }
  20042. bool AudioIODevice::hasControlPanel() const
  20043. {
  20044. return false;
  20045. }
  20046. bool AudioIODevice::showControlPanel()
  20047. {
  20048. jassertfalse // this should only be called for devices which return true from
  20049. // their hasControlPanel() method.
  20050. return false;
  20051. }
  20052. END_JUCE_NAMESPACE
  20053. /********* End of inlined file: juce_AudioIODevice.cpp *********/
  20054. /********* Start of inlined file: juce_AudioIODeviceType.cpp *********/
  20055. BEGIN_JUCE_NAMESPACE
  20056. AudioIODeviceType::AudioIODeviceType (const tchar* const name)
  20057. : typeName (name)
  20058. {
  20059. }
  20060. AudioIODeviceType::~AudioIODeviceType()
  20061. {
  20062. }
  20063. END_JUCE_NAMESPACE
  20064. /********* End of inlined file: juce_AudioIODeviceType.cpp *********/
  20065. /********* Start of inlined file: juce_MidiOutput.cpp *********/
  20066. BEGIN_JUCE_NAMESPACE
  20067. MidiOutput::MidiOutput() throw()
  20068. : Thread ("midi out"),
  20069. internal (0),
  20070. firstMessage (0)
  20071. {
  20072. }
  20073. MidiOutput::PendingMessage::PendingMessage (const uint8* const data,
  20074. const int len,
  20075. const double sampleNumber) throw()
  20076. : message (data, len, sampleNumber)
  20077. {
  20078. }
  20079. void MidiOutput::sendBlockOfMessages (const MidiBuffer& buffer,
  20080. const double millisecondCounterToStartAt,
  20081. double samplesPerSecondForBuffer) throw()
  20082. {
  20083. // You've got to call startBackgroundThread() for this to actually work..
  20084. jassert (isThreadRunning());
  20085. // this needs to be a value in the future - RTFM for this method!
  20086. jassert (millisecondCounterToStartAt > 0);
  20087. const double timeScaleFactor = 1000.0 / samplesPerSecondForBuffer;
  20088. MidiBuffer::Iterator i (buffer);
  20089. const uint8* data;
  20090. int len, time;
  20091. while (i.getNextEvent (data, len, time))
  20092. {
  20093. const double eventTime = millisecondCounterToStartAt + timeScaleFactor * time;
  20094. PendingMessage* const m
  20095. = new PendingMessage (data, len, eventTime);
  20096. const ScopedLock sl (lock);
  20097. if (firstMessage == 0 || firstMessage->message.getTimeStamp() > eventTime)
  20098. {
  20099. m->next = firstMessage;
  20100. firstMessage = m;
  20101. }
  20102. else
  20103. {
  20104. PendingMessage* mm = firstMessage;
  20105. while (mm->next != 0 && mm->next->message.getTimeStamp() <= eventTime)
  20106. mm = mm->next;
  20107. m->next = mm->next;
  20108. mm->next = m;
  20109. }
  20110. }
  20111. notify();
  20112. }
  20113. void MidiOutput::clearAllPendingMessages() throw()
  20114. {
  20115. const ScopedLock sl (lock);
  20116. while (firstMessage != 0)
  20117. {
  20118. PendingMessage* const m = firstMessage;
  20119. firstMessage = firstMessage->next;
  20120. delete m;
  20121. }
  20122. }
  20123. void MidiOutput::startBackgroundThread() throw()
  20124. {
  20125. startThread (9);
  20126. }
  20127. void MidiOutput::stopBackgroundThread() throw()
  20128. {
  20129. stopThread (5000);
  20130. }
  20131. void MidiOutput::run()
  20132. {
  20133. while (! threadShouldExit())
  20134. {
  20135. uint32 now = Time::getMillisecondCounter();
  20136. uint32 eventTime = 0;
  20137. uint32 timeToWait = 500;
  20138. lock.enter();
  20139. PendingMessage* message = firstMessage;
  20140. if (message != 0)
  20141. {
  20142. eventTime = roundToInt (message->message.getTimeStamp());
  20143. if (eventTime > now + 20)
  20144. {
  20145. timeToWait = eventTime - (now + 20);
  20146. message = 0;
  20147. }
  20148. else
  20149. {
  20150. firstMessage = message->next;
  20151. }
  20152. }
  20153. lock.exit();
  20154. if (message != 0)
  20155. {
  20156. if (eventTime > now)
  20157. {
  20158. Time::waitForMillisecondCounter (eventTime);
  20159. if (threadShouldExit())
  20160. break;
  20161. }
  20162. if (eventTime > now - 200)
  20163. sendMessageNow (message->message);
  20164. delete message;
  20165. }
  20166. else
  20167. {
  20168. jassert (timeToWait < 1000 * 30);
  20169. wait (timeToWait);
  20170. }
  20171. }
  20172. clearAllPendingMessages();
  20173. }
  20174. END_JUCE_NAMESPACE
  20175. /********* End of inlined file: juce_MidiOutput.cpp *********/
  20176. /********* Start of inlined file: juce_AudioDataConverters.cpp *********/
  20177. BEGIN_JUCE_NAMESPACE
  20178. void AudioDataConverters::convertFloatToInt16LE (const float* source, void* dest, int numSamples, const int destBytesPerSample)
  20179. {
  20180. const double maxVal = (double) 0x7fff;
  20181. char* intData = (char*) dest;
  20182. if (dest != (void*) source || destBytesPerSample <= 4)
  20183. {
  20184. for (int i = 0; i < numSamples; ++i)
  20185. {
  20186. *(uint16*)intData = ByteOrder::swapIfBigEndian ((uint16) (short) roundToInt (jlimit (-maxVal, maxVal, maxVal * source[i])));
  20187. intData += destBytesPerSample;
  20188. }
  20189. }
  20190. else
  20191. {
  20192. intData += destBytesPerSample * numSamples;
  20193. for (int i = numSamples; --i >= 0;)
  20194. {
  20195. intData -= destBytesPerSample;
  20196. *(uint16*)intData = ByteOrder::swapIfBigEndian ((uint16) (short) roundToInt (jlimit (-maxVal, maxVal, maxVal * source[i])));
  20197. }
  20198. }
  20199. }
  20200. void AudioDataConverters::convertFloatToInt16BE (const float* source, void* dest, int numSamples, const int destBytesPerSample)
  20201. {
  20202. const double maxVal = (double) 0x7fff;
  20203. char* intData = (char*) dest;
  20204. if (dest != (void*) source || destBytesPerSample <= 4)
  20205. {
  20206. for (int i = 0; i < numSamples; ++i)
  20207. {
  20208. *(uint16*) intData = ByteOrder::swapIfLittleEndian ((uint16) (short) roundToInt (jlimit (-maxVal, maxVal, maxVal * source[i])));
  20209. intData += destBytesPerSample;
  20210. }
  20211. }
  20212. else
  20213. {
  20214. intData += destBytesPerSample * numSamples;
  20215. for (int i = numSamples; --i >= 0;)
  20216. {
  20217. intData -= destBytesPerSample;
  20218. *(uint16*)intData = ByteOrder::swapIfLittleEndian ((uint16) (short) roundToInt (jlimit (-maxVal, maxVal, maxVal * source[i])));
  20219. }
  20220. }
  20221. }
  20222. void AudioDataConverters::convertFloatToInt24LE (const float* source, void* dest, int numSamples, const int destBytesPerSample)
  20223. {
  20224. const double maxVal = (double) 0x7fffff;
  20225. char* intData = (char*) dest;
  20226. if (dest != (void*) source || destBytesPerSample <= 4)
  20227. {
  20228. for (int i = 0; i < numSamples; ++i)
  20229. {
  20230. ByteOrder::littleEndian24BitToChars ((uint32) roundToInt (jlimit (-maxVal, maxVal, maxVal * source[i])), intData);
  20231. intData += destBytesPerSample;
  20232. }
  20233. }
  20234. else
  20235. {
  20236. intData += destBytesPerSample * numSamples;
  20237. for (int i = numSamples; --i >= 0;)
  20238. {
  20239. intData -= destBytesPerSample;
  20240. ByteOrder::littleEndian24BitToChars ((uint32) roundToInt (jlimit (-maxVal, maxVal, maxVal * source[i])), intData);
  20241. }
  20242. }
  20243. }
  20244. void AudioDataConverters::convertFloatToInt24BE (const float* source, void* dest, int numSamples, const int destBytesPerSample)
  20245. {
  20246. const double maxVal = (double) 0x7fffff;
  20247. char* intData = (char*) dest;
  20248. if (dest != (void*) source || destBytesPerSample <= 4)
  20249. {
  20250. for (int i = 0; i < numSamples; ++i)
  20251. {
  20252. ByteOrder::bigEndian24BitToChars ((uint32) roundToInt (jlimit (-maxVal, maxVal, maxVal * source[i])), intData);
  20253. intData += destBytesPerSample;
  20254. }
  20255. }
  20256. else
  20257. {
  20258. intData += destBytesPerSample * numSamples;
  20259. for (int i = numSamples; --i >= 0;)
  20260. {
  20261. intData -= destBytesPerSample;
  20262. ByteOrder::bigEndian24BitToChars ((uint32) roundToInt (jlimit (-maxVal, maxVal, maxVal * source[i])), intData);
  20263. }
  20264. }
  20265. }
  20266. void AudioDataConverters::convertFloatToInt32LE (const float* source, void* dest, int numSamples, const int destBytesPerSample)
  20267. {
  20268. const double maxVal = (double) 0x7fffffff;
  20269. char* intData = (char*) dest;
  20270. if (dest != (void*) source || destBytesPerSample <= 4)
  20271. {
  20272. for (int i = 0; i < numSamples; ++i)
  20273. {
  20274. *(uint32*)intData = ByteOrder::swapIfBigEndian ((uint32) roundToInt (jlimit (-maxVal, maxVal, maxVal * source[i])));
  20275. intData += destBytesPerSample;
  20276. }
  20277. }
  20278. else
  20279. {
  20280. intData += destBytesPerSample * numSamples;
  20281. for (int i = numSamples; --i >= 0;)
  20282. {
  20283. intData -= destBytesPerSample;
  20284. *(uint32*)intData = ByteOrder::swapIfBigEndian ((uint32) roundToInt (jlimit (-maxVal, maxVal, maxVal * source[i])));
  20285. }
  20286. }
  20287. }
  20288. void AudioDataConverters::convertFloatToInt32BE (const float* source, void* dest, int numSamples, const int destBytesPerSample)
  20289. {
  20290. const double maxVal = (double) 0x7fffffff;
  20291. char* intData = (char*) dest;
  20292. if (dest != (void*) source || destBytesPerSample <= 4)
  20293. {
  20294. for (int i = 0; i < numSamples; ++i)
  20295. {
  20296. *(uint32*)intData = ByteOrder::swapIfLittleEndian ((uint32) roundToInt (jlimit (-maxVal, maxVal, maxVal * source[i])));
  20297. intData += destBytesPerSample;
  20298. }
  20299. }
  20300. else
  20301. {
  20302. intData += destBytesPerSample * numSamples;
  20303. for (int i = numSamples; --i >= 0;)
  20304. {
  20305. intData -= destBytesPerSample;
  20306. *(uint32*)intData = ByteOrder::swapIfLittleEndian ((uint32) roundToInt (jlimit (-maxVal, maxVal, maxVal * source[i])));
  20307. }
  20308. }
  20309. }
  20310. void AudioDataConverters::convertFloatToFloat32LE (const float* source, void* dest, int numSamples, const int destBytesPerSample)
  20311. {
  20312. jassert (dest != (void*) source || destBytesPerSample <= 4); // This op can't be performed on in-place data!
  20313. char* d = (char*) dest;
  20314. for (int i = 0; i < numSamples; ++i)
  20315. {
  20316. *(float*) d = source[i];
  20317. #if JUCE_BIG_ENDIAN
  20318. *(uint32*) d = ByteOrder::swap (*(uint32*) d);
  20319. #endif
  20320. d += destBytesPerSample;
  20321. }
  20322. }
  20323. void AudioDataConverters::convertFloatToFloat32BE (const float* source, void* dest, int numSamples, const int destBytesPerSample)
  20324. {
  20325. jassert (dest != (void*) source || destBytesPerSample <= 4); // This op can't be performed on in-place data!
  20326. char* d = (char*) dest;
  20327. for (int i = 0; i < numSamples; ++i)
  20328. {
  20329. *(float*) d = source[i];
  20330. #if JUCE_LITTLE_ENDIAN
  20331. *(uint32*) d = ByteOrder::swap (*(uint32*) d);
  20332. #endif
  20333. d += destBytesPerSample;
  20334. }
  20335. }
  20336. void AudioDataConverters::convertInt16LEToFloat (const void* const source, float* const dest, int numSamples, const int srcBytesPerSample)
  20337. {
  20338. const float scale = 1.0f / 0x7fff;
  20339. const char* intData = (const char*) source;
  20340. if (source != (void*) dest || srcBytesPerSample >= 4)
  20341. {
  20342. for (int i = 0; i < numSamples; ++i)
  20343. {
  20344. dest[i] = scale * (short) ByteOrder::swapIfBigEndian (*(uint16*)intData);
  20345. intData += srcBytesPerSample;
  20346. }
  20347. }
  20348. else
  20349. {
  20350. intData += srcBytesPerSample * numSamples;
  20351. for (int i = numSamples; --i >= 0;)
  20352. {
  20353. intData -= srcBytesPerSample;
  20354. dest[i] = scale * (short) ByteOrder::swapIfBigEndian (*(uint16*)intData);
  20355. }
  20356. }
  20357. }
  20358. void AudioDataConverters::convertInt16BEToFloat (const void* const source, float* const dest, int numSamples, const int srcBytesPerSample)
  20359. {
  20360. const float scale = 1.0f / 0x7fff;
  20361. const char* intData = (const char*) source;
  20362. if (source != (void*) dest || srcBytesPerSample >= 4)
  20363. {
  20364. for (int i = 0; i < numSamples; ++i)
  20365. {
  20366. dest[i] = scale * (short) ByteOrder::swapIfLittleEndian (*(uint16*)intData);
  20367. intData += srcBytesPerSample;
  20368. }
  20369. }
  20370. else
  20371. {
  20372. intData += srcBytesPerSample * numSamples;
  20373. for (int i = numSamples; --i >= 0;)
  20374. {
  20375. intData -= srcBytesPerSample;
  20376. dest[i] = scale * (short) ByteOrder::swapIfLittleEndian (*(uint16*)intData);
  20377. }
  20378. }
  20379. }
  20380. void AudioDataConverters::convertInt24LEToFloat (const void* const source, float* const dest, int numSamples, const int srcBytesPerSample)
  20381. {
  20382. const float scale = 1.0f / 0x7fffff;
  20383. const char* intData = (const char*) source;
  20384. if (source != (void*) dest || srcBytesPerSample >= 4)
  20385. {
  20386. for (int i = 0; i < numSamples; ++i)
  20387. {
  20388. dest[i] = scale * (short) ByteOrder::littleEndian24Bit (intData);
  20389. intData += srcBytesPerSample;
  20390. }
  20391. }
  20392. else
  20393. {
  20394. intData += srcBytesPerSample * numSamples;
  20395. for (int i = numSamples; --i >= 0;)
  20396. {
  20397. intData -= srcBytesPerSample;
  20398. dest[i] = scale * (short) ByteOrder::littleEndian24Bit (intData);
  20399. }
  20400. }
  20401. }
  20402. void AudioDataConverters::convertInt24BEToFloat (const void* const source, float* const dest, int numSamples, const int srcBytesPerSample)
  20403. {
  20404. const float scale = 1.0f / 0x7fffff;
  20405. const char* intData = (const char*) source;
  20406. if (source != (void*) dest || srcBytesPerSample >= 4)
  20407. {
  20408. for (int i = 0; i < numSamples; ++i)
  20409. {
  20410. dest[i] = scale * (short) ByteOrder::bigEndian24Bit (intData);
  20411. intData += srcBytesPerSample;
  20412. }
  20413. }
  20414. else
  20415. {
  20416. intData += srcBytesPerSample * numSamples;
  20417. for (int i = numSamples; --i >= 0;)
  20418. {
  20419. intData -= srcBytesPerSample;
  20420. dest[i] = scale * (short) ByteOrder::bigEndian24Bit (intData);
  20421. }
  20422. }
  20423. }
  20424. void AudioDataConverters::convertInt32LEToFloat (const void* const source, float* const dest, int numSamples, const int srcBytesPerSample)
  20425. {
  20426. const float scale = 1.0f / 0x7fffffff;
  20427. const char* intData = (const char*) source;
  20428. if (source != (void*) dest || srcBytesPerSample >= 4)
  20429. {
  20430. for (int i = 0; i < numSamples; ++i)
  20431. {
  20432. dest[i] = scale * (int) ByteOrder::swapIfBigEndian (*(uint32*) intData);
  20433. intData += srcBytesPerSample;
  20434. }
  20435. }
  20436. else
  20437. {
  20438. intData += srcBytesPerSample * numSamples;
  20439. for (int i = numSamples; --i >= 0;)
  20440. {
  20441. intData -= srcBytesPerSample;
  20442. dest[i] = scale * (int) ByteOrder::swapIfBigEndian (*(uint32*) intData);
  20443. }
  20444. }
  20445. }
  20446. void AudioDataConverters::convertInt32BEToFloat (const void* const source, float* const dest, int numSamples, const int srcBytesPerSample)
  20447. {
  20448. const float scale = 1.0f / 0x7fffffff;
  20449. const char* intData = (const char*) source;
  20450. if (source != (void*) dest || srcBytesPerSample >= 4)
  20451. {
  20452. for (int i = 0; i < numSamples; ++i)
  20453. {
  20454. dest[i] = scale * (int) ByteOrder::swapIfLittleEndian (*(uint32*) intData);
  20455. intData += srcBytesPerSample;
  20456. }
  20457. }
  20458. else
  20459. {
  20460. intData += srcBytesPerSample * numSamples;
  20461. for (int i = numSamples; --i >= 0;)
  20462. {
  20463. intData -= srcBytesPerSample;
  20464. dest[i] = scale * (int) ByteOrder::swapIfLittleEndian (*(uint32*) intData);
  20465. }
  20466. }
  20467. }
  20468. void AudioDataConverters::convertFloat32LEToFloat (const void* const source, float* const dest, int numSamples, const int srcBytesPerSample)
  20469. {
  20470. const char* s = (const char*) source;
  20471. for (int i = 0; i < numSamples; ++i)
  20472. {
  20473. dest[i] = *(float*)s;
  20474. #if JUCE_BIG_ENDIAN
  20475. uint32* const d = (uint32*) (dest + i);
  20476. *d = ByteOrder::swap (*d);
  20477. #endif
  20478. s += srcBytesPerSample;
  20479. }
  20480. }
  20481. void AudioDataConverters::convertFloat32BEToFloat (const void* const source, float* const dest, int numSamples, const int srcBytesPerSample)
  20482. {
  20483. const char* s = (const char*) source;
  20484. for (int i = 0; i < numSamples; ++i)
  20485. {
  20486. dest[i] = *(float*)s;
  20487. #if JUCE_LITTLE_ENDIAN
  20488. uint32* const d = (uint32*) (dest + i);
  20489. *d = ByteOrder::swap (*d);
  20490. #endif
  20491. s += srcBytesPerSample;
  20492. }
  20493. }
  20494. void AudioDataConverters::convertFloatToFormat (const DataFormat destFormat,
  20495. const float* const source,
  20496. void* const dest,
  20497. const int numSamples)
  20498. {
  20499. switch (destFormat)
  20500. {
  20501. case int16LE:
  20502. convertFloatToInt16LE (source, dest, numSamples);
  20503. break;
  20504. case int16BE:
  20505. convertFloatToInt16BE (source, dest, numSamples);
  20506. break;
  20507. case int24LE:
  20508. convertFloatToInt24LE (source, dest, numSamples);
  20509. break;
  20510. case int24BE:
  20511. convertFloatToInt24BE (source, dest, numSamples);
  20512. break;
  20513. case int32LE:
  20514. convertFloatToInt32LE (source, dest, numSamples);
  20515. break;
  20516. case int32BE:
  20517. convertFloatToInt32BE (source, dest, numSamples);
  20518. break;
  20519. case float32LE:
  20520. convertFloatToFloat32LE (source, dest, numSamples);
  20521. break;
  20522. case float32BE:
  20523. convertFloatToFloat32BE (source, dest, numSamples);
  20524. break;
  20525. default:
  20526. jassertfalse
  20527. break;
  20528. }
  20529. }
  20530. void AudioDataConverters::convertFormatToFloat (const DataFormat sourceFormat,
  20531. const void* const source,
  20532. float* const dest,
  20533. const int numSamples)
  20534. {
  20535. switch (sourceFormat)
  20536. {
  20537. case int16LE:
  20538. convertInt16LEToFloat (source, dest, numSamples);
  20539. break;
  20540. case int16BE:
  20541. convertInt16BEToFloat (source, dest, numSamples);
  20542. break;
  20543. case int24LE:
  20544. convertInt24LEToFloat (source, dest, numSamples);
  20545. break;
  20546. case int24BE:
  20547. convertInt24BEToFloat (source, dest, numSamples);
  20548. break;
  20549. case int32LE:
  20550. convertInt32LEToFloat (source, dest, numSamples);
  20551. break;
  20552. case int32BE:
  20553. convertInt32BEToFloat (source, dest, numSamples);
  20554. break;
  20555. case float32LE:
  20556. convertFloat32LEToFloat (source, dest, numSamples);
  20557. break;
  20558. case float32BE:
  20559. convertFloat32BEToFloat (source, dest, numSamples);
  20560. break;
  20561. default:
  20562. jassertfalse
  20563. break;
  20564. }
  20565. }
  20566. void AudioDataConverters::interleaveSamples (const float** const source,
  20567. float* const dest,
  20568. const int numSamples,
  20569. const int numChannels)
  20570. {
  20571. for (int chan = 0; chan < numChannels; ++chan)
  20572. {
  20573. int i = chan;
  20574. const float* src = source [chan];
  20575. for (int j = 0; j < numSamples; ++j)
  20576. {
  20577. dest [i] = src [j];
  20578. i += numChannels;
  20579. }
  20580. }
  20581. }
  20582. void AudioDataConverters::deinterleaveSamples (const float* const source,
  20583. float** const dest,
  20584. const int numSamples,
  20585. const int numChannels)
  20586. {
  20587. for (int chan = 0; chan < numChannels; ++chan)
  20588. {
  20589. int i = chan;
  20590. float* dst = dest [chan];
  20591. for (int j = 0; j < numSamples; ++j)
  20592. {
  20593. dst [j] = source [i];
  20594. i += numChannels;
  20595. }
  20596. }
  20597. }
  20598. END_JUCE_NAMESPACE
  20599. /********* End of inlined file: juce_AudioDataConverters.cpp *********/
  20600. /********* Start of inlined file: juce_AudioSampleBuffer.cpp *********/
  20601. BEGIN_JUCE_NAMESPACE
  20602. AudioSampleBuffer::AudioSampleBuffer (const int numChannels_,
  20603. const int numSamples) throw()
  20604. : numChannels (numChannels_),
  20605. size (numSamples)
  20606. {
  20607. jassert (numSamples >= 0);
  20608. jassert (numChannels_ > 0);
  20609. allocateData();
  20610. }
  20611. AudioSampleBuffer::AudioSampleBuffer (const AudioSampleBuffer& other) throw()
  20612. : numChannels (other.numChannels),
  20613. size (other.size)
  20614. {
  20615. allocateData();
  20616. const size_t numBytes = size * sizeof (float);
  20617. for (int i = 0; i < numChannels; ++i)
  20618. memcpy (channels[i], other.channels[i], numBytes);
  20619. }
  20620. void AudioSampleBuffer::allocateData()
  20621. {
  20622. const size_t channelListSize = (numChannels + 1) * sizeof (float*);
  20623. allocatedBytes = (int) (numChannels * size * sizeof (float) + channelListSize + 32);
  20624. allocatedData.malloc (allocatedBytes);
  20625. channels = (float**) allocatedData;
  20626. float* chan = (float*) (allocatedData + channelListSize);
  20627. for (int i = 0; i < numChannels; ++i)
  20628. {
  20629. channels[i] = chan;
  20630. chan += size;
  20631. }
  20632. channels [numChannels] = 0;
  20633. }
  20634. AudioSampleBuffer::AudioSampleBuffer (float** dataToReferTo,
  20635. const int numChannels_,
  20636. const int numSamples) throw()
  20637. : numChannels (numChannels_),
  20638. size (numSamples),
  20639. allocatedBytes (0)
  20640. {
  20641. jassert (numChannels_ > 0);
  20642. allocateChannels (dataToReferTo);
  20643. }
  20644. void AudioSampleBuffer::setDataToReferTo (float** dataToReferTo,
  20645. const int newNumChannels,
  20646. const int newNumSamples) throw()
  20647. {
  20648. jassert (newNumChannels > 0);
  20649. allocatedBytes = 0;
  20650. allocatedData.free();
  20651. numChannels = newNumChannels;
  20652. size = newNumSamples;
  20653. allocateChannels (dataToReferTo);
  20654. }
  20655. void AudioSampleBuffer::allocateChannels (float** const dataToReferTo)
  20656. {
  20657. // (try to avoid doing a malloc here, as that'll blow up things like Pro-Tools)
  20658. if (numChannels < numElementsInArray (preallocatedChannelSpace))
  20659. {
  20660. channels = (float**) preallocatedChannelSpace;
  20661. }
  20662. else
  20663. {
  20664. allocatedData.malloc (numChannels + 1, sizeof (float*));
  20665. channels = (float**) allocatedData;
  20666. }
  20667. for (int i = 0; i < numChannels; ++i)
  20668. {
  20669. // you have to pass in the same number of valid pointers as numChannels
  20670. jassert (dataToReferTo[i] != 0);
  20671. channels[i] = dataToReferTo[i];
  20672. }
  20673. channels [numChannels] = 0;
  20674. }
  20675. const AudioSampleBuffer& AudioSampleBuffer::operator= (const AudioSampleBuffer& other) throw()
  20676. {
  20677. if (this != &other)
  20678. {
  20679. setSize (other.getNumChannels(), other.getNumSamples(), false, false, false);
  20680. const size_t numBytes = size * sizeof (float);
  20681. for (int i = 0; i < numChannels; ++i)
  20682. memcpy (channels[i], other.channels[i], numBytes);
  20683. }
  20684. return *this;
  20685. }
  20686. AudioSampleBuffer::~AudioSampleBuffer() throw()
  20687. {
  20688. }
  20689. void AudioSampleBuffer::setSize (const int newNumChannels,
  20690. const int newNumSamples,
  20691. const bool keepExistingContent,
  20692. const bool clearExtraSpace,
  20693. const bool avoidReallocating) throw()
  20694. {
  20695. jassert (newNumChannels > 0);
  20696. if (newNumSamples != size || newNumChannels != numChannels)
  20697. {
  20698. const size_t channelListSize = (newNumChannels + 1) * sizeof (float*);
  20699. const size_t newTotalBytes = (newNumChannels * newNumSamples * sizeof (float)) + channelListSize + 32;
  20700. if (keepExistingContent)
  20701. {
  20702. HeapBlock <char> newData;
  20703. newData.allocate (newTotalBytes, clearExtraSpace);
  20704. const int numChansToCopy = jmin (numChannels, newNumChannels);
  20705. const size_t numBytesToCopy = sizeof (float) * jmin (newNumSamples, size);
  20706. float** const newChannels = (float**) newData;
  20707. float* newChan = (float*) (newData + channelListSize);
  20708. for (int i = 0; i < numChansToCopy; ++i)
  20709. {
  20710. memcpy (newChan, channels[i], numBytesToCopy);
  20711. newChannels[i] = newChan;
  20712. newChan += newNumSamples;
  20713. }
  20714. allocatedData.swapWith (newData);
  20715. allocatedBytes = (int) newTotalBytes;
  20716. channels = (float**) allocatedData;
  20717. }
  20718. else
  20719. {
  20720. if (avoidReallocating && allocatedBytes >= newTotalBytes)
  20721. {
  20722. if (clearExtraSpace)
  20723. zeromem (allocatedData, newTotalBytes);
  20724. }
  20725. else
  20726. {
  20727. allocatedBytes = newTotalBytes;
  20728. allocatedData.allocate (newTotalBytes, clearExtraSpace);
  20729. channels = (float**) allocatedData;
  20730. }
  20731. float* chan = (float*) (allocatedData + channelListSize);
  20732. for (int i = 0; i < newNumChannels; ++i)
  20733. {
  20734. channels[i] = chan;
  20735. chan += newNumSamples;
  20736. }
  20737. }
  20738. channels [newNumChannels] = 0;
  20739. size = newNumSamples;
  20740. numChannels = newNumChannels;
  20741. }
  20742. }
  20743. void AudioSampleBuffer::clear() throw()
  20744. {
  20745. for (int i = 0; i < numChannels; ++i)
  20746. zeromem (channels[i], size * sizeof (float));
  20747. }
  20748. void AudioSampleBuffer::clear (const int startSample,
  20749. const int numSamples) throw()
  20750. {
  20751. jassert (startSample >= 0 && startSample + numSamples <= size);
  20752. for (int i = 0; i < numChannels; ++i)
  20753. zeromem (channels [i] + startSample, numSamples * sizeof (float));
  20754. }
  20755. void AudioSampleBuffer::clear (const int channel,
  20756. const int startSample,
  20757. const int numSamples) throw()
  20758. {
  20759. jassert (((unsigned int) channel) < (unsigned int) numChannels);
  20760. jassert (startSample >= 0 && startSample + numSamples <= size);
  20761. zeromem (channels [channel] + startSample, numSamples * sizeof (float));
  20762. }
  20763. void AudioSampleBuffer::applyGain (const int channel,
  20764. const int startSample,
  20765. int numSamples,
  20766. const float gain) throw()
  20767. {
  20768. jassert (((unsigned int) channel) < (unsigned int) numChannels);
  20769. jassert (startSample >= 0 && startSample + numSamples <= size);
  20770. if (gain != 1.0f)
  20771. {
  20772. float* d = channels [channel] + startSample;
  20773. if (gain == 0.0f)
  20774. {
  20775. zeromem (d, sizeof (float) * numSamples);
  20776. }
  20777. else
  20778. {
  20779. while (--numSamples >= 0)
  20780. *d++ *= gain;
  20781. }
  20782. }
  20783. }
  20784. void AudioSampleBuffer::applyGainRamp (const int channel,
  20785. const int startSample,
  20786. int numSamples,
  20787. float startGain,
  20788. float endGain) throw()
  20789. {
  20790. if (startGain == endGain)
  20791. {
  20792. applyGain (channel, startSample, numSamples, startGain);
  20793. }
  20794. else
  20795. {
  20796. jassert (((unsigned int) channel) < (unsigned int) numChannels);
  20797. jassert (startSample >= 0 && startSample + numSamples <= size);
  20798. const float increment = (endGain - startGain) / numSamples;
  20799. float* d = channels [channel] + startSample;
  20800. while (--numSamples >= 0)
  20801. {
  20802. *d++ *= startGain;
  20803. startGain += increment;
  20804. }
  20805. }
  20806. }
  20807. void AudioSampleBuffer::applyGain (const int startSample,
  20808. const int numSamples,
  20809. const float gain) throw()
  20810. {
  20811. for (int i = 0; i < numChannels; ++i)
  20812. applyGain (i, startSample, numSamples, gain);
  20813. }
  20814. void AudioSampleBuffer::addFrom (const int destChannel,
  20815. const int destStartSample,
  20816. const AudioSampleBuffer& source,
  20817. const int sourceChannel,
  20818. const int sourceStartSample,
  20819. int numSamples,
  20820. const float gain) throw()
  20821. {
  20822. jassert (&source != this || sourceChannel != destChannel);
  20823. jassert (((unsigned int) destChannel) < (unsigned int) numChannels);
  20824. jassert (destStartSample >= 0 && destStartSample + numSamples <= size);
  20825. jassert (((unsigned int) sourceChannel) < (unsigned int) source.numChannels);
  20826. jassert (sourceStartSample >= 0 && sourceStartSample + numSamples <= source.size);
  20827. if (gain != 0.0f && numSamples > 0)
  20828. {
  20829. float* d = channels [destChannel] + destStartSample;
  20830. const float* s = source.channels [sourceChannel] + sourceStartSample;
  20831. if (gain != 1.0f)
  20832. {
  20833. while (--numSamples >= 0)
  20834. *d++ += gain * *s++;
  20835. }
  20836. else
  20837. {
  20838. while (--numSamples >= 0)
  20839. *d++ += *s++;
  20840. }
  20841. }
  20842. }
  20843. void AudioSampleBuffer::addFrom (const int destChannel,
  20844. const int destStartSample,
  20845. const float* source,
  20846. int numSamples,
  20847. const float gain) throw()
  20848. {
  20849. jassert (((unsigned int) destChannel) < (unsigned int) numChannels);
  20850. jassert (destStartSample >= 0 && destStartSample + numSamples <= size);
  20851. jassert (source != 0);
  20852. if (gain != 0.0f && numSamples > 0)
  20853. {
  20854. float* d = channels [destChannel] + destStartSample;
  20855. if (gain != 1.0f)
  20856. {
  20857. while (--numSamples >= 0)
  20858. *d++ += gain * *source++;
  20859. }
  20860. else
  20861. {
  20862. while (--numSamples >= 0)
  20863. *d++ += *source++;
  20864. }
  20865. }
  20866. }
  20867. void AudioSampleBuffer::addFromWithRamp (const int destChannel,
  20868. const int destStartSample,
  20869. const float* source,
  20870. int numSamples,
  20871. float startGain,
  20872. const float endGain) throw()
  20873. {
  20874. jassert (((unsigned int) destChannel) < (unsigned int) numChannels);
  20875. jassert (destStartSample >= 0 && destStartSample + numSamples <= size);
  20876. jassert (source != 0);
  20877. if (startGain == endGain)
  20878. {
  20879. addFrom (destChannel,
  20880. destStartSample,
  20881. source,
  20882. numSamples,
  20883. startGain);
  20884. }
  20885. else
  20886. {
  20887. if (numSamples > 0 && (startGain != 0.0f || endGain != 0.0f))
  20888. {
  20889. const float increment = (endGain - startGain) / numSamples;
  20890. float* d = channels [destChannel] + destStartSample;
  20891. while (--numSamples >= 0)
  20892. {
  20893. *d++ += startGain * *source++;
  20894. startGain += increment;
  20895. }
  20896. }
  20897. }
  20898. }
  20899. void AudioSampleBuffer::copyFrom (const int destChannel,
  20900. const int destStartSample,
  20901. const AudioSampleBuffer& source,
  20902. const int sourceChannel,
  20903. const int sourceStartSample,
  20904. int numSamples) throw()
  20905. {
  20906. jassert (&source != this || sourceChannel != destChannel);
  20907. jassert (((unsigned int) destChannel) < (unsigned int) numChannels);
  20908. jassert (destStartSample >= 0 && destStartSample + numSamples <= size);
  20909. jassert (((unsigned int) sourceChannel) < (unsigned int) source.numChannels);
  20910. jassert (sourceStartSample >= 0 && sourceStartSample + numSamples <= source.size);
  20911. if (numSamples > 0)
  20912. {
  20913. memcpy (channels [destChannel] + destStartSample,
  20914. source.channels [sourceChannel] + sourceStartSample,
  20915. sizeof (float) * numSamples);
  20916. }
  20917. }
  20918. void AudioSampleBuffer::copyFrom (const int destChannel,
  20919. const int destStartSample,
  20920. const float* source,
  20921. int numSamples) throw()
  20922. {
  20923. jassert (((unsigned int) destChannel) < (unsigned int) numChannels);
  20924. jassert (destStartSample >= 0 && destStartSample + numSamples <= size);
  20925. jassert (source != 0);
  20926. if (numSamples > 0)
  20927. {
  20928. memcpy (channels [destChannel] + destStartSample,
  20929. source,
  20930. sizeof (float) * numSamples);
  20931. }
  20932. }
  20933. void AudioSampleBuffer::copyFrom (const int destChannel,
  20934. const int destStartSample,
  20935. const float* source,
  20936. int numSamples,
  20937. const float gain) throw()
  20938. {
  20939. jassert (((unsigned int) destChannel) < (unsigned int) numChannels);
  20940. jassert (destStartSample >= 0 && destStartSample + numSamples <= size);
  20941. jassert (source != 0);
  20942. if (numSamples > 0)
  20943. {
  20944. float* d = channels [destChannel] + destStartSample;
  20945. if (gain != 1.0f)
  20946. {
  20947. if (gain == 0)
  20948. {
  20949. zeromem (d, sizeof (float) * numSamples);
  20950. }
  20951. else
  20952. {
  20953. while (--numSamples >= 0)
  20954. *d++ = gain * *source++;
  20955. }
  20956. }
  20957. else
  20958. {
  20959. memcpy (d, source, sizeof (float) * numSamples);
  20960. }
  20961. }
  20962. }
  20963. void AudioSampleBuffer::copyFromWithRamp (const int destChannel,
  20964. const int destStartSample,
  20965. const float* source,
  20966. int numSamples,
  20967. float startGain,
  20968. float endGain) throw()
  20969. {
  20970. jassert (((unsigned int) destChannel) < (unsigned int) numChannels);
  20971. jassert (destStartSample >= 0 && destStartSample + numSamples <= size);
  20972. jassert (source != 0);
  20973. if (startGain == endGain)
  20974. {
  20975. copyFrom (destChannel,
  20976. destStartSample,
  20977. source,
  20978. numSamples,
  20979. startGain);
  20980. }
  20981. else
  20982. {
  20983. if (numSamples > 0 && (startGain != 0.0f || endGain != 0.0f))
  20984. {
  20985. const float increment = (endGain - startGain) / numSamples;
  20986. float* d = channels [destChannel] + destStartSample;
  20987. while (--numSamples >= 0)
  20988. {
  20989. *d++ = startGain * *source++;
  20990. startGain += increment;
  20991. }
  20992. }
  20993. }
  20994. }
  20995. void AudioSampleBuffer::findMinMax (const int channel,
  20996. const int startSample,
  20997. int numSamples,
  20998. float& minVal,
  20999. float& maxVal) const throw()
  21000. {
  21001. jassert (((unsigned int) channel) < (unsigned int) numChannels);
  21002. jassert (startSample >= 0 && startSample + numSamples <= size);
  21003. if (numSamples <= 0)
  21004. {
  21005. minVal = 0.0f;
  21006. maxVal = 0.0f;
  21007. }
  21008. else
  21009. {
  21010. const float* d = channels [channel] + startSample;
  21011. float mn = *d++;
  21012. float mx = mn;
  21013. while (--numSamples > 0) // (> 0 rather than >= 0 because we've already taken the first sample)
  21014. {
  21015. const float samp = *d++;
  21016. if (samp > mx)
  21017. mx = samp;
  21018. if (samp < mn)
  21019. mn = samp;
  21020. }
  21021. maxVal = mx;
  21022. minVal = mn;
  21023. }
  21024. }
  21025. float AudioSampleBuffer::getMagnitude (const int channel,
  21026. const int startSample,
  21027. const int numSamples) const throw()
  21028. {
  21029. jassert (((unsigned int) channel) < (unsigned int) numChannels);
  21030. jassert (startSample >= 0 && startSample + numSamples <= size);
  21031. float mn, mx;
  21032. findMinMax (channel, startSample, numSamples, mn, mx);
  21033. return jmax (mn, -mn, mx, -mx);
  21034. }
  21035. float AudioSampleBuffer::getMagnitude (const int startSample,
  21036. const int numSamples) const throw()
  21037. {
  21038. float mag = 0.0f;
  21039. for (int i = 0; i < numChannels; ++i)
  21040. mag = jmax (mag, getMagnitude (i, startSample, numSamples));
  21041. return mag;
  21042. }
  21043. float AudioSampleBuffer::getRMSLevel (const int channel,
  21044. const int startSample,
  21045. const int numSamples) const throw()
  21046. {
  21047. jassert (((unsigned int) channel) < (unsigned int) numChannels);
  21048. jassert (startSample >= 0 && startSample + numSamples <= size);
  21049. if (numSamples <= 0 || channel < 0 || channel >= numChannels)
  21050. return 0.0f;
  21051. const float* const data = channels [channel] + startSample;
  21052. double sum = 0.0;
  21053. for (int i = 0; i < numSamples; ++i)
  21054. {
  21055. const float sample = data [i];
  21056. sum += sample * sample;
  21057. }
  21058. return (float) sqrt (sum / numSamples);
  21059. }
  21060. void AudioSampleBuffer::readFromAudioReader (AudioFormatReader* reader,
  21061. const int startSample,
  21062. const int numSamples,
  21063. const int readerStartSample,
  21064. const bool useLeftChan,
  21065. const bool useRightChan) throw()
  21066. {
  21067. jassert (reader != 0);
  21068. jassert (startSample >= 0 && startSample + numSamples <= size);
  21069. if (numSamples > 0)
  21070. {
  21071. int* chans[3];
  21072. if (useLeftChan == useRightChan)
  21073. {
  21074. chans[0] = (int*) getSampleData (0, startSample);
  21075. chans[1] = (reader->numChannels > 1 && getNumChannels() > 1) ? (int*) getSampleData (1, startSample) : 0;
  21076. }
  21077. else if (useLeftChan || (reader->numChannels == 1))
  21078. {
  21079. chans[0] = (int*) getSampleData (0, startSample);
  21080. chans[1] = 0;
  21081. }
  21082. else if (useRightChan)
  21083. {
  21084. chans[0] = 0;
  21085. chans[1] = (int*) getSampleData (0, startSample);
  21086. }
  21087. chans[2] = 0;
  21088. reader->read (chans, 2, readerStartSample, numSamples, true);
  21089. if (! reader->usesFloatingPointData)
  21090. {
  21091. for (int j = 0; j < 2; ++j)
  21092. {
  21093. float* const d = (float*) (chans[j]);
  21094. if (d != 0)
  21095. {
  21096. const float multiplier = 1.0f / 0x7fffffff;
  21097. for (int i = 0; i < numSamples; ++i)
  21098. d[i] = *(int*)(d + i) * multiplier;
  21099. }
  21100. }
  21101. }
  21102. if (numChannels > 1 && (chans[0] == 0 || chans[1] == 0))
  21103. {
  21104. // if this is a stereo buffer and the source was mono, dupe the first channel..
  21105. memcpy (getSampleData (1, startSample),
  21106. getSampleData (0, startSample),
  21107. sizeof (float) * numSamples);
  21108. }
  21109. }
  21110. }
  21111. void AudioSampleBuffer::writeToAudioWriter (AudioFormatWriter* writer,
  21112. const int startSample,
  21113. const int numSamples) const throw()
  21114. {
  21115. jassert (startSample >= 0 && startSample + numSamples <= size);
  21116. if (numSamples > 0)
  21117. {
  21118. int* chans [3];
  21119. if (writer->isFloatingPoint())
  21120. {
  21121. chans[0] = (int*) getSampleData (0, startSample);
  21122. if (numChannels > 1)
  21123. chans[1] = (int*) getSampleData (1, startSample);
  21124. else
  21125. chans[1] = 0;
  21126. chans[2] = 0;
  21127. writer->write ((const int**) chans, numSamples);
  21128. }
  21129. else
  21130. {
  21131. HeapBlock <int> tempBuffer (numSamples * 2);
  21132. chans[0] = tempBuffer;
  21133. if (numChannels > 1)
  21134. chans[1] = chans[0] + numSamples;
  21135. else
  21136. chans[1] = 0;
  21137. chans[2] = 0;
  21138. for (int j = 0; j < 2; ++j)
  21139. {
  21140. int* const dest = chans[j];
  21141. if (dest != 0)
  21142. {
  21143. const float* const src = channels [j] + startSample;
  21144. for (int i = 0; i < numSamples; ++i)
  21145. {
  21146. const double samp = src[i];
  21147. if (samp <= -1.0)
  21148. dest[i] = INT_MIN;
  21149. else if (samp >= 1.0)
  21150. dest[i] = INT_MAX;
  21151. else
  21152. dest[i] = roundToInt (INT_MAX * samp);
  21153. }
  21154. }
  21155. }
  21156. writer->write ((const int**) chans, numSamples);
  21157. }
  21158. }
  21159. }
  21160. END_JUCE_NAMESPACE
  21161. /********* End of inlined file: juce_AudioSampleBuffer.cpp *********/
  21162. /********* Start of inlined file: juce_IIRFilter.cpp *********/
  21163. BEGIN_JUCE_NAMESPACE
  21164. IIRFilter::IIRFilter() throw()
  21165. : active (false)
  21166. {
  21167. reset();
  21168. }
  21169. IIRFilter::IIRFilter (const IIRFilter& other) throw()
  21170. : active (other.active)
  21171. {
  21172. const ScopedLock sl (other.processLock);
  21173. memcpy (coefficients, other.coefficients, sizeof (coefficients));
  21174. reset();
  21175. }
  21176. IIRFilter::~IIRFilter() throw()
  21177. {
  21178. }
  21179. void IIRFilter::reset() throw()
  21180. {
  21181. const ScopedLock sl (processLock);
  21182. x1 = 0;
  21183. x2 = 0;
  21184. y1 = 0;
  21185. y2 = 0;
  21186. }
  21187. float IIRFilter::processSingleSampleRaw (const float in) throw()
  21188. {
  21189. float out = coefficients[0] * in
  21190. + coefficients[1] * x1
  21191. + coefficients[2] * x2
  21192. - coefficients[4] * y1
  21193. - coefficients[5] * y2;
  21194. #if JUCE_INTEL
  21195. if (! (out < -1.0e-8 || out > 1.0e-8))
  21196. out = 0;
  21197. #endif
  21198. x2 = x1;
  21199. x1 = in;
  21200. y2 = y1;
  21201. y1 = out;
  21202. return out;
  21203. }
  21204. void IIRFilter::processSamples (float* const samples,
  21205. const int numSamples) throw()
  21206. {
  21207. const ScopedLock sl (processLock);
  21208. if (active)
  21209. {
  21210. for (int i = 0; i < numSamples; ++i)
  21211. {
  21212. const float in = samples[i];
  21213. float out = coefficients[0] * in
  21214. + coefficients[1] * x1
  21215. + coefficients[2] * x2
  21216. - coefficients[4] * y1
  21217. - coefficients[5] * y2;
  21218. #if JUCE_INTEL
  21219. if (! (out < -1.0e-8 || out > 1.0e-8))
  21220. out = 0;
  21221. #endif
  21222. x2 = x1;
  21223. x1 = in;
  21224. y2 = y1;
  21225. y1 = out;
  21226. samples[i] = out;
  21227. }
  21228. }
  21229. }
  21230. void IIRFilter::makeLowPass (const double sampleRate,
  21231. const double frequency) throw()
  21232. {
  21233. jassert (sampleRate > 0);
  21234. const double n = 1.0 / tan (double_Pi * frequency / sampleRate);
  21235. const double nSquared = n * n;
  21236. const double c1 = 1.0 / (1.0 + sqrt (2.0) * n + nSquared);
  21237. setCoefficients (c1,
  21238. c1 * 2.0f,
  21239. c1,
  21240. 1.0,
  21241. c1 * 2.0 * (1.0 - nSquared),
  21242. c1 * (1.0 - sqrt (2.0) * n + nSquared));
  21243. }
  21244. void IIRFilter::makeHighPass (const double sampleRate,
  21245. const double frequency) throw()
  21246. {
  21247. const double n = tan (double_Pi * frequency / sampleRate);
  21248. const double nSquared = n * n;
  21249. const double c1 = 1.0 / (1.0 + sqrt (2.0) * n + nSquared);
  21250. setCoefficients (c1,
  21251. c1 * -2.0f,
  21252. c1,
  21253. 1.0,
  21254. c1 * 2.0 * (nSquared - 1.0),
  21255. c1 * (1.0 - sqrt (2.0) * n + nSquared));
  21256. }
  21257. void IIRFilter::makeLowShelf (const double sampleRate,
  21258. const double cutOffFrequency,
  21259. const double Q,
  21260. const float gainFactor) throw()
  21261. {
  21262. jassert (sampleRate > 0);
  21263. jassert (Q > 0);
  21264. const double A = jmax (0.0f, gainFactor);
  21265. const double aminus1 = A - 1.0;
  21266. const double aplus1 = A + 1.0;
  21267. const double omega = (double_Pi * 2.0 * jmax (cutOffFrequency, 2.0)) / sampleRate;
  21268. const double coso = cos (omega);
  21269. const double beta = sin (omega) * sqrt (A) / Q;
  21270. const double aminus1TimesCoso = aminus1 * coso;
  21271. setCoefficients (A * (aplus1 - aminus1TimesCoso + beta),
  21272. A * 2.0 * (aminus1 - aplus1 * coso),
  21273. A * (aplus1 - aminus1TimesCoso - beta),
  21274. aplus1 + aminus1TimesCoso + beta,
  21275. -2.0 * (aminus1 + aplus1 * coso),
  21276. aplus1 + aminus1TimesCoso - beta);
  21277. }
  21278. void IIRFilter::makeHighShelf (const double sampleRate,
  21279. const double cutOffFrequency,
  21280. const double Q,
  21281. const float gainFactor) throw()
  21282. {
  21283. jassert (sampleRate > 0);
  21284. jassert (Q > 0);
  21285. const double A = jmax (0.0f, gainFactor);
  21286. const double aminus1 = A - 1.0;
  21287. const double aplus1 = A + 1.0;
  21288. const double omega = (double_Pi * 2.0 * jmax (cutOffFrequency, 2.0)) / sampleRate;
  21289. const double coso = cos (omega);
  21290. const double beta = sin (omega) * sqrt (A) / Q;
  21291. const double aminus1TimesCoso = aminus1 * coso;
  21292. setCoefficients (A * (aplus1 + aminus1TimesCoso + beta),
  21293. A * -2.0 * (aminus1 + aplus1 * coso),
  21294. A * (aplus1 + aminus1TimesCoso - beta),
  21295. aplus1 - aminus1TimesCoso + beta,
  21296. 2.0 * (aminus1 - aplus1 * coso),
  21297. aplus1 - aminus1TimesCoso - beta);
  21298. }
  21299. void IIRFilter::makeBandPass (const double sampleRate,
  21300. const double centreFrequency,
  21301. const double Q,
  21302. const float gainFactor) throw()
  21303. {
  21304. jassert (sampleRate > 0);
  21305. jassert (Q > 0);
  21306. const double A = jmax (0.0f, gainFactor);
  21307. const double omega = (double_Pi * 2.0 * jmax (centreFrequency, 2.0)) / sampleRate;
  21308. const double alpha = 0.5 * sin (omega) / Q;
  21309. const double c2 = -2.0 * cos (omega);
  21310. const double alphaTimesA = alpha * A;
  21311. const double alphaOverA = alpha / A;
  21312. setCoefficients (1.0 + alphaTimesA,
  21313. c2,
  21314. 1.0 - alphaTimesA,
  21315. 1.0 + alphaOverA,
  21316. c2,
  21317. 1.0 - alphaOverA);
  21318. }
  21319. void IIRFilter::makeInactive() throw()
  21320. {
  21321. const ScopedLock sl (processLock);
  21322. active = false;
  21323. }
  21324. void IIRFilter::copyCoefficientsFrom (const IIRFilter& other) throw()
  21325. {
  21326. const ScopedLock sl (processLock);
  21327. memcpy (coefficients, other.coefficients, sizeof (coefficients));
  21328. active = other.active;
  21329. }
  21330. void IIRFilter::setCoefficients (double c1,
  21331. double c2,
  21332. double c3,
  21333. double c4,
  21334. double c5,
  21335. double c6) throw()
  21336. {
  21337. const double a = 1.0 / c4;
  21338. c1 *= a;
  21339. c2 *= a;
  21340. c3 *= a;
  21341. c5 *= a;
  21342. c6 *= a;
  21343. const ScopedLock sl (processLock);
  21344. coefficients[0] = (float) c1;
  21345. coefficients[1] = (float) c2;
  21346. coefficients[2] = (float) c3;
  21347. coefficients[3] = (float) c4;
  21348. coefficients[4] = (float) c5;
  21349. coefficients[5] = (float) c6;
  21350. active = true;
  21351. }
  21352. END_JUCE_NAMESPACE
  21353. /********* End of inlined file: juce_IIRFilter.cpp *********/
  21354. /********* Start of inlined file: juce_MidiBuffer.cpp *********/
  21355. BEGIN_JUCE_NAMESPACE
  21356. MidiBuffer::MidiBuffer() throw()
  21357. : bytesUsed (0)
  21358. {
  21359. }
  21360. MidiBuffer::MidiBuffer (const MidiMessage& message) throw()
  21361. : bytesUsed (0)
  21362. {
  21363. addEvent (message, 0);
  21364. }
  21365. MidiBuffer::MidiBuffer (const MidiBuffer& other) throw()
  21366. : data (other.data),
  21367. bytesUsed (other.bytesUsed)
  21368. {
  21369. }
  21370. const MidiBuffer& MidiBuffer::operator= (const MidiBuffer& other) throw()
  21371. {
  21372. bytesUsed = other.bytesUsed;
  21373. data = other.data;
  21374. return *this;
  21375. }
  21376. void MidiBuffer::swap (MidiBuffer& other)
  21377. {
  21378. data.swapWith (other.data);
  21379. swapVariables <int> (bytesUsed, other.bytesUsed);
  21380. }
  21381. MidiBuffer::~MidiBuffer() throw()
  21382. {
  21383. }
  21384. void MidiBuffer::clear() throw()
  21385. {
  21386. bytesUsed = 0;
  21387. }
  21388. void MidiBuffer::clear (const int startSample,
  21389. const int numSamples) throw()
  21390. {
  21391. uint8* const start = findEventAfter (data, startSample - 1);
  21392. uint8* const end = findEventAfter (start, startSample + numSamples - 1);
  21393. if (end > start)
  21394. {
  21395. const size_t bytesToMove = (size_t) (bytesUsed - (end - (uint8*) data.getData()));
  21396. if (bytesToMove > 0)
  21397. memmove (start, end, bytesToMove);
  21398. bytesUsed -= (int) (end - start);
  21399. }
  21400. }
  21401. void MidiBuffer::addEvent (const MidiMessage& m,
  21402. const int sampleNumber) throw()
  21403. {
  21404. addEvent (m.getRawData(), m.getRawDataSize(), sampleNumber);
  21405. }
  21406. static int findActualEventLength (const uint8* const data,
  21407. const int maxBytes) throw()
  21408. {
  21409. unsigned int byte = (unsigned int) *data;
  21410. int size = 0;
  21411. if (byte == 0xf0 || byte == 0xf7)
  21412. {
  21413. const uint8* d = data + 1;
  21414. while (d < data + maxBytes)
  21415. if (*d++ == 0xf7)
  21416. break;
  21417. size = (int) (d - data);
  21418. }
  21419. else if (byte == 0xff)
  21420. {
  21421. int n;
  21422. const int bytesLeft = MidiMessage::readVariableLengthVal (data + 1, n);
  21423. size = jmin (maxBytes, n + 2 + bytesLeft);
  21424. }
  21425. else if (byte >= 0x80)
  21426. {
  21427. size = jmin (maxBytes, MidiMessage::getMessageLengthFromFirstByte ((uint8) byte));
  21428. }
  21429. return size;
  21430. }
  21431. void MidiBuffer::addEvent (const uint8* const newData,
  21432. const int maxBytes,
  21433. const int sampleNumber) throw()
  21434. {
  21435. const int numBytes = findActualEventLength (newData, maxBytes);
  21436. if (numBytes > 0)
  21437. {
  21438. int spaceNeeded = bytesUsed + numBytes + 6;
  21439. data.ensureSize ((spaceNeeded + spaceNeeded / 2 + 8) & ~7);
  21440. uint8* d = findEventAfter ((uint8*) data.getData(), sampleNumber);
  21441. const size_t bytesToMove = (size_t) (bytesUsed - (d - (uint8*) data.getData()));
  21442. if (bytesToMove > 0)
  21443. memmove (d + numBytes + 6,
  21444. d,
  21445. bytesToMove);
  21446. *(int*) d = sampleNumber;
  21447. d += 4;
  21448. *(uint16*) d = (uint16) numBytes;
  21449. d += 2;
  21450. memcpy (d, newData, numBytes);
  21451. bytesUsed += numBytes + 6;
  21452. }
  21453. }
  21454. void MidiBuffer::addEvents (const MidiBuffer& otherBuffer,
  21455. const int startSample,
  21456. const int numSamples,
  21457. const int sampleDeltaToAdd) throw()
  21458. {
  21459. Iterator i (otherBuffer);
  21460. i.setNextSamplePosition (startSample);
  21461. const uint8* eventData;
  21462. int eventSize, position;
  21463. while (i.getNextEvent (eventData, eventSize, position)
  21464. && (position < startSample + numSamples || numSamples < 0))
  21465. {
  21466. addEvent (eventData, eventSize, position + sampleDeltaToAdd);
  21467. }
  21468. }
  21469. bool MidiBuffer::isEmpty() const throw()
  21470. {
  21471. return bytesUsed == 0;
  21472. }
  21473. int MidiBuffer::getNumEvents() const throw()
  21474. {
  21475. int n = 0;
  21476. const uint8* d = (uint8*) data.getData();
  21477. const uint8* const end = d + bytesUsed;
  21478. while (d < end)
  21479. {
  21480. d += 4;
  21481. d += 2 + *(const uint16*) d;
  21482. ++n;
  21483. }
  21484. return n;
  21485. }
  21486. int MidiBuffer::getFirstEventTime() const throw()
  21487. {
  21488. return (bytesUsed > 0) ? *(const int*) data.getData() : 0;
  21489. }
  21490. int MidiBuffer::getLastEventTime() const throw()
  21491. {
  21492. if (bytesUsed == 0)
  21493. return 0;
  21494. const uint8* d = (uint8*) data.getData();
  21495. const uint8* const endData = d + bytesUsed;
  21496. for (;;)
  21497. {
  21498. const uint8* nextOne = d + 6 + * (const uint16*) (d + 4);
  21499. if (nextOne >= endData)
  21500. return *(const int*) d;
  21501. d = nextOne;
  21502. }
  21503. }
  21504. uint8* MidiBuffer::findEventAfter (uint8* d, const int samplePosition) const throw()
  21505. {
  21506. const uint8* const endData = ((uint8*) data.getData()) + bytesUsed;
  21507. while (d < endData && *(int*) d <= samplePosition)
  21508. {
  21509. d += 4;
  21510. d += 2 + *(uint16*) d;
  21511. }
  21512. return d;
  21513. }
  21514. MidiBuffer::Iterator::Iterator (const MidiBuffer& buffer_) throw()
  21515. : buffer (buffer_),
  21516. data ((uint8*) buffer_.data.getData())
  21517. {
  21518. }
  21519. MidiBuffer::Iterator::~Iterator() throw()
  21520. {
  21521. }
  21522. void MidiBuffer::Iterator::setNextSamplePosition (const int samplePosition) throw()
  21523. {
  21524. data = buffer.data;
  21525. const uint8* dataEnd = ((uint8*) buffer.data.getData()) + buffer.bytesUsed;
  21526. while (data < dataEnd && *(int*) data < samplePosition)
  21527. {
  21528. data += 4;
  21529. data += 2 + *(uint16*) data;
  21530. }
  21531. }
  21532. bool MidiBuffer::Iterator::getNextEvent (const uint8* &midiData,
  21533. int& numBytes,
  21534. int& samplePosition) throw()
  21535. {
  21536. if (data >= ((uint8*) buffer.data.getData()) + buffer.bytesUsed)
  21537. return false;
  21538. samplePosition = *(int*) data;
  21539. data += 4;
  21540. numBytes = *(uint16*) data;
  21541. data += 2;
  21542. midiData = data;
  21543. data += numBytes;
  21544. return true;
  21545. }
  21546. bool MidiBuffer::Iterator::getNextEvent (MidiMessage& result,
  21547. int& samplePosition) throw()
  21548. {
  21549. if (data >= ((uint8*) buffer.data.getData()) + buffer.bytesUsed)
  21550. return false;
  21551. samplePosition = *(int*) data;
  21552. data += 4;
  21553. const int numBytes = *(uint16*) data;
  21554. data += 2;
  21555. result = MidiMessage (data, numBytes, samplePosition);
  21556. data += numBytes;
  21557. return true;
  21558. }
  21559. END_JUCE_NAMESPACE
  21560. /********* End of inlined file: juce_MidiBuffer.cpp *********/
  21561. /********* Start of inlined file: juce_MidiFile.cpp *********/
  21562. BEGIN_JUCE_NAMESPACE
  21563. struct TempoInfo
  21564. {
  21565. double bpm, timestamp;
  21566. };
  21567. struct TimeSigInfo
  21568. {
  21569. int numerator, denominator;
  21570. double timestamp;
  21571. };
  21572. MidiFile::MidiFile() throw()
  21573. : timeFormat ((short) (unsigned short) 0xe728)
  21574. {
  21575. }
  21576. MidiFile::~MidiFile() throw()
  21577. {
  21578. clear();
  21579. }
  21580. void MidiFile::clear() throw()
  21581. {
  21582. tracks.clear();
  21583. }
  21584. int MidiFile::getNumTracks() const throw()
  21585. {
  21586. return tracks.size();
  21587. }
  21588. const MidiMessageSequence* MidiFile::getTrack (const int index) const throw()
  21589. {
  21590. return tracks [index];
  21591. }
  21592. void MidiFile::addTrack (const MidiMessageSequence& trackSequence) throw()
  21593. {
  21594. tracks.add (new MidiMessageSequence (trackSequence));
  21595. }
  21596. short MidiFile::getTimeFormat() const throw()
  21597. {
  21598. return timeFormat;
  21599. }
  21600. void MidiFile::setTicksPerQuarterNote (const int ticks) throw()
  21601. {
  21602. timeFormat = (short)ticks;
  21603. }
  21604. void MidiFile::setSmpteTimeFormat (const int framesPerSecond,
  21605. const int subframeResolution) throw()
  21606. {
  21607. timeFormat = (short) (((-framesPerSecond) << 8) | subframeResolution);
  21608. }
  21609. void MidiFile::findAllTempoEvents (MidiMessageSequence& tempoChangeEvents) const
  21610. {
  21611. for (int i = tracks.size(); --i >= 0;)
  21612. {
  21613. const int numEvents = tracks.getUnchecked(i)->getNumEvents();
  21614. for (int j = 0; j < numEvents; ++j)
  21615. {
  21616. const MidiMessage& m = tracks.getUnchecked(i)->getEventPointer (j)->message;
  21617. if (m.isTempoMetaEvent())
  21618. tempoChangeEvents.addEvent (m);
  21619. }
  21620. }
  21621. }
  21622. void MidiFile::findAllTimeSigEvents (MidiMessageSequence& timeSigEvents) const
  21623. {
  21624. for (int i = tracks.size(); --i >= 0;)
  21625. {
  21626. const int numEvents = tracks.getUnchecked(i)->getNumEvents();
  21627. for (int j = 0; j < numEvents; ++j)
  21628. {
  21629. const MidiMessage& m = tracks.getUnchecked(i)->getEventPointer (j)->message;
  21630. if (m.isTimeSignatureMetaEvent())
  21631. timeSigEvents.addEvent (m);
  21632. }
  21633. }
  21634. }
  21635. double MidiFile::getLastTimestamp() const
  21636. {
  21637. double t = 0.0;
  21638. for (int i = tracks.size(); --i >= 0;)
  21639. t = jmax (t, tracks.getUnchecked(i)->getEndTime());
  21640. return t;
  21641. }
  21642. static bool parseMidiHeader (const char* &data,
  21643. short& timeFormat,
  21644. short& fileType,
  21645. short& numberOfTracks)
  21646. {
  21647. unsigned int ch = (int) ByteOrder::bigEndianInt (data);
  21648. data += 4;
  21649. if (ch != ByteOrder::bigEndianInt ("MThd"))
  21650. {
  21651. bool ok = false;
  21652. if (ch == ByteOrder::bigEndianInt ("RIFF"))
  21653. {
  21654. for (int i = 0; i < 8; ++i)
  21655. {
  21656. ch = ByteOrder::bigEndianInt (data);
  21657. data += 4;
  21658. if (ch == ByteOrder::bigEndianInt ("MThd"))
  21659. {
  21660. ok = true;
  21661. break;
  21662. }
  21663. }
  21664. }
  21665. if (! ok)
  21666. return false;
  21667. }
  21668. unsigned int bytesRemaining = ByteOrder::bigEndianInt (data);
  21669. data += 4;
  21670. fileType = (short) ByteOrder::bigEndianShort (data);
  21671. data += 2;
  21672. numberOfTracks = (short) ByteOrder::bigEndianShort (data);
  21673. data += 2;
  21674. timeFormat = (short) ByteOrder::bigEndianShort (data);
  21675. data += 2;
  21676. bytesRemaining -= 6;
  21677. data += bytesRemaining;
  21678. return true;
  21679. }
  21680. bool MidiFile::readFrom (InputStream& sourceStream)
  21681. {
  21682. clear();
  21683. MemoryBlock data;
  21684. const int maxSensibleMidiFileSize = 2 * 1024 * 1024;
  21685. // (put a sanity-check on the file size, as midi files are generally small)
  21686. if (sourceStream.readIntoMemoryBlock (data, maxSensibleMidiFileSize))
  21687. {
  21688. size_t size = data.getSize();
  21689. const char* d = (char*) data.getData();
  21690. short fileType, expectedTracks;
  21691. if (size > 16 && parseMidiHeader (d, timeFormat, fileType, expectedTracks))
  21692. {
  21693. size -= (int) (d - (char*) data.getData());
  21694. int track = 0;
  21695. while (size > 0 && track < expectedTracks)
  21696. {
  21697. const int chunkType = (int) ByteOrder::bigEndianInt (d);
  21698. d += 4;
  21699. const int chunkSize = (int) ByteOrder::bigEndianInt (d);
  21700. d += 4;
  21701. if (chunkSize <= 0)
  21702. break;
  21703. if (size < 0)
  21704. return false;
  21705. if (chunkType == (int) ByteOrder::bigEndianInt ("MTrk"))
  21706. {
  21707. readNextTrack (d, chunkSize);
  21708. }
  21709. size -= chunkSize + 8;
  21710. d += chunkSize;
  21711. ++track;
  21712. }
  21713. return true;
  21714. }
  21715. }
  21716. return false;
  21717. }
  21718. // a comparator that puts all the note-offs before note-ons that have the same time
  21719. int MidiFile::compareElements (const MidiMessageSequence::MidiEventHolder* const first,
  21720. const MidiMessageSequence::MidiEventHolder* const second) throw()
  21721. {
  21722. const double diff = (first->message.getTimeStamp() - second->message.getTimeStamp());
  21723. if (diff == 0)
  21724. {
  21725. if (first->message.isNoteOff() && second->message.isNoteOn())
  21726. return -1;
  21727. else if (first->message.isNoteOn() && second->message.isNoteOff())
  21728. return 1;
  21729. else
  21730. return 0;
  21731. }
  21732. else
  21733. {
  21734. return (diff > 0) ? 1 : -1;
  21735. }
  21736. }
  21737. void MidiFile::readNextTrack (const char* data, int size)
  21738. {
  21739. double time = 0;
  21740. char lastStatusByte = 0;
  21741. MidiMessageSequence result;
  21742. while (size > 0)
  21743. {
  21744. int bytesUsed;
  21745. const int delay = MidiMessage::readVariableLengthVal ((const uint8*) data, bytesUsed);
  21746. data += bytesUsed;
  21747. size -= bytesUsed;
  21748. time += delay;
  21749. int messSize = 0;
  21750. const MidiMessage mm ((const uint8*) data, size, messSize, lastStatusByte, time);
  21751. if (messSize <= 0)
  21752. break;
  21753. size -= messSize;
  21754. data += messSize;
  21755. result.addEvent (mm);
  21756. const char firstByte = *(mm.getRawData());
  21757. if ((firstByte & 0xf0) != 0xf0)
  21758. lastStatusByte = firstByte;
  21759. }
  21760. // use a sort that puts all the note-offs before note-ons that have the same time
  21761. result.list.sort (*this, true);
  21762. result.updateMatchedPairs();
  21763. addTrack (result);
  21764. }
  21765. static double convertTicksToSeconds (const double time,
  21766. const MidiMessageSequence& tempoEvents,
  21767. const int timeFormat)
  21768. {
  21769. if (timeFormat > 0)
  21770. {
  21771. int numer = 4, denom = 4;
  21772. double tempoTime = 0.0, correctedTempoTime = 0.0;
  21773. const double tickLen = 1.0 / (timeFormat & 0x7fff);
  21774. double secsPerTick = 0.5 * tickLen;
  21775. const int numEvents = tempoEvents.getNumEvents();
  21776. for (int i = 0; i < numEvents; ++i)
  21777. {
  21778. const MidiMessage& m = tempoEvents.getEventPointer(i)->message;
  21779. if (time <= m.getTimeStamp())
  21780. break;
  21781. if (timeFormat > 0)
  21782. {
  21783. correctedTempoTime = correctedTempoTime
  21784. + (m.getTimeStamp() - tempoTime) * secsPerTick;
  21785. }
  21786. else
  21787. {
  21788. correctedTempoTime = tickLen * m.getTimeStamp() / (((timeFormat & 0x7fff) >> 8) * (timeFormat & 0xff));
  21789. }
  21790. tempoTime = m.getTimeStamp();
  21791. if (m.isTempoMetaEvent())
  21792. secsPerTick = tickLen * m.getTempoSecondsPerQuarterNote();
  21793. else if (m.isTimeSignatureMetaEvent())
  21794. m.getTimeSignatureInfo (numer, denom);
  21795. while (i + 1 < numEvents)
  21796. {
  21797. const MidiMessage& m2 = tempoEvents.getEventPointer(i + 1)->message;
  21798. if (m2.getTimeStamp() == tempoTime)
  21799. {
  21800. ++i;
  21801. if (m2.isTempoMetaEvent())
  21802. secsPerTick = tickLen * m2.getTempoSecondsPerQuarterNote();
  21803. else if (m2.isTimeSignatureMetaEvent())
  21804. m2.getTimeSignatureInfo (numer, denom);
  21805. }
  21806. else
  21807. {
  21808. break;
  21809. }
  21810. }
  21811. }
  21812. return correctedTempoTime + (time - tempoTime) * secsPerTick;
  21813. }
  21814. else
  21815. {
  21816. return time / (((timeFormat & 0x7fff) >> 8) * (timeFormat & 0xff));
  21817. }
  21818. }
  21819. void MidiFile::convertTimestampTicksToSeconds()
  21820. {
  21821. MidiMessageSequence tempoEvents;
  21822. findAllTempoEvents (tempoEvents);
  21823. findAllTimeSigEvents (tempoEvents);
  21824. for (int i = 0; i < tracks.size(); ++i)
  21825. {
  21826. MidiMessageSequence& ms = *tracks.getUnchecked(i);
  21827. for (int j = ms.getNumEvents(); --j >= 0;)
  21828. {
  21829. MidiMessage& m = ms.getEventPointer(j)->message;
  21830. m.setTimeStamp (convertTicksToSeconds (m.getTimeStamp(),
  21831. tempoEvents,
  21832. timeFormat));
  21833. }
  21834. }
  21835. }
  21836. static void writeVariableLengthInt (OutputStream& out, unsigned int v)
  21837. {
  21838. unsigned int buffer = v & 0x7F;
  21839. while ((v >>= 7) != 0)
  21840. {
  21841. buffer <<= 8;
  21842. buffer |= ((v & 0x7F) | 0x80);
  21843. }
  21844. for (;;)
  21845. {
  21846. out.writeByte ((char) buffer);
  21847. if (buffer & 0x80)
  21848. buffer >>= 8;
  21849. else
  21850. break;
  21851. }
  21852. }
  21853. bool MidiFile::writeTo (OutputStream& out)
  21854. {
  21855. out.writeIntBigEndian ((int) ByteOrder::bigEndianInt ("MThd"));
  21856. out.writeIntBigEndian (6);
  21857. out.writeShortBigEndian (1); // type
  21858. out.writeShortBigEndian ((short) tracks.size());
  21859. out.writeShortBigEndian (timeFormat);
  21860. for (int i = 0; i < tracks.size(); ++i)
  21861. writeTrack (out, i);
  21862. out.flush();
  21863. return true;
  21864. }
  21865. void MidiFile::writeTrack (OutputStream& mainOut,
  21866. const int trackNum)
  21867. {
  21868. MemoryOutputStream out;
  21869. const MidiMessageSequence& ms = *tracks[trackNum];
  21870. int lastTick = 0;
  21871. char lastStatusByte = 0;
  21872. for (int i = 0; i < ms.getNumEvents(); ++i)
  21873. {
  21874. const MidiMessage& mm = ms.getEventPointer(i)->message;
  21875. const int tick = roundToInt (mm.getTimeStamp());
  21876. const int delta = jmax (0, tick - lastTick);
  21877. writeVariableLengthInt (out, delta);
  21878. lastTick = tick;
  21879. const char statusByte = *(mm.getRawData());
  21880. if ((statusByte == lastStatusByte)
  21881. && ((statusByte & 0xf0) != 0xf0)
  21882. && i > 0
  21883. && mm.getRawDataSize() > 1)
  21884. {
  21885. out.write (mm.getRawData() + 1, mm.getRawDataSize() - 1);
  21886. }
  21887. else
  21888. {
  21889. out.write (mm.getRawData(), mm.getRawDataSize());
  21890. }
  21891. lastStatusByte = statusByte;
  21892. }
  21893. out.writeByte (0);
  21894. const MidiMessage m (MidiMessage::endOfTrack());
  21895. out.write (m.getRawData(),
  21896. m.getRawDataSize());
  21897. mainOut.writeIntBigEndian ((int) ByteOrder::bigEndianInt ("MTrk"));
  21898. mainOut.writeIntBigEndian ((int) out.getDataSize());
  21899. mainOut.write (out.getData(), (int) out.getDataSize());
  21900. }
  21901. END_JUCE_NAMESPACE
  21902. /********* End of inlined file: juce_MidiFile.cpp *********/
  21903. /********* Start of inlined file: juce_MidiKeyboardState.cpp *********/
  21904. BEGIN_JUCE_NAMESPACE
  21905. MidiKeyboardState::MidiKeyboardState()
  21906. {
  21907. zeromem (noteStates, sizeof (noteStates));
  21908. }
  21909. MidiKeyboardState::~MidiKeyboardState()
  21910. {
  21911. }
  21912. void MidiKeyboardState::reset()
  21913. {
  21914. const ScopedLock sl (lock);
  21915. zeromem (noteStates, sizeof (noteStates));
  21916. eventsToAdd.clear();
  21917. }
  21918. bool MidiKeyboardState::isNoteOn (const int midiChannel, const int n) const throw()
  21919. {
  21920. jassert (midiChannel >= 0 && midiChannel <= 16);
  21921. return ((unsigned int) n) < 128
  21922. && (noteStates[n] & (1 << (midiChannel - 1))) != 0;
  21923. }
  21924. bool MidiKeyboardState::isNoteOnForChannels (const int midiChannelMask, const int n) const throw()
  21925. {
  21926. return ((unsigned int) n) < 128
  21927. && (noteStates[n] & midiChannelMask) != 0;
  21928. }
  21929. void MidiKeyboardState::noteOn (const int midiChannel, const int midiNoteNumber, const float velocity)
  21930. {
  21931. jassert (midiChannel >= 0 && midiChannel <= 16);
  21932. jassert (((unsigned int) midiNoteNumber) < 128);
  21933. const ScopedLock sl (lock);
  21934. if (((unsigned int) midiNoteNumber) < 128)
  21935. {
  21936. const int timeNow = (int) Time::getMillisecondCounter();
  21937. eventsToAdd.addEvent (MidiMessage::noteOn (midiChannel, midiNoteNumber, velocity), timeNow);
  21938. eventsToAdd.clear (0, timeNow - 500);
  21939. noteOnInternal (midiChannel, midiNoteNumber, velocity);
  21940. }
  21941. }
  21942. void MidiKeyboardState::noteOnInternal (const int midiChannel, const int midiNoteNumber, const float velocity)
  21943. {
  21944. if (((unsigned int) midiNoteNumber) < 128)
  21945. {
  21946. noteStates [midiNoteNumber] |= (1 << (midiChannel - 1));
  21947. for (int i = listeners.size(); --i >= 0;)
  21948. ((MidiKeyboardStateListener*) listeners.getUnchecked(i))
  21949. ->handleNoteOn (this, midiChannel, midiNoteNumber, velocity);
  21950. }
  21951. }
  21952. void MidiKeyboardState::noteOff (const int midiChannel, const int midiNoteNumber)
  21953. {
  21954. const ScopedLock sl (lock);
  21955. if (isNoteOn (midiChannel, midiNoteNumber))
  21956. {
  21957. const int timeNow = (int) Time::getMillisecondCounter();
  21958. eventsToAdd.addEvent (MidiMessage::noteOff (midiChannel, midiNoteNumber), timeNow);
  21959. eventsToAdd.clear (0, timeNow - 500);
  21960. noteOffInternal (midiChannel, midiNoteNumber);
  21961. }
  21962. }
  21963. void MidiKeyboardState::noteOffInternal (const int midiChannel, const int midiNoteNumber)
  21964. {
  21965. if (isNoteOn (midiChannel, midiNoteNumber))
  21966. {
  21967. noteStates [midiNoteNumber] &= ~(1 << (midiChannel - 1));
  21968. for (int i = listeners.size(); --i >= 0;)
  21969. ((MidiKeyboardStateListener*) listeners.getUnchecked(i))
  21970. ->handleNoteOff (this, midiChannel, midiNoteNumber);
  21971. }
  21972. }
  21973. void MidiKeyboardState::allNotesOff (const int midiChannel)
  21974. {
  21975. const ScopedLock sl (lock);
  21976. if (midiChannel <= 0)
  21977. {
  21978. for (int i = 1; i <= 16; ++i)
  21979. allNotesOff (i);
  21980. }
  21981. else
  21982. {
  21983. for (int i = 0; i < 128; ++i)
  21984. noteOff (midiChannel, i);
  21985. }
  21986. }
  21987. void MidiKeyboardState::processNextMidiEvent (const MidiMessage& message)
  21988. {
  21989. if (message.isNoteOn())
  21990. {
  21991. noteOnInternal (message.getChannel(), message.getNoteNumber(), message.getFloatVelocity());
  21992. }
  21993. else if (message.isNoteOff())
  21994. {
  21995. noteOffInternal (message.getChannel(), message.getNoteNumber());
  21996. }
  21997. else if (message.isAllNotesOff())
  21998. {
  21999. for (int i = 0; i < 128; ++i)
  22000. noteOffInternal (message.getChannel(), i);
  22001. }
  22002. }
  22003. void MidiKeyboardState::processNextMidiBuffer (MidiBuffer& buffer,
  22004. const int startSample,
  22005. const int numSamples,
  22006. const bool injectIndirectEvents)
  22007. {
  22008. MidiBuffer::Iterator i (buffer);
  22009. MidiMessage message (0xf4, 0.0);
  22010. int time;
  22011. const ScopedLock sl (lock);
  22012. while (i.getNextEvent (message, time))
  22013. processNextMidiEvent (message);
  22014. if (injectIndirectEvents)
  22015. {
  22016. MidiBuffer::Iterator i2 (eventsToAdd);
  22017. const int firstEventToAdd = eventsToAdd.getFirstEventTime();
  22018. const double scaleFactor = numSamples / (double) (eventsToAdd.getLastEventTime() + 1 - firstEventToAdd);
  22019. while (i2.getNextEvent (message, time))
  22020. {
  22021. const int pos = jlimit (0, numSamples - 1, roundToInt ((time - firstEventToAdd) * scaleFactor));
  22022. buffer.addEvent (message, startSample + pos);
  22023. }
  22024. }
  22025. eventsToAdd.clear();
  22026. }
  22027. void MidiKeyboardState::addListener (MidiKeyboardStateListener* const listener) throw()
  22028. {
  22029. const ScopedLock sl (lock);
  22030. listeners.addIfNotAlreadyThere (listener);
  22031. }
  22032. void MidiKeyboardState::removeListener (MidiKeyboardStateListener* const listener) throw()
  22033. {
  22034. const ScopedLock sl (lock);
  22035. listeners.removeValue (listener);
  22036. }
  22037. END_JUCE_NAMESPACE
  22038. /********* End of inlined file: juce_MidiKeyboardState.cpp *********/
  22039. /********* Start of inlined file: juce_MidiMessage.cpp *********/
  22040. BEGIN_JUCE_NAMESPACE
  22041. int MidiMessage::readVariableLengthVal (const uint8* data,
  22042. int& numBytesUsed) throw()
  22043. {
  22044. numBytesUsed = 0;
  22045. int v = 0;
  22046. int i;
  22047. do
  22048. {
  22049. i = (int) *data++;
  22050. if (++numBytesUsed > 6)
  22051. break;
  22052. v = (v << 7) + (i & 0x7f);
  22053. } while (i & 0x80);
  22054. return v;
  22055. }
  22056. int MidiMessage::getMessageLengthFromFirstByte (const uint8 firstByte) throw()
  22057. {
  22058. // this method only works for valid starting bytes of a short midi message
  22059. jassert (firstByte >= 0x80
  22060. && firstByte != 0xf0
  22061. && firstByte != 0xf7);
  22062. static const char messageLengths[] =
  22063. {
  22064. 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
  22065. 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
  22066. 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
  22067. 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
  22068. 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  22069. 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  22070. 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
  22071. 1, 2, 3, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1
  22072. };
  22073. return messageLengths [firstByte & 0x7f];
  22074. }
  22075. MidiMessage::MidiMessage (const uint8* const d,
  22076. const int dataSize,
  22077. const double t) throw()
  22078. : timeStamp (t),
  22079. message (0),
  22080. size (dataSize)
  22081. {
  22082. jassert (dataSize > 0);
  22083. if (dataSize <= 4)
  22084. data = (uint8*) &message;
  22085. else
  22086. data = (uint8*) juce_malloc (dataSize);
  22087. memcpy (data, d, dataSize);
  22088. // check that the length matches the data..
  22089. jassert (size > 3 || *d >= 0xf0 || getMessageLengthFromFirstByte (*d) == size);
  22090. }
  22091. MidiMessage::MidiMessage (const int byte1,
  22092. const double t) throw()
  22093. : timeStamp (t),
  22094. data ((uint8*) &message),
  22095. size (1)
  22096. {
  22097. data[0] = (uint8) byte1;
  22098. // check that the length matches the data..
  22099. jassert (byte1 >= 0xf0 || getMessageLengthFromFirstByte ((uint8) byte1) == 1);
  22100. }
  22101. MidiMessage::MidiMessage (const int byte1,
  22102. const int byte2,
  22103. const double t) throw()
  22104. : timeStamp (t),
  22105. data ((uint8*) &message),
  22106. size (2)
  22107. {
  22108. data[0] = (uint8) byte1;
  22109. data[1] = (uint8) byte2;
  22110. // check that the length matches the data..
  22111. jassert (byte1 >= 0xf0 || getMessageLengthFromFirstByte ((uint8) byte1) == 2);
  22112. }
  22113. MidiMessage::MidiMessage (const int byte1,
  22114. const int byte2,
  22115. const int byte3,
  22116. const double t) throw()
  22117. : timeStamp (t),
  22118. data ((uint8*) &message),
  22119. size (3)
  22120. {
  22121. data[0] = (uint8) byte1;
  22122. data[1] = (uint8) byte2;
  22123. data[2] = (uint8) byte3;
  22124. // check that the length matches the data..
  22125. jassert (byte1 >= 0xf0 || getMessageLengthFromFirstByte ((uint8) byte1) == 3);
  22126. }
  22127. MidiMessage::MidiMessage (const MidiMessage& other) throw()
  22128. : timeStamp (other.timeStamp),
  22129. message (other.message),
  22130. size (other.size)
  22131. {
  22132. if (other.data != (uint8*) &other.message)
  22133. {
  22134. data = (uint8*) juce_malloc (size);
  22135. memcpy (data, other.data, size);
  22136. }
  22137. else
  22138. {
  22139. data = (uint8*) &message;
  22140. }
  22141. }
  22142. MidiMessage::MidiMessage (const MidiMessage& other,
  22143. const double newTimeStamp) throw()
  22144. : timeStamp (newTimeStamp),
  22145. message (other.message),
  22146. size (other.size)
  22147. {
  22148. if (other.data != (uint8*) &other.message)
  22149. {
  22150. data = (uint8*) juce_malloc (size);
  22151. memcpy (data, other.data, size);
  22152. }
  22153. else
  22154. {
  22155. data = (uint8*) &message;
  22156. }
  22157. }
  22158. MidiMessage::MidiMessage (const uint8* src,
  22159. int sz,
  22160. int& numBytesUsed,
  22161. const uint8 lastStatusByte,
  22162. double t) throw()
  22163. : timeStamp (t),
  22164. data ((uint8*) &message),
  22165. message (0)
  22166. {
  22167. unsigned int byte = (unsigned int) *src;
  22168. if (byte < 0x80)
  22169. {
  22170. byte = (unsigned int) (uint8) lastStatusByte;
  22171. numBytesUsed = -1;
  22172. }
  22173. else
  22174. {
  22175. numBytesUsed = 0;
  22176. --sz;
  22177. ++src;
  22178. }
  22179. if (byte >= 0x80)
  22180. {
  22181. if (byte == 0xf0)
  22182. {
  22183. const uint8* d = (const uint8*) src;
  22184. while (d < src + sz)
  22185. {
  22186. if (*d >= 0x80) // stop if we hit a status byte, and don't include it in this message
  22187. {
  22188. if (*d == 0xf7) // include an 0xf7 if we hit one
  22189. ++d;
  22190. break;
  22191. }
  22192. ++d;
  22193. }
  22194. size = 1 + (int) (d - src);
  22195. data = (uint8*) juce_malloc (size);
  22196. *data = (uint8) byte;
  22197. memcpy (data + 1, src, size - 1);
  22198. }
  22199. else if (byte == 0xff)
  22200. {
  22201. int n;
  22202. const int bytesLeft = readVariableLengthVal (src + 1, n);
  22203. size = jmin (sz + 1, n + 2 + bytesLeft);
  22204. data = (uint8*) juce_malloc (size);
  22205. *data = (uint8) byte;
  22206. memcpy (data + 1, src, size - 1);
  22207. }
  22208. else
  22209. {
  22210. size = getMessageLengthFromFirstByte ((uint8) byte);
  22211. *data = (uint8) byte;
  22212. if (size > 1)
  22213. {
  22214. data[1] = src[0];
  22215. if (size > 2)
  22216. data[2] = src[1];
  22217. }
  22218. }
  22219. numBytesUsed += size;
  22220. }
  22221. else
  22222. {
  22223. message = 0;
  22224. size = 0;
  22225. }
  22226. }
  22227. const MidiMessage& MidiMessage::operator= (const MidiMessage& other) throw()
  22228. {
  22229. if (this != &other)
  22230. {
  22231. timeStamp = other.timeStamp;
  22232. size = other.size;
  22233. message = other.message;
  22234. if (data != (uint8*) &message)
  22235. juce_free (data);
  22236. if (other.data != (uint8*) &other.message)
  22237. {
  22238. data = (uint8*) juce_malloc (size);
  22239. memcpy (data, other.data, size);
  22240. }
  22241. else
  22242. {
  22243. data = (uint8*) &message;
  22244. }
  22245. }
  22246. return *this;
  22247. }
  22248. MidiMessage::~MidiMessage() throw()
  22249. {
  22250. if (data != (uint8*) &message)
  22251. juce_free (data);
  22252. }
  22253. int MidiMessage::getChannel() const throw()
  22254. {
  22255. if ((data[0] & 0xf0) != 0xf0)
  22256. return (data[0] & 0xf) + 1;
  22257. else
  22258. return 0;
  22259. }
  22260. bool MidiMessage::isForChannel (const int channel) const throw()
  22261. {
  22262. jassert (channel > 0 && channel <= 16); // valid channels are numbered 1 to 16
  22263. return ((data[0] & 0xf) == channel - 1)
  22264. && ((data[0] & 0xf0) != 0xf0);
  22265. }
  22266. void MidiMessage::setChannel (const int channel) throw()
  22267. {
  22268. jassert (channel > 0 && channel <= 16); // valid channels are numbered 1 to 16
  22269. if ((data[0] & 0xf0) != (uint8) 0xf0)
  22270. data[0] = (uint8) ((data[0] & (uint8)0xf0)
  22271. | (uint8)(channel - 1));
  22272. }
  22273. bool MidiMessage::isNoteOn (const bool returnTrueForVelocity0) const throw()
  22274. {
  22275. return ((data[0] & 0xf0) == 0x90)
  22276. && (returnTrueForVelocity0 || data[2] != 0);
  22277. }
  22278. bool MidiMessage::isNoteOff (const bool returnTrueForNoteOnVelocity0) const throw()
  22279. {
  22280. return ((data[0] & 0xf0) == 0x80)
  22281. || (returnTrueForNoteOnVelocity0 && (data[2] == 0) && ((data[0] & 0xf0) == 0x90));
  22282. }
  22283. bool MidiMessage::isNoteOnOrOff() const throw()
  22284. {
  22285. const int d = data[0] & 0xf0;
  22286. return (d == 0x90) || (d == 0x80);
  22287. }
  22288. int MidiMessage::getNoteNumber() const throw()
  22289. {
  22290. return data[1];
  22291. }
  22292. void MidiMessage::setNoteNumber (const int newNoteNumber) throw()
  22293. {
  22294. if (isNoteOnOrOff())
  22295. data[1] = (uint8) jlimit (0, 127, newNoteNumber);
  22296. }
  22297. uint8 MidiMessage::getVelocity() const throw()
  22298. {
  22299. if (isNoteOnOrOff())
  22300. return data[2];
  22301. else
  22302. return 0;
  22303. }
  22304. float MidiMessage::getFloatVelocity() const throw()
  22305. {
  22306. return getVelocity() * (1.0f / 127.0f);
  22307. }
  22308. void MidiMessage::setVelocity (const float newVelocity) throw()
  22309. {
  22310. if (isNoteOnOrOff())
  22311. data[2] = (uint8) jlimit (0, 0x7f, roundToInt (newVelocity * 127.0f));
  22312. }
  22313. void MidiMessage::multiplyVelocity (const float scaleFactor) throw()
  22314. {
  22315. if (isNoteOnOrOff())
  22316. data[2] = (uint8) jlimit (0, 0x7f, roundToInt (scaleFactor * data[2]));
  22317. }
  22318. bool MidiMessage::isAftertouch() const throw()
  22319. {
  22320. return (data[0] & 0xf0) == 0xa0;
  22321. }
  22322. int MidiMessage::getAfterTouchValue() const throw()
  22323. {
  22324. return data[2];
  22325. }
  22326. const MidiMessage MidiMessage::aftertouchChange (const int channel,
  22327. const int noteNum,
  22328. const int aftertouchValue) throw()
  22329. {
  22330. jassert (channel > 0 && channel <= 16); // valid channels are numbered 1 to 16
  22331. jassert (((unsigned int) noteNum) <= 127);
  22332. jassert (((unsigned int) aftertouchValue) <= 127);
  22333. return MidiMessage (0xa0 | jlimit (0, 15, channel - 1),
  22334. noteNum & 0x7f,
  22335. aftertouchValue & 0x7f);
  22336. }
  22337. bool MidiMessage::isChannelPressure() const throw()
  22338. {
  22339. return (data[0] & 0xf0) == 0xd0;
  22340. }
  22341. int MidiMessage::getChannelPressureValue() const throw()
  22342. {
  22343. jassert (isChannelPressure());
  22344. return data[1];
  22345. }
  22346. const MidiMessage MidiMessage::channelPressureChange (const int channel,
  22347. const int pressure) throw()
  22348. {
  22349. jassert (channel > 0 && channel <= 16); // valid channels are numbered 1 to 16
  22350. jassert (((unsigned int) pressure) <= 127);
  22351. return MidiMessage (0xd0 | jlimit (0, 15, channel - 1),
  22352. pressure & 0x7f);
  22353. }
  22354. bool MidiMessage::isProgramChange() const throw()
  22355. {
  22356. return (data[0] & 0xf0) == 0xc0;
  22357. }
  22358. int MidiMessage::getProgramChangeNumber() const throw()
  22359. {
  22360. return data[1];
  22361. }
  22362. const MidiMessage MidiMessage::programChange (const int channel,
  22363. const int programNumber) throw()
  22364. {
  22365. jassert (channel > 0 && channel <= 16); // valid channels are numbered 1 to 16
  22366. return MidiMessage (0xc0 | jlimit (0, 15, channel - 1),
  22367. programNumber & 0x7f);
  22368. }
  22369. bool MidiMessage::isPitchWheel() const throw()
  22370. {
  22371. return (data[0] & 0xf0) == 0xe0;
  22372. }
  22373. int MidiMessage::getPitchWheelValue() const throw()
  22374. {
  22375. return data[1] | (data[2] << 7);
  22376. }
  22377. const MidiMessage MidiMessage::pitchWheel (const int channel,
  22378. const int position) throw()
  22379. {
  22380. jassert (channel > 0 && channel <= 16); // valid channels are numbered 1 to 16
  22381. jassert (((unsigned int) position) <= 0x3fff);
  22382. return MidiMessage (0xe0 | jlimit (0, 15, channel - 1),
  22383. position & 127,
  22384. (position >> 7) & 127);
  22385. }
  22386. bool MidiMessage::isController() const throw()
  22387. {
  22388. return (data[0] & 0xf0) == 0xb0;
  22389. }
  22390. int MidiMessage::getControllerNumber() const throw()
  22391. {
  22392. jassert (isController());
  22393. return data[1];
  22394. }
  22395. int MidiMessage::getControllerValue() const throw()
  22396. {
  22397. jassert (isController());
  22398. return data[2];
  22399. }
  22400. const MidiMessage MidiMessage::controllerEvent (const int channel,
  22401. const int controllerType,
  22402. const int value) throw()
  22403. {
  22404. // the channel must be between 1 and 16 inclusive
  22405. jassert (channel > 0 && channel <= 16);
  22406. return MidiMessage (0xb0 | jlimit (0, 15, channel - 1),
  22407. controllerType & 127,
  22408. value & 127);
  22409. }
  22410. const MidiMessage MidiMessage::noteOn (const int channel,
  22411. const int noteNumber,
  22412. const float velocity) throw()
  22413. {
  22414. return noteOn (channel, noteNumber, (uint8)(velocity * 127.0f));
  22415. }
  22416. const MidiMessage MidiMessage::noteOn (const int channel,
  22417. const int noteNumber,
  22418. const uint8 velocity) throw()
  22419. {
  22420. jassert (channel > 0 && channel <= 16);
  22421. jassert (((unsigned int) noteNumber) <= 127);
  22422. return MidiMessage (0x90 | jlimit (0, 15, channel - 1),
  22423. noteNumber & 127,
  22424. jlimit (0, 127, roundToInt (velocity)));
  22425. }
  22426. const MidiMessage MidiMessage::noteOff (const int channel,
  22427. const int noteNumber) throw()
  22428. {
  22429. jassert (channel > 0 && channel <= 16);
  22430. jassert (((unsigned int) noteNumber) <= 127);
  22431. return MidiMessage (0x80 | jlimit (0, 15, channel - 1), noteNumber & 127, 0);
  22432. }
  22433. const MidiMessage MidiMessage::allNotesOff (const int channel) throw()
  22434. {
  22435. jassert (channel > 0 && channel <= 16);
  22436. return controllerEvent (channel, 123, 0);
  22437. }
  22438. bool MidiMessage::isAllNotesOff() const throw()
  22439. {
  22440. return (data[0] & 0xf0) == 0xb0
  22441. && data[1] == 123;
  22442. }
  22443. const MidiMessage MidiMessage::allSoundOff (const int channel) throw()
  22444. {
  22445. return controllerEvent (channel, 120, 0);
  22446. }
  22447. bool MidiMessage::isAllSoundOff() const throw()
  22448. {
  22449. return (data[0] & 0xf0) == 0xb0
  22450. && data[1] == 120;
  22451. }
  22452. const MidiMessage MidiMessage::allControllersOff (const int channel) throw()
  22453. {
  22454. return controllerEvent (channel, 121, 0);
  22455. }
  22456. const MidiMessage MidiMessage::masterVolume (const float volume) throw()
  22457. {
  22458. const int vol = jlimit (0, 0x3fff, roundToInt (volume * 0x4000));
  22459. uint8 buf[8];
  22460. buf[0] = 0xf0;
  22461. buf[1] = 0x7f;
  22462. buf[2] = 0x7f;
  22463. buf[3] = 0x04;
  22464. buf[4] = 0x01;
  22465. buf[5] = (uint8) (vol & 0x7f);
  22466. buf[6] = (uint8) (vol >> 7);
  22467. buf[7] = 0xf7;
  22468. return MidiMessage (buf, 8);
  22469. }
  22470. bool MidiMessage::isSysEx() const throw()
  22471. {
  22472. return *data == 0xf0;
  22473. }
  22474. const MidiMessage MidiMessage::createSysExMessage (const uint8* sysexData,
  22475. const int dataSize) throw()
  22476. {
  22477. MemoryBlock mm (dataSize + 2);
  22478. uint8* const m = (uint8*) mm.getData();
  22479. m[0] = 0xf0;
  22480. memcpy (m + 1, sysexData, dataSize);
  22481. m[dataSize + 1] = 0xf7;
  22482. return MidiMessage (m, dataSize + 2);
  22483. }
  22484. const uint8* MidiMessage::getSysExData() const throw()
  22485. {
  22486. return (isSysEx()) ? getRawData() + 1
  22487. : 0;
  22488. }
  22489. int MidiMessage::getSysExDataSize() const throw()
  22490. {
  22491. return (isSysEx()) ? size - 2
  22492. : 0;
  22493. }
  22494. bool MidiMessage::isMetaEvent() const throw()
  22495. {
  22496. return *data == 0xff;
  22497. }
  22498. bool MidiMessage::isActiveSense() const throw()
  22499. {
  22500. return *data == 0xfe;
  22501. }
  22502. int MidiMessage::getMetaEventType() const throw()
  22503. {
  22504. if (*data != 0xff)
  22505. return -1;
  22506. else
  22507. return data[1];
  22508. }
  22509. int MidiMessage::getMetaEventLength() const throw()
  22510. {
  22511. if (*data == 0xff)
  22512. {
  22513. int n;
  22514. return jmin (size - 2, readVariableLengthVal (data + 2, n));
  22515. }
  22516. return 0;
  22517. }
  22518. const uint8* MidiMessage::getMetaEventData() const throw()
  22519. {
  22520. int n;
  22521. const uint8* d = data + 2;
  22522. readVariableLengthVal (d, n);
  22523. return d + n;
  22524. }
  22525. bool MidiMessage::isTrackMetaEvent() const throw()
  22526. {
  22527. return getMetaEventType() == 0;
  22528. }
  22529. bool MidiMessage::isEndOfTrackMetaEvent() const throw()
  22530. {
  22531. return getMetaEventType() == 47;
  22532. }
  22533. bool MidiMessage::isTextMetaEvent() const throw()
  22534. {
  22535. const int t = getMetaEventType();
  22536. return t > 0 && t < 16;
  22537. }
  22538. const String MidiMessage::getTextFromTextMetaEvent() const throw()
  22539. {
  22540. return String ((const char*) getMetaEventData(),
  22541. getMetaEventLength());
  22542. }
  22543. bool MidiMessage::isTrackNameEvent() const throw()
  22544. {
  22545. return (data[1] == 3)
  22546. && (*data == 0xff);
  22547. }
  22548. bool MidiMessage::isTempoMetaEvent() const throw()
  22549. {
  22550. return (data[1] == 81)
  22551. && (*data == 0xff);
  22552. }
  22553. bool MidiMessage::isMidiChannelMetaEvent() const throw()
  22554. {
  22555. return (data[1] == 0x20)
  22556. && (*data == 0xff)
  22557. && (data[2] == 1);
  22558. }
  22559. int MidiMessage::getMidiChannelMetaEventChannel() const throw()
  22560. {
  22561. return data[3] + 1;
  22562. }
  22563. double MidiMessage::getTempoSecondsPerQuarterNote() const throw()
  22564. {
  22565. if (! isTempoMetaEvent())
  22566. return 0.0;
  22567. const uint8* const d = getMetaEventData();
  22568. return (((unsigned int) d[0] << 16)
  22569. | ((unsigned int) d[1] << 8)
  22570. | d[2])
  22571. / 1000000.0;
  22572. }
  22573. double MidiMessage::getTempoMetaEventTickLength (const short timeFormat) const throw()
  22574. {
  22575. if (timeFormat > 0)
  22576. {
  22577. if (! isTempoMetaEvent())
  22578. return 0.5 / timeFormat;
  22579. return getTempoSecondsPerQuarterNote() / timeFormat;
  22580. }
  22581. else
  22582. {
  22583. const int frameCode = (-timeFormat) >> 8;
  22584. double framesPerSecond;
  22585. switch (frameCode)
  22586. {
  22587. case 24: framesPerSecond = 24.0; break;
  22588. case 25: framesPerSecond = 25.0; break;
  22589. case 29: framesPerSecond = 29.97; break;
  22590. case 30: framesPerSecond = 30.0; break;
  22591. default: framesPerSecond = 30.0; break;
  22592. }
  22593. return (1.0 / framesPerSecond) / (timeFormat & 0xff);
  22594. }
  22595. }
  22596. const MidiMessage MidiMessage::tempoMetaEvent (int microsecondsPerQuarterNote) throw()
  22597. {
  22598. uint8 d[8];
  22599. d[0] = 0xff;
  22600. d[1] = 81;
  22601. d[2] = 3;
  22602. d[3] = (uint8) (microsecondsPerQuarterNote >> 16);
  22603. d[4] = (uint8) ((microsecondsPerQuarterNote >> 8) & 0xff);
  22604. d[5] = (uint8) (microsecondsPerQuarterNote & 0xff);
  22605. return MidiMessage (d, 6, 0.0);
  22606. }
  22607. bool MidiMessage::isTimeSignatureMetaEvent() const throw()
  22608. {
  22609. return (data[1] == 0x58)
  22610. && (*data == (uint8) 0xff);
  22611. }
  22612. void MidiMessage::getTimeSignatureInfo (int& numerator,
  22613. int& denominator) const throw()
  22614. {
  22615. if (isTimeSignatureMetaEvent())
  22616. {
  22617. const uint8* const d = getMetaEventData();
  22618. numerator = d[0];
  22619. denominator = 1 << d[1];
  22620. }
  22621. else
  22622. {
  22623. numerator = 4;
  22624. denominator = 4;
  22625. }
  22626. }
  22627. const MidiMessage MidiMessage::timeSignatureMetaEvent (const int numerator,
  22628. const int denominator) throw()
  22629. {
  22630. uint8 d[8];
  22631. d[0] = 0xff;
  22632. d[1] = 0x58;
  22633. d[2] = 0x04;
  22634. d[3] = (uint8) numerator;
  22635. int n = 1;
  22636. int powerOfTwo = 0;
  22637. while (n < denominator)
  22638. {
  22639. n <<= 1;
  22640. ++powerOfTwo;
  22641. }
  22642. d[4] = (uint8) powerOfTwo;
  22643. d[5] = 0x01;
  22644. d[6] = 96;
  22645. return MidiMessage (d, 7, 0.0);
  22646. }
  22647. const MidiMessage MidiMessage::midiChannelMetaEvent (const int channel) throw()
  22648. {
  22649. uint8 d[8];
  22650. d[0] = 0xff;
  22651. d[1] = 0x20;
  22652. d[2] = 0x01;
  22653. d[3] = (uint8) jlimit (0, 0xff, channel - 1);
  22654. return MidiMessage (d, 4, 0.0);
  22655. }
  22656. bool MidiMessage::isKeySignatureMetaEvent() const throw()
  22657. {
  22658. return getMetaEventType() == 89;
  22659. }
  22660. int MidiMessage::getKeySignatureNumberOfSharpsOrFlats() const throw()
  22661. {
  22662. return (int) *getMetaEventData();
  22663. }
  22664. const MidiMessage MidiMessage::endOfTrack() throw()
  22665. {
  22666. return MidiMessage (0xff, 0x2f, 0, 0.0);
  22667. }
  22668. bool MidiMessage::isSongPositionPointer() const throw()
  22669. {
  22670. return *data == 0xf2;
  22671. }
  22672. int MidiMessage::getSongPositionPointerMidiBeat() const throw()
  22673. {
  22674. return data[1] | (data[2] << 7);
  22675. }
  22676. const MidiMessage MidiMessage::songPositionPointer (const int positionInMidiBeats) throw()
  22677. {
  22678. return MidiMessage (0xf2,
  22679. positionInMidiBeats & 127,
  22680. (positionInMidiBeats >> 7) & 127);
  22681. }
  22682. bool MidiMessage::isMidiStart() const throw()
  22683. {
  22684. return *data == 0xfa;
  22685. }
  22686. const MidiMessage MidiMessage::midiStart() throw()
  22687. {
  22688. return MidiMessage (0xfa);
  22689. }
  22690. bool MidiMessage::isMidiContinue() const throw()
  22691. {
  22692. return *data == 0xfb;
  22693. }
  22694. const MidiMessage MidiMessage::midiContinue() throw()
  22695. {
  22696. return MidiMessage (0xfb);
  22697. }
  22698. bool MidiMessage::isMidiStop() const throw()
  22699. {
  22700. return *data == 0xfc;
  22701. }
  22702. const MidiMessage MidiMessage::midiStop() throw()
  22703. {
  22704. return MidiMessage (0xfc);
  22705. }
  22706. bool MidiMessage::isMidiClock() const throw()
  22707. {
  22708. return *data == 0xf8;
  22709. }
  22710. const MidiMessage MidiMessage::midiClock() throw()
  22711. {
  22712. return MidiMessage (0xf8);
  22713. }
  22714. bool MidiMessage::isQuarterFrame() const throw()
  22715. {
  22716. return *data == 0xf1;
  22717. }
  22718. int MidiMessage::getQuarterFrameSequenceNumber() const throw()
  22719. {
  22720. return ((int) data[1]) >> 4;
  22721. }
  22722. int MidiMessage::getQuarterFrameValue() const throw()
  22723. {
  22724. return ((int) data[1]) & 0x0f;
  22725. }
  22726. const MidiMessage MidiMessage::quarterFrame (const int sequenceNumber,
  22727. const int value) throw()
  22728. {
  22729. return MidiMessage (0xf1, (sequenceNumber << 4) | value);
  22730. }
  22731. bool MidiMessage::isFullFrame() const throw()
  22732. {
  22733. return data[0] == 0xf0
  22734. && data[1] == 0x7f
  22735. && size >= 10
  22736. && data[3] == 0x01
  22737. && data[4] == 0x01;
  22738. }
  22739. void MidiMessage::getFullFrameParameters (int& hours,
  22740. int& minutes,
  22741. int& seconds,
  22742. int& frames,
  22743. MidiMessage::SmpteTimecodeType& timecodeType) const throw()
  22744. {
  22745. jassert (isFullFrame());
  22746. timecodeType = (SmpteTimecodeType) (data[5] >> 5);
  22747. hours = data[5] & 0x1f;
  22748. minutes = data[6];
  22749. seconds = data[7];
  22750. frames = data[8];
  22751. }
  22752. const MidiMessage MidiMessage::fullFrame (const int hours,
  22753. const int minutes,
  22754. const int seconds,
  22755. const int frames,
  22756. MidiMessage::SmpteTimecodeType timecodeType)
  22757. {
  22758. uint8 d[10];
  22759. d[0] = 0xf0;
  22760. d[1] = 0x7f;
  22761. d[2] = 0x7f;
  22762. d[3] = 0x01;
  22763. d[4] = 0x01;
  22764. d[5] = (uint8) ((hours & 0x01f) | (timecodeType << 5));
  22765. d[6] = (uint8) minutes;
  22766. d[7] = (uint8) seconds;
  22767. d[8] = (uint8) frames;
  22768. d[9] = 0xf7;
  22769. return MidiMessage (d, 10, 0.0);
  22770. }
  22771. bool MidiMessage::isMidiMachineControlMessage() const throw()
  22772. {
  22773. return data[0] == 0xf0
  22774. && data[1] == 0x7f
  22775. && data[3] == 0x06
  22776. && size > 5;
  22777. }
  22778. MidiMessage::MidiMachineControlCommand MidiMessage::getMidiMachineControlCommand() const throw()
  22779. {
  22780. jassert (isMidiMachineControlMessage());
  22781. return (MidiMachineControlCommand) data[4];
  22782. }
  22783. const MidiMessage MidiMessage::midiMachineControlCommand (MidiMessage::MidiMachineControlCommand command)
  22784. {
  22785. uint8 d[6];
  22786. d[0] = 0xf0;
  22787. d[1] = 0x7f;
  22788. d[2] = 0x00;
  22789. d[3] = 0x06;
  22790. d[4] = (uint8) command;
  22791. d[5] = 0xf7;
  22792. return MidiMessage (d, 6, 0.0);
  22793. }
  22794. bool MidiMessage::isMidiMachineControlGoto (int& hours,
  22795. int& minutes,
  22796. int& seconds,
  22797. int& frames) const throw()
  22798. {
  22799. if (size >= 12
  22800. && data[0] == 0xf0
  22801. && data[1] == 0x7f
  22802. && data[3] == 0x06
  22803. && data[4] == 0x44
  22804. && data[5] == 0x06
  22805. && data[6] == 0x01)
  22806. {
  22807. hours = data[7] % 24; // (that some machines send out hours > 24)
  22808. minutes = data[8];
  22809. seconds = data[9];
  22810. frames = data[10];
  22811. return true;
  22812. }
  22813. return false;
  22814. }
  22815. const MidiMessage MidiMessage::midiMachineControlGoto (int hours,
  22816. int minutes,
  22817. int seconds,
  22818. int frames)
  22819. {
  22820. uint8 d[12];
  22821. d[0] = 0xf0;
  22822. d[1] = 0x7f;
  22823. d[2] = 0x00;
  22824. d[3] = 0x06;
  22825. d[4] = 0x44;
  22826. d[5] = 0x06;
  22827. d[6] = 0x01;
  22828. d[7] = (uint8) hours;
  22829. d[8] = (uint8) minutes;
  22830. d[9] = (uint8) seconds;
  22831. d[10] = (uint8) frames;
  22832. d[11] = 0xf7;
  22833. return MidiMessage (d, 12, 0.0);
  22834. }
  22835. const String MidiMessage::getMidiNoteName (int note,
  22836. bool useSharps,
  22837. bool includeOctaveNumber,
  22838. int octaveNumForMiddleC) throw()
  22839. {
  22840. static const char* const sharpNoteNames[] = { "C", "C#", "D", "D#", "E",
  22841. "F", "F#", "G", "G#", "A",
  22842. "A#", "B" };
  22843. static const char* const flatNoteNames[] = { "C", "Db", "D", "Eb", "E",
  22844. "F", "Gb", "G", "Ab", "A",
  22845. "Bb", "B" };
  22846. if (((unsigned int) note) < 128)
  22847. {
  22848. const String s ((useSharps) ? sharpNoteNames [note % 12]
  22849. : flatNoteNames [note % 12]);
  22850. if (includeOctaveNumber)
  22851. return s + String (note / 12 + (octaveNumForMiddleC - 5));
  22852. else
  22853. return s;
  22854. }
  22855. return String::empty;
  22856. }
  22857. const double MidiMessage::getMidiNoteInHertz (int noteNumber) throw()
  22858. {
  22859. noteNumber -= 12 * 6 + 9; // now 0 = A440
  22860. return 440.0 * pow (2.0, noteNumber / 12.0);
  22861. }
  22862. const String MidiMessage::getGMInstrumentName (int n) throw()
  22863. {
  22864. const char *names[] =
  22865. {
  22866. "Acoustic Grand Piano", "Bright Acoustic Piano", "Electric Grand Piano", "Honky-tonk Piano",
  22867. "Electric Piano 1", "Electric Piano 2", "Harpsichord", "Clavinet", "Celesta", "Glockenspiel",
  22868. "Music Box", "Vibraphone", "Marimba", "Xylophone", "Tubular Bells", "Dulcimer", "Drawbar Organ",
  22869. "Percussive Organ", "Rock Organ", "Church Organ", "Reed Organ", "Accordion", "Harmonica",
  22870. "Tango Accordion", "Acoustic Guitar (nylon)", "Acoustic Guitar (steel)", "Electric Guitar (jazz)",
  22871. "Electric Guitar (clean)", "Electric Guitar (mute)", "Overdriven Guitar", "Distortion Guitar",
  22872. "Guitar Harmonics", "Acoustic Bass", "Electric Bass (finger)", "Electric Bass (pick)",
  22873. "Fretless Bass", "Slap Bass 1", "Slap Bass 2", "Synth Bass 1", "Synth Bass 2", "Violin",
  22874. "Viola", "Cello", "Contrabass", "Tremolo Strings", "Pizzicato Strings", "Orchestral Harp",
  22875. "Timpani", "String Ensemble 1", "String Ensemble 2", "SynthStrings 1", "SynthStrings 2",
  22876. "Choir Aahs", "Voice Oohs", "Synth Voice", "Orchestra Hit", "Trumpet", "Trombone", "Tuba",
  22877. "Muted Trumpet", "French Horn", "Brass Section", "SynthBrass 1", "SynthBrass 2", "Soprano Sax",
  22878. "Alto Sax", "Tenor Sax", "Baritone Sax", "Oboe", "English Horn", "Bassoon", "Clarinet",
  22879. "Piccolo", "Flute", "Recorder", "Pan Flute", "Blown Bottle", "Shakuhachi", "Whistle",
  22880. "Ocarina", "Lead 1 (square)", "Lead 2 (sawtooth)", "Lead 3 (calliope)", "Lead 4 (chiff)",
  22881. "Lead 5 (charang)", "Lead 6 (voice)", "Lead 7 (fifths)", "Lead 8 (bass+lead)", "Pad 1 (new age)",
  22882. "Pad 2 (warm)", "Pad 3 (polysynth)", "Pad 4 (choir)", "Pad 5 (bowed)", "Pad 6 (metallic)",
  22883. "Pad 7 (halo)", "Pad 8 (sweep)", "FX 1 (rain)", "FX 2 (soundtrack)", "FX 3 (crystal)",
  22884. "FX 4 (atmosphere)", "FX 5 (brightness)", "FX 6 (goblins)", "FX 7 (echoes)", "FX 8 (sci-fi)",
  22885. "Sitar", "Banjo", "Shamisen", "Koto", "Kalimba", "Bag pipe", "Fiddle", "Shanai", "Tinkle Bell",
  22886. "Agogo", "Steel Drums", "Woodblock", "Taiko Drum", "Melodic Tom", "Synth Drum", "Reverse Cymbal",
  22887. "Guitar Fret Noise", "Breath Noise", "Seashore", "Bird Tweet", "Telephone Ring", "Helicopter",
  22888. "Applause", "Gunshot"
  22889. };
  22890. return (((unsigned int) n) < 128) ? names[n]
  22891. : (const char*)0;
  22892. }
  22893. const String MidiMessage::getGMInstrumentBankName (int n) throw()
  22894. {
  22895. const char* names[] =
  22896. {
  22897. "Piano", "Chromatic Percussion", "Organ", "Guitar",
  22898. "Bass", "Strings", "Ensemble", "Brass",
  22899. "Reed", "Pipe", "Synth Lead", "Synth Pad",
  22900. "Synth Effects", "Ethnic", "Percussive", "Sound Effects"
  22901. };
  22902. return (((unsigned int) n) <= 15) ? names[n]
  22903. : (const char*)0;
  22904. }
  22905. const String MidiMessage::getRhythmInstrumentName (int n) throw()
  22906. {
  22907. const char* names[] =
  22908. {
  22909. "Acoustic Bass Drum", "Bass Drum 1", "Side Stick", "Acoustic Snare",
  22910. "Hand Clap", "Electric Snare", "Low Floor Tom", "Closed Hi-Hat", "High Floor Tom",
  22911. "Pedal Hi-Hat", "Low Tom", "Open Hi-Hat", "Low-Mid Tom", "Hi-Mid Tom", "Crash Cymbal 1",
  22912. "High Tom", "Ride Cymbal 1", "Chinese Cymbal", "Ride Bell", "Tambourine", "Splash Cymbal",
  22913. "Cowbell", "Crash Cymbal 2", "Vibraslap", "Ride Cymbal 2", "Hi Bongo", "Low Bongo",
  22914. "Mute Hi Conga", "Open Hi Conga", "Low Conga", "High Timbale", "Low Timbale", "High Agogo",
  22915. "Low Agogo", "Cabasa", "Maracas", "Short Whistle", "Long Whistle", "Short Guiro",
  22916. "Long Guiro", "Claves", "Hi Wood Block", "Low Wood Block", "Mute Cuica", "Open Cuica",
  22917. "Mute Triangle", "Open Triangle"
  22918. };
  22919. return (n >= 35 && n <= 81) ? names [n - 35]
  22920. : (const char*)0;
  22921. }
  22922. const String MidiMessage::getControllerName (int n) throw()
  22923. {
  22924. const char* names[] =
  22925. {
  22926. "Bank Select", "Modulation Wheel (coarse)", "Breath controller (coarse)",
  22927. 0, "Foot Pedal (coarse)", "Portamento Time (coarse)",
  22928. "Data Entry (coarse)", "Volume (coarse)", "Balance (coarse)",
  22929. 0, "Pan position (coarse)", "Expression (coarse)", "Effect Control 1 (coarse)",
  22930. "Effect Control 2 (coarse)", 0, 0, "General Purpose Slider 1", "General Purpose Slider 2",
  22931. "General Purpose Slider 3", "General Purpose Slider 4", 0, 0, 0, 0, 0, 0, 0, 0,
  22932. 0, 0, 0, 0, "Bank Select (fine)", "Modulation Wheel (fine)", "Breath controller (fine)",
  22933. 0, "Foot Pedal (fine)", "Portamento Time (fine)", "Data Entry (fine)", "Volume (fine)",
  22934. "Balance (fine)", 0, "Pan position (fine)", "Expression (fine)", "Effect Control 1 (fine)",
  22935. "Effect Control 2 (fine)", 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  22936. "Hold Pedal (on/off)", "Portamento (on/off)", "Sustenuto Pedal (on/off)", "Soft Pedal (on/off)",
  22937. "Legato Pedal (on/off)", "Hold 2 Pedal (on/off)", "Sound Variation", "Sound Timbre",
  22938. "Sound Release Time", "Sound Attack Time", "Sound Brightness", "Sound Control 6",
  22939. "Sound Control 7", "Sound Control 8", "Sound Control 9", "Sound Control 10",
  22940. "General Purpose Button 1 (on/off)", "General Purpose Button 2 (on/off)",
  22941. "General Purpose Button 3 (on/off)", "General Purpose Button 4 (on/off)",
  22942. 0, 0, 0, 0, 0, 0, 0, "Reverb Level", "Tremolo Level", "Chorus Level", "Celeste Level",
  22943. "Phaser Level", "Data Button increment", "Data Button decrement", "Non-registered Parameter (fine)",
  22944. "Non-registered Parameter (coarse)", "Registered Parameter (fine)", "Registered Parameter (coarse)",
  22945. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "All Sound Off", "All Controllers Off",
  22946. "Local Keyboard (on/off)", "All Notes Off", "Omni Mode Off", "Omni Mode On", "Mono Operation",
  22947. "Poly Operation"
  22948. };
  22949. return (((unsigned int) n) < 128) ? names[n]
  22950. : (const char*)0;
  22951. }
  22952. END_JUCE_NAMESPACE
  22953. /********* End of inlined file: juce_MidiMessage.cpp *********/
  22954. /********* Start of inlined file: juce_MidiMessageCollector.cpp *********/
  22955. BEGIN_JUCE_NAMESPACE
  22956. MidiMessageCollector::MidiMessageCollector()
  22957. : lastCallbackTime (0),
  22958. sampleRate (44100.0001)
  22959. {
  22960. }
  22961. MidiMessageCollector::~MidiMessageCollector()
  22962. {
  22963. }
  22964. void MidiMessageCollector::reset (const double sampleRate_)
  22965. {
  22966. jassert (sampleRate_ > 0);
  22967. const ScopedLock sl (midiCallbackLock);
  22968. sampleRate = sampleRate_;
  22969. incomingMessages.clear();
  22970. lastCallbackTime = Time::getMillisecondCounterHiRes();
  22971. }
  22972. void MidiMessageCollector::addMessageToQueue (const MidiMessage& message)
  22973. {
  22974. // you need to call reset() to set the correct sample rate before using this object
  22975. jassert (sampleRate != 44100.0001);
  22976. // the messages that come in here need to be time-stamped correctly - see MidiInput
  22977. // for details of what the number should be.
  22978. jassert (message.getTimeStamp() != 0);
  22979. const ScopedLock sl (midiCallbackLock);
  22980. const int sampleNumber
  22981. = (int) ((message.getTimeStamp() - 0.001 * lastCallbackTime) * sampleRate);
  22982. incomingMessages.addEvent (message, sampleNumber);
  22983. // if the messages don't get used for over a second, we'd better
  22984. // get rid of any old ones to avoid the queue getting too big
  22985. if (sampleNumber > sampleRate)
  22986. incomingMessages.clear (0, sampleNumber - (int) sampleRate);
  22987. }
  22988. void MidiMessageCollector::removeNextBlockOfMessages (MidiBuffer& destBuffer,
  22989. const int numSamples)
  22990. {
  22991. // you need to call reset() to set the correct sample rate before using this object
  22992. jassert (sampleRate != 44100.0001);
  22993. const double timeNow = Time::getMillisecondCounterHiRes();
  22994. const double msElapsed = timeNow - lastCallbackTime;
  22995. const ScopedLock sl (midiCallbackLock);
  22996. lastCallbackTime = timeNow;
  22997. if (! incomingMessages.isEmpty())
  22998. {
  22999. int numSourceSamples = jmax (1, roundToInt (msElapsed * 0.001 * sampleRate));
  23000. int startSample = 0;
  23001. int scale = 1 << 16;
  23002. const uint8* midiData;
  23003. int numBytes, samplePosition;
  23004. MidiBuffer::Iterator iter (incomingMessages);
  23005. if (numSourceSamples > numSamples)
  23006. {
  23007. // if our list of events is longer than the buffer we're being
  23008. // asked for, scale them down to squeeze them all in..
  23009. const int maxBlockLengthToUse = numSamples << 5;
  23010. if (numSourceSamples > maxBlockLengthToUse)
  23011. {
  23012. startSample = numSourceSamples - maxBlockLengthToUse;
  23013. numSourceSamples = maxBlockLengthToUse;
  23014. iter.setNextSamplePosition (startSample);
  23015. }
  23016. scale = (numSamples << 10) / numSourceSamples;
  23017. while (iter.getNextEvent (midiData, numBytes, samplePosition))
  23018. {
  23019. samplePosition = ((samplePosition - startSample) * scale) >> 10;
  23020. destBuffer.addEvent (midiData, numBytes,
  23021. jlimit (0, numSamples - 1, samplePosition));
  23022. }
  23023. }
  23024. else
  23025. {
  23026. // if our event list is shorter than the number we need, put them
  23027. // towards the end of the buffer
  23028. startSample = numSamples - numSourceSamples;
  23029. while (iter.getNextEvent (midiData, numBytes, samplePosition))
  23030. {
  23031. destBuffer.addEvent (midiData, numBytes,
  23032. jlimit (0, numSamples - 1, samplePosition + startSample));
  23033. }
  23034. }
  23035. incomingMessages.clear();
  23036. }
  23037. }
  23038. void MidiMessageCollector::handleNoteOn (MidiKeyboardState*, int midiChannel, int midiNoteNumber, float velocity)
  23039. {
  23040. MidiMessage m (MidiMessage::noteOn (midiChannel, midiNoteNumber, velocity));
  23041. m.setTimeStamp (Time::getMillisecondCounterHiRes() * 0.001);
  23042. addMessageToQueue (m);
  23043. }
  23044. void MidiMessageCollector::handleNoteOff (MidiKeyboardState*, int midiChannel, int midiNoteNumber)
  23045. {
  23046. MidiMessage m (MidiMessage::noteOff (midiChannel, midiNoteNumber));
  23047. m.setTimeStamp (Time::getMillisecondCounterHiRes() * 0.001);
  23048. addMessageToQueue (m);
  23049. }
  23050. void MidiMessageCollector::handleIncomingMidiMessage (MidiInput*, const MidiMessage& message)
  23051. {
  23052. addMessageToQueue (message);
  23053. }
  23054. END_JUCE_NAMESPACE
  23055. /********* End of inlined file: juce_MidiMessageCollector.cpp *********/
  23056. /********* Start of inlined file: juce_MidiMessageSequence.cpp *********/
  23057. BEGIN_JUCE_NAMESPACE
  23058. MidiMessageSequence::MidiMessageSequence()
  23059. {
  23060. }
  23061. MidiMessageSequence::MidiMessageSequence (const MidiMessageSequence& other)
  23062. {
  23063. list.ensureStorageAllocated (other.list.size());
  23064. for (int i = 0; i < other.list.size(); ++i)
  23065. list.add (new MidiEventHolder (other.list.getUnchecked(i)->message));
  23066. }
  23067. MidiMessageSequence& MidiMessageSequence::operator= (const MidiMessageSequence& other)
  23068. {
  23069. MidiMessageSequence otherCopy (other);
  23070. swapWith (otherCopy);
  23071. return *this;
  23072. }
  23073. void MidiMessageSequence::swapWith (MidiMessageSequence& other) throw()
  23074. {
  23075. list.swapWithArray (other.list);
  23076. }
  23077. MidiMessageSequence::~MidiMessageSequence()
  23078. {
  23079. }
  23080. void MidiMessageSequence::clear()
  23081. {
  23082. list.clear();
  23083. }
  23084. int MidiMessageSequence::getNumEvents() const
  23085. {
  23086. return list.size();
  23087. }
  23088. MidiMessageSequence::MidiEventHolder* MidiMessageSequence::getEventPointer (const int index) const
  23089. {
  23090. return list [index];
  23091. }
  23092. double MidiMessageSequence::getTimeOfMatchingKeyUp (const int index) const
  23093. {
  23094. const MidiEventHolder* const meh = list [index];
  23095. if (meh != 0 && meh->noteOffObject != 0)
  23096. return meh->noteOffObject->message.getTimeStamp();
  23097. else
  23098. return 0.0;
  23099. }
  23100. int MidiMessageSequence::getIndexOfMatchingKeyUp (const int index) const
  23101. {
  23102. const MidiEventHolder* const meh = list [index];
  23103. return (meh != 0) ? list.indexOf (meh->noteOffObject) : -1;
  23104. }
  23105. int MidiMessageSequence::getIndexOf (MidiEventHolder* const event) const
  23106. {
  23107. return list.indexOf (event);
  23108. }
  23109. int MidiMessageSequence::getNextIndexAtTime (const double timeStamp) const
  23110. {
  23111. const int numEvents = list.size();
  23112. int i;
  23113. for (i = 0; i < numEvents; ++i)
  23114. if (list.getUnchecked(i)->message.getTimeStamp() >= timeStamp)
  23115. break;
  23116. return i;
  23117. }
  23118. double MidiMessageSequence::getStartTime() const
  23119. {
  23120. if (list.size() > 0)
  23121. return list.getUnchecked(0)->message.getTimeStamp();
  23122. else
  23123. return 0;
  23124. }
  23125. double MidiMessageSequence::getEndTime() const
  23126. {
  23127. if (list.size() > 0)
  23128. return list.getLast()->message.getTimeStamp();
  23129. else
  23130. return 0;
  23131. }
  23132. double MidiMessageSequence::getEventTime (const int index) const
  23133. {
  23134. if (((unsigned int) index) < (unsigned int) list.size())
  23135. return list.getUnchecked (index)->message.getTimeStamp();
  23136. return 0.0;
  23137. }
  23138. void MidiMessageSequence::addEvent (const MidiMessage& newMessage,
  23139. double timeAdjustment)
  23140. {
  23141. MidiEventHolder* const newOne = new MidiEventHolder (newMessage);
  23142. timeAdjustment += newMessage.getTimeStamp();
  23143. newOne->message.setTimeStamp (timeAdjustment);
  23144. int i;
  23145. for (i = list.size(); --i >= 0;)
  23146. if (list.getUnchecked(i)->message.getTimeStamp() <= timeAdjustment)
  23147. break;
  23148. list.insert (i + 1, newOne);
  23149. }
  23150. void MidiMessageSequence::deleteEvent (const int index,
  23151. const bool deleteMatchingNoteUp)
  23152. {
  23153. if (((unsigned int) index) < (unsigned int) list.size())
  23154. {
  23155. if (deleteMatchingNoteUp)
  23156. deleteEvent (getIndexOfMatchingKeyUp (index), false);
  23157. list.remove (index);
  23158. }
  23159. }
  23160. void MidiMessageSequence::addSequence (const MidiMessageSequence& other,
  23161. double timeAdjustment,
  23162. double firstAllowableTime,
  23163. double endOfAllowableDestTimes)
  23164. {
  23165. firstAllowableTime -= timeAdjustment;
  23166. endOfAllowableDestTimes -= timeAdjustment;
  23167. for (int i = 0; i < other.list.size(); ++i)
  23168. {
  23169. const MidiMessage& m = other.list.getUnchecked(i)->message;
  23170. const double t = m.getTimeStamp();
  23171. if (t >= firstAllowableTime && t < endOfAllowableDestTimes)
  23172. {
  23173. MidiEventHolder* const newOne = new MidiEventHolder (m);
  23174. newOne->message.setTimeStamp (timeAdjustment + t);
  23175. list.add (newOne);
  23176. }
  23177. }
  23178. sort();
  23179. }
  23180. int MidiMessageSequence::compareElements (const MidiMessageSequence::MidiEventHolder* const first,
  23181. const MidiMessageSequence::MidiEventHolder* const second) throw()
  23182. {
  23183. const double diff = first->message.getTimeStamp()
  23184. - second->message.getTimeStamp();
  23185. return (diff > 0) - (diff < 0);
  23186. }
  23187. void MidiMessageSequence::sort()
  23188. {
  23189. list.sort (*this, true);
  23190. }
  23191. void MidiMessageSequence::updateMatchedPairs()
  23192. {
  23193. for (int i = 0; i < list.size(); ++i)
  23194. {
  23195. const MidiMessage& m1 = list.getUnchecked(i)->message;
  23196. if (m1.isNoteOn())
  23197. {
  23198. list.getUnchecked(i)->noteOffObject = 0;
  23199. const int note = m1.getNoteNumber();
  23200. const int chan = m1.getChannel();
  23201. const int len = list.size();
  23202. for (int j = i + 1; j < len; ++j)
  23203. {
  23204. const MidiMessage& m = list.getUnchecked(j)->message;
  23205. if (m.getNoteNumber() == note && m.getChannel() == chan)
  23206. {
  23207. if (m.isNoteOff())
  23208. {
  23209. list.getUnchecked(i)->noteOffObject = list[j];
  23210. break;
  23211. }
  23212. else if (m.isNoteOn())
  23213. {
  23214. list.insert (j, new MidiEventHolder (MidiMessage::noteOff (chan, note)));
  23215. list.getUnchecked(j)->message.setTimeStamp (m.getTimeStamp());
  23216. list.getUnchecked(i)->noteOffObject = list[j];
  23217. break;
  23218. }
  23219. }
  23220. }
  23221. }
  23222. }
  23223. }
  23224. void MidiMessageSequence::addTimeToMessages (const double delta)
  23225. {
  23226. for (int i = list.size(); --i >= 0;)
  23227. list.getUnchecked (i)->message.setTimeStamp (list.getUnchecked (i)->message.getTimeStamp()
  23228. + delta);
  23229. }
  23230. void MidiMessageSequence::extractMidiChannelMessages (const int channelNumberToExtract,
  23231. MidiMessageSequence& destSequence,
  23232. const bool alsoIncludeMetaEvents) const
  23233. {
  23234. for (int i = 0; i < list.size(); ++i)
  23235. {
  23236. const MidiMessage& mm = list.getUnchecked(i)->message;
  23237. if (mm.isForChannel (channelNumberToExtract)
  23238. || (alsoIncludeMetaEvents && mm.isMetaEvent()))
  23239. {
  23240. destSequence.addEvent (mm);
  23241. }
  23242. }
  23243. }
  23244. void MidiMessageSequence::extractSysExMessages (MidiMessageSequence& destSequence) const
  23245. {
  23246. for (int i = 0; i < list.size(); ++i)
  23247. {
  23248. const MidiMessage& mm = list.getUnchecked(i)->message;
  23249. if (mm.isSysEx())
  23250. destSequence.addEvent (mm);
  23251. }
  23252. }
  23253. void MidiMessageSequence::deleteMidiChannelMessages (const int channelNumberToRemove)
  23254. {
  23255. for (int i = list.size(); --i >= 0;)
  23256. if (list.getUnchecked(i)->message.isForChannel (channelNumberToRemove))
  23257. list.remove(i);
  23258. }
  23259. void MidiMessageSequence::deleteSysExMessages()
  23260. {
  23261. for (int i = list.size(); --i >= 0;)
  23262. if (list.getUnchecked(i)->message.isSysEx())
  23263. list.remove(i);
  23264. }
  23265. void MidiMessageSequence::createControllerUpdatesForTime (const int channelNumber,
  23266. const double time,
  23267. OwnedArray<MidiMessage>& dest)
  23268. {
  23269. bool doneProg = false;
  23270. bool donePitchWheel = false;
  23271. Array <int> doneControllers;
  23272. doneControllers.ensureStorageAllocated (32);
  23273. for (int i = list.size(); --i >= 0;)
  23274. {
  23275. const MidiMessage& mm = list.getUnchecked(i)->message;
  23276. if (mm.isForChannel (channelNumber)
  23277. && mm.getTimeStamp() <= time)
  23278. {
  23279. if (mm.isProgramChange())
  23280. {
  23281. if (! doneProg)
  23282. {
  23283. dest.add (new MidiMessage (mm, 0.0));
  23284. doneProg = true;
  23285. }
  23286. }
  23287. else if (mm.isController())
  23288. {
  23289. if (! doneControllers.contains (mm.getControllerNumber()))
  23290. {
  23291. dest.add (new MidiMessage (mm, 0.0));
  23292. doneControllers.add (mm.getControllerNumber());
  23293. }
  23294. }
  23295. else if (mm.isPitchWheel())
  23296. {
  23297. if (! donePitchWheel)
  23298. {
  23299. dest.add (new MidiMessage (mm, 0.0));
  23300. donePitchWheel = true;
  23301. }
  23302. }
  23303. }
  23304. }
  23305. }
  23306. MidiMessageSequence::MidiEventHolder::MidiEventHolder (const MidiMessage& message_)
  23307. : message (message_),
  23308. noteOffObject (0)
  23309. {
  23310. }
  23311. MidiMessageSequence::MidiEventHolder::~MidiEventHolder()
  23312. {
  23313. }
  23314. END_JUCE_NAMESPACE
  23315. /********* End of inlined file: juce_MidiMessageSequence.cpp *********/
  23316. /********* Start of inlined file: juce_AudioPluginFormat.cpp *********/
  23317. BEGIN_JUCE_NAMESPACE
  23318. AudioPluginFormat::AudioPluginFormat() throw()
  23319. {
  23320. }
  23321. AudioPluginFormat::~AudioPluginFormat()
  23322. {
  23323. }
  23324. END_JUCE_NAMESPACE
  23325. /********* End of inlined file: juce_AudioPluginFormat.cpp *********/
  23326. /********* Start of inlined file: juce_AudioPluginFormatManager.cpp *********/
  23327. BEGIN_JUCE_NAMESPACE
  23328. AudioPluginFormatManager::AudioPluginFormatManager() throw()
  23329. {
  23330. }
  23331. AudioPluginFormatManager::~AudioPluginFormatManager() throw()
  23332. {
  23333. clearSingletonInstance();
  23334. }
  23335. juce_ImplementSingleton_SingleThreaded (AudioPluginFormatManager);
  23336. void AudioPluginFormatManager::addDefaultFormats()
  23337. {
  23338. #ifdef JUCE_DEBUG
  23339. // you should only call this method once!
  23340. for (int i = formats.size(); --i >= 0;)
  23341. {
  23342. #if JUCE_PLUGINHOST_VST
  23343. jassert (dynamic_cast <VSTPluginFormat*> (formats[i]) == 0);
  23344. #endif
  23345. #if JUCE_PLUGINHOST_AU && JUCE_MAC
  23346. jassert (dynamic_cast <AudioUnitPluginFormat*> (formats[i]) == 0);
  23347. #endif
  23348. #if JUCE_PLUGINHOST_DX && JUCE_WIN32
  23349. jassert (dynamic_cast <DirectXPluginFormat*> (formats[i]) == 0);
  23350. #endif
  23351. #if JUCE_PLUGINHOST_LADSPA && JUCE_LINUX
  23352. jassert (dynamic_cast <LADSPAPluginFormat*> (formats[i]) == 0);
  23353. #endif
  23354. }
  23355. #endif
  23356. #if JUCE_PLUGINHOST_AU && JUCE_MAC
  23357. formats.add (new AudioUnitPluginFormat());
  23358. #endif
  23359. #if JUCE_PLUGINHOST_VST
  23360. formats.add (new VSTPluginFormat());
  23361. #endif
  23362. #if JUCE_PLUGINHOST_DX && JUCE_WIN32
  23363. formats.add (new DirectXPluginFormat());
  23364. #endif
  23365. #if JUCE_PLUGINHOST_LADSPA && JUCE_LINUX
  23366. formats.add (new LADSPAPluginFormat());
  23367. #endif
  23368. }
  23369. int AudioPluginFormatManager::getNumFormats() throw()
  23370. {
  23371. return formats.size();
  23372. }
  23373. AudioPluginFormat* AudioPluginFormatManager::getFormat (const int index) throw()
  23374. {
  23375. return formats [index];
  23376. }
  23377. void AudioPluginFormatManager::addFormat (AudioPluginFormat* const format) throw()
  23378. {
  23379. formats.add (format);
  23380. }
  23381. AudioPluginInstance* AudioPluginFormatManager::createPluginInstance (const PluginDescription& description,
  23382. String& errorMessage) const
  23383. {
  23384. AudioPluginInstance* result = 0;
  23385. for (int i = 0; i < formats.size(); ++i)
  23386. {
  23387. result = formats.getUnchecked(i)->createInstanceFromDescription (description);
  23388. if (result != 0)
  23389. break;
  23390. }
  23391. if (result == 0)
  23392. {
  23393. if (! doesPluginStillExist (description))
  23394. errorMessage = TRANS ("This plug-in file no longer exists");
  23395. else
  23396. errorMessage = TRANS ("This plug-in failed to load correctly");
  23397. }
  23398. return result;
  23399. }
  23400. bool AudioPluginFormatManager::doesPluginStillExist (const PluginDescription& description) const
  23401. {
  23402. for (int i = 0; i < formats.size(); ++i)
  23403. if (formats.getUnchecked(i)->getName() == description.pluginFormatName)
  23404. return formats.getUnchecked(i)->doesPluginStillExist (description);
  23405. return false;
  23406. }
  23407. END_JUCE_NAMESPACE
  23408. /********* End of inlined file: juce_AudioPluginFormatManager.cpp *********/
  23409. /********* Start of inlined file: juce_AudioPluginInstance.cpp *********/
  23410. #define JUCE_PLUGIN_HOST 1
  23411. BEGIN_JUCE_NAMESPACE
  23412. AudioPluginInstance::AudioPluginInstance()
  23413. {
  23414. }
  23415. AudioPluginInstance::~AudioPluginInstance()
  23416. {
  23417. }
  23418. END_JUCE_NAMESPACE
  23419. /********* End of inlined file: juce_AudioPluginInstance.cpp *********/
  23420. /********* Start of inlined file: juce_KnownPluginList.cpp *********/
  23421. BEGIN_JUCE_NAMESPACE
  23422. KnownPluginList::KnownPluginList()
  23423. {
  23424. }
  23425. KnownPluginList::~KnownPluginList()
  23426. {
  23427. }
  23428. void KnownPluginList::clear()
  23429. {
  23430. if (types.size() > 0)
  23431. {
  23432. types.clear();
  23433. sendChangeMessage (this);
  23434. }
  23435. }
  23436. PluginDescription* KnownPluginList::getTypeForFile (const String& fileOrIdentifier) const throw()
  23437. {
  23438. for (int i = 0; i < types.size(); ++i)
  23439. if (types.getUnchecked(i)->fileOrIdentifier == fileOrIdentifier)
  23440. return types.getUnchecked(i);
  23441. return 0;
  23442. }
  23443. PluginDescription* KnownPluginList::getTypeForIdentifierString (const String& identifierString) const throw()
  23444. {
  23445. for (int i = 0; i < types.size(); ++i)
  23446. if (types.getUnchecked(i)->createIdentifierString() == identifierString)
  23447. return types.getUnchecked(i);
  23448. return 0;
  23449. }
  23450. bool KnownPluginList::addType (const PluginDescription& type)
  23451. {
  23452. for (int i = types.size(); --i >= 0;)
  23453. {
  23454. if (types.getUnchecked(i)->isDuplicateOf (type))
  23455. {
  23456. // strange - found a duplicate plugin with different info..
  23457. jassert (types.getUnchecked(i)->name == type.name);
  23458. jassert (types.getUnchecked(i)->isInstrument == type.isInstrument);
  23459. *types.getUnchecked(i) = type;
  23460. return false;
  23461. }
  23462. }
  23463. types.add (new PluginDescription (type));
  23464. sendChangeMessage (this);
  23465. return true;
  23466. }
  23467. void KnownPluginList::removeType (const int index) throw()
  23468. {
  23469. types.remove (index);
  23470. sendChangeMessage (this);
  23471. }
  23472. static Time getFileModTime (const String& fileOrIdentifier) throw()
  23473. {
  23474. if (fileOrIdentifier.startsWithChar (T('/'))
  23475. || fileOrIdentifier[1] == T(':'))
  23476. {
  23477. return File (fileOrIdentifier).getLastModificationTime();
  23478. }
  23479. return Time (0);
  23480. }
  23481. static bool timesAreDifferent (const Time& t1, const Time& t2) throw()
  23482. {
  23483. return t1 != t2 || t1 == Time (0);
  23484. }
  23485. bool KnownPluginList::isListingUpToDate (const String& fileOrIdentifier) const throw()
  23486. {
  23487. if (getTypeForFile (fileOrIdentifier) == 0)
  23488. return false;
  23489. for (int i = types.size(); --i >= 0;)
  23490. {
  23491. const PluginDescription* const d = types.getUnchecked(i);
  23492. if (d->fileOrIdentifier == fileOrIdentifier
  23493. && timesAreDifferent (d->lastFileModTime, getFileModTime (fileOrIdentifier)))
  23494. {
  23495. return false;
  23496. }
  23497. }
  23498. return true;
  23499. }
  23500. bool KnownPluginList::scanAndAddFile (const String& fileOrIdentifier,
  23501. const bool dontRescanIfAlreadyInList,
  23502. OwnedArray <PluginDescription>& typesFound,
  23503. AudioPluginFormat& format)
  23504. {
  23505. bool addedOne = false;
  23506. if (dontRescanIfAlreadyInList
  23507. && getTypeForFile (fileOrIdentifier) != 0)
  23508. {
  23509. bool needsRescanning = false;
  23510. for (int i = types.size(); --i >= 0;)
  23511. {
  23512. const PluginDescription* const d = types.getUnchecked(i);
  23513. if (d->fileOrIdentifier == fileOrIdentifier)
  23514. {
  23515. if (timesAreDifferent (d->lastFileModTime, getFileModTime (fileOrIdentifier)))
  23516. needsRescanning = true;
  23517. else
  23518. typesFound.add (new PluginDescription (*d));
  23519. }
  23520. }
  23521. if (! needsRescanning)
  23522. return false;
  23523. }
  23524. OwnedArray <PluginDescription> found;
  23525. format.findAllTypesForFile (found, fileOrIdentifier);
  23526. for (int i = 0; i < found.size(); ++i)
  23527. {
  23528. PluginDescription* const desc = found.getUnchecked(i);
  23529. jassert (desc != 0);
  23530. if (addType (*desc))
  23531. addedOne = true;
  23532. typesFound.add (new PluginDescription (*desc));
  23533. }
  23534. return addedOne;
  23535. }
  23536. void KnownPluginList::scanAndAddDragAndDroppedFiles (const StringArray& files,
  23537. OwnedArray <PluginDescription>& typesFound)
  23538. {
  23539. for (int i = 0; i < files.size(); ++i)
  23540. {
  23541. bool loaded = false;
  23542. for (int j = 0; j < AudioPluginFormatManager::getInstance()->getNumFormats(); ++j)
  23543. {
  23544. AudioPluginFormat* const format = AudioPluginFormatManager::getInstance()->getFormat (j);
  23545. if (scanAndAddFile (files[i], true, typesFound, *format))
  23546. loaded = true;
  23547. }
  23548. if (! loaded)
  23549. {
  23550. const File f (files[i]);
  23551. if (f.isDirectory())
  23552. {
  23553. StringArray s;
  23554. {
  23555. Array<File> subFiles;
  23556. f.findChildFiles (subFiles, File::findFilesAndDirectories, false);
  23557. for (int j = 0; j < subFiles.size(); ++j)
  23558. s.add (subFiles.getReference(j).getFullPathName());
  23559. }
  23560. scanAndAddDragAndDroppedFiles (s, typesFound);
  23561. }
  23562. }
  23563. }
  23564. }
  23565. class PluginSorter
  23566. {
  23567. public:
  23568. KnownPluginList::SortMethod method;
  23569. PluginSorter() throw() {}
  23570. int compareElements (const PluginDescription* const first,
  23571. const PluginDescription* const second) const throw()
  23572. {
  23573. int diff = 0;
  23574. if (method == KnownPluginList::sortByCategory)
  23575. diff = first->category.compareLexicographically (second->category);
  23576. else if (method == KnownPluginList::sortByManufacturer)
  23577. diff = first->manufacturerName.compareLexicographically (second->manufacturerName);
  23578. else if (method == KnownPluginList::sortByFileSystemLocation)
  23579. diff = first->fileOrIdentifier.replaceCharacter (T('\\'), T('/'))
  23580. .upToLastOccurrenceOf (T("/"), false, false)
  23581. .compare (second->fileOrIdentifier.replaceCharacter (T('\\'), T('/'))
  23582. .upToLastOccurrenceOf (T("/"), false, false));
  23583. if (diff == 0)
  23584. diff = first->name.compareLexicographically (second->name);
  23585. return diff;
  23586. }
  23587. };
  23588. void KnownPluginList::sort (const SortMethod method)
  23589. {
  23590. if (method != defaultOrder)
  23591. {
  23592. PluginSorter sorter;
  23593. sorter.method = method;
  23594. types.sort (sorter, true);
  23595. sendChangeMessage (this);
  23596. }
  23597. }
  23598. XmlElement* KnownPluginList::createXml() const
  23599. {
  23600. XmlElement* const e = new XmlElement (T("KNOWNPLUGINS"));
  23601. for (int i = 0; i < types.size(); ++i)
  23602. e->addChildElement (types.getUnchecked(i)->createXml());
  23603. return e;
  23604. }
  23605. void KnownPluginList::recreateFromXml (const XmlElement& xml)
  23606. {
  23607. clear();
  23608. if (xml.hasTagName (T("KNOWNPLUGINS")))
  23609. {
  23610. forEachXmlChildElement (xml, e)
  23611. {
  23612. PluginDescription info;
  23613. if (info.loadFromXml (*e))
  23614. addType (info);
  23615. }
  23616. }
  23617. }
  23618. const int menuIdBase = 0x324503f4;
  23619. // This is used to turn a bunch of paths into a nested menu structure.
  23620. struct PluginFilesystemTree
  23621. {
  23622. private:
  23623. String folder;
  23624. OwnedArray <PluginFilesystemTree> subFolders;
  23625. Array <PluginDescription*> plugins;
  23626. void addPlugin (PluginDescription* const pd, const String& path)
  23627. {
  23628. if (path.isEmpty())
  23629. {
  23630. plugins.add (pd);
  23631. }
  23632. else
  23633. {
  23634. const String firstSubFolder (path.upToFirstOccurrenceOf (T("/"), false, false));
  23635. const String remainingPath (path.fromFirstOccurrenceOf (T("/"), false, false));
  23636. for (int i = subFolders.size(); --i >= 0;)
  23637. {
  23638. if (subFolders.getUnchecked(i)->folder.equalsIgnoreCase (firstSubFolder))
  23639. {
  23640. subFolders.getUnchecked(i)->addPlugin (pd, remainingPath);
  23641. return;
  23642. }
  23643. }
  23644. PluginFilesystemTree* const newFolder = new PluginFilesystemTree();
  23645. newFolder->folder = firstSubFolder;
  23646. subFolders.add (newFolder);
  23647. newFolder->addPlugin (pd, remainingPath);
  23648. }
  23649. }
  23650. // removes any deeply nested folders that don't contain any actual plugins
  23651. void optimise()
  23652. {
  23653. for (int i = subFolders.size(); --i >= 0;)
  23654. {
  23655. PluginFilesystemTree* const sub = subFolders.getUnchecked(i);
  23656. sub->optimise();
  23657. if (sub->plugins.size() == 0)
  23658. {
  23659. for (int j = 0; j < sub->subFolders.size(); ++j)
  23660. subFolders.add (sub->subFolders.getUnchecked(j));
  23661. sub->subFolders.clear (false);
  23662. subFolders.remove (i);
  23663. }
  23664. }
  23665. }
  23666. public:
  23667. void buildTree (const Array <PluginDescription*>& allPlugins)
  23668. {
  23669. for (int i = 0; i < allPlugins.size(); ++i)
  23670. {
  23671. String path (allPlugins.getUnchecked(i)
  23672. ->fileOrIdentifier.replaceCharacter (T('\\'), T('/'))
  23673. .upToLastOccurrenceOf (T("/"), false, false));
  23674. if (path.substring (1, 2) == T(":"))
  23675. path = path.substring (2);
  23676. addPlugin (allPlugins.getUnchecked(i), path);
  23677. }
  23678. optimise();
  23679. }
  23680. void addToMenu (PopupMenu& m, const OwnedArray <PluginDescription>& allPlugins) const
  23681. {
  23682. int i;
  23683. for (i = 0; i < subFolders.size(); ++i)
  23684. {
  23685. const PluginFilesystemTree* const sub = subFolders.getUnchecked(i);
  23686. PopupMenu subMenu;
  23687. sub->addToMenu (subMenu, allPlugins);
  23688. #if JUCE_MAC
  23689. // avoid the special AU formatting nonsense on Mac..
  23690. m.addSubMenu (sub->folder.fromFirstOccurrenceOf (T(":"), false, false), subMenu);
  23691. #else
  23692. m.addSubMenu (sub->folder, subMenu);
  23693. #endif
  23694. }
  23695. for (i = 0; i < plugins.size(); ++i)
  23696. {
  23697. PluginDescription* const plugin = plugins.getUnchecked(i);
  23698. m.addItem (allPlugins.indexOf (plugin) + menuIdBase,
  23699. plugin->name, true, false);
  23700. }
  23701. }
  23702. };
  23703. void KnownPluginList::addToMenu (PopupMenu& menu, const SortMethod sortMethod) const
  23704. {
  23705. Array <PluginDescription*> sorted;
  23706. {
  23707. PluginSorter sorter;
  23708. sorter.method = sortMethod;
  23709. for (int i = 0; i < types.size(); ++i)
  23710. sorted.addSorted (sorter, types.getUnchecked(i));
  23711. }
  23712. if (sortMethod == sortByCategory
  23713. || sortMethod == sortByManufacturer)
  23714. {
  23715. String lastSubMenuName;
  23716. PopupMenu sub;
  23717. for (int i = 0; i < sorted.size(); ++i)
  23718. {
  23719. const PluginDescription* const pd = sorted.getUnchecked(i);
  23720. String thisSubMenuName (sortMethod == sortByCategory ? pd->category
  23721. : pd->manufacturerName);
  23722. if (! thisSubMenuName.containsNonWhitespaceChars())
  23723. thisSubMenuName = T("Other");
  23724. if (thisSubMenuName != lastSubMenuName)
  23725. {
  23726. if (sub.getNumItems() > 0)
  23727. {
  23728. menu.addSubMenu (lastSubMenuName, sub);
  23729. sub.clear();
  23730. }
  23731. lastSubMenuName = thisSubMenuName;
  23732. }
  23733. sub.addItem (types.indexOf (pd) + menuIdBase, pd->name, true, false);
  23734. }
  23735. if (sub.getNumItems() > 0)
  23736. menu.addSubMenu (lastSubMenuName, sub);
  23737. }
  23738. else if (sortMethod == sortByFileSystemLocation)
  23739. {
  23740. PluginFilesystemTree root;
  23741. root.buildTree (sorted);
  23742. root.addToMenu (menu, types);
  23743. }
  23744. else
  23745. {
  23746. for (int i = 0; i < sorted.size(); ++i)
  23747. {
  23748. const PluginDescription* const pd = sorted.getUnchecked(i);
  23749. menu.addItem (types.indexOf (pd) + menuIdBase, pd->name, true, false);
  23750. }
  23751. }
  23752. }
  23753. int KnownPluginList::getIndexChosenByMenu (const int menuResultCode) const
  23754. {
  23755. const int i = menuResultCode - menuIdBase;
  23756. return (((unsigned int) i) < (unsigned int) types.size()) ? i : -1;
  23757. }
  23758. END_JUCE_NAMESPACE
  23759. /********* End of inlined file: juce_KnownPluginList.cpp *********/
  23760. /********* Start of inlined file: juce_PluginDescription.cpp *********/
  23761. BEGIN_JUCE_NAMESPACE
  23762. PluginDescription::PluginDescription() throw()
  23763. : uid (0),
  23764. isInstrument (false),
  23765. numInputChannels (0),
  23766. numOutputChannels (0)
  23767. {
  23768. }
  23769. PluginDescription::~PluginDescription() throw()
  23770. {
  23771. }
  23772. PluginDescription::PluginDescription (const PluginDescription& other) throw()
  23773. : name (other.name),
  23774. pluginFormatName (other.pluginFormatName),
  23775. category (other.category),
  23776. manufacturerName (other.manufacturerName),
  23777. version (other.version),
  23778. fileOrIdentifier (other.fileOrIdentifier),
  23779. lastFileModTime (other.lastFileModTime),
  23780. uid (other.uid),
  23781. isInstrument (other.isInstrument),
  23782. numInputChannels (other.numInputChannels),
  23783. numOutputChannels (other.numOutputChannels)
  23784. {
  23785. }
  23786. const PluginDescription& PluginDescription::operator= (const PluginDescription& other) throw()
  23787. {
  23788. name = other.name;
  23789. pluginFormatName = other.pluginFormatName;
  23790. category = other.category;
  23791. manufacturerName = other.manufacturerName;
  23792. version = other.version;
  23793. fileOrIdentifier = other.fileOrIdentifier;
  23794. uid = other.uid;
  23795. isInstrument = other.isInstrument;
  23796. lastFileModTime = other.lastFileModTime;
  23797. numInputChannels = other.numInputChannels;
  23798. numOutputChannels = other.numOutputChannels;
  23799. return *this;
  23800. }
  23801. bool PluginDescription::isDuplicateOf (const PluginDescription& other) const
  23802. {
  23803. return fileOrIdentifier == other.fileOrIdentifier
  23804. && uid == other.uid;
  23805. }
  23806. const String PluginDescription::createIdentifierString() const throw()
  23807. {
  23808. return pluginFormatName
  23809. + T("-") + name
  23810. + T("-") + String::toHexString (fileOrIdentifier.hashCode())
  23811. + T("-") + String::toHexString (uid);
  23812. }
  23813. XmlElement* PluginDescription::createXml() const
  23814. {
  23815. XmlElement* const e = new XmlElement (T("PLUGIN"));
  23816. e->setAttribute (T("name"), name);
  23817. e->setAttribute (T("format"), pluginFormatName);
  23818. e->setAttribute (T("category"), category);
  23819. e->setAttribute (T("manufacturer"), manufacturerName);
  23820. e->setAttribute (T("version"), version);
  23821. e->setAttribute (T("file"), fileOrIdentifier);
  23822. e->setAttribute (T("uid"), String::toHexString (uid));
  23823. e->setAttribute (T("isInstrument"), isInstrument);
  23824. e->setAttribute (T("fileTime"), String::toHexString (lastFileModTime.toMilliseconds()));
  23825. e->setAttribute (T("numInputs"), numInputChannels);
  23826. e->setAttribute (T("numOutputs"), numOutputChannels);
  23827. return e;
  23828. }
  23829. bool PluginDescription::loadFromXml (const XmlElement& xml)
  23830. {
  23831. if (xml.hasTagName (T("PLUGIN")))
  23832. {
  23833. name = xml.getStringAttribute (T("name"));
  23834. pluginFormatName = xml.getStringAttribute (T("format"));
  23835. category = xml.getStringAttribute (T("category"));
  23836. manufacturerName = xml.getStringAttribute (T("manufacturer"));
  23837. version = xml.getStringAttribute (T("version"));
  23838. fileOrIdentifier = xml.getStringAttribute (T("file"));
  23839. uid = xml.getStringAttribute (T("uid")).getHexValue32();
  23840. isInstrument = xml.getBoolAttribute (T("isInstrument"), false);
  23841. lastFileModTime = Time (xml.getStringAttribute (T("fileTime")).getHexValue64());
  23842. numInputChannels = xml.getIntAttribute (T("numInputs"));
  23843. numOutputChannels = xml.getIntAttribute (T("numOutputs"));
  23844. return true;
  23845. }
  23846. return false;
  23847. }
  23848. END_JUCE_NAMESPACE
  23849. /********* End of inlined file: juce_PluginDescription.cpp *********/
  23850. /********* Start of inlined file: juce_PluginDirectoryScanner.cpp *********/
  23851. BEGIN_JUCE_NAMESPACE
  23852. PluginDirectoryScanner::PluginDirectoryScanner (KnownPluginList& listToAddTo,
  23853. AudioPluginFormat& formatToLookFor,
  23854. FileSearchPath directoriesToSearch,
  23855. const bool recursive,
  23856. const File& deadMansPedalFile_)
  23857. : list (listToAddTo),
  23858. format (formatToLookFor),
  23859. deadMansPedalFile (deadMansPedalFile_),
  23860. nextIndex (0),
  23861. progress (0)
  23862. {
  23863. directoriesToSearch.removeRedundantPaths();
  23864. filesOrIdentifiersToScan = format.searchPathsForPlugins (directoriesToSearch, recursive);
  23865. // If any plugins have crashed recently when being loaded, move them to the
  23866. // end of the list to give the others a chance to load correctly..
  23867. const StringArray crashedPlugins (getDeadMansPedalFile());
  23868. for (int i = 0; i < crashedPlugins.size(); ++i)
  23869. {
  23870. const String f = crashedPlugins[i];
  23871. for (int j = filesOrIdentifiersToScan.size(); --j >= 0;)
  23872. if (f == filesOrIdentifiersToScan[j])
  23873. filesOrIdentifiersToScan.move (j, -1);
  23874. }
  23875. }
  23876. PluginDirectoryScanner::~PluginDirectoryScanner()
  23877. {
  23878. }
  23879. const String PluginDirectoryScanner::getNextPluginFileThatWillBeScanned() const throw()
  23880. {
  23881. return format.getNameOfPluginFromIdentifier (filesOrIdentifiersToScan [nextIndex]);
  23882. }
  23883. bool PluginDirectoryScanner::scanNextFile (const bool dontRescanIfAlreadyInList)
  23884. {
  23885. String file (filesOrIdentifiersToScan [nextIndex]);
  23886. if (file.isNotEmpty())
  23887. {
  23888. if (! list.isListingUpToDate (file))
  23889. {
  23890. OwnedArray <PluginDescription> typesFound;
  23891. // Add this plugin to the end of the dead-man's pedal list in case it crashes...
  23892. StringArray crashedPlugins (getDeadMansPedalFile());
  23893. crashedPlugins.removeString (file);
  23894. crashedPlugins.add (file);
  23895. setDeadMansPedalFile (crashedPlugins);
  23896. list.scanAndAddFile (file,
  23897. dontRescanIfAlreadyInList,
  23898. typesFound,
  23899. format);
  23900. // Managed to load without crashing, so remove it from the dead-man's-pedal..
  23901. crashedPlugins.removeString (file);
  23902. setDeadMansPedalFile (crashedPlugins);
  23903. if (typesFound.size() == 0)
  23904. failedFiles.add (file);
  23905. }
  23906. ++nextIndex;
  23907. progress = nextIndex / (float) filesOrIdentifiersToScan.size();
  23908. }
  23909. return nextIndex < filesOrIdentifiersToScan.size();
  23910. }
  23911. const StringArray PluginDirectoryScanner::getDeadMansPedalFile() throw()
  23912. {
  23913. StringArray lines;
  23914. if (deadMansPedalFile != File::nonexistent)
  23915. {
  23916. lines.addLines (deadMansPedalFile.loadFileAsString());
  23917. lines.removeEmptyStrings();
  23918. }
  23919. return lines;
  23920. }
  23921. void PluginDirectoryScanner::setDeadMansPedalFile (const StringArray& newContents) throw()
  23922. {
  23923. if (deadMansPedalFile != File::nonexistent)
  23924. deadMansPedalFile.replaceWithText (newContents.joinIntoString ("\n"), true, true);
  23925. }
  23926. END_JUCE_NAMESPACE
  23927. /********* End of inlined file: juce_PluginDirectoryScanner.cpp *********/
  23928. /********* Start of inlined file: juce_PluginListComponent.cpp *********/
  23929. BEGIN_JUCE_NAMESPACE
  23930. PluginListComponent::PluginListComponent (KnownPluginList& listToEdit,
  23931. const File& deadMansPedalFile_,
  23932. PropertiesFile* const propertiesToUse_)
  23933. : list (listToEdit),
  23934. deadMansPedalFile (deadMansPedalFile_),
  23935. propertiesToUse (propertiesToUse_)
  23936. {
  23937. addAndMakeVisible (listBox = new ListBox (String::empty, this));
  23938. addAndMakeVisible (optionsButton = new TextButton ("Options..."));
  23939. optionsButton->addButtonListener (this);
  23940. optionsButton->setTriggeredOnMouseDown (true);
  23941. setSize (400, 600);
  23942. list.addChangeListener (this);
  23943. }
  23944. PluginListComponent::~PluginListComponent()
  23945. {
  23946. list.removeChangeListener (this);
  23947. deleteAllChildren();
  23948. }
  23949. void PluginListComponent::resized()
  23950. {
  23951. listBox->setBounds (0, 0, getWidth(), getHeight() - 30);
  23952. optionsButton->changeWidthToFitText (24);
  23953. optionsButton->setTopLeftPosition (8, getHeight() - 28);
  23954. }
  23955. void PluginListComponent::changeListenerCallback (void*)
  23956. {
  23957. listBox->updateContent();
  23958. listBox->repaint();
  23959. }
  23960. int PluginListComponent::getNumRows()
  23961. {
  23962. return list.getNumTypes();
  23963. }
  23964. void PluginListComponent::paintListBoxItem (int row,
  23965. Graphics& g,
  23966. int width, int height,
  23967. bool rowIsSelected)
  23968. {
  23969. if (rowIsSelected)
  23970. g.fillAll (findColour (TextEditor::highlightColourId));
  23971. const PluginDescription* const pd = list.getType (row);
  23972. if (pd != 0)
  23973. {
  23974. GlyphArrangement ga;
  23975. ga.addCurtailedLineOfText (Font (height * 0.7f, Font::bold), pd->name, 8.0f, height * 0.8f, width - 10.0f, true);
  23976. g.setColour (Colours::black);
  23977. ga.draw (g);
  23978. float x, y, r, b;
  23979. ga.getBoundingBox (0, -1, x, y, r, b, false);
  23980. String desc;
  23981. desc << pd->pluginFormatName
  23982. << (pd->isInstrument ? " instrument" : " effect")
  23983. << " - "
  23984. << pd->numInputChannels << (pd->numInputChannels == 1 ? " in" : " ins")
  23985. << " / "
  23986. << pd->numOutputChannels << (pd->numOutputChannels == 1 ? " out" : " outs");
  23987. if (pd->manufacturerName.isNotEmpty())
  23988. desc << " - " << pd->manufacturerName;
  23989. if (pd->version.isNotEmpty())
  23990. desc << " - " << pd->version;
  23991. if (pd->category.isNotEmpty())
  23992. desc << " - category: '" << pd->category << '\'';
  23993. g.setColour (Colours::grey);
  23994. ga.clear();
  23995. ga.addCurtailedLineOfText (Font (height * 0.6f), desc, r + 10.0f, height * 0.8f, width - r - 12.0f, true);
  23996. ga.draw (g);
  23997. }
  23998. }
  23999. void PluginListComponent::deleteKeyPressed (int lastRowSelected)
  24000. {
  24001. list.removeType (lastRowSelected);
  24002. }
  24003. void PluginListComponent::buttonClicked (Button* b)
  24004. {
  24005. if (optionsButton == b)
  24006. {
  24007. PopupMenu menu;
  24008. menu.addItem (1, TRANS("Clear list"));
  24009. menu.addItem (5, TRANS("Remove selected plugin from list"), listBox->getNumSelectedRows() > 0);
  24010. menu.addItem (6, TRANS("Show folder containing selected plugin"), listBox->getNumSelectedRows() > 0);
  24011. menu.addItem (7, TRANS("Remove any plugins whose files no longer exist"));
  24012. menu.addSeparator();
  24013. menu.addItem (2, TRANS("Sort alphabetically"));
  24014. menu.addItem (3, TRANS("Sort by category"));
  24015. menu.addItem (4, TRANS("Sort by manufacturer"));
  24016. menu.addSeparator();
  24017. for (int i = 0; i < AudioPluginFormatManager::getInstance()->getNumFormats(); ++i)
  24018. {
  24019. AudioPluginFormat* const format = AudioPluginFormatManager::getInstance()->getFormat (i);
  24020. if (format->getDefaultLocationsToSearch().getNumPaths() > 0)
  24021. menu.addItem (10 + i, "Scan for new or updated " + format->getName() + " plugins...");
  24022. }
  24023. const int r = menu.showAt (optionsButton);
  24024. if (r == 1)
  24025. {
  24026. list.clear();
  24027. }
  24028. else if (r == 2)
  24029. {
  24030. list.sort (KnownPluginList::sortAlphabetically);
  24031. }
  24032. else if (r == 3)
  24033. {
  24034. list.sort (KnownPluginList::sortByCategory);
  24035. }
  24036. else if (r == 4)
  24037. {
  24038. list.sort (KnownPluginList::sortByManufacturer);
  24039. }
  24040. else if (r == 5)
  24041. {
  24042. const SparseSet <int> selected (listBox->getSelectedRows());
  24043. for (int i = list.getNumTypes(); --i >= 0;)
  24044. if (selected.contains (i))
  24045. list.removeType (i);
  24046. }
  24047. else if (r == 6)
  24048. {
  24049. const PluginDescription* const desc = list.getType (listBox->getSelectedRow());
  24050. if (desc != 0)
  24051. {
  24052. if (File (desc->fileOrIdentifier).existsAsFile())
  24053. File (desc->fileOrIdentifier).getParentDirectory().startAsProcess();
  24054. }
  24055. }
  24056. else if (r == 7)
  24057. {
  24058. for (int i = list.getNumTypes(); --i >= 0;)
  24059. {
  24060. if (! AudioPluginFormatManager::getInstance()->doesPluginStillExist (*list.getType (i)))
  24061. {
  24062. list.removeType (i);
  24063. }
  24064. }
  24065. }
  24066. else if (r != 0)
  24067. {
  24068. typeToScan = r - 10;
  24069. startTimer (1);
  24070. }
  24071. }
  24072. }
  24073. void PluginListComponent::timerCallback()
  24074. {
  24075. stopTimer();
  24076. scanFor (AudioPluginFormatManager::getInstance()->getFormat (typeToScan));
  24077. }
  24078. bool PluginListComponent::isInterestedInFileDrag (const StringArray& /*files*/)
  24079. {
  24080. return true;
  24081. }
  24082. void PluginListComponent::filesDropped (const StringArray& files, int, int)
  24083. {
  24084. OwnedArray <PluginDescription> typesFound;
  24085. list.scanAndAddDragAndDroppedFiles (files, typesFound);
  24086. }
  24087. void PluginListComponent::scanFor (AudioPluginFormat* format)
  24088. {
  24089. if (format == 0)
  24090. return;
  24091. FileSearchPath path (format->getDefaultLocationsToSearch());
  24092. if (propertiesToUse != 0)
  24093. path = propertiesToUse->getValue ("lastPluginScanPath_" + format->getName(), path.toString());
  24094. {
  24095. AlertWindow aw (TRANS("Select folders to scan..."), String::empty, AlertWindow::NoIcon);
  24096. FileSearchPathListComponent pathList;
  24097. pathList.setSize (500, 300);
  24098. pathList.setPath (path);
  24099. aw.addCustomComponent (&pathList);
  24100. aw.addButton (TRANS("Scan"), 1, KeyPress::returnKey);
  24101. aw.addButton (TRANS("Cancel"), 0, KeyPress (KeyPress::escapeKey));
  24102. if (aw.runModalLoop() == 0)
  24103. return;
  24104. path = pathList.getPath();
  24105. }
  24106. if (propertiesToUse != 0)
  24107. {
  24108. propertiesToUse->setValue ("lastPluginScanPath_" + format->getName(), path.toString());
  24109. propertiesToUse->saveIfNeeded();
  24110. }
  24111. double progress = 0.0;
  24112. AlertWindow aw (TRANS("Scanning for plugins..."),
  24113. TRANS("Searching for all possible plugin files..."), AlertWindow::NoIcon);
  24114. aw.addButton (TRANS("Cancel"), 0, KeyPress (KeyPress::escapeKey));
  24115. aw.addProgressBarComponent (progress);
  24116. aw.enterModalState();
  24117. MessageManager::getInstance()->runDispatchLoopUntil (300);
  24118. PluginDirectoryScanner scanner (list, *format, path, true, deadMansPedalFile);
  24119. for (;;)
  24120. {
  24121. aw.setMessage (TRANS("Testing:\n\n")
  24122. + scanner.getNextPluginFileThatWillBeScanned());
  24123. MessageManager::getInstance()->runDispatchLoopUntil (20);
  24124. if (! scanner.scanNextFile (true))
  24125. break;
  24126. if (! aw.isCurrentlyModal())
  24127. break;
  24128. progress = scanner.getProgress();
  24129. }
  24130. if (scanner.getFailedFiles().size() > 0)
  24131. {
  24132. StringArray shortNames;
  24133. for (int i = 0; i < scanner.getFailedFiles().size(); ++i)
  24134. shortNames.add (File (scanner.getFailedFiles()[i]).getFileName());
  24135. AlertWindow::showMessageBox (AlertWindow::InfoIcon,
  24136. TRANS("Scan complete"),
  24137. TRANS("Note that the following files appeared to be plugin files, but failed to load correctly:\n\n")
  24138. + shortNames.joinIntoString (", "));
  24139. }
  24140. }
  24141. END_JUCE_NAMESPACE
  24142. /********* End of inlined file: juce_PluginListComponent.cpp *********/
  24143. /********* Start of inlined file: juce_AudioUnitPluginFormat.mm *********/
  24144. #if JUCE_PLUGINHOST_AU && (! (defined (LINUX) || defined (_WIN32)))
  24145. #include <AudioUnit/AudioUnit.h>
  24146. #include <AudioUnit/AUCocoaUIView.h>
  24147. #include <CoreAudioKit/AUGenericView.h>
  24148. #if JUCE_SUPPORT_CARBON
  24149. #include <AudioToolbox/AudioUnitUtilities.h>
  24150. #include <AudioUnit/AudioUnitCarbonView.h>
  24151. #endif
  24152. BEGIN_JUCE_NAMESPACE
  24153. #if JUCE_MAC && JUCE_SUPPORT_CARBON
  24154. #endif
  24155. #if JUCE_MAC
  24156. // Change this to disable logging of various activities
  24157. #ifndef AU_LOGGING
  24158. #define AU_LOGGING 1
  24159. #endif
  24160. #if AU_LOGGING
  24161. #define log(a) Logger::writeToLog(a);
  24162. #else
  24163. #define log(a)
  24164. #endif
  24165. static int insideCallback = 0;
  24166. static const String osTypeToString (OSType type) throw()
  24167. {
  24168. char s[4];
  24169. s[0] = (char) (((uint32) type) >> 24);
  24170. s[1] = (char) (((uint32) type) >> 16);
  24171. s[2] = (char) (((uint32) type) >> 8);
  24172. s[3] = (char) ((uint32) type);
  24173. return String (s, 4);
  24174. }
  24175. static OSType stringToOSType (const String& s1) throw()
  24176. {
  24177. const String s (s1 + " ");
  24178. return (((OSType) (unsigned char) s[0]) << 24)
  24179. | (((OSType) (unsigned char) s[1]) << 16)
  24180. | (((OSType) (unsigned char) s[2]) << 8)
  24181. | ((OSType) (unsigned char) s[3]);
  24182. }
  24183. static const tchar* auIdentifierPrefix = T("AudioUnit:");
  24184. static const String createAUPluginIdentifier (const ComponentDescription& desc)
  24185. {
  24186. jassert (osTypeToString ('abcd') == T("abcd")); // agh, must have got the endianness wrong..
  24187. jassert (stringToOSType ("abcd") == (OSType) 'abcd'); // ditto
  24188. String s (auIdentifierPrefix);
  24189. if (desc.componentType == kAudioUnitType_MusicDevice)
  24190. s << "Synths/";
  24191. else if (desc.componentType == kAudioUnitType_MusicEffect
  24192. || desc.componentType == kAudioUnitType_Effect)
  24193. s << "Effects/";
  24194. else if (desc.componentType == kAudioUnitType_Generator)
  24195. s << "Generators/";
  24196. else if (desc.componentType == kAudioUnitType_Panner)
  24197. s << "Panners/";
  24198. s << osTypeToString (desc.componentType)
  24199. << T(",")
  24200. << osTypeToString (desc.componentSubType)
  24201. << T(",")
  24202. << osTypeToString (desc.componentManufacturer);
  24203. return s;
  24204. }
  24205. static void getAUDetails (ComponentRecord* comp, String& name, String& manufacturer)
  24206. {
  24207. Handle componentNameHandle = NewHandle (sizeof (void*));
  24208. Handle componentInfoHandle = NewHandle (sizeof (void*));
  24209. if (componentNameHandle != 0 && componentInfoHandle != 0)
  24210. {
  24211. ComponentDescription desc;
  24212. if (GetComponentInfo (comp, &desc, componentNameHandle, componentInfoHandle, 0) == noErr)
  24213. {
  24214. ConstStr255Param nameString = (ConstStr255Param) (*componentNameHandle);
  24215. ConstStr255Param infoString = (ConstStr255Param) (*componentInfoHandle);
  24216. if (nameString != 0 && nameString[0] != 0)
  24217. {
  24218. const String all ((const char*) nameString + 1, nameString[0]);
  24219. DBG ("name: "+ all);
  24220. manufacturer = all.upToFirstOccurrenceOf (T(":"), false, false).trim();
  24221. name = all.fromFirstOccurrenceOf (T(":"), false, false).trim();
  24222. }
  24223. if (infoString != 0 && infoString[0] != 0)
  24224. {
  24225. const String all ((const char*) infoString + 1, infoString[0]);
  24226. DBG ("info: " + all);
  24227. }
  24228. if (name.isEmpty())
  24229. name = "<Unknown>";
  24230. }
  24231. DisposeHandle (componentNameHandle);
  24232. DisposeHandle (componentInfoHandle);
  24233. }
  24234. }
  24235. static bool getComponentDescFromIdentifier (const String& fileOrIdentifier, ComponentDescription& desc,
  24236. String& name, String& version, String& manufacturer)
  24237. {
  24238. zerostruct (desc);
  24239. if (fileOrIdentifier.startsWithIgnoreCase (auIdentifierPrefix))
  24240. {
  24241. String s (fileOrIdentifier.substring (jmax (fileOrIdentifier.lastIndexOfChar (T(':')),
  24242. fileOrIdentifier.lastIndexOfChar (T('/'))) + 1));
  24243. StringArray tokens;
  24244. tokens.addTokens (s, T(","), 0);
  24245. tokens.trim();
  24246. tokens.removeEmptyStrings();
  24247. if (tokens.size() == 3)
  24248. {
  24249. desc.componentType = stringToOSType (tokens[0]);
  24250. desc.componentSubType = stringToOSType (tokens[1]);
  24251. desc.componentManufacturer = stringToOSType (tokens[2]);
  24252. ComponentRecord* comp = FindNextComponent (0, &desc);
  24253. if (comp != 0)
  24254. {
  24255. getAUDetails (comp, name, manufacturer);
  24256. return true;
  24257. }
  24258. }
  24259. }
  24260. return false;
  24261. }
  24262. class AudioUnitPluginWindowCarbon;
  24263. class AudioUnitPluginWindowCocoa;
  24264. class AudioUnitPluginInstance : public AudioPluginInstance
  24265. {
  24266. public:
  24267. ~AudioUnitPluginInstance();
  24268. // AudioPluginInstance methods:
  24269. void fillInPluginDescription (PluginDescription& desc) const
  24270. {
  24271. desc.name = pluginName;
  24272. desc.fileOrIdentifier = createAUPluginIdentifier (componentDesc);
  24273. desc.uid = ((int) componentDesc.componentType)
  24274. ^ ((int) componentDesc.componentSubType)
  24275. ^ ((int) componentDesc.componentManufacturer);
  24276. desc.lastFileModTime = 0;
  24277. desc.pluginFormatName = "AudioUnit";
  24278. desc.category = getCategory();
  24279. desc.manufacturerName = manufacturer;
  24280. desc.version = version;
  24281. desc.numInputChannels = getNumInputChannels();
  24282. desc.numOutputChannels = getNumOutputChannels();
  24283. desc.isInstrument = (componentDesc.componentType == kAudioUnitType_MusicDevice);
  24284. }
  24285. const String getName() const { return pluginName; }
  24286. bool acceptsMidi() const { return wantsMidiMessages; }
  24287. bool producesMidi() const { return false; }
  24288. // AudioProcessor methods:
  24289. void prepareToPlay (double sampleRate, int estimatedSamplesPerBlock);
  24290. void releaseResources();
  24291. void processBlock (AudioSampleBuffer& buffer,
  24292. MidiBuffer& midiMessages);
  24293. AudioProcessorEditor* createEditor();
  24294. const String getInputChannelName (const int index) const;
  24295. bool isInputChannelStereoPair (int index) const;
  24296. const String getOutputChannelName (const int index) const;
  24297. bool isOutputChannelStereoPair (int index) const;
  24298. int getNumParameters();
  24299. float getParameter (int index);
  24300. void setParameter (int index, float newValue);
  24301. const String getParameterName (int index);
  24302. const String getParameterText (int index);
  24303. bool isParameterAutomatable (int index) const;
  24304. int getNumPrograms();
  24305. int getCurrentProgram();
  24306. void setCurrentProgram (int index);
  24307. const String getProgramName (int index);
  24308. void changeProgramName (int index, const String& newName);
  24309. void getStateInformation (MemoryBlock& destData);
  24310. void getCurrentProgramStateInformation (MemoryBlock& destData);
  24311. void setStateInformation (const void* data, int sizeInBytes);
  24312. void setCurrentProgramStateInformation (const void* data, int sizeInBytes);
  24313. juce_UseDebuggingNewOperator
  24314. private:
  24315. friend class AudioUnitPluginWindowCarbon;
  24316. friend class AudioUnitPluginWindowCocoa;
  24317. friend class AudioUnitPluginFormat;
  24318. ComponentDescription componentDesc;
  24319. String pluginName, manufacturer, version;
  24320. String fileOrIdentifier;
  24321. CriticalSection lock;
  24322. bool initialised, wantsMidiMessages, wasPlaying;
  24323. HeapBlock <AudioBufferList> outputBufferList;
  24324. AudioTimeStamp timeStamp;
  24325. AudioSampleBuffer* currentBuffer;
  24326. AudioUnit audioUnit;
  24327. Array <int> parameterIds;
  24328. bool getComponentDescFromFile (const String& fileOrIdentifier);
  24329. void initialise();
  24330. OSStatus renderGetInput (AudioUnitRenderActionFlags* ioActionFlags,
  24331. const AudioTimeStamp* inTimeStamp,
  24332. UInt32 inBusNumber,
  24333. UInt32 inNumberFrames,
  24334. AudioBufferList* ioData) const;
  24335. static OSStatus renderGetInputCallback (void* inRefCon,
  24336. AudioUnitRenderActionFlags* ioActionFlags,
  24337. const AudioTimeStamp* inTimeStamp,
  24338. UInt32 inBusNumber,
  24339. UInt32 inNumberFrames,
  24340. AudioBufferList* ioData)
  24341. {
  24342. return ((AudioUnitPluginInstance*) inRefCon)
  24343. ->renderGetInput (ioActionFlags, inTimeStamp, inBusNumber, inNumberFrames, ioData);
  24344. }
  24345. OSStatus getBeatAndTempo (Float64* outCurrentBeat, Float64* outCurrentTempo) const;
  24346. OSStatus getMusicalTimeLocation (UInt32* outDeltaSampleOffsetToNextBeat, Float32* outTimeSig_Numerator,
  24347. UInt32* outTimeSig_Denominator, Float64* outCurrentMeasureDownBeat) const;
  24348. OSStatus getTransportState (Boolean* outIsPlaying, Boolean* outTransportStateChanged,
  24349. Float64* outCurrentSampleInTimeLine, Boolean* outIsCycling,
  24350. Float64* outCycleStartBeat, Float64* outCycleEndBeat);
  24351. static OSStatus getBeatAndTempoCallback (void* inHostUserData, Float64* outCurrentBeat, Float64* outCurrentTempo)
  24352. {
  24353. return ((AudioUnitPluginInstance*) inHostUserData)->getBeatAndTempo (outCurrentBeat, outCurrentTempo);
  24354. }
  24355. static OSStatus getMusicalTimeLocationCallback (void* inHostUserData, UInt32* outDeltaSampleOffsetToNextBeat,
  24356. Float32* outTimeSig_Numerator, UInt32* outTimeSig_Denominator,
  24357. Float64* outCurrentMeasureDownBeat)
  24358. {
  24359. return ((AudioUnitPluginInstance*) inHostUserData)
  24360. ->getMusicalTimeLocation (outDeltaSampleOffsetToNextBeat, outTimeSig_Numerator,
  24361. outTimeSig_Denominator, outCurrentMeasureDownBeat);
  24362. }
  24363. static OSStatus getTransportStateCallback (void* inHostUserData, Boolean* outIsPlaying, Boolean* outTransportStateChanged,
  24364. Float64* outCurrentSampleInTimeLine, Boolean* outIsCycling,
  24365. Float64* outCycleStartBeat, Float64* outCycleEndBeat)
  24366. {
  24367. return ((AudioUnitPluginInstance*) inHostUserData)
  24368. ->getTransportState (outIsPlaying, outTransportStateChanged,
  24369. outCurrentSampleInTimeLine, outIsCycling,
  24370. outCycleStartBeat, outCycleEndBeat);
  24371. }
  24372. void getNumChannels (int& numIns, int& numOuts)
  24373. {
  24374. numIns = 0;
  24375. numOuts = 0;
  24376. AUChannelInfo supportedChannels [128];
  24377. UInt32 supportedChannelsSize = sizeof (supportedChannels);
  24378. if (AudioUnitGetProperty (audioUnit, kAudioUnitProperty_SupportedNumChannels, kAudioUnitScope_Global,
  24379. 0, supportedChannels, &supportedChannelsSize) == noErr
  24380. && supportedChannelsSize > 0)
  24381. {
  24382. for (int i = 0; i < supportedChannelsSize / sizeof (AUChannelInfo); ++i)
  24383. {
  24384. numIns = jmax (numIns, (int) supportedChannels[i].inChannels);
  24385. numOuts = jmax (numOuts, (int) supportedChannels[i].outChannels);
  24386. }
  24387. }
  24388. else
  24389. {
  24390. // (this really means the plugin will take any number of ins/outs as long
  24391. // as they are the same)
  24392. numIns = numOuts = 2;
  24393. }
  24394. }
  24395. const String getCategory() const;
  24396. AudioUnitPluginInstance (const String& fileOrIdentifier);
  24397. };
  24398. AudioUnitPluginInstance::AudioUnitPluginInstance (const String& fileOrIdentifier)
  24399. : fileOrIdentifier (fileOrIdentifier),
  24400. initialised (false),
  24401. wantsMidiMessages (false),
  24402. audioUnit (0),
  24403. currentBuffer (0)
  24404. {
  24405. try
  24406. {
  24407. ++insideCallback;
  24408. log (T("Opening AU: ") + fileOrIdentifier);
  24409. if (getComponentDescFromFile (fileOrIdentifier))
  24410. {
  24411. ComponentRecord* const comp = FindNextComponent (0, &componentDesc);
  24412. if (comp != 0)
  24413. {
  24414. audioUnit = (AudioUnit) OpenComponent (comp);
  24415. wantsMidiMessages = componentDesc.componentType == kAudioUnitType_MusicDevice
  24416. || componentDesc.componentType == kAudioUnitType_MusicEffect;
  24417. }
  24418. }
  24419. --insideCallback;
  24420. }
  24421. catch (...)
  24422. {
  24423. --insideCallback;
  24424. }
  24425. }
  24426. AudioUnitPluginInstance::~AudioUnitPluginInstance()
  24427. {
  24428. {
  24429. const ScopedLock sl (lock);
  24430. jassert (insideCallback == 0);
  24431. if (audioUnit != 0)
  24432. {
  24433. AudioUnitUninitialize (audioUnit);
  24434. CloseComponent (audioUnit);
  24435. audioUnit = 0;
  24436. }
  24437. }
  24438. }
  24439. bool AudioUnitPluginInstance::getComponentDescFromFile (const String& fileOrIdentifier)
  24440. {
  24441. zerostruct (componentDesc);
  24442. if (getComponentDescFromIdentifier (fileOrIdentifier, componentDesc, pluginName, version, manufacturer))
  24443. return true;
  24444. const File file (fileOrIdentifier);
  24445. if (! file.hasFileExtension (T(".component")))
  24446. return false;
  24447. const char* const utf8 = fileOrIdentifier.toUTF8();
  24448. CFURLRef url = CFURLCreateFromFileSystemRepresentation (0, (const UInt8*) utf8,
  24449. strlen (utf8), file.isDirectory());
  24450. if (url != 0)
  24451. {
  24452. CFBundleRef bundleRef = CFBundleCreate (kCFAllocatorDefault, url);
  24453. CFRelease (url);
  24454. if (bundleRef != 0)
  24455. {
  24456. CFTypeRef name = CFBundleGetValueForInfoDictionaryKey (bundleRef, CFSTR("CFBundleName"));
  24457. if (name != 0 && CFGetTypeID (name) == CFStringGetTypeID())
  24458. pluginName = PlatformUtilities::cfStringToJuceString ((CFStringRef) name);
  24459. if (pluginName.isEmpty())
  24460. pluginName = file.getFileNameWithoutExtension();
  24461. CFTypeRef versionString = CFBundleGetValueForInfoDictionaryKey (bundleRef, CFSTR("CFBundleVersion"));
  24462. if (versionString != 0 && CFGetTypeID (versionString) == CFStringGetTypeID())
  24463. version = PlatformUtilities::cfStringToJuceString ((CFStringRef) versionString);
  24464. CFTypeRef manuString = CFBundleGetValueForInfoDictionaryKey (bundleRef, CFSTR("CFBundleGetInfoString"));
  24465. if (manuString != 0 && CFGetTypeID (manuString) == CFStringGetTypeID())
  24466. manufacturer = PlatformUtilities::cfStringToJuceString ((CFStringRef) manuString);
  24467. short resFileId = CFBundleOpenBundleResourceMap (bundleRef);
  24468. UseResFile (resFileId);
  24469. for (int i = 1; i <= Count1Resources ('thng'); ++i)
  24470. {
  24471. Handle h = Get1IndResource ('thng', i);
  24472. if (h != 0)
  24473. {
  24474. HLock (h);
  24475. const uint32* const types = (const uint32*) *h;
  24476. if (types[0] == kAudioUnitType_MusicDevice
  24477. || types[0] == kAudioUnitType_MusicEffect
  24478. || types[0] == kAudioUnitType_Effect
  24479. || types[0] == kAudioUnitType_Generator
  24480. || types[0] == kAudioUnitType_Panner)
  24481. {
  24482. componentDesc.componentType = types[0];
  24483. componentDesc.componentSubType = types[1];
  24484. componentDesc.componentManufacturer = types[2];
  24485. break;
  24486. }
  24487. HUnlock (h);
  24488. ReleaseResource (h);
  24489. }
  24490. }
  24491. CFBundleCloseBundleResourceMap (bundleRef, resFileId);
  24492. CFRelease (bundleRef);
  24493. }
  24494. }
  24495. return componentDesc.componentType != 0 && componentDesc.componentSubType != 0;
  24496. }
  24497. void AudioUnitPluginInstance::initialise()
  24498. {
  24499. if (initialised || audioUnit == 0)
  24500. return;
  24501. log (T("Initialising AU: ") + pluginName);
  24502. parameterIds.clear();
  24503. {
  24504. UInt32 paramListSize = 0;
  24505. AudioUnitGetProperty (audioUnit, kAudioUnitProperty_ParameterList, kAudioUnitScope_Global,
  24506. 0, 0, &paramListSize);
  24507. if (paramListSize > 0)
  24508. {
  24509. parameterIds.insertMultiple (0, 0, paramListSize / sizeof (int));
  24510. AudioUnitGetProperty (audioUnit, kAudioUnitProperty_ParameterList, kAudioUnitScope_Global,
  24511. 0, &parameterIds.getReference(0), &paramListSize);
  24512. }
  24513. }
  24514. {
  24515. AURenderCallbackStruct info;
  24516. zerostruct (info);
  24517. info.inputProcRefCon = this;
  24518. info.inputProc = renderGetInputCallback;
  24519. AudioUnitSetProperty (audioUnit, kAudioUnitProperty_SetRenderCallback, kAudioUnitScope_Input,
  24520. 0, &info, sizeof (info));
  24521. }
  24522. {
  24523. HostCallbackInfo info;
  24524. zerostruct (info);
  24525. info.hostUserData = this;
  24526. info.beatAndTempoProc = getBeatAndTempoCallback;
  24527. info.musicalTimeLocationProc = getMusicalTimeLocationCallback;
  24528. info.transportStateProc = getTransportStateCallback;
  24529. AudioUnitSetProperty (audioUnit, kAudioUnitProperty_HostCallbacks, kAudioUnitScope_Global,
  24530. 0, &info, sizeof (info));
  24531. }
  24532. int numIns, numOuts;
  24533. getNumChannels (numIns, numOuts);
  24534. setPlayConfigDetails (numIns, numOuts, 0, 0);
  24535. initialised = AudioUnitInitialize (audioUnit) == noErr;
  24536. setLatencySamples (0);
  24537. }
  24538. void AudioUnitPluginInstance::prepareToPlay (double sampleRate_,
  24539. int samplesPerBlockExpected)
  24540. {
  24541. initialise();
  24542. if (initialised)
  24543. {
  24544. int numIns, numOuts;
  24545. getNumChannels (numIns, numOuts);
  24546. setPlayConfigDetails (numIns, numOuts, sampleRate_, samplesPerBlockExpected);
  24547. Float64 latencySecs = 0.0;
  24548. UInt32 latencySize = sizeof (latencySecs);
  24549. AudioUnitGetProperty (audioUnit, kAudioUnitProperty_Latency, kAudioUnitScope_Global,
  24550. 0, &latencySecs, &latencySize);
  24551. setLatencySamples (roundToInt (latencySecs * sampleRate_));
  24552. AudioUnitReset (audioUnit, kAudioUnitScope_Input, 0);
  24553. AudioUnitReset (audioUnit, kAudioUnitScope_Output, 0);
  24554. AudioUnitReset (audioUnit, kAudioUnitScope_Global, 0);
  24555. AudioStreamBasicDescription stream;
  24556. zerostruct (stream);
  24557. stream.mSampleRate = sampleRate_;
  24558. stream.mFormatID = kAudioFormatLinearPCM;
  24559. stream.mFormatFlags = kAudioFormatFlagsNativeFloatPacked | kAudioFormatFlagIsNonInterleaved;
  24560. stream.mFramesPerPacket = 1;
  24561. stream.mBytesPerPacket = 4;
  24562. stream.mBytesPerFrame = 4;
  24563. stream.mBitsPerChannel = 32;
  24564. stream.mChannelsPerFrame = numIns;
  24565. OSStatus err = AudioUnitSetProperty (audioUnit,
  24566. kAudioUnitProperty_StreamFormat,
  24567. kAudioUnitScope_Input,
  24568. 0, &stream, sizeof (stream));
  24569. stream.mChannelsPerFrame = numOuts;
  24570. err = AudioUnitSetProperty (audioUnit,
  24571. kAudioUnitProperty_StreamFormat,
  24572. kAudioUnitScope_Output,
  24573. 0, &stream, sizeof (stream));
  24574. outputBufferList.calloc (sizeof (AudioBufferList) + sizeof (AudioBuffer) * (numOuts + 1), 1);
  24575. outputBufferList->mNumberBuffers = numOuts;
  24576. for (int i = numOuts; --i >= 0;)
  24577. outputBufferList->mBuffers[i].mNumberChannels = 1;
  24578. zerostruct (timeStamp);
  24579. timeStamp.mSampleTime = 0;
  24580. timeStamp.mHostTime = AudioGetCurrentHostTime();
  24581. timeStamp.mFlags = kAudioTimeStampSampleTimeValid | kAudioTimeStampHostTimeValid;
  24582. currentBuffer = 0;
  24583. wasPlaying = false;
  24584. }
  24585. }
  24586. void AudioUnitPluginInstance::releaseResources()
  24587. {
  24588. if (initialised)
  24589. {
  24590. AudioUnitReset (audioUnit, kAudioUnitScope_Input, 0);
  24591. AudioUnitReset (audioUnit, kAudioUnitScope_Output, 0);
  24592. AudioUnitReset (audioUnit, kAudioUnitScope_Global, 0);
  24593. outputBufferList.free();
  24594. currentBuffer = 0;
  24595. }
  24596. }
  24597. OSStatus AudioUnitPluginInstance::renderGetInput (AudioUnitRenderActionFlags* ioActionFlags,
  24598. const AudioTimeStamp* inTimeStamp,
  24599. UInt32 inBusNumber,
  24600. UInt32 inNumberFrames,
  24601. AudioBufferList* ioData) const
  24602. {
  24603. if (inBusNumber == 0
  24604. && currentBuffer != 0)
  24605. {
  24606. jassert (inNumberFrames == currentBuffer->getNumSamples()); // if this ever happens, might need to add extra handling
  24607. for (int i = 0; i < ioData->mNumberBuffers; ++i)
  24608. {
  24609. if (i < currentBuffer->getNumChannels())
  24610. {
  24611. memcpy (ioData->mBuffers[i].mData,
  24612. currentBuffer->getSampleData (i, 0),
  24613. sizeof (float) * inNumberFrames);
  24614. }
  24615. else
  24616. {
  24617. zeromem (ioData->mBuffers[i].mData, sizeof (float) * inNumberFrames);
  24618. }
  24619. }
  24620. }
  24621. return noErr;
  24622. }
  24623. void AudioUnitPluginInstance::processBlock (AudioSampleBuffer& buffer,
  24624. MidiBuffer& midiMessages)
  24625. {
  24626. const int numSamples = buffer.getNumSamples();
  24627. if (initialised)
  24628. {
  24629. AudioUnitRenderActionFlags flags = 0;
  24630. timeStamp.mHostTime = AudioGetCurrentHostTime();
  24631. for (int i = getNumOutputChannels(); --i >= 0;)
  24632. {
  24633. outputBufferList->mBuffers[i].mDataByteSize = sizeof (float) * numSamples;
  24634. outputBufferList->mBuffers[i].mData = buffer.getSampleData (i, 0);
  24635. }
  24636. currentBuffer = &buffer;
  24637. if (wantsMidiMessages)
  24638. {
  24639. const uint8* midiEventData;
  24640. int midiEventSize, midiEventPosition;
  24641. MidiBuffer::Iterator i (midiMessages);
  24642. while (i.getNextEvent (midiEventData, midiEventSize, midiEventPosition))
  24643. {
  24644. if (midiEventSize <= 3)
  24645. MusicDeviceMIDIEvent (audioUnit,
  24646. midiEventData[0], midiEventData[1], midiEventData[2],
  24647. midiEventPosition);
  24648. else
  24649. MusicDeviceSysEx (audioUnit, midiEventData, midiEventSize);
  24650. }
  24651. midiMessages.clear();
  24652. }
  24653. AudioUnitRender (audioUnit, &flags, &timeStamp,
  24654. 0, numSamples, outputBufferList);
  24655. timeStamp.mSampleTime += numSamples;
  24656. }
  24657. else
  24658. {
  24659. // Not initialised, so just bypass..
  24660. for (int i = getNumInputChannels(); i < getNumOutputChannels(); ++i)
  24661. buffer.clear (i, 0, buffer.getNumSamples());
  24662. }
  24663. }
  24664. OSStatus AudioUnitPluginInstance::getBeatAndTempo (Float64* outCurrentBeat, Float64* outCurrentTempo) const
  24665. {
  24666. AudioPlayHead* const ph = getPlayHead();
  24667. AudioPlayHead::CurrentPositionInfo result;
  24668. if (ph != 0 && ph->getCurrentPosition (result))
  24669. {
  24670. if (outCurrentBeat != 0)
  24671. *outCurrentBeat = result.ppqPosition;
  24672. if (outCurrentTempo != 0)
  24673. *outCurrentTempo = result.bpm;
  24674. }
  24675. else
  24676. {
  24677. if (outCurrentBeat != 0)
  24678. *outCurrentBeat = 0;
  24679. if (outCurrentTempo != 0)
  24680. *outCurrentTempo = 120.0;
  24681. }
  24682. return noErr;
  24683. }
  24684. OSStatus AudioUnitPluginInstance::getMusicalTimeLocation (UInt32* outDeltaSampleOffsetToNextBeat,
  24685. Float32* outTimeSig_Numerator,
  24686. UInt32* outTimeSig_Denominator,
  24687. Float64* outCurrentMeasureDownBeat) const
  24688. {
  24689. AudioPlayHead* const ph = getPlayHead();
  24690. AudioPlayHead::CurrentPositionInfo result;
  24691. if (ph != 0 && ph->getCurrentPosition (result))
  24692. {
  24693. if (outTimeSig_Numerator != 0)
  24694. *outTimeSig_Numerator = result.timeSigNumerator;
  24695. if (outTimeSig_Denominator != 0)
  24696. *outTimeSig_Denominator = result.timeSigDenominator;
  24697. if (outDeltaSampleOffsetToNextBeat != 0)
  24698. *outDeltaSampleOffsetToNextBeat = 0; //xxx
  24699. if (outCurrentMeasureDownBeat != 0)
  24700. *outCurrentMeasureDownBeat = result.ppqPositionOfLastBarStart; //xxx wrong
  24701. }
  24702. else
  24703. {
  24704. if (outDeltaSampleOffsetToNextBeat != 0)
  24705. *outDeltaSampleOffsetToNextBeat = 0;
  24706. if (outTimeSig_Numerator != 0)
  24707. *outTimeSig_Numerator = 4;
  24708. if (outTimeSig_Denominator != 0)
  24709. *outTimeSig_Denominator = 4;
  24710. if (outCurrentMeasureDownBeat != 0)
  24711. *outCurrentMeasureDownBeat = 0;
  24712. }
  24713. return noErr;
  24714. }
  24715. OSStatus AudioUnitPluginInstance::getTransportState (Boolean* outIsPlaying,
  24716. Boolean* outTransportStateChanged,
  24717. Float64* outCurrentSampleInTimeLine,
  24718. Boolean* outIsCycling,
  24719. Float64* outCycleStartBeat,
  24720. Float64* outCycleEndBeat)
  24721. {
  24722. AudioPlayHead* const ph = getPlayHead();
  24723. AudioPlayHead::CurrentPositionInfo result;
  24724. if (ph != 0 && ph->getCurrentPosition (result))
  24725. {
  24726. if (outIsPlaying != 0)
  24727. *outIsPlaying = result.isPlaying;
  24728. if (outTransportStateChanged != 0)
  24729. {
  24730. *outTransportStateChanged = result.isPlaying != wasPlaying;
  24731. wasPlaying = result.isPlaying;
  24732. }
  24733. if (outCurrentSampleInTimeLine != 0)
  24734. *outCurrentSampleInTimeLine = roundToInt (result.timeInSeconds * getSampleRate());
  24735. if (outIsCycling != 0)
  24736. *outIsCycling = false;
  24737. if (outCycleStartBeat != 0)
  24738. *outCycleStartBeat = 0;
  24739. if (outCycleEndBeat != 0)
  24740. *outCycleEndBeat = 0;
  24741. }
  24742. else
  24743. {
  24744. if (outIsPlaying != 0)
  24745. *outIsPlaying = false;
  24746. if (outTransportStateChanged != 0)
  24747. *outTransportStateChanged = false;
  24748. if (outCurrentSampleInTimeLine != 0)
  24749. *outCurrentSampleInTimeLine = 0;
  24750. if (outIsCycling != 0)
  24751. *outIsCycling = false;
  24752. if (outCycleStartBeat != 0)
  24753. *outCycleStartBeat = 0;
  24754. if (outCycleEndBeat != 0)
  24755. *outCycleEndBeat = 0;
  24756. }
  24757. return noErr;
  24758. }
  24759. static VoidArray activeWindows;
  24760. class AudioUnitPluginWindowCocoa : public AudioProcessorEditor
  24761. {
  24762. public:
  24763. AudioUnitPluginWindowCocoa (AudioUnitPluginInstance& plugin_, const bool createGenericViewIfNeeded)
  24764. : AudioProcessorEditor (&plugin_),
  24765. plugin (plugin_),
  24766. wrapper (0)
  24767. {
  24768. addAndMakeVisible (wrapper = new NSViewComponent());
  24769. activeWindows.add (this);
  24770. setOpaque (true);
  24771. setVisible (true);
  24772. setSize (100, 100);
  24773. createView (createGenericViewIfNeeded);
  24774. }
  24775. ~AudioUnitPluginWindowCocoa()
  24776. {
  24777. const bool wasValid = isValid();
  24778. wrapper->setView (0);
  24779. activeWindows.removeValue (this);
  24780. if (wasValid)
  24781. plugin.editorBeingDeleted (this);
  24782. delete wrapper;
  24783. }
  24784. bool isValid() const { return wrapper->getView() != 0; }
  24785. void paint (Graphics& g)
  24786. {
  24787. g.fillAll (Colours::white);
  24788. }
  24789. void resized()
  24790. {
  24791. wrapper->setSize (getWidth(), getHeight());
  24792. }
  24793. private:
  24794. AudioUnitPluginInstance& plugin;
  24795. NSViewComponent* wrapper;
  24796. bool createView (const bool createGenericViewIfNeeded)
  24797. {
  24798. NSView* pluginView = 0;
  24799. UInt32 dataSize = 0;
  24800. Boolean isWritable = false;
  24801. if (AudioUnitGetPropertyInfo (plugin.audioUnit, kAudioUnitProperty_CocoaUI, kAudioUnitScope_Global,
  24802. 0, &dataSize, &isWritable) == noErr
  24803. && dataSize != 0
  24804. && AudioUnitGetPropertyInfo (plugin.audioUnit, kAudioUnitProperty_CocoaUI, kAudioUnitScope_Global,
  24805. 0, &dataSize, &isWritable) == noErr)
  24806. {
  24807. HeapBlock <AudioUnitCocoaViewInfo> info;
  24808. info.calloc (dataSize, 1);
  24809. if (AudioUnitGetProperty (plugin.audioUnit, kAudioUnitProperty_CocoaUI, kAudioUnitScope_Global,
  24810. 0, info, &dataSize) == noErr)
  24811. {
  24812. NSString* viewClassName = (NSString*) (info->mCocoaAUViewClass[0]);
  24813. NSString* path = (NSString*) CFURLCopyPath (info->mCocoaAUViewBundleLocation);
  24814. NSBundle* viewBundle = [NSBundle bundleWithPath: [path autorelease]];
  24815. Class viewClass = [viewBundle classNamed: viewClassName];
  24816. if ([viewClass conformsToProtocol: @protocol (AUCocoaUIBase)]
  24817. && [viewClass instancesRespondToSelector: @selector (interfaceVersion)]
  24818. && [viewClass instancesRespondToSelector: @selector (uiViewForAudioUnit: withSize:)])
  24819. {
  24820. id factory = [[[viewClass alloc] init] autorelease];
  24821. pluginView = [factory uiViewForAudioUnit: plugin.audioUnit
  24822. withSize: NSMakeSize (getWidth(), getHeight())];
  24823. }
  24824. for (int i = (dataSize - sizeof (CFURLRef)) / sizeof (CFStringRef); --i >= 0;)
  24825. {
  24826. CFRelease (info->mCocoaAUViewClass[i]);
  24827. CFRelease (info->mCocoaAUViewBundleLocation);
  24828. }
  24829. }
  24830. }
  24831. if (createGenericViewIfNeeded && (pluginView == 0))
  24832. pluginView = [[AUGenericView alloc] initWithAudioUnit: plugin.audioUnit];
  24833. wrapper->setView (pluginView);
  24834. if (pluginView != 0)
  24835. setSize ([pluginView frame].size.width,
  24836. [pluginView frame].size.height);
  24837. return pluginView != 0;
  24838. }
  24839. };
  24840. #if JUCE_SUPPORT_CARBON
  24841. class AudioUnitPluginWindowCarbon : public AudioProcessorEditor
  24842. {
  24843. public:
  24844. AudioUnitPluginWindowCarbon (AudioUnitPluginInstance& plugin_)
  24845. : AudioProcessorEditor (&plugin_),
  24846. plugin (plugin_),
  24847. viewComponent (0)
  24848. {
  24849. addAndMakeVisible (innerWrapper = new InnerWrapperComponent (this));
  24850. activeWindows.add (this);
  24851. setOpaque (true);
  24852. setVisible (true);
  24853. setSize (400, 300);
  24854. ComponentDescription viewList [16];
  24855. UInt32 viewListSize = sizeof (viewList);
  24856. AudioUnitGetProperty (plugin.audioUnit, kAudioUnitProperty_GetUIComponentList, kAudioUnitScope_Global,
  24857. 0, &viewList, &viewListSize);
  24858. componentRecord = FindNextComponent (0, &viewList[0]);
  24859. }
  24860. ~AudioUnitPluginWindowCarbon()
  24861. {
  24862. deleteAndZero (innerWrapper);
  24863. activeWindows.removeValue (this);
  24864. if (isValid())
  24865. plugin.editorBeingDeleted (this);
  24866. }
  24867. bool isValid() const throw() { return componentRecord != 0; }
  24868. void paint (Graphics& g)
  24869. {
  24870. g.fillAll (Colours::black);
  24871. }
  24872. void resized()
  24873. {
  24874. innerWrapper->setSize (getWidth(), getHeight());
  24875. }
  24876. bool keyStateChanged (const bool)
  24877. {
  24878. return false;
  24879. }
  24880. bool keyPressed (const KeyPress&)
  24881. {
  24882. return false;
  24883. }
  24884. void broughtToFront()
  24885. {
  24886. activeWindows.removeValue (this);
  24887. activeWindows.add (this);
  24888. }
  24889. AudioUnit getAudioUnit() const { return plugin.audioUnit; }
  24890. AudioUnitCarbonView getViewComponent()
  24891. {
  24892. if (viewComponent == 0 && componentRecord != 0)
  24893. viewComponent = (AudioUnitCarbonView) OpenComponent (componentRecord);
  24894. return viewComponent;
  24895. }
  24896. void closeViewComponent()
  24897. {
  24898. if (viewComponent != 0)
  24899. {
  24900. CloseComponent (viewComponent);
  24901. viewComponent = 0;
  24902. }
  24903. }
  24904. juce_UseDebuggingNewOperator
  24905. private:
  24906. AudioUnitPluginInstance& plugin;
  24907. ComponentRecord* componentRecord;
  24908. AudioUnitCarbonView viewComponent;
  24909. class InnerWrapperComponent : public CarbonViewWrapperComponent
  24910. {
  24911. public:
  24912. InnerWrapperComponent (AudioUnitPluginWindowCarbon* const owner_)
  24913. : owner (owner_)
  24914. {
  24915. }
  24916. ~InnerWrapperComponent()
  24917. {
  24918. deleteWindow();
  24919. }
  24920. HIViewRef attachView (WindowRef windowRef, HIViewRef rootView)
  24921. {
  24922. log (T("Opening AU GUI: ") + owner->plugin.getName());
  24923. AudioUnitCarbonView viewComponent = owner->getViewComponent();
  24924. if (viewComponent == 0)
  24925. return 0;
  24926. Float32Point pos = { 0, 0 };
  24927. Float32Point size = { 250, 200 };
  24928. HIViewRef pluginView = 0;
  24929. AudioUnitCarbonViewCreate (viewComponent,
  24930. owner->getAudioUnit(),
  24931. windowRef,
  24932. rootView,
  24933. &pos,
  24934. &size,
  24935. (ControlRef*) &pluginView);
  24936. return pluginView;
  24937. }
  24938. void removeView (HIViewRef)
  24939. {
  24940. log (T("Closing AU GUI: ") + owner->plugin.getName());
  24941. owner->closeViewComponent();
  24942. }
  24943. private:
  24944. AudioUnitPluginWindowCarbon* const owner;
  24945. };
  24946. friend class InnerWrapperComponent;
  24947. InnerWrapperComponent* innerWrapper;
  24948. };
  24949. #endif
  24950. AudioProcessorEditor* AudioUnitPluginInstance::createEditor()
  24951. {
  24952. ScopedPointer <AudioProcessorEditor> w (new AudioUnitPluginWindowCocoa (*this, false));
  24953. if (! ((AudioUnitPluginWindowCocoa*) w)->isValid())
  24954. w = 0;
  24955. #if JUCE_SUPPORT_CARBON
  24956. if (w == 0)
  24957. {
  24958. w = new AudioUnitPluginWindowCarbon (*this);
  24959. if (! ((AudioUnitPluginWindowCarbon*) w)->isValid())
  24960. w = 0;
  24961. }
  24962. #endif
  24963. if (w == 0)
  24964. w = new AudioUnitPluginWindowCocoa (*this, true); // use AUGenericView as a fallback
  24965. return w.release();
  24966. }
  24967. const String AudioUnitPluginInstance::getCategory() const
  24968. {
  24969. const char* result = 0;
  24970. switch (componentDesc.componentType)
  24971. {
  24972. case kAudioUnitType_Effect:
  24973. case kAudioUnitType_MusicEffect:
  24974. result = "Effect";
  24975. break;
  24976. case kAudioUnitType_MusicDevice:
  24977. result = "Synth";
  24978. break;
  24979. case kAudioUnitType_Generator:
  24980. result = "Generator";
  24981. break;
  24982. case kAudioUnitType_Panner:
  24983. result = "Panner";
  24984. break;
  24985. default:
  24986. break;
  24987. }
  24988. return result;
  24989. }
  24990. int AudioUnitPluginInstance::getNumParameters()
  24991. {
  24992. return parameterIds.size();
  24993. }
  24994. float AudioUnitPluginInstance::getParameter (int index)
  24995. {
  24996. const ScopedLock sl (lock);
  24997. Float32 value = 0.0f;
  24998. if (audioUnit != 0 && ((unsigned int) index) < (unsigned int) parameterIds.size())
  24999. {
  25000. AudioUnitGetParameter (audioUnit,
  25001. (UInt32) parameterIds.getUnchecked (index),
  25002. kAudioUnitScope_Global, 0,
  25003. &value);
  25004. }
  25005. return value;
  25006. }
  25007. void AudioUnitPluginInstance::setParameter (int index, float newValue)
  25008. {
  25009. const ScopedLock sl (lock);
  25010. if (audioUnit != 0 && ((unsigned int) index) < (unsigned int) parameterIds.size())
  25011. {
  25012. AudioUnitSetParameter (audioUnit,
  25013. (UInt32) parameterIds.getUnchecked (index),
  25014. kAudioUnitScope_Global, 0,
  25015. newValue, 0);
  25016. }
  25017. }
  25018. const String AudioUnitPluginInstance::getParameterName (int index)
  25019. {
  25020. AudioUnitParameterInfo info;
  25021. zerostruct (info);
  25022. UInt32 sz = sizeof (info);
  25023. String name;
  25024. if (AudioUnitGetProperty (audioUnit,
  25025. kAudioUnitProperty_ParameterInfo,
  25026. kAudioUnitScope_Global,
  25027. parameterIds [index], &info, &sz) == noErr)
  25028. {
  25029. if ((info.flags & kAudioUnitParameterFlag_HasCFNameString) != 0)
  25030. name = PlatformUtilities::cfStringToJuceString (info.cfNameString);
  25031. else
  25032. name = String (info.name, sizeof (info.name));
  25033. }
  25034. return name;
  25035. }
  25036. const String AudioUnitPluginInstance::getParameterText (int index)
  25037. {
  25038. return String (getParameter (index));
  25039. }
  25040. bool AudioUnitPluginInstance::isParameterAutomatable (int index) const
  25041. {
  25042. AudioUnitParameterInfo info;
  25043. UInt32 sz = sizeof (info);
  25044. if (AudioUnitGetProperty (audioUnit,
  25045. kAudioUnitProperty_ParameterInfo,
  25046. kAudioUnitScope_Global,
  25047. parameterIds [index], &info, &sz) == noErr)
  25048. {
  25049. return (info.flags & kAudioUnitParameterFlag_NonRealTime) == 0;
  25050. }
  25051. return true;
  25052. }
  25053. int AudioUnitPluginInstance::getNumPrograms()
  25054. {
  25055. CFArrayRef presets;
  25056. UInt32 sz = sizeof (CFArrayRef);
  25057. int num = 0;
  25058. if (AudioUnitGetProperty (audioUnit,
  25059. kAudioUnitProperty_FactoryPresets,
  25060. kAudioUnitScope_Global,
  25061. 0, &presets, &sz) == noErr)
  25062. {
  25063. num = (int) CFArrayGetCount (presets);
  25064. CFRelease (presets);
  25065. }
  25066. return num;
  25067. }
  25068. int AudioUnitPluginInstance::getCurrentProgram()
  25069. {
  25070. AUPreset current;
  25071. current.presetNumber = 0;
  25072. UInt32 sz = sizeof (AUPreset);
  25073. AudioUnitGetProperty (audioUnit,
  25074. kAudioUnitProperty_FactoryPresets,
  25075. kAudioUnitScope_Global,
  25076. 0, &current, &sz);
  25077. return current.presetNumber;
  25078. }
  25079. void AudioUnitPluginInstance::setCurrentProgram (int newIndex)
  25080. {
  25081. AUPreset current;
  25082. current.presetNumber = newIndex;
  25083. current.presetName = 0;
  25084. AudioUnitSetProperty (audioUnit,
  25085. kAudioUnitProperty_FactoryPresets,
  25086. kAudioUnitScope_Global,
  25087. 0, &current, sizeof (AUPreset));
  25088. }
  25089. const String AudioUnitPluginInstance::getProgramName (int index)
  25090. {
  25091. String s;
  25092. CFArrayRef presets;
  25093. UInt32 sz = sizeof (CFArrayRef);
  25094. if (AudioUnitGetProperty (audioUnit,
  25095. kAudioUnitProperty_FactoryPresets,
  25096. kAudioUnitScope_Global,
  25097. 0, &presets, &sz) == noErr)
  25098. {
  25099. for (CFIndex i = 0; i < CFArrayGetCount (presets); ++i)
  25100. {
  25101. const AUPreset* p = (const AUPreset*) CFArrayGetValueAtIndex (presets, i);
  25102. if (p != 0 && p->presetNumber == index)
  25103. {
  25104. s = PlatformUtilities::cfStringToJuceString (p->presetName);
  25105. break;
  25106. }
  25107. }
  25108. CFRelease (presets);
  25109. }
  25110. return s;
  25111. }
  25112. void AudioUnitPluginInstance::changeProgramName (int index, const String& newName)
  25113. {
  25114. jassertfalse // xxx not implemented!
  25115. }
  25116. const String AudioUnitPluginInstance::getInputChannelName (const int index) const
  25117. {
  25118. if (((unsigned int) index) < (unsigned int) getNumInputChannels())
  25119. return T("Input ") + String (index + 1);
  25120. return String::empty;
  25121. }
  25122. bool AudioUnitPluginInstance::isInputChannelStereoPair (int index) const
  25123. {
  25124. if (((unsigned int) index) >= (unsigned int) getNumInputChannels())
  25125. return false;
  25126. return true;
  25127. }
  25128. const String AudioUnitPluginInstance::getOutputChannelName (const int index) const
  25129. {
  25130. if (((unsigned int) index) < (unsigned int) getNumOutputChannels())
  25131. return T("Output ") + String (index + 1);
  25132. return String::empty;
  25133. }
  25134. bool AudioUnitPluginInstance::isOutputChannelStereoPair (int index) const
  25135. {
  25136. if (((unsigned int) index) >= (unsigned int) getNumOutputChannels())
  25137. return false;
  25138. return true;
  25139. }
  25140. void AudioUnitPluginInstance::getStateInformation (MemoryBlock& destData)
  25141. {
  25142. getCurrentProgramStateInformation (destData);
  25143. }
  25144. void AudioUnitPluginInstance::getCurrentProgramStateInformation (MemoryBlock& destData)
  25145. {
  25146. CFPropertyListRef propertyList = 0;
  25147. UInt32 sz = sizeof (CFPropertyListRef);
  25148. if (AudioUnitGetProperty (audioUnit,
  25149. kAudioUnitProperty_ClassInfo,
  25150. kAudioUnitScope_Global,
  25151. 0, &propertyList, &sz) == noErr)
  25152. {
  25153. CFWriteStreamRef stream = CFWriteStreamCreateWithAllocatedBuffers (kCFAllocatorDefault, kCFAllocatorDefault);
  25154. CFWriteStreamOpen (stream);
  25155. CFIndex bytesWritten = CFPropertyListWriteToStream (propertyList, stream, kCFPropertyListBinaryFormat_v1_0, 0);
  25156. CFWriteStreamClose (stream);
  25157. CFDataRef data = (CFDataRef) CFWriteStreamCopyProperty (stream, kCFStreamPropertyDataWritten);
  25158. destData.setSize (bytesWritten);
  25159. destData.copyFrom (CFDataGetBytePtr (data), 0, destData.getSize());
  25160. CFRelease (data);
  25161. CFRelease (stream);
  25162. CFRelease (propertyList);
  25163. }
  25164. }
  25165. void AudioUnitPluginInstance::setStateInformation (const void* data, int sizeInBytes)
  25166. {
  25167. setCurrentProgramStateInformation (data, sizeInBytes);
  25168. }
  25169. void AudioUnitPluginInstance::setCurrentProgramStateInformation (const void* data, int sizeInBytes)
  25170. {
  25171. CFReadStreamRef stream = CFReadStreamCreateWithBytesNoCopy (kCFAllocatorDefault,
  25172. (const UInt8*) data,
  25173. sizeInBytes,
  25174. kCFAllocatorNull);
  25175. CFReadStreamOpen (stream);
  25176. CFPropertyListFormat format = kCFPropertyListBinaryFormat_v1_0;
  25177. CFPropertyListRef propertyList = CFPropertyListCreateFromStream (kCFAllocatorDefault,
  25178. stream,
  25179. 0,
  25180. kCFPropertyListImmutable,
  25181. &format,
  25182. 0);
  25183. CFRelease (stream);
  25184. if (propertyList != 0)
  25185. AudioUnitSetProperty (audioUnit,
  25186. kAudioUnitProperty_ClassInfo,
  25187. kAudioUnitScope_Global,
  25188. 0, &propertyList, sizeof (propertyList));
  25189. }
  25190. AudioUnitPluginFormat::AudioUnitPluginFormat()
  25191. {
  25192. }
  25193. AudioUnitPluginFormat::~AudioUnitPluginFormat()
  25194. {
  25195. }
  25196. void AudioUnitPluginFormat::findAllTypesForFile (OwnedArray <PluginDescription>& results,
  25197. const String& fileOrIdentifier)
  25198. {
  25199. if (! fileMightContainThisPluginType (fileOrIdentifier))
  25200. return;
  25201. PluginDescription desc;
  25202. desc.fileOrIdentifier = fileOrIdentifier;
  25203. desc.uid = 0;
  25204. try
  25205. {
  25206. ScopedPointer <AudioPluginInstance> createdInstance (createInstanceFromDescription (desc));
  25207. AudioUnitPluginInstance* const auInstance = dynamic_cast <AudioUnitPluginInstance*> ((AudioPluginInstance*) createdInstance);
  25208. if (auInstance != 0)
  25209. {
  25210. auInstance->fillInPluginDescription (desc);
  25211. results.add (new PluginDescription (desc));
  25212. }
  25213. }
  25214. catch (...)
  25215. {
  25216. // crashed while loading...
  25217. }
  25218. }
  25219. AudioPluginInstance* AudioUnitPluginFormat::createInstanceFromDescription (const PluginDescription& desc)
  25220. {
  25221. if (fileMightContainThisPluginType (desc.fileOrIdentifier))
  25222. {
  25223. ScopedPointer <AudioUnitPluginInstance> result (new AudioUnitPluginInstance (desc.fileOrIdentifier));
  25224. if (result->audioUnit != 0)
  25225. {
  25226. result->initialise();
  25227. return result.release();
  25228. }
  25229. }
  25230. return 0;
  25231. }
  25232. const StringArray AudioUnitPluginFormat::searchPathsForPlugins (const FileSearchPath& /*directoriesToSearch*/,
  25233. const bool /*recursive*/)
  25234. {
  25235. StringArray result;
  25236. ComponentRecord* comp = 0;
  25237. ComponentDescription desc;
  25238. zerostruct (desc);
  25239. for (;;)
  25240. {
  25241. zerostruct (desc);
  25242. comp = FindNextComponent (comp, &desc);
  25243. if (comp == 0)
  25244. break;
  25245. GetComponentInfo (comp, &desc, 0, 0, 0);
  25246. if (desc.componentType == kAudioUnitType_MusicDevice
  25247. || desc.componentType == kAudioUnitType_MusicEffect
  25248. || desc.componentType == kAudioUnitType_Effect
  25249. || desc.componentType == kAudioUnitType_Generator
  25250. || desc.componentType == kAudioUnitType_Panner)
  25251. {
  25252. const String s (createAUPluginIdentifier (desc));
  25253. DBG (s);
  25254. result.add (s);
  25255. }
  25256. }
  25257. return result;
  25258. }
  25259. bool AudioUnitPluginFormat::fileMightContainThisPluginType (const String& fileOrIdentifier)
  25260. {
  25261. ComponentDescription desc;
  25262. String name, version, manufacturer;
  25263. if (getComponentDescFromIdentifier (fileOrIdentifier, desc, name, version, manufacturer))
  25264. return FindNextComponent (0, &desc) != 0;
  25265. const File f (fileOrIdentifier);
  25266. return f.hasFileExtension (T(".component"))
  25267. && f.isDirectory();
  25268. }
  25269. const String AudioUnitPluginFormat::getNameOfPluginFromIdentifier (const String& fileOrIdentifier)
  25270. {
  25271. ComponentDescription desc;
  25272. String name, version, manufacturer;
  25273. getComponentDescFromIdentifier (fileOrIdentifier, desc, name, version, manufacturer);
  25274. if (name.isEmpty())
  25275. name = fileOrIdentifier;
  25276. return name;
  25277. }
  25278. bool AudioUnitPluginFormat::doesPluginStillExist (const PluginDescription& desc)
  25279. {
  25280. if (desc.fileOrIdentifier.startsWithIgnoreCase (auIdentifierPrefix))
  25281. return fileMightContainThisPluginType (desc.fileOrIdentifier);
  25282. else
  25283. return File (desc.fileOrIdentifier).exists();
  25284. }
  25285. const FileSearchPath AudioUnitPluginFormat::getDefaultLocationsToSearch()
  25286. {
  25287. return FileSearchPath ("/(Default AudioUnit locations)");
  25288. }
  25289. #endif
  25290. END_JUCE_NAMESPACE
  25291. #undef log
  25292. #endif
  25293. /********* End of inlined file: juce_AudioUnitPluginFormat.mm *********/
  25294. /********* Start of inlined file: juce_VSTPluginFormat.mm *********/
  25295. // This file just wraps juce_VSTPluginFormat.cpp in an objective-C wrapper
  25296. #define JUCE_MAC_VST_INCLUDED 1
  25297. /********* Start of inlined file: juce_VSTPluginFormat.cpp *********/
  25298. #if JUCE_PLUGINHOST_VST
  25299. #if (defined (_WIN32) || defined (_WIN64))
  25300. #undef _WIN32_WINNT
  25301. #define _WIN32_WINNT 0x500
  25302. #undef STRICT
  25303. #define STRICT
  25304. #include <windows.h>
  25305. #include <float.h>
  25306. #pragma warning (disable : 4312 4355)
  25307. #elif defined (LINUX) || defined (__linux__)
  25308. #include <float.h>
  25309. #include <sys/time.h>
  25310. #include <X11/Xlib.h>
  25311. #include <X11/Xutil.h>
  25312. #include <X11/Xatom.h>
  25313. #undef Font
  25314. #undef KeyPress
  25315. #undef Drawable
  25316. #undef Time
  25317. #else
  25318. #ifndef JUCE_MAC_VST_INCLUDED
  25319. // On the mac, this file needs to be compiled indirectly, by using
  25320. // juce_VSTPluginFormat.mm instead - that wraps it as an objective-C file for cocoa
  25321. #error
  25322. #endif
  25323. #include <Cocoa/Cocoa.h>
  25324. #include <Carbon/Carbon.h>
  25325. #endif
  25326. #if ! (JUCE_MAC && JUCE_64BIT)
  25327. BEGIN_JUCE_NAMESPACE
  25328. #if JUCE_MAC && JUCE_SUPPORT_CARBON
  25329. #endif
  25330. #undef PRAGMA_ALIGN_SUPPORTED
  25331. #define VST_FORCE_DEPRECATED 0
  25332. #ifdef _MSC_VER
  25333. #pragma warning (push)
  25334. #pragma warning (disable: 4996)
  25335. #endif
  25336. #include "pluginterfaces/vst2.x/aeffectx.h"
  25337. #ifdef _MSC_VER
  25338. #pragma warning (pop)
  25339. #endif
  25340. #if JUCE_LINUX
  25341. #define Font JUCE_NAMESPACE::Font
  25342. #define KeyPress JUCE_NAMESPACE::KeyPress
  25343. #define Drawable JUCE_NAMESPACE::Drawable
  25344. #define Time JUCE_NAMESPACE::Time
  25345. #endif
  25346. /********* Start of inlined file: juce_VSTMidiEventList.h *********/
  25347. #ifdef __aeffect__
  25348. #ifndef __JUCE_VSTMIDIEVENTLIST_JUCEHEADER__
  25349. #define __JUCE_VSTMIDIEVENTLIST_JUCEHEADER__
  25350. class VSTMidiEventList
  25351. {
  25352. public:
  25353. VSTMidiEventList()
  25354. : numEventsUsed (0), numEventsAllocated (0)
  25355. {
  25356. }
  25357. ~VSTMidiEventList()
  25358. {
  25359. freeEvents();
  25360. }
  25361. void clear()
  25362. {
  25363. numEventsUsed = 0;
  25364. if (events != 0)
  25365. events->numEvents = 0;
  25366. }
  25367. void addEvent (const void* const midiData, const int numBytes, const int frameOffset)
  25368. {
  25369. ensureSize (numEventsUsed + 1);
  25370. VstMidiEvent* const e = (VstMidiEvent*) (events->events [numEventsUsed]);
  25371. events->numEvents = ++numEventsUsed;
  25372. if (numBytes <= 4)
  25373. {
  25374. if (e->type == kVstSysExType)
  25375. {
  25376. juce_free (((VstMidiSysexEvent*) e)->sysexDump);
  25377. e->type = kVstMidiType;
  25378. e->byteSize = sizeof (VstMidiEvent);
  25379. e->noteLength = 0;
  25380. e->noteOffset = 0;
  25381. e->detune = 0;
  25382. e->noteOffVelocity = 0;
  25383. }
  25384. e->deltaFrames = frameOffset;
  25385. memcpy (e->midiData, midiData, numBytes);
  25386. }
  25387. else
  25388. {
  25389. VstMidiSysexEvent* const se = (VstMidiSysexEvent*) e;
  25390. if (se->type == kVstSysExType)
  25391. se->sysexDump = (char*) juce_realloc (se->sysexDump, numBytes);
  25392. else
  25393. se->sysexDump = (char*) juce_malloc (numBytes);
  25394. memcpy (se->sysexDump, midiData, numBytes);
  25395. se->type = kVstSysExType;
  25396. se->byteSize = sizeof (VstMidiSysexEvent);
  25397. se->deltaFrames = frameOffset;
  25398. se->flags = 0;
  25399. se->dumpBytes = numBytes;
  25400. se->resvd1 = 0;
  25401. se->resvd2 = 0;
  25402. }
  25403. }
  25404. // Handy method to pull the events out of an event buffer supplied by the host
  25405. // or plugin.
  25406. static void addEventsToMidiBuffer (const VstEvents* events, MidiBuffer& dest)
  25407. {
  25408. for (int i = 0; i < events->numEvents; ++i)
  25409. {
  25410. const VstEvent* const e = events->events[i];
  25411. if (e != 0)
  25412. {
  25413. if (e->type == kVstMidiType)
  25414. {
  25415. dest.addEvent ((const JUCE_NAMESPACE::uint8*) ((const VstMidiEvent*) e)->midiData,
  25416. 4, e->deltaFrames);
  25417. }
  25418. else if (e->type == kVstSysExType)
  25419. {
  25420. dest.addEvent ((const JUCE_NAMESPACE::uint8*) ((const VstMidiSysexEvent*) e)->sysexDump,
  25421. (int) ((const VstMidiSysexEvent*) e)->dumpBytes,
  25422. e->deltaFrames);
  25423. }
  25424. }
  25425. }
  25426. }
  25427. void ensureSize (int numEventsNeeded)
  25428. {
  25429. if (numEventsNeeded > numEventsAllocated)
  25430. {
  25431. numEventsNeeded = (numEventsNeeded + 32) & ~31;
  25432. const int size = 20 + sizeof (VstEvent*) * numEventsNeeded;
  25433. if (events == 0)
  25434. events.calloc (size, 1);
  25435. else
  25436. events.realloc (size, 1);
  25437. for (int i = numEventsAllocated; i < numEventsNeeded; ++i)
  25438. {
  25439. VstMidiEvent* const e = (VstMidiEvent*) juce_calloc (jmax ((int) sizeof (VstMidiEvent),
  25440. (int) sizeof (VstMidiSysexEvent)));
  25441. e->type = kVstMidiType;
  25442. e->byteSize = sizeof (VstMidiEvent);
  25443. events->events[i] = (VstEvent*) e;
  25444. }
  25445. numEventsAllocated = numEventsNeeded;
  25446. }
  25447. }
  25448. void freeEvents()
  25449. {
  25450. if (events != 0)
  25451. {
  25452. for (int i = numEventsAllocated; --i >= 0;)
  25453. {
  25454. VstMidiEvent* const e = (VstMidiEvent*) (events->events[i]);
  25455. if (e->type == kVstSysExType)
  25456. juce_free (((VstMidiSysexEvent*) e)->sysexDump);
  25457. juce_free (e);
  25458. }
  25459. events.free();
  25460. numEventsUsed = 0;
  25461. numEventsAllocated = 0;
  25462. }
  25463. }
  25464. HeapBlock <VstEvents> events;
  25465. private:
  25466. int numEventsUsed, numEventsAllocated;
  25467. };
  25468. #endif // __JUCE_VSTMIDIEVENTLIST_JUCEHEADER__
  25469. #endif // __JUCE_VSTMIDIEVENTLIST_JUCEHEADER__
  25470. /********* End of inlined file: juce_VSTMidiEventList.h *********/
  25471. #if ! JUCE_WIN32
  25472. #define _fpreset()
  25473. #define _clearfp()
  25474. #endif
  25475. extern void juce_callAnyTimersSynchronously();
  25476. const int fxbVersionNum = 1;
  25477. struct fxProgram
  25478. {
  25479. long chunkMagic; // 'CcnK'
  25480. long byteSize; // of this chunk, excl. magic + byteSize
  25481. long fxMagic; // 'FxCk'
  25482. long version;
  25483. long fxID; // fx unique id
  25484. long fxVersion;
  25485. long numParams;
  25486. char prgName[28];
  25487. float params[1]; // variable no. of parameters
  25488. };
  25489. struct fxSet
  25490. {
  25491. long chunkMagic; // 'CcnK'
  25492. long byteSize; // of this chunk, excl. magic + byteSize
  25493. long fxMagic; // 'FxBk'
  25494. long version;
  25495. long fxID; // fx unique id
  25496. long fxVersion;
  25497. long numPrograms;
  25498. char future[128];
  25499. fxProgram programs[1]; // variable no. of programs
  25500. };
  25501. struct fxChunkSet
  25502. {
  25503. long chunkMagic; // 'CcnK'
  25504. long byteSize; // of this chunk, excl. magic + byteSize
  25505. long fxMagic; // 'FxCh', 'FPCh', or 'FBCh'
  25506. long version;
  25507. long fxID; // fx unique id
  25508. long fxVersion;
  25509. long numPrograms;
  25510. char future[128];
  25511. long chunkSize;
  25512. char chunk[8]; // variable
  25513. };
  25514. struct fxProgramSet
  25515. {
  25516. long chunkMagic; // 'CcnK'
  25517. long byteSize; // of this chunk, excl. magic + byteSize
  25518. long fxMagic; // 'FxCh', 'FPCh', or 'FBCh'
  25519. long version;
  25520. long fxID; // fx unique id
  25521. long fxVersion;
  25522. long numPrograms;
  25523. char name[28];
  25524. long chunkSize;
  25525. char chunk[8]; // variable
  25526. };
  25527. static long vst_swap (const long x) throw()
  25528. {
  25529. #ifdef JUCE_LITTLE_ENDIAN
  25530. return (long) ByteOrder::swap ((uint32) x);
  25531. #else
  25532. return x;
  25533. #endif
  25534. }
  25535. static float vst_swapFloat (const float x) throw()
  25536. {
  25537. #ifdef JUCE_LITTLE_ENDIAN
  25538. union { uint32 asInt; float asFloat; } n;
  25539. n.asFloat = x;
  25540. n.asInt = ByteOrder::swap (n.asInt);
  25541. return n.asFloat;
  25542. #else
  25543. return x;
  25544. #endif
  25545. }
  25546. typedef AEffect* (*MainCall) (audioMasterCallback);
  25547. static VstIntPtr VSTCALLBACK audioMaster (AEffect* effect, VstInt32 opcode, VstInt32 index, VstIntPtr value, void* ptr, float opt);
  25548. static int shellUIDToCreate = 0;
  25549. static int insideVSTCallback = 0;
  25550. class VSTPluginWindow;
  25551. // Change this to disable logging of various VST activities
  25552. #ifndef VST_LOGGING
  25553. #define VST_LOGGING 1
  25554. #endif
  25555. #if VST_LOGGING
  25556. #define log(a) Logger::writeToLog(a);
  25557. #else
  25558. #define log(a)
  25559. #endif
  25560. #if JUCE_MAC && JUCE_PPC
  25561. static void* NewCFMFromMachO (void* const machofp) throw()
  25562. {
  25563. void* result = juce_malloc (8);
  25564. ((void**) result)[0] = machofp;
  25565. ((void**) result)[1] = result;
  25566. return result;
  25567. }
  25568. #endif
  25569. #if JUCE_LINUX
  25570. extern Display* display;
  25571. extern XContext improbableNumber;
  25572. typedef void (*EventProcPtr) (XEvent* ev);
  25573. static bool xErrorTriggered;
  25574. static int temporaryErrorHandler (Display*, XErrorEvent*)
  25575. {
  25576. xErrorTriggered = true;
  25577. return 0;
  25578. }
  25579. static int getPropertyFromXWindow (Window handle, Atom atom)
  25580. {
  25581. XErrorHandler oldErrorHandler = XSetErrorHandler (temporaryErrorHandler);
  25582. xErrorTriggered = false;
  25583. int userSize;
  25584. unsigned long bytes, userCount;
  25585. unsigned char* data;
  25586. Atom userType;
  25587. XGetWindowProperty (display, handle, atom, 0, 1, false, AnyPropertyType,
  25588. &userType, &userSize, &userCount, &bytes, &data);
  25589. XSetErrorHandler (oldErrorHandler);
  25590. return (userCount == 1 && ! xErrorTriggered) ? *(int*) data
  25591. : 0;
  25592. }
  25593. static Window getChildWindow (Window windowToCheck)
  25594. {
  25595. Window rootWindow, parentWindow;
  25596. Window* childWindows;
  25597. unsigned int numChildren;
  25598. XQueryTree (display,
  25599. windowToCheck,
  25600. &rootWindow,
  25601. &parentWindow,
  25602. &childWindows,
  25603. &numChildren);
  25604. if (numChildren > 0)
  25605. return childWindows [0];
  25606. return 0;
  25607. }
  25608. static void translateJuceToXButtonModifiers (const MouseEvent& e, XEvent& ev) throw()
  25609. {
  25610. if (e.mods.isLeftButtonDown())
  25611. {
  25612. ev.xbutton.button = Button1;
  25613. ev.xbutton.state |= Button1Mask;
  25614. }
  25615. else if (e.mods.isRightButtonDown())
  25616. {
  25617. ev.xbutton.button = Button3;
  25618. ev.xbutton.state |= Button3Mask;
  25619. }
  25620. else if (e.mods.isMiddleButtonDown())
  25621. {
  25622. ev.xbutton.button = Button2;
  25623. ev.xbutton.state |= Button2Mask;
  25624. }
  25625. }
  25626. static void translateJuceToXMotionModifiers (const MouseEvent& e, XEvent& ev) throw()
  25627. {
  25628. if (e.mods.isLeftButtonDown())
  25629. ev.xmotion.state |= Button1Mask;
  25630. else if (e.mods.isRightButtonDown())
  25631. ev.xmotion.state |= Button3Mask;
  25632. else if (e.mods.isMiddleButtonDown())
  25633. ev.xmotion.state |= Button2Mask;
  25634. }
  25635. static void translateJuceToXCrossingModifiers (const MouseEvent& e, XEvent& ev) throw()
  25636. {
  25637. if (e.mods.isLeftButtonDown())
  25638. ev.xcrossing.state |= Button1Mask;
  25639. else if (e.mods.isRightButtonDown())
  25640. ev.xcrossing.state |= Button3Mask;
  25641. else if (e.mods.isMiddleButtonDown())
  25642. ev.xcrossing.state |= Button2Mask;
  25643. }
  25644. static void translateJuceToXMouseWheelModifiers (const MouseEvent& e, const float increment, XEvent& ev) throw()
  25645. {
  25646. if (increment < 0)
  25647. {
  25648. ev.xbutton.button = Button5;
  25649. ev.xbutton.state |= Button5Mask;
  25650. }
  25651. else if (increment > 0)
  25652. {
  25653. ev.xbutton.button = Button4;
  25654. ev.xbutton.state |= Button4Mask;
  25655. }
  25656. }
  25657. #endif
  25658. static VoidArray activeModules;
  25659. class ModuleHandle : public ReferenceCountedObject
  25660. {
  25661. public:
  25662. File file;
  25663. MainCall moduleMain;
  25664. String pluginName;
  25665. static ModuleHandle* findOrCreateModule (const File& file)
  25666. {
  25667. for (int i = activeModules.size(); --i >= 0;)
  25668. {
  25669. ModuleHandle* const module = (ModuleHandle*) activeModules.getUnchecked(i);
  25670. if (module->file == file)
  25671. return module;
  25672. }
  25673. _fpreset(); // (doesn't do any harm)
  25674. ++insideVSTCallback;
  25675. shellUIDToCreate = 0;
  25676. log ("Attempting to load VST: " + file.getFullPathName());
  25677. ScopedPointer <ModuleHandle> m (new ModuleHandle (file));
  25678. if (! m->open())
  25679. m = 0;
  25680. --insideVSTCallback;
  25681. _fpreset(); // (doesn't do any harm)
  25682. return m.release();
  25683. }
  25684. ModuleHandle (const File& file_)
  25685. : file (file_),
  25686. moduleMain (0),
  25687. #if JUCE_WIN32 || JUCE_LINUX
  25688. hModule (0)
  25689. #elif JUCE_MAC
  25690. fragId (0),
  25691. resHandle (0),
  25692. bundleRef (0),
  25693. resFileId (0)
  25694. #endif
  25695. {
  25696. activeModules.add (this);
  25697. #if JUCE_WIN32 || JUCE_LINUX
  25698. fullParentDirectoryPathName = file_.getParentDirectory().getFullPathName();
  25699. #elif JUCE_MAC
  25700. FSRef ref;
  25701. PlatformUtilities::makeFSRefFromPath (&ref, file_.getParentDirectory().getFullPathName());
  25702. FSGetCatalogInfo (&ref, kFSCatInfoNone, 0, 0, &parentDirFSSpec, 0);
  25703. #endif
  25704. }
  25705. ~ModuleHandle()
  25706. {
  25707. activeModules.removeValue (this);
  25708. close();
  25709. }
  25710. juce_UseDebuggingNewOperator
  25711. #if JUCE_WIN32 || JUCE_LINUX
  25712. void* hModule;
  25713. String fullParentDirectoryPathName;
  25714. bool open()
  25715. {
  25716. #if JUCE_WIN32
  25717. static bool timePeriodSet = false;
  25718. if (! timePeriodSet)
  25719. {
  25720. timePeriodSet = true;
  25721. timeBeginPeriod (2);
  25722. }
  25723. #endif
  25724. pluginName = file.getFileNameWithoutExtension();
  25725. hModule = PlatformUtilities::loadDynamicLibrary (file.getFullPathName());
  25726. moduleMain = (MainCall) PlatformUtilities::getProcedureEntryPoint (hModule, "VSTPluginMain");
  25727. if (moduleMain == 0)
  25728. moduleMain = (MainCall) PlatformUtilities::getProcedureEntryPoint (hModule, "main");
  25729. return moduleMain != 0;
  25730. }
  25731. void close()
  25732. {
  25733. _fpreset(); // (doesn't do any harm)
  25734. PlatformUtilities::freeDynamicLibrary (hModule);
  25735. }
  25736. void closeEffect (AEffect* eff)
  25737. {
  25738. eff->dispatcher (eff, effClose, 0, 0, 0, 0);
  25739. }
  25740. #else
  25741. CFragConnectionID fragId;
  25742. Handle resHandle;
  25743. CFBundleRef bundleRef;
  25744. FSSpec parentDirFSSpec;
  25745. short resFileId;
  25746. bool open()
  25747. {
  25748. bool ok = false;
  25749. const String filename (file.getFullPathName());
  25750. if (file.hasFileExtension (T(".vst")))
  25751. {
  25752. const char* const utf8 = filename.toUTF8();
  25753. CFURLRef url = CFURLCreateFromFileSystemRepresentation (0, (const UInt8*) utf8,
  25754. strlen (utf8), file.isDirectory());
  25755. if (url != 0)
  25756. {
  25757. bundleRef = CFBundleCreate (kCFAllocatorDefault, url);
  25758. CFRelease (url);
  25759. if (bundleRef != 0)
  25760. {
  25761. if (CFBundleLoadExecutable (bundleRef))
  25762. {
  25763. moduleMain = (MainCall) CFBundleGetFunctionPointerForName (bundleRef, CFSTR("main_macho"));
  25764. if (moduleMain == 0)
  25765. moduleMain = (MainCall) CFBundleGetFunctionPointerForName (bundleRef, CFSTR("VSTPluginMain"));
  25766. if (moduleMain != 0)
  25767. {
  25768. CFTypeRef name = CFBundleGetValueForInfoDictionaryKey (bundleRef, CFSTR("CFBundleName"));
  25769. if (name != 0)
  25770. {
  25771. if (CFGetTypeID (name) == CFStringGetTypeID())
  25772. {
  25773. char buffer[1024];
  25774. if (CFStringGetCString ((CFStringRef) name, buffer, sizeof (buffer), CFStringGetSystemEncoding()))
  25775. pluginName = buffer;
  25776. }
  25777. }
  25778. if (pluginName.isEmpty())
  25779. pluginName = file.getFileNameWithoutExtension();
  25780. resFileId = CFBundleOpenBundleResourceMap (bundleRef);
  25781. ok = true;
  25782. }
  25783. }
  25784. if (! ok)
  25785. {
  25786. CFBundleUnloadExecutable (bundleRef);
  25787. CFRelease (bundleRef);
  25788. bundleRef = 0;
  25789. }
  25790. }
  25791. }
  25792. }
  25793. #if JUCE_PPC
  25794. else
  25795. {
  25796. FSRef fn;
  25797. if (FSPathMakeRef ((UInt8*) (const char*) filename, &fn, 0) == noErr)
  25798. {
  25799. resFileId = FSOpenResFile (&fn, fsRdPerm);
  25800. if (resFileId != -1)
  25801. {
  25802. const int numEffs = Count1Resources ('aEff');
  25803. for (int i = 0; i < numEffs; ++i)
  25804. {
  25805. resHandle = Get1IndResource ('aEff', i + 1);
  25806. if (resHandle != 0)
  25807. {
  25808. OSType type;
  25809. Str255 name;
  25810. SInt16 id;
  25811. GetResInfo (resHandle, &id, &type, name);
  25812. pluginName = String ((const char*) name + 1, name[0]);
  25813. DetachResource (resHandle);
  25814. HLock (resHandle);
  25815. Ptr ptr;
  25816. Str255 errorText;
  25817. OSErr err = GetMemFragment (*resHandle, GetHandleSize (resHandle),
  25818. name, kPrivateCFragCopy,
  25819. &fragId, &ptr, errorText);
  25820. if (err == noErr)
  25821. {
  25822. moduleMain = (MainCall) newMachOFromCFM (ptr);
  25823. ok = true;
  25824. }
  25825. else
  25826. {
  25827. HUnlock (resHandle);
  25828. }
  25829. break;
  25830. }
  25831. }
  25832. if (! ok)
  25833. CloseResFile (resFileId);
  25834. }
  25835. }
  25836. }
  25837. #endif
  25838. return ok;
  25839. }
  25840. void close()
  25841. {
  25842. #if JUCE_PPC
  25843. if (fragId != 0)
  25844. {
  25845. if (moduleMain != 0)
  25846. disposeMachOFromCFM ((void*) moduleMain);
  25847. CloseConnection (&fragId);
  25848. HUnlock (resHandle);
  25849. if (resFileId != 0)
  25850. CloseResFile (resFileId);
  25851. }
  25852. else
  25853. #endif
  25854. if (bundleRef != 0)
  25855. {
  25856. CFBundleCloseBundleResourceMap (bundleRef, resFileId);
  25857. if (CFGetRetainCount (bundleRef) == 1)
  25858. CFBundleUnloadExecutable (bundleRef);
  25859. if (CFGetRetainCount (bundleRef) > 0)
  25860. CFRelease (bundleRef);
  25861. }
  25862. }
  25863. void closeEffect (AEffect* eff)
  25864. {
  25865. #if JUCE_PPC
  25866. if (fragId != 0)
  25867. {
  25868. VoidArray thingsToDelete;
  25869. thingsToDelete.add ((void*) eff->dispatcher);
  25870. thingsToDelete.add ((void*) eff->process);
  25871. thingsToDelete.add ((void*) eff->setParameter);
  25872. thingsToDelete.add ((void*) eff->getParameter);
  25873. thingsToDelete.add ((void*) eff->processReplacing);
  25874. eff->dispatcher (eff, effClose, 0, 0, 0, 0);
  25875. for (int i = thingsToDelete.size(); --i >= 0;)
  25876. disposeMachOFromCFM (thingsToDelete[i]);
  25877. }
  25878. else
  25879. #endif
  25880. {
  25881. eff->dispatcher (eff, effClose, 0, 0, 0, 0);
  25882. }
  25883. }
  25884. #if JUCE_PPC
  25885. static void* newMachOFromCFM (void* cfmfp)
  25886. {
  25887. if (cfmfp == 0)
  25888. return 0;
  25889. UInt32* const mfp = (UInt32*) juce_malloc (sizeof (UInt32) * 6);
  25890. mfp[0] = 0x3d800000 | ((UInt32) cfmfp >> 16);
  25891. mfp[1] = 0x618c0000 | ((UInt32) cfmfp & 0xffff);
  25892. mfp[2] = 0x800c0000;
  25893. mfp[3] = 0x804c0004;
  25894. mfp[4] = 0x7c0903a6;
  25895. mfp[5] = 0x4e800420;
  25896. MakeDataExecutable (mfp, sizeof (UInt32) * 6);
  25897. return mfp;
  25898. }
  25899. static void disposeMachOFromCFM (void* ptr)
  25900. {
  25901. juce_free (ptr);
  25902. }
  25903. void coerceAEffectFunctionCalls (AEffect* eff)
  25904. {
  25905. if (fragId != 0)
  25906. {
  25907. eff->dispatcher = (AEffectDispatcherProc) newMachOFromCFM ((void*) eff->dispatcher);
  25908. eff->process = (AEffectProcessProc) newMachOFromCFM ((void*) eff->process);
  25909. eff->setParameter = (AEffectSetParameterProc) newMachOFromCFM ((void*) eff->setParameter);
  25910. eff->getParameter = (AEffectGetParameterProc) newMachOFromCFM ((void*) eff->getParameter);
  25911. eff->processReplacing = (AEffectProcessProc) newMachOFromCFM ((void*) eff->processReplacing);
  25912. }
  25913. }
  25914. #endif
  25915. #endif
  25916. };
  25917. class VSTPluginInstance : public AudioPluginInstance,
  25918. private Timer,
  25919. private AsyncUpdater
  25920. {
  25921. public:
  25922. ~VSTPluginInstance();
  25923. // AudioPluginInstance methods:
  25924. void fillInPluginDescription (PluginDescription& desc) const
  25925. {
  25926. desc.name = name;
  25927. desc.fileOrIdentifier = module->file.getFullPathName();
  25928. desc.uid = getUID();
  25929. desc.lastFileModTime = module->file.getLastModificationTime();
  25930. desc.pluginFormatName = "VST";
  25931. desc.category = getCategory();
  25932. {
  25933. char buffer [kVstMaxVendorStrLen + 8];
  25934. zerostruct (buffer);
  25935. dispatch (effGetVendorString, 0, 0, buffer, 0);
  25936. desc.manufacturerName = buffer;
  25937. }
  25938. desc.version = getVersion();
  25939. desc.numInputChannels = getNumInputChannels();
  25940. desc.numOutputChannels = getNumOutputChannels();
  25941. desc.isInstrument = (effect != 0 && (effect->flags & effFlagsIsSynth) != 0);
  25942. }
  25943. const String getName() const { return name; }
  25944. int getUID() const throw();
  25945. bool acceptsMidi() const { return wantsMidiMessages; }
  25946. bool producesMidi() const { return dispatch (effCanDo, 0, 0, (void*) "sendVstMidiEvent", 0) > 0; }
  25947. // AudioProcessor methods:
  25948. void prepareToPlay (double sampleRate, int estimatedSamplesPerBlock);
  25949. void releaseResources();
  25950. void processBlock (AudioSampleBuffer& buffer,
  25951. MidiBuffer& midiMessages);
  25952. AudioProcessorEditor* createEditor();
  25953. const String getInputChannelName (const int index) const;
  25954. bool isInputChannelStereoPair (int index) const;
  25955. const String getOutputChannelName (const int index) const;
  25956. bool isOutputChannelStereoPair (int index) const;
  25957. int getNumParameters() { return effect != 0 ? effect->numParams : 0; }
  25958. float getParameter (int index);
  25959. void setParameter (int index, float newValue);
  25960. const String getParameterName (int index);
  25961. const String getParameterText (int index);
  25962. bool isParameterAutomatable (int index) const;
  25963. int getNumPrograms() { return effect != 0 ? effect->numPrograms : 0; }
  25964. int getCurrentProgram() { return dispatch (effGetProgram, 0, 0, 0, 0); }
  25965. void setCurrentProgram (int index);
  25966. const String getProgramName (int index);
  25967. void changeProgramName (int index, const String& newName);
  25968. void getStateInformation (MemoryBlock& destData);
  25969. void getCurrentProgramStateInformation (MemoryBlock& destData);
  25970. void setStateInformation (const void* data, int sizeInBytes);
  25971. void setCurrentProgramStateInformation (const void* data, int sizeInBytes);
  25972. void timerCallback();
  25973. void handleAsyncUpdate();
  25974. VstIntPtr handleCallback (VstInt32 opcode, VstInt32 index, VstInt32 value, void *ptr, float opt);
  25975. juce_UseDebuggingNewOperator
  25976. private:
  25977. friend class VSTPluginWindow;
  25978. friend class VSTPluginFormat;
  25979. AEffect* effect;
  25980. String name;
  25981. CriticalSection lock;
  25982. bool wantsMidiMessages, initialised, isPowerOn;
  25983. mutable StringArray programNames;
  25984. AudioSampleBuffer tempBuffer;
  25985. CriticalSection midiInLock;
  25986. MidiBuffer incomingMidi;
  25987. VSTMidiEventList midiEventsToSend;
  25988. VstTimeInfo vstHostTime;
  25989. HeapBlock <float*> channels;
  25990. ReferenceCountedObjectPtr <ModuleHandle> module;
  25991. int dispatch (const int opcode, const int index, const int value, void* const ptr, float opt) const;
  25992. bool restoreProgramSettings (const fxProgram* const prog);
  25993. const String getCurrentProgramName();
  25994. void setParamsInProgramBlock (fxProgram* const prog) throw();
  25995. void updateStoredProgramNames();
  25996. void initialise();
  25997. void handleMidiFromPlugin (const VstEvents* const events);
  25998. void createTempParameterStore (MemoryBlock& dest);
  25999. void restoreFromTempParameterStore (const MemoryBlock& mb);
  26000. const String getParameterLabel (int index) const;
  26001. bool usesChunks() const throw() { return effect != 0 && (effect->flags & effFlagsProgramChunks) != 0; }
  26002. void getChunkData (MemoryBlock& mb, bool isPreset, int maxSizeMB) const;
  26003. void setChunkData (const char* data, int size, bool isPreset);
  26004. bool loadFromFXBFile (const void* data, int numBytes);
  26005. bool saveToFXBFile (MemoryBlock& dest, bool isFXB, int maxSizeMB);
  26006. int getVersionNumber() const throw() { return effect != 0 ? effect->version : 0; }
  26007. const String getVersion() const throw();
  26008. const String getCategory() const throw();
  26009. bool hasEditor() const throw() { return effect != 0 && (effect->flags & effFlagsHasEditor) != 0; }
  26010. void setPower (const bool on);
  26011. VSTPluginInstance (const ReferenceCountedObjectPtr <ModuleHandle>& module);
  26012. };
  26013. VSTPluginInstance::VSTPluginInstance (const ReferenceCountedObjectPtr <ModuleHandle>& module_)
  26014. : effect (0),
  26015. wantsMidiMessages (false),
  26016. initialised (false),
  26017. isPowerOn (false),
  26018. tempBuffer (1, 1),
  26019. module (module_)
  26020. {
  26021. try
  26022. {
  26023. _fpreset();
  26024. ++insideVSTCallback;
  26025. name = module->pluginName;
  26026. log (T("Creating VST instance: ") + name);
  26027. #if JUCE_MAC
  26028. if (module->resFileId != 0)
  26029. UseResFile (module->resFileId);
  26030. #if JUCE_PPC
  26031. if (module->fragId != 0)
  26032. {
  26033. static void* audioMasterCoerced = 0;
  26034. if (audioMasterCoerced == 0)
  26035. audioMasterCoerced = NewCFMFromMachO ((void*) &audioMaster);
  26036. effect = module->moduleMain ((audioMasterCallback) audioMasterCoerced);
  26037. }
  26038. else
  26039. #endif
  26040. #endif
  26041. {
  26042. effect = module->moduleMain (&audioMaster);
  26043. }
  26044. --insideVSTCallback;
  26045. if (effect != 0 && effect->magic == kEffectMagic)
  26046. {
  26047. #if JUCE_PPC
  26048. module->coerceAEffectFunctionCalls (effect);
  26049. #endif
  26050. jassert (effect->resvd2 == 0);
  26051. jassert (effect->object != 0);
  26052. _fpreset(); // some dodgy plugs fuck around with this
  26053. }
  26054. else
  26055. {
  26056. effect = 0;
  26057. }
  26058. }
  26059. catch (...)
  26060. {
  26061. --insideVSTCallback;
  26062. }
  26063. }
  26064. VSTPluginInstance::~VSTPluginInstance()
  26065. {
  26066. {
  26067. const ScopedLock sl (lock);
  26068. jassert (insideVSTCallback == 0);
  26069. if (effect != 0 && effect->magic == kEffectMagic)
  26070. {
  26071. try
  26072. {
  26073. #if JUCE_MAC
  26074. if (module->resFileId != 0)
  26075. UseResFile (module->resFileId);
  26076. #endif
  26077. // Must delete any editors before deleting the plugin instance!
  26078. jassert (getActiveEditor() == 0);
  26079. _fpreset(); // some dodgy plugs fuck around with this
  26080. module->closeEffect (effect);
  26081. }
  26082. catch (...)
  26083. {}
  26084. }
  26085. module = 0;
  26086. effect = 0;
  26087. }
  26088. }
  26089. void VSTPluginInstance::initialise()
  26090. {
  26091. if (initialised || effect == 0)
  26092. return;
  26093. log (T("Initialising VST: ") + module->pluginName);
  26094. initialised = true;
  26095. dispatch (effIdentify, 0, 0, 0, 0);
  26096. // this code would ask the plugin for its name, but so few plugins
  26097. // actually bother implementing this correctly, that it's better to
  26098. // just ignore it and use the file name instead.
  26099. if (getSampleRate() > 0)
  26100. dispatch (effSetSampleRate, 0, 0, 0, (float) getSampleRate());
  26101. if (getBlockSize() > 0)
  26102. dispatch (effSetBlockSize, 0, jmax (32, getBlockSize()), 0, 0);
  26103. dispatch (effOpen, 0, 0, 0, 0);
  26104. setPlayConfigDetails (effect->numInputs, effect->numOutputs,
  26105. getSampleRate(), getBlockSize());
  26106. if (getNumPrograms() > 1)
  26107. setCurrentProgram (0);
  26108. else
  26109. dispatch (effSetProgram, 0, 0, 0, 0);
  26110. int i;
  26111. for (i = effect->numInputs; --i >= 0;)
  26112. dispatch (effConnectInput, i, 1, 0, 0);
  26113. for (i = effect->numOutputs; --i >= 0;)
  26114. dispatch (effConnectOutput, i, 1, 0, 0);
  26115. updateStoredProgramNames();
  26116. wantsMidiMessages = dispatch (effCanDo, 0, 0, (void*) "receiveVstMidiEvent", 0) > 0;
  26117. setLatencySamples (effect->initialDelay);
  26118. }
  26119. void VSTPluginInstance::prepareToPlay (double sampleRate_,
  26120. int samplesPerBlockExpected)
  26121. {
  26122. setPlayConfigDetails (effect->numInputs, effect->numOutputs,
  26123. sampleRate_, samplesPerBlockExpected);
  26124. setLatencySamples (effect->initialDelay);
  26125. channels.calloc (jmax (16, getNumOutputChannels(), getNumInputChannels()) + 2);
  26126. vstHostTime.tempo = 120.0;
  26127. vstHostTime.timeSigNumerator = 4;
  26128. vstHostTime.timeSigDenominator = 4;
  26129. vstHostTime.sampleRate = sampleRate_;
  26130. vstHostTime.samplePos = 0;
  26131. vstHostTime.flags = kVstNanosValid; /*| kVstTransportPlaying | kVstTempoValid | kVstTimeSigValid*/;
  26132. initialise();
  26133. if (initialised)
  26134. {
  26135. wantsMidiMessages = wantsMidiMessages
  26136. || (dispatch (effCanDo, 0, 0, (void*) "receiveVstMidiEvent", 0) > 0);
  26137. if (wantsMidiMessages)
  26138. midiEventsToSend.ensureSize (256);
  26139. else
  26140. midiEventsToSend.freeEvents();
  26141. incomingMidi.clear();
  26142. dispatch (effSetSampleRate, 0, 0, 0, (float) sampleRate_);
  26143. dispatch (effSetBlockSize, 0, jmax (16, samplesPerBlockExpected), 0, 0);
  26144. tempBuffer.setSize (jmax (1, effect->numOutputs), samplesPerBlockExpected);
  26145. if (! isPowerOn)
  26146. setPower (true);
  26147. // dodgy hack to force some plugins to initialise the sample rate..
  26148. if ((! hasEditor()) && getNumParameters() > 0)
  26149. {
  26150. const float old = getParameter (0);
  26151. setParameter (0, (old < 0.5f) ? 1.0f : 0.0f);
  26152. setParameter (0, old);
  26153. }
  26154. dispatch (effStartProcess, 0, 0, 0, 0);
  26155. }
  26156. }
  26157. void VSTPluginInstance::releaseResources()
  26158. {
  26159. if (initialised)
  26160. {
  26161. dispatch (effStopProcess, 0, 0, 0, 0);
  26162. setPower (false);
  26163. }
  26164. tempBuffer.setSize (1, 1);
  26165. incomingMidi.clear();
  26166. midiEventsToSend.freeEvents();
  26167. channels.free();
  26168. }
  26169. void VSTPluginInstance::processBlock (AudioSampleBuffer& buffer,
  26170. MidiBuffer& midiMessages)
  26171. {
  26172. const int numSamples = buffer.getNumSamples();
  26173. if (initialised)
  26174. {
  26175. AudioPlayHead* playHead = getPlayHead();
  26176. if (playHead != 0)
  26177. {
  26178. AudioPlayHead::CurrentPositionInfo position;
  26179. playHead->getCurrentPosition (position);
  26180. vstHostTime.tempo = position.bpm;
  26181. vstHostTime.timeSigNumerator = position.timeSigNumerator;
  26182. vstHostTime.timeSigDenominator = position.timeSigDenominator;
  26183. vstHostTime.ppqPos = position.ppqPosition;
  26184. vstHostTime.barStartPos = position.ppqPositionOfLastBarStart;
  26185. vstHostTime.flags |= kVstTempoValid | kVstTimeSigValid | kVstPpqPosValid | kVstBarsValid;
  26186. if (position.isPlaying)
  26187. vstHostTime.flags |= kVstTransportPlaying;
  26188. else
  26189. vstHostTime.flags &= ~kVstTransportPlaying;
  26190. }
  26191. #if JUCE_WIN32
  26192. vstHostTime.nanoSeconds = timeGetTime() * 1000000.0;
  26193. #elif JUCE_LINUX
  26194. timeval micro;
  26195. gettimeofday (&micro, 0);
  26196. vstHostTime.nanoSeconds = micro.tv_usec * 1000.0;
  26197. #elif JUCE_MAC
  26198. UnsignedWide micro;
  26199. Microseconds (&micro);
  26200. vstHostTime.nanoSeconds = micro.lo * 1000.0;
  26201. #endif
  26202. if (wantsMidiMessages)
  26203. {
  26204. midiEventsToSend.clear();
  26205. midiEventsToSend.ensureSize (1);
  26206. MidiBuffer::Iterator iter (midiMessages);
  26207. const uint8* midiData;
  26208. int numBytesOfMidiData, samplePosition;
  26209. while (iter.getNextEvent (midiData, numBytesOfMidiData, samplePosition))
  26210. {
  26211. midiEventsToSend.addEvent (midiData, numBytesOfMidiData,
  26212. jlimit (0, numSamples - 1, samplePosition));
  26213. }
  26214. try
  26215. {
  26216. effect->dispatcher (effect, effProcessEvents, 0, 0, midiEventsToSend.events, 0);
  26217. }
  26218. catch (...)
  26219. {}
  26220. }
  26221. int i;
  26222. const int maxChans = jmax (effect->numInputs, effect->numOutputs);
  26223. for (i = 0; i < maxChans; ++i)
  26224. channels[i] = buffer.getSampleData (i);
  26225. channels [maxChans] = 0;
  26226. _clearfp();
  26227. if ((effect->flags & effFlagsCanReplacing) != 0)
  26228. {
  26229. try
  26230. {
  26231. effect->processReplacing (effect, channels, channels, numSamples);
  26232. }
  26233. catch (...)
  26234. {}
  26235. }
  26236. else
  26237. {
  26238. tempBuffer.setSize (effect->numOutputs, numSamples);
  26239. tempBuffer.clear();
  26240. float* outs [64];
  26241. for (i = effect->numOutputs; --i >= 0;)
  26242. outs[i] = tempBuffer.getSampleData (i);
  26243. outs [effect->numOutputs] = 0;
  26244. try
  26245. {
  26246. effect->process (effect, channels, outs, numSamples);
  26247. }
  26248. catch (...)
  26249. {}
  26250. for (i = effect->numOutputs; --i >= 0;)
  26251. buffer.copyFrom (i, 0, outs[i], numSamples);
  26252. }
  26253. }
  26254. else
  26255. {
  26256. // Not initialised, so just bypass..
  26257. for (int i = getNumInputChannels(); i < getNumOutputChannels(); ++i)
  26258. buffer.clear (i, 0, buffer.getNumSamples());
  26259. }
  26260. {
  26261. // copy any incoming midi..
  26262. const ScopedLock sl (midiInLock);
  26263. midiMessages = incomingMidi;
  26264. incomingMidi.clear();
  26265. }
  26266. }
  26267. void VSTPluginInstance::handleMidiFromPlugin (const VstEvents* const events)
  26268. {
  26269. if (events != 0)
  26270. {
  26271. const ScopedLock sl (midiInLock);
  26272. VSTMidiEventList::addEventsToMidiBuffer (events, incomingMidi);
  26273. }
  26274. }
  26275. static Array <VSTPluginWindow*> activeVSTWindows;
  26276. class VSTPluginWindow : public AudioProcessorEditor,
  26277. #if ! JUCE_MAC
  26278. public ComponentMovementWatcher,
  26279. #endif
  26280. public Timer
  26281. {
  26282. public:
  26283. VSTPluginWindow (VSTPluginInstance& plugin_)
  26284. : AudioProcessorEditor (&plugin_),
  26285. #if ! JUCE_MAC
  26286. ComponentMovementWatcher (this),
  26287. #endif
  26288. plugin (plugin_),
  26289. isOpen (false),
  26290. wasShowing (false),
  26291. pluginRefusesToResize (false),
  26292. pluginWantsKeys (false),
  26293. alreadyInside (false),
  26294. recursiveResize (false)
  26295. {
  26296. #if JUCE_WIN32
  26297. sizeCheckCount = 0;
  26298. pluginHWND = 0;
  26299. #elif JUCE_LINUX
  26300. pluginWindow = None;
  26301. pluginProc = None;
  26302. #else
  26303. addAndMakeVisible (innerWrapper = new InnerWrapperComponent (this));
  26304. #endif
  26305. activeVSTWindows.add (this);
  26306. setSize (1, 1);
  26307. setOpaque (true);
  26308. setVisible (true);
  26309. }
  26310. ~VSTPluginWindow()
  26311. {
  26312. #if JUCE_MAC
  26313. innerWrapper = 0;
  26314. #else
  26315. closePluginWindow();
  26316. #endif
  26317. activeVSTWindows.removeValue (this);
  26318. plugin.editorBeingDeleted (this);
  26319. }
  26320. #if ! JUCE_MAC
  26321. void componentMovedOrResized (bool /*wasMoved*/, bool /*wasResized*/)
  26322. {
  26323. if (recursiveResize)
  26324. return;
  26325. Component* const topComp = getTopLevelComponent();
  26326. if (topComp->getPeer() != 0)
  26327. {
  26328. int x = 0, y = 0;
  26329. relativePositionToOtherComponent (topComp, x, y);
  26330. recursiveResize = true;
  26331. #if JUCE_WIN32
  26332. if (pluginHWND != 0)
  26333. MoveWindow (pluginHWND, x, y, getWidth(), getHeight(), TRUE);
  26334. #elif JUCE_LINUX
  26335. if (pluginWindow != 0)
  26336. {
  26337. XResizeWindow (display, pluginWindow, getWidth(), getHeight());
  26338. XMoveWindow (display, pluginWindow, x, y);
  26339. XMapRaised (display, pluginWindow);
  26340. }
  26341. #endif
  26342. recursiveResize = false;
  26343. }
  26344. }
  26345. void componentVisibilityChanged (Component&)
  26346. {
  26347. const bool isShowingNow = isShowing();
  26348. if (wasShowing != isShowingNow)
  26349. {
  26350. wasShowing = isShowingNow;
  26351. if (isShowingNow)
  26352. openPluginWindow();
  26353. else
  26354. closePluginWindow();
  26355. }
  26356. componentMovedOrResized (true, true);
  26357. }
  26358. void componentPeerChanged()
  26359. {
  26360. closePluginWindow();
  26361. openPluginWindow();
  26362. }
  26363. #endif
  26364. bool keyStateChanged (const bool)
  26365. {
  26366. return pluginWantsKeys;
  26367. }
  26368. bool keyPressed (const KeyPress&)
  26369. {
  26370. return pluginWantsKeys;
  26371. }
  26372. #if JUCE_MAC
  26373. void paint (Graphics& g)
  26374. {
  26375. g.fillAll (Colours::black);
  26376. }
  26377. #else
  26378. void paint (Graphics& g)
  26379. {
  26380. if (isOpen)
  26381. {
  26382. ComponentPeer* const peer = getPeer();
  26383. if (peer != 0)
  26384. {
  26385. peer->addMaskedRegion (getScreenX() - peer->getScreenX(),
  26386. getScreenY() - peer->getScreenY(),
  26387. getWidth(), getHeight());
  26388. #if JUCE_LINUX
  26389. if (pluginWindow != 0)
  26390. {
  26391. const Rectangle clip (g.getClipBounds());
  26392. XEvent ev;
  26393. zerostruct (ev);
  26394. ev.xexpose.type = Expose;
  26395. ev.xexpose.display = display;
  26396. ev.xexpose.window = pluginWindow;
  26397. ev.xexpose.x = clip.getX();
  26398. ev.xexpose.y = clip.getY();
  26399. ev.xexpose.width = clip.getWidth();
  26400. ev.xexpose.height = clip.getHeight();
  26401. sendEventToChild (&ev);
  26402. }
  26403. #endif
  26404. }
  26405. }
  26406. else
  26407. {
  26408. g.fillAll (Colours::black);
  26409. }
  26410. }
  26411. #endif
  26412. void timerCallback()
  26413. {
  26414. #if JUCE_WIN32
  26415. if (--sizeCheckCount <= 0)
  26416. {
  26417. sizeCheckCount = 10;
  26418. checkPluginWindowSize();
  26419. }
  26420. #endif
  26421. try
  26422. {
  26423. static bool reentrant = false;
  26424. if (! reentrant)
  26425. {
  26426. reentrant = true;
  26427. plugin.dispatch (effEditIdle, 0, 0, 0, 0);
  26428. reentrant = false;
  26429. }
  26430. }
  26431. catch (...)
  26432. {}
  26433. }
  26434. void mouseDown (const MouseEvent& e)
  26435. {
  26436. #if JUCE_LINUX
  26437. if (pluginWindow == 0)
  26438. return;
  26439. toFront (true);
  26440. XEvent ev;
  26441. zerostruct (ev);
  26442. ev.xbutton.display = display;
  26443. ev.xbutton.type = ButtonPress;
  26444. ev.xbutton.window = pluginWindow;
  26445. ev.xbutton.root = RootWindow (display, DefaultScreen (display));
  26446. ev.xbutton.time = CurrentTime;
  26447. ev.xbutton.x = e.x;
  26448. ev.xbutton.y = e.y;
  26449. ev.xbutton.x_root = e.getScreenX();
  26450. ev.xbutton.y_root = e.getScreenY();
  26451. translateJuceToXButtonModifiers (e, ev);
  26452. sendEventToChild (&ev);
  26453. #elif JUCE_WIN32
  26454. (void) e;
  26455. toFront (true);
  26456. #endif
  26457. }
  26458. void broughtToFront()
  26459. {
  26460. activeVSTWindows.removeValue (this);
  26461. activeVSTWindows.add (this);
  26462. #if JUCE_MAC
  26463. dispatch (effEditTop, 0, 0, 0, 0);
  26464. #endif
  26465. }
  26466. juce_UseDebuggingNewOperator
  26467. private:
  26468. VSTPluginInstance& plugin;
  26469. bool isOpen, wasShowing, recursiveResize;
  26470. bool pluginWantsKeys, pluginRefusesToResize, alreadyInside;
  26471. #if JUCE_WIN32
  26472. HWND pluginHWND;
  26473. void* originalWndProc;
  26474. int sizeCheckCount;
  26475. #elif JUCE_LINUX
  26476. Window pluginWindow;
  26477. EventProcPtr pluginProc;
  26478. #endif
  26479. #if JUCE_MAC
  26480. void openPluginWindow (WindowRef parentWindow)
  26481. {
  26482. if (isOpen || parentWindow == 0)
  26483. return;
  26484. isOpen = true;
  26485. ERect* rect = 0;
  26486. dispatch (effEditGetRect, 0, 0, &rect, 0);
  26487. dispatch (effEditOpen, 0, 0, parentWindow, 0);
  26488. // do this before and after like in the steinberg example
  26489. dispatch (effEditGetRect, 0, 0, &rect, 0);
  26490. dispatch (effGetProgram, 0, 0, 0, 0); // also in steinberg code
  26491. // Install keyboard hooks
  26492. pluginWantsKeys = (dispatch (effKeysRequired, 0, 0, 0, 0) == 0);
  26493. // double-check it's not too tiny
  26494. int w = 250, h = 150;
  26495. if (rect != 0)
  26496. {
  26497. w = rect->right - rect->left;
  26498. h = rect->bottom - rect->top;
  26499. if (w == 0 || h == 0)
  26500. {
  26501. w = 250;
  26502. h = 150;
  26503. }
  26504. }
  26505. w = jmax (w, 32);
  26506. h = jmax (h, 32);
  26507. setSize (w, h);
  26508. startTimer (18 + JUCE_NAMESPACE::Random::getSystemRandom().nextInt (5));
  26509. repaint();
  26510. }
  26511. #else
  26512. void openPluginWindow()
  26513. {
  26514. if (isOpen || getWindowHandle() == 0)
  26515. return;
  26516. log (T("Opening VST UI: ") + plugin.name);
  26517. isOpen = true;
  26518. ERect* rect = 0;
  26519. dispatch (effEditGetRect, 0, 0, &rect, 0);
  26520. dispatch (effEditOpen, 0, 0, getWindowHandle(), 0);
  26521. // do this before and after like in the steinberg example
  26522. dispatch (effEditGetRect, 0, 0, &rect, 0);
  26523. dispatch (effGetProgram, 0, 0, 0, 0); // also in steinberg code
  26524. // Install keyboard hooks
  26525. pluginWantsKeys = (dispatch (effKeysRequired, 0, 0, 0, 0) == 0);
  26526. #if JUCE_WIN32
  26527. originalWndProc = 0;
  26528. pluginHWND = GetWindow ((HWND) getWindowHandle(), GW_CHILD);
  26529. if (pluginHWND == 0)
  26530. {
  26531. isOpen = false;
  26532. setSize (300, 150);
  26533. return;
  26534. }
  26535. #pragma warning (push)
  26536. #pragma warning (disable: 4244)
  26537. originalWndProc = (void*) GetWindowLongPtr (pluginHWND, GWL_WNDPROC);
  26538. if (! pluginWantsKeys)
  26539. SetWindowLongPtr (pluginHWND, GWL_WNDPROC, (LONG_PTR) vstHookWndProc);
  26540. #pragma warning (pop)
  26541. int w, h;
  26542. RECT r;
  26543. GetWindowRect (pluginHWND, &r);
  26544. w = r.right - r.left;
  26545. h = r.bottom - r.top;
  26546. if (rect != 0)
  26547. {
  26548. const int rw = rect->right - rect->left;
  26549. const int rh = rect->bottom - rect->top;
  26550. if ((rw > 50 && rh > 50 && rw < 2000 && rh < 2000 && rw != w && rh != h)
  26551. || ((w == 0 && rw > 0) || (h == 0 && rh > 0)))
  26552. {
  26553. // very dodgy logic to decide which size is right.
  26554. if (abs (rw - w) > 350 || abs (rh - h) > 350)
  26555. {
  26556. SetWindowPos (pluginHWND, 0,
  26557. 0, 0, rw, rh,
  26558. SWP_NOMOVE | SWP_NOACTIVATE | SWP_NOOWNERZORDER | SWP_NOZORDER);
  26559. GetWindowRect (pluginHWND, &r);
  26560. w = r.right - r.left;
  26561. h = r.bottom - r.top;
  26562. pluginRefusesToResize = (w != rw) || (h != rh);
  26563. w = rw;
  26564. h = rh;
  26565. }
  26566. }
  26567. }
  26568. #elif JUCE_LINUX
  26569. pluginWindow = getChildWindow ((Window) getWindowHandle());
  26570. if (pluginWindow != 0)
  26571. pluginProc = (EventProcPtr) getPropertyFromXWindow (pluginWindow,
  26572. XInternAtom (display, "_XEventProc", False));
  26573. int w = 250, h = 150;
  26574. if (rect != 0)
  26575. {
  26576. w = rect->right - rect->left;
  26577. h = rect->bottom - rect->top;
  26578. if (w == 0 || h == 0)
  26579. {
  26580. w = 250;
  26581. h = 150;
  26582. }
  26583. }
  26584. if (pluginWindow != 0)
  26585. XMapRaised (display, pluginWindow);
  26586. #endif
  26587. // double-check it's not too tiny
  26588. w = jmax (w, 32);
  26589. h = jmax (h, 32);
  26590. setSize (w, h);
  26591. #if JUCE_WIN32
  26592. checkPluginWindowSize();
  26593. #endif
  26594. startTimer (18 + JUCE_NAMESPACE::Random::getSystemRandom().nextInt (5));
  26595. repaint();
  26596. }
  26597. #endif
  26598. #if ! JUCE_MAC
  26599. void closePluginWindow()
  26600. {
  26601. if (isOpen)
  26602. {
  26603. log (T("Closing VST UI: ") + plugin.getName());
  26604. isOpen = false;
  26605. dispatch (effEditClose, 0, 0, 0, 0);
  26606. #if JUCE_WIN32
  26607. #pragma warning (push)
  26608. #pragma warning (disable: 4244)
  26609. if (pluginHWND != 0 && IsWindow (pluginHWND))
  26610. SetWindowLongPtr (pluginHWND, GWL_WNDPROC, (LONG_PTR) originalWndProc);
  26611. #pragma warning (pop)
  26612. stopTimer();
  26613. if (pluginHWND != 0 && IsWindow (pluginHWND))
  26614. DestroyWindow (pluginHWND);
  26615. pluginHWND = 0;
  26616. #elif JUCE_LINUX
  26617. stopTimer();
  26618. pluginWindow = 0;
  26619. pluginProc = 0;
  26620. #endif
  26621. }
  26622. }
  26623. #endif
  26624. int dispatch (const int opcode, const int index, const int value, void* const ptr, float opt)
  26625. {
  26626. return plugin.dispatch (opcode, index, value, ptr, opt);
  26627. }
  26628. #if JUCE_WIN32
  26629. void checkPluginWindowSize() throw()
  26630. {
  26631. RECT r;
  26632. GetWindowRect (pluginHWND, &r);
  26633. const int w = r.right - r.left;
  26634. const int h = r.bottom - r.top;
  26635. if (isShowing() && w > 0 && h > 0
  26636. && (w != getWidth() || h != getHeight())
  26637. && ! pluginRefusesToResize)
  26638. {
  26639. setSize (w, h);
  26640. sizeCheckCount = 0;
  26641. }
  26642. }
  26643. // hooks to get keyboard events from VST windows..
  26644. static LRESULT CALLBACK vstHookWndProc (HWND hW, UINT message, WPARAM wParam, LPARAM lParam)
  26645. {
  26646. for (int i = activeVSTWindows.size(); --i >= 0;)
  26647. {
  26648. const VSTPluginWindow* const w = (const VSTPluginWindow*) activeVSTWindows.getUnchecked (i);
  26649. if (w->pluginHWND == hW)
  26650. {
  26651. if (message == WM_CHAR
  26652. || message == WM_KEYDOWN
  26653. || message == WM_SYSKEYDOWN
  26654. || message == WM_KEYUP
  26655. || message == WM_SYSKEYUP
  26656. || message == WM_APPCOMMAND)
  26657. {
  26658. SendMessage ((HWND) w->getTopLevelComponent()->getWindowHandle(),
  26659. message, wParam, lParam);
  26660. }
  26661. return CallWindowProc ((WNDPROC) (w->originalWndProc),
  26662. (HWND) w->pluginHWND,
  26663. message,
  26664. wParam,
  26665. lParam);
  26666. }
  26667. }
  26668. return DefWindowProc (hW, message, wParam, lParam);
  26669. }
  26670. #endif
  26671. #if JUCE_LINUX
  26672. // overload mouse/keyboard events to forward them to the plugin's inner window..
  26673. void sendEventToChild (XEvent* event)
  26674. {
  26675. if (pluginProc != 0)
  26676. {
  26677. // if the plugin publishes an event procedure, pass the event directly..
  26678. pluginProc (event);
  26679. }
  26680. else if (pluginWindow != 0)
  26681. {
  26682. // if the plugin has a window, then send the event to the window so that
  26683. // its message thread will pick it up..
  26684. XSendEvent (display, pluginWindow, False, 0L, event);
  26685. XFlush (display);
  26686. }
  26687. }
  26688. void mouseEnter (const MouseEvent& e)
  26689. {
  26690. if (pluginWindow != 0)
  26691. {
  26692. XEvent ev;
  26693. zerostruct (ev);
  26694. ev.xcrossing.display = display;
  26695. ev.xcrossing.type = EnterNotify;
  26696. ev.xcrossing.window = pluginWindow;
  26697. ev.xcrossing.root = RootWindow (display, DefaultScreen (display));
  26698. ev.xcrossing.time = CurrentTime;
  26699. ev.xcrossing.x = e.x;
  26700. ev.xcrossing.y = e.y;
  26701. ev.xcrossing.x_root = e.getScreenX();
  26702. ev.xcrossing.y_root = e.getScreenY();
  26703. ev.xcrossing.mode = NotifyNormal; // NotifyGrab, NotifyUngrab
  26704. ev.xcrossing.detail = NotifyAncestor; // NotifyVirtual, NotifyInferior, NotifyNonlinear,NotifyNonlinearVirtual
  26705. translateJuceToXCrossingModifiers (e, ev);
  26706. sendEventToChild (&ev);
  26707. }
  26708. }
  26709. void mouseExit (const MouseEvent& e)
  26710. {
  26711. if (pluginWindow != 0)
  26712. {
  26713. XEvent ev;
  26714. zerostruct (ev);
  26715. ev.xcrossing.display = display;
  26716. ev.xcrossing.type = LeaveNotify;
  26717. ev.xcrossing.window = pluginWindow;
  26718. ev.xcrossing.root = RootWindow (display, DefaultScreen (display));
  26719. ev.xcrossing.time = CurrentTime;
  26720. ev.xcrossing.x = e.x;
  26721. ev.xcrossing.y = e.y;
  26722. ev.xcrossing.x_root = e.getScreenX();
  26723. ev.xcrossing.y_root = e.getScreenY();
  26724. ev.xcrossing.mode = NotifyNormal; // NotifyGrab, NotifyUngrab
  26725. ev.xcrossing.detail = NotifyAncestor; // NotifyVirtual, NotifyInferior, NotifyNonlinear,NotifyNonlinearVirtual
  26726. ev.xcrossing.focus = hasKeyboardFocus (true); // TODO - yes ?
  26727. translateJuceToXCrossingModifiers (e, ev);
  26728. sendEventToChild (&ev);
  26729. }
  26730. }
  26731. void mouseMove (const MouseEvent& e)
  26732. {
  26733. if (pluginWindow != 0)
  26734. {
  26735. XEvent ev;
  26736. zerostruct (ev);
  26737. ev.xmotion.display = display;
  26738. ev.xmotion.type = MotionNotify;
  26739. ev.xmotion.window = pluginWindow;
  26740. ev.xmotion.root = RootWindow (display, DefaultScreen (display));
  26741. ev.xmotion.time = CurrentTime;
  26742. ev.xmotion.is_hint = NotifyNormal;
  26743. ev.xmotion.x = e.x;
  26744. ev.xmotion.y = e.y;
  26745. ev.xmotion.x_root = e.getScreenX();
  26746. ev.xmotion.y_root = e.getScreenY();
  26747. sendEventToChild (&ev);
  26748. }
  26749. }
  26750. void mouseDrag (const MouseEvent& e)
  26751. {
  26752. if (pluginWindow != 0)
  26753. {
  26754. XEvent ev;
  26755. zerostruct (ev);
  26756. ev.xmotion.display = display;
  26757. ev.xmotion.type = MotionNotify;
  26758. ev.xmotion.window = pluginWindow;
  26759. ev.xmotion.root = RootWindow (display, DefaultScreen (display));
  26760. ev.xmotion.time = CurrentTime;
  26761. ev.xmotion.x = e.x ;
  26762. ev.xmotion.y = e.y;
  26763. ev.xmotion.x_root = e.getScreenX();
  26764. ev.xmotion.y_root = e.getScreenY();
  26765. ev.xmotion.is_hint = NotifyNormal;
  26766. translateJuceToXMotionModifiers (e, ev);
  26767. sendEventToChild (&ev);
  26768. }
  26769. }
  26770. void mouseUp (const MouseEvent& e)
  26771. {
  26772. if (pluginWindow != 0)
  26773. {
  26774. XEvent ev;
  26775. zerostruct (ev);
  26776. ev.xbutton.display = display;
  26777. ev.xbutton.type = ButtonRelease;
  26778. ev.xbutton.window = pluginWindow;
  26779. ev.xbutton.root = RootWindow (display, DefaultScreen (display));
  26780. ev.xbutton.time = CurrentTime;
  26781. ev.xbutton.x = e.x;
  26782. ev.xbutton.y = e.y;
  26783. ev.xbutton.x_root = e.getScreenX();
  26784. ev.xbutton.y_root = e.getScreenY();
  26785. translateJuceToXButtonModifiers (e, ev);
  26786. sendEventToChild (&ev);
  26787. }
  26788. }
  26789. void mouseWheelMove (const MouseEvent& e,
  26790. float incrementX,
  26791. float incrementY)
  26792. {
  26793. if (pluginWindow != 0)
  26794. {
  26795. XEvent ev;
  26796. zerostruct (ev);
  26797. ev.xbutton.display = display;
  26798. ev.xbutton.type = ButtonPress;
  26799. ev.xbutton.window = pluginWindow;
  26800. ev.xbutton.root = RootWindow (display, DefaultScreen (display));
  26801. ev.xbutton.time = CurrentTime;
  26802. ev.xbutton.x = e.x;
  26803. ev.xbutton.y = e.y;
  26804. ev.xbutton.x_root = e.getScreenX();
  26805. ev.xbutton.y_root = e.getScreenY();
  26806. translateJuceToXMouseWheelModifiers (e, incrementY, ev);
  26807. sendEventToChild (&ev);
  26808. // TODO - put a usleep here ?
  26809. ev.xbutton.type = ButtonRelease;
  26810. sendEventToChild (&ev);
  26811. }
  26812. }
  26813. #endif
  26814. #if JUCE_MAC
  26815. #if ! JUCE_SUPPORT_CARBON
  26816. #error "To build VSTs, you need to enable the JUCE_SUPPORT_CARBON flag in your config!"
  26817. #endif
  26818. class InnerWrapperComponent : public CarbonViewWrapperComponent
  26819. {
  26820. public:
  26821. InnerWrapperComponent (VSTPluginWindow* const owner_)
  26822. : owner (owner_),
  26823. alreadyInside (false)
  26824. {
  26825. }
  26826. ~InnerWrapperComponent()
  26827. {
  26828. deleteWindow();
  26829. }
  26830. HIViewRef attachView (WindowRef windowRef, HIViewRef rootView)
  26831. {
  26832. owner->openPluginWindow (windowRef);
  26833. return 0;
  26834. }
  26835. void removeView (HIViewRef)
  26836. {
  26837. owner->dispatch (effEditClose, 0, 0, 0, 0);
  26838. owner->dispatch (effEditSleep, 0, 0, 0, 0);
  26839. }
  26840. bool getEmbeddedViewSize (int& w, int& h)
  26841. {
  26842. ERect* rect = 0;
  26843. owner->dispatch (effEditGetRect, 0, 0, &rect, 0);
  26844. w = rect->right - rect->left;
  26845. h = rect->bottom - rect->top;
  26846. return true;
  26847. }
  26848. void mouseDown (int x, int y)
  26849. {
  26850. if (! alreadyInside)
  26851. {
  26852. alreadyInside = true;
  26853. getTopLevelComponent()->toFront (true);
  26854. owner->dispatch (effEditMouse, x, y, 0, 0);
  26855. alreadyInside = false;
  26856. }
  26857. else
  26858. {
  26859. PostEvent (::mouseDown, 0);
  26860. }
  26861. }
  26862. void paint()
  26863. {
  26864. ComponentPeer* const peer = getPeer();
  26865. if (peer != 0)
  26866. {
  26867. ERect r;
  26868. r.left = getScreenX() - peer->getScreenX();
  26869. r.right = r.left + getWidth();
  26870. r.top = getScreenY() - peer->getScreenY();
  26871. r.bottom = r.top + getHeight();
  26872. owner->dispatch (effEditDraw, 0, 0, &r, 0);
  26873. }
  26874. }
  26875. private:
  26876. VSTPluginWindow* const owner;
  26877. bool alreadyInside;
  26878. };
  26879. friend class InnerWrapperComponent;
  26880. ScopedPointer <InnerWrapperComponent> innerWrapper;
  26881. void resized()
  26882. {
  26883. innerWrapper->setSize (getWidth(), getHeight());
  26884. }
  26885. #endif
  26886. };
  26887. AudioProcessorEditor* VSTPluginInstance::createEditor()
  26888. {
  26889. if (hasEditor())
  26890. return new VSTPluginWindow (*this);
  26891. return 0;
  26892. }
  26893. void VSTPluginInstance::handleAsyncUpdate()
  26894. {
  26895. // indicates that something about the plugin has changed..
  26896. updateHostDisplay();
  26897. }
  26898. bool VSTPluginInstance::restoreProgramSettings (const fxProgram* const prog)
  26899. {
  26900. if (vst_swap (prog->chunkMagic) == 'CcnK' && vst_swap (prog->fxMagic) == 'FxCk')
  26901. {
  26902. changeProgramName (getCurrentProgram(), prog->prgName);
  26903. for (int i = 0; i < vst_swap (prog->numParams); ++i)
  26904. setParameter (i, vst_swapFloat (prog->params[i]));
  26905. return true;
  26906. }
  26907. return false;
  26908. }
  26909. bool VSTPluginInstance::loadFromFXBFile (const void* const data,
  26910. const int dataSize)
  26911. {
  26912. if (dataSize < 28)
  26913. return false;
  26914. const fxSet* const set = (const fxSet*) data;
  26915. if ((vst_swap (set->chunkMagic) != 'CcnK' && vst_swap (set->chunkMagic) != 'KncC')
  26916. || vst_swap (set->version) > fxbVersionNum)
  26917. return false;
  26918. if (vst_swap (set->fxMagic) == 'FxBk')
  26919. {
  26920. // bank of programs
  26921. if (vst_swap (set->numPrograms) >= 0)
  26922. {
  26923. const int oldProg = getCurrentProgram();
  26924. const int numParams = vst_swap (((const fxProgram*) (set->programs))->numParams);
  26925. const int progLen = sizeof (fxProgram) + (numParams - 1) * sizeof (float);
  26926. for (int i = 0; i < vst_swap (set->numPrograms); ++i)
  26927. {
  26928. if (i != oldProg)
  26929. {
  26930. const fxProgram* const prog = (const fxProgram*) (((const char*) (set->programs)) + i * progLen);
  26931. if (((const char*) prog) - ((const char*) set) >= dataSize)
  26932. return false;
  26933. if (vst_swap (set->numPrograms) > 0)
  26934. setCurrentProgram (i);
  26935. if (! restoreProgramSettings (prog))
  26936. return false;
  26937. }
  26938. }
  26939. if (vst_swap (set->numPrograms) > 0)
  26940. setCurrentProgram (oldProg);
  26941. const fxProgram* const prog = (const fxProgram*) (((const char*) (set->programs)) + oldProg * progLen);
  26942. if (((const char*) prog) - ((const char*) set) >= dataSize)
  26943. return false;
  26944. if (! restoreProgramSettings (prog))
  26945. return false;
  26946. }
  26947. }
  26948. else if (vst_swap (set->fxMagic) == 'FxCk')
  26949. {
  26950. // single program
  26951. const fxProgram* const prog = (const fxProgram*) data;
  26952. if (vst_swap (prog->chunkMagic) != 'CcnK')
  26953. return false;
  26954. changeProgramName (getCurrentProgram(), prog->prgName);
  26955. for (int i = 0; i < vst_swap (prog->numParams); ++i)
  26956. setParameter (i, vst_swapFloat (prog->params[i]));
  26957. }
  26958. else if (vst_swap (set->fxMagic) == 'FBCh' || vst_swap (set->fxMagic) == 'hCBF')
  26959. {
  26960. // non-preset chunk
  26961. const fxChunkSet* const cset = (const fxChunkSet*) data;
  26962. if (vst_swap (cset->chunkSize) + sizeof (fxChunkSet) - 8 > (unsigned int) dataSize)
  26963. return false;
  26964. setChunkData (cset->chunk, vst_swap (cset->chunkSize), false);
  26965. }
  26966. else if (vst_swap (set->fxMagic) == 'FPCh' || vst_swap (set->fxMagic) == 'hCPF')
  26967. {
  26968. // preset chunk
  26969. const fxProgramSet* const cset = (const fxProgramSet*) data;
  26970. if (vst_swap (cset->chunkSize) + sizeof (fxProgramSet) - 8 > (unsigned int) dataSize)
  26971. return false;
  26972. setChunkData (cset->chunk, vst_swap (cset->chunkSize), true);
  26973. changeProgramName (getCurrentProgram(), cset->name);
  26974. }
  26975. else
  26976. {
  26977. return false;
  26978. }
  26979. return true;
  26980. }
  26981. void VSTPluginInstance::setParamsInProgramBlock (fxProgram* const prog) throw()
  26982. {
  26983. const int numParams = getNumParameters();
  26984. prog->chunkMagic = vst_swap ('CcnK');
  26985. prog->byteSize = 0;
  26986. prog->fxMagic = vst_swap ('FxCk');
  26987. prog->version = vst_swap (fxbVersionNum);
  26988. prog->fxID = vst_swap (getUID());
  26989. prog->fxVersion = vst_swap (getVersionNumber());
  26990. prog->numParams = vst_swap (numParams);
  26991. getCurrentProgramName().copyToBuffer (prog->prgName, sizeof (prog->prgName) - 1);
  26992. for (int i = 0; i < numParams; ++i)
  26993. prog->params[i] = vst_swapFloat (getParameter (i));
  26994. }
  26995. bool VSTPluginInstance::saveToFXBFile (MemoryBlock& dest, bool isFXB, int maxSizeMB)
  26996. {
  26997. const int numPrograms = getNumPrograms();
  26998. const int numParams = getNumParameters();
  26999. if (usesChunks())
  27000. {
  27001. if (isFXB)
  27002. {
  27003. MemoryBlock chunk;
  27004. getChunkData (chunk, false, maxSizeMB);
  27005. const int totalLen = sizeof (fxChunkSet) + chunk.getSize() - 8;
  27006. dest.setSize (totalLen, true);
  27007. fxChunkSet* const set = (fxChunkSet*) dest.getData();
  27008. set->chunkMagic = vst_swap ('CcnK');
  27009. set->byteSize = 0;
  27010. set->fxMagic = vst_swap ('FBCh');
  27011. set->version = vst_swap (fxbVersionNum);
  27012. set->fxID = vst_swap (getUID());
  27013. set->fxVersion = vst_swap (getVersionNumber());
  27014. set->numPrograms = vst_swap (numPrograms);
  27015. set->chunkSize = vst_swap (chunk.getSize());
  27016. chunk.copyTo (set->chunk, 0, chunk.getSize());
  27017. }
  27018. else
  27019. {
  27020. MemoryBlock chunk;
  27021. getChunkData (chunk, true, maxSizeMB);
  27022. const int totalLen = sizeof (fxProgramSet) + chunk.getSize() - 8;
  27023. dest.setSize (totalLen, true);
  27024. fxProgramSet* const set = (fxProgramSet*) dest.getData();
  27025. set->chunkMagic = vst_swap ('CcnK');
  27026. set->byteSize = 0;
  27027. set->fxMagic = vst_swap ('FPCh');
  27028. set->version = vst_swap (fxbVersionNum);
  27029. set->fxID = vst_swap (getUID());
  27030. set->fxVersion = vst_swap (getVersionNumber());
  27031. set->numPrograms = vst_swap (numPrograms);
  27032. set->chunkSize = vst_swap (chunk.getSize());
  27033. getCurrentProgramName().copyToBuffer (set->name, sizeof (set->name) - 1);
  27034. chunk.copyTo (set->chunk, 0, chunk.getSize());
  27035. }
  27036. }
  27037. else
  27038. {
  27039. if (isFXB)
  27040. {
  27041. const int progLen = sizeof (fxProgram) + (numParams - 1) * sizeof (float);
  27042. const int len = (sizeof (fxSet) - sizeof (fxProgram)) + progLen * jmax (1, numPrograms);
  27043. dest.setSize (len, true);
  27044. fxSet* const set = (fxSet*) dest.getData();
  27045. set->chunkMagic = vst_swap ('CcnK');
  27046. set->byteSize = 0;
  27047. set->fxMagic = vst_swap ('FxBk');
  27048. set->version = vst_swap (fxbVersionNum);
  27049. set->fxID = vst_swap (getUID());
  27050. set->fxVersion = vst_swap (getVersionNumber());
  27051. set->numPrograms = vst_swap (numPrograms);
  27052. const int oldProgram = getCurrentProgram();
  27053. MemoryBlock oldSettings;
  27054. createTempParameterStore (oldSettings);
  27055. setParamsInProgramBlock ((fxProgram*) (((char*) (set->programs)) + oldProgram * progLen));
  27056. for (int i = 0; i < numPrograms; ++i)
  27057. {
  27058. if (i != oldProgram)
  27059. {
  27060. setCurrentProgram (i);
  27061. setParamsInProgramBlock ((fxProgram*) (((char*) (set->programs)) + i * progLen));
  27062. }
  27063. }
  27064. setCurrentProgram (oldProgram);
  27065. restoreFromTempParameterStore (oldSettings);
  27066. }
  27067. else
  27068. {
  27069. const int totalLen = sizeof (fxProgram) + (numParams - 1) * sizeof (float);
  27070. dest.setSize (totalLen, true);
  27071. setParamsInProgramBlock ((fxProgram*) dest.getData());
  27072. }
  27073. }
  27074. return true;
  27075. }
  27076. void VSTPluginInstance::getChunkData (MemoryBlock& mb, bool isPreset, int maxSizeMB) const
  27077. {
  27078. if (usesChunks())
  27079. {
  27080. void* data = 0;
  27081. const int bytes = dispatch (effGetChunk, isPreset ? 1 : 0, 0, &data, 0.0f);
  27082. if (data != 0 && bytes <= maxSizeMB * 1024 * 1024)
  27083. {
  27084. mb.setSize (bytes);
  27085. mb.copyFrom (data, 0, bytes);
  27086. }
  27087. }
  27088. }
  27089. void VSTPluginInstance::setChunkData (const char* data, int size, bool isPreset)
  27090. {
  27091. if (size > 0 && usesChunks())
  27092. {
  27093. dispatch (effSetChunk, isPreset ? 1 : 0, size, (void*) data, 0.0f);
  27094. if (! isPreset)
  27095. updateStoredProgramNames();
  27096. }
  27097. }
  27098. void VSTPluginInstance::timerCallback()
  27099. {
  27100. if (dispatch (effIdle, 0, 0, 0, 0) == 0)
  27101. stopTimer();
  27102. }
  27103. int VSTPluginInstance::dispatch (const int opcode, const int index, const int value, void* const ptr, float opt) const
  27104. {
  27105. const ScopedLock sl (lock);
  27106. ++insideVSTCallback;
  27107. int result = 0;
  27108. try
  27109. {
  27110. if (effect != 0)
  27111. {
  27112. #if JUCE_MAC
  27113. if (module->resFileId != 0)
  27114. UseResFile (module->resFileId);
  27115. CGrafPtr oldPort;
  27116. if (getActiveEditor() != 0)
  27117. {
  27118. int x = 0, y = 0;
  27119. getActiveEditor()->relativePositionToOtherComponent (getActiveEditor()->getTopLevelComponent(), x, y);
  27120. GetPort (&oldPort);
  27121. SetPortWindowPort ((WindowRef) getActiveEditor()->getWindowHandle());
  27122. SetOrigin (-x, -y);
  27123. }
  27124. #endif
  27125. result = effect->dispatcher (effect, opcode, index, value, ptr, opt);
  27126. #if JUCE_MAC
  27127. if (getActiveEditor() != 0)
  27128. SetPort (oldPort);
  27129. module->resFileId = CurResFile();
  27130. #endif
  27131. --insideVSTCallback;
  27132. return result;
  27133. }
  27134. }
  27135. catch (...)
  27136. {
  27137. //char s[512];
  27138. //sprintf (s, "dispatcher (%d, %d, %d, %x, %f)", opcode, index, value, (int)ptr, opt);
  27139. }
  27140. --insideVSTCallback;
  27141. return result;
  27142. }
  27143. // handles non plugin-specific callbacks..
  27144. static const int defaultVSTSampleRateValue = 16384;
  27145. static const int defaultVSTBlockSizeValue = 512;
  27146. static VstIntPtr handleGeneralCallback (VstInt32 opcode, VstInt32 index, VstInt32 value, void *ptr, float opt)
  27147. {
  27148. (void) index;
  27149. (void) value;
  27150. (void) opt;
  27151. switch (opcode)
  27152. {
  27153. case audioMasterCanDo:
  27154. {
  27155. static const char* canDos[] = { "supplyIdle",
  27156. "sendVstEvents",
  27157. "sendVstMidiEvent",
  27158. "sendVstTimeInfo",
  27159. "receiveVstEvents",
  27160. "receiveVstMidiEvent",
  27161. "supportShell",
  27162. "shellCategory" };
  27163. for (int i = 0; i < numElementsInArray (canDos); ++i)
  27164. if (strcmp (canDos[i], (const char*) ptr) == 0)
  27165. return 1;
  27166. return 0;
  27167. }
  27168. case audioMasterVersion:
  27169. return 0x2400;
  27170. case audioMasterCurrentId:
  27171. return shellUIDToCreate;
  27172. case audioMasterGetNumAutomatableParameters:
  27173. return 0;
  27174. case audioMasterGetAutomationState:
  27175. return 1;
  27176. case audioMasterGetVendorVersion:
  27177. return 0x0101;
  27178. case audioMasterGetVendorString:
  27179. case audioMasterGetProductString:
  27180. {
  27181. String hostName ("Juce VST Host");
  27182. if (JUCEApplication::getInstance() != 0)
  27183. hostName = JUCEApplication::getInstance()->getApplicationName();
  27184. hostName.copyToBuffer ((char*) ptr, jmin (kVstMaxVendorStrLen, kVstMaxProductStrLen) - 1);
  27185. }
  27186. break;
  27187. case audioMasterGetSampleRate:
  27188. return (VstIntPtr) defaultVSTSampleRateValue;
  27189. case audioMasterGetBlockSize:
  27190. return (VstIntPtr) defaultVSTBlockSizeValue;
  27191. case audioMasterSetOutputSampleRate:
  27192. return 0;
  27193. default:
  27194. DBG ("*** Unhandled VST Callback: " + String ((int) opcode));
  27195. break;
  27196. }
  27197. return 0;
  27198. }
  27199. // handles callbacks for a specific plugin
  27200. VstIntPtr VSTPluginInstance::handleCallback (VstInt32 opcode, VstInt32 index, VstInt32 value, void *ptr, float opt)
  27201. {
  27202. switch (opcode)
  27203. {
  27204. case audioMasterAutomate:
  27205. sendParamChangeMessageToListeners (index, opt);
  27206. break;
  27207. case audioMasterProcessEvents:
  27208. handleMidiFromPlugin ((const VstEvents*) ptr);
  27209. break;
  27210. case audioMasterGetTime:
  27211. #ifdef _MSC_VER
  27212. #pragma warning (push)
  27213. #pragma warning (disable: 4311)
  27214. #endif
  27215. return (VstIntPtr) &vstHostTime;
  27216. #ifdef _MSC_VER
  27217. #pragma warning (pop)
  27218. #endif
  27219. break;
  27220. case audioMasterIdle:
  27221. if (insideVSTCallback == 0 && MessageManager::getInstance()->isThisTheMessageThread())
  27222. {
  27223. ++insideVSTCallback;
  27224. #if JUCE_MAC
  27225. if (getActiveEditor() != 0)
  27226. dispatch (effEditIdle, 0, 0, 0, 0);
  27227. #endif
  27228. juce_callAnyTimersSynchronously();
  27229. handleUpdateNowIfNeeded();
  27230. for (int i = ComponentPeer::getNumPeers(); --i >= 0;)
  27231. ComponentPeer::getPeer (i)->performAnyPendingRepaintsNow();
  27232. --insideVSTCallback;
  27233. }
  27234. break;
  27235. case audioMasterUpdateDisplay:
  27236. triggerAsyncUpdate();
  27237. break;
  27238. case audioMasterTempoAt:
  27239. // returns (10000 * bpm)
  27240. break;
  27241. case audioMasterNeedIdle:
  27242. startTimer (50);
  27243. break;
  27244. case audioMasterSizeWindow:
  27245. if (getActiveEditor() != 0)
  27246. getActiveEditor()->setSize (index, value);
  27247. return 1;
  27248. case audioMasterGetSampleRate:
  27249. return (VstIntPtr) (getSampleRate() > 0 ? getSampleRate() : defaultVSTSampleRateValue);
  27250. case audioMasterGetBlockSize:
  27251. return (VstIntPtr) (getBlockSize() > 0 ? getBlockSize() : defaultVSTBlockSizeValue);
  27252. case audioMasterWantMidi:
  27253. wantsMidiMessages = true;
  27254. break;
  27255. case audioMasterGetDirectory:
  27256. #if JUCE_MAC
  27257. return (VstIntPtr) (void*) &module->parentDirFSSpec;
  27258. #else
  27259. return (VstIntPtr) (pointer_sized_uint) (const char*) module->fullParentDirectoryPathName;
  27260. #endif
  27261. case audioMasterGetAutomationState:
  27262. // returns 0: not supported, 1: off, 2:read, 3:write, 4:read/write
  27263. break;
  27264. // none of these are handled (yet)..
  27265. case audioMasterBeginEdit:
  27266. case audioMasterEndEdit:
  27267. case audioMasterSetTime:
  27268. case audioMasterPinConnected:
  27269. case audioMasterGetParameterQuantization:
  27270. case audioMasterIOChanged:
  27271. case audioMasterGetInputLatency:
  27272. case audioMasterGetOutputLatency:
  27273. case audioMasterGetPreviousPlug:
  27274. case audioMasterGetNextPlug:
  27275. case audioMasterWillReplaceOrAccumulate:
  27276. case audioMasterGetCurrentProcessLevel:
  27277. case audioMasterOfflineStart:
  27278. case audioMasterOfflineRead:
  27279. case audioMasterOfflineWrite:
  27280. case audioMasterOfflineGetCurrentPass:
  27281. case audioMasterOfflineGetCurrentMetaPass:
  27282. case audioMasterVendorSpecific:
  27283. case audioMasterSetIcon:
  27284. case audioMasterGetLanguage:
  27285. case audioMasterOpenWindow:
  27286. case audioMasterCloseWindow:
  27287. break;
  27288. default:
  27289. return handleGeneralCallback (opcode, index, value, ptr, opt);
  27290. }
  27291. return 0;
  27292. }
  27293. // entry point for all callbacks from the plugin
  27294. static VstIntPtr VSTCALLBACK audioMaster (AEffect* effect, VstInt32 opcode, VstInt32 index, VstIntPtr value, void* ptr, float opt)
  27295. {
  27296. try
  27297. {
  27298. if (effect != 0 && effect->resvd2 != 0)
  27299. {
  27300. return ((VSTPluginInstance*)(effect->resvd2))
  27301. ->handleCallback (opcode, index, value, ptr, opt);
  27302. }
  27303. return handleGeneralCallback (opcode, index, value, ptr, opt);
  27304. }
  27305. catch (...)
  27306. {
  27307. return 0;
  27308. }
  27309. }
  27310. const String VSTPluginInstance::getVersion() const throw()
  27311. {
  27312. unsigned int v = dispatch (effGetVendorVersion, 0, 0, 0, 0);
  27313. String s;
  27314. if (v == 0 || v == -1)
  27315. v = getVersionNumber();
  27316. if (v != 0)
  27317. {
  27318. int versionBits[4];
  27319. int n = 0;
  27320. while (v != 0)
  27321. {
  27322. versionBits [n++] = (v & 0xff);
  27323. v >>= 8;
  27324. }
  27325. s << 'V';
  27326. while (n > 0)
  27327. {
  27328. s << versionBits [--n];
  27329. if (n > 0)
  27330. s << '.';
  27331. }
  27332. }
  27333. return s;
  27334. }
  27335. int VSTPluginInstance::getUID() const throw()
  27336. {
  27337. int uid = effect != 0 ? effect->uniqueID : 0;
  27338. if (uid == 0)
  27339. uid = module->file.hashCode();
  27340. return uid;
  27341. }
  27342. const String VSTPluginInstance::getCategory() const throw()
  27343. {
  27344. const char* result = 0;
  27345. switch (dispatch (effGetPlugCategory, 0, 0, 0, 0))
  27346. {
  27347. case kPlugCategEffect:
  27348. result = "Effect";
  27349. break;
  27350. case kPlugCategSynth:
  27351. result = "Synth";
  27352. break;
  27353. case kPlugCategAnalysis:
  27354. result = "Anaylsis";
  27355. break;
  27356. case kPlugCategMastering:
  27357. result = "Mastering";
  27358. break;
  27359. case kPlugCategSpacializer:
  27360. result = "Spacial";
  27361. break;
  27362. case kPlugCategRoomFx:
  27363. result = "Reverb";
  27364. break;
  27365. case kPlugSurroundFx:
  27366. result = "Surround";
  27367. break;
  27368. case kPlugCategRestoration:
  27369. result = "Restoration";
  27370. break;
  27371. case kPlugCategGenerator:
  27372. result = "Tone generation";
  27373. break;
  27374. default:
  27375. break;
  27376. }
  27377. return result;
  27378. }
  27379. float VSTPluginInstance::getParameter (int index)
  27380. {
  27381. if (effect != 0 && ((unsigned int) index) < (unsigned int) effect->numParams)
  27382. {
  27383. try
  27384. {
  27385. const ScopedLock sl (lock);
  27386. return effect->getParameter (effect, index);
  27387. }
  27388. catch (...)
  27389. {
  27390. }
  27391. }
  27392. return 0.0f;
  27393. }
  27394. void VSTPluginInstance::setParameter (int index, float newValue)
  27395. {
  27396. if (effect != 0 && ((unsigned int) index) < (unsigned int) effect->numParams)
  27397. {
  27398. try
  27399. {
  27400. const ScopedLock sl (lock);
  27401. if (effect->getParameter (effect, index) != newValue)
  27402. effect->setParameter (effect, index, newValue);
  27403. }
  27404. catch (...)
  27405. {
  27406. }
  27407. }
  27408. }
  27409. const String VSTPluginInstance::getParameterName (int index)
  27410. {
  27411. if (effect != 0)
  27412. {
  27413. jassert (index >= 0 && index < effect->numParams);
  27414. char nm [256];
  27415. zerostruct (nm);
  27416. dispatch (effGetParamName, index, 0, nm, 0);
  27417. return String (nm).trim();
  27418. }
  27419. return String::empty;
  27420. }
  27421. const String VSTPluginInstance::getParameterLabel (int index) const
  27422. {
  27423. if (effect != 0)
  27424. {
  27425. jassert (index >= 0 && index < effect->numParams);
  27426. char nm [256];
  27427. zerostruct (nm);
  27428. dispatch (effGetParamLabel, index, 0, nm, 0);
  27429. return String (nm).trim();
  27430. }
  27431. return String::empty;
  27432. }
  27433. const String VSTPluginInstance::getParameterText (int index)
  27434. {
  27435. if (effect != 0)
  27436. {
  27437. jassert (index >= 0 && index < effect->numParams);
  27438. char nm [256];
  27439. zerostruct (nm);
  27440. dispatch (effGetParamDisplay, index, 0, nm, 0);
  27441. return String (nm).trim();
  27442. }
  27443. return String::empty;
  27444. }
  27445. bool VSTPluginInstance::isParameterAutomatable (int index) const
  27446. {
  27447. if (effect != 0)
  27448. {
  27449. jassert (index >= 0 && index < effect->numParams);
  27450. return dispatch (effCanBeAutomated, index, 0, 0, 0) != 0;
  27451. }
  27452. return false;
  27453. }
  27454. void VSTPluginInstance::createTempParameterStore (MemoryBlock& dest)
  27455. {
  27456. dest.setSize (64 + 4 * getNumParameters());
  27457. dest.fillWith (0);
  27458. getCurrentProgramName().copyToBuffer ((char*) dest.getData(), 63);
  27459. float* const p = (float*) (((char*) dest.getData()) + 64);
  27460. for (int i = 0; i < getNumParameters(); ++i)
  27461. p[i] = getParameter(i);
  27462. }
  27463. void VSTPluginInstance::restoreFromTempParameterStore (const MemoryBlock& m)
  27464. {
  27465. changeProgramName (getCurrentProgram(), (const char*) m.getData());
  27466. float* p = (float*) (((char*) m.getData()) + 64);
  27467. for (int i = 0; i < getNumParameters(); ++i)
  27468. setParameter (i, p[i]);
  27469. }
  27470. void VSTPluginInstance::setCurrentProgram (int newIndex)
  27471. {
  27472. if (getNumPrograms() > 0 && newIndex != getCurrentProgram())
  27473. dispatch (effSetProgram, 0, jlimit (0, getNumPrograms() - 1, newIndex), 0, 0);
  27474. }
  27475. const String VSTPluginInstance::getProgramName (int index)
  27476. {
  27477. if (index == getCurrentProgram())
  27478. {
  27479. return getCurrentProgramName();
  27480. }
  27481. else if (effect != 0)
  27482. {
  27483. char nm [256];
  27484. zerostruct (nm);
  27485. if (dispatch (effGetProgramNameIndexed,
  27486. jlimit (0, getNumPrograms(), index),
  27487. -1, nm, 0) != 0)
  27488. {
  27489. return String (nm).trim();
  27490. }
  27491. }
  27492. return programNames [index];
  27493. }
  27494. void VSTPluginInstance::changeProgramName (int index, const String& newName)
  27495. {
  27496. if (index == getCurrentProgram())
  27497. {
  27498. if (getNumPrograms() > 0 && newName != getCurrentProgramName())
  27499. dispatch (effSetProgramName, 0, 0, (void*) (const char*) newName.substring (0, 24), 0.0f);
  27500. }
  27501. else
  27502. {
  27503. jassertfalse // xxx not implemented!
  27504. }
  27505. }
  27506. void VSTPluginInstance::updateStoredProgramNames()
  27507. {
  27508. if (effect != 0 && getNumPrograms() > 0)
  27509. {
  27510. char nm [256];
  27511. zerostruct (nm);
  27512. // only do this if the plugin can't use indexed names..
  27513. if (dispatch (effGetProgramNameIndexed, 0, -1, nm, 0) == 0)
  27514. {
  27515. const int oldProgram = getCurrentProgram();
  27516. MemoryBlock oldSettings;
  27517. createTempParameterStore (oldSettings);
  27518. for (int i = 0; i < getNumPrograms(); ++i)
  27519. {
  27520. setCurrentProgram (i);
  27521. getCurrentProgramName(); // (this updates the list)
  27522. }
  27523. setCurrentProgram (oldProgram);
  27524. restoreFromTempParameterStore (oldSettings);
  27525. }
  27526. }
  27527. }
  27528. const String VSTPluginInstance::getCurrentProgramName()
  27529. {
  27530. if (effect != 0)
  27531. {
  27532. char nm [256];
  27533. zerostruct (nm);
  27534. dispatch (effGetProgramName, 0, 0, nm, 0);
  27535. const int index = getCurrentProgram();
  27536. if (programNames[index].isEmpty())
  27537. {
  27538. while (programNames.size() < index)
  27539. programNames.add (String::empty);
  27540. programNames.set (index, String (nm).trim());
  27541. }
  27542. return String (nm).trim();
  27543. }
  27544. return String::empty;
  27545. }
  27546. const String VSTPluginInstance::getInputChannelName (const int index) const
  27547. {
  27548. if (index >= 0 && index < getNumInputChannels())
  27549. {
  27550. VstPinProperties pinProps;
  27551. if (dispatch (effGetInputProperties, index, 0, &pinProps, 0.0f) != 0)
  27552. return String (pinProps.label, sizeof (pinProps.label));
  27553. }
  27554. return String::empty;
  27555. }
  27556. bool VSTPluginInstance::isInputChannelStereoPair (int index) const
  27557. {
  27558. if (index < 0 || index >= getNumInputChannels())
  27559. return false;
  27560. VstPinProperties pinProps;
  27561. if (dispatch (effGetInputProperties, index, 0, &pinProps, 0.0f) != 0)
  27562. return (pinProps.flags & kVstPinIsStereo) != 0;
  27563. return true;
  27564. }
  27565. const String VSTPluginInstance::getOutputChannelName (const int index) const
  27566. {
  27567. if (index >= 0 && index < getNumOutputChannels())
  27568. {
  27569. VstPinProperties pinProps;
  27570. if (dispatch (effGetOutputProperties, index, 0, &pinProps, 0.0f) != 0)
  27571. return String (pinProps.label, sizeof (pinProps.label));
  27572. }
  27573. return String::empty;
  27574. }
  27575. bool VSTPluginInstance::isOutputChannelStereoPair (int index) const
  27576. {
  27577. if (index < 0 || index >= getNumOutputChannels())
  27578. return false;
  27579. VstPinProperties pinProps;
  27580. if (dispatch (effGetOutputProperties, index, 0, &pinProps, 0.0f) != 0)
  27581. return (pinProps.flags & kVstPinIsStereo) != 0;
  27582. return true;
  27583. }
  27584. void VSTPluginInstance::setPower (const bool on)
  27585. {
  27586. dispatch (effMainsChanged, 0, on ? 1 : 0, 0, 0);
  27587. isPowerOn = on;
  27588. }
  27589. const int defaultMaxSizeMB = 64;
  27590. void VSTPluginInstance::getStateInformation (MemoryBlock& destData)
  27591. {
  27592. saveToFXBFile (destData, true, defaultMaxSizeMB);
  27593. }
  27594. void VSTPluginInstance::getCurrentProgramStateInformation (MemoryBlock& destData)
  27595. {
  27596. saveToFXBFile (destData, false, defaultMaxSizeMB);
  27597. }
  27598. void VSTPluginInstance::setStateInformation (const void* data, int sizeInBytes)
  27599. {
  27600. loadFromFXBFile (data, sizeInBytes);
  27601. }
  27602. void VSTPluginInstance::setCurrentProgramStateInformation (const void* data, int sizeInBytes)
  27603. {
  27604. loadFromFXBFile (data, sizeInBytes);
  27605. }
  27606. VSTPluginFormat::VSTPluginFormat()
  27607. {
  27608. }
  27609. VSTPluginFormat::~VSTPluginFormat()
  27610. {
  27611. }
  27612. void VSTPluginFormat::findAllTypesForFile (OwnedArray <PluginDescription>& results,
  27613. const String& fileOrIdentifier)
  27614. {
  27615. if (! fileMightContainThisPluginType (fileOrIdentifier))
  27616. return;
  27617. PluginDescription desc;
  27618. desc.fileOrIdentifier = fileOrIdentifier;
  27619. desc.uid = 0;
  27620. ScopedPointer <VSTPluginInstance> instance (dynamic_cast <VSTPluginInstance*> (createInstanceFromDescription (desc)));
  27621. if (instance == 0)
  27622. return;
  27623. try
  27624. {
  27625. #if JUCE_MAC
  27626. if (instance->module->resFileId != 0)
  27627. UseResFile (instance->module->resFileId);
  27628. #endif
  27629. instance->fillInPluginDescription (desc);
  27630. VstPlugCategory category = (VstPlugCategory) instance->dispatch (effGetPlugCategory, 0, 0, 0, 0);
  27631. if (category != kPlugCategShell)
  27632. {
  27633. // Normal plugin...
  27634. results.add (new PluginDescription (desc));
  27635. ++insideVSTCallback;
  27636. instance->dispatch (effOpen, 0, 0, 0, 0);
  27637. --insideVSTCallback;
  27638. }
  27639. else
  27640. {
  27641. // It's a shell plugin, so iterate all the subtypes...
  27642. char shellEffectName [64];
  27643. for (;;)
  27644. {
  27645. zerostruct (shellEffectName);
  27646. const int uid = instance->dispatch (effShellGetNextPlugin, 0, 0, shellEffectName, 0);
  27647. if (uid == 0)
  27648. {
  27649. break;
  27650. }
  27651. else
  27652. {
  27653. desc.uid = uid;
  27654. desc.name = shellEffectName;
  27655. bool alreadyThere = false;
  27656. for (int i = results.size(); --i >= 0;)
  27657. {
  27658. PluginDescription* const d = results.getUnchecked(i);
  27659. if (d->isDuplicateOf (desc))
  27660. {
  27661. alreadyThere = true;
  27662. break;
  27663. }
  27664. }
  27665. if (! alreadyThere)
  27666. results.add (new PluginDescription (desc));
  27667. }
  27668. }
  27669. }
  27670. }
  27671. catch (...)
  27672. {
  27673. // crashed while loading...
  27674. }
  27675. }
  27676. AudioPluginInstance* VSTPluginFormat::createInstanceFromDescription (const PluginDescription& desc)
  27677. {
  27678. ScopedPointer <VSTPluginInstance> result;
  27679. if (fileMightContainThisPluginType (desc.fileOrIdentifier))
  27680. {
  27681. File file (desc.fileOrIdentifier);
  27682. const File previousWorkingDirectory (File::getCurrentWorkingDirectory());
  27683. file.getParentDirectory().setAsCurrentWorkingDirectory();
  27684. const ReferenceCountedObjectPtr <ModuleHandle> module (ModuleHandle::findOrCreateModule (file));
  27685. if (module != 0)
  27686. {
  27687. shellUIDToCreate = desc.uid;
  27688. result = new VSTPluginInstance (module);
  27689. if (result->effect != 0)
  27690. {
  27691. result->effect->resvd2 = (VstIntPtr) (pointer_sized_int) (VSTPluginInstance*) result;
  27692. result->initialise();
  27693. }
  27694. else
  27695. {
  27696. result = 0;
  27697. }
  27698. }
  27699. previousWorkingDirectory.setAsCurrentWorkingDirectory();
  27700. }
  27701. return result.release();
  27702. }
  27703. bool VSTPluginFormat::fileMightContainThisPluginType (const String& fileOrIdentifier)
  27704. {
  27705. const File f (fileOrIdentifier);
  27706. #if JUCE_MAC
  27707. if (f.isDirectory() && f.hasFileExtension (T(".vst")))
  27708. return true;
  27709. #if JUCE_PPC
  27710. FSRef fileRef;
  27711. if (PlatformUtilities::makeFSRefFromPath (&fileRef, f.getFullPathName()))
  27712. {
  27713. const short resFileId = FSOpenResFile (&fileRef, fsRdPerm);
  27714. if (resFileId != -1)
  27715. {
  27716. const int numEffects = Count1Resources ('aEff');
  27717. CloseResFile (resFileId);
  27718. if (numEffects > 0)
  27719. return true;
  27720. }
  27721. }
  27722. #endif
  27723. return false;
  27724. #elif JUCE_WIN32
  27725. return f.existsAsFile()
  27726. && f.hasFileExtension (T(".dll"));
  27727. #elif JUCE_LINUX
  27728. return f.existsAsFile()
  27729. && f.hasFileExtension (T(".so"));
  27730. #endif
  27731. }
  27732. const String VSTPluginFormat::getNameOfPluginFromIdentifier (const String& fileOrIdentifier)
  27733. {
  27734. return fileOrIdentifier;
  27735. }
  27736. bool VSTPluginFormat::doesPluginStillExist (const PluginDescription& desc)
  27737. {
  27738. return File (desc.fileOrIdentifier).exists();
  27739. }
  27740. const StringArray VSTPluginFormat::searchPathsForPlugins (const FileSearchPath& directoriesToSearch, const bool recursive)
  27741. {
  27742. StringArray results;
  27743. for (int j = 0; j < directoriesToSearch.getNumPaths(); ++j)
  27744. recursiveFileSearch (results, directoriesToSearch [j], recursive);
  27745. return results;
  27746. }
  27747. void VSTPluginFormat::recursiveFileSearch (StringArray& results, const File& dir, const bool recursive)
  27748. {
  27749. // avoid allowing the dir iterator to be recursive, because we want to avoid letting it delve inside
  27750. // .component or .vst directories.
  27751. DirectoryIterator iter (dir, false, "*", File::findFilesAndDirectories);
  27752. while (iter.next())
  27753. {
  27754. const File f (iter.getFile());
  27755. bool isPlugin = false;
  27756. if (fileMightContainThisPluginType (f.getFullPathName()))
  27757. {
  27758. isPlugin = true;
  27759. results.add (f.getFullPathName());
  27760. }
  27761. if (recursive && (! isPlugin) && f.isDirectory())
  27762. recursiveFileSearch (results, f, true);
  27763. }
  27764. }
  27765. const FileSearchPath VSTPluginFormat::getDefaultLocationsToSearch()
  27766. {
  27767. #if JUCE_MAC
  27768. return FileSearchPath ("~/Library/Audio/Plug-Ins/VST;/Library/Audio/Plug-Ins/VST");
  27769. #elif JUCE_WIN32
  27770. const String programFiles (File::getSpecialLocation (File::globalApplicationsDirectory).getFullPathName());
  27771. return FileSearchPath (programFiles + "\\Steinberg\\VstPlugins");
  27772. #elif JUCE_LINUX
  27773. return FileSearchPath ("/usr/lib/vst");
  27774. #endif
  27775. }
  27776. END_JUCE_NAMESPACE
  27777. #endif
  27778. #undef log
  27779. #endif
  27780. /********* End of inlined file: juce_VSTPluginFormat.cpp *********/
  27781. /********* End of inlined file: juce_VSTPluginFormat.mm *********/
  27782. /********* Start of inlined file: juce_AudioProcessor.cpp *********/
  27783. BEGIN_JUCE_NAMESPACE
  27784. AudioProcessor::AudioProcessor()
  27785. : playHead (0),
  27786. activeEditor (0),
  27787. sampleRate (0),
  27788. blockSize (0),
  27789. numInputChannels (0),
  27790. numOutputChannels (0),
  27791. latencySamples (0),
  27792. suspended (false),
  27793. nonRealtime (false)
  27794. {
  27795. }
  27796. AudioProcessor::~AudioProcessor()
  27797. {
  27798. // ooh, nasty - the editor should have been deleted before the filter
  27799. // that it refers to is deleted..
  27800. jassert (activeEditor == 0);
  27801. #ifdef JUCE_DEBUG
  27802. // This will fail if you've called beginParameterChangeGesture() for one
  27803. // or more parameters without having made a corresponding call to endParameterChangeGesture...
  27804. jassert (changingParams.countNumberOfSetBits() == 0);
  27805. #endif
  27806. }
  27807. void AudioProcessor::setPlayHead (AudioPlayHead* const newPlayHead) throw()
  27808. {
  27809. playHead = newPlayHead;
  27810. }
  27811. void AudioProcessor::addListener (AudioProcessorListener* const newListener) throw()
  27812. {
  27813. const ScopedLock sl (listenerLock);
  27814. listeners.addIfNotAlreadyThere (newListener);
  27815. }
  27816. void AudioProcessor::removeListener (AudioProcessorListener* const listenerToRemove) throw()
  27817. {
  27818. const ScopedLock sl (listenerLock);
  27819. listeners.removeValue (listenerToRemove);
  27820. }
  27821. void AudioProcessor::setPlayConfigDetails (const int numIns,
  27822. const int numOuts,
  27823. const double sampleRate_,
  27824. const int blockSize_) throw()
  27825. {
  27826. numInputChannels = numIns;
  27827. numOutputChannels = numOuts;
  27828. sampleRate = sampleRate_;
  27829. blockSize = blockSize_;
  27830. }
  27831. void AudioProcessor::setNonRealtime (const bool nonRealtime_) throw()
  27832. {
  27833. nonRealtime = nonRealtime_;
  27834. }
  27835. void AudioProcessor::setLatencySamples (const int newLatency)
  27836. {
  27837. if (latencySamples != newLatency)
  27838. {
  27839. latencySamples = newLatency;
  27840. updateHostDisplay();
  27841. }
  27842. }
  27843. void AudioProcessor::setParameterNotifyingHost (const int parameterIndex,
  27844. const float newValue)
  27845. {
  27846. setParameter (parameterIndex, newValue);
  27847. sendParamChangeMessageToListeners (parameterIndex, newValue);
  27848. }
  27849. void AudioProcessor::sendParamChangeMessageToListeners (const int parameterIndex, const float newValue)
  27850. {
  27851. jassert (((unsigned int) parameterIndex) < (unsigned int) getNumParameters());
  27852. for (int i = listeners.size(); --i >= 0;)
  27853. {
  27854. listenerLock.enter();
  27855. AudioProcessorListener* const l = (AudioProcessorListener*) listeners [i];
  27856. listenerLock.exit();
  27857. if (l != 0)
  27858. l->audioProcessorParameterChanged (this, parameterIndex, newValue);
  27859. }
  27860. }
  27861. void AudioProcessor::beginParameterChangeGesture (int parameterIndex)
  27862. {
  27863. jassert (((unsigned int) parameterIndex) < (unsigned int) getNumParameters());
  27864. #ifdef JUCE_DEBUG
  27865. // This means you've called beginParameterChangeGesture twice in succession without a matching
  27866. // call to endParameterChangeGesture. That might be fine in most hosts, but better to avoid doing it.
  27867. jassert (! changingParams [parameterIndex]);
  27868. changingParams.setBit (parameterIndex);
  27869. #endif
  27870. for (int i = listeners.size(); --i >= 0;)
  27871. {
  27872. listenerLock.enter();
  27873. AudioProcessorListener* const l = (AudioProcessorListener*) listeners [i];
  27874. listenerLock.exit();
  27875. if (l != 0)
  27876. l->audioProcessorParameterChangeGestureBegin (this, parameterIndex);
  27877. }
  27878. }
  27879. void AudioProcessor::endParameterChangeGesture (int parameterIndex)
  27880. {
  27881. jassert (((unsigned int) parameterIndex) < (unsigned int) getNumParameters());
  27882. #ifdef JUCE_DEBUG
  27883. // This means you've called endParameterChangeGesture without having previously called
  27884. // endParameterChangeGesture. That might be fine in most hosts, but better to keep the
  27885. // calls matched correctly.
  27886. jassert (changingParams [parameterIndex]);
  27887. changingParams.clearBit (parameterIndex);
  27888. #endif
  27889. for (int i = listeners.size(); --i >= 0;)
  27890. {
  27891. listenerLock.enter();
  27892. AudioProcessorListener* const l = (AudioProcessorListener*) listeners [i];
  27893. listenerLock.exit();
  27894. if (l != 0)
  27895. l->audioProcessorParameterChangeGestureEnd (this, parameterIndex);
  27896. }
  27897. }
  27898. void AudioProcessor::updateHostDisplay()
  27899. {
  27900. for (int i = listeners.size(); --i >= 0;)
  27901. {
  27902. listenerLock.enter();
  27903. AudioProcessorListener* const l = (AudioProcessorListener*) listeners [i];
  27904. listenerLock.exit();
  27905. if (l != 0)
  27906. l->audioProcessorChanged (this);
  27907. }
  27908. }
  27909. bool AudioProcessor::isParameterAutomatable (int /*parameterIndex*/) const
  27910. {
  27911. return true;
  27912. }
  27913. bool AudioProcessor::isMetaParameter (int /*parameterIndex*/) const
  27914. {
  27915. return false;
  27916. }
  27917. void AudioProcessor::suspendProcessing (const bool shouldBeSuspended)
  27918. {
  27919. const ScopedLock sl (callbackLock);
  27920. suspended = shouldBeSuspended;
  27921. }
  27922. void AudioProcessor::reset()
  27923. {
  27924. }
  27925. void AudioProcessor::editorBeingDeleted (AudioProcessorEditor* const editor) throw()
  27926. {
  27927. const ScopedLock sl (callbackLock);
  27928. jassert (activeEditor == editor);
  27929. if (activeEditor == editor)
  27930. activeEditor = 0;
  27931. }
  27932. AudioProcessorEditor* AudioProcessor::createEditorIfNeeded()
  27933. {
  27934. if (activeEditor != 0)
  27935. return activeEditor;
  27936. AudioProcessorEditor* const ed = createEditor();
  27937. if (ed != 0)
  27938. {
  27939. // you must give your editor comp a size before returning it..
  27940. jassert (ed->getWidth() > 0 && ed->getHeight() > 0);
  27941. const ScopedLock sl (callbackLock);
  27942. activeEditor = ed;
  27943. }
  27944. return ed;
  27945. }
  27946. void AudioProcessor::getCurrentProgramStateInformation (JUCE_NAMESPACE::MemoryBlock& destData)
  27947. {
  27948. getStateInformation (destData);
  27949. }
  27950. void AudioProcessor::setCurrentProgramStateInformation (const void* data, int sizeInBytes)
  27951. {
  27952. setStateInformation (data, sizeInBytes);
  27953. }
  27954. // magic number to identify memory blocks that we've stored as XML
  27955. const uint32 magicXmlNumber = 0x21324356;
  27956. void AudioProcessor::copyXmlToBinary (const XmlElement& xml,
  27957. JUCE_NAMESPACE::MemoryBlock& destData)
  27958. {
  27959. const String xmlString (xml.createDocument (String::empty, true, false));
  27960. const int stringLength = xmlString.length();
  27961. destData.setSize (stringLength + 10);
  27962. char* const d = (char*) destData.getData();
  27963. *(uint32*) d = ByteOrder::swapIfBigEndian ((const uint32) magicXmlNumber);
  27964. *(uint32*) (d + 4) = ByteOrder::swapIfBigEndian ((const uint32) stringLength);
  27965. xmlString.copyToBuffer (d + 8, stringLength);
  27966. }
  27967. XmlElement* AudioProcessor::getXmlFromBinary (const void* data,
  27968. const int sizeInBytes)
  27969. {
  27970. if (sizeInBytes > 8
  27971. && ByteOrder::littleEndianInt ((const char*) data) == magicXmlNumber)
  27972. {
  27973. const int stringLength = (int) ByteOrder::littleEndianInt (((const char*) data) + 4);
  27974. if (stringLength > 0)
  27975. {
  27976. XmlDocument doc (String (((const char*) data) + 8,
  27977. jmin ((sizeInBytes - 8), stringLength)));
  27978. return doc.getDocumentElement();
  27979. }
  27980. }
  27981. return 0;
  27982. }
  27983. void AudioProcessorListener::audioProcessorParameterChangeGestureBegin (AudioProcessor*, int)
  27984. {
  27985. }
  27986. void AudioProcessorListener::audioProcessorParameterChangeGestureEnd (AudioProcessor*, int)
  27987. {
  27988. }
  27989. END_JUCE_NAMESPACE
  27990. /********* End of inlined file: juce_AudioProcessor.cpp *********/
  27991. /********* Start of inlined file: juce_AudioProcessorEditor.cpp *********/
  27992. BEGIN_JUCE_NAMESPACE
  27993. AudioProcessorEditor::AudioProcessorEditor (AudioProcessor* const owner_)
  27994. : owner (owner_)
  27995. {
  27996. // the filter must be valid..
  27997. jassert (owner != 0);
  27998. }
  27999. AudioProcessorEditor::~AudioProcessorEditor()
  28000. {
  28001. // if this fails, then the wrapper hasn't called editorBeingDeleted() on the
  28002. // filter for some reason..
  28003. jassert (owner->getActiveEditor() != this);
  28004. }
  28005. END_JUCE_NAMESPACE
  28006. /********* End of inlined file: juce_AudioProcessorEditor.cpp *********/
  28007. /********* Start of inlined file: juce_AudioProcessorGraph.cpp *********/
  28008. BEGIN_JUCE_NAMESPACE
  28009. const int AudioProcessorGraph::midiChannelIndex = 0x1000;
  28010. AudioProcessorGraph::Node::Node (const uint32 id_, AudioProcessor* const processor_)
  28011. : id (id_),
  28012. processor (processor_),
  28013. isPrepared (false)
  28014. {
  28015. jassert (processor_ != 0);
  28016. }
  28017. AudioProcessorGraph::Node::~Node()
  28018. {
  28019. delete processor;
  28020. }
  28021. void AudioProcessorGraph::Node::prepare (const double sampleRate, const int blockSize,
  28022. AudioProcessorGraph* const graph)
  28023. {
  28024. if (! isPrepared)
  28025. {
  28026. isPrepared = true;
  28027. AudioProcessorGraph::AudioGraphIOProcessor* const ioProc
  28028. = dynamic_cast <AudioProcessorGraph::AudioGraphIOProcessor*> (processor);
  28029. if (ioProc != 0)
  28030. ioProc->setParentGraph (graph);
  28031. processor->setPlayConfigDetails (processor->getNumInputChannels(),
  28032. processor->getNumOutputChannels(),
  28033. sampleRate, blockSize);
  28034. processor->prepareToPlay (sampleRate, blockSize);
  28035. }
  28036. }
  28037. void AudioProcessorGraph::Node::unprepare()
  28038. {
  28039. if (isPrepared)
  28040. {
  28041. isPrepared = false;
  28042. processor->releaseResources();
  28043. }
  28044. }
  28045. AudioProcessorGraph::AudioProcessorGraph()
  28046. : lastNodeId (0),
  28047. renderingBuffers (1, 1),
  28048. currentAudioOutputBuffer (1, 1)
  28049. {
  28050. }
  28051. AudioProcessorGraph::~AudioProcessorGraph()
  28052. {
  28053. clearRenderingSequence();
  28054. clear();
  28055. }
  28056. const String AudioProcessorGraph::getName() const
  28057. {
  28058. return "Audio Graph";
  28059. }
  28060. void AudioProcessorGraph::clear()
  28061. {
  28062. nodes.clear();
  28063. connections.clear();
  28064. triggerAsyncUpdate();
  28065. }
  28066. AudioProcessorGraph::Node* AudioProcessorGraph::getNodeForId (const uint32 nodeId) const
  28067. {
  28068. for (int i = nodes.size(); --i >= 0;)
  28069. if (nodes.getUnchecked(i)->id == nodeId)
  28070. return nodes.getUnchecked(i);
  28071. return 0;
  28072. }
  28073. AudioProcessorGraph::Node* AudioProcessorGraph::addNode (AudioProcessor* const newProcessor,
  28074. uint32 nodeId)
  28075. {
  28076. if (newProcessor == 0)
  28077. {
  28078. jassertfalse
  28079. return 0;
  28080. }
  28081. if (nodeId == 0)
  28082. {
  28083. nodeId = ++lastNodeId;
  28084. }
  28085. else
  28086. {
  28087. // you can't add a node with an id that already exists in the graph..
  28088. jassert (getNodeForId (nodeId) == 0);
  28089. removeNode (nodeId);
  28090. }
  28091. lastNodeId = nodeId;
  28092. Node* const n = new Node (nodeId, newProcessor);
  28093. nodes.add (n);
  28094. triggerAsyncUpdate();
  28095. AudioProcessorGraph::AudioGraphIOProcessor* const ioProc
  28096. = dynamic_cast <AudioProcessorGraph::AudioGraphIOProcessor*> (n->processor);
  28097. if (ioProc != 0)
  28098. ioProc->setParentGraph (this);
  28099. return n;
  28100. }
  28101. bool AudioProcessorGraph::removeNode (const uint32 nodeId)
  28102. {
  28103. disconnectNode (nodeId);
  28104. for (int i = nodes.size(); --i >= 0;)
  28105. {
  28106. if (nodes.getUnchecked(i)->id == nodeId)
  28107. {
  28108. AudioProcessorGraph::AudioGraphIOProcessor* const ioProc
  28109. = dynamic_cast <AudioProcessorGraph::AudioGraphIOProcessor*> (nodes.getUnchecked(i)->processor);
  28110. if (ioProc != 0)
  28111. ioProc->setParentGraph (0);
  28112. nodes.remove (i);
  28113. triggerAsyncUpdate();
  28114. return true;
  28115. }
  28116. }
  28117. return false;
  28118. }
  28119. const AudioProcessorGraph::Connection* AudioProcessorGraph::getConnectionBetween (const uint32 sourceNodeId,
  28120. const int sourceChannelIndex,
  28121. const uint32 destNodeId,
  28122. const int destChannelIndex) const
  28123. {
  28124. for (int i = connections.size(); --i >= 0;)
  28125. {
  28126. const Connection* const c = connections.getUnchecked(i);
  28127. if (c->sourceNodeId == sourceNodeId
  28128. && c->destNodeId == destNodeId
  28129. && c->sourceChannelIndex == sourceChannelIndex
  28130. && c->destChannelIndex == destChannelIndex)
  28131. {
  28132. return c;
  28133. }
  28134. }
  28135. return 0;
  28136. }
  28137. bool AudioProcessorGraph::isConnected (const uint32 possibleSourceNodeId,
  28138. const uint32 possibleDestNodeId) const
  28139. {
  28140. for (int i = connections.size(); --i >= 0;)
  28141. {
  28142. const Connection* const c = connections.getUnchecked(i);
  28143. if (c->sourceNodeId == possibleSourceNodeId
  28144. && c->destNodeId == possibleDestNodeId)
  28145. {
  28146. return true;
  28147. }
  28148. }
  28149. return false;
  28150. }
  28151. bool AudioProcessorGraph::canConnect (const uint32 sourceNodeId,
  28152. const int sourceChannelIndex,
  28153. const uint32 destNodeId,
  28154. const int destChannelIndex) const
  28155. {
  28156. if (sourceChannelIndex < 0
  28157. || destChannelIndex < 0
  28158. || sourceNodeId == destNodeId
  28159. || (destChannelIndex == midiChannelIndex) != (sourceChannelIndex == midiChannelIndex))
  28160. return false;
  28161. const Node* const source = getNodeForId (sourceNodeId);
  28162. if (source == 0
  28163. || (sourceChannelIndex != midiChannelIndex && sourceChannelIndex >= source->processor->getNumOutputChannels())
  28164. || (sourceChannelIndex == midiChannelIndex && ! source->processor->producesMidi()))
  28165. return false;
  28166. const Node* const dest = getNodeForId (destNodeId);
  28167. if (dest == 0
  28168. || (destChannelIndex != midiChannelIndex && destChannelIndex >= dest->processor->getNumInputChannels())
  28169. || (destChannelIndex == midiChannelIndex && ! dest->processor->acceptsMidi()))
  28170. return false;
  28171. return getConnectionBetween (sourceNodeId, sourceChannelIndex,
  28172. destNodeId, destChannelIndex) == 0;
  28173. }
  28174. bool AudioProcessorGraph::addConnection (const uint32 sourceNodeId,
  28175. const int sourceChannelIndex,
  28176. const uint32 destNodeId,
  28177. const int destChannelIndex)
  28178. {
  28179. if (! canConnect (sourceNodeId, sourceChannelIndex, destNodeId, destChannelIndex))
  28180. return false;
  28181. Connection* const c = new Connection();
  28182. c->sourceNodeId = sourceNodeId;
  28183. c->sourceChannelIndex = sourceChannelIndex;
  28184. c->destNodeId = destNodeId;
  28185. c->destChannelIndex = destChannelIndex;
  28186. connections.add (c);
  28187. triggerAsyncUpdate();
  28188. return true;
  28189. }
  28190. void AudioProcessorGraph::removeConnection (const int index)
  28191. {
  28192. connections.remove (index);
  28193. triggerAsyncUpdate();
  28194. }
  28195. bool AudioProcessorGraph::removeConnection (const uint32 sourceNodeId, const int sourceChannelIndex,
  28196. const uint32 destNodeId, const int destChannelIndex)
  28197. {
  28198. bool doneAnything = false;
  28199. for (int i = connections.size(); --i >= 0;)
  28200. {
  28201. const Connection* const c = connections.getUnchecked(i);
  28202. if (c->sourceNodeId == sourceNodeId
  28203. && c->destNodeId == destNodeId
  28204. && c->sourceChannelIndex == sourceChannelIndex
  28205. && c->destChannelIndex == destChannelIndex)
  28206. {
  28207. removeConnection (i);
  28208. doneAnything = true;
  28209. triggerAsyncUpdate();
  28210. }
  28211. }
  28212. return doneAnything;
  28213. }
  28214. bool AudioProcessorGraph::disconnectNode (const uint32 nodeId)
  28215. {
  28216. bool doneAnything = false;
  28217. for (int i = connections.size(); --i >= 0;)
  28218. {
  28219. const Connection* const c = connections.getUnchecked(i);
  28220. if (c->sourceNodeId == nodeId || c->destNodeId == nodeId)
  28221. {
  28222. removeConnection (i);
  28223. doneAnything = true;
  28224. triggerAsyncUpdate();
  28225. }
  28226. }
  28227. return doneAnything;
  28228. }
  28229. bool AudioProcessorGraph::removeIllegalConnections()
  28230. {
  28231. bool doneAnything = false;
  28232. for (int i = connections.size(); --i >= 0;)
  28233. {
  28234. const Connection* const c = connections.getUnchecked(i);
  28235. const Node* const source = getNodeForId (c->sourceNodeId);
  28236. const Node* const dest = getNodeForId (c->destNodeId);
  28237. if (source == 0 || dest == 0
  28238. || (c->sourceChannelIndex != midiChannelIndex
  28239. && (((unsigned int) c->sourceChannelIndex) >= (unsigned int) source->processor->getNumOutputChannels()))
  28240. || (c->sourceChannelIndex == midiChannelIndex
  28241. && ! source->processor->producesMidi())
  28242. || (c->destChannelIndex != midiChannelIndex
  28243. && (((unsigned int) c->destChannelIndex) >= (unsigned int) dest->processor->getNumInputChannels()))
  28244. || (c->destChannelIndex == midiChannelIndex
  28245. && ! dest->processor->acceptsMidi()))
  28246. {
  28247. removeConnection (i);
  28248. doneAnything = true;
  28249. triggerAsyncUpdate();
  28250. }
  28251. }
  28252. return doneAnything;
  28253. }
  28254. namespace GraphRenderingOps
  28255. {
  28256. class AudioGraphRenderingOp
  28257. {
  28258. public:
  28259. AudioGraphRenderingOp() {}
  28260. virtual ~AudioGraphRenderingOp() {}
  28261. virtual void perform (AudioSampleBuffer& sharedBufferChans,
  28262. const OwnedArray <MidiBuffer>& sharedMidiBuffers,
  28263. const int numSamples) = 0;
  28264. juce_UseDebuggingNewOperator
  28265. };
  28266. class ClearChannelOp : public AudioGraphRenderingOp
  28267. {
  28268. public:
  28269. ClearChannelOp (const int channelNum_)
  28270. : channelNum (channelNum_)
  28271. {}
  28272. ~ClearChannelOp() {}
  28273. void perform (AudioSampleBuffer& sharedBufferChans, const OwnedArray <MidiBuffer>&, const int numSamples)
  28274. {
  28275. sharedBufferChans.clear (channelNum, 0, numSamples);
  28276. }
  28277. private:
  28278. const int channelNum;
  28279. ClearChannelOp (const ClearChannelOp&);
  28280. const ClearChannelOp& operator= (const ClearChannelOp&);
  28281. };
  28282. class CopyChannelOp : public AudioGraphRenderingOp
  28283. {
  28284. public:
  28285. CopyChannelOp (const int srcChannelNum_, const int dstChannelNum_)
  28286. : srcChannelNum (srcChannelNum_),
  28287. dstChannelNum (dstChannelNum_)
  28288. {}
  28289. ~CopyChannelOp() {}
  28290. void perform (AudioSampleBuffer& sharedBufferChans, const OwnedArray <MidiBuffer>&, const int numSamples)
  28291. {
  28292. sharedBufferChans.copyFrom (dstChannelNum, 0, sharedBufferChans, srcChannelNum, 0, numSamples);
  28293. }
  28294. private:
  28295. const int srcChannelNum, dstChannelNum;
  28296. CopyChannelOp (const CopyChannelOp&);
  28297. const CopyChannelOp& operator= (const CopyChannelOp&);
  28298. };
  28299. class AddChannelOp : public AudioGraphRenderingOp
  28300. {
  28301. public:
  28302. AddChannelOp (const int srcChannelNum_, const int dstChannelNum_)
  28303. : srcChannelNum (srcChannelNum_),
  28304. dstChannelNum (dstChannelNum_)
  28305. {}
  28306. ~AddChannelOp() {}
  28307. void perform (AudioSampleBuffer& sharedBufferChans, const OwnedArray <MidiBuffer>&, const int numSamples)
  28308. {
  28309. sharedBufferChans.addFrom (dstChannelNum, 0, sharedBufferChans, srcChannelNum, 0, numSamples);
  28310. }
  28311. private:
  28312. const int srcChannelNum, dstChannelNum;
  28313. AddChannelOp (const AddChannelOp&);
  28314. const AddChannelOp& operator= (const AddChannelOp&);
  28315. };
  28316. class ClearMidiBufferOp : public AudioGraphRenderingOp
  28317. {
  28318. public:
  28319. ClearMidiBufferOp (const int bufferNum_)
  28320. : bufferNum (bufferNum_)
  28321. {}
  28322. ~ClearMidiBufferOp() {}
  28323. void perform (AudioSampleBuffer&, const OwnedArray <MidiBuffer>& sharedMidiBuffers, const int)
  28324. {
  28325. sharedMidiBuffers.getUnchecked (bufferNum)->clear();
  28326. }
  28327. private:
  28328. const int bufferNum;
  28329. ClearMidiBufferOp (const ClearMidiBufferOp&);
  28330. const ClearMidiBufferOp& operator= (const ClearMidiBufferOp&);
  28331. };
  28332. class CopyMidiBufferOp : public AudioGraphRenderingOp
  28333. {
  28334. public:
  28335. CopyMidiBufferOp (const int srcBufferNum_, const int dstBufferNum_)
  28336. : srcBufferNum (srcBufferNum_),
  28337. dstBufferNum (dstBufferNum_)
  28338. {}
  28339. ~CopyMidiBufferOp() {}
  28340. void perform (AudioSampleBuffer&, const OwnedArray <MidiBuffer>& sharedMidiBuffers, const int)
  28341. {
  28342. *sharedMidiBuffers.getUnchecked (dstBufferNum) = *sharedMidiBuffers.getUnchecked (srcBufferNum);
  28343. }
  28344. private:
  28345. const int srcBufferNum, dstBufferNum;
  28346. CopyMidiBufferOp (const CopyMidiBufferOp&);
  28347. const CopyMidiBufferOp& operator= (const CopyMidiBufferOp&);
  28348. };
  28349. class AddMidiBufferOp : public AudioGraphRenderingOp
  28350. {
  28351. public:
  28352. AddMidiBufferOp (const int srcBufferNum_, const int dstBufferNum_)
  28353. : srcBufferNum (srcBufferNum_),
  28354. dstBufferNum (dstBufferNum_)
  28355. {}
  28356. ~AddMidiBufferOp() {}
  28357. void perform (AudioSampleBuffer&, const OwnedArray <MidiBuffer>& sharedMidiBuffers, const int numSamples)
  28358. {
  28359. sharedMidiBuffers.getUnchecked (dstBufferNum)
  28360. ->addEvents (*sharedMidiBuffers.getUnchecked (srcBufferNum), 0, numSamples, 0);
  28361. }
  28362. private:
  28363. const int srcBufferNum, dstBufferNum;
  28364. AddMidiBufferOp (const AddMidiBufferOp&);
  28365. const AddMidiBufferOp& operator= (const AddMidiBufferOp&);
  28366. };
  28367. class ProcessBufferOp : public AudioGraphRenderingOp
  28368. {
  28369. public:
  28370. ProcessBufferOp (const AudioProcessorGraph::Node::Ptr& node_,
  28371. const Array <int>& audioChannelsToUse_,
  28372. const int totalChans_,
  28373. const int midiBufferToUse_)
  28374. : node (node_),
  28375. processor (node_->processor),
  28376. audioChannelsToUse (audioChannelsToUse_),
  28377. totalChans (jmax (1, totalChans_)),
  28378. midiBufferToUse (midiBufferToUse_)
  28379. {
  28380. channels.calloc (totalChans);
  28381. while (audioChannelsToUse.size() < totalChans)
  28382. audioChannelsToUse.add (0);
  28383. }
  28384. ~ProcessBufferOp()
  28385. {
  28386. }
  28387. void perform (AudioSampleBuffer& sharedBufferChans, const OwnedArray <MidiBuffer>& sharedMidiBuffers, const int numSamples)
  28388. {
  28389. for (int i = totalChans; --i >= 0;)
  28390. channels[i] = sharedBufferChans.getSampleData (audioChannelsToUse.getUnchecked (i), 0);
  28391. AudioSampleBuffer buffer (channels, totalChans, numSamples);
  28392. processor->processBlock (buffer, *sharedMidiBuffers.getUnchecked (midiBufferToUse));
  28393. }
  28394. const AudioProcessorGraph::Node::Ptr node;
  28395. AudioProcessor* const processor;
  28396. private:
  28397. Array <int> audioChannelsToUse;
  28398. HeapBlock <float*> channels;
  28399. int totalChans;
  28400. int midiBufferToUse;
  28401. ProcessBufferOp (const ProcessBufferOp&);
  28402. const ProcessBufferOp& operator= (const ProcessBufferOp&);
  28403. };
  28404. class RenderingOpSequenceCalculator
  28405. {
  28406. public:
  28407. RenderingOpSequenceCalculator (AudioProcessorGraph& graph_,
  28408. const VoidArray& orderedNodes_,
  28409. VoidArray& renderingOps)
  28410. : graph (graph_),
  28411. orderedNodes (orderedNodes_)
  28412. {
  28413. nodeIds.add (-2); // first buffer is read-only zeros
  28414. channels.add (0);
  28415. midiNodeIds.add (-2);
  28416. for (int i = 0; i < orderedNodes.size(); ++i)
  28417. {
  28418. createRenderingOpsForNode ((AudioProcessorGraph::Node*) orderedNodes.getUnchecked(i),
  28419. renderingOps, i);
  28420. markAnyUnusedBuffersAsFree (i);
  28421. }
  28422. }
  28423. int getNumBuffersNeeded() const { return nodeIds.size(); }
  28424. int getNumMidiBuffersNeeded() const { return midiNodeIds.size(); }
  28425. juce_UseDebuggingNewOperator
  28426. private:
  28427. AudioProcessorGraph& graph;
  28428. const VoidArray& orderedNodes;
  28429. Array <int> nodeIds, channels, midiNodeIds;
  28430. void createRenderingOpsForNode (AudioProcessorGraph::Node* const node,
  28431. VoidArray& renderingOps,
  28432. const int ourRenderingIndex)
  28433. {
  28434. const int numIns = node->processor->getNumInputChannels();
  28435. const int numOuts = node->processor->getNumOutputChannels();
  28436. const int totalChans = jmax (numIns, numOuts);
  28437. Array <int> audioChannelsToUse;
  28438. int midiBufferToUse = -1;
  28439. for (int inputChan = 0; inputChan < numIns; ++inputChan)
  28440. {
  28441. // get a list of all the inputs to this node
  28442. Array <int> sourceNodes, sourceOutputChans;
  28443. for (int i = graph.getNumConnections(); --i >= 0;)
  28444. {
  28445. const AudioProcessorGraph::Connection* const c = graph.getConnection (i);
  28446. if (c->destNodeId == node->id && c->destChannelIndex == inputChan)
  28447. {
  28448. sourceNodes.add (c->sourceNodeId);
  28449. sourceOutputChans.add (c->sourceChannelIndex);
  28450. }
  28451. }
  28452. int bufIndex = -1;
  28453. if (sourceNodes.size() == 0)
  28454. {
  28455. // unconnected input channel
  28456. if (inputChan >= numOuts)
  28457. {
  28458. bufIndex = getReadOnlyEmptyBuffer();
  28459. jassert (bufIndex >= 0);
  28460. }
  28461. else
  28462. {
  28463. bufIndex = getFreeBuffer (false);
  28464. renderingOps.add (new ClearChannelOp (bufIndex));
  28465. }
  28466. }
  28467. else if (sourceNodes.size() == 1)
  28468. {
  28469. // channel with a straightforward single input..
  28470. const int srcNode = sourceNodes.getUnchecked(0);
  28471. const int srcChan = sourceOutputChans.getUnchecked(0);
  28472. bufIndex = getBufferContaining (srcNode, srcChan);
  28473. if (bufIndex < 0)
  28474. {
  28475. // if not found, this is probably a feedback loop
  28476. bufIndex = getReadOnlyEmptyBuffer();
  28477. jassert (bufIndex >= 0);
  28478. }
  28479. if (inputChan < numOuts
  28480. && isBufferNeededLater (ourRenderingIndex,
  28481. inputChan,
  28482. srcNode, srcChan))
  28483. {
  28484. // can't mess up this channel because it's needed later by another node, so we
  28485. // need to use a copy of it..
  28486. const int newFreeBuffer = getFreeBuffer (false);
  28487. renderingOps.add (new CopyChannelOp (bufIndex, newFreeBuffer));
  28488. bufIndex = newFreeBuffer;
  28489. }
  28490. }
  28491. else
  28492. {
  28493. // channel with a mix of several inputs..
  28494. // try to find a re-usable channel from our inputs..
  28495. int reusableInputIndex = -1;
  28496. for (int i = 0; i < sourceNodes.size(); ++i)
  28497. {
  28498. const int sourceBufIndex = getBufferContaining (sourceNodes.getUnchecked(i),
  28499. sourceOutputChans.getUnchecked(i));
  28500. if (sourceBufIndex >= 0
  28501. && ! isBufferNeededLater (ourRenderingIndex,
  28502. inputChan,
  28503. sourceNodes.getUnchecked(i),
  28504. sourceOutputChans.getUnchecked(i)))
  28505. {
  28506. // we've found one of our input chans that can be re-used..
  28507. reusableInputIndex = i;
  28508. bufIndex = sourceBufIndex;
  28509. break;
  28510. }
  28511. }
  28512. if (reusableInputIndex < 0)
  28513. {
  28514. // can't re-use any of our input chans, so get a new one and copy everything into it..
  28515. bufIndex = getFreeBuffer (false);
  28516. jassert (bufIndex != 0);
  28517. const int srcIndex = getBufferContaining (sourceNodes.getUnchecked (0),
  28518. sourceOutputChans.getUnchecked (0));
  28519. if (srcIndex < 0)
  28520. {
  28521. // if not found, this is probably a feedback loop
  28522. renderingOps.add (new ClearChannelOp (bufIndex));
  28523. }
  28524. else
  28525. {
  28526. renderingOps.add (new CopyChannelOp (srcIndex, bufIndex));
  28527. }
  28528. reusableInputIndex = 0;
  28529. }
  28530. for (int j = 0; j < sourceNodes.size(); ++j)
  28531. {
  28532. if (j != reusableInputIndex)
  28533. {
  28534. const int srcIndex = getBufferContaining (sourceNodes.getUnchecked(j),
  28535. sourceOutputChans.getUnchecked(j));
  28536. if (srcIndex >= 0)
  28537. renderingOps.add (new AddChannelOp (srcIndex, bufIndex));
  28538. }
  28539. }
  28540. }
  28541. jassert (bufIndex >= 0);
  28542. audioChannelsToUse.add (bufIndex);
  28543. if (inputChan < numOuts)
  28544. markBufferAsContaining (bufIndex, node->id, inputChan);
  28545. }
  28546. for (int outputChan = numIns; outputChan < numOuts; ++outputChan)
  28547. {
  28548. const int bufIndex = getFreeBuffer (false);
  28549. jassert (bufIndex != 0);
  28550. audioChannelsToUse.add (bufIndex);
  28551. markBufferAsContaining (bufIndex, node->id, outputChan);
  28552. }
  28553. // Now the same thing for midi..
  28554. Array <int> midiSourceNodes;
  28555. for (int i = graph.getNumConnections(); --i >= 0;)
  28556. {
  28557. const AudioProcessorGraph::Connection* const c = graph.getConnection (i);
  28558. if (c->destNodeId == node->id && c->destChannelIndex == AudioProcessorGraph::midiChannelIndex)
  28559. midiSourceNodes.add (c->sourceNodeId);
  28560. }
  28561. if (midiSourceNodes.size() == 0)
  28562. {
  28563. // No midi inputs..
  28564. midiBufferToUse = getFreeBuffer (true); // need to pick a buffer even if the processor doesn't use midi
  28565. if (node->processor->acceptsMidi() || node->processor->producesMidi())
  28566. renderingOps.add (new ClearMidiBufferOp (midiBufferToUse));
  28567. }
  28568. else if (midiSourceNodes.size() == 1)
  28569. {
  28570. // One midi input..
  28571. midiBufferToUse = getBufferContaining (midiSourceNodes.getUnchecked(0),
  28572. AudioProcessorGraph::midiChannelIndex);
  28573. if (midiBufferToUse >= 0)
  28574. {
  28575. if (isBufferNeededLater (ourRenderingIndex,
  28576. AudioProcessorGraph::midiChannelIndex,
  28577. midiSourceNodes.getUnchecked(0),
  28578. AudioProcessorGraph::midiChannelIndex))
  28579. {
  28580. // can't mess up this channel because it's needed later by another node, so we
  28581. // need to use a copy of it..
  28582. const int newFreeBuffer = getFreeBuffer (true);
  28583. renderingOps.add (new CopyMidiBufferOp (midiBufferToUse, newFreeBuffer));
  28584. midiBufferToUse = newFreeBuffer;
  28585. }
  28586. }
  28587. else
  28588. {
  28589. // probably a feedback loop, so just use an empty one..
  28590. midiBufferToUse = getFreeBuffer (true); // need to pick a buffer even if the processor doesn't use midi
  28591. }
  28592. }
  28593. else
  28594. {
  28595. // More than one midi input being mixed..
  28596. int reusableInputIndex = -1;
  28597. for (int i = 0; i < midiSourceNodes.size(); ++i)
  28598. {
  28599. const int sourceBufIndex = getBufferContaining (midiSourceNodes.getUnchecked(i),
  28600. AudioProcessorGraph::midiChannelIndex);
  28601. if (sourceBufIndex >= 0
  28602. && ! isBufferNeededLater (ourRenderingIndex,
  28603. AudioProcessorGraph::midiChannelIndex,
  28604. midiSourceNodes.getUnchecked(i),
  28605. AudioProcessorGraph::midiChannelIndex))
  28606. {
  28607. // we've found one of our input buffers that can be re-used..
  28608. reusableInputIndex = i;
  28609. midiBufferToUse = sourceBufIndex;
  28610. break;
  28611. }
  28612. }
  28613. if (reusableInputIndex < 0)
  28614. {
  28615. // can't re-use any of our input buffers, so get a new one and copy everything into it..
  28616. midiBufferToUse = getFreeBuffer (true);
  28617. jassert (midiBufferToUse >= 0);
  28618. const int srcIndex = getBufferContaining (midiSourceNodes.getUnchecked(0),
  28619. AudioProcessorGraph::midiChannelIndex);
  28620. if (srcIndex >= 0)
  28621. renderingOps.add (new CopyMidiBufferOp (srcIndex, midiBufferToUse));
  28622. else
  28623. renderingOps.add (new ClearMidiBufferOp (midiBufferToUse));
  28624. reusableInputIndex = 0;
  28625. }
  28626. for (int j = 0; j < midiSourceNodes.size(); ++j)
  28627. {
  28628. if (j != reusableInputIndex)
  28629. {
  28630. const int srcIndex = getBufferContaining (midiSourceNodes.getUnchecked(j),
  28631. AudioProcessorGraph::midiChannelIndex);
  28632. if (srcIndex >= 0)
  28633. renderingOps.add (new AddMidiBufferOp (srcIndex, midiBufferToUse));
  28634. }
  28635. }
  28636. }
  28637. if (node->processor->producesMidi())
  28638. markBufferAsContaining (midiBufferToUse, node->id,
  28639. AudioProcessorGraph::midiChannelIndex);
  28640. renderingOps.add (new ProcessBufferOp (node, audioChannelsToUse,
  28641. totalChans, midiBufferToUse));
  28642. }
  28643. int getFreeBuffer (const bool forMidi)
  28644. {
  28645. if (forMidi)
  28646. {
  28647. for (int i = 1; i < midiNodeIds.size(); ++i)
  28648. if (midiNodeIds.getUnchecked(i) < 0)
  28649. return i;
  28650. midiNodeIds.add (-1);
  28651. return midiNodeIds.size() - 1;
  28652. }
  28653. else
  28654. {
  28655. for (int i = 1; i < nodeIds.size(); ++i)
  28656. if (nodeIds.getUnchecked(i) < 0)
  28657. return i;
  28658. nodeIds.add (-1);
  28659. channels.add (0);
  28660. return nodeIds.size() - 1;
  28661. }
  28662. }
  28663. int getReadOnlyEmptyBuffer() const
  28664. {
  28665. return 0;
  28666. }
  28667. int getBufferContaining (const int nodeId, const int outputChannel) const
  28668. {
  28669. if (outputChannel == AudioProcessorGraph::midiChannelIndex)
  28670. {
  28671. for (int i = midiNodeIds.size(); --i >= 0;)
  28672. if (midiNodeIds.getUnchecked(i) == nodeId)
  28673. return i;
  28674. }
  28675. else
  28676. {
  28677. for (int i = nodeIds.size(); --i >= 0;)
  28678. if (nodeIds.getUnchecked(i) == nodeId
  28679. && channels.getUnchecked(i) == outputChannel)
  28680. return i;
  28681. }
  28682. return -1;
  28683. }
  28684. void markAnyUnusedBuffersAsFree (const int stepIndex)
  28685. {
  28686. int i;
  28687. for (i = 0; i < nodeIds.size(); ++i)
  28688. {
  28689. if (nodeIds.getUnchecked(i) >= 0
  28690. && ! isBufferNeededLater (stepIndex, -1,
  28691. nodeIds.getUnchecked(i),
  28692. channels.getUnchecked(i)))
  28693. {
  28694. nodeIds.set (i, -1);
  28695. }
  28696. }
  28697. for (i = 0; i < midiNodeIds.size(); ++i)
  28698. {
  28699. if (midiNodeIds.getUnchecked(i) >= 0
  28700. && ! isBufferNeededLater (stepIndex, -1,
  28701. midiNodeIds.getUnchecked(i),
  28702. AudioProcessorGraph::midiChannelIndex))
  28703. {
  28704. midiNodeIds.set (i, -1);
  28705. }
  28706. }
  28707. }
  28708. bool isBufferNeededLater (int stepIndexToSearchFrom,
  28709. int inputChannelOfIndexToIgnore,
  28710. const int nodeId,
  28711. const int outputChanIndex) const
  28712. {
  28713. while (stepIndexToSearchFrom < orderedNodes.size())
  28714. {
  28715. const AudioProcessorGraph::Node* const node = (const AudioProcessorGraph::Node*) orderedNodes.getUnchecked (stepIndexToSearchFrom);
  28716. if (outputChanIndex == AudioProcessorGraph::midiChannelIndex)
  28717. {
  28718. if (inputChannelOfIndexToIgnore != AudioProcessorGraph::midiChannelIndex
  28719. && graph.getConnectionBetween (nodeId, AudioProcessorGraph::midiChannelIndex,
  28720. node->id, AudioProcessorGraph::midiChannelIndex) != 0)
  28721. return true;
  28722. }
  28723. else
  28724. {
  28725. for (int i = 0; i < node->processor->getNumInputChannels(); ++i)
  28726. if (i != inputChannelOfIndexToIgnore
  28727. && graph.getConnectionBetween (nodeId, outputChanIndex,
  28728. node->id, i) != 0)
  28729. return true;
  28730. }
  28731. inputChannelOfIndexToIgnore = -1;
  28732. ++stepIndexToSearchFrom;
  28733. }
  28734. return false;
  28735. }
  28736. void markBufferAsContaining (int bufferNum, int nodeId, int outputIndex)
  28737. {
  28738. if (outputIndex == AudioProcessorGraph::midiChannelIndex)
  28739. {
  28740. jassert (bufferNum > 0 && bufferNum < midiNodeIds.size());
  28741. midiNodeIds.set (bufferNum, nodeId);
  28742. }
  28743. else
  28744. {
  28745. jassert (bufferNum >= 0 && bufferNum < nodeIds.size());
  28746. nodeIds.set (bufferNum, nodeId);
  28747. channels.set (bufferNum, outputIndex);
  28748. }
  28749. }
  28750. RenderingOpSequenceCalculator (const RenderingOpSequenceCalculator&);
  28751. const RenderingOpSequenceCalculator& operator= (const RenderingOpSequenceCalculator&);
  28752. };
  28753. }
  28754. void AudioProcessorGraph::clearRenderingSequence()
  28755. {
  28756. const ScopedLock sl (renderLock);
  28757. for (int i = renderingOps.size(); --i >= 0;)
  28758. {
  28759. GraphRenderingOps::AudioGraphRenderingOp* const r
  28760. = (GraphRenderingOps::AudioGraphRenderingOp*) renderingOps.getUnchecked(i);
  28761. renderingOps.remove (i);
  28762. delete r;
  28763. }
  28764. }
  28765. bool AudioProcessorGraph::isAnInputTo (const uint32 possibleInputId,
  28766. const uint32 possibleDestinationId,
  28767. const int recursionCheck) const
  28768. {
  28769. if (recursionCheck > 0)
  28770. {
  28771. for (int i = connections.size(); --i >= 0;)
  28772. {
  28773. const AudioProcessorGraph::Connection* const c = connections.getUnchecked (i);
  28774. if (c->destNodeId == possibleDestinationId
  28775. && (c->sourceNodeId == possibleInputId
  28776. || isAnInputTo (possibleInputId, c->sourceNodeId, recursionCheck - 1)))
  28777. return true;
  28778. }
  28779. }
  28780. return false;
  28781. }
  28782. void AudioProcessorGraph::buildRenderingSequence()
  28783. {
  28784. VoidArray newRenderingOps;
  28785. int numRenderingBuffersNeeded = 2;
  28786. int numMidiBuffersNeeded = 1;
  28787. {
  28788. MessageManagerLock mml;
  28789. VoidArray orderedNodes;
  28790. int i;
  28791. for (i = 0; i < nodes.size(); ++i)
  28792. {
  28793. Node* const node = nodes.getUnchecked(i);
  28794. node->prepare (getSampleRate(), getBlockSize(), this);
  28795. int j = 0;
  28796. for (; j < orderedNodes.size(); ++j)
  28797. if (isAnInputTo (node->id,
  28798. ((Node*) orderedNodes.getUnchecked (j))->id,
  28799. nodes.size() + 1))
  28800. break;
  28801. orderedNodes.insert (j, node);
  28802. }
  28803. GraphRenderingOps::RenderingOpSequenceCalculator calculator (*this, orderedNodes, newRenderingOps);
  28804. numRenderingBuffersNeeded = calculator.getNumBuffersNeeded();
  28805. numMidiBuffersNeeded = calculator.getNumMidiBuffersNeeded();
  28806. }
  28807. VoidArray oldRenderingOps (renderingOps);
  28808. {
  28809. // swap over to the new rendering sequence..
  28810. const ScopedLock sl (renderLock);
  28811. renderingBuffers.setSize (numRenderingBuffersNeeded, getBlockSize());
  28812. renderingBuffers.clear();
  28813. for (int i = midiBuffers.size(); --i >= 0;)
  28814. midiBuffers.getUnchecked(i)->clear();
  28815. while (midiBuffers.size() < numMidiBuffersNeeded)
  28816. midiBuffers.add (new MidiBuffer());
  28817. renderingOps = newRenderingOps;
  28818. }
  28819. for (int i = oldRenderingOps.size(); --i >= 0;)
  28820. delete (GraphRenderingOps::AudioGraphRenderingOp*) oldRenderingOps.getUnchecked(i);
  28821. }
  28822. void AudioProcessorGraph::handleAsyncUpdate()
  28823. {
  28824. buildRenderingSequence();
  28825. }
  28826. void AudioProcessorGraph::prepareToPlay (double /*sampleRate*/, int estimatedSamplesPerBlock)
  28827. {
  28828. currentAudioInputBuffer = 0;
  28829. currentAudioOutputBuffer.setSize (jmax (1, getNumOutputChannels()), estimatedSamplesPerBlock);
  28830. currentMidiInputBuffer = 0;
  28831. currentMidiOutputBuffer.clear();
  28832. clearRenderingSequence();
  28833. buildRenderingSequence();
  28834. }
  28835. void AudioProcessorGraph::releaseResources()
  28836. {
  28837. for (int i = 0; i < nodes.size(); ++i)
  28838. nodes.getUnchecked(i)->unprepare();
  28839. renderingBuffers.setSize (1, 1);
  28840. midiBuffers.clear();
  28841. currentAudioInputBuffer = 0;
  28842. currentAudioOutputBuffer.setSize (1, 1);
  28843. currentMidiInputBuffer = 0;
  28844. currentMidiOutputBuffer.clear();
  28845. }
  28846. void AudioProcessorGraph::processBlock (AudioSampleBuffer& buffer, MidiBuffer& midiMessages)
  28847. {
  28848. const int numSamples = buffer.getNumSamples();
  28849. const ScopedLock sl (renderLock);
  28850. currentAudioInputBuffer = &buffer;
  28851. currentAudioOutputBuffer.setSize (jmax (1, buffer.getNumChannels()), numSamples);
  28852. currentAudioOutputBuffer.clear();
  28853. currentMidiInputBuffer = &midiMessages;
  28854. currentMidiOutputBuffer.clear();
  28855. int i;
  28856. for (i = 0; i < renderingOps.size(); ++i)
  28857. {
  28858. GraphRenderingOps::AudioGraphRenderingOp* const op
  28859. = (GraphRenderingOps::AudioGraphRenderingOp*) renderingOps.getUnchecked(i);
  28860. op->perform (renderingBuffers, midiBuffers, numSamples);
  28861. }
  28862. for (i = 0; i < buffer.getNumChannels(); ++i)
  28863. buffer.copyFrom (i, 0, currentAudioOutputBuffer, i, 0, numSamples);
  28864. midiMessages.clear();
  28865. midiMessages.addEvents (currentMidiOutputBuffer, 0, buffer.getNumSamples(), 0);
  28866. }
  28867. const String AudioProcessorGraph::getInputChannelName (const int channelIndex) const
  28868. {
  28869. return "Input " + String (channelIndex + 1);
  28870. }
  28871. const String AudioProcessorGraph::getOutputChannelName (const int channelIndex) const
  28872. {
  28873. return "Output " + String (channelIndex + 1);
  28874. }
  28875. bool AudioProcessorGraph::isInputChannelStereoPair (int /*index*/) const
  28876. {
  28877. return true;
  28878. }
  28879. bool AudioProcessorGraph::isOutputChannelStereoPair (int /*index*/) const
  28880. {
  28881. return true;
  28882. }
  28883. bool AudioProcessorGraph::acceptsMidi() const
  28884. {
  28885. return true;
  28886. }
  28887. bool AudioProcessorGraph::producesMidi() const
  28888. {
  28889. return true;
  28890. }
  28891. void AudioProcessorGraph::getStateInformation (JUCE_NAMESPACE::MemoryBlock& /*destData*/)
  28892. {
  28893. }
  28894. void AudioProcessorGraph::setStateInformation (const void* /*data*/, int /*sizeInBytes*/)
  28895. {
  28896. }
  28897. AudioProcessorGraph::AudioGraphIOProcessor::AudioGraphIOProcessor (const IODeviceType type_)
  28898. : type (type_),
  28899. graph (0)
  28900. {
  28901. }
  28902. AudioProcessorGraph::AudioGraphIOProcessor::~AudioGraphIOProcessor()
  28903. {
  28904. }
  28905. const String AudioProcessorGraph::AudioGraphIOProcessor::getName() const
  28906. {
  28907. switch (type)
  28908. {
  28909. case audioOutputNode:
  28910. return "Audio Output";
  28911. case audioInputNode:
  28912. return "Audio Input";
  28913. case midiOutputNode:
  28914. return "Midi Output";
  28915. case midiInputNode:
  28916. return "Midi Input";
  28917. default:
  28918. break;
  28919. }
  28920. return String::empty;
  28921. }
  28922. void AudioProcessorGraph::AudioGraphIOProcessor::fillInPluginDescription (PluginDescription& d) const
  28923. {
  28924. d.name = getName();
  28925. d.uid = d.name.hashCode();
  28926. d.category = "I/O devices";
  28927. d.pluginFormatName = "Internal";
  28928. d.manufacturerName = "Raw Material Software";
  28929. d.version = "1.0";
  28930. d.isInstrument = false;
  28931. d.numInputChannels = getNumInputChannels();
  28932. if (type == audioOutputNode && graph != 0)
  28933. d.numInputChannels = graph->getNumInputChannels();
  28934. d.numOutputChannels = getNumOutputChannels();
  28935. if (type == audioInputNode && graph != 0)
  28936. d.numOutputChannels = graph->getNumOutputChannels();
  28937. }
  28938. void AudioProcessorGraph::AudioGraphIOProcessor::prepareToPlay (double, int)
  28939. {
  28940. jassert (graph != 0);
  28941. }
  28942. void AudioProcessorGraph::AudioGraphIOProcessor::releaseResources()
  28943. {
  28944. }
  28945. void AudioProcessorGraph::AudioGraphIOProcessor::processBlock (AudioSampleBuffer& buffer,
  28946. MidiBuffer& midiMessages)
  28947. {
  28948. jassert (graph != 0);
  28949. switch (type)
  28950. {
  28951. case audioOutputNode:
  28952. {
  28953. for (int i = jmin (graph->currentAudioOutputBuffer.getNumChannels(),
  28954. buffer.getNumChannels()); --i >= 0;)
  28955. {
  28956. graph->currentAudioOutputBuffer.addFrom (i, 0, buffer, i, 0, buffer.getNumSamples());
  28957. }
  28958. break;
  28959. }
  28960. case audioInputNode:
  28961. {
  28962. for (int i = jmin (graph->currentAudioInputBuffer->getNumChannels(),
  28963. buffer.getNumChannels()); --i >= 0;)
  28964. {
  28965. buffer.copyFrom (i, 0, *graph->currentAudioInputBuffer, i, 0, buffer.getNumSamples());
  28966. }
  28967. break;
  28968. }
  28969. case midiOutputNode:
  28970. graph->currentMidiOutputBuffer.addEvents (midiMessages, 0, buffer.getNumSamples(), 0);
  28971. break;
  28972. case midiInputNode:
  28973. midiMessages.addEvents (*graph->currentMidiInputBuffer, 0, buffer.getNumSamples(), 0);
  28974. break;
  28975. default:
  28976. break;
  28977. }
  28978. }
  28979. bool AudioProcessorGraph::AudioGraphIOProcessor::acceptsMidi() const
  28980. {
  28981. return type == midiOutputNode;
  28982. }
  28983. bool AudioProcessorGraph::AudioGraphIOProcessor::producesMidi() const
  28984. {
  28985. return type == midiInputNode;
  28986. }
  28987. const String AudioProcessorGraph::AudioGraphIOProcessor::getInputChannelName (const int channelIndex) const
  28988. {
  28989. switch (type)
  28990. {
  28991. case audioOutputNode:
  28992. return "Output " + String (channelIndex + 1);
  28993. case midiOutputNode:
  28994. return "Midi Output";
  28995. default:
  28996. break;
  28997. }
  28998. return String::empty;
  28999. }
  29000. const String AudioProcessorGraph::AudioGraphIOProcessor::getOutputChannelName (const int channelIndex) const
  29001. {
  29002. switch (type)
  29003. {
  29004. case audioInputNode:
  29005. return "Input " + String (channelIndex + 1);
  29006. case midiInputNode:
  29007. return "Midi Input";
  29008. default:
  29009. break;
  29010. }
  29011. return String::empty;
  29012. }
  29013. bool AudioProcessorGraph::AudioGraphIOProcessor::isInputChannelStereoPair (int /*index*/) const
  29014. {
  29015. return type == audioInputNode || type == audioOutputNode;
  29016. }
  29017. bool AudioProcessorGraph::AudioGraphIOProcessor::isOutputChannelStereoPair (int index) const
  29018. {
  29019. return isInputChannelStereoPair (index);
  29020. }
  29021. bool AudioProcessorGraph::AudioGraphIOProcessor::isInput() const
  29022. {
  29023. return type == audioInputNode || type == midiInputNode;
  29024. }
  29025. bool AudioProcessorGraph::AudioGraphIOProcessor::isOutput() const
  29026. {
  29027. return type == audioOutputNode || type == midiOutputNode;
  29028. }
  29029. AudioProcessorEditor* AudioProcessorGraph::AudioGraphIOProcessor::createEditor()
  29030. {
  29031. return 0;
  29032. }
  29033. int AudioProcessorGraph::AudioGraphIOProcessor::getNumParameters() { return 0; }
  29034. const String AudioProcessorGraph::AudioGraphIOProcessor::getParameterName (int) { return String::empty; }
  29035. float AudioProcessorGraph::AudioGraphIOProcessor::getParameter (int) { return 0.0f; }
  29036. const String AudioProcessorGraph::AudioGraphIOProcessor::getParameterText (int) { return String::empty; }
  29037. void AudioProcessorGraph::AudioGraphIOProcessor::setParameter (int, float) { }
  29038. int AudioProcessorGraph::AudioGraphIOProcessor::getNumPrograms() { return 0; }
  29039. int AudioProcessorGraph::AudioGraphIOProcessor::getCurrentProgram() { return 0; }
  29040. void AudioProcessorGraph::AudioGraphIOProcessor::setCurrentProgram (int) { }
  29041. const String AudioProcessorGraph::AudioGraphIOProcessor::getProgramName (int) { return String::empty; }
  29042. void AudioProcessorGraph::AudioGraphIOProcessor::changeProgramName (int, const String&) { }
  29043. void AudioProcessorGraph::AudioGraphIOProcessor::getStateInformation (JUCE_NAMESPACE::MemoryBlock&)
  29044. {
  29045. }
  29046. void AudioProcessorGraph::AudioGraphIOProcessor::setStateInformation (const void*, int)
  29047. {
  29048. }
  29049. void AudioProcessorGraph::AudioGraphIOProcessor::setParentGraph (AudioProcessorGraph* const newGraph)
  29050. {
  29051. graph = newGraph;
  29052. if (graph != 0)
  29053. {
  29054. setPlayConfigDetails (type == audioOutputNode ? graph->getNumOutputChannels() : 0,
  29055. type == audioInputNode ? graph->getNumInputChannels() : 0,
  29056. getSampleRate(),
  29057. getBlockSize());
  29058. updateHostDisplay();
  29059. }
  29060. }
  29061. END_JUCE_NAMESPACE
  29062. /********* End of inlined file: juce_AudioProcessorGraph.cpp *********/
  29063. /********* Start of inlined file: juce_AudioProcessorPlayer.cpp *********/
  29064. BEGIN_JUCE_NAMESPACE
  29065. AudioProcessorPlayer::AudioProcessorPlayer()
  29066. : processor (0),
  29067. sampleRate (0),
  29068. blockSize (0),
  29069. isPrepared (false),
  29070. numInputChans (0),
  29071. numOutputChans (0),
  29072. tempBuffer (1, 1)
  29073. {
  29074. }
  29075. AudioProcessorPlayer::~AudioProcessorPlayer()
  29076. {
  29077. setProcessor (0);
  29078. }
  29079. void AudioProcessorPlayer::setProcessor (AudioProcessor* const processorToPlay)
  29080. {
  29081. if (processor != processorToPlay)
  29082. {
  29083. if (processorToPlay != 0 && sampleRate > 0 && blockSize > 0)
  29084. {
  29085. processorToPlay->setPlayConfigDetails (numInputChans, numOutputChans,
  29086. sampleRate, blockSize);
  29087. processorToPlay->prepareToPlay (sampleRate, blockSize);
  29088. }
  29089. lock.enter();
  29090. AudioProcessor* const oldOne = isPrepared ? processor : 0;
  29091. processor = processorToPlay;
  29092. isPrepared = true;
  29093. lock.exit();
  29094. if (oldOne != 0)
  29095. oldOne->releaseResources();
  29096. }
  29097. }
  29098. void AudioProcessorPlayer::audioDeviceIOCallback (const float** inputChannelData,
  29099. int numInputChannels,
  29100. float** outputChannelData,
  29101. int numOutputChannels,
  29102. int numSamples)
  29103. {
  29104. // these should have been prepared by audioDeviceAboutToStart()...
  29105. jassert (sampleRate > 0 && blockSize > 0);
  29106. incomingMidi.clear();
  29107. messageCollector.removeNextBlockOfMessages (incomingMidi, numSamples);
  29108. int i, totalNumChans = 0;
  29109. if (numInputChannels > numOutputChannels)
  29110. {
  29111. // if there aren't enough output channels for the number of
  29112. // inputs, we need to create some temporary extra ones (can't
  29113. // use the input data in case it gets written to)
  29114. tempBuffer.setSize (numInputChannels - numOutputChannels, numSamples,
  29115. false, false, true);
  29116. for (i = 0; i < numOutputChannels; ++i)
  29117. {
  29118. channels[totalNumChans] = outputChannelData[i];
  29119. memcpy (channels[totalNumChans], inputChannelData[i], sizeof (float) * numSamples);
  29120. ++totalNumChans;
  29121. }
  29122. for (i = numOutputChannels; i < numInputChannels; ++i)
  29123. {
  29124. channels[totalNumChans] = tempBuffer.getSampleData (i - numOutputChannels, 0);
  29125. memcpy (channels[totalNumChans], inputChannelData[i], sizeof (float) * numSamples);
  29126. ++totalNumChans;
  29127. }
  29128. }
  29129. else
  29130. {
  29131. for (i = 0; i < numInputChannels; ++i)
  29132. {
  29133. channels[totalNumChans] = outputChannelData[i];
  29134. memcpy (channels[totalNumChans], inputChannelData[i], sizeof (float) * numSamples);
  29135. ++totalNumChans;
  29136. }
  29137. for (i = numInputChannels; i < numOutputChannels; ++i)
  29138. {
  29139. channels[totalNumChans] = outputChannelData[i];
  29140. zeromem (channels[totalNumChans], sizeof (float) * numSamples);
  29141. ++totalNumChans;
  29142. }
  29143. }
  29144. AudioSampleBuffer buffer (channels, totalNumChans, numSamples);
  29145. const ScopedLock sl (lock);
  29146. if (processor != 0)
  29147. processor->processBlock (buffer, incomingMidi);
  29148. }
  29149. void AudioProcessorPlayer::audioDeviceAboutToStart (AudioIODevice* device)
  29150. {
  29151. const ScopedLock sl (lock);
  29152. sampleRate = device->getCurrentSampleRate();
  29153. blockSize = device->getCurrentBufferSizeSamples();
  29154. numInputChans = device->getActiveInputChannels().countNumberOfSetBits();
  29155. numOutputChans = device->getActiveOutputChannels().countNumberOfSetBits();
  29156. messageCollector.reset (sampleRate);
  29157. zeromem (channels, sizeof (channels));
  29158. if (processor != 0)
  29159. {
  29160. if (isPrepared)
  29161. processor->releaseResources();
  29162. AudioProcessor* const oldProcessor = processor;
  29163. setProcessor (0);
  29164. setProcessor (oldProcessor);
  29165. }
  29166. }
  29167. void AudioProcessorPlayer::audioDeviceStopped()
  29168. {
  29169. const ScopedLock sl (lock);
  29170. if (processor != 0 && isPrepared)
  29171. processor->releaseResources();
  29172. sampleRate = 0.0;
  29173. blockSize = 0;
  29174. isPrepared = false;
  29175. tempBuffer.setSize (1, 1);
  29176. }
  29177. void AudioProcessorPlayer::handleIncomingMidiMessage (MidiInput*, const MidiMessage& message)
  29178. {
  29179. messageCollector.addMessageToQueue (message);
  29180. }
  29181. END_JUCE_NAMESPACE
  29182. /********* End of inlined file: juce_AudioProcessorPlayer.cpp *********/
  29183. /********* Start of inlined file: juce_GenericAudioProcessorEditor.cpp *********/
  29184. BEGIN_JUCE_NAMESPACE
  29185. class ProcessorParameterPropertyComp : public PropertyComponent,
  29186. public AudioProcessorListener,
  29187. public AsyncUpdater
  29188. {
  29189. public:
  29190. ProcessorParameterPropertyComp (const String& name,
  29191. AudioProcessor* const owner_,
  29192. const int index_)
  29193. : PropertyComponent (name),
  29194. owner (owner_),
  29195. index (index_)
  29196. {
  29197. addAndMakeVisible (slider = new ParamSlider (owner_, index_));
  29198. owner_->addListener (this);
  29199. }
  29200. ~ProcessorParameterPropertyComp()
  29201. {
  29202. owner->removeListener (this);
  29203. deleteAllChildren();
  29204. }
  29205. void refresh()
  29206. {
  29207. slider->setValue (owner->getParameter (index), false);
  29208. }
  29209. void audioProcessorChanged (AudioProcessor*) {}
  29210. void audioProcessorParameterChanged (AudioProcessor*, int parameterIndex, float)
  29211. {
  29212. if (parameterIndex == index)
  29213. triggerAsyncUpdate();
  29214. }
  29215. void handleAsyncUpdate()
  29216. {
  29217. refresh();
  29218. }
  29219. juce_UseDebuggingNewOperator
  29220. private:
  29221. AudioProcessor* const owner;
  29222. const int index;
  29223. Slider* slider;
  29224. class ParamSlider : public Slider
  29225. {
  29226. public:
  29227. ParamSlider (AudioProcessor* const owner_, const int index_)
  29228. : Slider (String::empty),
  29229. owner (owner_),
  29230. index (index_)
  29231. {
  29232. setRange (0.0, 1.0, 0.0);
  29233. setSliderStyle (Slider::LinearBar);
  29234. setTextBoxIsEditable (false);
  29235. setScrollWheelEnabled (false);
  29236. }
  29237. ~ParamSlider()
  29238. {
  29239. }
  29240. void valueChanged()
  29241. {
  29242. const float newVal = (float) getValue();
  29243. if (owner->getParameter (index) != newVal)
  29244. owner->setParameter (index, newVal);
  29245. }
  29246. const String getTextFromValue (double /*value*/)
  29247. {
  29248. return owner->getParameterText (index);
  29249. }
  29250. juce_UseDebuggingNewOperator
  29251. private:
  29252. AudioProcessor* const owner;
  29253. const int index;
  29254. ParamSlider (const ParamSlider&);
  29255. const ParamSlider& operator= (const ParamSlider&);
  29256. };
  29257. ProcessorParameterPropertyComp (const ProcessorParameterPropertyComp&);
  29258. const ProcessorParameterPropertyComp& operator= (const ProcessorParameterPropertyComp&);
  29259. };
  29260. GenericAudioProcessorEditor::GenericAudioProcessorEditor (AudioProcessor* const owner_)
  29261. : AudioProcessorEditor (owner_)
  29262. {
  29263. setOpaque (true);
  29264. addAndMakeVisible (panel = new PropertyPanel());
  29265. Array <PropertyComponent*> params;
  29266. const int numParams = owner_->getNumParameters();
  29267. int totalHeight = 0;
  29268. for (int i = 0; i < numParams; ++i)
  29269. {
  29270. String name (owner_->getParameterName (i));
  29271. if (name.trim().isEmpty())
  29272. name = "Unnamed";
  29273. ProcessorParameterPropertyComp* const pc = new ProcessorParameterPropertyComp (name, owner_, i);
  29274. params.add (pc);
  29275. totalHeight += pc->getPreferredHeight();
  29276. }
  29277. panel->addProperties (params);
  29278. setSize (400, jlimit (25, 400, totalHeight));
  29279. }
  29280. GenericAudioProcessorEditor::~GenericAudioProcessorEditor()
  29281. {
  29282. deleteAllChildren();
  29283. }
  29284. void GenericAudioProcessorEditor::paint (Graphics& g)
  29285. {
  29286. g.fillAll (Colours::white);
  29287. }
  29288. void GenericAudioProcessorEditor::resized()
  29289. {
  29290. panel->setSize (getWidth(), getHeight());
  29291. }
  29292. END_JUCE_NAMESPACE
  29293. /********* End of inlined file: juce_GenericAudioProcessorEditor.cpp *********/
  29294. /********* Start of inlined file: juce_Sampler.cpp *********/
  29295. BEGIN_JUCE_NAMESPACE
  29296. SamplerSound::SamplerSound (const String& name_,
  29297. AudioFormatReader& source,
  29298. const BitArray& midiNotes_,
  29299. const int midiNoteForNormalPitch,
  29300. const double attackTimeSecs,
  29301. const double releaseTimeSecs,
  29302. const double maxSampleLengthSeconds)
  29303. : name (name_),
  29304. midiNotes (midiNotes_),
  29305. midiRootNote (midiNoteForNormalPitch)
  29306. {
  29307. sourceSampleRate = source.sampleRate;
  29308. if (sourceSampleRate <= 0 || source.lengthInSamples <= 0)
  29309. {
  29310. length = 0;
  29311. attackSamples = 0;
  29312. releaseSamples = 0;
  29313. }
  29314. else
  29315. {
  29316. length = jmin ((int) source.lengthInSamples,
  29317. (int) (maxSampleLengthSeconds * sourceSampleRate));
  29318. data = new AudioSampleBuffer (jmin (2, (int) source.numChannels), length + 4);
  29319. data->readFromAudioReader (&source, 0, length + 4, 0, true, true);
  29320. attackSamples = roundToInt (attackTimeSecs * sourceSampleRate);
  29321. releaseSamples = roundToInt (releaseTimeSecs * sourceSampleRate);
  29322. }
  29323. }
  29324. SamplerSound::~SamplerSound()
  29325. {
  29326. }
  29327. bool SamplerSound::appliesToNote (const int midiNoteNumber)
  29328. {
  29329. return midiNotes [midiNoteNumber];
  29330. }
  29331. bool SamplerSound::appliesToChannel (const int /*midiChannel*/)
  29332. {
  29333. return true;
  29334. }
  29335. SamplerVoice::SamplerVoice()
  29336. : pitchRatio (0.0),
  29337. sourceSamplePosition (0.0),
  29338. lgain (0.0f),
  29339. rgain (0.0f),
  29340. isInAttack (false),
  29341. isInRelease (false)
  29342. {
  29343. }
  29344. SamplerVoice::~SamplerVoice()
  29345. {
  29346. }
  29347. bool SamplerVoice::canPlaySound (SynthesiserSound* sound)
  29348. {
  29349. return dynamic_cast <const SamplerSound*> (sound) != 0;
  29350. }
  29351. void SamplerVoice::startNote (const int midiNoteNumber,
  29352. const float velocity,
  29353. SynthesiserSound* s,
  29354. const int /*currentPitchWheelPosition*/)
  29355. {
  29356. const SamplerSound* const sound = dynamic_cast <const SamplerSound*> (s);
  29357. jassert (sound != 0); // this object can only play SamplerSounds!
  29358. if (sound != 0)
  29359. {
  29360. const double targetFreq = MidiMessage::getMidiNoteInHertz (midiNoteNumber);
  29361. const double naturalFreq = MidiMessage::getMidiNoteInHertz (sound->midiRootNote);
  29362. pitchRatio = (targetFreq * sound->sourceSampleRate) / (naturalFreq * getSampleRate());
  29363. sourceSamplePosition = 0.0;
  29364. lgain = velocity;
  29365. rgain = velocity;
  29366. isInAttack = (sound->attackSamples > 0);
  29367. isInRelease = false;
  29368. if (isInAttack)
  29369. {
  29370. attackReleaseLevel = 0.0f;
  29371. attackDelta = (float) (pitchRatio / sound->attackSamples);
  29372. }
  29373. else
  29374. {
  29375. attackReleaseLevel = 1.0f;
  29376. attackDelta = 0.0f;
  29377. }
  29378. if (sound->releaseSamples > 0)
  29379. {
  29380. releaseDelta = (float) (-pitchRatio / sound->releaseSamples);
  29381. }
  29382. else
  29383. {
  29384. releaseDelta = 0.0f;
  29385. }
  29386. }
  29387. }
  29388. void SamplerVoice::stopNote (const bool allowTailOff)
  29389. {
  29390. if (allowTailOff)
  29391. {
  29392. isInAttack = false;
  29393. isInRelease = true;
  29394. }
  29395. else
  29396. {
  29397. clearCurrentNote();
  29398. }
  29399. }
  29400. void SamplerVoice::pitchWheelMoved (const int /*newValue*/)
  29401. {
  29402. }
  29403. void SamplerVoice::controllerMoved (const int /*controllerNumber*/,
  29404. const int /*newValue*/)
  29405. {
  29406. }
  29407. void SamplerVoice::renderNextBlock (AudioSampleBuffer& outputBuffer, int startSample, int numSamples)
  29408. {
  29409. const SamplerSound* const playingSound = (SamplerSound*) (SynthesiserSound*) getCurrentlyPlayingSound();
  29410. if (playingSound != 0)
  29411. {
  29412. const float* const inL = playingSound->data->getSampleData (0, 0);
  29413. const float* const inR = playingSound->data->getNumChannels() > 1
  29414. ? playingSound->data->getSampleData (1, 0) : 0;
  29415. float* outL = outputBuffer.getSampleData (0, startSample);
  29416. float* outR = outputBuffer.getNumChannels() > 1 ? outputBuffer.getSampleData (1, startSample) : 0;
  29417. while (--numSamples >= 0)
  29418. {
  29419. const int pos = (int) sourceSamplePosition;
  29420. const float alpha = (float) (sourceSamplePosition - pos);
  29421. const float invAlpha = 1.0f - alpha;
  29422. // just using a very simple linear interpolation here..
  29423. float l = (inL [pos] * invAlpha + inL [pos + 1] * alpha);
  29424. float r = (inR != 0) ? (inR [pos] * invAlpha + inR [pos + 1] * alpha)
  29425. : l;
  29426. l *= lgain;
  29427. r *= rgain;
  29428. if (isInAttack)
  29429. {
  29430. l *= attackReleaseLevel;
  29431. r *= attackReleaseLevel;
  29432. attackReleaseLevel += attackDelta;
  29433. if (attackReleaseLevel >= 1.0f)
  29434. {
  29435. attackReleaseLevel = 1.0f;
  29436. isInAttack = false;
  29437. }
  29438. }
  29439. else if (isInRelease)
  29440. {
  29441. l *= attackReleaseLevel;
  29442. r *= attackReleaseLevel;
  29443. attackReleaseLevel += releaseDelta;
  29444. if (attackReleaseLevel <= 0.0f)
  29445. {
  29446. stopNote (false);
  29447. break;
  29448. }
  29449. }
  29450. if (outR != 0)
  29451. {
  29452. *outL++ += l;
  29453. *outR++ += r;
  29454. }
  29455. else
  29456. {
  29457. *outL++ += (l + r) * 0.5f;
  29458. }
  29459. sourceSamplePosition += pitchRatio;
  29460. if (sourceSamplePosition > playingSound->length)
  29461. {
  29462. stopNote (false);
  29463. break;
  29464. }
  29465. }
  29466. }
  29467. }
  29468. END_JUCE_NAMESPACE
  29469. /********* End of inlined file: juce_Sampler.cpp *********/
  29470. /********* Start of inlined file: juce_Synthesiser.cpp *********/
  29471. BEGIN_JUCE_NAMESPACE
  29472. SynthesiserSound::SynthesiserSound()
  29473. {
  29474. }
  29475. SynthesiserSound::~SynthesiserSound()
  29476. {
  29477. }
  29478. SynthesiserVoice::SynthesiserVoice()
  29479. : currentSampleRate (44100.0),
  29480. currentlyPlayingNote (-1),
  29481. noteOnTime (0),
  29482. currentlyPlayingSound (0)
  29483. {
  29484. }
  29485. SynthesiserVoice::~SynthesiserVoice()
  29486. {
  29487. }
  29488. bool SynthesiserVoice::isPlayingChannel (const int midiChannel) const
  29489. {
  29490. return currentlyPlayingSound != 0
  29491. && currentlyPlayingSound->appliesToChannel (midiChannel);
  29492. }
  29493. void SynthesiserVoice::setCurrentPlaybackSampleRate (const double newRate)
  29494. {
  29495. currentSampleRate = newRate;
  29496. }
  29497. void SynthesiserVoice::clearCurrentNote()
  29498. {
  29499. currentlyPlayingNote = -1;
  29500. currentlyPlayingSound = 0;
  29501. }
  29502. Synthesiser::Synthesiser()
  29503. : sampleRate (0),
  29504. lastNoteOnCounter (0),
  29505. shouldStealNotes (true)
  29506. {
  29507. for (int i = 0; i < numElementsInArray (lastPitchWheelValues); ++i)
  29508. lastPitchWheelValues[i] = 0x2000;
  29509. }
  29510. Synthesiser::~Synthesiser()
  29511. {
  29512. }
  29513. SynthesiserVoice* Synthesiser::getVoice (const int index) const
  29514. {
  29515. const ScopedLock sl (lock);
  29516. return voices [index];
  29517. }
  29518. void Synthesiser::clearVoices()
  29519. {
  29520. const ScopedLock sl (lock);
  29521. voices.clear();
  29522. }
  29523. void Synthesiser::addVoice (SynthesiserVoice* const newVoice)
  29524. {
  29525. const ScopedLock sl (lock);
  29526. voices.add (newVoice);
  29527. }
  29528. void Synthesiser::removeVoice (const int index)
  29529. {
  29530. const ScopedLock sl (lock);
  29531. voices.remove (index);
  29532. }
  29533. void Synthesiser::clearSounds()
  29534. {
  29535. const ScopedLock sl (lock);
  29536. sounds.clear();
  29537. }
  29538. void Synthesiser::addSound (const SynthesiserSound::Ptr& newSound)
  29539. {
  29540. const ScopedLock sl (lock);
  29541. sounds.add (newSound);
  29542. }
  29543. void Synthesiser::removeSound (const int index)
  29544. {
  29545. const ScopedLock sl (lock);
  29546. sounds.remove (index);
  29547. }
  29548. void Synthesiser::setNoteStealingEnabled (const bool shouldStealNotes_)
  29549. {
  29550. shouldStealNotes = shouldStealNotes_;
  29551. }
  29552. void Synthesiser::setCurrentPlaybackSampleRate (const double newRate)
  29553. {
  29554. if (sampleRate != newRate)
  29555. {
  29556. const ScopedLock sl (lock);
  29557. allNotesOff (0, false);
  29558. sampleRate = newRate;
  29559. for (int i = voices.size(); --i >= 0;)
  29560. voices.getUnchecked (i)->setCurrentPlaybackSampleRate (newRate);
  29561. }
  29562. }
  29563. void Synthesiser::renderNextBlock (AudioSampleBuffer& outputBuffer,
  29564. const MidiBuffer& midiData,
  29565. int startSample,
  29566. int numSamples)
  29567. {
  29568. // must set the sample rate before using this!
  29569. jassert (sampleRate != 0);
  29570. const ScopedLock sl (lock);
  29571. MidiBuffer::Iterator midiIterator (midiData);
  29572. midiIterator.setNextSamplePosition (startSample);
  29573. MidiMessage m (0xf4, 0.0);
  29574. while (numSamples > 0)
  29575. {
  29576. int midiEventPos;
  29577. const bool useEvent = midiIterator.getNextEvent (m, midiEventPos)
  29578. && midiEventPos < startSample + numSamples;
  29579. const int numThisTime = useEvent ? midiEventPos - startSample
  29580. : numSamples;
  29581. if (numThisTime > 0)
  29582. {
  29583. for (int i = voices.size(); --i >= 0;)
  29584. voices.getUnchecked (i)->renderNextBlock (outputBuffer, startSample, numThisTime);
  29585. }
  29586. if (useEvent)
  29587. {
  29588. if (m.isNoteOn())
  29589. {
  29590. const int channel = m.getChannel();
  29591. noteOn (channel,
  29592. m.getNoteNumber(),
  29593. m.getFloatVelocity());
  29594. }
  29595. else if (m.isNoteOff())
  29596. {
  29597. noteOff (m.getChannel(),
  29598. m.getNoteNumber(),
  29599. true);
  29600. }
  29601. else if (m.isAllNotesOff() || m.isAllSoundOff())
  29602. {
  29603. allNotesOff (m.getChannel(), true);
  29604. }
  29605. else if (m.isPitchWheel())
  29606. {
  29607. const int channel = m.getChannel();
  29608. const int wheelPos = m.getPitchWheelValue();
  29609. lastPitchWheelValues [channel - 1] = wheelPos;
  29610. handlePitchWheel (channel, wheelPos);
  29611. }
  29612. else if (m.isController())
  29613. {
  29614. handleController (m.getChannel(),
  29615. m.getControllerNumber(),
  29616. m.getControllerValue());
  29617. }
  29618. }
  29619. startSample += numThisTime;
  29620. numSamples -= numThisTime;
  29621. }
  29622. }
  29623. void Synthesiser::noteOn (const int midiChannel,
  29624. const int midiNoteNumber,
  29625. const float velocity)
  29626. {
  29627. const ScopedLock sl (lock);
  29628. for (int i = sounds.size(); --i >= 0;)
  29629. {
  29630. SynthesiserSound* const sound = sounds.getUnchecked(i);
  29631. if (sound->appliesToNote (midiNoteNumber)
  29632. && sound->appliesToChannel (midiChannel))
  29633. {
  29634. startVoice (findFreeVoice (sound, shouldStealNotes),
  29635. sound, midiChannel, midiNoteNumber, velocity);
  29636. }
  29637. }
  29638. }
  29639. void Synthesiser::startVoice (SynthesiserVoice* const voice,
  29640. SynthesiserSound* const sound,
  29641. const int midiChannel,
  29642. const int midiNoteNumber,
  29643. const float velocity)
  29644. {
  29645. if (voice != 0 && sound != 0)
  29646. {
  29647. if (voice->currentlyPlayingSound != 0)
  29648. voice->stopNote (false);
  29649. voice->startNote (midiNoteNumber,
  29650. velocity,
  29651. sound,
  29652. lastPitchWheelValues [midiChannel - 1]);
  29653. voice->currentlyPlayingNote = midiNoteNumber;
  29654. voice->noteOnTime = ++lastNoteOnCounter;
  29655. voice->currentlyPlayingSound = sound;
  29656. }
  29657. }
  29658. void Synthesiser::noteOff (const int midiChannel,
  29659. const int midiNoteNumber,
  29660. const bool allowTailOff)
  29661. {
  29662. const ScopedLock sl (lock);
  29663. for (int i = voices.size(); --i >= 0;)
  29664. {
  29665. SynthesiserVoice* const voice = voices.getUnchecked (i);
  29666. if (voice->getCurrentlyPlayingNote() == midiNoteNumber)
  29667. {
  29668. SynthesiserSound* const sound = voice->getCurrentlyPlayingSound();
  29669. if (sound != 0
  29670. && sound->appliesToNote (midiNoteNumber)
  29671. && sound->appliesToChannel (midiChannel))
  29672. {
  29673. voice->stopNote (allowTailOff);
  29674. // the subclass MUST call clearCurrentNote() if it's not tailing off! RTFM for stopNote()!
  29675. jassert (allowTailOff || (voice->getCurrentlyPlayingNote() < 0 && voice->getCurrentlyPlayingSound() == 0));
  29676. }
  29677. }
  29678. }
  29679. }
  29680. void Synthesiser::allNotesOff (const int midiChannel,
  29681. const bool allowTailOff)
  29682. {
  29683. const ScopedLock sl (lock);
  29684. for (int i = voices.size(); --i >= 0;)
  29685. {
  29686. SynthesiserVoice* const voice = voices.getUnchecked (i);
  29687. if (midiChannel <= 0 || voice->isPlayingChannel (midiChannel))
  29688. voice->stopNote (allowTailOff);
  29689. }
  29690. }
  29691. void Synthesiser::handlePitchWheel (const int midiChannel,
  29692. const int wheelValue)
  29693. {
  29694. const ScopedLock sl (lock);
  29695. for (int i = voices.size(); --i >= 0;)
  29696. {
  29697. SynthesiserVoice* const voice = voices.getUnchecked (i);
  29698. if (midiChannel <= 0 || voice->isPlayingChannel (midiChannel))
  29699. {
  29700. voice->pitchWheelMoved (wheelValue);
  29701. }
  29702. }
  29703. }
  29704. void Synthesiser::handleController (const int midiChannel,
  29705. const int controllerNumber,
  29706. const int controllerValue)
  29707. {
  29708. const ScopedLock sl (lock);
  29709. for (int i = voices.size(); --i >= 0;)
  29710. {
  29711. SynthesiserVoice* const voice = voices.getUnchecked (i);
  29712. if (midiChannel <= 0 || voice->isPlayingChannel (midiChannel))
  29713. voice->controllerMoved (controllerNumber, controllerValue);
  29714. }
  29715. }
  29716. SynthesiserVoice* Synthesiser::findFreeVoice (SynthesiserSound* soundToPlay,
  29717. const bool stealIfNoneAvailable) const
  29718. {
  29719. const ScopedLock sl (lock);
  29720. for (int i = voices.size(); --i >= 0;)
  29721. if (voices.getUnchecked (i)->getCurrentlyPlayingNote() < 0
  29722. && voices.getUnchecked (i)->canPlaySound (soundToPlay))
  29723. return voices.getUnchecked (i);
  29724. if (stealIfNoneAvailable)
  29725. {
  29726. // currently this just steals the one that's been playing the longest, but could be made a bit smarter..
  29727. SynthesiserVoice* oldest = 0;
  29728. for (int i = voices.size(); --i >= 0;)
  29729. {
  29730. SynthesiserVoice* const voice = voices.getUnchecked (i);
  29731. if (voice->canPlaySound (soundToPlay)
  29732. && (oldest == 0 || oldest->noteOnTime > voice->noteOnTime))
  29733. oldest = voice;
  29734. }
  29735. jassert (oldest != 0);
  29736. return oldest;
  29737. }
  29738. return 0;
  29739. }
  29740. END_JUCE_NAMESPACE
  29741. /********* End of inlined file: juce_Synthesiser.cpp *********/
  29742. /********* Start of inlined file: juce_ActionBroadcaster.cpp *********/
  29743. BEGIN_JUCE_NAMESPACE
  29744. ActionBroadcaster::ActionBroadcaster() throw()
  29745. {
  29746. // are you trying to create this object before or after juce has been intialised??
  29747. jassert (MessageManager::instance != 0);
  29748. }
  29749. ActionBroadcaster::~ActionBroadcaster()
  29750. {
  29751. // all event-based objects must be deleted BEFORE juce is shut down!
  29752. jassert (MessageManager::instance != 0);
  29753. }
  29754. void ActionBroadcaster::addActionListener (ActionListener* const listener)
  29755. {
  29756. actionListenerList.addActionListener (listener);
  29757. }
  29758. void ActionBroadcaster::removeActionListener (ActionListener* const listener)
  29759. {
  29760. jassert (actionListenerList.isValidMessageListener());
  29761. if (actionListenerList.isValidMessageListener())
  29762. actionListenerList.removeActionListener (listener);
  29763. }
  29764. void ActionBroadcaster::removeAllActionListeners()
  29765. {
  29766. actionListenerList.removeAllActionListeners();
  29767. }
  29768. void ActionBroadcaster::sendActionMessage (const String& message) const
  29769. {
  29770. actionListenerList.sendActionMessage (message);
  29771. }
  29772. END_JUCE_NAMESPACE
  29773. /********* End of inlined file: juce_ActionBroadcaster.cpp *********/
  29774. /********* Start of inlined file: juce_ActionListenerList.cpp *********/
  29775. BEGIN_JUCE_NAMESPACE
  29776. // special message of our own with a string in it
  29777. class ActionMessage : public Message
  29778. {
  29779. public:
  29780. const String message;
  29781. ActionMessage (const String& messageText,
  29782. void* const listener_) throw()
  29783. : message (messageText)
  29784. {
  29785. pointerParameter = listener_;
  29786. }
  29787. ~ActionMessage() throw()
  29788. {
  29789. }
  29790. private:
  29791. ActionMessage (const ActionMessage&);
  29792. const ActionMessage& operator= (const ActionMessage&);
  29793. };
  29794. ActionListenerList::ActionListenerList() throw()
  29795. {
  29796. }
  29797. ActionListenerList::~ActionListenerList() throw()
  29798. {
  29799. }
  29800. void ActionListenerList::addActionListener (ActionListener* const listener) throw()
  29801. {
  29802. const ScopedLock sl (actionListenerLock_);
  29803. jassert (listener != 0);
  29804. jassert (! actionListeners_.contains (listener)); // trying to add a listener to the list twice!
  29805. if (listener != 0)
  29806. actionListeners_.add (listener);
  29807. }
  29808. void ActionListenerList::removeActionListener (ActionListener* const listener) throw()
  29809. {
  29810. const ScopedLock sl (actionListenerLock_);
  29811. jassert (actionListeners_.contains (listener)); // trying to remove a listener that isn't on the list!
  29812. actionListeners_.removeValue (listener);
  29813. }
  29814. void ActionListenerList::removeAllActionListeners() throw()
  29815. {
  29816. const ScopedLock sl (actionListenerLock_);
  29817. actionListeners_.clear();
  29818. }
  29819. void ActionListenerList::sendActionMessage (const String& message) const
  29820. {
  29821. const ScopedLock sl (actionListenerLock_);
  29822. for (int i = actionListeners_.size(); --i >= 0;)
  29823. {
  29824. postMessage (new ActionMessage (message,
  29825. (ActionListener*) actionListeners_.getUnchecked(i)));
  29826. }
  29827. }
  29828. void ActionListenerList::handleMessage (const Message& message)
  29829. {
  29830. const ActionMessage& am = (const ActionMessage&) message;
  29831. if (actionListeners_.contains (am.pointerParameter))
  29832. ((ActionListener*) am.pointerParameter)->actionListenerCallback (am.message);
  29833. }
  29834. END_JUCE_NAMESPACE
  29835. /********* End of inlined file: juce_ActionListenerList.cpp *********/
  29836. /********* Start of inlined file: juce_AsyncUpdater.cpp *********/
  29837. BEGIN_JUCE_NAMESPACE
  29838. AsyncUpdater::AsyncUpdater() throw()
  29839. : asyncMessagePending (false)
  29840. {
  29841. internalAsyncHandler.owner = this;
  29842. }
  29843. AsyncUpdater::~AsyncUpdater()
  29844. {
  29845. }
  29846. void AsyncUpdater::triggerAsyncUpdate() throw()
  29847. {
  29848. if (! asyncMessagePending)
  29849. {
  29850. asyncMessagePending = true;
  29851. internalAsyncHandler.postMessage (new Message());
  29852. }
  29853. }
  29854. void AsyncUpdater::cancelPendingUpdate() throw()
  29855. {
  29856. asyncMessagePending = false;
  29857. }
  29858. void AsyncUpdater::handleUpdateNowIfNeeded()
  29859. {
  29860. if (asyncMessagePending)
  29861. {
  29862. asyncMessagePending = false;
  29863. handleAsyncUpdate();
  29864. }
  29865. }
  29866. void AsyncUpdater::AsyncUpdaterInternal::handleMessage (const Message&)
  29867. {
  29868. owner->handleUpdateNowIfNeeded();
  29869. }
  29870. END_JUCE_NAMESPACE
  29871. /********* End of inlined file: juce_AsyncUpdater.cpp *********/
  29872. /********* Start of inlined file: juce_ChangeBroadcaster.cpp *********/
  29873. BEGIN_JUCE_NAMESPACE
  29874. ChangeBroadcaster::ChangeBroadcaster() throw()
  29875. {
  29876. // are you trying to create this object before or after juce has been intialised??
  29877. jassert (MessageManager::instance != 0);
  29878. }
  29879. ChangeBroadcaster::~ChangeBroadcaster()
  29880. {
  29881. // all event-based objects must be deleted BEFORE juce is shut down!
  29882. jassert (MessageManager::instance != 0);
  29883. }
  29884. void ChangeBroadcaster::addChangeListener (ChangeListener* const listener) throw()
  29885. {
  29886. changeListenerList.addChangeListener (listener);
  29887. }
  29888. void ChangeBroadcaster::removeChangeListener (ChangeListener* const listener) throw()
  29889. {
  29890. jassert (changeListenerList.isValidMessageListener());
  29891. if (changeListenerList.isValidMessageListener())
  29892. changeListenerList.removeChangeListener (listener);
  29893. }
  29894. void ChangeBroadcaster::removeAllChangeListeners() throw()
  29895. {
  29896. changeListenerList.removeAllChangeListeners();
  29897. }
  29898. void ChangeBroadcaster::sendChangeMessage (void* objectThatHasChanged) throw()
  29899. {
  29900. changeListenerList.sendChangeMessage (objectThatHasChanged);
  29901. }
  29902. void ChangeBroadcaster::sendSynchronousChangeMessage (void* objectThatHasChanged)
  29903. {
  29904. changeListenerList.sendSynchronousChangeMessage (objectThatHasChanged);
  29905. }
  29906. void ChangeBroadcaster::dispatchPendingMessages()
  29907. {
  29908. changeListenerList.dispatchPendingMessages();
  29909. }
  29910. END_JUCE_NAMESPACE
  29911. /********* End of inlined file: juce_ChangeBroadcaster.cpp *********/
  29912. /********* Start of inlined file: juce_ChangeListenerList.cpp *********/
  29913. BEGIN_JUCE_NAMESPACE
  29914. ChangeListenerList::ChangeListenerList() throw()
  29915. : lastChangedObject (0),
  29916. messagePending (false)
  29917. {
  29918. }
  29919. ChangeListenerList::~ChangeListenerList() throw()
  29920. {
  29921. }
  29922. void ChangeListenerList::addChangeListener (ChangeListener* const listener) throw()
  29923. {
  29924. const ScopedLock sl (lock);
  29925. jassert (listener != 0);
  29926. if (listener != 0)
  29927. listeners.add (listener);
  29928. }
  29929. void ChangeListenerList::removeChangeListener (ChangeListener* const listener) throw()
  29930. {
  29931. const ScopedLock sl (lock);
  29932. listeners.removeValue (listener);
  29933. }
  29934. void ChangeListenerList::removeAllChangeListeners() throw()
  29935. {
  29936. const ScopedLock sl (lock);
  29937. listeners.clear();
  29938. }
  29939. void ChangeListenerList::sendChangeMessage (void* const objectThatHasChanged) throw()
  29940. {
  29941. const ScopedLock sl (lock);
  29942. if ((! messagePending) && (listeners.size() > 0))
  29943. {
  29944. lastChangedObject = objectThatHasChanged;
  29945. postMessage (new Message (0, 0, 0, objectThatHasChanged));
  29946. messagePending = true;
  29947. }
  29948. }
  29949. void ChangeListenerList::handleMessage (const Message& message)
  29950. {
  29951. sendSynchronousChangeMessage (message.pointerParameter);
  29952. }
  29953. void ChangeListenerList::sendSynchronousChangeMessage (void* const objectThatHasChanged)
  29954. {
  29955. const ScopedLock sl (lock);
  29956. messagePending = false;
  29957. for (int i = listeners.size(); --i >= 0;)
  29958. {
  29959. ChangeListener* const l = (ChangeListener*) listeners.getUnchecked (i);
  29960. {
  29961. const ScopedUnlock tempUnlocker (lock);
  29962. l->changeListenerCallback (objectThatHasChanged);
  29963. }
  29964. i = jmin (i, listeners.size());
  29965. }
  29966. }
  29967. void ChangeListenerList::dispatchPendingMessages()
  29968. {
  29969. if (messagePending)
  29970. sendSynchronousChangeMessage (lastChangedObject);
  29971. }
  29972. END_JUCE_NAMESPACE
  29973. /********* End of inlined file: juce_ChangeListenerList.cpp *********/
  29974. /********* Start of inlined file: juce_InterprocessConnection.cpp *********/
  29975. BEGIN_JUCE_NAMESPACE
  29976. InterprocessConnection::InterprocessConnection (const bool callbacksOnMessageThread,
  29977. const uint32 magicMessageHeaderNumber)
  29978. : Thread ("Juce IPC connection"),
  29979. callbackConnectionState (false),
  29980. useMessageThread (callbacksOnMessageThread),
  29981. magicMessageHeader (magicMessageHeaderNumber),
  29982. pipeReceiveMessageTimeout (-1)
  29983. {
  29984. }
  29985. InterprocessConnection::~InterprocessConnection()
  29986. {
  29987. callbackConnectionState = false;
  29988. disconnect();
  29989. }
  29990. bool InterprocessConnection::connectToSocket (const String& hostName,
  29991. const int portNumber,
  29992. const int timeOutMillisecs)
  29993. {
  29994. disconnect();
  29995. const ScopedLock sl (pipeAndSocketLock);
  29996. socket = new StreamingSocket();
  29997. if (socket->connect (hostName, portNumber, timeOutMillisecs))
  29998. {
  29999. connectionMadeInt();
  30000. startThread();
  30001. return true;
  30002. }
  30003. else
  30004. {
  30005. socket = 0;
  30006. return false;
  30007. }
  30008. }
  30009. bool InterprocessConnection::connectToPipe (const String& pipeName,
  30010. const int pipeReceiveMessageTimeoutMs)
  30011. {
  30012. disconnect();
  30013. ScopedPointer <NamedPipe> newPipe (new NamedPipe());
  30014. if (newPipe->openExisting (pipeName))
  30015. {
  30016. const ScopedLock sl (pipeAndSocketLock);
  30017. pipeReceiveMessageTimeout = pipeReceiveMessageTimeoutMs;
  30018. initialiseWithPipe (newPipe.release());
  30019. return true;
  30020. }
  30021. return false;
  30022. }
  30023. bool InterprocessConnection::createPipe (const String& pipeName,
  30024. const int pipeReceiveMessageTimeoutMs)
  30025. {
  30026. disconnect();
  30027. ScopedPointer <NamedPipe> newPipe (new NamedPipe());
  30028. if (newPipe->createNewPipe (pipeName))
  30029. {
  30030. const ScopedLock sl (pipeAndSocketLock);
  30031. pipeReceiveMessageTimeout = pipeReceiveMessageTimeoutMs;
  30032. initialiseWithPipe (newPipe.release());
  30033. return true;
  30034. }
  30035. return false;
  30036. }
  30037. void InterprocessConnection::disconnect()
  30038. {
  30039. if (socket != 0)
  30040. socket->close();
  30041. if (pipe != 0)
  30042. {
  30043. pipe->cancelPendingReads();
  30044. pipe->close();
  30045. }
  30046. stopThread (4000);
  30047. {
  30048. const ScopedLock sl (pipeAndSocketLock);
  30049. socket = 0;
  30050. pipe = 0;
  30051. }
  30052. connectionLostInt();
  30053. }
  30054. bool InterprocessConnection::isConnected() const
  30055. {
  30056. const ScopedLock sl (pipeAndSocketLock);
  30057. return ((socket != 0 && socket->isConnected())
  30058. || (pipe != 0 && pipe->isOpen()))
  30059. && isThreadRunning();
  30060. }
  30061. const String InterprocessConnection::getConnectedHostName() const
  30062. {
  30063. if (pipe != 0)
  30064. {
  30065. return "localhost";
  30066. }
  30067. else if (socket != 0)
  30068. {
  30069. if (! socket->isLocal())
  30070. return socket->getHostName();
  30071. return "localhost";
  30072. }
  30073. return String::empty;
  30074. }
  30075. bool InterprocessConnection::sendMessage (const MemoryBlock& message)
  30076. {
  30077. uint32 messageHeader[2];
  30078. messageHeader [0] = ByteOrder::swapIfBigEndian (magicMessageHeader);
  30079. messageHeader [1] = ByteOrder::swapIfBigEndian ((uint32) message.getSize());
  30080. MemoryBlock messageData (sizeof (messageHeader) + message.getSize());
  30081. messageData.copyFrom (messageHeader, 0, sizeof (messageHeader));
  30082. messageData.copyFrom (message.getData(), sizeof (messageHeader), message.getSize());
  30083. size_t bytesWritten = 0;
  30084. const ScopedLock sl (pipeAndSocketLock);
  30085. if (socket != 0)
  30086. {
  30087. bytesWritten = socket->write (messageData.getData(), (int) messageData.getSize());
  30088. }
  30089. else if (pipe != 0)
  30090. {
  30091. bytesWritten = pipe->write (messageData.getData(), (int) messageData.getSize());
  30092. }
  30093. if (bytesWritten < 0)
  30094. {
  30095. // error..
  30096. return false;
  30097. }
  30098. return (bytesWritten == messageData.getSize());
  30099. }
  30100. void InterprocessConnection::initialiseWithSocket (StreamingSocket* const socket_)
  30101. {
  30102. jassert (socket == 0);
  30103. socket = socket_;
  30104. connectionMadeInt();
  30105. startThread();
  30106. }
  30107. void InterprocessConnection::initialiseWithPipe (NamedPipe* const pipe_)
  30108. {
  30109. jassert (pipe == 0);
  30110. pipe = pipe_;
  30111. connectionMadeInt();
  30112. startThread();
  30113. }
  30114. const int messageMagicNumber = 0xb734128b;
  30115. void InterprocessConnection::handleMessage (const Message& message)
  30116. {
  30117. if (message.intParameter1 == messageMagicNumber)
  30118. {
  30119. switch (message.intParameter2)
  30120. {
  30121. case 0:
  30122. {
  30123. ScopedPointer <MemoryBlock> data ((MemoryBlock*) message.pointerParameter);
  30124. messageReceived (*data);
  30125. break;
  30126. }
  30127. case 1:
  30128. connectionMade();
  30129. break;
  30130. case 2:
  30131. connectionLost();
  30132. break;
  30133. }
  30134. }
  30135. }
  30136. void InterprocessConnection::connectionMadeInt()
  30137. {
  30138. if (! callbackConnectionState)
  30139. {
  30140. callbackConnectionState = true;
  30141. if (useMessageThread)
  30142. postMessage (new Message (messageMagicNumber, 1, 0, 0));
  30143. else
  30144. connectionMade();
  30145. }
  30146. }
  30147. void InterprocessConnection::connectionLostInt()
  30148. {
  30149. if (callbackConnectionState)
  30150. {
  30151. callbackConnectionState = false;
  30152. if (useMessageThread)
  30153. postMessage (new Message (messageMagicNumber, 2, 0, 0));
  30154. else
  30155. connectionLost();
  30156. }
  30157. }
  30158. void InterprocessConnection::deliverDataInt (const MemoryBlock& data)
  30159. {
  30160. jassert (callbackConnectionState);
  30161. if (useMessageThread)
  30162. postMessage (new Message (messageMagicNumber, 0, 0, new MemoryBlock (data)));
  30163. else
  30164. messageReceived (data);
  30165. }
  30166. bool InterprocessConnection::readNextMessageInt()
  30167. {
  30168. const int maximumMessageSize = 1024 * 1024 * 10; // sanity check
  30169. uint32 messageHeader[2];
  30170. const int bytes = (socket != 0) ? socket->read (messageHeader, sizeof (messageHeader), true)
  30171. : pipe->read (messageHeader, sizeof (messageHeader), pipeReceiveMessageTimeout);
  30172. if (bytes == sizeof (messageHeader)
  30173. && ByteOrder::swapIfBigEndian (messageHeader[0]) == magicMessageHeader)
  30174. {
  30175. const int bytesInMessage = (int) ByteOrder::swapIfBigEndian (messageHeader[1]);
  30176. if (bytesInMessage > 0 && bytesInMessage < maximumMessageSize)
  30177. {
  30178. MemoryBlock messageData (bytesInMessage, true);
  30179. int bytesRead = 0;
  30180. while (bytesRead < bytesInMessage)
  30181. {
  30182. if (threadShouldExit())
  30183. return false;
  30184. const int numThisTime = jmin (bytesInMessage, 65536);
  30185. const int bytesIn = (socket != 0) ? socket->read (((char*) messageData.getData()) + bytesRead, numThisTime, true)
  30186. : pipe->read (((char*) messageData.getData()) + bytesRead, numThisTime,
  30187. pipeReceiveMessageTimeout);
  30188. if (bytesIn <= 0)
  30189. break;
  30190. bytesRead += bytesIn;
  30191. }
  30192. if (bytesRead >= 0)
  30193. deliverDataInt (messageData);
  30194. }
  30195. }
  30196. else if (bytes < 0)
  30197. {
  30198. {
  30199. const ScopedLock sl (pipeAndSocketLock);
  30200. socket = 0;
  30201. }
  30202. connectionLostInt();
  30203. return false;
  30204. }
  30205. return true;
  30206. }
  30207. void InterprocessConnection::run()
  30208. {
  30209. while (! threadShouldExit())
  30210. {
  30211. if (socket != 0)
  30212. {
  30213. const int ready = socket->waitUntilReady (true, 0);
  30214. if (ready < 0)
  30215. {
  30216. {
  30217. const ScopedLock sl (pipeAndSocketLock);
  30218. socket = 0;
  30219. }
  30220. connectionLostInt();
  30221. break;
  30222. }
  30223. else if (ready > 0)
  30224. {
  30225. if (! readNextMessageInt())
  30226. break;
  30227. }
  30228. else
  30229. {
  30230. Thread::sleep (2);
  30231. }
  30232. }
  30233. else if (pipe != 0)
  30234. {
  30235. if (! pipe->isOpen())
  30236. {
  30237. {
  30238. const ScopedLock sl (pipeAndSocketLock);
  30239. pipe = 0;
  30240. }
  30241. connectionLostInt();
  30242. break;
  30243. }
  30244. else
  30245. {
  30246. if (! readNextMessageInt())
  30247. break;
  30248. }
  30249. }
  30250. else
  30251. {
  30252. break;
  30253. }
  30254. }
  30255. }
  30256. END_JUCE_NAMESPACE
  30257. /********* End of inlined file: juce_InterprocessConnection.cpp *********/
  30258. /********* Start of inlined file: juce_InterprocessConnectionServer.cpp *********/
  30259. BEGIN_JUCE_NAMESPACE
  30260. InterprocessConnectionServer::InterprocessConnectionServer()
  30261. : Thread ("Juce IPC server")
  30262. {
  30263. }
  30264. InterprocessConnectionServer::~InterprocessConnectionServer()
  30265. {
  30266. stop();
  30267. }
  30268. bool InterprocessConnectionServer::beginWaitingForSocket (const int portNumber)
  30269. {
  30270. stop();
  30271. socket = new StreamingSocket();
  30272. if (socket->createListener (portNumber))
  30273. {
  30274. startThread();
  30275. return true;
  30276. }
  30277. socket = 0;
  30278. return false;
  30279. }
  30280. void InterprocessConnectionServer::stop()
  30281. {
  30282. signalThreadShouldExit();
  30283. if (socket != 0)
  30284. socket->close();
  30285. stopThread (4000);
  30286. socket = 0;
  30287. }
  30288. void InterprocessConnectionServer::run()
  30289. {
  30290. while ((! threadShouldExit()) && socket != 0)
  30291. {
  30292. ScopedPointer <StreamingSocket> clientSocket (socket->waitForNextConnection());
  30293. if (clientSocket != 0)
  30294. {
  30295. InterprocessConnection* newConnection = createConnectionObject();
  30296. if (newConnection != 0)
  30297. newConnection->initialiseWithSocket (clientSocket.release());
  30298. }
  30299. }
  30300. }
  30301. END_JUCE_NAMESPACE
  30302. /********* End of inlined file: juce_InterprocessConnectionServer.cpp *********/
  30303. /********* Start of inlined file: juce_Message.cpp *********/
  30304. BEGIN_JUCE_NAMESPACE
  30305. Message::Message() throw()
  30306. {
  30307. }
  30308. Message::~Message() throw()
  30309. {
  30310. }
  30311. Message::Message (const int intParameter1_,
  30312. const int intParameter2_,
  30313. const int intParameter3_,
  30314. void* const pointerParameter_) throw()
  30315. : intParameter1 (intParameter1_),
  30316. intParameter2 (intParameter2_),
  30317. intParameter3 (intParameter3_),
  30318. pointerParameter (pointerParameter_)
  30319. {
  30320. }
  30321. END_JUCE_NAMESPACE
  30322. /********* End of inlined file: juce_Message.cpp *********/
  30323. /********* Start of inlined file: juce_MessageListener.cpp *********/
  30324. BEGIN_JUCE_NAMESPACE
  30325. MessageListener::MessageListener() throw()
  30326. {
  30327. // are you trying to create a messagelistener before or after juce has been intialised??
  30328. jassert (MessageManager::instance != 0);
  30329. if (MessageManager::instance != 0)
  30330. MessageManager::instance->messageListeners.add (this);
  30331. }
  30332. MessageListener::~MessageListener()
  30333. {
  30334. if (MessageManager::instance != 0)
  30335. MessageManager::instance->messageListeners.removeValue (this);
  30336. }
  30337. void MessageListener::postMessage (Message* const message) const throw()
  30338. {
  30339. message->messageRecipient = const_cast <MessageListener*> (this);
  30340. if (MessageManager::instance == 0)
  30341. MessageManager::getInstance();
  30342. MessageManager::instance->postMessageToQueue (message);
  30343. }
  30344. bool MessageListener::isValidMessageListener() const throw()
  30345. {
  30346. return (MessageManager::instance != 0)
  30347. && MessageManager::instance->messageListeners.contains (this);
  30348. }
  30349. END_JUCE_NAMESPACE
  30350. /********* End of inlined file: juce_MessageListener.cpp *********/
  30351. /********* Start of inlined file: juce_MessageManager.cpp *********/
  30352. BEGIN_JUCE_NAMESPACE
  30353. // platform-specific functions..
  30354. bool juce_dispatchNextMessageOnSystemQueue (bool returnIfNoPendingMessages);
  30355. bool juce_postMessageToSystemQueue (void* message);
  30356. MessageManager* MessageManager::instance = 0;
  30357. static const int quitMessageId = 0xfffff321;
  30358. MessageManager::MessageManager() throw()
  30359. : quitMessagePosted (false),
  30360. quitMessageReceived (false),
  30361. threadWithLock (0)
  30362. {
  30363. messageThreadId = Thread::getCurrentThreadId();
  30364. }
  30365. MessageManager::~MessageManager() throw()
  30366. {
  30367. broadcastListeners = 0;
  30368. doPlatformSpecificShutdown();
  30369. jassert (instance == this);
  30370. instance = 0; // do this last in case this instance is still needed by doPlatformSpecificShutdown()
  30371. }
  30372. MessageManager* MessageManager::getInstance() throw()
  30373. {
  30374. if (instance == 0)
  30375. {
  30376. instance = new MessageManager();
  30377. doPlatformSpecificInitialisation();
  30378. }
  30379. return instance;
  30380. }
  30381. void MessageManager::postMessageToQueue (Message* const message)
  30382. {
  30383. if (quitMessagePosted || ! juce_postMessageToSystemQueue (message))
  30384. delete message;
  30385. }
  30386. CallbackMessage::CallbackMessage() throw() {}
  30387. CallbackMessage::~CallbackMessage() throw() {}
  30388. void CallbackMessage::post()
  30389. {
  30390. if (MessageManager::instance != 0)
  30391. MessageManager::instance->postCallbackMessage (this);
  30392. }
  30393. void MessageManager::postCallbackMessage (Message* const message)
  30394. {
  30395. message->messageRecipient = 0;
  30396. postMessageToQueue (message);
  30397. }
  30398. // not for public use..
  30399. void MessageManager::deliverMessage (void* message)
  30400. {
  30401. const ScopedPointer <Message> m ((Message*) message);
  30402. MessageListener* const recipient = m->messageRecipient;
  30403. JUCE_TRY
  30404. {
  30405. if (messageListeners.contains (recipient))
  30406. {
  30407. recipient->handleMessage (*m);
  30408. }
  30409. else if (recipient == 0)
  30410. {
  30411. if (m->intParameter1 == quitMessageId)
  30412. {
  30413. quitMessageReceived = true;
  30414. }
  30415. else
  30416. {
  30417. CallbackMessage* const cm = dynamic_cast <CallbackMessage*> ((Message*) m);
  30418. if (cm != 0)
  30419. cm->messageCallback();
  30420. }
  30421. }
  30422. }
  30423. JUCE_CATCH_EXCEPTION
  30424. }
  30425. #if ! (JUCE_MAC || JUCE_IPHONE)
  30426. void MessageManager::runDispatchLoop()
  30427. {
  30428. jassert (isThisTheMessageThread()); // must only be called by the message thread
  30429. runDispatchLoopUntil (-1);
  30430. }
  30431. void MessageManager::stopDispatchLoop()
  30432. {
  30433. Message* const m = new Message (quitMessageId, 0, 0, 0);
  30434. m->messageRecipient = 0;
  30435. postMessageToQueue (m);
  30436. quitMessagePosted = true;
  30437. }
  30438. bool MessageManager::runDispatchLoopUntil (int millisecondsToRunFor)
  30439. {
  30440. jassert (isThisTheMessageThread()); // must only be called by the message thread
  30441. const int64 endTime = Time::currentTimeMillis() + millisecondsToRunFor;
  30442. while ((millisecondsToRunFor < 0 || endTime > Time::currentTimeMillis())
  30443. && ! quitMessageReceived)
  30444. {
  30445. JUCE_TRY
  30446. {
  30447. if (! juce_dispatchNextMessageOnSystemQueue (millisecondsToRunFor >= 0))
  30448. {
  30449. const int msToWait = (int) (endTime - Time::currentTimeMillis());
  30450. if (msToWait > 0)
  30451. Thread::sleep (jmin (5, msToWait));
  30452. }
  30453. }
  30454. JUCE_CATCH_EXCEPTION
  30455. }
  30456. return ! quitMessageReceived;
  30457. }
  30458. #endif
  30459. void MessageManager::deliverBroadcastMessage (const String& value)
  30460. {
  30461. if (broadcastListeners != 0)
  30462. broadcastListeners->sendActionMessage (value);
  30463. }
  30464. void MessageManager::registerBroadcastListener (ActionListener* const listener) throw()
  30465. {
  30466. if (broadcastListeners == 0)
  30467. broadcastListeners = new ActionListenerList();
  30468. broadcastListeners->addActionListener (listener);
  30469. }
  30470. void MessageManager::deregisterBroadcastListener (ActionListener* const listener) throw()
  30471. {
  30472. if (broadcastListeners != 0)
  30473. broadcastListeners->removeActionListener (listener);
  30474. }
  30475. bool MessageManager::isThisTheMessageThread() const throw()
  30476. {
  30477. return Thread::getCurrentThreadId() == messageThreadId;
  30478. }
  30479. void MessageManager::setCurrentMessageThread (const Thread::ThreadID threadId) throw()
  30480. {
  30481. messageThreadId = threadId;
  30482. }
  30483. bool MessageManager::currentThreadHasLockedMessageManager() const throw()
  30484. {
  30485. const Thread::ThreadID thisThread = Thread::getCurrentThreadId();
  30486. return thisThread == messageThreadId || thisThread == threadWithLock;
  30487. }
  30488. class SharedLockingEvents : public ReferenceCountedObject
  30489. {
  30490. public:
  30491. SharedLockingEvents() throw() {}
  30492. ~SharedLockingEvents() {}
  30493. WaitableEvent lockedEvent, releaseEvent;
  30494. };
  30495. class MMLockMessage : public CallbackMessage
  30496. {
  30497. public:
  30498. MMLockMessage (SharedLockingEvents* const events_) throw()
  30499. : events (events_)
  30500. {}
  30501. ~MMLockMessage() throw() {}
  30502. ReferenceCountedObjectPtr <SharedLockingEvents> events;
  30503. void messageCallback()
  30504. {
  30505. events->lockedEvent.signal();
  30506. events->releaseEvent.wait();
  30507. }
  30508. juce_UseDebuggingNewOperator
  30509. MMLockMessage (const MMLockMessage&);
  30510. const MMLockMessage& operator= (const MMLockMessage&);
  30511. };
  30512. MessageManagerLock::MessageManagerLock (Thread* const threadToCheck) throw()
  30513. : locked (false),
  30514. needsUnlocking (false)
  30515. {
  30516. init (threadToCheck, 0);
  30517. }
  30518. MessageManagerLock::MessageManagerLock (ThreadPoolJob* const jobToCheckForExitSignal) throw()
  30519. : locked (false),
  30520. needsUnlocking (false)
  30521. {
  30522. init (0, jobToCheckForExitSignal);
  30523. }
  30524. void MessageManagerLock::init (Thread* const threadToCheck, ThreadPoolJob* const job) throw()
  30525. {
  30526. if (MessageManager::instance != 0)
  30527. {
  30528. if (MessageManager::instance->currentThreadHasLockedMessageManager())
  30529. {
  30530. locked = true; // either we're on the message thread, or this is a re-entrant call.
  30531. }
  30532. else
  30533. {
  30534. if (threadToCheck == 0 && job == 0)
  30535. {
  30536. MessageManager::instance->lockingLock.enter();
  30537. }
  30538. else
  30539. {
  30540. while (! MessageManager::instance->lockingLock.tryEnter())
  30541. {
  30542. if ((threadToCheck != 0 && threadToCheck->threadShouldExit())
  30543. || (job != 0 && job->shouldExit()))
  30544. return;
  30545. Thread::sleep (1);
  30546. }
  30547. }
  30548. SharedLockingEvents* const events = new SharedLockingEvents();
  30549. sharedEvents = events;
  30550. events->incReferenceCount();
  30551. (new MMLockMessage (events))->post();
  30552. while (! events->lockedEvent.wait (50))
  30553. {
  30554. if ((threadToCheck != 0 && threadToCheck->threadShouldExit())
  30555. || (job != 0 && job->shouldExit()))
  30556. {
  30557. events->releaseEvent.signal();
  30558. events->decReferenceCount();
  30559. MessageManager::instance->lockingLock.exit();
  30560. return;
  30561. }
  30562. }
  30563. jassert (MessageManager::instance->threadWithLock == 0);
  30564. MessageManager::instance->threadWithLock = Thread::getCurrentThreadId();
  30565. locked = true;
  30566. needsUnlocking = true;
  30567. }
  30568. }
  30569. }
  30570. MessageManagerLock::~MessageManagerLock() throw()
  30571. {
  30572. if (needsUnlocking && MessageManager::instance != 0)
  30573. {
  30574. jassert (MessageManager::instance->currentThreadHasLockedMessageManager());
  30575. ((SharedLockingEvents*) sharedEvents)->releaseEvent.signal();
  30576. ((SharedLockingEvents*) sharedEvents)->decReferenceCount();
  30577. MessageManager::instance->threadWithLock = 0;
  30578. MessageManager::instance->lockingLock.exit();
  30579. }
  30580. }
  30581. END_JUCE_NAMESPACE
  30582. /********* End of inlined file: juce_MessageManager.cpp *********/
  30583. /********* Start of inlined file: juce_MultiTimer.cpp *********/
  30584. BEGIN_JUCE_NAMESPACE
  30585. class MultiTimer::MultiTimerCallback : public Timer
  30586. {
  30587. public:
  30588. MultiTimerCallback (const int timerId_, MultiTimer& owner_)
  30589. : timerId (timerId_),
  30590. owner (owner_)
  30591. {
  30592. }
  30593. ~MultiTimerCallback()
  30594. {
  30595. }
  30596. void timerCallback()
  30597. {
  30598. owner.timerCallback (timerId);
  30599. }
  30600. const int timerId;
  30601. private:
  30602. MultiTimer& owner;
  30603. };
  30604. MultiTimer::MultiTimer() throw()
  30605. {
  30606. }
  30607. MultiTimer::MultiTimer (const MultiTimer&) throw()
  30608. {
  30609. }
  30610. MultiTimer::~MultiTimer()
  30611. {
  30612. const ScopedLock sl (timerListLock);
  30613. timers.clear();
  30614. }
  30615. void MultiTimer::startTimer (const int timerId, const int intervalInMilliseconds) throw()
  30616. {
  30617. const ScopedLock sl (timerListLock);
  30618. for (int i = timers.size(); --i >= 0;)
  30619. {
  30620. MultiTimerCallback* const t = timers.getUnchecked(i);
  30621. if (t->timerId == timerId)
  30622. {
  30623. t->startTimer (intervalInMilliseconds);
  30624. return;
  30625. }
  30626. }
  30627. MultiTimerCallback* const newTimer = new MultiTimerCallback (timerId, *this);
  30628. timers.add (newTimer);
  30629. newTimer->startTimer (intervalInMilliseconds);
  30630. }
  30631. void MultiTimer::stopTimer (const int timerId) throw()
  30632. {
  30633. const ScopedLock sl (timerListLock);
  30634. for (int i = timers.size(); --i >= 0;)
  30635. {
  30636. MultiTimerCallback* const t = timers.getUnchecked(i);
  30637. if (t->timerId == timerId)
  30638. t->stopTimer();
  30639. }
  30640. }
  30641. bool MultiTimer::isTimerRunning (const int timerId) const throw()
  30642. {
  30643. const ScopedLock sl (timerListLock);
  30644. for (int i = timers.size(); --i >= 0;)
  30645. {
  30646. const MultiTimerCallback* const t = timers.getUnchecked(i);
  30647. if (t->timerId == timerId)
  30648. return t->isTimerRunning();
  30649. }
  30650. return false;
  30651. }
  30652. int MultiTimer::getTimerInterval (const int timerId) const throw()
  30653. {
  30654. const ScopedLock sl (timerListLock);
  30655. for (int i = timers.size(); --i >= 0;)
  30656. {
  30657. const MultiTimerCallback* const t = timers.getUnchecked(i);
  30658. if (t->timerId == timerId)
  30659. return t->getTimerInterval();
  30660. }
  30661. return 0;
  30662. }
  30663. END_JUCE_NAMESPACE
  30664. /********* End of inlined file: juce_MultiTimer.cpp *********/
  30665. /********* Start of inlined file: juce_Timer.cpp *********/
  30666. BEGIN_JUCE_NAMESPACE
  30667. class InternalTimerThread : private Thread,
  30668. private MessageListener,
  30669. private DeletedAtShutdown,
  30670. private AsyncUpdater
  30671. {
  30672. public:
  30673. InternalTimerThread()
  30674. : Thread ("Juce Timer"),
  30675. firstTimer (0),
  30676. callbackNeeded (false)
  30677. {
  30678. triggerAsyncUpdate();
  30679. }
  30680. ~InternalTimerThread() throw()
  30681. {
  30682. stopThread (4000);
  30683. jassert (instance == this || instance == 0);
  30684. if (instance == this)
  30685. instance = 0;
  30686. }
  30687. void run()
  30688. {
  30689. uint32 lastTime = Time::getMillisecondCounter();
  30690. while (! threadShouldExit())
  30691. {
  30692. const uint32 now = Time::getMillisecondCounter();
  30693. if (now <= lastTime)
  30694. {
  30695. wait (2);
  30696. continue;
  30697. }
  30698. const int elapsed = now - lastTime;
  30699. lastTime = now;
  30700. lock.enter();
  30701. decrementAllCounters (elapsed);
  30702. const int timeUntilFirstTimer = (firstTimer != 0) ? firstTimer->countdownMs
  30703. : 1000;
  30704. lock.exit();
  30705. if (timeUntilFirstTimer <= 0)
  30706. {
  30707. if (callbackNeeded.set (true))
  30708. {
  30709. postMessage (new Message());
  30710. const uint32 messageDeliveryTimeout = now + 2000;
  30711. while (callbackNeeded.get())
  30712. {
  30713. wait (4);
  30714. if (threadShouldExit())
  30715. return;
  30716. if (Time::getMillisecondCounter() > messageDeliveryTimeout)
  30717. break;
  30718. }
  30719. }
  30720. }
  30721. else
  30722. {
  30723. // don't wait for too long because running this loop also helps keep the
  30724. // Time::getApproximateMillisecondTimer value stay up-to-date
  30725. wait (jlimit (1, 50, timeUntilFirstTimer));
  30726. }
  30727. }
  30728. }
  30729. void handleMessage (const Message&)
  30730. {
  30731. const ScopedLock sl (lock);
  30732. while (firstTimer != 0 && firstTimer->countdownMs <= 0)
  30733. {
  30734. Timer* const t = firstTimer;
  30735. t->countdownMs = t->periodMs;
  30736. removeTimer (t);
  30737. addTimer (t);
  30738. const ScopedUnlock ul (lock);
  30739. JUCE_TRY
  30740. {
  30741. t->timerCallback();
  30742. }
  30743. JUCE_CATCH_EXCEPTION
  30744. }
  30745. callbackNeeded.set (false);
  30746. }
  30747. static void callAnyTimersSynchronously()
  30748. {
  30749. if (InternalTimerThread::instance != 0)
  30750. {
  30751. const Message m;
  30752. InternalTimerThread::instance->handleMessage (m);
  30753. }
  30754. }
  30755. static inline void add (Timer* const tim) throw()
  30756. {
  30757. if (instance == 0)
  30758. instance = new InternalTimerThread();
  30759. const ScopedLock sl (instance->lock);
  30760. instance->addTimer (tim);
  30761. }
  30762. static inline void remove (Timer* const tim) throw()
  30763. {
  30764. if (instance != 0)
  30765. {
  30766. const ScopedLock sl (instance->lock);
  30767. instance->removeTimer (tim);
  30768. }
  30769. }
  30770. static inline void resetCounter (Timer* const tim,
  30771. const int newCounter) throw()
  30772. {
  30773. if (instance != 0)
  30774. {
  30775. tim->countdownMs = newCounter;
  30776. tim->periodMs = newCounter;
  30777. if ((tim->next != 0 && tim->next->countdownMs < tim->countdownMs)
  30778. || (tim->previous != 0 && tim->previous->countdownMs > tim->countdownMs))
  30779. {
  30780. const ScopedLock sl (instance->lock);
  30781. instance->removeTimer (tim);
  30782. instance->addTimer (tim);
  30783. }
  30784. }
  30785. }
  30786. private:
  30787. friend class Timer;
  30788. static InternalTimerThread* instance;
  30789. static CriticalSection lock;
  30790. Timer* volatile firstTimer;
  30791. class AtomicBool
  30792. {
  30793. public:
  30794. AtomicBool (const bool value) throw() : value (static_cast<int32> (value)) {}
  30795. ~AtomicBool() throw() {}
  30796. bool get() const throw() { return value != 0; }
  30797. bool set (const bool newValue) { return Atomic::compareAndExchange (value, newValue ? 1 : 0, value) != 0; }
  30798. private:
  30799. int32 value;
  30800. AtomicBool (const AtomicBool&);
  30801. AtomicBool& operator= (const AtomicBool&);
  30802. };
  30803. AtomicBool callbackNeeded;
  30804. void addTimer (Timer* const t) throw()
  30805. {
  30806. #ifdef JUCE_DEBUG
  30807. Timer* tt = firstTimer;
  30808. while (tt != 0)
  30809. {
  30810. // trying to add a timer that's already here - shouldn't get to this point,
  30811. // so if you get this assertion, let me know!
  30812. jassert (tt != t);
  30813. tt = tt->next;
  30814. }
  30815. jassert (t->previous == 0 && t->next == 0);
  30816. #endif
  30817. Timer* i = firstTimer;
  30818. if (i == 0 || i->countdownMs > t->countdownMs)
  30819. {
  30820. t->next = firstTimer;
  30821. firstTimer = t;
  30822. }
  30823. else
  30824. {
  30825. while (i->next != 0 && i->next->countdownMs <= t->countdownMs)
  30826. i = i->next;
  30827. jassert (i != 0);
  30828. t->next = i->next;
  30829. t->previous = i;
  30830. i->next = t;
  30831. }
  30832. if (t->next != 0)
  30833. t->next->previous = t;
  30834. jassert ((t->next == 0 || t->next->countdownMs >= t->countdownMs)
  30835. && (t->previous == 0 || t->previous->countdownMs <= t->countdownMs));
  30836. notify();
  30837. }
  30838. void removeTimer (Timer* const t) throw()
  30839. {
  30840. #ifdef JUCE_DEBUG
  30841. Timer* tt = firstTimer;
  30842. bool found = false;
  30843. while (tt != 0)
  30844. {
  30845. if (tt == t)
  30846. {
  30847. found = true;
  30848. break;
  30849. }
  30850. tt = tt->next;
  30851. }
  30852. // trying to remove a timer that's not here - shouldn't get to this point,
  30853. // so if you get this assertion, let me know!
  30854. jassert (found);
  30855. #endif
  30856. if (t->previous != 0)
  30857. {
  30858. jassert (firstTimer != t);
  30859. t->previous->next = t->next;
  30860. }
  30861. else
  30862. {
  30863. jassert (firstTimer == t);
  30864. firstTimer = t->next;
  30865. }
  30866. if (t->next != 0)
  30867. t->next->previous = t->previous;
  30868. t->next = 0;
  30869. t->previous = 0;
  30870. }
  30871. void decrementAllCounters (const int numMillisecs) const
  30872. {
  30873. Timer* t = firstTimer;
  30874. while (t != 0)
  30875. {
  30876. t->countdownMs -= numMillisecs;
  30877. t = t->next;
  30878. }
  30879. }
  30880. void handleAsyncUpdate()
  30881. {
  30882. startThread (7);
  30883. }
  30884. InternalTimerThread (const InternalTimerThread&);
  30885. InternalTimerThread& operator= (const InternalTimerThread&);
  30886. };
  30887. InternalTimerThread* InternalTimerThread::instance = 0;
  30888. CriticalSection InternalTimerThread::lock;
  30889. void juce_callAnyTimersSynchronously()
  30890. {
  30891. InternalTimerThread::callAnyTimersSynchronously();
  30892. }
  30893. #ifdef JUCE_DEBUG
  30894. static SortedSet <Timer*> activeTimers;
  30895. #endif
  30896. Timer::Timer() throw()
  30897. : countdownMs (0),
  30898. periodMs (0),
  30899. previous (0),
  30900. next (0)
  30901. {
  30902. #ifdef JUCE_DEBUG
  30903. activeTimers.add (this);
  30904. #endif
  30905. }
  30906. Timer::Timer (const Timer&) throw()
  30907. : countdownMs (0),
  30908. periodMs (0),
  30909. previous (0),
  30910. next (0)
  30911. {
  30912. #ifdef JUCE_DEBUG
  30913. activeTimers.add (this);
  30914. #endif
  30915. }
  30916. Timer::~Timer()
  30917. {
  30918. stopTimer();
  30919. #ifdef JUCE_DEBUG
  30920. activeTimers.removeValue (this);
  30921. #endif
  30922. }
  30923. void Timer::startTimer (const int interval) throw()
  30924. {
  30925. const ScopedLock sl (InternalTimerThread::lock);
  30926. #ifdef JUCE_DEBUG
  30927. // this isn't a valid object! Your timer might be a dangling pointer or something..
  30928. jassert (activeTimers.contains (this));
  30929. #endif
  30930. if (periodMs == 0)
  30931. {
  30932. countdownMs = interval;
  30933. periodMs = jmax (1, interval);
  30934. InternalTimerThread::add (this);
  30935. }
  30936. else
  30937. {
  30938. InternalTimerThread::resetCounter (this, interval);
  30939. }
  30940. }
  30941. void Timer::stopTimer() throw()
  30942. {
  30943. const ScopedLock sl (InternalTimerThread::lock);
  30944. #ifdef JUCE_DEBUG
  30945. // this isn't a valid object! Your timer might be a dangling pointer or something..
  30946. jassert (activeTimers.contains (this));
  30947. #endif
  30948. if (periodMs > 0)
  30949. {
  30950. InternalTimerThread::remove (this);
  30951. periodMs = 0;
  30952. }
  30953. }
  30954. END_JUCE_NAMESPACE
  30955. /********* End of inlined file: juce_Timer.cpp *********/
  30956. /********* Start of inlined file: juce_Component.cpp *********/
  30957. BEGIN_JUCE_NAMESPACE
  30958. Component* Component::componentUnderMouse = 0;
  30959. Component* Component::currentlyFocusedComponent = 0;
  30960. static Array <Component*> modalComponentStack, modalComponentReturnValueKeys;
  30961. static Array <int> modalReturnValues;
  30962. static const int customCommandMessage = 0x7fff0001;
  30963. static const int exitModalStateMessage = 0x7fff0002;
  30964. // these are also used by ComponentPeer
  30965. int64 juce_recentMouseDownTimes [4] = { 0, 0, 0, 0 };
  30966. int juce_recentMouseDownX [4] = { 0, 0, 0, 0 };
  30967. int juce_recentMouseDownY [4] = { 0, 0, 0, 0 };
  30968. Component* juce_recentMouseDownComponent [4] = { 0, 0, 0, 0 };
  30969. int juce_LastMousePosX = 0;
  30970. int juce_LastMousePosY = 0;
  30971. int juce_MouseClickCounter = 0;
  30972. bool juce_MouseHasMovedSignificantlySincePressed = false;
  30973. static int countMouseClicks() throw()
  30974. {
  30975. int numClicks = 0;
  30976. if (juce_recentMouseDownTimes[0] != 0)
  30977. {
  30978. if (! juce_MouseHasMovedSignificantlySincePressed)
  30979. ++numClicks;
  30980. for (int i = 1; i < numElementsInArray (juce_recentMouseDownTimes); ++i)
  30981. {
  30982. if (juce_recentMouseDownTimes[0] - juce_recentMouseDownTimes [i]
  30983. < (int) (MouseEvent::getDoubleClickTimeout() * (1.0 + 0.25 * (i - 1)))
  30984. && abs (juce_recentMouseDownX[0] - juce_recentMouseDownX[i]) < 8
  30985. && abs (juce_recentMouseDownY[0] - juce_recentMouseDownY[i]) < 8
  30986. && juce_recentMouseDownComponent[0] == juce_recentMouseDownComponent [i])
  30987. {
  30988. ++numClicks;
  30989. }
  30990. else
  30991. {
  30992. break;
  30993. }
  30994. }
  30995. }
  30996. return numClicks;
  30997. }
  30998. static int unboundedMouseOffsetX = 0;
  30999. static int unboundedMouseOffsetY = 0;
  31000. static bool isUnboundedMouseModeOn = false;
  31001. static bool isCursorVisibleUntilOffscreen;
  31002. #define checkMessageManagerIsLocked jassert (MessageManager::getInstance()->currentThreadHasLockedMessageManager());
  31003. static uint32 nextComponentUID = 0;
  31004. Component::Component() throw()
  31005. : parentComponent_ (0),
  31006. componentUID (++nextComponentUID),
  31007. numDeepMouseListeners (0),
  31008. lookAndFeel_ (0),
  31009. effect_ (0),
  31010. bufferedImage_ (0),
  31011. mouseListeners_ (0),
  31012. keyListeners_ (0),
  31013. componentListeners_ (0),
  31014. propertySet_ (0),
  31015. componentFlags_ (0)
  31016. {
  31017. }
  31018. Component::Component (const String& name) throw()
  31019. : componentName_ (name),
  31020. parentComponent_ (0),
  31021. componentUID (++nextComponentUID),
  31022. numDeepMouseListeners (0),
  31023. lookAndFeel_ (0),
  31024. effect_ (0),
  31025. bufferedImage_ (0),
  31026. mouseListeners_ (0),
  31027. keyListeners_ (0),
  31028. componentListeners_ (0),
  31029. propertySet_ (0),
  31030. componentFlags_ (0)
  31031. {
  31032. }
  31033. Component::~Component()
  31034. {
  31035. if (parentComponent_ != 0)
  31036. {
  31037. parentComponent_->removeChildComponent (this);
  31038. }
  31039. else if ((currentlyFocusedComponent == this)
  31040. || isParentOf (currentlyFocusedComponent))
  31041. {
  31042. giveAwayFocus();
  31043. }
  31044. if (componentUnderMouse == this)
  31045. componentUnderMouse = 0;
  31046. if (flags.hasHeavyweightPeerFlag)
  31047. removeFromDesktop();
  31048. modalComponentStack.removeValue (this);
  31049. for (int i = childComponentList_.size(); --i >= 0;)
  31050. childComponentList_.getUnchecked(i)->parentComponent_ = 0;
  31051. delete bufferedImage_;
  31052. delete mouseListeners_;
  31053. delete keyListeners_;
  31054. delete componentListeners_;
  31055. delete propertySet_;
  31056. }
  31057. void Component::setName (const String& name)
  31058. {
  31059. // if component methods are being called from threads other than the message
  31060. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  31061. checkMessageManagerIsLocked
  31062. if (componentName_ != name)
  31063. {
  31064. componentName_ = name;
  31065. if (flags.hasHeavyweightPeerFlag)
  31066. {
  31067. ComponentPeer* const peer = getPeer();
  31068. jassert (peer != 0);
  31069. if (peer != 0)
  31070. peer->setTitle (name);
  31071. }
  31072. if (componentListeners_ != 0)
  31073. {
  31074. const ComponentDeletionWatcher deletionChecker (this);
  31075. for (int i = componentListeners_->size(); --i >= 0;)
  31076. {
  31077. ((ComponentListener*) componentListeners_->getUnchecked (i))
  31078. ->componentNameChanged (*this);
  31079. if (deletionChecker.hasBeenDeleted())
  31080. return;
  31081. i = jmin (i, componentListeners_->size());
  31082. }
  31083. }
  31084. }
  31085. }
  31086. void Component::setVisible (bool shouldBeVisible)
  31087. {
  31088. if (flags.visibleFlag != shouldBeVisible)
  31089. {
  31090. // if component methods are being called from threads other than the message
  31091. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  31092. checkMessageManagerIsLocked
  31093. const ComponentDeletionWatcher deletionChecker (this);
  31094. flags.visibleFlag = shouldBeVisible;
  31095. internalRepaint (0, 0, getWidth(), getHeight());
  31096. sendFakeMouseMove();
  31097. if (! shouldBeVisible)
  31098. {
  31099. if (currentlyFocusedComponent == this
  31100. || isParentOf (currentlyFocusedComponent))
  31101. {
  31102. if (parentComponent_ != 0)
  31103. parentComponent_->grabKeyboardFocus();
  31104. else
  31105. giveAwayFocus();
  31106. }
  31107. }
  31108. sendVisibilityChangeMessage();
  31109. if ((! deletionChecker.hasBeenDeleted()) && flags.hasHeavyweightPeerFlag)
  31110. {
  31111. ComponentPeer* const peer = getPeer();
  31112. jassert (peer != 0);
  31113. if (peer != 0)
  31114. {
  31115. peer->setVisible (shouldBeVisible);
  31116. internalHierarchyChanged();
  31117. }
  31118. }
  31119. }
  31120. }
  31121. void Component::visibilityChanged()
  31122. {
  31123. }
  31124. void Component::sendVisibilityChangeMessage()
  31125. {
  31126. const ComponentDeletionWatcher deletionChecker (this);
  31127. visibilityChanged();
  31128. if ((! deletionChecker.hasBeenDeleted()) && componentListeners_ != 0)
  31129. {
  31130. for (int i = componentListeners_->size(); --i >= 0;)
  31131. {
  31132. ((ComponentListener*) componentListeners_->getUnchecked (i))
  31133. ->componentVisibilityChanged (*this);
  31134. if (deletionChecker.hasBeenDeleted())
  31135. return;
  31136. i = jmin (i, componentListeners_->size());
  31137. }
  31138. }
  31139. }
  31140. bool Component::isShowing() const throw()
  31141. {
  31142. if (flags.visibleFlag)
  31143. {
  31144. if (parentComponent_ != 0)
  31145. {
  31146. return parentComponent_->isShowing();
  31147. }
  31148. else
  31149. {
  31150. const ComponentPeer* const peer = getPeer();
  31151. return peer != 0 && ! peer->isMinimised();
  31152. }
  31153. }
  31154. return false;
  31155. }
  31156. class FadeOutProxyComponent : public Component,
  31157. public Timer
  31158. {
  31159. public:
  31160. FadeOutProxyComponent (Component* comp,
  31161. const int fadeLengthMs,
  31162. const int deltaXToMove,
  31163. const int deltaYToMove,
  31164. const float scaleFactorAtEnd)
  31165. : lastTime (0),
  31166. alpha (1.0f),
  31167. scale (1.0f)
  31168. {
  31169. image = comp->createComponentSnapshot (Rectangle (0, 0, comp->getWidth(), comp->getHeight()));
  31170. setBounds (comp->getBounds());
  31171. comp->getParentComponent()->addAndMakeVisible (this);
  31172. toBehind (comp);
  31173. alphaChangePerMs = -1.0f / (float)fadeLengthMs;
  31174. centreX = comp->getX() + comp->getWidth() * 0.5f;
  31175. xChangePerMs = deltaXToMove / (float)fadeLengthMs;
  31176. centreY = comp->getY() + comp->getHeight() * 0.5f;
  31177. yChangePerMs = deltaYToMove / (float)fadeLengthMs;
  31178. scaleChangePerMs = (scaleFactorAtEnd - 1.0f) / (float)fadeLengthMs;
  31179. setInterceptsMouseClicks (false, false);
  31180. // 30 fps is enough for a fade, but we need a higher rate if it's moving as well..
  31181. startTimer (1000 / ((deltaXToMove == 0 && deltaYToMove == 0) ? 30 : 50));
  31182. }
  31183. ~FadeOutProxyComponent()
  31184. {
  31185. delete image;
  31186. }
  31187. void paint (Graphics& g)
  31188. {
  31189. g.setOpacity (alpha);
  31190. g.drawImage (image,
  31191. 0, 0, getWidth(), getHeight(),
  31192. 0, 0, image->getWidth(), image->getHeight());
  31193. }
  31194. void timerCallback()
  31195. {
  31196. const uint32 now = Time::getMillisecondCounter();
  31197. if (lastTime == 0)
  31198. lastTime = now;
  31199. const int msPassed = (now > lastTime) ? now - lastTime : 0;
  31200. lastTime = now;
  31201. alpha += alphaChangePerMs * msPassed;
  31202. if (alpha > 0)
  31203. {
  31204. if (xChangePerMs != 0.0f || yChangePerMs != 0.0f || scaleChangePerMs != 0.0f)
  31205. {
  31206. centreX += xChangePerMs * msPassed;
  31207. centreY += yChangePerMs * msPassed;
  31208. scale += scaleChangePerMs * msPassed;
  31209. const int w = roundToInt (image->getWidth() * scale);
  31210. const int h = roundToInt (image->getHeight() * scale);
  31211. setBounds (roundToInt (centreX) - w / 2,
  31212. roundToInt (centreY) - h / 2,
  31213. w, h);
  31214. }
  31215. repaint();
  31216. }
  31217. else
  31218. {
  31219. delete this;
  31220. }
  31221. }
  31222. juce_UseDebuggingNewOperator
  31223. private:
  31224. Image* image;
  31225. uint32 lastTime;
  31226. float alpha, alphaChangePerMs;
  31227. float centreX, xChangePerMs;
  31228. float centreY, yChangePerMs;
  31229. float scale, scaleChangePerMs;
  31230. FadeOutProxyComponent (const FadeOutProxyComponent&);
  31231. const FadeOutProxyComponent& operator= (const FadeOutProxyComponent&);
  31232. };
  31233. void Component::fadeOutComponent (const int millisecondsToFade,
  31234. const int deltaXToMove,
  31235. const int deltaYToMove,
  31236. const float scaleFactorAtEnd)
  31237. {
  31238. //xxx won't work for comps without parents
  31239. if (isShowing() && millisecondsToFade > 0)
  31240. new FadeOutProxyComponent (this, millisecondsToFade,
  31241. deltaXToMove, deltaYToMove, scaleFactorAtEnd);
  31242. setVisible (false);
  31243. }
  31244. bool Component::isValidComponent() const throw()
  31245. {
  31246. return (this != 0) && isValidMessageListener();
  31247. }
  31248. void* Component::getWindowHandle() const throw()
  31249. {
  31250. const ComponentPeer* const peer = getPeer();
  31251. if (peer != 0)
  31252. return peer->getNativeHandle();
  31253. return 0;
  31254. }
  31255. void Component::addToDesktop (int styleWanted, void* nativeWindowToAttachTo)
  31256. {
  31257. // if component methods are being called from threads other than the message
  31258. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  31259. checkMessageManagerIsLocked
  31260. if (isOpaque())
  31261. styleWanted &= ~ComponentPeer::windowIsSemiTransparent;
  31262. else
  31263. styleWanted |= ComponentPeer::windowIsSemiTransparent;
  31264. int currentStyleFlags = 0;
  31265. // don't use getPeer(), so that we only get the peer that's specifically
  31266. // for this comp, and not for one of its parents.
  31267. ComponentPeer* peer = ComponentPeer::getPeerFor (this);
  31268. if (peer != 0)
  31269. currentStyleFlags = peer->getStyleFlags();
  31270. if (styleWanted != currentStyleFlags || ! flags.hasHeavyweightPeerFlag)
  31271. {
  31272. const ComponentDeletionWatcher deletionChecker (this);
  31273. #if JUCE_LINUX
  31274. // it's wise to give the component a non-zero size before
  31275. // putting it on the desktop, as X windows get confused by this, and
  31276. // a (1, 1) minimum size is enforced here.
  31277. setSize (jmax (1, getWidth()),
  31278. jmax (1, getHeight()));
  31279. #endif
  31280. int x = 0, y = 0;
  31281. relativePositionToGlobal (x, y);
  31282. bool wasFullscreen = false;
  31283. bool wasMinimised = false;
  31284. ComponentBoundsConstrainer* currentConstainer = 0;
  31285. Rectangle oldNonFullScreenBounds;
  31286. if (peer != 0)
  31287. {
  31288. wasFullscreen = peer->isFullScreen();
  31289. wasMinimised = peer->isMinimised();
  31290. currentConstainer = peer->getConstrainer();
  31291. oldNonFullScreenBounds = peer->getNonFullScreenBounds();
  31292. removeFromDesktop();
  31293. setTopLeftPosition (x, y);
  31294. }
  31295. if (parentComponent_ != 0)
  31296. parentComponent_->removeChildComponent (this);
  31297. if (! deletionChecker.hasBeenDeleted())
  31298. {
  31299. flags.hasHeavyweightPeerFlag = true;
  31300. peer = createNewPeer (styleWanted, nativeWindowToAttachTo);
  31301. Desktop::getInstance().addDesktopComponent (this);
  31302. bounds_.setPosition (x, y);
  31303. peer->setBounds (x, y, getWidth(), getHeight(), false);
  31304. peer->setVisible (isVisible());
  31305. if (wasFullscreen)
  31306. {
  31307. peer->setFullScreen (true);
  31308. peer->setNonFullScreenBounds (oldNonFullScreenBounds);
  31309. }
  31310. if (wasMinimised)
  31311. peer->setMinimised (true);
  31312. if (isAlwaysOnTop())
  31313. peer->setAlwaysOnTop (true);
  31314. peer->setConstrainer (currentConstainer);
  31315. repaint();
  31316. }
  31317. internalHierarchyChanged();
  31318. }
  31319. }
  31320. void Component::removeFromDesktop()
  31321. {
  31322. // if component methods are being called from threads other than the message
  31323. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  31324. checkMessageManagerIsLocked
  31325. if (flags.hasHeavyweightPeerFlag)
  31326. {
  31327. ComponentPeer* const peer = ComponentPeer::getPeerFor (this);
  31328. flags.hasHeavyweightPeerFlag = false;
  31329. jassert (peer != 0);
  31330. delete peer;
  31331. Desktop::getInstance().removeDesktopComponent (this);
  31332. }
  31333. }
  31334. bool Component::isOnDesktop() const throw()
  31335. {
  31336. return flags.hasHeavyweightPeerFlag;
  31337. }
  31338. void Component::userTriedToCloseWindow()
  31339. {
  31340. /* This means that the user's trying to get rid of your window with the 'close window' system
  31341. menu option (on windows) or possibly the task manager - you should really handle this
  31342. and delete or hide your component in an appropriate way.
  31343. If you want to ignore the event and don't want to trigger this assertion, just override
  31344. this method and do nothing.
  31345. */
  31346. jassertfalse
  31347. }
  31348. void Component::minimisationStateChanged (bool)
  31349. {
  31350. }
  31351. void Component::setOpaque (const bool shouldBeOpaque) throw()
  31352. {
  31353. if (shouldBeOpaque != flags.opaqueFlag)
  31354. {
  31355. flags.opaqueFlag = shouldBeOpaque;
  31356. if (flags.hasHeavyweightPeerFlag)
  31357. {
  31358. const ComponentPeer* const peer = ComponentPeer::getPeerFor (this);
  31359. if (peer != 0)
  31360. {
  31361. // to make it recreate the heavyweight window
  31362. addToDesktop (peer->getStyleFlags());
  31363. }
  31364. }
  31365. repaint();
  31366. }
  31367. }
  31368. bool Component::isOpaque() const throw()
  31369. {
  31370. return flags.opaqueFlag;
  31371. }
  31372. void Component::setBufferedToImage (const bool shouldBeBuffered) throw()
  31373. {
  31374. if (shouldBeBuffered != flags.bufferToImageFlag)
  31375. {
  31376. deleteAndZero (bufferedImage_);
  31377. flags.bufferToImageFlag = shouldBeBuffered;
  31378. }
  31379. }
  31380. void Component::toFront (const bool setAsForeground)
  31381. {
  31382. // if component methods are being called from threads other than the message
  31383. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  31384. checkMessageManagerIsLocked
  31385. if (flags.hasHeavyweightPeerFlag)
  31386. {
  31387. ComponentPeer* const peer = getPeer();
  31388. if (peer != 0)
  31389. {
  31390. peer->toFront (setAsForeground);
  31391. if (setAsForeground && ! hasKeyboardFocus (true))
  31392. grabKeyboardFocus();
  31393. }
  31394. }
  31395. else if (parentComponent_ != 0)
  31396. {
  31397. if (parentComponent_->childComponentList_.getLast() != this)
  31398. {
  31399. const int index = parentComponent_->childComponentList_.indexOf (this);
  31400. if (index >= 0)
  31401. {
  31402. int insertIndex = -1;
  31403. if (! flags.alwaysOnTopFlag)
  31404. {
  31405. insertIndex = parentComponent_->childComponentList_.size() - 1;
  31406. while (insertIndex > 0
  31407. && parentComponent_->childComponentList_.getUnchecked (insertIndex)->isAlwaysOnTop())
  31408. {
  31409. --insertIndex;
  31410. }
  31411. }
  31412. if (index != insertIndex)
  31413. {
  31414. parentComponent_->childComponentList_.move (index, insertIndex);
  31415. sendFakeMouseMove();
  31416. repaintParent();
  31417. }
  31418. }
  31419. }
  31420. if (setAsForeground)
  31421. {
  31422. internalBroughtToFront();
  31423. grabKeyboardFocus();
  31424. }
  31425. }
  31426. }
  31427. void Component::toBehind (Component* const other)
  31428. {
  31429. if (other != 0)
  31430. {
  31431. // the two components must belong to the same parent..
  31432. jassert (parentComponent_ == other->parentComponent_);
  31433. if (parentComponent_ != 0)
  31434. {
  31435. const int index = parentComponent_->childComponentList_.indexOf (this);
  31436. int otherIndex = parentComponent_->childComponentList_.indexOf (other);
  31437. if (index >= 0
  31438. && otherIndex >= 0
  31439. && index != otherIndex - 1
  31440. && other != this)
  31441. {
  31442. if (index < otherIndex)
  31443. --otherIndex;
  31444. parentComponent_->childComponentList_.move (index, otherIndex);
  31445. sendFakeMouseMove();
  31446. repaintParent();
  31447. }
  31448. }
  31449. else if (isOnDesktop())
  31450. {
  31451. jassert (other->isOnDesktop());
  31452. if (other->isOnDesktop())
  31453. {
  31454. ComponentPeer* const us = getPeer();
  31455. ComponentPeer* const them = other->getPeer();
  31456. jassert (us != 0 && them != 0);
  31457. if (us != 0 && them != 0)
  31458. us->toBehind (them);
  31459. }
  31460. }
  31461. }
  31462. }
  31463. void Component::toBack()
  31464. {
  31465. if (isOnDesktop())
  31466. {
  31467. jassertfalse //xxx need to add this to native window
  31468. }
  31469. else if (parentComponent_ != 0
  31470. && parentComponent_->childComponentList_.getFirst() != this)
  31471. {
  31472. const int index = parentComponent_->childComponentList_.indexOf (this);
  31473. if (index > 0)
  31474. {
  31475. int insertIndex = 0;
  31476. if (flags.alwaysOnTopFlag)
  31477. {
  31478. while (insertIndex < parentComponent_->childComponentList_.size()
  31479. && ! parentComponent_->childComponentList_.getUnchecked (insertIndex)->isAlwaysOnTop())
  31480. {
  31481. ++insertIndex;
  31482. }
  31483. }
  31484. if (index != insertIndex)
  31485. {
  31486. parentComponent_->childComponentList_.move (index, insertIndex);
  31487. sendFakeMouseMove();
  31488. repaintParent();
  31489. }
  31490. }
  31491. }
  31492. }
  31493. void Component::setAlwaysOnTop (const bool shouldStayOnTop)
  31494. {
  31495. if (shouldStayOnTop != flags.alwaysOnTopFlag)
  31496. {
  31497. flags.alwaysOnTopFlag = shouldStayOnTop;
  31498. if (isOnDesktop())
  31499. {
  31500. ComponentPeer* const peer = getPeer();
  31501. jassert (peer != 0);
  31502. if (peer != 0)
  31503. {
  31504. if (! peer->setAlwaysOnTop (shouldStayOnTop))
  31505. {
  31506. // some kinds of peer can't change their always-on-top status, so
  31507. // for these, we'll need to create a new window
  31508. const int oldFlags = peer->getStyleFlags();
  31509. removeFromDesktop();
  31510. addToDesktop (oldFlags);
  31511. }
  31512. }
  31513. }
  31514. if (shouldStayOnTop)
  31515. toFront (false);
  31516. internalHierarchyChanged();
  31517. }
  31518. }
  31519. bool Component::isAlwaysOnTop() const throw()
  31520. {
  31521. return flags.alwaysOnTopFlag;
  31522. }
  31523. int Component::proportionOfWidth (const float proportion) const throw()
  31524. {
  31525. return roundToInt (proportion * bounds_.getWidth());
  31526. }
  31527. int Component::proportionOfHeight (const float proportion) const throw()
  31528. {
  31529. return roundToInt (proportion * bounds_.getHeight());
  31530. }
  31531. int Component::getParentWidth() const throw()
  31532. {
  31533. return (parentComponent_ != 0) ? parentComponent_->getWidth()
  31534. : getParentMonitorArea().getWidth();
  31535. }
  31536. int Component::getParentHeight() const throw()
  31537. {
  31538. return (parentComponent_ != 0) ? parentComponent_->getHeight()
  31539. : getParentMonitorArea().getHeight();
  31540. }
  31541. int Component::getScreenX() const throw()
  31542. {
  31543. return (parentComponent_ != 0) ? parentComponent_->getScreenX() + getX()
  31544. : (flags.hasHeavyweightPeerFlag ? getPeer()->getScreenX()
  31545. : getX());
  31546. }
  31547. int Component::getScreenY() const throw()
  31548. {
  31549. return (parentComponent_ != 0) ? parentComponent_->getScreenY() + getY()
  31550. : (flags.hasHeavyweightPeerFlag ? getPeer()->getScreenY()
  31551. : getY());
  31552. }
  31553. void Component::relativePositionToGlobal (int& x, int& y) const throw()
  31554. {
  31555. const Component* c = this;
  31556. do
  31557. {
  31558. if (c->flags.hasHeavyweightPeerFlag)
  31559. {
  31560. c->getPeer()->relativePositionToGlobal (x, y);
  31561. break;
  31562. }
  31563. x += c->getX();
  31564. y += c->getY();
  31565. c = c->parentComponent_;
  31566. }
  31567. while (c != 0);
  31568. }
  31569. void Component::globalPositionToRelative (int& x, int& y) const throw()
  31570. {
  31571. if (flags.hasHeavyweightPeerFlag)
  31572. {
  31573. getPeer()->globalPositionToRelative (x, y);
  31574. }
  31575. else
  31576. {
  31577. if (parentComponent_ != 0)
  31578. parentComponent_->globalPositionToRelative (x, y);
  31579. x -= getX();
  31580. y -= getY();
  31581. }
  31582. }
  31583. void Component::relativePositionToOtherComponent (const Component* const targetComponent, int& x, int& y) const throw()
  31584. {
  31585. if (targetComponent != 0)
  31586. {
  31587. const Component* c = this;
  31588. do
  31589. {
  31590. if (c == targetComponent)
  31591. return;
  31592. if (c->flags.hasHeavyweightPeerFlag)
  31593. {
  31594. c->getPeer()->relativePositionToGlobal (x, y);
  31595. break;
  31596. }
  31597. x += c->getX();
  31598. y += c->getY();
  31599. c = c->parentComponent_;
  31600. }
  31601. while (c != 0);
  31602. targetComponent->globalPositionToRelative (x, y);
  31603. }
  31604. }
  31605. void Component::setBounds (int x, int y, int w, int h)
  31606. {
  31607. // if component methods are being called from threads other than the message
  31608. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  31609. checkMessageManagerIsLocked
  31610. if (w < 0) w = 0;
  31611. if (h < 0) h = 0;
  31612. const bool wasResized = (getWidth() != w || getHeight() != h);
  31613. const bool wasMoved = (getX() != x || getY() != y);
  31614. #ifdef JUCE_DEBUG
  31615. // It's a very bad idea to try to resize a window during its paint() method!
  31616. jassert (! (flags.isInsidePaintCall && wasResized && isOnDesktop()));
  31617. #endif
  31618. if (wasMoved || wasResized)
  31619. {
  31620. if (flags.visibleFlag)
  31621. {
  31622. // send a fake mouse move to trigger enter/exit messages if needed..
  31623. sendFakeMouseMove();
  31624. if (! flags.hasHeavyweightPeerFlag)
  31625. repaintParent();
  31626. }
  31627. bounds_.setBounds (x, y, w, h);
  31628. if (wasResized)
  31629. repaint();
  31630. else if (! flags.hasHeavyweightPeerFlag)
  31631. repaintParent();
  31632. if (flags.hasHeavyweightPeerFlag)
  31633. {
  31634. ComponentPeer* const peer = getPeer();
  31635. if (peer != 0)
  31636. {
  31637. if (wasMoved && wasResized)
  31638. peer->setBounds (getX(), getY(), getWidth(), getHeight(), false);
  31639. else if (wasMoved)
  31640. peer->setPosition (getX(), getY());
  31641. else if (wasResized)
  31642. peer->setSize (getWidth(), getHeight());
  31643. }
  31644. }
  31645. sendMovedResizedMessages (wasMoved, wasResized);
  31646. }
  31647. }
  31648. void Component::sendMovedResizedMessages (const bool wasMoved, const bool wasResized)
  31649. {
  31650. JUCE_TRY
  31651. {
  31652. if (wasMoved)
  31653. moved();
  31654. if (wasResized)
  31655. {
  31656. resized();
  31657. for (int i = childComponentList_.size(); --i >= 0;)
  31658. {
  31659. childComponentList_.getUnchecked(i)->parentSizeChanged();
  31660. i = jmin (i, childComponentList_.size());
  31661. }
  31662. }
  31663. if (parentComponent_ != 0)
  31664. parentComponent_->childBoundsChanged (this);
  31665. if (componentListeners_ != 0)
  31666. {
  31667. const ComponentDeletionWatcher deletionChecker (this);
  31668. for (int i = componentListeners_->size(); --i >= 0;)
  31669. {
  31670. ((ComponentListener*) componentListeners_->getUnchecked (i))
  31671. ->componentMovedOrResized (*this, wasMoved, wasResized);
  31672. if (deletionChecker.hasBeenDeleted())
  31673. return;
  31674. i = jmin (i, componentListeners_->size());
  31675. }
  31676. }
  31677. }
  31678. JUCE_CATCH_EXCEPTION
  31679. }
  31680. void Component::setSize (const int w, const int h)
  31681. {
  31682. setBounds (getX(), getY(), w, h);
  31683. }
  31684. void Component::setTopLeftPosition (const int x, const int y)
  31685. {
  31686. setBounds (x, y, getWidth(), getHeight());
  31687. }
  31688. void Component::setTopRightPosition (const int x, const int y)
  31689. {
  31690. setTopLeftPosition (x - getWidth(), y);
  31691. }
  31692. void Component::setBounds (const Rectangle& r)
  31693. {
  31694. setBounds (r.getX(),
  31695. r.getY(),
  31696. r.getWidth(),
  31697. r.getHeight());
  31698. }
  31699. void Component::setBoundsRelative (const float x, const float y,
  31700. const float w, const float h)
  31701. {
  31702. const int pw = getParentWidth();
  31703. const int ph = getParentHeight();
  31704. setBounds (roundToInt (x * pw),
  31705. roundToInt (y * ph),
  31706. roundToInt (w * pw),
  31707. roundToInt (h * ph));
  31708. }
  31709. void Component::setCentrePosition (const int x, const int y)
  31710. {
  31711. setTopLeftPosition (x - getWidth() / 2,
  31712. y - getHeight() / 2);
  31713. }
  31714. void Component::setCentreRelative (const float x, const float y)
  31715. {
  31716. setCentrePosition (roundToInt (getParentWidth() * x),
  31717. roundToInt (getParentHeight() * y));
  31718. }
  31719. void Component::centreWithSize (const int width, const int height)
  31720. {
  31721. setBounds ((getParentWidth() - width) / 2,
  31722. (getParentHeight() - height) / 2,
  31723. width,
  31724. height);
  31725. }
  31726. void Component::setBoundsInset (const BorderSize& borders)
  31727. {
  31728. setBounds (borders.getLeft(),
  31729. borders.getTop(),
  31730. getParentWidth() - (borders.getLeftAndRight()),
  31731. getParentHeight() - (borders.getTopAndBottom()));
  31732. }
  31733. void Component::setBoundsToFit (int x, int y, int width, int height,
  31734. const Justification& justification,
  31735. const bool onlyReduceInSize)
  31736. {
  31737. // it's no good calling this method unless both the component and
  31738. // target rectangle have a finite size.
  31739. jassert (getWidth() > 0 && getHeight() > 0 && width > 0 && height > 0);
  31740. if (getWidth() > 0 && getHeight() > 0
  31741. && width > 0 && height > 0)
  31742. {
  31743. int newW, newH;
  31744. if (onlyReduceInSize && getWidth() <= width && getHeight() <= height)
  31745. {
  31746. newW = getWidth();
  31747. newH = getHeight();
  31748. }
  31749. else
  31750. {
  31751. const double imageRatio = getHeight() / (double) getWidth();
  31752. const double targetRatio = height / (double) width;
  31753. if (imageRatio <= targetRatio)
  31754. {
  31755. newW = width;
  31756. newH = jmin (height, roundToInt (newW * imageRatio));
  31757. }
  31758. else
  31759. {
  31760. newH = height;
  31761. newW = jmin (width, roundToInt (newH / imageRatio));
  31762. }
  31763. }
  31764. if (newW > 0 && newH > 0)
  31765. {
  31766. int newX, newY;
  31767. justification.applyToRectangle (newX, newY, newW, newH,
  31768. x, y, width, height);
  31769. setBounds (newX, newY, newW, newH);
  31770. }
  31771. }
  31772. }
  31773. bool Component::hitTest (int x, int y)
  31774. {
  31775. if (! flags.ignoresMouseClicksFlag)
  31776. return true;
  31777. if (flags.allowChildMouseClicksFlag)
  31778. {
  31779. for (int i = getNumChildComponents(); --i >= 0;)
  31780. {
  31781. Component* const c = getChildComponent (i);
  31782. if (c->isVisible()
  31783. && c->bounds_.contains (x, y)
  31784. && c->hitTest (x - c->getX(),
  31785. y - c->getY()))
  31786. {
  31787. return true;
  31788. }
  31789. }
  31790. }
  31791. return false;
  31792. }
  31793. void Component::setInterceptsMouseClicks (const bool allowClicks,
  31794. const bool allowClicksOnChildComponents) throw()
  31795. {
  31796. flags.ignoresMouseClicksFlag = ! allowClicks;
  31797. flags.allowChildMouseClicksFlag = allowClicksOnChildComponents;
  31798. }
  31799. void Component::getInterceptsMouseClicks (bool& allowsClicksOnThisComponent,
  31800. bool& allowsClicksOnChildComponents) const throw()
  31801. {
  31802. allowsClicksOnThisComponent = ! flags.ignoresMouseClicksFlag;
  31803. allowsClicksOnChildComponents = flags.allowChildMouseClicksFlag;
  31804. }
  31805. bool Component::contains (const int x, const int y)
  31806. {
  31807. if (((unsigned int) x) < (unsigned int) getWidth()
  31808. && ((unsigned int) y) < (unsigned int) getHeight()
  31809. && hitTest (x, y))
  31810. {
  31811. if (parentComponent_ != 0)
  31812. {
  31813. return parentComponent_->contains (x + getX(),
  31814. y + getY());
  31815. }
  31816. else if (flags.hasHeavyweightPeerFlag)
  31817. {
  31818. const ComponentPeer* const peer = getPeer();
  31819. if (peer != 0)
  31820. return peer->contains (x, y, true);
  31821. }
  31822. }
  31823. return false;
  31824. }
  31825. bool Component::reallyContains (int x, int y, const bool returnTrueIfWithinAChild)
  31826. {
  31827. if (! contains (x, y))
  31828. return false;
  31829. Component* p = this;
  31830. while (p->parentComponent_ != 0)
  31831. {
  31832. x += p->getX();
  31833. y += p->getY();
  31834. p = p->parentComponent_;
  31835. }
  31836. const Component* const c = p->getComponentAt (x, y);
  31837. return (c == this) || (returnTrueIfWithinAChild && isParentOf (c));
  31838. }
  31839. Component* Component::getComponentAt (const int x, const int y)
  31840. {
  31841. if (flags.visibleFlag
  31842. && ((unsigned int) x) < (unsigned int) getWidth()
  31843. && ((unsigned int) y) < (unsigned int) getHeight()
  31844. && hitTest (x, y))
  31845. {
  31846. for (int i = childComponentList_.size(); --i >= 0;)
  31847. {
  31848. Component* const child = childComponentList_.getUnchecked(i);
  31849. Component* const c = child->getComponentAt (x - child->getX(),
  31850. y - child->getY());
  31851. if (c != 0)
  31852. return c;
  31853. }
  31854. return this;
  31855. }
  31856. return 0;
  31857. }
  31858. void Component::addChildComponent (Component* const child, int zOrder)
  31859. {
  31860. // if component methods are being called from threads other than the message
  31861. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  31862. checkMessageManagerIsLocked
  31863. if (child != 0 && child->parentComponent_ != this)
  31864. {
  31865. if (child->parentComponent_ != 0)
  31866. child->parentComponent_->removeChildComponent (child);
  31867. else
  31868. child->removeFromDesktop();
  31869. child->parentComponent_ = this;
  31870. if (child->isVisible())
  31871. child->repaintParent();
  31872. if (! child->isAlwaysOnTop())
  31873. {
  31874. if (zOrder < 0 || zOrder > childComponentList_.size())
  31875. zOrder = childComponentList_.size();
  31876. while (zOrder > 0)
  31877. {
  31878. if (! childComponentList_.getUnchecked (zOrder - 1)->isAlwaysOnTop())
  31879. break;
  31880. --zOrder;
  31881. }
  31882. }
  31883. childComponentList_.insert (zOrder, child);
  31884. child->internalHierarchyChanged();
  31885. internalChildrenChanged();
  31886. }
  31887. }
  31888. void Component::addAndMakeVisible (Component* const child, int zOrder)
  31889. {
  31890. if (child != 0)
  31891. {
  31892. child->setVisible (true);
  31893. addChildComponent (child, zOrder);
  31894. }
  31895. }
  31896. void Component::removeChildComponent (Component* const child)
  31897. {
  31898. removeChildComponent (childComponentList_.indexOf (child));
  31899. }
  31900. Component* Component::removeChildComponent (const int index)
  31901. {
  31902. // if component methods are being called from threads other than the message
  31903. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  31904. checkMessageManagerIsLocked
  31905. Component* const child = childComponentList_ [index];
  31906. if (child != 0)
  31907. {
  31908. sendFakeMouseMove();
  31909. child->repaintParent();
  31910. childComponentList_.remove (index);
  31911. child->parentComponent_ = 0;
  31912. JUCE_TRY
  31913. {
  31914. if ((currentlyFocusedComponent == child)
  31915. || child->isParentOf (currentlyFocusedComponent))
  31916. {
  31917. // get rid first to force the grabKeyboardFocus to change to us.
  31918. giveAwayFocus();
  31919. grabKeyboardFocus();
  31920. }
  31921. }
  31922. #if JUCE_CATCH_UNHANDLED_EXCEPTIONS
  31923. catch (const std::exception& e)
  31924. {
  31925. currentlyFocusedComponent = 0;
  31926. Desktop::getInstance().triggerFocusCallback();
  31927. JUCEApplication::sendUnhandledException (&e, __FILE__, __LINE__);
  31928. }
  31929. catch (...)
  31930. {
  31931. currentlyFocusedComponent = 0;
  31932. Desktop::getInstance().triggerFocusCallback();
  31933. JUCEApplication::sendUnhandledException (0, __FILE__, __LINE__);
  31934. }
  31935. #endif
  31936. child->internalHierarchyChanged();
  31937. internalChildrenChanged();
  31938. }
  31939. return child;
  31940. }
  31941. void Component::removeAllChildren()
  31942. {
  31943. for (int i = childComponentList_.size(); --i >= 0;)
  31944. removeChildComponent (i);
  31945. }
  31946. void Component::deleteAllChildren()
  31947. {
  31948. for (int i = childComponentList_.size(); --i >= 0;)
  31949. delete (removeChildComponent (i));
  31950. }
  31951. int Component::getNumChildComponents() const throw()
  31952. {
  31953. return childComponentList_.size();
  31954. }
  31955. Component* Component::getChildComponent (const int index) const throw()
  31956. {
  31957. return childComponentList_ [index];
  31958. }
  31959. int Component::getIndexOfChildComponent (const Component* const child) const throw()
  31960. {
  31961. return childComponentList_.indexOf (const_cast <Component*> (child));
  31962. }
  31963. Component* Component::getTopLevelComponent() const throw()
  31964. {
  31965. const Component* comp = this;
  31966. while (comp->parentComponent_ != 0)
  31967. comp = comp->parentComponent_;
  31968. return (Component*) comp;
  31969. }
  31970. bool Component::isParentOf (const Component* possibleChild) const throw()
  31971. {
  31972. while (possibleChild->isValidComponent())
  31973. {
  31974. possibleChild = possibleChild->parentComponent_;
  31975. if (possibleChild == this)
  31976. return true;
  31977. }
  31978. return false;
  31979. }
  31980. void Component::parentHierarchyChanged()
  31981. {
  31982. }
  31983. void Component::childrenChanged()
  31984. {
  31985. }
  31986. void Component::internalChildrenChanged()
  31987. {
  31988. const ComponentDeletionWatcher deletionChecker (this);
  31989. const bool hasListeners = componentListeners_ != 0;
  31990. childrenChanged();
  31991. if (hasListeners)
  31992. {
  31993. if (deletionChecker.hasBeenDeleted())
  31994. return;
  31995. for (int i = componentListeners_->size(); --i >= 0;)
  31996. {
  31997. ((ComponentListener*) componentListeners_->getUnchecked (i))
  31998. ->componentChildrenChanged (*this);
  31999. if (deletionChecker.hasBeenDeleted())
  32000. return;
  32001. i = jmin (i, componentListeners_->size());
  32002. }
  32003. }
  32004. }
  32005. void Component::internalHierarchyChanged()
  32006. {
  32007. parentHierarchyChanged();
  32008. const ComponentDeletionWatcher deletionChecker (this);
  32009. if (componentListeners_ != 0)
  32010. {
  32011. for (int i = componentListeners_->size(); --i >= 0;)
  32012. {
  32013. ((ComponentListener*) componentListeners_->getUnchecked (i))
  32014. ->componentParentHierarchyChanged (*this);
  32015. if (deletionChecker.hasBeenDeleted())
  32016. return;
  32017. i = jmin (i, componentListeners_->size());
  32018. }
  32019. }
  32020. for (int i = childComponentList_.size(); --i >= 0;)
  32021. {
  32022. childComponentList_.getUnchecked (i)->internalHierarchyChanged();
  32023. // you really shouldn't delete the parent component during a callback telling you
  32024. // that it's changed..
  32025. jassert (! deletionChecker.hasBeenDeleted());
  32026. if (deletionChecker.hasBeenDeleted())
  32027. return;
  32028. i = jmin (i, childComponentList_.size());
  32029. }
  32030. }
  32031. void* Component::runModalLoopCallback (void* userData)
  32032. {
  32033. return (void*) (pointer_sized_int) ((Component*) userData)->runModalLoop();
  32034. }
  32035. int Component::runModalLoop()
  32036. {
  32037. if (! MessageManager::getInstance()->isThisTheMessageThread())
  32038. {
  32039. // use a callback so this can be called from non-gui threads
  32040. return (int) (pointer_sized_int)
  32041. MessageManager::getInstance()
  32042. ->callFunctionOnMessageThread (&runModalLoopCallback, (void*) this);
  32043. }
  32044. Component* const prevFocused = getCurrentlyFocusedComponent();
  32045. ScopedPointer <ComponentDeletionWatcher> deletionChecker;
  32046. if (prevFocused != 0)
  32047. deletionChecker = new ComponentDeletionWatcher (prevFocused);
  32048. if (! isCurrentlyModal())
  32049. enterModalState();
  32050. JUCE_TRY
  32051. {
  32052. while (flags.currentlyModalFlag && flags.visibleFlag)
  32053. {
  32054. if (! MessageManager::getInstance()->runDispatchLoopUntil (20))
  32055. break;
  32056. // check whether this component was deleted during the last message
  32057. if (! isValidMessageListener())
  32058. break;
  32059. }
  32060. }
  32061. #if JUCE_CATCH_UNHANDLED_EXCEPTIONS
  32062. catch (const std::exception& e)
  32063. {
  32064. JUCEApplication::sendUnhandledException (&e, __FILE__, __LINE__);
  32065. return 0;
  32066. }
  32067. catch (...)
  32068. {
  32069. JUCEApplication::sendUnhandledException (0, __FILE__, __LINE__);
  32070. return 0;
  32071. }
  32072. #endif
  32073. const int modalIndex = modalComponentReturnValueKeys.indexOf (this);
  32074. int returnValue = 0;
  32075. if (modalIndex >= 0)
  32076. {
  32077. modalComponentReturnValueKeys.remove (modalIndex);
  32078. returnValue = modalReturnValues.remove (modalIndex);
  32079. }
  32080. modalComponentStack.removeValue (this);
  32081. if (deletionChecker != 0 && ! deletionChecker->hasBeenDeleted())
  32082. prevFocused->grabKeyboardFocus();
  32083. return returnValue;
  32084. }
  32085. void Component::enterModalState (const bool takeKeyboardFocus_)
  32086. {
  32087. // if component methods are being called from threads other than the message
  32088. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  32089. checkMessageManagerIsLocked
  32090. // Check for an attempt to make a component modal when it already is!
  32091. // This can cause nasty problems..
  32092. jassert (! flags.currentlyModalFlag);
  32093. if (! isCurrentlyModal())
  32094. {
  32095. modalComponentStack.add (this);
  32096. modalComponentReturnValueKeys.add (this);
  32097. modalReturnValues.add (0);
  32098. flags.currentlyModalFlag = true;
  32099. setVisible (true);
  32100. if (takeKeyboardFocus_)
  32101. grabKeyboardFocus();
  32102. }
  32103. }
  32104. void Component::exitModalState (const int returnValue)
  32105. {
  32106. if (isCurrentlyModal())
  32107. {
  32108. if (MessageManager::getInstance()->isThisTheMessageThread())
  32109. {
  32110. const int modalIndex = modalComponentReturnValueKeys.indexOf (this);
  32111. if (modalIndex >= 0)
  32112. {
  32113. modalReturnValues.set (modalIndex, returnValue);
  32114. }
  32115. else
  32116. {
  32117. modalComponentReturnValueKeys.add (this);
  32118. modalReturnValues.add (returnValue);
  32119. }
  32120. modalComponentStack.removeValue (this);
  32121. flags.currentlyModalFlag = false;
  32122. bringModalComponentToFront();
  32123. }
  32124. else
  32125. {
  32126. postMessage (new Message (exitModalStateMessage, returnValue, 0, 0));
  32127. }
  32128. }
  32129. }
  32130. bool Component::isCurrentlyModal() const throw()
  32131. {
  32132. return flags.currentlyModalFlag
  32133. && getCurrentlyModalComponent() == this;
  32134. }
  32135. bool Component::isCurrentlyBlockedByAnotherModalComponent() const throw()
  32136. {
  32137. Component* const mc = getCurrentlyModalComponent();
  32138. return mc != 0
  32139. && mc != this
  32140. && (! mc->isParentOf (this))
  32141. && ! mc->canModalEventBeSentToComponent (this);
  32142. }
  32143. int JUCE_CALLTYPE Component::getNumCurrentlyModalComponents() throw()
  32144. {
  32145. return modalComponentStack.size();
  32146. }
  32147. Component* JUCE_CALLTYPE Component::getCurrentlyModalComponent (int index) throw()
  32148. {
  32149. Component* const c = (Component*) (modalComponentStack [modalComponentStack.size() - index - 1]);
  32150. return c->isValidComponent() ? c : 0;
  32151. }
  32152. void Component::bringModalComponentToFront()
  32153. {
  32154. ComponentPeer* lastOne = 0;
  32155. for (int i = 0; i < getNumCurrentlyModalComponents(); ++i)
  32156. {
  32157. Component* const c = getCurrentlyModalComponent (i);
  32158. if (c == 0)
  32159. break;
  32160. ComponentPeer* peer = c->getPeer();
  32161. if (peer != 0 && peer != lastOne)
  32162. {
  32163. if (lastOne == 0)
  32164. {
  32165. peer->toFront (true);
  32166. peer->grabFocus();
  32167. }
  32168. else
  32169. peer->toBehind (lastOne);
  32170. lastOne = peer;
  32171. }
  32172. }
  32173. }
  32174. void Component::setBroughtToFrontOnMouseClick (const bool shouldBeBroughtToFront) throw()
  32175. {
  32176. flags.bringToFrontOnClickFlag = shouldBeBroughtToFront;
  32177. }
  32178. bool Component::isBroughtToFrontOnMouseClick() const throw()
  32179. {
  32180. return flags.bringToFrontOnClickFlag;
  32181. }
  32182. void Component::setMouseCursor (const MouseCursor& cursor) throw()
  32183. {
  32184. cursor_ = cursor;
  32185. if (flags.visibleFlag)
  32186. {
  32187. int mx, my;
  32188. getMouseXYRelative (mx, my);
  32189. if (flags.draggingFlag || reallyContains (mx, my, false))
  32190. {
  32191. internalUpdateMouseCursor (false);
  32192. }
  32193. }
  32194. }
  32195. const MouseCursor Component::getMouseCursor()
  32196. {
  32197. return cursor_;
  32198. }
  32199. void Component::updateMouseCursor() const throw()
  32200. {
  32201. sendFakeMouseMove();
  32202. }
  32203. void Component::internalUpdateMouseCursor (bool forcedUpdate) throw()
  32204. {
  32205. ComponentPeer* const peer = getPeer();
  32206. if (peer != 0)
  32207. {
  32208. MouseCursor mc (getLookAndFeel().getMouseCursorFor (*this));
  32209. if (isUnboundedMouseModeOn && (unboundedMouseOffsetX != 0
  32210. || unboundedMouseOffsetY != 0
  32211. || ! isCursorVisibleUntilOffscreen))
  32212. {
  32213. mc = MouseCursor::NoCursor;
  32214. forcedUpdate = true;
  32215. }
  32216. static void* currentCursorHandle = 0;
  32217. if (forcedUpdate || mc.getHandle() != currentCursorHandle)
  32218. {
  32219. currentCursorHandle = mc.getHandle();
  32220. mc.showInWindow (peer);
  32221. }
  32222. }
  32223. }
  32224. void Component::setRepaintsOnMouseActivity (const bool shouldRepaint) throw()
  32225. {
  32226. flags.repaintOnMouseActivityFlag = shouldRepaint;
  32227. }
  32228. void Component::repaintParent() throw()
  32229. {
  32230. if (flags.visibleFlag)
  32231. internalRepaint (0, 0, getWidth(), getHeight());
  32232. }
  32233. void Component::repaint() throw()
  32234. {
  32235. repaint (0, 0, getWidth(), getHeight());
  32236. }
  32237. void Component::repaint (const int x, const int y,
  32238. const int w, const int h) throw()
  32239. {
  32240. deleteAndZero (bufferedImage_);
  32241. if (flags.visibleFlag)
  32242. internalRepaint (x, y, w, h);
  32243. }
  32244. void Component::internalRepaint (int x, int y, int w, int h)
  32245. {
  32246. // if component methods are being called from threads other than the message
  32247. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  32248. checkMessageManagerIsLocked
  32249. if (x < 0)
  32250. {
  32251. w += x;
  32252. x = 0;
  32253. }
  32254. if (x + w > getWidth())
  32255. w = getWidth() - x;
  32256. if (w > 0)
  32257. {
  32258. if (y < 0)
  32259. {
  32260. h += y;
  32261. y = 0;
  32262. }
  32263. if (y + h > getHeight())
  32264. h = getHeight() - y;
  32265. if (h > 0)
  32266. {
  32267. if (parentComponent_ != 0)
  32268. {
  32269. x += getX();
  32270. y += getY();
  32271. if (parentComponent_->flags.visibleFlag)
  32272. parentComponent_->internalRepaint (x, y, w, h);
  32273. }
  32274. else if (flags.hasHeavyweightPeerFlag)
  32275. {
  32276. ComponentPeer* const peer = getPeer();
  32277. if (peer != 0)
  32278. peer->repaint (x, y, w, h);
  32279. }
  32280. }
  32281. }
  32282. }
  32283. void Component::paintEntireComponent (Graphics& originalContext)
  32284. {
  32285. jassert (! originalContext.isClipEmpty());
  32286. #ifdef JUCE_DEBUG
  32287. flags.isInsidePaintCall = true;
  32288. #endif
  32289. Graphics* g = &originalContext;
  32290. Image* effectImage = 0;
  32291. if (effect_ != 0)
  32292. {
  32293. effectImage = Image::createNativeImage (flags.opaqueFlag ? Image::RGB : Image::ARGB,
  32294. getWidth(), getHeight(),
  32295. ! flags.opaqueFlag);
  32296. g = new Graphics (*effectImage);
  32297. }
  32298. g->saveState();
  32299. clipObscuredRegions (*g, g->getClipBounds(), 0, 0);
  32300. if (! g->isClipEmpty())
  32301. {
  32302. if (bufferedImage_ != 0)
  32303. {
  32304. g->setColour (Colours::black);
  32305. g->drawImageAt (bufferedImage_, 0, 0);
  32306. }
  32307. else
  32308. {
  32309. if (flags.bufferToImageFlag)
  32310. {
  32311. if (bufferedImage_ == 0)
  32312. {
  32313. bufferedImage_ = Image::createNativeImage (flags.opaqueFlag ? Image::RGB : Image::ARGB,
  32314. getWidth(), getHeight(), ! flags.opaqueFlag);
  32315. Graphics imG (*bufferedImage_);
  32316. paint (imG);
  32317. }
  32318. g->setColour (Colours::black);
  32319. g->drawImageAt (bufferedImage_, 0, 0);
  32320. }
  32321. else
  32322. {
  32323. paint (*g);
  32324. g->resetToDefaultState();
  32325. }
  32326. }
  32327. }
  32328. g->restoreState();
  32329. for (int i = 0; i < childComponentList_.size(); ++i)
  32330. {
  32331. Component* const child = childComponentList_.getUnchecked (i);
  32332. if (child->isVisible())
  32333. {
  32334. g->saveState();
  32335. if (g->reduceClipRegion (child->getX(), child->getY(),
  32336. child->getWidth(), child->getHeight()))
  32337. {
  32338. for (int j = i + 1; j < childComponentList_.size(); ++j)
  32339. {
  32340. const Component* const sibling = childComponentList_.getUnchecked (j);
  32341. if (sibling->flags.opaqueFlag && sibling->isVisible())
  32342. g->excludeClipRegion (sibling->getX(), sibling->getY(),
  32343. sibling->getWidth(), sibling->getHeight());
  32344. }
  32345. if (! g->isClipEmpty())
  32346. {
  32347. g->setOrigin (child->getX(), child->getY());
  32348. child->paintEntireComponent (*g);
  32349. }
  32350. }
  32351. g->restoreState();
  32352. }
  32353. }
  32354. JUCE_TRY
  32355. {
  32356. g->saveState();
  32357. paintOverChildren (*g);
  32358. g->restoreState();
  32359. }
  32360. JUCE_CATCH_EXCEPTION
  32361. if (effect_ != 0)
  32362. {
  32363. delete g;
  32364. effect_->applyEffect (*effectImage, originalContext);
  32365. delete effectImage;
  32366. }
  32367. #ifdef JUCE_DEBUG
  32368. flags.isInsidePaintCall = false;
  32369. #endif
  32370. }
  32371. Image* Component::createComponentSnapshot (const Rectangle& areaToGrab,
  32372. const bool clipImageToComponentBounds)
  32373. {
  32374. Rectangle r (areaToGrab);
  32375. if (clipImageToComponentBounds)
  32376. r = r.getIntersection (Rectangle (0, 0, getWidth(), getHeight()));
  32377. Image* const componentImage = Image::createNativeImage (flags.opaqueFlag ? Image::RGB : Image::ARGB,
  32378. jmax (1, r.getWidth()),
  32379. jmax (1, r.getHeight()),
  32380. true);
  32381. Graphics imageContext (*componentImage);
  32382. imageContext.setOrigin (-r.getX(),
  32383. -r.getY());
  32384. paintEntireComponent (imageContext);
  32385. return componentImage;
  32386. }
  32387. void Component::setComponentEffect (ImageEffectFilter* const effect)
  32388. {
  32389. if (effect_ != effect)
  32390. {
  32391. effect_ = effect;
  32392. repaint();
  32393. }
  32394. }
  32395. LookAndFeel& Component::getLookAndFeel() const throw()
  32396. {
  32397. const Component* c = this;
  32398. do
  32399. {
  32400. if (c->lookAndFeel_ != 0)
  32401. return *(c->lookAndFeel_);
  32402. c = c->parentComponent_;
  32403. }
  32404. while (c != 0);
  32405. return LookAndFeel::getDefaultLookAndFeel();
  32406. }
  32407. void Component::setLookAndFeel (LookAndFeel* const newLookAndFeel)
  32408. {
  32409. if (lookAndFeel_ != newLookAndFeel)
  32410. {
  32411. lookAndFeel_ = newLookAndFeel;
  32412. sendLookAndFeelChange();
  32413. }
  32414. }
  32415. void Component::lookAndFeelChanged()
  32416. {
  32417. }
  32418. void Component::sendLookAndFeelChange()
  32419. {
  32420. repaint();
  32421. lookAndFeelChanged();
  32422. // (it's not a great idea to do anything that would delete this component
  32423. // during the lookAndFeelChanged() callback)
  32424. jassert (isValidComponent());
  32425. const ComponentDeletionWatcher deletionChecker (this);
  32426. for (int i = childComponentList_.size(); --i >= 0;)
  32427. {
  32428. childComponentList_.getUnchecked (i)->sendLookAndFeelChange();
  32429. if (deletionChecker.hasBeenDeleted())
  32430. return;
  32431. i = jmin (i, childComponentList_.size());
  32432. }
  32433. }
  32434. static const String getColourPropertyName (const int colourId) throw()
  32435. {
  32436. String s;
  32437. s.preallocateStorage (18);
  32438. s << T("jcclr_") << colourId;
  32439. return s;
  32440. }
  32441. const Colour Component::findColour (const int colourId, const bool inheritFromParent) const throw()
  32442. {
  32443. const String customColour (getComponentProperty (getColourPropertyName (colourId),
  32444. inheritFromParent,
  32445. String::empty));
  32446. if (customColour.isNotEmpty())
  32447. return Colour (customColour.getIntValue());
  32448. return getLookAndFeel().findColour (colourId);
  32449. }
  32450. bool Component::isColourSpecified (const int colourId) const throw()
  32451. {
  32452. return getComponentProperty (getColourPropertyName (colourId),
  32453. false,
  32454. String::empty).isNotEmpty();
  32455. }
  32456. void Component::removeColour (const int colourId)
  32457. {
  32458. if (isColourSpecified (colourId))
  32459. {
  32460. removeComponentProperty (getColourPropertyName (colourId));
  32461. colourChanged();
  32462. }
  32463. }
  32464. void Component::setColour (const int colourId, const Colour& colour)
  32465. {
  32466. const String colourName (getColourPropertyName (colourId));
  32467. const String customColour (getComponentProperty (colourName, false, String::empty));
  32468. if (customColour.isEmpty() || Colour (customColour.getIntValue()) != colour)
  32469. {
  32470. setComponentProperty (colourName, colour);
  32471. colourChanged();
  32472. }
  32473. }
  32474. void Component::copyAllExplicitColoursTo (Component& target) const throw()
  32475. {
  32476. if (propertySet_ != 0)
  32477. {
  32478. const StringPairArray& props = propertySet_->getAllProperties();
  32479. const StringArray& keys = props.getAllKeys();
  32480. for (int i = 0; i < keys.size(); ++i)
  32481. {
  32482. if (keys[i].startsWith (T("jcclr_")))
  32483. {
  32484. target.setComponentProperty (keys[i],
  32485. props.getAllValues() [i]);
  32486. }
  32487. }
  32488. target.colourChanged();
  32489. }
  32490. }
  32491. void Component::colourChanged()
  32492. {
  32493. }
  32494. const Rectangle Component::getUnclippedArea() const
  32495. {
  32496. int x = 0, y = 0, w = getWidth(), h = getHeight();
  32497. Component* p = parentComponent_;
  32498. int px = getX();
  32499. int py = getY();
  32500. while (p != 0)
  32501. {
  32502. if (! Rectangle::intersectRectangles (x, y, w, h, -px, -py, p->getWidth(), p->getHeight()))
  32503. return Rectangle();
  32504. px += p->getX();
  32505. py += p->getY();
  32506. p = p->parentComponent_;
  32507. }
  32508. return Rectangle (x, y, w, h);
  32509. }
  32510. void Component::clipObscuredRegions (Graphics& g, const Rectangle& clipRect,
  32511. const int deltaX, const int deltaY) const throw()
  32512. {
  32513. for (int i = childComponentList_.size(); --i >= 0;)
  32514. {
  32515. const Component* const c = childComponentList_.getUnchecked(i);
  32516. if (c->isVisible())
  32517. {
  32518. Rectangle newClip (clipRect.getIntersection (c->bounds_));
  32519. if (! newClip.isEmpty())
  32520. {
  32521. if (c->isOpaque())
  32522. {
  32523. g.excludeClipRegion (deltaX + newClip.getX(),
  32524. deltaY + newClip.getY(),
  32525. newClip.getWidth(),
  32526. newClip.getHeight());
  32527. }
  32528. else
  32529. {
  32530. newClip.translate (-c->getX(), -c->getY());
  32531. c->clipObscuredRegions (g, newClip,
  32532. c->getX() + deltaX,
  32533. c->getY() + deltaY);
  32534. }
  32535. }
  32536. }
  32537. }
  32538. }
  32539. void Component::getVisibleArea (RectangleList& result,
  32540. const bool includeSiblings) const
  32541. {
  32542. result.clear();
  32543. const Rectangle unclipped (getUnclippedArea());
  32544. if (! unclipped.isEmpty())
  32545. {
  32546. result.add (unclipped);
  32547. if (includeSiblings)
  32548. {
  32549. const Component* const c = getTopLevelComponent();
  32550. int x = 0, y = 0;
  32551. c->relativePositionToOtherComponent (this, x, y);
  32552. c->subtractObscuredRegions (result, x, y,
  32553. Rectangle (0, 0, c->getWidth(), c->getHeight()),
  32554. this);
  32555. }
  32556. subtractObscuredRegions (result, 0, 0, unclipped, 0);
  32557. result.consolidate();
  32558. }
  32559. }
  32560. void Component::subtractObscuredRegions (RectangleList& result,
  32561. const int deltaX,
  32562. const int deltaY,
  32563. const Rectangle& clipRect,
  32564. const Component* const compToAvoid) const throw()
  32565. {
  32566. for (int i = childComponentList_.size(); --i >= 0;)
  32567. {
  32568. const Component* const c = childComponentList_.getUnchecked(i);
  32569. if (c != compToAvoid && c->isVisible())
  32570. {
  32571. if (c->isOpaque())
  32572. {
  32573. Rectangle childBounds (c->bounds_.getIntersection (clipRect));
  32574. childBounds.translate (deltaX, deltaY);
  32575. result.subtract (childBounds);
  32576. }
  32577. else
  32578. {
  32579. Rectangle newClip (clipRect.getIntersection (c->bounds_));
  32580. newClip.translate (-c->getX(), -c->getY());
  32581. c->subtractObscuredRegions (result,
  32582. c->getX() + deltaX,
  32583. c->getY() + deltaY,
  32584. newClip,
  32585. compToAvoid);
  32586. }
  32587. }
  32588. }
  32589. }
  32590. void Component::mouseEnter (const MouseEvent&)
  32591. {
  32592. // base class does nothing
  32593. }
  32594. void Component::mouseExit (const MouseEvent&)
  32595. {
  32596. // base class does nothing
  32597. }
  32598. void Component::mouseDown (const MouseEvent&)
  32599. {
  32600. // base class does nothing
  32601. }
  32602. void Component::mouseUp (const MouseEvent&)
  32603. {
  32604. // base class does nothing
  32605. }
  32606. void Component::mouseDrag (const MouseEvent&)
  32607. {
  32608. // base class does nothing
  32609. }
  32610. void Component::mouseMove (const MouseEvent&)
  32611. {
  32612. // base class does nothing
  32613. }
  32614. void Component::mouseDoubleClick (const MouseEvent&)
  32615. {
  32616. // base class does nothing
  32617. }
  32618. void Component::mouseWheelMove (const MouseEvent& e, float wheelIncrementX, float wheelIncrementY)
  32619. {
  32620. // the base class just passes this event up to its parent..
  32621. if (parentComponent_ != 0)
  32622. parentComponent_->mouseWheelMove (e.getEventRelativeTo (parentComponent_),
  32623. wheelIncrementX, wheelIncrementY);
  32624. }
  32625. void Component::resized()
  32626. {
  32627. // base class does nothing
  32628. }
  32629. void Component::moved()
  32630. {
  32631. // base class does nothing
  32632. }
  32633. void Component::childBoundsChanged (Component*)
  32634. {
  32635. // base class does nothing
  32636. }
  32637. void Component::parentSizeChanged()
  32638. {
  32639. // base class does nothing
  32640. }
  32641. void Component::addComponentListener (ComponentListener* const newListener) throw()
  32642. {
  32643. if (componentListeners_ == 0)
  32644. componentListeners_ = new VoidArray();
  32645. componentListeners_->addIfNotAlreadyThere (newListener);
  32646. }
  32647. void Component::removeComponentListener (ComponentListener* const listenerToRemove) throw()
  32648. {
  32649. jassert (isValidComponent());
  32650. if (componentListeners_ != 0)
  32651. componentListeners_->removeValue (listenerToRemove);
  32652. }
  32653. void Component::inputAttemptWhenModal()
  32654. {
  32655. bringModalComponentToFront();
  32656. getLookAndFeel().playAlertSound();
  32657. }
  32658. bool Component::canModalEventBeSentToComponent (const Component*)
  32659. {
  32660. return false;
  32661. }
  32662. void Component::internalModalInputAttempt()
  32663. {
  32664. Component* const current = getCurrentlyModalComponent();
  32665. if (current != 0)
  32666. current->inputAttemptWhenModal();
  32667. }
  32668. void Component::paint (Graphics&)
  32669. {
  32670. // all painting is done in the subclasses
  32671. jassert (! isOpaque()); // if your component's opaque, you've gotta paint it!
  32672. }
  32673. void Component::paintOverChildren (Graphics&)
  32674. {
  32675. // all painting is done in the subclasses
  32676. }
  32677. void Component::handleMessage (const Message& message)
  32678. {
  32679. if (message.intParameter1 == exitModalStateMessage)
  32680. {
  32681. exitModalState (message.intParameter2);
  32682. }
  32683. else if (message.intParameter1 == customCommandMessage)
  32684. {
  32685. handleCommandMessage (message.intParameter2);
  32686. }
  32687. }
  32688. void Component::postCommandMessage (const int commandId) throw()
  32689. {
  32690. postMessage (new Message (customCommandMessage, commandId, 0, 0));
  32691. }
  32692. void Component::handleCommandMessage (int)
  32693. {
  32694. // used by subclasses
  32695. }
  32696. void Component::addMouseListener (MouseListener* const newListener,
  32697. const bool wantsEventsForAllNestedChildComponents) throw()
  32698. {
  32699. // if component methods are being called from threads other than the message
  32700. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  32701. checkMessageManagerIsLocked
  32702. if (mouseListeners_ == 0)
  32703. mouseListeners_ = new VoidArray();
  32704. if (! mouseListeners_->contains (newListener))
  32705. {
  32706. if (wantsEventsForAllNestedChildComponents)
  32707. {
  32708. mouseListeners_->insert (0, newListener);
  32709. ++numDeepMouseListeners;
  32710. }
  32711. else
  32712. {
  32713. mouseListeners_->add (newListener);
  32714. }
  32715. }
  32716. }
  32717. void Component::removeMouseListener (MouseListener* const listenerToRemove) throw()
  32718. {
  32719. // if component methods are being called from threads other than the message
  32720. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  32721. checkMessageManagerIsLocked
  32722. if (mouseListeners_ != 0)
  32723. {
  32724. const int index = mouseListeners_->indexOf (listenerToRemove);
  32725. if (index >= 0)
  32726. {
  32727. if (index < numDeepMouseListeners)
  32728. --numDeepMouseListeners;
  32729. mouseListeners_->remove (index);
  32730. }
  32731. }
  32732. }
  32733. void Component::internalMouseEnter (int x, int y, int64 time)
  32734. {
  32735. if (isCurrentlyBlockedByAnotherModalComponent())
  32736. {
  32737. // if something else is modal, always just show a normal mouse cursor
  32738. if (componentUnderMouse == this)
  32739. {
  32740. ComponentPeer* const peer = getPeer();
  32741. if (peer != 0)
  32742. {
  32743. MouseCursor mc (MouseCursor::NormalCursor);
  32744. mc.showInWindow (peer);
  32745. }
  32746. }
  32747. return;
  32748. }
  32749. if (! flags.mouseInsideFlag)
  32750. {
  32751. flags.mouseInsideFlag = true;
  32752. flags.mouseOverFlag = true;
  32753. flags.draggingFlag = false;
  32754. if (isValidComponent())
  32755. {
  32756. const ComponentDeletionWatcher deletionChecker (this);
  32757. if (flags.repaintOnMouseActivityFlag)
  32758. repaint();
  32759. const MouseEvent me (x, y,
  32760. ModifierKeys::getCurrentModifiers(),
  32761. this,
  32762. Time (time),
  32763. x, y,
  32764. Time (time),
  32765. 0, false);
  32766. mouseEnter (me);
  32767. if (deletionChecker.hasBeenDeleted())
  32768. return;
  32769. Desktop::getInstance().resetTimer();
  32770. for (int i = Desktop::getInstance().mouseListeners.size(); --i >= 0;)
  32771. {
  32772. ((MouseListener*) Desktop::getInstance().mouseListeners[i])->mouseEnter (me);
  32773. if (deletionChecker.hasBeenDeleted())
  32774. return;
  32775. i = jmin (i, Desktop::getInstance().mouseListeners.size());
  32776. }
  32777. if (mouseListeners_ != 0)
  32778. {
  32779. for (int i = mouseListeners_->size(); --i >= 0;)
  32780. {
  32781. ((MouseListener*) mouseListeners_->getUnchecked(i))->mouseEnter (me);
  32782. if (deletionChecker.hasBeenDeleted())
  32783. return;
  32784. i = jmin (i, mouseListeners_->size());
  32785. }
  32786. }
  32787. const Component* p = parentComponent_;
  32788. while (p != 0)
  32789. {
  32790. const ComponentDeletionWatcher parentDeletionChecker (p);
  32791. for (int i = p->numDeepMouseListeners; --i >= 0;)
  32792. {
  32793. ((MouseListener*) (p->mouseListeners_->getUnchecked(i)))->mouseEnter (me);
  32794. if (deletionChecker.hasBeenDeleted() || parentDeletionChecker.hasBeenDeleted())
  32795. return;
  32796. i = jmin (i, p->numDeepMouseListeners);
  32797. }
  32798. p = p->parentComponent_;
  32799. }
  32800. }
  32801. }
  32802. if (componentUnderMouse == this)
  32803. internalUpdateMouseCursor (true);
  32804. }
  32805. void Component::internalMouseExit (int x, int y, int64 time)
  32806. {
  32807. const ComponentDeletionWatcher deletionChecker (this);
  32808. if (flags.draggingFlag)
  32809. {
  32810. internalMouseUp (ModifierKeys::getCurrentModifiers().getRawFlags(), x, y, time);
  32811. if (deletionChecker.hasBeenDeleted())
  32812. return;
  32813. }
  32814. enableUnboundedMouseMovement (false);
  32815. if (flags.mouseInsideFlag || flags.mouseOverFlag)
  32816. {
  32817. flags.mouseInsideFlag = false;
  32818. flags.mouseOverFlag = false;
  32819. flags.draggingFlag = false;
  32820. if (flags.repaintOnMouseActivityFlag)
  32821. repaint();
  32822. const MouseEvent me (x, y,
  32823. ModifierKeys::getCurrentModifiers(),
  32824. this,
  32825. Time (time),
  32826. x, y,
  32827. Time (time),
  32828. 0, false);
  32829. mouseExit (me);
  32830. if (deletionChecker.hasBeenDeleted())
  32831. return;
  32832. Desktop::getInstance().resetTimer();
  32833. for (int i = Desktop::getInstance().mouseListeners.size(); --i >= 0;)
  32834. {
  32835. ((MouseListener*) Desktop::getInstance().mouseListeners[i])->mouseExit (me);
  32836. if (deletionChecker.hasBeenDeleted())
  32837. return;
  32838. i = jmin (i, Desktop::getInstance().mouseListeners.size());
  32839. }
  32840. if (mouseListeners_ != 0)
  32841. {
  32842. for (int i = mouseListeners_->size(); --i >= 0;)
  32843. {
  32844. ((MouseListener*) mouseListeners_->getUnchecked (i))->mouseExit (me);
  32845. if (deletionChecker.hasBeenDeleted())
  32846. return;
  32847. i = jmin (i, mouseListeners_->size());
  32848. }
  32849. }
  32850. const Component* p = parentComponent_;
  32851. while (p != 0)
  32852. {
  32853. const ComponentDeletionWatcher parentDeletionChecker (p);
  32854. for (int i = p->numDeepMouseListeners; --i >= 0;)
  32855. {
  32856. ((MouseListener*) (p->mouseListeners_->getUnchecked (i)))->mouseExit (me);
  32857. if (deletionChecker.hasBeenDeleted() || parentDeletionChecker.hasBeenDeleted())
  32858. return;
  32859. i = jmin (i, p->numDeepMouseListeners);
  32860. }
  32861. p = p->parentComponent_;
  32862. }
  32863. }
  32864. }
  32865. class InternalDragRepeater : public Timer
  32866. {
  32867. public:
  32868. InternalDragRepeater()
  32869. {}
  32870. ~InternalDragRepeater()
  32871. {}
  32872. void timerCallback()
  32873. {
  32874. Component* const c = Component::getComponentUnderMouse();
  32875. if (c != 0 && c->isMouseButtonDown())
  32876. {
  32877. int x, y;
  32878. c->getMouseXYRelative (x, y);
  32879. // the offsets have been added on, so must be taken off before calling the
  32880. // drag.. otherwise they'll be added twice
  32881. x -= unboundedMouseOffsetX;
  32882. y -= unboundedMouseOffsetY;
  32883. c->internalMouseDrag (x, y, Time::currentTimeMillis());
  32884. }
  32885. }
  32886. juce_UseDebuggingNewOperator
  32887. };
  32888. static InternalDragRepeater* dragRepeater = 0;
  32889. void Component::beginDragAutoRepeat (const int interval)
  32890. {
  32891. if (interval > 0)
  32892. {
  32893. if (dragRepeater == 0)
  32894. dragRepeater = new InternalDragRepeater();
  32895. if (dragRepeater->getTimerInterval() != interval)
  32896. dragRepeater->startTimer (interval);
  32897. }
  32898. else
  32899. {
  32900. deleteAndZero (dragRepeater);
  32901. }
  32902. }
  32903. void Component::internalMouseDown (const int x, const int y)
  32904. {
  32905. const ComponentDeletionWatcher deletionChecker (this);
  32906. if (isCurrentlyBlockedByAnotherModalComponent())
  32907. {
  32908. internalModalInputAttempt();
  32909. if (deletionChecker.hasBeenDeleted())
  32910. return;
  32911. // If processing the input attempt has exited the modal loop, we'll allow the event
  32912. // to be delivered..
  32913. if (isCurrentlyBlockedByAnotherModalComponent())
  32914. {
  32915. // allow blocked mouse-events to go to global listeners..
  32916. const MouseEvent me (x, y,
  32917. ModifierKeys::getCurrentModifiers(),
  32918. this,
  32919. Time (juce_recentMouseDownTimes[0]),
  32920. x, y,
  32921. Time (juce_recentMouseDownTimes[0]),
  32922. countMouseClicks(),
  32923. false);
  32924. Desktop::getInstance().resetTimer();
  32925. for (int i = Desktop::getInstance().mouseListeners.size(); --i >= 0;)
  32926. {
  32927. ((MouseListener*) Desktop::getInstance().mouseListeners[i])->mouseDown (me);
  32928. if (deletionChecker.hasBeenDeleted())
  32929. return;
  32930. i = jmin (i, Desktop::getInstance().mouseListeners.size());
  32931. }
  32932. return;
  32933. }
  32934. }
  32935. {
  32936. Component* c = this;
  32937. while (c != 0)
  32938. {
  32939. if (c->isBroughtToFrontOnMouseClick())
  32940. {
  32941. c->toFront (true);
  32942. if (deletionChecker.hasBeenDeleted())
  32943. return;
  32944. }
  32945. c = c->parentComponent_;
  32946. }
  32947. }
  32948. if (! flags.dontFocusOnMouseClickFlag)
  32949. grabFocusInternal (focusChangedByMouseClick);
  32950. if (! deletionChecker.hasBeenDeleted())
  32951. {
  32952. flags.draggingFlag = true;
  32953. flags.mouseOverFlag = true;
  32954. if (flags.repaintOnMouseActivityFlag)
  32955. repaint();
  32956. const MouseEvent me (x, y,
  32957. ModifierKeys::getCurrentModifiers(),
  32958. this,
  32959. Time (juce_recentMouseDownTimes[0]),
  32960. x, y,
  32961. Time (juce_recentMouseDownTimes[0]),
  32962. countMouseClicks(),
  32963. false);
  32964. mouseDown (me);
  32965. if (deletionChecker.hasBeenDeleted())
  32966. return;
  32967. Desktop::getInstance().resetTimer();
  32968. for (int i = Desktop::getInstance().mouseListeners.size(); --i >= 0;)
  32969. {
  32970. ((MouseListener*) Desktop::getInstance().mouseListeners[i])->mouseDown (me);
  32971. if (deletionChecker.hasBeenDeleted())
  32972. return;
  32973. i = jmin (i, Desktop::getInstance().mouseListeners.size());
  32974. }
  32975. if (mouseListeners_ != 0)
  32976. {
  32977. for (int i = mouseListeners_->size(); --i >= 0;)
  32978. {
  32979. ((MouseListener*) mouseListeners_->getUnchecked (i))->mouseDown (me);
  32980. if (deletionChecker.hasBeenDeleted())
  32981. return;
  32982. i = jmin (i, mouseListeners_->size());
  32983. }
  32984. }
  32985. const Component* p = parentComponent_;
  32986. while (p != 0)
  32987. {
  32988. const ComponentDeletionWatcher parentDeletionChecker (p);
  32989. for (int i = p->numDeepMouseListeners; --i >= 0;)
  32990. {
  32991. ((MouseListener*) (p->mouseListeners_->getUnchecked (i)))->mouseDown (me);
  32992. if (deletionChecker.hasBeenDeleted() || parentDeletionChecker.hasBeenDeleted())
  32993. return;
  32994. i = jmin (i, p->numDeepMouseListeners);
  32995. }
  32996. p = p->parentComponent_;
  32997. }
  32998. }
  32999. }
  33000. void Component::internalMouseUp (const int oldModifiers, int x, int y, const int64 time)
  33001. {
  33002. if (isValidComponent() && flags.draggingFlag)
  33003. {
  33004. flags.draggingFlag = false;
  33005. deleteAndZero (dragRepeater);
  33006. x += unboundedMouseOffsetX;
  33007. y += unboundedMouseOffsetY;
  33008. juce_LastMousePosX = x;
  33009. juce_LastMousePosY = y;
  33010. relativePositionToGlobal (juce_LastMousePosX, juce_LastMousePosY);
  33011. const ComponentDeletionWatcher deletionChecker (this);
  33012. if (flags.repaintOnMouseActivityFlag)
  33013. repaint();
  33014. int mdx = juce_recentMouseDownX[0];
  33015. int mdy = juce_recentMouseDownY[0];
  33016. globalPositionToRelative (mdx, mdy);
  33017. const MouseEvent me (x, y,
  33018. oldModifiers,
  33019. this,
  33020. Time (time),
  33021. mdx, mdy,
  33022. Time (juce_recentMouseDownTimes [0]),
  33023. countMouseClicks(),
  33024. juce_MouseHasMovedSignificantlySincePressed
  33025. || juce_recentMouseDownTimes[0] + 300 < time);
  33026. mouseUp (me);
  33027. if (deletionChecker.hasBeenDeleted())
  33028. return;
  33029. Desktop::getInstance().resetTimer();
  33030. for (int i = Desktop::getInstance().mouseListeners.size(); --i >= 0;)
  33031. {
  33032. ((MouseListener*) Desktop::getInstance().mouseListeners[i])->mouseUp (me);
  33033. if (deletionChecker.hasBeenDeleted())
  33034. return;
  33035. i = jmin (i, Desktop::getInstance().mouseListeners.size());
  33036. }
  33037. if (mouseListeners_ != 0)
  33038. {
  33039. for (int i = mouseListeners_->size(); --i >= 0;)
  33040. {
  33041. ((MouseListener*) mouseListeners_->getUnchecked (i))->mouseUp (me);
  33042. if (deletionChecker.hasBeenDeleted())
  33043. return;
  33044. i = jmin (i, mouseListeners_->size());
  33045. }
  33046. }
  33047. {
  33048. const Component* p = parentComponent_;
  33049. while (p != 0)
  33050. {
  33051. const ComponentDeletionWatcher parentDeletionChecker (p);
  33052. for (int i = p->numDeepMouseListeners; --i >= 0;)
  33053. {
  33054. ((MouseListener*) (p->mouseListeners_->getUnchecked (i)))->mouseUp (me);
  33055. if (deletionChecker.hasBeenDeleted() || parentDeletionChecker.hasBeenDeleted())
  33056. return;
  33057. i = jmin (i, p->numDeepMouseListeners);
  33058. }
  33059. p = p->parentComponent_;
  33060. }
  33061. }
  33062. // check for double-click
  33063. if (me.getNumberOfClicks() >= 2)
  33064. {
  33065. const int numListeners = (mouseListeners_ != 0) ? mouseListeners_->size() : 0;
  33066. mouseDoubleClick (me);
  33067. int i;
  33068. for (i = Desktop::getInstance().mouseListeners.size(); --i >= 0;)
  33069. {
  33070. ((MouseListener*) Desktop::getInstance().mouseListeners[i])->mouseDoubleClick (me);
  33071. if (deletionChecker.hasBeenDeleted())
  33072. return;
  33073. i = jmin (i, Desktop::getInstance().mouseListeners.size());
  33074. }
  33075. for (i = numListeners; --i >= 0;)
  33076. {
  33077. if (deletionChecker.hasBeenDeleted() || mouseListeners_ == 0)
  33078. return;
  33079. MouseListener* const ml = (MouseListener*)((*mouseListeners_)[i]);
  33080. if (ml != 0)
  33081. ml->mouseDoubleClick (me);
  33082. }
  33083. if (deletionChecker.hasBeenDeleted())
  33084. return;
  33085. const Component* p = parentComponent_;
  33086. while (p != 0)
  33087. {
  33088. const ComponentDeletionWatcher parentDeletionChecker (p);
  33089. for (i = p->numDeepMouseListeners; --i >= 0;)
  33090. {
  33091. ((MouseListener*) (p->mouseListeners_->getUnchecked (i)))->mouseDoubleClick (me);
  33092. if (deletionChecker.hasBeenDeleted() || parentDeletionChecker.hasBeenDeleted())
  33093. return;
  33094. i = jmin (i, p->numDeepMouseListeners);
  33095. }
  33096. p = p->parentComponent_;
  33097. }
  33098. }
  33099. }
  33100. enableUnboundedMouseMovement (false);
  33101. }
  33102. void Component::internalMouseDrag (int x, int y, const int64 time)
  33103. {
  33104. if (isValidComponent() && flags.draggingFlag)
  33105. {
  33106. flags.mouseOverFlag = reallyContains (x, y, false);
  33107. x += unboundedMouseOffsetX;
  33108. y += unboundedMouseOffsetY;
  33109. juce_LastMousePosX = x;
  33110. juce_LastMousePosY = y;
  33111. relativePositionToGlobal (juce_LastMousePosX, juce_LastMousePosY);
  33112. juce_MouseHasMovedSignificantlySincePressed
  33113. = juce_MouseHasMovedSignificantlySincePressed
  33114. || abs (juce_recentMouseDownX[0] - juce_LastMousePosX) >= 4
  33115. || abs (juce_recentMouseDownY[0] - juce_LastMousePosY) >= 4;
  33116. const ComponentDeletionWatcher deletionChecker (this);
  33117. int mdx = juce_recentMouseDownX[0];
  33118. int mdy = juce_recentMouseDownY[0];
  33119. globalPositionToRelative (mdx, mdy);
  33120. const MouseEvent me (x, y,
  33121. ModifierKeys::getCurrentModifiers(),
  33122. this,
  33123. Time (time),
  33124. mdx, mdy,
  33125. Time (juce_recentMouseDownTimes[0]),
  33126. countMouseClicks(),
  33127. juce_MouseHasMovedSignificantlySincePressed
  33128. || juce_recentMouseDownTimes[0] + 300 < time);
  33129. mouseDrag (me);
  33130. if (deletionChecker.hasBeenDeleted())
  33131. return;
  33132. Desktop::getInstance().resetTimer();
  33133. for (int i = Desktop::getInstance().mouseListeners.size(); --i >= 0;)
  33134. {
  33135. ((MouseListener*) Desktop::getInstance().mouseListeners[i])->mouseDrag (me);
  33136. if (deletionChecker.hasBeenDeleted())
  33137. return;
  33138. i = jmin (i, Desktop::getInstance().mouseListeners.size());
  33139. }
  33140. if (mouseListeners_ != 0)
  33141. {
  33142. for (int i = mouseListeners_->size(); --i >= 0;)
  33143. {
  33144. ((MouseListener*) mouseListeners_->getUnchecked (i))->mouseDrag (me);
  33145. if (deletionChecker.hasBeenDeleted())
  33146. return;
  33147. i = jmin (i, mouseListeners_->size());
  33148. }
  33149. }
  33150. const Component* p = parentComponent_;
  33151. while (p != 0)
  33152. {
  33153. const ComponentDeletionWatcher parentDeletionChecker (p);
  33154. for (int i = p->numDeepMouseListeners; --i >= 0;)
  33155. {
  33156. ((MouseListener*) (p->mouseListeners_->getUnchecked (i)))->mouseDrag (me);
  33157. if (deletionChecker.hasBeenDeleted() || parentDeletionChecker.hasBeenDeleted())
  33158. return;
  33159. i = jmin (i, p->numDeepMouseListeners);
  33160. }
  33161. p = p->parentComponent_;
  33162. }
  33163. if (this == componentUnderMouse)
  33164. {
  33165. if (isUnboundedMouseModeOn)
  33166. {
  33167. Rectangle screenArea (getParentMonitorArea().expanded (-2, -2));
  33168. int mx, my;
  33169. Desktop::getMousePosition (mx, my);
  33170. if (! screenArea.contains (mx, my))
  33171. {
  33172. int deltaX = 0, deltaY = 0;
  33173. if (mx <= screenArea.getX() || mx >= screenArea.getRight())
  33174. deltaX = getScreenX() + getWidth() / 2 - mx;
  33175. if (my <= screenArea.getY() || my >= screenArea.getBottom())
  33176. deltaY = getScreenY() + getHeight() / 2 - my;
  33177. unboundedMouseOffsetX -= deltaX;
  33178. unboundedMouseOffsetY -= deltaY;
  33179. Desktop::setMousePosition (mx + deltaX,
  33180. my + deltaY);
  33181. }
  33182. else if (isCursorVisibleUntilOffscreen
  33183. && (unboundedMouseOffsetX != 0 || unboundedMouseOffsetY != 0)
  33184. && screenArea.contains (mx + unboundedMouseOffsetX,
  33185. my + unboundedMouseOffsetY))
  33186. {
  33187. mx += unboundedMouseOffsetX;
  33188. my += unboundedMouseOffsetY;
  33189. unboundedMouseOffsetX = 0;
  33190. unboundedMouseOffsetY = 0;
  33191. Desktop::setMousePosition (mx, my);
  33192. }
  33193. }
  33194. internalUpdateMouseCursor (false);
  33195. }
  33196. }
  33197. }
  33198. void Component::internalMouseMove (const int x, const int y, const int64 time)
  33199. {
  33200. const ComponentDeletionWatcher deletionChecker (this);
  33201. if (isValidComponent())
  33202. {
  33203. const MouseEvent me (x, y,
  33204. ModifierKeys::getCurrentModifiers(),
  33205. this,
  33206. Time (time),
  33207. x, y,
  33208. Time (time),
  33209. 0, false);
  33210. if (isCurrentlyBlockedByAnotherModalComponent())
  33211. {
  33212. // allow blocked mouse-events to go to global listeners..
  33213. Desktop::getInstance().sendMouseMove();
  33214. }
  33215. else
  33216. {
  33217. if (this == componentUnderMouse)
  33218. internalUpdateMouseCursor (false);
  33219. flags.mouseOverFlag = true;
  33220. mouseMove (me);
  33221. if (deletionChecker.hasBeenDeleted())
  33222. return;
  33223. Desktop::getInstance().resetTimer();
  33224. for (int i = Desktop::getInstance().mouseListeners.size(); --i >= 0;)
  33225. {
  33226. ((MouseListener*) Desktop::getInstance().mouseListeners[i])->mouseMove (me);
  33227. if (deletionChecker.hasBeenDeleted())
  33228. return;
  33229. i = jmin (i, Desktop::getInstance().mouseListeners.size());
  33230. }
  33231. if (mouseListeners_ != 0)
  33232. {
  33233. for (int i = mouseListeners_->size(); --i >= 0;)
  33234. {
  33235. ((MouseListener*) mouseListeners_->getUnchecked (i))->mouseMove (me);
  33236. if (deletionChecker.hasBeenDeleted())
  33237. return;
  33238. i = jmin (i, mouseListeners_->size());
  33239. }
  33240. }
  33241. const Component* p = parentComponent_;
  33242. while (p != 0)
  33243. {
  33244. const ComponentDeletionWatcher parentDeletionChecker (p);
  33245. for (int i = p->numDeepMouseListeners; --i >= 0;)
  33246. {
  33247. ((MouseListener*) (p->mouseListeners_->getUnchecked (i)))->mouseMove (me);
  33248. if (deletionChecker.hasBeenDeleted() || parentDeletionChecker.hasBeenDeleted())
  33249. return;
  33250. i = jmin (i, p->numDeepMouseListeners);
  33251. }
  33252. p = p->parentComponent_;
  33253. }
  33254. }
  33255. }
  33256. }
  33257. void Component::internalMouseWheel (const int intAmountX, const int intAmountY, const int64 time)
  33258. {
  33259. const ComponentDeletionWatcher deletionChecker (this);
  33260. const float wheelIncrementX = intAmountX * (1.0f / 256.0f);
  33261. const float wheelIncrementY = intAmountY * (1.0f / 256.0f);
  33262. int mx, my;
  33263. getMouseXYRelative (mx, my);
  33264. const MouseEvent me (mx, my,
  33265. ModifierKeys::getCurrentModifiers(),
  33266. this,
  33267. Time (time),
  33268. mx, my,
  33269. Time (time),
  33270. 0, false);
  33271. if (isCurrentlyBlockedByAnotherModalComponent())
  33272. {
  33273. // allow blocked mouse-events to go to global listeners..
  33274. for (int i = Desktop::getInstance().mouseListeners.size(); --i >= 0;)
  33275. {
  33276. ((MouseListener*) Desktop::getInstance().mouseListeners[i])->mouseWheelMove (me, wheelIncrementX, wheelIncrementY);
  33277. if (deletionChecker.hasBeenDeleted())
  33278. return;
  33279. i = jmin (i, Desktop::getInstance().mouseListeners.size());
  33280. }
  33281. }
  33282. else
  33283. {
  33284. mouseWheelMove (me, wheelIncrementX, wheelIncrementY);
  33285. if (deletionChecker.hasBeenDeleted())
  33286. return;
  33287. for (int i = Desktop::getInstance().mouseListeners.size(); --i >= 0;)
  33288. {
  33289. ((MouseListener*) Desktop::getInstance().mouseListeners[i])->mouseWheelMove (me, wheelIncrementX, wheelIncrementY);
  33290. if (deletionChecker.hasBeenDeleted())
  33291. return;
  33292. i = jmin (i, Desktop::getInstance().mouseListeners.size());
  33293. }
  33294. if (mouseListeners_ != 0)
  33295. {
  33296. for (int i = mouseListeners_->size(); --i >= 0;)
  33297. {
  33298. ((MouseListener*) mouseListeners_->getUnchecked (i))->mouseWheelMove (me, wheelIncrementX, wheelIncrementY);
  33299. if (deletionChecker.hasBeenDeleted())
  33300. return;
  33301. i = jmin (i, mouseListeners_->size());
  33302. }
  33303. }
  33304. const Component* p = parentComponent_;
  33305. while (p != 0)
  33306. {
  33307. const ComponentDeletionWatcher parentDeletionChecker (p);
  33308. for (int i = p->numDeepMouseListeners; --i >= 0;)
  33309. {
  33310. ((MouseListener*) (p->mouseListeners_->getUnchecked (i)))->mouseWheelMove (me, wheelIncrementX, wheelIncrementY);
  33311. if (deletionChecker.hasBeenDeleted() || parentDeletionChecker.hasBeenDeleted())
  33312. return;
  33313. i = jmin (i, p->numDeepMouseListeners);
  33314. }
  33315. p = p->parentComponent_;
  33316. }
  33317. sendFakeMouseMove();
  33318. }
  33319. }
  33320. void Component::sendFakeMouseMove() const
  33321. {
  33322. ComponentPeer* const peer = getPeer();
  33323. if (peer != 0)
  33324. peer->sendFakeMouseMove();
  33325. }
  33326. void Component::broughtToFront()
  33327. {
  33328. }
  33329. void Component::internalBroughtToFront()
  33330. {
  33331. if (isValidComponent())
  33332. {
  33333. if (flags.hasHeavyweightPeerFlag)
  33334. Desktop::getInstance().componentBroughtToFront (this);
  33335. const ComponentDeletionWatcher deletionChecker (this);
  33336. broughtToFront();
  33337. if (deletionChecker.hasBeenDeleted())
  33338. return;
  33339. if (componentListeners_ != 0)
  33340. {
  33341. for (int i = componentListeners_->size(); --i >= 0;)
  33342. {
  33343. ((ComponentListener*) componentListeners_->getUnchecked (i))
  33344. ->componentBroughtToFront (*this);
  33345. if (deletionChecker.hasBeenDeleted())
  33346. return;
  33347. i = jmin (i, componentListeners_->size());
  33348. }
  33349. }
  33350. // when brought to the front and there's a modal component blocking this one,
  33351. // we need to bring the modal one to the front instead..
  33352. Component* const cm = getCurrentlyModalComponent();
  33353. if (cm != 0 && cm->getTopLevelComponent() != getTopLevelComponent())
  33354. bringModalComponentToFront();
  33355. }
  33356. }
  33357. void Component::focusGained (FocusChangeType)
  33358. {
  33359. // base class does nothing
  33360. }
  33361. void Component::internalFocusGain (const FocusChangeType cause)
  33362. {
  33363. const ComponentDeletionWatcher deletionChecker (this);
  33364. focusGained (cause);
  33365. if (! deletionChecker.hasBeenDeleted())
  33366. internalChildFocusChange (cause);
  33367. }
  33368. void Component::focusLost (FocusChangeType)
  33369. {
  33370. // base class does nothing
  33371. }
  33372. void Component::internalFocusLoss (const FocusChangeType cause)
  33373. {
  33374. const ComponentDeletionWatcher deletionChecker (this);
  33375. focusLost (focusChangedDirectly);
  33376. if (! deletionChecker.hasBeenDeleted())
  33377. internalChildFocusChange (cause);
  33378. }
  33379. void Component::focusOfChildComponentChanged (FocusChangeType /*cause*/)
  33380. {
  33381. // base class does nothing
  33382. }
  33383. void Component::internalChildFocusChange (FocusChangeType cause)
  33384. {
  33385. const bool childIsNowFocused = hasKeyboardFocus (true);
  33386. if (flags.childCompFocusedFlag != childIsNowFocused)
  33387. {
  33388. flags.childCompFocusedFlag = childIsNowFocused;
  33389. const ComponentDeletionWatcher deletionChecker (this);
  33390. focusOfChildComponentChanged (cause);
  33391. if (deletionChecker.hasBeenDeleted())
  33392. return;
  33393. }
  33394. if (parentComponent_ != 0)
  33395. parentComponent_->internalChildFocusChange (cause);
  33396. }
  33397. bool Component::isEnabled() const throw()
  33398. {
  33399. return (! flags.isDisabledFlag)
  33400. && (parentComponent_ == 0 || parentComponent_->isEnabled());
  33401. }
  33402. void Component::setEnabled (const bool shouldBeEnabled)
  33403. {
  33404. if (flags.isDisabledFlag == shouldBeEnabled)
  33405. {
  33406. flags.isDisabledFlag = ! shouldBeEnabled;
  33407. // if any parent components are disabled, setting our flag won't make a difference,
  33408. // so no need to send a change message
  33409. if (parentComponent_ == 0 || parentComponent_->isEnabled())
  33410. sendEnablementChangeMessage();
  33411. }
  33412. }
  33413. void Component::sendEnablementChangeMessage()
  33414. {
  33415. const ComponentDeletionWatcher deletionChecker (this);
  33416. enablementChanged();
  33417. if (deletionChecker.hasBeenDeleted())
  33418. return;
  33419. for (int i = getNumChildComponents(); --i >= 0;)
  33420. {
  33421. Component* const c = getChildComponent (i);
  33422. if (c != 0)
  33423. {
  33424. c->sendEnablementChangeMessage();
  33425. if (deletionChecker.hasBeenDeleted())
  33426. return;
  33427. }
  33428. }
  33429. }
  33430. void Component::enablementChanged()
  33431. {
  33432. }
  33433. void Component::setWantsKeyboardFocus (const bool wantsFocus) throw()
  33434. {
  33435. flags.wantsFocusFlag = wantsFocus;
  33436. }
  33437. void Component::setMouseClickGrabsKeyboardFocus (const bool shouldGrabFocus)
  33438. {
  33439. flags.dontFocusOnMouseClickFlag = ! shouldGrabFocus;
  33440. }
  33441. bool Component::getMouseClickGrabsKeyboardFocus() const throw()
  33442. {
  33443. return ! flags.dontFocusOnMouseClickFlag;
  33444. }
  33445. bool Component::getWantsKeyboardFocus() const throw()
  33446. {
  33447. return flags.wantsFocusFlag && ! flags.isDisabledFlag;
  33448. }
  33449. void Component::setFocusContainer (const bool shouldBeFocusContainer) throw()
  33450. {
  33451. flags.isFocusContainerFlag = shouldBeFocusContainer;
  33452. }
  33453. bool Component::isFocusContainer() const throw()
  33454. {
  33455. return flags.isFocusContainerFlag;
  33456. }
  33457. int Component::getExplicitFocusOrder() const throw()
  33458. {
  33459. return getComponentPropertyInt (T("_jexfo"), false, 0);
  33460. }
  33461. void Component::setExplicitFocusOrder (const int newFocusOrderIndex) throw()
  33462. {
  33463. setComponentProperty (T("_jexfo"), newFocusOrderIndex);
  33464. }
  33465. KeyboardFocusTraverser* Component::createFocusTraverser()
  33466. {
  33467. if (flags.isFocusContainerFlag || parentComponent_ == 0)
  33468. return new KeyboardFocusTraverser();
  33469. return parentComponent_->createFocusTraverser();
  33470. }
  33471. void Component::takeKeyboardFocus (const FocusChangeType cause)
  33472. {
  33473. // give the focus to this component
  33474. if (currentlyFocusedComponent != this)
  33475. {
  33476. JUCE_TRY
  33477. {
  33478. // get the focus onto our desktop window
  33479. ComponentPeer* const peer = getPeer();
  33480. if (peer != 0)
  33481. {
  33482. const ComponentDeletionWatcher deletionChecker (this);
  33483. peer->grabFocus();
  33484. if (peer->isFocused() && currentlyFocusedComponent != this)
  33485. {
  33486. Component* const componentLosingFocus = currentlyFocusedComponent;
  33487. currentlyFocusedComponent = this;
  33488. Desktop::getInstance().triggerFocusCallback();
  33489. // call this after setting currentlyFocusedComponent so that the one that's
  33490. // losing it has a chance to see where focus is going
  33491. if (componentLosingFocus->isValidComponent())
  33492. componentLosingFocus->internalFocusLoss (cause);
  33493. if (currentlyFocusedComponent == this)
  33494. {
  33495. focusGained (cause);
  33496. if (! deletionChecker.hasBeenDeleted())
  33497. internalChildFocusChange (cause);
  33498. }
  33499. }
  33500. }
  33501. }
  33502. #if JUCE_CATCH_UNHANDLED_EXCEPTIONS
  33503. catch (const std::exception& e)
  33504. {
  33505. currentlyFocusedComponent = 0;
  33506. Desktop::getInstance().triggerFocusCallback();
  33507. JUCEApplication::sendUnhandledException (&e, __FILE__, __LINE__);
  33508. }
  33509. catch (...)
  33510. {
  33511. currentlyFocusedComponent = 0;
  33512. Desktop::getInstance().triggerFocusCallback();
  33513. JUCEApplication::sendUnhandledException (0, __FILE__, __LINE__);
  33514. }
  33515. #endif
  33516. }
  33517. }
  33518. void Component::grabFocusInternal (const FocusChangeType cause, const bool canTryParent)
  33519. {
  33520. if (isShowing())
  33521. {
  33522. if (flags.wantsFocusFlag && (isEnabled() || parentComponent_ == 0))
  33523. {
  33524. takeKeyboardFocus (cause);
  33525. }
  33526. else
  33527. {
  33528. if (isParentOf (currentlyFocusedComponent)
  33529. && currentlyFocusedComponent->isShowing())
  33530. {
  33531. // do nothing if the focused component is actually a child of ours..
  33532. }
  33533. else
  33534. {
  33535. // find the default child component..
  33536. ScopedPointer <KeyboardFocusTraverser> traverser (createFocusTraverser());
  33537. if (traverser != 0)
  33538. {
  33539. Component* const defaultComp = traverser->getDefaultComponent (this);
  33540. traverser = 0;
  33541. if (defaultComp != 0)
  33542. {
  33543. defaultComp->grabFocusInternal (cause, false);
  33544. return;
  33545. }
  33546. }
  33547. if (canTryParent && parentComponent_ != 0)
  33548. {
  33549. // if no children want it and we're allowed to try our parent comp,
  33550. // then pass up to parent, which will try our siblings.
  33551. parentComponent_->grabFocusInternal (cause, true);
  33552. }
  33553. }
  33554. }
  33555. }
  33556. }
  33557. void Component::grabKeyboardFocus()
  33558. {
  33559. // if component methods are being called from threads other than the message
  33560. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  33561. checkMessageManagerIsLocked
  33562. grabFocusInternal (focusChangedDirectly);
  33563. }
  33564. void Component::moveKeyboardFocusToSibling (const bool moveToNext)
  33565. {
  33566. // if component methods are being called from threads other than the message
  33567. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  33568. checkMessageManagerIsLocked
  33569. if (parentComponent_ != 0)
  33570. {
  33571. ScopedPointer <KeyboardFocusTraverser> traverser (createFocusTraverser());
  33572. if (traverser != 0)
  33573. {
  33574. Component* const nextComp = moveToNext ? traverser->getNextComponent (this)
  33575. : traverser->getPreviousComponent (this);
  33576. traverser = 0;
  33577. if (nextComp != 0)
  33578. {
  33579. if (nextComp->isCurrentlyBlockedByAnotherModalComponent())
  33580. {
  33581. const ComponentDeletionWatcher deletionChecker (nextComp);
  33582. internalModalInputAttempt();
  33583. if (deletionChecker.hasBeenDeleted()
  33584. || nextComp->isCurrentlyBlockedByAnotherModalComponent())
  33585. return;
  33586. }
  33587. nextComp->grabFocusInternal (focusChangedByTabKey);
  33588. return;
  33589. }
  33590. }
  33591. parentComponent_->moveKeyboardFocusToSibling (moveToNext);
  33592. }
  33593. }
  33594. bool Component::hasKeyboardFocus (const bool trueIfChildIsFocused) const throw()
  33595. {
  33596. return (currentlyFocusedComponent == this)
  33597. || (trueIfChildIsFocused && isParentOf (currentlyFocusedComponent));
  33598. }
  33599. Component* JUCE_CALLTYPE Component::getCurrentlyFocusedComponent() throw()
  33600. {
  33601. return currentlyFocusedComponent;
  33602. }
  33603. void Component::giveAwayFocus()
  33604. {
  33605. // use a copy so we can clear the value before the call
  33606. Component* const componentLosingFocus = currentlyFocusedComponent;
  33607. currentlyFocusedComponent = 0;
  33608. Desktop::getInstance().triggerFocusCallback();
  33609. if (componentLosingFocus->isValidComponent())
  33610. componentLosingFocus->internalFocusLoss (focusChangedDirectly);
  33611. }
  33612. bool Component::isMouseOver() const throw()
  33613. {
  33614. return flags.mouseOverFlag;
  33615. }
  33616. bool Component::isMouseButtonDown() const throw()
  33617. {
  33618. return flags.draggingFlag;
  33619. }
  33620. bool Component::isMouseOverOrDragging() const throw()
  33621. {
  33622. return flags.mouseOverFlag || flags.draggingFlag;
  33623. }
  33624. bool JUCE_CALLTYPE Component::isMouseButtonDownAnywhere() throw()
  33625. {
  33626. return ModifierKeys::getCurrentModifiers().isAnyMouseButtonDown();
  33627. }
  33628. void Component::getMouseXYRelative (int& mx, int& my) const throw()
  33629. {
  33630. Desktop::getMousePosition (mx, my);
  33631. globalPositionToRelative (mx, my);
  33632. mx += unboundedMouseOffsetX;
  33633. my += unboundedMouseOffsetY;
  33634. }
  33635. void Component::enableUnboundedMouseMovement (bool enable,
  33636. bool keepCursorVisibleUntilOffscreen) throw()
  33637. {
  33638. enable = enable && isMouseButtonDown();
  33639. isCursorVisibleUntilOffscreen = keepCursorVisibleUntilOffscreen;
  33640. if (enable != isUnboundedMouseModeOn)
  33641. {
  33642. if ((! enable) && ((! isCursorVisibleUntilOffscreen)
  33643. || unboundedMouseOffsetX != 0
  33644. || unboundedMouseOffsetY != 0))
  33645. {
  33646. // when released, return the mouse to within the component's bounds
  33647. int mx, my;
  33648. getMouseXYRelative (mx, my);
  33649. mx = jlimit (0, getWidth(), mx);
  33650. my = jlimit (0, getHeight(), my);
  33651. relativePositionToGlobal (mx, my);
  33652. Desktop::setMousePosition (mx, my);
  33653. }
  33654. isUnboundedMouseModeOn = enable;
  33655. unboundedMouseOffsetX = 0;
  33656. unboundedMouseOffsetY = 0;
  33657. internalUpdateMouseCursor (true);
  33658. }
  33659. }
  33660. Component* JUCE_CALLTYPE Component::getComponentUnderMouse() throw()
  33661. {
  33662. return componentUnderMouse;
  33663. }
  33664. const Rectangle Component::getParentMonitorArea() const throw()
  33665. {
  33666. int centreX = getWidth() / 2;
  33667. int centreY = getHeight() / 2;
  33668. relativePositionToGlobal (centreX, centreY);
  33669. return Desktop::getInstance().getMonitorAreaContaining (centreX, centreY);
  33670. }
  33671. void Component::addKeyListener (KeyListener* const newListener) throw()
  33672. {
  33673. if (keyListeners_ == 0)
  33674. keyListeners_ = new VoidArray();
  33675. keyListeners_->addIfNotAlreadyThere (newListener);
  33676. }
  33677. void Component::removeKeyListener (KeyListener* const listenerToRemove) throw()
  33678. {
  33679. if (keyListeners_ != 0)
  33680. keyListeners_->removeValue (listenerToRemove);
  33681. }
  33682. bool Component::keyPressed (const KeyPress&)
  33683. {
  33684. return false;
  33685. }
  33686. bool Component::keyStateChanged (const bool /*isKeyDown*/)
  33687. {
  33688. return false;
  33689. }
  33690. void Component::modifierKeysChanged (const ModifierKeys& modifiers)
  33691. {
  33692. if (parentComponent_ != 0)
  33693. parentComponent_->modifierKeysChanged (modifiers);
  33694. }
  33695. void Component::internalModifierKeysChanged()
  33696. {
  33697. sendFakeMouseMove();
  33698. modifierKeysChanged (ModifierKeys::getCurrentModifiers());
  33699. }
  33700. ComponentPeer* Component::getPeer() const throw()
  33701. {
  33702. if (flags.hasHeavyweightPeerFlag)
  33703. return ComponentPeer::getPeerFor (this);
  33704. else if (parentComponent_ != 0)
  33705. return parentComponent_->getPeer();
  33706. else
  33707. return 0;
  33708. }
  33709. const String Component::getComponentProperty (const String& keyName,
  33710. const bool useParentComponentIfNotFound,
  33711. const String& defaultReturnValue) const throw()
  33712. {
  33713. if (propertySet_ != 0 && ((! useParentComponentIfNotFound) || propertySet_->containsKey (keyName)))
  33714. return propertySet_->getValue (keyName, defaultReturnValue);
  33715. if (useParentComponentIfNotFound && (parentComponent_ != 0))
  33716. return parentComponent_->getComponentProperty (keyName, true, defaultReturnValue);
  33717. return defaultReturnValue;
  33718. }
  33719. int Component::getComponentPropertyInt (const String& keyName,
  33720. const bool useParentComponentIfNotFound,
  33721. const int defaultReturnValue) const throw()
  33722. {
  33723. if (propertySet_ != 0 && ((! useParentComponentIfNotFound) || propertySet_->containsKey (keyName)))
  33724. return propertySet_->getIntValue (keyName, defaultReturnValue);
  33725. if (useParentComponentIfNotFound && (parentComponent_ != 0))
  33726. return parentComponent_->getComponentPropertyInt (keyName, true, defaultReturnValue);
  33727. return defaultReturnValue;
  33728. }
  33729. double Component::getComponentPropertyDouble (const String& keyName,
  33730. const bool useParentComponentIfNotFound,
  33731. const double defaultReturnValue) const throw()
  33732. {
  33733. if (propertySet_ != 0 && ((! useParentComponentIfNotFound) || propertySet_->containsKey (keyName)))
  33734. return propertySet_->getDoubleValue (keyName, defaultReturnValue);
  33735. if (useParentComponentIfNotFound && (parentComponent_ != 0))
  33736. return parentComponent_->getComponentPropertyDouble (keyName, true, defaultReturnValue);
  33737. return defaultReturnValue;
  33738. }
  33739. bool Component::getComponentPropertyBool (const String& keyName,
  33740. const bool useParentComponentIfNotFound,
  33741. const bool defaultReturnValue) const throw()
  33742. {
  33743. if (propertySet_ != 0 && ((! useParentComponentIfNotFound) || propertySet_->containsKey (keyName)))
  33744. return propertySet_->getBoolValue (keyName, defaultReturnValue);
  33745. if (useParentComponentIfNotFound && (parentComponent_ != 0))
  33746. return parentComponent_->getComponentPropertyBool (keyName, true, defaultReturnValue);
  33747. return defaultReturnValue;
  33748. }
  33749. const Colour Component::getComponentPropertyColour (const String& keyName,
  33750. const bool useParentComponentIfNotFound,
  33751. const Colour& defaultReturnValue) const throw()
  33752. {
  33753. return Colour ((uint32) getComponentPropertyInt (keyName,
  33754. useParentComponentIfNotFound,
  33755. defaultReturnValue.getARGB()));
  33756. }
  33757. void Component::setComponentProperty (const String& keyName, const String& value) throw()
  33758. {
  33759. if (propertySet_ == 0)
  33760. propertySet_ = new PropertySet();
  33761. propertySet_->setValue (keyName, value);
  33762. }
  33763. void Component::setComponentProperty (const String& keyName, const int value) throw()
  33764. {
  33765. if (propertySet_ == 0)
  33766. propertySet_ = new PropertySet();
  33767. propertySet_->setValue (keyName, value);
  33768. }
  33769. void Component::setComponentProperty (const String& keyName, const double value) throw()
  33770. {
  33771. if (propertySet_ == 0)
  33772. propertySet_ = new PropertySet();
  33773. propertySet_->setValue (keyName, value);
  33774. }
  33775. void Component::setComponentProperty (const String& keyName, const bool value) throw()
  33776. {
  33777. if (propertySet_ == 0)
  33778. propertySet_ = new PropertySet();
  33779. propertySet_->setValue (keyName, value);
  33780. }
  33781. void Component::setComponentProperty (const String& keyName, const Colour& colour) throw()
  33782. {
  33783. setComponentProperty (keyName, (int) colour.getARGB());
  33784. }
  33785. void Component::removeComponentProperty (const String& keyName) throw()
  33786. {
  33787. if (propertySet_ != 0)
  33788. propertySet_->removeValue (keyName);
  33789. }
  33790. ComponentDeletionWatcher::ComponentDeletionWatcher (const Component* const componentToWatch_) throw()
  33791. : componentToWatch (componentToWatch_),
  33792. componentUID (componentToWatch_->getComponentUID())
  33793. {
  33794. // not possible to check on an already-deleted object..
  33795. jassert (componentToWatch_->isValidComponent());
  33796. }
  33797. ComponentDeletionWatcher::~ComponentDeletionWatcher() throw() {}
  33798. bool ComponentDeletionWatcher::hasBeenDeleted() const throw()
  33799. {
  33800. return ! (componentToWatch->isValidComponent()
  33801. && componentToWatch->getComponentUID() == componentUID);
  33802. }
  33803. const Component* ComponentDeletionWatcher::getComponent() const throw()
  33804. {
  33805. return hasBeenDeleted() ? 0 : componentToWatch;
  33806. }
  33807. END_JUCE_NAMESPACE
  33808. /********* End of inlined file: juce_Component.cpp *********/
  33809. /********* Start of inlined file: juce_ComponentListener.cpp *********/
  33810. BEGIN_JUCE_NAMESPACE
  33811. void ComponentListener::componentMovedOrResized (Component&, bool, bool)
  33812. {
  33813. }
  33814. void ComponentListener::componentBroughtToFront (Component&)
  33815. {
  33816. }
  33817. void ComponentListener::componentVisibilityChanged (Component&)
  33818. {
  33819. }
  33820. void ComponentListener::componentChildrenChanged (Component&)
  33821. {
  33822. }
  33823. void ComponentListener::componentParentHierarchyChanged (Component&)
  33824. {
  33825. }
  33826. void ComponentListener::componentNameChanged (Component&)
  33827. {
  33828. }
  33829. END_JUCE_NAMESPACE
  33830. /********* End of inlined file: juce_ComponentListener.cpp *********/
  33831. /********* Start of inlined file: juce_Desktop.cpp *********/
  33832. BEGIN_JUCE_NAMESPACE
  33833. extern void juce_updateMultiMonitorInfo (Array <Rectangle>& monitorCoords,
  33834. const bool clipToWorkArea);
  33835. static Desktop* juce_desktopInstance = 0;
  33836. Desktop::Desktop() throw()
  33837. : lastMouseX (0),
  33838. lastMouseY (0),
  33839. kioskModeComponent (0)
  33840. {
  33841. refreshMonitorSizes();
  33842. }
  33843. Desktop::~Desktop() throw()
  33844. {
  33845. jassert (juce_desktopInstance == this);
  33846. juce_desktopInstance = 0;
  33847. // doh! If you don't delete all your windows before exiting, you're going to
  33848. // be leaking memory!
  33849. jassert (desktopComponents.size() == 0);
  33850. }
  33851. Desktop& JUCE_CALLTYPE Desktop::getInstance() throw()
  33852. {
  33853. if (juce_desktopInstance == 0)
  33854. juce_desktopInstance = new Desktop();
  33855. return *juce_desktopInstance;
  33856. }
  33857. void Desktop::refreshMonitorSizes() throw()
  33858. {
  33859. const Array <Rectangle> oldClipped (monitorCoordsClipped);
  33860. const Array <Rectangle> oldUnclipped (monitorCoordsUnclipped);
  33861. monitorCoordsClipped.clear();
  33862. monitorCoordsUnclipped.clear();
  33863. juce_updateMultiMonitorInfo (monitorCoordsClipped, true);
  33864. juce_updateMultiMonitorInfo (monitorCoordsUnclipped, false);
  33865. jassert (monitorCoordsClipped.size() > 0
  33866. && monitorCoordsClipped.size() == monitorCoordsUnclipped.size());
  33867. if (oldClipped != monitorCoordsClipped
  33868. || oldUnclipped != monitorCoordsUnclipped)
  33869. {
  33870. for (int i = ComponentPeer::getNumPeers(); --i >= 0;)
  33871. {
  33872. ComponentPeer* const p = ComponentPeer::getPeer (i);
  33873. if (p != 0)
  33874. p->handleScreenSizeChange();
  33875. }
  33876. }
  33877. }
  33878. int Desktop::getNumDisplayMonitors() const throw()
  33879. {
  33880. return monitorCoordsClipped.size();
  33881. }
  33882. const Rectangle Desktop::getDisplayMonitorCoordinates (const int index, const bool clippedToWorkArea) const throw()
  33883. {
  33884. return clippedToWorkArea ? monitorCoordsClipped [index]
  33885. : monitorCoordsUnclipped [index];
  33886. }
  33887. const RectangleList Desktop::getAllMonitorDisplayAreas (const bool clippedToWorkArea) const throw()
  33888. {
  33889. RectangleList rl;
  33890. for (int i = 0; i < getNumDisplayMonitors(); ++i)
  33891. rl.addWithoutMerging (getDisplayMonitorCoordinates (i, clippedToWorkArea));
  33892. return rl;
  33893. }
  33894. const Rectangle Desktop::getMainMonitorArea (const bool clippedToWorkArea) const throw()
  33895. {
  33896. return getDisplayMonitorCoordinates (0, clippedToWorkArea);
  33897. }
  33898. const Rectangle Desktop::getMonitorAreaContaining (int cx, int cy, const bool clippedToWorkArea) const throw()
  33899. {
  33900. Rectangle best (getMainMonitorArea (clippedToWorkArea));
  33901. double bestDistance = 1.0e10;
  33902. for (int i = getNumDisplayMonitors(); --i >= 0;)
  33903. {
  33904. const Rectangle rect (getDisplayMonitorCoordinates (i, clippedToWorkArea));
  33905. if (rect.contains (cx, cy))
  33906. return rect;
  33907. const double distance = juce_hypot ((double) (rect.getCentreX() - cx),
  33908. (double) (rect.getCentreY() - cy));
  33909. if (distance < bestDistance)
  33910. {
  33911. bestDistance = distance;
  33912. best = rect;
  33913. }
  33914. }
  33915. return best;
  33916. }
  33917. int Desktop::getNumComponents() const throw()
  33918. {
  33919. return desktopComponents.size();
  33920. }
  33921. Component* Desktop::getComponent (const int index) const throw()
  33922. {
  33923. return desktopComponents [index];
  33924. }
  33925. Component* Desktop::findComponentAt (const int screenX,
  33926. const int screenY) const
  33927. {
  33928. for (int i = desktopComponents.size(); --i >= 0;)
  33929. {
  33930. Component* const c = desktopComponents.getUnchecked(i);
  33931. int x = screenX, y = screenY;
  33932. c->globalPositionToRelative (x, y);
  33933. if (c->contains (x, y))
  33934. return c->getComponentAt (x, y);
  33935. }
  33936. return 0;
  33937. }
  33938. void Desktop::addDesktopComponent (Component* const c) throw()
  33939. {
  33940. jassert (c != 0);
  33941. jassert (! desktopComponents.contains (c));
  33942. desktopComponents.addIfNotAlreadyThere (c);
  33943. }
  33944. void Desktop::removeDesktopComponent (Component* const c) throw()
  33945. {
  33946. desktopComponents.removeValue (c);
  33947. }
  33948. void Desktop::componentBroughtToFront (Component* const c) throw()
  33949. {
  33950. const int index = desktopComponents.indexOf (c);
  33951. jassert (index >= 0);
  33952. if (index >= 0)
  33953. {
  33954. int newIndex = -1;
  33955. if (! c->isAlwaysOnTop())
  33956. {
  33957. newIndex = desktopComponents.size();
  33958. while (newIndex > 0 && desktopComponents.getUnchecked (newIndex - 1)->isAlwaysOnTop())
  33959. --newIndex;
  33960. --newIndex;
  33961. }
  33962. desktopComponents.move (index, newIndex);
  33963. }
  33964. }
  33965. // from Component.cpp
  33966. extern int juce_recentMouseDownX [4];
  33967. extern int juce_recentMouseDownY [4];
  33968. extern int juce_MouseClickCounter;
  33969. void Desktop::getLastMouseDownPosition (int& x, int& y) throw()
  33970. {
  33971. x = juce_recentMouseDownX [0];
  33972. y = juce_recentMouseDownY [0];
  33973. }
  33974. int Desktop::getMouseButtonClickCounter() throw()
  33975. {
  33976. return juce_MouseClickCounter;
  33977. }
  33978. void Desktop::addGlobalMouseListener (MouseListener* const listener) throw()
  33979. {
  33980. jassert (listener != 0);
  33981. if (listener != 0)
  33982. {
  33983. mouseListeners.add (listener);
  33984. resetTimer();
  33985. }
  33986. }
  33987. void Desktop::removeGlobalMouseListener (MouseListener* const listener) throw()
  33988. {
  33989. mouseListeners.removeValue (listener);
  33990. resetTimer();
  33991. }
  33992. void Desktop::addFocusChangeListener (FocusChangeListener* const listener) throw()
  33993. {
  33994. jassert (listener != 0);
  33995. if (listener != 0)
  33996. focusListeners.add (listener);
  33997. }
  33998. void Desktop::removeFocusChangeListener (FocusChangeListener* const listener) throw()
  33999. {
  34000. focusListeners.removeValue (listener);
  34001. }
  34002. void Desktop::triggerFocusCallback() throw()
  34003. {
  34004. triggerAsyncUpdate();
  34005. }
  34006. void Desktop::handleAsyncUpdate()
  34007. {
  34008. for (int i = focusListeners.size(); --i >= 0;)
  34009. {
  34010. ((FocusChangeListener*) focusListeners.getUnchecked (i))->globalFocusChanged (Component::getCurrentlyFocusedComponent());
  34011. i = jmin (i, focusListeners.size());
  34012. }
  34013. }
  34014. void Desktop::timerCallback()
  34015. {
  34016. int x, y;
  34017. getMousePosition (x, y);
  34018. if (lastMouseX != x || lastMouseY != y)
  34019. sendMouseMove();
  34020. }
  34021. void Desktop::sendMouseMove()
  34022. {
  34023. if (mouseListeners.size() > 0)
  34024. {
  34025. startTimer (20);
  34026. int x, y;
  34027. getMousePosition (x, y);
  34028. lastMouseX = x;
  34029. lastMouseY = y;
  34030. Component* const target = findComponentAt (x, y);
  34031. if (target != 0)
  34032. {
  34033. target->globalPositionToRelative (x, y);
  34034. ComponentDeletionWatcher deletionChecker (target);
  34035. const MouseEvent me (x, y,
  34036. ModifierKeys::getCurrentModifiers(),
  34037. target,
  34038. Time::getCurrentTime(),
  34039. x, y,
  34040. Time::getCurrentTime(),
  34041. 0, false);
  34042. for (int i = mouseListeners.size(); --i >= 0;)
  34043. {
  34044. if (ModifierKeys::getCurrentModifiers().isAnyMouseButtonDown())
  34045. ((MouseListener*) mouseListeners[i])->mouseDrag (me);
  34046. else
  34047. ((MouseListener*) mouseListeners[i])->mouseMove (me);
  34048. if (deletionChecker.hasBeenDeleted())
  34049. return;
  34050. i = jmin (i, mouseListeners.size());
  34051. }
  34052. }
  34053. }
  34054. }
  34055. void Desktop::resetTimer() throw()
  34056. {
  34057. if (mouseListeners.size() == 0)
  34058. stopTimer();
  34059. else
  34060. startTimer (100);
  34061. getMousePosition (lastMouseX, lastMouseY);
  34062. }
  34063. extern void juce_setKioskComponent (Component* kioskModeComponent, bool enableOrDisable, bool allowMenusAndBars);
  34064. void Desktop::setKioskModeComponent (Component* componentToUse, const bool allowMenusAndBars)
  34065. {
  34066. if (kioskModeComponent != componentToUse)
  34067. {
  34068. // agh! Don't delete a component without first stopping it being the kiosk comp
  34069. jassert (kioskModeComponent == 0 || kioskModeComponent->isValidComponent());
  34070. // agh! Don't remove a component from the desktop if it's the kiosk comp!
  34071. jassert (kioskModeComponent == 0 || kioskModeComponent->isOnDesktop());
  34072. if (kioskModeComponent->isValidComponent())
  34073. {
  34074. juce_setKioskComponent (kioskModeComponent, false, allowMenusAndBars);
  34075. kioskModeComponent->setBounds (kioskComponentOriginalBounds);
  34076. }
  34077. kioskModeComponent = componentToUse;
  34078. if (kioskModeComponent != 0)
  34079. {
  34080. jassert (kioskModeComponent->isValidComponent());
  34081. // Only components that are already on the desktop can be put into kiosk mode!
  34082. jassert (kioskModeComponent->isOnDesktop());
  34083. kioskComponentOriginalBounds = kioskModeComponent->getBounds();
  34084. juce_setKioskComponent (kioskModeComponent, true, allowMenusAndBars);
  34085. }
  34086. }
  34087. }
  34088. END_JUCE_NAMESPACE
  34089. /********* End of inlined file: juce_Desktop.cpp *********/
  34090. /********* Start of inlined file: juce_ArrowButton.cpp *********/
  34091. BEGIN_JUCE_NAMESPACE
  34092. ArrowButton::ArrowButton (const String& name,
  34093. float arrowDirectionInRadians,
  34094. const Colour& arrowColour)
  34095. : Button (name),
  34096. colour (arrowColour)
  34097. {
  34098. path.lineTo (0.0f, 1.0f);
  34099. path.lineTo (1.0f, 0.5f);
  34100. path.closeSubPath();
  34101. path.applyTransform (AffineTransform::rotation (float_Pi * 2.0f * arrowDirectionInRadians,
  34102. 0.5f, 0.5f));
  34103. setComponentEffect (&shadow);
  34104. buttonStateChanged();
  34105. }
  34106. ArrowButton::~ArrowButton()
  34107. {
  34108. }
  34109. void ArrowButton::paintButton (Graphics& g,
  34110. bool /*isMouseOverButton*/,
  34111. bool /*isButtonDown*/)
  34112. {
  34113. g.setColour (colour);
  34114. g.fillPath (path, path.getTransformToScaleToFit ((float) offset,
  34115. (float) offset,
  34116. (float) (getWidth() - 3),
  34117. (float) (getHeight() - 3),
  34118. false));
  34119. }
  34120. void ArrowButton::buttonStateChanged()
  34121. {
  34122. offset = (isDown()) ? 1 : 0;
  34123. shadow.setShadowProperties ((isDown()) ? 1.2f : 3.0f,
  34124. 0.3f, -1, 0);
  34125. }
  34126. END_JUCE_NAMESPACE
  34127. /********* End of inlined file: juce_ArrowButton.cpp *********/
  34128. /********* Start of inlined file: juce_Button.cpp *********/
  34129. BEGIN_JUCE_NAMESPACE
  34130. Button::Button (const String& name)
  34131. : Component (name),
  34132. keySource (0),
  34133. text (name),
  34134. buttonPressTime (0),
  34135. lastTimeCallbackTime (0),
  34136. commandManagerToUse (0),
  34137. autoRepeatDelay (-1),
  34138. autoRepeatSpeed (0),
  34139. autoRepeatMinimumDelay (-1),
  34140. radioGroupId (0),
  34141. commandID (0),
  34142. connectedEdgeFlags (0),
  34143. buttonState (buttonNormal),
  34144. lastToggleState (false),
  34145. clickTogglesState (false),
  34146. needsToRelease (false),
  34147. needsRepainting (false),
  34148. isKeyDown (false),
  34149. triggerOnMouseDown (false),
  34150. generateTooltip (false)
  34151. {
  34152. setWantsKeyboardFocus (true);
  34153. isOn.addListener (this);
  34154. }
  34155. Button::~Button()
  34156. {
  34157. isOn.removeListener (this);
  34158. if (commandManagerToUse != 0)
  34159. commandManagerToUse->removeListener (this);
  34160. repeatTimer = 0;
  34161. clearShortcuts();
  34162. }
  34163. void Button::setButtonText (const String& newText) throw()
  34164. {
  34165. if (text != newText)
  34166. {
  34167. text = newText;
  34168. repaint();
  34169. }
  34170. }
  34171. void Button::setTooltip (const String& newTooltip)
  34172. {
  34173. SettableTooltipClient::setTooltip (newTooltip);
  34174. generateTooltip = false;
  34175. }
  34176. const String Button::getTooltip()
  34177. {
  34178. if (generateTooltip && commandManagerToUse != 0 && commandID != 0)
  34179. {
  34180. String tt (commandManagerToUse->getDescriptionOfCommand (commandID));
  34181. Array <KeyPress> keyPresses (commandManagerToUse->getKeyMappings()->getKeyPressesAssignedToCommand (commandID));
  34182. for (int i = 0; i < keyPresses.size(); ++i)
  34183. {
  34184. const String key (keyPresses.getReference(i).getTextDescription());
  34185. tt << " [";
  34186. if (key.length() == 1)
  34187. tt << TRANS("shortcut") << ": '" << key << "']";
  34188. else
  34189. tt << key << ']';
  34190. }
  34191. return tt;
  34192. }
  34193. return SettableTooltipClient::getTooltip();
  34194. }
  34195. void Button::setConnectedEdges (const int connectedEdgeFlags_) throw()
  34196. {
  34197. if (connectedEdgeFlags != connectedEdgeFlags_)
  34198. {
  34199. connectedEdgeFlags = connectedEdgeFlags_;
  34200. repaint();
  34201. }
  34202. }
  34203. void Button::setToggleState (const bool shouldBeOn,
  34204. const bool sendChangeNotification)
  34205. {
  34206. if (shouldBeOn != lastToggleState)
  34207. {
  34208. const ComponentDeletionWatcher deletionWatcher (this);
  34209. isOn = shouldBeOn;
  34210. lastToggleState = shouldBeOn;
  34211. repaint();
  34212. if (sendChangeNotification)
  34213. sendClickMessage (ModifierKeys());
  34214. if ((! deletionWatcher.hasBeenDeleted()) && lastToggleState)
  34215. turnOffOtherButtonsInGroup (sendChangeNotification);
  34216. }
  34217. }
  34218. void Button::setClickingTogglesState (const bool shouldToggle) throw()
  34219. {
  34220. clickTogglesState = shouldToggle;
  34221. // if you've got clickTogglesState turned on, you shouldn't also connect the button
  34222. // up to be a command invoker. Instead, your command handler must flip the state of whatever
  34223. // it is that this button represents, and the button will update its state to reflect this
  34224. // in the applicationCommandListChanged() method.
  34225. jassert (commandManagerToUse == 0 || ! clickTogglesState);
  34226. }
  34227. bool Button::getClickingTogglesState() const throw()
  34228. {
  34229. return clickTogglesState;
  34230. }
  34231. void Button::valueChanged (Value& value)
  34232. {
  34233. if (value.refersToSameSourceAs (isOn))
  34234. setToggleState (isOn.getValue(), true);
  34235. }
  34236. void Button::setRadioGroupId (const int newGroupId)
  34237. {
  34238. if (radioGroupId != newGroupId)
  34239. {
  34240. radioGroupId = newGroupId;
  34241. if (lastToggleState)
  34242. turnOffOtherButtonsInGroup (true);
  34243. }
  34244. }
  34245. void Button::turnOffOtherButtonsInGroup (const bool sendChangeNotification)
  34246. {
  34247. Component* const p = getParentComponent();
  34248. if (p != 0 && radioGroupId != 0)
  34249. {
  34250. const ComponentDeletionWatcher deletionWatcher (this);
  34251. for (int i = p->getNumChildComponents(); --i >= 0;)
  34252. {
  34253. Component* const c = p->getChildComponent (i);
  34254. if (c != this)
  34255. {
  34256. Button* const b = dynamic_cast <Button*> (c);
  34257. if (b != 0 && b->getRadioGroupId() == radioGroupId)
  34258. {
  34259. b->setToggleState (false, sendChangeNotification);
  34260. if (deletionWatcher.hasBeenDeleted())
  34261. return;
  34262. }
  34263. }
  34264. }
  34265. }
  34266. }
  34267. void Button::enablementChanged()
  34268. {
  34269. updateState (0);
  34270. repaint();
  34271. }
  34272. Button::ButtonState Button::updateState (const MouseEvent* const e) throw()
  34273. {
  34274. ButtonState state = buttonNormal;
  34275. if (isEnabled() && isVisible() && ! isCurrentlyBlockedByAnotherModalComponent())
  34276. {
  34277. int mx, my;
  34278. if (e == 0)
  34279. {
  34280. getMouseXYRelative (mx, my);
  34281. }
  34282. else
  34283. {
  34284. const MouseEvent e2 (e->getEventRelativeTo (this));
  34285. mx = e2.x;
  34286. my = e2.y;
  34287. }
  34288. const bool over = reallyContains (mx, my, true);
  34289. const bool down = isMouseButtonDown();
  34290. if ((down && (over || (triggerOnMouseDown && buttonState == buttonDown))) || isKeyDown)
  34291. state = buttonDown;
  34292. else if (over)
  34293. state = buttonOver;
  34294. }
  34295. setState (state);
  34296. return state;
  34297. }
  34298. void Button::setState (const ButtonState newState)
  34299. {
  34300. if (buttonState != newState)
  34301. {
  34302. buttonState = newState;
  34303. repaint();
  34304. if (buttonState == buttonDown)
  34305. {
  34306. buttonPressTime = Time::getApproximateMillisecondCounter();
  34307. lastTimeCallbackTime = buttonPressTime;
  34308. }
  34309. sendStateMessage();
  34310. }
  34311. }
  34312. bool Button::isDown() const throw()
  34313. {
  34314. return buttonState == buttonDown;
  34315. }
  34316. bool Button::isOver() const throw()
  34317. {
  34318. return buttonState != buttonNormal;
  34319. }
  34320. void Button::buttonStateChanged()
  34321. {
  34322. }
  34323. uint32 Button::getMillisecondsSinceButtonDown() const throw()
  34324. {
  34325. const uint32 now = Time::getApproximateMillisecondCounter();
  34326. return now > buttonPressTime ? now - buttonPressTime : 0;
  34327. }
  34328. void Button::setTriggeredOnMouseDown (const bool isTriggeredOnMouseDown) throw()
  34329. {
  34330. triggerOnMouseDown = isTriggeredOnMouseDown;
  34331. }
  34332. void Button::clicked()
  34333. {
  34334. }
  34335. void Button::clicked (const ModifierKeys& /*modifiers*/)
  34336. {
  34337. clicked();
  34338. }
  34339. static const int clickMessageId = 0x2f3f4f99;
  34340. void Button::triggerClick()
  34341. {
  34342. postCommandMessage (clickMessageId);
  34343. }
  34344. void Button::internalClickCallback (const ModifierKeys& modifiers)
  34345. {
  34346. if (clickTogglesState)
  34347. setToggleState ((radioGroupId != 0) || ! lastToggleState, false);
  34348. sendClickMessage (modifiers);
  34349. }
  34350. void Button::flashButtonState() throw()
  34351. {
  34352. if (isEnabled())
  34353. {
  34354. needsToRelease = true;
  34355. setState (buttonDown);
  34356. getRepeatTimer().startTimer (100);
  34357. }
  34358. }
  34359. void Button::handleCommandMessage (int commandId)
  34360. {
  34361. if (commandId == clickMessageId)
  34362. {
  34363. if (isEnabled())
  34364. {
  34365. flashButtonState();
  34366. internalClickCallback (ModifierKeys::getCurrentModifiers());
  34367. }
  34368. }
  34369. else
  34370. {
  34371. Component::handleCommandMessage (commandId);
  34372. }
  34373. }
  34374. void Button::addButtonListener (ButtonListener* const newListener) throw()
  34375. {
  34376. jassert (newListener != 0);
  34377. jassert (! buttonListeners.contains (newListener)); // trying to add a listener to the list twice!
  34378. if (newListener != 0)
  34379. buttonListeners.add (newListener);
  34380. }
  34381. void Button::removeButtonListener (ButtonListener* const listener) throw()
  34382. {
  34383. jassert (buttonListeners.contains (listener)); // trying to remove a listener that isn't on the list!
  34384. buttonListeners.removeValue (listener);
  34385. }
  34386. void Button::sendClickMessage (const ModifierKeys& modifiers)
  34387. {
  34388. const ComponentDeletionWatcher cdw (this);
  34389. if (commandManagerToUse != 0 && commandID != 0)
  34390. {
  34391. ApplicationCommandTarget::InvocationInfo info (commandID);
  34392. info.invocationMethod = ApplicationCommandTarget::InvocationInfo::fromButton;
  34393. info.originatingComponent = this;
  34394. commandManagerToUse->invoke (info, true);
  34395. }
  34396. clicked (modifiers);
  34397. if (! cdw.hasBeenDeleted())
  34398. {
  34399. for (int i = buttonListeners.size(); --i >= 0;)
  34400. {
  34401. ButtonListener* const bl = (ButtonListener*) buttonListeners[i];
  34402. if (bl != 0)
  34403. {
  34404. bl->buttonClicked (this);
  34405. if (cdw.hasBeenDeleted())
  34406. return;
  34407. }
  34408. }
  34409. }
  34410. }
  34411. void Button::sendStateMessage()
  34412. {
  34413. const ComponentDeletionWatcher cdw (this);
  34414. buttonStateChanged();
  34415. if (cdw.hasBeenDeleted())
  34416. return;
  34417. for (int i = buttonListeners.size(); --i >= 0;)
  34418. {
  34419. ButtonListener* const bl = (ButtonListener*) buttonListeners[i];
  34420. if (bl != 0)
  34421. {
  34422. bl->buttonStateChanged (this);
  34423. if (cdw.hasBeenDeleted())
  34424. return;
  34425. }
  34426. }
  34427. }
  34428. void Button::paint (Graphics& g)
  34429. {
  34430. if (needsToRelease && isEnabled())
  34431. {
  34432. needsToRelease = false;
  34433. needsRepainting = true;
  34434. }
  34435. paintButton (g, isOver(), isDown());
  34436. }
  34437. void Button::mouseEnter (const MouseEvent& e)
  34438. {
  34439. updateState (&e);
  34440. }
  34441. void Button::mouseExit (const MouseEvent& e)
  34442. {
  34443. updateState (&e);
  34444. }
  34445. void Button::mouseDown (const MouseEvent& e)
  34446. {
  34447. updateState (&e);
  34448. if (isDown())
  34449. {
  34450. if (autoRepeatDelay >= 0)
  34451. getRepeatTimer().startTimer (autoRepeatDelay);
  34452. if (triggerOnMouseDown)
  34453. internalClickCallback (e.mods);
  34454. }
  34455. }
  34456. void Button::mouseUp (const MouseEvent& e)
  34457. {
  34458. const bool wasDown = isDown();
  34459. updateState (&e);
  34460. if (wasDown && isOver() && ! triggerOnMouseDown)
  34461. internalClickCallback (e.mods);
  34462. }
  34463. void Button::mouseDrag (const MouseEvent& e)
  34464. {
  34465. const ButtonState oldState = buttonState;
  34466. updateState (&e);
  34467. if (autoRepeatDelay >= 0 && buttonState != oldState && isDown())
  34468. getRepeatTimer().startTimer (autoRepeatSpeed);
  34469. }
  34470. void Button::focusGained (FocusChangeType)
  34471. {
  34472. updateState (0);
  34473. repaint();
  34474. }
  34475. void Button::focusLost (FocusChangeType)
  34476. {
  34477. updateState (0);
  34478. repaint();
  34479. }
  34480. void Button::setVisible (bool shouldBeVisible)
  34481. {
  34482. if (shouldBeVisible != isVisible())
  34483. {
  34484. Component::setVisible (shouldBeVisible);
  34485. if (! shouldBeVisible)
  34486. needsToRelease = false;
  34487. updateState (0);
  34488. }
  34489. else
  34490. {
  34491. Component::setVisible (shouldBeVisible);
  34492. }
  34493. }
  34494. void Button::parentHierarchyChanged()
  34495. {
  34496. Component* const newKeySource = (shortcuts.size() == 0) ? 0 : getTopLevelComponent();
  34497. if (newKeySource != keySource)
  34498. {
  34499. if (keySource->isValidComponent())
  34500. keySource->removeKeyListener (this);
  34501. keySource = newKeySource;
  34502. if (keySource->isValidComponent())
  34503. keySource->addKeyListener (this);
  34504. }
  34505. }
  34506. void Button::setCommandToTrigger (ApplicationCommandManager* const commandManagerToUse_,
  34507. const int commandID_,
  34508. const bool generateTooltip_)
  34509. {
  34510. commandID = commandID_;
  34511. generateTooltip = generateTooltip_;
  34512. if (commandManagerToUse != commandManagerToUse_)
  34513. {
  34514. if (commandManagerToUse != 0)
  34515. commandManagerToUse->removeListener (this);
  34516. commandManagerToUse = commandManagerToUse_;
  34517. if (commandManagerToUse != 0)
  34518. commandManagerToUse->addListener (this);
  34519. // if you've got clickTogglesState turned on, you shouldn't also connect the button
  34520. // up to be a command invoker. Instead, your command handler must flip the state of whatever
  34521. // it is that this button represents, and the button will update its state to reflect this
  34522. // in the applicationCommandListChanged() method.
  34523. jassert (commandManagerToUse == 0 || ! clickTogglesState);
  34524. }
  34525. if (commandManagerToUse != 0)
  34526. applicationCommandListChanged();
  34527. else
  34528. setEnabled (true);
  34529. }
  34530. void Button::applicationCommandInvoked (const ApplicationCommandTarget::InvocationInfo& info)
  34531. {
  34532. if (info.commandID == commandID
  34533. && (info.commandFlags & ApplicationCommandInfo::dontTriggerVisualFeedback) == 0)
  34534. {
  34535. flashButtonState();
  34536. }
  34537. }
  34538. void Button::applicationCommandListChanged()
  34539. {
  34540. if (commandManagerToUse != 0)
  34541. {
  34542. ApplicationCommandInfo info (0);
  34543. ApplicationCommandTarget* const target = commandManagerToUse->getTargetForCommand (commandID, info);
  34544. setEnabled (target != 0 && (info.flags & ApplicationCommandInfo::isDisabled) == 0);
  34545. if (target != 0)
  34546. setToggleState ((info.flags & ApplicationCommandInfo::isTicked) != 0, false);
  34547. }
  34548. }
  34549. void Button::addShortcut (const KeyPress& key)
  34550. {
  34551. if (key.isValid())
  34552. {
  34553. jassert (! isRegisteredForShortcut (key)); // already registered!
  34554. shortcuts.add (key);
  34555. parentHierarchyChanged();
  34556. }
  34557. }
  34558. void Button::clearShortcuts()
  34559. {
  34560. shortcuts.clear();
  34561. parentHierarchyChanged();
  34562. }
  34563. bool Button::isShortcutPressed() const throw()
  34564. {
  34565. if (! isCurrentlyBlockedByAnotherModalComponent())
  34566. {
  34567. for (int i = shortcuts.size(); --i >= 0;)
  34568. if (shortcuts.getReference(i).isCurrentlyDown())
  34569. return true;
  34570. }
  34571. return false;
  34572. }
  34573. bool Button::isRegisteredForShortcut (const KeyPress& key) const throw()
  34574. {
  34575. for (int i = shortcuts.size(); --i >= 0;)
  34576. if (key == shortcuts.getReference(i))
  34577. return true;
  34578. return false;
  34579. }
  34580. bool Button::keyStateChanged (const bool, Component*)
  34581. {
  34582. if (! isEnabled())
  34583. return false;
  34584. const bool wasDown = isKeyDown;
  34585. isKeyDown = isShortcutPressed();
  34586. if (autoRepeatDelay >= 0 && (isKeyDown && ! wasDown))
  34587. getRepeatTimer().startTimer (autoRepeatDelay);
  34588. updateState (0);
  34589. if (isEnabled() && wasDown && ! isKeyDown)
  34590. {
  34591. internalClickCallback (ModifierKeys::getCurrentModifiers());
  34592. // (return immediately - this button may now have been deleted)
  34593. return true;
  34594. }
  34595. return wasDown || isKeyDown;
  34596. }
  34597. bool Button::keyPressed (const KeyPress&, Component*)
  34598. {
  34599. // returning true will avoid forwarding events for keys that we're using as shortcuts
  34600. return isShortcutPressed();
  34601. }
  34602. bool Button::keyPressed (const KeyPress& key)
  34603. {
  34604. if (isEnabled() && key.isKeyCode (KeyPress::returnKey))
  34605. {
  34606. triggerClick();
  34607. return true;
  34608. }
  34609. return false;
  34610. }
  34611. void Button::setRepeatSpeed (const int initialDelayMillisecs,
  34612. const int repeatMillisecs,
  34613. const int minimumDelayInMillisecs) throw()
  34614. {
  34615. autoRepeatDelay = initialDelayMillisecs;
  34616. autoRepeatSpeed = repeatMillisecs;
  34617. autoRepeatMinimumDelay = jmin (autoRepeatSpeed, minimumDelayInMillisecs);
  34618. }
  34619. void Button::repeatTimerCallback() throw()
  34620. {
  34621. if (needsRepainting)
  34622. {
  34623. getRepeatTimer().stopTimer();
  34624. updateState (0);
  34625. needsRepainting = false;
  34626. }
  34627. else if (autoRepeatSpeed > 0 && (isKeyDown || (updateState (0) == buttonDown)))
  34628. {
  34629. int repeatSpeed = autoRepeatSpeed;
  34630. if (autoRepeatMinimumDelay >= 0)
  34631. {
  34632. double timeHeldDown = jmin (1.0, getMillisecondsSinceButtonDown() / 4000.0);
  34633. timeHeldDown *= timeHeldDown;
  34634. repeatSpeed = repeatSpeed + (int) (timeHeldDown * (autoRepeatMinimumDelay - repeatSpeed));
  34635. }
  34636. repeatSpeed = jmax (1, repeatSpeed);
  34637. getRepeatTimer().startTimer (repeatSpeed);
  34638. const uint32 now = Time::getApproximateMillisecondCounter();
  34639. const int numTimesToCallback = (now > lastTimeCallbackTime) ? jmax (1, (int) (now - lastTimeCallbackTime) / repeatSpeed) : 1;
  34640. lastTimeCallbackTime = now;
  34641. const ComponentDeletionWatcher cdw (this);
  34642. for (int i = numTimesToCallback; --i >= 0;)
  34643. {
  34644. internalClickCallback (ModifierKeys::getCurrentModifiers());
  34645. if (cdw.hasBeenDeleted() || ! isDown())
  34646. return;
  34647. }
  34648. }
  34649. else if (! needsToRelease)
  34650. {
  34651. getRepeatTimer().stopTimer();
  34652. }
  34653. }
  34654. class InternalButtonRepeatTimer : public Timer
  34655. {
  34656. public:
  34657. InternalButtonRepeatTimer (Button& owner_) throw()
  34658. : owner (owner_)
  34659. {
  34660. }
  34661. ~InternalButtonRepeatTimer()
  34662. {
  34663. }
  34664. void timerCallback()
  34665. {
  34666. owner.repeatTimerCallback();
  34667. }
  34668. private:
  34669. Button& owner;
  34670. InternalButtonRepeatTimer (const InternalButtonRepeatTimer&);
  34671. const InternalButtonRepeatTimer& operator= (const InternalButtonRepeatTimer&);
  34672. };
  34673. Timer& Button::getRepeatTimer() throw()
  34674. {
  34675. if (repeatTimer == 0)
  34676. repeatTimer = new InternalButtonRepeatTimer (*this);
  34677. return *repeatTimer;
  34678. }
  34679. END_JUCE_NAMESPACE
  34680. /********* End of inlined file: juce_Button.cpp *********/
  34681. /********* Start of inlined file: juce_DrawableButton.cpp *********/
  34682. BEGIN_JUCE_NAMESPACE
  34683. DrawableButton::DrawableButton (const String& name,
  34684. const DrawableButton::ButtonStyle buttonStyle)
  34685. : Button (name),
  34686. style (buttonStyle),
  34687. edgeIndent (3)
  34688. {
  34689. if (buttonStyle == ImageOnButtonBackground)
  34690. {
  34691. backgroundOff = Colour (0xffbbbbff);
  34692. backgroundOn = Colour (0xff3333ff);
  34693. }
  34694. else
  34695. {
  34696. backgroundOff = Colours::transparentBlack;
  34697. backgroundOn = Colour (0xaabbbbff);
  34698. }
  34699. }
  34700. DrawableButton::~DrawableButton()
  34701. {
  34702. deleteImages();
  34703. }
  34704. void DrawableButton::deleteImages()
  34705. {
  34706. }
  34707. void DrawableButton::setImages (const Drawable* normal,
  34708. const Drawable* over,
  34709. const Drawable* down,
  34710. const Drawable* disabled,
  34711. const Drawable* normalOn,
  34712. const Drawable* overOn,
  34713. const Drawable* downOn,
  34714. const Drawable* disabledOn)
  34715. {
  34716. deleteImages();
  34717. jassert (normal != 0); // you really need to give it at least a normal image..
  34718. if (normal != 0)
  34719. normalImage = normal->createCopy();
  34720. if (over != 0)
  34721. overImage = over->createCopy();
  34722. if (down != 0)
  34723. downImage = down->createCopy();
  34724. if (disabled != 0)
  34725. disabledImage = disabled->createCopy();
  34726. if (normalOn != 0)
  34727. normalImageOn = normalOn->createCopy();
  34728. if (overOn != 0)
  34729. overImageOn = overOn->createCopy();
  34730. if (downOn != 0)
  34731. downImageOn = downOn->createCopy();
  34732. if (disabledOn != 0)
  34733. disabledImageOn = disabledOn->createCopy();
  34734. repaint();
  34735. }
  34736. void DrawableButton::setButtonStyle (const DrawableButton::ButtonStyle newStyle)
  34737. {
  34738. if (style != newStyle)
  34739. {
  34740. style = newStyle;
  34741. repaint();
  34742. }
  34743. }
  34744. void DrawableButton::setBackgroundColours (const Colour& toggledOffColour,
  34745. const Colour& toggledOnColour)
  34746. {
  34747. if (backgroundOff != toggledOffColour
  34748. || backgroundOn != toggledOnColour)
  34749. {
  34750. backgroundOff = toggledOffColour;
  34751. backgroundOn = toggledOnColour;
  34752. repaint();
  34753. }
  34754. }
  34755. const Colour& DrawableButton::getBackgroundColour() const throw()
  34756. {
  34757. return getToggleState() ? backgroundOn
  34758. : backgroundOff;
  34759. }
  34760. void DrawableButton::setEdgeIndent (const int numPixelsIndent)
  34761. {
  34762. edgeIndent = numPixelsIndent;
  34763. repaint();
  34764. }
  34765. void DrawableButton::paintButton (Graphics& g,
  34766. bool isMouseOverButton,
  34767. bool isButtonDown)
  34768. {
  34769. Rectangle imageSpace;
  34770. if (style == ImageOnButtonBackground)
  34771. {
  34772. const int insetX = getWidth() / 4;
  34773. const int insetY = getHeight() / 4;
  34774. imageSpace.setBounds (insetX, insetY, getWidth() - insetX * 2, getHeight() - insetY * 2);
  34775. getLookAndFeel().drawButtonBackground (g, *this,
  34776. getBackgroundColour(),
  34777. isMouseOverButton,
  34778. isButtonDown);
  34779. }
  34780. else
  34781. {
  34782. g.fillAll (getBackgroundColour());
  34783. const int textH = (style == ImageAboveTextLabel)
  34784. ? jmin (16, proportionOfHeight (0.25f))
  34785. : 0;
  34786. const int indentX = jmin (edgeIndent, proportionOfWidth (0.3f));
  34787. const int indentY = jmin (edgeIndent, proportionOfHeight (0.3f));
  34788. imageSpace.setBounds (indentX, indentY,
  34789. getWidth() - indentX * 2,
  34790. getHeight() - indentY * 2 - textH);
  34791. if (textH > 0)
  34792. {
  34793. g.setFont ((float) textH);
  34794. g.setColour (Colours::black.withAlpha (isEnabled() ? 1.0f : 0.4f));
  34795. g.drawFittedText (getButtonText(),
  34796. 2, getHeight() - textH - 1,
  34797. getWidth() - 4, textH,
  34798. Justification::centred, 1);
  34799. }
  34800. }
  34801. g.setImageResamplingQuality (Graphics::mediumResamplingQuality);
  34802. g.setOpacity (1.0f);
  34803. const Drawable* imageToDraw = 0;
  34804. if (isEnabled())
  34805. {
  34806. imageToDraw = getCurrentImage();
  34807. }
  34808. else
  34809. {
  34810. imageToDraw = getToggleState() ? disabledImageOn
  34811. : disabledImage;
  34812. if (imageToDraw == 0)
  34813. {
  34814. g.setOpacity (0.4f);
  34815. imageToDraw = getNormalImage();
  34816. }
  34817. }
  34818. if (imageToDraw != 0)
  34819. {
  34820. if (style == ImageRaw)
  34821. {
  34822. imageToDraw->draw (g, 1.0f);
  34823. }
  34824. else
  34825. {
  34826. imageToDraw->drawWithin (g,
  34827. imageSpace.getX(),
  34828. imageSpace.getY(),
  34829. imageSpace.getWidth(),
  34830. imageSpace.getHeight(),
  34831. RectanglePlacement::centred,
  34832. 1.0f);
  34833. }
  34834. }
  34835. }
  34836. const Drawable* DrawableButton::getCurrentImage() const throw()
  34837. {
  34838. if (isDown())
  34839. return getDownImage();
  34840. if (isOver())
  34841. return getOverImage();
  34842. return getNormalImage();
  34843. }
  34844. const Drawable* DrawableButton::getNormalImage() const throw()
  34845. {
  34846. return (getToggleState() && normalImageOn != 0) ? normalImageOn
  34847. : normalImage;
  34848. }
  34849. const Drawable* DrawableButton::getOverImage() const throw()
  34850. {
  34851. const Drawable* d = normalImage;
  34852. if (getToggleState())
  34853. {
  34854. if (overImageOn != 0)
  34855. d = overImageOn;
  34856. else if (normalImageOn != 0)
  34857. d = normalImageOn;
  34858. else if (overImage != 0)
  34859. d = overImage;
  34860. }
  34861. else
  34862. {
  34863. if (overImage != 0)
  34864. d = overImage;
  34865. }
  34866. return d;
  34867. }
  34868. const Drawable* DrawableButton::getDownImage() const throw()
  34869. {
  34870. const Drawable* d = normalImage;
  34871. if (getToggleState())
  34872. {
  34873. if (downImageOn != 0)
  34874. d = downImageOn;
  34875. else if (overImageOn != 0)
  34876. d = overImageOn;
  34877. else if (normalImageOn != 0)
  34878. d = normalImageOn;
  34879. else if (downImage != 0)
  34880. d = downImage;
  34881. else
  34882. d = getOverImage();
  34883. }
  34884. else
  34885. {
  34886. if (downImage != 0)
  34887. d = downImage;
  34888. else
  34889. d = getOverImage();
  34890. }
  34891. return d;
  34892. }
  34893. END_JUCE_NAMESPACE
  34894. /********* End of inlined file: juce_DrawableButton.cpp *********/
  34895. /********* Start of inlined file: juce_HyperlinkButton.cpp *********/
  34896. BEGIN_JUCE_NAMESPACE
  34897. HyperlinkButton::HyperlinkButton (const String& linkText,
  34898. const URL& linkURL)
  34899. : Button (linkText),
  34900. url (linkURL),
  34901. font (14.0f, Font::underlined),
  34902. resizeFont (true),
  34903. justification (Justification::centred)
  34904. {
  34905. setMouseCursor (MouseCursor::PointingHandCursor);
  34906. setTooltip (linkURL.toString (false));
  34907. }
  34908. HyperlinkButton::~HyperlinkButton()
  34909. {
  34910. }
  34911. void HyperlinkButton::setFont (const Font& newFont,
  34912. const bool resizeToMatchComponentHeight,
  34913. const Justification& justificationType)
  34914. {
  34915. font = newFont;
  34916. resizeFont = resizeToMatchComponentHeight;
  34917. justification = justificationType;
  34918. repaint();
  34919. }
  34920. void HyperlinkButton::setURL (const URL& newURL) throw()
  34921. {
  34922. url = newURL;
  34923. setTooltip (newURL.toString (false));
  34924. }
  34925. const Font HyperlinkButton::getFontToUse() const
  34926. {
  34927. Font f (font);
  34928. if (resizeFont)
  34929. f.setHeight (getHeight() * 0.7f);
  34930. return f;
  34931. }
  34932. void HyperlinkButton::changeWidthToFitText()
  34933. {
  34934. setSize (getFontToUse().getStringWidth (getName()) + 6, getHeight());
  34935. }
  34936. void HyperlinkButton::colourChanged()
  34937. {
  34938. repaint();
  34939. }
  34940. void HyperlinkButton::clicked()
  34941. {
  34942. if (url.isWellFormed())
  34943. url.launchInDefaultBrowser();
  34944. }
  34945. void HyperlinkButton::paintButton (Graphics& g,
  34946. bool isMouseOverButton,
  34947. bool isButtonDown)
  34948. {
  34949. const Colour textColour (findColour (textColourId));
  34950. if (isEnabled())
  34951. g.setColour ((isMouseOverButton) ? textColour.darker ((isButtonDown) ? 1.3f : 0.4f)
  34952. : textColour);
  34953. else
  34954. g.setColour (textColour.withMultipliedAlpha (0.4f));
  34955. g.setFont (getFontToUse());
  34956. g.drawText (getButtonText(),
  34957. 2, 0, getWidth() - 2, getHeight(),
  34958. justification.getOnlyHorizontalFlags() | Justification::verticallyCentred,
  34959. true);
  34960. }
  34961. END_JUCE_NAMESPACE
  34962. /********* End of inlined file: juce_HyperlinkButton.cpp *********/
  34963. /********* Start of inlined file: juce_ImageButton.cpp *********/
  34964. BEGIN_JUCE_NAMESPACE
  34965. ImageButton::ImageButton (const String& text_)
  34966. : Button (text_),
  34967. scaleImageToFit (true),
  34968. preserveProportions (true),
  34969. alphaThreshold (0),
  34970. imageX (0),
  34971. imageY (0),
  34972. imageW (0),
  34973. imageH (0),
  34974. normalImage (0),
  34975. overImage (0),
  34976. downImage (0)
  34977. {
  34978. }
  34979. ImageButton::~ImageButton()
  34980. {
  34981. deleteImages();
  34982. }
  34983. void ImageButton::deleteImages()
  34984. {
  34985. ImageCache::releaseOrDelete (normalImage);
  34986. ImageCache::releaseOrDelete (overImage);
  34987. ImageCache::releaseOrDelete (downImage);
  34988. }
  34989. void ImageButton::setImages (const bool resizeButtonNowToFitThisImage,
  34990. const bool rescaleImagesWhenButtonSizeChanges,
  34991. const bool preserveImageProportions,
  34992. Image* const normalImage_,
  34993. const float imageOpacityWhenNormal,
  34994. const Colour& overlayColourWhenNormal,
  34995. Image* const overImage_,
  34996. const float imageOpacityWhenOver,
  34997. const Colour& overlayColourWhenOver,
  34998. Image* const downImage_,
  34999. const float imageOpacityWhenDown,
  35000. const Colour& overlayColourWhenDown,
  35001. const float hitTestAlphaThreshold)
  35002. {
  35003. deleteImages();
  35004. normalImage = normalImage_;
  35005. overImage = overImage_;
  35006. downImage = downImage_;
  35007. if (resizeButtonNowToFitThisImage && normalImage != 0)
  35008. {
  35009. imageW = normalImage->getWidth();
  35010. imageH = normalImage->getHeight();
  35011. setSize (imageW, imageH);
  35012. }
  35013. scaleImageToFit = rescaleImagesWhenButtonSizeChanges;
  35014. preserveProportions = preserveImageProportions;
  35015. normalOpacity = imageOpacityWhenNormal;
  35016. normalOverlay = overlayColourWhenNormal;
  35017. overOpacity = imageOpacityWhenOver;
  35018. overOverlay = overlayColourWhenOver;
  35019. downOpacity = imageOpacityWhenDown;
  35020. downOverlay = overlayColourWhenDown;
  35021. alphaThreshold = (unsigned char) jlimit (0, 0xff, roundToInt (255.0f * hitTestAlphaThreshold));
  35022. repaint();
  35023. }
  35024. Image* ImageButton::getCurrentImage() const
  35025. {
  35026. if (isDown() || getToggleState())
  35027. return getDownImage();
  35028. if (isOver())
  35029. return getOverImage();
  35030. return getNormalImage();
  35031. }
  35032. Image* ImageButton::getNormalImage() const throw()
  35033. {
  35034. return normalImage;
  35035. }
  35036. Image* ImageButton::getOverImage() const throw()
  35037. {
  35038. return (overImage != 0) ? overImage
  35039. : normalImage;
  35040. }
  35041. Image* ImageButton::getDownImage() const throw()
  35042. {
  35043. return (downImage != 0) ? downImage
  35044. : getOverImage();
  35045. }
  35046. void ImageButton::paintButton (Graphics& g,
  35047. bool isMouseOverButton,
  35048. bool isButtonDown)
  35049. {
  35050. if (! isEnabled())
  35051. {
  35052. isMouseOverButton = false;
  35053. isButtonDown = false;
  35054. }
  35055. Image* const im = getCurrentImage();
  35056. if (im != 0)
  35057. {
  35058. const int iw = im->getWidth();
  35059. const int ih = im->getHeight();
  35060. imageW = getWidth();
  35061. imageH = getHeight();
  35062. imageX = (imageW - iw) >> 1;
  35063. imageY = (imageH - ih) >> 1;
  35064. if (scaleImageToFit)
  35065. {
  35066. if (preserveProportions)
  35067. {
  35068. int newW, newH;
  35069. const float imRatio = ih / (float)iw;
  35070. const float destRatio = imageH / (float)imageW;
  35071. if (imRatio > destRatio)
  35072. {
  35073. newW = roundToInt (imageH / imRatio);
  35074. newH = imageH;
  35075. }
  35076. else
  35077. {
  35078. newW = imageW;
  35079. newH = roundToInt (imageW * imRatio);
  35080. }
  35081. imageX = (imageW - newW) / 2;
  35082. imageY = (imageH - newH) / 2;
  35083. imageW = newW;
  35084. imageH = newH;
  35085. }
  35086. else
  35087. {
  35088. imageX = 0;
  35089. imageY = 0;
  35090. }
  35091. }
  35092. if (! scaleImageToFit)
  35093. {
  35094. imageW = iw;
  35095. imageH = ih;
  35096. }
  35097. getLookAndFeel().drawImageButton (g, im, imageX, imageY, imageW, imageH,
  35098. isButtonDown ? downOverlay
  35099. : (isMouseOverButton ? overOverlay
  35100. : normalOverlay),
  35101. isButtonDown ? downOpacity
  35102. : (isMouseOverButton ? overOpacity
  35103. : normalOpacity),
  35104. *this);
  35105. }
  35106. }
  35107. bool ImageButton::hitTest (int x, int y)
  35108. {
  35109. if (alphaThreshold == 0)
  35110. return true;
  35111. Image* const im = getCurrentImage();
  35112. return im == 0
  35113. || (imageW > 0 && imageH > 0
  35114. && alphaThreshold < im->getPixelAt (((x - imageX) * im->getWidth()) / imageW,
  35115. ((y - imageY) * im->getHeight()) / imageH).getAlpha());
  35116. }
  35117. END_JUCE_NAMESPACE
  35118. /********* End of inlined file: juce_ImageButton.cpp *********/
  35119. /********* Start of inlined file: juce_ShapeButton.cpp *********/
  35120. BEGIN_JUCE_NAMESPACE
  35121. ShapeButton::ShapeButton (const String& text_,
  35122. const Colour& normalColour_,
  35123. const Colour& overColour_,
  35124. const Colour& downColour_)
  35125. : Button (text_),
  35126. normalColour (normalColour_),
  35127. overColour (overColour_),
  35128. downColour (downColour_),
  35129. maintainShapeProportions (false),
  35130. outlineWidth (0.0f)
  35131. {
  35132. }
  35133. ShapeButton::~ShapeButton()
  35134. {
  35135. }
  35136. void ShapeButton::setColours (const Colour& newNormalColour,
  35137. const Colour& newOverColour,
  35138. const Colour& newDownColour)
  35139. {
  35140. normalColour = newNormalColour;
  35141. overColour = newOverColour;
  35142. downColour = newDownColour;
  35143. }
  35144. void ShapeButton::setOutline (const Colour& newOutlineColour,
  35145. const float newOutlineWidth)
  35146. {
  35147. outlineColour = newOutlineColour;
  35148. outlineWidth = newOutlineWidth;
  35149. }
  35150. void ShapeButton::setShape (const Path& newShape,
  35151. const bool resizeNowToFitThisShape,
  35152. const bool maintainShapeProportions_,
  35153. const bool hasShadow)
  35154. {
  35155. shape = newShape;
  35156. maintainShapeProportions = maintainShapeProportions_;
  35157. shadow.setShadowProperties (3.0f, 0.5f, 0, 0);
  35158. setComponentEffect ((hasShadow) ? &shadow : 0);
  35159. if (resizeNowToFitThisShape)
  35160. {
  35161. float x, y, w, h;
  35162. shape.getBounds (x, y, w, h);
  35163. shape.applyTransform (AffineTransform::translation (-x, -y));
  35164. if (hasShadow)
  35165. {
  35166. w += 4.0f;
  35167. h += 4.0f;
  35168. shape.applyTransform (AffineTransform::translation (2.0f, 2.0f));
  35169. }
  35170. setSize (1 + (int) (w + outlineWidth),
  35171. 1 + (int) (h + outlineWidth));
  35172. }
  35173. }
  35174. void ShapeButton::paintButton (Graphics& g, bool isMouseOverButton, bool isButtonDown)
  35175. {
  35176. if (! isEnabled())
  35177. {
  35178. isMouseOverButton = false;
  35179. isButtonDown = false;
  35180. }
  35181. g.setColour ((isButtonDown) ? downColour
  35182. : (isMouseOverButton) ? overColour
  35183. : normalColour);
  35184. int w = getWidth();
  35185. int h = getHeight();
  35186. if (getComponentEffect() != 0)
  35187. {
  35188. w -= 4;
  35189. h -= 4;
  35190. }
  35191. const float offset = (outlineWidth * 0.5f) + (isButtonDown ? 1.5f : 0.0f);
  35192. const AffineTransform trans (shape.getTransformToScaleToFit (offset, offset,
  35193. w - offset - outlineWidth,
  35194. h - offset - outlineWidth,
  35195. maintainShapeProportions));
  35196. g.fillPath (shape, trans);
  35197. if (outlineWidth > 0.0f)
  35198. {
  35199. g.setColour (outlineColour);
  35200. g.strokePath (shape, PathStrokeType (outlineWidth), trans);
  35201. }
  35202. }
  35203. END_JUCE_NAMESPACE
  35204. /********* End of inlined file: juce_ShapeButton.cpp *********/
  35205. /********* Start of inlined file: juce_TextButton.cpp *********/
  35206. BEGIN_JUCE_NAMESPACE
  35207. TextButton::TextButton (const String& name,
  35208. const String& toolTip)
  35209. : Button (name)
  35210. {
  35211. setTooltip (toolTip);
  35212. }
  35213. TextButton::~TextButton()
  35214. {
  35215. }
  35216. void TextButton::paintButton (Graphics& g,
  35217. bool isMouseOverButton,
  35218. bool isButtonDown)
  35219. {
  35220. getLookAndFeel().drawButtonBackground (g, *this,
  35221. findColour (getToggleState() ? buttonOnColourId
  35222. : buttonColourId),
  35223. isMouseOverButton,
  35224. isButtonDown);
  35225. getLookAndFeel().drawButtonText (g, *this,
  35226. isMouseOverButton,
  35227. isButtonDown);
  35228. }
  35229. void TextButton::colourChanged()
  35230. {
  35231. repaint();
  35232. }
  35233. const Font TextButton::getFont()
  35234. {
  35235. return Font (jmin (15.0f, getHeight() * 0.6f));
  35236. }
  35237. void TextButton::changeWidthToFitText (const int newHeight)
  35238. {
  35239. if (newHeight >= 0)
  35240. setSize (jmax (1, getWidth()), newHeight);
  35241. setSize (getFont().getStringWidth (getButtonText()) + getHeight(),
  35242. getHeight());
  35243. }
  35244. END_JUCE_NAMESPACE
  35245. /********* End of inlined file: juce_TextButton.cpp *********/
  35246. /********* Start of inlined file: juce_ToggleButton.cpp *********/
  35247. BEGIN_JUCE_NAMESPACE
  35248. ToggleButton::ToggleButton (const String& buttonText)
  35249. : Button (buttonText)
  35250. {
  35251. setClickingTogglesState (true);
  35252. }
  35253. ToggleButton::~ToggleButton()
  35254. {
  35255. }
  35256. void ToggleButton::paintButton (Graphics& g,
  35257. bool isMouseOverButton,
  35258. bool isButtonDown)
  35259. {
  35260. getLookAndFeel().drawToggleButton (g, *this,
  35261. isMouseOverButton,
  35262. isButtonDown);
  35263. }
  35264. void ToggleButton::changeWidthToFitText()
  35265. {
  35266. getLookAndFeel().changeToggleButtonWidthToFitText (*this);
  35267. }
  35268. void ToggleButton::colourChanged()
  35269. {
  35270. repaint();
  35271. }
  35272. END_JUCE_NAMESPACE
  35273. /********* End of inlined file: juce_ToggleButton.cpp *********/
  35274. /********* Start of inlined file: juce_ToolbarButton.cpp *********/
  35275. BEGIN_JUCE_NAMESPACE
  35276. ToolbarButton::ToolbarButton (const int itemId_,
  35277. const String& buttonText,
  35278. Drawable* const normalImage_,
  35279. Drawable* const toggledOnImage_)
  35280. : ToolbarItemComponent (itemId_, buttonText, true),
  35281. normalImage (normalImage_),
  35282. toggledOnImage (toggledOnImage_)
  35283. {
  35284. }
  35285. ToolbarButton::~ToolbarButton()
  35286. {
  35287. }
  35288. bool ToolbarButton::getToolbarItemSizes (int toolbarDepth,
  35289. bool /*isToolbarVertical*/,
  35290. int& preferredSize,
  35291. int& minSize, int& maxSize)
  35292. {
  35293. preferredSize = minSize = maxSize = toolbarDepth;
  35294. return true;
  35295. }
  35296. void ToolbarButton::paintButtonArea (Graphics& g,
  35297. int width, int height,
  35298. bool /*isMouseOver*/,
  35299. bool /*isMouseDown*/)
  35300. {
  35301. Drawable* d = normalImage;
  35302. if (getToggleState() && toggledOnImage != 0)
  35303. d = toggledOnImage;
  35304. if (! isEnabled())
  35305. {
  35306. Image im (Image::ARGB, width, height, true);
  35307. Graphics g2 (im);
  35308. d->drawWithin (g2, 0, 0, width, height, RectanglePlacement::centred, 1.0f);
  35309. im.desaturate();
  35310. g.drawImageAt (&im, 0, 0);
  35311. }
  35312. else
  35313. {
  35314. d->drawWithin (g, 0, 0, width, height, RectanglePlacement::centred, 1.0f);
  35315. }
  35316. }
  35317. void ToolbarButton::contentAreaChanged (const Rectangle&)
  35318. {
  35319. }
  35320. END_JUCE_NAMESPACE
  35321. /********* End of inlined file: juce_ToolbarButton.cpp *********/
  35322. /********* Start of inlined file: juce_CodeDocument.cpp *********/
  35323. BEGIN_JUCE_NAMESPACE
  35324. class CodeDocumentLine
  35325. {
  35326. public:
  35327. CodeDocumentLine (const String& line_,
  35328. const int lineLength_,
  35329. const int lineStartInFile_) throw()
  35330. : line (line_),
  35331. lineStartInFile (lineStartInFile_),
  35332. lineLength (lineLength_)
  35333. {
  35334. lineLengthWithoutNewLines = lineLength;
  35335. while (lineLengthWithoutNewLines > 0
  35336. && (line [lineLengthWithoutNewLines - 1] == '\n'
  35337. || line [lineLengthWithoutNewLines - 1] == '\r'))
  35338. {
  35339. --lineLengthWithoutNewLines;
  35340. }
  35341. }
  35342. ~CodeDocumentLine() throw()
  35343. {
  35344. }
  35345. static void createLines (Array <CodeDocumentLine*>& newLines, const String& text) throw()
  35346. {
  35347. const tchar* const t = (const tchar*) text;
  35348. int pos = 0;
  35349. while (t [pos] != 0)
  35350. {
  35351. const int startOfLine = pos;
  35352. while (t[pos] != 0)
  35353. {
  35354. if (t[pos] == T('\r'))
  35355. {
  35356. ++pos;
  35357. if (t[pos] == T('\n'))
  35358. ++pos;
  35359. break;
  35360. }
  35361. if (t[pos] == T('\n'))
  35362. {
  35363. ++pos;
  35364. break;
  35365. }
  35366. ++pos;
  35367. }
  35368. newLines.add (new CodeDocumentLine (String (t + startOfLine, pos - startOfLine),
  35369. pos - startOfLine,
  35370. startOfLine));
  35371. }
  35372. jassert (pos == text.length());
  35373. }
  35374. bool endsWithLineBreak() const throw()
  35375. {
  35376. return lineLengthWithoutNewLines != lineLength;
  35377. }
  35378. void updateLength() throw()
  35379. {
  35380. lineLengthWithoutNewLines = lineLength = line.length();
  35381. while (lineLengthWithoutNewLines > 0
  35382. && (line [lineLengthWithoutNewLines - 1] == '\n'
  35383. || line [lineLengthWithoutNewLines - 1] == '\r'))
  35384. {
  35385. --lineLengthWithoutNewLines;
  35386. }
  35387. }
  35388. String line;
  35389. int lineStartInFile, lineLength, lineLengthWithoutNewLines;
  35390. };
  35391. CodeDocument::Iterator::Iterator (CodeDocument* const document_) throw()
  35392. : document (document_),
  35393. line (0),
  35394. position (0)
  35395. {
  35396. }
  35397. CodeDocument::Iterator::Iterator (const CodeDocument::Iterator& other)
  35398. : document (other.document),
  35399. line (other.line),
  35400. position (other.position)
  35401. {
  35402. }
  35403. const CodeDocument::Iterator& CodeDocument::Iterator::operator= (const CodeDocument::Iterator& other) throw()
  35404. {
  35405. document = other.document;
  35406. line = other.line;
  35407. position = other.position;
  35408. return *this;
  35409. }
  35410. CodeDocument::Iterator::~Iterator() throw()
  35411. {
  35412. }
  35413. juce_wchar CodeDocument::Iterator::nextChar() throw()
  35414. {
  35415. if (line >= document->lines.size())
  35416. return 0;
  35417. const CodeDocumentLine* const currentLine = document->lines.getUnchecked (line);
  35418. const juce_wchar result = currentLine->line [position - currentLine->lineStartInFile];
  35419. if (++position >= currentLine->lineStartInFile + currentLine->lineLength)
  35420. ++line;
  35421. return result;
  35422. }
  35423. void CodeDocument::Iterator::skip() throw()
  35424. {
  35425. if (line < document->lines.size())
  35426. {
  35427. const CodeDocumentLine* const currentLine = document->lines.getUnchecked (line);
  35428. if (++position >= currentLine->lineStartInFile + currentLine->lineLength)
  35429. ++line;
  35430. }
  35431. }
  35432. juce_wchar CodeDocument::Iterator::peekNextChar() const throw()
  35433. {
  35434. if (line >= document->lines.size())
  35435. return 0;
  35436. const CodeDocumentLine* const currentLine = document->lines.getUnchecked (line);
  35437. return currentLine->line [position - currentLine->lineStartInFile];
  35438. }
  35439. void CodeDocument::Iterator::skipWhitespace()
  35440. {
  35441. while (line < document->lines.size())
  35442. {
  35443. const CodeDocumentLine* const currentLine = document->lines.getUnchecked (line);
  35444. for (;;)
  35445. {
  35446. if (! CharacterFunctions::isWhitespace (currentLine->line [position - currentLine->lineStartInFile]))
  35447. return;
  35448. if (++position >= currentLine->lineStartInFile + currentLine->lineLength)
  35449. {
  35450. ++line;
  35451. break;
  35452. }
  35453. }
  35454. }
  35455. }
  35456. void CodeDocument::Iterator::skipToEndOfLine()
  35457. {
  35458. if (line < document->lines.size())
  35459. {
  35460. const CodeDocumentLine* const currentLine = document->lines.getUnchecked (line);
  35461. position = currentLine->lineStartInFile + currentLine->lineLength;
  35462. ++line;
  35463. }
  35464. }
  35465. bool CodeDocument::Iterator::isEOF() const throw()
  35466. {
  35467. return position >= document->getNumCharacters();
  35468. }
  35469. CodeDocument::Position::Position() throw()
  35470. : owner (0), characterPos (0), line (0),
  35471. indexInLine (0), positionMaintained (false)
  35472. {
  35473. }
  35474. CodeDocument::Position::Position (const CodeDocument* const ownerDocument,
  35475. const int line_, const int indexInLine_) throw()
  35476. : owner (const_cast <CodeDocument*> (ownerDocument)),
  35477. characterPos (0), line (line_),
  35478. indexInLine (indexInLine_), positionMaintained (false)
  35479. {
  35480. setLineAndIndex (line_, indexInLine_);
  35481. }
  35482. CodeDocument::Position::Position (const CodeDocument* const ownerDocument,
  35483. const int characterPos_) throw()
  35484. : owner (const_cast <CodeDocument*> (ownerDocument)),
  35485. positionMaintained (false)
  35486. {
  35487. setPosition (characterPos_);
  35488. }
  35489. CodeDocument::Position::Position (const Position& other) throw()
  35490. : owner (other.owner), characterPos (other.characterPos), line (other.line),
  35491. indexInLine (other.indexInLine), positionMaintained (false)
  35492. {
  35493. jassert (*this == other);
  35494. }
  35495. CodeDocument::Position::~Position() throw()
  35496. {
  35497. setPositionMaintained (false);
  35498. }
  35499. const CodeDocument::Position& CodeDocument::Position::operator= (const Position& other) throw()
  35500. {
  35501. if (this != &other)
  35502. {
  35503. const bool wasPositionMaintained = positionMaintained;
  35504. if (owner != other.owner)
  35505. setPositionMaintained (false);
  35506. owner = other.owner;
  35507. line = other.line;
  35508. indexInLine = other.indexInLine;
  35509. characterPos = other.characterPos;
  35510. setPositionMaintained (wasPositionMaintained);
  35511. jassert (*this == other);
  35512. }
  35513. return *this;
  35514. }
  35515. bool CodeDocument::Position::operator== (const Position& other) const throw()
  35516. {
  35517. jassert ((characterPos == other.characterPos)
  35518. == (line == other.line && indexInLine == other.indexInLine));
  35519. return characterPos == other.characterPos
  35520. && line == other.line
  35521. && indexInLine == other.indexInLine
  35522. && owner == other.owner;
  35523. }
  35524. bool CodeDocument::Position::operator!= (const Position& other) const throw()
  35525. {
  35526. return ! operator== (other);
  35527. }
  35528. void CodeDocument::Position::setLineAndIndex (const int newLine, const int newIndexInLine) throw()
  35529. {
  35530. jassert (owner != 0);
  35531. if (owner->lines.size() == 0)
  35532. {
  35533. line = 0;
  35534. indexInLine = 0;
  35535. characterPos = 0;
  35536. }
  35537. else
  35538. {
  35539. if (newLine >= owner->lines.size())
  35540. {
  35541. line = owner->lines.size() - 1;
  35542. CodeDocumentLine* const l = owner->lines.getUnchecked (line);
  35543. jassert (l != 0);
  35544. indexInLine = l->lineLengthWithoutNewLines;
  35545. characterPos = l->lineStartInFile + indexInLine;
  35546. }
  35547. else
  35548. {
  35549. line = jmax (0, newLine);
  35550. CodeDocumentLine* const l = owner->lines.getUnchecked (line);
  35551. jassert (l != 0);
  35552. if (l->lineLengthWithoutNewLines > 0)
  35553. indexInLine = jlimit (0, l->lineLengthWithoutNewLines, newIndexInLine);
  35554. else
  35555. indexInLine = 0;
  35556. characterPos = l->lineStartInFile + indexInLine;
  35557. }
  35558. }
  35559. }
  35560. void CodeDocument::Position::setPosition (const int newPosition) throw()
  35561. {
  35562. jassert (owner != 0);
  35563. line = 0;
  35564. indexInLine = 0;
  35565. characterPos = 0;
  35566. if (newPosition > 0)
  35567. {
  35568. int lineStart = 0;
  35569. int lineEnd = owner->lines.size();
  35570. for (;;)
  35571. {
  35572. if (lineEnd - lineStart < 4)
  35573. {
  35574. for (int i = lineStart; i < lineEnd; ++i)
  35575. {
  35576. CodeDocumentLine* const l = owner->lines.getUnchecked (i);
  35577. int index = newPosition - l->lineStartInFile;
  35578. if (index >= 0 && (index < l->lineLength || i == lineEnd - 1))
  35579. {
  35580. line = i;
  35581. indexInLine = jmin (l->lineLengthWithoutNewLines, index);
  35582. characterPos = l->lineStartInFile + indexInLine;
  35583. }
  35584. }
  35585. break;
  35586. }
  35587. else
  35588. {
  35589. const int midIndex = (lineStart + lineEnd + 1) / 2;
  35590. CodeDocumentLine* const mid = owner->lines.getUnchecked (midIndex);
  35591. if (newPosition >= mid->lineStartInFile)
  35592. lineStart = midIndex;
  35593. else
  35594. lineEnd = midIndex;
  35595. }
  35596. }
  35597. }
  35598. }
  35599. void CodeDocument::Position::moveBy (int characterDelta) throw()
  35600. {
  35601. jassert (owner != 0);
  35602. if (characterDelta == 1)
  35603. {
  35604. setPosition (getPosition());
  35605. // If moving right, make sure we don't get stuck between the \r and \n characters..
  35606. CodeDocumentLine* const l = owner->lines.getUnchecked (line);
  35607. if (indexInLine + characterDelta < l->lineLength
  35608. && indexInLine + characterDelta >= l->lineLengthWithoutNewLines + 1)
  35609. ++characterDelta;
  35610. }
  35611. setPosition (characterPos + characterDelta);
  35612. }
  35613. const CodeDocument::Position CodeDocument::Position::movedBy (const int characterDelta) const throw()
  35614. {
  35615. CodeDocument::Position p (*this);
  35616. p.moveBy (characterDelta);
  35617. return p;
  35618. }
  35619. const CodeDocument::Position CodeDocument::Position::movedByLines (const int deltaLines) const throw()
  35620. {
  35621. CodeDocument::Position p (*this);
  35622. p.setLineAndIndex (getLineNumber() + deltaLines, getIndexInLine());
  35623. return p;
  35624. }
  35625. const tchar CodeDocument::Position::getCharacter() const throw()
  35626. {
  35627. const CodeDocumentLine* const l = owner->lines [line];
  35628. return l == 0 ? 0 : l->line [getIndexInLine()];
  35629. }
  35630. const String CodeDocument::Position::getLineText() const throw()
  35631. {
  35632. const CodeDocumentLine* const l = owner->lines [line];
  35633. return l == 0 ? String::empty : l->line;
  35634. }
  35635. void CodeDocument::Position::setPositionMaintained (const bool isMaintained) throw()
  35636. {
  35637. if (isMaintained != positionMaintained)
  35638. {
  35639. positionMaintained = isMaintained;
  35640. if (owner != 0)
  35641. {
  35642. if (isMaintained)
  35643. {
  35644. jassert (! owner->positionsToMaintain.contains (this));
  35645. owner->positionsToMaintain.add (this);
  35646. }
  35647. else
  35648. {
  35649. jassert (owner->positionsToMaintain.contains (this));
  35650. owner->positionsToMaintain.removeValue (this);
  35651. }
  35652. }
  35653. }
  35654. }
  35655. CodeDocument::CodeDocument()
  35656. : undoManager (INT_MAX, 10000),
  35657. currentActionIndex (0),
  35658. indexOfSavedState (-1),
  35659. maximumLineLength (-1),
  35660. newLineChars ("\r\n")
  35661. {
  35662. }
  35663. CodeDocument::~CodeDocument()
  35664. {
  35665. }
  35666. const String CodeDocument::getAllContent() const throw()
  35667. {
  35668. return getTextBetween (Position (this, 0),
  35669. Position (this, lines.size(), 0));
  35670. }
  35671. const String CodeDocument::getTextBetween (const Position& start, const Position& end) const throw()
  35672. {
  35673. if (end.getPosition() <= start.getPosition())
  35674. return String::empty;
  35675. const int startLine = start.getLineNumber();
  35676. const int endLine = end.getLineNumber();
  35677. if (startLine == endLine)
  35678. {
  35679. CodeDocumentLine* const line = lines [startLine];
  35680. return (line == 0) ? String::empty : line->line.substring (start.getIndexInLine(), end.getIndexInLine());
  35681. }
  35682. String result;
  35683. result.preallocateStorage (end.getPosition() - start.getPosition() + 4);
  35684. String::Concatenator concatenator (result);
  35685. const int maxLine = jmin (lines.size() - 1, endLine);
  35686. for (int i = jmax (0, startLine); i <= maxLine; ++i)
  35687. {
  35688. const CodeDocumentLine* line = lines.getUnchecked(i);
  35689. int len = line->lineLength;
  35690. if (i == startLine)
  35691. {
  35692. const int index = start.getIndexInLine();
  35693. concatenator.append (line->line.substring (index, len));
  35694. }
  35695. else if (i == endLine)
  35696. {
  35697. len = end.getIndexInLine();
  35698. concatenator.append (line->line.substring (0, len));
  35699. }
  35700. else
  35701. {
  35702. concatenator.append (line->line);
  35703. }
  35704. }
  35705. return result;
  35706. }
  35707. int CodeDocument::getNumCharacters() const throw()
  35708. {
  35709. const CodeDocumentLine* const lastLine = lines.getLast();
  35710. return (lastLine == 0) ? 0 : lastLine->lineStartInFile + lastLine->lineLength;
  35711. }
  35712. const String CodeDocument::getLine (const int lineIndex) const throw()
  35713. {
  35714. const CodeDocumentLine* const line = lines [lineIndex];
  35715. return (line == 0) ? String::empty : line->line;
  35716. }
  35717. int CodeDocument::getMaximumLineLength() throw()
  35718. {
  35719. if (maximumLineLength < 0)
  35720. {
  35721. maximumLineLength = 0;
  35722. for (int i = lines.size(); --i >= 0;)
  35723. maximumLineLength = jmax (maximumLineLength, lines.getUnchecked(i)->lineLength);
  35724. }
  35725. return maximumLineLength;
  35726. }
  35727. void CodeDocument::deleteSection (const Position& startPosition, const Position& endPosition)
  35728. {
  35729. remove (startPosition.getPosition(), endPosition.getPosition(), true);
  35730. }
  35731. void CodeDocument::insertText (const Position& position, const String& text)
  35732. {
  35733. insert (text, position.getPosition(), true);
  35734. }
  35735. void CodeDocument::replaceAllContent (const String& newContent)
  35736. {
  35737. remove (0, getNumCharacters(), true);
  35738. insert (newContent, 0, true);
  35739. }
  35740. void CodeDocument::setNewLineCharacters (const String& newLine) throw()
  35741. {
  35742. jassert (newLine == T("\r\n") || newLine == T("\n") || newLine == T("\r"));
  35743. newLineChars = newLine;
  35744. }
  35745. void CodeDocument::newTransaction()
  35746. {
  35747. undoManager.beginNewTransaction (String::empty);
  35748. }
  35749. void CodeDocument::undo()
  35750. {
  35751. newTransaction();
  35752. undoManager.undo();
  35753. }
  35754. void CodeDocument::redo()
  35755. {
  35756. undoManager.redo();
  35757. }
  35758. void CodeDocument::clearUndoHistory()
  35759. {
  35760. undoManager.clearUndoHistory();
  35761. }
  35762. void CodeDocument::setSavePoint() throw()
  35763. {
  35764. indexOfSavedState = currentActionIndex;
  35765. }
  35766. bool CodeDocument::hasChangedSinceSavePoint() const throw()
  35767. {
  35768. return currentActionIndex != indexOfSavedState;
  35769. }
  35770. static int getCodeCharacterCategory (const tchar character) throw()
  35771. {
  35772. return (CharacterFunctions::isLetterOrDigit (character) || character == '_')
  35773. ? 2 : (CharacterFunctions::isWhitespace (character) ? 0 : 1);
  35774. }
  35775. const CodeDocument::Position CodeDocument::findWordBreakAfter (const Position& position) const throw()
  35776. {
  35777. Position p (position);
  35778. const int maxDistance = 256;
  35779. int i = 0;
  35780. while (i < maxDistance
  35781. && CharacterFunctions::isWhitespace (p.getCharacter())
  35782. && (i == 0 || (p.getCharacter() != T('\n')
  35783. && p.getCharacter() != T('\r'))))
  35784. {
  35785. ++i;
  35786. p.moveBy (1);
  35787. }
  35788. if (i == 0)
  35789. {
  35790. const int type = getCodeCharacterCategory (p.getCharacter());
  35791. while (i < maxDistance && type == getCodeCharacterCategory (p.getCharacter()))
  35792. {
  35793. ++i;
  35794. p.moveBy (1);
  35795. }
  35796. while (i < maxDistance
  35797. && CharacterFunctions::isWhitespace (p.getCharacter())
  35798. && (i == 0 || (p.getCharacter() != T('\n')
  35799. && p.getCharacter() != T('\r'))))
  35800. {
  35801. ++i;
  35802. p.moveBy (1);
  35803. }
  35804. }
  35805. return p;
  35806. }
  35807. const CodeDocument::Position CodeDocument::findWordBreakBefore (const Position& position) const throw()
  35808. {
  35809. Position p (position);
  35810. const int maxDistance = 256;
  35811. int i = 0;
  35812. bool stoppedAtLineStart = false;
  35813. while (i < maxDistance)
  35814. {
  35815. const tchar c = p.movedBy (-1).getCharacter();
  35816. if (c == T('\r') || c == T('\n'))
  35817. {
  35818. stoppedAtLineStart = true;
  35819. if (i > 0)
  35820. break;
  35821. }
  35822. if (! CharacterFunctions::isWhitespace (c))
  35823. break;
  35824. p.moveBy (-1);
  35825. ++i;
  35826. }
  35827. if (i < maxDistance && ! stoppedAtLineStart)
  35828. {
  35829. const int type = getCodeCharacterCategory (p.movedBy (-1).getCharacter());
  35830. while (i < maxDistance && type == getCodeCharacterCategory (p.movedBy (-1).getCharacter()))
  35831. {
  35832. p.moveBy (-1);
  35833. ++i;
  35834. }
  35835. }
  35836. return p;
  35837. }
  35838. void CodeDocument::addListener (CodeDocument::Listener* const listener) throw()
  35839. {
  35840. listeners.addIfNotAlreadyThere (listener);
  35841. }
  35842. void CodeDocument::removeListener (CodeDocument::Listener* const listener) throw()
  35843. {
  35844. listeners.removeValue (listener);
  35845. }
  35846. void CodeDocument::sendListenerChangeMessage (const int startLine, const int endLine)
  35847. {
  35848. const Position startPos (this, startLine, 0);
  35849. const Position endPos (this, endLine, 0);
  35850. for (int i = listeners.size(); --i >= 0;)
  35851. {
  35852. Listener* const l = (Listener*) listeners[i];
  35853. if (l != 0)
  35854. l->codeDocumentChanged (startPos, endPos);
  35855. }
  35856. }
  35857. class CodeDocumentInsertAction : public UndoableAction
  35858. {
  35859. CodeDocument& owner;
  35860. const String text;
  35861. int insertPos;
  35862. CodeDocumentInsertAction (const CodeDocumentInsertAction&);
  35863. const CodeDocumentInsertAction& operator= (const CodeDocumentInsertAction&);
  35864. public:
  35865. CodeDocumentInsertAction (CodeDocument& owner_, const String& text_, const int insertPos_) throw()
  35866. : owner (owner_),
  35867. text (text_),
  35868. insertPos (insertPos_)
  35869. {
  35870. }
  35871. ~CodeDocumentInsertAction() {}
  35872. bool perform()
  35873. {
  35874. owner.currentActionIndex++;
  35875. owner.insert (text, insertPos, false);
  35876. return true;
  35877. }
  35878. bool undo()
  35879. {
  35880. owner.currentActionIndex--;
  35881. owner.remove (insertPos, insertPos + text.length(), false);
  35882. return true;
  35883. }
  35884. int getSizeInUnits() { return text.length() + 32; }
  35885. };
  35886. void CodeDocument::insert (const String& text, const int insertPos, const bool undoable)
  35887. {
  35888. if (text.isEmpty())
  35889. return;
  35890. if (undoable)
  35891. {
  35892. undoManager.perform (new CodeDocumentInsertAction (*this, text, insertPos));
  35893. }
  35894. else
  35895. {
  35896. Position pos (this, insertPos);
  35897. const int firstAffectedLine = pos.getLineNumber();
  35898. int lastAffectedLine = firstAffectedLine + 1;
  35899. CodeDocumentLine* const firstLine = lines [firstAffectedLine];
  35900. String textInsideOriginalLine (text);
  35901. if (firstLine != 0)
  35902. {
  35903. const int index = pos.getIndexInLine();
  35904. textInsideOriginalLine = firstLine->line.substring (0, index)
  35905. + textInsideOriginalLine
  35906. + firstLine->line.substring (index);
  35907. }
  35908. maximumLineLength = -1;
  35909. Array <CodeDocumentLine*> newLines;
  35910. CodeDocumentLine::createLines (newLines, textInsideOriginalLine);
  35911. jassert (newLines.size() > 0);
  35912. CodeDocumentLine* const newFirstLine = newLines.getUnchecked (0);
  35913. newFirstLine->lineStartInFile = firstLine != 0 ? firstLine->lineStartInFile : 0;
  35914. lines.set (firstAffectedLine, newFirstLine);
  35915. if (newLines.size() > 1)
  35916. {
  35917. for (int i = 1; i < newLines.size(); ++i)
  35918. {
  35919. CodeDocumentLine* const l = newLines.getUnchecked (i);
  35920. lines.insert (firstAffectedLine + i, l);
  35921. }
  35922. lastAffectedLine = lines.size();
  35923. }
  35924. int i, lineStart = newFirstLine->lineStartInFile;
  35925. for (i = firstAffectedLine; i < lines.size(); ++i)
  35926. {
  35927. CodeDocumentLine* const l = lines.getUnchecked (i);
  35928. l->lineStartInFile = lineStart;
  35929. lineStart += l->lineLength;
  35930. }
  35931. const int newTextLength = text.length();
  35932. for (i = 0; i < positionsToMaintain.size(); ++i)
  35933. {
  35934. CodeDocument::Position* const p = positionsToMaintain.getUnchecked(i);
  35935. if (p->getPosition() >= insertPos)
  35936. p->setPosition (p->getPosition() + newTextLength);
  35937. }
  35938. sendListenerChangeMessage (firstAffectedLine, lastAffectedLine);
  35939. }
  35940. }
  35941. class CodeDocumentDeleteAction : public UndoableAction
  35942. {
  35943. CodeDocument& owner;
  35944. int startPos, endPos;
  35945. String removedText;
  35946. CodeDocumentDeleteAction (const CodeDocumentDeleteAction&);
  35947. const CodeDocumentDeleteAction& operator= (const CodeDocumentDeleteAction&);
  35948. public:
  35949. CodeDocumentDeleteAction (CodeDocument& owner_, const int startPos_, const int endPos_) throw()
  35950. : owner (owner_),
  35951. startPos (startPos_),
  35952. endPos (endPos_)
  35953. {
  35954. removedText = owner.getTextBetween (CodeDocument::Position (&owner, startPos),
  35955. CodeDocument::Position (&owner, endPos));
  35956. }
  35957. ~CodeDocumentDeleteAction() {}
  35958. bool perform()
  35959. {
  35960. owner.currentActionIndex++;
  35961. owner.remove (startPos, endPos, false);
  35962. return true;
  35963. }
  35964. bool undo()
  35965. {
  35966. owner.currentActionIndex--;
  35967. owner.insert (removedText, startPos, false);
  35968. return true;
  35969. }
  35970. int getSizeInUnits() { return removedText.length() + 32; }
  35971. };
  35972. void CodeDocument::remove (const int startPos, const int endPos, const bool undoable)
  35973. {
  35974. if (endPos <= startPos)
  35975. return;
  35976. if (undoable)
  35977. {
  35978. undoManager.perform (new CodeDocumentDeleteAction (*this, startPos, endPos));
  35979. }
  35980. else
  35981. {
  35982. Position startPosition (this, startPos);
  35983. Position endPosition (this, endPos);
  35984. maximumLineLength = -1;
  35985. const int firstAffectedLine = startPosition.getLineNumber();
  35986. const int endLine = endPosition.getLineNumber();
  35987. int lastAffectedLine = firstAffectedLine + 1;
  35988. CodeDocumentLine* const firstLine = lines.getUnchecked (firstAffectedLine);
  35989. if (firstAffectedLine == endLine)
  35990. {
  35991. firstLine->line = firstLine->line.substring (0, startPosition.getIndexInLine())
  35992. + firstLine->line.substring (endPosition.getIndexInLine());
  35993. firstLine->updateLength();
  35994. }
  35995. else
  35996. {
  35997. lastAffectedLine = lines.size();
  35998. CodeDocumentLine* const lastLine = lines.getUnchecked (endLine);
  35999. jassert (lastLine != 0);
  36000. firstLine->line = firstLine->line.substring (0, startPosition.getIndexInLine())
  36001. + lastLine->line.substring (endPosition.getIndexInLine());
  36002. firstLine->updateLength();
  36003. int numLinesToRemove = endLine - firstAffectedLine;
  36004. lines.removeRange (firstAffectedLine + 1, numLinesToRemove);
  36005. }
  36006. int i;
  36007. for (i = firstAffectedLine + 1; i < lines.size(); ++i)
  36008. {
  36009. CodeDocumentLine* const l = lines.getUnchecked (i);
  36010. const CodeDocumentLine* const previousLine = lines.getUnchecked (i - 1);
  36011. l->lineStartInFile = previousLine->lineStartInFile + previousLine->lineLength;
  36012. }
  36013. const int totalChars = getNumCharacters();
  36014. for (i = 0; i < positionsToMaintain.size(); ++i)
  36015. {
  36016. CodeDocument::Position* p = positionsToMaintain.getUnchecked(i);
  36017. if (p->getPosition() > startPosition.getPosition())
  36018. p->setPosition (jmax (startPos, p->getPosition() + startPos - endPos));
  36019. if (p->getPosition() > totalChars)
  36020. p->setPosition (totalChars);
  36021. }
  36022. sendListenerChangeMessage (firstAffectedLine, lastAffectedLine);
  36023. }
  36024. }
  36025. END_JUCE_NAMESPACE
  36026. /********* End of inlined file: juce_CodeDocument.cpp *********/
  36027. /********* Start of inlined file: juce_CodeEditorComponent.cpp *********/
  36028. BEGIN_JUCE_NAMESPACE
  36029. class CaretComponent : public Component,
  36030. public Timer
  36031. {
  36032. public:
  36033. CaretComponent()
  36034. {
  36035. setAlwaysOnTop (true);
  36036. setInterceptsMouseClicks (false, false);
  36037. }
  36038. ~CaretComponent()
  36039. {
  36040. }
  36041. void paint (Graphics& g)
  36042. {
  36043. if (getParentComponent()->hasKeyboardFocus (true))
  36044. g.fillAll (findColour (CodeEditorComponent::caretColourId));
  36045. }
  36046. void timerCallback()
  36047. {
  36048. setVisible (! isVisible());
  36049. }
  36050. void updatePosition (CodeEditorComponent& owner)
  36051. {
  36052. startTimer (400);
  36053. setVisible (true);
  36054. const Rectangle pos (owner.getCharacterBounds (owner.getCaretPos()));
  36055. setBounds (pos.getX(), pos.getY(), 2, pos.getHeight());
  36056. }
  36057. };
  36058. class CodeEditorComponent::CodeEditorLine
  36059. {
  36060. public:
  36061. CodeEditorLine() throw()
  36062. {
  36063. }
  36064. ~CodeEditorLine() throw()
  36065. {
  36066. }
  36067. bool update (CodeDocument& document, int lineNum,
  36068. CodeDocument::Iterator& source,
  36069. CodeTokeniser* analyser, const int spacesPerTab,
  36070. const CodeDocument::Position& selectionStart,
  36071. const CodeDocument::Position& selectionEnd)
  36072. {
  36073. Array <SyntaxToken> newTokens;
  36074. newTokens.ensureStorageAllocated (8);
  36075. if (analyser == 0)
  36076. {
  36077. newTokens.add (SyntaxToken (document.getLine (lineNum), -1));
  36078. }
  36079. else if (lineNum < document.getNumLines())
  36080. {
  36081. const CodeDocument::Position pos (&document, lineNum, 0);
  36082. createTokens (pos.getPosition(), pos.getLineText(),
  36083. source, analyser, newTokens);
  36084. }
  36085. replaceTabsWithSpaces (newTokens, spacesPerTab);
  36086. int newHighlightStart = 0;
  36087. int newHighlightEnd = 0;
  36088. if (selectionStart.getLineNumber() <= lineNum && selectionEnd.getLineNumber() >= lineNum)
  36089. {
  36090. const String line (document.getLine (lineNum));
  36091. CodeDocument::Position lineStart (&document, lineNum, 0), lineEnd (&document, lineNum + 1, 0);
  36092. newHighlightStart = indexToColumn (jmax (0, selectionStart.getPosition() - lineStart.getPosition()),
  36093. line, spacesPerTab);
  36094. newHighlightEnd = indexToColumn (jmin (lineEnd.getPosition() - lineStart.getPosition(), selectionEnd.getPosition() - lineStart.getPosition()),
  36095. line, spacesPerTab);
  36096. }
  36097. if (newHighlightStart != highlightColumnStart || newHighlightEnd != highlightColumnEnd)
  36098. {
  36099. highlightColumnStart = newHighlightStart;
  36100. highlightColumnEnd = newHighlightEnd;
  36101. }
  36102. else
  36103. {
  36104. if (tokens.size() == newTokens.size())
  36105. {
  36106. bool allTheSame = true;
  36107. for (int i = newTokens.size(); --i >= 0;)
  36108. {
  36109. if (tokens.getReference(i) != newTokens.getReference(i))
  36110. {
  36111. allTheSame = false;
  36112. break;
  36113. }
  36114. }
  36115. if (allTheSame)
  36116. return false;
  36117. }
  36118. }
  36119. tokens.swapWithArray (newTokens);
  36120. return true;
  36121. }
  36122. void draw (CodeEditorComponent& owner, Graphics& g, const Font& font,
  36123. float x, const int y, const int baselineOffset, const int lineHeight,
  36124. const Colour& highlightColour) const throw()
  36125. {
  36126. if (highlightColumnStart < highlightColumnEnd)
  36127. {
  36128. g.setColour (highlightColour);
  36129. g.fillRect (roundToInt (x + highlightColumnStart * owner.getCharWidth()), y,
  36130. roundToInt ((highlightColumnEnd - highlightColumnStart) * owner.getCharWidth()), lineHeight);
  36131. }
  36132. int lastType = INT_MIN;
  36133. for (int i = 0; i < tokens.size(); ++i)
  36134. {
  36135. SyntaxToken& token = tokens.getReference(i);
  36136. if (lastType != token.tokenType)
  36137. {
  36138. lastType = token.tokenType;
  36139. g.setColour (owner.getColourForTokenType (lastType));
  36140. }
  36141. g.drawSingleLineText (token.text, roundToInt (x), y + baselineOffset);
  36142. if (i < tokens.size() - 1)
  36143. {
  36144. if (token.width < 0)
  36145. token.width = font.getStringWidthFloat (token.text);
  36146. x += token.width;
  36147. }
  36148. }
  36149. }
  36150. private:
  36151. struct SyntaxToken
  36152. {
  36153. String text;
  36154. int tokenType;
  36155. float width;
  36156. SyntaxToken (const String& text_, const int type) throw()
  36157. : text (text_), tokenType (type), width (-1.0f)
  36158. {
  36159. }
  36160. bool operator!= (const SyntaxToken& other) const throw()
  36161. {
  36162. return text != other.text || tokenType != other.tokenType;
  36163. }
  36164. };
  36165. Array <SyntaxToken> tokens;
  36166. int highlightColumnStart, highlightColumnEnd;
  36167. static void createTokens (int startPosition, const String& lineText,
  36168. CodeDocument::Iterator& source,
  36169. CodeTokeniser* analyser,
  36170. Array <SyntaxToken>& newTokens)
  36171. {
  36172. CodeDocument::Iterator lastIterator (source);
  36173. const int lineLength = lineText.length();
  36174. for (;;)
  36175. {
  36176. int tokenType = analyser->readNextToken (source);
  36177. int tokenStart = lastIterator.getPosition();
  36178. int tokenEnd = source.getPosition();
  36179. if (tokenEnd <= tokenStart)
  36180. break;
  36181. tokenEnd -= startPosition;
  36182. if (tokenEnd > 0)
  36183. {
  36184. tokenStart -= startPosition;
  36185. newTokens.add (SyntaxToken (lineText.substring (jmax (0, tokenStart), tokenEnd),
  36186. tokenType));
  36187. if (tokenEnd >= lineLength)
  36188. break;
  36189. }
  36190. lastIterator = source;
  36191. }
  36192. source = lastIterator;
  36193. }
  36194. static void replaceTabsWithSpaces (Array <SyntaxToken>& tokens, const int spacesPerTab) throw()
  36195. {
  36196. int x = 0;
  36197. for (int i = 0; i < tokens.size(); ++i)
  36198. {
  36199. SyntaxToken& t = tokens.getReference(i);
  36200. for (;;)
  36201. {
  36202. int tabPos = t.text.indexOfChar (T('\t'));
  36203. if (tabPos < 0)
  36204. break;
  36205. const int spacesNeeded = spacesPerTab - ((tabPos + x) % spacesPerTab);
  36206. t.text = t.text.replaceSection (tabPos, 1, String::repeatedString (T(" "), spacesNeeded));
  36207. }
  36208. x += t.text.length();
  36209. }
  36210. }
  36211. int indexToColumn (int index, const String& line, int spacesPerTab) const throw()
  36212. {
  36213. jassert (index <= line.length());
  36214. int col = 0;
  36215. for (int i = 0; i < index; ++i)
  36216. {
  36217. if (line[i] != T('\t'))
  36218. ++col;
  36219. else
  36220. col += spacesPerTab - (col % spacesPerTab);
  36221. }
  36222. return col;
  36223. }
  36224. };
  36225. CodeEditorComponent::CodeEditorComponent (CodeDocument& document_,
  36226. CodeTokeniser* const codeTokeniser_)
  36227. : document (document_),
  36228. firstLineOnScreen (0),
  36229. gutter (5),
  36230. spacesPerTab (4),
  36231. lineHeight (0),
  36232. linesOnScreen (0),
  36233. columnsOnScreen (0),
  36234. scrollbarThickness (16),
  36235. useSpacesForTabs (false),
  36236. xOffset (0),
  36237. codeTokeniser (codeTokeniser_)
  36238. {
  36239. caretPos = CodeDocument::Position (&document_, 0, 0);
  36240. caretPos.setPositionMaintained (true);
  36241. selectionStart = CodeDocument::Position (&document_, 0, 0);
  36242. selectionStart.setPositionMaintained (true);
  36243. selectionEnd = CodeDocument::Position (&document_, 0, 0);
  36244. selectionEnd.setPositionMaintained (true);
  36245. setOpaque (true);
  36246. setMouseCursor (MouseCursor (MouseCursor::IBeamCursor));
  36247. setWantsKeyboardFocus (true);
  36248. addAndMakeVisible (verticalScrollBar = new ScrollBar (true));
  36249. verticalScrollBar->setSingleStepSize (1.0);
  36250. addAndMakeVisible (horizontalScrollBar = new ScrollBar (false));
  36251. horizontalScrollBar->setSingleStepSize (1.0);
  36252. addAndMakeVisible (caret = new CaretComponent());
  36253. Font f (12.0f);
  36254. f.setTypefaceName (Font::getDefaultMonospacedFontName());
  36255. setFont (f);
  36256. resetToDefaultColours();
  36257. verticalScrollBar->addListener (this);
  36258. horizontalScrollBar->addListener (this);
  36259. document.addListener (this);
  36260. }
  36261. CodeEditorComponent::~CodeEditorComponent()
  36262. {
  36263. document.removeListener (this);
  36264. deleteAllChildren();
  36265. }
  36266. void CodeEditorComponent::loadContent (const String& newContent)
  36267. {
  36268. clearCachedIterators (0);
  36269. document.replaceAllContent (newContent);
  36270. document.clearUndoHistory();
  36271. document.setSavePoint();
  36272. caretPos.setPosition (0);
  36273. selectionStart.setPosition (0);
  36274. selectionEnd.setPosition (0);
  36275. scrollToLine (0);
  36276. }
  36277. void CodeEditorComponent::codeDocumentChanged (const CodeDocument::Position& affectedTextStart,
  36278. const CodeDocument::Position& affectedTextEnd)
  36279. {
  36280. clearCachedIterators (affectedTextStart.getLineNumber());
  36281. triggerAsyncUpdate();
  36282. ((CaretComponent*) caret)->updatePosition (*this);
  36283. if (affectedTextEnd.getPosition() >= selectionStart.getPosition()
  36284. && affectedTextStart.getPosition() <= selectionEnd.getPosition())
  36285. deselectAll();
  36286. if (caretPos.getPosition() > affectedTextEnd.getPosition()
  36287. || caretPos.getPosition() < affectedTextStart.getPosition())
  36288. moveCaretTo (affectedTextStart, false);
  36289. updateScrollBars();
  36290. }
  36291. void CodeEditorComponent::resized()
  36292. {
  36293. linesOnScreen = (getHeight() - scrollbarThickness) / lineHeight;
  36294. columnsOnScreen = (int) ((getWidth() - scrollbarThickness) / charWidth);
  36295. lines.clear();
  36296. rebuildLineTokens();
  36297. ((CaretComponent*) caret)->updatePosition (*this);
  36298. verticalScrollBar->setBounds (getWidth() - scrollbarThickness, 0, scrollbarThickness, getHeight() - scrollbarThickness);
  36299. horizontalScrollBar->setBounds (gutter, getHeight() - scrollbarThickness, getWidth() - scrollbarThickness - gutter, scrollbarThickness);
  36300. updateScrollBars();
  36301. }
  36302. void CodeEditorComponent::paint (Graphics& g)
  36303. {
  36304. handleUpdateNowIfNeeded();
  36305. g.fillAll (findColour (CodeEditorComponent::backgroundColourId));
  36306. g.reduceClipRegion (gutter, 0, verticalScrollBar->getX() - gutter, horizontalScrollBar->getY());
  36307. g.setFont (font);
  36308. const int baselineOffset = (int) font.getAscent();
  36309. const Colour defaultColour (findColour (CodeEditorComponent::defaultTextColourId));
  36310. const Colour highlightColour (findColour (CodeEditorComponent::highlightColourId));
  36311. const Rectangle clip (g.getClipBounds());
  36312. const int firstLineToDraw = jmax (0, clip.getY() / lineHeight);
  36313. const int lastLineToDraw = jmin (lines.size(), clip.getBottom() / lineHeight + 1);
  36314. for (int j = firstLineToDraw; j < lastLineToDraw; ++j)
  36315. {
  36316. lines.getUnchecked(j)->draw (*this, g, font,
  36317. (float) (gutter - xOffset * charWidth),
  36318. lineHeight * j, baselineOffset, lineHeight,
  36319. highlightColour);
  36320. }
  36321. }
  36322. void CodeEditorComponent::setScrollbarThickness (const int thickness) throw()
  36323. {
  36324. if (scrollbarThickness != thickness)
  36325. {
  36326. scrollbarThickness = thickness;
  36327. resized();
  36328. }
  36329. }
  36330. void CodeEditorComponent::handleAsyncUpdate()
  36331. {
  36332. rebuildLineTokens();
  36333. }
  36334. void CodeEditorComponent::rebuildLineTokens()
  36335. {
  36336. cancelPendingUpdate();
  36337. const int numNeeded = linesOnScreen + 1;
  36338. int minLineToRepaint = numNeeded;
  36339. int maxLineToRepaint = 0;
  36340. if (numNeeded != lines.size())
  36341. {
  36342. lines.clear();
  36343. for (int i = numNeeded; --i >= 0;)
  36344. lines.add (new CodeEditorLine());
  36345. minLineToRepaint = 0;
  36346. maxLineToRepaint = numNeeded;
  36347. }
  36348. jassert (numNeeded == lines.size());
  36349. CodeDocument::Iterator source (&document);
  36350. getIteratorForPosition (CodeDocument::Position (&document, firstLineOnScreen, 0).getPosition(), source);
  36351. for (int i = 0; i < numNeeded; ++i)
  36352. {
  36353. CodeEditorLine* const line = lines.getUnchecked(i);
  36354. if (line->update (document, firstLineOnScreen + i, source, codeTokeniser, spacesPerTab,
  36355. selectionStart, selectionEnd))
  36356. {
  36357. minLineToRepaint = jmin (minLineToRepaint, i);
  36358. maxLineToRepaint = jmax (maxLineToRepaint, i);
  36359. }
  36360. }
  36361. if (minLineToRepaint <= maxLineToRepaint)
  36362. {
  36363. repaint (gutter, lineHeight * minLineToRepaint - 1,
  36364. verticalScrollBar->getX() - gutter,
  36365. lineHeight * (1 + maxLineToRepaint - minLineToRepaint) + 2);
  36366. }
  36367. }
  36368. void CodeEditorComponent::moveCaretTo (const CodeDocument::Position& newPos, const bool highlighting)
  36369. {
  36370. caretPos = newPos;
  36371. if (highlighting)
  36372. {
  36373. if (dragType == notDragging)
  36374. {
  36375. if (abs (caretPos.getPosition() - selectionStart.getPosition())
  36376. < abs (caretPos.getPosition() - selectionEnd.getPosition()))
  36377. dragType = draggingSelectionStart;
  36378. else
  36379. dragType = draggingSelectionEnd;
  36380. }
  36381. if (dragType == draggingSelectionStart)
  36382. {
  36383. selectionStart = caretPos;
  36384. if (selectionEnd.getPosition() < selectionStart.getPosition())
  36385. {
  36386. const CodeDocument::Position temp (selectionStart);
  36387. selectionStart = selectionEnd;
  36388. selectionEnd = temp;
  36389. dragType = draggingSelectionEnd;
  36390. }
  36391. }
  36392. else
  36393. {
  36394. selectionEnd = caretPos;
  36395. if (selectionEnd.getPosition() < selectionStart.getPosition())
  36396. {
  36397. const CodeDocument::Position temp (selectionStart);
  36398. selectionStart = selectionEnd;
  36399. selectionEnd = temp;
  36400. dragType = draggingSelectionStart;
  36401. }
  36402. }
  36403. triggerAsyncUpdate();
  36404. }
  36405. else
  36406. {
  36407. deselectAll();
  36408. }
  36409. ((CaretComponent*) caret)->updatePosition (*this);
  36410. scrollToKeepCaretOnScreen();
  36411. updateScrollBars();
  36412. }
  36413. void CodeEditorComponent::deselectAll()
  36414. {
  36415. if (selectionStart != selectionEnd)
  36416. triggerAsyncUpdate();
  36417. selectionStart = caretPos;
  36418. selectionEnd = caretPos;
  36419. }
  36420. void CodeEditorComponent::updateScrollBars()
  36421. {
  36422. verticalScrollBar->setRangeLimits (0, jmax (document.getNumLines(), firstLineOnScreen + linesOnScreen));
  36423. verticalScrollBar->setCurrentRange (firstLineOnScreen, linesOnScreen);
  36424. horizontalScrollBar->setRangeLimits (0, jmax ((double) document.getMaximumLineLength(), xOffset + columnsOnScreen));
  36425. horizontalScrollBar->setCurrentRange (xOffset, columnsOnScreen);
  36426. }
  36427. void CodeEditorComponent::scrollToLineInternal (int newFirstLineOnScreen)
  36428. {
  36429. newFirstLineOnScreen = jlimit (0, jmax (0, document.getNumLines() - 1),
  36430. newFirstLineOnScreen);
  36431. if (newFirstLineOnScreen != firstLineOnScreen)
  36432. {
  36433. firstLineOnScreen = newFirstLineOnScreen;
  36434. ((CaretComponent*) caret)->updatePosition (*this);
  36435. updateCachedIterators (firstLineOnScreen);
  36436. triggerAsyncUpdate();
  36437. }
  36438. }
  36439. void CodeEditorComponent::scrollToColumnInternal (double column)
  36440. {
  36441. const double newOffset = jlimit (0.0, document.getMaximumLineLength() + 3.0, column);
  36442. if (xOffset != newOffset)
  36443. {
  36444. xOffset = newOffset;
  36445. ((CaretComponent*) caret)->updatePosition (*this);
  36446. repaint();
  36447. }
  36448. }
  36449. void CodeEditorComponent::scrollToLine (int newFirstLineOnScreen)
  36450. {
  36451. scrollToLineInternal (newFirstLineOnScreen);
  36452. updateScrollBars();
  36453. }
  36454. void CodeEditorComponent::scrollToColumn (int newFirstColumnOnScreen)
  36455. {
  36456. scrollToColumnInternal (newFirstColumnOnScreen);
  36457. updateScrollBars();
  36458. }
  36459. void CodeEditorComponent::scrollBy (int deltaLines)
  36460. {
  36461. scrollToLine (firstLineOnScreen + deltaLines);
  36462. }
  36463. void CodeEditorComponent::scrollToKeepCaretOnScreen()
  36464. {
  36465. if (caretPos.getLineNumber() < firstLineOnScreen)
  36466. scrollBy (caretPos.getLineNumber() - firstLineOnScreen);
  36467. else if (caretPos.getLineNumber() >= firstLineOnScreen + linesOnScreen)
  36468. scrollBy (caretPos.getLineNumber() - (firstLineOnScreen + linesOnScreen - 1));
  36469. const int column = indexToColumn (caretPos.getLineNumber(), caretPos.getIndexInLine());
  36470. if (column >= xOffset + columnsOnScreen - 1)
  36471. scrollToColumn (column + 1 - columnsOnScreen);
  36472. else if (column < xOffset)
  36473. scrollToColumn (column);
  36474. }
  36475. const Rectangle CodeEditorComponent::getCharacterBounds (const CodeDocument::Position& pos) const throw()
  36476. {
  36477. return Rectangle (roundToInt ((gutter - xOffset * charWidth) + indexToColumn (pos.getLineNumber(), pos.getIndexInLine()) * charWidth),
  36478. (pos.getLineNumber() - firstLineOnScreen) * lineHeight,
  36479. roundToInt (charWidth),
  36480. lineHeight);
  36481. }
  36482. const CodeDocument::Position CodeEditorComponent::getPositionAt (int x, int y)
  36483. {
  36484. const int line = y / lineHeight + firstLineOnScreen;
  36485. const int column = roundToInt ((x - (gutter - xOffset * charWidth)) / charWidth);
  36486. const int index = columnToIndex (line, column);
  36487. return CodeDocument::Position (&document, line, index);
  36488. }
  36489. void CodeEditorComponent::insertTextAtCaret (const String& newText)
  36490. {
  36491. document.deleteSection (selectionStart, selectionEnd);
  36492. if (newText.isNotEmpty())
  36493. document.insertText (caretPos, newText);
  36494. scrollToKeepCaretOnScreen();
  36495. }
  36496. void CodeEditorComponent::insertTabAtCaret()
  36497. {
  36498. if (CharacterFunctions::isWhitespace (caretPos.getCharacter())
  36499. && caretPos.getLineNumber() == caretPos.movedBy (1).getLineNumber())
  36500. {
  36501. moveCaretTo (document.findWordBreakAfter (caretPos), false);
  36502. }
  36503. if (useSpacesForTabs)
  36504. {
  36505. const int caretCol = indexToColumn (caretPos.getLineNumber(), caretPos.getIndexInLine());
  36506. const int spacesNeeded = spacesPerTab - (caretCol % spacesPerTab);
  36507. insertTextAtCaret (String::repeatedString (T(" "), spacesNeeded));
  36508. }
  36509. else
  36510. {
  36511. insertTextAtCaret (T("\t"));
  36512. }
  36513. }
  36514. void CodeEditorComponent::cut()
  36515. {
  36516. insertTextAtCaret (String::empty);
  36517. }
  36518. void CodeEditorComponent::copy()
  36519. {
  36520. newTransaction();
  36521. const String selection (document.getTextBetween (selectionStart, selectionEnd));
  36522. if (selection.isNotEmpty())
  36523. SystemClipboard::copyTextToClipboard (selection);
  36524. }
  36525. void CodeEditorComponent::copyThenCut()
  36526. {
  36527. copy();
  36528. cut();
  36529. newTransaction();
  36530. }
  36531. void CodeEditorComponent::paste()
  36532. {
  36533. newTransaction();
  36534. const String clip (SystemClipboard::getTextFromClipboard());
  36535. if (clip.isNotEmpty())
  36536. insertTextAtCaret (clip);
  36537. newTransaction();
  36538. }
  36539. void CodeEditorComponent::cursorLeft (const bool moveInWholeWordSteps, const bool selecting)
  36540. {
  36541. newTransaction();
  36542. if (moveInWholeWordSteps)
  36543. moveCaretTo (document.findWordBreakBefore (caretPos), selecting);
  36544. else
  36545. moveCaretTo (caretPos.movedBy (-1), selecting);
  36546. }
  36547. void CodeEditorComponent::cursorRight (const bool moveInWholeWordSteps, const bool selecting)
  36548. {
  36549. newTransaction();
  36550. if (moveInWholeWordSteps)
  36551. moveCaretTo (document.findWordBreakAfter (caretPos), selecting);
  36552. else
  36553. moveCaretTo (caretPos.movedBy (1), selecting);
  36554. }
  36555. void CodeEditorComponent::cursorDown (const bool selecting)
  36556. {
  36557. newTransaction();
  36558. if (caretPos.getLineNumber() == document.getNumLines() - 1)
  36559. moveCaretTo (CodeDocument::Position (&document, INT_MAX, INT_MAX), selecting);
  36560. else
  36561. moveCaretTo (caretPos.movedByLines (1), selecting);
  36562. }
  36563. void CodeEditorComponent::cursorUp (const bool selecting)
  36564. {
  36565. newTransaction();
  36566. if (caretPos.getLineNumber() == 0)
  36567. moveCaretTo (CodeDocument::Position (&document, 0, 0), selecting);
  36568. else
  36569. moveCaretTo (caretPos.movedByLines (-1), selecting);
  36570. }
  36571. void CodeEditorComponent::pageDown (const bool selecting)
  36572. {
  36573. newTransaction();
  36574. scrollBy (jlimit (0, linesOnScreen, 1 + document.getNumLines() - firstLineOnScreen - linesOnScreen));
  36575. moveCaretTo (caretPos.movedByLines (linesOnScreen), selecting);
  36576. }
  36577. void CodeEditorComponent::pageUp (const bool selecting)
  36578. {
  36579. newTransaction();
  36580. scrollBy (-linesOnScreen);
  36581. moveCaretTo (caretPos.movedByLines (-linesOnScreen), selecting);
  36582. }
  36583. void CodeEditorComponent::scrollUp()
  36584. {
  36585. newTransaction();
  36586. scrollBy (1);
  36587. if (caretPos.getLineNumber() < firstLineOnScreen)
  36588. moveCaretTo (caretPos.movedByLines (1), false);
  36589. }
  36590. void CodeEditorComponent::scrollDown()
  36591. {
  36592. newTransaction();
  36593. scrollBy (-1);
  36594. if (caretPos.getLineNumber() >= firstLineOnScreen + linesOnScreen)
  36595. moveCaretTo (caretPos.movedByLines (-1), false);
  36596. }
  36597. void CodeEditorComponent::goToStartOfDocument (const bool selecting)
  36598. {
  36599. newTransaction();
  36600. moveCaretTo (CodeDocument::Position (&document, 0, 0), selecting);
  36601. }
  36602. static int findFirstNonWhitespaceChar (const String& line) throw()
  36603. {
  36604. const int len = line.length();
  36605. for (int i = 0; i < len; ++i)
  36606. if (! CharacterFunctions::isWhitespace (line [i]))
  36607. return i;
  36608. return 0;
  36609. }
  36610. void CodeEditorComponent::goToStartOfLine (const bool selecting)
  36611. {
  36612. newTransaction();
  36613. int index = findFirstNonWhitespaceChar (caretPos.getLineText());
  36614. if (index >= caretPos.getIndexInLine() && caretPos.getIndexInLine() > 0)
  36615. index = 0;
  36616. moveCaretTo (CodeDocument::Position (&document, caretPos.getLineNumber(), index), selecting);
  36617. }
  36618. void CodeEditorComponent::goToEndOfDocument (const bool selecting)
  36619. {
  36620. newTransaction();
  36621. moveCaretTo (CodeDocument::Position (&document, INT_MAX, INT_MAX), selecting);
  36622. }
  36623. void CodeEditorComponent::goToEndOfLine (const bool selecting)
  36624. {
  36625. newTransaction();
  36626. moveCaretTo (CodeDocument::Position (&document, caretPos.getLineNumber(), INT_MAX), selecting);
  36627. }
  36628. void CodeEditorComponent::backspace (const bool moveInWholeWordSteps)
  36629. {
  36630. if (moveInWholeWordSteps)
  36631. {
  36632. cut(); // in case something is already highlighted
  36633. moveCaretTo (document.findWordBreakBefore (caretPos), true);
  36634. }
  36635. else
  36636. {
  36637. if (selectionStart == selectionEnd)
  36638. selectionStart.moveBy (-1);
  36639. }
  36640. cut();
  36641. }
  36642. void CodeEditorComponent::deleteForward (const bool moveInWholeWordSteps)
  36643. {
  36644. if (moveInWholeWordSteps)
  36645. {
  36646. cut(); // in case something is already highlighted
  36647. moveCaretTo (document.findWordBreakAfter (caretPos), true);
  36648. }
  36649. else
  36650. {
  36651. if (selectionStart == selectionEnd)
  36652. selectionEnd.moveBy (1);
  36653. else
  36654. newTransaction();
  36655. }
  36656. cut();
  36657. }
  36658. void CodeEditorComponent::selectAll()
  36659. {
  36660. newTransaction();
  36661. moveCaretTo (CodeDocument::Position (&document, INT_MAX, INT_MAX), false);
  36662. moveCaretTo (CodeDocument::Position (&document, 0, 0), true);
  36663. }
  36664. void CodeEditorComponent::undo()
  36665. {
  36666. document.undo();
  36667. scrollToKeepCaretOnScreen();
  36668. }
  36669. void CodeEditorComponent::redo()
  36670. {
  36671. document.redo();
  36672. scrollToKeepCaretOnScreen();
  36673. }
  36674. void CodeEditorComponent::newTransaction()
  36675. {
  36676. document.newTransaction();
  36677. startTimer (600);
  36678. }
  36679. void CodeEditorComponent::timerCallback()
  36680. {
  36681. newTransaction();
  36682. }
  36683. bool CodeEditorComponent::keyPressed (const KeyPress& key)
  36684. {
  36685. const bool moveInWholeWordSteps = key.getModifiers().isCtrlDown() || key.getModifiers().isAltDown();
  36686. const bool shiftDown = key.getModifiers().isShiftDown();
  36687. if (key.isKeyCode (KeyPress::leftKey))
  36688. {
  36689. cursorLeft (moveInWholeWordSteps, shiftDown);
  36690. }
  36691. else if (key.isKeyCode (KeyPress::rightKey))
  36692. {
  36693. cursorRight (moveInWholeWordSteps, shiftDown);
  36694. }
  36695. else if (key.isKeyCode (KeyPress::upKey))
  36696. {
  36697. if (key.getModifiers().isCtrlDown() && ! shiftDown)
  36698. scrollDown();
  36699. #if JUCE_MAC
  36700. else if (key.getModifiers().isCommandDown())
  36701. goToStartOfDocument (shiftDown);
  36702. #endif
  36703. else
  36704. cursorUp (shiftDown);
  36705. }
  36706. else if (key.isKeyCode (KeyPress::downKey))
  36707. {
  36708. if (key.getModifiers().isCtrlDown() && ! shiftDown)
  36709. scrollUp();
  36710. #if JUCE_MAC
  36711. else if (key.getModifiers().isCommandDown())
  36712. goToEndOfDocument (shiftDown);
  36713. #endif
  36714. else
  36715. cursorDown (shiftDown);
  36716. }
  36717. else if (key.isKeyCode (KeyPress::pageDownKey))
  36718. {
  36719. pageDown (shiftDown);
  36720. }
  36721. else if (key.isKeyCode (KeyPress::pageUpKey))
  36722. {
  36723. pageUp (shiftDown);
  36724. }
  36725. else if (key.isKeyCode (KeyPress::homeKey))
  36726. {
  36727. if (moveInWholeWordSteps)
  36728. goToStartOfDocument (shiftDown);
  36729. else
  36730. goToStartOfLine (shiftDown);
  36731. }
  36732. else if (key.isKeyCode (KeyPress::endKey))
  36733. {
  36734. if (moveInWholeWordSteps)
  36735. goToEndOfDocument (shiftDown);
  36736. else
  36737. goToEndOfLine (shiftDown);
  36738. }
  36739. else if (key.isKeyCode (KeyPress::backspaceKey))
  36740. {
  36741. backspace (moveInWholeWordSteps);
  36742. }
  36743. else if (key.isKeyCode (KeyPress::deleteKey))
  36744. {
  36745. deleteForward (moveInWholeWordSteps);
  36746. }
  36747. else if (key == KeyPress (T('c'), ModifierKeys::commandModifier, 0))
  36748. {
  36749. copy();
  36750. }
  36751. else if (key == KeyPress (T('x'), ModifierKeys::commandModifier, 0))
  36752. {
  36753. copyThenCut();
  36754. }
  36755. else if (key == KeyPress (T('v'), ModifierKeys::commandModifier, 0))
  36756. {
  36757. paste();
  36758. }
  36759. else if (key == KeyPress (T('z'), ModifierKeys::commandModifier, 0))
  36760. {
  36761. undo();
  36762. }
  36763. else if (key == KeyPress (T('y'), ModifierKeys::commandModifier, 0)
  36764. || key == KeyPress (T('z'), ModifierKeys::commandModifier | ModifierKeys::shiftModifier, 0))
  36765. {
  36766. redo();
  36767. }
  36768. else if (key == KeyPress (T('a'), ModifierKeys::commandModifier, 0))
  36769. {
  36770. selectAll();
  36771. }
  36772. else if (key == KeyPress::tabKey || key.getTextCharacter() == '\t')
  36773. {
  36774. insertTabAtCaret();
  36775. }
  36776. else if (key == KeyPress::returnKey)
  36777. {
  36778. newTransaction();
  36779. insertTextAtCaret (document.getNewLineCharacters());
  36780. }
  36781. else if (key.isKeyCode (KeyPress::escapeKey))
  36782. {
  36783. newTransaction();
  36784. }
  36785. else if (key.getTextCharacter() >= ' ')
  36786. {
  36787. insertTextAtCaret (String::charToString (key.getTextCharacter()));
  36788. }
  36789. else
  36790. {
  36791. return false;
  36792. }
  36793. return true;
  36794. }
  36795. void CodeEditorComponent::mouseDown (const MouseEvent& e)
  36796. {
  36797. newTransaction();
  36798. dragType = notDragging;
  36799. if (! e.mods.isPopupMenu())
  36800. {
  36801. beginDragAutoRepeat (100);
  36802. moveCaretTo (getPositionAt (e.x, e.y), e.mods.isShiftDown());
  36803. }
  36804. else
  36805. {
  36806. }
  36807. }
  36808. void CodeEditorComponent::mouseDrag (const MouseEvent& e)
  36809. {
  36810. if (! e.mods.isPopupMenu())
  36811. moveCaretTo (getPositionAt (e.x, e.y), true);
  36812. }
  36813. void CodeEditorComponent::mouseUp (const MouseEvent&)
  36814. {
  36815. newTransaction();
  36816. beginDragAutoRepeat (0);
  36817. dragType = notDragging;
  36818. }
  36819. void CodeEditorComponent::mouseDoubleClick (const MouseEvent& e)
  36820. {
  36821. CodeDocument::Position tokenStart (getPositionAt (e.x, e.y));
  36822. CodeDocument::Position tokenEnd (tokenStart);
  36823. if (e.getNumberOfClicks() > 2)
  36824. {
  36825. tokenStart.setLineAndIndex (tokenStart.getLineNumber(), 0);
  36826. tokenEnd.setLineAndIndex (tokenStart.getLineNumber() + 1, 0);
  36827. }
  36828. else
  36829. {
  36830. while (CharacterFunctions::isLetterOrDigit (tokenEnd.getCharacter()))
  36831. tokenEnd.moveBy (1);
  36832. tokenStart = tokenEnd;
  36833. while (tokenStart.getIndexInLine() > 0
  36834. && CharacterFunctions::isLetterOrDigit (tokenStart.movedBy (-1).getCharacter()))
  36835. tokenStart.moveBy (-1);
  36836. }
  36837. moveCaretTo (tokenEnd, false);
  36838. moveCaretTo (tokenStart, true);
  36839. }
  36840. void CodeEditorComponent::mouseWheelMove (const MouseEvent& e, float wheelIncrementX, float wheelIncrementY)
  36841. {
  36842. verticalScrollBar->mouseWheelMove (e, 0, wheelIncrementY);
  36843. horizontalScrollBar->mouseWheelMove (e, wheelIncrementX, 0);
  36844. }
  36845. void CodeEditorComponent::scrollBarMoved (ScrollBar* scrollBarThatHasMoved, const double newRangeStart)
  36846. {
  36847. if (scrollBarThatHasMoved == verticalScrollBar)
  36848. scrollToLineInternal ((int) newRangeStart);
  36849. else
  36850. scrollToColumnInternal (newRangeStart);
  36851. }
  36852. void CodeEditorComponent::setTabSize (const int numSpaces, const bool insertSpaces) throw()
  36853. {
  36854. useSpacesForTabs = insertSpaces;
  36855. if (spacesPerTab != numSpaces)
  36856. {
  36857. spacesPerTab = numSpaces;
  36858. triggerAsyncUpdate();
  36859. }
  36860. }
  36861. int CodeEditorComponent::indexToColumn (int lineNum, int index) const throw()
  36862. {
  36863. const String line (document.getLine (lineNum));
  36864. jassert (index <= line.length());
  36865. int col = 0;
  36866. for (int i = 0; i < index; ++i)
  36867. {
  36868. if (line[i] != T('\t'))
  36869. ++col;
  36870. else
  36871. col += getTabSize() - (col % getTabSize());
  36872. }
  36873. return col;
  36874. }
  36875. int CodeEditorComponent::columnToIndex (int lineNum, int column) const throw()
  36876. {
  36877. const String line (document.getLine (lineNum));
  36878. const int lineLength = line.length();
  36879. int i, col = 0;
  36880. for (i = 0; i < lineLength; ++i)
  36881. {
  36882. if (line[i] != T('\t'))
  36883. ++col;
  36884. else
  36885. col += getTabSize() - (col % getTabSize());
  36886. if (col > column)
  36887. break;
  36888. }
  36889. return i;
  36890. }
  36891. void CodeEditorComponent::setFont (const Font& newFont)
  36892. {
  36893. font = newFont;
  36894. charWidth = font.getStringWidthFloat (T("0"));
  36895. lineHeight = roundToInt (font.getHeight());
  36896. resized();
  36897. }
  36898. void CodeEditorComponent::resetToDefaultColours()
  36899. {
  36900. coloursForTokenCategories.clear();
  36901. if (codeTokeniser != 0)
  36902. {
  36903. for (int i = codeTokeniser->getTokenTypes().size(); --i >= 0;)
  36904. setColourForTokenType (i, codeTokeniser->getDefaultColour (i));
  36905. }
  36906. }
  36907. void CodeEditorComponent::setColourForTokenType (const int tokenType, const Colour& colour)
  36908. {
  36909. jassert (tokenType < 256);
  36910. while (coloursForTokenCategories.size() < tokenType)
  36911. coloursForTokenCategories.add (Colours::black);
  36912. coloursForTokenCategories.set (tokenType, colour);
  36913. repaint();
  36914. }
  36915. const Colour CodeEditorComponent::getColourForTokenType (const int tokenType) const throw()
  36916. {
  36917. if (((unsigned int) tokenType) >= (unsigned int) coloursForTokenCategories.size())
  36918. return findColour (CodeEditorComponent::defaultTextColourId);
  36919. return coloursForTokenCategories.getReference (tokenType);
  36920. }
  36921. void CodeEditorComponent::clearCachedIterators (const int firstLineToBeInvalid) throw()
  36922. {
  36923. for (int i = cachedIterators.size(); --i >= 0;)
  36924. if (cachedIterators.getUnchecked (i)->getLine() >= firstLineToBeInvalid)
  36925. cachedIterators.remove (i);
  36926. // need to also clear the one before the invalid line
  36927. cachedIterators.removeLast();
  36928. }
  36929. void CodeEditorComponent::updateCachedIterators (int maxLineNum)
  36930. {
  36931. const int maxNumCachedPositions = 5000;
  36932. const int linesBetweenCachedSources = jmax (10, document.getNumLines() / maxNumCachedPositions);
  36933. if (cachedIterators.size() == 0)
  36934. cachedIterators.add (new CodeDocument::Iterator (&document));
  36935. if (codeTokeniser == 0)
  36936. return;
  36937. for (;;)
  36938. {
  36939. CodeDocument::Iterator* last = cachedIterators.getLast();
  36940. if (last->getLine() >= maxLineNum)
  36941. break;
  36942. CodeDocument::Iterator* t = new CodeDocument::Iterator (*last);
  36943. cachedIterators.add (t);
  36944. const int targetLine = last->getLine() + linesBetweenCachedSources;
  36945. for (;;)
  36946. {
  36947. codeTokeniser->readNextToken (*t);
  36948. if (t->getLine() >= targetLine)
  36949. break;
  36950. if (t->isEOF())
  36951. return;
  36952. }
  36953. }
  36954. }
  36955. void CodeEditorComponent::getIteratorForPosition (int position, CodeDocument::Iterator& source)
  36956. {
  36957. if (codeTokeniser == 0)
  36958. return;
  36959. for (int i = cachedIterators.size(); --i >= 0;)
  36960. {
  36961. CodeDocument::Iterator* t = cachedIterators.getUnchecked (i);
  36962. if (t->getPosition() <= position)
  36963. {
  36964. source = *t;
  36965. break;
  36966. }
  36967. }
  36968. while (source.getPosition() < position)
  36969. {
  36970. const CodeDocument::Iterator original (source);
  36971. codeTokeniser->readNextToken (source);
  36972. if (source.getPosition() > position || source.isEOF())
  36973. {
  36974. source = original;
  36975. break;
  36976. }
  36977. }
  36978. }
  36979. END_JUCE_NAMESPACE
  36980. /********* End of inlined file: juce_CodeEditorComponent.cpp *********/
  36981. /********* Start of inlined file: juce_CPlusPlusCodeTokeniser.cpp *********/
  36982. BEGIN_JUCE_NAMESPACE
  36983. CPlusPlusCodeTokeniser::CPlusPlusCodeTokeniser()
  36984. {
  36985. }
  36986. CPlusPlusCodeTokeniser::~CPlusPlusCodeTokeniser()
  36987. {
  36988. }
  36989. namespace CppTokeniser
  36990. {
  36991. static bool isIdentifierStart (const tchar c) throw()
  36992. {
  36993. return CharacterFunctions::isLetter (c)
  36994. || c == T('_') || c == T('@');
  36995. }
  36996. static bool isIdentifierBody (const tchar c) throw()
  36997. {
  36998. return CharacterFunctions::isLetter (c)
  36999. || CharacterFunctions::isDigit (c)
  37000. || c == T('_') || c == T('@');
  37001. }
  37002. static int parseIdentifier (CodeDocument::Iterator& source) throw()
  37003. {
  37004. static const tchar* keywords2Char[] =
  37005. { T("if"), T("do"), T("or"), 0 };
  37006. static const tchar* keywords3Char[] =
  37007. { T("for"), T("int"), T("new"), T("try"), T("xor"), T("and"), T("asm"), T("not"), 0 };
  37008. static const tchar* keywords4Char[] =
  37009. { T("bool"), T("void"), T("this"), T("true"), T("long"), T("else"), T("char"),
  37010. T("enum"), T("case"), T("goto"), T("auto"), 0 };
  37011. static const tchar* keywords5Char[] =
  37012. { T("while"), T("bitor"), T("break"), T("catch"), T("class"), T("compl"), T("const"), T("false"),
  37013. T("float"), T("short"), T("throw"), T("union"), T("using"), T("or_eq"), 0 };
  37014. static const tchar* keywords6Char[] =
  37015. { T("return"), T("struct"), T("and_eq"), T("bitand"), T("delete"), T("double"), T("extern"),
  37016. T("friend"), T("inline"), T("not_eq"), T("public"), T("sizeof"), T("static"), T("signed"),
  37017. T("switch"), T("typeid"), T("wchar_t"), T("xor_eq"), 0};
  37018. static const tchar* keywordsOther[] =
  37019. { T("const_cast"), T("continue"), T("default"), T("explicit"), T("mutable"), T("namespace"),
  37020. T("operator"), T("private"), T("protected"), T("register"), T("reinterpret_cast"), T("static_cast"),
  37021. T("template"), T("typedef"), T("typename"), T("unsigned"), T("virtual"), T("volatile"),
  37022. T("@implementation"), T("@interface"), T("@end"), T("@synthesize"), T("@dynamic"), T("@public"),
  37023. T("@private"), T("@property"), T("@protected"), T("@class"), 0 };
  37024. int tokenLength = 0;
  37025. tchar possibleIdentifier [19];
  37026. while (isIdentifierBody (source.peekNextChar()))
  37027. {
  37028. const tchar c = source.nextChar();
  37029. if (tokenLength < numElementsInArray (possibleIdentifier) - 1)
  37030. possibleIdentifier [tokenLength] = c;
  37031. ++tokenLength;
  37032. }
  37033. if (tokenLength > 1 && tokenLength <= 16)
  37034. {
  37035. possibleIdentifier [tokenLength] = 0;
  37036. const tchar** k;
  37037. switch (tokenLength)
  37038. {
  37039. case 2: k = keywords2Char; break;
  37040. case 3: k = keywords3Char; break;
  37041. case 4: k = keywords4Char; break;
  37042. case 5: k = keywords5Char; break;
  37043. case 6: k = keywords6Char; break;
  37044. default: k = keywordsOther; break;
  37045. }
  37046. int i = 0;
  37047. while (k[i] != 0)
  37048. {
  37049. if (k[i][0] == possibleIdentifier[0] && CharacterFunctions::compare (k[i], possibleIdentifier) == 0)
  37050. return CPlusPlusCodeTokeniser::tokenType_builtInKeyword;
  37051. ++i;
  37052. }
  37053. }
  37054. return CPlusPlusCodeTokeniser::tokenType_identifier;
  37055. }
  37056. static bool skipNumberSuffix (CodeDocument::Iterator& source)
  37057. {
  37058. const juce_wchar c = source.peekNextChar();
  37059. if (c == 'l' || c == 'L' || c == 'u' || c == 'U')
  37060. source.skip();
  37061. if (CharacterFunctions::isLetterOrDigit (source.peekNextChar()))
  37062. return false;
  37063. return true;
  37064. }
  37065. static bool isHexDigit (const juce_wchar c) throw()
  37066. {
  37067. return (c >= '0' && c <= '9')
  37068. || (c >= 'a' && c <= 'f')
  37069. || (c >= 'A' && c <= 'F');
  37070. }
  37071. static bool parseHexLiteral (CodeDocument::Iterator& source) throw()
  37072. {
  37073. if (source.nextChar() != '0')
  37074. return false;
  37075. juce_wchar c = source.nextChar();
  37076. if (c != 'x' && c != 'X')
  37077. return false;
  37078. int numDigits = 0;
  37079. while (isHexDigit (source.peekNextChar()))
  37080. {
  37081. ++numDigits;
  37082. source.skip();
  37083. }
  37084. if (numDigits == 0)
  37085. return false;
  37086. return skipNumberSuffix (source);
  37087. }
  37088. static bool isOctalDigit (const juce_wchar c) throw()
  37089. {
  37090. return c >= '0' && c <= '7';
  37091. }
  37092. static bool parseOctalLiteral (CodeDocument::Iterator& source) throw()
  37093. {
  37094. if (source.nextChar() != '0')
  37095. return false;
  37096. if (! isOctalDigit (source.nextChar()))
  37097. return false;
  37098. while (isOctalDigit (source.peekNextChar()))
  37099. source.skip();
  37100. return skipNumberSuffix (source);
  37101. }
  37102. static bool isDecimalDigit (const juce_wchar c) throw()
  37103. {
  37104. return c >= '0' && c <= '9';
  37105. }
  37106. static bool parseDecimalLiteral (CodeDocument::Iterator& source) throw()
  37107. {
  37108. int numChars = 0;
  37109. while (isDecimalDigit (source.peekNextChar()))
  37110. {
  37111. ++numChars;
  37112. source.skip();
  37113. }
  37114. if (numChars == 0)
  37115. return false;
  37116. return skipNumberSuffix (source);
  37117. }
  37118. static bool parseFloatLiteral (CodeDocument::Iterator& source) throw()
  37119. {
  37120. int numDigits = 0;
  37121. while (isDecimalDigit (source.peekNextChar()))
  37122. {
  37123. source.skip();
  37124. ++numDigits;
  37125. }
  37126. const bool hasPoint = (source.peekNextChar() == '.');
  37127. if (hasPoint)
  37128. {
  37129. source.skip();
  37130. while (isDecimalDigit (source.peekNextChar()))
  37131. {
  37132. source.skip();
  37133. ++numDigits;
  37134. }
  37135. }
  37136. if (numDigits == 0)
  37137. return false;
  37138. juce_wchar c = source.peekNextChar();
  37139. const bool hasExponent = (c == 'e' || c == 'E');
  37140. if (hasExponent)
  37141. {
  37142. source.skip();
  37143. c = source.peekNextChar();
  37144. if (c == '+' || c == '-')
  37145. source.skip();
  37146. int numExpDigits = 0;
  37147. while (isDecimalDigit (source.peekNextChar()))
  37148. {
  37149. source.skip();
  37150. ++numExpDigits;
  37151. }
  37152. if (numExpDigits == 0)
  37153. return false;
  37154. }
  37155. c = source.peekNextChar();
  37156. if (c == 'f' || c == 'F')
  37157. source.skip();
  37158. else if (! (hasExponent || hasPoint))
  37159. return false;
  37160. return true;
  37161. }
  37162. static int parseNumber (CodeDocument::Iterator& source)
  37163. {
  37164. const CodeDocument::Iterator original (source);
  37165. if (parseFloatLiteral (source))
  37166. return CPlusPlusCodeTokeniser::tokenType_floatLiteral;
  37167. source = original;
  37168. if (parseHexLiteral (source))
  37169. return CPlusPlusCodeTokeniser::tokenType_integerLiteral;
  37170. source = original;
  37171. if (parseOctalLiteral (source))
  37172. return CPlusPlusCodeTokeniser::tokenType_integerLiteral;
  37173. source = original;
  37174. if (parseDecimalLiteral (source))
  37175. return CPlusPlusCodeTokeniser::tokenType_integerLiteral;
  37176. source = original;
  37177. source.skip();
  37178. return CPlusPlusCodeTokeniser::tokenType_error;
  37179. }
  37180. static void skipQuotedString (CodeDocument::Iterator& source) throw()
  37181. {
  37182. const juce_wchar quote = source.nextChar();
  37183. for (;;)
  37184. {
  37185. const juce_wchar c = source.nextChar();
  37186. if (c == quote || c == 0)
  37187. break;
  37188. if (c == '\\')
  37189. source.skip();
  37190. }
  37191. }
  37192. static void skipComment (CodeDocument::Iterator& source) throw()
  37193. {
  37194. bool lastWasStar = false;
  37195. for (;;)
  37196. {
  37197. const juce_wchar c = source.nextChar();
  37198. if (c == 0 || (c == T('/') && lastWasStar))
  37199. break;
  37200. lastWasStar = (c == '*');
  37201. }
  37202. }
  37203. }
  37204. int CPlusPlusCodeTokeniser::readNextToken (CodeDocument::Iterator& source)
  37205. {
  37206. int result = tokenType_error;
  37207. source.skipWhitespace();
  37208. tchar firstChar = source.peekNextChar();
  37209. switch (firstChar)
  37210. {
  37211. case 0:
  37212. source.skip();
  37213. break;
  37214. case T('0'):
  37215. case T('1'):
  37216. case T('2'):
  37217. case T('3'):
  37218. case T('4'):
  37219. case T('5'):
  37220. case T('6'):
  37221. case T('7'):
  37222. case T('8'):
  37223. case T('9'):
  37224. result = CppTokeniser::parseNumber (source);
  37225. break;
  37226. case T('.'):
  37227. result = CppTokeniser::parseNumber (source);
  37228. if (result == tokenType_error)
  37229. result = tokenType_punctuation;
  37230. break;
  37231. case T(','):
  37232. case T(';'):
  37233. case T(':'):
  37234. source.skip();
  37235. result = tokenType_punctuation;
  37236. break;
  37237. case T('('):
  37238. case T(')'):
  37239. case T('{'):
  37240. case T('}'):
  37241. case T('['):
  37242. case T(']'):
  37243. source.skip();
  37244. result = tokenType_bracket;
  37245. break;
  37246. case T('"'):
  37247. case T('\''):
  37248. CppTokeniser::skipQuotedString (source);
  37249. result = tokenType_stringLiteral;
  37250. break;
  37251. case T('+'):
  37252. result = tokenType_operator;
  37253. source.skip();
  37254. if (source.peekNextChar() == T('+'))
  37255. source.skip();
  37256. else if (source.peekNextChar() == T('='))
  37257. source.skip();
  37258. break;
  37259. case T('-'):
  37260. source.skip();
  37261. result = CppTokeniser::parseNumber (source);
  37262. if (result == tokenType_error)
  37263. {
  37264. result = tokenType_operator;
  37265. if (source.peekNextChar() == T('-'))
  37266. source.skip();
  37267. else if (source.peekNextChar() == T('='))
  37268. source.skip();
  37269. }
  37270. break;
  37271. case T('*'):
  37272. case T('%'):
  37273. case T('='):
  37274. case T('!'):
  37275. result = tokenType_operator;
  37276. source.skip();
  37277. if (source.peekNextChar() == T('='))
  37278. source.skip();
  37279. break;
  37280. case T('/'):
  37281. result = tokenType_operator;
  37282. source.skip();
  37283. if (source.peekNextChar() == T('='))
  37284. {
  37285. source.skip();
  37286. }
  37287. else if (source.peekNextChar() == T('/'))
  37288. {
  37289. result = tokenType_comment;
  37290. source.skipToEndOfLine();
  37291. }
  37292. else if (source.peekNextChar() == T('*'))
  37293. {
  37294. source.skip();
  37295. result = tokenType_comment;
  37296. CppTokeniser::skipComment (source);
  37297. }
  37298. break;
  37299. case T('?'):
  37300. case T('~'):
  37301. source.skip();
  37302. result = tokenType_operator;
  37303. break;
  37304. case T('<'):
  37305. source.skip();
  37306. result = tokenType_operator;
  37307. if (source.peekNextChar() == T('='))
  37308. {
  37309. source.skip();
  37310. }
  37311. else if (source.peekNextChar() == T('<'))
  37312. {
  37313. source.skip();
  37314. if (source.peekNextChar() == T('='))
  37315. source.skip();
  37316. }
  37317. break;
  37318. case T('>'):
  37319. source.skip();
  37320. result = tokenType_operator;
  37321. if (source.peekNextChar() == T('='))
  37322. {
  37323. source.skip();
  37324. }
  37325. else if (source.peekNextChar() == T('<'))
  37326. {
  37327. source.skip();
  37328. if (source.peekNextChar() == T('='))
  37329. source.skip();
  37330. }
  37331. break;
  37332. case T('|'):
  37333. source.skip();
  37334. result = tokenType_operator;
  37335. if (source.peekNextChar() == T('='))
  37336. {
  37337. source.skip();
  37338. }
  37339. else if (source.peekNextChar() == T('|'))
  37340. {
  37341. source.skip();
  37342. if (source.peekNextChar() == T('='))
  37343. source.skip();
  37344. }
  37345. break;
  37346. case T('&'):
  37347. source.skip();
  37348. result = tokenType_operator;
  37349. if (source.peekNextChar() == T('='))
  37350. {
  37351. source.skip();
  37352. }
  37353. else if (source.peekNextChar() == T('&'))
  37354. {
  37355. source.skip();
  37356. if (source.peekNextChar() == T('='))
  37357. source.skip();
  37358. }
  37359. break;
  37360. case T('^'):
  37361. source.skip();
  37362. result = tokenType_operator;
  37363. if (source.peekNextChar() == T('='))
  37364. {
  37365. source.skip();
  37366. }
  37367. else if (source.peekNextChar() == T('^'))
  37368. {
  37369. source.skip();
  37370. if (source.peekNextChar() == T('='))
  37371. source.skip();
  37372. }
  37373. break;
  37374. case T('#'):
  37375. result = tokenType_preprocessor;
  37376. source.skipToEndOfLine();
  37377. break;
  37378. default:
  37379. if (CppTokeniser::isIdentifierStart (firstChar))
  37380. result = CppTokeniser::parseIdentifier (source);
  37381. else
  37382. source.skip();
  37383. break;
  37384. }
  37385. //jassert (result != tokenType_unknown);
  37386. return result;
  37387. }
  37388. const StringArray CPlusPlusCodeTokeniser::getTokenTypes()
  37389. {
  37390. StringArray s;
  37391. s.add ("Error");
  37392. s.add ("Comment");
  37393. s.add ("C++ keyword");
  37394. s.add ("Identifier");
  37395. s.add ("Integer literal");
  37396. s.add ("Float literal");
  37397. s.add ("String literal");
  37398. s.add ("Operator");
  37399. s.add ("Bracket");
  37400. s.add ("Punctuation");
  37401. s.add ("Preprocessor line");
  37402. return s;
  37403. }
  37404. const Colour CPlusPlusCodeTokeniser::getDefaultColour (const int tokenType)
  37405. {
  37406. const uint32 colours[] =
  37407. {
  37408. 0xffcc0000, // error
  37409. 0xff00aa00, // comment
  37410. 0xff0000cc, // keyword
  37411. 0xff000000, // identifier
  37412. 0xff880000, // int literal
  37413. 0xff885500, // float literal
  37414. 0xff990099, // string literal
  37415. 0xff225500, // operator
  37416. 0xff000055, // bracket
  37417. 0xff004400, // punctuation
  37418. 0xff660000 // preprocessor
  37419. };
  37420. if (tokenType >= 0 && tokenType < numElementsInArray (colours))
  37421. return Colour (colours [tokenType]);
  37422. return Colours::black;
  37423. }
  37424. END_JUCE_NAMESPACE
  37425. /********* End of inlined file: juce_CPlusPlusCodeTokeniser.cpp *********/
  37426. /********* Start of inlined file: juce_ComboBox.cpp *********/
  37427. BEGIN_JUCE_NAMESPACE
  37428. ComboBox::ComboBox (const String& name)
  37429. : Component (name),
  37430. lastCurrentId (0),
  37431. isButtonDown (false),
  37432. separatorPending (false),
  37433. menuActive (false),
  37434. label (0)
  37435. {
  37436. noChoicesMessage = TRANS("(no choices)");
  37437. setRepaintsOnMouseActivity (true);
  37438. lookAndFeelChanged();
  37439. currentId.addListener (this);
  37440. }
  37441. ComboBox::~ComboBox()
  37442. {
  37443. currentId.removeListener (this);
  37444. if (menuActive)
  37445. PopupMenu::dismissAllActiveMenus();
  37446. deleteAllChildren();
  37447. }
  37448. void ComboBox::setEditableText (const bool isEditable)
  37449. {
  37450. label->setEditable (isEditable, isEditable, false);
  37451. setWantsKeyboardFocus (! isEditable);
  37452. resized();
  37453. }
  37454. bool ComboBox::isTextEditable() const throw()
  37455. {
  37456. return label->isEditable();
  37457. }
  37458. void ComboBox::setJustificationType (const Justification& justification) throw()
  37459. {
  37460. label->setJustificationType (justification);
  37461. }
  37462. const Justification ComboBox::getJustificationType() const throw()
  37463. {
  37464. return label->getJustificationType();
  37465. }
  37466. void ComboBox::setTooltip (const String& newTooltip)
  37467. {
  37468. SettableTooltipClient::setTooltip (newTooltip);
  37469. label->setTooltip (newTooltip);
  37470. }
  37471. void ComboBox::addItem (const String& newItemText,
  37472. const int newItemId) throw()
  37473. {
  37474. // you can't add empty strings to the list..
  37475. jassert (newItemText.isNotEmpty());
  37476. // IDs must be non-zero, as zero is used to indicate a lack of selecion.
  37477. jassert (newItemId != 0);
  37478. // you shouldn't use duplicate item IDs!
  37479. jassert (getItemForId (newItemId) == 0);
  37480. if (newItemText.isNotEmpty() && newItemId != 0)
  37481. {
  37482. if (separatorPending)
  37483. {
  37484. separatorPending = false;
  37485. ItemInfo* const item = new ItemInfo();
  37486. item->itemId = 0;
  37487. item->isEnabled = false;
  37488. item->isHeading = false;
  37489. items.add (item);
  37490. }
  37491. ItemInfo* const item = new ItemInfo();
  37492. item->name = newItemText;
  37493. item->itemId = newItemId;
  37494. item->isEnabled = true;
  37495. item->isHeading = false;
  37496. items.add (item);
  37497. }
  37498. }
  37499. void ComboBox::addSeparator() throw()
  37500. {
  37501. separatorPending = (items.size() > 0);
  37502. }
  37503. void ComboBox::addSectionHeading (const String& headingName) throw()
  37504. {
  37505. // you can't add empty strings to the list..
  37506. jassert (headingName.isNotEmpty());
  37507. if (headingName.isNotEmpty())
  37508. {
  37509. if (separatorPending)
  37510. {
  37511. separatorPending = false;
  37512. ItemInfo* const item = new ItemInfo();
  37513. item->itemId = 0;
  37514. item->isEnabled = false;
  37515. item->isHeading = false;
  37516. items.add (item);
  37517. }
  37518. ItemInfo* const item = new ItemInfo();
  37519. item->name = headingName;
  37520. item->itemId = 0;
  37521. item->isEnabled = true;
  37522. item->isHeading = true;
  37523. items.add (item);
  37524. }
  37525. }
  37526. void ComboBox::setItemEnabled (const int itemId,
  37527. const bool shouldBeEnabled) throw()
  37528. {
  37529. ItemInfo* const item = getItemForId (itemId);
  37530. if (item != 0)
  37531. item->isEnabled = shouldBeEnabled;
  37532. }
  37533. void ComboBox::changeItemText (const int itemId,
  37534. const String& newText) throw()
  37535. {
  37536. ItemInfo* const item = getItemForId (itemId);
  37537. jassert (item != 0);
  37538. if (item != 0)
  37539. item->name = newText;
  37540. }
  37541. void ComboBox::clear (const bool dontSendChangeMessage)
  37542. {
  37543. items.clear();
  37544. separatorPending = false;
  37545. if (! label->isEditable())
  37546. setSelectedItemIndex (-1, dontSendChangeMessage);
  37547. }
  37548. bool ComboBox::ItemInfo::isSeparator() const throw()
  37549. {
  37550. return name.isEmpty();
  37551. }
  37552. bool ComboBox::ItemInfo::isRealItem() const throw()
  37553. {
  37554. return ! (isHeading || name.isEmpty());
  37555. }
  37556. ComboBox::ItemInfo* ComboBox::getItemForId (const int itemId) const throw()
  37557. {
  37558. if (itemId != 0)
  37559. {
  37560. for (int i = items.size(); --i >= 0;)
  37561. if (items.getUnchecked(i)->itemId == itemId)
  37562. return items.getUnchecked(i);
  37563. }
  37564. return 0;
  37565. }
  37566. ComboBox::ItemInfo* ComboBox::getItemForIndex (const int index) const throw()
  37567. {
  37568. int n = 0;
  37569. for (int i = 0; i < items.size(); ++i)
  37570. {
  37571. ItemInfo* const item = items.getUnchecked(i);
  37572. if (item->isRealItem())
  37573. if (n++ == index)
  37574. return item;
  37575. }
  37576. return 0;
  37577. }
  37578. int ComboBox::getNumItems() const throw()
  37579. {
  37580. int n = 0;
  37581. for (int i = items.size(); --i >= 0;)
  37582. if (items.getUnchecked(i)->isRealItem())
  37583. ++n;
  37584. return n;
  37585. }
  37586. const String ComboBox::getItemText (const int index) const throw()
  37587. {
  37588. const ItemInfo* const item = getItemForIndex (index);
  37589. if (item != 0)
  37590. return item->name;
  37591. return String::empty;
  37592. }
  37593. int ComboBox::getItemId (const int index) const throw()
  37594. {
  37595. const ItemInfo* const item = getItemForIndex (index);
  37596. return (item != 0) ? item->itemId : 0;
  37597. }
  37598. int ComboBox::indexOfItemId (const int itemId) const throw()
  37599. {
  37600. int n = 0;
  37601. for (int i = 0; i < items.size(); ++i)
  37602. {
  37603. const ItemInfo* const item = items.getUnchecked(i);
  37604. if (item->isRealItem())
  37605. {
  37606. if (item->itemId == itemId)
  37607. return n;
  37608. ++n;
  37609. }
  37610. }
  37611. return -1;
  37612. }
  37613. int ComboBox::getSelectedItemIndex() const throw()
  37614. {
  37615. int index = indexOfItemId (currentId.getValue());
  37616. if (getText() != getItemText (index))
  37617. index = -1;
  37618. return index;
  37619. }
  37620. void ComboBox::setSelectedItemIndex (const int index,
  37621. const bool dontSendChangeMessage) throw()
  37622. {
  37623. setSelectedId (getItemId (index), dontSendChangeMessage);
  37624. }
  37625. int ComboBox::getSelectedId() const throw()
  37626. {
  37627. const ItemInfo* const item = getItemForId (currentId.getValue());
  37628. return (item != 0 && getText() == item->name)
  37629. ? item->itemId
  37630. : 0;
  37631. }
  37632. void ComboBox::setSelectedId (const int newItemId,
  37633. const bool dontSendChangeMessage) throw()
  37634. {
  37635. const ItemInfo* const item = getItemForId (newItemId);
  37636. const String newItemText (item != 0 ? item->name : String::empty);
  37637. if (lastCurrentId != newItemId || label->getText() != newItemText)
  37638. {
  37639. if (! dontSendChangeMessage)
  37640. triggerAsyncUpdate();
  37641. label->setText (newItemText, false);
  37642. lastCurrentId = newItemId;
  37643. currentId = newItemId;
  37644. repaint(); // for the benefit of the 'none selected' text
  37645. }
  37646. }
  37647. void ComboBox::valueChanged (Value&)
  37648. {
  37649. if (lastCurrentId != (int) currentId.getValue())
  37650. setSelectedId (currentId.getValue(), false);
  37651. }
  37652. const String ComboBox::getText() const throw()
  37653. {
  37654. return label->getText();
  37655. }
  37656. void ComboBox::setText (const String& newText,
  37657. const bool dontSendChangeMessage) throw()
  37658. {
  37659. for (int i = items.size(); --i >= 0;)
  37660. {
  37661. const ItemInfo* const item = items.getUnchecked(i);
  37662. if (item->isRealItem()
  37663. && item->name == newText)
  37664. {
  37665. setSelectedId (item->itemId, dontSendChangeMessage);
  37666. return;
  37667. }
  37668. }
  37669. lastCurrentId = 0;
  37670. currentId = 0;
  37671. if (label->getText() != newText)
  37672. {
  37673. label->setText (newText, false);
  37674. if (! dontSendChangeMessage)
  37675. triggerAsyncUpdate();
  37676. }
  37677. repaint();
  37678. }
  37679. void ComboBox::showEditor()
  37680. {
  37681. jassert (isTextEditable()); // you probably shouldn't do this to a non-editable combo box?
  37682. label->showEditor();
  37683. }
  37684. void ComboBox::setTextWhenNothingSelected (const String& newMessage) throw()
  37685. {
  37686. textWhenNothingSelected = newMessage;
  37687. repaint();
  37688. }
  37689. const String ComboBox::getTextWhenNothingSelected() const throw()
  37690. {
  37691. return textWhenNothingSelected;
  37692. }
  37693. void ComboBox::setTextWhenNoChoicesAvailable (const String& newMessage) throw()
  37694. {
  37695. noChoicesMessage = newMessage;
  37696. }
  37697. const String ComboBox::getTextWhenNoChoicesAvailable() const throw()
  37698. {
  37699. return noChoicesMessage;
  37700. }
  37701. void ComboBox::paint (Graphics& g)
  37702. {
  37703. getLookAndFeel().drawComboBox (g,
  37704. getWidth(),
  37705. getHeight(),
  37706. isButtonDown,
  37707. label->getRight(),
  37708. 0,
  37709. getWidth() - label->getRight(),
  37710. getHeight(),
  37711. *this);
  37712. if (textWhenNothingSelected.isNotEmpty()
  37713. && label->getText().isEmpty()
  37714. && ! label->isBeingEdited())
  37715. {
  37716. g.setColour (findColour (textColourId).withMultipliedAlpha (0.5f));
  37717. g.setFont (label->getFont());
  37718. g.drawFittedText (textWhenNothingSelected,
  37719. label->getX() + 2, label->getY() + 1,
  37720. label->getWidth() - 4, label->getHeight() - 2,
  37721. label->getJustificationType(),
  37722. jmax (1, (int) (label->getHeight() / label->getFont().getHeight())));
  37723. }
  37724. }
  37725. void ComboBox::resized()
  37726. {
  37727. if (getHeight() > 0 && getWidth() > 0)
  37728. getLookAndFeel().positionComboBoxText (*this, *label);
  37729. }
  37730. void ComboBox::enablementChanged()
  37731. {
  37732. repaint();
  37733. }
  37734. void ComboBox::lookAndFeelChanged()
  37735. {
  37736. repaint();
  37737. Label* const newLabel = getLookAndFeel().createComboBoxTextBox (*this);
  37738. if (label != 0)
  37739. {
  37740. newLabel->setEditable (label->isEditable());
  37741. newLabel->setJustificationType (label->getJustificationType());
  37742. newLabel->setTooltip (label->getTooltip());
  37743. newLabel->setText (label->getText(), false);
  37744. }
  37745. delete label;
  37746. label = newLabel;
  37747. addAndMakeVisible (newLabel);
  37748. newLabel->addListener (this);
  37749. newLabel->addMouseListener (this, false);
  37750. newLabel->setColour (Label::backgroundColourId, Colours::transparentBlack);
  37751. newLabel->setColour (Label::textColourId, findColour (ComboBox::textColourId));
  37752. newLabel->setColour (TextEditor::textColourId, findColour (ComboBox::textColourId));
  37753. newLabel->setColour (TextEditor::backgroundColourId, Colours::transparentBlack);
  37754. newLabel->setColour (TextEditor::highlightColourId, findColour (TextEditor::highlightColourId));
  37755. newLabel->setColour (TextEditor::outlineColourId, Colours::transparentBlack);
  37756. resized();
  37757. }
  37758. void ComboBox::colourChanged()
  37759. {
  37760. lookAndFeelChanged();
  37761. }
  37762. bool ComboBox::keyPressed (const KeyPress& key)
  37763. {
  37764. bool used = false;
  37765. if (key.isKeyCode (KeyPress::upKey)
  37766. || key.isKeyCode (KeyPress::leftKey))
  37767. {
  37768. setSelectedItemIndex (jmax (0, getSelectedItemIndex() - 1));
  37769. used = true;
  37770. }
  37771. else if (key.isKeyCode (KeyPress::downKey)
  37772. || key.isKeyCode (KeyPress::rightKey))
  37773. {
  37774. setSelectedItemIndex (jmin (getSelectedItemIndex() + 1, getNumItems() - 1));
  37775. used = true;
  37776. }
  37777. else if (key.isKeyCode (KeyPress::returnKey))
  37778. {
  37779. showPopup();
  37780. used = true;
  37781. }
  37782. return used;
  37783. }
  37784. bool ComboBox::keyStateChanged (const bool isKeyDown)
  37785. {
  37786. // only forward key events that aren't used by this component
  37787. return isKeyDown
  37788. && (KeyPress::isKeyCurrentlyDown (KeyPress::upKey)
  37789. || KeyPress::isKeyCurrentlyDown (KeyPress::leftKey)
  37790. || KeyPress::isKeyCurrentlyDown (KeyPress::downKey)
  37791. || KeyPress::isKeyCurrentlyDown (KeyPress::rightKey));
  37792. }
  37793. void ComboBox::focusGained (FocusChangeType)
  37794. {
  37795. repaint();
  37796. }
  37797. void ComboBox::focusLost (FocusChangeType)
  37798. {
  37799. repaint();
  37800. }
  37801. void ComboBox::labelTextChanged (Label*)
  37802. {
  37803. triggerAsyncUpdate();
  37804. }
  37805. void ComboBox::showPopup()
  37806. {
  37807. if (! menuActive)
  37808. {
  37809. const int selectedId = getSelectedId();
  37810. ComponentDeletionWatcher deletionWatcher (this);
  37811. PopupMenu menu;
  37812. menu.setLookAndFeel (&getLookAndFeel());
  37813. for (int i = 0; i < items.size(); ++i)
  37814. {
  37815. const ItemInfo* const item = items.getUnchecked(i);
  37816. if (item->isSeparator())
  37817. menu.addSeparator();
  37818. else if (item->isHeading)
  37819. menu.addSectionHeader (item->name);
  37820. else
  37821. menu.addItem (item->itemId, item->name,
  37822. item->isEnabled, item->itemId == selectedId);
  37823. }
  37824. if (items.size() == 0)
  37825. menu.addItem (1, noChoicesMessage, false);
  37826. const int itemHeight = jlimit (12, 24, getHeight());
  37827. menuActive = true;
  37828. const int resultId = menu.showAt (this, selectedId,
  37829. getWidth(), 1, itemHeight);
  37830. if (deletionWatcher.hasBeenDeleted())
  37831. return;
  37832. menuActive = false;
  37833. if (resultId != 0)
  37834. setSelectedId (resultId);
  37835. }
  37836. }
  37837. void ComboBox::mouseDown (const MouseEvent& e)
  37838. {
  37839. beginDragAutoRepeat (300);
  37840. isButtonDown = isEnabled();
  37841. if (isButtonDown
  37842. && (e.eventComponent == this || ! label->isEditable()))
  37843. {
  37844. showPopup();
  37845. }
  37846. }
  37847. void ComboBox::mouseDrag (const MouseEvent& e)
  37848. {
  37849. beginDragAutoRepeat (50);
  37850. if (isButtonDown && ! e.mouseWasClicked())
  37851. showPopup();
  37852. }
  37853. void ComboBox::mouseUp (const MouseEvent& e2)
  37854. {
  37855. if (isButtonDown)
  37856. {
  37857. isButtonDown = false;
  37858. repaint();
  37859. const MouseEvent e (e2.getEventRelativeTo (this));
  37860. if (reallyContains (e.x, e.y, true)
  37861. && (e2.eventComponent == this || ! label->isEditable()))
  37862. {
  37863. showPopup();
  37864. }
  37865. }
  37866. }
  37867. void ComboBox::addListener (ComboBoxListener* const listener) throw()
  37868. {
  37869. jassert (listener != 0);
  37870. if (listener != 0)
  37871. listeners.add (listener);
  37872. }
  37873. void ComboBox::removeListener (ComboBoxListener* const listener) throw()
  37874. {
  37875. listeners.removeValue (listener);
  37876. }
  37877. void ComboBox::handleAsyncUpdate()
  37878. {
  37879. for (int i = listeners.size(); --i >= 0;)
  37880. {
  37881. ((ComboBoxListener*) listeners.getUnchecked (i))->comboBoxChanged (this);
  37882. i = jmin (i, listeners.size());
  37883. }
  37884. }
  37885. END_JUCE_NAMESPACE
  37886. /********* End of inlined file: juce_ComboBox.cpp *********/
  37887. /********* Start of inlined file: juce_Label.cpp *********/
  37888. BEGIN_JUCE_NAMESPACE
  37889. Label::Label (const String& componentName,
  37890. const String& labelText)
  37891. : Component (componentName),
  37892. textValue (labelText),
  37893. lastTextValue (labelText),
  37894. font (15.0f),
  37895. justification (Justification::centredLeft),
  37896. ownerComponent (0),
  37897. horizontalBorderSize (5),
  37898. verticalBorderSize (1),
  37899. minimumHorizontalScale (0.7f),
  37900. editSingleClick (false),
  37901. editDoubleClick (false),
  37902. lossOfFocusDiscardsChanges (false)
  37903. {
  37904. setColour (TextEditor::textColourId, Colours::black);
  37905. setColour (TextEditor::backgroundColourId, Colours::transparentBlack);
  37906. setColour (TextEditor::outlineColourId, Colours::transparentBlack);
  37907. textValue.addListener (this);
  37908. }
  37909. Label::~Label()
  37910. {
  37911. textValue.removeListener (this);
  37912. if (ownerComponent != 0 && ! deletionWatcher->hasBeenDeleted())
  37913. ownerComponent->removeComponentListener (this);
  37914. editor = 0;
  37915. }
  37916. void Label::setText (const String& newText,
  37917. const bool broadcastChangeMessage)
  37918. {
  37919. hideEditor (true);
  37920. if (lastTextValue != newText)
  37921. {
  37922. lastTextValue = newText;
  37923. textValue = newText;
  37924. repaint();
  37925. textWasChanged();
  37926. if (ownerComponent != 0 && ! deletionWatcher->hasBeenDeleted())
  37927. componentMovedOrResized (*ownerComponent, true, true);
  37928. if (broadcastChangeMessage)
  37929. callChangeListeners();
  37930. }
  37931. }
  37932. const String Label::getText (const bool returnActiveEditorContents) const throw()
  37933. {
  37934. return (returnActiveEditorContents && isBeingEdited())
  37935. ? editor->getText()
  37936. : textValue.toString();
  37937. }
  37938. void Label::valueChanged (Value&)
  37939. {
  37940. if (lastTextValue != textValue.toString())
  37941. setText (textValue.toString(), true);
  37942. }
  37943. void Label::setFont (const Font& newFont) throw()
  37944. {
  37945. font = newFont;
  37946. repaint();
  37947. }
  37948. const Font& Label::getFont() const throw()
  37949. {
  37950. return font;
  37951. }
  37952. void Label::setEditable (const bool editOnSingleClick,
  37953. const bool editOnDoubleClick,
  37954. const bool lossOfFocusDiscardsChanges_) throw()
  37955. {
  37956. editSingleClick = editOnSingleClick;
  37957. editDoubleClick = editOnDoubleClick;
  37958. lossOfFocusDiscardsChanges = lossOfFocusDiscardsChanges_;
  37959. setWantsKeyboardFocus (editOnSingleClick || editOnDoubleClick);
  37960. setFocusContainer (editOnSingleClick || editOnDoubleClick);
  37961. }
  37962. void Label::setJustificationType (const Justification& justification_) throw()
  37963. {
  37964. justification = justification_;
  37965. repaint();
  37966. }
  37967. void Label::setBorderSize (int h, int v)
  37968. {
  37969. horizontalBorderSize = h;
  37970. verticalBorderSize = v;
  37971. repaint();
  37972. }
  37973. void Label::attachToComponent (Component* owner,
  37974. const bool onLeft)
  37975. {
  37976. if (ownerComponent != 0 && ! deletionWatcher->hasBeenDeleted())
  37977. ownerComponent->removeComponentListener (this);
  37978. deletionWatcher = 0;
  37979. ownerComponent = owner;
  37980. leftOfOwnerComp = onLeft;
  37981. if (ownerComponent != 0)
  37982. {
  37983. deletionWatcher = new ComponentDeletionWatcher (owner);
  37984. setVisible (owner->isVisible());
  37985. ownerComponent->addComponentListener (this);
  37986. componentParentHierarchyChanged (*ownerComponent);
  37987. componentMovedOrResized (*ownerComponent, true, true);
  37988. }
  37989. }
  37990. void Label::componentMovedOrResized (Component& component,
  37991. bool /*wasMoved*/,
  37992. bool /*wasResized*/)
  37993. {
  37994. if (leftOfOwnerComp)
  37995. {
  37996. setSize (jmin (getFont().getStringWidth (textValue.toString()) + 8, component.getX()),
  37997. component.getHeight());
  37998. setTopRightPosition (component.getX(), component.getY());
  37999. }
  38000. else
  38001. {
  38002. setSize (component.getWidth(),
  38003. 8 + roundToInt (getFont().getHeight()));
  38004. setTopLeftPosition (component.getX(), component.getY() - getHeight());
  38005. }
  38006. }
  38007. void Label::componentParentHierarchyChanged (Component& component)
  38008. {
  38009. if (component.getParentComponent() != 0)
  38010. component.getParentComponent()->addChildComponent (this);
  38011. }
  38012. void Label::componentVisibilityChanged (Component& component)
  38013. {
  38014. setVisible (component.isVisible());
  38015. }
  38016. void Label::textWasEdited()
  38017. {
  38018. }
  38019. void Label::textWasChanged()
  38020. {
  38021. }
  38022. void Label::showEditor()
  38023. {
  38024. if (editor == 0)
  38025. {
  38026. addAndMakeVisible (editor = createEditorComponent());
  38027. editor->setText (getText(), false);
  38028. editor->addListener (this);
  38029. editor->grabKeyboardFocus();
  38030. editor->setHighlightedRegion (0, textValue.toString().length());
  38031. editor->addListener (this);
  38032. resized();
  38033. repaint();
  38034. editorShown (editor);
  38035. enterModalState();
  38036. editor->grabKeyboardFocus();
  38037. }
  38038. }
  38039. void Label::editorShown (TextEditor* /*editorComponent*/)
  38040. {
  38041. }
  38042. void Label::editorAboutToBeHidden (TextEditor* /*editorComponent*/)
  38043. {
  38044. }
  38045. bool Label::updateFromTextEditorContents()
  38046. {
  38047. jassert (editor != 0);
  38048. const String newText (editor->getText());
  38049. if (textValue.toString() != newText)
  38050. {
  38051. lastTextValue = newText;
  38052. textValue = newText;
  38053. repaint();
  38054. textWasChanged();
  38055. if (ownerComponent != 0 && ! deletionWatcher->hasBeenDeleted())
  38056. componentMovedOrResized (*ownerComponent, true, true);
  38057. return true;
  38058. }
  38059. return false;
  38060. }
  38061. void Label::hideEditor (const bool discardCurrentEditorContents)
  38062. {
  38063. if (editor != 0)
  38064. {
  38065. editorAboutToBeHidden (editor);
  38066. const bool changed = (! discardCurrentEditorContents)
  38067. && updateFromTextEditorContents();
  38068. editor = 0;
  38069. repaint();
  38070. if (changed)
  38071. textWasEdited();
  38072. exitModalState (0);
  38073. if (changed && isValidComponent())
  38074. callChangeListeners();
  38075. }
  38076. }
  38077. void Label::inputAttemptWhenModal()
  38078. {
  38079. if (editor != 0)
  38080. {
  38081. if (lossOfFocusDiscardsChanges)
  38082. textEditorEscapeKeyPressed (*editor);
  38083. else
  38084. textEditorReturnKeyPressed (*editor);
  38085. }
  38086. }
  38087. bool Label::isBeingEdited() const throw()
  38088. {
  38089. return editor != 0;
  38090. }
  38091. TextEditor* Label::createEditorComponent()
  38092. {
  38093. TextEditor* const ed = new TextEditor (getName());
  38094. ed->setFont (font);
  38095. // copy these colours from our own settings..
  38096. const int cols[] = { TextEditor::backgroundColourId,
  38097. TextEditor::textColourId,
  38098. TextEditor::highlightColourId,
  38099. TextEditor::highlightedTextColourId,
  38100. TextEditor::caretColourId,
  38101. TextEditor::outlineColourId,
  38102. TextEditor::focusedOutlineColourId,
  38103. TextEditor::shadowColourId };
  38104. for (int i = 0; i < numElementsInArray (cols); ++i)
  38105. ed->setColour (cols[i], findColour (cols[i]));
  38106. return ed;
  38107. }
  38108. void Label::paint (Graphics& g)
  38109. {
  38110. getLookAndFeel().drawLabel (g, *this);
  38111. }
  38112. void Label::mouseUp (const MouseEvent& e)
  38113. {
  38114. if (editSingleClick
  38115. && e.mouseWasClicked()
  38116. && contains (e.x, e.y)
  38117. && ! e.mods.isPopupMenu())
  38118. {
  38119. showEditor();
  38120. }
  38121. }
  38122. void Label::mouseDoubleClick (const MouseEvent& e)
  38123. {
  38124. if (editDoubleClick && ! e.mods.isPopupMenu())
  38125. showEditor();
  38126. }
  38127. void Label::resized()
  38128. {
  38129. if (editor != 0)
  38130. editor->setBoundsInset (BorderSize (0));
  38131. }
  38132. void Label::focusGained (FocusChangeType cause)
  38133. {
  38134. if (editSingleClick && cause == focusChangedByTabKey)
  38135. showEditor();
  38136. }
  38137. void Label::enablementChanged()
  38138. {
  38139. repaint();
  38140. }
  38141. void Label::colourChanged()
  38142. {
  38143. repaint();
  38144. }
  38145. void Label::setMinimumHorizontalScale (const float newScale)
  38146. {
  38147. if (minimumHorizontalScale != newScale)
  38148. {
  38149. minimumHorizontalScale = newScale;
  38150. repaint();
  38151. }
  38152. }
  38153. // We'll use a custom focus traverser here to make sure focus goes from the
  38154. // text editor to another component rather than back to the label itself.
  38155. class LabelKeyboardFocusTraverser : public KeyboardFocusTraverser
  38156. {
  38157. public:
  38158. LabelKeyboardFocusTraverser() {}
  38159. Component* getNextComponent (Component* current)
  38160. {
  38161. return KeyboardFocusTraverser::getNextComponent (dynamic_cast <TextEditor*> (current) != 0
  38162. ? current->getParentComponent() : current);
  38163. }
  38164. Component* getPreviousComponent (Component* current)
  38165. {
  38166. return KeyboardFocusTraverser::getPreviousComponent (dynamic_cast <TextEditor*> (current) != 0
  38167. ? current->getParentComponent() : current);
  38168. }
  38169. };
  38170. KeyboardFocusTraverser* Label::createFocusTraverser()
  38171. {
  38172. return new LabelKeyboardFocusTraverser();
  38173. }
  38174. void Label::addListener (LabelListener* const listener) throw()
  38175. {
  38176. jassert (listener != 0);
  38177. if (listener != 0)
  38178. listeners.add (listener);
  38179. }
  38180. void Label::removeListener (LabelListener* const listener) throw()
  38181. {
  38182. listeners.removeValue (listener);
  38183. }
  38184. void Label::callChangeListeners()
  38185. {
  38186. for (int i = listeners.size(); --i >= 0;)
  38187. {
  38188. ((LabelListener*) listeners.getUnchecked (i))->labelTextChanged (this);
  38189. i = jmin (i, listeners.size());
  38190. }
  38191. }
  38192. void Label::textEditorTextChanged (TextEditor& ed)
  38193. {
  38194. if (editor != 0)
  38195. {
  38196. jassert (&ed == editor);
  38197. if (! (hasKeyboardFocus (true) || isCurrentlyBlockedByAnotherModalComponent()))
  38198. {
  38199. if (lossOfFocusDiscardsChanges)
  38200. textEditorEscapeKeyPressed (ed);
  38201. else
  38202. textEditorReturnKeyPressed (ed);
  38203. }
  38204. }
  38205. }
  38206. void Label::textEditorReturnKeyPressed (TextEditor& ed)
  38207. {
  38208. if (editor != 0)
  38209. {
  38210. jassert (&ed == editor);
  38211. (void) ed;
  38212. const bool changed = updateFromTextEditorContents();
  38213. hideEditor (true);
  38214. if (changed)
  38215. {
  38216. textWasEdited();
  38217. if (isValidComponent())
  38218. callChangeListeners();
  38219. }
  38220. }
  38221. }
  38222. void Label::textEditorEscapeKeyPressed (TextEditor& ed)
  38223. {
  38224. if (editor != 0)
  38225. {
  38226. jassert (&ed == editor);
  38227. (void) ed;
  38228. editor->setText (textValue.toString(), false);
  38229. hideEditor (true);
  38230. }
  38231. }
  38232. void Label::textEditorFocusLost (TextEditor& ed)
  38233. {
  38234. textEditorTextChanged (ed);
  38235. }
  38236. END_JUCE_NAMESPACE
  38237. /********* End of inlined file: juce_Label.cpp *********/
  38238. /********* Start of inlined file: juce_ListBox.cpp *********/
  38239. BEGIN_JUCE_NAMESPACE
  38240. class ListBoxRowComponent : public Component,
  38241. public TooltipClient
  38242. {
  38243. public:
  38244. ListBoxRowComponent (ListBox& owner_)
  38245. : owner (owner_),
  38246. row (-1),
  38247. selected (false),
  38248. isDragging (false)
  38249. {
  38250. }
  38251. ~ListBoxRowComponent()
  38252. {
  38253. deleteAllChildren();
  38254. }
  38255. void paint (Graphics& g)
  38256. {
  38257. if (owner.getModel() != 0)
  38258. owner.getModel()->paintListBoxItem (row, g, getWidth(), getHeight(), selected);
  38259. }
  38260. void update (const int row_, const bool selected_)
  38261. {
  38262. if (row != row_ || selected != selected_)
  38263. {
  38264. repaint();
  38265. row = row_;
  38266. selected = selected_;
  38267. }
  38268. if (owner.getModel() != 0)
  38269. {
  38270. Component* const customComp = owner.getModel()->refreshComponentForRow (row_, selected_, getChildComponent (0));
  38271. if (customComp != 0)
  38272. {
  38273. addAndMakeVisible (customComp);
  38274. customComp->setBounds (0, 0, getWidth(), getHeight());
  38275. for (int i = getNumChildComponents(); --i >= 0;)
  38276. if (getChildComponent (i) != customComp)
  38277. delete getChildComponent (i);
  38278. }
  38279. else
  38280. {
  38281. deleteAllChildren();
  38282. }
  38283. }
  38284. }
  38285. void mouseDown (const MouseEvent& e)
  38286. {
  38287. isDragging = false;
  38288. selectRowOnMouseUp = false;
  38289. if (isEnabled())
  38290. {
  38291. if (! selected)
  38292. {
  38293. owner.selectRowsBasedOnModifierKeys (row, e.mods);
  38294. if (owner.getModel() != 0)
  38295. owner.getModel()->listBoxItemClicked (row, e);
  38296. }
  38297. else
  38298. {
  38299. selectRowOnMouseUp = true;
  38300. }
  38301. }
  38302. }
  38303. void mouseUp (const MouseEvent& e)
  38304. {
  38305. if (isEnabled() && selectRowOnMouseUp && ! isDragging)
  38306. {
  38307. owner.selectRowsBasedOnModifierKeys (row, e.mods);
  38308. if (owner.getModel() != 0)
  38309. owner.getModel()->listBoxItemClicked (row, e);
  38310. }
  38311. }
  38312. void mouseDoubleClick (const MouseEvent& e)
  38313. {
  38314. if (owner.getModel() != 0 && isEnabled())
  38315. owner.getModel()->listBoxItemDoubleClicked (row, e);
  38316. }
  38317. void mouseDrag (const MouseEvent& e)
  38318. {
  38319. if (isEnabled() && owner.getModel() != 0 && ! (e.mouseWasClicked() || isDragging))
  38320. {
  38321. const SparseSet <int> selectedRows (owner.getSelectedRows());
  38322. if (selectedRows.size() > 0)
  38323. {
  38324. const String dragDescription (owner.getModel()->getDragSourceDescription (selectedRows));
  38325. if (dragDescription.isNotEmpty())
  38326. {
  38327. isDragging = true;
  38328. owner.startDragAndDrop (e, dragDescription);
  38329. }
  38330. }
  38331. }
  38332. }
  38333. void resized()
  38334. {
  38335. if (getNumChildComponents() > 0)
  38336. getChildComponent(0)->setBounds (0, 0, getWidth(), getHeight());
  38337. }
  38338. const String getTooltip()
  38339. {
  38340. if (owner.getModel() != 0)
  38341. return owner.getModel()->getTooltipForRow (row);
  38342. return String::empty;
  38343. }
  38344. juce_UseDebuggingNewOperator
  38345. bool neededFlag;
  38346. private:
  38347. ListBox& owner;
  38348. int row;
  38349. bool selected, isDragging, selectRowOnMouseUp;
  38350. ListBoxRowComponent (const ListBoxRowComponent&);
  38351. const ListBoxRowComponent& operator= (const ListBoxRowComponent&);
  38352. };
  38353. class ListViewport : public Viewport
  38354. {
  38355. public:
  38356. int firstIndex, firstWholeIndex, lastWholeIndex;
  38357. bool hasUpdated;
  38358. ListViewport (ListBox& owner_)
  38359. : owner (owner_)
  38360. {
  38361. setWantsKeyboardFocus (false);
  38362. setViewedComponent (new Component());
  38363. getViewedComponent()->addMouseListener (this, false);
  38364. getViewedComponent()->setWantsKeyboardFocus (false);
  38365. }
  38366. ~ListViewport()
  38367. {
  38368. getViewedComponent()->removeMouseListener (this);
  38369. getViewedComponent()->deleteAllChildren();
  38370. }
  38371. ListBoxRowComponent* getComponentForRow (const int row) const throw()
  38372. {
  38373. return (ListBoxRowComponent*) getViewedComponent()
  38374. ->getChildComponent (row % jmax (1, getViewedComponent()->getNumChildComponents()));
  38375. }
  38376. int getRowNumberOfComponent (Component* const rowComponent) const throw()
  38377. {
  38378. const int index = getIndexOfChildComponent (rowComponent);
  38379. const int num = getViewedComponent()->getNumChildComponents();
  38380. for (int i = num; --i >= 0;)
  38381. if (((firstIndex + i) % jmax (1, num)) == index)
  38382. return firstIndex + i;
  38383. return -1;
  38384. }
  38385. Component* getComponentForRowIfOnscreen (const int row) const throw()
  38386. {
  38387. return (row >= firstIndex && row < firstIndex + getViewedComponent()->getNumChildComponents())
  38388. ? getComponentForRow (row) : 0;
  38389. }
  38390. void visibleAreaChanged (int, int, int, int)
  38391. {
  38392. updateVisibleArea (true);
  38393. if (owner.getModel() != 0)
  38394. owner.getModel()->listWasScrolled();
  38395. }
  38396. void updateVisibleArea (const bool makeSureItUpdatesContent)
  38397. {
  38398. hasUpdated = false;
  38399. const int newX = getViewedComponent()->getX();
  38400. int newY = getViewedComponent()->getY();
  38401. const int newW = jmax (owner.minimumRowWidth, getMaximumVisibleWidth());
  38402. const int newH = owner.totalItems * owner.getRowHeight();
  38403. if (newY + newH < getMaximumVisibleHeight() && newH > getMaximumVisibleHeight())
  38404. newY = getMaximumVisibleHeight() - newH;
  38405. getViewedComponent()->setBounds (newX, newY, newW, newH);
  38406. if (makeSureItUpdatesContent && ! hasUpdated)
  38407. updateContents();
  38408. }
  38409. void updateContents()
  38410. {
  38411. hasUpdated = true;
  38412. const int rowHeight = owner.getRowHeight();
  38413. if (rowHeight > 0)
  38414. {
  38415. const int y = getViewPositionY();
  38416. const int w = getViewedComponent()->getWidth();
  38417. const int numNeeded = 2 + getMaximumVisibleHeight() / rowHeight;
  38418. while (numNeeded > getViewedComponent()->getNumChildComponents())
  38419. getViewedComponent()->addAndMakeVisible (new ListBoxRowComponent (owner));
  38420. jassert (numNeeded >= 0);
  38421. while (numNeeded < getViewedComponent()->getNumChildComponents())
  38422. {
  38423. Component* const rowToRemove
  38424. = getViewedComponent()->getChildComponent (getViewedComponent()->getNumChildComponents() - 1);
  38425. delete rowToRemove;
  38426. }
  38427. firstIndex = y / rowHeight;
  38428. firstWholeIndex = (y + rowHeight - 1) / rowHeight;
  38429. lastWholeIndex = (y + getMaximumVisibleHeight() - 1) / rowHeight;
  38430. for (int i = 0; i < numNeeded; ++i)
  38431. {
  38432. const int row = i + firstIndex;
  38433. ListBoxRowComponent* const rowComp = getComponentForRow (row);
  38434. if (rowComp != 0)
  38435. {
  38436. rowComp->setBounds (0, row * rowHeight, w, rowHeight);
  38437. rowComp->update (row, owner.isRowSelected (row));
  38438. }
  38439. }
  38440. }
  38441. if (owner.headerComponent != 0)
  38442. owner.headerComponent->setBounds (owner.outlineThickness + getViewedComponent()->getX(),
  38443. owner.outlineThickness,
  38444. jmax (owner.getWidth() - owner.outlineThickness * 2,
  38445. getViewedComponent()->getWidth()),
  38446. owner.headerComponent->getHeight());
  38447. }
  38448. void paint (Graphics& g)
  38449. {
  38450. if (isOpaque())
  38451. g.fillAll (owner.findColour (ListBox::backgroundColourId));
  38452. }
  38453. bool keyPressed (const KeyPress& key)
  38454. {
  38455. if (key.isKeyCode (KeyPress::upKey)
  38456. || key.isKeyCode (KeyPress::downKey)
  38457. || key.isKeyCode (KeyPress::pageUpKey)
  38458. || key.isKeyCode (KeyPress::pageDownKey)
  38459. || key.isKeyCode (KeyPress::homeKey)
  38460. || key.isKeyCode (KeyPress::endKey))
  38461. {
  38462. // we want to avoid these keypresses going to the viewport, and instead allow
  38463. // them to pass up to our listbox..
  38464. return false;
  38465. }
  38466. return Viewport::keyPressed (key);
  38467. }
  38468. juce_UseDebuggingNewOperator
  38469. private:
  38470. ListBox& owner;
  38471. ListViewport (const ListViewport&);
  38472. const ListViewport& operator= (const ListViewport&);
  38473. };
  38474. ListBox::ListBox (const String& name, ListBoxModel* const model_)
  38475. : Component (name),
  38476. model (model_),
  38477. headerComponent (0),
  38478. totalItems (0),
  38479. rowHeight (22),
  38480. minimumRowWidth (0),
  38481. outlineThickness (0),
  38482. lastRowSelected (-1),
  38483. mouseMoveSelects (false),
  38484. multipleSelection (false),
  38485. hasDoneInitialUpdate (false)
  38486. {
  38487. addAndMakeVisible (viewport = new ListViewport (*this));
  38488. setWantsKeyboardFocus (true);
  38489. colourChanged();
  38490. }
  38491. ListBox::~ListBox()
  38492. {
  38493. deleteAllChildren();
  38494. }
  38495. void ListBox::setModel (ListBoxModel* const newModel)
  38496. {
  38497. if (model != newModel)
  38498. {
  38499. model = newModel;
  38500. updateContent();
  38501. }
  38502. }
  38503. void ListBox::setMultipleSelectionEnabled (bool b)
  38504. {
  38505. multipleSelection = b;
  38506. }
  38507. void ListBox::setMouseMoveSelectsRows (bool b)
  38508. {
  38509. mouseMoveSelects = b;
  38510. if (b)
  38511. addMouseListener (this, true);
  38512. }
  38513. void ListBox::paint (Graphics& g)
  38514. {
  38515. if (! hasDoneInitialUpdate)
  38516. updateContent();
  38517. g.fillAll (findColour (backgroundColourId));
  38518. }
  38519. void ListBox::paintOverChildren (Graphics& g)
  38520. {
  38521. if (outlineThickness > 0)
  38522. {
  38523. g.setColour (findColour (outlineColourId));
  38524. g.drawRect (0, 0, getWidth(), getHeight(), outlineThickness);
  38525. }
  38526. }
  38527. void ListBox::resized()
  38528. {
  38529. viewport->setBoundsInset (BorderSize (outlineThickness + ((headerComponent != 0) ? headerComponent->getHeight() : 0),
  38530. outlineThickness,
  38531. outlineThickness,
  38532. outlineThickness));
  38533. viewport->setSingleStepSizes (20, getRowHeight());
  38534. viewport->updateVisibleArea (false);
  38535. }
  38536. void ListBox::visibilityChanged()
  38537. {
  38538. viewport->updateVisibleArea (true);
  38539. }
  38540. Viewport* ListBox::getViewport() const throw()
  38541. {
  38542. return viewport;
  38543. }
  38544. void ListBox::updateContent()
  38545. {
  38546. hasDoneInitialUpdate = true;
  38547. totalItems = (model != 0) ? model->getNumRows() : 0;
  38548. bool selectionChanged = false;
  38549. if (selected [selected.size() - 1] >= totalItems)
  38550. {
  38551. selected.removeRange (totalItems, INT_MAX - totalItems);
  38552. lastRowSelected = getSelectedRow (0);
  38553. selectionChanged = true;
  38554. }
  38555. viewport->updateVisibleArea (isVisible());
  38556. viewport->resized();
  38557. if (selectionChanged && model != 0)
  38558. model->selectedRowsChanged (lastRowSelected);
  38559. }
  38560. void ListBox::selectRow (const int row,
  38561. bool dontScroll,
  38562. bool deselectOthersFirst)
  38563. {
  38564. selectRowInternal (row, dontScroll, deselectOthersFirst, false);
  38565. }
  38566. void ListBox::selectRowInternal (const int row,
  38567. bool dontScroll,
  38568. bool deselectOthersFirst,
  38569. bool isMouseClick)
  38570. {
  38571. if (! multipleSelection)
  38572. deselectOthersFirst = true;
  38573. if ((! isRowSelected (row))
  38574. || (deselectOthersFirst && getNumSelectedRows() > 1))
  38575. {
  38576. if (((unsigned int) row) < (unsigned int) totalItems)
  38577. {
  38578. if (deselectOthersFirst)
  38579. selected.clear();
  38580. selected.addRange (row, 1);
  38581. if (getHeight() == 0 || getWidth() == 0)
  38582. dontScroll = true;
  38583. viewport->hasUpdated = false;
  38584. if (row < viewport->firstWholeIndex && ! dontScroll)
  38585. {
  38586. viewport->setViewPosition (viewport->getViewPositionX(),
  38587. row * getRowHeight());
  38588. }
  38589. else if (row >= viewport->lastWholeIndex && ! dontScroll)
  38590. {
  38591. const int rowsOnScreen = viewport->lastWholeIndex - viewport->firstWholeIndex;
  38592. if (row >= lastRowSelected + rowsOnScreen
  38593. && rowsOnScreen < totalItems - 1
  38594. && ! isMouseClick)
  38595. {
  38596. viewport->setViewPosition (viewport->getViewPositionX(),
  38597. jlimit (0, jmax (0, totalItems - rowsOnScreen), row)
  38598. * getRowHeight());
  38599. }
  38600. else
  38601. {
  38602. viewport->setViewPosition (viewport->getViewPositionX(),
  38603. jmax (0, (row + 1) * getRowHeight() - viewport->getMaximumVisibleHeight()));
  38604. }
  38605. }
  38606. if (! viewport->hasUpdated)
  38607. viewport->updateContents();
  38608. lastRowSelected = row;
  38609. model->selectedRowsChanged (row);
  38610. }
  38611. else
  38612. {
  38613. if (deselectOthersFirst)
  38614. deselectAllRows();
  38615. }
  38616. }
  38617. }
  38618. void ListBox::deselectRow (const int row)
  38619. {
  38620. if (selected.contains (row))
  38621. {
  38622. selected.removeRange (row, 1);
  38623. if (row == lastRowSelected)
  38624. lastRowSelected = getSelectedRow (0);
  38625. viewport->updateContents();
  38626. model->selectedRowsChanged (lastRowSelected);
  38627. }
  38628. }
  38629. void ListBox::setSelectedRows (const SparseSet<int>& setOfRowsToBeSelected,
  38630. const bool sendNotificationEventToModel)
  38631. {
  38632. selected = setOfRowsToBeSelected;
  38633. selected.removeRange (totalItems, INT_MAX - totalItems);
  38634. if (! isRowSelected (lastRowSelected))
  38635. lastRowSelected = getSelectedRow (0);
  38636. viewport->updateContents();
  38637. if ((model != 0) && sendNotificationEventToModel)
  38638. model->selectedRowsChanged (lastRowSelected);
  38639. }
  38640. const SparseSet<int> ListBox::getSelectedRows() const
  38641. {
  38642. return selected;
  38643. }
  38644. void ListBox::selectRangeOfRows (int firstRow, int lastRow)
  38645. {
  38646. if (multipleSelection && (firstRow != lastRow))
  38647. {
  38648. const int numRows = totalItems - 1;
  38649. firstRow = jlimit (0, jmax (0, numRows), firstRow);
  38650. lastRow = jlimit (0, jmax (0, numRows), lastRow);
  38651. selected.addRange (jmin (firstRow, lastRow),
  38652. abs (firstRow - lastRow) + 1);
  38653. selected.removeRange (lastRow, 1);
  38654. }
  38655. selectRowInternal (lastRow, false, false, true);
  38656. }
  38657. void ListBox::flipRowSelection (const int row)
  38658. {
  38659. if (isRowSelected (row))
  38660. deselectRow (row);
  38661. else
  38662. selectRowInternal (row, false, false, true);
  38663. }
  38664. void ListBox::deselectAllRows()
  38665. {
  38666. if (! selected.isEmpty())
  38667. {
  38668. selected.clear();
  38669. lastRowSelected = -1;
  38670. viewport->updateContents();
  38671. if (model != 0)
  38672. model->selectedRowsChanged (lastRowSelected);
  38673. }
  38674. }
  38675. void ListBox::selectRowsBasedOnModifierKeys (const int row,
  38676. const ModifierKeys& mods)
  38677. {
  38678. if (multipleSelection && mods.isCommandDown())
  38679. {
  38680. flipRowSelection (row);
  38681. }
  38682. else if (multipleSelection && mods.isShiftDown() && lastRowSelected >= 0)
  38683. {
  38684. selectRangeOfRows (lastRowSelected, row);
  38685. }
  38686. else if ((! mods.isPopupMenu()) || ! isRowSelected (row))
  38687. {
  38688. selectRowInternal (row, false, true, true);
  38689. }
  38690. }
  38691. int ListBox::getNumSelectedRows() const
  38692. {
  38693. return selected.size();
  38694. }
  38695. int ListBox::getSelectedRow (const int index) const
  38696. {
  38697. return (((unsigned int) index) < (unsigned int) selected.size())
  38698. ? selected [index] : -1;
  38699. }
  38700. bool ListBox::isRowSelected (const int row) const
  38701. {
  38702. return selected.contains (row);
  38703. }
  38704. int ListBox::getLastRowSelected() const
  38705. {
  38706. return (isRowSelected (lastRowSelected)) ? lastRowSelected : -1;
  38707. }
  38708. int ListBox::getRowContainingPosition (const int x, const int y) const throw()
  38709. {
  38710. if (((unsigned int) x) < (unsigned int) getWidth())
  38711. {
  38712. const int row = (viewport->getViewPositionY() + y - viewport->getY()) / rowHeight;
  38713. if (((unsigned int) row) < (unsigned int) totalItems)
  38714. return row;
  38715. }
  38716. return -1;
  38717. }
  38718. int ListBox::getInsertionIndexForPosition (const int x, const int y) const throw()
  38719. {
  38720. if (((unsigned int) x) < (unsigned int) getWidth())
  38721. {
  38722. const int row = (viewport->getViewPositionY() + y + rowHeight / 2 - viewport->getY()) / rowHeight;
  38723. return jlimit (0, totalItems, row);
  38724. }
  38725. return -1;
  38726. }
  38727. Component* ListBox::getComponentForRowNumber (const int row) const throw()
  38728. {
  38729. Component* const listRowComp = viewport->getComponentForRowIfOnscreen (row);
  38730. return listRowComp != 0 ? listRowComp->getChildComponent (0) : 0;
  38731. }
  38732. int ListBox::getRowNumberOfComponent (Component* const rowComponent) const throw()
  38733. {
  38734. return viewport->getRowNumberOfComponent (rowComponent);
  38735. }
  38736. const Rectangle ListBox::getRowPosition (const int rowNumber,
  38737. const bool relativeToComponentTopLeft) const throw()
  38738. {
  38739. const int rowHeight = getRowHeight();
  38740. int y = viewport->getY() + rowHeight * rowNumber;
  38741. if (relativeToComponentTopLeft)
  38742. y -= viewport->getViewPositionY();
  38743. return Rectangle (viewport->getX(), y,
  38744. viewport->getViewedComponent()->getWidth(), rowHeight);
  38745. }
  38746. void ListBox::setVerticalPosition (const double proportion)
  38747. {
  38748. const int offscreen = viewport->getViewedComponent()->getHeight() - viewport->getHeight();
  38749. viewport->setViewPosition (viewport->getViewPositionX(),
  38750. jmax (0, roundToInt (proportion * offscreen)));
  38751. }
  38752. double ListBox::getVerticalPosition() const
  38753. {
  38754. const int offscreen = viewport->getViewedComponent()->getHeight() - viewport->getHeight();
  38755. return (offscreen > 0) ? viewport->getViewPositionY() / (double) offscreen
  38756. : 0;
  38757. }
  38758. int ListBox::getVisibleRowWidth() const throw()
  38759. {
  38760. return viewport->getViewWidth();
  38761. }
  38762. void ListBox::scrollToEnsureRowIsOnscreen (const int row)
  38763. {
  38764. if (row < viewport->firstWholeIndex)
  38765. {
  38766. viewport->setViewPosition (viewport->getViewPositionX(),
  38767. row * getRowHeight());
  38768. }
  38769. else if (row >= viewport->lastWholeIndex)
  38770. {
  38771. viewport->setViewPosition (viewport->getViewPositionX(),
  38772. jmax (0, (row + 1) * getRowHeight() - viewport->getMaximumVisibleHeight()));
  38773. }
  38774. }
  38775. bool ListBox::keyPressed (const KeyPress& key)
  38776. {
  38777. const int numVisibleRows = viewport->getHeight() / getRowHeight();
  38778. const bool multiple = multipleSelection
  38779. && (lastRowSelected >= 0)
  38780. && (key.getModifiers().isShiftDown()
  38781. || key.getModifiers().isCtrlDown()
  38782. || key.getModifiers().isCommandDown());
  38783. if (key.isKeyCode (KeyPress::upKey))
  38784. {
  38785. if (multiple)
  38786. selectRangeOfRows (lastRowSelected, lastRowSelected - 1);
  38787. else
  38788. selectRow (jmax (0, lastRowSelected - 1));
  38789. }
  38790. else if (key.isKeyCode (KeyPress::returnKey)
  38791. && isRowSelected (lastRowSelected))
  38792. {
  38793. if (model != 0)
  38794. model->returnKeyPressed (lastRowSelected);
  38795. }
  38796. else if (key.isKeyCode (KeyPress::pageUpKey))
  38797. {
  38798. if (multiple)
  38799. selectRangeOfRows (lastRowSelected, lastRowSelected - numVisibleRows);
  38800. else
  38801. selectRow (jmax (0, jmax (0, lastRowSelected) - numVisibleRows));
  38802. }
  38803. else if (key.isKeyCode (KeyPress::pageDownKey))
  38804. {
  38805. if (multiple)
  38806. selectRangeOfRows (lastRowSelected, lastRowSelected + numVisibleRows);
  38807. else
  38808. selectRow (jmin (totalItems - 1, jmax (0, lastRowSelected) + numVisibleRows));
  38809. }
  38810. else if (key.isKeyCode (KeyPress::homeKey))
  38811. {
  38812. if (multiple && key.getModifiers().isShiftDown())
  38813. selectRangeOfRows (lastRowSelected, 0);
  38814. else
  38815. selectRow (0);
  38816. }
  38817. else if (key.isKeyCode (KeyPress::endKey))
  38818. {
  38819. if (multiple && key.getModifiers().isShiftDown())
  38820. selectRangeOfRows (lastRowSelected, totalItems - 1);
  38821. else
  38822. selectRow (totalItems - 1);
  38823. }
  38824. else if (key.isKeyCode (KeyPress::downKey))
  38825. {
  38826. if (multiple)
  38827. selectRangeOfRows (lastRowSelected, lastRowSelected + 1);
  38828. else
  38829. selectRow (jmin (totalItems - 1, jmax (0, lastRowSelected) + 1));
  38830. }
  38831. else if ((key.isKeyCode (KeyPress::deleteKey) || key.isKeyCode (KeyPress::backspaceKey))
  38832. && isRowSelected (lastRowSelected))
  38833. {
  38834. if (model != 0)
  38835. model->deleteKeyPressed (lastRowSelected);
  38836. }
  38837. else if (multiple && key == KeyPress (T('a'), ModifierKeys::commandModifier, 0))
  38838. {
  38839. selectRangeOfRows (0, INT_MAX);
  38840. }
  38841. else
  38842. {
  38843. return false;
  38844. }
  38845. return true;
  38846. }
  38847. bool ListBox::keyStateChanged (const bool isKeyDown)
  38848. {
  38849. return isKeyDown
  38850. && (KeyPress::isKeyCurrentlyDown (KeyPress::upKey)
  38851. || KeyPress::isKeyCurrentlyDown (KeyPress::pageUpKey)
  38852. || KeyPress::isKeyCurrentlyDown (KeyPress::downKey)
  38853. || KeyPress::isKeyCurrentlyDown (KeyPress::pageDownKey)
  38854. || KeyPress::isKeyCurrentlyDown (KeyPress::homeKey)
  38855. || KeyPress::isKeyCurrentlyDown (KeyPress::endKey)
  38856. || KeyPress::isKeyCurrentlyDown (KeyPress::returnKey));
  38857. }
  38858. void ListBox::mouseWheelMove (const MouseEvent& e, float wheelIncrementX, float wheelIncrementY)
  38859. {
  38860. getHorizontalScrollBar()->mouseWheelMove (e, wheelIncrementX, 0);
  38861. getVerticalScrollBar()->mouseWheelMove (e, 0, wheelIncrementY);
  38862. }
  38863. void ListBox::mouseMove (const MouseEvent& e)
  38864. {
  38865. if (mouseMoveSelects)
  38866. {
  38867. const MouseEvent e2 (e.getEventRelativeTo (this));
  38868. selectRow (getRowContainingPosition (e2.x, e2.y), true);
  38869. lastMouseX = e2.x;
  38870. lastMouseY = e2.y;
  38871. }
  38872. }
  38873. void ListBox::mouseExit (const MouseEvent& e)
  38874. {
  38875. mouseMove (e);
  38876. }
  38877. void ListBox::mouseUp (const MouseEvent& e)
  38878. {
  38879. if (e.mouseWasClicked() && model != 0)
  38880. model->backgroundClicked();
  38881. }
  38882. void ListBox::setRowHeight (const int newHeight)
  38883. {
  38884. rowHeight = jmax (1, newHeight);
  38885. viewport->setSingleStepSizes (20, rowHeight);
  38886. updateContent();
  38887. }
  38888. int ListBox::getNumRowsOnScreen() const throw()
  38889. {
  38890. return viewport->getMaximumVisibleHeight() / rowHeight;
  38891. }
  38892. void ListBox::setMinimumContentWidth (const int newMinimumWidth)
  38893. {
  38894. minimumRowWidth = newMinimumWidth;
  38895. updateContent();
  38896. }
  38897. int ListBox::getVisibleContentWidth() const throw()
  38898. {
  38899. return viewport->getMaximumVisibleWidth();
  38900. }
  38901. ScrollBar* ListBox::getVerticalScrollBar() const throw()
  38902. {
  38903. return viewport->getVerticalScrollBar();
  38904. }
  38905. ScrollBar* ListBox::getHorizontalScrollBar() const throw()
  38906. {
  38907. return viewport->getHorizontalScrollBar();
  38908. }
  38909. void ListBox::colourChanged()
  38910. {
  38911. setOpaque (findColour (backgroundColourId).isOpaque());
  38912. viewport->setOpaque (isOpaque());
  38913. repaint();
  38914. }
  38915. void ListBox::setOutlineThickness (const int outlineThickness_)
  38916. {
  38917. outlineThickness = outlineThickness_;
  38918. resized();
  38919. }
  38920. void ListBox::setHeaderComponent (Component* const newHeaderComponent)
  38921. {
  38922. if (headerComponent != newHeaderComponent)
  38923. {
  38924. delete headerComponent;
  38925. headerComponent = newHeaderComponent;
  38926. addAndMakeVisible (newHeaderComponent);
  38927. ListBox::resized();
  38928. }
  38929. }
  38930. void ListBox::repaintRow (const int rowNumber) throw()
  38931. {
  38932. const Rectangle r (getRowPosition (rowNumber, true));
  38933. repaint (r.getX(), r.getY(), r.getWidth(), r.getHeight());
  38934. }
  38935. Image* ListBox::createSnapshotOfSelectedRows (int& imageX, int& imageY)
  38936. {
  38937. Rectangle imageArea;
  38938. const int firstRow = getRowContainingPosition (0, 0);
  38939. int i;
  38940. for (i = getNumRowsOnScreen() + 2; --i >= 0;)
  38941. {
  38942. Component* rowComp = viewport->getComponentForRowIfOnscreen (firstRow + i);
  38943. if (rowComp != 0 && isRowSelected (firstRow + i))
  38944. {
  38945. int x = 0, y = 0;
  38946. rowComp->relativePositionToOtherComponent (this, x, y);
  38947. const Rectangle rowRect (x, y, rowComp->getWidth(), rowComp->getHeight());
  38948. if (imageArea.isEmpty())
  38949. imageArea = rowRect;
  38950. else
  38951. imageArea = imageArea.getUnion (rowRect);
  38952. }
  38953. }
  38954. imageArea = imageArea.getIntersection (Rectangle (0, 0, getWidth(), getHeight()));
  38955. imageX = imageArea.getX();
  38956. imageY = imageArea.getY();
  38957. Image* snapshot = Image::createNativeImage (Image::ARGB, imageArea.getWidth(), imageArea.getHeight(), true);
  38958. for (i = getNumRowsOnScreen() + 2; --i >= 0;)
  38959. {
  38960. Component* rowComp = viewport->getComponentForRowIfOnscreen (firstRow + i);
  38961. if (rowComp != 0 && isRowSelected (firstRow + i))
  38962. {
  38963. int x = 0, y = 0;
  38964. rowComp->relativePositionToOtherComponent (this, x, y);
  38965. Graphics g (*snapshot);
  38966. g.setOrigin (x - imageX, y - imageY);
  38967. if (g.reduceClipRegion (0, 0, rowComp->getWidth(), rowComp->getHeight()))
  38968. rowComp->paintEntireComponent (g);
  38969. }
  38970. }
  38971. return snapshot;
  38972. }
  38973. void ListBox::startDragAndDrop (const MouseEvent& e, const String& dragDescription)
  38974. {
  38975. DragAndDropContainer* const dragContainer
  38976. = DragAndDropContainer::findParentDragContainerFor (this);
  38977. if (dragContainer != 0)
  38978. {
  38979. int x, y;
  38980. Image* dragImage = createSnapshotOfSelectedRows (x, y);
  38981. dragImage->multiplyAllAlphas (0.6f);
  38982. MouseEvent e2 (e.getEventRelativeTo (this));
  38983. const Point p ((float) (x - e2.x), (float) (y - e2.y));
  38984. dragContainer->startDragging (dragDescription, this, dragImage, true, &p);
  38985. }
  38986. else
  38987. {
  38988. // to be able to do a drag-and-drop operation, the listbox needs to
  38989. // be inside a component which is also a DragAndDropContainer.
  38990. jassertfalse
  38991. }
  38992. }
  38993. Component* ListBoxModel::refreshComponentForRow (int, bool, Component* existingComponentToUpdate)
  38994. {
  38995. (void) existingComponentToUpdate;
  38996. jassert (existingComponentToUpdate == 0); // indicates a failure in the code the recycles the components
  38997. return 0;
  38998. }
  38999. void ListBoxModel::listBoxItemClicked (int, const MouseEvent&)
  39000. {
  39001. }
  39002. void ListBoxModel::listBoxItemDoubleClicked (int, const MouseEvent&)
  39003. {
  39004. }
  39005. void ListBoxModel::backgroundClicked()
  39006. {
  39007. }
  39008. void ListBoxModel::selectedRowsChanged (int)
  39009. {
  39010. }
  39011. void ListBoxModel::deleteKeyPressed (int)
  39012. {
  39013. }
  39014. void ListBoxModel::returnKeyPressed (int)
  39015. {
  39016. }
  39017. void ListBoxModel::listWasScrolled()
  39018. {
  39019. }
  39020. const String ListBoxModel::getDragSourceDescription (const SparseSet<int>&)
  39021. {
  39022. return String::empty;
  39023. }
  39024. const String ListBoxModel::getTooltipForRow (int)
  39025. {
  39026. return String::empty;
  39027. }
  39028. END_JUCE_NAMESPACE
  39029. /********* End of inlined file: juce_ListBox.cpp *********/
  39030. /********* Start of inlined file: juce_ProgressBar.cpp *********/
  39031. BEGIN_JUCE_NAMESPACE
  39032. ProgressBar::ProgressBar (double& progress_)
  39033. : progress (progress_),
  39034. displayPercentage (true),
  39035. lastCallbackTime (0)
  39036. {
  39037. currentValue = jlimit (0.0, 1.0, progress);
  39038. }
  39039. ProgressBar::~ProgressBar()
  39040. {
  39041. }
  39042. void ProgressBar::setPercentageDisplay (const bool shouldDisplayPercentage)
  39043. {
  39044. displayPercentage = shouldDisplayPercentage;
  39045. repaint();
  39046. }
  39047. void ProgressBar::setTextToDisplay (const String& text)
  39048. {
  39049. displayPercentage = false;
  39050. displayedMessage = text;
  39051. }
  39052. void ProgressBar::lookAndFeelChanged()
  39053. {
  39054. setOpaque (findColour (backgroundColourId).isOpaque());
  39055. }
  39056. void ProgressBar::colourChanged()
  39057. {
  39058. lookAndFeelChanged();
  39059. }
  39060. void ProgressBar::paint (Graphics& g)
  39061. {
  39062. String text;
  39063. if (displayPercentage)
  39064. {
  39065. if (currentValue >= 0 && currentValue <= 1.0)
  39066. text << roundToInt (currentValue * 100.0) << T("%");
  39067. }
  39068. else
  39069. {
  39070. text = displayedMessage;
  39071. }
  39072. getLookAndFeel().drawProgressBar (g, *this,
  39073. getWidth(), getHeight(),
  39074. currentValue, text);
  39075. }
  39076. void ProgressBar::visibilityChanged()
  39077. {
  39078. if (isVisible())
  39079. startTimer (30);
  39080. else
  39081. stopTimer();
  39082. }
  39083. void ProgressBar::timerCallback()
  39084. {
  39085. double newProgress = progress;
  39086. const uint32 now = Time::getMillisecondCounter();
  39087. const int timeSinceLastCallback = (int) (now - lastCallbackTime);
  39088. lastCallbackTime = now;
  39089. if (currentValue != newProgress
  39090. || newProgress < 0 || newProgress >= 1.0
  39091. || currentMessage != displayedMessage)
  39092. {
  39093. if (currentValue < newProgress
  39094. && newProgress >= 0 && newProgress < 1.0
  39095. && currentValue >= 0 && currentValue < 1.0)
  39096. {
  39097. newProgress = jmin (currentValue + 0.0008 * timeSinceLastCallback,
  39098. newProgress);
  39099. }
  39100. currentValue = newProgress;
  39101. currentMessage = displayedMessage;
  39102. repaint();
  39103. }
  39104. }
  39105. END_JUCE_NAMESPACE
  39106. /********* End of inlined file: juce_ProgressBar.cpp *********/
  39107. /********* Start of inlined file: juce_Slider.cpp *********/
  39108. BEGIN_JUCE_NAMESPACE
  39109. class SliderPopupDisplayComponent : public BubbleComponent
  39110. {
  39111. public:
  39112. SliderPopupDisplayComponent (Slider* const owner_)
  39113. : owner (owner_),
  39114. font (15.0f, Font::bold)
  39115. {
  39116. setAlwaysOnTop (true);
  39117. }
  39118. ~SliderPopupDisplayComponent()
  39119. {
  39120. }
  39121. void paintContent (Graphics& g, int w, int h)
  39122. {
  39123. g.setFont (font);
  39124. g.setColour (Colours::black);
  39125. g.drawFittedText (text, 0, 0, w, h, Justification::centred, 1);
  39126. }
  39127. void getContentSize (int& w, int& h)
  39128. {
  39129. w = font.getStringWidth (text) + 18;
  39130. h = (int) (font.getHeight() * 1.6f);
  39131. }
  39132. void updatePosition (const String& newText)
  39133. {
  39134. if (text != newText)
  39135. {
  39136. text = newText;
  39137. repaint();
  39138. }
  39139. BubbleComponent::setPosition (owner);
  39140. }
  39141. juce_UseDebuggingNewOperator
  39142. private:
  39143. Slider* owner;
  39144. Font font;
  39145. String text;
  39146. SliderPopupDisplayComponent (const SliderPopupDisplayComponent&);
  39147. const SliderPopupDisplayComponent& operator= (const SliderPopupDisplayComponent&);
  39148. };
  39149. Slider::Slider (const String& name)
  39150. : Component (name),
  39151. lastCurrentValue (0),
  39152. lastValueMin (0),
  39153. lastValueMax (0),
  39154. minimum (0),
  39155. maximum (10),
  39156. interval (0),
  39157. skewFactor (1.0),
  39158. velocityModeSensitivity (1.0),
  39159. velocityModeOffset (0.0),
  39160. velocityModeThreshold (1),
  39161. rotaryStart (float_Pi * 1.2f),
  39162. rotaryEnd (float_Pi * 2.8f),
  39163. numDecimalPlaces (7),
  39164. sliderRegionStart (0),
  39165. sliderRegionSize (1),
  39166. sliderBeingDragged (-1),
  39167. pixelsForFullDragExtent (250),
  39168. style (LinearHorizontal),
  39169. textBoxPos (TextBoxLeft),
  39170. textBoxWidth (80),
  39171. textBoxHeight (20),
  39172. incDecButtonMode (incDecButtonsNotDraggable),
  39173. editableText (true),
  39174. doubleClickToValue (false),
  39175. isVelocityBased (false),
  39176. userKeyOverridesVelocity (true),
  39177. rotaryStop (true),
  39178. incDecButtonsSideBySide (false),
  39179. sendChangeOnlyOnRelease (false),
  39180. popupDisplayEnabled (false),
  39181. menuEnabled (false),
  39182. menuShown (false),
  39183. scrollWheelEnabled (true),
  39184. snapsToMousePos (true),
  39185. valueBox (0),
  39186. incButton (0),
  39187. decButton (0),
  39188. popupDisplay (0),
  39189. parentForPopupDisplay (0)
  39190. {
  39191. setWantsKeyboardFocus (false);
  39192. setRepaintsOnMouseActivity (true);
  39193. lookAndFeelChanged();
  39194. updateText();
  39195. currentValue.addListener (this);
  39196. valueMin.addListener (this);
  39197. valueMax.addListener (this);
  39198. }
  39199. Slider::~Slider()
  39200. {
  39201. currentValue.removeListener (this);
  39202. valueMin.removeListener (this);
  39203. valueMax.removeListener (this);
  39204. popupDisplay = 0;
  39205. deleteAllChildren();
  39206. }
  39207. void Slider::handleAsyncUpdate()
  39208. {
  39209. cancelPendingUpdate();
  39210. for (int i = listeners.size(); --i >= 0;)
  39211. {
  39212. ((SliderListener*) listeners.getUnchecked (i))->sliderValueChanged (this);
  39213. i = jmin (i, listeners.size());
  39214. }
  39215. }
  39216. void Slider::sendDragStart()
  39217. {
  39218. startedDragging();
  39219. for (int i = listeners.size(); --i >= 0;)
  39220. {
  39221. ((SliderListener*) listeners.getUnchecked (i))->sliderDragStarted (this);
  39222. i = jmin (i, listeners.size());
  39223. }
  39224. }
  39225. void Slider::sendDragEnd()
  39226. {
  39227. stoppedDragging();
  39228. sliderBeingDragged = -1;
  39229. for (int i = listeners.size(); --i >= 0;)
  39230. {
  39231. ((SliderListener*) listeners.getUnchecked (i))->sliderDragEnded (this);
  39232. i = jmin (i, listeners.size());
  39233. }
  39234. }
  39235. void Slider::addListener (SliderListener* const listener)
  39236. {
  39237. jassert (listener != 0);
  39238. if (listener != 0)
  39239. listeners.add (listener);
  39240. }
  39241. void Slider::removeListener (SliderListener* const listener)
  39242. {
  39243. listeners.removeValue (listener);
  39244. }
  39245. void Slider::setSliderStyle (const SliderStyle newStyle)
  39246. {
  39247. if (style != newStyle)
  39248. {
  39249. style = newStyle;
  39250. repaint();
  39251. lookAndFeelChanged();
  39252. }
  39253. }
  39254. void Slider::setRotaryParameters (const float startAngleRadians,
  39255. const float endAngleRadians,
  39256. const bool stopAtEnd)
  39257. {
  39258. // make sure the values are sensible..
  39259. jassert (rotaryStart >= 0 && rotaryEnd >= 0);
  39260. jassert (rotaryStart < float_Pi * 4.0f && rotaryEnd < float_Pi * 4.0f);
  39261. jassert (rotaryStart < rotaryEnd);
  39262. rotaryStart = startAngleRadians;
  39263. rotaryEnd = endAngleRadians;
  39264. rotaryStop = stopAtEnd;
  39265. }
  39266. void Slider::setVelocityBasedMode (const bool velBased)
  39267. {
  39268. isVelocityBased = velBased;
  39269. }
  39270. void Slider::setVelocityModeParameters (const double sensitivity,
  39271. const int threshold,
  39272. const double offset,
  39273. const bool userCanPressKeyToSwapMode)
  39274. {
  39275. jassert (threshold >= 0);
  39276. jassert (sensitivity > 0);
  39277. jassert (offset >= 0);
  39278. velocityModeSensitivity = sensitivity;
  39279. velocityModeOffset = offset;
  39280. velocityModeThreshold = threshold;
  39281. userKeyOverridesVelocity = userCanPressKeyToSwapMode;
  39282. }
  39283. void Slider::setSkewFactor (const double factor)
  39284. {
  39285. skewFactor = factor;
  39286. }
  39287. void Slider::setSkewFactorFromMidPoint (const double sliderValueToShowAtMidPoint)
  39288. {
  39289. if (maximum > minimum)
  39290. skewFactor = log (0.5) / log ((sliderValueToShowAtMidPoint - minimum)
  39291. / (maximum - minimum));
  39292. }
  39293. void Slider::setMouseDragSensitivity (const int distanceForFullScaleDrag)
  39294. {
  39295. jassert (distanceForFullScaleDrag > 0);
  39296. pixelsForFullDragExtent = distanceForFullScaleDrag;
  39297. }
  39298. void Slider::setIncDecButtonsMode (const IncDecButtonMode mode)
  39299. {
  39300. if (incDecButtonMode != mode)
  39301. {
  39302. incDecButtonMode = mode;
  39303. lookAndFeelChanged();
  39304. }
  39305. }
  39306. void Slider::setTextBoxStyle (const TextEntryBoxPosition newPosition,
  39307. const bool isReadOnly,
  39308. const int textEntryBoxWidth,
  39309. const int textEntryBoxHeight)
  39310. {
  39311. textBoxPos = newPosition;
  39312. editableText = ! isReadOnly;
  39313. textBoxWidth = textEntryBoxWidth;
  39314. textBoxHeight = textEntryBoxHeight;
  39315. repaint();
  39316. lookAndFeelChanged();
  39317. }
  39318. void Slider::setTextBoxIsEditable (const bool shouldBeEditable)
  39319. {
  39320. editableText = shouldBeEditable;
  39321. if (valueBox != 0)
  39322. valueBox->setEditable (shouldBeEditable && isEnabled());
  39323. }
  39324. void Slider::showTextBox()
  39325. {
  39326. jassert (editableText); // this should probably be avoided in read-only sliders.
  39327. if (valueBox != 0)
  39328. valueBox->showEditor();
  39329. }
  39330. void Slider::hideTextBox (const bool discardCurrentEditorContents)
  39331. {
  39332. if (valueBox != 0)
  39333. {
  39334. valueBox->hideEditor (discardCurrentEditorContents);
  39335. if (discardCurrentEditorContents)
  39336. updateText();
  39337. }
  39338. }
  39339. void Slider::setChangeNotificationOnlyOnRelease (const bool onlyNotifyOnRelease)
  39340. {
  39341. sendChangeOnlyOnRelease = onlyNotifyOnRelease;
  39342. }
  39343. void Slider::setSliderSnapsToMousePosition (const bool shouldSnapToMouse)
  39344. {
  39345. snapsToMousePos = shouldSnapToMouse;
  39346. }
  39347. void Slider::setPopupDisplayEnabled (const bool enabled,
  39348. Component* const parentComponentToUse)
  39349. {
  39350. popupDisplayEnabled = enabled;
  39351. parentForPopupDisplay = parentComponentToUse;
  39352. }
  39353. void Slider::colourChanged()
  39354. {
  39355. lookAndFeelChanged();
  39356. }
  39357. void Slider::lookAndFeelChanged()
  39358. {
  39359. const String previousTextBoxContent (valueBox != 0 ? valueBox->getText()
  39360. : getTextFromValue (currentValue.getValue()));
  39361. deleteAllChildren();
  39362. valueBox = 0;
  39363. LookAndFeel& lf = getLookAndFeel();
  39364. if (textBoxPos != NoTextBox)
  39365. {
  39366. addAndMakeVisible (valueBox = getLookAndFeel().createSliderTextBox (*this));
  39367. valueBox->setWantsKeyboardFocus (false);
  39368. valueBox->setText (previousTextBoxContent, false);
  39369. valueBox->setEditable (editableText && isEnabled());
  39370. valueBox->addListener (this);
  39371. if (style == LinearBar)
  39372. valueBox->addMouseListener (this, false);
  39373. valueBox->setTooltip (getTooltip());
  39374. }
  39375. if (style == IncDecButtons)
  39376. {
  39377. addAndMakeVisible (incButton = lf.createSliderButton (true));
  39378. incButton->addButtonListener (this);
  39379. addAndMakeVisible (decButton = lf.createSliderButton (false));
  39380. decButton->addButtonListener (this);
  39381. if (incDecButtonMode != incDecButtonsNotDraggable)
  39382. {
  39383. incButton->addMouseListener (this, false);
  39384. decButton->addMouseListener (this, false);
  39385. }
  39386. else
  39387. {
  39388. incButton->setRepeatSpeed (300, 100, 20);
  39389. incButton->addMouseListener (decButton, false);
  39390. decButton->setRepeatSpeed (300, 100, 20);
  39391. decButton->addMouseListener (incButton, false);
  39392. }
  39393. incButton->setTooltip (getTooltip());
  39394. decButton->setTooltip (getTooltip());
  39395. }
  39396. setComponentEffect (lf.getSliderEffect());
  39397. resized();
  39398. repaint();
  39399. }
  39400. void Slider::setRange (const double newMin,
  39401. const double newMax,
  39402. const double newInt)
  39403. {
  39404. if (minimum != newMin
  39405. || maximum != newMax
  39406. || interval != newInt)
  39407. {
  39408. minimum = newMin;
  39409. maximum = newMax;
  39410. interval = newInt;
  39411. // figure out the number of DPs needed to display all values at this
  39412. // interval setting.
  39413. numDecimalPlaces = 7;
  39414. if (newInt != 0)
  39415. {
  39416. int v = abs ((int) (newInt * 10000000));
  39417. while ((v % 10) == 0)
  39418. {
  39419. --numDecimalPlaces;
  39420. v /= 10;
  39421. }
  39422. }
  39423. // keep the current values inside the new range..
  39424. if (style != TwoValueHorizontal && style != TwoValueVertical)
  39425. {
  39426. setValue (getValue(), false, false);
  39427. }
  39428. else
  39429. {
  39430. setMinValue (getMinValue(), false, false);
  39431. setMaxValue (getMaxValue(), false, false);
  39432. }
  39433. updateText();
  39434. }
  39435. }
  39436. void Slider::triggerChangeMessage (const bool synchronous)
  39437. {
  39438. if (synchronous)
  39439. handleAsyncUpdate();
  39440. else
  39441. triggerAsyncUpdate();
  39442. valueChanged();
  39443. }
  39444. void Slider::valueChanged (Value& value)
  39445. {
  39446. if (value.refersToSameSourceAs (currentValue))
  39447. {
  39448. if (style != TwoValueHorizontal && style != TwoValueVertical)
  39449. setValue (currentValue.getValue(), false, false);
  39450. }
  39451. else if (value.refersToSameSourceAs (valueMin))
  39452. setMinValue (valueMin.getValue(), false, false, true);
  39453. else if (value.refersToSameSourceAs (valueMax))
  39454. setMaxValue (valueMax.getValue(), false, false, true);
  39455. }
  39456. double Slider::getValue() const
  39457. {
  39458. // for a two-value style slider, you should use the getMinValue() and getMaxValue()
  39459. // methods to get the two values.
  39460. jassert (style != TwoValueHorizontal && style != TwoValueVertical);
  39461. return currentValue.getValue();
  39462. }
  39463. void Slider::setValue (double newValue,
  39464. const bool sendUpdateMessage,
  39465. const bool sendMessageSynchronously)
  39466. {
  39467. // for a two-value style slider, you should use the setMinValue() and setMaxValue()
  39468. // methods to set the two values.
  39469. jassert (style != TwoValueHorizontal && style != TwoValueVertical);
  39470. newValue = constrainedValue (newValue);
  39471. if (style == ThreeValueHorizontal || style == ThreeValueVertical)
  39472. {
  39473. jassert ((double) valueMin.getValue() <= (double) valueMax.getValue());
  39474. newValue = jlimit ((double) valueMin.getValue(),
  39475. (double) valueMax.getValue(),
  39476. newValue);
  39477. }
  39478. if (newValue != lastCurrentValue)
  39479. {
  39480. if (valueBox != 0)
  39481. valueBox->hideEditor (true);
  39482. lastCurrentValue = newValue;
  39483. currentValue = newValue;
  39484. updateText();
  39485. repaint();
  39486. if (popupDisplay != 0)
  39487. {
  39488. ((SliderPopupDisplayComponent*) popupDisplay)->updatePosition (getTextFromValue (newValue));
  39489. popupDisplay->repaint();
  39490. }
  39491. if (sendUpdateMessage)
  39492. triggerChangeMessage (sendMessageSynchronously);
  39493. }
  39494. }
  39495. double Slider::getMinValue() const
  39496. {
  39497. // The minimum value only applies to sliders that are in two- or three-value mode.
  39498. jassert (style == TwoValueHorizontal || style == TwoValueVertical
  39499. || style == ThreeValueHorizontal || style == ThreeValueVertical);
  39500. return valueMin.getValue();
  39501. }
  39502. double Slider::getMaxValue() const
  39503. {
  39504. // The maximum value only applies to sliders that are in two- or three-value mode.
  39505. jassert (style == TwoValueHorizontal || style == TwoValueVertical
  39506. || style == ThreeValueHorizontal || style == ThreeValueVertical);
  39507. return valueMax.getValue();
  39508. }
  39509. void Slider::setMinValue (double newValue, const bool sendUpdateMessage, const bool sendMessageSynchronously, const bool allowNudgingOfOtherValues)
  39510. {
  39511. // The minimum value only applies to sliders that are in two- or three-value mode.
  39512. jassert (style == TwoValueHorizontal || style == TwoValueVertical
  39513. || style == ThreeValueHorizontal || style == ThreeValueVertical);
  39514. newValue = constrainedValue (newValue);
  39515. if (style == TwoValueHorizontal || style == TwoValueVertical)
  39516. {
  39517. if (allowNudgingOfOtherValues && newValue > (double) valueMax.getValue())
  39518. setMaxValue (newValue, sendUpdateMessage, sendMessageSynchronously);
  39519. newValue = jmin ((double) valueMax.getValue(), newValue);
  39520. }
  39521. else
  39522. {
  39523. if (allowNudgingOfOtherValues && newValue > lastCurrentValue)
  39524. setValue (newValue, sendUpdateMessage, sendMessageSynchronously);
  39525. newValue = jmin (lastCurrentValue, newValue);
  39526. }
  39527. if (lastValueMin != newValue)
  39528. {
  39529. lastValueMin = newValue;
  39530. valueMin = newValue;
  39531. repaint();
  39532. if (popupDisplay != 0)
  39533. {
  39534. ((SliderPopupDisplayComponent*) popupDisplay)->updatePosition (getTextFromValue (newValue));
  39535. popupDisplay->repaint();
  39536. }
  39537. if (sendUpdateMessage)
  39538. triggerChangeMessage (sendMessageSynchronously);
  39539. }
  39540. }
  39541. void Slider::setMaxValue (double newValue, const bool sendUpdateMessage, const bool sendMessageSynchronously, const bool allowNudgingOfOtherValues)
  39542. {
  39543. // The maximum value only applies to sliders that are in two- or three-value mode.
  39544. jassert (style == TwoValueHorizontal || style == TwoValueVertical
  39545. || style == ThreeValueHorizontal || style == ThreeValueVertical);
  39546. newValue = constrainedValue (newValue);
  39547. if (style == TwoValueHorizontal || style == TwoValueVertical)
  39548. {
  39549. if (allowNudgingOfOtherValues && newValue < (double) valueMin.getValue())
  39550. setMinValue (newValue, sendUpdateMessage, sendMessageSynchronously);
  39551. newValue = jmax ((double) valueMin.getValue(), newValue);
  39552. }
  39553. else
  39554. {
  39555. if (allowNudgingOfOtherValues && newValue < lastCurrentValue)
  39556. setValue (newValue, sendUpdateMessage, sendMessageSynchronously);
  39557. newValue = jmax (lastCurrentValue, newValue);
  39558. }
  39559. if (lastValueMax != newValue)
  39560. {
  39561. lastValueMax = newValue;
  39562. valueMax = newValue;
  39563. repaint();
  39564. if (popupDisplay != 0)
  39565. {
  39566. ((SliderPopupDisplayComponent*) popupDisplay)->updatePosition (getTextFromValue (valueMax.getValue()));
  39567. popupDisplay->repaint();
  39568. }
  39569. if (sendUpdateMessage)
  39570. triggerChangeMessage (sendMessageSynchronously);
  39571. }
  39572. }
  39573. void Slider::setDoubleClickReturnValue (const bool isDoubleClickEnabled,
  39574. const double valueToSetOnDoubleClick)
  39575. {
  39576. doubleClickToValue = isDoubleClickEnabled;
  39577. doubleClickReturnValue = valueToSetOnDoubleClick;
  39578. }
  39579. double Slider::getDoubleClickReturnValue (bool& isEnabled_) const
  39580. {
  39581. isEnabled_ = doubleClickToValue;
  39582. return doubleClickReturnValue;
  39583. }
  39584. void Slider::updateText()
  39585. {
  39586. if (valueBox != 0)
  39587. valueBox->setText (getTextFromValue (currentValue.getValue()), false);
  39588. }
  39589. void Slider::setTextValueSuffix (const String& suffix)
  39590. {
  39591. if (textSuffix != suffix)
  39592. {
  39593. textSuffix = suffix;
  39594. updateText();
  39595. }
  39596. }
  39597. const String Slider::getTextFromValue (double v)
  39598. {
  39599. if (numDecimalPlaces > 0)
  39600. return String (v, numDecimalPlaces) + textSuffix;
  39601. else
  39602. return String (roundToInt (v)) + textSuffix;
  39603. }
  39604. double Slider::getValueFromText (const String& text)
  39605. {
  39606. String t (text.trimStart());
  39607. if (t.endsWith (textSuffix))
  39608. t = t.substring (0, t.length() - textSuffix.length());
  39609. while (t.startsWithChar (T('+')))
  39610. t = t.substring (1).trimStart();
  39611. return t.initialSectionContainingOnly (T("0123456789.,-"))
  39612. .getDoubleValue();
  39613. }
  39614. double Slider::proportionOfLengthToValue (double proportion)
  39615. {
  39616. if (skewFactor != 1.0 && proportion > 0.0)
  39617. proportion = exp (log (proportion) / skewFactor);
  39618. return minimum + (maximum - minimum) * proportion;
  39619. }
  39620. double Slider::valueToProportionOfLength (double value)
  39621. {
  39622. const double n = (value - minimum) / (maximum - minimum);
  39623. return skewFactor == 1.0 ? n : pow (n, skewFactor);
  39624. }
  39625. double Slider::snapValue (double attemptedValue, const bool)
  39626. {
  39627. return attemptedValue;
  39628. }
  39629. void Slider::startedDragging()
  39630. {
  39631. }
  39632. void Slider::stoppedDragging()
  39633. {
  39634. }
  39635. void Slider::valueChanged()
  39636. {
  39637. }
  39638. void Slider::enablementChanged()
  39639. {
  39640. repaint();
  39641. }
  39642. void Slider::setPopupMenuEnabled (const bool menuEnabled_)
  39643. {
  39644. menuEnabled = menuEnabled_;
  39645. }
  39646. void Slider::setScrollWheelEnabled (const bool enabled)
  39647. {
  39648. scrollWheelEnabled = enabled;
  39649. }
  39650. void Slider::labelTextChanged (Label* label)
  39651. {
  39652. const double newValue = snapValue (getValueFromText (label->getText()), false);
  39653. if (newValue != (double) currentValue.getValue())
  39654. {
  39655. sendDragStart();
  39656. setValue (newValue, true, true);
  39657. sendDragEnd();
  39658. }
  39659. updateText(); // force a clean-up of the text, needed in case setValue() hasn't done this.
  39660. }
  39661. void Slider::buttonClicked (Button* button)
  39662. {
  39663. if (style == IncDecButtons)
  39664. {
  39665. sendDragStart();
  39666. if (button == incButton)
  39667. setValue (snapValue (getValue() + interval, false), true, true);
  39668. else if (button == decButton)
  39669. setValue (snapValue (getValue() - interval, false), true, true);
  39670. sendDragEnd();
  39671. }
  39672. }
  39673. double Slider::constrainedValue (double value) const
  39674. {
  39675. if (interval > 0)
  39676. value = minimum + interval * floor ((value - minimum) / interval + 0.5);
  39677. if (value <= minimum || maximum <= minimum)
  39678. value = minimum;
  39679. else if (value >= maximum)
  39680. value = maximum;
  39681. return value;
  39682. }
  39683. float Slider::getLinearSliderPos (const double value)
  39684. {
  39685. double sliderPosProportional;
  39686. if (maximum > minimum)
  39687. {
  39688. if (value < minimum)
  39689. {
  39690. sliderPosProportional = 0.0;
  39691. }
  39692. else if (value > maximum)
  39693. {
  39694. sliderPosProportional = 1.0;
  39695. }
  39696. else
  39697. {
  39698. sliderPosProportional = valueToProportionOfLength (value);
  39699. jassert (sliderPosProportional >= 0 && sliderPosProportional <= 1.0);
  39700. }
  39701. }
  39702. else
  39703. {
  39704. sliderPosProportional = 0.5;
  39705. }
  39706. if (isVertical() || style == IncDecButtons)
  39707. sliderPosProportional = 1.0 - sliderPosProportional;
  39708. return (float) (sliderRegionStart + sliderPosProportional * sliderRegionSize);
  39709. }
  39710. bool Slider::isHorizontal() const
  39711. {
  39712. return style == LinearHorizontal
  39713. || style == LinearBar
  39714. || style == TwoValueHorizontal
  39715. || style == ThreeValueHorizontal;
  39716. }
  39717. bool Slider::isVertical() const
  39718. {
  39719. return style == LinearVertical
  39720. || style == TwoValueVertical
  39721. || style == ThreeValueVertical;
  39722. }
  39723. bool Slider::incDecDragDirectionIsHorizontal() const
  39724. {
  39725. return incDecButtonMode == incDecButtonsDraggable_Horizontal
  39726. || (incDecButtonMode == incDecButtonsDraggable_AutoDirection && incDecButtonsSideBySide);
  39727. }
  39728. float Slider::getPositionOfValue (const double value)
  39729. {
  39730. if (isHorizontal() || isVertical())
  39731. {
  39732. return getLinearSliderPos (value);
  39733. }
  39734. else
  39735. {
  39736. jassertfalse // not a valid call on a slider that doesn't work linearly!
  39737. return 0.0f;
  39738. }
  39739. }
  39740. void Slider::paint (Graphics& g)
  39741. {
  39742. if (style != IncDecButtons)
  39743. {
  39744. if (style == Rotary || style == RotaryHorizontalDrag || style == RotaryVerticalDrag)
  39745. {
  39746. const float sliderPos = (float) valueToProportionOfLength (lastCurrentValue);
  39747. jassert (sliderPos >= 0 && sliderPos <= 1.0f);
  39748. getLookAndFeel().drawRotarySlider (g,
  39749. sliderRect.getX(),
  39750. sliderRect.getY(),
  39751. sliderRect.getWidth(),
  39752. sliderRect.getHeight(),
  39753. sliderPos,
  39754. rotaryStart, rotaryEnd,
  39755. *this);
  39756. }
  39757. else
  39758. {
  39759. getLookAndFeel().drawLinearSlider (g,
  39760. sliderRect.getX(),
  39761. sliderRect.getY(),
  39762. sliderRect.getWidth(),
  39763. sliderRect.getHeight(),
  39764. getLinearSliderPos (lastCurrentValue),
  39765. getLinearSliderPos (lastValueMin),
  39766. getLinearSliderPos (lastValueMax),
  39767. style,
  39768. *this);
  39769. }
  39770. if (style == LinearBar && valueBox == 0)
  39771. {
  39772. g.setColour (findColour (Slider::textBoxOutlineColourId));
  39773. g.drawRect (0, 0, getWidth(), getHeight(), 1);
  39774. }
  39775. }
  39776. }
  39777. void Slider::resized()
  39778. {
  39779. int minXSpace = 0;
  39780. int minYSpace = 0;
  39781. if (textBoxPos == TextBoxLeft || textBoxPos == TextBoxRight)
  39782. minXSpace = 30;
  39783. else
  39784. minYSpace = 15;
  39785. const int tbw = jmax (0, jmin (textBoxWidth, getWidth() - minXSpace));
  39786. const int tbh = jmax (0, jmin (textBoxHeight, getHeight() - minYSpace));
  39787. if (style == LinearBar)
  39788. {
  39789. if (valueBox != 0)
  39790. valueBox->setBounds (0, 0, getWidth(), getHeight());
  39791. }
  39792. else
  39793. {
  39794. if (textBoxPos == NoTextBox)
  39795. {
  39796. sliderRect.setBounds (0, 0, getWidth(), getHeight());
  39797. }
  39798. else if (textBoxPos == TextBoxLeft)
  39799. {
  39800. valueBox->setBounds (0, (getHeight() - tbh) / 2, tbw, tbh);
  39801. sliderRect.setBounds (tbw, 0, getWidth() - tbw, getHeight());
  39802. }
  39803. else if (textBoxPos == TextBoxRight)
  39804. {
  39805. valueBox->setBounds (getWidth() - tbw, (getHeight() - tbh) / 2, tbw, tbh);
  39806. sliderRect.setBounds (0, 0, getWidth() - tbw, getHeight());
  39807. }
  39808. else if (textBoxPos == TextBoxAbove)
  39809. {
  39810. valueBox->setBounds ((getWidth() - tbw) / 2, 0, tbw, tbh);
  39811. sliderRect.setBounds (0, tbh, getWidth(), getHeight() - tbh);
  39812. }
  39813. else if (textBoxPos == TextBoxBelow)
  39814. {
  39815. valueBox->setBounds ((getWidth() - tbw) / 2, getHeight() - tbh, tbw, tbh);
  39816. sliderRect.setBounds (0, 0, getWidth(), getHeight() - tbh);
  39817. }
  39818. }
  39819. const int indent = getLookAndFeel().getSliderThumbRadius (*this);
  39820. if (style == LinearBar)
  39821. {
  39822. const int barIndent = 1;
  39823. sliderRegionStart = barIndent;
  39824. sliderRegionSize = getWidth() - barIndent * 2;
  39825. sliderRect.setBounds (sliderRegionStart, barIndent,
  39826. sliderRegionSize, getHeight() - barIndent * 2);
  39827. }
  39828. else if (isHorizontal())
  39829. {
  39830. sliderRegionStart = sliderRect.getX() + indent;
  39831. sliderRegionSize = jmax (1, sliderRect.getWidth() - indent * 2);
  39832. sliderRect.setBounds (sliderRegionStart, sliderRect.getY(),
  39833. sliderRegionSize, sliderRect.getHeight());
  39834. }
  39835. else if (isVertical())
  39836. {
  39837. sliderRegionStart = sliderRect.getY() + indent;
  39838. sliderRegionSize = jmax (1, sliderRect.getHeight() - indent * 2);
  39839. sliderRect.setBounds (sliderRect.getX(), sliderRegionStart,
  39840. sliderRect.getWidth(), sliderRegionSize);
  39841. }
  39842. else
  39843. {
  39844. sliderRegionStart = 0;
  39845. sliderRegionSize = 100;
  39846. }
  39847. if (style == IncDecButtons)
  39848. {
  39849. Rectangle buttonRect (sliderRect);
  39850. if (textBoxPos == TextBoxLeft || textBoxPos == TextBoxRight)
  39851. buttonRect.expand (-2, 0);
  39852. else
  39853. buttonRect.expand (0, -2);
  39854. incDecButtonsSideBySide = buttonRect.getWidth() > buttonRect.getHeight();
  39855. if (incDecButtonsSideBySide)
  39856. {
  39857. decButton->setBounds (buttonRect.getX(),
  39858. buttonRect.getY(),
  39859. buttonRect.getWidth() / 2,
  39860. buttonRect.getHeight());
  39861. decButton->setConnectedEdges (Button::ConnectedOnRight);
  39862. incButton->setBounds (buttonRect.getCentreX(),
  39863. buttonRect.getY(),
  39864. buttonRect.getWidth() / 2,
  39865. buttonRect.getHeight());
  39866. incButton->setConnectedEdges (Button::ConnectedOnLeft);
  39867. }
  39868. else
  39869. {
  39870. incButton->setBounds (buttonRect.getX(),
  39871. buttonRect.getY(),
  39872. buttonRect.getWidth(),
  39873. buttonRect.getHeight() / 2);
  39874. incButton->setConnectedEdges (Button::ConnectedOnBottom);
  39875. decButton->setBounds (buttonRect.getX(),
  39876. buttonRect.getCentreY(),
  39877. buttonRect.getWidth(),
  39878. buttonRect.getHeight() / 2);
  39879. decButton->setConnectedEdges (Button::ConnectedOnTop);
  39880. }
  39881. }
  39882. }
  39883. void Slider::focusOfChildComponentChanged (FocusChangeType)
  39884. {
  39885. repaint();
  39886. }
  39887. void Slider::mouseDown (const MouseEvent& e)
  39888. {
  39889. mouseWasHidden = false;
  39890. incDecDragged = false;
  39891. mouseXWhenLastDragged = e.x;
  39892. mouseYWhenLastDragged = e.y;
  39893. mouseDragStartX = e.getMouseDownX();
  39894. mouseDragStartY = e.getMouseDownY();
  39895. if (isEnabled())
  39896. {
  39897. if (e.mods.isPopupMenu() && menuEnabled)
  39898. {
  39899. menuShown = true;
  39900. PopupMenu m;
  39901. m.setLookAndFeel (&getLookAndFeel());
  39902. m.addItem (1, TRANS ("velocity-sensitive mode"), true, isVelocityBased);
  39903. m.addSeparator();
  39904. if (style == Rotary || style == RotaryHorizontalDrag || style == RotaryVerticalDrag)
  39905. {
  39906. PopupMenu rotaryMenu;
  39907. rotaryMenu.addItem (2, TRANS ("use circular dragging"), true, style == Rotary);
  39908. rotaryMenu.addItem (3, TRANS ("use left-right dragging"), true, style == RotaryHorizontalDrag);
  39909. rotaryMenu.addItem (4, TRANS ("use up-down dragging"), true, style == RotaryVerticalDrag);
  39910. m.addSubMenu (TRANS ("rotary mode"), rotaryMenu);
  39911. }
  39912. const int r = m.show();
  39913. if (r == 1)
  39914. {
  39915. setVelocityBasedMode (! isVelocityBased);
  39916. }
  39917. else if (r == 2)
  39918. {
  39919. setSliderStyle (Rotary);
  39920. }
  39921. else if (r == 3)
  39922. {
  39923. setSliderStyle (RotaryHorizontalDrag);
  39924. }
  39925. else if (r == 4)
  39926. {
  39927. setSliderStyle (RotaryVerticalDrag);
  39928. }
  39929. }
  39930. else if (maximum > minimum)
  39931. {
  39932. menuShown = false;
  39933. if (valueBox != 0)
  39934. valueBox->hideEditor (true);
  39935. sliderBeingDragged = 0;
  39936. if (style == TwoValueHorizontal
  39937. || style == TwoValueVertical
  39938. || style == ThreeValueHorizontal
  39939. || style == ThreeValueVertical)
  39940. {
  39941. const float mousePos = (float) (isVertical() ? e.y : e.x);
  39942. const float normalPosDistance = fabsf (getLinearSliderPos (currentValue.getValue()) - mousePos);
  39943. const float minPosDistance = fabsf (getLinearSliderPos (valueMin.getValue()) - 0.1f - mousePos);
  39944. const float maxPosDistance = fabsf (getLinearSliderPos (valueMax.getValue()) + 0.1f - mousePos);
  39945. if (style == TwoValueHorizontal || style == TwoValueVertical)
  39946. {
  39947. if (maxPosDistance <= minPosDistance)
  39948. sliderBeingDragged = 2;
  39949. else
  39950. sliderBeingDragged = 1;
  39951. }
  39952. else if (style == ThreeValueHorizontal || style == ThreeValueVertical)
  39953. {
  39954. if (normalPosDistance >= minPosDistance && maxPosDistance >= minPosDistance)
  39955. sliderBeingDragged = 1;
  39956. else if (normalPosDistance >= maxPosDistance)
  39957. sliderBeingDragged = 2;
  39958. }
  39959. }
  39960. minMaxDiff = (double) valueMax.getValue() - (double) valueMin.getValue();
  39961. lastAngle = rotaryStart + (rotaryEnd - rotaryStart)
  39962. * valueToProportionOfLength (currentValue.getValue());
  39963. valueWhenLastDragged = ((sliderBeingDragged == 2) ? valueMax
  39964. : ((sliderBeingDragged == 1) ? valueMin
  39965. : currentValue)).getValue();
  39966. valueOnMouseDown = valueWhenLastDragged;
  39967. if (popupDisplayEnabled)
  39968. {
  39969. SliderPopupDisplayComponent* const popup = new SliderPopupDisplayComponent (this);
  39970. popupDisplay = popup;
  39971. if (parentForPopupDisplay != 0)
  39972. {
  39973. parentForPopupDisplay->addChildComponent (popup);
  39974. }
  39975. else
  39976. {
  39977. popup->addToDesktop (0);
  39978. }
  39979. popup->setVisible (true);
  39980. }
  39981. sendDragStart();
  39982. mouseDrag (e);
  39983. }
  39984. }
  39985. }
  39986. void Slider::mouseUp (const MouseEvent&)
  39987. {
  39988. if (isEnabled()
  39989. && (! menuShown)
  39990. && (maximum > minimum)
  39991. && (style != IncDecButtons || incDecDragged))
  39992. {
  39993. restoreMouseIfHidden();
  39994. if (sendChangeOnlyOnRelease && valueOnMouseDown != (double) currentValue.getValue())
  39995. triggerChangeMessage (false);
  39996. sendDragEnd();
  39997. popupDisplay = 0;
  39998. if (style == IncDecButtons)
  39999. {
  40000. incButton->setState (Button::buttonNormal);
  40001. decButton->setState (Button::buttonNormal);
  40002. }
  40003. }
  40004. }
  40005. void Slider::restoreMouseIfHidden()
  40006. {
  40007. if (mouseWasHidden)
  40008. {
  40009. mouseWasHidden = false;
  40010. Component* c = Component::getComponentUnderMouse();
  40011. if (c == 0)
  40012. c = this;
  40013. c->enableUnboundedMouseMovement (false);
  40014. const double pos = (sliderBeingDragged == 2) ? getMaxValue()
  40015. : ((sliderBeingDragged == 1) ? getMinValue()
  40016. : (double) currentValue.getValue());
  40017. if (style == RotaryHorizontalDrag || style == RotaryVerticalDrag)
  40018. {
  40019. int x, y, downX, downY;
  40020. Desktop::getMousePosition (x, y);
  40021. Desktop::getLastMouseDownPosition (downX, downY);
  40022. if (style == RotaryHorizontalDrag)
  40023. {
  40024. const double posDiff = valueToProportionOfLength (pos) - valueToProportionOfLength (valueOnMouseDown);
  40025. x = roundToInt (pixelsForFullDragExtent * posDiff + downX);
  40026. y = downY;
  40027. }
  40028. else
  40029. {
  40030. const double posDiff = valueToProportionOfLength (valueOnMouseDown) - valueToProportionOfLength (pos);
  40031. x = downX;
  40032. y = roundToInt (pixelsForFullDragExtent * posDiff + downY);
  40033. }
  40034. Desktop::setMousePosition (x, y);
  40035. }
  40036. else
  40037. {
  40038. const int pixelPos = (int) getLinearSliderPos (pos);
  40039. int x = isHorizontal() ? pixelPos : (getWidth() / 2);
  40040. int y = isVertical() ? pixelPos : (getHeight() / 2);
  40041. relativePositionToGlobal (x, y);
  40042. Desktop::setMousePosition (x, y);
  40043. }
  40044. }
  40045. }
  40046. void Slider::modifierKeysChanged (const ModifierKeys& modifiers)
  40047. {
  40048. if (isEnabled()
  40049. && style != IncDecButtons
  40050. && style != Rotary
  40051. && isVelocityBased == modifiers.isAnyModifierKeyDown())
  40052. {
  40053. restoreMouseIfHidden();
  40054. }
  40055. }
  40056. static double smallestAngleBetween (double a1, double a2)
  40057. {
  40058. return jmin (fabs (a1 - a2),
  40059. fabs (a1 + double_Pi * 2.0 - a2),
  40060. fabs (a2 + double_Pi * 2.0 - a1));
  40061. }
  40062. void Slider::mouseDrag (const MouseEvent& e)
  40063. {
  40064. if (isEnabled()
  40065. && (! menuShown)
  40066. && (maximum > minimum))
  40067. {
  40068. if (style == Rotary)
  40069. {
  40070. int dx = e.x - sliderRect.getCentreX();
  40071. int dy = e.y - sliderRect.getCentreY();
  40072. if (dx * dx + dy * dy > 25)
  40073. {
  40074. double angle = atan2 ((double) dx, (double) -dy);
  40075. while (angle < 0.0)
  40076. angle += double_Pi * 2.0;
  40077. if (rotaryStop && ! e.mouseWasClicked())
  40078. {
  40079. if (fabs (angle - lastAngle) > double_Pi)
  40080. {
  40081. if (angle >= lastAngle)
  40082. angle -= double_Pi * 2.0;
  40083. else
  40084. angle += double_Pi * 2.0;
  40085. }
  40086. if (angle >= lastAngle)
  40087. angle = jmin (angle, (double) jmax (rotaryStart, rotaryEnd));
  40088. else
  40089. angle = jmax (angle, (double) jmin (rotaryStart, rotaryEnd));
  40090. }
  40091. else
  40092. {
  40093. while (angle < rotaryStart)
  40094. angle += double_Pi * 2.0;
  40095. if (angle > rotaryEnd)
  40096. {
  40097. if (smallestAngleBetween (angle, rotaryStart) <= smallestAngleBetween (angle, rotaryEnd))
  40098. angle = rotaryStart;
  40099. else
  40100. angle = rotaryEnd;
  40101. }
  40102. }
  40103. const double proportion = (angle - rotaryStart) / (rotaryEnd - rotaryStart);
  40104. valueWhenLastDragged = proportionOfLengthToValue (jlimit (0.0, 1.0, proportion));
  40105. lastAngle = angle;
  40106. }
  40107. }
  40108. else
  40109. {
  40110. if (style == LinearBar && e.mouseWasClicked()
  40111. && valueBox != 0 && valueBox->isEditable())
  40112. return;
  40113. if (style == IncDecButtons && ! incDecDragged)
  40114. {
  40115. if (e.getDistanceFromDragStart() < 10 || e.mouseWasClicked())
  40116. return;
  40117. incDecDragged = true;
  40118. mouseDragStartX = e.x;
  40119. mouseDragStartY = e.y;
  40120. }
  40121. if ((isVelocityBased == (userKeyOverridesVelocity ? e.mods.testFlags (ModifierKeys::ctrlModifier | ModifierKeys::commandModifier | ModifierKeys::altModifier)
  40122. : false))
  40123. || ((maximum - minimum) / sliderRegionSize < interval))
  40124. {
  40125. const int mousePos = (isHorizontal() || style == RotaryHorizontalDrag) ? e.x : e.y;
  40126. double scaledMousePos = (mousePos - sliderRegionStart) / (double) sliderRegionSize;
  40127. if (style == RotaryHorizontalDrag
  40128. || style == RotaryVerticalDrag
  40129. || style == IncDecButtons
  40130. || ((style == LinearHorizontal || style == LinearVertical || style == LinearBar)
  40131. && ! snapsToMousePos))
  40132. {
  40133. const int mouseDiff = (style == RotaryHorizontalDrag
  40134. || style == LinearHorizontal
  40135. || style == LinearBar
  40136. || (style == IncDecButtons && incDecDragDirectionIsHorizontal()))
  40137. ? e.x - mouseDragStartX
  40138. : mouseDragStartY - e.y;
  40139. double newPos = valueToProportionOfLength (valueOnMouseDown)
  40140. + mouseDiff * (1.0 / pixelsForFullDragExtent);
  40141. valueWhenLastDragged = proportionOfLengthToValue (jlimit (0.0, 1.0, newPos));
  40142. if (style == IncDecButtons)
  40143. {
  40144. incButton->setState (mouseDiff < 0 ? Button::buttonNormal : Button::buttonDown);
  40145. decButton->setState (mouseDiff > 0 ? Button::buttonNormal : Button::buttonDown);
  40146. }
  40147. }
  40148. else
  40149. {
  40150. if (isVertical())
  40151. scaledMousePos = 1.0 - scaledMousePos;
  40152. valueWhenLastDragged = proportionOfLengthToValue (jlimit (0.0, 1.0, scaledMousePos));
  40153. }
  40154. }
  40155. else
  40156. {
  40157. const int mouseDiff = (isHorizontal() || style == RotaryHorizontalDrag
  40158. || (style == IncDecButtons && incDecDragDirectionIsHorizontal()))
  40159. ? e.x - mouseXWhenLastDragged
  40160. : e.y - mouseYWhenLastDragged;
  40161. const double maxSpeed = jmax (200, sliderRegionSize);
  40162. double speed = jlimit (0.0, maxSpeed, (double) abs (mouseDiff));
  40163. if (speed != 0)
  40164. {
  40165. speed = 0.2 * velocityModeSensitivity
  40166. * (1.0 + sin (double_Pi * (1.5 + jmin (0.5, velocityModeOffset
  40167. + jmax (0.0, (double) (speed - velocityModeThreshold))
  40168. / maxSpeed))));
  40169. if (mouseDiff < 0)
  40170. speed = -speed;
  40171. if (isVertical() || style == RotaryVerticalDrag
  40172. || (style == IncDecButtons && ! incDecDragDirectionIsHorizontal()))
  40173. speed = -speed;
  40174. const double currentPos = valueToProportionOfLength (valueWhenLastDragged);
  40175. valueWhenLastDragged = proportionOfLengthToValue (jlimit (0.0, 1.0, currentPos + speed));
  40176. e.originalComponent->enableUnboundedMouseMovement (true, false);
  40177. mouseWasHidden = true;
  40178. }
  40179. }
  40180. }
  40181. valueWhenLastDragged = jlimit (minimum, maximum, valueWhenLastDragged);
  40182. if (sliderBeingDragged == 0)
  40183. {
  40184. setValue (snapValue (valueWhenLastDragged, true),
  40185. ! sendChangeOnlyOnRelease, true);
  40186. }
  40187. else if (sliderBeingDragged == 1)
  40188. {
  40189. setMinValue (snapValue (valueWhenLastDragged, true),
  40190. ! sendChangeOnlyOnRelease, false, true);
  40191. if (e.mods.isShiftDown())
  40192. setMaxValue (getMinValue() + minMaxDiff, false, false, true);
  40193. else
  40194. minMaxDiff = (double) valueMax.getValue() - (double) valueMin.getValue();
  40195. }
  40196. else
  40197. {
  40198. jassert (sliderBeingDragged == 2);
  40199. setMaxValue (snapValue (valueWhenLastDragged, true),
  40200. ! sendChangeOnlyOnRelease, false, true);
  40201. if (e.mods.isShiftDown())
  40202. setMinValue (getMaxValue() - minMaxDiff, false, false, true);
  40203. else
  40204. minMaxDiff = (double) valueMax.getValue() - (double) valueMin.getValue();
  40205. }
  40206. mouseXWhenLastDragged = e.x;
  40207. mouseYWhenLastDragged = e.y;
  40208. }
  40209. }
  40210. void Slider::mouseDoubleClick (const MouseEvent&)
  40211. {
  40212. if (doubleClickToValue
  40213. && isEnabled()
  40214. && style != IncDecButtons
  40215. && minimum <= doubleClickReturnValue
  40216. && maximum >= doubleClickReturnValue)
  40217. {
  40218. sendDragStart();
  40219. setValue (doubleClickReturnValue, true, true);
  40220. sendDragEnd();
  40221. }
  40222. }
  40223. void Slider::mouseWheelMove (const MouseEvent& e, float wheelIncrementX, float wheelIncrementY)
  40224. {
  40225. if (scrollWheelEnabled && isEnabled()
  40226. && style != TwoValueHorizontal
  40227. && style != TwoValueVertical)
  40228. {
  40229. if (maximum > minimum && ! isMouseButtonDownAnywhere())
  40230. {
  40231. if (valueBox != 0)
  40232. valueBox->hideEditor (false);
  40233. const double value = (double) currentValue.getValue();
  40234. const double proportionDelta = (wheelIncrementX != 0 ? -wheelIncrementX : wheelIncrementY) * 0.15f;
  40235. const double currentPos = valueToProportionOfLength (value);
  40236. const double newValue = proportionOfLengthToValue (jlimit (0.0, 1.0, currentPos + proportionDelta));
  40237. double delta = (newValue != value)
  40238. ? jmax (fabs (newValue - value), interval) : 0;
  40239. if (value > newValue)
  40240. delta = -delta;
  40241. sendDragStart();
  40242. setValue (snapValue (value + delta, false), true, true);
  40243. sendDragEnd();
  40244. }
  40245. }
  40246. else
  40247. {
  40248. Component::mouseWheelMove (e, wheelIncrementX, wheelIncrementY);
  40249. }
  40250. }
  40251. void SliderListener::sliderDragStarted (Slider*)
  40252. {
  40253. }
  40254. void SliderListener::sliderDragEnded (Slider*)
  40255. {
  40256. }
  40257. END_JUCE_NAMESPACE
  40258. /********* End of inlined file: juce_Slider.cpp *********/
  40259. /********* Start of inlined file: juce_TableHeaderComponent.cpp *********/
  40260. BEGIN_JUCE_NAMESPACE
  40261. class DragOverlayComp : public Component
  40262. {
  40263. public:
  40264. DragOverlayComp (Image* const image_)
  40265. : image (image_)
  40266. {
  40267. image->multiplyAllAlphas (0.8f);
  40268. setAlwaysOnTop (true);
  40269. }
  40270. ~DragOverlayComp()
  40271. {
  40272. }
  40273. void paint (Graphics& g)
  40274. {
  40275. g.drawImageAt (image, 0, 0);
  40276. }
  40277. private:
  40278. ScopedPointer <Image> image;
  40279. DragOverlayComp (const DragOverlayComp&);
  40280. const DragOverlayComp& operator= (const DragOverlayComp&);
  40281. };
  40282. TableHeaderComponent::TableHeaderComponent()
  40283. : columnsChanged (false),
  40284. columnsResized (false),
  40285. sortChanged (false),
  40286. menuActive (true),
  40287. stretchToFit (false),
  40288. columnIdBeingResized (0),
  40289. columnIdBeingDragged (0),
  40290. columnIdUnderMouse (0),
  40291. lastDeliberateWidth (0)
  40292. {
  40293. }
  40294. TableHeaderComponent::~TableHeaderComponent()
  40295. {
  40296. dragOverlayComp = 0;
  40297. }
  40298. void TableHeaderComponent::setPopupMenuActive (const bool hasMenu)
  40299. {
  40300. menuActive = hasMenu;
  40301. }
  40302. bool TableHeaderComponent::isPopupMenuActive() const { return menuActive; }
  40303. int TableHeaderComponent::getNumColumns (const bool onlyCountVisibleColumns) const
  40304. {
  40305. if (onlyCountVisibleColumns)
  40306. {
  40307. int num = 0;
  40308. for (int i = columns.size(); --i >= 0;)
  40309. if (columns.getUnchecked(i)->isVisible())
  40310. ++num;
  40311. return num;
  40312. }
  40313. else
  40314. {
  40315. return columns.size();
  40316. }
  40317. }
  40318. const String TableHeaderComponent::getColumnName (const int columnId) const
  40319. {
  40320. const ColumnInfo* const ci = getInfoForId (columnId);
  40321. return ci != 0 ? ci->name : String::empty;
  40322. }
  40323. void TableHeaderComponent::setColumnName (const int columnId, const String& newName)
  40324. {
  40325. ColumnInfo* const ci = getInfoForId (columnId);
  40326. if (ci != 0 && ci->name != newName)
  40327. {
  40328. ci->name = newName;
  40329. sendColumnsChanged();
  40330. }
  40331. }
  40332. void TableHeaderComponent::addColumn (const String& columnName,
  40333. const int columnId,
  40334. const int width,
  40335. const int minimumWidth,
  40336. const int maximumWidth,
  40337. const int propertyFlags,
  40338. const int insertIndex)
  40339. {
  40340. // can't have a duplicate or null ID!
  40341. jassert (columnId != 0 && getIndexOfColumnId (columnId, false) < 0);
  40342. jassert (width > 0);
  40343. ColumnInfo* const ci = new ColumnInfo();
  40344. ci->name = columnName;
  40345. ci->id = columnId;
  40346. ci->width = width;
  40347. ci->lastDeliberateWidth = width;
  40348. ci->minimumWidth = minimumWidth;
  40349. ci->maximumWidth = maximumWidth;
  40350. if (ci->maximumWidth < 0)
  40351. ci->maximumWidth = INT_MAX;
  40352. jassert (ci->maximumWidth >= ci->minimumWidth);
  40353. ci->propertyFlags = propertyFlags;
  40354. columns.insert (insertIndex, ci);
  40355. sendColumnsChanged();
  40356. }
  40357. void TableHeaderComponent::removeColumn (const int columnIdToRemove)
  40358. {
  40359. const int index = getIndexOfColumnId (columnIdToRemove, false);
  40360. if (index >= 0)
  40361. {
  40362. columns.remove (index);
  40363. sortChanged = true;
  40364. sendColumnsChanged();
  40365. }
  40366. }
  40367. void TableHeaderComponent::removeAllColumns()
  40368. {
  40369. if (columns.size() > 0)
  40370. {
  40371. columns.clear();
  40372. sendColumnsChanged();
  40373. }
  40374. }
  40375. void TableHeaderComponent::moveColumn (const int columnId, int newIndex)
  40376. {
  40377. const int currentIndex = getIndexOfColumnId (columnId, false);
  40378. newIndex = visibleIndexToTotalIndex (newIndex);
  40379. if (columns [currentIndex] != 0 && currentIndex != newIndex)
  40380. {
  40381. columns.move (currentIndex, newIndex);
  40382. sendColumnsChanged();
  40383. }
  40384. }
  40385. int TableHeaderComponent::getColumnWidth (const int columnId) const
  40386. {
  40387. const ColumnInfo* const ci = getInfoForId (columnId);
  40388. return ci != 0 ? ci->width : 0;
  40389. }
  40390. void TableHeaderComponent::setColumnWidth (const int columnId, const int newWidth)
  40391. {
  40392. ColumnInfo* const ci = getInfoForId (columnId);
  40393. if (ci != 0 && ci->width != newWidth)
  40394. {
  40395. const int numColumns = getNumColumns (true);
  40396. ci->lastDeliberateWidth = ci->width
  40397. = jlimit (ci->minimumWidth, ci->maximumWidth, newWidth);
  40398. if (stretchToFit)
  40399. {
  40400. const int index = getIndexOfColumnId (columnId, true) + 1;
  40401. if (((unsigned int) index) < (unsigned int) numColumns)
  40402. {
  40403. const int x = getColumnPosition (index).getX();
  40404. if (lastDeliberateWidth == 0)
  40405. lastDeliberateWidth = getTotalWidth();
  40406. resizeColumnsToFit (visibleIndexToTotalIndex (index), lastDeliberateWidth - x);
  40407. }
  40408. }
  40409. repaint();
  40410. columnsResized = true;
  40411. triggerAsyncUpdate();
  40412. }
  40413. }
  40414. int TableHeaderComponent::getIndexOfColumnId (const int columnId, const bool onlyCountVisibleColumns) const
  40415. {
  40416. int n = 0;
  40417. for (int i = 0; i < columns.size(); ++i)
  40418. {
  40419. if ((! onlyCountVisibleColumns) || columns.getUnchecked(i)->isVisible())
  40420. {
  40421. if (columns.getUnchecked(i)->id == columnId)
  40422. return n;
  40423. ++n;
  40424. }
  40425. }
  40426. return -1;
  40427. }
  40428. int TableHeaderComponent::getColumnIdOfIndex (int index, const bool onlyCountVisibleColumns) const
  40429. {
  40430. if (onlyCountVisibleColumns)
  40431. index = visibleIndexToTotalIndex (index);
  40432. const ColumnInfo* const ci = columns [index];
  40433. return (ci != 0) ? ci->id : 0;
  40434. }
  40435. const Rectangle TableHeaderComponent::getColumnPosition (const int index) const
  40436. {
  40437. int x = 0, width = 0, n = 0;
  40438. for (int i = 0; i < columns.size(); ++i)
  40439. {
  40440. x += width;
  40441. if (columns.getUnchecked(i)->isVisible())
  40442. {
  40443. width = columns.getUnchecked(i)->width;
  40444. if (n++ == index)
  40445. break;
  40446. }
  40447. else
  40448. {
  40449. width = 0;
  40450. }
  40451. }
  40452. return Rectangle (x, 0, width, getHeight());
  40453. }
  40454. int TableHeaderComponent::getColumnIdAtX (const int xToFind) const
  40455. {
  40456. if (xToFind >= 0)
  40457. {
  40458. int x = 0;
  40459. for (int i = 0; i < columns.size(); ++i)
  40460. {
  40461. const ColumnInfo* const ci = columns.getUnchecked(i);
  40462. if (ci->isVisible())
  40463. {
  40464. x += ci->width;
  40465. if (xToFind < x)
  40466. return ci->id;
  40467. }
  40468. }
  40469. }
  40470. return 0;
  40471. }
  40472. int TableHeaderComponent::getTotalWidth() const
  40473. {
  40474. int w = 0;
  40475. for (int i = columns.size(); --i >= 0;)
  40476. if (columns.getUnchecked(i)->isVisible())
  40477. w += columns.getUnchecked(i)->width;
  40478. return w;
  40479. }
  40480. void TableHeaderComponent::setStretchToFitActive (const bool shouldStretchToFit)
  40481. {
  40482. stretchToFit = shouldStretchToFit;
  40483. lastDeliberateWidth = getTotalWidth();
  40484. resized();
  40485. }
  40486. bool TableHeaderComponent::isStretchToFitActive() const
  40487. {
  40488. return stretchToFit;
  40489. }
  40490. void TableHeaderComponent::resizeAllColumnsToFit (int targetTotalWidth)
  40491. {
  40492. if (stretchToFit && getWidth() > 0
  40493. && columnIdBeingResized == 0 && columnIdBeingDragged == 0)
  40494. {
  40495. lastDeliberateWidth = targetTotalWidth;
  40496. resizeColumnsToFit (0, targetTotalWidth);
  40497. }
  40498. }
  40499. void TableHeaderComponent::resizeColumnsToFit (int firstColumnIndex, int targetTotalWidth)
  40500. {
  40501. targetTotalWidth = jmax (targetTotalWidth, 0);
  40502. StretchableObjectResizer sor;
  40503. int i;
  40504. for (i = firstColumnIndex; i < columns.size(); ++i)
  40505. {
  40506. ColumnInfo* const ci = columns.getUnchecked(i);
  40507. if (ci->isVisible())
  40508. sor.addItem (ci->lastDeliberateWidth, ci->minimumWidth, ci->maximumWidth);
  40509. }
  40510. sor.resizeToFit (targetTotalWidth);
  40511. int visIndex = 0;
  40512. for (i = firstColumnIndex; i < columns.size(); ++i)
  40513. {
  40514. ColumnInfo* const ci = columns.getUnchecked(i);
  40515. if (ci->isVisible())
  40516. {
  40517. const int newWidth = jlimit (ci->minimumWidth, ci->maximumWidth,
  40518. (int) floor (sor.getItemSize (visIndex++)));
  40519. if (newWidth != ci->width)
  40520. {
  40521. ci->width = newWidth;
  40522. repaint();
  40523. columnsResized = true;
  40524. triggerAsyncUpdate();
  40525. }
  40526. }
  40527. }
  40528. }
  40529. void TableHeaderComponent::setColumnVisible (const int columnId, const bool shouldBeVisible)
  40530. {
  40531. ColumnInfo* const ci = getInfoForId (columnId);
  40532. if (ci != 0 && shouldBeVisible != ci->isVisible())
  40533. {
  40534. if (shouldBeVisible)
  40535. ci->propertyFlags |= visible;
  40536. else
  40537. ci->propertyFlags &= ~visible;
  40538. sendColumnsChanged();
  40539. resized();
  40540. }
  40541. }
  40542. bool TableHeaderComponent::isColumnVisible (const int columnId) const
  40543. {
  40544. const ColumnInfo* const ci = getInfoForId (columnId);
  40545. return ci != 0 && ci->isVisible();
  40546. }
  40547. void TableHeaderComponent::setSortColumnId (const int columnId, const bool sortForwards)
  40548. {
  40549. if (getSortColumnId() != columnId || isSortedForwards() != sortForwards)
  40550. {
  40551. for (int i = columns.size(); --i >= 0;)
  40552. columns.getUnchecked(i)->propertyFlags &= ~(sortedForwards | sortedBackwards);
  40553. ColumnInfo* const ci = getInfoForId (columnId);
  40554. if (ci != 0)
  40555. ci->propertyFlags |= (sortForwards ? sortedForwards : sortedBackwards);
  40556. reSortTable();
  40557. }
  40558. }
  40559. int TableHeaderComponent::getSortColumnId() const
  40560. {
  40561. for (int i = columns.size(); --i >= 0;)
  40562. if ((columns.getUnchecked(i)->propertyFlags & (sortedForwards | sortedBackwards)) != 0)
  40563. return columns.getUnchecked(i)->id;
  40564. return 0;
  40565. }
  40566. bool TableHeaderComponent::isSortedForwards() const
  40567. {
  40568. for (int i = columns.size(); --i >= 0;)
  40569. if ((columns.getUnchecked(i)->propertyFlags & (sortedForwards | sortedBackwards)) != 0)
  40570. return (columns.getUnchecked(i)->propertyFlags & sortedForwards) != 0;
  40571. return true;
  40572. }
  40573. void TableHeaderComponent::reSortTable()
  40574. {
  40575. sortChanged = true;
  40576. repaint();
  40577. triggerAsyncUpdate();
  40578. }
  40579. const String TableHeaderComponent::toString() const
  40580. {
  40581. String s;
  40582. XmlElement doc (T("TABLELAYOUT"));
  40583. doc.setAttribute (T("sortedCol"), getSortColumnId());
  40584. doc.setAttribute (T("sortForwards"), isSortedForwards());
  40585. for (int i = 0; i < columns.size(); ++i)
  40586. {
  40587. const ColumnInfo* const ci = columns.getUnchecked (i);
  40588. XmlElement* const e = new XmlElement (T("COLUMN"));
  40589. doc.addChildElement (e);
  40590. e->setAttribute (T("id"), ci->id);
  40591. e->setAttribute (T("visible"), ci->isVisible());
  40592. e->setAttribute (T("width"), ci->width);
  40593. }
  40594. return doc.createDocument (String::empty, true, false);
  40595. }
  40596. void TableHeaderComponent::restoreFromString (const String& storedVersion)
  40597. {
  40598. XmlDocument doc (storedVersion);
  40599. ScopedPointer <XmlElement> storedXml (doc.getDocumentElement());
  40600. int index = 0;
  40601. if (storedXml != 0 && storedXml->hasTagName (T("TABLELAYOUT")))
  40602. {
  40603. forEachXmlChildElement (*storedXml, col)
  40604. {
  40605. const int tabId = col->getIntAttribute (T("id"));
  40606. ColumnInfo* const ci = getInfoForId (tabId);
  40607. if (ci != 0)
  40608. {
  40609. columns.move (columns.indexOf (ci), index);
  40610. ci->width = col->getIntAttribute (T("width"));
  40611. setColumnVisible (tabId, col->getBoolAttribute (T("visible")));
  40612. }
  40613. ++index;
  40614. }
  40615. columnsResized = true;
  40616. sendColumnsChanged();
  40617. setSortColumnId (storedXml->getIntAttribute (T("sortedCol")),
  40618. storedXml->getBoolAttribute (T("sortForwards"), true));
  40619. }
  40620. }
  40621. void TableHeaderComponent::addListener (TableHeaderListener* const newListener)
  40622. {
  40623. listeners.addIfNotAlreadyThere (newListener);
  40624. }
  40625. void TableHeaderComponent::removeListener (TableHeaderListener* const listenerToRemove)
  40626. {
  40627. listeners.removeValue (listenerToRemove);
  40628. }
  40629. void TableHeaderComponent::columnClicked (int columnId, const ModifierKeys& mods)
  40630. {
  40631. const ColumnInfo* const ci = getInfoForId (columnId);
  40632. if (ci != 0 && (ci->propertyFlags & sortable) != 0 && ! mods.isPopupMenu())
  40633. setSortColumnId (columnId, (ci->propertyFlags & sortedForwards) == 0);
  40634. }
  40635. void TableHeaderComponent::addMenuItems (PopupMenu& menu, const int /*columnIdClicked*/)
  40636. {
  40637. for (int i = 0; i < columns.size(); ++i)
  40638. {
  40639. const ColumnInfo* const ci = columns.getUnchecked(i);
  40640. if ((ci->propertyFlags & appearsOnColumnMenu) != 0)
  40641. menu.addItem (ci->id, ci->name,
  40642. (ci->propertyFlags & (sortedForwards | sortedBackwards)) == 0,
  40643. isColumnVisible (ci->id));
  40644. }
  40645. }
  40646. void TableHeaderComponent::reactToMenuItem (const int menuReturnId, const int /*columnIdClicked*/)
  40647. {
  40648. if (getIndexOfColumnId (menuReturnId, false) >= 0)
  40649. setColumnVisible (menuReturnId, ! isColumnVisible (menuReturnId));
  40650. }
  40651. void TableHeaderComponent::paint (Graphics& g)
  40652. {
  40653. LookAndFeel& lf = getLookAndFeel();
  40654. lf.drawTableHeaderBackground (g, *this);
  40655. const Rectangle clip (g.getClipBounds());
  40656. int x = 0;
  40657. for (int i = 0; i < columns.size(); ++i)
  40658. {
  40659. const ColumnInfo* const ci = columns.getUnchecked(i);
  40660. if (ci->isVisible())
  40661. {
  40662. if (x + ci->width > clip.getX()
  40663. && (ci->id != columnIdBeingDragged
  40664. || dragOverlayComp == 0
  40665. || ! dragOverlayComp->isVisible()))
  40666. {
  40667. g.saveState();
  40668. g.setOrigin (x, 0);
  40669. g.reduceClipRegion (0, 0, ci->width, getHeight());
  40670. lf.drawTableHeaderColumn (g, ci->name, ci->id, ci->width, getHeight(),
  40671. ci->id == columnIdUnderMouse,
  40672. ci->id == columnIdUnderMouse && isMouseButtonDown(),
  40673. ci->propertyFlags);
  40674. g.restoreState();
  40675. }
  40676. x += ci->width;
  40677. if (x >= clip.getRight())
  40678. break;
  40679. }
  40680. }
  40681. }
  40682. void TableHeaderComponent::resized()
  40683. {
  40684. }
  40685. void TableHeaderComponent::mouseMove (const MouseEvent& e)
  40686. {
  40687. updateColumnUnderMouse (e.x, e.y);
  40688. }
  40689. void TableHeaderComponent::mouseEnter (const MouseEvent& e)
  40690. {
  40691. updateColumnUnderMouse (e.x, e.y);
  40692. }
  40693. void TableHeaderComponent::mouseExit (const MouseEvent& e)
  40694. {
  40695. updateColumnUnderMouse (e.x, e.y);
  40696. }
  40697. void TableHeaderComponent::mouseDown (const MouseEvent& e)
  40698. {
  40699. repaint();
  40700. columnIdBeingResized = 0;
  40701. columnIdBeingDragged = 0;
  40702. if (columnIdUnderMouse != 0)
  40703. {
  40704. draggingColumnOffset = e.x - getColumnPosition (getIndexOfColumnId (columnIdUnderMouse, true)).getX();
  40705. if (e.mods.isPopupMenu())
  40706. columnClicked (columnIdUnderMouse, e.mods);
  40707. }
  40708. if (menuActive && e.mods.isPopupMenu())
  40709. showColumnChooserMenu (columnIdUnderMouse);
  40710. }
  40711. void TableHeaderComponent::mouseDrag (const MouseEvent& e)
  40712. {
  40713. if (columnIdBeingResized == 0
  40714. && columnIdBeingDragged == 0
  40715. && ! (e.mouseWasClicked() || e.mods.isPopupMenu()))
  40716. {
  40717. dragOverlayComp = 0;
  40718. columnIdBeingResized = getResizeDraggerAt (e.getMouseDownX());
  40719. if (columnIdBeingResized != 0)
  40720. {
  40721. const ColumnInfo* const ci = getInfoForId (columnIdBeingResized);
  40722. initialColumnWidth = ci->width;
  40723. }
  40724. else
  40725. {
  40726. beginDrag (e);
  40727. }
  40728. }
  40729. if (columnIdBeingResized != 0)
  40730. {
  40731. const ColumnInfo* const ci = getInfoForId (columnIdBeingResized);
  40732. if (ci != 0)
  40733. {
  40734. int w = jlimit (ci->minimumWidth, ci->maximumWidth,
  40735. initialColumnWidth + e.getDistanceFromDragStartX());
  40736. if (stretchToFit)
  40737. {
  40738. // prevent us dragging a column too far right if we're in stretch-to-fit mode
  40739. int minWidthOnRight = 0;
  40740. for (int i = getIndexOfColumnId (columnIdBeingResized, false) + 1; i < columns.size(); ++i)
  40741. if (columns.getUnchecked (i)->isVisible())
  40742. minWidthOnRight += columns.getUnchecked (i)->minimumWidth;
  40743. const Rectangle currentPos (getColumnPosition (getIndexOfColumnId (columnIdBeingResized, true)));
  40744. w = jmax (ci->minimumWidth, jmin (w, getWidth() - minWidthOnRight - currentPos.getX()));
  40745. }
  40746. setColumnWidth (columnIdBeingResized, w);
  40747. }
  40748. }
  40749. else if (columnIdBeingDragged != 0)
  40750. {
  40751. if (e.y >= -50 && e.y < getHeight() + 50)
  40752. {
  40753. if (dragOverlayComp != 0)
  40754. {
  40755. dragOverlayComp->setVisible (true);
  40756. dragOverlayComp->setBounds (jlimit (0,
  40757. jmax (0, getTotalWidth() - dragOverlayComp->getWidth()),
  40758. e.x - draggingColumnOffset),
  40759. 0,
  40760. dragOverlayComp->getWidth(),
  40761. getHeight());
  40762. for (int i = columns.size(); --i >= 0;)
  40763. {
  40764. const int currentIndex = getIndexOfColumnId (columnIdBeingDragged, true);
  40765. int newIndex = currentIndex;
  40766. if (newIndex > 0)
  40767. {
  40768. // if the previous column isn't draggable, we can't move our column
  40769. // past it, because that'd change the undraggable column's position..
  40770. const ColumnInfo* const previous = columns.getUnchecked (newIndex - 1);
  40771. if ((previous->propertyFlags & draggable) != 0)
  40772. {
  40773. const int leftOfPrevious = getColumnPosition (newIndex - 1).getX();
  40774. const int rightOfCurrent = getColumnPosition (newIndex).getRight();
  40775. if (abs (dragOverlayComp->getX() - leftOfPrevious)
  40776. < abs (dragOverlayComp->getRight() - rightOfCurrent))
  40777. {
  40778. --newIndex;
  40779. }
  40780. }
  40781. }
  40782. if (newIndex < columns.size() - 1)
  40783. {
  40784. // if the next column isn't draggable, we can't move our column
  40785. // past it, because that'd change the undraggable column's position..
  40786. const ColumnInfo* const nextCol = columns.getUnchecked (newIndex + 1);
  40787. if ((nextCol->propertyFlags & draggable) != 0)
  40788. {
  40789. const int leftOfCurrent = getColumnPosition (newIndex).getX();
  40790. const int rightOfNext = getColumnPosition (newIndex + 1).getRight();
  40791. if (abs (dragOverlayComp->getX() - leftOfCurrent)
  40792. > abs (dragOverlayComp->getRight() - rightOfNext))
  40793. {
  40794. ++newIndex;
  40795. }
  40796. }
  40797. }
  40798. if (newIndex != currentIndex)
  40799. moveColumn (columnIdBeingDragged, newIndex);
  40800. else
  40801. break;
  40802. }
  40803. }
  40804. }
  40805. else
  40806. {
  40807. endDrag (draggingColumnOriginalIndex);
  40808. }
  40809. }
  40810. }
  40811. void TableHeaderComponent::beginDrag (const MouseEvent& e)
  40812. {
  40813. if (columnIdBeingDragged == 0)
  40814. {
  40815. columnIdBeingDragged = getColumnIdAtX (e.getMouseDownX());
  40816. const ColumnInfo* const ci = getInfoForId (columnIdBeingDragged);
  40817. if (ci == 0 || (ci->propertyFlags & draggable) == 0)
  40818. {
  40819. columnIdBeingDragged = 0;
  40820. }
  40821. else
  40822. {
  40823. draggingColumnOriginalIndex = getIndexOfColumnId (columnIdBeingDragged, true);
  40824. const Rectangle columnRect (getColumnPosition (draggingColumnOriginalIndex));
  40825. const int temp = columnIdBeingDragged;
  40826. columnIdBeingDragged = 0;
  40827. addAndMakeVisible (dragOverlayComp = new DragOverlayComp (createComponentSnapshot (columnRect, false)));
  40828. columnIdBeingDragged = temp;
  40829. dragOverlayComp->setBounds (columnRect);
  40830. for (int i = listeners.size(); --i >= 0;)
  40831. {
  40832. listeners.getUnchecked(i)->tableColumnDraggingChanged (this, columnIdBeingDragged);
  40833. i = jmin (i, listeners.size() - 1);
  40834. }
  40835. }
  40836. }
  40837. }
  40838. void TableHeaderComponent::endDrag (const int finalIndex)
  40839. {
  40840. if (columnIdBeingDragged != 0)
  40841. {
  40842. moveColumn (columnIdBeingDragged, finalIndex);
  40843. columnIdBeingDragged = 0;
  40844. repaint();
  40845. for (int i = listeners.size(); --i >= 0;)
  40846. {
  40847. listeners.getUnchecked(i)->tableColumnDraggingChanged (this, 0);
  40848. i = jmin (i, listeners.size() - 1);
  40849. }
  40850. }
  40851. }
  40852. void TableHeaderComponent::mouseUp (const MouseEvent& e)
  40853. {
  40854. mouseDrag (e);
  40855. for (int i = columns.size(); --i >= 0;)
  40856. if (columns.getUnchecked (i)->isVisible())
  40857. columns.getUnchecked (i)->lastDeliberateWidth = columns.getUnchecked (i)->width;
  40858. columnIdBeingResized = 0;
  40859. repaint();
  40860. endDrag (getIndexOfColumnId (columnIdBeingDragged, true));
  40861. updateColumnUnderMouse (e.x, e.y);
  40862. if (columnIdUnderMouse != 0 && e.mouseWasClicked() && ! e.mods.isPopupMenu())
  40863. columnClicked (columnIdUnderMouse, e.mods);
  40864. dragOverlayComp = 0;
  40865. }
  40866. const MouseCursor TableHeaderComponent::getMouseCursor()
  40867. {
  40868. int x, y;
  40869. getMouseXYRelative (x, y);
  40870. if (columnIdBeingResized != 0 || (getResizeDraggerAt (x) != 0 && ! isMouseButtonDown()))
  40871. return MouseCursor (MouseCursor::LeftRightResizeCursor);
  40872. return Component::getMouseCursor();
  40873. }
  40874. bool TableHeaderComponent::ColumnInfo::isVisible() const
  40875. {
  40876. return (propertyFlags & TableHeaderComponent::visible) != 0;
  40877. }
  40878. TableHeaderComponent::ColumnInfo* TableHeaderComponent::getInfoForId (const int id) const
  40879. {
  40880. for (int i = columns.size(); --i >= 0;)
  40881. if (columns.getUnchecked(i)->id == id)
  40882. return columns.getUnchecked(i);
  40883. return 0;
  40884. }
  40885. int TableHeaderComponent::visibleIndexToTotalIndex (const int visibleIndex) const
  40886. {
  40887. int n = 0;
  40888. for (int i = 0; i < columns.size(); ++i)
  40889. {
  40890. if (columns.getUnchecked(i)->isVisible())
  40891. {
  40892. if (n == visibleIndex)
  40893. return i;
  40894. ++n;
  40895. }
  40896. }
  40897. return -1;
  40898. }
  40899. void TableHeaderComponent::sendColumnsChanged()
  40900. {
  40901. if (stretchToFit && lastDeliberateWidth > 0)
  40902. resizeAllColumnsToFit (lastDeliberateWidth);
  40903. repaint();
  40904. columnsChanged = true;
  40905. triggerAsyncUpdate();
  40906. }
  40907. void TableHeaderComponent::handleAsyncUpdate()
  40908. {
  40909. const bool changed = columnsChanged || sortChanged;
  40910. const bool sized = columnsResized || changed;
  40911. const bool sorted = sortChanged;
  40912. columnsChanged = false;
  40913. columnsResized = false;
  40914. sortChanged = false;
  40915. if (sorted)
  40916. {
  40917. for (int i = listeners.size(); --i >= 0;)
  40918. {
  40919. listeners.getUnchecked(i)->tableSortOrderChanged (this);
  40920. i = jmin (i, listeners.size() - 1);
  40921. }
  40922. }
  40923. if (changed)
  40924. {
  40925. for (int i = listeners.size(); --i >= 0;)
  40926. {
  40927. listeners.getUnchecked(i)->tableColumnsChanged (this);
  40928. i = jmin (i, listeners.size() - 1);
  40929. }
  40930. }
  40931. if (sized)
  40932. {
  40933. for (int i = listeners.size(); --i >= 0;)
  40934. {
  40935. listeners.getUnchecked(i)->tableColumnsResized (this);
  40936. i = jmin (i, listeners.size() - 1);
  40937. }
  40938. }
  40939. }
  40940. int TableHeaderComponent::getResizeDraggerAt (const int mouseX) const
  40941. {
  40942. if (((unsigned int) mouseX) < (unsigned int) getWidth())
  40943. {
  40944. const int draggableDistance = 3;
  40945. int x = 0;
  40946. for (int i = 0; i < columns.size(); ++i)
  40947. {
  40948. const ColumnInfo* const ci = columns.getUnchecked(i);
  40949. if (ci->isVisible())
  40950. {
  40951. if (abs (mouseX - (x + ci->width)) <= draggableDistance
  40952. && (ci->propertyFlags & resizable) != 0)
  40953. return ci->id;
  40954. x += ci->width;
  40955. }
  40956. }
  40957. }
  40958. return 0;
  40959. }
  40960. void TableHeaderComponent::updateColumnUnderMouse (int x, int y)
  40961. {
  40962. const int newCol = (reallyContains (x, y, true) && getResizeDraggerAt (x) == 0)
  40963. ? getColumnIdAtX (x) : 0;
  40964. if (newCol != columnIdUnderMouse)
  40965. {
  40966. columnIdUnderMouse = newCol;
  40967. repaint();
  40968. }
  40969. }
  40970. void TableHeaderComponent::showColumnChooserMenu (const int columnIdClicked)
  40971. {
  40972. PopupMenu m;
  40973. addMenuItems (m, columnIdClicked);
  40974. if (m.getNumItems() > 0)
  40975. {
  40976. m.setLookAndFeel (&getLookAndFeel());
  40977. const int result = m.show();
  40978. if (result != 0)
  40979. reactToMenuItem (result, columnIdClicked);
  40980. }
  40981. }
  40982. void TableHeaderListener::tableColumnDraggingChanged (TableHeaderComponent*, int)
  40983. {
  40984. }
  40985. END_JUCE_NAMESPACE
  40986. /********* End of inlined file: juce_TableHeaderComponent.cpp *********/
  40987. /********* Start of inlined file: juce_TableListBox.cpp *********/
  40988. BEGIN_JUCE_NAMESPACE
  40989. static const tchar* const tableColumnPropertyTag = T("_tableColumnID");
  40990. class TableListRowComp : public Component,
  40991. public TooltipClient
  40992. {
  40993. public:
  40994. TableListRowComp (TableListBox& owner_)
  40995. : owner (owner_),
  40996. row (-1),
  40997. isSelected (false)
  40998. {
  40999. }
  41000. ~TableListRowComp()
  41001. {
  41002. deleteAllChildren();
  41003. }
  41004. void paint (Graphics& g)
  41005. {
  41006. TableListBoxModel* const model = owner.getModel();
  41007. if (model != 0)
  41008. {
  41009. const TableHeaderComponent* const header = owner.getHeader();
  41010. model->paintRowBackground (g, row, getWidth(), getHeight(), isSelected);
  41011. const int numColumns = header->getNumColumns (true);
  41012. for (int i = 0; i < numColumns; ++i)
  41013. {
  41014. if (! columnsWithComponents [i])
  41015. {
  41016. const int columnId = header->getColumnIdOfIndex (i, true);
  41017. Rectangle columnRect (header->getColumnPosition (i));
  41018. columnRect.setSize (columnRect.getWidth(), getHeight());
  41019. g.saveState();
  41020. g.reduceClipRegion (columnRect);
  41021. g.setOrigin (columnRect.getX(), 0);
  41022. model->paintCell (g, row, columnId, columnRect.getWidth(), columnRect.getHeight(), isSelected);
  41023. g.restoreState();
  41024. }
  41025. }
  41026. }
  41027. }
  41028. void update (const int newRow, const bool isNowSelected)
  41029. {
  41030. if (newRow != row || isNowSelected != isSelected)
  41031. {
  41032. row = newRow;
  41033. isSelected = isNowSelected;
  41034. repaint();
  41035. }
  41036. if (row < owner.getNumRows())
  41037. {
  41038. jassert (row >= 0);
  41039. const tchar* const tagPropertyName = T("_tableLastUseNum");
  41040. const int newTag = Random::getSystemRandom().nextInt();
  41041. const TableHeaderComponent* const header = owner.getHeader();
  41042. const int numColumns = header->getNumColumns (true);
  41043. int i;
  41044. columnsWithComponents.clear();
  41045. if (owner.getModel() != 0)
  41046. {
  41047. for (i = 0; i < numColumns; ++i)
  41048. {
  41049. const int columnId = header->getColumnIdOfIndex (i, true);
  41050. Component* const newComp
  41051. = owner.getModel()->refreshComponentForCell (row, columnId, isSelected,
  41052. findChildComponentForColumn (columnId));
  41053. if (newComp != 0)
  41054. {
  41055. addAndMakeVisible (newComp);
  41056. newComp->setComponentProperty (tagPropertyName, newTag);
  41057. newComp->setComponentProperty (tableColumnPropertyTag, columnId);
  41058. const Rectangle columnRect (header->getColumnPosition (i));
  41059. newComp->setBounds (columnRect.getX(), 0, columnRect.getWidth(), getHeight());
  41060. columnsWithComponents.setBit (i);
  41061. }
  41062. }
  41063. }
  41064. for (i = getNumChildComponents(); --i >= 0;)
  41065. {
  41066. Component* const c = getChildComponent (i);
  41067. if (c->getComponentPropertyInt (tagPropertyName, false, 0) != newTag)
  41068. delete c;
  41069. }
  41070. }
  41071. else
  41072. {
  41073. columnsWithComponents.clear();
  41074. deleteAllChildren();
  41075. }
  41076. }
  41077. void resized()
  41078. {
  41079. for (int i = getNumChildComponents(); --i >= 0;)
  41080. {
  41081. Component* const c = getChildComponent (i);
  41082. const int columnId = c->getComponentPropertyInt (tableColumnPropertyTag, false, 0);
  41083. if (columnId != 0)
  41084. {
  41085. const Rectangle columnRect (owner.getHeader()->getColumnPosition (owner.getHeader()->getIndexOfColumnId (columnId, true)));
  41086. c->setBounds (columnRect.getX(), 0, columnRect.getWidth(), getHeight());
  41087. }
  41088. }
  41089. }
  41090. void mouseDown (const MouseEvent& e)
  41091. {
  41092. isDragging = false;
  41093. selectRowOnMouseUp = false;
  41094. if (isEnabled())
  41095. {
  41096. if (! isSelected)
  41097. {
  41098. owner.selectRowsBasedOnModifierKeys (row, e.mods);
  41099. const int columnId = owner.getHeader()->getColumnIdAtX (e.x);
  41100. if (columnId != 0 && owner.getModel() != 0)
  41101. owner.getModel()->cellClicked (row, columnId, e);
  41102. }
  41103. else
  41104. {
  41105. selectRowOnMouseUp = true;
  41106. }
  41107. }
  41108. }
  41109. void mouseDrag (const MouseEvent& e)
  41110. {
  41111. if (isEnabled() && owner.getModel() != 0 && ! (e.mouseWasClicked() || isDragging))
  41112. {
  41113. const SparseSet <int> selectedRows (owner.getSelectedRows());
  41114. if (selectedRows.size() > 0)
  41115. {
  41116. const String dragDescription (owner.getModel()->getDragSourceDescription (selectedRows));
  41117. if (dragDescription.isNotEmpty())
  41118. {
  41119. isDragging = true;
  41120. owner.startDragAndDrop (e, dragDescription);
  41121. }
  41122. }
  41123. }
  41124. }
  41125. void mouseUp (const MouseEvent& e)
  41126. {
  41127. if (selectRowOnMouseUp && e.mouseWasClicked() && isEnabled())
  41128. {
  41129. owner.selectRowsBasedOnModifierKeys (row, e.mods);
  41130. const int columnId = owner.getHeader()->getColumnIdAtX (e.x);
  41131. if (columnId != 0 && owner.getModel() != 0)
  41132. owner.getModel()->cellClicked (row, columnId, e);
  41133. }
  41134. }
  41135. void mouseDoubleClick (const MouseEvent& e)
  41136. {
  41137. const int columnId = owner.getHeader()->getColumnIdAtX (e.x);
  41138. if (columnId != 0 && owner.getModel() != 0)
  41139. owner.getModel()->cellDoubleClicked (row, columnId, e);
  41140. }
  41141. const String getTooltip()
  41142. {
  41143. int x, y;
  41144. getMouseXYRelative (x, y);
  41145. const int columnId = owner.getHeader()->getColumnIdAtX (x);
  41146. if (columnId != 0 && owner.getModel() != 0)
  41147. return owner.getModel()->getCellTooltip (row, columnId);
  41148. return String::empty;
  41149. }
  41150. juce_UseDebuggingNewOperator
  41151. private:
  41152. TableListBox& owner;
  41153. int row;
  41154. bool isSelected, isDragging, selectRowOnMouseUp;
  41155. BitArray columnsWithComponents;
  41156. Component* findChildComponentForColumn (const int columnId) const
  41157. {
  41158. for (int i = getNumChildComponents(); --i >= 0;)
  41159. {
  41160. Component* const c = getChildComponent (i);
  41161. if (c->getComponentPropertyInt (tableColumnPropertyTag, false, 0) == columnId)
  41162. return c;
  41163. }
  41164. return 0;
  41165. }
  41166. TableListRowComp (const TableListRowComp&);
  41167. const TableListRowComp& operator= (const TableListRowComp&);
  41168. };
  41169. class TableListBoxHeader : public TableHeaderComponent
  41170. {
  41171. public:
  41172. TableListBoxHeader (TableListBox& owner_)
  41173. : owner (owner_)
  41174. {
  41175. }
  41176. ~TableListBoxHeader()
  41177. {
  41178. }
  41179. void addMenuItems (PopupMenu& menu, const int columnIdClicked)
  41180. {
  41181. if (owner.isAutoSizeMenuOptionShown())
  41182. {
  41183. menu.addItem (0xf836743, TRANS("Auto-size this column"), columnIdClicked != 0);
  41184. menu.addItem (0xf836744, TRANS("Auto-size all columns"), owner.getHeader()->getNumColumns (true) > 0);
  41185. menu.addSeparator();
  41186. }
  41187. TableHeaderComponent::addMenuItems (menu, columnIdClicked);
  41188. }
  41189. void reactToMenuItem (const int menuReturnId, const int columnIdClicked)
  41190. {
  41191. if (menuReturnId == 0xf836743)
  41192. {
  41193. owner.autoSizeColumn (columnIdClicked);
  41194. }
  41195. else if (menuReturnId == 0xf836744)
  41196. {
  41197. owner.autoSizeAllColumns();
  41198. }
  41199. else
  41200. {
  41201. TableHeaderComponent::reactToMenuItem (menuReturnId, columnIdClicked);
  41202. }
  41203. }
  41204. juce_UseDebuggingNewOperator
  41205. private:
  41206. TableListBox& owner;
  41207. TableListBoxHeader (const TableListBoxHeader&);
  41208. const TableListBoxHeader& operator= (const TableListBoxHeader&);
  41209. };
  41210. TableListBox::TableListBox (const String& name, TableListBoxModel* const model_)
  41211. : ListBox (name, 0),
  41212. model (model_),
  41213. autoSizeOptionsShown (true)
  41214. {
  41215. ListBox::model = this;
  41216. header = new TableListBoxHeader (*this);
  41217. header->setSize (100, 28);
  41218. header->addListener (this);
  41219. setHeaderComponent (header);
  41220. }
  41221. TableListBox::~TableListBox()
  41222. {
  41223. deleteAllChildren();
  41224. }
  41225. void TableListBox::setModel (TableListBoxModel* const newModel)
  41226. {
  41227. if (model != newModel)
  41228. {
  41229. model = newModel;
  41230. updateContent();
  41231. }
  41232. }
  41233. int TableListBox::getHeaderHeight() const
  41234. {
  41235. return header->getHeight();
  41236. }
  41237. void TableListBox::setHeaderHeight (const int newHeight)
  41238. {
  41239. header->setSize (header->getWidth(), newHeight);
  41240. resized();
  41241. }
  41242. void TableListBox::autoSizeColumn (const int columnId)
  41243. {
  41244. const int width = model != 0 ? model->getColumnAutoSizeWidth (columnId) : 0;
  41245. if (width > 0)
  41246. header->setColumnWidth (columnId, width);
  41247. }
  41248. void TableListBox::autoSizeAllColumns()
  41249. {
  41250. for (int i = 0; i < header->getNumColumns (true); ++i)
  41251. autoSizeColumn (header->getColumnIdOfIndex (i, true));
  41252. }
  41253. void TableListBox::setAutoSizeMenuOptionShown (const bool shouldBeShown)
  41254. {
  41255. autoSizeOptionsShown = shouldBeShown;
  41256. }
  41257. bool TableListBox::isAutoSizeMenuOptionShown() const
  41258. {
  41259. return autoSizeOptionsShown;
  41260. }
  41261. const Rectangle TableListBox::getCellPosition (const int columnId,
  41262. const int rowNumber,
  41263. const bool relativeToComponentTopLeft) const
  41264. {
  41265. Rectangle headerCell (header->getColumnPosition (header->getIndexOfColumnId (columnId, true)));
  41266. if (relativeToComponentTopLeft)
  41267. headerCell.translate (header->getX(), 0);
  41268. const Rectangle row (getRowPosition (rowNumber, relativeToComponentTopLeft));
  41269. return Rectangle (headerCell.getX(), row.getY(),
  41270. headerCell.getWidth(), row.getHeight());
  41271. }
  41272. void TableListBox::scrollToEnsureColumnIsOnscreen (const int columnId)
  41273. {
  41274. ScrollBar* const scrollbar = getHorizontalScrollBar();
  41275. if (scrollbar != 0)
  41276. {
  41277. const Rectangle pos (header->getColumnPosition (header->getIndexOfColumnId (columnId, true)));
  41278. double x = scrollbar->getCurrentRangeStart();
  41279. const double w = scrollbar->getCurrentRangeSize();
  41280. if (pos.getX() < x)
  41281. x = pos.getX();
  41282. else if (pos.getRight() > x + w)
  41283. x += jmax (0.0, pos.getRight() - (x + w));
  41284. scrollbar->setCurrentRangeStart (x);
  41285. }
  41286. }
  41287. int TableListBox::getNumRows()
  41288. {
  41289. return model != 0 ? model->getNumRows() : 0;
  41290. }
  41291. void TableListBox::paintListBoxItem (int, Graphics&, int, int, bool)
  41292. {
  41293. }
  41294. Component* TableListBox::refreshComponentForRow (int rowNumber, bool isRowSelected_, Component* existingComponentToUpdate)
  41295. {
  41296. if (existingComponentToUpdate == 0)
  41297. existingComponentToUpdate = new TableListRowComp (*this);
  41298. ((TableListRowComp*) existingComponentToUpdate)->update (rowNumber, isRowSelected_);
  41299. return existingComponentToUpdate;
  41300. }
  41301. void TableListBox::selectedRowsChanged (int row)
  41302. {
  41303. if (model != 0)
  41304. model->selectedRowsChanged (row);
  41305. }
  41306. void TableListBox::deleteKeyPressed (int row)
  41307. {
  41308. if (model != 0)
  41309. model->deleteKeyPressed (row);
  41310. }
  41311. void TableListBox::returnKeyPressed (int row)
  41312. {
  41313. if (model != 0)
  41314. model->returnKeyPressed (row);
  41315. }
  41316. void TableListBox::backgroundClicked()
  41317. {
  41318. if (model != 0)
  41319. model->backgroundClicked();
  41320. }
  41321. void TableListBox::listWasScrolled()
  41322. {
  41323. if (model != 0)
  41324. model->listWasScrolled();
  41325. }
  41326. void TableListBox::tableColumnsChanged (TableHeaderComponent*)
  41327. {
  41328. setMinimumContentWidth (header->getTotalWidth());
  41329. repaint();
  41330. updateColumnComponents();
  41331. }
  41332. void TableListBox::tableColumnsResized (TableHeaderComponent*)
  41333. {
  41334. setMinimumContentWidth (header->getTotalWidth());
  41335. repaint();
  41336. updateColumnComponents();
  41337. }
  41338. void TableListBox::tableSortOrderChanged (TableHeaderComponent*)
  41339. {
  41340. if (model != 0)
  41341. model->sortOrderChanged (header->getSortColumnId(),
  41342. header->isSortedForwards());
  41343. }
  41344. void TableListBox::tableColumnDraggingChanged (TableHeaderComponent*, int columnIdNowBeingDragged_)
  41345. {
  41346. columnIdNowBeingDragged = columnIdNowBeingDragged_;
  41347. repaint();
  41348. }
  41349. void TableListBox::resized()
  41350. {
  41351. ListBox::resized();
  41352. header->resizeAllColumnsToFit (getVisibleContentWidth());
  41353. setMinimumContentWidth (header->getTotalWidth());
  41354. }
  41355. void TableListBox::updateColumnComponents() const
  41356. {
  41357. const int firstRow = getRowContainingPosition (0, 0);
  41358. for (int i = firstRow + getNumRowsOnScreen() + 2; --i >= firstRow;)
  41359. {
  41360. TableListRowComp* const rowComp = dynamic_cast <TableListRowComp*> (getComponentForRowNumber (i));
  41361. if (rowComp != 0)
  41362. rowComp->resized();
  41363. }
  41364. }
  41365. void TableListBoxModel::cellClicked (int, int, const MouseEvent&)
  41366. {
  41367. }
  41368. void TableListBoxModel::cellDoubleClicked (int, int, const MouseEvent&)
  41369. {
  41370. }
  41371. void TableListBoxModel::backgroundClicked()
  41372. {
  41373. }
  41374. void TableListBoxModel::sortOrderChanged (int, const bool)
  41375. {
  41376. }
  41377. int TableListBoxModel::getColumnAutoSizeWidth (int)
  41378. {
  41379. return 0;
  41380. }
  41381. void TableListBoxModel::selectedRowsChanged (int)
  41382. {
  41383. }
  41384. void TableListBoxModel::deleteKeyPressed (int)
  41385. {
  41386. }
  41387. void TableListBoxModel::returnKeyPressed (int)
  41388. {
  41389. }
  41390. void TableListBoxModel::listWasScrolled()
  41391. {
  41392. }
  41393. const String TableListBoxModel::getCellTooltip (int /*rowNumber*/, int /*columnId*/)
  41394. {
  41395. return String::empty;
  41396. }
  41397. const String TableListBoxModel::getDragSourceDescription (const SparseSet<int>&)
  41398. {
  41399. return String::empty;
  41400. }
  41401. Component* TableListBoxModel::refreshComponentForCell (int, int, bool, Component* existingComponentToUpdate)
  41402. {
  41403. (void) existingComponentToUpdate;
  41404. jassert (existingComponentToUpdate == 0); // indicates a failure in the code the recycles the components
  41405. return 0;
  41406. }
  41407. END_JUCE_NAMESPACE
  41408. /********* End of inlined file: juce_TableListBox.cpp *********/
  41409. /********* Start of inlined file: juce_TextEditor.cpp *********/
  41410. BEGIN_JUCE_NAMESPACE
  41411. // a word or space that can't be broken down any further
  41412. struct TextAtom
  41413. {
  41414. String atomText;
  41415. float width;
  41416. uint16 numChars;
  41417. bool isWhitespace() const { return CharacterFunctions::isWhitespace (atomText[0]); }
  41418. bool isNewLine() const { return atomText[0] == T('\r') || atomText[0] == T('\n'); }
  41419. const String getText (const tchar passwordCharacter) const
  41420. {
  41421. if (passwordCharacter == 0)
  41422. return atomText;
  41423. else
  41424. return String::repeatedString (String::charToString (passwordCharacter),
  41425. atomText.length());
  41426. }
  41427. const String getTrimmedText (const tchar passwordCharacter) const
  41428. {
  41429. if (passwordCharacter == 0)
  41430. return atomText.substring (0, numChars);
  41431. else if (isNewLine())
  41432. return String::empty;
  41433. else
  41434. return String::repeatedString (String::charToString (passwordCharacter), numChars);
  41435. }
  41436. };
  41437. // a run of text with a single font and colour
  41438. class UniformTextSection
  41439. {
  41440. public:
  41441. UniformTextSection (const String& text,
  41442. const Font& font_,
  41443. const Colour& colour_,
  41444. const tchar passwordCharacter)
  41445. : font (font_),
  41446. colour (colour_)
  41447. {
  41448. initialiseAtoms (text, passwordCharacter);
  41449. }
  41450. UniformTextSection (const UniformTextSection& other)
  41451. : font (other.font),
  41452. colour (other.colour)
  41453. {
  41454. atoms.ensureStorageAllocated (other.atoms.size());
  41455. for (int i = 0; i < other.atoms.size(); ++i)
  41456. atoms.add (new TextAtom (*(const TextAtom*) other.atoms.getUnchecked(i)));
  41457. }
  41458. ~UniformTextSection()
  41459. {
  41460. // (no need to delete the atoms, as they're explicitly deleted by the caller)
  41461. }
  41462. void clear()
  41463. {
  41464. for (int i = atoms.size(); --i >= 0;)
  41465. delete getAtom(i);
  41466. atoms.clear();
  41467. }
  41468. int getNumAtoms() const
  41469. {
  41470. return atoms.size();
  41471. }
  41472. TextAtom* getAtom (const int index) const
  41473. {
  41474. return (TextAtom*) atoms.getUnchecked (index);
  41475. }
  41476. void append (const UniformTextSection& other, const tchar passwordCharacter)
  41477. {
  41478. if (other.atoms.size() > 0)
  41479. {
  41480. TextAtom* const lastAtom = (TextAtom*) atoms.getLast();
  41481. int i = 0;
  41482. if (lastAtom != 0)
  41483. {
  41484. if (! CharacterFunctions::isWhitespace (lastAtom->atomText.getLastCharacter()))
  41485. {
  41486. TextAtom* const first = other.getAtom(0);
  41487. if (! CharacterFunctions::isWhitespace (first->atomText[0]))
  41488. {
  41489. lastAtom->atomText += first->atomText;
  41490. lastAtom->numChars = (uint16) (lastAtom->numChars + first->numChars);
  41491. lastAtom->width = font.getStringWidthFloat (lastAtom->getText (passwordCharacter));
  41492. delete first;
  41493. ++i;
  41494. }
  41495. }
  41496. }
  41497. atoms.ensureStorageAllocated (atoms.size() + other.atoms.size() - i);
  41498. while (i < other.atoms.size())
  41499. {
  41500. atoms.add (other.getAtom(i));
  41501. ++i;
  41502. }
  41503. }
  41504. }
  41505. UniformTextSection* split (const int indexToBreakAt,
  41506. const tchar passwordCharacter)
  41507. {
  41508. UniformTextSection* const section2 = new UniformTextSection (String::empty,
  41509. font, colour,
  41510. passwordCharacter);
  41511. int index = 0;
  41512. for (int i = 0; i < atoms.size(); ++i)
  41513. {
  41514. TextAtom* const atom = getAtom(i);
  41515. const int nextIndex = index + atom->numChars;
  41516. if (index == indexToBreakAt)
  41517. {
  41518. int j;
  41519. for (j = i; j < atoms.size(); ++j)
  41520. section2->atoms.add (getAtom (j));
  41521. for (j = atoms.size(); --j >= i;)
  41522. atoms.remove (j);
  41523. break;
  41524. }
  41525. else if (indexToBreakAt >= index && indexToBreakAt < nextIndex)
  41526. {
  41527. TextAtom* const secondAtom = new TextAtom();
  41528. secondAtom->atomText = atom->atomText.substring (indexToBreakAt - index);
  41529. secondAtom->width = font.getStringWidthFloat (secondAtom->getText (passwordCharacter));
  41530. secondAtom->numChars = (uint16) secondAtom->atomText.length();
  41531. section2->atoms.add (secondAtom);
  41532. atom->atomText = atom->atomText.substring (0, indexToBreakAt - index);
  41533. atom->width = font.getStringWidthFloat (atom->getText (passwordCharacter));
  41534. atom->numChars = (uint16) (indexToBreakAt - index);
  41535. int j;
  41536. for (j = i + 1; j < atoms.size(); ++j)
  41537. section2->atoms.add (getAtom (j));
  41538. for (j = atoms.size(); --j > i;)
  41539. atoms.remove (j);
  41540. break;
  41541. }
  41542. index = nextIndex;
  41543. }
  41544. return section2;
  41545. }
  41546. void appendAllText (String::Concatenator& concatenator) const
  41547. {
  41548. for (int i = 0; i < atoms.size(); ++i)
  41549. concatenator.append (getAtom(i)->atomText);
  41550. }
  41551. void appendSubstring (String::Concatenator& concatenator,
  41552. const int startCharacter,
  41553. const int endCharacter) const
  41554. {
  41555. int index = 0;
  41556. for (int i = 0; i < atoms.size(); ++i)
  41557. {
  41558. const TextAtom* const atom = getAtom (i);
  41559. const int nextIndex = index + atom->numChars;
  41560. if (startCharacter < nextIndex)
  41561. {
  41562. if (endCharacter <= index)
  41563. break;
  41564. const int start = jmax (0, startCharacter - index);
  41565. const int end = jmin (endCharacter - index, (int) atom->numChars);
  41566. if (start < end)
  41567. concatenator.append (atom->atomText.substring (start, end));
  41568. }
  41569. index = nextIndex;
  41570. }
  41571. }
  41572. int getTotalLength() const
  41573. {
  41574. int total = 0;
  41575. for (int i = atoms.size(); --i >= 0;)
  41576. total += getAtom(i)->numChars;
  41577. return total;
  41578. }
  41579. void setFont (const Font& newFont,
  41580. const tchar passwordCharacter)
  41581. {
  41582. if (font != newFont)
  41583. {
  41584. font = newFont;
  41585. for (int i = atoms.size(); --i >= 0;)
  41586. {
  41587. TextAtom* const atom = (TextAtom*) atoms.getUnchecked(i);
  41588. atom->width = newFont.getStringWidthFloat (atom->getText (passwordCharacter));
  41589. }
  41590. }
  41591. }
  41592. juce_UseDebuggingNewOperator
  41593. Font font;
  41594. Colour colour;
  41595. private:
  41596. VoidArray atoms;
  41597. void initialiseAtoms (const String& textToParse,
  41598. const tchar passwordCharacter)
  41599. {
  41600. int i = 0;
  41601. const int len = textToParse.length();
  41602. const tchar* const text = (const tchar*) textToParse;
  41603. while (i < len)
  41604. {
  41605. int start = i;
  41606. // create a whitespace atom unless it starts with non-ws
  41607. if (CharacterFunctions::isWhitespace (text[i])
  41608. && text[i] != T('\r')
  41609. && text[i] != T('\n'))
  41610. {
  41611. while (i < len
  41612. && CharacterFunctions::isWhitespace (text[i])
  41613. && text[i] != T('\r')
  41614. && text[i] != T('\n'))
  41615. {
  41616. ++i;
  41617. }
  41618. }
  41619. else
  41620. {
  41621. if (text[i] == T('\r'))
  41622. {
  41623. ++i;
  41624. if ((i < len) && (text[i] == T('\n')))
  41625. {
  41626. ++start;
  41627. ++i;
  41628. }
  41629. }
  41630. else if (text[i] == T('\n'))
  41631. {
  41632. ++i;
  41633. }
  41634. else
  41635. {
  41636. while ((i < len) && ! CharacterFunctions::isWhitespace (text[i]))
  41637. ++i;
  41638. }
  41639. }
  41640. TextAtom* const atom = new TextAtom();
  41641. atom->atomText = String (text + start, i - start);
  41642. atom->width = font.getStringWidthFloat (atom->getText (passwordCharacter));
  41643. atom->numChars = (uint16) (i - start);
  41644. atoms.add (atom);
  41645. }
  41646. }
  41647. const UniformTextSection& operator= (const UniformTextSection& other);
  41648. };
  41649. class TextEditorIterator
  41650. {
  41651. public:
  41652. TextEditorIterator (const VoidArray& sections_,
  41653. const float wordWrapWidth_,
  41654. const tchar passwordCharacter_)
  41655. : indexInText (0),
  41656. lineY (0),
  41657. lineHeight (0),
  41658. maxDescent (0),
  41659. atomX (0),
  41660. atomRight (0),
  41661. atom (0),
  41662. currentSection (0),
  41663. sections (sections_),
  41664. sectionIndex (0),
  41665. atomIndex (0),
  41666. wordWrapWidth (wordWrapWidth_),
  41667. passwordCharacter (passwordCharacter_)
  41668. {
  41669. jassert (wordWrapWidth_ > 0);
  41670. if (sections.size() > 0)
  41671. {
  41672. currentSection = (const UniformTextSection*) sections.getUnchecked (sectionIndex);
  41673. if (currentSection != 0)
  41674. beginNewLine();
  41675. }
  41676. }
  41677. TextEditorIterator (const TextEditorIterator& other)
  41678. : indexInText (other.indexInText),
  41679. lineY (other.lineY),
  41680. lineHeight (other.lineHeight),
  41681. maxDescent (other.maxDescent),
  41682. atomX (other.atomX),
  41683. atomRight (other.atomRight),
  41684. atom (other.atom),
  41685. currentSection (other.currentSection),
  41686. sections (other.sections),
  41687. sectionIndex (other.sectionIndex),
  41688. atomIndex (other.atomIndex),
  41689. wordWrapWidth (other.wordWrapWidth),
  41690. passwordCharacter (other.passwordCharacter),
  41691. tempAtom (other.tempAtom)
  41692. {
  41693. }
  41694. ~TextEditorIterator()
  41695. {
  41696. }
  41697. bool next()
  41698. {
  41699. if (atom == &tempAtom)
  41700. {
  41701. const int numRemaining = tempAtom.atomText.length() - tempAtom.numChars;
  41702. if (numRemaining > 0)
  41703. {
  41704. tempAtom.atomText = tempAtom.atomText.substring (tempAtom.numChars);
  41705. atomX = 0;
  41706. if (tempAtom.numChars > 0)
  41707. lineY += lineHeight;
  41708. indexInText += tempAtom.numChars;
  41709. GlyphArrangement g;
  41710. g.addLineOfText (currentSection->font, atom->getText (passwordCharacter), 0.0f, 0.0f);
  41711. int split;
  41712. for (split = 0; split < g.getNumGlyphs(); ++split)
  41713. if (shouldWrap (g.getGlyph (split).getRight()))
  41714. break;
  41715. if (split > 0 && split <= numRemaining)
  41716. {
  41717. tempAtom.numChars = (uint16) split;
  41718. tempAtom.width = g.getGlyph (split - 1).getRight();
  41719. atomRight = atomX + tempAtom.width;
  41720. return true;
  41721. }
  41722. }
  41723. }
  41724. bool forceNewLine = false;
  41725. if (sectionIndex >= sections.size())
  41726. {
  41727. moveToEndOfLastAtom();
  41728. return false;
  41729. }
  41730. else if (atomIndex >= currentSection->getNumAtoms() - 1)
  41731. {
  41732. if (atomIndex >= currentSection->getNumAtoms())
  41733. {
  41734. if (++sectionIndex >= sections.size())
  41735. {
  41736. moveToEndOfLastAtom();
  41737. return false;
  41738. }
  41739. atomIndex = 0;
  41740. currentSection = (const UniformTextSection*) sections.getUnchecked (sectionIndex);
  41741. }
  41742. else
  41743. {
  41744. const TextAtom* const lastAtom = currentSection->getAtom (atomIndex);
  41745. if (! lastAtom->isWhitespace())
  41746. {
  41747. // handle the case where the last atom in a section is actually part of the same
  41748. // word as the first atom of the next section...
  41749. float right = atomRight + lastAtom->width;
  41750. float lineHeight2 = lineHeight;
  41751. float maxDescent2 = maxDescent;
  41752. for (int section = sectionIndex + 1; section < sections.size(); ++section)
  41753. {
  41754. const UniformTextSection* const s = (const UniformTextSection*) sections.getUnchecked (section);
  41755. if (s->getNumAtoms() == 0)
  41756. break;
  41757. const TextAtom* const nextAtom = s->getAtom (0);
  41758. if (nextAtom->isWhitespace())
  41759. break;
  41760. right += nextAtom->width;
  41761. lineHeight2 = jmax (lineHeight2, s->font.getHeight());
  41762. maxDescent2 = jmax (maxDescent2, s->font.getDescent());
  41763. if (shouldWrap (right))
  41764. {
  41765. lineHeight = lineHeight2;
  41766. maxDescent = maxDescent2;
  41767. forceNewLine = true;
  41768. break;
  41769. }
  41770. if (s->getNumAtoms() > 1)
  41771. break;
  41772. }
  41773. }
  41774. }
  41775. }
  41776. if (atom != 0)
  41777. {
  41778. atomX = atomRight;
  41779. indexInText += atom->numChars;
  41780. if (atom->isNewLine())
  41781. beginNewLine();
  41782. }
  41783. atom = currentSection->getAtom (atomIndex);
  41784. atomRight = atomX + atom->width;
  41785. ++atomIndex;
  41786. if (shouldWrap (atomRight) || forceNewLine)
  41787. {
  41788. if (atom->isWhitespace())
  41789. {
  41790. // leave whitespace at the end of a line, but truncate it to avoid scrolling
  41791. atomRight = jmin (atomRight, wordWrapWidth);
  41792. }
  41793. else
  41794. {
  41795. atomRight = atom->width;
  41796. if (shouldWrap (atomRight)) // atom too big to fit on a line, so break it up..
  41797. {
  41798. tempAtom = *atom;
  41799. tempAtom.width = 0;
  41800. tempAtom.numChars = 0;
  41801. atom = &tempAtom;
  41802. if (atomX > 0)
  41803. beginNewLine();
  41804. return next();
  41805. }
  41806. beginNewLine();
  41807. return true;
  41808. }
  41809. }
  41810. return true;
  41811. }
  41812. void beginNewLine()
  41813. {
  41814. atomX = 0;
  41815. lineY += lineHeight;
  41816. int tempSectionIndex = sectionIndex;
  41817. int tempAtomIndex = atomIndex;
  41818. const UniformTextSection* section = (const UniformTextSection*) sections.getUnchecked (tempSectionIndex);
  41819. lineHeight = section->font.getHeight();
  41820. maxDescent = section->font.getDescent();
  41821. float x = (atom != 0) ? atom->width : 0;
  41822. while (! shouldWrap (x))
  41823. {
  41824. if (tempSectionIndex >= sections.size())
  41825. break;
  41826. bool checkSize = false;
  41827. if (tempAtomIndex >= section->getNumAtoms())
  41828. {
  41829. if (++tempSectionIndex >= sections.size())
  41830. break;
  41831. tempAtomIndex = 0;
  41832. section = (const UniformTextSection*) sections.getUnchecked (tempSectionIndex);
  41833. checkSize = true;
  41834. }
  41835. const TextAtom* const nextAtom = section->getAtom (tempAtomIndex);
  41836. if (nextAtom == 0)
  41837. break;
  41838. x += nextAtom->width;
  41839. if (shouldWrap (x) || nextAtom->isNewLine())
  41840. break;
  41841. if (checkSize)
  41842. {
  41843. lineHeight = jmax (lineHeight, section->font.getHeight());
  41844. maxDescent = jmax (maxDescent, section->font.getDescent());
  41845. }
  41846. ++tempAtomIndex;
  41847. }
  41848. }
  41849. void draw (Graphics& g, const UniformTextSection*& lastSection) const
  41850. {
  41851. if (passwordCharacter != 0 || ! atom->isWhitespace())
  41852. {
  41853. if (lastSection != currentSection)
  41854. {
  41855. lastSection = currentSection;
  41856. g.setColour (currentSection->colour);
  41857. g.setFont (currentSection->font);
  41858. }
  41859. jassert (atom->getTrimmedText (passwordCharacter).isNotEmpty());
  41860. GlyphArrangement ga;
  41861. ga.addLineOfText (currentSection->font,
  41862. atom->getTrimmedText (passwordCharacter),
  41863. atomX,
  41864. (float) roundToInt (lineY + lineHeight - maxDescent));
  41865. ga.draw (g);
  41866. }
  41867. }
  41868. void drawSelection (Graphics& g,
  41869. const int selectionStart,
  41870. const int selectionEnd) const
  41871. {
  41872. const int startX = roundToInt (indexToX (selectionStart));
  41873. const int endX = roundToInt (indexToX (selectionEnd));
  41874. const int y = roundToInt (lineY);
  41875. const int nextY = roundToInt (lineY + lineHeight);
  41876. g.fillRect (startX, y, endX - startX, nextY - y);
  41877. }
  41878. void drawSelectedText (Graphics& g,
  41879. const int selectionStart,
  41880. const int selectionEnd,
  41881. const Colour& selectedTextColour) const
  41882. {
  41883. if (passwordCharacter != 0 || ! atom->isWhitespace())
  41884. {
  41885. GlyphArrangement ga;
  41886. ga.addLineOfText (currentSection->font,
  41887. atom->getTrimmedText (passwordCharacter),
  41888. atomX,
  41889. (float) roundToInt (lineY + lineHeight - maxDescent));
  41890. if (selectionEnd < indexInText + atom->numChars)
  41891. {
  41892. GlyphArrangement ga2 (ga);
  41893. ga2.removeRangeOfGlyphs (0, selectionEnd - indexInText);
  41894. ga.removeRangeOfGlyphs (selectionEnd - indexInText, -1);
  41895. g.setColour (currentSection->colour);
  41896. ga2.draw (g);
  41897. }
  41898. if (selectionStart > indexInText)
  41899. {
  41900. GlyphArrangement ga2 (ga);
  41901. ga2.removeRangeOfGlyphs (selectionStart - indexInText, -1);
  41902. ga.removeRangeOfGlyphs (0, selectionStart - indexInText);
  41903. g.setColour (currentSection->colour);
  41904. ga2.draw (g);
  41905. }
  41906. g.setColour (selectedTextColour);
  41907. ga.draw (g);
  41908. }
  41909. }
  41910. float indexToX (const int indexToFind) const
  41911. {
  41912. if (indexToFind <= indexInText)
  41913. return atomX;
  41914. if (indexToFind >= indexInText + atom->numChars)
  41915. return atomRight;
  41916. GlyphArrangement g;
  41917. g.addLineOfText (currentSection->font,
  41918. atom->getText (passwordCharacter),
  41919. atomX, 0.0f);
  41920. if (indexToFind - indexInText >= g.getNumGlyphs())
  41921. return atomRight;
  41922. return jmin (atomRight, g.getGlyph (indexToFind - indexInText).getLeft());
  41923. }
  41924. int xToIndex (const float xToFind) const
  41925. {
  41926. if (xToFind <= atomX || atom->isNewLine())
  41927. return indexInText;
  41928. if (xToFind >= atomRight)
  41929. return indexInText + atom->numChars;
  41930. GlyphArrangement g;
  41931. g.addLineOfText (currentSection->font,
  41932. atom->getText (passwordCharacter),
  41933. atomX, 0.0f);
  41934. int j;
  41935. for (j = 0; j < g.getNumGlyphs(); ++j)
  41936. if ((g.getGlyph(j).getLeft() + g.getGlyph(j).getRight()) / 2 > xToFind)
  41937. break;
  41938. return indexInText + j;
  41939. }
  41940. bool getCharPosition (const int index, float& cx, float& cy, float& lineHeight_)
  41941. {
  41942. while (next())
  41943. {
  41944. if (indexInText + atom->numChars > index)
  41945. {
  41946. cx = indexToX (index);
  41947. cy = lineY;
  41948. lineHeight_ = lineHeight;
  41949. return true;
  41950. }
  41951. }
  41952. cx = atomX;
  41953. cy = lineY;
  41954. lineHeight_ = lineHeight;
  41955. return false;
  41956. }
  41957. juce_UseDebuggingNewOperator
  41958. int indexInText;
  41959. float lineY, lineHeight, maxDescent;
  41960. float atomX, atomRight;
  41961. const TextAtom* atom;
  41962. const UniformTextSection* currentSection;
  41963. private:
  41964. const VoidArray& sections;
  41965. int sectionIndex, atomIndex;
  41966. const float wordWrapWidth;
  41967. const tchar passwordCharacter;
  41968. TextAtom tempAtom;
  41969. const TextEditorIterator& operator= (const TextEditorIterator&);
  41970. void moveToEndOfLastAtom()
  41971. {
  41972. if (atom != 0)
  41973. {
  41974. atomX = atomRight;
  41975. if (atom->isNewLine())
  41976. {
  41977. atomX = 0.0f;
  41978. lineY += lineHeight;
  41979. }
  41980. }
  41981. }
  41982. bool shouldWrap (const float x) const
  41983. {
  41984. return (x - 0.0001f) >= wordWrapWidth;
  41985. }
  41986. };
  41987. class TextEditorInsertAction : public UndoableAction
  41988. {
  41989. TextEditor& owner;
  41990. const String text;
  41991. const int insertIndex, oldCaretPos, newCaretPos;
  41992. const Font font;
  41993. const Colour colour;
  41994. TextEditorInsertAction (const TextEditorInsertAction&);
  41995. const TextEditorInsertAction& operator= (const TextEditorInsertAction&);
  41996. public:
  41997. TextEditorInsertAction (TextEditor& owner_,
  41998. const String& text_,
  41999. const int insertIndex_,
  42000. const Font& font_,
  42001. const Colour& colour_,
  42002. const int oldCaretPos_,
  42003. const int newCaretPos_)
  42004. : owner (owner_),
  42005. text (text_),
  42006. insertIndex (insertIndex_),
  42007. oldCaretPos (oldCaretPos_),
  42008. newCaretPos (newCaretPos_),
  42009. font (font_),
  42010. colour (colour_)
  42011. {
  42012. }
  42013. ~TextEditorInsertAction()
  42014. {
  42015. }
  42016. bool perform()
  42017. {
  42018. owner.insert (text, insertIndex, font, colour, 0, newCaretPos);
  42019. return true;
  42020. }
  42021. bool undo()
  42022. {
  42023. owner.remove (insertIndex, insertIndex + text.length(), 0, oldCaretPos);
  42024. return true;
  42025. }
  42026. int getSizeInUnits()
  42027. {
  42028. return text.length() + 16;
  42029. }
  42030. };
  42031. class TextEditorRemoveAction : public UndoableAction
  42032. {
  42033. TextEditor& owner;
  42034. const int startIndex, endIndex, oldCaretPos, newCaretPos;
  42035. VoidArray removedSections;
  42036. TextEditorRemoveAction (const TextEditorRemoveAction&);
  42037. const TextEditorRemoveAction& operator= (const TextEditorRemoveAction&);
  42038. public:
  42039. TextEditorRemoveAction (TextEditor& owner_,
  42040. const int startIndex_,
  42041. const int endIndex_,
  42042. const int oldCaretPos_,
  42043. const int newCaretPos_,
  42044. const VoidArray& removedSections_)
  42045. : owner (owner_),
  42046. startIndex (startIndex_),
  42047. endIndex (endIndex_),
  42048. oldCaretPos (oldCaretPos_),
  42049. newCaretPos (newCaretPos_),
  42050. removedSections (removedSections_)
  42051. {
  42052. }
  42053. ~TextEditorRemoveAction()
  42054. {
  42055. for (int i = removedSections.size(); --i >= 0;)
  42056. {
  42057. UniformTextSection* const section = (UniformTextSection*) removedSections.getUnchecked (i);
  42058. section->clear();
  42059. delete section;
  42060. }
  42061. }
  42062. bool perform()
  42063. {
  42064. owner.remove (startIndex, endIndex, 0, newCaretPos);
  42065. return true;
  42066. }
  42067. bool undo()
  42068. {
  42069. owner.reinsert (startIndex, removedSections);
  42070. owner.moveCursorTo (oldCaretPos, false);
  42071. return true;
  42072. }
  42073. int getSizeInUnits()
  42074. {
  42075. int n = 0;
  42076. for (int i = removedSections.size(); --i >= 0;)
  42077. {
  42078. UniformTextSection* const section = (UniformTextSection*) removedSections.getUnchecked (i);
  42079. n += section->getTotalLength();
  42080. }
  42081. return n + 16;
  42082. }
  42083. };
  42084. class TextHolderComponent : public Component,
  42085. public Timer,
  42086. public Value::Listener
  42087. {
  42088. TextEditor& owner;
  42089. TextHolderComponent (const TextHolderComponent&);
  42090. const TextHolderComponent& operator= (const TextHolderComponent&);
  42091. public:
  42092. TextHolderComponent (TextEditor& owner_)
  42093. : owner (owner_)
  42094. {
  42095. setWantsKeyboardFocus (false);
  42096. setInterceptsMouseClicks (false, true);
  42097. owner.getTextValue().addListener (this);
  42098. }
  42099. ~TextHolderComponent()
  42100. {
  42101. owner.getTextValue().removeListener (this);
  42102. }
  42103. void paint (Graphics& g)
  42104. {
  42105. owner.drawContent (g);
  42106. }
  42107. void timerCallback()
  42108. {
  42109. owner.timerCallbackInt();
  42110. }
  42111. const MouseCursor getMouseCursor()
  42112. {
  42113. return owner.getMouseCursor();
  42114. }
  42115. void valueChanged (Value&)
  42116. {
  42117. owner.textWasChangedByValue();
  42118. }
  42119. };
  42120. class TextEditorViewport : public Viewport
  42121. {
  42122. TextEditor* const owner;
  42123. float lastWordWrapWidth;
  42124. TextEditorViewport (const TextEditorViewport&);
  42125. const TextEditorViewport& operator= (const TextEditorViewport&);
  42126. public:
  42127. TextEditorViewport (TextEditor* const owner_)
  42128. : owner (owner_),
  42129. lastWordWrapWidth (0)
  42130. {
  42131. }
  42132. ~TextEditorViewport()
  42133. {
  42134. }
  42135. void visibleAreaChanged (int, int, int, int)
  42136. {
  42137. const float wordWrapWidth = owner->getWordWrapWidth();
  42138. if (wordWrapWidth != lastWordWrapWidth)
  42139. {
  42140. lastWordWrapWidth = wordWrapWidth;
  42141. owner->updateTextHolderSize();
  42142. }
  42143. }
  42144. };
  42145. namespace TextEditorDefs
  42146. {
  42147. const int flashSpeedIntervalMs = 380;
  42148. const int textChangeMessageId = 0x10003001;
  42149. const int returnKeyMessageId = 0x10003002;
  42150. const int escapeKeyMessageId = 0x10003003;
  42151. const int focusLossMessageId = 0x10003004;
  42152. const int maxActionsPerTransaction = 100;
  42153. }
  42154. TextEditor::TextEditor (const String& name,
  42155. const tchar passwordCharacter_)
  42156. : Component (name),
  42157. borderSize (1, 1, 1, 3),
  42158. readOnly (false),
  42159. multiline (false),
  42160. wordWrap (false),
  42161. returnKeyStartsNewLine (false),
  42162. caretVisible (true),
  42163. popupMenuEnabled (true),
  42164. selectAllTextWhenFocused (false),
  42165. scrollbarVisible (true),
  42166. wasFocused (false),
  42167. caretFlashState (true),
  42168. keepCursorOnScreen (true),
  42169. tabKeyUsed (false),
  42170. menuActive (false),
  42171. valueTextNeedsUpdating (false),
  42172. cursorX (0),
  42173. cursorY (0),
  42174. cursorHeight (0),
  42175. maxTextLength (0),
  42176. selectionStart (0),
  42177. selectionEnd (0),
  42178. leftIndent (4),
  42179. topIndent (4),
  42180. lastTransactionTime (0),
  42181. currentFont (14.0f),
  42182. totalNumChars (0),
  42183. caretPosition (0),
  42184. passwordCharacter (passwordCharacter_),
  42185. dragType (notDragging)
  42186. {
  42187. setOpaque (true);
  42188. addAndMakeVisible (viewport = new TextEditorViewport (this));
  42189. viewport->setViewedComponent (textHolder = new TextHolderComponent (*this));
  42190. viewport->setWantsKeyboardFocus (false);
  42191. viewport->setScrollBarsShown (false, false);
  42192. setMouseCursor (MouseCursor::IBeamCursor);
  42193. setWantsKeyboardFocus (true);
  42194. }
  42195. TextEditor::~TextEditor()
  42196. {
  42197. textValue.referTo (Value());
  42198. clearInternal (0);
  42199. viewport = 0;
  42200. textHolder = 0;
  42201. }
  42202. void TextEditor::newTransaction()
  42203. {
  42204. lastTransactionTime = Time::getApproximateMillisecondCounter();
  42205. undoManager.beginNewTransaction();
  42206. }
  42207. void TextEditor::doUndoRedo (const bool isRedo)
  42208. {
  42209. if (! isReadOnly())
  42210. {
  42211. if ((isRedo) ? undoManager.redo()
  42212. : undoManager.undo())
  42213. {
  42214. scrollToMakeSureCursorIsVisible();
  42215. repaint();
  42216. textChanged();
  42217. }
  42218. }
  42219. }
  42220. void TextEditor::setMultiLine (const bool shouldBeMultiLine,
  42221. const bool shouldWordWrap)
  42222. {
  42223. multiline = shouldBeMultiLine;
  42224. wordWrap = shouldWordWrap && shouldBeMultiLine;
  42225. setScrollbarsShown (scrollbarVisible);
  42226. viewport->setViewPosition (0, 0);
  42227. resized();
  42228. scrollToMakeSureCursorIsVisible();
  42229. }
  42230. bool TextEditor::isMultiLine() const
  42231. {
  42232. return multiline;
  42233. }
  42234. void TextEditor::setScrollbarsShown (bool enabled)
  42235. {
  42236. scrollbarVisible = enabled;
  42237. enabled = enabled && isMultiLine();
  42238. viewport->setScrollBarsShown (enabled, enabled);
  42239. }
  42240. void TextEditor::setReadOnly (const bool shouldBeReadOnly)
  42241. {
  42242. readOnly = shouldBeReadOnly;
  42243. enablementChanged();
  42244. }
  42245. bool TextEditor::isReadOnly() const
  42246. {
  42247. return readOnly || ! isEnabled();
  42248. }
  42249. void TextEditor::setReturnKeyStartsNewLine (const bool shouldStartNewLine)
  42250. {
  42251. returnKeyStartsNewLine = shouldStartNewLine;
  42252. }
  42253. void TextEditor::setTabKeyUsedAsCharacter (const bool shouldTabKeyBeUsed)
  42254. {
  42255. tabKeyUsed = shouldTabKeyBeUsed;
  42256. }
  42257. void TextEditor::setPopupMenuEnabled (const bool b)
  42258. {
  42259. popupMenuEnabled = b;
  42260. }
  42261. void TextEditor::setSelectAllWhenFocused (const bool b)
  42262. {
  42263. selectAllTextWhenFocused = b;
  42264. }
  42265. const Font TextEditor::getFont() const
  42266. {
  42267. return currentFont;
  42268. }
  42269. void TextEditor::setFont (const Font& newFont)
  42270. {
  42271. currentFont = newFont;
  42272. scrollToMakeSureCursorIsVisible();
  42273. }
  42274. void TextEditor::applyFontToAllText (const Font& newFont)
  42275. {
  42276. currentFont = newFont;
  42277. const Colour overallColour (findColour (textColourId));
  42278. for (int i = sections.size(); --i >= 0;)
  42279. {
  42280. UniformTextSection* const uts = (UniformTextSection*) sections.getUnchecked(i);
  42281. uts->setFont (newFont, passwordCharacter);
  42282. uts->colour = overallColour;
  42283. }
  42284. coalesceSimilarSections();
  42285. updateTextHolderSize();
  42286. scrollToMakeSureCursorIsVisible();
  42287. repaint();
  42288. }
  42289. void TextEditor::colourChanged()
  42290. {
  42291. setOpaque (findColour (backgroundColourId).isOpaque());
  42292. repaint();
  42293. }
  42294. void TextEditor::setCaretVisible (const bool shouldCaretBeVisible)
  42295. {
  42296. caretVisible = shouldCaretBeVisible;
  42297. if (shouldCaretBeVisible)
  42298. textHolder->startTimer (TextEditorDefs::flashSpeedIntervalMs);
  42299. setMouseCursor (shouldCaretBeVisible ? MouseCursor::IBeamCursor
  42300. : MouseCursor::NormalCursor);
  42301. }
  42302. void TextEditor::setInputRestrictions (const int maxLen,
  42303. const String& chars)
  42304. {
  42305. maxTextLength = jmax (0, maxLen);
  42306. allowedCharacters = chars;
  42307. }
  42308. void TextEditor::setTextToShowWhenEmpty (const String& text, const Colour& colourToUse)
  42309. {
  42310. textToShowWhenEmpty = text;
  42311. colourForTextWhenEmpty = colourToUse;
  42312. }
  42313. void TextEditor::setPasswordCharacter (const tchar newPasswordCharacter)
  42314. {
  42315. if (passwordCharacter != newPasswordCharacter)
  42316. {
  42317. passwordCharacter = newPasswordCharacter;
  42318. resized();
  42319. repaint();
  42320. }
  42321. }
  42322. void TextEditor::setScrollBarThickness (const int newThicknessPixels)
  42323. {
  42324. viewport->setScrollBarThickness (newThicknessPixels);
  42325. }
  42326. void TextEditor::setScrollBarButtonVisibility (const bool buttonsVisible)
  42327. {
  42328. viewport->setScrollBarButtonVisibility (buttonsVisible);
  42329. }
  42330. void TextEditor::clear()
  42331. {
  42332. clearInternal (0);
  42333. updateTextHolderSize();
  42334. undoManager.clearUndoHistory();
  42335. }
  42336. void TextEditor::setText (const String& newText,
  42337. const bool sendTextChangeMessage)
  42338. {
  42339. const int newLength = newText.length();
  42340. if (newLength != getTotalNumChars() || getText() != newText)
  42341. {
  42342. const int oldCursorPos = caretPosition;
  42343. const bool cursorWasAtEnd = oldCursorPos >= getTotalNumChars();
  42344. clearInternal (0);
  42345. insert (newText, 0, currentFont, findColour (textColourId), 0, caretPosition);
  42346. // if you're adding text with line-feeds to a single-line text editor, it
  42347. // ain't gonna look right!
  42348. jassert (multiline || ! newText.containsAnyOf (T("\r\n")));
  42349. if (cursorWasAtEnd && ! isMultiLine())
  42350. moveCursorTo (getTotalNumChars(), false);
  42351. else
  42352. moveCursorTo (oldCursorPos, false);
  42353. if (sendTextChangeMessage)
  42354. textChanged();
  42355. repaint();
  42356. }
  42357. updateTextHolderSize();
  42358. scrollToMakeSureCursorIsVisible();
  42359. undoManager.clearUndoHistory();
  42360. }
  42361. Value& TextEditor::getTextValue()
  42362. {
  42363. if (valueTextNeedsUpdating)
  42364. {
  42365. valueTextNeedsUpdating = false;
  42366. textValue = getText();
  42367. }
  42368. return textValue;
  42369. }
  42370. void TextEditor::textWasChangedByValue()
  42371. {
  42372. if (textValue.getValueSource().getReferenceCount() > 1)
  42373. setText (textValue.getValue());
  42374. }
  42375. void TextEditor::textChanged()
  42376. {
  42377. updateTextHolderSize();
  42378. postCommandMessage (TextEditorDefs::textChangeMessageId);
  42379. if (textValue.getValueSource().getReferenceCount() > 1)
  42380. {
  42381. valueTextNeedsUpdating = false;
  42382. textValue = getText();
  42383. }
  42384. }
  42385. void TextEditor::returnPressed()
  42386. {
  42387. postCommandMessage (TextEditorDefs::returnKeyMessageId);
  42388. }
  42389. void TextEditor::escapePressed()
  42390. {
  42391. postCommandMessage (TextEditorDefs::escapeKeyMessageId);
  42392. }
  42393. void TextEditor::addListener (TextEditorListener* const newListener)
  42394. {
  42395. jassert (newListener != 0)
  42396. if (newListener != 0)
  42397. listeners.add (newListener);
  42398. }
  42399. void TextEditor::removeListener (TextEditorListener* const listenerToRemove)
  42400. {
  42401. listeners.removeValue (listenerToRemove);
  42402. }
  42403. void TextEditor::timerCallbackInt()
  42404. {
  42405. const bool newState = (! caretFlashState) && ! isCurrentlyBlockedByAnotherModalComponent();
  42406. if (caretFlashState != newState)
  42407. {
  42408. caretFlashState = newState;
  42409. if (caretFlashState)
  42410. wasFocused = true;
  42411. if (caretVisible
  42412. && hasKeyboardFocus (false)
  42413. && ! isReadOnly())
  42414. {
  42415. repaintCaret();
  42416. }
  42417. }
  42418. const unsigned int now = Time::getApproximateMillisecondCounter();
  42419. if (now > lastTransactionTime + 200)
  42420. newTransaction();
  42421. }
  42422. void TextEditor::repaintCaret()
  42423. {
  42424. if (! findColour (caretColourId).isTransparent())
  42425. repaint (borderSize.getLeft() + textHolder->getX() + leftIndent + roundToInt (cursorX) - 1,
  42426. borderSize.getTop() + textHolder->getY() + topIndent + roundToInt (cursorY) - 1,
  42427. 4,
  42428. roundToInt (cursorHeight) + 2);
  42429. }
  42430. void TextEditor::repaintText (int textStartIndex, int textEndIndex)
  42431. {
  42432. if (textStartIndex > textEndIndex && textEndIndex > 0)
  42433. swapVariables (textStartIndex, textEndIndex);
  42434. float x = 0, y = 0, lh = currentFont.getHeight();
  42435. const float wordWrapWidth = getWordWrapWidth();
  42436. if (wordWrapWidth > 0)
  42437. {
  42438. TextEditorIterator i (sections, wordWrapWidth, passwordCharacter);
  42439. i.getCharPosition (textStartIndex, x, y, lh);
  42440. const int y1 = (int) y;
  42441. int y2;
  42442. if (textEndIndex >= 0)
  42443. {
  42444. i.getCharPosition (textEndIndex, x, y, lh);
  42445. y2 = (int) (y + lh * 2.0f);
  42446. }
  42447. else
  42448. {
  42449. y2 = textHolder->getHeight();
  42450. }
  42451. textHolder->repaint (0, y1, textHolder->getWidth(), y2 - y1);
  42452. }
  42453. }
  42454. void TextEditor::moveCaret (int newCaretPos)
  42455. {
  42456. if (newCaretPos < 0)
  42457. newCaretPos = 0;
  42458. else if (newCaretPos > getTotalNumChars())
  42459. newCaretPos = getTotalNumChars();
  42460. if (newCaretPos != getCaretPosition())
  42461. {
  42462. repaintCaret();
  42463. caretFlashState = true;
  42464. caretPosition = newCaretPos;
  42465. textHolder->startTimer (TextEditorDefs::flashSpeedIntervalMs);
  42466. scrollToMakeSureCursorIsVisible();
  42467. repaintCaret();
  42468. }
  42469. }
  42470. void TextEditor::setCaretPosition (const int newIndex)
  42471. {
  42472. moveCursorTo (newIndex, false);
  42473. }
  42474. int TextEditor::getCaretPosition() const
  42475. {
  42476. return caretPosition;
  42477. }
  42478. void TextEditor::scrollEditorToPositionCaret (const int desiredCaretX,
  42479. const int desiredCaretY)
  42480. {
  42481. updateCaretPosition();
  42482. int vx = roundToInt (cursorX) - desiredCaretX;
  42483. int vy = roundToInt (cursorY) - desiredCaretY;
  42484. if (desiredCaretX < jmax (1, proportionOfWidth (0.05f)))
  42485. {
  42486. vx += desiredCaretX - proportionOfWidth (0.2f);
  42487. }
  42488. else if (desiredCaretX > jmax (0, viewport->getMaximumVisibleWidth() - (wordWrap ? 2 : 10)))
  42489. {
  42490. vx += desiredCaretX + (isMultiLine() ? proportionOfWidth (0.2f) : 10) - viewport->getMaximumVisibleWidth();
  42491. }
  42492. vx = jlimit (0, jmax (0, textHolder->getWidth() + 8 - viewport->getMaximumVisibleWidth()), vx);
  42493. if (! isMultiLine())
  42494. {
  42495. vy = viewport->getViewPositionY();
  42496. }
  42497. else
  42498. {
  42499. vy = jlimit (0, jmax (0, textHolder->getHeight() - viewport->getMaximumVisibleHeight()), vy);
  42500. const int curH = roundToInt (cursorHeight);
  42501. if (desiredCaretY < 0)
  42502. {
  42503. vy = jmax (0, desiredCaretY + vy);
  42504. }
  42505. else if (desiredCaretY > jmax (0, viewport->getMaximumVisibleHeight() - topIndent - curH))
  42506. {
  42507. vy += desiredCaretY + 2 + curH + topIndent - viewport->getMaximumVisibleHeight();
  42508. }
  42509. }
  42510. viewport->setViewPosition (vx, vy);
  42511. }
  42512. const Rectangle TextEditor::getCaretRectangle()
  42513. {
  42514. updateCaretPosition();
  42515. return Rectangle (roundToInt (cursorX) - viewport->getX(),
  42516. roundToInt (cursorY) - viewport->getY(),
  42517. 1, roundToInt (cursorHeight));
  42518. }
  42519. float TextEditor::getWordWrapWidth() const
  42520. {
  42521. return (wordWrap) ? (float) (viewport->getMaximumVisibleWidth() - leftIndent - leftIndent / 2)
  42522. : 1.0e10f;
  42523. }
  42524. void TextEditor::updateTextHolderSize()
  42525. {
  42526. const float wordWrapWidth = getWordWrapWidth();
  42527. if (wordWrapWidth > 0)
  42528. {
  42529. float maxWidth = 0.0f;
  42530. TextEditorIterator i (sections, wordWrapWidth, passwordCharacter);
  42531. while (i.next())
  42532. maxWidth = jmax (maxWidth, i.atomRight);
  42533. const int w = leftIndent + roundToInt (maxWidth);
  42534. const int h = topIndent + roundToInt (jmax (i.lineY + i.lineHeight,
  42535. currentFont.getHeight()));
  42536. textHolder->setSize (w + 1, h + 1);
  42537. }
  42538. }
  42539. int TextEditor::getTextWidth() const
  42540. {
  42541. return textHolder->getWidth();
  42542. }
  42543. int TextEditor::getTextHeight() const
  42544. {
  42545. return textHolder->getHeight();
  42546. }
  42547. void TextEditor::setIndents (const int newLeftIndent,
  42548. const int newTopIndent)
  42549. {
  42550. leftIndent = newLeftIndent;
  42551. topIndent = newTopIndent;
  42552. }
  42553. void TextEditor::setBorder (const BorderSize& border)
  42554. {
  42555. borderSize = border;
  42556. resized();
  42557. }
  42558. const BorderSize TextEditor::getBorder() const
  42559. {
  42560. return borderSize;
  42561. }
  42562. void TextEditor::setScrollToShowCursor (const bool shouldScrollToShowCursor)
  42563. {
  42564. keepCursorOnScreen = shouldScrollToShowCursor;
  42565. }
  42566. void TextEditor::updateCaretPosition()
  42567. {
  42568. cursorHeight = currentFont.getHeight(); // (in case the text is empty and the call below doesn't set this value)
  42569. getCharPosition (caretPosition, cursorX, cursorY, cursorHeight);
  42570. }
  42571. void TextEditor::scrollToMakeSureCursorIsVisible()
  42572. {
  42573. updateCaretPosition();
  42574. if (keepCursorOnScreen)
  42575. {
  42576. int x = viewport->getViewPositionX();
  42577. int y = viewport->getViewPositionY();
  42578. const int relativeCursorX = roundToInt (cursorX) - x;
  42579. const int relativeCursorY = roundToInt (cursorY) - y;
  42580. if (relativeCursorX < jmax (1, proportionOfWidth (0.05f)))
  42581. {
  42582. x += relativeCursorX - proportionOfWidth (0.2f);
  42583. }
  42584. else if (relativeCursorX > jmax (0, viewport->getMaximumVisibleWidth() - (wordWrap ? 2 : 10)))
  42585. {
  42586. x += relativeCursorX + (isMultiLine() ? proportionOfWidth (0.2f) : 10) - viewport->getMaximumVisibleWidth();
  42587. }
  42588. x = jlimit (0, jmax (0, textHolder->getWidth() + 8 - viewport->getMaximumVisibleWidth()), x);
  42589. if (! isMultiLine())
  42590. {
  42591. y = (getHeight() - textHolder->getHeight() - topIndent) / -2;
  42592. }
  42593. else
  42594. {
  42595. const int curH = roundToInt (cursorHeight);
  42596. if (relativeCursorY < 0)
  42597. {
  42598. y = jmax (0, relativeCursorY + y);
  42599. }
  42600. else if (relativeCursorY > jmax (0, viewport->getMaximumVisibleHeight() - topIndent - curH))
  42601. {
  42602. y += relativeCursorY + 2 + curH + topIndent - viewport->getMaximumVisibleHeight();
  42603. }
  42604. }
  42605. viewport->setViewPosition (x, y);
  42606. }
  42607. }
  42608. void TextEditor::moveCursorTo (const int newPosition,
  42609. const bool isSelecting)
  42610. {
  42611. if (isSelecting)
  42612. {
  42613. moveCaret (newPosition);
  42614. const int oldSelStart = selectionStart;
  42615. const int oldSelEnd = selectionEnd;
  42616. if (dragType == notDragging)
  42617. {
  42618. if (abs (getCaretPosition() - selectionStart) < abs (getCaretPosition() - selectionEnd))
  42619. dragType = draggingSelectionStart;
  42620. else
  42621. dragType = draggingSelectionEnd;
  42622. }
  42623. if (dragType == draggingSelectionStart)
  42624. {
  42625. selectionStart = getCaretPosition();
  42626. if (selectionEnd < selectionStart)
  42627. {
  42628. swapVariables (selectionStart, selectionEnd);
  42629. dragType = draggingSelectionEnd;
  42630. }
  42631. }
  42632. else
  42633. {
  42634. selectionEnd = getCaretPosition();
  42635. if (selectionEnd < selectionStart)
  42636. {
  42637. swapVariables (selectionStart, selectionEnd);
  42638. dragType = draggingSelectionStart;
  42639. }
  42640. }
  42641. jassert (selectionStart <= selectionEnd);
  42642. jassert (oldSelStart <= oldSelEnd);
  42643. repaintText (jmin (oldSelStart, selectionStart),
  42644. jmax (oldSelEnd, selectionEnd));
  42645. }
  42646. else
  42647. {
  42648. dragType = notDragging;
  42649. if (selectionEnd > selectionStart)
  42650. repaintText (selectionStart, selectionEnd);
  42651. moveCaret (newPosition);
  42652. selectionStart = getCaretPosition();
  42653. selectionEnd = getCaretPosition();
  42654. }
  42655. }
  42656. int TextEditor::getTextIndexAt (const int x,
  42657. const int y)
  42658. {
  42659. return indexAtPosition ((float) (x + viewport->getViewPositionX() - leftIndent),
  42660. (float) (y + viewport->getViewPositionY() - topIndent));
  42661. }
  42662. void TextEditor::insertTextAtCursor (String newText)
  42663. {
  42664. if (allowedCharacters.isNotEmpty())
  42665. newText = newText.retainCharacters (allowedCharacters);
  42666. if (! isMultiLine())
  42667. newText = newText.replaceCharacters (T("\r\n"), T(" "));
  42668. else
  42669. newText = newText.replace (T("\r\n"), T("\n"));
  42670. const int newCaretPos = selectionStart + newText.length();
  42671. const int insertIndex = selectionStart;
  42672. remove (selectionStart, selectionEnd,
  42673. &undoManager,
  42674. newText.isNotEmpty() ? newCaretPos - 1 : newCaretPos);
  42675. if (maxTextLength > 0)
  42676. newText = newText.substring (0, maxTextLength - getTotalNumChars());
  42677. if (newText.isNotEmpty())
  42678. insert (newText,
  42679. insertIndex,
  42680. currentFont,
  42681. findColour (textColourId),
  42682. &undoManager,
  42683. newCaretPos);
  42684. textChanged();
  42685. }
  42686. void TextEditor::setHighlightedRegion (int startPos, int numChars)
  42687. {
  42688. moveCursorTo (startPos, false);
  42689. moveCursorTo (startPos + numChars, true);
  42690. }
  42691. void TextEditor::copy()
  42692. {
  42693. if (passwordCharacter == 0)
  42694. {
  42695. const String selection (getTextSubstring (selectionStart, selectionEnd));
  42696. if (selection.isNotEmpty())
  42697. SystemClipboard::copyTextToClipboard (selection);
  42698. }
  42699. }
  42700. void TextEditor::paste()
  42701. {
  42702. if (! isReadOnly())
  42703. {
  42704. const String clip (SystemClipboard::getTextFromClipboard());
  42705. if (clip.isNotEmpty())
  42706. insertTextAtCursor (clip);
  42707. }
  42708. }
  42709. void TextEditor::cut()
  42710. {
  42711. if (! isReadOnly())
  42712. {
  42713. moveCaret (selectionEnd);
  42714. insertTextAtCursor (String::empty);
  42715. }
  42716. }
  42717. void TextEditor::drawContent (Graphics& g)
  42718. {
  42719. const float wordWrapWidth = getWordWrapWidth();
  42720. if (wordWrapWidth > 0)
  42721. {
  42722. g.setOrigin (leftIndent, topIndent);
  42723. const Rectangle clip (g.getClipBounds());
  42724. Colour selectedTextColour;
  42725. TextEditorIterator i (sections, wordWrapWidth, passwordCharacter);
  42726. while (i.lineY + 200.0 < clip.getY() && i.next())
  42727. {}
  42728. if (selectionStart < selectionEnd)
  42729. {
  42730. g.setColour (findColour (highlightColourId)
  42731. .withMultipliedAlpha (hasKeyboardFocus (true) ? 1.0f : 0.5f));
  42732. selectedTextColour = findColour (highlightedTextColourId);
  42733. TextEditorIterator i2 (i);
  42734. while (i2.next() && i2.lineY < clip.getBottom())
  42735. {
  42736. if (i2.lineY + i2.lineHeight >= clip.getY()
  42737. && selectionEnd >= i2.indexInText
  42738. && selectionStart <= i2.indexInText + i2.atom->numChars)
  42739. {
  42740. i2.drawSelection (g, selectionStart, selectionEnd);
  42741. }
  42742. }
  42743. }
  42744. const UniformTextSection* lastSection = 0;
  42745. while (i.next() && i.lineY < clip.getBottom())
  42746. {
  42747. if (i.lineY + i.lineHeight >= clip.getY())
  42748. {
  42749. if (selectionEnd >= i.indexInText
  42750. && selectionStart <= i.indexInText + i.atom->numChars)
  42751. {
  42752. i.drawSelectedText (g, selectionStart, selectionEnd, selectedTextColour);
  42753. lastSection = 0;
  42754. }
  42755. else
  42756. {
  42757. i.draw (g, lastSection);
  42758. }
  42759. }
  42760. }
  42761. }
  42762. }
  42763. void TextEditor::paint (Graphics& g)
  42764. {
  42765. getLookAndFeel().fillTextEditorBackground (g, getWidth(), getHeight(), *this);
  42766. }
  42767. void TextEditor::paintOverChildren (Graphics& g)
  42768. {
  42769. if (caretFlashState
  42770. && hasKeyboardFocus (false)
  42771. && caretVisible
  42772. && ! isReadOnly())
  42773. {
  42774. g.setColour (findColour (caretColourId));
  42775. g.fillRect (borderSize.getLeft() + textHolder->getX() + leftIndent + cursorX,
  42776. borderSize.getTop() + textHolder->getY() + topIndent + cursorY,
  42777. 2.0f, cursorHeight);
  42778. }
  42779. if (textToShowWhenEmpty.isNotEmpty()
  42780. && (! hasKeyboardFocus (false))
  42781. && getTotalNumChars() == 0)
  42782. {
  42783. g.setColour (colourForTextWhenEmpty);
  42784. g.setFont (getFont());
  42785. if (isMultiLine())
  42786. {
  42787. g.drawText (textToShowWhenEmpty,
  42788. 0, 0, getWidth(), getHeight(),
  42789. Justification::centred, true);
  42790. }
  42791. else
  42792. {
  42793. g.drawText (textToShowWhenEmpty,
  42794. leftIndent, topIndent,
  42795. viewport->getWidth() - leftIndent,
  42796. viewport->getHeight() - topIndent,
  42797. Justification::centredLeft, true);
  42798. }
  42799. }
  42800. getLookAndFeel().drawTextEditorOutline (g, getWidth(), getHeight(), *this);
  42801. }
  42802. void TextEditor::mouseDown (const MouseEvent& e)
  42803. {
  42804. beginDragAutoRepeat (100);
  42805. newTransaction();
  42806. if (wasFocused || ! selectAllTextWhenFocused)
  42807. {
  42808. if (! (popupMenuEnabled && e.mods.isPopupMenu()))
  42809. {
  42810. moveCursorTo (getTextIndexAt (e.x, e.y),
  42811. e.mods.isShiftDown());
  42812. }
  42813. else
  42814. {
  42815. PopupMenu m;
  42816. m.setLookAndFeel (&getLookAndFeel());
  42817. addPopupMenuItems (m, &e);
  42818. menuActive = true;
  42819. const int result = m.show();
  42820. menuActive = false;
  42821. if (result != 0)
  42822. performPopupMenuAction (result);
  42823. }
  42824. }
  42825. }
  42826. void TextEditor::mouseDrag (const MouseEvent& e)
  42827. {
  42828. if (wasFocused || ! selectAllTextWhenFocused)
  42829. {
  42830. if (! (popupMenuEnabled && e.mods.isPopupMenu()))
  42831. {
  42832. moveCursorTo (getTextIndexAt (e.x, e.y), true);
  42833. }
  42834. }
  42835. }
  42836. void TextEditor::mouseUp (const MouseEvent& e)
  42837. {
  42838. newTransaction();
  42839. textHolder->startTimer (TextEditorDefs::flashSpeedIntervalMs);
  42840. if (wasFocused || ! selectAllTextWhenFocused)
  42841. {
  42842. if (e.mouseWasClicked() && ! (popupMenuEnabled && e.mods.isPopupMenu()))
  42843. {
  42844. moveCaret (getTextIndexAt (e.x, e.y));
  42845. }
  42846. }
  42847. wasFocused = true;
  42848. }
  42849. void TextEditor::mouseDoubleClick (const MouseEvent& e)
  42850. {
  42851. int tokenEnd = getTextIndexAt (e.x, e.y);
  42852. int tokenStart = tokenEnd;
  42853. if (e.getNumberOfClicks() > 3)
  42854. {
  42855. tokenStart = 0;
  42856. tokenEnd = getTotalNumChars();
  42857. }
  42858. else
  42859. {
  42860. const String t (getText());
  42861. const int totalLength = getTotalNumChars();
  42862. while (tokenEnd < totalLength)
  42863. {
  42864. if (CharacterFunctions::isLetterOrDigit (t [tokenEnd]))
  42865. ++tokenEnd;
  42866. else
  42867. break;
  42868. }
  42869. tokenStart = tokenEnd;
  42870. while (tokenStart > 0)
  42871. {
  42872. if (CharacterFunctions::isLetterOrDigit (t [tokenStart - 1]))
  42873. --tokenStart;
  42874. else
  42875. break;
  42876. }
  42877. if (e.getNumberOfClicks() > 2)
  42878. {
  42879. while (tokenEnd < totalLength)
  42880. {
  42881. if (t [tokenEnd] != T('\r') && t [tokenEnd] != T('\n'))
  42882. ++tokenEnd;
  42883. else
  42884. break;
  42885. }
  42886. while (tokenStart > 0)
  42887. {
  42888. if (t [tokenStart - 1] != T('\r') && t [tokenStart - 1] != T('\n'))
  42889. --tokenStart;
  42890. else
  42891. break;
  42892. }
  42893. }
  42894. }
  42895. moveCursorTo (tokenEnd, false);
  42896. moveCursorTo (tokenStart, true);
  42897. }
  42898. void TextEditor::mouseWheelMove (const MouseEvent& e, float wheelIncrementX, float wheelIncrementY)
  42899. {
  42900. if (! viewport->useMouseWheelMoveIfNeeded (e, wheelIncrementX, wheelIncrementY))
  42901. Component::mouseWheelMove (e, wheelIncrementX, wheelIncrementY);
  42902. }
  42903. bool TextEditor::keyPressed (const KeyPress& key)
  42904. {
  42905. if (isReadOnly() && key != KeyPress (T('c'), ModifierKeys::commandModifier, 0))
  42906. return false;
  42907. const bool moveInWholeWordSteps = key.getModifiers().isCtrlDown() || key.getModifiers().isAltDown();
  42908. if (key.isKeyCode (KeyPress::leftKey)
  42909. || key.isKeyCode (KeyPress::upKey))
  42910. {
  42911. newTransaction();
  42912. int newPos;
  42913. if (isMultiLine() && key.isKeyCode (KeyPress::upKey))
  42914. newPos = indexAtPosition (cursorX, cursorY - 1);
  42915. else if (moveInWholeWordSteps)
  42916. newPos = findWordBreakBefore (getCaretPosition());
  42917. else
  42918. newPos = getCaretPosition() - 1;
  42919. moveCursorTo (newPos, key.getModifiers().isShiftDown());
  42920. }
  42921. else if (key.isKeyCode (KeyPress::rightKey)
  42922. || key.isKeyCode (KeyPress::downKey))
  42923. {
  42924. newTransaction();
  42925. int newPos;
  42926. if (isMultiLine() && key.isKeyCode (KeyPress::downKey))
  42927. newPos = indexAtPosition (cursorX, cursorY + cursorHeight + 1);
  42928. else if (moveInWholeWordSteps)
  42929. newPos = findWordBreakAfter (getCaretPosition());
  42930. else
  42931. newPos = getCaretPosition() + 1;
  42932. moveCursorTo (newPos, key.getModifiers().isShiftDown());
  42933. }
  42934. else if (key.isKeyCode (KeyPress::pageDownKey) && isMultiLine())
  42935. {
  42936. newTransaction();
  42937. moveCursorTo (indexAtPosition (cursorX, cursorY + cursorHeight + viewport->getViewHeight()),
  42938. key.getModifiers().isShiftDown());
  42939. }
  42940. else if (key.isKeyCode (KeyPress::pageUpKey) && isMultiLine())
  42941. {
  42942. newTransaction();
  42943. moveCursorTo (indexAtPosition (cursorX, cursorY - viewport->getViewHeight()),
  42944. key.getModifiers().isShiftDown());
  42945. }
  42946. else if (key.isKeyCode (KeyPress::homeKey))
  42947. {
  42948. newTransaction();
  42949. if (isMultiLine() && ! moveInWholeWordSteps)
  42950. moveCursorTo (indexAtPosition (0.0f, cursorY),
  42951. key.getModifiers().isShiftDown());
  42952. else
  42953. moveCursorTo (0, key.getModifiers().isShiftDown());
  42954. }
  42955. else if (key.isKeyCode (KeyPress::endKey))
  42956. {
  42957. newTransaction();
  42958. if (isMultiLine() && ! moveInWholeWordSteps)
  42959. moveCursorTo (indexAtPosition ((float) textHolder->getWidth(), cursorY),
  42960. key.getModifiers().isShiftDown());
  42961. else
  42962. moveCursorTo (getTotalNumChars(), key.getModifiers().isShiftDown());
  42963. }
  42964. else if (key.isKeyCode (KeyPress::backspaceKey))
  42965. {
  42966. if (moveInWholeWordSteps)
  42967. {
  42968. moveCursorTo (findWordBreakBefore (getCaretPosition()), true);
  42969. }
  42970. else
  42971. {
  42972. if (selectionStart == selectionEnd && selectionStart > 0)
  42973. --selectionStart;
  42974. }
  42975. cut();
  42976. }
  42977. else if (key.isKeyCode (KeyPress::deleteKey))
  42978. {
  42979. if (key.getModifiers().isShiftDown())
  42980. copy();
  42981. if (selectionStart == selectionEnd
  42982. && selectionEnd < getTotalNumChars())
  42983. {
  42984. ++selectionEnd;
  42985. }
  42986. cut();
  42987. }
  42988. else if (key == KeyPress (T('c'), ModifierKeys::commandModifier, 0)
  42989. || key == KeyPress (KeyPress::insertKey, ModifierKeys::ctrlModifier, 0))
  42990. {
  42991. newTransaction();
  42992. copy();
  42993. }
  42994. else if (key == KeyPress (T('x'), ModifierKeys::commandModifier, 0))
  42995. {
  42996. newTransaction();
  42997. copy();
  42998. cut();
  42999. }
  43000. else if (key == KeyPress (T('v'), ModifierKeys::commandModifier, 0)
  43001. || key == KeyPress (KeyPress::insertKey, ModifierKeys::shiftModifier, 0))
  43002. {
  43003. newTransaction();
  43004. paste();
  43005. }
  43006. else if (key == KeyPress (T('z'), ModifierKeys::commandModifier, 0))
  43007. {
  43008. newTransaction();
  43009. doUndoRedo (false);
  43010. }
  43011. else if (key == KeyPress (T('y'), ModifierKeys::commandModifier, 0))
  43012. {
  43013. newTransaction();
  43014. doUndoRedo (true);
  43015. }
  43016. else if (key == KeyPress (T('a'), ModifierKeys::commandModifier, 0))
  43017. {
  43018. newTransaction();
  43019. moveCursorTo (getTotalNumChars(), false);
  43020. moveCursorTo (0, true);
  43021. }
  43022. else if (key == KeyPress::returnKey)
  43023. {
  43024. newTransaction();
  43025. if (returnKeyStartsNewLine)
  43026. insertTextAtCursor (T("\n"));
  43027. else
  43028. returnPressed();
  43029. }
  43030. else if (key.isKeyCode (KeyPress::escapeKey))
  43031. {
  43032. newTransaction();
  43033. moveCursorTo (getCaretPosition(), false);
  43034. escapePressed();
  43035. }
  43036. else if (key.getTextCharacter() >= ' '
  43037. || (tabKeyUsed && (key.getTextCharacter() == '\t')))
  43038. {
  43039. insertTextAtCursor (String::charToString (key.getTextCharacter()));
  43040. lastTransactionTime = Time::getApproximateMillisecondCounter();
  43041. }
  43042. else
  43043. {
  43044. return false;
  43045. }
  43046. return true;
  43047. }
  43048. bool TextEditor::keyStateChanged (const bool isKeyDown)
  43049. {
  43050. if (! isKeyDown)
  43051. return false;
  43052. #if JUCE_WIN32
  43053. if (KeyPress (KeyPress::F4Key, ModifierKeys::altModifier, 0).isCurrentlyDown())
  43054. return false; // We need to explicitly allow alt-F4 to pass through on Windows
  43055. #endif
  43056. // (overridden to avoid forwarding key events to the parent)
  43057. return ! ModifierKeys::getCurrentModifiers().isCommandDown();
  43058. }
  43059. const int baseMenuItemID = 0x7fff0000;
  43060. void TextEditor::addPopupMenuItems (PopupMenu& m, const MouseEvent*)
  43061. {
  43062. const bool writable = ! isReadOnly();
  43063. if (passwordCharacter == 0)
  43064. {
  43065. m.addItem (baseMenuItemID + 1, TRANS("cut"), writable);
  43066. m.addItem (baseMenuItemID + 2, TRANS("copy"), selectionStart < selectionEnd);
  43067. m.addItem (baseMenuItemID + 3, TRANS("paste"), writable);
  43068. }
  43069. m.addItem (baseMenuItemID + 4, TRANS("delete"), writable);
  43070. m.addSeparator();
  43071. m.addItem (baseMenuItemID + 5, TRANS("select all"));
  43072. m.addSeparator();
  43073. m.addItem (baseMenuItemID + 6, TRANS("undo"), undoManager.canUndo());
  43074. m.addItem (baseMenuItemID + 7, TRANS("redo"), undoManager.canRedo());
  43075. }
  43076. void TextEditor::performPopupMenuAction (const int menuItemID)
  43077. {
  43078. switch (menuItemID)
  43079. {
  43080. case baseMenuItemID + 1:
  43081. copy();
  43082. cut();
  43083. break;
  43084. case baseMenuItemID + 2:
  43085. copy();
  43086. break;
  43087. case baseMenuItemID + 3:
  43088. paste();
  43089. break;
  43090. case baseMenuItemID + 4:
  43091. cut();
  43092. break;
  43093. case baseMenuItemID + 5:
  43094. moveCursorTo (getTotalNumChars(), false);
  43095. moveCursorTo (0, true);
  43096. break;
  43097. case baseMenuItemID + 6:
  43098. doUndoRedo (false);
  43099. break;
  43100. case baseMenuItemID + 7:
  43101. doUndoRedo (true);
  43102. break;
  43103. default:
  43104. break;
  43105. }
  43106. }
  43107. void TextEditor::focusGained (FocusChangeType)
  43108. {
  43109. newTransaction();
  43110. caretFlashState = true;
  43111. if (selectAllTextWhenFocused)
  43112. {
  43113. moveCursorTo (0, false);
  43114. moveCursorTo (getTotalNumChars(), true);
  43115. }
  43116. repaint();
  43117. if (caretVisible)
  43118. textHolder->startTimer (TextEditorDefs::flashSpeedIntervalMs);
  43119. ComponentPeer* const peer = getPeer();
  43120. if (peer != 0 && ! isReadOnly())
  43121. peer->textInputRequired (getScreenX() - peer->getScreenX(),
  43122. getScreenY() - peer->getScreenY());
  43123. }
  43124. void TextEditor::focusLost (FocusChangeType)
  43125. {
  43126. newTransaction();
  43127. wasFocused = false;
  43128. textHolder->stopTimer();
  43129. caretFlashState = false;
  43130. postCommandMessage (TextEditorDefs::focusLossMessageId);
  43131. repaint();
  43132. }
  43133. void TextEditor::resized()
  43134. {
  43135. viewport->setBoundsInset (borderSize);
  43136. viewport->setSingleStepSizes (16, roundToInt (currentFont.getHeight()));
  43137. updateTextHolderSize();
  43138. if (! isMultiLine())
  43139. {
  43140. scrollToMakeSureCursorIsVisible();
  43141. }
  43142. else
  43143. {
  43144. updateCaretPosition();
  43145. }
  43146. }
  43147. void TextEditor::handleCommandMessage (const int commandId)
  43148. {
  43149. const ComponentDeletionWatcher deletionChecker (this);
  43150. for (int i = listeners.size(); --i >= 0;)
  43151. {
  43152. TextEditorListener* const tl = (TextEditorListener*) listeners [i];
  43153. if (tl != 0)
  43154. {
  43155. switch (commandId)
  43156. {
  43157. case TextEditorDefs::textChangeMessageId:
  43158. tl->textEditorTextChanged (*this);
  43159. break;
  43160. case TextEditorDefs::returnKeyMessageId:
  43161. tl->textEditorReturnKeyPressed (*this);
  43162. break;
  43163. case TextEditorDefs::escapeKeyMessageId:
  43164. tl->textEditorEscapeKeyPressed (*this);
  43165. break;
  43166. case TextEditorDefs::focusLossMessageId:
  43167. tl->textEditorFocusLost (*this);
  43168. break;
  43169. default:
  43170. jassertfalse
  43171. break;
  43172. }
  43173. if (i > 0 && deletionChecker.hasBeenDeleted())
  43174. return;
  43175. }
  43176. }
  43177. }
  43178. void TextEditor::enablementChanged()
  43179. {
  43180. setMouseCursor (MouseCursor (isReadOnly() ? MouseCursor::NormalCursor
  43181. : MouseCursor::IBeamCursor));
  43182. repaint();
  43183. }
  43184. void TextEditor::clearInternal (UndoManager* const um)
  43185. {
  43186. remove (0, getTotalNumChars(), um, caretPosition);
  43187. }
  43188. void TextEditor::insert (const String& text,
  43189. const int insertIndex,
  43190. const Font& font,
  43191. const Colour& colour,
  43192. UndoManager* const um,
  43193. const int caretPositionToMoveTo)
  43194. {
  43195. if (text.isNotEmpty())
  43196. {
  43197. if (um != 0)
  43198. {
  43199. if (um->getNumActionsInCurrentTransaction() > TextEditorDefs::maxActionsPerTransaction)
  43200. newTransaction();
  43201. um->perform (new TextEditorInsertAction (*this,
  43202. text,
  43203. insertIndex,
  43204. font,
  43205. colour,
  43206. caretPosition,
  43207. caretPositionToMoveTo));
  43208. }
  43209. else
  43210. {
  43211. repaintText (insertIndex, -1); // must do this before and after changing the data, in case
  43212. // a line gets moved due to word wrap
  43213. int index = 0;
  43214. int nextIndex = 0;
  43215. for (int i = 0; i < sections.size(); ++i)
  43216. {
  43217. nextIndex = index + ((UniformTextSection*) sections.getUnchecked(i))->getTotalLength();
  43218. if (insertIndex == index)
  43219. {
  43220. sections.insert (i, new UniformTextSection (text,
  43221. font, colour,
  43222. passwordCharacter));
  43223. break;
  43224. }
  43225. else if (insertIndex > index && insertIndex < nextIndex)
  43226. {
  43227. splitSection (i, insertIndex - index);
  43228. sections.insert (i + 1, new UniformTextSection (text,
  43229. font, colour,
  43230. passwordCharacter));
  43231. break;
  43232. }
  43233. index = nextIndex;
  43234. }
  43235. if (nextIndex == insertIndex)
  43236. sections.add (new UniformTextSection (text,
  43237. font, colour,
  43238. passwordCharacter));
  43239. coalesceSimilarSections();
  43240. totalNumChars = -1;
  43241. valueTextNeedsUpdating = true;
  43242. moveCursorTo (caretPositionToMoveTo, false);
  43243. repaintText (insertIndex, -1);
  43244. }
  43245. }
  43246. }
  43247. void TextEditor::reinsert (const int insertIndex,
  43248. const VoidArray& sectionsToInsert)
  43249. {
  43250. int index = 0;
  43251. int nextIndex = 0;
  43252. for (int i = 0; i < sections.size(); ++i)
  43253. {
  43254. nextIndex = index + ((UniformTextSection*) sections.getUnchecked(i))->getTotalLength();
  43255. if (insertIndex == index)
  43256. {
  43257. for (int j = sectionsToInsert.size(); --j >= 0;)
  43258. sections.insert (i, new UniformTextSection (*(UniformTextSection*) sectionsToInsert.getUnchecked(j)));
  43259. break;
  43260. }
  43261. else if (insertIndex > index && insertIndex < nextIndex)
  43262. {
  43263. splitSection (i, insertIndex - index);
  43264. for (int j = sectionsToInsert.size(); --j >= 0;)
  43265. sections.insert (i + 1, new UniformTextSection (*(UniformTextSection*) sectionsToInsert.getUnchecked(j)));
  43266. break;
  43267. }
  43268. index = nextIndex;
  43269. }
  43270. if (nextIndex == insertIndex)
  43271. {
  43272. for (int j = 0; j < sectionsToInsert.size(); ++j)
  43273. sections.add (new UniformTextSection (*(UniformTextSection*) sectionsToInsert.getUnchecked(j)));
  43274. }
  43275. coalesceSimilarSections();
  43276. totalNumChars = -1;
  43277. valueTextNeedsUpdating = true;
  43278. }
  43279. void TextEditor::remove (const int startIndex,
  43280. int endIndex,
  43281. UndoManager* const um,
  43282. const int caretPositionToMoveTo)
  43283. {
  43284. if (endIndex > startIndex)
  43285. {
  43286. int index = 0;
  43287. for (int i = 0; i < sections.size(); ++i)
  43288. {
  43289. const int nextIndex = index + ((UniformTextSection*) sections[i])->getTotalLength();
  43290. if (startIndex > index && startIndex < nextIndex)
  43291. {
  43292. splitSection (i, startIndex - index);
  43293. --i;
  43294. }
  43295. else if (endIndex > index && endIndex < nextIndex)
  43296. {
  43297. splitSection (i, endIndex - index);
  43298. --i;
  43299. }
  43300. else
  43301. {
  43302. index = nextIndex;
  43303. if (index > endIndex)
  43304. break;
  43305. }
  43306. }
  43307. index = 0;
  43308. if (um != 0)
  43309. {
  43310. VoidArray removedSections;
  43311. for (int i = 0; i < sections.size(); ++i)
  43312. {
  43313. if (endIndex <= startIndex)
  43314. break;
  43315. UniformTextSection* const section = (UniformTextSection*) sections.getUnchecked (i);
  43316. const int nextIndex = index + section->getTotalLength();
  43317. if (startIndex <= index && endIndex >= nextIndex)
  43318. removedSections.add (new UniformTextSection (*section));
  43319. index = nextIndex;
  43320. }
  43321. if (um->getNumActionsInCurrentTransaction() > TextEditorDefs::maxActionsPerTransaction)
  43322. newTransaction();
  43323. um->perform (new TextEditorRemoveAction (*this,
  43324. startIndex,
  43325. endIndex,
  43326. caretPosition,
  43327. caretPositionToMoveTo,
  43328. removedSections));
  43329. }
  43330. else
  43331. {
  43332. for (int i = 0; i < sections.size(); ++i)
  43333. {
  43334. if (endIndex <= startIndex)
  43335. break;
  43336. UniformTextSection* const section = (UniformTextSection*) sections.getUnchecked (i);
  43337. const int nextIndex = index + section->getTotalLength();
  43338. if (startIndex <= index && endIndex >= nextIndex)
  43339. {
  43340. sections.remove(i);
  43341. endIndex -= (nextIndex - index);
  43342. section->clear();
  43343. delete section;
  43344. --i;
  43345. }
  43346. else
  43347. {
  43348. index = nextIndex;
  43349. }
  43350. }
  43351. coalesceSimilarSections();
  43352. totalNumChars = -1;
  43353. valueTextNeedsUpdating = true;
  43354. moveCursorTo (caretPositionToMoveTo, false);
  43355. repaintText (startIndex, -1);
  43356. }
  43357. }
  43358. }
  43359. const String TextEditor::getText() const
  43360. {
  43361. String t;
  43362. t.preallocateStorage (getTotalNumChars());
  43363. String::Concatenator concatenator (t);
  43364. for (int i = 0; i < sections.size(); ++i)
  43365. ((const UniformTextSection*) sections.getUnchecked(i))->appendAllText (concatenator);
  43366. return t;
  43367. }
  43368. const String TextEditor::getTextSubstring (const int startCharacter, const int endCharacter) const
  43369. {
  43370. String t;
  43371. if (endCharacter > startCharacter)
  43372. {
  43373. t.preallocateStorage (jmin (getTotalNumChars(), endCharacter - startCharacter));
  43374. String::Concatenator concatenator (t);
  43375. int index = 0;
  43376. for (int i = 0; i < sections.size(); ++i)
  43377. {
  43378. const UniformTextSection* const s = (const UniformTextSection*) sections.getUnchecked(i);
  43379. const int nextIndex = index + s->getTotalLength();
  43380. if (startCharacter < nextIndex)
  43381. {
  43382. if (endCharacter <= index)
  43383. break;
  43384. s->appendSubstring (concatenator,
  43385. startCharacter - index,
  43386. endCharacter - index);
  43387. }
  43388. index = nextIndex;
  43389. }
  43390. }
  43391. return t;
  43392. }
  43393. const String TextEditor::getHighlightedText() const
  43394. {
  43395. return getTextSubstring (selectionStart, selectionEnd);
  43396. }
  43397. int TextEditor::getTotalNumChars() const
  43398. {
  43399. if (totalNumChars < 0)
  43400. {
  43401. totalNumChars = 0;
  43402. for (int i = sections.size(); --i >= 0;)
  43403. totalNumChars += ((const UniformTextSection*) sections.getUnchecked(i))->getTotalLength();
  43404. }
  43405. return totalNumChars;
  43406. }
  43407. bool TextEditor::isEmpty() const
  43408. {
  43409. return getTotalNumChars() == 0;
  43410. }
  43411. void TextEditor::getCharPosition (const int index, float& cx, float& cy, float& lineHeight) const
  43412. {
  43413. const float wordWrapWidth = getWordWrapWidth();
  43414. if (wordWrapWidth > 0 && sections.size() > 0)
  43415. {
  43416. TextEditorIterator i (sections, wordWrapWidth, passwordCharacter);
  43417. i.getCharPosition (index, cx, cy, lineHeight);
  43418. }
  43419. else
  43420. {
  43421. cx = cy = 0;
  43422. lineHeight = currentFont.getHeight();
  43423. }
  43424. }
  43425. int TextEditor::indexAtPosition (const float x, const float y)
  43426. {
  43427. const float wordWrapWidth = getWordWrapWidth();
  43428. if (wordWrapWidth > 0)
  43429. {
  43430. TextEditorIterator i (sections, wordWrapWidth, passwordCharacter);
  43431. while (i.next())
  43432. {
  43433. if (i.lineY + i.lineHeight > y)
  43434. {
  43435. if (i.lineY > y)
  43436. return jmax (0, i.indexInText - 1);
  43437. if (i.atomX >= x)
  43438. return i.indexInText;
  43439. if (x < i.atomRight)
  43440. return i.xToIndex (x);
  43441. }
  43442. }
  43443. }
  43444. return getTotalNumChars();
  43445. }
  43446. static int getCharacterCategory (const tchar character)
  43447. {
  43448. return CharacterFunctions::isLetterOrDigit (character)
  43449. ? 2 : (CharacterFunctions::isWhitespace (character) ? 0 : 1);
  43450. }
  43451. int TextEditor::findWordBreakAfter (const int position) const
  43452. {
  43453. const String t (getTextSubstring (position, position + 512));
  43454. const int totalLength = t.length();
  43455. int i = 0;
  43456. while (i < totalLength && CharacterFunctions::isWhitespace (t[i]))
  43457. ++i;
  43458. const int type = getCharacterCategory (t[i]);
  43459. while (i < totalLength && type == getCharacterCategory (t[i]))
  43460. ++i;
  43461. while (i < totalLength && CharacterFunctions::isWhitespace (t[i]))
  43462. ++i;
  43463. return position + i;
  43464. }
  43465. int TextEditor::findWordBreakBefore (const int position) const
  43466. {
  43467. if (position <= 0)
  43468. return 0;
  43469. const int startOfBuffer = jmax (0, position - 512);
  43470. const String t (getTextSubstring (startOfBuffer, position));
  43471. int i = position - startOfBuffer;
  43472. while (i > 0 && CharacterFunctions::isWhitespace (t [i - 1]))
  43473. --i;
  43474. if (i > 0)
  43475. {
  43476. const int type = getCharacterCategory (t [i - 1]);
  43477. while (i > 0 && type == getCharacterCategory (t [i - 1]))
  43478. --i;
  43479. }
  43480. jassert (startOfBuffer + i >= 0);
  43481. return startOfBuffer + i;
  43482. }
  43483. void TextEditor::splitSection (const int sectionIndex,
  43484. const int charToSplitAt)
  43485. {
  43486. jassert (sections[sectionIndex] != 0);
  43487. sections.insert (sectionIndex + 1,
  43488. ((UniformTextSection*) sections.getUnchecked (sectionIndex))
  43489. ->split (charToSplitAt, passwordCharacter));
  43490. }
  43491. void TextEditor::coalesceSimilarSections()
  43492. {
  43493. for (int i = 0; i < sections.size() - 1; ++i)
  43494. {
  43495. UniformTextSection* const s1 = (UniformTextSection*) sections.getUnchecked (i);
  43496. UniformTextSection* const s2 = (UniformTextSection*) sections.getUnchecked (i + 1);
  43497. if (s1->font == s2->font
  43498. && s1->colour == s2->colour)
  43499. {
  43500. s1->append (*s2, passwordCharacter);
  43501. sections.remove (i + 1);
  43502. delete s2;
  43503. --i;
  43504. }
  43505. }
  43506. }
  43507. END_JUCE_NAMESPACE
  43508. /********* End of inlined file: juce_TextEditor.cpp *********/
  43509. /********* Start of inlined file: juce_Toolbar.cpp *********/
  43510. BEGIN_JUCE_NAMESPACE
  43511. const tchar* const Toolbar::toolbarDragDescriptor = T("_toolbarItem_");
  43512. class ToolbarSpacerComp : public ToolbarItemComponent
  43513. {
  43514. public:
  43515. ToolbarSpacerComp (const int itemId_, const float fixedSize_, const bool drawBar_)
  43516. : ToolbarItemComponent (itemId_, String::empty, false),
  43517. fixedSize (fixedSize_),
  43518. drawBar (drawBar_)
  43519. {
  43520. }
  43521. ~ToolbarSpacerComp()
  43522. {
  43523. }
  43524. bool getToolbarItemSizes (int toolbarThickness, bool /*isToolbarVertical*/,
  43525. int& preferredSize, int& minSize, int& maxSize)
  43526. {
  43527. if (fixedSize <= 0)
  43528. {
  43529. preferredSize = toolbarThickness * 2;
  43530. minSize = 4;
  43531. maxSize = 32768;
  43532. }
  43533. else
  43534. {
  43535. maxSize = roundToInt (toolbarThickness * fixedSize);
  43536. minSize = drawBar ? maxSize : jmin (4, maxSize);
  43537. preferredSize = maxSize;
  43538. if (getEditingMode() == editableOnPalette)
  43539. preferredSize = maxSize = toolbarThickness / (drawBar ? 3 : 2);
  43540. }
  43541. return true;
  43542. }
  43543. void paintButtonArea (Graphics&, int, int, bool, bool)
  43544. {
  43545. }
  43546. void contentAreaChanged (const Rectangle&)
  43547. {
  43548. }
  43549. int getResizeOrder() const throw()
  43550. {
  43551. return fixedSize <= 0 ? 0 : 1;
  43552. }
  43553. void paint (Graphics& g)
  43554. {
  43555. const int w = getWidth();
  43556. const int h = getHeight();
  43557. if (drawBar)
  43558. {
  43559. g.setColour (findColour (Toolbar::separatorColourId, true));
  43560. const float thickness = 0.2f;
  43561. if (isToolbarVertical())
  43562. g.fillRect (w * 0.1f, h * (0.5f - thickness * 0.5f), w * 0.8f, h * thickness);
  43563. else
  43564. g.fillRect (w * (0.5f - thickness * 0.5f), h * 0.1f, w * thickness, h * 0.8f);
  43565. }
  43566. if (getEditingMode() != normalMode && ! drawBar)
  43567. {
  43568. g.setColour (findColour (Toolbar::separatorColourId, true));
  43569. const int indentX = jmin (2, (w - 3) / 2);
  43570. const int indentY = jmin (2, (h - 3) / 2);
  43571. g.drawRect (indentX, indentY, w - indentX * 2, h - indentY * 2, 1);
  43572. if (fixedSize <= 0)
  43573. {
  43574. float x1, y1, x2, y2, x3, y3, x4, y4, hw, hl;
  43575. if (isToolbarVertical())
  43576. {
  43577. x1 = w * 0.5f;
  43578. y1 = h * 0.4f;
  43579. x2 = x1;
  43580. y2 = indentX * 2.0f;
  43581. x3 = x1;
  43582. y3 = h * 0.6f;
  43583. x4 = x1;
  43584. y4 = h - y2;
  43585. hw = w * 0.15f;
  43586. hl = w * 0.2f;
  43587. }
  43588. else
  43589. {
  43590. x1 = w * 0.4f;
  43591. y1 = h * 0.5f;
  43592. x2 = indentX * 2.0f;
  43593. y2 = y1;
  43594. x3 = w * 0.6f;
  43595. y3 = y1;
  43596. x4 = w - x2;
  43597. y4 = y1;
  43598. hw = h * 0.15f;
  43599. hl = h * 0.2f;
  43600. }
  43601. Path p;
  43602. p.addArrow (x1, y1, x2, y2, 1.5f, hw, hl);
  43603. p.addArrow (x3, y3, x4, y4, 1.5f, hw, hl);
  43604. g.fillPath (p);
  43605. }
  43606. }
  43607. }
  43608. juce_UseDebuggingNewOperator
  43609. private:
  43610. const float fixedSize;
  43611. const bool drawBar;
  43612. ToolbarSpacerComp (const ToolbarSpacerComp&);
  43613. const ToolbarSpacerComp& operator= (const ToolbarSpacerComp&);
  43614. };
  43615. class MissingItemsComponent : public PopupMenuCustomComponent
  43616. {
  43617. public:
  43618. MissingItemsComponent (Toolbar& owner_, const int height_)
  43619. : PopupMenuCustomComponent (true),
  43620. owner (owner_),
  43621. height (height_)
  43622. {
  43623. for (int i = owner_.items.size(); --i >= 0;)
  43624. {
  43625. ToolbarItemComponent* const tc = owner_.items.getUnchecked(i);
  43626. if (dynamic_cast <ToolbarSpacerComp*> (tc) == 0 && ! tc->isVisible())
  43627. {
  43628. oldIndexes.insert (0, i);
  43629. addAndMakeVisible (tc, 0);
  43630. }
  43631. }
  43632. layout (400);
  43633. }
  43634. ~MissingItemsComponent()
  43635. {
  43636. // deleting the toolbar while its menu it open??
  43637. jassert (owner.isValidComponent());
  43638. for (int i = 0; i < getNumChildComponents(); ++i)
  43639. {
  43640. ToolbarItemComponent* const tc = dynamic_cast <ToolbarItemComponent*> (getChildComponent (i));
  43641. if (tc != 0)
  43642. {
  43643. tc->setVisible (false);
  43644. const int index = oldIndexes.remove (i);
  43645. owner.addChildComponent (tc, index);
  43646. --i;
  43647. }
  43648. }
  43649. owner.resized();
  43650. }
  43651. void layout (const int preferredWidth)
  43652. {
  43653. const int indent = 8;
  43654. int x = indent;
  43655. int y = indent;
  43656. int maxX = 0;
  43657. for (int i = 0; i < getNumChildComponents(); ++i)
  43658. {
  43659. ToolbarItemComponent* const tc = dynamic_cast <ToolbarItemComponent*> (getChildComponent (i));
  43660. if (tc != 0)
  43661. {
  43662. int preferredSize = 1, minSize = 1, maxSize = 1;
  43663. if (tc->getToolbarItemSizes (height, false, preferredSize, minSize, maxSize))
  43664. {
  43665. if (x + preferredSize > preferredWidth && x > indent)
  43666. {
  43667. x = indent;
  43668. y += height;
  43669. }
  43670. tc->setBounds (x, y, preferredSize, height);
  43671. x += preferredSize;
  43672. maxX = jmax (maxX, x);
  43673. }
  43674. }
  43675. }
  43676. setSize (maxX + 8, y + height + 8);
  43677. }
  43678. void getIdealSize (int& idealWidth, int& idealHeight)
  43679. {
  43680. idealWidth = getWidth();
  43681. idealHeight = getHeight();
  43682. }
  43683. juce_UseDebuggingNewOperator
  43684. private:
  43685. Toolbar& owner;
  43686. const int height;
  43687. Array <int> oldIndexes;
  43688. MissingItemsComponent (const MissingItemsComponent&);
  43689. const MissingItemsComponent& operator= (const MissingItemsComponent&);
  43690. };
  43691. Toolbar::Toolbar()
  43692. : vertical (false),
  43693. isEditingActive (false),
  43694. toolbarStyle (Toolbar::iconsOnly)
  43695. {
  43696. addChildComponent (missingItemsButton = getLookAndFeel().createToolbarMissingItemsButton (*this));
  43697. missingItemsButton->setAlwaysOnTop (true);
  43698. missingItemsButton->addButtonListener (this);
  43699. }
  43700. Toolbar::~Toolbar()
  43701. {
  43702. animator.cancelAllAnimations (true);
  43703. deleteAllChildren();
  43704. }
  43705. void Toolbar::setVertical (const bool shouldBeVertical)
  43706. {
  43707. if (vertical != shouldBeVertical)
  43708. {
  43709. vertical = shouldBeVertical;
  43710. resized();
  43711. }
  43712. }
  43713. void Toolbar::clear()
  43714. {
  43715. for (int i = items.size(); --i >= 0;)
  43716. {
  43717. ToolbarItemComponent* const tc = items.getUnchecked(i);
  43718. items.remove (i);
  43719. delete tc;
  43720. }
  43721. resized();
  43722. }
  43723. ToolbarItemComponent* Toolbar::createItem (ToolbarItemFactory& factory, const int itemId)
  43724. {
  43725. if (itemId == ToolbarItemFactory::separatorBarId)
  43726. return new ToolbarSpacerComp (itemId, 0.1f, true);
  43727. else if (itemId == ToolbarItemFactory::spacerId)
  43728. return new ToolbarSpacerComp (itemId, 0.5f, false);
  43729. else if (itemId == ToolbarItemFactory::flexibleSpacerId)
  43730. return new ToolbarSpacerComp (itemId, 0, false);
  43731. return factory.createItem (itemId);
  43732. }
  43733. void Toolbar::addItemInternal (ToolbarItemFactory& factory,
  43734. const int itemId,
  43735. const int insertIndex)
  43736. {
  43737. // An ID can't be zero - this might indicate a mistake somewhere?
  43738. jassert (itemId != 0);
  43739. ToolbarItemComponent* const tc = createItem (factory, itemId);
  43740. if (tc != 0)
  43741. {
  43742. #ifdef JUCE_DEBUG
  43743. Array <int> allowedIds;
  43744. factory.getAllToolbarItemIds (allowedIds);
  43745. // If your factory can create an item for a given ID, it must also return
  43746. // that ID from its getAllToolbarItemIds() method!
  43747. jassert (allowedIds.contains (itemId));
  43748. #endif
  43749. items.insert (insertIndex, tc);
  43750. addAndMakeVisible (tc, insertIndex);
  43751. }
  43752. }
  43753. void Toolbar::addItem (ToolbarItemFactory& factory,
  43754. const int itemId,
  43755. const int insertIndex)
  43756. {
  43757. addItemInternal (factory, itemId, insertIndex);
  43758. resized();
  43759. }
  43760. void Toolbar::addDefaultItems (ToolbarItemFactory& factoryToUse)
  43761. {
  43762. Array <int> ids;
  43763. factoryToUse.getDefaultItemSet (ids);
  43764. clear();
  43765. for (int i = 0; i < ids.size(); ++i)
  43766. addItemInternal (factoryToUse, ids.getUnchecked (i), -1);
  43767. resized();
  43768. }
  43769. void Toolbar::removeToolbarItem (const int itemIndex)
  43770. {
  43771. ToolbarItemComponent* const tc = getItemComponent (itemIndex);
  43772. if (tc != 0)
  43773. {
  43774. items.removeValue (tc);
  43775. delete tc;
  43776. resized();
  43777. }
  43778. }
  43779. int Toolbar::getNumItems() const throw()
  43780. {
  43781. return items.size();
  43782. }
  43783. int Toolbar::getItemId (const int itemIndex) const throw()
  43784. {
  43785. ToolbarItemComponent* const tc = getItemComponent (itemIndex);
  43786. return tc != 0 ? tc->getItemId() : 0;
  43787. }
  43788. ToolbarItemComponent* Toolbar::getItemComponent (const int itemIndex) const throw()
  43789. {
  43790. return items [itemIndex];
  43791. }
  43792. ToolbarItemComponent* Toolbar::getNextActiveComponent (int index, const int delta) const
  43793. {
  43794. for (;;)
  43795. {
  43796. index += delta;
  43797. ToolbarItemComponent* const tc = getItemComponent (index);
  43798. if (tc == 0)
  43799. break;
  43800. if (tc->isActive)
  43801. return tc;
  43802. }
  43803. return 0;
  43804. }
  43805. void Toolbar::setStyle (const ToolbarItemStyle& newStyle)
  43806. {
  43807. if (toolbarStyle != newStyle)
  43808. {
  43809. toolbarStyle = newStyle;
  43810. updateAllItemPositions (false);
  43811. }
  43812. }
  43813. const String Toolbar::toString() const
  43814. {
  43815. String s (T("TB:"));
  43816. for (int i = 0; i < getNumItems(); ++i)
  43817. s << getItemId(i) << T(' ');
  43818. return s.trimEnd();
  43819. }
  43820. bool Toolbar::restoreFromString (ToolbarItemFactory& factoryToUse,
  43821. const String& savedVersion)
  43822. {
  43823. if (! savedVersion.startsWith (T("TB:")))
  43824. return false;
  43825. StringArray tokens;
  43826. tokens.addTokens (savedVersion.substring (3), false);
  43827. clear();
  43828. for (int i = 0; i < tokens.size(); ++i)
  43829. addItemInternal (factoryToUse, tokens[i].getIntValue(), -1);
  43830. resized();
  43831. return true;
  43832. }
  43833. void Toolbar::paint (Graphics& g)
  43834. {
  43835. getLookAndFeel().paintToolbarBackground (g, getWidth(), getHeight(), *this);
  43836. }
  43837. int Toolbar::getThickness() const throw()
  43838. {
  43839. return vertical ? getWidth() : getHeight();
  43840. }
  43841. int Toolbar::getLength() const throw()
  43842. {
  43843. return vertical ? getHeight() : getWidth();
  43844. }
  43845. void Toolbar::setEditingActive (const bool active)
  43846. {
  43847. if (isEditingActive != active)
  43848. {
  43849. isEditingActive = active;
  43850. updateAllItemPositions (false);
  43851. }
  43852. }
  43853. void Toolbar::resized()
  43854. {
  43855. updateAllItemPositions (false);
  43856. }
  43857. void Toolbar::updateAllItemPositions (const bool animate)
  43858. {
  43859. if (getWidth() > 0 && getHeight() > 0)
  43860. {
  43861. StretchableObjectResizer resizer;
  43862. int i;
  43863. for (i = 0; i < items.size(); ++i)
  43864. {
  43865. ToolbarItemComponent* const tc = items.getUnchecked(i);
  43866. tc->setEditingMode (isEditingActive ? ToolbarItemComponent::editableOnToolbar
  43867. : ToolbarItemComponent::normalMode);
  43868. tc->setStyle (toolbarStyle);
  43869. ToolbarSpacerComp* const spacer = dynamic_cast <ToolbarSpacerComp*> (tc);
  43870. int preferredSize = 1, minSize = 1, maxSize = 1;
  43871. if (tc->getToolbarItemSizes (getThickness(), isVertical(),
  43872. preferredSize, minSize, maxSize))
  43873. {
  43874. tc->isActive = true;
  43875. resizer.addItem (preferredSize, minSize, maxSize,
  43876. spacer != 0 ? spacer->getResizeOrder() : 2);
  43877. }
  43878. else
  43879. {
  43880. tc->isActive = false;
  43881. tc->setVisible (false);
  43882. }
  43883. }
  43884. resizer.resizeToFit (getLength());
  43885. int totalLength = 0;
  43886. for (i = 0; i < resizer.getNumItems(); ++i)
  43887. totalLength += (int) resizer.getItemSize (i);
  43888. const bool itemsOffTheEnd = totalLength > getLength();
  43889. const int extrasButtonSize = getThickness() / 2;
  43890. missingItemsButton->setSize (extrasButtonSize, extrasButtonSize);
  43891. missingItemsButton->setVisible (itemsOffTheEnd);
  43892. missingItemsButton->setEnabled (! isEditingActive);
  43893. if (vertical)
  43894. missingItemsButton->setCentrePosition (getWidth() / 2,
  43895. getHeight() - 4 - extrasButtonSize / 2);
  43896. else
  43897. missingItemsButton->setCentrePosition (getWidth() - 4 - extrasButtonSize / 2,
  43898. getHeight() / 2);
  43899. const int maxLength = itemsOffTheEnd ? (vertical ? missingItemsButton->getY()
  43900. : missingItemsButton->getX()) - 4
  43901. : getLength();
  43902. int pos = 0, activeIndex = 0;
  43903. for (i = 0; i < items.size(); ++i)
  43904. {
  43905. ToolbarItemComponent* const tc = items.getUnchecked(i);
  43906. if (tc->isActive)
  43907. {
  43908. const int size = (int) resizer.getItemSize (activeIndex++);
  43909. Rectangle newBounds;
  43910. if (vertical)
  43911. newBounds.setBounds (0, pos, getWidth(), size);
  43912. else
  43913. newBounds.setBounds (pos, 0, size, getHeight());
  43914. if (animate)
  43915. {
  43916. animator.animateComponent (tc, newBounds, 200, 3.0, 0.0);
  43917. }
  43918. else
  43919. {
  43920. animator.cancelAnimation (tc, false);
  43921. tc->setBounds (newBounds);
  43922. }
  43923. pos += size;
  43924. tc->setVisible (pos <= maxLength
  43925. && ((! tc->isBeingDragged)
  43926. || tc->getEditingMode() == ToolbarItemComponent::editableOnPalette));
  43927. }
  43928. }
  43929. }
  43930. }
  43931. void Toolbar::buttonClicked (Button*)
  43932. {
  43933. jassert (missingItemsButton->isShowing());
  43934. if (missingItemsButton->isShowing())
  43935. {
  43936. PopupMenu m;
  43937. m.addCustomItem (1, new MissingItemsComponent (*this, getThickness()));
  43938. m.showAt (missingItemsButton);
  43939. }
  43940. }
  43941. bool Toolbar::isInterestedInDragSource (const String& sourceDescription,
  43942. Component* /*sourceComponent*/)
  43943. {
  43944. return sourceDescription == toolbarDragDescriptor && isEditingActive;
  43945. }
  43946. void Toolbar::itemDragMove (const String&, Component* sourceComponent, int x, int y)
  43947. {
  43948. ToolbarItemComponent* const tc = dynamic_cast <ToolbarItemComponent*> (sourceComponent);
  43949. if (tc != 0)
  43950. {
  43951. if (getNumItems() == 0)
  43952. {
  43953. if (tc->getEditingMode() == ToolbarItemComponent::editableOnPalette)
  43954. {
  43955. ToolbarItemPalette* const palette = tc->findParentComponentOfClass ((ToolbarItemPalette*) 0);
  43956. if (palette != 0)
  43957. palette->replaceComponent (tc);
  43958. }
  43959. else
  43960. {
  43961. jassert (tc->getEditingMode() == ToolbarItemComponent::editableOnToolbar);
  43962. }
  43963. items.add (tc);
  43964. addChildComponent (tc);
  43965. updateAllItemPositions (false);
  43966. }
  43967. else
  43968. {
  43969. for (int i = getNumItems(); --i >= 0;)
  43970. {
  43971. int currentIndex = getIndexOfChildComponent (tc);
  43972. if (currentIndex < 0)
  43973. {
  43974. if (tc->getEditingMode() == ToolbarItemComponent::editableOnPalette)
  43975. {
  43976. ToolbarItemPalette* const palette = tc->findParentComponentOfClass ((ToolbarItemPalette*) 0);
  43977. if (palette != 0)
  43978. palette->replaceComponent (tc);
  43979. }
  43980. else
  43981. {
  43982. jassert (tc->getEditingMode() == ToolbarItemComponent::editableOnToolbar);
  43983. }
  43984. items.add (tc);
  43985. addChildComponent (tc);
  43986. currentIndex = getIndexOfChildComponent (tc);
  43987. updateAllItemPositions (true);
  43988. }
  43989. int newIndex = currentIndex;
  43990. const int dragObjectLeft = vertical ? (y - tc->dragOffsetY) : (x - tc->dragOffsetX);
  43991. const int dragObjectRight = dragObjectLeft + (vertical ? tc->getHeight() : tc->getWidth());
  43992. const Rectangle current (animator.getComponentDestination (getChildComponent (newIndex)));
  43993. ToolbarItemComponent* const prev = getNextActiveComponent (newIndex, -1);
  43994. if (prev != 0)
  43995. {
  43996. const Rectangle previousPos (animator.getComponentDestination (prev));
  43997. if (abs (dragObjectLeft - (vertical ? previousPos.getY() : previousPos.getX())
  43998. < abs (dragObjectRight - (vertical ? current.getBottom() : current.getRight()))))
  43999. {
  44000. newIndex = getIndexOfChildComponent (prev);
  44001. }
  44002. }
  44003. ToolbarItemComponent* const next = getNextActiveComponent (newIndex, 1);
  44004. if (next != 0)
  44005. {
  44006. const Rectangle nextPos (animator.getComponentDestination (next));
  44007. if (abs (dragObjectLeft - (vertical ? current.getY() : current.getX())
  44008. > abs (dragObjectRight - (vertical ? nextPos.getBottom() : nextPos.getRight()))))
  44009. {
  44010. newIndex = getIndexOfChildComponent (next) + 1;
  44011. }
  44012. }
  44013. if (newIndex != currentIndex)
  44014. {
  44015. items.removeValue (tc);
  44016. removeChildComponent (tc);
  44017. addChildComponent (tc, newIndex);
  44018. items.insert (newIndex, tc);
  44019. updateAllItemPositions (true);
  44020. }
  44021. else
  44022. {
  44023. break;
  44024. }
  44025. }
  44026. }
  44027. }
  44028. }
  44029. void Toolbar::itemDragExit (const String&, Component* sourceComponent)
  44030. {
  44031. ToolbarItemComponent* const tc = dynamic_cast <ToolbarItemComponent*> (sourceComponent);
  44032. if (tc != 0)
  44033. {
  44034. if (isParentOf (tc))
  44035. {
  44036. items.removeValue (tc);
  44037. removeChildComponent (tc);
  44038. updateAllItemPositions (true);
  44039. }
  44040. }
  44041. }
  44042. void Toolbar::itemDropped (const String&, Component*, int, int)
  44043. {
  44044. }
  44045. void Toolbar::mouseDown (const MouseEvent& e)
  44046. {
  44047. if (e.mods.isPopupMenu())
  44048. {
  44049. }
  44050. }
  44051. class ToolbarCustomisationDialog : public DialogWindow
  44052. {
  44053. public:
  44054. ToolbarCustomisationDialog (ToolbarItemFactory& factory,
  44055. Toolbar* const toolbar_,
  44056. const int optionFlags)
  44057. : DialogWindow (TRANS("Add/remove items from toolbar"), Colours::white, true, true),
  44058. toolbar (toolbar_)
  44059. {
  44060. setContentComponent (new CustomiserPanel (factory, toolbar, optionFlags), true, true);
  44061. setResizable (true, true);
  44062. setResizeLimits (400, 300, 1500, 1000);
  44063. positionNearBar();
  44064. }
  44065. ~ToolbarCustomisationDialog()
  44066. {
  44067. setContentComponent (0, true);
  44068. }
  44069. void closeButtonPressed()
  44070. {
  44071. setVisible (false);
  44072. }
  44073. bool canModalEventBeSentToComponent (const Component* comp)
  44074. {
  44075. return toolbar->isParentOf (comp);
  44076. }
  44077. void positionNearBar()
  44078. {
  44079. const Rectangle screenSize (toolbar->getParentMonitorArea());
  44080. const int tbx = toolbar->getScreenX();
  44081. const int tby = toolbar->getScreenY();
  44082. const int gap = 8;
  44083. int x, y;
  44084. if (toolbar->isVertical())
  44085. {
  44086. y = tby;
  44087. if (tbx > screenSize.getCentreX())
  44088. x = tbx - getWidth() - gap;
  44089. else
  44090. x = tbx + toolbar->getWidth() + gap;
  44091. }
  44092. else
  44093. {
  44094. x = tbx + (toolbar->getWidth() - getWidth()) / 2;
  44095. if (tby > screenSize.getCentreY())
  44096. y = tby - getHeight() - gap;
  44097. else
  44098. y = tby + toolbar->getHeight() + gap;
  44099. }
  44100. setTopLeftPosition (x, y);
  44101. }
  44102. private:
  44103. Toolbar* const toolbar;
  44104. class CustomiserPanel : public Component,
  44105. private ComboBoxListener,
  44106. private ButtonListener
  44107. {
  44108. public:
  44109. CustomiserPanel (ToolbarItemFactory& factory_,
  44110. Toolbar* const toolbar_,
  44111. const int optionFlags)
  44112. : factory (factory_),
  44113. toolbar (toolbar_),
  44114. styleBox (0),
  44115. defaultButton (0)
  44116. {
  44117. addAndMakeVisible (palette = new ToolbarItemPalette (factory, toolbar));
  44118. if ((optionFlags & (Toolbar::allowIconsOnlyChoice
  44119. | Toolbar::allowIconsWithTextChoice
  44120. | Toolbar::allowTextOnlyChoice)) != 0)
  44121. {
  44122. addAndMakeVisible (styleBox = new ComboBox (String::empty));
  44123. styleBox->setEditableText (false);
  44124. if ((optionFlags & Toolbar::allowIconsOnlyChoice) != 0)
  44125. styleBox->addItem (TRANS("Show icons only"), 1);
  44126. if ((optionFlags & Toolbar::allowIconsWithTextChoice) != 0)
  44127. styleBox->addItem (TRANS("Show icons and descriptions"), 2);
  44128. if ((optionFlags & Toolbar::allowTextOnlyChoice) != 0)
  44129. styleBox->addItem (TRANS("Show descriptions only"), 3);
  44130. if (toolbar_->getStyle() == Toolbar::iconsOnly)
  44131. styleBox->setSelectedId (1);
  44132. else if (toolbar_->getStyle() == Toolbar::iconsWithText)
  44133. styleBox->setSelectedId (2);
  44134. else if (toolbar_->getStyle() == Toolbar::textOnly)
  44135. styleBox->setSelectedId (3);
  44136. styleBox->addListener (this);
  44137. }
  44138. if ((optionFlags & Toolbar::showResetToDefaultsButton) != 0)
  44139. {
  44140. addAndMakeVisible (defaultButton = new TextButton (TRANS ("Restore to default set of items")));
  44141. defaultButton->addButtonListener (this);
  44142. }
  44143. addAndMakeVisible (instructions = new Label (String::empty,
  44144. 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.")));
  44145. instructions->setFont (Font (13.0f));
  44146. setSize (500, 300);
  44147. }
  44148. ~CustomiserPanel()
  44149. {
  44150. deleteAllChildren();
  44151. }
  44152. void comboBoxChanged (ComboBox*)
  44153. {
  44154. if (styleBox->getSelectedId() == 1)
  44155. toolbar->setStyle (Toolbar::iconsOnly);
  44156. else if (styleBox->getSelectedId() == 2)
  44157. toolbar->setStyle (Toolbar::iconsWithText);
  44158. else if (styleBox->getSelectedId() == 3)
  44159. toolbar->setStyle (Toolbar::textOnly);
  44160. palette->resized(); // to make it update the styles
  44161. }
  44162. void buttonClicked (Button*)
  44163. {
  44164. toolbar->addDefaultItems (factory);
  44165. }
  44166. void paint (Graphics& g)
  44167. {
  44168. Colour background;
  44169. DialogWindow* const dw = findParentComponentOfClass ((DialogWindow*) 0);
  44170. if (dw != 0)
  44171. background = dw->getBackgroundColour();
  44172. g.setColour (background.contrasting().withAlpha (0.3f));
  44173. g.fillRect (palette->getX(), palette->getBottom() - 1, palette->getWidth(), 1);
  44174. }
  44175. void resized()
  44176. {
  44177. palette->setBounds (0, 0, getWidth(), getHeight() - 120);
  44178. if (styleBox != 0)
  44179. styleBox->setBounds (10, getHeight() - 110, 200, 22);
  44180. if (defaultButton != 0)
  44181. {
  44182. defaultButton->changeWidthToFitText (22);
  44183. defaultButton->setTopLeftPosition (240, getHeight() - 110);
  44184. }
  44185. instructions->setBounds (10, getHeight() - 80, getWidth() - 20, 80);
  44186. }
  44187. private:
  44188. ToolbarItemFactory& factory;
  44189. Toolbar* const toolbar;
  44190. Label* instructions;
  44191. ToolbarItemPalette* palette;
  44192. ComboBox* styleBox;
  44193. TextButton* defaultButton;
  44194. };
  44195. };
  44196. void Toolbar::showCustomisationDialog (ToolbarItemFactory& factory, const int optionFlags)
  44197. {
  44198. setEditingActive (true);
  44199. ToolbarCustomisationDialog dw (factory, this, optionFlags);
  44200. dw.runModalLoop();
  44201. jassert (isValidComponent()); // ? deleting the toolbar while it's being edited?
  44202. setEditingActive (false);
  44203. }
  44204. END_JUCE_NAMESPACE
  44205. /********* End of inlined file: juce_Toolbar.cpp *********/
  44206. /********* Start of inlined file: juce_ToolbarItemComponent.cpp *********/
  44207. BEGIN_JUCE_NAMESPACE
  44208. ToolbarItemFactory::ToolbarItemFactory()
  44209. {
  44210. }
  44211. ToolbarItemFactory::~ToolbarItemFactory()
  44212. {
  44213. }
  44214. class ItemDragAndDropOverlayComponent : public Component
  44215. {
  44216. public:
  44217. ItemDragAndDropOverlayComponent()
  44218. : isDragging (false)
  44219. {
  44220. setAlwaysOnTop (true);
  44221. setRepaintsOnMouseActivity (true);
  44222. setMouseCursor (MouseCursor::DraggingHandCursor);
  44223. }
  44224. ~ItemDragAndDropOverlayComponent()
  44225. {
  44226. }
  44227. void paint (Graphics& g)
  44228. {
  44229. ToolbarItemComponent* const tc = dynamic_cast <ToolbarItemComponent*> (getParentComponent());
  44230. if (isMouseOverOrDragging()
  44231. && tc != 0
  44232. && tc->getEditingMode() == ToolbarItemComponent::editableOnToolbar)
  44233. {
  44234. g.setColour (findColour (Toolbar::editingModeOutlineColourId, true));
  44235. g.drawRect (0, 0, getWidth(), getHeight(),
  44236. jmin (2, (getWidth() - 1) / 2, (getHeight() - 1) / 2));
  44237. }
  44238. }
  44239. void mouseDown (const MouseEvent& e)
  44240. {
  44241. isDragging = false;
  44242. ToolbarItemComponent* const tc = dynamic_cast <ToolbarItemComponent*> (getParentComponent());
  44243. if (tc != 0)
  44244. {
  44245. tc->dragOffsetX = e.x;
  44246. tc->dragOffsetY = e.y;
  44247. }
  44248. }
  44249. void mouseDrag (const MouseEvent& e)
  44250. {
  44251. if (! (isDragging || e.mouseWasClicked()))
  44252. {
  44253. isDragging = true;
  44254. DragAndDropContainer* const dnd = DragAndDropContainer::findParentDragContainerFor (this);
  44255. if (dnd != 0)
  44256. {
  44257. dnd->startDragging (Toolbar::toolbarDragDescriptor, getParentComponent(), 0, true);
  44258. ToolbarItemComponent* const tc = dynamic_cast <ToolbarItemComponent*> (getParentComponent());
  44259. if (tc != 0)
  44260. {
  44261. tc->isBeingDragged = true;
  44262. if (tc->getEditingMode() == ToolbarItemComponent::editableOnToolbar)
  44263. tc->setVisible (false);
  44264. }
  44265. }
  44266. }
  44267. }
  44268. void mouseUp (const MouseEvent&)
  44269. {
  44270. isDragging = false;
  44271. ToolbarItemComponent* const tc = dynamic_cast <ToolbarItemComponent*> (getParentComponent());
  44272. if (tc != 0)
  44273. {
  44274. tc->isBeingDragged = false;
  44275. Toolbar* const tb = tc->getToolbar();
  44276. if (tb != 0)
  44277. tb->updateAllItemPositions (true);
  44278. else if (tc->getEditingMode() == ToolbarItemComponent::editableOnToolbar)
  44279. delete tc;
  44280. }
  44281. }
  44282. void parentSizeChanged()
  44283. {
  44284. setBounds (0, 0, getParentWidth(), getParentHeight());
  44285. }
  44286. juce_UseDebuggingNewOperator
  44287. private:
  44288. bool isDragging;
  44289. ItemDragAndDropOverlayComponent (const ItemDragAndDropOverlayComponent&);
  44290. const ItemDragAndDropOverlayComponent& operator= (const ItemDragAndDropOverlayComponent&);
  44291. };
  44292. ToolbarItemComponent::ToolbarItemComponent (const int itemId_,
  44293. const String& labelText,
  44294. const bool isBeingUsedAsAButton_)
  44295. : Button (labelText),
  44296. itemId (itemId_),
  44297. mode (normalMode),
  44298. toolbarStyle (Toolbar::iconsOnly),
  44299. dragOffsetX (0),
  44300. dragOffsetY (0),
  44301. isActive (true),
  44302. isBeingDragged (false),
  44303. isBeingUsedAsAButton (isBeingUsedAsAButton_)
  44304. {
  44305. // Your item ID can't be 0!
  44306. jassert (itemId_ != 0);
  44307. }
  44308. ToolbarItemComponent::~ToolbarItemComponent()
  44309. {
  44310. jassert (overlayComp == 0 || overlayComp->isValidComponent());
  44311. overlayComp = 0;
  44312. }
  44313. Toolbar* ToolbarItemComponent::getToolbar() const
  44314. {
  44315. return dynamic_cast <Toolbar*> (getParentComponent());
  44316. }
  44317. bool ToolbarItemComponent::isToolbarVertical() const
  44318. {
  44319. const Toolbar* const t = getToolbar();
  44320. return t != 0 && t->isVertical();
  44321. }
  44322. void ToolbarItemComponent::setStyle (const Toolbar::ToolbarItemStyle& newStyle)
  44323. {
  44324. if (toolbarStyle != newStyle)
  44325. {
  44326. toolbarStyle = newStyle;
  44327. repaint();
  44328. resized();
  44329. }
  44330. }
  44331. void ToolbarItemComponent::paintButton (Graphics& g, bool isMouseOver, bool isMouseDown)
  44332. {
  44333. if (isBeingUsedAsAButton)
  44334. getLookAndFeel().paintToolbarButtonBackground (g, getWidth(), getHeight(),
  44335. isMouseOver, isMouseDown, *this);
  44336. if (toolbarStyle != Toolbar::iconsOnly)
  44337. {
  44338. const int indent = contentArea.getX();
  44339. int y = indent;
  44340. int h = getHeight() - indent * 2;
  44341. if (toolbarStyle == Toolbar::iconsWithText)
  44342. {
  44343. y = contentArea.getBottom() + indent / 2;
  44344. h -= contentArea.getHeight();
  44345. }
  44346. getLookAndFeel().paintToolbarButtonLabel (g, indent, y, getWidth() - indent * 2, h,
  44347. getButtonText(), *this);
  44348. }
  44349. if (! contentArea.isEmpty())
  44350. {
  44351. g.saveState();
  44352. g.setOrigin (contentArea.getX(), contentArea.getY());
  44353. g.reduceClipRegion (0, 0, contentArea.getWidth(), contentArea.getHeight());
  44354. paintButtonArea (g, contentArea.getWidth(), contentArea.getHeight(), isMouseOver, isMouseDown);
  44355. g.restoreState();
  44356. }
  44357. }
  44358. void ToolbarItemComponent::resized()
  44359. {
  44360. if (toolbarStyle != Toolbar::textOnly)
  44361. {
  44362. const int indent = jmin (proportionOfWidth (0.08f),
  44363. proportionOfHeight (0.08f));
  44364. contentArea = Rectangle (indent, indent,
  44365. getWidth() - indent * 2,
  44366. toolbarStyle == Toolbar::iconsWithText ? proportionOfHeight (0.55f)
  44367. : (getHeight() - indent * 2));
  44368. }
  44369. else
  44370. {
  44371. contentArea = Rectangle();
  44372. }
  44373. contentAreaChanged (contentArea);
  44374. }
  44375. void ToolbarItemComponent::setEditingMode (const ToolbarEditingMode newMode)
  44376. {
  44377. if (mode != newMode)
  44378. {
  44379. mode = newMode;
  44380. repaint();
  44381. if (mode == normalMode)
  44382. {
  44383. jassert (overlayComp == 0 || overlayComp->isValidComponent());
  44384. overlayComp = 0;
  44385. }
  44386. else if (overlayComp == 0)
  44387. {
  44388. addAndMakeVisible (overlayComp = new ItemDragAndDropOverlayComponent());
  44389. overlayComp->parentSizeChanged();
  44390. }
  44391. resized();
  44392. }
  44393. }
  44394. END_JUCE_NAMESPACE
  44395. /********* End of inlined file: juce_ToolbarItemComponent.cpp *********/
  44396. /********* Start of inlined file: juce_ToolbarItemPalette.cpp *********/
  44397. BEGIN_JUCE_NAMESPACE
  44398. ToolbarItemPalette::ToolbarItemPalette (ToolbarItemFactory& factory_,
  44399. Toolbar* const toolbar_)
  44400. : factory (factory_),
  44401. toolbar (toolbar_)
  44402. {
  44403. Component* const itemHolder = new Component();
  44404. Array <int> allIds;
  44405. factory_.getAllToolbarItemIds (allIds);
  44406. for (int i = 0; i < allIds.size(); ++i)
  44407. {
  44408. ToolbarItemComponent* const tc = Toolbar::createItem (factory_, allIds.getUnchecked (i));
  44409. jassert (tc != 0);
  44410. if (tc != 0)
  44411. {
  44412. itemHolder->addAndMakeVisible (tc);
  44413. tc->setEditingMode (ToolbarItemComponent::editableOnPalette);
  44414. }
  44415. }
  44416. viewport = new Viewport();
  44417. viewport->setViewedComponent (itemHolder);
  44418. addAndMakeVisible (viewport);
  44419. }
  44420. ToolbarItemPalette::~ToolbarItemPalette()
  44421. {
  44422. viewport->getViewedComponent()->deleteAllChildren();
  44423. deleteAllChildren();
  44424. }
  44425. void ToolbarItemPalette::resized()
  44426. {
  44427. viewport->setBoundsInset (BorderSize (1));
  44428. Component* const itemHolder = viewport->getViewedComponent();
  44429. const int indent = 8;
  44430. const int preferredWidth = viewport->getWidth() - viewport->getScrollBarThickness() - indent;
  44431. const int height = toolbar->getThickness();
  44432. int x = indent;
  44433. int y = indent;
  44434. int maxX = 0;
  44435. for (int i = 0; i < itemHolder->getNumChildComponents(); ++i)
  44436. {
  44437. ToolbarItemComponent* const tc = dynamic_cast <ToolbarItemComponent*> (itemHolder->getChildComponent (i));
  44438. if (tc != 0)
  44439. {
  44440. tc->setStyle (toolbar->getStyle());
  44441. int preferredSize = 1, minSize = 1, maxSize = 1;
  44442. if (tc->getToolbarItemSizes (height, false, preferredSize, minSize, maxSize))
  44443. {
  44444. if (x + preferredSize > preferredWidth && x > indent)
  44445. {
  44446. x = indent;
  44447. y += height;
  44448. }
  44449. tc->setBounds (x, y, preferredSize, height);
  44450. x += preferredSize + 8;
  44451. maxX = jmax (maxX, x);
  44452. }
  44453. }
  44454. }
  44455. itemHolder->setSize (maxX, y + height + 8);
  44456. }
  44457. void ToolbarItemPalette::replaceComponent (ToolbarItemComponent* const comp)
  44458. {
  44459. ToolbarItemComponent* const tc = Toolbar::createItem (factory, comp->getItemId());
  44460. jassert (tc != 0);
  44461. if (tc != 0)
  44462. {
  44463. tc->setBounds (comp->getBounds());
  44464. tc->setStyle (toolbar->getStyle());
  44465. tc->setEditingMode (comp->getEditingMode());
  44466. viewport->getViewedComponent()->addAndMakeVisible (tc, getIndexOfChildComponent (comp));
  44467. }
  44468. }
  44469. END_JUCE_NAMESPACE
  44470. /********* End of inlined file: juce_ToolbarItemPalette.cpp *********/
  44471. /********* Start of inlined file: juce_TreeView.cpp *********/
  44472. BEGIN_JUCE_NAMESPACE
  44473. class TreeViewContentComponent : public Component,
  44474. public TooltipClient
  44475. {
  44476. public:
  44477. TreeViewContentComponent (TreeView* const owner_)
  44478. : owner (owner_),
  44479. buttonUnderMouse (0),
  44480. isDragging (false)
  44481. {
  44482. }
  44483. ~TreeViewContentComponent()
  44484. {
  44485. deleteAllChildren();
  44486. }
  44487. void mouseDown (const MouseEvent& e)
  44488. {
  44489. updateButtonUnderMouse (e);
  44490. isDragging = false;
  44491. needSelectionOnMouseUp = false;
  44492. Rectangle pos;
  44493. TreeViewItem* const item = findItemAt (e.y, pos);
  44494. if (item == 0)
  44495. return;
  44496. // (if the open/close buttons are hidden, we'll treat clicks to the left of the item
  44497. // as selection clicks)
  44498. if (e.x < pos.getX() && owner->openCloseButtonsVisible)
  44499. {
  44500. if (e.x >= pos.getX() - owner->getIndentSize())
  44501. item->setOpen (! item->isOpen());
  44502. // (clicks to the left of an open/close button are ignored)
  44503. }
  44504. else
  44505. {
  44506. // mouse-down inside the body of the item..
  44507. if (! owner->isMultiSelectEnabled())
  44508. item->setSelected (true, true);
  44509. else if (item->isSelected())
  44510. needSelectionOnMouseUp = ! e.mods.isPopupMenu();
  44511. else
  44512. selectBasedOnModifiers (item, e.mods);
  44513. MouseEvent e2 (e);
  44514. e2.x -= pos.getX();
  44515. e2.y -= pos.getY();
  44516. if (e2.x >= 0)
  44517. item->itemClicked (e2);
  44518. }
  44519. }
  44520. void mouseUp (const MouseEvent& e)
  44521. {
  44522. updateButtonUnderMouse (e);
  44523. if (needSelectionOnMouseUp && e.mouseWasClicked())
  44524. {
  44525. Rectangle pos;
  44526. TreeViewItem* const item = findItemAt (e.y, pos);
  44527. if (item != 0)
  44528. selectBasedOnModifiers (item, e.mods);
  44529. }
  44530. }
  44531. void mouseDoubleClick (const MouseEvent& e)
  44532. {
  44533. if (e.getNumberOfClicks() != 3) // ignore triple clicks
  44534. {
  44535. Rectangle pos;
  44536. TreeViewItem* const item = findItemAt (e.y, pos);
  44537. if (item != 0 && (e.x >= pos.getX() || ! owner->openCloseButtonsVisible))
  44538. {
  44539. MouseEvent e2 (e);
  44540. e2.x -= pos.getX();
  44541. e2.y -= pos.getY();
  44542. item->itemDoubleClicked (e2);
  44543. }
  44544. }
  44545. }
  44546. void mouseDrag (const MouseEvent& e)
  44547. {
  44548. if (isEnabled()
  44549. && ! (isDragging || e.mouseWasClicked()
  44550. || e.getDistanceFromDragStart() < 5
  44551. || e.mods.isPopupMenu()))
  44552. {
  44553. isDragging = true;
  44554. Rectangle pos;
  44555. TreeViewItem* const item = findItemAt (e.getMouseDownY(), pos);
  44556. if (item != 0 && e.getMouseDownX() >= pos.getX())
  44557. {
  44558. const String dragDescription (item->getDragSourceDescription());
  44559. if (dragDescription.isNotEmpty())
  44560. {
  44561. DragAndDropContainer* const dragContainer
  44562. = DragAndDropContainer::findParentDragContainerFor (this);
  44563. if (dragContainer != 0)
  44564. {
  44565. pos.setSize (pos.getWidth(), item->itemHeight);
  44566. Image* dragImage = Component::createComponentSnapshot (pos, true);
  44567. dragImage->multiplyAllAlphas (0.6f);
  44568. Point imageOffset ((float) (pos.getX() - e.x), (float) (pos.getY() - e.y));
  44569. dragContainer->startDragging (dragDescription, owner, dragImage, true, &imageOffset);
  44570. }
  44571. else
  44572. {
  44573. // to be able to do a drag-and-drop operation, the treeview needs to
  44574. // be inside a component which is also a DragAndDropContainer.
  44575. jassertfalse
  44576. }
  44577. }
  44578. }
  44579. }
  44580. }
  44581. void mouseMove (const MouseEvent& e)
  44582. {
  44583. updateButtonUnderMouse (e);
  44584. }
  44585. void mouseExit (const MouseEvent& e)
  44586. {
  44587. updateButtonUnderMouse (e);
  44588. }
  44589. void paint (Graphics& g);
  44590. TreeViewItem* findItemAt (int y, Rectangle& itemPosition) const;
  44591. void updateComponents()
  44592. {
  44593. const int visibleTop = -getY();
  44594. const int visibleBottom = visibleTop + getParentHeight();
  44595. BitArray itemsToKeep;
  44596. TreeViewItem* item = owner->rootItem;
  44597. int y = (item != 0 && !owner->rootItemVisible) ? -item->itemHeight : 0;
  44598. while (item != 0 && y < visibleBottom)
  44599. {
  44600. y += item->itemHeight;
  44601. if (y >= visibleTop)
  44602. {
  44603. const int index = rowComponentIds.indexOf (item->uid);
  44604. if (index < 0)
  44605. {
  44606. Component* const comp = item->createItemComponent();
  44607. if (comp != 0)
  44608. {
  44609. addAndMakeVisible (comp);
  44610. itemsToKeep.setBit (rowComponentItems.size());
  44611. rowComponentItems.add (item);
  44612. rowComponentIds.add (item->uid);
  44613. rowComponents.add (comp);
  44614. }
  44615. }
  44616. else
  44617. {
  44618. itemsToKeep.setBit (index);
  44619. }
  44620. }
  44621. item = item->getNextVisibleItem (true);
  44622. }
  44623. for (int i = rowComponentItems.size(); --i >= 0;)
  44624. {
  44625. Component* const comp = (Component*) rowComponents.getUnchecked(i);
  44626. bool keep = false;
  44627. if (isParentOf (comp))
  44628. {
  44629. if (itemsToKeep[i])
  44630. {
  44631. const TreeViewItem* const item = (TreeViewItem*) rowComponentItems.getUnchecked(i);
  44632. Rectangle pos (item->getItemPosition (false));
  44633. pos.setSize (pos.getWidth(), item->itemHeight);
  44634. if (pos.getBottom() >= visibleTop && pos.getY() < visibleBottom)
  44635. {
  44636. keep = true;
  44637. comp->setBounds (pos);
  44638. }
  44639. }
  44640. if ((! keep)
  44641. && Component::isMouseButtonDownAnywhere()
  44642. && (comp == Component::getComponentUnderMouse()
  44643. || comp->isParentOf (Component::getComponentUnderMouse())))
  44644. {
  44645. keep = true;
  44646. comp->setSize (0, 0);
  44647. }
  44648. }
  44649. if (! keep)
  44650. {
  44651. delete comp;
  44652. rowComponents.remove (i);
  44653. rowComponentIds.remove (i);
  44654. rowComponentItems.remove (i);
  44655. }
  44656. }
  44657. }
  44658. void updateButtonUnderMouse (const MouseEvent& e)
  44659. {
  44660. TreeViewItem* newItem = 0;
  44661. if (owner->openCloseButtonsVisible)
  44662. {
  44663. Rectangle pos;
  44664. TreeViewItem* item = findItemAt (e.y, pos);
  44665. if (item != 0 && e.x < pos.getX() && e.x >= pos.getX() - owner->getIndentSize())
  44666. {
  44667. newItem = item;
  44668. if (! newItem->mightContainSubItems())
  44669. newItem = 0;
  44670. }
  44671. }
  44672. if (buttonUnderMouse != newItem)
  44673. {
  44674. if (buttonUnderMouse != 0 && containsItem (buttonUnderMouse))
  44675. {
  44676. const Rectangle r (buttonUnderMouse->getItemPosition (false));
  44677. repaint (0, r.getY(), r.getX(), buttonUnderMouse->getItemHeight());
  44678. }
  44679. buttonUnderMouse = newItem;
  44680. if (buttonUnderMouse != 0)
  44681. {
  44682. const Rectangle r (buttonUnderMouse->getItemPosition (false));
  44683. repaint (0, r.getY(), r.getX(), buttonUnderMouse->getItemHeight());
  44684. }
  44685. }
  44686. }
  44687. bool isMouseOverButton (TreeViewItem* item) const throw()
  44688. {
  44689. return item == buttonUnderMouse;
  44690. }
  44691. void resized()
  44692. {
  44693. owner->itemsChanged();
  44694. }
  44695. const String getTooltip()
  44696. {
  44697. int x, y;
  44698. getMouseXYRelative (x, y);
  44699. Rectangle pos;
  44700. TreeViewItem* const item = findItemAt (y, pos);
  44701. if (item != 0)
  44702. return item->getTooltip();
  44703. return owner->getTooltip();
  44704. }
  44705. juce_UseDebuggingNewOperator
  44706. private:
  44707. TreeView* const owner;
  44708. VoidArray rowComponentItems;
  44709. Array <int> rowComponentIds;
  44710. VoidArray rowComponents;
  44711. TreeViewItem* buttonUnderMouse;
  44712. bool isDragging, needSelectionOnMouseUp;
  44713. TreeViewContentComponent (const TreeViewContentComponent&);
  44714. const TreeViewContentComponent& operator= (const TreeViewContentComponent&);
  44715. void selectBasedOnModifiers (TreeViewItem* const item, const ModifierKeys& modifiers)
  44716. {
  44717. TreeViewItem* firstSelected = 0;
  44718. if (modifiers.isShiftDown() && ((firstSelected = owner->getSelectedItem (0)) != 0))
  44719. {
  44720. TreeViewItem* const lastSelected = owner->getSelectedItem (owner->getNumSelectedItems() - 1);
  44721. jassert (lastSelected != 0);
  44722. int rowStart = firstSelected->getRowNumberInTree();
  44723. int rowEnd = lastSelected->getRowNumberInTree();
  44724. if (rowStart > rowEnd)
  44725. swapVariables (rowStart, rowEnd);
  44726. int ourRow = item->getRowNumberInTree();
  44727. int otherEnd = ourRow < rowEnd ? rowStart : rowEnd;
  44728. if (ourRow > otherEnd)
  44729. swapVariables (ourRow, otherEnd);
  44730. for (int i = ourRow; i <= otherEnd; ++i)
  44731. owner->getItemOnRow (i)->setSelected (true, false);
  44732. }
  44733. else
  44734. {
  44735. const bool cmd = modifiers.isCommandDown();
  44736. item->setSelected ((! cmd) || (! item->isSelected()), ! cmd);
  44737. }
  44738. }
  44739. bool containsItem (TreeViewItem* const item) const
  44740. {
  44741. for (int i = rowComponentItems.size(); --i >= 0;)
  44742. if ((TreeViewItem*) rowComponentItems.getUnchecked (i) == item)
  44743. return true;
  44744. return false;
  44745. }
  44746. };
  44747. class TreeViewport : public Viewport
  44748. {
  44749. public:
  44750. TreeViewport() throw() {}
  44751. ~TreeViewport() throw() {}
  44752. void updateComponents()
  44753. {
  44754. if (getViewedComponent() != 0)
  44755. ((TreeViewContentComponent*) getViewedComponent())->updateComponents();
  44756. repaint();
  44757. }
  44758. void visibleAreaChanged (int, int, int, int)
  44759. {
  44760. updateComponents();
  44761. }
  44762. juce_UseDebuggingNewOperator
  44763. private:
  44764. TreeViewport (const TreeViewport&);
  44765. const TreeViewport& operator= (const TreeViewport&);
  44766. };
  44767. TreeView::TreeView (const String& componentName)
  44768. : Component (componentName),
  44769. rootItem (0),
  44770. dragInsertPointHighlight (0),
  44771. dragTargetGroupHighlight (0),
  44772. indentSize (24),
  44773. defaultOpenness (false),
  44774. needsRecalculating (true),
  44775. rootItemVisible (true),
  44776. multiSelectEnabled (false),
  44777. openCloseButtonsVisible (true)
  44778. {
  44779. addAndMakeVisible (viewport = new TreeViewport());
  44780. viewport->setViewedComponent (new TreeViewContentComponent (this));
  44781. viewport->setWantsKeyboardFocus (false);
  44782. setWantsKeyboardFocus (true);
  44783. }
  44784. TreeView::~TreeView()
  44785. {
  44786. if (rootItem != 0)
  44787. rootItem->setOwnerView (0);
  44788. deleteAllChildren();
  44789. }
  44790. void TreeView::setRootItem (TreeViewItem* const newRootItem)
  44791. {
  44792. if (rootItem != newRootItem)
  44793. {
  44794. if (newRootItem != 0)
  44795. {
  44796. jassert (newRootItem->ownerView == 0); // can't use a tree item in more than one tree at once..
  44797. if (newRootItem->ownerView != 0)
  44798. newRootItem->ownerView->setRootItem (0);
  44799. }
  44800. if (rootItem != 0)
  44801. rootItem->setOwnerView (0);
  44802. rootItem = newRootItem;
  44803. if (newRootItem != 0)
  44804. newRootItem->setOwnerView (this);
  44805. needsRecalculating = true;
  44806. handleAsyncUpdate();
  44807. if (rootItem != 0 && (defaultOpenness || ! rootItemVisible))
  44808. {
  44809. rootItem->setOpen (false); // force a re-open
  44810. rootItem->setOpen (true);
  44811. }
  44812. }
  44813. }
  44814. void TreeView::deleteRootItem()
  44815. {
  44816. const ScopedPointer <TreeViewItem> deleter (rootItem);
  44817. setRootItem (0);
  44818. }
  44819. void TreeView::setRootItemVisible (const bool shouldBeVisible)
  44820. {
  44821. rootItemVisible = shouldBeVisible;
  44822. if (rootItem != 0 && (defaultOpenness || ! rootItemVisible))
  44823. {
  44824. rootItem->setOpen (false); // force a re-open
  44825. rootItem->setOpen (true);
  44826. }
  44827. itemsChanged();
  44828. }
  44829. void TreeView::colourChanged()
  44830. {
  44831. setOpaque (findColour (backgroundColourId).isOpaque());
  44832. repaint();
  44833. }
  44834. void TreeView::setIndentSize (const int newIndentSize)
  44835. {
  44836. if (indentSize != newIndentSize)
  44837. {
  44838. indentSize = newIndentSize;
  44839. resized();
  44840. }
  44841. }
  44842. void TreeView::setDefaultOpenness (const bool isOpenByDefault)
  44843. {
  44844. if (defaultOpenness != isOpenByDefault)
  44845. {
  44846. defaultOpenness = isOpenByDefault;
  44847. itemsChanged();
  44848. }
  44849. }
  44850. void TreeView::setMultiSelectEnabled (const bool canMultiSelect)
  44851. {
  44852. multiSelectEnabled = canMultiSelect;
  44853. }
  44854. void TreeView::setOpenCloseButtonsVisible (const bool shouldBeVisible)
  44855. {
  44856. if (openCloseButtonsVisible != shouldBeVisible)
  44857. {
  44858. openCloseButtonsVisible = shouldBeVisible;
  44859. itemsChanged();
  44860. }
  44861. }
  44862. void TreeView::clearSelectedItems()
  44863. {
  44864. if (rootItem != 0)
  44865. rootItem->deselectAllRecursively();
  44866. }
  44867. int TreeView::getNumSelectedItems() const throw()
  44868. {
  44869. return (rootItem != 0) ? rootItem->countSelectedItemsRecursively() : 0;
  44870. }
  44871. TreeViewItem* TreeView::getSelectedItem (const int index) const throw()
  44872. {
  44873. return (rootItem != 0) ? rootItem->getSelectedItemWithIndex (index) : 0;
  44874. }
  44875. int TreeView::getNumRowsInTree() const
  44876. {
  44877. if (rootItem != 0)
  44878. return rootItem->getNumRows() - (rootItemVisible ? 0 : 1);
  44879. return 0;
  44880. }
  44881. TreeViewItem* TreeView::getItemOnRow (int index) const
  44882. {
  44883. if (! rootItemVisible)
  44884. ++index;
  44885. if (rootItem != 0 && index >= 0)
  44886. return rootItem->getItemOnRow (index);
  44887. return 0;
  44888. }
  44889. TreeViewItem* TreeView::getItemAt (int y) const throw()
  44890. {
  44891. TreeViewContentComponent* const tc = (TreeViewContentComponent*) viewport->getViewedComponent();
  44892. int x;
  44893. relativePositionToOtherComponent (tc, x, y);
  44894. Rectangle pos;
  44895. return tc->findItemAt (y, pos);
  44896. }
  44897. TreeViewItem* TreeView::findItemFromIdentifierString (const String& identifierString) const
  44898. {
  44899. if (rootItem == 0)
  44900. return 0;
  44901. return rootItem->findItemFromIdentifierString (identifierString);
  44902. }
  44903. XmlElement* TreeView::getOpennessState (const bool alsoIncludeScrollPosition) const
  44904. {
  44905. XmlElement* e = 0;
  44906. if (rootItem != 0)
  44907. {
  44908. e = rootItem->getOpennessState();
  44909. if (e != 0 && alsoIncludeScrollPosition)
  44910. e->setAttribute (T("scrollPos"), viewport->getViewPositionY());
  44911. }
  44912. return e;
  44913. }
  44914. void TreeView::restoreOpennessState (const XmlElement& newState)
  44915. {
  44916. if (rootItem != 0)
  44917. {
  44918. rootItem->restoreOpennessState (newState);
  44919. if (newState.hasAttribute (T("scrollPos")))
  44920. viewport->setViewPosition (viewport->getViewPositionX(),
  44921. newState.getIntAttribute (T("scrollPos")));
  44922. }
  44923. }
  44924. void TreeView::paint (Graphics& g)
  44925. {
  44926. g.fillAll (findColour (backgroundColourId));
  44927. }
  44928. void TreeView::resized()
  44929. {
  44930. viewport->setBounds (0, 0, getWidth(), getHeight());
  44931. itemsChanged();
  44932. handleAsyncUpdate();
  44933. }
  44934. void TreeView::enablementChanged()
  44935. {
  44936. repaint();
  44937. }
  44938. void TreeView::moveSelectedRow (int delta)
  44939. {
  44940. if (delta == 0)
  44941. return;
  44942. int rowSelected = 0;
  44943. TreeViewItem* const firstSelected = getSelectedItem (0);
  44944. if (firstSelected != 0)
  44945. rowSelected = firstSelected->getRowNumberInTree();
  44946. rowSelected = jlimit (0, getNumRowsInTree() - 1, rowSelected + delta);
  44947. for (;;)
  44948. {
  44949. TreeViewItem* item = getItemOnRow (rowSelected);
  44950. if (item != 0)
  44951. {
  44952. if (! item->canBeSelected())
  44953. {
  44954. // if the row we want to highlight doesn't allow it, try skipping
  44955. // to the next item..
  44956. const int nextRowToTry = jlimit (0, getNumRowsInTree() - 1,
  44957. rowSelected + (delta < 0 ? -1 : 1));
  44958. if (rowSelected != nextRowToTry)
  44959. {
  44960. rowSelected = nextRowToTry;
  44961. continue;
  44962. }
  44963. else
  44964. {
  44965. break;
  44966. }
  44967. }
  44968. item->setSelected (true, true);
  44969. scrollToKeepItemVisible (item);
  44970. }
  44971. break;
  44972. }
  44973. }
  44974. void TreeView::scrollToKeepItemVisible (TreeViewItem* item)
  44975. {
  44976. if (item != 0 && item->ownerView == this)
  44977. {
  44978. handleAsyncUpdate();
  44979. item = item->getDeepestOpenParentItem();
  44980. int y = item->y;
  44981. int viewTop = viewport->getViewPositionY();
  44982. if (y < viewTop)
  44983. {
  44984. viewport->setViewPosition (viewport->getViewPositionX(), y);
  44985. }
  44986. else if (y + item->itemHeight > viewTop + viewport->getViewHeight())
  44987. {
  44988. viewport->setViewPosition (viewport->getViewPositionX(),
  44989. (y + item->itemHeight) - viewport->getViewHeight());
  44990. }
  44991. }
  44992. }
  44993. bool TreeView::keyPressed (const KeyPress& key)
  44994. {
  44995. if (key.isKeyCode (KeyPress::upKey))
  44996. {
  44997. moveSelectedRow (-1);
  44998. }
  44999. else if (key.isKeyCode (KeyPress::downKey))
  45000. {
  45001. moveSelectedRow (1);
  45002. }
  45003. else if (key.isKeyCode (KeyPress::pageDownKey) || key.isKeyCode (KeyPress::pageUpKey))
  45004. {
  45005. if (rootItem != 0)
  45006. {
  45007. int rowsOnScreen = getHeight() / jmax (1, rootItem->itemHeight);
  45008. if (key.isKeyCode (KeyPress::pageUpKey))
  45009. rowsOnScreen = -rowsOnScreen;
  45010. moveSelectedRow (rowsOnScreen);
  45011. }
  45012. }
  45013. else if (key.isKeyCode (KeyPress::homeKey))
  45014. {
  45015. moveSelectedRow (-0x3fffffff);
  45016. }
  45017. else if (key.isKeyCode (KeyPress::endKey))
  45018. {
  45019. moveSelectedRow (0x3fffffff);
  45020. }
  45021. else if (key.isKeyCode (KeyPress::returnKey))
  45022. {
  45023. TreeViewItem* const firstSelected = getSelectedItem (0);
  45024. if (firstSelected != 0)
  45025. firstSelected->setOpen (! firstSelected->isOpen());
  45026. }
  45027. else if (key.isKeyCode (KeyPress::leftKey))
  45028. {
  45029. TreeViewItem* const firstSelected = getSelectedItem (0);
  45030. if (firstSelected != 0)
  45031. {
  45032. if (firstSelected->isOpen())
  45033. {
  45034. firstSelected->setOpen (false);
  45035. }
  45036. else
  45037. {
  45038. TreeViewItem* parent = firstSelected->parentItem;
  45039. if ((! rootItemVisible) && parent == rootItem)
  45040. parent = 0;
  45041. if (parent != 0)
  45042. {
  45043. parent->setSelected (true, true);
  45044. scrollToKeepItemVisible (parent);
  45045. }
  45046. }
  45047. }
  45048. }
  45049. else if (key.isKeyCode (KeyPress::rightKey))
  45050. {
  45051. TreeViewItem* const firstSelected = getSelectedItem (0);
  45052. if (firstSelected != 0)
  45053. {
  45054. if (firstSelected->isOpen() || ! firstSelected->mightContainSubItems())
  45055. moveSelectedRow (1);
  45056. else
  45057. firstSelected->setOpen (true);
  45058. }
  45059. }
  45060. else
  45061. {
  45062. return false;
  45063. }
  45064. return true;
  45065. }
  45066. void TreeView::itemsChanged() throw()
  45067. {
  45068. needsRecalculating = true;
  45069. repaint();
  45070. triggerAsyncUpdate();
  45071. }
  45072. void TreeView::handleAsyncUpdate()
  45073. {
  45074. if (needsRecalculating)
  45075. {
  45076. needsRecalculating = false;
  45077. const ScopedLock sl (nodeAlterationLock);
  45078. if (rootItem != 0)
  45079. rootItem->updatePositions (rootItemVisible ? 0 : -rootItem->itemHeight);
  45080. ((TreeViewport*) viewport)->updateComponents();
  45081. if (rootItem != 0)
  45082. {
  45083. viewport->getViewedComponent()
  45084. ->setSize (jmax (viewport->getMaximumVisibleWidth(), rootItem->totalWidth),
  45085. rootItem->totalHeight - (rootItemVisible ? 0 : rootItem->itemHeight));
  45086. }
  45087. else
  45088. {
  45089. viewport->getViewedComponent()->setSize (0, 0);
  45090. }
  45091. }
  45092. }
  45093. class TreeViewDragInsertPointHighlight : public Component
  45094. {
  45095. public:
  45096. TreeViewDragInsertPointHighlight()
  45097. : lastItem (0)
  45098. {
  45099. setSize (100, 12);
  45100. setAlwaysOnTop (true);
  45101. setInterceptsMouseClicks (false, false);
  45102. }
  45103. ~TreeViewDragInsertPointHighlight() {}
  45104. void setTargetPosition (TreeViewItem* const item, int insertIndex, const int x, const int y, const int width) throw()
  45105. {
  45106. lastItem = item;
  45107. lastIndex = insertIndex;
  45108. const int offset = getHeight() / 2;
  45109. setBounds (x - offset, y - offset, width - (x - offset), getHeight());
  45110. }
  45111. void paint (Graphics& g)
  45112. {
  45113. Path p;
  45114. const float h = (float) getHeight();
  45115. p.addEllipse (2.0f, 2.0f, h - 4.0f, h - 4.0f);
  45116. p.startNewSubPath (h - 2.0f, h / 2.0f);
  45117. p.lineTo ((float) getWidth(), h / 2.0f);
  45118. g.setColour (findColour (TreeView::dragAndDropIndicatorColourId, true));
  45119. g.strokePath (p, PathStrokeType (2.0f));
  45120. }
  45121. TreeViewItem* lastItem;
  45122. int lastIndex;
  45123. };
  45124. class TreeViewDragTargetGroupHighlight : public Component
  45125. {
  45126. public:
  45127. TreeViewDragTargetGroupHighlight()
  45128. {
  45129. setAlwaysOnTop (true);
  45130. setInterceptsMouseClicks (false, false);
  45131. }
  45132. ~TreeViewDragTargetGroupHighlight() {}
  45133. void setTargetPosition (TreeViewItem* const item) throw()
  45134. {
  45135. Rectangle r (item->getItemPosition (true));
  45136. r.setHeight (item->getItemHeight());
  45137. setBounds (r);
  45138. }
  45139. void paint (Graphics& g)
  45140. {
  45141. g.setColour (findColour (TreeView::dragAndDropIndicatorColourId, true));
  45142. g.drawRoundedRectangle (1.0f, 1.0f, getWidth() - 2.0f, getHeight() - 2.0f, 3.0f, 2.0f);
  45143. }
  45144. };
  45145. void TreeView::showDragHighlight (TreeViewItem* item, int insertIndex, int x, int y) throw()
  45146. {
  45147. beginDragAutoRepeat (1000 / 30);
  45148. if (dragInsertPointHighlight == 0)
  45149. {
  45150. addAndMakeVisible (dragInsertPointHighlight = new TreeViewDragInsertPointHighlight());
  45151. addAndMakeVisible (dragTargetGroupHighlight = new TreeViewDragTargetGroupHighlight());
  45152. }
  45153. ((TreeViewDragInsertPointHighlight*) dragInsertPointHighlight)
  45154. ->setTargetPosition (item, insertIndex, x, y, viewport->getViewWidth());
  45155. ((TreeViewDragTargetGroupHighlight*) dragTargetGroupHighlight)
  45156. ->setTargetPosition (item);
  45157. }
  45158. void TreeView::hideDragHighlight() throw()
  45159. {
  45160. deleteAndZero (dragInsertPointHighlight);
  45161. deleteAndZero (dragTargetGroupHighlight);
  45162. }
  45163. TreeViewItem* TreeView::getInsertPosition (int& x, int& y, int& insertIndex,
  45164. const StringArray& files, const String& sourceDescription,
  45165. Component* sourceComponent) const throw()
  45166. {
  45167. insertIndex = 0;
  45168. TreeViewItem* item = getItemAt (y);
  45169. if (item == 0)
  45170. return 0;
  45171. Rectangle itemPos (item->getItemPosition (true));
  45172. insertIndex = item->getIndexInParent();
  45173. const int oldY = y;
  45174. y = itemPos.getY();
  45175. if (item->getNumSubItems() == 0 || ! item->isOpen())
  45176. {
  45177. if (files.size() > 0 ? item->isInterestedInFileDrag (files)
  45178. : item->isInterestedInDragSource (sourceDescription, sourceComponent))
  45179. {
  45180. // Check if we're trying to drag into an empty group item..
  45181. if (oldY > itemPos.getY() + itemPos.getHeight() / 4
  45182. && oldY < itemPos.getBottom() - itemPos.getHeight() / 4)
  45183. {
  45184. insertIndex = 0;
  45185. x = itemPos.getX() + getIndentSize();
  45186. y = itemPos.getBottom();
  45187. return item;
  45188. }
  45189. }
  45190. }
  45191. if (oldY > itemPos.getCentreY())
  45192. {
  45193. y += item->getItemHeight();
  45194. while (item->isLastOfSiblings() && item->parentItem != 0
  45195. && item->parentItem->parentItem != 0)
  45196. {
  45197. if (x > itemPos.getX())
  45198. break;
  45199. item = item->parentItem;
  45200. itemPos = item->getItemPosition (true);
  45201. insertIndex = item->getIndexInParent();
  45202. }
  45203. ++insertIndex;
  45204. }
  45205. x = itemPos.getX();
  45206. return item->parentItem;
  45207. }
  45208. void TreeView::handleDrag (const StringArray& files, const String& sourceDescription, Component* sourceComponent, int x, int y)
  45209. {
  45210. const bool scrolled = viewport->autoScroll (x, y, 20, 10);
  45211. int insertIndex;
  45212. TreeViewItem* const item = getInsertPosition (x, y, insertIndex, files, sourceDescription, sourceComponent);
  45213. if (item != 0)
  45214. {
  45215. if (scrolled || dragInsertPointHighlight == 0
  45216. || ((TreeViewDragInsertPointHighlight*) dragInsertPointHighlight)->lastItem != item
  45217. || ((TreeViewDragInsertPointHighlight*) dragInsertPointHighlight)->lastIndex != insertIndex)
  45218. {
  45219. if (files.size() > 0 ? item->isInterestedInFileDrag (files)
  45220. : item->isInterestedInDragSource (sourceDescription, sourceComponent))
  45221. showDragHighlight (item, insertIndex, x, y);
  45222. else
  45223. hideDragHighlight();
  45224. }
  45225. }
  45226. else
  45227. {
  45228. hideDragHighlight();
  45229. }
  45230. }
  45231. void TreeView::handleDrop (const StringArray& files, const String& sourceDescription, Component* sourceComponent, int x, int y)
  45232. {
  45233. hideDragHighlight();
  45234. int insertIndex;
  45235. TreeViewItem* const item = getInsertPosition (x, y, insertIndex, files, sourceDescription, sourceComponent);
  45236. if (item != 0)
  45237. {
  45238. if (files.size() > 0)
  45239. {
  45240. if (item->isInterestedInFileDrag (files))
  45241. item->filesDropped (files, insertIndex);
  45242. }
  45243. else
  45244. {
  45245. if (item->isInterestedInDragSource (sourceDescription, sourceComponent))
  45246. item->itemDropped (sourceDescription, sourceComponent, insertIndex);
  45247. }
  45248. }
  45249. }
  45250. bool TreeView::isInterestedInFileDrag (const StringArray&)
  45251. {
  45252. return true;
  45253. }
  45254. void TreeView::fileDragEnter (const StringArray& files, int x, int y)
  45255. {
  45256. fileDragMove (files, x, y);
  45257. }
  45258. void TreeView::fileDragMove (const StringArray& files, int x, int y)
  45259. {
  45260. handleDrag (files, String::empty, 0, x, y);
  45261. }
  45262. void TreeView::fileDragExit (const StringArray&)
  45263. {
  45264. hideDragHighlight();
  45265. }
  45266. void TreeView::filesDropped (const StringArray& files, int x, int y)
  45267. {
  45268. handleDrop (files, String::empty, 0, x, y);
  45269. }
  45270. bool TreeView::isInterestedInDragSource (const String& /*sourceDescription*/, Component* /*sourceComponent*/)
  45271. {
  45272. return true;
  45273. }
  45274. void TreeView::itemDragEnter (const String& sourceDescription, Component* sourceComponent, int x, int y)
  45275. {
  45276. itemDragMove (sourceDescription, sourceComponent, x, y);
  45277. }
  45278. void TreeView::itemDragMove (const String& sourceDescription, Component* sourceComponent, int x, int y)
  45279. {
  45280. handleDrag (StringArray(), sourceDescription, sourceComponent, x, y);
  45281. }
  45282. void TreeView::itemDragExit (const String& /*sourceDescription*/, Component* /*sourceComponent*/)
  45283. {
  45284. hideDragHighlight();
  45285. }
  45286. void TreeView::itemDropped (const String& sourceDescription, Component* sourceComponent, int x, int y)
  45287. {
  45288. handleDrop (StringArray(), sourceDescription, sourceComponent, x, y);
  45289. }
  45290. void TreeViewContentComponent::paint (Graphics& g)
  45291. {
  45292. if (owner->rootItem != 0)
  45293. {
  45294. owner->handleAsyncUpdate();
  45295. if (! owner->rootItemVisible)
  45296. g.setOrigin (0, -owner->rootItem->itemHeight);
  45297. owner->rootItem->paintRecursively (g, getWidth());
  45298. }
  45299. }
  45300. TreeViewItem* TreeViewContentComponent::findItemAt (int y, Rectangle& itemPosition) const
  45301. {
  45302. if (owner->rootItem != 0)
  45303. {
  45304. owner->handleAsyncUpdate();
  45305. if (! owner->rootItemVisible)
  45306. y += owner->rootItem->itemHeight;
  45307. TreeViewItem* const ti = owner->rootItem->findItemRecursively (y);
  45308. if (ti != 0)
  45309. itemPosition = ti->getItemPosition (false);
  45310. return ti;
  45311. }
  45312. return 0;
  45313. }
  45314. enum TreeViewOpenness
  45315. {
  45316. opennessDefault = 0,
  45317. opennessClosed = 1,
  45318. opennessOpen = 2
  45319. };
  45320. TreeViewItem::TreeViewItem()
  45321. : ownerView (0),
  45322. parentItem (0),
  45323. y (0),
  45324. itemHeight (0),
  45325. totalHeight (0),
  45326. selected (false),
  45327. redrawNeeded (true),
  45328. drawLinesInside (true),
  45329. drawsInLeftMargin (false),
  45330. openness (opennessDefault)
  45331. {
  45332. static int nextUID = 0;
  45333. uid = nextUID++;
  45334. }
  45335. TreeViewItem::~TreeViewItem()
  45336. {
  45337. }
  45338. const String TreeViewItem::getUniqueName() const
  45339. {
  45340. return String::empty;
  45341. }
  45342. void TreeViewItem::itemOpennessChanged (bool)
  45343. {
  45344. }
  45345. int TreeViewItem::getNumSubItems() const throw()
  45346. {
  45347. return subItems.size();
  45348. }
  45349. TreeViewItem* TreeViewItem::getSubItem (const int index) const throw()
  45350. {
  45351. return subItems [index];
  45352. }
  45353. void TreeViewItem::clearSubItems()
  45354. {
  45355. if (subItems.size() > 0)
  45356. {
  45357. if (ownerView != 0)
  45358. {
  45359. const ScopedLock sl (ownerView->nodeAlterationLock);
  45360. subItems.clear();
  45361. treeHasChanged();
  45362. }
  45363. else
  45364. {
  45365. subItems.clear();
  45366. }
  45367. }
  45368. }
  45369. void TreeViewItem::addSubItem (TreeViewItem* const newItem, const int insertPosition)
  45370. {
  45371. if (newItem != 0)
  45372. {
  45373. newItem->parentItem = this;
  45374. newItem->setOwnerView (ownerView);
  45375. newItem->y = 0;
  45376. newItem->itemHeight = newItem->getItemHeight();
  45377. newItem->totalHeight = 0;
  45378. newItem->itemWidth = newItem->getItemWidth();
  45379. newItem->totalWidth = 0;
  45380. if (ownerView != 0)
  45381. {
  45382. const ScopedLock sl (ownerView->nodeAlterationLock);
  45383. subItems.insert (insertPosition, newItem);
  45384. treeHasChanged();
  45385. if (newItem->isOpen())
  45386. newItem->itemOpennessChanged (true);
  45387. }
  45388. else
  45389. {
  45390. subItems.insert (insertPosition, newItem);
  45391. if (newItem->isOpen())
  45392. newItem->itemOpennessChanged (true);
  45393. }
  45394. }
  45395. }
  45396. void TreeViewItem::removeSubItem (const int index, const bool deleteItem)
  45397. {
  45398. if (ownerView != 0)
  45399. ownerView->nodeAlterationLock.enter();
  45400. if (((unsigned int) index) < (unsigned int) subItems.size())
  45401. {
  45402. subItems.remove (index, deleteItem);
  45403. treeHasChanged();
  45404. }
  45405. if (ownerView != 0)
  45406. ownerView->nodeAlterationLock.exit();
  45407. }
  45408. bool TreeViewItem::isOpen() const throw()
  45409. {
  45410. if (openness == opennessDefault)
  45411. return ownerView != 0 && ownerView->defaultOpenness;
  45412. else
  45413. return openness == opennessOpen;
  45414. }
  45415. void TreeViewItem::setOpen (const bool shouldBeOpen)
  45416. {
  45417. if (isOpen() != shouldBeOpen)
  45418. {
  45419. openness = shouldBeOpen ? opennessOpen
  45420. : opennessClosed;
  45421. treeHasChanged();
  45422. itemOpennessChanged (isOpen());
  45423. }
  45424. }
  45425. bool TreeViewItem::isSelected() const throw()
  45426. {
  45427. return selected;
  45428. }
  45429. void TreeViewItem::deselectAllRecursively()
  45430. {
  45431. setSelected (false, false);
  45432. for (int i = 0; i < subItems.size(); ++i)
  45433. subItems.getUnchecked(i)->deselectAllRecursively();
  45434. }
  45435. void TreeViewItem::setSelected (const bool shouldBeSelected,
  45436. const bool deselectOtherItemsFirst)
  45437. {
  45438. if (shouldBeSelected && ! canBeSelected())
  45439. return;
  45440. if (deselectOtherItemsFirst)
  45441. getTopLevelItem()->deselectAllRecursively();
  45442. if (shouldBeSelected != selected)
  45443. {
  45444. selected = shouldBeSelected;
  45445. if (ownerView != 0)
  45446. ownerView->repaint();
  45447. itemSelectionChanged (shouldBeSelected);
  45448. }
  45449. }
  45450. void TreeViewItem::paintItem (Graphics&, int, int)
  45451. {
  45452. }
  45453. void TreeViewItem::paintOpenCloseButton (Graphics& g, int width, int height, bool isMouseOver)
  45454. {
  45455. ownerView->getLookAndFeel()
  45456. .drawTreeviewPlusMinusBox (g, 0, 0, width, height, ! isOpen(), isMouseOver);
  45457. }
  45458. void TreeViewItem::itemClicked (const MouseEvent&)
  45459. {
  45460. }
  45461. void TreeViewItem::itemDoubleClicked (const MouseEvent&)
  45462. {
  45463. if (mightContainSubItems())
  45464. setOpen (! isOpen());
  45465. }
  45466. void TreeViewItem::itemSelectionChanged (bool)
  45467. {
  45468. }
  45469. const String TreeViewItem::getTooltip()
  45470. {
  45471. return String::empty;
  45472. }
  45473. const String TreeViewItem::getDragSourceDescription()
  45474. {
  45475. return String::empty;
  45476. }
  45477. bool TreeViewItem::isInterestedInFileDrag (const StringArray&)
  45478. {
  45479. return false;
  45480. }
  45481. void TreeViewItem::filesDropped (const StringArray& /*files*/, int /*insertIndex*/)
  45482. {
  45483. }
  45484. bool TreeViewItem::isInterestedInDragSource (const String& /*sourceDescription*/, Component* /*sourceComponent*/)
  45485. {
  45486. return false;
  45487. }
  45488. void TreeViewItem::itemDropped (const String& /*sourceDescription*/, Component* /*sourceComponent*/, int /*insertIndex*/)
  45489. {
  45490. }
  45491. const Rectangle TreeViewItem::getItemPosition (const bool relativeToTreeViewTopLeft) const throw()
  45492. {
  45493. const int indentX = getIndentX();
  45494. int width = itemWidth;
  45495. if (ownerView != 0 && width < 0)
  45496. width = ownerView->viewport->getViewWidth() - indentX;
  45497. Rectangle r (indentX, y, jmax (0, width), totalHeight);
  45498. if (relativeToTreeViewTopLeft)
  45499. r.setPosition (r.getX() - ownerView->viewport->getViewPositionX(),
  45500. r.getY() - ownerView->viewport->getViewPositionY());
  45501. return r;
  45502. }
  45503. void TreeViewItem::treeHasChanged() const throw()
  45504. {
  45505. if (ownerView != 0)
  45506. ownerView->itemsChanged();
  45507. }
  45508. void TreeViewItem::repaintItem() const
  45509. {
  45510. if (ownerView != 0 && areAllParentsOpen())
  45511. {
  45512. const Rectangle r (getItemPosition (true));
  45513. ownerView->viewport->repaint (0, r.getY(), r.getRight(), r.getHeight());
  45514. }
  45515. }
  45516. bool TreeViewItem::areAllParentsOpen() const throw()
  45517. {
  45518. return parentItem == 0
  45519. || (parentItem->isOpen() && parentItem->areAllParentsOpen());
  45520. }
  45521. void TreeViewItem::updatePositions (int newY)
  45522. {
  45523. y = newY;
  45524. itemHeight = getItemHeight();
  45525. totalHeight = itemHeight;
  45526. itemWidth = getItemWidth();
  45527. totalWidth = jmax (itemWidth, 0) + getIndentX();
  45528. if (isOpen())
  45529. {
  45530. newY += totalHeight;
  45531. for (int i = 0; i < subItems.size(); ++i)
  45532. {
  45533. TreeViewItem* const ti = subItems.getUnchecked(i);
  45534. ti->updatePositions (newY);
  45535. newY += ti->totalHeight;
  45536. totalHeight += ti->totalHeight;
  45537. totalWidth = jmax (totalWidth, ti->totalWidth);
  45538. }
  45539. }
  45540. }
  45541. TreeViewItem* TreeViewItem::getDeepestOpenParentItem() throw()
  45542. {
  45543. TreeViewItem* result = this;
  45544. TreeViewItem* item = this;
  45545. while (item->parentItem != 0)
  45546. {
  45547. item = item->parentItem;
  45548. if (! item->isOpen())
  45549. result = item;
  45550. }
  45551. return result;
  45552. }
  45553. void TreeViewItem::setOwnerView (TreeView* const newOwner) throw()
  45554. {
  45555. ownerView = newOwner;
  45556. for (int i = subItems.size(); --i >= 0;)
  45557. subItems.getUnchecked(i)->setOwnerView (newOwner);
  45558. }
  45559. int TreeViewItem::getIndentX() const throw()
  45560. {
  45561. const int indentWidth = ownerView->getIndentSize();
  45562. int x = ownerView->rootItemVisible ? indentWidth : 0;
  45563. if (! ownerView->openCloseButtonsVisible)
  45564. x -= indentWidth;
  45565. TreeViewItem* p = parentItem;
  45566. while (p != 0)
  45567. {
  45568. x += indentWidth;
  45569. p = p->parentItem;
  45570. }
  45571. return x;
  45572. }
  45573. void TreeViewItem::setDrawsInLeftMargin (bool canDrawInLeftMargin) throw()
  45574. {
  45575. drawsInLeftMargin = canDrawInLeftMargin;
  45576. }
  45577. void TreeViewItem::paintRecursively (Graphics& g, int width)
  45578. {
  45579. jassert (ownerView != 0);
  45580. if (ownerView == 0)
  45581. return;
  45582. const int indent = getIndentX();
  45583. const int itemW = itemWidth < 0 ? width - indent : itemWidth;
  45584. g.setColour (ownerView->findColour (TreeView::linesColourId));
  45585. const float halfH = itemHeight * 0.5f;
  45586. int depth = 0;
  45587. TreeViewItem* p = parentItem;
  45588. while (p != 0)
  45589. {
  45590. ++depth;
  45591. p = p->parentItem;
  45592. }
  45593. if (! ownerView->rootItemVisible)
  45594. --depth;
  45595. const int indentWidth = ownerView->getIndentSize();
  45596. if (depth >= 0 && ownerView->openCloseButtonsVisible)
  45597. {
  45598. float x = (depth + 0.5f) * indentWidth;
  45599. if (depth >= 0)
  45600. {
  45601. if (parentItem != 0 && parentItem->drawLinesInside)
  45602. g.drawLine (x, 0, x, isLastOfSiblings() ? halfH : (float) itemHeight);
  45603. if ((parentItem != 0 && parentItem->drawLinesInside)
  45604. || (parentItem == 0 && drawLinesInside))
  45605. g.drawLine (x, halfH, x + indentWidth / 2, halfH);
  45606. }
  45607. p = parentItem;
  45608. int d = depth;
  45609. while (p != 0 && --d >= 0)
  45610. {
  45611. x -= (float) indentWidth;
  45612. if ((p->parentItem == 0 || p->parentItem->drawLinesInside)
  45613. && ! p->isLastOfSiblings())
  45614. {
  45615. g.drawLine (x, 0, x, (float) itemHeight);
  45616. }
  45617. p = p->parentItem;
  45618. }
  45619. if (mightContainSubItems())
  45620. {
  45621. g.saveState();
  45622. g.setOrigin (depth * indentWidth, 0);
  45623. g.reduceClipRegion (0, 0, indentWidth, itemHeight);
  45624. paintOpenCloseButton (g, indentWidth, itemHeight,
  45625. ((TreeViewContentComponent*) ownerView->viewport->getViewedComponent())
  45626. ->isMouseOverButton (this));
  45627. g.restoreState();
  45628. }
  45629. }
  45630. {
  45631. g.saveState();
  45632. g.setOrigin (indent, 0);
  45633. if (g.reduceClipRegion (drawsInLeftMargin ? -indent : 0, 0,
  45634. drawsInLeftMargin ? itemW + indent : itemW, itemHeight))
  45635. paintItem (g, itemW, itemHeight);
  45636. g.restoreState();
  45637. }
  45638. if (isOpen())
  45639. {
  45640. const Rectangle clip (g.getClipBounds());
  45641. for (int i = 0; i < subItems.size(); ++i)
  45642. {
  45643. TreeViewItem* const ti = subItems.getUnchecked(i);
  45644. const int relY = ti->y - y;
  45645. if (relY >= clip.getBottom())
  45646. break;
  45647. if (relY + ti->totalHeight >= clip.getY())
  45648. {
  45649. g.saveState();
  45650. g.setOrigin (0, relY);
  45651. if (g.reduceClipRegion (0, 0, width, ti->totalHeight))
  45652. ti->paintRecursively (g, width);
  45653. g.restoreState();
  45654. }
  45655. }
  45656. }
  45657. }
  45658. bool TreeViewItem::isLastOfSiblings() const throw()
  45659. {
  45660. return parentItem == 0
  45661. || parentItem->subItems.getLast() == this;
  45662. }
  45663. int TreeViewItem::getIndexInParent() const throw()
  45664. {
  45665. if (parentItem == 0)
  45666. return 0;
  45667. return parentItem->subItems.indexOf (this);
  45668. }
  45669. TreeViewItem* TreeViewItem::getTopLevelItem() throw()
  45670. {
  45671. return (parentItem == 0) ? this
  45672. : parentItem->getTopLevelItem();
  45673. }
  45674. int TreeViewItem::getNumRows() const throw()
  45675. {
  45676. int num = 1;
  45677. if (isOpen())
  45678. {
  45679. for (int i = subItems.size(); --i >= 0;)
  45680. num += subItems.getUnchecked(i)->getNumRows();
  45681. }
  45682. return num;
  45683. }
  45684. TreeViewItem* TreeViewItem::getItemOnRow (int index) throw()
  45685. {
  45686. if (index == 0)
  45687. return this;
  45688. if (index > 0 && isOpen())
  45689. {
  45690. --index;
  45691. for (int i = 0; i < subItems.size(); ++i)
  45692. {
  45693. TreeViewItem* const item = subItems.getUnchecked(i);
  45694. if (index == 0)
  45695. return item;
  45696. const int numRows = item->getNumRows();
  45697. if (numRows > index)
  45698. return item->getItemOnRow (index);
  45699. index -= numRows;
  45700. }
  45701. }
  45702. return 0;
  45703. }
  45704. TreeViewItem* TreeViewItem::findItemRecursively (int targetY) throw()
  45705. {
  45706. if (((unsigned int) targetY) < (unsigned int) totalHeight)
  45707. {
  45708. const int h = itemHeight;
  45709. if (targetY < h)
  45710. return this;
  45711. if (isOpen())
  45712. {
  45713. targetY -= h;
  45714. for (int i = 0; i < subItems.size(); ++i)
  45715. {
  45716. TreeViewItem* const ti = subItems.getUnchecked(i);
  45717. if (targetY < ti->totalHeight)
  45718. return ti->findItemRecursively (targetY);
  45719. targetY -= ti->totalHeight;
  45720. }
  45721. }
  45722. }
  45723. return 0;
  45724. }
  45725. int TreeViewItem::countSelectedItemsRecursively() const throw()
  45726. {
  45727. int total = 0;
  45728. if (isSelected())
  45729. ++total;
  45730. for (int i = subItems.size(); --i >= 0;)
  45731. total += subItems.getUnchecked(i)->countSelectedItemsRecursively();
  45732. return total;
  45733. }
  45734. TreeViewItem* TreeViewItem::getSelectedItemWithIndex (int index) throw()
  45735. {
  45736. if (isSelected())
  45737. {
  45738. if (index == 0)
  45739. return this;
  45740. --index;
  45741. }
  45742. if (index >= 0)
  45743. {
  45744. for (int i = 0; i < subItems.size(); ++i)
  45745. {
  45746. TreeViewItem* const item = subItems.getUnchecked(i);
  45747. TreeViewItem* const found = item->getSelectedItemWithIndex (index);
  45748. if (found != 0)
  45749. return found;
  45750. index -= item->countSelectedItemsRecursively();
  45751. }
  45752. }
  45753. return 0;
  45754. }
  45755. int TreeViewItem::getRowNumberInTree() const throw()
  45756. {
  45757. if (parentItem != 0 && ownerView != 0)
  45758. {
  45759. int n = 1 + parentItem->getRowNumberInTree();
  45760. int ourIndex = parentItem->subItems.indexOf (this);
  45761. jassert (ourIndex >= 0);
  45762. while (--ourIndex >= 0)
  45763. n += parentItem->subItems [ourIndex]->getNumRows();
  45764. if (parentItem->parentItem == 0
  45765. && ! ownerView->rootItemVisible)
  45766. --n;
  45767. return n;
  45768. }
  45769. else
  45770. {
  45771. return 0;
  45772. }
  45773. }
  45774. void TreeViewItem::setLinesDrawnForSubItems (const bool drawLines) throw()
  45775. {
  45776. drawLinesInside = drawLines;
  45777. }
  45778. TreeViewItem* TreeViewItem::getNextVisibleItem (const bool recurse) const throw()
  45779. {
  45780. if (recurse && isOpen() && subItems.size() > 0)
  45781. return subItems [0];
  45782. if (parentItem != 0)
  45783. {
  45784. const int nextIndex = parentItem->subItems.indexOf (this) + 1;
  45785. if (nextIndex >= parentItem->subItems.size())
  45786. return parentItem->getNextVisibleItem (false);
  45787. return parentItem->subItems [nextIndex];
  45788. }
  45789. return 0;
  45790. }
  45791. const String TreeViewItem::getItemIdentifierString() const
  45792. {
  45793. String s;
  45794. if (parentItem != 0)
  45795. s = parentItem->getItemIdentifierString();
  45796. return s + T("/") + getUniqueName().replaceCharacter (T('/'), T('\\'));
  45797. }
  45798. TreeViewItem* TreeViewItem::findItemFromIdentifierString (const String& identifierString)
  45799. {
  45800. const String uid (getUniqueName());
  45801. if (uid == identifierString)
  45802. return this;
  45803. if (identifierString.startsWith (uid + T("/")))
  45804. {
  45805. const String remainingPath (identifierString.substring (uid.length() + 1));
  45806. bool wasOpen = isOpen();
  45807. setOpen (true);
  45808. for (int i = subItems.size(); --i >= 0;)
  45809. {
  45810. TreeViewItem* item = subItems.getUnchecked(i)->findItemFromIdentifierString (remainingPath);
  45811. if (item != 0)
  45812. return item;
  45813. }
  45814. setOpen (wasOpen);
  45815. }
  45816. return 0;
  45817. }
  45818. void TreeViewItem::restoreOpennessState (const XmlElement& e) throw()
  45819. {
  45820. if (e.hasTagName (T("CLOSED")))
  45821. {
  45822. setOpen (false);
  45823. }
  45824. else if (e.hasTagName (T("OPEN")))
  45825. {
  45826. setOpen (true);
  45827. forEachXmlChildElement (e, n)
  45828. {
  45829. const String id (n->getStringAttribute (T("id")));
  45830. for (int i = 0; i < subItems.size(); ++i)
  45831. {
  45832. TreeViewItem* const ti = subItems.getUnchecked(i);
  45833. if (ti->getUniqueName() == id)
  45834. {
  45835. ti->restoreOpennessState (*n);
  45836. break;
  45837. }
  45838. }
  45839. }
  45840. }
  45841. }
  45842. XmlElement* TreeViewItem::getOpennessState() const throw()
  45843. {
  45844. const String name (getUniqueName());
  45845. if (name.isNotEmpty())
  45846. {
  45847. XmlElement* e;
  45848. if (isOpen())
  45849. {
  45850. e = new XmlElement (T("OPEN"));
  45851. for (int i = 0; i < subItems.size(); ++i)
  45852. e->addChildElement (subItems.getUnchecked(i)->getOpennessState());
  45853. }
  45854. else
  45855. {
  45856. e = new XmlElement (T("CLOSED"));
  45857. }
  45858. e->setAttribute (T("id"), name);
  45859. return e;
  45860. }
  45861. else
  45862. {
  45863. // trying to save the openness for an element that has no name - this won't
  45864. // work because it needs the names to identify what to open.
  45865. jassertfalse
  45866. }
  45867. return 0;
  45868. }
  45869. END_JUCE_NAMESPACE
  45870. /********* End of inlined file: juce_TreeView.cpp *********/
  45871. /********* Start of inlined file: juce_DirectoryContentsDisplayComponent.cpp *********/
  45872. BEGIN_JUCE_NAMESPACE
  45873. DirectoryContentsDisplayComponent::DirectoryContentsDisplayComponent (DirectoryContentsList& listToShow)
  45874. : fileList (listToShow)
  45875. {
  45876. }
  45877. DirectoryContentsDisplayComponent::~DirectoryContentsDisplayComponent()
  45878. {
  45879. }
  45880. FileBrowserListener::~FileBrowserListener()
  45881. {
  45882. }
  45883. void DirectoryContentsDisplayComponent::addListener (FileBrowserListener* const listener) throw()
  45884. {
  45885. jassert (listener != 0);
  45886. if (listener != 0)
  45887. listeners.add (listener);
  45888. }
  45889. void DirectoryContentsDisplayComponent::removeListener (FileBrowserListener* const listener) throw()
  45890. {
  45891. listeners.removeValue (listener);
  45892. }
  45893. void DirectoryContentsDisplayComponent::sendSelectionChangeMessage()
  45894. {
  45895. const ComponentDeletionWatcher deletionWatcher (dynamic_cast <Component*> (this));
  45896. for (int i = listeners.size(); --i >= 0;)
  45897. {
  45898. ((FileBrowserListener*) listeners.getUnchecked (i))->selectionChanged();
  45899. if (deletionWatcher.hasBeenDeleted())
  45900. return;
  45901. i = jmin (i, listeners.size() - 1);
  45902. }
  45903. }
  45904. void DirectoryContentsDisplayComponent::sendMouseClickMessage (const File& file, const MouseEvent& e)
  45905. {
  45906. if (fileList.getDirectory().exists())
  45907. {
  45908. const ComponentDeletionWatcher deletionWatcher (dynamic_cast <Component*> (this));
  45909. for (int i = listeners.size(); --i >= 0;)
  45910. {
  45911. ((FileBrowserListener*) listeners.getUnchecked (i))->fileClicked (file, e);
  45912. if (deletionWatcher.hasBeenDeleted())
  45913. return;
  45914. i = jmin (i, listeners.size() - 1);
  45915. }
  45916. }
  45917. }
  45918. void DirectoryContentsDisplayComponent::sendDoubleClickMessage (const File& file)
  45919. {
  45920. if (fileList.getDirectory().exists())
  45921. {
  45922. const ComponentDeletionWatcher deletionWatcher (dynamic_cast <Component*> (this));
  45923. for (int i = listeners.size(); --i >= 0;)
  45924. {
  45925. ((FileBrowserListener*) listeners.getUnchecked (i))->fileDoubleClicked (file);
  45926. if (deletionWatcher.hasBeenDeleted())
  45927. return;
  45928. i = jmin (i, listeners.size() - 1);
  45929. }
  45930. }
  45931. }
  45932. END_JUCE_NAMESPACE
  45933. /********* End of inlined file: juce_DirectoryContentsDisplayComponent.cpp *********/
  45934. /********* Start of inlined file: juce_DirectoryContentsList.cpp *********/
  45935. BEGIN_JUCE_NAMESPACE
  45936. void* juce_findFileStart (const String& directory, const String& wildCard, String& firstResultFile,
  45937. bool* isDirectory, bool* isHidden, int64* fileSize, Time* modTime,
  45938. Time* creationTime, bool* isReadOnly);
  45939. bool juce_findFileNext (void* handle, String& resultFile,
  45940. bool* isDirectory, bool* isHidden, int64* fileSize,
  45941. Time* modTime, Time* creationTime, bool* isReadOnly);
  45942. void juce_findFileClose (void* handle);
  45943. DirectoryContentsList::DirectoryContentsList (const FileFilter* const fileFilter_,
  45944. TimeSliceThread& thread_)
  45945. : fileFilter (fileFilter_),
  45946. thread (thread_),
  45947. includeDirectories (false),
  45948. includeFiles (false),
  45949. ignoreHiddenFiles (true),
  45950. fileFindHandle (0),
  45951. shouldStop (true)
  45952. {
  45953. }
  45954. DirectoryContentsList::~DirectoryContentsList()
  45955. {
  45956. clear();
  45957. }
  45958. void DirectoryContentsList::setIgnoresHiddenFiles (const bool shouldIgnoreHiddenFiles)
  45959. {
  45960. ignoreHiddenFiles = shouldIgnoreHiddenFiles;
  45961. }
  45962. const File& DirectoryContentsList::getDirectory() const
  45963. {
  45964. return root;
  45965. }
  45966. void DirectoryContentsList::setDirectory (const File& directory,
  45967. const bool includeDirectories_,
  45968. const bool includeFiles_)
  45969. {
  45970. if (directory != root
  45971. || includeDirectories != includeDirectories_
  45972. || includeFiles != includeFiles_)
  45973. {
  45974. clear();
  45975. root = directory;
  45976. includeDirectories = includeDirectories_;
  45977. includeFiles = includeFiles_;
  45978. refresh();
  45979. }
  45980. }
  45981. void DirectoryContentsList::clear()
  45982. {
  45983. shouldStop = true;
  45984. thread.removeTimeSliceClient (this);
  45985. if (fileFindHandle != 0)
  45986. {
  45987. juce_findFileClose (fileFindHandle);
  45988. fileFindHandle = 0;
  45989. }
  45990. if (files.size() > 0)
  45991. {
  45992. files.clear();
  45993. changed();
  45994. }
  45995. }
  45996. void DirectoryContentsList::refresh()
  45997. {
  45998. clear();
  45999. if (root.isDirectory())
  46000. {
  46001. String fileFound;
  46002. bool fileFoundIsDir, isHidden, isReadOnly;
  46003. int64 fileSize;
  46004. Time modTime, creationTime;
  46005. String path (root.getFullPathName());
  46006. if (! path.endsWithChar (File::separator))
  46007. path += File::separator;
  46008. jassert (fileFindHandle == 0);
  46009. fileFindHandle = juce_findFileStart (path, T("*"), fileFound,
  46010. &fileFoundIsDir,
  46011. &isHidden,
  46012. &fileSize,
  46013. &modTime,
  46014. &creationTime,
  46015. &isReadOnly);
  46016. if (fileFindHandle != 0 && fileFound.isNotEmpty())
  46017. {
  46018. if (addFile (fileFound, fileFoundIsDir, isHidden,
  46019. fileSize, modTime, creationTime, isReadOnly))
  46020. {
  46021. changed();
  46022. }
  46023. }
  46024. shouldStop = false;
  46025. thread.addTimeSliceClient (this);
  46026. }
  46027. }
  46028. int DirectoryContentsList::getNumFiles() const
  46029. {
  46030. return files.size();
  46031. }
  46032. bool DirectoryContentsList::getFileInfo (const int index,
  46033. FileInfo& result) const
  46034. {
  46035. const ScopedLock sl (fileListLock);
  46036. const FileInfo* const info = files [index];
  46037. if (info != 0)
  46038. {
  46039. result = *info;
  46040. return true;
  46041. }
  46042. return false;
  46043. }
  46044. const File DirectoryContentsList::getFile (const int index) const
  46045. {
  46046. const ScopedLock sl (fileListLock);
  46047. const FileInfo* const info = files [index];
  46048. if (info != 0)
  46049. return root.getChildFile (info->filename);
  46050. return File::nonexistent;
  46051. }
  46052. bool DirectoryContentsList::isStillLoading() const
  46053. {
  46054. return fileFindHandle != 0;
  46055. }
  46056. void DirectoryContentsList::changed()
  46057. {
  46058. sendChangeMessage (this);
  46059. }
  46060. bool DirectoryContentsList::useTimeSlice()
  46061. {
  46062. const uint32 startTime = Time::getApproximateMillisecondCounter();
  46063. bool hasChanged = false;
  46064. for (int i = 100; --i >= 0;)
  46065. {
  46066. if (! checkNextFile (hasChanged))
  46067. {
  46068. if (hasChanged)
  46069. changed();
  46070. return false;
  46071. }
  46072. if (shouldStop || (Time::getApproximateMillisecondCounter() > startTime + 150))
  46073. break;
  46074. }
  46075. if (hasChanged)
  46076. changed();
  46077. return true;
  46078. }
  46079. bool DirectoryContentsList::checkNextFile (bool& hasChanged)
  46080. {
  46081. if (fileFindHandle != 0)
  46082. {
  46083. String fileFound;
  46084. bool fileFoundIsDir, isHidden, isReadOnly;
  46085. int64 fileSize;
  46086. Time modTime, creationTime;
  46087. if (juce_findFileNext (fileFindHandle, fileFound,
  46088. &fileFoundIsDir, &isHidden,
  46089. &fileSize,
  46090. &modTime,
  46091. &creationTime,
  46092. &isReadOnly))
  46093. {
  46094. if (addFile (fileFound, fileFoundIsDir, isHidden, fileSize,
  46095. modTime, creationTime, isReadOnly))
  46096. {
  46097. hasChanged = true;
  46098. }
  46099. return true;
  46100. }
  46101. else
  46102. {
  46103. juce_findFileClose (fileFindHandle);
  46104. fileFindHandle = 0;
  46105. }
  46106. }
  46107. return false;
  46108. }
  46109. int DirectoryContentsList::compareElements (const DirectoryContentsList::FileInfo* const first,
  46110. const DirectoryContentsList::FileInfo* const second)
  46111. {
  46112. #if JUCE_WINDOWS
  46113. if (first->isDirectory != second->isDirectory)
  46114. return first->isDirectory ? -1 : 1;
  46115. #endif
  46116. return first->filename.compareIgnoreCase (second->filename);
  46117. }
  46118. bool DirectoryContentsList::addFile (const String& filename,
  46119. const bool isDir,
  46120. const bool isHidden,
  46121. const int64 fileSize,
  46122. const Time& modTime,
  46123. const Time& creationTime,
  46124. const bool isReadOnly)
  46125. {
  46126. if (filename == T("..")
  46127. || filename == T(".")
  46128. || (ignoreHiddenFiles && isHidden))
  46129. return false;
  46130. const File file (root.getChildFile (filename));
  46131. if (((isDir && includeDirectories) || ((! isDir) && includeFiles))
  46132. && (fileFilter == 0
  46133. || ((! isDir) && fileFilter->isFileSuitable (file))
  46134. || (isDir && fileFilter->isDirectorySuitable (file))))
  46135. {
  46136. ScopedPointer <FileInfo> info (new FileInfo());
  46137. info->filename = filename;
  46138. info->fileSize = fileSize;
  46139. info->modificationTime = modTime;
  46140. info->creationTime = creationTime;
  46141. info->isDirectory = isDir;
  46142. info->isReadOnly = isReadOnly;
  46143. const ScopedLock sl (fileListLock);
  46144. for (int i = files.size(); --i >= 0;)
  46145. if (files.getUnchecked(i)->filename == info->filename)
  46146. return false;
  46147. files.addSorted (*this, info.release());
  46148. return true;
  46149. }
  46150. return false;
  46151. }
  46152. END_JUCE_NAMESPACE
  46153. /********* End of inlined file: juce_DirectoryContentsList.cpp *********/
  46154. /********* Start of inlined file: juce_FileBrowserComponent.cpp *********/
  46155. BEGIN_JUCE_NAMESPACE
  46156. FileBrowserComponent::FileBrowserComponent (int flags_,
  46157. const File& initialFileOrDirectory,
  46158. const FileFilter* fileFilter_,
  46159. FilePreviewComponent* previewComp_)
  46160. : FileFilter (String::empty),
  46161. fileFilter (fileFilter_),
  46162. flags (flags_),
  46163. previewComp (previewComp_),
  46164. thread ("Juce FileBrowser")
  46165. {
  46166. // You need to specify one or other of the open/save flags..
  46167. jassert ((flags & (saveMode | openMode)) != 0);
  46168. jassert ((flags & (saveMode | openMode)) != (saveMode | openMode));
  46169. // You need to specify at least one of these flags..
  46170. jassert ((flags & (canSelectFiles | canSelectDirectories)) != 0);
  46171. String filename;
  46172. if (initialFileOrDirectory == File::nonexistent)
  46173. {
  46174. currentRoot = File::getCurrentWorkingDirectory();
  46175. }
  46176. else if (initialFileOrDirectory.isDirectory())
  46177. {
  46178. currentRoot = initialFileOrDirectory;
  46179. }
  46180. else
  46181. {
  46182. chosenFiles.add (initialFileOrDirectory);
  46183. currentRoot = initialFileOrDirectory.getParentDirectory();
  46184. filename = initialFileOrDirectory.getFileName();
  46185. }
  46186. fileList = new DirectoryContentsList (this, thread);
  46187. if ((flags & useTreeView) != 0)
  46188. {
  46189. FileTreeComponent* const tree = new FileTreeComponent (*fileList);
  46190. if ((flags & canSelectMultipleItems) != 0)
  46191. tree->setMultiSelectEnabled (true);
  46192. addAndMakeVisible (tree);
  46193. fileListComponent = tree;
  46194. }
  46195. else
  46196. {
  46197. FileListComponent* const list = new FileListComponent (*fileList);
  46198. list->setOutlineThickness (1);
  46199. if ((flags & canSelectMultipleItems) != 0)
  46200. list->setMultipleSelectionEnabled (true);
  46201. addAndMakeVisible (list);
  46202. fileListComponent = list;
  46203. }
  46204. fileListComponent->addListener (this);
  46205. addAndMakeVisible (currentPathBox = new ComboBox ("path"));
  46206. currentPathBox->setEditableText (true);
  46207. StringArray rootNames, rootPaths;
  46208. const BitArray separators (getRoots (rootNames, rootPaths));
  46209. for (int i = 0; i < rootNames.size(); ++i)
  46210. {
  46211. if (separators [i])
  46212. currentPathBox->addSeparator();
  46213. currentPathBox->addItem (rootNames[i], i + 1);
  46214. }
  46215. currentPathBox->addSeparator();
  46216. currentPathBox->addListener (this);
  46217. addAndMakeVisible (filenameBox = new TextEditor());
  46218. filenameBox->setMultiLine (false);
  46219. filenameBox->setSelectAllWhenFocused (true);
  46220. filenameBox->setText (filename, false);
  46221. filenameBox->addListener (this);
  46222. filenameBox->setReadOnly ((flags & (filenameBoxIsReadOnly | canSelectMultipleItems)) != 0);
  46223. Label* label = new Label ("f", TRANS("file:"));
  46224. addAndMakeVisible (label);
  46225. label->attachToComponent (filenameBox, true);
  46226. addAndMakeVisible (goUpButton = getLookAndFeel().createFileBrowserGoUpButton());
  46227. goUpButton->addButtonListener (this);
  46228. goUpButton->setTooltip (TRANS ("go up to parent directory"));
  46229. if (previewComp != 0)
  46230. addAndMakeVisible (previewComp);
  46231. setRoot (currentRoot);
  46232. thread.startThread (4);
  46233. }
  46234. FileBrowserComponent::~FileBrowserComponent()
  46235. {
  46236. if (previewComp != 0)
  46237. removeChildComponent (previewComp);
  46238. deleteAllChildren();
  46239. fileList = 0;
  46240. thread.stopThread (10000);
  46241. }
  46242. void FileBrowserComponent::addListener (FileBrowserListener* const newListener) throw()
  46243. {
  46244. jassert (newListener != 0)
  46245. if (newListener != 0)
  46246. listeners.add (newListener);
  46247. }
  46248. void FileBrowserComponent::removeListener (FileBrowserListener* const listener) throw()
  46249. {
  46250. listeners.removeValue (listener);
  46251. }
  46252. bool FileBrowserComponent::isSaveMode() const throw()
  46253. {
  46254. return (flags & saveMode) != 0;
  46255. }
  46256. int FileBrowserComponent::getNumSelectedFiles() const throw()
  46257. {
  46258. if (chosenFiles.size() == 0 && currentFileIsValid())
  46259. return 1;
  46260. return chosenFiles.size();
  46261. }
  46262. const File FileBrowserComponent::getSelectedFile (int index) const throw()
  46263. {
  46264. if (! filenameBox->isReadOnly())
  46265. return currentRoot.getChildFile (filenameBox->getText());
  46266. else
  46267. return chosenFiles[index];
  46268. }
  46269. bool FileBrowserComponent::currentFileIsValid() const
  46270. {
  46271. if (isSaveMode())
  46272. return ! getSelectedFile (0).isDirectory();
  46273. else
  46274. return getSelectedFile (0).exists();
  46275. }
  46276. const File FileBrowserComponent::getHighlightedFile() const throw()
  46277. {
  46278. return fileListComponent->getSelectedFile (0);
  46279. }
  46280. bool FileBrowserComponent::isFileSuitable (const File& file) const
  46281. {
  46282. return (flags & canSelectFiles) != 0 ? (fileFilter == 0 || fileFilter->isFileSuitable (file))
  46283. : false;
  46284. }
  46285. bool FileBrowserComponent::isDirectorySuitable (const File&) const
  46286. {
  46287. return true;
  46288. }
  46289. bool FileBrowserComponent::isFileOrDirSuitable (const File& f) const
  46290. {
  46291. if (f.isDirectory())
  46292. return (flags & canSelectDirectories) != 0 && (fileFilter == 0 || fileFilter->isDirectorySuitable (f));
  46293. return (flags & canSelectFiles) != 0 && f.exists()
  46294. && (fileFilter == 0 || fileFilter->isFileSuitable (f));
  46295. }
  46296. const File FileBrowserComponent::getRoot() const
  46297. {
  46298. return currentRoot;
  46299. }
  46300. void FileBrowserComponent::setRoot (const File& newRootDirectory)
  46301. {
  46302. if (currentRoot != newRootDirectory)
  46303. {
  46304. fileListComponent->scrollToTop();
  46305. String path (newRootDirectory.getFullPathName());
  46306. if (path.isEmpty())
  46307. path += File::separator;
  46308. StringArray rootNames, rootPaths;
  46309. getRoots (rootNames, rootPaths);
  46310. if (! rootPaths.contains (path, true))
  46311. {
  46312. bool alreadyListed = false;
  46313. for (int i = currentPathBox->getNumItems(); --i >= 0;)
  46314. {
  46315. if (currentPathBox->getItemText (i).equalsIgnoreCase (path))
  46316. {
  46317. alreadyListed = true;
  46318. break;
  46319. }
  46320. }
  46321. if (! alreadyListed)
  46322. currentPathBox->addItem (path, currentPathBox->getNumItems() + 2);
  46323. }
  46324. }
  46325. currentRoot = newRootDirectory;
  46326. fileList->setDirectory (currentRoot, true, true);
  46327. String currentRootName (currentRoot.getFullPathName());
  46328. if (currentRootName.isEmpty())
  46329. currentRootName += File::separator;
  46330. currentPathBox->setText (currentRootName, true);
  46331. goUpButton->setEnabled (currentRoot.getParentDirectory().isDirectory()
  46332. && currentRoot.getParentDirectory() != currentRoot);
  46333. }
  46334. void FileBrowserComponent::goUp()
  46335. {
  46336. setRoot (getRoot().getParentDirectory());
  46337. }
  46338. void FileBrowserComponent::refresh()
  46339. {
  46340. fileList->refresh();
  46341. }
  46342. const String FileBrowserComponent::getActionVerb() const
  46343. {
  46344. return isSaveMode() ? TRANS("Save") : TRANS("Open");
  46345. }
  46346. FilePreviewComponent* FileBrowserComponent::getPreviewComponent() const throw()
  46347. {
  46348. return previewComp;
  46349. }
  46350. void FileBrowserComponent::resized()
  46351. {
  46352. getLookAndFeel()
  46353. .layoutFileBrowserComponent (*this, fileListComponent,
  46354. previewComp, currentPathBox,
  46355. filenameBox, goUpButton);
  46356. }
  46357. void FileBrowserComponent::sendListenerChangeMessage()
  46358. {
  46359. ComponentDeletionWatcher deletionWatcher (this);
  46360. if (previewComp != 0)
  46361. previewComp->selectedFileChanged (getSelectedFile (0));
  46362. jassert (! deletionWatcher.hasBeenDeleted());
  46363. for (int i = listeners.size(); --i >= 0;)
  46364. {
  46365. ((FileBrowserListener*) listeners.getUnchecked (i))->selectionChanged();
  46366. if (deletionWatcher.hasBeenDeleted())
  46367. return;
  46368. i = jmin (i, listeners.size() - 1);
  46369. }
  46370. }
  46371. void FileBrowserComponent::selectionChanged()
  46372. {
  46373. StringArray newFilenames;
  46374. bool resetChosenFiles = true;
  46375. for (int i = 0; i < fileListComponent->getNumSelectedFiles(); ++i)
  46376. {
  46377. const File f (fileListComponent->getSelectedFile (i));
  46378. if (isFileOrDirSuitable (f))
  46379. {
  46380. if (resetChosenFiles)
  46381. {
  46382. chosenFiles.clear();
  46383. resetChosenFiles = false;
  46384. }
  46385. chosenFiles.add (f);
  46386. newFilenames.add (f.getRelativePathFrom (getRoot()));
  46387. }
  46388. }
  46389. if (newFilenames.size() > 0)
  46390. filenameBox->setText (newFilenames.joinIntoString (T(", ")), false);
  46391. sendListenerChangeMessage();
  46392. }
  46393. void FileBrowserComponent::fileClicked (const File& f, const MouseEvent& e)
  46394. {
  46395. ComponentDeletionWatcher deletionWatcher (this);
  46396. for (int i = listeners.size(); --i >= 0;)
  46397. {
  46398. ((FileBrowserListener*) listeners.getUnchecked (i))->fileClicked (f, e);
  46399. if (deletionWatcher.hasBeenDeleted())
  46400. return;
  46401. i = jmin (i, listeners.size() - 1);
  46402. }
  46403. }
  46404. void FileBrowserComponent::fileDoubleClicked (const File& f)
  46405. {
  46406. if (f.isDirectory())
  46407. {
  46408. setRoot (f);
  46409. }
  46410. else
  46411. {
  46412. ComponentDeletionWatcher deletionWatcher (this);
  46413. for (int i = listeners.size(); --i >= 0;)
  46414. {
  46415. ((FileBrowserListener*) listeners.getUnchecked (i))->fileDoubleClicked (f);
  46416. if (deletionWatcher.hasBeenDeleted())
  46417. return;
  46418. i = jmin (i, listeners.size() - 1);
  46419. }
  46420. }
  46421. }
  46422. bool FileBrowserComponent::keyPressed (const KeyPress& key)
  46423. {
  46424. #if JUCE_LINUX || JUCE_WINDOWS
  46425. if (key.getModifiers().isCommandDown()
  46426. && (key.getKeyCode() == 'H' || key.getKeyCode() == 'h'))
  46427. {
  46428. fileList->setIgnoresHiddenFiles (! fileList->ignoresHiddenFiles());
  46429. fileList->refresh();
  46430. return true;
  46431. }
  46432. #endif
  46433. return false;
  46434. }
  46435. void FileBrowserComponent::textEditorTextChanged (TextEditor&)
  46436. {
  46437. sendListenerChangeMessage();
  46438. }
  46439. void FileBrowserComponent::textEditorReturnKeyPressed (TextEditor&)
  46440. {
  46441. if (filenameBox->getText().containsChar (File::separator))
  46442. {
  46443. const File f (currentRoot.getChildFile (filenameBox->getText()));
  46444. if (f.isDirectory())
  46445. {
  46446. setRoot (f);
  46447. chosenFiles.clear();
  46448. filenameBox->setText (String::empty);
  46449. }
  46450. else
  46451. {
  46452. setRoot (f.getParentDirectory());
  46453. chosenFiles.clear();
  46454. chosenFiles.add (f);
  46455. filenameBox->setText (f.getFileName());
  46456. }
  46457. }
  46458. else
  46459. {
  46460. fileDoubleClicked (getSelectedFile (0));
  46461. }
  46462. }
  46463. void FileBrowserComponent::textEditorEscapeKeyPressed (TextEditor&)
  46464. {
  46465. }
  46466. void FileBrowserComponent::textEditorFocusLost (TextEditor&)
  46467. {
  46468. if (! isSaveMode())
  46469. selectionChanged();
  46470. }
  46471. void FileBrowserComponent::buttonClicked (Button*)
  46472. {
  46473. goUp();
  46474. }
  46475. void FileBrowserComponent::comboBoxChanged (ComboBox*)
  46476. {
  46477. const String newText (currentPathBox->getText().trim().unquoted());
  46478. if (newText.isNotEmpty())
  46479. {
  46480. const int index = currentPathBox->getSelectedId() - 1;
  46481. StringArray rootNames, rootPaths;
  46482. getRoots (rootNames, rootPaths);
  46483. if (rootPaths [index].isNotEmpty())
  46484. {
  46485. setRoot (File (rootPaths [index]));
  46486. }
  46487. else
  46488. {
  46489. File f (newText);
  46490. for (;;)
  46491. {
  46492. if (f.isDirectory())
  46493. {
  46494. setRoot (f);
  46495. break;
  46496. }
  46497. if (f.getParentDirectory() == f)
  46498. break;
  46499. f = f.getParentDirectory();
  46500. }
  46501. }
  46502. }
  46503. }
  46504. const BitArray FileBrowserComponent::getRoots (StringArray& rootNames, StringArray& rootPaths)
  46505. {
  46506. BitArray separators;
  46507. #if JUCE_WINDOWS
  46508. Array<File> roots;
  46509. File::findFileSystemRoots (roots);
  46510. rootPaths.clear();
  46511. for (int i = 0; i < roots.size(); ++i)
  46512. {
  46513. const File& drive = roots.getReference(i);
  46514. String name (drive.getFullPathName());
  46515. rootPaths.add (name);
  46516. if (drive.isOnHardDisk())
  46517. {
  46518. String volume (drive.getVolumeLabel());
  46519. if (volume.isEmpty())
  46520. volume = TRANS("Hard Drive");
  46521. name << " [" << drive.getVolumeLabel() << ']';
  46522. }
  46523. else if (drive.isOnCDRomDrive())
  46524. {
  46525. name << TRANS(" [CD/DVD drive]");
  46526. }
  46527. rootNames.add (name);
  46528. }
  46529. separators.setBit (rootPaths.size());
  46530. rootPaths.add (File::getSpecialLocation (File::userDocumentsDirectory).getFullPathName());
  46531. rootNames.add ("Documents");
  46532. rootPaths.add (File::getSpecialLocation (File::userDesktopDirectory).getFullPathName());
  46533. rootNames.add ("Desktop");
  46534. #endif
  46535. #if JUCE_MAC
  46536. rootPaths.add (File::getSpecialLocation (File::userHomeDirectory).getFullPathName());
  46537. rootNames.add ("Home folder");
  46538. rootPaths.add (File::getSpecialLocation (File::userDocumentsDirectory).getFullPathName());
  46539. rootNames.add ("Documents");
  46540. rootPaths.add (File::getSpecialLocation (File::userDesktopDirectory).getFullPathName());
  46541. rootNames.add ("Desktop");
  46542. separators.setBit (rootPaths.size());
  46543. Array <File> volumes;
  46544. File vol ("/Volumes");
  46545. vol.findChildFiles (volumes, File::findDirectories, false);
  46546. for (int i = 0; i < volumes.size(); ++i)
  46547. {
  46548. const File& volume = volumes.getReference(i);
  46549. if (volume.isDirectory() && ! volume.getFileName().startsWithChar (T('.')))
  46550. {
  46551. rootPaths.add (volume.getFullPathName());
  46552. rootNames.add (volume.getFileName());
  46553. }
  46554. }
  46555. #endif
  46556. #if JUCE_LINUX
  46557. rootPaths.add ("/");
  46558. rootNames.add ("/");
  46559. rootPaths.add (File::getSpecialLocation (File::userHomeDirectory).getFullPathName());
  46560. rootNames.add ("Home folder");
  46561. rootPaths.add (File::getSpecialLocation (File::userDesktopDirectory).getFullPathName());
  46562. rootNames.add ("Desktop");
  46563. #endif
  46564. return separators;
  46565. }
  46566. END_JUCE_NAMESPACE
  46567. /********* End of inlined file: juce_FileBrowserComponent.cpp *********/
  46568. /********* Start of inlined file: juce_FileChooser.cpp *********/
  46569. BEGIN_JUCE_NAMESPACE
  46570. FileChooser::FileChooser (const String& chooserBoxTitle,
  46571. const File& currentFileOrDirectory,
  46572. const String& fileFilters,
  46573. const bool useNativeDialogBox_)
  46574. : title (chooserBoxTitle),
  46575. filters (fileFilters),
  46576. startingFile (currentFileOrDirectory),
  46577. useNativeDialogBox (useNativeDialogBox_)
  46578. {
  46579. #if JUCE_LINUX
  46580. useNativeDialogBox = false;
  46581. #endif
  46582. if (! fileFilters.containsNonWhitespaceChars())
  46583. filters = T("*");
  46584. }
  46585. FileChooser::~FileChooser()
  46586. {
  46587. }
  46588. bool FileChooser::browseForFileToOpen (FilePreviewComponent* previewComponent)
  46589. {
  46590. return showDialog (false, true, false, false, false, previewComponent);
  46591. }
  46592. bool FileChooser::browseForMultipleFilesToOpen (FilePreviewComponent* previewComponent)
  46593. {
  46594. return showDialog (false, true, false, false, true, previewComponent);
  46595. }
  46596. bool FileChooser::browseForMultipleFilesOrDirectories (FilePreviewComponent* previewComponent)
  46597. {
  46598. return showDialog (true, true, false, false, true, previewComponent);
  46599. }
  46600. bool FileChooser::browseForFileToSave (const bool warnAboutOverwritingExistingFiles)
  46601. {
  46602. return showDialog (false, true, true, warnAboutOverwritingExistingFiles, false, 0);
  46603. }
  46604. bool FileChooser::browseForDirectory()
  46605. {
  46606. return showDialog (true, false, false, false, false, 0);
  46607. }
  46608. const File FileChooser::getResult() const
  46609. {
  46610. // if you've used a multiple-file select, you should use the getResults() method
  46611. // to retrieve all the files that were chosen.
  46612. jassert (results.size() <= 1);
  46613. return results.getFirst();
  46614. }
  46615. const Array<File>& FileChooser::getResults() const
  46616. {
  46617. return results;
  46618. }
  46619. bool FileChooser::showDialog (const bool selectsDirectories,
  46620. const bool selectsFiles,
  46621. const bool isSave,
  46622. const bool warnAboutOverwritingExistingFiles,
  46623. const bool selectMultipleFiles,
  46624. FilePreviewComponent* const previewComponent)
  46625. {
  46626. ScopedPointer <ComponentDeletionWatcher> currentlyFocusedChecker;
  46627. Component* const currentlyFocused = Component::getCurrentlyFocusedComponent();
  46628. if (currentlyFocused != 0)
  46629. currentlyFocusedChecker = new ComponentDeletionWatcher (currentlyFocused);
  46630. results.clear();
  46631. // the preview component needs to be the right size before you pass it in here..
  46632. jassert (previewComponent == 0 || (previewComponent->getWidth() > 10
  46633. && previewComponent->getHeight() > 10));
  46634. #if JUCE_WINDOWS
  46635. if (useNativeDialogBox && ! (selectsFiles && selectsDirectories))
  46636. #elif JUCE_MAC
  46637. if (useNativeDialogBox && (previewComponent == 0))
  46638. #else
  46639. if (false)
  46640. #endif
  46641. {
  46642. showPlatformDialog (results, title, startingFile, filters,
  46643. selectsDirectories, selectsFiles, isSave,
  46644. warnAboutOverwritingExistingFiles,
  46645. selectMultipleFiles,
  46646. previewComponent);
  46647. }
  46648. else
  46649. {
  46650. WildcardFileFilter wildcard (selectsFiles ? filters : String::empty,
  46651. selectsDirectories ? "*" : String::empty,
  46652. String::empty);
  46653. int flags = isSave ? FileBrowserComponent::saveMode
  46654. : FileBrowserComponent::openMode;
  46655. if (selectsFiles)
  46656. flags |= FileBrowserComponent::canSelectFiles;
  46657. if (selectsDirectories)
  46658. flags |= FileBrowserComponent::canSelectDirectories;
  46659. if (selectMultipleFiles)
  46660. flags |= FileBrowserComponent::canSelectMultipleItems;
  46661. FileBrowserComponent browserComponent (flags, startingFile, &wildcard, previewComponent);
  46662. FileChooserDialogBox box (title, String::empty,
  46663. browserComponent,
  46664. warnAboutOverwritingExistingFiles,
  46665. browserComponent.findColour (AlertWindow::backgroundColourId));
  46666. if (box.show())
  46667. {
  46668. for (int i = 0; i < browserComponent.getNumSelectedFiles(); ++i)
  46669. results.add (browserComponent.getSelectedFile (i));
  46670. }
  46671. }
  46672. if (currentlyFocused != 0 && ! currentlyFocusedChecker->hasBeenDeleted())
  46673. currentlyFocused->grabKeyboardFocus();
  46674. return results.size() > 0;
  46675. }
  46676. FilePreviewComponent::FilePreviewComponent()
  46677. {
  46678. }
  46679. FilePreviewComponent::~FilePreviewComponent()
  46680. {
  46681. }
  46682. END_JUCE_NAMESPACE
  46683. /********* End of inlined file: juce_FileChooser.cpp *********/
  46684. /********* Start of inlined file: juce_FileChooserDialogBox.cpp *********/
  46685. BEGIN_JUCE_NAMESPACE
  46686. FileChooserDialogBox::FileChooserDialogBox (const String& name,
  46687. const String& instructions,
  46688. FileBrowserComponent& chooserComponent,
  46689. const bool warnAboutOverwritingExistingFiles_,
  46690. const Colour& backgroundColour)
  46691. : ResizableWindow (name, backgroundColour, true),
  46692. warnAboutOverwritingExistingFiles (warnAboutOverwritingExistingFiles_)
  46693. {
  46694. content = new ContentComponent();
  46695. content->setName (name);
  46696. content->instructions = instructions;
  46697. content->chooserComponent = &chooserComponent;
  46698. content->addAndMakeVisible (&chooserComponent);
  46699. content->okButton = new TextButton (chooserComponent.getActionVerb());
  46700. content->addAndMakeVisible (content->okButton);
  46701. content->okButton->addButtonListener (this);
  46702. content->okButton->setEnabled (chooserComponent.currentFileIsValid());
  46703. content->okButton->addShortcut (KeyPress (KeyPress::returnKey, 0, 0));
  46704. content->cancelButton = new TextButton (TRANS("Cancel"));
  46705. content->addAndMakeVisible (content->cancelButton);
  46706. content->cancelButton->addButtonListener (this);
  46707. content->cancelButton->addShortcut (KeyPress (KeyPress::escapeKey, 0, 0));
  46708. setContentComponent (content);
  46709. setResizable (true, true);
  46710. setResizeLimits (300, 300, 1200, 1000);
  46711. content->chooserComponent->addListener (this);
  46712. }
  46713. FileChooserDialogBox::~FileChooserDialogBox()
  46714. {
  46715. content->chooserComponent->removeListener (this);
  46716. }
  46717. bool FileChooserDialogBox::show (int w, int h)
  46718. {
  46719. if (w <= 0)
  46720. {
  46721. Component* const previewComp = content->chooserComponent->getPreviewComponent();
  46722. if (previewComp != 0)
  46723. w = 400 + previewComp->getWidth();
  46724. else
  46725. w = 600;
  46726. }
  46727. if (h <= 0)
  46728. h = 500;
  46729. centreWithSize (w, h);
  46730. const bool ok = (runModalLoop() != 0);
  46731. setVisible (false);
  46732. return ok;
  46733. }
  46734. void FileChooserDialogBox::buttonClicked (Button* button)
  46735. {
  46736. if (button == content->okButton)
  46737. {
  46738. if (warnAboutOverwritingExistingFiles
  46739. && content->chooserComponent->isSaveMode()
  46740. && content->chooserComponent->getSelectedFile(0).exists())
  46741. {
  46742. if (! AlertWindow::showOkCancelBox (AlertWindow::WarningIcon,
  46743. TRANS("File already exists"),
  46744. TRANS("There's already a file called:\n\n")
  46745. + content->chooserComponent->getSelectedFile(0).getFullPathName()
  46746. + T("\n\nAre you sure you want to overwrite it?"),
  46747. TRANS("overwrite"),
  46748. TRANS("cancel")))
  46749. {
  46750. return;
  46751. }
  46752. }
  46753. exitModalState (1);
  46754. }
  46755. else if (button == content->cancelButton)
  46756. closeButtonPressed();
  46757. }
  46758. void FileChooserDialogBox::closeButtonPressed()
  46759. {
  46760. setVisible (false);
  46761. }
  46762. void FileChooserDialogBox::selectionChanged()
  46763. {
  46764. content->okButton->setEnabled (content->chooserComponent->currentFileIsValid());
  46765. }
  46766. void FileChooserDialogBox::fileClicked (const File&, const MouseEvent&)
  46767. {
  46768. }
  46769. void FileChooserDialogBox::fileDoubleClicked (const File&)
  46770. {
  46771. selectionChanged();
  46772. content->okButton->triggerClick();
  46773. }
  46774. FileChooserDialogBox::ContentComponent::ContentComponent()
  46775. {
  46776. setInterceptsMouseClicks (false, true);
  46777. }
  46778. FileChooserDialogBox::ContentComponent::~ContentComponent()
  46779. {
  46780. delete okButton;
  46781. delete cancelButton;
  46782. }
  46783. void FileChooserDialogBox::ContentComponent::paint (Graphics& g)
  46784. {
  46785. g.setColour (getLookAndFeel().findColour (FileChooserDialogBox::titleTextColourId));
  46786. text.draw (g);
  46787. }
  46788. void FileChooserDialogBox::ContentComponent::resized()
  46789. {
  46790. getLookAndFeel().createFileChooserHeaderText (getName(), instructions, text, getWidth());
  46791. float left, top, right, bottom;
  46792. text.getBoundingBox (0, text.getNumGlyphs(), left, top, right, bottom, false);
  46793. const int y = roundToInt (bottom) + 10;
  46794. const int buttonHeight = 26;
  46795. const int buttonY = getHeight() - buttonHeight - 8;
  46796. chooserComponent->setBounds (0, y, getWidth(), buttonY - y - 20);
  46797. okButton->setBounds (proportionOfWidth (0.25f), buttonY,
  46798. proportionOfWidth (0.2f), buttonHeight);
  46799. cancelButton->setBounds (proportionOfWidth (0.55f), buttonY,
  46800. proportionOfWidth (0.2f), buttonHeight);
  46801. }
  46802. END_JUCE_NAMESPACE
  46803. /********* End of inlined file: juce_FileChooserDialogBox.cpp *********/
  46804. /********* Start of inlined file: juce_FileFilter.cpp *********/
  46805. BEGIN_JUCE_NAMESPACE
  46806. FileFilter::FileFilter (const String& filterDescription)
  46807. : description (filterDescription)
  46808. {
  46809. }
  46810. FileFilter::~FileFilter()
  46811. {
  46812. }
  46813. const String& FileFilter::getDescription() const throw()
  46814. {
  46815. return description;
  46816. }
  46817. END_JUCE_NAMESPACE
  46818. /********* End of inlined file: juce_FileFilter.cpp *********/
  46819. /********* Start of inlined file: juce_FileListComponent.cpp *********/
  46820. BEGIN_JUCE_NAMESPACE
  46821. Image* juce_createIconForFile (const File& file);
  46822. FileListComponent::FileListComponent (DirectoryContentsList& listToShow)
  46823. : ListBox (String::empty, 0),
  46824. DirectoryContentsDisplayComponent (listToShow)
  46825. {
  46826. setModel (this);
  46827. fileList.addChangeListener (this);
  46828. }
  46829. FileListComponent::~FileListComponent()
  46830. {
  46831. fileList.removeChangeListener (this);
  46832. deleteAllChildren();
  46833. }
  46834. int FileListComponent::getNumSelectedFiles() const
  46835. {
  46836. return getNumSelectedRows();
  46837. }
  46838. const File FileListComponent::getSelectedFile (int index) const
  46839. {
  46840. return fileList.getFile (getSelectedRow (index));
  46841. }
  46842. void FileListComponent::scrollToTop()
  46843. {
  46844. getVerticalScrollBar()->setCurrentRangeStart (0);
  46845. }
  46846. void FileListComponent::changeListenerCallback (void*)
  46847. {
  46848. updateContent();
  46849. if (lastDirectory != fileList.getDirectory())
  46850. {
  46851. lastDirectory = fileList.getDirectory();
  46852. deselectAllRows();
  46853. }
  46854. }
  46855. class FileListItemComponent : public Component,
  46856. public TimeSliceClient,
  46857. public AsyncUpdater
  46858. {
  46859. public:
  46860. FileListItemComponent (FileListComponent& owner_,
  46861. TimeSliceThread& thread_) throw()
  46862. : owner (owner_),
  46863. thread (thread_),
  46864. icon (0)
  46865. {
  46866. }
  46867. ~FileListItemComponent() throw()
  46868. {
  46869. thread.removeTimeSliceClient (this);
  46870. clearIcon();
  46871. }
  46872. void paint (Graphics& g)
  46873. {
  46874. getLookAndFeel().drawFileBrowserRow (g, getWidth(), getHeight(),
  46875. file.getFileName(),
  46876. icon,
  46877. fileSize, modTime,
  46878. isDirectory, highlighted,
  46879. index);
  46880. }
  46881. void mouseDown (const MouseEvent& e)
  46882. {
  46883. owner.selectRowsBasedOnModifierKeys (index, e.mods);
  46884. owner.sendMouseClickMessage (file, e);
  46885. }
  46886. void mouseDoubleClick (const MouseEvent&)
  46887. {
  46888. owner.sendDoubleClickMessage (file);
  46889. }
  46890. void update (const File& root,
  46891. const DirectoryContentsList::FileInfo* const fileInfo,
  46892. const int index_,
  46893. const bool highlighted_) throw()
  46894. {
  46895. thread.removeTimeSliceClient (this);
  46896. if (highlighted_ != highlighted
  46897. || index_ != index)
  46898. {
  46899. index = index_;
  46900. highlighted = highlighted_;
  46901. repaint();
  46902. }
  46903. File newFile;
  46904. String newFileSize;
  46905. String newModTime;
  46906. if (fileInfo != 0)
  46907. {
  46908. newFile = root.getChildFile (fileInfo->filename);
  46909. newFileSize = File::descriptionOfSizeInBytes (fileInfo->fileSize);
  46910. newModTime = fileInfo->modificationTime.formatted (T("%d %b '%y %H:%M"));
  46911. }
  46912. if (newFile != file
  46913. || fileSize != newFileSize
  46914. || modTime != newModTime)
  46915. {
  46916. file = newFile;
  46917. fileSize = newFileSize;
  46918. modTime = newModTime;
  46919. isDirectory = fileInfo != 0 && fileInfo->isDirectory;
  46920. repaint();
  46921. clearIcon();
  46922. }
  46923. if (file != File::nonexistent
  46924. && icon == 0 && ! isDirectory)
  46925. {
  46926. updateIcon (true);
  46927. if (icon == 0)
  46928. thread.addTimeSliceClient (this);
  46929. }
  46930. }
  46931. bool useTimeSlice()
  46932. {
  46933. updateIcon (false);
  46934. return false;
  46935. }
  46936. void handleAsyncUpdate()
  46937. {
  46938. repaint();
  46939. }
  46940. juce_UseDebuggingNewOperator
  46941. private:
  46942. FileListComponent& owner;
  46943. TimeSliceThread& thread;
  46944. bool highlighted;
  46945. int index;
  46946. File file;
  46947. String fileSize;
  46948. String modTime;
  46949. Image* icon;
  46950. bool isDirectory;
  46951. void clearIcon() throw()
  46952. {
  46953. ImageCache::release (icon);
  46954. icon = 0;
  46955. }
  46956. void updateIcon (const bool onlyUpdateIfCached) throw()
  46957. {
  46958. if (icon == 0)
  46959. {
  46960. const int hashCode = (file.getFullPathName() + T("_iconCacheSalt")).hashCode();
  46961. Image* im = ImageCache::getFromHashCode (hashCode);
  46962. if (im == 0 && ! onlyUpdateIfCached)
  46963. {
  46964. im = juce_createIconForFile (file);
  46965. if (im != 0)
  46966. ImageCache::addImageToCache (im, hashCode);
  46967. }
  46968. if (im != 0)
  46969. {
  46970. icon = im;
  46971. triggerAsyncUpdate();
  46972. }
  46973. }
  46974. }
  46975. };
  46976. int FileListComponent::getNumRows()
  46977. {
  46978. return fileList.getNumFiles();
  46979. }
  46980. void FileListComponent::paintListBoxItem (int, Graphics&, int, int, bool)
  46981. {
  46982. }
  46983. Component* FileListComponent::refreshComponentForRow (int row, bool isSelected, Component* existingComponentToUpdate)
  46984. {
  46985. FileListItemComponent* comp = dynamic_cast <FileListItemComponent*> (existingComponentToUpdate);
  46986. if (comp == 0)
  46987. {
  46988. delete existingComponentToUpdate;
  46989. comp = new FileListItemComponent (*this, fileList.getTimeSliceThread());
  46990. }
  46991. DirectoryContentsList::FileInfo fileInfo;
  46992. if (fileList.getFileInfo (row, fileInfo))
  46993. comp->update (fileList.getDirectory(), &fileInfo, row, isSelected);
  46994. else
  46995. comp->update (fileList.getDirectory(), 0, row, isSelected);
  46996. return comp;
  46997. }
  46998. void FileListComponent::selectedRowsChanged (int /*lastRowSelected*/)
  46999. {
  47000. sendSelectionChangeMessage();
  47001. }
  47002. void FileListComponent::deleteKeyPressed (int /*currentSelectedRow*/)
  47003. {
  47004. }
  47005. void FileListComponent::returnKeyPressed (int currentSelectedRow)
  47006. {
  47007. sendDoubleClickMessage (fileList.getFile (currentSelectedRow));
  47008. }
  47009. END_JUCE_NAMESPACE
  47010. /********* End of inlined file: juce_FileListComponent.cpp *********/
  47011. /********* Start of inlined file: juce_FilenameComponent.cpp *********/
  47012. BEGIN_JUCE_NAMESPACE
  47013. FilenameComponent::FilenameComponent (const String& name,
  47014. const File& currentFile,
  47015. const bool canEditFilename,
  47016. const bool isDirectory,
  47017. const bool isForSaving,
  47018. const String& fileBrowserWildcard,
  47019. const String& enforcedSuffix_,
  47020. const String& textWhenNothingSelected)
  47021. : Component (name),
  47022. maxRecentFiles (30),
  47023. isDir (isDirectory),
  47024. isSaving (isForSaving),
  47025. isFileDragOver (false),
  47026. wildcard (fileBrowserWildcard),
  47027. enforcedSuffix (enforcedSuffix_)
  47028. {
  47029. addAndMakeVisible (filenameBox = new ComboBox (T("fn")));
  47030. filenameBox->setEditableText (canEditFilename);
  47031. filenameBox->addListener (this);
  47032. filenameBox->setTextWhenNothingSelected (textWhenNothingSelected);
  47033. filenameBox->setTextWhenNoChoicesAvailable (TRANS("(no recently seleced files)"));
  47034. browseButton = 0;
  47035. setBrowseButtonText (T("..."));
  47036. setCurrentFile (currentFile, true);
  47037. }
  47038. FilenameComponent::~FilenameComponent()
  47039. {
  47040. deleteAllChildren();
  47041. }
  47042. void FilenameComponent::paintOverChildren (Graphics& g)
  47043. {
  47044. if (isFileDragOver)
  47045. {
  47046. g.setColour (Colours::red.withAlpha (0.2f));
  47047. g.drawRect (0, 0, getWidth(), getHeight(), 3);
  47048. }
  47049. }
  47050. void FilenameComponent::resized()
  47051. {
  47052. getLookAndFeel().layoutFilenameComponent (*this, filenameBox, browseButton);
  47053. }
  47054. void FilenameComponent::setBrowseButtonText (const String& newBrowseButtonText)
  47055. {
  47056. browseButtonText = newBrowseButtonText;
  47057. lookAndFeelChanged();
  47058. }
  47059. void FilenameComponent::lookAndFeelChanged()
  47060. {
  47061. deleteAndZero (browseButton);
  47062. addAndMakeVisible (browseButton = getLookAndFeel().createFilenameComponentBrowseButton (browseButtonText));
  47063. browseButton->setConnectedEdges (Button::ConnectedOnLeft);
  47064. resized();
  47065. browseButton->addButtonListener (this);
  47066. }
  47067. void FilenameComponent::setTooltip (const String& newTooltip)
  47068. {
  47069. SettableTooltipClient::setTooltip (newTooltip);
  47070. filenameBox->setTooltip (newTooltip);
  47071. }
  47072. void FilenameComponent::setDefaultBrowseTarget (const File& newDefaultDirectory) throw()
  47073. {
  47074. defaultBrowseFile = newDefaultDirectory;
  47075. }
  47076. void FilenameComponent::buttonClicked (Button*)
  47077. {
  47078. FileChooser fc (TRANS("Choose a new file"),
  47079. getCurrentFile() == File::nonexistent ? defaultBrowseFile
  47080. : getCurrentFile(),
  47081. wildcard);
  47082. if (isDir ? fc.browseForDirectory()
  47083. : (isSaving ? fc.browseForFileToSave (false)
  47084. : fc.browseForFileToOpen()))
  47085. {
  47086. setCurrentFile (fc.getResult(), true);
  47087. }
  47088. }
  47089. void FilenameComponent::comboBoxChanged (ComboBox*)
  47090. {
  47091. setCurrentFile (getCurrentFile(), true);
  47092. }
  47093. bool FilenameComponent::isInterestedInFileDrag (const StringArray&)
  47094. {
  47095. return true;
  47096. }
  47097. void FilenameComponent::filesDropped (const StringArray& filenames, int, int)
  47098. {
  47099. isFileDragOver = false;
  47100. repaint();
  47101. const File f (filenames[0]);
  47102. if (f.exists() && (f.isDirectory() == isDir))
  47103. setCurrentFile (f, true);
  47104. }
  47105. void FilenameComponent::fileDragEnter (const StringArray&, int, int)
  47106. {
  47107. isFileDragOver = true;
  47108. repaint();
  47109. }
  47110. void FilenameComponent::fileDragExit (const StringArray&)
  47111. {
  47112. isFileDragOver = false;
  47113. repaint();
  47114. }
  47115. const File FilenameComponent::getCurrentFile() const
  47116. {
  47117. File f (filenameBox->getText());
  47118. if (enforcedSuffix.isNotEmpty())
  47119. f = f.withFileExtension (enforcedSuffix);
  47120. return f;
  47121. }
  47122. void FilenameComponent::setCurrentFile (File newFile,
  47123. const bool addToRecentlyUsedList,
  47124. const bool sendChangeNotification)
  47125. {
  47126. if (enforcedSuffix.isNotEmpty())
  47127. newFile = newFile.withFileExtension (enforcedSuffix);
  47128. if (newFile.getFullPathName() != lastFilename)
  47129. {
  47130. lastFilename = newFile.getFullPathName();
  47131. if (addToRecentlyUsedList)
  47132. addRecentlyUsedFile (newFile);
  47133. filenameBox->setText (lastFilename, true);
  47134. if (sendChangeNotification)
  47135. triggerAsyncUpdate();
  47136. }
  47137. }
  47138. void FilenameComponent::setFilenameIsEditable (const bool shouldBeEditable)
  47139. {
  47140. filenameBox->setEditableText (shouldBeEditable);
  47141. }
  47142. const StringArray FilenameComponent::getRecentlyUsedFilenames() const
  47143. {
  47144. StringArray names;
  47145. for (int i = 0; i < filenameBox->getNumItems(); ++i)
  47146. names.add (filenameBox->getItemText (i));
  47147. return names;
  47148. }
  47149. void FilenameComponent::setRecentlyUsedFilenames (const StringArray& filenames)
  47150. {
  47151. if (filenames != getRecentlyUsedFilenames())
  47152. {
  47153. filenameBox->clear();
  47154. for (int i = 0; i < jmin (filenames.size(), maxRecentFiles); ++i)
  47155. filenameBox->addItem (filenames[i], i + 1);
  47156. }
  47157. }
  47158. void FilenameComponent::setMaxNumberOfRecentFiles (const int newMaximum)
  47159. {
  47160. maxRecentFiles = jmax (1, newMaximum);
  47161. setRecentlyUsedFilenames (getRecentlyUsedFilenames());
  47162. }
  47163. void FilenameComponent::addRecentlyUsedFile (const File& file)
  47164. {
  47165. StringArray files (getRecentlyUsedFilenames());
  47166. if (file.getFullPathName().isNotEmpty())
  47167. {
  47168. files.removeString (file.getFullPathName(), true);
  47169. files.insert (0, file.getFullPathName());
  47170. setRecentlyUsedFilenames (files);
  47171. }
  47172. }
  47173. void FilenameComponent::addListener (FilenameComponentListener* const listener) throw()
  47174. {
  47175. jassert (listener != 0);
  47176. if (listener != 0)
  47177. listeners.add (listener);
  47178. }
  47179. void FilenameComponent::removeListener (FilenameComponentListener* const listener) throw()
  47180. {
  47181. listeners.removeValue (listener);
  47182. }
  47183. void FilenameComponent::handleAsyncUpdate()
  47184. {
  47185. for (int i = listeners.size(); --i >= 0;)
  47186. {
  47187. ((FilenameComponentListener*) listeners.getUnchecked (i))->filenameComponentChanged (this);
  47188. i = jmin (i, listeners.size());
  47189. }
  47190. }
  47191. END_JUCE_NAMESPACE
  47192. /********* End of inlined file: juce_FilenameComponent.cpp *********/
  47193. /********* Start of inlined file: juce_FileSearchPathListComponent.cpp *********/
  47194. BEGIN_JUCE_NAMESPACE
  47195. FileSearchPathListComponent::FileSearchPathListComponent()
  47196. {
  47197. addAndMakeVisible (listBox = new ListBox (String::empty, this));
  47198. listBox->setColour (ListBox::backgroundColourId, Colours::black.withAlpha (0.02f));
  47199. listBox->setColour (ListBox::outlineColourId, Colours::black.withAlpha (0.1f));
  47200. listBox->setOutlineThickness (1);
  47201. addAndMakeVisible (addButton = new TextButton ("+"));
  47202. addButton->addButtonListener (this);
  47203. addButton->setConnectedEdges (Button::ConnectedOnLeft | Button::ConnectedOnRight | Button::ConnectedOnBottom | Button::ConnectedOnTop);
  47204. addAndMakeVisible (removeButton = new TextButton ("-"));
  47205. removeButton->addButtonListener (this);
  47206. removeButton->setConnectedEdges (Button::ConnectedOnLeft | Button::ConnectedOnRight | Button::ConnectedOnBottom | Button::ConnectedOnTop);
  47207. addAndMakeVisible (changeButton = new TextButton (TRANS("change...")));
  47208. changeButton->addButtonListener (this);
  47209. addAndMakeVisible (upButton = new DrawableButton (String::empty, DrawableButton::ImageOnButtonBackground));
  47210. upButton->addButtonListener (this);
  47211. {
  47212. Path arrowPath;
  47213. arrowPath.addArrow (50.0f, 100.0f, 50.0f, 0.0f, 40.0f, 100.0f, 50.0f);
  47214. DrawablePath arrowImage;
  47215. arrowImage.setFill (Colours::black.withAlpha (0.4f));
  47216. arrowImage.setPath (arrowPath);
  47217. ((DrawableButton*) upButton)->setImages (&arrowImage);
  47218. }
  47219. addAndMakeVisible (downButton = new DrawableButton (String::empty, DrawableButton::ImageOnButtonBackground));
  47220. downButton->addButtonListener (this);
  47221. {
  47222. Path arrowPath;
  47223. arrowPath.addArrow (50.0f, 0.0f, 50.0f, 100.0f, 40.0f, 100.0f, 50.0f);
  47224. DrawablePath arrowImage;
  47225. arrowImage.setFill (Colours::black.withAlpha (0.4f));
  47226. arrowImage.setPath (arrowPath);
  47227. ((DrawableButton*) downButton)->setImages (&arrowImage);
  47228. }
  47229. updateButtons();
  47230. }
  47231. FileSearchPathListComponent::~FileSearchPathListComponent()
  47232. {
  47233. deleteAllChildren();
  47234. }
  47235. void FileSearchPathListComponent::updateButtons() throw()
  47236. {
  47237. const bool anythingSelected = listBox->getNumSelectedRows() > 0;
  47238. removeButton->setEnabled (anythingSelected);
  47239. changeButton->setEnabled (anythingSelected);
  47240. upButton->setEnabled (anythingSelected);
  47241. downButton->setEnabled (anythingSelected);
  47242. }
  47243. void FileSearchPathListComponent::changed() throw()
  47244. {
  47245. listBox->updateContent();
  47246. listBox->repaint();
  47247. updateButtons();
  47248. }
  47249. void FileSearchPathListComponent::setPath (const FileSearchPath& newPath)
  47250. {
  47251. if (newPath.toString() != path.toString())
  47252. {
  47253. path = newPath;
  47254. changed();
  47255. }
  47256. }
  47257. void FileSearchPathListComponent::setDefaultBrowseTarget (const File& newDefaultDirectory) throw()
  47258. {
  47259. defaultBrowseTarget = newDefaultDirectory;
  47260. }
  47261. int FileSearchPathListComponent::getNumRows()
  47262. {
  47263. return path.getNumPaths();
  47264. }
  47265. void FileSearchPathListComponent::paintListBoxItem (int rowNumber, Graphics& g, int width, int height, bool rowIsSelected)
  47266. {
  47267. if (rowIsSelected)
  47268. g.fillAll (findColour (TextEditor::highlightColourId));
  47269. g.setColour (findColour (ListBox::textColourId));
  47270. Font f (height * 0.7f);
  47271. f.setHorizontalScale (0.9f);
  47272. g.setFont (f);
  47273. g.drawText (path [rowNumber].getFullPathName(),
  47274. 4, 0, width - 6, height,
  47275. Justification::centredLeft, true);
  47276. }
  47277. void FileSearchPathListComponent::deleteKeyPressed (int row)
  47278. {
  47279. if (((unsigned int) row) < (unsigned int) path.getNumPaths())
  47280. {
  47281. path.remove (row);
  47282. changed();
  47283. }
  47284. }
  47285. void FileSearchPathListComponent::returnKeyPressed (int row)
  47286. {
  47287. FileChooser chooser (TRANS("Change folder..."), path [row], T("*"));
  47288. if (chooser.browseForDirectory())
  47289. {
  47290. path.remove (row);
  47291. path.add (chooser.getResult(), row);
  47292. changed();
  47293. }
  47294. }
  47295. void FileSearchPathListComponent::listBoxItemDoubleClicked (int row, const MouseEvent&)
  47296. {
  47297. returnKeyPressed (row);
  47298. }
  47299. void FileSearchPathListComponent::selectedRowsChanged (int)
  47300. {
  47301. updateButtons();
  47302. }
  47303. void FileSearchPathListComponent::paint (Graphics& g)
  47304. {
  47305. g.fillAll (findColour (backgroundColourId));
  47306. }
  47307. void FileSearchPathListComponent::resized()
  47308. {
  47309. const int buttonH = 22;
  47310. const int buttonY = getHeight() - buttonH - 4;
  47311. listBox->setBounds (2, 2, getWidth() - 4, buttonY - 5);
  47312. addButton->setBounds (2, buttonY, buttonH, buttonH);
  47313. removeButton->setBounds (addButton->getRight(), buttonY, buttonH, buttonH);
  47314. ((TextButton*) changeButton)->changeWidthToFitText (buttonH);
  47315. downButton->setSize (buttonH * 2, buttonH);
  47316. upButton->setSize (buttonH * 2, buttonH);
  47317. downButton->setTopRightPosition (getWidth() - 2, buttonY);
  47318. upButton->setTopRightPosition (downButton->getX() - 4, buttonY);
  47319. changeButton->setTopRightPosition (upButton->getX() - 8, buttonY);
  47320. }
  47321. bool FileSearchPathListComponent::isInterestedInFileDrag (const StringArray&)
  47322. {
  47323. return true;
  47324. }
  47325. void FileSearchPathListComponent::filesDropped (const StringArray& filenames, int, int mouseY)
  47326. {
  47327. for (int i = filenames.size(); --i >= 0;)
  47328. {
  47329. const File f (filenames[i]);
  47330. if (f.isDirectory())
  47331. {
  47332. const int row = listBox->getRowContainingPosition (0, mouseY - listBox->getY());
  47333. path.add (f, row);
  47334. changed();
  47335. }
  47336. }
  47337. }
  47338. void FileSearchPathListComponent::buttonClicked (Button* button)
  47339. {
  47340. const int currentRow = listBox->getSelectedRow();
  47341. if (button == removeButton)
  47342. {
  47343. deleteKeyPressed (currentRow);
  47344. }
  47345. else if (button == addButton)
  47346. {
  47347. File start (defaultBrowseTarget);
  47348. if (start == File::nonexistent)
  47349. start = path [0];
  47350. if (start == File::nonexistent)
  47351. start = File::getCurrentWorkingDirectory();
  47352. FileChooser chooser (TRANS("Add a folder..."), start, T("*"));
  47353. if (chooser.browseForDirectory())
  47354. {
  47355. path.add (chooser.getResult(), currentRow);
  47356. }
  47357. }
  47358. else if (button == changeButton)
  47359. {
  47360. returnKeyPressed (currentRow);
  47361. }
  47362. else if (button == upButton)
  47363. {
  47364. if (currentRow > 0 && currentRow < path.getNumPaths())
  47365. {
  47366. const File f (path[currentRow]);
  47367. path.remove (currentRow);
  47368. path.add (f, currentRow - 1);
  47369. listBox->selectRow (currentRow - 1);
  47370. }
  47371. }
  47372. else if (button == downButton)
  47373. {
  47374. if (currentRow >= 0 && currentRow < path.getNumPaths() - 1)
  47375. {
  47376. const File f (path[currentRow]);
  47377. path.remove (currentRow);
  47378. path.add (f, currentRow + 1);
  47379. listBox->selectRow (currentRow + 1);
  47380. }
  47381. }
  47382. changed();
  47383. }
  47384. END_JUCE_NAMESPACE
  47385. /********* End of inlined file: juce_FileSearchPathListComponent.cpp *********/
  47386. /********* Start of inlined file: juce_FileTreeComponent.cpp *********/
  47387. BEGIN_JUCE_NAMESPACE
  47388. Image* juce_createIconForFile (const File& file);
  47389. class FileListTreeItem : public TreeViewItem,
  47390. public TimeSliceClient,
  47391. public AsyncUpdater,
  47392. public ChangeListener
  47393. {
  47394. public:
  47395. FileListTreeItem (FileTreeComponent& owner_,
  47396. DirectoryContentsList* const parentContentsList_,
  47397. const int indexInContentsList_,
  47398. const File& file_,
  47399. TimeSliceThread& thread_) throw()
  47400. : file (file_),
  47401. owner (owner_),
  47402. parentContentsList (parentContentsList_),
  47403. indexInContentsList (indexInContentsList_),
  47404. subContentsList (0),
  47405. canDeleteSubContentsList (false),
  47406. thread (thread_),
  47407. icon (0)
  47408. {
  47409. DirectoryContentsList::FileInfo fileInfo;
  47410. if (parentContentsList_ != 0
  47411. && parentContentsList_->getFileInfo (indexInContentsList_, fileInfo))
  47412. {
  47413. fileSize = File::descriptionOfSizeInBytes (fileInfo.fileSize);
  47414. modTime = fileInfo.modificationTime.formatted (T("%d %b '%y %H:%M"));
  47415. isDirectory = fileInfo.isDirectory;
  47416. }
  47417. else
  47418. {
  47419. isDirectory = true;
  47420. }
  47421. }
  47422. ~FileListTreeItem() throw()
  47423. {
  47424. thread.removeTimeSliceClient (this);
  47425. clearSubItems();
  47426. ImageCache::release (icon);
  47427. if (canDeleteSubContentsList)
  47428. delete subContentsList;
  47429. }
  47430. bool mightContainSubItems() { return isDirectory; }
  47431. const String getUniqueName() const { return file.getFullPathName(); }
  47432. int getItemHeight() const { return 22; }
  47433. const String getDragSourceDescription() { return owner.getDragAndDropDescription(); }
  47434. void itemOpennessChanged (bool isNowOpen)
  47435. {
  47436. if (isNowOpen)
  47437. {
  47438. clearSubItems();
  47439. isDirectory = file.isDirectory();
  47440. if (isDirectory)
  47441. {
  47442. if (subContentsList == 0)
  47443. {
  47444. jassert (parentContentsList != 0);
  47445. DirectoryContentsList* const l = new DirectoryContentsList (parentContentsList->getFilter(), thread);
  47446. l->setDirectory (file, true, true);
  47447. setSubContentsList (l);
  47448. canDeleteSubContentsList = true;
  47449. }
  47450. changeListenerCallback (0);
  47451. }
  47452. }
  47453. }
  47454. void setSubContentsList (DirectoryContentsList* newList) throw()
  47455. {
  47456. jassert (subContentsList == 0);
  47457. subContentsList = newList;
  47458. newList->addChangeListener (this);
  47459. }
  47460. void changeListenerCallback (void*)
  47461. {
  47462. clearSubItems();
  47463. if (isOpen() && subContentsList != 0)
  47464. {
  47465. for (int i = 0; i < subContentsList->getNumFiles(); ++i)
  47466. {
  47467. FileListTreeItem* const item
  47468. = new FileListTreeItem (owner, subContentsList, i, subContentsList->getFile(i), thread);
  47469. addSubItem (item);
  47470. }
  47471. }
  47472. }
  47473. void paintItem (Graphics& g, int width, int height)
  47474. {
  47475. if (file != File::nonexistent)
  47476. {
  47477. updateIcon (true);
  47478. if (icon == 0)
  47479. thread.addTimeSliceClient (this);
  47480. }
  47481. owner.getLookAndFeel()
  47482. .drawFileBrowserRow (g, width, height,
  47483. file.getFileName(),
  47484. icon,
  47485. fileSize, modTime,
  47486. isDirectory, isSelected(),
  47487. indexInContentsList);
  47488. }
  47489. void itemClicked (const MouseEvent& e)
  47490. {
  47491. owner.sendMouseClickMessage (file, e);
  47492. }
  47493. void itemDoubleClicked (const MouseEvent& e)
  47494. {
  47495. TreeViewItem::itemDoubleClicked (e);
  47496. owner.sendDoubleClickMessage (file);
  47497. }
  47498. void itemSelectionChanged (bool)
  47499. {
  47500. owner.sendSelectionChangeMessage();
  47501. }
  47502. bool useTimeSlice()
  47503. {
  47504. updateIcon (false);
  47505. thread.removeTimeSliceClient (this);
  47506. return false;
  47507. }
  47508. void handleAsyncUpdate()
  47509. {
  47510. owner.repaint();
  47511. }
  47512. const File file;
  47513. juce_UseDebuggingNewOperator
  47514. private:
  47515. FileTreeComponent& owner;
  47516. DirectoryContentsList* parentContentsList;
  47517. int indexInContentsList;
  47518. DirectoryContentsList* subContentsList;
  47519. bool isDirectory, canDeleteSubContentsList;
  47520. TimeSliceThread& thread;
  47521. Image* icon;
  47522. String fileSize;
  47523. String modTime;
  47524. void updateIcon (const bool onlyUpdateIfCached) throw()
  47525. {
  47526. if (icon == 0)
  47527. {
  47528. const int hashCode = (file.getFullPathName() + T("_iconCacheSalt")).hashCode();
  47529. Image* im = ImageCache::getFromHashCode (hashCode);
  47530. if (im == 0 && ! onlyUpdateIfCached)
  47531. {
  47532. im = juce_createIconForFile (file);
  47533. if (im != 0)
  47534. ImageCache::addImageToCache (im, hashCode);
  47535. }
  47536. if (im != 0)
  47537. {
  47538. icon = im;
  47539. triggerAsyncUpdate();
  47540. }
  47541. }
  47542. }
  47543. };
  47544. FileTreeComponent::FileTreeComponent (DirectoryContentsList& listToShow)
  47545. : DirectoryContentsDisplayComponent (listToShow)
  47546. {
  47547. FileListTreeItem* const root
  47548. = new FileListTreeItem (*this, 0, 0, listToShow.getDirectory(),
  47549. listToShow.getTimeSliceThread());
  47550. root->setSubContentsList (&listToShow);
  47551. setRootItemVisible (false);
  47552. setRootItem (root);
  47553. }
  47554. FileTreeComponent::~FileTreeComponent()
  47555. {
  47556. deleteRootItem();
  47557. }
  47558. const File FileTreeComponent::getSelectedFile (const int index) const
  47559. {
  47560. const FileListTreeItem* const item = dynamic_cast <const FileListTreeItem*> (getSelectedItem (index));
  47561. if (item != 0)
  47562. return item->file;
  47563. return File::nonexistent;
  47564. }
  47565. void FileTreeComponent::scrollToTop()
  47566. {
  47567. getViewport()->getVerticalScrollBar()->setCurrentRangeStart (0);
  47568. }
  47569. void FileTreeComponent::setDragAndDropDescription (const String& description) throw()
  47570. {
  47571. dragAndDropDescription = description;
  47572. }
  47573. END_JUCE_NAMESPACE
  47574. /********* End of inlined file: juce_FileTreeComponent.cpp *********/
  47575. /********* Start of inlined file: juce_ImagePreviewComponent.cpp *********/
  47576. BEGIN_JUCE_NAMESPACE
  47577. ImagePreviewComponent::ImagePreviewComponent()
  47578. {
  47579. }
  47580. ImagePreviewComponent::~ImagePreviewComponent()
  47581. {
  47582. }
  47583. void ImagePreviewComponent::getThumbSize (int& w, int& h) const
  47584. {
  47585. const int availableW = proportionOfWidth (0.97f);
  47586. const int availableH = getHeight() - 13 * 4;
  47587. const double scale = jmin (1.0,
  47588. availableW / (double) w,
  47589. availableH / (double) h);
  47590. w = roundToInt (scale * w);
  47591. h = roundToInt (scale * h);
  47592. }
  47593. void ImagePreviewComponent::selectedFileChanged (const File& file)
  47594. {
  47595. if (fileToLoad != file)
  47596. {
  47597. fileToLoad = file;
  47598. startTimer (100);
  47599. }
  47600. }
  47601. void ImagePreviewComponent::timerCallback()
  47602. {
  47603. stopTimer();
  47604. currentThumbnail = 0;
  47605. currentDetails = String::empty;
  47606. repaint();
  47607. ScopedPointer <FileInputStream> in (fileToLoad.createInputStream());
  47608. if (in != 0)
  47609. {
  47610. ImageFileFormat* const format = ImageFileFormat::findImageFormatForStream (*in);
  47611. if (format != 0)
  47612. {
  47613. currentThumbnail = format->decodeImage (*in);
  47614. if (currentThumbnail != 0)
  47615. {
  47616. int w = currentThumbnail->getWidth();
  47617. int h = currentThumbnail->getHeight();
  47618. currentDetails
  47619. << fileToLoad.getFileName() << "\n"
  47620. << format->getFormatName() << "\n"
  47621. << w << " x " << h << " pixels\n"
  47622. << File::descriptionOfSizeInBytes (fileToLoad.getSize());
  47623. getThumbSize (w, h);
  47624. currentThumbnail = currentThumbnail->createCopy (w, h);
  47625. }
  47626. }
  47627. }
  47628. }
  47629. void ImagePreviewComponent::paint (Graphics& g)
  47630. {
  47631. if (currentThumbnail != 0)
  47632. {
  47633. g.setFont (13.0f);
  47634. int w = currentThumbnail->getWidth();
  47635. int h = currentThumbnail->getHeight();
  47636. getThumbSize (w, h);
  47637. const int numLines = 4;
  47638. const int totalH = 13 * numLines + h + 4;
  47639. const int y = (getHeight() - totalH) / 2;
  47640. g.drawImageWithin (currentThumbnail,
  47641. (getWidth() - w) / 2, y, w, h,
  47642. RectanglePlacement::centred | RectanglePlacement::onlyReduceInSize,
  47643. false);
  47644. g.drawFittedText (currentDetails,
  47645. 0, y + h + 4, getWidth(), 100,
  47646. Justification::centredTop, numLines);
  47647. }
  47648. }
  47649. END_JUCE_NAMESPACE
  47650. /********* End of inlined file: juce_ImagePreviewComponent.cpp *********/
  47651. /********* Start of inlined file: juce_WildcardFileFilter.cpp *********/
  47652. BEGIN_JUCE_NAMESPACE
  47653. WildcardFileFilter::WildcardFileFilter (const String& fileWildcardPatterns,
  47654. const String& directoryWildcardPatterns,
  47655. const String& description_)
  47656. : FileFilter (description_.isEmpty() ? fileWildcardPatterns
  47657. : (description_ + T(" (") + fileWildcardPatterns + T(")")))
  47658. {
  47659. parse (fileWildcardPatterns, fileWildcards);
  47660. parse (directoryWildcardPatterns, directoryWildcards);
  47661. }
  47662. WildcardFileFilter::~WildcardFileFilter()
  47663. {
  47664. }
  47665. bool WildcardFileFilter::isFileSuitable (const File& file) const
  47666. {
  47667. return match (file, fileWildcards);
  47668. }
  47669. bool WildcardFileFilter::isDirectorySuitable (const File& file) const
  47670. {
  47671. return match (file, directoryWildcards);
  47672. }
  47673. void WildcardFileFilter::parse (const String& pattern, StringArray& result) throw()
  47674. {
  47675. result.addTokens (pattern.toLowerCase(), T(";,"), T("\"'"));
  47676. result.trim();
  47677. result.removeEmptyStrings();
  47678. // special case for *.*, because people use it to mean "any file", but it
  47679. // would actually ignore files with no extension.
  47680. for (int i = result.size(); --i >= 0;)
  47681. if (result[i] == T("*.*"))
  47682. result.set (i, T("*"));
  47683. }
  47684. bool WildcardFileFilter::match (const File& file, const StringArray& wildcards) throw()
  47685. {
  47686. const String filename (file.getFileName());
  47687. for (int i = wildcards.size(); --i >= 0;)
  47688. if (filename.matchesWildcard (wildcards[i], true))
  47689. return true;
  47690. return false;
  47691. }
  47692. END_JUCE_NAMESPACE
  47693. /********* End of inlined file: juce_WildcardFileFilter.cpp *********/
  47694. /********* Start of inlined file: juce_KeyboardFocusTraverser.cpp *********/
  47695. BEGIN_JUCE_NAMESPACE
  47696. KeyboardFocusTraverser::KeyboardFocusTraverser()
  47697. {
  47698. }
  47699. KeyboardFocusTraverser::~KeyboardFocusTraverser()
  47700. {
  47701. }
  47702. // This will sort a set of components, so that they are ordered in terms of
  47703. // left-to-right and then top-to-bottom.
  47704. class ScreenPositionComparator
  47705. {
  47706. public:
  47707. ScreenPositionComparator() {}
  47708. static int compareElements (const Component* const first, const Component* const second) throw()
  47709. {
  47710. int explicitOrder1 = first->getExplicitFocusOrder();
  47711. if (explicitOrder1 <= 0)
  47712. explicitOrder1 = INT_MAX / 2;
  47713. int explicitOrder2 = second->getExplicitFocusOrder();
  47714. if (explicitOrder2 <= 0)
  47715. explicitOrder2 = INT_MAX / 2;
  47716. if (explicitOrder1 != explicitOrder2)
  47717. return explicitOrder1 - explicitOrder2;
  47718. const int diff = first->getY() - second->getY();
  47719. return (diff == 0) ? first->getX() - second->getX()
  47720. : diff;
  47721. }
  47722. };
  47723. static void findAllFocusableComponents (Component* const parent, Array <Component*>& comps)
  47724. {
  47725. if (parent->getNumChildComponents() > 0)
  47726. {
  47727. Array <Component*> localComps;
  47728. ScreenPositionComparator comparator;
  47729. int i;
  47730. for (i = parent->getNumChildComponents(); --i >= 0;)
  47731. {
  47732. Component* const c = parent->getChildComponent (i);
  47733. if (c->isVisible() && c->isEnabled())
  47734. localComps.addSorted (comparator, c);
  47735. }
  47736. for (i = 0; i < localComps.size(); ++i)
  47737. {
  47738. Component* const c = localComps.getUnchecked (i);
  47739. if (c->getWantsKeyboardFocus())
  47740. comps.add (c);
  47741. if (! c->isFocusContainer())
  47742. findAllFocusableComponents (c, comps);
  47743. }
  47744. }
  47745. }
  47746. static Component* getIncrementedComponent (Component* const current, const int delta) throw()
  47747. {
  47748. Component* focusContainer = current->getParentComponent();
  47749. if (focusContainer != 0)
  47750. {
  47751. while (focusContainer->getParentComponent() != 0 && ! focusContainer->isFocusContainer())
  47752. focusContainer = focusContainer->getParentComponent();
  47753. if (focusContainer != 0)
  47754. {
  47755. Array <Component*> comps;
  47756. findAllFocusableComponents (focusContainer, comps);
  47757. if (comps.size() > 0)
  47758. {
  47759. const int index = comps.indexOf (current);
  47760. return comps [(index + comps.size() + delta) % comps.size()];
  47761. }
  47762. }
  47763. }
  47764. return 0;
  47765. }
  47766. Component* KeyboardFocusTraverser::getNextComponent (Component* current)
  47767. {
  47768. return getIncrementedComponent (current, 1);
  47769. }
  47770. Component* KeyboardFocusTraverser::getPreviousComponent (Component* current)
  47771. {
  47772. return getIncrementedComponent (current, -1);
  47773. }
  47774. Component* KeyboardFocusTraverser::getDefaultComponent (Component* parentComponent)
  47775. {
  47776. Array <Component*> comps;
  47777. if (parentComponent != 0)
  47778. findAllFocusableComponents (parentComponent, comps);
  47779. return comps.getFirst();
  47780. }
  47781. END_JUCE_NAMESPACE
  47782. /********* End of inlined file: juce_KeyboardFocusTraverser.cpp *********/
  47783. /********* Start of inlined file: juce_KeyListener.cpp *********/
  47784. BEGIN_JUCE_NAMESPACE
  47785. bool KeyListener::keyStateChanged (const bool, Component*)
  47786. {
  47787. return false;
  47788. }
  47789. END_JUCE_NAMESPACE
  47790. /********* End of inlined file: juce_KeyListener.cpp *********/
  47791. /********* Start of inlined file: juce_KeyMappingEditorComponent.cpp *********/
  47792. BEGIN_JUCE_NAMESPACE
  47793. // N.B. these two includes are put here deliberately to avoid problems with
  47794. // old GCCs failing on long include paths
  47795. const int maxKeys = 3;
  47796. class KeyMappingChangeButton : public Button
  47797. {
  47798. public:
  47799. KeyMappingChangeButton (KeyMappingEditorComponent* const owner_,
  47800. const CommandID commandID_,
  47801. const String& keyName,
  47802. const int keyNum_)
  47803. : Button (keyName),
  47804. owner (owner_),
  47805. commandID (commandID_),
  47806. keyNum (keyNum_)
  47807. {
  47808. setWantsKeyboardFocus (false);
  47809. setTriggeredOnMouseDown (keyNum >= 0);
  47810. if (keyNum_ < 0)
  47811. setTooltip (TRANS("adds a new key-mapping"));
  47812. else
  47813. setTooltip (TRANS("click to change this key-mapping"));
  47814. }
  47815. ~KeyMappingChangeButton()
  47816. {
  47817. }
  47818. void paintButton (Graphics& g, bool /*isOver*/, bool /*isDown*/)
  47819. {
  47820. getLookAndFeel().drawKeymapChangeButton (g, getWidth(), getHeight(), *this,
  47821. keyNum >= 0 ? getName() : String::empty);
  47822. }
  47823. void clicked()
  47824. {
  47825. if (keyNum >= 0)
  47826. {
  47827. // existing key clicked..
  47828. PopupMenu m;
  47829. m.addItem (1, TRANS("change this key-mapping"));
  47830. m.addSeparator();
  47831. m.addItem (2, TRANS("remove this key-mapping"));
  47832. const int res = m.show();
  47833. if (res == 1)
  47834. {
  47835. owner->assignNewKey (commandID, keyNum);
  47836. }
  47837. else if (res == 2)
  47838. {
  47839. owner->getMappings()->removeKeyPress (commandID, keyNum);
  47840. }
  47841. }
  47842. else
  47843. {
  47844. // + button pressed..
  47845. owner->assignNewKey (commandID, -1);
  47846. }
  47847. }
  47848. void fitToContent (const int h) throw()
  47849. {
  47850. if (keyNum < 0)
  47851. {
  47852. setSize (h, h);
  47853. }
  47854. else
  47855. {
  47856. Font f (h * 0.6f);
  47857. setSize (jlimit (h * 4, h * 8, 6 + f.getStringWidth (getName())), h);
  47858. }
  47859. }
  47860. juce_UseDebuggingNewOperator
  47861. private:
  47862. KeyMappingEditorComponent* const owner;
  47863. const CommandID commandID;
  47864. const int keyNum;
  47865. KeyMappingChangeButton (const KeyMappingChangeButton&);
  47866. const KeyMappingChangeButton& operator= (const KeyMappingChangeButton&);
  47867. };
  47868. class KeyMappingItemComponent : public Component
  47869. {
  47870. public:
  47871. KeyMappingItemComponent (KeyMappingEditorComponent* const owner_,
  47872. const CommandID commandID_)
  47873. : owner (owner_),
  47874. commandID (commandID_)
  47875. {
  47876. setInterceptsMouseClicks (false, true);
  47877. const bool isReadOnly = owner_->isCommandReadOnly (commandID);
  47878. const Array <KeyPress> keyPresses (owner_->getMappings()->getKeyPressesAssignedToCommand (commandID));
  47879. for (int i = 0; i < jmin (maxKeys, keyPresses.size()); ++i)
  47880. {
  47881. KeyMappingChangeButton* const kb
  47882. = new KeyMappingChangeButton (owner_, commandID,
  47883. owner_->getDescriptionForKeyPress (keyPresses.getReference (i)), i);
  47884. kb->setEnabled (! isReadOnly);
  47885. addAndMakeVisible (kb);
  47886. }
  47887. KeyMappingChangeButton* const kb
  47888. = new KeyMappingChangeButton (owner_, commandID, String::empty, -1);
  47889. addChildComponent (kb);
  47890. kb->setVisible (keyPresses.size() < maxKeys && ! isReadOnly);
  47891. }
  47892. ~KeyMappingItemComponent()
  47893. {
  47894. deleteAllChildren();
  47895. }
  47896. void paint (Graphics& g)
  47897. {
  47898. g.setFont (getHeight() * 0.7f);
  47899. g.setColour (findColour (KeyMappingEditorComponent::textColourId));
  47900. g.drawFittedText (owner->getMappings()->getCommandManager()->getNameOfCommand (commandID),
  47901. 4, 0, jmax (40, getChildComponent (0)->getX() - 5), getHeight(),
  47902. Justification::centredLeft, true);
  47903. }
  47904. void resized()
  47905. {
  47906. int x = getWidth() - 4;
  47907. for (int i = getNumChildComponents(); --i >= 0;)
  47908. {
  47909. KeyMappingChangeButton* const kb = dynamic_cast <KeyMappingChangeButton*> (getChildComponent (i));
  47910. kb->fitToContent (getHeight() - 2);
  47911. kb->setTopRightPosition (x, 1);
  47912. x -= kb->getWidth() + 5;
  47913. }
  47914. }
  47915. juce_UseDebuggingNewOperator
  47916. private:
  47917. KeyMappingEditorComponent* const owner;
  47918. const CommandID commandID;
  47919. KeyMappingItemComponent (const KeyMappingItemComponent&);
  47920. const KeyMappingItemComponent& operator= (const KeyMappingItemComponent&);
  47921. };
  47922. class KeyMappingTreeViewItem : public TreeViewItem
  47923. {
  47924. public:
  47925. KeyMappingTreeViewItem (KeyMappingEditorComponent* const owner_,
  47926. const CommandID commandID_)
  47927. : owner (owner_),
  47928. commandID (commandID_)
  47929. {
  47930. }
  47931. ~KeyMappingTreeViewItem()
  47932. {
  47933. }
  47934. const String getUniqueName() const { return String ((int) commandID) + "_id"; }
  47935. bool mightContainSubItems() { return false; }
  47936. int getItemHeight() const { return 20; }
  47937. Component* createItemComponent()
  47938. {
  47939. return new KeyMappingItemComponent (owner, commandID);
  47940. }
  47941. juce_UseDebuggingNewOperator
  47942. private:
  47943. KeyMappingEditorComponent* const owner;
  47944. const CommandID commandID;
  47945. KeyMappingTreeViewItem (const KeyMappingTreeViewItem&);
  47946. const KeyMappingTreeViewItem& operator= (const KeyMappingTreeViewItem&);
  47947. };
  47948. class KeyCategoryTreeViewItem : public TreeViewItem
  47949. {
  47950. public:
  47951. KeyCategoryTreeViewItem (KeyMappingEditorComponent* const owner_,
  47952. const String& name)
  47953. : owner (owner_),
  47954. categoryName (name)
  47955. {
  47956. }
  47957. ~KeyCategoryTreeViewItem()
  47958. {
  47959. }
  47960. const String getUniqueName() const { return categoryName + "_cat"; }
  47961. bool mightContainSubItems() { return true; }
  47962. int getItemHeight() const { return 28; }
  47963. void paintItem (Graphics& g, int width, int height)
  47964. {
  47965. g.setFont (height * 0.6f, Font::bold);
  47966. g.setColour (owner->findColour (KeyMappingEditorComponent::textColourId));
  47967. g.drawText (categoryName,
  47968. 2, 0, width - 2, height,
  47969. Justification::centredLeft, true);
  47970. }
  47971. void itemOpennessChanged (bool isNowOpen)
  47972. {
  47973. if (isNowOpen)
  47974. {
  47975. if (getNumSubItems() == 0)
  47976. {
  47977. Array <CommandID> commands (owner->getMappings()->getCommandManager()->getCommandsInCategory (categoryName));
  47978. for (int i = 0; i < commands.size(); ++i)
  47979. {
  47980. if (owner->shouldCommandBeIncluded (commands[i]))
  47981. addSubItem (new KeyMappingTreeViewItem (owner, commands[i]));
  47982. }
  47983. }
  47984. }
  47985. else
  47986. {
  47987. clearSubItems();
  47988. }
  47989. }
  47990. juce_UseDebuggingNewOperator
  47991. private:
  47992. KeyMappingEditorComponent* owner;
  47993. String categoryName;
  47994. KeyCategoryTreeViewItem (const KeyCategoryTreeViewItem&);
  47995. const KeyCategoryTreeViewItem& operator= (const KeyCategoryTreeViewItem&);
  47996. };
  47997. KeyMappingEditorComponent::KeyMappingEditorComponent (KeyPressMappingSet* const mappingManager,
  47998. const bool showResetToDefaultButton)
  47999. : mappings (mappingManager)
  48000. {
  48001. jassert (mappingManager != 0); // can't be null!
  48002. mappingManager->addChangeListener (this);
  48003. setLinesDrawnForSubItems (false);
  48004. resetButton = 0;
  48005. if (showResetToDefaultButton)
  48006. {
  48007. addAndMakeVisible (resetButton = new TextButton (TRANS("reset to defaults")));
  48008. resetButton->addButtonListener (this);
  48009. }
  48010. addAndMakeVisible (tree = new TreeView());
  48011. tree->setColour (TreeView::backgroundColourId, findColour (backgroundColourId));
  48012. tree->setRootItemVisible (false);
  48013. tree->setDefaultOpenness (true);
  48014. tree->setRootItem (this);
  48015. }
  48016. KeyMappingEditorComponent::~KeyMappingEditorComponent()
  48017. {
  48018. mappings->removeChangeListener (this);
  48019. deleteAllChildren();
  48020. }
  48021. bool KeyMappingEditorComponent::mightContainSubItems()
  48022. {
  48023. return true;
  48024. }
  48025. const String KeyMappingEditorComponent::getUniqueName() const
  48026. {
  48027. return T("keys");
  48028. }
  48029. void KeyMappingEditorComponent::setColours (const Colour& mainBackground,
  48030. const Colour& textColour)
  48031. {
  48032. setColour (backgroundColourId, mainBackground);
  48033. setColour (textColourId, textColour);
  48034. tree->setColour (TreeView::backgroundColourId, mainBackground);
  48035. }
  48036. void KeyMappingEditorComponent::parentHierarchyChanged()
  48037. {
  48038. changeListenerCallback (0);
  48039. }
  48040. void KeyMappingEditorComponent::resized()
  48041. {
  48042. int h = getHeight();
  48043. if (resetButton != 0)
  48044. {
  48045. const int buttonHeight = 20;
  48046. h -= buttonHeight + 8;
  48047. int x = getWidth() - 8;
  48048. const int y = h + 6;
  48049. resetButton->changeWidthToFitText (buttonHeight);
  48050. resetButton->setTopRightPosition (x, y);
  48051. }
  48052. tree->setBounds (0, 0, getWidth(), h);
  48053. }
  48054. void KeyMappingEditorComponent::buttonClicked (Button* button)
  48055. {
  48056. if (button == resetButton)
  48057. {
  48058. if (AlertWindow::showOkCancelBox (AlertWindow::QuestionIcon,
  48059. TRANS("Reset to defaults"),
  48060. TRANS("Are you sure you want to reset all the key-mappings to their default state?"),
  48061. TRANS("Reset")))
  48062. {
  48063. mappings->resetToDefaultMappings();
  48064. }
  48065. }
  48066. }
  48067. void KeyMappingEditorComponent::changeListenerCallback (void*)
  48068. {
  48069. ScopedPointer <XmlElement> openness (tree->getOpennessState (true));
  48070. clearSubItems();
  48071. const StringArray categories (mappings->getCommandManager()->getCommandCategories());
  48072. for (int i = 0; i < categories.size(); ++i)
  48073. {
  48074. const Array <CommandID> commands (mappings->getCommandManager()->getCommandsInCategory (categories[i]));
  48075. int count = 0;
  48076. for (int j = 0; j < commands.size(); ++j)
  48077. if (shouldCommandBeIncluded (commands[j]))
  48078. ++count;
  48079. if (count > 0)
  48080. addSubItem (new KeyCategoryTreeViewItem (this, categories[i]));
  48081. }
  48082. if (openness != 0)
  48083. tree->restoreOpennessState (*openness);
  48084. }
  48085. class KeyEntryWindow : public AlertWindow
  48086. {
  48087. public:
  48088. KeyEntryWindow (KeyMappingEditorComponent* const owner_)
  48089. : AlertWindow (TRANS("New key-mapping"),
  48090. TRANS("Please press a key combination now..."),
  48091. AlertWindow::NoIcon),
  48092. owner (owner_)
  48093. {
  48094. addButton (TRANS("ok"), 1);
  48095. addButton (TRANS("cancel"), 0);
  48096. // (avoid return + escape keys getting processed by the buttons..)
  48097. for (int i = getNumChildComponents(); --i >= 0;)
  48098. getChildComponent (i)->setWantsKeyboardFocus (false);
  48099. setWantsKeyboardFocus (true);
  48100. grabKeyboardFocus();
  48101. }
  48102. ~KeyEntryWindow()
  48103. {
  48104. }
  48105. bool keyPressed (const KeyPress& key)
  48106. {
  48107. lastPress = key;
  48108. String message (TRANS("Key: ") + owner->getDescriptionForKeyPress (key));
  48109. const CommandID previousCommand = owner->getMappings()->findCommandForKeyPress (key);
  48110. if (previousCommand != 0)
  48111. {
  48112. message << "\n\n"
  48113. << TRANS("(Currently assigned to \"")
  48114. << owner->getMappings()->getCommandManager()->getNameOfCommand (previousCommand)
  48115. << "\")";
  48116. }
  48117. setMessage (message);
  48118. return true;
  48119. }
  48120. bool keyStateChanged (const bool)
  48121. {
  48122. return true;
  48123. }
  48124. KeyPress lastPress;
  48125. juce_UseDebuggingNewOperator
  48126. private:
  48127. KeyMappingEditorComponent* owner;
  48128. KeyEntryWindow (const KeyEntryWindow&);
  48129. const KeyEntryWindow& operator= (const KeyEntryWindow&);
  48130. };
  48131. void KeyMappingEditorComponent::assignNewKey (const CommandID commandID, const int index)
  48132. {
  48133. KeyEntryWindow entryWindow (this);
  48134. if (entryWindow.runModalLoop() != 0)
  48135. {
  48136. entryWindow.setVisible (false);
  48137. if (entryWindow.lastPress.isValid())
  48138. {
  48139. const CommandID previousCommand = mappings->findCommandForKeyPress (entryWindow.lastPress);
  48140. if (previousCommand != 0)
  48141. {
  48142. if (! AlertWindow::showOkCancelBox (AlertWindow::WarningIcon,
  48143. TRANS("Change key-mapping"),
  48144. TRANS("This key is already assigned to the command \"")
  48145. + mappings->getCommandManager()->getNameOfCommand (previousCommand)
  48146. + TRANS("\"\n\nDo you want to re-assign it to this new command instead?"),
  48147. TRANS("re-assign"),
  48148. TRANS("cancel")))
  48149. {
  48150. return;
  48151. }
  48152. }
  48153. mappings->removeKeyPress (entryWindow.lastPress);
  48154. if (index >= 0)
  48155. mappings->removeKeyPress (commandID, index);
  48156. mappings->addKeyPress (commandID, entryWindow.lastPress, index);
  48157. }
  48158. }
  48159. }
  48160. bool KeyMappingEditorComponent::shouldCommandBeIncluded (const CommandID commandID)
  48161. {
  48162. const ApplicationCommandInfo* const ci = mappings->getCommandManager()->getCommandForID (commandID);
  48163. return (ci != 0) && ((ci->flags & ApplicationCommandInfo::hiddenFromKeyEditor) == 0);
  48164. }
  48165. bool KeyMappingEditorComponent::isCommandReadOnly (const CommandID commandID)
  48166. {
  48167. const ApplicationCommandInfo* const ci = mappings->getCommandManager()->getCommandForID (commandID);
  48168. return (ci != 0) && ((ci->flags & ApplicationCommandInfo::readOnlyInKeyEditor) != 0);
  48169. }
  48170. const String KeyMappingEditorComponent::getDescriptionForKeyPress (const KeyPress& key)
  48171. {
  48172. return key.getTextDescription();
  48173. }
  48174. END_JUCE_NAMESPACE
  48175. /********* End of inlined file: juce_KeyMappingEditorComponent.cpp *********/
  48176. /********* Start of inlined file: juce_KeyPress.cpp *********/
  48177. BEGIN_JUCE_NAMESPACE
  48178. KeyPress::KeyPress() throw()
  48179. : keyCode (0),
  48180. mods (0),
  48181. textCharacter (0)
  48182. {
  48183. }
  48184. KeyPress::KeyPress (const int keyCode_,
  48185. const ModifierKeys& mods_,
  48186. const juce_wchar textCharacter_) throw()
  48187. : keyCode (keyCode_),
  48188. mods (mods_),
  48189. textCharacter (textCharacter_)
  48190. {
  48191. }
  48192. KeyPress::KeyPress (const int keyCode_) throw()
  48193. : keyCode (keyCode_),
  48194. textCharacter (0)
  48195. {
  48196. }
  48197. KeyPress::KeyPress (const KeyPress& other) throw()
  48198. : keyCode (other.keyCode),
  48199. mods (other.mods),
  48200. textCharacter (other.textCharacter)
  48201. {
  48202. }
  48203. const KeyPress& KeyPress::operator= (const KeyPress& other) throw()
  48204. {
  48205. keyCode = other.keyCode;
  48206. mods = other.mods;
  48207. textCharacter = other.textCharacter;
  48208. return *this;
  48209. }
  48210. bool KeyPress::operator== (const KeyPress& other) const throw()
  48211. {
  48212. return mods.getRawFlags() == other.mods.getRawFlags()
  48213. && (textCharacter == other.textCharacter
  48214. || textCharacter == 0
  48215. || other.textCharacter == 0)
  48216. && (keyCode == other.keyCode
  48217. || (keyCode < 256
  48218. && other.keyCode < 256
  48219. && CharacterFunctions::toLowerCase ((tchar) keyCode)
  48220. == CharacterFunctions::toLowerCase ((tchar) other.keyCode)));
  48221. }
  48222. bool KeyPress::operator!= (const KeyPress& other) const throw()
  48223. {
  48224. return ! operator== (other);
  48225. }
  48226. bool KeyPress::isCurrentlyDown() const throw()
  48227. {
  48228. return isKeyCurrentlyDown (keyCode)
  48229. && (ModifierKeys::getCurrentModifiers().getRawFlags() & ModifierKeys::allKeyboardModifiers)
  48230. == (mods.getRawFlags() & ModifierKeys::allKeyboardModifiers);
  48231. }
  48232. struct KeyNameAndCode
  48233. {
  48234. const char* name;
  48235. int code;
  48236. };
  48237. static const KeyNameAndCode keyNameTranslations[] =
  48238. {
  48239. { "spacebar", KeyPress::spaceKey },
  48240. { "return", KeyPress::returnKey },
  48241. { "escape", KeyPress::escapeKey },
  48242. { "backspace", KeyPress::backspaceKey },
  48243. { "cursor left", KeyPress::leftKey },
  48244. { "cursor right", KeyPress::rightKey },
  48245. { "cursor up", KeyPress::upKey },
  48246. { "cursor down", KeyPress::downKey },
  48247. { "page up", KeyPress::pageUpKey },
  48248. { "page down", KeyPress::pageDownKey },
  48249. { "home", KeyPress::homeKey },
  48250. { "end", KeyPress::endKey },
  48251. { "delete", KeyPress::deleteKey },
  48252. { "insert", KeyPress::insertKey },
  48253. { "tab", KeyPress::tabKey },
  48254. { "play", KeyPress::playKey },
  48255. { "stop", KeyPress::stopKey },
  48256. { "fast forward", KeyPress::fastForwardKey },
  48257. { "rewind", KeyPress::rewindKey }
  48258. };
  48259. static const tchar* const numberPadPrefix = T("numpad ");
  48260. const KeyPress KeyPress::createFromDescription (const String& desc) throw()
  48261. {
  48262. int modifiers = 0;
  48263. if (desc.containsWholeWordIgnoreCase (T("ctrl"))
  48264. || desc.containsWholeWordIgnoreCase (T("control"))
  48265. || desc.containsWholeWordIgnoreCase (T("ctl")))
  48266. modifiers |= ModifierKeys::ctrlModifier;
  48267. if (desc.containsWholeWordIgnoreCase (T("shift"))
  48268. || desc.containsWholeWordIgnoreCase (T("shft")))
  48269. modifiers |= ModifierKeys::shiftModifier;
  48270. if (desc.containsWholeWordIgnoreCase (T("alt"))
  48271. || desc.containsWholeWordIgnoreCase (T("option")))
  48272. modifiers |= ModifierKeys::altModifier;
  48273. if (desc.containsWholeWordIgnoreCase (T("command"))
  48274. || desc.containsWholeWordIgnoreCase (T("cmd")))
  48275. modifiers |= ModifierKeys::commandModifier;
  48276. int key = 0;
  48277. for (int i = 0; i < numElementsInArray (keyNameTranslations); ++i)
  48278. {
  48279. if (desc.containsWholeWordIgnoreCase (String (keyNameTranslations[i].name)))
  48280. {
  48281. key = keyNameTranslations[i].code;
  48282. break;
  48283. }
  48284. }
  48285. if (key == 0)
  48286. {
  48287. // see if it's a numpad key..
  48288. if (desc.containsIgnoreCase (numberPadPrefix))
  48289. {
  48290. const tchar lastChar = desc.trimEnd().getLastCharacter();
  48291. if (lastChar >= T('0') && lastChar <= T('9'))
  48292. key = numberPad0 + lastChar - T('0');
  48293. else if (lastChar == T('+'))
  48294. key = numberPadAdd;
  48295. else if (lastChar == T('-'))
  48296. key = numberPadSubtract;
  48297. else if (lastChar == T('*'))
  48298. key = numberPadMultiply;
  48299. else if (lastChar == T('/'))
  48300. key = numberPadDivide;
  48301. else if (lastChar == T('.'))
  48302. key = numberPadDecimalPoint;
  48303. else if (lastChar == T('='))
  48304. key = numberPadEquals;
  48305. else if (desc.endsWith (T("separator")))
  48306. key = numberPadSeparator;
  48307. else if (desc.endsWith (T("delete")))
  48308. key = numberPadDelete;
  48309. }
  48310. if (key == 0)
  48311. {
  48312. // see if it's a function key..
  48313. for (int i = 1; i <= 12; ++i)
  48314. if (desc.containsWholeWordIgnoreCase (T("f") + String (i)))
  48315. key = F1Key + i - 1;
  48316. if (key == 0)
  48317. {
  48318. // give up and use the hex code..
  48319. const int hexCode = desc.fromFirstOccurrenceOf (T("#"), false, false)
  48320. .toLowerCase()
  48321. .retainCharacters (T("0123456789abcdef"))
  48322. .getHexValue32();
  48323. if (hexCode > 0)
  48324. key = hexCode;
  48325. else
  48326. key = CharacterFunctions::toUpperCase (desc.getLastCharacter());
  48327. }
  48328. }
  48329. }
  48330. return KeyPress (key, ModifierKeys (modifiers), 0);
  48331. }
  48332. const String KeyPress::getTextDescription() const throw()
  48333. {
  48334. String desc;
  48335. if (keyCode > 0)
  48336. {
  48337. // some keyboard layouts use a shift-key to get the slash, but in those cases, we
  48338. // want to store it as being a slash, not shift+whatever.
  48339. if (textCharacter == T('/'))
  48340. return "/";
  48341. if (mods.isCtrlDown())
  48342. desc << "ctrl + ";
  48343. if (mods.isShiftDown())
  48344. desc << "shift + ";
  48345. #if JUCE_MAC
  48346. // only do this on the mac, because on Windows ctrl and command are the same,
  48347. // and this would get confusing
  48348. if (mods.isCommandDown())
  48349. desc << "command + ";
  48350. if (mods.isAltDown())
  48351. desc << "option + ";
  48352. #else
  48353. if (mods.isAltDown())
  48354. desc << "alt + ";
  48355. #endif
  48356. for (int i = 0; i < numElementsInArray (keyNameTranslations); ++i)
  48357. if (keyCode == keyNameTranslations[i].code)
  48358. return desc + keyNameTranslations[i].name;
  48359. if (keyCode >= F1Key && keyCode <= F16Key)
  48360. desc << 'F' << (1 + keyCode - F1Key);
  48361. else if (keyCode >= numberPad0 && keyCode <= numberPad9)
  48362. desc << numberPadPrefix << (keyCode - numberPad0);
  48363. else if (keyCode >= 33 && keyCode < 176)
  48364. desc += CharacterFunctions::toUpperCase ((tchar) keyCode);
  48365. else if (keyCode == numberPadAdd)
  48366. desc << numberPadPrefix << '+';
  48367. else if (keyCode == numberPadSubtract)
  48368. desc << numberPadPrefix << '-';
  48369. else if (keyCode == numberPadMultiply)
  48370. desc << numberPadPrefix << '*';
  48371. else if (keyCode == numberPadDivide)
  48372. desc << numberPadPrefix << '/';
  48373. else if (keyCode == numberPadSeparator)
  48374. desc << numberPadPrefix << "separator";
  48375. else if (keyCode == numberPadDecimalPoint)
  48376. desc << numberPadPrefix << '.';
  48377. else if (keyCode == numberPadDelete)
  48378. desc << numberPadPrefix << "delete";
  48379. else
  48380. desc << '#' << String::toHexString (keyCode);
  48381. }
  48382. return desc;
  48383. }
  48384. END_JUCE_NAMESPACE
  48385. /********* End of inlined file: juce_KeyPress.cpp *********/
  48386. /********* Start of inlined file: juce_KeyPressMappingSet.cpp *********/
  48387. BEGIN_JUCE_NAMESPACE
  48388. KeyPressMappingSet::KeyPressMappingSet (ApplicationCommandManager* const commandManager_) throw()
  48389. : commandManager (commandManager_)
  48390. {
  48391. // A manager is needed to get the descriptions of commands, and will be called when
  48392. // a command is invoked. So you can't leave this null..
  48393. jassert (commandManager_ != 0);
  48394. Desktop::getInstance().addFocusChangeListener (this);
  48395. }
  48396. KeyPressMappingSet::KeyPressMappingSet (const KeyPressMappingSet& other) throw()
  48397. : commandManager (other.commandManager)
  48398. {
  48399. Desktop::getInstance().addFocusChangeListener (this);
  48400. }
  48401. KeyPressMappingSet::~KeyPressMappingSet()
  48402. {
  48403. Desktop::getInstance().removeFocusChangeListener (this);
  48404. }
  48405. const Array <KeyPress> KeyPressMappingSet::getKeyPressesAssignedToCommand (const CommandID commandID) const throw()
  48406. {
  48407. for (int i = 0; i < mappings.size(); ++i)
  48408. if (mappings.getUnchecked(i)->commandID == commandID)
  48409. return mappings.getUnchecked (i)->keypresses;
  48410. return Array <KeyPress> ();
  48411. }
  48412. void KeyPressMappingSet::addKeyPress (const CommandID commandID,
  48413. const KeyPress& newKeyPress,
  48414. int insertIndex) throw()
  48415. {
  48416. // If you specify an upper-case letter but no shift key, how is the user supposed to press it!?
  48417. // Stick to lower-case letters when defining a keypress, to avoid ambiguity.
  48418. jassert (! (CharacterFunctions::isUpperCase (newKeyPress.getTextCharacter())
  48419. && ! newKeyPress.getModifiers().isShiftDown()));
  48420. if (findCommandForKeyPress (newKeyPress) != commandID)
  48421. {
  48422. removeKeyPress (newKeyPress);
  48423. if (newKeyPress.isValid())
  48424. {
  48425. for (int i = mappings.size(); --i >= 0;)
  48426. {
  48427. if (mappings.getUnchecked(i)->commandID == commandID)
  48428. {
  48429. mappings.getUnchecked(i)->keypresses.insert (insertIndex, newKeyPress);
  48430. sendChangeMessage (this);
  48431. return;
  48432. }
  48433. }
  48434. const ApplicationCommandInfo* const ci = commandManager->getCommandForID (commandID);
  48435. if (ci != 0)
  48436. {
  48437. CommandMapping* const cm = new CommandMapping();
  48438. cm->commandID = commandID;
  48439. cm->keypresses.add (newKeyPress);
  48440. cm->wantsKeyUpDownCallbacks = (ci->flags & ApplicationCommandInfo::wantsKeyUpDownCallbacks) != 0;
  48441. mappings.add (cm);
  48442. sendChangeMessage (this);
  48443. }
  48444. }
  48445. }
  48446. }
  48447. void KeyPressMappingSet::resetToDefaultMappings() throw()
  48448. {
  48449. mappings.clear();
  48450. for (int i = 0; i < commandManager->getNumCommands(); ++i)
  48451. {
  48452. const ApplicationCommandInfo* const ci = commandManager->getCommandForIndex (i);
  48453. for (int j = 0; j < ci->defaultKeypresses.size(); ++j)
  48454. {
  48455. addKeyPress (ci->commandID,
  48456. ci->defaultKeypresses.getReference (j));
  48457. }
  48458. }
  48459. sendChangeMessage (this);
  48460. }
  48461. void KeyPressMappingSet::resetToDefaultMapping (const CommandID commandID) throw()
  48462. {
  48463. clearAllKeyPresses (commandID);
  48464. const ApplicationCommandInfo* const ci = commandManager->getCommandForID (commandID);
  48465. for (int j = 0; j < ci->defaultKeypresses.size(); ++j)
  48466. {
  48467. addKeyPress (ci->commandID,
  48468. ci->defaultKeypresses.getReference (j));
  48469. }
  48470. }
  48471. void KeyPressMappingSet::clearAllKeyPresses() throw()
  48472. {
  48473. if (mappings.size() > 0)
  48474. {
  48475. sendChangeMessage (this);
  48476. mappings.clear();
  48477. }
  48478. }
  48479. void KeyPressMappingSet::clearAllKeyPresses (const CommandID commandID) throw()
  48480. {
  48481. for (int i = mappings.size(); --i >= 0;)
  48482. {
  48483. if (mappings.getUnchecked(i)->commandID == commandID)
  48484. {
  48485. mappings.remove (i);
  48486. sendChangeMessage (this);
  48487. }
  48488. }
  48489. }
  48490. void KeyPressMappingSet::removeKeyPress (const KeyPress& keypress) throw()
  48491. {
  48492. if (keypress.isValid())
  48493. {
  48494. for (int i = mappings.size(); --i >= 0;)
  48495. {
  48496. CommandMapping* const cm = mappings.getUnchecked(i);
  48497. for (int j = cm->keypresses.size(); --j >= 0;)
  48498. {
  48499. if (keypress == cm->keypresses [j])
  48500. {
  48501. cm->keypresses.remove (j);
  48502. sendChangeMessage (this);
  48503. }
  48504. }
  48505. }
  48506. }
  48507. }
  48508. void KeyPressMappingSet::removeKeyPress (const CommandID commandID,
  48509. const int keyPressIndex) throw()
  48510. {
  48511. for (int i = mappings.size(); --i >= 0;)
  48512. {
  48513. if (mappings.getUnchecked(i)->commandID == commandID)
  48514. {
  48515. mappings.getUnchecked(i)->keypresses.remove (keyPressIndex);
  48516. sendChangeMessage (this);
  48517. break;
  48518. }
  48519. }
  48520. }
  48521. CommandID KeyPressMappingSet::findCommandForKeyPress (const KeyPress& keyPress) const throw()
  48522. {
  48523. for (int i = 0; i < mappings.size(); ++i)
  48524. if (mappings.getUnchecked(i)->keypresses.contains (keyPress))
  48525. return mappings.getUnchecked(i)->commandID;
  48526. return 0;
  48527. }
  48528. bool KeyPressMappingSet::containsMapping (const CommandID commandID,
  48529. const KeyPress& keyPress) const throw()
  48530. {
  48531. for (int i = mappings.size(); --i >= 0;)
  48532. if (mappings.getUnchecked(i)->commandID == commandID)
  48533. return mappings.getUnchecked(i)->keypresses.contains (keyPress);
  48534. return false;
  48535. }
  48536. void KeyPressMappingSet::invokeCommand (const CommandID commandID,
  48537. const KeyPress& key,
  48538. const bool isKeyDown,
  48539. const int millisecsSinceKeyPressed,
  48540. Component* const originatingComponent) const
  48541. {
  48542. ApplicationCommandTarget::InvocationInfo info (commandID);
  48543. info.invocationMethod = ApplicationCommandTarget::InvocationInfo::fromKeyPress;
  48544. info.isKeyDown = isKeyDown;
  48545. info.keyPress = key;
  48546. info.millisecsSinceKeyPressed = millisecsSinceKeyPressed;
  48547. info.originatingComponent = originatingComponent;
  48548. commandManager->invoke (info, false);
  48549. }
  48550. bool KeyPressMappingSet::restoreFromXml (const XmlElement& xmlVersion)
  48551. {
  48552. if (xmlVersion.hasTagName (T("KEYMAPPINGS")))
  48553. {
  48554. if (xmlVersion.getBoolAttribute (T("basedOnDefaults"), true))
  48555. {
  48556. // if the XML was created as a set of differences from the default mappings,
  48557. // (i.e. by calling createXml (true)), then we need to first restore the defaults.
  48558. resetToDefaultMappings();
  48559. }
  48560. else
  48561. {
  48562. // if the XML was created calling createXml (false), then we need to clear all
  48563. // the keys and treat the xml as describing the entire set of mappings.
  48564. clearAllKeyPresses();
  48565. }
  48566. forEachXmlChildElement (xmlVersion, map)
  48567. {
  48568. const CommandID commandId = map->getStringAttribute (T("commandId")).getHexValue32();
  48569. if (commandId != 0)
  48570. {
  48571. const KeyPress key (KeyPress::createFromDescription (map->getStringAttribute (T("key"))));
  48572. if (map->hasTagName (T("MAPPING")))
  48573. {
  48574. addKeyPress (commandId, key);
  48575. }
  48576. else if (map->hasTagName (T("UNMAPPING")))
  48577. {
  48578. if (containsMapping (commandId, key))
  48579. removeKeyPress (key);
  48580. }
  48581. }
  48582. }
  48583. return true;
  48584. }
  48585. return false;
  48586. }
  48587. XmlElement* KeyPressMappingSet::createXml (const bool saveDifferencesFromDefaultSet) const
  48588. {
  48589. ScopedPointer <KeyPressMappingSet> defaultSet;
  48590. if (saveDifferencesFromDefaultSet)
  48591. {
  48592. defaultSet = new KeyPressMappingSet (commandManager);
  48593. defaultSet->resetToDefaultMappings();
  48594. }
  48595. XmlElement* const doc = new XmlElement (T("KEYMAPPINGS"));
  48596. doc->setAttribute (T("basedOnDefaults"), saveDifferencesFromDefaultSet);
  48597. int i;
  48598. for (i = 0; i < mappings.size(); ++i)
  48599. {
  48600. const CommandMapping* const cm = mappings.getUnchecked(i);
  48601. for (int j = 0; j < cm->keypresses.size(); ++j)
  48602. {
  48603. if (defaultSet == 0
  48604. || ! defaultSet->containsMapping (cm->commandID, cm->keypresses.getReference (j)))
  48605. {
  48606. XmlElement* const map = new XmlElement (T("MAPPING"));
  48607. map->setAttribute (T("commandId"), String::toHexString ((int) cm->commandID));
  48608. map->setAttribute (T("description"), commandManager->getDescriptionOfCommand (cm->commandID));
  48609. map->setAttribute (T("key"), cm->keypresses.getReference (j).getTextDescription());
  48610. doc->addChildElement (map);
  48611. }
  48612. }
  48613. }
  48614. if (defaultSet != 0)
  48615. {
  48616. for (i = 0; i < defaultSet->mappings.size(); ++i)
  48617. {
  48618. const CommandMapping* const cm = defaultSet->mappings.getUnchecked(i);
  48619. for (int j = 0; j < cm->keypresses.size(); ++j)
  48620. {
  48621. if (! containsMapping (cm->commandID, cm->keypresses.getReference (j)))
  48622. {
  48623. XmlElement* const map = new XmlElement (T("UNMAPPING"));
  48624. map->setAttribute (T("commandId"), String::toHexString ((int) cm->commandID));
  48625. map->setAttribute (T("description"), commandManager->getDescriptionOfCommand (cm->commandID));
  48626. map->setAttribute (T("key"), cm->keypresses.getReference (j).getTextDescription());
  48627. doc->addChildElement (map);
  48628. }
  48629. }
  48630. }
  48631. }
  48632. return doc;
  48633. }
  48634. bool KeyPressMappingSet::keyPressed (const KeyPress& key,
  48635. Component* originatingComponent)
  48636. {
  48637. bool used = false;
  48638. const CommandID commandID = findCommandForKeyPress (key);
  48639. const ApplicationCommandInfo* const ci = commandManager->getCommandForID (commandID);
  48640. if (ci != 0
  48641. && (ci->flags & ApplicationCommandInfo::wantsKeyUpDownCallbacks) == 0)
  48642. {
  48643. ApplicationCommandInfo info (0);
  48644. if (commandManager->getTargetForCommand (commandID, info) != 0
  48645. && (info.flags & ApplicationCommandInfo::isDisabled) == 0)
  48646. {
  48647. invokeCommand (commandID, key, true, 0, originatingComponent);
  48648. used = true;
  48649. }
  48650. else
  48651. {
  48652. if (originatingComponent != 0)
  48653. originatingComponent->getLookAndFeel().playAlertSound();
  48654. }
  48655. }
  48656. return used;
  48657. }
  48658. bool KeyPressMappingSet::keyStateChanged (const bool /*isKeyDown*/, Component* originatingComponent)
  48659. {
  48660. bool used = false;
  48661. const uint32 now = Time::getMillisecondCounter();
  48662. for (int i = mappings.size(); --i >= 0;)
  48663. {
  48664. CommandMapping* const cm = mappings.getUnchecked(i);
  48665. if (cm->wantsKeyUpDownCallbacks)
  48666. {
  48667. for (int j = cm->keypresses.size(); --j >= 0;)
  48668. {
  48669. const KeyPress key (cm->keypresses.getReference (j));
  48670. const bool isDown = key.isCurrentlyDown();
  48671. int keyPressEntryIndex = 0;
  48672. bool wasDown = false;
  48673. for (int k = keysDown.size(); --k >= 0;)
  48674. {
  48675. if (key == keysDown.getUnchecked(k)->key)
  48676. {
  48677. keyPressEntryIndex = k;
  48678. wasDown = true;
  48679. used = true;
  48680. break;
  48681. }
  48682. }
  48683. if (isDown != wasDown)
  48684. {
  48685. int millisecs = 0;
  48686. if (isDown)
  48687. {
  48688. KeyPressTime* const k = new KeyPressTime();
  48689. k->key = key;
  48690. k->timeWhenPressed = now;
  48691. keysDown.add (k);
  48692. }
  48693. else
  48694. {
  48695. const uint32 pressTime = keysDown.getUnchecked (keyPressEntryIndex)->timeWhenPressed;
  48696. if (now > pressTime)
  48697. millisecs = now - pressTime;
  48698. keysDown.remove (keyPressEntryIndex);
  48699. }
  48700. invokeCommand (cm->commandID, key, isDown, millisecs, originatingComponent);
  48701. used = true;
  48702. }
  48703. }
  48704. }
  48705. }
  48706. return used;
  48707. }
  48708. void KeyPressMappingSet::globalFocusChanged (Component* focusedComponent)
  48709. {
  48710. if (focusedComponent != 0)
  48711. focusedComponent->keyStateChanged (false);
  48712. }
  48713. END_JUCE_NAMESPACE
  48714. /********* End of inlined file: juce_KeyPressMappingSet.cpp *********/
  48715. /********* Start of inlined file: juce_ModifierKeys.cpp *********/
  48716. BEGIN_JUCE_NAMESPACE
  48717. ModifierKeys::ModifierKeys (const int flags_) throw()
  48718. : flags (flags_)
  48719. {
  48720. }
  48721. ModifierKeys::ModifierKeys (const ModifierKeys& other) throw()
  48722. : flags (other.flags)
  48723. {
  48724. }
  48725. const ModifierKeys& ModifierKeys::operator= (const ModifierKeys& other) throw()
  48726. {
  48727. flags = other.flags;
  48728. return *this;
  48729. }
  48730. int ModifierKeys::currentModifierFlags = 0;
  48731. const ModifierKeys ModifierKeys::getCurrentModifiers() throw()
  48732. {
  48733. return ModifierKeys (currentModifierFlags);
  48734. }
  48735. END_JUCE_NAMESPACE
  48736. /********* End of inlined file: juce_ModifierKeys.cpp *********/
  48737. /********* Start of inlined file: juce_ComponentAnimator.cpp *********/
  48738. BEGIN_JUCE_NAMESPACE
  48739. struct AnimationTask
  48740. {
  48741. AnimationTask (Component* const comp)
  48742. : component (comp),
  48743. watcher (comp)
  48744. {
  48745. }
  48746. Component* component;
  48747. ComponentDeletionWatcher watcher;
  48748. Rectangle destination;
  48749. int msElapsed, msTotal;
  48750. double startSpeed, midSpeed, endSpeed, lastProgress;
  48751. double left, top, right, bottom;
  48752. bool useTimeslice (const int elapsed)
  48753. {
  48754. if (watcher.hasBeenDeleted())
  48755. return false;
  48756. msElapsed += elapsed;
  48757. double newProgress = msElapsed / (double) msTotal;
  48758. if (newProgress >= 0 && newProgress < 1.0)
  48759. {
  48760. newProgress = timeToDistance (newProgress);
  48761. const double delta = (newProgress - lastProgress) / (1.0 - lastProgress);
  48762. jassert (newProgress >= lastProgress);
  48763. lastProgress = newProgress;
  48764. left += (destination.getX() - left) * delta;
  48765. top += (destination.getY() - top) * delta;
  48766. right += (destination.getRight() - right) * delta;
  48767. bottom += (destination.getBottom() - bottom) * delta;
  48768. if (delta < 1.0)
  48769. {
  48770. const Rectangle newBounds (roundToInt (left),
  48771. roundToInt (top),
  48772. roundToInt (right - left),
  48773. roundToInt (bottom - top));
  48774. if (newBounds != destination)
  48775. {
  48776. component->setBounds (newBounds);
  48777. return true;
  48778. }
  48779. }
  48780. }
  48781. component->setBounds (destination);
  48782. return false;
  48783. }
  48784. void moveToFinalDestination()
  48785. {
  48786. if (! watcher.hasBeenDeleted())
  48787. component->setBounds (destination);
  48788. }
  48789. private:
  48790. inline double timeToDistance (const double time) const
  48791. {
  48792. return (time < 0.5) ? time * (startSpeed + time * (midSpeed - startSpeed))
  48793. : 0.5 * (startSpeed + 0.5 * (midSpeed - startSpeed))
  48794. + (time - 0.5) * (midSpeed + (time - 0.5) * (endSpeed - midSpeed));
  48795. }
  48796. };
  48797. ComponentAnimator::ComponentAnimator()
  48798. : lastTime (0)
  48799. {
  48800. }
  48801. ComponentAnimator::~ComponentAnimator()
  48802. {
  48803. cancelAllAnimations (false);
  48804. jassert (tasks.size() == 0);
  48805. }
  48806. void* ComponentAnimator::findTaskFor (Component* const component) const
  48807. {
  48808. for (int i = tasks.size(); --i >= 0;)
  48809. if (component == ((AnimationTask*) tasks.getUnchecked(i))->component)
  48810. return tasks.getUnchecked(i);
  48811. return 0;
  48812. }
  48813. void ComponentAnimator::animateComponent (Component* const component,
  48814. const Rectangle& finalPosition,
  48815. const int millisecondsToSpendMoving,
  48816. const double startSpeed,
  48817. const double endSpeed)
  48818. {
  48819. if (component != 0)
  48820. {
  48821. AnimationTask* at = (AnimationTask*) findTaskFor (component);
  48822. if (at == 0)
  48823. {
  48824. at = new AnimationTask (component);
  48825. tasks.add (at);
  48826. sendChangeMessage (this);
  48827. }
  48828. at->msElapsed = 0;
  48829. at->lastProgress = 0;
  48830. at->msTotal = jmax (1, millisecondsToSpendMoving);
  48831. at->destination = finalPosition;
  48832. // the speeds must be 0 or greater!
  48833. jassert (startSpeed >= 0 && endSpeed >= 0)
  48834. const double invTotalDistance = 4.0 / (startSpeed + endSpeed + 2.0);
  48835. at->startSpeed = jmax (0.0, startSpeed * invTotalDistance);
  48836. at->midSpeed = invTotalDistance;
  48837. at->endSpeed = jmax (0.0, endSpeed * invTotalDistance);
  48838. at->left = component->getX();
  48839. at->top = component->getY();
  48840. at->right = component->getRight();
  48841. at->bottom = component->getBottom();
  48842. if (! isTimerRunning())
  48843. {
  48844. lastTime = Time::getMillisecondCounter();
  48845. startTimer (1000 / 50);
  48846. }
  48847. }
  48848. }
  48849. void ComponentAnimator::cancelAllAnimations (const bool moveComponentsToTheirFinalPositions)
  48850. {
  48851. for (int i = tasks.size(); --i >= 0;)
  48852. {
  48853. AnimationTask* const at = (AnimationTask*) tasks.getUnchecked(i);
  48854. if (moveComponentsToTheirFinalPositions)
  48855. at->moveToFinalDestination();
  48856. delete at;
  48857. tasks.remove (i);
  48858. sendChangeMessage (this);
  48859. }
  48860. }
  48861. void ComponentAnimator::cancelAnimation (Component* const component,
  48862. const bool moveComponentToItsFinalPosition)
  48863. {
  48864. AnimationTask* const at = (AnimationTask*) findTaskFor (component);
  48865. if (at != 0)
  48866. {
  48867. if (moveComponentToItsFinalPosition)
  48868. at->moveToFinalDestination();
  48869. tasks.removeValue (at);
  48870. delete at;
  48871. sendChangeMessage (this);
  48872. }
  48873. }
  48874. const Rectangle ComponentAnimator::getComponentDestination (Component* const component)
  48875. {
  48876. AnimationTask* const at = (AnimationTask*) findTaskFor (component);
  48877. if (at != 0)
  48878. return at->destination;
  48879. else if (component != 0)
  48880. return component->getBounds();
  48881. return Rectangle();
  48882. }
  48883. bool ComponentAnimator::isAnimating (Component* component) const
  48884. {
  48885. return findTaskFor (component) != 0;
  48886. }
  48887. void ComponentAnimator::timerCallback()
  48888. {
  48889. const uint32 timeNow = Time::getMillisecondCounter();
  48890. if (lastTime == 0 || lastTime == timeNow)
  48891. lastTime = timeNow;
  48892. const int elapsed = timeNow - lastTime;
  48893. for (int i = tasks.size(); --i >= 0;)
  48894. {
  48895. AnimationTask* const at = (AnimationTask*) tasks.getUnchecked(i);
  48896. if (! at->useTimeslice (elapsed))
  48897. {
  48898. tasks.remove (i);
  48899. delete at;
  48900. sendChangeMessage (this);
  48901. }
  48902. }
  48903. lastTime = timeNow;
  48904. if (tasks.size() == 0)
  48905. stopTimer();
  48906. }
  48907. END_JUCE_NAMESPACE
  48908. /********* End of inlined file: juce_ComponentAnimator.cpp *********/
  48909. /********* Start of inlined file: juce_ComponentBoundsConstrainer.cpp *********/
  48910. BEGIN_JUCE_NAMESPACE
  48911. ComponentBoundsConstrainer::ComponentBoundsConstrainer() throw()
  48912. : minW (0),
  48913. maxW (0x3fffffff),
  48914. minH (0),
  48915. maxH (0x3fffffff),
  48916. minOffTop (0),
  48917. minOffLeft (0),
  48918. minOffBottom (0),
  48919. minOffRight (0),
  48920. aspectRatio (0.0)
  48921. {
  48922. }
  48923. ComponentBoundsConstrainer::~ComponentBoundsConstrainer()
  48924. {
  48925. }
  48926. void ComponentBoundsConstrainer::setMinimumWidth (const int minimumWidth) throw()
  48927. {
  48928. minW = minimumWidth;
  48929. }
  48930. void ComponentBoundsConstrainer::setMaximumWidth (const int maximumWidth) throw()
  48931. {
  48932. maxW = maximumWidth;
  48933. }
  48934. void ComponentBoundsConstrainer::setMinimumHeight (const int minimumHeight) throw()
  48935. {
  48936. minH = minimumHeight;
  48937. }
  48938. void ComponentBoundsConstrainer::setMaximumHeight (const int maximumHeight) throw()
  48939. {
  48940. maxH = maximumHeight;
  48941. }
  48942. void ComponentBoundsConstrainer::setMinimumSize (const int minimumWidth, const int minimumHeight) throw()
  48943. {
  48944. jassert (maxW >= minimumWidth);
  48945. jassert (maxH >= minimumHeight);
  48946. jassert (minimumWidth > 0 && minimumHeight > 0);
  48947. minW = minimumWidth;
  48948. minH = minimumHeight;
  48949. if (minW > maxW)
  48950. maxW = minW;
  48951. if (minH > maxH)
  48952. maxH = minH;
  48953. }
  48954. void ComponentBoundsConstrainer::setMaximumSize (const int maximumWidth, const int maximumHeight) throw()
  48955. {
  48956. jassert (maximumWidth >= minW);
  48957. jassert (maximumHeight >= minH);
  48958. jassert (maximumWidth > 0 && maximumHeight > 0);
  48959. maxW = jmax (minW, maximumWidth);
  48960. maxH = jmax (minH, maximumHeight);
  48961. }
  48962. void ComponentBoundsConstrainer::setSizeLimits (const int minimumWidth,
  48963. const int minimumHeight,
  48964. const int maximumWidth,
  48965. const int maximumHeight) throw()
  48966. {
  48967. jassert (maximumWidth >= minimumWidth);
  48968. jassert (maximumHeight >= minimumHeight);
  48969. jassert (maximumWidth > 0 && maximumHeight > 0);
  48970. jassert (minimumWidth > 0 && minimumHeight > 0);
  48971. minW = jmax (0, minimumWidth);
  48972. minH = jmax (0, minimumHeight);
  48973. maxW = jmax (minW, maximumWidth);
  48974. maxH = jmax (minH, maximumHeight);
  48975. }
  48976. void ComponentBoundsConstrainer::setMinimumOnscreenAmounts (const int minimumWhenOffTheTop,
  48977. const int minimumWhenOffTheLeft,
  48978. const int minimumWhenOffTheBottom,
  48979. const int minimumWhenOffTheRight) throw()
  48980. {
  48981. minOffTop = minimumWhenOffTheTop;
  48982. minOffLeft = minimumWhenOffTheLeft;
  48983. minOffBottom = minimumWhenOffTheBottom;
  48984. minOffRight = minimumWhenOffTheRight;
  48985. }
  48986. void ComponentBoundsConstrainer::setFixedAspectRatio (const double widthOverHeight) throw()
  48987. {
  48988. aspectRatio = jmax (0.0, widthOverHeight);
  48989. }
  48990. double ComponentBoundsConstrainer::getFixedAspectRatio() const throw()
  48991. {
  48992. return aspectRatio;
  48993. }
  48994. void ComponentBoundsConstrainer::setBoundsForComponent (Component* const component,
  48995. int x, int y, int w, int h,
  48996. const bool isStretchingTop,
  48997. const bool isStretchingLeft,
  48998. const bool isStretchingBottom,
  48999. const bool isStretchingRight)
  49000. {
  49001. jassert (component != 0);
  49002. Rectangle limits;
  49003. Component* const p = component->getParentComponent();
  49004. if (p == 0)
  49005. limits = Desktop::getInstance().getAllMonitorDisplayAreas().getBounds();
  49006. else
  49007. limits.setSize (p->getWidth(), p->getHeight());
  49008. if (component->isOnDesktop())
  49009. {
  49010. ComponentPeer* const peer = component->getPeer();
  49011. const BorderSize border (peer->getFrameSize());
  49012. x -= border.getLeft();
  49013. y -= border.getTop();
  49014. w += border.getLeftAndRight();
  49015. h += border.getTopAndBottom();
  49016. checkBounds (x, y, w, h,
  49017. border.addedTo (component->getBounds()), limits,
  49018. isStretchingTop, isStretchingLeft,
  49019. isStretchingBottom, isStretchingRight);
  49020. x += border.getLeft();
  49021. y += border.getTop();
  49022. w -= border.getLeftAndRight();
  49023. h -= border.getTopAndBottom();
  49024. }
  49025. else
  49026. {
  49027. checkBounds (x, y, w, h,
  49028. component->getBounds(), limits,
  49029. isStretchingTop, isStretchingLeft,
  49030. isStretchingBottom, isStretchingRight);
  49031. }
  49032. applyBoundsToComponent (component, x, y, w, h);
  49033. }
  49034. void ComponentBoundsConstrainer::checkComponentBounds (Component* component)
  49035. {
  49036. setBoundsForComponent (component,
  49037. component->getX(), component->getY(),
  49038. component->getWidth(), component->getHeight(),
  49039. false, false, false, false);
  49040. }
  49041. void ComponentBoundsConstrainer::applyBoundsToComponent (Component* component,
  49042. int x, int y, int w, int h)
  49043. {
  49044. component->setBounds (x, y, w, h);
  49045. }
  49046. void ComponentBoundsConstrainer::resizeStart()
  49047. {
  49048. }
  49049. void ComponentBoundsConstrainer::resizeEnd()
  49050. {
  49051. }
  49052. void ComponentBoundsConstrainer::checkBounds (int& x, int& y, int& w, int& h,
  49053. const Rectangle& old,
  49054. const Rectangle& limits,
  49055. const bool isStretchingTop,
  49056. const bool isStretchingLeft,
  49057. const bool isStretchingBottom,
  49058. const bool isStretchingRight)
  49059. {
  49060. // constrain the size if it's being stretched..
  49061. if (isStretchingLeft)
  49062. {
  49063. x = jlimit (old.getRight() - maxW, old.getRight() - minW, x);
  49064. w = old.getRight() - x;
  49065. }
  49066. if (isStretchingRight)
  49067. {
  49068. w = jlimit (minW, maxW, w);
  49069. }
  49070. if (isStretchingTop)
  49071. {
  49072. y = jlimit (old.getBottom() - maxH, old.getBottom() - minH, y);
  49073. h = old.getBottom() - y;
  49074. }
  49075. if (isStretchingBottom)
  49076. {
  49077. h = jlimit (minH, maxH, h);
  49078. }
  49079. // constrain the aspect ratio if one has been specified..
  49080. if (aspectRatio > 0.0 && w > 0 && h > 0)
  49081. {
  49082. bool adjustWidth;
  49083. if ((isStretchingTop || isStretchingBottom) && ! (isStretchingLeft || isStretchingRight))
  49084. {
  49085. adjustWidth = true;
  49086. }
  49087. else if ((isStretchingLeft || isStretchingRight) && ! (isStretchingTop || isStretchingBottom))
  49088. {
  49089. adjustWidth = false;
  49090. }
  49091. else
  49092. {
  49093. const double oldRatio = (old.getHeight() > 0) ? fabs (old.getWidth() / (double) old.getHeight()) : 0.0;
  49094. const double newRatio = fabs (w / (double) h);
  49095. adjustWidth = (oldRatio > newRatio);
  49096. }
  49097. if (adjustWidth)
  49098. {
  49099. w = roundToInt (h * aspectRatio);
  49100. if (w > maxW || w < minW)
  49101. {
  49102. w = jlimit (minW, maxW, w);
  49103. h = roundToInt (w / aspectRatio);
  49104. }
  49105. }
  49106. else
  49107. {
  49108. h = roundToInt (w / aspectRatio);
  49109. if (h > maxH || h < minH)
  49110. {
  49111. h = jlimit (minH, maxH, h);
  49112. w = roundToInt (h * aspectRatio);
  49113. }
  49114. }
  49115. if ((isStretchingTop || isStretchingBottom) && ! (isStretchingLeft || isStretchingRight))
  49116. {
  49117. x = old.getX() + (old.getWidth() - w) / 2;
  49118. }
  49119. else if ((isStretchingLeft || isStretchingRight) && ! (isStretchingTop || isStretchingBottom))
  49120. {
  49121. y = old.getY() + (old.getHeight() - h) / 2;
  49122. }
  49123. else
  49124. {
  49125. if (isStretchingLeft)
  49126. x = old.getRight() - w;
  49127. if (isStretchingTop)
  49128. y = old.getBottom() - h;
  49129. }
  49130. }
  49131. // ...and constrain the position if limits have been set for that.
  49132. if (minOffTop > 0 || minOffLeft > 0 || minOffBottom > 0 || minOffRight > 0)
  49133. {
  49134. if (minOffTop > 0)
  49135. {
  49136. const int limit = limits.getY() + jmin (minOffTop - h, 0);
  49137. if (y < limit)
  49138. {
  49139. if (isStretchingTop)
  49140. h -= (limit - y);
  49141. y = limit;
  49142. }
  49143. }
  49144. if (minOffLeft > 0)
  49145. {
  49146. const int limit = limits.getX() + jmin (minOffLeft - w, 0);
  49147. if (x < limit)
  49148. {
  49149. if (isStretchingLeft)
  49150. w -= (limit - x);
  49151. x = limit;
  49152. }
  49153. }
  49154. if (minOffBottom > 0)
  49155. {
  49156. const int limit = limits.getBottom() - jmin (minOffBottom, h);
  49157. if (y > limit)
  49158. {
  49159. if (isStretchingBottom)
  49160. h += (limit - y);
  49161. else
  49162. y = limit;
  49163. }
  49164. }
  49165. if (minOffRight > 0)
  49166. {
  49167. const int limit = limits.getRight() - jmin (minOffRight, w);
  49168. if (x > limit)
  49169. {
  49170. if (isStretchingRight)
  49171. w += (limit - x);
  49172. else
  49173. x = limit;
  49174. }
  49175. }
  49176. }
  49177. jassert (w >= 0 && h >= 0);
  49178. }
  49179. END_JUCE_NAMESPACE
  49180. /********* End of inlined file: juce_ComponentBoundsConstrainer.cpp *********/
  49181. /********* Start of inlined file: juce_ComponentMovementWatcher.cpp *********/
  49182. BEGIN_JUCE_NAMESPACE
  49183. ComponentMovementWatcher::ComponentMovementWatcher (Component* const component_)
  49184. : component (component_),
  49185. lastPeer (0),
  49186. reentrant (false)
  49187. {
  49188. jassert (component != 0); // can't use this with a null pointer..
  49189. #ifdef JUCE_DEBUG
  49190. deletionWatcher = new ComponentDeletionWatcher (component_);
  49191. #endif
  49192. component->addComponentListener (this);
  49193. registerWithParentComps();
  49194. }
  49195. ComponentMovementWatcher::~ComponentMovementWatcher()
  49196. {
  49197. component->removeComponentListener (this);
  49198. unregister();
  49199. }
  49200. void ComponentMovementWatcher::componentParentHierarchyChanged (Component&)
  49201. {
  49202. #ifdef JUCE_DEBUG
  49203. // agh! don't delete the target component without deleting this object first!
  49204. jassert (! deletionWatcher->hasBeenDeleted());
  49205. #endif
  49206. if (! reentrant)
  49207. {
  49208. reentrant = true;
  49209. ComponentPeer* const peer = component->getPeer();
  49210. if (peer != lastPeer)
  49211. {
  49212. ComponentDeletionWatcher watcher (component);
  49213. componentPeerChanged();
  49214. if (watcher.hasBeenDeleted())
  49215. return;
  49216. lastPeer = peer;
  49217. }
  49218. unregister();
  49219. registerWithParentComps();
  49220. reentrant = false;
  49221. componentMovedOrResized (*component, true, true);
  49222. }
  49223. }
  49224. void ComponentMovementWatcher::componentMovedOrResized (Component&, bool wasMoved, bool wasResized)
  49225. {
  49226. #ifdef JUCE_DEBUG
  49227. // agh! don't delete the target component without deleting this object first!
  49228. jassert (! deletionWatcher->hasBeenDeleted());
  49229. #endif
  49230. if (wasMoved)
  49231. {
  49232. int x = 0, y = 0;
  49233. component->relativePositionToOtherComponent (component->getTopLevelComponent(), x, y);
  49234. wasMoved = (lastX != x || lastY != y);
  49235. lastX = x;
  49236. lastY = y;
  49237. }
  49238. wasResized = (lastWidth != component->getWidth() || lastHeight != component->getHeight());
  49239. lastWidth = component->getWidth();
  49240. lastHeight = component->getHeight();
  49241. if (wasMoved || wasResized)
  49242. componentMovedOrResized (wasMoved, wasResized);
  49243. }
  49244. void ComponentMovementWatcher::registerWithParentComps() throw()
  49245. {
  49246. Component* p = component->getParentComponent();
  49247. while (p != 0)
  49248. {
  49249. p->addComponentListener (this);
  49250. registeredParentComps.add (p);
  49251. p = p->getParentComponent();
  49252. }
  49253. }
  49254. void ComponentMovementWatcher::unregister() throw()
  49255. {
  49256. for (int i = registeredParentComps.size(); --i >= 0;)
  49257. ((Component*) registeredParentComps.getUnchecked(i))->removeComponentListener (this);
  49258. registeredParentComps.clear();
  49259. }
  49260. END_JUCE_NAMESPACE
  49261. /********* End of inlined file: juce_ComponentMovementWatcher.cpp *********/
  49262. /********* Start of inlined file: juce_GroupComponent.cpp *********/
  49263. BEGIN_JUCE_NAMESPACE
  49264. GroupComponent::GroupComponent (const String& componentName,
  49265. const String& labelText)
  49266. : Component (componentName),
  49267. text (labelText),
  49268. justification (Justification::left)
  49269. {
  49270. setInterceptsMouseClicks (false, true);
  49271. }
  49272. GroupComponent::~GroupComponent()
  49273. {
  49274. }
  49275. void GroupComponent::setText (const String& newText) throw()
  49276. {
  49277. if (text != newText)
  49278. {
  49279. text = newText;
  49280. repaint();
  49281. }
  49282. }
  49283. const String GroupComponent::getText() const throw()
  49284. {
  49285. return text;
  49286. }
  49287. void GroupComponent::setTextLabelPosition (const Justification& newJustification)
  49288. {
  49289. if (justification.getFlags() != newJustification.getFlags())
  49290. {
  49291. justification = newJustification;
  49292. repaint();
  49293. }
  49294. }
  49295. void GroupComponent::paint (Graphics& g)
  49296. {
  49297. getLookAndFeel()
  49298. .drawGroupComponentOutline (g, getWidth(), getHeight(),
  49299. text, justification,
  49300. *this);
  49301. }
  49302. void GroupComponent::enablementChanged()
  49303. {
  49304. repaint();
  49305. }
  49306. void GroupComponent::colourChanged()
  49307. {
  49308. repaint();
  49309. }
  49310. END_JUCE_NAMESPACE
  49311. /********* End of inlined file: juce_GroupComponent.cpp *********/
  49312. /********* Start of inlined file: juce_MultiDocumentPanel.cpp *********/
  49313. BEGIN_JUCE_NAMESPACE
  49314. MultiDocumentPanelWindow::MultiDocumentPanelWindow (const Colour& backgroundColour)
  49315. : DocumentWindow (String::empty, backgroundColour,
  49316. DocumentWindow::maximiseButton | DocumentWindow::closeButton, false)
  49317. {
  49318. }
  49319. MultiDocumentPanelWindow::~MultiDocumentPanelWindow()
  49320. {
  49321. }
  49322. void MultiDocumentPanelWindow::maximiseButtonPressed()
  49323. {
  49324. MultiDocumentPanel* const owner = getOwner();
  49325. jassert (owner != 0); // these windows are only designed to be used inside a MultiDocumentPanel!
  49326. if (owner != 0)
  49327. owner->setLayoutMode (MultiDocumentPanel::MaximisedWindowsWithTabs);
  49328. }
  49329. void MultiDocumentPanelWindow::closeButtonPressed()
  49330. {
  49331. MultiDocumentPanel* const owner = getOwner();
  49332. jassert (owner != 0); // these windows are only designed to be used inside a MultiDocumentPanel!
  49333. if (owner != 0)
  49334. owner->closeDocument (getContentComponent(), true);
  49335. }
  49336. void MultiDocumentPanelWindow::activeWindowStatusChanged()
  49337. {
  49338. DocumentWindow::activeWindowStatusChanged();
  49339. updateOrder();
  49340. }
  49341. void MultiDocumentPanelWindow::broughtToFront()
  49342. {
  49343. DocumentWindow::broughtToFront();
  49344. updateOrder();
  49345. }
  49346. void MultiDocumentPanelWindow::updateOrder()
  49347. {
  49348. MultiDocumentPanel* const owner = getOwner();
  49349. if (owner != 0)
  49350. owner->updateOrder();
  49351. }
  49352. MultiDocumentPanel* MultiDocumentPanelWindow::getOwner() const throw()
  49353. {
  49354. // (unable to use the syntax findParentComponentOfClass <MultiDocumentPanel> () because of a VC6 compiler bug)
  49355. return findParentComponentOfClass ((MultiDocumentPanel*) 0);
  49356. }
  49357. class MDITabbedComponentInternal : public TabbedComponent
  49358. {
  49359. public:
  49360. MDITabbedComponentInternal()
  49361. : TabbedComponent (TabbedButtonBar::TabsAtTop)
  49362. {
  49363. }
  49364. ~MDITabbedComponentInternal()
  49365. {
  49366. }
  49367. void currentTabChanged (const int, const String&)
  49368. {
  49369. // (unable to use the syntax findParentComponentOfClass <MultiDocumentPanel> () because of a VC6 compiler bug)
  49370. MultiDocumentPanel* const owner = findParentComponentOfClass ((MultiDocumentPanel*) 0);
  49371. if (owner != 0)
  49372. owner->updateOrder();
  49373. }
  49374. };
  49375. MultiDocumentPanel::MultiDocumentPanel()
  49376. : mode (MaximisedWindowsWithTabs),
  49377. tabComponent (0),
  49378. backgroundColour (Colours::lightblue),
  49379. maximumNumDocuments (0),
  49380. numDocsBeforeTabsUsed (0)
  49381. {
  49382. setOpaque (true);
  49383. }
  49384. MultiDocumentPanel::~MultiDocumentPanel()
  49385. {
  49386. closeAllDocuments (false);
  49387. }
  49388. static bool shouldDeleteComp (Component* const c)
  49389. {
  49390. return c->getComponentPropertyBool (T("mdiDocumentDelete_"), false);
  49391. }
  49392. bool MultiDocumentPanel::closeAllDocuments (const bool checkItsOkToCloseFirst)
  49393. {
  49394. while (components.size() > 0)
  49395. if (! closeDocument (components.getLast(), checkItsOkToCloseFirst))
  49396. return false;
  49397. return true;
  49398. }
  49399. MultiDocumentPanelWindow* MultiDocumentPanel::createNewDocumentWindow()
  49400. {
  49401. return new MultiDocumentPanelWindow (backgroundColour);
  49402. }
  49403. void MultiDocumentPanel::addWindow (Component* component)
  49404. {
  49405. MultiDocumentPanelWindow* const dw = createNewDocumentWindow();
  49406. dw->setResizable (true, false);
  49407. dw->setContentComponent (component, false, true);
  49408. dw->setName (component->getName());
  49409. dw->setBackgroundColour (component->getComponentPropertyColour (T("mdiDocumentBkg_"), false, backgroundColour));
  49410. int x = 4;
  49411. Component* const topComp = getChildComponent (getNumChildComponents() - 1);
  49412. if (topComp != 0 && topComp->getX() == x && topComp->getY() == x)
  49413. x += 16;
  49414. dw->setTopLeftPosition (x, x);
  49415. if (component->getComponentProperty (T("mdiDocumentPos_"), false, String::empty).isNotEmpty())
  49416. dw->restoreWindowStateFromString (component->getComponentProperty (T("mdiDocumentPos_"), false, String::empty));
  49417. addAndMakeVisible (dw);
  49418. dw->toFront (true);
  49419. }
  49420. bool MultiDocumentPanel::addDocument (Component* const component,
  49421. const Colour& docColour,
  49422. const bool deleteWhenRemoved)
  49423. {
  49424. // If you try passing a full DocumentWindow or ResizableWindow in here, you'll end up
  49425. // with a frame-within-a-frame! Just pass in the bare content component.
  49426. jassert (dynamic_cast <ResizableWindow*> (component) == 0);
  49427. if (component == 0 || (maximumNumDocuments > 0 && components.size() >= maximumNumDocuments))
  49428. return false;
  49429. components.add (component);
  49430. component->setComponentProperty (T("mdiDocumentDelete_"), deleteWhenRemoved);
  49431. component->setComponentProperty (T("mdiDocumentBkg_"), docColour);
  49432. component->addComponentListener (this);
  49433. if (mode == FloatingWindows)
  49434. {
  49435. if (isFullscreenWhenOneDocument())
  49436. {
  49437. if (components.size() == 1)
  49438. {
  49439. addAndMakeVisible (component);
  49440. }
  49441. else
  49442. {
  49443. if (components.size() == 2)
  49444. addWindow (components.getFirst());
  49445. addWindow (component);
  49446. }
  49447. }
  49448. else
  49449. {
  49450. addWindow (component);
  49451. }
  49452. }
  49453. else
  49454. {
  49455. if (tabComponent == 0 && components.size() > numDocsBeforeTabsUsed)
  49456. {
  49457. addAndMakeVisible (tabComponent = new MDITabbedComponentInternal());
  49458. Array <Component*> temp (components);
  49459. for (int i = 0; i < temp.size(); ++i)
  49460. tabComponent->addTab (temp[i]->getName(), docColour, temp[i], false);
  49461. resized();
  49462. }
  49463. else
  49464. {
  49465. if (tabComponent != 0)
  49466. tabComponent->addTab (component->getName(), docColour, component, false);
  49467. else
  49468. addAndMakeVisible (component);
  49469. }
  49470. setActiveDocument (component);
  49471. }
  49472. resized();
  49473. activeDocumentChanged();
  49474. return true;
  49475. }
  49476. bool MultiDocumentPanel::closeDocument (Component* component,
  49477. const bool checkItsOkToCloseFirst)
  49478. {
  49479. if (components.contains (component))
  49480. {
  49481. if (checkItsOkToCloseFirst && ! tryToCloseDocument (component))
  49482. return false;
  49483. component->removeComponentListener (this);
  49484. const bool shouldDelete = shouldDeleteComp (component);
  49485. component->removeComponentProperty (T("mdiDocumentDelete_"));
  49486. component->removeComponentProperty (T("mdiDocumentBkg_"));
  49487. if (mode == FloatingWindows)
  49488. {
  49489. for (int i = getNumChildComponents(); --i >= 0;)
  49490. {
  49491. MultiDocumentPanelWindow* const dw = dynamic_cast <MultiDocumentPanelWindow*> (getChildComponent (i));
  49492. if (dw != 0 && dw->getContentComponent() == component)
  49493. {
  49494. dw->setContentComponent (0, false);
  49495. delete dw;
  49496. break;
  49497. }
  49498. }
  49499. if (shouldDelete)
  49500. delete component;
  49501. components.removeValue (component);
  49502. if (isFullscreenWhenOneDocument() && components.size() == 1)
  49503. {
  49504. for (int i = getNumChildComponents(); --i >= 0;)
  49505. {
  49506. MultiDocumentPanelWindow* const dw = dynamic_cast <MultiDocumentPanelWindow*> (getChildComponent (i));
  49507. if (dw != 0)
  49508. {
  49509. dw->setContentComponent (0, false);
  49510. delete dw;
  49511. }
  49512. }
  49513. addAndMakeVisible (components.getFirst());
  49514. }
  49515. }
  49516. else
  49517. {
  49518. jassert (components.indexOf (component) >= 0);
  49519. if (tabComponent != 0)
  49520. {
  49521. for (int i = tabComponent->getNumTabs(); --i >= 0;)
  49522. if (tabComponent->getTabContentComponent (i) == component)
  49523. tabComponent->removeTab (i);
  49524. }
  49525. else
  49526. {
  49527. removeChildComponent (component);
  49528. }
  49529. if (shouldDelete)
  49530. delete component;
  49531. if (tabComponent != 0 && tabComponent->getNumTabs() <= numDocsBeforeTabsUsed)
  49532. deleteAndZero (tabComponent);
  49533. components.removeValue (component);
  49534. if (components.size() > 0 && tabComponent == 0)
  49535. addAndMakeVisible (components.getFirst());
  49536. }
  49537. resized();
  49538. activeDocumentChanged();
  49539. }
  49540. else
  49541. {
  49542. jassertfalse
  49543. }
  49544. return true;
  49545. }
  49546. int MultiDocumentPanel::getNumDocuments() const throw()
  49547. {
  49548. return components.size();
  49549. }
  49550. Component* MultiDocumentPanel::getDocument (const int index) const throw()
  49551. {
  49552. return components [index];
  49553. }
  49554. Component* MultiDocumentPanel::getActiveDocument() const throw()
  49555. {
  49556. if (mode == FloatingWindows)
  49557. {
  49558. for (int i = getNumChildComponents(); --i >= 0;)
  49559. {
  49560. MultiDocumentPanelWindow* const dw = dynamic_cast <MultiDocumentPanelWindow*> (getChildComponent (i));
  49561. if (dw != 0 && dw->isActiveWindow())
  49562. return dw->getContentComponent();
  49563. }
  49564. }
  49565. return components.getLast();
  49566. }
  49567. void MultiDocumentPanel::setActiveDocument (Component* component)
  49568. {
  49569. if (mode == FloatingWindows)
  49570. {
  49571. component = getContainerComp (component);
  49572. if (component != 0)
  49573. component->toFront (true);
  49574. }
  49575. else if (tabComponent != 0)
  49576. {
  49577. jassert (components.indexOf (component) >= 0);
  49578. for (int i = tabComponent->getNumTabs(); --i >= 0;)
  49579. {
  49580. if (tabComponent->getTabContentComponent (i) == component)
  49581. {
  49582. tabComponent->setCurrentTabIndex (i);
  49583. break;
  49584. }
  49585. }
  49586. }
  49587. else
  49588. {
  49589. component->grabKeyboardFocus();
  49590. }
  49591. }
  49592. void MultiDocumentPanel::activeDocumentChanged()
  49593. {
  49594. }
  49595. void MultiDocumentPanel::setMaximumNumDocuments (const int newNumber)
  49596. {
  49597. maximumNumDocuments = newNumber;
  49598. }
  49599. void MultiDocumentPanel::useFullscreenWhenOneDocument (const bool shouldUseTabs)
  49600. {
  49601. numDocsBeforeTabsUsed = shouldUseTabs ? 1 : 0;
  49602. }
  49603. bool MultiDocumentPanel::isFullscreenWhenOneDocument() const throw()
  49604. {
  49605. return numDocsBeforeTabsUsed != 0;
  49606. }
  49607. void MultiDocumentPanel::setLayoutMode (const LayoutMode newLayoutMode)
  49608. {
  49609. if (mode != newLayoutMode)
  49610. {
  49611. mode = newLayoutMode;
  49612. if (mode == FloatingWindows)
  49613. {
  49614. deleteAndZero (tabComponent);
  49615. }
  49616. else
  49617. {
  49618. for (int i = getNumChildComponents(); --i >= 0;)
  49619. {
  49620. MultiDocumentPanelWindow* const dw = dynamic_cast <MultiDocumentPanelWindow*> (getChildComponent (i));
  49621. if (dw != 0)
  49622. {
  49623. dw->getContentComponent()->setComponentProperty (T("mdiDocumentPos_"), dw->getWindowStateAsString());
  49624. dw->setContentComponent (0, false);
  49625. delete dw;
  49626. }
  49627. }
  49628. }
  49629. resized();
  49630. const Array <Component*> tempComps (components);
  49631. components.clear();
  49632. for (int i = 0; i < tempComps.size(); ++i)
  49633. {
  49634. Component* const c = tempComps.getUnchecked(i);
  49635. addDocument (c,
  49636. c->getComponentPropertyColour (T("mdiDocumentBkg_"), false, Colours::white),
  49637. shouldDeleteComp (c));
  49638. }
  49639. }
  49640. }
  49641. void MultiDocumentPanel::setBackgroundColour (const Colour& newBackgroundColour)
  49642. {
  49643. if (backgroundColour != newBackgroundColour)
  49644. {
  49645. backgroundColour = newBackgroundColour;
  49646. setOpaque (newBackgroundColour.isOpaque());
  49647. repaint();
  49648. }
  49649. }
  49650. void MultiDocumentPanel::paint (Graphics& g)
  49651. {
  49652. g.fillAll (backgroundColour);
  49653. }
  49654. void MultiDocumentPanel::resized()
  49655. {
  49656. if (mode == MaximisedWindowsWithTabs || components.size() == numDocsBeforeTabsUsed)
  49657. {
  49658. for (int i = getNumChildComponents(); --i >= 0;)
  49659. getChildComponent (i)->setBounds (0, 0, getWidth(), getHeight());
  49660. }
  49661. setWantsKeyboardFocus (components.size() == 0);
  49662. }
  49663. Component* MultiDocumentPanel::getContainerComp (Component* c) const
  49664. {
  49665. if (mode == FloatingWindows)
  49666. {
  49667. for (int i = 0; i < getNumChildComponents(); ++i)
  49668. {
  49669. MultiDocumentPanelWindow* const dw = dynamic_cast <MultiDocumentPanelWindow*> (getChildComponent (i));
  49670. if (dw != 0 && dw->getContentComponent() == c)
  49671. {
  49672. c = dw;
  49673. break;
  49674. }
  49675. }
  49676. }
  49677. return c;
  49678. }
  49679. void MultiDocumentPanel::componentNameChanged (Component&)
  49680. {
  49681. if (mode == FloatingWindows)
  49682. {
  49683. for (int i = 0; i < getNumChildComponents(); ++i)
  49684. {
  49685. MultiDocumentPanelWindow* const dw = dynamic_cast <MultiDocumentPanelWindow*> (getChildComponent (i));
  49686. if (dw != 0)
  49687. dw->setName (dw->getContentComponent()->getName());
  49688. }
  49689. }
  49690. else if (tabComponent != 0)
  49691. {
  49692. for (int i = tabComponent->getNumTabs(); --i >= 0;)
  49693. tabComponent->setTabName (i, tabComponent->getTabContentComponent (i)->getName());
  49694. }
  49695. }
  49696. void MultiDocumentPanel::updateOrder()
  49697. {
  49698. const Array <Component*> oldList (components);
  49699. if (mode == FloatingWindows)
  49700. {
  49701. components.clear();
  49702. for (int i = 0; i < getNumChildComponents(); ++i)
  49703. {
  49704. MultiDocumentPanelWindow* const dw = dynamic_cast <MultiDocumentPanelWindow*> (getChildComponent (i));
  49705. if (dw != 0)
  49706. components.add (dw->getContentComponent());
  49707. }
  49708. }
  49709. else
  49710. {
  49711. if (tabComponent != 0)
  49712. {
  49713. Component* const current = tabComponent->getCurrentContentComponent();
  49714. if (current != 0)
  49715. {
  49716. components.removeValue (current);
  49717. components.add (current);
  49718. }
  49719. }
  49720. }
  49721. if (components != oldList)
  49722. activeDocumentChanged();
  49723. }
  49724. END_JUCE_NAMESPACE
  49725. /********* End of inlined file: juce_MultiDocumentPanel.cpp *********/
  49726. /********* Start of inlined file: juce_ResizableBorderComponent.cpp *********/
  49727. BEGIN_JUCE_NAMESPACE
  49728. const int zoneL = 1;
  49729. const int zoneR = 2;
  49730. const int zoneT = 4;
  49731. const int zoneB = 8;
  49732. ResizableBorderComponent::ResizableBorderComponent (Component* const componentToResize,
  49733. ComponentBoundsConstrainer* const constrainer_)
  49734. : component (componentToResize),
  49735. constrainer (constrainer_),
  49736. borderSize (5),
  49737. mouseZone (0)
  49738. {
  49739. }
  49740. ResizableBorderComponent::~ResizableBorderComponent()
  49741. {
  49742. }
  49743. void ResizableBorderComponent::paint (Graphics& g)
  49744. {
  49745. getLookAndFeel().drawResizableFrame (g, getWidth(), getHeight(), borderSize);
  49746. }
  49747. void ResizableBorderComponent::mouseEnter (const MouseEvent& e)
  49748. {
  49749. updateMouseZone (e);
  49750. }
  49751. void ResizableBorderComponent::mouseMove (const MouseEvent& e)
  49752. {
  49753. updateMouseZone (e);
  49754. }
  49755. void ResizableBorderComponent::mouseDown (const MouseEvent& e)
  49756. {
  49757. if (component->isValidComponent())
  49758. {
  49759. updateMouseZone (e);
  49760. originalX = component->getX();
  49761. originalY = component->getY();
  49762. originalW = component->getWidth();
  49763. originalH = component->getHeight();
  49764. if (constrainer != 0)
  49765. constrainer->resizeStart();
  49766. }
  49767. else
  49768. {
  49769. jassertfalse
  49770. }
  49771. }
  49772. void ResizableBorderComponent::mouseDrag (const MouseEvent& e)
  49773. {
  49774. if (! component->isValidComponent())
  49775. {
  49776. jassertfalse
  49777. return;
  49778. }
  49779. int x = originalX;
  49780. int y = originalY;
  49781. int w = originalW;
  49782. int h = originalH;
  49783. const int dx = e.getDistanceFromDragStartX();
  49784. const int dy = e.getDistanceFromDragStartY();
  49785. if ((mouseZone & zoneL) != 0)
  49786. {
  49787. x += dx;
  49788. w -= dx;
  49789. }
  49790. if ((mouseZone & zoneT) != 0)
  49791. {
  49792. y += dy;
  49793. h -= dy;
  49794. }
  49795. if ((mouseZone & zoneR) != 0)
  49796. w += dx;
  49797. if ((mouseZone & zoneB) != 0)
  49798. h += dy;
  49799. if (constrainer != 0)
  49800. constrainer->setBoundsForComponent (component,
  49801. x, y, w, h,
  49802. (mouseZone & zoneT) != 0,
  49803. (mouseZone & zoneL) != 0,
  49804. (mouseZone & zoneB) != 0,
  49805. (mouseZone & zoneR) != 0);
  49806. else
  49807. component->setBounds (x, y, w, h);
  49808. }
  49809. void ResizableBorderComponent::mouseUp (const MouseEvent&)
  49810. {
  49811. if (constrainer != 0)
  49812. constrainer->resizeEnd();
  49813. }
  49814. bool ResizableBorderComponent::hitTest (int x, int y)
  49815. {
  49816. return x < borderSize.getLeft()
  49817. || x >= getWidth() - borderSize.getRight()
  49818. || y < borderSize.getTop()
  49819. || y >= getHeight() - borderSize.getBottom();
  49820. }
  49821. void ResizableBorderComponent::setBorderThickness (const BorderSize& newBorderSize) throw()
  49822. {
  49823. if (borderSize != newBorderSize)
  49824. {
  49825. borderSize = newBorderSize;
  49826. repaint();
  49827. }
  49828. }
  49829. const BorderSize ResizableBorderComponent::getBorderThickness() const throw()
  49830. {
  49831. return borderSize;
  49832. }
  49833. void ResizableBorderComponent::updateMouseZone (const MouseEvent& e) throw()
  49834. {
  49835. int newZone = 0;
  49836. if (ResizableBorderComponent::hitTest (e.x, e.y))
  49837. {
  49838. if (e.x < jmax (borderSize.getLeft(),
  49839. proportionOfWidth (0.1f),
  49840. jmin (10, proportionOfWidth (0.33f))))
  49841. newZone |= zoneL;
  49842. else if (e.x >= jmin (getWidth() - borderSize.getRight(),
  49843. proportionOfWidth (0.9f),
  49844. getWidth() - jmin (10, proportionOfWidth (0.33f))))
  49845. newZone |= zoneR;
  49846. if (e.y < jmax (borderSize.getTop(),
  49847. proportionOfHeight (0.1f),
  49848. jmin (10, proportionOfHeight (0.33f))))
  49849. newZone |= zoneT;
  49850. else if (e.y >= jmin (getHeight() - borderSize.getBottom(),
  49851. proportionOfHeight (0.9f),
  49852. getHeight() - jmin (10, proportionOfHeight (0.33f))))
  49853. newZone |= zoneB;
  49854. }
  49855. if (mouseZone != newZone)
  49856. {
  49857. mouseZone = newZone;
  49858. MouseCursor::StandardCursorType mc = MouseCursor::NormalCursor;
  49859. switch (newZone)
  49860. {
  49861. case (zoneL | zoneT):
  49862. mc = MouseCursor::TopLeftCornerResizeCursor;
  49863. break;
  49864. case zoneT:
  49865. mc = MouseCursor::TopEdgeResizeCursor;
  49866. break;
  49867. case (zoneR | zoneT):
  49868. mc = MouseCursor::TopRightCornerResizeCursor;
  49869. break;
  49870. case zoneL:
  49871. mc = MouseCursor::LeftEdgeResizeCursor;
  49872. break;
  49873. case zoneR:
  49874. mc = MouseCursor::RightEdgeResizeCursor;
  49875. break;
  49876. case (zoneL | zoneB):
  49877. mc = MouseCursor::BottomLeftCornerResizeCursor;
  49878. break;
  49879. case zoneB:
  49880. mc = MouseCursor::BottomEdgeResizeCursor;
  49881. break;
  49882. case (zoneR | zoneB):
  49883. mc = MouseCursor::BottomRightCornerResizeCursor;
  49884. break;
  49885. default:
  49886. break;
  49887. }
  49888. setMouseCursor (mc);
  49889. }
  49890. }
  49891. END_JUCE_NAMESPACE
  49892. /********* End of inlined file: juce_ResizableBorderComponent.cpp *********/
  49893. /********* Start of inlined file: juce_ResizableCornerComponent.cpp *********/
  49894. BEGIN_JUCE_NAMESPACE
  49895. ResizableCornerComponent::ResizableCornerComponent (Component* const componentToResize,
  49896. ComponentBoundsConstrainer* const constrainer_)
  49897. : component (componentToResize),
  49898. constrainer (constrainer_)
  49899. {
  49900. setRepaintsOnMouseActivity (true);
  49901. setMouseCursor (MouseCursor::BottomRightCornerResizeCursor);
  49902. }
  49903. ResizableCornerComponent::~ResizableCornerComponent()
  49904. {
  49905. }
  49906. void ResizableCornerComponent::paint (Graphics& g)
  49907. {
  49908. getLookAndFeel()
  49909. .drawCornerResizer (g, getWidth(), getHeight(),
  49910. isMouseOverOrDragging(),
  49911. isMouseButtonDown());
  49912. }
  49913. void ResizableCornerComponent::mouseDown (const MouseEvent&)
  49914. {
  49915. if (component->isValidComponent())
  49916. {
  49917. originalX = component->getX();
  49918. originalY = component->getY();
  49919. originalW = component->getWidth();
  49920. originalH = component->getHeight();
  49921. if (constrainer != 0)
  49922. constrainer->resizeStart();
  49923. }
  49924. else
  49925. {
  49926. jassertfalse
  49927. }
  49928. }
  49929. void ResizableCornerComponent::mouseDrag (const MouseEvent& e)
  49930. {
  49931. if (! component->isValidComponent())
  49932. {
  49933. jassertfalse
  49934. return;
  49935. }
  49936. int x = originalX;
  49937. int y = originalY;
  49938. int w = originalW + e.getDistanceFromDragStartX();
  49939. int h = originalH + e.getDistanceFromDragStartY();
  49940. if (constrainer != 0)
  49941. constrainer->setBoundsForComponent (component, x, y, w, h,
  49942. false, false, true, true);
  49943. else
  49944. component->setBounds (x, y, w, h);
  49945. }
  49946. void ResizableCornerComponent::mouseUp (const MouseEvent&)
  49947. {
  49948. if (constrainer != 0)
  49949. constrainer->resizeStart();
  49950. }
  49951. bool ResizableCornerComponent::hitTest (int x, int y)
  49952. {
  49953. if (getWidth() <= 0)
  49954. return false;
  49955. const int yAtX = getHeight() - (getHeight() * x / getWidth());
  49956. return y >= yAtX - getHeight() / 4;
  49957. }
  49958. END_JUCE_NAMESPACE
  49959. /********* End of inlined file: juce_ResizableCornerComponent.cpp *********/
  49960. /********* Start of inlined file: juce_ScrollBar.cpp *********/
  49961. BEGIN_JUCE_NAMESPACE
  49962. class ScrollbarButton : public Button
  49963. {
  49964. public:
  49965. int direction;
  49966. ScrollbarButton (const int direction_,
  49967. ScrollBar& owner_) throw()
  49968. : Button (String::empty),
  49969. direction (direction_),
  49970. owner (owner_)
  49971. {
  49972. setWantsKeyboardFocus (false);
  49973. }
  49974. ~ScrollbarButton()
  49975. {
  49976. }
  49977. void paintButton (Graphics& g,
  49978. bool isMouseOver,
  49979. bool isMouseDown)
  49980. {
  49981. getLookAndFeel()
  49982. .drawScrollbarButton (g, owner,
  49983. getWidth(), getHeight(),
  49984. direction,
  49985. owner.isVertical(),
  49986. isMouseOver, isMouseDown);
  49987. }
  49988. void clicked()
  49989. {
  49990. owner.moveScrollbarInSteps ((direction == 1 || direction == 2) ? 1 : -1);
  49991. }
  49992. juce_UseDebuggingNewOperator
  49993. private:
  49994. ScrollBar& owner;
  49995. ScrollbarButton (const ScrollbarButton&);
  49996. const ScrollbarButton& operator= (const ScrollbarButton&);
  49997. };
  49998. ScrollBar::ScrollBar (const bool vertical_,
  49999. const bool buttonsAreVisible)
  50000. : minimum (0.0),
  50001. maximum (1.0),
  50002. rangeStart (0.0),
  50003. rangeSize (0.1),
  50004. singleStepSize (0.1),
  50005. thumbAreaStart (0),
  50006. thumbAreaSize (0),
  50007. thumbStart (0),
  50008. thumbSize (0),
  50009. initialDelayInMillisecs (100),
  50010. repeatDelayInMillisecs (50),
  50011. minimumDelayInMillisecs (10),
  50012. vertical (vertical_),
  50013. isDraggingThumb (false),
  50014. alwaysVisible (false),
  50015. upButton (0),
  50016. downButton (0)
  50017. {
  50018. setButtonVisibility (buttonsAreVisible);
  50019. setRepaintsOnMouseActivity (true);
  50020. setFocusContainer (true);
  50021. }
  50022. ScrollBar::~ScrollBar()
  50023. {
  50024. deleteAllChildren();
  50025. }
  50026. void ScrollBar::setRangeLimits (const double newMinimum,
  50027. const double newMaximum) throw()
  50028. {
  50029. minimum = newMinimum;
  50030. maximum = newMaximum;
  50031. jassert (maximum >= minimum); // these can't be the wrong way round!
  50032. setCurrentRangeStart (rangeStart);
  50033. updateThumbPosition();
  50034. }
  50035. void ScrollBar::setCurrentRange (double newStart,
  50036. double newSize) throw()
  50037. {
  50038. newSize = jlimit (0.0, maximum - minimum, newSize);
  50039. newStart = jlimit (minimum, maximum - newSize, newStart);
  50040. if (rangeStart != newStart
  50041. || rangeSize != newSize)
  50042. {
  50043. rangeStart = newStart;
  50044. rangeSize = newSize;
  50045. updateThumbPosition();
  50046. triggerAsyncUpdate();
  50047. }
  50048. }
  50049. void ScrollBar::setCurrentRangeStart (double newStart) throw()
  50050. {
  50051. setCurrentRange (newStart, rangeSize);
  50052. }
  50053. void ScrollBar::setSingleStepSize (const double newSingleStepSize) throw()
  50054. {
  50055. singleStepSize = newSingleStepSize;
  50056. }
  50057. void ScrollBar::moveScrollbarInSteps (const int howManySteps) throw()
  50058. {
  50059. setCurrentRangeStart (rangeStart + howManySteps * singleStepSize);
  50060. }
  50061. void ScrollBar::moveScrollbarInPages (const int howManyPages) throw()
  50062. {
  50063. setCurrentRangeStart (rangeStart + howManyPages * rangeSize);
  50064. }
  50065. void ScrollBar::scrollToTop() throw()
  50066. {
  50067. setCurrentRangeStart (minimum);
  50068. }
  50069. void ScrollBar::scrollToBottom() throw()
  50070. {
  50071. setCurrentRangeStart (maximum - rangeSize);
  50072. }
  50073. void ScrollBar::setButtonRepeatSpeed (const int initialDelayInMillisecs_,
  50074. const int repeatDelayInMillisecs_,
  50075. const int minimumDelayInMillisecs_) throw()
  50076. {
  50077. initialDelayInMillisecs = initialDelayInMillisecs_;
  50078. repeatDelayInMillisecs = repeatDelayInMillisecs_;
  50079. minimumDelayInMillisecs = minimumDelayInMillisecs_;
  50080. if (upButton != 0)
  50081. {
  50082. upButton->setRepeatSpeed (initialDelayInMillisecs, repeatDelayInMillisecs, minimumDelayInMillisecs);
  50083. downButton->setRepeatSpeed (initialDelayInMillisecs, repeatDelayInMillisecs, minimumDelayInMillisecs);
  50084. }
  50085. }
  50086. void ScrollBar::addListener (ScrollBarListener* const listener) throw()
  50087. {
  50088. jassert (listener != 0);
  50089. if (listener != 0)
  50090. listeners.add (listener);
  50091. }
  50092. void ScrollBar::removeListener (ScrollBarListener* const listener) throw()
  50093. {
  50094. listeners.removeValue (listener);
  50095. }
  50096. void ScrollBar::handleAsyncUpdate()
  50097. {
  50098. const double value = getCurrentRangeStart();
  50099. for (int i = listeners.size(); --i >= 0;)
  50100. {
  50101. ((ScrollBarListener*) listeners.getUnchecked (i))->scrollBarMoved (this, value);
  50102. i = jmin (i, listeners.size());
  50103. }
  50104. }
  50105. void ScrollBar::updateThumbPosition() throw()
  50106. {
  50107. int newThumbSize = roundToInt ((maximum > minimum) ? (rangeSize * thumbAreaSize) / (maximum - minimum)
  50108. : thumbAreaSize);
  50109. if (newThumbSize < getLookAndFeel().getMinimumScrollbarThumbSize (*this))
  50110. newThumbSize = jmin (getLookAndFeel().getMinimumScrollbarThumbSize (*this), thumbAreaSize - 1);
  50111. if (newThumbSize > thumbAreaSize)
  50112. newThumbSize = thumbAreaSize;
  50113. int newThumbStart = thumbAreaStart;
  50114. if (maximum - minimum > rangeSize)
  50115. newThumbStart += roundToInt (((rangeStart - minimum) * (thumbAreaSize - newThumbSize))
  50116. / ((maximum - minimum) - rangeSize));
  50117. setVisible (alwaysVisible || (maximum - minimum > rangeSize && rangeSize > 0.0));
  50118. if (thumbStart != newThumbStart || thumbSize != newThumbSize)
  50119. {
  50120. const int repaintStart = jmin (thumbStart, newThumbStart) - 4;
  50121. const int repaintSize = jmax (thumbStart + thumbSize, newThumbStart + newThumbSize) + 8 - repaintStart;
  50122. if (vertical)
  50123. repaint (0, repaintStart, getWidth(), repaintSize);
  50124. else
  50125. repaint (repaintStart, 0, repaintSize, getHeight());
  50126. thumbStart = newThumbStart;
  50127. thumbSize = newThumbSize;
  50128. }
  50129. }
  50130. void ScrollBar::setOrientation (const bool shouldBeVertical) throw()
  50131. {
  50132. if (vertical != shouldBeVertical)
  50133. {
  50134. vertical = shouldBeVertical;
  50135. if (upButton != 0)
  50136. {
  50137. ((ScrollbarButton*) upButton)->direction = (vertical) ? 0 : 3;
  50138. ((ScrollbarButton*) downButton)->direction = (vertical) ? 2 : 1;
  50139. }
  50140. updateThumbPosition();
  50141. }
  50142. }
  50143. void ScrollBar::setButtonVisibility (const bool buttonsAreVisible)
  50144. {
  50145. deleteAndZero (upButton);
  50146. deleteAndZero (downButton);
  50147. if (buttonsAreVisible)
  50148. {
  50149. addAndMakeVisible (upButton = new ScrollbarButton ((vertical) ? 0 : 3, *this));
  50150. addAndMakeVisible (downButton = new ScrollbarButton ((vertical) ? 2 : 1, *this));
  50151. setButtonRepeatSpeed (initialDelayInMillisecs, repeatDelayInMillisecs, minimumDelayInMillisecs);
  50152. }
  50153. updateThumbPosition();
  50154. }
  50155. void ScrollBar::setAutoHide (const bool shouldHideWhenFullRange)
  50156. {
  50157. alwaysVisible = ! shouldHideWhenFullRange;
  50158. updateThumbPosition();
  50159. }
  50160. void ScrollBar::paint (Graphics& g)
  50161. {
  50162. if (thumbAreaSize > 0)
  50163. {
  50164. LookAndFeel& lf = getLookAndFeel();
  50165. const int thumb = (thumbAreaSize > lf.getMinimumScrollbarThumbSize (*this))
  50166. ? thumbSize : 0;
  50167. if (vertical)
  50168. {
  50169. lf.drawScrollbar (g, *this,
  50170. 0, thumbAreaStart,
  50171. getWidth(), thumbAreaSize,
  50172. vertical,
  50173. thumbStart, thumb,
  50174. isMouseOver(), isMouseButtonDown());
  50175. }
  50176. else
  50177. {
  50178. lf.drawScrollbar (g, *this,
  50179. thumbAreaStart, 0,
  50180. thumbAreaSize, getHeight(),
  50181. vertical,
  50182. thumbStart, thumb,
  50183. isMouseOver(), isMouseButtonDown());
  50184. }
  50185. }
  50186. }
  50187. void ScrollBar::lookAndFeelChanged()
  50188. {
  50189. setComponentEffect (getLookAndFeel().getScrollbarEffect());
  50190. }
  50191. void ScrollBar::resized()
  50192. {
  50193. const int length = ((vertical) ? getHeight() : getWidth());
  50194. const int buttonSize = (upButton != 0) ? jmin (getLookAndFeel().getScrollbarButtonSize (*this), (length >> 1))
  50195. : 0;
  50196. if (length < 32 + getLookAndFeel().getMinimumScrollbarThumbSize (*this))
  50197. {
  50198. thumbAreaStart = length >> 1;
  50199. thumbAreaSize = 0;
  50200. }
  50201. else
  50202. {
  50203. thumbAreaStart = buttonSize;
  50204. thumbAreaSize = length - (buttonSize << 1);
  50205. }
  50206. if (upButton != 0)
  50207. {
  50208. if (vertical)
  50209. {
  50210. upButton->setBounds (0, 0, getWidth(), buttonSize);
  50211. downButton->setBounds (0, thumbAreaStart + thumbAreaSize, getWidth(), buttonSize);
  50212. }
  50213. else
  50214. {
  50215. upButton->setBounds (0, 0, buttonSize, getHeight());
  50216. downButton->setBounds (thumbAreaStart + thumbAreaSize, 0, buttonSize, getHeight());
  50217. }
  50218. }
  50219. updateThumbPosition();
  50220. }
  50221. void ScrollBar::mouseDown (const MouseEvent& e)
  50222. {
  50223. isDraggingThumb = false;
  50224. lastMousePos = vertical ? e.y : e.x;
  50225. dragStartMousePos = lastMousePos;
  50226. dragStartRange = rangeStart;
  50227. if (dragStartMousePos < thumbStart)
  50228. {
  50229. moveScrollbarInPages (-1);
  50230. startTimer (400);
  50231. }
  50232. else if (dragStartMousePos >= thumbStart + thumbSize)
  50233. {
  50234. moveScrollbarInPages (1);
  50235. startTimer (400);
  50236. }
  50237. else
  50238. {
  50239. isDraggingThumb = (thumbAreaSize > getLookAndFeel().getMinimumScrollbarThumbSize (*this))
  50240. && (thumbAreaSize > thumbSize);
  50241. }
  50242. }
  50243. void ScrollBar::mouseDrag (const MouseEvent& e)
  50244. {
  50245. if (isDraggingThumb)
  50246. {
  50247. const int deltaPixels = ((vertical) ? e.y : e.x) - dragStartMousePos;
  50248. setCurrentRangeStart (dragStartRange
  50249. + deltaPixels * ((maximum - minimum) - rangeSize)
  50250. / (thumbAreaSize - thumbSize));
  50251. }
  50252. else
  50253. {
  50254. lastMousePos = (vertical) ? e.y : e.x;
  50255. }
  50256. }
  50257. void ScrollBar::mouseUp (const MouseEvent&)
  50258. {
  50259. isDraggingThumb = false;
  50260. stopTimer();
  50261. repaint();
  50262. }
  50263. void ScrollBar::mouseWheelMove (const MouseEvent&,
  50264. float wheelIncrementX,
  50265. float wheelIncrementY)
  50266. {
  50267. float increment = vertical ? wheelIncrementY : wheelIncrementX;
  50268. if (increment < 0)
  50269. increment = jmin (increment * 10.0f, -1.0f);
  50270. else if (increment > 0)
  50271. increment = jmax (increment * 10.0f, 1.0f);
  50272. setCurrentRangeStart (rangeStart - singleStepSize * increment);
  50273. }
  50274. void ScrollBar::timerCallback()
  50275. {
  50276. if (isMouseButtonDown())
  50277. {
  50278. startTimer (40);
  50279. if (lastMousePos < thumbStart)
  50280. setCurrentRangeStart (rangeStart - rangeSize);
  50281. else if (lastMousePos > thumbStart + thumbSize)
  50282. setCurrentRangeStart (rangeStart + rangeSize);
  50283. }
  50284. else
  50285. {
  50286. stopTimer();
  50287. }
  50288. }
  50289. bool ScrollBar::keyPressed (const KeyPress& key)
  50290. {
  50291. if (! isVisible())
  50292. return false;
  50293. if (key.isKeyCode (KeyPress::upKey) || key.isKeyCode (KeyPress::leftKey))
  50294. moveScrollbarInSteps (-1);
  50295. else if (key.isKeyCode (KeyPress::downKey) || key.isKeyCode (KeyPress::rightKey))
  50296. moveScrollbarInSteps (1);
  50297. else if (key.isKeyCode (KeyPress::pageUpKey))
  50298. moveScrollbarInPages (-1);
  50299. else if (key.isKeyCode (KeyPress::pageDownKey))
  50300. moveScrollbarInPages (1);
  50301. else if (key.isKeyCode (KeyPress::homeKey))
  50302. scrollToTop();
  50303. else if (key.isKeyCode (KeyPress::endKey))
  50304. scrollToBottom();
  50305. else
  50306. return false;
  50307. return true;
  50308. }
  50309. END_JUCE_NAMESPACE
  50310. /********* End of inlined file: juce_ScrollBar.cpp *********/
  50311. /********* Start of inlined file: juce_StretchableLayoutManager.cpp *********/
  50312. BEGIN_JUCE_NAMESPACE
  50313. StretchableLayoutManager::StretchableLayoutManager()
  50314. : totalSize (0)
  50315. {
  50316. }
  50317. StretchableLayoutManager::~StretchableLayoutManager()
  50318. {
  50319. }
  50320. void StretchableLayoutManager::clearAllItems()
  50321. {
  50322. items.clear();
  50323. totalSize = 0;
  50324. }
  50325. void StretchableLayoutManager::setItemLayout (const int itemIndex,
  50326. const double minimumSize,
  50327. const double maximumSize,
  50328. const double preferredSize)
  50329. {
  50330. ItemLayoutProperties* layout = getInfoFor (itemIndex);
  50331. if (layout == 0)
  50332. {
  50333. layout = new ItemLayoutProperties();
  50334. layout->itemIndex = itemIndex;
  50335. int i;
  50336. for (i = 0; i < items.size(); ++i)
  50337. if (items.getUnchecked (i)->itemIndex > itemIndex)
  50338. break;
  50339. items.insert (i, layout);
  50340. }
  50341. layout->minSize = minimumSize;
  50342. layout->maxSize = maximumSize;
  50343. layout->preferredSize = preferredSize;
  50344. layout->currentSize = 0;
  50345. }
  50346. bool StretchableLayoutManager::getItemLayout (const int itemIndex,
  50347. double& minimumSize,
  50348. double& maximumSize,
  50349. double& preferredSize) const
  50350. {
  50351. const ItemLayoutProperties* const layout = getInfoFor (itemIndex);
  50352. if (layout != 0)
  50353. {
  50354. minimumSize = layout->minSize;
  50355. maximumSize = layout->maxSize;
  50356. preferredSize = layout->preferredSize;
  50357. return true;
  50358. }
  50359. return false;
  50360. }
  50361. void StretchableLayoutManager::setTotalSize (const int newTotalSize)
  50362. {
  50363. totalSize = newTotalSize;
  50364. fitComponentsIntoSpace (0, items.size(), totalSize, 0);
  50365. }
  50366. int StretchableLayoutManager::getItemCurrentPosition (const int itemIndex) const
  50367. {
  50368. int pos = 0;
  50369. for (int i = 0; i < itemIndex; ++i)
  50370. {
  50371. const ItemLayoutProperties* const layout = getInfoFor (i);
  50372. if (layout != 0)
  50373. pos += layout->currentSize;
  50374. }
  50375. return pos;
  50376. }
  50377. int StretchableLayoutManager::getItemCurrentAbsoluteSize (const int itemIndex) const
  50378. {
  50379. const ItemLayoutProperties* const layout = getInfoFor (itemIndex);
  50380. if (layout != 0)
  50381. return layout->currentSize;
  50382. return 0;
  50383. }
  50384. double StretchableLayoutManager::getItemCurrentRelativeSize (const int itemIndex) const
  50385. {
  50386. const ItemLayoutProperties* const layout = getInfoFor (itemIndex);
  50387. if (layout != 0)
  50388. return -layout->currentSize / (double) totalSize;
  50389. return 0;
  50390. }
  50391. void StretchableLayoutManager::setItemPosition (const int itemIndex,
  50392. int newPosition)
  50393. {
  50394. for (int i = items.size(); --i >= 0;)
  50395. {
  50396. const ItemLayoutProperties* const layout = items.getUnchecked(i);
  50397. if (layout->itemIndex == itemIndex)
  50398. {
  50399. int realTotalSize = jmax (totalSize, getMinimumSizeOfItems (0, items.size()));
  50400. const int minSizeAfterThisComp = getMinimumSizeOfItems (i, items.size());
  50401. const int maxSizeAfterThisComp = getMaximumSizeOfItems (i + 1, items.size());
  50402. newPosition = jmax (newPosition, totalSize - maxSizeAfterThisComp - layout->currentSize);
  50403. newPosition = jmin (newPosition, realTotalSize - minSizeAfterThisComp);
  50404. int endPos = fitComponentsIntoSpace (0, i, newPosition, 0);
  50405. endPos += layout->currentSize;
  50406. fitComponentsIntoSpace (i + 1, items.size(), totalSize - endPos, endPos);
  50407. updatePrefSizesToMatchCurrentPositions();
  50408. break;
  50409. }
  50410. }
  50411. }
  50412. void StretchableLayoutManager::layOutComponents (Component** const components,
  50413. int numComponents,
  50414. int x, int y, int w, int h,
  50415. const bool vertically,
  50416. const bool resizeOtherDimension)
  50417. {
  50418. setTotalSize (vertically ? h : w);
  50419. int pos = vertically ? y : x;
  50420. for (int i = 0; i < numComponents; ++i)
  50421. {
  50422. const ItemLayoutProperties* const layout = getInfoFor (i);
  50423. if (layout != 0)
  50424. {
  50425. Component* const c = components[i];
  50426. if (c != 0)
  50427. {
  50428. if (i == numComponents - 1)
  50429. {
  50430. // if it's the last item, crop it to exactly fit the available space..
  50431. if (resizeOtherDimension)
  50432. {
  50433. if (vertically)
  50434. c->setBounds (x, pos, w, jmax (layout->currentSize, h - pos));
  50435. else
  50436. c->setBounds (pos, y, jmax (layout->currentSize, w - pos), h);
  50437. }
  50438. else
  50439. {
  50440. if (vertically)
  50441. c->setBounds (c->getX(), pos, c->getWidth(), jmax (layout->currentSize, h - pos));
  50442. else
  50443. c->setBounds (pos, c->getY(), jmax (layout->currentSize, w - pos), c->getHeight());
  50444. }
  50445. }
  50446. else
  50447. {
  50448. if (resizeOtherDimension)
  50449. {
  50450. if (vertically)
  50451. c->setBounds (x, pos, w, layout->currentSize);
  50452. else
  50453. c->setBounds (pos, y, layout->currentSize, h);
  50454. }
  50455. else
  50456. {
  50457. if (vertically)
  50458. c->setBounds (c->getX(), pos, c->getWidth(), layout->currentSize);
  50459. else
  50460. c->setBounds (pos, c->getY(), layout->currentSize, c->getHeight());
  50461. }
  50462. }
  50463. }
  50464. pos += layout->currentSize;
  50465. }
  50466. }
  50467. }
  50468. StretchableLayoutManager::ItemLayoutProperties* StretchableLayoutManager::getInfoFor (const int itemIndex) const
  50469. {
  50470. for (int i = items.size(); --i >= 0;)
  50471. if (items.getUnchecked(i)->itemIndex == itemIndex)
  50472. return items.getUnchecked(i);
  50473. return 0;
  50474. }
  50475. int StretchableLayoutManager::fitComponentsIntoSpace (const int startIndex,
  50476. const int endIndex,
  50477. const int availableSpace,
  50478. int startPos)
  50479. {
  50480. // calculate the total sizes
  50481. int i;
  50482. double totalIdealSize = 0.0;
  50483. int totalMinimums = 0;
  50484. for (i = startIndex; i < endIndex; ++i)
  50485. {
  50486. ItemLayoutProperties* const layout = items.getUnchecked (i);
  50487. layout->currentSize = sizeToRealSize (layout->minSize, totalSize);
  50488. totalMinimums += layout->currentSize;
  50489. totalIdealSize += sizeToRealSize (layout->preferredSize, availableSpace);
  50490. }
  50491. if (totalIdealSize <= 0)
  50492. totalIdealSize = 1.0;
  50493. // now calc the best sizes..
  50494. int extraSpace = availableSpace - totalMinimums;
  50495. while (extraSpace > 0)
  50496. {
  50497. int numWantingMoreSpace = 0;
  50498. int numHavingTakenExtraSpace = 0;
  50499. // first figure out how many comps want a slice of the extra space..
  50500. for (i = startIndex; i < endIndex; ++i)
  50501. {
  50502. ItemLayoutProperties* const layout = items.getUnchecked (i);
  50503. double sizeWanted = sizeToRealSize (layout->preferredSize, availableSpace);
  50504. const int bestSize = jlimit (layout->currentSize,
  50505. jmax (layout->currentSize,
  50506. sizeToRealSize (layout->maxSize, totalSize)),
  50507. roundToInt (sizeWanted * availableSpace / totalIdealSize));
  50508. if (bestSize > layout->currentSize)
  50509. ++numWantingMoreSpace;
  50510. }
  50511. // ..share out the extra space..
  50512. for (i = startIndex; i < endIndex; ++i)
  50513. {
  50514. ItemLayoutProperties* const layout = items.getUnchecked (i);
  50515. double sizeWanted = sizeToRealSize (layout->preferredSize, availableSpace);
  50516. int bestSize = jlimit (layout->currentSize,
  50517. jmax (layout->currentSize, sizeToRealSize (layout->maxSize, totalSize)),
  50518. roundToInt (sizeWanted * availableSpace / totalIdealSize));
  50519. const int extraWanted = bestSize - layout->currentSize;
  50520. if (extraWanted > 0)
  50521. {
  50522. const int extraAllowed = jmin (extraWanted,
  50523. extraSpace / jmax (1, numWantingMoreSpace));
  50524. if (extraAllowed > 0)
  50525. {
  50526. ++numHavingTakenExtraSpace;
  50527. --numWantingMoreSpace;
  50528. layout->currentSize += extraAllowed;
  50529. extraSpace -= extraAllowed;
  50530. }
  50531. }
  50532. }
  50533. if (numHavingTakenExtraSpace <= 0)
  50534. break;
  50535. }
  50536. // ..and calculate the end position
  50537. for (i = startIndex; i < endIndex; ++i)
  50538. {
  50539. ItemLayoutProperties* const layout = items.getUnchecked(i);
  50540. startPos += layout->currentSize;
  50541. }
  50542. return startPos;
  50543. }
  50544. int StretchableLayoutManager::getMinimumSizeOfItems (const int startIndex,
  50545. const int endIndex) const
  50546. {
  50547. int totalMinimums = 0;
  50548. for (int i = startIndex; i < endIndex; ++i)
  50549. totalMinimums += sizeToRealSize (items.getUnchecked (i)->minSize, totalSize);
  50550. return totalMinimums;
  50551. }
  50552. int StretchableLayoutManager::getMaximumSizeOfItems (const int startIndex, const int endIndex) const
  50553. {
  50554. int totalMaximums = 0;
  50555. for (int i = startIndex; i < endIndex; ++i)
  50556. totalMaximums += sizeToRealSize (items.getUnchecked (i)->maxSize, totalSize);
  50557. return totalMaximums;
  50558. }
  50559. void StretchableLayoutManager::updatePrefSizesToMatchCurrentPositions()
  50560. {
  50561. for (int i = 0; i < items.size(); ++i)
  50562. {
  50563. ItemLayoutProperties* const layout = items.getUnchecked (i);
  50564. layout->preferredSize
  50565. = (layout->preferredSize < 0) ? getItemCurrentRelativeSize (i)
  50566. : getItemCurrentAbsoluteSize (i);
  50567. }
  50568. }
  50569. int StretchableLayoutManager::sizeToRealSize (double size, int totalSpace)
  50570. {
  50571. if (size < 0)
  50572. size *= -totalSpace;
  50573. return roundToInt (size);
  50574. }
  50575. END_JUCE_NAMESPACE
  50576. /********* End of inlined file: juce_StretchableLayoutManager.cpp *********/
  50577. /********* Start of inlined file: juce_StretchableLayoutResizerBar.cpp *********/
  50578. BEGIN_JUCE_NAMESPACE
  50579. StretchableLayoutResizerBar::StretchableLayoutResizerBar (StretchableLayoutManager* layout_,
  50580. const int itemIndex_,
  50581. const bool isVertical_)
  50582. : layout (layout_),
  50583. itemIndex (itemIndex_),
  50584. isVertical (isVertical_)
  50585. {
  50586. setRepaintsOnMouseActivity (true);
  50587. setMouseCursor (MouseCursor (isVertical_ ? MouseCursor::LeftRightResizeCursor
  50588. : MouseCursor::UpDownResizeCursor));
  50589. }
  50590. StretchableLayoutResizerBar::~StretchableLayoutResizerBar()
  50591. {
  50592. }
  50593. void StretchableLayoutResizerBar::paint (Graphics& g)
  50594. {
  50595. getLookAndFeel().drawStretchableLayoutResizerBar (g,
  50596. getWidth(), getHeight(),
  50597. isVertical,
  50598. isMouseOver(),
  50599. isMouseButtonDown());
  50600. }
  50601. void StretchableLayoutResizerBar::mouseDown (const MouseEvent&)
  50602. {
  50603. mouseDownPos = layout->getItemCurrentPosition (itemIndex);
  50604. }
  50605. void StretchableLayoutResizerBar::mouseDrag (const MouseEvent& e)
  50606. {
  50607. const int desiredPos = mouseDownPos + (isVertical ? e.getDistanceFromDragStartX()
  50608. : e.getDistanceFromDragStartY());
  50609. layout->setItemPosition (itemIndex, desiredPos);
  50610. hasBeenMoved();
  50611. }
  50612. void StretchableLayoutResizerBar::hasBeenMoved()
  50613. {
  50614. if (getParentComponent() != 0)
  50615. getParentComponent()->resized();
  50616. }
  50617. END_JUCE_NAMESPACE
  50618. /********* End of inlined file: juce_StretchableLayoutResizerBar.cpp *********/
  50619. /********* Start of inlined file: juce_StretchableObjectResizer.cpp *********/
  50620. BEGIN_JUCE_NAMESPACE
  50621. StretchableObjectResizer::StretchableObjectResizer()
  50622. {
  50623. }
  50624. StretchableObjectResizer::~StretchableObjectResizer()
  50625. {
  50626. }
  50627. void StretchableObjectResizer::addItem (const double size,
  50628. const double minSize, const double maxSize,
  50629. const int order)
  50630. {
  50631. jassert (order >= 0 && order < INT_MAX); // the order must be >= 0 and less than INT_MAX
  50632. Item* const item = new Item();
  50633. item->size = size;
  50634. item->minSize = minSize;
  50635. item->maxSize = maxSize;
  50636. item->order = order;
  50637. items.add (item);
  50638. }
  50639. double StretchableObjectResizer::getItemSize (const int index) const throw()
  50640. {
  50641. const Item* const it = items [index];
  50642. return it != 0 ? it->size : 0;
  50643. }
  50644. void StretchableObjectResizer::resizeToFit (const double targetSize)
  50645. {
  50646. int order = 0;
  50647. for (;;)
  50648. {
  50649. double currentSize = 0;
  50650. double minSize = 0;
  50651. double maxSize = 0;
  50652. int nextHighestOrder = INT_MAX;
  50653. for (int i = 0; i < items.size(); ++i)
  50654. {
  50655. const Item* const it = items.getUnchecked(i);
  50656. currentSize += it->size;
  50657. if (it->order <= order)
  50658. {
  50659. minSize += it->minSize;
  50660. maxSize += it->maxSize;
  50661. }
  50662. else
  50663. {
  50664. minSize += it->size;
  50665. maxSize += it->size;
  50666. nextHighestOrder = jmin (nextHighestOrder, it->order);
  50667. }
  50668. }
  50669. const double thisIterationTarget = jlimit (minSize, maxSize, targetSize);
  50670. if (thisIterationTarget >= currentSize)
  50671. {
  50672. const double availableExtraSpace = maxSize - currentSize;
  50673. const double targetAmountOfExtraSpace = thisIterationTarget - currentSize;
  50674. const double scale = targetAmountOfExtraSpace / availableExtraSpace;
  50675. for (int i = 0; i < items.size(); ++i)
  50676. {
  50677. Item* const it = items.getUnchecked(i);
  50678. if (it->order <= order)
  50679. it->size = jmin (it->maxSize, it->size + (it->maxSize - it->size) * scale);
  50680. }
  50681. }
  50682. else
  50683. {
  50684. const double amountOfSlack = currentSize - minSize;
  50685. const double targetAmountOfSlack = thisIterationTarget - minSize;
  50686. const double scale = targetAmountOfSlack / amountOfSlack;
  50687. for (int i = 0; i < items.size(); ++i)
  50688. {
  50689. Item* const it = items.getUnchecked(i);
  50690. if (it->order <= order)
  50691. it->size = jmax (it->minSize, it->minSize + (it->size - it->minSize) * scale);
  50692. }
  50693. }
  50694. if (nextHighestOrder < INT_MAX)
  50695. order = nextHighestOrder;
  50696. else
  50697. break;
  50698. }
  50699. }
  50700. END_JUCE_NAMESPACE
  50701. /********* End of inlined file: juce_StretchableObjectResizer.cpp *********/
  50702. /********* Start of inlined file: juce_TabbedButtonBar.cpp *********/
  50703. BEGIN_JUCE_NAMESPACE
  50704. TabBarButton::TabBarButton (const String& name,
  50705. TabbedButtonBar* const owner_,
  50706. const int index)
  50707. : Button (name),
  50708. owner (owner_),
  50709. tabIndex (index),
  50710. overlapPixels (0)
  50711. {
  50712. shadow.setShadowProperties (2.2f, 0.7f, 0, 0);
  50713. setComponentEffect (&shadow);
  50714. setWantsKeyboardFocus (false);
  50715. }
  50716. TabBarButton::~TabBarButton()
  50717. {
  50718. }
  50719. void TabBarButton::paintButton (Graphics& g,
  50720. bool isMouseOverButton,
  50721. bool isButtonDown)
  50722. {
  50723. int x, y, w, h;
  50724. getActiveArea (x, y, w, h);
  50725. g.setOrigin (x, y);
  50726. getLookAndFeel()
  50727. .drawTabButton (g, w, h,
  50728. owner->getTabBackgroundColour (tabIndex),
  50729. tabIndex, getButtonText(), *this,
  50730. owner->getOrientation(),
  50731. isMouseOverButton, isButtonDown,
  50732. getToggleState());
  50733. }
  50734. void TabBarButton::clicked (const ModifierKeys& mods)
  50735. {
  50736. if (mods.isPopupMenu())
  50737. owner->popupMenuClickOnTab (tabIndex, getButtonText());
  50738. else
  50739. owner->setCurrentTabIndex (tabIndex);
  50740. }
  50741. bool TabBarButton::hitTest (int mx, int my)
  50742. {
  50743. int x, y, w, h;
  50744. getActiveArea (x, y, w, h);
  50745. if (owner->getOrientation() == TabbedButtonBar::TabsAtLeft
  50746. || owner->getOrientation() == TabbedButtonBar::TabsAtRight)
  50747. {
  50748. if (((unsigned int) mx) < (unsigned int) getWidth()
  50749. && my >= y + overlapPixels
  50750. && my < y + h - overlapPixels)
  50751. return true;
  50752. }
  50753. else
  50754. {
  50755. if (mx >= x + overlapPixels && mx < x + w - overlapPixels
  50756. && ((unsigned int) my) < (unsigned int) getHeight())
  50757. return true;
  50758. }
  50759. Path p;
  50760. getLookAndFeel()
  50761. .createTabButtonShape (p, w, h, tabIndex, getButtonText(), *this,
  50762. owner->getOrientation(),
  50763. false, false, getToggleState());
  50764. return p.contains ((float) (mx - x),
  50765. (float) (my - y));
  50766. }
  50767. int TabBarButton::getBestTabLength (const int depth)
  50768. {
  50769. return jlimit (depth * 2,
  50770. depth * 7,
  50771. getLookAndFeel().getTabButtonBestWidth (tabIndex, getButtonText(), depth, *this));
  50772. }
  50773. void TabBarButton::getActiveArea (int& x, int& y, int& w, int& h)
  50774. {
  50775. x = 0;
  50776. y = 0;
  50777. int r = getWidth();
  50778. int b = getHeight();
  50779. const int spaceAroundImage = getLookAndFeel().getTabButtonSpaceAroundImage();
  50780. if (owner->getOrientation() != TabbedButtonBar::TabsAtLeft)
  50781. r -= spaceAroundImage;
  50782. if (owner->getOrientation() != TabbedButtonBar::TabsAtRight)
  50783. x += spaceAroundImage;
  50784. if (owner->getOrientation() != TabbedButtonBar::TabsAtBottom)
  50785. y += spaceAroundImage;
  50786. if (owner->getOrientation() != TabbedButtonBar::TabsAtTop)
  50787. b -= spaceAroundImage;
  50788. w = r - x;
  50789. h = b - y;
  50790. }
  50791. class TabAreaBehindFrontButtonComponent : public Component
  50792. {
  50793. public:
  50794. TabAreaBehindFrontButtonComponent (TabbedButtonBar* const owner_)
  50795. : owner (owner_)
  50796. {
  50797. setInterceptsMouseClicks (false, false);
  50798. }
  50799. ~TabAreaBehindFrontButtonComponent()
  50800. {
  50801. }
  50802. void paint (Graphics& g)
  50803. {
  50804. getLookAndFeel()
  50805. .drawTabAreaBehindFrontButton (g, getWidth(), getHeight(),
  50806. *owner, owner->getOrientation());
  50807. }
  50808. void enablementChanged()
  50809. {
  50810. repaint();
  50811. }
  50812. private:
  50813. TabbedButtonBar* const owner;
  50814. TabAreaBehindFrontButtonComponent (const TabAreaBehindFrontButtonComponent&);
  50815. const TabAreaBehindFrontButtonComponent& operator= (const TabAreaBehindFrontButtonComponent&);
  50816. };
  50817. TabbedButtonBar::TabbedButtonBar (const Orientation orientation_)
  50818. : orientation (orientation_),
  50819. currentTabIndex (-1),
  50820. extraTabsButton (0)
  50821. {
  50822. setInterceptsMouseClicks (false, true);
  50823. addAndMakeVisible (behindFrontTab = new TabAreaBehindFrontButtonComponent (this));
  50824. setFocusContainer (true);
  50825. }
  50826. TabbedButtonBar::~TabbedButtonBar()
  50827. {
  50828. deleteAllChildren();
  50829. }
  50830. void TabbedButtonBar::setOrientation (const Orientation newOrientation)
  50831. {
  50832. orientation = newOrientation;
  50833. for (int i = getNumChildComponents(); --i >= 0;)
  50834. getChildComponent (i)->resized();
  50835. resized();
  50836. }
  50837. TabBarButton* TabbedButtonBar::createTabButton (const String& name, const int index)
  50838. {
  50839. return new TabBarButton (name, this, index);
  50840. }
  50841. void TabbedButtonBar::clearTabs()
  50842. {
  50843. tabs.clear();
  50844. tabColours.clear();
  50845. currentTabIndex = -1;
  50846. deleteAndZero (extraTabsButton);
  50847. removeChildComponent (behindFrontTab);
  50848. deleteAllChildren();
  50849. addChildComponent (behindFrontTab);
  50850. setCurrentTabIndex (-1);
  50851. }
  50852. void TabbedButtonBar::addTab (const String& tabName,
  50853. const Colour& tabBackgroundColour,
  50854. int insertIndex)
  50855. {
  50856. jassert (tabName.isNotEmpty()); // you have to give them all a name..
  50857. if (tabName.isNotEmpty())
  50858. {
  50859. if (((unsigned int) insertIndex) > (unsigned int) tabs.size())
  50860. insertIndex = tabs.size();
  50861. for (int i = tabs.size(); --i >= insertIndex;)
  50862. {
  50863. TabBarButton* const tb = getTabButton (i);
  50864. if (tb != 0)
  50865. tb->tabIndex++;
  50866. }
  50867. tabs.insert (insertIndex, tabName);
  50868. tabColours.insert (insertIndex, tabBackgroundColour);
  50869. TabBarButton* const tb = createTabButton (tabName, insertIndex);
  50870. jassert (tb != 0); // your createTabButton() mustn't return zero!
  50871. addAndMakeVisible (tb, insertIndex);
  50872. resized();
  50873. if (currentTabIndex < 0)
  50874. setCurrentTabIndex (0);
  50875. }
  50876. }
  50877. void TabbedButtonBar::setTabName (const int tabIndex,
  50878. const String& newName)
  50879. {
  50880. if (((unsigned int) tabIndex) < (unsigned int) tabs.size()
  50881. && tabs[tabIndex] != newName)
  50882. {
  50883. tabs.set (tabIndex, newName);
  50884. TabBarButton* const tb = getTabButton (tabIndex);
  50885. if (tb != 0)
  50886. tb->setButtonText (newName);
  50887. resized();
  50888. }
  50889. }
  50890. void TabbedButtonBar::removeTab (const int tabIndex)
  50891. {
  50892. if (((unsigned int) tabIndex) < (unsigned int) tabs.size())
  50893. {
  50894. const int oldTabIndex = currentTabIndex;
  50895. if (currentTabIndex == tabIndex)
  50896. currentTabIndex = -1;
  50897. tabs.remove (tabIndex);
  50898. tabColours.remove (tabIndex);
  50899. delete getTabButton (tabIndex);
  50900. for (int i = tabIndex + 1; i <= tabs.size(); ++i)
  50901. {
  50902. TabBarButton* const tb = getTabButton (i);
  50903. if (tb != 0)
  50904. tb->tabIndex--;
  50905. }
  50906. resized();
  50907. setCurrentTabIndex (jlimit (0, jmax (0, tabs.size() - 1), oldTabIndex));
  50908. }
  50909. }
  50910. void TabbedButtonBar::moveTab (const int currentIndex,
  50911. const int newIndex)
  50912. {
  50913. tabs.move (currentIndex, newIndex);
  50914. tabColours.move (currentIndex, newIndex);
  50915. resized();
  50916. }
  50917. int TabbedButtonBar::getNumTabs() const
  50918. {
  50919. return tabs.size();
  50920. }
  50921. const StringArray TabbedButtonBar::getTabNames() const
  50922. {
  50923. return tabs;
  50924. }
  50925. void TabbedButtonBar::setCurrentTabIndex (int newIndex, const bool sendChangeMessage_)
  50926. {
  50927. if (currentTabIndex != newIndex)
  50928. {
  50929. if (((unsigned int) newIndex) >= (unsigned int) tabs.size())
  50930. newIndex = -1;
  50931. currentTabIndex = newIndex;
  50932. for (int i = 0; i < getNumChildComponents(); ++i)
  50933. {
  50934. TabBarButton* const tb = dynamic_cast <TabBarButton*> (getChildComponent (i));
  50935. if (tb != 0)
  50936. tb->setToggleState (tb->tabIndex == newIndex, false);
  50937. }
  50938. resized();
  50939. if (sendChangeMessage_)
  50940. sendChangeMessage (this);
  50941. currentTabChanged (newIndex, newIndex >= 0 ? tabs [newIndex] : String::empty);
  50942. }
  50943. }
  50944. TabBarButton* TabbedButtonBar::getTabButton (const int index) const
  50945. {
  50946. for (int i = getNumChildComponents(); --i >= 0;)
  50947. {
  50948. TabBarButton* const tb = dynamic_cast <TabBarButton*> (getChildComponent (i));
  50949. if (tb != 0 && tb->tabIndex == index)
  50950. return tb;
  50951. }
  50952. return 0;
  50953. }
  50954. void TabbedButtonBar::lookAndFeelChanged()
  50955. {
  50956. deleteAndZero (extraTabsButton);
  50957. resized();
  50958. }
  50959. void TabbedButtonBar::resized()
  50960. {
  50961. const double minimumScale = 0.7;
  50962. int depth = getWidth();
  50963. int length = getHeight();
  50964. if (orientation == TabsAtTop || orientation == TabsAtBottom)
  50965. swapVariables (depth, length);
  50966. const int overlap = getLookAndFeel().getTabButtonOverlap (depth)
  50967. + getLookAndFeel().getTabButtonSpaceAroundImage() * 2;
  50968. int i, totalLength = overlap;
  50969. int numVisibleButtons = tabs.size();
  50970. for (i = 0; i < getNumChildComponents(); ++i)
  50971. {
  50972. TabBarButton* const tb = dynamic_cast <TabBarButton*> (getChildComponent (i));
  50973. if (tb != 0)
  50974. {
  50975. totalLength += tb->getBestTabLength (depth) - overlap;
  50976. tb->overlapPixels = overlap / 2;
  50977. }
  50978. }
  50979. double scale = 1.0;
  50980. if (totalLength > length)
  50981. scale = jmax (minimumScale, length / (double) totalLength);
  50982. const bool isTooBig = totalLength * scale > length;
  50983. int tabsButtonPos = 0;
  50984. if (isTooBig)
  50985. {
  50986. if (extraTabsButton == 0)
  50987. {
  50988. addAndMakeVisible (extraTabsButton = getLookAndFeel().createTabBarExtrasButton());
  50989. extraTabsButton->addButtonListener (this);
  50990. extraTabsButton->setAlwaysOnTop (true);
  50991. extraTabsButton->setTriggeredOnMouseDown (true);
  50992. }
  50993. const int buttonSize = jmin (proportionOfWidth (0.7f), proportionOfHeight (0.7f));
  50994. extraTabsButton->setSize (buttonSize, buttonSize);
  50995. if (orientation == TabsAtTop || orientation == TabsAtBottom)
  50996. {
  50997. tabsButtonPos = getWidth() - buttonSize / 2 - 1;
  50998. extraTabsButton->setCentrePosition (tabsButtonPos, getHeight() / 2);
  50999. }
  51000. else
  51001. {
  51002. tabsButtonPos = getHeight() - buttonSize / 2 - 1;
  51003. extraTabsButton->setCentrePosition (getWidth() / 2, tabsButtonPos);
  51004. }
  51005. totalLength = 0;
  51006. for (i = 0; i < tabs.size(); ++i)
  51007. {
  51008. TabBarButton* const tb = getTabButton (i);
  51009. if (tb != 0)
  51010. {
  51011. const int newLength = totalLength + tb->getBestTabLength (depth);
  51012. if (i > 0 && newLength * minimumScale > tabsButtonPos)
  51013. {
  51014. totalLength += overlap;
  51015. break;
  51016. }
  51017. numVisibleButtons = i + 1;
  51018. totalLength = newLength - overlap;
  51019. }
  51020. }
  51021. scale = jmax (minimumScale, tabsButtonPos / (double) totalLength);
  51022. }
  51023. else
  51024. {
  51025. deleteAndZero (extraTabsButton);
  51026. }
  51027. int pos = 0;
  51028. TabBarButton* frontTab = 0;
  51029. for (i = 0; i < tabs.size(); ++i)
  51030. {
  51031. TabBarButton* const tb = getTabButton (i);
  51032. if (tb != 0)
  51033. {
  51034. const int bestLength = roundToInt (scale * tb->getBestTabLength (depth));
  51035. if (i < numVisibleButtons)
  51036. {
  51037. if (orientation == TabsAtTop || orientation == TabsAtBottom)
  51038. tb->setBounds (pos, 0, bestLength, getHeight());
  51039. else
  51040. tb->setBounds (0, pos, getWidth(), bestLength);
  51041. tb->toBack();
  51042. if (tb->tabIndex == currentTabIndex)
  51043. frontTab = tb;
  51044. tb->setVisible (true);
  51045. }
  51046. else
  51047. {
  51048. tb->setVisible (false);
  51049. }
  51050. pos += bestLength - overlap;
  51051. }
  51052. }
  51053. behindFrontTab->setBounds (0, 0, getWidth(), getHeight());
  51054. if (frontTab != 0)
  51055. {
  51056. frontTab->toFront (false);
  51057. behindFrontTab->toBehind (frontTab);
  51058. }
  51059. }
  51060. const Colour TabbedButtonBar::getTabBackgroundColour (const int tabIndex)
  51061. {
  51062. return tabColours [tabIndex];
  51063. }
  51064. void TabbedButtonBar::setTabBackgroundColour (const int tabIndex, const Colour& newColour)
  51065. {
  51066. if (((unsigned int) tabIndex) < (unsigned int) tabColours.size()
  51067. && tabColours [tabIndex] != newColour)
  51068. {
  51069. tabColours.set (tabIndex, newColour);
  51070. repaint();
  51071. }
  51072. }
  51073. void TabbedButtonBar::buttonClicked (Button* button)
  51074. {
  51075. if (extraTabsButton == button)
  51076. {
  51077. PopupMenu m;
  51078. for (int i = 0; i < tabs.size(); ++i)
  51079. {
  51080. TabBarButton* const tb = getTabButton (i);
  51081. if (tb != 0 && ! tb->isVisible())
  51082. m.addItem (tb->tabIndex + 1, tabs[i], true, i == currentTabIndex);
  51083. }
  51084. const int res = m.showAt (extraTabsButton);
  51085. if (res != 0)
  51086. setCurrentTabIndex (res - 1);
  51087. }
  51088. }
  51089. void TabbedButtonBar::currentTabChanged (const int, const String&)
  51090. {
  51091. }
  51092. void TabbedButtonBar::popupMenuClickOnTab (const int, const String&)
  51093. {
  51094. }
  51095. END_JUCE_NAMESPACE
  51096. /********* End of inlined file: juce_TabbedButtonBar.cpp *********/
  51097. /********* Start of inlined file: juce_TabbedComponent.cpp *********/
  51098. BEGIN_JUCE_NAMESPACE
  51099. class TabCompButtonBar : public TabbedButtonBar
  51100. {
  51101. public:
  51102. TabCompButtonBar (TabbedComponent* const owner_,
  51103. const TabbedButtonBar::Orientation orientation)
  51104. : TabbedButtonBar (orientation),
  51105. owner (owner_)
  51106. {
  51107. }
  51108. ~TabCompButtonBar()
  51109. {
  51110. }
  51111. void currentTabChanged (const int newCurrentTabIndex,
  51112. const String& newTabName)
  51113. {
  51114. owner->changeCallback (newCurrentTabIndex, newTabName);
  51115. }
  51116. void popupMenuClickOnTab (const int tabIndex,
  51117. const String& tabName)
  51118. {
  51119. owner->popupMenuClickOnTab (tabIndex, tabName);
  51120. }
  51121. const Colour getTabBackgroundColour (const int tabIndex)
  51122. {
  51123. return owner->tabs->getTabBackgroundColour (tabIndex);
  51124. }
  51125. TabBarButton* createTabButton (const String& tabName, const int tabIndex)
  51126. {
  51127. return owner->createTabButton (tabName, tabIndex);
  51128. }
  51129. juce_UseDebuggingNewOperator
  51130. private:
  51131. TabbedComponent* const owner;
  51132. TabCompButtonBar (const TabCompButtonBar&);
  51133. const TabCompButtonBar& operator= (const TabCompButtonBar&);
  51134. };
  51135. TabbedComponent::TabbedComponent (const TabbedButtonBar::Orientation orientation)
  51136. : panelComponent (0),
  51137. tabDepth (30),
  51138. outlineThickness (1),
  51139. edgeIndent (0)
  51140. {
  51141. addAndMakeVisible (tabs = new TabCompButtonBar (this, orientation));
  51142. }
  51143. TabbedComponent::~TabbedComponent()
  51144. {
  51145. clearTabs();
  51146. delete tabs;
  51147. }
  51148. void TabbedComponent::setOrientation (const TabbedButtonBar::Orientation orientation)
  51149. {
  51150. tabs->setOrientation (orientation);
  51151. resized();
  51152. }
  51153. TabbedButtonBar::Orientation TabbedComponent::getOrientation() const throw()
  51154. {
  51155. return tabs->getOrientation();
  51156. }
  51157. void TabbedComponent::setTabBarDepth (const int newDepth)
  51158. {
  51159. if (tabDepth != newDepth)
  51160. {
  51161. tabDepth = newDepth;
  51162. resized();
  51163. }
  51164. }
  51165. TabBarButton* TabbedComponent::createTabButton (const String& tabName, const int tabIndex)
  51166. {
  51167. return new TabBarButton (tabName, tabs, tabIndex);
  51168. }
  51169. void TabbedComponent::clearTabs()
  51170. {
  51171. if (panelComponent != 0)
  51172. {
  51173. panelComponent->setVisible (false);
  51174. removeChildComponent (panelComponent);
  51175. panelComponent = 0;
  51176. }
  51177. tabs->clearTabs();
  51178. for (int i = contentComponents.size(); --i >= 0;)
  51179. {
  51180. Component* const c = contentComponents.getUnchecked(i);
  51181. // be careful not to delete these components until they've been removed from the tab component
  51182. jassert (c == 0 || c->isValidComponent());
  51183. if (c != 0 && c->getComponentPropertyBool (T("deleteByTabComp_"), false, false))
  51184. delete c;
  51185. }
  51186. contentComponents.clear();
  51187. }
  51188. void TabbedComponent::addTab (const String& tabName,
  51189. const Colour& tabBackgroundColour,
  51190. Component* const contentComponent,
  51191. const bool deleteComponentWhenNotNeeded,
  51192. const int insertIndex)
  51193. {
  51194. contentComponents.insert (insertIndex, contentComponent);
  51195. if (contentComponent != 0)
  51196. contentComponent->setComponentProperty (T("deleteByTabComp_"), deleteComponentWhenNotNeeded);
  51197. tabs->addTab (tabName, tabBackgroundColour, insertIndex);
  51198. }
  51199. void TabbedComponent::setTabName (const int tabIndex,
  51200. const String& newName)
  51201. {
  51202. tabs->setTabName (tabIndex, newName);
  51203. }
  51204. void TabbedComponent::removeTab (const int tabIndex)
  51205. {
  51206. Component* const c = contentComponents [tabIndex];
  51207. if (c != 0 && c->getComponentPropertyBool (T("deleteByTabComp_"), false, false))
  51208. {
  51209. if (c == panelComponent)
  51210. panelComponent = 0;
  51211. delete c;
  51212. }
  51213. contentComponents.remove (tabIndex);
  51214. tabs->removeTab (tabIndex);
  51215. }
  51216. int TabbedComponent::getNumTabs() const
  51217. {
  51218. return tabs->getNumTabs();
  51219. }
  51220. const StringArray TabbedComponent::getTabNames() const
  51221. {
  51222. return tabs->getTabNames();
  51223. }
  51224. Component* TabbedComponent::getTabContentComponent (const int tabIndex) const throw()
  51225. {
  51226. return contentComponents [tabIndex];
  51227. }
  51228. const Colour TabbedComponent::getTabBackgroundColour (const int tabIndex) const throw()
  51229. {
  51230. return tabs->getTabBackgroundColour (tabIndex);
  51231. }
  51232. void TabbedComponent::setTabBackgroundColour (const int tabIndex, const Colour& newColour)
  51233. {
  51234. tabs->setTabBackgroundColour (tabIndex, newColour);
  51235. if (getCurrentTabIndex() == tabIndex)
  51236. repaint();
  51237. }
  51238. void TabbedComponent::setCurrentTabIndex (const int newTabIndex, const bool sendChangeMessage)
  51239. {
  51240. tabs->setCurrentTabIndex (newTabIndex, sendChangeMessage);
  51241. }
  51242. int TabbedComponent::getCurrentTabIndex() const
  51243. {
  51244. return tabs->getCurrentTabIndex();
  51245. }
  51246. const String& TabbedComponent::getCurrentTabName() const
  51247. {
  51248. return tabs->getCurrentTabName();
  51249. }
  51250. void TabbedComponent::setOutline (int thickness)
  51251. {
  51252. outlineThickness = thickness;
  51253. repaint();
  51254. }
  51255. void TabbedComponent::setIndent (const int indentThickness)
  51256. {
  51257. edgeIndent = indentThickness;
  51258. }
  51259. void TabbedComponent::paint (Graphics& g)
  51260. {
  51261. g.fillAll (findColour (backgroundColourId));
  51262. const TabbedButtonBar::Orientation o = getOrientation();
  51263. int x = 0;
  51264. int y = 0;
  51265. int r = getWidth();
  51266. int b = getHeight();
  51267. if (o == TabbedButtonBar::TabsAtTop)
  51268. y += tabDepth;
  51269. else if (o == TabbedButtonBar::TabsAtBottom)
  51270. b -= tabDepth;
  51271. else if (o == TabbedButtonBar::TabsAtLeft)
  51272. x += tabDepth;
  51273. else if (o == TabbedButtonBar::TabsAtRight)
  51274. r -= tabDepth;
  51275. g.reduceClipRegion (x, y, r - x, b - y);
  51276. g.fillAll (tabs->getTabBackgroundColour (getCurrentTabIndex()));
  51277. if (outlineThickness > 0)
  51278. {
  51279. if (o == TabbedButtonBar::TabsAtTop)
  51280. --y;
  51281. else if (o == TabbedButtonBar::TabsAtBottom)
  51282. ++b;
  51283. else if (o == TabbedButtonBar::TabsAtLeft)
  51284. --x;
  51285. else if (o == TabbedButtonBar::TabsAtRight)
  51286. ++r;
  51287. g.setColour (findColour (outlineColourId));
  51288. g.drawRect (x, y, r - x, b - y, outlineThickness);
  51289. }
  51290. }
  51291. void TabbedComponent::resized()
  51292. {
  51293. const TabbedButtonBar::Orientation o = getOrientation();
  51294. const int indent = edgeIndent + outlineThickness;
  51295. BorderSize indents (indent);
  51296. if (o == TabbedButtonBar::TabsAtTop)
  51297. {
  51298. tabs->setBounds (0, 0, getWidth(), tabDepth);
  51299. indents.setTop (tabDepth + edgeIndent);
  51300. }
  51301. else if (o == TabbedButtonBar::TabsAtBottom)
  51302. {
  51303. tabs->setBounds (0, getHeight() - tabDepth, getWidth(), tabDepth);
  51304. indents.setBottom (tabDepth + edgeIndent);
  51305. }
  51306. else if (o == TabbedButtonBar::TabsAtLeft)
  51307. {
  51308. tabs->setBounds (0, 0, tabDepth, getHeight());
  51309. indents.setLeft (tabDepth + edgeIndent);
  51310. }
  51311. else if (o == TabbedButtonBar::TabsAtRight)
  51312. {
  51313. tabs->setBounds (getWidth() - tabDepth, 0, tabDepth, getHeight());
  51314. indents.setRight (tabDepth + edgeIndent);
  51315. }
  51316. const Rectangle bounds (indents.subtractedFrom (Rectangle (0, 0, getWidth(), getHeight())));
  51317. for (int i = contentComponents.size(); --i >= 0;)
  51318. if (contentComponents.getUnchecked (i) != 0)
  51319. contentComponents.getUnchecked (i)->setBounds (bounds);
  51320. }
  51321. void TabbedComponent::lookAndFeelChanged()
  51322. {
  51323. for (int i = contentComponents.size(); --i >= 0;)
  51324. if (contentComponents.getUnchecked (i) != 0)
  51325. contentComponents.getUnchecked (i)->lookAndFeelChanged();
  51326. }
  51327. void TabbedComponent::changeCallback (const int newCurrentTabIndex,
  51328. const String& newTabName)
  51329. {
  51330. if (panelComponent != 0)
  51331. {
  51332. panelComponent->setVisible (false);
  51333. removeChildComponent (panelComponent);
  51334. panelComponent = 0;
  51335. }
  51336. if (getCurrentTabIndex() >= 0)
  51337. {
  51338. panelComponent = contentComponents [getCurrentTabIndex()];
  51339. if (panelComponent != 0)
  51340. {
  51341. // do these ops as two stages instead of addAndMakeVisible() so that the
  51342. // component has always got a parent when it gets the visibilityChanged() callback
  51343. addChildComponent (panelComponent);
  51344. panelComponent->setVisible (true);
  51345. panelComponent->toFront (true);
  51346. }
  51347. repaint();
  51348. }
  51349. resized();
  51350. currentTabChanged (newCurrentTabIndex, newTabName);
  51351. }
  51352. void TabbedComponent::currentTabChanged (const int, const String&)
  51353. {
  51354. }
  51355. void TabbedComponent::popupMenuClickOnTab (const int, const String&)
  51356. {
  51357. }
  51358. END_JUCE_NAMESPACE
  51359. /********* End of inlined file: juce_TabbedComponent.cpp *********/
  51360. /********* Start of inlined file: juce_Viewport.cpp *********/
  51361. BEGIN_JUCE_NAMESPACE
  51362. Viewport::Viewport (const String& componentName)
  51363. : Component (componentName),
  51364. contentComp (0),
  51365. lastVX (0),
  51366. lastVY (0),
  51367. lastVW (0),
  51368. lastVH (0),
  51369. scrollBarThickness (0),
  51370. singleStepX (16),
  51371. singleStepY (16),
  51372. showHScrollbar (true),
  51373. showVScrollbar (true)
  51374. {
  51375. // content holder is used to clip the contents so they don't overlap the scrollbars
  51376. addAndMakeVisible (contentHolder = new Component());
  51377. contentHolder->setInterceptsMouseClicks (false, true);
  51378. verticalScrollBar = new ScrollBar (true);
  51379. horizontalScrollBar = new ScrollBar (false);
  51380. addChildComponent (verticalScrollBar);
  51381. addChildComponent (horizontalScrollBar);
  51382. verticalScrollBar->addListener (this);
  51383. horizontalScrollBar->addListener (this);
  51384. setInterceptsMouseClicks (false, true);
  51385. setWantsKeyboardFocus (true);
  51386. }
  51387. Viewport::~Viewport()
  51388. {
  51389. contentHolder->deleteAllChildren();
  51390. deleteAllChildren();
  51391. }
  51392. void Viewport::visibleAreaChanged (int, int, int, int)
  51393. {
  51394. }
  51395. void Viewport::setViewedComponent (Component* const newViewedComponent)
  51396. {
  51397. if (contentComp != newViewedComponent)
  51398. {
  51399. if (contentComp->isValidComponent())
  51400. {
  51401. Component* const oldComp = contentComp;
  51402. contentComp = 0;
  51403. delete oldComp;
  51404. }
  51405. contentComp = newViewedComponent;
  51406. if (contentComp != 0)
  51407. {
  51408. contentComp->setTopLeftPosition (0, 0);
  51409. contentHolder->addAndMakeVisible (contentComp);
  51410. contentComp->addComponentListener (this);
  51411. }
  51412. updateVisibleRegion();
  51413. }
  51414. }
  51415. int Viewport::getMaximumVisibleWidth() const throw()
  51416. {
  51417. return jmax (0, getWidth() - (verticalScrollBar->isVisible() ? getScrollBarThickness() : 0));
  51418. }
  51419. int Viewport::getMaximumVisibleHeight() const throw()
  51420. {
  51421. return jmax (0, getHeight() - (horizontalScrollBar->isVisible() ? getScrollBarThickness() : 0));
  51422. }
  51423. void Viewport::setViewPosition (const int xPixelsOffset,
  51424. const int yPixelsOffset)
  51425. {
  51426. if (contentComp != 0)
  51427. contentComp->setTopLeftPosition (-xPixelsOffset,
  51428. -yPixelsOffset);
  51429. }
  51430. void Viewport::setViewPositionProportionately (const double x,
  51431. const double y)
  51432. {
  51433. if (contentComp != 0)
  51434. setViewPosition (jmax (0, roundToInt (x * (contentComp->getWidth() - getWidth()))),
  51435. jmax (0, roundToInt (y * (contentComp->getHeight() - getHeight()))));
  51436. }
  51437. bool Viewport::autoScroll (int mouseX, int mouseY, int activeBorderThickness, int maximumSpeed)
  51438. {
  51439. if (contentComp != 0)
  51440. {
  51441. int dx = 0, dy = 0;
  51442. if (mouseX < activeBorderThickness)
  51443. dx = activeBorderThickness - mouseX;
  51444. else if (mouseX >= contentHolder->getWidth() - activeBorderThickness)
  51445. dx = (contentHolder->getWidth() - activeBorderThickness) - mouseX;
  51446. if (dx < 0)
  51447. dx = jmax (dx, -maximumSpeed, contentHolder->getWidth() - contentComp->getRight());
  51448. else
  51449. dx = jmin (dx, maximumSpeed, -contentComp->getX());
  51450. if (mouseY < activeBorderThickness)
  51451. dy = activeBorderThickness - mouseY;
  51452. else if (mouseY >= contentHolder->getHeight() - activeBorderThickness)
  51453. dy = (contentHolder->getHeight() - activeBorderThickness) - mouseY;
  51454. if (dy < 0)
  51455. dy = jmax (dy, -maximumSpeed, contentHolder->getHeight() - contentComp->getBottom());
  51456. else
  51457. dy = jmin (dy, maximumSpeed, -contentComp->getY());
  51458. if (dx != 0 || dy != 0)
  51459. {
  51460. contentComp->setTopLeftPosition (contentComp->getX() + dx,
  51461. contentComp->getY() + dy);
  51462. return true;
  51463. }
  51464. }
  51465. return false;
  51466. }
  51467. void Viewport::componentMovedOrResized (Component&, bool, bool)
  51468. {
  51469. updateVisibleRegion();
  51470. }
  51471. void Viewport::resized()
  51472. {
  51473. updateVisibleRegion();
  51474. }
  51475. void Viewport::updateVisibleRegion()
  51476. {
  51477. if (contentComp != 0)
  51478. {
  51479. const int newVX = -contentComp->getX();
  51480. const int newVY = -contentComp->getY();
  51481. if (newVX == 0 && newVY == 0
  51482. && contentComp->getWidth() <= getWidth()
  51483. && contentComp->getHeight() <= getHeight())
  51484. {
  51485. horizontalScrollBar->setVisible (false);
  51486. verticalScrollBar->setVisible (false);
  51487. }
  51488. horizontalScrollBar->setRangeLimits (0.0, contentComp->getWidth());
  51489. horizontalScrollBar->setCurrentRange (newVX, getMaximumVisibleWidth());
  51490. horizontalScrollBar->setSingleStepSize (singleStepX);
  51491. if (! (contentComp->getWidth() > 0 && showHScrollbar && getHeight() > getScrollBarThickness()))
  51492. horizontalScrollBar->setVisible (false);
  51493. verticalScrollBar->setRangeLimits (0.0, contentComp->getHeight());
  51494. verticalScrollBar->setCurrentRange (newVY, getMaximumVisibleHeight());
  51495. verticalScrollBar->setSingleStepSize (singleStepY);
  51496. if (! (contentComp->getHeight() > 0 && showVScrollbar && getWidth() > getScrollBarThickness()))
  51497. verticalScrollBar->setVisible (false);
  51498. if (verticalScrollBar->isVisible())
  51499. {
  51500. horizontalScrollBar->setCurrentRange (newVX, getMaximumVisibleWidth());
  51501. verticalScrollBar->setCurrentRange (newVY, getMaximumVisibleHeight());
  51502. verticalScrollBar
  51503. ->setBounds (getMaximumVisibleWidth(), 0,
  51504. getScrollBarThickness(), getMaximumVisibleHeight());
  51505. }
  51506. if (horizontalScrollBar->isVisible())
  51507. {
  51508. horizontalScrollBar->setCurrentRange (newVX, getMaximumVisibleWidth());
  51509. horizontalScrollBar
  51510. ->setBounds (0, getMaximumVisibleHeight(),
  51511. getMaximumVisibleWidth(), getScrollBarThickness());
  51512. }
  51513. contentHolder->setSize (getMaximumVisibleWidth(),
  51514. getMaximumVisibleHeight());
  51515. const int newVW = jmin (contentComp->getRight(), getMaximumVisibleWidth());
  51516. const int newVH = jmin (contentComp->getBottom(), getMaximumVisibleHeight());
  51517. if (newVX != lastVX
  51518. || newVY != lastVY
  51519. || newVW != lastVW
  51520. || newVH != lastVH)
  51521. {
  51522. lastVX = newVX;
  51523. lastVY = newVY;
  51524. lastVW = newVW;
  51525. lastVH = newVH;
  51526. visibleAreaChanged (newVX, newVY, newVW, newVH);
  51527. }
  51528. horizontalScrollBar->handleUpdateNowIfNeeded();
  51529. verticalScrollBar->handleUpdateNowIfNeeded();
  51530. }
  51531. else
  51532. {
  51533. horizontalScrollBar->setVisible (false);
  51534. verticalScrollBar->setVisible (false);
  51535. }
  51536. }
  51537. void Viewport::setSingleStepSizes (const int stepX,
  51538. const int stepY)
  51539. {
  51540. singleStepX = stepX;
  51541. singleStepY = stepY;
  51542. updateVisibleRegion();
  51543. }
  51544. void Viewport::setScrollBarsShown (const bool showVerticalScrollbarIfNeeded,
  51545. const bool showHorizontalScrollbarIfNeeded)
  51546. {
  51547. showVScrollbar = showVerticalScrollbarIfNeeded;
  51548. showHScrollbar = showHorizontalScrollbarIfNeeded;
  51549. updateVisibleRegion();
  51550. }
  51551. void Viewport::setScrollBarThickness (const int thickness)
  51552. {
  51553. scrollBarThickness = thickness;
  51554. updateVisibleRegion();
  51555. }
  51556. int Viewport::getScrollBarThickness() const throw()
  51557. {
  51558. return (scrollBarThickness > 0) ? scrollBarThickness
  51559. : getLookAndFeel().getDefaultScrollbarWidth();
  51560. }
  51561. void Viewport::setScrollBarButtonVisibility (const bool buttonsVisible)
  51562. {
  51563. verticalScrollBar->setButtonVisibility (buttonsVisible);
  51564. horizontalScrollBar->setButtonVisibility (buttonsVisible);
  51565. }
  51566. void Viewport::scrollBarMoved (ScrollBar* scrollBarThatHasMoved, const double newRangeStart)
  51567. {
  51568. if (scrollBarThatHasMoved == horizontalScrollBar)
  51569. {
  51570. setViewPosition (roundToInt (newRangeStart), getViewPositionY());
  51571. }
  51572. else if (scrollBarThatHasMoved == verticalScrollBar)
  51573. {
  51574. setViewPosition (getViewPositionX(), roundToInt (newRangeStart));
  51575. }
  51576. }
  51577. void Viewport::mouseWheelMove (const MouseEvent& e, float wheelIncrementX, float wheelIncrementY)
  51578. {
  51579. if (! useMouseWheelMoveIfNeeded (e, wheelIncrementX, wheelIncrementY))
  51580. Component::mouseWheelMove (e, wheelIncrementX, wheelIncrementY);
  51581. }
  51582. bool Viewport::useMouseWheelMoveIfNeeded (const MouseEvent& e, float wheelIncrementX, float wheelIncrementY)
  51583. {
  51584. if (! (e.mods.isAltDown() || e.mods.isCtrlDown()))
  51585. {
  51586. const bool hasVertBar = verticalScrollBar->isVisible();
  51587. const bool hasHorzBar = horizontalScrollBar->isVisible();
  51588. if (hasHorzBar && (wheelIncrementX != 0 || e.mods.isShiftDown() || ! hasVertBar))
  51589. {
  51590. if (wheelIncrementX == 0 && ! hasVertBar)
  51591. wheelIncrementX = wheelIncrementY;
  51592. horizontalScrollBar->mouseWheelMove (e.getEventRelativeTo (horizontalScrollBar),
  51593. wheelIncrementX, wheelIncrementY);
  51594. return true;
  51595. }
  51596. else if (hasVertBar && wheelIncrementY != 0)
  51597. {
  51598. verticalScrollBar->mouseWheelMove (e.getEventRelativeTo (verticalScrollBar),
  51599. wheelIncrementX, wheelIncrementY);
  51600. return true;
  51601. }
  51602. }
  51603. return false;
  51604. }
  51605. bool Viewport::keyPressed (const KeyPress& key)
  51606. {
  51607. const bool isUpDownKey = key.isKeyCode (KeyPress::upKey)
  51608. || key.isKeyCode (KeyPress::downKey)
  51609. || key.isKeyCode (KeyPress::pageUpKey)
  51610. || key.isKeyCode (KeyPress::pageDownKey)
  51611. || key.isKeyCode (KeyPress::homeKey)
  51612. || key.isKeyCode (KeyPress::endKey);
  51613. if (verticalScrollBar->isVisible() && isUpDownKey)
  51614. return verticalScrollBar->keyPressed (key);
  51615. const bool isLeftRightKey = key.isKeyCode (KeyPress::leftKey)
  51616. || key.isKeyCode (KeyPress::rightKey);
  51617. if (horizontalScrollBar->isVisible() && (isUpDownKey || isLeftRightKey))
  51618. return horizontalScrollBar->keyPressed (key);
  51619. return false;
  51620. }
  51621. END_JUCE_NAMESPACE
  51622. /********* End of inlined file: juce_Viewport.cpp *********/
  51623. /********* Start of inlined file: juce_LookAndFeel.cpp *********/
  51624. BEGIN_JUCE_NAMESPACE
  51625. static const Colour createBaseColour (const Colour& buttonColour,
  51626. const bool hasKeyboardFocus,
  51627. const bool isMouseOverButton,
  51628. const bool isButtonDown) throw()
  51629. {
  51630. const float sat = hasKeyboardFocus ? 1.3f : 0.9f;
  51631. const Colour baseColour (buttonColour.withMultipliedSaturation (sat));
  51632. if (isButtonDown)
  51633. return baseColour.contrasting (0.2f);
  51634. else if (isMouseOverButton)
  51635. return baseColour.contrasting (0.1f);
  51636. return baseColour;
  51637. }
  51638. static String defaultSansName, defaultSerifName, defaultFixedName;
  51639. void clearUpDefaultFontNames() throw()
  51640. {
  51641. defaultSansName = String::empty;
  51642. defaultSerifName = String::empty;
  51643. defaultFixedName = String::empty;
  51644. }
  51645. LookAndFeel::LookAndFeel()
  51646. {
  51647. /* if this fails it means you're trying to create a LookAndFeel object before
  51648. the static Colours have been initialised. That ain't gonna work. It probably
  51649. means that you're using a static LookAndFeel object and that your compiler has
  51650. decided to intialise it before the Colours class.
  51651. */
  51652. jassert (Colours::white == Colour (0xffffffff));
  51653. // set up the standard set of colours..
  51654. const int textButtonColour = 0xffbbbbff;
  51655. const int textHighlightColour = 0x401111ee;
  51656. const int standardOutlineColour = 0xb2808080;
  51657. static const int standardColours[] =
  51658. {
  51659. TextButton::buttonColourId, textButtonColour,
  51660. TextButton::buttonOnColourId, 0xff4444ff,
  51661. TextButton::textColourOnId, 0xff000000,
  51662. TextButton::textColourOffId, 0xff000000,
  51663. ComboBox::buttonColourId, 0xffbbbbff,
  51664. ComboBox::outlineColourId, standardOutlineColour,
  51665. ToggleButton::textColourId, 0xff000000,
  51666. TextEditor::backgroundColourId, 0xffffffff,
  51667. TextEditor::textColourId, 0xff000000,
  51668. TextEditor::highlightColourId, textHighlightColour,
  51669. TextEditor::highlightedTextColourId, 0xff000000,
  51670. TextEditor::caretColourId, 0xff000000,
  51671. TextEditor::outlineColourId, 0x00000000,
  51672. TextEditor::focusedOutlineColourId, textButtonColour,
  51673. TextEditor::shadowColourId, 0x38000000,
  51674. Label::backgroundColourId, 0x00000000,
  51675. Label::textColourId, 0xff000000,
  51676. Label::outlineColourId, 0x00000000,
  51677. ScrollBar::backgroundColourId, 0x00000000,
  51678. ScrollBar::thumbColourId, 0xffffffff,
  51679. ScrollBar::trackColourId, 0xffffffff,
  51680. TreeView::linesColourId, 0x4c000000,
  51681. TreeView::backgroundColourId, 0x00000000,
  51682. TreeView::dragAndDropIndicatorColourId, 0x80ff0000,
  51683. PopupMenu::backgroundColourId, 0xffffffff,
  51684. PopupMenu::textColourId, 0xff000000,
  51685. PopupMenu::headerTextColourId, 0xff000000,
  51686. PopupMenu::highlightedTextColourId, 0xffffffff,
  51687. PopupMenu::highlightedBackgroundColourId, 0x991111aa,
  51688. ComboBox::textColourId, 0xff000000,
  51689. ComboBox::backgroundColourId, 0xffffffff,
  51690. ComboBox::arrowColourId, 0x99000000,
  51691. ListBox::backgroundColourId, 0xffffffff,
  51692. ListBox::outlineColourId, standardOutlineColour,
  51693. ListBox::textColourId, 0xff000000,
  51694. Slider::backgroundColourId, 0x00000000,
  51695. Slider::thumbColourId, textButtonColour,
  51696. Slider::trackColourId, 0x7fffffff,
  51697. Slider::rotarySliderFillColourId, 0x7f0000ff,
  51698. Slider::rotarySliderOutlineColourId, 0x66000000,
  51699. Slider::textBoxTextColourId, 0xff000000,
  51700. Slider::textBoxBackgroundColourId, 0xffffffff,
  51701. Slider::textBoxHighlightColourId, textHighlightColour,
  51702. Slider::textBoxOutlineColourId, standardOutlineColour,
  51703. ResizableWindow::backgroundColourId, 0xff777777,
  51704. //DocumentWindow::textColourId, 0xff000000, // (this is deliberately not set)
  51705. AlertWindow::backgroundColourId, 0xffededed,
  51706. AlertWindow::textColourId, 0xff000000,
  51707. AlertWindow::outlineColourId, 0xff666666,
  51708. ProgressBar::backgroundColourId, 0xffeeeeee,
  51709. ProgressBar::foregroundColourId, 0xffaaaaee,
  51710. TooltipWindow::backgroundColourId, 0xffeeeebb,
  51711. TooltipWindow::textColourId, 0xff000000,
  51712. TooltipWindow::outlineColourId, 0x4c000000,
  51713. TabbedComponent::backgroundColourId, 0x00000000,
  51714. TabbedComponent::outlineColourId, 0xff777777,
  51715. TabbedButtonBar::tabOutlineColourId, 0x80000000,
  51716. TabbedButtonBar::frontOutlineColourId, 0x90000000,
  51717. Toolbar::backgroundColourId, 0xfff6f8f9,
  51718. Toolbar::separatorColourId, 0x4c000000,
  51719. Toolbar::buttonMouseOverBackgroundColourId, 0x4c0000ff,
  51720. Toolbar::buttonMouseDownBackgroundColourId, 0x800000ff,
  51721. Toolbar::labelTextColourId, 0xff000000,
  51722. Toolbar::editingModeOutlineColourId, 0xffff0000,
  51723. HyperlinkButton::textColourId, 0xcc1111ee,
  51724. GroupComponent::outlineColourId, 0x66000000,
  51725. GroupComponent::textColourId, 0xff000000,
  51726. DirectoryContentsDisplayComponent::highlightColourId, textHighlightColour,
  51727. DirectoryContentsDisplayComponent::textColourId, 0xff000000,
  51728. 0x1000440, /*LassoComponent::lassoFillColourId*/ 0x66dddddd,
  51729. 0x1000441, /*LassoComponent::lassoOutlineColourId*/ 0x99111111,
  51730. MidiKeyboardComponent::whiteNoteColourId, 0xffffffff,
  51731. MidiKeyboardComponent::blackNoteColourId, 0xff000000,
  51732. MidiKeyboardComponent::keySeparatorLineColourId, 0x66000000,
  51733. MidiKeyboardComponent::mouseOverKeyOverlayColourId, 0x80ffff00,
  51734. MidiKeyboardComponent::keyDownOverlayColourId, 0xffb6b600,
  51735. MidiKeyboardComponent::textLabelColourId, 0xff000000,
  51736. MidiKeyboardComponent::upDownButtonBackgroundColourId, 0xffd3d3d3,
  51737. MidiKeyboardComponent::upDownButtonArrowColourId, 0xff000000,
  51738. CodeEditorComponent::backgroundColourId, 0xffffffff,
  51739. CodeEditorComponent::caretColourId, 0xff000000,
  51740. CodeEditorComponent::highlightColourId, textHighlightColour,
  51741. CodeEditorComponent::defaultTextColourId, 0xff000000,
  51742. ColourSelector::backgroundColourId, 0xffe5e5e5,
  51743. ColourSelector::labelTextColourId, 0xff000000,
  51744. KeyMappingEditorComponent::backgroundColourId, 0x00000000,
  51745. KeyMappingEditorComponent::textColourId, 0xff000000,
  51746. FileSearchPathListComponent::backgroundColourId, 0xffffffff,
  51747. FileChooserDialogBox::titleTextColourId, 0xff000000,
  51748. };
  51749. for (int i = 0; i < numElementsInArray (standardColours); i += 2)
  51750. setColour (standardColours [i], Colour (standardColours [i + 1]));
  51751. if (defaultSansName.isEmpty())
  51752. Font::getPlatformDefaultFontNames (defaultSansName, defaultSerifName, defaultFixedName);
  51753. defaultSans = defaultSansName;
  51754. defaultSerif = defaultSerifName;
  51755. defaultFixed = defaultFixedName;
  51756. }
  51757. LookAndFeel::~LookAndFeel()
  51758. {
  51759. }
  51760. const Colour LookAndFeel::findColour (const int colourId) const throw()
  51761. {
  51762. const int index = colourIds.indexOf (colourId);
  51763. if (index >= 0)
  51764. return colours [index];
  51765. jassertfalse
  51766. return Colours::black;
  51767. }
  51768. void LookAndFeel::setColour (const int colourId, const Colour& colour) throw()
  51769. {
  51770. const int index = colourIds.indexOf (colourId);
  51771. if (index >= 0)
  51772. colours.set (index, colour);
  51773. colourIds.add (colourId);
  51774. colours.add (colour);
  51775. }
  51776. bool LookAndFeel::isColourSpecified (const int colourId) const throw()
  51777. {
  51778. return colourIds.contains (colourId);
  51779. }
  51780. static LookAndFeel* defaultLF = 0;
  51781. static LookAndFeel* currentDefaultLF = 0;
  51782. LookAndFeel& LookAndFeel::getDefaultLookAndFeel() throw()
  51783. {
  51784. // if this happens, your app hasn't initialised itself properly.. if you're
  51785. // trying to hack your own main() function, have a look at
  51786. // JUCEApplication::initialiseForGUI()
  51787. jassert (currentDefaultLF != 0);
  51788. return *currentDefaultLF;
  51789. }
  51790. void LookAndFeel::setDefaultLookAndFeel (LookAndFeel* newDefaultLookAndFeel) throw()
  51791. {
  51792. if (newDefaultLookAndFeel == 0)
  51793. {
  51794. if (defaultLF == 0)
  51795. defaultLF = new LookAndFeel();
  51796. newDefaultLookAndFeel = defaultLF;
  51797. }
  51798. currentDefaultLF = newDefaultLookAndFeel;
  51799. for (int i = Desktop::getInstance().getNumComponents(); --i >= 0;)
  51800. {
  51801. Component* const c = Desktop::getInstance().getComponent (i);
  51802. if (c != 0)
  51803. c->sendLookAndFeelChange();
  51804. }
  51805. }
  51806. void LookAndFeel::clearDefaultLookAndFeel() throw()
  51807. {
  51808. if (currentDefaultLF == defaultLF)
  51809. currentDefaultLF = 0;
  51810. deleteAndZero (defaultLF);
  51811. }
  51812. const Typeface::Ptr LookAndFeel::getTypefaceForFont (const Font& font)
  51813. {
  51814. String faceName (font.getTypefaceName());
  51815. if (faceName == Font::getDefaultSansSerifFontName())
  51816. faceName = defaultSans;
  51817. else if (faceName == Font::getDefaultSerifFontName())
  51818. faceName = defaultSerif;
  51819. else if (faceName == Font::getDefaultMonospacedFontName())
  51820. faceName = defaultFixed;
  51821. Font f (font);
  51822. f.setTypefaceName (faceName);
  51823. return Typeface::createSystemTypefaceFor (f);
  51824. }
  51825. void LookAndFeel::setDefaultSansSerifTypefaceName (const String& newName)
  51826. {
  51827. defaultSans = newName;
  51828. }
  51829. const MouseCursor LookAndFeel::getMouseCursorFor (Component& component)
  51830. {
  51831. return component.getMouseCursor();
  51832. }
  51833. void LookAndFeel::drawButtonBackground (Graphics& g,
  51834. Button& button,
  51835. const Colour& backgroundColour,
  51836. bool isMouseOverButton,
  51837. bool isButtonDown)
  51838. {
  51839. const int width = button.getWidth();
  51840. const int height = button.getHeight();
  51841. const float outlineThickness = button.isEnabled() ? ((isButtonDown || isMouseOverButton) ? 1.2f : 0.7f) : 0.4f;
  51842. const float halfThickness = outlineThickness * 0.5f;
  51843. const float indentL = button.isConnectedOnLeft() ? 0.1f : halfThickness;
  51844. const float indentR = button.isConnectedOnRight() ? 0.1f : halfThickness;
  51845. const float indentT = button.isConnectedOnTop() ? 0.1f : halfThickness;
  51846. const float indentB = button.isConnectedOnBottom() ? 0.1f : halfThickness;
  51847. const Colour baseColour (createBaseColour (backgroundColour,
  51848. button.hasKeyboardFocus (true),
  51849. isMouseOverButton, isButtonDown)
  51850. .withMultipliedAlpha (button.isEnabled() ? 1.0f : 0.5f));
  51851. drawGlassLozenge (g,
  51852. indentL,
  51853. indentT,
  51854. width - indentL - indentR,
  51855. height - indentT - indentB,
  51856. baseColour, outlineThickness, -1.0f,
  51857. button.isConnectedOnLeft(),
  51858. button.isConnectedOnRight(),
  51859. button.isConnectedOnTop(),
  51860. button.isConnectedOnBottom());
  51861. }
  51862. const Font LookAndFeel::getFontForTextButton (TextButton& button)
  51863. {
  51864. return button.getFont();
  51865. }
  51866. void LookAndFeel::drawButtonText (Graphics& g, TextButton& button,
  51867. bool /*isMouseOverButton*/, bool /*isButtonDown*/)
  51868. {
  51869. Font font (getFontForTextButton (button));
  51870. g.setFont (font);
  51871. g.setColour (button.findColour (button.getToggleState() ? TextButton::textColourOnId
  51872. : TextButton::textColourOffId)
  51873. .withMultipliedAlpha (button.isEnabled() ? 1.0f : 0.5f));
  51874. const int yIndent = jmin (4, button.proportionOfHeight (0.3f));
  51875. const int cornerSize = jmin (button.getHeight(), button.getWidth()) / 2;
  51876. const int fontHeight = roundToInt (font.getHeight() * 0.6f);
  51877. const int leftIndent = jmin (fontHeight, 2 + cornerSize / (button.isConnectedOnLeft() ? 4 : 2));
  51878. const int rightIndent = jmin (fontHeight, 2 + cornerSize / (button.isConnectedOnRight() ? 4 : 2));
  51879. g.drawFittedText (button.getButtonText(),
  51880. leftIndent,
  51881. yIndent,
  51882. button.getWidth() - leftIndent - rightIndent,
  51883. button.getHeight() - yIndent * 2,
  51884. Justification::centred, 2);
  51885. }
  51886. void LookAndFeel::drawTickBox (Graphics& g,
  51887. Component& component,
  51888. int x, int y, int w, int h,
  51889. const bool ticked,
  51890. const bool isEnabled,
  51891. const bool isMouseOverButton,
  51892. const bool isButtonDown)
  51893. {
  51894. const float boxSize = w * 0.7f;
  51895. drawGlassSphere (g, (float) x, y + (h - boxSize) * 0.5f, boxSize,
  51896. createBaseColour (component.findColour (TextButton::buttonColourId)
  51897. .withMultipliedAlpha (isEnabled ? 1.0f : 0.5f),
  51898. true,
  51899. isMouseOverButton,
  51900. isButtonDown),
  51901. isEnabled ? ((isButtonDown || isMouseOverButton) ? 1.1f : 0.5f) : 0.3f);
  51902. if (ticked)
  51903. {
  51904. Path tick;
  51905. tick.startNewSubPath (1.5f, 3.0f);
  51906. tick.lineTo (3.0f, 6.0f);
  51907. tick.lineTo (6.0f, 0.0f);
  51908. g.setColour (isEnabled ? Colours::black : Colours::grey);
  51909. const AffineTransform trans (AffineTransform::scale (w / 9.0f, h / 9.0f)
  51910. .translated ((float) x, (float) y));
  51911. g.strokePath (tick, PathStrokeType (2.5f), trans);
  51912. }
  51913. }
  51914. void LookAndFeel::drawToggleButton (Graphics& g,
  51915. ToggleButton& button,
  51916. bool isMouseOverButton,
  51917. bool isButtonDown)
  51918. {
  51919. if (button.hasKeyboardFocus (true))
  51920. {
  51921. g.setColour (button.findColour (TextEditor::focusedOutlineColourId));
  51922. g.drawRect (0, 0, button.getWidth(), button.getHeight());
  51923. }
  51924. const int tickWidth = jmin (20, button.getHeight() - 4);
  51925. drawTickBox (g, button, 4, (button.getHeight() - tickWidth) / 2,
  51926. tickWidth, tickWidth,
  51927. button.getToggleState(),
  51928. button.isEnabled(),
  51929. isMouseOverButton,
  51930. isButtonDown);
  51931. g.setColour (button.findColour (ToggleButton::textColourId));
  51932. g.setFont (jmin (15.0f, button.getHeight() * 0.6f));
  51933. if (! button.isEnabled())
  51934. g.setOpacity (0.5f);
  51935. const int textX = tickWidth + 5;
  51936. g.drawFittedText (button.getButtonText(),
  51937. textX, 4,
  51938. button.getWidth() - textX - 2, button.getHeight() - 8,
  51939. Justification::centredLeft, 10);
  51940. }
  51941. void LookAndFeel::changeToggleButtonWidthToFitText (ToggleButton& button)
  51942. {
  51943. Font font (jmin (15.0f, button.getHeight() * 0.6f));
  51944. const int tickWidth = jmin (24, button.getHeight());
  51945. button.setSize (font.getStringWidth (button.getButtonText()) + tickWidth + 8,
  51946. button.getHeight());
  51947. }
  51948. AlertWindow* LookAndFeel::createAlertWindow (const String& title,
  51949. const String& message,
  51950. const String& button1,
  51951. const String& button2,
  51952. const String& button3,
  51953. AlertWindow::AlertIconType iconType,
  51954. int numButtons,
  51955. Component* associatedComponent)
  51956. {
  51957. AlertWindow* aw = new AlertWindow (title, message, iconType, associatedComponent);
  51958. if (numButtons == 1)
  51959. {
  51960. aw->addButton (button1, 0,
  51961. KeyPress (KeyPress::escapeKey, 0, 0),
  51962. KeyPress (KeyPress::returnKey, 0, 0));
  51963. }
  51964. else
  51965. {
  51966. const KeyPress button1ShortCut (CharacterFunctions::toLowerCase (button1[0]), 0, 0);
  51967. KeyPress button2ShortCut (CharacterFunctions::toLowerCase (button2[0]), 0, 0);
  51968. if (button1ShortCut == button2ShortCut)
  51969. button2ShortCut = KeyPress();
  51970. if (numButtons == 2)
  51971. {
  51972. aw->addButton (button1, 1, KeyPress (KeyPress::returnKey, 0, 0), button1ShortCut);
  51973. aw->addButton (button2, 0, KeyPress (KeyPress::escapeKey, 0, 0), button2ShortCut);
  51974. }
  51975. else if (numButtons == 3)
  51976. {
  51977. aw->addButton (button1, 1, button1ShortCut);
  51978. aw->addButton (button2, 2, button2ShortCut);
  51979. aw->addButton (button3, 0, KeyPress (KeyPress::escapeKey, 0, 0));
  51980. }
  51981. }
  51982. return aw;
  51983. }
  51984. void LookAndFeel::drawAlertBox (Graphics& g,
  51985. AlertWindow& alert,
  51986. const Rectangle& textArea,
  51987. TextLayout& textLayout)
  51988. {
  51989. g.fillAll (alert.findColour (AlertWindow::backgroundColourId));
  51990. int iconSpaceUsed = 0;
  51991. Justification alignment (Justification::horizontallyCentred);
  51992. const int iconWidth = 80;
  51993. int iconSize = jmin (iconWidth + 50, alert.getHeight() + 20);
  51994. if (alert.containsAnyExtraComponents() || alert.getNumButtons() > 2)
  51995. iconSize = jmin (iconSize, textArea.getHeight() + 50);
  51996. const Rectangle iconRect (iconSize / -10, iconSize / -10,
  51997. iconSize, iconSize);
  51998. if (alert.getAlertType() != AlertWindow::NoIcon)
  51999. {
  52000. Path icon;
  52001. uint32 colour;
  52002. char character;
  52003. if (alert.getAlertType() == AlertWindow::WarningIcon)
  52004. {
  52005. colour = 0x55ff5555;
  52006. character = '!';
  52007. icon.addTriangle (iconRect.getX() + iconRect.getWidth() * 0.5f, (float) iconRect.getY(),
  52008. (float) iconRect.getRight(), (float) iconRect.getBottom(),
  52009. (float) iconRect.getX(), (float) iconRect.getBottom());
  52010. icon = icon.createPathWithRoundedCorners (5.0f);
  52011. }
  52012. else
  52013. {
  52014. colour = alert.getAlertType() == AlertWindow::InfoIcon ? 0x605555ff : 0x40b69900;
  52015. character = alert.getAlertType() == AlertWindow::InfoIcon ? 'i' : '?';
  52016. icon.addEllipse ((float) iconRect.getX(), (float) iconRect.getY(),
  52017. (float) iconRect.getWidth(), (float) iconRect.getHeight());
  52018. }
  52019. GlyphArrangement ga;
  52020. ga.addFittedText (Font (iconRect.getHeight() * 0.9f, Font::bold),
  52021. String::charToString (character),
  52022. (float) iconRect.getX(), (float) iconRect.getY(),
  52023. (float) iconRect.getWidth(), (float) iconRect.getHeight(),
  52024. Justification::centred, false);
  52025. ga.createPath (icon);
  52026. icon.setUsingNonZeroWinding (false);
  52027. g.setColour (Colour (colour));
  52028. g.fillPath (icon);
  52029. iconSpaceUsed = iconWidth;
  52030. alignment = Justification::left;
  52031. }
  52032. g.setColour (alert.findColour (AlertWindow::textColourId));
  52033. textLayout.drawWithin (g,
  52034. textArea.getX() + iconSpaceUsed, textArea.getY(),
  52035. textArea.getWidth() - iconSpaceUsed, textArea.getHeight(),
  52036. alignment.getFlags() | Justification::top);
  52037. g.setColour (alert.findColour (AlertWindow::outlineColourId));
  52038. g.drawRect (0, 0, alert.getWidth(), alert.getHeight());
  52039. }
  52040. int LookAndFeel::getAlertBoxWindowFlags()
  52041. {
  52042. return ComponentPeer::windowAppearsOnTaskbar
  52043. | ComponentPeer::windowHasDropShadow;
  52044. }
  52045. int LookAndFeel::getAlertWindowButtonHeight()
  52046. {
  52047. return 28;
  52048. }
  52049. const Font LookAndFeel::getAlertWindowFont()
  52050. {
  52051. return Font (12.0f);
  52052. }
  52053. void LookAndFeel::drawProgressBar (Graphics& g, ProgressBar& progressBar,
  52054. int width, int height,
  52055. double progress, const String& textToShow)
  52056. {
  52057. const Colour background (progressBar.findColour (ProgressBar::backgroundColourId));
  52058. const Colour foreground (progressBar.findColour (ProgressBar::foregroundColourId));
  52059. g.fillAll (background);
  52060. if (progress >= 0.0f && progress < 1.0f)
  52061. {
  52062. drawGlassLozenge (g, 1.0f, 1.0f,
  52063. (float) jlimit (0.0, width - 2.0, progress * (width - 2.0)),
  52064. (float) (height - 2),
  52065. foreground,
  52066. 0.5f, 0.0f,
  52067. true, true, true, true);
  52068. }
  52069. else
  52070. {
  52071. // spinning bar..
  52072. g.setColour (foreground);
  52073. const int stripeWidth = height * 2;
  52074. const int position = (Time::getMillisecondCounter() / 15) % stripeWidth;
  52075. Path p;
  52076. for (float x = (float) (- position); x < width + stripeWidth; x += stripeWidth)
  52077. p.addQuadrilateral (x, 0.0f,
  52078. x + stripeWidth * 0.5f, 0.0f,
  52079. x, (float) height,
  52080. x - stripeWidth * 0.5f, (float) height);
  52081. Image im (Image::ARGB, width, height, true);
  52082. {
  52083. Graphics g2 (im);
  52084. drawGlassLozenge (g2, 1.0f, 1.0f,
  52085. (float) (width - 2),
  52086. (float) (height - 2),
  52087. foreground,
  52088. 0.5f, 0.0f,
  52089. true, true, true, true);
  52090. }
  52091. g.setTiledImageFill (im, 0, 0, 0.85f);
  52092. g.fillPath (p);
  52093. }
  52094. if (textToShow.isNotEmpty())
  52095. {
  52096. g.setColour (Colour::contrasting (background, foreground));
  52097. g.setFont (height * 0.6f);
  52098. g.drawText (textToShow, 0, 0, width, height, Justification::centred, false);
  52099. }
  52100. }
  52101. void LookAndFeel::drawSpinningWaitAnimation (Graphics& g, const Colour& colour, int x, int y, int w, int h)
  52102. {
  52103. const float radius = jmin (w, h) * 0.4f;
  52104. const float thickness = radius * 0.15f;
  52105. Path p;
  52106. p.addRoundedRectangle (radius * 0.4f, thickness * -0.5f,
  52107. radius * 0.6f, thickness,
  52108. thickness * 0.5f);
  52109. const float cx = x + w * 0.5f;
  52110. const float cy = y + h * 0.5f;
  52111. const uint32 animationIndex = (Time::getMillisecondCounter() / (1000 / 10)) % 12;
  52112. for (int i = 0; i < 12; ++i)
  52113. {
  52114. const int n = (i + 12 - animationIndex) % 12;
  52115. g.setColour (colour.withMultipliedAlpha ((n + 1) / 12.0f));
  52116. g.fillPath (p, AffineTransform::rotation (i * (float_Pi / 6.0f))
  52117. .translated (cx, cy));
  52118. }
  52119. }
  52120. void LookAndFeel::drawScrollbarButton (Graphics& g,
  52121. ScrollBar& scrollbar,
  52122. int width, int height,
  52123. int buttonDirection,
  52124. bool /*isScrollbarVertical*/,
  52125. bool /*isMouseOverButton*/,
  52126. bool isButtonDown)
  52127. {
  52128. Path p;
  52129. if (buttonDirection == 0)
  52130. p.addTriangle (width * 0.5f, height * 0.2f,
  52131. width * 0.1f, height * 0.7f,
  52132. width * 0.9f, height * 0.7f);
  52133. else if (buttonDirection == 1)
  52134. p.addTriangle (width * 0.8f, height * 0.5f,
  52135. width * 0.3f, height * 0.1f,
  52136. width * 0.3f, height * 0.9f);
  52137. else if (buttonDirection == 2)
  52138. p.addTriangle (width * 0.5f, height * 0.8f,
  52139. width * 0.1f, height * 0.3f,
  52140. width * 0.9f, height * 0.3f);
  52141. else if (buttonDirection == 3)
  52142. p.addTriangle (width * 0.2f, height * 0.5f,
  52143. width * 0.7f, height * 0.1f,
  52144. width * 0.7f, height * 0.9f);
  52145. if (isButtonDown)
  52146. g.setColour (scrollbar.findColour (ScrollBar::thumbColourId).contrasting (0.2f));
  52147. else
  52148. g.setColour (scrollbar.findColour (ScrollBar::thumbColourId));
  52149. g.fillPath (p);
  52150. g.setColour (Colour (0x80000000));
  52151. g.strokePath (p, PathStrokeType (0.5f));
  52152. }
  52153. void LookAndFeel::drawScrollbar (Graphics& g,
  52154. ScrollBar& scrollbar,
  52155. int x, int y,
  52156. int width, int height,
  52157. bool isScrollbarVertical,
  52158. int thumbStartPosition,
  52159. int thumbSize,
  52160. bool /*isMouseOver*/,
  52161. bool /*isMouseDown*/)
  52162. {
  52163. g.fillAll (scrollbar.findColour (ScrollBar::backgroundColourId));
  52164. Path slotPath, thumbPath;
  52165. const float slotIndent = jmin (width, height) > 15 ? 1.0f : 0.0f;
  52166. const float slotIndentx2 = slotIndent * 2.0f;
  52167. const float thumbIndent = slotIndent + 1.0f;
  52168. const float thumbIndentx2 = thumbIndent * 2.0f;
  52169. float gx1 = 0.0f, gy1 = 0.0f, gx2 = 0.0f, gy2 = 0.0f;
  52170. if (isScrollbarVertical)
  52171. {
  52172. slotPath.addRoundedRectangle (x + slotIndent,
  52173. y + slotIndent,
  52174. width - slotIndentx2,
  52175. height - slotIndentx2,
  52176. (width - slotIndentx2) * 0.5f);
  52177. if (thumbSize > 0)
  52178. thumbPath.addRoundedRectangle (x + thumbIndent,
  52179. thumbStartPosition + thumbIndent,
  52180. width - thumbIndentx2,
  52181. thumbSize - thumbIndentx2,
  52182. (width - thumbIndentx2) * 0.5f);
  52183. gx1 = (float) x;
  52184. gx2 = x + width * 0.7f;
  52185. }
  52186. else
  52187. {
  52188. slotPath.addRoundedRectangle (x + slotIndent,
  52189. y + slotIndent,
  52190. width - slotIndentx2,
  52191. height - slotIndentx2,
  52192. (height - slotIndentx2) * 0.5f);
  52193. if (thumbSize > 0)
  52194. thumbPath.addRoundedRectangle (thumbStartPosition + thumbIndent,
  52195. y + thumbIndent,
  52196. thumbSize - thumbIndentx2,
  52197. height - thumbIndentx2,
  52198. (height - thumbIndentx2) * 0.5f);
  52199. gy1 = (float) y;
  52200. gy2 = y + height * 0.7f;
  52201. }
  52202. const Colour thumbColour (scrollbar.findColour (ScrollBar::thumbColourId));
  52203. g.setGradientFill (ColourGradient (thumbColour.overlaidWith (Colour (0x44000000)), gx1, gy1,
  52204. thumbColour.overlaidWith (Colour (0x19000000)), gx2, gy2, false));
  52205. g.fillPath (slotPath);
  52206. if (isScrollbarVertical)
  52207. {
  52208. gx1 = x + width * 0.6f;
  52209. gx2 = (float) x + width;
  52210. }
  52211. else
  52212. {
  52213. gy1 = y + height * 0.6f;
  52214. gy2 = (float) y + height;
  52215. }
  52216. g.setGradientFill (ColourGradient (Colours::transparentBlack,gx1, gy1,
  52217. Colour (0x19000000), gx2, gy2, false));
  52218. g.fillPath (slotPath);
  52219. g.setColour (thumbColour);
  52220. g.fillPath (thumbPath);
  52221. g.setGradientFill (ColourGradient (Colour (0x10000000), gx1, gy1,
  52222. Colours::transparentBlack, gx2, gy2, false));
  52223. g.saveState();
  52224. if (isScrollbarVertical)
  52225. g.reduceClipRegion (x + width / 2, y, width, height);
  52226. else
  52227. g.reduceClipRegion (x, y + height / 2, width, height);
  52228. g.fillPath (thumbPath);
  52229. g.restoreState();
  52230. g.setColour (Colour (0x4c000000));
  52231. g.strokePath (thumbPath, PathStrokeType (0.4f));
  52232. }
  52233. ImageEffectFilter* LookAndFeel::getScrollbarEffect()
  52234. {
  52235. return 0;
  52236. }
  52237. int LookAndFeel::getMinimumScrollbarThumbSize (ScrollBar& scrollbar)
  52238. {
  52239. return jmin (scrollbar.getWidth(), scrollbar.getHeight()) * 2;
  52240. }
  52241. int LookAndFeel::getDefaultScrollbarWidth()
  52242. {
  52243. return 18;
  52244. }
  52245. int LookAndFeel::getScrollbarButtonSize (ScrollBar& scrollbar)
  52246. {
  52247. return 2 + (scrollbar.isVertical() ? scrollbar.getWidth()
  52248. : scrollbar.getHeight());
  52249. }
  52250. const Path LookAndFeel::getTickShape (const float height)
  52251. {
  52252. static const unsigned char tickShapeData[] =
  52253. {
  52254. 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,
  52255. 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,
  52256. 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,
  52257. 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,
  52258. 96,140,68,0,128,188,67,0,224,168,68,0,0,119,67,99,101
  52259. };
  52260. Path p;
  52261. p.loadPathFromData (tickShapeData, sizeof (tickShapeData));
  52262. p.scaleToFit (0, 0, height * 2.0f, height, true);
  52263. return p;
  52264. }
  52265. const Path LookAndFeel::getCrossShape (const float height)
  52266. {
  52267. static const unsigned char crossShapeData[] =
  52268. {
  52269. 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,
  52270. 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,
  52271. 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,
  52272. 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,
  52273. 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,
  52274. 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,
  52275. 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
  52276. };
  52277. Path p;
  52278. p.loadPathFromData (crossShapeData, sizeof (crossShapeData));
  52279. p.scaleToFit (0, 0, height * 2.0f, height, true);
  52280. return p;
  52281. }
  52282. void LookAndFeel::drawTreeviewPlusMinusBox (Graphics& g, int x, int y, int w, int h, bool isPlus, bool /*isMouseOver*/)
  52283. {
  52284. const int boxSize = ((jmin (16, w, h) << 1) / 3) | 1;
  52285. x += (w - boxSize) >> 1;
  52286. y += (h - boxSize) >> 1;
  52287. w = boxSize;
  52288. h = boxSize;
  52289. g.setColour (Colour (0xe5ffffff));
  52290. g.fillRect (x, y, w, h);
  52291. g.setColour (Colour (0x80000000));
  52292. g.drawRect (x, y, w, h);
  52293. const float size = boxSize / 2 + 1.0f;
  52294. const float centre = (float) (boxSize / 2);
  52295. g.fillRect (x + (w - size) * 0.5f, y + centre, size, 1.0f);
  52296. if (isPlus)
  52297. g.fillRect (x + centre, y + (h - size) * 0.5f, 1.0f, size);
  52298. }
  52299. void LookAndFeel::drawBubble (Graphics& g,
  52300. float tipX, float tipY,
  52301. float boxX, float boxY,
  52302. float boxW, float boxH)
  52303. {
  52304. int side = 0;
  52305. if (tipX < boxX)
  52306. side = 1;
  52307. else if (tipX > boxX + boxW)
  52308. side = 3;
  52309. else if (tipY > boxY + boxH)
  52310. side = 2;
  52311. const float indent = 2.0f;
  52312. Path p;
  52313. p.addBubble (boxX + indent,
  52314. boxY + indent,
  52315. boxW - indent * 2.0f,
  52316. boxH - indent * 2.0f,
  52317. 5.0f,
  52318. tipX, tipY,
  52319. side,
  52320. 0.5f,
  52321. jmin (15.0f, boxW * 0.3f, boxH * 0.3f));
  52322. //xxx need to take comp as param for colour
  52323. g.setColour (findColour (TooltipWindow::backgroundColourId).withAlpha (0.9f));
  52324. g.fillPath (p);
  52325. //xxx as above
  52326. g.setColour (findColour (TooltipWindow::textColourId).withAlpha (0.4f));
  52327. g.strokePath (p, PathStrokeType (1.33f));
  52328. }
  52329. const Font LookAndFeel::getPopupMenuFont()
  52330. {
  52331. return Font (17.0f);
  52332. }
  52333. void LookAndFeel::getIdealPopupMenuItemSize (const String& text,
  52334. const bool isSeparator,
  52335. int standardMenuItemHeight,
  52336. int& idealWidth,
  52337. int& idealHeight)
  52338. {
  52339. if (isSeparator)
  52340. {
  52341. idealWidth = 50;
  52342. idealHeight = standardMenuItemHeight > 0 ? standardMenuItemHeight / 2 : 10;
  52343. }
  52344. else
  52345. {
  52346. Font font (getPopupMenuFont());
  52347. if (standardMenuItemHeight > 0 && font.getHeight() > standardMenuItemHeight / 1.3f)
  52348. font.setHeight (standardMenuItemHeight / 1.3f);
  52349. idealHeight = standardMenuItemHeight > 0 ? standardMenuItemHeight : roundToInt (font.getHeight() * 1.3f);
  52350. idealWidth = font.getStringWidth (text) + idealHeight * 2;
  52351. }
  52352. }
  52353. void LookAndFeel::drawPopupMenuBackground (Graphics& g, int width, int height)
  52354. {
  52355. const Colour background (findColour (PopupMenu::backgroundColourId));
  52356. g.fillAll (background);
  52357. g.setColour (background.overlaidWith (Colour (0x2badd8e6)));
  52358. for (int i = 0; i < height; i += 3)
  52359. g.fillRect (0, i, width, 1);
  52360. #if ! JUCE_MAC
  52361. g.setColour (findColour (PopupMenu::textColourId).withAlpha (0.6f));
  52362. g.drawRect (0, 0, width, height);
  52363. #endif
  52364. }
  52365. void LookAndFeel::drawPopupMenuUpDownArrow (Graphics& g,
  52366. int width, int height,
  52367. bool isScrollUpArrow)
  52368. {
  52369. const Colour background (findColour (PopupMenu::backgroundColourId));
  52370. g.setGradientFill (ColourGradient (background, 0.0f, height * 0.5f,
  52371. background.withAlpha (0.0f),
  52372. 0.0f, isScrollUpArrow ? ((float) height) : 0.0f,
  52373. false));
  52374. g.fillRect (1, 1, width - 2, height - 2);
  52375. const float hw = width * 0.5f;
  52376. const float arrowW = height * 0.3f;
  52377. const float y1 = height * (isScrollUpArrow ? 0.6f : 0.3f);
  52378. const float y2 = height * (isScrollUpArrow ? 0.3f : 0.6f);
  52379. Path p;
  52380. p.addTriangle (hw - arrowW, y1,
  52381. hw + arrowW, y1,
  52382. hw, y2);
  52383. g.setColour (findColour (PopupMenu::textColourId).withAlpha (0.5f));
  52384. g.fillPath (p);
  52385. }
  52386. void LookAndFeel::drawPopupMenuItem (Graphics& g,
  52387. int width, int height,
  52388. const bool isSeparator,
  52389. const bool isActive,
  52390. const bool isHighlighted,
  52391. const bool isTicked,
  52392. const bool hasSubMenu,
  52393. const String& text,
  52394. const String& shortcutKeyText,
  52395. Image* image,
  52396. const Colour* const textColourToUse)
  52397. {
  52398. const float halfH = height * 0.5f;
  52399. if (isSeparator)
  52400. {
  52401. const float separatorIndent = 5.5f;
  52402. g.setColour (Colour (0x33000000));
  52403. g.drawLine (separatorIndent, halfH, width - separatorIndent, halfH);
  52404. g.setColour (Colour (0x66ffffff));
  52405. g.drawLine (separatorIndent, halfH + 1.0f, width - separatorIndent, halfH + 1.0f);
  52406. }
  52407. else
  52408. {
  52409. Colour textColour (findColour (PopupMenu::textColourId));
  52410. if (textColourToUse != 0)
  52411. textColour = *textColourToUse;
  52412. if (isHighlighted)
  52413. {
  52414. g.setColour (findColour (PopupMenu::highlightedBackgroundColourId));
  52415. g.fillRect (1, 1, width - 2, height - 2);
  52416. g.setColour (findColour (PopupMenu::highlightedTextColourId));
  52417. }
  52418. else
  52419. {
  52420. g.setColour (textColour);
  52421. }
  52422. if (! isActive)
  52423. g.setOpacity (0.3f);
  52424. Font font (getPopupMenuFont());
  52425. if (font.getHeight() > height / 1.3f)
  52426. font.setHeight (height / 1.3f);
  52427. g.setFont (font);
  52428. const int leftBorder = (height * 5) / 4;
  52429. const int rightBorder = 4;
  52430. if (image != 0)
  52431. {
  52432. g.drawImageWithin (image,
  52433. 2, 1, leftBorder - 4, height - 2,
  52434. RectanglePlacement::centred | RectanglePlacement::onlyReduceInSize, false);
  52435. }
  52436. else if (isTicked)
  52437. {
  52438. const Path tick (getTickShape (1.0f));
  52439. const float th = font.getAscent();
  52440. const float ty = halfH - th * 0.5f;
  52441. g.fillPath (tick, tick.getTransformToScaleToFit (2.0f, ty, (float) (leftBorder - 4),
  52442. th, true));
  52443. }
  52444. g.drawFittedText (text,
  52445. leftBorder, 0,
  52446. width - (leftBorder + rightBorder), height,
  52447. Justification::centredLeft, 1);
  52448. if (shortcutKeyText.isNotEmpty())
  52449. {
  52450. Font f2 (font);
  52451. f2.setHeight (f2.getHeight() * 0.75f);
  52452. f2.setHorizontalScale (0.95f);
  52453. g.setFont (f2);
  52454. g.drawText (shortcutKeyText,
  52455. leftBorder,
  52456. 0,
  52457. width - (leftBorder + rightBorder + 4),
  52458. height,
  52459. Justification::centredRight,
  52460. true);
  52461. }
  52462. if (hasSubMenu)
  52463. {
  52464. const float arrowH = 0.6f * getPopupMenuFont().getAscent();
  52465. const float x = width - height * 0.6f;
  52466. Path p;
  52467. p.addTriangle (x, halfH - arrowH * 0.5f,
  52468. x, halfH + arrowH * 0.5f,
  52469. x + arrowH * 0.6f, halfH);
  52470. g.fillPath (p);
  52471. }
  52472. }
  52473. }
  52474. int LookAndFeel::getMenuWindowFlags()
  52475. {
  52476. return ComponentPeer::windowHasDropShadow;
  52477. }
  52478. void LookAndFeel::drawMenuBarBackground (Graphics& g, int width, int height,
  52479. bool, MenuBarComponent& menuBar)
  52480. {
  52481. const Colour baseColour (createBaseColour (menuBar.findColour (PopupMenu::backgroundColourId), false, false, false));
  52482. if (menuBar.isEnabled())
  52483. {
  52484. drawShinyButtonShape (g,
  52485. -4.0f, 0.0f,
  52486. width + 8.0f, (float) height,
  52487. 0.0f,
  52488. baseColour,
  52489. 0.4f,
  52490. true, true, true, true);
  52491. }
  52492. else
  52493. {
  52494. g.fillAll (baseColour);
  52495. }
  52496. }
  52497. const Font LookAndFeel::getMenuBarFont (MenuBarComponent& menuBar, int /*itemIndex*/, const String& /*itemText*/)
  52498. {
  52499. return Font (menuBar.getHeight() * 0.7f);
  52500. }
  52501. int LookAndFeel::getMenuBarItemWidth (MenuBarComponent& menuBar, int itemIndex, const String& itemText)
  52502. {
  52503. return getMenuBarFont (menuBar, itemIndex, itemText)
  52504. .getStringWidth (itemText) + menuBar.getHeight();
  52505. }
  52506. void LookAndFeel::drawMenuBarItem (Graphics& g,
  52507. int width, int height,
  52508. int itemIndex,
  52509. const String& itemText,
  52510. bool isMouseOverItem,
  52511. bool isMenuOpen,
  52512. bool /*isMouseOverBar*/,
  52513. MenuBarComponent& menuBar)
  52514. {
  52515. if (! menuBar.isEnabled())
  52516. {
  52517. g.setColour (menuBar.findColour (PopupMenu::textColourId)
  52518. .withMultipliedAlpha (0.5f));
  52519. }
  52520. else if (isMenuOpen || isMouseOverItem)
  52521. {
  52522. g.fillAll (menuBar.findColour (PopupMenu::highlightedBackgroundColourId));
  52523. g.setColour (menuBar.findColour (PopupMenu::highlightedTextColourId));
  52524. }
  52525. else
  52526. {
  52527. g.setColour (menuBar.findColour (PopupMenu::textColourId));
  52528. }
  52529. g.setFont (getMenuBarFont (menuBar, itemIndex, itemText));
  52530. g.drawFittedText (itemText, 0, 0, width, height, Justification::centred, 1);
  52531. }
  52532. void LookAndFeel::fillTextEditorBackground (Graphics& g, int /*width*/, int /*height*/,
  52533. TextEditor& textEditor)
  52534. {
  52535. g.fillAll (textEditor.findColour (TextEditor::backgroundColourId));
  52536. }
  52537. void LookAndFeel::drawTextEditorOutline (Graphics& g, int width, int height, TextEditor& textEditor)
  52538. {
  52539. if (textEditor.isEnabled())
  52540. {
  52541. if (textEditor.hasKeyboardFocus (true) && ! textEditor.isReadOnly())
  52542. {
  52543. const int border = 2;
  52544. g.setColour (textEditor.findColour (TextEditor::focusedOutlineColourId));
  52545. g.drawRect (0, 0, width, height, border);
  52546. g.setOpacity (1.0f);
  52547. const Colour shadowColour (textEditor.findColour (TextEditor::shadowColourId).withMultipliedAlpha (0.75f));
  52548. g.drawBevel (0, 0, width, height + 2, border + 2, shadowColour, shadowColour);
  52549. }
  52550. else
  52551. {
  52552. g.setColour (textEditor.findColour (TextEditor::outlineColourId));
  52553. g.drawRect (0, 0, width, height);
  52554. g.setOpacity (1.0f);
  52555. const Colour shadowColour (textEditor.findColour (TextEditor::shadowColourId));
  52556. g.drawBevel (0, 0, width, height + 2, 3, shadowColour, shadowColour);
  52557. }
  52558. }
  52559. }
  52560. void LookAndFeel::drawComboBox (Graphics& g, int width, int height,
  52561. const bool isButtonDown,
  52562. int buttonX, int buttonY,
  52563. int buttonW, int buttonH,
  52564. ComboBox& box)
  52565. {
  52566. g.fillAll (box.findColour (ComboBox::backgroundColourId));
  52567. if (box.isEnabled() && box.hasKeyboardFocus (false))
  52568. {
  52569. g.setColour (box.findColour (TextButton::buttonColourId));
  52570. g.drawRect (0, 0, width, height, 2);
  52571. }
  52572. else
  52573. {
  52574. g.setColour (box.findColour (ComboBox::outlineColourId));
  52575. g.drawRect (0, 0, width, height);
  52576. }
  52577. const float outlineThickness = box.isEnabled() ? (isButtonDown ? 1.2f : 0.5f) : 0.3f;
  52578. const Colour baseColour (createBaseColour (box.findColour (ComboBox::buttonColourId),
  52579. box.hasKeyboardFocus (true),
  52580. false, isButtonDown)
  52581. .withMultipliedAlpha (box.isEnabled() ? 1.0f : 0.5f));
  52582. drawGlassLozenge (g,
  52583. buttonX + outlineThickness, buttonY + outlineThickness,
  52584. buttonW - outlineThickness * 2.0f, buttonH - outlineThickness * 2.0f,
  52585. baseColour, outlineThickness, -1.0f,
  52586. true, true, true, true);
  52587. if (box.isEnabled())
  52588. {
  52589. const float arrowX = 0.3f;
  52590. const float arrowH = 0.2f;
  52591. Path p;
  52592. p.addTriangle (buttonX + buttonW * 0.5f, buttonY + buttonH * (0.45f - arrowH),
  52593. buttonX + buttonW * (1.0f - arrowX), buttonY + buttonH * 0.45f,
  52594. buttonX + buttonW * arrowX, buttonY + buttonH * 0.45f);
  52595. p.addTriangle (buttonX + buttonW * 0.5f, buttonY + buttonH * (0.55f + arrowH),
  52596. buttonX + buttonW * (1.0f - arrowX), buttonY + buttonH * 0.55f,
  52597. buttonX + buttonW * arrowX, buttonY + buttonH * 0.55f);
  52598. g.setColour (box.findColour (ComboBox::arrowColourId));
  52599. g.fillPath (p);
  52600. }
  52601. }
  52602. const Font LookAndFeel::getComboBoxFont (ComboBox& box)
  52603. {
  52604. return Font (jmin (15.0f, box.getHeight() * 0.85f));
  52605. }
  52606. Label* LookAndFeel::createComboBoxTextBox (ComboBox&)
  52607. {
  52608. return new Label (String::empty, String::empty);
  52609. }
  52610. void LookAndFeel::positionComboBoxText (ComboBox& box, Label& label)
  52611. {
  52612. label.setBounds (1, 1,
  52613. box.getWidth() + 3 - box.getHeight(),
  52614. box.getHeight() - 2);
  52615. label.setFont (getComboBoxFont (box));
  52616. }
  52617. void LookAndFeel::drawLabel (Graphics& g, Label& label)
  52618. {
  52619. g.fillAll (label.findColour (Label::backgroundColourId));
  52620. if (! label.isBeingEdited())
  52621. {
  52622. const float alpha = label.isEnabled() ? 1.0f : 0.5f;
  52623. g.setColour (label.findColour (Label::textColourId).withMultipliedAlpha (alpha));
  52624. g.setFont (label.getFont());
  52625. g.drawFittedText (label.getText(),
  52626. label.getHorizontalBorderSize(),
  52627. label.getVerticalBorderSize(),
  52628. label.getWidth() - 2 * label.getHorizontalBorderSize(),
  52629. label.getHeight() - 2 * label.getVerticalBorderSize(),
  52630. label.getJustificationType(),
  52631. jmax (1, (int) (label.getHeight() / label.getFont().getHeight())),
  52632. label.getMinimumHorizontalScale());
  52633. g.setColour (label.findColour (Label::outlineColourId).withMultipliedAlpha (alpha));
  52634. g.drawRect (0, 0, label.getWidth(), label.getHeight());
  52635. }
  52636. else if (label.isEnabled())
  52637. {
  52638. g.setColour (label.findColour (Label::outlineColourId));
  52639. g.drawRect (0, 0, label.getWidth(), label.getHeight());
  52640. }
  52641. }
  52642. void LookAndFeel::drawLinearSliderBackground (Graphics& g,
  52643. int x, int y,
  52644. int width, int height,
  52645. float /*sliderPos*/,
  52646. float /*minSliderPos*/,
  52647. float /*maxSliderPos*/,
  52648. const Slider::SliderStyle /*style*/,
  52649. Slider& slider)
  52650. {
  52651. const float sliderRadius = (float) (getSliderThumbRadius (slider) - 2);
  52652. const Colour trackColour (slider.findColour (Slider::trackColourId));
  52653. const Colour gradCol1 (trackColour.overlaidWith (Colours::black.withAlpha (slider.isEnabled() ? 0.25f : 0.13f)));
  52654. const Colour gradCol2 (trackColour.overlaidWith (Colour (0x14000000)));
  52655. Path indent;
  52656. if (slider.isHorizontal())
  52657. {
  52658. const float iy = y + height * 0.5f - sliderRadius * 0.5f;
  52659. const float ih = sliderRadius;
  52660. g.setGradientFill (ColourGradient (gradCol1, 0.0f, iy,
  52661. gradCol2, 0.0f, iy + ih, false));
  52662. indent.addRoundedRectangle (x - sliderRadius * 0.5f, iy,
  52663. width + sliderRadius, ih,
  52664. 5.0f);
  52665. g.fillPath (indent);
  52666. }
  52667. else
  52668. {
  52669. const float ix = x + width * 0.5f - sliderRadius * 0.5f;
  52670. const float iw = sliderRadius;
  52671. g.setGradientFill (ColourGradient (gradCol1, ix, 0.0f,
  52672. gradCol2, ix + iw, 0.0f, false));
  52673. indent.addRoundedRectangle (ix, y - sliderRadius * 0.5f,
  52674. iw, height + sliderRadius,
  52675. 5.0f);
  52676. g.fillPath (indent);
  52677. }
  52678. g.setColour (Colour (0x4c000000));
  52679. g.strokePath (indent, PathStrokeType (0.5f));
  52680. }
  52681. void LookAndFeel::drawLinearSliderThumb (Graphics& g,
  52682. int x, int y,
  52683. int width, int height,
  52684. float sliderPos,
  52685. float minSliderPos,
  52686. float maxSliderPos,
  52687. const Slider::SliderStyle style,
  52688. Slider& slider)
  52689. {
  52690. const float sliderRadius = (float) (getSliderThumbRadius (slider) - 2);
  52691. Colour knobColour (createBaseColour (slider.findColour (Slider::thumbColourId),
  52692. slider.hasKeyboardFocus (false) && slider.isEnabled(),
  52693. slider.isMouseOverOrDragging() && slider.isEnabled(),
  52694. slider.isMouseButtonDown() && slider.isEnabled()));
  52695. const float outlineThickness = slider.isEnabled() ? 0.8f : 0.3f;
  52696. if (style == Slider::LinearHorizontal || style == Slider::LinearVertical)
  52697. {
  52698. float kx, ky;
  52699. if (style == Slider::LinearVertical)
  52700. {
  52701. kx = x + width * 0.5f;
  52702. ky = sliderPos;
  52703. }
  52704. else
  52705. {
  52706. kx = sliderPos;
  52707. ky = y + height * 0.5f;
  52708. }
  52709. drawGlassSphere (g,
  52710. kx - sliderRadius,
  52711. ky - sliderRadius,
  52712. sliderRadius * 2.0f,
  52713. knobColour, outlineThickness);
  52714. }
  52715. else
  52716. {
  52717. if (style == Slider::ThreeValueVertical)
  52718. {
  52719. drawGlassSphere (g, x + width * 0.5f - sliderRadius,
  52720. sliderPos - sliderRadius,
  52721. sliderRadius * 2.0f,
  52722. knobColour, outlineThickness);
  52723. }
  52724. else if (style == Slider::ThreeValueHorizontal)
  52725. {
  52726. drawGlassSphere (g,sliderPos - sliderRadius,
  52727. y + height * 0.5f - sliderRadius,
  52728. sliderRadius * 2.0f,
  52729. knobColour, outlineThickness);
  52730. }
  52731. if (style == Slider::TwoValueVertical || style == Slider::ThreeValueVertical)
  52732. {
  52733. const float sr = jmin (sliderRadius, width * 0.4f);
  52734. drawGlassPointer (g, jmax (0.0f, x + width * 0.5f - sliderRadius * 2.0f),
  52735. minSliderPos - sliderRadius,
  52736. sliderRadius * 2.0f, knobColour, outlineThickness, 1);
  52737. drawGlassPointer (g, jmin (x + width - sliderRadius * 2.0f, x + width * 0.5f), maxSliderPos - sr,
  52738. sliderRadius * 2.0f, knobColour, outlineThickness, 3);
  52739. }
  52740. else if (style == Slider::TwoValueHorizontal || style == Slider::ThreeValueHorizontal)
  52741. {
  52742. const float sr = jmin (sliderRadius, height * 0.4f);
  52743. drawGlassPointer (g, minSliderPos - sr,
  52744. jmax (0.0f, y + height * 0.5f - sliderRadius * 2.0f),
  52745. sliderRadius * 2.0f, knobColour, outlineThickness, 2);
  52746. drawGlassPointer (g, maxSliderPos - sliderRadius,
  52747. jmin (y + height - sliderRadius * 2.0f, y + height * 0.5f),
  52748. sliderRadius * 2.0f, knobColour, outlineThickness, 4);
  52749. }
  52750. }
  52751. }
  52752. void LookAndFeel::drawLinearSlider (Graphics& g,
  52753. int x, int y,
  52754. int width, int height,
  52755. float sliderPos,
  52756. float minSliderPos,
  52757. float maxSliderPos,
  52758. const Slider::SliderStyle style,
  52759. Slider& slider)
  52760. {
  52761. g.fillAll (slider.findColour (Slider::backgroundColourId));
  52762. if (style == Slider::LinearBar)
  52763. {
  52764. const bool isMouseOver = slider.isMouseOverOrDragging() && slider.isEnabled();
  52765. Colour baseColour (createBaseColour (slider.findColour (Slider::thumbColourId)
  52766. .withMultipliedSaturation (slider.isEnabled() ? 1.0f : 0.5f),
  52767. false,
  52768. isMouseOver,
  52769. isMouseOver || slider.isMouseButtonDown()));
  52770. drawShinyButtonShape (g,
  52771. (float) x, (float) y, sliderPos - (float) x, (float) height, 0.0f,
  52772. baseColour,
  52773. slider.isEnabled() ? 0.9f : 0.3f,
  52774. true, true, true, true);
  52775. }
  52776. else
  52777. {
  52778. drawLinearSliderBackground (g, x, y, width, height, sliderPos, minSliderPos, maxSliderPos, style, slider);
  52779. drawLinearSliderThumb (g, x, y, width, height, sliderPos, minSliderPos, maxSliderPos, style, slider);
  52780. }
  52781. }
  52782. int LookAndFeel::getSliderThumbRadius (Slider& slider)
  52783. {
  52784. return jmin (7,
  52785. slider.getHeight() / 2,
  52786. slider.getWidth() / 2) + 2;
  52787. }
  52788. void LookAndFeel::drawRotarySlider (Graphics& g,
  52789. int x, int y,
  52790. int width, int height,
  52791. float sliderPos,
  52792. const float rotaryStartAngle,
  52793. const float rotaryEndAngle,
  52794. Slider& slider)
  52795. {
  52796. const float radius = jmin (width / 2, height / 2) - 2.0f;
  52797. const float centreX = x + width * 0.5f;
  52798. const float centreY = y + height * 0.5f;
  52799. const float rx = centreX - radius;
  52800. const float ry = centreY - radius;
  52801. const float rw = radius * 2.0f;
  52802. const float angle = rotaryStartAngle + sliderPos * (rotaryEndAngle - rotaryStartAngle);
  52803. const bool isMouseOver = slider.isMouseOverOrDragging() && slider.isEnabled();
  52804. if (radius > 12.0f)
  52805. {
  52806. if (slider.isEnabled())
  52807. g.setColour (slider.findColour (Slider::rotarySliderFillColourId).withAlpha (isMouseOver ? 1.0f : 0.7f));
  52808. else
  52809. g.setColour (Colour (0x80808080));
  52810. const float thickness = 0.7f;
  52811. {
  52812. Path filledArc;
  52813. filledArc.addPieSegment (rx, ry, rw, rw,
  52814. rotaryStartAngle,
  52815. angle,
  52816. thickness);
  52817. g.fillPath (filledArc);
  52818. }
  52819. if (thickness > 0)
  52820. {
  52821. const float innerRadius = radius * 0.2f;
  52822. Path p;
  52823. p.addTriangle (-innerRadius, 0.0f,
  52824. 0.0f, -radius * thickness * 1.1f,
  52825. innerRadius, 0.0f);
  52826. p.addEllipse (-innerRadius, -innerRadius, innerRadius * 2.0f, innerRadius * 2.0f);
  52827. g.fillPath (p, AffineTransform::rotation (angle).translated (centreX, centreY));
  52828. }
  52829. if (slider.isEnabled())
  52830. g.setColour (slider.findColour (Slider::rotarySliderOutlineColourId));
  52831. else
  52832. g.setColour (Colour (0x80808080));
  52833. Path outlineArc;
  52834. outlineArc.addPieSegment (rx, ry, rw, rw, rotaryStartAngle, rotaryEndAngle, thickness);
  52835. outlineArc.closeSubPath();
  52836. g.strokePath (outlineArc, PathStrokeType (slider.isEnabled() ? (isMouseOver ? 2.0f : 1.2f) : 0.3f));
  52837. }
  52838. else
  52839. {
  52840. if (slider.isEnabled())
  52841. g.setColour (slider.findColour (Slider::rotarySliderFillColourId).withAlpha (isMouseOver ? 1.0f : 0.7f));
  52842. else
  52843. g.setColour (Colour (0x80808080));
  52844. Path p;
  52845. p.addEllipse (-0.4f * rw, -0.4f * rw, rw * 0.8f, rw * 0.8f);
  52846. PathStrokeType (rw * 0.1f).createStrokedPath (p, p);
  52847. p.addLineSegment (0.0f, 0.0f, 0.0f, -radius, rw * 0.2f);
  52848. g.fillPath (p, AffineTransform::rotation (angle).translated (centreX, centreY));
  52849. }
  52850. }
  52851. Button* LookAndFeel::createSliderButton (const bool isIncrement)
  52852. {
  52853. return new TextButton (isIncrement ? "+" : "-", String::empty);
  52854. }
  52855. class SliderLabelComp : public Label
  52856. {
  52857. public:
  52858. SliderLabelComp() : Label (String::empty, String::empty) {}
  52859. ~SliderLabelComp() {}
  52860. void mouseWheelMove (const MouseEvent&, float, float) {}
  52861. };
  52862. Label* LookAndFeel::createSliderTextBox (Slider& slider)
  52863. {
  52864. Label* const l = new SliderLabelComp();
  52865. l->setJustificationType (Justification::centred);
  52866. l->setColour (Label::textColourId, slider.findColour (Slider::textBoxTextColourId));
  52867. l->setColour (Label::backgroundColourId,
  52868. (slider.getSliderStyle() == Slider::LinearBar) ? Colours::transparentBlack
  52869. : slider.findColour (Slider::textBoxBackgroundColourId));
  52870. l->setColour (Label::outlineColourId, slider.findColour (Slider::textBoxOutlineColourId));
  52871. l->setColour (TextEditor::textColourId, slider.findColour (Slider::textBoxTextColourId));
  52872. l->setColour (TextEditor::backgroundColourId,
  52873. slider.findColour (Slider::textBoxBackgroundColourId)
  52874. .withAlpha (slider.getSliderStyle() == Slider::LinearBar ? 0.7f : 1.0f));
  52875. l->setColour (TextEditor::outlineColourId, slider.findColour (Slider::textBoxOutlineColourId));
  52876. return l;
  52877. }
  52878. ImageEffectFilter* LookAndFeel::getSliderEffect()
  52879. {
  52880. return 0;
  52881. }
  52882. static const TextLayout layoutTooltipText (const String& text) throw()
  52883. {
  52884. const float tooltipFontSize = 12.0f;
  52885. const int maxToolTipWidth = 400;
  52886. const Font f (tooltipFontSize, Font::bold);
  52887. TextLayout tl (text, f);
  52888. tl.layout (maxToolTipWidth, Justification::left, true);
  52889. return tl;
  52890. }
  52891. void LookAndFeel::getTooltipSize (const String& tipText, int& width, int& height)
  52892. {
  52893. const TextLayout tl (layoutTooltipText (tipText));
  52894. width = tl.getWidth() + 14;
  52895. height = tl.getHeight() + 6;
  52896. }
  52897. void LookAndFeel::drawTooltip (Graphics& g, const String& text, int width, int height)
  52898. {
  52899. g.fillAll (findColour (TooltipWindow::backgroundColourId));
  52900. const Colour textCol (findColour (TooltipWindow::textColourId));
  52901. #if ! JUCE_MAC // The mac windows already have a non-optional 1 pix outline, so don't double it here..
  52902. g.setColour (findColour (TooltipWindow::outlineColourId));
  52903. g.drawRect (0, 0, width, height, 1);
  52904. #endif
  52905. const TextLayout tl (layoutTooltipText (text));
  52906. g.setColour (findColour (TooltipWindow::textColourId));
  52907. tl.drawWithin (g, 0, 0, width, height, Justification::centred);
  52908. }
  52909. Button* LookAndFeel::createFilenameComponentBrowseButton (const String& text)
  52910. {
  52911. return new TextButton (text, TRANS("click to browse for a different file"));
  52912. }
  52913. void LookAndFeel::layoutFilenameComponent (FilenameComponent& filenameComp,
  52914. ComboBox* filenameBox,
  52915. Button* browseButton)
  52916. {
  52917. browseButton->setSize (80, filenameComp.getHeight());
  52918. TextButton* const tb = dynamic_cast <TextButton*> (browseButton);
  52919. if (tb != 0)
  52920. tb->changeWidthToFitText();
  52921. browseButton->setTopRightPosition (filenameComp.getWidth(), 0);
  52922. filenameBox->setBounds (0, 0, browseButton->getX(), filenameComp.getHeight());
  52923. }
  52924. void LookAndFeel::drawImageButton (Graphics& g, Image* image,
  52925. int imageX, int imageY, int imageW, int imageH,
  52926. const Colour& overlayColour,
  52927. float imageOpacity,
  52928. ImageButton& button)
  52929. {
  52930. if (! button.isEnabled())
  52931. imageOpacity *= 0.3f;
  52932. if (! overlayColour.isOpaque())
  52933. {
  52934. g.setOpacity (imageOpacity);
  52935. g.drawImage (image, imageX, imageY, imageW, imageH,
  52936. 0, 0, image->getWidth(), image->getHeight(), false);
  52937. }
  52938. if (! overlayColour.isTransparent())
  52939. {
  52940. g.setColour (overlayColour);
  52941. g.drawImage (image, imageX, imageY, imageW, imageH,
  52942. 0, 0, image->getWidth(), image->getHeight(), true);
  52943. }
  52944. }
  52945. void LookAndFeel::drawCornerResizer (Graphics& g,
  52946. int w, int h,
  52947. bool /*isMouseOver*/,
  52948. bool /*isMouseDragging*/)
  52949. {
  52950. const float lineThickness = jmin (w, h) * 0.075f;
  52951. for (float i = 0.0f; i < 1.0f; i += 0.3f)
  52952. {
  52953. g.setColour (Colours::lightgrey);
  52954. g.drawLine (w * i,
  52955. h + 1.0f,
  52956. w + 1.0f,
  52957. h * i,
  52958. lineThickness);
  52959. g.setColour (Colours::darkgrey);
  52960. g.drawLine (w * i + lineThickness,
  52961. h + 1.0f,
  52962. w + 1.0f,
  52963. h * i + lineThickness,
  52964. lineThickness);
  52965. }
  52966. }
  52967. void LookAndFeel::drawResizableFrame (Graphics&, int /*w*/, int /*h*/,
  52968. const BorderSize& /*borders*/)
  52969. {
  52970. }
  52971. void LookAndFeel::fillResizableWindowBackground (Graphics& g, int /*w*/, int /*h*/,
  52972. const BorderSize& /*border*/, ResizableWindow& window)
  52973. {
  52974. g.fillAll (window.getBackgroundColour());
  52975. }
  52976. void LookAndFeel::drawResizableWindowBorder (Graphics& g, int w, int h,
  52977. const BorderSize& border, ResizableWindow&)
  52978. {
  52979. g.setColour (Colour (0x80000000));
  52980. g.drawRect (0, 0, w, h);
  52981. g.setColour (Colour (0x19000000));
  52982. g.drawRect (border.getLeft() - 1,
  52983. border.getTop() - 1,
  52984. w + 2 - border.getLeftAndRight(),
  52985. h + 2 - border.getTopAndBottom());
  52986. }
  52987. void LookAndFeel::drawDocumentWindowTitleBar (DocumentWindow& window,
  52988. Graphics& g, int w, int h,
  52989. int titleSpaceX, int titleSpaceW,
  52990. const Image* icon,
  52991. bool drawTitleTextOnLeft)
  52992. {
  52993. const bool isActive = window.isActiveWindow();
  52994. g.setGradientFill (ColourGradient (window.getBackgroundColour(),
  52995. 0.0f, 0.0f,
  52996. window.getBackgroundColour().contrasting (isActive ? 0.15f : 0.05f),
  52997. 0.0f, (float) h, false));
  52998. g.fillAll();
  52999. Font font (h * 0.65f, Font::bold);
  53000. g.setFont (font);
  53001. int textW = font.getStringWidth (window.getName());
  53002. int iconW = 0;
  53003. int iconH = 0;
  53004. if (icon != 0)
  53005. {
  53006. iconH = (int) font.getHeight();
  53007. iconW = icon->getWidth() * iconH / icon->getHeight() + 4;
  53008. }
  53009. textW = jmin (titleSpaceW, textW + iconW);
  53010. int textX = drawTitleTextOnLeft ? titleSpaceX
  53011. : jmax (titleSpaceX, (w - textW) / 2);
  53012. if (textX + textW > titleSpaceX + titleSpaceW)
  53013. textX = titleSpaceX + titleSpaceW - textW;
  53014. if (icon != 0)
  53015. {
  53016. g.setOpacity (isActive ? 1.0f : 0.6f);
  53017. g.drawImageWithin (icon, textX, (h - iconH) / 2, iconW, iconH,
  53018. RectanglePlacement::centred, false);
  53019. textX += iconW;
  53020. textW -= iconW;
  53021. }
  53022. if (window.isColourSpecified (DocumentWindow::textColourId) || isColourSpecified (DocumentWindow::textColourId))
  53023. g.setColour (findColour (DocumentWindow::textColourId));
  53024. else
  53025. g.setColour (window.getBackgroundColour().contrasting (isActive ? 0.7f : 0.4f));
  53026. g.drawText (window.getName(), textX, 0, textW, h, Justification::centredLeft, true);
  53027. }
  53028. class GlassWindowButton : public Button
  53029. {
  53030. public:
  53031. GlassWindowButton (const String& name, const Colour& col,
  53032. const Path& normalShape_,
  53033. const Path& toggledShape_) throw()
  53034. : Button (name),
  53035. colour (col),
  53036. normalShape (normalShape_),
  53037. toggledShape (toggledShape_)
  53038. {
  53039. }
  53040. ~GlassWindowButton()
  53041. {
  53042. }
  53043. void paintButton (Graphics& g, bool isMouseOverButton, bool isButtonDown)
  53044. {
  53045. float alpha = isMouseOverButton ? (isButtonDown ? 1.0f : 0.8f) : 0.55f;
  53046. if (! isEnabled())
  53047. alpha *= 0.5f;
  53048. float x = 0, y = 0, diam;
  53049. if (getWidth() < getHeight())
  53050. {
  53051. diam = (float) getWidth();
  53052. y = (getHeight() - getWidth()) * 0.5f;
  53053. }
  53054. else
  53055. {
  53056. diam = (float) getHeight();
  53057. y = (getWidth() - getHeight()) * 0.5f;
  53058. }
  53059. x += diam * 0.05f;
  53060. y += diam * 0.05f;
  53061. diam *= 0.9f;
  53062. g.setGradientFill (ColourGradient (Colour::greyLevel (0.9f).withAlpha (alpha), 0, y + diam,
  53063. Colour::greyLevel (0.6f).withAlpha (alpha), 0, y, false));
  53064. g.fillEllipse (x, y, diam, diam);
  53065. x += 2.0f;
  53066. y += 2.0f;
  53067. diam -= 4.0f;
  53068. LookAndFeel::drawGlassSphere (g, x, y, diam, colour.withAlpha (alpha), 1.0f);
  53069. Path& p = getToggleState() ? toggledShape : normalShape;
  53070. const AffineTransform t (p.getTransformToScaleToFit (x + diam * 0.3f, y + diam * 0.3f,
  53071. diam * 0.4f, diam * 0.4f, true));
  53072. g.setColour (Colours::black.withAlpha (alpha * 0.6f));
  53073. g.fillPath (p, t);
  53074. }
  53075. juce_UseDebuggingNewOperator
  53076. private:
  53077. Colour colour;
  53078. Path normalShape, toggledShape;
  53079. GlassWindowButton (const GlassWindowButton&);
  53080. const GlassWindowButton& operator= (const GlassWindowButton&);
  53081. };
  53082. Button* LookAndFeel::createDocumentWindowButton (int buttonType)
  53083. {
  53084. Path shape;
  53085. const float crossThickness = 0.25f;
  53086. if (buttonType == DocumentWindow::closeButton)
  53087. {
  53088. shape.addLineSegment (0.0f, 0.0f, 1.0f, 1.0f, crossThickness * 1.4f);
  53089. shape.addLineSegment (1.0f, 0.0f, 0.0f, 1.0f, crossThickness * 1.4f);
  53090. return new GlassWindowButton ("close", Colour (0xffdd1100), shape, shape);
  53091. }
  53092. else if (buttonType == DocumentWindow::minimiseButton)
  53093. {
  53094. shape.addLineSegment (0.0f, 0.5f, 1.0f, 0.5f, crossThickness);
  53095. return new GlassWindowButton ("minimise", Colour (0xffaa8811), shape, shape);
  53096. }
  53097. else if (buttonType == DocumentWindow::maximiseButton)
  53098. {
  53099. shape.addLineSegment (0.5f, 0.0f, 0.5f, 1.0f, crossThickness);
  53100. shape.addLineSegment (0.0f, 0.5f, 1.0f, 0.5f, crossThickness);
  53101. Path fullscreenShape;
  53102. fullscreenShape.startNewSubPath (45.0f, 100.0f);
  53103. fullscreenShape.lineTo (0.0f, 100.0f);
  53104. fullscreenShape.lineTo (0.0f, 0.0f);
  53105. fullscreenShape.lineTo (100.0f, 0.0f);
  53106. fullscreenShape.lineTo (100.0f, 45.0f);
  53107. fullscreenShape.addRectangle (45.0f, 45.0f, 100.0f, 100.0f);
  53108. PathStrokeType (30.0f).createStrokedPath (fullscreenShape, fullscreenShape);
  53109. return new GlassWindowButton ("maximise", Colour (0xff119911), shape, fullscreenShape);
  53110. }
  53111. jassertfalse
  53112. return 0;
  53113. }
  53114. void LookAndFeel::positionDocumentWindowButtons (DocumentWindow&,
  53115. int titleBarX,
  53116. int titleBarY,
  53117. int titleBarW,
  53118. int titleBarH,
  53119. Button* minimiseButton,
  53120. Button* maximiseButton,
  53121. Button* closeButton,
  53122. bool positionTitleBarButtonsOnLeft)
  53123. {
  53124. const int buttonW = titleBarH - titleBarH / 8;
  53125. int x = positionTitleBarButtonsOnLeft ? titleBarX + 4
  53126. : titleBarX + titleBarW - buttonW - buttonW / 4;
  53127. if (closeButton != 0)
  53128. {
  53129. closeButton->setBounds (x, titleBarY, buttonW, titleBarH);
  53130. x += positionTitleBarButtonsOnLeft ? buttonW : -(buttonW + buttonW / 4);
  53131. }
  53132. if (positionTitleBarButtonsOnLeft)
  53133. swapVariables (minimiseButton, maximiseButton);
  53134. if (maximiseButton != 0)
  53135. {
  53136. maximiseButton->setBounds (x, titleBarY, buttonW, titleBarH);
  53137. x += positionTitleBarButtonsOnLeft ? buttonW : -buttonW;
  53138. }
  53139. if (minimiseButton != 0)
  53140. minimiseButton->setBounds (x, titleBarY, buttonW, titleBarH);
  53141. }
  53142. int LookAndFeel::getDefaultMenuBarHeight()
  53143. {
  53144. return 24;
  53145. }
  53146. DropShadower* LookAndFeel::createDropShadowerForComponent (Component*)
  53147. {
  53148. return new DropShadower (0.4f, 1, 5, 10);
  53149. }
  53150. void LookAndFeel::drawStretchableLayoutResizerBar (Graphics& g,
  53151. int w, int h,
  53152. bool /*isVerticalBar*/,
  53153. bool isMouseOver,
  53154. bool isMouseDragging)
  53155. {
  53156. float alpha = 0.5f;
  53157. if (isMouseOver || isMouseDragging)
  53158. {
  53159. g.fillAll (Colour (0x190000ff));
  53160. alpha = 1.0f;
  53161. }
  53162. const float cx = w * 0.5f;
  53163. const float cy = h * 0.5f;
  53164. const float cr = jmin (w, h) * 0.4f;
  53165. g.setGradientFill (ColourGradient (Colours::white.withAlpha (alpha), cx + cr * 0.1f, cy + cr,
  53166. Colours::black.withAlpha (alpha), cx, cy - cr * 4.0f,
  53167. true));
  53168. g.fillEllipse (cx - cr, cy - cr, cr * 2.0f, cr * 2.0f);
  53169. }
  53170. void LookAndFeel::drawGroupComponentOutline (Graphics& g, int width, int height,
  53171. const String& text,
  53172. const Justification& position,
  53173. GroupComponent& group)
  53174. {
  53175. const float textH = 15.0f;
  53176. const float indent = 3.0f;
  53177. const float textEdgeGap = 4.0f;
  53178. float cs = 5.0f;
  53179. Font f (textH);
  53180. Path p;
  53181. float x = indent;
  53182. float y = f.getAscent() - 3.0f;
  53183. float w = jmax (0.0f, width - x * 2.0f);
  53184. float h = jmax (0.0f, height - y - indent);
  53185. cs = jmin (cs, w * 0.5f, h * 0.5f);
  53186. const float cs2 = 2.0f * cs;
  53187. float textW = text.isEmpty() ? 0 : jlimit (0.0f, jmax (0.0f, w - cs2 - textEdgeGap * 2), f.getStringWidth (text) + textEdgeGap * 2.0f);
  53188. float textX = cs + textEdgeGap;
  53189. if (position.testFlags (Justification::horizontallyCentred))
  53190. textX = cs + (w - cs2 - textW) * 0.5f;
  53191. else if (position.testFlags (Justification::right))
  53192. textX = w - cs - textW - textEdgeGap;
  53193. p.startNewSubPath (x + textX + textW, y);
  53194. p.lineTo (x + w - cs, y);
  53195. p.addArc (x + w - cs2, y, cs2, cs2, 0, float_Pi * 0.5f);
  53196. p.lineTo (x + w, y + h - cs);
  53197. p.addArc (x + w - cs2, y + h - cs2, cs2, cs2, float_Pi * 0.5f, float_Pi);
  53198. p.lineTo (x + cs, y + h);
  53199. p.addArc (x, y + h - cs2, cs2, cs2, float_Pi, float_Pi * 1.5f);
  53200. p.lineTo (x, y + cs);
  53201. p.addArc (x, y, cs2, cs2, float_Pi * 1.5f, float_Pi * 2.0f);
  53202. p.lineTo (x + textX, y);
  53203. const float alpha = group.isEnabled() ? 1.0f : 0.5f;
  53204. g.setColour (group.findColour (GroupComponent::outlineColourId)
  53205. .withMultipliedAlpha (alpha));
  53206. g.strokePath (p, PathStrokeType (2.0f));
  53207. g.setColour (group.findColour (GroupComponent::textColourId)
  53208. .withMultipliedAlpha (alpha));
  53209. g.setFont (f);
  53210. g.drawText (text,
  53211. roundToInt (x + textX), 0,
  53212. roundToInt (textW),
  53213. roundToInt (textH),
  53214. Justification::centred, true);
  53215. }
  53216. int LookAndFeel::getTabButtonOverlap (int tabDepth)
  53217. {
  53218. return 1 + tabDepth / 3;
  53219. }
  53220. int LookAndFeel::getTabButtonSpaceAroundImage()
  53221. {
  53222. return 4;
  53223. }
  53224. void LookAndFeel::createTabButtonShape (Path& p,
  53225. int width, int height,
  53226. int /*tabIndex*/,
  53227. const String& /*text*/,
  53228. Button& /*button*/,
  53229. TabbedButtonBar::Orientation orientation,
  53230. const bool /*isMouseOver*/,
  53231. const bool /*isMouseDown*/,
  53232. const bool /*isFrontTab*/)
  53233. {
  53234. const float w = (float) width;
  53235. const float h = (float) height;
  53236. float length = w;
  53237. float depth = h;
  53238. if (orientation == TabbedButtonBar::TabsAtLeft
  53239. || orientation == TabbedButtonBar::TabsAtRight)
  53240. {
  53241. swapVariables (length, depth);
  53242. }
  53243. const float indent = (float) getTabButtonOverlap ((int) depth);
  53244. const float overhang = 4.0f;
  53245. if (orientation == TabbedButtonBar::TabsAtLeft)
  53246. {
  53247. p.startNewSubPath (w, 0.0f);
  53248. p.lineTo (0.0f, indent);
  53249. p.lineTo (0.0f, h - indent);
  53250. p.lineTo (w, h);
  53251. p.lineTo (w + overhang, h + overhang);
  53252. p.lineTo (w + overhang, -overhang);
  53253. }
  53254. else if (orientation == TabbedButtonBar::TabsAtRight)
  53255. {
  53256. p.startNewSubPath (0.0f, 0.0f);
  53257. p.lineTo (w, indent);
  53258. p.lineTo (w, h - indent);
  53259. p.lineTo (0.0f, h);
  53260. p.lineTo (-overhang, h + overhang);
  53261. p.lineTo (-overhang, -overhang);
  53262. }
  53263. else if (orientation == TabbedButtonBar::TabsAtBottom)
  53264. {
  53265. p.startNewSubPath (0.0f, 0.0f);
  53266. p.lineTo (indent, h);
  53267. p.lineTo (w - indent, h);
  53268. p.lineTo (w, 0.0f);
  53269. p.lineTo (w + overhang, -overhang);
  53270. p.lineTo (-overhang, -overhang);
  53271. }
  53272. else
  53273. {
  53274. p.startNewSubPath (0.0f, h);
  53275. p.lineTo (indent, 0.0f);
  53276. p.lineTo (w - indent, 0.0f);
  53277. p.lineTo (w, h);
  53278. p.lineTo (w + overhang, h + overhang);
  53279. p.lineTo (-overhang, h + overhang);
  53280. }
  53281. p.closeSubPath();
  53282. p = p.createPathWithRoundedCorners (3.0f);
  53283. }
  53284. void LookAndFeel::fillTabButtonShape (Graphics& g,
  53285. const Path& path,
  53286. const Colour& preferredColour,
  53287. int /*tabIndex*/,
  53288. const String& /*text*/,
  53289. Button& button,
  53290. TabbedButtonBar::Orientation /*orientation*/,
  53291. const bool /*isMouseOver*/,
  53292. const bool /*isMouseDown*/,
  53293. const bool isFrontTab)
  53294. {
  53295. g.setColour (isFrontTab ? preferredColour
  53296. : preferredColour.withMultipliedAlpha (0.9f));
  53297. g.fillPath (path);
  53298. g.setColour (button.findColour (isFrontTab ? TabbedButtonBar::frontOutlineColourId
  53299. : TabbedButtonBar::tabOutlineColourId, false)
  53300. .withMultipliedAlpha (button.isEnabled() ? 1.0f : 0.5f));
  53301. g.strokePath (path, PathStrokeType (isFrontTab ? 1.0f : 0.5f));
  53302. }
  53303. void LookAndFeel::drawTabButtonText (Graphics& g,
  53304. int x, int y, int w, int h,
  53305. const Colour& preferredBackgroundColour,
  53306. int /*tabIndex*/,
  53307. const String& text,
  53308. Button& button,
  53309. TabbedButtonBar::Orientation orientation,
  53310. const bool isMouseOver,
  53311. const bool isMouseDown,
  53312. const bool isFrontTab)
  53313. {
  53314. int length = w;
  53315. int depth = h;
  53316. if (orientation == TabbedButtonBar::TabsAtLeft
  53317. || orientation == TabbedButtonBar::TabsAtRight)
  53318. {
  53319. swapVariables (length, depth);
  53320. }
  53321. Font font (depth * 0.6f);
  53322. font.setUnderline (button.hasKeyboardFocus (false));
  53323. GlyphArrangement textLayout;
  53324. textLayout.addFittedText (font, text.trim(),
  53325. 0.0f, 0.0f, (float) length, (float) depth,
  53326. Justification::centred,
  53327. jmax (1, depth / 12));
  53328. AffineTransform transform;
  53329. if (orientation == TabbedButtonBar::TabsAtLeft)
  53330. {
  53331. transform = transform.rotated (float_Pi * -0.5f)
  53332. .translated ((float) x, (float) (y + h));
  53333. }
  53334. else if (orientation == TabbedButtonBar::TabsAtRight)
  53335. {
  53336. transform = transform.rotated (float_Pi * 0.5f)
  53337. .translated ((float) (x + w), (float) y);
  53338. }
  53339. else
  53340. {
  53341. transform = transform.translated ((float) x, (float) y);
  53342. }
  53343. if (isFrontTab && (button.isColourSpecified (TabbedButtonBar::frontTextColourId) || isColourSpecified (TabbedButtonBar::frontTextColourId)))
  53344. g.setColour (findColour (TabbedButtonBar::frontTextColourId));
  53345. else if (button.isColourSpecified (TabbedButtonBar::tabTextColourId) || isColourSpecified (TabbedButtonBar::tabTextColourId))
  53346. g.setColour (findColour (TabbedButtonBar::tabTextColourId));
  53347. else
  53348. g.setColour (preferredBackgroundColour.contrasting());
  53349. if (! (isMouseOver || isMouseDown))
  53350. g.setOpacity (0.8f);
  53351. if (! button.isEnabled())
  53352. g.setOpacity (0.3f);
  53353. textLayout.draw (g, transform);
  53354. }
  53355. int LookAndFeel::getTabButtonBestWidth (int /*tabIndex*/,
  53356. const String& text,
  53357. int tabDepth,
  53358. Button&)
  53359. {
  53360. Font f (tabDepth * 0.6f);
  53361. return f.getStringWidth (text.trim()) + getTabButtonOverlap (tabDepth) * 2;
  53362. }
  53363. void LookAndFeel::drawTabButton (Graphics& g,
  53364. int w, int h,
  53365. const Colour& preferredColour,
  53366. int tabIndex,
  53367. const String& text,
  53368. Button& button,
  53369. TabbedButtonBar::Orientation orientation,
  53370. const bool isMouseOver,
  53371. const bool isMouseDown,
  53372. const bool isFrontTab)
  53373. {
  53374. int length = w;
  53375. int depth = h;
  53376. if (orientation == TabbedButtonBar::TabsAtLeft
  53377. || orientation == TabbedButtonBar::TabsAtRight)
  53378. {
  53379. swapVariables (length, depth);
  53380. }
  53381. Path tabShape;
  53382. createTabButtonShape (tabShape, w, h,
  53383. tabIndex, text, button, orientation,
  53384. isMouseOver, isMouseDown, isFrontTab);
  53385. fillTabButtonShape (g, tabShape, preferredColour,
  53386. tabIndex, text, button, orientation,
  53387. isMouseOver, isMouseDown, isFrontTab);
  53388. const int indent = getTabButtonOverlap (depth);
  53389. int x = 0, y = 0;
  53390. if (orientation == TabbedButtonBar::TabsAtLeft
  53391. || orientation == TabbedButtonBar::TabsAtRight)
  53392. {
  53393. y += indent;
  53394. h -= indent * 2;
  53395. }
  53396. else
  53397. {
  53398. x += indent;
  53399. w -= indent * 2;
  53400. }
  53401. drawTabButtonText (g, x, y, w, h, preferredColour,
  53402. tabIndex, text, button, orientation,
  53403. isMouseOver, isMouseDown, isFrontTab);
  53404. }
  53405. void LookAndFeel::drawTabAreaBehindFrontButton (Graphics& g,
  53406. int w, int h,
  53407. TabbedButtonBar& tabBar,
  53408. TabbedButtonBar::Orientation orientation)
  53409. {
  53410. const float shadowSize = 0.2f;
  53411. float x1 = 0.0f, y1 = 0.0f, x2 = 0.0f, y2 = 0.0f;
  53412. Rectangle shadowRect;
  53413. if (orientation == TabbedButtonBar::TabsAtLeft)
  53414. {
  53415. x1 = (float) w;
  53416. x2 = w * (1.0f - shadowSize);
  53417. shadowRect.setBounds ((int) x2, 0, w - (int) x2, h);
  53418. }
  53419. else if (orientation == TabbedButtonBar::TabsAtRight)
  53420. {
  53421. x2 = w * shadowSize;
  53422. shadowRect.setBounds (0, 0, (int) x2, h);
  53423. }
  53424. else if (orientation == TabbedButtonBar::TabsAtBottom)
  53425. {
  53426. y2 = h * shadowSize;
  53427. shadowRect.setBounds (0, 0, w, (int) y2);
  53428. }
  53429. else
  53430. {
  53431. y1 = (float) h;
  53432. y2 = h * (1.0f - shadowSize);
  53433. shadowRect.setBounds (0, (int) y2, w, h - (int) y2);
  53434. }
  53435. g.setGradientFill (ColourGradient (Colours::black.withAlpha (tabBar.isEnabled() ? 0.3f : 0.15f), x1, y1,
  53436. Colours::transparentBlack, x2, y2, false));
  53437. shadowRect.expand (2, 2);
  53438. g.fillRect (shadowRect);
  53439. g.setColour (Colour (0x80000000));
  53440. if (orientation == TabbedButtonBar::TabsAtLeft)
  53441. {
  53442. g.fillRect (w - 1, 0, 1, h);
  53443. }
  53444. else if (orientation == TabbedButtonBar::TabsAtRight)
  53445. {
  53446. g.fillRect (0, 0, 1, h);
  53447. }
  53448. else if (orientation == TabbedButtonBar::TabsAtBottom)
  53449. {
  53450. g.fillRect (0, 0, w, 1);
  53451. }
  53452. else
  53453. {
  53454. g.fillRect (0, h - 1, w, 1);
  53455. }
  53456. }
  53457. Button* LookAndFeel::createTabBarExtrasButton()
  53458. {
  53459. const float thickness = 7.0f;
  53460. const float indent = 22.0f;
  53461. Path p;
  53462. p.addEllipse (-10.0f, -10.0f, 120.0f, 120.0f);
  53463. DrawablePath ellipse;
  53464. ellipse.setPath (p);
  53465. ellipse.setFill (Colour (0x99ffffff));
  53466. p.clear();
  53467. p.addEllipse (0.0f, 0.0f, 100.0f, 100.0f);
  53468. p.addRectangle (indent, 50.0f - thickness, 100.0f - indent * 2.0f, thickness * 2.0f);
  53469. p.addRectangle (50.0f - thickness, indent, thickness * 2.0f, 50.0f - indent - thickness);
  53470. p.addRectangle (50.0f - thickness, 50.0f + thickness, thickness * 2.0f, 50.0f - indent - thickness);
  53471. p.setUsingNonZeroWinding (false);
  53472. DrawablePath dp;
  53473. dp.setPath (p);
  53474. dp.setFill (Colour (0x59000000));
  53475. DrawableComposite normalImage;
  53476. normalImage.insertDrawable (ellipse);
  53477. normalImage.insertDrawable (dp);
  53478. dp.setFill (Colour (0xcc000000));
  53479. DrawableComposite overImage;
  53480. overImage.insertDrawable (ellipse);
  53481. overImage.insertDrawable (dp);
  53482. DrawableButton* db = new DrawableButton (T("tabs"), DrawableButton::ImageFitted);
  53483. db->setImages (&normalImage, &overImage, 0);
  53484. return db;
  53485. }
  53486. void LookAndFeel::drawTableHeaderBackground (Graphics& g, TableHeaderComponent& header)
  53487. {
  53488. g.fillAll (Colours::white);
  53489. const int w = header.getWidth();
  53490. const int h = header.getHeight();
  53491. g.setGradientFill (ColourGradient (Colour (0xffe8ebf9), 0.0f, h * 0.5f,
  53492. Colour (0xfff6f8f9), 0.0f, h - 1.0f,
  53493. false));
  53494. g.fillRect (0, h / 2, w, h);
  53495. g.setColour (Colour (0x33000000));
  53496. g.fillRect (0, h - 1, w, 1);
  53497. for (int i = header.getNumColumns (true); --i >= 0;)
  53498. g.fillRect (header.getColumnPosition (i).getRight() - 1, 0, 1, h - 1);
  53499. }
  53500. void LookAndFeel::drawTableHeaderColumn (Graphics& g, const String& columnName, int /*columnId*/,
  53501. int width, int height,
  53502. bool isMouseOver, bool isMouseDown,
  53503. int columnFlags)
  53504. {
  53505. if (isMouseDown)
  53506. g.fillAll (Colour (0x8899aadd));
  53507. else if (isMouseOver)
  53508. g.fillAll (Colour (0x5599aadd));
  53509. int rightOfText = width - 4;
  53510. if ((columnFlags & (TableHeaderComponent::sortedForwards | TableHeaderComponent::sortedBackwards)) != 0)
  53511. {
  53512. const float top = height * ((columnFlags & TableHeaderComponent::sortedForwards) != 0 ? 0.35f : (1.0f - 0.35f));
  53513. const float bottom = height - top;
  53514. const float w = height * 0.5f;
  53515. const float x = rightOfText - (w * 1.25f);
  53516. rightOfText = (int) x;
  53517. Path sortArrow;
  53518. sortArrow.addTriangle (x, bottom, x + w * 0.5f, top, x + w, bottom);
  53519. g.setColour (Colour (0x99000000));
  53520. g.fillPath (sortArrow);
  53521. }
  53522. g.setColour (Colours::black);
  53523. g.setFont (height * 0.5f, Font::bold);
  53524. const int textX = 4;
  53525. g.drawFittedText (columnName, textX, 0, rightOfText - textX, height, Justification::centredLeft, 1);
  53526. }
  53527. void LookAndFeel::paintToolbarBackground (Graphics& g, int w, int h, Toolbar& toolbar)
  53528. {
  53529. const Colour background (toolbar.findColour (Toolbar::backgroundColourId));
  53530. g.setGradientFill (ColourGradient (background, 0.0f, 0.0f,
  53531. background.darker (0.1f),
  53532. toolbar.isVertical() ? w - 1.0f : 0.0f,
  53533. toolbar.isVertical() ? 0.0f : h - 1.0f,
  53534. false));
  53535. g.fillAll();
  53536. }
  53537. Button* LookAndFeel::createToolbarMissingItemsButton (Toolbar& /*toolbar*/)
  53538. {
  53539. return createTabBarExtrasButton();
  53540. }
  53541. void LookAndFeel::paintToolbarButtonBackground (Graphics& g, int /*width*/, int /*height*/,
  53542. bool isMouseOver, bool isMouseDown,
  53543. ToolbarItemComponent& component)
  53544. {
  53545. if (isMouseDown)
  53546. g.fillAll (component.findColour (Toolbar::buttonMouseDownBackgroundColourId, true));
  53547. else if (isMouseOver)
  53548. g.fillAll (component.findColour (Toolbar::buttonMouseOverBackgroundColourId, true));
  53549. }
  53550. void LookAndFeel::paintToolbarButtonLabel (Graphics& g, int x, int y, int width, int height,
  53551. const String& text, ToolbarItemComponent& component)
  53552. {
  53553. g.setColour (component.findColour (Toolbar::labelTextColourId, true)
  53554. .withAlpha (component.isEnabled() ? 1.0f : 0.25f));
  53555. const float fontHeight = jmin (14.0f, height * 0.85f);
  53556. g.setFont (fontHeight);
  53557. g.drawFittedText (text,
  53558. x, y, width, height,
  53559. Justification::centred,
  53560. jmax (1, height / (int) fontHeight));
  53561. }
  53562. void LookAndFeel::drawPropertyPanelSectionHeader (Graphics& g, const String& name,
  53563. bool isOpen, int width, int height)
  53564. {
  53565. const int buttonSize = (height * 3) / 4;
  53566. const int buttonIndent = (height - buttonSize) / 2;
  53567. drawTreeviewPlusMinusBox (g, buttonIndent, buttonIndent, buttonSize, buttonSize, ! isOpen, false);
  53568. const int textX = buttonIndent * 2 + buttonSize + 2;
  53569. g.setColour (Colours::black);
  53570. g.setFont (height * 0.7f, Font::bold);
  53571. g.drawText (name, textX, 0, width - textX - 4, height, Justification::centredLeft, true);
  53572. }
  53573. void LookAndFeel::drawPropertyComponentBackground (Graphics& g, int width, int height,
  53574. PropertyComponent&)
  53575. {
  53576. g.setColour (Colour (0x66ffffff));
  53577. g.fillRect (0, 0, width, height - 1);
  53578. }
  53579. void LookAndFeel::drawPropertyComponentLabel (Graphics& g, int, int height,
  53580. PropertyComponent& component)
  53581. {
  53582. g.setColour (Colours::black);
  53583. if (! component.isEnabled())
  53584. g.setOpacity (0.6f);
  53585. g.setFont (jmin (height, 24) * 0.65f);
  53586. const Rectangle r (getPropertyComponentContentPosition (component));
  53587. g.drawFittedText (component.getName(),
  53588. 3, r.getY(), r.getX() - 5, r.getHeight(),
  53589. Justification::centredLeft, 2);
  53590. }
  53591. const Rectangle LookAndFeel::getPropertyComponentContentPosition (PropertyComponent& component)
  53592. {
  53593. return Rectangle (component.getWidth() / 3, 1,
  53594. component.getWidth() - component.getWidth() / 3 - 1, component.getHeight() - 3);
  53595. }
  53596. void LookAndFeel::createFileChooserHeaderText (const String& title,
  53597. const String& instructions,
  53598. GlyphArrangement& text,
  53599. int width)
  53600. {
  53601. text.clear();
  53602. text.addJustifiedText (Font (17.0f, Font::bold), title,
  53603. 8.0f, 22.0f, width - 16.0f,
  53604. Justification::centred);
  53605. text.addJustifiedText (Font (14.0f), instructions,
  53606. 8.0f, 24.0f + 16.0f, width - 16.0f,
  53607. Justification::centred);
  53608. }
  53609. void LookAndFeel::drawFileBrowserRow (Graphics& g, int width, int height,
  53610. const String& filename, Image* icon,
  53611. const String& fileSizeDescription,
  53612. const String& fileTimeDescription,
  53613. const bool isDirectory,
  53614. const bool isItemSelected,
  53615. const int /*itemIndex*/)
  53616. {
  53617. if (isItemSelected)
  53618. g.fillAll (findColour (DirectoryContentsDisplayComponent::highlightColourId));
  53619. g.setColour (findColour (DirectoryContentsDisplayComponent::textColourId));
  53620. g.setFont (height * 0.7f);
  53621. Image* im = icon;
  53622. Image* toRelease = 0;
  53623. if (im == 0)
  53624. {
  53625. toRelease = im = (isDirectory ? getDefaultFolderImage()
  53626. : getDefaultDocumentFileImage());
  53627. }
  53628. const int x = 32;
  53629. if (im != 0)
  53630. {
  53631. g.drawImageWithin (im, 2, 2, x - 4, height - 4,
  53632. RectanglePlacement::centred | RectanglePlacement::onlyReduceInSize,
  53633. false);
  53634. ImageCache::release (toRelease);
  53635. }
  53636. if (width > 450 && ! isDirectory)
  53637. {
  53638. const int sizeX = roundToInt (width * 0.7f);
  53639. const int dateX = roundToInt (width * 0.8f);
  53640. g.drawFittedText (filename,
  53641. x, 0, sizeX - x, height,
  53642. Justification::centredLeft, 1);
  53643. g.setFont (height * 0.5f);
  53644. g.setColour (Colours::darkgrey);
  53645. if (! isDirectory)
  53646. {
  53647. g.drawFittedText (fileSizeDescription,
  53648. sizeX, 0, dateX - sizeX - 8, height,
  53649. Justification::centredRight, 1);
  53650. g.drawFittedText (fileTimeDescription,
  53651. dateX, 0, width - 8 - dateX, height,
  53652. Justification::centredRight, 1);
  53653. }
  53654. }
  53655. else
  53656. {
  53657. g.drawFittedText (filename,
  53658. x, 0, width - x, height,
  53659. Justification::centredLeft, 1);
  53660. }
  53661. }
  53662. Button* LookAndFeel::createFileBrowserGoUpButton()
  53663. {
  53664. DrawableButton* goUpButton = new DrawableButton ("up", DrawableButton::ImageOnButtonBackground);
  53665. Path arrowPath;
  53666. arrowPath.addArrow (50.0f, 100.0f, 50.0f, 0.0f, 40.0f, 100.0f, 50.0f);
  53667. DrawablePath arrowImage;
  53668. arrowImage.setFill (Colours::black.withAlpha (0.4f));
  53669. arrowImage.setPath (arrowPath);
  53670. goUpButton->setImages (&arrowImage);
  53671. return goUpButton;
  53672. }
  53673. void LookAndFeel::layoutFileBrowserComponent (FileBrowserComponent& browserComp,
  53674. DirectoryContentsDisplayComponent* fileListComponent,
  53675. FilePreviewComponent* previewComp,
  53676. ComboBox* currentPathBox,
  53677. TextEditor* filenameBox,
  53678. Button* goUpButton)
  53679. {
  53680. const int x = 8;
  53681. int w = browserComp.getWidth() - x - x;
  53682. if (previewComp != 0)
  53683. {
  53684. const int previewWidth = w / 3;
  53685. previewComp->setBounds (x + w - previewWidth, 0, previewWidth, browserComp.getHeight());
  53686. w -= previewWidth + 4;
  53687. }
  53688. int y = 4;
  53689. const int controlsHeight = 22;
  53690. const int bottomSectionHeight = controlsHeight + 8;
  53691. const int upButtonWidth = 50;
  53692. currentPathBox->setBounds (x, y, w - upButtonWidth - 6, controlsHeight);
  53693. goUpButton->setBounds (x + w - upButtonWidth, y, upButtonWidth, controlsHeight);
  53694. y += controlsHeight + 4;
  53695. Component* const listAsComp = dynamic_cast <Component*> (fileListComponent);
  53696. listAsComp->setBounds (x, y, w, browserComp.getHeight() - y - bottomSectionHeight);
  53697. y = listAsComp->getBottom() + 4;
  53698. filenameBox->setBounds (x + 50, y, w - 50, controlsHeight);
  53699. }
  53700. Image* LookAndFeel::getDefaultFolderImage()
  53701. {
  53702. 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,
  53703. 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,
  53704. 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,
  53705. 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,
  53706. 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,
  53707. 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,
  53708. 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,
  53709. 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,
  53710. 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,
  53711. 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,
  53712. 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,
  53713. 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,
  53714. 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,
  53715. 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,
  53716. 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,
  53717. 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,
  53718. 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,
  53719. 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,
  53720. 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,
  53721. 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,
  53722. 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,
  53723. 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,
  53724. 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,
  53725. 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,
  53726. 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,
  53727. 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,
  53728. 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,
  53729. 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,
  53730. 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,
  53731. 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,
  53732. 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,
  53733. 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,
  53734. 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,
  53735. 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,
  53736. 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,
  53737. 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,
  53738. 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,
  53739. 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,
  53740. 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,
  53741. 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,
  53742. 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,
  53743. 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,
  53744. 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,
  53745. 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};
  53746. return ImageCache::getFromMemory (foldericon_png, sizeof (foldericon_png));
  53747. }
  53748. Image* LookAndFeel::getDefaultDocumentFileImage()
  53749. {
  53750. 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,
  53751. 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,
  53752. 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,
  53753. 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,
  53754. 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,
  53755. 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,
  53756. 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,
  53757. 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,
  53758. 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,
  53759. 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,
  53760. 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,
  53761. 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,
  53762. 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,
  53763. 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,
  53764. 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,
  53765. 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,
  53766. 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,
  53767. 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,
  53768. 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,
  53769. 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,
  53770. 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,
  53771. 174,66,96,130,0,0};
  53772. return ImageCache::getFromMemory (fileicon_png, sizeof (fileicon_png));
  53773. }
  53774. void LookAndFeel::playAlertSound()
  53775. {
  53776. PlatformUtilities::beep();
  53777. }
  53778. void LookAndFeel::drawLevelMeter (Graphics& g, int width, int height, float level)
  53779. {
  53780. g.setColour (Colours::white.withAlpha (0.7f));
  53781. g.fillRoundedRectangle (0.0f, 0.0f, (float) width, (float) height, 3.0f);
  53782. g.setColour (Colours::black.withAlpha (0.2f));
  53783. g.drawRoundedRectangle (1.0f, 1.0f, width - 2.0f, height - 2.0f, 3.0f, 1.0f);
  53784. const int totalBlocks = 7;
  53785. const int numBlocks = roundToInt (totalBlocks * level);
  53786. const float w = (width - 6.0f) / (float) totalBlocks;
  53787. for (int i = 0; i < totalBlocks; ++i)
  53788. {
  53789. if (i >= numBlocks)
  53790. g.setColour (Colours::lightblue.withAlpha (0.6f));
  53791. else
  53792. g.setColour (i < totalBlocks - 1 ? Colours::blue.withAlpha (0.5f)
  53793. : Colours::red);
  53794. g.fillRoundedRectangle (3.0f + i * w + w * 0.1f, 3.0f, w * 0.8f, height - 6.0f, w * 0.4f);
  53795. }
  53796. }
  53797. void LookAndFeel::drawKeymapChangeButton (Graphics& g, int width, int height, Button& button, const String& keyDescription)
  53798. {
  53799. const Colour textColour (button.findColour (KeyMappingEditorComponent::textColourId, true));
  53800. if (keyDescription.isNotEmpty())
  53801. {
  53802. if (button.isEnabled())
  53803. {
  53804. const float alpha = button.isDown() ? 0.3f : (button.isOver() ? 0.15f : 0.08f);
  53805. g.fillAll (textColour.withAlpha (alpha));
  53806. g.setOpacity (0.3f);
  53807. g.drawBevel (0, 0, width, height, 2);
  53808. }
  53809. g.setColour (textColour);
  53810. g.setFont (height * 0.6f);
  53811. g.drawFittedText (keyDescription,
  53812. 3, 0, width - 6, height,
  53813. Justification::centred, 1);
  53814. }
  53815. else
  53816. {
  53817. const float thickness = 7.0f;
  53818. const float indent = 22.0f;
  53819. Path p;
  53820. p.addEllipse (0.0f, 0.0f, 100.0f, 100.0f);
  53821. p.addRectangle (indent, 50.0f - thickness, 100.0f - indent * 2.0f, thickness * 2.0f);
  53822. p.addRectangle (50.0f - thickness, indent, thickness * 2.0f, 50.0f - indent - thickness);
  53823. p.addRectangle (50.0f - thickness, 50.0f + thickness, thickness * 2.0f, 50.0f - indent - thickness);
  53824. p.setUsingNonZeroWinding (false);
  53825. g.setColour (textColour.withAlpha (button.isDown() ? 0.7f : (button.isOver() ? 0.5f : 0.3f)));
  53826. g.fillPath (p, p.getTransformToScaleToFit (2.0f, 2.0f, width - 4.0f, height - 4.0f, true));
  53827. }
  53828. if (button.hasKeyboardFocus (false))
  53829. {
  53830. g.setColour (textColour.withAlpha (0.4f));
  53831. g.drawRect (0, 0, width, height);
  53832. }
  53833. }
  53834. static void createRoundedPath (Path& p,
  53835. const float x, const float y,
  53836. const float w, const float h,
  53837. const float cs,
  53838. const bool curveTopLeft, const bool curveTopRight,
  53839. const bool curveBottomLeft, const bool curveBottomRight) throw()
  53840. {
  53841. const float cs2 = 2.0f * cs;
  53842. if (curveTopLeft)
  53843. {
  53844. p.startNewSubPath (x, y + cs);
  53845. p.addArc (x, y, cs2, cs2, float_Pi * 1.5f, float_Pi * 2.0f);
  53846. }
  53847. else
  53848. {
  53849. p.startNewSubPath (x, y);
  53850. }
  53851. if (curveTopRight)
  53852. {
  53853. p.lineTo (x + w - cs, y);
  53854. p.addArc (x + w - cs2, y, cs2, cs2, 0.0f, float_Pi * 0.5f);
  53855. }
  53856. else
  53857. {
  53858. p.lineTo (x + w, y);
  53859. }
  53860. if (curveBottomRight)
  53861. {
  53862. p.lineTo (x + w, y + h - cs);
  53863. p.addArc (x + w - cs2, y + h - cs2, cs2, cs2, float_Pi * 0.5f, float_Pi);
  53864. }
  53865. else
  53866. {
  53867. p.lineTo (x + w, y + h);
  53868. }
  53869. if (curveBottomLeft)
  53870. {
  53871. p.lineTo (x + cs, y + h);
  53872. p.addArc (x, y + h - cs2, cs2, cs2, float_Pi, float_Pi * 1.5f);
  53873. }
  53874. else
  53875. {
  53876. p.lineTo (x, y + h);
  53877. }
  53878. p.closeSubPath();
  53879. }
  53880. void LookAndFeel::drawShinyButtonShape (Graphics& g,
  53881. float x, float y, float w, float h,
  53882. float maxCornerSize,
  53883. const Colour& baseColour,
  53884. const float strokeWidth,
  53885. const bool flatOnLeft,
  53886. const bool flatOnRight,
  53887. const bool flatOnTop,
  53888. const bool flatOnBottom) throw()
  53889. {
  53890. if (w <= strokeWidth * 1.1f || h <= strokeWidth * 1.1f)
  53891. return;
  53892. const float cs = jmin (maxCornerSize, w * 0.5f, h * 0.5f);
  53893. Path outline;
  53894. createRoundedPath (outline, x, y, w, h, cs,
  53895. ! (flatOnLeft || flatOnTop),
  53896. ! (flatOnRight || flatOnTop),
  53897. ! (flatOnLeft || flatOnBottom),
  53898. ! (flatOnRight || flatOnBottom));
  53899. ColourGradient cg (baseColour, 0.0f, y,
  53900. baseColour.overlaidWith (Colour (0x070000ff)), 0.0f, y + h,
  53901. false);
  53902. cg.addColour (0.5, baseColour.overlaidWith (Colour (0x33ffffff)));
  53903. cg.addColour (0.51, baseColour.overlaidWith (Colour (0x110000ff)));
  53904. g.setGradientFill (cg);
  53905. g.fillPath (outline);
  53906. g.setColour (Colour (0x80000000));
  53907. g.strokePath (outline, PathStrokeType (strokeWidth));
  53908. }
  53909. void LookAndFeel::drawGlassSphere (Graphics& g,
  53910. const float x, const float y,
  53911. const float diameter,
  53912. const Colour& colour,
  53913. const float outlineThickness) throw()
  53914. {
  53915. if (diameter <= outlineThickness)
  53916. return;
  53917. Path p;
  53918. p.addEllipse (x, y, diameter, diameter);
  53919. {
  53920. ColourGradient cg (Colours::white.overlaidWith (colour.withMultipliedAlpha (0.3f)), 0, y,
  53921. Colours::white.overlaidWith (colour.withMultipliedAlpha (0.3f)), 0, y + diameter, false);
  53922. cg.addColour (0.4, Colours::white.overlaidWith (colour));
  53923. g.setGradientFill (cg);
  53924. g.fillPath (p);
  53925. }
  53926. g.setGradientFill (ColourGradient (Colours::white, 0, y + diameter * 0.06f,
  53927. Colours::transparentWhite, 0, y + diameter * 0.3f, false));
  53928. g.fillEllipse (x + diameter * 0.2f, y + diameter * 0.05f, diameter * 0.6f, diameter * 0.4f);
  53929. ColourGradient cg (Colours::transparentBlack,
  53930. x + diameter * 0.5f, y + diameter * 0.5f,
  53931. Colours::black.withAlpha (0.5f * outlineThickness * colour.getFloatAlpha()),
  53932. x, y + diameter * 0.5f, true);
  53933. cg.addColour (0.7, Colours::transparentBlack);
  53934. cg.addColour (0.8, Colours::black.withAlpha (0.1f * outlineThickness));
  53935. g.setGradientFill (cg);
  53936. g.fillPath (p);
  53937. g.setColour (Colours::black.withAlpha (0.5f * colour.getFloatAlpha()));
  53938. g.drawEllipse (x, y, diameter, diameter, outlineThickness);
  53939. }
  53940. void LookAndFeel::drawGlassPointer (Graphics& g,
  53941. const float x, const float y,
  53942. const float diameter,
  53943. const Colour& colour, const float outlineThickness,
  53944. const int direction) throw()
  53945. {
  53946. if (diameter <= outlineThickness)
  53947. return;
  53948. Path p;
  53949. p.startNewSubPath (x + diameter * 0.5f, y);
  53950. p.lineTo (x + diameter, y + diameter * 0.6f);
  53951. p.lineTo (x + diameter, y + diameter);
  53952. p.lineTo (x, y + diameter);
  53953. p.lineTo (x, y + diameter * 0.6f);
  53954. p.closeSubPath();
  53955. p.applyTransform (AffineTransform::rotation (direction * (float_Pi * 0.5f), x + diameter * 0.5f, y + diameter * 0.5f));
  53956. {
  53957. ColourGradient cg (Colours::white.overlaidWith (colour.withMultipliedAlpha (0.3f)), 0, y,
  53958. Colours::white.overlaidWith (colour.withMultipliedAlpha (0.3f)), 0, y + diameter, false);
  53959. cg.addColour (0.4, Colours::white.overlaidWith (colour));
  53960. g.setGradientFill (cg);
  53961. g.fillPath (p);
  53962. }
  53963. ColourGradient cg (Colours::transparentBlack,
  53964. x + diameter * 0.5f, y + diameter * 0.5f,
  53965. Colours::black.withAlpha (0.5f * outlineThickness * colour.getFloatAlpha()),
  53966. x - diameter * 0.2f, y + diameter * 0.5f, true);
  53967. cg.addColour (0.5, Colours::transparentBlack);
  53968. cg.addColour (0.7, Colours::black.withAlpha (0.07f * outlineThickness));
  53969. g.setGradientFill (cg);
  53970. g.fillPath (p);
  53971. g.setColour (Colours::black.withAlpha (0.5f * colour.getFloatAlpha()));
  53972. g.strokePath (p, PathStrokeType (outlineThickness));
  53973. }
  53974. void LookAndFeel::drawGlassLozenge (Graphics& g,
  53975. const float x, const float y,
  53976. const float width, const float height,
  53977. const Colour& colour,
  53978. const float outlineThickness,
  53979. const float cornerSize,
  53980. const bool flatOnLeft,
  53981. const bool flatOnRight,
  53982. const bool flatOnTop,
  53983. const bool flatOnBottom) throw()
  53984. {
  53985. if (width <= outlineThickness || height <= outlineThickness)
  53986. return;
  53987. const int intX = (int) x;
  53988. const int intY = (int) y;
  53989. const int intW = (int) width;
  53990. const int intH = (int) height;
  53991. const float cs = cornerSize < 0 ? jmin (width * 0.5f, height * 0.5f) : cornerSize;
  53992. const float edgeBlurRadius = height * 0.75f + (height - cs * 2.0f);
  53993. const int intEdge = (int) edgeBlurRadius;
  53994. Path outline;
  53995. createRoundedPath (outline, x, y, width, height, cs,
  53996. ! (flatOnLeft || flatOnTop),
  53997. ! (flatOnRight || flatOnTop),
  53998. ! (flatOnLeft || flatOnBottom),
  53999. ! (flatOnRight || flatOnBottom));
  54000. {
  54001. ColourGradient cg (colour.darker (0.2f), 0, y,
  54002. colour.darker (0.2f), 0, y + height, false);
  54003. cg.addColour (0.03, colour.withMultipliedAlpha (0.3f));
  54004. cg.addColour (0.4, colour);
  54005. cg.addColour (0.97, colour.withMultipliedAlpha (0.3f));
  54006. g.setGradientFill (cg);
  54007. g.fillPath (outline);
  54008. }
  54009. ColourGradient cg (Colours::transparentBlack, x + edgeBlurRadius, y + height * 0.5f,
  54010. colour.darker (0.2f), x, y + height * 0.5f, true);
  54011. cg.addColour (jlimit (0.0, 1.0, 1.0 - (cs * 0.5f) / edgeBlurRadius), Colours::transparentBlack);
  54012. cg.addColour (jlimit (0.0, 1.0, 1.0 - (cs * 0.25f) / edgeBlurRadius), colour.darker (0.2f).withMultipliedAlpha (0.3f));
  54013. if (! (flatOnLeft || flatOnTop || flatOnBottom))
  54014. {
  54015. g.saveState();
  54016. g.setGradientFill (cg);
  54017. g.reduceClipRegion (intX, intY, intEdge, intH);
  54018. g.fillPath (outline);
  54019. g.restoreState();
  54020. }
  54021. if (! (flatOnRight || flatOnTop || flatOnBottom))
  54022. {
  54023. cg.x1 = x + width - edgeBlurRadius;
  54024. cg.x2 = x + width;
  54025. g.saveState();
  54026. g.setGradientFill (cg);
  54027. g.reduceClipRegion (intX + intW - intEdge, intY, 2 + intEdge, intH);
  54028. g.fillPath (outline);
  54029. g.restoreState();
  54030. }
  54031. {
  54032. const float leftIndent = flatOnLeft ? 0.0f : cs * 0.4f;
  54033. const float rightIndent = flatOnRight ? 0.0f : cs * 0.4f;
  54034. Path highlight;
  54035. createRoundedPath (highlight,
  54036. x + leftIndent,
  54037. y + cs * 0.1f,
  54038. width - (leftIndent + rightIndent),
  54039. height * 0.4f, cs * 0.4f,
  54040. ! (flatOnLeft || flatOnTop),
  54041. ! (flatOnRight || flatOnTop),
  54042. ! (flatOnLeft || flatOnBottom),
  54043. ! (flatOnRight || flatOnBottom));
  54044. g.setGradientFill (ColourGradient (colour.brighter (10.0f), 0, y + height * 0.06f,
  54045. Colours::transparentWhite, 0, y + height * 0.4f, false));
  54046. g.fillPath (highlight);
  54047. }
  54048. g.setColour (colour.darker().withMultipliedAlpha (1.5f));
  54049. g.strokePath (outline, PathStrokeType (outlineThickness));
  54050. }
  54051. END_JUCE_NAMESPACE
  54052. /********* End of inlined file: juce_LookAndFeel.cpp *********/
  54053. /********* Start of inlined file: juce_OldSchoolLookAndFeel.cpp *********/
  54054. BEGIN_JUCE_NAMESPACE
  54055. OldSchoolLookAndFeel::OldSchoolLookAndFeel()
  54056. {
  54057. setColour (TextButton::buttonColourId, Colour (0xffbbbbff));
  54058. setColour (ListBox::outlineColourId, findColour (ComboBox::outlineColourId));
  54059. setColour (ScrollBar::thumbColourId, Colour (0xffbbbbdd));
  54060. setColour (ScrollBar::backgroundColourId, Colours::transparentBlack);
  54061. setColour (Slider::thumbColourId, Colours::white);
  54062. setColour (Slider::trackColourId, Colour (0x7f000000));
  54063. setColour (Slider::textBoxOutlineColourId, Colours::grey);
  54064. setColour (ProgressBar::backgroundColourId, Colours::white.withAlpha (0.6f));
  54065. setColour (ProgressBar::foregroundColourId, Colours::green.withAlpha (0.7f));
  54066. setColour (PopupMenu::backgroundColourId, Colour (0xffeef5f8));
  54067. setColour (PopupMenu::highlightedBackgroundColourId, Colour (0xbfa4c2ce));
  54068. setColour (PopupMenu::highlightedTextColourId, Colours::black);
  54069. setColour (TextEditor::focusedOutlineColourId, findColour (TextButton::buttonColourId));
  54070. scrollbarShadow.setShadowProperties (2.2f, 0.5f, 0, 0);
  54071. }
  54072. OldSchoolLookAndFeel::~OldSchoolLookAndFeel()
  54073. {
  54074. }
  54075. void OldSchoolLookAndFeel::drawButtonBackground (Graphics& g,
  54076. Button& button,
  54077. const Colour& backgroundColour,
  54078. bool isMouseOverButton,
  54079. bool isButtonDown)
  54080. {
  54081. const int width = button.getWidth();
  54082. const int height = button.getHeight();
  54083. const float indent = 2.0f;
  54084. const int cornerSize = jmin (roundToInt (width * 0.4f),
  54085. roundToInt (height * 0.4f));
  54086. Path p;
  54087. p.addRoundedRectangle (indent, indent,
  54088. width - indent * 2.0f,
  54089. height - indent * 2.0f,
  54090. (float) cornerSize);
  54091. Colour bc (backgroundColour.withMultipliedSaturation (0.3f));
  54092. if (isMouseOverButton)
  54093. {
  54094. if (isButtonDown)
  54095. bc = bc.brighter();
  54096. else if (bc.getBrightness() > 0.5f)
  54097. bc = bc.darker (0.1f);
  54098. else
  54099. bc = bc.brighter (0.1f);
  54100. }
  54101. g.setColour (bc);
  54102. g.fillPath (p);
  54103. g.setColour (bc.contrasting().withAlpha ((isMouseOverButton) ? 0.6f : 0.4f));
  54104. g.strokePath (p, PathStrokeType ((isMouseOverButton) ? 2.0f : 1.4f));
  54105. }
  54106. void OldSchoolLookAndFeel::drawTickBox (Graphics& g,
  54107. Component& /*component*/,
  54108. int x, int y, int w, int h,
  54109. const bool ticked,
  54110. const bool isEnabled,
  54111. const bool /*isMouseOverButton*/,
  54112. const bool isButtonDown)
  54113. {
  54114. Path box;
  54115. box.addRoundedRectangle (0.0f, 2.0f, 6.0f, 6.0f, 1.0f);
  54116. g.setColour (isEnabled ? Colours::blue.withAlpha (isButtonDown ? 0.3f : 0.1f)
  54117. : Colours::lightgrey.withAlpha (0.1f));
  54118. AffineTransform trans (AffineTransform::scale (w / 9.0f, h / 9.0f)
  54119. .translated ((float) x, (float) y));
  54120. g.fillPath (box, trans);
  54121. g.setColour (Colours::black.withAlpha (0.6f));
  54122. g.strokePath (box, PathStrokeType (0.9f), trans);
  54123. if (ticked)
  54124. {
  54125. Path tick;
  54126. tick.startNewSubPath (1.5f, 3.0f);
  54127. tick.lineTo (3.0f, 6.0f);
  54128. tick.lineTo (6.0f, 0.0f);
  54129. g.setColour (isEnabled ? Colours::black : Colours::grey);
  54130. g.strokePath (tick, PathStrokeType (2.5f), trans);
  54131. }
  54132. }
  54133. void OldSchoolLookAndFeel::drawToggleButton (Graphics& g,
  54134. ToggleButton& button,
  54135. bool isMouseOverButton,
  54136. bool isButtonDown)
  54137. {
  54138. if (button.hasKeyboardFocus (true))
  54139. {
  54140. g.setColour (button.findColour (TextEditor::focusedOutlineColourId));
  54141. g.drawRect (0, 0, button.getWidth(), button.getHeight());
  54142. }
  54143. const int tickWidth = jmin (20, button.getHeight() - 4);
  54144. drawTickBox (g, button, 4, (button.getHeight() - tickWidth) / 2,
  54145. tickWidth, tickWidth,
  54146. button.getToggleState(),
  54147. button.isEnabled(),
  54148. isMouseOverButton,
  54149. isButtonDown);
  54150. g.setColour (button.findColour (ToggleButton::textColourId));
  54151. g.setFont (jmin (15.0f, button.getHeight() * 0.6f));
  54152. if (! button.isEnabled())
  54153. g.setOpacity (0.5f);
  54154. const int textX = tickWidth + 5;
  54155. g.drawFittedText (button.getButtonText(),
  54156. textX, 4,
  54157. button.getWidth() - textX - 2, button.getHeight() - 8,
  54158. Justification::centredLeft, 10);
  54159. }
  54160. void OldSchoolLookAndFeel::drawProgressBar (Graphics& g, ProgressBar& progressBar,
  54161. int width, int height,
  54162. double progress, const String& textToShow)
  54163. {
  54164. if (progress < 0 || progress >= 1.0)
  54165. {
  54166. LookAndFeel::drawProgressBar (g, progressBar, width, height, progress, textToShow);
  54167. }
  54168. else
  54169. {
  54170. const Colour background (progressBar.findColour (ProgressBar::backgroundColourId));
  54171. const Colour foreground (progressBar.findColour (ProgressBar::foregroundColourId));
  54172. g.fillAll (background);
  54173. g.setColour (foreground);
  54174. g.fillRect (1, 1,
  54175. jlimit (0, width - 2, roundToInt (progress * (width - 2))),
  54176. height - 2);
  54177. if (textToShow.isNotEmpty())
  54178. {
  54179. g.setColour (Colour::contrasting (background, foreground));
  54180. g.setFont (height * 0.6f);
  54181. g.drawText (textToShow, 0, 0, width, height, Justification::centred, false);
  54182. }
  54183. }
  54184. }
  54185. void OldSchoolLookAndFeel::drawScrollbarButton (Graphics& g,
  54186. ScrollBar& bar,
  54187. int width, int height,
  54188. int buttonDirection,
  54189. bool isScrollbarVertical,
  54190. bool isMouseOverButton,
  54191. bool isButtonDown)
  54192. {
  54193. if (isScrollbarVertical)
  54194. width -= 2;
  54195. else
  54196. height -= 2;
  54197. Path p;
  54198. if (buttonDirection == 0)
  54199. p.addTriangle (width * 0.5f, height * 0.2f,
  54200. width * 0.1f, height * 0.7f,
  54201. width * 0.9f, height * 0.7f);
  54202. else if (buttonDirection == 1)
  54203. p.addTriangle (width * 0.8f, height * 0.5f,
  54204. width * 0.3f, height * 0.1f,
  54205. width * 0.3f, height * 0.9f);
  54206. else if (buttonDirection == 2)
  54207. p.addTriangle (width * 0.5f, height * 0.8f,
  54208. width * 0.1f, height * 0.3f,
  54209. width * 0.9f, height * 0.3f);
  54210. else if (buttonDirection == 3)
  54211. p.addTriangle (width * 0.2f, height * 0.5f,
  54212. width * 0.7f, height * 0.1f,
  54213. width * 0.7f, height * 0.9f);
  54214. if (isButtonDown)
  54215. g.setColour (Colours::white);
  54216. else if (isMouseOverButton)
  54217. g.setColour (Colours::white.withAlpha (0.7f));
  54218. else
  54219. g.setColour (bar.findColour (ScrollBar::thumbColourId).withAlpha (0.5f));
  54220. g.fillPath (p);
  54221. g.setColour (Colours::black.withAlpha (0.5f));
  54222. g.strokePath (p, PathStrokeType (0.5f));
  54223. }
  54224. void OldSchoolLookAndFeel::drawScrollbar (Graphics& g,
  54225. ScrollBar& bar,
  54226. int x, int y,
  54227. int width, int height,
  54228. bool isScrollbarVertical,
  54229. int thumbStartPosition,
  54230. int thumbSize,
  54231. bool isMouseOver,
  54232. bool isMouseDown)
  54233. {
  54234. g.fillAll (bar.findColour (ScrollBar::backgroundColourId));
  54235. g.setColour (bar.findColour (ScrollBar::thumbColourId)
  54236. .withAlpha ((isMouseOver || isMouseDown) ? 0.4f : 0.15f));
  54237. if (thumbSize > 0.0f)
  54238. {
  54239. Rectangle thumb;
  54240. if (isScrollbarVertical)
  54241. {
  54242. width -= 2;
  54243. g.fillRect (x + roundToInt (width * 0.35f), y,
  54244. roundToInt (width * 0.3f), height);
  54245. thumb.setBounds (x + 1, thumbStartPosition,
  54246. width - 2, thumbSize);
  54247. }
  54248. else
  54249. {
  54250. height -= 2;
  54251. g.fillRect (x, y + roundToInt (height * 0.35f),
  54252. width, roundToInt (height * 0.3f));
  54253. thumb.setBounds (thumbStartPosition, y + 1,
  54254. thumbSize, height - 2);
  54255. }
  54256. g.setColour (bar.findColour (ScrollBar::thumbColourId)
  54257. .withAlpha ((isMouseOver || isMouseDown) ? 0.95f : 0.7f));
  54258. g.fillRect (thumb);
  54259. g.setColour (Colours::black.withAlpha ((isMouseOver || isMouseDown) ? 0.4f : 0.25f));
  54260. g.drawRect (thumb.getX(), thumb.getY(), thumb.getWidth(), thumb.getHeight());
  54261. if (thumbSize > 16)
  54262. {
  54263. for (int i = 3; --i >= 0;)
  54264. {
  54265. const float linePos = thumbStartPosition + thumbSize / 2 + (i - 1) * 4.0f;
  54266. g.setColour (Colours::black.withAlpha (0.15f));
  54267. if (isScrollbarVertical)
  54268. {
  54269. g.drawLine (x + width * 0.2f, linePos, width * 0.8f, linePos);
  54270. g.setColour (Colours::white.withAlpha (0.15f));
  54271. g.drawLine (width * 0.2f, linePos - 1, width * 0.8f, linePos - 1);
  54272. }
  54273. else
  54274. {
  54275. g.drawLine (linePos, height * 0.2f, linePos, height * 0.8f);
  54276. g.setColour (Colours::white.withAlpha (0.15f));
  54277. g.drawLine (linePos - 1, height * 0.2f, linePos - 1, height * 0.8f);
  54278. }
  54279. }
  54280. }
  54281. }
  54282. }
  54283. ImageEffectFilter* OldSchoolLookAndFeel::getScrollbarEffect()
  54284. {
  54285. return &scrollbarShadow;
  54286. }
  54287. void OldSchoolLookAndFeel::drawPopupMenuBackground (Graphics& g, int width, int height)
  54288. {
  54289. g.fillAll (findColour (PopupMenu::backgroundColourId));
  54290. g.setColour (Colours::black.withAlpha (0.6f));
  54291. g.drawRect (0, 0, width, height);
  54292. }
  54293. void OldSchoolLookAndFeel::drawMenuBarBackground (Graphics& g, int /*width*/, int /*height*/,
  54294. bool, MenuBarComponent& menuBar)
  54295. {
  54296. g.fillAll (menuBar.findColour (PopupMenu::backgroundColourId));
  54297. }
  54298. void OldSchoolLookAndFeel::drawTextEditorOutline (Graphics& g, int width, int height, TextEditor& textEditor)
  54299. {
  54300. if (textEditor.isEnabled())
  54301. {
  54302. g.setColour (textEditor.findColour (TextEditor::outlineColourId));
  54303. g.drawRect (0, 0, width, height);
  54304. }
  54305. }
  54306. void OldSchoolLookAndFeel::drawComboBox (Graphics& g, int width, int height,
  54307. const bool isButtonDown,
  54308. int buttonX, int buttonY,
  54309. int buttonW, int buttonH,
  54310. ComboBox& box)
  54311. {
  54312. g.fillAll (box.findColour (ComboBox::backgroundColourId));
  54313. g.setColour (box.findColour ((isButtonDown) ? ComboBox::buttonColourId
  54314. : ComboBox::backgroundColourId));
  54315. g.fillRect (buttonX, buttonY, buttonW, buttonH);
  54316. g.setColour (box.findColour (ComboBox::outlineColourId));
  54317. g.drawRect (0, 0, width, height);
  54318. const float arrowX = 0.2f;
  54319. const float arrowH = 0.3f;
  54320. if (box.isEnabled())
  54321. {
  54322. Path p;
  54323. p.addTriangle (buttonX + buttonW * 0.5f, buttonY + buttonH * (0.45f - arrowH),
  54324. buttonX + buttonW * (1.0f - arrowX), buttonY + buttonH * 0.45f,
  54325. buttonX + buttonW * arrowX, buttonY + buttonH * 0.45f);
  54326. p.addTriangle (buttonX + buttonW * 0.5f, buttonY + buttonH * (0.55f + arrowH),
  54327. buttonX + buttonW * (1.0f - arrowX), buttonY + buttonH * 0.55f,
  54328. buttonX + buttonW * arrowX, buttonY + buttonH * 0.55f);
  54329. g.setColour (box.findColour ((isButtonDown) ? ComboBox::backgroundColourId
  54330. : ComboBox::buttonColourId));
  54331. g.fillPath (p);
  54332. }
  54333. }
  54334. const Font OldSchoolLookAndFeel::getComboBoxFont (ComboBox& box)
  54335. {
  54336. Font f (jmin (15.0f, box.getHeight() * 0.85f));
  54337. f.setHorizontalScale (0.9f);
  54338. return f;
  54339. }
  54340. static void drawTriangle (Graphics& g, float x1, float y1, float x2, float y2, float x3, float y3, const Colour& fill, const Colour& outline) throw()
  54341. {
  54342. Path p;
  54343. p.addTriangle (x1, y1, x2, y2, x3, y3);
  54344. g.setColour (fill);
  54345. g.fillPath (p);
  54346. g.setColour (outline);
  54347. g.strokePath (p, PathStrokeType (0.3f));
  54348. }
  54349. void OldSchoolLookAndFeel::drawLinearSlider (Graphics& g,
  54350. int x, int y,
  54351. int w, int h,
  54352. float sliderPos,
  54353. float minSliderPos,
  54354. float maxSliderPos,
  54355. const Slider::SliderStyle style,
  54356. Slider& slider)
  54357. {
  54358. g.fillAll (slider.findColour (Slider::backgroundColourId));
  54359. if (style == Slider::LinearBar)
  54360. {
  54361. g.setColour (slider.findColour (Slider::thumbColourId));
  54362. g.fillRect (x, y, (int) sliderPos - x, h);
  54363. g.setColour (slider.findColour (Slider::textBoxTextColourId).withMultipliedAlpha (0.5f));
  54364. g.drawRect (x, y, (int) sliderPos - x, h);
  54365. }
  54366. else
  54367. {
  54368. g.setColour (slider.findColour (Slider::trackColourId)
  54369. .withMultipliedAlpha (slider.isEnabled() ? 1.0f : 0.3f));
  54370. if (slider.isHorizontal())
  54371. {
  54372. g.fillRect (x, y + roundToInt (h * 0.6f),
  54373. w, roundToInt (h * 0.2f));
  54374. }
  54375. else
  54376. {
  54377. g.fillRect (x + roundToInt (w * 0.5f - jmin (3.0f, w * 0.1f)), y,
  54378. jmin (4, roundToInt (w * 0.2f)), h);
  54379. }
  54380. float alpha = 0.35f;
  54381. if (slider.isEnabled())
  54382. alpha = slider.isMouseOverOrDragging() ? 1.0f : 0.7f;
  54383. const Colour fill (slider.findColour (Slider::thumbColourId).withAlpha (alpha));
  54384. const Colour outline (Colours::black.withAlpha (slider.isEnabled() ? 0.7f : 0.35f));
  54385. if (style == Slider::TwoValueVertical || style == Slider::ThreeValueVertical)
  54386. {
  54387. drawTriangle (g, x + w * 0.5f + jmin (4.0f, w * 0.3f), minSliderPos,
  54388. x + w * 0.5f - jmin (8.0f, w * 0.4f), minSliderPos - 7.0f,
  54389. x + w * 0.5f - jmin (8.0f, w * 0.4f), minSliderPos,
  54390. fill, outline);
  54391. drawTriangle (g, x + w * 0.5f + jmin (4.0f, w * 0.3f), maxSliderPos,
  54392. x + w * 0.5f - jmin (8.0f, w * 0.4f), maxSliderPos,
  54393. x + w * 0.5f - jmin (8.0f, w * 0.4f), maxSliderPos + 7.0f,
  54394. fill, outline);
  54395. }
  54396. else if (style == Slider::TwoValueHorizontal || style == Slider::ThreeValueHorizontal)
  54397. {
  54398. drawTriangle (g, minSliderPos, y + h * 0.6f - jmin (4.0f, h * 0.3f),
  54399. minSliderPos - 7.0f, y + h * 0.9f ,
  54400. minSliderPos, y + h * 0.9f,
  54401. fill, outline);
  54402. drawTriangle (g, maxSliderPos, y + h * 0.6f - jmin (4.0f, h * 0.3f),
  54403. maxSliderPos, y + h * 0.9f,
  54404. maxSliderPos + 7.0f, y + h * 0.9f,
  54405. fill, outline);
  54406. }
  54407. if (style == Slider::LinearHorizontal || style == Slider::ThreeValueHorizontal)
  54408. {
  54409. drawTriangle (g, sliderPos, y + h * 0.9f,
  54410. sliderPos - 7.0f, y + h * 0.2f,
  54411. sliderPos + 7.0f, y + h * 0.2f,
  54412. fill, outline);
  54413. }
  54414. else if (style == Slider::LinearVertical || style == Slider::ThreeValueVertical)
  54415. {
  54416. drawTriangle (g, x + w * 0.5f - jmin (4.0f, w * 0.3f), sliderPos,
  54417. x + w * 0.5f + jmin (8.0f, w * 0.4f), sliderPos - 7.0f,
  54418. x + w * 0.5f + jmin (8.0f, w * 0.4f), sliderPos + 7.0f,
  54419. fill, outline);
  54420. }
  54421. }
  54422. }
  54423. Button* OldSchoolLookAndFeel::createSliderButton (const bool isIncrement)
  54424. {
  54425. if (isIncrement)
  54426. return new ArrowButton ("u", 0.75f, Colours::white.withAlpha (0.8f));
  54427. else
  54428. return new ArrowButton ("d", 0.25f, Colours::white.withAlpha (0.8f));
  54429. }
  54430. ImageEffectFilter* OldSchoolLookAndFeel::getSliderEffect()
  54431. {
  54432. return &scrollbarShadow;
  54433. }
  54434. int OldSchoolLookAndFeel::getSliderThumbRadius (Slider&)
  54435. {
  54436. return 8;
  54437. }
  54438. void OldSchoolLookAndFeel::drawCornerResizer (Graphics& g,
  54439. int w, int h,
  54440. bool isMouseOver,
  54441. bool isMouseDragging)
  54442. {
  54443. g.setColour ((isMouseOver || isMouseDragging) ? Colours::lightgrey
  54444. : Colours::darkgrey);
  54445. const float lineThickness = jmin (w, h) * 0.1f;
  54446. for (float i = 0.0f; i < 1.0f; i += 0.3f)
  54447. {
  54448. g.drawLine (w * i,
  54449. h + 1.0f,
  54450. w + 1.0f,
  54451. h * i,
  54452. lineThickness);
  54453. }
  54454. }
  54455. Button* OldSchoolLookAndFeel::createDocumentWindowButton (int buttonType)
  54456. {
  54457. Path shape;
  54458. if (buttonType == DocumentWindow::closeButton)
  54459. {
  54460. shape.addLineSegment (0.0f, 0.0f, 1.0f, 1.0f, 0.35f);
  54461. shape.addLineSegment (1.0f, 0.0f, 0.0f, 1.0f, 0.35f);
  54462. ShapeButton* const b = new ShapeButton ("close",
  54463. Colour (0x7fff3333),
  54464. Colour (0xd7ff3333),
  54465. Colour (0xf7ff3333));
  54466. b->setShape (shape, true, true, true);
  54467. return b;
  54468. }
  54469. else if (buttonType == DocumentWindow::minimiseButton)
  54470. {
  54471. shape.addLineSegment (0.0f, 0.5f, 1.0f, 0.5f, 0.25f);
  54472. DrawableButton* b = new DrawableButton ("minimise", DrawableButton::ImageFitted);
  54473. DrawablePath dp;
  54474. dp.setPath (shape);
  54475. dp.setFill (Colours::black.withAlpha (0.3f));
  54476. b->setImages (&dp);
  54477. return b;
  54478. }
  54479. else if (buttonType == DocumentWindow::maximiseButton)
  54480. {
  54481. shape.addLineSegment (0.5f, 0.0f, 0.5f, 1.0f, 0.25f);
  54482. shape.addLineSegment (0.0f, 0.5f, 1.0f, 0.5f, 0.25f);
  54483. DrawableButton* b = new DrawableButton ("maximise", DrawableButton::ImageFitted);
  54484. DrawablePath dp;
  54485. dp.setPath (shape);
  54486. dp.setFill (Colours::black.withAlpha (0.3f));
  54487. b->setImages (&dp);
  54488. return b;
  54489. }
  54490. jassertfalse
  54491. return 0;
  54492. }
  54493. void OldSchoolLookAndFeel::positionDocumentWindowButtons (DocumentWindow&,
  54494. int titleBarX,
  54495. int titleBarY,
  54496. int titleBarW,
  54497. int titleBarH,
  54498. Button* minimiseButton,
  54499. Button* maximiseButton,
  54500. Button* closeButton,
  54501. bool positionTitleBarButtonsOnLeft)
  54502. {
  54503. titleBarY += titleBarH / 8;
  54504. titleBarH -= titleBarH / 4;
  54505. const int buttonW = titleBarH;
  54506. int x = positionTitleBarButtonsOnLeft ? titleBarX + 4
  54507. : titleBarX + titleBarW - buttonW - 4;
  54508. if (closeButton != 0)
  54509. {
  54510. closeButton->setBounds (x, titleBarY, buttonW, titleBarH);
  54511. x += positionTitleBarButtonsOnLeft ? buttonW + buttonW / 5
  54512. : -(buttonW + buttonW / 5);
  54513. }
  54514. if (positionTitleBarButtonsOnLeft)
  54515. swapVariables (minimiseButton, maximiseButton);
  54516. if (maximiseButton != 0)
  54517. {
  54518. maximiseButton->setBounds (x, titleBarY - 2, buttonW, titleBarH);
  54519. x += positionTitleBarButtonsOnLeft ? buttonW : -buttonW;
  54520. }
  54521. if (minimiseButton != 0)
  54522. minimiseButton->setBounds (x, titleBarY - 2, buttonW, titleBarH);
  54523. }
  54524. END_JUCE_NAMESPACE
  54525. /********* End of inlined file: juce_OldSchoolLookAndFeel.cpp *********/
  54526. /********* Start of inlined file: juce_MenuBarComponent.cpp *********/
  54527. BEGIN_JUCE_NAMESPACE
  54528. class DummyMenuComponent : public Component
  54529. {
  54530. DummyMenuComponent (const DummyMenuComponent&);
  54531. const DummyMenuComponent& operator= (const DummyMenuComponent&);
  54532. public:
  54533. DummyMenuComponent() {}
  54534. ~DummyMenuComponent() {}
  54535. void inputAttemptWhenModal()
  54536. {
  54537. exitModalState (0);
  54538. }
  54539. };
  54540. MenuBarComponent::MenuBarComponent (MenuBarModel* model_)
  54541. : model (0),
  54542. itemUnderMouse (-1),
  54543. currentPopupIndex (-1),
  54544. indexToShowAgain (-1),
  54545. lastMouseX (0),
  54546. lastMouseY (0),
  54547. inModalState (false)
  54548. {
  54549. setRepaintsOnMouseActivity (true);
  54550. setWantsKeyboardFocus (false);
  54551. setMouseClickGrabsKeyboardFocus (false);
  54552. setModel (model_);
  54553. }
  54554. MenuBarComponent::~MenuBarComponent()
  54555. {
  54556. setModel (0);
  54557. Desktop::getInstance().removeGlobalMouseListener (this);
  54558. currentPopup = 0;
  54559. }
  54560. void MenuBarComponent::setModel (MenuBarModel* const newModel)
  54561. {
  54562. if (model != newModel)
  54563. {
  54564. if (model != 0)
  54565. model->removeListener (this);
  54566. model = newModel;
  54567. if (model != 0)
  54568. model->addListener (this);
  54569. repaint();
  54570. menuBarItemsChanged (0);
  54571. }
  54572. }
  54573. void MenuBarComponent::paint (Graphics& g)
  54574. {
  54575. const bool isMouseOverBar = currentPopupIndex >= 0 || itemUnderMouse >= 0 || isMouseOver();
  54576. getLookAndFeel().drawMenuBarBackground (g,
  54577. getWidth(),
  54578. getHeight(),
  54579. isMouseOverBar,
  54580. *this);
  54581. if (model != 0)
  54582. {
  54583. for (int i = 0; i < menuNames.size(); ++i)
  54584. {
  54585. g.saveState();
  54586. g.setOrigin (xPositions [i], 0);
  54587. g.reduceClipRegion (0, 0, xPositions[i + 1] - xPositions[i], getHeight());
  54588. getLookAndFeel().drawMenuBarItem (g,
  54589. xPositions[i + 1] - xPositions[i],
  54590. getHeight(),
  54591. i,
  54592. menuNames[i],
  54593. i == itemUnderMouse,
  54594. i == currentPopupIndex,
  54595. isMouseOverBar,
  54596. *this);
  54597. g.restoreState();
  54598. }
  54599. }
  54600. }
  54601. void MenuBarComponent::resized()
  54602. {
  54603. xPositions.clear();
  54604. int x = 2;
  54605. xPositions.add (x);
  54606. for (int i = 0; i < menuNames.size(); ++i)
  54607. {
  54608. x += getLookAndFeel().getMenuBarItemWidth (*this, i, menuNames[i]);
  54609. xPositions.add (x);
  54610. }
  54611. }
  54612. int MenuBarComponent::getItemAt (const int x, const int y)
  54613. {
  54614. for (int i = 0; i < xPositions.size(); ++i)
  54615. if (x >= xPositions[i] && x < xPositions[i + 1])
  54616. return reallyContains (x, y, true) ? i : -1;
  54617. return -1;
  54618. }
  54619. void MenuBarComponent::repaintMenuItem (int index)
  54620. {
  54621. if (((unsigned int) index) < (unsigned int) xPositions.size())
  54622. {
  54623. const int x1 = xPositions [index];
  54624. const int x2 = xPositions [index + 1];
  54625. repaint (x1 - 2, 0, x2 - x1 + 4, getHeight());
  54626. }
  54627. }
  54628. void MenuBarComponent::updateItemUnderMouse (int x, int y)
  54629. {
  54630. const int newItem = getItemAt (x, y);
  54631. if (itemUnderMouse != newItem)
  54632. {
  54633. repaintMenuItem (itemUnderMouse);
  54634. itemUnderMouse = newItem;
  54635. repaintMenuItem (itemUnderMouse);
  54636. }
  54637. }
  54638. void MenuBarComponent::hideCurrentMenu()
  54639. {
  54640. currentPopup = 0;
  54641. repaint();
  54642. }
  54643. void MenuBarComponent::showMenu (int index)
  54644. {
  54645. if (index != currentPopupIndex)
  54646. {
  54647. if (inModalState)
  54648. {
  54649. hideCurrentMenu();
  54650. indexToShowAgain = index;
  54651. return;
  54652. }
  54653. indexToShowAgain = -1;
  54654. currentPopupIndex = -1;
  54655. itemUnderMouse = index;
  54656. currentPopup = 0;
  54657. menuBarItemsChanged (0);
  54658. Component* const prevFocused = getCurrentlyFocusedComponent();
  54659. ScopedPointer <ComponentDeletionWatcher> prevCompDeletionChecker;
  54660. if (prevFocused != 0)
  54661. prevCompDeletionChecker = new ComponentDeletionWatcher (prevFocused);
  54662. ComponentDeletionWatcher deletionChecker (this);
  54663. enterModalState (false);
  54664. inModalState = true;
  54665. int result = 0;
  54666. ApplicationCommandManager* managerOfChosenCommand = 0;
  54667. Desktop::getInstance().addGlobalMouseListener (this);
  54668. for (;;)
  54669. {
  54670. const int x = getScreenX() + xPositions [itemUnderMouse];
  54671. const int w = xPositions [itemUnderMouse + 1] - xPositions [itemUnderMouse];
  54672. currentPopupIndex = itemUnderMouse;
  54673. indexToShowAgain = -1;
  54674. repaint();
  54675. if (((unsigned int) itemUnderMouse) < (unsigned int) menuNames.size())
  54676. {
  54677. PopupMenu m (model->getMenuForIndex (itemUnderMouse,
  54678. menuNames [itemUnderMouse]));
  54679. if (m.lookAndFeel == 0)
  54680. m.setLookAndFeel (&getLookAndFeel());
  54681. currentPopup = m.createMenuComponent (x, getScreenY(),
  54682. w, getHeight(),
  54683. 0, w, 0, 0,
  54684. true, this,
  54685. &managerOfChosenCommand,
  54686. this);
  54687. }
  54688. if (currentPopup == 0)
  54689. {
  54690. currentPopup = new DummyMenuComponent();
  54691. addAndMakeVisible (currentPopup);
  54692. }
  54693. currentPopup->enterModalState (false);
  54694. currentPopup->toFront (false); // need to do this after making it modal, or it could
  54695. // be stuck behind other comps that are already modal..
  54696. result = currentPopup->runModalLoop();
  54697. if (deletionChecker.hasBeenDeleted())
  54698. return;
  54699. const int lastPopupIndex = currentPopupIndex;
  54700. currentPopup = 0;
  54701. currentPopupIndex = -1;
  54702. if (result != 0)
  54703. {
  54704. topLevelIndexClicked = lastPopupIndex;
  54705. break;
  54706. }
  54707. else if (indexToShowAgain >= 0)
  54708. {
  54709. menuBarItemsChanged (0);
  54710. repaint();
  54711. itemUnderMouse = indexToShowAgain;
  54712. if (((unsigned int) itemUnderMouse) >= (unsigned int) menuNames.size())
  54713. break;
  54714. }
  54715. else
  54716. {
  54717. break;
  54718. }
  54719. }
  54720. Desktop::getInstance().removeGlobalMouseListener (this);
  54721. inModalState = false;
  54722. exitModalState (0);
  54723. if (prevCompDeletionChecker != 0 && ! prevCompDeletionChecker->hasBeenDeleted())
  54724. prevFocused->grabKeyboardFocus();
  54725. int mx, my;
  54726. getMouseXYRelative (mx, my);
  54727. updateItemUnderMouse (mx, my);
  54728. repaint();
  54729. if (result != 0)
  54730. {
  54731. if (managerOfChosenCommand != 0)
  54732. {
  54733. ApplicationCommandTarget::InvocationInfo info (result);
  54734. info.invocationMethod = ApplicationCommandTarget::InvocationInfo::fromMenu;
  54735. managerOfChosenCommand->invoke (info, true);
  54736. }
  54737. postCommandMessage (result);
  54738. }
  54739. }
  54740. }
  54741. void MenuBarComponent::handleCommandMessage (int commandId)
  54742. {
  54743. if (model != 0)
  54744. model->menuItemSelected (commandId, topLevelIndexClicked);
  54745. }
  54746. void MenuBarComponent::mouseEnter (const MouseEvent& e)
  54747. {
  54748. if (e.eventComponent == this)
  54749. updateItemUnderMouse (e.x, e.y);
  54750. }
  54751. void MenuBarComponent::mouseExit (const MouseEvent& e)
  54752. {
  54753. if (e.eventComponent == this)
  54754. updateItemUnderMouse (e.x, e.y);
  54755. }
  54756. void MenuBarComponent::mouseDown (const MouseEvent& e)
  54757. {
  54758. const MouseEvent e2 (e.getEventRelativeTo (this));
  54759. if (currentPopupIndex < 0)
  54760. {
  54761. updateItemUnderMouse (e2.x, e2.y);
  54762. currentPopupIndex = -2;
  54763. showMenu (itemUnderMouse);
  54764. }
  54765. }
  54766. void MenuBarComponent::mouseDrag (const MouseEvent& e)
  54767. {
  54768. const MouseEvent e2 (e.getEventRelativeTo (this));
  54769. const int item = getItemAt (e2.x, e2.y);
  54770. if (item >= 0)
  54771. showMenu (item);
  54772. }
  54773. void MenuBarComponent::mouseUp (const MouseEvent& e)
  54774. {
  54775. const MouseEvent e2 (e.getEventRelativeTo (this));
  54776. updateItemUnderMouse (e2.x, e2.y);
  54777. if (itemUnderMouse < 0 && dynamic_cast <DummyMenuComponent*> ((Component*) currentPopup) != 0)
  54778. hideCurrentMenu();
  54779. }
  54780. void MenuBarComponent::mouseMove (const MouseEvent& e)
  54781. {
  54782. const MouseEvent e2 (e.getEventRelativeTo (this));
  54783. if (lastMouseX != e2.x || lastMouseY != e2.y)
  54784. {
  54785. if (currentPopupIndex >= 0)
  54786. {
  54787. const int item = getItemAt (e2.x, e2.y);
  54788. if (item >= 0)
  54789. showMenu (item);
  54790. }
  54791. else
  54792. {
  54793. updateItemUnderMouse (e2.x, e2.y);
  54794. }
  54795. lastMouseX = e2.x;
  54796. lastMouseY = e2.y;
  54797. }
  54798. }
  54799. bool MenuBarComponent::keyPressed (const KeyPress& key)
  54800. {
  54801. bool used = false;
  54802. const int numMenus = menuNames.size();
  54803. const int currentIndex = jlimit (0, menuNames.size() - 1, currentPopupIndex);
  54804. if (key.isKeyCode (KeyPress::leftKey))
  54805. {
  54806. showMenu ((currentIndex + numMenus - 1) % numMenus);
  54807. used = true;
  54808. }
  54809. else if (key.isKeyCode (KeyPress::rightKey))
  54810. {
  54811. showMenu ((currentIndex + 1) % numMenus);
  54812. used = true;
  54813. }
  54814. return used;
  54815. }
  54816. void MenuBarComponent::inputAttemptWhenModal()
  54817. {
  54818. hideCurrentMenu();
  54819. }
  54820. void MenuBarComponent::menuBarItemsChanged (MenuBarModel* /*menuBarModel*/)
  54821. {
  54822. StringArray newNames;
  54823. if (model != 0)
  54824. newNames = model->getMenuBarNames();
  54825. if (newNames != menuNames)
  54826. {
  54827. menuNames = newNames;
  54828. repaint();
  54829. resized();
  54830. }
  54831. }
  54832. void MenuBarComponent::menuCommandInvoked (MenuBarModel* /*menuBarModel*/,
  54833. const ApplicationCommandTarget::InvocationInfo& info)
  54834. {
  54835. if (model == 0
  54836. || (info.commandFlags & ApplicationCommandInfo::dontTriggerVisualFeedback) != 0)
  54837. return;
  54838. for (int i = 0; i < menuNames.size(); ++i)
  54839. {
  54840. const PopupMenu menu (model->getMenuForIndex (i, menuNames [i]));
  54841. if (menu.containsCommandItem (info.commandID))
  54842. {
  54843. itemUnderMouse = i;
  54844. repaintMenuItem (i);
  54845. startTimer (200);
  54846. break;
  54847. }
  54848. }
  54849. }
  54850. void MenuBarComponent::timerCallback()
  54851. {
  54852. stopTimer();
  54853. int mx, my;
  54854. getMouseXYRelative (mx, my);
  54855. updateItemUnderMouse (mx, my);
  54856. }
  54857. END_JUCE_NAMESPACE
  54858. /********* End of inlined file: juce_MenuBarComponent.cpp *********/
  54859. /********* Start of inlined file: juce_MenuBarModel.cpp *********/
  54860. BEGIN_JUCE_NAMESPACE
  54861. MenuBarModel::MenuBarModel() throw()
  54862. : manager (0)
  54863. {
  54864. }
  54865. MenuBarModel::~MenuBarModel()
  54866. {
  54867. setApplicationCommandManagerToWatch (0);
  54868. }
  54869. void MenuBarModel::menuItemsChanged()
  54870. {
  54871. triggerAsyncUpdate();
  54872. }
  54873. void MenuBarModel::setApplicationCommandManagerToWatch (ApplicationCommandManager* const newManager) throw()
  54874. {
  54875. if (manager != newManager)
  54876. {
  54877. if (manager != 0)
  54878. manager->removeListener (this);
  54879. manager = newManager;
  54880. if (manager != 0)
  54881. manager->addListener (this);
  54882. }
  54883. }
  54884. void MenuBarModel::addListener (MenuBarModelListener* const newListener) throw()
  54885. {
  54886. jassert (newListener != 0);
  54887. jassert (! listeners.contains (newListener)); // trying to add a listener to the list twice!
  54888. if (newListener != 0)
  54889. listeners.add (newListener);
  54890. }
  54891. void MenuBarModel::removeListener (MenuBarModelListener* const listenerToRemove) throw()
  54892. {
  54893. // Trying to remove a listener that isn't on the list!
  54894. // If this assertion happens because this object is a dangling pointer, make sure you've not
  54895. // deleted this menu model while it's still being used by something (e.g. by a MenuBarComponent)
  54896. jassert (listeners.contains (listenerToRemove));
  54897. listeners.removeValue (listenerToRemove);
  54898. }
  54899. void MenuBarModel::handleAsyncUpdate()
  54900. {
  54901. for (int i = listeners.size(); --i >= 0;)
  54902. {
  54903. ((MenuBarModelListener*) listeners.getUnchecked (i))->menuBarItemsChanged (this);
  54904. i = jmin (i, listeners.size());
  54905. }
  54906. }
  54907. void MenuBarModel::applicationCommandInvoked (const ApplicationCommandTarget::InvocationInfo& info)
  54908. {
  54909. for (int i = listeners.size(); --i >= 0;)
  54910. {
  54911. ((MenuBarModelListener*) listeners.getUnchecked (i))->menuCommandInvoked (this, info);
  54912. i = jmin (i, listeners.size());
  54913. }
  54914. }
  54915. void MenuBarModel::applicationCommandListChanged()
  54916. {
  54917. menuItemsChanged();
  54918. }
  54919. END_JUCE_NAMESPACE
  54920. /********* End of inlined file: juce_MenuBarModel.cpp *********/
  54921. /********* Start of inlined file: juce_PopupMenu.cpp *********/
  54922. BEGIN_JUCE_NAMESPACE
  54923. static VoidArray activeMenuWindows;
  54924. class MenuItemInfo
  54925. {
  54926. public:
  54927. const int itemId;
  54928. String text;
  54929. const Colour textColour;
  54930. const bool active, isSeparator, isTicked, usesColour;
  54931. ScopedPointer <Image> image;
  54932. PopupMenuCustomComponent* const customComp;
  54933. ScopedPointer <PopupMenu> subMenu;
  54934. ApplicationCommandManager* const commandManager;
  54935. MenuItemInfo()
  54936. : itemId (0),
  54937. active (true),
  54938. isSeparator (true),
  54939. isTicked (false),
  54940. usesColour (false),
  54941. customComp (0),
  54942. commandManager (0)
  54943. {
  54944. }
  54945. MenuItemInfo (const int itemId_,
  54946. const String& text_,
  54947. const bool active_,
  54948. const bool isTicked_,
  54949. const Image* im,
  54950. const Colour& textColour_,
  54951. const bool usesColour_,
  54952. PopupMenuCustomComponent* const customComp_,
  54953. const PopupMenu* const subMenu_,
  54954. ApplicationCommandManager* const commandManager_)
  54955. : itemId (itemId_),
  54956. text (text_),
  54957. textColour (textColour_),
  54958. active (active_),
  54959. isSeparator (false),
  54960. isTicked (isTicked_),
  54961. usesColour (usesColour_),
  54962. customComp (customComp_),
  54963. commandManager (commandManager_)
  54964. {
  54965. if (subMenu_ != 0)
  54966. subMenu = new PopupMenu (*subMenu_);
  54967. if (customComp != 0)
  54968. customComp->refCount_++;
  54969. if (im != 0)
  54970. image = im->createCopy();
  54971. if (commandManager_ != 0 && itemId_ != 0)
  54972. {
  54973. String shortcutKey;
  54974. Array <KeyPress> keyPresses (commandManager_->getKeyMappings()
  54975. ->getKeyPressesAssignedToCommand (itemId_));
  54976. for (int i = 0; i < keyPresses.size(); ++i)
  54977. {
  54978. const String key (keyPresses.getReference(i).getTextDescription());
  54979. if (shortcutKey.isNotEmpty())
  54980. shortcutKey << ", ";
  54981. if (key.length() == 1)
  54982. shortcutKey << "shortcut: '" << key << '\'';
  54983. else
  54984. shortcutKey << key;
  54985. }
  54986. shortcutKey = shortcutKey.trim();
  54987. if (shortcutKey.isNotEmpty())
  54988. text << "<end>" << shortcutKey;
  54989. }
  54990. }
  54991. MenuItemInfo (const MenuItemInfo& other)
  54992. : itemId (other.itemId),
  54993. text (other.text),
  54994. textColour (other.textColour),
  54995. active (other.active),
  54996. isSeparator (other.isSeparator),
  54997. isTicked (other.isTicked),
  54998. usesColour (other.usesColour),
  54999. customComp (other.customComp),
  55000. commandManager (other.commandManager)
  55001. {
  55002. if (other.subMenu != 0)
  55003. subMenu = new PopupMenu (*(other.subMenu));
  55004. if (other.image != 0)
  55005. image = other.image->createCopy();
  55006. if (customComp != 0)
  55007. customComp->refCount_++;
  55008. }
  55009. ~MenuItemInfo()
  55010. {
  55011. if (customComp != 0 && --(customComp->refCount_) == 0)
  55012. delete customComp;
  55013. }
  55014. bool canBeTriggered() const
  55015. {
  55016. return active && ! (isSeparator || (subMenu != 0));
  55017. }
  55018. bool hasActiveSubMenu() const
  55019. {
  55020. return active && (subMenu != 0);
  55021. }
  55022. juce_UseDebuggingNewOperator
  55023. private:
  55024. const MenuItemInfo& operator= (const MenuItemInfo&);
  55025. };
  55026. class MenuItemComponent : public Component
  55027. {
  55028. bool isHighlighted;
  55029. public:
  55030. MenuItemInfo itemInfo;
  55031. MenuItemComponent (const MenuItemInfo& itemInfo_)
  55032. : isHighlighted (false),
  55033. itemInfo (itemInfo_)
  55034. {
  55035. if (itemInfo.customComp != 0)
  55036. addAndMakeVisible (itemInfo.customComp);
  55037. }
  55038. ~MenuItemComponent()
  55039. {
  55040. if (itemInfo.customComp != 0)
  55041. removeChildComponent (itemInfo.customComp);
  55042. }
  55043. void getIdealSize (int& idealWidth,
  55044. int& idealHeight,
  55045. const int standardItemHeight)
  55046. {
  55047. if (itemInfo.customComp != 0)
  55048. {
  55049. itemInfo.customComp->getIdealSize (idealWidth, idealHeight);
  55050. }
  55051. else
  55052. {
  55053. getLookAndFeel().getIdealPopupMenuItemSize (itemInfo.text,
  55054. itemInfo.isSeparator,
  55055. standardItemHeight,
  55056. idealWidth,
  55057. idealHeight);
  55058. }
  55059. }
  55060. void paint (Graphics& g)
  55061. {
  55062. if (itemInfo.customComp == 0)
  55063. {
  55064. String mainText (itemInfo.text);
  55065. String endText;
  55066. const int endIndex = mainText.indexOf (T("<end>"));
  55067. if (endIndex >= 0)
  55068. {
  55069. endText = mainText.substring (endIndex + 5).trim();
  55070. mainText = mainText.substring (0, endIndex);
  55071. }
  55072. getLookAndFeel()
  55073. .drawPopupMenuItem (g, getWidth(), getHeight(),
  55074. itemInfo.isSeparator,
  55075. itemInfo.active,
  55076. isHighlighted,
  55077. itemInfo.isTicked,
  55078. itemInfo.subMenu != 0,
  55079. mainText, endText,
  55080. itemInfo.image,
  55081. itemInfo.usesColour ? &(itemInfo.textColour) : 0);
  55082. }
  55083. }
  55084. void resized()
  55085. {
  55086. if (getNumChildComponents() > 0)
  55087. getChildComponent(0)->setBounds (2, 0, getWidth() - 4, getHeight());
  55088. }
  55089. void setHighlighted (bool shouldBeHighlighted)
  55090. {
  55091. shouldBeHighlighted = shouldBeHighlighted && itemInfo.active;
  55092. if (isHighlighted != shouldBeHighlighted)
  55093. {
  55094. isHighlighted = shouldBeHighlighted;
  55095. if (itemInfo.customComp != 0)
  55096. {
  55097. itemInfo.customComp->isHighlighted = shouldBeHighlighted;
  55098. itemInfo.customComp->repaint();
  55099. }
  55100. repaint();
  55101. }
  55102. }
  55103. private:
  55104. MenuItemComponent (const MenuItemComponent&);
  55105. const MenuItemComponent& operator= (const MenuItemComponent&);
  55106. };
  55107. static const int scrollZone = 24;
  55108. static const int borderSize = 2;
  55109. static const int timerInterval = 50;
  55110. static const int dismissCommandId = 0x6287345f;
  55111. static bool wasHiddenBecauseOfAppChange = false;
  55112. class PopupMenuWindow : public Component,
  55113. private Timer
  55114. {
  55115. public:
  55116. PopupMenuWindow()
  55117. : Component (T("menu")),
  55118. owner (0),
  55119. currentChild (0),
  55120. activeSubMenu (0),
  55121. menuBarComponent (0),
  55122. managerOfChosenCommand (0),
  55123. componentAttachedTo (0),
  55124. lastMouseX (0),
  55125. lastMouseY (0),
  55126. minimumWidth (0),
  55127. maximumNumColumns (7),
  55128. standardItemHeight (0),
  55129. isOver (false),
  55130. hasBeenOver (false),
  55131. isDown (false),
  55132. needsToScroll (false),
  55133. hideOnExit (false),
  55134. disableMouseMoves (false),
  55135. hasAnyJuceCompHadFocus (false),
  55136. numColumns (0),
  55137. contentHeight (0),
  55138. childYOffset (0),
  55139. timeEnteredCurrentChildComp (0),
  55140. scrollAcceleration (1.0)
  55141. {
  55142. menuCreationTime = lastFocused = lastScroll = Time::getMillisecondCounter();
  55143. setWantsKeyboardFocus (true);
  55144. setMouseClickGrabsKeyboardFocus (false);
  55145. setOpaque (true);
  55146. setAlwaysOnTop (true);
  55147. Desktop::getInstance().addGlobalMouseListener (this);
  55148. activeMenuWindows.add (this);
  55149. }
  55150. ~PopupMenuWindow()
  55151. {
  55152. activeMenuWindows.removeValue (this);
  55153. Desktop::getInstance().removeGlobalMouseListener (this);
  55154. jassert (activeSubMenu == 0 || activeSubMenu->isValidComponent());
  55155. delete activeSubMenu;
  55156. deleteAllChildren();
  55157. attachedCompWatcher = 0;
  55158. }
  55159. static PopupMenuWindow* create (const PopupMenu& menu,
  55160. const bool dismissOnMouseUp,
  55161. PopupMenuWindow* const owner_,
  55162. const int minX, const int maxX,
  55163. const int minY, const int maxY,
  55164. const int minimumWidth,
  55165. const int maximumNumColumns,
  55166. const int standardItemHeight,
  55167. const bool alignToRectangle,
  55168. const int itemIdThatMustBeVisible,
  55169. Component* const menuBarComponent,
  55170. ApplicationCommandManager** managerOfChosenCommand,
  55171. Component* const componentAttachedTo)
  55172. {
  55173. if (menu.items.size() > 0)
  55174. {
  55175. int totalItems = 0;
  55176. ScopedPointer <PopupMenuWindow> mw (new PopupMenuWindow());
  55177. mw->setLookAndFeel (menu.lookAndFeel);
  55178. mw->setWantsKeyboardFocus (false);
  55179. mw->minimumWidth = minimumWidth;
  55180. mw->maximumNumColumns = maximumNumColumns;
  55181. mw->standardItemHeight = standardItemHeight;
  55182. mw->dismissOnMouseUp = dismissOnMouseUp;
  55183. for (int i = 0; i < menu.items.size(); ++i)
  55184. {
  55185. MenuItemInfo* const item = (MenuItemInfo*) menu.items.getUnchecked(i);
  55186. mw->addItem (*item);
  55187. ++totalItems;
  55188. }
  55189. if (totalItems > 0)
  55190. {
  55191. mw->owner = owner_;
  55192. mw->menuBarComponent = menuBarComponent;
  55193. mw->managerOfChosenCommand = managerOfChosenCommand;
  55194. mw->componentAttachedTo = componentAttachedTo;
  55195. mw->attachedCompWatcher = componentAttachedTo != 0 ? new ComponentDeletionWatcher (componentAttachedTo) : 0;
  55196. mw->calculateWindowPos (minX, maxX, minY, maxY, alignToRectangle);
  55197. mw->setTopLeftPosition (mw->windowPos.getX(),
  55198. mw->windowPos.getY());
  55199. mw->updateYPositions();
  55200. if (itemIdThatMustBeVisible != 0)
  55201. {
  55202. const int y = minY - mw->windowPos.getY();
  55203. mw->ensureItemIsVisible (itemIdThatMustBeVisible,
  55204. (((unsigned int) y) < (unsigned int) mw->windowPos.getHeight()) ? y : -1);
  55205. }
  55206. mw->resizeToBestWindowPos();
  55207. mw->addToDesktop (ComponentPeer::windowIsTemporary
  55208. | mw->getLookAndFeel().getMenuWindowFlags());
  55209. return mw.release();
  55210. }
  55211. }
  55212. return 0;
  55213. }
  55214. void paint (Graphics& g)
  55215. {
  55216. getLookAndFeel().drawPopupMenuBackground (g, getWidth(), getHeight());
  55217. }
  55218. void paintOverChildren (Graphics& g)
  55219. {
  55220. if (isScrolling())
  55221. {
  55222. LookAndFeel& lf = getLookAndFeel();
  55223. if (isScrollZoneActive (false))
  55224. lf.drawPopupMenuUpDownArrow (g, getWidth(), scrollZone, true);
  55225. if (isScrollZoneActive (true))
  55226. {
  55227. g.setOrigin (0, getHeight() - scrollZone);
  55228. lf.drawPopupMenuUpDownArrow (g, getWidth(), scrollZone, false);
  55229. }
  55230. }
  55231. }
  55232. bool isScrollZoneActive (bool bottomOne) const
  55233. {
  55234. return isScrolling()
  55235. && (bottomOne
  55236. ? childYOffset < contentHeight - windowPos.getHeight()
  55237. : childYOffset > 0);
  55238. }
  55239. void addItem (const MenuItemInfo& item)
  55240. {
  55241. MenuItemComponent* const mic = new MenuItemComponent (item);
  55242. addAndMakeVisible (mic);
  55243. int itemW = 80;
  55244. int itemH = 16;
  55245. mic->getIdealSize (itemW, itemH, standardItemHeight);
  55246. mic->setSize (itemW, jlimit (2, 600, itemH));
  55247. mic->addMouseListener (this, false);
  55248. }
  55249. // hide this and all sub-comps
  55250. void hide (const MenuItemInfo* const item)
  55251. {
  55252. if (isVisible())
  55253. {
  55254. jassert (activeSubMenu == 0 || activeSubMenu->isValidComponent());
  55255. deleteAndZero (activeSubMenu);
  55256. currentChild = 0;
  55257. exitModalState (item != 0 ? item->itemId : 0);
  55258. setVisible (false);
  55259. if (item != 0
  55260. && item->commandManager != 0
  55261. && item->itemId != 0)
  55262. {
  55263. *managerOfChosenCommand = item->commandManager;
  55264. }
  55265. }
  55266. }
  55267. void dismissMenu (const MenuItemInfo* const item)
  55268. {
  55269. if (owner != 0)
  55270. {
  55271. owner->dismissMenu (item);
  55272. }
  55273. else
  55274. {
  55275. if (item != 0)
  55276. {
  55277. // need a copy of this on the stack as the one passed in will get deleted during this call
  55278. const MenuItemInfo mi (*item);
  55279. hide (&mi);
  55280. }
  55281. else
  55282. {
  55283. hide (0);
  55284. }
  55285. }
  55286. }
  55287. void mouseMove (const MouseEvent&)
  55288. {
  55289. timerCallback();
  55290. }
  55291. void mouseDown (const MouseEvent&)
  55292. {
  55293. timerCallback();
  55294. }
  55295. void mouseDrag (const MouseEvent&)
  55296. {
  55297. timerCallback();
  55298. }
  55299. void mouseUp (const MouseEvent&)
  55300. {
  55301. timerCallback();
  55302. }
  55303. void mouseWheelMove (const MouseEvent&, float /*amountX*/, float amountY)
  55304. {
  55305. alterChildYPos (roundToInt (-10.0f * amountY * scrollZone));
  55306. lastMouseX = -1;
  55307. }
  55308. bool keyPressed (const KeyPress& key)
  55309. {
  55310. if (key.isKeyCode (KeyPress::downKey))
  55311. {
  55312. selectNextItem (1);
  55313. }
  55314. else if (key.isKeyCode (KeyPress::upKey))
  55315. {
  55316. selectNextItem (-1);
  55317. }
  55318. else if (key.isKeyCode (KeyPress::leftKey))
  55319. {
  55320. PopupMenuWindow* parentWindow = owner;
  55321. if (parentWindow != 0)
  55322. {
  55323. MenuItemComponent* currentChildOfParent
  55324. = (parentWindow != 0) ? parentWindow->currentChild : 0;
  55325. hide (0);
  55326. if (parentWindow->isValidComponent())
  55327. parentWindow->setCurrentlyHighlightedChild (currentChildOfParent);
  55328. disableTimerUntilMouseMoves();
  55329. }
  55330. else if (menuBarComponent != 0)
  55331. {
  55332. menuBarComponent->keyPressed (key);
  55333. }
  55334. }
  55335. else if (key.isKeyCode (KeyPress::rightKey))
  55336. {
  55337. disableTimerUntilMouseMoves();
  55338. if (showSubMenuFor (currentChild))
  55339. {
  55340. jassert (activeSubMenu == 0 || activeSubMenu->isValidComponent());
  55341. if (activeSubMenu != 0 && activeSubMenu->isVisible())
  55342. activeSubMenu->selectNextItem (1);
  55343. }
  55344. else if (menuBarComponent != 0)
  55345. {
  55346. menuBarComponent->keyPressed (key);
  55347. }
  55348. }
  55349. else if (key.isKeyCode (KeyPress::returnKey))
  55350. {
  55351. triggerCurrentlyHighlightedItem();
  55352. }
  55353. else if (key.isKeyCode (KeyPress::escapeKey))
  55354. {
  55355. dismissMenu (0);
  55356. }
  55357. else
  55358. {
  55359. return false;
  55360. }
  55361. return true;
  55362. }
  55363. void inputAttemptWhenModal()
  55364. {
  55365. timerCallback();
  55366. if (! isOverAnyMenu())
  55367. {
  55368. if (componentAttachedTo != 0 && ! attachedCompWatcher->hasBeenDeleted())
  55369. {
  55370. // we want to dismiss the menu, but if we do it synchronously, then
  55371. // the mouse-click will be allowed to pass through. That's good, except
  55372. // when the user clicks on the button that orginally popped the menu up,
  55373. // as they'll expect the menu to go away, and in fact it'll just
  55374. // come back. So only dismiss synchronously if they're not on the original
  55375. // comp that we're attached to.
  55376. int mx, my;
  55377. componentAttachedTo->getMouseXYRelative (mx, my);
  55378. if (componentAttachedTo->reallyContains (mx, my, true))
  55379. {
  55380. postCommandMessage (dismissCommandId); // dismiss asynchrounously
  55381. return;
  55382. }
  55383. }
  55384. dismissMenu (0);
  55385. }
  55386. }
  55387. void handleCommandMessage (int commandId)
  55388. {
  55389. Component::handleCommandMessage (commandId);
  55390. if (commandId == dismissCommandId)
  55391. dismissMenu (0);
  55392. }
  55393. void timerCallback()
  55394. {
  55395. if (! isVisible())
  55396. return;
  55397. if (attachedCompWatcher != 0 && attachedCompWatcher->hasBeenDeleted())
  55398. {
  55399. dismissMenu (0);
  55400. return;
  55401. }
  55402. PopupMenuWindow* currentlyModalWindow = dynamic_cast <PopupMenuWindow*> (Component::getCurrentlyModalComponent());
  55403. if (currentlyModalWindow != 0 && ! treeContains (currentlyModalWindow))
  55404. return;
  55405. startTimer (timerInterval); // do this in case it was called from a mouse
  55406. // move rather than a real timer callback
  55407. int mx, my;
  55408. Desktop::getMousePosition (mx, my);
  55409. int x = mx, y = my;
  55410. globalPositionToRelative (x, y);
  55411. const uint32 now = Time::getMillisecondCounter();
  55412. if (now > timeEnteredCurrentChildComp + 100
  55413. && reallyContains (x, y, true)
  55414. && currentChild->isValidComponent()
  55415. && (! disableMouseMoves)
  55416. && ! (activeSubMenu != 0 && activeSubMenu->isVisible()))
  55417. {
  55418. showSubMenuFor (currentChild);
  55419. }
  55420. if (mx != lastMouseX || my != lastMouseY || now > lastMouseMoveTime + 350)
  55421. {
  55422. highlightItemUnderMouse (mx, my, x, y);
  55423. }
  55424. bool overScrollArea = false;
  55425. if (isScrolling()
  55426. && (isOver || (isDown && ((unsigned int) x) < (unsigned int) getWidth()))
  55427. && ((isScrollZoneActive (false) && y < scrollZone)
  55428. || (isScrollZoneActive (true) && y > getHeight() - scrollZone)))
  55429. {
  55430. if (now > lastScroll + 20)
  55431. {
  55432. scrollAcceleration = jmin (4.0, scrollAcceleration * 1.04);
  55433. int amount = 0;
  55434. for (int i = 0; i < getNumChildComponents() && amount == 0; ++i)
  55435. amount = ((int) scrollAcceleration) * getChildComponent (i)->getHeight();
  55436. alterChildYPos (y < scrollZone ? -amount : amount);
  55437. lastScroll = now;
  55438. }
  55439. overScrollArea = true;
  55440. lastMouseX = -1; // trigger a mouse-move
  55441. }
  55442. else
  55443. {
  55444. scrollAcceleration = 1.0;
  55445. }
  55446. const bool wasDown = isDown;
  55447. bool isOverAny = isOverAnyMenu();
  55448. if (hideOnExit && hasBeenOver && (! isOverAny) && activeSubMenu != 0)
  55449. {
  55450. activeSubMenu->updateMouseOverStatus (mx, my);
  55451. isOverAny = isOverAnyMenu();
  55452. }
  55453. if (hideOnExit && hasBeenOver && ! isOverAny)
  55454. {
  55455. hide (0);
  55456. }
  55457. else
  55458. {
  55459. isDown = hasBeenOver
  55460. && (ModifierKeys::getCurrentModifiers().isAnyMouseButtonDown()
  55461. || ModifierKeys::getCurrentModifiersRealtime().isAnyMouseButtonDown());
  55462. bool anyFocused = Process::isForegroundProcess();
  55463. if (anyFocused && Component::getCurrentlyFocusedComponent() == 0)
  55464. {
  55465. // because no component at all may have focus, our test here will
  55466. // only be triggered when something has focus and then loses it.
  55467. anyFocused = ! hasAnyJuceCompHadFocus;
  55468. for (int i = ComponentPeer::getNumPeers(); --i >= 0;)
  55469. {
  55470. if (ComponentPeer::getPeer (i)->isFocused())
  55471. {
  55472. anyFocused = true;
  55473. hasAnyJuceCompHadFocus = true;
  55474. break;
  55475. }
  55476. }
  55477. }
  55478. if (! anyFocused)
  55479. {
  55480. if (now > lastFocused + 10)
  55481. {
  55482. wasHiddenBecauseOfAppChange = true;
  55483. dismissMenu (0);
  55484. return; // may have been deleted by the previous call..
  55485. }
  55486. }
  55487. else if (wasDown && now > menuCreationTime + 250
  55488. && ! (isDown || overScrollArea))
  55489. {
  55490. isOver = reallyContains (x, y, true);
  55491. if (isOver)
  55492. {
  55493. triggerCurrentlyHighlightedItem();
  55494. }
  55495. else if ((hasBeenOver || ! dismissOnMouseUp) && ! isOverAny)
  55496. {
  55497. dismissMenu (0);
  55498. }
  55499. return; // may have been deleted by the previous calls..
  55500. }
  55501. else
  55502. {
  55503. lastFocused = now;
  55504. }
  55505. }
  55506. }
  55507. juce_UseDebuggingNewOperator
  55508. private:
  55509. PopupMenuWindow* owner;
  55510. MenuItemComponent* currentChild;
  55511. PopupMenuWindow* activeSubMenu;
  55512. Component* menuBarComponent;
  55513. ApplicationCommandManager** managerOfChosenCommand;
  55514. Component* componentAttachedTo;
  55515. ScopedPointer <ComponentDeletionWatcher> attachedCompWatcher;
  55516. Rectangle windowPos;
  55517. int lastMouseX, lastMouseY;
  55518. int minimumWidth, maximumNumColumns, standardItemHeight;
  55519. bool isOver, hasBeenOver, isDown, needsToScroll;
  55520. bool dismissOnMouseUp, hideOnExit, disableMouseMoves, hasAnyJuceCompHadFocus;
  55521. int numColumns, contentHeight, childYOffset;
  55522. Array <int> columnWidths;
  55523. uint32 menuCreationTime, lastFocused, lastScroll, lastMouseMoveTime, timeEnteredCurrentChildComp;
  55524. double scrollAcceleration;
  55525. bool overlaps (const Rectangle& r) const
  55526. {
  55527. return r.intersects (getBounds())
  55528. || (owner != 0 && owner->overlaps (r));
  55529. }
  55530. bool isOverAnyMenu() const
  55531. {
  55532. return (owner != 0) ? owner->isOverAnyMenu()
  55533. : isOverChildren();
  55534. }
  55535. bool isOverChildren() const
  55536. {
  55537. jassert (activeSubMenu == 0 || activeSubMenu->isValidComponent());
  55538. return isVisible()
  55539. && (isOver || (activeSubMenu != 0 && activeSubMenu->isOverChildren()));
  55540. }
  55541. void updateMouseOverStatus (const int mx, const int my)
  55542. {
  55543. int rx = mx, ry = my;
  55544. globalPositionToRelative (rx, ry);
  55545. isOver = reallyContains (rx, ry, true);
  55546. if (activeSubMenu != 0)
  55547. activeSubMenu->updateMouseOverStatus (mx, my);
  55548. }
  55549. bool treeContains (const PopupMenuWindow* const window) const
  55550. {
  55551. const PopupMenuWindow* mw = this;
  55552. while (mw->owner != 0)
  55553. mw = mw->owner;
  55554. while (mw != 0)
  55555. {
  55556. if (mw == window)
  55557. return true;
  55558. mw = mw->activeSubMenu;
  55559. }
  55560. return false;
  55561. }
  55562. void calculateWindowPos (const int minX, const int maxX,
  55563. const int minY, const int maxY,
  55564. const bool alignToRectangle)
  55565. {
  55566. const Rectangle mon (Desktop::getInstance()
  55567. .getMonitorAreaContaining ((minX + maxX) / 2,
  55568. (minY + maxY) / 2,
  55569. #if JUCE_MAC
  55570. true));
  55571. #else
  55572. false)); // on windows, don't stop the menu overlapping the taskbar
  55573. #endif
  55574. int x, y, widthToUse, heightToUse;
  55575. layoutMenuItems (mon.getWidth() - 24, widthToUse, heightToUse);
  55576. if (alignToRectangle)
  55577. {
  55578. x = minX;
  55579. const int spaceUnder = mon.getHeight() - (maxY - mon.getY());
  55580. const int spaceOver = minY - mon.getY();
  55581. if (heightToUse < spaceUnder - 30 || spaceUnder >= spaceOver)
  55582. y = maxY;
  55583. else
  55584. y = minY - heightToUse;
  55585. }
  55586. else
  55587. {
  55588. bool tendTowardsRight = (minX + maxX) / 2 < mon.getCentreX();
  55589. if (owner != 0)
  55590. {
  55591. if (owner->owner != 0)
  55592. {
  55593. const bool ownerGoingRight = (owner->getX() + owner->getWidth() / 2
  55594. > owner->owner->getX() + owner->owner->getWidth() / 2);
  55595. if (ownerGoingRight && maxX + widthToUse < mon.getRight() - 4)
  55596. tendTowardsRight = true;
  55597. else if ((! ownerGoingRight) && minX > widthToUse + 4)
  55598. tendTowardsRight = false;
  55599. }
  55600. else if (maxX + widthToUse < mon.getRight() - 32)
  55601. {
  55602. tendTowardsRight = true;
  55603. }
  55604. }
  55605. const int biggestSpace = jmax (mon.getRight() - maxX,
  55606. minX - mon.getX()) - 32;
  55607. if (biggestSpace < widthToUse)
  55608. {
  55609. layoutMenuItems (biggestSpace + (maxX - minX) / 3, widthToUse, heightToUse);
  55610. if (numColumns > 1)
  55611. layoutMenuItems (biggestSpace - 4, widthToUse, heightToUse);
  55612. tendTowardsRight = (mon.getRight() - maxX) >= (minX - mon.getX());
  55613. }
  55614. if (tendTowardsRight)
  55615. x = jmin (mon.getRight() - widthToUse - 4, maxX);
  55616. else
  55617. x = jmax (mon.getX() + 4, minX - widthToUse);
  55618. y = minY;
  55619. if ((minY + maxY) / 2 > mon.getCentreY())
  55620. y = jmax (mon.getY(), maxY - heightToUse);
  55621. }
  55622. x = jmax (mon.getX() + 1, jmin (mon.getRight() - (widthToUse + 6), x));
  55623. y = jmax (mon.getY() + 1, jmin (mon.getBottom() - (heightToUse + 6), y));
  55624. windowPos.setBounds (x, y, widthToUse, heightToUse);
  55625. // sets this flag if it's big enough to obscure any of its parent menus
  55626. hideOnExit = (owner != 0)
  55627. && owner->windowPos.intersects (windowPos.expanded (-4, -4));
  55628. }
  55629. void layoutMenuItems (const int maxMenuW, int& width, int& height)
  55630. {
  55631. numColumns = 0;
  55632. contentHeight = 0;
  55633. const int maxMenuH = getParentHeight() - 24;
  55634. int totalW;
  55635. do
  55636. {
  55637. ++numColumns;
  55638. totalW = workOutBestSize (maxMenuW);
  55639. if (totalW > maxMenuW)
  55640. {
  55641. numColumns = jmax (1, numColumns - 1);
  55642. totalW = workOutBestSize (maxMenuW); // to update col widths
  55643. break;
  55644. }
  55645. else if (totalW > maxMenuW / 2 || contentHeight < maxMenuH)
  55646. {
  55647. break;
  55648. }
  55649. } while (numColumns < maximumNumColumns);
  55650. const int actualH = jmin (contentHeight, maxMenuH);
  55651. needsToScroll = contentHeight > actualH;
  55652. width = updateYPositions();
  55653. height = actualH + borderSize * 2;
  55654. }
  55655. int workOutBestSize (const int maxMenuW)
  55656. {
  55657. int totalW = 0;
  55658. contentHeight = 0;
  55659. int childNum = 0;
  55660. for (int col = 0; col < numColumns; ++col)
  55661. {
  55662. int i, colW = 50, colH = 0;
  55663. const int numChildren = jmin (getNumChildComponents() - childNum,
  55664. (getNumChildComponents() + numColumns - 1) / numColumns);
  55665. for (i = numChildren; --i >= 0;)
  55666. {
  55667. colW = jmax (colW, getChildComponent (childNum + i)->getWidth());
  55668. colH += getChildComponent (childNum + i)->getHeight();
  55669. }
  55670. colW = jmin (maxMenuW / jmax (1, numColumns - 2), colW + borderSize * 2);
  55671. columnWidths.set (col, colW);
  55672. totalW += colW;
  55673. contentHeight = jmax (contentHeight, colH);
  55674. childNum += numChildren;
  55675. }
  55676. if (totalW < minimumWidth)
  55677. {
  55678. totalW = minimumWidth;
  55679. for (int col = 0; col < numColumns; ++col)
  55680. columnWidths.set (0, totalW / numColumns);
  55681. }
  55682. return totalW;
  55683. }
  55684. void ensureItemIsVisible (const int itemId, int wantedY)
  55685. {
  55686. jassert (itemId != 0)
  55687. for (int i = getNumChildComponents(); --i >= 0;)
  55688. {
  55689. MenuItemComponent* const m = (MenuItemComponent*) getChildComponent (i);
  55690. if (m != 0
  55691. && m->itemInfo.itemId == itemId
  55692. && windowPos.getHeight() > scrollZone * 4)
  55693. {
  55694. const int currentY = m->getY();
  55695. if (wantedY > 0 || currentY < 0 || m->getBottom() > windowPos.getHeight())
  55696. {
  55697. if (wantedY < 0)
  55698. wantedY = jlimit (scrollZone,
  55699. jmax (scrollZone, windowPos.getHeight() - (scrollZone + m->getHeight())),
  55700. currentY);
  55701. const Rectangle mon (Desktop::getInstance()
  55702. .getMonitorAreaContaining (windowPos.getX(),
  55703. windowPos.getY(),
  55704. true));
  55705. int deltaY = wantedY - currentY;
  55706. const int newY = jlimit (mon.getY(),
  55707. mon.getBottom() - windowPos.getHeight(),
  55708. windowPos.getY() + deltaY);
  55709. deltaY -= newY - windowPos.getY();
  55710. childYOffset -= deltaY;
  55711. windowPos.setPosition (windowPos.getX(), newY);
  55712. updateYPositions();
  55713. }
  55714. break;
  55715. }
  55716. }
  55717. }
  55718. void resizeToBestWindowPos()
  55719. {
  55720. Rectangle r (windowPos);
  55721. if (childYOffset < 0)
  55722. {
  55723. r.setBounds (r.getX(), r.getY() - childYOffset,
  55724. r.getWidth(), r.getHeight() + childYOffset);
  55725. }
  55726. else if (childYOffset > 0)
  55727. {
  55728. const int spaceAtBottom = r.getHeight() - (contentHeight - childYOffset);
  55729. if (spaceAtBottom > 0)
  55730. r.setSize (r.getWidth(), r.getHeight() - spaceAtBottom);
  55731. }
  55732. setBounds (r);
  55733. updateYPositions();
  55734. }
  55735. void alterChildYPos (const int delta)
  55736. {
  55737. if (isScrolling())
  55738. {
  55739. childYOffset += delta;
  55740. if (delta < 0)
  55741. {
  55742. childYOffset = jmax (childYOffset, 0);
  55743. }
  55744. else if (delta > 0)
  55745. {
  55746. childYOffset = jmin (childYOffset,
  55747. contentHeight - windowPos.getHeight() + borderSize);
  55748. }
  55749. updateYPositions();
  55750. }
  55751. else
  55752. {
  55753. childYOffset = 0;
  55754. }
  55755. resizeToBestWindowPos();
  55756. repaint();
  55757. }
  55758. int updateYPositions()
  55759. {
  55760. int x = 0;
  55761. int childNum = 0;
  55762. for (int col = 0; col < numColumns; ++col)
  55763. {
  55764. const int numChildren = jmin (getNumChildComponents() - childNum,
  55765. (getNumChildComponents() + numColumns - 1) / numColumns);
  55766. const int colW = columnWidths [col];
  55767. int y = borderSize - (childYOffset + (getY() - windowPos.getY()));
  55768. for (int i = 0; i < numChildren; ++i)
  55769. {
  55770. Component* const c = getChildComponent (childNum + i);
  55771. c->setBounds (x, y, colW, c->getHeight());
  55772. y += c->getHeight();
  55773. }
  55774. x += colW;
  55775. childNum += numChildren;
  55776. }
  55777. return x;
  55778. }
  55779. bool isScrolling() const
  55780. {
  55781. return childYOffset != 0 || needsToScroll;
  55782. }
  55783. void setCurrentlyHighlightedChild (MenuItemComponent* const child)
  55784. {
  55785. if (currentChild->isValidComponent())
  55786. currentChild->setHighlighted (false);
  55787. currentChild = child;
  55788. if (currentChild != 0)
  55789. {
  55790. currentChild->setHighlighted (true);
  55791. timeEnteredCurrentChildComp = Time::getApproximateMillisecondCounter();
  55792. }
  55793. }
  55794. bool showSubMenuFor (MenuItemComponent* const childComp)
  55795. {
  55796. jassert (activeSubMenu == 0 || activeSubMenu->isValidComponent());
  55797. deleteAndZero (activeSubMenu);
  55798. if (childComp->isValidComponent() && childComp->itemInfo.hasActiveSubMenu())
  55799. {
  55800. int left = 0, top = 0;
  55801. childComp->relativePositionToGlobal (left, top);
  55802. int right = childComp->getWidth(), bottom = childComp->getHeight();
  55803. childComp->relativePositionToGlobal (right, bottom);
  55804. activeSubMenu = PopupMenuWindow::create (*(childComp->itemInfo.subMenu),
  55805. dismissOnMouseUp,
  55806. this,
  55807. left, right, top, bottom,
  55808. 0, maximumNumColumns,
  55809. standardItemHeight,
  55810. false, 0, menuBarComponent,
  55811. managerOfChosenCommand,
  55812. componentAttachedTo);
  55813. if (activeSubMenu != 0)
  55814. {
  55815. activeSubMenu->setVisible (true);
  55816. activeSubMenu->enterModalState (false);
  55817. activeSubMenu->toFront (false);
  55818. return true;
  55819. }
  55820. }
  55821. return false;
  55822. }
  55823. void highlightItemUnderMouse (const int mx, const int my, const int x, const int y)
  55824. {
  55825. isOver = reallyContains (x, y, true);
  55826. if (isOver)
  55827. hasBeenOver = true;
  55828. if (abs (lastMouseX - mx) > 2 || abs (lastMouseY - my) > 2)
  55829. {
  55830. lastMouseMoveTime = Time::getApproximateMillisecondCounter();
  55831. if (disableMouseMoves && isOver)
  55832. disableMouseMoves = false;
  55833. }
  55834. if (disableMouseMoves)
  55835. return;
  55836. bool isMovingTowardsMenu = false;
  55837. jassert (activeSubMenu == 0 || activeSubMenu->isValidComponent())
  55838. if (isOver && (activeSubMenu != 0) && (mx != lastMouseX || my != lastMouseY))
  55839. {
  55840. // try to intelligently guess whether the user is moving the mouse towards a currently-open
  55841. // submenu. To do this, look at whether the mouse stays inside a triangular region that
  55842. // extends from the last mouse pos to the submenu's rectangle..
  55843. float subX = (float) activeSubMenu->getScreenX();
  55844. if (activeSubMenu->getX() > getX())
  55845. {
  55846. lastMouseX -= 2; // to enlarge the triangle a bit, in case the mouse only moves a couple of pixels
  55847. }
  55848. else
  55849. {
  55850. lastMouseX += 2;
  55851. subX += activeSubMenu->getWidth();
  55852. }
  55853. Path areaTowardsSubMenu;
  55854. areaTowardsSubMenu.addTriangle ((float) lastMouseX,
  55855. (float) lastMouseY,
  55856. subX,
  55857. (float) activeSubMenu->getScreenY(),
  55858. subX,
  55859. (float) (activeSubMenu->getScreenY() + activeSubMenu->getHeight()));
  55860. isMovingTowardsMenu = areaTowardsSubMenu.contains ((float) mx, (float) my);
  55861. }
  55862. lastMouseX = mx;
  55863. lastMouseY = my;
  55864. if (! isMovingTowardsMenu)
  55865. {
  55866. Component* c = getComponentAt (x, y);
  55867. if (c == this)
  55868. c = 0;
  55869. MenuItemComponent* mic = dynamic_cast <MenuItemComponent*> (c);
  55870. if (mic == 0 && c != 0)
  55871. mic = c->findParentComponentOfClass ((MenuItemComponent*) 0);
  55872. if (mic != currentChild
  55873. && (isOver || (activeSubMenu == 0) || ! activeSubMenu->isVisible()))
  55874. {
  55875. if (isOver && (c != 0) && (activeSubMenu != 0))
  55876. {
  55877. activeSubMenu->hide (0);
  55878. }
  55879. if (! isOver)
  55880. mic = 0;
  55881. setCurrentlyHighlightedChild (mic);
  55882. }
  55883. }
  55884. }
  55885. void triggerCurrentlyHighlightedItem()
  55886. {
  55887. if (currentChild->isValidComponent()
  55888. && currentChild->itemInfo.canBeTriggered()
  55889. && (currentChild->itemInfo.customComp == 0
  55890. || currentChild->itemInfo.customComp->isTriggeredAutomatically))
  55891. {
  55892. dismissMenu (&currentChild->itemInfo);
  55893. }
  55894. }
  55895. void selectNextItem (const int delta)
  55896. {
  55897. disableTimerUntilMouseMoves();
  55898. MenuItemComponent* mic = 0;
  55899. bool wasLastOne = (currentChild == 0);
  55900. const int numItems = getNumChildComponents();
  55901. for (int i = 0; i < numItems + 1; ++i)
  55902. {
  55903. int index = (delta > 0) ? i : (numItems - 1 - i);
  55904. index = (index + numItems) % numItems;
  55905. mic = dynamic_cast <MenuItemComponent*> (getChildComponent (index));
  55906. if (mic != 0 && (mic->itemInfo.canBeTriggered() || mic->itemInfo.hasActiveSubMenu())
  55907. && wasLastOne)
  55908. break;
  55909. if (mic == currentChild)
  55910. wasLastOne = true;
  55911. }
  55912. setCurrentlyHighlightedChild (mic);
  55913. }
  55914. void disableTimerUntilMouseMoves()
  55915. {
  55916. disableMouseMoves = true;
  55917. if (owner != 0)
  55918. owner->disableTimerUntilMouseMoves();
  55919. }
  55920. PopupMenuWindow (const PopupMenuWindow&);
  55921. const PopupMenuWindow& operator= (const PopupMenuWindow&);
  55922. };
  55923. PopupMenu::PopupMenu()
  55924. : lookAndFeel (0),
  55925. separatorPending (false)
  55926. {
  55927. }
  55928. PopupMenu::PopupMenu (const PopupMenu& other)
  55929. : lookAndFeel (other.lookAndFeel),
  55930. separatorPending (false)
  55931. {
  55932. items.ensureStorageAllocated (other.items.size());
  55933. for (int i = 0; i < other.items.size(); ++i)
  55934. items.add (new MenuItemInfo (*(const MenuItemInfo*) other.items.getUnchecked(i)));
  55935. }
  55936. const PopupMenu& PopupMenu::operator= (const PopupMenu& other)
  55937. {
  55938. if (this != &other)
  55939. {
  55940. lookAndFeel = other.lookAndFeel;
  55941. clear();
  55942. items.ensureStorageAllocated (other.items.size());
  55943. for (int i = 0; i < other.items.size(); ++i)
  55944. items.add (new MenuItemInfo (*(const MenuItemInfo*) other.items.getUnchecked(i)));
  55945. }
  55946. return *this;
  55947. }
  55948. PopupMenu::~PopupMenu()
  55949. {
  55950. clear();
  55951. }
  55952. void PopupMenu::clear()
  55953. {
  55954. for (int i = items.size(); --i >= 0;)
  55955. delete (MenuItemInfo*) items.getUnchecked(i);
  55956. items.clear();
  55957. separatorPending = false;
  55958. }
  55959. void PopupMenu::addSeparatorIfPending()
  55960. {
  55961. if (separatorPending)
  55962. {
  55963. separatorPending = false;
  55964. if (items.size() > 0)
  55965. items.add (new MenuItemInfo());
  55966. }
  55967. }
  55968. void PopupMenu::addItem (const int itemResultId,
  55969. const String& itemText,
  55970. const bool isActive,
  55971. const bool isTicked,
  55972. const Image* const iconToUse)
  55973. {
  55974. jassert (itemResultId != 0); // 0 is used as a return value to indicate that the user
  55975. // didn't pick anything, so you shouldn't use it as the id
  55976. // for an item..
  55977. addSeparatorIfPending();
  55978. items.add (new MenuItemInfo (itemResultId,
  55979. itemText,
  55980. isActive,
  55981. isTicked,
  55982. iconToUse,
  55983. Colours::black,
  55984. false,
  55985. 0, 0, 0));
  55986. }
  55987. void PopupMenu::addCommandItem (ApplicationCommandManager* commandManager,
  55988. const int commandID,
  55989. const String& displayName)
  55990. {
  55991. jassert (commandManager != 0 && commandID != 0);
  55992. const ApplicationCommandInfo* const registeredInfo = commandManager->getCommandForID (commandID);
  55993. if (registeredInfo != 0)
  55994. {
  55995. ApplicationCommandInfo info (*registeredInfo);
  55996. ApplicationCommandTarget* const target = commandManager->getTargetForCommand (commandID, info);
  55997. addSeparatorIfPending();
  55998. items.add (new MenuItemInfo (commandID,
  55999. displayName.isNotEmpty() ? displayName
  56000. : info.shortName,
  56001. target != 0 && (info.flags & ApplicationCommandInfo::isDisabled) == 0,
  56002. (info.flags & ApplicationCommandInfo::isTicked) != 0,
  56003. 0,
  56004. Colours::black,
  56005. false,
  56006. 0, 0,
  56007. commandManager));
  56008. }
  56009. }
  56010. void PopupMenu::addColouredItem (const int itemResultId,
  56011. const String& itemText,
  56012. const Colour& itemTextColour,
  56013. const bool isActive,
  56014. const bool isTicked,
  56015. const Image* const iconToUse)
  56016. {
  56017. jassert (itemResultId != 0); // 0 is used as a return value to indicate that the user
  56018. // didn't pick anything, so you shouldn't use it as the id
  56019. // for an item..
  56020. addSeparatorIfPending();
  56021. items.add (new MenuItemInfo (itemResultId,
  56022. itemText,
  56023. isActive,
  56024. isTicked,
  56025. iconToUse,
  56026. itemTextColour,
  56027. true,
  56028. 0, 0, 0));
  56029. }
  56030. void PopupMenu::addCustomItem (const int itemResultId,
  56031. PopupMenuCustomComponent* const customComponent)
  56032. {
  56033. jassert (itemResultId != 0); // 0 is used as a return value to indicate that the user
  56034. // didn't pick anything, so you shouldn't use it as the id
  56035. // for an item..
  56036. addSeparatorIfPending();
  56037. items.add (new MenuItemInfo (itemResultId,
  56038. String::empty,
  56039. true,
  56040. false,
  56041. 0,
  56042. Colours::black,
  56043. false,
  56044. customComponent,
  56045. 0, 0));
  56046. }
  56047. class NormalComponentWrapper : public PopupMenuCustomComponent
  56048. {
  56049. public:
  56050. NormalComponentWrapper (Component* const comp,
  56051. const int w, const int h,
  56052. const bool triggerMenuItemAutomaticallyWhenClicked)
  56053. : PopupMenuCustomComponent (triggerMenuItemAutomaticallyWhenClicked),
  56054. width (w),
  56055. height (h)
  56056. {
  56057. addAndMakeVisible (comp);
  56058. }
  56059. ~NormalComponentWrapper() {}
  56060. void getIdealSize (int& idealWidth, int& idealHeight)
  56061. {
  56062. idealWidth = width;
  56063. idealHeight = height;
  56064. }
  56065. void resized()
  56066. {
  56067. if (getChildComponent(0) != 0)
  56068. getChildComponent(0)->setBounds (0, 0, getWidth(), getHeight());
  56069. }
  56070. juce_UseDebuggingNewOperator
  56071. private:
  56072. const int width, height;
  56073. NormalComponentWrapper (const NormalComponentWrapper&);
  56074. const NormalComponentWrapper& operator= (const NormalComponentWrapper&);
  56075. };
  56076. void PopupMenu::addCustomItem (const int itemResultId,
  56077. Component* customComponent,
  56078. int idealWidth, int idealHeight,
  56079. const bool triggerMenuItemAutomaticallyWhenClicked)
  56080. {
  56081. addCustomItem (itemResultId,
  56082. new NormalComponentWrapper (customComponent,
  56083. idealWidth, idealHeight,
  56084. triggerMenuItemAutomaticallyWhenClicked));
  56085. }
  56086. void PopupMenu::addSubMenu (const String& subMenuName,
  56087. const PopupMenu& subMenu,
  56088. const bool isActive,
  56089. Image* const iconToUse,
  56090. const bool isTicked)
  56091. {
  56092. addSeparatorIfPending();
  56093. items.add (new MenuItemInfo (0,
  56094. subMenuName,
  56095. isActive && (subMenu.getNumItems() > 0),
  56096. isTicked,
  56097. iconToUse,
  56098. Colours::black,
  56099. false,
  56100. 0,
  56101. &subMenu,
  56102. 0));
  56103. }
  56104. void PopupMenu::addSeparator()
  56105. {
  56106. separatorPending = true;
  56107. }
  56108. class HeaderItemComponent : public PopupMenuCustomComponent
  56109. {
  56110. public:
  56111. HeaderItemComponent (const String& name)
  56112. : PopupMenuCustomComponent (false)
  56113. {
  56114. setName (name);
  56115. }
  56116. ~HeaderItemComponent()
  56117. {
  56118. }
  56119. void paint (Graphics& g)
  56120. {
  56121. Font f (getLookAndFeel().getPopupMenuFont());
  56122. f.setBold (true);
  56123. g.setFont (f);
  56124. g.setColour (findColour (PopupMenu::headerTextColourId));
  56125. g.drawFittedText (getName(),
  56126. 12, 0, getWidth() - 16, proportionOfHeight (0.8f),
  56127. Justification::bottomLeft, 1);
  56128. }
  56129. void getIdealSize (int& idealWidth,
  56130. int& idealHeight)
  56131. {
  56132. getLookAndFeel().getIdealPopupMenuItemSize (getName(), false, -1, idealWidth, idealHeight);
  56133. idealHeight += idealHeight / 2;
  56134. idealWidth += idealWidth / 4;
  56135. }
  56136. juce_UseDebuggingNewOperator
  56137. };
  56138. void PopupMenu::addSectionHeader (const String& title)
  56139. {
  56140. addCustomItem (0X4734a34f, new HeaderItemComponent (title));
  56141. }
  56142. Component* PopupMenu::createMenuComponent (const int x, const int y, const int w, const int h,
  56143. const int itemIdThatMustBeVisible,
  56144. const int minimumWidth,
  56145. const int maximumNumColumns,
  56146. const int standardItemHeight,
  56147. const bool alignToRectangle,
  56148. Component* menuBarComponent,
  56149. ApplicationCommandManager** managerOfChosenCommand,
  56150. Component* const componentAttachedTo)
  56151. {
  56152. PopupMenuWindow* const pw
  56153. = PopupMenuWindow::create (*this,
  56154. ModifierKeys::getCurrentModifiers().isAnyMouseButtonDown(),
  56155. 0,
  56156. x, x + w,
  56157. y, y + h,
  56158. minimumWidth,
  56159. maximumNumColumns,
  56160. standardItemHeight,
  56161. alignToRectangle,
  56162. itemIdThatMustBeVisible,
  56163. menuBarComponent,
  56164. managerOfChosenCommand,
  56165. componentAttachedTo);
  56166. if (pw != 0)
  56167. pw->setVisible (true);
  56168. return pw;
  56169. }
  56170. int PopupMenu::showMenu (const int x, const int y, const int w, const int h,
  56171. const int itemIdThatMustBeVisible,
  56172. const int minimumWidth,
  56173. const int maximumNumColumns,
  56174. const int standardItemHeight,
  56175. const bool alignToRectangle,
  56176. Component* const componentAttachedTo)
  56177. {
  56178. Component* const prevFocused = Component::getCurrentlyFocusedComponent();
  56179. ScopedPointer <ComponentDeletionWatcher> deletionChecker[2];
  56180. if (prevFocused != 0)
  56181. deletionChecker[0] = new ComponentDeletionWatcher (prevFocused);
  56182. Component* const prevTopLevel = (prevFocused != 0) ? prevFocused->getTopLevelComponent() : 0;
  56183. if (prevTopLevel != 0)
  56184. deletionChecker[1] = new ComponentDeletionWatcher (prevTopLevel);
  56185. wasHiddenBecauseOfAppChange = false;
  56186. int result = 0;
  56187. ApplicationCommandManager* managerOfChosenCommand = 0;
  56188. ScopedPointer <Component> popupComp (createMenuComponent (x, y, w, h,
  56189. itemIdThatMustBeVisible,
  56190. minimumWidth,
  56191. maximumNumColumns > 0 ? maximumNumColumns : 7,
  56192. standardItemHeight,
  56193. alignToRectangle, 0,
  56194. &managerOfChosenCommand,
  56195. componentAttachedTo));
  56196. if (popupComp != 0)
  56197. {
  56198. popupComp->enterModalState (false);
  56199. popupComp->toFront (false); // need to do this after making it modal, or it could
  56200. // be stuck behind other comps that are already modal..
  56201. result = popupComp->runModalLoop();
  56202. popupComp = 0;
  56203. if (! wasHiddenBecauseOfAppChange)
  56204. {
  56205. if (deletionChecker[1] != 0 && ! deletionChecker[1]->hasBeenDeleted())
  56206. prevTopLevel->toFront (true);
  56207. if (deletionChecker[0] != 0 && ! deletionChecker[0]->hasBeenDeleted())
  56208. prevFocused->grabKeyboardFocus();
  56209. }
  56210. }
  56211. if (managerOfChosenCommand != 0 && result != 0)
  56212. {
  56213. ApplicationCommandTarget::InvocationInfo info (result);
  56214. info.invocationMethod = ApplicationCommandTarget::InvocationInfo::fromMenu;
  56215. managerOfChosenCommand->invoke (info, true);
  56216. }
  56217. return result;
  56218. }
  56219. int PopupMenu::show (const int itemIdThatMustBeVisible,
  56220. const int minimumWidth,
  56221. const int maximumNumColumns,
  56222. const int standardItemHeight)
  56223. {
  56224. int x, y;
  56225. Desktop::getMousePosition (x, y);
  56226. return showAt (x, y,
  56227. itemIdThatMustBeVisible,
  56228. minimumWidth,
  56229. maximumNumColumns,
  56230. standardItemHeight);
  56231. }
  56232. int PopupMenu::showAt (const int screenX,
  56233. const int screenY,
  56234. const int itemIdThatMustBeVisible,
  56235. const int minimumWidth,
  56236. const int maximumNumColumns,
  56237. const int standardItemHeight)
  56238. {
  56239. return showMenu (screenX, screenY, 1, 1,
  56240. itemIdThatMustBeVisible,
  56241. minimumWidth, maximumNumColumns,
  56242. standardItemHeight,
  56243. false, 0);
  56244. }
  56245. int PopupMenu::showAt (Component* componentToAttachTo,
  56246. const int itemIdThatMustBeVisible,
  56247. const int minimumWidth,
  56248. const int maximumNumColumns,
  56249. const int standardItemHeight)
  56250. {
  56251. if (componentToAttachTo != 0)
  56252. {
  56253. return showMenu (componentToAttachTo->getScreenX(),
  56254. componentToAttachTo->getScreenY(),
  56255. componentToAttachTo->getWidth(),
  56256. componentToAttachTo->getHeight(),
  56257. itemIdThatMustBeVisible,
  56258. minimumWidth,
  56259. maximumNumColumns,
  56260. standardItemHeight,
  56261. true, componentToAttachTo);
  56262. }
  56263. else
  56264. {
  56265. return show (itemIdThatMustBeVisible,
  56266. minimumWidth,
  56267. maximumNumColumns,
  56268. standardItemHeight);
  56269. }
  56270. }
  56271. void JUCE_CALLTYPE PopupMenu::dismissAllActiveMenus()
  56272. {
  56273. for (int i = activeMenuWindows.size(); --i >= 0;)
  56274. {
  56275. PopupMenuWindow* const pmw = (PopupMenuWindow*) activeMenuWindows[i];
  56276. if (pmw != 0)
  56277. pmw->dismissMenu (0);
  56278. }
  56279. }
  56280. int PopupMenu::getNumItems() const
  56281. {
  56282. int num = 0;
  56283. for (int i = items.size(); --i >= 0;)
  56284. if (! ((MenuItemInfo*) items.getUnchecked(i))->isSeparator)
  56285. ++num;
  56286. return num;
  56287. }
  56288. bool PopupMenu::containsCommandItem (const int commandID) const
  56289. {
  56290. for (int i = items.size(); --i >= 0;)
  56291. {
  56292. const MenuItemInfo* mi = (const MenuItemInfo*) items.getUnchecked (i);
  56293. if ((mi->itemId == commandID && mi->commandManager != 0)
  56294. || (mi->subMenu != 0 && mi->subMenu->containsCommandItem (commandID)))
  56295. {
  56296. return true;
  56297. }
  56298. }
  56299. return false;
  56300. }
  56301. bool PopupMenu::containsAnyActiveItems() const
  56302. {
  56303. for (int i = items.size(); --i >= 0;)
  56304. {
  56305. const MenuItemInfo* const mi = (const MenuItemInfo*) items.getUnchecked (i);
  56306. if (mi->subMenu != 0)
  56307. {
  56308. if (mi->subMenu->containsAnyActiveItems())
  56309. return true;
  56310. }
  56311. else if (mi->active)
  56312. {
  56313. return true;
  56314. }
  56315. }
  56316. return false;
  56317. }
  56318. void PopupMenu::setLookAndFeel (LookAndFeel* const newLookAndFeel)
  56319. {
  56320. lookAndFeel = newLookAndFeel;
  56321. }
  56322. PopupMenuCustomComponent::PopupMenuCustomComponent (const bool isTriggeredAutomatically_)
  56323. : refCount_ (0),
  56324. isHighlighted (false),
  56325. isTriggeredAutomatically (isTriggeredAutomatically_)
  56326. {
  56327. }
  56328. PopupMenuCustomComponent::~PopupMenuCustomComponent()
  56329. {
  56330. jassert (refCount_ == 0); // should be deleted only by the menu component, as they keep a ref-count.
  56331. }
  56332. void PopupMenuCustomComponent::triggerMenuItem()
  56333. {
  56334. MenuItemComponent* const mic = dynamic_cast<MenuItemComponent*> (getParentComponent());
  56335. if (mic != 0)
  56336. {
  56337. PopupMenuWindow* const pmw = dynamic_cast<PopupMenuWindow*> (mic->getParentComponent());
  56338. if (pmw != 0)
  56339. {
  56340. pmw->dismissMenu (&mic->itemInfo);
  56341. }
  56342. else
  56343. {
  56344. // something must have gone wrong with the component hierarchy if this happens..
  56345. jassertfalse
  56346. }
  56347. }
  56348. else
  56349. {
  56350. // why isn't this component inside a menu? Not much point triggering the item if
  56351. // there's no menu.
  56352. jassertfalse
  56353. }
  56354. }
  56355. PopupMenu::MenuItemIterator::MenuItemIterator (const PopupMenu& menu_)
  56356. : subMenu (0),
  56357. itemId (0),
  56358. isSeparator (false),
  56359. isTicked (false),
  56360. isEnabled (false),
  56361. isCustomComponent (false),
  56362. isSectionHeader (false),
  56363. customColour (0),
  56364. customImage (0),
  56365. menu (menu_),
  56366. index (0)
  56367. {
  56368. }
  56369. PopupMenu::MenuItemIterator::~MenuItemIterator()
  56370. {
  56371. }
  56372. bool PopupMenu::MenuItemIterator::next()
  56373. {
  56374. if (index >= menu.items.size())
  56375. return false;
  56376. const MenuItemInfo* const item = (const MenuItemInfo*) menu.items.getUnchecked (index);
  56377. ++index;
  56378. itemName = item->customComp != 0 ? item->customComp->getName() : item->text;
  56379. subMenu = item->subMenu;
  56380. itemId = item->itemId;
  56381. isSeparator = item->isSeparator;
  56382. isTicked = item->isTicked;
  56383. isEnabled = item->active;
  56384. isSectionHeader = dynamic_cast <HeaderItemComponent*> (item->customComp) != 0;
  56385. isCustomComponent = (! isSectionHeader) && item->customComp != 0;
  56386. customColour = item->usesColour ? &(item->textColour) : 0;
  56387. customImage = item->image;
  56388. commandManager = item->commandManager;
  56389. return true;
  56390. }
  56391. END_JUCE_NAMESPACE
  56392. /********* End of inlined file: juce_PopupMenu.cpp *********/
  56393. /********* Start of inlined file: juce_ComponentDragger.cpp *********/
  56394. BEGIN_JUCE_NAMESPACE
  56395. ComponentDragger::ComponentDragger()
  56396. : constrainer (0),
  56397. originalX (0),
  56398. originalY (0)
  56399. {
  56400. }
  56401. ComponentDragger::~ComponentDragger()
  56402. {
  56403. }
  56404. void ComponentDragger::startDraggingComponent (Component* const componentToDrag,
  56405. ComponentBoundsConstrainer* const constrainer_)
  56406. {
  56407. jassert (componentToDrag->isValidComponent());
  56408. if (componentToDrag->isValidComponent())
  56409. {
  56410. constrainer = constrainer_;
  56411. originalX = 0;
  56412. originalY = 0;
  56413. componentToDrag->relativePositionToGlobal (originalX, originalY);
  56414. }
  56415. }
  56416. void ComponentDragger::dragComponent (Component* const componentToDrag, const MouseEvent& e)
  56417. {
  56418. jassert (componentToDrag->isValidComponent());
  56419. jassert (e.mods.isAnyMouseButtonDown()); // (the event has to be a drag event..)
  56420. if (componentToDrag->isValidComponent())
  56421. {
  56422. int x = originalX;
  56423. int y = originalY;
  56424. int w = componentToDrag->getWidth();
  56425. int h = componentToDrag->getHeight();
  56426. const Component* const parentComp = componentToDrag->getParentComponent();
  56427. if (parentComp != 0)
  56428. parentComp->globalPositionToRelative (x, y);
  56429. x += e.getDistanceFromDragStartX();
  56430. y += e.getDistanceFromDragStartY();
  56431. if (constrainer != 0)
  56432. constrainer->setBoundsForComponent (componentToDrag, x, y, w, h,
  56433. false, false, false, false);
  56434. else
  56435. componentToDrag->setBounds (x, y, w, h);
  56436. }
  56437. }
  56438. END_JUCE_NAMESPACE
  56439. /********* End of inlined file: juce_ComponentDragger.cpp *********/
  56440. /********* Start of inlined file: juce_DragAndDropContainer.cpp *********/
  56441. BEGIN_JUCE_NAMESPACE
  56442. bool juce_performDragDropFiles (const StringArray& files, const bool copyFiles, bool& shouldStop);
  56443. bool juce_performDragDropText (const String& text, bool& shouldStop);
  56444. class DragImageComponent : public Component,
  56445. public Timer
  56446. {
  56447. private:
  56448. ScopedPointer <Image> image;
  56449. Component* const source;
  56450. DragAndDropContainer* const owner;
  56451. ScopedPointer <ComponentDeletionWatcher> sourceWatcher, mouseDragSourceWatcher, currentlyOverWatcher;
  56452. Component* mouseDragSource;
  56453. DragAndDropTarget* currentlyOver;
  56454. String dragDesc;
  56455. const int imageX, imageY;
  56456. bool hasCheckedForExternalDrag, drawImage;
  56457. DragImageComponent (const DragImageComponent&);
  56458. const DragImageComponent& operator= (const DragImageComponent&);
  56459. public:
  56460. DragImageComponent (Image* const im,
  56461. const String& desc,
  56462. Component* const s,
  56463. DragAndDropContainer* const o,
  56464. const int imageX_, const int imageY_)
  56465. : image (im),
  56466. source (s),
  56467. owner (o),
  56468. currentlyOver (0),
  56469. dragDesc (desc),
  56470. imageX (imageX_),
  56471. imageY (imageY_),
  56472. hasCheckedForExternalDrag (false),
  56473. drawImage (true)
  56474. {
  56475. setSize (im->getWidth(), im->getHeight());
  56476. sourceWatcher = new ComponentDeletionWatcher (source);
  56477. mouseDragSource = Component::getComponentUnderMouse();
  56478. if (mouseDragSource == 0)
  56479. mouseDragSource = source;
  56480. mouseDragSourceWatcher = new ComponentDeletionWatcher (mouseDragSource);
  56481. mouseDragSource->addMouseListener (this, false);
  56482. startTimer (200);
  56483. setInterceptsMouseClicks (false, false);
  56484. setAlwaysOnTop (true);
  56485. }
  56486. ~DragImageComponent()
  56487. {
  56488. if ((DragImageComponent*) owner->dragImageComponent == this)
  56489. owner->dragImageComponent.release();
  56490. if (! mouseDragSourceWatcher->hasBeenDeleted())
  56491. {
  56492. mouseDragSource->removeMouseListener (this);
  56493. if (currentlyOverWatcher != 0 && ! currentlyOverWatcher->hasBeenDeleted())
  56494. if (currentlyOver->isInterestedInDragSource (dragDesc, source))
  56495. currentlyOver->itemDragExit (dragDesc, source);
  56496. }
  56497. }
  56498. void paint (Graphics& g)
  56499. {
  56500. if (isOpaque())
  56501. g.fillAll (Colours::white);
  56502. if (drawImage)
  56503. {
  56504. g.setOpacity (1.0f);
  56505. g.drawImageAt (image, 0, 0);
  56506. }
  56507. }
  56508. DragAndDropTarget* findTarget (const int screenX, const int screenY,
  56509. int& relX, int& relY) const
  56510. {
  56511. Component* hit = getParentComponent();
  56512. if (hit == 0)
  56513. {
  56514. hit = Desktop::getInstance().findComponentAt (screenX, screenY);
  56515. }
  56516. else
  56517. {
  56518. int rx = screenX, ry = screenY;
  56519. hit->globalPositionToRelative (rx, ry);
  56520. hit = hit->getComponentAt (rx, ry);
  56521. }
  56522. // (note: use a local copy of the dragDesc member in case the callback runs
  56523. // a modal loop and deletes this object before the method completes)
  56524. const String dragDescLocal (dragDesc);
  56525. while (hit != 0)
  56526. {
  56527. DragAndDropTarget* const ddt = dynamic_cast <DragAndDropTarget*> (hit);
  56528. if (ddt != 0 && ddt->isInterestedInDragSource (dragDescLocal, source))
  56529. {
  56530. relX = screenX;
  56531. relY = screenY;
  56532. hit->globalPositionToRelative (relX, relY);
  56533. return ddt;
  56534. }
  56535. hit = hit->getParentComponent();
  56536. }
  56537. return 0;
  56538. }
  56539. void mouseUp (const MouseEvent& e)
  56540. {
  56541. if (e.originalComponent != this)
  56542. {
  56543. if (! mouseDragSourceWatcher->hasBeenDeleted())
  56544. mouseDragSource->removeMouseListener (this);
  56545. bool dropAccepted = false;
  56546. DragAndDropTarget* ddt = 0;
  56547. int relX = 0, relY = 0;
  56548. if (isVisible())
  56549. {
  56550. setVisible (false);
  56551. ddt = findTarget (e.getScreenX(),
  56552. e.getScreenY(),
  56553. relX, relY);
  56554. // fade this component and remove it - it'll be deleted later by the timer callback
  56555. dropAccepted = ddt != 0;
  56556. setVisible (true);
  56557. if (dropAccepted || sourceWatcher->hasBeenDeleted())
  56558. {
  56559. fadeOutComponent (120);
  56560. }
  56561. else
  56562. {
  56563. int targetX = source->getWidth() / 2;
  56564. int targetY = source->getHeight() / 2;
  56565. source->relativePositionToGlobal (targetX, targetY);
  56566. int ourCentreX = getWidth() / 2;
  56567. int ourCentreY = getHeight() / 2;
  56568. relativePositionToGlobal (ourCentreX, ourCentreY);
  56569. fadeOutComponent (120,
  56570. targetX - ourCentreX,
  56571. targetY - ourCentreY);
  56572. }
  56573. }
  56574. if (getParentComponent() != 0)
  56575. getParentComponent()->removeChildComponent (this);
  56576. if (dropAccepted && ddt != 0)
  56577. {
  56578. // (note: use a local copy of the dragDesc member in case the callback runs
  56579. // a modal loop and deletes this object before the method completes)
  56580. const String dragDescLocal (dragDesc);
  56581. currentlyOverWatcher = 0;
  56582. currentlyOver = 0;
  56583. ddt->itemDropped (dragDescLocal, source, relX, relY);
  56584. }
  56585. // careful - this object could now be deleted..
  56586. }
  56587. }
  56588. void updateLocation (const bool canDoExternalDrag, int x, int y)
  56589. {
  56590. // (note: use a local copy of the dragDesc member in case the callback runs
  56591. // a modal loop and deletes this object before it returns)
  56592. const String dragDescLocal (dragDesc);
  56593. int newX = x + imageX;
  56594. int newY = y + imageY;
  56595. if (getParentComponent() != 0)
  56596. getParentComponent()->globalPositionToRelative (newX, newY);
  56597. //if (newX != getX() || newY != getY())
  56598. {
  56599. setTopLeftPosition (newX, newY);
  56600. int relX = 0, relY = 0;
  56601. DragAndDropTarget* const ddt = findTarget (x, y, relX, relY);
  56602. drawImage = (ddt == 0) || ddt->shouldDrawDragImageWhenOver();
  56603. if (ddt != currentlyOver)
  56604. {
  56605. if (currentlyOverWatcher != 0 && ! currentlyOverWatcher->hasBeenDeleted())
  56606. {
  56607. Component* const over = dynamic_cast <Component*> (currentlyOver);
  56608. if (over != 0
  56609. && over->isValidComponent()
  56610. && ! (sourceWatcher->hasBeenDeleted())
  56611. && currentlyOver->isInterestedInDragSource (dragDescLocal, source))
  56612. {
  56613. currentlyOver->itemDragExit (dragDescLocal, source);
  56614. }
  56615. }
  56616. currentlyOver = ddt;
  56617. currentlyOverWatcher = 0;
  56618. if (ddt != 0)
  56619. {
  56620. currentlyOverWatcher = new ComponentDeletionWatcher (dynamic_cast <Component*> (ddt));
  56621. if (currentlyOver->isInterestedInDragSource (dragDescLocal, source))
  56622. currentlyOver->itemDragEnter (dragDescLocal, source, relX, relY);
  56623. }
  56624. }
  56625. else if (currentlyOverWatcher != 0 && currentlyOverWatcher->hasBeenDeleted())
  56626. {
  56627. currentlyOver = 0;
  56628. currentlyOverWatcher = 0;
  56629. }
  56630. if (currentlyOver != 0
  56631. && currentlyOver->isInterestedInDragSource (dragDescLocal, source))
  56632. currentlyOver->itemDragMove (dragDescLocal, source, relX, relY);
  56633. if (currentlyOver == 0
  56634. && canDoExternalDrag
  56635. && ! hasCheckedForExternalDrag)
  56636. {
  56637. if (Desktop::getInstance().findComponentAt (x, y) == 0)
  56638. {
  56639. hasCheckedForExternalDrag = true;
  56640. StringArray files;
  56641. bool canMoveFiles = false;
  56642. if (owner->shouldDropFilesWhenDraggedExternally (dragDescLocal, source, files, canMoveFiles)
  56643. && files.size() > 0)
  56644. {
  56645. ComponentDeletionWatcher cdw (this);
  56646. setVisible (false);
  56647. if (ModifierKeys::getCurrentModifiersRealtime().isAnyMouseButtonDown())
  56648. DragAndDropContainer::performExternalDragDropOfFiles (files, canMoveFiles);
  56649. if (! cdw.hasBeenDeleted())
  56650. delete this;
  56651. return;
  56652. }
  56653. }
  56654. }
  56655. }
  56656. }
  56657. void mouseDrag (const MouseEvent& e)
  56658. {
  56659. if (e.originalComponent != this)
  56660. updateLocation (true, e.getScreenX(), e.getScreenY());
  56661. }
  56662. void timerCallback()
  56663. {
  56664. if (sourceWatcher->hasBeenDeleted())
  56665. {
  56666. delete this;
  56667. }
  56668. else if (! isMouseButtonDownAnywhere())
  56669. {
  56670. if (! mouseDragSourceWatcher->hasBeenDeleted())
  56671. mouseDragSource->removeMouseListener (this);
  56672. delete this;
  56673. }
  56674. }
  56675. };
  56676. DragAndDropContainer::DragAndDropContainer()
  56677. {
  56678. }
  56679. DragAndDropContainer::~DragAndDropContainer()
  56680. {
  56681. dragImageComponent = 0;
  56682. }
  56683. void DragAndDropContainer::startDragging (const String& sourceDescription,
  56684. Component* sourceComponent,
  56685. Image* dragImage_,
  56686. const bool allowDraggingToExternalWindows,
  56687. const Point* imageOffsetFromMouse)
  56688. {
  56689. ScopedPointer <Image> dragImage (dragImage_);
  56690. if (dragImageComponent == 0)
  56691. {
  56692. Component* const thisComp = dynamic_cast <Component*> (this);
  56693. if (thisComp != 0)
  56694. {
  56695. int mx, my;
  56696. Desktop::getLastMouseDownPosition (mx, my);
  56697. int imageX = 0, imageY = 0;
  56698. if (dragImage == 0)
  56699. {
  56700. dragImage = sourceComponent->createComponentSnapshot (Rectangle (0, 0, sourceComponent->getWidth(), sourceComponent->getHeight()));
  56701. if (dragImage->getFormat() != Image::ARGB)
  56702. {
  56703. Image* newIm = Image::createNativeImage (Image::ARGB, dragImage->getWidth(), dragImage->getHeight(), true);
  56704. Graphics g2 (*newIm);
  56705. g2.drawImageAt (dragImage, 0, 0);
  56706. dragImage = newIm;
  56707. }
  56708. dragImage->multiplyAllAlphas (0.6f);
  56709. const int lo = 150;
  56710. const int hi = 400;
  56711. int rx = mx, ry = my;
  56712. sourceComponent->globalPositionToRelative (rx, ry);
  56713. const int cx = jlimit (0, dragImage->getWidth(), rx);
  56714. const int cy = jlimit (0, dragImage->getHeight(), ry);
  56715. for (int y = dragImage->getHeight(); --y >= 0;)
  56716. {
  56717. const double dy = (y - cy) * (y - cy);
  56718. for (int x = dragImage->getWidth(); --x >= 0;)
  56719. {
  56720. const int dx = x - cx;
  56721. const int distance = roundToInt (sqrt (dx * dx + dy));
  56722. if (distance > lo)
  56723. {
  56724. const float alpha = (distance > hi) ? 0
  56725. : (hi - distance) / (float) (hi - lo)
  56726. + Random::getSystemRandom().nextFloat() * 0.008f;
  56727. dragImage->multiplyAlphaAt (x, y, alpha);
  56728. }
  56729. }
  56730. }
  56731. imageX = -cx;
  56732. imageY = -cy;
  56733. }
  56734. else
  56735. {
  56736. if (imageOffsetFromMouse == 0)
  56737. {
  56738. imageX = dragImage->getWidth() / -2;
  56739. imageY = dragImage->getHeight() / -2;
  56740. }
  56741. else
  56742. {
  56743. imageX = (int) imageOffsetFromMouse->getX();
  56744. imageY = (int) imageOffsetFromMouse->getY();
  56745. }
  56746. }
  56747. dragImageComponent = new DragImageComponent (dragImage.release(), sourceDescription, sourceComponent,
  56748. this, imageX, imageY);
  56749. currentDragDesc = sourceDescription;
  56750. if (allowDraggingToExternalWindows)
  56751. {
  56752. if (! Desktop::canUseSemiTransparentWindows())
  56753. dragImageComponent->setOpaque (true);
  56754. dragImageComponent->addToDesktop (ComponentPeer::windowIgnoresMouseClicks
  56755. | ComponentPeer::windowIsTemporary
  56756. | ComponentPeer::windowIgnoresKeyPresses);
  56757. }
  56758. else
  56759. thisComp->addChildComponent (dragImageComponent);
  56760. ((DragImageComponent*) dragImageComponent)->updateLocation (false, mx, my);
  56761. dragImageComponent->setVisible (true);
  56762. }
  56763. else
  56764. {
  56765. // this class must only be implemented by an object that
  56766. // is also a Component.
  56767. jassertfalse
  56768. }
  56769. }
  56770. }
  56771. bool DragAndDropContainer::isDragAndDropActive() const
  56772. {
  56773. return dragImageComponent != 0;
  56774. }
  56775. const String DragAndDropContainer::getCurrentDragDescription() const
  56776. {
  56777. return (dragImageComponent != 0) ? currentDragDesc
  56778. : String::empty;
  56779. }
  56780. DragAndDropContainer* DragAndDropContainer::findParentDragContainerFor (Component* c)
  56781. {
  56782. if (c == 0)
  56783. return 0;
  56784. // (unable to use the syntax findParentComponentOfClass <DragAndDropContainer> () because of a VC6 compiler bug)
  56785. return c->findParentComponentOfClass ((DragAndDropContainer*) 0);
  56786. }
  56787. bool DragAndDropContainer::shouldDropFilesWhenDraggedExternally (const String&, Component*, StringArray&, bool&)
  56788. {
  56789. return false;
  56790. }
  56791. void DragAndDropTarget::itemDragEnter (const String&, Component*, int, int)
  56792. {
  56793. }
  56794. void DragAndDropTarget::itemDragMove (const String&, Component*, int, int)
  56795. {
  56796. }
  56797. void DragAndDropTarget::itemDragExit (const String&, Component*)
  56798. {
  56799. }
  56800. bool DragAndDropTarget::shouldDrawDragImageWhenOver()
  56801. {
  56802. return true;
  56803. }
  56804. void FileDragAndDropTarget::fileDragEnter (const StringArray&, int, int)
  56805. {
  56806. }
  56807. void FileDragAndDropTarget::fileDragMove (const StringArray&, int, int)
  56808. {
  56809. }
  56810. void FileDragAndDropTarget::fileDragExit (const StringArray&)
  56811. {
  56812. }
  56813. END_JUCE_NAMESPACE
  56814. /********* End of inlined file: juce_DragAndDropContainer.cpp *********/
  56815. /********* Start of inlined file: juce_MouseCursor.cpp *********/
  56816. BEGIN_JUCE_NAMESPACE
  56817. void* juce_createMouseCursorFromImage (const Image& image, int hotspotX, int hotspotY) throw();
  56818. void* juce_createStandardMouseCursor (MouseCursor::StandardCursorType type) throw();
  56819. // isStandard set depending on which interface was used to create the cursor
  56820. void juce_deleteMouseCursor (void* const cursorHandle, const bool isStandard) throw();
  56821. static CriticalSection activeCursorListLock;
  56822. static VoidArray activeCursors;
  56823. class SharedMouseCursorInternal : public ReferenceCountedObject
  56824. {
  56825. public:
  56826. SharedMouseCursorInternal (const MouseCursor::StandardCursorType type) throw()
  56827. : standardType (type),
  56828. isStandard (true)
  56829. {
  56830. handle = juce_createStandardMouseCursor (standardType);
  56831. activeCursors.add (this);
  56832. }
  56833. SharedMouseCursorInternal (const Image& image, const int hotSpotX, const int hotSpotY) throw()
  56834. : standardType (MouseCursor::NormalCursor),
  56835. isStandard (false)
  56836. {
  56837. handle = juce_createMouseCursorFromImage (image, hotSpotX, hotSpotY);
  56838. }
  56839. ~SharedMouseCursorInternal() throw()
  56840. {
  56841. juce_deleteMouseCursor (handle, isStandard);
  56842. activeCursors.removeValue (this);
  56843. }
  56844. void* getHandle() const throw()
  56845. {
  56846. return handle;
  56847. }
  56848. static SharedMouseCursorInternal* findInstance (MouseCursor::StandardCursorType type) throw()
  56849. {
  56850. for (int i = activeCursors.size(); --i >= 0;)
  56851. {
  56852. SharedMouseCursorInternal* const r = (SharedMouseCursorInternal*) activeCursors.getUnchecked(i);
  56853. if (r->standardType == type)
  56854. return r;
  56855. }
  56856. return new SharedMouseCursorInternal (type);
  56857. }
  56858. juce_UseDebuggingNewOperator
  56859. private:
  56860. void* handle;
  56861. const MouseCursor::StandardCursorType standardType;
  56862. const bool isStandard;
  56863. const SharedMouseCursorInternal& operator= (const SharedMouseCursorInternal&);
  56864. };
  56865. MouseCursor::MouseCursor() throw()
  56866. {
  56867. const ScopedLock sl (activeCursorListLock);
  56868. cursorHandle = SharedMouseCursorInternal::findInstance (NormalCursor);
  56869. }
  56870. MouseCursor::MouseCursor (const StandardCursorType type) throw()
  56871. {
  56872. const ScopedLock sl (activeCursorListLock);
  56873. cursorHandle = SharedMouseCursorInternal::findInstance (type);
  56874. }
  56875. MouseCursor::MouseCursor (const Image& image, const int hotSpotX, const int hotSpotY) throw()
  56876. {
  56877. const ScopedLock sl (activeCursorListLock);
  56878. cursorHandle = new SharedMouseCursorInternal (image, hotSpotX, hotSpotY);
  56879. }
  56880. MouseCursor::MouseCursor (const MouseCursor& other) throw()
  56881. : cursorHandle (other.cursorHandle)
  56882. {
  56883. }
  56884. MouseCursor::~MouseCursor() throw()
  56885. {
  56886. }
  56887. const MouseCursor& MouseCursor::operator= (const MouseCursor& other) throw()
  56888. {
  56889. cursorHandle = other.cursorHandle;
  56890. return *this;
  56891. }
  56892. bool MouseCursor::operator== (const MouseCursor& other) const throw()
  56893. {
  56894. return cursorHandle == other.cursorHandle;
  56895. }
  56896. bool MouseCursor::operator!= (const MouseCursor& other) const throw()
  56897. {
  56898. return cursorHandle != other.cursorHandle;
  56899. }
  56900. void* MouseCursor::getHandle() const throw()
  56901. {
  56902. return cursorHandle->getHandle();
  56903. }
  56904. void MouseCursor::showWaitCursor() throw()
  56905. {
  56906. const MouseCursor mc (MouseCursor::WaitCursor);
  56907. mc.showInAllWindows();
  56908. }
  56909. void MouseCursor::hideWaitCursor() throw()
  56910. {
  56911. Component* const c = Component::getComponentUnderMouse();
  56912. MouseCursor mc (c->isValidComponent() ? c->getLookAndFeel().getMouseCursorFor (*c)
  56913. : MouseCursor::NormalCursor);
  56914. mc.showInAllWindows();
  56915. }
  56916. END_JUCE_NAMESPACE
  56917. /********* End of inlined file: juce_MouseCursor.cpp *********/
  56918. /********* Start of inlined file: juce_MouseEvent.cpp *********/
  56919. BEGIN_JUCE_NAMESPACE
  56920. MouseEvent::MouseEvent (const int x_,
  56921. const int y_,
  56922. const ModifierKeys& mods_,
  56923. Component* const originator,
  56924. const Time& eventTime_,
  56925. const int mouseDownX_,
  56926. const int mouseDownY_,
  56927. const Time& mouseDownTime_,
  56928. const int numberOfClicks_,
  56929. const bool mouseWasDragged) throw()
  56930. : x (x_),
  56931. y (y_),
  56932. mods (mods_),
  56933. eventComponent (originator),
  56934. originalComponent (originator),
  56935. eventTime (eventTime_),
  56936. mouseDownX (mouseDownX_),
  56937. mouseDownY (mouseDownY_),
  56938. mouseDownTime (mouseDownTime_),
  56939. numberOfClicks (numberOfClicks_),
  56940. wasMovedSinceMouseDown (mouseWasDragged)
  56941. {
  56942. }
  56943. MouseEvent::~MouseEvent() throw()
  56944. {
  56945. }
  56946. bool MouseEvent::mouseWasClicked() const throw()
  56947. {
  56948. return ! wasMovedSinceMouseDown;
  56949. }
  56950. int MouseEvent::getMouseDownX() const throw()
  56951. {
  56952. return mouseDownX;
  56953. }
  56954. int MouseEvent::getMouseDownY() const throw()
  56955. {
  56956. return mouseDownY;
  56957. }
  56958. int MouseEvent::getDistanceFromDragStartX() const throw()
  56959. {
  56960. return x - mouseDownX;
  56961. }
  56962. int MouseEvent::getDistanceFromDragStartY() const throw()
  56963. {
  56964. return y - mouseDownY;
  56965. }
  56966. int MouseEvent::getDistanceFromDragStart() const throw()
  56967. {
  56968. return roundToInt (juce_hypot (getDistanceFromDragStartX(),
  56969. getDistanceFromDragStartY()));
  56970. }
  56971. int MouseEvent::getLengthOfMousePress() const throw()
  56972. {
  56973. if (mouseDownTime.toMilliseconds() > 0)
  56974. return jmax (0, (int) (eventTime - mouseDownTime).inMilliseconds());
  56975. return 0;
  56976. }
  56977. int MouseEvent::getScreenX() const throw()
  56978. {
  56979. int sx = x, sy = y;
  56980. eventComponent->relativePositionToGlobal (sx, sy);
  56981. return sx;
  56982. }
  56983. int MouseEvent::getScreenY() const throw()
  56984. {
  56985. int sx = x, sy = y;
  56986. eventComponent->relativePositionToGlobal (sx, sy);
  56987. return sy;
  56988. }
  56989. int MouseEvent::getMouseDownScreenX() const throw()
  56990. {
  56991. int sx = mouseDownX, sy = mouseDownY;
  56992. eventComponent->relativePositionToGlobal (sx, sy);
  56993. return sx;
  56994. }
  56995. int MouseEvent::getMouseDownScreenY() const throw()
  56996. {
  56997. int sx = mouseDownX, sy = mouseDownY;
  56998. eventComponent->relativePositionToGlobal (sx, sy);
  56999. return sy;
  57000. }
  57001. const MouseEvent MouseEvent::getEventRelativeTo (Component* const otherComponent) const throw()
  57002. {
  57003. if (otherComponent == 0)
  57004. {
  57005. jassertfalse
  57006. return *this;
  57007. }
  57008. MouseEvent me (*this);
  57009. eventComponent->relativePositionToOtherComponent (otherComponent, me.x, me.y);
  57010. eventComponent->relativePositionToOtherComponent (otherComponent, me.mouseDownX, me.mouseDownY);
  57011. me.eventComponent = otherComponent;
  57012. return me;
  57013. }
  57014. static int doubleClickTimeOutMs = 400;
  57015. void MouseEvent::setDoubleClickTimeout (const int newTime) throw()
  57016. {
  57017. doubleClickTimeOutMs = newTime;
  57018. }
  57019. int MouseEvent::getDoubleClickTimeout() throw()
  57020. {
  57021. return doubleClickTimeOutMs;
  57022. }
  57023. END_JUCE_NAMESPACE
  57024. /********* End of inlined file: juce_MouseEvent.cpp *********/
  57025. /********* Start of inlined file: juce_MouseHoverDetector.cpp *********/
  57026. BEGIN_JUCE_NAMESPACE
  57027. MouseHoverDetector::MouseHoverDetector (const int hoverTimeMillisecs_)
  57028. : source (0),
  57029. hoverTimeMillisecs (hoverTimeMillisecs_),
  57030. hasJustHovered (false)
  57031. {
  57032. internalTimer.owner = this;
  57033. }
  57034. MouseHoverDetector::~MouseHoverDetector()
  57035. {
  57036. setHoverComponent (0);
  57037. }
  57038. void MouseHoverDetector::setHoverTimeMillisecs (const int newTimeInMillisecs)
  57039. {
  57040. hoverTimeMillisecs = newTimeInMillisecs;
  57041. }
  57042. void MouseHoverDetector::setHoverComponent (Component* const newSourceComponent)
  57043. {
  57044. if (source != newSourceComponent)
  57045. {
  57046. internalTimer.stopTimer();
  57047. hasJustHovered = false;
  57048. if (source != 0)
  57049. {
  57050. // ! you need to delete the hover detector before deleting its component
  57051. jassert (source->isValidComponent());
  57052. source->removeMouseListener (&internalTimer);
  57053. }
  57054. source = newSourceComponent;
  57055. if (newSourceComponent != 0)
  57056. newSourceComponent->addMouseListener (&internalTimer, false);
  57057. }
  57058. }
  57059. void MouseHoverDetector::hoverTimerCallback()
  57060. {
  57061. internalTimer.stopTimer();
  57062. if (source != 0)
  57063. {
  57064. int mx, my;
  57065. source->getMouseXYRelative (mx, my);
  57066. if (source->reallyContains (mx, my, false))
  57067. {
  57068. hasJustHovered = true;
  57069. mouseHovered (mx, my);
  57070. }
  57071. }
  57072. }
  57073. void MouseHoverDetector::checkJustHoveredCallback()
  57074. {
  57075. if (hasJustHovered)
  57076. {
  57077. hasJustHovered = false;
  57078. mouseMovedAfterHover();
  57079. }
  57080. }
  57081. void MouseHoverDetector::HoverDetectorInternal::timerCallback()
  57082. {
  57083. owner->hoverTimerCallback();
  57084. }
  57085. void MouseHoverDetector::HoverDetectorInternal::mouseEnter (const MouseEvent&)
  57086. {
  57087. stopTimer();
  57088. owner->checkJustHoveredCallback();
  57089. }
  57090. void MouseHoverDetector::HoverDetectorInternal::mouseExit (const MouseEvent&)
  57091. {
  57092. stopTimer();
  57093. owner->checkJustHoveredCallback();
  57094. }
  57095. void MouseHoverDetector::HoverDetectorInternal::mouseDown (const MouseEvent&)
  57096. {
  57097. stopTimer();
  57098. owner->checkJustHoveredCallback();
  57099. }
  57100. void MouseHoverDetector::HoverDetectorInternal::mouseUp (const MouseEvent&)
  57101. {
  57102. stopTimer();
  57103. owner->checkJustHoveredCallback();
  57104. }
  57105. void MouseHoverDetector::HoverDetectorInternal::mouseMove (const MouseEvent& e)
  57106. {
  57107. if (lastX != e.x || lastY != e.y) // to avoid fake mouse-moves setting it off
  57108. {
  57109. lastX = e.x;
  57110. lastY = e.y;
  57111. if (owner->source != 0)
  57112. startTimer (owner->hoverTimeMillisecs);
  57113. owner->checkJustHoveredCallback();
  57114. }
  57115. }
  57116. void MouseHoverDetector::HoverDetectorInternal::mouseWheelMove (const MouseEvent&, float, float)
  57117. {
  57118. stopTimer();
  57119. owner->checkJustHoveredCallback();
  57120. }
  57121. END_JUCE_NAMESPACE
  57122. /********* End of inlined file: juce_MouseHoverDetector.cpp *********/
  57123. /********* Start of inlined file: juce_MouseListener.cpp *********/
  57124. BEGIN_JUCE_NAMESPACE
  57125. void MouseListener::mouseEnter (const MouseEvent&)
  57126. {
  57127. }
  57128. void MouseListener::mouseExit (const MouseEvent&)
  57129. {
  57130. }
  57131. void MouseListener::mouseDown (const MouseEvent&)
  57132. {
  57133. }
  57134. void MouseListener::mouseUp (const MouseEvent&)
  57135. {
  57136. }
  57137. void MouseListener::mouseDrag (const MouseEvent&)
  57138. {
  57139. }
  57140. void MouseListener::mouseMove (const MouseEvent&)
  57141. {
  57142. }
  57143. void MouseListener::mouseDoubleClick (const MouseEvent&)
  57144. {
  57145. }
  57146. void MouseListener::mouseWheelMove (const MouseEvent&, float, float)
  57147. {
  57148. }
  57149. END_JUCE_NAMESPACE
  57150. /********* End of inlined file: juce_MouseListener.cpp *********/
  57151. /********* Start of inlined file: juce_BooleanPropertyComponent.cpp *********/
  57152. BEGIN_JUCE_NAMESPACE
  57153. BooleanPropertyComponent::BooleanPropertyComponent (const String& name,
  57154. const String& buttonTextWhenTrue,
  57155. const String& buttonTextWhenFalse)
  57156. : PropertyComponent (name),
  57157. onText (buttonTextWhenTrue),
  57158. offText (buttonTextWhenFalse)
  57159. {
  57160. createButton();
  57161. button->addButtonListener (this);
  57162. }
  57163. BooleanPropertyComponent::BooleanPropertyComponent (const Value& valueToControl,
  57164. const String& name,
  57165. const String& buttonText)
  57166. : PropertyComponent (name),
  57167. onText (buttonText),
  57168. offText (buttonText)
  57169. {
  57170. createButton();
  57171. button->setButtonText (buttonText);
  57172. button->getToggleStateValue().referTo (valueToControl);
  57173. button->setClickingTogglesState (true);
  57174. }
  57175. BooleanPropertyComponent::~BooleanPropertyComponent()
  57176. {
  57177. deleteAllChildren();
  57178. }
  57179. void BooleanPropertyComponent::createButton()
  57180. {
  57181. addAndMakeVisible (button = new ToggleButton (String::empty));
  57182. button->setClickingTogglesState (false);
  57183. }
  57184. void BooleanPropertyComponent::setState (const bool newState)
  57185. {
  57186. button->setToggleState (newState, true);
  57187. }
  57188. bool BooleanPropertyComponent::getState() const
  57189. {
  57190. return button->getToggleState();
  57191. }
  57192. void BooleanPropertyComponent::paint (Graphics& g)
  57193. {
  57194. PropertyComponent::paint (g);
  57195. const Rectangle r (button->getBounds());
  57196. g.setColour (Colours::white);
  57197. g.fillRect (r);
  57198. g.setColour (findColour (ComboBox::outlineColourId));
  57199. g.drawRect (r.getX(), r.getY(), r.getWidth(), r.getHeight());
  57200. }
  57201. void BooleanPropertyComponent::refresh()
  57202. {
  57203. button->setToggleState (getState(), false);
  57204. button->setButtonText (button->getToggleState() ? onText : offText);
  57205. }
  57206. void BooleanPropertyComponent::buttonClicked (Button*)
  57207. {
  57208. setState (! getState());
  57209. }
  57210. END_JUCE_NAMESPACE
  57211. /********* End of inlined file: juce_BooleanPropertyComponent.cpp *********/
  57212. /********* Start of inlined file: juce_ButtonPropertyComponent.cpp *********/
  57213. BEGIN_JUCE_NAMESPACE
  57214. ButtonPropertyComponent::ButtonPropertyComponent (const String& name,
  57215. const bool triggerOnMouseDown)
  57216. : PropertyComponent (name)
  57217. {
  57218. addAndMakeVisible (button = new TextButton (String::empty));
  57219. button->setTriggeredOnMouseDown (triggerOnMouseDown);
  57220. button->addButtonListener (this);
  57221. }
  57222. ButtonPropertyComponent::~ButtonPropertyComponent()
  57223. {
  57224. deleteAllChildren();
  57225. }
  57226. void ButtonPropertyComponent::refresh()
  57227. {
  57228. button->setButtonText (getButtonText());
  57229. }
  57230. void ButtonPropertyComponent::buttonClicked (Button*)
  57231. {
  57232. buttonClicked();
  57233. }
  57234. END_JUCE_NAMESPACE
  57235. /********* End of inlined file: juce_ButtonPropertyComponent.cpp *********/
  57236. /********* Start of inlined file: juce_ChoicePropertyComponent.cpp *********/
  57237. BEGIN_JUCE_NAMESPACE
  57238. ChoicePropertyComponent::ChoicePropertyComponent (const String& name)
  57239. : PropertyComponent (name),
  57240. comboBox (0)
  57241. {
  57242. }
  57243. ChoicePropertyComponent::ChoicePropertyComponent (const Value& valueToControl,
  57244. const String& name,
  57245. const StringArray& choices_,
  57246. const Array <int>* choiceIDs)
  57247. : PropertyComponent (name),
  57248. choices (choices_),
  57249. comboBox (0)
  57250. {
  57251. createComboBox (choiceIDs);
  57252. comboBox->getSelectedIdAsValue().referTo (valueToControl);
  57253. }
  57254. ChoicePropertyComponent::~ChoicePropertyComponent()
  57255. {
  57256. deleteAllChildren();
  57257. }
  57258. void ChoicePropertyComponent::createComboBox (const Array <int>* choiceIDs)
  57259. {
  57260. // The array of IDs must contain the same number of values as the choices list!
  57261. jassert (choiceIDs == 0 || choiceIDs->size() == choices.size());
  57262. addAndMakeVisible (comboBox = new ComboBox (String::empty));
  57263. for (int i = 0; i < choices.size(); ++i)
  57264. {
  57265. if (choices[i].isNotEmpty())
  57266. comboBox->addItem (choices[i], choiceIDs == 0 ? (i + 1)
  57267. : ((*choiceIDs)[i]));
  57268. else
  57269. comboBox->addSeparator();
  57270. }
  57271. comboBox->setEditableText (false);
  57272. }
  57273. void ChoicePropertyComponent::setIndex (const int newIndex)
  57274. {
  57275. comboBox->setSelectedId (comboBox->getItemId (newIndex));
  57276. }
  57277. int ChoicePropertyComponent::getIndex() const
  57278. {
  57279. return comboBox->getSelectedItemIndex();
  57280. }
  57281. const StringArray& ChoicePropertyComponent::getChoices() const
  57282. {
  57283. return choices;
  57284. }
  57285. void ChoicePropertyComponent::refresh()
  57286. {
  57287. if (comboBox == 0)
  57288. {
  57289. createComboBox (0);
  57290. comboBox->addListener (this);
  57291. }
  57292. comboBox->setSelectedId (getIndex() + 1, true);
  57293. }
  57294. void ChoicePropertyComponent::comboBoxChanged (ComboBox*)
  57295. {
  57296. const int newIndex = comboBox->getSelectedId() - 1;
  57297. if (newIndex != getIndex())
  57298. setIndex (newIndex);
  57299. }
  57300. END_JUCE_NAMESPACE
  57301. /********* End of inlined file: juce_ChoicePropertyComponent.cpp *********/
  57302. /********* Start of inlined file: juce_PropertyComponent.cpp *********/
  57303. BEGIN_JUCE_NAMESPACE
  57304. PropertyComponent::PropertyComponent (const String& name,
  57305. const int preferredHeight_)
  57306. : Component (name),
  57307. preferredHeight (preferredHeight_)
  57308. {
  57309. jassert (name.isNotEmpty());
  57310. }
  57311. PropertyComponent::~PropertyComponent()
  57312. {
  57313. }
  57314. void PropertyComponent::paint (Graphics& g)
  57315. {
  57316. getLookAndFeel().drawPropertyComponentBackground (g, getWidth(), getHeight(), *this);
  57317. getLookAndFeel().drawPropertyComponentLabel (g, getWidth(), getHeight(), *this);
  57318. }
  57319. void PropertyComponent::resized()
  57320. {
  57321. if (getNumChildComponents() > 0)
  57322. getChildComponent (0)->setBounds (getLookAndFeel().getPropertyComponentContentPosition (*this));
  57323. }
  57324. void PropertyComponent::enablementChanged()
  57325. {
  57326. repaint();
  57327. }
  57328. END_JUCE_NAMESPACE
  57329. /********* End of inlined file: juce_PropertyComponent.cpp *********/
  57330. /********* Start of inlined file: juce_PropertyPanel.cpp *********/
  57331. BEGIN_JUCE_NAMESPACE
  57332. class PropertyHolderComponent : public Component
  57333. {
  57334. public:
  57335. PropertyHolderComponent()
  57336. {
  57337. }
  57338. ~PropertyHolderComponent()
  57339. {
  57340. deleteAllChildren();
  57341. }
  57342. void paint (Graphics&)
  57343. {
  57344. }
  57345. void updateLayout (const int width);
  57346. void refreshAll() const;
  57347. };
  57348. class PropertySectionComponent : public Component
  57349. {
  57350. public:
  57351. PropertySectionComponent (const String& sectionTitle,
  57352. const Array <PropertyComponent*>& newProperties,
  57353. const bool open)
  57354. : Component (sectionTitle),
  57355. titleHeight (sectionTitle.isNotEmpty() ? 22 : 0),
  57356. isOpen_ (open)
  57357. {
  57358. for (int i = newProperties.size(); --i >= 0;)
  57359. {
  57360. addAndMakeVisible (newProperties.getUnchecked(i));
  57361. newProperties.getUnchecked(i)->refresh();
  57362. }
  57363. }
  57364. ~PropertySectionComponent()
  57365. {
  57366. deleteAllChildren();
  57367. }
  57368. void paint (Graphics& g)
  57369. {
  57370. if (titleHeight > 0)
  57371. getLookAndFeel().drawPropertyPanelSectionHeader (g, getName(), isOpen(), getWidth(), titleHeight);
  57372. }
  57373. void resized()
  57374. {
  57375. int y = titleHeight;
  57376. for (int i = getNumChildComponents(); --i >= 0;)
  57377. {
  57378. PropertyComponent* const pec = dynamic_cast <PropertyComponent*> (getChildComponent (i));
  57379. if (pec != 0)
  57380. {
  57381. const int prefH = pec->getPreferredHeight();
  57382. pec->setBounds (1, y, getWidth() - 2, prefH);
  57383. y += prefH;
  57384. }
  57385. }
  57386. }
  57387. int getPreferredHeight() const
  57388. {
  57389. int y = titleHeight;
  57390. if (isOpen())
  57391. {
  57392. for (int i = 0; i < getNumChildComponents(); ++i)
  57393. {
  57394. PropertyComponent* pec = dynamic_cast <PropertyComponent*> (getChildComponent (i));
  57395. if (pec != 0)
  57396. y += pec->getPreferredHeight();
  57397. }
  57398. }
  57399. return y;
  57400. }
  57401. void setOpen (const bool open)
  57402. {
  57403. if (isOpen_ != open)
  57404. {
  57405. isOpen_ = open;
  57406. for (int i = 0; i < getNumChildComponents(); ++i)
  57407. {
  57408. PropertyComponent* pec = dynamic_cast <PropertyComponent*> (getChildComponent (i));
  57409. if (pec != 0)
  57410. pec->setVisible (open);
  57411. }
  57412. // (unable to use the syntax findParentComponentOfClass <DragAndDropContainer> () because of a VC6 compiler bug)
  57413. PropertyPanel* const pp = findParentComponentOfClass ((PropertyPanel*) 0);
  57414. if (pp != 0)
  57415. pp->resized();
  57416. }
  57417. }
  57418. bool isOpen() const
  57419. {
  57420. return isOpen_;
  57421. }
  57422. void refreshAll() const
  57423. {
  57424. for (int i = 0; i < getNumChildComponents(); ++i)
  57425. {
  57426. PropertyComponent* pec = dynamic_cast <PropertyComponent*> (getChildComponent (i));
  57427. if (pec != 0)
  57428. pec->refresh();
  57429. }
  57430. }
  57431. void mouseDown (const MouseEvent&)
  57432. {
  57433. }
  57434. void mouseUp (const MouseEvent& e)
  57435. {
  57436. if (e.getMouseDownX() < titleHeight
  57437. && e.x < titleHeight
  57438. && e.y < titleHeight
  57439. && e.getNumberOfClicks() != 2)
  57440. {
  57441. setOpen (! isOpen());
  57442. }
  57443. }
  57444. void mouseDoubleClick (const MouseEvent& e)
  57445. {
  57446. if (e.y < titleHeight)
  57447. setOpen (! isOpen());
  57448. }
  57449. private:
  57450. int titleHeight;
  57451. bool isOpen_;
  57452. };
  57453. void PropertyHolderComponent::updateLayout (const int width)
  57454. {
  57455. int y = 0;
  57456. for (int i = getNumChildComponents(); --i >= 0;)
  57457. {
  57458. PropertySectionComponent* const section
  57459. = dynamic_cast <PropertySectionComponent*> (getChildComponent (i));
  57460. if (section != 0)
  57461. {
  57462. const int prefH = section->getPreferredHeight();
  57463. section->setBounds (0, y, width, prefH);
  57464. y += prefH;
  57465. }
  57466. }
  57467. setSize (width, y);
  57468. repaint();
  57469. }
  57470. void PropertyHolderComponent::refreshAll() const
  57471. {
  57472. for (int i = getNumChildComponents(); --i >= 0;)
  57473. {
  57474. PropertySectionComponent* const section
  57475. = dynamic_cast <PropertySectionComponent*> (getChildComponent (i));
  57476. if (section != 0)
  57477. section->refreshAll();
  57478. }
  57479. }
  57480. PropertyPanel::PropertyPanel()
  57481. {
  57482. messageWhenEmpty = TRANS("(nothing selected)");
  57483. addAndMakeVisible (viewport = new Viewport());
  57484. viewport->setViewedComponent (propertyHolderComponent = new PropertyHolderComponent());
  57485. viewport->setFocusContainer (true);
  57486. }
  57487. PropertyPanel::~PropertyPanel()
  57488. {
  57489. clear();
  57490. deleteAllChildren();
  57491. }
  57492. void PropertyPanel::paint (Graphics& g)
  57493. {
  57494. if (propertyHolderComponent->getNumChildComponents() == 0)
  57495. {
  57496. g.setColour (Colours::black.withAlpha (0.5f));
  57497. g.setFont (14.0f);
  57498. g.drawText (messageWhenEmpty, 0, 0, getWidth(), 30,
  57499. Justification::centred, true);
  57500. }
  57501. }
  57502. void PropertyPanel::resized()
  57503. {
  57504. viewport->setBounds (0, 0, getWidth(), getHeight());
  57505. updatePropHolderLayout();
  57506. }
  57507. void PropertyPanel::clear()
  57508. {
  57509. if (propertyHolderComponent->getNumChildComponents() > 0)
  57510. {
  57511. propertyHolderComponent->deleteAllChildren();
  57512. repaint();
  57513. }
  57514. }
  57515. void PropertyPanel::addProperties (const Array <PropertyComponent*>& newProperties)
  57516. {
  57517. if (propertyHolderComponent->getNumChildComponents() == 0)
  57518. repaint();
  57519. propertyHolderComponent->addAndMakeVisible (new PropertySectionComponent (String::empty,
  57520. newProperties,
  57521. true), 0);
  57522. updatePropHolderLayout();
  57523. }
  57524. void PropertyPanel::addSection (const String& sectionTitle,
  57525. const Array <PropertyComponent*>& newProperties,
  57526. const bool shouldBeOpen)
  57527. {
  57528. jassert (sectionTitle.isNotEmpty());
  57529. if (propertyHolderComponent->getNumChildComponents() == 0)
  57530. repaint();
  57531. propertyHolderComponent->addAndMakeVisible (new PropertySectionComponent (sectionTitle,
  57532. newProperties,
  57533. shouldBeOpen), 0);
  57534. updatePropHolderLayout();
  57535. }
  57536. void PropertyPanel::updatePropHolderLayout() const
  57537. {
  57538. const int maxWidth = viewport->getMaximumVisibleWidth();
  57539. ((PropertyHolderComponent*) propertyHolderComponent)->updateLayout (maxWidth);
  57540. const int newMaxWidth = viewport->getMaximumVisibleWidth();
  57541. if (maxWidth != newMaxWidth)
  57542. {
  57543. // need to do this twice because of scrollbars changing the size, etc.
  57544. ((PropertyHolderComponent*) propertyHolderComponent)->updateLayout (newMaxWidth);
  57545. }
  57546. }
  57547. void PropertyPanel::refreshAll() const
  57548. {
  57549. ((PropertyHolderComponent*) propertyHolderComponent)->refreshAll();
  57550. }
  57551. const StringArray PropertyPanel::getSectionNames() const
  57552. {
  57553. StringArray s;
  57554. for (int i = 0; i < propertyHolderComponent->getNumChildComponents(); ++i)
  57555. {
  57556. PropertySectionComponent* const section = dynamic_cast <PropertySectionComponent*> (propertyHolderComponent->getChildComponent (i));
  57557. if (section != 0 && section->getName().isNotEmpty())
  57558. s.add (section->getName());
  57559. }
  57560. return s;
  57561. }
  57562. bool PropertyPanel::isSectionOpen (const int sectionIndex) const
  57563. {
  57564. int index = 0;
  57565. for (int i = 0; i < propertyHolderComponent->getNumChildComponents(); ++i)
  57566. {
  57567. PropertySectionComponent* const section = dynamic_cast <PropertySectionComponent*> (propertyHolderComponent->getChildComponent (i));
  57568. if (section != 0 && section->getName().isNotEmpty())
  57569. {
  57570. if (index == sectionIndex)
  57571. return section->isOpen();
  57572. ++index;
  57573. }
  57574. }
  57575. return false;
  57576. }
  57577. void PropertyPanel::setSectionOpen (const int sectionIndex, const bool shouldBeOpen)
  57578. {
  57579. int index = 0;
  57580. for (int i = 0; i < propertyHolderComponent->getNumChildComponents(); ++i)
  57581. {
  57582. PropertySectionComponent* const section = dynamic_cast <PropertySectionComponent*> (propertyHolderComponent->getChildComponent (i));
  57583. if (section != 0 && section->getName().isNotEmpty())
  57584. {
  57585. if (index == sectionIndex)
  57586. {
  57587. section->setOpen (shouldBeOpen);
  57588. break;
  57589. }
  57590. ++index;
  57591. }
  57592. }
  57593. }
  57594. void PropertyPanel::setSectionEnabled (const int sectionIndex, const bool shouldBeEnabled)
  57595. {
  57596. int index = 0;
  57597. for (int i = 0; i < propertyHolderComponent->getNumChildComponents(); ++i)
  57598. {
  57599. PropertySectionComponent* const section = dynamic_cast <PropertySectionComponent*> (propertyHolderComponent->getChildComponent (i));
  57600. if (section != 0 && section->getName().isNotEmpty())
  57601. {
  57602. if (index == sectionIndex)
  57603. {
  57604. section->setEnabled (shouldBeEnabled);
  57605. break;
  57606. }
  57607. ++index;
  57608. }
  57609. }
  57610. }
  57611. XmlElement* PropertyPanel::getOpennessState() const
  57612. {
  57613. XmlElement* const xml = new XmlElement (T("PROPERTYPANELSTATE"));
  57614. const StringArray sections (getSectionNames());
  57615. for (int i = 0; i < sections.size(); ++i)
  57616. {
  57617. if (sections[i].isNotEmpty())
  57618. {
  57619. XmlElement* const e = new XmlElement (T("SECTION"));
  57620. e->setAttribute (T("name"), sections[i]);
  57621. e->setAttribute (T("open"), isSectionOpen (i) ? 1 : 0);
  57622. xml->addChildElement (e);
  57623. }
  57624. }
  57625. return xml;
  57626. }
  57627. void PropertyPanel::restoreOpennessState (const XmlElement& xml)
  57628. {
  57629. if (xml.hasTagName (T("PROPERTYPANELSTATE")))
  57630. {
  57631. const StringArray sections (getSectionNames());
  57632. forEachXmlChildElementWithTagName (xml, e, T("SECTION"))
  57633. {
  57634. setSectionOpen (sections.indexOf (e->getStringAttribute (T("name"))),
  57635. e->getBoolAttribute (T("open")));
  57636. }
  57637. }
  57638. }
  57639. void PropertyPanel::setMessageWhenEmpty (const String& newMessage)
  57640. {
  57641. if (messageWhenEmpty != newMessage)
  57642. {
  57643. messageWhenEmpty = newMessage;
  57644. repaint();
  57645. }
  57646. }
  57647. const String& PropertyPanel::getMessageWhenEmpty() const
  57648. {
  57649. return messageWhenEmpty;
  57650. }
  57651. END_JUCE_NAMESPACE
  57652. /********* End of inlined file: juce_PropertyPanel.cpp *********/
  57653. /********* Start of inlined file: juce_SliderPropertyComponent.cpp *********/
  57654. BEGIN_JUCE_NAMESPACE
  57655. SliderPropertyComponent::SliderPropertyComponent (const String& name,
  57656. const double rangeMin,
  57657. const double rangeMax,
  57658. const double interval,
  57659. const double skewFactor)
  57660. : PropertyComponent (name)
  57661. {
  57662. addAndMakeVisible (slider = new Slider (name));
  57663. slider->setRange (rangeMin, rangeMax, interval);
  57664. slider->setSkewFactor (skewFactor);
  57665. slider->setSliderStyle (Slider::LinearBar);
  57666. slider->addListener (this);
  57667. }
  57668. SliderPropertyComponent::SliderPropertyComponent (Value& valueToControl,
  57669. const String& name,
  57670. const double rangeMin,
  57671. const double rangeMax,
  57672. const double interval,
  57673. const double skewFactor)
  57674. : PropertyComponent (name)
  57675. {
  57676. addAndMakeVisible (slider = new Slider (name));
  57677. slider->setRange (rangeMin, rangeMax, interval);
  57678. slider->setSkewFactor (skewFactor);
  57679. slider->setSliderStyle (Slider::LinearBar);
  57680. slider->getValueObject().referTo (valueToControl);
  57681. }
  57682. SliderPropertyComponent::~SliderPropertyComponent()
  57683. {
  57684. deleteAllChildren();
  57685. }
  57686. void SliderPropertyComponent::setValue (const double /*newValue*/)
  57687. {
  57688. }
  57689. const double SliderPropertyComponent::getValue() const
  57690. {
  57691. return slider->getValue();
  57692. }
  57693. void SliderPropertyComponent::refresh()
  57694. {
  57695. slider->setValue (getValue(), false);
  57696. }
  57697. void SliderPropertyComponent::sliderValueChanged (Slider*)
  57698. {
  57699. if (getValue() != slider->getValue())
  57700. setValue (slider->getValue());
  57701. }
  57702. END_JUCE_NAMESPACE
  57703. /********* End of inlined file: juce_SliderPropertyComponent.cpp *********/
  57704. /********* Start of inlined file: juce_TextPropertyComponent.cpp *********/
  57705. BEGIN_JUCE_NAMESPACE
  57706. class TextPropLabel : public Label
  57707. {
  57708. TextPropertyComponent& owner;
  57709. int maxChars;
  57710. bool isMultiline;
  57711. public:
  57712. TextPropLabel (TextPropertyComponent& owner_,
  57713. const int maxChars_, const bool isMultiline_)
  57714. : Label (String::empty, String::empty),
  57715. owner (owner_),
  57716. maxChars (maxChars_),
  57717. isMultiline (isMultiline_)
  57718. {
  57719. setEditable (true, true, false);
  57720. setColour (backgroundColourId, Colours::white);
  57721. setColour (outlineColourId, findColour (ComboBox::outlineColourId));
  57722. }
  57723. ~TextPropLabel()
  57724. {
  57725. }
  57726. TextEditor* createEditorComponent()
  57727. {
  57728. TextEditor* const textEditor = Label::createEditorComponent();
  57729. textEditor->setInputRestrictions (maxChars);
  57730. if (isMultiline)
  57731. {
  57732. textEditor->setMultiLine (true, true);
  57733. textEditor->setReturnKeyStartsNewLine (true);
  57734. }
  57735. return textEditor;
  57736. }
  57737. void textWasEdited()
  57738. {
  57739. owner.textWasEdited();
  57740. }
  57741. };
  57742. TextPropertyComponent::TextPropertyComponent (const String& name,
  57743. const int maxNumChars,
  57744. const bool isMultiLine)
  57745. : PropertyComponent (name)
  57746. {
  57747. createEditor (maxNumChars, isMultiLine);
  57748. }
  57749. TextPropertyComponent::TextPropertyComponent (const Value& valueToControl,
  57750. const String& name,
  57751. const int maxNumChars,
  57752. const bool isMultiLine)
  57753. : PropertyComponent (name)
  57754. {
  57755. createEditor (maxNumChars, isMultiLine);
  57756. textEditor->getTextValue().referTo (valueToControl);
  57757. }
  57758. TextPropertyComponent::~TextPropertyComponent()
  57759. {
  57760. deleteAllChildren();
  57761. }
  57762. void TextPropertyComponent::setText (const String& newText)
  57763. {
  57764. textEditor->setText (newText, true);
  57765. }
  57766. const String TextPropertyComponent::getText() const
  57767. {
  57768. return textEditor->getText();
  57769. }
  57770. void TextPropertyComponent::createEditor (const int maxNumChars, const bool isMultiLine)
  57771. {
  57772. addAndMakeVisible (textEditor = new TextPropLabel (*this, maxNumChars, isMultiLine));
  57773. if (isMultiLine)
  57774. {
  57775. textEditor->setJustificationType (Justification::topLeft);
  57776. preferredHeight = 120;
  57777. }
  57778. }
  57779. void TextPropertyComponent::refresh()
  57780. {
  57781. textEditor->setText (getText(), false);
  57782. }
  57783. void TextPropertyComponent::textWasEdited()
  57784. {
  57785. const String newText (textEditor->getText());
  57786. if (getText() != newText)
  57787. setText (newText);
  57788. }
  57789. END_JUCE_NAMESPACE
  57790. /********* End of inlined file: juce_TextPropertyComponent.cpp *********/
  57791. /********* Start of inlined file: juce_AudioDeviceSelectorComponent.cpp *********/
  57792. BEGIN_JUCE_NAMESPACE
  57793. class SimpleDeviceManagerInputLevelMeter : public Component,
  57794. public Timer
  57795. {
  57796. public:
  57797. SimpleDeviceManagerInputLevelMeter (AudioDeviceManager* const manager_)
  57798. : manager (manager_),
  57799. level (0)
  57800. {
  57801. startTimer (50);
  57802. manager->enableInputLevelMeasurement (true);
  57803. }
  57804. ~SimpleDeviceManagerInputLevelMeter()
  57805. {
  57806. manager->enableInputLevelMeasurement (false);
  57807. }
  57808. void timerCallback()
  57809. {
  57810. const float newLevel = (float) manager->getCurrentInputLevel();
  57811. if (fabsf (level - newLevel) > 0.005f)
  57812. {
  57813. level = newLevel;
  57814. repaint();
  57815. }
  57816. }
  57817. void paint (Graphics& g)
  57818. {
  57819. getLookAndFeel().drawLevelMeter (g, getWidth(), getHeight(),
  57820. (float) exp (log (level) / 3.0)); // (add a bit of a skew to make the level more obvious)
  57821. }
  57822. private:
  57823. AudioDeviceManager* const manager;
  57824. float level;
  57825. };
  57826. class MidiInputSelectorComponentListBox : public ListBox,
  57827. public ListBoxModel
  57828. {
  57829. public:
  57830. MidiInputSelectorComponentListBox (AudioDeviceManager& deviceManager_,
  57831. const String& noItemsMessage_,
  57832. const int minNumber_,
  57833. const int maxNumber_)
  57834. : ListBox (String::empty, 0),
  57835. deviceManager (deviceManager_),
  57836. noItemsMessage (noItemsMessage_),
  57837. minNumber (minNumber_),
  57838. maxNumber (maxNumber_)
  57839. {
  57840. items = MidiInput::getDevices();
  57841. setModel (this);
  57842. setOutlineThickness (1);
  57843. }
  57844. ~MidiInputSelectorComponentListBox()
  57845. {
  57846. }
  57847. int getNumRows()
  57848. {
  57849. return items.size();
  57850. }
  57851. void paintListBoxItem (int row,
  57852. Graphics& g,
  57853. int width, int height,
  57854. bool rowIsSelected)
  57855. {
  57856. if (((unsigned int) row) < (unsigned int) items.size())
  57857. {
  57858. if (rowIsSelected)
  57859. g.fillAll (findColour (TextEditor::highlightColourId)
  57860. .withMultipliedAlpha (0.3f));
  57861. const String item (items [row]);
  57862. bool enabled = deviceManager.isMidiInputEnabled (item);
  57863. const int x = getTickX();
  57864. const int tickW = height - height / 4;
  57865. getLookAndFeel().drawTickBox (g, *this, x - tickW, (height - tickW) / 2, tickW, tickW,
  57866. enabled, true, true, false);
  57867. g.setFont (height * 0.6f);
  57868. g.setColour (findColour (ListBox::textColourId, true).withMultipliedAlpha (enabled ? 1.0f : 0.6f));
  57869. g.drawText (item, x, 0, width - x - 2, height, Justification::centredLeft, true);
  57870. }
  57871. }
  57872. void listBoxItemClicked (int row, const MouseEvent& e)
  57873. {
  57874. selectRow (row);
  57875. if (e.x < getTickX())
  57876. flipEnablement (row);
  57877. }
  57878. void listBoxItemDoubleClicked (int row, const MouseEvent&)
  57879. {
  57880. flipEnablement (row);
  57881. }
  57882. void returnKeyPressed (int row)
  57883. {
  57884. flipEnablement (row);
  57885. }
  57886. void paint (Graphics& g)
  57887. {
  57888. ListBox::paint (g);
  57889. if (items.size() == 0)
  57890. {
  57891. g.setColour (Colours::grey);
  57892. g.setFont (13.0f);
  57893. g.drawText (noItemsMessage,
  57894. 0, 0, getWidth(), getHeight() / 2,
  57895. Justification::centred, true);
  57896. }
  57897. }
  57898. int getBestHeight (const int preferredHeight)
  57899. {
  57900. const int extra = getOutlineThickness() * 2;
  57901. return jmax (getRowHeight() * 2 + extra,
  57902. jmin (getRowHeight() * getNumRows() + extra,
  57903. preferredHeight));
  57904. }
  57905. juce_UseDebuggingNewOperator
  57906. private:
  57907. AudioDeviceManager& deviceManager;
  57908. const String noItemsMessage;
  57909. StringArray items;
  57910. int minNumber, maxNumber;
  57911. void flipEnablement (const int row)
  57912. {
  57913. if (((unsigned int) row) < (unsigned int) items.size())
  57914. {
  57915. const String item (items [row]);
  57916. deviceManager.setMidiInputEnabled (item, ! deviceManager.isMidiInputEnabled (item));
  57917. }
  57918. }
  57919. int getTickX() const
  57920. {
  57921. return getRowHeight() + 5;
  57922. }
  57923. MidiInputSelectorComponentListBox (const MidiInputSelectorComponentListBox&);
  57924. const MidiInputSelectorComponentListBox& operator= (const MidiInputSelectorComponentListBox&);
  57925. };
  57926. class AudioDeviceSettingsPanel : public Component,
  57927. public ComboBoxListener,
  57928. public ChangeListener,
  57929. public ButtonListener
  57930. {
  57931. public:
  57932. AudioDeviceSettingsPanel (AudioIODeviceType* type_,
  57933. AudioIODeviceType::DeviceSetupDetails& setup_,
  57934. const bool hideAdvancedOptionsWithButton)
  57935. : type (type_),
  57936. setup (setup_)
  57937. {
  57938. sampleRateDropDown = 0;
  57939. sampleRateLabel = 0;
  57940. bufferSizeDropDown = 0;
  57941. bufferSizeLabel = 0;
  57942. outputDeviceDropDown = 0;
  57943. outputDeviceLabel = 0;
  57944. inputDeviceDropDown = 0;
  57945. inputDeviceLabel = 0;
  57946. testButton = 0;
  57947. inputLevelMeter = 0;
  57948. showUIButton = 0;
  57949. inputChanList = 0;
  57950. outputChanList = 0;
  57951. inputChanLabel = 0;
  57952. outputChanLabel = 0;
  57953. showAdvancedSettingsButton = 0;
  57954. if (hideAdvancedOptionsWithButton)
  57955. {
  57956. addAndMakeVisible (showAdvancedSettingsButton = new TextButton (TRANS("Show advanced settings...")));
  57957. showAdvancedSettingsButton->addButtonListener (this);
  57958. }
  57959. type->scanForDevices();
  57960. setup.manager->addChangeListener (this);
  57961. changeListenerCallback (0);
  57962. }
  57963. ~AudioDeviceSettingsPanel()
  57964. {
  57965. setup.manager->removeChangeListener (this);
  57966. deleteAndZero (outputDeviceLabel);
  57967. deleteAndZero (inputDeviceLabel);
  57968. deleteAndZero (sampleRateLabel);
  57969. deleteAndZero (bufferSizeLabel);
  57970. deleteAndZero (showUIButton);
  57971. deleteAndZero (inputChanLabel);
  57972. deleteAndZero (outputChanLabel);
  57973. deleteAndZero (showAdvancedSettingsButton);
  57974. deleteAllChildren();
  57975. }
  57976. void resized()
  57977. {
  57978. const int lx = proportionOfWidth (0.35f);
  57979. const int w = proportionOfWidth (0.4f);
  57980. const int h = 24;
  57981. const int space = 6;
  57982. const int dh = h + space;
  57983. int y = 0;
  57984. if (outputDeviceDropDown != 0)
  57985. {
  57986. outputDeviceDropDown->setBounds (lx, y, w, h);
  57987. if (testButton != 0)
  57988. testButton->setBounds (proportionOfWidth (0.77f),
  57989. outputDeviceDropDown->getY(),
  57990. proportionOfWidth (0.18f),
  57991. h);
  57992. y += dh;
  57993. }
  57994. if (inputDeviceDropDown != 0)
  57995. {
  57996. inputDeviceDropDown->setBounds (lx, y, w, h);
  57997. inputLevelMeter->setBounds (proportionOfWidth (0.77f),
  57998. inputDeviceDropDown->getY(),
  57999. proportionOfWidth (0.18f),
  58000. h);
  58001. y += dh;
  58002. }
  58003. const int maxBoxHeight = 100;//(getHeight() - y - dh * 2) / numBoxes;
  58004. if (outputChanList != 0)
  58005. {
  58006. const int bh = outputChanList->getBestHeight (maxBoxHeight);
  58007. outputChanList->setBounds (lx, y, proportionOfWidth (0.55f), bh);
  58008. y += bh + space;
  58009. }
  58010. if (inputChanList != 0)
  58011. {
  58012. const int bh = inputChanList->getBestHeight (maxBoxHeight);
  58013. inputChanList->setBounds (lx, y, proportionOfWidth (0.55f), bh);
  58014. y += bh + space;
  58015. }
  58016. y += space * 2;
  58017. if (showAdvancedSettingsButton != 0)
  58018. {
  58019. showAdvancedSettingsButton->changeWidthToFitText (h);
  58020. showAdvancedSettingsButton->setTopLeftPosition (lx, y);
  58021. }
  58022. if (sampleRateDropDown != 0)
  58023. {
  58024. sampleRateDropDown->setVisible (showAdvancedSettingsButton == 0
  58025. || ! showAdvancedSettingsButton->isVisible());
  58026. sampleRateDropDown->setBounds (lx, y, w, h);
  58027. y += dh;
  58028. }
  58029. if (bufferSizeDropDown != 0)
  58030. {
  58031. bufferSizeDropDown->setVisible (showAdvancedSettingsButton == 0
  58032. || ! showAdvancedSettingsButton->isVisible());
  58033. bufferSizeDropDown->setBounds (lx, y, w, h);
  58034. y += dh;
  58035. }
  58036. if (showUIButton != 0)
  58037. {
  58038. showUIButton->setVisible (showAdvancedSettingsButton == 0
  58039. || ! showAdvancedSettingsButton->isVisible());
  58040. showUIButton->changeWidthToFitText (h);
  58041. showUIButton->setTopLeftPosition (lx, y);
  58042. }
  58043. }
  58044. void comboBoxChanged (ComboBox* comboBoxThatHasChanged)
  58045. {
  58046. if (comboBoxThatHasChanged == 0)
  58047. return;
  58048. AudioDeviceManager::AudioDeviceSetup config;
  58049. setup.manager->getAudioDeviceSetup (config);
  58050. String error;
  58051. if (comboBoxThatHasChanged == outputDeviceDropDown
  58052. || comboBoxThatHasChanged == inputDeviceDropDown)
  58053. {
  58054. if (outputDeviceDropDown != 0)
  58055. config.outputDeviceName = outputDeviceDropDown->getSelectedId() < 0 ? String::empty
  58056. : outputDeviceDropDown->getText();
  58057. if (inputDeviceDropDown != 0)
  58058. config.inputDeviceName = inputDeviceDropDown->getSelectedId() < 0 ? String::empty
  58059. : inputDeviceDropDown->getText();
  58060. if (! type->hasSeparateInputsAndOutputs())
  58061. config.inputDeviceName = config.outputDeviceName;
  58062. if (comboBoxThatHasChanged == inputDeviceDropDown)
  58063. config.useDefaultInputChannels = true;
  58064. else
  58065. config.useDefaultOutputChannels = true;
  58066. error = setup.manager->setAudioDeviceSetup (config, true);
  58067. showCorrectDeviceName (inputDeviceDropDown, true);
  58068. showCorrectDeviceName (outputDeviceDropDown, false);
  58069. updateControlPanelButton();
  58070. resized();
  58071. }
  58072. else if (comboBoxThatHasChanged == sampleRateDropDown)
  58073. {
  58074. if (sampleRateDropDown->getSelectedId() > 0)
  58075. {
  58076. config.sampleRate = sampleRateDropDown->getSelectedId();
  58077. error = setup.manager->setAudioDeviceSetup (config, true);
  58078. }
  58079. }
  58080. else if (comboBoxThatHasChanged == bufferSizeDropDown)
  58081. {
  58082. if (bufferSizeDropDown->getSelectedId() > 0)
  58083. {
  58084. config.bufferSize = bufferSizeDropDown->getSelectedId();
  58085. error = setup.manager->setAudioDeviceSetup (config, true);
  58086. }
  58087. }
  58088. if (error.isNotEmpty())
  58089. {
  58090. AlertWindow::showMessageBox (AlertWindow::WarningIcon,
  58091. T("Error when trying to open audio device!"),
  58092. error);
  58093. }
  58094. }
  58095. void buttonClicked (Button* button)
  58096. {
  58097. if (button == showAdvancedSettingsButton)
  58098. {
  58099. showAdvancedSettingsButton->setVisible (false);
  58100. resized();
  58101. }
  58102. else if (button == showUIButton)
  58103. {
  58104. AudioIODevice* const device = setup.manager->getCurrentAudioDevice();
  58105. if (device != 0 && device->showControlPanel())
  58106. {
  58107. setup.manager->closeAudioDevice();
  58108. setup.manager->restartLastAudioDevice();
  58109. getTopLevelComponent()->toFront (true);
  58110. }
  58111. }
  58112. else if (button == testButton && testButton != 0)
  58113. {
  58114. setup.manager->playTestSound();
  58115. }
  58116. }
  58117. void updateControlPanelButton()
  58118. {
  58119. AudioIODevice* const currentDevice = setup.manager->getCurrentAudioDevice();
  58120. deleteAndZero (showUIButton);
  58121. if (currentDevice != 0 && currentDevice->hasControlPanel())
  58122. {
  58123. addAndMakeVisible (showUIButton = new TextButton (TRANS ("show this device's control panel"),
  58124. TRANS ("opens the device's own control panel")));
  58125. showUIButton->addButtonListener (this);
  58126. }
  58127. resized();
  58128. }
  58129. void changeListenerCallback (void*)
  58130. {
  58131. AudioIODevice* const currentDevice = setup.manager->getCurrentAudioDevice();
  58132. if (setup.maxNumOutputChannels > 0 || ! type->hasSeparateInputsAndOutputs())
  58133. {
  58134. if (outputDeviceDropDown == 0)
  58135. {
  58136. outputDeviceDropDown = new ComboBox (String::empty);
  58137. outputDeviceDropDown->addListener (this);
  58138. addAndMakeVisible (outputDeviceDropDown);
  58139. outputDeviceLabel = new Label (String::empty,
  58140. type->hasSeparateInputsAndOutputs() ? TRANS ("output:")
  58141. : TRANS ("device:"));
  58142. outputDeviceLabel->attachToComponent (outputDeviceDropDown, true);
  58143. if (setup.maxNumOutputChannels > 0)
  58144. {
  58145. addAndMakeVisible (testButton = new TextButton (TRANS ("Test")));
  58146. testButton->addButtonListener (this);
  58147. }
  58148. }
  58149. addNamesToDeviceBox (*outputDeviceDropDown, false);
  58150. }
  58151. if (setup.maxNumInputChannels > 0 && type->hasSeparateInputsAndOutputs())
  58152. {
  58153. if (inputDeviceDropDown == 0)
  58154. {
  58155. inputDeviceDropDown = new ComboBox (String::empty);
  58156. inputDeviceDropDown->addListener (this);
  58157. addAndMakeVisible (inputDeviceDropDown);
  58158. inputDeviceLabel = new Label (String::empty, TRANS ("input:"));
  58159. inputDeviceLabel->attachToComponent (inputDeviceDropDown, true);
  58160. addAndMakeVisible (inputLevelMeter
  58161. = new SimpleDeviceManagerInputLevelMeter (setup.manager));
  58162. }
  58163. addNamesToDeviceBox (*inputDeviceDropDown, true);
  58164. }
  58165. updateControlPanelButton();
  58166. showCorrectDeviceName (inputDeviceDropDown, true);
  58167. showCorrectDeviceName (outputDeviceDropDown, false);
  58168. if (currentDevice != 0)
  58169. {
  58170. if (setup.maxNumOutputChannels > 0
  58171. && setup.minNumOutputChannels < setup.manager->getCurrentAudioDevice()->getOutputChannelNames().size())
  58172. {
  58173. if (outputChanList == 0)
  58174. {
  58175. addAndMakeVisible (outputChanList
  58176. = new ChannelSelectorListBox (setup, ChannelSelectorListBox::audioOutputType,
  58177. TRANS ("(no audio output channels found)")));
  58178. outputChanLabel = new Label (String::empty, TRANS ("active output channels:"));
  58179. outputChanLabel->attachToComponent (outputChanList, true);
  58180. }
  58181. outputChanList->refresh();
  58182. }
  58183. else
  58184. {
  58185. deleteAndZero (outputChanLabel);
  58186. deleteAndZero (outputChanList);
  58187. }
  58188. if (setup.maxNumInputChannels > 0
  58189. && setup.minNumInputChannels < setup.manager->getCurrentAudioDevice()->getInputChannelNames().size())
  58190. {
  58191. if (inputChanList == 0)
  58192. {
  58193. addAndMakeVisible (inputChanList
  58194. = new ChannelSelectorListBox (setup, ChannelSelectorListBox::audioInputType,
  58195. TRANS ("(no audio input channels found)")));
  58196. inputChanLabel = new Label (String::empty, TRANS ("active input channels:"));
  58197. inputChanLabel->attachToComponent (inputChanList, true);
  58198. }
  58199. inputChanList->refresh();
  58200. }
  58201. else
  58202. {
  58203. deleteAndZero (inputChanLabel);
  58204. deleteAndZero (inputChanList);
  58205. }
  58206. // sample rate..
  58207. {
  58208. if (sampleRateDropDown == 0)
  58209. {
  58210. addAndMakeVisible (sampleRateDropDown = new ComboBox (String::empty));
  58211. sampleRateDropDown->addListener (this);
  58212. delete sampleRateLabel;
  58213. sampleRateLabel = new Label (String::empty, TRANS ("sample rate:"));
  58214. sampleRateLabel->attachToComponent (sampleRateDropDown, true);
  58215. }
  58216. else
  58217. {
  58218. sampleRateDropDown->clear();
  58219. sampleRateDropDown->removeListener (this);
  58220. }
  58221. const int numRates = currentDevice->getNumSampleRates();
  58222. for (int i = 0; i < numRates; ++i)
  58223. {
  58224. const int rate = roundToInt (currentDevice->getSampleRate (i));
  58225. sampleRateDropDown->addItem (String (rate) + T(" Hz"), rate);
  58226. }
  58227. sampleRateDropDown->setSelectedId (roundToInt (currentDevice->getCurrentSampleRate()), true);
  58228. sampleRateDropDown->addListener (this);
  58229. }
  58230. // buffer size
  58231. {
  58232. if (bufferSizeDropDown == 0)
  58233. {
  58234. addAndMakeVisible (bufferSizeDropDown = new ComboBox (String::empty));
  58235. bufferSizeDropDown->addListener (this);
  58236. delete bufferSizeLabel;
  58237. bufferSizeLabel = new Label (String::empty, TRANS ("audio buffer size:"));
  58238. bufferSizeLabel->attachToComponent (bufferSizeDropDown, true);
  58239. }
  58240. else
  58241. {
  58242. bufferSizeDropDown->clear();
  58243. }
  58244. const int numBufferSizes = currentDevice->getNumBufferSizesAvailable();
  58245. double currentRate = currentDevice->getCurrentSampleRate();
  58246. if (currentRate == 0)
  58247. currentRate = 48000.0;
  58248. for (int i = 0; i < numBufferSizes; ++i)
  58249. {
  58250. const int bs = currentDevice->getBufferSizeSamples (i);
  58251. bufferSizeDropDown->addItem (String (bs)
  58252. + T(" samples (")
  58253. + String (bs * 1000.0 / currentRate, 1)
  58254. + T(" ms)"),
  58255. bs);
  58256. }
  58257. bufferSizeDropDown->setSelectedId (currentDevice->getCurrentBufferSizeSamples(), true);
  58258. }
  58259. }
  58260. else
  58261. {
  58262. jassert (setup.manager->getCurrentAudioDevice() == 0); // not the correct device type!
  58263. deleteAndZero (sampleRateLabel);
  58264. deleteAndZero (bufferSizeLabel);
  58265. deleteAndZero (sampleRateDropDown);
  58266. deleteAndZero (bufferSizeDropDown);
  58267. if (outputDeviceDropDown != 0)
  58268. outputDeviceDropDown->setSelectedId (-1, true);
  58269. if (inputDeviceDropDown != 0)
  58270. inputDeviceDropDown->setSelectedId (-1, true);
  58271. }
  58272. resized();
  58273. setSize (getWidth(), getLowestY() + 4);
  58274. }
  58275. private:
  58276. AudioIODeviceType* const type;
  58277. const AudioIODeviceType::DeviceSetupDetails setup;
  58278. ComboBox* outputDeviceDropDown;
  58279. ComboBox* inputDeviceDropDown;
  58280. ComboBox* sampleRateDropDown;
  58281. ComboBox* bufferSizeDropDown;
  58282. Label* outputDeviceLabel;
  58283. Label* inputDeviceLabel;
  58284. Label* sampleRateLabel;
  58285. Label* bufferSizeLabel;
  58286. Label* inputChanLabel;
  58287. Label* outputChanLabel;
  58288. TextButton* testButton;
  58289. Component* inputLevelMeter;
  58290. TextButton* showUIButton;
  58291. TextButton* showAdvancedSettingsButton;
  58292. void showCorrectDeviceName (ComboBox* const box, const bool isInput)
  58293. {
  58294. if (box != 0)
  58295. {
  58296. AudioIODevice* const currentDevice = dynamic_cast <AudioIODevice*> (setup.manager->getCurrentAudioDevice());
  58297. const int index = type->getIndexOfDevice (currentDevice, isInput);
  58298. box->setSelectedId (index + 1, true);
  58299. if (testButton != 0 && ! isInput)
  58300. testButton->setEnabled (index >= 0);
  58301. }
  58302. }
  58303. void addNamesToDeviceBox (ComboBox& combo, bool isInputs)
  58304. {
  58305. const StringArray devs (type->getDeviceNames (isInputs));
  58306. combo.clear (true);
  58307. for (int i = 0; i < devs.size(); ++i)
  58308. combo.addItem (devs[i], i + 1);
  58309. combo.addItem (TRANS("<< none >>"), -1);
  58310. combo.setSelectedId (-1, true);
  58311. }
  58312. int getLowestY() const
  58313. {
  58314. int y = 0;
  58315. for (int i = getNumChildComponents(); --i >= 0;)
  58316. y = jmax (y, getChildComponent (i)->getBottom());
  58317. return y;
  58318. }
  58319. public:
  58320. class ChannelSelectorListBox : public ListBox,
  58321. public ListBoxModel
  58322. {
  58323. public:
  58324. enum BoxType
  58325. {
  58326. audioInputType,
  58327. audioOutputType
  58328. };
  58329. ChannelSelectorListBox (const AudioIODeviceType::DeviceSetupDetails& setup_,
  58330. const BoxType type_,
  58331. const String& noItemsMessage_)
  58332. : ListBox (String::empty, 0),
  58333. setup (setup_),
  58334. type (type_),
  58335. noItemsMessage (noItemsMessage_)
  58336. {
  58337. refresh();
  58338. setModel (this);
  58339. setOutlineThickness (1);
  58340. }
  58341. ~ChannelSelectorListBox()
  58342. {
  58343. }
  58344. void refresh()
  58345. {
  58346. items.clear();
  58347. AudioIODevice* const currentDevice = setup.manager->getCurrentAudioDevice();
  58348. if (currentDevice != 0)
  58349. {
  58350. if (type == audioInputType)
  58351. items = currentDevice->getInputChannelNames();
  58352. else if (type == audioOutputType)
  58353. items = currentDevice->getOutputChannelNames();
  58354. if (setup.useStereoPairs)
  58355. {
  58356. StringArray pairs;
  58357. for (int i = 0; i < items.size(); i += 2)
  58358. {
  58359. String name (items[i]);
  58360. String name2 (items[i + 1]);
  58361. String commonBit;
  58362. for (int j = 0; j < name.length(); ++j)
  58363. if (name.substring (0, j).equalsIgnoreCase (name2.substring (0, j)))
  58364. commonBit = name.substring (0, j);
  58365. pairs.add (name.trim()
  58366. + " + "
  58367. + name2.substring (commonBit.length()).trim());
  58368. }
  58369. items = pairs;
  58370. }
  58371. }
  58372. updateContent();
  58373. repaint();
  58374. }
  58375. int getNumRows()
  58376. {
  58377. return items.size();
  58378. }
  58379. void paintListBoxItem (int row,
  58380. Graphics& g,
  58381. int width, int height,
  58382. bool rowIsSelected)
  58383. {
  58384. if (((unsigned int) row) < (unsigned int) items.size())
  58385. {
  58386. if (rowIsSelected)
  58387. g.fillAll (findColour (TextEditor::highlightColourId)
  58388. .withMultipliedAlpha (0.3f));
  58389. const String item (items [row]);
  58390. bool enabled = false;
  58391. AudioDeviceManager::AudioDeviceSetup config;
  58392. setup.manager->getAudioDeviceSetup (config);
  58393. if (setup.useStereoPairs)
  58394. {
  58395. if (type == audioInputType)
  58396. enabled = config.inputChannels [row * 2] || config.inputChannels [row * 2 + 1];
  58397. else if (type == audioOutputType)
  58398. enabled = config.outputChannels [row * 2] || config.outputChannels [row * 2 + 1];
  58399. }
  58400. else
  58401. {
  58402. if (type == audioInputType)
  58403. enabled = config.inputChannels [row];
  58404. else if (type == audioOutputType)
  58405. enabled = config.outputChannels [row];
  58406. }
  58407. const int x = getTickX();
  58408. const int tickW = height - height / 4;
  58409. getLookAndFeel().drawTickBox (g, *this, x - tickW, (height - tickW) / 2, tickW, tickW,
  58410. enabled, true, true, false);
  58411. g.setFont (height * 0.6f);
  58412. g.setColour (findColour (ListBox::textColourId, true).withMultipliedAlpha (enabled ? 1.0f : 0.6f));
  58413. g.drawText (item, x, 0, width - x - 2, height, Justification::centredLeft, true);
  58414. }
  58415. }
  58416. void listBoxItemClicked (int row, const MouseEvent& e)
  58417. {
  58418. selectRow (row);
  58419. if (e.x < getTickX())
  58420. flipEnablement (row);
  58421. }
  58422. void listBoxItemDoubleClicked (int row, const MouseEvent&)
  58423. {
  58424. flipEnablement (row);
  58425. }
  58426. void returnKeyPressed (int row)
  58427. {
  58428. flipEnablement (row);
  58429. }
  58430. void paint (Graphics& g)
  58431. {
  58432. ListBox::paint (g);
  58433. if (items.size() == 0)
  58434. {
  58435. g.setColour (Colours::grey);
  58436. g.setFont (13.0f);
  58437. g.drawText (noItemsMessage,
  58438. 0, 0, getWidth(), getHeight() / 2,
  58439. Justification::centred, true);
  58440. }
  58441. }
  58442. int getBestHeight (int maxHeight)
  58443. {
  58444. return getRowHeight() * jlimit (2, jmax (2, maxHeight / getRowHeight()),
  58445. getNumRows())
  58446. + getOutlineThickness() * 2;
  58447. }
  58448. juce_UseDebuggingNewOperator
  58449. private:
  58450. const AudioIODeviceType::DeviceSetupDetails setup;
  58451. const BoxType type;
  58452. const String noItemsMessage;
  58453. StringArray items;
  58454. void flipEnablement (const int row)
  58455. {
  58456. jassert (type == audioInputType || type == audioOutputType);
  58457. if (((unsigned int) row) < (unsigned int) items.size())
  58458. {
  58459. AudioDeviceManager::AudioDeviceSetup config;
  58460. setup.manager->getAudioDeviceSetup (config);
  58461. if (setup.useStereoPairs)
  58462. {
  58463. BitArray bits;
  58464. BitArray& original = (type == audioInputType ? config.inputChannels
  58465. : config.outputChannels);
  58466. int i;
  58467. for (i = 0; i < 256; i += 2)
  58468. bits.setBit (i / 2, original [i] || original [i + 1]);
  58469. if (type == audioInputType)
  58470. {
  58471. config.useDefaultInputChannels = false;
  58472. flipBit (bits, row, setup.minNumInputChannels / 2, setup.maxNumInputChannels / 2);
  58473. }
  58474. else
  58475. {
  58476. config.useDefaultOutputChannels = false;
  58477. flipBit (bits, row, setup.minNumOutputChannels / 2, setup.maxNumOutputChannels / 2);
  58478. }
  58479. for (i = 0; i < 256; ++i)
  58480. original.setBit (i, bits [i / 2]);
  58481. }
  58482. else
  58483. {
  58484. if (type == audioInputType)
  58485. {
  58486. config.useDefaultInputChannels = false;
  58487. flipBit (config.inputChannels, row, setup.minNumInputChannels, setup.maxNumInputChannels);
  58488. }
  58489. else
  58490. {
  58491. config.useDefaultOutputChannels = false;
  58492. flipBit (config.outputChannels, row, setup.minNumOutputChannels, setup.maxNumOutputChannels);
  58493. }
  58494. }
  58495. String error (setup.manager->setAudioDeviceSetup (config, true));
  58496. if (! error.isEmpty())
  58497. {
  58498. //xxx
  58499. }
  58500. }
  58501. }
  58502. static void flipBit (BitArray& chans, int index, int minNumber, int maxNumber)
  58503. {
  58504. const int numActive = chans.countNumberOfSetBits();
  58505. if (chans [index])
  58506. {
  58507. if (numActive > minNumber)
  58508. chans.setBit (index, false);
  58509. }
  58510. else
  58511. {
  58512. if (numActive >= maxNumber)
  58513. {
  58514. const int firstActiveChan = chans.findNextSetBit();
  58515. chans.setBit (index > firstActiveChan
  58516. ? firstActiveChan : chans.getHighestBit(),
  58517. false);
  58518. }
  58519. chans.setBit (index, true);
  58520. }
  58521. }
  58522. int getTickX() const
  58523. {
  58524. return getRowHeight() + 5;
  58525. }
  58526. ChannelSelectorListBox (const ChannelSelectorListBox&);
  58527. const ChannelSelectorListBox& operator= (const ChannelSelectorListBox&);
  58528. };
  58529. private:
  58530. ChannelSelectorListBox* inputChanList;
  58531. ChannelSelectorListBox* outputChanList;
  58532. AudioDeviceSettingsPanel (const AudioDeviceSettingsPanel&);
  58533. const AudioDeviceSettingsPanel& operator= (const AudioDeviceSettingsPanel&);
  58534. };
  58535. AudioDeviceSelectorComponent::AudioDeviceSelectorComponent (AudioDeviceManager& deviceManager_,
  58536. const int minInputChannels_,
  58537. const int maxInputChannels_,
  58538. const int minOutputChannels_,
  58539. const int maxOutputChannels_,
  58540. const bool showMidiInputOptions,
  58541. const bool showMidiOutputSelector,
  58542. const bool showChannelsAsStereoPairs_,
  58543. const bool hideAdvancedOptionsWithButton_)
  58544. : deviceManager (deviceManager_),
  58545. deviceTypeDropDown (0),
  58546. deviceTypeDropDownLabel (0),
  58547. audioDeviceSettingsComp (0),
  58548. minOutputChannels (minOutputChannels_),
  58549. maxOutputChannels (maxOutputChannels_),
  58550. minInputChannels (minInputChannels_),
  58551. maxInputChannels (maxInputChannels_),
  58552. showChannelsAsStereoPairs (showChannelsAsStereoPairs_),
  58553. hideAdvancedOptionsWithButton (hideAdvancedOptionsWithButton_)
  58554. {
  58555. jassert (minOutputChannels >= 0 && minOutputChannels <= maxOutputChannels);
  58556. jassert (minInputChannels >= 0 && minInputChannels <= maxInputChannels);
  58557. if (deviceManager_.getAvailableDeviceTypes().size() > 1)
  58558. {
  58559. deviceTypeDropDown = new ComboBox (String::empty);
  58560. for (int i = 0; i < deviceManager_.getAvailableDeviceTypes().size(); ++i)
  58561. {
  58562. deviceTypeDropDown
  58563. ->addItem (deviceManager_.getAvailableDeviceTypes().getUnchecked(i)->getTypeName(),
  58564. i + 1);
  58565. }
  58566. addAndMakeVisible (deviceTypeDropDown);
  58567. deviceTypeDropDown->addListener (this);
  58568. deviceTypeDropDownLabel = new Label (String::empty, TRANS ("audio device type:"));
  58569. deviceTypeDropDownLabel->setJustificationType (Justification::centredRight);
  58570. deviceTypeDropDownLabel->attachToComponent (deviceTypeDropDown, true);
  58571. }
  58572. if (showMidiInputOptions)
  58573. {
  58574. addAndMakeVisible (midiInputsList
  58575. = new MidiInputSelectorComponentListBox (deviceManager,
  58576. TRANS("(no midi inputs available)"),
  58577. 0, 0));
  58578. midiInputsLabel = new Label (String::empty, TRANS ("active midi inputs:"));
  58579. midiInputsLabel->setJustificationType (Justification::topRight);
  58580. midiInputsLabel->attachToComponent (midiInputsList, true);
  58581. }
  58582. else
  58583. {
  58584. midiInputsList = 0;
  58585. midiInputsLabel = 0;
  58586. }
  58587. if (showMidiOutputSelector)
  58588. {
  58589. addAndMakeVisible (midiOutputSelector = new ComboBox (String::empty));
  58590. midiOutputSelector->addListener (this);
  58591. midiOutputLabel = new Label ("lm", TRANS("Midi Output:"));
  58592. midiOutputLabel->attachToComponent (midiOutputSelector, true);
  58593. }
  58594. else
  58595. {
  58596. midiOutputSelector = 0;
  58597. midiOutputLabel = 0;
  58598. }
  58599. deviceManager_.addChangeListener (this);
  58600. changeListenerCallback (0);
  58601. }
  58602. AudioDeviceSelectorComponent::~AudioDeviceSelectorComponent()
  58603. {
  58604. deviceManager.removeChangeListener (this);
  58605. deleteAllChildren();
  58606. }
  58607. void AudioDeviceSelectorComponent::resized()
  58608. {
  58609. const int lx = proportionOfWidth (0.35f);
  58610. const int w = proportionOfWidth (0.4f);
  58611. const int h = 24;
  58612. const int space = 6;
  58613. const int dh = h + space;
  58614. int y = 15;
  58615. if (deviceTypeDropDown != 0)
  58616. {
  58617. deviceTypeDropDown->setBounds (lx, y, proportionOfWidth (0.3f), h);
  58618. y += dh + space * 2;
  58619. }
  58620. if (audioDeviceSettingsComp != 0)
  58621. {
  58622. audioDeviceSettingsComp->setBounds (0, y, getWidth(), audioDeviceSettingsComp->getHeight());
  58623. y += audioDeviceSettingsComp->getHeight() + space;
  58624. }
  58625. if (midiInputsList != 0)
  58626. {
  58627. const int bh = midiInputsList->getBestHeight (jmin (h * 8, getHeight() - y - space - h));
  58628. midiInputsList->setBounds (lx, y, w, bh);
  58629. y += bh + space;
  58630. }
  58631. if (midiOutputSelector != 0)
  58632. midiOutputSelector->setBounds (lx, y, w, h);
  58633. }
  58634. void AudioDeviceSelectorComponent::childBoundsChanged (Component* child)
  58635. {
  58636. if (child == audioDeviceSettingsComp)
  58637. resized();
  58638. }
  58639. void AudioDeviceSelectorComponent::buttonClicked (Button*)
  58640. {
  58641. AudioIODevice* const device = deviceManager.getCurrentAudioDevice();
  58642. if (device != 0 && device->hasControlPanel())
  58643. {
  58644. if (device->showControlPanel())
  58645. deviceManager.restartLastAudioDevice();
  58646. getTopLevelComponent()->toFront (true);
  58647. }
  58648. }
  58649. void AudioDeviceSelectorComponent::comboBoxChanged (ComboBox* comboBoxThatHasChanged)
  58650. {
  58651. if (comboBoxThatHasChanged == deviceTypeDropDown)
  58652. {
  58653. AudioIODeviceType* const type = deviceManager.getAvailableDeviceTypes() [deviceTypeDropDown->getSelectedId() - 1];
  58654. if (type != 0)
  58655. {
  58656. deleteAndZero (audioDeviceSettingsComp);
  58657. deviceManager.setCurrentAudioDeviceType (type->getTypeName(), true);
  58658. changeListenerCallback (0); // needed in case the type hasn't actally changed
  58659. }
  58660. }
  58661. else if (comboBoxThatHasChanged == midiOutputSelector)
  58662. {
  58663. deviceManager.setDefaultMidiOutput (midiOutputSelector->getText());
  58664. }
  58665. }
  58666. void AudioDeviceSelectorComponent::changeListenerCallback (void*)
  58667. {
  58668. if (deviceTypeDropDown != 0)
  58669. {
  58670. deviceTypeDropDown->setText (deviceManager.getCurrentAudioDeviceType(), false);
  58671. }
  58672. if (audioDeviceSettingsComp == 0
  58673. || audioDeviceSettingsCompType != deviceManager.getCurrentAudioDeviceType())
  58674. {
  58675. audioDeviceSettingsCompType = deviceManager.getCurrentAudioDeviceType();
  58676. deleteAndZero (audioDeviceSettingsComp);
  58677. AudioIODeviceType* const type
  58678. = deviceManager.getAvailableDeviceTypes() [deviceTypeDropDown == 0
  58679. ? 0 : deviceTypeDropDown->getSelectedId() - 1];
  58680. if (type != 0)
  58681. {
  58682. AudioIODeviceType::DeviceSetupDetails details;
  58683. details.manager = &deviceManager;
  58684. details.minNumInputChannels = minInputChannels;
  58685. details.maxNumInputChannels = maxInputChannels;
  58686. details.minNumOutputChannels = minOutputChannels;
  58687. details.maxNumOutputChannels = maxOutputChannels;
  58688. details.useStereoPairs = showChannelsAsStereoPairs;
  58689. audioDeviceSettingsComp = new AudioDeviceSettingsPanel (type, details, hideAdvancedOptionsWithButton);
  58690. if (audioDeviceSettingsComp != 0)
  58691. {
  58692. addAndMakeVisible (audioDeviceSettingsComp);
  58693. audioDeviceSettingsComp->resized();
  58694. }
  58695. }
  58696. }
  58697. if (midiInputsList != 0)
  58698. {
  58699. midiInputsList->updateContent();
  58700. midiInputsList->repaint();
  58701. }
  58702. if (midiOutputSelector != 0)
  58703. {
  58704. midiOutputSelector->clear();
  58705. const StringArray midiOuts (MidiOutput::getDevices());
  58706. midiOutputSelector->addItem (TRANS("<< none >>"), -1);
  58707. midiOutputSelector->addSeparator();
  58708. for (int i = 0; i < midiOuts.size(); ++i)
  58709. midiOutputSelector->addItem (midiOuts[i], i + 1);
  58710. int current = -1;
  58711. if (deviceManager.getDefaultMidiOutput() != 0)
  58712. current = 1 + midiOuts.indexOf (deviceManager.getDefaultMidiOutputName());
  58713. midiOutputSelector->setSelectedId (current, true);
  58714. }
  58715. resized();
  58716. }
  58717. END_JUCE_NAMESPACE
  58718. /********* End of inlined file: juce_AudioDeviceSelectorComponent.cpp *********/
  58719. /********* Start of inlined file: juce_BubbleComponent.cpp *********/
  58720. BEGIN_JUCE_NAMESPACE
  58721. BubbleComponent::BubbleComponent()
  58722. : side (0),
  58723. allowablePlacements (above | below | left | right),
  58724. arrowTipX (0.0f),
  58725. arrowTipY (0.0f)
  58726. {
  58727. setInterceptsMouseClicks (false, false);
  58728. shadow.setShadowProperties (5.0f, 0.35f, 0, 0);
  58729. setComponentEffect (&shadow);
  58730. }
  58731. BubbleComponent::~BubbleComponent()
  58732. {
  58733. }
  58734. void BubbleComponent::paint (Graphics& g)
  58735. {
  58736. int x = content.getX();
  58737. int y = content.getY();
  58738. int w = content.getWidth();
  58739. int h = content.getHeight();
  58740. int cw, ch;
  58741. getContentSize (cw, ch);
  58742. if (side == 3)
  58743. x += w - cw;
  58744. else if (side != 1)
  58745. x += (w - cw) / 2;
  58746. w = cw;
  58747. if (side == 2)
  58748. y += h - ch;
  58749. else if (side != 0)
  58750. y += (h - ch) / 2;
  58751. h = ch;
  58752. getLookAndFeel().drawBubble (g, arrowTipX, arrowTipY,
  58753. (float) x, (float) y,
  58754. (float) w, (float) h);
  58755. const int cx = x + (w - cw) / 2;
  58756. const int cy = y + (h - ch) / 2;
  58757. const int indent = 3;
  58758. g.setOrigin (cx + indent, cy + indent);
  58759. g.reduceClipRegion (0, 0, cw - indent * 2, ch - indent * 2);
  58760. paintContent (g, cw - indent * 2, ch - indent * 2);
  58761. }
  58762. void BubbleComponent::setAllowedPlacement (const int newPlacement)
  58763. {
  58764. allowablePlacements = newPlacement;
  58765. }
  58766. void BubbleComponent::setPosition (Component* componentToPointTo)
  58767. {
  58768. jassert (componentToPointTo->isValidComponent());
  58769. int tx = 0;
  58770. int ty = 0;
  58771. if (getParentComponent() != 0)
  58772. componentToPointTo->relativePositionToOtherComponent (getParentComponent(), tx, ty);
  58773. else
  58774. componentToPointTo->relativePositionToGlobal (tx, ty);
  58775. setPosition (Rectangle (tx, ty, componentToPointTo->getWidth(), componentToPointTo->getHeight()));
  58776. }
  58777. void BubbleComponent::setPosition (const int arrowTipX_,
  58778. const int arrowTipY_)
  58779. {
  58780. setPosition (Rectangle (arrowTipX_, arrowTipY_, 1, 1));
  58781. }
  58782. void BubbleComponent::setPosition (const Rectangle& rectangleToPointTo)
  58783. {
  58784. Rectangle availableSpace;
  58785. if (getParentComponent() != 0)
  58786. {
  58787. availableSpace.setSize (getParentComponent()->getWidth(),
  58788. getParentComponent()->getHeight());
  58789. }
  58790. else
  58791. {
  58792. availableSpace = getParentMonitorArea();
  58793. }
  58794. int x = 0;
  58795. int y = 0;
  58796. int w = 150;
  58797. int h = 30;
  58798. getContentSize (w, h);
  58799. w += 30;
  58800. h += 30;
  58801. const float edgeIndent = 2.0f;
  58802. const int arrowLength = jmin (10, h / 3, w / 3);
  58803. int spaceAbove = ((allowablePlacements & above) != 0) ? jmax (0, rectangleToPointTo.getY() - availableSpace.getY()) : -1;
  58804. int spaceBelow = ((allowablePlacements & below) != 0) ? jmax (0, availableSpace.getBottom() - rectangleToPointTo.getBottom()) : -1;
  58805. int spaceLeft = ((allowablePlacements & left) != 0) ? jmax (0, rectangleToPointTo.getX() - availableSpace.getX()) : -1;
  58806. int spaceRight = ((allowablePlacements & right) != 0) ? jmax (0, availableSpace.getRight() - rectangleToPointTo.getRight()) : -1;
  58807. // look at whether the component is elongated, and if so, try to position next to its longer dimension.
  58808. if (rectangleToPointTo.getWidth() > rectangleToPointTo.getHeight() * 2
  58809. && (spaceAbove > h + 20 || spaceBelow > h + 20))
  58810. {
  58811. spaceLeft = spaceRight = 0;
  58812. }
  58813. else if (rectangleToPointTo.getWidth() < rectangleToPointTo.getHeight() / 2
  58814. && (spaceLeft > w + 20 || spaceRight > w + 20))
  58815. {
  58816. spaceAbove = spaceBelow = 0;
  58817. }
  58818. if (jmax (spaceAbove, spaceBelow) >= jmax (spaceLeft, spaceRight))
  58819. {
  58820. x = rectangleToPointTo.getX() + (rectangleToPointTo.getWidth() - w) / 2;
  58821. arrowTipX = w * 0.5f;
  58822. content.setSize (w, h - arrowLength);
  58823. if (spaceAbove >= spaceBelow)
  58824. {
  58825. // above
  58826. y = rectangleToPointTo.getY() - h;
  58827. content.setPosition (0, 0);
  58828. arrowTipY = h - edgeIndent;
  58829. side = 2;
  58830. }
  58831. else
  58832. {
  58833. // below
  58834. y = rectangleToPointTo.getBottom();
  58835. content.setPosition (0, arrowLength);
  58836. arrowTipY = edgeIndent;
  58837. side = 0;
  58838. }
  58839. }
  58840. else
  58841. {
  58842. y = rectangleToPointTo.getY() + (rectangleToPointTo.getHeight() - h) / 2;
  58843. arrowTipY = h * 0.5f;
  58844. content.setSize (w - arrowLength, h);
  58845. if (spaceLeft > spaceRight)
  58846. {
  58847. // on the left
  58848. x = rectangleToPointTo.getX() - w;
  58849. content.setPosition (0, 0);
  58850. arrowTipX = w - edgeIndent;
  58851. side = 3;
  58852. }
  58853. else
  58854. {
  58855. // on the right
  58856. x = rectangleToPointTo.getRight();
  58857. content.setPosition (arrowLength, 0);
  58858. arrowTipX = edgeIndent;
  58859. side = 1;
  58860. }
  58861. }
  58862. setBounds (x, y, w, h);
  58863. }
  58864. END_JUCE_NAMESPACE
  58865. /********* End of inlined file: juce_BubbleComponent.cpp *********/
  58866. /********* Start of inlined file: juce_BubbleMessageComponent.cpp *********/
  58867. BEGIN_JUCE_NAMESPACE
  58868. BubbleMessageComponent::BubbleMessageComponent (int fadeOutLengthMs)
  58869. : fadeOutLength (fadeOutLengthMs),
  58870. deleteAfterUse (false)
  58871. {
  58872. }
  58873. BubbleMessageComponent::~BubbleMessageComponent()
  58874. {
  58875. fadeOutComponent (fadeOutLength);
  58876. }
  58877. void BubbleMessageComponent::showAt (int x, int y,
  58878. const String& text,
  58879. const int numMillisecondsBeforeRemoving,
  58880. const bool removeWhenMouseClicked,
  58881. const bool deleteSelfAfterUse)
  58882. {
  58883. textLayout.clear();
  58884. textLayout.setText (text, Font (14.0f));
  58885. textLayout.layout (256, Justification::centredLeft, true);
  58886. setPosition (x, y);
  58887. init (numMillisecondsBeforeRemoving, removeWhenMouseClicked, deleteSelfAfterUse);
  58888. }
  58889. void BubbleMessageComponent::showAt (Component* const component,
  58890. const String& text,
  58891. const int numMillisecondsBeforeRemoving,
  58892. const bool removeWhenMouseClicked,
  58893. const bool deleteSelfAfterUse)
  58894. {
  58895. textLayout.clear();
  58896. textLayout.setText (text, Font (14.0f));
  58897. textLayout.layout (256, Justification::centredLeft, true);
  58898. setPosition (component);
  58899. init (numMillisecondsBeforeRemoving, removeWhenMouseClicked, deleteSelfAfterUse);
  58900. }
  58901. void BubbleMessageComponent::init (const int numMillisecondsBeforeRemoving,
  58902. const bool removeWhenMouseClicked,
  58903. const bool deleteSelfAfterUse)
  58904. {
  58905. setVisible (true);
  58906. deleteAfterUse = deleteSelfAfterUse;
  58907. if (numMillisecondsBeforeRemoving > 0)
  58908. expiryTime = Time::getMillisecondCounter() + numMillisecondsBeforeRemoving;
  58909. else
  58910. expiryTime = 0;
  58911. startTimer (77);
  58912. mouseClickCounter = Desktop::getInstance().getMouseButtonClickCounter();
  58913. if (! (removeWhenMouseClicked && isShowing()))
  58914. mouseClickCounter += 0xfffff;
  58915. repaint();
  58916. }
  58917. void BubbleMessageComponent::getContentSize (int& w, int& h)
  58918. {
  58919. w = textLayout.getWidth() + 16;
  58920. h = textLayout.getHeight() + 16;
  58921. }
  58922. void BubbleMessageComponent::paintContent (Graphics& g, int w, int h)
  58923. {
  58924. g.setColour (findColour (TooltipWindow::textColourId));
  58925. textLayout.drawWithin (g, 0, 0, w, h, Justification::centred);
  58926. }
  58927. void BubbleMessageComponent::timerCallback()
  58928. {
  58929. if (Desktop::getInstance().getMouseButtonClickCounter() > mouseClickCounter)
  58930. {
  58931. stopTimer();
  58932. setVisible (false);
  58933. if (deleteAfterUse)
  58934. delete this;
  58935. }
  58936. else if (expiryTime != 0 && Time::getMillisecondCounter() > expiryTime)
  58937. {
  58938. stopTimer();
  58939. fadeOutComponent (fadeOutLength);
  58940. if (deleteAfterUse)
  58941. delete this;
  58942. }
  58943. }
  58944. END_JUCE_NAMESPACE
  58945. /********* End of inlined file: juce_BubbleMessageComponent.cpp *********/
  58946. /********* Start of inlined file: juce_ColourSelector.cpp *********/
  58947. BEGIN_JUCE_NAMESPACE
  58948. static const int swatchesPerRow = 8;
  58949. static const int swatchHeight = 22;
  58950. class ColourComponentSlider : public Slider
  58951. {
  58952. public:
  58953. ColourComponentSlider (const String& name)
  58954. : Slider (name)
  58955. {
  58956. setRange (0.0, 255.0, 1.0);
  58957. }
  58958. ~ColourComponentSlider()
  58959. {
  58960. }
  58961. const String getTextFromValue (double value)
  58962. {
  58963. return String::formatted (T("%02X"), (int) value);
  58964. }
  58965. double getValueFromText (const String& text)
  58966. {
  58967. return (double) text.getHexValue32();
  58968. }
  58969. private:
  58970. ColourComponentSlider (const ColourComponentSlider&);
  58971. const ColourComponentSlider& operator= (const ColourComponentSlider&);
  58972. };
  58973. class ColourSpaceMarker : public Component
  58974. {
  58975. public:
  58976. ColourSpaceMarker()
  58977. {
  58978. setInterceptsMouseClicks (false, false);
  58979. }
  58980. ~ColourSpaceMarker()
  58981. {
  58982. }
  58983. void paint (Graphics& g)
  58984. {
  58985. g.setColour (Colour::greyLevel (0.1f));
  58986. g.drawEllipse (1.0f, 1.0f, getWidth() - 2.0f, getHeight() - 2.0f, 1.0f);
  58987. g.setColour (Colour::greyLevel (0.9f));
  58988. g.drawEllipse (2.0f, 2.0f, getWidth() - 4.0f, getHeight() - 4.0f, 1.0f);
  58989. }
  58990. private:
  58991. ColourSpaceMarker (const ColourSpaceMarker&);
  58992. const ColourSpaceMarker& operator= (const ColourSpaceMarker&);
  58993. };
  58994. class ColourSpaceView : public Component
  58995. {
  58996. ColourSelector* const owner;
  58997. float& h;
  58998. float& s;
  58999. float& v;
  59000. float lastHue;
  59001. ColourSpaceMarker* marker;
  59002. const int edge;
  59003. public:
  59004. ColourSpaceView (ColourSelector* owner_,
  59005. float& h_, float& s_, float& v_,
  59006. const int edgeSize)
  59007. : owner (owner_),
  59008. h (h_), s (s_), v (v_),
  59009. lastHue (0.0f),
  59010. edge (edgeSize)
  59011. {
  59012. addAndMakeVisible (marker = new ColourSpaceMarker());
  59013. setMouseCursor (MouseCursor::CrosshairCursor);
  59014. }
  59015. ~ColourSpaceView()
  59016. {
  59017. deleteAllChildren();
  59018. }
  59019. void paint (Graphics& g)
  59020. {
  59021. if (colours == 0)
  59022. {
  59023. const int width = getWidth() / 2;
  59024. const int height = getHeight() / 2;
  59025. colours = new Image (Image::RGB, width, height, false);
  59026. Image::BitmapData pixels (*colours, 0, 0, width, height, true);
  59027. for (int y = 0; y < height; ++y)
  59028. {
  59029. const float v = 1.0f - y / (float) height;
  59030. for (int x = 0; x < width; ++x)
  59031. {
  59032. const float s = x / (float) width;
  59033. const Colour col (h, s, v, 1.0f);
  59034. PixelRGB* const pix = (PixelRGB*) pixels.getPixelPointer (x, y);
  59035. pix->set (col.getPixelARGB());
  59036. }
  59037. }
  59038. }
  59039. g.setOpacity (1.0f);
  59040. g.drawImage (colours, edge, edge, getWidth() - edge * 2, getHeight() - edge * 2,
  59041. 0, 0, colours->getWidth(), colours->getHeight());
  59042. }
  59043. void mouseDown (const MouseEvent& e)
  59044. {
  59045. mouseDrag (e);
  59046. }
  59047. void mouseDrag (const MouseEvent& e)
  59048. {
  59049. const float s = (e.x - edge) / (float) (getWidth() - edge * 2);
  59050. const float v = 1.0f - (e.y - edge) / (float) (getHeight() - edge * 2);
  59051. owner->setSV (s, v);
  59052. }
  59053. void updateIfNeeded()
  59054. {
  59055. if (lastHue != h)
  59056. {
  59057. lastHue = h;
  59058. colours = 0;
  59059. repaint();
  59060. }
  59061. updateMarker();
  59062. }
  59063. void resized()
  59064. {
  59065. colours = 0;
  59066. updateMarker();
  59067. }
  59068. private:
  59069. ScopedPointer <Image> colours;
  59070. void updateMarker() const throw()
  59071. {
  59072. marker->setBounds (roundToInt ((getWidth() - edge * 2) * s),
  59073. roundToInt ((getHeight() - edge * 2) * (1.0f - v)),
  59074. edge * 2, edge * 2);
  59075. }
  59076. ColourSpaceView (const ColourSpaceView&);
  59077. const ColourSpaceView& operator= (const ColourSpaceView&);
  59078. };
  59079. class HueSelectorMarker : public Component
  59080. {
  59081. public:
  59082. HueSelectorMarker()
  59083. {
  59084. setInterceptsMouseClicks (false, false);
  59085. }
  59086. ~HueSelectorMarker()
  59087. {
  59088. }
  59089. void paint (Graphics& g)
  59090. {
  59091. Path p;
  59092. p.addTriangle (1.0f, 1.0f,
  59093. getWidth() * 0.3f, getHeight() * 0.5f,
  59094. 1.0f, getHeight() - 1.0f);
  59095. p.addTriangle (getWidth() - 1.0f, 1.0f,
  59096. getWidth() * 0.7f, getHeight() * 0.5f,
  59097. getWidth() - 1.0f, getHeight() - 1.0f);
  59098. g.setColour (Colours::white.withAlpha (0.75f));
  59099. g.fillPath (p);
  59100. g.setColour (Colours::black.withAlpha (0.75f));
  59101. g.strokePath (p, PathStrokeType (1.2f));
  59102. }
  59103. private:
  59104. HueSelectorMarker (const HueSelectorMarker&);
  59105. const HueSelectorMarker& operator= (const HueSelectorMarker&);
  59106. };
  59107. class HueSelectorComp : public Component
  59108. {
  59109. public:
  59110. HueSelectorComp (ColourSelector* owner_,
  59111. float& h_, float& s_, float& v_,
  59112. const int edgeSize)
  59113. : owner (owner_),
  59114. h (h_), s (s_), v (v_),
  59115. lastHue (0.0f),
  59116. edge (edgeSize)
  59117. {
  59118. addAndMakeVisible (marker = new HueSelectorMarker());
  59119. }
  59120. ~HueSelectorComp()
  59121. {
  59122. deleteAllChildren();
  59123. }
  59124. void paint (Graphics& g)
  59125. {
  59126. const float yScale = 1.0f / (getHeight() - edge * 2);
  59127. const Rectangle clip (g.getClipBounds());
  59128. for (int y = jmin (clip.getBottom(), getHeight() - edge); --y >= jmax (edge, clip.getY());)
  59129. {
  59130. g.setColour (Colour ((y - edge) * yScale, 1.0f, 1.0f, 1.0f));
  59131. g.fillRect (edge, y, getWidth() - edge * 2, 1);
  59132. }
  59133. }
  59134. void resized()
  59135. {
  59136. marker->setBounds (0, roundToInt ((getHeight() - edge * 2) * h),
  59137. getWidth(), edge * 2);
  59138. }
  59139. void mouseDown (const MouseEvent& e)
  59140. {
  59141. mouseDrag (e);
  59142. }
  59143. void mouseDrag (const MouseEvent& e)
  59144. {
  59145. const float hue = (e.y - edge) / (float) (getHeight() - edge * 2);
  59146. owner->setHue (hue);
  59147. }
  59148. void updateIfNeeded()
  59149. {
  59150. resized();
  59151. }
  59152. private:
  59153. ColourSelector* const owner;
  59154. float& h;
  59155. float& s;
  59156. float& v;
  59157. float lastHue;
  59158. HueSelectorMarker* marker;
  59159. const int edge;
  59160. HueSelectorComp (const HueSelectorComp&);
  59161. const HueSelectorComp& operator= (const HueSelectorComp&);
  59162. };
  59163. class ColourSelector::SwatchComponent : public Component
  59164. {
  59165. public:
  59166. SwatchComponent (ColourSelector* owner_, int index_)
  59167. : owner (owner_),
  59168. index (index_)
  59169. {
  59170. }
  59171. ~SwatchComponent()
  59172. {
  59173. }
  59174. void paint (Graphics& g)
  59175. {
  59176. const Colour colour (owner->getSwatchColour (index));
  59177. g.fillCheckerBoard (0, 0, getWidth(), getHeight(),
  59178. 6, 6,
  59179. Colour (0xffdddddd).overlaidWith (colour),
  59180. Colour (0xffffffff).overlaidWith (colour));
  59181. }
  59182. void mouseDown (const MouseEvent&)
  59183. {
  59184. PopupMenu m;
  59185. m.addItem (1, TRANS("Use this swatch as the current colour"));
  59186. m.addSeparator();
  59187. m.addItem (2, TRANS("Set this swatch to the current colour"));
  59188. const int r = m.showAt (this);
  59189. if (r == 1)
  59190. {
  59191. owner->setCurrentColour (owner->getSwatchColour (index));
  59192. }
  59193. else if (r == 2)
  59194. {
  59195. if (owner->getSwatchColour (index) != owner->getCurrentColour())
  59196. {
  59197. owner->setSwatchColour (index, owner->getCurrentColour());
  59198. repaint();
  59199. }
  59200. }
  59201. }
  59202. private:
  59203. ColourSelector* const owner;
  59204. const int index;
  59205. SwatchComponent (const SwatchComponent&);
  59206. const SwatchComponent& operator= (const SwatchComponent&);
  59207. };
  59208. ColourSelector::ColourSelector (const int flags_,
  59209. const int edgeGap_,
  59210. const int gapAroundColourSpaceComponent)
  59211. : colour (Colours::white),
  59212. flags (flags_),
  59213. topSpace (0),
  59214. edgeGap (edgeGap_)
  59215. {
  59216. // not much point having a selector with no components in it!
  59217. jassert ((flags_ & (showColourAtTop | showSliders | showColourspace)) != 0);
  59218. updateHSV();
  59219. if ((flags & showSliders) != 0)
  59220. {
  59221. addAndMakeVisible (sliders[0] = new ColourComponentSlider (TRANS ("red")));
  59222. addAndMakeVisible (sliders[1] = new ColourComponentSlider (TRANS ("green")));
  59223. addAndMakeVisible (sliders[2] = new ColourComponentSlider (TRANS ("blue")));
  59224. addChildComponent (sliders[3] = new ColourComponentSlider (TRANS ("alpha")));
  59225. sliders[3]->setVisible ((flags & showAlphaChannel) != 0);
  59226. for (int i = 4; --i >= 0;)
  59227. sliders[i]->addListener (this);
  59228. }
  59229. else
  59230. {
  59231. zeromem (sliders, sizeof (sliders));
  59232. }
  59233. if ((flags & showColourspace) != 0)
  59234. {
  59235. addAndMakeVisible (colourSpace = new ColourSpaceView (this, h, s, v, gapAroundColourSpaceComponent));
  59236. addAndMakeVisible (hueSelector = new HueSelectorComp (this, h, s, v, gapAroundColourSpaceComponent));
  59237. }
  59238. else
  59239. {
  59240. colourSpace = 0;
  59241. hueSelector = 0;
  59242. }
  59243. update();
  59244. }
  59245. ColourSelector::~ColourSelector()
  59246. {
  59247. dispatchPendingMessages();
  59248. swatchComponents.clear();
  59249. deleteAllChildren();
  59250. }
  59251. const Colour ColourSelector::getCurrentColour() const
  59252. {
  59253. return ((flags & showAlphaChannel) != 0) ? colour
  59254. : colour.withAlpha ((uint8) 0xff);
  59255. }
  59256. void ColourSelector::setCurrentColour (const Colour& c)
  59257. {
  59258. if (c != colour)
  59259. {
  59260. colour = ((flags & showAlphaChannel) != 0) ? c : c.withAlpha ((uint8) 0xff);
  59261. updateHSV();
  59262. update();
  59263. }
  59264. }
  59265. void ColourSelector::setHue (float newH)
  59266. {
  59267. newH = jlimit (0.0f, 1.0f, newH);
  59268. if (h != newH)
  59269. {
  59270. h = newH;
  59271. colour = Colour (h, s, v, colour.getFloatAlpha());
  59272. update();
  59273. }
  59274. }
  59275. void ColourSelector::setSV (float newS, float newV)
  59276. {
  59277. newS = jlimit (0.0f, 1.0f, newS);
  59278. newV = jlimit (0.0f, 1.0f, newV);
  59279. if (s != newS || v != newV)
  59280. {
  59281. s = newS;
  59282. v = newV;
  59283. colour = Colour (h, s, v, colour.getFloatAlpha());
  59284. update();
  59285. }
  59286. }
  59287. void ColourSelector::updateHSV()
  59288. {
  59289. colour.getHSB (h, s, v);
  59290. }
  59291. void ColourSelector::update()
  59292. {
  59293. if (sliders[0] != 0)
  59294. {
  59295. sliders[0]->setValue ((int) colour.getRed());
  59296. sliders[1]->setValue ((int) colour.getGreen());
  59297. sliders[2]->setValue ((int) colour.getBlue());
  59298. sliders[3]->setValue ((int) colour.getAlpha());
  59299. }
  59300. if (colourSpace != 0)
  59301. {
  59302. ((ColourSpaceView*) colourSpace)->updateIfNeeded();
  59303. ((HueSelectorComp*) hueSelector)->updateIfNeeded();
  59304. }
  59305. if ((flags & showColourAtTop) != 0)
  59306. repaint (0, edgeGap, getWidth(), topSpace - edgeGap);
  59307. sendChangeMessage (this);
  59308. }
  59309. void ColourSelector::paint (Graphics& g)
  59310. {
  59311. g.fillAll (findColour (backgroundColourId));
  59312. if ((flags & showColourAtTop) != 0)
  59313. {
  59314. const Colour colour (getCurrentColour());
  59315. g.fillCheckerBoard (edgeGap, edgeGap, getWidth() - edgeGap - edgeGap, topSpace - edgeGap - edgeGap,
  59316. 10, 10,
  59317. Colour (0xffdddddd).overlaidWith (colour),
  59318. Colour (0xffffffff).overlaidWith (colour));
  59319. g.setColour (Colours::white.overlaidWith (colour).contrasting());
  59320. g.setFont (14.0f, true);
  59321. g.drawText (((flags & showAlphaChannel) != 0)
  59322. ? String::formatted (T("#%02X%02X%02X%02X"),
  59323. (int) colour.getAlpha(),
  59324. (int) colour.getRed(),
  59325. (int) colour.getGreen(),
  59326. (int) colour.getBlue())
  59327. : String::formatted (T("#%02X%02X%02X"),
  59328. (int) colour.getRed(),
  59329. (int) colour.getGreen(),
  59330. (int) colour.getBlue()),
  59331. 0, edgeGap, getWidth(), topSpace - edgeGap * 2,
  59332. Justification::centred, false);
  59333. }
  59334. if ((flags & showSliders) != 0)
  59335. {
  59336. g.setColour (findColour (labelTextColourId));
  59337. g.setFont (11.0f);
  59338. for (int i = 4; --i >= 0;)
  59339. {
  59340. if (sliders[i]->isVisible())
  59341. g.drawText (sliders[i]->getName() + T(":"),
  59342. 0, sliders[i]->getY(),
  59343. sliders[i]->getX() - 8, sliders[i]->getHeight(),
  59344. Justification::centredRight, false);
  59345. }
  59346. }
  59347. }
  59348. void ColourSelector::resized()
  59349. {
  59350. const int numSliders = ((flags & showAlphaChannel) != 0) ? 4 : 3;
  59351. const int numSwatches = getNumSwatches();
  59352. const int swatchSpace = numSwatches > 0 ? edgeGap + swatchHeight * ((numSwatches + 7) / swatchesPerRow) : 0;
  59353. const int sliderSpace = ((flags & showSliders) != 0) ? jmin (22 * numSliders + edgeGap, proportionOfHeight (0.3f)) : 0;
  59354. topSpace = ((flags & showColourAtTop) != 0) ? jmin (30 + edgeGap * 2, proportionOfHeight (0.2f)) : edgeGap;
  59355. int y = topSpace;
  59356. if ((flags & showColourspace) != 0)
  59357. {
  59358. const int hueWidth = jmin (50, proportionOfWidth (0.15f));
  59359. colourSpace->setBounds (edgeGap, y,
  59360. getWidth() - hueWidth - edgeGap - 4,
  59361. getHeight() - topSpace - sliderSpace - swatchSpace - edgeGap);
  59362. hueSelector->setBounds (colourSpace->getRight() + 4, y,
  59363. getWidth() - edgeGap - (colourSpace->getRight() + 4),
  59364. colourSpace->getHeight());
  59365. y = getHeight() - sliderSpace - swatchSpace - edgeGap;
  59366. }
  59367. if ((flags & showSliders) != 0)
  59368. {
  59369. const int sliderHeight = jmax (4, sliderSpace / numSliders);
  59370. for (int i = 0; i < numSliders; ++i)
  59371. {
  59372. sliders[i]->setBounds (proportionOfWidth (0.2f), y,
  59373. proportionOfWidth (0.72f), sliderHeight - 2);
  59374. y += sliderHeight;
  59375. }
  59376. }
  59377. if (numSwatches > 0)
  59378. {
  59379. const int startX = 8;
  59380. const int xGap = 4;
  59381. const int yGap = 4;
  59382. const int swatchWidth = (getWidth() - startX * 2) / swatchesPerRow;
  59383. y += edgeGap;
  59384. if (swatchComponents.size() != numSwatches)
  59385. {
  59386. swatchComponents.clear();
  59387. for (int i = 0; i < numSwatches; ++i)
  59388. {
  59389. SwatchComponent* const sc = new SwatchComponent (this, i);
  59390. swatchComponents.add (sc);
  59391. addAndMakeVisible (sc);
  59392. }
  59393. }
  59394. int x = startX;
  59395. for (int i = 0; i < swatchComponents.size(); ++i)
  59396. {
  59397. SwatchComponent* const sc = swatchComponents.getUnchecked(i);
  59398. sc->setBounds (x + xGap / 2,
  59399. y + yGap / 2,
  59400. swatchWidth - xGap,
  59401. swatchHeight - yGap);
  59402. if (((i + 1) % swatchesPerRow) == 0)
  59403. {
  59404. x = startX;
  59405. y += swatchHeight;
  59406. }
  59407. else
  59408. {
  59409. x += swatchWidth;
  59410. }
  59411. }
  59412. }
  59413. }
  59414. void ColourSelector::sliderValueChanged (Slider*)
  59415. {
  59416. if (sliders[0] != 0)
  59417. setCurrentColour (Colour ((uint8) sliders[0]->getValue(),
  59418. (uint8) sliders[1]->getValue(),
  59419. (uint8) sliders[2]->getValue(),
  59420. (uint8) sliders[3]->getValue()));
  59421. }
  59422. int ColourSelector::getNumSwatches() const
  59423. {
  59424. return 0;
  59425. }
  59426. const Colour ColourSelector::getSwatchColour (const int) const
  59427. {
  59428. jassertfalse // if you've overridden getNumSwatches(), you also need to implement this method
  59429. return Colours::black;
  59430. }
  59431. void ColourSelector::setSwatchColour (const int, const Colour&) const
  59432. {
  59433. jassertfalse // if you've overridden getNumSwatches(), you also need to implement this method
  59434. }
  59435. END_JUCE_NAMESPACE
  59436. /********* End of inlined file: juce_ColourSelector.cpp *********/
  59437. /********* Start of inlined file: juce_DropShadower.cpp *********/
  59438. BEGIN_JUCE_NAMESPACE
  59439. class ShadowWindow : public Component
  59440. {
  59441. Component* owner;
  59442. Image** shadowImageSections;
  59443. const int type; // 0 = left, 1 = right, 2 = top, 3 = bottom. left + right are full-height
  59444. public:
  59445. ShadowWindow (Component* const owner_,
  59446. const int type_,
  59447. Image** const shadowImageSections_)
  59448. : owner (owner_),
  59449. shadowImageSections (shadowImageSections_),
  59450. type (type_)
  59451. {
  59452. setInterceptsMouseClicks (false, false);
  59453. if (owner_->isOnDesktop())
  59454. {
  59455. setSize (1, 1); // to keep the OS happy by not having zero-size windows
  59456. addToDesktop (ComponentPeer::windowIgnoresMouseClicks
  59457. | ComponentPeer::windowIsTemporary
  59458. | ComponentPeer::windowIgnoresKeyPresses);
  59459. }
  59460. else if (owner_->getParentComponent() != 0)
  59461. {
  59462. owner_->getParentComponent()->addChildComponent (this);
  59463. }
  59464. }
  59465. ~ShadowWindow()
  59466. {
  59467. }
  59468. void paint (Graphics& g)
  59469. {
  59470. Image* const topLeft = shadowImageSections [type * 3];
  59471. Image* const bottomRight = shadowImageSections [type * 3 + 1];
  59472. Image* const filler = shadowImageSections [type * 3 + 2];
  59473. g.setOpacity (1.0f);
  59474. if (type < 2)
  59475. {
  59476. int imH = jmin (topLeft->getHeight(), getHeight() / 2);
  59477. g.drawImage (topLeft,
  59478. 0, 0, topLeft->getWidth(), imH,
  59479. 0, 0, topLeft->getWidth(), imH);
  59480. imH = jmin (bottomRight->getHeight(), getHeight() - getHeight() / 2);
  59481. g.drawImage (bottomRight,
  59482. 0, getHeight() - imH, bottomRight->getWidth(), imH,
  59483. 0, bottomRight->getHeight() - imH, bottomRight->getWidth(), imH);
  59484. g.setTiledImageFill (*filler, 0, 0, 1.0f);
  59485. g.fillRect (0, topLeft->getHeight(), getWidth(), getHeight() - (topLeft->getHeight() + bottomRight->getHeight()));
  59486. }
  59487. else
  59488. {
  59489. int imW = jmin (topLeft->getWidth(), getWidth() / 2);
  59490. g.drawImage (topLeft,
  59491. 0, 0, imW, topLeft->getHeight(),
  59492. 0, 0, imW, topLeft->getHeight());
  59493. imW = jmin (bottomRight->getWidth(), getWidth() - getWidth() / 2);
  59494. g.drawImage (bottomRight,
  59495. getWidth() - imW, 0, imW, bottomRight->getHeight(),
  59496. bottomRight->getWidth() - imW, 0, imW, bottomRight->getHeight());
  59497. g.setTiledImageFill (*filler, 0, 0, 1.0f);
  59498. g.fillRect (topLeft->getWidth(), 0, getWidth() - (topLeft->getWidth() + bottomRight->getWidth()), getHeight());
  59499. }
  59500. }
  59501. void resized()
  59502. {
  59503. repaint(); // (needed for correct repainting)
  59504. }
  59505. private:
  59506. ShadowWindow (const ShadowWindow&);
  59507. const ShadowWindow& operator= (const ShadowWindow&);
  59508. };
  59509. DropShadower::DropShadower (const float alpha_,
  59510. const int xOffset_,
  59511. const int yOffset_,
  59512. const float blurRadius_)
  59513. : owner (0),
  59514. numShadows (0),
  59515. shadowEdge (jmax (xOffset_, yOffset_) + (int) blurRadius_),
  59516. xOffset (xOffset_),
  59517. yOffset (yOffset_),
  59518. alpha (alpha_),
  59519. blurRadius (blurRadius_),
  59520. inDestructor (false),
  59521. reentrant (false)
  59522. {
  59523. }
  59524. DropShadower::~DropShadower()
  59525. {
  59526. if (owner != 0)
  59527. owner->removeComponentListener (this);
  59528. inDestructor = true;
  59529. deleteShadowWindows();
  59530. }
  59531. void DropShadower::deleteShadowWindows()
  59532. {
  59533. if (numShadows > 0)
  59534. {
  59535. int i;
  59536. for (i = numShadows; --i >= 0;)
  59537. delete shadowWindows[i];
  59538. for (i = 12; --i >= 0;)
  59539. delete shadowImageSections[i];
  59540. numShadows = 0;
  59541. }
  59542. }
  59543. void DropShadower::setOwner (Component* componentToFollow)
  59544. {
  59545. if (componentToFollow != owner)
  59546. {
  59547. if (owner != 0)
  59548. owner->removeComponentListener (this);
  59549. // (the component can't be null)
  59550. jassert (componentToFollow != 0);
  59551. owner = componentToFollow;
  59552. jassert (owner != 0);
  59553. jassert (owner->isOpaque()); // doesn't work properly for semi-transparent comps!
  59554. owner->addComponentListener (this);
  59555. updateShadows();
  59556. }
  59557. }
  59558. void DropShadower::componentMovedOrResized (Component&, bool /*wasMoved*/, bool /*wasResized*/)
  59559. {
  59560. updateShadows();
  59561. }
  59562. void DropShadower::componentBroughtToFront (Component&)
  59563. {
  59564. bringShadowWindowsToFront();
  59565. }
  59566. void DropShadower::componentChildrenChanged (Component&)
  59567. {
  59568. }
  59569. void DropShadower::componentParentHierarchyChanged (Component&)
  59570. {
  59571. deleteShadowWindows();
  59572. updateShadows();
  59573. }
  59574. void DropShadower::componentVisibilityChanged (Component&)
  59575. {
  59576. updateShadows();
  59577. }
  59578. void DropShadower::updateShadows()
  59579. {
  59580. if (reentrant || inDestructor || (owner == 0))
  59581. return;
  59582. reentrant = true;
  59583. ComponentPeer* const nw = owner->getPeer();
  59584. const bool isOwnerVisible = owner->isVisible()
  59585. && (nw == 0 || ! nw->isMinimised());
  59586. const bool createShadowWindows = numShadows == 0
  59587. && owner->getWidth() > 0
  59588. && owner->getHeight() > 0
  59589. && isOwnerVisible
  59590. && (Desktop::canUseSemiTransparentWindows()
  59591. || owner->getParentComponent() != 0);
  59592. if (createShadowWindows)
  59593. {
  59594. // keep a cached version of the image to save doing the gaussian too often
  59595. String imageId;
  59596. imageId << shadowEdge << T(',')
  59597. << xOffset << T(',')
  59598. << yOffset << T(',')
  59599. << alpha;
  59600. const int hash = imageId.hashCode();
  59601. Image* bigIm = ImageCache::getFromHashCode (hash);
  59602. if (bigIm == 0)
  59603. {
  59604. bigIm = Image::createNativeImage (Image::ARGB, shadowEdge * 5, shadowEdge * 5, true);
  59605. Graphics bigG (*bigIm);
  59606. bigG.setColour (Colours::black.withAlpha (alpha));
  59607. bigG.fillRect (shadowEdge + xOffset,
  59608. shadowEdge + yOffset,
  59609. bigIm->getWidth() - (shadowEdge * 2),
  59610. bigIm->getHeight() - (shadowEdge * 2));
  59611. ImageConvolutionKernel blurKernel (roundToInt (blurRadius * 2.0f));
  59612. blurKernel.createGaussianBlur (blurRadius);
  59613. blurKernel.applyToImage (*bigIm, 0,
  59614. xOffset,
  59615. yOffset,
  59616. bigIm->getWidth(),
  59617. bigIm->getHeight());
  59618. ImageCache::addImageToCache (bigIm, hash);
  59619. }
  59620. const int iw = bigIm->getWidth();
  59621. const int ih = bigIm->getHeight();
  59622. const int shadowEdge2 = shadowEdge * 2;
  59623. setShadowImage (bigIm, 0, shadowEdge, shadowEdge2, 0, 0);
  59624. setShadowImage (bigIm, 1, shadowEdge, shadowEdge2, 0, ih - shadowEdge2);
  59625. setShadowImage (bigIm, 2, shadowEdge, shadowEdge, 0, shadowEdge2);
  59626. setShadowImage (bigIm, 3, shadowEdge, shadowEdge2, iw - shadowEdge, 0);
  59627. setShadowImage (bigIm, 4, shadowEdge, shadowEdge2, iw - shadowEdge, ih - shadowEdge2);
  59628. setShadowImage (bigIm, 5, shadowEdge, shadowEdge, iw - shadowEdge, shadowEdge2);
  59629. setShadowImage (bigIm, 6, shadowEdge, shadowEdge, shadowEdge, 0);
  59630. setShadowImage (bigIm, 7, shadowEdge, shadowEdge, iw - shadowEdge2, 0);
  59631. setShadowImage (bigIm, 8, shadowEdge, shadowEdge, shadowEdge2, 0);
  59632. setShadowImage (bigIm, 9, shadowEdge, shadowEdge, shadowEdge, ih - shadowEdge);
  59633. setShadowImage (bigIm, 10, shadowEdge, shadowEdge, iw - shadowEdge2, ih - shadowEdge);
  59634. setShadowImage (bigIm, 11, shadowEdge, shadowEdge, shadowEdge2, ih - shadowEdge);
  59635. ImageCache::release (bigIm);
  59636. for (int i = 0; i < 4; ++i)
  59637. {
  59638. shadowWindows[numShadows] = new ShadowWindow (owner, i, shadowImageSections);
  59639. ++numShadows;
  59640. }
  59641. }
  59642. if (numShadows > 0)
  59643. {
  59644. for (int i = numShadows; --i >= 0;)
  59645. {
  59646. shadowWindows[i]->setAlwaysOnTop (owner->isAlwaysOnTop());
  59647. shadowWindows[i]->setVisible (isOwnerVisible);
  59648. }
  59649. const int x = owner->getX();
  59650. const int y = owner->getY() - shadowEdge;
  59651. const int w = owner->getWidth();
  59652. const int h = owner->getHeight() + shadowEdge + shadowEdge;
  59653. shadowWindows[0]->setBounds (x - shadowEdge,
  59654. y,
  59655. shadowEdge,
  59656. h);
  59657. shadowWindows[1]->setBounds (x + w,
  59658. y,
  59659. shadowEdge,
  59660. h);
  59661. shadowWindows[2]->setBounds (x,
  59662. y,
  59663. w,
  59664. shadowEdge);
  59665. shadowWindows[3]->setBounds (x,
  59666. owner->getBottom(),
  59667. w,
  59668. shadowEdge);
  59669. }
  59670. reentrant = false;
  59671. if (createShadowWindows)
  59672. bringShadowWindowsToFront();
  59673. }
  59674. void DropShadower::setShadowImage (Image* const src,
  59675. const int num,
  59676. const int w,
  59677. const int h,
  59678. const int sx,
  59679. const int sy)
  59680. {
  59681. shadowImageSections[num] = new Image (Image::ARGB, w, h, true);
  59682. Graphics g (*shadowImageSections[num]);
  59683. g.drawImage (src, 0, 0, w, h, sx, sy, w, h);
  59684. }
  59685. void DropShadower::bringShadowWindowsToFront()
  59686. {
  59687. if (! (inDestructor || reentrant))
  59688. {
  59689. updateShadows();
  59690. reentrant = true;
  59691. for (int i = numShadows; --i >= 0;)
  59692. shadowWindows[i]->toBehind (owner);
  59693. reentrant = false;
  59694. }
  59695. }
  59696. END_JUCE_NAMESPACE
  59697. /********* End of inlined file: juce_DropShadower.cpp *********/
  59698. /********* Start of inlined file: juce_MagnifierComponent.cpp *********/
  59699. BEGIN_JUCE_NAMESPACE
  59700. class MagnifyingPeer : public ComponentPeer
  59701. {
  59702. public:
  59703. MagnifyingPeer (Component* const component_,
  59704. MagnifierComponent* const magnifierComp_)
  59705. : ComponentPeer (component_, 0),
  59706. magnifierComp (magnifierComp_)
  59707. {
  59708. }
  59709. ~MagnifyingPeer()
  59710. {
  59711. }
  59712. void* getNativeHandle() const { return 0; }
  59713. void setVisible (bool) {}
  59714. void setTitle (const String&) {}
  59715. void setPosition (int, int) {}
  59716. void setSize (int, int) {}
  59717. void setBounds (int, int, int, int, const bool) {}
  59718. void setMinimised (bool) {}
  59719. bool isMinimised() const { return false; }
  59720. void setFullScreen (bool) {}
  59721. bool isFullScreen() const { return false; }
  59722. const BorderSize getFrameSize() const { return BorderSize (0); }
  59723. bool setAlwaysOnTop (bool) { return true; }
  59724. void toFront (bool) {}
  59725. void toBehind (ComponentPeer*) {}
  59726. void setIcon (const Image&) {}
  59727. bool isFocused() const
  59728. {
  59729. return magnifierComp->hasKeyboardFocus (true);
  59730. }
  59731. void grabFocus()
  59732. {
  59733. ComponentPeer* peer = magnifierComp->getPeer();
  59734. if (peer != 0)
  59735. peer->grabFocus();
  59736. }
  59737. void textInputRequired (int x, int y)
  59738. {
  59739. ComponentPeer* peer = magnifierComp->getPeer();
  59740. if (peer != 0)
  59741. peer->textInputRequired (x, y);
  59742. }
  59743. void getBounds (int& x, int& y, int& w, int& h) const
  59744. {
  59745. x = magnifierComp->getScreenX();
  59746. y = magnifierComp->getScreenY();
  59747. w = component->getWidth();
  59748. h = component->getHeight();
  59749. }
  59750. int getScreenX() const { return magnifierComp->getScreenX(); }
  59751. int getScreenY() const { return magnifierComp->getScreenY(); }
  59752. void relativePositionToGlobal (int& x, int& y)
  59753. {
  59754. const double zoom = magnifierComp->getScaleFactor();
  59755. x = roundToInt (x * zoom);
  59756. y = roundToInt (y * zoom);
  59757. magnifierComp->relativePositionToGlobal (x, y);
  59758. }
  59759. void globalPositionToRelative (int& x, int& y)
  59760. {
  59761. magnifierComp->globalPositionToRelative (x, y);
  59762. const double zoom = magnifierComp->getScaleFactor();
  59763. x = roundToInt (x / zoom);
  59764. y = roundToInt (y / zoom);
  59765. }
  59766. bool contains (int x, int y, bool) const
  59767. {
  59768. return ((unsigned int) x) < (unsigned int) magnifierComp->getWidth()
  59769. && ((unsigned int) y) < (unsigned int) magnifierComp->getHeight();
  59770. }
  59771. void repaint (int x, int y, int w, int h)
  59772. {
  59773. const double zoom = magnifierComp->getScaleFactor();
  59774. magnifierComp->repaint ((int) (x * zoom),
  59775. (int) (y * zoom),
  59776. roundToInt (w * zoom) + 1,
  59777. roundToInt (h * zoom) + 1);
  59778. }
  59779. void performAnyPendingRepaintsNow()
  59780. {
  59781. }
  59782. juce_UseDebuggingNewOperator
  59783. private:
  59784. MagnifierComponent* const magnifierComp;
  59785. MagnifyingPeer (const MagnifyingPeer&);
  59786. const MagnifyingPeer& operator= (const MagnifyingPeer&);
  59787. };
  59788. class PeerHolderComp : public Component
  59789. {
  59790. public:
  59791. PeerHolderComp (MagnifierComponent* const magnifierComp_)
  59792. : magnifierComp (magnifierComp_)
  59793. {
  59794. setVisible (true);
  59795. }
  59796. ~PeerHolderComp()
  59797. {
  59798. }
  59799. ComponentPeer* createNewPeer (int, void*)
  59800. {
  59801. return new MagnifyingPeer (this, magnifierComp);
  59802. }
  59803. void childBoundsChanged (Component* c)
  59804. {
  59805. if (c != 0)
  59806. {
  59807. setSize (c->getWidth(), c->getHeight());
  59808. magnifierComp->childBoundsChanged (this);
  59809. }
  59810. }
  59811. void mouseWheelMove (const MouseEvent& e, float ix, float iy)
  59812. {
  59813. // unhandled mouse wheel moves can be referred upwards to the parent comp..
  59814. Component* const p = magnifierComp->getParentComponent();
  59815. if (p != 0)
  59816. p->mouseWheelMove (e.getEventRelativeTo (p), ix, iy);
  59817. }
  59818. private:
  59819. MagnifierComponent* const magnifierComp;
  59820. PeerHolderComp (const PeerHolderComp&);
  59821. const PeerHolderComp& operator= (const PeerHolderComp&);
  59822. };
  59823. MagnifierComponent::MagnifierComponent (Component* const content_,
  59824. const bool deleteContentCompWhenNoLongerNeeded)
  59825. : content (content_),
  59826. scaleFactor (0.0),
  59827. peer (0),
  59828. deleteContent (deleteContentCompWhenNoLongerNeeded),
  59829. quality (Graphics::lowResamplingQuality)
  59830. {
  59831. holderComp = new PeerHolderComp (this);
  59832. setScaleFactor (1.0);
  59833. }
  59834. MagnifierComponent::~MagnifierComponent()
  59835. {
  59836. delete holderComp;
  59837. if (deleteContent)
  59838. delete content;
  59839. }
  59840. void MagnifierComponent::setScaleFactor (double newScaleFactor)
  59841. {
  59842. jassert (newScaleFactor > 0.0); // hmm - unlikely to work well with a negative scale factor
  59843. newScaleFactor = jlimit (1.0 / 8.0, 1000.0, newScaleFactor);
  59844. if (scaleFactor != newScaleFactor)
  59845. {
  59846. scaleFactor = newScaleFactor;
  59847. if (scaleFactor == 1.0)
  59848. {
  59849. holderComp->removeFromDesktop();
  59850. peer = 0;
  59851. addChildComponent (content);
  59852. childBoundsChanged (content);
  59853. }
  59854. else
  59855. {
  59856. holderComp->addAndMakeVisible (content);
  59857. holderComp->childBoundsChanged (content);
  59858. childBoundsChanged (holderComp);
  59859. holderComp->addToDesktop (0);
  59860. peer = holderComp->getPeer();
  59861. }
  59862. repaint();
  59863. }
  59864. }
  59865. void MagnifierComponent::setResamplingQuality (Graphics::ResamplingQuality newQuality)
  59866. {
  59867. quality = newQuality;
  59868. }
  59869. void MagnifierComponent::paint (Graphics& g)
  59870. {
  59871. const int w = holderComp->getWidth();
  59872. const int h = holderComp->getHeight();
  59873. if (w == 0 || h == 0)
  59874. return;
  59875. const Rectangle r (g.getClipBounds());
  59876. const int srcX = (int) (r.getX() / scaleFactor);
  59877. const int srcY = (int) (r.getY() / scaleFactor);
  59878. int srcW = roundToInt (r.getRight() / scaleFactor) - srcX;
  59879. int srcH = roundToInt (r.getBottom() / scaleFactor) - srcY;
  59880. if (scaleFactor >= 1.0)
  59881. {
  59882. ++srcW;
  59883. ++srcH;
  59884. }
  59885. Image temp (Image::ARGB, jmax (w, srcX + srcW), jmax (h, srcY + srcH), false);
  59886. temp.clear (srcX, srcY, srcW, srcH);
  59887. {
  59888. Graphics g2 (temp);
  59889. g2.reduceClipRegion (srcX, srcY, srcW, srcH);
  59890. holderComp->paintEntireComponent (g2);
  59891. }
  59892. g.setImageResamplingQuality (quality);
  59893. g.drawImageTransformed (&temp, temp.getBounds(),
  59894. AffineTransform::scale ((float) scaleFactor, (float) scaleFactor),
  59895. false);
  59896. }
  59897. void MagnifierComponent::childBoundsChanged (Component* c)
  59898. {
  59899. if (c != 0)
  59900. setSize (roundToInt (c->getWidth() * scaleFactor),
  59901. roundToInt (c->getHeight() * scaleFactor));
  59902. }
  59903. void MagnifierComponent::mouseDown (const MouseEvent& e)
  59904. {
  59905. if (peer != 0)
  59906. peer->handleMouseDown (scaleInt (e.x), scaleInt (e.y), e.eventTime.toMilliseconds());
  59907. }
  59908. void MagnifierComponent::mouseUp (const MouseEvent& e)
  59909. {
  59910. if (peer != 0)
  59911. peer->handleMouseUp (e.mods.getRawFlags(), scaleInt (e.x), scaleInt (e.y), e.eventTime.toMilliseconds());
  59912. }
  59913. void MagnifierComponent::mouseDrag (const MouseEvent& e)
  59914. {
  59915. if (peer != 0)
  59916. peer->handleMouseDrag (scaleInt (e.x), scaleInt (e.y), e.eventTime.toMilliseconds());
  59917. }
  59918. void MagnifierComponent::mouseMove (const MouseEvent& e)
  59919. {
  59920. if (peer != 0)
  59921. peer->handleMouseMove (scaleInt (e.x), scaleInt (e.y), e.eventTime.toMilliseconds());
  59922. }
  59923. void MagnifierComponent::mouseEnter (const MouseEvent& e)
  59924. {
  59925. if (peer != 0)
  59926. peer->handleMouseEnter (scaleInt (e.x), scaleInt (e.y), e.eventTime.toMilliseconds());
  59927. }
  59928. void MagnifierComponent::mouseExit (const MouseEvent& e)
  59929. {
  59930. if (peer != 0)
  59931. peer->handleMouseExit (scaleInt (e.x), scaleInt (e.y), e.eventTime.toMilliseconds());
  59932. }
  59933. void MagnifierComponent::mouseWheelMove (const MouseEvent& e, float ix, float iy)
  59934. {
  59935. if (peer != 0)
  59936. peer->handleMouseWheel (roundToInt (ix * 256.0f),
  59937. roundToInt (iy * 256.0f),
  59938. e.eventTime.toMilliseconds());
  59939. else
  59940. Component::mouseWheelMove (e, ix, iy);
  59941. }
  59942. int MagnifierComponent::scaleInt (const int n) const
  59943. {
  59944. return roundToInt (n / scaleFactor);
  59945. }
  59946. END_JUCE_NAMESPACE
  59947. /********* End of inlined file: juce_MagnifierComponent.cpp *********/
  59948. /********* Start of inlined file: juce_MidiKeyboardComponent.cpp *********/
  59949. BEGIN_JUCE_NAMESPACE
  59950. class MidiKeyboardUpDownButton : public Button
  59951. {
  59952. public:
  59953. MidiKeyboardUpDownButton (MidiKeyboardComponent* const owner_,
  59954. const int delta_)
  59955. : Button (String::empty),
  59956. owner (owner_),
  59957. delta (delta_)
  59958. {
  59959. setOpaque (true);
  59960. }
  59961. ~MidiKeyboardUpDownButton()
  59962. {
  59963. }
  59964. void clicked()
  59965. {
  59966. int note = owner->getLowestVisibleKey();
  59967. if (delta < 0)
  59968. note = (note - 1) / 12;
  59969. else
  59970. note = note / 12 + 1;
  59971. owner->setLowestVisibleKey (note * 12);
  59972. }
  59973. void paintButton (Graphics& g,
  59974. bool isMouseOverButton,
  59975. bool isButtonDown)
  59976. {
  59977. owner->drawUpDownButton (g, getWidth(), getHeight(),
  59978. isMouseOverButton, isButtonDown,
  59979. delta > 0);
  59980. }
  59981. private:
  59982. MidiKeyboardComponent* const owner;
  59983. const int delta;
  59984. MidiKeyboardUpDownButton (const MidiKeyboardUpDownButton&);
  59985. const MidiKeyboardUpDownButton& operator= (const MidiKeyboardUpDownButton&);
  59986. };
  59987. MidiKeyboardComponent::MidiKeyboardComponent (MidiKeyboardState& state_,
  59988. const Orientation orientation_)
  59989. : state (state_),
  59990. xOffset (0),
  59991. blackNoteLength (1),
  59992. keyWidth (16.0f),
  59993. orientation (orientation_),
  59994. midiChannel (1),
  59995. midiInChannelMask (0xffff),
  59996. velocity (1.0f),
  59997. noteUnderMouse (-1),
  59998. mouseDownNote (-1),
  59999. rangeStart (0),
  60000. rangeEnd (127),
  60001. firstKey (12 * 4),
  60002. canScroll (true),
  60003. mouseDragging (false),
  60004. useMousePositionForVelocity (true),
  60005. keyMappingOctave (6),
  60006. octaveNumForMiddleC (3)
  60007. {
  60008. addChildComponent (scrollDown = new MidiKeyboardUpDownButton (this, -1));
  60009. addChildComponent (scrollUp = new MidiKeyboardUpDownButton (this, 1));
  60010. // initialise with a default set of querty key-mappings..
  60011. const char* const keymap = "awsedftgyhujkolp;";
  60012. for (int i = String (keymap).length(); --i >= 0;)
  60013. setKeyPressForNote (KeyPress (keymap[i], 0, 0), i);
  60014. setOpaque (true);
  60015. setWantsKeyboardFocus (true);
  60016. state.addListener (this);
  60017. }
  60018. MidiKeyboardComponent::~MidiKeyboardComponent()
  60019. {
  60020. state.removeListener (this);
  60021. jassert (mouseDownNote < 0 && keysPressed.countNumberOfSetBits() == 0); // leaving stuck notes!
  60022. deleteAllChildren();
  60023. }
  60024. void MidiKeyboardComponent::setKeyWidth (const float widthInPixels)
  60025. {
  60026. keyWidth = widthInPixels;
  60027. resized();
  60028. }
  60029. void MidiKeyboardComponent::setOrientation (const Orientation newOrientation)
  60030. {
  60031. if (orientation != newOrientation)
  60032. {
  60033. orientation = newOrientation;
  60034. resized();
  60035. }
  60036. }
  60037. void MidiKeyboardComponent::setAvailableRange (const int lowestNote,
  60038. const int highestNote)
  60039. {
  60040. jassert (lowestNote >= 0 && lowestNote <= 127);
  60041. jassert (highestNote >= 0 && highestNote <= 127);
  60042. jassert (lowestNote <= highestNote);
  60043. if (rangeStart != lowestNote || rangeEnd != highestNote)
  60044. {
  60045. rangeStart = jlimit (0, 127, lowestNote);
  60046. rangeEnd = jlimit (0, 127, highestNote);
  60047. firstKey = jlimit (rangeStart, rangeEnd, firstKey);
  60048. resized();
  60049. }
  60050. }
  60051. void MidiKeyboardComponent::setLowestVisibleKey (int noteNumber)
  60052. {
  60053. noteNumber = jlimit (rangeStart, rangeEnd, noteNumber);
  60054. if (noteNumber != firstKey)
  60055. {
  60056. firstKey = noteNumber;
  60057. sendChangeMessage (this);
  60058. resized();
  60059. }
  60060. }
  60061. void MidiKeyboardComponent::setScrollButtonsVisible (const bool canScroll_)
  60062. {
  60063. if (canScroll != canScroll_)
  60064. {
  60065. canScroll = canScroll_;
  60066. resized();
  60067. }
  60068. }
  60069. void MidiKeyboardComponent::colourChanged()
  60070. {
  60071. repaint();
  60072. }
  60073. void MidiKeyboardComponent::setMidiChannel (const int midiChannelNumber)
  60074. {
  60075. jassert (midiChannelNumber > 0 && midiChannelNumber <= 16);
  60076. if (midiChannel != midiChannelNumber)
  60077. {
  60078. resetAnyKeysInUse();
  60079. midiChannel = jlimit (1, 16, midiChannelNumber);
  60080. }
  60081. }
  60082. void MidiKeyboardComponent::setMidiChannelsToDisplay (const int midiChannelMask)
  60083. {
  60084. midiInChannelMask = midiChannelMask;
  60085. triggerAsyncUpdate();
  60086. }
  60087. void MidiKeyboardComponent::setVelocity (const float velocity_, const bool useMousePositionForVelocity_)
  60088. {
  60089. velocity = jlimit (0.0f, 1.0f, velocity_);
  60090. useMousePositionForVelocity = useMousePositionForVelocity_;
  60091. }
  60092. void MidiKeyboardComponent::getKeyPosition (int midiNoteNumber, const float keyWidth, int& x, int& w) const
  60093. {
  60094. jassert (midiNoteNumber >= 0 && midiNoteNumber < 128);
  60095. static const float blackNoteWidth = 0.7f;
  60096. static const float notePos[] = { 0.0f, 1 - blackNoteWidth * 0.6f,
  60097. 1.0f, 2 - blackNoteWidth * 0.4f,
  60098. 2.0f, 3.0f, 4 - blackNoteWidth * 0.7f,
  60099. 4.0f, 5 - blackNoteWidth * 0.5f,
  60100. 5.0f, 6 - blackNoteWidth * 0.3f,
  60101. 6.0f };
  60102. static const float widths[] = { 1.0f, blackNoteWidth,
  60103. 1.0f, blackNoteWidth,
  60104. 1.0f, 1.0f, blackNoteWidth,
  60105. 1.0f, blackNoteWidth,
  60106. 1.0f, blackNoteWidth,
  60107. 1.0f };
  60108. const int octave = midiNoteNumber / 12;
  60109. const int note = midiNoteNumber % 12;
  60110. x = roundToInt (octave * 7.0f * keyWidth + notePos [note] * keyWidth);
  60111. w = roundToInt (widths [note] * keyWidth);
  60112. }
  60113. void MidiKeyboardComponent::getKeyPos (int midiNoteNumber, int& x, int& w) const
  60114. {
  60115. getKeyPosition (midiNoteNumber, keyWidth, x, w);
  60116. int rx, rw;
  60117. getKeyPosition (rangeStart, keyWidth, rx, rw);
  60118. x -= xOffset + rx;
  60119. }
  60120. int MidiKeyboardComponent::getKeyStartPosition (const int midiNoteNumber) const
  60121. {
  60122. int x, y;
  60123. getKeyPos (midiNoteNumber, x, y);
  60124. return x;
  60125. }
  60126. static const uint8 whiteNotes[] = { 0, 2, 4, 5, 7, 9, 11 };
  60127. static const uint8 blackNotes[] = { 1, 3, 6, 8, 10 };
  60128. int MidiKeyboardComponent::xyToNote (int x, int y, float& mousePositionVelocity)
  60129. {
  60130. if (! reallyContains (x, y, false))
  60131. return -1;
  60132. if (orientation != horizontalKeyboard)
  60133. {
  60134. swapVariables (x, y);
  60135. if (orientation == verticalKeyboardFacingLeft)
  60136. y = getWidth() - y;
  60137. else
  60138. x = getHeight() - x;
  60139. }
  60140. return remappedXYToNote (x + xOffset, y, mousePositionVelocity);
  60141. }
  60142. int MidiKeyboardComponent::remappedXYToNote (int x, int y, float& mousePositionVelocity) const
  60143. {
  60144. if (y < blackNoteLength)
  60145. {
  60146. for (int octaveStart = 12 * (rangeStart / 12); octaveStart <= rangeEnd; octaveStart += 12)
  60147. {
  60148. for (int i = 0; i < 5; ++i)
  60149. {
  60150. const int note = octaveStart + blackNotes [i];
  60151. if (note >= rangeStart && note <= rangeEnd)
  60152. {
  60153. int kx, kw;
  60154. getKeyPos (note, kx, kw);
  60155. kx += xOffset;
  60156. if (x >= kx && x < kx + kw)
  60157. {
  60158. mousePositionVelocity = y / (float) blackNoteLength;
  60159. return note;
  60160. }
  60161. }
  60162. }
  60163. }
  60164. }
  60165. for (int octaveStart = 12 * (rangeStart / 12); octaveStart <= rangeEnd; octaveStart += 12)
  60166. {
  60167. for (int i = 0; i < 7; ++i)
  60168. {
  60169. const int note = octaveStart + whiteNotes [i];
  60170. if (note >= rangeStart && note <= rangeEnd)
  60171. {
  60172. int kx, kw;
  60173. getKeyPos (note, kx, kw);
  60174. kx += xOffset;
  60175. if (x >= kx && x < kx + kw)
  60176. {
  60177. const int whiteNoteLength = (orientation == horizontalKeyboard) ? getHeight() : getWidth();
  60178. mousePositionVelocity = y / (float) whiteNoteLength;
  60179. return note;
  60180. }
  60181. }
  60182. }
  60183. }
  60184. mousePositionVelocity = 0;
  60185. return -1;
  60186. }
  60187. void MidiKeyboardComponent::repaintNote (const int noteNum)
  60188. {
  60189. if (noteNum >= rangeStart && noteNum <= rangeEnd)
  60190. {
  60191. int x, w;
  60192. getKeyPos (noteNum, x, w);
  60193. if (orientation == horizontalKeyboard)
  60194. repaint (x, 0, w, getHeight());
  60195. else if (orientation == verticalKeyboardFacingLeft)
  60196. repaint (0, x, getWidth(), w);
  60197. else if (orientation == verticalKeyboardFacingRight)
  60198. repaint (0, getHeight() - x - w, getWidth(), w);
  60199. }
  60200. }
  60201. void MidiKeyboardComponent::paint (Graphics& g)
  60202. {
  60203. g.fillAll (Colours::white.overlaidWith (findColour (whiteNoteColourId)));
  60204. const Colour lineColour (findColour (keySeparatorLineColourId));
  60205. const Colour textColour (findColour (textLabelColourId));
  60206. int x, w, octave;
  60207. for (octave = 0; octave < 128; octave += 12)
  60208. {
  60209. for (int white = 0; white < 7; ++white)
  60210. {
  60211. const int noteNum = octave + whiteNotes [white];
  60212. if (noteNum >= rangeStart && noteNum <= rangeEnd)
  60213. {
  60214. getKeyPos (noteNum, x, w);
  60215. if (orientation == horizontalKeyboard)
  60216. drawWhiteNote (noteNum, g, x, 0, w, getHeight(),
  60217. state.isNoteOnForChannels (midiInChannelMask, noteNum),
  60218. noteUnderMouse == noteNum,
  60219. lineColour, textColour);
  60220. else if (orientation == verticalKeyboardFacingLeft)
  60221. drawWhiteNote (noteNum, g, 0, x, getWidth(), w,
  60222. state.isNoteOnForChannels (midiInChannelMask, noteNum),
  60223. noteUnderMouse == noteNum,
  60224. lineColour, textColour);
  60225. else if (orientation == verticalKeyboardFacingRight)
  60226. drawWhiteNote (noteNum, g, 0, getHeight() - x - w, getWidth(), w,
  60227. state.isNoteOnForChannels (midiInChannelMask, noteNum),
  60228. noteUnderMouse == noteNum,
  60229. lineColour, textColour);
  60230. }
  60231. }
  60232. }
  60233. float x1 = 0.0f, y1 = 0.0f, x2 = 0.0f, y2 = 0.0f;
  60234. if (orientation == verticalKeyboardFacingLeft)
  60235. {
  60236. x1 = getWidth() - 1.0f;
  60237. x2 = getWidth() - 5.0f;
  60238. }
  60239. else if (orientation == verticalKeyboardFacingRight)
  60240. x2 = 5.0f;
  60241. else
  60242. y2 = 5.0f;
  60243. g.setGradientFill (ColourGradient (Colours::black.withAlpha (0.3f), x1, y1,
  60244. Colours::transparentBlack, x2, y2, false));
  60245. getKeyPos (rangeEnd, x, w);
  60246. x += w;
  60247. if (orientation == verticalKeyboardFacingLeft)
  60248. g.fillRect (getWidth() - 5, 0, 5, x);
  60249. else if (orientation == verticalKeyboardFacingRight)
  60250. g.fillRect (0, 0, 5, x);
  60251. else
  60252. g.fillRect (0, 0, x, 5);
  60253. g.setColour (lineColour);
  60254. if (orientation == verticalKeyboardFacingLeft)
  60255. g.fillRect (0, 0, 1, x);
  60256. else if (orientation == verticalKeyboardFacingRight)
  60257. g.fillRect (getWidth() - 1, 0, 1, x);
  60258. else
  60259. g.fillRect (0, getHeight() - 1, x, 1);
  60260. const Colour blackNoteColour (findColour (blackNoteColourId));
  60261. for (octave = 0; octave < 128; octave += 12)
  60262. {
  60263. for (int black = 0; black < 5; ++black)
  60264. {
  60265. const int noteNum = octave + blackNotes [black];
  60266. if (noteNum >= rangeStart && noteNum <= rangeEnd)
  60267. {
  60268. getKeyPos (noteNum, x, w);
  60269. if (orientation == horizontalKeyboard)
  60270. drawBlackNote (noteNum, g, x, 0, w, blackNoteLength,
  60271. state.isNoteOnForChannels (midiInChannelMask, noteNum),
  60272. noteUnderMouse == noteNum,
  60273. blackNoteColour);
  60274. else if (orientation == verticalKeyboardFacingLeft)
  60275. drawBlackNote (noteNum, g, getWidth() - blackNoteLength, x, blackNoteLength, w,
  60276. state.isNoteOnForChannels (midiInChannelMask, noteNum),
  60277. noteUnderMouse == noteNum,
  60278. blackNoteColour);
  60279. else if (orientation == verticalKeyboardFacingRight)
  60280. drawBlackNote (noteNum, g, 0, getHeight() - x - w, blackNoteLength, w,
  60281. state.isNoteOnForChannels (midiInChannelMask, noteNum),
  60282. noteUnderMouse == noteNum,
  60283. blackNoteColour);
  60284. }
  60285. }
  60286. }
  60287. }
  60288. void MidiKeyboardComponent::drawWhiteNote (int midiNoteNumber,
  60289. Graphics& g, int x, int y, int w, int h,
  60290. bool isDown, bool isOver,
  60291. const Colour& lineColour,
  60292. const Colour& textColour)
  60293. {
  60294. Colour c (Colours::transparentWhite);
  60295. if (isDown)
  60296. c = findColour (keyDownOverlayColourId);
  60297. if (isOver)
  60298. c = c.overlaidWith (findColour (mouseOverKeyOverlayColourId));
  60299. g.setColour (c);
  60300. g.fillRect (x, y, w, h);
  60301. const String text (getWhiteNoteText (midiNoteNumber));
  60302. if (! text.isEmpty())
  60303. {
  60304. g.setColour (textColour);
  60305. Font f (jmin (12.0f, keyWidth * 0.9f));
  60306. f.setHorizontalScale (0.8f);
  60307. g.setFont (f);
  60308. Justification justification (Justification::centredBottom);
  60309. if (orientation == verticalKeyboardFacingLeft)
  60310. justification = Justification::centredLeft;
  60311. else if (orientation == verticalKeyboardFacingRight)
  60312. justification = Justification::centredRight;
  60313. g.drawFittedText (text, x + 2, y + 2, w - 4, h - 4, justification, 1);
  60314. }
  60315. g.setColour (lineColour);
  60316. if (orientation == horizontalKeyboard)
  60317. g.fillRect (x, y, 1, h);
  60318. else if (orientation == verticalKeyboardFacingLeft)
  60319. g.fillRect (x, y, w, 1);
  60320. else if (orientation == verticalKeyboardFacingRight)
  60321. g.fillRect (x, y + h - 1, w, 1);
  60322. if (midiNoteNumber == rangeEnd)
  60323. {
  60324. if (orientation == horizontalKeyboard)
  60325. g.fillRect (x + w, y, 1, h);
  60326. else if (orientation == verticalKeyboardFacingLeft)
  60327. g.fillRect (x, y + h, w, 1);
  60328. else if (orientation == verticalKeyboardFacingRight)
  60329. g.fillRect (x, y - 1, w, 1);
  60330. }
  60331. }
  60332. void MidiKeyboardComponent::drawBlackNote (int /*midiNoteNumber*/,
  60333. Graphics& g, int x, int y, int w, int h,
  60334. bool isDown, bool isOver,
  60335. const Colour& noteFillColour)
  60336. {
  60337. Colour c (noteFillColour);
  60338. if (isDown)
  60339. c = c.overlaidWith (findColour (keyDownOverlayColourId));
  60340. if (isOver)
  60341. c = c.overlaidWith (findColour (mouseOverKeyOverlayColourId));
  60342. g.setColour (c);
  60343. g.fillRect (x, y, w, h);
  60344. if (isDown)
  60345. {
  60346. g.setColour (noteFillColour);
  60347. g.drawRect (x, y, w, h);
  60348. }
  60349. else
  60350. {
  60351. const int xIndent = jmax (1, jmin (w, h) / 8);
  60352. g.setColour (c.brighter());
  60353. if (orientation == horizontalKeyboard)
  60354. g.fillRect (x + xIndent, y, w - xIndent * 2, 7 * h / 8);
  60355. else if (orientation == verticalKeyboardFacingLeft)
  60356. g.fillRect (x + w / 8, y + xIndent, w - w / 8, h - xIndent * 2);
  60357. else if (orientation == verticalKeyboardFacingRight)
  60358. g.fillRect (x, y + xIndent, 7 * w / 8, h - xIndent * 2);
  60359. }
  60360. }
  60361. void MidiKeyboardComponent::setOctaveForMiddleC (const int octaveNumForMiddleC_) throw()
  60362. {
  60363. octaveNumForMiddleC = octaveNumForMiddleC_;
  60364. repaint();
  60365. }
  60366. const String MidiKeyboardComponent::getWhiteNoteText (const int midiNoteNumber)
  60367. {
  60368. if (keyWidth > 14.0f && midiNoteNumber % 12 == 0)
  60369. return MidiMessage::getMidiNoteName (midiNoteNumber, true, true, octaveNumForMiddleC);
  60370. return String::empty;
  60371. }
  60372. void MidiKeyboardComponent::drawUpDownButton (Graphics& g, int w, int h,
  60373. const bool isMouseOver,
  60374. const bool isButtonDown,
  60375. const bool movesOctavesUp)
  60376. {
  60377. g.fillAll (findColour (upDownButtonBackgroundColourId));
  60378. float angle;
  60379. if (orientation == MidiKeyboardComponent::horizontalKeyboard)
  60380. angle = movesOctavesUp ? 0.0f : 0.5f;
  60381. else if (orientation == MidiKeyboardComponent::verticalKeyboardFacingLeft)
  60382. angle = movesOctavesUp ? 0.25f : 0.75f;
  60383. else
  60384. angle = movesOctavesUp ? 0.75f : 0.25f;
  60385. Path path;
  60386. path.lineTo (0.0f, 1.0f);
  60387. path.lineTo (1.0f, 0.5f);
  60388. path.closeSubPath();
  60389. path.applyTransform (AffineTransform::rotation (float_Pi * 2.0f * angle, 0.5f, 0.5f));
  60390. g.setColour (findColour (upDownButtonArrowColourId)
  60391. .withAlpha (isButtonDown ? 1.0f : (isMouseOver ? 0.6f : 0.4f)));
  60392. g.fillPath (path, path.getTransformToScaleToFit (1.0f, 1.0f,
  60393. w - 2.0f,
  60394. h - 2.0f,
  60395. true));
  60396. }
  60397. void MidiKeyboardComponent::resized()
  60398. {
  60399. int w = getWidth();
  60400. int h = getHeight();
  60401. if (w > 0 && h > 0)
  60402. {
  60403. if (orientation != horizontalKeyboard)
  60404. swapVariables (w, h);
  60405. blackNoteLength = roundToInt (h * 0.7f);
  60406. int kx2, kw2;
  60407. getKeyPos (rangeEnd, kx2, kw2);
  60408. kx2 += kw2;
  60409. if (firstKey != rangeStart)
  60410. {
  60411. int kx1, kw1;
  60412. getKeyPos (rangeStart, kx1, kw1);
  60413. if (kx2 - kx1 <= w)
  60414. {
  60415. firstKey = rangeStart;
  60416. sendChangeMessage (this);
  60417. repaint();
  60418. }
  60419. }
  60420. const bool showScrollButtons = canScroll && (firstKey > rangeStart || kx2 > w + xOffset * 2);
  60421. scrollDown->setVisible (showScrollButtons);
  60422. scrollUp->setVisible (showScrollButtons);
  60423. xOffset = 0;
  60424. if (showScrollButtons)
  60425. {
  60426. const int scrollButtonW = jmin (12, w / 2);
  60427. if (orientation == horizontalKeyboard)
  60428. {
  60429. scrollDown->setBounds (0, 0, scrollButtonW, getHeight());
  60430. scrollUp->setBounds (getWidth() - scrollButtonW, 0, scrollButtonW, getHeight());
  60431. }
  60432. else if (orientation == verticalKeyboardFacingLeft)
  60433. {
  60434. scrollDown->setBounds (0, 0, getWidth(), scrollButtonW);
  60435. scrollUp->setBounds (0, getHeight() - scrollButtonW, getWidth(), scrollButtonW);
  60436. }
  60437. else if (orientation == verticalKeyboardFacingRight)
  60438. {
  60439. scrollDown->setBounds (0, getHeight() - scrollButtonW, getWidth(), scrollButtonW);
  60440. scrollUp->setBounds (0, 0, getWidth(), scrollButtonW);
  60441. }
  60442. int endOfLastKey, kw;
  60443. getKeyPos (rangeEnd, endOfLastKey, kw);
  60444. endOfLastKey += kw;
  60445. float mousePositionVelocity;
  60446. const int spaceAvailable = w - scrollButtonW * 2;
  60447. const int lastStartKey = remappedXYToNote (endOfLastKey - spaceAvailable, 0, mousePositionVelocity) + 1;
  60448. if (lastStartKey >= 0 && firstKey > lastStartKey)
  60449. {
  60450. firstKey = jlimit (rangeStart, rangeEnd, lastStartKey);
  60451. sendChangeMessage (this);
  60452. }
  60453. int newOffset = 0;
  60454. getKeyPos (firstKey, newOffset, kw);
  60455. xOffset = newOffset - scrollButtonW;
  60456. }
  60457. else
  60458. {
  60459. firstKey = rangeStart;
  60460. }
  60461. timerCallback();
  60462. repaint();
  60463. }
  60464. }
  60465. void MidiKeyboardComponent::handleNoteOn (MidiKeyboardState*, int /*midiChannel*/, int /*midiNoteNumber*/, float /*velocity*/)
  60466. {
  60467. triggerAsyncUpdate();
  60468. }
  60469. void MidiKeyboardComponent::handleNoteOff (MidiKeyboardState*, int /*midiChannel*/, int /*midiNoteNumber*/)
  60470. {
  60471. triggerAsyncUpdate();
  60472. }
  60473. void MidiKeyboardComponent::handleAsyncUpdate()
  60474. {
  60475. for (int i = rangeStart; i <= rangeEnd; ++i)
  60476. {
  60477. if (keysCurrentlyDrawnDown[i] != state.isNoteOnForChannels (midiInChannelMask, i))
  60478. {
  60479. keysCurrentlyDrawnDown.setBit (i, state.isNoteOnForChannels (midiInChannelMask, i));
  60480. repaintNote (i);
  60481. }
  60482. }
  60483. }
  60484. void MidiKeyboardComponent::resetAnyKeysInUse()
  60485. {
  60486. if (keysPressed.countNumberOfSetBits() > 0 || mouseDownNote > 0)
  60487. {
  60488. state.allNotesOff (midiChannel);
  60489. keysPressed.clear();
  60490. mouseDownNote = -1;
  60491. }
  60492. }
  60493. void MidiKeyboardComponent::updateNoteUnderMouse (int x, int y)
  60494. {
  60495. float mousePositionVelocity = 0.0f;
  60496. const int newNote = (mouseDragging || isMouseOver())
  60497. ? xyToNote (x, y, mousePositionVelocity) : -1;
  60498. if (noteUnderMouse != newNote)
  60499. {
  60500. if (mouseDownNote >= 0)
  60501. {
  60502. state.noteOff (midiChannel, mouseDownNote);
  60503. mouseDownNote = -1;
  60504. }
  60505. if (mouseDragging && newNote >= 0)
  60506. {
  60507. if (! useMousePositionForVelocity)
  60508. mousePositionVelocity = 1.0f;
  60509. state.noteOn (midiChannel, newNote, mousePositionVelocity * velocity);
  60510. mouseDownNote = newNote;
  60511. }
  60512. repaintNote (noteUnderMouse);
  60513. noteUnderMouse = newNote;
  60514. repaintNote (noteUnderMouse);
  60515. }
  60516. else if (mouseDownNote >= 0 && ! mouseDragging)
  60517. {
  60518. state.noteOff (midiChannel, mouseDownNote);
  60519. mouseDownNote = -1;
  60520. }
  60521. }
  60522. void MidiKeyboardComponent::mouseMove (const MouseEvent& e)
  60523. {
  60524. updateNoteUnderMouse (e.x, e.y);
  60525. stopTimer();
  60526. }
  60527. void MidiKeyboardComponent::mouseDrag (const MouseEvent& e)
  60528. {
  60529. float mousePositionVelocity;
  60530. const int newNote = xyToNote (e.x, e.y, mousePositionVelocity);
  60531. if (newNote >= 0)
  60532. mouseDraggedToKey (newNote, e);
  60533. updateNoteUnderMouse (e.x, e.y);
  60534. }
  60535. bool MidiKeyboardComponent::mouseDownOnKey (int /*midiNoteNumber*/, const MouseEvent&)
  60536. {
  60537. return true;
  60538. }
  60539. void MidiKeyboardComponent::mouseDraggedToKey (int /*midiNoteNumber*/, const MouseEvent&)
  60540. {
  60541. }
  60542. void MidiKeyboardComponent::mouseDown (const MouseEvent& e)
  60543. {
  60544. float mousePositionVelocity;
  60545. const int newNote = xyToNote (e.x, e.y, mousePositionVelocity);
  60546. mouseDragging = false;
  60547. if (newNote >= 0 && mouseDownOnKey (newNote, e))
  60548. {
  60549. repaintNote (noteUnderMouse);
  60550. noteUnderMouse = -1;
  60551. mouseDragging = true;
  60552. updateNoteUnderMouse (e.x, e.y);
  60553. startTimer (500);
  60554. }
  60555. }
  60556. void MidiKeyboardComponent::mouseUp (const MouseEvent& e)
  60557. {
  60558. mouseDragging = false;
  60559. updateNoteUnderMouse (e.x, e.y);
  60560. stopTimer();
  60561. }
  60562. void MidiKeyboardComponent::mouseEnter (const MouseEvent& e)
  60563. {
  60564. updateNoteUnderMouse (e.x, e.y);
  60565. }
  60566. void MidiKeyboardComponent::mouseExit (const MouseEvent& e)
  60567. {
  60568. updateNoteUnderMouse (e.x, e.y);
  60569. }
  60570. void MidiKeyboardComponent::mouseWheelMove (const MouseEvent&, float ix, float iy)
  60571. {
  60572. setLowestVisibleKey (getLowestVisibleKey() + roundToInt ((ix != 0 ? ix : iy) * 5.0f));
  60573. }
  60574. void MidiKeyboardComponent::timerCallback()
  60575. {
  60576. int mx, my;
  60577. getMouseXYRelative (mx, my);
  60578. updateNoteUnderMouse (mx, my);
  60579. }
  60580. void MidiKeyboardComponent::clearKeyMappings()
  60581. {
  60582. resetAnyKeysInUse();
  60583. keyPressNotes.clear();
  60584. keyPresses.clear();
  60585. }
  60586. void MidiKeyboardComponent::setKeyPressForNote (const KeyPress& key,
  60587. const int midiNoteOffsetFromC)
  60588. {
  60589. removeKeyPressForNote (midiNoteOffsetFromC);
  60590. keyPressNotes.add (midiNoteOffsetFromC);
  60591. keyPresses.add (key);
  60592. }
  60593. void MidiKeyboardComponent::removeKeyPressForNote (const int midiNoteOffsetFromC)
  60594. {
  60595. for (int i = keyPressNotes.size(); --i >= 0;)
  60596. {
  60597. if (keyPressNotes.getUnchecked (i) == midiNoteOffsetFromC)
  60598. {
  60599. keyPressNotes.remove (i);
  60600. keyPresses.remove (i);
  60601. }
  60602. }
  60603. }
  60604. void MidiKeyboardComponent::setKeyPressBaseOctave (const int newOctaveNumber)
  60605. {
  60606. jassert (newOctaveNumber >= 0 && newOctaveNumber <= 10);
  60607. keyMappingOctave = newOctaveNumber;
  60608. }
  60609. bool MidiKeyboardComponent::keyStateChanged (const bool /*isKeyDown*/)
  60610. {
  60611. bool keyPressUsed = false;
  60612. for (int i = keyPresses.size(); --i >= 0;)
  60613. {
  60614. const int note = 12 * keyMappingOctave + keyPressNotes.getUnchecked (i);
  60615. if (keyPresses.getReference(i).isCurrentlyDown())
  60616. {
  60617. if (! keysPressed [note])
  60618. {
  60619. keysPressed.setBit (note);
  60620. state.noteOn (midiChannel, note, velocity);
  60621. keyPressUsed = true;
  60622. }
  60623. }
  60624. else
  60625. {
  60626. if (keysPressed [note])
  60627. {
  60628. keysPressed.clearBit (note);
  60629. state.noteOff (midiChannel, note);
  60630. keyPressUsed = true;
  60631. }
  60632. }
  60633. }
  60634. return keyPressUsed;
  60635. }
  60636. void MidiKeyboardComponent::focusLost (FocusChangeType)
  60637. {
  60638. resetAnyKeysInUse();
  60639. }
  60640. END_JUCE_NAMESPACE
  60641. /********* End of inlined file: juce_MidiKeyboardComponent.cpp *********/
  60642. /********* Start of inlined file: juce_OpenGLComponent.cpp *********/
  60643. #if JUCE_OPENGL
  60644. BEGIN_JUCE_NAMESPACE
  60645. extern void juce_glViewport (const int w, const int h);
  60646. OpenGLPixelFormat::OpenGLPixelFormat (const int bitsPerRGBComponent,
  60647. const int alphaBits_,
  60648. const int depthBufferBits_,
  60649. const int stencilBufferBits_) throw()
  60650. : redBits (bitsPerRGBComponent),
  60651. greenBits (bitsPerRGBComponent),
  60652. blueBits (bitsPerRGBComponent),
  60653. alphaBits (alphaBits_),
  60654. depthBufferBits (depthBufferBits_),
  60655. stencilBufferBits (stencilBufferBits_),
  60656. accumulationBufferRedBits (0),
  60657. accumulationBufferGreenBits (0),
  60658. accumulationBufferBlueBits (0),
  60659. accumulationBufferAlphaBits (0),
  60660. fullSceneAntiAliasingNumSamples (0)
  60661. {
  60662. }
  60663. bool OpenGLPixelFormat::operator== (const OpenGLPixelFormat& other) const throw()
  60664. {
  60665. return memcmp (this, &other, sizeof (other)) == 0;
  60666. }
  60667. static VoidArray knownContexts;
  60668. OpenGLContext::OpenGLContext() throw()
  60669. {
  60670. knownContexts.add (this);
  60671. }
  60672. OpenGLContext::~OpenGLContext()
  60673. {
  60674. knownContexts.removeValue (this);
  60675. }
  60676. OpenGLContext* OpenGLContext::getCurrentContext()
  60677. {
  60678. for (int i = knownContexts.size(); --i >= 0;)
  60679. {
  60680. OpenGLContext* const oglc = (OpenGLContext*) knownContexts.getUnchecked(i);
  60681. if (oglc->isActive())
  60682. return oglc;
  60683. }
  60684. return 0;
  60685. }
  60686. class OpenGLComponent::OpenGLComponentWatcher : public ComponentMovementWatcher
  60687. {
  60688. public:
  60689. OpenGLComponentWatcher (OpenGLComponent* const owner_)
  60690. : ComponentMovementWatcher (owner_),
  60691. owner (owner_),
  60692. wasShowing (false)
  60693. {
  60694. }
  60695. ~OpenGLComponentWatcher() {}
  60696. void componentMovedOrResized (bool /*wasMoved*/, bool /*wasResized*/)
  60697. {
  60698. owner->updateContextPosition();
  60699. }
  60700. void componentPeerChanged()
  60701. {
  60702. const ScopedLock sl (owner->getContextLock());
  60703. owner->deleteContext();
  60704. }
  60705. void componentVisibilityChanged (Component&)
  60706. {
  60707. const bool isShowingNow = owner->isShowing();
  60708. if (wasShowing != isShowingNow)
  60709. {
  60710. wasShowing = isShowingNow;
  60711. owner->updateContextPosition();
  60712. }
  60713. }
  60714. juce_UseDebuggingNewOperator
  60715. private:
  60716. OpenGLComponent* const owner;
  60717. bool wasShowing;
  60718. };
  60719. OpenGLComponent::OpenGLComponent()
  60720. : context (0),
  60721. contextToShareListsWith (0),
  60722. needToUpdateViewport (true)
  60723. {
  60724. setOpaque (true);
  60725. componentWatcher = new OpenGLComponentWatcher (this);
  60726. }
  60727. OpenGLComponent::~OpenGLComponent()
  60728. {
  60729. deleteContext();
  60730. componentWatcher = 0;
  60731. }
  60732. void OpenGLComponent::deleteContext()
  60733. {
  60734. const ScopedLock sl (contextLock);
  60735. deleteAndZero (context);
  60736. }
  60737. void OpenGLComponent::updateContextPosition()
  60738. {
  60739. needToUpdateViewport = true;
  60740. if (getWidth() > 0 && getHeight() > 0)
  60741. {
  60742. Component* const topComp = getTopLevelComponent();
  60743. if (topComp->getPeer() != 0)
  60744. {
  60745. const ScopedLock sl (contextLock);
  60746. if (context != 0)
  60747. context->updateWindowPosition (getScreenX() - topComp->getScreenX(),
  60748. getScreenY() - topComp->getScreenY(),
  60749. getWidth(),
  60750. getHeight(),
  60751. topComp->getHeight());
  60752. }
  60753. }
  60754. }
  60755. const OpenGLPixelFormat OpenGLComponent::getPixelFormat() const
  60756. {
  60757. OpenGLPixelFormat pf;
  60758. const ScopedLock sl (contextLock);
  60759. if (context != 0)
  60760. pf = context->getPixelFormat();
  60761. return pf;
  60762. }
  60763. void OpenGLComponent::setPixelFormat (const OpenGLPixelFormat& formatToUse)
  60764. {
  60765. if (! (preferredPixelFormat == formatToUse))
  60766. {
  60767. const ScopedLock sl (contextLock);
  60768. deleteContext();
  60769. preferredPixelFormat = formatToUse;
  60770. }
  60771. }
  60772. void OpenGLComponent::shareWith (OpenGLContext* c)
  60773. {
  60774. if (contextToShareListsWith != c)
  60775. {
  60776. const ScopedLock sl (contextLock);
  60777. deleteContext();
  60778. contextToShareListsWith = c;
  60779. }
  60780. }
  60781. bool OpenGLComponent::makeCurrentContextActive()
  60782. {
  60783. if (context == 0)
  60784. {
  60785. const ScopedLock sl (contextLock);
  60786. if (isShowing() && getTopLevelComponent()->getPeer() != 0)
  60787. {
  60788. context = OpenGLContext::createContextForWindow (this,
  60789. preferredPixelFormat,
  60790. contextToShareListsWith);
  60791. if (context != 0)
  60792. {
  60793. updateContextPosition();
  60794. if (context->makeActive())
  60795. newOpenGLContextCreated();
  60796. }
  60797. }
  60798. }
  60799. return context != 0 && context->makeActive();
  60800. }
  60801. void OpenGLComponent::makeCurrentContextInactive()
  60802. {
  60803. if (context != 0)
  60804. context->makeInactive();
  60805. }
  60806. bool OpenGLComponent::isActiveContext() const throw()
  60807. {
  60808. return context != 0 && context->isActive();
  60809. }
  60810. void OpenGLComponent::swapBuffers()
  60811. {
  60812. if (context != 0)
  60813. context->swapBuffers();
  60814. }
  60815. void OpenGLComponent::paint (Graphics&)
  60816. {
  60817. if (renderAndSwapBuffers())
  60818. {
  60819. ComponentPeer* const peer = getPeer();
  60820. if (peer != 0)
  60821. {
  60822. peer->addMaskedRegion (getScreenX() - peer->getScreenX(),
  60823. getScreenY() - peer->getScreenY(),
  60824. getWidth(), getHeight());
  60825. }
  60826. }
  60827. }
  60828. bool OpenGLComponent::renderAndSwapBuffers()
  60829. {
  60830. const ScopedLock sl (contextLock);
  60831. if (! makeCurrentContextActive())
  60832. return false;
  60833. if (needToUpdateViewport)
  60834. {
  60835. needToUpdateViewport = false;
  60836. juce_glViewport (getWidth(), getHeight());
  60837. }
  60838. renderOpenGL();
  60839. swapBuffers();
  60840. return true;
  60841. }
  60842. void OpenGLComponent::internalRepaint (int x, int y, int w, int h)
  60843. {
  60844. Component::internalRepaint (x, y, w, h);
  60845. if (context != 0)
  60846. context->repaint();
  60847. }
  60848. END_JUCE_NAMESPACE
  60849. #endif
  60850. /********* End of inlined file: juce_OpenGLComponent.cpp *********/
  60851. /********* Start of inlined file: juce_PreferencesPanel.cpp *********/
  60852. BEGIN_JUCE_NAMESPACE
  60853. PreferencesPanel::PreferencesPanel()
  60854. : buttonSize (70)
  60855. {
  60856. }
  60857. PreferencesPanel::~PreferencesPanel()
  60858. {
  60859. currentPage = 0;
  60860. deleteAllChildren();
  60861. }
  60862. void PreferencesPanel::addSettingsPage (const String& title,
  60863. const Drawable* icon,
  60864. const Drawable* overIcon,
  60865. const Drawable* downIcon)
  60866. {
  60867. DrawableButton* button = new DrawableButton (title, DrawableButton::ImageAboveTextLabel);
  60868. button->setImages (icon, overIcon, downIcon);
  60869. button->setRadioGroupId (1);
  60870. button->addButtonListener (this);
  60871. button->setClickingTogglesState (true);
  60872. button->setWantsKeyboardFocus (false);
  60873. addAndMakeVisible (button);
  60874. resized();
  60875. if (currentPage == 0)
  60876. setCurrentPage (title);
  60877. }
  60878. void PreferencesPanel::addSettingsPage (const String& title,
  60879. const char* imageData,
  60880. const int imageDataSize)
  60881. {
  60882. DrawableImage icon, iconOver, iconDown;
  60883. icon.setImage (ImageCache::getFromMemory (imageData, imageDataSize), true);
  60884. iconOver.setImage (ImageCache::getFromMemory (imageData, imageDataSize), true);
  60885. iconOver.setOverlayColour (Colours::black.withAlpha (0.12f));
  60886. iconDown.setImage (ImageCache::getFromMemory (imageData, imageDataSize), true);
  60887. iconDown.setOverlayColour (Colours::black.withAlpha (0.25f));
  60888. addSettingsPage (title, &icon, &iconOver, &iconDown);
  60889. }
  60890. class PrefsDialogWindow : public DialogWindow
  60891. {
  60892. public:
  60893. PrefsDialogWindow (const String& dialogtitle,
  60894. const Colour& backgroundColour)
  60895. : DialogWindow (dialogtitle, backgroundColour, true)
  60896. {
  60897. }
  60898. ~PrefsDialogWindow()
  60899. {
  60900. }
  60901. void closeButtonPressed()
  60902. {
  60903. exitModalState (0);
  60904. }
  60905. private:
  60906. PrefsDialogWindow (const PrefsDialogWindow&);
  60907. const PrefsDialogWindow& operator= (const PrefsDialogWindow&);
  60908. };
  60909. void PreferencesPanel::showInDialogBox (const String& dialogtitle,
  60910. int dialogWidth,
  60911. int dialogHeight,
  60912. const Colour& backgroundColour)
  60913. {
  60914. setSize (dialogWidth, dialogHeight);
  60915. PrefsDialogWindow dw (dialogtitle, backgroundColour);
  60916. dw.setContentComponent (this, true, true);
  60917. dw.centreAroundComponent (0, dw.getWidth(), dw.getHeight());
  60918. dw.runModalLoop();
  60919. dw.setContentComponent (0, false, false);
  60920. }
  60921. void PreferencesPanel::resized()
  60922. {
  60923. int x = 0;
  60924. for (int i = 0; i < getNumChildComponents(); ++i)
  60925. {
  60926. Component* c = getChildComponent (i);
  60927. if (dynamic_cast <DrawableButton*> (c) == 0)
  60928. {
  60929. c->setBounds (0, buttonSize + 5, getWidth(), getHeight() - buttonSize - 5);
  60930. }
  60931. else
  60932. {
  60933. c->setBounds (x, 0, buttonSize, buttonSize);
  60934. x += buttonSize;
  60935. }
  60936. }
  60937. }
  60938. void PreferencesPanel::paint (Graphics& g)
  60939. {
  60940. g.setColour (Colours::grey);
  60941. g.fillRect (0, buttonSize + 2, getWidth(), 1);
  60942. }
  60943. void PreferencesPanel::setCurrentPage (const String& pageName)
  60944. {
  60945. if (currentPageName != pageName)
  60946. {
  60947. currentPageName = pageName;
  60948. currentPage = 0;
  60949. currentPage = createComponentForPage (pageName);
  60950. if (currentPage != 0)
  60951. {
  60952. addAndMakeVisible (currentPage);
  60953. currentPage->toBack();
  60954. resized();
  60955. }
  60956. for (int i = 0; i < getNumChildComponents(); ++i)
  60957. {
  60958. DrawableButton* db = dynamic_cast <DrawableButton*> (getChildComponent (i));
  60959. if (db != 0 && db->getName() == pageName)
  60960. {
  60961. db->setToggleState (true, false);
  60962. break;
  60963. }
  60964. }
  60965. }
  60966. }
  60967. void PreferencesPanel::buttonClicked (Button*)
  60968. {
  60969. for (int i = 0; i < getNumChildComponents(); ++i)
  60970. {
  60971. DrawableButton* db = dynamic_cast <DrawableButton*> (getChildComponent (i));
  60972. if (db != 0 && db->getToggleState())
  60973. {
  60974. setCurrentPage (db->getName());
  60975. break;
  60976. }
  60977. }
  60978. }
  60979. END_JUCE_NAMESPACE
  60980. /********* End of inlined file: juce_PreferencesPanel.cpp *********/
  60981. /********* Start of inlined file: juce_SystemTrayIconComponent.cpp *********/
  60982. #if JUCE_WINDOWS || JUCE_LINUX
  60983. BEGIN_JUCE_NAMESPACE
  60984. SystemTrayIconComponent::SystemTrayIconComponent()
  60985. {
  60986. addToDesktop (0);
  60987. }
  60988. SystemTrayIconComponent::~SystemTrayIconComponent()
  60989. {
  60990. }
  60991. END_JUCE_NAMESPACE
  60992. #endif
  60993. /********* End of inlined file: juce_SystemTrayIconComponent.cpp *********/
  60994. /********* Start of inlined file: juce_AlertWindow.cpp *********/
  60995. BEGIN_JUCE_NAMESPACE
  60996. static const int titleH = 24;
  60997. static const int iconWidth = 80;
  60998. class AlertWindowTextEditor : public TextEditor
  60999. {
  61000. public:
  61001. static const tchar passwordChar;
  61002. AlertWindowTextEditor (const String& name, const bool isPasswordBox)
  61003. : TextEditor (name, isPasswordBox ? passwordChar : 0)
  61004. {
  61005. setSelectAllWhenFocused (true);
  61006. }
  61007. ~AlertWindowTextEditor()
  61008. {
  61009. }
  61010. void returnPressed()
  61011. {
  61012. // pass these up the component hierarchy to be trigger the buttons
  61013. getParentComponent()->keyPressed (KeyPress (KeyPress::returnKey, 0, T('\n')));
  61014. }
  61015. void escapePressed()
  61016. {
  61017. // pass these up the component hierarchy to be trigger the buttons
  61018. getParentComponent()->keyPressed (KeyPress (KeyPress::escapeKey, 0, 0));
  61019. }
  61020. private:
  61021. AlertWindowTextEditor (const AlertWindowTextEditor&);
  61022. const AlertWindowTextEditor& operator= (const AlertWindowTextEditor&);
  61023. };
  61024. #if JUCE_LINUX
  61025. const tchar AlertWindowTextEditor::passwordChar = 0x2022;
  61026. #else
  61027. const tchar AlertWindowTextEditor::passwordChar = 0x25cf;
  61028. #endif
  61029. AlertWindow::AlertWindow (const String& title,
  61030. const String& message,
  61031. AlertIconType iconType,
  61032. Component* associatedComponent_)
  61033. : TopLevelWindow (title, true),
  61034. alertIconType (iconType),
  61035. associatedComponent (associatedComponent_)
  61036. {
  61037. if (message.isEmpty())
  61038. text = T(" "); // to force an update if the message is empty
  61039. setMessage (message);
  61040. for (int i = Desktop::getInstance().getNumComponents(); --i >= 0;)
  61041. {
  61042. Component* const c = Desktop::getInstance().getComponent (i);
  61043. if (c != 0 && c->isAlwaysOnTop() && c->isShowing())
  61044. {
  61045. setAlwaysOnTop (true);
  61046. break;
  61047. }
  61048. }
  61049. if (JUCEApplication::getInstance() == 0)
  61050. setAlwaysOnTop (true); // for a plugin, make it always-on-top because the host windows are often top-level
  61051. lookAndFeelChanged();
  61052. constrainer.setMinimumOnscreenAmounts (0x10000, 0x10000, 0x10000, 0x10000);
  61053. }
  61054. AlertWindow::~AlertWindow()
  61055. {
  61056. for (int i = customComps.size(); --i >= 0;)
  61057. removeChildComponent ((Component*) customComps[i]);
  61058. deleteAllChildren();
  61059. }
  61060. void AlertWindow::userTriedToCloseWindow()
  61061. {
  61062. exitModalState (0);
  61063. }
  61064. void AlertWindow::setMessage (const String& message)
  61065. {
  61066. const String newMessage (message.substring (0, 2048));
  61067. if (text != newMessage)
  61068. {
  61069. text = newMessage;
  61070. font.setHeight (15.0f);
  61071. Font titleFont (font.getHeight() * 1.1f, Font::bold);
  61072. textLayout.setText (getName() + T("\n\n"), titleFont);
  61073. textLayout.appendText (text, font);
  61074. updateLayout (true);
  61075. repaint();
  61076. }
  61077. }
  61078. void AlertWindow::buttonClicked (Button* button)
  61079. {
  61080. for (int i = 0; i < buttons.size(); i++)
  61081. {
  61082. TextButton* const c = (TextButton*) buttons[i];
  61083. if (button->getName() == c->getName())
  61084. {
  61085. if (c->getParentComponent() != 0)
  61086. c->getParentComponent()->exitModalState (c->getCommandID());
  61087. break;
  61088. }
  61089. }
  61090. }
  61091. void AlertWindow::addButton (const String& name,
  61092. const int returnValue,
  61093. const KeyPress& shortcutKey1,
  61094. const KeyPress& shortcutKey2)
  61095. {
  61096. TextButton* const b = new TextButton (name, String::empty);
  61097. b->setWantsKeyboardFocus (true);
  61098. b->setMouseClickGrabsKeyboardFocus (false);
  61099. b->setCommandToTrigger (0, returnValue, false);
  61100. b->addShortcut (shortcutKey1);
  61101. b->addShortcut (shortcutKey2);
  61102. b->addButtonListener (this);
  61103. b->changeWidthToFitText (getLookAndFeel().getAlertWindowButtonHeight());
  61104. addAndMakeVisible (b, 0);
  61105. buttons.add (b);
  61106. updateLayout (false);
  61107. }
  61108. int AlertWindow::getNumButtons() const
  61109. {
  61110. return buttons.size();
  61111. }
  61112. void AlertWindow::addTextEditor (const String& name,
  61113. const String& initialContents,
  61114. const String& onScreenLabel,
  61115. const bool isPasswordBox)
  61116. {
  61117. AlertWindowTextEditor* const tc = new AlertWindowTextEditor (name, isPasswordBox);
  61118. tc->setColour (TextEditor::outlineColourId, findColour (ComboBox::outlineColourId));
  61119. tc->setFont (font);
  61120. tc->setText (initialContents);
  61121. tc->setCaretPosition (initialContents.length());
  61122. addAndMakeVisible (tc);
  61123. textBoxes.add (tc);
  61124. allComps.add (tc);
  61125. textboxNames.add (onScreenLabel);
  61126. updateLayout (false);
  61127. }
  61128. const String AlertWindow::getTextEditorContents (const String& nameOfTextEditor) const
  61129. {
  61130. for (int i = textBoxes.size(); --i >= 0;)
  61131. if (((TextEditor*)textBoxes[i])->getName() == nameOfTextEditor)
  61132. return ((TextEditor*)textBoxes[i])->getText();
  61133. return String::empty;
  61134. }
  61135. void AlertWindow::addComboBox (const String& name,
  61136. const StringArray& items,
  61137. const String& onScreenLabel)
  61138. {
  61139. ComboBox* const cb = new ComboBox (name);
  61140. for (int i = 0; i < items.size(); ++i)
  61141. cb->addItem (items[i], i + 1);
  61142. addAndMakeVisible (cb);
  61143. cb->setSelectedItemIndex (0);
  61144. comboBoxes.add (cb);
  61145. allComps.add (cb);
  61146. comboBoxNames.add (onScreenLabel);
  61147. updateLayout (false);
  61148. }
  61149. ComboBox* AlertWindow::getComboBoxComponent (const String& nameOfList) const
  61150. {
  61151. for (int i = comboBoxes.size(); --i >= 0;)
  61152. if (((ComboBox*) comboBoxes[i])->getName() == nameOfList)
  61153. return (ComboBox*) comboBoxes[i];
  61154. return 0;
  61155. }
  61156. class AlertTextComp : public TextEditor
  61157. {
  61158. AlertTextComp (const AlertTextComp&);
  61159. const AlertTextComp& operator= (const AlertTextComp&);
  61160. int bestWidth;
  61161. public:
  61162. AlertTextComp (const String& message,
  61163. const Font& font)
  61164. {
  61165. setReadOnly (true);
  61166. setMultiLine (true, true);
  61167. setCaretVisible (false);
  61168. setScrollbarsShown (true);
  61169. lookAndFeelChanged();
  61170. setWantsKeyboardFocus (false);
  61171. setFont (font);
  61172. setText (message, false);
  61173. bestWidth = 2 * (int) sqrt (font.getHeight() * font.getStringWidth (message));
  61174. setColour (TextEditor::backgroundColourId, Colours::transparentBlack);
  61175. setColour (TextEditor::outlineColourId, Colours::transparentBlack);
  61176. setColour (TextEditor::shadowColourId, Colours::transparentBlack);
  61177. }
  61178. ~AlertTextComp()
  61179. {
  61180. }
  61181. int getPreferredWidth() const throw() { return bestWidth; }
  61182. void updateLayout (const int width)
  61183. {
  61184. TextLayout text;
  61185. text.appendText (getText(), getFont());
  61186. text.layout (width - 8, Justification::topLeft, true);
  61187. setSize (width, jmin (width, text.getHeight() + (int) getFont().getHeight()));
  61188. }
  61189. };
  61190. void AlertWindow::addTextBlock (const String& text)
  61191. {
  61192. AlertTextComp* const c = new AlertTextComp (text, font);
  61193. textBlocks.add (c);
  61194. allComps.add (c);
  61195. addAndMakeVisible (c);
  61196. updateLayout (false);
  61197. }
  61198. void AlertWindow::addProgressBarComponent (double& progressValue)
  61199. {
  61200. ProgressBar* const pb = new ProgressBar (progressValue);
  61201. progressBars.add (pb);
  61202. allComps.add (pb);
  61203. addAndMakeVisible (pb);
  61204. updateLayout (false);
  61205. }
  61206. void AlertWindow::addCustomComponent (Component* const component)
  61207. {
  61208. customComps.add (component);
  61209. allComps.add (component);
  61210. addAndMakeVisible (component);
  61211. updateLayout (false);
  61212. }
  61213. int AlertWindow::getNumCustomComponents() const
  61214. {
  61215. return customComps.size();
  61216. }
  61217. Component* AlertWindow::getCustomComponent (const int index) const
  61218. {
  61219. return (Component*) customComps [index];
  61220. }
  61221. Component* AlertWindow::removeCustomComponent (const int index)
  61222. {
  61223. Component* const c = getCustomComponent (index);
  61224. if (c != 0)
  61225. {
  61226. customComps.removeValue (c);
  61227. allComps.removeValue (c);
  61228. removeChildComponent (c);
  61229. updateLayout (false);
  61230. }
  61231. return c;
  61232. }
  61233. void AlertWindow::paint (Graphics& g)
  61234. {
  61235. getLookAndFeel().drawAlertBox (g, *this, textArea, textLayout);
  61236. g.setColour (findColour (textColourId));
  61237. g.setFont (getLookAndFeel().getAlertWindowFont());
  61238. int i;
  61239. for (i = textBoxes.size(); --i >= 0;)
  61240. {
  61241. if (textboxNames[i].isNotEmpty())
  61242. {
  61243. const TextEditor* const te = (TextEditor*) textBoxes[i];
  61244. g.drawFittedText (textboxNames[i],
  61245. te->getX(), te->getY() - 14,
  61246. te->getWidth(), 14,
  61247. Justification::centredLeft, 1);
  61248. }
  61249. }
  61250. for (i = comboBoxNames.size(); --i >= 0;)
  61251. {
  61252. if (comboBoxNames[i].isNotEmpty())
  61253. {
  61254. const ComboBox* const cb = (ComboBox*) comboBoxes[i];
  61255. g.drawFittedText (comboBoxNames[i],
  61256. cb->getX(), cb->getY() - 14,
  61257. cb->getWidth(), 14,
  61258. Justification::centredLeft, 1);
  61259. }
  61260. }
  61261. }
  61262. void AlertWindow::updateLayout (const bool onlyIncreaseSize)
  61263. {
  61264. const int wid = jmax (font.getStringWidth (text),
  61265. font.getStringWidth (getName()));
  61266. const int sw = (int) sqrt (font.getHeight() * wid);
  61267. int w = jmin (300 + sw * 2, (int) (getParentWidth() * 0.7f));
  61268. const int edgeGap = 10;
  61269. int iconSpace;
  61270. if (alertIconType == NoIcon)
  61271. {
  61272. textLayout.layout (w, Justification::horizontallyCentred, true);
  61273. iconSpace = 0;
  61274. }
  61275. else
  61276. {
  61277. textLayout.layout (w, Justification::left, true);
  61278. iconSpace = iconWidth;
  61279. }
  61280. w = jmax (350, textLayout.getWidth() + iconSpace + edgeGap * 4);
  61281. w = jmin (w, (int) (getParentWidth() * 0.7f));
  61282. const int textLayoutH = textLayout.getHeight();
  61283. const int textBottom = 16 + titleH + textLayoutH;
  61284. int h = textBottom;
  61285. int buttonW = 40;
  61286. int i;
  61287. for (i = 0; i < buttons.size(); ++i)
  61288. buttonW += 16 + ((const TextButton*) buttons[i])->getWidth();
  61289. w = jmax (buttonW, w);
  61290. h += (textBoxes.size() + comboBoxes.size() + progressBars.size()) * 50;
  61291. if (buttons.size() > 0)
  61292. h += 20 + ((TextButton*) buttons[0])->getHeight();
  61293. for (i = customComps.size(); --i >= 0;)
  61294. {
  61295. w = jmax (w, ((Component*) customComps[i])->getWidth() + 40);
  61296. h += 10 + ((Component*) customComps[i])->getHeight();
  61297. }
  61298. for (i = textBlocks.size(); --i >= 0;)
  61299. {
  61300. const AlertTextComp* const ac = (AlertTextComp*) textBlocks[i];
  61301. w = jmax (w, ac->getPreferredWidth());
  61302. }
  61303. w = jmin (w, (int) (getParentWidth() * 0.7f));
  61304. for (i = textBlocks.size(); --i >= 0;)
  61305. {
  61306. AlertTextComp* const ac = (AlertTextComp*) textBlocks[i];
  61307. ac->updateLayout ((int) (w * 0.8f));
  61308. h += ac->getHeight() + 10;
  61309. }
  61310. h = jmin (getParentHeight() - 50, h);
  61311. if (onlyIncreaseSize)
  61312. {
  61313. w = jmax (w, getWidth());
  61314. h = jmax (h, getHeight());
  61315. }
  61316. if (! isVisible())
  61317. {
  61318. centreAroundComponent (associatedComponent, w, h);
  61319. }
  61320. else
  61321. {
  61322. const int cx = getX() + getWidth() / 2;
  61323. const int cy = getY() + getHeight() / 2;
  61324. setBounds (cx - w / 2,
  61325. cy - h / 2,
  61326. w, h);
  61327. }
  61328. textArea.setBounds (edgeGap, edgeGap, w - (edgeGap * 2), h - edgeGap);
  61329. const int spacer = 16;
  61330. int totalWidth = -spacer;
  61331. for (i = buttons.size(); --i >= 0;)
  61332. totalWidth += ((TextButton*) buttons[i])->getWidth() + spacer;
  61333. int x = (w - totalWidth) / 2;
  61334. int y = (int) (getHeight() * 0.95f);
  61335. for (i = 0; i < buttons.size(); ++i)
  61336. {
  61337. TextButton* const c = (TextButton*) buttons[i];
  61338. int ny = proportionOfHeight (0.95f) - c->getHeight();
  61339. c->setTopLeftPosition (x, ny);
  61340. if (ny < y)
  61341. y = ny;
  61342. x += c->getWidth() + spacer;
  61343. c->toFront (false);
  61344. }
  61345. y = textBottom;
  61346. for (i = 0; i < allComps.size(); ++i)
  61347. {
  61348. Component* const c = (Component*) allComps[i];
  61349. const int h = 22;
  61350. const int comboIndex = comboBoxes.indexOf (c);
  61351. if (comboIndex >= 0 && comboBoxNames [comboIndex].isNotEmpty())
  61352. y += 18;
  61353. const int tbIndex = textBoxes.indexOf (c);
  61354. if (tbIndex >= 0 && textboxNames[tbIndex].isNotEmpty())
  61355. y += 18;
  61356. if (customComps.contains (c) || textBlocks.contains (c))
  61357. {
  61358. c->setTopLeftPosition ((getWidth() - c->getWidth()) / 2, y);
  61359. y += c->getHeight() + 10;
  61360. }
  61361. else
  61362. {
  61363. c->setBounds (proportionOfWidth (0.1f), y, proportionOfWidth (0.8f), h);
  61364. y += h + 10;
  61365. }
  61366. }
  61367. setWantsKeyboardFocus (getNumChildComponents() == 0);
  61368. }
  61369. bool AlertWindow::containsAnyExtraComponents() const
  61370. {
  61371. return textBoxes.size()
  61372. + comboBoxes.size()
  61373. + progressBars.size()
  61374. + customComps.size() > 0;
  61375. }
  61376. void AlertWindow::mouseDown (const MouseEvent&)
  61377. {
  61378. dragger.startDraggingComponent (this, &constrainer);
  61379. }
  61380. void AlertWindow::mouseDrag (const MouseEvent& e)
  61381. {
  61382. dragger.dragComponent (this, e);
  61383. }
  61384. bool AlertWindow::keyPressed (const KeyPress& key)
  61385. {
  61386. for (int i = buttons.size(); --i >= 0;)
  61387. {
  61388. TextButton* const b = (TextButton*) buttons[i];
  61389. if (b->isRegisteredForShortcut (key))
  61390. {
  61391. b->triggerClick();
  61392. return true;
  61393. }
  61394. }
  61395. if (key.isKeyCode (KeyPress::escapeKey) && buttons.size() == 0)
  61396. {
  61397. exitModalState (0);
  61398. return true;
  61399. }
  61400. else if (key.isKeyCode (KeyPress::returnKey) && buttons.size() == 1)
  61401. {
  61402. ((TextButton*) buttons.getFirst())->triggerClick();
  61403. return true;
  61404. }
  61405. return false;
  61406. }
  61407. void AlertWindow::lookAndFeelChanged()
  61408. {
  61409. const int flags = getLookAndFeel().getAlertBoxWindowFlags();
  61410. setUsingNativeTitleBar ((flags & ComponentPeer::windowHasTitleBar) != 0);
  61411. setDropShadowEnabled (isOpaque() && (flags & ComponentPeer::windowHasDropShadow) != 0);
  61412. }
  61413. int AlertWindow::getDesktopWindowStyleFlags() const
  61414. {
  61415. return getLookAndFeel().getAlertBoxWindowFlags();
  61416. }
  61417. struct AlertWindowInfo
  61418. {
  61419. String title, message, button1, button2, button3;
  61420. AlertWindow::AlertIconType iconType;
  61421. int numButtons;
  61422. Component* associatedComponent;
  61423. int run() const
  61424. {
  61425. return (int) (pointer_sized_int)
  61426. MessageManager::getInstance()->callFunctionOnMessageThread (showCallback, (void*) this);
  61427. }
  61428. private:
  61429. int show() const
  61430. {
  61431. jassert (associatedComponent == 0 || associatedComponent->isValidComponent()); // has your comp been deleted?
  61432. LookAndFeel& lf = associatedComponent->isValidComponent() ? associatedComponent->getLookAndFeel()
  61433. : LookAndFeel::getDefaultLookAndFeel();
  61434. ScopedPointer <Component> alertBox (lf.createAlertWindow (title, message, button1, button2, button3,
  61435. iconType, numButtons, associatedComponent));
  61436. jassert (alertBox != 0); // you have to return one of these!
  61437. return alertBox->runModalLoop();
  61438. }
  61439. static void* showCallback (void* userData)
  61440. {
  61441. return (void*) (pointer_sized_int) ((const AlertWindowInfo*) userData)->show();
  61442. }
  61443. };
  61444. void AlertWindow::showMessageBox (AlertIconType iconType,
  61445. const String& title,
  61446. const String& message,
  61447. const String& buttonText,
  61448. Component* associatedComponent)
  61449. {
  61450. AlertWindowInfo info;
  61451. info.title = title;
  61452. info.message = message;
  61453. info.button1 = buttonText.isEmpty() ? TRANS("ok") : buttonText;
  61454. info.iconType = iconType;
  61455. info.numButtons = 1;
  61456. info.associatedComponent = associatedComponent;
  61457. info.run();
  61458. }
  61459. bool AlertWindow::showOkCancelBox (AlertIconType iconType,
  61460. const String& title,
  61461. const String& message,
  61462. const String& button1Text,
  61463. const String& button2Text,
  61464. Component* associatedComponent)
  61465. {
  61466. AlertWindowInfo info;
  61467. info.title = title;
  61468. info.message = message;
  61469. info.button1 = button1Text.isEmpty() ? TRANS("ok") : button1Text;
  61470. info.button2 = button2Text.isEmpty() ? TRANS("cancel") : button2Text;
  61471. info.iconType = iconType;
  61472. info.numButtons = 2;
  61473. info.associatedComponent = associatedComponent;
  61474. return info.run() != 0;
  61475. }
  61476. int AlertWindow::showYesNoCancelBox (AlertIconType iconType,
  61477. const String& title,
  61478. const String& message,
  61479. const String& button1Text,
  61480. const String& button2Text,
  61481. const String& button3Text,
  61482. Component* associatedComponent)
  61483. {
  61484. AlertWindowInfo info;
  61485. info.title = title;
  61486. info.message = message;
  61487. info.button1 = button1Text.isEmpty() ? TRANS("yes") : button1Text;
  61488. info.button2 = button2Text.isEmpty() ? TRANS("no") : button2Text;
  61489. info.button3 = button3Text.isEmpty() ? TRANS("cancel") : button3Text;
  61490. info.iconType = iconType;
  61491. info.numButtons = 3;
  61492. info.associatedComponent = associatedComponent;
  61493. return info.run();
  61494. }
  61495. END_JUCE_NAMESPACE
  61496. /********* End of inlined file: juce_AlertWindow.cpp *********/
  61497. /********* Start of inlined file: juce_ComponentPeer.cpp *********/
  61498. BEGIN_JUCE_NAMESPACE
  61499. //#define JUCE_ENABLE_REPAINT_DEBUGGING 1
  61500. // these are over in juce_component.cpp
  61501. extern int64 juce_recentMouseDownTimes[4];
  61502. extern int juce_recentMouseDownX [4];
  61503. extern int juce_recentMouseDownY [4];
  61504. extern Component* juce_recentMouseDownComponent [4];
  61505. extern int juce_LastMousePosX;
  61506. extern int juce_LastMousePosY;
  61507. extern int juce_MouseClickCounter;
  61508. extern bool juce_MouseHasMovedSignificantlySincePressed;
  61509. static const int fakeMouseMoveMessage = 0x7fff00ff;
  61510. static VoidArray heavyweightPeers;
  61511. ComponentPeer::ComponentPeer (Component* const component_,
  61512. const int styleFlags_) throw()
  61513. : component (component_),
  61514. styleFlags (styleFlags_),
  61515. lastPaintTime (0),
  61516. constrainer (0),
  61517. lastFocusedComponent (0),
  61518. lastDragAndDropCompUnderMouse (0),
  61519. fakeMouseMessageSent (false),
  61520. isWindowMinimised (false)
  61521. {
  61522. heavyweightPeers.add (this);
  61523. }
  61524. ComponentPeer::~ComponentPeer()
  61525. {
  61526. heavyweightPeers.removeValue (this);
  61527. Desktop::getInstance().triggerFocusCallback();
  61528. }
  61529. int ComponentPeer::getNumPeers() throw()
  61530. {
  61531. return heavyweightPeers.size();
  61532. }
  61533. ComponentPeer* ComponentPeer::getPeer (const int index) throw()
  61534. {
  61535. return (ComponentPeer*) heavyweightPeers [index];
  61536. }
  61537. ComponentPeer* ComponentPeer::getPeerFor (const Component* const component) throw()
  61538. {
  61539. for (int i = heavyweightPeers.size(); --i >= 0;)
  61540. {
  61541. ComponentPeer* const peer = (ComponentPeer*) heavyweightPeers.getUnchecked(i);
  61542. if (peer->getComponent() == component)
  61543. return peer;
  61544. }
  61545. return 0;
  61546. }
  61547. bool ComponentPeer::isValidPeer (const ComponentPeer* const peer) throw()
  61548. {
  61549. return heavyweightPeers.contains (const_cast <ComponentPeer*> (peer));
  61550. }
  61551. void ComponentPeer::updateCurrentModifiers() throw()
  61552. {
  61553. ModifierKeys::updateCurrentModifiers();
  61554. }
  61555. void ComponentPeer::handleMouseEnter (int x, int y, const int64 time)
  61556. {
  61557. jassert (component->isValidComponent());
  61558. updateCurrentModifiers();
  61559. Component* c = component->getComponentAt (x, y);
  61560. const ComponentDeletionWatcher deletionChecker (component);
  61561. if (c != Component::componentUnderMouse && Component::componentUnderMouse != 0)
  61562. {
  61563. jassert (Component::componentUnderMouse->isValidComponent());
  61564. const int oldX = x;
  61565. const int oldY = y;
  61566. component->relativePositionToOtherComponent (Component::componentUnderMouse, x, y);
  61567. Component::componentUnderMouse->internalMouseExit (x, y, time);
  61568. Component::componentUnderMouse = 0;
  61569. if (deletionChecker.hasBeenDeleted())
  61570. return;
  61571. c = component->getComponentAt (oldX, oldY);
  61572. }
  61573. Component::componentUnderMouse = c;
  61574. if (Component::componentUnderMouse != 0)
  61575. {
  61576. component->relativePositionToOtherComponent (Component::componentUnderMouse, x, y);
  61577. Component::componentUnderMouse->internalMouseEnter (x, y, time);
  61578. }
  61579. }
  61580. void ComponentPeer::handleMouseMove (int x, int y, const int64 time)
  61581. {
  61582. jassert (component->isValidComponent());
  61583. updateCurrentModifiers();
  61584. fakeMouseMessageSent = false;
  61585. const ComponentDeletionWatcher deletionChecker (component);
  61586. Component* c = component->getComponentAt (x, y);
  61587. if (c != Component::componentUnderMouse)
  61588. {
  61589. const int oldX = x;
  61590. const int oldY = y;
  61591. if (Component::componentUnderMouse != 0)
  61592. {
  61593. component->relativePositionToOtherComponent (Component::componentUnderMouse, x, y);
  61594. Component::componentUnderMouse->internalMouseExit (x, y, time);
  61595. x = oldX;
  61596. y = oldY;
  61597. Component::componentUnderMouse = 0;
  61598. if (deletionChecker.hasBeenDeleted())
  61599. return; // if this window has just been deleted..
  61600. c = component->getComponentAt (x, y);
  61601. }
  61602. Component::componentUnderMouse = c;
  61603. if (c != 0)
  61604. {
  61605. component->relativePositionToOtherComponent (c, x, y);
  61606. c->internalMouseEnter (x, y, time);
  61607. x = oldX;
  61608. y = oldY;
  61609. if (deletionChecker.hasBeenDeleted())
  61610. return; // if this window has just been deleted..
  61611. }
  61612. }
  61613. if (Component::componentUnderMouse != 0)
  61614. {
  61615. component->relativePositionToOtherComponent (Component::componentUnderMouse, x, y);
  61616. Component::componentUnderMouse->internalMouseMove (x, y, time);
  61617. }
  61618. }
  61619. void ComponentPeer::handleMouseDown (int x, int y, const int64 time)
  61620. {
  61621. ++juce_MouseClickCounter;
  61622. updateCurrentModifiers();
  61623. int numMouseButtonsDown = 0;
  61624. if (ModifierKeys::getCurrentModifiers().isLeftButtonDown())
  61625. ++numMouseButtonsDown;
  61626. if (ModifierKeys::getCurrentModifiers().isRightButtonDown())
  61627. ++numMouseButtonsDown;
  61628. if (ModifierKeys::getCurrentModifiers().isMiddleButtonDown())
  61629. ++numMouseButtonsDown;
  61630. if (numMouseButtonsDown == 1)
  61631. {
  61632. Component::componentUnderMouse = component->getComponentAt (x, y);
  61633. if (Component::componentUnderMouse != 0)
  61634. {
  61635. // can't set these in the mouseDownInt() method, because it's re-entrant, so do it here..
  61636. for (int i = numElementsInArray (juce_recentMouseDownTimes); --i > 0;)
  61637. {
  61638. juce_recentMouseDownTimes [i] = juce_recentMouseDownTimes [i - 1];
  61639. juce_recentMouseDownX [i] = juce_recentMouseDownX [i - 1];
  61640. juce_recentMouseDownY [i] = juce_recentMouseDownY [i - 1];
  61641. juce_recentMouseDownComponent [i] = juce_recentMouseDownComponent [i - 1];
  61642. }
  61643. juce_recentMouseDownTimes[0] = time;
  61644. juce_recentMouseDownX[0] = x;
  61645. juce_recentMouseDownY[0] = y;
  61646. juce_recentMouseDownComponent[0] = Component::componentUnderMouse;
  61647. relativePositionToGlobal (juce_recentMouseDownX[0], juce_recentMouseDownY[0]);
  61648. juce_MouseHasMovedSignificantlySincePressed = false;
  61649. component->relativePositionToOtherComponent (Component::componentUnderMouse, x, y);
  61650. Component::componentUnderMouse->internalMouseDown (x, y);
  61651. }
  61652. }
  61653. }
  61654. void ComponentPeer::handleMouseDrag (int x, int y, const int64 time)
  61655. {
  61656. updateCurrentModifiers();
  61657. if (Component::componentUnderMouse != 0)
  61658. {
  61659. component->relativePositionToOtherComponent (Component::componentUnderMouse, x, y);
  61660. Component::componentUnderMouse->internalMouseDrag (x, y, time);
  61661. }
  61662. }
  61663. void ComponentPeer::handleMouseUp (const int oldModifiers, int x, int y, const int64 time)
  61664. {
  61665. updateCurrentModifiers();
  61666. int numMouseButtonsDown = 0;
  61667. if ((oldModifiers & ModifierKeys::leftButtonModifier) != 0)
  61668. ++numMouseButtonsDown;
  61669. if ((oldModifiers & ModifierKeys::rightButtonModifier) != 0)
  61670. ++numMouseButtonsDown;
  61671. if ((oldModifiers & ModifierKeys::middleButtonModifier) != 0)
  61672. ++numMouseButtonsDown;
  61673. if (numMouseButtonsDown == 1)
  61674. {
  61675. const ComponentDeletionWatcher deletionChecker (component);
  61676. Component* c = component->getComponentAt (x, y);
  61677. if (c != Component::componentUnderMouse)
  61678. {
  61679. const int oldX = x;
  61680. const int oldY = y;
  61681. if (Component::componentUnderMouse != 0)
  61682. {
  61683. component->relativePositionToOtherComponent (Component::componentUnderMouse, x, y);
  61684. Component::componentUnderMouse->internalMouseUp (oldModifiers, x, y, time);
  61685. x = oldX;
  61686. y = oldY;
  61687. if (Component::componentUnderMouse != 0)
  61688. Component::componentUnderMouse->internalMouseExit (x, y, time);
  61689. if (deletionChecker.hasBeenDeleted())
  61690. return;
  61691. c = component->getComponentAt (oldX, oldY);
  61692. }
  61693. Component::componentUnderMouse = c;
  61694. if (Component::componentUnderMouse != 0)
  61695. {
  61696. component->relativePositionToOtherComponent (Component::componentUnderMouse, x, y);
  61697. Component::componentUnderMouse->internalMouseEnter (x, y, time);
  61698. }
  61699. }
  61700. else
  61701. {
  61702. if (Component::componentUnderMouse != 0)
  61703. {
  61704. component->relativePositionToOtherComponent (Component::componentUnderMouse, x, y);
  61705. Component::componentUnderMouse->internalMouseUp (oldModifiers, x, y, time);
  61706. }
  61707. }
  61708. }
  61709. }
  61710. void ComponentPeer::handleMouseExit (int x, int y, const int64 time)
  61711. {
  61712. jassert (component->isValidComponent());
  61713. updateCurrentModifiers();
  61714. if (Component::componentUnderMouse != 0)
  61715. {
  61716. component->relativePositionToOtherComponent (Component::componentUnderMouse, x, y);
  61717. Component::componentUnderMouse->internalMouseExit (x, y, time);
  61718. Component::componentUnderMouse = 0;
  61719. }
  61720. }
  61721. void ComponentPeer::handleMouseWheel (const int amountX, const int amountY, const int64 time)
  61722. {
  61723. updateCurrentModifiers();
  61724. if (Component::componentUnderMouse != 0)
  61725. Component::componentUnderMouse->internalMouseWheel (amountX, amountY, time);
  61726. }
  61727. void ComponentPeer::sendFakeMouseMove() throw()
  61728. {
  61729. if ((! fakeMouseMessageSent)
  61730. && component->flags.hasHeavyweightPeerFlag
  61731. && ! ModifierKeys::getCurrentModifiers().isAnyMouseButtonDown())
  61732. {
  61733. if (! isMinimised())
  61734. {
  61735. int realX, realY, realW, realH;
  61736. getBounds (realX, realY, realW, realH);
  61737. component->bounds_.setBounds (realX, realY, realW, realH);
  61738. }
  61739. int x, y;
  61740. component->getMouseXYRelative (x, y);
  61741. if (((unsigned int) x) < (unsigned int) component->getWidth()
  61742. && ((unsigned int) y) < (unsigned int) component->getHeight()
  61743. && contains (x, y, false))
  61744. {
  61745. postMessage (new Message (fakeMouseMoveMessage, x, y, 0));
  61746. }
  61747. fakeMouseMessageSent = true;
  61748. }
  61749. }
  61750. void ComponentPeer::handleMessage (const Message& message)
  61751. {
  61752. if (message.intParameter1 == fakeMouseMoveMessage)
  61753. {
  61754. if (! ModifierKeys::getCurrentModifiers().isAnyMouseButtonDown())
  61755. handleMouseMove (message.intParameter2,
  61756. message.intParameter3,
  61757. Time::currentTimeMillis());
  61758. }
  61759. }
  61760. void ComponentPeer::handlePaint (LowLevelGraphicsContext& contextToPaintTo)
  61761. {
  61762. Graphics g (&contextToPaintTo);
  61763. #if JUCE_ENABLE_REPAINT_DEBUGGING
  61764. g.saveState();
  61765. #endif
  61766. JUCE_TRY
  61767. {
  61768. component->paintEntireComponent (g);
  61769. }
  61770. JUCE_CATCH_EXCEPTION
  61771. #if JUCE_ENABLE_REPAINT_DEBUGGING
  61772. // enabling this code will fill all areas that get repainted with a colour overlay, to show
  61773. // clearly when things are being repainted.
  61774. {
  61775. g.restoreState();
  61776. g.fillAll (Colour ((uint8) Random::getSystemRandom().nextInt (255),
  61777. (uint8) Random::getSystemRandom().nextInt (255),
  61778. (uint8) Random::getSystemRandom().nextInt (255),
  61779. (uint8) 0x50));
  61780. }
  61781. #endif
  61782. }
  61783. bool ComponentPeer::handleKeyPress (const int keyCode,
  61784. const juce_wchar textCharacter)
  61785. {
  61786. updateCurrentModifiers();
  61787. Component* target = Component::currentlyFocusedComponent->isValidComponent()
  61788. ? Component::currentlyFocusedComponent
  61789. : component;
  61790. if (target->isCurrentlyBlockedByAnotherModalComponent())
  61791. {
  61792. Component* const currentModalComp = Component::getCurrentlyModalComponent();
  61793. if (currentModalComp != 0)
  61794. target = currentModalComp;
  61795. }
  61796. const KeyPress keyInfo (keyCode,
  61797. ModifierKeys::getCurrentModifiers().getRawFlags()
  61798. & ModifierKeys::allKeyboardModifiers,
  61799. textCharacter);
  61800. bool keyWasUsed = false;
  61801. while (target != 0)
  61802. {
  61803. const ComponentDeletionWatcher deletionChecker (target);
  61804. if (target->keyListeners_ != 0)
  61805. {
  61806. for (int i = target->keyListeners_->size(); --i >= 0;)
  61807. {
  61808. keyWasUsed = ((KeyListener*) target->keyListeners_->getUnchecked(i))->keyPressed (keyInfo, target);
  61809. if (keyWasUsed || deletionChecker.hasBeenDeleted())
  61810. return keyWasUsed;
  61811. i = jmin (i, target->keyListeners_->size());
  61812. }
  61813. }
  61814. keyWasUsed = target->keyPressed (keyInfo);
  61815. if (keyWasUsed || deletionChecker.hasBeenDeleted())
  61816. break;
  61817. if (keyInfo.isKeyCode (KeyPress::tabKey) && Component::getCurrentlyFocusedComponent() != 0)
  61818. {
  61819. Component* const currentlyFocused = Component::getCurrentlyFocusedComponent();
  61820. currentlyFocused->moveKeyboardFocusToSibling (! keyInfo.getModifiers().isShiftDown());
  61821. keyWasUsed = (currentlyFocused != Component::getCurrentlyFocusedComponent());
  61822. break;
  61823. }
  61824. target = target->parentComponent_;
  61825. }
  61826. return keyWasUsed;
  61827. }
  61828. bool ComponentPeer::handleKeyUpOrDown (const bool isKeyDown)
  61829. {
  61830. updateCurrentModifiers();
  61831. Component* target = Component::currentlyFocusedComponent->isValidComponent()
  61832. ? Component::currentlyFocusedComponent
  61833. : component;
  61834. if (target->isCurrentlyBlockedByAnotherModalComponent())
  61835. {
  61836. Component* const currentModalComp = Component::getCurrentlyModalComponent();
  61837. if (currentModalComp != 0)
  61838. target = currentModalComp;
  61839. }
  61840. bool keyWasUsed = false;
  61841. while (target != 0)
  61842. {
  61843. const ComponentDeletionWatcher deletionChecker (target);
  61844. keyWasUsed = target->keyStateChanged (isKeyDown);
  61845. if (keyWasUsed || deletionChecker.hasBeenDeleted())
  61846. break;
  61847. if (target->keyListeners_ != 0)
  61848. {
  61849. for (int i = target->keyListeners_->size(); --i >= 0;)
  61850. {
  61851. keyWasUsed = ((KeyListener*) target->keyListeners_->getUnchecked(i))->keyStateChanged (isKeyDown, target);
  61852. if (keyWasUsed || deletionChecker.hasBeenDeleted())
  61853. return keyWasUsed;
  61854. i = jmin (i, target->keyListeners_->size());
  61855. }
  61856. }
  61857. target = target->parentComponent_;
  61858. }
  61859. return keyWasUsed;
  61860. }
  61861. void ComponentPeer::handleModifierKeysChange()
  61862. {
  61863. updateCurrentModifiers();
  61864. Component* target = Component::getComponentUnderMouse();
  61865. if (target == 0)
  61866. target = Component::getCurrentlyFocusedComponent();
  61867. if (target == 0)
  61868. target = component;
  61869. if (target->isValidComponent())
  61870. target->internalModifierKeysChanged();
  61871. }
  61872. void ComponentPeer::handleBroughtToFront()
  61873. {
  61874. updateCurrentModifiers();
  61875. if (component != 0)
  61876. component->internalBroughtToFront();
  61877. }
  61878. void ComponentPeer::setConstrainer (ComponentBoundsConstrainer* const newConstrainer) throw()
  61879. {
  61880. constrainer = newConstrainer;
  61881. }
  61882. void ComponentPeer::handleMovedOrResized()
  61883. {
  61884. jassert (component->isValidComponent());
  61885. updateCurrentModifiers();
  61886. const bool nowMinimised = isMinimised();
  61887. if (component->flags.hasHeavyweightPeerFlag && ! nowMinimised)
  61888. {
  61889. const ComponentDeletionWatcher deletionChecker (component);
  61890. int realX, realY, realW, realH;
  61891. getBounds (realX, realY, realW, realH);
  61892. const bool wasMoved = (component->getX() != realX || component->getY() != realY);
  61893. const bool wasResized = (component->getWidth() != realW || component->getHeight() != realH);
  61894. if (wasMoved || wasResized)
  61895. {
  61896. component->bounds_.setBounds (realX, realY, realW, realH);
  61897. if (wasResized)
  61898. component->repaint();
  61899. component->sendMovedResizedMessages (wasMoved, wasResized);
  61900. if (deletionChecker.hasBeenDeleted())
  61901. return;
  61902. }
  61903. }
  61904. if (isWindowMinimised != nowMinimised)
  61905. {
  61906. isWindowMinimised = nowMinimised;
  61907. component->minimisationStateChanged (nowMinimised);
  61908. component->sendVisibilityChangeMessage();
  61909. }
  61910. if (! isFullScreen())
  61911. lastNonFullscreenBounds = component->getBounds();
  61912. }
  61913. void ComponentPeer::handleFocusGain()
  61914. {
  61915. updateCurrentModifiers();
  61916. if (component->isParentOf (lastFocusedComponent))
  61917. {
  61918. Component::currentlyFocusedComponent = lastFocusedComponent;
  61919. Desktop::getInstance().triggerFocusCallback();
  61920. lastFocusedComponent->internalFocusGain (Component::focusChangedDirectly);
  61921. }
  61922. else
  61923. {
  61924. if (! component->isCurrentlyBlockedByAnotherModalComponent())
  61925. component->grabKeyboardFocus();
  61926. else
  61927. Component::bringModalComponentToFront();
  61928. }
  61929. }
  61930. void ComponentPeer::handleFocusLoss()
  61931. {
  61932. updateCurrentModifiers();
  61933. if (component->hasKeyboardFocus (true))
  61934. {
  61935. lastFocusedComponent = Component::currentlyFocusedComponent;
  61936. if (lastFocusedComponent != 0)
  61937. {
  61938. Component::currentlyFocusedComponent = 0;
  61939. Desktop::getInstance().triggerFocusCallback();
  61940. lastFocusedComponent->internalFocusLoss (Component::focusChangedByMouseClick);
  61941. }
  61942. }
  61943. }
  61944. Component* ComponentPeer::getLastFocusedSubcomponent() const throw()
  61945. {
  61946. return (component->isParentOf (lastFocusedComponent) && lastFocusedComponent->isShowing())
  61947. ? lastFocusedComponent
  61948. : component;
  61949. }
  61950. void ComponentPeer::handleScreenSizeChange()
  61951. {
  61952. updateCurrentModifiers();
  61953. component->parentSizeChanged();
  61954. handleMovedOrResized();
  61955. }
  61956. void ComponentPeer::setNonFullScreenBounds (const Rectangle& newBounds) throw()
  61957. {
  61958. lastNonFullscreenBounds = newBounds;
  61959. }
  61960. const Rectangle& ComponentPeer::getNonFullScreenBounds() const throw()
  61961. {
  61962. return lastNonFullscreenBounds;
  61963. }
  61964. static FileDragAndDropTarget* findDragAndDropTarget (Component* c,
  61965. const StringArray& files,
  61966. FileDragAndDropTarget* const lastOne)
  61967. {
  61968. while (c != 0)
  61969. {
  61970. FileDragAndDropTarget* const t = dynamic_cast <FileDragAndDropTarget*> (c);
  61971. if (t != 0 && (t == lastOne || t->isInterestedInFileDrag (files)))
  61972. return t;
  61973. c = c->getParentComponent();
  61974. }
  61975. return 0;
  61976. }
  61977. void ComponentPeer::handleFileDragMove (const StringArray& files, int x, int y)
  61978. {
  61979. updateCurrentModifiers();
  61980. FileDragAndDropTarget* lastTarget = 0;
  61981. if (dragAndDropTargetComponent != 0 && ! dragAndDropTargetComponent->hasBeenDeleted())
  61982. lastTarget = const_cast <FileDragAndDropTarget*> (dynamic_cast <const FileDragAndDropTarget*> (dragAndDropTargetComponent->getComponent()));
  61983. FileDragAndDropTarget* newTarget = 0;
  61984. Component* const compUnderMouse = component->getComponentAt (x, y);
  61985. if (compUnderMouse != lastDragAndDropCompUnderMouse)
  61986. {
  61987. lastDragAndDropCompUnderMouse = compUnderMouse;
  61988. newTarget = findDragAndDropTarget (compUnderMouse, files, lastTarget);
  61989. if (newTarget != lastTarget)
  61990. {
  61991. if (lastTarget != 0)
  61992. lastTarget->fileDragExit (files);
  61993. dragAndDropTargetComponent = 0;
  61994. if (newTarget != 0)
  61995. {
  61996. Component* const targetComp = dynamic_cast <Component*> (newTarget);
  61997. int mx = x, my = y;
  61998. component->relativePositionToOtherComponent (targetComp, mx, my);
  61999. dragAndDropTargetComponent = new ComponentDeletionWatcher (dynamic_cast <Component*> (newTarget));
  62000. newTarget->fileDragEnter (files, mx, my);
  62001. }
  62002. }
  62003. }
  62004. else
  62005. {
  62006. newTarget = lastTarget;
  62007. }
  62008. if (newTarget != 0)
  62009. {
  62010. Component* const targetComp = dynamic_cast <Component*> (newTarget);
  62011. component->relativePositionToOtherComponent (targetComp, x, y);
  62012. newTarget->fileDragMove (files, x, y);
  62013. }
  62014. }
  62015. void ComponentPeer::handleFileDragExit (const StringArray& files)
  62016. {
  62017. handleFileDragMove (files, -1, -1);
  62018. jassert (dragAndDropTargetComponent == 0);
  62019. lastDragAndDropCompUnderMouse = 0;
  62020. }
  62021. void ComponentPeer::handleFileDragDrop (const StringArray& files, int x, int y)
  62022. {
  62023. handleFileDragMove (files, x, y);
  62024. if (dragAndDropTargetComponent != 0 && ! dragAndDropTargetComponent->hasBeenDeleted())
  62025. {
  62026. FileDragAndDropTarget* const target = const_cast <FileDragAndDropTarget*> (dynamic_cast <const FileDragAndDropTarget*> (dragAndDropTargetComponent->getComponent()));
  62027. dragAndDropTargetComponent = 0;
  62028. lastDragAndDropCompUnderMouse = 0;
  62029. if (target != 0)
  62030. {
  62031. Component* const targetComp = dynamic_cast <Component*> (target);
  62032. if (targetComp->isCurrentlyBlockedByAnotherModalComponent())
  62033. {
  62034. targetComp->internalModalInputAttempt();
  62035. if (targetComp->isCurrentlyBlockedByAnotherModalComponent())
  62036. return;
  62037. }
  62038. component->relativePositionToOtherComponent (targetComp, x, y);
  62039. target->filesDropped (files, x, y);
  62040. }
  62041. }
  62042. }
  62043. void ComponentPeer::handleUserClosingWindow()
  62044. {
  62045. updateCurrentModifiers();
  62046. component->userTriedToCloseWindow();
  62047. }
  62048. void ComponentPeer::bringModalComponentToFront()
  62049. {
  62050. Component::bringModalComponentToFront();
  62051. }
  62052. void ComponentPeer::clearMaskedRegion() throw()
  62053. {
  62054. maskedRegion.clear();
  62055. }
  62056. void ComponentPeer::addMaskedRegion (int x, int y, int w, int h) throw()
  62057. {
  62058. maskedRegion.add (x, y, w, h);
  62059. }
  62060. const StringArray ComponentPeer::getAvailableRenderingEngines() throw()
  62061. {
  62062. StringArray s;
  62063. s.add ("Software Renderer");
  62064. return s;
  62065. }
  62066. int ComponentPeer::getCurrentRenderingEngine() throw()
  62067. {
  62068. return 0;
  62069. }
  62070. void ComponentPeer::setCurrentRenderingEngine (int /*index*/) throw()
  62071. {
  62072. }
  62073. END_JUCE_NAMESPACE
  62074. /********* End of inlined file: juce_ComponentPeer.cpp *********/
  62075. /********* Start of inlined file: juce_DialogWindow.cpp *********/
  62076. BEGIN_JUCE_NAMESPACE
  62077. DialogWindow::DialogWindow (const String& name,
  62078. const Colour& backgroundColour_,
  62079. const bool escapeKeyTriggersCloseButton_,
  62080. const bool addToDesktop_)
  62081. : DocumentWindow (name, backgroundColour_, DocumentWindow::closeButton, addToDesktop_),
  62082. escapeKeyTriggersCloseButton (escapeKeyTriggersCloseButton_)
  62083. {
  62084. }
  62085. DialogWindow::~DialogWindow()
  62086. {
  62087. }
  62088. void DialogWindow::resized()
  62089. {
  62090. DocumentWindow::resized();
  62091. const KeyPress esc (KeyPress::escapeKey, 0, 0);
  62092. if (escapeKeyTriggersCloseButton
  62093. && getCloseButton() != 0
  62094. && ! getCloseButton()->isRegisteredForShortcut (esc))
  62095. {
  62096. getCloseButton()->addShortcut (esc);
  62097. }
  62098. }
  62099. class TempDialogWindow : public DialogWindow
  62100. {
  62101. public:
  62102. TempDialogWindow (const String& title, const Colour& colour, const bool escapeCloses)
  62103. : DialogWindow (title, colour, escapeCloses, true)
  62104. {
  62105. }
  62106. ~TempDialogWindow()
  62107. {
  62108. }
  62109. void closeButtonPressed()
  62110. {
  62111. setVisible (false);
  62112. }
  62113. private:
  62114. TempDialogWindow (const TempDialogWindow&);
  62115. const TempDialogWindow& operator= (const TempDialogWindow&);
  62116. };
  62117. int DialogWindow::showModalDialog (const String& dialogTitle,
  62118. Component* contentComponent,
  62119. Component* componentToCentreAround,
  62120. const Colour& colour,
  62121. const bool escapeKeyTriggersCloseButton,
  62122. const bool shouldBeResizable,
  62123. const bool useBottomRightCornerResizer)
  62124. {
  62125. TempDialogWindow dw (dialogTitle, colour, escapeKeyTriggersCloseButton);
  62126. dw.setContentComponent (contentComponent, true, true);
  62127. dw.centreAroundComponent (componentToCentreAround, dw.getWidth(), dw.getHeight());
  62128. dw.setResizable (shouldBeResizable, useBottomRightCornerResizer);
  62129. const int result = dw.runModalLoop();
  62130. dw.setContentComponent (0, false);
  62131. return result;
  62132. }
  62133. END_JUCE_NAMESPACE
  62134. /********* End of inlined file: juce_DialogWindow.cpp *********/
  62135. /********* Start of inlined file: juce_DocumentWindow.cpp *********/
  62136. BEGIN_JUCE_NAMESPACE
  62137. DocumentWindow::DocumentWindow (const String& title,
  62138. const Colour& backgroundColour,
  62139. const int requiredButtons_,
  62140. const bool addToDesktop_)
  62141. : ResizableWindow (title, backgroundColour, addToDesktop_),
  62142. titleBarHeight (26),
  62143. menuBarHeight (24),
  62144. requiredButtons (requiredButtons_),
  62145. #if JUCE_MAC
  62146. positionTitleBarButtonsOnLeft (true),
  62147. #else
  62148. positionTitleBarButtonsOnLeft (false),
  62149. #endif
  62150. drawTitleTextCentred (true),
  62151. menuBarModel (0)
  62152. {
  62153. setResizeLimits (128, 128, 32768, 32768);
  62154. lookAndFeelChanged();
  62155. }
  62156. DocumentWindow::~DocumentWindow()
  62157. {
  62158. for (int i = numElementsInArray (titleBarButtons); --i >= 0;)
  62159. titleBarButtons[i] = 0;
  62160. menuBar = 0;
  62161. }
  62162. void DocumentWindow::repaintTitleBar()
  62163. {
  62164. const Rectangle titleBarArea (getTitleBarArea());
  62165. repaint (titleBarArea.getX(), titleBarArea.getY(),
  62166. titleBarArea.getWidth(), titleBarArea.getHeight());
  62167. }
  62168. void DocumentWindow::setName (const String& newName)
  62169. {
  62170. if (newName != getName())
  62171. {
  62172. Component::setName (newName);
  62173. repaintTitleBar();
  62174. }
  62175. }
  62176. void DocumentWindow::setIcon (const Image* imageToUse)
  62177. {
  62178. titleBarIcon = imageToUse != 0 ? imageToUse->createCopy() : 0;
  62179. repaintTitleBar();
  62180. }
  62181. void DocumentWindow::setTitleBarHeight (const int newHeight)
  62182. {
  62183. titleBarHeight = newHeight;
  62184. resized();
  62185. repaintTitleBar();
  62186. }
  62187. void DocumentWindow::setTitleBarButtonsRequired (const int requiredButtons_,
  62188. const bool positionTitleBarButtonsOnLeft_)
  62189. {
  62190. requiredButtons = requiredButtons_;
  62191. positionTitleBarButtonsOnLeft = positionTitleBarButtonsOnLeft_;
  62192. lookAndFeelChanged();
  62193. }
  62194. void DocumentWindow::setTitleBarTextCentred (const bool textShouldBeCentred)
  62195. {
  62196. drawTitleTextCentred = textShouldBeCentred;
  62197. repaintTitleBar();
  62198. }
  62199. void DocumentWindow::setMenuBar (MenuBarModel* menuBarModel_,
  62200. const int menuBarHeight_)
  62201. {
  62202. if (menuBarModel != menuBarModel_)
  62203. {
  62204. menuBar = 0;
  62205. menuBarModel = menuBarModel_;
  62206. menuBarHeight = (menuBarHeight_ > 0) ? menuBarHeight_
  62207. : getLookAndFeel().getDefaultMenuBarHeight();
  62208. if (menuBarModel != 0)
  62209. {
  62210. // (call the Component method directly to avoid the assertion in ResizableWindow)
  62211. Component::addAndMakeVisible (menuBar = new MenuBarComponent (menuBarModel));
  62212. menuBar->setEnabled (isActiveWindow());
  62213. }
  62214. resized();
  62215. }
  62216. }
  62217. void DocumentWindow::closeButtonPressed()
  62218. {
  62219. /* If you've got a close button, you have to override this method to get
  62220. rid of your window!
  62221. If the window is just a pop-up, you should override this method and make
  62222. it delete the window in whatever way is appropriate for your app. E.g. you
  62223. might just want to call "delete this".
  62224. If your app is centred around this window such that the whole app should quit when
  62225. the window is closed, then you will probably want to use this method as an opportunity
  62226. to call JUCEApplication::quit(), and leave the window to be deleted later by your
  62227. JUCEApplication::shutdown() method. (Doing it this way means that your window will
  62228. still get cleaned-up if the app is quit by some other means (e.g. a cmd-Q on the mac
  62229. or closing it via the taskbar icon on Windows).
  62230. */
  62231. jassertfalse
  62232. }
  62233. void DocumentWindow::minimiseButtonPressed()
  62234. {
  62235. setMinimised (true);
  62236. }
  62237. void DocumentWindow::maximiseButtonPressed()
  62238. {
  62239. setFullScreen (! isFullScreen());
  62240. }
  62241. void DocumentWindow::paint (Graphics& g)
  62242. {
  62243. ResizableWindow::paint (g);
  62244. if (resizableBorder == 0)
  62245. {
  62246. g.setColour (getBackgroundColour().overlaidWith (Colour (0x80000000)));
  62247. const BorderSize border (getBorderThickness());
  62248. g.fillRect (0, 0, getWidth(), border.getTop());
  62249. g.fillRect (0, border.getTop(), border.getLeft(), getHeight() - border.getTopAndBottom());
  62250. g.fillRect (getWidth() - border.getRight(), border.getTop(), border.getRight(), getHeight() - border.getTopAndBottom());
  62251. g.fillRect (0, getHeight() - border.getBottom(), getWidth(), border.getBottom());
  62252. }
  62253. const Rectangle titleBarArea (getTitleBarArea());
  62254. g.setOrigin (titleBarArea.getX(), titleBarArea.getY());
  62255. g.reduceClipRegion (0, 0, titleBarArea.getWidth(), titleBarArea.getHeight());
  62256. int titleSpaceX1 = 6;
  62257. int titleSpaceX2 = titleBarArea.getWidth() - 6;
  62258. for (int i = 0; i < 3; ++i)
  62259. {
  62260. if (titleBarButtons[i] != 0)
  62261. {
  62262. if (positionTitleBarButtonsOnLeft)
  62263. titleSpaceX1 = jmax (titleSpaceX1, titleBarButtons[i]->getRight() + (getWidth() - titleBarButtons[i]->getRight()) / 8);
  62264. else
  62265. titleSpaceX2 = jmin (titleSpaceX2, titleBarButtons[i]->getX() - (titleBarButtons[i]->getX() / 8));
  62266. }
  62267. }
  62268. getLookAndFeel().drawDocumentWindowTitleBar (*this, g,
  62269. titleBarArea.getWidth(),
  62270. titleBarArea.getHeight(),
  62271. titleSpaceX1,
  62272. jmax (1, titleSpaceX2 - titleSpaceX1),
  62273. titleBarIcon,
  62274. ! drawTitleTextCentred);
  62275. }
  62276. void DocumentWindow::resized()
  62277. {
  62278. ResizableWindow::resized();
  62279. if (titleBarButtons[1] != 0)
  62280. titleBarButtons[1]->setToggleState (isFullScreen(), false);
  62281. const Rectangle titleBarArea (getTitleBarArea());
  62282. getLookAndFeel()
  62283. .positionDocumentWindowButtons (*this,
  62284. titleBarArea.getX(), titleBarArea.getY(),
  62285. titleBarArea.getWidth(), titleBarArea.getHeight(),
  62286. titleBarButtons[0],
  62287. titleBarButtons[1],
  62288. titleBarButtons[2],
  62289. positionTitleBarButtonsOnLeft);
  62290. if (menuBar != 0)
  62291. menuBar->setBounds (titleBarArea.getX(), titleBarArea.getBottom(),
  62292. titleBarArea.getWidth(), menuBarHeight);
  62293. }
  62294. const BorderSize DocumentWindow::getBorderThickness()
  62295. {
  62296. return BorderSize ((isFullScreen() || isUsingNativeTitleBar())
  62297. ? 0 : (resizableBorder != 0 ? 4 : 1));
  62298. }
  62299. const BorderSize DocumentWindow::getContentComponentBorder()
  62300. {
  62301. BorderSize border (getBorderThickness());
  62302. border.setTop (border.getTop()
  62303. + (isUsingNativeTitleBar() ? 0 : titleBarHeight)
  62304. + (menuBar != 0 ? menuBarHeight : 0));
  62305. return border;
  62306. }
  62307. int DocumentWindow::getTitleBarHeight() const
  62308. {
  62309. return isUsingNativeTitleBar() ? 0 : jmin (titleBarHeight, getHeight() - 4);
  62310. }
  62311. const Rectangle DocumentWindow::getTitleBarArea()
  62312. {
  62313. const BorderSize border (getBorderThickness());
  62314. return Rectangle (border.getLeft(), border.getTop(),
  62315. getWidth() - border.getLeftAndRight(),
  62316. getTitleBarHeight());
  62317. }
  62318. Button* DocumentWindow::getCloseButton() const throw()
  62319. {
  62320. return titleBarButtons[2];
  62321. }
  62322. Button* DocumentWindow::getMinimiseButton() const throw()
  62323. {
  62324. return titleBarButtons[0];
  62325. }
  62326. Button* DocumentWindow::getMaximiseButton() const throw()
  62327. {
  62328. return titleBarButtons[1];
  62329. }
  62330. int DocumentWindow::getDesktopWindowStyleFlags() const
  62331. {
  62332. int flags = ResizableWindow::getDesktopWindowStyleFlags();
  62333. if ((requiredButtons & minimiseButton) != 0)
  62334. flags |= ComponentPeer::windowHasMinimiseButton;
  62335. if ((requiredButtons & maximiseButton) != 0)
  62336. flags |= ComponentPeer::windowHasMaximiseButton;
  62337. if ((requiredButtons & closeButton) != 0)
  62338. flags |= ComponentPeer::windowHasCloseButton;
  62339. return flags;
  62340. }
  62341. void DocumentWindow::lookAndFeelChanged()
  62342. {
  62343. int i;
  62344. for (i = numElementsInArray (titleBarButtons); --i >= 0;)
  62345. titleBarButtons[i] = 0;
  62346. if (! isUsingNativeTitleBar())
  62347. {
  62348. titleBarButtons[0] = ((requiredButtons & minimiseButton) != 0)
  62349. ? getLookAndFeel().createDocumentWindowButton (minimiseButton) : 0;
  62350. titleBarButtons[1] = ((requiredButtons & maximiseButton) != 0)
  62351. ? getLookAndFeel().createDocumentWindowButton (maximiseButton) : 0;
  62352. titleBarButtons[2] = ((requiredButtons & closeButton) != 0)
  62353. ? getLookAndFeel().createDocumentWindowButton (closeButton) : 0;
  62354. for (i = 0; i < 3; ++i)
  62355. {
  62356. if (titleBarButtons[i] != 0)
  62357. {
  62358. buttonListener.owner = this;
  62359. titleBarButtons[i]->addButtonListener (&buttonListener);
  62360. titleBarButtons[i]->setWantsKeyboardFocus (false);
  62361. // (call the Component method directly to avoid the assertion in ResizableWindow)
  62362. Component::addAndMakeVisible (titleBarButtons[i]);
  62363. }
  62364. }
  62365. if (getCloseButton() != 0)
  62366. {
  62367. #if JUCE_MAC
  62368. getCloseButton()->addShortcut (KeyPress (T('w'), ModifierKeys::commandModifier, 0));
  62369. #else
  62370. getCloseButton()->addShortcut (KeyPress (KeyPress::F4Key, ModifierKeys::altModifier, 0));
  62371. #endif
  62372. }
  62373. }
  62374. activeWindowStatusChanged();
  62375. ResizableWindow::lookAndFeelChanged();
  62376. }
  62377. void DocumentWindow::parentHierarchyChanged()
  62378. {
  62379. lookAndFeelChanged();
  62380. }
  62381. void DocumentWindow::activeWindowStatusChanged()
  62382. {
  62383. ResizableWindow::activeWindowStatusChanged();
  62384. for (int i = numElementsInArray (titleBarButtons); --i >= 0;)
  62385. if (titleBarButtons[i] != 0)
  62386. titleBarButtons[i]->setEnabled (isActiveWindow());
  62387. if (menuBar != 0)
  62388. menuBar->setEnabled (isActiveWindow());
  62389. }
  62390. void DocumentWindow::mouseDoubleClick (const MouseEvent& e)
  62391. {
  62392. if (getTitleBarArea().contains (e.x, e.y)
  62393. && getMaximiseButton() != 0)
  62394. {
  62395. getMaximiseButton()->triggerClick();
  62396. }
  62397. }
  62398. void DocumentWindow::userTriedToCloseWindow()
  62399. {
  62400. closeButtonPressed();
  62401. }
  62402. DocumentWindow::ButtonListenerProxy::ButtonListenerProxy()
  62403. {
  62404. }
  62405. void DocumentWindow::ButtonListenerProxy::buttonClicked (Button* button)
  62406. {
  62407. if (button == owner->getMinimiseButton())
  62408. {
  62409. owner->minimiseButtonPressed();
  62410. }
  62411. else if (button == owner->getMaximiseButton())
  62412. {
  62413. owner->maximiseButtonPressed();
  62414. }
  62415. else if (button == owner->getCloseButton())
  62416. {
  62417. owner->closeButtonPressed();
  62418. }
  62419. }
  62420. END_JUCE_NAMESPACE
  62421. /********* End of inlined file: juce_DocumentWindow.cpp *********/
  62422. /********* Start of inlined file: juce_ResizableWindow.cpp *********/
  62423. BEGIN_JUCE_NAMESPACE
  62424. ResizableWindow::ResizableWindow (const String& name,
  62425. const bool addToDesktop_)
  62426. : TopLevelWindow (name, addToDesktop_),
  62427. resizeToFitContent (false),
  62428. fullscreen (false),
  62429. lastNonFullScreenPos (50, 50, 256, 256),
  62430. constrainer (0)
  62431. #ifdef JUCE_DEBUG
  62432. , hasBeenResized (false)
  62433. #endif
  62434. {
  62435. defaultConstrainer.setMinimumOnscreenAmounts (0x10000, 16, 24, 16);
  62436. lastNonFullScreenPos.setBounds (50, 50, 256, 256);
  62437. if (addToDesktop_)
  62438. Component::addToDesktop (getDesktopWindowStyleFlags());
  62439. }
  62440. ResizableWindow::ResizableWindow (const String& name,
  62441. const Colour& backgroundColour_,
  62442. const bool addToDesktop_)
  62443. : TopLevelWindow (name, addToDesktop_),
  62444. resizeToFitContent (false),
  62445. fullscreen (false),
  62446. lastNonFullScreenPos (50, 50, 256, 256),
  62447. constrainer (0)
  62448. #ifdef JUCE_DEBUG
  62449. , hasBeenResized (false)
  62450. #endif
  62451. {
  62452. setBackgroundColour (backgroundColour_);
  62453. defaultConstrainer.setMinimumOnscreenAmounts (0x10000, 16, 24, 16);
  62454. if (addToDesktop_)
  62455. Component::addToDesktop (getDesktopWindowStyleFlags());
  62456. }
  62457. ResizableWindow::~ResizableWindow()
  62458. {
  62459. resizableCorner = 0;
  62460. resizableBorder = 0;
  62461. contentComponent = 0;
  62462. // have you been adding your own components directly to this window..? tut tut tut.
  62463. // Read the instructions for using a ResizableWindow!
  62464. jassert (getNumChildComponents() == 0);
  62465. }
  62466. int ResizableWindow::getDesktopWindowStyleFlags() const
  62467. {
  62468. int flags = TopLevelWindow::getDesktopWindowStyleFlags();
  62469. if (isResizable() && (flags & ComponentPeer::windowHasTitleBar) != 0)
  62470. flags |= ComponentPeer::windowIsResizable;
  62471. return flags;
  62472. }
  62473. void ResizableWindow::setContentComponent (Component* const newContentComponent,
  62474. const bool deleteOldOne,
  62475. const bool resizeToFit)
  62476. {
  62477. resizeToFitContent = resizeToFit;
  62478. if (newContentComponent != (Component*) contentComponent)
  62479. {
  62480. if (! deleteOldOne)
  62481. removeChildComponent (contentComponent.release());
  62482. contentComponent = newContentComponent;
  62483. Component::addAndMakeVisible (contentComponent);
  62484. }
  62485. if (resizeToFit)
  62486. childBoundsChanged (contentComponent);
  62487. resized(); // must always be called to position the new content comp
  62488. }
  62489. void ResizableWindow::setContentComponentSize (int width, int height)
  62490. {
  62491. jassert (width > 0 && height > 0); // not a great idea to give it a zero size..
  62492. const BorderSize border (getContentComponentBorder());
  62493. setSize (width + border.getLeftAndRight(),
  62494. height + border.getTopAndBottom());
  62495. }
  62496. const BorderSize ResizableWindow::getBorderThickness()
  62497. {
  62498. return BorderSize (isUsingNativeTitleBar() ? 0 : ((resizableBorder != 0 && ! isFullScreen()) ? 5 : 3));
  62499. }
  62500. const BorderSize ResizableWindow::getContentComponentBorder()
  62501. {
  62502. return getBorderThickness();
  62503. }
  62504. void ResizableWindow::moved()
  62505. {
  62506. updateLastPos();
  62507. }
  62508. void ResizableWindow::visibilityChanged()
  62509. {
  62510. TopLevelWindow::visibilityChanged();
  62511. updateLastPos();
  62512. }
  62513. void ResizableWindow::resized()
  62514. {
  62515. if (resizableBorder != 0)
  62516. {
  62517. resizableBorder->setVisible (! isFullScreen());
  62518. resizableBorder->setBorderThickness (getBorderThickness());
  62519. resizableBorder->setSize (getWidth(), getHeight());
  62520. resizableBorder->toBack();
  62521. }
  62522. if (resizableCorner != 0)
  62523. {
  62524. resizableCorner->setVisible (! isFullScreen());
  62525. const int resizerSize = 18;
  62526. resizableCorner->setBounds (getWidth() - resizerSize,
  62527. getHeight() - resizerSize,
  62528. resizerSize, resizerSize);
  62529. }
  62530. if (contentComponent != 0)
  62531. contentComponent->setBoundsInset (getContentComponentBorder());
  62532. updateLastPos();
  62533. #ifdef JUCE_DEBUG
  62534. hasBeenResized = true;
  62535. #endif
  62536. }
  62537. void ResizableWindow::childBoundsChanged (Component* child)
  62538. {
  62539. if ((child == contentComponent) && (child != 0) && resizeToFitContent)
  62540. {
  62541. // not going to look very good if this component has a zero size..
  62542. jassert (child->getWidth() > 0);
  62543. jassert (child->getHeight() > 0);
  62544. const BorderSize borders (getContentComponentBorder());
  62545. setSize (child->getWidth() + borders.getLeftAndRight(),
  62546. child->getHeight() + borders.getTopAndBottom());
  62547. }
  62548. }
  62549. void ResizableWindow::activeWindowStatusChanged()
  62550. {
  62551. const BorderSize borders (getContentComponentBorder());
  62552. repaint (0, 0, getWidth(), borders.getTop());
  62553. repaint (0, borders.getTop(), borders.getLeft(), getHeight() - borders.getBottom() - borders.getTop());
  62554. repaint (0, getHeight() - borders.getBottom(), getWidth(), borders.getBottom());
  62555. repaint (getWidth() - borders.getRight(), borders.getTop(), borders.getRight(), getHeight() - borders.getBottom() - borders.getTop());
  62556. }
  62557. void ResizableWindow::setResizable (const bool shouldBeResizable,
  62558. const bool useBottomRightCornerResizer)
  62559. {
  62560. if (shouldBeResizable)
  62561. {
  62562. if (useBottomRightCornerResizer)
  62563. {
  62564. resizableBorder = 0;
  62565. if (resizableCorner == 0)
  62566. {
  62567. Component::addChildComponent (resizableCorner = new ResizableCornerComponent (this, constrainer));
  62568. resizableCorner->setAlwaysOnTop (true);
  62569. }
  62570. }
  62571. else
  62572. {
  62573. resizableCorner = 0;
  62574. if (resizableBorder == 0)
  62575. Component::addChildComponent (resizableBorder = new ResizableBorderComponent (this, constrainer));
  62576. }
  62577. }
  62578. else
  62579. {
  62580. resizableCorner = 0;
  62581. resizableBorder = 0;
  62582. }
  62583. if (isUsingNativeTitleBar())
  62584. recreateDesktopWindow();
  62585. childBoundsChanged (contentComponent);
  62586. resized();
  62587. }
  62588. bool ResizableWindow::isResizable() const throw()
  62589. {
  62590. return resizableCorner != 0
  62591. || resizableBorder != 0;
  62592. }
  62593. void ResizableWindow::setResizeLimits (const int newMinimumWidth,
  62594. const int newMinimumHeight,
  62595. const int newMaximumWidth,
  62596. const int newMaximumHeight) throw()
  62597. {
  62598. // if you've set up a custom constrainer then these settings won't have any effect..
  62599. jassert (constrainer == &defaultConstrainer || constrainer == 0);
  62600. if (constrainer == 0)
  62601. setConstrainer (&defaultConstrainer);
  62602. defaultConstrainer.setSizeLimits (newMinimumWidth, newMinimumHeight,
  62603. newMaximumWidth, newMaximumHeight);
  62604. setBoundsConstrained (getX(), getY(), getWidth(), getHeight());
  62605. }
  62606. void ResizableWindow::setConstrainer (ComponentBoundsConstrainer* newConstrainer)
  62607. {
  62608. if (constrainer != newConstrainer)
  62609. {
  62610. constrainer = newConstrainer;
  62611. const bool useBottomRightCornerResizer = resizableCorner != 0;
  62612. const bool shouldBeResizable = useBottomRightCornerResizer || resizableBorder != 0;
  62613. resizableCorner = 0;
  62614. resizableBorder = 0;
  62615. setResizable (shouldBeResizable, useBottomRightCornerResizer);
  62616. ComponentPeer* const peer = getPeer();
  62617. if (peer != 0)
  62618. peer->setConstrainer (newConstrainer);
  62619. }
  62620. }
  62621. void ResizableWindow::setBoundsConstrained (int x, int y, int w, int h)
  62622. {
  62623. if (constrainer != 0)
  62624. constrainer->setBoundsForComponent (this, x, y, w, h, false, false, false, false);
  62625. else
  62626. setBounds (x, y, w, h);
  62627. }
  62628. void ResizableWindow::paint (Graphics& g)
  62629. {
  62630. getLookAndFeel().fillResizableWindowBackground (g, getWidth(), getHeight(),
  62631. getBorderThickness(), *this);
  62632. if (! isFullScreen())
  62633. {
  62634. getLookAndFeel().drawResizableWindowBorder (g, getWidth(), getHeight(),
  62635. getBorderThickness(), *this);
  62636. }
  62637. #ifdef JUCE_DEBUG
  62638. /* If this fails, then you've probably written a subclass with a resized()
  62639. callback but forgotten to make it call its parent class's resized() method.
  62640. It's important when you override methods like resized(), moved(),
  62641. etc., that you make sure the base class methods also get called.
  62642. Of course you shouldn't really be overriding ResizableWindow::resized() anyway,
  62643. because your content should all be inside the content component - and it's the
  62644. content component's resized() method that you should be using to do your
  62645. layout.
  62646. */
  62647. jassert (hasBeenResized || (getWidth() == 0 && getHeight() == 0));
  62648. #endif
  62649. }
  62650. void ResizableWindow::lookAndFeelChanged()
  62651. {
  62652. resized();
  62653. if (isOnDesktop())
  62654. {
  62655. Component::addToDesktop (getDesktopWindowStyleFlags());
  62656. ComponentPeer* const peer = getPeer();
  62657. if (peer != 0)
  62658. peer->setConstrainer (constrainer);
  62659. }
  62660. }
  62661. const Colour ResizableWindow::getBackgroundColour() const throw()
  62662. {
  62663. return findColour (backgroundColourId, false);
  62664. }
  62665. void ResizableWindow::setBackgroundColour (const Colour& newColour)
  62666. {
  62667. Colour backgroundColour (newColour);
  62668. if (! Desktop::canUseSemiTransparentWindows())
  62669. backgroundColour = newColour.withAlpha (1.0f);
  62670. setColour (backgroundColourId, backgroundColour);
  62671. setOpaque (backgroundColour.isOpaque());
  62672. repaint();
  62673. }
  62674. bool ResizableWindow::isFullScreen() const
  62675. {
  62676. if (isOnDesktop())
  62677. {
  62678. ComponentPeer* const peer = getPeer();
  62679. return peer != 0 && peer->isFullScreen();
  62680. }
  62681. return fullscreen;
  62682. }
  62683. void ResizableWindow::setFullScreen (const bool shouldBeFullScreen)
  62684. {
  62685. if (shouldBeFullScreen != isFullScreen())
  62686. {
  62687. updateLastPos();
  62688. fullscreen = shouldBeFullScreen;
  62689. if (isOnDesktop())
  62690. {
  62691. ComponentPeer* const peer = getPeer();
  62692. if (peer != 0)
  62693. {
  62694. // keep a copy of this intact in case the real one gets messed-up while we're un-maximising
  62695. const Rectangle lastPos (lastNonFullScreenPos);
  62696. peer->setFullScreen (shouldBeFullScreen);
  62697. if (! shouldBeFullScreen)
  62698. setBounds (lastPos);
  62699. }
  62700. else
  62701. {
  62702. jassertfalse
  62703. }
  62704. }
  62705. else
  62706. {
  62707. if (shouldBeFullScreen)
  62708. setBounds (0, 0, getParentWidth(), getParentHeight());
  62709. else
  62710. setBounds (lastNonFullScreenPos);
  62711. }
  62712. resized();
  62713. }
  62714. }
  62715. bool ResizableWindow::isMinimised() const
  62716. {
  62717. ComponentPeer* const peer = getPeer();
  62718. return (peer != 0) && peer->isMinimised();
  62719. }
  62720. void ResizableWindow::setMinimised (const bool shouldMinimise)
  62721. {
  62722. if (shouldMinimise != isMinimised())
  62723. {
  62724. ComponentPeer* const peer = getPeer();
  62725. if (peer != 0)
  62726. {
  62727. updateLastPos();
  62728. peer->setMinimised (shouldMinimise);
  62729. }
  62730. else
  62731. {
  62732. jassertfalse
  62733. }
  62734. }
  62735. }
  62736. void ResizableWindow::updateLastPos()
  62737. {
  62738. if (isShowing() && ! (isFullScreen() || isMinimised()))
  62739. {
  62740. lastNonFullScreenPos = getBounds();
  62741. }
  62742. }
  62743. void ResizableWindow::parentSizeChanged()
  62744. {
  62745. if (isFullScreen() && getParentComponent() != 0)
  62746. {
  62747. setBounds (0, 0, getParentWidth(), getParentHeight());
  62748. }
  62749. }
  62750. const String ResizableWindow::getWindowStateAsString()
  62751. {
  62752. updateLastPos();
  62753. String s;
  62754. if (isFullScreen())
  62755. s << "fs ";
  62756. s << lastNonFullScreenPos.getX() << T(' ')
  62757. << lastNonFullScreenPos.getY() << T(' ')
  62758. << lastNonFullScreenPos.getWidth() << T(' ')
  62759. << lastNonFullScreenPos.getHeight();
  62760. return s;
  62761. }
  62762. bool ResizableWindow::restoreWindowStateFromString (const String& s)
  62763. {
  62764. StringArray tokens;
  62765. tokens.addTokens (s, false);
  62766. tokens.removeEmptyStrings();
  62767. tokens.trim();
  62768. const bool fs = tokens[0].startsWithIgnoreCase (T("fs"));
  62769. const int n = fs ? 1 : 0;
  62770. if (tokens.size() != 4 + n)
  62771. return false;
  62772. Rectangle r (tokens[n].getIntValue(),
  62773. tokens[n + 1].getIntValue(),
  62774. tokens[n + 2].getIntValue(),
  62775. tokens[n + 3].getIntValue());
  62776. if (r.isEmpty())
  62777. return false;
  62778. const Rectangle screen (Desktop::getInstance().getMonitorAreaContaining (r.getX(), r.getY()));
  62779. if (! screen.contains (r))
  62780. {
  62781. r.setSize (jmin (r.getWidth(), screen.getWidth()),
  62782. jmin (r.getHeight(), screen.getHeight()));
  62783. r.setPosition (jlimit (screen.getX(), screen.getRight() - r.getWidth(), r.getX()),
  62784. jlimit (screen.getY(), screen.getBottom() - r.getHeight(), r.getY()));
  62785. }
  62786. lastNonFullScreenPos = r;
  62787. if (isOnDesktop())
  62788. {
  62789. ComponentPeer* const peer = getPeer();
  62790. if (peer != 0)
  62791. peer->setNonFullScreenBounds (r);
  62792. }
  62793. setFullScreen (fs);
  62794. if (! fs)
  62795. setBoundsConstrained (r.getX(),
  62796. r.getY(),
  62797. r.getWidth(),
  62798. r.getHeight());
  62799. return true;
  62800. }
  62801. void ResizableWindow::mouseDown (const MouseEvent&)
  62802. {
  62803. if (! isFullScreen())
  62804. dragger.startDraggingComponent (this, constrainer);
  62805. }
  62806. void ResizableWindow::mouseDrag (const MouseEvent& e)
  62807. {
  62808. if (! isFullScreen())
  62809. dragger.dragComponent (this, e);
  62810. }
  62811. #ifdef JUCE_DEBUG
  62812. void ResizableWindow::addChildComponent (Component* const child, int zOrder)
  62813. {
  62814. /* Agh! You shouldn't add components directly to a ResizableWindow - this class
  62815. manages its child components automatically, and if you add your own it'll cause
  62816. trouble. Instead, use setContentComponent() to give it a component which
  62817. will be automatically resized and kept in the right place - then you can add
  62818. subcomponents to the content comp. See the notes for the ResizableWindow class
  62819. for more info.
  62820. If you really know what you're doing and want to avoid this assertion, just call
  62821. Component::addChildComponent directly.
  62822. */
  62823. jassertfalse
  62824. Component::addChildComponent (child, zOrder);
  62825. }
  62826. void ResizableWindow::addAndMakeVisible (Component* const child, int zOrder)
  62827. {
  62828. /* Agh! You shouldn't add components directly to a ResizableWindow - this class
  62829. manages its child components automatically, and if you add your own it'll cause
  62830. trouble. Instead, use setContentComponent() to give it a component which
  62831. will be automatically resized and kept in the right place - then you can add
  62832. subcomponents to the content comp. See the notes for the ResizableWindow class
  62833. for more info.
  62834. If you really know what you're doing and want to avoid this assertion, just call
  62835. Component::addAndMakeVisible directly.
  62836. */
  62837. jassertfalse
  62838. Component::addAndMakeVisible (child, zOrder);
  62839. }
  62840. #endif
  62841. END_JUCE_NAMESPACE
  62842. /********* End of inlined file: juce_ResizableWindow.cpp *********/
  62843. /********* Start of inlined file: juce_SplashScreen.cpp *********/
  62844. BEGIN_JUCE_NAMESPACE
  62845. SplashScreen::SplashScreen()
  62846. : backgroundImage (0)
  62847. {
  62848. setOpaque (true);
  62849. }
  62850. SplashScreen::~SplashScreen()
  62851. {
  62852. ImageCache::releaseOrDelete (backgroundImage);
  62853. }
  62854. void SplashScreen::show (const String& title,
  62855. Image* const backgroundImage_,
  62856. const int minimumTimeToDisplayFor,
  62857. const bool useDropShadow,
  62858. const bool removeOnMouseClick)
  62859. {
  62860. backgroundImage = backgroundImage_;
  62861. jassert (backgroundImage_ != 0);
  62862. if (backgroundImage_ != 0)
  62863. {
  62864. setOpaque (! backgroundImage_->hasAlphaChannel());
  62865. show (title,
  62866. backgroundImage_->getWidth(),
  62867. backgroundImage_->getHeight(),
  62868. minimumTimeToDisplayFor,
  62869. useDropShadow,
  62870. removeOnMouseClick);
  62871. }
  62872. }
  62873. void SplashScreen::show (const String& title,
  62874. const int width,
  62875. const int height,
  62876. const int minimumTimeToDisplayFor,
  62877. const bool useDropShadow,
  62878. const bool removeOnMouseClick)
  62879. {
  62880. setName (title);
  62881. setAlwaysOnTop (true);
  62882. setVisible (true);
  62883. centreWithSize (width, height);
  62884. addToDesktop (useDropShadow ? ComponentPeer::windowHasDropShadow : 0);
  62885. toFront (false);
  62886. MessageManager::getInstance()->runDispatchLoopUntil (300);
  62887. repaint();
  62888. originalClickCounter = removeOnMouseClick
  62889. ? Desktop::getMouseButtonClickCounter()
  62890. : INT_MAX;
  62891. earliestTimeToDelete = Time::getCurrentTime() + RelativeTime::milliseconds (minimumTimeToDisplayFor);
  62892. startTimer (50);
  62893. }
  62894. void SplashScreen::paint (Graphics& g)
  62895. {
  62896. if (backgroundImage != 0)
  62897. {
  62898. g.setOpacity (1.0f);
  62899. g.drawImage (backgroundImage,
  62900. 0, 0, getWidth(), getHeight(),
  62901. 0, 0, backgroundImage->getWidth(), backgroundImage->getHeight());
  62902. }
  62903. }
  62904. void SplashScreen::timerCallback()
  62905. {
  62906. if (Time::getCurrentTime() > earliestTimeToDelete
  62907. || Desktop::getMouseButtonClickCounter() > originalClickCounter)
  62908. {
  62909. delete this;
  62910. }
  62911. }
  62912. END_JUCE_NAMESPACE
  62913. /********* End of inlined file: juce_SplashScreen.cpp *********/
  62914. /********* Start of inlined file: juce_ThreadWithProgressWindow.cpp *********/
  62915. BEGIN_JUCE_NAMESPACE
  62916. ThreadWithProgressWindow::ThreadWithProgressWindow (const String& title,
  62917. const bool hasProgressBar,
  62918. const bool hasCancelButton,
  62919. const int timeOutMsWhenCancelling_,
  62920. const String& cancelButtonText)
  62921. : Thread ("Juce Progress Window"),
  62922. progress (0.0),
  62923. timeOutMsWhenCancelling (timeOutMsWhenCancelling_)
  62924. {
  62925. alertWindow = LookAndFeel::getDefaultLookAndFeel()
  62926. .createAlertWindow (title, String::empty, cancelButtonText,
  62927. String::empty, String::empty,
  62928. AlertWindow::NoIcon, hasCancelButton ? 1 : 0, 0);
  62929. if (hasProgressBar)
  62930. alertWindow->addProgressBarComponent (progress);
  62931. }
  62932. ThreadWithProgressWindow::~ThreadWithProgressWindow()
  62933. {
  62934. stopThread (timeOutMsWhenCancelling);
  62935. }
  62936. bool ThreadWithProgressWindow::runThread (const int priority)
  62937. {
  62938. startThread (priority);
  62939. startTimer (100);
  62940. {
  62941. const ScopedLock sl (messageLock);
  62942. alertWindow->setMessage (message);
  62943. }
  62944. const bool finishedNaturally = alertWindow->runModalLoop() != 0;
  62945. stopThread (timeOutMsWhenCancelling);
  62946. alertWindow->setVisible (false);
  62947. return finishedNaturally;
  62948. }
  62949. void ThreadWithProgressWindow::setProgress (const double newProgress)
  62950. {
  62951. progress = newProgress;
  62952. }
  62953. void ThreadWithProgressWindow::setStatusMessage (const String& newStatusMessage)
  62954. {
  62955. const ScopedLock sl (messageLock);
  62956. message = newStatusMessage;
  62957. }
  62958. void ThreadWithProgressWindow::timerCallback()
  62959. {
  62960. if (! isThreadRunning())
  62961. {
  62962. // thread has finished normally..
  62963. alertWindow->exitModalState (1);
  62964. alertWindow->setVisible (false);
  62965. }
  62966. else
  62967. {
  62968. const ScopedLock sl (messageLock);
  62969. alertWindow->setMessage (message);
  62970. }
  62971. }
  62972. END_JUCE_NAMESPACE
  62973. /********* End of inlined file: juce_ThreadWithProgressWindow.cpp *********/
  62974. /********* Start of inlined file: juce_TooltipWindow.cpp *********/
  62975. BEGIN_JUCE_NAMESPACE
  62976. TooltipWindow::TooltipWindow (Component* const parentComponent,
  62977. const int millisecondsBeforeTipAppears_)
  62978. : Component ("tooltip"),
  62979. millisecondsBeforeTipAppears (millisecondsBeforeTipAppears_),
  62980. mouseX (0),
  62981. mouseY (0),
  62982. lastHideTime (0),
  62983. lastComponentUnderMouse (0),
  62984. changedCompsSinceShown (true)
  62985. {
  62986. startTimer (123);
  62987. setAlwaysOnTop (true);
  62988. setOpaque (true);
  62989. if (parentComponent != 0)
  62990. parentComponent->addChildComponent (this);
  62991. }
  62992. TooltipWindow::~TooltipWindow()
  62993. {
  62994. hide();
  62995. }
  62996. void TooltipWindow::setMillisecondsBeforeTipAppears (const int newTimeMs) throw()
  62997. {
  62998. millisecondsBeforeTipAppears = newTimeMs;
  62999. }
  63000. void TooltipWindow::paint (Graphics& g)
  63001. {
  63002. getLookAndFeel().drawTooltip (g, tipShowing, getWidth(), getHeight());
  63003. }
  63004. void TooltipWindow::mouseEnter (const MouseEvent&)
  63005. {
  63006. hide();
  63007. }
  63008. void TooltipWindow::showFor (const String& tip)
  63009. {
  63010. jassert (tip.isNotEmpty());
  63011. tipShowing = tip;
  63012. int mx, my;
  63013. Desktop::getMousePosition (mx, my);
  63014. if (getParentComponent() != 0)
  63015. getParentComponent()->globalPositionToRelative (mx, my);
  63016. int x, y, w, h;
  63017. getLookAndFeel().getTooltipSize (tip, w, h);
  63018. if (mx > getParentWidth() / 2)
  63019. x = mx - (w + 12);
  63020. else
  63021. x = mx + 24;
  63022. if (my > getParentHeight() / 2)
  63023. y = my - (h + 6);
  63024. else
  63025. y = my + 6;
  63026. setBounds (x, y, w, h);
  63027. setVisible (true);
  63028. if (getParentComponent() == 0)
  63029. {
  63030. addToDesktop (ComponentPeer::windowHasDropShadow
  63031. | ComponentPeer::windowIsTemporary
  63032. | ComponentPeer::windowIgnoresKeyPresses);
  63033. }
  63034. toFront (false);
  63035. }
  63036. const String TooltipWindow::getTipFor (Component* const c)
  63037. {
  63038. if (c->isValidComponent()
  63039. && Process::isForegroundProcess()
  63040. && ! Component::isMouseButtonDownAnywhere())
  63041. {
  63042. TooltipClient* const ttc = dynamic_cast <TooltipClient*> (c);
  63043. if (ttc != 0 && ! c->isCurrentlyBlockedByAnotherModalComponent())
  63044. return ttc->getTooltip();
  63045. }
  63046. return String::empty;
  63047. }
  63048. void TooltipWindow::hide()
  63049. {
  63050. tipShowing = String::empty;
  63051. removeFromDesktop();
  63052. setVisible (false);
  63053. }
  63054. void TooltipWindow::timerCallback()
  63055. {
  63056. const unsigned int now = Time::getApproximateMillisecondCounter();
  63057. Component* const newComp = Component::getComponentUnderMouse();
  63058. const String newTip (getTipFor (newComp));
  63059. const bool tipChanged = (newTip != lastTipUnderMouse || newComp != lastComponentUnderMouse);
  63060. lastComponentUnderMouse = newComp;
  63061. lastTipUnderMouse = newTip;
  63062. const int clickCount = Desktop::getInstance().getMouseButtonClickCounter();
  63063. const bool mouseWasClicked = clickCount > mouseClicks;
  63064. mouseClicks = clickCount;
  63065. int mx, my;
  63066. Desktop::getMousePosition (mx, my);
  63067. const bool mouseMovedQuickly = (abs (mx - mouseX) + abs (my - mouseY) > 12);
  63068. mouseX = mx;
  63069. mouseY = my;
  63070. if (tipChanged || mouseWasClicked || mouseMovedQuickly)
  63071. lastCompChangeTime = now;
  63072. if (isVisible() || now < lastHideTime + 500)
  63073. {
  63074. // if a tip is currently visible (or has just disappeared), update to a new one
  63075. // immediately if needed..
  63076. if (newComp == 0 || mouseWasClicked || newTip.isEmpty())
  63077. {
  63078. if (isVisible())
  63079. {
  63080. lastHideTime = now;
  63081. hide();
  63082. }
  63083. }
  63084. else if (tipChanged)
  63085. {
  63086. showFor (newTip);
  63087. }
  63088. }
  63089. else
  63090. {
  63091. // if there isn't currently a tip, but one is needed, only let it
  63092. // appear after a timeout..
  63093. if (newTip.isNotEmpty()
  63094. && newTip != tipShowing
  63095. && now > lastCompChangeTime + millisecondsBeforeTipAppears)
  63096. {
  63097. showFor (newTip);
  63098. }
  63099. }
  63100. }
  63101. END_JUCE_NAMESPACE
  63102. /********* End of inlined file: juce_TooltipWindow.cpp *********/
  63103. /********* Start of inlined file: juce_TopLevelWindow.cpp *********/
  63104. BEGIN_JUCE_NAMESPACE
  63105. class TopLevelWindowManager : public Timer,
  63106. public DeletedAtShutdown
  63107. {
  63108. public:
  63109. TopLevelWindowManager()
  63110. : currentActive (0)
  63111. {
  63112. }
  63113. ~TopLevelWindowManager()
  63114. {
  63115. clearSingletonInstance();
  63116. }
  63117. juce_DeclareSingleton_SingleThreaded_Minimal (TopLevelWindowManager)
  63118. void timerCallback()
  63119. {
  63120. startTimer (jmin (1731, getTimerInterval() * 2));
  63121. TopLevelWindow* active = 0;
  63122. if (Process::isForegroundProcess())
  63123. {
  63124. active = currentActive;
  63125. Component* const c = Component::getCurrentlyFocusedComponent();
  63126. TopLevelWindow* tlw = dynamic_cast <TopLevelWindow*> (c);
  63127. if (tlw == 0 && c != 0)
  63128. // (unable to use the syntax findParentComponentOfClass <TopLevelWindow> () because of a VC6 compiler bug)
  63129. tlw = c->findParentComponentOfClass ((TopLevelWindow*) 0);
  63130. if (tlw != 0)
  63131. active = tlw;
  63132. }
  63133. if (active != currentActive)
  63134. {
  63135. currentActive = active;
  63136. for (int i = windows.size(); --i >= 0;)
  63137. {
  63138. TopLevelWindow* const tlw = (TopLevelWindow*) windows.getUnchecked (i);
  63139. tlw->setWindowActive (isWindowActive (tlw));
  63140. i = jmin (i, windows.size() - 1);
  63141. }
  63142. Desktop::getInstance().triggerFocusCallback();
  63143. }
  63144. }
  63145. bool addWindow (TopLevelWindow* const w) throw()
  63146. {
  63147. windows.add (w);
  63148. startTimer (10);
  63149. return isWindowActive (w);
  63150. }
  63151. void removeWindow (TopLevelWindow* const w) throw()
  63152. {
  63153. startTimer (10);
  63154. if (currentActive == w)
  63155. currentActive = 0;
  63156. windows.removeValue (w);
  63157. if (windows.size() == 0)
  63158. deleteInstance();
  63159. }
  63160. VoidArray windows;
  63161. private:
  63162. TopLevelWindow* currentActive;
  63163. bool isWindowActive (TopLevelWindow* const tlw) const throw()
  63164. {
  63165. return (tlw == currentActive
  63166. || tlw->isParentOf (currentActive)
  63167. || tlw->hasKeyboardFocus (true))
  63168. && tlw->isShowing();
  63169. }
  63170. TopLevelWindowManager (const TopLevelWindowManager&);
  63171. const TopLevelWindowManager& operator= (const TopLevelWindowManager&);
  63172. };
  63173. juce_ImplementSingleton_SingleThreaded (TopLevelWindowManager)
  63174. void juce_CheckCurrentlyFocusedTopLevelWindow()
  63175. {
  63176. if (TopLevelWindowManager::getInstanceWithoutCreating() != 0)
  63177. TopLevelWindowManager::getInstanceWithoutCreating()->startTimer (20);
  63178. }
  63179. TopLevelWindow::TopLevelWindow (const String& name,
  63180. const bool addToDesktop_)
  63181. : Component (name),
  63182. useDropShadow (true),
  63183. useNativeTitleBar (false),
  63184. windowIsActive_ (false)
  63185. {
  63186. setOpaque (true);
  63187. if (addToDesktop_)
  63188. Component::addToDesktop (getDesktopWindowStyleFlags());
  63189. else
  63190. setDropShadowEnabled (true);
  63191. setWantsKeyboardFocus (true);
  63192. setBroughtToFrontOnMouseClick (true);
  63193. windowIsActive_ = TopLevelWindowManager::getInstance()->addWindow (this);
  63194. }
  63195. TopLevelWindow::~TopLevelWindow()
  63196. {
  63197. shadower = 0;
  63198. TopLevelWindowManager::getInstance()->removeWindow (this);
  63199. }
  63200. void TopLevelWindow::focusOfChildComponentChanged (FocusChangeType)
  63201. {
  63202. if (hasKeyboardFocus (true))
  63203. TopLevelWindowManager::getInstance()->timerCallback();
  63204. else
  63205. TopLevelWindowManager::getInstance()->startTimer (10);
  63206. }
  63207. void TopLevelWindow::setWindowActive (const bool isNowActive) throw()
  63208. {
  63209. if (windowIsActive_ != isNowActive)
  63210. {
  63211. windowIsActive_ = isNowActive;
  63212. activeWindowStatusChanged();
  63213. }
  63214. }
  63215. void TopLevelWindow::activeWindowStatusChanged()
  63216. {
  63217. }
  63218. void TopLevelWindow::parentHierarchyChanged()
  63219. {
  63220. setDropShadowEnabled (useDropShadow);
  63221. }
  63222. void TopLevelWindow::visibilityChanged()
  63223. {
  63224. if (isShowing())
  63225. toFront (true);
  63226. }
  63227. int TopLevelWindow::getDesktopWindowStyleFlags() const
  63228. {
  63229. int flags = ComponentPeer::windowAppearsOnTaskbar;
  63230. if (useDropShadow)
  63231. flags |= ComponentPeer::windowHasDropShadow;
  63232. if (useNativeTitleBar)
  63233. flags |= ComponentPeer::windowHasTitleBar;
  63234. return flags;
  63235. }
  63236. void TopLevelWindow::setDropShadowEnabled (const bool useShadow)
  63237. {
  63238. useDropShadow = useShadow;
  63239. if (isOnDesktop())
  63240. {
  63241. shadower = 0;
  63242. Component::addToDesktop (getDesktopWindowStyleFlags());
  63243. }
  63244. else
  63245. {
  63246. if (useShadow && isOpaque())
  63247. {
  63248. if (shadower == 0)
  63249. {
  63250. shadower = getLookAndFeel().createDropShadowerForComponent (this);
  63251. if (shadower != 0)
  63252. shadower->setOwner (this);
  63253. }
  63254. }
  63255. else
  63256. {
  63257. shadower = 0;
  63258. }
  63259. }
  63260. }
  63261. void TopLevelWindow::setUsingNativeTitleBar (const bool useNativeTitleBar_)
  63262. {
  63263. if (useNativeTitleBar != useNativeTitleBar_)
  63264. {
  63265. useNativeTitleBar = useNativeTitleBar_;
  63266. recreateDesktopWindow();
  63267. sendLookAndFeelChange();
  63268. }
  63269. }
  63270. void TopLevelWindow::recreateDesktopWindow()
  63271. {
  63272. if (isOnDesktop())
  63273. {
  63274. Component::addToDesktop (getDesktopWindowStyleFlags());
  63275. toFront (true);
  63276. }
  63277. }
  63278. void TopLevelWindow::addToDesktop (int windowStyleFlags, void* nativeWindowToAttachTo)
  63279. {
  63280. /* It's not recommended to change the desktop window flags directly for a TopLevelWindow,
  63281. because this class needs to make sure its layout corresponds with settings like whether
  63282. it's got a native title bar or not.
  63283. If you need custom flags for your window, you can override the getDesktopWindowStyleFlags()
  63284. method. If you do this, it's best to call the base class's getDesktopWindowStyleFlags()
  63285. method, then add or remove whatever flags are necessary from this value before returning it.
  63286. */
  63287. jassert ((windowStyleFlags & ~ComponentPeer::windowIsSemiTransparent)
  63288. == (getDesktopWindowStyleFlags() & ~ComponentPeer::windowIsSemiTransparent));
  63289. Component::addToDesktop (windowStyleFlags, nativeWindowToAttachTo);
  63290. if (windowStyleFlags != getDesktopWindowStyleFlags())
  63291. sendLookAndFeelChange();
  63292. }
  63293. void TopLevelWindow::centreAroundComponent (Component* c, const int width, const int height)
  63294. {
  63295. if (c == 0)
  63296. c = TopLevelWindow::getActiveTopLevelWindow();
  63297. if (c == 0)
  63298. {
  63299. centreWithSize (width, height);
  63300. }
  63301. else
  63302. {
  63303. int x = (c->getWidth() - width) / 2;
  63304. int y = (c->getHeight() - height) / 2;
  63305. c->relativePositionToGlobal (x, y);
  63306. Rectangle parentArea (c->getParentMonitorArea());
  63307. if (getParentComponent() != 0)
  63308. {
  63309. getParentComponent()->globalPositionToRelative (x, y);
  63310. parentArea.setBounds (0, 0, getParentWidth(), getParentHeight());
  63311. }
  63312. parentArea.reduce (12, 12);
  63313. setBounds (jlimit (parentArea.getX(), jmax (parentArea.getX(), parentArea.getRight() - width), x),
  63314. jlimit (parentArea.getY(), jmax (parentArea.getY(), parentArea.getBottom() - height), y),
  63315. width, height);
  63316. }
  63317. }
  63318. int TopLevelWindow::getNumTopLevelWindows() throw()
  63319. {
  63320. return TopLevelWindowManager::getInstance()->windows.size();
  63321. }
  63322. TopLevelWindow* TopLevelWindow::getTopLevelWindow (const int index) throw()
  63323. {
  63324. return (TopLevelWindow*) TopLevelWindowManager::getInstance()->windows [index];
  63325. }
  63326. TopLevelWindow* TopLevelWindow::getActiveTopLevelWindow() throw()
  63327. {
  63328. TopLevelWindow* best = 0;
  63329. int bestNumTWLParents = -1;
  63330. for (int i = TopLevelWindow::getNumTopLevelWindows(); --i >= 0;)
  63331. {
  63332. TopLevelWindow* const tlw = TopLevelWindow::getTopLevelWindow (i);
  63333. if (tlw->isActiveWindow())
  63334. {
  63335. int numTWLParents = 0;
  63336. const Component* c = tlw->getParentComponent();
  63337. while (c != 0)
  63338. {
  63339. if (dynamic_cast <const TopLevelWindow*> (c) != 0)
  63340. ++numTWLParents;
  63341. c = c->getParentComponent();
  63342. }
  63343. if (bestNumTWLParents < numTWLParents)
  63344. {
  63345. best = tlw;
  63346. bestNumTWLParents = numTWLParents;
  63347. }
  63348. }
  63349. }
  63350. return best;
  63351. }
  63352. END_JUCE_NAMESPACE
  63353. /********* End of inlined file: juce_TopLevelWindow.cpp *********/
  63354. /********* Start of inlined file: juce_Colour.cpp *********/
  63355. BEGIN_JUCE_NAMESPACE
  63356. static uint8 floatAlphaToInt (const float alpha)
  63357. {
  63358. return (uint8) jlimit (0, 0xff, roundToInt (alpha * 255.0f));
  63359. }
  63360. static const float oneOver255 = 1.0f / 255.0f;
  63361. Colour::Colour() throw()
  63362. : argb (0)
  63363. {
  63364. }
  63365. Colour::Colour (const Colour& other) throw()
  63366. : argb (other.argb)
  63367. {
  63368. }
  63369. const Colour& Colour::operator= (const Colour& other) throw()
  63370. {
  63371. argb = other.argb;
  63372. return *this;
  63373. }
  63374. bool Colour::operator== (const Colour& other) const throw()
  63375. {
  63376. return argb.getARGB() == other.argb.getARGB();
  63377. }
  63378. bool Colour::operator!= (const Colour& other) const throw()
  63379. {
  63380. return argb.getARGB() != other.argb.getARGB();
  63381. }
  63382. Colour::Colour (const uint32 argb_) throw()
  63383. : argb (argb_)
  63384. {
  63385. }
  63386. Colour::Colour (const uint8 red,
  63387. const uint8 green,
  63388. const uint8 blue) throw()
  63389. {
  63390. argb.setARGB (0xff, red, green, blue);
  63391. }
  63392. const Colour Colour::fromRGB (const uint8 red,
  63393. const uint8 green,
  63394. const uint8 blue) throw()
  63395. {
  63396. return Colour (red, green, blue);
  63397. }
  63398. Colour::Colour (const uint8 red,
  63399. const uint8 green,
  63400. const uint8 blue,
  63401. const uint8 alpha) throw()
  63402. {
  63403. argb.setARGB (alpha, red, green, blue);
  63404. }
  63405. const Colour Colour::fromRGBA (const uint8 red,
  63406. const uint8 green,
  63407. const uint8 blue,
  63408. const uint8 alpha) throw()
  63409. {
  63410. return Colour (red, green, blue, alpha);
  63411. }
  63412. Colour::Colour (const uint8 red,
  63413. const uint8 green,
  63414. const uint8 blue,
  63415. const float alpha) throw()
  63416. {
  63417. argb.setARGB (floatAlphaToInt (alpha), red, green, blue);
  63418. }
  63419. const Colour Colour::fromRGBAFloat (const uint8 red,
  63420. const uint8 green,
  63421. const uint8 blue,
  63422. const float alpha) throw()
  63423. {
  63424. return Colour (red, green, blue, alpha);
  63425. }
  63426. static void convertHSBtoRGB (float h, float s, float v,
  63427. uint8& r, uint8& g, uint8& b) throw()
  63428. {
  63429. v = jlimit (0.0f, 1.0f, v);
  63430. v *= 255.0f;
  63431. const uint8 intV = (uint8) roundToInt (v);
  63432. if (s <= 0)
  63433. {
  63434. r = intV;
  63435. g = intV;
  63436. b = intV;
  63437. }
  63438. else
  63439. {
  63440. s = jmin (1.0f, s);
  63441. h = jlimit (0.0f, 1.0f, h);
  63442. h = (h - floorf (h)) * 6.0f + 0.00001f; // need a small adjustment to compensate for rounding errors
  63443. const float f = h - floorf (h);
  63444. const uint8 x = (uint8) roundToInt (v * (1.0f - s));
  63445. const float y = v * (1.0f - s * f);
  63446. const float z = v * (1.0f - (s * (1.0f - f)));
  63447. if (h < 1.0f)
  63448. {
  63449. r = intV;
  63450. g = (uint8) roundToInt (z);
  63451. b = x;
  63452. }
  63453. else if (h < 2.0f)
  63454. {
  63455. r = (uint8) roundToInt (y);
  63456. g = intV;
  63457. b = x;
  63458. }
  63459. else if (h < 3.0f)
  63460. {
  63461. r = x;
  63462. g = intV;
  63463. b = (uint8) roundToInt (z);
  63464. }
  63465. else if (h < 4.0f)
  63466. {
  63467. r = x;
  63468. g = (uint8) roundToInt (y);
  63469. b = intV;
  63470. }
  63471. else if (h < 5.0f)
  63472. {
  63473. r = (uint8) roundToInt (z);
  63474. g = x;
  63475. b = intV;
  63476. }
  63477. else if (h < 6.0f)
  63478. {
  63479. r = intV;
  63480. g = x;
  63481. b = (uint8) roundToInt (y);
  63482. }
  63483. else
  63484. {
  63485. r = 0;
  63486. g = 0;
  63487. b = 0;
  63488. }
  63489. }
  63490. }
  63491. Colour::Colour (const float hue,
  63492. const float saturation,
  63493. const float brightness,
  63494. const float alpha) throw()
  63495. {
  63496. uint8 r = getRed(), g = getGreen(), b = getBlue();
  63497. convertHSBtoRGB (hue, saturation, brightness, r, g, b);
  63498. argb.setARGB (floatAlphaToInt (alpha), r, g, b);
  63499. }
  63500. const Colour Colour::fromHSV (const float hue,
  63501. const float saturation,
  63502. const float brightness,
  63503. const float alpha) throw()
  63504. {
  63505. return Colour (hue, saturation, brightness, alpha);
  63506. }
  63507. Colour::Colour (const float hue,
  63508. const float saturation,
  63509. const float brightness,
  63510. const uint8 alpha) throw()
  63511. {
  63512. uint8 r = getRed(), g = getGreen(), b = getBlue();
  63513. convertHSBtoRGB (hue, saturation, brightness, r, g, b);
  63514. argb.setARGB (alpha, r, g, b);
  63515. }
  63516. Colour::~Colour() throw()
  63517. {
  63518. }
  63519. const PixelARGB Colour::getPixelARGB() const throw()
  63520. {
  63521. PixelARGB p (argb);
  63522. p.premultiply();
  63523. return p;
  63524. }
  63525. uint32 Colour::getARGB() const throw()
  63526. {
  63527. return argb.getARGB();
  63528. }
  63529. bool Colour::isTransparent() const throw()
  63530. {
  63531. return getAlpha() == 0;
  63532. }
  63533. bool Colour::isOpaque() const throw()
  63534. {
  63535. return getAlpha() == 0xff;
  63536. }
  63537. const Colour Colour::withAlpha (const uint8 newAlpha) const throw()
  63538. {
  63539. PixelARGB newCol (argb);
  63540. newCol.setAlpha (newAlpha);
  63541. return Colour (newCol.getARGB());
  63542. }
  63543. const Colour Colour::withAlpha (const float newAlpha) const throw()
  63544. {
  63545. jassert (newAlpha >= 0 && newAlpha <= 1.0f);
  63546. PixelARGB newCol (argb);
  63547. newCol.setAlpha (floatAlphaToInt (newAlpha));
  63548. return Colour (newCol.getARGB());
  63549. }
  63550. const Colour Colour::withMultipliedAlpha (const float alphaMultiplier) const throw()
  63551. {
  63552. jassert (alphaMultiplier >= 0);
  63553. PixelARGB newCol (argb);
  63554. newCol.setAlpha ((uint8) jmin (0xff, roundToInt (alphaMultiplier * newCol.getAlpha())));
  63555. return Colour (newCol.getARGB());
  63556. }
  63557. const Colour Colour::overlaidWith (const Colour& src) const throw()
  63558. {
  63559. const int destAlpha = getAlpha();
  63560. if (destAlpha > 0)
  63561. {
  63562. const int invA = 0xff - (int) src.getAlpha();
  63563. const int resA = 0xff - (((0xff - destAlpha) * invA) >> 8);
  63564. if (resA > 0)
  63565. {
  63566. const int da = (invA * destAlpha) / resA;
  63567. return Colour ((uint8) (src.getRed() + ((((int) getRed() - src.getRed()) * da) >> 8)),
  63568. (uint8) (src.getGreen() + ((((int) getGreen() - src.getGreen()) * da) >> 8)),
  63569. (uint8) (src.getBlue() + ((((int) getBlue() - src.getBlue()) * da) >> 8)),
  63570. (uint8) resA);
  63571. }
  63572. return *this;
  63573. }
  63574. else
  63575. {
  63576. return src;
  63577. }
  63578. }
  63579. const Colour Colour::interpolatedWith (const Colour& other, float proportionOfOther) const throw()
  63580. {
  63581. if (proportionOfOther <= 0)
  63582. return *this;
  63583. if (proportionOfOther >= 1.0f)
  63584. return other;
  63585. PixelARGB c1 (getPixelARGB());
  63586. const PixelARGB c2 (other.getPixelARGB());
  63587. c1.tween (c2, roundToInt (proportionOfOther * 255.0f));
  63588. c1.unpremultiply();
  63589. return Colour (c1.getARGB());
  63590. }
  63591. float Colour::getFloatRed() const throw()
  63592. {
  63593. return getRed() * oneOver255;
  63594. }
  63595. float Colour::getFloatGreen() const throw()
  63596. {
  63597. return getGreen() * oneOver255;
  63598. }
  63599. float Colour::getFloatBlue() const throw()
  63600. {
  63601. return getBlue() * oneOver255;
  63602. }
  63603. float Colour::getFloatAlpha() const throw()
  63604. {
  63605. return getAlpha() * oneOver255;
  63606. }
  63607. void Colour::getHSB (float& h, float& s, float& v) const throw()
  63608. {
  63609. const int r = getRed();
  63610. const int g = getGreen();
  63611. const int b = getBlue();
  63612. const int hi = jmax (r, g, b);
  63613. const int lo = jmin (r, g, b);
  63614. if (hi != 0)
  63615. {
  63616. s = (hi - lo) / (float) hi;
  63617. if (s != 0)
  63618. {
  63619. const float invDiff = 1.0f / (hi - lo);
  63620. const float red = (hi - r) * invDiff;
  63621. const float green = (hi - g) * invDiff;
  63622. const float blue = (hi - b) * invDiff;
  63623. if (r == hi)
  63624. h = blue - green;
  63625. else if (g == hi)
  63626. h = 2.0f + red - blue;
  63627. else
  63628. h = 4.0f + green - red;
  63629. h *= 1.0f / 6.0f;
  63630. if (h < 0)
  63631. ++h;
  63632. }
  63633. else
  63634. {
  63635. h = 0;
  63636. }
  63637. }
  63638. else
  63639. {
  63640. s = 0;
  63641. h = 0;
  63642. }
  63643. v = hi * oneOver255;
  63644. }
  63645. float Colour::getHue() const throw()
  63646. {
  63647. float h, s, b;
  63648. getHSB (h, s, b);
  63649. return h;
  63650. }
  63651. const Colour Colour::withHue (const float hue) const throw()
  63652. {
  63653. float h, s, b;
  63654. getHSB (h, s, b);
  63655. return Colour (hue, s, b, getAlpha());
  63656. }
  63657. const Colour Colour::withRotatedHue (const float amountToRotate) const throw()
  63658. {
  63659. float h, s, b;
  63660. getHSB (h, s, b);
  63661. h += amountToRotate;
  63662. h -= floorf (h);
  63663. return Colour (h, s, b, getAlpha());
  63664. }
  63665. float Colour::getSaturation() const throw()
  63666. {
  63667. float h, s, b;
  63668. getHSB (h, s, b);
  63669. return s;
  63670. }
  63671. const Colour Colour::withSaturation (const float saturation) const throw()
  63672. {
  63673. float h, s, b;
  63674. getHSB (h, s, b);
  63675. return Colour (h, saturation, b, getAlpha());
  63676. }
  63677. const Colour Colour::withMultipliedSaturation (const float amount) const throw()
  63678. {
  63679. float h, s, b;
  63680. getHSB (h, s, b);
  63681. return Colour (h, jmin (1.0f, s * amount), b, getAlpha());
  63682. }
  63683. float Colour::getBrightness() const throw()
  63684. {
  63685. float h, s, b;
  63686. getHSB (h, s, b);
  63687. return b;
  63688. }
  63689. const Colour Colour::withBrightness (const float brightness) const throw()
  63690. {
  63691. float h, s, b;
  63692. getHSB (h, s, b);
  63693. return Colour (h, s, brightness, getAlpha());
  63694. }
  63695. const Colour Colour::withMultipliedBrightness (const float amount) const throw()
  63696. {
  63697. float h, s, b;
  63698. getHSB (h, s, b);
  63699. b *= amount;
  63700. if (b > 1.0f)
  63701. b = 1.0f;
  63702. return Colour (h, s, b, getAlpha());
  63703. }
  63704. const Colour Colour::brighter (float amount) const throw()
  63705. {
  63706. amount = 1.0f / (1.0f + amount);
  63707. return Colour ((uint8) (255 - (amount * (255 - getRed()))),
  63708. (uint8) (255 - (amount * (255 - getGreen()))),
  63709. (uint8) (255 - (amount * (255 - getBlue()))),
  63710. getAlpha());
  63711. }
  63712. const Colour Colour::darker (float amount) const throw()
  63713. {
  63714. amount = 1.0f / (1.0f + amount);
  63715. return Colour ((uint8) (amount * getRed()),
  63716. (uint8) (amount * getGreen()),
  63717. (uint8) (amount * getBlue()),
  63718. getAlpha());
  63719. }
  63720. const Colour Colour::greyLevel (const float brightness) throw()
  63721. {
  63722. const uint8 level
  63723. = (uint8) jlimit (0x00, 0xff, roundToInt (brightness * 255.0f));
  63724. return Colour (level, level, level);
  63725. }
  63726. const Colour Colour::contrasting (const float amount) const throw()
  63727. {
  63728. return overlaidWith ((((int) getRed() + (int) getGreen() + (int) getBlue() >= 3 * 128)
  63729. ? Colours::black
  63730. : Colours::white).withAlpha (amount));
  63731. }
  63732. const Colour Colour::contrasting (const Colour& colour1,
  63733. const Colour& colour2) throw()
  63734. {
  63735. const float b1 = colour1.getBrightness();
  63736. const float b2 = colour2.getBrightness();
  63737. float best = 0.0f;
  63738. float bestDist = 0.0f;
  63739. for (float i = 0.0f; i < 1.0f; i += 0.02f)
  63740. {
  63741. const float d1 = fabsf (i - b1);
  63742. const float d2 = fabsf (i - b2);
  63743. const float dist = jmin (d1, d2, 1.0f - d1, 1.0f - d2);
  63744. if (dist > bestDist)
  63745. {
  63746. best = i;
  63747. bestDist = dist;
  63748. }
  63749. }
  63750. return colour1.overlaidWith (colour2.withMultipliedAlpha (0.5f))
  63751. .withBrightness (best);
  63752. }
  63753. const String Colour::toString() const throw()
  63754. {
  63755. return String::toHexString ((int) argb.getARGB());
  63756. }
  63757. const Colour Colour::fromString (const String& encodedColourString)
  63758. {
  63759. return Colour ((uint32) encodedColourString.getHexValue32());
  63760. }
  63761. END_JUCE_NAMESPACE
  63762. /********* End of inlined file: juce_Colour.cpp *********/
  63763. /********* Start of inlined file: juce_ColourGradient.cpp *********/
  63764. BEGIN_JUCE_NAMESPACE
  63765. ColourGradient::ColourGradient() throw()
  63766. {
  63767. #ifdef JUCE_DEBUG
  63768. x1 = 987654.0f;
  63769. #endif
  63770. }
  63771. ColourGradient::ColourGradient (const Colour& colour1,
  63772. const float x1_,
  63773. const float y1_,
  63774. const Colour& colour2,
  63775. const float x2_,
  63776. const float y2_,
  63777. const bool isRadial_) throw()
  63778. : x1 (x1_),
  63779. y1 (y1_),
  63780. x2 (x2_),
  63781. y2 (y2_),
  63782. isRadial (isRadial_)
  63783. {
  63784. colours.add (0);
  63785. colours.add (colour1.getARGB());
  63786. colours.add (1 << 16);
  63787. colours.add (colour2.getARGB());
  63788. }
  63789. ColourGradient::~ColourGradient() throw()
  63790. {
  63791. }
  63792. void ColourGradient::clearColours() throw()
  63793. {
  63794. colours.clear();
  63795. }
  63796. void ColourGradient::addColour (const double proportionAlongGradient,
  63797. const Colour& colour) throw()
  63798. {
  63799. // must be within the two end-points
  63800. jassert (proportionAlongGradient >= 0 && proportionAlongGradient <= 1.0);
  63801. const uint32 pos = jlimit (0, 65535, roundToInt (proportionAlongGradient * 65536.0));
  63802. int i;
  63803. for (i = 0; i < colours.size(); i += 2)
  63804. if (colours.getUnchecked(i) > pos)
  63805. break;
  63806. colours.insert (i, pos);
  63807. colours.insert (i + 1, colour.getARGB());
  63808. }
  63809. void ColourGradient::multiplyOpacity (const float multiplier) throw()
  63810. {
  63811. for (int i = 1; i < colours.size(); i += 2)
  63812. {
  63813. const Colour c (colours.getUnchecked(i));
  63814. colours.set (i, c.withMultipliedAlpha (multiplier).getARGB());
  63815. }
  63816. }
  63817. int ColourGradient::getNumColours() const throw()
  63818. {
  63819. return colours.size() >> 1;
  63820. }
  63821. double ColourGradient::getColourPosition (const int index) const throw()
  63822. {
  63823. return jlimit (0.0, 1.0, colours [index << 1] / 65535.0);
  63824. }
  63825. const Colour ColourGradient::getColour (const int index) const throw()
  63826. {
  63827. return Colour (colours [(index << 1) + 1]);
  63828. }
  63829. const Colour ColourGradient::getColourAtPosition (const float position) const throw()
  63830. {
  63831. jassert (colours.getUnchecked (0) == 0); // the first colour specified has to go at position 0
  63832. const int integerPos = jlimit (0, 65535, roundToInt (position * 65536.0f));
  63833. if (integerPos <= 0 || colours.size() <= 2)
  63834. return getColour (0);
  63835. int i = colours.size() - 2;
  63836. while (integerPos < (int) colours.getUnchecked(i))
  63837. i -= 2;
  63838. if (i >= colours.size() - 2)
  63839. return Colour (colours.getUnchecked(i));
  63840. const int pos1 = colours.getUnchecked (i);
  63841. const Colour col1 (colours.getUnchecked (i + 1));
  63842. const int pos2 = colours.getUnchecked (i + 2);
  63843. const Colour col2 (colours.getUnchecked (i + 3));
  63844. return col1.interpolatedWith (col2, (integerPos - pos1) / (float) (pos2 - pos1));
  63845. }
  63846. int ColourGradient::createLookupTable (const AffineTransform& transform, HeapBlock <PixelARGB>& lookupTable) const throw()
  63847. {
  63848. #ifdef JUCE_DEBUG
  63849. // trying to use the object without setting its co-ordinates? Have a careful read of
  63850. // the comments for the constructors.
  63851. jassert (x1 != 987654.0f);
  63852. #endif
  63853. const int numColours = colours.size() >> 1;
  63854. float tx1 = x1, ty1 = y1, tx2 = x2, ty2 = y2;
  63855. transform.transformPoint (tx1, ty1);
  63856. transform.transformPoint (tx2, ty2);
  63857. const double distance = juce_hypot (tx1 - tx2, ty1 - ty2);
  63858. const int numEntries = jlimit (1, (numColours - 1) << 8, 3 * (int) distance);
  63859. lookupTable.malloc (numEntries);
  63860. if (numColours >= 2)
  63861. {
  63862. jassert (colours.getUnchecked (0) == 0); // the first colour specified has to go at position 0
  63863. PixelARGB pix1 (colours.getUnchecked (1));
  63864. pix1.premultiply();
  63865. int index = 0;
  63866. for (int j = 2; j < colours.size(); j += 2)
  63867. {
  63868. const int numToDo = ((colours.getUnchecked (j) * (numEntries - 1)) >> 16) - index;
  63869. PixelARGB pix2 (colours.getUnchecked (j + 1));
  63870. pix2.premultiply();
  63871. for (int i = 0; i < numToDo; ++i)
  63872. {
  63873. jassert (index >= 0 && index < numEntries);
  63874. lookupTable[index] = pix1;
  63875. lookupTable[index].tween (pix2, (i << 8) / numToDo);
  63876. ++index;
  63877. }
  63878. pix1 = pix2;
  63879. }
  63880. while (index < numEntries)
  63881. lookupTable [index++] = pix1;
  63882. }
  63883. else
  63884. {
  63885. jassertfalse // no colours specified!
  63886. }
  63887. return numEntries;
  63888. }
  63889. bool ColourGradient::isOpaque() const throw()
  63890. {
  63891. for (int i = 1; i < colours.size(); i += 2)
  63892. if (PixelARGB (colours.getUnchecked(i)).getAlpha() < 0xff)
  63893. return false;
  63894. return true;
  63895. }
  63896. bool ColourGradient::isInvisible() const throw()
  63897. {
  63898. for (int i = 1; i < colours.size(); i += 2)
  63899. if (PixelARGB (colours.getUnchecked(i)).getAlpha() > 0)
  63900. return false;
  63901. return true;
  63902. }
  63903. END_JUCE_NAMESPACE
  63904. /********* End of inlined file: juce_ColourGradient.cpp *********/
  63905. /********* Start of inlined file: juce_Colours.cpp *********/
  63906. BEGIN_JUCE_NAMESPACE
  63907. const Colour Colours::transparentBlack (0);
  63908. const Colour Colours::transparentWhite (0x00ffffff);
  63909. const Colour Colours::aliceblue (0xfff0f8ff);
  63910. const Colour Colours::antiquewhite (0xfffaebd7);
  63911. const Colour Colours::aqua (0xff00ffff);
  63912. const Colour Colours::aquamarine (0xff7fffd4);
  63913. const Colour Colours::azure (0xfff0ffff);
  63914. const Colour Colours::beige (0xfff5f5dc);
  63915. const Colour Colours::bisque (0xffffe4c4);
  63916. const Colour Colours::black (0xff000000);
  63917. const Colour Colours::blanchedalmond (0xffffebcd);
  63918. const Colour Colours::blue (0xff0000ff);
  63919. const Colour Colours::blueviolet (0xff8a2be2);
  63920. const Colour Colours::brown (0xffa52a2a);
  63921. const Colour Colours::burlywood (0xffdeb887);
  63922. const Colour Colours::cadetblue (0xff5f9ea0);
  63923. const Colour Colours::chartreuse (0xff7fff00);
  63924. const Colour Colours::chocolate (0xffd2691e);
  63925. const Colour Colours::coral (0xffff7f50);
  63926. const Colour Colours::cornflowerblue (0xff6495ed);
  63927. const Colour Colours::cornsilk (0xfffff8dc);
  63928. const Colour Colours::crimson (0xffdc143c);
  63929. const Colour Colours::cyan (0xff00ffff);
  63930. const Colour Colours::darkblue (0xff00008b);
  63931. const Colour Colours::darkcyan (0xff008b8b);
  63932. const Colour Colours::darkgoldenrod (0xffb8860b);
  63933. const Colour Colours::darkgrey (0xff555555);
  63934. const Colour Colours::darkgreen (0xff006400);
  63935. const Colour Colours::darkkhaki (0xffbdb76b);
  63936. const Colour Colours::darkmagenta (0xff8b008b);
  63937. const Colour Colours::darkolivegreen (0xff556b2f);
  63938. const Colour Colours::darkorange (0xffff8c00);
  63939. const Colour Colours::darkorchid (0xff9932cc);
  63940. const Colour Colours::darkred (0xff8b0000);
  63941. const Colour Colours::darksalmon (0xffe9967a);
  63942. const Colour Colours::darkseagreen (0xff8fbc8f);
  63943. const Colour Colours::darkslateblue (0xff483d8b);
  63944. const Colour Colours::darkslategrey (0xff2f4f4f);
  63945. const Colour Colours::darkturquoise (0xff00ced1);
  63946. const Colour Colours::darkviolet (0xff9400d3);
  63947. const Colour Colours::deeppink (0xffff1493);
  63948. const Colour Colours::deepskyblue (0xff00bfff);
  63949. const Colour Colours::dimgrey (0xff696969);
  63950. const Colour Colours::dodgerblue (0xff1e90ff);
  63951. const Colour Colours::firebrick (0xffb22222);
  63952. const Colour Colours::floralwhite (0xfffffaf0);
  63953. const Colour Colours::forestgreen (0xff228b22);
  63954. const Colour Colours::fuchsia (0xffff00ff);
  63955. const Colour Colours::gainsboro (0xffdcdcdc);
  63956. const Colour Colours::gold (0xffffd700);
  63957. const Colour Colours::goldenrod (0xffdaa520);
  63958. const Colour Colours::grey (0xff808080);
  63959. const Colour Colours::green (0xff008000);
  63960. const Colour Colours::greenyellow (0xffadff2f);
  63961. const Colour Colours::honeydew (0xfff0fff0);
  63962. const Colour Colours::hotpink (0xffff69b4);
  63963. const Colour Colours::indianred (0xffcd5c5c);
  63964. const Colour Colours::indigo (0xff4b0082);
  63965. const Colour Colours::ivory (0xfffffff0);
  63966. const Colour Colours::khaki (0xfff0e68c);
  63967. const Colour Colours::lavender (0xffe6e6fa);
  63968. const Colour Colours::lavenderblush (0xfffff0f5);
  63969. const Colour Colours::lemonchiffon (0xfffffacd);
  63970. const Colour Colours::lightblue (0xffadd8e6);
  63971. const Colour Colours::lightcoral (0xfff08080);
  63972. const Colour Colours::lightcyan (0xffe0ffff);
  63973. const Colour Colours::lightgoldenrodyellow (0xfffafad2);
  63974. const Colour Colours::lightgreen (0xff90ee90);
  63975. const Colour Colours::lightgrey (0xffd3d3d3);
  63976. const Colour Colours::lightpink (0xffffb6c1);
  63977. const Colour Colours::lightsalmon (0xffffa07a);
  63978. const Colour Colours::lightseagreen (0xff20b2aa);
  63979. const Colour Colours::lightskyblue (0xff87cefa);
  63980. const Colour Colours::lightslategrey (0xff778899);
  63981. const Colour Colours::lightsteelblue (0xffb0c4de);
  63982. const Colour Colours::lightyellow (0xffffffe0);
  63983. const Colour Colours::lime (0xff00ff00);
  63984. const Colour Colours::limegreen (0xff32cd32);
  63985. const Colour Colours::linen (0xfffaf0e6);
  63986. const Colour Colours::magenta (0xffff00ff);
  63987. const Colour Colours::maroon (0xff800000);
  63988. const Colour Colours::mediumaquamarine (0xff66cdaa);
  63989. const Colour Colours::mediumblue (0xff0000cd);
  63990. const Colour Colours::mediumorchid (0xffba55d3);
  63991. const Colour Colours::mediumpurple (0xff9370db);
  63992. const Colour Colours::mediumseagreen (0xff3cb371);
  63993. const Colour Colours::mediumslateblue (0xff7b68ee);
  63994. const Colour Colours::mediumspringgreen (0xff00fa9a);
  63995. const Colour Colours::mediumturquoise (0xff48d1cc);
  63996. const Colour Colours::mediumvioletred (0xffc71585);
  63997. const Colour Colours::midnightblue (0xff191970);
  63998. const Colour Colours::mintcream (0xfff5fffa);
  63999. const Colour Colours::mistyrose (0xffffe4e1);
  64000. const Colour Colours::navajowhite (0xffffdead);
  64001. const Colour Colours::navy (0xff000080);
  64002. const Colour Colours::oldlace (0xfffdf5e6);
  64003. const Colour Colours::olive (0xff808000);
  64004. const Colour Colours::olivedrab (0xff6b8e23);
  64005. const Colour Colours::orange (0xffffa500);
  64006. const Colour Colours::orangered (0xffff4500);
  64007. const Colour Colours::orchid (0xffda70d6);
  64008. const Colour Colours::palegoldenrod (0xffeee8aa);
  64009. const Colour Colours::palegreen (0xff98fb98);
  64010. const Colour Colours::paleturquoise (0xffafeeee);
  64011. const Colour Colours::palevioletred (0xffdb7093);
  64012. const Colour Colours::papayawhip (0xffffefd5);
  64013. const Colour Colours::peachpuff (0xffffdab9);
  64014. const Colour Colours::peru (0xffcd853f);
  64015. const Colour Colours::pink (0xffffc0cb);
  64016. const Colour Colours::plum (0xffdda0dd);
  64017. const Colour Colours::powderblue (0xffb0e0e6);
  64018. const Colour Colours::purple (0xff800080);
  64019. const Colour Colours::red (0xffff0000);
  64020. const Colour Colours::rosybrown (0xffbc8f8f);
  64021. const Colour Colours::royalblue (0xff4169e1);
  64022. const Colour Colours::saddlebrown (0xff8b4513);
  64023. const Colour Colours::salmon (0xfffa8072);
  64024. const Colour Colours::sandybrown (0xfff4a460);
  64025. const Colour Colours::seagreen (0xff2e8b57);
  64026. const Colour Colours::seashell (0xfffff5ee);
  64027. const Colour Colours::sienna (0xffa0522d);
  64028. const Colour Colours::silver (0xffc0c0c0);
  64029. const Colour Colours::skyblue (0xff87ceeb);
  64030. const Colour Colours::slateblue (0xff6a5acd);
  64031. const Colour Colours::slategrey (0xff708090);
  64032. const Colour Colours::snow (0xfffffafa);
  64033. const Colour Colours::springgreen (0xff00ff7f);
  64034. const Colour Colours::steelblue (0xff4682b4);
  64035. const Colour Colours::tan (0xffd2b48c);
  64036. const Colour Colours::teal (0xff008080);
  64037. const Colour Colours::thistle (0xffd8bfd8);
  64038. const Colour Colours::tomato (0xffff6347);
  64039. const Colour Colours::turquoise (0xff40e0d0);
  64040. const Colour Colours::violet (0xffee82ee);
  64041. const Colour Colours::wheat (0xfff5deb3);
  64042. const Colour Colours::white (0xffffffff);
  64043. const Colour Colours::whitesmoke (0xfff5f5f5);
  64044. const Colour Colours::yellow (0xffffff00);
  64045. const Colour Colours::yellowgreen (0xff9acd32);
  64046. const Colour Colours::findColourForName (const String& colourName,
  64047. const Colour& defaultColour)
  64048. {
  64049. static const int presets[] =
  64050. {
  64051. // (first value is the string's hashcode, second is ARGB)
  64052. 0x05978fff, 0xff000000, /* black */
  64053. 0x06bdcc29, 0xffffffff, /* white */
  64054. 0x002e305a, 0xff0000ff, /* blue */
  64055. 0x00308adf, 0xff808080, /* grey */
  64056. 0x05e0cf03, 0xff008000, /* green */
  64057. 0x0001b891, 0xffff0000, /* red */
  64058. 0xd43c6474, 0xffffff00, /* yellow */
  64059. 0x620886da, 0xfff0f8ff, /* aliceblue */
  64060. 0x20a2676a, 0xfffaebd7, /* antiquewhite */
  64061. 0x002dcebc, 0xff00ffff, /* aqua */
  64062. 0x46bb5f7e, 0xff7fffd4, /* aquamarine */
  64063. 0x0590228f, 0xfff0ffff, /* azure */
  64064. 0x05947fe4, 0xfff5f5dc, /* beige */
  64065. 0xad388e35, 0xffffe4c4, /* bisque */
  64066. 0x00674f7e, 0xffffebcd, /* blanchedalmond */
  64067. 0x39129959, 0xff8a2be2, /* blueviolet */
  64068. 0x059a8136, 0xffa52a2a, /* brown */
  64069. 0x89cea8f9, 0xffdeb887, /* burlywood */
  64070. 0x0fa260cf, 0xff5f9ea0, /* cadetblue */
  64071. 0x6b748956, 0xff7fff00, /* chartreuse */
  64072. 0x2903623c, 0xffd2691e, /* chocolate */
  64073. 0x05a74431, 0xffff7f50, /* coral */
  64074. 0x618d42dd, 0xff6495ed, /* cornflowerblue */
  64075. 0xe4b479fd, 0xfffff8dc, /* cornsilk */
  64076. 0x3d8c4edf, 0xffdc143c, /* crimson */
  64077. 0x002ed323, 0xff00ffff, /* cyan */
  64078. 0x67cc74d0, 0xff00008b, /* darkblue */
  64079. 0x67cd1799, 0xff008b8b, /* darkcyan */
  64080. 0x31bbd168, 0xffb8860b, /* darkgoldenrod */
  64081. 0x67cecf55, 0xff555555, /* darkgrey */
  64082. 0x920b194d, 0xff006400, /* darkgreen */
  64083. 0x923edd4c, 0xffbdb76b, /* darkkhaki */
  64084. 0x5c293873, 0xff8b008b, /* darkmagenta */
  64085. 0x6b6671fe, 0xff556b2f, /* darkolivegreen */
  64086. 0xbcfd2524, 0xffff8c00, /* darkorange */
  64087. 0xbcfdf799, 0xff9932cc, /* darkorchid */
  64088. 0x55ee0d5b, 0xff8b0000, /* darkred */
  64089. 0xc2e5f564, 0xffe9967a, /* darksalmon */
  64090. 0x61be858a, 0xff8fbc8f, /* darkseagreen */
  64091. 0xc2b0f2bd, 0xff483d8b, /* darkslateblue */
  64092. 0xc2b34d42, 0xff2f4f4f, /* darkslategrey */
  64093. 0x7cf2b06b, 0xff00ced1, /* darkturquoise */
  64094. 0xc8769375, 0xff9400d3, /* darkviolet */
  64095. 0x25832862, 0xffff1493, /* deeppink */
  64096. 0xfcad568f, 0xff00bfff, /* deepskyblue */
  64097. 0x634c8b67, 0xff696969, /* dimgrey */
  64098. 0x45c1ce55, 0xff1e90ff, /* dodgerblue */
  64099. 0xef19e3cb, 0xffb22222, /* firebrick */
  64100. 0xb852b195, 0xfffffaf0, /* floralwhite */
  64101. 0xd086fd06, 0xff228b22, /* forestgreen */
  64102. 0xe106b6d7, 0xffff00ff, /* fuchsia */
  64103. 0x7880d61e, 0xffdcdcdc, /* gainsboro */
  64104. 0x00308060, 0xffffd700, /* gold */
  64105. 0xb3b3bc1e, 0xffdaa520, /* goldenrod */
  64106. 0xbab8a537, 0xffadff2f, /* greenyellow */
  64107. 0xe4cacafb, 0xfff0fff0, /* honeydew */
  64108. 0x41892743, 0xffff69b4, /* hotpink */
  64109. 0xd5796f1a, 0xffcd5c5c, /* indianred */
  64110. 0xb969fed2, 0xff4b0082, /* indigo */
  64111. 0x05fef6a9, 0xfffffff0, /* ivory */
  64112. 0x06149302, 0xfff0e68c, /* khaki */
  64113. 0xad5a05c7, 0xffe6e6fa, /* lavender */
  64114. 0x7c4d5b99, 0xfffff0f5, /* lavenderblush */
  64115. 0x195756f0, 0xfffffacd, /* lemonchiffon */
  64116. 0x28e4ea70, 0xffadd8e6, /* lightblue */
  64117. 0xf3c7ccdb, 0xfff08080, /* lightcoral */
  64118. 0x28e58d39, 0xffe0ffff, /* lightcyan */
  64119. 0x21234e3c, 0xfffafad2, /* lightgoldenrodyellow */
  64120. 0xf40157ad, 0xff90ee90, /* lightgreen */
  64121. 0x28e744f5, 0xffd3d3d3, /* lightgrey */
  64122. 0x28eb3b8c, 0xffffb6c1, /* lightpink */
  64123. 0x9fb78304, 0xffffa07a, /* lightsalmon */
  64124. 0x50632b2a, 0xff20b2aa, /* lightseagreen */
  64125. 0x68fb7b25, 0xff87cefa, /* lightskyblue */
  64126. 0xa8a35ba2, 0xff778899, /* lightslategrey */
  64127. 0xa20d484f, 0xffb0c4de, /* lightsteelblue */
  64128. 0xaa2cf10a, 0xffffffe0, /* lightyellow */
  64129. 0x0032afd5, 0xff00ff00, /* lime */
  64130. 0x607bbc4e, 0xff32cd32, /* limegreen */
  64131. 0x06234efa, 0xfffaf0e6, /* linen */
  64132. 0x316858a9, 0xffff00ff, /* magenta */
  64133. 0xbf8ca470, 0xff800000, /* maroon */
  64134. 0xbd58e0b3, 0xff66cdaa, /* mediumaquamarine */
  64135. 0x967dfd4f, 0xff0000cd, /* mediumblue */
  64136. 0x056f5c58, 0xffba55d3, /* mediumorchid */
  64137. 0x07556b71, 0xff9370db, /* mediumpurple */
  64138. 0x5369b689, 0xff3cb371, /* mediumseagreen */
  64139. 0x066be19e, 0xff7b68ee, /* mediumslateblue */
  64140. 0x3256b281, 0xff00fa9a, /* mediumspringgreen */
  64141. 0xc0ad9f4c, 0xff48d1cc, /* mediumturquoise */
  64142. 0x628e63dd, 0xffc71585, /* mediumvioletred */
  64143. 0x168eb32a, 0xff191970, /* midnightblue */
  64144. 0x4306b960, 0xfff5fffa, /* mintcream */
  64145. 0x4cbc0e6b, 0xffffe4e1, /* mistyrose */
  64146. 0xe97218a6, 0xffffdead, /* navajowhite */
  64147. 0x00337bb6, 0xff000080, /* navy */
  64148. 0xadd2d33e, 0xfffdf5e6, /* oldlace */
  64149. 0x064ee1db, 0xff808000, /* olive */
  64150. 0x9e33a98a, 0xff6b8e23, /* olivedrab */
  64151. 0xc3de262e, 0xffffa500, /* orange */
  64152. 0x58bebba3, 0xffff4500, /* orangered */
  64153. 0xc3def8a3, 0xffda70d6, /* orchid */
  64154. 0x28cb4834, 0xffeee8aa, /* palegoldenrod */
  64155. 0x3d9dd619, 0xff98fb98, /* palegreen */
  64156. 0x74022737, 0xffafeeee, /* paleturquoise */
  64157. 0x15e2ebc8, 0xffdb7093, /* palevioletred */
  64158. 0x5fd898e2, 0xffffefd5, /* papayawhip */
  64159. 0x93e1b776, 0xffffdab9, /* peachpuff */
  64160. 0x003472f8, 0xffcd853f, /* peru */
  64161. 0x00348176, 0xffffc0cb, /* pink */
  64162. 0x00348d94, 0xffdda0dd, /* plum */
  64163. 0xd036be93, 0xffb0e0e6, /* powderblue */
  64164. 0xc5c507bc, 0xff800080, /* purple */
  64165. 0xa89d65b3, 0xffbc8f8f, /* rosybrown */
  64166. 0xbd9413e1, 0xff4169e1, /* royalblue */
  64167. 0xf456044f, 0xff8b4513, /* saddlebrown */
  64168. 0xc9c6f66e, 0xfffa8072, /* salmon */
  64169. 0x0bb131e1, 0xfff4a460, /* sandybrown */
  64170. 0x34636c14, 0xff2e8b57, /* seagreen */
  64171. 0x3507fb41, 0xfffff5ee, /* seashell */
  64172. 0xca348772, 0xffa0522d, /* sienna */
  64173. 0xca37d30d, 0xffc0c0c0, /* silver */
  64174. 0x80da74fb, 0xff87ceeb, /* skyblue */
  64175. 0x44a8dd73, 0xff6a5acd, /* slateblue */
  64176. 0x44ab37f8, 0xff708090, /* slategrey */
  64177. 0x0035f183, 0xfffffafa, /* snow */
  64178. 0xd5440d16, 0xff00ff7f, /* springgreen */
  64179. 0x3e1524a5, 0xff4682b4, /* steelblue */
  64180. 0x0001bfa1, 0xffd2b48c, /* tan */
  64181. 0x0036425c, 0xff008080, /* teal */
  64182. 0xafc8858f, 0xffd8bfd8, /* thistle */
  64183. 0xcc41600a, 0xffff6347, /* tomato */
  64184. 0xfeea9b21, 0xff40e0d0, /* turquoise */
  64185. 0xcf57947f, 0xffee82ee, /* violet */
  64186. 0x06bdbae7, 0xfff5deb3, /* wheat */
  64187. 0x10802ee6, 0xfff5f5f5, /* whitesmoke */
  64188. 0xe1b5130f, 0xff9acd32 /* yellowgreen */
  64189. };
  64190. const int hash = colourName.trim().toLowerCase().hashCode();
  64191. for (int i = 0; i < numElementsInArray (presets); i += 2)
  64192. if (presets [i] == hash)
  64193. return Colour (presets [i + 1]);
  64194. return defaultColour;
  64195. }
  64196. END_JUCE_NAMESPACE
  64197. /********* End of inlined file: juce_Colours.cpp *********/
  64198. /********* Start of inlined file: juce_EdgeTable.cpp *********/
  64199. BEGIN_JUCE_NAMESPACE
  64200. const int juce_edgeTableDefaultEdgesPerLine = 32;
  64201. static void copyEdgeTableData (int* dest, const int destLineStride, const int* src, const int srcLineStride, int numLines) throw()
  64202. {
  64203. while (--numLines >= 0)
  64204. {
  64205. memcpy (dest, src, (src[0] * 2 + 1) * sizeof (int));
  64206. src += srcLineStride;
  64207. dest += destLineStride;
  64208. }
  64209. }
  64210. EdgeTable::EdgeTable (const Rectangle& bounds_,
  64211. const Path& path, const AffineTransform& transform) throw()
  64212. : bounds (bounds_),
  64213. maxEdgesPerLine (juce_edgeTableDefaultEdgesPerLine),
  64214. lineStrideElements ((juce_edgeTableDefaultEdgesPerLine << 1) + 1),
  64215. needToCheckEmptinesss (true)
  64216. {
  64217. table.malloc ((bounds.getHeight() + 1) * lineStrideElements);
  64218. int* t = table;
  64219. for (int i = bounds.getHeight(); --i >= 0;)
  64220. {
  64221. *t = 0;
  64222. t += lineStrideElements;
  64223. }
  64224. const int topLimit = bounds.getY() << 8;
  64225. const int heightLimit = bounds.getHeight() << 8;
  64226. const int leftLimit = bounds.getX() << 8;
  64227. const int rightLimit = bounds.getRight() << 8;
  64228. PathFlatteningIterator iter (path, transform);
  64229. while (iter.next())
  64230. {
  64231. int y1 = roundToInt (iter.y1 * 256.0f);
  64232. int y2 = roundToInt (iter.y2 * 256.0f);
  64233. if (y1 != y2)
  64234. {
  64235. y1 -= topLimit;
  64236. y2 -= topLimit;
  64237. const int startY = y1;
  64238. int direction = -1;
  64239. if (y1 > y2)
  64240. {
  64241. swapVariables (y1, y2);
  64242. direction = 1;
  64243. }
  64244. if (y1 < 0)
  64245. y1 = 0;
  64246. if (y2 > heightLimit)
  64247. y2 = heightLimit;
  64248. if (y1 < y2)
  64249. {
  64250. const double startX = 256.0f * iter.x1;
  64251. const double multiplier = (iter.x2 - iter.x1) / (iter.y2 - iter.y1);
  64252. const int stepSize = jlimit (1, 256, 256 / (1 + (int) fabs (multiplier)));
  64253. do
  64254. {
  64255. const int step = jmin (stepSize, y2 - y1, 256 - (y1 & 255));
  64256. int x = roundToInt (startX + multiplier * ((y1 + (step >> 1)) - startY));
  64257. if (x < leftLimit)
  64258. x = leftLimit;
  64259. else if (x >= rightLimit)
  64260. x = rightLimit - 1;
  64261. addEdgePoint (x, y1 >> 8, direction * step);
  64262. y1 += step;
  64263. }
  64264. while (y1 < y2);
  64265. }
  64266. }
  64267. }
  64268. sanitiseLevels (path.isUsingNonZeroWinding());
  64269. }
  64270. EdgeTable::EdgeTable (const Rectangle& rectangleToAdd) throw()
  64271. : bounds (rectangleToAdd),
  64272. maxEdgesPerLine (juce_edgeTableDefaultEdgesPerLine),
  64273. lineStrideElements ((juce_edgeTableDefaultEdgesPerLine << 1) + 1),
  64274. needToCheckEmptinesss (true)
  64275. {
  64276. table.malloc (jmax (1, bounds.getHeight()) * lineStrideElements);
  64277. table[0] = 0;
  64278. const int x1 = rectangleToAdd.getX() << 8;
  64279. const int x2 = rectangleToAdd.getRight() << 8;
  64280. int* t = table;
  64281. for (int i = rectangleToAdd.getHeight(); --i >= 0;)
  64282. {
  64283. t[0] = 2;
  64284. t[1] = x1;
  64285. t[2] = 255;
  64286. t[3] = x2;
  64287. t[4] = 0;
  64288. t += lineStrideElements;
  64289. }
  64290. }
  64291. EdgeTable::EdgeTable (const RectangleList& rectanglesToAdd) throw()
  64292. : bounds (rectanglesToAdd.getBounds()),
  64293. maxEdgesPerLine (juce_edgeTableDefaultEdgesPerLine),
  64294. lineStrideElements ((juce_edgeTableDefaultEdgesPerLine << 1) + 1),
  64295. needToCheckEmptinesss (true)
  64296. {
  64297. table.malloc (jmax (1, bounds.getHeight()) * lineStrideElements);
  64298. int* t = table;
  64299. for (int i = bounds.getHeight(); --i >= 0;)
  64300. {
  64301. *t = 0;
  64302. t += lineStrideElements;
  64303. }
  64304. for (RectangleList::Iterator iter (rectanglesToAdd); iter.next();)
  64305. {
  64306. const Rectangle* const r = iter.getRectangle();
  64307. const int x1 = r->getX() << 8;
  64308. const int x2 = r->getRight() << 8;
  64309. int y = r->getY() - bounds.getY();
  64310. for (int j = r->getHeight(); --j >= 0;)
  64311. {
  64312. addEdgePoint (x1, y, 255);
  64313. addEdgePoint (x2, y, -255);
  64314. ++y;
  64315. }
  64316. }
  64317. sanitiseLevels (true);
  64318. }
  64319. EdgeTable::EdgeTable (const float x, const float y, const float w, const float h) throw()
  64320. : bounds (Rectangle ((int) floorf (x), roundToInt (y * 256.0f) >> 8, 2 + (int) w, 2 + (int) h)),
  64321. maxEdgesPerLine (juce_edgeTableDefaultEdgesPerLine),
  64322. lineStrideElements ((juce_edgeTableDefaultEdgesPerLine << 1) + 1),
  64323. needToCheckEmptinesss (true)
  64324. {
  64325. jassert (w > 0 && h > 0);
  64326. table.malloc (jmax (1, bounds.getHeight()) * lineStrideElements);
  64327. table[0] = 0;
  64328. const int x1 = roundToInt (x * 256.0f);
  64329. const int x2 = roundToInt ((x + w) * 256.0f);
  64330. int y1 = roundToInt (y * 256.0f) - (bounds.getY() << 8);
  64331. jassert (y1 < 256);
  64332. int y2 = roundToInt ((y + h) * 256.0f) - (bounds.getY() << 8);
  64333. if (x2 <= x1 || y2 <= y1)
  64334. {
  64335. bounds.setHeight (0);
  64336. return;
  64337. }
  64338. int lineY = 0;
  64339. int* t = table;
  64340. if ((y1 >> 8) == (y2 >> 8))
  64341. {
  64342. t[0] = 2;
  64343. t[1] = x1;
  64344. t[2] = y2 - y1;
  64345. t[3] = x2;
  64346. t[4] = 0;
  64347. ++lineY;
  64348. t += lineStrideElements;
  64349. }
  64350. else
  64351. {
  64352. t[0] = 2;
  64353. t[1] = x1;
  64354. t[2] = 255 - (y1 & 255);
  64355. t[3] = x2;
  64356. t[4] = 0;
  64357. ++lineY;
  64358. t += lineStrideElements;
  64359. while (lineY < (y2 >> 8))
  64360. {
  64361. t[0] = 2;
  64362. t[1] = x1;
  64363. t[2] = 255;
  64364. t[3] = x2;
  64365. t[4] = 0;
  64366. ++lineY;
  64367. t += lineStrideElements;
  64368. }
  64369. jassert (lineY < bounds.getHeight());
  64370. t[0] = 2;
  64371. t[1] = x1;
  64372. t[2] = y2 & 255;
  64373. t[3] = x2;
  64374. t[4] = 0;
  64375. ++lineY;
  64376. t += lineStrideElements;
  64377. }
  64378. while (lineY < bounds.getHeight())
  64379. {
  64380. t[0] = 0;
  64381. t += lineStrideElements;
  64382. ++lineY;
  64383. }
  64384. }
  64385. EdgeTable::EdgeTable (const EdgeTable& other) throw()
  64386. : table (0)
  64387. {
  64388. operator= (other);
  64389. }
  64390. const EdgeTable& EdgeTable::operator= (const EdgeTable& other) throw()
  64391. {
  64392. bounds = other.bounds;
  64393. maxEdgesPerLine = other.maxEdgesPerLine;
  64394. lineStrideElements = other.lineStrideElements;
  64395. needToCheckEmptinesss = other.needToCheckEmptinesss;
  64396. table.malloc (jmax (1, bounds.getHeight()) * lineStrideElements);
  64397. copyEdgeTableData (table, lineStrideElements, other.table, lineStrideElements, bounds.getHeight());
  64398. return *this;
  64399. }
  64400. EdgeTable::~EdgeTable() throw()
  64401. {
  64402. }
  64403. void EdgeTable::sanitiseLevels (const bool useNonZeroWinding) throw()
  64404. {
  64405. // Convert the table from relative windings to absolute levels..
  64406. int* lineStart = table;
  64407. for (int i = bounds.getHeight(); --i >= 0;)
  64408. {
  64409. int* line = lineStart;
  64410. lineStart += lineStrideElements;
  64411. int num = *line;
  64412. if (num == 0)
  64413. continue;
  64414. int level = 0;
  64415. if (useNonZeroWinding)
  64416. {
  64417. while (--num > 0)
  64418. {
  64419. line += 2;
  64420. level += *line;
  64421. int corrected = abs (level);
  64422. if (corrected >> 8)
  64423. corrected = 255;
  64424. *line = corrected;
  64425. }
  64426. }
  64427. else
  64428. {
  64429. while (--num > 0)
  64430. {
  64431. line += 2;
  64432. level += *line;
  64433. int corrected = abs (level);
  64434. if (corrected >> 8)
  64435. {
  64436. corrected &= 511;
  64437. if (corrected >> 8)
  64438. corrected = 511 - corrected;
  64439. }
  64440. *line = corrected;
  64441. }
  64442. }
  64443. line[2] = 0; // force the last level to 0, just in case something went wrong in creating the table
  64444. }
  64445. }
  64446. void EdgeTable::remapTableForNumEdges (const int newNumEdgesPerLine) throw()
  64447. {
  64448. if (newNumEdgesPerLine != maxEdgesPerLine)
  64449. {
  64450. maxEdgesPerLine = newNumEdgesPerLine;
  64451. jassert (bounds.getHeight() > 0);
  64452. const int newLineStrideElements = maxEdgesPerLine * 2 + 1;
  64453. HeapBlock <int> newTable (bounds.getHeight() * newLineStrideElements);
  64454. copyEdgeTableData (newTable, newLineStrideElements, table, lineStrideElements, bounds.getHeight());
  64455. table.swapWith (newTable);
  64456. lineStrideElements = newLineStrideElements;
  64457. }
  64458. }
  64459. void EdgeTable::optimiseTable() throw()
  64460. {
  64461. int maxLineElements = 0;
  64462. for (int i = bounds.getHeight(); --i >= 0;)
  64463. maxLineElements = jmax (maxLineElements, table [i * lineStrideElements]);
  64464. remapTableForNumEdges (maxLineElements);
  64465. }
  64466. void EdgeTable::addEdgePoint (const int x, const int y, const int winding) throw()
  64467. {
  64468. jassert (y >= 0 && y < bounds.getHeight());
  64469. int* line = table + lineStrideElements * y;
  64470. const int numPoints = line[0];
  64471. int n = numPoints << 1;
  64472. if (n > 0)
  64473. {
  64474. while (n > 0)
  64475. {
  64476. const int cx = line [n - 1];
  64477. if (cx <= x)
  64478. {
  64479. if (cx == x)
  64480. {
  64481. line [n] += winding;
  64482. return;
  64483. }
  64484. break;
  64485. }
  64486. n -= 2;
  64487. }
  64488. if (numPoints >= maxEdgesPerLine)
  64489. {
  64490. remapTableForNumEdges (maxEdgesPerLine + juce_edgeTableDefaultEdgesPerLine);
  64491. jassert (numPoints < maxEdgesPerLine);
  64492. line = table + lineStrideElements * y;
  64493. }
  64494. memmove (line + (n + 3), line + (n + 1), sizeof (int) * ((numPoints << 1) - n));
  64495. }
  64496. line [n + 1] = x;
  64497. line [n + 2] = winding;
  64498. line[0]++;
  64499. }
  64500. void EdgeTable::translate (float dx, int dy) throw()
  64501. {
  64502. bounds.setPosition (bounds.getX() + (int) floorf (dx), bounds.getY() + dy);
  64503. int* lineStart = table;
  64504. const int intDx = (int) (dx * 256.0f);
  64505. for (int i = bounds.getHeight(); --i >= 0;)
  64506. {
  64507. int* line = lineStart;
  64508. lineStart += lineStrideElements;
  64509. int num = *line++;
  64510. while (--num >= 0)
  64511. {
  64512. *line += intDx;
  64513. line += 2;
  64514. }
  64515. }
  64516. }
  64517. void EdgeTable::intersectWithEdgeTableLine (const int y, const int* otherLine) throw()
  64518. {
  64519. jassert (y >= 0 && y < bounds.getHeight());
  64520. int* dest = table + lineStrideElements * y;
  64521. if (dest[0] == 0)
  64522. return;
  64523. int otherNumPoints = *otherLine;
  64524. if (otherNumPoints == 0)
  64525. {
  64526. *dest = 0;
  64527. return;
  64528. }
  64529. const int right = bounds.getRight() << 8;
  64530. // optimise for the common case where our line lies entirely within a
  64531. // single pair of points, as happens when clipping to a simple rect.
  64532. if (otherNumPoints == 2 && otherLine[2] >= 255)
  64533. {
  64534. clipEdgeTableLineToRange (dest, otherLine[1], jmin (right, otherLine[3]));
  64535. return;
  64536. }
  64537. ++otherLine;
  64538. const size_t lineSizeBytes = (dest[0] * 2 + 1) * sizeof (int);
  64539. int* temp = (int*) alloca (lineSizeBytes);
  64540. memcpy (temp, dest, lineSizeBytes);
  64541. const int* src1 = temp;
  64542. int srcNum1 = *src1++;
  64543. int x1 = *src1++;
  64544. const int* src2 = otherLine;
  64545. int srcNum2 = otherNumPoints;
  64546. int x2 = *src2++;
  64547. int destIndex = 0, destTotal = 0;
  64548. int level1 = 0, level2 = 0;
  64549. int lastX = INT_MIN, lastLevel = 0;
  64550. while (srcNum1 > 0 && srcNum2 > 0)
  64551. {
  64552. int nextX;
  64553. if (x1 < x2)
  64554. {
  64555. nextX = x1;
  64556. level1 = *src1++;
  64557. x1 = *src1++;
  64558. --srcNum1;
  64559. }
  64560. else if (x1 == x2)
  64561. {
  64562. nextX = x1;
  64563. level1 = *src1++;
  64564. level2 = *src2++;
  64565. x1 = *src1++;
  64566. x2 = *src2++;
  64567. --srcNum1;
  64568. --srcNum2;
  64569. }
  64570. else
  64571. {
  64572. nextX = x2;
  64573. level2 = *src2++;
  64574. x2 = *src2++;
  64575. --srcNum2;
  64576. }
  64577. if (nextX > lastX)
  64578. {
  64579. if (nextX >= right)
  64580. break;
  64581. lastX = nextX;
  64582. const int nextLevel = (level1 * (level2 + 1)) >> 8;
  64583. jassert (((unsigned int) nextLevel) < (unsigned int) 256);
  64584. if (nextLevel != lastLevel)
  64585. {
  64586. if (destTotal >= maxEdgesPerLine)
  64587. {
  64588. dest[0] = destTotal;
  64589. remapTableForNumEdges (maxEdgesPerLine + juce_edgeTableDefaultEdgesPerLine);
  64590. dest = table + lineStrideElements * y;
  64591. }
  64592. ++destTotal;
  64593. lastLevel = nextLevel;
  64594. dest[++destIndex] = nextX;
  64595. dest[++destIndex] = nextLevel;
  64596. }
  64597. }
  64598. }
  64599. if (lastLevel > 0)
  64600. {
  64601. if (destTotal >= maxEdgesPerLine)
  64602. {
  64603. dest[0] = destTotal;
  64604. remapTableForNumEdges (maxEdgesPerLine + juce_edgeTableDefaultEdgesPerLine);
  64605. dest = table + lineStrideElements * y;
  64606. }
  64607. ++destTotal;
  64608. dest[++destIndex] = right;
  64609. dest[++destIndex] = 0;
  64610. }
  64611. dest[0] = destTotal;
  64612. #if JUCE_DEBUG
  64613. int last = INT_MIN;
  64614. for (int i = 0; i < dest[0]; ++i)
  64615. {
  64616. jassert (dest[i * 2 + 1] > last);
  64617. last = dest[i * 2 + 1];
  64618. }
  64619. jassert (dest [dest[0] * 2] == 0);
  64620. #endif
  64621. }
  64622. void EdgeTable::clipEdgeTableLineToRange (int* dest, const int x1, const int x2) throw()
  64623. {
  64624. int* lastItem = dest + (dest[0] * 2 - 1);
  64625. if (x2 < lastItem[0])
  64626. {
  64627. if (x2 <= dest[1])
  64628. {
  64629. dest[0] = 0;
  64630. return;
  64631. }
  64632. while (x2 < lastItem[-2])
  64633. {
  64634. --(dest[0]);
  64635. lastItem -= 2;
  64636. }
  64637. lastItem[0] = x2;
  64638. lastItem[1] = 0;
  64639. }
  64640. if (x1 > dest[1])
  64641. {
  64642. while (lastItem[0] > x1)
  64643. lastItem -= 2;
  64644. const int itemsRemoved = (lastItem - (dest + 1)) / 2;
  64645. if (itemsRemoved > 0)
  64646. {
  64647. dest[0] -= itemsRemoved;
  64648. memmove (dest + 1, lastItem, dest[0] * (sizeof (int) * 2));
  64649. }
  64650. dest[1] = x1;
  64651. }
  64652. }
  64653. void EdgeTable::clipToRectangle (const Rectangle& r) throw()
  64654. {
  64655. const Rectangle clipped (r.getIntersection (bounds));
  64656. if (clipped.isEmpty())
  64657. {
  64658. needToCheckEmptinesss = false;
  64659. bounds.setHeight (0);
  64660. }
  64661. else
  64662. {
  64663. const int top = clipped.getY() - bounds.getY();
  64664. const int bottom = clipped.getBottom() - bounds.getY();
  64665. if (bottom < bounds.getHeight())
  64666. bounds.setHeight (bottom);
  64667. if (clipped.getRight() < bounds.getRight())
  64668. bounds.setRight (clipped.getRight());
  64669. for (int i = top; --i >= 0;)
  64670. table [lineStrideElements * i] = 0;
  64671. if (clipped.getX() > bounds.getX())
  64672. {
  64673. const int x1 = clipped.getX() << 8;
  64674. const int x2 = jmin (bounds.getRight(), clipped.getRight()) << 8;
  64675. int* line = table + lineStrideElements * top;
  64676. for (int i = bottom - top; --i >= 0;)
  64677. {
  64678. if (line[0] != 0)
  64679. clipEdgeTableLineToRange (line, x1, x2);
  64680. line += lineStrideElements;
  64681. }
  64682. }
  64683. needToCheckEmptinesss = true;
  64684. }
  64685. }
  64686. void EdgeTable::excludeRectangle (const Rectangle& r) throw()
  64687. {
  64688. const Rectangle clipped (r.getIntersection (bounds));
  64689. if (! clipped.isEmpty())
  64690. {
  64691. const int top = clipped.getY() - bounds.getY();
  64692. const int bottom = clipped.getBottom() - bounds.getY();
  64693. //XXX optimise here by shortening the table if it fills top or bottom
  64694. const int rectLine[] = { 4, INT_MIN, 255, clipped.getX() << 8, 0, clipped.getRight() << 8, 255, INT_MAX, 0 };
  64695. for (int i = top; i < bottom; ++i)
  64696. intersectWithEdgeTableLine (i, rectLine);
  64697. needToCheckEmptinesss = true;
  64698. }
  64699. }
  64700. void EdgeTable::clipToEdgeTable (const EdgeTable& other)
  64701. {
  64702. const Rectangle clipped (other.bounds.getIntersection (bounds));
  64703. if (clipped.isEmpty())
  64704. {
  64705. needToCheckEmptinesss = false;
  64706. bounds.setHeight (0);
  64707. }
  64708. else
  64709. {
  64710. const int top = clipped.getY() - bounds.getY();
  64711. const int bottom = clipped.getBottom() - bounds.getY();
  64712. if (bottom < bounds.getHeight())
  64713. bounds.setHeight (bottom);
  64714. if (clipped.getRight() < bounds.getRight())
  64715. bounds.setRight (clipped.getRight());
  64716. int i = 0;
  64717. for (i = top; --i >= 0;)
  64718. table [lineStrideElements * i] = 0;
  64719. const int* otherLine = other.table + other.lineStrideElements * (clipped.getY() - other.bounds.getY());
  64720. for (i = top; i < bottom; ++i)
  64721. {
  64722. intersectWithEdgeTableLine (i, otherLine);
  64723. otherLine += other.lineStrideElements;
  64724. }
  64725. needToCheckEmptinesss = true;
  64726. }
  64727. }
  64728. void EdgeTable::clipLineToMask (int x, int y, uint8* mask, int maskStride, int numPixels) throw()
  64729. {
  64730. y -= bounds.getY();
  64731. if (y < 0 || y >= bounds.getHeight())
  64732. return;
  64733. needToCheckEmptinesss = true;
  64734. if (numPixels <= 0)
  64735. {
  64736. table [lineStrideElements * y] = 0;
  64737. return;
  64738. }
  64739. int* tempLine = (int*) alloca ((numPixels * 2 + 4) * sizeof (int));
  64740. int destIndex = 0, lastLevel = 0;
  64741. while (--numPixels >= 0)
  64742. {
  64743. const int alpha = *mask;
  64744. mask += maskStride;
  64745. if (alpha != lastLevel)
  64746. {
  64747. tempLine[++destIndex] = (x << 8);
  64748. tempLine[++destIndex] = alpha;
  64749. lastLevel = alpha;
  64750. }
  64751. ++x;
  64752. }
  64753. if (lastLevel > 0)
  64754. {
  64755. tempLine[++destIndex] = (x << 8);
  64756. tempLine[++destIndex] = 0;
  64757. }
  64758. tempLine[0] = destIndex >> 1;
  64759. intersectWithEdgeTableLine (y, tempLine);
  64760. }
  64761. bool EdgeTable::isEmpty() throw()
  64762. {
  64763. if (needToCheckEmptinesss)
  64764. {
  64765. needToCheckEmptinesss = false;
  64766. int* t = table;
  64767. for (int i = bounds.getHeight(); --i >= 0;)
  64768. {
  64769. if (t[0] > 1)
  64770. return false;
  64771. t += lineStrideElements;
  64772. }
  64773. bounds.setHeight (0);
  64774. }
  64775. return bounds.getHeight() == 0;
  64776. }
  64777. END_JUCE_NAMESPACE
  64778. /********* End of inlined file: juce_EdgeTable.cpp *********/
  64779. /********* Start of inlined file: juce_FillType.cpp *********/
  64780. BEGIN_JUCE_NAMESPACE
  64781. FillType::FillType() throw()
  64782. : colour (0xff000000), image (0)
  64783. {
  64784. }
  64785. FillType::FillType (const Colour& colour_) throw()
  64786. : colour (colour_), image (0)
  64787. {
  64788. }
  64789. FillType::FillType (const ColourGradient& gradient_) throw()
  64790. : colour (0xff000000), gradient (new ColourGradient (gradient_)), image (0)
  64791. {
  64792. }
  64793. FillType::FillType (const Image& image_, const AffineTransform& transform_) throw()
  64794. : colour (0xff000000), image (&image_), transform (transform_)
  64795. {
  64796. }
  64797. FillType::FillType (const FillType& other) throw()
  64798. : colour (other.colour),
  64799. gradient (other.gradient != 0 ? new ColourGradient (*other.gradient) : 0),
  64800. image (other.image), transform (other.transform)
  64801. {
  64802. }
  64803. const FillType& FillType::operator= (const FillType& other) throw()
  64804. {
  64805. if (this != &other)
  64806. {
  64807. colour = other.colour;
  64808. gradient = (other.gradient != 0 ? new ColourGradient (*other.gradient) : 0);
  64809. image = other.image;
  64810. transform = other.transform;
  64811. }
  64812. return *this;
  64813. }
  64814. FillType::~FillType() throw()
  64815. {
  64816. }
  64817. void FillType::setColour (const Colour& newColour) throw()
  64818. {
  64819. gradient = 0;
  64820. image = 0;
  64821. colour = newColour;
  64822. }
  64823. void FillType::setGradient (const ColourGradient& newGradient) throw()
  64824. {
  64825. if (gradient != 0)
  64826. {
  64827. *gradient = newGradient;
  64828. }
  64829. else
  64830. {
  64831. image = 0;
  64832. gradient = new ColourGradient (newGradient);
  64833. colour = Colours::black;
  64834. }
  64835. }
  64836. void FillType::setTiledImage (const Image& image_, const AffineTransform& transform_) throw()
  64837. {
  64838. gradient = 0;
  64839. image = &image_;
  64840. transform = transform_;
  64841. colour = Colours::black;
  64842. }
  64843. void FillType::setOpacity (const float newOpacity) throw()
  64844. {
  64845. colour = colour.withAlpha (newOpacity);
  64846. }
  64847. END_JUCE_NAMESPACE
  64848. /********* End of inlined file: juce_FillType.cpp *********/
  64849. /********* Start of inlined file: juce_Graphics.cpp *********/
  64850. BEGIN_JUCE_NAMESPACE
  64851. static const Graphics::ResamplingQuality defaultQuality = Graphics::mediumResamplingQuality;
  64852. template <typename Type>
  64853. static bool areCoordsSensibleNumbers (Type x, Type y, Type w, Type h)
  64854. {
  64855. const int maxVal = 0x3fffffff;
  64856. return (int) x >= -maxVal && (int) x <= maxVal
  64857. && (int) y >= -maxVal && (int) y <= maxVal
  64858. && (int) w >= -maxVal && (int) w <= maxVal
  64859. && (int) h >= -maxVal && (int) h <= maxVal;
  64860. }
  64861. LowLevelGraphicsContext::LowLevelGraphicsContext()
  64862. {
  64863. }
  64864. LowLevelGraphicsContext::~LowLevelGraphicsContext()
  64865. {
  64866. }
  64867. Graphics::Graphics (Image& imageToDrawOnto) throw()
  64868. : context (imageToDrawOnto.createLowLevelContext()),
  64869. contextToDelete (context),
  64870. saveStatePending (false)
  64871. {
  64872. resetToDefaultState();
  64873. }
  64874. Graphics::Graphics (LowLevelGraphicsContext* const internalContext) throw()
  64875. : context (internalContext),
  64876. saveStatePending (false)
  64877. {
  64878. resetToDefaultState();
  64879. }
  64880. Graphics::~Graphics() throw()
  64881. {
  64882. }
  64883. void Graphics::resetToDefaultState() throw()
  64884. {
  64885. saveStateIfPending();
  64886. context->setFill (FillType());
  64887. context->setFont (Font());
  64888. context->setInterpolationQuality (defaultQuality);
  64889. }
  64890. bool Graphics::isVectorDevice() const throw()
  64891. {
  64892. return context->isVectorDevice();
  64893. }
  64894. bool Graphics::reduceClipRegion (const int x, const int y,
  64895. const int w, const int h) throw()
  64896. {
  64897. saveStateIfPending();
  64898. return context->clipToRectangle (Rectangle (x, y, w, h));
  64899. }
  64900. bool Graphics::reduceClipRegion (const RectangleList& clipRegion) throw()
  64901. {
  64902. saveStateIfPending();
  64903. return context->clipToRectangleList (clipRegion);
  64904. }
  64905. bool Graphics::reduceClipRegion (const Path& path, const AffineTransform& transform) throw()
  64906. {
  64907. saveStateIfPending();
  64908. context->clipToPath (path, transform);
  64909. return ! context->isClipEmpty();
  64910. }
  64911. bool Graphics::reduceClipRegion (const Image& image, const Rectangle& sourceClipRegion, const AffineTransform& transform) throw()
  64912. {
  64913. saveStateIfPending();
  64914. context->clipToImageAlpha (image, sourceClipRegion, transform);
  64915. return ! context->isClipEmpty();
  64916. }
  64917. void Graphics::excludeClipRegion (const int x, const int y,
  64918. const int w, const int h) throw()
  64919. {
  64920. saveStateIfPending();
  64921. context->excludeClipRectangle (Rectangle (x, y, w, h));
  64922. }
  64923. bool Graphics::isClipEmpty() const throw()
  64924. {
  64925. return context->isClipEmpty();
  64926. }
  64927. const Rectangle Graphics::getClipBounds() const throw()
  64928. {
  64929. return context->getClipBounds();
  64930. }
  64931. void Graphics::saveState() throw()
  64932. {
  64933. saveStateIfPending();
  64934. saveStatePending = true;
  64935. }
  64936. void Graphics::restoreState() throw()
  64937. {
  64938. if (saveStatePending)
  64939. saveStatePending = false;
  64940. else
  64941. context->restoreState();
  64942. }
  64943. void Graphics::saveStateIfPending() throw()
  64944. {
  64945. if (saveStatePending)
  64946. {
  64947. saveStatePending = false;
  64948. context->saveState();
  64949. }
  64950. }
  64951. void Graphics::setOrigin (const int newOriginX,
  64952. const int newOriginY) throw()
  64953. {
  64954. saveStateIfPending();
  64955. context->setOrigin (newOriginX, newOriginY);
  64956. }
  64957. bool Graphics::clipRegionIntersects (const int x, const int y,
  64958. const int w, const int h) const throw()
  64959. {
  64960. return context->clipRegionIntersects (Rectangle (x, y, w, h));
  64961. }
  64962. void Graphics::setColour (const Colour& newColour) throw()
  64963. {
  64964. saveStateIfPending();
  64965. context->setFill (FillType (newColour));
  64966. }
  64967. void Graphics::setOpacity (const float newOpacity) throw()
  64968. {
  64969. saveStateIfPending();
  64970. context->setOpacity (newOpacity);
  64971. }
  64972. void Graphics::setGradientFill (const ColourGradient& gradient) throw()
  64973. {
  64974. saveStateIfPending();
  64975. context->setFill (FillType (gradient));
  64976. }
  64977. void Graphics::setTiledImageFill (const Image& imageToUse,
  64978. const int anchorX,
  64979. const int anchorY,
  64980. const float opacity) throw()
  64981. {
  64982. saveStateIfPending();
  64983. context->setFill (FillType (imageToUse, AffineTransform::translation ((float) anchorX, (float) anchorY)));
  64984. context->setOpacity (opacity);
  64985. }
  64986. void Graphics::setFillType (const FillType& newFill) throw()
  64987. {
  64988. saveStateIfPending();
  64989. context->setFill (newFill);
  64990. }
  64991. void Graphics::setFont (const Font& newFont) throw()
  64992. {
  64993. saveStateIfPending();
  64994. context->setFont (newFont);
  64995. }
  64996. void Graphics::setFont (const float newFontHeight,
  64997. const int newFontStyleFlags) throw()
  64998. {
  64999. saveStateIfPending();
  65000. Font f (context->getFont());
  65001. f.setSizeAndStyle (newFontHeight, newFontStyleFlags, 1.0f, 0);
  65002. context->setFont (f);
  65003. }
  65004. void Graphics::drawSingleLineText (const String& text,
  65005. const int startX,
  65006. const int baselineY) const throw()
  65007. {
  65008. if (text.isNotEmpty()
  65009. && startX < context->getClipBounds().getRight())
  65010. {
  65011. GlyphArrangement arr;
  65012. arr.addLineOfText (context->getFont(), text, (float) startX, (float) baselineY);
  65013. arr.draw (*this);
  65014. }
  65015. }
  65016. void Graphics::drawTextAsPath (const String& text,
  65017. const AffineTransform& transform) const throw()
  65018. {
  65019. if (text.isNotEmpty())
  65020. {
  65021. GlyphArrangement arr;
  65022. arr.addLineOfText (context->getFont(), text, 0.0f, 0.0f);
  65023. arr.draw (*this, transform);
  65024. }
  65025. }
  65026. void Graphics::drawMultiLineText (const String& text,
  65027. const int startX,
  65028. const int baselineY,
  65029. const int maximumLineWidth) const throw()
  65030. {
  65031. if (text.isNotEmpty()
  65032. && startX < context->getClipBounds().getRight())
  65033. {
  65034. GlyphArrangement arr;
  65035. arr.addJustifiedText (context->getFont(), text,
  65036. (float) startX, (float) baselineY, (float) maximumLineWidth,
  65037. Justification::left);
  65038. arr.draw (*this);
  65039. }
  65040. }
  65041. void Graphics::drawText (const String& text,
  65042. const int x,
  65043. const int y,
  65044. const int width,
  65045. const int height,
  65046. const Justification& justificationType,
  65047. const bool useEllipsesIfTooBig) const throw()
  65048. {
  65049. if (text.isNotEmpty() && context->clipRegionIntersects (Rectangle (x, y, width, height)))
  65050. {
  65051. GlyphArrangement arr;
  65052. arr.addCurtailedLineOfText (context->getFont(), text,
  65053. 0.0f, 0.0f, (float)width,
  65054. useEllipsesIfTooBig);
  65055. arr.justifyGlyphs (0, arr.getNumGlyphs(),
  65056. (float) x, (float) y,
  65057. (float) width, (float) height,
  65058. justificationType);
  65059. arr.draw (*this);
  65060. }
  65061. }
  65062. void Graphics::drawFittedText (const String& text,
  65063. const int x,
  65064. const int y,
  65065. const int width,
  65066. const int height,
  65067. const Justification& justification,
  65068. const int maximumNumberOfLines,
  65069. const float minimumHorizontalScale) const throw()
  65070. {
  65071. if (text.isNotEmpty()
  65072. && width > 0 && height > 0
  65073. && context->clipRegionIntersects (Rectangle (x, y, width, height)))
  65074. {
  65075. GlyphArrangement arr;
  65076. arr.addFittedText (context->getFont(), text,
  65077. (float) x, (float) y,
  65078. (float) width, (float) height,
  65079. justification,
  65080. maximumNumberOfLines,
  65081. minimumHorizontalScale);
  65082. arr.draw (*this);
  65083. }
  65084. }
  65085. void Graphics::fillRect (int x,
  65086. int y,
  65087. int width,
  65088. int height) const throw()
  65089. {
  65090. // passing in a silly number can cause maths problems in rendering!
  65091. jassert (areCoordsSensibleNumbers (x, y, width, height));
  65092. context->fillRect (Rectangle (x, y, width, height), false);
  65093. }
  65094. void Graphics::fillRect (const Rectangle& r) const throw()
  65095. {
  65096. context->fillRect (r, false);
  65097. }
  65098. void Graphics::fillRect (const float x,
  65099. const float y,
  65100. const float width,
  65101. const float height) const throw()
  65102. {
  65103. // passing in a silly number can cause maths problems in rendering!
  65104. jassert (areCoordsSensibleNumbers (x, y, width, height));
  65105. Path p;
  65106. p.addRectangle (x, y, width, height);
  65107. fillPath (p);
  65108. }
  65109. void Graphics::setPixel (int x, int y) const throw()
  65110. {
  65111. context->fillRect (Rectangle (x, y, 1, 1), false);
  65112. }
  65113. void Graphics::fillAll() const throw()
  65114. {
  65115. fillRect (context->getClipBounds());
  65116. }
  65117. void Graphics::fillAll (const Colour& colourToUse) const throw()
  65118. {
  65119. if (! colourToUse.isTransparent())
  65120. {
  65121. const Rectangle clip (context->getClipBounds());
  65122. context->saveState();
  65123. context->setFill (FillType (colourToUse));
  65124. context->fillRect (clip, false);
  65125. context->restoreState();
  65126. }
  65127. }
  65128. void Graphics::fillPath (const Path& path,
  65129. const AffineTransform& transform) const throw()
  65130. {
  65131. if ((! context->isClipEmpty()) && ! path.isEmpty())
  65132. context->fillPath (path, transform);
  65133. }
  65134. void Graphics::strokePath (const Path& path,
  65135. const PathStrokeType& strokeType,
  65136. const AffineTransform& transform) const throw()
  65137. {
  65138. Path stroke;
  65139. strokeType.createStrokedPath (stroke, path, transform);
  65140. fillPath (stroke);
  65141. }
  65142. void Graphics::drawRect (const int x,
  65143. const int y,
  65144. const int width,
  65145. const int height,
  65146. const int lineThickness) const throw()
  65147. {
  65148. // passing in a silly number can cause maths problems in rendering!
  65149. jassert (areCoordsSensibleNumbers (x, y, width, height));
  65150. context->fillRect (Rectangle (x, y, width, lineThickness), false);
  65151. context->fillRect (Rectangle (x, y + lineThickness, lineThickness, height - lineThickness * 2), false);
  65152. context->fillRect (Rectangle (x + width - lineThickness, y + lineThickness, lineThickness, height - lineThickness * 2), false);
  65153. context->fillRect (Rectangle (x, y + height - lineThickness, width, lineThickness), false);
  65154. }
  65155. void Graphics::drawRect (const float x,
  65156. const float y,
  65157. const float width,
  65158. const float height,
  65159. const float lineThickness) const throw()
  65160. {
  65161. // passing in a silly number can cause maths problems in rendering!
  65162. jassert (areCoordsSensibleNumbers (x, y, width, height));
  65163. Path p;
  65164. p.addRectangle (x, y, width, lineThickness);
  65165. p.addRectangle (x, y + lineThickness, lineThickness, height - lineThickness * 2.0f);
  65166. p.addRectangle (x + width - lineThickness, y + lineThickness, lineThickness, height - lineThickness * 2.0f);
  65167. p.addRectangle (x, y + height - lineThickness, width, lineThickness);
  65168. fillPath (p);
  65169. }
  65170. void Graphics::drawRect (const Rectangle& r,
  65171. const int lineThickness) const throw()
  65172. {
  65173. drawRect (r.getX(), r.getY(),
  65174. r.getWidth(), r.getHeight(),
  65175. lineThickness);
  65176. }
  65177. void Graphics::drawBevel (const int x,
  65178. const int y,
  65179. const int width,
  65180. const int height,
  65181. const int bevelThickness,
  65182. const Colour& topLeftColour,
  65183. const Colour& bottomRightColour,
  65184. const bool useGradient,
  65185. const bool sharpEdgeOnOutside) const throw()
  65186. {
  65187. // passing in a silly number can cause maths problems in rendering!
  65188. jassert (areCoordsSensibleNumbers (x, y, width, height));
  65189. if (clipRegionIntersects (x, y, width, height))
  65190. {
  65191. context->saveState();
  65192. const float oldOpacity = 1.0f;//xxx state->colour.getFloatAlpha();
  65193. const float ramp = oldOpacity / bevelThickness;
  65194. for (int i = bevelThickness; --i >= 0;)
  65195. {
  65196. const float op = useGradient ? ramp * (sharpEdgeOnOutside ? bevelThickness - i : i)
  65197. : oldOpacity;
  65198. context->setFill (FillType (topLeftColour.withMultipliedAlpha (op)));
  65199. context->fillRect (Rectangle (x + i, y + i, width - i * 2, 1), false);
  65200. context->setFill (FillType (topLeftColour.withMultipliedAlpha (op * 0.75f)));
  65201. context->fillRect (Rectangle (x + i, y + i + 1, 1, height - i * 2 - 2), false);
  65202. context->setFill (FillType (bottomRightColour.withMultipliedAlpha (op)));
  65203. context->fillRect (Rectangle (x + i, y + height - i - 1, width - i * 2, 1), false);
  65204. context->setFill (FillType (bottomRightColour.withMultipliedAlpha (op * 0.75f)));
  65205. context->fillRect (Rectangle (x + width - i - 1, y + i + 1, 1, height - i * 2 - 2), false);
  65206. }
  65207. context->restoreState();
  65208. }
  65209. }
  65210. void Graphics::fillEllipse (const float x,
  65211. const float y,
  65212. const float width,
  65213. const float height) const throw()
  65214. {
  65215. // passing in a silly number can cause maths problems in rendering!
  65216. jassert (areCoordsSensibleNumbers (x, y, width, height));
  65217. Path p;
  65218. p.addEllipse (x, y, width, height);
  65219. fillPath (p);
  65220. }
  65221. void Graphics::drawEllipse (const float x,
  65222. const float y,
  65223. const float width,
  65224. const float height,
  65225. const float lineThickness) const throw()
  65226. {
  65227. // passing in a silly number can cause maths problems in rendering!
  65228. jassert (areCoordsSensibleNumbers (x, y, width, height));
  65229. Path p;
  65230. p.addEllipse (x, y, width, height);
  65231. strokePath (p, PathStrokeType (lineThickness));
  65232. }
  65233. void Graphics::fillRoundedRectangle (const float x,
  65234. const float y,
  65235. const float width,
  65236. const float height,
  65237. const float cornerSize) const throw()
  65238. {
  65239. // passing in a silly number can cause maths problems in rendering!
  65240. jassert (areCoordsSensibleNumbers (x, y, width, height));
  65241. Path p;
  65242. p.addRoundedRectangle (x, y, width, height, cornerSize);
  65243. fillPath (p);
  65244. }
  65245. void Graphics::fillRoundedRectangle (const Rectangle& r,
  65246. const float cornerSize) const throw()
  65247. {
  65248. fillRoundedRectangle ((float) r.getX(),
  65249. (float) r.getY(),
  65250. (float) r.getWidth(),
  65251. (float) r.getHeight(),
  65252. cornerSize);
  65253. }
  65254. void Graphics::drawRoundedRectangle (const float x,
  65255. const float y,
  65256. const float width,
  65257. const float height,
  65258. const float cornerSize,
  65259. const float lineThickness) const throw()
  65260. {
  65261. // passing in a silly number can cause maths problems in rendering!
  65262. jassert (areCoordsSensibleNumbers (x, y, width, height));
  65263. Path p;
  65264. p.addRoundedRectangle (x, y, width, height, cornerSize);
  65265. strokePath (p, PathStrokeType (lineThickness));
  65266. }
  65267. void Graphics::drawRoundedRectangle (const Rectangle& r,
  65268. const float cornerSize,
  65269. const float lineThickness) const throw()
  65270. {
  65271. drawRoundedRectangle ((float) r.getX(),
  65272. (float) r.getY(),
  65273. (float) r.getWidth(),
  65274. (float) r.getHeight(),
  65275. cornerSize, lineThickness);
  65276. }
  65277. void Graphics::drawArrow (const float startX,
  65278. const float startY,
  65279. const float endX,
  65280. const float endY,
  65281. const float lineThickness,
  65282. const float arrowheadWidth,
  65283. const float arrowheadLength) const throw()
  65284. {
  65285. Path p;
  65286. p.addArrow (startX, startY, endX, endY,
  65287. lineThickness, arrowheadWidth, arrowheadLength);
  65288. fillPath (p);
  65289. }
  65290. void Graphics::fillCheckerBoard (int x, int y,
  65291. int width, int height,
  65292. const int checkWidth,
  65293. const int checkHeight,
  65294. const Colour& colour1,
  65295. const Colour& colour2) const throw()
  65296. {
  65297. jassert (checkWidth > 0 && checkHeight > 0); // can't be zero or less!
  65298. if (checkWidth > 0 && checkHeight > 0)
  65299. {
  65300. context->saveState();
  65301. if (colour1 == colour2)
  65302. {
  65303. context->setFill (FillType (colour1));
  65304. context->fillRect (Rectangle (x, y, width, height), false);
  65305. }
  65306. else
  65307. {
  65308. const Rectangle clip (context->getClipBounds());
  65309. const int right = jmin (x + width, clip.getRight());
  65310. const int bottom = jmin (y + height, clip.getBottom());
  65311. int cy = 0;
  65312. while (y < bottom)
  65313. {
  65314. int cx = cy;
  65315. for (int xx = x; xx < right; xx += checkWidth)
  65316. {
  65317. context->setFill (FillType (((cx++ & 1) == 0) ? colour1 : colour2));
  65318. context->fillRect (Rectangle (xx, y, jmin (checkWidth, right - xx), jmin (checkHeight, bottom - y)),
  65319. false);
  65320. }
  65321. ++cy;
  65322. y += checkHeight;
  65323. }
  65324. }
  65325. context->restoreState();
  65326. }
  65327. }
  65328. void Graphics::drawVerticalLine (const int x, float top, float bottom) const throw()
  65329. {
  65330. context->drawVerticalLine (x, top, bottom);
  65331. }
  65332. void Graphics::drawHorizontalLine (const int y, float left, float right) const throw()
  65333. {
  65334. context->drawHorizontalLine (y, left, right);
  65335. }
  65336. void Graphics::drawLine (float x1, float y1, float x2, float y2) const throw()
  65337. {
  65338. context->drawLine (x1, y1, x2, y2);
  65339. }
  65340. void Graphics::drawLine (const float startX,
  65341. const float startY,
  65342. const float endX,
  65343. const float endY,
  65344. const float lineThickness) const throw()
  65345. {
  65346. Path p;
  65347. p.addLineSegment (startX, startY, endX, endY, lineThickness);
  65348. fillPath (p);
  65349. }
  65350. void Graphics::drawLine (const Line& line) const throw()
  65351. {
  65352. drawLine (line.getStartX(), line.getStartY(), line.getEndX(), line.getEndY());
  65353. }
  65354. void Graphics::drawLine (const Line& line,
  65355. const float lineThickness) const throw()
  65356. {
  65357. drawLine (line.getStartX(), line.getStartY(), line.getEndX(), line.getEndY(), lineThickness);
  65358. }
  65359. void Graphics::drawDashedLine (const float startX,
  65360. const float startY,
  65361. const float endX,
  65362. const float endY,
  65363. const float* const dashLengths,
  65364. const int numDashLengths,
  65365. const float lineThickness) const throw()
  65366. {
  65367. const double dx = endX - startX;
  65368. const double dy = endY - startY;
  65369. const double totalLen = juce_hypot (dx, dy);
  65370. if (totalLen >= 0.5)
  65371. {
  65372. const double onePixAlpha = 1.0 / totalLen;
  65373. double alpha = 0.0;
  65374. float x = startX;
  65375. float y = startY;
  65376. int n = 0;
  65377. while (alpha < 1.0f)
  65378. {
  65379. alpha = jmin (1.0, alpha + dashLengths[n++] * onePixAlpha);
  65380. n = n % numDashLengths;
  65381. const float oldX = x;
  65382. const float oldY = y;
  65383. x = (float) (startX + dx * alpha);
  65384. y = (float) (startY + dy * alpha);
  65385. if ((n & 1) != 0)
  65386. {
  65387. if (lineThickness != 1.0f)
  65388. drawLine (oldX, oldY, x, y, lineThickness);
  65389. else
  65390. drawLine (oldX, oldY, x, y);
  65391. }
  65392. }
  65393. }
  65394. }
  65395. void Graphics::setImageResamplingQuality (const Graphics::ResamplingQuality newQuality) throw()
  65396. {
  65397. saveStateIfPending();
  65398. context->setInterpolationQuality (newQuality);
  65399. }
  65400. void Graphics::drawImageAt (const Image* const imageToDraw,
  65401. const int topLeftX,
  65402. const int topLeftY,
  65403. const bool fillAlphaChannelWithCurrentBrush) const throw()
  65404. {
  65405. if (imageToDraw != 0)
  65406. {
  65407. const int imageW = imageToDraw->getWidth();
  65408. const int imageH = imageToDraw->getHeight();
  65409. drawImage (imageToDraw,
  65410. topLeftX, topLeftY, imageW, imageH,
  65411. 0, 0, imageW, imageH,
  65412. fillAlphaChannelWithCurrentBrush);
  65413. }
  65414. }
  65415. void Graphics::drawImageWithin (const Image* const imageToDraw,
  65416. const int destX,
  65417. const int destY,
  65418. const int destW,
  65419. const int destH,
  65420. const RectanglePlacement& placementWithinTarget,
  65421. const bool fillAlphaChannelWithCurrentBrush) const throw()
  65422. {
  65423. // passing in a silly number can cause maths problems in rendering!
  65424. jassert (areCoordsSensibleNumbers (destX, destY, destW, destH));
  65425. if (imageToDraw != 0)
  65426. {
  65427. const int imageW = imageToDraw->getWidth();
  65428. const int imageH = imageToDraw->getHeight();
  65429. if (imageW > 0 && imageH > 0)
  65430. {
  65431. double newX = 0.0, newY = 0.0;
  65432. double newW = imageW;
  65433. double newH = imageH;
  65434. placementWithinTarget.applyTo (newX, newY, newW, newH,
  65435. destX, destY, destW, destH);
  65436. if (newW > 0 && newH > 0)
  65437. {
  65438. drawImage (imageToDraw,
  65439. roundToInt (newX), roundToInt (newY),
  65440. roundToInt (newW), roundToInt (newH),
  65441. 0, 0, imageW, imageH,
  65442. fillAlphaChannelWithCurrentBrush);
  65443. }
  65444. }
  65445. }
  65446. }
  65447. void Graphics::drawImage (const Image* const imageToDraw,
  65448. int dx, int dy, int dw, int dh,
  65449. int sx, int sy, int sw, int sh,
  65450. const bool fillAlphaChannelWithCurrentBrush) const throw()
  65451. {
  65452. // passing in a silly number can cause maths problems in rendering!
  65453. jassert (areCoordsSensibleNumbers (dx, dy, dw, dh));
  65454. jassert (areCoordsSensibleNumbers (sx, sy, sw, sh));
  65455. if (context->clipRegionIntersects (Rectangle (dx, dy, dw, dh)))
  65456. {
  65457. drawImageTransformed (imageToDraw, Rectangle (sx, sy, sw, sh),
  65458. AffineTransform::scale (dw / (float) sw, dh / (float) sh)
  65459. .translated ((float) dx, (float) dy),
  65460. fillAlphaChannelWithCurrentBrush);
  65461. }
  65462. }
  65463. void Graphics::drawImageTransformed (const Image* const imageToDraw,
  65464. const Rectangle& imageSubRegion,
  65465. const AffineTransform& transform,
  65466. const bool fillAlphaChannelWithCurrentBrush) const throw()
  65467. {
  65468. if (imageToDraw != 0 && ! context->isClipEmpty())
  65469. {
  65470. const Rectangle srcClip (imageSubRegion.getIntersection (imageToDraw->getBounds()));
  65471. if (fillAlphaChannelWithCurrentBrush)
  65472. {
  65473. context->saveState();
  65474. context->clipToImageAlpha (*imageToDraw, srcClip, transform);
  65475. fillAll();
  65476. context->restoreState();
  65477. }
  65478. else
  65479. {
  65480. context->drawImage (*imageToDraw, srcClip, transform, false);
  65481. }
  65482. }
  65483. }
  65484. END_JUCE_NAMESPACE
  65485. /********* End of inlined file: juce_Graphics.cpp *********/
  65486. /********* Start of inlined file: juce_Justification.cpp *********/
  65487. BEGIN_JUCE_NAMESPACE
  65488. Justification::Justification (const Justification& other) throw()
  65489. : flags (other.flags)
  65490. {
  65491. }
  65492. const Justification& Justification::operator= (const Justification& other) throw()
  65493. {
  65494. flags = other.flags;
  65495. return *this;
  65496. }
  65497. int Justification::getOnlyVerticalFlags() const throw()
  65498. {
  65499. return flags & (top | bottom | verticallyCentred);
  65500. }
  65501. int Justification::getOnlyHorizontalFlags() const throw()
  65502. {
  65503. return flags & (left | right | horizontallyCentred | horizontallyJustified);
  65504. }
  65505. void Justification::applyToRectangle (int& x, int& y,
  65506. const int w, const int h,
  65507. const int spaceX, const int spaceY,
  65508. const int spaceW, const int spaceH) const throw()
  65509. {
  65510. if ((flags & horizontallyCentred) != 0)
  65511. {
  65512. x = spaceX + ((spaceW - w) >> 1);
  65513. }
  65514. else if ((flags & right) != 0)
  65515. {
  65516. x = spaceX + spaceW - w;
  65517. }
  65518. else
  65519. {
  65520. x = spaceX;
  65521. }
  65522. if ((flags & verticallyCentred) != 0)
  65523. {
  65524. y = spaceY + ((spaceH - h) >> 1);
  65525. }
  65526. else if ((flags & bottom) != 0)
  65527. {
  65528. y = spaceY + spaceH - h;
  65529. }
  65530. else
  65531. {
  65532. y = spaceY;
  65533. }
  65534. }
  65535. END_JUCE_NAMESPACE
  65536. /********* End of inlined file: juce_Justification.cpp *********/
  65537. /********* Start of inlined file: juce_LowLevelGraphicsPostScriptRenderer.cpp *********/
  65538. BEGIN_JUCE_NAMESPACE
  65539. // this will throw an assertion if you try to draw something that's not
  65540. // possible in postscript
  65541. #define WARN_ABOUT_NON_POSTSCRIPT_OPERATIONS 0
  65542. #if defined (JUCE_DEBUG) && WARN_ABOUT_NON_POSTSCRIPT_OPERATIONS
  65543. #define notPossibleInPostscriptAssert jassertfalse
  65544. #else
  65545. #define notPossibleInPostscriptAssert
  65546. #endif
  65547. LowLevelGraphicsPostScriptRenderer::LowLevelGraphicsPostScriptRenderer (OutputStream& resultingPostScript,
  65548. const String& documentTitle,
  65549. const int totalWidth_,
  65550. const int totalHeight_)
  65551. : out (resultingPostScript),
  65552. totalWidth (totalWidth_),
  65553. totalHeight (totalHeight_),
  65554. needToClip (true)
  65555. {
  65556. stateStack.add (new SavedState());
  65557. stateStack.getLast()->clip = Rectangle (0, 0, totalWidth_, totalHeight_);
  65558. const float scale = jmin ((520.0f / totalWidth_), (750.0f / totalHeight));
  65559. out << "%!PS-Adobe-3.0 EPSF-3.0"
  65560. "\n%%BoundingBox: 0 0 600 824"
  65561. "\n%%Pages: 0"
  65562. "\n%%Creator: Raw Material Software JUCE"
  65563. "\n%%Title: " << documentTitle <<
  65564. "\n%%CreationDate: none"
  65565. "\n%%LanguageLevel: 2"
  65566. "\n%%EndComments"
  65567. "\n%%BeginProlog"
  65568. "\n%%BeginResource: JRes"
  65569. "\n/bd {bind def} bind def"
  65570. "\n/c {setrgbcolor} bd"
  65571. "\n/m {moveto} bd"
  65572. "\n/l {lineto} bd"
  65573. "\n/rl {rlineto} bd"
  65574. "\n/ct {curveto} bd"
  65575. "\n/cp {closepath} bd"
  65576. "\n/pr {3 index 3 index moveto 1 index 0 rlineto 0 1 index rlineto pop neg 0 rlineto pop pop closepath} bd"
  65577. "\n/doclip {initclip newpath} bd"
  65578. "\n/endclip {clip newpath} bd"
  65579. "\n%%EndResource"
  65580. "\n%%EndProlog"
  65581. "\n%%BeginSetup"
  65582. "\n%%EndSetup"
  65583. "\n%%Page: 1 1"
  65584. "\n%%BeginPageSetup"
  65585. "\n%%EndPageSetup\n\n"
  65586. << "40 800 translate\n"
  65587. << scale << ' ' << scale << " scale\n\n";
  65588. }
  65589. LowLevelGraphicsPostScriptRenderer::~LowLevelGraphicsPostScriptRenderer()
  65590. {
  65591. }
  65592. bool LowLevelGraphicsPostScriptRenderer::isVectorDevice() const
  65593. {
  65594. return true;
  65595. }
  65596. void LowLevelGraphicsPostScriptRenderer::setOrigin (int x, int y)
  65597. {
  65598. if (x != 0 || y != 0)
  65599. {
  65600. stateStack.getLast()->xOffset += x;
  65601. stateStack.getLast()->yOffset += y;
  65602. needToClip = true;
  65603. }
  65604. }
  65605. bool LowLevelGraphicsPostScriptRenderer::clipToRectangle (const Rectangle& r)
  65606. {
  65607. needToClip = true;
  65608. return stateStack.getLast()->clip.clipTo (r.translated (stateStack.getLast()->xOffset, stateStack.getLast()->yOffset));
  65609. }
  65610. bool LowLevelGraphicsPostScriptRenderer::clipToRectangleList (const RectangleList& clipRegion)
  65611. {
  65612. needToClip = true;
  65613. return stateStack.getLast()->clip.clipTo (clipRegion);
  65614. }
  65615. void LowLevelGraphicsPostScriptRenderer::excludeClipRectangle (const Rectangle& r)
  65616. {
  65617. needToClip = true;
  65618. stateStack.getLast()->clip.subtract (r.translated (stateStack.getLast()->xOffset, stateStack.getLast()->yOffset));
  65619. }
  65620. void LowLevelGraphicsPostScriptRenderer::clipToPath (const Path& path, const AffineTransform& transform)
  65621. {
  65622. writeClip();
  65623. Path p (path);
  65624. p.applyTransform (transform.translated ((float) stateStack.getLast()->xOffset, (float) stateStack.getLast()->yOffset));
  65625. writePath (p);
  65626. out << "clip\n";
  65627. }
  65628. void LowLevelGraphicsPostScriptRenderer::clipToImageAlpha (const Image& /*sourceImage*/, const Rectangle& /*srcClip*/, const AffineTransform& /*transform*/)
  65629. {
  65630. needToClip = true;
  65631. jassertfalse // xxx
  65632. }
  65633. bool LowLevelGraphicsPostScriptRenderer::clipRegionIntersects (const Rectangle& r)
  65634. {
  65635. return stateStack.getLast()->clip.intersectsRectangle (r.translated (stateStack.getLast()->xOffset, stateStack.getLast()->yOffset));
  65636. }
  65637. const Rectangle LowLevelGraphicsPostScriptRenderer::getClipBounds() const
  65638. {
  65639. return stateStack.getLast()->clip.getBounds().translated (-stateStack.getLast()->xOffset,
  65640. -stateStack.getLast()->yOffset);
  65641. }
  65642. bool LowLevelGraphicsPostScriptRenderer::isClipEmpty() const
  65643. {
  65644. return stateStack.getLast()->clip.isEmpty();
  65645. }
  65646. LowLevelGraphicsPostScriptRenderer::SavedState::SavedState()
  65647. : xOffset (0),
  65648. yOffset (0)
  65649. {
  65650. }
  65651. LowLevelGraphicsPostScriptRenderer::SavedState::~SavedState()
  65652. {
  65653. }
  65654. void LowLevelGraphicsPostScriptRenderer::saveState()
  65655. {
  65656. stateStack.add (new SavedState (*stateStack.getLast()));
  65657. }
  65658. void LowLevelGraphicsPostScriptRenderer::restoreState()
  65659. {
  65660. jassert (stateStack.size() > 0);
  65661. if (stateStack.size() > 0)
  65662. stateStack.removeLast();
  65663. }
  65664. void LowLevelGraphicsPostScriptRenderer::writeClip()
  65665. {
  65666. if (needToClip)
  65667. {
  65668. needToClip = false;
  65669. out << "doclip ";
  65670. int itemsOnLine = 0;
  65671. for (RectangleList::Iterator i (stateStack.getLast()->clip); i.next();)
  65672. {
  65673. if (++itemsOnLine == 6)
  65674. {
  65675. itemsOnLine = 0;
  65676. out << '\n';
  65677. }
  65678. const Rectangle& r = *i.getRectangle();
  65679. out << r.getX() << ' ' << -r.getY() << ' '
  65680. << r.getWidth() << ' ' << -r.getHeight() << " pr ";
  65681. }
  65682. out << "endclip\n";
  65683. }
  65684. }
  65685. void LowLevelGraphicsPostScriptRenderer::writeColour (const Colour& colour)
  65686. {
  65687. Colour c (Colours::white.overlaidWith (colour));
  65688. if (lastColour != c)
  65689. {
  65690. lastColour = c;
  65691. out << String (c.getFloatRed(), 3) << ' '
  65692. << String (c.getFloatGreen(), 3) << ' '
  65693. << String (c.getFloatBlue(), 3) << " c\n";
  65694. }
  65695. }
  65696. void LowLevelGraphicsPostScriptRenderer::writeXY (const float x, const float y) const
  65697. {
  65698. out << String (x, 2) << ' '
  65699. << String (-y, 2) << ' ';
  65700. }
  65701. void LowLevelGraphicsPostScriptRenderer::writePath (const Path& path) const
  65702. {
  65703. out << "newpath ";
  65704. float lastX = 0.0f;
  65705. float lastY = 0.0f;
  65706. int itemsOnLine = 0;
  65707. Path::Iterator i (path);
  65708. while (i.next())
  65709. {
  65710. if (++itemsOnLine == 4)
  65711. {
  65712. itemsOnLine = 0;
  65713. out << '\n';
  65714. }
  65715. switch (i.elementType)
  65716. {
  65717. case Path::Iterator::startNewSubPath:
  65718. writeXY (i.x1, i.y1);
  65719. lastX = i.x1;
  65720. lastY = i.y1;
  65721. out << "m ";
  65722. break;
  65723. case Path::Iterator::lineTo:
  65724. writeXY (i.x1, i.y1);
  65725. lastX = i.x1;
  65726. lastY = i.y1;
  65727. out << "l ";
  65728. break;
  65729. case Path::Iterator::quadraticTo:
  65730. {
  65731. const float cp1x = lastX + (i.x1 - lastX) * 2.0f / 3.0f;
  65732. const float cp1y = lastY + (i.y1 - lastY) * 2.0f / 3.0f;
  65733. const float cp2x = cp1x + (i.x2 - lastX) / 3.0f;
  65734. const float cp2y = cp1y + (i.y2 - lastY) / 3.0f;
  65735. writeXY (cp1x, cp1y);
  65736. writeXY (cp2x, cp2y);
  65737. writeXY (i.x2, i.y2);
  65738. out << "ct ";
  65739. lastX = i.x2;
  65740. lastY = i.y2;
  65741. }
  65742. break;
  65743. case Path::Iterator::cubicTo:
  65744. writeXY (i.x1, i.y1);
  65745. writeXY (i.x2, i.y2);
  65746. writeXY (i.x3, i.y3);
  65747. out << "ct ";
  65748. lastX = i.x3;
  65749. lastY = i.y3;
  65750. break;
  65751. case Path::Iterator::closePath:
  65752. out << "cp ";
  65753. break;
  65754. default:
  65755. jassertfalse
  65756. break;
  65757. }
  65758. }
  65759. out << '\n';
  65760. }
  65761. void LowLevelGraphicsPostScriptRenderer::writeTransform (const AffineTransform& trans) const
  65762. {
  65763. out << "[ "
  65764. << trans.mat00 << ' '
  65765. << trans.mat10 << ' '
  65766. << trans.mat01 << ' '
  65767. << trans.mat11 << ' '
  65768. << trans.mat02 << ' '
  65769. << trans.mat12 << " ] concat ";
  65770. }
  65771. void LowLevelGraphicsPostScriptRenderer::setFill (const FillType& fillType)
  65772. {
  65773. stateStack.getLast()->fillType = fillType;
  65774. }
  65775. void LowLevelGraphicsPostScriptRenderer::setOpacity (float /*opacity*/)
  65776. {
  65777. }
  65778. void LowLevelGraphicsPostScriptRenderer::setInterpolationQuality (Graphics::ResamplingQuality /*quality*/)
  65779. {
  65780. }
  65781. void LowLevelGraphicsPostScriptRenderer::fillRect (const Rectangle& r, const bool /*replaceExistingContents*/)
  65782. {
  65783. if (stateStack.getLast()->fillType.isColour())
  65784. {
  65785. writeClip();
  65786. writeColour (stateStack.getLast()->fillType.colour);
  65787. Rectangle r2 (r.translated (stateStack.getLast()->xOffset, stateStack.getLast()->yOffset));
  65788. out << r2.getX() << ' ' << -r2.getBottom() << ' ' << r2.getWidth() << ' ' << r2.getHeight() << " rectfill\n";
  65789. }
  65790. else
  65791. {
  65792. Path p;
  65793. p.addRectangle (r);
  65794. fillPath (p, AffineTransform::identity);
  65795. }
  65796. }
  65797. void LowLevelGraphicsPostScriptRenderer::fillPath (const Path& path, const AffineTransform& t)
  65798. {
  65799. if (stateStack.getLast()->fillType.isColour())
  65800. {
  65801. writeClip();
  65802. Path p (path);
  65803. p.applyTransform (t.translated ((float) stateStack.getLast()->xOffset,
  65804. (float) stateStack.getLast()->yOffset));
  65805. writePath (p);
  65806. writeColour (stateStack.getLast()->fillType.colour);
  65807. out << "fill\n";
  65808. }
  65809. else if (stateStack.getLast()->fillType.isGradient())
  65810. {
  65811. // this doesn't work correctly yet - it could be improved to handle solid gradients, but
  65812. // postscript can't do semi-transparent ones.
  65813. notPossibleInPostscriptAssert // you can disable this warning by setting the WARN_ABOUT_NON_POSTSCRIPT_OPERATIONS flag at the top of this file
  65814. writeClip();
  65815. out << "gsave ";
  65816. {
  65817. Path p (path);
  65818. p.applyTransform (t.translated ((float) stateStack.getLast()->xOffset, (float) stateStack.getLast()->yOffset));
  65819. writePath (p);
  65820. out << "clip\n";
  65821. }
  65822. const Rectangle bounds (stateStack.getLast()->clip.getBounds());
  65823. // ideally this would draw lots of lines or ellipses to approximate the gradient, but for the
  65824. // time-being, this just fills it with the average colour..
  65825. writeColour (stateStack.getLast()->fillType.gradient->getColourAtPosition (0.5f));
  65826. out << bounds.getX() << ' ' << -bounds.getBottom() << ' ' << bounds.getWidth() << ' ' << bounds.getHeight() << " rectfill\n";
  65827. out << "grestore\n";
  65828. }
  65829. }
  65830. void LowLevelGraphicsPostScriptRenderer::writeImage (const Image& im,
  65831. const int sx, const int sy,
  65832. const int maxW, const int maxH) const
  65833. {
  65834. out << "{<\n";
  65835. const int w = jmin (maxW, im.getWidth());
  65836. const int h = jmin (maxH, im.getHeight());
  65837. int charsOnLine = 0;
  65838. const Image::BitmapData srcData (im, 0, 0, w, h);
  65839. Colour pixel;
  65840. for (int y = h; --y >= 0;)
  65841. {
  65842. for (int x = 0; x < w; ++x)
  65843. {
  65844. const uint8* pixelData = srcData.getPixelPointer (x, y);
  65845. if (x >= sx && y >= sy)
  65846. {
  65847. if (im.isARGB())
  65848. {
  65849. PixelARGB p (*(const PixelARGB*) pixelData);
  65850. p.unpremultiply();
  65851. pixel = Colours::white.overlaidWith (Colour (p.getARGB()));
  65852. }
  65853. else if (im.isRGB())
  65854. {
  65855. pixel = Colour (((const PixelRGB*) pixelData)->getARGB());
  65856. }
  65857. else
  65858. {
  65859. pixel = Colour ((uint8) 0, (uint8) 0, (uint8) 0, *pixelData);
  65860. }
  65861. }
  65862. else
  65863. {
  65864. pixel = Colours::transparentWhite;
  65865. }
  65866. const uint8 pixelValues[3] = { pixel.getRed(), pixel.getGreen(), pixel.getBlue() };
  65867. out << String::toHexString (pixelValues, 3, 0);
  65868. charsOnLine += 3;
  65869. if (charsOnLine > 100)
  65870. {
  65871. out << '\n';
  65872. charsOnLine = 0;
  65873. }
  65874. }
  65875. }
  65876. out << "\n>}\n";
  65877. }
  65878. void LowLevelGraphicsPostScriptRenderer::drawImage (const Image& sourceImage, const Rectangle& srcClip,
  65879. const AffineTransform& transform, const bool /*fillEntireClipAsTiles*/)
  65880. {
  65881. const int w = jmin (sourceImage.getWidth(), srcClip.getRight());
  65882. const int h = jmin (sourceImage.getHeight(), srcClip.getBottom());
  65883. writeClip();
  65884. out << "gsave ";
  65885. writeTransform (transform.translated ((float) stateStack.getLast()->xOffset, (float) stateStack.getLast()->yOffset)
  65886. .scaled (1.0f, -1.0f));
  65887. RectangleList imageClip;
  65888. sourceImage.createSolidAreaMask (imageClip, 0.5f);
  65889. imageClip.clipTo (srcClip);
  65890. out << "newpath ";
  65891. int itemsOnLine = 0;
  65892. for (RectangleList::Iterator i (imageClip); i.next();)
  65893. {
  65894. if (++itemsOnLine == 6)
  65895. {
  65896. out << '\n';
  65897. itemsOnLine = 0;
  65898. }
  65899. const Rectangle& r = *i.getRectangle();
  65900. out << r.getX() << ' ' << r.getY() << ' ' << r.getWidth() << ' ' << r.getHeight() << " pr ";
  65901. }
  65902. out << " clip newpath\n";
  65903. out << w << ' ' << h << " scale\n";
  65904. out << w << ' ' << h << " 8 [" << w << " 0 0 -" << h << ' ' << (int) 0 << ' ' << h << " ]\n";
  65905. writeImage (sourceImage, srcClip.getX(), srcClip.getY(), srcClip.getWidth(), srcClip.getHeight());
  65906. out << "false 3 colorimage grestore\n";
  65907. needToClip = true;
  65908. }
  65909. void LowLevelGraphicsPostScriptRenderer::drawLine (double x1, double y1, double x2, double y2)
  65910. {
  65911. Path p;
  65912. p.addLineSegment ((float) x1, (float) y1, (float) x2, (float) y2, 1.0f);
  65913. fillPath (p, AffineTransform::identity);
  65914. }
  65915. void LowLevelGraphicsPostScriptRenderer::drawVerticalLine (const int x, double top, double bottom)
  65916. {
  65917. drawLine (x, top, x, bottom);
  65918. }
  65919. void LowLevelGraphicsPostScriptRenderer::drawHorizontalLine (const int y, double left, double right)
  65920. {
  65921. drawLine (left, y, right, y);
  65922. }
  65923. void LowLevelGraphicsPostScriptRenderer::setFont (const Font& newFont)
  65924. {
  65925. stateStack.getLast()->font = newFont;
  65926. }
  65927. const Font LowLevelGraphicsPostScriptRenderer::getFont()
  65928. {
  65929. return stateStack.getLast()->font;
  65930. }
  65931. void LowLevelGraphicsPostScriptRenderer::drawGlyph (int glyphNumber, const AffineTransform& transform)
  65932. {
  65933. Path p;
  65934. Font& font = stateStack.getLast()->font;
  65935. font.getTypeface()->getOutlineForGlyph (glyphNumber, p);
  65936. fillPath (p, AffineTransform::scale (font.getHeight() * font.getHorizontalScale(), font.getHeight()).followedBy (transform));
  65937. }
  65938. END_JUCE_NAMESPACE
  65939. /********* End of inlined file: juce_LowLevelGraphicsPostScriptRenderer.cpp *********/
  65940. /********* Start of inlined file: juce_LowLevelGraphicsSoftwareRenderer.cpp *********/
  65941. BEGIN_JUCE_NAMESPACE
  65942. #if (JUCE_WINDOWS || JUCE_LINUX) && ! JUCE_64BIT
  65943. #define JUCE_USE_SSE_INSTRUCTIONS 1
  65944. #endif
  65945. #if JUCE_MSVC && JUCE_DEBUG
  65946. #pragma warning (disable: 4714) // warning about forcedinline methods not being inlined
  65947. #endif
  65948. #if JUCE_MSVC
  65949. #pragma warning (push)
  65950. #pragma warning (disable: 4127) // "expression is constant" warning
  65951. #endif
  65952. template <class PixelType, bool replaceExisting = false>
  65953. class SolidColourEdgeTableRenderer
  65954. {
  65955. public:
  65956. SolidColourEdgeTableRenderer (const Image::BitmapData& data_, const PixelARGB& colour) throw()
  65957. : data (data_),
  65958. sourceColour (colour)
  65959. {
  65960. if (sizeof (PixelType) == 3)
  65961. {
  65962. areRGBComponentsEqual = sourceColour.getRed() == sourceColour.getGreen()
  65963. && sourceColour.getGreen() == sourceColour.getBlue();
  65964. filler[0].set (sourceColour);
  65965. filler[1].set (sourceColour);
  65966. filler[2].set (sourceColour);
  65967. filler[3].set (sourceColour);
  65968. }
  65969. }
  65970. forcedinline void setEdgeTableYPos (const int y) throw()
  65971. {
  65972. linePixels = (PixelType*) data.getLinePointer (y);
  65973. }
  65974. forcedinline void handleEdgeTablePixel (const int x, const int alphaLevel) const throw()
  65975. {
  65976. if (replaceExisting)
  65977. linePixels[x].set (sourceColour);
  65978. else
  65979. linePixels[x].blend (sourceColour, alphaLevel);
  65980. }
  65981. forcedinline void handleEdgeTableLine (const int x, int width, const int alphaLevel) const throw()
  65982. {
  65983. PixelARGB p (sourceColour);
  65984. p.multiplyAlpha (alphaLevel);
  65985. PixelType* dest = linePixels + x;
  65986. if (replaceExisting || p.getAlpha() >= 0xff)
  65987. replaceLine (dest, p, width);
  65988. else
  65989. blendLine (dest, p, width);
  65990. }
  65991. private:
  65992. const Image::BitmapData& data;
  65993. PixelType* linePixels;
  65994. PixelARGB sourceColour;
  65995. PixelRGB filler [4];
  65996. bool areRGBComponentsEqual;
  65997. forcedinline void blendLine (PixelType* dest, const PixelARGB& colour, int width) const
  65998. {
  65999. do
  66000. {
  66001. dest->blend (colour);
  66002. ++dest;
  66003. } while (--width > 0);
  66004. }
  66005. forcedinline void replaceLine (PixelRGB* dest, const PixelARGB& colour, int width) const throw()
  66006. {
  66007. if (areRGBComponentsEqual) // if all the component values are the same, we can cheat..
  66008. {
  66009. memset (dest, colour.getRed(), width * 3);
  66010. }
  66011. else
  66012. {
  66013. if (width >> 5)
  66014. {
  66015. const int* const intFiller = (const int*) filler;
  66016. while (width > 8 && (((pointer_sized_int) dest) & 7) != 0)
  66017. {
  66018. dest->set (colour);
  66019. ++dest;
  66020. --width;
  66021. }
  66022. while (width > 4)
  66023. {
  66024. ((int*) dest) [0] = intFiller[0];
  66025. ((int*) dest) [1] = intFiller[1];
  66026. ((int*) dest) [2] = intFiller[2];
  66027. dest = (PixelRGB*) (((uint8*) dest) + 12);
  66028. width -= 4;
  66029. }
  66030. }
  66031. while (--width >= 0)
  66032. {
  66033. dest->set (colour);
  66034. ++dest;
  66035. }
  66036. }
  66037. }
  66038. forcedinline void replaceLine (PixelAlpha* dest, const PixelARGB& colour, int width) const throw()
  66039. {
  66040. memset (dest, colour.getAlpha(), width);
  66041. }
  66042. forcedinline void replaceLine (PixelARGB* dest, const PixelARGB& colour, int width) const throw()
  66043. {
  66044. do
  66045. {
  66046. dest->set (colour);
  66047. ++dest;
  66048. } while (--width > 0);
  66049. }
  66050. SolidColourEdgeTableRenderer (const SolidColourEdgeTableRenderer&);
  66051. const SolidColourEdgeTableRenderer& operator= (const SolidColourEdgeTableRenderer&);
  66052. };
  66053. class LinearGradientPixelGenerator
  66054. {
  66055. public:
  66056. LinearGradientPixelGenerator (const ColourGradient& gradient, const AffineTransform& transform, const PixelARGB* const lookupTable_, const int numEntries_)
  66057. : lookupTable (lookupTable_), numEntries (numEntries_)
  66058. {
  66059. jassert (numEntries_ >= 0);
  66060. float x1 = gradient.x1;
  66061. float y1 = gradient.y1;
  66062. float x2 = gradient.x2;
  66063. float y2 = gradient.y2;
  66064. if (! transform.isIdentity())
  66065. {
  66066. const Line l (x2, y2, x1, y1);
  66067. const Point p3 = l.getPointAlongLine (0.0f, 100.0f);
  66068. float x3 = p3.getX();
  66069. float y3 = p3.getY();
  66070. transform.transformPoint (x1, y1);
  66071. transform.transformPoint (x2, y2);
  66072. transform.transformPoint (x3, y3);
  66073. const Line l2 (x2, y2, x3, y3);
  66074. const float prop = l2.findNearestPointTo (x1, y1);
  66075. const Point newP2 (l2.getPointAlongLineProportionally (prop));
  66076. x2 = newP2.getX();
  66077. y2 = newP2.getY();
  66078. }
  66079. vertical = fabs (x1 - x2) < 0.001f;
  66080. horizontal = fabs (y1 - y2) < 0.001f;
  66081. if (vertical)
  66082. {
  66083. scale = roundToInt ((numEntries << (int) numScaleBits) / (double) (y2 - y1));
  66084. start = roundToInt (y1 * scale);
  66085. }
  66086. else if (horizontal)
  66087. {
  66088. scale = roundToInt ((numEntries << (int) numScaleBits) / (double) (x2 - x1));
  66089. start = roundToInt (x1 * scale);
  66090. }
  66091. else
  66092. {
  66093. grad = (y2 - y1) / (double) (x1 - x2);
  66094. yTerm = y1 - x1 / grad;
  66095. scale = roundToInt ((numEntries << (int) numScaleBits) / (yTerm * grad - (y2 * grad - x2)));
  66096. grad *= scale;
  66097. }
  66098. }
  66099. forcedinline void setY (const int y) throw()
  66100. {
  66101. if (vertical)
  66102. linePix = lookupTable [jlimit (0, numEntries, (y * scale - start) >> (int) numScaleBits)];
  66103. else if (! horizontal)
  66104. start = roundToInt ((y - yTerm) * grad);
  66105. }
  66106. forcedinline const PixelARGB getPixel (const int x) const throw()
  66107. {
  66108. return vertical ? linePix
  66109. : lookupTable [jlimit (0, numEntries, (x * scale - start) >> (int) numScaleBits)];
  66110. }
  66111. private:
  66112. const PixelARGB* const lookupTable;
  66113. const int numEntries;
  66114. PixelARGB linePix;
  66115. int start, scale;
  66116. double grad, yTerm;
  66117. bool vertical, horizontal;
  66118. enum { numScaleBits = 12 };
  66119. LinearGradientPixelGenerator (const LinearGradientPixelGenerator&);
  66120. const LinearGradientPixelGenerator& operator= (const LinearGradientPixelGenerator&);
  66121. };
  66122. class RadialGradientPixelGenerator
  66123. {
  66124. public:
  66125. RadialGradientPixelGenerator (const ColourGradient& gradient, const AffineTransform&,
  66126. const PixelARGB* const lookupTable_, const int numEntries_) throw()
  66127. : lookupTable (lookupTable_),
  66128. numEntries (numEntries_),
  66129. gx1 (gradient.x1),
  66130. gy1 (gradient.y1)
  66131. {
  66132. jassert (numEntries_ >= 0);
  66133. const float gdx = gradient.x1 - gradient.x2;
  66134. const float gdy = gradient.y1 - gradient.y2;
  66135. maxDist = gdx * gdx + gdy * gdy;
  66136. invScale = numEntries / sqrt (maxDist);
  66137. jassert (roundToInt (sqrt (maxDist) * invScale) <= numEntries);
  66138. }
  66139. forcedinline void setY (const int y) throw()
  66140. {
  66141. dy = y - gy1;
  66142. dy *= dy;
  66143. }
  66144. forcedinline const PixelARGB getPixel (const int px) const throw()
  66145. {
  66146. double x = px - gx1;
  66147. x *= x;
  66148. x += dy;
  66149. return lookupTable [x >= maxDist ? numEntries : roundToInt (sqrt (x) * invScale)];
  66150. }
  66151. protected:
  66152. const PixelARGB* const lookupTable;
  66153. const int numEntries;
  66154. const double gx1, gy1;
  66155. double maxDist, invScale, dy;
  66156. RadialGradientPixelGenerator (const RadialGradientPixelGenerator&);
  66157. const RadialGradientPixelGenerator& operator= (const RadialGradientPixelGenerator&);
  66158. };
  66159. class TransformedRadialGradientPixelGenerator : public RadialGradientPixelGenerator
  66160. {
  66161. public:
  66162. TransformedRadialGradientPixelGenerator (const ColourGradient& gradient, const AffineTransform& transform,
  66163. const PixelARGB* const lookupTable_, const int numEntries_) throw()
  66164. : RadialGradientPixelGenerator (gradient, transform, lookupTable_, numEntries_),
  66165. inverseTransform (transform.inverted())
  66166. {
  66167. tM10 = inverseTransform.mat10;
  66168. tM00 = inverseTransform.mat00;
  66169. }
  66170. forcedinline void setY (const int y) throw()
  66171. {
  66172. lineYM01 = inverseTransform.mat01 * y + inverseTransform.mat02 - gx1;
  66173. lineYM11 = inverseTransform.mat11 * y + inverseTransform.mat12 - gy1;
  66174. }
  66175. forcedinline const PixelARGB getPixel (const int px) const throw()
  66176. {
  66177. double x = px;
  66178. const double y = tM10 * x + lineYM11;
  66179. x = tM00 * x + lineYM01;
  66180. x *= x;
  66181. x += y * y;
  66182. if (x >= maxDist)
  66183. return lookupTable [numEntries];
  66184. else
  66185. return lookupTable [jmin (numEntries, roundToInt (sqrt (x) * invScale))];
  66186. }
  66187. private:
  66188. double tM10, tM00, lineYM01, lineYM11;
  66189. const AffineTransform inverseTransform;
  66190. TransformedRadialGradientPixelGenerator (const TransformedRadialGradientPixelGenerator&);
  66191. const TransformedRadialGradientPixelGenerator& operator= (const TransformedRadialGradientPixelGenerator&);
  66192. };
  66193. template <class PixelType, class GradientType>
  66194. class GradientEdgeTableRenderer : public GradientType
  66195. {
  66196. public:
  66197. GradientEdgeTableRenderer (const Image::BitmapData& destData_, const ColourGradient& gradient, const AffineTransform& transform,
  66198. const PixelARGB* const lookupTable_, const int numEntries_) throw()
  66199. : GradientType (gradient, transform, lookupTable_, numEntries_ - 1),
  66200. destData (destData_)
  66201. {
  66202. }
  66203. forcedinline void setEdgeTableYPos (const int y) throw()
  66204. {
  66205. linePixels = (PixelType*) destData.getLinePointer (y);
  66206. GradientType::setY (y);
  66207. }
  66208. forcedinline void handleEdgeTablePixel (const int x, const int alphaLevel) const throw()
  66209. {
  66210. linePixels[x].blend (GradientType::getPixel (x), alphaLevel);
  66211. }
  66212. forcedinline void handleEdgeTableLine (int x, int width, const int alphaLevel) const throw()
  66213. {
  66214. PixelType* dest = linePixels + x;
  66215. if (alphaLevel < 0xff)
  66216. {
  66217. do
  66218. {
  66219. (dest++)->blend (GradientType::getPixel (x++), alphaLevel);
  66220. } while (--width > 0);
  66221. }
  66222. else
  66223. {
  66224. do
  66225. {
  66226. (dest++)->blend (GradientType::getPixel (x++));
  66227. } while (--width > 0);
  66228. }
  66229. }
  66230. private:
  66231. const Image::BitmapData& destData;
  66232. PixelType* linePixels;
  66233. GradientEdgeTableRenderer (const GradientEdgeTableRenderer&);
  66234. const GradientEdgeTableRenderer& operator= (const GradientEdgeTableRenderer&);
  66235. };
  66236. static forcedinline int safeModulo (int n, const int divisor) throw()
  66237. {
  66238. jassert (divisor > 0);
  66239. n %= divisor;
  66240. return (n < 0) ? (n + divisor) : n;
  66241. }
  66242. template <class DestPixelType, class SrcPixelType, bool repeatPattern>
  66243. class ImageFillEdgeTableRenderer
  66244. {
  66245. public:
  66246. ImageFillEdgeTableRenderer (const Image::BitmapData& destData_,
  66247. const Image::BitmapData& srcData_,
  66248. const int extraAlpha_,
  66249. const int x, const int y) throw()
  66250. : destData (destData_),
  66251. srcData (srcData_),
  66252. extraAlpha (extraAlpha_ + 1),
  66253. xOffset (repeatPattern ? safeModulo (x, srcData_.width) - srcData_.width : x),
  66254. yOffset (repeatPattern ? safeModulo (y, srcData_.height) - srcData_.height : y)
  66255. {
  66256. }
  66257. forcedinline void setEdgeTableYPos (int y) throw()
  66258. {
  66259. linePixels = (DestPixelType*) destData.getLinePointer (y);
  66260. y -= yOffset;
  66261. if (repeatPattern)
  66262. {
  66263. jassert (y >= 0);
  66264. y %= srcData.height;
  66265. }
  66266. sourceLineStart = (SrcPixelType*) srcData.getLinePointer (y);
  66267. }
  66268. forcedinline void handleEdgeTablePixel (int x, int alphaLevel) const throw()
  66269. {
  66270. alphaLevel = (alphaLevel * extraAlpha) >> 8;
  66271. linePixels[x].blend (sourceLineStart [repeatPattern ? ((x - xOffset) % srcData.width) : (x - xOffset)], alphaLevel);
  66272. }
  66273. forcedinline void handleEdgeTableLine (int x, int width, int alphaLevel) const throw()
  66274. {
  66275. DestPixelType* dest = linePixels + x;
  66276. alphaLevel = (alphaLevel * extraAlpha) >> 8;
  66277. x -= xOffset;
  66278. jassert (repeatPattern || (x >= 0 && x + width <= srcData.width));
  66279. if (alphaLevel < 0xfe)
  66280. {
  66281. do
  66282. {
  66283. dest++ ->blend (sourceLineStart [repeatPattern ? (x++ % srcData.width) : x++], alphaLevel);
  66284. } while (--width > 0);
  66285. }
  66286. else
  66287. {
  66288. if (repeatPattern)
  66289. {
  66290. do
  66291. {
  66292. dest++ ->blend (sourceLineStart [x++ % srcData.width]);
  66293. } while (--width > 0);
  66294. }
  66295. else
  66296. {
  66297. copyRow (dest, sourceLineStart + x, width);
  66298. }
  66299. }
  66300. }
  66301. void clipEdgeTableLine (EdgeTable& et, int x, int y, int width) throw()
  66302. {
  66303. jassert (x - xOffset >= 0 && x + width - xOffset <= srcData.width);
  66304. SrcPixelType* s = (SrcPixelType*) srcData.getLinePointer (y - yOffset);
  66305. uint8* mask = (uint8*) (s + x - xOffset);
  66306. if (sizeof (SrcPixelType) == sizeof (PixelARGB))
  66307. mask += PixelARGB::indexA;
  66308. et.clipLineToMask (x, y, mask, sizeof (SrcPixelType), width);
  66309. }
  66310. private:
  66311. const Image::BitmapData& destData;
  66312. const Image::BitmapData& srcData;
  66313. const int extraAlpha, xOffset, yOffset;
  66314. DestPixelType* linePixels;
  66315. SrcPixelType* sourceLineStart;
  66316. template <class PixelType1, class PixelType2>
  66317. forcedinline static void copyRow (PixelType1* dest, PixelType2* src, int width) throw()
  66318. {
  66319. do
  66320. {
  66321. dest++ ->blend (*src++);
  66322. } while (--width > 0);
  66323. }
  66324. forcedinline static void copyRow (PixelRGB* dest, PixelRGB* src, int width) throw()
  66325. {
  66326. memcpy (dest, src, width * sizeof (PixelRGB));
  66327. }
  66328. ImageFillEdgeTableRenderer (const ImageFillEdgeTableRenderer&);
  66329. const ImageFillEdgeTableRenderer& operator= (const ImageFillEdgeTableRenderer&);
  66330. };
  66331. template <class DestPixelType, class SrcPixelType, bool repeatPattern>
  66332. class TransformedImageFillEdgeTableRenderer
  66333. {
  66334. public:
  66335. TransformedImageFillEdgeTableRenderer (const Image::BitmapData& destData_,
  66336. const Image::BitmapData& srcData_,
  66337. const AffineTransform& transform,
  66338. const int extraAlpha_,
  66339. const bool betterQuality_) throw()
  66340. : interpolator (transform),
  66341. destData (destData_),
  66342. srcData (srcData_),
  66343. extraAlpha (extraAlpha_ + 1),
  66344. betterQuality (betterQuality_),
  66345. pixelOffset (betterQuality_ ? 0.5f : 0.0f),
  66346. pixelOffsetInt (betterQuality_ ? -128 : 0),
  66347. maxX (srcData_.width - 1),
  66348. maxY (srcData_.height - 1),
  66349. scratchSize (2048)
  66350. {
  66351. scratchBuffer.malloc (scratchSize);
  66352. }
  66353. ~TransformedImageFillEdgeTableRenderer() throw()
  66354. {
  66355. }
  66356. forcedinline void setEdgeTableYPos (const int newY) throw()
  66357. {
  66358. y = newY;
  66359. linePixels = (DestPixelType*) destData.getLinePointer (newY);
  66360. }
  66361. forcedinline void handleEdgeTablePixel (const int x, int alphaLevel) throw()
  66362. {
  66363. alphaLevel *= extraAlpha;
  66364. alphaLevel >>= 8;
  66365. SrcPixelType p;
  66366. generate (&p, x, 1);
  66367. linePixels[x].blend (p, alphaLevel);
  66368. }
  66369. forcedinline void handleEdgeTableLine (const int x, int width, int alphaLevel) throw()
  66370. {
  66371. if (width > scratchSize)
  66372. {
  66373. scratchSize = width;
  66374. scratchBuffer.malloc (scratchSize);
  66375. }
  66376. SrcPixelType* span = scratchBuffer;
  66377. generate (span, x, width);
  66378. DestPixelType* dest = linePixels + x;
  66379. alphaLevel *= extraAlpha;
  66380. alphaLevel >>= 8;
  66381. if (alphaLevel < 0xfe)
  66382. {
  66383. do
  66384. {
  66385. dest++ ->blend (*span++, alphaLevel);
  66386. } while (--width > 0);
  66387. }
  66388. else
  66389. {
  66390. do
  66391. {
  66392. dest++ ->blend (*span++);
  66393. } while (--width > 0);
  66394. }
  66395. }
  66396. void clipEdgeTableLine (EdgeTable& et, int x, int y_, int width) throw()
  66397. {
  66398. if (width > scratchSize)
  66399. {
  66400. scratchSize = width;
  66401. scratchBuffer.malloc (scratchSize);
  66402. }
  66403. uint8* mask = (uint8*) scratchBuffer;
  66404. y = y_;
  66405. generate ((SrcPixelType*) mask, x, width);
  66406. if (sizeof (SrcPixelType) == sizeof (PixelARGB))
  66407. mask += PixelARGB::indexA;
  66408. et.clipLineToMask (x, y_, mask, sizeof (SrcPixelType), width);
  66409. }
  66410. private:
  66411. void generate (PixelARGB* dest, const int x, int numPixels) throw()
  66412. {
  66413. this->interpolator.setStartOfLine (x + pixelOffset, y + pixelOffset, numPixels);
  66414. do
  66415. {
  66416. int hiResX, hiResY;
  66417. this->interpolator.next (hiResX, hiResY);
  66418. hiResX += pixelOffsetInt;
  66419. hiResY += pixelOffsetInt;
  66420. int loResX = hiResX >> 8;
  66421. int loResY = hiResY >> 8;
  66422. if (repeatPattern)
  66423. {
  66424. loResX = safeModulo (loResX, srcData.width);
  66425. loResY = safeModulo (loResY, srcData.height);
  66426. }
  66427. if (betterQuality
  66428. && ((unsigned int) loResX) < (unsigned int) maxX
  66429. && ((unsigned int) loResY) < (unsigned int) maxY)
  66430. {
  66431. uint32 c[4] = { 256 * 128, 256 * 128, 256 * 128, 256 * 128 };
  66432. hiResX &= 255;
  66433. hiResY &= 255;
  66434. const uint8* src = this->srcData.getPixelPointer (loResX, loResY);
  66435. uint32 weight = (256 - hiResX) * (256 - hiResY);
  66436. c[0] += weight * src[0];
  66437. c[1] += weight * src[1];
  66438. c[2] += weight * src[2];
  66439. c[3] += weight * src[3];
  66440. weight = hiResX * (256 - hiResY);
  66441. c[0] += weight * src[4];
  66442. c[1] += weight * src[5];
  66443. c[2] += weight * src[6];
  66444. c[3] += weight * src[7];
  66445. src += this->srcData.lineStride;
  66446. weight = (256 - hiResX) * hiResY;
  66447. c[0] += weight * src[0];
  66448. c[1] += weight * src[1];
  66449. c[2] += weight * src[2];
  66450. c[3] += weight * src[3];
  66451. weight = hiResX * hiResY;
  66452. c[0] += weight * src[4];
  66453. c[1] += weight * src[5];
  66454. c[2] += weight * src[6];
  66455. c[3] += weight * src[7];
  66456. dest->setARGB ((uint8) (c[PixelARGB::indexA] >> 16),
  66457. (uint8) (c[PixelARGB::indexR] >> 16),
  66458. (uint8) (c[PixelARGB::indexG] >> 16),
  66459. (uint8) (c[PixelARGB::indexB] >> 16));
  66460. }
  66461. else
  66462. {
  66463. if (! repeatPattern)
  66464. {
  66465. // Beyond the edges, just repeat the edge pixels and leave the anti-aliasing to be handled by the edgetable
  66466. if (loResX < 0) loResX = 0;
  66467. if (loResY < 0) loResY = 0;
  66468. if (loResX > maxX) loResX = maxX;
  66469. if (loResY > maxY) loResY = maxY;
  66470. }
  66471. dest->set (*(const PixelARGB*) this->srcData.getPixelPointer (loResX, loResY));
  66472. }
  66473. ++dest;
  66474. } while (--numPixels > 0);
  66475. }
  66476. void generate (PixelRGB* dest, const int x, int numPixels) throw()
  66477. {
  66478. this->interpolator.setStartOfLine (x + pixelOffset, y + pixelOffset, numPixels);
  66479. do
  66480. {
  66481. int hiResX, hiResY;
  66482. this->interpolator.next (hiResX, hiResY);
  66483. hiResX += pixelOffsetInt;
  66484. hiResY += pixelOffsetInt;
  66485. int loResX = hiResX >> 8;
  66486. int loResY = hiResY >> 8;
  66487. if (repeatPattern)
  66488. {
  66489. loResX = safeModulo (loResX, srcData.width);
  66490. loResY = safeModulo (loResY, srcData.height);
  66491. }
  66492. if (betterQuality
  66493. && ((unsigned int) loResX) < (unsigned int) maxX
  66494. && ((unsigned int) loResY) < (unsigned int) maxY)
  66495. {
  66496. uint32 c[3] = { 256 * 128, 256 * 128, 256 * 128 };
  66497. hiResX &= 255;
  66498. hiResY &= 255;
  66499. const uint8* src = this->srcData.getPixelPointer (loResX, loResY);
  66500. unsigned int weight = (256 - hiResX) * (256 - hiResY);
  66501. c[0] += weight * src[0];
  66502. c[1] += weight * src[1];
  66503. c[2] += weight * src[2];
  66504. weight = hiResX * (256 - hiResY);
  66505. c[0] += weight * src[3];
  66506. c[1] += weight * src[4];
  66507. c[2] += weight * src[5];
  66508. src += this->srcData.lineStride;
  66509. weight = (256 - hiResX) * hiResY;
  66510. c[0] += weight * src[0];
  66511. c[1] += weight * src[1];
  66512. c[2] += weight * src[2];
  66513. weight = hiResX * hiResY;
  66514. c[0] += weight * src[3];
  66515. c[1] += weight * src[4];
  66516. c[2] += weight * src[5];
  66517. dest->setARGB ((uint8) 255,
  66518. (uint8) (c[PixelRGB::indexR] >> 16),
  66519. (uint8) (c[PixelRGB::indexG] >> 16),
  66520. (uint8) (c[PixelRGB::indexB] >> 16));
  66521. }
  66522. else
  66523. {
  66524. if (! repeatPattern)
  66525. {
  66526. // Beyond the edges, just repeat the edge pixels and leave the anti-aliasing to be handled by the edgetable
  66527. if (loResX < 0) loResX = 0;
  66528. if (loResY < 0) loResY = 0;
  66529. if (loResX > maxX) loResX = maxX;
  66530. if (loResY > maxY) loResY = maxY;
  66531. }
  66532. dest->set (*(const PixelRGB*) this->srcData.getPixelPointer (loResX, loResY));
  66533. }
  66534. ++dest;
  66535. } while (--numPixels > 0);
  66536. }
  66537. void generate (PixelAlpha* dest, const int x, int numPixels) throw()
  66538. {
  66539. this->interpolator.setStartOfLine (x + pixelOffset, y + pixelOffset, numPixels);
  66540. do
  66541. {
  66542. int hiResX, hiResY;
  66543. this->interpolator.next (hiResX, hiResY);
  66544. hiResX += pixelOffsetInt;
  66545. hiResY += pixelOffsetInt;
  66546. int loResX = hiResX >> 8;
  66547. int loResY = hiResY >> 8;
  66548. if (repeatPattern)
  66549. {
  66550. loResX = safeModulo (loResX, srcData.width);
  66551. loResY = safeModulo (loResY, srcData.height);
  66552. }
  66553. if (betterQuality
  66554. && ((unsigned int) loResX) < (unsigned int) maxX
  66555. && ((unsigned int) loResY) < (unsigned int) maxY)
  66556. {
  66557. hiResX &= 255;
  66558. hiResY &= 255;
  66559. const uint8* src = this->srcData.getPixelPointer (loResX, loResY);
  66560. uint32 c = 256 * 128;
  66561. c += src[0] * ((256 - hiResX) * (256 - hiResY));
  66562. c += src[1] * (hiResX * (256 - hiResY));
  66563. src += this->srcData.lineStride;
  66564. c += src[0] * ((256 - hiResX) * hiResY);
  66565. c += src[1] * (hiResX * hiResY);
  66566. *((uint8*) dest) = (uint8) c;
  66567. }
  66568. else
  66569. {
  66570. if (! repeatPattern)
  66571. {
  66572. // Beyond the edges, just repeat the edge pixels and leave the anti-aliasing to be handled by the edgetable
  66573. if (loResX < 0) loResX = 0;
  66574. if (loResY < 0) loResY = 0;
  66575. if (loResX > maxX) loResX = maxX;
  66576. if (loResY > maxY) loResY = maxY;
  66577. }
  66578. *((uint8*) dest) = *(this->srcData.getPixelPointer (loResX, loResY));
  66579. }
  66580. ++dest;
  66581. } while (--numPixels > 0);
  66582. }
  66583. class TransformedImageSpanInterpolator
  66584. {
  66585. public:
  66586. TransformedImageSpanInterpolator (const AffineTransform& transform) throw()
  66587. : inverseTransform (transform.inverted())
  66588. {}
  66589. void setStartOfLine (float x, float y, const int numPixels) throw()
  66590. {
  66591. float x1 = x, y1 = y;
  66592. inverseTransform.transformPoint (x1, y1);
  66593. x += numPixels;
  66594. inverseTransform.transformPoint (x, y);
  66595. xBresenham.set ((int) (x1 * 256.0f), (int) (x * 256.0f), numPixels);
  66596. yBresenham.set ((int) (y1 * 256.0f), (int) (y * 256.0f), numPixels);
  66597. }
  66598. void next (int& x, int& y) throw()
  66599. {
  66600. x = xBresenham.n;
  66601. xBresenham.stepToNext();
  66602. y = yBresenham.n;
  66603. yBresenham.stepToNext();
  66604. }
  66605. private:
  66606. class BresenhamInterpolator
  66607. {
  66608. public:
  66609. BresenhamInterpolator() throw() {}
  66610. void set (const int n1, const int n2, const int numSteps_) throw()
  66611. {
  66612. numSteps = jmax (1, numSteps_);
  66613. step = (n2 - n1) / numSteps;
  66614. remainder = modulo = (n2 - n1) % numSteps;
  66615. n = n1;
  66616. if (modulo <= 0)
  66617. {
  66618. modulo += numSteps;
  66619. remainder += numSteps;
  66620. --step;
  66621. }
  66622. modulo -= numSteps;
  66623. }
  66624. forcedinline void stepToNext() throw()
  66625. {
  66626. modulo += remainder;
  66627. n += step;
  66628. if (modulo > 0)
  66629. {
  66630. modulo -= numSteps;
  66631. ++n;
  66632. }
  66633. }
  66634. int n;
  66635. private:
  66636. int numSteps, step, modulo, remainder;
  66637. };
  66638. const AffineTransform inverseTransform;
  66639. BresenhamInterpolator xBresenham, yBresenham;
  66640. TransformedImageSpanInterpolator (const TransformedImageSpanInterpolator&);
  66641. const TransformedImageSpanInterpolator& operator= (const TransformedImageSpanInterpolator&);
  66642. };
  66643. TransformedImageSpanInterpolator interpolator;
  66644. const Image::BitmapData& destData;
  66645. const Image::BitmapData& srcData;
  66646. const int extraAlpha;
  66647. const bool betterQuality;
  66648. const float pixelOffset;
  66649. const int pixelOffsetInt, maxX, maxY;
  66650. int y;
  66651. DestPixelType* linePixels;
  66652. HeapBlock <SrcPixelType> scratchBuffer;
  66653. int scratchSize;
  66654. TransformedImageFillEdgeTableRenderer (const TransformedImageFillEdgeTableRenderer&);
  66655. const TransformedImageFillEdgeTableRenderer& operator= (const TransformedImageFillEdgeTableRenderer&);
  66656. };
  66657. class LLGCSavedState
  66658. {
  66659. public:
  66660. LLGCSavedState (const Rectangle& clip_, const int xOffset_, const int yOffset_,
  66661. const Font& font_, const FillType& fillType_,
  66662. const Graphics::ResamplingQuality interpolationQuality_) throw()
  66663. : edgeTable (new EdgeTableHolder (EdgeTable (clip_))),
  66664. xOffset (xOffset_), yOffset (yOffset_),
  66665. font (font_), fillType (fillType_),
  66666. interpolationQuality (interpolationQuality_)
  66667. {
  66668. }
  66669. LLGCSavedState (const LLGCSavedState& other) throw()
  66670. : edgeTable (other.edgeTable), xOffset (other.xOffset),
  66671. yOffset (other.yOffset), font (other.font),
  66672. fillType (other.fillType), interpolationQuality (other.interpolationQuality)
  66673. {
  66674. }
  66675. ~LLGCSavedState() throw()
  66676. {
  66677. }
  66678. bool clipToRectangle (const Rectangle& r) throw()
  66679. {
  66680. dupeEdgeTableIfMultiplyReferenced();
  66681. edgeTable->edgeTable.clipToRectangle (r.translated (xOffset, yOffset));
  66682. return ! edgeTable->edgeTable.isEmpty();
  66683. }
  66684. bool clipToRectangleList (const RectangleList& r) throw()
  66685. {
  66686. dupeEdgeTableIfMultiplyReferenced();
  66687. RectangleList offsetList (r);
  66688. offsetList.offsetAll (xOffset, yOffset);
  66689. EdgeTable e2 (offsetList);
  66690. edgeTable->edgeTable.clipToEdgeTable (e2);
  66691. return ! edgeTable->edgeTable.isEmpty();
  66692. }
  66693. bool excludeClipRectangle (const Rectangle& r) throw()
  66694. {
  66695. dupeEdgeTableIfMultiplyReferenced();
  66696. edgeTable->edgeTable.excludeRectangle (r.translated (xOffset, yOffset));
  66697. return ! edgeTable->edgeTable.isEmpty();
  66698. }
  66699. void clipToPath (const Path& p, const AffineTransform& transform) throw()
  66700. {
  66701. dupeEdgeTableIfMultiplyReferenced();
  66702. EdgeTable et (edgeTable->edgeTable.getMaximumBounds(), p, transform.translated ((float) xOffset, (float) yOffset));
  66703. edgeTable->edgeTable.clipToEdgeTable (et);
  66704. }
  66705. void fillEdgeTable (Image& image, EdgeTable& et, const bool replaceContents = false) throw()
  66706. {
  66707. et.clipToEdgeTable (edgeTable->edgeTable);
  66708. Image::BitmapData destData (image, 0, 0, image.getWidth(), image.getHeight(), true);
  66709. if (fillType.isGradient())
  66710. {
  66711. jassert (! replaceContents); // that option is just for solid colours
  66712. ColourGradient g2 (*(fillType.gradient));
  66713. g2.multiplyOpacity (fillType.getOpacity());
  66714. g2.x1 -= 0.5f; g2.y1 -= 0.5f;
  66715. g2.x2 -= 0.5f; g2.y2 -= 0.5f;
  66716. AffineTransform transform (fillType.transform.translated ((float) xOffset, (float) yOffset));
  66717. const bool isIdentity = transform.isOnlyTranslation();
  66718. if (isIdentity)
  66719. {
  66720. // If our translation doesn't involve any distortion, we can speed it up..
  66721. transform.transformPoint (g2.x1, g2.y1);
  66722. transform.transformPoint (g2.x2, g2.y2);
  66723. transform = AffineTransform::identity;
  66724. }
  66725. HeapBlock <PixelARGB> lookupTable;
  66726. const int numLookupEntries = g2.createLookupTable (transform, lookupTable);
  66727. jassert (numLookupEntries > 0);
  66728. switch (image.getFormat())
  66729. {
  66730. case Image::ARGB: renderGradient (et, destData, g2, transform, lookupTable, numLookupEntries, isIdentity, (PixelARGB*) 0); break;
  66731. case Image::RGB: renderGradient (et, destData, g2, transform, lookupTable, numLookupEntries, isIdentity, (PixelRGB*) 0); break;
  66732. default: renderGradient (et, destData, g2, transform, lookupTable, numLookupEntries, isIdentity, (PixelAlpha*) 0); break;
  66733. }
  66734. }
  66735. else if (fillType.isTiledImage())
  66736. {
  66737. renderImage (image, *(fillType.image), fillType.image->getBounds(), fillType.transform, &et);
  66738. }
  66739. else
  66740. {
  66741. const PixelARGB fillColour (fillType.colour.getPixelARGB());
  66742. switch (image.getFormat())
  66743. {
  66744. case Image::ARGB: renderSolidFill (et, destData, fillColour, replaceContents, (PixelARGB*) 0); break;
  66745. case Image::RGB: renderSolidFill (et, destData, fillColour, replaceContents, (PixelRGB*) 0); break;
  66746. default: renderSolidFill (et, destData, fillColour, replaceContents, (PixelAlpha*) 0); break;
  66747. }
  66748. }
  66749. }
  66750. void renderImage (Image& destImage, const Image& sourceImage, const Rectangle& srcClip,
  66751. const AffineTransform& t, const EdgeTable* const tiledFillClipRegion) throw()
  66752. {
  66753. const AffineTransform transform (t.translated ((float) xOffset, (float) yOffset));
  66754. const Image::BitmapData destData (destImage, 0, 0, destImage.getWidth(), destImage.getHeight(), true);
  66755. const Image::BitmapData srcData (sourceImage, srcClip.getX(), srcClip.getY(), srcClip.getWidth(), srcClip.getHeight());
  66756. const int alpha = fillType.colour.getAlpha();
  66757. const bool betterQuality = (interpolationQuality != Graphics::lowResamplingQuality);
  66758. if (transform.isOnlyTranslation())
  66759. {
  66760. // If our translation doesn't involve any distortion, just use a simple blit..
  66761. int tx = (int) (transform.getTranslationX() * 256.0f);
  66762. int ty = (int) (transform.getTranslationY() * 256.0f);
  66763. if ((! betterQuality) || ((tx | ty) & 224) == 0)
  66764. {
  66765. tx = ((tx + 128) >> 8);
  66766. ty = ((ty + 128) >> 8);
  66767. if (tiledFillClipRegion != 0)
  66768. {
  66769. blittedRenderImage (sourceImage, destImage, *tiledFillClipRegion, destData, srcData, alpha, tx, ty, true);
  66770. }
  66771. else
  66772. {
  66773. EdgeTable et (Rectangle (tx, ty, srcClip.getWidth(), srcClip.getHeight()).getIntersection (destImage.getBounds()));
  66774. et.clipToEdgeTable (edgeTable->edgeTable);
  66775. if (! et.isEmpty())
  66776. blittedRenderImage (sourceImage, destImage, et, destData, srcData, alpha, tx, ty, false);
  66777. }
  66778. return;
  66779. }
  66780. }
  66781. if (transform.isSingularity())
  66782. return;
  66783. if (tiledFillClipRegion != 0)
  66784. {
  66785. transformedRenderImage (sourceImage, destImage, *tiledFillClipRegion, destData, srcData, alpha, transform, betterQuality, true);
  66786. }
  66787. else
  66788. {
  66789. Path p;
  66790. p.addRectangle (0.0f, 0.0f, (float) srcClip.getWidth(), (float) srcClip.getHeight());
  66791. EdgeTable et (edgeTable->edgeTable.getMaximumBounds(), p, transform);
  66792. et.clipToEdgeTable (edgeTable->edgeTable);
  66793. if (! et.isEmpty())
  66794. transformedRenderImage (sourceImage, destImage, et, destData, srcData, alpha, transform, betterQuality, false);
  66795. }
  66796. }
  66797. void clipToImageAlpha (const Image& image, const Rectangle& srcClip, const AffineTransform& t) throw()
  66798. {
  66799. if (! image.hasAlphaChannel())
  66800. {
  66801. Path p;
  66802. p.addRectangle (srcClip);
  66803. clipToPath (p, t);
  66804. return;
  66805. }
  66806. dupeEdgeTableIfMultiplyReferenced();
  66807. const AffineTransform transform (t.translated ((float) xOffset, (float) yOffset));
  66808. const Image::BitmapData srcData (image, srcClip.getX(), srcClip.getY(), srcClip.getWidth(), srcClip.getHeight());
  66809. const bool betterQuality = (interpolationQuality != Graphics::lowResamplingQuality);
  66810. EdgeTable& et = edgeTable->edgeTable;
  66811. if (transform.isOnlyTranslation())
  66812. {
  66813. // If our translation doesn't involve any distortion, just use a simple blit..
  66814. const int tx = (int) (transform.getTranslationX() * 256.0f);
  66815. const int ty = (int) (transform.getTranslationY() * 256.0f);
  66816. if ((! betterQuality) || ((tx | ty) & 224) == 0)
  66817. {
  66818. const int imageX = ((tx + 128) >> 8);
  66819. const int imageY = ((ty + 128) >> 8);
  66820. if (image.getFormat() == Image::ARGB)
  66821. straightClipImage (et, srcData, imageX, imageY, (PixelARGB*)0);
  66822. else
  66823. straightClipImage (et, srcData, imageX, imageY, (PixelAlpha*)0);
  66824. return;
  66825. }
  66826. }
  66827. if (transform.isSingularity())
  66828. {
  66829. et.clipToRectangle (Rectangle());
  66830. return;
  66831. }
  66832. {
  66833. Path p;
  66834. p.addRectangle (0, 0, (float) srcData.width, (float) srcData.height);
  66835. EdgeTable et2 (et.getMaximumBounds(), p, transform);
  66836. et.clipToEdgeTable (et2);
  66837. }
  66838. if (! et.isEmpty())
  66839. {
  66840. if (image.getFormat() == Image::ARGB)
  66841. transformedClipImage (et, srcData, transform, betterQuality, (PixelARGB*)0);
  66842. else
  66843. transformedClipImage (et, srcData, transform, betterQuality, (PixelAlpha*)0);
  66844. }
  66845. }
  66846. template <class SrcPixelType>
  66847. void transformedClipImage (EdgeTable& et, const Image::BitmapData& srcData, const AffineTransform& transform, const bool betterQuality, const SrcPixelType *) throw()
  66848. {
  66849. TransformedImageFillEdgeTableRenderer <SrcPixelType, SrcPixelType, false> renderer (srcData, srcData, transform, 255, betterQuality);
  66850. for (int y = 0; y < et.getMaximumBounds().getHeight(); ++y)
  66851. renderer.clipEdgeTableLine (et, et.getMaximumBounds().getX(), y + et.getMaximumBounds().getY(),
  66852. et.getMaximumBounds().getWidth());
  66853. }
  66854. template <class SrcPixelType>
  66855. void straightClipImage (EdgeTable& et, const Image::BitmapData& srcData, int imageX, int imageY, const SrcPixelType *) throw()
  66856. {
  66857. Rectangle r (imageX, imageY, srcData.width, srcData.height);
  66858. et.clipToRectangle (r);
  66859. ImageFillEdgeTableRenderer <SrcPixelType, SrcPixelType, false> renderer (srcData, srcData, 255, imageX, imageY);
  66860. for (int y = 0; y < r.getHeight(); ++y)
  66861. renderer.clipEdgeTableLine (et, r.getX(), y + r.getY(), r.getWidth());
  66862. }
  66863. class EdgeTableHolder : public ReferenceCountedObject
  66864. {
  66865. public:
  66866. EdgeTableHolder (const EdgeTable& e) throw() : edgeTable (e) {}
  66867. EdgeTable edgeTable;
  66868. };
  66869. ReferenceCountedObjectPtr<EdgeTableHolder> edgeTable;
  66870. int xOffset, yOffset;
  66871. Font font;
  66872. FillType fillType;
  66873. Graphics::ResamplingQuality interpolationQuality;
  66874. private:
  66875. const LLGCSavedState& operator= (const LLGCSavedState&);
  66876. void dupeEdgeTableIfMultiplyReferenced() throw()
  66877. {
  66878. if (edgeTable->getReferenceCount() > 1)
  66879. edgeTable = new EdgeTableHolder (edgeTable->edgeTable);
  66880. }
  66881. template <class DestPixelType>
  66882. void renderGradient (EdgeTable& et, const Image::BitmapData& destData, const ColourGradient& g, const AffineTransform& transform,
  66883. const PixelARGB* const lookupTable, const int numLookupEntries, const bool isIdentity, DestPixelType*) throw()
  66884. {
  66885. jassert (destData.pixelStride == sizeof (DestPixelType));
  66886. if (g.isRadial)
  66887. {
  66888. if (isIdentity)
  66889. {
  66890. GradientEdgeTableRenderer <DestPixelType, RadialGradientPixelGenerator> renderer (destData, g, transform, lookupTable, numLookupEntries);
  66891. et.iterate (renderer);
  66892. }
  66893. else
  66894. {
  66895. GradientEdgeTableRenderer <DestPixelType, TransformedRadialGradientPixelGenerator> renderer (destData, g, transform, lookupTable, numLookupEntries);
  66896. et.iterate (renderer);
  66897. }
  66898. }
  66899. else
  66900. {
  66901. GradientEdgeTableRenderer <DestPixelType, LinearGradientPixelGenerator> renderer (destData, g, transform, lookupTable, numLookupEntries);
  66902. et.iterate (renderer);
  66903. }
  66904. }
  66905. template <class DestPixelType>
  66906. void renderSolidFill (EdgeTable& et, const Image::BitmapData& destData, const PixelARGB& fillColour, const bool replaceContents, DestPixelType*) throw()
  66907. {
  66908. jassert (destData.pixelStride == sizeof (DestPixelType));
  66909. if (replaceContents)
  66910. {
  66911. SolidColourEdgeTableRenderer <DestPixelType, true> r (destData, fillColour);
  66912. et.iterate (r);
  66913. }
  66914. else
  66915. {
  66916. SolidColourEdgeTableRenderer <DestPixelType, false> r (destData, fillColour);
  66917. et.iterate (r);
  66918. }
  66919. }
  66920. void transformedRenderImage (const Image& srcImage, Image& destImage, const EdgeTable& et, const Image::BitmapData& destData, const Image::BitmapData& srcData,
  66921. const int alpha, const AffineTransform& transform, const bool betterQuality, const bool repeatPattern) throw()
  66922. {
  66923. switch (destImage.getFormat())
  66924. {
  66925. case Image::ARGB:
  66926. switch (srcImage.getFormat())
  66927. {
  66928. case Image::ARGB:
  66929. if (repeatPattern) { TransformedImageFillEdgeTableRenderer <PixelARGB, PixelARGB, true> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66930. else { TransformedImageFillEdgeTableRenderer <PixelARGB, PixelARGB, false> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66931. break;
  66932. case Image::RGB:
  66933. if (repeatPattern) { TransformedImageFillEdgeTableRenderer <PixelARGB, PixelRGB, true> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66934. else { TransformedImageFillEdgeTableRenderer <PixelARGB, PixelRGB, false> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66935. break;
  66936. default:
  66937. if (repeatPattern) { TransformedImageFillEdgeTableRenderer <PixelARGB, PixelAlpha, true> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66938. else { TransformedImageFillEdgeTableRenderer <PixelARGB, PixelAlpha, false> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66939. break;
  66940. }
  66941. break;
  66942. case Image::RGB:
  66943. switch (srcImage.getFormat())
  66944. {
  66945. case Image::ARGB:
  66946. if (repeatPattern) { TransformedImageFillEdgeTableRenderer <PixelRGB, PixelARGB, true> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66947. else { TransformedImageFillEdgeTableRenderer <PixelRGB, PixelARGB, false> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66948. break;
  66949. case Image::RGB:
  66950. if (repeatPattern) { TransformedImageFillEdgeTableRenderer <PixelRGB, PixelRGB, true> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66951. else { TransformedImageFillEdgeTableRenderer <PixelRGB, PixelRGB, false> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66952. break;
  66953. default:
  66954. if (repeatPattern) { TransformedImageFillEdgeTableRenderer <PixelRGB, PixelAlpha, true> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66955. else { TransformedImageFillEdgeTableRenderer <PixelRGB, PixelAlpha, false> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66956. break;
  66957. }
  66958. break;
  66959. default:
  66960. switch (srcImage.getFormat())
  66961. {
  66962. case Image::ARGB:
  66963. if (repeatPattern) { TransformedImageFillEdgeTableRenderer <PixelAlpha, PixelARGB, true> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66964. else { TransformedImageFillEdgeTableRenderer <PixelAlpha, PixelARGB, false> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66965. break;
  66966. case Image::RGB:
  66967. if (repeatPattern) { TransformedImageFillEdgeTableRenderer <PixelAlpha, PixelRGB, true> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66968. else { TransformedImageFillEdgeTableRenderer <PixelAlpha, PixelRGB, false> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66969. break;
  66970. default:
  66971. if (repeatPattern) { TransformedImageFillEdgeTableRenderer <PixelAlpha, PixelAlpha, true> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66972. else { TransformedImageFillEdgeTableRenderer <PixelAlpha, PixelAlpha, false> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66973. break;
  66974. }
  66975. break;
  66976. }
  66977. }
  66978. void blittedRenderImage (const Image& srcImage, Image& destImage, const EdgeTable& et, const Image::BitmapData& destData,
  66979. const Image::BitmapData& srcData, const int alpha, int x, int y, const bool repeatPattern) throw()
  66980. {
  66981. switch (destImage.getFormat())
  66982. {
  66983. case Image::ARGB:
  66984. switch (srcImage.getFormat())
  66985. {
  66986. case Image::ARGB:
  66987. if (repeatPattern) { ImageFillEdgeTableRenderer <PixelARGB, PixelARGB, true> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66988. else { ImageFillEdgeTableRenderer <PixelARGB, PixelARGB, false> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66989. break;
  66990. case Image::RGB:
  66991. if (repeatPattern) { ImageFillEdgeTableRenderer <PixelARGB, PixelRGB, true> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66992. else { ImageFillEdgeTableRenderer <PixelARGB, PixelRGB, false> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66993. break;
  66994. default:
  66995. if (repeatPattern) { ImageFillEdgeTableRenderer <PixelARGB, PixelAlpha, true> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66996. else { ImageFillEdgeTableRenderer <PixelARGB, PixelAlpha, false> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66997. break;
  66998. }
  66999. break;
  67000. case Image::RGB:
  67001. switch (srcImage.getFormat())
  67002. {
  67003. case Image::ARGB:
  67004. if (repeatPattern) { ImageFillEdgeTableRenderer <PixelRGB, PixelARGB, true> r (destData, srcData, alpha, x, y); et.iterate (r); }
  67005. else { ImageFillEdgeTableRenderer <PixelRGB, PixelARGB, false> r (destData, srcData, alpha, x, y); et.iterate (r); }
  67006. break;
  67007. case Image::RGB:
  67008. if (repeatPattern) { ImageFillEdgeTableRenderer <PixelRGB, PixelRGB, true> r (destData, srcData, alpha, x, y); et.iterate (r); }
  67009. else { ImageFillEdgeTableRenderer <PixelRGB, PixelRGB, false> r (destData, srcData, alpha, x, y); et.iterate (r); }
  67010. break;
  67011. default:
  67012. if (repeatPattern) { ImageFillEdgeTableRenderer <PixelRGB, PixelAlpha, true> r (destData, srcData, alpha, x, y); et.iterate (r); }
  67013. else { ImageFillEdgeTableRenderer <PixelRGB, PixelAlpha, false> r (destData, srcData, alpha, x, y); et.iterate (r); }
  67014. break;
  67015. }
  67016. break;
  67017. default:
  67018. switch (srcImage.getFormat())
  67019. {
  67020. case Image::ARGB:
  67021. if (repeatPattern) { ImageFillEdgeTableRenderer <PixelAlpha, PixelARGB, true> r (destData, srcData, alpha, x, y); et.iterate (r); }
  67022. else { ImageFillEdgeTableRenderer <PixelAlpha, PixelARGB, false> r (destData, srcData, alpha, x, y); et.iterate (r); }
  67023. break;
  67024. case Image::RGB:
  67025. if (repeatPattern) { ImageFillEdgeTableRenderer <PixelAlpha, PixelRGB, true> r (destData, srcData, alpha, x, y); et.iterate (r); }
  67026. else { ImageFillEdgeTableRenderer <PixelAlpha, PixelRGB, false> r (destData, srcData, alpha, x, y); et.iterate (r); }
  67027. break;
  67028. default:
  67029. if (repeatPattern) { ImageFillEdgeTableRenderer <PixelAlpha, PixelAlpha, true> r (destData, srcData, alpha, x, y); et.iterate (r); }
  67030. else { ImageFillEdgeTableRenderer <PixelAlpha, PixelAlpha, false> r (destData, srcData, alpha, x, y); et.iterate (r); }
  67031. break;
  67032. }
  67033. break;
  67034. }
  67035. }
  67036. };
  67037. LowLevelGraphicsSoftwareRenderer::LowLevelGraphicsSoftwareRenderer (Image& image_)
  67038. : image (image_)
  67039. {
  67040. currentState = new LLGCSavedState (image_.getBounds(), 0, 0, Font(),
  67041. FillType(), Graphics::mediumResamplingQuality);
  67042. }
  67043. LowLevelGraphicsSoftwareRenderer::~LowLevelGraphicsSoftwareRenderer()
  67044. {
  67045. }
  67046. bool LowLevelGraphicsSoftwareRenderer::isVectorDevice() const
  67047. {
  67048. return false;
  67049. }
  67050. void LowLevelGraphicsSoftwareRenderer::setOrigin (int x, int y)
  67051. {
  67052. currentState->xOffset += x;
  67053. currentState->yOffset += y;
  67054. }
  67055. bool LowLevelGraphicsSoftwareRenderer::clipToRectangle (const Rectangle& r)
  67056. {
  67057. return currentState->clipToRectangle (r);
  67058. }
  67059. bool LowLevelGraphicsSoftwareRenderer::clipToRectangleList (const RectangleList& clipRegion)
  67060. {
  67061. return currentState->clipToRectangleList (clipRegion);
  67062. }
  67063. void LowLevelGraphicsSoftwareRenderer::excludeClipRectangle (const Rectangle& r)
  67064. {
  67065. currentState->excludeClipRectangle (r);
  67066. }
  67067. void LowLevelGraphicsSoftwareRenderer::clipToPath (const Path& path, const AffineTransform& transform)
  67068. {
  67069. currentState->clipToPath (path, transform);
  67070. }
  67071. void LowLevelGraphicsSoftwareRenderer::clipToImageAlpha (const Image& sourceImage, const Rectangle& srcClip, const AffineTransform& transform)
  67072. {
  67073. currentState->clipToImageAlpha (sourceImage, srcClip, transform);
  67074. }
  67075. bool LowLevelGraphicsSoftwareRenderer::clipRegionIntersects (const Rectangle& r)
  67076. {
  67077. return currentState->edgeTable->edgeTable.getMaximumBounds()
  67078. .intersects (r.translated (currentState->xOffset, currentState->yOffset));
  67079. }
  67080. const Rectangle LowLevelGraphicsSoftwareRenderer::getClipBounds() const
  67081. {
  67082. return currentState->edgeTable->edgeTable.getMaximumBounds().translated (-currentState->xOffset, -currentState->yOffset);
  67083. }
  67084. bool LowLevelGraphicsSoftwareRenderer::isClipEmpty() const
  67085. {
  67086. return currentState->edgeTable->edgeTable.isEmpty();
  67087. }
  67088. void LowLevelGraphicsSoftwareRenderer::saveState()
  67089. {
  67090. stateStack.add (new LLGCSavedState (*currentState));
  67091. }
  67092. void LowLevelGraphicsSoftwareRenderer::restoreState()
  67093. {
  67094. LLGCSavedState* const top = stateStack.getLast();
  67095. if (top != 0)
  67096. {
  67097. currentState = top;
  67098. stateStack.removeLast (1, false);
  67099. }
  67100. else
  67101. {
  67102. jassertfalse // trying to pop with an empty stack!
  67103. }
  67104. }
  67105. void LowLevelGraphicsSoftwareRenderer::setFill (const FillType& fillType)
  67106. {
  67107. currentState->fillType = fillType;
  67108. }
  67109. void LowLevelGraphicsSoftwareRenderer::setOpacity (float newOpacity)
  67110. {
  67111. currentState->fillType.setOpacity (newOpacity);
  67112. }
  67113. void LowLevelGraphicsSoftwareRenderer::setInterpolationQuality (Graphics::ResamplingQuality quality)
  67114. {
  67115. currentState->interpolationQuality = quality;
  67116. }
  67117. void LowLevelGraphicsSoftwareRenderer::fillRect (const Rectangle& r, const bool replaceExistingContents)
  67118. {
  67119. const Rectangle& totalClip = currentState->edgeTable->edgeTable.getMaximumBounds();
  67120. const Rectangle clipped (totalClip.getIntersection (r.translated (currentState->xOffset, currentState->yOffset)));
  67121. if (! clipped.isEmpty())
  67122. {
  67123. EdgeTable et (clipped);
  67124. currentState->fillEdgeTable (image, et, replaceExistingContents);
  67125. }
  67126. }
  67127. void LowLevelGraphicsSoftwareRenderer::fillPath (const Path& path, const AffineTransform& transform)
  67128. {
  67129. EdgeTable et (currentState->edgeTable->edgeTable.getMaximumBounds(),
  67130. path, transform.translated ((float) currentState->xOffset,
  67131. (float) currentState->yOffset));
  67132. currentState->fillEdgeTable (image, et);
  67133. }
  67134. void LowLevelGraphicsSoftwareRenderer::drawImage (const Image& sourceImage, const Rectangle& srcClip,
  67135. const AffineTransform& transform, const bool fillEntireClipAsTiles)
  67136. {
  67137. jassert (sourceImage.getBounds().contains (srcClip));
  67138. currentState->renderImage (image, sourceImage, srcClip, transform,
  67139. fillEntireClipAsTiles ? &(currentState->edgeTable->edgeTable) : 0);
  67140. }
  67141. void LowLevelGraphicsSoftwareRenderer::drawLine (double x1, double y1, double x2, double y2)
  67142. {
  67143. Path p;
  67144. p.addLineSegment ((float) x1, (float) y1, (float) x2, (float) y2, 1.0f);
  67145. fillPath (p, AffineTransform::identity);
  67146. }
  67147. void LowLevelGraphicsSoftwareRenderer::drawVerticalLine (const int x, double top, double bottom)
  67148. {
  67149. if (bottom > top)
  67150. {
  67151. EdgeTable et ((float) (x + currentState->xOffset), (float) (top + currentState->yOffset), 1.0f, (float) (bottom - top));
  67152. currentState->fillEdgeTable (image, et);
  67153. }
  67154. }
  67155. void LowLevelGraphicsSoftwareRenderer::drawHorizontalLine (const int y, double left, double right)
  67156. {
  67157. if (right > left)
  67158. {
  67159. EdgeTable et ((float) (left + currentState->xOffset), (float) (y + currentState->yOffset),
  67160. (float) (right - left), 1.0f);
  67161. currentState->fillEdgeTable (image, et);
  67162. }
  67163. }
  67164. class GlyphCache : private DeletedAtShutdown
  67165. {
  67166. public:
  67167. GlyphCache() throw()
  67168. : accessCounter (0), hits (0), misses (0)
  67169. {
  67170. for (int i = 120; --i >= 0;)
  67171. glyphs.add (new CachedGlyph());
  67172. }
  67173. ~GlyphCache() throw()
  67174. {
  67175. clearSingletonInstance();
  67176. }
  67177. juce_DeclareSingleton_SingleThreaded_Minimal (GlyphCache);
  67178. void drawGlyph (LLGCSavedState& state, Image& image, const Font& font, const int glyphNumber, float x, float y) throw()
  67179. {
  67180. ++accessCounter;
  67181. int oldestCounter = INT_MAX;
  67182. CachedGlyph* oldest = 0;
  67183. for (int i = glyphs.size(); --i >= 0;)
  67184. {
  67185. CachedGlyph* const glyph = glyphs.getUnchecked (i);
  67186. if (glyph->glyph == glyphNumber && glyph->font == font)
  67187. {
  67188. ++hits;
  67189. glyph->lastAccessCount = accessCounter;
  67190. glyph->draw (state, image, x, y);
  67191. return;
  67192. }
  67193. if (glyph->lastAccessCount <= oldestCounter)
  67194. {
  67195. oldestCounter = glyph->lastAccessCount;
  67196. oldest = glyph;
  67197. }
  67198. }
  67199. if (hits + ++misses > (glyphs.size() << 4))
  67200. {
  67201. if (misses * 2 > hits)
  67202. {
  67203. for (int i = 32; --i >= 0;)
  67204. glyphs.add (new CachedGlyph());
  67205. }
  67206. hits = misses = 0;
  67207. oldest = glyphs.getLast();
  67208. }
  67209. jassert (oldest != 0);
  67210. oldest->lastAccessCount = accessCounter;
  67211. oldest->generate (font, glyphNumber);
  67212. oldest->draw (state, image, x, y);
  67213. }
  67214. class CachedGlyph
  67215. {
  67216. public:
  67217. CachedGlyph() : glyph (0), lastAccessCount (0) {}
  67218. ~CachedGlyph() {}
  67219. void draw (LLGCSavedState& state, Image& image, const float x, const float y) const throw()
  67220. {
  67221. if (edgeTable != 0)
  67222. {
  67223. EdgeTable et (*edgeTable);
  67224. et.translate (x, roundToInt (y));
  67225. state.fillEdgeTable (image, et, false);
  67226. }
  67227. }
  67228. void generate (const Font& newFont, const int glyphNumber) throw()
  67229. {
  67230. font = newFont;
  67231. glyph = glyphNumber;
  67232. edgeTable = 0;
  67233. Path glyphPath;
  67234. font.getTypeface()->getOutlineForGlyph (glyphNumber, glyphPath);
  67235. if (! glyphPath.isEmpty())
  67236. {
  67237. const float fontHeight = font.getHeight();
  67238. const AffineTransform transform (AffineTransform::scale (fontHeight * font.getHorizontalScale(), fontHeight));
  67239. float px, py, pw, ph;
  67240. glyphPath.getBoundsTransformed (transform.translated (0.0f, -0.5f), px, py, pw, ph);
  67241. Rectangle clip ((int) floorf (px), (int) floorf (py),
  67242. roundToInt (pw) + 2, roundToInt (ph) + 2);
  67243. edgeTable = new EdgeTable (clip, glyphPath, transform);
  67244. }
  67245. }
  67246. int glyph, lastAccessCount;
  67247. Font font;
  67248. juce_UseDebuggingNewOperator
  67249. private:
  67250. ScopedPointer <EdgeTable> edgeTable;
  67251. CachedGlyph (const CachedGlyph&);
  67252. const CachedGlyph& operator= (const CachedGlyph&);
  67253. };
  67254. juce_UseDebuggingNewOperator
  67255. private:
  67256. OwnedArray <CachedGlyph> glyphs;
  67257. int accessCounter, hits, misses;
  67258. GlyphCache (const GlyphCache&);
  67259. const GlyphCache& operator= (const GlyphCache&);
  67260. };
  67261. juce_ImplementSingleton_SingleThreaded (GlyphCache);
  67262. void LowLevelGraphicsSoftwareRenderer::setFont (const Font& newFont)
  67263. {
  67264. currentState->font = newFont;
  67265. }
  67266. const Font LowLevelGraphicsSoftwareRenderer::getFont()
  67267. {
  67268. return currentState->font;
  67269. }
  67270. void LowLevelGraphicsSoftwareRenderer::drawGlyph (int glyphNumber, const AffineTransform& transform)
  67271. {
  67272. Font& f = currentState->font;
  67273. if (transform.isOnlyTranslation())
  67274. {
  67275. GlyphCache::getInstance()->drawGlyph (*currentState, image, f, glyphNumber,
  67276. transform.getTranslationX() + (float) currentState->xOffset,
  67277. transform.getTranslationY() + (float) currentState->yOffset);
  67278. }
  67279. else
  67280. {
  67281. Path p;
  67282. f.getTypeface()->getOutlineForGlyph (glyphNumber, p);
  67283. fillPath (p, AffineTransform::scale (f.getHeight() * f.getHorizontalScale(), f.getHeight()).followedBy (transform));
  67284. }
  67285. }
  67286. #if JUCE_MSVC
  67287. #pragma warning (pop)
  67288. #endif
  67289. END_JUCE_NAMESPACE
  67290. /********* End of inlined file: juce_LowLevelGraphicsSoftwareRenderer.cpp *********/
  67291. /********* Start of inlined file: juce_RectanglePlacement.cpp *********/
  67292. BEGIN_JUCE_NAMESPACE
  67293. RectanglePlacement::RectanglePlacement (const RectanglePlacement& other) throw()
  67294. : flags (other.flags)
  67295. {
  67296. }
  67297. const RectanglePlacement& RectanglePlacement::operator= (const RectanglePlacement& other) throw()
  67298. {
  67299. flags = other.flags;
  67300. return *this;
  67301. }
  67302. void RectanglePlacement::applyTo (double& x, double& y,
  67303. double& w, double& h,
  67304. const double dx, const double dy,
  67305. const double dw, const double dh) const throw()
  67306. {
  67307. if (w == 0 || h == 0)
  67308. return;
  67309. if ((flags & stretchToFit) != 0)
  67310. {
  67311. x = dx;
  67312. y = dy;
  67313. w = dw;
  67314. h = dh;
  67315. }
  67316. else
  67317. {
  67318. double scale = (flags & fillDestination) != 0 ? jmax (dw / w, dh / h)
  67319. : jmin (dw / w, dh / h);
  67320. if ((flags & onlyReduceInSize) != 0)
  67321. scale = jmin (scale, 1.0);
  67322. if ((flags & onlyIncreaseInSize) != 0)
  67323. scale = jmax (scale, 1.0);
  67324. w *= scale;
  67325. h *= scale;
  67326. if ((flags & xLeft) != 0)
  67327. x = dx;
  67328. else if ((flags & xRight) != 0)
  67329. x = dx + dw - w;
  67330. else
  67331. x = dx + (dw - w) * 0.5;
  67332. if ((flags & yTop) != 0)
  67333. y = dy;
  67334. else if ((flags & yBottom) != 0)
  67335. y = dy + dh - h;
  67336. else
  67337. y = dy + (dh - h) * 0.5;
  67338. }
  67339. }
  67340. const AffineTransform RectanglePlacement::getTransformToFit (float x, float y,
  67341. float w, float h,
  67342. const float dx, const float dy,
  67343. const float dw, const float dh) const throw()
  67344. {
  67345. if (w == 0 || h == 0)
  67346. return AffineTransform::identity;
  67347. const float scaleX = dw / w;
  67348. const float scaleY = dh / h;
  67349. if ((flags & stretchToFit) != 0)
  67350. return AffineTransform::translation (-x, -y)
  67351. .scaled (scaleX, scaleY)
  67352. .translated (dx, dy);
  67353. float scale = (flags & fillDestination) != 0 ? jmax (scaleX, scaleY)
  67354. : jmin (scaleX, scaleY);
  67355. if ((flags & onlyReduceInSize) != 0)
  67356. scale = jmin (scale, 1.0f);
  67357. if ((flags & onlyIncreaseInSize) != 0)
  67358. scale = jmax (scale, 1.0f);
  67359. w *= scale;
  67360. h *= scale;
  67361. float newX = dx;
  67362. if ((flags & xRight) != 0)
  67363. newX += dw - w; // right
  67364. else if ((flags & xLeft) == 0)
  67365. newX += (dw - w) / 2.0f; // centre
  67366. float newY = dy;
  67367. if ((flags & yBottom) != 0)
  67368. newY += dh - h; // bottom
  67369. else if ((flags & yTop) == 0)
  67370. newY += (dh - h) / 2.0f; // centre
  67371. return AffineTransform::translation (-x, -y)
  67372. .scaled (scale, scale)
  67373. .translated (newX, newY);
  67374. }
  67375. END_JUCE_NAMESPACE
  67376. /********* End of inlined file: juce_RectanglePlacement.cpp *********/
  67377. /********* Start of inlined file: juce_Drawable.cpp *********/
  67378. BEGIN_JUCE_NAMESPACE
  67379. Drawable::RenderingContext::RenderingContext (Graphics& g_,
  67380. const AffineTransform& transform_,
  67381. const float opacity_) throw()
  67382. : g (g_),
  67383. transform (transform_),
  67384. opacity (opacity_)
  67385. {
  67386. }
  67387. Drawable::Drawable()
  67388. {
  67389. }
  67390. Drawable::~Drawable()
  67391. {
  67392. }
  67393. void Drawable::draw (Graphics& g, const float opacity,
  67394. const AffineTransform& transform) const
  67395. {
  67396. render (RenderingContext (g, transform, opacity));
  67397. }
  67398. void Drawable::drawAt (Graphics& g, const float x, const float y, const float opacity) const
  67399. {
  67400. draw (g, opacity, AffineTransform::translation (x, y));
  67401. }
  67402. void Drawable::drawWithin (Graphics& g,
  67403. const int destX,
  67404. const int destY,
  67405. const int destW,
  67406. const int destH,
  67407. const RectanglePlacement& placement,
  67408. const float opacity) const
  67409. {
  67410. if (destW > 0 && destH > 0)
  67411. {
  67412. float x, y, w, h;
  67413. getBounds (x, y, w, h);
  67414. draw (g, opacity,
  67415. placement.getTransformToFit (x, y, w, h,
  67416. (float) destX, (float) destY,
  67417. (float) destW, (float) destH));
  67418. }
  67419. }
  67420. Drawable* Drawable::createFromImageData (const void* data, const size_t numBytes)
  67421. {
  67422. Drawable* result = 0;
  67423. Image* const image = ImageFileFormat::loadFrom (data, (int) numBytes);
  67424. if (image != 0)
  67425. {
  67426. DrawableImage* const di = new DrawableImage();
  67427. di->setImage (image, true);
  67428. result = di;
  67429. }
  67430. else
  67431. {
  67432. const String asString (String::createStringFromData (data, (int) numBytes));
  67433. XmlDocument doc (asString);
  67434. ScopedPointer <XmlElement> outer (doc.getDocumentElement (true));
  67435. if (outer != 0 && outer->hasTagName (T("svg")))
  67436. {
  67437. ScopedPointer <XmlElement> svg (doc.getDocumentElement());
  67438. if (svg != 0)
  67439. result = Drawable::createFromSVG (*svg);
  67440. }
  67441. }
  67442. return result;
  67443. }
  67444. Drawable* Drawable::createFromImageDataStream (InputStream& dataSource)
  67445. {
  67446. MemoryBlock mb;
  67447. dataSource.readIntoMemoryBlock (mb);
  67448. return createFromImageData (mb.getData(), mb.getSize());
  67449. }
  67450. Drawable* Drawable::createFromImageFile (const File& file)
  67451. {
  67452. const ScopedPointer <FileInputStream> fin (file.createInputStream());
  67453. return fin != 0 ? createFromImageDataStream (*fin) : 0;
  67454. }
  67455. Drawable* Drawable::createFromValueTree (const ValueTree& tree) throw()
  67456. {
  67457. Drawable* d = DrawablePath::createFromValueTree (tree);
  67458. if (d == 0)
  67459. {
  67460. d = DrawableComposite::createFromValueTree (tree);
  67461. if (d == 0)
  67462. {
  67463. d = DrawableImage::createFromValueTree (tree);
  67464. if (d == 0)
  67465. d = DrawableText::createFromValueTree (tree);
  67466. }
  67467. }
  67468. return d;
  67469. }
  67470. END_JUCE_NAMESPACE
  67471. /********* End of inlined file: juce_Drawable.cpp *********/
  67472. /********* Start of inlined file: juce_DrawableComposite.cpp *********/
  67473. BEGIN_JUCE_NAMESPACE
  67474. DrawableComposite::DrawableComposite()
  67475. {
  67476. }
  67477. DrawableComposite::~DrawableComposite()
  67478. {
  67479. }
  67480. void DrawableComposite::insertDrawable (Drawable* drawable,
  67481. const AffineTransform& transform,
  67482. const int index)
  67483. {
  67484. if (drawable != 0)
  67485. {
  67486. if (! drawables.contains (drawable))
  67487. {
  67488. drawables.insert (index, drawable);
  67489. if (transform.isIdentity())
  67490. transforms.insert (index, 0);
  67491. else
  67492. transforms.insert (index, new AffineTransform (transform));
  67493. }
  67494. else
  67495. {
  67496. jassertfalse // trying to add a drawable that's already in here!
  67497. }
  67498. }
  67499. }
  67500. void DrawableComposite::insertDrawable (const Drawable& drawable,
  67501. const AffineTransform& transform,
  67502. const int index)
  67503. {
  67504. insertDrawable (drawable.createCopy(), transform, index);
  67505. }
  67506. void DrawableComposite::removeDrawable (const int index, const bool deleteDrawable)
  67507. {
  67508. drawables.remove (index, deleteDrawable);
  67509. transforms.remove (index);
  67510. }
  67511. void DrawableComposite::bringToFront (const int index)
  67512. {
  67513. if (index >= 0 && index < drawables.size() - 1)
  67514. {
  67515. drawables.move (index, -1);
  67516. transforms.move (index, -1);
  67517. }
  67518. }
  67519. void DrawableComposite::render (const Drawable::RenderingContext& context) const
  67520. {
  67521. if (drawables.size() > 0 && context.opacity > 0)
  67522. {
  67523. if (context.opacity >= 1.0f || drawables.size() == 1)
  67524. {
  67525. Drawable::RenderingContext contextCopy (context);
  67526. for (int i = 0; i < drawables.size(); ++i)
  67527. {
  67528. const AffineTransform* const t = transforms.getUnchecked(i);
  67529. contextCopy.transform = (t == 0) ? context.transform
  67530. : t->followedBy (context.transform);
  67531. drawables.getUnchecked(i)->render (contextCopy);
  67532. }
  67533. }
  67534. else
  67535. {
  67536. // To correctly render a whole composite layer with an overall transparency,
  67537. // we need to render everything opaquely into a temp buffer, then blend that
  67538. // with the target opacity...
  67539. const Rectangle clipBounds (context.g.getClipBounds());
  67540. Image tempImage (Image::ARGB, clipBounds.getWidth(), clipBounds.getHeight(), true);
  67541. {
  67542. Graphics tempG (tempImage);
  67543. tempG.setOrigin (-clipBounds.getX(), -clipBounds.getY());
  67544. Drawable::RenderingContext tempContext (tempG, context.transform, 1.0f);
  67545. render (tempContext);
  67546. }
  67547. context.g.setOpacity (context.opacity);
  67548. context.g.drawImageAt (&tempImage, clipBounds.getX(), clipBounds.getY());
  67549. }
  67550. }
  67551. }
  67552. void DrawableComposite::getBounds (float& x, float& y, float& width, float& height) const
  67553. {
  67554. Path totalPath;
  67555. for (int i = 0; i < drawables.size(); ++i)
  67556. {
  67557. drawables.getUnchecked(i)->getBounds (x, y, width, height);
  67558. if (width > 0.0f && height > 0.0f)
  67559. {
  67560. Path outline;
  67561. outline.addRectangle (x, y, width, height);
  67562. const AffineTransform* const t = transforms.getUnchecked(i);
  67563. if (t == 0)
  67564. totalPath.addPath (outline);
  67565. else
  67566. totalPath.addPath (outline, *t);
  67567. }
  67568. }
  67569. totalPath.getBounds (x, y, width, height);
  67570. }
  67571. bool DrawableComposite::hitTest (float x, float y) const
  67572. {
  67573. for (int i = 0; i < drawables.size(); ++i)
  67574. {
  67575. float tx = x;
  67576. float ty = y;
  67577. const AffineTransform* const t = transforms.getUnchecked(i);
  67578. if (t != 0)
  67579. t->inverted().transformPoint (tx, ty);
  67580. if (drawables.getUnchecked(i)->hitTest (tx, ty))
  67581. return true;
  67582. }
  67583. return false;
  67584. }
  67585. Drawable* DrawableComposite::createCopy() const
  67586. {
  67587. DrawableComposite* const dc = new DrawableComposite();
  67588. for (int i = 0; i < drawables.size(); ++i)
  67589. {
  67590. dc->drawables.add (drawables.getUnchecked(i)->createCopy());
  67591. const AffineTransform* const t = transforms.getUnchecked(i);
  67592. dc->transforms.add (t != 0 ? new AffineTransform (*t) : 0);
  67593. }
  67594. return dc;
  67595. }
  67596. ValueTree DrawableComposite::createValueTree() const throw()
  67597. {
  67598. ValueTree v (T("Group"));
  67599. if (getName().isNotEmpty())
  67600. v.setProperty ("id", getName(), 0);
  67601. for (int i = 0; i < drawables.size(); ++i)
  67602. {
  67603. Drawable* const d = drawables.getUnchecked(i);
  67604. ValueTree child (d->createValueTree());
  67605. AffineTransform* transform = transforms.getUnchecked(i);
  67606. if (transform != 0)
  67607. {
  67608. String t;
  67609. t << transform->mat00 << " " << transform->mat01 << " " << transform->mat02 << " "
  67610. << transform->mat10 << " " << transform->mat11 << " " << transform->mat12;
  67611. child.setProperty ("transform", t, 0);
  67612. }
  67613. v.addChild (child, -1, 0);
  67614. }
  67615. return v;
  67616. }
  67617. DrawableComposite* DrawableComposite::createFromValueTree (const ValueTree& tree) throw()
  67618. {
  67619. if (! tree.hasType ("Group"))
  67620. return 0;
  67621. DrawableComposite* dc = new DrawableComposite();
  67622. dc->setName (tree ["id"]);
  67623. for (int i = 0; i < tree.getNumChildren(); ++i)
  67624. {
  67625. ValueTree childTree (tree.getChild (i));
  67626. Drawable* d = Drawable::createFromValueTree (childTree);
  67627. if (d != 0)
  67628. {
  67629. AffineTransform transform;
  67630. const String transformAtt (childTree ["transform"].toString());
  67631. if (transformAtt.isNotEmpty())
  67632. {
  67633. StringArray tokens;
  67634. tokens.addTokens (transformAtt.trim(), false);
  67635. tokens.removeEmptyStrings (true);
  67636. if (tokens.size() == 6)
  67637. {
  67638. float f[6];
  67639. for (int j = 0; j < 6; ++j)
  67640. f[j] = (float) tokens[j].getDoubleValue();
  67641. transform = AffineTransform (f[0], f[1], f[2], f[3], f[4], f[5]);
  67642. }
  67643. }
  67644. dc->insertDrawable (d, transform);
  67645. }
  67646. }
  67647. return dc;
  67648. }
  67649. END_JUCE_NAMESPACE
  67650. /********* End of inlined file: juce_DrawableComposite.cpp *********/
  67651. /********* Start of inlined file: juce_DrawableImage.cpp *********/
  67652. BEGIN_JUCE_NAMESPACE
  67653. DrawableImage::DrawableImage()
  67654. : image (0),
  67655. canDeleteImage (false),
  67656. opacity (1.0f),
  67657. overlayColour (0x00000000)
  67658. {
  67659. }
  67660. DrawableImage::~DrawableImage()
  67661. {
  67662. clearImage();
  67663. }
  67664. void DrawableImage::clearImage()
  67665. {
  67666. if (canDeleteImage && image != 0)
  67667. ImageCache::releaseOrDelete (image);
  67668. image = 0;
  67669. }
  67670. void DrawableImage::setImage (const Image& imageToCopy)
  67671. {
  67672. clearImage();
  67673. image = new Image (imageToCopy);
  67674. canDeleteImage = true;
  67675. }
  67676. void DrawableImage::setImage (Image* imageToUse,
  67677. const bool releaseWhenNotNeeded)
  67678. {
  67679. clearImage();
  67680. image = imageToUse;
  67681. canDeleteImage = releaseWhenNotNeeded;
  67682. }
  67683. void DrawableImage::setOpacity (const float newOpacity)
  67684. {
  67685. opacity = newOpacity;
  67686. }
  67687. void DrawableImage::setOverlayColour (const Colour& newOverlayColour)
  67688. {
  67689. overlayColour = newOverlayColour;
  67690. }
  67691. void DrawableImage::render (const Drawable::RenderingContext& context) const
  67692. {
  67693. if (image != 0)
  67694. {
  67695. if (opacity > 0.0f && ! overlayColour.isOpaque())
  67696. {
  67697. context.g.setOpacity (context.opacity * opacity);
  67698. context.g.drawImageTransformed (image, image->getBounds(),
  67699. context.transform, false);
  67700. }
  67701. if (! overlayColour.isTransparent())
  67702. {
  67703. context.g.setColour (overlayColour.withMultipliedAlpha (context.opacity));
  67704. context.g.drawImageTransformed (image, image->getBounds(),
  67705. context.transform, true);
  67706. }
  67707. }
  67708. }
  67709. void DrawableImage::getBounds (float& x, float& y, float& width, float& height) const
  67710. {
  67711. x = 0.0f;
  67712. y = 0.0f;
  67713. width = 0.0f;
  67714. height = 0.0f;
  67715. if (image != 0)
  67716. {
  67717. width = (float) image->getWidth();
  67718. height = (float) image->getHeight();
  67719. }
  67720. }
  67721. bool DrawableImage::hitTest (float x, float y) const
  67722. {
  67723. return image != 0
  67724. && x >= 0.0f
  67725. && y >= 0.0f
  67726. && x < image->getWidth()
  67727. && y < image->getHeight()
  67728. && image->getPixelAt (roundToInt (x), roundToInt (y)).getAlpha() >= 127;
  67729. }
  67730. Drawable* DrawableImage::createCopy() const
  67731. {
  67732. DrawableImage* const di = new DrawableImage();
  67733. di->opacity = opacity;
  67734. di->overlayColour = overlayColour;
  67735. if (image != 0)
  67736. {
  67737. if ((! canDeleteImage) || ! ImageCache::isImageInCache (image))
  67738. {
  67739. di->setImage (*image);
  67740. }
  67741. else
  67742. {
  67743. ImageCache::incReferenceCount (image);
  67744. di->setImage (image, true);
  67745. }
  67746. }
  67747. return di;
  67748. }
  67749. ValueTree DrawableImage::createValueTree() const throw()
  67750. {
  67751. ValueTree v (T("Image"));
  67752. if (getName().isNotEmpty())
  67753. v.setProperty ("id", getName(), 0);
  67754. if (opacity < 1.0f)
  67755. v.setProperty ("opacity", (double) opacity, 0);
  67756. if (! overlayColour.isTransparent())
  67757. v.setProperty ("overlay", String::toHexString ((int) overlayColour.getARGB()), 0);
  67758. if (image != 0)
  67759. {
  67760. MemoryOutputStream imageData;
  67761. PNGImageFormat pngFormat;
  67762. if (pngFormat.writeImageToStream (*image, imageData))
  67763. {
  67764. String base64 (MemoryBlock (imageData.getData(), imageData.getDataSize()).toBase64Encoding());
  67765. for (int i = (base64.length() & ~127); i >= 0; i -= 128)
  67766. base64 = base64.substring (0, i) + "\n" + base64.substring (i);
  67767. v.setProperty ("data", base64, 0);
  67768. }
  67769. }
  67770. return v;
  67771. }
  67772. DrawableImage* DrawableImage::createFromValueTree (const ValueTree& tree) throw()
  67773. {
  67774. if (! tree.hasType ("Image"))
  67775. return 0;
  67776. DrawableImage* di = new DrawableImage();
  67777. di->setName (tree ["id"]);
  67778. di->opacity = tree.hasProperty ("opacity") ? (float) tree ["opacity"] : 1.0f;
  67779. di->overlayColour = Colour (tree ["overlay"].toString().getHexValue32());
  67780. MemoryBlock imageData;
  67781. if (imageData.fromBase64Encoding (tree ["data"]))
  67782. {
  67783. Image* const im = ImageFileFormat::loadFrom (imageData.getData(), (int) imageData.getSize());
  67784. if (im == 0)
  67785. return false;
  67786. di->setImage (im, true);
  67787. }
  67788. return di;
  67789. }
  67790. END_JUCE_NAMESPACE
  67791. /********* End of inlined file: juce_DrawableImage.cpp *********/
  67792. /********* Start of inlined file: juce_DrawablePath.cpp *********/
  67793. BEGIN_JUCE_NAMESPACE
  67794. DrawablePath::DrawablePath()
  67795. : mainFill (FillType (Colours::black)),
  67796. strokeFill (FillType (Colours::transparentBlack)),
  67797. strokeType (0.0f)
  67798. {
  67799. }
  67800. DrawablePath::~DrawablePath()
  67801. {
  67802. }
  67803. void DrawablePath::setPath (const Path& newPath) throw()
  67804. {
  67805. path = newPath;
  67806. updateOutline();
  67807. }
  67808. void DrawablePath::setFill (const FillType& newFill) throw()
  67809. {
  67810. mainFill = newFill;
  67811. }
  67812. void DrawablePath::setStrokeFill (const FillType& newFill) throw()
  67813. {
  67814. strokeFill = newFill;
  67815. }
  67816. void DrawablePath::setStrokeType (const PathStrokeType& newStrokeType) throw()
  67817. {
  67818. strokeType = newStrokeType;
  67819. updateOutline();
  67820. }
  67821. void DrawablePath::setStrokeThickness (const float newThickness) throw()
  67822. {
  67823. setStrokeType (PathStrokeType (newThickness, strokeType.getJointStyle(), strokeType.getEndStyle()));
  67824. }
  67825. void DrawablePath::render (const Drawable::RenderingContext& context) const
  67826. {
  67827. {
  67828. FillType f (mainFill);
  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 (path, context.transform);
  67834. }
  67835. if (strokeType.getStrokeThickness() > 0.0f)
  67836. {
  67837. FillType f (strokeFill);
  67838. if (f.isGradient())
  67839. f.gradient->multiplyOpacity (context.opacity);
  67840. f.transform = f.transform.followedBy (context.transform);
  67841. context.g.setFillType (f);
  67842. context.g.fillPath (stroke, context.transform);
  67843. }
  67844. }
  67845. void DrawablePath::updateOutline()
  67846. {
  67847. stroke.clear();
  67848. strokeType.createStrokedPath (stroke, path, AffineTransform::identity, 4.0f);
  67849. }
  67850. void DrawablePath::getBounds (float& x, float& y, float& width, float& height) const
  67851. {
  67852. if (strokeType.getStrokeThickness() > 0.0f)
  67853. stroke.getBounds (x, y, width, height);
  67854. else
  67855. path.getBounds (x, y, width, height);
  67856. }
  67857. bool DrawablePath::hitTest (float x, float y) const
  67858. {
  67859. return path.contains (x, y)
  67860. || stroke.contains (x, y);
  67861. }
  67862. Drawable* DrawablePath::createCopy() const
  67863. {
  67864. DrawablePath* const dp = new DrawablePath();
  67865. dp->path = path;
  67866. dp->stroke = stroke;
  67867. dp->mainFill = mainFill;
  67868. dp->strokeFill = strokeFill;
  67869. dp->strokeType = strokeType;
  67870. return dp;
  67871. }
  67872. static const FillType readFillTypeFromTree (const ValueTree& v)
  67873. {
  67874. const String type (v["type"].toString());
  67875. if (type.equalsIgnoreCase (T("solid")))
  67876. {
  67877. const String colour (v ["colour"].toString());
  67878. return FillType (Colour (colour.isEmpty() ? (uint32) 0xff000000
  67879. : (uint32) colour.getHexValue32()));
  67880. }
  67881. else if (type.equalsIgnoreCase ("gradient"))
  67882. {
  67883. ColourGradient g;
  67884. g.x1 = v["x1"];
  67885. g.y1 = v["y1"];
  67886. g.x2 = v["x2"];
  67887. g.y2 = v["y2"];
  67888. g.isRadial = v["radial"];
  67889. StringArray colours;
  67890. colours.addTokens (v["colours"].toString(), false);
  67891. for (int i = 0; i < colours.size() / 2; ++i)
  67892. g.addColour (colours[i * 2].getDoubleValue(),
  67893. Colour ((uint32) colours[i * 2 + 1].getHexValue32()));
  67894. return FillType (g);
  67895. }
  67896. jassertfalse
  67897. return FillType();
  67898. }
  67899. static ValueTree createTreeForFillType (const String& tagName, const FillType& fillType)
  67900. {
  67901. ValueTree v (tagName);
  67902. if (fillType.isColour())
  67903. {
  67904. v.setProperty ("type", T("solid"), 0);
  67905. v.setProperty ("colour", String::toHexString ((int) fillType.colour.getARGB()), 0);
  67906. }
  67907. else if (fillType.isGradient())
  67908. {
  67909. v.setProperty ("type", T("gradient"), 0);
  67910. v.setProperty ("x1", fillType.gradient->x1, 0);
  67911. v.setProperty ("y1", fillType.gradient->y1, 0);
  67912. v.setProperty ("x2", fillType.gradient->x2, 0);
  67913. v.setProperty ("y2", fillType.gradient->y2, 0);
  67914. v.setProperty ("radial", fillType.gradient->isRadial, 0);
  67915. String s;
  67916. for (int i = 0; i < fillType.gradient->getNumColours(); ++i)
  67917. s << " " << fillType.gradient->getColourPosition (i)
  67918. << " " << String::toHexString ((int) fillType.gradient->getColour(i).getARGB());
  67919. v.setProperty ("colours", s.trimStart(), 0);
  67920. }
  67921. else
  67922. {
  67923. jassertfalse //xxx
  67924. }
  67925. return v;
  67926. }
  67927. ValueTree DrawablePath::createValueTree() const throw()
  67928. {
  67929. ValueTree v (T("Path"));
  67930. v.addChild (createTreeForFillType (T("fill"), mainFill), -1, 0);
  67931. v.addChild (createTreeForFillType (T("stroke"), strokeFill), -1, 0);
  67932. if (getName().isNotEmpty())
  67933. v.setProperty ("id", getName(), 0);
  67934. v.setProperty ("strokeWidth", (double) strokeType.getStrokeThickness(), 0);
  67935. v.setProperty ("jointStyle", strokeType.getJointStyle() == PathStrokeType::mitered
  67936. ? T("miter") : (strokeType.getJointStyle() == PathStrokeType::curved ? T("curved") : T("bevel")), 0);
  67937. v.setProperty ("capStyle", strokeType.getEndStyle() == PathStrokeType::butt
  67938. ? T("butt") : (strokeType.getEndStyle() == PathStrokeType::square ? T("square") : T("round")), 0);
  67939. v.setProperty ("path", path.toString(), 0);
  67940. return v;
  67941. }
  67942. DrawablePath* DrawablePath::createFromValueTree (const ValueTree& tree) throw()
  67943. {
  67944. if (! tree.hasType ("Path"))
  67945. return 0;
  67946. DrawablePath* p = new DrawablePath();
  67947. p->setName (tree ["id"]);
  67948. p->mainFill = readFillTypeFromTree (tree.getChildWithName (T("fill")));
  67949. p->strokeFill = readFillTypeFromTree (tree.getChildWithName (T("stroke")));
  67950. const String jointStyle (tree ["jointStyle"].toString());
  67951. const String endStyle (tree ["capStyle"].toString());
  67952. p->strokeType
  67953. = PathStrokeType (tree ["strokeWidth"],
  67954. jointStyle.equalsIgnoreCase (T("curved")) ? PathStrokeType::curved
  67955. : (jointStyle.equalsIgnoreCase (T("bevel")) ? PathStrokeType::beveled
  67956. : PathStrokeType::mitered),
  67957. endStyle.equalsIgnoreCase (T("square")) ? PathStrokeType::square
  67958. : (endStyle.equalsIgnoreCase (T("round")) ? PathStrokeType::rounded
  67959. : PathStrokeType::butt));
  67960. p->path.clear();
  67961. p->path.restoreFromString (tree ["path"]);
  67962. p->updateOutline();
  67963. return p;
  67964. }
  67965. END_JUCE_NAMESPACE
  67966. /********* End of inlined file: juce_DrawablePath.cpp *********/
  67967. /********* Start of inlined file: juce_DrawableText.cpp *********/
  67968. BEGIN_JUCE_NAMESPACE
  67969. DrawableText::DrawableText()
  67970. : colour (Colours::white)
  67971. {
  67972. }
  67973. DrawableText::~DrawableText()
  67974. {
  67975. }
  67976. void DrawableText::setText (const GlyphArrangement& newText)
  67977. {
  67978. text = newText;
  67979. }
  67980. void DrawableText::setText (const String& newText, const Font& fontToUse)
  67981. {
  67982. text.clear();
  67983. text.addLineOfText (fontToUse, newText, 0.0f, 0.0f);
  67984. }
  67985. void DrawableText::setColour (const Colour& newColour)
  67986. {
  67987. colour = newColour;
  67988. }
  67989. void DrawableText::render (const Drawable::RenderingContext& context) const
  67990. {
  67991. context.g.setColour (colour.withMultipliedAlpha (context.opacity));
  67992. text.draw (context.g, context.transform);
  67993. }
  67994. void DrawableText::getBounds (float& x, float& y, float& width, float& height) const
  67995. {
  67996. text.getBoundingBox (0, -1, x, y, width, height, false); // (really returns top, left, bottom, right)
  67997. width -= x;
  67998. height -= y;
  67999. }
  68000. bool DrawableText::hitTest (float x, float y) const
  68001. {
  68002. return text.findGlyphIndexAt (x, y) >= 0;
  68003. }
  68004. Drawable* DrawableText::createCopy() const
  68005. {
  68006. DrawableText* const dt = new DrawableText();
  68007. dt->text = text;
  68008. dt->colour = colour;
  68009. return dt;
  68010. }
  68011. ValueTree DrawableText::createValueTree() const throw()
  68012. {
  68013. ValueTree v (T("Text"));
  68014. if (getName().isNotEmpty())
  68015. v.setProperty ("id", getName(), 0);
  68016. jassertfalse // xxx not finished!
  68017. return v;
  68018. }
  68019. DrawableText* DrawableText::createFromValueTree (const ValueTree& tree) throw()
  68020. {
  68021. if (! tree.hasType ("Text"))
  68022. return 0;
  68023. DrawableText* dt = new DrawableText();
  68024. dt->setName (tree ["id"]);
  68025. jassertfalse // xxx not finished!
  68026. return dt;
  68027. }
  68028. END_JUCE_NAMESPACE
  68029. /********* End of inlined file: juce_DrawableText.cpp *********/
  68030. /********* Start of inlined file: juce_SVGParser.cpp *********/
  68031. BEGIN_JUCE_NAMESPACE
  68032. class SVGState
  68033. {
  68034. public:
  68035. SVGState (const XmlElement* const topLevel)
  68036. : topLevelXml (topLevel),
  68037. elementX (0), elementY (0),
  68038. width (512), height (512),
  68039. viewBoxW (0), viewBoxH (0)
  68040. {
  68041. }
  68042. ~SVGState()
  68043. {
  68044. }
  68045. Drawable* parseSVGElement (const XmlElement& xml)
  68046. {
  68047. if (! xml.hasTagName (T("svg")))
  68048. return 0;
  68049. DrawableComposite* const drawable = new DrawableComposite();
  68050. drawable->setName (xml.getStringAttribute (T("id")));
  68051. SVGState newState (*this);
  68052. if (xml.hasAttribute (T("transform")))
  68053. newState.addTransform (xml);
  68054. newState.elementX = getCoordLength (xml.getStringAttribute (T("x"), String (newState.elementX)), viewBoxW);
  68055. newState.elementY = getCoordLength (xml.getStringAttribute (T("y"), String (newState.elementY)), viewBoxH);
  68056. newState.width = getCoordLength (xml.getStringAttribute (T("width"), String (newState.width)), viewBoxW);
  68057. newState.height = getCoordLength (xml.getStringAttribute (T("height"), String (newState.height)), viewBoxH);
  68058. if (xml.hasAttribute (T("viewBox")))
  68059. {
  68060. const String viewParams (xml.getStringAttribute (T("viewBox")));
  68061. int i = 0;
  68062. float vx, vy, vw, vh;
  68063. if (parseCoords (viewParams, vx, vy, i, true)
  68064. && parseCoords (viewParams, vw, vh, i, true)
  68065. && vw > 0
  68066. && vh > 0)
  68067. {
  68068. newState.viewBoxW = vw;
  68069. newState.viewBoxH = vh;
  68070. int placementFlags = 0;
  68071. const String aspect (xml.getStringAttribute (T("preserveAspectRatio")));
  68072. if (aspect.containsIgnoreCase (T("none")))
  68073. {
  68074. placementFlags = RectanglePlacement::stretchToFit;
  68075. }
  68076. else
  68077. {
  68078. if (aspect.containsIgnoreCase (T("slice")))
  68079. placementFlags |= RectanglePlacement::fillDestination;
  68080. if (aspect.containsIgnoreCase (T("xMin")))
  68081. placementFlags |= RectanglePlacement::xLeft;
  68082. else if (aspect.containsIgnoreCase (T("xMax")))
  68083. placementFlags |= RectanglePlacement::xRight;
  68084. else
  68085. placementFlags |= RectanglePlacement::xMid;
  68086. if (aspect.containsIgnoreCase (T("yMin")))
  68087. placementFlags |= RectanglePlacement::yTop;
  68088. else if (aspect.containsIgnoreCase (T("yMax")))
  68089. placementFlags |= RectanglePlacement::yBottom;
  68090. else
  68091. placementFlags |= RectanglePlacement::yMid;
  68092. }
  68093. const RectanglePlacement placement (placementFlags);
  68094. newState.transform
  68095. = placement.getTransformToFit (vx, vy, vw, vh,
  68096. 0.0f, 0.0f, newState.width, newState.height)
  68097. .followedBy (newState.transform);
  68098. }
  68099. }
  68100. else
  68101. {
  68102. if (viewBoxW == 0)
  68103. newState.viewBoxW = newState.width;
  68104. if (viewBoxH == 0)
  68105. newState.viewBoxH = newState.height;
  68106. }
  68107. newState.parseSubElements (xml, drawable);
  68108. return drawable;
  68109. }
  68110. private:
  68111. const XmlElement* const topLevelXml;
  68112. float elementX, elementY, width, height, viewBoxW, viewBoxH;
  68113. AffineTransform transform;
  68114. String cssStyleText;
  68115. void parseSubElements (const XmlElement& xml, DrawableComposite* const parentDrawable)
  68116. {
  68117. forEachXmlChildElement (xml, e)
  68118. {
  68119. Drawable* d = 0;
  68120. if (e->hasTagName (T("g")))
  68121. d = parseGroupElement (*e);
  68122. else if (e->hasTagName (T("svg")))
  68123. d = parseSVGElement (*e);
  68124. else if (e->hasTagName (T("path")))
  68125. d = parsePath (*e);
  68126. else if (e->hasTagName (T("rect")))
  68127. d = parseRect (*e);
  68128. else if (e->hasTagName (T("circle")))
  68129. d = parseCircle (*e);
  68130. else if (e->hasTagName (T("ellipse")))
  68131. d = parseEllipse (*e);
  68132. else if (e->hasTagName (T("line")))
  68133. d = parseLine (*e);
  68134. else if (e->hasTagName (T("polyline")))
  68135. d = parsePolygon (*e, true);
  68136. else if (e->hasTagName (T("polygon")))
  68137. d = parsePolygon (*e, false);
  68138. else if (e->hasTagName (T("text")))
  68139. d = parseText (*e);
  68140. else if (e->hasTagName (T("switch")))
  68141. d = parseSwitch (*e);
  68142. else if (e->hasTagName (T("style")))
  68143. parseCSSStyle (*e);
  68144. parentDrawable->insertDrawable (d);
  68145. }
  68146. }
  68147. DrawableComposite* parseSwitch (const XmlElement& xml)
  68148. {
  68149. const XmlElement* const group = xml.getChildByName (T("g"));
  68150. if (group != 0)
  68151. return parseGroupElement (*group);
  68152. return 0;
  68153. }
  68154. DrawableComposite* parseGroupElement (const XmlElement& xml)
  68155. {
  68156. DrawableComposite* const drawable = new DrawableComposite();
  68157. drawable->setName (xml.getStringAttribute (T("id")));
  68158. if (xml.hasAttribute (T("transform")))
  68159. {
  68160. SVGState newState (*this);
  68161. newState.addTransform (xml);
  68162. newState.parseSubElements (xml, drawable);
  68163. }
  68164. else
  68165. {
  68166. parseSubElements (xml, drawable);
  68167. }
  68168. return drawable;
  68169. }
  68170. Drawable* parsePath (const XmlElement& xml) const
  68171. {
  68172. const String d (xml.getStringAttribute (T("d")).trimStart());
  68173. Path path;
  68174. if (getStyleAttribute (&xml, T("fill-rule")).trim().equalsIgnoreCase (T("evenodd")))
  68175. path.setUsingNonZeroWinding (false);
  68176. int index = 0;
  68177. float lastX = 0, lastY = 0;
  68178. float lastX2 = 0, lastY2 = 0;
  68179. tchar lastCommandChar = 0;
  68180. bool carryOn = true;
  68181. const String validCommandChars (T("MmLlHhVvCcSsQqTtAaZz"));
  68182. for (;;)
  68183. {
  68184. float x, y, x2, y2, x3, y3;
  68185. const bool isRelative = (d[index] >= 'a' && d[index] <= 'z');
  68186. if (validCommandChars.containsChar (d[index]))
  68187. lastCommandChar = d [index++];
  68188. switch (lastCommandChar)
  68189. {
  68190. case T('M'):
  68191. case T('m'):
  68192. case T('L'):
  68193. case T('l'):
  68194. if (parseCoords (d, x, y, index, false))
  68195. {
  68196. if (isRelative)
  68197. {
  68198. x += lastX;
  68199. y += lastY;
  68200. }
  68201. if (lastCommandChar == T('M') || lastCommandChar == T('m'))
  68202. path.startNewSubPath (x, y);
  68203. else
  68204. path.lineTo (x, y);
  68205. lastX2 = lastX;
  68206. lastY2 = lastY;
  68207. lastX = x;
  68208. lastY = y;
  68209. }
  68210. else
  68211. {
  68212. ++index;
  68213. }
  68214. break;
  68215. case T('H'):
  68216. case T('h'):
  68217. if (parseCoord (d, x, index, false, true))
  68218. {
  68219. if (isRelative)
  68220. x += lastX;
  68221. path.lineTo (x, lastY);
  68222. lastX2 = lastX;
  68223. lastX = x;
  68224. }
  68225. else
  68226. {
  68227. ++index;
  68228. }
  68229. break;
  68230. case T('V'):
  68231. case T('v'):
  68232. if (parseCoord (d, y, index, false, false))
  68233. {
  68234. if (isRelative)
  68235. y += lastY;
  68236. path.lineTo (lastX, y);
  68237. lastY2 = lastY;
  68238. lastY = y;
  68239. }
  68240. else
  68241. {
  68242. ++index;
  68243. }
  68244. break;
  68245. case T('C'):
  68246. case T('c'):
  68247. if (parseCoords (d, x, y, index, false)
  68248. && parseCoords (d, x2, y2, index, false)
  68249. && parseCoords (d, x3, y3, index, false))
  68250. {
  68251. if (isRelative)
  68252. {
  68253. x += lastX;
  68254. y += lastY;
  68255. x2 += lastX;
  68256. y2 += lastY;
  68257. x3 += lastX;
  68258. y3 += lastY;
  68259. }
  68260. path.cubicTo (x, y, x2, y2, x3, y3);
  68261. lastX2 = x2;
  68262. lastY2 = y2;
  68263. lastX = x3;
  68264. lastY = y3;
  68265. }
  68266. else
  68267. {
  68268. ++index;
  68269. }
  68270. break;
  68271. case T('S'):
  68272. case T('s'):
  68273. if (parseCoords (d, x, y, index, false)
  68274. && parseCoords (d, x3, y3, index, false))
  68275. {
  68276. if (isRelative)
  68277. {
  68278. x += lastX;
  68279. y += lastY;
  68280. x3 += lastX;
  68281. y3 += lastY;
  68282. }
  68283. x2 = lastX + (lastX - lastX2);
  68284. y2 = lastY + (lastY - lastY2);
  68285. path.cubicTo (x2, y2, x, y, x3, y3);
  68286. lastX2 = x;
  68287. lastY2 = y;
  68288. lastX = x3;
  68289. lastY = y3;
  68290. }
  68291. else
  68292. {
  68293. ++index;
  68294. }
  68295. break;
  68296. case T('Q'):
  68297. case T('q'):
  68298. if (parseCoords (d, x, y, index, false)
  68299. && parseCoords (d, x2, y2, index, false))
  68300. {
  68301. if (isRelative)
  68302. {
  68303. x += lastX;
  68304. y += lastY;
  68305. x2 += lastX;
  68306. y2 += lastY;
  68307. }
  68308. path.quadraticTo (x, y, x2, y2);
  68309. lastX2 = x;
  68310. lastY2 = y;
  68311. lastX = x2;
  68312. lastY = y2;
  68313. }
  68314. else
  68315. {
  68316. ++index;
  68317. }
  68318. break;
  68319. case T('T'):
  68320. case T('t'):
  68321. if (parseCoords (d, x, y, index, false))
  68322. {
  68323. if (isRelative)
  68324. {
  68325. x += lastX;
  68326. y += lastY;
  68327. }
  68328. x2 = lastX + (lastX - lastX2);
  68329. y2 = lastY + (lastY - lastY2);
  68330. path.quadraticTo (x2, y2, x, y);
  68331. lastX2 = x2;
  68332. lastY2 = y2;
  68333. lastX = x;
  68334. lastY = y;
  68335. }
  68336. else
  68337. {
  68338. ++index;
  68339. }
  68340. break;
  68341. case T('A'):
  68342. case T('a'):
  68343. if (parseCoords (d, x, y, index, false))
  68344. {
  68345. String num;
  68346. if (parseNextNumber (d, num, index, false))
  68347. {
  68348. const float angle = num.getFloatValue() * (180.0f / float_Pi);
  68349. if (parseNextNumber (d, num, index, false))
  68350. {
  68351. const bool largeArc = num.getIntValue() != 0;
  68352. if (parseNextNumber (d, num, index, false))
  68353. {
  68354. const bool sweep = num.getIntValue() != 0;
  68355. if (parseCoords (d, x2, y2, index, false))
  68356. {
  68357. if (isRelative)
  68358. {
  68359. x2 += lastX;
  68360. y2 += lastY;
  68361. }
  68362. if (lastX != x2 || lastY != y2)
  68363. {
  68364. double centreX, centreY, startAngle, deltaAngle;
  68365. double rx = x, ry = y;
  68366. endpointToCentreParameters (lastX, lastY, x2, y2,
  68367. angle, largeArc, sweep,
  68368. rx, ry, centreX, centreY,
  68369. startAngle, deltaAngle);
  68370. path.addCentredArc ((float) centreX, (float) centreY,
  68371. (float) rx, (float) ry,
  68372. angle, (float) startAngle, (float) (startAngle + deltaAngle),
  68373. false);
  68374. path.lineTo (x2, y2);
  68375. }
  68376. lastX2 = lastX;
  68377. lastY2 = lastY;
  68378. lastX = x2;
  68379. lastY = y2;
  68380. }
  68381. }
  68382. }
  68383. }
  68384. }
  68385. else
  68386. {
  68387. ++index;
  68388. }
  68389. break;
  68390. case T('Z'):
  68391. case T('z'):
  68392. path.closeSubPath();
  68393. while (CharacterFunctions::isWhitespace (d [index]))
  68394. ++index;
  68395. break;
  68396. default:
  68397. carryOn = false;
  68398. break;
  68399. }
  68400. if (! carryOn)
  68401. break;
  68402. }
  68403. return parseShape (xml, path);
  68404. }
  68405. Drawable* parseRect (const XmlElement& xml) const
  68406. {
  68407. Path rect;
  68408. const bool hasRX = xml.hasAttribute (T("rx"));
  68409. const bool hasRY = xml.hasAttribute (T("ry"));
  68410. if (hasRX || hasRY)
  68411. {
  68412. float rx = getCoordLength (xml.getStringAttribute (T("rx")), viewBoxW);
  68413. float ry = getCoordLength (xml.getStringAttribute (T("ry")), viewBoxH);
  68414. if (! hasRX)
  68415. rx = ry;
  68416. else if (! hasRY)
  68417. ry = rx;
  68418. rect.addRoundedRectangle (getCoordLength (xml.getStringAttribute (T("x")), viewBoxW),
  68419. getCoordLength (xml.getStringAttribute (T("y")), viewBoxH),
  68420. getCoordLength (xml.getStringAttribute (T("width")), viewBoxW),
  68421. getCoordLength (xml.getStringAttribute (T("height")), viewBoxH),
  68422. rx, ry);
  68423. }
  68424. else
  68425. {
  68426. rect.addRectangle (getCoordLength (xml.getStringAttribute (T("x")), viewBoxW),
  68427. getCoordLength (xml.getStringAttribute (T("y")), viewBoxH),
  68428. getCoordLength (xml.getStringAttribute (T("width")), viewBoxW),
  68429. getCoordLength (xml.getStringAttribute (T("height")), viewBoxH));
  68430. }
  68431. return parseShape (xml, rect);
  68432. }
  68433. Drawable* parseCircle (const XmlElement& xml) const
  68434. {
  68435. Path circle;
  68436. const float cx = getCoordLength (xml.getStringAttribute (T("cx")), viewBoxW);
  68437. const float cy = getCoordLength (xml.getStringAttribute (T("cy")), viewBoxH);
  68438. const float radius = getCoordLength (xml.getStringAttribute (T("r")), viewBoxW);
  68439. circle.addEllipse (cx - radius, cy - radius, radius * 2.0f, radius * 2.0f);
  68440. return parseShape (xml, circle);
  68441. }
  68442. Drawable* parseEllipse (const XmlElement& xml) const
  68443. {
  68444. Path ellipse;
  68445. const float cx = getCoordLength (xml.getStringAttribute (T("cx")), viewBoxW);
  68446. const float cy = getCoordLength (xml.getStringAttribute (T("cy")), viewBoxH);
  68447. const float radiusX = getCoordLength (xml.getStringAttribute (T("rx")), viewBoxW);
  68448. const float radiusY = getCoordLength (xml.getStringAttribute (T("ry")), viewBoxH);
  68449. ellipse.addEllipse (cx - radiusX, cy - radiusY, radiusX * 2.0f, radiusY * 2.0f);
  68450. return parseShape (xml, ellipse);
  68451. }
  68452. Drawable* parseLine (const XmlElement& xml) const
  68453. {
  68454. Path line;
  68455. const float x1 = getCoordLength (xml.getStringAttribute (T("x1")), viewBoxW);
  68456. const float y1 = getCoordLength (xml.getStringAttribute (T("y1")), viewBoxH);
  68457. const float x2 = getCoordLength (xml.getStringAttribute (T("x2")), viewBoxW);
  68458. const float y2 = getCoordLength (xml.getStringAttribute (T("y2")), viewBoxH);
  68459. line.startNewSubPath (x1, y1);
  68460. line.lineTo (x2, y2);
  68461. return parseShape (xml, line);
  68462. }
  68463. Drawable* parsePolygon (const XmlElement& xml, const bool isPolyline) const
  68464. {
  68465. const String points (xml.getStringAttribute (T("points")));
  68466. Path path;
  68467. int index = 0;
  68468. float x, y;
  68469. if (parseCoords (points, x, y, index, true))
  68470. {
  68471. float firstX = x;
  68472. float firstY = y;
  68473. float lastX = 0, lastY = 0;
  68474. path.startNewSubPath (x, y);
  68475. while (parseCoords (points, x, y, index, true))
  68476. {
  68477. lastX = x;
  68478. lastY = y;
  68479. path.lineTo (x, y);
  68480. }
  68481. if ((! isPolyline) || (firstX == lastX && firstY == lastY))
  68482. path.closeSubPath();
  68483. }
  68484. return parseShape (xml, path);
  68485. }
  68486. Drawable* parseShape (const XmlElement& xml, Path& path,
  68487. const bool shouldParseTransform = true) const
  68488. {
  68489. if (shouldParseTransform && xml.hasAttribute (T("transform")))
  68490. {
  68491. SVGState newState (*this);
  68492. newState.addTransform (xml);
  68493. return newState.parseShape (xml, path, false);
  68494. }
  68495. DrawablePath* dp = new DrawablePath();
  68496. dp->setName (xml.getStringAttribute (T("id")));
  68497. dp->setFill (FillType (Colours::transparentBlack));
  68498. path.applyTransform (transform);
  68499. dp->setPath (path);
  68500. Path::Iterator iter (path);
  68501. bool containsClosedSubPath = false;
  68502. while (iter.next())
  68503. {
  68504. if (iter.elementType == Path::Iterator::closePath)
  68505. {
  68506. containsClosedSubPath = true;
  68507. break;
  68508. }
  68509. }
  68510. dp->setFill (getPathFillType (path,
  68511. getStyleAttribute (&xml, T("fill")),
  68512. getStyleAttribute (&xml, T("fill-opacity")),
  68513. getStyleAttribute (&xml, T("opacity")),
  68514. containsClosedSubPath ? Colours::black
  68515. : Colours::transparentBlack));
  68516. const String strokeType (getStyleAttribute (&xml, T("stroke")));
  68517. if (strokeType.isNotEmpty() && ! strokeType.equalsIgnoreCase (T("none")))
  68518. {
  68519. dp->setStrokeFill (getPathFillType (path, strokeType,
  68520. getStyleAttribute (&xml, T("stroke-opacity")),
  68521. getStyleAttribute (&xml, T("opacity")),
  68522. Colours::transparentBlack));
  68523. dp->setStrokeType (getStrokeFor (&xml));
  68524. }
  68525. return dp;
  68526. }
  68527. const XmlElement* findLinkedElement (const XmlElement* e) const
  68528. {
  68529. const String id (e->getStringAttribute (T("xlink:href")));
  68530. if (! id.startsWithChar (T('#')))
  68531. return 0;
  68532. return findElementForId (topLevelXml, id.substring (1));
  68533. }
  68534. void addGradientStopsIn (ColourGradient& cg, const XmlElement* const fillXml) const
  68535. {
  68536. if (fillXml == 0)
  68537. return;
  68538. forEachXmlChildElementWithTagName (*fillXml, e, T("stop"))
  68539. {
  68540. int index = 0;
  68541. Colour col (parseColour (getStyleAttribute (e, T("stop-color")), index, Colours::black));
  68542. const String opacity (getStyleAttribute (e, T("stop-opacity"), T("1")));
  68543. col = col.withMultipliedAlpha (jlimit (0.0f, 1.0f, opacity.getFloatValue()));
  68544. double offset = e->getDoubleAttribute (T("offset"));
  68545. if (e->getStringAttribute (T("offset")).containsChar (T('%')))
  68546. offset *= 0.01;
  68547. cg.addColour (jlimit (0.0, 1.0, offset), col);
  68548. }
  68549. }
  68550. const FillType getPathFillType (const Path& path,
  68551. const String& fill,
  68552. const String& fillOpacity,
  68553. const String& overallOpacity,
  68554. const Colour& defaultColour) const
  68555. {
  68556. float opacity = 1.0f;
  68557. if (overallOpacity.isNotEmpty())
  68558. opacity = jlimit (0.0f, 1.0f, overallOpacity.getFloatValue());
  68559. if (fillOpacity.isNotEmpty())
  68560. opacity *= (jlimit (0.0f, 1.0f, fillOpacity.getFloatValue()));
  68561. if (fill.startsWithIgnoreCase (T("url")))
  68562. {
  68563. const String id (fill.fromFirstOccurrenceOf (T("#"), false, false)
  68564. .upToLastOccurrenceOf (T(")"), false, false).trim());
  68565. const XmlElement* const fillXml = findElementForId (topLevelXml, id);
  68566. if (fillXml != 0
  68567. && (fillXml->hasTagName (T("linearGradient"))
  68568. || fillXml->hasTagName (T("radialGradient"))))
  68569. {
  68570. const XmlElement* inheritedFrom = findLinkedElement (fillXml);
  68571. ColourGradient gradient;
  68572. addGradientStopsIn (gradient, inheritedFrom);
  68573. addGradientStopsIn (gradient, fillXml);
  68574. if (gradient.getNumColours() > 0)
  68575. {
  68576. gradient.addColour (0.0, gradient.getColour (0));
  68577. gradient.addColour (1.0, gradient.getColour (gradient.getNumColours() - 1));
  68578. }
  68579. else
  68580. {
  68581. gradient.addColour (0.0, Colours::black);
  68582. gradient.addColour (1.0, Colours::black);
  68583. }
  68584. if (overallOpacity.isNotEmpty())
  68585. gradient.multiplyOpacity (overallOpacity.getFloatValue());
  68586. jassert (gradient.getNumColours() > 0);
  68587. gradient.isRadial = fillXml->hasTagName (T("radialGradient"));
  68588. float width = viewBoxW;
  68589. float height = viewBoxH;
  68590. float dx = 0.0f;
  68591. float dy = 0.0f;
  68592. const bool userSpace = fillXml->getStringAttribute (T("gradientUnits")).equalsIgnoreCase (T("userSpaceOnUse"));
  68593. if (! userSpace)
  68594. path.getBounds (dx, dy, width, height);
  68595. if (gradient.isRadial)
  68596. {
  68597. gradient.x1 = dx + getCoordLength (fillXml->getStringAttribute (T("cx"), T("50%")), width);
  68598. gradient.y1 = dy + getCoordLength (fillXml->getStringAttribute (T("cy"), T("50%")), height);
  68599. const float radius = getCoordLength (fillXml->getStringAttribute (T("r"), T("50%")), width);
  68600. gradient.x2 = gradient.x1 + radius;
  68601. gradient.y2 = gradient.y1;
  68602. //xxx (the fx, fy focal point isn't handled properly here..)
  68603. }
  68604. else
  68605. {
  68606. gradient.x1 = dx + getCoordLength (fillXml->getStringAttribute (T("x1"), T("0%")), width);
  68607. gradient.y1 = dy + getCoordLength (fillXml->getStringAttribute (T("y1"), T("0%")), height);
  68608. gradient.x2 = dx + getCoordLength (fillXml->getStringAttribute (T("x2"), T("100%")), width);
  68609. gradient.y2 = dy + getCoordLength (fillXml->getStringAttribute (T("y2"), T("0%")), height);
  68610. if (gradient.x1 == gradient.x2 && gradient.y1 == gradient.y2)
  68611. return Colour (gradient.getColour (gradient.getNumColours() - 1));
  68612. }
  68613. FillType type (gradient);
  68614. type.transform = parseTransform (fillXml->getStringAttribute (T("gradientTransform")))
  68615. .followedBy (transform);
  68616. return type;
  68617. }
  68618. }
  68619. if (fill.equalsIgnoreCase (T("none")))
  68620. return Colours::transparentBlack;
  68621. int i = 0;
  68622. const Colour colour (parseColour (fill, i, defaultColour));
  68623. return colour.withMultipliedAlpha (opacity);
  68624. }
  68625. const PathStrokeType getStrokeFor (const XmlElement* const xml) const
  68626. {
  68627. const String width (getStyleAttribute (xml, T("stroke-width")));
  68628. const String cap (getStyleAttribute (xml, T("stroke-linecap")));
  68629. const String join (getStyleAttribute (xml, T("stroke-linejoin")));
  68630. //const String mitreLimit (getStyleAttribute (xml, T("stroke-miterlimit")));
  68631. //const String dashArray (getStyleAttribute (xml, T("stroke-dasharray")));
  68632. //const String dashOffset (getStyleAttribute (xml, T("stroke-dashoffset")));
  68633. PathStrokeType::JointStyle joinStyle = PathStrokeType::mitered;
  68634. PathStrokeType::EndCapStyle capStyle = PathStrokeType::butt;
  68635. if (join.equalsIgnoreCase (T("round")))
  68636. joinStyle = PathStrokeType::curved;
  68637. else if (join.equalsIgnoreCase (T("bevel")))
  68638. joinStyle = PathStrokeType::beveled;
  68639. if (cap.equalsIgnoreCase (T("round")))
  68640. capStyle = PathStrokeType::rounded;
  68641. else if (cap.equalsIgnoreCase (T("square")))
  68642. capStyle = PathStrokeType::square;
  68643. float ox = 0.0f, oy = 0.0f;
  68644. transform.transformPoint (ox, oy);
  68645. float x = getCoordLength (width, viewBoxW), y = 0.0f;
  68646. transform.transformPoint (x, y);
  68647. return PathStrokeType (width.isNotEmpty() ? juce_hypotf (x - ox, y - oy) : 1.0f,
  68648. joinStyle, capStyle);
  68649. }
  68650. Drawable* parseText (const XmlElement& xml)
  68651. {
  68652. Array <float> xCoords, yCoords, dxCoords, dyCoords;
  68653. getCoordList (xCoords, getInheritedAttribute (&xml, T("x")), true, true);
  68654. getCoordList (yCoords, getInheritedAttribute (&xml, T("y")), true, false);
  68655. getCoordList (dxCoords, getInheritedAttribute (&xml, T("dx")), true, true);
  68656. getCoordList (dyCoords, getInheritedAttribute (&xml, T("dy")), true, false);
  68657. //xxx not done text yet!
  68658. forEachXmlChildElement (xml, e)
  68659. {
  68660. if (e->isTextElement())
  68661. {
  68662. const String text (e->getText());
  68663. Path path;
  68664. Drawable* s = parseShape (*e, path);
  68665. delete s;
  68666. }
  68667. else if (e->hasTagName (T("tspan")))
  68668. {
  68669. Drawable* s = parseText (*e);
  68670. delete s;
  68671. }
  68672. }
  68673. return 0;
  68674. }
  68675. void addTransform (const XmlElement& xml)
  68676. {
  68677. transform = parseTransform (xml.getStringAttribute (T("transform")))
  68678. .followedBy (transform);
  68679. }
  68680. bool parseCoord (const String& s, float& value, int& index,
  68681. const bool allowUnits, const bool isX) const
  68682. {
  68683. String number;
  68684. if (! parseNextNumber (s, number, index, allowUnits))
  68685. {
  68686. value = 0;
  68687. return false;
  68688. }
  68689. value = getCoordLength (number, isX ? viewBoxW : viewBoxH);
  68690. return true;
  68691. }
  68692. bool parseCoords (const String& s, float& x, float& y,
  68693. int& index, const bool allowUnits) const
  68694. {
  68695. return parseCoord (s, x, index, allowUnits, true)
  68696. && parseCoord (s, y, index, allowUnits, false);
  68697. }
  68698. float getCoordLength (const String& s, const float sizeForProportions) const
  68699. {
  68700. float n = s.getFloatValue();
  68701. const int len = s.length();
  68702. if (len > 2)
  68703. {
  68704. const float dpi = 96.0f;
  68705. const tchar n1 = s [len - 2];
  68706. const tchar n2 = s [len - 1];
  68707. if (n1 == T('i') && n2 == T('n'))
  68708. n *= dpi;
  68709. else if (n1 == T('m') && n2 == T('m'))
  68710. n *= dpi / 25.4f;
  68711. else if (n1 == T('c') && n2 == T('m'))
  68712. n *= dpi / 2.54f;
  68713. else if (n1 == T('p') && n2 == T('c'))
  68714. n *= 15.0f;
  68715. else if (n2 == T('%'))
  68716. n *= 0.01f * sizeForProportions;
  68717. }
  68718. return n;
  68719. }
  68720. void getCoordList (Array <float>& coords, const String& list,
  68721. const bool allowUnits, const bool isX) const
  68722. {
  68723. int index = 0;
  68724. float value;
  68725. while (parseCoord (list, value, index, allowUnits, isX))
  68726. coords.add (value);
  68727. }
  68728. void parseCSSStyle (const XmlElement& xml)
  68729. {
  68730. cssStyleText = xml.getAllSubText() + T("\n") + cssStyleText;
  68731. }
  68732. const String getStyleAttribute (const XmlElement* xml, const String& attributeName,
  68733. const String& defaultValue = String::empty) const
  68734. {
  68735. if (xml->hasAttribute (attributeName))
  68736. return xml->getStringAttribute (attributeName, defaultValue);
  68737. const String styleAtt (xml->getStringAttribute (T("style")));
  68738. if (styleAtt.isNotEmpty())
  68739. {
  68740. const String value (getAttributeFromStyleList (styleAtt, attributeName, String::empty));
  68741. if (value.isNotEmpty())
  68742. return value;
  68743. }
  68744. else if (xml->hasAttribute (T("class")))
  68745. {
  68746. const String className (T(".") + xml->getStringAttribute (T("class")));
  68747. int index = cssStyleText.indexOfIgnoreCase (className + T(" "));
  68748. if (index < 0)
  68749. index = cssStyleText.indexOfIgnoreCase (className + T("{"));
  68750. if (index >= 0)
  68751. {
  68752. const int openBracket = cssStyleText.indexOfChar (index, T('{'));
  68753. if (openBracket > index)
  68754. {
  68755. const int closeBracket = cssStyleText.indexOfChar (openBracket, T('}'));
  68756. if (closeBracket > openBracket)
  68757. {
  68758. const String value (getAttributeFromStyleList (cssStyleText.substring (openBracket + 1, closeBracket), attributeName, defaultValue));
  68759. if (value.isNotEmpty())
  68760. return value;
  68761. }
  68762. }
  68763. }
  68764. }
  68765. xml = const_cast <XmlElement*> (topLevelXml)->findParentElementOf (xml);
  68766. if (xml != 0)
  68767. return getStyleAttribute (xml, attributeName, defaultValue);
  68768. return defaultValue;
  68769. }
  68770. const String getInheritedAttribute (const XmlElement* xml, const String& attributeName) const
  68771. {
  68772. if (xml->hasAttribute (attributeName))
  68773. return xml->getStringAttribute (attributeName);
  68774. xml = const_cast <XmlElement*> (topLevelXml)->findParentElementOf (xml);
  68775. if (xml != 0)
  68776. return getInheritedAttribute (xml, attributeName);
  68777. return String::empty;
  68778. }
  68779. static bool isIdentifierChar (const tchar c)
  68780. {
  68781. return CharacterFunctions::isLetter (c) || c == T('-');
  68782. }
  68783. static const String getAttributeFromStyleList (const String& list, const String& attributeName, const String& defaultValue)
  68784. {
  68785. int i = 0;
  68786. for (;;)
  68787. {
  68788. i = list.indexOf (i, attributeName);
  68789. if (i < 0)
  68790. break;
  68791. if ((i == 0 || (i > 0 && ! isIdentifierChar (list [i - 1])))
  68792. && ! isIdentifierChar (list [i + attributeName.length()]))
  68793. {
  68794. i = list.indexOfChar (i, T(':'));
  68795. if (i < 0)
  68796. break;
  68797. int end = list.indexOfChar (i, T(';'));
  68798. if (end < 0)
  68799. end = 0x7ffff;
  68800. return list.substring (i + 1, end).trim();
  68801. }
  68802. ++i;
  68803. }
  68804. return defaultValue;
  68805. }
  68806. static bool parseNextNumber (const String& source, String& value, int& index, const bool allowUnits)
  68807. {
  68808. const tchar* const s = (const tchar*) source;
  68809. while (CharacterFunctions::isWhitespace (s[index]) || s[index] == T(','))
  68810. ++index;
  68811. int start = index;
  68812. if (CharacterFunctions::isDigit (s[index]) || s[index] == T('.') || s[index] == T('-'))
  68813. ++index;
  68814. while (CharacterFunctions::isDigit (s[index]) || s[index] == T('.'))
  68815. ++index;
  68816. if ((s[index] == T('e') || s[index] == T('E'))
  68817. && (CharacterFunctions::isDigit (s[index + 1])
  68818. || s[index + 1] == T('-')
  68819. || s[index + 1] == T('+')))
  68820. {
  68821. index += 2;
  68822. while (CharacterFunctions::isDigit (s[index]))
  68823. ++index;
  68824. }
  68825. if (allowUnits)
  68826. {
  68827. while (CharacterFunctions::isLetter (s[index]))
  68828. ++index;
  68829. }
  68830. if (index == start)
  68831. return false;
  68832. value = String (s + start, index - start);
  68833. while (CharacterFunctions::isWhitespace (s[index]) || s[index] == T(','))
  68834. ++index;
  68835. return true;
  68836. }
  68837. static const Colour parseColour (const String& s, int& index, const Colour& defaultColour)
  68838. {
  68839. if (s [index] == T('#'))
  68840. {
  68841. uint32 hex [6];
  68842. zeromem (hex, sizeof (hex));
  68843. int numChars = 0;
  68844. for (int i = 6; --i >= 0;)
  68845. {
  68846. const int hexValue = CharacterFunctions::getHexDigitValue (s [++index]);
  68847. if (hexValue >= 0)
  68848. hex [numChars++] = hexValue;
  68849. else
  68850. break;
  68851. }
  68852. if (numChars <= 3)
  68853. return Colour ((uint8) (hex [0] * 0x11),
  68854. (uint8) (hex [1] * 0x11),
  68855. (uint8) (hex [2] * 0x11));
  68856. else
  68857. return Colour ((uint8) ((hex [0] << 4) + hex [1]),
  68858. (uint8) ((hex [2] << 4) + hex [3]),
  68859. (uint8) ((hex [4] << 4) + hex [5]));
  68860. }
  68861. else if (s [index] == T('r')
  68862. && s [index + 1] == T('g')
  68863. && s [index + 2] == T('b'))
  68864. {
  68865. const int openBracket = s.indexOfChar (index, T('('));
  68866. const int closeBracket = s.indexOfChar (openBracket, T(')'));
  68867. if (openBracket >= 3 && closeBracket > openBracket)
  68868. {
  68869. index = closeBracket;
  68870. StringArray tokens;
  68871. tokens.addTokens (s.substring (openBracket + 1, closeBracket), T(","), T(""));
  68872. tokens.trim();
  68873. tokens.removeEmptyStrings();
  68874. if (tokens[0].containsChar (T('%')))
  68875. return Colour ((uint8) roundToInt (2.55 * tokens[0].getDoubleValue()),
  68876. (uint8) roundToInt (2.55 * tokens[1].getDoubleValue()),
  68877. (uint8) roundToInt (2.55 * tokens[2].getDoubleValue()));
  68878. else
  68879. return Colour ((uint8) tokens[0].getIntValue(),
  68880. (uint8) tokens[1].getIntValue(),
  68881. (uint8) tokens[2].getIntValue());
  68882. }
  68883. }
  68884. return Colours::findColourForName (s, defaultColour);
  68885. }
  68886. static const AffineTransform parseTransform (String t)
  68887. {
  68888. AffineTransform result;
  68889. while (t.isNotEmpty())
  68890. {
  68891. StringArray tokens;
  68892. tokens.addTokens (t.fromFirstOccurrenceOf (T("("), false, false)
  68893. .upToFirstOccurrenceOf (T(")"), false, false),
  68894. T(", "), 0);
  68895. tokens.removeEmptyStrings (true);
  68896. float numbers [6];
  68897. for (int i = 0; i < 6; ++i)
  68898. numbers[i] = tokens[i].getFloatValue();
  68899. AffineTransform trans;
  68900. if (t.startsWithIgnoreCase (T("matrix")))
  68901. {
  68902. trans = AffineTransform (numbers[0], numbers[2], numbers[4],
  68903. numbers[1], numbers[3], numbers[5]);
  68904. }
  68905. else if (t.startsWithIgnoreCase (T("translate")))
  68906. {
  68907. trans = trans.translated (numbers[0], numbers[1]);
  68908. }
  68909. else if (t.startsWithIgnoreCase (T("scale")))
  68910. {
  68911. if (tokens.size() == 1)
  68912. trans = trans.scaled (numbers[0], numbers[0]);
  68913. else
  68914. trans = trans.scaled (numbers[0], numbers[1]);
  68915. }
  68916. else if (t.startsWithIgnoreCase (T("rotate")))
  68917. {
  68918. if (tokens.size() != 3)
  68919. trans = trans.rotated (numbers[0] / (180.0f / float_Pi));
  68920. else
  68921. trans = trans.rotated (numbers[0] / (180.0f / float_Pi),
  68922. numbers[1], numbers[2]);
  68923. }
  68924. else if (t.startsWithIgnoreCase (T("skewX")))
  68925. {
  68926. trans = AffineTransform (1.0f, tanf (numbers[0] * (float_Pi / 180.0f)), 0.0f,
  68927. 0.0f, 1.0f, 0.0f);
  68928. }
  68929. else if (t.startsWithIgnoreCase (T("skewY")))
  68930. {
  68931. trans = AffineTransform (1.0f, 0.0f, 0.0f,
  68932. tanf (numbers[0] * (float_Pi / 180.0f)), 1.0f, 0.0f);
  68933. }
  68934. result = trans.followedBy (result);
  68935. t = t.fromFirstOccurrenceOf (T(")"), false, false).trimStart();
  68936. }
  68937. return result;
  68938. }
  68939. static void endpointToCentreParameters (const double x1, const double y1,
  68940. const double x2, const double y2,
  68941. const double angle,
  68942. const bool largeArc, const bool sweep,
  68943. double& rx, double& ry,
  68944. double& centreX, double& centreY,
  68945. double& startAngle, double& deltaAngle)
  68946. {
  68947. const double midX = (x1 - x2) * 0.5;
  68948. const double midY = (y1 - y2) * 0.5;
  68949. const double cosAngle = cos (angle);
  68950. const double sinAngle = sin (angle);
  68951. const double xp = cosAngle * midX + sinAngle * midY;
  68952. const double yp = cosAngle * midY - sinAngle * midX;
  68953. const double xp2 = xp * xp;
  68954. const double yp2 = yp * yp;
  68955. double rx2 = rx * rx;
  68956. double ry2 = ry * ry;
  68957. const double s = (xp2 / rx2) + (yp2 / ry2);
  68958. double c;
  68959. if (s <= 1.0)
  68960. {
  68961. c = sqrt (jmax (0.0, ((rx2 * ry2) - (rx2 * yp2) - (ry2 * xp2))
  68962. / (( rx2 * yp2) + (ry2 * xp2))));
  68963. if (largeArc == sweep)
  68964. c = -c;
  68965. }
  68966. else
  68967. {
  68968. const double s2 = sqrt (s);
  68969. rx *= s2;
  68970. ry *= s2;
  68971. rx2 = rx * rx;
  68972. ry2 = ry * ry;
  68973. c = 0;
  68974. }
  68975. const double cpx = ((rx * yp) / ry) * c;
  68976. const double cpy = ((-ry * xp) / rx) * c;
  68977. centreX = ((x1 + x2) * 0.5) + (cosAngle * cpx) - (sinAngle * cpy);
  68978. centreY = ((y1 + y2) * 0.5) + (sinAngle * cpx) + (cosAngle * cpy);
  68979. const double ux = (xp - cpx) / rx;
  68980. const double uy = (yp - cpy) / ry;
  68981. const double vx = (-xp - cpx) / rx;
  68982. const double vy = (-yp - cpy) / ry;
  68983. const double length = juce_hypot (ux, uy);
  68984. startAngle = acos (jlimit (-1.0, 1.0, ux / length));
  68985. if (uy < 0)
  68986. startAngle = -startAngle;
  68987. startAngle += double_Pi * 0.5;
  68988. deltaAngle = acos (jlimit (-1.0, 1.0, ((ux * vx) + (uy * vy))
  68989. / (length * juce_hypot (vx, vy))));
  68990. if ((ux * vy) - (uy * vx) < 0)
  68991. deltaAngle = -deltaAngle;
  68992. if (sweep)
  68993. {
  68994. if (deltaAngle < 0)
  68995. deltaAngle += double_Pi * 2.0;
  68996. }
  68997. else
  68998. {
  68999. if (deltaAngle > 0)
  69000. deltaAngle -= double_Pi * 2.0;
  69001. }
  69002. deltaAngle = fmod (deltaAngle, double_Pi * 2.0);
  69003. }
  69004. static const XmlElement* findElementForId (const XmlElement* const parent, const String& id)
  69005. {
  69006. forEachXmlChildElement (*parent, e)
  69007. {
  69008. if (e->compareAttribute (T("id"), id))
  69009. return e;
  69010. const XmlElement* const found = findElementForId (e, id);
  69011. if (found != 0)
  69012. return found;
  69013. }
  69014. return 0;
  69015. }
  69016. const SVGState& operator= (const SVGState&);
  69017. };
  69018. Drawable* Drawable::createFromSVG (const XmlElement& svgDocument)
  69019. {
  69020. SVGState state (&svgDocument);
  69021. return state.parseSVGElement (svgDocument);
  69022. }
  69023. END_JUCE_NAMESPACE
  69024. /********* End of inlined file: juce_SVGParser.cpp *********/
  69025. /********* Start of inlined file: juce_DropShadowEffect.cpp *********/
  69026. BEGIN_JUCE_NAMESPACE
  69027. #if JUCE_MSVC
  69028. #pragma optimize ("t", on) // try to avoid slowing everything down in debug builds
  69029. #endif
  69030. DropShadowEffect::DropShadowEffect()
  69031. : offsetX (0),
  69032. offsetY (0),
  69033. radius (4),
  69034. opacity (0.6f)
  69035. {
  69036. }
  69037. DropShadowEffect::~DropShadowEffect()
  69038. {
  69039. }
  69040. void DropShadowEffect::setShadowProperties (const float newRadius,
  69041. const float newOpacity,
  69042. const int newShadowOffsetX,
  69043. const int newShadowOffsetY)
  69044. {
  69045. radius = jmax (1.1f, newRadius);
  69046. offsetX = newShadowOffsetX;
  69047. offsetY = newShadowOffsetY;
  69048. opacity = newOpacity;
  69049. }
  69050. void DropShadowEffect::applyEffect (Image& image, Graphics& g)
  69051. {
  69052. const int w = image.getWidth();
  69053. const int h = image.getHeight();
  69054. Image shadowImage (Image::SingleChannel, w, h, false);
  69055. const Image::BitmapData srcData (image, 0, 0, w, h);
  69056. const Image::BitmapData destData (shadowImage, 0, 0, w, h, true);
  69057. const int filter = roundToInt (63.0f / radius);
  69058. const int radiusMinus1 = roundToInt ((radius - 1.0f) * 63.0f);
  69059. for (int x = w; --x >= 0;)
  69060. {
  69061. int shadowAlpha = 0;
  69062. const PixelARGB* src = ((const PixelARGB*) srcData.data) + x;
  69063. uint8* shadowPix = destData.data + x;
  69064. for (int y = h; --y >= 0;)
  69065. {
  69066. shadowAlpha = ((shadowAlpha * radiusMinus1 + (src->getAlpha() << 6)) * filter) >> 12;
  69067. *shadowPix = (uint8) shadowAlpha;
  69068. src = (const PixelARGB*) (((const uint8*) src) + srcData.lineStride);
  69069. shadowPix += destData.lineStride;
  69070. }
  69071. }
  69072. for (int y = h; --y >= 0;)
  69073. {
  69074. int shadowAlpha = 0;
  69075. uint8* shadowPix = destData.getLinePointer (y);
  69076. for (int x = w; --x >= 0;)
  69077. {
  69078. shadowAlpha = ((shadowAlpha * radiusMinus1 + (*shadowPix << 6)) * filter) >> 12;
  69079. *shadowPix++ = (uint8) shadowAlpha;
  69080. }
  69081. }
  69082. g.setColour (Colours::black.withAlpha (opacity));
  69083. g.drawImageAt (&shadowImage, offsetX, offsetY, true);
  69084. g.setOpacity (1.0f);
  69085. g.drawImageAt (&image, 0, 0);
  69086. }
  69087. END_JUCE_NAMESPACE
  69088. /********* End of inlined file: juce_DropShadowEffect.cpp *********/
  69089. /********* Start of inlined file: juce_GlowEffect.cpp *********/
  69090. BEGIN_JUCE_NAMESPACE
  69091. GlowEffect::GlowEffect()
  69092. : radius (2.0f),
  69093. colour (Colours::white)
  69094. {
  69095. }
  69096. GlowEffect::~GlowEffect()
  69097. {
  69098. }
  69099. void GlowEffect::setGlowProperties (const float newRadius,
  69100. const Colour& newColour)
  69101. {
  69102. radius = newRadius;
  69103. colour = newColour;
  69104. }
  69105. void GlowEffect::applyEffect (Image& image, Graphics& g)
  69106. {
  69107. const int w = image.getWidth();
  69108. const int h = image.getHeight();
  69109. Image temp (image.getFormat(), w, h, true);
  69110. ImageConvolutionKernel blurKernel (roundToInt (radius * 2.0f));
  69111. blurKernel.createGaussianBlur (radius);
  69112. blurKernel.rescaleAllValues (radius);
  69113. blurKernel.applyToImage (temp, &image, 0, 0, w, h);
  69114. g.setColour (colour);
  69115. g.drawImageAt (&temp, 0, 0, true);
  69116. g.setOpacity (1.0f);
  69117. g.drawImageAt (&image, 0, 0, false);
  69118. }
  69119. END_JUCE_NAMESPACE
  69120. /********* End of inlined file: juce_GlowEffect.cpp *********/
  69121. /********* Start of inlined file: juce_ReduceOpacityEffect.cpp *********/
  69122. BEGIN_JUCE_NAMESPACE
  69123. ReduceOpacityEffect::ReduceOpacityEffect (const float opacity_)
  69124. : opacity (opacity_)
  69125. {
  69126. }
  69127. ReduceOpacityEffect::~ReduceOpacityEffect()
  69128. {
  69129. }
  69130. void ReduceOpacityEffect::setOpacity (const float newOpacity)
  69131. {
  69132. opacity = jlimit (0.0f, 1.0f, newOpacity);
  69133. }
  69134. void ReduceOpacityEffect::applyEffect (Image& image, Graphics& g)
  69135. {
  69136. g.setOpacity (opacity);
  69137. g.drawImageAt (&image, 0, 0);
  69138. }
  69139. END_JUCE_NAMESPACE
  69140. /********* End of inlined file: juce_ReduceOpacityEffect.cpp *********/
  69141. /********* Start of inlined file: juce_Font.cpp *********/
  69142. BEGIN_JUCE_NAMESPACE
  69143. static const float minFontHeight = 0.1f;
  69144. static const float maxFontHeight = 10000.0f;
  69145. static const float defaultFontHeight = 14.0f;
  69146. static const tchar* const juce_defaultFontNameSans = T("<Sans-Serif>");
  69147. static const tchar* const juce_defaultFontNameSerif = T("<Serif>");
  69148. static const tchar* const juce_defaultFontNameMono = T("<Monospaced>");
  69149. void clearUpDefaultFontNames() throw(); // in juce_LookAndFeel.cpp
  69150. Font::SharedFontInternal::SharedFontInternal (const String& typefaceName_, const float height_, const float horizontalScale_,
  69151. const float kerning_, const float ascent_, const int styleFlags_,
  69152. Typeface* const typeface_) throw()
  69153. : typefaceName (typefaceName_),
  69154. height (height_),
  69155. horizontalScale (horizontalScale_),
  69156. kerning (kerning_),
  69157. ascent (ascent_),
  69158. styleFlags (styleFlags_),
  69159. typeface (typeface_)
  69160. {
  69161. }
  69162. Font::SharedFontInternal::SharedFontInternal (const SharedFontInternal& other) throw()
  69163. : typefaceName (other.typefaceName),
  69164. height (other.height),
  69165. horizontalScale (other.horizontalScale),
  69166. kerning (other.kerning),
  69167. ascent (other.ascent),
  69168. styleFlags (other.styleFlags),
  69169. typeface (other.typeface)
  69170. {
  69171. }
  69172. Font::Font() throw()
  69173. : font (new SharedFontInternal (juce_defaultFontNameSans, defaultFontHeight,
  69174. 1.0f, 0, 0, Font::plain, 0))
  69175. {
  69176. }
  69177. Font::Font (const float fontHeight, const int styleFlags_) throw()
  69178. : font (new SharedFontInternal (juce_defaultFontNameSans, jlimit (minFontHeight, maxFontHeight, fontHeight),
  69179. 1.0f, 0, 0, styleFlags_, 0))
  69180. {
  69181. }
  69182. Font::Font (const String& typefaceName_,
  69183. const float fontHeight,
  69184. const int styleFlags_) throw()
  69185. : font (new SharedFontInternal (typefaceName_, jlimit (minFontHeight, maxFontHeight, fontHeight),
  69186. 1.0f, 0, 0, styleFlags_, 0))
  69187. {
  69188. }
  69189. Font::Font (const Font& other) throw()
  69190. : font (other.font)
  69191. {
  69192. }
  69193. const Font& Font::operator= (const Font& other) throw()
  69194. {
  69195. font = other.font;
  69196. return *this;
  69197. }
  69198. Font::~Font() throw()
  69199. {
  69200. }
  69201. Font::Font (const Typeface::Ptr& typeface) throw()
  69202. : font (new SharedFontInternal (typeface->getName(), defaultFontHeight,
  69203. 1.0f, 0, 0, Font::plain, typeface))
  69204. {
  69205. }
  69206. bool Font::operator== (const Font& other) const throw()
  69207. {
  69208. return font == other.font
  69209. || (font->height == other.font->height
  69210. && font->styleFlags == other.font->styleFlags
  69211. && font->horizontalScale == other.font->horizontalScale
  69212. && font->kerning == other.font->kerning
  69213. && font->typefaceName == other.font->typefaceName);
  69214. }
  69215. bool Font::operator!= (const Font& other) const throw()
  69216. {
  69217. return ! operator== (other);
  69218. }
  69219. void Font::dupeInternalIfShared() throw()
  69220. {
  69221. if (font->getReferenceCount() > 1)
  69222. font = new SharedFontInternal (*font);
  69223. }
  69224. const String Font::getDefaultSansSerifFontName() throw()
  69225. {
  69226. return juce_defaultFontNameSans;
  69227. }
  69228. const String Font::getDefaultSerifFontName() throw()
  69229. {
  69230. return juce_defaultFontNameSerif;
  69231. }
  69232. const String Font::getDefaultMonospacedFontName() throw()
  69233. {
  69234. return juce_defaultFontNameMono;
  69235. }
  69236. void Font::setTypefaceName (const String& faceName) throw()
  69237. {
  69238. if (faceName != font->typefaceName)
  69239. {
  69240. dupeInternalIfShared();
  69241. font->typefaceName = faceName;
  69242. font->typeface = 0;
  69243. font->ascent = 0;
  69244. }
  69245. }
  69246. static String fallbackFont;
  69247. const String Font::getFallbackFontName() throw()
  69248. {
  69249. return fallbackFont;
  69250. }
  69251. void Font::setFallbackFontName (const String& name) throw()
  69252. {
  69253. fallbackFont = name;
  69254. }
  69255. void Font::setHeight (float newHeight) throw()
  69256. {
  69257. newHeight = jlimit (minFontHeight, maxFontHeight, newHeight);
  69258. if (font->height != newHeight)
  69259. {
  69260. dupeInternalIfShared();
  69261. font->height = newHeight;
  69262. }
  69263. }
  69264. void Font::setHeightWithoutChangingWidth (float newHeight) throw()
  69265. {
  69266. newHeight = jlimit (minFontHeight, maxFontHeight, newHeight);
  69267. if (font->height != newHeight)
  69268. {
  69269. dupeInternalIfShared();
  69270. font->horizontalScale *= (font->height / newHeight);
  69271. font->height = newHeight;
  69272. }
  69273. }
  69274. void Font::setStyleFlags (const int newFlags) throw()
  69275. {
  69276. if (font->styleFlags != newFlags)
  69277. {
  69278. dupeInternalIfShared();
  69279. font->styleFlags = newFlags;
  69280. font->typeface = 0;
  69281. font->ascent = 0;
  69282. }
  69283. }
  69284. void Font::setSizeAndStyle (float newHeight,
  69285. const int newStyleFlags,
  69286. const float newHorizontalScale,
  69287. const float newKerningAmount) throw()
  69288. {
  69289. newHeight = jlimit (minFontHeight, maxFontHeight, newHeight);
  69290. if (font->height != newHeight
  69291. || font->horizontalScale != newHorizontalScale
  69292. || font->kerning != newKerningAmount)
  69293. {
  69294. dupeInternalIfShared();
  69295. font->height = newHeight;
  69296. font->horizontalScale = newHorizontalScale;
  69297. font->kerning = newKerningAmount;
  69298. }
  69299. setStyleFlags (newStyleFlags);
  69300. }
  69301. void Font::setHorizontalScale (const float scaleFactor) throw()
  69302. {
  69303. dupeInternalIfShared();
  69304. font->horizontalScale = scaleFactor;
  69305. }
  69306. void Font::setExtraKerningFactor (const float extraKerning) throw()
  69307. {
  69308. dupeInternalIfShared();
  69309. font->kerning = extraKerning;
  69310. }
  69311. void Font::setBold (const bool shouldBeBold) throw()
  69312. {
  69313. setStyleFlags (shouldBeBold ? (font->styleFlags | bold)
  69314. : (font->styleFlags & ~bold));
  69315. }
  69316. bool Font::isBold() const throw()
  69317. {
  69318. return (font->styleFlags & bold) != 0;
  69319. }
  69320. void Font::setItalic (const bool shouldBeItalic) throw()
  69321. {
  69322. setStyleFlags (shouldBeItalic ? (font->styleFlags | italic)
  69323. : (font->styleFlags & ~italic));
  69324. }
  69325. bool Font::isItalic() const throw()
  69326. {
  69327. return (font->styleFlags & italic) != 0;
  69328. }
  69329. void Font::setUnderline (const bool shouldBeUnderlined) throw()
  69330. {
  69331. setStyleFlags (shouldBeUnderlined ? (font->styleFlags | underlined)
  69332. : (font->styleFlags & ~underlined));
  69333. }
  69334. bool Font::isUnderlined() const throw()
  69335. {
  69336. return (font->styleFlags & underlined) != 0;
  69337. }
  69338. float Font::getAscent() const throw()
  69339. {
  69340. if (font->ascent == 0)
  69341. font->ascent = getTypeface()->getAscent();
  69342. return font->height * font->ascent;
  69343. }
  69344. float Font::getDescent() const throw()
  69345. {
  69346. return font->height - getAscent();
  69347. }
  69348. int Font::getStringWidth (const String& text) const throw()
  69349. {
  69350. return roundToInt (getStringWidthFloat (text));
  69351. }
  69352. float Font::getStringWidthFloat (const String& text) const throw()
  69353. {
  69354. float w = getTypeface()->getStringWidth (text);
  69355. if (font->kerning != 0)
  69356. w += font->kerning * text.length();
  69357. return w * font->height * font->horizontalScale;
  69358. }
  69359. void Font::getGlyphPositions (const String& text, Array <int>& glyphs, Array <float>& xOffsets) const throw()
  69360. {
  69361. getTypeface()->getGlyphPositions (text, glyphs, xOffsets);
  69362. const float scale = font->height * font->horizontalScale;
  69363. const int num = xOffsets.size();
  69364. if (num > 0)
  69365. {
  69366. float* const x = &(xOffsets.getReference(0));
  69367. if (font->kerning != 0)
  69368. {
  69369. for (int i = 0; i < num; ++i)
  69370. x[i] = (x[i] + i * font->kerning) * scale;
  69371. }
  69372. else
  69373. {
  69374. for (int i = 0; i < num; ++i)
  69375. x[i] *= scale;
  69376. }
  69377. }
  69378. }
  69379. void Font::findFonts (OwnedArray<Font>& destArray) throw()
  69380. {
  69381. const StringArray names (findAllTypefaceNames());
  69382. for (int i = 0; i < names.size(); ++i)
  69383. destArray.add (new Font (names[i], defaultFontHeight, Font::plain));
  69384. }
  69385. class TypefaceCache : public DeletedAtShutdown
  69386. {
  69387. public:
  69388. TypefaceCache (int numToCache = 10) throw()
  69389. : counter (1)
  69390. {
  69391. while (--numToCache >= 0)
  69392. faces.add (new CachedFace());
  69393. }
  69394. ~TypefaceCache()
  69395. {
  69396. clearUpDefaultFontNames();
  69397. clearSingletonInstance();
  69398. }
  69399. juce_DeclareSingleton_SingleThreaded_Minimal (TypefaceCache)
  69400. const Typeface::Ptr findTypefaceFor (const Font& font) throw()
  69401. {
  69402. const int flags = font.getStyleFlags() & (Font::bold | Font::italic);
  69403. const String faceName (font.getTypefaceName());
  69404. int i;
  69405. for (i = faces.size(); --i >= 0;)
  69406. {
  69407. CachedFace* const face = faces.getUnchecked(i);
  69408. if (face->flags == flags
  69409. && face->typefaceName == faceName)
  69410. {
  69411. face->lastUsageCount = ++counter;
  69412. return face->typeFace;
  69413. }
  69414. }
  69415. int replaceIndex = 0;
  69416. int bestLastUsageCount = INT_MAX;
  69417. for (i = faces.size(); --i >= 0;)
  69418. {
  69419. const int lu = faces.getUnchecked(i)->lastUsageCount;
  69420. if (bestLastUsageCount > lu)
  69421. {
  69422. bestLastUsageCount = lu;
  69423. replaceIndex = i;
  69424. }
  69425. }
  69426. CachedFace* const face = faces.getUnchecked (replaceIndex);
  69427. face->typefaceName = faceName;
  69428. face->flags = flags;
  69429. face->lastUsageCount = ++counter;
  69430. face->typeFace = LookAndFeel::getDefaultLookAndFeel().getTypefaceForFont (font);
  69431. jassert (face->typeFace != 0); // the look and feel must return a typeface!
  69432. return face->typeFace;
  69433. }
  69434. juce_UseDebuggingNewOperator
  69435. private:
  69436. struct CachedFace
  69437. {
  69438. CachedFace() throw()
  69439. : lastUsageCount (0), flags (-1)
  69440. {
  69441. }
  69442. String typefaceName;
  69443. int lastUsageCount;
  69444. int flags;
  69445. Typeface::Ptr typeFace;
  69446. };
  69447. int counter;
  69448. OwnedArray <CachedFace> faces;
  69449. TypefaceCache (const TypefaceCache&);
  69450. const TypefaceCache& operator= (const TypefaceCache&);
  69451. };
  69452. juce_ImplementSingleton_SingleThreaded (TypefaceCache)
  69453. Typeface* Font::getTypeface() const throw()
  69454. {
  69455. if (font->typeface == 0)
  69456. font->typeface = TypefaceCache::getInstance()->findTypefaceFor (*this);
  69457. return font->typeface;
  69458. }
  69459. END_JUCE_NAMESPACE
  69460. /********* End of inlined file: juce_Font.cpp *********/
  69461. /********* Start of inlined file: juce_GlyphArrangement.cpp *********/
  69462. BEGIN_JUCE_NAMESPACE
  69463. PositionedGlyph::PositionedGlyph()
  69464. {
  69465. }
  69466. void PositionedGlyph::draw (const Graphics& g) const
  69467. {
  69468. if (! isWhitespace())
  69469. {
  69470. g.getInternalContext()->setFont (font);
  69471. g.getInternalContext()->drawGlyph (glyph, AffineTransform::translation (x, y));
  69472. }
  69473. }
  69474. void PositionedGlyph::draw (const Graphics& g,
  69475. const AffineTransform& transform) const
  69476. {
  69477. if (! isWhitespace())
  69478. {
  69479. g.getInternalContext()->setFont (font);
  69480. g.getInternalContext()->drawGlyph (glyph, AffineTransform::translation (x, y)
  69481. .followedBy (transform));
  69482. }
  69483. }
  69484. void PositionedGlyph::createPath (Path& path) const
  69485. {
  69486. if (! isWhitespace())
  69487. {
  69488. Typeface* const t = font.getTypeface();
  69489. if (t != 0)
  69490. {
  69491. Path p;
  69492. t->getOutlineForGlyph (glyph, p);
  69493. path.addPath (p, AffineTransform::scale (font.getHeight() * font.getHorizontalScale(), font.getHeight())
  69494. .translated (x, y));
  69495. }
  69496. }
  69497. }
  69498. bool PositionedGlyph::hitTest (float px, float py) const
  69499. {
  69500. if (px >= getLeft() && px < getRight()
  69501. && py >= getTop() && py < getBottom()
  69502. && ! isWhitespace())
  69503. {
  69504. Typeface* const t = font.getTypeface();
  69505. if (t != 0)
  69506. {
  69507. Path p;
  69508. t->getOutlineForGlyph (glyph, p);
  69509. AffineTransform::translation (-x, -y)
  69510. .scaled (1.0f / (font.getHeight() * font.getHorizontalScale()), 1.0f / font.getHeight())
  69511. .transformPoint (px, py);
  69512. return p.contains (px, py);
  69513. }
  69514. }
  69515. return false;
  69516. }
  69517. void PositionedGlyph::moveBy (const float deltaX,
  69518. const float deltaY)
  69519. {
  69520. x += deltaX;
  69521. y += deltaY;
  69522. }
  69523. GlyphArrangement::GlyphArrangement()
  69524. {
  69525. glyphs.ensureStorageAllocated (128);
  69526. }
  69527. GlyphArrangement::GlyphArrangement (const GlyphArrangement& other)
  69528. {
  69529. addGlyphArrangement (other);
  69530. }
  69531. const GlyphArrangement& GlyphArrangement::operator= (const GlyphArrangement& other)
  69532. {
  69533. if (this != &other)
  69534. {
  69535. clear();
  69536. addGlyphArrangement (other);
  69537. }
  69538. return *this;
  69539. }
  69540. GlyphArrangement::~GlyphArrangement()
  69541. {
  69542. }
  69543. void GlyphArrangement::clear()
  69544. {
  69545. glyphs.clear();
  69546. }
  69547. PositionedGlyph& GlyphArrangement::getGlyph (const int index) const
  69548. {
  69549. jassert (((unsigned int) index) < (unsigned int) glyphs.size());
  69550. return *glyphs [index];
  69551. }
  69552. void GlyphArrangement::addGlyphArrangement (const GlyphArrangement& other)
  69553. {
  69554. glyphs.ensureStorageAllocated (glyphs.size() + other.glyphs.size());
  69555. for (int i = 0; i < other.glyphs.size(); ++i)
  69556. glyphs.add (new PositionedGlyph (*other.glyphs.getUnchecked (i)));
  69557. }
  69558. void GlyphArrangement::removeRangeOfGlyphs (int startIndex, const int num)
  69559. {
  69560. glyphs.removeRange (startIndex, num < 0 ? glyphs.size() : num);
  69561. }
  69562. void GlyphArrangement::addLineOfText (const Font& font,
  69563. const String& text,
  69564. const float xOffset,
  69565. const float yOffset)
  69566. {
  69567. addCurtailedLineOfText (font, text,
  69568. xOffset, yOffset,
  69569. 1.0e10f, false);
  69570. }
  69571. void GlyphArrangement::addCurtailedLineOfText (const Font& font,
  69572. const String& text,
  69573. float xOffset,
  69574. const float yOffset,
  69575. const float maxWidthPixels,
  69576. const bool useEllipsis)
  69577. {
  69578. int textLen = text.length();
  69579. if (textLen > 0)
  69580. {
  69581. Array <int> newGlyphs;
  69582. Array <float> xOffsets;
  69583. font.getGlyphPositions (text, newGlyphs, xOffsets);
  69584. const juce_wchar* const unicodeText = (const juce_wchar*) text;
  69585. textLen = jmin (textLen, newGlyphs.size());
  69586. for (int i = 0; i < textLen; ++i)
  69587. {
  69588. const float thisX = xOffsets.getUnchecked (i);
  69589. const float nextX = xOffsets.getUnchecked (i + 1);
  69590. if (nextX > maxWidthPixels + 1.0f)
  69591. {
  69592. // curtail the string if it's too wide..
  69593. if (useEllipsis && textLen > 3 && glyphs.size() >= 3)
  69594. insertEllipsis (font, xOffset + maxWidthPixels, 0, glyphs.size());
  69595. break;
  69596. }
  69597. else
  69598. {
  69599. PositionedGlyph* const pg = new PositionedGlyph();
  69600. pg->x = xOffset + thisX;
  69601. pg->y = yOffset;
  69602. pg->w = nextX - thisX;
  69603. pg->font = font;
  69604. pg->glyph = newGlyphs.getUnchecked(i);
  69605. pg->character = unicodeText[i];
  69606. glyphs.add (pg);
  69607. }
  69608. }
  69609. }
  69610. }
  69611. int GlyphArrangement::insertEllipsis (const Font& font, const float maxXPos,
  69612. const int startIndex, int endIndex)
  69613. {
  69614. int numDeleted = 0;
  69615. if (glyphs.size() > 0)
  69616. {
  69617. Array<int> dotGlyphs;
  69618. Array<float> dotXs;
  69619. font.getGlyphPositions (T(".."), dotGlyphs, dotXs);
  69620. const float dx = dotXs[1];
  69621. float xOffset = 0.0f, yOffset = 0.0f;
  69622. while (endIndex > startIndex)
  69623. {
  69624. const PositionedGlyph* pg = glyphs.getUnchecked (--endIndex);
  69625. xOffset = pg->x;
  69626. yOffset = pg->y;
  69627. glyphs.remove (endIndex);
  69628. ++numDeleted;
  69629. if (xOffset + dx * 3 <= maxXPos)
  69630. break;
  69631. }
  69632. for (int i = 3; --i >= 0;)
  69633. {
  69634. PositionedGlyph* const pg = new PositionedGlyph();
  69635. pg->x = xOffset;
  69636. pg->y = yOffset;
  69637. pg->w = dx;
  69638. pg->font = font;
  69639. pg->character = '.';
  69640. pg->glyph = dotGlyphs.getFirst();
  69641. glyphs.insert (endIndex++, pg);
  69642. --numDeleted;
  69643. xOffset += dx;
  69644. if (xOffset > maxXPos)
  69645. break;
  69646. }
  69647. }
  69648. return numDeleted;
  69649. }
  69650. void GlyphArrangement::addJustifiedText (const Font& font,
  69651. const String& text,
  69652. float x, float y,
  69653. const float maxLineWidth,
  69654. const Justification& horizontalLayout)
  69655. {
  69656. int lineStartIndex = glyphs.size();
  69657. addLineOfText (font, text, x, y);
  69658. const float originalY = y;
  69659. while (lineStartIndex < glyphs.size())
  69660. {
  69661. int i = lineStartIndex;
  69662. if (glyphs.getUnchecked(i)->getCharacter() != T('\n')
  69663. && glyphs.getUnchecked(i)->getCharacter() != T('\r'))
  69664. ++i;
  69665. const float lineMaxX = glyphs.getUnchecked (lineStartIndex)->getLeft() + maxLineWidth;
  69666. int lastWordBreakIndex = -1;
  69667. while (i < glyphs.size())
  69668. {
  69669. const PositionedGlyph* pg = glyphs.getUnchecked (i);
  69670. const juce_wchar c = pg->getCharacter();
  69671. if (c == T('\r') || c == T('\n'))
  69672. {
  69673. ++i;
  69674. if (c == T('\r') && i < glyphs.size()
  69675. && glyphs.getUnchecked(i)->getCharacter() == T('\n'))
  69676. ++i;
  69677. break;
  69678. }
  69679. else if (pg->isWhitespace())
  69680. {
  69681. lastWordBreakIndex = i + 1;
  69682. }
  69683. else if (pg->getRight() - 0.0001f >= lineMaxX)
  69684. {
  69685. if (lastWordBreakIndex >= 0)
  69686. i = lastWordBreakIndex;
  69687. break;
  69688. }
  69689. ++i;
  69690. }
  69691. const float currentLineStartX = glyphs.getUnchecked (lineStartIndex)->getLeft();
  69692. float currentLineEndX = currentLineStartX;
  69693. for (int j = i; --j >= lineStartIndex;)
  69694. {
  69695. if (! glyphs.getUnchecked (j)->isWhitespace())
  69696. {
  69697. currentLineEndX = glyphs.getUnchecked (j)->getRight();
  69698. break;
  69699. }
  69700. }
  69701. float deltaX = 0.0f;
  69702. if (horizontalLayout.testFlags (Justification::horizontallyJustified))
  69703. spreadOutLine (lineStartIndex, i - lineStartIndex, maxLineWidth);
  69704. else if (horizontalLayout.testFlags (Justification::horizontallyCentred))
  69705. deltaX = (maxLineWidth - (currentLineEndX - currentLineStartX)) * 0.5f;
  69706. else if (horizontalLayout.testFlags (Justification::right))
  69707. deltaX = maxLineWidth - (currentLineEndX - currentLineStartX);
  69708. moveRangeOfGlyphs (lineStartIndex, i - lineStartIndex,
  69709. x + deltaX - currentLineStartX, y - originalY);
  69710. lineStartIndex = i;
  69711. y += font.getHeight();
  69712. }
  69713. }
  69714. void GlyphArrangement::addFittedText (const Font& f,
  69715. const String& text,
  69716. const float x, const float y,
  69717. const float width, const float height,
  69718. const Justification& layout,
  69719. int maximumLines,
  69720. const float minimumHorizontalScale)
  69721. {
  69722. // doesn't make much sense if this is outside a sensible range of 0.5 to 1.0
  69723. jassert (minimumHorizontalScale > 0 && minimumHorizontalScale <= 1.0f);
  69724. if (text.containsAnyOf (T("\r\n")))
  69725. {
  69726. GlyphArrangement ga;
  69727. ga.addJustifiedText (f, text, x, y, width, layout);
  69728. float l, t, r, b;
  69729. ga.getBoundingBox (0, -1, l, t, r, b, false);
  69730. float dy = y - t;
  69731. if (layout.testFlags (Justification::verticallyCentred))
  69732. dy += (height - (b - t)) * 0.5f;
  69733. else if (layout.testFlags (Justification::bottom))
  69734. dy += height - (b - t);
  69735. ga.moveRangeOfGlyphs (0, -1, 0.0f, dy);
  69736. glyphs.ensureStorageAllocated (glyphs.size() + ga.glyphs.size());
  69737. for (int i = 0; i < ga.glyphs.size(); ++i)
  69738. glyphs.add (ga.glyphs.getUnchecked (i));
  69739. ga.glyphs.clear (false);
  69740. return;
  69741. }
  69742. int startIndex = glyphs.size();
  69743. addLineOfText (f, text.trim(), x, y);
  69744. if (glyphs.size() > startIndex)
  69745. {
  69746. float lineWidth = glyphs.getUnchecked (glyphs.size() - 1)->getRight()
  69747. - glyphs.getUnchecked (startIndex)->getLeft();
  69748. if (lineWidth <= 0)
  69749. return;
  69750. if (lineWidth * minimumHorizontalScale < width)
  69751. {
  69752. if (lineWidth > width)
  69753. stretchRangeOfGlyphs (startIndex, glyphs.size() - startIndex,
  69754. width / lineWidth);
  69755. justifyGlyphs (startIndex, glyphs.size() - startIndex,
  69756. x, y, width, height, layout);
  69757. }
  69758. else if (maximumLines <= 1)
  69759. {
  69760. fitLineIntoSpace (startIndex, glyphs.size() - startIndex,
  69761. x, y, width, height, f, layout, minimumHorizontalScale);
  69762. }
  69763. else
  69764. {
  69765. Font font (f);
  69766. String txt (text.trim());
  69767. const int length = txt.length();
  69768. const int originalStartIndex = startIndex;
  69769. int numLines = 1;
  69770. if (length <= 12 && ! txt.containsAnyOf (T(" -\t\r\n")))
  69771. maximumLines = 1;
  69772. maximumLines = jmin (maximumLines, length);
  69773. while (numLines < maximumLines)
  69774. {
  69775. ++numLines;
  69776. const float newFontHeight = height / (float) numLines;
  69777. if (newFontHeight < font.getHeight())
  69778. {
  69779. font.setHeight (jmax (8.0f, newFontHeight));
  69780. removeRangeOfGlyphs (startIndex, -1);
  69781. addLineOfText (font, txt, x, y);
  69782. lineWidth = glyphs.getUnchecked (glyphs.size() - 1)->getRight()
  69783. - glyphs.getUnchecked (startIndex)->getLeft();
  69784. }
  69785. if (numLines > lineWidth / width || newFontHeight < 8.0f)
  69786. break;
  69787. }
  69788. if (numLines < 1)
  69789. numLines = 1;
  69790. float lineY = y;
  69791. float widthPerLine = lineWidth / numLines;
  69792. int lastLineStartIndex = 0;
  69793. for (int line = 0; line < numLines; ++line)
  69794. {
  69795. int i = startIndex;
  69796. lastLineStartIndex = i;
  69797. float lineStartX = glyphs.getUnchecked (startIndex)->getLeft();
  69798. if (line == numLines - 1)
  69799. {
  69800. widthPerLine = width;
  69801. i = glyphs.size();
  69802. }
  69803. else
  69804. {
  69805. while (i < glyphs.size())
  69806. {
  69807. lineWidth = (glyphs.getUnchecked (i)->getRight() - lineStartX);
  69808. if (lineWidth > widthPerLine)
  69809. {
  69810. // got to a point where the line's too long, so skip forward to find a
  69811. // good place to break it..
  69812. const int searchStartIndex = i;
  69813. while (i < glyphs.size())
  69814. {
  69815. if ((glyphs.getUnchecked (i)->getRight() - lineStartX) * minimumHorizontalScale < width)
  69816. {
  69817. if (glyphs.getUnchecked (i)->isWhitespace()
  69818. || glyphs.getUnchecked (i)->getCharacter() == T('-'))
  69819. {
  69820. ++i;
  69821. break;
  69822. }
  69823. }
  69824. else
  69825. {
  69826. // can't find a suitable break, so try looking backwards..
  69827. i = searchStartIndex;
  69828. for (int back = 1; back < jmin (5, i - startIndex - 1); ++back)
  69829. {
  69830. if (glyphs.getUnchecked (i - back)->isWhitespace()
  69831. || glyphs.getUnchecked (i - back)->getCharacter() == T('-'))
  69832. {
  69833. i -= back - 1;
  69834. break;
  69835. }
  69836. }
  69837. break;
  69838. }
  69839. ++i;
  69840. }
  69841. break;
  69842. }
  69843. ++i;
  69844. }
  69845. int wsStart = i;
  69846. while (wsStart > 0 && glyphs.getUnchecked (wsStart - 1)->isWhitespace())
  69847. --wsStart;
  69848. int wsEnd = i;
  69849. while (wsEnd < glyphs.size() && glyphs.getUnchecked (wsEnd)->isWhitespace())
  69850. ++wsEnd;
  69851. removeRangeOfGlyphs (wsStart, wsEnd - wsStart);
  69852. i = jmax (wsStart, startIndex + 1);
  69853. }
  69854. i -= fitLineIntoSpace (startIndex, i - startIndex,
  69855. x, lineY, width, font.getHeight(), font,
  69856. layout.getOnlyHorizontalFlags() | Justification::verticallyCentred,
  69857. minimumHorizontalScale);
  69858. startIndex = i;
  69859. lineY += font.getHeight();
  69860. if (startIndex >= glyphs.size())
  69861. break;
  69862. }
  69863. justifyGlyphs (originalStartIndex, glyphs.size() - originalStartIndex,
  69864. x, y, width, height, layout.getFlags() & ~Justification::horizontallyJustified);
  69865. }
  69866. }
  69867. }
  69868. void GlyphArrangement::moveRangeOfGlyphs (int startIndex, int num,
  69869. const float dx, const float dy)
  69870. {
  69871. jassert (startIndex >= 0);
  69872. if (dx != 0.0f || dy != 0.0f)
  69873. {
  69874. if (num < 0 || startIndex + num > glyphs.size())
  69875. num = glyphs.size() - startIndex;
  69876. while (--num >= 0)
  69877. glyphs.getUnchecked (startIndex++)->moveBy (dx, dy);
  69878. }
  69879. }
  69880. int GlyphArrangement::fitLineIntoSpace (int start, int numGlyphs, float x, float y, float w, float h, const Font& font,
  69881. const Justification& justification, float minimumHorizontalScale)
  69882. {
  69883. int numDeleted = 0;
  69884. const float lineStartX = glyphs.getUnchecked (start)->getLeft();
  69885. float lineWidth = glyphs.getUnchecked (start + numGlyphs - 1)->getRight() - lineStartX;
  69886. if (lineWidth > w)
  69887. {
  69888. if (minimumHorizontalScale < 1.0f)
  69889. {
  69890. stretchRangeOfGlyphs (start, numGlyphs, jmax (minimumHorizontalScale, w / lineWidth));
  69891. lineWidth = glyphs.getUnchecked (start + numGlyphs - 1)->getRight() - lineStartX - 0.5f;
  69892. }
  69893. if (lineWidth > w)
  69894. {
  69895. numDeleted = insertEllipsis (font, lineStartX + w, start, start + numGlyphs);
  69896. numGlyphs -= numDeleted;
  69897. }
  69898. }
  69899. justifyGlyphs (start, numGlyphs, x, y, w, h, justification);
  69900. return numDeleted;
  69901. }
  69902. void GlyphArrangement::stretchRangeOfGlyphs (int startIndex, int num,
  69903. const float horizontalScaleFactor)
  69904. {
  69905. jassert (startIndex >= 0);
  69906. if (num < 0 || startIndex + num > glyphs.size())
  69907. num = glyphs.size() - startIndex;
  69908. if (num > 0)
  69909. {
  69910. const float xAnchor = glyphs.getUnchecked (startIndex)->getLeft();
  69911. while (--num >= 0)
  69912. {
  69913. PositionedGlyph* const pg = glyphs.getUnchecked (startIndex++);
  69914. pg->x = xAnchor + (pg->x - xAnchor) * horizontalScaleFactor;
  69915. pg->font.setHorizontalScale (pg->font.getHorizontalScale() * horizontalScaleFactor);
  69916. pg->w *= horizontalScaleFactor;
  69917. }
  69918. }
  69919. }
  69920. void GlyphArrangement::getBoundingBox (int startIndex, int num,
  69921. float& left,
  69922. float& top,
  69923. float& right,
  69924. float& bottom,
  69925. const bool includeWhitespace) const
  69926. {
  69927. jassert (startIndex >= 0);
  69928. if (num < 0 || startIndex + num > glyphs.size())
  69929. num = glyphs.size() - startIndex;
  69930. left = 0.0f;
  69931. top = 0.0f;
  69932. right = 0.0f;
  69933. bottom = 0.0f;
  69934. bool isFirst = true;
  69935. while (--num >= 0)
  69936. {
  69937. const PositionedGlyph* const pg = glyphs.getUnchecked (startIndex++);
  69938. if (includeWhitespace || ! pg->isWhitespace())
  69939. {
  69940. if (isFirst)
  69941. {
  69942. isFirst = false;
  69943. left = pg->getLeft();
  69944. top = pg->getTop();
  69945. right = pg->getRight();
  69946. bottom = pg->getBottom();
  69947. }
  69948. else
  69949. {
  69950. left = jmin (left, pg->getLeft());
  69951. top = jmin (top, pg->getTop());
  69952. right = jmax (right, pg->getRight());
  69953. bottom = jmax (bottom, pg->getBottom());
  69954. }
  69955. }
  69956. }
  69957. }
  69958. void GlyphArrangement::justifyGlyphs (const int startIndex,
  69959. const int num,
  69960. const float x, const float y,
  69961. const float width, const float height,
  69962. const Justification& justification)
  69963. {
  69964. jassert (num >= 0 && startIndex >= 0);
  69965. if (glyphs.size() > 0 && num > 0)
  69966. {
  69967. float left, top, right, bottom;
  69968. getBoundingBox (startIndex, num, left, top, right, bottom,
  69969. ! justification.testFlags (Justification::horizontallyJustified
  69970. | Justification::horizontallyCentred));
  69971. float deltaX = 0.0f;
  69972. if (justification.testFlags (Justification::horizontallyJustified))
  69973. deltaX = x - left;
  69974. else if (justification.testFlags (Justification::horizontallyCentred))
  69975. deltaX = x + (width - (right - left)) * 0.5f - left;
  69976. else if (justification.testFlags (Justification::right))
  69977. deltaX = (x + width) - right;
  69978. else
  69979. deltaX = x - left;
  69980. float deltaY = 0.0f;
  69981. if (justification.testFlags (Justification::top))
  69982. deltaY = y - top;
  69983. else if (justification.testFlags (Justification::bottom))
  69984. deltaY = (y + height) - bottom;
  69985. else
  69986. deltaY = y + (height - (bottom - top)) * 0.5f - top;
  69987. moveRangeOfGlyphs (startIndex, num, deltaX, deltaY);
  69988. if (justification.testFlags (Justification::horizontallyJustified))
  69989. {
  69990. int lineStart = 0;
  69991. float baseY = glyphs.getUnchecked (startIndex)->getBaselineY();
  69992. int i;
  69993. for (i = 0; i < num; ++i)
  69994. {
  69995. const float glyphY = glyphs.getUnchecked (startIndex + i)->getBaselineY();
  69996. if (glyphY != baseY)
  69997. {
  69998. spreadOutLine (startIndex + lineStart, i - lineStart, width);
  69999. lineStart = i;
  70000. baseY = glyphY;
  70001. }
  70002. }
  70003. if (i > lineStart)
  70004. spreadOutLine (startIndex + lineStart, i - lineStart, width);
  70005. }
  70006. }
  70007. }
  70008. void GlyphArrangement::spreadOutLine (const int start, const int num, const float targetWidth)
  70009. {
  70010. if (start + num < glyphs.size()
  70011. && glyphs.getUnchecked (start + num - 1)->getCharacter() != T('\r')
  70012. && glyphs.getUnchecked (start + num - 1)->getCharacter() != T('\n'))
  70013. {
  70014. int numSpaces = 0;
  70015. int spacesAtEnd = 0;
  70016. for (int i = 0; i < num; ++i)
  70017. {
  70018. if (glyphs.getUnchecked (start + i)->isWhitespace())
  70019. {
  70020. ++spacesAtEnd;
  70021. ++numSpaces;
  70022. }
  70023. else
  70024. {
  70025. spacesAtEnd = 0;
  70026. }
  70027. }
  70028. numSpaces -= spacesAtEnd;
  70029. if (numSpaces > 0)
  70030. {
  70031. const float startX = glyphs.getUnchecked (start)->getLeft();
  70032. const float endX = glyphs.getUnchecked (start + num - 1 - spacesAtEnd)->getRight();
  70033. const float extraPaddingBetweenWords
  70034. = (targetWidth - (endX - startX)) / (float) numSpaces;
  70035. float deltaX = 0.0f;
  70036. for (int i = 0; i < num; ++i)
  70037. {
  70038. glyphs.getUnchecked (start + i)->moveBy (deltaX, 0.0f);
  70039. if (glyphs.getUnchecked (start + i)->isWhitespace())
  70040. deltaX += extraPaddingBetweenWords;
  70041. }
  70042. }
  70043. }
  70044. }
  70045. void GlyphArrangement::draw (const Graphics& g) const
  70046. {
  70047. for (int i = 0; i < glyphs.size(); ++i)
  70048. {
  70049. const PositionedGlyph* const pg = glyphs.getUnchecked(i);
  70050. if (pg->font.isUnderlined())
  70051. {
  70052. const float lineThickness = (pg->font.getDescent()) * 0.3f;
  70053. float nextX = pg->x + pg->w;
  70054. if (i < glyphs.size() - 1 && glyphs.getUnchecked (i + 1)->y == pg->y)
  70055. nextX = glyphs.getUnchecked (i + 1)->x;
  70056. g.fillRect (pg->x, pg->y + lineThickness * 2.0f,
  70057. nextX - pg->x, lineThickness);
  70058. }
  70059. pg->draw (g);
  70060. }
  70061. }
  70062. void GlyphArrangement::draw (const Graphics& g, const AffineTransform& transform) const
  70063. {
  70064. for (int i = 0; i < glyphs.size(); ++i)
  70065. {
  70066. const PositionedGlyph* const pg = glyphs.getUnchecked(i);
  70067. if (pg->font.isUnderlined())
  70068. {
  70069. const float lineThickness = (pg->font.getDescent()) * 0.3f;
  70070. float nextX = pg->x + pg->w;
  70071. if (i < glyphs.size() - 1 && glyphs.getUnchecked (i + 1)->y == pg->y)
  70072. nextX = glyphs.getUnchecked (i + 1)->x;
  70073. Path p;
  70074. p.addLineSegment (pg->x, pg->y + lineThickness * 2.0f,
  70075. nextX, pg->y + lineThickness * 2.0f,
  70076. lineThickness);
  70077. g.fillPath (p, transform);
  70078. }
  70079. pg->draw (g, transform);
  70080. }
  70081. }
  70082. void GlyphArrangement::createPath (Path& path) const
  70083. {
  70084. for (int i = 0; i < glyphs.size(); ++i)
  70085. glyphs.getUnchecked (i)->createPath (path);
  70086. }
  70087. int GlyphArrangement::findGlyphIndexAt (float x, float y) const
  70088. {
  70089. for (int i = 0; i < glyphs.size(); ++i)
  70090. if (glyphs.getUnchecked (i)->hitTest (x, y))
  70091. return i;
  70092. return -1;
  70093. }
  70094. END_JUCE_NAMESPACE
  70095. /********* End of inlined file: juce_GlyphArrangement.cpp *********/
  70096. /********* Start of inlined file: juce_TextLayout.cpp *********/
  70097. BEGIN_JUCE_NAMESPACE
  70098. class TextLayout::Token
  70099. {
  70100. public:
  70101. String text;
  70102. Font font;
  70103. int x, y, w, h;
  70104. int line, lineHeight;
  70105. bool isWhitespace, isNewLine;
  70106. Token (const String& t,
  70107. const Font& f,
  70108. const bool isWhitespace_) throw()
  70109. : text (t),
  70110. font (f),
  70111. x(0),
  70112. y(0),
  70113. isWhitespace (isWhitespace_)
  70114. {
  70115. w = font.getStringWidth (t);
  70116. h = roundToInt (f.getHeight());
  70117. isNewLine = t.containsAnyOf (T("\r\n"));
  70118. }
  70119. Token (const Token& other) throw()
  70120. : text (other.text),
  70121. font (other.font),
  70122. x (other.x),
  70123. y (other.y),
  70124. w (other.w),
  70125. h (other.h),
  70126. line (other.line),
  70127. lineHeight (other.lineHeight),
  70128. isWhitespace (other.isWhitespace),
  70129. isNewLine (other.isNewLine)
  70130. {
  70131. }
  70132. ~Token() throw()
  70133. {
  70134. }
  70135. void draw (Graphics& g,
  70136. const int xOffset,
  70137. const int yOffset) throw()
  70138. {
  70139. if (! isWhitespace)
  70140. {
  70141. g.setFont (font);
  70142. g.drawSingleLineText (text.trimEnd(),
  70143. xOffset + x,
  70144. yOffset + y + (lineHeight - h)
  70145. + roundToInt (font.getAscent()));
  70146. }
  70147. }
  70148. juce_UseDebuggingNewOperator
  70149. };
  70150. TextLayout::TextLayout() throw()
  70151. : totalLines (0)
  70152. {
  70153. tokens.ensureStorageAllocated (64);
  70154. }
  70155. TextLayout::TextLayout (const String& text,
  70156. const Font& font) throw()
  70157. : totalLines (0)
  70158. {
  70159. tokens.ensureStorageAllocated (64);
  70160. appendText (text, font);
  70161. }
  70162. TextLayout::TextLayout (const TextLayout& other) throw()
  70163. : totalLines (0)
  70164. {
  70165. *this = other;
  70166. }
  70167. const TextLayout& TextLayout::operator= (const TextLayout& other) throw()
  70168. {
  70169. if (this != &other)
  70170. {
  70171. clear();
  70172. totalLines = other.totalLines;
  70173. for (int i = 0; i < other.tokens.size(); ++i)
  70174. tokens.add (new Token (*other.tokens.getUnchecked(i)));
  70175. }
  70176. return *this;
  70177. }
  70178. TextLayout::~TextLayout() throw()
  70179. {
  70180. clear();
  70181. }
  70182. void TextLayout::clear() throw()
  70183. {
  70184. tokens.clear();
  70185. totalLines = 0;
  70186. }
  70187. void TextLayout::appendText (const String& text,
  70188. const Font& font) throw()
  70189. {
  70190. const tchar* t = text;
  70191. String currentString;
  70192. int lastCharType = 0;
  70193. for (;;)
  70194. {
  70195. const tchar c = *t++;
  70196. if (c == 0)
  70197. break;
  70198. int charType;
  70199. if (c == T('\r') || c == T('\n'))
  70200. {
  70201. charType = 0;
  70202. }
  70203. else if (CharacterFunctions::isWhitespace (c))
  70204. {
  70205. charType = 2;
  70206. }
  70207. else
  70208. {
  70209. charType = 1;
  70210. }
  70211. if (charType == 0 || charType != lastCharType)
  70212. {
  70213. if (currentString.isNotEmpty())
  70214. {
  70215. tokens.add (new Token (currentString, font,
  70216. lastCharType == 2 || lastCharType == 0));
  70217. }
  70218. currentString = String::charToString (c);
  70219. if (c == T('\r') && *t == T('\n'))
  70220. currentString += *t++;
  70221. }
  70222. else
  70223. {
  70224. currentString += c;
  70225. }
  70226. lastCharType = charType;
  70227. }
  70228. if (currentString.isNotEmpty())
  70229. tokens.add (new Token (currentString, font, lastCharType == 2));
  70230. }
  70231. void TextLayout::setText (const String& text, const Font& font) throw()
  70232. {
  70233. clear();
  70234. appendText (text, font);
  70235. }
  70236. void TextLayout::layout (int maxWidth,
  70237. const Justification& justification,
  70238. const bool attemptToBalanceLineLengths) throw()
  70239. {
  70240. if (attemptToBalanceLineLengths)
  70241. {
  70242. const int originalW = maxWidth;
  70243. int bestWidth = maxWidth;
  70244. float bestLineProportion = 0.0f;
  70245. while (maxWidth > originalW / 2)
  70246. {
  70247. layout (maxWidth, justification, false);
  70248. if (getNumLines() <= 1)
  70249. return;
  70250. const int lastLineW = getLineWidth (getNumLines() - 1);
  70251. const int lastButOneLineW = getLineWidth (getNumLines() - 2);
  70252. const float prop = lastLineW / (float) lastButOneLineW;
  70253. if (prop > 0.9f)
  70254. return;
  70255. if (prop > bestLineProportion)
  70256. {
  70257. bestLineProportion = prop;
  70258. bestWidth = maxWidth;
  70259. }
  70260. maxWidth -= 10;
  70261. }
  70262. layout (bestWidth, justification, false);
  70263. }
  70264. else
  70265. {
  70266. int x = 0;
  70267. int y = 0;
  70268. int h = 0;
  70269. totalLines = 0;
  70270. int i;
  70271. for (i = 0; i < tokens.size(); ++i)
  70272. {
  70273. Token* const t = tokens.getUnchecked(i);
  70274. t->x = x;
  70275. t->y = y;
  70276. t->line = totalLines;
  70277. x += t->w;
  70278. h = jmax (h, t->h);
  70279. const Token* nextTok = tokens [i + 1];
  70280. if (nextTok == 0)
  70281. break;
  70282. if (t->isNewLine || ((! nextTok->isWhitespace) && x + nextTok->w > maxWidth))
  70283. {
  70284. // finished a line, so go back and update the heights of the things on it
  70285. for (int j = i; j >= 0; --j)
  70286. {
  70287. Token* const tok = tokens.getUnchecked(j);
  70288. if (tok->line == totalLines)
  70289. tok->lineHeight = h;
  70290. else
  70291. break;
  70292. }
  70293. x = 0;
  70294. y += h;
  70295. h = 0;
  70296. ++totalLines;
  70297. }
  70298. }
  70299. // finished a line, so go back and update the heights of the things on it
  70300. for (int j = jmin (i, tokens.size() - 1); j >= 0; --j)
  70301. {
  70302. Token* const t = tokens.getUnchecked(j);
  70303. if (t->line == totalLines)
  70304. t->lineHeight = h;
  70305. else
  70306. break;
  70307. }
  70308. ++totalLines;
  70309. if (! justification.testFlags (Justification::left))
  70310. {
  70311. int totalW = getWidth();
  70312. for (i = totalLines; --i >= 0;)
  70313. {
  70314. const int lineW = getLineWidth (i);
  70315. int dx = 0;
  70316. if (justification.testFlags (Justification::horizontallyCentred))
  70317. dx = (totalW - lineW) / 2;
  70318. else if (justification.testFlags (Justification::right))
  70319. dx = totalW - lineW;
  70320. for (int j = tokens.size(); --j >= 0;)
  70321. {
  70322. Token* const t = tokens.getUnchecked(j);
  70323. if (t->line == i)
  70324. t->x += dx;
  70325. }
  70326. }
  70327. }
  70328. }
  70329. }
  70330. int TextLayout::getLineWidth (const int lineNumber) const throw()
  70331. {
  70332. int maxW = 0;
  70333. for (int i = tokens.size(); --i >= 0;)
  70334. {
  70335. const Token* const t = tokens.getUnchecked(i);
  70336. if (t->line == lineNumber && ! t->isWhitespace)
  70337. maxW = jmax (maxW, t->x + t->w);
  70338. }
  70339. return maxW;
  70340. }
  70341. int TextLayout::getWidth() const throw()
  70342. {
  70343. int maxW = 0;
  70344. for (int i = tokens.size(); --i >= 0;)
  70345. {
  70346. const Token* const t = tokens.getUnchecked(i);
  70347. if (! t->isWhitespace)
  70348. maxW = jmax (maxW, t->x + t->w);
  70349. }
  70350. return maxW;
  70351. }
  70352. int TextLayout::getHeight() const throw()
  70353. {
  70354. int maxH = 0;
  70355. for (int i = tokens.size(); --i >= 0;)
  70356. {
  70357. const Token* const t = tokens.getUnchecked(i);
  70358. if (! t->isWhitespace)
  70359. maxH = jmax (maxH, t->y + t->h);
  70360. }
  70361. return maxH;
  70362. }
  70363. void TextLayout::draw (Graphics& g,
  70364. const int xOffset,
  70365. const int yOffset) const throw()
  70366. {
  70367. for (int i = tokens.size(); --i >= 0;)
  70368. tokens.getUnchecked(i)->draw (g, xOffset, yOffset);
  70369. }
  70370. void TextLayout::drawWithin (Graphics& g,
  70371. int x, int y, int w, int h,
  70372. const Justification& justification) const throw()
  70373. {
  70374. justification.applyToRectangle (x, y, getWidth(), getHeight(),
  70375. x, y, w, h);
  70376. draw (g, x, y);
  70377. }
  70378. END_JUCE_NAMESPACE
  70379. /********* End of inlined file: juce_TextLayout.cpp *********/
  70380. /********* Start of inlined file: juce_Typeface.cpp *********/
  70381. BEGIN_JUCE_NAMESPACE
  70382. Typeface::Typeface (const String& name_) throw()
  70383. : name (name_)
  70384. {
  70385. }
  70386. Typeface::~Typeface()
  70387. {
  70388. }
  70389. class CustomTypeface::GlyphInfo
  70390. {
  70391. public:
  70392. GlyphInfo (const juce_wchar character_, const Path& path_, const float width_) throw()
  70393. : character (character_), path (path_), width (width_)
  70394. {
  70395. }
  70396. ~GlyphInfo() throw()
  70397. {
  70398. }
  70399. struct KerningPair
  70400. {
  70401. juce_wchar character2;
  70402. float kerningAmount;
  70403. };
  70404. void addKerningPair (const juce_wchar subsequentCharacter,
  70405. const float extraKerningAmount) throw()
  70406. {
  70407. KerningPair kp;
  70408. kp.character2 = subsequentCharacter;
  70409. kp.kerningAmount = extraKerningAmount;
  70410. kerningPairs.add (kp);
  70411. }
  70412. float getHorizontalSpacing (const juce_wchar subsequentCharacter) const throw()
  70413. {
  70414. if (subsequentCharacter != 0)
  70415. {
  70416. for (int i = kerningPairs.size(); --i >= 0;)
  70417. if (kerningPairs.getReference(i).character2 == subsequentCharacter)
  70418. return width + kerningPairs.getReference(i).kerningAmount;
  70419. }
  70420. return width;
  70421. }
  70422. const juce_wchar character;
  70423. const Path path;
  70424. float width;
  70425. Array <KerningPair> kerningPairs;
  70426. juce_UseDebuggingNewOperator
  70427. private:
  70428. GlyphInfo (const GlyphInfo&);
  70429. const GlyphInfo& operator= (const GlyphInfo&);
  70430. };
  70431. CustomTypeface::CustomTypeface()
  70432. : Typeface (String::empty)
  70433. {
  70434. clear();
  70435. }
  70436. CustomTypeface::CustomTypeface (InputStream& serialisedTypefaceStream)
  70437. : Typeface (String::empty)
  70438. {
  70439. clear();
  70440. GZIPDecompressorInputStream gzin (&serialisedTypefaceStream, false);
  70441. BufferedInputStream in (&gzin, 32768, false);
  70442. name = in.readString();
  70443. isBold = in.readBool();
  70444. isItalic = in.readBool();
  70445. ascent = in.readFloat();
  70446. defaultCharacter = (juce_wchar) in.readShort();
  70447. int i, numChars = in.readInt();
  70448. for (i = 0; i < numChars; ++i)
  70449. {
  70450. const juce_wchar c = (juce_wchar) in.readShort();
  70451. const float width = in.readFloat();
  70452. Path p;
  70453. p.loadPathFromStream (in);
  70454. addGlyph (c, p, width);
  70455. }
  70456. const int numKerningPairs = in.readInt();
  70457. for (i = 0; i < numKerningPairs; ++i)
  70458. {
  70459. const juce_wchar char1 = (juce_wchar) in.readShort();
  70460. const juce_wchar char2 = (juce_wchar) in.readShort();
  70461. addKerningPair (char1, char2, in.readFloat());
  70462. }
  70463. }
  70464. CustomTypeface::~CustomTypeface()
  70465. {
  70466. }
  70467. void CustomTypeface::clear()
  70468. {
  70469. defaultCharacter = 0;
  70470. ascent = 1.0f;
  70471. isBold = isItalic = false;
  70472. zeromem (lookupTable, sizeof (lookupTable));
  70473. glyphs.clear();
  70474. }
  70475. void CustomTypeface::setCharacteristics (const String& name_, const float ascent_, const bool isBold_,
  70476. const bool isItalic_, const juce_wchar defaultCharacter_) throw()
  70477. {
  70478. name = name_;
  70479. defaultCharacter = defaultCharacter_;
  70480. ascent = ascent_;
  70481. isBold = isBold_;
  70482. isItalic = isItalic_;
  70483. }
  70484. void CustomTypeface::addGlyph (const juce_wchar character, const Path& path, const float width) throw()
  70485. {
  70486. // Check that you're not trying to add the same character twice..
  70487. jassert (findGlyph (character, false) == 0);
  70488. if (((unsigned int) character) < (unsigned int) numElementsInArray (lookupTable))
  70489. lookupTable [character] = (short) glyphs.size();
  70490. glyphs.add (new GlyphInfo (character, path, width));
  70491. }
  70492. void CustomTypeface::addKerningPair (const juce_wchar char1, const juce_wchar char2, const float extraAmount) throw()
  70493. {
  70494. if (extraAmount != 0)
  70495. {
  70496. GlyphInfo* const g = findGlyph (char1, true);
  70497. jassert (g != 0); // can only add kerning pairs for characters that exist!
  70498. if (g != 0)
  70499. g->addKerningPair (char2, extraAmount);
  70500. }
  70501. }
  70502. CustomTypeface::GlyphInfo* CustomTypeface::findGlyph (const juce_wchar character, const bool loadIfNeeded) throw()
  70503. {
  70504. if (((unsigned int) character) < (unsigned int) numElementsInArray (lookupTable) && lookupTable [character] > 0)
  70505. return glyphs [(int) lookupTable [(int) character]];
  70506. for (int i = 0; i < glyphs.size(); ++i)
  70507. {
  70508. GlyphInfo* const g = glyphs.getUnchecked(i);
  70509. if (g->character == character)
  70510. return g;
  70511. }
  70512. if (loadIfNeeded && loadGlyphIfPossible (character))
  70513. return findGlyph (character, false);
  70514. return 0;
  70515. }
  70516. CustomTypeface::GlyphInfo* CustomTypeface::findGlyphSubstituting (const juce_wchar character) throw()
  70517. {
  70518. GlyphInfo* glyph = findGlyph (character, true);
  70519. if (glyph == 0)
  70520. {
  70521. if (CharacterFunctions::isWhitespace (character) && character != L' ')
  70522. glyph = findGlyph (L' ', true);
  70523. if (glyph == 0)
  70524. {
  70525. const Font fallbackFont (Font::getFallbackFontName(), 10, 0);
  70526. Typeface* const fallbackTypeface = fallbackFont.getTypeface();
  70527. if (fallbackTypeface != 0 && fallbackTypeface != this)
  70528. {
  70529. //xxx
  70530. }
  70531. if (glyph == 0)
  70532. glyph = findGlyph (defaultCharacter, true);
  70533. }
  70534. }
  70535. return glyph;
  70536. }
  70537. bool CustomTypeface::loadGlyphIfPossible (const juce_wchar /*characterNeeded*/)
  70538. {
  70539. return false;
  70540. }
  70541. void CustomTypeface::addGlyphsFromOtherTypeface (Typeface& typefaceToCopy, juce_wchar characterStartIndex, int numCharacters) throw()
  70542. {
  70543. for (int i = 0; i < numCharacters; ++i)
  70544. {
  70545. const juce_wchar c = (juce_wchar) (characterStartIndex + i);
  70546. Array <int> glyphIndexes;
  70547. Array <float> offsets;
  70548. typefaceToCopy.getGlyphPositions (String::charToString (c), glyphIndexes, offsets);
  70549. const int glyphIndex = glyphIndexes.getFirst();
  70550. if (glyphIndex >= 0 && glyphIndexes.size() > 0)
  70551. {
  70552. const float glyphWidth = offsets[1];
  70553. Path p;
  70554. typefaceToCopy.getOutlineForGlyph (glyphIndex, p);
  70555. addGlyph (c, p, glyphWidth);
  70556. for (int j = glyphs.size() - 1; --j >= 0;)
  70557. {
  70558. const juce_wchar char2 = glyphs.getUnchecked (j)->character;
  70559. glyphIndexes.clearQuick();
  70560. offsets.clearQuick();
  70561. typefaceToCopy.getGlyphPositions (String::charToString (c) + String::charToString (char2), glyphIndexes, offsets);
  70562. if (offsets.size() > 1)
  70563. addKerningPair (c, char2, offsets[1] - glyphWidth);
  70564. }
  70565. }
  70566. }
  70567. }
  70568. bool CustomTypeface::writeToStream (OutputStream& outputStream)
  70569. {
  70570. GZIPCompressorOutputStream out (&outputStream);
  70571. out.writeString (name);
  70572. out.writeBool (isBold);
  70573. out.writeBool (isItalic);
  70574. out.writeFloat (ascent);
  70575. out.writeShort ((short) (unsigned short) defaultCharacter);
  70576. out.writeInt (glyphs.size());
  70577. int i, numKerningPairs = 0;
  70578. for (i = 0; i < glyphs.size(); ++i)
  70579. {
  70580. const GlyphInfo* const g = glyphs.getUnchecked (i);
  70581. out.writeShort ((short) (unsigned short) g->character);
  70582. out.writeFloat (g->width);
  70583. g->path.writePathToStream (out);
  70584. numKerningPairs += g->kerningPairs.size();
  70585. }
  70586. out.writeInt (numKerningPairs);
  70587. for (i = 0; i < glyphs.size(); ++i)
  70588. {
  70589. const GlyphInfo* const g = glyphs.getUnchecked (i);
  70590. for (int j = 0; j < g->kerningPairs.size(); ++j)
  70591. {
  70592. const GlyphInfo::KerningPair& p = g->kerningPairs.getReference (j);
  70593. out.writeShort ((short) (unsigned short) g->character);
  70594. out.writeShort ((short) (unsigned short) p.character2);
  70595. out.writeFloat (p.kerningAmount);
  70596. }
  70597. }
  70598. return true;
  70599. }
  70600. float CustomTypeface::getAscent() const
  70601. {
  70602. return ascent;
  70603. }
  70604. float CustomTypeface::getDescent() const
  70605. {
  70606. return 1.0f - ascent;
  70607. }
  70608. float CustomTypeface::getStringWidth (const String& text)
  70609. {
  70610. float x = 0;
  70611. const juce_wchar* t = (const juce_wchar*) text;
  70612. while (*t != 0)
  70613. {
  70614. const GlyphInfo* const glyph = findGlyphSubstituting (*t++);
  70615. if (glyph != 0)
  70616. x += glyph->getHorizontalSpacing (*t);
  70617. }
  70618. return x;
  70619. }
  70620. void CustomTypeface::getGlyphPositions (const String& text, Array <int>& resultGlyphs, Array<float>& xOffsets)
  70621. {
  70622. xOffsets.add (0);
  70623. float x = 0;
  70624. const juce_wchar* t = (const juce_wchar*) text;
  70625. while (*t != 0)
  70626. {
  70627. const juce_wchar c = *t++;
  70628. const GlyphInfo* const glyph = findGlyphSubstituting (c);
  70629. if (glyph != 0)
  70630. {
  70631. x += glyph->getHorizontalSpacing (*t);
  70632. resultGlyphs.add ((int) glyph->character);
  70633. xOffsets.add (x);
  70634. }
  70635. }
  70636. }
  70637. bool CustomTypeface::getOutlineForGlyph (int glyphNumber, Path& path)
  70638. {
  70639. const GlyphInfo* const glyph = findGlyphSubstituting ((juce_wchar) glyphNumber);
  70640. if (glyph != 0)
  70641. {
  70642. path = glyph->path;
  70643. return true;
  70644. }
  70645. return false;
  70646. }
  70647. END_JUCE_NAMESPACE
  70648. /********* End of inlined file: juce_Typeface.cpp *********/
  70649. /********* Start of inlined file: juce_AffineTransform.cpp *********/
  70650. BEGIN_JUCE_NAMESPACE
  70651. AffineTransform::AffineTransform() throw()
  70652. : mat00 (1.0f),
  70653. mat01 (0),
  70654. mat02 (0),
  70655. mat10 (0),
  70656. mat11 (1.0f),
  70657. mat12 (0)
  70658. {
  70659. }
  70660. AffineTransform::AffineTransform (const AffineTransform& other) throw()
  70661. : mat00 (other.mat00),
  70662. mat01 (other.mat01),
  70663. mat02 (other.mat02),
  70664. mat10 (other.mat10),
  70665. mat11 (other.mat11),
  70666. mat12 (other.mat12)
  70667. {
  70668. }
  70669. AffineTransform::AffineTransform (const float mat00_,
  70670. const float mat01_,
  70671. const float mat02_,
  70672. const float mat10_,
  70673. const float mat11_,
  70674. const float mat12_) throw()
  70675. : mat00 (mat00_),
  70676. mat01 (mat01_),
  70677. mat02 (mat02_),
  70678. mat10 (mat10_),
  70679. mat11 (mat11_),
  70680. mat12 (mat12_)
  70681. {
  70682. }
  70683. const AffineTransform& AffineTransform::operator= (const AffineTransform& other) throw()
  70684. {
  70685. mat00 = other.mat00;
  70686. mat01 = other.mat01;
  70687. mat02 = other.mat02;
  70688. mat10 = other.mat10;
  70689. mat11 = other.mat11;
  70690. mat12 = other.mat12;
  70691. return *this;
  70692. }
  70693. bool AffineTransform::operator== (const AffineTransform& other) const throw()
  70694. {
  70695. return mat00 == other.mat00
  70696. && mat01 == other.mat01
  70697. && mat02 == other.mat02
  70698. && mat10 == other.mat10
  70699. && mat11 == other.mat11
  70700. && mat12 == other.mat12;
  70701. }
  70702. bool AffineTransform::operator!= (const AffineTransform& other) const throw()
  70703. {
  70704. return ! operator== (other);
  70705. }
  70706. bool AffineTransform::isIdentity() const throw()
  70707. {
  70708. return (mat01 == 0)
  70709. && (mat02 == 0)
  70710. && (mat10 == 0)
  70711. && (mat12 == 0)
  70712. && (mat00 == 1.0f)
  70713. && (mat11 == 1.0f);
  70714. }
  70715. const AffineTransform AffineTransform::identity;
  70716. const AffineTransform AffineTransform::followedBy (const AffineTransform& other) const throw()
  70717. {
  70718. return AffineTransform (other.mat00 * mat00 + other.mat01 * mat10,
  70719. other.mat00 * mat01 + other.mat01 * mat11,
  70720. other.mat00 * mat02 + other.mat01 * mat12 + other.mat02,
  70721. other.mat10 * mat00 + other.mat11 * mat10,
  70722. other.mat10 * mat01 + other.mat11 * mat11,
  70723. other.mat10 * mat02 + other.mat11 * mat12 + other.mat12);
  70724. }
  70725. const AffineTransform AffineTransform::followedBy (const float omat00,
  70726. const float omat01,
  70727. const float omat02,
  70728. const float omat10,
  70729. const float omat11,
  70730. const float omat12) const throw()
  70731. {
  70732. return AffineTransform (omat00 * mat00 + omat01 * mat10,
  70733. omat00 * mat01 + omat01 * mat11,
  70734. omat00 * mat02 + omat01 * mat12 + omat02,
  70735. omat10 * mat00 + omat11 * mat10,
  70736. omat10 * mat01 + omat11 * mat11,
  70737. omat10 * mat02 + omat11 * mat12 + omat12);
  70738. }
  70739. const AffineTransform AffineTransform::translated (const float dx,
  70740. const float dy) const throw()
  70741. {
  70742. return AffineTransform (mat00, mat01, mat02 + dx,
  70743. mat10, mat11, mat12 + dy);
  70744. }
  70745. const AffineTransform AffineTransform::translation (const float dx,
  70746. const float dy) throw()
  70747. {
  70748. return AffineTransform (1.0f, 0, dx,
  70749. 0, 1.0f, dy);
  70750. }
  70751. const AffineTransform AffineTransform::rotated (const float rad) const throw()
  70752. {
  70753. const float cosRad = cosf (rad);
  70754. const float sinRad = sinf (rad);
  70755. return followedBy (cosRad, -sinRad, 0,
  70756. sinRad, cosRad, 0);
  70757. }
  70758. const AffineTransform AffineTransform::rotation (const float rad) throw()
  70759. {
  70760. const float cosRad = cosf (rad);
  70761. const float sinRad = sinf (rad);
  70762. return AffineTransform (cosRad, -sinRad, 0,
  70763. sinRad, cosRad, 0);
  70764. }
  70765. const AffineTransform AffineTransform::rotated (const float angle,
  70766. const float pivotX,
  70767. const float pivotY) const throw()
  70768. {
  70769. return translated (-pivotX, -pivotY)
  70770. .rotated (angle)
  70771. .translated (pivotX, pivotY);
  70772. }
  70773. const AffineTransform AffineTransform::rotation (const float angle,
  70774. const float pivotX,
  70775. const float pivotY) throw()
  70776. {
  70777. return translation (-pivotX, -pivotY)
  70778. .rotated (angle)
  70779. .translated (pivotX, pivotY);
  70780. }
  70781. const AffineTransform AffineTransform::scaled (const float factorX,
  70782. const float factorY) const throw()
  70783. {
  70784. return AffineTransform (factorX * mat00, factorX * mat01, factorX * mat02,
  70785. factorY * mat10, factorY * mat11, factorY * mat12);
  70786. }
  70787. const AffineTransform AffineTransform::scale (const float factorX,
  70788. const float factorY) throw()
  70789. {
  70790. return AffineTransform (factorX, 0, 0,
  70791. 0, factorY, 0);
  70792. }
  70793. const AffineTransform AffineTransform::sheared (const float shearX,
  70794. const float shearY) const throw()
  70795. {
  70796. return followedBy (1.0f, shearX, 0,
  70797. shearY, 1.0f, 0);
  70798. }
  70799. const AffineTransform AffineTransform::inverted() const throw()
  70800. {
  70801. double determinant = (mat00 * mat11 - mat10 * mat01);
  70802. if (determinant != 0.0)
  70803. {
  70804. determinant = 1.0 / determinant;
  70805. const float dst00 = (float) (mat11 * determinant);
  70806. const float dst10 = (float) (-mat10 * determinant);
  70807. const float dst01 = (float) (-mat01 * determinant);
  70808. const float dst11 = (float) (mat00 * determinant);
  70809. return AffineTransform (dst00, dst01, -mat02 * dst00 - mat12 * dst01,
  70810. dst10, dst11, -mat02 * dst10 - mat12 * dst11);
  70811. }
  70812. else
  70813. {
  70814. // singularity..
  70815. return *this;
  70816. }
  70817. }
  70818. bool AffineTransform::isSingularity() const throw()
  70819. {
  70820. return (mat00 * mat11 - mat10 * mat01) == 0.0;
  70821. }
  70822. bool AffineTransform::isOnlyTranslation() const throw()
  70823. {
  70824. return (mat01 == 0)
  70825. && (mat10 == 0)
  70826. && (mat00 == 1.0f)
  70827. && (mat11 == 1.0f);
  70828. }
  70829. void AffineTransform::transformPoint (float& x,
  70830. float& y) const throw()
  70831. {
  70832. const float oldX = x;
  70833. x = mat00 * oldX + mat01 * y + mat02;
  70834. y = mat10 * oldX + mat11 * y + mat12;
  70835. }
  70836. void AffineTransform::transformPoint (double& x,
  70837. double& y) const throw()
  70838. {
  70839. const double oldX = x;
  70840. x = mat00 * oldX + mat01 * y + mat02;
  70841. y = mat10 * oldX + mat11 * y + mat12;
  70842. }
  70843. END_JUCE_NAMESPACE
  70844. /********* End of inlined file: juce_AffineTransform.cpp *********/
  70845. /********* Start of inlined file: juce_BorderSize.cpp *********/
  70846. BEGIN_JUCE_NAMESPACE
  70847. BorderSize::BorderSize() throw()
  70848. : top (0),
  70849. left (0),
  70850. bottom (0),
  70851. right (0)
  70852. {
  70853. }
  70854. BorderSize::BorderSize (const BorderSize& other) throw()
  70855. : top (other.top),
  70856. left (other.left),
  70857. bottom (other.bottom),
  70858. right (other.right)
  70859. {
  70860. }
  70861. BorderSize::BorderSize (const int topGap,
  70862. const int leftGap,
  70863. const int bottomGap,
  70864. const int rightGap) throw()
  70865. : top (topGap),
  70866. left (leftGap),
  70867. bottom (bottomGap),
  70868. right (rightGap)
  70869. {
  70870. }
  70871. BorderSize::BorderSize (const int allGaps) throw()
  70872. : top (allGaps),
  70873. left (allGaps),
  70874. bottom (allGaps),
  70875. right (allGaps)
  70876. {
  70877. }
  70878. BorderSize::~BorderSize() throw()
  70879. {
  70880. }
  70881. void BorderSize::setTop (const int newTopGap) throw()
  70882. {
  70883. top = newTopGap;
  70884. }
  70885. void BorderSize::setLeft (const int newLeftGap) throw()
  70886. {
  70887. left = newLeftGap;
  70888. }
  70889. void BorderSize::setBottom (const int newBottomGap) throw()
  70890. {
  70891. bottom = newBottomGap;
  70892. }
  70893. void BorderSize::setRight (const int newRightGap) throw()
  70894. {
  70895. right = newRightGap;
  70896. }
  70897. const Rectangle BorderSize::subtractedFrom (const Rectangle& r) const throw()
  70898. {
  70899. return Rectangle (r.getX() + left,
  70900. r.getY() + top,
  70901. r.getWidth() - (left + right),
  70902. r.getHeight() - (top + bottom));
  70903. }
  70904. void BorderSize::subtractFrom (Rectangle& r) const throw()
  70905. {
  70906. r.setBounds (r.getX() + left,
  70907. r.getY() + top,
  70908. r.getWidth() - (left + right),
  70909. r.getHeight() - (top + bottom));
  70910. }
  70911. const Rectangle BorderSize::addedTo (const Rectangle& r) const throw()
  70912. {
  70913. return Rectangle (r.getX() - left,
  70914. r.getY() - top,
  70915. r.getWidth() + (left + right),
  70916. r.getHeight() + (top + bottom));
  70917. }
  70918. void BorderSize::addTo (Rectangle& r) const throw()
  70919. {
  70920. r.setBounds (r.getX() - left,
  70921. r.getY() - top,
  70922. r.getWidth() + (left + right),
  70923. r.getHeight() + (top + bottom));
  70924. }
  70925. bool BorderSize::operator== (const BorderSize& other) const throw()
  70926. {
  70927. return top == other.top
  70928. && left == other.left
  70929. && bottom == other.bottom
  70930. && right == other.right;
  70931. }
  70932. bool BorderSize::operator!= (const BorderSize& other) const throw()
  70933. {
  70934. return ! operator== (other);
  70935. }
  70936. END_JUCE_NAMESPACE
  70937. /********* End of inlined file: juce_BorderSize.cpp *********/
  70938. /********* Start of inlined file: juce_Line.cpp *********/
  70939. BEGIN_JUCE_NAMESPACE
  70940. static bool juce_lineIntersection (const float x1, const float y1,
  70941. const float x2, const float y2,
  70942. const float x3, const float y3,
  70943. const float x4, const float y4,
  70944. float& intersectionX,
  70945. float& intersectionY) throw()
  70946. {
  70947. if (x2 != x3 || y2 != y3)
  70948. {
  70949. const float dx1 = x2 - x1;
  70950. const float dy1 = y2 - y1;
  70951. const float dx2 = x4 - x3;
  70952. const float dy2 = y4 - y3;
  70953. const float divisor = dx1 * dy2 - dx2 * dy1;
  70954. if (divisor == 0)
  70955. {
  70956. if (! ((dx1 == 0 && dy1 == 0) || (dx2 == 0 && dy2 == 0)))
  70957. {
  70958. if (dy1 == 0 && dy2 != 0)
  70959. {
  70960. const float along = (y1 - y3) / dy2;
  70961. intersectionX = x3 + along * dx2;
  70962. intersectionY = y1;
  70963. return along >= 0 && along <= 1.0f;
  70964. }
  70965. else if (dy2 == 0 && dy1 != 0)
  70966. {
  70967. const float along = (y3 - y1) / dy1;
  70968. intersectionX = x1 + along * dx1;
  70969. intersectionY = y3;
  70970. return along >= 0 && along <= 1.0f;
  70971. }
  70972. else if (dx1 == 0 && dx2 != 0)
  70973. {
  70974. const float along = (x1 - x3) / dx2;
  70975. intersectionX = x1;
  70976. intersectionY = y3 + along * dy2;
  70977. return along >= 0 && along <= 1.0f;
  70978. }
  70979. else if (dx2 == 0 && dx1 != 0)
  70980. {
  70981. const float along = (x3 - x1) / dx1;
  70982. intersectionX = x3;
  70983. intersectionY = y1 + along * dy1;
  70984. return along >= 0 && along <= 1.0f;
  70985. }
  70986. }
  70987. intersectionX = 0.5f * (x2 + x3);
  70988. intersectionY = 0.5f * (y2 + y3);
  70989. return false;
  70990. }
  70991. const float along1 = ((y1 - y3) * dx2 - (x1 - x3) * dy2) / divisor;
  70992. intersectionX = x1 + along1 * dx1;
  70993. intersectionY = y1 + along1 * dy1;
  70994. if (along1 < 0 || along1 > 1.0f)
  70995. return false;
  70996. const float along2 = ((y1 - y3) * dx1 - (x1 - x3) * dy1) / divisor;
  70997. return along2 >= 0 && along2 <= 1.0f;
  70998. }
  70999. intersectionX = x2;
  71000. intersectionY = y2;
  71001. return true;
  71002. }
  71003. Line::Line() throw()
  71004. : startX (0.0f),
  71005. startY (0.0f),
  71006. endX (0.0f),
  71007. endY (0.0f)
  71008. {
  71009. }
  71010. Line::Line (const Line& other) throw()
  71011. : startX (other.startX),
  71012. startY (other.startY),
  71013. endX (other.endX),
  71014. endY (other.endY)
  71015. {
  71016. }
  71017. Line::Line (const float startX_, const float startY_,
  71018. const float endX_, const float endY_) throw()
  71019. : startX (startX_),
  71020. startY (startY_),
  71021. endX (endX_),
  71022. endY (endY_)
  71023. {
  71024. }
  71025. Line::Line (const Point& start,
  71026. const Point& end) throw()
  71027. : startX (start.getX()),
  71028. startY (start.getY()),
  71029. endX (end.getX()),
  71030. endY (end.getY())
  71031. {
  71032. }
  71033. const Line& Line::operator= (const Line& other) throw()
  71034. {
  71035. startX = other.startX;
  71036. startY = other.startY;
  71037. endX = other.endX;
  71038. endY = other.endY;
  71039. return *this;
  71040. }
  71041. Line::~Line() throw()
  71042. {
  71043. }
  71044. const Point Line::getStart() const throw()
  71045. {
  71046. return Point (startX, startY);
  71047. }
  71048. const Point Line::getEnd() const throw()
  71049. {
  71050. return Point (endX, endY);
  71051. }
  71052. void Line::setStart (const float newStartX,
  71053. const float newStartY) throw()
  71054. {
  71055. startX = newStartX;
  71056. startY = newStartY;
  71057. }
  71058. void Line::setStart (const Point& newStart) throw()
  71059. {
  71060. startX = newStart.getX();
  71061. startY = newStart.getY();
  71062. }
  71063. void Line::setEnd (const float newEndX,
  71064. const float newEndY) throw()
  71065. {
  71066. endX = newEndX;
  71067. endY = newEndY;
  71068. }
  71069. void Line::setEnd (const Point& newEnd) throw()
  71070. {
  71071. endX = newEnd.getX();
  71072. endY = newEnd.getY();
  71073. }
  71074. bool Line::operator== (const Line& other) const throw()
  71075. {
  71076. return startX == other.startX
  71077. && startY == other.startY
  71078. && endX == other.endX
  71079. && endY == other.endY;
  71080. }
  71081. bool Line::operator!= (const Line& other) const throw()
  71082. {
  71083. return startX != other.startX
  71084. || startY != other.startY
  71085. || endX != other.endX
  71086. || endY != other.endY;
  71087. }
  71088. void Line::applyTransform (const AffineTransform& transform) throw()
  71089. {
  71090. transform.transformPoint (startX, startY);
  71091. transform.transformPoint (endX, endY);
  71092. }
  71093. float Line::getLength() const throw()
  71094. {
  71095. return (float) juce_hypot (startX - endX,
  71096. startY - endY);
  71097. }
  71098. float Line::getAngle() const throw()
  71099. {
  71100. return atan2f (endX - startX,
  71101. endY - startY);
  71102. }
  71103. const Point Line::getPointAlongLine (const float distanceFromStart) const throw()
  71104. {
  71105. const float alpha = distanceFromStart / getLength();
  71106. return Point (startX + (endX - startX) * alpha,
  71107. startY + (endY - startY) * alpha);
  71108. }
  71109. const Point Line::getPointAlongLine (const float offsetX,
  71110. const float offsetY) const throw()
  71111. {
  71112. const float dx = endX - startX;
  71113. const float dy = endY - startY;
  71114. const double length = juce_hypot (dx, dy);
  71115. if (length == 0)
  71116. return Point (startX, startY);
  71117. else
  71118. return Point (startX + (float) (((dx * offsetX) - (dy * offsetY)) / length),
  71119. startY + (float) (((dy * offsetX) + (dx * offsetY)) / length));
  71120. }
  71121. const Point Line::getPointAlongLineProportionally (const float alpha) const throw()
  71122. {
  71123. return Point (startX + (endX - startX) * alpha,
  71124. startY + (endY - startY) * alpha);
  71125. }
  71126. float Line::getDistanceFromLine (const float x,
  71127. const float y) const throw()
  71128. {
  71129. const double dx = endX - startX;
  71130. const double dy = endY - startY;
  71131. const double length = dx * dx + dy * dy;
  71132. if (length > 0)
  71133. {
  71134. const double prop = ((x - startX) * dx + (y - startY) * dy) / length;
  71135. if (prop >= 0.0f && prop < 1.0f)
  71136. {
  71137. return (float) juce_hypot (x - (startX + prop * dx),
  71138. y - (startY + prop * dy));
  71139. }
  71140. }
  71141. return (float) jmin (juce_hypot (x - startX, y - startY),
  71142. juce_hypot (x - endX, y - endY));
  71143. }
  71144. float Line::findNearestPointTo (const float x,
  71145. const float y) const throw()
  71146. {
  71147. const double dx = endX - startX;
  71148. const double dy = endY - startY;
  71149. const double length = dx * dx + dy * dy;
  71150. if (length <= 0.0)
  71151. return 0.0f;
  71152. return jlimit (0.0f, 1.0f,
  71153. (float) (((x - startX) * dx + (y - startY) * dy) / length));
  71154. }
  71155. const Line Line::withShortenedStart (const float distanceToShortenBy) const throw()
  71156. {
  71157. const float length = getLength();
  71158. return Line (getPointAlongLine (jmin (distanceToShortenBy, length)),
  71159. getEnd());
  71160. }
  71161. const Line Line::withShortenedEnd (const float distanceToShortenBy) const throw()
  71162. {
  71163. const float length = getLength();
  71164. return Line (getStart(),
  71165. getPointAlongLine (length - jmin (distanceToShortenBy, length)));
  71166. }
  71167. bool Line::clipToPath (const Path& path,
  71168. const bool keepSectionOutsidePath) throw()
  71169. {
  71170. const bool startInside = path.contains (startX, startY);
  71171. const bool endInside = path.contains (endX, endY);
  71172. if (startInside == endInside)
  71173. {
  71174. if (keepSectionOutsidePath != startInside)
  71175. {
  71176. // entirely outside the path
  71177. return false;
  71178. }
  71179. else
  71180. {
  71181. // entirely inside the path
  71182. startX = 0.0f;
  71183. startY = 0.0f;
  71184. endX = 0.0f;
  71185. endY = 0.0f;
  71186. return true;
  71187. }
  71188. }
  71189. else
  71190. {
  71191. bool changed = false;
  71192. PathFlatteningIterator iter (path, AffineTransform::identity);
  71193. while (iter.next())
  71194. {
  71195. float ix, iy;
  71196. if (intersects (Line (iter.x1, iter.y1,
  71197. iter.x2, iter.y2),
  71198. ix, iy))
  71199. {
  71200. if ((startInside && keepSectionOutsidePath)
  71201. || (endInside && ! keepSectionOutsidePath))
  71202. {
  71203. setStart (ix, iy);
  71204. }
  71205. else
  71206. {
  71207. setEnd (ix, iy);
  71208. }
  71209. changed = true;
  71210. }
  71211. }
  71212. return changed;
  71213. }
  71214. }
  71215. bool Line::intersects (const Line& line,
  71216. float& intersectionX,
  71217. float& intersectionY) const throw()
  71218. {
  71219. return juce_lineIntersection (startX, startY,
  71220. endX, endY,
  71221. line.startX, line.startY,
  71222. line.endX, line.endY,
  71223. intersectionX,
  71224. intersectionY);
  71225. }
  71226. bool Line::isVertical() const throw()
  71227. {
  71228. return startX == endX;
  71229. }
  71230. bool Line::isHorizontal() const throw()
  71231. {
  71232. return startY == endY;
  71233. }
  71234. bool Line::isPointAbove (const float x, const float y) const throw()
  71235. {
  71236. return startX != endX
  71237. && y < ((endY - startY) * (x - startX)) / (endX - startX) + startY;
  71238. }
  71239. END_JUCE_NAMESPACE
  71240. /********* End of inlined file: juce_Line.cpp *********/
  71241. /********* Start of inlined file: juce_Path.cpp *********/
  71242. BEGIN_JUCE_NAMESPACE
  71243. // tests that some co-ords aren't NaNs
  71244. #define CHECK_COORDS_ARE_VALID(x, y) \
  71245. jassert (x == x && y == y);
  71246. const float Path::lineMarker = 100001.0f;
  71247. const float Path::moveMarker = 100002.0f;
  71248. const float Path::quadMarker = 100003.0f;
  71249. const float Path::cubicMarker = 100004.0f;
  71250. const float Path::closeSubPathMarker = 100005.0f;
  71251. static const int defaultGranularity = 32;
  71252. Path::Path() throw()
  71253. : numElements (0),
  71254. pathXMin (0),
  71255. pathXMax (0),
  71256. pathYMin (0),
  71257. pathYMax (0),
  71258. useNonZeroWinding (true)
  71259. {
  71260. }
  71261. Path::~Path() throw()
  71262. {
  71263. }
  71264. Path::Path (const Path& other) throw()
  71265. : numElements (other.numElements),
  71266. pathXMin (other.pathXMin),
  71267. pathXMax (other.pathXMax),
  71268. pathYMin (other.pathYMin),
  71269. pathYMax (other.pathYMax),
  71270. useNonZeroWinding (other.useNonZeroWinding)
  71271. {
  71272. if (numElements > 0)
  71273. {
  71274. data.setAllocatedSize (numElements);
  71275. memcpy (data.elements, other.data.elements, numElements * sizeof (float));
  71276. }
  71277. }
  71278. const Path& Path::operator= (const Path& other) throw()
  71279. {
  71280. if (this != &other)
  71281. {
  71282. data.ensureAllocatedSize (other.numElements);
  71283. numElements = other.numElements;
  71284. pathXMin = other.pathXMin;
  71285. pathXMax = other.pathXMax;
  71286. pathYMin = other.pathYMin;
  71287. pathYMax = other.pathYMax;
  71288. useNonZeroWinding = other.useNonZeroWinding;
  71289. if (numElements > 0)
  71290. memcpy (data.elements, other.data.elements, numElements * sizeof (float));
  71291. }
  71292. return *this;
  71293. }
  71294. void Path::clear() throw()
  71295. {
  71296. numElements = 0;
  71297. pathXMin = 0;
  71298. pathYMin = 0;
  71299. pathYMax = 0;
  71300. pathXMax = 0;
  71301. }
  71302. void Path::swapWithPath (Path& other)
  71303. {
  71304. data.swapWith (other.data);
  71305. swapVariables <int> (numElements, other.numElements);
  71306. swapVariables <float> (pathXMin, other.pathXMin);
  71307. swapVariables <float> (pathXMax, other.pathXMax);
  71308. swapVariables <float> (pathYMin, other.pathYMin);
  71309. swapVariables <float> (pathYMax, other.pathYMax);
  71310. swapVariables <bool> (useNonZeroWinding, other.useNonZeroWinding);
  71311. }
  71312. void Path::setUsingNonZeroWinding (const bool isNonZero) throw()
  71313. {
  71314. useNonZeroWinding = isNonZero;
  71315. }
  71316. void Path::scaleToFit (const float x, const float y, const float w, const float h,
  71317. const bool preserveProportions) throw()
  71318. {
  71319. applyTransform (getTransformToScaleToFit (x, y, w, h, preserveProportions));
  71320. }
  71321. bool Path::isEmpty() const throw()
  71322. {
  71323. int i = 0;
  71324. while (i < numElements)
  71325. {
  71326. const float type = data.elements [i++];
  71327. if (type == moveMarker)
  71328. {
  71329. i += 2;
  71330. }
  71331. else if (type == lineMarker
  71332. || type == quadMarker
  71333. || type == cubicMarker)
  71334. {
  71335. return false;
  71336. }
  71337. }
  71338. return true;
  71339. }
  71340. void Path::getBounds (float& x, float& y,
  71341. float& w, float& h) const throw()
  71342. {
  71343. x = pathXMin;
  71344. y = pathYMin;
  71345. w = pathXMax - pathXMin;
  71346. h = pathYMax - pathYMin;
  71347. }
  71348. void Path::getBoundsTransformed (const AffineTransform& transform,
  71349. float& x, float& y,
  71350. float& w, float& h) const throw()
  71351. {
  71352. float x1 = pathXMin;
  71353. float y1 = pathYMin;
  71354. transform.transformPoint (x1, y1);
  71355. float x2 = pathXMax;
  71356. float y2 = pathYMin;
  71357. transform.transformPoint (x2, y2);
  71358. float x3 = pathXMin;
  71359. float y3 = pathYMax;
  71360. transform.transformPoint (x3, y3);
  71361. float x4 = pathXMax;
  71362. float y4 = pathYMax;
  71363. transform.transformPoint (x4, y4);
  71364. x = jmin (x1, x2, x3, x4);
  71365. y = jmin (y1, y2, y3, y4);
  71366. w = jmax (x1, x2, x3, x4) - x;
  71367. h = jmax (y1, y2, y3, y4) - y;
  71368. }
  71369. void Path::startNewSubPath (const float x,
  71370. const float y) throw()
  71371. {
  71372. CHECK_COORDS_ARE_VALID (x, y);
  71373. if (numElements == 0)
  71374. {
  71375. pathXMin = pathXMax = x;
  71376. pathYMin = pathYMax = y;
  71377. }
  71378. else
  71379. {
  71380. pathXMin = jmin (pathXMin, x);
  71381. pathXMax = jmax (pathXMax, x);
  71382. pathYMin = jmin (pathYMin, y);
  71383. pathYMax = jmax (pathYMax, y);
  71384. }
  71385. data.ensureAllocatedSize (numElements + 3);
  71386. data.elements [numElements++] = moveMarker;
  71387. data.elements [numElements++] = x;
  71388. data.elements [numElements++] = y;
  71389. }
  71390. void Path::lineTo (const float x, const float y) throw()
  71391. {
  71392. CHECK_COORDS_ARE_VALID (x, y);
  71393. if (numElements == 0)
  71394. startNewSubPath (0, 0);
  71395. data.ensureAllocatedSize (numElements + 3);
  71396. data.elements [numElements++] = lineMarker;
  71397. data.elements [numElements++] = x;
  71398. data.elements [numElements++] = y;
  71399. pathXMin = jmin (pathXMin, x);
  71400. pathXMax = jmax (pathXMax, x);
  71401. pathYMin = jmin (pathYMin, y);
  71402. pathYMax = jmax (pathYMax, y);
  71403. }
  71404. void Path::quadraticTo (const float x1, const float y1,
  71405. const float x2, const float y2) throw()
  71406. {
  71407. CHECK_COORDS_ARE_VALID (x1, y1);
  71408. CHECK_COORDS_ARE_VALID (x2, y2);
  71409. if (numElements == 0)
  71410. startNewSubPath (0, 0);
  71411. data.ensureAllocatedSize (numElements + 5);
  71412. data.elements [numElements++] = quadMarker;
  71413. data.elements [numElements++] = x1;
  71414. data.elements [numElements++] = y1;
  71415. data.elements [numElements++] = x2;
  71416. data.elements [numElements++] = y2;
  71417. pathXMin = jmin (pathXMin, x1, x2);
  71418. pathXMax = jmax (pathXMax, x1, x2);
  71419. pathYMin = jmin (pathYMin, y1, y2);
  71420. pathYMax = jmax (pathYMax, y1, y2);
  71421. }
  71422. void Path::cubicTo (const float x1, const float y1,
  71423. const float x2, const float y2,
  71424. const float x3, const float y3) throw()
  71425. {
  71426. CHECK_COORDS_ARE_VALID (x1, y1);
  71427. CHECK_COORDS_ARE_VALID (x2, y2);
  71428. CHECK_COORDS_ARE_VALID (x3, y3);
  71429. if (numElements == 0)
  71430. startNewSubPath (0, 0);
  71431. data.ensureAllocatedSize (numElements + 7);
  71432. data.elements [numElements++] = cubicMarker;
  71433. data.elements [numElements++] = x1;
  71434. data.elements [numElements++] = y1;
  71435. data.elements [numElements++] = x2;
  71436. data.elements [numElements++] = y2;
  71437. data.elements [numElements++] = x3;
  71438. data.elements [numElements++] = y3;
  71439. pathXMin = jmin (pathXMin, x1, x2, x3);
  71440. pathXMax = jmax (pathXMax, x1, x2, x3);
  71441. pathYMin = jmin (pathYMin, y1, y2, y3);
  71442. pathYMax = jmax (pathYMax, y1, y2, y3);
  71443. }
  71444. void Path::closeSubPath() throw()
  71445. {
  71446. if (numElements > 0
  71447. && data.elements [numElements - 1] != closeSubPathMarker)
  71448. {
  71449. data.ensureAllocatedSize (numElements + 1);
  71450. data.elements [numElements++] = closeSubPathMarker;
  71451. }
  71452. }
  71453. const Point Path::getCurrentPosition() const
  71454. {
  71455. int i = numElements - 1;
  71456. if (i > 0 && data.elements[i] == closeSubPathMarker)
  71457. {
  71458. while (i >= 0)
  71459. {
  71460. if (data.elements[i] == moveMarker)
  71461. {
  71462. i += 2;
  71463. break;
  71464. }
  71465. --i;
  71466. }
  71467. }
  71468. if (i > 0)
  71469. return Point (data.elements [i - 1], data.elements [i]);
  71470. return Point (0.0f, 0.0f);
  71471. }
  71472. void Path::addRectangle (const float x, const float y,
  71473. const float w, const float h) throw()
  71474. {
  71475. float x1 = x, y1 = y, x2 = x + w, y2 = y + h;
  71476. if (w < 0)
  71477. swapVariables (x1, x2);
  71478. if (h < 0)
  71479. swapVariables (y1, y2);
  71480. data.ensureAllocatedSize (numElements + 13);
  71481. if (numElements == 0)
  71482. {
  71483. pathXMin = x1;
  71484. pathXMax = x2;
  71485. pathYMin = y1;
  71486. pathYMax = y2;
  71487. }
  71488. else
  71489. {
  71490. pathXMin = jmin (pathXMin, x1);
  71491. pathXMax = jmax (pathXMax, x2);
  71492. pathYMin = jmin (pathYMin, y1);
  71493. pathYMax = jmax (pathYMax, y2);
  71494. }
  71495. data.elements [numElements++] = moveMarker;
  71496. data.elements [numElements++] = x1;
  71497. data.elements [numElements++] = y2;
  71498. data.elements [numElements++] = lineMarker;
  71499. data.elements [numElements++] = x1;
  71500. data.elements [numElements++] = y1;
  71501. data.elements [numElements++] = lineMarker;
  71502. data.elements [numElements++] = x2;
  71503. data.elements [numElements++] = y1;
  71504. data.elements [numElements++] = lineMarker;
  71505. data.elements [numElements++] = x2;
  71506. data.elements [numElements++] = y2;
  71507. data.elements [numElements++] = closeSubPathMarker;
  71508. }
  71509. void Path::addRectangle (const Rectangle& rectangle) throw()
  71510. {
  71511. addRectangle ((float) rectangle.getX(), (float) rectangle.getY(),
  71512. (float) rectangle.getWidth(), (float) rectangle.getHeight());
  71513. }
  71514. void Path::addRoundedRectangle (const float x, const float y,
  71515. const float w, const float h,
  71516. float csx,
  71517. float csy) throw()
  71518. {
  71519. csx = jmin (csx, w * 0.5f);
  71520. csy = jmin (csy, h * 0.5f);
  71521. const float cs45x = csx * 0.45f;
  71522. const float cs45y = csy * 0.45f;
  71523. const float x2 = x + w;
  71524. const float y2 = y + h;
  71525. startNewSubPath (x + csx, y);
  71526. lineTo (x2 - csx, y);
  71527. cubicTo (x2 - cs45x, y, x2, y + cs45y, x2, y + csy);
  71528. lineTo (x2, y2 - csy);
  71529. cubicTo (x2, y2 - cs45y, x2 - cs45x, y2, x2 - csx, y2);
  71530. lineTo (x + csx, y2);
  71531. cubicTo (x + cs45x, y2, x, y2 - cs45y, x, y2 - csy);
  71532. lineTo (x, y + csy);
  71533. cubicTo (x, y + cs45y, x + cs45x, y, x + csx, y);
  71534. closeSubPath();
  71535. }
  71536. void Path::addRoundedRectangle (const float x, const float y,
  71537. const float w, const float h,
  71538. float cs) throw()
  71539. {
  71540. addRoundedRectangle (x, y, w, h, cs, cs);
  71541. }
  71542. void Path::addTriangle (const float x1, const float y1,
  71543. const float x2, const float y2,
  71544. const float x3, const float y3) throw()
  71545. {
  71546. startNewSubPath (x1, y1);
  71547. lineTo (x2, y2);
  71548. lineTo (x3, y3);
  71549. closeSubPath();
  71550. }
  71551. void Path::addQuadrilateral (const float x1, const float y1,
  71552. const float x2, const float y2,
  71553. const float x3, const float y3,
  71554. const float x4, const float y4) throw()
  71555. {
  71556. startNewSubPath (x1, y1);
  71557. lineTo (x2, y2);
  71558. lineTo (x3, y3);
  71559. lineTo (x4, y4);
  71560. closeSubPath();
  71561. }
  71562. void Path::addEllipse (const float x, const float y,
  71563. const float w, const float h) throw()
  71564. {
  71565. const float hw = w * 0.5f;
  71566. const float hw55 = hw * 0.55f;
  71567. const float hh = h * 0.5f;
  71568. const float hh45 = hh * 0.55f;
  71569. const float cx = x + hw;
  71570. const float cy = y + hh;
  71571. startNewSubPath (cx, cy - hh);
  71572. cubicTo (cx + hw55, cy - hh, cx + hw, cy - hh45, cx + hw, cy);
  71573. cubicTo (cx + hw, cy + hh45, cx + hw55, cy + hh, cx, cy + hh);
  71574. cubicTo (cx - hw55, cy + hh, cx - hw, cy + hh45, cx - hw, cy);
  71575. cubicTo (cx - hw, cy - hh45, cx - hw55, cy - hh, cx, cy - hh);
  71576. closeSubPath();
  71577. }
  71578. void Path::addArc (const float x, const float y,
  71579. const float w, const float h,
  71580. const float fromRadians,
  71581. const float toRadians,
  71582. const bool startAsNewSubPath) throw()
  71583. {
  71584. const float radiusX = w / 2.0f;
  71585. const float radiusY = h / 2.0f;
  71586. addCentredArc (x + radiusX,
  71587. y + radiusY,
  71588. radiusX, radiusY,
  71589. 0.0f,
  71590. fromRadians, toRadians,
  71591. startAsNewSubPath);
  71592. }
  71593. static const float ellipseAngularIncrement = 0.05f;
  71594. void Path::addCentredArc (const float centreX, const float centreY,
  71595. const float radiusX, const float radiusY,
  71596. const float rotationOfEllipse,
  71597. const float fromRadians,
  71598. const float toRadians,
  71599. const bool startAsNewSubPath) throw()
  71600. {
  71601. if (radiusX > 0.0f && radiusY > 0.0f)
  71602. {
  71603. const AffineTransform rotation (AffineTransform::rotation (rotationOfEllipse, centreX, centreY));
  71604. float angle = fromRadians;
  71605. if (startAsNewSubPath)
  71606. {
  71607. float x = centreX + radiusX * sinf (angle);
  71608. float y = centreY - radiusY * cosf (angle);
  71609. if (rotationOfEllipse != 0)
  71610. rotation.transformPoint (x, y);
  71611. startNewSubPath (x, y);
  71612. }
  71613. if (fromRadians < toRadians)
  71614. {
  71615. if (startAsNewSubPath)
  71616. angle += ellipseAngularIncrement;
  71617. while (angle < toRadians)
  71618. {
  71619. float x = centreX + radiusX * sinf (angle);
  71620. float y = centreY - radiusY * cosf (angle);
  71621. if (rotationOfEllipse != 0)
  71622. rotation.transformPoint (x, y);
  71623. lineTo (x, y);
  71624. angle += ellipseAngularIncrement;
  71625. }
  71626. }
  71627. else
  71628. {
  71629. if (startAsNewSubPath)
  71630. angle -= ellipseAngularIncrement;
  71631. while (angle > toRadians)
  71632. {
  71633. float x = centreX + radiusX * sinf (angle);
  71634. float y = centreY - radiusY * cosf (angle);
  71635. if (rotationOfEllipse != 0)
  71636. rotation.transformPoint (x, y);
  71637. lineTo (x, y);
  71638. angle -= ellipseAngularIncrement;
  71639. }
  71640. }
  71641. float x = centreX + radiusX * sinf (toRadians);
  71642. float y = centreY - radiusY * cosf (toRadians);
  71643. if (rotationOfEllipse != 0)
  71644. rotation.transformPoint (x, y);
  71645. lineTo (x, y);
  71646. }
  71647. }
  71648. void Path::addPieSegment (const float x, const float y,
  71649. const float width, const float height,
  71650. const float fromRadians,
  71651. const float toRadians,
  71652. const float innerCircleProportionalSize)
  71653. {
  71654. float hw = width * 0.5f;
  71655. float hh = height * 0.5f;
  71656. const float centreX = x + hw;
  71657. const float centreY = y + hh;
  71658. startNewSubPath (centreX + hw * sinf (fromRadians),
  71659. centreY - hh * cosf (fromRadians));
  71660. addArc (x, y, width, height, fromRadians, toRadians);
  71661. if (fabs (fromRadians - toRadians) > float_Pi * 1.999f)
  71662. {
  71663. closeSubPath();
  71664. if (innerCircleProportionalSize > 0)
  71665. {
  71666. hw *= innerCircleProportionalSize;
  71667. hh *= innerCircleProportionalSize;
  71668. startNewSubPath (centreX + hw * sinf (toRadians),
  71669. centreY - hh * cosf (toRadians));
  71670. addArc (centreX - hw, centreY - hh, hw * 2.0f, hh * 2.0f,
  71671. toRadians, fromRadians);
  71672. }
  71673. }
  71674. else
  71675. {
  71676. if (innerCircleProportionalSize > 0)
  71677. {
  71678. hw *= innerCircleProportionalSize;
  71679. hh *= innerCircleProportionalSize;
  71680. addArc (centreX - hw, centreY - hh, hw * 2.0f, hh * 2.0f,
  71681. toRadians, fromRadians);
  71682. }
  71683. else
  71684. {
  71685. lineTo (centreX, centreY);
  71686. }
  71687. }
  71688. closeSubPath();
  71689. }
  71690. static void perpendicularOffset (const float x1, const float y1,
  71691. const float x2, const float y2,
  71692. const float offsetX, const float offsetY,
  71693. float& resultX, float& resultY) throw()
  71694. {
  71695. const float dx = x2 - x1;
  71696. const float dy = y2 - y1;
  71697. const float len = juce_hypotf (dx, dy);
  71698. if (len == 0)
  71699. {
  71700. resultX = x1;
  71701. resultY = y1;
  71702. }
  71703. else
  71704. {
  71705. resultX = x1 + ((dx * offsetX) - (dy * offsetY)) / len;
  71706. resultY = y1 + ((dy * offsetX) + (dx * offsetY)) / len;
  71707. }
  71708. }
  71709. void Path::addLineSegment (const float startX, const float startY,
  71710. const float endX, const float endY,
  71711. float lineThickness) throw()
  71712. {
  71713. lineThickness *= 0.5f;
  71714. float x, y;
  71715. perpendicularOffset (startX, startY, endX, endY,
  71716. 0, lineThickness, x, y);
  71717. startNewSubPath (x, y);
  71718. perpendicularOffset (startX, startY, endX, endY,
  71719. 0, -lineThickness, x, y);
  71720. lineTo (x, y);
  71721. perpendicularOffset (endX, endY, startX, startY,
  71722. 0, lineThickness, x, y);
  71723. lineTo (x, y);
  71724. perpendicularOffset (endX, endY, startX, startY,
  71725. 0, -lineThickness, x, y);
  71726. lineTo (x, y);
  71727. closeSubPath();
  71728. }
  71729. void Path::addArrow (const float startX, const float startY,
  71730. const float endX, const float endY,
  71731. float lineThickness,
  71732. float arrowheadWidth,
  71733. float arrowheadLength) throw()
  71734. {
  71735. lineThickness *= 0.5f;
  71736. arrowheadWidth *= 0.5f;
  71737. arrowheadLength = jmin (arrowheadLength, 0.8f * juce_hypotf (startX - endX,
  71738. startY - endY));
  71739. float x, y;
  71740. perpendicularOffset (startX, startY, endX, endY,
  71741. 0, lineThickness, x, y);
  71742. startNewSubPath (x, y);
  71743. perpendicularOffset (startX, startY, endX, endY,
  71744. 0, -lineThickness, x, y);
  71745. lineTo (x, y);
  71746. perpendicularOffset (endX, endY, startX, startY,
  71747. arrowheadLength, lineThickness, x, y);
  71748. lineTo (x, y);
  71749. perpendicularOffset (endX, endY, startX, startY,
  71750. arrowheadLength, arrowheadWidth, x, y);
  71751. lineTo (x, y);
  71752. perpendicularOffset (endX, endY, startX, startY,
  71753. 0, 0, x, y);
  71754. lineTo (x, y);
  71755. perpendicularOffset (endX, endY, startX, startY,
  71756. arrowheadLength, -arrowheadWidth, x, y);
  71757. lineTo (x, y);
  71758. perpendicularOffset (endX, endY, startX, startY,
  71759. arrowheadLength, -lineThickness, x, y);
  71760. lineTo (x, y);
  71761. closeSubPath();
  71762. }
  71763. void Path::addStar (const float centreX,
  71764. const float centreY,
  71765. const int numberOfPoints,
  71766. const float innerRadius,
  71767. const float outerRadius,
  71768. const float startAngle)
  71769. {
  71770. jassert (numberOfPoints > 1); // this would be silly.
  71771. if (numberOfPoints > 1)
  71772. {
  71773. const float angleBetweenPoints = float_Pi * 2.0f / numberOfPoints;
  71774. for (int i = 0; i < numberOfPoints; ++i)
  71775. {
  71776. float angle = startAngle + i * angleBetweenPoints;
  71777. const float x = centreX + outerRadius * sinf (angle);
  71778. const float y = centreY - outerRadius * cosf (angle);
  71779. if (i == 0)
  71780. startNewSubPath (x, y);
  71781. else
  71782. lineTo (x, y);
  71783. angle += angleBetweenPoints * 0.5f;
  71784. lineTo (centreX + innerRadius * sinf (angle),
  71785. centreY - innerRadius * cosf (angle));
  71786. }
  71787. closeSubPath();
  71788. }
  71789. }
  71790. void Path::addBubble (float x, float y,
  71791. float w, float h,
  71792. float cs,
  71793. float tipX,
  71794. float tipY,
  71795. int whichSide,
  71796. float arrowPos,
  71797. float arrowWidth)
  71798. {
  71799. if (w > 1.0f && h > 1.0f)
  71800. {
  71801. cs = jmin (cs, w * 0.5f, h * 0.5f);
  71802. const float cs2 = 2.0f * cs;
  71803. startNewSubPath (x + cs, y);
  71804. if (whichSide == 0)
  71805. {
  71806. const float halfArrowW = jmin (arrowWidth, w - cs2) * 0.5f;
  71807. const float arrowX1 = x + cs + jmax (0.0f, (w - cs2) * arrowPos - halfArrowW);
  71808. lineTo (arrowX1, y);
  71809. lineTo (tipX, tipY);
  71810. lineTo (arrowX1 + halfArrowW * 2.0f, y);
  71811. }
  71812. lineTo (x + w - cs, y);
  71813. if (cs > 0.0f)
  71814. addArc (x + w - cs2, y, cs2, cs2, 0, float_Pi * 0.5f);
  71815. if (whichSide == 3)
  71816. {
  71817. const float halfArrowH = jmin (arrowWidth, h - cs2) * 0.5f;
  71818. const float arrowY1 = y + cs + jmax (0.0f, (h - cs2) * arrowPos - halfArrowH);
  71819. lineTo (x + w, arrowY1);
  71820. lineTo (tipX, tipY);
  71821. lineTo (x + w, arrowY1 + halfArrowH * 2.0f);
  71822. }
  71823. lineTo (x + w, y + h - cs);
  71824. if (cs > 0.0f)
  71825. addArc (x + w - cs2, y + h - cs2, cs2, cs2, float_Pi * 0.5f, float_Pi);
  71826. if (whichSide == 2)
  71827. {
  71828. const float halfArrowW = jmin (arrowWidth, w - cs2) * 0.5f;
  71829. const float arrowX1 = x + cs + jmax (0.0f, (w - cs2) * arrowPos - halfArrowW);
  71830. lineTo (arrowX1 + halfArrowW * 2.0f, y + h);
  71831. lineTo (tipX, tipY);
  71832. lineTo (arrowX1, y + h);
  71833. }
  71834. lineTo (x + cs, y + h);
  71835. if (cs > 0.0f)
  71836. addArc (x, y + h - cs2, cs2, cs2, float_Pi, float_Pi * 1.5f);
  71837. if (whichSide == 1)
  71838. {
  71839. const float halfArrowH = jmin (arrowWidth, h - cs2) * 0.5f;
  71840. const float arrowY1 = y + cs + jmax (0.0f, (h - cs2) * arrowPos - halfArrowH);
  71841. lineTo (x, arrowY1 + halfArrowH * 2.0f);
  71842. lineTo (tipX, tipY);
  71843. lineTo (x, arrowY1);
  71844. }
  71845. lineTo (x, y + cs);
  71846. if (cs > 0.0f)
  71847. addArc (x, y, cs2, cs2, float_Pi * 1.5f, float_Pi * 2.0f - ellipseAngularIncrement);
  71848. closeSubPath();
  71849. }
  71850. }
  71851. void Path::addPath (const Path& other) throw()
  71852. {
  71853. int i = 0;
  71854. while (i < other.numElements)
  71855. {
  71856. const float type = other.data.elements [i++];
  71857. if (type == moveMarker)
  71858. {
  71859. startNewSubPath (other.data.elements [i],
  71860. other.data.elements [i + 1]);
  71861. i += 2;
  71862. }
  71863. else if (type == lineMarker)
  71864. {
  71865. lineTo (other.data.elements [i],
  71866. other.data.elements [i + 1]);
  71867. i += 2;
  71868. }
  71869. else if (type == quadMarker)
  71870. {
  71871. quadraticTo (other.data.elements [i],
  71872. other.data.elements [i + 1],
  71873. other.data.elements [i + 2],
  71874. other.data.elements [i + 3]);
  71875. i += 4;
  71876. }
  71877. else if (type == cubicMarker)
  71878. {
  71879. cubicTo (other.data.elements [i],
  71880. other.data.elements [i + 1],
  71881. other.data.elements [i + 2],
  71882. other.data.elements [i + 3],
  71883. other.data.elements [i + 4],
  71884. other.data.elements [i + 5]);
  71885. i += 6;
  71886. }
  71887. else if (type == closeSubPathMarker)
  71888. {
  71889. closeSubPath();
  71890. }
  71891. else
  71892. {
  71893. // something's gone wrong with the element list!
  71894. jassertfalse
  71895. }
  71896. }
  71897. }
  71898. void Path::addPath (const Path& other,
  71899. const AffineTransform& transformToApply) throw()
  71900. {
  71901. int i = 0;
  71902. while (i < other.numElements)
  71903. {
  71904. const float type = other.data.elements [i++];
  71905. if (type == closeSubPathMarker)
  71906. {
  71907. closeSubPath();
  71908. }
  71909. else
  71910. {
  71911. float x = other.data.elements [i++];
  71912. float y = other.data.elements [i++];
  71913. transformToApply.transformPoint (x, y);
  71914. if (type == moveMarker)
  71915. {
  71916. startNewSubPath (x, y);
  71917. }
  71918. else if (type == lineMarker)
  71919. {
  71920. lineTo (x, y);
  71921. }
  71922. else if (type == quadMarker)
  71923. {
  71924. float x2 = other.data.elements [i++];
  71925. float y2 = other.data.elements [i++];
  71926. transformToApply.transformPoint (x2, y2);
  71927. quadraticTo (x, y, x2, y2);
  71928. }
  71929. else if (type == cubicMarker)
  71930. {
  71931. float x2 = other.data.elements [i++];
  71932. float y2 = other.data.elements [i++];
  71933. float x3 = other.data.elements [i++];
  71934. float y3 = other.data.elements [i++];
  71935. transformToApply.transformPoint (x2, y2);
  71936. transformToApply.transformPoint (x3, y3);
  71937. cubicTo (x, y, x2, y2, x3, y3);
  71938. }
  71939. else
  71940. {
  71941. // something's gone wrong with the element list!
  71942. jassertfalse
  71943. }
  71944. }
  71945. }
  71946. }
  71947. void Path::applyTransform (const AffineTransform& transform) throw()
  71948. {
  71949. int i = 0;
  71950. pathYMin = pathXMin = 0;
  71951. pathYMax = pathXMax = 0;
  71952. bool setMaxMin = false;
  71953. while (i < numElements)
  71954. {
  71955. const float type = data.elements [i++];
  71956. if (type == moveMarker)
  71957. {
  71958. transform.transformPoint (data.elements [i],
  71959. data.elements [i + 1]);
  71960. if (setMaxMin)
  71961. {
  71962. pathXMin = jmin (pathXMin, data.elements [i]);
  71963. pathXMax = jmax (pathXMax, data.elements [i]);
  71964. pathYMin = jmin (pathYMin, data.elements [i + 1]);
  71965. pathYMax = jmax (pathYMax, data.elements [i + 1]);
  71966. }
  71967. else
  71968. {
  71969. pathXMin = pathXMax = data.elements [i];
  71970. pathYMin = pathYMax = data.elements [i + 1];
  71971. setMaxMin = true;
  71972. }
  71973. i += 2;
  71974. }
  71975. else if (type == lineMarker)
  71976. {
  71977. transform.transformPoint (data.elements [i],
  71978. data.elements [i + 1]);
  71979. pathXMin = jmin (pathXMin, data.elements [i]);
  71980. pathXMax = jmax (pathXMax, data.elements [i]);
  71981. pathYMin = jmin (pathYMin, data.elements [i + 1]);
  71982. pathYMax = jmax (pathYMax, data.elements [i + 1]);
  71983. i += 2;
  71984. }
  71985. else if (type == quadMarker)
  71986. {
  71987. transform.transformPoint (data.elements [i],
  71988. data.elements [i + 1]);
  71989. transform.transformPoint (data.elements [i + 2],
  71990. data.elements [i + 3]);
  71991. pathXMin = jmin (pathXMin, data.elements [i], data.elements [i + 2]);
  71992. pathXMax = jmax (pathXMax, data.elements [i], data.elements [i + 2]);
  71993. pathYMin = jmin (pathYMin, data.elements [i + 1], data.elements [i + 3]);
  71994. pathYMax = jmax (pathYMax, data.elements [i + 1], data.elements [i + 3]);
  71995. i += 4;
  71996. }
  71997. else if (type == cubicMarker)
  71998. {
  71999. transform.transformPoint (data.elements [i],
  72000. data.elements [i + 1]);
  72001. transform.transformPoint (data.elements [i + 2],
  72002. data.elements [i + 3]);
  72003. transform.transformPoint (data.elements [i + 4],
  72004. data.elements [i + 5]);
  72005. pathXMin = jmin (pathXMin, data.elements [i], data.elements [i + 2], data.elements [i + 4]);
  72006. pathXMax = jmax (pathXMax, data.elements [i], data.elements [i + 2], data.elements [i + 4]);
  72007. pathYMin = jmin (pathYMin, data.elements [i + 1], data.elements [i + 3], data.elements [i + 5]);
  72008. pathYMax = jmax (pathYMax, data.elements [i + 1], data.elements [i + 3], data.elements [i + 5]);
  72009. i += 6;
  72010. }
  72011. }
  72012. }
  72013. const AffineTransform Path::getTransformToScaleToFit (const float x, const float y,
  72014. const float w, const float h,
  72015. const bool preserveProportions,
  72016. const Justification& justification) const throw()
  72017. {
  72018. float sx, sy, sw, sh;
  72019. getBounds (sx, sy, sw, sh);
  72020. if (preserveProportions)
  72021. {
  72022. if (w <= 0 || h <= 0 || sw <= 0 || sh <= 0)
  72023. return AffineTransform::identity;
  72024. float newW, newH;
  72025. const float srcRatio = sh / sw;
  72026. if (srcRatio > h / w)
  72027. {
  72028. newW = h / srcRatio;
  72029. newH = h;
  72030. }
  72031. else
  72032. {
  72033. newW = w;
  72034. newH = w * srcRatio;
  72035. }
  72036. float newXCentre = x;
  72037. float newYCentre = y;
  72038. if (justification.testFlags (Justification::left))
  72039. newXCentre += newW * 0.5f;
  72040. else if (justification.testFlags (Justification::right))
  72041. newXCentre += w - newW * 0.5f;
  72042. else
  72043. newXCentre += w * 0.5f;
  72044. if (justification.testFlags (Justification::top))
  72045. newYCentre += newH * 0.5f;
  72046. else if (justification.testFlags (Justification::bottom))
  72047. newYCentre += h - newH * 0.5f;
  72048. else
  72049. newYCentre += h * 0.5f;
  72050. return AffineTransform::translation (sw * -0.5f - sx, sh * -0.5f - sy)
  72051. .scaled (newW / sw, newH / sh)
  72052. .translated (newXCentre, newYCentre);
  72053. }
  72054. else
  72055. {
  72056. return AffineTransform::translation (-sx, -sy)
  72057. .scaled (w / sw, h / sh)
  72058. .translated (x, y);
  72059. }
  72060. }
  72061. bool Path::contains (const float x, const float y, const float tolerence) const throw()
  72062. {
  72063. if (x <= pathXMin || x >= pathXMax
  72064. || y <= pathYMin || y >= pathYMax)
  72065. return false;
  72066. PathFlatteningIterator i (*this, AffineTransform::identity, tolerence);
  72067. int positiveCrossings = 0;
  72068. int negativeCrossings = 0;
  72069. while (i.next())
  72070. {
  72071. if ((i.y1 <= y && i.y2 > y)
  72072. || (i.y2 <= y && i.y1 > y))
  72073. {
  72074. const float intersectX = i.x1 + (i.x2 - i.x1) * (y - i.y1) / (i.y2 - i.y1);
  72075. if (intersectX <= x)
  72076. {
  72077. if (i.y1 < i.y2)
  72078. ++positiveCrossings;
  72079. else
  72080. ++negativeCrossings;
  72081. }
  72082. }
  72083. }
  72084. return (useNonZeroWinding) ? (negativeCrossings != positiveCrossings)
  72085. : ((negativeCrossings + positiveCrossings) & 1) != 0;
  72086. }
  72087. bool Path::intersectsLine (const float x1, const float y1,
  72088. const float x2, const float y2,
  72089. const float tolerence) throw()
  72090. {
  72091. PathFlatteningIterator i (*this, AffineTransform::identity, tolerence);
  72092. const Line line1 (x1, y1, x2, y2);
  72093. while (i.next())
  72094. {
  72095. const Line line2 (i.x1, i.y1, i.x2, i.y2);
  72096. float ix, iy;
  72097. if (line1.intersects (line2, ix, iy))
  72098. return true;
  72099. }
  72100. return false;
  72101. }
  72102. const Path Path::createPathWithRoundedCorners (const float cornerRadius) const throw()
  72103. {
  72104. if (cornerRadius <= 0.01f)
  72105. return *this;
  72106. int indexOfPathStart = 0, indexOfPathStartThis = 0;
  72107. int n = 0;
  72108. bool lastWasLine = false, firstWasLine = false;
  72109. Path p;
  72110. while (n < numElements)
  72111. {
  72112. const float type = data.elements [n++];
  72113. if (type == moveMarker)
  72114. {
  72115. indexOfPathStart = p.numElements;
  72116. indexOfPathStartThis = n - 1;
  72117. const float x = data.elements [n++];
  72118. const float y = data.elements [n++];
  72119. p.startNewSubPath (x, y);
  72120. lastWasLine = false;
  72121. firstWasLine = (data.elements [n] == lineMarker);
  72122. }
  72123. else if (type == lineMarker || type == closeSubPathMarker)
  72124. {
  72125. float startX = 0, startY = 0, joinX = 0, joinY = 0, endX, endY;
  72126. if (type == lineMarker)
  72127. {
  72128. endX = data.elements [n++];
  72129. endY = data.elements [n++];
  72130. if (n > 8)
  72131. {
  72132. startX = data.elements [n - 8];
  72133. startY = data.elements [n - 7];
  72134. joinX = data.elements [n - 5];
  72135. joinY = data.elements [n - 4];
  72136. }
  72137. }
  72138. else
  72139. {
  72140. endX = data.elements [indexOfPathStartThis + 1];
  72141. endY = data.elements [indexOfPathStartThis + 2];
  72142. if (n > 6)
  72143. {
  72144. startX = data.elements [n - 6];
  72145. startY = data.elements [n - 5];
  72146. joinX = data.elements [n - 3];
  72147. joinY = data.elements [n - 2];
  72148. }
  72149. }
  72150. if (lastWasLine)
  72151. {
  72152. const double len1 = juce_hypot (startX - joinX,
  72153. startY - joinY);
  72154. if (len1 > 0)
  72155. {
  72156. const double propNeeded = jmin (0.5, cornerRadius / len1);
  72157. p.data.elements [p.numElements - 2] = (float) (joinX - (joinX - startX) * propNeeded);
  72158. p.data.elements [p.numElements - 1] = (float) (joinY - (joinY - startY) * propNeeded);
  72159. }
  72160. const double len2 = juce_hypot (endX - joinX,
  72161. endY - joinY);
  72162. if (len2 > 0)
  72163. {
  72164. const double propNeeded = jmin (0.5, cornerRadius / len2);
  72165. p.quadraticTo (joinX, joinY,
  72166. (float) (joinX + (endX - joinX) * propNeeded),
  72167. (float) (joinY + (endY - joinY) * propNeeded));
  72168. }
  72169. p.lineTo (endX, endY);
  72170. }
  72171. else if (type == lineMarker)
  72172. {
  72173. p.lineTo (endX, endY);
  72174. lastWasLine = true;
  72175. }
  72176. if (type == closeSubPathMarker)
  72177. {
  72178. if (firstWasLine)
  72179. {
  72180. startX = data.elements [n - 3];
  72181. startY = data.elements [n - 2];
  72182. joinX = endX;
  72183. joinY = endY;
  72184. endX = data.elements [indexOfPathStartThis + 4];
  72185. endY = data.elements [indexOfPathStartThis + 5];
  72186. const double len1 = juce_hypot (startX - joinX,
  72187. startY - joinY);
  72188. if (len1 > 0)
  72189. {
  72190. const double propNeeded = jmin (0.5, cornerRadius / len1);
  72191. p.data.elements [p.numElements - 2] = (float) (joinX - (joinX - startX) * propNeeded);
  72192. p.data.elements [p.numElements - 1] = (float) (joinY - (joinY - startY) * propNeeded);
  72193. }
  72194. const double len2 = juce_hypot (endX - joinX,
  72195. endY - joinY);
  72196. if (len2 > 0)
  72197. {
  72198. const double propNeeded = jmin (0.5, cornerRadius / len2);
  72199. endX = (float) (joinX + (endX - joinX) * propNeeded);
  72200. endY = (float) (joinY + (endY - joinY) * propNeeded);
  72201. p.quadraticTo (joinX, joinY, endX, endY);
  72202. p.data.elements [indexOfPathStart + 1] = endX;
  72203. p.data.elements [indexOfPathStart + 2] = endY;
  72204. }
  72205. }
  72206. p.closeSubPath();
  72207. }
  72208. }
  72209. else if (type == quadMarker)
  72210. {
  72211. lastWasLine = false;
  72212. const float x1 = data.elements [n++];
  72213. const float y1 = data.elements [n++];
  72214. const float x2 = data.elements [n++];
  72215. const float y2 = data.elements [n++];
  72216. p.quadraticTo (x1, y1, x2, y2);
  72217. }
  72218. else if (type == cubicMarker)
  72219. {
  72220. lastWasLine = false;
  72221. const float x1 = data.elements [n++];
  72222. const float y1 = data.elements [n++];
  72223. const float x2 = data.elements [n++];
  72224. const float y2 = data.elements [n++];
  72225. const float x3 = data.elements [n++];
  72226. const float y3 = data.elements [n++];
  72227. p.cubicTo (x1, y1, x2, y2, x3, y3);
  72228. }
  72229. }
  72230. return p;
  72231. }
  72232. void Path::loadPathFromStream (InputStream& source)
  72233. {
  72234. while (! source.isExhausted())
  72235. {
  72236. switch (source.readByte())
  72237. {
  72238. case 'm':
  72239. {
  72240. const float x = source.readFloat();
  72241. const float y = source.readFloat();
  72242. startNewSubPath (x, y);
  72243. break;
  72244. }
  72245. case 'l':
  72246. {
  72247. const float x = source.readFloat();
  72248. const float y = source.readFloat();
  72249. lineTo (x, y);
  72250. break;
  72251. }
  72252. case 'q':
  72253. {
  72254. const float x1 = source.readFloat();
  72255. const float y1 = source.readFloat();
  72256. const float x2 = source.readFloat();
  72257. const float y2 = source.readFloat();
  72258. quadraticTo (x1, y1, x2, y2);
  72259. break;
  72260. }
  72261. case 'b':
  72262. {
  72263. const float x1 = source.readFloat();
  72264. const float y1 = source.readFloat();
  72265. const float x2 = source.readFloat();
  72266. const float y2 = source.readFloat();
  72267. const float x3 = source.readFloat();
  72268. const float y3 = source.readFloat();
  72269. cubicTo (x1, y1, x2, y2, x3, y3);
  72270. break;
  72271. }
  72272. case 'c':
  72273. closeSubPath();
  72274. break;
  72275. case 'n':
  72276. useNonZeroWinding = true;
  72277. break;
  72278. case 'z':
  72279. useNonZeroWinding = false;
  72280. break;
  72281. case 'e':
  72282. return; // end of path marker
  72283. default:
  72284. jassertfalse // illegal char in the stream
  72285. break;
  72286. }
  72287. }
  72288. }
  72289. void Path::loadPathFromData (const unsigned char* const data,
  72290. const int numberOfBytes) throw()
  72291. {
  72292. MemoryInputStream in ((const char*) data, numberOfBytes, false);
  72293. loadPathFromStream (in);
  72294. }
  72295. void Path::writePathToStream (OutputStream& dest) const
  72296. {
  72297. dest.writeByte ((useNonZeroWinding) ? 'n' : 'z');
  72298. int i = 0;
  72299. while (i < numElements)
  72300. {
  72301. const float type = data.elements [i++];
  72302. if (type == moveMarker)
  72303. {
  72304. dest.writeByte ('m');
  72305. dest.writeFloat (data.elements [i++]);
  72306. dest.writeFloat (data.elements [i++]);
  72307. }
  72308. else if (type == lineMarker)
  72309. {
  72310. dest.writeByte ('l');
  72311. dest.writeFloat (data.elements [i++]);
  72312. dest.writeFloat (data.elements [i++]);
  72313. }
  72314. else if (type == quadMarker)
  72315. {
  72316. dest.writeByte ('q');
  72317. dest.writeFloat (data.elements [i++]);
  72318. dest.writeFloat (data.elements [i++]);
  72319. dest.writeFloat (data.elements [i++]);
  72320. dest.writeFloat (data.elements [i++]);
  72321. }
  72322. else if (type == cubicMarker)
  72323. {
  72324. dest.writeByte ('b');
  72325. dest.writeFloat (data.elements [i++]);
  72326. dest.writeFloat (data.elements [i++]);
  72327. dest.writeFloat (data.elements [i++]);
  72328. dest.writeFloat (data.elements [i++]);
  72329. dest.writeFloat (data.elements [i++]);
  72330. dest.writeFloat (data.elements [i++]);
  72331. }
  72332. else if (type == closeSubPathMarker)
  72333. {
  72334. dest.writeByte ('c');
  72335. }
  72336. }
  72337. dest.writeByte ('e'); // marks the end-of-path
  72338. }
  72339. const String Path::toString() const
  72340. {
  72341. MemoryOutputStream s (2048, 2048);
  72342. if (! useNonZeroWinding)
  72343. s << "a ";
  72344. int i = 0;
  72345. float lastMarker = 0.0f;
  72346. while (i < numElements)
  72347. {
  72348. const float marker = data.elements [i++];
  72349. char markerChar = 0;
  72350. int numCoords = 0;
  72351. if (marker == moveMarker)
  72352. {
  72353. markerChar = 'm';
  72354. numCoords = 2;
  72355. }
  72356. else if (marker == lineMarker)
  72357. {
  72358. markerChar = 'l';
  72359. numCoords = 2;
  72360. }
  72361. else if (marker == quadMarker)
  72362. {
  72363. markerChar = 'q';
  72364. numCoords = 4;
  72365. }
  72366. else if (marker == cubicMarker)
  72367. {
  72368. markerChar = 'c';
  72369. numCoords = 6;
  72370. }
  72371. else
  72372. {
  72373. jassert (marker == closeSubPathMarker);
  72374. markerChar = 'z';
  72375. }
  72376. if (marker != lastMarker)
  72377. {
  72378. s << markerChar << ' ';
  72379. lastMarker = marker;
  72380. }
  72381. while (--numCoords >= 0 && i < numElements)
  72382. {
  72383. String n (data.elements [i++], 3);
  72384. if (n.endsWithChar (T('0')))
  72385. {
  72386. do
  72387. {
  72388. n = n.dropLastCharacters (1);
  72389. } while (n.endsWithChar (T('0')));
  72390. if (n.endsWithChar (T('.')))
  72391. n = n.dropLastCharacters (1);
  72392. }
  72393. s << n << ' ';
  72394. }
  72395. }
  72396. const char* const result = (const char*) s.getData();
  72397. size_t len = s.getDataSize();
  72398. while (len > 0 && CharacterFunctions::isWhitespace (result [len - 1]))
  72399. --len;
  72400. return String (result, len);
  72401. }
  72402. static const String nextToken (const tchar*& t)
  72403. {
  72404. while (CharacterFunctions::isWhitespace (*t))
  72405. ++t;
  72406. const tchar* const start = t;
  72407. while (*t != 0 && ! CharacterFunctions::isWhitespace (*t))
  72408. ++t;
  72409. const int length = (int) (t - start);
  72410. while (CharacterFunctions::isWhitespace (*t))
  72411. ++t;
  72412. return String (start, length);
  72413. }
  72414. void Path::restoreFromString (const String& stringVersion)
  72415. {
  72416. clear();
  72417. setUsingNonZeroWinding (true);
  72418. const tchar* t = stringVersion;
  72419. tchar marker = T('m');
  72420. int numValues = 2;
  72421. float values [6];
  72422. while (*t != 0)
  72423. {
  72424. const String token (nextToken (t));
  72425. const tchar firstChar = token[0];
  72426. int startNum = 0;
  72427. if (firstChar == T('m') || firstChar == T('l'))
  72428. {
  72429. marker = firstChar;
  72430. numValues = 2;
  72431. }
  72432. else if (firstChar == T('q'))
  72433. {
  72434. marker = firstChar;
  72435. numValues = 4;
  72436. }
  72437. else if (firstChar == T('c'))
  72438. {
  72439. marker = firstChar;
  72440. numValues = 6;
  72441. }
  72442. else if (firstChar == T('z'))
  72443. {
  72444. marker = firstChar;
  72445. numValues = 0;
  72446. }
  72447. else if (firstChar == T('a'))
  72448. {
  72449. setUsingNonZeroWinding (false);
  72450. continue;
  72451. }
  72452. else
  72453. {
  72454. ++startNum;
  72455. values [0] = token.getFloatValue();
  72456. }
  72457. for (int i = startNum; i < numValues; ++i)
  72458. values [i] = nextToken (t).getFloatValue();
  72459. switch (marker)
  72460. {
  72461. case T('m'):
  72462. startNewSubPath (values[0], values[1]);
  72463. break;
  72464. case T('l'):
  72465. lineTo (values[0], values[1]);
  72466. break;
  72467. case T('q'):
  72468. quadraticTo (values[0], values[1],
  72469. values[2], values[3]);
  72470. break;
  72471. case T('c'):
  72472. cubicTo (values[0], values[1],
  72473. values[2], values[3],
  72474. values[4], values[5]);
  72475. break;
  72476. case T('z'):
  72477. closeSubPath();
  72478. break;
  72479. default:
  72480. jassertfalse // illegal string format?
  72481. break;
  72482. }
  72483. }
  72484. }
  72485. Path::Iterator::Iterator (const Path& path_)
  72486. : path (path_),
  72487. index (0)
  72488. {
  72489. }
  72490. Path::Iterator::~Iterator()
  72491. {
  72492. }
  72493. bool Path::Iterator::next()
  72494. {
  72495. const float* const elements = path.data.elements;
  72496. if (index < path.numElements)
  72497. {
  72498. const float type = elements [index++];
  72499. if (type == moveMarker)
  72500. {
  72501. elementType = startNewSubPath;
  72502. x1 = elements [index++];
  72503. y1 = elements [index++];
  72504. }
  72505. else if (type == lineMarker)
  72506. {
  72507. elementType = lineTo;
  72508. x1 = elements [index++];
  72509. y1 = elements [index++];
  72510. }
  72511. else if (type == quadMarker)
  72512. {
  72513. elementType = quadraticTo;
  72514. x1 = elements [index++];
  72515. y1 = elements [index++];
  72516. x2 = elements [index++];
  72517. y2 = elements [index++];
  72518. }
  72519. else if (type == cubicMarker)
  72520. {
  72521. elementType = cubicTo;
  72522. x1 = elements [index++];
  72523. y1 = elements [index++];
  72524. x2 = elements [index++];
  72525. y2 = elements [index++];
  72526. x3 = elements [index++];
  72527. y3 = elements [index++];
  72528. }
  72529. else if (type == closeSubPathMarker)
  72530. {
  72531. elementType = closePath;
  72532. }
  72533. return true;
  72534. }
  72535. return false;
  72536. }
  72537. END_JUCE_NAMESPACE
  72538. /********* End of inlined file: juce_Path.cpp *********/
  72539. /********* Start of inlined file: juce_PathIterator.cpp *********/
  72540. BEGIN_JUCE_NAMESPACE
  72541. #if JUCE_MSVC
  72542. #pragma optimize ("t", on)
  72543. #endif
  72544. PathFlatteningIterator::PathFlatteningIterator (const Path& path_,
  72545. const AffineTransform& transform_,
  72546. float tolerence_) throw()
  72547. : x2 (0),
  72548. y2 (0),
  72549. closesSubPath (false),
  72550. subPathIndex (-1),
  72551. path (path_),
  72552. transform (transform_),
  72553. points (path_.data.elements),
  72554. tolerence (tolerence_ * tolerence_),
  72555. subPathCloseX (0),
  72556. subPathCloseY (0),
  72557. stackBase (32),
  72558. index (0),
  72559. stackSize (32)
  72560. {
  72561. isIdentityTransform = transform.isIdentity();
  72562. stackPos = stackBase;
  72563. }
  72564. PathFlatteningIterator::~PathFlatteningIterator() throw()
  72565. {
  72566. }
  72567. bool PathFlatteningIterator::next() throw()
  72568. {
  72569. x1 = x2;
  72570. y1 = y2;
  72571. float x3 = 0;
  72572. float y3 = 0;
  72573. float x4 = 0;
  72574. float y4 = 0;
  72575. float type;
  72576. for (;;)
  72577. {
  72578. if (stackPos == stackBase)
  72579. {
  72580. if (index >= path.numElements)
  72581. {
  72582. return false;
  72583. }
  72584. else
  72585. {
  72586. type = points [index++];
  72587. if (type != Path::closeSubPathMarker)
  72588. {
  72589. x2 = points [index++];
  72590. y2 = points [index++];
  72591. if (! isIdentityTransform)
  72592. transform.transformPoint (x2, y2);
  72593. if (type == Path::quadMarker)
  72594. {
  72595. x3 = points [index++];
  72596. y3 = points [index++];
  72597. if (! isIdentityTransform)
  72598. transform.transformPoint (x3, y3);
  72599. }
  72600. else if (type == Path::cubicMarker)
  72601. {
  72602. x3 = points [index++];
  72603. y3 = points [index++];
  72604. x4 = points [index++];
  72605. y4 = points [index++];
  72606. if (! isIdentityTransform)
  72607. {
  72608. transform.transformPoint (x3, y3);
  72609. transform.transformPoint (x4, y4);
  72610. }
  72611. }
  72612. }
  72613. }
  72614. }
  72615. else
  72616. {
  72617. type = *--stackPos;
  72618. if (type != Path::closeSubPathMarker)
  72619. {
  72620. x2 = *--stackPos;
  72621. y2 = *--stackPos;
  72622. if (type == Path::quadMarker)
  72623. {
  72624. x3 = *--stackPos;
  72625. y3 = *--stackPos;
  72626. }
  72627. else if (type == Path::cubicMarker)
  72628. {
  72629. x3 = *--stackPos;
  72630. y3 = *--stackPos;
  72631. x4 = *--stackPos;
  72632. y4 = *--stackPos;
  72633. }
  72634. }
  72635. }
  72636. if (type == Path::lineMarker)
  72637. {
  72638. ++subPathIndex;
  72639. closesSubPath = (stackPos == stackBase)
  72640. && (index < path.numElements)
  72641. && (points [index] == Path::closeSubPathMarker)
  72642. && x2 == subPathCloseX
  72643. && y2 == subPathCloseY;
  72644. return true;
  72645. }
  72646. else if (type == Path::quadMarker)
  72647. {
  72648. const int offset = (int) (stackPos - stackBase);
  72649. if (offset >= stackSize - 10)
  72650. {
  72651. stackSize <<= 1;
  72652. stackBase.realloc (stackSize);
  72653. stackPos = stackBase + offset;
  72654. }
  72655. const float dx1 = x1 - x2;
  72656. const float dy1 = y1 - y2;
  72657. const float dx2 = x2 - x3;
  72658. const float dy2 = y2 - y3;
  72659. const float m1x = (x1 + x2) * 0.5f;
  72660. const float m1y = (y1 + y2) * 0.5f;
  72661. const float m2x = (x2 + x3) * 0.5f;
  72662. const float m2y = (y2 + y3) * 0.5f;
  72663. const float m3x = (m1x + m2x) * 0.5f;
  72664. const float m3y = (m1y + m2y) * 0.5f;
  72665. if (dx1*dx1 + dy1*dy1 + dx2*dx2 + dy2*dy2 > tolerence)
  72666. {
  72667. *stackPos++ = y3;
  72668. *stackPos++ = x3;
  72669. *stackPos++ = m2y;
  72670. *stackPos++ = m2x;
  72671. *stackPos++ = Path::quadMarker;
  72672. *stackPos++ = m3y;
  72673. *stackPos++ = m3x;
  72674. *stackPos++ = m1y;
  72675. *stackPos++ = m1x;
  72676. *stackPos++ = Path::quadMarker;
  72677. }
  72678. else
  72679. {
  72680. *stackPos++ = y3;
  72681. *stackPos++ = x3;
  72682. *stackPos++ = Path::lineMarker;
  72683. *stackPos++ = m3y;
  72684. *stackPos++ = m3x;
  72685. *stackPos++ = Path::lineMarker;
  72686. }
  72687. jassert (stackPos < stackBase + stackSize);
  72688. }
  72689. else if (type == Path::cubicMarker)
  72690. {
  72691. const int offset = (int) (stackPos - stackBase);
  72692. if (offset >= stackSize - 16)
  72693. {
  72694. stackSize <<= 1;
  72695. stackBase.realloc (stackSize);
  72696. stackPos = stackBase + offset;
  72697. }
  72698. const float dx1 = x1 - x2;
  72699. const float dy1 = y1 - y2;
  72700. const float dx2 = x2 - x3;
  72701. const float dy2 = y2 - y3;
  72702. const float dx3 = x3 - x4;
  72703. const float dy3 = y3 - y4;
  72704. const float m1x = (x1 + x2) * 0.5f;
  72705. const float m1y = (y1 + y2) * 0.5f;
  72706. const float m2x = (x3 + x2) * 0.5f;
  72707. const float m2y = (y3 + y2) * 0.5f;
  72708. const float m3x = (x3 + x4) * 0.5f;
  72709. const float m3y = (y3 + y4) * 0.5f;
  72710. const float m4x = (m1x + m2x) * 0.5f;
  72711. const float m4y = (m1y + m2y) * 0.5f;
  72712. const float m5x = (m3x + m2x) * 0.5f;
  72713. const float m5y = (m3y + m2y) * 0.5f;
  72714. if (dx1*dx1 + dy1*dy1 + dx2*dx2
  72715. + dy2*dy2 + dx3*dx3 + dy3*dy3 > tolerence)
  72716. {
  72717. *stackPos++ = y4;
  72718. *stackPos++ = x4;
  72719. *stackPos++ = m3y;
  72720. *stackPos++ = m3x;
  72721. *stackPos++ = m5y;
  72722. *stackPos++ = m5x;
  72723. *stackPos++ = Path::cubicMarker;
  72724. *stackPos++ = (m4y + m5y) * 0.5f;
  72725. *stackPos++ = (m4x + m5x) * 0.5f;
  72726. *stackPos++ = m4y;
  72727. *stackPos++ = m4x;
  72728. *stackPos++ = m1y;
  72729. *stackPos++ = m1x;
  72730. *stackPos++ = Path::cubicMarker;
  72731. }
  72732. else
  72733. {
  72734. *stackPos++ = y4;
  72735. *stackPos++ = x4;
  72736. *stackPos++ = Path::lineMarker;
  72737. *stackPos++ = m5y;
  72738. *stackPos++ = m5x;
  72739. *stackPos++ = Path::lineMarker;
  72740. *stackPos++ = m4y;
  72741. *stackPos++ = m4x;
  72742. *stackPos++ = Path::lineMarker;
  72743. }
  72744. }
  72745. else if (type == Path::closeSubPathMarker)
  72746. {
  72747. if (x2 != subPathCloseX || y2 != subPathCloseY)
  72748. {
  72749. x1 = x2;
  72750. y1 = y2;
  72751. x2 = subPathCloseX;
  72752. y2 = subPathCloseY;
  72753. closesSubPath = true;
  72754. return true;
  72755. }
  72756. }
  72757. else
  72758. {
  72759. jassert (type == Path::moveMarker);
  72760. subPathIndex = -1;
  72761. subPathCloseX = x1 = x2;
  72762. subPathCloseY = y1 = y2;
  72763. }
  72764. }
  72765. }
  72766. END_JUCE_NAMESPACE
  72767. /********* End of inlined file: juce_PathIterator.cpp *********/
  72768. /********* Start of inlined file: juce_PathStrokeType.cpp *********/
  72769. BEGIN_JUCE_NAMESPACE
  72770. PathStrokeType::PathStrokeType (const float strokeThickness,
  72771. const JointStyle jointStyle_,
  72772. const EndCapStyle endStyle_) throw()
  72773. : thickness (strokeThickness),
  72774. jointStyle (jointStyle_),
  72775. endStyle (endStyle_)
  72776. {
  72777. }
  72778. PathStrokeType::PathStrokeType (const PathStrokeType& other) throw()
  72779. : thickness (other.thickness),
  72780. jointStyle (other.jointStyle),
  72781. endStyle (other.endStyle)
  72782. {
  72783. }
  72784. const PathStrokeType& PathStrokeType::operator= (const PathStrokeType& other) throw()
  72785. {
  72786. thickness = other.thickness;
  72787. jointStyle = other.jointStyle;
  72788. endStyle = other.endStyle;
  72789. return *this;
  72790. }
  72791. PathStrokeType::~PathStrokeType() throw()
  72792. {
  72793. }
  72794. bool PathStrokeType::operator== (const PathStrokeType& other) const throw()
  72795. {
  72796. return thickness == other.thickness
  72797. && jointStyle == other.jointStyle
  72798. && endStyle == other.endStyle;
  72799. }
  72800. bool PathStrokeType::operator!= (const PathStrokeType& other) const throw()
  72801. {
  72802. return ! operator== (other);
  72803. }
  72804. static bool lineIntersection (const float x1, const float y1,
  72805. const float x2, const float y2,
  72806. const float x3, const float y3,
  72807. const float x4, const float y4,
  72808. float& intersectionX,
  72809. float& intersectionY,
  72810. float& distanceBeyondLine1EndSquared) throw()
  72811. {
  72812. if (x2 != x3 || y2 != y3)
  72813. {
  72814. const float dx1 = x2 - x1;
  72815. const float dy1 = y2 - y1;
  72816. const float dx2 = x4 - x3;
  72817. const float dy2 = y4 - y3;
  72818. const float divisor = dx1 * dy2 - dx2 * dy1;
  72819. if (divisor == 0)
  72820. {
  72821. if (! ((dx1 == 0 && dy1 == 0) || (dx2 == 0 && dy2 == 0)))
  72822. {
  72823. if (dy1 == 0 && dy2 != 0)
  72824. {
  72825. const float along = (y1 - y3) / dy2;
  72826. intersectionX = x3 + along * dx2;
  72827. intersectionY = y1;
  72828. distanceBeyondLine1EndSquared = intersectionX - x2;
  72829. distanceBeyondLine1EndSquared *= distanceBeyondLine1EndSquared;
  72830. if ((x2 > x1) == (intersectionX < x2))
  72831. distanceBeyondLine1EndSquared = -distanceBeyondLine1EndSquared;
  72832. return along >= 0 && along <= 1.0f;
  72833. }
  72834. else if (dy2 == 0 && dy1 != 0)
  72835. {
  72836. const float along = (y3 - y1) / dy1;
  72837. intersectionX = x1 + along * dx1;
  72838. intersectionY = y3;
  72839. distanceBeyondLine1EndSquared = (along - 1.0f) * dx1;
  72840. distanceBeyondLine1EndSquared *= distanceBeyondLine1EndSquared;
  72841. if (along < 1.0f)
  72842. distanceBeyondLine1EndSquared = -distanceBeyondLine1EndSquared;
  72843. return along >= 0 && along <= 1.0f;
  72844. }
  72845. else if (dx1 == 0 && dx2 != 0)
  72846. {
  72847. const float along = (x1 - x3) / dx2;
  72848. intersectionX = x1;
  72849. intersectionY = y3 + along * dy2;
  72850. distanceBeyondLine1EndSquared = intersectionY - y2;
  72851. distanceBeyondLine1EndSquared *= distanceBeyondLine1EndSquared;
  72852. if ((y2 > y1) == (intersectionY < y2))
  72853. distanceBeyondLine1EndSquared = -distanceBeyondLine1EndSquared;
  72854. return along >= 0 && along <= 1.0f;
  72855. }
  72856. else if (dx2 == 0 && dx1 != 0)
  72857. {
  72858. const float along = (x3 - x1) / dx1;
  72859. intersectionX = x3;
  72860. intersectionY = y1 + along * dy1;
  72861. distanceBeyondLine1EndSquared = (along - 1.0f) * dy1;
  72862. distanceBeyondLine1EndSquared *= distanceBeyondLine1EndSquared;
  72863. if (along < 1.0f)
  72864. distanceBeyondLine1EndSquared = -distanceBeyondLine1EndSquared;
  72865. return along >= 0 && along <= 1.0f;
  72866. }
  72867. }
  72868. intersectionX = 0.5f * (x2 + x3);
  72869. intersectionY = 0.5f * (y2 + y3);
  72870. distanceBeyondLine1EndSquared = 0.0f;
  72871. return false;
  72872. }
  72873. else
  72874. {
  72875. const float along1 = ((y1 - y3) * dx2 - (x1 - x3) * dy2) / divisor;
  72876. intersectionX = x1 + along1 * dx1;
  72877. intersectionY = y1 + along1 * dy1;
  72878. if (along1 >= 0 && along1 <= 1.0f)
  72879. {
  72880. const float along2 = ((y1 - y3) * dx1 - (x1 - x3) * dy1);
  72881. if (along2 >= 0 && along2 <= divisor)
  72882. {
  72883. distanceBeyondLine1EndSquared = 0.0f;
  72884. return true;
  72885. }
  72886. }
  72887. distanceBeyondLine1EndSquared = along1 - 1.0f;
  72888. distanceBeyondLine1EndSquared *= distanceBeyondLine1EndSquared;
  72889. distanceBeyondLine1EndSquared *= (dx1 * dx1 + dy1 * dy1);
  72890. if (along1 < 1.0f)
  72891. distanceBeyondLine1EndSquared = -distanceBeyondLine1EndSquared;
  72892. return false;
  72893. }
  72894. }
  72895. intersectionX = x2;
  72896. intersectionY = y2;
  72897. distanceBeyondLine1EndSquared = 0.0f;
  72898. return true;
  72899. }
  72900. // part of stroke drawing stuff
  72901. static void addEdgeAndJoint (Path& destPath,
  72902. const PathStrokeType::JointStyle style,
  72903. const float maxMiterExtensionSquared, const float width,
  72904. const float x1, const float y1,
  72905. const float x2, const float y2,
  72906. const float x3, const float y3,
  72907. const float x4, const float y4,
  72908. const float midX, const float midY) throw()
  72909. {
  72910. if (style == PathStrokeType::beveled
  72911. || (x3 == x4 && y3 == y4)
  72912. || (x1 == x2 && y1 == y2))
  72913. {
  72914. destPath.lineTo (x2, y2);
  72915. destPath.lineTo (x3, y3);
  72916. }
  72917. else
  72918. {
  72919. float jx, jy, distanceBeyondLine1EndSquared;
  72920. // if they intersect, use this point..
  72921. if (lineIntersection (x1, y1, x2, y2,
  72922. x3, y3, x4, y4,
  72923. jx, jy, distanceBeyondLine1EndSquared))
  72924. {
  72925. destPath.lineTo (jx, jy);
  72926. }
  72927. else
  72928. {
  72929. if (style == PathStrokeType::mitered)
  72930. {
  72931. if (distanceBeyondLine1EndSquared < maxMiterExtensionSquared
  72932. && distanceBeyondLine1EndSquared > 0.0f)
  72933. {
  72934. destPath.lineTo (jx, jy);
  72935. }
  72936. else
  72937. {
  72938. // the end sticks out too far, so just use a blunt joint
  72939. destPath.lineTo (x2, y2);
  72940. destPath.lineTo (x3, y3);
  72941. }
  72942. }
  72943. else
  72944. {
  72945. // curved joints
  72946. float angle1 = atan2f (x2 - midX, y2 - midY);
  72947. float angle2 = atan2f (x3 - midX, y3 - midY);
  72948. const float angleIncrement = 0.1f;
  72949. destPath.lineTo (x2, y2);
  72950. if (fabs (angle1 - angle2) > angleIncrement)
  72951. {
  72952. if (angle2 > angle1 + float_Pi
  72953. || (angle2 < angle1 && angle2 >= angle1 - float_Pi))
  72954. {
  72955. if (angle2 > angle1)
  72956. angle2 -= float_Pi * 2.0f;
  72957. jassert (angle1 <= angle2 + float_Pi);
  72958. angle1 -= angleIncrement;
  72959. while (angle1 > angle2)
  72960. {
  72961. destPath.lineTo (midX + width * sinf (angle1),
  72962. midY + width * cosf (angle1));
  72963. angle1 -= angleIncrement;
  72964. }
  72965. }
  72966. else
  72967. {
  72968. if (angle1 > angle2)
  72969. angle1 -= float_Pi * 2.0f;
  72970. jassert (angle1 >= angle2 - float_Pi);
  72971. angle1 += angleIncrement;
  72972. while (angle1 < angle2)
  72973. {
  72974. destPath.lineTo (midX + width * sinf (angle1),
  72975. midY + width * cosf (angle1));
  72976. angle1 += angleIncrement;
  72977. }
  72978. }
  72979. }
  72980. destPath.lineTo (x3, y3);
  72981. }
  72982. }
  72983. }
  72984. }
  72985. static inline void addLineEnd (Path& destPath,
  72986. const PathStrokeType::EndCapStyle style,
  72987. const float x1, const float y1,
  72988. const float x2, const float y2,
  72989. const float width) throw()
  72990. {
  72991. if (style == PathStrokeType::butt)
  72992. {
  72993. destPath.lineTo (x2, y2);
  72994. }
  72995. else
  72996. {
  72997. float offx1, offy1, offx2, offy2;
  72998. float dx = x2 - x1;
  72999. float dy = y2 - y1;
  73000. const float len = juce_hypotf (dx, dy);
  73001. if (len == 0)
  73002. {
  73003. offx1 = offx2 = x1;
  73004. offy1 = offy2 = y1;
  73005. }
  73006. else
  73007. {
  73008. const float offset = width / len;
  73009. dx *= offset;
  73010. dy *= offset;
  73011. offx1 = x1 + dy;
  73012. offy1 = y1 - dx;
  73013. offx2 = x2 + dy;
  73014. offy2 = y2 - dx;
  73015. }
  73016. if (style == PathStrokeType::square)
  73017. {
  73018. // sqaure ends
  73019. destPath.lineTo (offx1, offy1);
  73020. destPath.lineTo (offx2, offy2);
  73021. destPath.lineTo (x2, y2);
  73022. }
  73023. else
  73024. {
  73025. // rounded ends
  73026. const float midx = (offx1 + offx2) * 0.5f;
  73027. const float midy = (offy1 + offy2) * 0.5f;
  73028. destPath.cubicTo (x1 + (offx1 - x1) * 0.55f, y1 + (offy1 - y1) * 0.55f,
  73029. offx1 + (midx - offx1) * 0.45f, offy1 + (midy - offy1) * 0.45f,
  73030. midx, midy);
  73031. destPath.cubicTo (midx + (offx2 - midx) * 0.55f, midy + (offy2 - midy) * 0.55f,
  73032. offx2 + (x2 - offx2) * 0.45f, offy2 + (y2 - offy2) * 0.45f,
  73033. x2, y2);
  73034. }
  73035. }
  73036. }
  73037. struct LineSection
  73038. {
  73039. LineSection() {}
  73040. LineSection (int) {}
  73041. float x1, y1, x2, y2; // original line
  73042. float lx1, ly1, lx2, ly2; // the left-hand stroke
  73043. float rx1, ry1, rx2, ry2; // the right-hand stroke
  73044. };
  73045. static void addSubPath (Path& destPath, const Array <LineSection>& subPath,
  73046. const bool isClosed,
  73047. const float width, const float maxMiterExtensionSquared,
  73048. const PathStrokeType::JointStyle jointStyle, const PathStrokeType::EndCapStyle endStyle) throw()
  73049. {
  73050. jassert (subPath.size() > 0);
  73051. const LineSection& firstLine = subPath.getReference (0);
  73052. float lastX1 = firstLine.lx1;
  73053. float lastY1 = firstLine.ly1;
  73054. float lastX2 = firstLine.lx2;
  73055. float lastY2 = firstLine.ly2;
  73056. if (isClosed)
  73057. {
  73058. destPath.startNewSubPath (lastX1, lastY1);
  73059. }
  73060. else
  73061. {
  73062. destPath.startNewSubPath (firstLine.rx2, firstLine.ry2);
  73063. addLineEnd (destPath, endStyle,
  73064. firstLine.rx2, firstLine.ry2,
  73065. lastX1, lastY1,
  73066. width);
  73067. }
  73068. int i;
  73069. for (i = 1; i < subPath.size(); ++i)
  73070. {
  73071. const LineSection& l = subPath.getReference (i);
  73072. addEdgeAndJoint (destPath, jointStyle,
  73073. maxMiterExtensionSquared, width,
  73074. lastX1, lastY1, lastX2, lastY2,
  73075. l.lx1, l.ly1, l.lx2, l.ly2,
  73076. l.x1, l.y1);
  73077. lastX1 = l.lx1;
  73078. lastY1 = l.ly1;
  73079. lastX2 = l.lx2;
  73080. lastY2 = l.ly2;
  73081. }
  73082. const LineSection& lastLine = subPath.getReference (subPath.size() - 1);
  73083. if (isClosed)
  73084. {
  73085. const LineSection& l = subPath.getReference (0);
  73086. addEdgeAndJoint (destPath, jointStyle,
  73087. maxMiterExtensionSquared, width,
  73088. lastX1, lastY1, lastX2, lastY2,
  73089. l.lx1, l.ly1, l.lx2, l.ly2,
  73090. l.x1, l.y1);
  73091. destPath.closeSubPath();
  73092. destPath.startNewSubPath (lastLine.rx1, lastLine.ry1);
  73093. }
  73094. else
  73095. {
  73096. destPath.lineTo (lastX2, lastY2);
  73097. addLineEnd (destPath, endStyle,
  73098. lastX2, lastY2,
  73099. lastLine.rx1, lastLine.ry1,
  73100. width);
  73101. }
  73102. lastX1 = lastLine.rx1;
  73103. lastY1 = lastLine.ry1;
  73104. lastX2 = lastLine.rx2;
  73105. lastY2 = lastLine.ry2;
  73106. for (i = subPath.size() - 1; --i >= 0;)
  73107. {
  73108. const LineSection& l = subPath.getReference (i);
  73109. addEdgeAndJoint (destPath, jointStyle,
  73110. maxMiterExtensionSquared, width,
  73111. lastX1, lastY1, lastX2, lastY2,
  73112. l.rx1, l.ry1, l.rx2, l.ry2,
  73113. l.x2, l.y2);
  73114. lastX1 = l.rx1;
  73115. lastY1 = l.ry1;
  73116. lastX2 = l.rx2;
  73117. lastY2 = l.ry2;
  73118. }
  73119. if (isClosed)
  73120. {
  73121. addEdgeAndJoint (destPath, jointStyle,
  73122. maxMiterExtensionSquared, width,
  73123. lastX1, lastY1, lastX2, lastY2,
  73124. lastLine.rx1, lastLine.ry1, lastLine.rx2, lastLine.ry2,
  73125. lastLine.x2, lastLine.y2);
  73126. }
  73127. else
  73128. {
  73129. // do the last line
  73130. destPath.lineTo (lastX2, lastY2);
  73131. }
  73132. destPath.closeSubPath();
  73133. }
  73134. void PathStrokeType::createStrokedPath (Path& destPath,
  73135. const Path& source,
  73136. const AffineTransform& transform,
  73137. const float extraAccuracy) const throw()
  73138. {
  73139. if (thickness <= 0)
  73140. {
  73141. destPath.clear();
  73142. return;
  73143. }
  73144. const Path* sourcePath = &source;
  73145. Path temp;
  73146. if (sourcePath == &destPath)
  73147. {
  73148. destPath.swapWithPath (temp);
  73149. sourcePath = &temp;
  73150. }
  73151. else
  73152. {
  73153. destPath.clear();
  73154. }
  73155. destPath.setUsingNonZeroWinding (true);
  73156. const float maxMiterExtensionSquared = 9.0f * thickness * thickness;
  73157. const float width = 0.5f * thickness;
  73158. // Iterate the path, creating a list of the
  73159. // left/right-hand lines along either side of it...
  73160. PathFlatteningIterator it (*sourcePath, transform, 9.0f / extraAccuracy);
  73161. Array <LineSection> subPath;
  73162. LineSection l;
  73163. l.x1 = 0;
  73164. l.y1 = 0;
  73165. const float minSegmentLength = 2.0f / (extraAccuracy * extraAccuracy);
  73166. while (it.next())
  73167. {
  73168. if (it.subPathIndex == 0)
  73169. {
  73170. if (subPath.size() > 0)
  73171. {
  73172. addSubPath (destPath, subPath, false, width, maxMiterExtensionSquared, jointStyle, endStyle);
  73173. subPath.clearQuick();
  73174. }
  73175. l.x1 = it.x1;
  73176. l.y1 = it.y1;
  73177. }
  73178. l.x2 = it.x2;
  73179. l.y2 = it.y2;
  73180. float dx = l.x2 - l.x1;
  73181. float dy = l.y2 - l.y1;
  73182. const float hypotSquared = dx*dx + dy*dy;
  73183. if (it.closesSubPath || hypotSquared > minSegmentLength || it.isLastInSubpath())
  73184. {
  73185. const float len = sqrtf (hypotSquared);
  73186. if (len == 0)
  73187. {
  73188. l.rx1 = l.rx2 = l.lx1 = l.lx2 = l.x1;
  73189. l.ry1 = l.ry2 = l.ly1 = l.ly2 = l.y1;
  73190. }
  73191. else
  73192. {
  73193. const float offset = width / len;
  73194. dx *= offset;
  73195. dy *= offset;
  73196. l.rx2 = l.x1 - dy;
  73197. l.ry2 = l.y1 + dx;
  73198. l.lx1 = l.x1 + dy;
  73199. l.ly1 = l.y1 - dx;
  73200. l.lx2 = l.x2 + dy;
  73201. l.ly2 = l.y2 - dx;
  73202. l.rx1 = l.x2 - dy;
  73203. l.ry1 = l.y2 + dx;
  73204. }
  73205. subPath.add (l);
  73206. if (it.closesSubPath)
  73207. {
  73208. addSubPath (destPath, subPath, true, width, maxMiterExtensionSquared, jointStyle, endStyle);
  73209. subPath.clearQuick();
  73210. }
  73211. else
  73212. {
  73213. l.x1 = it.x2;
  73214. l.y1 = it.y2;
  73215. }
  73216. }
  73217. }
  73218. if (subPath.size() > 0)
  73219. addSubPath (destPath, subPath, false, width, maxMiterExtensionSquared, jointStyle, endStyle);
  73220. }
  73221. void PathStrokeType::createDashedStroke (Path& destPath,
  73222. const Path& sourcePath,
  73223. const float* dashLengths,
  73224. int numDashLengths,
  73225. const AffineTransform& transform,
  73226. const float extraAccuracy) const throw()
  73227. {
  73228. if (thickness <= 0)
  73229. return;
  73230. // this should really be an even number..
  73231. jassert ((numDashLengths & 1) == 0);
  73232. Path newDestPath;
  73233. PathFlatteningIterator it (sourcePath, transform, 9.0f / extraAccuracy);
  73234. bool first = true;
  73235. int dashNum = 0;
  73236. float pos = 0.0f, lineLen = 0.0f, lineEndPos = 0.0f;
  73237. float dx = 0.0f, dy = 0.0f;
  73238. for (;;)
  73239. {
  73240. const bool isSolid = ((dashNum & 1) == 0);
  73241. const float dashLen = dashLengths [dashNum++ % numDashLengths];
  73242. jassert (dashLen > 0); // must be a positive increment!
  73243. if (dashLen <= 0)
  73244. break;
  73245. pos += dashLen;
  73246. while (pos > lineEndPos)
  73247. {
  73248. if (! it.next())
  73249. {
  73250. if (isSolid && ! first)
  73251. newDestPath.lineTo (it.x2, it.y2);
  73252. createStrokedPath (destPath, newDestPath, AffineTransform::identity, extraAccuracy);
  73253. return;
  73254. }
  73255. if (isSolid && ! first)
  73256. newDestPath.lineTo (it.x1, it.y1);
  73257. else
  73258. newDestPath.startNewSubPath (it.x1, it.y1);
  73259. dx = it.x2 - it.x1;
  73260. dy = it.y2 - it.y1;
  73261. lineLen = juce_hypotf (dx, dy);
  73262. lineEndPos += lineLen;
  73263. first = it.closesSubPath;
  73264. }
  73265. const float alpha = (pos - (lineEndPos - lineLen)) / lineLen;
  73266. if (isSolid)
  73267. newDestPath.lineTo (it.x1 + dx * alpha,
  73268. it.y1 + dy * alpha);
  73269. else
  73270. newDestPath.startNewSubPath (it.x1 + dx * alpha,
  73271. it.y1 + dy * alpha);
  73272. }
  73273. }
  73274. END_JUCE_NAMESPACE
  73275. /********* End of inlined file: juce_PathStrokeType.cpp *********/
  73276. /********* Start of inlined file: juce_Point.cpp *********/
  73277. BEGIN_JUCE_NAMESPACE
  73278. Point::Point() throw()
  73279. : x (0.0f),
  73280. y (0.0f)
  73281. {
  73282. }
  73283. Point::Point (const Point& other) throw()
  73284. : x (other.x),
  73285. y (other.y)
  73286. {
  73287. }
  73288. const Point& Point::operator= (const Point& other) throw()
  73289. {
  73290. x = other.x;
  73291. y = other.y;
  73292. return *this;
  73293. }
  73294. Point::Point (const float x_,
  73295. const float y_) throw()
  73296. : x (x_),
  73297. y (y_)
  73298. {
  73299. }
  73300. Point::~Point() throw()
  73301. {
  73302. }
  73303. void Point::setXY (const float x_,
  73304. const float y_) throw()
  73305. {
  73306. x = x_;
  73307. y = y_;
  73308. }
  73309. void Point::applyTransform (const AffineTransform& transform) throw()
  73310. {
  73311. transform.transformPoint (x, y);
  73312. }
  73313. END_JUCE_NAMESPACE
  73314. /********* End of inlined file: juce_Point.cpp *********/
  73315. /********* Start of inlined file: juce_PositionedRectangle.cpp *********/
  73316. BEGIN_JUCE_NAMESPACE
  73317. PositionedRectangle::PositionedRectangle() throw()
  73318. : x (0.0),
  73319. y (0.0),
  73320. w (0.0),
  73321. h (0.0),
  73322. xMode (anchorAtLeftOrTop | absoluteFromParentTopLeft),
  73323. yMode (anchorAtLeftOrTop | absoluteFromParentTopLeft),
  73324. wMode (absoluteSize),
  73325. hMode (absoluteSize)
  73326. {
  73327. }
  73328. PositionedRectangle::PositionedRectangle (const PositionedRectangle& other) throw()
  73329. : x (other.x),
  73330. y (other.y),
  73331. w (other.w),
  73332. h (other.h),
  73333. xMode (other.xMode),
  73334. yMode (other.yMode),
  73335. wMode (other.wMode),
  73336. hMode (other.hMode)
  73337. {
  73338. }
  73339. const PositionedRectangle& PositionedRectangle::operator= (const PositionedRectangle& other) throw()
  73340. {
  73341. x = other.x;
  73342. y = other.y;
  73343. w = other.w;
  73344. h = other.h;
  73345. xMode = other.xMode;
  73346. yMode = other.yMode;
  73347. wMode = other.wMode;
  73348. hMode = other.hMode;
  73349. return *this;
  73350. }
  73351. PositionedRectangle::~PositionedRectangle() throw()
  73352. {
  73353. }
  73354. const bool PositionedRectangle::operator== (const PositionedRectangle& other) const throw()
  73355. {
  73356. return x == other.x
  73357. && y == other.y
  73358. && w == other.w
  73359. && h == other.h
  73360. && xMode == other.xMode
  73361. && yMode == other.yMode
  73362. && wMode == other.wMode
  73363. && hMode == other.hMode;
  73364. }
  73365. const bool PositionedRectangle::operator!= (const PositionedRectangle& other) const throw()
  73366. {
  73367. return ! operator== (other);
  73368. }
  73369. PositionedRectangle::PositionedRectangle (const String& stringVersion) throw()
  73370. {
  73371. StringArray tokens;
  73372. tokens.addTokens (stringVersion, false);
  73373. decodePosString (tokens [0], xMode, x);
  73374. decodePosString (tokens [1], yMode, y);
  73375. decodeSizeString (tokens [2], wMode, w);
  73376. decodeSizeString (tokens [3], hMode, h);
  73377. }
  73378. const String PositionedRectangle::toString() const throw()
  73379. {
  73380. String s;
  73381. s.preallocateStorage (12);
  73382. addPosDescription (s, xMode, x);
  73383. s << T(' ');
  73384. addPosDescription (s, yMode, y);
  73385. s << T(' ');
  73386. addSizeDescription (s, wMode, w);
  73387. s << T(' ');
  73388. addSizeDescription (s, hMode, h);
  73389. return s;
  73390. }
  73391. const Rectangle PositionedRectangle::getRectangle (const Rectangle& target) const throw()
  73392. {
  73393. jassert (! target.isEmpty());
  73394. double x_, y_, w_, h_;
  73395. applyPosAndSize (x_, w_, x, w, xMode, wMode, target.getX(), target.getWidth());
  73396. applyPosAndSize (y_, h_, y, h, yMode, hMode, target.getY(), target.getHeight());
  73397. return Rectangle (roundToInt (x_), roundToInt (y_),
  73398. roundToInt (w_), roundToInt (h_));
  73399. }
  73400. void PositionedRectangle::getRectangleDouble (const Rectangle& target,
  73401. double& x_, double& y_,
  73402. double& w_, double& h_) const throw()
  73403. {
  73404. jassert (! target.isEmpty());
  73405. applyPosAndSize (x_, w_, x, w, xMode, wMode, target.getX(), target.getWidth());
  73406. applyPosAndSize (y_, h_, y, h, yMode, hMode, target.getY(), target.getHeight());
  73407. }
  73408. void PositionedRectangle::applyToComponent (Component& comp) const throw()
  73409. {
  73410. comp.setBounds (getRectangle (Rectangle (0, 0, comp.getParentWidth(), comp.getParentHeight())));
  73411. }
  73412. void PositionedRectangle::updateFrom (const Rectangle& rectangle,
  73413. const Rectangle& target) throw()
  73414. {
  73415. updatePosAndSize (x, w, rectangle.getX(), rectangle.getWidth(), xMode, wMode, target.getX(), target.getWidth());
  73416. updatePosAndSize (y, h, rectangle.getY(), rectangle.getHeight(), yMode, hMode, target.getY(), target.getHeight());
  73417. }
  73418. void PositionedRectangle::updateFromDouble (const double newX, const double newY,
  73419. const double newW, const double newH,
  73420. const Rectangle& target) throw()
  73421. {
  73422. updatePosAndSize (x, w, newX, newW, xMode, wMode, target.getX(), target.getWidth());
  73423. updatePosAndSize (y, h, newY, newH, yMode, hMode, target.getY(), target.getHeight());
  73424. }
  73425. void PositionedRectangle::updateFromComponent (const Component& comp) throw()
  73426. {
  73427. if (comp.getParentComponent() == 0 && ! comp.isOnDesktop())
  73428. updateFrom (comp.getBounds(), Rectangle());
  73429. else
  73430. updateFrom (comp.getBounds(), Rectangle (0, 0, comp.getParentWidth(), comp.getParentHeight()));
  73431. }
  73432. PositionedRectangle::AnchorPoint PositionedRectangle::getAnchorPointX() const throw()
  73433. {
  73434. return (AnchorPoint) (xMode & (anchorAtLeftOrTop | anchorAtRightOrBottom | anchorAtCentre));
  73435. }
  73436. PositionedRectangle::PositionMode PositionedRectangle::getPositionModeX() const throw()
  73437. {
  73438. return (PositionMode) (xMode & (absoluteFromParentTopLeft
  73439. | absoluteFromParentBottomRight
  73440. | absoluteFromParentCentre
  73441. | proportionOfParentSize));
  73442. }
  73443. PositionedRectangle::AnchorPoint PositionedRectangle::getAnchorPointY() const throw()
  73444. {
  73445. return (AnchorPoint) (yMode & (anchorAtLeftOrTop | anchorAtRightOrBottom | anchorAtCentre));
  73446. }
  73447. PositionedRectangle::PositionMode PositionedRectangle::getPositionModeY() const throw()
  73448. {
  73449. return (PositionMode) (yMode & (absoluteFromParentTopLeft
  73450. | absoluteFromParentBottomRight
  73451. | absoluteFromParentCentre
  73452. | proportionOfParentSize));
  73453. }
  73454. PositionedRectangle::SizeMode PositionedRectangle::getWidthMode() const throw()
  73455. {
  73456. return (SizeMode) wMode;
  73457. }
  73458. PositionedRectangle::SizeMode PositionedRectangle::getHeightMode() const throw()
  73459. {
  73460. return (SizeMode) hMode;
  73461. }
  73462. void PositionedRectangle::setModes (const AnchorPoint xAnchor,
  73463. const PositionMode xMode_,
  73464. const AnchorPoint yAnchor,
  73465. const PositionMode yMode_,
  73466. const SizeMode widthMode,
  73467. const SizeMode heightMode,
  73468. const Rectangle& target) throw()
  73469. {
  73470. if (xMode != (xAnchor | xMode_) || wMode != widthMode)
  73471. {
  73472. double tx, tw;
  73473. applyPosAndSize (tx, tw, x, w, xMode, wMode, target.getX(), target.getWidth());
  73474. xMode = (uint8) (xAnchor | xMode_);
  73475. wMode = (uint8) widthMode;
  73476. updatePosAndSize (x, w, tx, tw, xMode, wMode, target.getX(), target.getWidth());
  73477. }
  73478. if (yMode != (yAnchor | yMode_) || hMode != heightMode)
  73479. {
  73480. double ty, th;
  73481. applyPosAndSize (ty, th, y, h, yMode, hMode, target.getY(), target.getHeight());
  73482. yMode = (uint8) (yAnchor | yMode_);
  73483. hMode = (uint8) heightMode;
  73484. updatePosAndSize (y, h, ty, th, yMode, hMode, target.getY(), target.getHeight());
  73485. }
  73486. }
  73487. bool PositionedRectangle::isPositionAbsolute() const throw()
  73488. {
  73489. return xMode == absoluteFromParentTopLeft
  73490. && yMode == absoluteFromParentTopLeft
  73491. && wMode == absoluteSize
  73492. && hMode == absoluteSize;
  73493. }
  73494. void PositionedRectangle::addPosDescription (String& s, const uint8 mode, const double value) const throw()
  73495. {
  73496. if ((mode & proportionOfParentSize) != 0)
  73497. {
  73498. s << (roundToInt (value * 100000.0) / 1000.0) << T('%');
  73499. }
  73500. else
  73501. {
  73502. s << (roundToInt (value * 100.0) / 100.0);
  73503. if ((mode & absoluteFromParentBottomRight) != 0)
  73504. s << T('R');
  73505. else if ((mode & absoluteFromParentCentre) != 0)
  73506. s << T('C');
  73507. }
  73508. if ((mode & anchorAtRightOrBottom) != 0)
  73509. s << T('r');
  73510. else if ((mode & anchorAtCentre) != 0)
  73511. s << T('c');
  73512. }
  73513. void PositionedRectangle::addSizeDescription (String& s, const uint8 mode, const double value) const throw()
  73514. {
  73515. if (mode == proportionalSize)
  73516. s << (roundToInt (value * 100000.0) / 1000.0) << T('%');
  73517. else if (mode == parentSizeMinusAbsolute)
  73518. s << (roundToInt (value * 100.0) / 100.0) << T('M');
  73519. else
  73520. s << (roundToInt (value * 100.0) / 100.0);
  73521. }
  73522. void PositionedRectangle::decodePosString (const String& s, uint8& mode, double& value) throw()
  73523. {
  73524. if (s.containsChar (T('r')))
  73525. mode = anchorAtRightOrBottom;
  73526. else if (s.containsChar (T('c')))
  73527. mode = anchorAtCentre;
  73528. else
  73529. mode = anchorAtLeftOrTop;
  73530. if (s.containsChar (T('%')))
  73531. {
  73532. mode |= proportionOfParentSize;
  73533. value = s.removeCharacters (T("%rcRC")).getDoubleValue() / 100.0;
  73534. }
  73535. else
  73536. {
  73537. if (s.containsChar (T('R')))
  73538. mode |= absoluteFromParentBottomRight;
  73539. else if (s.containsChar (T('C')))
  73540. mode |= absoluteFromParentCentre;
  73541. else
  73542. mode |= absoluteFromParentTopLeft;
  73543. value = s.removeCharacters (T("rcRC")).getDoubleValue();
  73544. }
  73545. }
  73546. void PositionedRectangle::decodeSizeString (const String& s, uint8& mode, double& value) throw()
  73547. {
  73548. if (s.containsChar (T('%')))
  73549. {
  73550. mode = proportionalSize;
  73551. value = s.upToFirstOccurrenceOf (T("%"), false, false).getDoubleValue() / 100.0;
  73552. }
  73553. else if (s.containsChar (T('M')))
  73554. {
  73555. mode = parentSizeMinusAbsolute;
  73556. value = s.getDoubleValue();
  73557. }
  73558. else
  73559. {
  73560. mode = absoluteSize;
  73561. value = s.getDoubleValue();
  73562. }
  73563. }
  73564. void PositionedRectangle::applyPosAndSize (double& xOut, double& wOut,
  73565. const double x_, const double w_,
  73566. const uint8 xMode_, const uint8 wMode_,
  73567. const int parentPos,
  73568. const int parentSize) const throw()
  73569. {
  73570. if (wMode_ == proportionalSize)
  73571. wOut = roundToInt (w_ * parentSize);
  73572. else if (wMode_ == parentSizeMinusAbsolute)
  73573. wOut = jmax (0, parentSize - roundToInt (w_));
  73574. else
  73575. wOut = roundToInt (w_);
  73576. if ((xMode_ & proportionOfParentSize) != 0)
  73577. xOut = parentPos + x_ * parentSize;
  73578. else if ((xMode_ & absoluteFromParentBottomRight) != 0)
  73579. xOut = (parentPos + parentSize) - x_;
  73580. else if ((xMode_ & absoluteFromParentCentre) != 0)
  73581. xOut = x_ + (parentPos + parentSize / 2);
  73582. else
  73583. xOut = x_ + parentPos;
  73584. if ((xMode_ & anchorAtRightOrBottom) != 0)
  73585. xOut -= wOut;
  73586. else if ((xMode_ & anchorAtCentre) != 0)
  73587. xOut -= wOut / 2;
  73588. }
  73589. void PositionedRectangle::updatePosAndSize (double& xOut, double& wOut,
  73590. double x_, const double w_,
  73591. const uint8 xMode_, const uint8 wMode_,
  73592. const int parentPos,
  73593. const int parentSize) const throw()
  73594. {
  73595. if (wMode_ == proportionalSize)
  73596. {
  73597. if (parentSize > 0)
  73598. wOut = w_ / parentSize;
  73599. }
  73600. else if (wMode_ == parentSizeMinusAbsolute)
  73601. wOut = parentSize - w_;
  73602. else
  73603. wOut = w_;
  73604. if ((xMode_ & anchorAtRightOrBottom) != 0)
  73605. x_ += w_;
  73606. else if ((xMode_ & anchorAtCentre) != 0)
  73607. x_ += w_ / 2;
  73608. if ((xMode_ & proportionOfParentSize) != 0)
  73609. {
  73610. if (parentSize > 0)
  73611. xOut = (x_ - parentPos) / parentSize;
  73612. }
  73613. else if ((xMode_ & absoluteFromParentBottomRight) != 0)
  73614. xOut = (parentPos + parentSize) - x_;
  73615. else if ((xMode_ & absoluteFromParentCentre) != 0)
  73616. xOut = x_ - (parentPos + parentSize / 2);
  73617. else
  73618. xOut = x_ - parentPos;
  73619. }
  73620. END_JUCE_NAMESPACE
  73621. /********* End of inlined file: juce_PositionedRectangle.cpp *********/
  73622. /********* Start of inlined file: juce_Rectangle.cpp *********/
  73623. BEGIN_JUCE_NAMESPACE
  73624. Rectangle::Rectangle() throw()
  73625. : x (0),
  73626. y (0),
  73627. w (0),
  73628. h (0)
  73629. {
  73630. }
  73631. Rectangle::Rectangle (const int x_, const int y_,
  73632. const int w_, const int h_) throw()
  73633. : x (x_),
  73634. y (y_),
  73635. w (w_),
  73636. h (h_)
  73637. {
  73638. }
  73639. Rectangle::Rectangle (const int w_, const int h_) throw()
  73640. : x (0),
  73641. y (0),
  73642. w (w_),
  73643. h (h_)
  73644. {
  73645. }
  73646. Rectangle::Rectangle (const Rectangle& other) throw()
  73647. : x (other.x),
  73648. y (other.y),
  73649. w (other.w),
  73650. h (other.h)
  73651. {
  73652. }
  73653. Rectangle::~Rectangle() throw()
  73654. {
  73655. }
  73656. bool Rectangle::isEmpty() const throw()
  73657. {
  73658. return w <= 0 || h <= 0;
  73659. }
  73660. void Rectangle::setBounds (const int x_,
  73661. const int y_,
  73662. const int w_,
  73663. const int h_) throw()
  73664. {
  73665. x = x_;
  73666. y = y_;
  73667. w = w_;
  73668. h = h_;
  73669. }
  73670. void Rectangle::setPosition (const int x_,
  73671. const int y_) throw()
  73672. {
  73673. x = x_;
  73674. y = y_;
  73675. }
  73676. void Rectangle::setSize (const int w_,
  73677. const int h_) throw()
  73678. {
  73679. w = w_;
  73680. h = h_;
  73681. }
  73682. void Rectangle::setWidth (const int newWidth) throw()
  73683. {
  73684. w = newWidth;
  73685. }
  73686. void Rectangle::setHeight (const int newHeight) throw()
  73687. {
  73688. h = newHeight;
  73689. }
  73690. void Rectangle::setLeft (const int newLeft) throw()
  73691. {
  73692. w = jmax (0, x + w - newLeft);
  73693. x = newLeft;
  73694. }
  73695. void Rectangle::setTop (const int newTop) throw()
  73696. {
  73697. h = jmax (0, y + h - newTop);
  73698. y = newTop;
  73699. }
  73700. void Rectangle::setRight (const int newRight) throw()
  73701. {
  73702. x = jmin (x, newRight);
  73703. w = newRight - x;
  73704. }
  73705. void Rectangle::setBottom (const int newBottom) throw()
  73706. {
  73707. y = jmin (y, newBottom);
  73708. h = newBottom - y;
  73709. }
  73710. void Rectangle::translate (const int dx,
  73711. const int dy) throw()
  73712. {
  73713. x += dx;
  73714. y += dy;
  73715. }
  73716. const Rectangle Rectangle::translated (const int dx,
  73717. const int dy) const throw()
  73718. {
  73719. return Rectangle (x + dx, y + dy, w, h);
  73720. }
  73721. void Rectangle::expand (const int deltaX,
  73722. const int deltaY) throw()
  73723. {
  73724. const int nw = jmax (0, w + deltaX + deltaX);
  73725. const int nh = jmax (0, h + deltaY + deltaY);
  73726. setBounds (x - deltaX,
  73727. y - deltaY,
  73728. nw, nh);
  73729. }
  73730. const Rectangle Rectangle::expanded (const int deltaX,
  73731. const int deltaY) const throw()
  73732. {
  73733. const int nw = jmax (0, w + deltaX + deltaX);
  73734. const int nh = jmax (0, h + deltaY + deltaY);
  73735. return Rectangle (x - deltaX,
  73736. y - deltaY,
  73737. nw, nh);
  73738. }
  73739. void Rectangle::reduce (const int deltaX,
  73740. const int deltaY) throw()
  73741. {
  73742. expand (-deltaX, -deltaY);
  73743. }
  73744. const Rectangle Rectangle::reduced (const int deltaX,
  73745. const int deltaY) const throw()
  73746. {
  73747. return expanded (-deltaX, -deltaY);
  73748. }
  73749. bool Rectangle::operator== (const Rectangle& other) const throw()
  73750. {
  73751. return x == other.x
  73752. && y == other.y
  73753. && w == other.w
  73754. && h == other.h;
  73755. }
  73756. bool Rectangle::operator!= (const Rectangle& other) const throw()
  73757. {
  73758. return x != other.x
  73759. || y != other.y
  73760. || w != other.w
  73761. || h != other.h;
  73762. }
  73763. bool Rectangle::contains (const int px,
  73764. const int py) const throw()
  73765. {
  73766. return px >= x
  73767. && py >= y
  73768. && px < x + w
  73769. && py < y + h;
  73770. }
  73771. bool Rectangle::contains (const Rectangle& other) const throw()
  73772. {
  73773. return x <= other.x
  73774. && y <= other.y
  73775. && x + w >= other.x + other.w
  73776. && y + h >= other.y + other.h;
  73777. }
  73778. bool Rectangle::intersects (const Rectangle& other) const throw()
  73779. {
  73780. return x + w > other.x
  73781. && y + h > other.y
  73782. && x < other.x + other.w
  73783. && y < other.y + other.h
  73784. && w > 0
  73785. && h > 0;
  73786. }
  73787. const Rectangle Rectangle::getIntersection (const Rectangle& other) const throw()
  73788. {
  73789. const int nx = jmax (x, other.x);
  73790. const int ny = jmax (y, other.y);
  73791. const int nw = jmin (x + w, other.x + other.w) - nx;
  73792. const int nh = jmin (y + h, other.y + other.h) - ny;
  73793. if (nw >= 0 && nh >= 0)
  73794. return Rectangle (nx, ny, nw, nh);
  73795. else
  73796. return Rectangle();
  73797. }
  73798. bool Rectangle::intersectRectangle (int& x1, int& y1, int& w1, int& h1) const throw()
  73799. {
  73800. const int maxX = jmax (x1, x);
  73801. w1 = jmin (x1 + w1, x + w) - maxX;
  73802. if (w1 > 0)
  73803. {
  73804. const int maxY = jmax (y1, y);
  73805. h1 = jmin (y1 + h1, y + h) - maxY;
  73806. if (h1 > 0)
  73807. {
  73808. x1 = maxX;
  73809. y1 = maxY;
  73810. return true;
  73811. }
  73812. }
  73813. return false;
  73814. }
  73815. bool Rectangle::intersectRectangles (int& x1, int& y1, int& w1, int& h1,
  73816. int x2, int y2, int w2, int h2) throw()
  73817. {
  73818. const int x = jmax (x1, x2);
  73819. w1 = jmin (x1 + w1, x2 + w2) - x;
  73820. if (w1 > 0)
  73821. {
  73822. const int y = jmax (y1, y2);
  73823. h1 = jmin (y1 + h1, y2 + h2) - y;
  73824. if (h1 > 0)
  73825. {
  73826. x1 = x;
  73827. y1 = y;
  73828. return true;
  73829. }
  73830. }
  73831. return false;
  73832. }
  73833. const Rectangle Rectangle::getUnion (const Rectangle& other) const throw()
  73834. {
  73835. const int newX = jmin (x, other.x);
  73836. const int newY = jmin (y, other.y);
  73837. return Rectangle (newX, newY,
  73838. jmax (x + w, other.x + other.w) - newX,
  73839. jmax (y + h, other.y + other.h) - newY);
  73840. }
  73841. bool Rectangle::enlargeIfAdjacent (const Rectangle& other) throw()
  73842. {
  73843. if (x == other.x && getRight() == other.getRight()
  73844. && (other.getBottom() >= y && other.y <= getBottom()))
  73845. {
  73846. const int newY = jmin (y, other.y);
  73847. h = jmax (getBottom(), other.getBottom()) - newY;
  73848. y = newY;
  73849. return true;
  73850. }
  73851. else if (y == other.y && getBottom() == other.getBottom()
  73852. && (other.getRight() >= x && other.x <= getRight()))
  73853. {
  73854. const int newX = jmin (x, other.x);
  73855. w = jmax (getRight(), other.getRight()) - newX;
  73856. x = newX;
  73857. return true;
  73858. }
  73859. return false;
  73860. }
  73861. bool Rectangle::reduceIfPartlyContainedIn (const Rectangle& other) throw()
  73862. {
  73863. int inside = 0;
  73864. const int otherR = other.getRight();
  73865. if (x >= other.x && x < otherR)
  73866. inside = 1;
  73867. const int otherB = other.getBottom();
  73868. if (y >= other.y && y < otherB)
  73869. inside |= 2;
  73870. const int r = x + w;
  73871. if (r >= other.x && r < otherR)
  73872. inside |= 4;
  73873. const int b = y + h;
  73874. if (b >= other.y && b < otherB)
  73875. inside |= 8;
  73876. switch (inside)
  73877. {
  73878. case 1 + 2 + 8:
  73879. w = r - otherR;
  73880. x = otherR;
  73881. return true;
  73882. case 1 + 2 + 4:
  73883. h = b - otherB;
  73884. y = otherB;
  73885. return true;
  73886. case 2 + 4 + 8:
  73887. w = other.x - x;
  73888. return true;
  73889. case 1 + 4 + 8:
  73890. h = other.y - y;
  73891. return true;
  73892. }
  73893. return false;
  73894. }
  73895. const String Rectangle::toString() const throw()
  73896. {
  73897. String s;
  73898. s.preallocateStorage (16);
  73899. s << x << T(' ')
  73900. << y << T(' ')
  73901. << w << T(' ')
  73902. << h;
  73903. return s;
  73904. }
  73905. const Rectangle Rectangle::fromString (const String& stringVersion)
  73906. {
  73907. StringArray toks;
  73908. toks.addTokens (stringVersion.trim(), T(",; \t\r\n"), 0);
  73909. return Rectangle (toks[0].trim().getIntValue(),
  73910. toks[1].trim().getIntValue(),
  73911. toks[2].trim().getIntValue(),
  73912. toks[3].trim().getIntValue());
  73913. }
  73914. END_JUCE_NAMESPACE
  73915. /********* End of inlined file: juce_Rectangle.cpp *********/
  73916. /********* Start of inlined file: juce_RectangleList.cpp *********/
  73917. BEGIN_JUCE_NAMESPACE
  73918. RectangleList::RectangleList() throw()
  73919. {
  73920. }
  73921. RectangleList::RectangleList (const Rectangle& rect) throw()
  73922. {
  73923. if (! rect.isEmpty())
  73924. rects.add (rect);
  73925. }
  73926. RectangleList::RectangleList (const RectangleList& other) throw()
  73927. : rects (other.rects)
  73928. {
  73929. }
  73930. const RectangleList& RectangleList::operator= (const RectangleList& other) throw()
  73931. {
  73932. rects = other.rects;
  73933. return *this;
  73934. }
  73935. RectangleList::~RectangleList() throw()
  73936. {
  73937. }
  73938. void RectangleList::clear() throw()
  73939. {
  73940. rects.clearQuick();
  73941. }
  73942. const Rectangle RectangleList::getRectangle (const int index) const throw()
  73943. {
  73944. if (((unsigned int) index) < (unsigned int) rects.size())
  73945. return rects.getReference (index);
  73946. return Rectangle();
  73947. }
  73948. bool RectangleList::isEmpty() const throw()
  73949. {
  73950. return rects.size() == 0;
  73951. }
  73952. RectangleList::Iterator::Iterator (const RectangleList& list) throw()
  73953. : current (0),
  73954. owner (list),
  73955. index (list.rects.size())
  73956. {
  73957. }
  73958. RectangleList::Iterator::~Iterator() throw()
  73959. {
  73960. }
  73961. bool RectangleList::Iterator::next() throw()
  73962. {
  73963. if (--index >= 0)
  73964. {
  73965. current = & (owner.rects.getReference (index));
  73966. return true;
  73967. }
  73968. return false;
  73969. }
  73970. void RectangleList::add (const Rectangle& rect) throw()
  73971. {
  73972. if (! rect.isEmpty())
  73973. {
  73974. if (rects.size() == 0)
  73975. {
  73976. rects.add (rect);
  73977. }
  73978. else
  73979. {
  73980. bool anyOverlaps = false;
  73981. int i;
  73982. for (i = rects.size(); --i >= 0;)
  73983. {
  73984. Rectangle& ourRect = rects.getReference (i);
  73985. if (rect.intersects (ourRect))
  73986. {
  73987. if (rect.contains (ourRect))
  73988. rects.remove (i);
  73989. else if (! ourRect.reduceIfPartlyContainedIn (rect))
  73990. anyOverlaps = true;
  73991. }
  73992. }
  73993. if (anyOverlaps && rects.size() > 0)
  73994. {
  73995. RectangleList r (rect);
  73996. for (i = rects.size(); --i >= 0;)
  73997. {
  73998. const Rectangle& ourRect = rects.getReference (i);
  73999. if (rect.intersects (ourRect))
  74000. {
  74001. r.subtract (ourRect);
  74002. if (r.rects.size() == 0)
  74003. return;
  74004. }
  74005. }
  74006. for (i = r.getNumRectangles(); --i >= 0;)
  74007. rects.add (r.rects.getReference (i));
  74008. }
  74009. else
  74010. {
  74011. rects.add (rect);
  74012. }
  74013. }
  74014. }
  74015. }
  74016. void RectangleList::addWithoutMerging (const Rectangle& rect) throw()
  74017. {
  74018. rects.add (rect);
  74019. }
  74020. void RectangleList::add (const int x, const int y, const int w, const int h) throw()
  74021. {
  74022. if (rects.size() == 0)
  74023. {
  74024. if (w > 0 && h > 0)
  74025. rects.add (Rectangle (x, y, w, h));
  74026. }
  74027. else
  74028. {
  74029. add (Rectangle (x, y, w, h));
  74030. }
  74031. }
  74032. void RectangleList::add (const RectangleList& other) throw()
  74033. {
  74034. for (int i = 0; i < other.rects.size(); ++i)
  74035. add (other.rects.getReference (i));
  74036. }
  74037. void RectangleList::subtract (const Rectangle& rect) throw()
  74038. {
  74039. const int originalNumRects = rects.size();
  74040. if (originalNumRects > 0)
  74041. {
  74042. const int x1 = rect.x;
  74043. const int y1 = rect.y;
  74044. const int x2 = x1 + rect.w;
  74045. const int y2 = y1 + rect.h;
  74046. for (int i = getNumRectangles(); --i >= 0;)
  74047. {
  74048. Rectangle& r = rects.getReference (i);
  74049. const int rx1 = r.x;
  74050. const int ry1 = r.y;
  74051. const int rx2 = rx1 + r.w;
  74052. const int ry2 = ry1 + r.h;
  74053. if (! (x2 <= rx1 || x1 >= rx2 || y2 <= ry1 || y1 >= ry2))
  74054. {
  74055. if (x1 > rx1 && x1 < rx2)
  74056. {
  74057. if (y1 <= ry1 && y2 >= ry2 && x2 >= rx2)
  74058. {
  74059. r.w = x1 - rx1;
  74060. }
  74061. else
  74062. {
  74063. r.x = x1;
  74064. r.w = rx2 - x1;
  74065. rects.insert (i + 1, Rectangle (rx1, ry1, x1 - rx1, ry2 - ry1));
  74066. i += 2;
  74067. }
  74068. }
  74069. else if (x2 > rx1 && x2 < rx2)
  74070. {
  74071. r.x = x2;
  74072. r.w = rx2 - x2;
  74073. if (y1 > ry1 || y2 < ry2 || x1 > rx1)
  74074. {
  74075. rects.insert (i + 1, Rectangle (rx1, ry1, x2 - rx1, ry2 - ry1));
  74076. i += 2;
  74077. }
  74078. }
  74079. else if (y1 > ry1 && y1 < ry2)
  74080. {
  74081. if (x1 <= rx1 && x2 >= rx2 && y2 >= ry2)
  74082. {
  74083. r.h = y1 - ry1;
  74084. }
  74085. else
  74086. {
  74087. r.y = y1;
  74088. r.h = ry2 - y1;
  74089. rects.insert (i + 1, Rectangle (rx1, ry1, rx2 - rx1, y1 - ry1));
  74090. i += 2;
  74091. }
  74092. }
  74093. else if (y2 > ry1 && y2 < ry2)
  74094. {
  74095. r.y = y2;
  74096. r.h = ry2 - y2;
  74097. if (x1 > rx1 || x2 < rx2 || y1 > ry1)
  74098. {
  74099. rects.insert (i + 1, Rectangle (rx1, ry1, rx2 - rx1, y2 - ry1));
  74100. i += 2;
  74101. }
  74102. }
  74103. else
  74104. {
  74105. rects.remove (i);
  74106. }
  74107. }
  74108. }
  74109. if (rects.size() > originalNumRects + 10)
  74110. consolidate();
  74111. }
  74112. }
  74113. void RectangleList::subtract (const RectangleList& otherList) throw()
  74114. {
  74115. for (int i = otherList.rects.size(); --i >= 0;)
  74116. subtract (otherList.rects.getReference (i));
  74117. }
  74118. bool RectangleList::clipTo (const Rectangle& rect) throw()
  74119. {
  74120. bool notEmpty = false;
  74121. if (rect.isEmpty())
  74122. {
  74123. clear();
  74124. }
  74125. else
  74126. {
  74127. for (int i = rects.size(); --i >= 0;)
  74128. {
  74129. Rectangle& r = rects.getReference (i);
  74130. if (! rect.intersectRectangle (r.x, r.y, r.w, r.h))
  74131. rects.remove (i);
  74132. else
  74133. notEmpty = true;
  74134. }
  74135. }
  74136. return notEmpty;
  74137. }
  74138. bool RectangleList::clipTo (const RectangleList& other) throw()
  74139. {
  74140. if (rects.size() == 0)
  74141. return false;
  74142. RectangleList result;
  74143. for (int j = 0; j < rects.size(); ++j)
  74144. {
  74145. const Rectangle& rect = rects.getReference (j);
  74146. for (int i = other.rects.size(); --i >= 0;)
  74147. {
  74148. Rectangle r (other.rects.getReference (i));
  74149. if (rect.intersectRectangle (r.x, r.y, r.w, r.h))
  74150. result.rects.add (r);
  74151. }
  74152. }
  74153. swapWith (result);
  74154. return ! isEmpty();
  74155. }
  74156. bool RectangleList::getIntersectionWith (const Rectangle& rect, RectangleList& destRegion) const throw()
  74157. {
  74158. destRegion.clear();
  74159. if (! rect.isEmpty())
  74160. {
  74161. for (int i = rects.size(); --i >= 0;)
  74162. {
  74163. Rectangle r (rects.getReference (i));
  74164. if (rect.intersectRectangle (r.x, r.y, r.w, r.h))
  74165. destRegion.rects.add (r);
  74166. }
  74167. }
  74168. return destRegion.rects.size() > 0;
  74169. }
  74170. void RectangleList::swapWith (RectangleList& otherList) throw()
  74171. {
  74172. rects.swapWithArray (otherList.rects);
  74173. }
  74174. void RectangleList::consolidate() throw()
  74175. {
  74176. int i;
  74177. for (i = 0; i < getNumRectangles() - 1; ++i)
  74178. {
  74179. Rectangle& r = rects.getReference (i);
  74180. const int rx1 = r.x;
  74181. const int ry1 = r.y;
  74182. const int rx2 = rx1 + r.w;
  74183. const int ry2 = ry1 + r.h;
  74184. for (int j = rects.size(); --j > i;)
  74185. {
  74186. Rectangle& r2 = rects.getReference (j);
  74187. const int jrx1 = r2.x;
  74188. const int jry1 = r2.y;
  74189. const int jrx2 = jrx1 + r2.w;
  74190. const int jry2 = jry1 + r2.h;
  74191. // if the vertical edges of any blocks are touching and their horizontals don't
  74192. // line up, split them horizontally..
  74193. if (jrx1 == rx2 || jrx2 == rx1)
  74194. {
  74195. if (jry1 > ry1 && jry1 < ry2)
  74196. {
  74197. r.h = jry1 - ry1;
  74198. rects.add (Rectangle (rx1, jry1, rx2 - rx1, ry2 - jry1));
  74199. i = -1;
  74200. break;
  74201. }
  74202. if (jry2 > ry1 && jry2 < ry2)
  74203. {
  74204. r.h = jry2 - ry1;
  74205. rects.add (Rectangle (rx1, jry2, rx2 - rx1, ry2 - jry2));
  74206. i = -1;
  74207. break;
  74208. }
  74209. else if (ry1 > jry1 && ry1 < jry2)
  74210. {
  74211. r2.h = ry1 - jry1;
  74212. rects.add (Rectangle (jrx1, ry1, jrx2 - jrx1, jry2 - ry1));
  74213. i = -1;
  74214. break;
  74215. }
  74216. else if (ry2 > jry1 && ry2 < jry2)
  74217. {
  74218. r2.h = ry2 - jry1;
  74219. rects.add (Rectangle (jrx1, ry2, jrx2 - jrx1, jry2 - ry2));
  74220. i = -1;
  74221. break;
  74222. }
  74223. }
  74224. }
  74225. }
  74226. for (i = 0; i < rects.size() - 1; ++i)
  74227. {
  74228. Rectangle& r = rects.getReference (i);
  74229. for (int j = rects.size(); --j > i;)
  74230. {
  74231. if (r.enlargeIfAdjacent (rects.getReference (j)))
  74232. {
  74233. rects.remove (j);
  74234. i = -1;
  74235. break;
  74236. }
  74237. }
  74238. }
  74239. }
  74240. bool RectangleList::containsPoint (const int x, const int y) const throw()
  74241. {
  74242. for (int i = getNumRectangles(); --i >= 0;)
  74243. if (rects.getReference (i).contains (x, y))
  74244. return true;
  74245. return false;
  74246. }
  74247. bool RectangleList::containsRectangle (const Rectangle& rectangleToCheck) const throw()
  74248. {
  74249. if (rects.size() > 1)
  74250. {
  74251. RectangleList r (rectangleToCheck);
  74252. for (int i = rects.size(); --i >= 0;)
  74253. {
  74254. r.subtract (rects.getReference (i));
  74255. if (r.rects.size() == 0)
  74256. return true;
  74257. }
  74258. }
  74259. else if (rects.size() > 0)
  74260. {
  74261. return rects.getReference (0).contains (rectangleToCheck);
  74262. }
  74263. return false;
  74264. }
  74265. bool RectangleList::intersectsRectangle (const Rectangle& rectangleToCheck) const throw()
  74266. {
  74267. for (int i = rects.size(); --i >= 0;)
  74268. if (rects.getReference (i).intersects (rectangleToCheck))
  74269. return true;
  74270. return false;
  74271. }
  74272. bool RectangleList::intersects (const RectangleList& other) const throw()
  74273. {
  74274. for (int i = rects.size(); --i >= 0;)
  74275. if (other.intersectsRectangle (rects.getReference (i)))
  74276. return true;
  74277. return false;
  74278. }
  74279. const Rectangle RectangleList::getBounds() const throw()
  74280. {
  74281. if (rects.size() <= 1)
  74282. {
  74283. if (rects.size() == 0)
  74284. return Rectangle();
  74285. else
  74286. return rects.getReference (0);
  74287. }
  74288. else
  74289. {
  74290. const Rectangle& r = rects.getReference (0);
  74291. int minX = r.x;
  74292. int minY = r.y;
  74293. int maxX = minX + r.w;
  74294. int maxY = minY + r.h;
  74295. for (int i = rects.size(); --i > 0;)
  74296. {
  74297. const Rectangle& r2 = rects.getReference (i);
  74298. minX = jmin (minX, r2.x);
  74299. minY = jmin (minY, r2.y);
  74300. maxX = jmax (maxX, r2.getRight());
  74301. maxY = jmax (maxY, r2.getBottom());
  74302. }
  74303. return Rectangle (minX, minY, maxX - minX, maxY - minY);
  74304. }
  74305. }
  74306. void RectangleList::offsetAll (const int dx, const int dy) throw()
  74307. {
  74308. for (int i = rects.size(); --i >= 0;)
  74309. {
  74310. Rectangle& r = rects.getReference (i);
  74311. r.x += dx;
  74312. r.y += dy;
  74313. }
  74314. }
  74315. const Path RectangleList::toPath() const throw()
  74316. {
  74317. Path p;
  74318. for (int i = rects.size(); --i >= 0;)
  74319. {
  74320. const Rectangle& r = rects.getReference (i);
  74321. p.addRectangle ((float) r.x,
  74322. (float) r.y,
  74323. (float) r.w,
  74324. (float) r.h);
  74325. }
  74326. return p;
  74327. }
  74328. END_JUCE_NAMESPACE
  74329. /********* End of inlined file: juce_RectangleList.cpp *********/
  74330. /********* Start of inlined file: juce_Image.cpp *********/
  74331. BEGIN_JUCE_NAMESPACE
  74332. static const int fullAlphaThreshold = 253;
  74333. Image::Image (const PixelFormat format_,
  74334. const int imageWidth_,
  74335. const int imageHeight_)
  74336. : format (format_),
  74337. imageWidth (imageWidth_),
  74338. imageHeight (imageHeight_),
  74339. imageData (0)
  74340. {
  74341. jassert (format_ == RGB || format_ == ARGB || format_ == SingleChannel);
  74342. jassert (imageWidth_ > 0 && imageHeight_ > 0); // it's illegal to create a zero-sized image - the
  74343. // actual image will be at least 1x1.
  74344. }
  74345. Image::Image (const PixelFormat format_,
  74346. const int imageWidth_,
  74347. const int imageHeight_,
  74348. const bool clearImage)
  74349. : format (format_),
  74350. imageWidth (imageWidth_),
  74351. imageHeight (imageHeight_)
  74352. {
  74353. jassert (format_ == RGB || format_ == ARGB || format_ == SingleChannel);
  74354. jassert (imageWidth_ > 0 && imageHeight_ > 0); // it's illegal to create a zero-sized image - the
  74355. // actual image will be at least 1x1.
  74356. pixelStride = (format == RGB) ? 3 : ((format == ARGB) ? 4 : 1);
  74357. lineStride = (pixelStride * jmax (1, imageWidth_) + 3) & ~3;
  74358. imageDataAllocated.allocate (lineStride * jmax (1, imageHeight_), clearImage);
  74359. imageData = imageDataAllocated;
  74360. }
  74361. Image::Image (const Image& other)
  74362. : format (other.format),
  74363. imageWidth (other.imageWidth),
  74364. imageHeight (other.imageHeight)
  74365. {
  74366. pixelStride = (format == RGB) ? 3 : ((format == ARGB) ? 4 : 1);
  74367. lineStride = (pixelStride * jmax (1, imageWidth) + 3) & ~3;
  74368. imageDataAllocated.malloc (lineStride * jmax (1, imageHeight));
  74369. imageData = imageDataAllocated;
  74370. BitmapData srcData (other, 0, 0, imageWidth, imageHeight);
  74371. setPixelData (0, 0, imageWidth, imageHeight, srcData.data, srcData.lineStride);
  74372. }
  74373. Image::~Image()
  74374. {
  74375. }
  74376. LowLevelGraphicsContext* Image::createLowLevelContext()
  74377. {
  74378. return new LowLevelGraphicsSoftwareRenderer (*this);
  74379. }
  74380. Image::BitmapData::BitmapData (Image& image, int x, int y, int w, int h, const bool /*makeWritable*/)
  74381. : data (image.imageData + image.lineStride * y + image.pixelStride * x),
  74382. lineStride (image.lineStride),
  74383. pixelStride (image.pixelStride),
  74384. width (w),
  74385. height (h)
  74386. {
  74387. jassert (x >= 0 && y >= 0 && w > 0 && h > 0 && x + w <= image.getWidth() && y + h <= image.getHeight());
  74388. }
  74389. Image::BitmapData::BitmapData (const Image& image, int x, int y, int w, int h)
  74390. : data (image.imageData + image.lineStride * y + image.pixelStride * x),
  74391. lineStride (image.lineStride),
  74392. pixelStride (image.pixelStride),
  74393. width (w),
  74394. height (h)
  74395. {
  74396. jassert (x >= 0 && y >= 0 && w > 0 && h > 0 && x + w <= image.getWidth() && y + h <= image.getHeight());
  74397. }
  74398. Image::BitmapData::~BitmapData()
  74399. {
  74400. }
  74401. void Image::setPixelData (int x, int y, int w, int h,
  74402. const uint8* sourcePixelData, int sourceLineStride)
  74403. {
  74404. jassert (x >= 0 && y >= 0 && w > 0 && h > 0 && x + w <= imageWidth && y + h <= imageHeight);
  74405. if (Rectangle::intersectRectangles (x, y, w, h, 0, 0, imageWidth, imageHeight))
  74406. {
  74407. const BitmapData dest (*this, x, y, w, h, true);
  74408. for (int i = 0; i < h; ++i)
  74409. {
  74410. memcpy (dest.getLinePointer(i),
  74411. sourcePixelData + sourceLineStride * i,
  74412. w * dest.pixelStride);
  74413. }
  74414. }
  74415. }
  74416. void Image::clear (int dx, int dy, int dw, int dh,
  74417. const Colour& colourToClearTo)
  74418. {
  74419. const PixelARGB col (colourToClearTo.getPixelARGB());
  74420. const BitmapData destData (*this, dx, dy, dw, dh, true);
  74421. uint8* dest = destData.data;
  74422. while (--dh >= 0)
  74423. {
  74424. uint8* line = dest;
  74425. dest += destData.lineStride;
  74426. if (isARGB())
  74427. {
  74428. for (int x = dw; --x >= 0;)
  74429. {
  74430. ((PixelARGB*) line)->set (col);
  74431. line += destData.pixelStride;
  74432. }
  74433. }
  74434. else if (isRGB())
  74435. {
  74436. for (int x = dw; --x >= 0;)
  74437. {
  74438. ((PixelRGB*) line)->set (col);
  74439. line += destData.pixelStride;
  74440. }
  74441. }
  74442. else
  74443. {
  74444. for (int x = dw; --x >= 0;)
  74445. {
  74446. *line = col.getAlpha();
  74447. line += destData.pixelStride;
  74448. }
  74449. }
  74450. }
  74451. }
  74452. Image* Image::createCopy (int newWidth, int newHeight,
  74453. const Graphics::ResamplingQuality quality) const
  74454. {
  74455. if (newWidth < 0)
  74456. newWidth = imageWidth;
  74457. if (newHeight < 0)
  74458. newHeight = imageHeight;
  74459. Image* const newImage = Image::createNativeImage (format, newWidth, newHeight, true);
  74460. Graphics g (*newImage);
  74461. g.setImageResamplingQuality (quality);
  74462. g.drawImage (this,
  74463. 0, 0, newWidth, newHeight,
  74464. 0, 0, imageWidth, imageHeight,
  74465. false);
  74466. return newImage;
  74467. }
  74468. Image* Image::createCopyOfAlphaChannel() const
  74469. {
  74470. jassert (format != SingleChannel);
  74471. Image* const newImage = Image::createNativeImage (SingleChannel, imageWidth, imageHeight, false);
  74472. if (! hasAlphaChannel())
  74473. {
  74474. newImage->clear (0, 0, imageWidth, imageHeight, Colours::black);
  74475. }
  74476. else
  74477. {
  74478. const BitmapData destData (*newImage, 0, 0, imageWidth, imageHeight, true);
  74479. const BitmapData srcData (*this, 0, 0, imageWidth, imageHeight);
  74480. for (int y = 0; y < imageHeight; ++y)
  74481. {
  74482. const PixelARGB* src = (const PixelARGB*) srcData.getLinePointer(y);
  74483. uint8* dst = destData.getLinePointer (y);
  74484. for (int x = imageWidth; --x >= 0;)
  74485. {
  74486. *dst++ = src->getAlpha();
  74487. ++src;
  74488. }
  74489. }
  74490. }
  74491. return newImage;
  74492. }
  74493. const Colour Image::getPixelAt (const int x, const int y) const
  74494. {
  74495. Colour c;
  74496. if (((unsigned int) x) < (unsigned int) imageWidth
  74497. && ((unsigned int) y) < (unsigned int) imageHeight)
  74498. {
  74499. const BitmapData srcData (*this, x, y, 1, 1);
  74500. if (isARGB())
  74501. {
  74502. PixelARGB p (*(const PixelARGB*) srcData.data);
  74503. p.unpremultiply();
  74504. c = Colour (p.getARGB());
  74505. }
  74506. else if (isRGB())
  74507. c = Colour (((const PixelRGB*) srcData.data)->getARGB());
  74508. else
  74509. c = Colour ((uint8) 0, (uint8) 0, (uint8) 0, *(srcData.data));
  74510. }
  74511. return c;
  74512. }
  74513. void Image::setPixelAt (const int x, const int y,
  74514. const Colour& colour)
  74515. {
  74516. if (((unsigned int) x) < (unsigned int) imageWidth
  74517. && ((unsigned int) y) < (unsigned int) imageHeight)
  74518. {
  74519. const BitmapData destData (*this, x, y, 1, 1, true);
  74520. const PixelARGB col (colour.getPixelARGB());
  74521. if (isARGB())
  74522. ((PixelARGB*) destData.data)->set (col);
  74523. else if (isRGB())
  74524. ((PixelRGB*) destData.data)->set (col);
  74525. else
  74526. *(destData.data) = col.getAlpha();
  74527. }
  74528. }
  74529. void Image::multiplyAlphaAt (const int x, const int y,
  74530. const float multiplier)
  74531. {
  74532. if (((unsigned int) x) < (unsigned int) imageWidth
  74533. && ((unsigned int) y) < (unsigned int) imageHeight
  74534. && hasAlphaChannel())
  74535. {
  74536. const BitmapData destData (*this, x, y, 1, 1, true);
  74537. if (isARGB())
  74538. ((PixelARGB*) destData.data)->multiplyAlpha (multiplier);
  74539. else
  74540. *(destData.data) = (uint8) (*(destData.data) * multiplier);
  74541. }
  74542. }
  74543. void Image::multiplyAllAlphas (const float amountToMultiplyBy)
  74544. {
  74545. if (hasAlphaChannel())
  74546. {
  74547. const BitmapData destData (*this, 0, 0, getWidth(), getHeight(), true);
  74548. if (isARGB())
  74549. {
  74550. for (int y = 0; y < imageHeight; ++y)
  74551. {
  74552. uint8* p = destData.getLinePointer (y);
  74553. for (int x = 0; x < imageWidth; ++x)
  74554. {
  74555. ((PixelARGB*) p)->multiplyAlpha (amountToMultiplyBy);
  74556. p += destData.pixelStride;
  74557. }
  74558. }
  74559. }
  74560. else
  74561. {
  74562. for (int y = 0; y < imageHeight; ++y)
  74563. {
  74564. uint8* p = destData.getLinePointer (y);
  74565. for (int x = 0; x < imageWidth; ++x)
  74566. {
  74567. *p = (uint8) (*p * amountToMultiplyBy);
  74568. p += destData.pixelStride;
  74569. }
  74570. }
  74571. }
  74572. }
  74573. else
  74574. {
  74575. jassertfalse // can't do this without an alpha-channel!
  74576. }
  74577. }
  74578. void Image::desaturate()
  74579. {
  74580. if (isARGB() || isRGB())
  74581. {
  74582. const BitmapData destData (*this, 0, 0, getWidth(), getHeight(), true);
  74583. if (isARGB())
  74584. {
  74585. for (int y = 0; y < imageHeight; ++y)
  74586. {
  74587. uint8* p = destData.getLinePointer (y);
  74588. for (int x = 0; x < imageWidth; ++x)
  74589. {
  74590. ((PixelARGB*) p)->desaturate();
  74591. p += destData.pixelStride;
  74592. }
  74593. }
  74594. }
  74595. else
  74596. {
  74597. for (int y = 0; y < imageHeight; ++y)
  74598. {
  74599. uint8* p = destData.getLinePointer (y);
  74600. for (int x = 0; x < imageWidth; ++x)
  74601. {
  74602. ((PixelRGB*) p)->desaturate();
  74603. p += destData.pixelStride;
  74604. }
  74605. }
  74606. }
  74607. }
  74608. }
  74609. void Image::createSolidAreaMask (RectangleList& result, const float alphaThreshold) const
  74610. {
  74611. if (hasAlphaChannel())
  74612. {
  74613. const uint8 threshold = (uint8) jlimit (0, 255, roundToInt (alphaThreshold * 255.0f));
  74614. SparseSet <int> pixelsOnRow;
  74615. const BitmapData srcData (*this, 0, 0, getWidth(), getHeight());
  74616. for (int y = 0; y < imageHeight; ++y)
  74617. {
  74618. pixelsOnRow.clear();
  74619. const uint8* lineData = srcData.getLinePointer (y);
  74620. if (isARGB())
  74621. {
  74622. for (int x = 0; x < imageWidth; ++x)
  74623. {
  74624. if (((const PixelARGB*) lineData)->getAlpha() >= threshold)
  74625. pixelsOnRow.addRange (x, 1);
  74626. lineData += srcData.pixelStride;
  74627. }
  74628. }
  74629. else
  74630. {
  74631. for (int x = 0; x < imageWidth; ++x)
  74632. {
  74633. if (*lineData >= threshold)
  74634. pixelsOnRow.addRange (x, 1);
  74635. lineData += srcData.pixelStride;
  74636. }
  74637. }
  74638. for (int i = 0; i < pixelsOnRow.getNumRanges(); ++i)
  74639. {
  74640. int x, w;
  74641. if (pixelsOnRow.getRange (i, x, w))
  74642. result.add (Rectangle (x, y, w, 1));
  74643. }
  74644. result.consolidate();
  74645. }
  74646. }
  74647. else
  74648. {
  74649. result.add (0, 0, imageWidth, imageHeight);
  74650. }
  74651. }
  74652. void Image::moveImageSection (int dx, int dy,
  74653. int sx, int sy,
  74654. int w, int h)
  74655. {
  74656. if (dx < 0)
  74657. {
  74658. w += dx;
  74659. sx -= dx;
  74660. dx = 0;
  74661. }
  74662. if (dy < 0)
  74663. {
  74664. h += dy;
  74665. sy -= dy;
  74666. dy = 0;
  74667. }
  74668. if (sx < 0)
  74669. {
  74670. w += sx;
  74671. dx -= sx;
  74672. sx = 0;
  74673. }
  74674. if (sy < 0)
  74675. {
  74676. h += sy;
  74677. dy -= sy;
  74678. sy = 0;
  74679. }
  74680. const int minX = jmin (dx, sx);
  74681. const int minY = jmin (dy, sy);
  74682. w = jmin (w, getWidth() - jmax (sx, dx));
  74683. h = jmin (h, getHeight() - jmax (sy, dy));
  74684. if (w > 0 && h > 0)
  74685. {
  74686. const int maxX = jmax (dx, sx) + w;
  74687. const int maxY = jmax (dy, sy) + h;
  74688. const BitmapData destData (*this, minX, minY, maxX - minX, maxY - minY, true);
  74689. uint8* dst = destData.getPixelPointer (dx - minX, dy - minY);
  74690. const uint8* src = destData.getPixelPointer (sx - minX, sy - minY);
  74691. const int lineSize = destData.pixelStride * w;
  74692. if (dy > sy)
  74693. {
  74694. while (--h >= 0)
  74695. {
  74696. const int offset = h * destData.lineStride;
  74697. memmove (dst + offset, src + offset, lineSize);
  74698. }
  74699. }
  74700. else if (dst != src)
  74701. {
  74702. while (--h >= 0)
  74703. {
  74704. memmove (dst, src, lineSize);
  74705. dst += destData.lineStride;
  74706. src += destData.lineStride;
  74707. }
  74708. }
  74709. }
  74710. }
  74711. END_JUCE_NAMESPACE
  74712. /********* End of inlined file: juce_Image.cpp *********/
  74713. /********* Start of inlined file: juce_ImageCache.cpp *********/
  74714. BEGIN_JUCE_NAMESPACE
  74715. struct ImageCacheItem
  74716. {
  74717. ScopedPointer <Image> image;
  74718. int64 hashCode;
  74719. int refCount;
  74720. uint32 releaseTime;
  74721. juce_UseDebuggingNewOperator
  74722. };
  74723. static ImageCache* instance = 0;
  74724. static int cacheTimeout = 5000;
  74725. ImageCache::ImageCache()
  74726. {
  74727. }
  74728. ImageCache::~ImageCache()
  74729. {
  74730. jassert (instance == this);
  74731. instance = 0;
  74732. }
  74733. Image* ImageCache::getFromHashCode (const int64 hashCode)
  74734. {
  74735. if (instance != 0)
  74736. {
  74737. const ScopedLock sl (instance->lock);
  74738. for (int i = instance->images.size(); --i >= 0;)
  74739. {
  74740. ImageCacheItem* const ci = instance->images.getUnchecked(i);
  74741. if (ci->hashCode == hashCode)
  74742. {
  74743. ci->refCount++;
  74744. return ci->image;
  74745. }
  74746. }
  74747. }
  74748. return 0;
  74749. }
  74750. void ImageCache::addImageToCache (Image* const image,
  74751. const int64 hashCode)
  74752. {
  74753. if (image != 0)
  74754. {
  74755. if (instance == 0)
  74756. instance = new ImageCache();
  74757. ImageCacheItem* const newC = new ImageCacheItem();
  74758. newC->hashCode = hashCode;
  74759. newC->image = image;
  74760. newC->refCount = 1;
  74761. newC->releaseTime = 0;
  74762. const ScopedLock sl (instance->lock);
  74763. instance->images.add (newC);
  74764. }
  74765. }
  74766. void ImageCache::release (Image* const imageToRelease)
  74767. {
  74768. if (imageToRelease != 0 && instance != 0)
  74769. {
  74770. const ScopedLock sl (instance->lock);
  74771. for (int i = instance->images.size(); --i >= 0;)
  74772. {
  74773. ImageCacheItem* const ci = instance->images.getUnchecked(i);
  74774. if ((Image*) ci->image == imageToRelease)
  74775. {
  74776. if (--(ci->refCount) == 0)
  74777. ci->releaseTime = Time::getApproximateMillisecondCounter();
  74778. if (! instance->isTimerRunning())
  74779. instance->startTimer (999);
  74780. break;
  74781. }
  74782. }
  74783. }
  74784. }
  74785. void ImageCache::releaseOrDelete (Image* const imageToRelease)
  74786. {
  74787. if (isImageInCache (imageToRelease))
  74788. release (imageToRelease);
  74789. else
  74790. delete imageToRelease;
  74791. }
  74792. bool ImageCache::isImageInCache (Image* const imageToLookFor)
  74793. {
  74794. if (instance != 0)
  74795. {
  74796. const ScopedLock sl (instance->lock);
  74797. for (int i = instance->images.size(); --i >= 0;)
  74798. if ((Image*) instance->images.getUnchecked(i)->image == imageToLookFor)
  74799. return true;
  74800. }
  74801. return false;
  74802. }
  74803. void ImageCache::incReferenceCount (Image* const image)
  74804. {
  74805. if (instance != 0)
  74806. {
  74807. const ScopedLock sl (instance->lock);
  74808. for (int i = instance->images.size(); --i >= 0;)
  74809. {
  74810. ImageCacheItem* const ci = (ImageCacheItem*) instance->images.getUnchecked(i);
  74811. if ((Image*) ci->image == image)
  74812. {
  74813. ci->refCount++;
  74814. return;
  74815. }
  74816. }
  74817. }
  74818. jassertfalse // (trying to inc the ref count of an image that's not in the cache)
  74819. }
  74820. void ImageCache::timerCallback()
  74821. {
  74822. int numberStillNeedingReleasing = 0;
  74823. const unsigned int now = Time::getApproximateMillisecondCounter();
  74824. const ScopedLock sl (lock);
  74825. for (int i = images.size(); --i >= 0;)
  74826. {
  74827. ImageCacheItem* const ci = images.getUnchecked(i);
  74828. if (ci->refCount <= 0)
  74829. {
  74830. if (now > ci->releaseTime + cacheTimeout
  74831. || now < ci->releaseTime - 1000)
  74832. {
  74833. images.remove (i);
  74834. }
  74835. else
  74836. {
  74837. ++numberStillNeedingReleasing;
  74838. }
  74839. }
  74840. }
  74841. if (numberStillNeedingReleasing == 0)
  74842. stopTimer();
  74843. }
  74844. Image* ImageCache::getFromFile (const File& file)
  74845. {
  74846. const int64 hashCode = file.hashCode64();
  74847. Image* image = getFromHashCode (hashCode);
  74848. if (image == 0)
  74849. {
  74850. image = ImageFileFormat::loadFrom (file);
  74851. addImageToCache (image, hashCode);
  74852. }
  74853. return image;
  74854. }
  74855. Image* ImageCache::getFromMemory (const void* imageData,
  74856. const int dataSize)
  74857. {
  74858. const int64 hashCode = (int64) (pointer_sized_int) imageData;
  74859. Image* image = getFromHashCode (hashCode);
  74860. if (image == 0)
  74861. {
  74862. image = ImageFileFormat::loadFrom (imageData, dataSize);
  74863. addImageToCache (image, hashCode);
  74864. }
  74865. return image;
  74866. }
  74867. void ImageCache::setCacheTimeout (const int millisecs)
  74868. {
  74869. cacheTimeout = millisecs;
  74870. }
  74871. END_JUCE_NAMESPACE
  74872. /********* End of inlined file: juce_ImageCache.cpp *********/
  74873. /********* Start of inlined file: juce_ImageConvolutionKernel.cpp *********/
  74874. BEGIN_JUCE_NAMESPACE
  74875. ImageConvolutionKernel::ImageConvolutionKernel (const int size_)
  74876. : values (size_ * size_),
  74877. size (size_)
  74878. {
  74879. clear();
  74880. }
  74881. ImageConvolutionKernel::~ImageConvolutionKernel()
  74882. {
  74883. }
  74884. void ImageConvolutionKernel::setKernelValue (const int x,
  74885. const int y,
  74886. const float value)
  74887. {
  74888. if (((unsigned int) x) < (unsigned int) size
  74889. && ((unsigned int) y) < (unsigned int) size)
  74890. {
  74891. values [x + y * size] = value;
  74892. }
  74893. else
  74894. {
  74895. jassertfalse
  74896. }
  74897. }
  74898. void ImageConvolutionKernel::clear()
  74899. {
  74900. for (int i = size * size; --i >= 0;)
  74901. values[i] = 0;
  74902. }
  74903. void ImageConvolutionKernel::setOverallSum (const float desiredTotalSum)
  74904. {
  74905. double currentTotal = 0.0;
  74906. for (int i = size * size; --i >= 0;)
  74907. currentTotal += values[i];
  74908. rescaleAllValues ((float) (desiredTotalSum / currentTotal));
  74909. }
  74910. void ImageConvolutionKernel::rescaleAllValues (const float multiplier)
  74911. {
  74912. for (int i = size * size; --i >= 0;)
  74913. values[i] *= multiplier;
  74914. }
  74915. void ImageConvolutionKernel::createGaussianBlur (const float radius)
  74916. {
  74917. const double radiusFactor = -1.0 / (radius * radius * 2);
  74918. const int centre = size >> 1;
  74919. for (int y = size; --y >= 0;)
  74920. {
  74921. for (int x = size; --x >= 0;)
  74922. {
  74923. const int cx = x - centre;
  74924. const int cy = y - centre;
  74925. values [x + y * size] = (float) exp (radiusFactor * (cx * cx + cy * cy));
  74926. }
  74927. }
  74928. setOverallSum (1.0f);
  74929. }
  74930. void ImageConvolutionKernel::applyToImage (Image& destImage,
  74931. const Image* sourceImage,
  74932. int dx,
  74933. int dy,
  74934. int dw,
  74935. int dh) const
  74936. {
  74937. ScopedPointer <Image> imageCreated;
  74938. if (sourceImage == 0)
  74939. {
  74940. sourceImage = imageCreated = destImage.createCopy();
  74941. }
  74942. else
  74943. {
  74944. jassert (sourceImage->getWidth() == destImage.getWidth()
  74945. && sourceImage->getHeight() == destImage.getHeight()
  74946. && sourceImage->getFormat() == destImage.getFormat());
  74947. if (sourceImage->getWidth() != destImage.getWidth()
  74948. || sourceImage->getHeight() != destImage.getHeight()
  74949. || sourceImage->getFormat() != destImage.getFormat())
  74950. return;
  74951. }
  74952. const int imageWidth = destImage.getWidth();
  74953. const int imageHeight = destImage.getHeight();
  74954. if (dx >= imageWidth || dy >= imageHeight)
  74955. return;
  74956. if (dx + dw > imageWidth)
  74957. dw = imageWidth - dx;
  74958. if (dy + dh > imageHeight)
  74959. dh = imageHeight - dy;
  74960. const int dx2 = dx + dw;
  74961. const int dy2 = dy + dh;
  74962. const Image::BitmapData destData (destImage, dx, dy, dw, dh, true);
  74963. uint8* line = destData.data;
  74964. const Image::BitmapData srcData (*sourceImage, 0, 0, sourceImage->getWidth(), sourceImage->getHeight());
  74965. if (destData.pixelStride == 4)
  74966. {
  74967. for (int y = dy; y < dy2; ++y)
  74968. {
  74969. uint8* dest = line;
  74970. line += destData.lineStride;
  74971. for (int x = dx; x < dx2; ++x)
  74972. {
  74973. float c1 = 0;
  74974. float c2 = 0;
  74975. float c3 = 0;
  74976. float c4 = 0;
  74977. for (int yy = 0; yy < size; ++yy)
  74978. {
  74979. const int sy = y + yy - (size >> 1);
  74980. if (sy >= imageHeight)
  74981. break;
  74982. if (sy >= 0)
  74983. {
  74984. int sx = x - (size >> 1);
  74985. const uint8* src = srcData.getPixelPointer (sx, sy);
  74986. for (int xx = 0; xx < size; ++xx)
  74987. {
  74988. if (sx >= imageWidth)
  74989. break;
  74990. if (sx >= 0)
  74991. {
  74992. const float kernelMult = values [xx + yy * size];
  74993. c1 += kernelMult * *src++;
  74994. c2 += kernelMult * *src++;
  74995. c3 += kernelMult * *src++;
  74996. c4 += kernelMult * *src++;
  74997. }
  74998. else
  74999. {
  75000. src += 4;
  75001. }
  75002. ++sx;
  75003. }
  75004. }
  75005. }
  75006. *dest++ = (uint8) jmin (0xff, roundToInt (c1));
  75007. *dest++ = (uint8) jmin (0xff, roundToInt (c2));
  75008. *dest++ = (uint8) jmin (0xff, roundToInt (c3));
  75009. *dest++ = (uint8) jmin (0xff, roundToInt (c4));
  75010. }
  75011. }
  75012. }
  75013. else if (destData.pixelStride == 3)
  75014. {
  75015. for (int y = dy; y < dy2; ++y)
  75016. {
  75017. uint8* dest = line;
  75018. line += destData.lineStride;
  75019. for (int x = dx; x < dx2; ++x)
  75020. {
  75021. float c1 = 0;
  75022. float c2 = 0;
  75023. float c3 = 0;
  75024. for (int yy = 0; yy < size; ++yy)
  75025. {
  75026. const int sy = y + yy - (size >> 1);
  75027. if (sy >= imageHeight)
  75028. break;
  75029. if (sy >= 0)
  75030. {
  75031. int sx = x - (size >> 1);
  75032. const uint8* src = srcData.getPixelPointer (sx, sy);
  75033. for (int xx = 0; xx < size; ++xx)
  75034. {
  75035. if (sx >= imageWidth)
  75036. break;
  75037. if (sx >= 0)
  75038. {
  75039. const float kernelMult = values [xx + yy * size];
  75040. c1 += kernelMult * *src++;
  75041. c2 += kernelMult * *src++;
  75042. c3 += kernelMult * *src++;
  75043. }
  75044. else
  75045. {
  75046. src += 3;
  75047. }
  75048. ++sx;
  75049. }
  75050. }
  75051. }
  75052. *dest++ = (uint8) roundToInt (c1);
  75053. *dest++ = (uint8) roundToInt (c2);
  75054. *dest++ = (uint8) roundToInt (c3);
  75055. }
  75056. }
  75057. }
  75058. }
  75059. END_JUCE_NAMESPACE
  75060. /********* End of inlined file: juce_ImageConvolutionKernel.cpp *********/
  75061. /********* Start of inlined file: juce_ImageFileFormat.cpp *********/
  75062. BEGIN_JUCE_NAMESPACE
  75063. /********* Start of inlined file: juce_GIFLoader.h *********/
  75064. #ifndef __JUCE_GIFLOADER_JUCEHEADER__
  75065. #define __JUCE_GIFLOADER_JUCEHEADER__
  75066. #ifndef DOXYGEN
  75067. class GIFLoader
  75068. {
  75069. public:
  75070. GIFLoader (InputStream& in);
  75071. ~GIFLoader();
  75072. Image* getImage() const { return image; }
  75073. private:
  75074. Image* image;
  75075. InputStream& input;
  75076. uint8 buffer [300];
  75077. uint8 palette [256][4];
  75078. bool dataBlockIsZero, fresh, finished;
  75079. int currentBit, lastBit, lastByteIndex;
  75080. int codeSize, setCodeSize;
  75081. int maxCode, maxCodeSize;
  75082. int firstcode, oldcode;
  75083. int clearCode, end_code;
  75084. enum { maxGifCode = 1 << 12 };
  75085. int table [2] [maxGifCode];
  75086. int stack [2 * maxGifCode];
  75087. int *sp;
  75088. bool getSizeFromHeader (int& width, int& height);
  75089. bool readPalette (const int numCols);
  75090. int readDataBlock (unsigned char* dest);
  75091. int processExtension (int type, int& transparent);
  75092. int readLZWByte (bool initialise, int input_code_size);
  75093. int getCode (int code_size, bool initialise);
  75094. bool readImage (int width, int height, int interlace, int transparent);
  75095. static inline int makeWord (const uint8 a, const uint8 b) { return (b << 8) | a; }
  75096. GIFLoader (const GIFLoader&);
  75097. const GIFLoader& operator= (const GIFLoader&);
  75098. };
  75099. #endif // DOXYGEN
  75100. #endif // __JUCE_GIFLOADER_JUCEHEADER__
  75101. /********* End of inlined file: juce_GIFLoader.h *********/
  75102. Image* juce_loadPNGImageFromStream (InputStream& inputStream);
  75103. bool juce_writePNGImageToStream (const Image& image, OutputStream& out);
  75104. PNGImageFormat::PNGImageFormat() {}
  75105. PNGImageFormat::~PNGImageFormat() {}
  75106. const String PNGImageFormat::getFormatName()
  75107. {
  75108. return T("PNG");
  75109. }
  75110. bool PNGImageFormat::canUnderstand (InputStream& in)
  75111. {
  75112. const int bytesNeeded = 4;
  75113. char header [bytesNeeded];
  75114. return in.read (header, bytesNeeded) == bytesNeeded
  75115. && header[1] == 'P'
  75116. && header[2] == 'N'
  75117. && header[3] == 'G';
  75118. }
  75119. Image* PNGImageFormat::decodeImage (InputStream& in)
  75120. {
  75121. return juce_loadPNGImageFromStream (in);
  75122. }
  75123. bool PNGImageFormat::writeImageToStream (const Image& sourceImage,
  75124. OutputStream& destStream)
  75125. {
  75126. return juce_writePNGImageToStream (sourceImage, destStream);
  75127. }
  75128. Image* juce_loadJPEGImageFromStream (InputStream& inputStream);
  75129. bool juce_writeJPEGImageToStream (const Image& image, OutputStream& out, float quality);
  75130. JPEGImageFormat::JPEGImageFormat()
  75131. : quality (-1.0f)
  75132. {
  75133. }
  75134. JPEGImageFormat::~JPEGImageFormat() {}
  75135. void JPEGImageFormat::setQuality (const float newQuality)
  75136. {
  75137. quality = newQuality;
  75138. }
  75139. const String JPEGImageFormat::getFormatName()
  75140. {
  75141. return T("JPEG");
  75142. }
  75143. bool JPEGImageFormat::canUnderstand (InputStream& in)
  75144. {
  75145. const int bytesNeeded = 10;
  75146. uint8 header [bytesNeeded];
  75147. if (in.read (header, bytesNeeded) == bytesNeeded)
  75148. {
  75149. return header[0] == 0xff
  75150. && header[1] == 0xd8
  75151. && header[2] == 0xff
  75152. && (header[3] == 0xe0 || header[3] == 0xe1);
  75153. }
  75154. return false;
  75155. }
  75156. Image* JPEGImageFormat::decodeImage (InputStream& in)
  75157. {
  75158. return juce_loadJPEGImageFromStream (in);
  75159. }
  75160. bool JPEGImageFormat::writeImageToStream (const Image& sourceImage,
  75161. OutputStream& destStream)
  75162. {
  75163. return juce_writeJPEGImageToStream (sourceImage, destStream, quality);
  75164. }
  75165. class GIFImageFormat : public ImageFileFormat
  75166. {
  75167. public:
  75168. GIFImageFormat() {}
  75169. ~GIFImageFormat() {}
  75170. const String getFormatName()
  75171. {
  75172. return T("GIF");
  75173. }
  75174. bool canUnderstand (InputStream& in)
  75175. {
  75176. const int bytesNeeded = 4;
  75177. char header [bytesNeeded];
  75178. return (in.read (header, bytesNeeded) == bytesNeeded)
  75179. && header[0] == 'G'
  75180. && header[1] == 'I'
  75181. && header[2] == 'F';
  75182. }
  75183. Image* decodeImage (InputStream& in)
  75184. {
  75185. const ScopedPointer <GIFLoader> loader (new GIFLoader (in));
  75186. return loader->getImage();
  75187. }
  75188. bool writeImageToStream (const Image& /*sourceImage*/, OutputStream& /*destStream*/)
  75189. {
  75190. return false;
  75191. }
  75192. };
  75193. ImageFileFormat* ImageFileFormat::findImageFormatForStream (InputStream& input)
  75194. {
  75195. static PNGImageFormat png;
  75196. static JPEGImageFormat jpg;
  75197. static GIFImageFormat gif;
  75198. ImageFileFormat* formats[4];
  75199. int numFormats = 0;
  75200. formats [numFormats++] = &png;
  75201. formats [numFormats++] = &jpg;
  75202. formats [numFormats++] = &gif;
  75203. const int64 streamPos = input.getPosition();
  75204. for (int i = 0; i < numFormats; ++i)
  75205. {
  75206. const bool found = formats[i]->canUnderstand (input);
  75207. input.setPosition (streamPos);
  75208. if (found)
  75209. return formats[i];
  75210. }
  75211. return 0;
  75212. }
  75213. Image* ImageFileFormat::loadFrom (InputStream& input)
  75214. {
  75215. ImageFileFormat* const format = findImageFormatForStream (input);
  75216. if (format != 0)
  75217. return format->decodeImage (input);
  75218. return 0;
  75219. }
  75220. Image* ImageFileFormat::loadFrom (const File& file)
  75221. {
  75222. InputStream* const in = file.createInputStream();
  75223. if (in != 0)
  75224. {
  75225. BufferedInputStream b (in, 8192, true);
  75226. return loadFrom (b);
  75227. }
  75228. return 0;
  75229. }
  75230. Image* ImageFileFormat::loadFrom (const void* rawData, const int numBytes)
  75231. {
  75232. if (rawData != 0 && numBytes > 4)
  75233. {
  75234. MemoryInputStream stream (rawData, numBytes, false);
  75235. return loadFrom (stream);
  75236. }
  75237. return 0;
  75238. }
  75239. END_JUCE_NAMESPACE
  75240. /********* End of inlined file: juce_ImageFileFormat.cpp *********/
  75241. /********* Start of inlined file: juce_GIFLoader.cpp *********/
  75242. BEGIN_JUCE_NAMESPACE
  75243. GIFLoader::GIFLoader (InputStream& in)
  75244. : image (0),
  75245. input (in),
  75246. dataBlockIsZero (false),
  75247. fresh (false),
  75248. finished (false)
  75249. {
  75250. currentBit = lastBit = lastByteIndex = 0;
  75251. maxCode = maxCodeSize = codeSize = setCodeSize = 0;
  75252. firstcode = oldcode = 0;
  75253. clearCode = end_code = 0;
  75254. int imageWidth, imageHeight;
  75255. int transparent = -1;
  75256. if (! getSizeFromHeader (imageWidth, imageHeight))
  75257. return;
  75258. if ((imageWidth <= 0) || (imageHeight <= 0))
  75259. return;
  75260. unsigned char buf [16];
  75261. if (in.read (buf, 3) != 3)
  75262. return;
  75263. int numColours = 2 << (buf[0] & 7);
  75264. if ((buf[0] & 0x80) != 0)
  75265. readPalette (numColours);
  75266. for (;;)
  75267. {
  75268. if (input.read (buf, 1) != 1)
  75269. break;
  75270. if (buf[0] == ';')
  75271. break;
  75272. if (buf[0] == '!')
  75273. {
  75274. if (input.read (buf, 1) != 1)
  75275. break;
  75276. if (processExtension (buf[0], transparent) < 0)
  75277. break;
  75278. continue;
  75279. }
  75280. if (buf[0] != ',')
  75281. continue;
  75282. if (input.read (buf, 9) != 9)
  75283. break;
  75284. imageWidth = makeWord (buf[4], buf[5]);
  75285. imageHeight = makeWord (buf[6], buf[7]);
  75286. numColours = 2 << (buf[8] & 7);
  75287. if ((buf[8] & 0x80) != 0)
  75288. if (! readPalette (numColours))
  75289. break;
  75290. image = Image::createNativeImage ((transparent >= 0) ? Image::ARGB : Image::RGB,
  75291. imageWidth, imageHeight, (transparent >= 0));
  75292. readImage (imageWidth, imageHeight,
  75293. (buf[8] & 0x40) != 0,
  75294. transparent);
  75295. break;
  75296. }
  75297. }
  75298. GIFLoader::~GIFLoader()
  75299. {
  75300. }
  75301. bool GIFLoader::getSizeFromHeader (int& w, int& h)
  75302. {
  75303. unsigned char b [8];
  75304. if (input.read (b, 6) == 6)
  75305. {
  75306. if ((strncmp ("GIF87a", (char*) b, 6) == 0)
  75307. || (strncmp ("GIF89a", (char*) b, 6) == 0))
  75308. {
  75309. if (input.read (b, 4) == 4)
  75310. {
  75311. w = makeWord (b[0], b[1]);
  75312. h = makeWord (b[2], b[3]);
  75313. return true;
  75314. }
  75315. }
  75316. }
  75317. return false;
  75318. }
  75319. bool GIFLoader::readPalette (const int numCols)
  75320. {
  75321. unsigned char rgb[4];
  75322. for (int i = 0; i < numCols; ++i)
  75323. {
  75324. input.read (rgb, 3);
  75325. palette [i][0] = rgb[0];
  75326. palette [i][1] = rgb[1];
  75327. palette [i][2] = rgb[2];
  75328. palette [i][3] = 0xff;
  75329. }
  75330. return true;
  75331. }
  75332. int GIFLoader::readDataBlock (unsigned char* const dest)
  75333. {
  75334. unsigned char n;
  75335. if (input.read (&n, 1) == 1)
  75336. {
  75337. dataBlockIsZero = (n == 0);
  75338. if (dataBlockIsZero || (input.read (dest, n) == n))
  75339. return n;
  75340. }
  75341. return -1;
  75342. }
  75343. int GIFLoader::processExtension (const int type, int& transparent)
  75344. {
  75345. unsigned char b [300];
  75346. int n = 0;
  75347. if (type == 0xf9)
  75348. {
  75349. n = readDataBlock (b);
  75350. if (n < 0)
  75351. return 1;
  75352. if ((b[0] & 0x1) != 0)
  75353. transparent = b[3];
  75354. }
  75355. do
  75356. {
  75357. n = readDataBlock (b);
  75358. }
  75359. while (n > 0);
  75360. return n;
  75361. }
  75362. int GIFLoader::getCode (const int codeSize_, const bool initialise)
  75363. {
  75364. if (initialise)
  75365. {
  75366. currentBit = 0;
  75367. lastBit = 0;
  75368. finished = false;
  75369. return 0;
  75370. }
  75371. if ((currentBit + codeSize_) >= lastBit)
  75372. {
  75373. if (finished)
  75374. return -1;
  75375. buffer[0] = buffer [lastByteIndex - 2];
  75376. buffer[1] = buffer [lastByteIndex - 1];
  75377. const int n = readDataBlock (&buffer[2]);
  75378. if (n == 0)
  75379. finished = true;
  75380. lastByteIndex = 2 + n;
  75381. currentBit = (currentBit - lastBit) + 16;
  75382. lastBit = (2 + n) * 8 ;
  75383. }
  75384. int result = 0;
  75385. int i = currentBit;
  75386. for (int j = 0; j < codeSize_; ++j)
  75387. {
  75388. result |= ((buffer[i >> 3] & (1 << (i & 7))) != 0) << j;
  75389. ++i;
  75390. }
  75391. currentBit += codeSize_;
  75392. return result;
  75393. }
  75394. int GIFLoader::readLZWByte (const bool initialise, const int inputCodeSize)
  75395. {
  75396. int code, incode, i;
  75397. if (initialise)
  75398. {
  75399. setCodeSize = inputCodeSize;
  75400. codeSize = setCodeSize + 1;
  75401. clearCode = 1 << setCodeSize;
  75402. end_code = clearCode + 1;
  75403. maxCodeSize = 2 * clearCode;
  75404. maxCode = clearCode + 2;
  75405. getCode (0, true);
  75406. fresh = true;
  75407. for (i = 0; i < clearCode; ++i)
  75408. {
  75409. table[0][i] = 0;
  75410. table[1][i] = i;
  75411. }
  75412. for (; i < maxGifCode; ++i)
  75413. {
  75414. table[0][i] = 0;
  75415. table[1][i] = 0;
  75416. }
  75417. sp = stack;
  75418. return 0;
  75419. }
  75420. else if (fresh)
  75421. {
  75422. fresh = false;
  75423. do
  75424. {
  75425. firstcode = oldcode
  75426. = getCode (codeSize, false);
  75427. }
  75428. while (firstcode == clearCode);
  75429. return firstcode;
  75430. }
  75431. if (sp > stack)
  75432. return *--sp;
  75433. while ((code = getCode (codeSize, false)) >= 0)
  75434. {
  75435. if (code == clearCode)
  75436. {
  75437. for (i = 0; i < clearCode; ++i)
  75438. {
  75439. table[0][i] = 0;
  75440. table[1][i] = i;
  75441. }
  75442. for (; i < maxGifCode; ++i)
  75443. {
  75444. table[0][i] = 0;
  75445. table[1][i] = 0;
  75446. }
  75447. codeSize = setCodeSize + 1;
  75448. maxCodeSize = 2 * clearCode;
  75449. maxCode = clearCode + 2;
  75450. sp = stack;
  75451. firstcode = oldcode = getCode (codeSize, false);
  75452. return firstcode;
  75453. }
  75454. else if (code == end_code)
  75455. {
  75456. if (dataBlockIsZero)
  75457. return -2;
  75458. unsigned char buf [260];
  75459. int n;
  75460. while ((n = readDataBlock (buf)) > 0)
  75461. {}
  75462. if (n != 0)
  75463. return -2;
  75464. }
  75465. incode = code;
  75466. if (code >= maxCode)
  75467. {
  75468. *sp++ = firstcode;
  75469. code = oldcode;
  75470. }
  75471. while (code >= clearCode)
  75472. {
  75473. *sp++ = table[1][code];
  75474. if (code == table[0][code])
  75475. return -2;
  75476. code = table[0][code];
  75477. }
  75478. *sp++ = firstcode = table[1][code];
  75479. if ((code = maxCode) < maxGifCode)
  75480. {
  75481. table[0][code] = oldcode;
  75482. table[1][code] = firstcode;
  75483. ++maxCode;
  75484. if ((maxCode >= maxCodeSize)
  75485. && (maxCodeSize < maxGifCode))
  75486. {
  75487. maxCodeSize <<= 1;
  75488. ++codeSize;
  75489. }
  75490. }
  75491. oldcode = incode;
  75492. if (sp > stack)
  75493. return *--sp;
  75494. }
  75495. return code;
  75496. }
  75497. bool GIFLoader::readImage (const int width, const int height,
  75498. const int interlace, const int transparent)
  75499. {
  75500. unsigned char c;
  75501. if (input.read (&c, 1) != 1
  75502. || readLZWByte (true, c) < 0)
  75503. return false;
  75504. if (transparent >= 0)
  75505. {
  75506. palette [transparent][0] = 0;
  75507. palette [transparent][1] = 0;
  75508. palette [transparent][2] = 0;
  75509. palette [transparent][3] = 0;
  75510. }
  75511. int index;
  75512. int xpos = 0, ypos = 0, pass = 0;
  75513. const Image::BitmapData destData (*image, 0, 0, width, height, true);
  75514. uint8* p = destData.data;
  75515. const bool hasAlpha = image->hasAlphaChannel();
  75516. while ((index = readLZWByte (false, c)) >= 0)
  75517. {
  75518. const uint8* const paletteEntry = palette [index];
  75519. if (hasAlpha)
  75520. {
  75521. ((PixelARGB*) p)->setARGB (paletteEntry[3],
  75522. paletteEntry[0],
  75523. paletteEntry[1],
  75524. paletteEntry[2]);
  75525. ((PixelARGB*) p)->premultiply();
  75526. }
  75527. else
  75528. {
  75529. ((PixelRGB*) p)->setARGB (0,
  75530. paletteEntry[0],
  75531. paletteEntry[1],
  75532. paletteEntry[2]);
  75533. }
  75534. p += destData.pixelStride;
  75535. ++xpos;
  75536. if (xpos == width)
  75537. {
  75538. xpos = 0;
  75539. if (interlace)
  75540. {
  75541. switch (pass)
  75542. {
  75543. case 0:
  75544. case 1:
  75545. ypos += 8;
  75546. break;
  75547. case 2:
  75548. ypos += 4;
  75549. break;
  75550. case 3:
  75551. ypos += 2;
  75552. break;
  75553. }
  75554. while (ypos >= height)
  75555. {
  75556. ++pass;
  75557. switch (pass)
  75558. {
  75559. case 1:
  75560. ypos = 4;
  75561. break;
  75562. case 2:
  75563. ypos = 2;
  75564. break;
  75565. case 3:
  75566. ypos = 1;
  75567. break;
  75568. default:
  75569. return true;
  75570. }
  75571. }
  75572. }
  75573. else
  75574. {
  75575. ++ypos;
  75576. }
  75577. p = destData.getPixelPointer (xpos, ypos);
  75578. }
  75579. if (ypos >= height)
  75580. break;
  75581. }
  75582. return true;
  75583. }
  75584. END_JUCE_NAMESPACE
  75585. /********* End of inlined file: juce_GIFLoader.cpp *********/
  75586. #endif
  75587. //==============================================================================
  75588. // some files include lots of library code, so leave them to the end to avoid cluttering
  75589. // up the build for the clean files.
  75590. /********* Start of inlined file: juce_GZIPCompressorOutputStream.cpp *********/
  75591. namespace zlibNamespace
  75592. {
  75593. #if JUCE_INCLUDE_ZLIB_CODE
  75594. #undef OS_CODE
  75595. #undef fdopen
  75596. /********* Start of inlined file: zlib.h *********/
  75597. #ifndef ZLIB_H
  75598. #define ZLIB_H
  75599. /********* Start of inlined file: zconf.h *********/
  75600. #ifndef ZCONF_H
  75601. #define ZCONF_H
  75602. // *** Just a few hacks here to make it compile nicely with Juce..
  75603. #define Z_PREFIX 1
  75604. #undef __MACTYPES__
  75605. #ifdef _MSC_VER
  75606. #pragma warning (disable : 4131 4127 4244 4267)
  75607. #endif
  75608. #ifdef Z_PREFIX
  75609. # define deflateInit_ z_deflateInit_
  75610. # define deflate z_deflate
  75611. # define deflateEnd z_deflateEnd
  75612. # define inflateInit_ z_inflateInit_
  75613. # define inflate z_inflate
  75614. # define inflateEnd z_inflateEnd
  75615. # define deflateInit2_ z_deflateInit2_
  75616. # define deflateSetDictionary z_deflateSetDictionary
  75617. # define deflateCopy z_deflateCopy
  75618. # define deflateReset z_deflateReset
  75619. # define deflateParams z_deflateParams
  75620. # define deflateBound z_deflateBound
  75621. # define deflatePrime z_deflatePrime
  75622. # define inflateInit2_ z_inflateInit2_
  75623. # define inflateSetDictionary z_inflateSetDictionary
  75624. # define inflateSync z_inflateSync
  75625. # define inflateSyncPoint z_inflateSyncPoint
  75626. # define inflateCopy z_inflateCopy
  75627. # define inflateReset z_inflateReset
  75628. # define inflateBack z_inflateBack
  75629. # define inflateBackEnd z_inflateBackEnd
  75630. # define compress z_compress
  75631. # define compress2 z_compress2
  75632. # define compressBound z_compressBound
  75633. # define uncompress z_uncompress
  75634. # define adler32 z_adler32
  75635. # define crc32 z_crc32
  75636. # define get_crc_table z_get_crc_table
  75637. # define zError z_zError
  75638. # define alloc_func z_alloc_func
  75639. # define free_func z_free_func
  75640. # define in_func z_in_func
  75641. # define out_func z_out_func
  75642. # define Byte z_Byte
  75643. # define uInt z_uInt
  75644. # define uLong z_uLong
  75645. # define Bytef z_Bytef
  75646. # define charf z_charf
  75647. # define intf z_intf
  75648. # define uIntf z_uIntf
  75649. # define uLongf z_uLongf
  75650. # define voidpf z_voidpf
  75651. # define voidp z_voidp
  75652. #endif
  75653. #if defined(__MSDOS__) && !defined(MSDOS)
  75654. # define MSDOS
  75655. #endif
  75656. #if (defined(OS_2) || defined(__OS2__)) && !defined(OS2)
  75657. # define OS2
  75658. #endif
  75659. #if defined(_WINDOWS) && !defined(WINDOWS)
  75660. # define WINDOWS
  75661. #endif
  75662. #if defined(_WIN32) || defined(_WIN32_WCE) || defined(__WIN32__)
  75663. # ifndef WIN32
  75664. # define WIN32
  75665. # endif
  75666. #endif
  75667. #if (defined(MSDOS) || defined(OS2) || defined(WINDOWS)) && !defined(WIN32)
  75668. # if !defined(__GNUC__) && !defined(__FLAT__) && !defined(__386__)
  75669. # ifndef SYS16BIT
  75670. # define SYS16BIT
  75671. # endif
  75672. # endif
  75673. #endif
  75674. #ifdef SYS16BIT
  75675. # define MAXSEG_64K
  75676. #endif
  75677. #ifdef MSDOS
  75678. # define UNALIGNED_OK
  75679. #endif
  75680. #ifdef __STDC_VERSION__
  75681. # ifndef STDC
  75682. # define STDC
  75683. # endif
  75684. # if __STDC_VERSION__ >= 199901L
  75685. # ifndef STDC99
  75686. # define STDC99
  75687. # endif
  75688. # endif
  75689. #endif
  75690. #if !defined(STDC) && (defined(__STDC__) || defined(__cplusplus))
  75691. # define STDC
  75692. #endif
  75693. #if !defined(STDC) && (defined(__GNUC__) || defined(__BORLANDC__))
  75694. # define STDC
  75695. #endif
  75696. #if !defined(STDC) && (defined(MSDOS) || defined(WINDOWS) || defined(WIN32))
  75697. # define STDC
  75698. #endif
  75699. #if !defined(STDC) && (defined(OS2) || defined(__HOS_AIX__))
  75700. # define STDC
  75701. #endif
  75702. #if defined(__OS400__) && !defined(STDC) /* iSeries (formerly AS/400). */
  75703. # define STDC
  75704. #endif
  75705. #ifndef STDC
  75706. # ifndef const /* cannot use !defined(STDC) && !defined(const) on Mac */
  75707. # define const /* note: need a more gentle solution here */
  75708. # endif
  75709. #endif
  75710. #if defined(__MWERKS__)||defined(applec)||defined(THINK_C)||defined(__SC__)
  75711. # define NO_DUMMY_DECL
  75712. #endif
  75713. #ifndef MAX_MEM_LEVEL
  75714. # ifdef MAXSEG_64K
  75715. # define MAX_MEM_LEVEL 8
  75716. # else
  75717. # define MAX_MEM_LEVEL 9
  75718. # endif
  75719. #endif
  75720. #ifndef MAX_WBITS
  75721. # define MAX_WBITS 15 /* 32K LZ77 window */
  75722. #endif
  75723. #ifndef OF /* function prototypes */
  75724. # ifdef STDC
  75725. # define OF(args) args
  75726. # else
  75727. # define OF(args) ()
  75728. # endif
  75729. #endif
  75730. #ifdef SYS16BIT
  75731. # if defined(M_I86SM) || defined(M_I86MM)
  75732. # define SMALL_MEDIUM
  75733. # ifdef _MSC_VER
  75734. # define FAR _far
  75735. # else
  75736. # define FAR far
  75737. # endif
  75738. # endif
  75739. # if (defined(__SMALL__) || defined(__MEDIUM__))
  75740. # define SMALL_MEDIUM
  75741. # ifdef __BORLANDC__
  75742. # define FAR _far
  75743. # else
  75744. # define FAR far
  75745. # endif
  75746. # endif
  75747. #endif
  75748. #if defined(WINDOWS) || defined(WIN32)
  75749. # ifdef ZLIB_DLL
  75750. # if defined(WIN32) && (!defined(__BORLANDC__) || (__BORLANDC__ >= 0x500))
  75751. # ifdef ZLIB_INTERNAL
  75752. # define ZEXTERN extern __declspec(dllexport)
  75753. # else
  75754. # define ZEXTERN extern __declspec(dllimport)
  75755. # endif
  75756. # endif
  75757. # endif /* ZLIB_DLL */
  75758. # ifdef ZLIB_WINAPI
  75759. # ifdef FAR
  75760. # undef FAR
  75761. # endif
  75762. # include <windows.h>
  75763. # define ZEXPORT WINAPI
  75764. # ifdef WIN32
  75765. # define ZEXPORTVA WINAPIV
  75766. # else
  75767. # define ZEXPORTVA FAR CDECL
  75768. # endif
  75769. # endif
  75770. #endif
  75771. #if defined (__BEOS__)
  75772. # ifdef ZLIB_DLL
  75773. # ifdef ZLIB_INTERNAL
  75774. # define ZEXPORT __declspec(dllexport)
  75775. # define ZEXPORTVA __declspec(dllexport)
  75776. # else
  75777. # define ZEXPORT __declspec(dllimport)
  75778. # define ZEXPORTVA __declspec(dllimport)
  75779. # endif
  75780. # endif
  75781. #endif
  75782. #ifndef ZEXTERN
  75783. # define ZEXTERN extern
  75784. #endif
  75785. #ifndef ZEXPORT
  75786. # define ZEXPORT
  75787. #endif
  75788. #ifndef ZEXPORTVA
  75789. # define ZEXPORTVA
  75790. #endif
  75791. #ifndef FAR
  75792. # define FAR
  75793. #endif
  75794. #if !defined(__MACTYPES__)
  75795. typedef unsigned char Byte; /* 8 bits */
  75796. #endif
  75797. typedef unsigned int uInt; /* 16 bits or more */
  75798. typedef unsigned long uLong; /* 32 bits or more */
  75799. #ifdef SMALL_MEDIUM
  75800. # define Bytef Byte FAR
  75801. #else
  75802. typedef Byte FAR Bytef;
  75803. #endif
  75804. typedef char FAR charf;
  75805. typedef int FAR intf;
  75806. typedef uInt FAR uIntf;
  75807. typedef uLong FAR uLongf;
  75808. #ifdef STDC
  75809. typedef void const *voidpc;
  75810. typedef void FAR *voidpf;
  75811. typedef void *voidp;
  75812. #else
  75813. typedef Byte const *voidpc;
  75814. typedef Byte FAR *voidpf;
  75815. typedef Byte *voidp;
  75816. #endif
  75817. #if 0 /* HAVE_UNISTD_H -- this line is updated by ./configure */
  75818. # include <sys/types.h> /* for off_t */
  75819. # include <unistd.h> /* for SEEK_* and off_t */
  75820. # ifdef VMS
  75821. # include <unixio.h> /* for off_t */
  75822. # endif
  75823. # define z_off_t off_t
  75824. #endif
  75825. #ifndef SEEK_SET
  75826. # define SEEK_SET 0 /* Seek from beginning of file. */
  75827. # define SEEK_CUR 1 /* Seek from current position. */
  75828. # define SEEK_END 2 /* Set file pointer to EOF plus "offset" */
  75829. #endif
  75830. #ifndef z_off_t
  75831. # define z_off_t long
  75832. #endif
  75833. #if defined(__OS400__)
  75834. # define NO_vsnprintf
  75835. #endif
  75836. #if defined(__MVS__)
  75837. # define NO_vsnprintf
  75838. # ifdef FAR
  75839. # undef FAR
  75840. # endif
  75841. #endif
  75842. #if defined(__MVS__)
  75843. # pragma map(deflateInit_,"DEIN")
  75844. # pragma map(deflateInit2_,"DEIN2")
  75845. # pragma map(deflateEnd,"DEEND")
  75846. # pragma map(deflateBound,"DEBND")
  75847. # pragma map(inflateInit_,"ININ")
  75848. # pragma map(inflateInit2_,"ININ2")
  75849. # pragma map(inflateEnd,"INEND")
  75850. # pragma map(inflateSync,"INSY")
  75851. # pragma map(inflateSetDictionary,"INSEDI")
  75852. # pragma map(compressBound,"CMBND")
  75853. # pragma map(inflate_table,"INTABL")
  75854. # pragma map(inflate_fast,"INFA")
  75855. # pragma map(inflate_copyright,"INCOPY")
  75856. #endif
  75857. #endif /* ZCONF_H */
  75858. /********* End of inlined file: zconf.h *********/
  75859. #ifdef __cplusplus
  75860. extern "C" {
  75861. #endif
  75862. #define ZLIB_VERSION "1.2.3"
  75863. #define ZLIB_VERNUM 0x1230
  75864. typedef voidpf (*alloc_func) OF((voidpf opaque, uInt items, uInt size));
  75865. typedef void (*free_func) OF((voidpf opaque, voidpf address));
  75866. struct internal_state;
  75867. typedef struct z_stream_s {
  75868. Bytef *next_in; /* next input byte */
  75869. uInt avail_in; /* number of bytes available at next_in */
  75870. uLong total_in; /* total nb of input bytes read so far */
  75871. Bytef *next_out; /* next output byte should be put there */
  75872. uInt avail_out; /* remaining free space at next_out */
  75873. uLong total_out; /* total nb of bytes output so far */
  75874. char *msg; /* last error message, NULL if no error */
  75875. struct internal_state FAR *state; /* not visible by applications */
  75876. alloc_func zalloc; /* used to allocate the internal state */
  75877. free_func zfree; /* used to free the internal state */
  75878. voidpf opaque; /* private data object passed to zalloc and zfree */
  75879. int data_type; /* best guess about the data type: binary or text */
  75880. uLong adler; /* adler32 value of the uncompressed data */
  75881. uLong reserved; /* reserved for future use */
  75882. } z_stream;
  75883. typedef z_stream FAR *z_streamp;
  75884. typedef struct gz_header_s {
  75885. int text; /* true if compressed data believed to be text */
  75886. uLong time; /* modification time */
  75887. int xflags; /* extra flags (not used when writing a gzip file) */
  75888. int os; /* operating system */
  75889. Bytef *extra; /* pointer to extra field or Z_NULL if none */
  75890. uInt extra_len; /* extra field length (valid if extra != Z_NULL) */
  75891. uInt extra_max; /* space at extra (only when reading header) */
  75892. Bytef *name; /* pointer to zero-terminated file name or Z_NULL */
  75893. uInt name_max; /* space at name (only when reading header) */
  75894. Bytef *comment; /* pointer to zero-terminated comment or Z_NULL */
  75895. uInt comm_max; /* space at comment (only when reading header) */
  75896. int hcrc; /* true if there was or will be a header crc */
  75897. int done; /* true when done reading gzip header (not used
  75898. when writing a gzip file) */
  75899. } gz_header;
  75900. typedef gz_header FAR *gz_headerp;
  75901. #define Z_NO_FLUSH 0
  75902. #define Z_PARTIAL_FLUSH 1 /* will be removed, use Z_SYNC_FLUSH instead */
  75903. #define Z_SYNC_FLUSH 2
  75904. #define Z_FULL_FLUSH 3
  75905. #define Z_FINISH 4
  75906. #define Z_BLOCK 5
  75907. #define Z_OK 0
  75908. #define Z_STREAM_END 1
  75909. #define Z_NEED_DICT 2
  75910. #define Z_ERRNO (-1)
  75911. #define Z_STREAM_ERROR (-2)
  75912. #define Z_DATA_ERROR (-3)
  75913. #define Z_MEM_ERROR (-4)
  75914. #define Z_BUF_ERROR (-5)
  75915. #define Z_VERSION_ERROR (-6)
  75916. #define Z_NO_COMPRESSION 0
  75917. #define Z_BEST_SPEED 1
  75918. #define Z_BEST_COMPRESSION 9
  75919. #define Z_DEFAULT_COMPRESSION (-1)
  75920. #define Z_FILTERED 1
  75921. #define Z_HUFFMAN_ONLY 2
  75922. #define Z_RLE 3
  75923. #define Z_FIXED 4
  75924. #define Z_DEFAULT_STRATEGY 0
  75925. #define Z_BINARY 0
  75926. #define Z_TEXT 1
  75927. #define Z_ASCII Z_TEXT /* for compatibility with 1.2.2 and earlier */
  75928. #define Z_UNKNOWN 2
  75929. #define Z_DEFLATED 8
  75930. #define Z_NULL 0 /* for initializing zalloc, zfree, opaque */
  75931. #define zlib_version zlibVersion()
  75932. //ZEXTERN const char * ZEXPORT zlibVersion OF((void));
  75933. ZEXTERN int ZEXPORT deflate OF((z_streamp strm, int flush));
  75934. ZEXTERN int ZEXPORT deflateEnd OF((z_streamp strm));
  75935. ZEXTERN int ZEXPORT inflate OF((z_streamp strm, int flush));
  75936. ZEXTERN int ZEXPORT inflateEnd OF((z_streamp strm));
  75937. ZEXTERN int ZEXPORT deflateSetDictionary OF((z_streamp strm,
  75938. const Bytef *dictionary,
  75939. uInt dictLength));
  75940. ZEXTERN int ZEXPORT deflateCopy OF((z_streamp dest,
  75941. z_streamp source));
  75942. ZEXTERN int ZEXPORT deflateReset OF((z_streamp strm));
  75943. ZEXTERN int ZEXPORT deflateParams OF((z_streamp strm,
  75944. int level,
  75945. int strategy));
  75946. ZEXTERN int ZEXPORT deflateTune OF((z_streamp strm,
  75947. int good_length,
  75948. int max_lazy,
  75949. int nice_length,
  75950. int max_chain));
  75951. ZEXTERN uLong ZEXPORT deflateBound OF((z_streamp strm,
  75952. uLong sourceLen));
  75953. ZEXTERN int ZEXPORT deflatePrime OF((z_streamp strm,
  75954. int bits,
  75955. int value));
  75956. ZEXTERN int ZEXPORT deflateSetHeader OF((z_streamp strm,
  75957. gz_headerp head));
  75958. ZEXTERN int ZEXPORT inflateSetDictionary OF((z_streamp strm,
  75959. const Bytef *dictionary,
  75960. uInt dictLength));
  75961. ZEXTERN int ZEXPORT inflateSync OF((z_streamp strm));
  75962. ZEXTERN int ZEXPORT inflateCopy OF((z_streamp dest,
  75963. z_streamp source));
  75964. ZEXTERN int ZEXPORT inflateReset OF((z_streamp strm));
  75965. ZEXTERN int ZEXPORT inflatePrime OF((z_streamp strm,
  75966. int bits,
  75967. int value));
  75968. ZEXTERN int ZEXPORT inflateGetHeader OF((z_streamp strm,
  75969. gz_headerp head));
  75970. typedef unsigned (*in_func) OF((void FAR *, unsigned char FAR * FAR *));
  75971. typedef int (*out_func) OF((void FAR *, unsigned char FAR *, unsigned));
  75972. ZEXTERN int ZEXPORT inflateBack OF((z_streamp strm,
  75973. in_func in, void FAR *in_desc,
  75974. out_func out, void FAR *out_desc));
  75975. ZEXTERN int ZEXPORT inflateBackEnd OF((z_streamp strm));
  75976. //ZEXTERN uLong ZEXPORT zlibCompileFlags OF((void));
  75977. ZEXTERN int ZEXPORT compress OF((Bytef *dest, uLongf *destLen,
  75978. const Bytef *source, uLong sourceLen));
  75979. ZEXTERN int ZEXPORT compress2 OF((Bytef *dest, uLongf *destLen,
  75980. const Bytef *source, uLong sourceLen,
  75981. int level));
  75982. ZEXTERN uLong ZEXPORT compressBound OF((uLong sourceLen));
  75983. ZEXTERN int ZEXPORT uncompress OF((Bytef *dest, uLongf *destLen,
  75984. const Bytef *source, uLong sourceLen));
  75985. typedef voidp gzFile;
  75986. ZEXTERN gzFile ZEXPORT gzopen OF((const char *path, const char *mode));
  75987. ZEXTERN gzFile ZEXPORT gzdopen OF((int fd, const char *mode));
  75988. ZEXTERN int ZEXPORT gzsetparams OF((gzFile file, int level, int strategy));
  75989. ZEXTERN int ZEXPORT gzread OF((gzFile file, voidp buf, unsigned len));
  75990. ZEXTERN int ZEXPORT gzwrite OF((gzFile file,
  75991. voidpc buf, unsigned len));
  75992. ZEXTERN int ZEXPORTVA gzprintf OF((gzFile file, const char *format, ...));
  75993. ZEXTERN int ZEXPORT gzputs OF((gzFile file, const char *s));
  75994. ZEXTERN char * ZEXPORT gzgets OF((gzFile file, char *buf, int len));
  75995. ZEXTERN int ZEXPORT gzputc OF((gzFile file, int c));
  75996. ZEXTERN int ZEXPORT gzgetc OF((gzFile file));
  75997. ZEXTERN int ZEXPORT gzungetc OF((int c, gzFile file));
  75998. ZEXTERN int ZEXPORT gzflush OF((gzFile file, int flush));
  75999. ZEXTERN z_off_t ZEXPORT gzseek OF((gzFile file,
  76000. z_off_t offset, int whence));
  76001. ZEXTERN int ZEXPORT gzrewind OF((gzFile file));
  76002. ZEXTERN z_off_t ZEXPORT gztell OF((gzFile file));
  76003. ZEXTERN int ZEXPORT gzeof OF((gzFile file));
  76004. ZEXTERN int ZEXPORT gzdirect OF((gzFile file));
  76005. ZEXTERN int ZEXPORT gzclose OF((gzFile file));
  76006. ZEXTERN const char * ZEXPORT gzerror OF((gzFile file, int *errnum));
  76007. ZEXTERN void ZEXPORT gzclearerr OF((gzFile file));
  76008. ZEXTERN uLong ZEXPORT adler32 OF((uLong adler, const Bytef *buf, uInt len));
  76009. ZEXTERN uLong ZEXPORT adler32_combine OF((uLong adler1, uLong adler2,
  76010. z_off_t len2));
  76011. ZEXTERN uLong ZEXPORT crc32 OF((uLong crc, const Bytef *buf, uInt len));
  76012. ZEXTERN uLong ZEXPORT crc32_combine OF((uLong crc1, uLong crc2, z_off_t len2));
  76013. ZEXTERN int ZEXPORT deflateInit_ OF((z_streamp strm, int level,
  76014. const char *version, int stream_size));
  76015. ZEXTERN int ZEXPORT inflateInit_ OF((z_streamp strm,
  76016. const char *version, int stream_size));
  76017. ZEXTERN int ZEXPORT deflateInit2_ OF((z_streamp strm, int level, int method,
  76018. int windowBits, int memLevel,
  76019. int strategy, const char *version,
  76020. int stream_size));
  76021. ZEXTERN int ZEXPORT inflateInit2_ OF((z_streamp strm, int windowBits,
  76022. const char *version, int stream_size));
  76023. ZEXTERN int ZEXPORT inflateBackInit_ OF((z_streamp strm, int windowBits,
  76024. unsigned char FAR *window,
  76025. const char *version,
  76026. int stream_size));
  76027. #define deflateInit(strm, level) \
  76028. deflateInit_((strm), (level), ZLIB_VERSION, sizeof(z_stream))
  76029. #define inflateInit(strm) \
  76030. inflateInit_((strm), ZLIB_VERSION, sizeof(z_stream))
  76031. #define deflateInit2(strm, level, method, windowBits, memLevel, strategy) \
  76032. deflateInit2_((strm),(level),(method),(windowBits),(memLevel),\
  76033. (strategy), ZLIB_VERSION, sizeof(z_stream))
  76034. #define inflateInit2(strm, windowBits) \
  76035. inflateInit2_((strm), (windowBits), ZLIB_VERSION, sizeof(z_stream))
  76036. #define inflateBackInit(strm, windowBits, window) \
  76037. inflateBackInit_((strm), (windowBits), (window), \
  76038. ZLIB_VERSION, sizeof(z_stream))
  76039. #if !defined(ZUTIL_H) && !defined(NO_DUMMY_DECL)
  76040. struct internal_state {int dummy;}; /* hack for buggy compilers */
  76041. #endif
  76042. ZEXTERN const char * ZEXPORT zError OF((int));
  76043. ZEXTERN int ZEXPORT inflateSyncPoint OF((z_streamp z));
  76044. ZEXTERN const uLongf * ZEXPORT get_crc_table OF((void));
  76045. #ifdef __cplusplus
  76046. }
  76047. #endif
  76048. #endif /* ZLIB_H */
  76049. /********* End of inlined file: zlib.h *********/
  76050. #undef OS_CODE
  76051. #else
  76052. #include <zlib.h>
  76053. #endif
  76054. }
  76055. BEGIN_JUCE_NAMESPACE
  76056. using namespace zlibNamespace;
  76057. // internal helper object that holds the zlib structures so they don't have to be
  76058. // included publicly.
  76059. class GZIPCompressorHelper
  76060. {
  76061. public:
  76062. GZIPCompressorHelper (const int compressionLevel, const bool nowrap)
  76063. : data (0),
  76064. dataSize (0),
  76065. compLevel (compressionLevel),
  76066. strategy (0),
  76067. setParams (true),
  76068. streamIsValid (false),
  76069. finished (false),
  76070. shouldFinish (false)
  76071. {
  76072. zerostruct (stream);
  76073. streamIsValid = (deflateInit2 (&stream, compLevel, Z_DEFLATED,
  76074. nowrap ? -MAX_WBITS : MAX_WBITS,
  76075. 8, strategy) == Z_OK);
  76076. }
  76077. ~GZIPCompressorHelper()
  76078. {
  76079. if (streamIsValid)
  76080. deflateEnd (&stream);
  76081. }
  76082. bool needsInput() const throw()
  76083. {
  76084. return dataSize <= 0;
  76085. }
  76086. void setInput (uint8* const newData, const int size) throw()
  76087. {
  76088. data = newData;
  76089. dataSize = size;
  76090. }
  76091. int doNextBlock (uint8* const dest, const int destSize) throw()
  76092. {
  76093. if (streamIsValid)
  76094. {
  76095. stream.next_in = data;
  76096. stream.next_out = dest;
  76097. stream.avail_in = dataSize;
  76098. stream.avail_out = destSize;
  76099. const int result = setParams ? deflateParams (&stream, compLevel, strategy)
  76100. : deflate (&stream, shouldFinish ? Z_FINISH : Z_NO_FLUSH);
  76101. setParams = false;
  76102. switch (result)
  76103. {
  76104. case Z_STREAM_END:
  76105. finished = true;
  76106. // Deliberate fall-through..
  76107. case Z_OK:
  76108. data += dataSize - stream.avail_in;
  76109. dataSize = stream.avail_in;
  76110. return destSize - stream.avail_out;
  76111. default:
  76112. break;
  76113. }
  76114. }
  76115. return 0;
  76116. }
  76117. private:
  76118. z_stream stream;
  76119. uint8* data;
  76120. int dataSize, compLevel, strategy;
  76121. bool setParams, streamIsValid;
  76122. public:
  76123. bool finished, shouldFinish;
  76124. };
  76125. const int gzipCompBufferSize = 32768;
  76126. GZIPCompressorOutputStream::GZIPCompressorOutputStream (OutputStream* const destStream_,
  76127. int compressionLevel,
  76128. const bool deleteDestStream,
  76129. const bool noWrap)
  76130. : destStream (destStream_),
  76131. streamToDelete (deleteDestStream ? destStream_ : 0),
  76132. buffer (gzipCompBufferSize)
  76133. {
  76134. if (compressionLevel < 1 || compressionLevel > 9)
  76135. compressionLevel = -1;
  76136. helper = new GZIPCompressorHelper (compressionLevel, noWrap);
  76137. }
  76138. GZIPCompressorOutputStream::~GZIPCompressorOutputStream()
  76139. {
  76140. flush();
  76141. }
  76142. void GZIPCompressorOutputStream::flush()
  76143. {
  76144. if (! helper->finished)
  76145. {
  76146. helper->shouldFinish = true;
  76147. while (! helper->finished)
  76148. doNextBlock();
  76149. }
  76150. destStream->flush();
  76151. }
  76152. bool GZIPCompressorOutputStream::write (const void* destBuffer, int howMany)
  76153. {
  76154. if (! helper->finished)
  76155. {
  76156. helper->setInput ((uint8*) destBuffer, howMany);
  76157. while (! helper->needsInput())
  76158. {
  76159. if (! doNextBlock())
  76160. return false;
  76161. }
  76162. }
  76163. return true;
  76164. }
  76165. bool GZIPCompressorOutputStream::doNextBlock()
  76166. {
  76167. const int len = helper->doNextBlock (buffer, gzipCompBufferSize);
  76168. if (len > 0)
  76169. return destStream->write (buffer, len);
  76170. else
  76171. return true;
  76172. }
  76173. int64 GZIPCompressorOutputStream::getPosition()
  76174. {
  76175. return destStream->getPosition();
  76176. }
  76177. bool GZIPCompressorOutputStream::setPosition (int64 /*newPosition*/)
  76178. {
  76179. jassertfalse // can't do it!
  76180. return false;
  76181. }
  76182. END_JUCE_NAMESPACE
  76183. /********* End of inlined file: juce_GZIPCompressorOutputStream.cpp *********/
  76184. /********* Start of inlined file: juce_GZIPDecompressorInputStream.cpp *********/
  76185. #if JUCE_MSVC
  76186. #pragma warning (push)
  76187. #pragma warning (disable: 4309 4305)
  76188. #endif
  76189. namespace zlibNamespace
  76190. {
  76191. #if JUCE_INCLUDE_ZLIB_CODE
  76192. extern "C"
  76193. {
  76194. #undef OS_CODE
  76195. #undef fdopen
  76196. #define ZLIB_INTERNAL
  76197. #define NO_DUMMY_DECL
  76198. /********* Start of inlined file: adler32.c *********/
  76199. #define ZLIB_INTERNAL
  76200. #define BASE 65521UL /* largest prime smaller than 65536 */
  76201. #define NMAX 5552
  76202. #define DO1(buf,i) {adler += (buf)[i]; sum2 += adler;}
  76203. #define DO2(buf,i) DO1(buf,i); DO1(buf,i+1);
  76204. #define DO4(buf,i) DO2(buf,i); DO2(buf,i+2);
  76205. #define DO8(buf,i) DO4(buf,i); DO4(buf,i+4);
  76206. #define DO16(buf) DO8(buf,0); DO8(buf,8);
  76207. #ifdef NO_DIVIDE
  76208. # define MOD(a) \
  76209. do { \
  76210. if (a >= (BASE << 16)) a -= (BASE << 16); \
  76211. if (a >= (BASE << 15)) a -= (BASE << 15); \
  76212. if (a >= (BASE << 14)) a -= (BASE << 14); \
  76213. if (a >= (BASE << 13)) a -= (BASE << 13); \
  76214. if (a >= (BASE << 12)) a -= (BASE << 12); \
  76215. if (a >= (BASE << 11)) a -= (BASE << 11); \
  76216. if (a >= (BASE << 10)) a -= (BASE << 10); \
  76217. if (a >= (BASE << 9)) a -= (BASE << 9); \
  76218. if (a >= (BASE << 8)) a -= (BASE << 8); \
  76219. if (a >= (BASE << 7)) a -= (BASE << 7); \
  76220. if (a >= (BASE << 6)) a -= (BASE << 6); \
  76221. if (a >= (BASE << 5)) a -= (BASE << 5); \
  76222. if (a >= (BASE << 4)) a -= (BASE << 4); \
  76223. if (a >= (BASE << 3)) a -= (BASE << 3); \
  76224. if (a >= (BASE << 2)) a -= (BASE << 2); \
  76225. if (a >= (BASE << 1)) a -= (BASE << 1); \
  76226. if (a >= BASE) a -= BASE; \
  76227. } while (0)
  76228. # define MOD4(a) \
  76229. do { \
  76230. if (a >= (BASE << 4)) a -= (BASE << 4); \
  76231. if (a >= (BASE << 3)) a -= (BASE << 3); \
  76232. if (a >= (BASE << 2)) a -= (BASE << 2); \
  76233. if (a >= (BASE << 1)) a -= (BASE << 1); \
  76234. if (a >= BASE) a -= BASE; \
  76235. } while (0)
  76236. #else
  76237. # define MOD(a) a %= BASE
  76238. # define MOD4(a) a %= BASE
  76239. #endif
  76240. uLong ZEXPORT adler32(uLong adler, const Bytef *buf, uInt len)
  76241. {
  76242. unsigned long sum2;
  76243. unsigned n;
  76244. sum2 = (adler >> 16) & 0xffff;
  76245. adler &= 0xffff;
  76246. if (len == 1) {
  76247. adler += buf[0];
  76248. if (adler >= BASE)
  76249. adler -= BASE;
  76250. sum2 += adler;
  76251. if (sum2 >= BASE)
  76252. sum2 -= BASE;
  76253. return adler | (sum2 << 16);
  76254. }
  76255. if (buf == Z_NULL)
  76256. return 1L;
  76257. if (len < 16) {
  76258. while (len--) {
  76259. adler += *buf++;
  76260. sum2 += adler;
  76261. }
  76262. if (adler >= BASE)
  76263. adler -= BASE;
  76264. MOD4(sum2); /* only added so many BASE's */
  76265. return adler | (sum2 << 16);
  76266. }
  76267. while (len >= NMAX) {
  76268. len -= NMAX;
  76269. n = NMAX / 16; /* NMAX is divisible by 16 */
  76270. do {
  76271. DO16(buf); /* 16 sums unrolled */
  76272. buf += 16;
  76273. } while (--n);
  76274. MOD(adler);
  76275. MOD(sum2);
  76276. }
  76277. if (len) { /* avoid modulos if none remaining */
  76278. while (len >= 16) {
  76279. len -= 16;
  76280. DO16(buf);
  76281. buf += 16;
  76282. }
  76283. while (len--) {
  76284. adler += *buf++;
  76285. sum2 += adler;
  76286. }
  76287. MOD(adler);
  76288. MOD(sum2);
  76289. }
  76290. return adler | (sum2 << 16);
  76291. }
  76292. uLong ZEXPORT adler32_combine(uLong adler1, uLong adler2, z_off_t len2)
  76293. {
  76294. unsigned long sum1;
  76295. unsigned long sum2;
  76296. unsigned rem;
  76297. rem = (unsigned)(len2 % BASE);
  76298. sum1 = adler1 & 0xffff;
  76299. sum2 = rem * sum1;
  76300. MOD(sum2);
  76301. sum1 += (adler2 & 0xffff) + BASE - 1;
  76302. sum2 += ((adler1 >> 16) & 0xffff) + ((adler2 >> 16) & 0xffff) + BASE - rem;
  76303. if (sum1 > BASE) sum1 -= BASE;
  76304. if (sum1 > BASE) sum1 -= BASE;
  76305. if (sum2 > (BASE << 1)) sum2 -= (BASE << 1);
  76306. if (sum2 > BASE) sum2 -= BASE;
  76307. return sum1 | (sum2 << 16);
  76308. }
  76309. /********* End of inlined file: adler32.c *********/
  76310. /********* Start of inlined file: compress.c *********/
  76311. #define ZLIB_INTERNAL
  76312. int ZEXPORT compress2 (Bytef *dest, uLongf *destLen, const Bytef *source,
  76313. uLong sourceLen, int level)
  76314. {
  76315. z_stream stream;
  76316. int err;
  76317. stream.next_in = (Bytef*)source;
  76318. stream.avail_in = (uInt)sourceLen;
  76319. #ifdef MAXSEG_64K
  76320. if ((uLong)stream.avail_in != sourceLen) return Z_BUF_ERROR;
  76321. #endif
  76322. stream.next_out = dest;
  76323. stream.avail_out = (uInt)*destLen;
  76324. if ((uLong)stream.avail_out != *destLen) return Z_BUF_ERROR;
  76325. stream.zalloc = (alloc_func)0;
  76326. stream.zfree = (free_func)0;
  76327. stream.opaque = (voidpf)0;
  76328. err = deflateInit(&stream, level);
  76329. if (err != Z_OK) return err;
  76330. err = deflate(&stream, Z_FINISH);
  76331. if (err != Z_STREAM_END) {
  76332. deflateEnd(&stream);
  76333. return err == Z_OK ? Z_BUF_ERROR : err;
  76334. }
  76335. *destLen = stream.total_out;
  76336. err = deflateEnd(&stream);
  76337. return err;
  76338. }
  76339. int ZEXPORT compress (Bytef *dest, uLongf *destLen, const Bytef *source, uLong sourceLen)
  76340. {
  76341. return compress2(dest, destLen, source, sourceLen, Z_DEFAULT_COMPRESSION);
  76342. }
  76343. uLong ZEXPORT compressBound (uLong sourceLen)
  76344. {
  76345. return sourceLen + (sourceLen >> 12) + (sourceLen >> 14) + 11;
  76346. }
  76347. /********* End of inlined file: compress.c *********/
  76348. #undef DO1
  76349. #undef DO8
  76350. /********* Start of inlined file: crc32.c *********/
  76351. #ifdef MAKECRCH
  76352. # include <stdio.h>
  76353. # ifndef DYNAMIC_CRC_TABLE
  76354. # define DYNAMIC_CRC_TABLE
  76355. # endif /* !DYNAMIC_CRC_TABLE */
  76356. #endif /* MAKECRCH */
  76357. /********* Start of inlined file: zutil.h *********/
  76358. #ifndef ZUTIL_H
  76359. #define ZUTIL_H
  76360. #define ZLIB_INTERNAL
  76361. #ifdef STDC
  76362. # ifndef _WIN32_WCE
  76363. # include <stddef.h>
  76364. # endif
  76365. # include <string.h>
  76366. # include <stdlib.h>
  76367. #endif
  76368. #ifdef NO_ERRNO_H
  76369. # ifdef _WIN32_WCE
  76370. # define errno z_errno
  76371. # endif
  76372. extern int errno;
  76373. #else
  76374. # ifndef _WIN32_WCE
  76375. # include <errno.h>
  76376. # endif
  76377. #endif
  76378. #ifndef local
  76379. # define local static
  76380. #endif
  76381. typedef unsigned char uch;
  76382. typedef uch FAR uchf;
  76383. typedef unsigned short ush;
  76384. typedef ush FAR ushf;
  76385. typedef unsigned long ulg;
  76386. extern const char * const z_errmsg[10]; /* indexed by 2-zlib_error */
  76387. #define ERR_MSG(err) z_errmsg[Z_NEED_DICT-(err)]
  76388. #define ERR_RETURN(strm,err) \
  76389. return (strm->msg = (char*)ERR_MSG(err), (err))
  76390. #ifndef DEF_WBITS
  76391. # define DEF_WBITS MAX_WBITS
  76392. #endif
  76393. #if MAX_MEM_LEVEL >= 8
  76394. # define DEF_MEM_LEVEL 8
  76395. #else
  76396. # define DEF_MEM_LEVEL MAX_MEM_LEVEL
  76397. #endif
  76398. #define STORED_BLOCK 0
  76399. #define STATIC_TREES 1
  76400. #define DYN_TREES 2
  76401. #define MIN_MATCH 3
  76402. #define MAX_MATCH 258
  76403. #define PRESET_DICT 0x20 /* preset dictionary flag in zlib header */
  76404. #if defined(MSDOS) || (defined(WINDOWS) && !defined(WIN32))
  76405. # define OS_CODE 0x00
  76406. # if defined(__TURBOC__) || defined(__BORLANDC__)
  76407. # if(__STDC__ == 1) && (defined(__LARGE__) || defined(__COMPACT__))
  76408. void _Cdecl farfree( void *block );
  76409. void *_Cdecl farmalloc( unsigned long nbytes );
  76410. # else
  76411. # include <alloc.h>
  76412. # endif
  76413. # else /* MSC or DJGPP */
  76414. # include <malloc.h>
  76415. # endif
  76416. #endif
  76417. #ifdef AMIGA
  76418. # define OS_CODE 0x01
  76419. #endif
  76420. #if defined(VAXC) || defined(VMS)
  76421. # define OS_CODE 0x02
  76422. # define F_OPEN(name, mode) \
  76423. fopen((name), (mode), "mbc=60", "ctx=stm", "rfm=fix", "mrs=512")
  76424. #endif
  76425. #if defined(ATARI) || defined(atarist)
  76426. # define OS_CODE 0x05
  76427. #endif
  76428. #ifdef OS2
  76429. # define OS_CODE 0x06
  76430. # ifdef M_I86
  76431. #include <malloc.h>
  76432. # endif
  76433. #endif
  76434. #if defined(MACOS) || TARGET_OS_MAC
  76435. # define OS_CODE 0x07
  76436. # if defined(__MWERKS__) && __dest_os != __be_os && __dest_os != __win32_os
  76437. # include <unix.h> /* for fdopen */
  76438. # else
  76439. # ifndef fdopen
  76440. # define fdopen(fd,mode) NULL /* No fdopen() */
  76441. # endif
  76442. # endif
  76443. #endif
  76444. #ifdef TOPS20
  76445. # define OS_CODE 0x0a
  76446. #endif
  76447. #ifdef WIN32
  76448. # ifndef __CYGWIN__ /* Cygwin is Unix, not Win32 */
  76449. # define OS_CODE 0x0b
  76450. # endif
  76451. #endif
  76452. #ifdef __50SERIES /* Prime/PRIMOS */
  76453. # define OS_CODE 0x0f
  76454. #endif
  76455. #if defined(_BEOS_) || defined(RISCOS)
  76456. # define fdopen(fd,mode) NULL /* No fdopen() */
  76457. #endif
  76458. #if (defined(_MSC_VER) && (_MSC_VER > 600))
  76459. # if defined(_WIN32_WCE)
  76460. # define fdopen(fd,mode) NULL /* No fdopen() */
  76461. # ifndef _PTRDIFF_T_DEFINED
  76462. typedef int ptrdiff_t;
  76463. # define _PTRDIFF_T_DEFINED
  76464. # endif
  76465. # else
  76466. # define fdopen(fd,type) _fdopen(fd,type)
  76467. # endif
  76468. #endif
  76469. #ifndef OS_CODE
  76470. # define OS_CODE 0x03 /* assume Unix */
  76471. #endif
  76472. #ifndef F_OPEN
  76473. # define F_OPEN(name, mode) fopen((name), (mode))
  76474. #endif
  76475. #if defined(STDC99) || (defined(__TURBOC__) && __TURBOC__ >= 0x550)
  76476. # ifndef HAVE_VSNPRINTF
  76477. # define HAVE_VSNPRINTF
  76478. # endif
  76479. #endif
  76480. #if defined(__CYGWIN__)
  76481. # ifndef HAVE_VSNPRINTF
  76482. # define HAVE_VSNPRINTF
  76483. # endif
  76484. #endif
  76485. #ifndef HAVE_VSNPRINTF
  76486. # ifdef MSDOS
  76487. # define NO_vsnprintf
  76488. # endif
  76489. # ifdef __TURBOC__
  76490. # define NO_vsnprintf
  76491. # endif
  76492. # ifdef WIN32
  76493. # if !defined(vsnprintf) && !defined(NO_vsnprintf)
  76494. # define vsnprintf _vsnprintf
  76495. # endif
  76496. # endif
  76497. # ifdef __SASC
  76498. # define NO_vsnprintf
  76499. # endif
  76500. #endif
  76501. #ifdef VMS
  76502. # define NO_vsnprintf
  76503. #endif
  76504. #if defined(pyr)
  76505. # define NO_MEMCPY
  76506. #endif
  76507. #if defined(SMALL_MEDIUM) && !defined(_MSC_VER) && !defined(__SC__)
  76508. # define NO_MEMCPY
  76509. #endif
  76510. #if defined(STDC) && !defined(HAVE_MEMCPY) && !defined(NO_MEMCPY)
  76511. # define HAVE_MEMCPY
  76512. #endif
  76513. #ifdef HAVE_MEMCPY
  76514. # ifdef SMALL_MEDIUM /* MSDOS small or medium model */
  76515. # define zmemcpy _fmemcpy
  76516. # define zmemcmp _fmemcmp
  76517. # define zmemzero(dest, len) _fmemset(dest, 0, len)
  76518. # else
  76519. # define zmemcpy memcpy
  76520. # define zmemcmp memcmp
  76521. # define zmemzero(dest, len) memset(dest, 0, len)
  76522. # endif
  76523. #else
  76524. extern void zmemcpy OF((Bytef* dest, const Bytef* source, uInt len));
  76525. extern int zmemcmp OF((const Bytef* s1, const Bytef* s2, uInt len));
  76526. extern void zmemzero OF((Bytef* dest, uInt len));
  76527. #endif
  76528. #ifdef DEBUG
  76529. # include <stdio.h>
  76530. extern int z_verbose;
  76531. extern void z_error OF((const char *m));
  76532. # define Assert(cond,msg) {if(!(cond)) z_error(msg);}
  76533. # define Trace(x) {if (z_verbose>=0) fprintf x ;}
  76534. # define Tracev(x) {if (z_verbose>0) fprintf x ;}
  76535. # define Tracevv(x) {if (z_verbose>1) fprintf x ;}
  76536. # define Tracec(c,x) {if (z_verbose>0 && (c)) fprintf x ;}
  76537. # define Tracecv(c,x) {if (z_verbose>1 && (c)) fprintf x ;}
  76538. #else
  76539. # define Assert(cond,msg)
  76540. # define Trace(x)
  76541. # define Tracev(x)
  76542. # define Tracevv(x)
  76543. # define Tracec(c,x)
  76544. # define Tracecv(c,x)
  76545. #endif
  76546. voidpf zcalloc OF((voidpf opaque, unsigned items, unsigned size));
  76547. void zcfree OF((voidpf opaque, voidpf ptr));
  76548. #define ZALLOC(strm, items, size) \
  76549. (*((strm)->zalloc))((strm)->opaque, (items), (size))
  76550. #define ZFREE(strm, addr) (*((strm)->zfree))((strm)->opaque, (voidpf)(addr))
  76551. #define TRY_FREE(s, p) {if (p) ZFREE(s, p);}
  76552. #endif /* ZUTIL_H */
  76553. /********* End of inlined file: zutil.h *********/
  76554. #define local static
  76555. #ifndef NOBYFOUR
  76556. # ifdef STDC /* need ANSI C limits.h to determine sizes */
  76557. # include <limits.h>
  76558. # define BYFOUR
  76559. # if (UINT_MAX == 0xffffffffUL)
  76560. typedef unsigned int u4;
  76561. # else
  76562. # if (ULONG_MAX == 0xffffffffUL)
  76563. typedef unsigned long u4;
  76564. # else
  76565. # if (USHRT_MAX == 0xffffffffUL)
  76566. typedef unsigned short u4;
  76567. # else
  76568. # undef BYFOUR /* can't find a four-byte integer type! */
  76569. # endif
  76570. # endif
  76571. # endif
  76572. # endif /* STDC */
  76573. #endif /* !NOBYFOUR */
  76574. #ifdef BYFOUR
  76575. # define REV(w) (((w)>>24)+(((w)>>8)&0xff00)+ \
  76576. (((w)&0xff00)<<8)+(((w)&0xff)<<24))
  76577. local unsigned long crc32_little OF((unsigned long,
  76578. const unsigned char FAR *, unsigned));
  76579. local unsigned long crc32_big OF((unsigned long,
  76580. const unsigned char FAR *, unsigned));
  76581. # define TBLS 8
  76582. #else
  76583. # define TBLS 1
  76584. #endif /* BYFOUR */
  76585. local unsigned long gf2_matrix_times OF((unsigned long *mat,
  76586. unsigned long vec));
  76587. local void gf2_matrix_square OF((unsigned long *square, unsigned long *mat));
  76588. #ifdef DYNAMIC_CRC_TABLE
  76589. local volatile int crc_table_empty = 1;
  76590. local unsigned long FAR crc_table[TBLS][256];
  76591. local void make_crc_table OF((void));
  76592. #ifdef MAKECRCH
  76593. local void write_table OF((FILE *, const unsigned long FAR *));
  76594. #endif /* MAKECRCH */
  76595. local void make_crc_table()
  76596. {
  76597. unsigned long c;
  76598. int n, k;
  76599. unsigned long poly; /* polynomial exclusive-or pattern */
  76600. static volatile int first = 1; /* flag to limit concurrent making */
  76601. static const unsigned char p[] = {0,1,2,4,5,7,8,10,11,12,16,22,23,26};
  76602. if (first) {
  76603. first = 0;
  76604. poly = 0UL;
  76605. for (n = 0; n < sizeof(p)/sizeof(unsigned char); n++)
  76606. poly |= 1UL << (31 - p[n]);
  76607. for (n = 0; n < 256; n++) {
  76608. c = (unsigned long)n;
  76609. for (k = 0; k < 8; k++)
  76610. c = c & 1 ? poly ^ (c >> 1) : c >> 1;
  76611. crc_table[0][n] = c;
  76612. }
  76613. #ifdef BYFOUR
  76614. for (n = 0; n < 256; n++) {
  76615. c = crc_table[0][n];
  76616. crc_table[4][n] = REV(c);
  76617. for (k = 1; k < 4; k++) {
  76618. c = crc_table[0][c & 0xff] ^ (c >> 8);
  76619. crc_table[k][n] = c;
  76620. crc_table[k + 4][n] = REV(c);
  76621. }
  76622. }
  76623. #endif /* BYFOUR */
  76624. crc_table_empty = 0;
  76625. }
  76626. else { /* not first */
  76627. while (crc_table_empty)
  76628. ;
  76629. }
  76630. #ifdef MAKECRCH
  76631. {
  76632. FILE *out;
  76633. out = fopen("crc32.h", "w");
  76634. if (out == NULL) return;
  76635. fprintf(out, "/* crc32.h -- tables for rapid CRC calculation\n");
  76636. fprintf(out, " * Generated automatically by crc32.c\n */\n\n");
  76637. fprintf(out, "local const unsigned long FAR ");
  76638. fprintf(out, "crc_table[TBLS][256] =\n{\n {\n");
  76639. write_table(out, crc_table[0]);
  76640. # ifdef BYFOUR
  76641. fprintf(out, "#ifdef BYFOUR\n");
  76642. for (k = 1; k < 8; k++) {
  76643. fprintf(out, " },\n {\n");
  76644. write_table(out, crc_table[k]);
  76645. }
  76646. fprintf(out, "#endif\n");
  76647. # endif /* BYFOUR */
  76648. fprintf(out, " }\n};\n");
  76649. fclose(out);
  76650. }
  76651. #endif /* MAKECRCH */
  76652. }
  76653. #ifdef MAKECRCH
  76654. local void write_table(out, table)
  76655. FILE *out;
  76656. const unsigned long FAR *table;
  76657. {
  76658. int n;
  76659. for (n = 0; n < 256; n++)
  76660. fprintf(out, "%s0x%08lxUL%s", n % 5 ? "" : " ", table[n],
  76661. n == 255 ? "\n" : (n % 5 == 4 ? ",\n" : ", "));
  76662. }
  76663. #endif /* MAKECRCH */
  76664. #else /* !DYNAMIC_CRC_TABLE */
  76665. /********* Start of inlined file: crc32.h *********/
  76666. local const unsigned long FAR crc_table[TBLS][256] =
  76667. {
  76668. {
  76669. 0x00000000UL, 0x77073096UL, 0xee0e612cUL, 0x990951baUL, 0x076dc419UL,
  76670. 0x706af48fUL, 0xe963a535UL, 0x9e6495a3UL, 0x0edb8832UL, 0x79dcb8a4UL,
  76671. 0xe0d5e91eUL, 0x97d2d988UL, 0x09b64c2bUL, 0x7eb17cbdUL, 0xe7b82d07UL,
  76672. 0x90bf1d91UL, 0x1db71064UL, 0x6ab020f2UL, 0xf3b97148UL, 0x84be41deUL,
  76673. 0x1adad47dUL, 0x6ddde4ebUL, 0xf4d4b551UL, 0x83d385c7UL, 0x136c9856UL,
  76674. 0x646ba8c0UL, 0xfd62f97aUL, 0x8a65c9ecUL, 0x14015c4fUL, 0x63066cd9UL,
  76675. 0xfa0f3d63UL, 0x8d080df5UL, 0x3b6e20c8UL, 0x4c69105eUL, 0xd56041e4UL,
  76676. 0xa2677172UL, 0x3c03e4d1UL, 0x4b04d447UL, 0xd20d85fdUL, 0xa50ab56bUL,
  76677. 0x35b5a8faUL, 0x42b2986cUL, 0xdbbbc9d6UL, 0xacbcf940UL, 0x32d86ce3UL,
  76678. 0x45df5c75UL, 0xdcd60dcfUL, 0xabd13d59UL, 0x26d930acUL, 0x51de003aUL,
  76679. 0xc8d75180UL, 0xbfd06116UL, 0x21b4f4b5UL, 0x56b3c423UL, 0xcfba9599UL,
  76680. 0xb8bda50fUL, 0x2802b89eUL, 0x5f058808UL, 0xc60cd9b2UL, 0xb10be924UL,
  76681. 0x2f6f7c87UL, 0x58684c11UL, 0xc1611dabUL, 0xb6662d3dUL, 0x76dc4190UL,
  76682. 0x01db7106UL, 0x98d220bcUL, 0xefd5102aUL, 0x71b18589UL, 0x06b6b51fUL,
  76683. 0x9fbfe4a5UL, 0xe8b8d433UL, 0x7807c9a2UL, 0x0f00f934UL, 0x9609a88eUL,
  76684. 0xe10e9818UL, 0x7f6a0dbbUL, 0x086d3d2dUL, 0x91646c97UL, 0xe6635c01UL,
  76685. 0x6b6b51f4UL, 0x1c6c6162UL, 0x856530d8UL, 0xf262004eUL, 0x6c0695edUL,
  76686. 0x1b01a57bUL, 0x8208f4c1UL, 0xf50fc457UL, 0x65b0d9c6UL, 0x12b7e950UL,
  76687. 0x8bbeb8eaUL, 0xfcb9887cUL, 0x62dd1ddfUL, 0x15da2d49UL, 0x8cd37cf3UL,
  76688. 0xfbd44c65UL, 0x4db26158UL, 0x3ab551ceUL, 0xa3bc0074UL, 0xd4bb30e2UL,
  76689. 0x4adfa541UL, 0x3dd895d7UL, 0xa4d1c46dUL, 0xd3d6f4fbUL, 0x4369e96aUL,
  76690. 0x346ed9fcUL, 0xad678846UL, 0xda60b8d0UL, 0x44042d73UL, 0x33031de5UL,
  76691. 0xaa0a4c5fUL, 0xdd0d7cc9UL, 0x5005713cUL, 0x270241aaUL, 0xbe0b1010UL,
  76692. 0xc90c2086UL, 0x5768b525UL, 0x206f85b3UL, 0xb966d409UL, 0xce61e49fUL,
  76693. 0x5edef90eUL, 0x29d9c998UL, 0xb0d09822UL, 0xc7d7a8b4UL, 0x59b33d17UL,
  76694. 0x2eb40d81UL, 0xb7bd5c3bUL, 0xc0ba6cadUL, 0xedb88320UL, 0x9abfb3b6UL,
  76695. 0x03b6e20cUL, 0x74b1d29aUL, 0xead54739UL, 0x9dd277afUL, 0x04db2615UL,
  76696. 0x73dc1683UL, 0xe3630b12UL, 0x94643b84UL, 0x0d6d6a3eUL, 0x7a6a5aa8UL,
  76697. 0xe40ecf0bUL, 0x9309ff9dUL, 0x0a00ae27UL, 0x7d079eb1UL, 0xf00f9344UL,
  76698. 0x8708a3d2UL, 0x1e01f268UL, 0x6906c2feUL, 0xf762575dUL, 0x806567cbUL,
  76699. 0x196c3671UL, 0x6e6b06e7UL, 0xfed41b76UL, 0x89d32be0UL, 0x10da7a5aUL,
  76700. 0x67dd4accUL, 0xf9b9df6fUL, 0x8ebeeff9UL, 0x17b7be43UL, 0x60b08ed5UL,
  76701. 0xd6d6a3e8UL, 0xa1d1937eUL, 0x38d8c2c4UL, 0x4fdff252UL, 0xd1bb67f1UL,
  76702. 0xa6bc5767UL, 0x3fb506ddUL, 0x48b2364bUL, 0xd80d2bdaUL, 0xaf0a1b4cUL,
  76703. 0x36034af6UL, 0x41047a60UL, 0xdf60efc3UL, 0xa867df55UL, 0x316e8eefUL,
  76704. 0x4669be79UL, 0xcb61b38cUL, 0xbc66831aUL, 0x256fd2a0UL, 0x5268e236UL,
  76705. 0xcc0c7795UL, 0xbb0b4703UL, 0x220216b9UL, 0x5505262fUL, 0xc5ba3bbeUL,
  76706. 0xb2bd0b28UL, 0x2bb45a92UL, 0x5cb36a04UL, 0xc2d7ffa7UL, 0xb5d0cf31UL,
  76707. 0x2cd99e8bUL, 0x5bdeae1dUL, 0x9b64c2b0UL, 0xec63f226UL, 0x756aa39cUL,
  76708. 0x026d930aUL, 0x9c0906a9UL, 0xeb0e363fUL, 0x72076785UL, 0x05005713UL,
  76709. 0x95bf4a82UL, 0xe2b87a14UL, 0x7bb12baeUL, 0x0cb61b38UL, 0x92d28e9bUL,
  76710. 0xe5d5be0dUL, 0x7cdcefb7UL, 0x0bdbdf21UL, 0x86d3d2d4UL, 0xf1d4e242UL,
  76711. 0x68ddb3f8UL, 0x1fda836eUL, 0x81be16cdUL, 0xf6b9265bUL, 0x6fb077e1UL,
  76712. 0x18b74777UL, 0x88085ae6UL, 0xff0f6a70UL, 0x66063bcaUL, 0x11010b5cUL,
  76713. 0x8f659effUL, 0xf862ae69UL, 0x616bffd3UL, 0x166ccf45UL, 0xa00ae278UL,
  76714. 0xd70dd2eeUL, 0x4e048354UL, 0x3903b3c2UL, 0xa7672661UL, 0xd06016f7UL,
  76715. 0x4969474dUL, 0x3e6e77dbUL, 0xaed16a4aUL, 0xd9d65adcUL, 0x40df0b66UL,
  76716. 0x37d83bf0UL, 0xa9bcae53UL, 0xdebb9ec5UL, 0x47b2cf7fUL, 0x30b5ffe9UL,
  76717. 0xbdbdf21cUL, 0xcabac28aUL, 0x53b39330UL, 0x24b4a3a6UL, 0xbad03605UL,
  76718. 0xcdd70693UL, 0x54de5729UL, 0x23d967bfUL, 0xb3667a2eUL, 0xc4614ab8UL,
  76719. 0x5d681b02UL, 0x2a6f2b94UL, 0xb40bbe37UL, 0xc30c8ea1UL, 0x5a05df1bUL,
  76720. 0x2d02ef8dUL
  76721. #ifdef BYFOUR
  76722. },
  76723. {
  76724. 0x00000000UL, 0x191b3141UL, 0x32366282UL, 0x2b2d53c3UL, 0x646cc504UL,
  76725. 0x7d77f445UL, 0x565aa786UL, 0x4f4196c7UL, 0xc8d98a08UL, 0xd1c2bb49UL,
  76726. 0xfaefe88aUL, 0xe3f4d9cbUL, 0xacb54f0cUL, 0xb5ae7e4dUL, 0x9e832d8eUL,
  76727. 0x87981ccfUL, 0x4ac21251UL, 0x53d92310UL, 0x78f470d3UL, 0x61ef4192UL,
  76728. 0x2eaed755UL, 0x37b5e614UL, 0x1c98b5d7UL, 0x05838496UL, 0x821b9859UL,
  76729. 0x9b00a918UL, 0xb02dfadbUL, 0xa936cb9aUL, 0xe6775d5dUL, 0xff6c6c1cUL,
  76730. 0xd4413fdfUL, 0xcd5a0e9eUL, 0x958424a2UL, 0x8c9f15e3UL, 0xa7b24620UL,
  76731. 0xbea97761UL, 0xf1e8e1a6UL, 0xe8f3d0e7UL, 0xc3de8324UL, 0xdac5b265UL,
  76732. 0x5d5daeaaUL, 0x44469febUL, 0x6f6bcc28UL, 0x7670fd69UL, 0x39316baeUL,
  76733. 0x202a5aefUL, 0x0b07092cUL, 0x121c386dUL, 0xdf4636f3UL, 0xc65d07b2UL,
  76734. 0xed705471UL, 0xf46b6530UL, 0xbb2af3f7UL, 0xa231c2b6UL, 0x891c9175UL,
  76735. 0x9007a034UL, 0x179fbcfbUL, 0x0e848dbaUL, 0x25a9de79UL, 0x3cb2ef38UL,
  76736. 0x73f379ffUL, 0x6ae848beUL, 0x41c51b7dUL, 0x58de2a3cUL, 0xf0794f05UL,
  76737. 0xe9627e44UL, 0xc24f2d87UL, 0xdb541cc6UL, 0x94158a01UL, 0x8d0ebb40UL,
  76738. 0xa623e883UL, 0xbf38d9c2UL, 0x38a0c50dUL, 0x21bbf44cUL, 0x0a96a78fUL,
  76739. 0x138d96ceUL, 0x5ccc0009UL, 0x45d73148UL, 0x6efa628bUL, 0x77e153caUL,
  76740. 0xbabb5d54UL, 0xa3a06c15UL, 0x888d3fd6UL, 0x91960e97UL, 0xded79850UL,
  76741. 0xc7cca911UL, 0xece1fad2UL, 0xf5facb93UL, 0x7262d75cUL, 0x6b79e61dUL,
  76742. 0x4054b5deUL, 0x594f849fUL, 0x160e1258UL, 0x0f152319UL, 0x243870daUL,
  76743. 0x3d23419bUL, 0x65fd6ba7UL, 0x7ce65ae6UL, 0x57cb0925UL, 0x4ed03864UL,
  76744. 0x0191aea3UL, 0x188a9fe2UL, 0x33a7cc21UL, 0x2abcfd60UL, 0xad24e1afUL,
  76745. 0xb43fd0eeUL, 0x9f12832dUL, 0x8609b26cUL, 0xc94824abUL, 0xd05315eaUL,
  76746. 0xfb7e4629UL, 0xe2657768UL, 0x2f3f79f6UL, 0x362448b7UL, 0x1d091b74UL,
  76747. 0x04122a35UL, 0x4b53bcf2UL, 0x52488db3UL, 0x7965de70UL, 0x607eef31UL,
  76748. 0xe7e6f3feUL, 0xfefdc2bfUL, 0xd5d0917cUL, 0xcccba03dUL, 0x838a36faUL,
  76749. 0x9a9107bbUL, 0xb1bc5478UL, 0xa8a76539UL, 0x3b83984bUL, 0x2298a90aUL,
  76750. 0x09b5fac9UL, 0x10aecb88UL, 0x5fef5d4fUL, 0x46f46c0eUL, 0x6dd93fcdUL,
  76751. 0x74c20e8cUL, 0xf35a1243UL, 0xea412302UL, 0xc16c70c1UL, 0xd8774180UL,
  76752. 0x9736d747UL, 0x8e2de606UL, 0xa500b5c5UL, 0xbc1b8484UL, 0x71418a1aUL,
  76753. 0x685abb5bUL, 0x4377e898UL, 0x5a6cd9d9UL, 0x152d4f1eUL, 0x0c367e5fUL,
  76754. 0x271b2d9cUL, 0x3e001cddUL, 0xb9980012UL, 0xa0833153UL, 0x8bae6290UL,
  76755. 0x92b553d1UL, 0xddf4c516UL, 0xc4eff457UL, 0xefc2a794UL, 0xf6d996d5UL,
  76756. 0xae07bce9UL, 0xb71c8da8UL, 0x9c31de6bUL, 0x852aef2aUL, 0xca6b79edUL,
  76757. 0xd37048acUL, 0xf85d1b6fUL, 0xe1462a2eUL, 0x66de36e1UL, 0x7fc507a0UL,
  76758. 0x54e85463UL, 0x4df36522UL, 0x02b2f3e5UL, 0x1ba9c2a4UL, 0x30849167UL,
  76759. 0x299fa026UL, 0xe4c5aeb8UL, 0xfdde9ff9UL, 0xd6f3cc3aUL, 0xcfe8fd7bUL,
  76760. 0x80a96bbcUL, 0x99b25afdUL, 0xb29f093eUL, 0xab84387fUL, 0x2c1c24b0UL,
  76761. 0x350715f1UL, 0x1e2a4632UL, 0x07317773UL, 0x4870e1b4UL, 0x516bd0f5UL,
  76762. 0x7a468336UL, 0x635db277UL, 0xcbfad74eUL, 0xd2e1e60fUL, 0xf9ccb5ccUL,
  76763. 0xe0d7848dUL, 0xaf96124aUL, 0xb68d230bUL, 0x9da070c8UL, 0x84bb4189UL,
  76764. 0x03235d46UL, 0x1a386c07UL, 0x31153fc4UL, 0x280e0e85UL, 0x674f9842UL,
  76765. 0x7e54a903UL, 0x5579fac0UL, 0x4c62cb81UL, 0x8138c51fUL, 0x9823f45eUL,
  76766. 0xb30ea79dUL, 0xaa1596dcUL, 0xe554001bUL, 0xfc4f315aUL, 0xd7626299UL,
  76767. 0xce7953d8UL, 0x49e14f17UL, 0x50fa7e56UL, 0x7bd72d95UL, 0x62cc1cd4UL,
  76768. 0x2d8d8a13UL, 0x3496bb52UL, 0x1fbbe891UL, 0x06a0d9d0UL, 0x5e7ef3ecUL,
  76769. 0x4765c2adUL, 0x6c48916eUL, 0x7553a02fUL, 0x3a1236e8UL, 0x230907a9UL,
  76770. 0x0824546aUL, 0x113f652bUL, 0x96a779e4UL, 0x8fbc48a5UL, 0xa4911b66UL,
  76771. 0xbd8a2a27UL, 0xf2cbbce0UL, 0xebd08da1UL, 0xc0fdde62UL, 0xd9e6ef23UL,
  76772. 0x14bce1bdUL, 0x0da7d0fcUL, 0x268a833fUL, 0x3f91b27eUL, 0x70d024b9UL,
  76773. 0x69cb15f8UL, 0x42e6463bUL, 0x5bfd777aUL, 0xdc656bb5UL, 0xc57e5af4UL,
  76774. 0xee530937UL, 0xf7483876UL, 0xb809aeb1UL, 0xa1129ff0UL, 0x8a3fcc33UL,
  76775. 0x9324fd72UL
  76776. },
  76777. {
  76778. 0x00000000UL, 0x01c26a37UL, 0x0384d46eUL, 0x0246be59UL, 0x0709a8dcUL,
  76779. 0x06cbc2ebUL, 0x048d7cb2UL, 0x054f1685UL, 0x0e1351b8UL, 0x0fd13b8fUL,
  76780. 0x0d9785d6UL, 0x0c55efe1UL, 0x091af964UL, 0x08d89353UL, 0x0a9e2d0aUL,
  76781. 0x0b5c473dUL, 0x1c26a370UL, 0x1de4c947UL, 0x1fa2771eUL, 0x1e601d29UL,
  76782. 0x1b2f0bacUL, 0x1aed619bUL, 0x18abdfc2UL, 0x1969b5f5UL, 0x1235f2c8UL,
  76783. 0x13f798ffUL, 0x11b126a6UL, 0x10734c91UL, 0x153c5a14UL, 0x14fe3023UL,
  76784. 0x16b88e7aUL, 0x177ae44dUL, 0x384d46e0UL, 0x398f2cd7UL, 0x3bc9928eUL,
  76785. 0x3a0bf8b9UL, 0x3f44ee3cUL, 0x3e86840bUL, 0x3cc03a52UL, 0x3d025065UL,
  76786. 0x365e1758UL, 0x379c7d6fUL, 0x35dac336UL, 0x3418a901UL, 0x3157bf84UL,
  76787. 0x3095d5b3UL, 0x32d36beaUL, 0x331101ddUL, 0x246be590UL, 0x25a98fa7UL,
  76788. 0x27ef31feUL, 0x262d5bc9UL, 0x23624d4cUL, 0x22a0277bUL, 0x20e69922UL,
  76789. 0x2124f315UL, 0x2a78b428UL, 0x2bbade1fUL, 0x29fc6046UL, 0x283e0a71UL,
  76790. 0x2d711cf4UL, 0x2cb376c3UL, 0x2ef5c89aUL, 0x2f37a2adUL, 0x709a8dc0UL,
  76791. 0x7158e7f7UL, 0x731e59aeUL, 0x72dc3399UL, 0x7793251cUL, 0x76514f2bUL,
  76792. 0x7417f172UL, 0x75d59b45UL, 0x7e89dc78UL, 0x7f4bb64fUL, 0x7d0d0816UL,
  76793. 0x7ccf6221UL, 0x798074a4UL, 0x78421e93UL, 0x7a04a0caUL, 0x7bc6cafdUL,
  76794. 0x6cbc2eb0UL, 0x6d7e4487UL, 0x6f38fadeUL, 0x6efa90e9UL, 0x6bb5866cUL,
  76795. 0x6a77ec5bUL, 0x68315202UL, 0x69f33835UL, 0x62af7f08UL, 0x636d153fUL,
  76796. 0x612bab66UL, 0x60e9c151UL, 0x65a6d7d4UL, 0x6464bde3UL, 0x662203baUL,
  76797. 0x67e0698dUL, 0x48d7cb20UL, 0x4915a117UL, 0x4b531f4eUL, 0x4a917579UL,
  76798. 0x4fde63fcUL, 0x4e1c09cbUL, 0x4c5ab792UL, 0x4d98dda5UL, 0x46c49a98UL,
  76799. 0x4706f0afUL, 0x45404ef6UL, 0x448224c1UL, 0x41cd3244UL, 0x400f5873UL,
  76800. 0x4249e62aUL, 0x438b8c1dUL, 0x54f16850UL, 0x55330267UL, 0x5775bc3eUL,
  76801. 0x56b7d609UL, 0x53f8c08cUL, 0x523aaabbUL, 0x507c14e2UL, 0x51be7ed5UL,
  76802. 0x5ae239e8UL, 0x5b2053dfUL, 0x5966ed86UL, 0x58a487b1UL, 0x5deb9134UL,
  76803. 0x5c29fb03UL, 0x5e6f455aUL, 0x5fad2f6dUL, 0xe1351b80UL, 0xe0f771b7UL,
  76804. 0xe2b1cfeeUL, 0xe373a5d9UL, 0xe63cb35cUL, 0xe7fed96bUL, 0xe5b86732UL,
  76805. 0xe47a0d05UL, 0xef264a38UL, 0xeee4200fUL, 0xeca29e56UL, 0xed60f461UL,
  76806. 0xe82fe2e4UL, 0xe9ed88d3UL, 0xebab368aUL, 0xea695cbdUL, 0xfd13b8f0UL,
  76807. 0xfcd1d2c7UL, 0xfe976c9eUL, 0xff5506a9UL, 0xfa1a102cUL, 0xfbd87a1bUL,
  76808. 0xf99ec442UL, 0xf85cae75UL, 0xf300e948UL, 0xf2c2837fUL, 0xf0843d26UL,
  76809. 0xf1465711UL, 0xf4094194UL, 0xf5cb2ba3UL, 0xf78d95faUL, 0xf64fffcdUL,
  76810. 0xd9785d60UL, 0xd8ba3757UL, 0xdafc890eUL, 0xdb3ee339UL, 0xde71f5bcUL,
  76811. 0xdfb39f8bUL, 0xddf521d2UL, 0xdc374be5UL, 0xd76b0cd8UL, 0xd6a966efUL,
  76812. 0xd4efd8b6UL, 0xd52db281UL, 0xd062a404UL, 0xd1a0ce33UL, 0xd3e6706aUL,
  76813. 0xd2241a5dUL, 0xc55efe10UL, 0xc49c9427UL, 0xc6da2a7eUL, 0xc7184049UL,
  76814. 0xc25756ccUL, 0xc3953cfbUL, 0xc1d382a2UL, 0xc011e895UL, 0xcb4dafa8UL,
  76815. 0xca8fc59fUL, 0xc8c97bc6UL, 0xc90b11f1UL, 0xcc440774UL, 0xcd866d43UL,
  76816. 0xcfc0d31aUL, 0xce02b92dUL, 0x91af9640UL, 0x906dfc77UL, 0x922b422eUL,
  76817. 0x93e92819UL, 0x96a63e9cUL, 0x976454abUL, 0x9522eaf2UL, 0x94e080c5UL,
  76818. 0x9fbcc7f8UL, 0x9e7eadcfUL, 0x9c381396UL, 0x9dfa79a1UL, 0x98b56f24UL,
  76819. 0x99770513UL, 0x9b31bb4aUL, 0x9af3d17dUL, 0x8d893530UL, 0x8c4b5f07UL,
  76820. 0x8e0de15eUL, 0x8fcf8b69UL, 0x8a809decUL, 0x8b42f7dbUL, 0x89044982UL,
  76821. 0x88c623b5UL, 0x839a6488UL, 0x82580ebfUL, 0x801eb0e6UL, 0x81dcdad1UL,
  76822. 0x8493cc54UL, 0x8551a663UL, 0x8717183aUL, 0x86d5720dUL, 0xa9e2d0a0UL,
  76823. 0xa820ba97UL, 0xaa6604ceUL, 0xaba46ef9UL, 0xaeeb787cUL, 0xaf29124bUL,
  76824. 0xad6fac12UL, 0xacadc625UL, 0xa7f18118UL, 0xa633eb2fUL, 0xa4755576UL,
  76825. 0xa5b73f41UL, 0xa0f829c4UL, 0xa13a43f3UL, 0xa37cfdaaUL, 0xa2be979dUL,
  76826. 0xb5c473d0UL, 0xb40619e7UL, 0xb640a7beUL, 0xb782cd89UL, 0xb2cddb0cUL,
  76827. 0xb30fb13bUL, 0xb1490f62UL, 0xb08b6555UL, 0xbbd72268UL, 0xba15485fUL,
  76828. 0xb853f606UL, 0xb9919c31UL, 0xbcde8ab4UL, 0xbd1ce083UL, 0xbf5a5edaUL,
  76829. 0xbe9834edUL
  76830. },
  76831. {
  76832. 0x00000000UL, 0xb8bc6765UL, 0xaa09c88bUL, 0x12b5afeeUL, 0x8f629757UL,
  76833. 0x37def032UL, 0x256b5fdcUL, 0x9dd738b9UL, 0xc5b428efUL, 0x7d084f8aUL,
  76834. 0x6fbde064UL, 0xd7018701UL, 0x4ad6bfb8UL, 0xf26ad8ddUL, 0xe0df7733UL,
  76835. 0x58631056UL, 0x5019579fUL, 0xe8a530faUL, 0xfa109f14UL, 0x42acf871UL,
  76836. 0xdf7bc0c8UL, 0x67c7a7adUL, 0x75720843UL, 0xcdce6f26UL, 0x95ad7f70UL,
  76837. 0x2d111815UL, 0x3fa4b7fbUL, 0x8718d09eUL, 0x1acfe827UL, 0xa2738f42UL,
  76838. 0xb0c620acUL, 0x087a47c9UL, 0xa032af3eUL, 0x188ec85bUL, 0x0a3b67b5UL,
  76839. 0xb28700d0UL, 0x2f503869UL, 0x97ec5f0cUL, 0x8559f0e2UL, 0x3de59787UL,
  76840. 0x658687d1UL, 0xdd3ae0b4UL, 0xcf8f4f5aUL, 0x7733283fUL, 0xeae41086UL,
  76841. 0x525877e3UL, 0x40edd80dUL, 0xf851bf68UL, 0xf02bf8a1UL, 0x48979fc4UL,
  76842. 0x5a22302aUL, 0xe29e574fUL, 0x7f496ff6UL, 0xc7f50893UL, 0xd540a77dUL,
  76843. 0x6dfcc018UL, 0x359fd04eUL, 0x8d23b72bUL, 0x9f9618c5UL, 0x272a7fa0UL,
  76844. 0xbafd4719UL, 0x0241207cUL, 0x10f48f92UL, 0xa848e8f7UL, 0x9b14583dUL,
  76845. 0x23a83f58UL, 0x311d90b6UL, 0x89a1f7d3UL, 0x1476cf6aUL, 0xaccaa80fUL,
  76846. 0xbe7f07e1UL, 0x06c36084UL, 0x5ea070d2UL, 0xe61c17b7UL, 0xf4a9b859UL,
  76847. 0x4c15df3cUL, 0xd1c2e785UL, 0x697e80e0UL, 0x7bcb2f0eUL, 0xc377486bUL,
  76848. 0xcb0d0fa2UL, 0x73b168c7UL, 0x6104c729UL, 0xd9b8a04cUL, 0x446f98f5UL,
  76849. 0xfcd3ff90UL, 0xee66507eUL, 0x56da371bUL, 0x0eb9274dUL, 0xb6054028UL,
  76850. 0xa4b0efc6UL, 0x1c0c88a3UL, 0x81dbb01aUL, 0x3967d77fUL, 0x2bd27891UL,
  76851. 0x936e1ff4UL, 0x3b26f703UL, 0x839a9066UL, 0x912f3f88UL, 0x299358edUL,
  76852. 0xb4446054UL, 0x0cf80731UL, 0x1e4da8dfUL, 0xa6f1cfbaUL, 0xfe92dfecUL,
  76853. 0x462eb889UL, 0x549b1767UL, 0xec277002UL, 0x71f048bbUL, 0xc94c2fdeUL,
  76854. 0xdbf98030UL, 0x6345e755UL, 0x6b3fa09cUL, 0xd383c7f9UL, 0xc1366817UL,
  76855. 0x798a0f72UL, 0xe45d37cbUL, 0x5ce150aeUL, 0x4e54ff40UL, 0xf6e89825UL,
  76856. 0xae8b8873UL, 0x1637ef16UL, 0x048240f8UL, 0xbc3e279dUL, 0x21e91f24UL,
  76857. 0x99557841UL, 0x8be0d7afUL, 0x335cb0caUL, 0xed59b63bUL, 0x55e5d15eUL,
  76858. 0x47507eb0UL, 0xffec19d5UL, 0x623b216cUL, 0xda874609UL, 0xc832e9e7UL,
  76859. 0x708e8e82UL, 0x28ed9ed4UL, 0x9051f9b1UL, 0x82e4565fUL, 0x3a58313aUL,
  76860. 0xa78f0983UL, 0x1f336ee6UL, 0x0d86c108UL, 0xb53aa66dUL, 0xbd40e1a4UL,
  76861. 0x05fc86c1UL, 0x1749292fUL, 0xaff54e4aUL, 0x322276f3UL, 0x8a9e1196UL,
  76862. 0x982bbe78UL, 0x2097d91dUL, 0x78f4c94bUL, 0xc048ae2eUL, 0xd2fd01c0UL,
  76863. 0x6a4166a5UL, 0xf7965e1cUL, 0x4f2a3979UL, 0x5d9f9697UL, 0xe523f1f2UL,
  76864. 0x4d6b1905UL, 0xf5d77e60UL, 0xe762d18eUL, 0x5fdeb6ebUL, 0xc2098e52UL,
  76865. 0x7ab5e937UL, 0x680046d9UL, 0xd0bc21bcUL, 0x88df31eaUL, 0x3063568fUL,
  76866. 0x22d6f961UL, 0x9a6a9e04UL, 0x07bda6bdUL, 0xbf01c1d8UL, 0xadb46e36UL,
  76867. 0x15080953UL, 0x1d724e9aUL, 0xa5ce29ffUL, 0xb77b8611UL, 0x0fc7e174UL,
  76868. 0x9210d9cdUL, 0x2aacbea8UL, 0x38191146UL, 0x80a57623UL, 0xd8c66675UL,
  76869. 0x607a0110UL, 0x72cfaefeUL, 0xca73c99bUL, 0x57a4f122UL, 0xef189647UL,
  76870. 0xfdad39a9UL, 0x45115eccUL, 0x764dee06UL, 0xcef18963UL, 0xdc44268dUL,
  76871. 0x64f841e8UL, 0xf92f7951UL, 0x41931e34UL, 0x5326b1daUL, 0xeb9ad6bfUL,
  76872. 0xb3f9c6e9UL, 0x0b45a18cUL, 0x19f00e62UL, 0xa14c6907UL, 0x3c9b51beUL,
  76873. 0x842736dbUL, 0x96929935UL, 0x2e2efe50UL, 0x2654b999UL, 0x9ee8defcUL,
  76874. 0x8c5d7112UL, 0x34e11677UL, 0xa9362eceUL, 0x118a49abUL, 0x033fe645UL,
  76875. 0xbb838120UL, 0xe3e09176UL, 0x5b5cf613UL, 0x49e959fdUL, 0xf1553e98UL,
  76876. 0x6c820621UL, 0xd43e6144UL, 0xc68bceaaUL, 0x7e37a9cfUL, 0xd67f4138UL,
  76877. 0x6ec3265dUL, 0x7c7689b3UL, 0xc4caeed6UL, 0x591dd66fUL, 0xe1a1b10aUL,
  76878. 0xf3141ee4UL, 0x4ba87981UL, 0x13cb69d7UL, 0xab770eb2UL, 0xb9c2a15cUL,
  76879. 0x017ec639UL, 0x9ca9fe80UL, 0x241599e5UL, 0x36a0360bUL, 0x8e1c516eUL,
  76880. 0x866616a7UL, 0x3eda71c2UL, 0x2c6fde2cUL, 0x94d3b949UL, 0x090481f0UL,
  76881. 0xb1b8e695UL, 0xa30d497bUL, 0x1bb12e1eUL, 0x43d23e48UL, 0xfb6e592dUL,
  76882. 0xe9dbf6c3UL, 0x516791a6UL, 0xccb0a91fUL, 0x740cce7aUL, 0x66b96194UL,
  76883. 0xde0506f1UL
  76884. },
  76885. {
  76886. 0x00000000UL, 0x96300777UL, 0x2c610eeeUL, 0xba510999UL, 0x19c46d07UL,
  76887. 0x8ff46a70UL, 0x35a563e9UL, 0xa395649eUL, 0x3288db0eUL, 0xa4b8dc79UL,
  76888. 0x1ee9d5e0UL, 0x88d9d297UL, 0x2b4cb609UL, 0xbd7cb17eUL, 0x072db8e7UL,
  76889. 0x911dbf90UL, 0x6410b71dUL, 0xf220b06aUL, 0x4871b9f3UL, 0xde41be84UL,
  76890. 0x7dd4da1aUL, 0xebe4dd6dUL, 0x51b5d4f4UL, 0xc785d383UL, 0x56986c13UL,
  76891. 0xc0a86b64UL, 0x7af962fdUL, 0xecc9658aUL, 0x4f5c0114UL, 0xd96c0663UL,
  76892. 0x633d0ffaUL, 0xf50d088dUL, 0xc8206e3bUL, 0x5e10694cUL, 0xe44160d5UL,
  76893. 0x727167a2UL, 0xd1e4033cUL, 0x47d4044bUL, 0xfd850dd2UL, 0x6bb50aa5UL,
  76894. 0xfaa8b535UL, 0x6c98b242UL, 0xd6c9bbdbUL, 0x40f9bcacUL, 0xe36cd832UL,
  76895. 0x755cdf45UL, 0xcf0dd6dcUL, 0x593dd1abUL, 0xac30d926UL, 0x3a00de51UL,
  76896. 0x8051d7c8UL, 0x1661d0bfUL, 0xb5f4b421UL, 0x23c4b356UL, 0x9995bacfUL,
  76897. 0x0fa5bdb8UL, 0x9eb80228UL, 0x0888055fUL, 0xb2d90cc6UL, 0x24e90bb1UL,
  76898. 0x877c6f2fUL, 0x114c6858UL, 0xab1d61c1UL, 0x3d2d66b6UL, 0x9041dc76UL,
  76899. 0x0671db01UL, 0xbc20d298UL, 0x2a10d5efUL, 0x8985b171UL, 0x1fb5b606UL,
  76900. 0xa5e4bf9fUL, 0x33d4b8e8UL, 0xa2c90778UL, 0x34f9000fUL, 0x8ea80996UL,
  76901. 0x18980ee1UL, 0xbb0d6a7fUL, 0x2d3d6d08UL, 0x976c6491UL, 0x015c63e6UL,
  76902. 0xf4516b6bUL, 0x62616c1cUL, 0xd8306585UL, 0x4e0062f2UL, 0xed95066cUL,
  76903. 0x7ba5011bUL, 0xc1f40882UL, 0x57c40ff5UL, 0xc6d9b065UL, 0x50e9b712UL,
  76904. 0xeab8be8bUL, 0x7c88b9fcUL, 0xdf1ddd62UL, 0x492dda15UL, 0xf37cd38cUL,
  76905. 0x654cd4fbUL, 0x5861b24dUL, 0xce51b53aUL, 0x7400bca3UL, 0xe230bbd4UL,
  76906. 0x41a5df4aUL, 0xd795d83dUL, 0x6dc4d1a4UL, 0xfbf4d6d3UL, 0x6ae96943UL,
  76907. 0xfcd96e34UL, 0x468867adUL, 0xd0b860daUL, 0x732d0444UL, 0xe51d0333UL,
  76908. 0x5f4c0aaaUL, 0xc97c0dddUL, 0x3c710550UL, 0xaa410227UL, 0x10100bbeUL,
  76909. 0x86200cc9UL, 0x25b56857UL, 0xb3856f20UL, 0x09d466b9UL, 0x9fe461ceUL,
  76910. 0x0ef9de5eUL, 0x98c9d929UL, 0x2298d0b0UL, 0xb4a8d7c7UL, 0x173db359UL,
  76911. 0x810db42eUL, 0x3b5cbdb7UL, 0xad6cbac0UL, 0x2083b8edUL, 0xb6b3bf9aUL,
  76912. 0x0ce2b603UL, 0x9ad2b174UL, 0x3947d5eaUL, 0xaf77d29dUL, 0x1526db04UL,
  76913. 0x8316dc73UL, 0x120b63e3UL, 0x843b6494UL, 0x3e6a6d0dUL, 0xa85a6a7aUL,
  76914. 0x0bcf0ee4UL, 0x9dff0993UL, 0x27ae000aUL, 0xb19e077dUL, 0x44930ff0UL,
  76915. 0xd2a30887UL, 0x68f2011eUL, 0xfec20669UL, 0x5d5762f7UL, 0xcb676580UL,
  76916. 0x71366c19UL, 0xe7066b6eUL, 0x761bd4feUL, 0xe02bd389UL, 0x5a7ada10UL,
  76917. 0xcc4add67UL, 0x6fdfb9f9UL, 0xf9efbe8eUL, 0x43beb717UL, 0xd58eb060UL,
  76918. 0xe8a3d6d6UL, 0x7e93d1a1UL, 0xc4c2d838UL, 0x52f2df4fUL, 0xf167bbd1UL,
  76919. 0x6757bca6UL, 0xdd06b53fUL, 0x4b36b248UL, 0xda2b0dd8UL, 0x4c1b0aafUL,
  76920. 0xf64a0336UL, 0x607a0441UL, 0xc3ef60dfUL, 0x55df67a8UL, 0xef8e6e31UL,
  76921. 0x79be6946UL, 0x8cb361cbUL, 0x1a8366bcUL, 0xa0d26f25UL, 0x36e26852UL,
  76922. 0x95770cccUL, 0x03470bbbUL, 0xb9160222UL, 0x2f260555UL, 0xbe3bbac5UL,
  76923. 0x280bbdb2UL, 0x925ab42bUL, 0x046ab35cUL, 0xa7ffd7c2UL, 0x31cfd0b5UL,
  76924. 0x8b9ed92cUL, 0x1daede5bUL, 0xb0c2649bUL, 0x26f263ecUL, 0x9ca36a75UL,
  76925. 0x0a936d02UL, 0xa906099cUL, 0x3f360eebUL, 0x85670772UL, 0x13570005UL,
  76926. 0x824abf95UL, 0x147ab8e2UL, 0xae2bb17bUL, 0x381bb60cUL, 0x9b8ed292UL,
  76927. 0x0dbed5e5UL, 0xb7efdc7cUL, 0x21dfdb0bUL, 0xd4d2d386UL, 0x42e2d4f1UL,
  76928. 0xf8b3dd68UL, 0x6e83da1fUL, 0xcd16be81UL, 0x5b26b9f6UL, 0xe177b06fUL,
  76929. 0x7747b718UL, 0xe65a0888UL, 0x706a0fffUL, 0xca3b0666UL, 0x5c0b0111UL,
  76930. 0xff9e658fUL, 0x69ae62f8UL, 0xd3ff6b61UL, 0x45cf6c16UL, 0x78e20aa0UL,
  76931. 0xeed20dd7UL, 0x5483044eUL, 0xc2b30339UL, 0x612667a7UL, 0xf71660d0UL,
  76932. 0x4d476949UL, 0xdb776e3eUL, 0x4a6ad1aeUL, 0xdc5ad6d9UL, 0x660bdf40UL,
  76933. 0xf03bd837UL, 0x53aebca9UL, 0xc59ebbdeUL, 0x7fcfb247UL, 0xe9ffb530UL,
  76934. 0x1cf2bdbdUL, 0x8ac2bacaUL, 0x3093b353UL, 0xa6a3b424UL, 0x0536d0baUL,
  76935. 0x9306d7cdUL, 0x2957de54UL, 0xbf67d923UL, 0x2e7a66b3UL, 0xb84a61c4UL,
  76936. 0x021b685dUL, 0x942b6f2aUL, 0x37be0bb4UL, 0xa18e0cc3UL, 0x1bdf055aUL,
  76937. 0x8def022dUL
  76938. },
  76939. {
  76940. 0x00000000UL, 0x41311b19UL, 0x82623632UL, 0xc3532d2bUL, 0x04c56c64UL,
  76941. 0x45f4777dUL, 0x86a75a56UL, 0xc796414fUL, 0x088ad9c8UL, 0x49bbc2d1UL,
  76942. 0x8ae8effaUL, 0xcbd9f4e3UL, 0x0c4fb5acUL, 0x4d7eaeb5UL, 0x8e2d839eUL,
  76943. 0xcf1c9887UL, 0x5112c24aUL, 0x1023d953UL, 0xd370f478UL, 0x9241ef61UL,
  76944. 0x55d7ae2eUL, 0x14e6b537UL, 0xd7b5981cUL, 0x96848305UL, 0x59981b82UL,
  76945. 0x18a9009bUL, 0xdbfa2db0UL, 0x9acb36a9UL, 0x5d5d77e6UL, 0x1c6c6cffUL,
  76946. 0xdf3f41d4UL, 0x9e0e5acdUL, 0xa2248495UL, 0xe3159f8cUL, 0x2046b2a7UL,
  76947. 0x6177a9beUL, 0xa6e1e8f1UL, 0xe7d0f3e8UL, 0x2483dec3UL, 0x65b2c5daUL,
  76948. 0xaaae5d5dUL, 0xeb9f4644UL, 0x28cc6b6fUL, 0x69fd7076UL, 0xae6b3139UL,
  76949. 0xef5a2a20UL, 0x2c09070bUL, 0x6d381c12UL, 0xf33646dfUL, 0xb2075dc6UL,
  76950. 0x715470edUL, 0x30656bf4UL, 0xf7f32abbUL, 0xb6c231a2UL, 0x75911c89UL,
  76951. 0x34a00790UL, 0xfbbc9f17UL, 0xba8d840eUL, 0x79dea925UL, 0x38efb23cUL,
  76952. 0xff79f373UL, 0xbe48e86aUL, 0x7d1bc541UL, 0x3c2ade58UL, 0x054f79f0UL,
  76953. 0x447e62e9UL, 0x872d4fc2UL, 0xc61c54dbUL, 0x018a1594UL, 0x40bb0e8dUL,
  76954. 0x83e823a6UL, 0xc2d938bfUL, 0x0dc5a038UL, 0x4cf4bb21UL, 0x8fa7960aUL,
  76955. 0xce968d13UL, 0x0900cc5cUL, 0x4831d745UL, 0x8b62fa6eUL, 0xca53e177UL,
  76956. 0x545dbbbaUL, 0x156ca0a3UL, 0xd63f8d88UL, 0x970e9691UL, 0x5098d7deUL,
  76957. 0x11a9ccc7UL, 0xd2fae1ecUL, 0x93cbfaf5UL, 0x5cd76272UL, 0x1de6796bUL,
  76958. 0xdeb55440UL, 0x9f844f59UL, 0x58120e16UL, 0x1923150fUL, 0xda703824UL,
  76959. 0x9b41233dUL, 0xa76bfd65UL, 0xe65ae67cUL, 0x2509cb57UL, 0x6438d04eUL,
  76960. 0xa3ae9101UL, 0xe29f8a18UL, 0x21cca733UL, 0x60fdbc2aUL, 0xafe124adUL,
  76961. 0xeed03fb4UL, 0x2d83129fUL, 0x6cb20986UL, 0xab2448c9UL, 0xea1553d0UL,
  76962. 0x29467efbUL, 0x687765e2UL, 0xf6793f2fUL, 0xb7482436UL, 0x741b091dUL,
  76963. 0x352a1204UL, 0xf2bc534bUL, 0xb38d4852UL, 0x70de6579UL, 0x31ef7e60UL,
  76964. 0xfef3e6e7UL, 0xbfc2fdfeUL, 0x7c91d0d5UL, 0x3da0cbccUL, 0xfa368a83UL,
  76965. 0xbb07919aUL, 0x7854bcb1UL, 0x3965a7a8UL, 0x4b98833bUL, 0x0aa99822UL,
  76966. 0xc9fab509UL, 0x88cbae10UL, 0x4f5def5fUL, 0x0e6cf446UL, 0xcd3fd96dUL,
  76967. 0x8c0ec274UL, 0x43125af3UL, 0x022341eaUL, 0xc1706cc1UL, 0x804177d8UL,
  76968. 0x47d73697UL, 0x06e62d8eUL, 0xc5b500a5UL, 0x84841bbcUL, 0x1a8a4171UL,
  76969. 0x5bbb5a68UL, 0x98e87743UL, 0xd9d96c5aUL, 0x1e4f2d15UL, 0x5f7e360cUL,
  76970. 0x9c2d1b27UL, 0xdd1c003eUL, 0x120098b9UL, 0x533183a0UL, 0x9062ae8bUL,
  76971. 0xd153b592UL, 0x16c5f4ddUL, 0x57f4efc4UL, 0x94a7c2efUL, 0xd596d9f6UL,
  76972. 0xe9bc07aeUL, 0xa88d1cb7UL, 0x6bde319cUL, 0x2aef2a85UL, 0xed796bcaUL,
  76973. 0xac4870d3UL, 0x6f1b5df8UL, 0x2e2a46e1UL, 0xe136de66UL, 0xa007c57fUL,
  76974. 0x6354e854UL, 0x2265f34dUL, 0xe5f3b202UL, 0xa4c2a91bUL, 0x67918430UL,
  76975. 0x26a09f29UL, 0xb8aec5e4UL, 0xf99fdefdUL, 0x3accf3d6UL, 0x7bfde8cfUL,
  76976. 0xbc6ba980UL, 0xfd5ab299UL, 0x3e099fb2UL, 0x7f3884abUL, 0xb0241c2cUL,
  76977. 0xf1150735UL, 0x32462a1eUL, 0x73773107UL, 0xb4e17048UL, 0xf5d06b51UL,
  76978. 0x3683467aUL, 0x77b25d63UL, 0x4ed7facbUL, 0x0fe6e1d2UL, 0xccb5ccf9UL,
  76979. 0x8d84d7e0UL, 0x4a1296afUL, 0x0b238db6UL, 0xc870a09dUL, 0x8941bb84UL,
  76980. 0x465d2303UL, 0x076c381aUL, 0xc43f1531UL, 0x850e0e28UL, 0x42984f67UL,
  76981. 0x03a9547eUL, 0xc0fa7955UL, 0x81cb624cUL, 0x1fc53881UL, 0x5ef42398UL,
  76982. 0x9da70eb3UL, 0xdc9615aaUL, 0x1b0054e5UL, 0x5a314ffcUL, 0x996262d7UL,
  76983. 0xd85379ceUL, 0x174fe149UL, 0x567efa50UL, 0x952dd77bUL, 0xd41ccc62UL,
  76984. 0x138a8d2dUL, 0x52bb9634UL, 0x91e8bb1fUL, 0xd0d9a006UL, 0xecf37e5eUL,
  76985. 0xadc26547UL, 0x6e91486cUL, 0x2fa05375UL, 0xe836123aUL, 0xa9070923UL,
  76986. 0x6a542408UL, 0x2b653f11UL, 0xe479a796UL, 0xa548bc8fUL, 0x661b91a4UL,
  76987. 0x272a8abdUL, 0xe0bccbf2UL, 0xa18dd0ebUL, 0x62defdc0UL, 0x23efe6d9UL,
  76988. 0xbde1bc14UL, 0xfcd0a70dUL, 0x3f838a26UL, 0x7eb2913fUL, 0xb924d070UL,
  76989. 0xf815cb69UL, 0x3b46e642UL, 0x7a77fd5bUL, 0xb56b65dcUL, 0xf45a7ec5UL,
  76990. 0x370953eeUL, 0x763848f7UL, 0xb1ae09b8UL, 0xf09f12a1UL, 0x33cc3f8aUL,
  76991. 0x72fd2493UL
  76992. },
  76993. {
  76994. 0x00000000UL, 0x376ac201UL, 0x6ed48403UL, 0x59be4602UL, 0xdca80907UL,
  76995. 0xebc2cb06UL, 0xb27c8d04UL, 0x85164f05UL, 0xb851130eUL, 0x8f3bd10fUL,
  76996. 0xd685970dUL, 0xe1ef550cUL, 0x64f91a09UL, 0x5393d808UL, 0x0a2d9e0aUL,
  76997. 0x3d475c0bUL, 0x70a3261cUL, 0x47c9e41dUL, 0x1e77a21fUL, 0x291d601eUL,
  76998. 0xac0b2f1bUL, 0x9b61ed1aUL, 0xc2dfab18UL, 0xf5b56919UL, 0xc8f23512UL,
  76999. 0xff98f713UL, 0xa626b111UL, 0x914c7310UL, 0x145a3c15UL, 0x2330fe14UL,
  77000. 0x7a8eb816UL, 0x4de47a17UL, 0xe0464d38UL, 0xd72c8f39UL, 0x8e92c93bUL,
  77001. 0xb9f80b3aUL, 0x3cee443fUL, 0x0b84863eUL, 0x523ac03cUL, 0x6550023dUL,
  77002. 0x58175e36UL, 0x6f7d9c37UL, 0x36c3da35UL, 0x01a91834UL, 0x84bf5731UL,
  77003. 0xb3d59530UL, 0xea6bd332UL, 0xdd011133UL, 0x90e56b24UL, 0xa78fa925UL,
  77004. 0xfe31ef27UL, 0xc95b2d26UL, 0x4c4d6223UL, 0x7b27a022UL, 0x2299e620UL,
  77005. 0x15f32421UL, 0x28b4782aUL, 0x1fdeba2bUL, 0x4660fc29UL, 0x710a3e28UL,
  77006. 0xf41c712dUL, 0xc376b32cUL, 0x9ac8f52eUL, 0xada2372fUL, 0xc08d9a70UL,
  77007. 0xf7e75871UL, 0xae591e73UL, 0x9933dc72UL, 0x1c259377UL, 0x2b4f5176UL,
  77008. 0x72f11774UL, 0x459bd575UL, 0x78dc897eUL, 0x4fb64b7fUL, 0x16080d7dUL,
  77009. 0x2162cf7cUL, 0xa4748079UL, 0x931e4278UL, 0xcaa0047aUL, 0xfdcac67bUL,
  77010. 0xb02ebc6cUL, 0x87447e6dUL, 0xdefa386fUL, 0xe990fa6eUL, 0x6c86b56bUL,
  77011. 0x5bec776aUL, 0x02523168UL, 0x3538f369UL, 0x087faf62UL, 0x3f156d63UL,
  77012. 0x66ab2b61UL, 0x51c1e960UL, 0xd4d7a665UL, 0xe3bd6464UL, 0xba032266UL,
  77013. 0x8d69e067UL, 0x20cbd748UL, 0x17a11549UL, 0x4e1f534bUL, 0x7975914aUL,
  77014. 0xfc63de4fUL, 0xcb091c4eUL, 0x92b75a4cUL, 0xa5dd984dUL, 0x989ac446UL,
  77015. 0xaff00647UL, 0xf64e4045UL, 0xc1248244UL, 0x4432cd41UL, 0x73580f40UL,
  77016. 0x2ae64942UL, 0x1d8c8b43UL, 0x5068f154UL, 0x67023355UL, 0x3ebc7557UL,
  77017. 0x09d6b756UL, 0x8cc0f853UL, 0xbbaa3a52UL, 0xe2147c50UL, 0xd57ebe51UL,
  77018. 0xe839e25aUL, 0xdf53205bUL, 0x86ed6659UL, 0xb187a458UL, 0x3491eb5dUL,
  77019. 0x03fb295cUL, 0x5a456f5eUL, 0x6d2fad5fUL, 0x801b35e1UL, 0xb771f7e0UL,
  77020. 0xeecfb1e2UL, 0xd9a573e3UL, 0x5cb33ce6UL, 0x6bd9fee7UL, 0x3267b8e5UL,
  77021. 0x050d7ae4UL, 0x384a26efUL, 0x0f20e4eeUL, 0x569ea2ecUL, 0x61f460edUL,
  77022. 0xe4e22fe8UL, 0xd388ede9UL, 0x8a36abebUL, 0xbd5c69eaUL, 0xf0b813fdUL,
  77023. 0xc7d2d1fcUL, 0x9e6c97feUL, 0xa90655ffUL, 0x2c101afaUL, 0x1b7ad8fbUL,
  77024. 0x42c49ef9UL, 0x75ae5cf8UL, 0x48e900f3UL, 0x7f83c2f2UL, 0x263d84f0UL,
  77025. 0x115746f1UL, 0x944109f4UL, 0xa32bcbf5UL, 0xfa958df7UL, 0xcdff4ff6UL,
  77026. 0x605d78d9UL, 0x5737bad8UL, 0x0e89fcdaUL, 0x39e33edbUL, 0xbcf571deUL,
  77027. 0x8b9fb3dfUL, 0xd221f5ddUL, 0xe54b37dcUL, 0xd80c6bd7UL, 0xef66a9d6UL,
  77028. 0xb6d8efd4UL, 0x81b22dd5UL, 0x04a462d0UL, 0x33cea0d1UL, 0x6a70e6d3UL,
  77029. 0x5d1a24d2UL, 0x10fe5ec5UL, 0x27949cc4UL, 0x7e2adac6UL, 0x494018c7UL,
  77030. 0xcc5657c2UL, 0xfb3c95c3UL, 0xa282d3c1UL, 0x95e811c0UL, 0xa8af4dcbUL,
  77031. 0x9fc58fcaUL, 0xc67bc9c8UL, 0xf1110bc9UL, 0x740744ccUL, 0x436d86cdUL,
  77032. 0x1ad3c0cfUL, 0x2db902ceUL, 0x4096af91UL, 0x77fc6d90UL, 0x2e422b92UL,
  77033. 0x1928e993UL, 0x9c3ea696UL, 0xab546497UL, 0xf2ea2295UL, 0xc580e094UL,
  77034. 0xf8c7bc9fUL, 0xcfad7e9eUL, 0x9613389cUL, 0xa179fa9dUL, 0x246fb598UL,
  77035. 0x13057799UL, 0x4abb319bUL, 0x7dd1f39aUL, 0x3035898dUL, 0x075f4b8cUL,
  77036. 0x5ee10d8eUL, 0x698bcf8fUL, 0xec9d808aUL, 0xdbf7428bUL, 0x82490489UL,
  77037. 0xb523c688UL, 0x88649a83UL, 0xbf0e5882UL, 0xe6b01e80UL, 0xd1dadc81UL,
  77038. 0x54cc9384UL, 0x63a65185UL, 0x3a181787UL, 0x0d72d586UL, 0xa0d0e2a9UL,
  77039. 0x97ba20a8UL, 0xce0466aaUL, 0xf96ea4abUL, 0x7c78ebaeUL, 0x4b1229afUL,
  77040. 0x12ac6fadUL, 0x25c6adacUL, 0x1881f1a7UL, 0x2feb33a6UL, 0x765575a4UL,
  77041. 0x413fb7a5UL, 0xc429f8a0UL, 0xf3433aa1UL, 0xaafd7ca3UL, 0x9d97bea2UL,
  77042. 0xd073c4b5UL, 0xe71906b4UL, 0xbea740b6UL, 0x89cd82b7UL, 0x0cdbcdb2UL,
  77043. 0x3bb10fb3UL, 0x620f49b1UL, 0x55658bb0UL, 0x6822d7bbUL, 0x5f4815baUL,
  77044. 0x06f653b8UL, 0x319c91b9UL, 0xb48adebcUL, 0x83e01cbdUL, 0xda5e5abfUL,
  77045. 0xed3498beUL
  77046. },
  77047. {
  77048. 0x00000000UL, 0x6567bcb8UL, 0x8bc809aaUL, 0xeeafb512UL, 0x5797628fUL,
  77049. 0x32f0de37UL, 0xdc5f6b25UL, 0xb938d79dUL, 0xef28b4c5UL, 0x8a4f087dUL,
  77050. 0x64e0bd6fUL, 0x018701d7UL, 0xb8bfd64aUL, 0xddd86af2UL, 0x3377dfe0UL,
  77051. 0x56106358UL, 0x9f571950UL, 0xfa30a5e8UL, 0x149f10faUL, 0x71f8ac42UL,
  77052. 0xc8c07bdfUL, 0xada7c767UL, 0x43087275UL, 0x266fcecdUL, 0x707fad95UL,
  77053. 0x1518112dUL, 0xfbb7a43fUL, 0x9ed01887UL, 0x27e8cf1aUL, 0x428f73a2UL,
  77054. 0xac20c6b0UL, 0xc9477a08UL, 0x3eaf32a0UL, 0x5bc88e18UL, 0xb5673b0aUL,
  77055. 0xd00087b2UL, 0x6938502fUL, 0x0c5fec97UL, 0xe2f05985UL, 0x8797e53dUL,
  77056. 0xd1878665UL, 0xb4e03addUL, 0x5a4f8fcfUL, 0x3f283377UL, 0x8610e4eaUL,
  77057. 0xe3775852UL, 0x0dd8ed40UL, 0x68bf51f8UL, 0xa1f82bf0UL, 0xc49f9748UL,
  77058. 0x2a30225aUL, 0x4f579ee2UL, 0xf66f497fUL, 0x9308f5c7UL, 0x7da740d5UL,
  77059. 0x18c0fc6dUL, 0x4ed09f35UL, 0x2bb7238dUL, 0xc518969fUL, 0xa07f2a27UL,
  77060. 0x1947fdbaUL, 0x7c204102UL, 0x928ff410UL, 0xf7e848a8UL, 0x3d58149bUL,
  77061. 0x583fa823UL, 0xb6901d31UL, 0xd3f7a189UL, 0x6acf7614UL, 0x0fa8caacUL,
  77062. 0xe1077fbeUL, 0x8460c306UL, 0xd270a05eUL, 0xb7171ce6UL, 0x59b8a9f4UL,
  77063. 0x3cdf154cUL, 0x85e7c2d1UL, 0xe0807e69UL, 0x0e2fcb7bUL, 0x6b4877c3UL,
  77064. 0xa20f0dcbUL, 0xc768b173UL, 0x29c70461UL, 0x4ca0b8d9UL, 0xf5986f44UL,
  77065. 0x90ffd3fcUL, 0x7e5066eeUL, 0x1b37da56UL, 0x4d27b90eUL, 0x284005b6UL,
  77066. 0xc6efb0a4UL, 0xa3880c1cUL, 0x1ab0db81UL, 0x7fd76739UL, 0x9178d22bUL,
  77067. 0xf41f6e93UL, 0x03f7263bUL, 0x66909a83UL, 0x883f2f91UL, 0xed589329UL,
  77068. 0x546044b4UL, 0x3107f80cUL, 0xdfa84d1eUL, 0xbacff1a6UL, 0xecdf92feUL,
  77069. 0x89b82e46UL, 0x67179b54UL, 0x027027ecUL, 0xbb48f071UL, 0xde2f4cc9UL,
  77070. 0x3080f9dbUL, 0x55e74563UL, 0x9ca03f6bUL, 0xf9c783d3UL, 0x176836c1UL,
  77071. 0x720f8a79UL, 0xcb375de4UL, 0xae50e15cUL, 0x40ff544eUL, 0x2598e8f6UL,
  77072. 0x73888baeUL, 0x16ef3716UL, 0xf8408204UL, 0x9d273ebcUL, 0x241fe921UL,
  77073. 0x41785599UL, 0xafd7e08bUL, 0xcab05c33UL, 0x3bb659edUL, 0x5ed1e555UL,
  77074. 0xb07e5047UL, 0xd519ecffUL, 0x6c213b62UL, 0x094687daUL, 0xe7e932c8UL,
  77075. 0x828e8e70UL, 0xd49eed28UL, 0xb1f95190UL, 0x5f56e482UL, 0x3a31583aUL,
  77076. 0x83098fa7UL, 0xe66e331fUL, 0x08c1860dUL, 0x6da63ab5UL, 0xa4e140bdUL,
  77077. 0xc186fc05UL, 0x2f294917UL, 0x4a4ef5afUL, 0xf3762232UL, 0x96119e8aUL,
  77078. 0x78be2b98UL, 0x1dd99720UL, 0x4bc9f478UL, 0x2eae48c0UL, 0xc001fdd2UL,
  77079. 0xa566416aUL, 0x1c5e96f7UL, 0x79392a4fUL, 0x97969f5dUL, 0xf2f123e5UL,
  77080. 0x05196b4dUL, 0x607ed7f5UL, 0x8ed162e7UL, 0xebb6de5fUL, 0x528e09c2UL,
  77081. 0x37e9b57aUL, 0xd9460068UL, 0xbc21bcd0UL, 0xea31df88UL, 0x8f566330UL,
  77082. 0x61f9d622UL, 0x049e6a9aUL, 0xbda6bd07UL, 0xd8c101bfUL, 0x366eb4adUL,
  77083. 0x53090815UL, 0x9a4e721dUL, 0xff29cea5UL, 0x11867bb7UL, 0x74e1c70fUL,
  77084. 0xcdd91092UL, 0xa8beac2aUL, 0x46111938UL, 0x2376a580UL, 0x7566c6d8UL,
  77085. 0x10017a60UL, 0xfeaecf72UL, 0x9bc973caUL, 0x22f1a457UL, 0x479618efUL,
  77086. 0xa939adfdUL, 0xcc5e1145UL, 0x06ee4d76UL, 0x6389f1ceUL, 0x8d2644dcUL,
  77087. 0xe841f864UL, 0x51792ff9UL, 0x341e9341UL, 0xdab12653UL, 0xbfd69aebUL,
  77088. 0xe9c6f9b3UL, 0x8ca1450bUL, 0x620ef019UL, 0x07694ca1UL, 0xbe519b3cUL,
  77089. 0xdb362784UL, 0x35999296UL, 0x50fe2e2eUL, 0x99b95426UL, 0xfcdee89eUL,
  77090. 0x12715d8cUL, 0x7716e134UL, 0xce2e36a9UL, 0xab498a11UL, 0x45e63f03UL,
  77091. 0x208183bbUL, 0x7691e0e3UL, 0x13f65c5bUL, 0xfd59e949UL, 0x983e55f1UL,
  77092. 0x2106826cUL, 0x44613ed4UL, 0xaace8bc6UL, 0xcfa9377eUL, 0x38417fd6UL,
  77093. 0x5d26c36eUL, 0xb389767cUL, 0xd6eecac4UL, 0x6fd61d59UL, 0x0ab1a1e1UL,
  77094. 0xe41e14f3UL, 0x8179a84bUL, 0xd769cb13UL, 0xb20e77abUL, 0x5ca1c2b9UL,
  77095. 0x39c67e01UL, 0x80fea99cUL, 0xe5991524UL, 0x0b36a036UL, 0x6e511c8eUL,
  77096. 0xa7166686UL, 0xc271da3eUL, 0x2cde6f2cUL, 0x49b9d394UL, 0xf0810409UL,
  77097. 0x95e6b8b1UL, 0x7b490da3UL, 0x1e2eb11bUL, 0x483ed243UL, 0x2d596efbUL,
  77098. 0xc3f6dbe9UL, 0xa6916751UL, 0x1fa9b0ccUL, 0x7ace0c74UL, 0x9461b966UL,
  77099. 0xf10605deUL
  77100. #endif
  77101. }
  77102. };
  77103. /********* End of inlined file: crc32.h *********/
  77104. #endif /* DYNAMIC_CRC_TABLE */
  77105. const unsigned long FAR * ZEXPORT get_crc_table()
  77106. {
  77107. #ifdef DYNAMIC_CRC_TABLE
  77108. if (crc_table_empty)
  77109. make_crc_table();
  77110. #endif /* DYNAMIC_CRC_TABLE */
  77111. return (const unsigned long FAR *)crc_table;
  77112. }
  77113. #define DO1 crc = crc_table[0][((int)crc ^ (*buf++)) & 0xff] ^ (crc >> 8)
  77114. #define DO8 DO1; DO1; DO1; DO1; DO1; DO1; DO1; DO1
  77115. unsigned long ZEXPORT crc32 (unsigned long crc, const unsigned char FAR *buf, unsigned len)
  77116. {
  77117. if (buf == Z_NULL) return 0UL;
  77118. #ifdef DYNAMIC_CRC_TABLE
  77119. if (crc_table_empty)
  77120. make_crc_table();
  77121. #endif /* DYNAMIC_CRC_TABLE */
  77122. #ifdef BYFOUR
  77123. if (sizeof(void *) == sizeof(ptrdiff_t)) {
  77124. u4 endian;
  77125. endian = 1;
  77126. if (*((unsigned char *)(&endian)))
  77127. return crc32_little(crc, buf, len);
  77128. else
  77129. return crc32_big(crc, buf, len);
  77130. }
  77131. #endif /* BYFOUR */
  77132. crc = crc ^ 0xffffffffUL;
  77133. while (len >= 8) {
  77134. DO8;
  77135. len -= 8;
  77136. }
  77137. if (len) do {
  77138. DO1;
  77139. } while (--len);
  77140. return crc ^ 0xffffffffUL;
  77141. }
  77142. #ifdef BYFOUR
  77143. #define DOLIT4 c ^= *buf4++; \
  77144. c = crc_table[3][c & 0xff] ^ crc_table[2][(c >> 8) & 0xff] ^ \
  77145. crc_table[1][(c >> 16) & 0xff] ^ crc_table[0][c >> 24]
  77146. #define DOLIT32 DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4
  77147. local unsigned long crc32_little(unsigned long crc, const unsigned char FAR *buf, unsigned len)
  77148. {
  77149. register u4 c;
  77150. register const u4 FAR *buf4;
  77151. c = (u4)crc;
  77152. c = ~c;
  77153. while (len && ((ptrdiff_t)buf & 3)) {
  77154. c = crc_table[0][(c ^ *buf++) & 0xff] ^ (c >> 8);
  77155. len--;
  77156. }
  77157. buf4 = (const u4 FAR *)(const void FAR *)buf;
  77158. while (len >= 32) {
  77159. DOLIT32;
  77160. len -= 32;
  77161. }
  77162. while (len >= 4) {
  77163. DOLIT4;
  77164. len -= 4;
  77165. }
  77166. buf = (const unsigned char FAR *)buf4;
  77167. if (len) do {
  77168. c = crc_table[0][(c ^ *buf++) & 0xff] ^ (c >> 8);
  77169. } while (--len);
  77170. c = ~c;
  77171. return (unsigned long)c;
  77172. }
  77173. #define DOBIG4 c ^= *++buf4; \
  77174. c = crc_table[4][c & 0xff] ^ crc_table[5][(c >> 8) & 0xff] ^ \
  77175. crc_table[6][(c >> 16) & 0xff] ^ crc_table[7][c >> 24]
  77176. #define DOBIG32 DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4
  77177. local unsigned long crc32_big (unsigned long crc, const unsigned char FAR *buf, unsigned len)
  77178. {
  77179. register u4 c;
  77180. register const u4 FAR *buf4;
  77181. c = REV((u4)crc);
  77182. c = ~c;
  77183. while (len && ((ptrdiff_t)buf & 3)) {
  77184. c = crc_table[4][(c >> 24) ^ *buf++] ^ (c << 8);
  77185. len--;
  77186. }
  77187. buf4 = (const u4 FAR *)(const void FAR *)buf;
  77188. buf4--;
  77189. while (len >= 32) {
  77190. DOBIG32;
  77191. len -= 32;
  77192. }
  77193. while (len >= 4) {
  77194. DOBIG4;
  77195. len -= 4;
  77196. }
  77197. buf4++;
  77198. buf = (const unsigned char FAR *)buf4;
  77199. if (len) do {
  77200. c = crc_table[4][(c >> 24) ^ *buf++] ^ (c << 8);
  77201. } while (--len);
  77202. c = ~c;
  77203. return (unsigned long)(REV(c));
  77204. }
  77205. #endif /* BYFOUR */
  77206. #define GF2_DIM 32 /* dimension of GF(2) vectors (length of CRC) */
  77207. local unsigned long gf2_matrix_times (unsigned long *mat, unsigned long vec)
  77208. {
  77209. unsigned long sum;
  77210. sum = 0;
  77211. while (vec) {
  77212. if (vec & 1)
  77213. sum ^= *mat;
  77214. vec >>= 1;
  77215. mat++;
  77216. }
  77217. return sum;
  77218. }
  77219. local void gf2_matrix_square (unsigned long *square, unsigned long *mat)
  77220. {
  77221. int n;
  77222. for (n = 0; n < GF2_DIM; n++)
  77223. square[n] = gf2_matrix_times(mat, mat[n]);
  77224. }
  77225. uLong ZEXPORT crc32_combine (uLong crc1, uLong crc2, z_off_t len2)
  77226. {
  77227. int n;
  77228. unsigned long row;
  77229. unsigned long even[GF2_DIM]; /* even-power-of-two zeros operator */
  77230. unsigned long odd[GF2_DIM]; /* odd-power-of-two zeros operator */
  77231. if (len2 == 0)
  77232. return crc1;
  77233. odd[0] = 0xedb88320L; /* CRC-32 polynomial */
  77234. row = 1;
  77235. for (n = 1; n < GF2_DIM; n++) {
  77236. odd[n] = row;
  77237. row <<= 1;
  77238. }
  77239. gf2_matrix_square(even, odd);
  77240. gf2_matrix_square(odd, even);
  77241. do {
  77242. gf2_matrix_square(even, odd);
  77243. if (len2 & 1)
  77244. crc1 = gf2_matrix_times(even, crc1);
  77245. len2 >>= 1;
  77246. if (len2 == 0)
  77247. break;
  77248. gf2_matrix_square(odd, even);
  77249. if (len2 & 1)
  77250. crc1 = gf2_matrix_times(odd, crc1);
  77251. len2 >>= 1;
  77252. } while (len2 != 0);
  77253. crc1 ^= crc2;
  77254. return crc1;
  77255. }
  77256. /********* End of inlined file: crc32.c *********/
  77257. /********* Start of inlined file: deflate.c *********/
  77258. /********* Start of inlined file: deflate.h *********/
  77259. #ifndef DEFLATE_H
  77260. #define DEFLATE_H
  77261. #ifndef NO_GZIP
  77262. # define GZIP
  77263. #endif
  77264. #define NO_DUMMY_DECL
  77265. #define LENGTH_CODES 29
  77266. #define LITERALS 256
  77267. #define L_CODES (LITERALS+1+LENGTH_CODES)
  77268. #define D_CODES 30
  77269. #define BL_CODES 19
  77270. #define HEAP_SIZE (2*L_CODES+1)
  77271. #define MAX_BITS 15
  77272. #define INIT_STATE 42
  77273. #define EXTRA_STATE 69
  77274. #define NAME_STATE 73
  77275. #define COMMENT_STATE 91
  77276. #define HCRC_STATE 103
  77277. #define BUSY_STATE 113
  77278. #define FINISH_STATE 666
  77279. typedef struct ct_data_s {
  77280. union {
  77281. ush freq; /* frequency count */
  77282. ush code; /* bit string */
  77283. } fc;
  77284. union {
  77285. ush dad; /* father node in Huffman tree */
  77286. ush len; /* length of bit string */
  77287. } dl;
  77288. } FAR ct_data;
  77289. #define Freq fc.freq
  77290. #define Code fc.code
  77291. #define Dad dl.dad
  77292. #define Len dl.len
  77293. typedef struct static_tree_desc_s static_tree_desc;
  77294. typedef struct tree_desc_s {
  77295. ct_data *dyn_tree; /* the dynamic tree */
  77296. int max_code; /* largest code with non zero frequency */
  77297. static_tree_desc *stat_desc; /* the corresponding static tree */
  77298. } FAR tree_desc;
  77299. typedef ush Pos;
  77300. typedef Pos FAR Posf;
  77301. typedef unsigned IPos;
  77302. typedef struct internal_state {
  77303. z_streamp strm; /* pointer back to this zlib stream */
  77304. int status; /* as the name implies */
  77305. Bytef *pending_buf; /* output still pending */
  77306. ulg pending_buf_size; /* size of pending_buf */
  77307. Bytef *pending_out; /* next pending byte to output to the stream */
  77308. uInt pending; /* nb of bytes in the pending buffer */
  77309. int wrap; /* bit 0 true for zlib, bit 1 true for gzip */
  77310. gz_headerp gzhead; /* gzip header information to write */
  77311. uInt gzindex; /* where in extra, name, or comment */
  77312. Byte method; /* STORED (for zip only) or DEFLATED */
  77313. int last_flush; /* value of flush param for previous deflate call */
  77314. uInt w_size; /* LZ77 window size (32K by default) */
  77315. uInt w_bits; /* log2(w_size) (8..16) */
  77316. uInt w_mask; /* w_size - 1 */
  77317. Bytef *window;
  77318. ulg window_size;
  77319. Posf *prev;
  77320. Posf *head; /* Heads of the hash chains or NIL. */
  77321. uInt ins_h; /* hash index of string to be inserted */
  77322. uInt hash_size; /* number of elements in hash table */
  77323. uInt hash_bits; /* log2(hash_size) */
  77324. uInt hash_mask; /* hash_size-1 */
  77325. uInt hash_shift;
  77326. long block_start;
  77327. uInt match_length; /* length of best match */
  77328. IPos prev_match; /* previous match */
  77329. int match_available; /* set if previous match exists */
  77330. uInt strstart; /* start of string to insert */
  77331. uInt match_start; /* start of matching string */
  77332. uInt lookahead; /* number of valid bytes ahead in window */
  77333. uInt prev_length;
  77334. uInt max_chain_length;
  77335. uInt max_lazy_match;
  77336. # define max_insert_length max_lazy_match
  77337. int level; /* compression level (1..9) */
  77338. int strategy; /* favor or force Huffman coding*/
  77339. uInt good_match;
  77340. int nice_match; /* Stop searching when current match exceeds this */
  77341. struct ct_data_s dyn_ltree[HEAP_SIZE]; /* literal and length tree */
  77342. struct ct_data_s dyn_dtree[2*D_CODES+1]; /* distance tree */
  77343. struct ct_data_s bl_tree[2*BL_CODES+1]; /* Huffman tree for bit lengths */
  77344. struct tree_desc_s l_desc; /* desc. for literal tree */
  77345. struct tree_desc_s d_desc; /* desc. for distance tree */
  77346. struct tree_desc_s bl_desc; /* desc. for bit length tree */
  77347. ush bl_count[MAX_BITS+1];
  77348. int heap[2*L_CODES+1]; /* heap used to build the Huffman trees */
  77349. int heap_len; /* number of elements in the heap */
  77350. int heap_max; /* element of largest frequency */
  77351. uch depth[2*L_CODES+1];
  77352. uchf *l_buf; /* buffer for literals or lengths */
  77353. uInt lit_bufsize;
  77354. uInt last_lit; /* running index in l_buf */
  77355. ushf *d_buf;
  77356. ulg opt_len; /* bit length of current block with optimal trees */
  77357. ulg static_len; /* bit length of current block with static trees */
  77358. uInt matches; /* number of string matches in current block */
  77359. int last_eob_len; /* bit length of EOB code for last block */
  77360. #ifdef DEBUG
  77361. ulg compressed_len; /* total bit length of compressed file mod 2^32 */
  77362. ulg bits_sent; /* bit length of compressed data sent mod 2^32 */
  77363. #endif
  77364. ush bi_buf;
  77365. int bi_valid;
  77366. } FAR deflate_state;
  77367. #define put_byte(s, c) {s->pending_buf[s->pending++] = (c);}
  77368. #define MIN_LOOKAHEAD (MAX_MATCH+MIN_MATCH+1)
  77369. #define MAX_DIST(s) ((s)->w_size-MIN_LOOKAHEAD)
  77370. void _tr_init OF((deflate_state *s));
  77371. int _tr_tally OF((deflate_state *s, unsigned dist, unsigned lc));
  77372. void _tr_flush_block OF((deflate_state *s, charf *buf, ulg stored_len,
  77373. int eof));
  77374. void _tr_align OF((deflate_state *s));
  77375. void _tr_stored_block OF((deflate_state *s, charf *buf, ulg stored_len,
  77376. int eof));
  77377. #define d_code(dist) \
  77378. ((dist) < 256 ? _dist_code[dist] : _dist_code[256+((dist)>>7)])
  77379. #ifndef DEBUG
  77380. #if defined(GEN_TREES_H) || !defined(STDC)
  77381. extern uch _length_code[];
  77382. extern uch _dist_code[];
  77383. #else
  77384. extern const uch _length_code[];
  77385. extern const uch _dist_code[];
  77386. #endif
  77387. # define _tr_tally_lit(s, c, flush) \
  77388. { uch cc = (c); \
  77389. s->d_buf[s->last_lit] = 0; \
  77390. s->l_buf[s->last_lit++] = cc; \
  77391. s->dyn_ltree[cc].Freq++; \
  77392. flush = (s->last_lit == s->lit_bufsize-1); \
  77393. }
  77394. # define _tr_tally_dist(s, distance, length, flush) \
  77395. { uch len = (length); \
  77396. ush dist = (distance); \
  77397. s->d_buf[s->last_lit] = dist; \
  77398. s->l_buf[s->last_lit++] = len; \
  77399. dist--; \
  77400. s->dyn_ltree[_length_code[len]+LITERALS+1].Freq++; \
  77401. s->dyn_dtree[d_code(dist)].Freq++; \
  77402. flush = (s->last_lit == s->lit_bufsize-1); \
  77403. }
  77404. #else
  77405. # define _tr_tally_lit(s, c, flush) flush = _tr_tally(s, 0, c)
  77406. # define _tr_tally_dist(s, distance, length, flush) \
  77407. flush = _tr_tally(s, distance, length)
  77408. #endif
  77409. #endif /* DEFLATE_H */
  77410. /********* End of inlined file: deflate.h *********/
  77411. const char deflate_copyright[] =
  77412. " deflate 1.2.3 Copyright 1995-2005 Jean-loup Gailly ";
  77413. typedef enum {
  77414. need_more, /* block not completed, need more input or more output */
  77415. block_done, /* block flush performed */
  77416. finish_started, /* finish started, need only more output at next deflate */
  77417. finish_done /* finish done, accept no more input or output */
  77418. } block_state;
  77419. typedef block_state (*compress_func) OF((deflate_state *s, int flush));
  77420. local void fill_window OF((deflate_state *s));
  77421. local block_state deflate_stored OF((deflate_state *s, int flush));
  77422. local block_state deflate_fast OF((deflate_state *s, int flush));
  77423. #ifndef FASTEST
  77424. local block_state deflate_slow OF((deflate_state *s, int flush));
  77425. #endif
  77426. local void lm_init OF((deflate_state *s));
  77427. local void putShortMSB OF((deflate_state *s, uInt b));
  77428. local void flush_pending OF((z_streamp strm));
  77429. local int read_buf OF((z_streamp strm, Bytef *buf, unsigned size));
  77430. #ifndef FASTEST
  77431. #ifdef ASMV
  77432. void match_init OF((void)); /* asm code initialization */
  77433. uInt longest_match OF((deflate_state *s, IPos cur_match));
  77434. #else
  77435. local uInt longest_match OF((deflate_state *s, IPos cur_match));
  77436. #endif
  77437. #endif
  77438. local uInt longest_match_fast OF((deflate_state *s, IPos cur_match));
  77439. #ifdef DEBUG
  77440. local void check_match OF((deflate_state *s, IPos start, IPos match,
  77441. int length));
  77442. #endif
  77443. #define NIL 0
  77444. #ifndef TOO_FAR
  77445. # define TOO_FAR 4096
  77446. #endif
  77447. #define MIN_LOOKAHEAD (MAX_MATCH+MIN_MATCH+1)
  77448. typedef struct config_s {
  77449. ush good_length; /* reduce lazy search above this match length */
  77450. ush max_lazy; /* do not perform lazy search above this match length */
  77451. ush nice_length; /* quit search above this match length */
  77452. ush max_chain;
  77453. compress_func func;
  77454. } config;
  77455. #ifdef FASTEST
  77456. local const config configuration_table[2] = {
  77457. {0, 0, 0, 0, deflate_stored}, /* store only */
  77458. {4, 4, 8, 4, deflate_fast}}; /* max speed, no lazy matches */
  77459. #else
  77460. local const config configuration_table[10] = {
  77461. {0, 0, 0, 0, deflate_stored}, /* store only */
  77462. {4, 4, 8, 4, deflate_fast}, /* max speed, no lazy matches */
  77463. {4, 5, 16, 8, deflate_fast},
  77464. {4, 6, 32, 32, deflate_fast},
  77465. {4, 4, 16, 16, deflate_slow}, /* lazy matches */
  77466. {8, 16, 32, 32, deflate_slow},
  77467. {8, 16, 128, 128, deflate_slow},
  77468. {8, 32, 128, 256, deflate_slow},
  77469. {32, 128, 258, 1024, deflate_slow},
  77470. {32, 258, 258, 4096, deflate_slow}}; /* max compression */
  77471. #endif
  77472. #define EQUAL 0
  77473. #ifndef NO_DUMMY_DECL
  77474. struct static_tree_desc_s {int dummy;}; /* for buggy compilers */
  77475. #endif
  77476. #define UPDATE_HASH(s,h,c) (h = (((h)<<s->hash_shift) ^ (c)) & s->hash_mask)
  77477. #ifdef FASTEST
  77478. #define INSERT_STRING(s, str, match_head) \
  77479. (UPDATE_HASH(s, s->ins_h, s->window[(str) + (MIN_MATCH-1)]), \
  77480. match_head = s->head[s->ins_h], \
  77481. s->head[s->ins_h] = (Pos)(str))
  77482. #else
  77483. #define INSERT_STRING(s, str, match_head) \
  77484. (UPDATE_HASH(s, s->ins_h, s->window[(str) + (MIN_MATCH-1)]), \
  77485. match_head = s->prev[(str) & s->w_mask] = s->head[s->ins_h], \
  77486. s->head[s->ins_h] = (Pos)(str))
  77487. #endif
  77488. #define CLEAR_HASH(s) \
  77489. s->head[s->hash_size-1] = NIL; \
  77490. zmemzero((Bytef *)s->head, (unsigned)(s->hash_size-1)*sizeof(*s->head));
  77491. int ZEXPORT deflateInit_(z_streamp strm, int level, const char *version, int stream_size)
  77492. {
  77493. return deflateInit2_(strm, level, Z_DEFLATED, MAX_WBITS, DEF_MEM_LEVEL,
  77494. Z_DEFAULT_STRATEGY, version, stream_size);
  77495. }
  77496. int ZEXPORT deflateInit2_ (z_streamp strm, int level, int method, int windowBits, int memLevel, int strategy, const char *version, int stream_size)
  77497. {
  77498. deflate_state *s;
  77499. int wrap = 1;
  77500. static const char my_version[] = ZLIB_VERSION;
  77501. ushf *overlay;
  77502. if (version == Z_NULL || version[0] != my_version[0] ||
  77503. stream_size != sizeof(z_stream)) {
  77504. return Z_VERSION_ERROR;
  77505. }
  77506. if (strm == Z_NULL) return Z_STREAM_ERROR;
  77507. strm->msg = Z_NULL;
  77508. if (strm->zalloc == (alloc_func)0) {
  77509. strm->zalloc = zcalloc;
  77510. strm->opaque = (voidpf)0;
  77511. }
  77512. if (strm->zfree == (free_func)0) strm->zfree = zcfree;
  77513. #ifdef FASTEST
  77514. if (level != 0) level = 1;
  77515. #else
  77516. if (level == Z_DEFAULT_COMPRESSION) level = 6;
  77517. #endif
  77518. if (windowBits < 0) { /* suppress zlib wrapper */
  77519. wrap = 0;
  77520. windowBits = -windowBits;
  77521. }
  77522. #ifdef GZIP
  77523. else if (windowBits > 15) {
  77524. wrap = 2; /* write gzip wrapper instead */
  77525. windowBits -= 16;
  77526. }
  77527. #endif
  77528. if (memLevel < 1 || memLevel > MAX_MEM_LEVEL || method != Z_DEFLATED ||
  77529. windowBits < 8 || windowBits > 15 || level < 0 || level > 9 ||
  77530. strategy < 0 || strategy > Z_FIXED) {
  77531. return Z_STREAM_ERROR;
  77532. }
  77533. if (windowBits == 8) windowBits = 9; /* until 256-byte window bug fixed */
  77534. s = (deflate_state *) ZALLOC(strm, 1, sizeof(deflate_state));
  77535. if (s == Z_NULL) return Z_MEM_ERROR;
  77536. strm->state = (struct internal_state FAR *)s;
  77537. s->strm = strm;
  77538. s->wrap = wrap;
  77539. s->gzhead = Z_NULL;
  77540. s->w_bits = windowBits;
  77541. s->w_size = 1 << s->w_bits;
  77542. s->w_mask = s->w_size - 1;
  77543. s->hash_bits = memLevel + 7;
  77544. s->hash_size = 1 << s->hash_bits;
  77545. s->hash_mask = s->hash_size - 1;
  77546. s->hash_shift = ((s->hash_bits+MIN_MATCH-1)/MIN_MATCH);
  77547. s->window = (Bytef *) ZALLOC(strm, s->w_size, 2*sizeof(Byte));
  77548. s->prev = (Posf *) ZALLOC(strm, s->w_size, sizeof(Pos));
  77549. s->head = (Posf *) ZALLOC(strm, s->hash_size, sizeof(Pos));
  77550. s->lit_bufsize = 1 << (memLevel + 6); /* 16K elements by default */
  77551. overlay = (ushf *) ZALLOC(strm, s->lit_bufsize, sizeof(ush)+2);
  77552. s->pending_buf = (uchf *) overlay;
  77553. s->pending_buf_size = (ulg)s->lit_bufsize * (sizeof(ush)+2L);
  77554. if (s->window == Z_NULL || s->prev == Z_NULL || s->head == Z_NULL ||
  77555. s->pending_buf == Z_NULL) {
  77556. s->status = FINISH_STATE;
  77557. strm->msg = (char*)ERR_MSG(Z_MEM_ERROR);
  77558. deflateEnd (strm);
  77559. return Z_MEM_ERROR;
  77560. }
  77561. s->d_buf = overlay + s->lit_bufsize/sizeof(ush);
  77562. s->l_buf = s->pending_buf + (1+sizeof(ush))*s->lit_bufsize;
  77563. s->level = level;
  77564. s->strategy = strategy;
  77565. s->method = (Byte)method;
  77566. return deflateReset(strm);
  77567. }
  77568. int ZEXPORT deflateSetDictionary (z_streamp strm, const Bytef *dictionary, uInt dictLength)
  77569. {
  77570. deflate_state *s;
  77571. uInt length = dictLength;
  77572. uInt n;
  77573. IPos hash_head = 0;
  77574. if (strm == Z_NULL || strm->state == Z_NULL || dictionary == Z_NULL ||
  77575. strm->state->wrap == 2 ||
  77576. (strm->state->wrap == 1 && strm->state->status != INIT_STATE))
  77577. return Z_STREAM_ERROR;
  77578. s = strm->state;
  77579. if (s->wrap)
  77580. strm->adler = adler32(strm->adler, dictionary, dictLength);
  77581. if (length < MIN_MATCH) return Z_OK;
  77582. if (length > MAX_DIST(s)) {
  77583. length = MAX_DIST(s);
  77584. dictionary += dictLength - length; /* use the tail of the dictionary */
  77585. }
  77586. zmemcpy(s->window, dictionary, length);
  77587. s->strstart = length;
  77588. s->block_start = (long)length;
  77589. s->ins_h = s->window[0];
  77590. UPDATE_HASH(s, s->ins_h, s->window[1]);
  77591. for (n = 0; n <= length - MIN_MATCH; n++) {
  77592. INSERT_STRING(s, n, hash_head);
  77593. }
  77594. if (hash_head) hash_head = 0; /* to make compiler happy */
  77595. return Z_OK;
  77596. }
  77597. int ZEXPORT deflateReset (z_streamp strm)
  77598. {
  77599. deflate_state *s;
  77600. if (strm == Z_NULL || strm->state == Z_NULL ||
  77601. strm->zalloc == (alloc_func)0 || strm->zfree == (free_func)0) {
  77602. return Z_STREAM_ERROR;
  77603. }
  77604. strm->total_in = strm->total_out = 0;
  77605. strm->msg = Z_NULL; /* use zfree if we ever allocate msg dynamically */
  77606. strm->data_type = Z_UNKNOWN;
  77607. s = (deflate_state *)strm->state;
  77608. s->pending = 0;
  77609. s->pending_out = s->pending_buf;
  77610. if (s->wrap < 0) {
  77611. s->wrap = -s->wrap; /* was made negative by deflate(..., Z_FINISH); */
  77612. }
  77613. s->status = s->wrap ? INIT_STATE : BUSY_STATE;
  77614. strm->adler =
  77615. #ifdef GZIP
  77616. s->wrap == 2 ? crc32(0L, Z_NULL, 0) :
  77617. #endif
  77618. adler32(0L, Z_NULL, 0);
  77619. s->last_flush = Z_NO_FLUSH;
  77620. _tr_init(s);
  77621. lm_init(s);
  77622. return Z_OK;
  77623. }
  77624. int ZEXPORT deflateSetHeader (z_streamp strm, gz_headerp head)
  77625. {
  77626. if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
  77627. if (strm->state->wrap != 2) return Z_STREAM_ERROR;
  77628. strm->state->gzhead = head;
  77629. return Z_OK;
  77630. }
  77631. int ZEXPORT deflatePrime (z_streamp strm, int bits, int value)
  77632. {
  77633. if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
  77634. strm->state->bi_valid = bits;
  77635. strm->state->bi_buf = (ush)(value & ((1 << bits) - 1));
  77636. return Z_OK;
  77637. }
  77638. int ZEXPORT deflateParams (z_streamp strm, int level, int strategy)
  77639. {
  77640. deflate_state *s;
  77641. compress_func func;
  77642. int err = Z_OK;
  77643. if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
  77644. s = strm->state;
  77645. #ifdef FASTEST
  77646. if (level != 0) level = 1;
  77647. #else
  77648. if (level == Z_DEFAULT_COMPRESSION) level = 6;
  77649. #endif
  77650. if (level < 0 || level > 9 || strategy < 0 || strategy > Z_FIXED) {
  77651. return Z_STREAM_ERROR;
  77652. }
  77653. func = configuration_table[s->level].func;
  77654. if (func != configuration_table[level].func && strm->total_in != 0) {
  77655. err = deflate(strm, Z_PARTIAL_FLUSH);
  77656. }
  77657. if (s->level != level) {
  77658. s->level = level;
  77659. s->max_lazy_match = configuration_table[level].max_lazy;
  77660. s->good_match = configuration_table[level].good_length;
  77661. s->nice_match = configuration_table[level].nice_length;
  77662. s->max_chain_length = configuration_table[level].max_chain;
  77663. }
  77664. s->strategy = strategy;
  77665. return err;
  77666. }
  77667. int ZEXPORT deflateTune (z_streamp strm, int good_length, int max_lazy, int nice_length, int max_chain)
  77668. {
  77669. deflate_state *s;
  77670. if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
  77671. s = strm->state;
  77672. s->good_match = good_length;
  77673. s->max_lazy_match = max_lazy;
  77674. s->nice_match = nice_length;
  77675. s->max_chain_length = max_chain;
  77676. return Z_OK;
  77677. }
  77678. uLong ZEXPORT deflateBound (z_streamp strm, uLong sourceLen)
  77679. {
  77680. deflate_state *s;
  77681. uLong destLen;
  77682. destLen = sourceLen +
  77683. ((sourceLen + 7) >> 3) + ((sourceLen + 63) >> 6) + 11;
  77684. if (strm == Z_NULL || strm->state == Z_NULL)
  77685. return destLen;
  77686. s = strm->state;
  77687. if (s->w_bits != 15 || s->hash_bits != 8 + 7)
  77688. return destLen;
  77689. return compressBound(sourceLen);
  77690. }
  77691. local void putShortMSB (deflate_state *s, uInt b)
  77692. {
  77693. put_byte(s, (Byte)(b >> 8));
  77694. put_byte(s, (Byte)(b & 0xff));
  77695. }
  77696. local void flush_pending (z_streamp strm)
  77697. {
  77698. unsigned len = strm->state->pending;
  77699. if (len > strm->avail_out) len = strm->avail_out;
  77700. if (len == 0) return;
  77701. zmemcpy(strm->next_out, strm->state->pending_out, len);
  77702. strm->next_out += len;
  77703. strm->state->pending_out += len;
  77704. strm->total_out += len;
  77705. strm->avail_out -= len;
  77706. strm->state->pending -= len;
  77707. if (strm->state->pending == 0) {
  77708. strm->state->pending_out = strm->state->pending_buf;
  77709. }
  77710. }
  77711. int ZEXPORT deflate (z_streamp strm, int flush)
  77712. {
  77713. int old_flush; /* value of flush param for previous deflate call */
  77714. deflate_state *s;
  77715. if (strm == Z_NULL || strm->state == Z_NULL ||
  77716. flush > Z_FINISH || flush < 0) {
  77717. return Z_STREAM_ERROR;
  77718. }
  77719. s = strm->state;
  77720. if (strm->next_out == Z_NULL ||
  77721. (strm->next_in == Z_NULL && strm->avail_in != 0) ||
  77722. (s->status == FINISH_STATE && flush != Z_FINISH)) {
  77723. ERR_RETURN(strm, Z_STREAM_ERROR);
  77724. }
  77725. if (strm->avail_out == 0) ERR_RETURN(strm, Z_BUF_ERROR);
  77726. s->strm = strm; /* just in case */
  77727. old_flush = s->last_flush;
  77728. s->last_flush = flush;
  77729. if (s->status == INIT_STATE) {
  77730. #ifdef GZIP
  77731. if (s->wrap == 2) {
  77732. strm->adler = crc32(0L, Z_NULL, 0);
  77733. put_byte(s, 31);
  77734. put_byte(s, 139);
  77735. put_byte(s, 8);
  77736. if (s->gzhead == NULL) {
  77737. put_byte(s, 0);
  77738. put_byte(s, 0);
  77739. put_byte(s, 0);
  77740. put_byte(s, 0);
  77741. put_byte(s, 0);
  77742. put_byte(s, s->level == 9 ? 2 :
  77743. (s->strategy >= Z_HUFFMAN_ONLY || s->level < 2 ?
  77744. 4 : 0));
  77745. put_byte(s, OS_CODE);
  77746. s->status = BUSY_STATE;
  77747. }
  77748. else {
  77749. put_byte(s, (s->gzhead->text ? 1 : 0) +
  77750. (s->gzhead->hcrc ? 2 : 0) +
  77751. (s->gzhead->extra == Z_NULL ? 0 : 4) +
  77752. (s->gzhead->name == Z_NULL ? 0 : 8) +
  77753. (s->gzhead->comment == Z_NULL ? 0 : 16)
  77754. );
  77755. put_byte(s, (Byte)(s->gzhead->time & 0xff));
  77756. put_byte(s, (Byte)((s->gzhead->time >> 8) & 0xff));
  77757. put_byte(s, (Byte)((s->gzhead->time >> 16) & 0xff));
  77758. put_byte(s, (Byte)((s->gzhead->time >> 24) & 0xff));
  77759. put_byte(s, s->level == 9 ? 2 :
  77760. (s->strategy >= Z_HUFFMAN_ONLY || s->level < 2 ?
  77761. 4 : 0));
  77762. put_byte(s, s->gzhead->os & 0xff);
  77763. if (s->gzhead->extra != NULL) {
  77764. put_byte(s, s->gzhead->extra_len & 0xff);
  77765. put_byte(s, (s->gzhead->extra_len >> 8) & 0xff);
  77766. }
  77767. if (s->gzhead->hcrc)
  77768. strm->adler = crc32(strm->adler, s->pending_buf,
  77769. s->pending);
  77770. s->gzindex = 0;
  77771. s->status = EXTRA_STATE;
  77772. }
  77773. }
  77774. else
  77775. #endif
  77776. {
  77777. uInt header = (Z_DEFLATED + ((s->w_bits-8)<<4)) << 8;
  77778. uInt level_flags;
  77779. if (s->strategy >= Z_HUFFMAN_ONLY || s->level < 2)
  77780. level_flags = 0;
  77781. else if (s->level < 6)
  77782. level_flags = 1;
  77783. else if (s->level == 6)
  77784. level_flags = 2;
  77785. else
  77786. level_flags = 3;
  77787. header |= (level_flags << 6);
  77788. if (s->strstart != 0) header |= PRESET_DICT;
  77789. header += 31 - (header % 31);
  77790. s->status = BUSY_STATE;
  77791. putShortMSB(s, header);
  77792. if (s->strstart != 0) {
  77793. putShortMSB(s, (uInt)(strm->adler >> 16));
  77794. putShortMSB(s, (uInt)(strm->adler & 0xffff));
  77795. }
  77796. strm->adler = adler32(0L, Z_NULL, 0);
  77797. }
  77798. }
  77799. #ifdef GZIP
  77800. if (s->status == EXTRA_STATE) {
  77801. if (s->gzhead->extra != NULL) {
  77802. uInt beg = s->pending; /* start of bytes to update crc */
  77803. while (s->gzindex < (s->gzhead->extra_len & 0xffff)) {
  77804. if (s->pending == s->pending_buf_size) {
  77805. if (s->gzhead->hcrc && s->pending > beg)
  77806. strm->adler = crc32(strm->adler, s->pending_buf + beg,
  77807. s->pending - beg);
  77808. flush_pending(strm);
  77809. beg = s->pending;
  77810. if (s->pending == s->pending_buf_size)
  77811. break;
  77812. }
  77813. put_byte(s, s->gzhead->extra[s->gzindex]);
  77814. s->gzindex++;
  77815. }
  77816. if (s->gzhead->hcrc && s->pending > beg)
  77817. strm->adler = crc32(strm->adler, s->pending_buf + beg,
  77818. s->pending - beg);
  77819. if (s->gzindex == s->gzhead->extra_len) {
  77820. s->gzindex = 0;
  77821. s->status = NAME_STATE;
  77822. }
  77823. }
  77824. else
  77825. s->status = NAME_STATE;
  77826. }
  77827. if (s->status == NAME_STATE) {
  77828. if (s->gzhead->name != NULL) {
  77829. uInt beg = s->pending; /* start of bytes to update crc */
  77830. int val;
  77831. do {
  77832. if (s->pending == s->pending_buf_size) {
  77833. if (s->gzhead->hcrc && s->pending > beg)
  77834. strm->adler = crc32(strm->adler, s->pending_buf + beg,
  77835. s->pending - beg);
  77836. flush_pending(strm);
  77837. beg = s->pending;
  77838. if (s->pending == s->pending_buf_size) {
  77839. val = 1;
  77840. break;
  77841. }
  77842. }
  77843. val = s->gzhead->name[s->gzindex++];
  77844. put_byte(s, val);
  77845. } while (val != 0);
  77846. if (s->gzhead->hcrc && s->pending > beg)
  77847. strm->adler = crc32(strm->adler, s->pending_buf + beg,
  77848. s->pending - beg);
  77849. if (val == 0) {
  77850. s->gzindex = 0;
  77851. s->status = COMMENT_STATE;
  77852. }
  77853. }
  77854. else
  77855. s->status = COMMENT_STATE;
  77856. }
  77857. if (s->status == COMMENT_STATE) {
  77858. if (s->gzhead->comment != NULL) {
  77859. uInt beg = s->pending; /* start of bytes to update crc */
  77860. int val;
  77861. do {
  77862. if (s->pending == s->pending_buf_size) {
  77863. if (s->gzhead->hcrc && s->pending > beg)
  77864. strm->adler = crc32(strm->adler, s->pending_buf + beg,
  77865. s->pending - beg);
  77866. flush_pending(strm);
  77867. beg = s->pending;
  77868. if (s->pending == s->pending_buf_size) {
  77869. val = 1;
  77870. break;
  77871. }
  77872. }
  77873. val = s->gzhead->comment[s->gzindex++];
  77874. put_byte(s, val);
  77875. } while (val != 0);
  77876. if (s->gzhead->hcrc && s->pending > beg)
  77877. strm->adler = crc32(strm->adler, s->pending_buf + beg,
  77878. s->pending - beg);
  77879. if (val == 0)
  77880. s->status = HCRC_STATE;
  77881. }
  77882. else
  77883. s->status = HCRC_STATE;
  77884. }
  77885. if (s->status == HCRC_STATE) {
  77886. if (s->gzhead->hcrc) {
  77887. if (s->pending + 2 > s->pending_buf_size)
  77888. flush_pending(strm);
  77889. if (s->pending + 2 <= s->pending_buf_size) {
  77890. put_byte(s, (Byte)(strm->adler & 0xff));
  77891. put_byte(s, (Byte)((strm->adler >> 8) & 0xff));
  77892. strm->adler = crc32(0L, Z_NULL, 0);
  77893. s->status = BUSY_STATE;
  77894. }
  77895. }
  77896. else
  77897. s->status = BUSY_STATE;
  77898. }
  77899. #endif
  77900. if (s->pending != 0) {
  77901. flush_pending(strm);
  77902. if (strm->avail_out == 0) {
  77903. s->last_flush = -1;
  77904. return Z_OK;
  77905. }
  77906. } else if (strm->avail_in == 0 && flush <= old_flush &&
  77907. flush != Z_FINISH) {
  77908. ERR_RETURN(strm, Z_BUF_ERROR);
  77909. }
  77910. if (s->status == FINISH_STATE && strm->avail_in != 0) {
  77911. ERR_RETURN(strm, Z_BUF_ERROR);
  77912. }
  77913. if (strm->avail_in != 0 || s->lookahead != 0 ||
  77914. (flush != Z_NO_FLUSH && s->status != FINISH_STATE)) {
  77915. block_state bstate;
  77916. bstate = (*(configuration_table[s->level].func))(s, flush);
  77917. if (bstate == finish_started || bstate == finish_done) {
  77918. s->status = FINISH_STATE;
  77919. }
  77920. if (bstate == need_more || bstate == finish_started) {
  77921. if (strm->avail_out == 0) {
  77922. s->last_flush = -1; /* avoid BUF_ERROR next call, see above */
  77923. }
  77924. return Z_OK;
  77925. }
  77926. if (bstate == block_done) {
  77927. if (flush == Z_PARTIAL_FLUSH) {
  77928. _tr_align(s);
  77929. } else { /* FULL_FLUSH or SYNC_FLUSH */
  77930. _tr_stored_block(s, (char*)0, 0L, 0);
  77931. if (flush == Z_FULL_FLUSH) {
  77932. CLEAR_HASH(s); /* forget history */
  77933. }
  77934. }
  77935. flush_pending(strm);
  77936. if (strm->avail_out == 0) {
  77937. s->last_flush = -1; /* avoid BUF_ERROR at next call, see above */
  77938. return Z_OK;
  77939. }
  77940. }
  77941. }
  77942. Assert(strm->avail_out > 0, "bug2");
  77943. if (flush != Z_FINISH) return Z_OK;
  77944. if (s->wrap <= 0) return Z_STREAM_END;
  77945. #ifdef GZIP
  77946. if (s->wrap == 2) {
  77947. put_byte(s, (Byte)(strm->adler & 0xff));
  77948. put_byte(s, (Byte)((strm->adler >> 8) & 0xff));
  77949. put_byte(s, (Byte)((strm->adler >> 16) & 0xff));
  77950. put_byte(s, (Byte)((strm->adler >> 24) & 0xff));
  77951. put_byte(s, (Byte)(strm->total_in & 0xff));
  77952. put_byte(s, (Byte)((strm->total_in >> 8) & 0xff));
  77953. put_byte(s, (Byte)((strm->total_in >> 16) & 0xff));
  77954. put_byte(s, (Byte)((strm->total_in >> 24) & 0xff));
  77955. }
  77956. else
  77957. #endif
  77958. {
  77959. putShortMSB(s, (uInt)(strm->adler >> 16));
  77960. putShortMSB(s, (uInt)(strm->adler & 0xffff));
  77961. }
  77962. flush_pending(strm);
  77963. if (s->wrap > 0) s->wrap = -s->wrap; /* write the trailer only once! */
  77964. return s->pending != 0 ? Z_OK : Z_STREAM_END;
  77965. }
  77966. int ZEXPORT deflateEnd (z_streamp strm)
  77967. {
  77968. int status;
  77969. if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
  77970. status = strm->state->status;
  77971. if (status != INIT_STATE &&
  77972. status != EXTRA_STATE &&
  77973. status != NAME_STATE &&
  77974. status != COMMENT_STATE &&
  77975. status != HCRC_STATE &&
  77976. status != BUSY_STATE &&
  77977. status != FINISH_STATE) {
  77978. return Z_STREAM_ERROR;
  77979. }
  77980. TRY_FREE(strm, strm->state->pending_buf);
  77981. TRY_FREE(strm, strm->state->head);
  77982. TRY_FREE(strm, strm->state->prev);
  77983. TRY_FREE(strm, strm->state->window);
  77984. ZFREE(strm, strm->state);
  77985. strm->state = Z_NULL;
  77986. return status == BUSY_STATE ? Z_DATA_ERROR : Z_OK;
  77987. }
  77988. int ZEXPORT deflateCopy (z_streamp dest, z_streamp source)
  77989. {
  77990. #ifdef MAXSEG_64K
  77991. return Z_STREAM_ERROR;
  77992. #else
  77993. deflate_state *ds;
  77994. deflate_state *ss;
  77995. ushf *overlay;
  77996. if (source == Z_NULL || dest == Z_NULL || source->state == Z_NULL) {
  77997. return Z_STREAM_ERROR;
  77998. }
  77999. ss = source->state;
  78000. zmemcpy(dest, source, sizeof(z_stream));
  78001. ds = (deflate_state *) ZALLOC(dest, 1, sizeof(deflate_state));
  78002. if (ds == Z_NULL) return Z_MEM_ERROR;
  78003. dest->state = (struct internal_state FAR *) ds;
  78004. zmemcpy(ds, ss, sizeof(deflate_state));
  78005. ds->strm = dest;
  78006. ds->window = (Bytef *) ZALLOC(dest, ds->w_size, 2*sizeof(Byte));
  78007. ds->prev = (Posf *) ZALLOC(dest, ds->w_size, sizeof(Pos));
  78008. ds->head = (Posf *) ZALLOC(dest, ds->hash_size, sizeof(Pos));
  78009. overlay = (ushf *) ZALLOC(dest, ds->lit_bufsize, sizeof(ush)+2);
  78010. ds->pending_buf = (uchf *) overlay;
  78011. if (ds->window == Z_NULL || ds->prev == Z_NULL || ds->head == Z_NULL ||
  78012. ds->pending_buf == Z_NULL) {
  78013. deflateEnd (dest);
  78014. return Z_MEM_ERROR;
  78015. }
  78016. zmemcpy(ds->window, ss->window, ds->w_size * 2 * sizeof(Byte));
  78017. zmemcpy(ds->prev, ss->prev, ds->w_size * sizeof(Pos));
  78018. zmemcpy(ds->head, ss->head, ds->hash_size * sizeof(Pos));
  78019. zmemcpy(ds->pending_buf, ss->pending_buf, (uInt)ds->pending_buf_size);
  78020. ds->pending_out = ds->pending_buf + (ss->pending_out - ss->pending_buf);
  78021. ds->d_buf = overlay + ds->lit_bufsize/sizeof(ush);
  78022. ds->l_buf = ds->pending_buf + (1+sizeof(ush))*ds->lit_bufsize;
  78023. ds->l_desc.dyn_tree = ds->dyn_ltree;
  78024. ds->d_desc.dyn_tree = ds->dyn_dtree;
  78025. ds->bl_desc.dyn_tree = ds->bl_tree;
  78026. return Z_OK;
  78027. #endif /* MAXSEG_64K */
  78028. }
  78029. local int read_buf (z_streamp strm, Bytef *buf, unsigned size)
  78030. {
  78031. unsigned len = strm->avail_in;
  78032. if (len > size) len = size;
  78033. if (len == 0) return 0;
  78034. strm->avail_in -= len;
  78035. if (strm->state->wrap == 1) {
  78036. strm->adler = adler32(strm->adler, strm->next_in, len);
  78037. }
  78038. #ifdef GZIP
  78039. else if (strm->state->wrap == 2) {
  78040. strm->adler = crc32(strm->adler, strm->next_in, len);
  78041. }
  78042. #endif
  78043. zmemcpy(buf, strm->next_in, len);
  78044. strm->next_in += len;
  78045. strm->total_in += len;
  78046. return (int)len;
  78047. }
  78048. local void lm_init (deflate_state *s)
  78049. {
  78050. s->window_size = (ulg)2L*s->w_size;
  78051. CLEAR_HASH(s);
  78052. s->max_lazy_match = configuration_table[s->level].max_lazy;
  78053. s->good_match = configuration_table[s->level].good_length;
  78054. s->nice_match = configuration_table[s->level].nice_length;
  78055. s->max_chain_length = configuration_table[s->level].max_chain;
  78056. s->strstart = 0;
  78057. s->block_start = 0L;
  78058. s->lookahead = 0;
  78059. s->match_length = s->prev_length = MIN_MATCH-1;
  78060. s->match_available = 0;
  78061. s->ins_h = 0;
  78062. #ifndef FASTEST
  78063. #ifdef ASMV
  78064. match_init(); /* initialize the asm code */
  78065. #endif
  78066. #endif
  78067. }
  78068. #ifndef FASTEST
  78069. #ifndef ASMV
  78070. local uInt longest_match(deflate_state *s, IPos cur_match)
  78071. {
  78072. unsigned chain_length = s->max_chain_length;/* max hash chain length */
  78073. register Bytef *scan = s->window + s->strstart; /* current string */
  78074. register Bytef *match; /* matched string */
  78075. register int len; /* length of current match */
  78076. int best_len = s->prev_length; /* best match length so far */
  78077. int nice_match = s->nice_match; /* stop if match long enough */
  78078. IPos limit = s->strstart > (IPos)MAX_DIST(s) ?
  78079. s->strstart - (IPos)MAX_DIST(s) : NIL;
  78080. Posf *prev = s->prev;
  78081. uInt wmask = s->w_mask;
  78082. #ifdef UNALIGNED_OK
  78083. register Bytef *strend = s->window + s->strstart + MAX_MATCH - 1;
  78084. register ush scan_start = *(ushf*)scan;
  78085. register ush scan_end = *(ushf*)(scan+best_len-1);
  78086. #else
  78087. register Bytef *strend = s->window + s->strstart + MAX_MATCH;
  78088. register Byte scan_end1 = scan[best_len-1];
  78089. register Byte scan_end = scan[best_len];
  78090. #endif
  78091. Assert(s->hash_bits >= 8 && MAX_MATCH == 258, "Code too clever");
  78092. if (s->prev_length >= s->good_match) {
  78093. chain_length >>= 2;
  78094. }
  78095. if ((uInt)nice_match > s->lookahead) nice_match = s->lookahead;
  78096. Assert((ulg)s->strstart <= s->window_size-MIN_LOOKAHEAD, "need lookahead");
  78097. do {
  78098. Assert(cur_match < s->strstart, "no future");
  78099. match = s->window + cur_match;
  78100. #if (defined(UNALIGNED_OK) && MAX_MATCH == 258)
  78101. if (*(ushf*)(match+best_len-1) != scan_end ||
  78102. *(ushf*)match != scan_start) continue;
  78103. Assert(scan[2] == match[2], "scan[2]?");
  78104. scan++, match++;
  78105. do {
  78106. } while (*(ushf*)(scan+=2) == *(ushf*)(match+=2) &&
  78107. *(ushf*)(scan+=2) == *(ushf*)(match+=2) &&
  78108. *(ushf*)(scan+=2) == *(ushf*)(match+=2) &&
  78109. *(ushf*)(scan+=2) == *(ushf*)(match+=2) &&
  78110. scan < strend);
  78111. Assert(scan <= s->window+(unsigned)(s->window_size-1), "wild scan");
  78112. if (*scan == *match) scan++;
  78113. len = (MAX_MATCH - 1) - (int)(strend-scan);
  78114. scan = strend - (MAX_MATCH-1);
  78115. #else /* UNALIGNED_OK */
  78116. if (match[best_len] != scan_end ||
  78117. match[best_len-1] != scan_end1 ||
  78118. *match != *scan ||
  78119. *++match != scan[1]) continue;
  78120. scan += 2, match++;
  78121. Assert(*scan == *match, "match[2]?");
  78122. do {
  78123. } while (*++scan == *++match && *++scan == *++match &&
  78124. *++scan == *++match && *++scan == *++match &&
  78125. *++scan == *++match && *++scan == *++match &&
  78126. *++scan == *++match && *++scan == *++match &&
  78127. scan < strend);
  78128. Assert(scan <= s->window+(unsigned)(s->window_size-1), "wild scan");
  78129. len = MAX_MATCH - (int)(strend - scan);
  78130. scan = strend - MAX_MATCH;
  78131. #endif /* UNALIGNED_OK */
  78132. if (len > best_len) {
  78133. s->match_start = cur_match;
  78134. best_len = len;
  78135. if (len >= nice_match) break;
  78136. #ifdef UNALIGNED_OK
  78137. scan_end = *(ushf*)(scan+best_len-1);
  78138. #else
  78139. scan_end1 = scan[best_len-1];
  78140. scan_end = scan[best_len];
  78141. #endif
  78142. }
  78143. } while ((cur_match = prev[cur_match & wmask]) > limit
  78144. && --chain_length != 0);
  78145. if ((uInt)best_len <= s->lookahead) return (uInt)best_len;
  78146. return s->lookahead;
  78147. }
  78148. #endif /* ASMV */
  78149. #endif /* FASTEST */
  78150. local uInt longest_match_fast (deflate_state *s, IPos cur_match)
  78151. {
  78152. register Bytef *scan = s->window + s->strstart; /* current string */
  78153. register Bytef *match; /* matched string */
  78154. register int len; /* length of current match */
  78155. register Bytef *strend = s->window + s->strstart + MAX_MATCH;
  78156. Assert(s->hash_bits >= 8 && MAX_MATCH == 258, "Code too clever");
  78157. Assert((ulg)s->strstart <= s->window_size-MIN_LOOKAHEAD, "need lookahead");
  78158. Assert(cur_match < s->strstart, "no future");
  78159. match = s->window + cur_match;
  78160. if (match[0] != scan[0] || match[1] != scan[1]) return MIN_MATCH-1;
  78161. scan += 2, match += 2;
  78162. Assert(*scan == *match, "match[2]?");
  78163. do {
  78164. } while (*++scan == *++match && *++scan == *++match &&
  78165. *++scan == *++match && *++scan == *++match &&
  78166. *++scan == *++match && *++scan == *++match &&
  78167. *++scan == *++match && *++scan == *++match &&
  78168. scan < strend);
  78169. Assert(scan <= s->window+(unsigned)(s->window_size-1), "wild scan");
  78170. len = MAX_MATCH - (int)(strend - scan);
  78171. if (len < MIN_MATCH) return MIN_MATCH - 1;
  78172. s->match_start = cur_match;
  78173. return (uInt)len <= s->lookahead ? (uInt)len : s->lookahead;
  78174. }
  78175. #ifdef DEBUG
  78176. local void check_match(deflate_state *s, IPos start, IPos match, int length)
  78177. {
  78178. if (zmemcmp(s->window + match,
  78179. s->window + start, length) != EQUAL) {
  78180. fprintf(stderr, " start %u, match %u, length %d\n",
  78181. start, match, length);
  78182. do {
  78183. fprintf(stderr, "%c%c", s->window[match++], s->window[start++]);
  78184. } while (--length != 0);
  78185. z_error("invalid match");
  78186. }
  78187. if (z_verbose > 1) {
  78188. fprintf(stderr,"\\[%d,%d]", start-match, length);
  78189. do { putc(s->window[start++], stderr); } while (--length != 0);
  78190. }
  78191. }
  78192. #else
  78193. # define check_match(s, start, match, length)
  78194. #endif /* DEBUG */
  78195. local void fill_window (deflate_state *s)
  78196. {
  78197. register unsigned n, m;
  78198. register Posf *p;
  78199. unsigned more; /* Amount of free space at the end of the window. */
  78200. uInt wsize = s->w_size;
  78201. do {
  78202. more = (unsigned)(s->window_size -(ulg)s->lookahead -(ulg)s->strstart);
  78203. if (sizeof(int) <= 2) {
  78204. if (more == 0 && s->strstart == 0 && s->lookahead == 0) {
  78205. more = wsize;
  78206. } else if (more == (unsigned)(-1)) {
  78207. more--;
  78208. }
  78209. }
  78210. if (s->strstart >= wsize+MAX_DIST(s)) {
  78211. zmemcpy(s->window, s->window+wsize, (unsigned)wsize);
  78212. s->match_start -= wsize;
  78213. s->strstart -= wsize; /* we now have strstart >= MAX_DIST */
  78214. s->block_start -= (long) wsize;
  78215. n = s->hash_size;
  78216. p = &s->head[n];
  78217. do {
  78218. m = *--p;
  78219. *p = (Pos)(m >= wsize ? m-wsize : NIL);
  78220. } while (--n);
  78221. n = wsize;
  78222. #ifndef FASTEST
  78223. p = &s->prev[n];
  78224. do {
  78225. m = *--p;
  78226. *p = (Pos)(m >= wsize ? m-wsize : NIL);
  78227. } while (--n);
  78228. #endif
  78229. more += wsize;
  78230. }
  78231. if (s->strm->avail_in == 0) return;
  78232. Assert(more >= 2, "more < 2");
  78233. n = read_buf(s->strm, s->window + s->strstart + s->lookahead, more);
  78234. s->lookahead += n;
  78235. if (s->lookahead >= MIN_MATCH) {
  78236. s->ins_h = s->window[s->strstart];
  78237. UPDATE_HASH(s, s->ins_h, s->window[s->strstart+1]);
  78238. #if MIN_MATCH != 3
  78239. Call UPDATE_HASH() MIN_MATCH-3 more times
  78240. #endif
  78241. }
  78242. } while (s->lookahead < MIN_LOOKAHEAD && s->strm->avail_in != 0);
  78243. }
  78244. #define FLUSH_BLOCK_ONLY(s, eof) { \
  78245. _tr_flush_block(s, (s->block_start >= 0L ? \
  78246. (charf *)&s->window[(unsigned)s->block_start] : \
  78247. (charf *)Z_NULL), \
  78248. (ulg)((long)s->strstart - s->block_start), \
  78249. (eof)); \
  78250. s->block_start = s->strstart; \
  78251. flush_pending(s->strm); \
  78252. Tracev((stderr,"[FLUSH]")); \
  78253. }
  78254. #define FLUSH_BLOCK(s, eof) { \
  78255. FLUSH_BLOCK_ONLY(s, eof); \
  78256. if (s->strm->avail_out == 0) return (eof) ? finish_started : need_more; \
  78257. }
  78258. local block_state deflate_stored(deflate_state *s, int flush)
  78259. {
  78260. ulg max_block_size = 0xffff;
  78261. ulg max_start;
  78262. if (max_block_size > s->pending_buf_size - 5) {
  78263. max_block_size = s->pending_buf_size - 5;
  78264. }
  78265. for (;;) {
  78266. if (s->lookahead <= 1) {
  78267. Assert(s->strstart < s->w_size+MAX_DIST(s) ||
  78268. s->block_start >= (long)s->w_size, "slide too late");
  78269. fill_window(s);
  78270. if (s->lookahead == 0 && flush == Z_NO_FLUSH) return need_more;
  78271. if (s->lookahead == 0) break; /* flush the current block */
  78272. }
  78273. Assert(s->block_start >= 0L, "block gone");
  78274. s->strstart += s->lookahead;
  78275. s->lookahead = 0;
  78276. max_start = s->block_start + max_block_size;
  78277. if (s->strstart == 0 || (ulg)s->strstart >= max_start) {
  78278. s->lookahead = (uInt)(s->strstart - max_start);
  78279. s->strstart = (uInt)max_start;
  78280. FLUSH_BLOCK(s, 0);
  78281. }
  78282. if (s->strstart - (uInt)s->block_start >= MAX_DIST(s)) {
  78283. FLUSH_BLOCK(s, 0);
  78284. }
  78285. }
  78286. FLUSH_BLOCK(s, flush == Z_FINISH);
  78287. return flush == Z_FINISH ? finish_done : block_done;
  78288. }
  78289. local block_state deflate_fast(deflate_state *s, int flush)
  78290. {
  78291. IPos hash_head = NIL; /* head of the hash chain */
  78292. int bflush; /* set if current block must be flushed */
  78293. for (;;) {
  78294. if (s->lookahead < MIN_LOOKAHEAD) {
  78295. fill_window(s);
  78296. if (s->lookahead < MIN_LOOKAHEAD && flush == Z_NO_FLUSH) {
  78297. return need_more;
  78298. }
  78299. if (s->lookahead == 0) break; /* flush the current block */
  78300. }
  78301. if (s->lookahead >= MIN_MATCH) {
  78302. INSERT_STRING(s, s->strstart, hash_head);
  78303. }
  78304. if (hash_head != NIL && s->strstart - hash_head <= MAX_DIST(s)) {
  78305. #ifdef FASTEST
  78306. if ((s->strategy != Z_HUFFMAN_ONLY && s->strategy != Z_RLE) ||
  78307. (s->strategy == Z_RLE && s->strstart - hash_head == 1)) {
  78308. s->match_length = longest_match_fast (s, hash_head);
  78309. }
  78310. #else
  78311. if (s->strategy != Z_HUFFMAN_ONLY && s->strategy != Z_RLE) {
  78312. s->match_length = longest_match (s, hash_head);
  78313. } else if (s->strategy == Z_RLE && s->strstart - hash_head == 1) {
  78314. s->match_length = longest_match_fast (s, hash_head);
  78315. }
  78316. #endif
  78317. }
  78318. if (s->match_length >= MIN_MATCH) {
  78319. check_match(s, s->strstart, s->match_start, s->match_length);
  78320. _tr_tally_dist(s, s->strstart - s->match_start,
  78321. s->match_length - MIN_MATCH, bflush);
  78322. s->lookahead -= s->match_length;
  78323. #ifndef FASTEST
  78324. if (s->match_length <= s->max_insert_length &&
  78325. s->lookahead >= MIN_MATCH) {
  78326. s->match_length--; /* string at strstart already in table */
  78327. do {
  78328. s->strstart++;
  78329. INSERT_STRING(s, s->strstart, hash_head);
  78330. } while (--s->match_length != 0);
  78331. s->strstart++;
  78332. } else
  78333. #endif
  78334. {
  78335. s->strstart += s->match_length;
  78336. s->match_length = 0;
  78337. s->ins_h = s->window[s->strstart];
  78338. UPDATE_HASH(s, s->ins_h, s->window[s->strstart+1]);
  78339. #if MIN_MATCH != 3
  78340. Call UPDATE_HASH() MIN_MATCH-3 more times
  78341. #endif
  78342. }
  78343. } else {
  78344. Tracevv((stderr,"%c", s->window[s->strstart]));
  78345. _tr_tally_lit (s, s->window[s->strstart], bflush);
  78346. s->lookahead--;
  78347. s->strstart++;
  78348. }
  78349. if (bflush) FLUSH_BLOCK(s, 0);
  78350. }
  78351. FLUSH_BLOCK(s, flush == Z_FINISH);
  78352. return flush == Z_FINISH ? finish_done : block_done;
  78353. }
  78354. #ifndef FASTEST
  78355. local block_state deflate_slow(deflate_state *s, int flush)
  78356. {
  78357. IPos hash_head = NIL; /* head of hash chain */
  78358. int bflush; /* set if current block must be flushed */
  78359. for (;;) {
  78360. if (s->lookahead < MIN_LOOKAHEAD) {
  78361. fill_window(s);
  78362. if (s->lookahead < MIN_LOOKAHEAD && flush == Z_NO_FLUSH) {
  78363. return need_more;
  78364. }
  78365. if (s->lookahead == 0) break; /* flush the current block */
  78366. }
  78367. if (s->lookahead >= MIN_MATCH) {
  78368. INSERT_STRING(s, s->strstart, hash_head);
  78369. }
  78370. s->prev_length = s->match_length, s->prev_match = s->match_start;
  78371. s->match_length = MIN_MATCH-1;
  78372. if (hash_head != NIL && s->prev_length < s->max_lazy_match &&
  78373. s->strstart - hash_head <= MAX_DIST(s)) {
  78374. if (s->strategy != Z_HUFFMAN_ONLY && s->strategy != Z_RLE) {
  78375. s->match_length = longest_match (s, hash_head);
  78376. } else if (s->strategy == Z_RLE && s->strstart - hash_head == 1) {
  78377. s->match_length = longest_match_fast (s, hash_head);
  78378. }
  78379. if (s->match_length <= 5 && (s->strategy == Z_FILTERED
  78380. #if TOO_FAR <= 32767
  78381. || (s->match_length == MIN_MATCH &&
  78382. s->strstart - s->match_start > TOO_FAR)
  78383. #endif
  78384. )) {
  78385. s->match_length = MIN_MATCH-1;
  78386. }
  78387. }
  78388. if (s->prev_length >= MIN_MATCH && s->match_length <= s->prev_length) {
  78389. uInt max_insert = s->strstart + s->lookahead - MIN_MATCH;
  78390. check_match(s, s->strstart-1, s->prev_match, s->prev_length);
  78391. _tr_tally_dist(s, s->strstart -1 - s->prev_match,
  78392. s->prev_length - MIN_MATCH, bflush);
  78393. s->lookahead -= s->prev_length-1;
  78394. s->prev_length -= 2;
  78395. do {
  78396. if (++s->strstart <= max_insert) {
  78397. INSERT_STRING(s, s->strstart, hash_head);
  78398. }
  78399. } while (--s->prev_length != 0);
  78400. s->match_available = 0;
  78401. s->match_length = MIN_MATCH-1;
  78402. s->strstart++;
  78403. if (bflush) FLUSH_BLOCK(s, 0);
  78404. } else if (s->match_available) {
  78405. Tracevv((stderr,"%c", s->window[s->strstart-1]));
  78406. _tr_tally_lit(s, s->window[s->strstart-1], bflush);
  78407. if (bflush) {
  78408. FLUSH_BLOCK_ONLY(s, 0);
  78409. }
  78410. s->strstart++;
  78411. s->lookahead--;
  78412. if (s->strm->avail_out == 0) return need_more;
  78413. } else {
  78414. s->match_available = 1;
  78415. s->strstart++;
  78416. s->lookahead--;
  78417. }
  78418. }
  78419. Assert (flush != Z_NO_FLUSH, "no flush?");
  78420. if (s->match_available) {
  78421. Tracevv((stderr,"%c", s->window[s->strstart-1]));
  78422. _tr_tally_lit(s, s->window[s->strstart-1], bflush);
  78423. s->match_available = 0;
  78424. }
  78425. FLUSH_BLOCK(s, flush == Z_FINISH);
  78426. return flush == Z_FINISH ? finish_done : block_done;
  78427. }
  78428. #endif /* FASTEST */
  78429. #if 0
  78430. local block_state deflate_rle(s, flush)
  78431. deflate_state *s;
  78432. int flush;
  78433. {
  78434. int bflush; /* set if current block must be flushed */
  78435. uInt run; /* length of run */
  78436. uInt max; /* maximum length of run */
  78437. uInt prev; /* byte at distance one to match */
  78438. Bytef *scan; /* scan for end of run */
  78439. for (;;) {
  78440. if (s->lookahead < MAX_MATCH) {
  78441. fill_window(s);
  78442. if (s->lookahead < MAX_MATCH && flush == Z_NO_FLUSH) {
  78443. return need_more;
  78444. }
  78445. if (s->lookahead == 0) break; /* flush the current block */
  78446. }
  78447. run = 0;
  78448. if (s->strstart > 0) { /* if there is a previous byte, that is */
  78449. max = s->lookahead < MAX_MATCH ? s->lookahead : MAX_MATCH;
  78450. scan = s->window + s->strstart - 1;
  78451. prev = *scan++;
  78452. do {
  78453. if (*scan++ != prev)
  78454. break;
  78455. } while (++run < max);
  78456. }
  78457. if (run >= MIN_MATCH) {
  78458. check_match(s, s->strstart, s->strstart - 1, run);
  78459. _tr_tally_dist(s, 1, run - MIN_MATCH, bflush);
  78460. s->lookahead -= run;
  78461. s->strstart += run;
  78462. } else {
  78463. Tracevv((stderr,"%c", s->window[s->strstart]));
  78464. _tr_tally_lit (s, s->window[s->strstart], bflush);
  78465. s->lookahead--;
  78466. s->strstart++;
  78467. }
  78468. if (bflush) FLUSH_BLOCK(s, 0);
  78469. }
  78470. FLUSH_BLOCK(s, flush == Z_FINISH);
  78471. return flush == Z_FINISH ? finish_done : block_done;
  78472. }
  78473. #endif
  78474. /********* End of inlined file: deflate.c *********/
  78475. /********* Start of inlined file: inffast.c *********/
  78476. /********* Start of inlined file: inftrees.h *********/
  78477. #ifndef _INFTREES_H_
  78478. #define _INFTREES_H_
  78479. typedef struct {
  78480. unsigned char op; /* operation, extra bits, table bits */
  78481. unsigned char bits; /* bits in this part of the code */
  78482. unsigned short val; /* offset in table or code value */
  78483. } code;
  78484. #define ENOUGH 2048
  78485. #define MAXD 592
  78486. typedef enum {
  78487. CODES,
  78488. LENS,
  78489. DISTS
  78490. } codetype;
  78491. extern int inflate_table OF((codetype type, unsigned short FAR *lens,
  78492. unsigned codes, code FAR * FAR *table,
  78493. unsigned FAR *bits, unsigned short FAR *work));
  78494. #endif
  78495. /********* End of inlined file: inftrees.h *********/
  78496. /********* Start of inlined file: inflate.h *********/
  78497. #ifndef _INFLATE_H_
  78498. #define _INFLATE_H_
  78499. #ifndef NO_GZIP
  78500. # define GUNZIP
  78501. #endif
  78502. typedef enum {
  78503. HEAD, /* i: waiting for magic header */
  78504. FLAGS, /* i: waiting for method and flags (gzip) */
  78505. TIME, /* i: waiting for modification time (gzip) */
  78506. OS, /* i: waiting for extra flags and operating system (gzip) */
  78507. EXLEN, /* i: waiting for extra length (gzip) */
  78508. EXTRA, /* i: waiting for extra bytes (gzip) */
  78509. NAME, /* i: waiting for end of file name (gzip) */
  78510. COMMENT, /* i: waiting for end of comment (gzip) */
  78511. HCRC, /* i: waiting for header crc (gzip) */
  78512. DICTID, /* i: waiting for dictionary check value */
  78513. DICT, /* waiting for inflateSetDictionary() call */
  78514. TYPE, /* i: waiting for type bits, including last-flag bit */
  78515. TYPEDO, /* i: same, but skip check to exit inflate on new block */
  78516. STORED, /* i: waiting for stored size (length and complement) */
  78517. COPY, /* i/o: waiting for input or output to copy stored block */
  78518. TABLE, /* i: waiting for dynamic block table lengths */
  78519. LENLENS, /* i: waiting for code length code lengths */
  78520. CODELENS, /* i: waiting for length/lit and distance code lengths */
  78521. LEN, /* i: waiting for length/lit code */
  78522. LENEXT, /* i: waiting for length extra bits */
  78523. DIST, /* i: waiting for distance code */
  78524. DISTEXT, /* i: waiting for distance extra bits */
  78525. MATCH, /* o: waiting for output space to copy string */
  78526. LIT, /* o: waiting for output space to write literal */
  78527. CHECK, /* i: waiting for 32-bit check value */
  78528. LENGTH, /* i: waiting for 32-bit length (gzip) */
  78529. DONE, /* finished check, done -- remain here until reset */
  78530. BAD, /* got a data error -- remain here until reset */
  78531. MEM, /* got an inflate() memory error -- remain here until reset */
  78532. SYNC /* looking for synchronization bytes to restart inflate() */
  78533. } inflate_mode;
  78534. struct inflate_state {
  78535. inflate_mode mode; /* current inflate mode */
  78536. int last; /* true if processing last block */
  78537. int wrap; /* bit 0 true for zlib, bit 1 true for gzip */
  78538. int havedict; /* true if dictionary provided */
  78539. int flags; /* gzip header method and flags (0 if zlib) */
  78540. unsigned dmax; /* zlib header max distance (INFLATE_STRICT) */
  78541. unsigned long check; /* protected copy of check value */
  78542. unsigned long total; /* protected copy of output count */
  78543. gz_headerp head; /* where to save gzip header information */
  78544. unsigned wbits; /* log base 2 of requested window size */
  78545. unsigned wsize; /* window size or zero if not using window */
  78546. unsigned whave; /* valid bytes in the window */
  78547. unsigned write; /* window write index */
  78548. unsigned char FAR *window; /* allocated sliding window, if needed */
  78549. unsigned long hold; /* input bit accumulator */
  78550. unsigned bits; /* number of bits in "in" */
  78551. unsigned length; /* literal or length of data to copy */
  78552. unsigned offset; /* distance back to copy string from */
  78553. unsigned extra; /* extra bits needed */
  78554. code const FAR *lencode; /* starting table for length/literal codes */
  78555. code const FAR *distcode; /* starting table for distance codes */
  78556. unsigned lenbits; /* index bits for lencode */
  78557. unsigned distbits; /* index bits for distcode */
  78558. unsigned ncode; /* number of code length code lengths */
  78559. unsigned nlen; /* number of length code lengths */
  78560. unsigned ndist; /* number of distance code lengths */
  78561. unsigned have; /* number of code lengths in lens[] */
  78562. code FAR *next; /* next available space in codes[] */
  78563. unsigned short lens[320]; /* temporary storage for code lengths */
  78564. unsigned short work[288]; /* work area for code table building */
  78565. code codes[ENOUGH]; /* space for code tables */
  78566. };
  78567. #endif
  78568. /********* End of inlined file: inflate.h *********/
  78569. /********* Start of inlined file: inffast.h *********/
  78570. void inflate_fast OF((z_streamp strm, unsigned start));
  78571. /********* End of inlined file: inffast.h *********/
  78572. #ifndef ASMINF
  78573. #ifdef POSTINC
  78574. # define OFF 0
  78575. # define PUP(a) *(a)++
  78576. #else
  78577. # define OFF 1
  78578. # define PUP(a) *++(a)
  78579. #endif
  78580. void inflate_fast (z_streamp strm, unsigned start)
  78581. {
  78582. struct inflate_state FAR *state;
  78583. unsigned char FAR *in; /* local strm->next_in */
  78584. unsigned char FAR *last; /* while in < last, enough input available */
  78585. unsigned char FAR *out; /* local strm->next_out */
  78586. unsigned char FAR *beg; /* inflate()'s initial strm->next_out */
  78587. unsigned char FAR *end; /* while out < end, enough space available */
  78588. #ifdef INFLATE_STRICT
  78589. unsigned dmax; /* maximum distance from zlib header */
  78590. #endif
  78591. unsigned wsize; /* window size or zero if not using window */
  78592. unsigned whave; /* valid bytes in the window */
  78593. unsigned write; /* window write index */
  78594. unsigned char FAR *window; /* allocated sliding window, if wsize != 0 */
  78595. unsigned long hold; /* local strm->hold */
  78596. unsigned bits; /* local strm->bits */
  78597. code const FAR *lcode; /* local strm->lencode */
  78598. code const FAR *dcode; /* local strm->distcode */
  78599. unsigned lmask; /* mask for first level of length codes */
  78600. unsigned dmask; /* mask for first level of distance codes */
  78601. code thisx; /* retrieved table entry */
  78602. unsigned op; /* code bits, operation, extra bits, or */
  78603. unsigned len; /* match length, unused bytes */
  78604. unsigned dist; /* match distance */
  78605. unsigned char FAR *from; /* where to copy match from */
  78606. state = (struct inflate_state FAR *)strm->state;
  78607. in = strm->next_in - OFF;
  78608. last = in + (strm->avail_in - 5);
  78609. out = strm->next_out - OFF;
  78610. beg = out - (start - strm->avail_out);
  78611. end = out + (strm->avail_out - 257);
  78612. #ifdef INFLATE_STRICT
  78613. dmax = state->dmax;
  78614. #endif
  78615. wsize = state->wsize;
  78616. whave = state->whave;
  78617. write = state->write;
  78618. window = state->window;
  78619. hold = state->hold;
  78620. bits = state->bits;
  78621. lcode = state->lencode;
  78622. dcode = state->distcode;
  78623. lmask = (1U << state->lenbits) - 1;
  78624. dmask = (1U << state->distbits) - 1;
  78625. do {
  78626. if (bits < 15) {
  78627. hold += (unsigned long)(PUP(in)) << bits;
  78628. bits += 8;
  78629. hold += (unsigned long)(PUP(in)) << bits;
  78630. bits += 8;
  78631. }
  78632. thisx = lcode[hold & lmask];
  78633. dolen:
  78634. op = (unsigned)(thisx.bits);
  78635. hold >>= op;
  78636. bits -= op;
  78637. op = (unsigned)(thisx.op);
  78638. if (op == 0) { /* literal */
  78639. Tracevv((stderr, thisx.val >= 0x20 && thisx.val < 0x7f ?
  78640. "inflate: literal '%c'\n" :
  78641. "inflate: literal 0x%02x\n", thisx.val));
  78642. PUP(out) = (unsigned char)(thisx.val);
  78643. }
  78644. else if (op & 16) { /* length base */
  78645. len = (unsigned)(thisx.val);
  78646. op &= 15; /* number of extra bits */
  78647. if (op) {
  78648. if (bits < op) {
  78649. hold += (unsigned long)(PUP(in)) << bits;
  78650. bits += 8;
  78651. }
  78652. len += (unsigned)hold & ((1U << op) - 1);
  78653. hold >>= op;
  78654. bits -= op;
  78655. }
  78656. Tracevv((stderr, "inflate: length %u\n", len));
  78657. if (bits < 15) {
  78658. hold += (unsigned long)(PUP(in)) << bits;
  78659. bits += 8;
  78660. hold += (unsigned long)(PUP(in)) << bits;
  78661. bits += 8;
  78662. }
  78663. thisx = dcode[hold & dmask];
  78664. dodist:
  78665. op = (unsigned)(thisx.bits);
  78666. hold >>= op;
  78667. bits -= op;
  78668. op = (unsigned)(thisx.op);
  78669. if (op & 16) { /* distance base */
  78670. dist = (unsigned)(thisx.val);
  78671. op &= 15; /* number of extra bits */
  78672. if (bits < op) {
  78673. hold += (unsigned long)(PUP(in)) << bits;
  78674. bits += 8;
  78675. if (bits < op) {
  78676. hold += (unsigned long)(PUP(in)) << bits;
  78677. bits += 8;
  78678. }
  78679. }
  78680. dist += (unsigned)hold & ((1U << op) - 1);
  78681. #ifdef INFLATE_STRICT
  78682. if (dist > dmax) {
  78683. strm->msg = (char *)"invalid distance too far back";
  78684. state->mode = BAD;
  78685. break;
  78686. }
  78687. #endif
  78688. hold >>= op;
  78689. bits -= op;
  78690. Tracevv((stderr, "inflate: distance %u\n", dist));
  78691. op = (unsigned)(out - beg); /* max distance in output */
  78692. if (dist > op) { /* see if copy from window */
  78693. op = dist - op; /* distance back in window */
  78694. if (op > whave) {
  78695. strm->msg = (char *)"invalid distance too far back";
  78696. state->mode = BAD;
  78697. break;
  78698. }
  78699. from = window - OFF;
  78700. if (write == 0) { /* very common case */
  78701. from += wsize - op;
  78702. if (op < len) { /* some from window */
  78703. len -= op;
  78704. do {
  78705. PUP(out) = PUP(from);
  78706. } while (--op);
  78707. from = out - dist; /* rest from output */
  78708. }
  78709. }
  78710. else if (write < op) { /* wrap around window */
  78711. from += wsize + write - op;
  78712. op -= write;
  78713. if (op < len) { /* some from end of window */
  78714. len -= op;
  78715. do {
  78716. PUP(out) = PUP(from);
  78717. } while (--op);
  78718. from = window - OFF;
  78719. if (write < len) { /* some from start of window */
  78720. op = write;
  78721. len -= op;
  78722. do {
  78723. PUP(out) = PUP(from);
  78724. } while (--op);
  78725. from = out - dist; /* rest from output */
  78726. }
  78727. }
  78728. }
  78729. else { /* contiguous in window */
  78730. from += write - op;
  78731. if (op < len) { /* some from window */
  78732. len -= op;
  78733. do {
  78734. PUP(out) = PUP(from);
  78735. } while (--op);
  78736. from = out - dist; /* rest from output */
  78737. }
  78738. }
  78739. while (len > 2) {
  78740. PUP(out) = PUP(from);
  78741. PUP(out) = PUP(from);
  78742. PUP(out) = PUP(from);
  78743. len -= 3;
  78744. }
  78745. if (len) {
  78746. PUP(out) = PUP(from);
  78747. if (len > 1)
  78748. PUP(out) = PUP(from);
  78749. }
  78750. }
  78751. else {
  78752. from = out - dist; /* copy direct from output */
  78753. do { /* minimum length is three */
  78754. PUP(out) = PUP(from);
  78755. PUP(out) = PUP(from);
  78756. PUP(out) = PUP(from);
  78757. len -= 3;
  78758. } while (len > 2);
  78759. if (len) {
  78760. PUP(out) = PUP(from);
  78761. if (len > 1)
  78762. PUP(out) = PUP(from);
  78763. }
  78764. }
  78765. }
  78766. else if ((op & 64) == 0) { /* 2nd level distance code */
  78767. thisx = dcode[thisx.val + (hold & ((1U << op) - 1))];
  78768. goto dodist;
  78769. }
  78770. else {
  78771. strm->msg = (char *)"invalid distance code";
  78772. state->mode = BAD;
  78773. break;
  78774. }
  78775. }
  78776. else if ((op & 64) == 0) { /* 2nd level length code */
  78777. thisx = lcode[thisx.val + (hold & ((1U << op) - 1))];
  78778. goto dolen;
  78779. }
  78780. else if (op & 32) { /* end-of-block */
  78781. Tracevv((stderr, "inflate: end of block\n"));
  78782. state->mode = TYPE;
  78783. break;
  78784. }
  78785. else {
  78786. strm->msg = (char *)"invalid literal/length code";
  78787. state->mode = BAD;
  78788. break;
  78789. }
  78790. } while (in < last && out < end);
  78791. len = bits >> 3;
  78792. in -= len;
  78793. bits -= len << 3;
  78794. hold &= (1U << bits) - 1;
  78795. strm->next_in = in + OFF;
  78796. strm->next_out = out + OFF;
  78797. strm->avail_in = (unsigned)(in < last ? 5 + (last - in) : 5 - (in - last));
  78798. strm->avail_out = (unsigned)(out < end ?
  78799. 257 + (end - out) : 257 - (out - end));
  78800. state->hold = hold;
  78801. state->bits = bits;
  78802. return;
  78803. }
  78804. #endif /* !ASMINF */
  78805. /********* End of inlined file: inffast.c *********/
  78806. #undef PULLBYTE
  78807. #undef LOAD
  78808. #undef RESTORE
  78809. #undef INITBITS
  78810. #undef NEEDBITS
  78811. #undef DROPBITS
  78812. #undef BYTEBITS
  78813. /********* Start of inlined file: inflate.c *********/
  78814. /********* Start of inlined file: inffast.h *********/
  78815. void inflate_fast OF((z_streamp strm, unsigned start));
  78816. /********* End of inlined file: inffast.h *********/
  78817. #ifdef MAKEFIXED
  78818. # ifndef BUILDFIXED
  78819. # define BUILDFIXED
  78820. # endif
  78821. #endif
  78822. local void fixedtables OF((struct inflate_state FAR *state));
  78823. local int updatewindow OF((z_streamp strm, unsigned out));
  78824. #ifdef BUILDFIXED
  78825. void makefixed OF((void));
  78826. #endif
  78827. local unsigned syncsearch OF((unsigned FAR *have, unsigned char FAR *buf,
  78828. unsigned len));
  78829. int ZEXPORT inflateReset (z_streamp strm)
  78830. {
  78831. struct inflate_state FAR *state;
  78832. if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
  78833. state = (struct inflate_state FAR *)strm->state;
  78834. strm->total_in = strm->total_out = state->total = 0;
  78835. strm->msg = Z_NULL;
  78836. strm->adler = 1; /* to support ill-conceived Java test suite */
  78837. state->mode = HEAD;
  78838. state->last = 0;
  78839. state->havedict = 0;
  78840. state->dmax = 32768U;
  78841. state->head = Z_NULL;
  78842. state->wsize = 0;
  78843. state->whave = 0;
  78844. state->write = 0;
  78845. state->hold = 0;
  78846. state->bits = 0;
  78847. state->lencode = state->distcode = state->next = state->codes;
  78848. Tracev((stderr, "inflate: reset\n"));
  78849. return Z_OK;
  78850. }
  78851. int ZEXPORT inflatePrime (z_streamp strm, int bits, int value)
  78852. {
  78853. struct inflate_state FAR *state;
  78854. if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
  78855. state = (struct inflate_state FAR *)strm->state;
  78856. if (bits > 16 || state->bits + bits > 32) return Z_STREAM_ERROR;
  78857. value &= (1L << bits) - 1;
  78858. state->hold += value << state->bits;
  78859. state->bits += bits;
  78860. return Z_OK;
  78861. }
  78862. int ZEXPORT inflateInit2_(z_streamp strm, int windowBits, const char *version, int stream_size)
  78863. {
  78864. struct inflate_state FAR *state;
  78865. if (version == Z_NULL || version[0] != ZLIB_VERSION[0] ||
  78866. stream_size != (int)(sizeof(z_stream)))
  78867. return Z_VERSION_ERROR;
  78868. if (strm == Z_NULL) return Z_STREAM_ERROR;
  78869. strm->msg = Z_NULL; /* in case we return an error */
  78870. if (strm->zalloc == (alloc_func)0) {
  78871. strm->zalloc = zcalloc;
  78872. strm->opaque = (voidpf)0;
  78873. }
  78874. if (strm->zfree == (free_func)0) strm->zfree = zcfree;
  78875. state = (struct inflate_state FAR *)
  78876. ZALLOC(strm, 1, sizeof(struct inflate_state));
  78877. if (state == Z_NULL) return Z_MEM_ERROR;
  78878. Tracev((stderr, "inflate: allocated\n"));
  78879. strm->state = (struct internal_state FAR *)state;
  78880. if (windowBits < 0) {
  78881. state->wrap = 0;
  78882. windowBits = -windowBits;
  78883. }
  78884. else {
  78885. state->wrap = (windowBits >> 4) + 1;
  78886. #ifdef GUNZIP
  78887. if (windowBits < 48) windowBits &= 15;
  78888. #endif
  78889. }
  78890. if (windowBits < 8 || windowBits > 15) {
  78891. ZFREE(strm, state);
  78892. strm->state = Z_NULL;
  78893. return Z_STREAM_ERROR;
  78894. }
  78895. state->wbits = (unsigned)windowBits;
  78896. state->window = Z_NULL;
  78897. return inflateReset(strm);
  78898. }
  78899. int ZEXPORT inflateInit_ (z_streamp strm, const char *version, int stream_size)
  78900. {
  78901. return inflateInit2_(strm, DEF_WBITS, version, stream_size);
  78902. }
  78903. local void fixedtables (struct inflate_state FAR *state)
  78904. {
  78905. #ifdef BUILDFIXED
  78906. static int virgin = 1;
  78907. static code *lenfix, *distfix;
  78908. static code fixed[544];
  78909. if (virgin) {
  78910. unsigned sym, bits;
  78911. static code *next;
  78912. sym = 0;
  78913. while (sym < 144) state->lens[sym++] = 8;
  78914. while (sym < 256) state->lens[sym++] = 9;
  78915. while (sym < 280) state->lens[sym++] = 7;
  78916. while (sym < 288) state->lens[sym++] = 8;
  78917. next = fixed;
  78918. lenfix = next;
  78919. bits = 9;
  78920. inflate_table(LENS, state->lens, 288, &(next), &(bits), state->work);
  78921. sym = 0;
  78922. while (sym < 32) state->lens[sym++] = 5;
  78923. distfix = next;
  78924. bits = 5;
  78925. inflate_table(DISTS, state->lens, 32, &(next), &(bits), state->work);
  78926. virgin = 0;
  78927. }
  78928. #else /* !BUILDFIXED */
  78929. /********* Start of inlined file: inffixed.h *********/
  78930. static const code lenfix[512] = {
  78931. {96,7,0},{0,8,80},{0,8,16},{20,8,115},{18,7,31},{0,8,112},{0,8,48},
  78932. {0,9,192},{16,7,10},{0,8,96},{0,8,32},{0,9,160},{0,8,0},{0,8,128},
  78933. {0,8,64},{0,9,224},{16,7,6},{0,8,88},{0,8,24},{0,9,144},{19,7,59},
  78934. {0,8,120},{0,8,56},{0,9,208},{17,7,17},{0,8,104},{0,8,40},{0,9,176},
  78935. {0,8,8},{0,8,136},{0,8,72},{0,9,240},{16,7,4},{0,8,84},{0,8,20},
  78936. {21,8,227},{19,7,43},{0,8,116},{0,8,52},{0,9,200},{17,7,13},{0,8,100},
  78937. {0,8,36},{0,9,168},{0,8,4},{0,8,132},{0,8,68},{0,9,232},{16,7,8},
  78938. {0,8,92},{0,8,28},{0,9,152},{20,7,83},{0,8,124},{0,8,60},{0,9,216},
  78939. {18,7,23},{0,8,108},{0,8,44},{0,9,184},{0,8,12},{0,8,140},{0,8,76},
  78940. {0,9,248},{16,7,3},{0,8,82},{0,8,18},{21,8,163},{19,7,35},{0,8,114},
  78941. {0,8,50},{0,9,196},{17,7,11},{0,8,98},{0,8,34},{0,9,164},{0,8,2},
  78942. {0,8,130},{0,8,66},{0,9,228},{16,7,7},{0,8,90},{0,8,26},{0,9,148},
  78943. {20,7,67},{0,8,122},{0,8,58},{0,9,212},{18,7,19},{0,8,106},{0,8,42},
  78944. {0,9,180},{0,8,10},{0,8,138},{0,8,74},{0,9,244},{16,7,5},{0,8,86},
  78945. {0,8,22},{64,8,0},{19,7,51},{0,8,118},{0,8,54},{0,9,204},{17,7,15},
  78946. {0,8,102},{0,8,38},{0,9,172},{0,8,6},{0,8,134},{0,8,70},{0,9,236},
  78947. {16,7,9},{0,8,94},{0,8,30},{0,9,156},{20,7,99},{0,8,126},{0,8,62},
  78948. {0,9,220},{18,7,27},{0,8,110},{0,8,46},{0,9,188},{0,8,14},{0,8,142},
  78949. {0,8,78},{0,9,252},{96,7,0},{0,8,81},{0,8,17},{21,8,131},{18,7,31},
  78950. {0,8,113},{0,8,49},{0,9,194},{16,7,10},{0,8,97},{0,8,33},{0,9,162},
  78951. {0,8,1},{0,8,129},{0,8,65},{0,9,226},{16,7,6},{0,8,89},{0,8,25},
  78952. {0,9,146},{19,7,59},{0,8,121},{0,8,57},{0,9,210},{17,7,17},{0,8,105},
  78953. {0,8,41},{0,9,178},{0,8,9},{0,8,137},{0,8,73},{0,9,242},{16,7,4},
  78954. {0,8,85},{0,8,21},{16,8,258},{19,7,43},{0,8,117},{0,8,53},{0,9,202},
  78955. {17,7,13},{0,8,101},{0,8,37},{0,9,170},{0,8,5},{0,8,133},{0,8,69},
  78956. {0,9,234},{16,7,8},{0,8,93},{0,8,29},{0,9,154},{20,7,83},{0,8,125},
  78957. {0,8,61},{0,9,218},{18,7,23},{0,8,109},{0,8,45},{0,9,186},{0,8,13},
  78958. {0,8,141},{0,8,77},{0,9,250},{16,7,3},{0,8,83},{0,8,19},{21,8,195},
  78959. {19,7,35},{0,8,115},{0,8,51},{0,9,198},{17,7,11},{0,8,99},{0,8,35},
  78960. {0,9,166},{0,8,3},{0,8,131},{0,8,67},{0,9,230},{16,7,7},{0,8,91},
  78961. {0,8,27},{0,9,150},{20,7,67},{0,8,123},{0,8,59},{0,9,214},{18,7,19},
  78962. {0,8,107},{0,8,43},{0,9,182},{0,8,11},{0,8,139},{0,8,75},{0,9,246},
  78963. {16,7,5},{0,8,87},{0,8,23},{64,8,0},{19,7,51},{0,8,119},{0,8,55},
  78964. {0,9,206},{17,7,15},{0,8,103},{0,8,39},{0,9,174},{0,8,7},{0,8,135},
  78965. {0,8,71},{0,9,238},{16,7,9},{0,8,95},{0,8,31},{0,9,158},{20,7,99},
  78966. {0,8,127},{0,8,63},{0,9,222},{18,7,27},{0,8,111},{0,8,47},{0,9,190},
  78967. {0,8,15},{0,8,143},{0,8,79},{0,9,254},{96,7,0},{0,8,80},{0,8,16},
  78968. {20,8,115},{18,7,31},{0,8,112},{0,8,48},{0,9,193},{16,7,10},{0,8,96},
  78969. {0,8,32},{0,9,161},{0,8,0},{0,8,128},{0,8,64},{0,9,225},{16,7,6},
  78970. {0,8,88},{0,8,24},{0,9,145},{19,7,59},{0,8,120},{0,8,56},{0,9,209},
  78971. {17,7,17},{0,8,104},{0,8,40},{0,9,177},{0,8,8},{0,8,136},{0,8,72},
  78972. {0,9,241},{16,7,4},{0,8,84},{0,8,20},{21,8,227},{19,7,43},{0,8,116},
  78973. {0,8,52},{0,9,201},{17,7,13},{0,8,100},{0,8,36},{0,9,169},{0,8,4},
  78974. {0,8,132},{0,8,68},{0,9,233},{16,7,8},{0,8,92},{0,8,28},{0,9,153},
  78975. {20,7,83},{0,8,124},{0,8,60},{0,9,217},{18,7,23},{0,8,108},{0,8,44},
  78976. {0,9,185},{0,8,12},{0,8,140},{0,8,76},{0,9,249},{16,7,3},{0,8,82},
  78977. {0,8,18},{21,8,163},{19,7,35},{0,8,114},{0,8,50},{0,9,197},{17,7,11},
  78978. {0,8,98},{0,8,34},{0,9,165},{0,8,2},{0,8,130},{0,8,66},{0,9,229},
  78979. {16,7,7},{0,8,90},{0,8,26},{0,9,149},{20,7,67},{0,8,122},{0,8,58},
  78980. {0,9,213},{18,7,19},{0,8,106},{0,8,42},{0,9,181},{0,8,10},{0,8,138},
  78981. {0,8,74},{0,9,245},{16,7,5},{0,8,86},{0,8,22},{64,8,0},{19,7,51},
  78982. {0,8,118},{0,8,54},{0,9,205},{17,7,15},{0,8,102},{0,8,38},{0,9,173},
  78983. {0,8,6},{0,8,134},{0,8,70},{0,9,237},{16,7,9},{0,8,94},{0,8,30},
  78984. {0,9,157},{20,7,99},{0,8,126},{0,8,62},{0,9,221},{18,7,27},{0,8,110},
  78985. {0,8,46},{0,9,189},{0,8,14},{0,8,142},{0,8,78},{0,9,253},{96,7,0},
  78986. {0,8,81},{0,8,17},{21,8,131},{18,7,31},{0,8,113},{0,8,49},{0,9,195},
  78987. {16,7,10},{0,8,97},{0,8,33},{0,9,163},{0,8,1},{0,8,129},{0,8,65},
  78988. {0,9,227},{16,7,6},{0,8,89},{0,8,25},{0,9,147},{19,7,59},{0,8,121},
  78989. {0,8,57},{0,9,211},{17,7,17},{0,8,105},{0,8,41},{0,9,179},{0,8,9},
  78990. {0,8,137},{0,8,73},{0,9,243},{16,7,4},{0,8,85},{0,8,21},{16,8,258},
  78991. {19,7,43},{0,8,117},{0,8,53},{0,9,203},{17,7,13},{0,8,101},{0,8,37},
  78992. {0,9,171},{0,8,5},{0,8,133},{0,8,69},{0,9,235},{16,7,8},{0,8,93},
  78993. {0,8,29},{0,9,155},{20,7,83},{0,8,125},{0,8,61},{0,9,219},{18,7,23},
  78994. {0,8,109},{0,8,45},{0,9,187},{0,8,13},{0,8,141},{0,8,77},{0,9,251},
  78995. {16,7,3},{0,8,83},{0,8,19},{21,8,195},{19,7,35},{0,8,115},{0,8,51},
  78996. {0,9,199},{17,7,11},{0,8,99},{0,8,35},{0,9,167},{0,8,3},{0,8,131},
  78997. {0,8,67},{0,9,231},{16,7,7},{0,8,91},{0,8,27},{0,9,151},{20,7,67},
  78998. {0,8,123},{0,8,59},{0,9,215},{18,7,19},{0,8,107},{0,8,43},{0,9,183},
  78999. {0,8,11},{0,8,139},{0,8,75},{0,9,247},{16,7,5},{0,8,87},{0,8,23},
  79000. {64,8,0},{19,7,51},{0,8,119},{0,8,55},{0,9,207},{17,7,15},{0,8,103},
  79001. {0,8,39},{0,9,175},{0,8,7},{0,8,135},{0,8,71},{0,9,239},{16,7,9},
  79002. {0,8,95},{0,8,31},{0,9,159},{20,7,99},{0,8,127},{0,8,63},{0,9,223},
  79003. {18,7,27},{0,8,111},{0,8,47},{0,9,191},{0,8,15},{0,8,143},{0,8,79},
  79004. {0,9,255}
  79005. };
  79006. static const code distfix[32] = {
  79007. {16,5,1},{23,5,257},{19,5,17},{27,5,4097},{17,5,5},{25,5,1025},
  79008. {21,5,65},{29,5,16385},{16,5,3},{24,5,513},{20,5,33},{28,5,8193},
  79009. {18,5,9},{26,5,2049},{22,5,129},{64,5,0},{16,5,2},{23,5,385},
  79010. {19,5,25},{27,5,6145},{17,5,7},{25,5,1537},{21,5,97},{29,5,24577},
  79011. {16,5,4},{24,5,769},{20,5,49},{28,5,12289},{18,5,13},{26,5,3073},
  79012. {22,5,193},{64,5,0}
  79013. };
  79014. /********* End of inlined file: inffixed.h *********/
  79015. #endif /* BUILDFIXED */
  79016. state->lencode = lenfix;
  79017. state->lenbits = 9;
  79018. state->distcode = distfix;
  79019. state->distbits = 5;
  79020. }
  79021. #ifdef MAKEFIXED
  79022. #include <stdio.h>
  79023. void makefixed()
  79024. {
  79025. unsigned low, size;
  79026. struct inflate_state state;
  79027. fixedtables(&state);
  79028. puts(" /* inffixed.h -- table for decoding fixed codes");
  79029. puts(" * Generated automatically by makefixed().");
  79030. puts(" */");
  79031. puts("");
  79032. puts(" /* WARNING: this file should *not* be used by applications.");
  79033. puts(" It is part of the implementation of this library and is");
  79034. puts(" subject to change. Applications should only use zlib.h.");
  79035. puts(" */");
  79036. puts("");
  79037. size = 1U << 9;
  79038. printf(" static const code lenfix[%u] = {", size);
  79039. low = 0;
  79040. for (;;) {
  79041. if ((low % 7) == 0) printf("\n ");
  79042. printf("{%u,%u,%d}", state.lencode[low].op, state.lencode[low].bits,
  79043. state.lencode[low].val);
  79044. if (++low == size) break;
  79045. putchar(',');
  79046. }
  79047. puts("\n };");
  79048. size = 1U << 5;
  79049. printf("\n static const code distfix[%u] = {", size);
  79050. low = 0;
  79051. for (;;) {
  79052. if ((low % 6) == 0) printf("\n ");
  79053. printf("{%u,%u,%d}", state.distcode[low].op, state.distcode[low].bits,
  79054. state.distcode[low].val);
  79055. if (++low == size) break;
  79056. putchar(',');
  79057. }
  79058. puts("\n };");
  79059. }
  79060. #endif /* MAKEFIXED */
  79061. local int updatewindow (z_streamp strm, unsigned out)
  79062. {
  79063. struct inflate_state FAR *state;
  79064. unsigned copy, dist;
  79065. state = (struct inflate_state FAR *)strm->state;
  79066. if (state->window == Z_NULL) {
  79067. state->window = (unsigned char FAR *)
  79068. ZALLOC(strm, 1U << state->wbits,
  79069. sizeof(unsigned char));
  79070. if (state->window == Z_NULL) return 1;
  79071. }
  79072. if (state->wsize == 0) {
  79073. state->wsize = 1U << state->wbits;
  79074. state->write = 0;
  79075. state->whave = 0;
  79076. }
  79077. copy = out - strm->avail_out;
  79078. if (copy >= state->wsize) {
  79079. zmemcpy(state->window, strm->next_out - state->wsize, state->wsize);
  79080. state->write = 0;
  79081. state->whave = state->wsize;
  79082. }
  79083. else {
  79084. dist = state->wsize - state->write;
  79085. if (dist > copy) dist = copy;
  79086. zmemcpy(state->window + state->write, strm->next_out - copy, dist);
  79087. copy -= dist;
  79088. if (copy) {
  79089. zmemcpy(state->window, strm->next_out - copy, copy);
  79090. state->write = copy;
  79091. state->whave = state->wsize;
  79092. }
  79093. else {
  79094. state->write += dist;
  79095. if (state->write == state->wsize) state->write = 0;
  79096. if (state->whave < state->wsize) state->whave += dist;
  79097. }
  79098. }
  79099. return 0;
  79100. }
  79101. #ifdef GUNZIP
  79102. # define UPDATE(check, buf, len) \
  79103. (state->flags ? crc32(check, buf, len) : adler32(check, buf, len))
  79104. #else
  79105. # define UPDATE(check, buf, len) adler32(check, buf, len)
  79106. #endif
  79107. #ifdef GUNZIP
  79108. # define CRC2(check, word) \
  79109. do { \
  79110. hbuf[0] = (unsigned char)(word); \
  79111. hbuf[1] = (unsigned char)((word) >> 8); \
  79112. check = crc32(check, hbuf, 2); \
  79113. } while (0)
  79114. # define CRC4(check, word) \
  79115. do { \
  79116. hbuf[0] = (unsigned char)(word); \
  79117. hbuf[1] = (unsigned char)((word) >> 8); \
  79118. hbuf[2] = (unsigned char)((word) >> 16); \
  79119. hbuf[3] = (unsigned char)((word) >> 24); \
  79120. check = crc32(check, hbuf, 4); \
  79121. } while (0)
  79122. #endif
  79123. #define LOAD() \
  79124. do { \
  79125. put = strm->next_out; \
  79126. left = strm->avail_out; \
  79127. next = strm->next_in; \
  79128. have = strm->avail_in; \
  79129. hold = state->hold; \
  79130. bits = state->bits; \
  79131. } while (0)
  79132. #define RESTORE() \
  79133. do { \
  79134. strm->next_out = put; \
  79135. strm->avail_out = left; \
  79136. strm->next_in = next; \
  79137. strm->avail_in = have; \
  79138. state->hold = hold; \
  79139. state->bits = bits; \
  79140. } while (0)
  79141. #define INITBITS() \
  79142. do { \
  79143. hold = 0; \
  79144. bits = 0; \
  79145. } while (0)
  79146. #define PULLBYTE() \
  79147. do { \
  79148. if (have == 0) goto inf_leave; \
  79149. have--; \
  79150. hold += (unsigned long)(*next++) << bits; \
  79151. bits += 8; \
  79152. } while (0)
  79153. #define NEEDBITS(n) \
  79154. do { \
  79155. while (bits < (unsigned)(n)) \
  79156. PULLBYTE(); \
  79157. } while (0)
  79158. #define BITS(n) \
  79159. ((unsigned)hold & ((1U << (n)) - 1))
  79160. #define DROPBITS(n) \
  79161. do { \
  79162. hold >>= (n); \
  79163. bits -= (unsigned)(n); \
  79164. } while (0)
  79165. #define BYTEBITS() \
  79166. do { \
  79167. hold >>= bits & 7; \
  79168. bits -= bits & 7; \
  79169. } while (0)
  79170. #define REVERSE(q) \
  79171. ((((q) >> 24) & 0xff) + (((q) >> 8) & 0xff00) + \
  79172. (((q) & 0xff00) << 8) + (((q) & 0xff) << 24))
  79173. int ZEXPORT inflate (z_streamp strm, int flush)
  79174. {
  79175. struct inflate_state FAR *state;
  79176. unsigned char FAR *next; /* next input */
  79177. unsigned char FAR *put; /* next output */
  79178. unsigned have, left; /* available input and output */
  79179. unsigned long hold; /* bit buffer */
  79180. unsigned bits; /* bits in bit buffer */
  79181. unsigned in, out; /* save starting available input and output */
  79182. unsigned copy; /* number of stored or match bytes to copy */
  79183. unsigned char FAR *from; /* where to copy match bytes from */
  79184. code thisx; /* current decoding table entry */
  79185. code last; /* parent table entry */
  79186. unsigned len; /* length to copy for repeats, bits to drop */
  79187. int ret; /* return code */
  79188. #ifdef GUNZIP
  79189. unsigned char hbuf[4]; /* buffer for gzip header crc calculation */
  79190. #endif
  79191. static const unsigned short order[19] = /* permutation of code lengths */
  79192. {16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15};
  79193. if (strm == Z_NULL || strm->state == Z_NULL || strm->next_out == Z_NULL ||
  79194. (strm->next_in == Z_NULL && strm->avail_in != 0))
  79195. return Z_STREAM_ERROR;
  79196. state = (struct inflate_state FAR *)strm->state;
  79197. if (state->mode == TYPE) state->mode = TYPEDO; /* skip check */
  79198. LOAD();
  79199. in = have;
  79200. out = left;
  79201. ret = Z_OK;
  79202. for (;;)
  79203. switch (state->mode) {
  79204. case HEAD:
  79205. if (state->wrap == 0) {
  79206. state->mode = TYPEDO;
  79207. break;
  79208. }
  79209. NEEDBITS(16);
  79210. #ifdef GUNZIP
  79211. if ((state->wrap & 2) && hold == 0x8b1f) { /* gzip header */
  79212. state->check = crc32(0L, Z_NULL, 0);
  79213. CRC2(state->check, hold);
  79214. INITBITS();
  79215. state->mode = FLAGS;
  79216. break;
  79217. }
  79218. state->flags = 0; /* expect zlib header */
  79219. if (state->head != Z_NULL)
  79220. state->head->done = -1;
  79221. if (!(state->wrap & 1) || /* check if zlib header allowed */
  79222. #else
  79223. if (
  79224. #endif
  79225. ((BITS(8) << 8) + (hold >> 8)) % 31) {
  79226. strm->msg = (char *)"incorrect header check";
  79227. state->mode = BAD;
  79228. break;
  79229. }
  79230. if (BITS(4) != Z_DEFLATED) {
  79231. strm->msg = (char *)"unknown compression method";
  79232. state->mode = BAD;
  79233. break;
  79234. }
  79235. DROPBITS(4);
  79236. len = BITS(4) + 8;
  79237. if (len > state->wbits) {
  79238. strm->msg = (char *)"invalid window size";
  79239. state->mode = BAD;
  79240. break;
  79241. }
  79242. state->dmax = 1U << len;
  79243. Tracev((stderr, "inflate: zlib header ok\n"));
  79244. strm->adler = state->check = adler32(0L, Z_NULL, 0);
  79245. state->mode = hold & 0x200 ? DICTID : TYPE;
  79246. INITBITS();
  79247. break;
  79248. #ifdef GUNZIP
  79249. case FLAGS:
  79250. NEEDBITS(16);
  79251. state->flags = (int)(hold);
  79252. if ((state->flags & 0xff) != Z_DEFLATED) {
  79253. strm->msg = (char *)"unknown compression method";
  79254. state->mode = BAD;
  79255. break;
  79256. }
  79257. if (state->flags & 0xe000) {
  79258. strm->msg = (char *)"unknown header flags set";
  79259. state->mode = BAD;
  79260. break;
  79261. }
  79262. if (state->head != Z_NULL)
  79263. state->head->text = (int)((hold >> 8) & 1);
  79264. if (state->flags & 0x0200) CRC2(state->check, hold);
  79265. INITBITS();
  79266. state->mode = TIME;
  79267. case TIME:
  79268. NEEDBITS(32);
  79269. if (state->head != Z_NULL)
  79270. state->head->time = hold;
  79271. if (state->flags & 0x0200) CRC4(state->check, hold);
  79272. INITBITS();
  79273. state->mode = OS;
  79274. case OS:
  79275. NEEDBITS(16);
  79276. if (state->head != Z_NULL) {
  79277. state->head->xflags = (int)(hold & 0xff);
  79278. state->head->os = (int)(hold >> 8);
  79279. }
  79280. if (state->flags & 0x0200) CRC2(state->check, hold);
  79281. INITBITS();
  79282. state->mode = EXLEN;
  79283. case EXLEN:
  79284. if (state->flags & 0x0400) {
  79285. NEEDBITS(16);
  79286. state->length = (unsigned)(hold);
  79287. if (state->head != Z_NULL)
  79288. state->head->extra_len = (unsigned)hold;
  79289. if (state->flags & 0x0200) CRC2(state->check, hold);
  79290. INITBITS();
  79291. }
  79292. else if (state->head != Z_NULL)
  79293. state->head->extra = Z_NULL;
  79294. state->mode = EXTRA;
  79295. case EXTRA:
  79296. if (state->flags & 0x0400) {
  79297. copy = state->length;
  79298. if (copy > have) copy = have;
  79299. if (copy) {
  79300. if (state->head != Z_NULL &&
  79301. state->head->extra != Z_NULL) {
  79302. len = state->head->extra_len - state->length;
  79303. zmemcpy(state->head->extra + len, next,
  79304. len + copy > state->head->extra_max ?
  79305. state->head->extra_max - len : copy);
  79306. }
  79307. if (state->flags & 0x0200)
  79308. state->check = crc32(state->check, next, copy);
  79309. have -= copy;
  79310. next += copy;
  79311. state->length -= copy;
  79312. }
  79313. if (state->length) goto inf_leave;
  79314. }
  79315. state->length = 0;
  79316. state->mode = NAME;
  79317. case NAME:
  79318. if (state->flags & 0x0800) {
  79319. if (have == 0) goto inf_leave;
  79320. copy = 0;
  79321. do {
  79322. len = (unsigned)(next[copy++]);
  79323. if (state->head != Z_NULL &&
  79324. state->head->name != Z_NULL &&
  79325. state->length < state->head->name_max)
  79326. state->head->name[state->length++] = len;
  79327. } while (len && copy < have);
  79328. if (state->flags & 0x0200)
  79329. state->check = crc32(state->check, next, copy);
  79330. have -= copy;
  79331. next += copy;
  79332. if (len) goto inf_leave;
  79333. }
  79334. else if (state->head != Z_NULL)
  79335. state->head->name = Z_NULL;
  79336. state->length = 0;
  79337. state->mode = COMMENT;
  79338. case COMMENT:
  79339. if (state->flags & 0x1000) {
  79340. if (have == 0) goto inf_leave;
  79341. copy = 0;
  79342. do {
  79343. len = (unsigned)(next[copy++]);
  79344. if (state->head != Z_NULL &&
  79345. state->head->comment != Z_NULL &&
  79346. state->length < state->head->comm_max)
  79347. state->head->comment[state->length++] = len;
  79348. } while (len && copy < have);
  79349. if (state->flags & 0x0200)
  79350. state->check = crc32(state->check, next, copy);
  79351. have -= copy;
  79352. next += copy;
  79353. if (len) goto inf_leave;
  79354. }
  79355. else if (state->head != Z_NULL)
  79356. state->head->comment = Z_NULL;
  79357. state->mode = HCRC;
  79358. case HCRC:
  79359. if (state->flags & 0x0200) {
  79360. NEEDBITS(16);
  79361. if (hold != (state->check & 0xffff)) {
  79362. strm->msg = (char *)"header crc mismatch";
  79363. state->mode = BAD;
  79364. break;
  79365. }
  79366. INITBITS();
  79367. }
  79368. if (state->head != Z_NULL) {
  79369. state->head->hcrc = (int)((state->flags >> 9) & 1);
  79370. state->head->done = 1;
  79371. }
  79372. strm->adler = state->check = crc32(0L, Z_NULL, 0);
  79373. state->mode = TYPE;
  79374. break;
  79375. #endif
  79376. case DICTID:
  79377. NEEDBITS(32);
  79378. strm->adler = state->check = REVERSE(hold);
  79379. INITBITS();
  79380. state->mode = DICT;
  79381. case DICT:
  79382. if (state->havedict == 0) {
  79383. RESTORE();
  79384. return Z_NEED_DICT;
  79385. }
  79386. strm->adler = state->check = adler32(0L, Z_NULL, 0);
  79387. state->mode = TYPE;
  79388. case TYPE:
  79389. if (flush == Z_BLOCK) goto inf_leave;
  79390. case TYPEDO:
  79391. if (state->last) {
  79392. BYTEBITS();
  79393. state->mode = CHECK;
  79394. break;
  79395. }
  79396. NEEDBITS(3);
  79397. state->last = BITS(1);
  79398. DROPBITS(1);
  79399. switch (BITS(2)) {
  79400. case 0: /* stored block */
  79401. Tracev((stderr, "inflate: stored block%s\n",
  79402. state->last ? " (last)" : ""));
  79403. state->mode = STORED;
  79404. break;
  79405. case 1: /* fixed block */
  79406. fixedtables(state);
  79407. Tracev((stderr, "inflate: fixed codes block%s\n",
  79408. state->last ? " (last)" : ""));
  79409. state->mode = LEN; /* decode codes */
  79410. break;
  79411. case 2: /* dynamic block */
  79412. Tracev((stderr, "inflate: dynamic codes block%s\n",
  79413. state->last ? " (last)" : ""));
  79414. state->mode = TABLE;
  79415. break;
  79416. case 3:
  79417. strm->msg = (char *)"invalid block type";
  79418. state->mode = BAD;
  79419. }
  79420. DROPBITS(2);
  79421. break;
  79422. case STORED:
  79423. BYTEBITS(); /* go to byte boundary */
  79424. NEEDBITS(32);
  79425. if ((hold & 0xffff) != ((hold >> 16) ^ 0xffff)) {
  79426. strm->msg = (char *)"invalid stored block lengths";
  79427. state->mode = BAD;
  79428. break;
  79429. }
  79430. state->length = (unsigned)hold & 0xffff;
  79431. Tracev((stderr, "inflate: stored length %u\n",
  79432. state->length));
  79433. INITBITS();
  79434. state->mode = COPY;
  79435. case COPY:
  79436. copy = state->length;
  79437. if (copy) {
  79438. if (copy > have) copy = have;
  79439. if (copy > left) copy = left;
  79440. if (copy == 0) goto inf_leave;
  79441. zmemcpy(put, next, copy);
  79442. have -= copy;
  79443. next += copy;
  79444. left -= copy;
  79445. put += copy;
  79446. state->length -= copy;
  79447. break;
  79448. }
  79449. Tracev((stderr, "inflate: stored end\n"));
  79450. state->mode = TYPE;
  79451. break;
  79452. case TABLE:
  79453. NEEDBITS(14);
  79454. state->nlen = BITS(5) + 257;
  79455. DROPBITS(5);
  79456. state->ndist = BITS(5) + 1;
  79457. DROPBITS(5);
  79458. state->ncode = BITS(4) + 4;
  79459. DROPBITS(4);
  79460. #ifndef PKZIP_BUG_WORKAROUND
  79461. if (state->nlen > 286 || state->ndist > 30) {
  79462. strm->msg = (char *)"too many length or distance symbols";
  79463. state->mode = BAD;
  79464. break;
  79465. }
  79466. #endif
  79467. Tracev((stderr, "inflate: table sizes ok\n"));
  79468. state->have = 0;
  79469. state->mode = LENLENS;
  79470. case LENLENS:
  79471. while (state->have < state->ncode) {
  79472. NEEDBITS(3);
  79473. state->lens[order[state->have++]] = (unsigned short)BITS(3);
  79474. DROPBITS(3);
  79475. }
  79476. while (state->have < 19)
  79477. state->lens[order[state->have++]] = 0;
  79478. state->next = state->codes;
  79479. state->lencode = (code const FAR *)(state->next);
  79480. state->lenbits = 7;
  79481. ret = inflate_table(CODES, state->lens, 19, &(state->next),
  79482. &(state->lenbits), state->work);
  79483. if (ret) {
  79484. strm->msg = (char *)"invalid code lengths set";
  79485. state->mode = BAD;
  79486. break;
  79487. }
  79488. Tracev((stderr, "inflate: code lengths ok\n"));
  79489. state->have = 0;
  79490. state->mode = CODELENS;
  79491. case CODELENS:
  79492. while (state->have < state->nlen + state->ndist) {
  79493. for (;;) {
  79494. thisx = state->lencode[BITS(state->lenbits)];
  79495. if ((unsigned)(thisx.bits) <= bits) break;
  79496. PULLBYTE();
  79497. }
  79498. if (thisx.val < 16) {
  79499. NEEDBITS(thisx.bits);
  79500. DROPBITS(thisx.bits);
  79501. state->lens[state->have++] = thisx.val;
  79502. }
  79503. else {
  79504. if (thisx.val == 16) {
  79505. NEEDBITS(thisx.bits + 2);
  79506. DROPBITS(thisx.bits);
  79507. if (state->have == 0) {
  79508. strm->msg = (char *)"invalid bit length repeat";
  79509. state->mode = BAD;
  79510. break;
  79511. }
  79512. len = state->lens[state->have - 1];
  79513. copy = 3 + BITS(2);
  79514. DROPBITS(2);
  79515. }
  79516. else if (thisx.val == 17) {
  79517. NEEDBITS(thisx.bits + 3);
  79518. DROPBITS(thisx.bits);
  79519. len = 0;
  79520. copy = 3 + BITS(3);
  79521. DROPBITS(3);
  79522. }
  79523. else {
  79524. NEEDBITS(thisx.bits + 7);
  79525. DROPBITS(thisx.bits);
  79526. len = 0;
  79527. copy = 11 + BITS(7);
  79528. DROPBITS(7);
  79529. }
  79530. if (state->have + copy > state->nlen + state->ndist) {
  79531. strm->msg = (char *)"invalid bit length repeat";
  79532. state->mode = BAD;
  79533. break;
  79534. }
  79535. while (copy--)
  79536. state->lens[state->have++] = (unsigned short)len;
  79537. }
  79538. }
  79539. if (state->mode == BAD) break;
  79540. state->next = state->codes;
  79541. state->lencode = (code const FAR *)(state->next);
  79542. state->lenbits = 9;
  79543. ret = inflate_table(LENS, state->lens, state->nlen, &(state->next),
  79544. &(state->lenbits), state->work);
  79545. if (ret) {
  79546. strm->msg = (char *)"invalid literal/lengths set";
  79547. state->mode = BAD;
  79548. break;
  79549. }
  79550. state->distcode = (code const FAR *)(state->next);
  79551. state->distbits = 6;
  79552. ret = inflate_table(DISTS, state->lens + state->nlen, state->ndist,
  79553. &(state->next), &(state->distbits), state->work);
  79554. if (ret) {
  79555. strm->msg = (char *)"invalid distances set";
  79556. state->mode = BAD;
  79557. break;
  79558. }
  79559. Tracev((stderr, "inflate: codes ok\n"));
  79560. state->mode = LEN;
  79561. case LEN:
  79562. if (have >= 6 && left >= 258) {
  79563. RESTORE();
  79564. inflate_fast(strm, out);
  79565. LOAD();
  79566. break;
  79567. }
  79568. for (;;) {
  79569. thisx = state->lencode[BITS(state->lenbits)];
  79570. if ((unsigned)(thisx.bits) <= bits) break;
  79571. PULLBYTE();
  79572. }
  79573. if (thisx.op && (thisx.op & 0xf0) == 0) {
  79574. last = thisx;
  79575. for (;;) {
  79576. thisx = state->lencode[last.val +
  79577. (BITS(last.bits + last.op) >> last.bits)];
  79578. if ((unsigned)(last.bits + thisx.bits) <= bits) break;
  79579. PULLBYTE();
  79580. }
  79581. DROPBITS(last.bits);
  79582. }
  79583. DROPBITS(thisx.bits);
  79584. state->length = (unsigned)thisx.val;
  79585. if ((int)(thisx.op) == 0) {
  79586. Tracevv((stderr, thisx.val >= 0x20 && thisx.val < 0x7f ?
  79587. "inflate: literal '%c'\n" :
  79588. "inflate: literal 0x%02x\n", thisx.val));
  79589. state->mode = LIT;
  79590. break;
  79591. }
  79592. if (thisx.op & 32) {
  79593. Tracevv((stderr, "inflate: end of block\n"));
  79594. state->mode = TYPE;
  79595. break;
  79596. }
  79597. if (thisx.op & 64) {
  79598. strm->msg = (char *)"invalid literal/length code";
  79599. state->mode = BAD;
  79600. break;
  79601. }
  79602. state->extra = (unsigned)(thisx.op) & 15;
  79603. state->mode = LENEXT;
  79604. case LENEXT:
  79605. if (state->extra) {
  79606. NEEDBITS(state->extra);
  79607. state->length += BITS(state->extra);
  79608. DROPBITS(state->extra);
  79609. }
  79610. Tracevv((stderr, "inflate: length %u\n", state->length));
  79611. state->mode = DIST;
  79612. case DIST:
  79613. for (;;) {
  79614. thisx = state->distcode[BITS(state->distbits)];
  79615. if ((unsigned)(thisx.bits) <= bits) break;
  79616. PULLBYTE();
  79617. }
  79618. if ((thisx.op & 0xf0) == 0) {
  79619. last = thisx;
  79620. for (;;) {
  79621. thisx = state->distcode[last.val +
  79622. (BITS(last.bits + last.op) >> last.bits)];
  79623. if ((unsigned)(last.bits + thisx.bits) <= bits) break;
  79624. PULLBYTE();
  79625. }
  79626. DROPBITS(last.bits);
  79627. }
  79628. DROPBITS(thisx.bits);
  79629. if (thisx.op & 64) {
  79630. strm->msg = (char *)"invalid distance code";
  79631. state->mode = BAD;
  79632. break;
  79633. }
  79634. state->offset = (unsigned)thisx.val;
  79635. state->extra = (unsigned)(thisx.op) & 15;
  79636. state->mode = DISTEXT;
  79637. case DISTEXT:
  79638. if (state->extra) {
  79639. NEEDBITS(state->extra);
  79640. state->offset += BITS(state->extra);
  79641. DROPBITS(state->extra);
  79642. }
  79643. #ifdef INFLATE_STRICT
  79644. if (state->offset > state->dmax) {
  79645. strm->msg = (char *)"invalid distance too far back";
  79646. state->mode = BAD;
  79647. break;
  79648. }
  79649. #endif
  79650. if (state->offset > state->whave + out - left) {
  79651. strm->msg = (char *)"invalid distance too far back";
  79652. state->mode = BAD;
  79653. break;
  79654. }
  79655. Tracevv((stderr, "inflate: distance %u\n", state->offset));
  79656. state->mode = MATCH;
  79657. case MATCH:
  79658. if (left == 0) goto inf_leave;
  79659. copy = out - left;
  79660. if (state->offset > copy) { /* copy from window */
  79661. copy = state->offset - copy;
  79662. if (copy > state->write) {
  79663. copy -= state->write;
  79664. from = state->window + (state->wsize - copy);
  79665. }
  79666. else
  79667. from = state->window + (state->write - copy);
  79668. if (copy > state->length) copy = state->length;
  79669. }
  79670. else { /* copy from output */
  79671. from = put - state->offset;
  79672. copy = state->length;
  79673. }
  79674. if (copy > left) copy = left;
  79675. left -= copy;
  79676. state->length -= copy;
  79677. do {
  79678. *put++ = *from++;
  79679. } while (--copy);
  79680. if (state->length == 0) state->mode = LEN;
  79681. break;
  79682. case LIT:
  79683. if (left == 0) goto inf_leave;
  79684. *put++ = (unsigned char)(state->length);
  79685. left--;
  79686. state->mode = LEN;
  79687. break;
  79688. case CHECK:
  79689. if (state->wrap) {
  79690. NEEDBITS(32);
  79691. out -= left;
  79692. strm->total_out += out;
  79693. state->total += out;
  79694. if (out)
  79695. strm->adler = state->check =
  79696. UPDATE(state->check, put - out, out);
  79697. out = left;
  79698. if ((
  79699. #ifdef GUNZIP
  79700. state->flags ? hold :
  79701. #endif
  79702. REVERSE(hold)) != state->check) {
  79703. strm->msg = (char *)"incorrect data check";
  79704. state->mode = BAD;
  79705. break;
  79706. }
  79707. INITBITS();
  79708. Tracev((stderr, "inflate: check matches trailer\n"));
  79709. }
  79710. #ifdef GUNZIP
  79711. state->mode = LENGTH;
  79712. case LENGTH:
  79713. if (state->wrap && state->flags) {
  79714. NEEDBITS(32);
  79715. if (hold != (state->total & 0xffffffffUL)) {
  79716. strm->msg = (char *)"incorrect length check";
  79717. state->mode = BAD;
  79718. break;
  79719. }
  79720. INITBITS();
  79721. Tracev((stderr, "inflate: length matches trailer\n"));
  79722. }
  79723. #endif
  79724. state->mode = DONE;
  79725. case DONE:
  79726. ret = Z_STREAM_END;
  79727. goto inf_leave;
  79728. case BAD:
  79729. ret = Z_DATA_ERROR;
  79730. goto inf_leave;
  79731. case MEM:
  79732. return Z_MEM_ERROR;
  79733. case SYNC:
  79734. default:
  79735. return Z_STREAM_ERROR;
  79736. }
  79737. inf_leave:
  79738. RESTORE();
  79739. if (state->wsize || (state->mode < CHECK && out != strm->avail_out))
  79740. if (updatewindow(strm, out)) {
  79741. state->mode = MEM;
  79742. return Z_MEM_ERROR;
  79743. }
  79744. in -= strm->avail_in;
  79745. out -= strm->avail_out;
  79746. strm->total_in += in;
  79747. strm->total_out += out;
  79748. state->total += out;
  79749. if (state->wrap && out)
  79750. strm->adler = state->check =
  79751. UPDATE(state->check, strm->next_out - out, out);
  79752. strm->data_type = state->bits + (state->last ? 64 : 0) +
  79753. (state->mode == TYPE ? 128 : 0);
  79754. if (((in == 0 && out == 0) || flush == Z_FINISH) && ret == Z_OK)
  79755. ret = Z_BUF_ERROR;
  79756. return ret;
  79757. }
  79758. int ZEXPORT inflateEnd (z_streamp strm)
  79759. {
  79760. struct inflate_state FAR *state;
  79761. if (strm == Z_NULL || strm->state == Z_NULL || strm->zfree == (free_func)0)
  79762. return Z_STREAM_ERROR;
  79763. state = (struct inflate_state FAR *)strm->state;
  79764. if (state->window != Z_NULL) ZFREE(strm, state->window);
  79765. ZFREE(strm, strm->state);
  79766. strm->state = Z_NULL;
  79767. Tracev((stderr, "inflate: end\n"));
  79768. return Z_OK;
  79769. }
  79770. int ZEXPORT inflateSetDictionary (z_streamp strm, const Bytef *dictionary, uInt dictLength)
  79771. {
  79772. struct inflate_state FAR *state;
  79773. unsigned long id_;
  79774. if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
  79775. state = (struct inflate_state FAR *)strm->state;
  79776. if (state->wrap != 0 && state->mode != DICT)
  79777. return Z_STREAM_ERROR;
  79778. if (state->mode == DICT) {
  79779. id_ = adler32(0L, Z_NULL, 0);
  79780. id_ = adler32(id_, dictionary, dictLength);
  79781. if (id_ != state->check)
  79782. return Z_DATA_ERROR;
  79783. }
  79784. if (updatewindow(strm, strm->avail_out)) {
  79785. state->mode = MEM;
  79786. return Z_MEM_ERROR;
  79787. }
  79788. if (dictLength > state->wsize) {
  79789. zmemcpy(state->window, dictionary + dictLength - state->wsize,
  79790. state->wsize);
  79791. state->whave = state->wsize;
  79792. }
  79793. else {
  79794. zmemcpy(state->window + state->wsize - dictLength, dictionary,
  79795. dictLength);
  79796. state->whave = dictLength;
  79797. }
  79798. state->havedict = 1;
  79799. Tracev((stderr, "inflate: dictionary set\n"));
  79800. return Z_OK;
  79801. }
  79802. int ZEXPORT inflateGetHeader (z_streamp strm, gz_headerp head)
  79803. {
  79804. struct inflate_state FAR *state;
  79805. if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
  79806. state = (struct inflate_state FAR *)strm->state;
  79807. if ((state->wrap & 2) == 0) return Z_STREAM_ERROR;
  79808. state->head = head;
  79809. head->done = 0;
  79810. return Z_OK;
  79811. }
  79812. local unsigned syncsearch (unsigned FAR *have, unsigned char FAR *buf, unsigned len)
  79813. {
  79814. unsigned got;
  79815. unsigned next;
  79816. got = *have;
  79817. next = 0;
  79818. while (next < len && got < 4) {
  79819. if ((int)(buf[next]) == (got < 2 ? 0 : 0xff))
  79820. got++;
  79821. else if (buf[next])
  79822. got = 0;
  79823. else
  79824. got = 4 - got;
  79825. next++;
  79826. }
  79827. *have = got;
  79828. return next;
  79829. }
  79830. int ZEXPORT inflateSync (z_streamp strm)
  79831. {
  79832. unsigned len; /* number of bytes to look at or looked at */
  79833. unsigned long in, out; /* temporary to save total_in and total_out */
  79834. unsigned char buf[4]; /* to restore bit buffer to byte string */
  79835. struct inflate_state FAR *state;
  79836. if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
  79837. state = (struct inflate_state FAR *)strm->state;
  79838. if (strm->avail_in == 0 && state->bits < 8) return Z_BUF_ERROR;
  79839. if (state->mode != SYNC) {
  79840. state->mode = SYNC;
  79841. state->hold <<= state->bits & 7;
  79842. state->bits -= state->bits & 7;
  79843. len = 0;
  79844. while (state->bits >= 8) {
  79845. buf[len++] = (unsigned char)(state->hold);
  79846. state->hold >>= 8;
  79847. state->bits -= 8;
  79848. }
  79849. state->have = 0;
  79850. syncsearch(&(state->have), buf, len);
  79851. }
  79852. len = syncsearch(&(state->have), strm->next_in, strm->avail_in);
  79853. strm->avail_in -= len;
  79854. strm->next_in += len;
  79855. strm->total_in += len;
  79856. if (state->have != 4) return Z_DATA_ERROR;
  79857. in = strm->total_in; out = strm->total_out;
  79858. inflateReset(strm);
  79859. strm->total_in = in; strm->total_out = out;
  79860. state->mode = TYPE;
  79861. return Z_OK;
  79862. }
  79863. int ZEXPORT inflateSyncPoint (z_streamp strm)
  79864. {
  79865. struct inflate_state FAR *state;
  79866. if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
  79867. state = (struct inflate_state FAR *)strm->state;
  79868. return state->mode == STORED && state->bits == 0;
  79869. }
  79870. int ZEXPORT inflateCopy(z_streamp dest, z_streamp source)
  79871. {
  79872. struct inflate_state FAR *state;
  79873. struct inflate_state FAR *copy;
  79874. unsigned char FAR *window;
  79875. unsigned wsize;
  79876. if (dest == Z_NULL || source == Z_NULL || source->state == Z_NULL ||
  79877. source->zalloc == (alloc_func)0 || source->zfree == (free_func)0)
  79878. return Z_STREAM_ERROR;
  79879. state = (struct inflate_state FAR *)source->state;
  79880. copy = (struct inflate_state FAR *)
  79881. ZALLOC(source, 1, sizeof(struct inflate_state));
  79882. if (copy == Z_NULL) return Z_MEM_ERROR;
  79883. window = Z_NULL;
  79884. if (state->window != Z_NULL) {
  79885. window = (unsigned char FAR *)
  79886. ZALLOC(source, 1U << state->wbits, sizeof(unsigned char));
  79887. if (window == Z_NULL) {
  79888. ZFREE(source, copy);
  79889. return Z_MEM_ERROR;
  79890. }
  79891. }
  79892. zmemcpy(dest, source, sizeof(z_stream));
  79893. zmemcpy(copy, state, sizeof(struct inflate_state));
  79894. if (state->lencode >= state->codes &&
  79895. state->lencode <= state->codes + ENOUGH - 1) {
  79896. copy->lencode = copy->codes + (state->lencode - state->codes);
  79897. copy->distcode = copy->codes + (state->distcode - state->codes);
  79898. }
  79899. copy->next = copy->codes + (state->next - state->codes);
  79900. if (window != Z_NULL) {
  79901. wsize = 1U << state->wbits;
  79902. zmemcpy(window, state->window, wsize);
  79903. }
  79904. copy->window = window;
  79905. dest->state = (struct internal_state FAR *)copy;
  79906. return Z_OK;
  79907. }
  79908. /********* End of inlined file: inflate.c *********/
  79909. /********* Start of inlined file: inftrees.c *********/
  79910. #define MAXBITS 15
  79911. const char inflate_copyright[] =
  79912. " inflate 1.2.3 Copyright 1995-2005 Mark Adler ";
  79913. int inflate_table (codetype type,
  79914. unsigned short FAR *lens,
  79915. unsigned codes,
  79916. code FAR * FAR *table,
  79917. unsigned FAR *bits,
  79918. unsigned short FAR *work)
  79919. {
  79920. unsigned len; /* a code's length in bits */
  79921. unsigned sym; /* index of code symbols */
  79922. unsigned min, max; /* minimum and maximum code lengths */
  79923. unsigned root; /* number of index bits for root table */
  79924. unsigned curr; /* number of index bits for current table */
  79925. unsigned drop; /* code bits to drop for sub-table */
  79926. int left; /* number of prefix codes available */
  79927. unsigned used; /* code entries in table used */
  79928. unsigned huff; /* Huffman code */
  79929. unsigned incr; /* for incrementing code, index */
  79930. unsigned fill; /* index for replicating entries */
  79931. unsigned low; /* low bits for current root entry */
  79932. unsigned mask; /* mask for low root bits */
  79933. code thisx; /* table entry for duplication */
  79934. code FAR *next; /* next available space in table */
  79935. const unsigned short FAR *base; /* base value table to use */
  79936. const unsigned short FAR *extra; /* extra bits table to use */
  79937. int end; /* use base and extra for symbol > end */
  79938. unsigned short count[MAXBITS+1]; /* number of codes of each length */
  79939. unsigned short offs[MAXBITS+1]; /* offsets in table for each length */
  79940. static const unsigned short lbase[31] = { /* Length codes 257..285 base */
  79941. 3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31,
  79942. 35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0};
  79943. static const unsigned short lext[31] = { /* Length codes 257..285 extra */
  79944. 16, 16, 16, 16, 16, 16, 16, 16, 17, 17, 17, 17, 18, 18, 18, 18,
  79945. 19, 19, 19, 19, 20, 20, 20, 20, 21, 21, 21, 21, 16, 201, 196};
  79946. static const unsigned short dbase[32] = { /* Distance codes 0..29 base */
  79947. 1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193,
  79948. 257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145,
  79949. 8193, 12289, 16385, 24577, 0, 0};
  79950. static const unsigned short dext[32] = { /* Distance codes 0..29 extra */
  79951. 16, 16, 16, 16, 17, 17, 18, 18, 19, 19, 20, 20, 21, 21, 22, 22,
  79952. 23, 23, 24, 24, 25, 25, 26, 26, 27, 27,
  79953. 28, 28, 29, 29, 64, 64};
  79954. for (len = 0; len <= MAXBITS; len++)
  79955. count[len] = 0;
  79956. for (sym = 0; sym < codes; sym++)
  79957. count[lens[sym]]++;
  79958. root = *bits;
  79959. for (max = MAXBITS; max >= 1; max--)
  79960. if (count[max] != 0) break;
  79961. if (root > max) root = max;
  79962. if (max == 0) { /* no symbols to code at all */
  79963. thisx.op = (unsigned char)64; /* invalid code marker */
  79964. thisx.bits = (unsigned char)1;
  79965. thisx.val = (unsigned short)0;
  79966. *(*table)++ = thisx; /* make a table to force an error */
  79967. *(*table)++ = thisx;
  79968. *bits = 1;
  79969. return 0; /* no symbols, but wait for decoding to report error */
  79970. }
  79971. for (min = 1; min <= MAXBITS; min++)
  79972. if (count[min] != 0) break;
  79973. if (root < min) root = min;
  79974. left = 1;
  79975. for (len = 1; len <= MAXBITS; len++) {
  79976. left <<= 1;
  79977. left -= count[len];
  79978. if (left < 0) return -1; /* over-subscribed */
  79979. }
  79980. if (left > 0 && (type == CODES || max != 1))
  79981. return -1; /* incomplete set */
  79982. offs[1] = 0;
  79983. for (len = 1; len < MAXBITS; len++)
  79984. offs[len + 1] = offs[len] + count[len];
  79985. for (sym = 0; sym < codes; sym++)
  79986. if (lens[sym] != 0) work[offs[lens[sym]]++] = (unsigned short)sym;
  79987. switch (type) {
  79988. case CODES:
  79989. base = extra = work; /* dummy value--not used */
  79990. end = 19;
  79991. break;
  79992. case LENS:
  79993. base = lbase;
  79994. base -= 257;
  79995. extra = lext;
  79996. extra -= 257;
  79997. end = 256;
  79998. break;
  79999. default: /* DISTS */
  80000. base = dbase;
  80001. extra = dext;
  80002. end = -1;
  80003. }
  80004. huff = 0; /* starting code */
  80005. sym = 0; /* starting code symbol */
  80006. len = min; /* starting code length */
  80007. next = *table; /* current table to fill in */
  80008. curr = root; /* current table index bits */
  80009. drop = 0; /* current bits to drop from code for index */
  80010. low = (unsigned)(-1); /* trigger new sub-table when len > root */
  80011. used = 1U << root; /* use root table entries */
  80012. mask = used - 1; /* mask for comparing low */
  80013. if (type == LENS && used >= ENOUGH - MAXD)
  80014. return 1;
  80015. for (;;) {
  80016. thisx.bits = (unsigned char)(len - drop);
  80017. if ((int)(work[sym]) < end) {
  80018. thisx.op = (unsigned char)0;
  80019. thisx.val = work[sym];
  80020. }
  80021. else if ((int)(work[sym]) > end) {
  80022. thisx.op = (unsigned char)(extra[work[sym]]);
  80023. thisx.val = base[work[sym]];
  80024. }
  80025. else {
  80026. thisx.op = (unsigned char)(32 + 64); /* end of block */
  80027. thisx.val = 0;
  80028. }
  80029. incr = 1U << (len - drop);
  80030. fill = 1U << curr;
  80031. min = fill; /* save offset to next table */
  80032. do {
  80033. fill -= incr;
  80034. next[(huff >> drop) + fill] = thisx;
  80035. } while (fill != 0);
  80036. incr = 1U << (len - 1);
  80037. while (huff & incr)
  80038. incr >>= 1;
  80039. if (incr != 0) {
  80040. huff &= incr - 1;
  80041. huff += incr;
  80042. }
  80043. else
  80044. huff = 0;
  80045. sym++;
  80046. if (--(count[len]) == 0) {
  80047. if (len == max) break;
  80048. len = lens[work[sym]];
  80049. }
  80050. if (len > root && (huff & mask) != low) {
  80051. if (drop == 0)
  80052. drop = root;
  80053. next += min; /* here min is 1 << curr */
  80054. curr = len - drop;
  80055. left = (int)(1 << curr);
  80056. while (curr + drop < max) {
  80057. left -= count[curr + drop];
  80058. if (left <= 0) break;
  80059. curr++;
  80060. left <<= 1;
  80061. }
  80062. used += 1U << curr;
  80063. if (type == LENS && used >= ENOUGH - MAXD)
  80064. return 1;
  80065. low = huff & mask;
  80066. (*table)[low].op = (unsigned char)curr;
  80067. (*table)[low].bits = (unsigned char)root;
  80068. (*table)[low].val = (unsigned short)(next - *table);
  80069. }
  80070. }
  80071. thisx.op = (unsigned char)64; /* invalid code marker */
  80072. thisx.bits = (unsigned char)(len - drop);
  80073. thisx.val = (unsigned short)0;
  80074. while (huff != 0) {
  80075. if (drop != 0 && (huff & mask) != low) {
  80076. drop = 0;
  80077. len = root;
  80078. next = *table;
  80079. thisx.bits = (unsigned char)len;
  80080. }
  80081. next[huff >> drop] = thisx;
  80082. incr = 1U << (len - 1);
  80083. while (huff & incr)
  80084. incr >>= 1;
  80085. if (incr != 0) {
  80086. huff &= incr - 1;
  80087. huff += incr;
  80088. }
  80089. else
  80090. huff = 0;
  80091. }
  80092. *table += used;
  80093. *bits = root;
  80094. return 0;
  80095. }
  80096. /********* End of inlined file: inftrees.c *********/
  80097. /********* Start of inlined file: trees.c *********/
  80098. #ifdef DEBUG
  80099. # include <ctype.h>
  80100. #endif
  80101. #define MAX_BL_BITS 7
  80102. #define END_BLOCK 256
  80103. #define REP_3_6 16
  80104. #define REPZ_3_10 17
  80105. #define REPZ_11_138 18
  80106. local const int extra_lbits[LENGTH_CODES] /* extra bits for each length code */
  80107. = {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};
  80108. local const int extra_dbits[D_CODES] /* extra bits for each distance code */
  80109. = {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};
  80110. local const int extra_blbits[BL_CODES]/* extra bits for each bit length code */
  80111. = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,3,7};
  80112. local const uch bl_order[BL_CODES]
  80113. = {16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15};
  80114. #define Buf_size (8 * 2*sizeof(char))
  80115. #define DIST_CODE_LEN 512 /* see definition of array dist_code below */
  80116. #if defined(GEN_TREES_H) || !defined(STDC)
  80117. local ct_data static_ltree[L_CODES+2];
  80118. local ct_data static_dtree[D_CODES];
  80119. uch _dist_code[DIST_CODE_LEN];
  80120. uch _length_code[MAX_MATCH-MIN_MATCH+1];
  80121. local int base_length[LENGTH_CODES];
  80122. local int base_dist[D_CODES];
  80123. #else
  80124. /********* Start of inlined file: trees.h *********/
  80125. local const ct_data static_ltree[L_CODES+2] = {
  80126. {{ 12},{ 8}}, {{140},{ 8}}, {{ 76},{ 8}}, {{204},{ 8}}, {{ 44},{ 8}},
  80127. {{172},{ 8}}, {{108},{ 8}}, {{236},{ 8}}, {{ 28},{ 8}}, {{156},{ 8}},
  80128. {{ 92},{ 8}}, {{220},{ 8}}, {{ 60},{ 8}}, {{188},{ 8}}, {{124},{ 8}},
  80129. {{252},{ 8}}, {{ 2},{ 8}}, {{130},{ 8}}, {{ 66},{ 8}}, {{194},{ 8}},
  80130. {{ 34},{ 8}}, {{162},{ 8}}, {{ 98},{ 8}}, {{226},{ 8}}, {{ 18},{ 8}},
  80131. {{146},{ 8}}, {{ 82},{ 8}}, {{210},{ 8}}, {{ 50},{ 8}}, {{178},{ 8}},
  80132. {{114},{ 8}}, {{242},{ 8}}, {{ 10},{ 8}}, {{138},{ 8}}, {{ 74},{ 8}},
  80133. {{202},{ 8}}, {{ 42},{ 8}}, {{170},{ 8}}, {{106},{ 8}}, {{234},{ 8}},
  80134. {{ 26},{ 8}}, {{154},{ 8}}, {{ 90},{ 8}}, {{218},{ 8}}, {{ 58},{ 8}},
  80135. {{186},{ 8}}, {{122},{ 8}}, {{250},{ 8}}, {{ 6},{ 8}}, {{134},{ 8}},
  80136. {{ 70},{ 8}}, {{198},{ 8}}, {{ 38},{ 8}}, {{166},{ 8}}, {{102},{ 8}},
  80137. {{230},{ 8}}, {{ 22},{ 8}}, {{150},{ 8}}, {{ 86},{ 8}}, {{214},{ 8}},
  80138. {{ 54},{ 8}}, {{182},{ 8}}, {{118},{ 8}}, {{246},{ 8}}, {{ 14},{ 8}},
  80139. {{142},{ 8}}, {{ 78},{ 8}}, {{206},{ 8}}, {{ 46},{ 8}}, {{174},{ 8}},
  80140. {{110},{ 8}}, {{238},{ 8}}, {{ 30},{ 8}}, {{158},{ 8}}, {{ 94},{ 8}},
  80141. {{222},{ 8}}, {{ 62},{ 8}}, {{190},{ 8}}, {{126},{ 8}}, {{254},{ 8}},
  80142. {{ 1},{ 8}}, {{129},{ 8}}, {{ 65},{ 8}}, {{193},{ 8}}, {{ 33},{ 8}},
  80143. {{161},{ 8}}, {{ 97},{ 8}}, {{225},{ 8}}, {{ 17},{ 8}}, {{145},{ 8}},
  80144. {{ 81},{ 8}}, {{209},{ 8}}, {{ 49},{ 8}}, {{177},{ 8}}, {{113},{ 8}},
  80145. {{241},{ 8}}, {{ 9},{ 8}}, {{137},{ 8}}, {{ 73},{ 8}}, {{201},{ 8}},
  80146. {{ 41},{ 8}}, {{169},{ 8}}, {{105},{ 8}}, {{233},{ 8}}, {{ 25},{ 8}},
  80147. {{153},{ 8}}, {{ 89},{ 8}}, {{217},{ 8}}, {{ 57},{ 8}}, {{185},{ 8}},
  80148. {{121},{ 8}}, {{249},{ 8}}, {{ 5},{ 8}}, {{133},{ 8}}, {{ 69},{ 8}},
  80149. {{197},{ 8}}, {{ 37},{ 8}}, {{165},{ 8}}, {{101},{ 8}}, {{229},{ 8}},
  80150. {{ 21},{ 8}}, {{149},{ 8}}, {{ 85},{ 8}}, {{213},{ 8}}, {{ 53},{ 8}},
  80151. {{181},{ 8}}, {{117},{ 8}}, {{245},{ 8}}, {{ 13},{ 8}}, {{141},{ 8}},
  80152. {{ 77},{ 8}}, {{205},{ 8}}, {{ 45},{ 8}}, {{173},{ 8}}, {{109},{ 8}},
  80153. {{237},{ 8}}, {{ 29},{ 8}}, {{157},{ 8}}, {{ 93},{ 8}}, {{221},{ 8}},
  80154. {{ 61},{ 8}}, {{189},{ 8}}, {{125},{ 8}}, {{253},{ 8}}, {{ 19},{ 9}},
  80155. {{275},{ 9}}, {{147},{ 9}}, {{403},{ 9}}, {{ 83},{ 9}}, {{339},{ 9}},
  80156. {{211},{ 9}}, {{467},{ 9}}, {{ 51},{ 9}}, {{307},{ 9}}, {{179},{ 9}},
  80157. {{435},{ 9}}, {{115},{ 9}}, {{371},{ 9}}, {{243},{ 9}}, {{499},{ 9}},
  80158. {{ 11},{ 9}}, {{267},{ 9}}, {{139},{ 9}}, {{395},{ 9}}, {{ 75},{ 9}},
  80159. {{331},{ 9}}, {{203},{ 9}}, {{459},{ 9}}, {{ 43},{ 9}}, {{299},{ 9}},
  80160. {{171},{ 9}}, {{427},{ 9}}, {{107},{ 9}}, {{363},{ 9}}, {{235},{ 9}},
  80161. {{491},{ 9}}, {{ 27},{ 9}}, {{283},{ 9}}, {{155},{ 9}}, {{411},{ 9}},
  80162. {{ 91},{ 9}}, {{347},{ 9}}, {{219},{ 9}}, {{475},{ 9}}, {{ 59},{ 9}},
  80163. {{315},{ 9}}, {{187},{ 9}}, {{443},{ 9}}, {{123},{ 9}}, {{379},{ 9}},
  80164. {{251},{ 9}}, {{507},{ 9}}, {{ 7},{ 9}}, {{263},{ 9}}, {{135},{ 9}},
  80165. {{391},{ 9}}, {{ 71},{ 9}}, {{327},{ 9}}, {{199},{ 9}}, {{455},{ 9}},
  80166. {{ 39},{ 9}}, {{295},{ 9}}, {{167},{ 9}}, {{423},{ 9}}, {{103},{ 9}},
  80167. {{359},{ 9}}, {{231},{ 9}}, {{487},{ 9}}, {{ 23},{ 9}}, {{279},{ 9}},
  80168. {{151},{ 9}}, {{407},{ 9}}, {{ 87},{ 9}}, {{343},{ 9}}, {{215},{ 9}},
  80169. {{471},{ 9}}, {{ 55},{ 9}}, {{311},{ 9}}, {{183},{ 9}}, {{439},{ 9}},
  80170. {{119},{ 9}}, {{375},{ 9}}, {{247},{ 9}}, {{503},{ 9}}, {{ 15},{ 9}},
  80171. {{271},{ 9}}, {{143},{ 9}}, {{399},{ 9}}, {{ 79},{ 9}}, {{335},{ 9}},
  80172. {{207},{ 9}}, {{463},{ 9}}, {{ 47},{ 9}}, {{303},{ 9}}, {{175},{ 9}},
  80173. {{431},{ 9}}, {{111},{ 9}}, {{367},{ 9}}, {{239},{ 9}}, {{495},{ 9}},
  80174. {{ 31},{ 9}}, {{287},{ 9}}, {{159},{ 9}}, {{415},{ 9}}, {{ 95},{ 9}},
  80175. {{351},{ 9}}, {{223},{ 9}}, {{479},{ 9}}, {{ 63},{ 9}}, {{319},{ 9}},
  80176. {{191},{ 9}}, {{447},{ 9}}, {{127},{ 9}}, {{383},{ 9}}, {{255},{ 9}},
  80177. {{511},{ 9}}, {{ 0},{ 7}}, {{ 64},{ 7}}, {{ 32},{ 7}}, {{ 96},{ 7}},
  80178. {{ 16},{ 7}}, {{ 80},{ 7}}, {{ 48},{ 7}}, {{112},{ 7}}, {{ 8},{ 7}},
  80179. {{ 72},{ 7}}, {{ 40},{ 7}}, {{104},{ 7}}, {{ 24},{ 7}}, {{ 88},{ 7}},
  80180. {{ 56},{ 7}}, {{120},{ 7}}, {{ 4},{ 7}}, {{ 68},{ 7}}, {{ 36},{ 7}},
  80181. {{100},{ 7}}, {{ 20},{ 7}}, {{ 84},{ 7}}, {{ 52},{ 7}}, {{116},{ 7}},
  80182. {{ 3},{ 8}}, {{131},{ 8}}, {{ 67},{ 8}}, {{195},{ 8}}, {{ 35},{ 8}},
  80183. {{163},{ 8}}, {{ 99},{ 8}}, {{227},{ 8}}
  80184. };
  80185. local const ct_data static_dtree[D_CODES] = {
  80186. {{ 0},{ 5}}, {{16},{ 5}}, {{ 8},{ 5}}, {{24},{ 5}}, {{ 4},{ 5}},
  80187. {{20},{ 5}}, {{12},{ 5}}, {{28},{ 5}}, {{ 2},{ 5}}, {{18},{ 5}},
  80188. {{10},{ 5}}, {{26},{ 5}}, {{ 6},{ 5}}, {{22},{ 5}}, {{14},{ 5}},
  80189. {{30},{ 5}}, {{ 1},{ 5}}, {{17},{ 5}}, {{ 9},{ 5}}, {{25},{ 5}},
  80190. {{ 5},{ 5}}, {{21},{ 5}}, {{13},{ 5}}, {{29},{ 5}}, {{ 3},{ 5}},
  80191. {{19},{ 5}}, {{11},{ 5}}, {{27},{ 5}}, {{ 7},{ 5}}, {{23},{ 5}}
  80192. };
  80193. const uch _dist_code[DIST_CODE_LEN] = {
  80194. 0, 1, 2, 3, 4, 4, 5, 5, 6, 6, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8,
  80195. 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 10, 10, 10, 10, 10, 10, 10, 10,
  80196. 10, 10, 10, 10, 10, 10, 10, 10, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11,
  80197. 11, 11, 11, 11, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
  80198. 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 13, 13, 13, 13,
  80199. 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
  80200. 13, 13, 13, 13, 13, 13, 13, 13, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
  80201. 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
  80202. 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
  80203. 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 15, 15, 15, 15, 15, 15, 15, 15,
  80204. 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
  80205. 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
  80206. 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 0, 0, 16, 17,
  80207. 18, 18, 19, 19, 20, 20, 20, 20, 21, 21, 21, 21, 22, 22, 22, 22, 22, 22, 22, 22,
  80208. 23, 23, 23, 23, 23, 23, 23, 23, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
  80209. 24, 24, 24, 24, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
  80210. 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26,
  80211. 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 27, 27, 27, 27, 27, 27, 27, 27,
  80212. 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27,
  80213. 27, 27, 27, 27, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28,
  80214. 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28,
  80215. 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28,
  80216. 28, 28, 28, 28, 28, 28, 28, 28, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29,
  80217. 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29,
  80218. 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29,
  80219. 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29
  80220. };
  80221. const uch _length_code[MAX_MATCH-MIN_MATCH+1]= {
  80222. 0, 1, 2, 3, 4, 5, 6, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 12, 12,
  80223. 13, 13, 13, 13, 14, 14, 14, 14, 15, 15, 15, 15, 16, 16, 16, 16, 16, 16, 16, 16,
  80224. 17, 17, 17, 17, 17, 17, 17, 17, 18, 18, 18, 18, 18, 18, 18, 18, 19, 19, 19, 19,
  80225. 19, 19, 19, 19, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
  80226. 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 22, 22, 22, 22,
  80227. 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 23, 23, 23, 23, 23, 23, 23, 23,
  80228. 23, 23, 23, 23, 23, 23, 23, 23, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
  80229. 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
  80230. 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
  80231. 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 26, 26, 26, 26, 26, 26, 26, 26,
  80232. 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26,
  80233. 26, 26, 26, 26, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27,
  80234. 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 28
  80235. };
  80236. local const int base_length[LENGTH_CODES] = {
  80237. 0, 1, 2, 3, 4, 5, 6, 7, 8, 10, 12, 14, 16, 20, 24, 28, 32, 40, 48, 56,
  80238. 64, 80, 96, 112, 128, 160, 192, 224, 0
  80239. };
  80240. local const int base_dist[D_CODES] = {
  80241. 0, 1, 2, 3, 4, 6, 8, 12, 16, 24,
  80242. 32, 48, 64, 96, 128, 192, 256, 384, 512, 768,
  80243. 1024, 1536, 2048, 3072, 4096, 6144, 8192, 12288, 16384, 24576
  80244. };
  80245. /********* End of inlined file: trees.h *********/
  80246. #endif /* GEN_TREES_H */
  80247. struct static_tree_desc_s {
  80248. const ct_data *static_tree; /* static tree or NULL */
  80249. const intf *extra_bits; /* extra bits for each code or NULL */
  80250. int extra_base; /* base index for extra_bits */
  80251. int elems; /* max number of elements in the tree */
  80252. int max_length; /* max bit length for the codes */
  80253. };
  80254. local static_tree_desc static_l_desc =
  80255. {static_ltree, extra_lbits, LITERALS+1, L_CODES, MAX_BITS};
  80256. local static_tree_desc static_d_desc =
  80257. {static_dtree, extra_dbits, 0, D_CODES, MAX_BITS};
  80258. local static_tree_desc static_bl_desc =
  80259. {(const ct_data *)0, extra_blbits, 0, BL_CODES, MAX_BL_BITS};
  80260. local void tr_static_init OF((void));
  80261. local void init_block OF((deflate_state *s));
  80262. local void pqdownheap OF((deflate_state *s, ct_data *tree, int k));
  80263. local void gen_bitlen OF((deflate_state *s, tree_desc *desc));
  80264. local void gen_codes OF((ct_data *tree, int max_code, ushf *bl_count));
  80265. local void build_tree OF((deflate_state *s, tree_desc *desc));
  80266. local void scan_tree OF((deflate_state *s, ct_data *tree, int max_code));
  80267. local void send_tree OF((deflate_state *s, ct_data *tree, int max_code));
  80268. local int build_bl_tree OF((deflate_state *s));
  80269. local void send_all_trees OF((deflate_state *s, int lcodes, int dcodes,
  80270. int blcodes));
  80271. local void compress_block OF((deflate_state *s, ct_data *ltree,
  80272. ct_data *dtree));
  80273. local void set_data_type OF((deflate_state *s));
  80274. local unsigned bi_reverse OF((unsigned value, int length));
  80275. local void bi_windup OF((deflate_state *s));
  80276. local void bi_flush OF((deflate_state *s));
  80277. local void copy_block OF((deflate_state *s, charf *buf, unsigned len,
  80278. int header));
  80279. #ifdef GEN_TREES_H
  80280. local void gen_trees_header OF((void));
  80281. #endif
  80282. #ifndef DEBUG
  80283. # define send_code(s, c, tree) send_bits(s, tree[c].Code, tree[c].Len)
  80284. #else /* DEBUG */
  80285. # define send_code(s, c, tree) \
  80286. { if (z_verbose>2) fprintf(stderr,"\ncd %3d ",(c)); \
  80287. send_bits(s, tree[c].Code, tree[c].Len); }
  80288. #endif
  80289. #define put_short(s, w) { \
  80290. put_byte(s, (uch)((w) & 0xff)); \
  80291. put_byte(s, (uch)((ush)(w) >> 8)); \
  80292. }
  80293. #ifdef DEBUG
  80294. local void send_bits OF((deflate_state *s, int value, int length));
  80295. local void send_bits (deflate_state *s, int value, int length)
  80296. {
  80297. Tracevv((stderr," l %2d v %4x ", length, value));
  80298. Assert(length > 0 && length <= 15, "invalid length");
  80299. s->bits_sent += (ulg)length;
  80300. if (s->bi_valid > (int)Buf_size - length) {
  80301. s->bi_buf |= (value << s->bi_valid);
  80302. put_short(s, s->bi_buf);
  80303. s->bi_buf = (ush)value >> (Buf_size - s->bi_valid);
  80304. s->bi_valid += length - Buf_size;
  80305. } else {
  80306. s->bi_buf |= value << s->bi_valid;
  80307. s->bi_valid += length;
  80308. }
  80309. }
  80310. #else /* !DEBUG */
  80311. #define send_bits(s, value, length) \
  80312. { int len = length;\
  80313. if (s->bi_valid > (int)Buf_size - len) {\
  80314. int val = value;\
  80315. s->bi_buf |= (val << s->bi_valid);\
  80316. put_short(s, s->bi_buf);\
  80317. s->bi_buf = (ush)val >> (Buf_size - s->bi_valid);\
  80318. s->bi_valid += len - Buf_size;\
  80319. } else {\
  80320. s->bi_buf |= (value) << s->bi_valid;\
  80321. s->bi_valid += len;\
  80322. }\
  80323. }
  80324. #endif /* DEBUG */
  80325. local void tr_static_init()
  80326. {
  80327. #if defined(GEN_TREES_H) || !defined(STDC)
  80328. static int static_init_done = 0;
  80329. int n; /* iterates over tree elements */
  80330. int bits; /* bit counter */
  80331. int length; /* length value */
  80332. int code; /* code value */
  80333. int dist; /* distance index */
  80334. ush bl_count[MAX_BITS+1];
  80335. if (static_init_done) return;
  80336. static_l_desc.static_tree = static_ltree;
  80337. static_l_desc.extra_bits = extra_lbits;
  80338. static_d_desc.static_tree = static_dtree;
  80339. static_d_desc.extra_bits = extra_dbits;
  80340. static_bl_desc.extra_bits = extra_blbits;
  80341. length = 0;
  80342. for (code = 0; code < LENGTH_CODES-1; code++) {
  80343. base_length[code] = length;
  80344. for (n = 0; n < (1<<extra_lbits[code]); n++) {
  80345. _length_code[length++] = (uch)code;
  80346. }
  80347. }
  80348. Assert (length == 256, "tr_static_init: length != 256");
  80349. _length_code[length-1] = (uch)code;
  80350. dist = 0;
  80351. for (code = 0 ; code < 16; code++) {
  80352. base_dist[code] = dist;
  80353. for (n = 0; n < (1<<extra_dbits[code]); n++) {
  80354. _dist_code[dist++] = (uch)code;
  80355. }
  80356. }
  80357. Assert (dist == 256, "tr_static_init: dist != 256");
  80358. dist >>= 7; /* from now on, all distances are divided by 128 */
  80359. for ( ; code < D_CODES; code++) {
  80360. base_dist[code] = dist << 7;
  80361. for (n = 0; n < (1<<(extra_dbits[code]-7)); n++) {
  80362. _dist_code[256 + dist++] = (uch)code;
  80363. }
  80364. }
  80365. Assert (dist == 256, "tr_static_init: 256+dist != 512");
  80366. for (bits = 0; bits <= MAX_BITS; bits++) bl_count[bits] = 0;
  80367. n = 0;
  80368. while (n <= 143) static_ltree[n++].Len = 8, bl_count[8]++;
  80369. while (n <= 255) static_ltree[n++].Len = 9, bl_count[9]++;
  80370. while (n <= 279) static_ltree[n++].Len = 7, bl_count[7]++;
  80371. while (n <= 287) static_ltree[n++].Len = 8, bl_count[8]++;
  80372. gen_codes((ct_data *)static_ltree, L_CODES+1, bl_count);
  80373. for (n = 0; n < D_CODES; n++) {
  80374. static_dtree[n].Len = 5;
  80375. static_dtree[n].Code = bi_reverse((unsigned)n, 5);
  80376. }
  80377. static_init_done = 1;
  80378. # ifdef GEN_TREES_H
  80379. gen_trees_header();
  80380. # endif
  80381. #endif /* defined(GEN_TREES_H) || !defined(STDC) */
  80382. }
  80383. #ifdef GEN_TREES_H
  80384. # ifndef DEBUG
  80385. # include <stdio.h>
  80386. # endif
  80387. # define SEPARATOR(i, last, width) \
  80388. ((i) == (last)? "\n};\n\n" : \
  80389. ((i) % (width) == (width)-1 ? ",\n" : ", "))
  80390. void gen_trees_header()
  80391. {
  80392. FILE *header = fopen("trees.h", "w");
  80393. int i;
  80394. Assert (header != NULL, "Can't open trees.h");
  80395. fprintf(header,
  80396. "/* header created automatically with -DGEN_TREES_H */\n\n");
  80397. fprintf(header, "local const ct_data static_ltree[L_CODES+2] = {\n");
  80398. for (i = 0; i < L_CODES+2; i++) {
  80399. fprintf(header, "{{%3u},{%3u}}%s", static_ltree[i].Code,
  80400. static_ltree[i].Len, SEPARATOR(i, L_CODES+1, 5));
  80401. }
  80402. fprintf(header, "local const ct_data static_dtree[D_CODES] = {\n");
  80403. for (i = 0; i < D_CODES; i++) {
  80404. fprintf(header, "{{%2u},{%2u}}%s", static_dtree[i].Code,
  80405. static_dtree[i].Len, SEPARATOR(i, D_CODES-1, 5));
  80406. }
  80407. fprintf(header, "const uch _dist_code[DIST_CODE_LEN] = {\n");
  80408. for (i = 0; i < DIST_CODE_LEN; i++) {
  80409. fprintf(header, "%2u%s", _dist_code[i],
  80410. SEPARATOR(i, DIST_CODE_LEN-1, 20));
  80411. }
  80412. fprintf(header, "const uch _length_code[MAX_MATCH-MIN_MATCH+1]= {\n");
  80413. for (i = 0; i < MAX_MATCH-MIN_MATCH+1; i++) {
  80414. fprintf(header, "%2u%s", _length_code[i],
  80415. SEPARATOR(i, MAX_MATCH-MIN_MATCH, 20));
  80416. }
  80417. fprintf(header, "local const int base_length[LENGTH_CODES] = {\n");
  80418. for (i = 0; i < LENGTH_CODES; i++) {
  80419. fprintf(header, "%1u%s", base_length[i],
  80420. SEPARATOR(i, LENGTH_CODES-1, 20));
  80421. }
  80422. fprintf(header, "local const int base_dist[D_CODES] = {\n");
  80423. for (i = 0; i < D_CODES; i++) {
  80424. fprintf(header, "%5u%s", base_dist[i],
  80425. SEPARATOR(i, D_CODES-1, 10));
  80426. }
  80427. fclose(header);
  80428. }
  80429. #endif /* GEN_TREES_H */
  80430. void _tr_init(deflate_state *s)
  80431. {
  80432. tr_static_init();
  80433. s->l_desc.dyn_tree = s->dyn_ltree;
  80434. s->l_desc.stat_desc = &static_l_desc;
  80435. s->d_desc.dyn_tree = s->dyn_dtree;
  80436. s->d_desc.stat_desc = &static_d_desc;
  80437. s->bl_desc.dyn_tree = s->bl_tree;
  80438. s->bl_desc.stat_desc = &static_bl_desc;
  80439. s->bi_buf = 0;
  80440. s->bi_valid = 0;
  80441. s->last_eob_len = 8; /* enough lookahead for inflate */
  80442. #ifdef DEBUG
  80443. s->compressed_len = 0L;
  80444. s->bits_sent = 0L;
  80445. #endif
  80446. init_block(s);
  80447. }
  80448. local void init_block (deflate_state *s)
  80449. {
  80450. int n; /* iterates over tree elements */
  80451. for (n = 0; n < L_CODES; n++) s->dyn_ltree[n].Freq = 0;
  80452. for (n = 0; n < D_CODES; n++) s->dyn_dtree[n].Freq = 0;
  80453. for (n = 0; n < BL_CODES; n++) s->bl_tree[n].Freq = 0;
  80454. s->dyn_ltree[END_BLOCK].Freq = 1;
  80455. s->opt_len = s->static_len = 0L;
  80456. s->last_lit = s->matches = 0;
  80457. }
  80458. #define SMALLEST 1
  80459. #define pqremove(s, tree, top) \
  80460. {\
  80461. top = s->heap[SMALLEST]; \
  80462. s->heap[SMALLEST] = s->heap[s->heap_len--]; \
  80463. pqdownheap(s, tree, SMALLEST); \
  80464. }
  80465. #define smaller(tree, n, m, depth) \
  80466. (tree[n].Freq < tree[m].Freq || \
  80467. (tree[n].Freq == tree[m].Freq && depth[n] <= depth[m]))
  80468. local void pqdownheap (deflate_state *s,
  80469. ct_data *tree, /* the tree to restore */
  80470. int k) /* node to move down */
  80471. {
  80472. int v = s->heap[k];
  80473. int j = k << 1; /* left son of k */
  80474. while (j <= s->heap_len) {
  80475. if (j < s->heap_len &&
  80476. smaller(tree, s->heap[j+1], s->heap[j], s->depth)) {
  80477. j++;
  80478. }
  80479. if (smaller(tree, v, s->heap[j], s->depth)) break;
  80480. s->heap[k] = s->heap[j]; k = j;
  80481. j <<= 1;
  80482. }
  80483. s->heap[k] = v;
  80484. }
  80485. local void gen_bitlen (deflate_state *s, tree_desc *desc)
  80486. {
  80487. ct_data *tree = desc->dyn_tree;
  80488. int max_code = desc->max_code;
  80489. const ct_data *stree = desc->stat_desc->static_tree;
  80490. const intf *extra = desc->stat_desc->extra_bits;
  80491. int base = desc->stat_desc->extra_base;
  80492. int max_length = desc->stat_desc->max_length;
  80493. int h; /* heap index */
  80494. int n, m; /* iterate over the tree elements */
  80495. int bits; /* bit length */
  80496. int xbits; /* extra bits */
  80497. ush f; /* frequency */
  80498. int overflow = 0; /* number of elements with bit length too large */
  80499. for (bits = 0; bits <= MAX_BITS; bits++) s->bl_count[bits] = 0;
  80500. tree[s->heap[s->heap_max]].Len = 0; /* root of the heap */
  80501. for (h = s->heap_max+1; h < HEAP_SIZE; h++) {
  80502. n = s->heap[h];
  80503. bits = tree[tree[n].Dad].Len + 1;
  80504. if (bits > max_length) bits = max_length, overflow++;
  80505. tree[n].Len = (ush)bits;
  80506. if (n > max_code) continue; /* not a leaf node */
  80507. s->bl_count[bits]++;
  80508. xbits = 0;
  80509. if (n >= base) xbits = extra[n-base];
  80510. f = tree[n].Freq;
  80511. s->opt_len += (ulg)f * (bits + xbits);
  80512. if (stree) s->static_len += (ulg)f * (stree[n].Len + xbits);
  80513. }
  80514. if (overflow == 0) return;
  80515. Trace((stderr,"\nbit length overflow\n"));
  80516. do {
  80517. bits = max_length-1;
  80518. while (s->bl_count[bits] == 0) bits--;
  80519. s->bl_count[bits]--; /* move one leaf down the tree */
  80520. s->bl_count[bits+1] += 2; /* move one overflow item as its brother */
  80521. s->bl_count[max_length]--;
  80522. overflow -= 2;
  80523. } while (overflow > 0);
  80524. for (bits = max_length; bits != 0; bits--) {
  80525. n = s->bl_count[bits];
  80526. while (n != 0) {
  80527. m = s->heap[--h];
  80528. if (m > max_code) continue;
  80529. if ((unsigned) tree[m].Len != (unsigned) bits) {
  80530. Trace((stderr,"code %d bits %d->%d\n", m, tree[m].Len, bits));
  80531. s->opt_len += ((long)bits - (long)tree[m].Len)
  80532. *(long)tree[m].Freq;
  80533. tree[m].Len = (ush)bits;
  80534. }
  80535. n--;
  80536. }
  80537. }
  80538. }
  80539. local void gen_codes (ct_data *tree, /* the tree to decorate */
  80540. int max_code, /* largest code with non zero frequency */
  80541. ushf *bl_count) /* number of codes at each bit length */
  80542. {
  80543. ush next_code[MAX_BITS+1]; /* next code value for each bit length */
  80544. ush code = 0; /* running code value */
  80545. int bits; /* bit index */
  80546. int n; /* code index */
  80547. for (bits = 1; bits <= MAX_BITS; bits++) {
  80548. next_code[bits] = code = (code + bl_count[bits-1]) << 1;
  80549. }
  80550. Assert (code + bl_count[MAX_BITS]-1 == (1<<MAX_BITS)-1,
  80551. "inconsistent bit counts");
  80552. Tracev((stderr,"\ngen_codes: max_code %d ", max_code));
  80553. for (n = 0; n <= max_code; n++) {
  80554. int len = tree[n].Len;
  80555. if (len == 0) continue;
  80556. tree[n].Code = bi_reverse(next_code[len]++, len);
  80557. Tracecv(tree != static_ltree, (stderr,"\nn %3d %c l %2d c %4x (%x) ",
  80558. n, (isgraph(n) ? n : ' '), len, tree[n].Code, next_code[len]-1));
  80559. }
  80560. }
  80561. local void build_tree (deflate_state *s,
  80562. tree_desc *desc) /* the tree descriptor */
  80563. {
  80564. ct_data *tree = desc->dyn_tree;
  80565. const ct_data *stree = desc->stat_desc->static_tree;
  80566. int elems = desc->stat_desc->elems;
  80567. int n, m; /* iterate over heap elements */
  80568. int max_code = -1; /* largest code with non zero frequency */
  80569. int node; /* new node being created */
  80570. s->heap_len = 0, s->heap_max = HEAP_SIZE;
  80571. for (n = 0; n < elems; n++) {
  80572. if (tree[n].Freq != 0) {
  80573. s->heap[++(s->heap_len)] = max_code = n;
  80574. s->depth[n] = 0;
  80575. } else {
  80576. tree[n].Len = 0;
  80577. }
  80578. }
  80579. while (s->heap_len < 2) {
  80580. node = s->heap[++(s->heap_len)] = (max_code < 2 ? ++max_code : 0);
  80581. tree[node].Freq = 1;
  80582. s->depth[node] = 0;
  80583. s->opt_len--; if (stree) s->static_len -= stree[node].Len;
  80584. }
  80585. desc->max_code = max_code;
  80586. for (n = s->heap_len/2; n >= 1; n--) pqdownheap(s, tree, n);
  80587. node = elems; /* next internal node of the tree */
  80588. do {
  80589. pqremove(s, tree, n); /* n = node of least frequency */
  80590. m = s->heap[SMALLEST]; /* m = node of next least frequency */
  80591. s->heap[--(s->heap_max)] = n; /* keep the nodes sorted by frequency */
  80592. s->heap[--(s->heap_max)] = m;
  80593. tree[node].Freq = tree[n].Freq + tree[m].Freq;
  80594. s->depth[node] = (uch)((s->depth[n] >= s->depth[m] ?
  80595. s->depth[n] : s->depth[m]) + 1);
  80596. tree[n].Dad = tree[m].Dad = (ush)node;
  80597. #ifdef DUMP_BL_TREE
  80598. if (tree == s->bl_tree) {
  80599. fprintf(stderr,"\nnode %d(%d), sons %d(%d) %d(%d)",
  80600. node, tree[node].Freq, n, tree[n].Freq, m, tree[m].Freq);
  80601. }
  80602. #endif
  80603. s->heap[SMALLEST] = node++;
  80604. pqdownheap(s, tree, SMALLEST);
  80605. } while (s->heap_len >= 2);
  80606. s->heap[--(s->heap_max)] = s->heap[SMALLEST];
  80607. gen_bitlen(s, (tree_desc *)desc);
  80608. gen_codes ((ct_data *)tree, max_code, s->bl_count);
  80609. }
  80610. local void scan_tree (deflate_state *s,
  80611. ct_data *tree, /* the tree to be scanned */
  80612. int max_code) /* and its largest code of non zero frequency */
  80613. {
  80614. int n; /* iterates over all tree elements */
  80615. int prevlen = -1; /* last emitted length */
  80616. int curlen; /* length of current code */
  80617. int nextlen = tree[0].Len; /* length of next code */
  80618. int count = 0; /* repeat count of the current code */
  80619. int max_count = 7; /* max repeat count */
  80620. int min_count = 4; /* min repeat count */
  80621. if (nextlen == 0) max_count = 138, min_count = 3;
  80622. tree[max_code+1].Len = (ush)0xffff; /* guard */
  80623. for (n = 0; n <= max_code; n++) {
  80624. curlen = nextlen; nextlen = tree[n+1].Len;
  80625. if (++count < max_count && curlen == nextlen) {
  80626. continue;
  80627. } else if (count < min_count) {
  80628. s->bl_tree[curlen].Freq += count;
  80629. } else if (curlen != 0) {
  80630. if (curlen != prevlen) s->bl_tree[curlen].Freq++;
  80631. s->bl_tree[REP_3_6].Freq++;
  80632. } else if (count <= 10) {
  80633. s->bl_tree[REPZ_3_10].Freq++;
  80634. } else {
  80635. s->bl_tree[REPZ_11_138].Freq++;
  80636. }
  80637. count = 0; prevlen = curlen;
  80638. if (nextlen == 0) {
  80639. max_count = 138, min_count = 3;
  80640. } else if (curlen == nextlen) {
  80641. max_count = 6, min_count = 3;
  80642. } else {
  80643. max_count = 7, min_count = 4;
  80644. }
  80645. }
  80646. }
  80647. local void send_tree (deflate_state *s,
  80648. ct_data *tree, /* the tree to be scanned */
  80649. int max_code) /* and its largest code of non zero frequency */
  80650. {
  80651. int n; /* iterates over all tree elements */
  80652. int prevlen = -1; /* last emitted length */
  80653. int curlen; /* length of current code */
  80654. int nextlen = tree[0].Len; /* length of next code */
  80655. int count = 0; /* repeat count of the current code */
  80656. int max_count = 7; /* max repeat count */
  80657. int min_count = 4; /* min repeat count */
  80658. /* guard already set */
  80659. if (nextlen == 0) max_count = 138, min_count = 3;
  80660. for (n = 0; n <= max_code; n++) {
  80661. curlen = nextlen; nextlen = tree[n+1].Len;
  80662. if (++count < max_count && curlen == nextlen) {
  80663. continue;
  80664. } else if (count < min_count) {
  80665. do { send_code(s, curlen, s->bl_tree); } while (--count != 0);
  80666. } else if (curlen != 0) {
  80667. if (curlen != prevlen) {
  80668. send_code(s, curlen, s->bl_tree); count--;
  80669. }
  80670. Assert(count >= 3 && count <= 6, " 3_6?");
  80671. send_code(s, REP_3_6, s->bl_tree); send_bits(s, count-3, 2);
  80672. } else if (count <= 10) {
  80673. send_code(s, REPZ_3_10, s->bl_tree); send_bits(s, count-3, 3);
  80674. } else {
  80675. send_code(s, REPZ_11_138, s->bl_tree); send_bits(s, count-11, 7);
  80676. }
  80677. count = 0; prevlen = curlen;
  80678. if (nextlen == 0) {
  80679. max_count = 138, min_count = 3;
  80680. } else if (curlen == nextlen) {
  80681. max_count = 6, min_count = 3;
  80682. } else {
  80683. max_count = 7, min_count = 4;
  80684. }
  80685. }
  80686. }
  80687. local int build_bl_tree (deflate_state *s)
  80688. {
  80689. int max_blindex; /* index of last bit length code of non zero freq */
  80690. scan_tree(s, (ct_data *)s->dyn_ltree, s->l_desc.max_code);
  80691. scan_tree(s, (ct_data *)s->dyn_dtree, s->d_desc.max_code);
  80692. build_tree(s, (tree_desc *)(&(s->bl_desc)));
  80693. for (max_blindex = BL_CODES-1; max_blindex >= 3; max_blindex--) {
  80694. if (s->bl_tree[bl_order[max_blindex]].Len != 0) break;
  80695. }
  80696. s->opt_len += 3*(max_blindex+1) + 5+5+4;
  80697. Tracev((stderr, "\ndyn trees: dyn %ld, stat %ld",
  80698. s->opt_len, s->static_len));
  80699. return max_blindex;
  80700. }
  80701. local void send_all_trees (deflate_state *s,
  80702. int lcodes, int dcodes, int blcodes) /* number of codes for each tree */
  80703. {
  80704. int rank; /* index in bl_order */
  80705. Assert (lcodes >= 257 && dcodes >= 1 && blcodes >= 4, "not enough codes");
  80706. Assert (lcodes <= L_CODES && dcodes <= D_CODES && blcodes <= BL_CODES,
  80707. "too many codes");
  80708. Tracev((stderr, "\nbl counts: "));
  80709. send_bits(s, lcodes-257, 5); /* not +255 as stated in appnote.txt */
  80710. send_bits(s, dcodes-1, 5);
  80711. send_bits(s, blcodes-4, 4); /* not -3 as stated in appnote.txt */
  80712. for (rank = 0; rank < blcodes; rank++) {
  80713. Tracev((stderr, "\nbl code %2d ", bl_order[rank]));
  80714. send_bits(s, s->bl_tree[bl_order[rank]].Len, 3);
  80715. }
  80716. Tracev((stderr, "\nbl tree: sent %ld", s->bits_sent));
  80717. send_tree(s, (ct_data *)s->dyn_ltree, lcodes-1); /* literal tree */
  80718. Tracev((stderr, "\nlit tree: sent %ld", s->bits_sent));
  80719. send_tree(s, (ct_data *)s->dyn_dtree, dcodes-1); /* distance tree */
  80720. Tracev((stderr, "\ndist tree: sent %ld", s->bits_sent));
  80721. }
  80722. void _tr_stored_block (deflate_state *s, charf *buf, ulg stored_len, int eof)
  80723. {
  80724. send_bits(s, (STORED_BLOCK<<1)+eof, 3); /* send block type */
  80725. #ifdef DEBUG
  80726. s->compressed_len = (s->compressed_len + 3 + 7) & (ulg)~7L;
  80727. s->compressed_len += (stored_len + 4) << 3;
  80728. #endif
  80729. copy_block(s, buf, (unsigned)stored_len, 1); /* with header */
  80730. }
  80731. void _tr_align (deflate_state *s)
  80732. {
  80733. send_bits(s, STATIC_TREES<<1, 3);
  80734. send_code(s, END_BLOCK, static_ltree);
  80735. #ifdef DEBUG
  80736. s->compressed_len += 10L; /* 3 for block type, 7 for EOB */
  80737. #endif
  80738. bi_flush(s);
  80739. if (1 + s->last_eob_len + 10 - s->bi_valid < 9) {
  80740. send_bits(s, STATIC_TREES<<1, 3);
  80741. send_code(s, END_BLOCK, static_ltree);
  80742. #ifdef DEBUG
  80743. s->compressed_len += 10L;
  80744. #endif
  80745. bi_flush(s);
  80746. }
  80747. s->last_eob_len = 7;
  80748. }
  80749. void _tr_flush_block (deflate_state *s,
  80750. charf *buf, /* input block, or NULL if too old */
  80751. ulg stored_len, /* length of input block */
  80752. int eof) /* true if this is the last block for a file */
  80753. {
  80754. ulg opt_lenb, static_lenb; /* opt_len and static_len in bytes */
  80755. int max_blindex = 0; /* index of last bit length code of non zero freq */
  80756. if (s->level > 0) {
  80757. if (stored_len > 0 && s->strm->data_type == Z_UNKNOWN)
  80758. set_data_type(s);
  80759. build_tree(s, (tree_desc *)(&(s->l_desc)));
  80760. Tracev((stderr, "\nlit data: dyn %ld, stat %ld", s->opt_len,
  80761. s->static_len));
  80762. build_tree(s, (tree_desc *)(&(s->d_desc)));
  80763. Tracev((stderr, "\ndist data: dyn %ld, stat %ld", s->opt_len,
  80764. s->static_len));
  80765. max_blindex = build_bl_tree(s);
  80766. opt_lenb = (s->opt_len+3+7)>>3;
  80767. static_lenb = (s->static_len+3+7)>>3;
  80768. Tracev((stderr, "\nopt %lu(%lu) stat %lu(%lu) stored %lu lit %u ",
  80769. opt_lenb, s->opt_len, static_lenb, s->static_len, stored_len,
  80770. s->last_lit));
  80771. if (static_lenb <= opt_lenb) opt_lenb = static_lenb;
  80772. } else {
  80773. Assert(buf != (char*)0, "lost buf");
  80774. opt_lenb = static_lenb = stored_len + 5; /* force a stored block */
  80775. }
  80776. #ifdef FORCE_STORED
  80777. if (buf != (char*)0) { /* force stored block */
  80778. #else
  80779. if (stored_len+4 <= opt_lenb && buf != (char*)0) {
  80780. #endif
  80781. _tr_stored_block(s, buf, stored_len, eof);
  80782. #ifdef FORCE_STATIC
  80783. } else if (static_lenb >= 0) { /* force static trees */
  80784. #else
  80785. } else if (s->strategy == Z_FIXED || static_lenb == opt_lenb) {
  80786. #endif
  80787. send_bits(s, (STATIC_TREES<<1)+eof, 3);
  80788. compress_block(s, (ct_data *)static_ltree, (ct_data *)static_dtree);
  80789. #ifdef DEBUG
  80790. s->compressed_len += 3 + s->static_len;
  80791. #endif
  80792. } else {
  80793. send_bits(s, (DYN_TREES<<1)+eof, 3);
  80794. send_all_trees(s, s->l_desc.max_code+1, s->d_desc.max_code+1,
  80795. max_blindex+1);
  80796. compress_block(s, (ct_data *)s->dyn_ltree, (ct_data *)s->dyn_dtree);
  80797. #ifdef DEBUG
  80798. s->compressed_len += 3 + s->opt_len;
  80799. #endif
  80800. }
  80801. Assert (s->compressed_len == s->bits_sent, "bad compressed size");
  80802. init_block(s);
  80803. if (eof) {
  80804. bi_windup(s);
  80805. #ifdef DEBUG
  80806. s->compressed_len += 7; /* align on byte boundary */
  80807. #endif
  80808. }
  80809. Tracev((stderr,"\ncomprlen %lu(%lu) ", s->compressed_len>>3,
  80810. s->compressed_len-7*eof));
  80811. }
  80812. int _tr_tally (deflate_state *s,
  80813. unsigned dist, /* distance of matched string */
  80814. unsigned lc) /* match length-MIN_MATCH or unmatched char (if dist==0) */
  80815. {
  80816. s->d_buf[s->last_lit] = (ush)dist;
  80817. s->l_buf[s->last_lit++] = (uch)lc;
  80818. if (dist == 0) {
  80819. s->dyn_ltree[lc].Freq++;
  80820. } else {
  80821. s->matches++;
  80822. dist--; /* dist = match distance - 1 */
  80823. Assert((ush)dist < (ush)MAX_DIST(s) &&
  80824. (ush)lc <= (ush)(MAX_MATCH-MIN_MATCH) &&
  80825. (ush)d_code(dist) < (ush)D_CODES, "_tr_tally: bad match");
  80826. s->dyn_ltree[_length_code[lc]+LITERALS+1].Freq++;
  80827. s->dyn_dtree[d_code(dist)].Freq++;
  80828. }
  80829. #ifdef TRUNCATE_BLOCK
  80830. if ((s->last_lit & 0x1fff) == 0 && s->level > 2) {
  80831. ulg out_length = (ulg)s->last_lit*8L;
  80832. ulg in_length = (ulg)((long)s->strstart - s->block_start);
  80833. int dcode;
  80834. for (dcode = 0; dcode < D_CODES; dcode++) {
  80835. out_length += (ulg)s->dyn_dtree[dcode].Freq *
  80836. (5L+extra_dbits[dcode]);
  80837. }
  80838. out_length >>= 3;
  80839. Tracev((stderr,"\nlast_lit %u, in %ld, out ~%ld(%ld%%) ",
  80840. s->last_lit, in_length, out_length,
  80841. 100L - out_length*100L/in_length));
  80842. if (s->matches < s->last_lit/2 && out_length < in_length/2) return 1;
  80843. }
  80844. #endif
  80845. return (s->last_lit == s->lit_bufsize-1);
  80846. }
  80847. local void compress_block (deflate_state *s,
  80848. ct_data *ltree, /* literal tree */
  80849. ct_data *dtree) /* distance tree */
  80850. {
  80851. unsigned dist; /* distance of matched string */
  80852. int lc; /* match length or unmatched char (if dist == 0) */
  80853. unsigned lx = 0; /* running index in l_buf */
  80854. unsigned code; /* the code to send */
  80855. int extra; /* number of extra bits to send */
  80856. if (s->last_lit != 0) do {
  80857. dist = s->d_buf[lx];
  80858. lc = s->l_buf[lx++];
  80859. if (dist == 0) {
  80860. send_code(s, lc, ltree); /* send a literal byte */
  80861. Tracecv(isgraph(lc), (stderr," '%c' ", lc));
  80862. } else {
  80863. code = _length_code[lc];
  80864. send_code(s, code+LITERALS+1, ltree); /* send the length code */
  80865. extra = extra_lbits[code];
  80866. if (extra != 0) {
  80867. lc -= base_length[code];
  80868. send_bits(s, lc, extra); /* send the extra length bits */
  80869. }
  80870. dist--; /* dist is now the match distance - 1 */
  80871. code = d_code(dist);
  80872. Assert (code < D_CODES, "bad d_code");
  80873. send_code(s, code, dtree); /* send the distance code */
  80874. extra = extra_dbits[code];
  80875. if (extra != 0) {
  80876. dist -= base_dist[code];
  80877. send_bits(s, dist, extra); /* send the extra distance bits */
  80878. }
  80879. } /* literal or match pair ? */
  80880. Assert((uInt)(s->pending) < s->lit_bufsize + 2*lx,
  80881. "pendingBuf overflow");
  80882. } while (lx < s->last_lit);
  80883. send_code(s, END_BLOCK, ltree);
  80884. s->last_eob_len = ltree[END_BLOCK].Len;
  80885. }
  80886. local void set_data_type (deflate_state *s)
  80887. {
  80888. int n;
  80889. for (n = 0; n < 9; n++)
  80890. if (s->dyn_ltree[n].Freq != 0)
  80891. break;
  80892. if (n == 9)
  80893. for (n = 14; n < 32; n++)
  80894. if (s->dyn_ltree[n].Freq != 0)
  80895. break;
  80896. s->strm->data_type = (n == 32) ? Z_TEXT : Z_BINARY;
  80897. }
  80898. local unsigned bi_reverse (unsigned code, int len)
  80899. {
  80900. register unsigned res = 0;
  80901. do {
  80902. res |= code & 1;
  80903. code >>= 1, res <<= 1;
  80904. } while (--len > 0);
  80905. return res >> 1;
  80906. }
  80907. local void bi_flush (deflate_state *s)
  80908. {
  80909. if (s->bi_valid == 16) {
  80910. put_short(s, s->bi_buf);
  80911. s->bi_buf = 0;
  80912. s->bi_valid = 0;
  80913. } else if (s->bi_valid >= 8) {
  80914. put_byte(s, (Byte)s->bi_buf);
  80915. s->bi_buf >>= 8;
  80916. s->bi_valid -= 8;
  80917. }
  80918. }
  80919. local void bi_windup (deflate_state *s)
  80920. {
  80921. if (s->bi_valid > 8) {
  80922. put_short(s, s->bi_buf);
  80923. } else if (s->bi_valid > 0) {
  80924. put_byte(s, (Byte)s->bi_buf);
  80925. }
  80926. s->bi_buf = 0;
  80927. s->bi_valid = 0;
  80928. #ifdef DEBUG
  80929. s->bits_sent = (s->bits_sent+7) & ~7;
  80930. #endif
  80931. }
  80932. local void copy_block(deflate_state *s,
  80933. charf *buf, /* the input data */
  80934. unsigned len, /* its length */
  80935. int header) /* true if block header must be written */
  80936. {
  80937. bi_windup(s); /* align on byte boundary */
  80938. s->last_eob_len = 8; /* enough lookahead for inflate */
  80939. if (header) {
  80940. put_short(s, (ush)len);
  80941. put_short(s, (ush)~len);
  80942. #ifdef DEBUG
  80943. s->bits_sent += 2*16;
  80944. #endif
  80945. }
  80946. #ifdef DEBUG
  80947. s->bits_sent += (ulg)len<<3;
  80948. #endif
  80949. while (len--) {
  80950. put_byte(s, *buf++);
  80951. }
  80952. }
  80953. /********* End of inlined file: trees.c *********/
  80954. /********* Start of inlined file: zutil.c *********/
  80955. #ifndef NO_DUMMY_DECL
  80956. struct internal_state {int dummy;}; /* for buggy compilers */
  80957. #endif
  80958. const char * const z_errmsg[10] = {
  80959. "need dictionary", /* Z_NEED_DICT 2 */
  80960. "stream end", /* Z_STREAM_END 1 */
  80961. "", /* Z_OK 0 */
  80962. "file error", /* Z_ERRNO (-1) */
  80963. "stream error", /* Z_STREAM_ERROR (-2) */
  80964. "data error", /* Z_DATA_ERROR (-3) */
  80965. "insufficient memory", /* Z_MEM_ERROR (-4) */
  80966. "buffer error", /* Z_BUF_ERROR (-5) */
  80967. "incompatible version",/* Z_VERSION_ERROR (-6) */
  80968. ""};
  80969. #ifdef DEBUG
  80970. # ifndef verbose
  80971. # define verbose 0
  80972. # endif
  80973. int z_verbose = verbose;
  80974. void z_error (const char *m)
  80975. {
  80976. fprintf(stderr, "%s\n", m);
  80977. exit(1);
  80978. }
  80979. #endif
  80980. const char * ZEXPORT zError(int err)
  80981. {
  80982. return ERR_MSG(err);
  80983. }
  80984. #if defined(_WIN32_WCE)
  80985. int errno = 0;
  80986. #endif
  80987. #ifndef HAVE_MEMCPY
  80988. void zmemcpy(dest, source, len)
  80989. Bytef* dest;
  80990. const Bytef* source;
  80991. uInt len;
  80992. {
  80993. if (len == 0) return;
  80994. do {
  80995. *dest++ = *source++; /* ??? to be unrolled */
  80996. } while (--len != 0);
  80997. }
  80998. int zmemcmp(s1, s2, len)
  80999. const Bytef* s1;
  81000. const Bytef* s2;
  81001. uInt len;
  81002. {
  81003. uInt j;
  81004. for (j = 0; j < len; j++) {
  81005. if (s1[j] != s2[j]) return 2*(s1[j] > s2[j])-1;
  81006. }
  81007. return 0;
  81008. }
  81009. void zmemzero(dest, len)
  81010. Bytef* dest;
  81011. uInt len;
  81012. {
  81013. if (len == 0) return;
  81014. do {
  81015. *dest++ = 0; /* ??? to be unrolled */
  81016. } while (--len != 0);
  81017. }
  81018. #endif
  81019. #ifdef SYS16BIT
  81020. #ifdef __TURBOC__
  81021. # define MY_ZCALLOC
  81022. #define MAX_PTR 10
  81023. local int next_ptr = 0;
  81024. typedef struct ptr_table_s {
  81025. voidpf org_ptr;
  81026. voidpf new_ptr;
  81027. } ptr_table;
  81028. local ptr_table table[MAX_PTR];
  81029. voidpf zcalloc (voidpf opaque, unsigned items, unsigned size)
  81030. {
  81031. voidpf buf = opaque; /* just to make some compilers happy */
  81032. ulg bsize = (ulg)items*size;
  81033. if (bsize < 65520L) {
  81034. buf = farmalloc(bsize);
  81035. if (*(ush*)&buf != 0) return buf;
  81036. } else {
  81037. buf = farmalloc(bsize + 16L);
  81038. }
  81039. if (buf == NULL || next_ptr >= MAX_PTR) return NULL;
  81040. table[next_ptr].org_ptr = buf;
  81041. *((ush*)&buf+1) += ((ush)((uch*)buf-0) + 15) >> 4;
  81042. *(ush*)&buf = 0;
  81043. table[next_ptr++].new_ptr = buf;
  81044. return buf;
  81045. }
  81046. void zcfree (voidpf opaque, voidpf ptr)
  81047. {
  81048. int n;
  81049. if (*(ush*)&ptr != 0) { /* object < 64K */
  81050. farfree(ptr);
  81051. return;
  81052. }
  81053. for (n = 0; n < next_ptr; n++) {
  81054. if (ptr != table[n].new_ptr) continue;
  81055. farfree(table[n].org_ptr);
  81056. while (++n < next_ptr) {
  81057. table[n-1] = table[n];
  81058. }
  81059. next_ptr--;
  81060. return;
  81061. }
  81062. ptr = opaque; /* just to make some compilers happy */
  81063. Assert(0, "zcfree: ptr not found");
  81064. }
  81065. #endif /* __TURBOC__ */
  81066. #ifdef M_I86
  81067. # define MY_ZCALLOC
  81068. #if (!defined(_MSC_VER) || (_MSC_VER <= 600))
  81069. # define _halloc halloc
  81070. # define _hfree hfree
  81071. #endif
  81072. voidpf zcalloc (voidpf opaque, unsigned items, unsigned size)
  81073. {
  81074. if (opaque) opaque = 0; /* to make compiler happy */
  81075. return _halloc((long)items, size);
  81076. }
  81077. void zcfree (voidpf opaque, voidpf ptr)
  81078. {
  81079. if (opaque) opaque = 0; /* to make compiler happy */
  81080. _hfree(ptr);
  81081. }
  81082. #endif /* M_I86 */
  81083. #endif /* SYS16BIT */
  81084. #ifndef MY_ZCALLOC /* Any system without a special alloc function */
  81085. #ifndef STDC
  81086. extern voidp malloc OF((uInt size));
  81087. extern voidp calloc OF((uInt items, uInt size));
  81088. extern void free OF((voidpf ptr));
  81089. #endif
  81090. voidpf zcalloc (voidpf opaque, unsigned items, unsigned size)
  81091. {
  81092. if (opaque) items += size - size; /* make compiler happy */
  81093. return sizeof(uInt) > 2 ? (voidpf)malloc(items * size) :
  81094. (voidpf)calloc(items, size);
  81095. }
  81096. void zcfree (voidpf opaque, voidpf ptr)
  81097. {
  81098. free(ptr);
  81099. if (opaque) return; /* make compiler happy */
  81100. }
  81101. #endif /* MY_ZCALLOC */
  81102. /********* End of inlined file: zutil.c *********/
  81103. #undef Byte
  81104. }
  81105. #else
  81106. #include <zlib.h>
  81107. #endif
  81108. }
  81109. #if JUCE_MSVC
  81110. #pragma warning (pop)
  81111. #endif
  81112. BEGIN_JUCE_NAMESPACE
  81113. using namespace zlibNamespace;
  81114. // internal helper object that holds the zlib structures so they don't have to be
  81115. // included publicly.
  81116. class GZIPDecompressHelper
  81117. {
  81118. public:
  81119. GZIPDecompressHelper (const bool noWrap) throw()
  81120. : data (0),
  81121. dataSize (0),
  81122. finished (true),
  81123. needsDictionary (false),
  81124. error (true),
  81125. streamIsValid (false)
  81126. {
  81127. zerostruct (stream);
  81128. streamIsValid = (inflateInit2 (&stream, noWrap ? -MAX_WBITS : MAX_WBITS) == Z_OK);
  81129. finished = error = ! streamIsValid;
  81130. }
  81131. ~GZIPDecompressHelper() throw()
  81132. {
  81133. if (streamIsValid)
  81134. inflateEnd (&stream);
  81135. }
  81136. bool needsInput() const throw() { return dataSize <= 0; }
  81137. void setInput (uint8* const data_, const int size) throw()
  81138. {
  81139. data = data_;
  81140. dataSize = size;
  81141. }
  81142. int doNextBlock (uint8* const dest, const int destSize) throw()
  81143. {
  81144. if (streamIsValid && data != 0 && ! finished)
  81145. {
  81146. stream.next_in = data;
  81147. stream.next_out = dest;
  81148. stream.avail_in = dataSize;
  81149. stream.avail_out = destSize;
  81150. switch (inflate (&stream, Z_PARTIAL_FLUSH))
  81151. {
  81152. case Z_STREAM_END:
  81153. finished = true;
  81154. // deliberate fall-through
  81155. case Z_OK:
  81156. data += dataSize - stream.avail_in;
  81157. dataSize = stream.avail_in;
  81158. return destSize - stream.avail_out;
  81159. case Z_NEED_DICT:
  81160. needsDictionary = true;
  81161. data += dataSize - stream.avail_in;
  81162. dataSize = stream.avail_in;
  81163. break;
  81164. case Z_DATA_ERROR:
  81165. case Z_MEM_ERROR:
  81166. error = true;
  81167. default:
  81168. break;
  81169. }
  81170. }
  81171. return 0;
  81172. }
  81173. private:
  81174. z_stream stream;
  81175. uint8* data;
  81176. int dataSize;
  81177. public:
  81178. bool finished, needsDictionary, error, streamIsValid;
  81179. };
  81180. const int gzipDecompBufferSize = 32768;
  81181. GZIPDecompressorInputStream::GZIPDecompressorInputStream (InputStream* const sourceStream_,
  81182. const bool deleteSourceWhenDestroyed,
  81183. const bool noWrap_,
  81184. const int64 uncompressedStreamLength_)
  81185. : sourceStream (sourceStream_),
  81186. streamToDelete (deleteSourceWhenDestroyed ? sourceStream_ : 0),
  81187. uncompressedStreamLength (uncompressedStreamLength_),
  81188. noWrap (noWrap_),
  81189. isEof (false),
  81190. activeBufferSize (0),
  81191. originalSourcePos (sourceStream_->getPosition()),
  81192. currentPos (0),
  81193. buffer (gzipDecompBufferSize),
  81194. helper (new GZIPDecompressHelper (noWrap_))
  81195. {
  81196. }
  81197. GZIPDecompressorInputStream::~GZIPDecompressorInputStream()
  81198. {
  81199. }
  81200. int64 GZIPDecompressorInputStream::getTotalLength()
  81201. {
  81202. return uncompressedStreamLength;
  81203. }
  81204. int GZIPDecompressorInputStream::read (void* destBuffer, int howMany)
  81205. {
  81206. if ((howMany > 0) && ! isEof)
  81207. {
  81208. jassert (destBuffer != 0);
  81209. if (destBuffer != 0)
  81210. {
  81211. int numRead = 0;
  81212. uint8* d = (uint8*) destBuffer;
  81213. while (! helper->error)
  81214. {
  81215. const int n = helper->doNextBlock (d, howMany);
  81216. currentPos += n;
  81217. if (n == 0)
  81218. {
  81219. if (helper->finished || helper->needsDictionary)
  81220. {
  81221. isEof = true;
  81222. return numRead;
  81223. }
  81224. if (helper->needsInput())
  81225. {
  81226. activeBufferSize = sourceStream->read (buffer, gzipDecompBufferSize);
  81227. if (activeBufferSize > 0)
  81228. {
  81229. helper->setInput ((uint8*) buffer, activeBufferSize);
  81230. }
  81231. else
  81232. {
  81233. isEof = true;
  81234. return numRead;
  81235. }
  81236. }
  81237. }
  81238. else
  81239. {
  81240. numRead += n;
  81241. howMany -= n;
  81242. d += n;
  81243. if (howMany <= 0)
  81244. return numRead;
  81245. }
  81246. }
  81247. }
  81248. }
  81249. return 0;
  81250. }
  81251. bool GZIPDecompressorInputStream::isExhausted()
  81252. {
  81253. return helper->error || isEof;
  81254. }
  81255. int64 GZIPDecompressorInputStream::getPosition()
  81256. {
  81257. return currentPos;
  81258. }
  81259. bool GZIPDecompressorInputStream::setPosition (int64 newPos)
  81260. {
  81261. if (newPos < currentPos)
  81262. {
  81263. // to go backwards, reset the stream and start again..
  81264. isEof = false;
  81265. activeBufferSize = 0;
  81266. currentPos = 0;
  81267. helper = new GZIPDecompressHelper (noWrap);
  81268. sourceStream->setPosition (originalSourcePos);
  81269. }
  81270. skipNextBytes (newPos - currentPos);
  81271. return true;
  81272. }
  81273. END_JUCE_NAMESPACE
  81274. /********* End of inlined file: juce_GZIPDecompressorInputStream.cpp *********/
  81275. #if ! JUCE_ONLY_BUILD_CORE_LIBRARY
  81276. /********* Start of inlined file: juce_FlacAudioFormat.cpp *********/
  81277. #if JUCE_USE_FLAC
  81278. #if JUCE_WINDOWS
  81279. #include <windows.h>
  81280. #endif
  81281. #ifdef _MSC_VER
  81282. #pragma warning (disable : 4505)
  81283. #pragma warning (push)
  81284. #endif
  81285. namespace FlacNamespace
  81286. {
  81287. #if JUCE_INCLUDE_FLAC_CODE
  81288. #define FLAC__NO_DLL 1
  81289. #if ! defined (SIZE_MAX)
  81290. #define SIZE_MAX 0xffffffff
  81291. #endif
  81292. #define __STDC_LIMIT_MACROS 1
  81293. /********* Start of inlined file: all.h *********/
  81294. #ifndef FLAC__ALL_H
  81295. #define FLAC__ALL_H
  81296. /********* Start of inlined file: export.h *********/
  81297. #ifndef FLAC__EXPORT_H
  81298. #define FLAC__EXPORT_H
  81299. #if defined(FLAC__NO_DLL) || !defined(_MSC_VER)
  81300. #define FLAC_API
  81301. #else
  81302. #ifdef FLAC_API_EXPORTS
  81303. #define FLAC_API _declspec(dllexport)
  81304. #else
  81305. #define FLAC_API _declspec(dllimport)
  81306. #endif
  81307. #endif
  81308. #define FLAC_API_VERSION_CURRENT 10
  81309. #define FLAC_API_VERSION_REVISION 0 /**< see above */
  81310. #define FLAC_API_VERSION_AGE 2 /**< see above */
  81311. #ifdef __cplusplus
  81312. extern "C" {
  81313. #endif
  81314. extern FLAC_API int FLAC_API_SUPPORTS_OGG_FLAC;
  81315. #ifdef __cplusplus
  81316. }
  81317. #endif
  81318. #endif
  81319. /********* End of inlined file: export.h *********/
  81320. /********* Start of inlined file: assert.h *********/
  81321. #ifndef FLAC__ASSERT_H
  81322. #define FLAC__ASSERT_H
  81323. /* we need this since some compilers (like MSVC) leave assert()s on release code (and we don't want to use their ASSERT) */
  81324. #ifdef DEBUG
  81325. #include <assert.h>
  81326. #define FLAC__ASSERT(x) assert(x)
  81327. #define FLAC__ASSERT_DECLARATION(x) x
  81328. #else
  81329. #define FLAC__ASSERT(x)
  81330. #define FLAC__ASSERT_DECLARATION(x)
  81331. #endif
  81332. #endif
  81333. /********* End of inlined file: assert.h *********/
  81334. /********* Start of inlined file: callback.h *********/
  81335. #ifndef FLAC__CALLBACK_H
  81336. #define FLAC__CALLBACK_H
  81337. /********* Start of inlined file: ordinals.h *********/
  81338. #ifndef FLAC__ORDINALS_H
  81339. #define FLAC__ORDINALS_H
  81340. #if !(defined(_MSC_VER) || defined(__BORLANDC__) || defined(__EMX__))
  81341. #include <inttypes.h>
  81342. #endif
  81343. typedef signed char FLAC__int8;
  81344. typedef unsigned char FLAC__uint8;
  81345. #if defined(_MSC_VER) || defined(__BORLANDC__)
  81346. typedef __int16 FLAC__int16;
  81347. typedef __int32 FLAC__int32;
  81348. typedef __int64 FLAC__int64;
  81349. typedef unsigned __int16 FLAC__uint16;
  81350. typedef unsigned __int32 FLAC__uint32;
  81351. typedef unsigned __int64 FLAC__uint64;
  81352. #elif defined(__EMX__)
  81353. typedef short FLAC__int16;
  81354. typedef long FLAC__int32;
  81355. typedef long long FLAC__int64;
  81356. typedef unsigned short FLAC__uint16;
  81357. typedef unsigned long FLAC__uint32;
  81358. typedef unsigned long long FLAC__uint64;
  81359. #else
  81360. typedef int16_t FLAC__int16;
  81361. typedef int32_t FLAC__int32;
  81362. typedef int64_t FLAC__int64;
  81363. typedef uint16_t FLAC__uint16;
  81364. typedef uint32_t FLAC__uint32;
  81365. typedef uint64_t FLAC__uint64;
  81366. #endif
  81367. typedef int FLAC__bool;
  81368. typedef FLAC__uint8 FLAC__byte;
  81369. #ifdef true
  81370. #undef true
  81371. #endif
  81372. #ifdef false
  81373. #undef false
  81374. #endif
  81375. #ifndef __cplusplus
  81376. #define true 1
  81377. #define false 0
  81378. #endif
  81379. #endif
  81380. /********* End of inlined file: ordinals.h *********/
  81381. #include <stdlib.h> /* for size_t */
  81382. #ifdef __cplusplus
  81383. extern "C" {
  81384. #endif
  81385. typedef void* FLAC__IOHandle;
  81386. typedef size_t (*FLAC__IOCallback_Read) (void *ptr, size_t size, size_t nmemb, FLAC__IOHandle handle);
  81387. typedef size_t (*FLAC__IOCallback_Write) (const void *ptr, size_t size, size_t nmemb, FLAC__IOHandle handle);
  81388. typedef int (*FLAC__IOCallback_Seek) (FLAC__IOHandle handle, FLAC__int64 offset, int whence);
  81389. typedef FLAC__int64 (*FLAC__IOCallback_Tell) (FLAC__IOHandle handle);
  81390. typedef int (*FLAC__IOCallback_Eof) (FLAC__IOHandle handle);
  81391. typedef int (*FLAC__IOCallback_Close) (FLAC__IOHandle handle);
  81392. typedef struct {
  81393. FLAC__IOCallback_Read read;
  81394. FLAC__IOCallback_Write write;
  81395. FLAC__IOCallback_Seek seek;
  81396. FLAC__IOCallback_Tell tell;
  81397. FLAC__IOCallback_Eof eof;
  81398. FLAC__IOCallback_Close close;
  81399. } FLAC__IOCallbacks;
  81400. #ifdef __cplusplus
  81401. }
  81402. #endif
  81403. #endif
  81404. /********* End of inlined file: callback.h *********/
  81405. /********* Start of inlined file: format.h *********/
  81406. #ifndef FLAC__FORMAT_H
  81407. #define FLAC__FORMAT_H
  81408. #ifdef __cplusplus
  81409. extern "C" {
  81410. #endif
  81411. #define FLAC__MAX_METADATA_TYPE_CODE (126u)
  81412. #define FLAC__MIN_BLOCK_SIZE (16u)
  81413. #define FLAC__MAX_BLOCK_SIZE (65535u)
  81414. #define FLAC__SUBSET_MAX_BLOCK_SIZE_48000HZ (4608u)
  81415. #define FLAC__MAX_CHANNELS (8u)
  81416. #define FLAC__MIN_BITS_PER_SAMPLE (4u)
  81417. #define FLAC__MAX_BITS_PER_SAMPLE (32u)
  81418. #define FLAC__REFERENCE_CODEC_MAX_BITS_PER_SAMPLE (24u)
  81419. #define FLAC__MAX_SAMPLE_RATE (655350u)
  81420. #define FLAC__MAX_LPC_ORDER (32u)
  81421. #define FLAC__SUBSET_MAX_LPC_ORDER_48000HZ (12u)
  81422. #define FLAC__MIN_QLP_COEFF_PRECISION (5u)
  81423. #define FLAC__MAX_QLP_COEFF_PRECISION (15u)
  81424. #define FLAC__MAX_FIXED_ORDER (4u)
  81425. #define FLAC__MAX_RICE_PARTITION_ORDER (15u)
  81426. #define FLAC__SUBSET_MAX_RICE_PARTITION_ORDER (8u)
  81427. extern FLAC_API const char *FLAC__VERSION_STRING;
  81428. extern FLAC_API const char *FLAC__VENDOR_STRING;
  81429. extern FLAC_API const FLAC__byte FLAC__STREAM_SYNC_STRING[4]; /* = "fLaC" */
  81430. extern FLAC_API const unsigned FLAC__STREAM_SYNC; /* = 0x664C6143 */
  81431. extern FLAC_API const unsigned FLAC__STREAM_SYNC_LEN; /* = 32 bits */
  81432. #define FLAC__STREAM_SYNC_LENGTH (4u)
  81433. typedef enum {
  81434. FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE = 0,
  81435. FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2 = 1
  81436. } FLAC__EntropyCodingMethodType;
  81437. extern FLAC_API const char * const FLAC__EntropyCodingMethodTypeString[];
  81438. typedef struct {
  81439. unsigned *parameters;
  81440. unsigned *raw_bits;
  81441. unsigned capacity_by_order;
  81442. } FLAC__EntropyCodingMethod_PartitionedRiceContents;
  81443. typedef struct {
  81444. unsigned order;
  81445. const FLAC__EntropyCodingMethod_PartitionedRiceContents *contents;
  81446. } FLAC__EntropyCodingMethod_PartitionedRice;
  81447. extern FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ORDER_LEN; /**< == 4 (bits) */
  81448. extern FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_PARAMETER_LEN; /**< == 4 (bits) */
  81449. extern FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_PARAMETER_LEN; /**< == 5 (bits) */
  81450. extern FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_RAW_LEN; /**< == 5 (bits) */
  81451. extern FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ESCAPE_PARAMETER;
  81452. extern FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_ESCAPE_PARAMETER;
  81453. typedef struct {
  81454. FLAC__EntropyCodingMethodType type;
  81455. union {
  81456. FLAC__EntropyCodingMethod_PartitionedRice partitioned_rice;
  81457. } data;
  81458. } FLAC__EntropyCodingMethod;
  81459. extern FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_TYPE_LEN; /**< == 2 (bits) */
  81460. typedef enum {
  81461. FLAC__SUBFRAME_TYPE_CONSTANT = 0, /**< constant signal */
  81462. FLAC__SUBFRAME_TYPE_VERBATIM = 1, /**< uncompressed signal */
  81463. FLAC__SUBFRAME_TYPE_FIXED = 2, /**< fixed polynomial prediction */
  81464. FLAC__SUBFRAME_TYPE_LPC = 3 /**< linear prediction */
  81465. } FLAC__SubframeType;
  81466. extern FLAC_API const char * const FLAC__SubframeTypeString[];
  81467. typedef struct {
  81468. FLAC__int32 value; /**< The constant signal value. */
  81469. } FLAC__Subframe_Constant;
  81470. typedef struct {
  81471. const FLAC__int32 *data; /**< A pointer to verbatim signal. */
  81472. } FLAC__Subframe_Verbatim;
  81473. typedef struct {
  81474. FLAC__EntropyCodingMethod entropy_coding_method;
  81475. unsigned order;
  81476. FLAC__int32 warmup[FLAC__MAX_FIXED_ORDER];
  81477. const FLAC__int32 *residual;
  81478. } FLAC__Subframe_Fixed;
  81479. typedef struct {
  81480. FLAC__EntropyCodingMethod entropy_coding_method;
  81481. unsigned order;
  81482. unsigned qlp_coeff_precision;
  81483. int quantization_level;
  81484. FLAC__int32 qlp_coeff[FLAC__MAX_LPC_ORDER];
  81485. FLAC__int32 warmup[FLAC__MAX_LPC_ORDER];
  81486. const FLAC__int32 *residual;
  81487. } FLAC__Subframe_LPC;
  81488. extern FLAC_API const unsigned FLAC__SUBFRAME_LPC_QLP_COEFF_PRECISION_LEN; /**< == 4 (bits) */
  81489. extern FLAC_API const unsigned FLAC__SUBFRAME_LPC_QLP_SHIFT_LEN; /**< == 5 (bits) */
  81490. typedef struct {
  81491. FLAC__SubframeType type;
  81492. union {
  81493. FLAC__Subframe_Constant constant;
  81494. FLAC__Subframe_Fixed fixed;
  81495. FLAC__Subframe_LPC lpc;
  81496. FLAC__Subframe_Verbatim verbatim;
  81497. } data;
  81498. unsigned wasted_bits;
  81499. } FLAC__Subframe;
  81500. extern FLAC_API const unsigned FLAC__SUBFRAME_ZERO_PAD_LEN;
  81501. extern FLAC_API const unsigned FLAC__SUBFRAME_TYPE_LEN; /**< == 6 (bits) */
  81502. extern FLAC_API const unsigned FLAC__SUBFRAME_WASTED_BITS_FLAG_LEN; /**< == 1 (bit) */
  81503. extern FLAC_API const unsigned FLAC__SUBFRAME_TYPE_CONSTANT_BYTE_ALIGNED_MASK; /**< = 0x00 */
  81504. extern FLAC_API const unsigned FLAC__SUBFRAME_TYPE_VERBATIM_BYTE_ALIGNED_MASK; /**< = 0x02 */
  81505. extern FLAC_API const unsigned FLAC__SUBFRAME_TYPE_FIXED_BYTE_ALIGNED_MASK; /**< = 0x10 */
  81506. extern FLAC_API const unsigned FLAC__SUBFRAME_TYPE_LPC_BYTE_ALIGNED_MASK; /**< = 0x40 */
  81507. typedef enum {
  81508. FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT = 0, /**< independent channels */
  81509. FLAC__CHANNEL_ASSIGNMENT_LEFT_SIDE = 1, /**< left+side stereo */
  81510. FLAC__CHANNEL_ASSIGNMENT_RIGHT_SIDE = 2, /**< right+side stereo */
  81511. FLAC__CHANNEL_ASSIGNMENT_MID_SIDE = 3 /**< mid+side stereo */
  81512. } FLAC__ChannelAssignment;
  81513. extern FLAC_API const char * const FLAC__ChannelAssignmentString[];
  81514. typedef enum {
  81515. FLAC__FRAME_NUMBER_TYPE_FRAME_NUMBER, /**< number contains the frame number */
  81516. FLAC__FRAME_NUMBER_TYPE_SAMPLE_NUMBER /**< number contains the sample number of first sample in frame */
  81517. } FLAC__FrameNumberType;
  81518. extern FLAC_API const char * const FLAC__FrameNumberTypeString[];
  81519. typedef struct {
  81520. unsigned blocksize;
  81521. unsigned sample_rate;
  81522. unsigned channels;
  81523. FLAC__ChannelAssignment channel_assignment;
  81524. unsigned bits_per_sample;
  81525. FLAC__FrameNumberType number_type;
  81526. union {
  81527. FLAC__uint32 frame_number;
  81528. FLAC__uint64 sample_number;
  81529. } number;
  81530. FLAC__uint8 crc;
  81531. } FLAC__FrameHeader;
  81532. extern FLAC_API const unsigned FLAC__FRAME_HEADER_SYNC; /**< == 0x3ffe; the frame header sync code */
  81533. extern FLAC_API const unsigned FLAC__FRAME_HEADER_SYNC_LEN; /**< == 14 (bits) */
  81534. extern FLAC_API const unsigned FLAC__FRAME_HEADER_RESERVED_LEN; /**< == 1 (bits) */
  81535. extern FLAC_API const unsigned FLAC__FRAME_HEADER_BLOCKING_STRATEGY_LEN; /**< == 1 (bits) */
  81536. extern FLAC_API const unsigned FLAC__FRAME_HEADER_BLOCK_SIZE_LEN; /**< == 4 (bits) */
  81537. extern FLAC_API const unsigned FLAC__FRAME_HEADER_SAMPLE_RATE_LEN; /**< == 4 (bits) */
  81538. extern FLAC_API const unsigned FLAC__FRAME_HEADER_CHANNEL_ASSIGNMENT_LEN; /**< == 4 (bits) */
  81539. extern FLAC_API const unsigned FLAC__FRAME_HEADER_BITS_PER_SAMPLE_LEN; /**< == 3 (bits) */
  81540. extern FLAC_API const unsigned FLAC__FRAME_HEADER_ZERO_PAD_LEN; /**< == 1 (bit) */
  81541. extern FLAC_API const unsigned FLAC__FRAME_HEADER_CRC_LEN; /**< == 8 (bits) */
  81542. typedef struct {
  81543. FLAC__uint16 crc;
  81544. } FLAC__FrameFooter;
  81545. extern FLAC_API const unsigned FLAC__FRAME_FOOTER_CRC_LEN; /**< == 16 (bits) */
  81546. typedef struct {
  81547. FLAC__FrameHeader header;
  81548. FLAC__Subframe subframes[FLAC__MAX_CHANNELS];
  81549. FLAC__FrameFooter footer;
  81550. } FLAC__Frame;
  81551. typedef enum {
  81552. FLAC__METADATA_TYPE_STREAMINFO = 0,
  81553. FLAC__METADATA_TYPE_PADDING = 1,
  81554. FLAC__METADATA_TYPE_APPLICATION = 2,
  81555. FLAC__METADATA_TYPE_SEEKTABLE = 3,
  81556. FLAC__METADATA_TYPE_VORBIS_COMMENT = 4,
  81557. FLAC__METADATA_TYPE_CUESHEET = 5,
  81558. FLAC__METADATA_TYPE_PICTURE = 6,
  81559. FLAC__METADATA_TYPE_UNDEFINED = 7
  81560. } FLAC__MetadataType;
  81561. extern FLAC_API const char * const FLAC__MetadataTypeString[];
  81562. typedef struct {
  81563. unsigned min_blocksize, max_blocksize;
  81564. unsigned min_framesize, max_framesize;
  81565. unsigned sample_rate;
  81566. unsigned channels;
  81567. unsigned bits_per_sample;
  81568. FLAC__uint64 total_samples;
  81569. FLAC__byte md5sum[16];
  81570. } FLAC__StreamMetadata_StreamInfo;
  81571. extern FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN; /**< == 16 (bits) */
  81572. extern FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN; /**< == 16 (bits) */
  81573. extern FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN; /**< == 24 (bits) */
  81574. extern FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_MAX_FRAME_SIZE_LEN; /**< == 24 (bits) */
  81575. extern FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_SAMPLE_RATE_LEN; /**< == 20 (bits) */
  81576. extern FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_CHANNELS_LEN; /**< == 3 (bits) */
  81577. extern FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN; /**< == 5 (bits) */
  81578. extern FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_TOTAL_SAMPLES_LEN; /**< == 36 (bits) */
  81579. extern FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_MD5SUM_LEN; /**< == 128 (bits) */
  81580. #define FLAC__STREAM_METADATA_STREAMINFO_LENGTH (34u)
  81581. typedef struct {
  81582. int dummy;
  81583. } FLAC__StreamMetadata_Padding;
  81584. typedef struct {
  81585. FLAC__byte id[4];
  81586. FLAC__byte *data;
  81587. } FLAC__StreamMetadata_Application;
  81588. extern FLAC_API const unsigned FLAC__STREAM_METADATA_APPLICATION_ID_LEN; /**< == 32 (bits) */
  81589. typedef struct {
  81590. FLAC__uint64 sample_number;
  81591. FLAC__uint64 stream_offset;
  81592. unsigned frame_samples;
  81593. } FLAC__StreamMetadata_SeekPoint;
  81594. extern FLAC_API const unsigned FLAC__STREAM_METADATA_SEEKPOINT_SAMPLE_NUMBER_LEN; /**< == 64 (bits) */
  81595. extern FLAC_API const unsigned FLAC__STREAM_METADATA_SEEKPOINT_STREAM_OFFSET_LEN; /**< == 64 (bits) */
  81596. extern FLAC_API const unsigned FLAC__STREAM_METADATA_SEEKPOINT_FRAME_SAMPLES_LEN; /**< == 16 (bits) */
  81597. #define FLAC__STREAM_METADATA_SEEKPOINT_LENGTH (18u)
  81598. extern FLAC_API const FLAC__uint64 FLAC__STREAM_METADATA_SEEKPOINT_PLACEHOLDER;
  81599. typedef struct {
  81600. unsigned num_points;
  81601. FLAC__StreamMetadata_SeekPoint *points;
  81602. } FLAC__StreamMetadata_SeekTable;
  81603. typedef struct {
  81604. FLAC__uint32 length;
  81605. FLAC__byte *entry;
  81606. } FLAC__StreamMetadata_VorbisComment_Entry;
  81607. extern FLAC_API const unsigned FLAC__STREAM_METADATA_VORBIS_COMMENT_ENTRY_LENGTH_LEN; /**< == 32 (bits) */
  81608. typedef struct {
  81609. FLAC__StreamMetadata_VorbisComment_Entry vendor_string;
  81610. FLAC__uint32 num_comments;
  81611. FLAC__StreamMetadata_VorbisComment_Entry *comments;
  81612. } FLAC__StreamMetadata_VorbisComment;
  81613. extern FLAC_API const unsigned FLAC__STREAM_METADATA_VORBIS_COMMENT_NUM_COMMENTS_LEN; /**< == 32 (bits) */
  81614. typedef struct {
  81615. FLAC__uint64 offset;
  81616. FLAC__byte number;
  81617. } FLAC__StreamMetadata_CueSheet_Index;
  81618. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_INDEX_OFFSET_LEN; /**< == 64 (bits) */
  81619. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_INDEX_NUMBER_LEN; /**< == 8 (bits) */
  81620. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_INDEX_RESERVED_LEN; /**< == 3*8 (bits) */
  81621. typedef struct {
  81622. FLAC__uint64 offset;
  81623. FLAC__byte number;
  81624. char isrc[13];
  81625. unsigned type:1;
  81626. unsigned pre_emphasis:1;
  81627. FLAC__byte num_indices;
  81628. FLAC__StreamMetadata_CueSheet_Index *indices;
  81629. } FLAC__StreamMetadata_CueSheet_Track;
  81630. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_OFFSET_LEN; /**< == 64 (bits) */
  81631. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_NUMBER_LEN; /**< == 8 (bits) */
  81632. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_ISRC_LEN; /**< == 12*8 (bits) */
  81633. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_TYPE_LEN; /**< == 1 (bit) */
  81634. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_PRE_EMPHASIS_LEN; /**< == 1 (bit) */
  81635. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_RESERVED_LEN; /**< == 6+13*8 (bits) */
  81636. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_NUM_INDICES_LEN; /**< == 8 (bits) */
  81637. typedef struct {
  81638. char media_catalog_number[129];
  81639. FLAC__uint64 lead_in;
  81640. FLAC__bool is_cd;
  81641. unsigned num_tracks;
  81642. FLAC__StreamMetadata_CueSheet_Track *tracks;
  81643. } FLAC__StreamMetadata_CueSheet;
  81644. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_MEDIA_CATALOG_NUMBER_LEN; /**< == 128*8 (bits) */
  81645. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_LEAD_IN_LEN; /**< == 64 (bits) */
  81646. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_IS_CD_LEN; /**< == 1 (bit) */
  81647. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_RESERVED_LEN; /**< == 7+258*8 (bits) */
  81648. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_NUM_TRACKS_LEN; /**< == 8 (bits) */
  81649. typedef enum {
  81650. FLAC__STREAM_METADATA_PICTURE_TYPE_OTHER = 0, /**< Other */
  81651. FLAC__STREAM_METADATA_PICTURE_TYPE_FILE_ICON_STANDARD = 1, /**< 32x32 pixels 'file icon' (PNG only) */
  81652. FLAC__STREAM_METADATA_PICTURE_TYPE_FILE_ICON = 2, /**< Other file icon */
  81653. FLAC__STREAM_METADATA_PICTURE_TYPE_FRONT_COVER = 3, /**< Cover (front) */
  81654. FLAC__STREAM_METADATA_PICTURE_TYPE_BACK_COVER = 4, /**< Cover (back) */
  81655. FLAC__STREAM_METADATA_PICTURE_TYPE_LEAFLET_PAGE = 5, /**< Leaflet page */
  81656. FLAC__STREAM_METADATA_PICTURE_TYPE_MEDIA = 6, /**< Media (e.g. label side of CD) */
  81657. FLAC__STREAM_METADATA_PICTURE_TYPE_LEAD_ARTIST = 7, /**< Lead artist/lead performer/soloist */
  81658. FLAC__STREAM_METADATA_PICTURE_TYPE_ARTIST = 8, /**< Artist/performer */
  81659. FLAC__STREAM_METADATA_PICTURE_TYPE_CONDUCTOR = 9, /**< Conductor */
  81660. FLAC__STREAM_METADATA_PICTURE_TYPE_BAND = 10, /**< Band/Orchestra */
  81661. FLAC__STREAM_METADATA_PICTURE_TYPE_COMPOSER = 11, /**< Composer */
  81662. FLAC__STREAM_METADATA_PICTURE_TYPE_LYRICIST = 12, /**< Lyricist/text writer */
  81663. FLAC__STREAM_METADATA_PICTURE_TYPE_RECORDING_LOCATION = 13, /**< Recording Location */
  81664. FLAC__STREAM_METADATA_PICTURE_TYPE_DURING_RECORDING = 14, /**< During recording */
  81665. FLAC__STREAM_METADATA_PICTURE_TYPE_DURING_PERFORMANCE = 15, /**< During performance */
  81666. FLAC__STREAM_METADATA_PICTURE_TYPE_VIDEO_SCREEN_CAPTURE = 16, /**< Movie/video screen capture */
  81667. FLAC__STREAM_METADATA_PICTURE_TYPE_FISH = 17, /**< A bright coloured fish */
  81668. FLAC__STREAM_METADATA_PICTURE_TYPE_ILLUSTRATION = 18, /**< Illustration */
  81669. FLAC__STREAM_METADATA_PICTURE_TYPE_BAND_LOGOTYPE = 19, /**< Band/artist logotype */
  81670. FLAC__STREAM_METADATA_PICTURE_TYPE_PUBLISHER_LOGOTYPE = 20, /**< Publisher/Studio logotype */
  81671. FLAC__STREAM_METADATA_PICTURE_TYPE_UNDEFINED
  81672. } FLAC__StreamMetadata_Picture_Type;
  81673. extern FLAC_API const char * const FLAC__StreamMetadata_Picture_TypeString[];
  81674. typedef struct {
  81675. FLAC__StreamMetadata_Picture_Type type;
  81676. char *mime_type;
  81677. FLAC__byte *description;
  81678. FLAC__uint32 width;
  81679. FLAC__uint32 height;
  81680. FLAC__uint32 depth;
  81681. FLAC__uint32 colors;
  81682. FLAC__uint32 data_length;
  81683. FLAC__byte *data;
  81684. } FLAC__StreamMetadata_Picture;
  81685. extern FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_TYPE_LEN; /**< == 32 (bits) */
  81686. extern FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_MIME_TYPE_LENGTH_LEN; /**< == 32 (bits) */
  81687. extern FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_DESCRIPTION_LENGTH_LEN; /**< == 32 (bits) */
  81688. extern FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_WIDTH_LEN; /**< == 32 (bits) */
  81689. extern FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_HEIGHT_LEN; /**< == 32 (bits) */
  81690. extern FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_DEPTH_LEN; /**< == 32 (bits) */
  81691. extern FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_COLORS_LEN; /**< == 32 (bits) */
  81692. extern FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_DATA_LENGTH_LEN; /**< == 32 (bits) */
  81693. typedef struct {
  81694. FLAC__byte *data;
  81695. } FLAC__StreamMetadata_Unknown;
  81696. typedef struct {
  81697. FLAC__MetadataType type;
  81698. FLAC__bool is_last;
  81699. unsigned length;
  81700. union {
  81701. FLAC__StreamMetadata_StreamInfo stream_info;
  81702. FLAC__StreamMetadata_Padding padding;
  81703. FLAC__StreamMetadata_Application application;
  81704. FLAC__StreamMetadata_SeekTable seek_table;
  81705. FLAC__StreamMetadata_VorbisComment vorbis_comment;
  81706. FLAC__StreamMetadata_CueSheet cue_sheet;
  81707. FLAC__StreamMetadata_Picture picture;
  81708. FLAC__StreamMetadata_Unknown unknown;
  81709. } data;
  81710. } FLAC__StreamMetadata;
  81711. extern FLAC_API const unsigned FLAC__STREAM_METADATA_IS_LAST_LEN; /**< == 1 (bit) */
  81712. extern FLAC_API const unsigned FLAC__STREAM_METADATA_TYPE_LEN; /**< == 7 (bits) */
  81713. extern FLAC_API const unsigned FLAC__STREAM_METADATA_LENGTH_LEN; /**< == 24 (bits) */
  81714. #define FLAC__STREAM_METADATA_HEADER_LENGTH (4u)
  81715. FLAC_API FLAC__bool FLAC__format_sample_rate_is_valid(unsigned sample_rate);
  81716. FLAC_API FLAC__bool FLAC__format_sample_rate_is_subset(unsigned sample_rate);
  81717. FLAC_API FLAC__bool FLAC__format_vorbiscomment_entry_name_is_legal(const char *name);
  81718. FLAC_API FLAC__bool FLAC__format_vorbiscomment_entry_value_is_legal(const FLAC__byte *value, unsigned length);
  81719. FLAC_API FLAC__bool FLAC__format_vorbiscomment_entry_is_legal(const FLAC__byte *entry, unsigned length);
  81720. FLAC_API FLAC__bool FLAC__format_seektable_is_legal(const FLAC__StreamMetadata_SeekTable *seek_table);
  81721. FLAC_API unsigned FLAC__format_seektable_sort(FLAC__StreamMetadata_SeekTable *seek_table);
  81722. FLAC_API FLAC__bool FLAC__format_cuesheet_is_legal(const FLAC__StreamMetadata_CueSheet *cue_sheet, FLAC__bool check_cd_da_subset, const char **violation);
  81723. FLAC_API FLAC__bool FLAC__format_picture_is_legal(const FLAC__StreamMetadata_Picture *picture, const char **violation);
  81724. #ifdef __cplusplus
  81725. }
  81726. #endif
  81727. #endif
  81728. /********* End of inlined file: format.h *********/
  81729. /********* Start of inlined file: metadata.h *********/
  81730. #ifndef FLAC__METADATA_H
  81731. #define FLAC__METADATA_H
  81732. #include <sys/types.h> /* for off_t */
  81733. #ifdef __cplusplus
  81734. extern "C" {
  81735. #endif
  81736. FLAC_API FLAC__bool FLAC__metadata_get_streaminfo(const char *filename, FLAC__StreamMetadata *streaminfo);
  81737. FLAC_API FLAC__bool FLAC__metadata_get_tags(const char *filename, FLAC__StreamMetadata **tags);
  81738. FLAC_API FLAC__bool FLAC__metadata_get_cuesheet(const char *filename, FLAC__StreamMetadata **cuesheet);
  81739. 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);
  81740. struct FLAC__Metadata_SimpleIterator;
  81741. typedef struct FLAC__Metadata_SimpleIterator FLAC__Metadata_SimpleIterator;
  81742. typedef enum {
  81743. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_OK = 0,
  81744. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_ILLEGAL_INPUT,
  81745. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_ERROR_OPENING_FILE,
  81746. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_NOT_A_FLAC_FILE,
  81747. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_NOT_WRITABLE,
  81748. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_BAD_METADATA,
  81749. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_READ_ERROR,
  81750. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_SEEK_ERROR,
  81751. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_WRITE_ERROR,
  81752. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_RENAME_ERROR,
  81753. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_UNLINK_ERROR,
  81754. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_MEMORY_ALLOCATION_ERROR,
  81755. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_INTERNAL_ERROR
  81756. } FLAC__Metadata_SimpleIteratorStatus;
  81757. extern FLAC_API const char * const FLAC__Metadata_SimpleIteratorStatusString[];
  81758. FLAC_API FLAC__Metadata_SimpleIterator *FLAC__metadata_simple_iterator_new(void);
  81759. FLAC_API void FLAC__metadata_simple_iterator_delete(FLAC__Metadata_SimpleIterator *iterator);
  81760. FLAC_API FLAC__Metadata_SimpleIteratorStatus FLAC__metadata_simple_iterator_status(FLAC__Metadata_SimpleIterator *iterator);
  81761. 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);
  81762. FLAC_API FLAC__bool FLAC__metadata_simple_iterator_is_writable(const FLAC__Metadata_SimpleIterator *iterator);
  81763. FLAC_API FLAC__bool FLAC__metadata_simple_iterator_next(FLAC__Metadata_SimpleIterator *iterator);
  81764. FLAC_API FLAC__bool FLAC__metadata_simple_iterator_prev(FLAC__Metadata_SimpleIterator *iterator);
  81765. FLAC_API FLAC__bool FLAC__metadata_simple_iterator_is_last(const FLAC__Metadata_SimpleIterator *iterator);
  81766. FLAC_API off_t FLAC__metadata_simple_iterator_get_block_offset(const FLAC__Metadata_SimpleIterator *iterator);
  81767. FLAC_API FLAC__MetadataType FLAC__metadata_simple_iterator_get_block_type(const FLAC__Metadata_SimpleIterator *iterator);
  81768. FLAC_API unsigned FLAC__metadata_simple_iterator_get_block_length(const FLAC__Metadata_SimpleIterator *iterator);
  81769. FLAC_API FLAC__bool FLAC__metadata_simple_iterator_get_application_id(FLAC__Metadata_SimpleIterator *iterator, FLAC__byte *id);
  81770. FLAC_API FLAC__StreamMetadata *FLAC__metadata_simple_iterator_get_block(FLAC__Metadata_SimpleIterator *iterator);
  81771. FLAC_API FLAC__bool FLAC__metadata_simple_iterator_set_block(FLAC__Metadata_SimpleIterator *iterator, FLAC__StreamMetadata *block, FLAC__bool use_padding);
  81772. FLAC_API FLAC__bool FLAC__metadata_simple_iterator_insert_block_after(FLAC__Metadata_SimpleIterator *iterator, FLAC__StreamMetadata *block, FLAC__bool use_padding);
  81773. FLAC_API FLAC__bool FLAC__metadata_simple_iterator_delete_block(FLAC__Metadata_SimpleIterator *iterator, FLAC__bool use_padding);
  81774. struct FLAC__Metadata_Chain;
  81775. typedef struct FLAC__Metadata_Chain FLAC__Metadata_Chain;
  81776. struct FLAC__Metadata_Iterator;
  81777. typedef struct FLAC__Metadata_Iterator FLAC__Metadata_Iterator;
  81778. typedef enum {
  81779. FLAC__METADATA_CHAIN_STATUS_OK = 0,
  81780. FLAC__METADATA_CHAIN_STATUS_ILLEGAL_INPUT,
  81781. FLAC__METADATA_CHAIN_STATUS_ERROR_OPENING_FILE,
  81782. FLAC__METADATA_CHAIN_STATUS_NOT_A_FLAC_FILE,
  81783. FLAC__METADATA_CHAIN_STATUS_NOT_WRITABLE,
  81784. FLAC__METADATA_CHAIN_STATUS_BAD_METADATA,
  81785. FLAC__METADATA_CHAIN_STATUS_READ_ERROR,
  81786. FLAC__METADATA_CHAIN_STATUS_SEEK_ERROR,
  81787. FLAC__METADATA_CHAIN_STATUS_WRITE_ERROR,
  81788. FLAC__METADATA_CHAIN_STATUS_RENAME_ERROR,
  81789. FLAC__METADATA_CHAIN_STATUS_UNLINK_ERROR,
  81790. FLAC__METADATA_CHAIN_STATUS_MEMORY_ALLOCATION_ERROR,
  81791. FLAC__METADATA_CHAIN_STATUS_INTERNAL_ERROR,
  81792. FLAC__METADATA_CHAIN_STATUS_INVALID_CALLBACKS,
  81793. FLAC__METADATA_CHAIN_STATUS_READ_WRITE_MISMATCH,
  81794. FLAC__METADATA_CHAIN_STATUS_WRONG_WRITE_CALL
  81795. } FLAC__Metadata_ChainStatus;
  81796. extern FLAC_API const char * const FLAC__Metadata_ChainStatusString[];
  81797. FLAC_API FLAC__Metadata_Chain *FLAC__metadata_chain_new(void);
  81798. FLAC_API void FLAC__metadata_chain_delete(FLAC__Metadata_Chain *chain);
  81799. FLAC_API FLAC__Metadata_ChainStatus FLAC__metadata_chain_status(FLAC__Metadata_Chain *chain);
  81800. FLAC_API FLAC__bool FLAC__metadata_chain_read(FLAC__Metadata_Chain *chain, const char *filename);
  81801. FLAC_API FLAC__bool FLAC__metadata_chain_read_ogg(FLAC__Metadata_Chain *chain, const char *filename);
  81802. FLAC_API FLAC__bool FLAC__metadata_chain_read_with_callbacks(FLAC__Metadata_Chain *chain, FLAC__IOHandle handle, FLAC__IOCallbacks callbacks);
  81803. FLAC_API FLAC__bool FLAC__metadata_chain_read_ogg_with_callbacks(FLAC__Metadata_Chain *chain, FLAC__IOHandle handle, FLAC__IOCallbacks callbacks);
  81804. FLAC_API FLAC__bool FLAC__metadata_chain_check_if_tempfile_needed(FLAC__Metadata_Chain *chain, FLAC__bool use_padding);
  81805. FLAC_API FLAC__bool FLAC__metadata_chain_write(FLAC__Metadata_Chain *chain, FLAC__bool use_padding, FLAC__bool preserve_file_stats);
  81806. FLAC_API FLAC__bool FLAC__metadata_chain_write_with_callbacks(FLAC__Metadata_Chain *chain, FLAC__bool use_padding, FLAC__IOHandle handle, FLAC__IOCallbacks callbacks);
  81807. 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);
  81808. FLAC_API void FLAC__metadata_chain_merge_padding(FLAC__Metadata_Chain *chain);
  81809. FLAC_API void FLAC__metadata_chain_sort_padding(FLAC__Metadata_Chain *chain);
  81810. FLAC_API FLAC__Metadata_Iterator *FLAC__metadata_iterator_new(void);
  81811. FLAC_API void FLAC__metadata_iterator_delete(FLAC__Metadata_Iterator *iterator);
  81812. FLAC_API void FLAC__metadata_iterator_init(FLAC__Metadata_Iterator *iterator, FLAC__Metadata_Chain *chain);
  81813. FLAC_API FLAC__bool FLAC__metadata_iterator_next(FLAC__Metadata_Iterator *iterator);
  81814. FLAC_API FLAC__bool FLAC__metadata_iterator_prev(FLAC__Metadata_Iterator *iterator);
  81815. FLAC_API FLAC__MetadataType FLAC__metadata_iterator_get_block_type(const FLAC__Metadata_Iterator *iterator);
  81816. FLAC_API FLAC__StreamMetadata *FLAC__metadata_iterator_get_block(FLAC__Metadata_Iterator *iterator);
  81817. FLAC_API FLAC__bool FLAC__metadata_iterator_set_block(FLAC__Metadata_Iterator *iterator, FLAC__StreamMetadata *block);
  81818. FLAC_API FLAC__bool FLAC__metadata_iterator_delete_block(FLAC__Metadata_Iterator *iterator, FLAC__bool replace_with_padding);
  81819. FLAC_API FLAC__bool FLAC__metadata_iterator_insert_block_before(FLAC__Metadata_Iterator *iterator, FLAC__StreamMetadata *block);
  81820. FLAC_API FLAC__bool FLAC__metadata_iterator_insert_block_after(FLAC__Metadata_Iterator *iterator, FLAC__StreamMetadata *block);
  81821. FLAC_API FLAC__StreamMetadata *FLAC__metadata_object_new(FLAC__MetadataType type);
  81822. FLAC_API FLAC__StreamMetadata *FLAC__metadata_object_clone(const FLAC__StreamMetadata *object);
  81823. FLAC_API void FLAC__metadata_object_delete(FLAC__StreamMetadata *object);
  81824. FLAC_API FLAC__bool FLAC__metadata_object_is_equal(const FLAC__StreamMetadata *block1, const FLAC__StreamMetadata *block2);
  81825. FLAC_API FLAC__bool FLAC__metadata_object_application_set_data(FLAC__StreamMetadata *object, FLAC__byte *data, unsigned length, FLAC__bool copy);
  81826. FLAC_API FLAC__bool FLAC__metadata_object_seektable_resize_points(FLAC__StreamMetadata *object, unsigned new_num_points);
  81827. FLAC_API void FLAC__metadata_object_seektable_set_point(FLAC__StreamMetadata *object, unsigned point_num, FLAC__StreamMetadata_SeekPoint point);
  81828. FLAC_API FLAC__bool FLAC__metadata_object_seektable_insert_point(FLAC__StreamMetadata *object, unsigned point_num, FLAC__StreamMetadata_SeekPoint point);
  81829. FLAC_API FLAC__bool FLAC__metadata_object_seektable_delete_point(FLAC__StreamMetadata *object, unsigned point_num);
  81830. FLAC_API FLAC__bool FLAC__metadata_object_seektable_is_legal(const FLAC__StreamMetadata *object);
  81831. FLAC_API FLAC__bool FLAC__metadata_object_seektable_template_append_placeholders(FLAC__StreamMetadata *object, unsigned num);
  81832. FLAC_API FLAC__bool FLAC__metadata_object_seektable_template_append_point(FLAC__StreamMetadata *object, FLAC__uint64 sample_number);
  81833. FLAC_API FLAC__bool FLAC__metadata_object_seektable_template_append_points(FLAC__StreamMetadata *object, FLAC__uint64 sample_numbers[], unsigned num);
  81834. FLAC_API FLAC__bool FLAC__metadata_object_seektable_template_append_spaced_points(FLAC__StreamMetadata *object, unsigned num, FLAC__uint64 total_samples);
  81835. FLAC_API FLAC__bool FLAC__metadata_object_seektable_template_append_spaced_points_by_samples(FLAC__StreamMetadata *object, unsigned samples, FLAC__uint64 total_samples);
  81836. FLAC_API FLAC__bool FLAC__metadata_object_seektable_template_sort(FLAC__StreamMetadata *object, FLAC__bool compact);
  81837. FLAC_API FLAC__bool FLAC__metadata_object_vorbiscomment_set_vendor_string(FLAC__StreamMetadata *object, FLAC__StreamMetadata_VorbisComment_Entry entry, FLAC__bool copy);
  81838. FLAC_API FLAC__bool FLAC__metadata_object_vorbiscomment_resize_comments(FLAC__StreamMetadata *object, unsigned new_num_comments);
  81839. FLAC_API FLAC__bool FLAC__metadata_object_vorbiscomment_set_comment(FLAC__StreamMetadata *object, unsigned comment_num, FLAC__StreamMetadata_VorbisComment_Entry entry, FLAC__bool copy);
  81840. FLAC_API FLAC__bool FLAC__metadata_object_vorbiscomment_insert_comment(FLAC__StreamMetadata *object, unsigned comment_num, FLAC__StreamMetadata_VorbisComment_Entry entry, FLAC__bool copy);
  81841. FLAC_API FLAC__bool FLAC__metadata_object_vorbiscomment_append_comment(FLAC__StreamMetadata *object, FLAC__StreamMetadata_VorbisComment_Entry entry, FLAC__bool copy);
  81842. FLAC_API FLAC__bool FLAC__metadata_object_vorbiscomment_replace_comment(FLAC__StreamMetadata *object, FLAC__StreamMetadata_VorbisComment_Entry entry, FLAC__bool all, FLAC__bool copy);
  81843. FLAC_API FLAC__bool FLAC__metadata_object_vorbiscomment_delete_comment(FLAC__StreamMetadata *object, unsigned comment_num);
  81844. 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);
  81845. 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);
  81846. FLAC_API FLAC__bool FLAC__metadata_object_vorbiscomment_entry_matches(const FLAC__StreamMetadata_VorbisComment_Entry entry, const char *field_name, unsigned field_name_length);
  81847. FLAC_API int FLAC__metadata_object_vorbiscomment_find_entry_from(const FLAC__StreamMetadata *object, unsigned offset, const char *field_name);
  81848. FLAC_API int FLAC__metadata_object_vorbiscomment_remove_entry_matching(FLAC__StreamMetadata *object, const char *field_name);
  81849. FLAC_API int FLAC__metadata_object_vorbiscomment_remove_entries_matching(FLAC__StreamMetadata *object, const char *field_name);
  81850. FLAC_API FLAC__StreamMetadata_CueSheet_Track *FLAC__metadata_object_cuesheet_track_new(void);
  81851. FLAC_API FLAC__StreamMetadata_CueSheet_Track *FLAC__metadata_object_cuesheet_track_clone(const FLAC__StreamMetadata_CueSheet_Track *object);
  81852. FLAC_API void FLAC__metadata_object_cuesheet_track_delete(FLAC__StreamMetadata_CueSheet_Track *object);
  81853. FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_track_resize_indices(FLAC__StreamMetadata *object, unsigned track_num, unsigned new_num_indices);
  81854. 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);
  81855. FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_track_insert_blank_index(FLAC__StreamMetadata *object, unsigned track_num, unsigned index_num);
  81856. FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_track_delete_index(FLAC__StreamMetadata *object, unsigned track_num, unsigned index_num);
  81857. FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_resize_tracks(FLAC__StreamMetadata *object, unsigned new_num_tracks);
  81858. FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_set_track(FLAC__StreamMetadata *object, unsigned track_num, FLAC__StreamMetadata_CueSheet_Track *track, FLAC__bool copy);
  81859. FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_insert_track(FLAC__StreamMetadata *object, unsigned track_num, FLAC__StreamMetadata_CueSheet_Track *track, FLAC__bool copy);
  81860. FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_insert_blank_track(FLAC__StreamMetadata *object, unsigned track_num);
  81861. FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_delete_track(FLAC__StreamMetadata *object, unsigned track_num);
  81862. FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_is_legal(const FLAC__StreamMetadata *object, FLAC__bool check_cd_da_subset, const char **violation);
  81863. FLAC_API FLAC__uint32 FLAC__metadata_object_cuesheet_calculate_cddb_id(const FLAC__StreamMetadata *object);
  81864. FLAC_API FLAC__bool FLAC__metadata_object_picture_set_mime_type(FLAC__StreamMetadata *object, char *mime_type, FLAC__bool copy);
  81865. FLAC_API FLAC__bool FLAC__metadata_object_picture_set_description(FLAC__StreamMetadata *object, FLAC__byte *description, FLAC__bool copy);
  81866. FLAC_API FLAC__bool FLAC__metadata_object_picture_set_data(FLAC__StreamMetadata *object, FLAC__byte *data, FLAC__uint32 length, FLAC__bool copy);
  81867. FLAC_API FLAC__bool FLAC__metadata_object_picture_is_legal(const FLAC__StreamMetadata *object, const char **violation);
  81868. #ifdef __cplusplus
  81869. }
  81870. #endif
  81871. #endif
  81872. /********* End of inlined file: metadata.h *********/
  81873. /********* Start of inlined file: stream_decoder.h *********/
  81874. #ifndef FLAC__STREAM_DECODER_H
  81875. #define FLAC__STREAM_DECODER_H
  81876. #include <stdio.h> /* for FILE */
  81877. #ifdef __cplusplus
  81878. extern "C" {
  81879. #endif
  81880. typedef enum {
  81881. FLAC__STREAM_DECODER_SEARCH_FOR_METADATA = 0,
  81882. FLAC__STREAM_DECODER_READ_METADATA,
  81883. FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC,
  81884. FLAC__STREAM_DECODER_READ_FRAME,
  81885. FLAC__STREAM_DECODER_END_OF_STREAM,
  81886. FLAC__STREAM_DECODER_OGG_ERROR,
  81887. FLAC__STREAM_DECODER_SEEK_ERROR,
  81888. FLAC__STREAM_DECODER_ABORTED,
  81889. FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR,
  81890. FLAC__STREAM_DECODER_UNINITIALIZED
  81891. } FLAC__StreamDecoderState;
  81892. extern FLAC_API const char * const FLAC__StreamDecoderStateString[];
  81893. typedef enum {
  81894. FLAC__STREAM_DECODER_INIT_STATUS_OK = 0,
  81895. FLAC__STREAM_DECODER_INIT_STATUS_UNSUPPORTED_CONTAINER,
  81896. FLAC__STREAM_DECODER_INIT_STATUS_INVALID_CALLBACKS,
  81897. FLAC__STREAM_DECODER_INIT_STATUS_MEMORY_ALLOCATION_ERROR,
  81898. FLAC__STREAM_DECODER_INIT_STATUS_ERROR_OPENING_FILE,
  81899. FLAC__STREAM_DECODER_INIT_STATUS_ALREADY_INITIALIZED
  81900. } FLAC__StreamDecoderInitStatus;
  81901. extern FLAC_API const char * const FLAC__StreamDecoderInitStatusString[];
  81902. typedef enum {
  81903. FLAC__STREAM_DECODER_READ_STATUS_CONTINUE,
  81904. FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM,
  81905. FLAC__STREAM_DECODER_READ_STATUS_ABORT
  81906. } FLAC__StreamDecoderReadStatus;
  81907. extern FLAC_API const char * const FLAC__StreamDecoderReadStatusString[];
  81908. typedef enum {
  81909. FLAC__STREAM_DECODER_SEEK_STATUS_OK,
  81910. FLAC__STREAM_DECODER_SEEK_STATUS_ERROR,
  81911. FLAC__STREAM_DECODER_SEEK_STATUS_UNSUPPORTED
  81912. } FLAC__StreamDecoderSeekStatus;
  81913. extern FLAC_API const char * const FLAC__StreamDecoderSeekStatusString[];
  81914. typedef enum {
  81915. FLAC__STREAM_DECODER_TELL_STATUS_OK,
  81916. FLAC__STREAM_DECODER_TELL_STATUS_ERROR,
  81917. FLAC__STREAM_DECODER_TELL_STATUS_UNSUPPORTED
  81918. } FLAC__StreamDecoderTellStatus;
  81919. extern FLAC_API const char * const FLAC__StreamDecoderTellStatusString[];
  81920. typedef enum {
  81921. FLAC__STREAM_DECODER_LENGTH_STATUS_OK,
  81922. FLAC__STREAM_DECODER_LENGTH_STATUS_ERROR,
  81923. FLAC__STREAM_DECODER_LENGTH_STATUS_UNSUPPORTED
  81924. } FLAC__StreamDecoderLengthStatus;
  81925. extern FLAC_API const char * const FLAC__StreamDecoderLengthStatusString[];
  81926. typedef enum {
  81927. FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE,
  81928. FLAC__STREAM_DECODER_WRITE_STATUS_ABORT
  81929. } FLAC__StreamDecoderWriteStatus;
  81930. extern FLAC_API const char * const FLAC__StreamDecoderWriteStatusString[];
  81931. typedef enum {
  81932. FLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC,
  81933. FLAC__STREAM_DECODER_ERROR_STATUS_BAD_HEADER,
  81934. FLAC__STREAM_DECODER_ERROR_STATUS_FRAME_CRC_MISMATCH,
  81935. FLAC__STREAM_DECODER_ERROR_STATUS_UNPARSEABLE_STREAM
  81936. } FLAC__StreamDecoderErrorStatus;
  81937. extern FLAC_API const char * const FLAC__StreamDecoderErrorStatusString[];
  81938. struct FLAC__StreamDecoderProtected;
  81939. struct FLAC__StreamDecoderPrivate;
  81940. typedef struct {
  81941. struct FLAC__StreamDecoderProtected *protected_; /* avoid the C++ keyword 'protected' */
  81942. struct FLAC__StreamDecoderPrivate *private_; /* avoid the C++ keyword 'private' */
  81943. } FLAC__StreamDecoder;
  81944. typedef FLAC__StreamDecoderReadStatus (*FLAC__StreamDecoderReadCallback)(const FLAC__StreamDecoder *decoder, FLAC__byte buffer[], size_t *bytes, void *client_data);
  81945. typedef FLAC__StreamDecoderSeekStatus (*FLAC__StreamDecoderSeekCallback)(const FLAC__StreamDecoder *decoder, FLAC__uint64 absolute_byte_offset, void *client_data);
  81946. typedef FLAC__StreamDecoderTellStatus (*FLAC__StreamDecoderTellCallback)(const FLAC__StreamDecoder *decoder, FLAC__uint64 *absolute_byte_offset, void *client_data);
  81947. typedef FLAC__StreamDecoderLengthStatus (*FLAC__StreamDecoderLengthCallback)(const FLAC__StreamDecoder *decoder, FLAC__uint64 *stream_length, void *client_data);
  81948. typedef FLAC__bool (*FLAC__StreamDecoderEofCallback)(const FLAC__StreamDecoder *decoder, void *client_data);
  81949. typedef FLAC__StreamDecoderWriteStatus (*FLAC__StreamDecoderWriteCallback)(const FLAC__StreamDecoder *decoder, const FLAC__Frame *frame, const FLAC__int32 * const buffer[], void *client_data);
  81950. typedef void (*FLAC__StreamDecoderMetadataCallback)(const FLAC__StreamDecoder *decoder, const FLAC__StreamMetadata *metadata, void *client_data);
  81951. typedef void (*FLAC__StreamDecoderErrorCallback)(const FLAC__StreamDecoder *decoder, FLAC__StreamDecoderErrorStatus status, void *client_data);
  81952. FLAC_API FLAC__StreamDecoder *FLAC__stream_decoder_new(void);
  81953. FLAC_API void FLAC__stream_decoder_delete(FLAC__StreamDecoder *decoder);
  81954. FLAC_API FLAC__bool FLAC__stream_decoder_set_ogg_serial_number(FLAC__StreamDecoder *decoder, long serial_number);
  81955. FLAC_API FLAC__bool FLAC__stream_decoder_set_md5_checking(FLAC__StreamDecoder *decoder, FLAC__bool value);
  81956. FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_respond(FLAC__StreamDecoder *decoder, FLAC__MetadataType type);
  81957. FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_respond_application(FLAC__StreamDecoder *decoder, const FLAC__byte id[4]);
  81958. FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_respond_all(FLAC__StreamDecoder *decoder);
  81959. FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_ignore(FLAC__StreamDecoder *decoder, FLAC__MetadataType type);
  81960. FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_ignore_application(FLAC__StreamDecoder *decoder, const FLAC__byte id[4]);
  81961. FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_ignore_all(FLAC__StreamDecoder *decoder);
  81962. FLAC_API FLAC__StreamDecoderState FLAC__stream_decoder_get_state(const FLAC__StreamDecoder *decoder);
  81963. FLAC_API const char *FLAC__stream_decoder_get_resolved_state_string(const FLAC__StreamDecoder *decoder);
  81964. FLAC_API FLAC__bool FLAC__stream_decoder_get_md5_checking(const FLAC__StreamDecoder *decoder);
  81965. FLAC_API FLAC__uint64 FLAC__stream_decoder_get_total_samples(const FLAC__StreamDecoder *decoder);
  81966. FLAC_API unsigned FLAC__stream_decoder_get_channels(const FLAC__StreamDecoder *decoder);
  81967. FLAC_API FLAC__ChannelAssignment FLAC__stream_decoder_get_channel_assignment(const FLAC__StreamDecoder *decoder);
  81968. FLAC_API unsigned FLAC__stream_decoder_get_bits_per_sample(const FLAC__StreamDecoder *decoder);
  81969. FLAC_API unsigned FLAC__stream_decoder_get_sample_rate(const FLAC__StreamDecoder *decoder);
  81970. FLAC_API unsigned FLAC__stream_decoder_get_blocksize(const FLAC__StreamDecoder *decoder);
  81971. FLAC_API FLAC__bool FLAC__stream_decoder_get_decode_position(const FLAC__StreamDecoder *decoder, FLAC__uint64 *position);
  81972. FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_stream(
  81973. FLAC__StreamDecoder *decoder,
  81974. FLAC__StreamDecoderReadCallback read_callback,
  81975. FLAC__StreamDecoderSeekCallback seek_callback,
  81976. FLAC__StreamDecoderTellCallback tell_callback,
  81977. FLAC__StreamDecoderLengthCallback length_callback,
  81978. FLAC__StreamDecoderEofCallback eof_callback,
  81979. FLAC__StreamDecoderWriteCallback write_callback,
  81980. FLAC__StreamDecoderMetadataCallback metadata_callback,
  81981. FLAC__StreamDecoderErrorCallback error_callback,
  81982. void *client_data
  81983. );
  81984. FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_ogg_stream(
  81985. FLAC__StreamDecoder *decoder,
  81986. FLAC__StreamDecoderReadCallback read_callback,
  81987. FLAC__StreamDecoderSeekCallback seek_callback,
  81988. FLAC__StreamDecoderTellCallback tell_callback,
  81989. FLAC__StreamDecoderLengthCallback length_callback,
  81990. FLAC__StreamDecoderEofCallback eof_callback,
  81991. FLAC__StreamDecoderWriteCallback write_callback,
  81992. FLAC__StreamDecoderMetadataCallback metadata_callback,
  81993. FLAC__StreamDecoderErrorCallback error_callback,
  81994. void *client_data
  81995. );
  81996. FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_FILE(
  81997. FLAC__StreamDecoder *decoder,
  81998. FILE *file,
  81999. FLAC__StreamDecoderWriteCallback write_callback,
  82000. FLAC__StreamDecoderMetadataCallback metadata_callback,
  82001. FLAC__StreamDecoderErrorCallback error_callback,
  82002. void *client_data
  82003. );
  82004. FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_ogg_FILE(
  82005. FLAC__StreamDecoder *decoder,
  82006. FILE *file,
  82007. FLAC__StreamDecoderWriteCallback write_callback,
  82008. FLAC__StreamDecoderMetadataCallback metadata_callback,
  82009. FLAC__StreamDecoderErrorCallback error_callback,
  82010. void *client_data
  82011. );
  82012. FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_file(
  82013. FLAC__StreamDecoder *decoder,
  82014. const char *filename,
  82015. FLAC__StreamDecoderWriteCallback write_callback,
  82016. FLAC__StreamDecoderMetadataCallback metadata_callback,
  82017. FLAC__StreamDecoderErrorCallback error_callback,
  82018. void *client_data
  82019. );
  82020. FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_ogg_file(
  82021. FLAC__StreamDecoder *decoder,
  82022. const char *filename,
  82023. FLAC__StreamDecoderWriteCallback write_callback,
  82024. FLAC__StreamDecoderMetadataCallback metadata_callback,
  82025. FLAC__StreamDecoderErrorCallback error_callback,
  82026. void *client_data
  82027. );
  82028. FLAC_API FLAC__bool FLAC__stream_decoder_finish(FLAC__StreamDecoder *decoder);
  82029. FLAC_API FLAC__bool FLAC__stream_decoder_flush(FLAC__StreamDecoder *decoder);
  82030. FLAC_API FLAC__bool FLAC__stream_decoder_reset(FLAC__StreamDecoder *decoder);
  82031. FLAC_API FLAC__bool FLAC__stream_decoder_process_single(FLAC__StreamDecoder *decoder);
  82032. FLAC_API FLAC__bool FLAC__stream_decoder_process_until_end_of_metadata(FLAC__StreamDecoder *decoder);
  82033. FLAC_API FLAC__bool FLAC__stream_decoder_process_until_end_of_stream(FLAC__StreamDecoder *decoder);
  82034. FLAC_API FLAC__bool FLAC__stream_decoder_skip_single_frame(FLAC__StreamDecoder *decoder);
  82035. FLAC_API FLAC__bool FLAC__stream_decoder_seek_absolute(FLAC__StreamDecoder *decoder, FLAC__uint64 sample);
  82036. #ifdef __cplusplus
  82037. }
  82038. #endif
  82039. #endif
  82040. /********* End of inlined file: stream_decoder.h *********/
  82041. /********* Start of inlined file: stream_encoder.h *********/
  82042. #ifndef FLAC__STREAM_ENCODER_H
  82043. #define FLAC__STREAM_ENCODER_H
  82044. #include <stdio.h> /* for FILE */
  82045. #ifdef __cplusplus
  82046. extern "C" {
  82047. #endif
  82048. typedef enum {
  82049. FLAC__STREAM_ENCODER_OK = 0,
  82050. FLAC__STREAM_ENCODER_UNINITIALIZED,
  82051. FLAC__STREAM_ENCODER_OGG_ERROR,
  82052. FLAC__STREAM_ENCODER_VERIFY_DECODER_ERROR,
  82053. FLAC__STREAM_ENCODER_VERIFY_MISMATCH_IN_AUDIO_DATA,
  82054. FLAC__STREAM_ENCODER_CLIENT_ERROR,
  82055. FLAC__STREAM_ENCODER_IO_ERROR,
  82056. FLAC__STREAM_ENCODER_FRAMING_ERROR,
  82057. FLAC__STREAM_ENCODER_MEMORY_ALLOCATION_ERROR
  82058. } FLAC__StreamEncoderState;
  82059. extern FLAC_API const char * const FLAC__StreamEncoderStateString[];
  82060. typedef enum {
  82061. FLAC__STREAM_ENCODER_INIT_STATUS_OK = 0,
  82062. FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR,
  82063. FLAC__STREAM_ENCODER_INIT_STATUS_UNSUPPORTED_CONTAINER,
  82064. FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_CALLBACKS,
  82065. FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_NUMBER_OF_CHANNELS,
  82066. FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_BITS_PER_SAMPLE,
  82067. FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_SAMPLE_RATE,
  82068. FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_BLOCK_SIZE,
  82069. FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_MAX_LPC_ORDER,
  82070. FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_QLP_COEFF_PRECISION,
  82071. FLAC__STREAM_ENCODER_INIT_STATUS_BLOCK_SIZE_TOO_SMALL_FOR_LPC_ORDER,
  82072. FLAC__STREAM_ENCODER_INIT_STATUS_NOT_STREAMABLE,
  82073. FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA,
  82074. FLAC__STREAM_ENCODER_INIT_STATUS_ALREADY_INITIALIZED
  82075. } FLAC__StreamEncoderInitStatus;
  82076. extern FLAC_API const char * const FLAC__StreamEncoderInitStatusString[];
  82077. typedef enum {
  82078. FLAC__STREAM_ENCODER_READ_STATUS_CONTINUE,
  82079. FLAC__STREAM_ENCODER_READ_STATUS_END_OF_STREAM,
  82080. FLAC__STREAM_ENCODER_READ_STATUS_ABORT,
  82081. FLAC__STREAM_ENCODER_READ_STATUS_UNSUPPORTED
  82082. } FLAC__StreamEncoderReadStatus;
  82083. extern FLAC_API const char * const FLAC__StreamEncoderReadStatusString[];
  82084. typedef enum {
  82085. FLAC__STREAM_ENCODER_WRITE_STATUS_OK = 0,
  82086. FLAC__STREAM_ENCODER_WRITE_STATUS_FATAL_ERROR
  82087. } FLAC__StreamEncoderWriteStatus;
  82088. extern FLAC_API const char * const FLAC__StreamEncoderWriteStatusString[];
  82089. typedef enum {
  82090. FLAC__STREAM_ENCODER_SEEK_STATUS_OK,
  82091. FLAC__STREAM_ENCODER_SEEK_STATUS_ERROR,
  82092. FLAC__STREAM_ENCODER_SEEK_STATUS_UNSUPPORTED
  82093. } FLAC__StreamEncoderSeekStatus;
  82094. extern FLAC_API const char * const FLAC__StreamEncoderSeekStatusString[];
  82095. typedef enum {
  82096. FLAC__STREAM_ENCODER_TELL_STATUS_OK,
  82097. FLAC__STREAM_ENCODER_TELL_STATUS_ERROR,
  82098. FLAC__STREAM_ENCODER_TELL_STATUS_UNSUPPORTED
  82099. } FLAC__StreamEncoderTellStatus;
  82100. extern FLAC_API const char * const FLAC__StreamEncoderTellStatusString[];
  82101. struct FLAC__StreamEncoderProtected;
  82102. struct FLAC__StreamEncoderPrivate;
  82103. typedef struct {
  82104. struct FLAC__StreamEncoderProtected *protected_; /* avoid the C++ keyword 'protected' */
  82105. struct FLAC__StreamEncoderPrivate *private_; /* avoid the C++ keyword 'private' */
  82106. } FLAC__StreamEncoder;
  82107. typedef FLAC__StreamEncoderReadStatus (*FLAC__StreamEncoderReadCallback)(const FLAC__StreamEncoder *encoder, FLAC__byte buffer[], size_t *bytes, void *client_data);
  82108. typedef FLAC__StreamEncoderWriteStatus (*FLAC__StreamEncoderWriteCallback)(const FLAC__StreamEncoder *encoder, const FLAC__byte buffer[], size_t bytes, unsigned samples, unsigned current_frame, void *client_data);
  82109. typedef FLAC__StreamEncoderSeekStatus (*FLAC__StreamEncoderSeekCallback)(const FLAC__StreamEncoder *encoder, FLAC__uint64 absolute_byte_offset, void *client_data);
  82110. typedef FLAC__StreamEncoderTellStatus (*FLAC__StreamEncoderTellCallback)(const FLAC__StreamEncoder *encoder, FLAC__uint64 *absolute_byte_offset, void *client_data);
  82111. typedef void (*FLAC__StreamEncoderMetadataCallback)(const FLAC__StreamEncoder *encoder, const FLAC__StreamMetadata *metadata, void *client_data);
  82112. 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);
  82113. FLAC_API FLAC__StreamEncoder *FLAC__stream_encoder_new(void);
  82114. FLAC_API void FLAC__stream_encoder_delete(FLAC__StreamEncoder *encoder);
  82115. FLAC_API FLAC__bool FLAC__stream_encoder_set_ogg_serial_number(FLAC__StreamEncoder *encoder, long serial_number);
  82116. FLAC_API FLAC__bool FLAC__stream_encoder_set_verify(FLAC__StreamEncoder *encoder, FLAC__bool value);
  82117. FLAC_API FLAC__bool FLAC__stream_encoder_set_streamable_subset(FLAC__StreamEncoder *encoder, FLAC__bool value);
  82118. FLAC_API FLAC__bool FLAC__stream_encoder_set_channels(FLAC__StreamEncoder *encoder, unsigned value);
  82119. FLAC_API FLAC__bool FLAC__stream_encoder_set_bits_per_sample(FLAC__StreamEncoder *encoder, unsigned value);
  82120. FLAC_API FLAC__bool FLAC__stream_encoder_set_sample_rate(FLAC__StreamEncoder *encoder, unsigned value);
  82121. FLAC_API FLAC__bool FLAC__stream_encoder_set_compression_level(FLAC__StreamEncoder *encoder, unsigned value);
  82122. FLAC_API FLAC__bool FLAC__stream_encoder_set_blocksize(FLAC__StreamEncoder *encoder, unsigned value);
  82123. FLAC_API FLAC__bool FLAC__stream_encoder_set_do_mid_side_stereo(FLAC__StreamEncoder *encoder, FLAC__bool value);
  82124. FLAC_API FLAC__bool FLAC__stream_encoder_set_loose_mid_side_stereo(FLAC__StreamEncoder *encoder, FLAC__bool value);
  82125. FLAC_API FLAC__bool FLAC__stream_encoder_set_apodization(FLAC__StreamEncoder *encoder, const char *specification);
  82126. FLAC_API FLAC__bool FLAC__stream_encoder_set_max_lpc_order(FLAC__StreamEncoder *encoder, unsigned value);
  82127. FLAC_API FLAC__bool FLAC__stream_encoder_set_qlp_coeff_precision(FLAC__StreamEncoder *encoder, unsigned value);
  82128. FLAC_API FLAC__bool FLAC__stream_encoder_set_do_qlp_coeff_prec_search(FLAC__StreamEncoder *encoder, FLAC__bool value);
  82129. FLAC_API FLAC__bool FLAC__stream_encoder_set_do_escape_coding(FLAC__StreamEncoder *encoder, FLAC__bool value);
  82130. FLAC_API FLAC__bool FLAC__stream_encoder_set_do_exhaustive_model_search(FLAC__StreamEncoder *encoder, FLAC__bool value);
  82131. FLAC_API FLAC__bool FLAC__stream_encoder_set_min_residual_partition_order(FLAC__StreamEncoder *encoder, unsigned value);
  82132. FLAC_API FLAC__bool FLAC__stream_encoder_set_max_residual_partition_order(FLAC__StreamEncoder *encoder, unsigned value);
  82133. FLAC_API FLAC__bool FLAC__stream_encoder_set_rice_parameter_search_dist(FLAC__StreamEncoder *encoder, unsigned value);
  82134. FLAC_API FLAC__bool FLAC__stream_encoder_set_total_samples_estimate(FLAC__StreamEncoder *encoder, FLAC__uint64 value);
  82135. FLAC_API FLAC__bool FLAC__stream_encoder_set_metadata(FLAC__StreamEncoder *encoder, FLAC__StreamMetadata **metadata, unsigned num_blocks);
  82136. FLAC_API FLAC__StreamEncoderState FLAC__stream_encoder_get_state(const FLAC__StreamEncoder *encoder);
  82137. FLAC_API FLAC__StreamDecoderState FLAC__stream_encoder_get_verify_decoder_state(const FLAC__StreamEncoder *encoder);
  82138. FLAC_API const char *FLAC__stream_encoder_get_resolved_state_string(const FLAC__StreamEncoder *encoder);
  82139. 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);
  82140. FLAC_API FLAC__bool FLAC__stream_encoder_get_verify(const FLAC__StreamEncoder *encoder);
  82141. FLAC_API FLAC__bool FLAC__stream_encoder_get_streamable_subset(const FLAC__StreamEncoder *encoder);
  82142. FLAC_API unsigned FLAC__stream_encoder_get_channels(const FLAC__StreamEncoder *encoder);
  82143. FLAC_API unsigned FLAC__stream_encoder_get_bits_per_sample(const FLAC__StreamEncoder *encoder);
  82144. FLAC_API unsigned FLAC__stream_encoder_get_sample_rate(const FLAC__StreamEncoder *encoder);
  82145. FLAC_API unsigned FLAC__stream_encoder_get_blocksize(const FLAC__StreamEncoder *encoder);
  82146. FLAC_API FLAC__bool FLAC__stream_encoder_get_do_mid_side_stereo(const FLAC__StreamEncoder *encoder);
  82147. FLAC_API FLAC__bool FLAC__stream_encoder_get_loose_mid_side_stereo(const FLAC__StreamEncoder *encoder);
  82148. FLAC_API unsigned FLAC__stream_encoder_get_max_lpc_order(const FLAC__StreamEncoder *encoder);
  82149. FLAC_API unsigned FLAC__stream_encoder_get_qlp_coeff_precision(const FLAC__StreamEncoder *encoder);
  82150. FLAC_API FLAC__bool FLAC__stream_encoder_get_do_qlp_coeff_prec_search(const FLAC__StreamEncoder *encoder);
  82151. FLAC_API FLAC__bool FLAC__stream_encoder_get_do_escape_coding(const FLAC__StreamEncoder *encoder);
  82152. FLAC_API FLAC__bool FLAC__stream_encoder_get_do_exhaustive_model_search(const FLAC__StreamEncoder *encoder);
  82153. FLAC_API unsigned FLAC__stream_encoder_get_min_residual_partition_order(const FLAC__StreamEncoder *encoder);
  82154. FLAC_API unsigned FLAC__stream_encoder_get_max_residual_partition_order(const FLAC__StreamEncoder *encoder);
  82155. FLAC_API unsigned FLAC__stream_encoder_get_rice_parameter_search_dist(const FLAC__StreamEncoder *encoder);
  82156. FLAC_API FLAC__uint64 FLAC__stream_encoder_get_total_samples_estimate(const FLAC__StreamEncoder *encoder);
  82157. 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);
  82158. 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);
  82159. FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_FILE(FLAC__StreamEncoder *encoder, FILE *file, FLAC__StreamEncoderProgressCallback progress_callback, void *client_data);
  82160. FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_ogg_FILE(FLAC__StreamEncoder *encoder, FILE *file, FLAC__StreamEncoderProgressCallback progress_callback, void *client_data);
  82161. FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_file(FLAC__StreamEncoder *encoder, const char *filename, FLAC__StreamEncoderProgressCallback progress_callback, void *client_data);
  82162. FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_ogg_file(FLAC__StreamEncoder *encoder, const char *filename, FLAC__StreamEncoderProgressCallback progress_callback, void *client_data);
  82163. FLAC_API FLAC__bool FLAC__stream_encoder_finish(FLAC__StreamEncoder *encoder);
  82164. FLAC_API FLAC__bool FLAC__stream_encoder_process(FLAC__StreamEncoder *encoder, const FLAC__int32 * const buffer[], unsigned samples);
  82165. FLAC_API FLAC__bool FLAC__stream_encoder_process_interleaved(FLAC__StreamEncoder *encoder, const FLAC__int32 buffer[], unsigned samples);
  82166. #ifdef __cplusplus
  82167. }
  82168. #endif
  82169. #endif
  82170. /********* End of inlined file: stream_encoder.h *********/
  82171. #ifdef _MSC_VER
  82172. static _inline FLAC__uint32 local_swap32_(FLAC__uint32 x)
  82173. {
  82174. x = ((x<<8)&0xFF00FF00) | ((x>>8)&0x00FF00FF);
  82175. return (x>>16) | (x<<16);
  82176. }
  82177. #endif
  82178. #if defined(_MSC_VER) && defined(_X86_)
  82179. static void local_swap32_block_(FLAC__uint32 *start, FLAC__uint32 len)
  82180. {
  82181. __asm {
  82182. mov edx, start
  82183. mov ecx, len
  82184. test ecx, ecx
  82185. loop1:
  82186. jz done1
  82187. mov eax, [edx]
  82188. bswap eax
  82189. mov [edx], eax
  82190. add edx, 4
  82191. dec ecx
  82192. jmp short loop1
  82193. done1:
  82194. }
  82195. }
  82196. #endif
  82197. #endif
  82198. /********* End of inlined file: all.h *********/
  82199. /********* Start of inlined file: bitmath.c *********/
  82200. /********* Start of inlined file: juce_FlacHeader.h *********/
  82201. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  82202. // tasks..
  82203. #define VERSION "1.2.1"
  82204. #define FLAC__NO_DLL 1
  82205. #if JUCE_MSVC
  82206. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  82207. #endif
  82208. #if JUCE_MAC
  82209. #define FLAC__SYS_DARWIN 1
  82210. #endif
  82211. /********* End of inlined file: juce_FlacHeader.h *********/
  82212. #if JUCE_USE_FLAC
  82213. #if HAVE_CONFIG_H
  82214. # include <config.h>
  82215. #endif
  82216. /********* Start of inlined file: bitmath.h *********/
  82217. #ifndef FLAC__PRIVATE__BITMATH_H
  82218. #define FLAC__PRIVATE__BITMATH_H
  82219. unsigned FLAC__bitmath_ilog2(FLAC__uint32 v);
  82220. unsigned FLAC__bitmath_ilog2_wide(FLAC__uint64 v);
  82221. unsigned FLAC__bitmath_silog2(int v);
  82222. unsigned FLAC__bitmath_silog2_wide(FLAC__int64 v);
  82223. #endif
  82224. /********* End of inlined file: bitmath.h *********/
  82225. unsigned FLAC__bitmath_ilog2(FLAC__uint32 v)
  82226. {
  82227. unsigned l = 0;
  82228. FLAC__ASSERT(v > 0);
  82229. while(v >>= 1)
  82230. l++;
  82231. return l;
  82232. }
  82233. unsigned FLAC__bitmath_ilog2_wide(FLAC__uint64 v)
  82234. {
  82235. unsigned l = 0;
  82236. FLAC__ASSERT(v > 0);
  82237. while(v >>= 1)
  82238. l++;
  82239. return l;
  82240. }
  82241. unsigned FLAC__bitmath_silog2(int v)
  82242. {
  82243. while(1) {
  82244. if(v == 0) {
  82245. return 0;
  82246. }
  82247. else if(v > 0) {
  82248. unsigned l = 0;
  82249. while(v) {
  82250. l++;
  82251. v >>= 1;
  82252. }
  82253. return l+1;
  82254. }
  82255. else if(v == -1) {
  82256. return 2;
  82257. }
  82258. else {
  82259. v++;
  82260. v = -v;
  82261. }
  82262. }
  82263. }
  82264. unsigned FLAC__bitmath_silog2_wide(FLAC__int64 v)
  82265. {
  82266. while(1) {
  82267. if(v == 0) {
  82268. return 0;
  82269. }
  82270. else if(v > 0) {
  82271. unsigned l = 0;
  82272. while(v) {
  82273. l++;
  82274. v >>= 1;
  82275. }
  82276. return l+1;
  82277. }
  82278. else if(v == -1) {
  82279. return 2;
  82280. }
  82281. else {
  82282. v++;
  82283. v = -v;
  82284. }
  82285. }
  82286. }
  82287. #endif
  82288. /********* End of inlined file: bitmath.c *********/
  82289. /********* Start of inlined file: bitreader.c *********/
  82290. /********* Start of inlined file: juce_FlacHeader.h *********/
  82291. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  82292. // tasks..
  82293. #define VERSION "1.2.1"
  82294. #define FLAC__NO_DLL 1
  82295. #if JUCE_MSVC
  82296. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  82297. #endif
  82298. #if JUCE_MAC
  82299. #define FLAC__SYS_DARWIN 1
  82300. #endif
  82301. /********* End of inlined file: juce_FlacHeader.h *********/
  82302. #if JUCE_USE_FLAC
  82303. #if HAVE_CONFIG_H
  82304. # include <config.h>
  82305. #endif
  82306. #include <stdlib.h> /* for malloc() */
  82307. #include <string.h> /* for memcpy(), memset() */
  82308. #ifdef _MSC_VER
  82309. #include <winsock.h> /* for ntohl() */
  82310. #elif defined FLAC__SYS_DARWIN
  82311. #include <machine/endian.h> /* for ntohl() */
  82312. #elif defined __MINGW32__
  82313. #include <winsock.h> /* for ntohl() */
  82314. #else
  82315. #include <netinet/in.h> /* for ntohl() */
  82316. #endif
  82317. /********* Start of inlined file: bitreader.h *********/
  82318. #ifndef FLAC__PRIVATE__BITREADER_H
  82319. #define FLAC__PRIVATE__BITREADER_H
  82320. #include <stdio.h> /* for FILE */
  82321. /********* Start of inlined file: cpu.h *********/
  82322. #ifndef FLAC__PRIVATE__CPU_H
  82323. #define FLAC__PRIVATE__CPU_H
  82324. #ifdef HAVE_CONFIG_H
  82325. #include <config.h>
  82326. #endif
  82327. typedef enum {
  82328. FLAC__CPUINFO_TYPE_IA32,
  82329. FLAC__CPUINFO_TYPE_PPC,
  82330. FLAC__CPUINFO_TYPE_UNKNOWN
  82331. } FLAC__CPUInfo_Type;
  82332. typedef struct {
  82333. FLAC__bool cpuid;
  82334. FLAC__bool bswap;
  82335. FLAC__bool cmov;
  82336. FLAC__bool mmx;
  82337. FLAC__bool fxsr;
  82338. FLAC__bool sse;
  82339. FLAC__bool sse2;
  82340. FLAC__bool sse3;
  82341. FLAC__bool ssse3;
  82342. FLAC__bool _3dnow;
  82343. FLAC__bool ext3dnow;
  82344. FLAC__bool extmmx;
  82345. } FLAC__CPUInfo_IA32;
  82346. typedef struct {
  82347. FLAC__bool altivec;
  82348. FLAC__bool ppc64;
  82349. } FLAC__CPUInfo_PPC;
  82350. typedef struct {
  82351. FLAC__bool use_asm;
  82352. FLAC__CPUInfo_Type type;
  82353. union {
  82354. FLAC__CPUInfo_IA32 ia32;
  82355. FLAC__CPUInfo_PPC ppc;
  82356. } data;
  82357. } FLAC__CPUInfo;
  82358. void FLAC__cpu_info(FLAC__CPUInfo *info);
  82359. #ifndef FLAC__NO_ASM
  82360. #ifdef FLAC__CPU_IA32
  82361. #ifdef FLAC__HAS_NASM
  82362. FLAC__uint32 FLAC__cpu_have_cpuid_asm_ia32(void);
  82363. void FLAC__cpu_info_asm_ia32(FLAC__uint32 *flags_edx, FLAC__uint32 *flags_ecx);
  82364. FLAC__uint32 FLAC__cpu_info_extended_amd_asm_ia32(void);
  82365. #endif
  82366. #endif
  82367. #endif
  82368. #endif
  82369. /********* End of inlined file: cpu.h *********/
  82370. struct FLAC__BitReader;
  82371. typedef struct FLAC__BitReader FLAC__BitReader;
  82372. typedef FLAC__bool (*FLAC__BitReaderReadCallback)(FLAC__byte buffer[], size_t *bytes, void *client_data);
  82373. FLAC__BitReader *FLAC__bitreader_new(void);
  82374. void FLAC__bitreader_delete(FLAC__BitReader *br);
  82375. FLAC__bool FLAC__bitreader_init(FLAC__BitReader *br, FLAC__CPUInfo cpu, FLAC__BitReaderReadCallback rcb, void *cd);
  82376. void FLAC__bitreader_free(FLAC__BitReader *br); /* does not 'free(br)' */
  82377. FLAC__bool FLAC__bitreader_clear(FLAC__BitReader *br);
  82378. void FLAC__bitreader_dump(const FLAC__BitReader *br, FILE *out);
  82379. void FLAC__bitreader_reset_read_crc16(FLAC__BitReader *br, FLAC__uint16 seed);
  82380. FLAC__uint16 FLAC__bitreader_get_read_crc16(FLAC__BitReader *br);
  82381. FLAC__bool FLAC__bitreader_is_consumed_byte_aligned(const FLAC__BitReader *br);
  82382. unsigned FLAC__bitreader_bits_left_for_byte_alignment(const FLAC__BitReader *br);
  82383. unsigned FLAC__bitreader_get_input_bits_unconsumed(const FLAC__BitReader *br);
  82384. FLAC__bool FLAC__bitreader_read_raw_uint32(FLAC__BitReader *br, FLAC__uint32 *val, unsigned bits);
  82385. FLAC__bool FLAC__bitreader_read_raw_int32(FLAC__BitReader *br, FLAC__int32 *val, unsigned bits);
  82386. FLAC__bool FLAC__bitreader_read_raw_uint64(FLAC__BitReader *br, FLAC__uint64 *val, unsigned bits);
  82387. FLAC__bool FLAC__bitreader_read_uint32_little_endian(FLAC__BitReader *br, FLAC__uint32 *val); /*only for bits=32*/
  82388. FLAC__bool FLAC__bitreader_skip_bits_no_crc(FLAC__BitReader *br, unsigned bits); /* WATCHOUT: does not CRC the skipped data! */ /*@@@@ add to unit tests */
  82389. FLAC__bool FLAC__bitreader_skip_byte_block_aligned_no_crc(FLAC__BitReader *br, unsigned nvals); /* WATCHOUT: does not CRC the read data! */
  82390. 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! */
  82391. FLAC__bool FLAC__bitreader_read_unary_unsigned(FLAC__BitReader *br, unsigned *val);
  82392. FLAC__bool FLAC__bitreader_read_rice_signed(FLAC__BitReader *br, int *val, unsigned parameter);
  82393. FLAC__bool FLAC__bitreader_read_rice_signed_block(FLAC__BitReader *br, int vals[], unsigned nvals, unsigned parameter);
  82394. #ifndef FLAC__NO_ASM
  82395. # ifdef FLAC__CPU_IA32
  82396. # ifdef FLAC__HAS_NASM
  82397. FLAC__bool FLAC__bitreader_read_rice_signed_block_asm_ia32_bswap(FLAC__BitReader *br, int vals[], unsigned nvals, unsigned parameter);
  82398. # endif
  82399. # endif
  82400. #endif
  82401. #if 0 /* UNUSED */
  82402. FLAC__bool FLAC__bitreader_read_golomb_signed(FLAC__BitReader *br, int *val, unsigned parameter);
  82403. FLAC__bool FLAC__bitreader_read_golomb_unsigned(FLAC__BitReader *br, unsigned *val, unsigned parameter);
  82404. #endif
  82405. FLAC__bool FLAC__bitreader_read_utf8_uint32(FLAC__BitReader *br, FLAC__uint32 *val, FLAC__byte *raw, unsigned *rawlen);
  82406. FLAC__bool FLAC__bitreader_read_utf8_uint64(FLAC__BitReader *br, FLAC__uint64 *val, FLAC__byte *raw, unsigned *rawlen);
  82407. FLAC__bool bitreader_read_from_client_(FLAC__BitReader *br);
  82408. #endif
  82409. /********* End of inlined file: bitreader.h *********/
  82410. /********* Start of inlined file: crc.h *********/
  82411. #ifndef FLAC__PRIVATE__CRC_H
  82412. #define FLAC__PRIVATE__CRC_H
  82413. extern FLAC__byte const FLAC__crc8_table[256];
  82414. #define FLAC__CRC8_UPDATE(data, crc) (crc) = FLAC__crc8_table[(crc) ^ (data)];
  82415. void FLAC__crc8_update(const FLAC__byte data, FLAC__uint8 *crc);
  82416. void FLAC__crc8_update_block(const FLAC__byte *data, unsigned len, FLAC__uint8 *crc);
  82417. FLAC__uint8 FLAC__crc8(const FLAC__byte *data, unsigned len);
  82418. extern unsigned FLAC__crc16_table[256];
  82419. #define FLAC__CRC16_UPDATE(data, crc) (((((crc)<<8) & 0xffff) ^ FLAC__crc16_table[((crc)>>8) ^ (data)]))
  82420. #if 0
  82421. #define FLAC__CRC16_UPDATE(data, crc) ((((crc)<<8) ^ FLAC__crc16_table[((crc)>>8) ^ (data)]) & 0xffff)
  82422. #endif
  82423. unsigned FLAC__crc16(const FLAC__byte *data, unsigned len);
  82424. #endif
  82425. /********* End of inlined file: crc.h *********/
  82426. typedef FLAC__uint32 brword;
  82427. #define FLAC__BYTES_PER_WORD 4
  82428. #define FLAC__BITS_PER_WORD 32
  82429. #define FLAC__WORD_ALL_ONES ((FLAC__uint32)0xffffffff)
  82430. #if WORDS_BIGENDIAN
  82431. #define SWAP_BE_WORD_TO_HOST(x) (x)
  82432. #else
  82433. #if defined (_MSC_VER) && defined (_X86_)
  82434. #define SWAP_BE_WORD_TO_HOST(x) local_swap32_(x)
  82435. #else
  82436. #define SWAP_BE_WORD_TO_HOST(x) ntohl(x)
  82437. #endif
  82438. #endif
  82439. #define COUNT_ZERO_MSBS(word) ( \
  82440. (word) <= 0xffff ? \
  82441. ( (word) <= 0xff? byte_to_unary_table[word] + 24 : byte_to_unary_table[(word) >> 8] + 16 ) : \
  82442. ( (word) <= 0xffffff? byte_to_unary_table[word >> 16] + 8 : byte_to_unary_table[(word) >> 24] ) \
  82443. )
  82444. #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])) )
  82445. static const unsigned FLAC__BITREADER_DEFAULT_CAPACITY = 65536u / FLAC__BITS_PER_WORD; /* in words */
  82446. static const unsigned char byte_to_unary_table[] = {
  82447. 8, 7, 6, 6, 5, 5, 5, 5, 4, 4, 4, 4, 4, 4, 4, 4,
  82448. 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
  82449. 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  82450. 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  82451. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  82452. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  82453. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  82454. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  82455. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  82456. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  82457. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  82458. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  82459. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  82460. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  82461. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  82462. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
  82463. };
  82464. #ifdef min
  82465. #undef min
  82466. #endif
  82467. #define min(x,y) ((x)<(y)?(x):(y))
  82468. #ifdef max
  82469. #undef max
  82470. #endif
  82471. #define max(x,y) ((x)>(y)?(x):(y))
  82472. #ifdef _MSC_VER
  82473. #define FLAC__U64L(x) x
  82474. #else
  82475. #define FLAC__U64L(x) x##LLU
  82476. #endif
  82477. #ifndef FLaC__INLINE
  82478. #define FLaC__INLINE
  82479. #endif
  82480. struct FLAC__BitReader {
  82481. brword *buffer;
  82482. unsigned capacity; /* in words */
  82483. unsigned words; /* # of completed words in buffer */
  82484. unsigned bytes; /* # of bytes in incomplete word at buffer[words] */
  82485. unsigned consumed_words; /* #words ... */
  82486. unsigned consumed_bits; /* ... + (#bits of head word) already consumed from the front of buffer */
  82487. unsigned read_crc16; /* the running frame CRC */
  82488. unsigned crc16_align; /* the number of bits in the current consumed word that should not be CRC'd */
  82489. FLAC__BitReaderReadCallback read_callback;
  82490. void *client_data;
  82491. FLAC__CPUInfo cpu_info;
  82492. };
  82493. static FLaC__INLINE void crc16_update_word_(FLAC__BitReader *br, brword word)
  82494. {
  82495. register unsigned crc = br->read_crc16;
  82496. #if FLAC__BYTES_PER_WORD == 4
  82497. switch(br->crc16_align) {
  82498. case 0: crc = FLAC__CRC16_UPDATE((unsigned)(word >> 24), crc);
  82499. case 8: crc = FLAC__CRC16_UPDATE((unsigned)((word >> 16) & 0xff), crc);
  82500. case 16: crc = FLAC__CRC16_UPDATE((unsigned)((word >> 8) & 0xff), crc);
  82501. case 24: br->read_crc16 = FLAC__CRC16_UPDATE((unsigned)(word & 0xff), crc);
  82502. }
  82503. #elif FLAC__BYTES_PER_WORD == 8
  82504. switch(br->crc16_align) {
  82505. case 0: crc = FLAC__CRC16_UPDATE((unsigned)(word >> 56), crc);
  82506. case 8: crc = FLAC__CRC16_UPDATE((unsigned)((word >> 48) & 0xff), crc);
  82507. case 16: crc = FLAC__CRC16_UPDATE((unsigned)((word >> 40) & 0xff), crc);
  82508. case 24: crc = FLAC__CRC16_UPDATE((unsigned)((word >> 32) & 0xff), crc);
  82509. case 32: crc = FLAC__CRC16_UPDATE((unsigned)((word >> 24) & 0xff), crc);
  82510. case 40: crc = FLAC__CRC16_UPDATE((unsigned)((word >> 16) & 0xff), crc);
  82511. case 48: crc = FLAC__CRC16_UPDATE((unsigned)((word >> 8) & 0xff), crc);
  82512. case 56: br->read_crc16 = FLAC__CRC16_UPDATE((unsigned)(word & 0xff), crc);
  82513. }
  82514. #else
  82515. for( ; br->crc16_align < FLAC__BITS_PER_WORD; br->crc16_align += 8)
  82516. crc = FLAC__CRC16_UPDATE((unsigned)((word >> (FLAC__BITS_PER_WORD-8-br->crc16_align)) & 0xff), crc);
  82517. br->read_crc16 = crc;
  82518. #endif
  82519. br->crc16_align = 0;
  82520. }
  82521. FLAC__bool bitreader_read_from_client_(FLAC__BitReader *br)
  82522. {
  82523. unsigned start, end;
  82524. size_t bytes;
  82525. FLAC__byte *target;
  82526. if(br->consumed_words > 0) {
  82527. start = br->consumed_words;
  82528. end = br->words + (br->bytes? 1:0);
  82529. memmove(br->buffer, br->buffer+start, FLAC__BYTES_PER_WORD * (end - start));
  82530. br->words -= start;
  82531. br->consumed_words = 0;
  82532. }
  82533. bytes = (br->capacity - br->words) * FLAC__BYTES_PER_WORD - br->bytes;
  82534. if(bytes == 0)
  82535. return false; /* no space left, buffer is too small; see note for FLAC__BITREADER_DEFAULT_CAPACITY */
  82536. target = ((FLAC__byte*)(br->buffer+br->words)) + br->bytes;
  82537. #if WORDS_BIGENDIAN
  82538. #else
  82539. if(br->bytes)
  82540. br->buffer[br->words] = SWAP_BE_WORD_TO_HOST(br->buffer[br->words]);
  82541. #endif
  82542. if(!br->read_callback(target, &bytes, br->client_data))
  82543. return false;
  82544. #if WORDS_BIGENDIAN
  82545. #else
  82546. end = (br->words*FLAC__BYTES_PER_WORD + br->bytes + bytes + (FLAC__BYTES_PER_WORD-1)) / FLAC__BYTES_PER_WORD;
  82547. # if defined(_MSC_VER) && defined (_X86_) && (FLAC__BYTES_PER_WORD == 4)
  82548. if(br->cpu_info.type == FLAC__CPUINFO_TYPE_IA32 && br->cpu_info.data.ia32.bswap) {
  82549. start = br->words;
  82550. local_swap32_block_(br->buffer + start, end - start);
  82551. }
  82552. else
  82553. # endif
  82554. for(start = br->words; start < end; start++)
  82555. br->buffer[start] = SWAP_BE_WORD_TO_HOST(br->buffer[start]);
  82556. #endif
  82557. end = br->words*FLAC__BYTES_PER_WORD + br->bytes + bytes;
  82558. br->words = end / FLAC__BYTES_PER_WORD;
  82559. br->bytes = end % FLAC__BYTES_PER_WORD;
  82560. return true;
  82561. }
  82562. FLAC__BitReader *FLAC__bitreader_new(void)
  82563. {
  82564. FLAC__BitReader *br = (FLAC__BitReader*)calloc(1, sizeof(FLAC__BitReader));
  82565. return br;
  82566. }
  82567. void FLAC__bitreader_delete(FLAC__BitReader *br)
  82568. {
  82569. FLAC__ASSERT(0 != br);
  82570. FLAC__bitreader_free(br);
  82571. free(br);
  82572. }
  82573. FLAC__bool FLAC__bitreader_init(FLAC__BitReader *br, FLAC__CPUInfo cpu, FLAC__BitReaderReadCallback rcb, void *cd)
  82574. {
  82575. FLAC__ASSERT(0 != br);
  82576. br->words = br->bytes = 0;
  82577. br->consumed_words = br->consumed_bits = 0;
  82578. br->capacity = FLAC__BITREADER_DEFAULT_CAPACITY;
  82579. br->buffer = (brword*)malloc(sizeof(brword) * br->capacity);
  82580. if(br->buffer == 0)
  82581. return false;
  82582. br->read_callback = rcb;
  82583. br->client_data = cd;
  82584. br->cpu_info = cpu;
  82585. return true;
  82586. }
  82587. void FLAC__bitreader_free(FLAC__BitReader *br)
  82588. {
  82589. FLAC__ASSERT(0 != br);
  82590. if(0 != br->buffer)
  82591. free(br->buffer);
  82592. br->buffer = 0;
  82593. br->capacity = 0;
  82594. br->words = br->bytes = 0;
  82595. br->consumed_words = br->consumed_bits = 0;
  82596. br->read_callback = 0;
  82597. br->client_data = 0;
  82598. }
  82599. FLAC__bool FLAC__bitreader_clear(FLAC__BitReader *br)
  82600. {
  82601. br->words = br->bytes = 0;
  82602. br->consumed_words = br->consumed_bits = 0;
  82603. return true;
  82604. }
  82605. void FLAC__bitreader_dump(const FLAC__BitReader *br, FILE *out)
  82606. {
  82607. unsigned i, j;
  82608. if(br == 0) {
  82609. fprintf(out, "bitreader is NULL\n");
  82610. }
  82611. else {
  82612. 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);
  82613. for(i = 0; i < br->words; i++) {
  82614. fprintf(out, "%08X: ", i);
  82615. for(j = 0; j < FLAC__BITS_PER_WORD; j++)
  82616. if(i < br->consumed_words || (i == br->consumed_words && j < br->consumed_bits))
  82617. fprintf(out, ".");
  82618. else
  82619. fprintf(out, "%01u", br->buffer[i] & (1 << (FLAC__BITS_PER_WORD-j-1)) ? 1:0);
  82620. fprintf(out, "\n");
  82621. }
  82622. if(br->bytes > 0) {
  82623. fprintf(out, "%08X: ", i);
  82624. for(j = 0; j < br->bytes*8; j++)
  82625. if(i < br->consumed_words || (i == br->consumed_words && j < br->consumed_bits))
  82626. fprintf(out, ".");
  82627. else
  82628. fprintf(out, "%01u", br->buffer[i] & (1 << (br->bytes*8-j-1)) ? 1:0);
  82629. fprintf(out, "\n");
  82630. }
  82631. }
  82632. }
  82633. void FLAC__bitreader_reset_read_crc16(FLAC__BitReader *br, FLAC__uint16 seed)
  82634. {
  82635. FLAC__ASSERT(0 != br);
  82636. FLAC__ASSERT(0 != br->buffer);
  82637. FLAC__ASSERT((br->consumed_bits & 7) == 0);
  82638. br->read_crc16 = (unsigned)seed;
  82639. br->crc16_align = br->consumed_bits;
  82640. }
  82641. FLAC__uint16 FLAC__bitreader_get_read_crc16(FLAC__BitReader *br)
  82642. {
  82643. FLAC__ASSERT(0 != br);
  82644. FLAC__ASSERT(0 != br->buffer);
  82645. FLAC__ASSERT((br->consumed_bits & 7) == 0);
  82646. FLAC__ASSERT(br->crc16_align <= br->consumed_bits);
  82647. if(br->consumed_bits) {
  82648. const brword tail = br->buffer[br->consumed_words];
  82649. for( ; br->crc16_align < br->consumed_bits; br->crc16_align += 8)
  82650. br->read_crc16 = FLAC__CRC16_UPDATE((unsigned)((tail >> (FLAC__BITS_PER_WORD-8-br->crc16_align)) & 0xff), br->read_crc16);
  82651. }
  82652. return br->read_crc16;
  82653. }
  82654. FLaC__INLINE FLAC__bool FLAC__bitreader_is_consumed_byte_aligned(const FLAC__BitReader *br)
  82655. {
  82656. return ((br->consumed_bits & 7) == 0);
  82657. }
  82658. FLaC__INLINE unsigned FLAC__bitreader_bits_left_for_byte_alignment(const FLAC__BitReader *br)
  82659. {
  82660. return 8 - (br->consumed_bits & 7);
  82661. }
  82662. FLaC__INLINE unsigned FLAC__bitreader_get_input_bits_unconsumed(const FLAC__BitReader *br)
  82663. {
  82664. return (br->words-br->consumed_words)*FLAC__BITS_PER_WORD + br->bytes*8 - br->consumed_bits;
  82665. }
  82666. FLaC__INLINE FLAC__bool FLAC__bitreader_read_raw_uint32(FLAC__BitReader *br, FLAC__uint32 *val, unsigned bits)
  82667. {
  82668. FLAC__ASSERT(0 != br);
  82669. FLAC__ASSERT(0 != br->buffer);
  82670. FLAC__ASSERT(bits <= 32);
  82671. FLAC__ASSERT((br->capacity*FLAC__BITS_PER_WORD) * 2 >= bits);
  82672. FLAC__ASSERT(br->consumed_words <= br->words);
  82673. FLAC__ASSERT(FLAC__BITS_PER_WORD >= 32);
  82674. if(bits == 0) { /* OPT: investigate if this can ever happen, maybe change to assertion */
  82675. *val = 0;
  82676. return true;
  82677. }
  82678. while((br->words-br->consumed_words)*FLAC__BITS_PER_WORD + br->bytes*8 - br->consumed_bits < bits) {
  82679. if(!bitreader_read_from_client_(br))
  82680. return false;
  82681. }
  82682. if(br->consumed_words < br->words) { /* if we've not consumed up to a partial tail word... */
  82683. if(br->consumed_bits) {
  82684. const unsigned n = FLAC__BITS_PER_WORD - br->consumed_bits;
  82685. const brword word = br->buffer[br->consumed_words];
  82686. if(bits < n) {
  82687. *val = (word & (FLAC__WORD_ALL_ONES >> br->consumed_bits)) >> (n-bits);
  82688. br->consumed_bits += bits;
  82689. return true;
  82690. }
  82691. *val = word & (FLAC__WORD_ALL_ONES >> br->consumed_bits);
  82692. bits -= n;
  82693. crc16_update_word_(br, word);
  82694. br->consumed_words++;
  82695. br->consumed_bits = 0;
  82696. 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 */
  82697. *val <<= bits;
  82698. *val |= (br->buffer[br->consumed_words] >> (FLAC__BITS_PER_WORD-bits));
  82699. br->consumed_bits = bits;
  82700. }
  82701. return true;
  82702. }
  82703. else {
  82704. const brword word = br->buffer[br->consumed_words];
  82705. if(bits < FLAC__BITS_PER_WORD) {
  82706. *val = word >> (FLAC__BITS_PER_WORD-bits);
  82707. br->consumed_bits = bits;
  82708. return true;
  82709. }
  82710. *val = word;
  82711. crc16_update_word_(br, word);
  82712. br->consumed_words++;
  82713. return true;
  82714. }
  82715. }
  82716. else {
  82717. if(br->consumed_bits) {
  82718. FLAC__ASSERT(br->consumed_bits + bits <= br->bytes*8);
  82719. *val = (br->buffer[br->consumed_words] & (FLAC__WORD_ALL_ONES >> br->consumed_bits)) >> (FLAC__BITS_PER_WORD-br->consumed_bits-bits);
  82720. br->consumed_bits += bits;
  82721. return true;
  82722. }
  82723. else {
  82724. *val = br->buffer[br->consumed_words] >> (FLAC__BITS_PER_WORD-bits);
  82725. br->consumed_bits += bits;
  82726. return true;
  82727. }
  82728. }
  82729. }
  82730. FLAC__bool FLAC__bitreader_read_raw_int32(FLAC__BitReader *br, FLAC__int32 *val, unsigned bits)
  82731. {
  82732. if(!FLAC__bitreader_read_raw_uint32(br, (FLAC__uint32*)val, bits))
  82733. return false;
  82734. *val <<= (32-bits);
  82735. *val >>= (32-bits);
  82736. return true;
  82737. }
  82738. FLAC__bool FLAC__bitreader_read_raw_uint64(FLAC__BitReader *br, FLAC__uint64 *val, unsigned bits)
  82739. {
  82740. FLAC__uint32 hi, lo;
  82741. if(bits > 32) {
  82742. if(!FLAC__bitreader_read_raw_uint32(br, &hi, bits-32))
  82743. return false;
  82744. if(!FLAC__bitreader_read_raw_uint32(br, &lo, 32))
  82745. return false;
  82746. *val = hi;
  82747. *val <<= 32;
  82748. *val |= lo;
  82749. }
  82750. else {
  82751. if(!FLAC__bitreader_read_raw_uint32(br, &lo, bits))
  82752. return false;
  82753. *val = lo;
  82754. }
  82755. return true;
  82756. }
  82757. FLaC__INLINE FLAC__bool FLAC__bitreader_read_uint32_little_endian(FLAC__BitReader *br, FLAC__uint32 *val)
  82758. {
  82759. FLAC__uint32 x8, x32 = 0;
  82760. if(!FLAC__bitreader_read_raw_uint32(br, &x32, 8))
  82761. return false;
  82762. if(!FLAC__bitreader_read_raw_uint32(br, &x8, 8))
  82763. return false;
  82764. x32 |= (x8 << 8);
  82765. if(!FLAC__bitreader_read_raw_uint32(br, &x8, 8))
  82766. return false;
  82767. x32 |= (x8 << 16);
  82768. if(!FLAC__bitreader_read_raw_uint32(br, &x8, 8))
  82769. return false;
  82770. x32 |= (x8 << 24);
  82771. *val = x32;
  82772. return true;
  82773. }
  82774. FLAC__bool FLAC__bitreader_skip_bits_no_crc(FLAC__BitReader *br, unsigned bits)
  82775. {
  82776. FLAC__ASSERT(0 != br);
  82777. FLAC__ASSERT(0 != br->buffer);
  82778. if(bits > 0) {
  82779. const unsigned n = br->consumed_bits & 7;
  82780. unsigned m;
  82781. FLAC__uint32 x;
  82782. if(n != 0) {
  82783. m = min(8-n, bits);
  82784. if(!FLAC__bitreader_read_raw_uint32(br, &x, m))
  82785. return false;
  82786. bits -= m;
  82787. }
  82788. m = bits / 8;
  82789. if(m > 0) {
  82790. if(!FLAC__bitreader_skip_byte_block_aligned_no_crc(br, m))
  82791. return false;
  82792. bits %= 8;
  82793. }
  82794. if(bits > 0) {
  82795. if(!FLAC__bitreader_read_raw_uint32(br, &x, bits))
  82796. return false;
  82797. }
  82798. }
  82799. return true;
  82800. }
  82801. FLAC__bool FLAC__bitreader_skip_byte_block_aligned_no_crc(FLAC__BitReader *br, unsigned nvals)
  82802. {
  82803. FLAC__uint32 x;
  82804. FLAC__ASSERT(0 != br);
  82805. FLAC__ASSERT(0 != br->buffer);
  82806. FLAC__ASSERT(FLAC__bitreader_is_consumed_byte_aligned(br));
  82807. while(nvals && br->consumed_bits) { /* i.e. run until we read 'nvals' bytes or we hit the end of the head word */
  82808. if(!FLAC__bitreader_read_raw_uint32(br, &x, 8))
  82809. return false;
  82810. nvals--;
  82811. }
  82812. if(0 == nvals)
  82813. return true;
  82814. while(nvals >= FLAC__BYTES_PER_WORD) {
  82815. if(br->consumed_words < br->words) {
  82816. br->consumed_words++;
  82817. nvals -= FLAC__BYTES_PER_WORD;
  82818. }
  82819. else if(!bitreader_read_from_client_(br))
  82820. return false;
  82821. }
  82822. while(nvals) {
  82823. if(!FLAC__bitreader_read_raw_uint32(br, &x, 8))
  82824. return false;
  82825. nvals--;
  82826. }
  82827. return true;
  82828. }
  82829. FLAC__bool FLAC__bitreader_read_byte_block_aligned_no_crc(FLAC__BitReader *br, FLAC__byte *val, unsigned nvals)
  82830. {
  82831. FLAC__uint32 x;
  82832. FLAC__ASSERT(0 != br);
  82833. FLAC__ASSERT(0 != br->buffer);
  82834. FLAC__ASSERT(FLAC__bitreader_is_consumed_byte_aligned(br));
  82835. while(nvals && br->consumed_bits) { /* i.e. run until we read 'nvals' bytes or we hit the end of the head word */
  82836. if(!FLAC__bitreader_read_raw_uint32(br, &x, 8))
  82837. return false;
  82838. *val++ = (FLAC__byte)x;
  82839. nvals--;
  82840. }
  82841. if(0 == nvals)
  82842. return true;
  82843. while(nvals >= FLAC__BYTES_PER_WORD) {
  82844. if(br->consumed_words < br->words) {
  82845. const brword word = br->buffer[br->consumed_words++];
  82846. #if FLAC__BYTES_PER_WORD == 4
  82847. val[0] = (FLAC__byte)(word >> 24);
  82848. val[1] = (FLAC__byte)(word >> 16);
  82849. val[2] = (FLAC__byte)(word >> 8);
  82850. val[3] = (FLAC__byte)word;
  82851. #elif FLAC__BYTES_PER_WORD == 8
  82852. val[0] = (FLAC__byte)(word >> 56);
  82853. val[1] = (FLAC__byte)(word >> 48);
  82854. val[2] = (FLAC__byte)(word >> 40);
  82855. val[3] = (FLAC__byte)(word >> 32);
  82856. val[4] = (FLAC__byte)(word >> 24);
  82857. val[5] = (FLAC__byte)(word >> 16);
  82858. val[6] = (FLAC__byte)(word >> 8);
  82859. val[7] = (FLAC__byte)word;
  82860. #else
  82861. for(x = 0; x < FLAC__BYTES_PER_WORD; x++)
  82862. val[x] = (FLAC__byte)(word >> (8*(FLAC__BYTES_PER_WORD-x-1)));
  82863. #endif
  82864. val += FLAC__BYTES_PER_WORD;
  82865. nvals -= FLAC__BYTES_PER_WORD;
  82866. }
  82867. else if(!bitreader_read_from_client_(br))
  82868. return false;
  82869. }
  82870. while(nvals) {
  82871. if(!FLAC__bitreader_read_raw_uint32(br, &x, 8))
  82872. return false;
  82873. *val++ = (FLAC__byte)x;
  82874. nvals--;
  82875. }
  82876. return true;
  82877. }
  82878. FLaC__INLINE FLAC__bool FLAC__bitreader_read_unary_unsigned(FLAC__BitReader *br, unsigned *val)
  82879. #if 0 /* slow but readable version */
  82880. {
  82881. unsigned bit;
  82882. FLAC__ASSERT(0 != br);
  82883. FLAC__ASSERT(0 != br->buffer);
  82884. *val = 0;
  82885. while(1) {
  82886. if(!FLAC__bitreader_read_bit(br, &bit))
  82887. return false;
  82888. if(bit)
  82889. break;
  82890. else
  82891. *val++;
  82892. }
  82893. return true;
  82894. }
  82895. #else
  82896. {
  82897. unsigned i;
  82898. FLAC__ASSERT(0 != br);
  82899. FLAC__ASSERT(0 != br->buffer);
  82900. *val = 0;
  82901. while(1) {
  82902. while(br->consumed_words < br->words) { /* if we've not consumed up to a partial tail word... */
  82903. brword b = br->buffer[br->consumed_words] << br->consumed_bits;
  82904. if(b) {
  82905. i = COUNT_ZERO_MSBS(b);
  82906. *val += i;
  82907. i++;
  82908. br->consumed_bits += i;
  82909. if(br->consumed_bits >= FLAC__BITS_PER_WORD) { /* faster way of testing if(br->consumed_bits == FLAC__BITS_PER_WORD) */
  82910. crc16_update_word_(br, br->buffer[br->consumed_words]);
  82911. br->consumed_words++;
  82912. br->consumed_bits = 0;
  82913. }
  82914. return true;
  82915. }
  82916. else {
  82917. *val += FLAC__BITS_PER_WORD - br->consumed_bits;
  82918. crc16_update_word_(br, br->buffer[br->consumed_words]);
  82919. br->consumed_words++;
  82920. br->consumed_bits = 0;
  82921. }
  82922. }
  82923. if(br->bytes) {
  82924. const unsigned end = br->bytes * 8;
  82925. brword b = (br->buffer[br->consumed_words] & (FLAC__WORD_ALL_ONES << (FLAC__BITS_PER_WORD-end))) << br->consumed_bits;
  82926. if(b) {
  82927. i = COUNT_ZERO_MSBS(b);
  82928. *val += i;
  82929. i++;
  82930. br->consumed_bits += i;
  82931. FLAC__ASSERT(br->consumed_bits < FLAC__BITS_PER_WORD);
  82932. return true;
  82933. }
  82934. else {
  82935. *val += end - br->consumed_bits;
  82936. br->consumed_bits += end;
  82937. FLAC__ASSERT(br->consumed_bits < FLAC__BITS_PER_WORD);
  82938. }
  82939. }
  82940. if(!bitreader_read_from_client_(br))
  82941. return false;
  82942. }
  82943. }
  82944. #endif
  82945. FLAC__bool FLAC__bitreader_read_rice_signed(FLAC__BitReader *br, int *val, unsigned parameter)
  82946. {
  82947. FLAC__uint32 lsbs = 0, msbs = 0;
  82948. unsigned uval;
  82949. FLAC__ASSERT(0 != br);
  82950. FLAC__ASSERT(0 != br->buffer);
  82951. FLAC__ASSERT(parameter <= 31);
  82952. if(!FLAC__bitreader_read_unary_unsigned(br, (unsigned int*) &msbs))
  82953. return false;
  82954. if(!FLAC__bitreader_read_raw_uint32(br, &lsbs, parameter))
  82955. return false;
  82956. uval = (msbs << parameter) | lsbs;
  82957. if(uval & 1)
  82958. *val = -((int)(uval >> 1)) - 1;
  82959. else
  82960. *val = (int)(uval >> 1);
  82961. return true;
  82962. }
  82963. FLAC__bool FLAC__bitreader_read_rice_signed_block(FLAC__BitReader *br, int vals[], unsigned nvals, unsigned parameter)
  82964. #ifdef _MSC_VER
  82965. {
  82966. unsigned i;
  82967. unsigned uval = 0;
  82968. unsigned bits; /* the # of binary LSBs left to read to finish a rice codeword */
  82969. register unsigned cwords;
  82970. register unsigned cbits;
  82971. FLAC__ASSERT(0 != br);
  82972. FLAC__ASSERT(0 != br->buffer);
  82973. FLAC__ASSERT(FLAC__BITS_PER_WORD >= 32);
  82974. FLAC__ASSERT(parameter < 32);
  82975. if(nvals == 0)
  82976. return true;
  82977. cbits = br->consumed_bits;
  82978. cwords = br->consumed_words;
  82979. while(1) {
  82980. while(1) {
  82981. while(cwords < br->words) { /* if we've not consumed up to a partial tail word... */
  82982. brword b = br->buffer[cwords] << cbits;
  82983. if(b) {
  82984. #if 0 /* slower, probably due to bad register allocation... */ && defined FLAC__CPU_IA32 && !defined FLAC__NO_ASM && FLAC__BITS_PER_WORD == 32
  82985. __asm {
  82986. bsr eax, b
  82987. not eax
  82988. and eax, 31
  82989. mov i, eax
  82990. }
  82991. #else
  82992. i = COUNT_ZERO_MSBS(b);
  82993. #endif
  82994. uval += i;
  82995. bits = parameter;
  82996. i++;
  82997. cbits += i;
  82998. if(cbits == FLAC__BITS_PER_WORD) {
  82999. crc16_update_word_(br, br->buffer[cwords]);
  83000. cwords++;
  83001. cbits = 0;
  83002. }
  83003. goto break1;
  83004. }
  83005. else {
  83006. uval += FLAC__BITS_PER_WORD - cbits;
  83007. crc16_update_word_(br, br->buffer[cwords]);
  83008. cwords++;
  83009. cbits = 0;
  83010. }
  83011. }
  83012. if(br->bytes) {
  83013. const unsigned end = br->bytes * 8;
  83014. brword b = (br->buffer[cwords] & (FLAC__WORD_ALL_ONES << (FLAC__BITS_PER_WORD-end))) << cbits;
  83015. if(b) {
  83016. i = COUNT_ZERO_MSBS(b);
  83017. uval += i;
  83018. bits = parameter;
  83019. i++;
  83020. cbits += i;
  83021. FLAC__ASSERT(cbits < FLAC__BITS_PER_WORD);
  83022. goto break1;
  83023. }
  83024. else {
  83025. uval += end - cbits;
  83026. cbits += end;
  83027. FLAC__ASSERT(cbits < FLAC__BITS_PER_WORD);
  83028. }
  83029. }
  83030. br->consumed_bits = cbits;
  83031. br->consumed_words = cwords;
  83032. if(!bitreader_read_from_client_(br))
  83033. return false;
  83034. cwords = br->consumed_words;
  83035. }
  83036. break1:
  83037. FLAC__ASSERT(cwords <= br->words);
  83038. if(bits) {
  83039. while((br->words-cwords)*FLAC__BITS_PER_WORD + br->bytes*8 - cbits < bits) {
  83040. br->consumed_bits = cbits;
  83041. br->consumed_words = cwords;
  83042. if(!bitreader_read_from_client_(br))
  83043. return false;
  83044. cwords = br->consumed_words;
  83045. }
  83046. if(cwords < br->words) { /* if we've not consumed up to a partial tail word... */
  83047. if(cbits) {
  83048. const unsigned n = FLAC__BITS_PER_WORD - cbits;
  83049. const brword word = br->buffer[cwords];
  83050. if(bits < n) {
  83051. uval <<= bits;
  83052. uval |= (word & (FLAC__WORD_ALL_ONES >> cbits)) >> (n-bits);
  83053. cbits += bits;
  83054. goto break2;
  83055. }
  83056. uval <<= n;
  83057. uval |= word & (FLAC__WORD_ALL_ONES >> cbits);
  83058. bits -= n;
  83059. crc16_update_word_(br, word);
  83060. cwords++;
  83061. cbits = 0;
  83062. 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 */
  83063. uval <<= bits;
  83064. uval |= (br->buffer[cwords] >> (FLAC__BITS_PER_WORD-bits));
  83065. cbits = bits;
  83066. }
  83067. goto break2;
  83068. }
  83069. else {
  83070. FLAC__ASSERT(bits < FLAC__BITS_PER_WORD);
  83071. uval <<= bits;
  83072. uval |= br->buffer[cwords] >> (FLAC__BITS_PER_WORD-bits);
  83073. cbits = bits;
  83074. goto break2;
  83075. }
  83076. }
  83077. else {
  83078. uval <<= bits;
  83079. if(cbits) {
  83080. FLAC__ASSERT(cbits + bits <= br->bytes*8);
  83081. uval |= (br->buffer[cwords] & (FLAC__WORD_ALL_ONES >> cbits)) >> (FLAC__BITS_PER_WORD-cbits-bits);
  83082. cbits += bits;
  83083. goto break2;
  83084. }
  83085. else {
  83086. uval |= br->buffer[cwords] >> (FLAC__BITS_PER_WORD-bits);
  83087. cbits += bits;
  83088. goto break2;
  83089. }
  83090. }
  83091. }
  83092. break2:
  83093. *vals = (int)(uval >> 1 ^ -(int)(uval & 1));
  83094. --nvals;
  83095. if(nvals == 0) {
  83096. br->consumed_bits = cbits;
  83097. br->consumed_words = cwords;
  83098. return true;
  83099. }
  83100. uval = 0;
  83101. ++vals;
  83102. }
  83103. }
  83104. #else
  83105. {
  83106. unsigned i;
  83107. unsigned uval = 0;
  83108. register unsigned cwords;
  83109. register unsigned cbits;
  83110. unsigned ucbits; /* keep track of the number of unconsumed bits in the buffer */
  83111. FLAC__ASSERT(0 != br);
  83112. FLAC__ASSERT(0 != br->buffer);
  83113. FLAC__ASSERT(FLAC__BITS_PER_WORD >= 32);
  83114. FLAC__ASSERT(parameter < 32);
  83115. if(nvals == 0)
  83116. return true;
  83117. cbits = br->consumed_bits;
  83118. cwords = br->consumed_words;
  83119. ucbits = (br->words-cwords)*FLAC__BITS_PER_WORD + br->bytes*8 - cbits;
  83120. while(1) {
  83121. while(1) {
  83122. while(cwords < br->words) { /* if we've not consumed up to a partial tail word... */
  83123. brword b = br->buffer[cwords] << cbits;
  83124. if(b) {
  83125. #if 0 /* is not discernably faster... */ && defined FLAC__CPU_IA32 && !defined FLAC__NO_ASM && FLAC__BITS_PER_WORD == 32 && defined __GNUC__
  83126. asm volatile (
  83127. "bsrl %1, %0;"
  83128. "notl %0;"
  83129. "andl $31, %0;"
  83130. : "=r"(i)
  83131. : "r"(b)
  83132. );
  83133. #else
  83134. i = COUNT_ZERO_MSBS(b);
  83135. #endif
  83136. uval += i;
  83137. cbits += i;
  83138. cbits++; /* skip over stop bit */
  83139. if(cbits >= FLAC__BITS_PER_WORD) { /* faster way of testing if(cbits == FLAC__BITS_PER_WORD) */
  83140. crc16_update_word_(br, br->buffer[cwords]);
  83141. cwords++;
  83142. cbits = 0;
  83143. }
  83144. goto break1;
  83145. }
  83146. else {
  83147. uval += FLAC__BITS_PER_WORD - cbits;
  83148. crc16_update_word_(br, br->buffer[cwords]);
  83149. cwords++;
  83150. cbits = 0;
  83151. }
  83152. }
  83153. if(br->bytes) {
  83154. const unsigned end = br->bytes * 8;
  83155. brword b = (br->buffer[cwords] & ~(FLAC__WORD_ALL_ONES >> end)) << cbits;
  83156. if(b) {
  83157. i = COUNT_ZERO_MSBS(b);
  83158. uval += i;
  83159. cbits += i;
  83160. cbits++; /* skip over stop bit */
  83161. FLAC__ASSERT(cbits < FLAC__BITS_PER_WORD);
  83162. goto break1;
  83163. }
  83164. else {
  83165. uval += end - cbits;
  83166. cbits += end;
  83167. FLAC__ASSERT(cbits < FLAC__BITS_PER_WORD);
  83168. }
  83169. }
  83170. br->consumed_bits = cbits;
  83171. br->consumed_words = cwords;
  83172. if(!bitreader_read_from_client_(br))
  83173. return false;
  83174. cwords = br->consumed_words;
  83175. ucbits = (br->words-cwords)*FLAC__BITS_PER_WORD + br->bytes*8 - cbits + uval;
  83176. }
  83177. break1:
  83178. ucbits -= uval;
  83179. ucbits--; /* account for stop bit */
  83180. FLAC__ASSERT(cwords <= br->words);
  83181. if(parameter) {
  83182. while(ucbits < parameter) {
  83183. br->consumed_bits = cbits;
  83184. br->consumed_words = cwords;
  83185. if(!bitreader_read_from_client_(br))
  83186. return false;
  83187. cwords = br->consumed_words;
  83188. ucbits = (br->words-cwords)*FLAC__BITS_PER_WORD + br->bytes*8 - cbits;
  83189. }
  83190. if(cwords < br->words) { /* if we've not consumed up to a partial tail word... */
  83191. if(cbits) {
  83192. const unsigned n = FLAC__BITS_PER_WORD - cbits;
  83193. const brword word = br->buffer[cwords];
  83194. if(parameter < n) {
  83195. uval <<= parameter;
  83196. uval |= (word & (FLAC__WORD_ALL_ONES >> cbits)) >> (n-parameter);
  83197. cbits += parameter;
  83198. }
  83199. else {
  83200. uval <<= n;
  83201. uval |= word & (FLAC__WORD_ALL_ONES >> cbits);
  83202. crc16_update_word_(br, word);
  83203. cwords++;
  83204. cbits = parameter - n;
  83205. 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 */
  83206. uval <<= cbits;
  83207. uval |= (br->buffer[cwords] >> (FLAC__BITS_PER_WORD-cbits));
  83208. }
  83209. }
  83210. }
  83211. else {
  83212. cbits = parameter;
  83213. uval <<= parameter;
  83214. uval |= br->buffer[cwords] >> (FLAC__BITS_PER_WORD-cbits);
  83215. }
  83216. }
  83217. else {
  83218. uval <<= parameter;
  83219. if(cbits) {
  83220. FLAC__ASSERT(cbits + parameter <= br->bytes*8);
  83221. uval |= (br->buffer[cwords] & (FLAC__WORD_ALL_ONES >> cbits)) >> (FLAC__BITS_PER_WORD-cbits-parameter);
  83222. cbits += parameter;
  83223. }
  83224. else {
  83225. cbits = parameter;
  83226. uval |= br->buffer[cwords] >> (FLAC__BITS_PER_WORD-cbits);
  83227. }
  83228. }
  83229. }
  83230. ucbits -= parameter;
  83231. *vals = (int)(uval >> 1 ^ -(int)(uval & 1));
  83232. --nvals;
  83233. if(nvals == 0) {
  83234. br->consumed_bits = cbits;
  83235. br->consumed_words = cwords;
  83236. return true;
  83237. }
  83238. uval = 0;
  83239. ++vals;
  83240. }
  83241. }
  83242. #endif
  83243. #if 0 /* UNUSED */
  83244. FLAC__bool FLAC__bitreader_read_golomb_signed(FLAC__BitReader *br, int *val, unsigned parameter)
  83245. {
  83246. FLAC__uint32 lsbs = 0, msbs = 0;
  83247. unsigned bit, uval, k;
  83248. FLAC__ASSERT(0 != br);
  83249. FLAC__ASSERT(0 != br->buffer);
  83250. k = FLAC__bitmath_ilog2(parameter);
  83251. if(!FLAC__bitreader_read_unary_unsigned(br, &msbs))
  83252. return false;
  83253. if(!FLAC__bitreader_read_raw_uint32(br, &lsbs, k))
  83254. return false;
  83255. if(parameter == 1u<<k) {
  83256. uval = (msbs << k) | lsbs;
  83257. }
  83258. else {
  83259. unsigned d = (1 << (k+1)) - parameter;
  83260. if(lsbs >= d) {
  83261. if(!FLAC__bitreader_read_bit(br, &bit))
  83262. return false;
  83263. lsbs <<= 1;
  83264. lsbs |= bit;
  83265. lsbs -= d;
  83266. }
  83267. uval = msbs * parameter + lsbs;
  83268. }
  83269. if(uval & 1)
  83270. *val = -((int)(uval >> 1)) - 1;
  83271. else
  83272. *val = (int)(uval >> 1);
  83273. return true;
  83274. }
  83275. FLAC__bool FLAC__bitreader_read_golomb_unsigned(FLAC__BitReader *br, unsigned *val, unsigned parameter)
  83276. {
  83277. FLAC__uint32 lsbs, msbs = 0;
  83278. unsigned bit, k;
  83279. FLAC__ASSERT(0 != br);
  83280. FLAC__ASSERT(0 != br->buffer);
  83281. k = FLAC__bitmath_ilog2(parameter);
  83282. if(!FLAC__bitreader_read_unary_unsigned(br, &msbs))
  83283. return false;
  83284. if(!FLAC__bitreader_read_raw_uint32(br, &lsbs, k))
  83285. return false;
  83286. if(parameter == 1u<<k) {
  83287. *val = (msbs << k) | lsbs;
  83288. }
  83289. else {
  83290. unsigned d = (1 << (k+1)) - parameter;
  83291. if(lsbs >= d) {
  83292. if(!FLAC__bitreader_read_bit(br, &bit))
  83293. return false;
  83294. lsbs <<= 1;
  83295. lsbs |= bit;
  83296. lsbs -= d;
  83297. }
  83298. *val = msbs * parameter + lsbs;
  83299. }
  83300. return true;
  83301. }
  83302. #endif /* UNUSED */
  83303. FLAC__bool FLAC__bitreader_read_utf8_uint32(FLAC__BitReader *br, FLAC__uint32 *val, FLAC__byte *raw, unsigned *rawlen)
  83304. {
  83305. FLAC__uint32 v = 0;
  83306. FLAC__uint32 x;
  83307. unsigned i;
  83308. if(!FLAC__bitreader_read_raw_uint32(br, &x, 8))
  83309. return false;
  83310. if(raw)
  83311. raw[(*rawlen)++] = (FLAC__byte)x;
  83312. if(!(x & 0x80)) { /* 0xxxxxxx */
  83313. v = x;
  83314. i = 0;
  83315. }
  83316. else if(x & 0xC0 && !(x & 0x20)) { /* 110xxxxx */
  83317. v = x & 0x1F;
  83318. i = 1;
  83319. }
  83320. else if(x & 0xE0 && !(x & 0x10)) { /* 1110xxxx */
  83321. v = x & 0x0F;
  83322. i = 2;
  83323. }
  83324. else if(x & 0xF0 && !(x & 0x08)) { /* 11110xxx */
  83325. v = x & 0x07;
  83326. i = 3;
  83327. }
  83328. else if(x & 0xF8 && !(x & 0x04)) { /* 111110xx */
  83329. v = x & 0x03;
  83330. i = 4;
  83331. }
  83332. else if(x & 0xFC && !(x & 0x02)) { /* 1111110x */
  83333. v = x & 0x01;
  83334. i = 5;
  83335. }
  83336. else {
  83337. *val = 0xffffffff;
  83338. return true;
  83339. }
  83340. for( ; i; i--) {
  83341. if(!FLAC__bitreader_read_raw_uint32(br, &x, 8))
  83342. return false;
  83343. if(raw)
  83344. raw[(*rawlen)++] = (FLAC__byte)x;
  83345. if(!(x & 0x80) || (x & 0x40)) { /* 10xxxxxx */
  83346. *val = 0xffffffff;
  83347. return true;
  83348. }
  83349. v <<= 6;
  83350. v |= (x & 0x3F);
  83351. }
  83352. *val = v;
  83353. return true;
  83354. }
  83355. FLAC__bool FLAC__bitreader_read_utf8_uint64(FLAC__BitReader *br, FLAC__uint64 *val, FLAC__byte *raw, unsigned *rawlen)
  83356. {
  83357. FLAC__uint64 v = 0;
  83358. FLAC__uint32 x;
  83359. unsigned i;
  83360. if(!FLAC__bitreader_read_raw_uint32(br, &x, 8))
  83361. return false;
  83362. if(raw)
  83363. raw[(*rawlen)++] = (FLAC__byte)x;
  83364. if(!(x & 0x80)) { /* 0xxxxxxx */
  83365. v = x;
  83366. i = 0;
  83367. }
  83368. else if(x & 0xC0 && !(x & 0x20)) { /* 110xxxxx */
  83369. v = x & 0x1F;
  83370. i = 1;
  83371. }
  83372. else if(x & 0xE0 && !(x & 0x10)) { /* 1110xxxx */
  83373. v = x & 0x0F;
  83374. i = 2;
  83375. }
  83376. else if(x & 0xF0 && !(x & 0x08)) { /* 11110xxx */
  83377. v = x & 0x07;
  83378. i = 3;
  83379. }
  83380. else if(x & 0xF8 && !(x & 0x04)) { /* 111110xx */
  83381. v = x & 0x03;
  83382. i = 4;
  83383. }
  83384. else if(x & 0xFC && !(x & 0x02)) { /* 1111110x */
  83385. v = x & 0x01;
  83386. i = 5;
  83387. }
  83388. else if(x & 0xFE && !(x & 0x01)) { /* 11111110 */
  83389. v = 0;
  83390. i = 6;
  83391. }
  83392. else {
  83393. *val = FLAC__U64L(0xffffffffffffffff);
  83394. return true;
  83395. }
  83396. for( ; i; i--) {
  83397. if(!FLAC__bitreader_read_raw_uint32(br, &x, 8))
  83398. return false;
  83399. if(raw)
  83400. raw[(*rawlen)++] = (FLAC__byte)x;
  83401. if(!(x & 0x80) || (x & 0x40)) { /* 10xxxxxx */
  83402. *val = FLAC__U64L(0xffffffffffffffff);
  83403. return true;
  83404. }
  83405. v <<= 6;
  83406. v |= (x & 0x3F);
  83407. }
  83408. *val = v;
  83409. return true;
  83410. }
  83411. #endif
  83412. /********* End of inlined file: bitreader.c *********/
  83413. /********* Start of inlined file: bitwriter.c *********/
  83414. /********* Start of inlined file: juce_FlacHeader.h *********/
  83415. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  83416. // tasks..
  83417. #define VERSION "1.2.1"
  83418. #define FLAC__NO_DLL 1
  83419. #if JUCE_MSVC
  83420. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  83421. #endif
  83422. #if JUCE_MAC
  83423. #define FLAC__SYS_DARWIN 1
  83424. #endif
  83425. /********* End of inlined file: juce_FlacHeader.h *********/
  83426. #if JUCE_USE_FLAC
  83427. #if HAVE_CONFIG_H
  83428. # include <config.h>
  83429. #endif
  83430. #include <stdlib.h> /* for malloc() */
  83431. #include <string.h> /* for memcpy(), memset() */
  83432. #ifdef _MSC_VER
  83433. #include <winsock.h> /* for ntohl() */
  83434. #elif defined FLAC__SYS_DARWIN
  83435. #include <machine/endian.h> /* for ntohl() */
  83436. #elif defined __MINGW32__
  83437. #include <winsock.h> /* for ntohl() */
  83438. #else
  83439. #include <netinet/in.h> /* for ntohl() */
  83440. #endif
  83441. #if 0 /* UNUSED */
  83442. #endif
  83443. /********* Start of inlined file: bitwriter.h *********/
  83444. #ifndef FLAC__PRIVATE__BITWRITER_H
  83445. #define FLAC__PRIVATE__BITWRITER_H
  83446. #include <stdio.h> /* for FILE */
  83447. struct FLAC__BitWriter;
  83448. typedef struct FLAC__BitWriter FLAC__BitWriter;
  83449. FLAC__BitWriter *FLAC__bitwriter_new(void);
  83450. void FLAC__bitwriter_delete(FLAC__BitWriter *bw);
  83451. FLAC__bool FLAC__bitwriter_init(FLAC__BitWriter *bw);
  83452. void FLAC__bitwriter_free(FLAC__BitWriter *bw); /* does not 'free(buffer)' */
  83453. void FLAC__bitwriter_clear(FLAC__BitWriter *bw);
  83454. void FLAC__bitwriter_dump(const FLAC__BitWriter *bw, FILE *out);
  83455. FLAC__bool FLAC__bitwriter_get_write_crc16(FLAC__BitWriter *bw, FLAC__uint16 *crc);
  83456. FLAC__bool FLAC__bitwriter_get_write_crc8(FLAC__BitWriter *bw, FLAC__byte *crc);
  83457. FLAC__bool FLAC__bitwriter_is_byte_aligned(const FLAC__BitWriter *bw);
  83458. unsigned FLAC__bitwriter_get_input_bits_unconsumed(const FLAC__BitWriter *bw); /* can be called anytime, returns total # of bits unconsumed */
  83459. FLAC__bool FLAC__bitwriter_get_buffer(FLAC__BitWriter *bw, const FLAC__byte **buffer, size_t *bytes);
  83460. void FLAC__bitwriter_release_buffer(FLAC__BitWriter *bw);
  83461. FLAC__bool FLAC__bitwriter_write_zeroes(FLAC__BitWriter *bw, unsigned bits);
  83462. FLAC__bool FLAC__bitwriter_write_raw_uint32(FLAC__BitWriter *bw, FLAC__uint32 val, unsigned bits);
  83463. FLAC__bool FLAC__bitwriter_write_raw_int32(FLAC__BitWriter *bw, FLAC__int32 val, unsigned bits);
  83464. FLAC__bool FLAC__bitwriter_write_raw_uint64(FLAC__BitWriter *bw, FLAC__uint64 val, unsigned bits);
  83465. FLAC__bool FLAC__bitwriter_write_raw_uint32_little_endian(FLAC__BitWriter *bw, FLAC__uint32 val); /*only for bits=32*/
  83466. FLAC__bool FLAC__bitwriter_write_byte_block(FLAC__BitWriter *bw, const FLAC__byte vals[], unsigned nvals);
  83467. FLAC__bool FLAC__bitwriter_write_unary_unsigned(FLAC__BitWriter *bw, unsigned val);
  83468. unsigned FLAC__bitwriter_rice_bits(FLAC__int32 val, unsigned parameter);
  83469. #if 0 /* UNUSED */
  83470. unsigned FLAC__bitwriter_golomb_bits_signed(int val, unsigned parameter);
  83471. unsigned FLAC__bitwriter_golomb_bits_unsigned(unsigned val, unsigned parameter);
  83472. #endif
  83473. FLAC__bool FLAC__bitwriter_write_rice_signed(FLAC__BitWriter *bw, FLAC__int32 val, unsigned parameter);
  83474. FLAC__bool FLAC__bitwriter_write_rice_signed_block(FLAC__BitWriter *bw, const FLAC__int32 *vals, unsigned nvals, unsigned parameter);
  83475. #if 0 /* UNUSED */
  83476. FLAC__bool FLAC__bitwriter_write_golomb_signed(FLAC__BitWriter *bw, int val, unsigned parameter);
  83477. FLAC__bool FLAC__bitwriter_write_golomb_unsigned(FLAC__BitWriter *bw, unsigned val, unsigned parameter);
  83478. #endif
  83479. FLAC__bool FLAC__bitwriter_write_utf8_uint32(FLAC__BitWriter *bw, FLAC__uint32 val);
  83480. FLAC__bool FLAC__bitwriter_write_utf8_uint64(FLAC__BitWriter *bw, FLAC__uint64 val);
  83481. FLAC__bool FLAC__bitwriter_zero_pad_to_byte_boundary(FLAC__BitWriter *bw);
  83482. #endif
  83483. /********* End of inlined file: bitwriter.h *********/
  83484. /********* Start of inlined file: alloc.h *********/
  83485. #ifndef FLAC__SHARE__ALLOC_H
  83486. #define FLAC__SHARE__ALLOC_H
  83487. #if HAVE_CONFIG_H
  83488. # include <config.h>
  83489. #endif
  83490. #include <limits.h> /* for SIZE_MAX */
  83491. #if !defined _MSC_VER && !defined __MINGW32__ && !defined __EMX__
  83492. #include <stdint.h> /* for SIZE_MAX in case limits.h didn't get it */
  83493. #endif
  83494. #include <stdlib.h> /* for size_t, malloc(), etc */
  83495. #ifndef SIZE_MAX
  83496. # ifndef SIZE_T_MAX
  83497. # ifdef _MSC_VER
  83498. # define SIZE_T_MAX UINT_MAX
  83499. # else
  83500. # error
  83501. # endif
  83502. # endif
  83503. # define SIZE_MAX SIZE_T_MAX
  83504. #endif
  83505. #ifndef FLaC__INLINE
  83506. #define FLaC__INLINE
  83507. #endif
  83508. static FLaC__INLINE void *safe_malloc_(size_t size)
  83509. {
  83510. if(!size)
  83511. size++;
  83512. return malloc(size);
  83513. }
  83514. static FLaC__INLINE void *safe_calloc_(size_t nmemb, size_t size)
  83515. {
  83516. if(!nmemb || !size)
  83517. return malloc(1); /* malloc(0) is undefined; FLAC src convention is to always allocate */
  83518. return calloc(nmemb, size);
  83519. }
  83520. static FLaC__INLINE void *safe_malloc_add_2op_(size_t size1, size_t size2)
  83521. {
  83522. size2 += size1;
  83523. if(size2 < size1)
  83524. return 0;
  83525. return safe_malloc_(size2);
  83526. }
  83527. static FLaC__INLINE void *safe_malloc_add_3op_(size_t size1, size_t size2, size_t size3)
  83528. {
  83529. size2 += size1;
  83530. if(size2 < size1)
  83531. return 0;
  83532. size3 += size2;
  83533. if(size3 < size2)
  83534. return 0;
  83535. return safe_malloc_(size3);
  83536. }
  83537. static FLaC__INLINE void *safe_malloc_add_4op_(size_t size1, size_t size2, size_t size3, size_t size4)
  83538. {
  83539. size2 += size1;
  83540. if(size2 < size1)
  83541. return 0;
  83542. size3 += size2;
  83543. if(size3 < size2)
  83544. return 0;
  83545. size4 += size3;
  83546. if(size4 < size3)
  83547. return 0;
  83548. return safe_malloc_(size4);
  83549. }
  83550. static FLaC__INLINE void *safe_malloc_mul_2op_(size_t size1, size_t size2)
  83551. #if 0
  83552. needs support for cases where sizeof(size_t) != 4
  83553. {
  83554. if(sizeof(size_t) == 4) {
  83555. if ((double)size1 * (double)size2 < 4294967296.0)
  83556. return malloc(size1*size2);
  83557. }
  83558. return 0;
  83559. }
  83560. #else
  83561. {
  83562. if(!size1 || !size2)
  83563. return malloc(1); /* malloc(0) is undefined; FLAC src convention is to always allocate */
  83564. if(size1 > SIZE_MAX / size2)
  83565. return 0;
  83566. return malloc(size1*size2);
  83567. }
  83568. #endif
  83569. static FLaC__INLINE void *safe_malloc_mul_3op_(size_t size1, size_t size2, size_t size3)
  83570. {
  83571. if(!size1 || !size2 || !size3)
  83572. return malloc(1); /* malloc(0) is undefined; FLAC src convention is to always allocate */
  83573. if(size1 > SIZE_MAX / size2)
  83574. return 0;
  83575. size1 *= size2;
  83576. if(size1 > SIZE_MAX / size3)
  83577. return 0;
  83578. return malloc(size1*size3);
  83579. }
  83580. static FLaC__INLINE void *safe_malloc_mul2add_(size_t size1, size_t size2, size_t size3)
  83581. {
  83582. if(!size1 || !size2)
  83583. return safe_malloc_(size3);
  83584. if(size1 > SIZE_MAX / size2)
  83585. return 0;
  83586. return safe_malloc_add_2op_(size1*size2, size3);
  83587. }
  83588. static FLaC__INLINE void *safe_malloc_muladd2_(size_t size1, size_t size2, size_t size3)
  83589. {
  83590. if(!size1 || (!size2 && !size3))
  83591. return malloc(1); /* malloc(0) is undefined; FLAC src convention is to always allocate */
  83592. size2 += size3;
  83593. if(size2 < size3)
  83594. return 0;
  83595. return safe_malloc_mul_2op_(size1, size2);
  83596. }
  83597. static FLaC__INLINE void *safe_realloc_add_2op_(void *ptr, size_t size1, size_t size2)
  83598. {
  83599. size2 += size1;
  83600. if(size2 < size1)
  83601. return 0;
  83602. return realloc(ptr, size2);
  83603. }
  83604. static FLaC__INLINE void *safe_realloc_add_3op_(void *ptr, size_t size1, size_t size2, size_t size3)
  83605. {
  83606. size2 += size1;
  83607. if(size2 < size1)
  83608. return 0;
  83609. size3 += size2;
  83610. if(size3 < size2)
  83611. return 0;
  83612. return realloc(ptr, size3);
  83613. }
  83614. static FLaC__INLINE void *safe_realloc_add_4op_(void *ptr, size_t size1, size_t size2, size_t size3, size_t size4)
  83615. {
  83616. size2 += size1;
  83617. if(size2 < size1)
  83618. return 0;
  83619. size3 += size2;
  83620. if(size3 < size2)
  83621. return 0;
  83622. size4 += size3;
  83623. if(size4 < size3)
  83624. return 0;
  83625. return realloc(ptr, size4);
  83626. }
  83627. static FLaC__INLINE void *safe_realloc_mul_2op_(void *ptr, size_t size1, size_t size2)
  83628. {
  83629. if(!size1 || !size2)
  83630. return realloc(ptr, 0); /* preserve POSIX realloc(ptr, 0) semantics */
  83631. if(size1 > SIZE_MAX / size2)
  83632. return 0;
  83633. return realloc(ptr, size1*size2);
  83634. }
  83635. static FLaC__INLINE void *safe_realloc_muladd2_(void *ptr, size_t size1, size_t size2, size_t size3)
  83636. {
  83637. if(!size1 || (!size2 && !size3))
  83638. return realloc(ptr, 0); /* preserve POSIX realloc(ptr, 0) semantics */
  83639. size2 += size3;
  83640. if(size2 < size3)
  83641. return 0;
  83642. return safe_realloc_mul_2op_(ptr, size1, size2);
  83643. }
  83644. #endif
  83645. /********* End of inlined file: alloc.h *********/
  83646. typedef FLAC__uint32 bwword;
  83647. #define FLAC__BYTES_PER_WORD 4
  83648. #define FLAC__BITS_PER_WORD 32
  83649. #define FLAC__WORD_ALL_ONES ((FLAC__uint32)0xffffffff)
  83650. #if WORDS_BIGENDIAN
  83651. #define SWAP_BE_WORD_TO_HOST(x) (x)
  83652. #else
  83653. #ifdef _MSC_VER
  83654. #define SWAP_BE_WORD_TO_HOST(x) local_swap32_(x)
  83655. #else
  83656. #define SWAP_BE_WORD_TO_HOST(x) ntohl(x)
  83657. #endif
  83658. #endif
  83659. static const unsigned FLAC__BITWRITER_DEFAULT_CAPACITY = 32768u / sizeof(bwword); /* size in words */
  83660. static const unsigned FLAC__BITWRITER_DEFAULT_INCREMENT = 4096u / sizeof(bwword); /* size in words */
  83661. #define FLAC__WORDS_TO_BITS(words) ((words) * FLAC__BITS_PER_WORD)
  83662. #define FLAC__TOTAL_BITS(bw) (FLAC__WORDS_TO_BITS((bw)->words) + (bw)->bits)
  83663. #ifdef min
  83664. #undef min
  83665. #endif
  83666. #define min(x,y) ((x)<(y)?(x):(y))
  83667. #ifdef _MSC_VER
  83668. #define FLAC__U64L(x) x
  83669. #else
  83670. #define FLAC__U64L(x) x##LLU
  83671. #endif
  83672. #ifndef FLaC__INLINE
  83673. #define FLaC__INLINE
  83674. #endif
  83675. struct FLAC__BitWriter {
  83676. bwword *buffer;
  83677. bwword accum; /* accumulator; bits are right-justified; when full, accum is appended to buffer */
  83678. unsigned capacity; /* capacity of buffer in words */
  83679. unsigned words; /* # of complete words in buffer */
  83680. unsigned bits; /* # of used bits in accum */
  83681. };
  83682. static FLAC__bool bitwriter_grow_(FLAC__BitWriter *bw, unsigned bits_to_add)
  83683. {
  83684. unsigned new_capacity;
  83685. bwword *new_buffer;
  83686. FLAC__ASSERT(0 != bw);
  83687. FLAC__ASSERT(0 != bw->buffer);
  83688. new_capacity = bw->words + ((bw->bits + bits_to_add + FLAC__BITS_PER_WORD - 1) / FLAC__BITS_PER_WORD);
  83689. if(bw->capacity >= new_capacity)
  83690. return true;
  83691. if((new_capacity - bw->capacity) % FLAC__BITWRITER_DEFAULT_INCREMENT)
  83692. new_capacity += FLAC__BITWRITER_DEFAULT_INCREMENT - ((new_capacity - bw->capacity) % FLAC__BITWRITER_DEFAULT_INCREMENT);
  83693. FLAC__ASSERT(0 == (new_capacity - bw->capacity) % FLAC__BITWRITER_DEFAULT_INCREMENT);
  83694. FLAC__ASSERT(new_capacity > bw->capacity);
  83695. FLAC__ASSERT(new_capacity >= bw->words + ((bw->bits + bits_to_add + FLAC__BITS_PER_WORD - 1) / FLAC__BITS_PER_WORD));
  83696. new_buffer = (bwword*)safe_realloc_mul_2op_(bw->buffer, sizeof(bwword), /*times*/new_capacity);
  83697. if(new_buffer == 0)
  83698. return false;
  83699. bw->buffer = new_buffer;
  83700. bw->capacity = new_capacity;
  83701. return true;
  83702. }
  83703. FLAC__BitWriter *FLAC__bitwriter_new(void)
  83704. {
  83705. FLAC__BitWriter *bw = (FLAC__BitWriter*)calloc(1, sizeof(FLAC__BitWriter));
  83706. return bw;
  83707. }
  83708. void FLAC__bitwriter_delete(FLAC__BitWriter *bw)
  83709. {
  83710. FLAC__ASSERT(0 != bw);
  83711. FLAC__bitwriter_free(bw);
  83712. free(bw);
  83713. }
  83714. FLAC__bool FLAC__bitwriter_init(FLAC__BitWriter *bw)
  83715. {
  83716. FLAC__ASSERT(0 != bw);
  83717. bw->words = bw->bits = 0;
  83718. bw->capacity = FLAC__BITWRITER_DEFAULT_CAPACITY;
  83719. bw->buffer = (bwword*)malloc(sizeof(bwword) * bw->capacity);
  83720. if(bw->buffer == 0)
  83721. return false;
  83722. return true;
  83723. }
  83724. void FLAC__bitwriter_free(FLAC__BitWriter *bw)
  83725. {
  83726. FLAC__ASSERT(0 != bw);
  83727. if(0 != bw->buffer)
  83728. free(bw->buffer);
  83729. bw->buffer = 0;
  83730. bw->capacity = 0;
  83731. bw->words = bw->bits = 0;
  83732. }
  83733. void FLAC__bitwriter_clear(FLAC__BitWriter *bw)
  83734. {
  83735. bw->words = bw->bits = 0;
  83736. }
  83737. void FLAC__bitwriter_dump(const FLAC__BitWriter *bw, FILE *out)
  83738. {
  83739. unsigned i, j;
  83740. if(bw == 0) {
  83741. fprintf(out, "bitwriter is NULL\n");
  83742. }
  83743. else {
  83744. fprintf(out, "bitwriter: capacity=%u words=%u bits=%u total_bits=%u\n", bw->capacity, bw->words, bw->bits, FLAC__TOTAL_BITS(bw));
  83745. for(i = 0; i < bw->words; i++) {
  83746. fprintf(out, "%08X: ", i);
  83747. for(j = 0; j < FLAC__BITS_PER_WORD; j++)
  83748. fprintf(out, "%01u", bw->buffer[i] & (1 << (FLAC__BITS_PER_WORD-j-1)) ? 1:0);
  83749. fprintf(out, "\n");
  83750. }
  83751. if(bw->bits > 0) {
  83752. fprintf(out, "%08X: ", i);
  83753. for(j = 0; j < bw->bits; j++)
  83754. fprintf(out, "%01u", bw->accum & (1 << (bw->bits-j-1)) ? 1:0);
  83755. fprintf(out, "\n");
  83756. }
  83757. }
  83758. }
  83759. FLAC__bool FLAC__bitwriter_get_write_crc16(FLAC__BitWriter *bw, FLAC__uint16 *crc)
  83760. {
  83761. const FLAC__byte *buffer;
  83762. size_t bytes;
  83763. FLAC__ASSERT((bw->bits & 7) == 0); /* assert that we're byte-aligned */
  83764. if(!FLAC__bitwriter_get_buffer(bw, &buffer, &bytes))
  83765. return false;
  83766. *crc = (FLAC__uint16)FLAC__crc16(buffer, bytes);
  83767. FLAC__bitwriter_release_buffer(bw);
  83768. return true;
  83769. }
  83770. FLAC__bool FLAC__bitwriter_get_write_crc8(FLAC__BitWriter *bw, FLAC__byte *crc)
  83771. {
  83772. const FLAC__byte *buffer;
  83773. size_t bytes;
  83774. FLAC__ASSERT((bw->bits & 7) == 0); /* assert that we're byte-aligned */
  83775. if(!FLAC__bitwriter_get_buffer(bw, &buffer, &bytes))
  83776. return false;
  83777. *crc = FLAC__crc8(buffer, bytes);
  83778. FLAC__bitwriter_release_buffer(bw);
  83779. return true;
  83780. }
  83781. FLAC__bool FLAC__bitwriter_is_byte_aligned(const FLAC__BitWriter *bw)
  83782. {
  83783. return ((bw->bits & 7) == 0);
  83784. }
  83785. unsigned FLAC__bitwriter_get_input_bits_unconsumed(const FLAC__BitWriter *bw)
  83786. {
  83787. return FLAC__TOTAL_BITS(bw);
  83788. }
  83789. FLAC__bool FLAC__bitwriter_get_buffer(FLAC__BitWriter *bw, const FLAC__byte **buffer, size_t *bytes)
  83790. {
  83791. FLAC__ASSERT((bw->bits & 7) == 0);
  83792. if(bw->bits & 7)
  83793. return false;
  83794. if(bw->bits) {
  83795. FLAC__ASSERT(bw->words <= bw->capacity);
  83796. if(bw->words == bw->capacity && !bitwriter_grow_(bw, FLAC__BITS_PER_WORD))
  83797. return false;
  83798. bw->buffer[bw->words] = SWAP_BE_WORD_TO_HOST(bw->accum << (FLAC__BITS_PER_WORD-bw->bits));
  83799. }
  83800. *buffer = (FLAC__byte*)bw->buffer;
  83801. *bytes = (FLAC__BYTES_PER_WORD * bw->words) + (bw->bits >> 3);
  83802. return true;
  83803. }
  83804. void FLAC__bitwriter_release_buffer(FLAC__BitWriter *bw)
  83805. {
  83806. (void)bw;
  83807. }
  83808. FLaC__INLINE FLAC__bool FLAC__bitwriter_write_zeroes(FLAC__BitWriter *bw, unsigned bits)
  83809. {
  83810. unsigned n;
  83811. FLAC__ASSERT(0 != bw);
  83812. FLAC__ASSERT(0 != bw->buffer);
  83813. if(bits == 0)
  83814. return true;
  83815. if(bw->capacity <= bw->words + bits && !bitwriter_grow_(bw, bits))
  83816. return false;
  83817. if(bw->bits) {
  83818. n = min(FLAC__BITS_PER_WORD - bw->bits, bits);
  83819. bw->accum <<= n;
  83820. bits -= n;
  83821. bw->bits += n;
  83822. if(bw->bits == FLAC__BITS_PER_WORD) {
  83823. bw->buffer[bw->words++] = SWAP_BE_WORD_TO_HOST(bw->accum);
  83824. bw->bits = 0;
  83825. }
  83826. else
  83827. return true;
  83828. }
  83829. while(bits >= FLAC__BITS_PER_WORD) {
  83830. bw->buffer[bw->words++] = 0;
  83831. bits -= FLAC__BITS_PER_WORD;
  83832. }
  83833. if(bits > 0) {
  83834. bw->accum = 0;
  83835. bw->bits = bits;
  83836. }
  83837. return true;
  83838. }
  83839. FLaC__INLINE FLAC__bool FLAC__bitwriter_write_raw_uint32(FLAC__BitWriter *bw, FLAC__uint32 val, unsigned bits)
  83840. {
  83841. register unsigned left;
  83842. FLAC__ASSERT(FLAC__BITS_PER_WORD >= 32);
  83843. FLAC__ASSERT(0 != bw);
  83844. FLAC__ASSERT(0 != bw->buffer);
  83845. FLAC__ASSERT(bits <= 32);
  83846. if(bits == 0)
  83847. return true;
  83848. if(bw->capacity <= bw->words + bits && !bitwriter_grow_(bw, bits))
  83849. return false;
  83850. left = FLAC__BITS_PER_WORD - bw->bits;
  83851. if(bits < left) {
  83852. bw->accum <<= bits;
  83853. bw->accum |= val;
  83854. bw->bits += bits;
  83855. }
  83856. 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 */
  83857. bw->accum <<= left;
  83858. bw->accum |= val >> (bw->bits = bits - left);
  83859. bw->buffer[bw->words++] = SWAP_BE_WORD_TO_HOST(bw->accum);
  83860. bw->accum = val;
  83861. }
  83862. else {
  83863. bw->accum = val;
  83864. bw->bits = 0;
  83865. bw->buffer[bw->words++] = SWAP_BE_WORD_TO_HOST(val);
  83866. }
  83867. return true;
  83868. }
  83869. FLaC__INLINE FLAC__bool FLAC__bitwriter_write_raw_int32(FLAC__BitWriter *bw, FLAC__int32 val, unsigned bits)
  83870. {
  83871. if(bits < 32)
  83872. val &= (~(0xffffffff << bits));
  83873. return FLAC__bitwriter_write_raw_uint32(bw, (FLAC__uint32)val, bits);
  83874. }
  83875. FLaC__INLINE FLAC__bool FLAC__bitwriter_write_raw_uint64(FLAC__BitWriter *bw, FLAC__uint64 val, unsigned bits)
  83876. {
  83877. if(bits > 32) {
  83878. return
  83879. FLAC__bitwriter_write_raw_uint32(bw, (FLAC__uint32)(val>>32), bits-32) &&
  83880. FLAC__bitwriter_write_raw_uint32(bw, (FLAC__uint32)val, 32);
  83881. }
  83882. else
  83883. return FLAC__bitwriter_write_raw_uint32(bw, (FLAC__uint32)val, bits);
  83884. }
  83885. FLaC__INLINE FLAC__bool FLAC__bitwriter_write_raw_uint32_little_endian(FLAC__BitWriter *bw, FLAC__uint32 val)
  83886. {
  83887. if(!FLAC__bitwriter_write_raw_uint32(bw, val & 0xff, 8))
  83888. return false;
  83889. if(!FLAC__bitwriter_write_raw_uint32(bw, (val>>8) & 0xff, 8))
  83890. return false;
  83891. if(!FLAC__bitwriter_write_raw_uint32(bw, (val>>16) & 0xff, 8))
  83892. return false;
  83893. if(!FLAC__bitwriter_write_raw_uint32(bw, val>>24, 8))
  83894. return false;
  83895. return true;
  83896. }
  83897. FLaC__INLINE FLAC__bool FLAC__bitwriter_write_byte_block(FLAC__BitWriter *bw, const FLAC__byte vals[], unsigned nvals)
  83898. {
  83899. unsigned i;
  83900. for(i = 0; i < nvals; i++) {
  83901. if(!FLAC__bitwriter_write_raw_uint32(bw, (FLAC__uint32)(vals[i]), 8))
  83902. return false;
  83903. }
  83904. return true;
  83905. }
  83906. FLAC__bool FLAC__bitwriter_write_unary_unsigned(FLAC__BitWriter *bw, unsigned val)
  83907. {
  83908. if(val < 32)
  83909. return FLAC__bitwriter_write_raw_uint32(bw, 1, ++val);
  83910. else
  83911. return
  83912. FLAC__bitwriter_write_zeroes(bw, val) &&
  83913. FLAC__bitwriter_write_raw_uint32(bw, 1, 1);
  83914. }
  83915. unsigned FLAC__bitwriter_rice_bits(FLAC__int32 val, unsigned parameter)
  83916. {
  83917. FLAC__uint32 uval;
  83918. FLAC__ASSERT(parameter < sizeof(unsigned)*8);
  83919. uval = (val<<1) ^ (val>>31);
  83920. return 1 + parameter + (uval >> parameter);
  83921. }
  83922. #if 0 /* UNUSED */
  83923. unsigned FLAC__bitwriter_golomb_bits_signed(int val, unsigned parameter)
  83924. {
  83925. unsigned bits, msbs, uval;
  83926. unsigned k;
  83927. FLAC__ASSERT(parameter > 0);
  83928. if(val < 0)
  83929. uval = (unsigned)(((-(++val)) << 1) + 1);
  83930. else
  83931. uval = (unsigned)(val << 1);
  83932. k = FLAC__bitmath_ilog2(parameter);
  83933. if(parameter == 1u<<k) {
  83934. FLAC__ASSERT(k <= 30);
  83935. msbs = uval >> k;
  83936. bits = 1 + k + msbs;
  83937. }
  83938. else {
  83939. unsigned q, r, d;
  83940. d = (1 << (k+1)) - parameter;
  83941. q = uval / parameter;
  83942. r = uval - (q * parameter);
  83943. bits = 1 + q + k;
  83944. if(r >= d)
  83945. bits++;
  83946. }
  83947. return bits;
  83948. }
  83949. unsigned FLAC__bitwriter_golomb_bits_unsigned(unsigned uval, unsigned parameter)
  83950. {
  83951. unsigned bits, msbs;
  83952. unsigned k;
  83953. FLAC__ASSERT(parameter > 0);
  83954. k = FLAC__bitmath_ilog2(parameter);
  83955. if(parameter == 1u<<k) {
  83956. FLAC__ASSERT(k <= 30);
  83957. msbs = uval >> k;
  83958. bits = 1 + k + msbs;
  83959. }
  83960. else {
  83961. unsigned q, r, d;
  83962. d = (1 << (k+1)) - parameter;
  83963. q = uval / parameter;
  83964. r = uval - (q * parameter);
  83965. bits = 1 + q + k;
  83966. if(r >= d)
  83967. bits++;
  83968. }
  83969. return bits;
  83970. }
  83971. #endif /* UNUSED */
  83972. FLAC__bool FLAC__bitwriter_write_rice_signed(FLAC__BitWriter *bw, FLAC__int32 val, unsigned parameter)
  83973. {
  83974. unsigned total_bits, interesting_bits, msbs;
  83975. FLAC__uint32 uval, pattern;
  83976. FLAC__ASSERT(0 != bw);
  83977. FLAC__ASSERT(0 != bw->buffer);
  83978. FLAC__ASSERT(parameter < 8*sizeof(uval));
  83979. uval = (val<<1) ^ (val>>31);
  83980. msbs = uval >> parameter;
  83981. interesting_bits = 1 + parameter;
  83982. total_bits = interesting_bits + msbs;
  83983. pattern = 1 << parameter; /* the unary end bit */
  83984. pattern |= (uval & ((1<<parameter)-1)); /* the binary LSBs */
  83985. if(total_bits <= 32)
  83986. return FLAC__bitwriter_write_raw_uint32(bw, pattern, total_bits);
  83987. else
  83988. return
  83989. FLAC__bitwriter_write_zeroes(bw, msbs) && /* write the unary MSBs */
  83990. FLAC__bitwriter_write_raw_uint32(bw, pattern, interesting_bits); /* write the unary end bit and binary LSBs */
  83991. }
  83992. FLAC__bool FLAC__bitwriter_write_rice_signed_block(FLAC__BitWriter *bw, const FLAC__int32 *vals, unsigned nvals, unsigned parameter)
  83993. {
  83994. const FLAC__uint32 mask1 = FLAC__WORD_ALL_ONES << parameter; /* we val|=mask1 to set the stop bit above it... */
  83995. const FLAC__uint32 mask2 = FLAC__WORD_ALL_ONES >> (31-parameter); /* ...then mask off the bits above the stop bit with val&=mask2*/
  83996. FLAC__uint32 uval;
  83997. unsigned left;
  83998. const unsigned lsbits = 1 + parameter;
  83999. unsigned msbits;
  84000. FLAC__ASSERT(0 != bw);
  84001. FLAC__ASSERT(0 != bw->buffer);
  84002. FLAC__ASSERT(parameter < 8*sizeof(bwword)-1);
  84003. FLAC__ASSERT(FLAC__BITS_PER_WORD >= 32);
  84004. while(nvals) {
  84005. uval = (*vals<<1) ^ (*vals>>31);
  84006. msbits = uval >> parameter;
  84007. #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) */
  84008. if(bw->bits && bw->bits + msbits + lsbits <= FLAC__BITS_PER_WORD) { /* i.e. if the whole thing fits in the current bwword */
  84009. bw->bits = bw->bits + msbits + lsbits;
  84010. uval |= mask1; /* set stop bit */
  84011. uval &= mask2; /* mask off unused top bits */
  84012. bw->accum <<= msbits;
  84013. bw->accum <<= lsbits;
  84014. bw->accum |= uval;
  84015. if(bw->bits == FLAC__BITS_PER_WORD) {
  84016. bw->buffer[bw->words++] = SWAP_BE_WORD_TO_HOST(bw->accum);
  84017. bw->bits = 0;
  84018. if(bw->capacity <= bw->words && nvals > 1 && !bitwriter_grow_(bw, 1)) {
  84019. FLAC__ASSERT(bw->capacity == bw->words);
  84020. return false;
  84021. }
  84022. }
  84023. }
  84024. else {
  84025. #elif 1 /*@@@@@@ OPT: try this version with MSVC6 to see if better, not much difference for gcc-4 */
  84026. if(bw->bits && bw->bits + msbits + lsbits < FLAC__BITS_PER_WORD) { /* i.e. if the whole thing fits in the current bwword */
  84027. bw->bits = bw->bits + msbits + lsbits;
  84028. uval |= mask1; /* set stop bit */
  84029. uval &= mask2; /* mask off unused top bits */
  84030. bw->accum <<= msbits + lsbits;
  84031. bw->accum |= uval;
  84032. }
  84033. else {
  84034. #endif
  84035. if(bw->capacity <= bw->words + bw->bits + msbits + 1/*lsbits always fit in 1 bwword*/ && !bitwriter_grow_(bw, msbits+lsbits))
  84036. return false;
  84037. if(msbits) {
  84038. if(bw->bits) {
  84039. left = FLAC__BITS_PER_WORD - bw->bits;
  84040. if(msbits < left) {
  84041. bw->accum <<= msbits;
  84042. bw->bits += msbits;
  84043. goto break1;
  84044. }
  84045. else {
  84046. bw->accum <<= left;
  84047. msbits -= left;
  84048. bw->buffer[bw->words++] = SWAP_BE_WORD_TO_HOST(bw->accum);
  84049. bw->bits = 0;
  84050. }
  84051. }
  84052. while(msbits >= FLAC__BITS_PER_WORD) {
  84053. bw->buffer[bw->words++] = 0;
  84054. msbits -= FLAC__BITS_PER_WORD;
  84055. }
  84056. if(msbits > 0) {
  84057. bw->accum = 0;
  84058. bw->bits = msbits;
  84059. }
  84060. }
  84061. break1:
  84062. uval |= mask1; /* set stop bit */
  84063. uval &= mask2; /* mask off unused top bits */
  84064. left = FLAC__BITS_PER_WORD - bw->bits;
  84065. if(lsbits < left) {
  84066. bw->accum <<= lsbits;
  84067. bw->accum |= uval;
  84068. bw->bits += lsbits;
  84069. }
  84070. else {
  84071. FLAC__ASSERT(bw->bits);
  84072. FLAC__ASSERT(left < FLAC__BITS_PER_WORD);
  84073. bw->accum <<= left;
  84074. bw->accum |= uval >> (bw->bits = lsbits - left);
  84075. bw->buffer[bw->words++] = SWAP_BE_WORD_TO_HOST(bw->accum);
  84076. bw->accum = uval;
  84077. }
  84078. #if 1
  84079. }
  84080. #endif
  84081. vals++;
  84082. nvals--;
  84083. }
  84084. return true;
  84085. }
  84086. #if 0 /* UNUSED */
  84087. FLAC__bool FLAC__bitwriter_write_golomb_signed(FLAC__BitWriter *bw, int val, unsigned parameter)
  84088. {
  84089. unsigned total_bits, msbs, uval;
  84090. unsigned k;
  84091. FLAC__ASSERT(0 != bw);
  84092. FLAC__ASSERT(0 != bw->buffer);
  84093. FLAC__ASSERT(parameter > 0);
  84094. if(val < 0)
  84095. uval = (unsigned)(((-(++val)) << 1) + 1);
  84096. else
  84097. uval = (unsigned)(val << 1);
  84098. k = FLAC__bitmath_ilog2(parameter);
  84099. if(parameter == 1u<<k) {
  84100. unsigned pattern;
  84101. FLAC__ASSERT(k <= 30);
  84102. msbs = uval >> k;
  84103. total_bits = 1 + k + msbs;
  84104. pattern = 1 << k; /* the unary end bit */
  84105. pattern |= (uval & ((1u<<k)-1)); /* the binary LSBs */
  84106. if(total_bits <= 32) {
  84107. if(!FLAC__bitwriter_write_raw_uint32(bw, pattern, total_bits))
  84108. return false;
  84109. }
  84110. else {
  84111. if(!FLAC__bitwriter_write_zeroes(bw, msbs))
  84112. return false;
  84113. if(!FLAC__bitwriter_write_raw_uint32(bw, pattern, k+1))
  84114. return false;
  84115. }
  84116. }
  84117. else {
  84118. unsigned q, r, d;
  84119. d = (1 << (k+1)) - parameter;
  84120. q = uval / parameter;
  84121. r = uval - (q * parameter);
  84122. if(!FLAC__bitwriter_write_zeroes(bw, q))
  84123. return false;
  84124. if(!FLAC__bitwriter_write_raw_uint32(bw, 1, 1))
  84125. return false;
  84126. if(r >= d) {
  84127. if(!FLAC__bitwriter_write_raw_uint32(bw, r+d, k+1))
  84128. return false;
  84129. }
  84130. else {
  84131. if(!FLAC__bitwriter_write_raw_uint32(bw, r, k))
  84132. return false;
  84133. }
  84134. }
  84135. return true;
  84136. }
  84137. FLAC__bool FLAC__bitwriter_write_golomb_unsigned(FLAC__BitWriter *bw, unsigned uval, unsigned parameter)
  84138. {
  84139. unsigned total_bits, msbs;
  84140. unsigned k;
  84141. FLAC__ASSERT(0 != bw);
  84142. FLAC__ASSERT(0 != bw->buffer);
  84143. FLAC__ASSERT(parameter > 0);
  84144. k = FLAC__bitmath_ilog2(parameter);
  84145. if(parameter == 1u<<k) {
  84146. unsigned pattern;
  84147. FLAC__ASSERT(k <= 30);
  84148. msbs = uval >> k;
  84149. total_bits = 1 + k + msbs;
  84150. pattern = 1 << k; /* the unary end bit */
  84151. pattern |= (uval & ((1u<<k)-1)); /* the binary LSBs */
  84152. if(total_bits <= 32) {
  84153. if(!FLAC__bitwriter_write_raw_uint32(bw, pattern, total_bits))
  84154. return false;
  84155. }
  84156. else {
  84157. if(!FLAC__bitwriter_write_zeroes(bw, msbs))
  84158. return false;
  84159. if(!FLAC__bitwriter_write_raw_uint32(bw, pattern, k+1))
  84160. return false;
  84161. }
  84162. }
  84163. else {
  84164. unsigned q, r, d;
  84165. d = (1 << (k+1)) - parameter;
  84166. q = uval / parameter;
  84167. r = uval - (q * parameter);
  84168. if(!FLAC__bitwriter_write_zeroes(bw, q))
  84169. return false;
  84170. if(!FLAC__bitwriter_write_raw_uint32(bw, 1, 1))
  84171. return false;
  84172. if(r >= d) {
  84173. if(!FLAC__bitwriter_write_raw_uint32(bw, r+d, k+1))
  84174. return false;
  84175. }
  84176. else {
  84177. if(!FLAC__bitwriter_write_raw_uint32(bw, r, k))
  84178. return false;
  84179. }
  84180. }
  84181. return true;
  84182. }
  84183. #endif /* UNUSED */
  84184. FLAC__bool FLAC__bitwriter_write_utf8_uint32(FLAC__BitWriter *bw, FLAC__uint32 val)
  84185. {
  84186. FLAC__bool ok = 1;
  84187. FLAC__ASSERT(0 != bw);
  84188. FLAC__ASSERT(0 != bw->buffer);
  84189. FLAC__ASSERT(!(val & 0x80000000)); /* this version only handles 31 bits */
  84190. if(val < 0x80) {
  84191. return FLAC__bitwriter_write_raw_uint32(bw, val, 8);
  84192. }
  84193. else if(val < 0x800) {
  84194. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0xC0 | (val>>6), 8);
  84195. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (val&0x3F), 8);
  84196. }
  84197. else if(val < 0x10000) {
  84198. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0xE0 | (val>>12), 8);
  84199. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | ((val>>6)&0x3F), 8);
  84200. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (val&0x3F), 8);
  84201. }
  84202. else if(val < 0x200000) {
  84203. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0xF0 | (val>>18), 8);
  84204. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | ((val>>12)&0x3F), 8);
  84205. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | ((val>>6)&0x3F), 8);
  84206. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (val&0x3F), 8);
  84207. }
  84208. else if(val < 0x4000000) {
  84209. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0xF8 | (val>>24), 8);
  84210. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | ((val>>18)&0x3F), 8);
  84211. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | ((val>>12)&0x3F), 8);
  84212. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | ((val>>6)&0x3F), 8);
  84213. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (val&0x3F), 8);
  84214. }
  84215. else {
  84216. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0xFC | (val>>30), 8);
  84217. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | ((val>>24)&0x3F), 8);
  84218. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | ((val>>18)&0x3F), 8);
  84219. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | ((val>>12)&0x3F), 8);
  84220. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | ((val>>6)&0x3F), 8);
  84221. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (val&0x3F), 8);
  84222. }
  84223. return ok;
  84224. }
  84225. FLAC__bool FLAC__bitwriter_write_utf8_uint64(FLAC__BitWriter *bw, FLAC__uint64 val)
  84226. {
  84227. FLAC__bool ok = 1;
  84228. FLAC__ASSERT(0 != bw);
  84229. FLAC__ASSERT(0 != bw->buffer);
  84230. FLAC__ASSERT(!(val & FLAC__U64L(0xFFFFFFF000000000))); /* this version only handles 36 bits */
  84231. if(val < 0x80) {
  84232. return FLAC__bitwriter_write_raw_uint32(bw, (FLAC__uint32)val, 8);
  84233. }
  84234. else if(val < 0x800) {
  84235. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0xC0 | (FLAC__uint32)(val>>6), 8);
  84236. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)(val&0x3F), 8);
  84237. }
  84238. else if(val < 0x10000) {
  84239. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0xE0 | (FLAC__uint32)(val>>12), 8);
  84240. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>6)&0x3F), 8);
  84241. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)(val&0x3F), 8);
  84242. }
  84243. else if(val < 0x200000) {
  84244. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0xF0 | (FLAC__uint32)(val>>18), 8);
  84245. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>12)&0x3F), 8);
  84246. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>6)&0x3F), 8);
  84247. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)(val&0x3F), 8);
  84248. }
  84249. else if(val < 0x4000000) {
  84250. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0xF8 | (FLAC__uint32)(val>>24), 8);
  84251. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>18)&0x3F), 8);
  84252. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>12)&0x3F), 8);
  84253. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>6)&0x3F), 8);
  84254. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)(val&0x3F), 8);
  84255. }
  84256. else if(val < 0x80000000) {
  84257. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0xFC | (FLAC__uint32)(val>>30), 8);
  84258. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>24)&0x3F), 8);
  84259. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>18)&0x3F), 8);
  84260. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>12)&0x3F), 8);
  84261. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>6)&0x3F), 8);
  84262. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)(val&0x3F), 8);
  84263. }
  84264. else {
  84265. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0xFE, 8);
  84266. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>30)&0x3F), 8);
  84267. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>24)&0x3F), 8);
  84268. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>18)&0x3F), 8);
  84269. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>12)&0x3F), 8);
  84270. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>6)&0x3F), 8);
  84271. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)(val&0x3F), 8);
  84272. }
  84273. return ok;
  84274. }
  84275. FLAC__bool FLAC__bitwriter_zero_pad_to_byte_boundary(FLAC__BitWriter *bw)
  84276. {
  84277. if(bw->bits & 7u)
  84278. return FLAC__bitwriter_write_zeroes(bw, 8 - (bw->bits & 7u));
  84279. else
  84280. return true;
  84281. }
  84282. #endif
  84283. /********* End of inlined file: bitwriter.c *********/
  84284. /********* Start of inlined file: cpu.c *********/
  84285. /********* Start of inlined file: juce_FlacHeader.h *********/
  84286. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  84287. // tasks..
  84288. #define VERSION "1.2.1"
  84289. #define FLAC__NO_DLL 1
  84290. #if JUCE_MSVC
  84291. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  84292. #endif
  84293. #if JUCE_MAC
  84294. #define FLAC__SYS_DARWIN 1
  84295. #endif
  84296. /********* End of inlined file: juce_FlacHeader.h *********/
  84297. #if JUCE_USE_FLAC
  84298. #if HAVE_CONFIG_H
  84299. # include <config.h>
  84300. #endif
  84301. #include <stdlib.h>
  84302. #include <stdio.h>
  84303. #if defined FLAC__CPU_IA32
  84304. # include <signal.h>
  84305. #elif defined FLAC__CPU_PPC
  84306. # if !defined FLAC__NO_ASM
  84307. # if defined FLAC__SYS_DARWIN
  84308. # include <sys/sysctl.h>
  84309. # include <mach/mach.h>
  84310. # include <mach/mach_host.h>
  84311. # include <mach/host_info.h>
  84312. # include <mach/machine.h>
  84313. # ifndef CPU_SUBTYPE_POWERPC_970
  84314. # define CPU_SUBTYPE_POWERPC_970 ((cpu_subtype_t) 100)
  84315. # endif
  84316. # else /* FLAC__SYS_DARWIN */
  84317. # include <signal.h>
  84318. # include <setjmp.h>
  84319. static sigjmp_buf jmpbuf;
  84320. static volatile sig_atomic_t canjump = 0;
  84321. static void sigill_handler (int sig)
  84322. {
  84323. if (!canjump) {
  84324. signal (sig, SIG_DFL);
  84325. raise (sig);
  84326. }
  84327. canjump = 0;
  84328. siglongjmp (jmpbuf, 1);
  84329. }
  84330. # endif /* FLAC__SYS_DARWIN */
  84331. # endif /* FLAC__NO_ASM */
  84332. #endif /* FLAC__CPU_PPC */
  84333. #if defined (__NetBSD__) || defined(__OpenBSD__)
  84334. #include <sys/param.h>
  84335. #include <sys/sysctl.h>
  84336. #include <machine/cpu.h>
  84337. #endif
  84338. #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__)
  84339. #include <sys/types.h>
  84340. #include <sys/sysctl.h>
  84341. #endif
  84342. #if defined(__APPLE__)
  84343. #endif
  84344. static const unsigned FLAC__CPUINFO_IA32_CPUID_CMOV = 0x00008000;
  84345. static const unsigned FLAC__CPUINFO_IA32_CPUID_MMX = 0x00800000;
  84346. static const unsigned FLAC__CPUINFO_IA32_CPUID_FXSR = 0x01000000;
  84347. static const unsigned FLAC__CPUINFO_IA32_CPUID_SSE = 0x02000000;
  84348. static const unsigned FLAC__CPUINFO_IA32_CPUID_SSE2 = 0x04000000;
  84349. static const unsigned FLAC__CPUINFO_IA32_CPUID_SSE3 = 0x00000001;
  84350. static const unsigned FLAC__CPUINFO_IA32_CPUID_SSSE3 = 0x00000200;
  84351. static const unsigned FLAC__CPUINFO_IA32_CPUID_EXTENDED_AMD_3DNOW = 0x80000000;
  84352. static const unsigned FLAC__CPUINFO_IA32_CPUID_EXTENDED_AMD_EXT3DNOW = 0x40000000;
  84353. static const unsigned FLAC__CPUINFO_IA32_CPUID_EXTENDED_AMD_EXTMMX = 0x00400000;
  84354. #if defined(FLAC__CPU_IA32) && !defined FLAC__NO_ASM && defined FLAC__HAS_NASM && !defined FLAC__NO_SSE_OS && !defined FLAC__SSE_OS
  84355. # if defined(__linux__)
  84356. # undef USE_OBSOLETE_SIGCONTEXT_FLAVOR /* #define this to use the older signal handler method */
  84357. # ifdef USE_OBSOLETE_SIGCONTEXT_FLAVOR
  84358. static void sigill_handler_sse_os(int signal, struct sigcontext sc)
  84359. {
  84360. (void)signal;
  84361. sc.eip += 3 + 3 + 6;
  84362. }
  84363. # else
  84364. # include <sys/ucontext.h>
  84365. static void sigill_handler_sse_os(int signal, siginfo_t *si, void *uc)
  84366. {
  84367. (void)signal, (void)si;
  84368. ((ucontext_t*)uc)->uc_mcontext.gregs[14/*REG_EIP*/] += 3 + 3 + 6;
  84369. }
  84370. # endif
  84371. # elif defined(_MSC_VER)
  84372. # include <windows.h>
  84373. # undef USE_TRY_CATCH_FLAVOR /* #define this to use the try/catch method for catching illegal opcode exception */
  84374. # ifdef USE_TRY_CATCH_FLAVOR
  84375. # else
  84376. LONG CALLBACK sigill_handler_sse_os(EXCEPTION_POINTERS *ep)
  84377. {
  84378. if(ep->ExceptionRecord->ExceptionCode == EXCEPTION_ILLEGAL_INSTRUCTION) {
  84379. ep->ContextRecord->Eip += 3 + 3 + 6;
  84380. return EXCEPTION_CONTINUE_EXECUTION;
  84381. }
  84382. return EXCEPTION_CONTINUE_SEARCH;
  84383. }
  84384. # endif
  84385. # endif
  84386. #endif
  84387. void FLAC__cpu_info(FLAC__CPUInfo *info)
  84388. {
  84389. #ifdef FLAC__CPU_IA32
  84390. info->type = FLAC__CPUINFO_TYPE_IA32;
  84391. #if !defined FLAC__NO_ASM && defined FLAC__HAS_NASM
  84392. info->use_asm = true; /* we assume a minimum of 80386 with FLAC__CPU_IA32 */
  84393. info->data.ia32.cpuid = FLAC__cpu_have_cpuid_asm_ia32()? true : false;
  84394. info->data.ia32.bswap = info->data.ia32.cpuid; /* CPUID => BSWAP since it came after */
  84395. info->data.ia32.cmov = false;
  84396. info->data.ia32.mmx = false;
  84397. info->data.ia32.fxsr = false;
  84398. info->data.ia32.sse = false;
  84399. info->data.ia32.sse2 = false;
  84400. info->data.ia32.sse3 = false;
  84401. info->data.ia32.ssse3 = false;
  84402. info->data.ia32._3dnow = false;
  84403. info->data.ia32.ext3dnow = false;
  84404. info->data.ia32.extmmx = false;
  84405. if(info->data.ia32.cpuid) {
  84406. FLAC__uint32 flags_edx, flags_ecx;
  84407. FLAC__cpu_info_asm_ia32(&flags_edx, &flags_ecx);
  84408. info->data.ia32.cmov = (flags_edx & FLAC__CPUINFO_IA32_CPUID_CMOV )? true : false;
  84409. info->data.ia32.mmx = (flags_edx & FLAC__CPUINFO_IA32_CPUID_MMX )? true : false;
  84410. info->data.ia32.fxsr = (flags_edx & FLAC__CPUINFO_IA32_CPUID_FXSR )? true : false;
  84411. info->data.ia32.sse = (flags_edx & FLAC__CPUINFO_IA32_CPUID_SSE )? true : false;
  84412. info->data.ia32.sse2 = (flags_edx & FLAC__CPUINFO_IA32_CPUID_SSE2 )? true : false;
  84413. info->data.ia32.sse3 = (flags_ecx & FLAC__CPUINFO_IA32_CPUID_SSE3 )? true : false;
  84414. info->data.ia32.ssse3 = (flags_ecx & FLAC__CPUINFO_IA32_CPUID_SSSE3)? true : false;
  84415. #ifdef FLAC__USE_3DNOW
  84416. flags_edx = FLAC__cpu_info_extended_amd_asm_ia32();
  84417. info->data.ia32._3dnow = (flags_edx & FLAC__CPUINFO_IA32_CPUID_EXTENDED_AMD_3DNOW )? true : false;
  84418. info->data.ia32.ext3dnow = (flags_edx & FLAC__CPUINFO_IA32_CPUID_EXTENDED_AMD_EXT3DNOW)? true : false;
  84419. info->data.ia32.extmmx = (flags_edx & FLAC__CPUINFO_IA32_CPUID_EXTENDED_AMD_EXTMMX )? true : false;
  84420. #else
  84421. info->data.ia32._3dnow = info->data.ia32.ext3dnow = info->data.ia32.extmmx = false;
  84422. #endif
  84423. #ifdef DEBUG
  84424. fprintf(stderr, "CPU info (IA-32):\n");
  84425. fprintf(stderr, " CPUID ...... %c\n", info->data.ia32.cpuid ? 'Y' : 'n');
  84426. fprintf(stderr, " BSWAP ...... %c\n", info->data.ia32.bswap ? 'Y' : 'n');
  84427. fprintf(stderr, " CMOV ....... %c\n", info->data.ia32.cmov ? 'Y' : 'n');
  84428. fprintf(stderr, " MMX ........ %c\n", info->data.ia32.mmx ? 'Y' : 'n');
  84429. fprintf(stderr, " FXSR ....... %c\n", info->data.ia32.fxsr ? 'Y' : 'n');
  84430. fprintf(stderr, " SSE ........ %c\n", info->data.ia32.sse ? 'Y' : 'n');
  84431. fprintf(stderr, " SSE2 ....... %c\n", info->data.ia32.sse2 ? 'Y' : 'n');
  84432. fprintf(stderr, " SSE3 ....... %c\n", info->data.ia32.sse3 ? 'Y' : 'n');
  84433. fprintf(stderr, " SSSE3 ...... %c\n", info->data.ia32.ssse3 ? 'Y' : 'n');
  84434. fprintf(stderr, " 3DNow! ..... %c\n", info->data.ia32._3dnow ? 'Y' : 'n');
  84435. fprintf(stderr, " 3DNow!-ext . %c\n", info->data.ia32.ext3dnow? 'Y' : 'n');
  84436. fprintf(stderr, " 3DNow!-MMX . %c\n", info->data.ia32.extmmx ? 'Y' : 'n');
  84437. #endif
  84438. if(info->data.ia32.fxsr || info->data.ia32.sse || info->data.ia32.sse2) {
  84439. #if defined FLAC__NO_SSE_OS
  84440. info->data.ia32.fxsr = info->data.ia32.sse = info->data.ia32.sse2 = info->data.ia32.sse3 = info->data.ia32.ssse3 = false;
  84441. #elif defined FLAC__SSE_OS
  84442. #elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__) || defined(__APPLE__)
  84443. int sse = 0;
  84444. size_t len;
  84445. len = sizeof(sse); sse = sse || (sysctlbyname("hw.instruction_sse", &sse, &len, NULL, 0) == 0 && sse);
  84446. len = sizeof(sse); sse = sse || (sysctlbyname("hw.optional.sse" , &sse, &len, NULL, 0) == 0 && sse); /* __APPLE__ ? */
  84447. if(!sse)
  84448. info->data.ia32.fxsr = info->data.ia32.sse = info->data.ia32.sse2 = info->data.ia32.sse3 = info->data.ia32.ssse3 = false;
  84449. #elif defined(__NetBSD__) || defined (__OpenBSD__)
  84450. # if __NetBSD_Version__ >= 105250000 || (defined __OpenBSD__)
  84451. int val = 0, mib[2] = { CTL_MACHDEP, CPU_SSE };
  84452. size_t len = sizeof(val);
  84453. if(sysctl(mib, 2, &val, &len, NULL, 0) < 0 || !val)
  84454. info->data.ia32.fxsr = info->data.ia32.sse = info->data.ia32.sse2 = info->data.ia32.sse3 = info->data.ia32.ssse3 = false;
  84455. else { /* double-check SSE2 */
  84456. mib[1] = CPU_SSE2;
  84457. len = sizeof(val);
  84458. if(sysctl(mib, 2, &val, &len, NULL, 0) < 0 || !val)
  84459. info->data.ia32.sse2 = info->data.ia32.sse3 = info->data.ia32.ssse3 = false;
  84460. }
  84461. # else
  84462. info->data.ia32.fxsr = info->data.ia32.sse = info->data.ia32.sse2 = info->data.ia32.sse3 = info->data.ia32.ssse3 = false;
  84463. # endif
  84464. #elif defined(__linux__)
  84465. int sse = 0;
  84466. struct sigaction sigill_save;
  84467. #ifdef USE_OBSOLETE_SIGCONTEXT_FLAVOR
  84468. if(0 == sigaction(SIGILL, NULL, &sigill_save) && signal(SIGILL, (void (*)(int))sigill_handler_sse_os) != SIG_ERR)
  84469. #else
  84470. struct sigaction sigill_sse;
  84471. sigill_sse.sa_sigaction = sigill_handler_sse_os;
  84472. __sigemptyset(&sigill_sse.sa_mask);
  84473. 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 */
  84474. if(0 == sigaction(SIGILL, &sigill_sse, &sigill_save))
  84475. #endif
  84476. {
  84477. asm volatile (
  84478. "xorl %0,%0\n\t" /* for some reason, still need to do this to clear 'sse' var */
  84479. "xorps %%xmm0,%%xmm0\n\t" /* will cause SIGILL if unsupported by OS */
  84480. "incl %0\n\t" /* SIGILL handler will jump over this */
  84481. "nop\n\t" /* SIGILL jump lands here if "inc" is 9 bytes */
  84482. "nop\n\t"
  84483. "nop\n\t"
  84484. "nop\n\t"
  84485. "nop\n\t"
  84486. "nop\n\t"
  84487. "nop\n\t" /* SIGILL jump lands here if "inc" is 3 bytes (expected) */
  84488. "nop\n\t"
  84489. "nop" /* SIGILL jump lands here if "inc" is 1 byte */
  84490. : "=r"(sse)
  84491. : "r"(sse)
  84492. );
  84493. sigaction(SIGILL, &sigill_save, NULL);
  84494. }
  84495. if(!sse)
  84496. info->data.ia32.fxsr = info->data.ia32.sse = info->data.ia32.sse2 = info->data.ia32.sse3 = info->data.ia32.ssse3 = false;
  84497. #elif defined(_MSC_VER)
  84498. # ifdef USE_TRY_CATCH_FLAVOR
  84499. _try {
  84500. __asm {
  84501. # if _MSC_VER <= 1200
  84502. _emit 0x0F
  84503. _emit 0x57
  84504. _emit 0xC0
  84505. # else
  84506. xorps xmm0,xmm0
  84507. # endif
  84508. }
  84509. }
  84510. _except(EXCEPTION_EXECUTE_HANDLER) {
  84511. if (_exception_code() == STATUS_ILLEGAL_INSTRUCTION)
  84512. info->data.ia32.fxsr = info->data.ia32.sse = info->data.ia32.sse2 = info->data.ia32.sse3 = info->data.ia32.ssse3 = false;
  84513. }
  84514. # else
  84515. int sse = 0;
  84516. LPTOP_LEVEL_EXCEPTION_FILTER save = SetUnhandledExceptionFilter(sigill_handler_sse_os);
  84517. __asm {
  84518. # if _MSC_VER <= 1200
  84519. _emit 0x0F
  84520. _emit 0x57
  84521. _emit 0xC0
  84522. # else
  84523. xorps xmm0,xmm0
  84524. # endif
  84525. inc sse
  84526. nop
  84527. nop
  84528. nop
  84529. nop
  84530. nop
  84531. nop
  84532. nop
  84533. nop
  84534. nop
  84535. }
  84536. SetUnhandledExceptionFilter(save);
  84537. if(!sse)
  84538. info->data.ia32.fxsr = info->data.ia32.sse = info->data.ia32.sse2 = info->data.ia32.sse3 = info->data.ia32.ssse3 = false;
  84539. # endif
  84540. #else
  84541. info->data.ia32.fxsr = info->data.ia32.sse = info->data.ia32.sse2 = info->data.ia32.sse3 = info->data.ia32.ssse3 = false;
  84542. #endif
  84543. #ifdef DEBUG
  84544. fprintf(stderr, " SSE OS sup . %c\n", info->data.ia32.sse ? 'Y' : 'n');
  84545. #endif
  84546. }
  84547. }
  84548. #else
  84549. info->use_asm = false;
  84550. #endif
  84551. #elif defined FLAC__CPU_PPC
  84552. info->type = FLAC__CPUINFO_TYPE_PPC;
  84553. # if !defined FLAC__NO_ASM
  84554. info->use_asm = true;
  84555. # ifdef FLAC__USE_ALTIVEC
  84556. # if defined FLAC__SYS_DARWIN
  84557. {
  84558. int val = 0, mib[2] = { CTL_HW, HW_VECTORUNIT };
  84559. size_t len = sizeof(val);
  84560. info->data.ppc.altivec = !(sysctl(mib, 2, &val, &len, NULL, 0) || !val);
  84561. }
  84562. {
  84563. host_basic_info_data_t hostInfo;
  84564. mach_msg_type_number_t infoCount;
  84565. infoCount = HOST_BASIC_INFO_COUNT;
  84566. host_info(mach_host_self(), HOST_BASIC_INFO, (host_info_t)&hostInfo, &infoCount);
  84567. info->data.ppc.ppc64 = (hostInfo.cpu_type == CPU_TYPE_POWERPC) && (hostInfo.cpu_subtype == CPU_SUBTYPE_POWERPC_970);
  84568. }
  84569. # else /* FLAC__USE_ALTIVEC && !FLAC__SYS_DARWIN */
  84570. {
  84571. info->data.ppc.altivec = 0;
  84572. info->data.ppc.ppc64 = 0;
  84573. signal (SIGILL, sigill_handler);
  84574. canjump = 0;
  84575. if (!sigsetjmp (jmpbuf, 1)) {
  84576. canjump = 1;
  84577. asm volatile (
  84578. "mtspr 256, %0\n\t"
  84579. "vand %%v0, %%v0, %%v0"
  84580. :
  84581. : "r" (-1)
  84582. );
  84583. info->data.ppc.altivec = 1;
  84584. }
  84585. canjump = 0;
  84586. if (!sigsetjmp (jmpbuf, 1)) {
  84587. int x = 0;
  84588. canjump = 1;
  84589. asm volatile ("cntlzd %0, %1" : "=r" (x) : "r" (x) );
  84590. info->data.ppc.ppc64 = 1;
  84591. }
  84592. signal (SIGILL, SIG_DFL); /*@@@@@@ should save and restore old signal */
  84593. }
  84594. # endif
  84595. # else /* !FLAC__USE_ALTIVEC */
  84596. info->data.ppc.altivec = 0;
  84597. info->data.ppc.ppc64 = 0;
  84598. # endif
  84599. # else
  84600. info->use_asm = false;
  84601. # endif
  84602. #else
  84603. info->type = FLAC__CPUINFO_TYPE_UNKNOWN;
  84604. info->use_asm = false;
  84605. #endif
  84606. }
  84607. #endif
  84608. /********* End of inlined file: cpu.c *********/
  84609. /********* Start of inlined file: crc.c *********/
  84610. /********* Start of inlined file: juce_FlacHeader.h *********/
  84611. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  84612. // tasks..
  84613. #define VERSION "1.2.1"
  84614. #define FLAC__NO_DLL 1
  84615. #if JUCE_MSVC
  84616. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  84617. #endif
  84618. #if JUCE_MAC
  84619. #define FLAC__SYS_DARWIN 1
  84620. #endif
  84621. /********* End of inlined file: juce_FlacHeader.h *********/
  84622. #if JUCE_USE_FLAC
  84623. #if HAVE_CONFIG_H
  84624. # include <config.h>
  84625. #endif
  84626. FLAC__byte const FLAC__crc8_table[256] = {
  84627. 0x00, 0x07, 0x0E, 0x09, 0x1C, 0x1B, 0x12, 0x15,
  84628. 0x38, 0x3F, 0x36, 0x31, 0x24, 0x23, 0x2A, 0x2D,
  84629. 0x70, 0x77, 0x7E, 0x79, 0x6C, 0x6B, 0x62, 0x65,
  84630. 0x48, 0x4F, 0x46, 0x41, 0x54, 0x53, 0x5A, 0x5D,
  84631. 0xE0, 0xE7, 0xEE, 0xE9, 0xFC, 0xFB, 0xF2, 0xF5,
  84632. 0xD8, 0xDF, 0xD6, 0xD1, 0xC4, 0xC3, 0xCA, 0xCD,
  84633. 0x90, 0x97, 0x9E, 0x99, 0x8C, 0x8B, 0x82, 0x85,
  84634. 0xA8, 0xAF, 0xA6, 0xA1, 0xB4, 0xB3, 0xBA, 0xBD,
  84635. 0xC7, 0xC0, 0xC9, 0xCE, 0xDB, 0xDC, 0xD5, 0xD2,
  84636. 0xFF, 0xF8, 0xF1, 0xF6, 0xE3, 0xE4, 0xED, 0xEA,
  84637. 0xB7, 0xB0, 0xB9, 0xBE, 0xAB, 0xAC, 0xA5, 0xA2,
  84638. 0x8F, 0x88, 0x81, 0x86, 0x93, 0x94, 0x9D, 0x9A,
  84639. 0x27, 0x20, 0x29, 0x2E, 0x3B, 0x3C, 0x35, 0x32,
  84640. 0x1F, 0x18, 0x11, 0x16, 0x03, 0x04, 0x0D, 0x0A,
  84641. 0x57, 0x50, 0x59, 0x5E, 0x4B, 0x4C, 0x45, 0x42,
  84642. 0x6F, 0x68, 0x61, 0x66, 0x73, 0x74, 0x7D, 0x7A,
  84643. 0x89, 0x8E, 0x87, 0x80, 0x95, 0x92, 0x9B, 0x9C,
  84644. 0xB1, 0xB6, 0xBF, 0xB8, 0xAD, 0xAA, 0xA3, 0xA4,
  84645. 0xF9, 0xFE, 0xF7, 0xF0, 0xE5, 0xE2, 0xEB, 0xEC,
  84646. 0xC1, 0xC6, 0xCF, 0xC8, 0xDD, 0xDA, 0xD3, 0xD4,
  84647. 0x69, 0x6E, 0x67, 0x60, 0x75, 0x72, 0x7B, 0x7C,
  84648. 0x51, 0x56, 0x5F, 0x58, 0x4D, 0x4A, 0x43, 0x44,
  84649. 0x19, 0x1E, 0x17, 0x10, 0x05, 0x02, 0x0B, 0x0C,
  84650. 0x21, 0x26, 0x2F, 0x28, 0x3D, 0x3A, 0x33, 0x34,
  84651. 0x4E, 0x49, 0x40, 0x47, 0x52, 0x55, 0x5C, 0x5B,
  84652. 0x76, 0x71, 0x78, 0x7F, 0x6A, 0x6D, 0x64, 0x63,
  84653. 0x3E, 0x39, 0x30, 0x37, 0x22, 0x25, 0x2C, 0x2B,
  84654. 0x06, 0x01, 0x08, 0x0F, 0x1A, 0x1D, 0x14, 0x13,
  84655. 0xAE, 0xA9, 0xA0, 0xA7, 0xB2, 0xB5, 0xBC, 0xBB,
  84656. 0x96, 0x91, 0x98, 0x9F, 0x8A, 0x8D, 0x84, 0x83,
  84657. 0xDE, 0xD9, 0xD0, 0xD7, 0xC2, 0xC5, 0xCC, 0xCB,
  84658. 0xE6, 0xE1, 0xE8, 0xEF, 0xFA, 0xFD, 0xF4, 0xF3
  84659. };
  84660. unsigned FLAC__crc16_table[256] = {
  84661. 0x0000, 0x8005, 0x800f, 0x000a, 0x801b, 0x001e, 0x0014, 0x8011,
  84662. 0x8033, 0x0036, 0x003c, 0x8039, 0x0028, 0x802d, 0x8027, 0x0022,
  84663. 0x8063, 0x0066, 0x006c, 0x8069, 0x0078, 0x807d, 0x8077, 0x0072,
  84664. 0x0050, 0x8055, 0x805f, 0x005a, 0x804b, 0x004e, 0x0044, 0x8041,
  84665. 0x80c3, 0x00c6, 0x00cc, 0x80c9, 0x00d8, 0x80dd, 0x80d7, 0x00d2,
  84666. 0x00f0, 0x80f5, 0x80ff, 0x00fa, 0x80eb, 0x00ee, 0x00e4, 0x80e1,
  84667. 0x00a0, 0x80a5, 0x80af, 0x00aa, 0x80bb, 0x00be, 0x00b4, 0x80b1,
  84668. 0x8093, 0x0096, 0x009c, 0x8099, 0x0088, 0x808d, 0x8087, 0x0082,
  84669. 0x8183, 0x0186, 0x018c, 0x8189, 0x0198, 0x819d, 0x8197, 0x0192,
  84670. 0x01b0, 0x81b5, 0x81bf, 0x01ba, 0x81ab, 0x01ae, 0x01a4, 0x81a1,
  84671. 0x01e0, 0x81e5, 0x81ef, 0x01ea, 0x81fb, 0x01fe, 0x01f4, 0x81f1,
  84672. 0x81d3, 0x01d6, 0x01dc, 0x81d9, 0x01c8, 0x81cd, 0x81c7, 0x01c2,
  84673. 0x0140, 0x8145, 0x814f, 0x014a, 0x815b, 0x015e, 0x0154, 0x8151,
  84674. 0x8173, 0x0176, 0x017c, 0x8179, 0x0168, 0x816d, 0x8167, 0x0162,
  84675. 0x8123, 0x0126, 0x012c, 0x8129, 0x0138, 0x813d, 0x8137, 0x0132,
  84676. 0x0110, 0x8115, 0x811f, 0x011a, 0x810b, 0x010e, 0x0104, 0x8101,
  84677. 0x8303, 0x0306, 0x030c, 0x8309, 0x0318, 0x831d, 0x8317, 0x0312,
  84678. 0x0330, 0x8335, 0x833f, 0x033a, 0x832b, 0x032e, 0x0324, 0x8321,
  84679. 0x0360, 0x8365, 0x836f, 0x036a, 0x837b, 0x037e, 0x0374, 0x8371,
  84680. 0x8353, 0x0356, 0x035c, 0x8359, 0x0348, 0x834d, 0x8347, 0x0342,
  84681. 0x03c0, 0x83c5, 0x83cf, 0x03ca, 0x83db, 0x03de, 0x03d4, 0x83d1,
  84682. 0x83f3, 0x03f6, 0x03fc, 0x83f9, 0x03e8, 0x83ed, 0x83e7, 0x03e2,
  84683. 0x83a3, 0x03a6, 0x03ac, 0x83a9, 0x03b8, 0x83bd, 0x83b7, 0x03b2,
  84684. 0x0390, 0x8395, 0x839f, 0x039a, 0x838b, 0x038e, 0x0384, 0x8381,
  84685. 0x0280, 0x8285, 0x828f, 0x028a, 0x829b, 0x029e, 0x0294, 0x8291,
  84686. 0x82b3, 0x02b6, 0x02bc, 0x82b9, 0x02a8, 0x82ad, 0x82a7, 0x02a2,
  84687. 0x82e3, 0x02e6, 0x02ec, 0x82e9, 0x02f8, 0x82fd, 0x82f7, 0x02f2,
  84688. 0x02d0, 0x82d5, 0x82df, 0x02da, 0x82cb, 0x02ce, 0x02c4, 0x82c1,
  84689. 0x8243, 0x0246, 0x024c, 0x8249, 0x0258, 0x825d, 0x8257, 0x0252,
  84690. 0x0270, 0x8275, 0x827f, 0x027a, 0x826b, 0x026e, 0x0264, 0x8261,
  84691. 0x0220, 0x8225, 0x822f, 0x022a, 0x823b, 0x023e, 0x0234, 0x8231,
  84692. 0x8213, 0x0216, 0x021c, 0x8219, 0x0208, 0x820d, 0x8207, 0x0202
  84693. };
  84694. void FLAC__crc8_update(const FLAC__byte data, FLAC__uint8 *crc)
  84695. {
  84696. *crc = FLAC__crc8_table[*crc ^ data];
  84697. }
  84698. void FLAC__crc8_update_block(const FLAC__byte *data, unsigned len, FLAC__uint8 *crc)
  84699. {
  84700. while(len--)
  84701. *crc = FLAC__crc8_table[*crc ^ *data++];
  84702. }
  84703. FLAC__uint8 FLAC__crc8(const FLAC__byte *data, unsigned len)
  84704. {
  84705. FLAC__uint8 crc = 0;
  84706. while(len--)
  84707. crc = FLAC__crc8_table[crc ^ *data++];
  84708. return crc;
  84709. }
  84710. unsigned FLAC__crc16(const FLAC__byte *data, unsigned len)
  84711. {
  84712. unsigned crc = 0;
  84713. while(len--)
  84714. crc = ((crc<<8) ^ FLAC__crc16_table[(crc>>8) ^ *data++]) & 0xffff;
  84715. return crc;
  84716. }
  84717. #endif
  84718. /********* End of inlined file: crc.c *********/
  84719. /********* Start of inlined file: fixed.c *********/
  84720. /********* Start of inlined file: juce_FlacHeader.h *********/
  84721. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  84722. // tasks..
  84723. #define VERSION "1.2.1"
  84724. #define FLAC__NO_DLL 1
  84725. #if JUCE_MSVC
  84726. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  84727. #endif
  84728. #if JUCE_MAC
  84729. #define FLAC__SYS_DARWIN 1
  84730. #endif
  84731. /********* End of inlined file: juce_FlacHeader.h *********/
  84732. #if JUCE_USE_FLAC
  84733. #if HAVE_CONFIG_H
  84734. # include <config.h>
  84735. #endif
  84736. #include <math.h>
  84737. #include <string.h>
  84738. /********* Start of inlined file: fixed.h *********/
  84739. #ifndef FLAC__PRIVATE__FIXED_H
  84740. #define FLAC__PRIVATE__FIXED_H
  84741. #ifdef HAVE_CONFIG_H
  84742. #include <config.h>
  84743. #endif
  84744. /********* Start of inlined file: float.h *********/
  84745. #ifndef FLAC__PRIVATE__FLOAT_H
  84746. #define FLAC__PRIVATE__FLOAT_H
  84747. #ifdef HAVE_CONFIG_H
  84748. #include <config.h>
  84749. #endif
  84750. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  84751. typedef double FLAC__double;
  84752. typedef float FLAC__float;
  84753. typedef float FLAC__real;
  84754. #else
  84755. typedef FLAC__int32 FLAC__fixedpoint;
  84756. extern const FLAC__fixedpoint FLAC__FP_ZERO;
  84757. extern const FLAC__fixedpoint FLAC__FP_ONE_HALF;
  84758. extern const FLAC__fixedpoint FLAC__FP_ONE;
  84759. extern const FLAC__fixedpoint FLAC__FP_LN2;
  84760. extern const FLAC__fixedpoint FLAC__FP_E;
  84761. #define FLAC__fixedpoint_trunc(x) ((x)>>16)
  84762. #define FLAC__fixedpoint_mul(x, y) ( (FLAC__fixedpoint) ( ((FLAC__int64)(x)*(FLAC__int64)(y)) >> 16 ) )
  84763. #define FLAC__fixedpoint_div(x, y) ( (FLAC__fixedpoint) ( ( ((FLAC__int64)(x)<<32) / (FLAC__int64)(y) ) >> 16 ) )
  84764. FLAC__uint32 FLAC__fixedpoint_log2(FLAC__uint32 x, unsigned fracbits, unsigned precision);
  84765. #endif
  84766. #endif
  84767. /********* End of inlined file: float.h *********/
  84768. /********* Start of inlined file: format.h *********/
  84769. #ifndef FLAC__PRIVATE__FORMAT_H
  84770. #define FLAC__PRIVATE__FORMAT_H
  84771. unsigned FLAC__format_get_max_rice_partition_order(unsigned blocksize, unsigned predictor_order);
  84772. unsigned FLAC__format_get_max_rice_partition_order_from_blocksize(unsigned blocksize);
  84773. unsigned FLAC__format_get_max_rice_partition_order_from_blocksize_limited_max_and_predictor_order(unsigned limit, unsigned blocksize, unsigned predictor_order);
  84774. void FLAC__format_entropy_coding_method_partitioned_rice_contents_init(FLAC__EntropyCodingMethod_PartitionedRiceContents *object);
  84775. void FLAC__format_entropy_coding_method_partitioned_rice_contents_clear(FLAC__EntropyCodingMethod_PartitionedRiceContents *object);
  84776. FLAC__bool FLAC__format_entropy_coding_method_partitioned_rice_contents_ensure_size(FLAC__EntropyCodingMethod_PartitionedRiceContents *object, unsigned max_partition_order);
  84777. #endif
  84778. /********* End of inlined file: format.h *********/
  84779. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  84780. unsigned FLAC__fixed_compute_best_predictor(const FLAC__int32 data[], unsigned data_len, FLAC__float residual_bits_per_sample[FLAC__MAX_FIXED_ORDER+1]);
  84781. # ifndef FLAC__NO_ASM
  84782. # ifdef FLAC__CPU_IA32
  84783. # ifdef FLAC__HAS_NASM
  84784. 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]);
  84785. # endif
  84786. # endif
  84787. # endif
  84788. 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]);
  84789. #else
  84790. unsigned FLAC__fixed_compute_best_predictor(const FLAC__int32 data[], unsigned data_len, FLAC__fixedpoint residual_bits_per_sample[FLAC__MAX_FIXED_ORDER+1]);
  84791. 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]);
  84792. #endif
  84793. void FLAC__fixed_compute_residual(const FLAC__int32 data[], unsigned data_len, unsigned order, FLAC__int32 residual[]);
  84794. void FLAC__fixed_restore_signal(const FLAC__int32 residual[], unsigned data_len, unsigned order, FLAC__int32 data[]);
  84795. #endif
  84796. /********* End of inlined file: fixed.h *********/
  84797. #ifndef M_LN2
  84798. #define M_LN2 0.69314718055994530942
  84799. #endif
  84800. #ifdef min
  84801. #undef min
  84802. #endif
  84803. #define min(x,y) ((x) < (y)? (x) : (y))
  84804. #ifdef local_abs
  84805. #undef local_abs
  84806. #endif
  84807. #define local_abs(x) ((unsigned)((x)<0? -(x) : (x)))
  84808. #ifdef FLAC__INTEGER_ONLY_LIBRARY
  84809. static FLAC__fixedpoint local__compute_rbps_integerized(FLAC__uint32 err, FLAC__uint32 n)
  84810. {
  84811. FLAC__uint32 rbps;
  84812. unsigned bits; /* the number of bits required to represent a number */
  84813. int fracbits; /* the number of bits of rbps that comprise the fractional part */
  84814. FLAC__ASSERT(sizeof(rbps) == sizeof(FLAC__fixedpoint));
  84815. FLAC__ASSERT(err > 0);
  84816. FLAC__ASSERT(n > 0);
  84817. FLAC__ASSERT(n <= FLAC__MAX_BLOCK_SIZE);
  84818. if(err <= n)
  84819. return 0;
  84820. fracbits = (8*sizeof(err)) - (FLAC__bitmath_ilog2(err)+1);
  84821. err <<= fracbits;
  84822. err /= n;
  84823. FLAC__ASSERT(err > 0);
  84824. bits = FLAC__bitmath_ilog2(err)+1;
  84825. if(bits > 16) {
  84826. err >>= (bits-16);
  84827. fracbits -= (bits-16);
  84828. }
  84829. rbps = (FLAC__uint32)err;
  84830. rbps *= FLAC__FP_LN2;
  84831. fracbits += 16;
  84832. FLAC__ASSERT(fracbits >= 0);
  84833. {
  84834. const int f = fracbits & 3;
  84835. if(f) {
  84836. rbps >>= f;
  84837. fracbits -= f;
  84838. }
  84839. }
  84840. rbps = FLAC__fixedpoint_log2(rbps, fracbits, (unsigned)(-1));
  84841. if(rbps == 0)
  84842. return 0;
  84843. FLAC__ASSERT((int)FLAC__bitmath_ilog2(rbps)+1 <= fracbits + 6);
  84844. FLAC__ASSERT(fracbits >= -3);
  84845. if(fracbits < 16)
  84846. return rbps << (16-fracbits);
  84847. else if(fracbits > 16)
  84848. return rbps >> (fracbits-16);
  84849. else
  84850. return rbps;
  84851. }
  84852. static FLAC__fixedpoint local__compute_rbps_wide_integerized(FLAC__uint64 err, FLAC__uint32 n)
  84853. {
  84854. FLAC__uint32 rbps;
  84855. unsigned bits; /* the number of bits required to represent a number */
  84856. int fracbits; /* the number of bits of rbps that comprise the fractional part */
  84857. FLAC__ASSERT(sizeof(rbps) == sizeof(FLAC__fixedpoint));
  84858. FLAC__ASSERT(err > 0);
  84859. FLAC__ASSERT(n > 0);
  84860. FLAC__ASSERT(n <= FLAC__MAX_BLOCK_SIZE);
  84861. if(err <= n)
  84862. return 0;
  84863. fracbits = (8*sizeof(err)) - (FLAC__bitmath_ilog2_wide(err)+1);
  84864. err <<= fracbits;
  84865. err /= n;
  84866. FLAC__ASSERT(err > 0);
  84867. bits = FLAC__bitmath_ilog2_wide(err)+1;
  84868. if(bits > 16) {
  84869. err >>= (bits-16);
  84870. fracbits -= (bits-16);
  84871. }
  84872. rbps = (FLAC__uint32)err;
  84873. rbps *= FLAC__FP_LN2;
  84874. fracbits += 16;
  84875. FLAC__ASSERT(fracbits >= 0);
  84876. {
  84877. const int f = fracbits & 3;
  84878. if(f) {
  84879. rbps >>= f;
  84880. fracbits -= f;
  84881. }
  84882. }
  84883. rbps = FLAC__fixedpoint_log2(rbps, fracbits, (unsigned)(-1));
  84884. if(rbps == 0)
  84885. return 0;
  84886. FLAC__ASSERT((int)FLAC__bitmath_ilog2(rbps)+1 <= fracbits + 6);
  84887. FLAC__ASSERT(fracbits >= -3);
  84888. if(fracbits < 16)
  84889. return rbps << (16-fracbits);
  84890. else if(fracbits > 16)
  84891. return rbps >> (fracbits-16);
  84892. else
  84893. return rbps;
  84894. }
  84895. #endif
  84896. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  84897. unsigned FLAC__fixed_compute_best_predictor(const FLAC__int32 data[], unsigned data_len, FLAC__float residual_bits_per_sample[FLAC__MAX_FIXED_ORDER+1])
  84898. #else
  84899. unsigned FLAC__fixed_compute_best_predictor(const FLAC__int32 data[], unsigned data_len, FLAC__fixedpoint residual_bits_per_sample[FLAC__MAX_FIXED_ORDER+1])
  84900. #endif
  84901. {
  84902. FLAC__int32 last_error_0 = data[-1];
  84903. FLAC__int32 last_error_1 = data[-1] - data[-2];
  84904. FLAC__int32 last_error_2 = last_error_1 - (data[-2] - data[-3]);
  84905. FLAC__int32 last_error_3 = last_error_2 - (data[-2] - 2*data[-3] + data[-4]);
  84906. FLAC__int32 error, save;
  84907. FLAC__uint32 total_error_0 = 0, total_error_1 = 0, total_error_2 = 0, total_error_3 = 0, total_error_4 = 0;
  84908. unsigned i, order;
  84909. for(i = 0; i < data_len; i++) {
  84910. error = data[i] ; total_error_0 += local_abs(error); save = error;
  84911. error -= last_error_0; total_error_1 += local_abs(error); last_error_0 = save; save = error;
  84912. error -= last_error_1; total_error_2 += local_abs(error); last_error_1 = save; save = error;
  84913. error -= last_error_2; total_error_3 += local_abs(error); last_error_2 = save; save = error;
  84914. error -= last_error_3; total_error_4 += local_abs(error); last_error_3 = save;
  84915. }
  84916. if(total_error_0 < min(min(min(total_error_1, total_error_2), total_error_3), total_error_4))
  84917. order = 0;
  84918. else if(total_error_1 < min(min(total_error_2, total_error_3), total_error_4))
  84919. order = 1;
  84920. else if(total_error_2 < min(total_error_3, total_error_4))
  84921. order = 2;
  84922. else if(total_error_3 < total_error_4)
  84923. order = 3;
  84924. else
  84925. order = 4;
  84926. FLAC__ASSERT(data_len > 0 || total_error_0 == 0);
  84927. FLAC__ASSERT(data_len > 0 || total_error_1 == 0);
  84928. FLAC__ASSERT(data_len > 0 || total_error_2 == 0);
  84929. FLAC__ASSERT(data_len > 0 || total_error_3 == 0);
  84930. FLAC__ASSERT(data_len > 0 || total_error_4 == 0);
  84931. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  84932. 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);
  84933. 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);
  84934. 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);
  84935. 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);
  84936. 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);
  84937. #else
  84938. residual_bits_per_sample[0] = (total_error_0 > 0) ? local__compute_rbps_integerized(total_error_0, data_len) : 0;
  84939. residual_bits_per_sample[1] = (total_error_1 > 0) ? local__compute_rbps_integerized(total_error_1, data_len) : 0;
  84940. residual_bits_per_sample[2] = (total_error_2 > 0) ? local__compute_rbps_integerized(total_error_2, data_len) : 0;
  84941. residual_bits_per_sample[3] = (total_error_3 > 0) ? local__compute_rbps_integerized(total_error_3, data_len) : 0;
  84942. residual_bits_per_sample[4] = (total_error_4 > 0) ? local__compute_rbps_integerized(total_error_4, data_len) : 0;
  84943. #endif
  84944. return order;
  84945. }
  84946. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  84947. 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])
  84948. #else
  84949. 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])
  84950. #endif
  84951. {
  84952. FLAC__int32 last_error_0 = data[-1];
  84953. FLAC__int32 last_error_1 = data[-1] - data[-2];
  84954. FLAC__int32 last_error_2 = last_error_1 - (data[-2] - data[-3]);
  84955. FLAC__int32 last_error_3 = last_error_2 - (data[-2] - 2*data[-3] + data[-4]);
  84956. FLAC__int32 error, save;
  84957. FLAC__uint64 total_error_0 = 0, total_error_1 = 0, total_error_2 = 0, total_error_3 = 0, total_error_4 = 0;
  84958. unsigned i, order;
  84959. for(i = 0; i < data_len; i++) {
  84960. error = data[i] ; total_error_0 += local_abs(error); save = error;
  84961. error -= last_error_0; total_error_1 += local_abs(error); last_error_0 = save; save = error;
  84962. error -= last_error_1; total_error_2 += local_abs(error); last_error_1 = save; save = error;
  84963. error -= last_error_2; total_error_3 += local_abs(error); last_error_2 = save; save = error;
  84964. error -= last_error_3; total_error_4 += local_abs(error); last_error_3 = save;
  84965. }
  84966. if(total_error_0 < min(min(min(total_error_1, total_error_2), total_error_3), total_error_4))
  84967. order = 0;
  84968. else if(total_error_1 < min(min(total_error_2, total_error_3), total_error_4))
  84969. order = 1;
  84970. else if(total_error_2 < min(total_error_3, total_error_4))
  84971. order = 2;
  84972. else if(total_error_3 < total_error_4)
  84973. order = 3;
  84974. else
  84975. order = 4;
  84976. FLAC__ASSERT(data_len > 0 || total_error_0 == 0);
  84977. FLAC__ASSERT(data_len > 0 || total_error_1 == 0);
  84978. FLAC__ASSERT(data_len > 0 || total_error_2 == 0);
  84979. FLAC__ASSERT(data_len > 0 || total_error_3 == 0);
  84980. FLAC__ASSERT(data_len > 0 || total_error_4 == 0);
  84981. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  84982. #if defined _MSC_VER || defined __MINGW32__
  84983. 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);
  84984. 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);
  84985. 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);
  84986. 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);
  84987. 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);
  84988. #else
  84989. 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);
  84990. 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);
  84991. 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);
  84992. 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);
  84993. 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);
  84994. #endif
  84995. #else
  84996. residual_bits_per_sample[0] = (total_error_0 > 0) ? local__compute_rbps_wide_integerized(total_error_0, data_len) : 0;
  84997. residual_bits_per_sample[1] = (total_error_1 > 0) ? local__compute_rbps_wide_integerized(total_error_1, data_len) : 0;
  84998. residual_bits_per_sample[2] = (total_error_2 > 0) ? local__compute_rbps_wide_integerized(total_error_2, data_len) : 0;
  84999. residual_bits_per_sample[3] = (total_error_3 > 0) ? local__compute_rbps_wide_integerized(total_error_3, data_len) : 0;
  85000. residual_bits_per_sample[4] = (total_error_4 > 0) ? local__compute_rbps_wide_integerized(total_error_4, data_len) : 0;
  85001. #endif
  85002. return order;
  85003. }
  85004. void FLAC__fixed_compute_residual(const FLAC__int32 data[], unsigned data_len, unsigned order, FLAC__int32 residual[])
  85005. {
  85006. const int idata_len = (int)data_len;
  85007. int i;
  85008. switch(order) {
  85009. case 0:
  85010. FLAC__ASSERT(sizeof(residual[0]) == sizeof(data[0]));
  85011. memcpy(residual, data, sizeof(residual[0])*data_len);
  85012. break;
  85013. case 1:
  85014. for(i = 0; i < idata_len; i++)
  85015. residual[i] = data[i] - data[i-1];
  85016. break;
  85017. case 2:
  85018. for(i = 0; i < idata_len; i++)
  85019. #if 1 /* OPT: may be faster with some compilers on some systems */
  85020. residual[i] = data[i] - (data[i-1] << 1) + data[i-2];
  85021. #else
  85022. residual[i] = data[i] - 2*data[i-1] + data[i-2];
  85023. #endif
  85024. break;
  85025. case 3:
  85026. for(i = 0; i < idata_len; i++)
  85027. #if 1 /* OPT: may be faster with some compilers on some systems */
  85028. residual[i] = data[i] - (((data[i-1]-data[i-2])<<1) + (data[i-1]-data[i-2])) - data[i-3];
  85029. #else
  85030. residual[i] = data[i] - 3*data[i-1] + 3*data[i-2] - data[i-3];
  85031. #endif
  85032. break;
  85033. case 4:
  85034. for(i = 0; i < idata_len; i++)
  85035. #if 1 /* OPT: may be faster with some compilers on some systems */
  85036. residual[i] = data[i] - ((data[i-1]+data[i-3])<<2) + ((data[i-2]<<2) + (data[i-2]<<1)) + data[i-4];
  85037. #else
  85038. residual[i] = data[i] - 4*data[i-1] + 6*data[i-2] - 4*data[i-3] + data[i-4];
  85039. #endif
  85040. break;
  85041. default:
  85042. FLAC__ASSERT(0);
  85043. }
  85044. }
  85045. void FLAC__fixed_restore_signal(const FLAC__int32 residual[], unsigned data_len, unsigned order, FLAC__int32 data[])
  85046. {
  85047. int i, idata_len = (int)data_len;
  85048. switch(order) {
  85049. case 0:
  85050. FLAC__ASSERT(sizeof(residual[0]) == sizeof(data[0]));
  85051. memcpy(data, residual, sizeof(residual[0])*data_len);
  85052. break;
  85053. case 1:
  85054. for(i = 0; i < idata_len; i++)
  85055. data[i] = residual[i] + data[i-1];
  85056. break;
  85057. case 2:
  85058. for(i = 0; i < idata_len; i++)
  85059. #if 1 /* OPT: may be faster with some compilers on some systems */
  85060. data[i] = residual[i] + (data[i-1]<<1) - data[i-2];
  85061. #else
  85062. data[i] = residual[i] + 2*data[i-1] - data[i-2];
  85063. #endif
  85064. break;
  85065. case 3:
  85066. for(i = 0; i < idata_len; i++)
  85067. #if 1 /* OPT: may be faster with some compilers on some systems */
  85068. data[i] = residual[i] + (((data[i-1]-data[i-2])<<1) + (data[i-1]-data[i-2])) + data[i-3];
  85069. #else
  85070. data[i] = residual[i] + 3*data[i-1] - 3*data[i-2] + data[i-3];
  85071. #endif
  85072. break;
  85073. case 4:
  85074. for(i = 0; i < idata_len; i++)
  85075. #if 1 /* OPT: may be faster with some compilers on some systems */
  85076. data[i] = residual[i] + ((data[i-1]+data[i-3])<<2) - ((data[i-2]<<2) + (data[i-2]<<1)) - data[i-4];
  85077. #else
  85078. data[i] = residual[i] + 4*data[i-1] - 6*data[i-2] + 4*data[i-3] - data[i-4];
  85079. #endif
  85080. break;
  85081. default:
  85082. FLAC__ASSERT(0);
  85083. }
  85084. }
  85085. #endif
  85086. /********* End of inlined file: fixed.c *********/
  85087. /********* Start of inlined file: float.c *********/
  85088. /********* Start of inlined file: juce_FlacHeader.h *********/
  85089. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  85090. // tasks..
  85091. #define VERSION "1.2.1"
  85092. #define FLAC__NO_DLL 1
  85093. #if JUCE_MSVC
  85094. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  85095. #endif
  85096. #if JUCE_MAC
  85097. #define FLAC__SYS_DARWIN 1
  85098. #endif
  85099. /********* End of inlined file: juce_FlacHeader.h *********/
  85100. #if JUCE_USE_FLAC
  85101. #if HAVE_CONFIG_H
  85102. # include <config.h>
  85103. #endif
  85104. #ifdef FLAC__INTEGER_ONLY_LIBRARY
  85105. #ifdef _MSC_VER
  85106. #define FLAC__U64L(x) x
  85107. #else
  85108. #define FLAC__U64L(x) x##LLU
  85109. #endif
  85110. const FLAC__fixedpoint FLAC__FP_ZERO = 0;
  85111. const FLAC__fixedpoint FLAC__FP_ONE_HALF = 0x00008000;
  85112. const FLAC__fixedpoint FLAC__FP_ONE = 0x00010000;
  85113. const FLAC__fixedpoint FLAC__FP_LN2 = 45426;
  85114. const FLAC__fixedpoint FLAC__FP_E = 178145;
  85115. #define LOG2_LOOKUP_PRECISION 16
  85116. static const FLAC__uint32 log2_lookup[][LOG2_LOOKUP_PRECISION] = {
  85117. {
  85118. 0x00000000,
  85119. 0x00000001,
  85120. 0x00000000,
  85121. 0x00000000,
  85122. 0x00000000,
  85123. 0x00000000,
  85124. 0x00000000,
  85125. 0x00000000,
  85126. 0x00000000,
  85127. 0x00000000,
  85128. 0x00000000,
  85129. 0x00000000,
  85130. 0x00000000,
  85131. 0x00000000,
  85132. 0x00000000,
  85133. 0x00000000
  85134. },
  85135. {
  85136. 0x00000000,
  85137. 0x00000010,
  85138. 0x00000007,
  85139. 0x00000003,
  85140. 0x00000001,
  85141. 0x00000001,
  85142. 0x00000000,
  85143. 0x00000000,
  85144. 0x00000000,
  85145. 0x00000000,
  85146. 0x00000000,
  85147. 0x00000000,
  85148. 0x00000000,
  85149. 0x00000000,
  85150. 0x00000000,
  85151. 0x00000000
  85152. },
  85153. {
  85154. 0x00000000,
  85155. 0x00000100,
  85156. 0x0000006a,
  85157. 0x00000031,
  85158. 0x00000018,
  85159. 0x0000000c,
  85160. 0x00000006,
  85161. 0x00000003,
  85162. 0x00000001,
  85163. 0x00000001,
  85164. 0x00000000,
  85165. 0x00000000,
  85166. 0x00000000,
  85167. 0x00000000,
  85168. 0x00000000,
  85169. 0x00000000
  85170. },
  85171. {
  85172. 0x00000000,
  85173. 0x00001000,
  85174. 0x000006a4,
  85175. 0x00000315,
  85176. 0x0000017d,
  85177. 0x000000bc,
  85178. 0x0000005d,
  85179. 0x0000002e,
  85180. 0x00000017,
  85181. 0x0000000c,
  85182. 0x00000006,
  85183. 0x00000003,
  85184. 0x00000001,
  85185. 0x00000001,
  85186. 0x00000000,
  85187. 0x00000000
  85188. },
  85189. {
  85190. 0x00000000,
  85191. 0x00010000,
  85192. 0x00006a40,
  85193. 0x00003151,
  85194. 0x000017d6,
  85195. 0x00000bba,
  85196. 0x000005d1,
  85197. 0x000002e6,
  85198. 0x00000172,
  85199. 0x000000b9,
  85200. 0x0000005c,
  85201. 0x0000002e,
  85202. 0x00000017,
  85203. 0x0000000c,
  85204. 0x00000006,
  85205. 0x00000003
  85206. },
  85207. {
  85208. 0x00000000,
  85209. 0x00100000,
  85210. 0x0006a3fe,
  85211. 0x00031513,
  85212. 0x00017d60,
  85213. 0x0000bb9d,
  85214. 0x00005d10,
  85215. 0x00002e59,
  85216. 0x00001721,
  85217. 0x00000b8e,
  85218. 0x000005c6,
  85219. 0x000002e3,
  85220. 0x00000171,
  85221. 0x000000b9,
  85222. 0x0000005c,
  85223. 0x0000002e
  85224. },
  85225. {
  85226. 0x00000000,
  85227. 0x01000000,
  85228. 0x006a3fe6,
  85229. 0x00315130,
  85230. 0x0017d605,
  85231. 0x000bb9ca,
  85232. 0x0005d0fc,
  85233. 0x0002e58f,
  85234. 0x0001720e,
  85235. 0x0000b8d8,
  85236. 0x00005c61,
  85237. 0x00002e2d,
  85238. 0x00001716,
  85239. 0x00000b8b,
  85240. 0x000005c5,
  85241. 0x000002e3
  85242. },
  85243. {
  85244. 0x00000000,
  85245. 0x10000000,
  85246. 0x06a3fe5c,
  85247. 0x03151301,
  85248. 0x017d6049,
  85249. 0x00bb9ca6,
  85250. 0x005d0fba,
  85251. 0x002e58f7,
  85252. 0x001720da,
  85253. 0x000b8d87,
  85254. 0x0005c60b,
  85255. 0x0002e2d7,
  85256. 0x00017160,
  85257. 0x0000b8ad,
  85258. 0x00005c56,
  85259. 0x00002e2b
  85260. }
  85261. };
  85262. #if 0
  85263. static const FLAC__uint64 log2_lookup_wide[] = {
  85264. {
  85265. 0x00000000,
  85266. FLAC__U64L(0x100000000),
  85267. FLAC__U64L(0x6a3fe5c6),
  85268. FLAC__U64L(0x31513015),
  85269. FLAC__U64L(0x17d60497),
  85270. FLAC__U64L(0x0bb9ca65),
  85271. FLAC__U64L(0x05d0fba2),
  85272. FLAC__U64L(0x02e58f74),
  85273. FLAC__U64L(0x01720d9c),
  85274. FLAC__U64L(0x00b8d875),
  85275. FLAC__U64L(0x005c60aa),
  85276. FLAC__U64L(0x002e2d72),
  85277. FLAC__U64L(0x00171600),
  85278. FLAC__U64L(0x000b8ad2),
  85279. FLAC__U64L(0x0005c55d),
  85280. FLAC__U64L(0x0002e2ac)
  85281. },
  85282. {
  85283. 0x00000000,
  85284. FLAC__U64L(0x1000000000000),
  85285. FLAC__U64L(0x6a3fe5c60429),
  85286. FLAC__U64L(0x315130157f7a),
  85287. FLAC__U64L(0x17d60496cfbb),
  85288. FLAC__U64L(0xbb9ca64ecac),
  85289. FLAC__U64L(0x5d0fba187cd),
  85290. FLAC__U64L(0x2e58f7441ee),
  85291. FLAC__U64L(0x1720d9c06a8),
  85292. FLAC__U64L(0xb8d8752173),
  85293. FLAC__U64L(0x5c60aa252e),
  85294. FLAC__U64L(0x2e2d71b0d8),
  85295. FLAC__U64L(0x1716001719),
  85296. FLAC__U64L(0xb8ad1de1b),
  85297. FLAC__U64L(0x5c55d640d),
  85298. FLAC__U64L(0x2e2abcf52)
  85299. }
  85300. };
  85301. #endif
  85302. FLAC__uint32 FLAC__fixedpoint_log2(FLAC__uint32 x, unsigned fracbits, unsigned precision)
  85303. {
  85304. const FLAC__uint32 ONE = (1u << fracbits);
  85305. const FLAC__uint32 *table = log2_lookup[fracbits >> 2];
  85306. FLAC__ASSERT(fracbits < 32);
  85307. FLAC__ASSERT((fracbits & 0x3) == 0);
  85308. if(x < ONE)
  85309. return 0;
  85310. if(precision > LOG2_LOOKUP_PRECISION)
  85311. precision = LOG2_LOOKUP_PRECISION;
  85312. {
  85313. FLAC__uint32 y = 0;
  85314. FLAC__uint32 z = x >> 1, k = 1;
  85315. while (x > ONE && k < precision) {
  85316. if (x - z >= ONE) {
  85317. x -= z;
  85318. z = x >> k;
  85319. y += table[k];
  85320. }
  85321. else {
  85322. z >>= 1;
  85323. k++;
  85324. }
  85325. }
  85326. return y;
  85327. }
  85328. }
  85329. #endif /* defined FLAC__INTEGER_ONLY_LIBRARY */
  85330. #endif
  85331. /********* End of inlined file: float.c *********/
  85332. /********* Start of inlined file: format.c *********/
  85333. /********* Start of inlined file: juce_FlacHeader.h *********/
  85334. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  85335. // tasks..
  85336. #define VERSION "1.2.1"
  85337. #define FLAC__NO_DLL 1
  85338. #if JUCE_MSVC
  85339. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  85340. #endif
  85341. #if JUCE_MAC
  85342. #define FLAC__SYS_DARWIN 1
  85343. #endif
  85344. /********* End of inlined file: juce_FlacHeader.h *********/
  85345. #if JUCE_USE_FLAC
  85346. #if HAVE_CONFIG_H
  85347. # include <config.h>
  85348. #endif
  85349. #include <stdio.h>
  85350. #include <stdlib.h> /* for qsort() */
  85351. #include <string.h> /* for memset() */
  85352. #ifndef FLaC__INLINE
  85353. #define FLaC__INLINE
  85354. #endif
  85355. #ifdef min
  85356. #undef min
  85357. #endif
  85358. #define min(a,b) ((a)<(b)?(a):(b))
  85359. #ifdef _MSC_VER
  85360. #define FLAC__U64L(x) x
  85361. #else
  85362. #define FLAC__U64L(x) x##LLU
  85363. #endif
  85364. FLAC_API const char *FLAC__VERSION_STRING = VERSION
  85365. ;
  85366. #if defined _MSC_VER || defined __BORLANDC__ || defined __MINW32__
  85367. FLAC_API const char *FLAC__VENDOR_STRING = "reference libFLAC 1.2.1 20070917";
  85368. #else
  85369. FLAC_API const char *FLAC__VENDOR_STRING = "reference libFLAC " VERSION " 20070917";
  85370. #endif
  85371. FLAC_API const FLAC__byte FLAC__STREAM_SYNC_STRING[4] = { 'f','L','a','C' };
  85372. FLAC_API const unsigned FLAC__STREAM_SYNC = 0x664C6143;
  85373. FLAC_API const unsigned FLAC__STREAM_SYNC_LEN = 32; /* bits */
  85374. FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN = 16; /* bits */
  85375. FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN = 16; /* bits */
  85376. FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN = 24; /* bits */
  85377. FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_MAX_FRAME_SIZE_LEN = 24; /* bits */
  85378. FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_SAMPLE_RATE_LEN = 20; /* bits */
  85379. FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_CHANNELS_LEN = 3; /* bits */
  85380. FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN = 5; /* bits */
  85381. FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_TOTAL_SAMPLES_LEN = 36; /* bits */
  85382. FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_MD5SUM_LEN = 128; /* bits */
  85383. FLAC_API const unsigned FLAC__STREAM_METADATA_APPLICATION_ID_LEN = 32; /* bits */
  85384. FLAC_API const unsigned FLAC__STREAM_METADATA_SEEKPOINT_SAMPLE_NUMBER_LEN = 64; /* bits */
  85385. FLAC_API const unsigned FLAC__STREAM_METADATA_SEEKPOINT_STREAM_OFFSET_LEN = 64; /* bits */
  85386. FLAC_API const unsigned FLAC__STREAM_METADATA_SEEKPOINT_FRAME_SAMPLES_LEN = 16; /* bits */
  85387. FLAC_API const FLAC__uint64 FLAC__STREAM_METADATA_SEEKPOINT_PLACEHOLDER = FLAC__U64L(0xffffffffffffffff);
  85388. FLAC_API const unsigned FLAC__STREAM_METADATA_VORBIS_COMMENT_ENTRY_LENGTH_LEN = 32; /* bits */
  85389. FLAC_API const unsigned FLAC__STREAM_METADATA_VORBIS_COMMENT_NUM_COMMENTS_LEN = 32; /* bits */
  85390. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_INDEX_OFFSET_LEN = 64; /* bits */
  85391. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_INDEX_NUMBER_LEN = 8; /* bits */
  85392. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_INDEX_RESERVED_LEN = 3*8; /* bits */
  85393. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_OFFSET_LEN = 64; /* bits */
  85394. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_NUMBER_LEN = 8; /* bits */
  85395. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_ISRC_LEN = 12*8; /* bits */
  85396. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_TYPE_LEN = 1; /* bit */
  85397. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_PRE_EMPHASIS_LEN = 1; /* bit */
  85398. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_RESERVED_LEN = 6+13*8; /* bits */
  85399. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_NUM_INDICES_LEN = 8; /* bits */
  85400. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_MEDIA_CATALOG_NUMBER_LEN = 128*8; /* bits */
  85401. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_LEAD_IN_LEN = 64; /* bits */
  85402. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_IS_CD_LEN = 1; /* bit */
  85403. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_RESERVED_LEN = 7+258*8; /* bits */
  85404. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_NUM_TRACKS_LEN = 8; /* bits */
  85405. FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_TYPE_LEN = 32; /* bits */
  85406. FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_MIME_TYPE_LENGTH_LEN = 32; /* bits */
  85407. FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_DESCRIPTION_LENGTH_LEN = 32; /* bits */
  85408. FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_WIDTH_LEN = 32; /* bits */
  85409. FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_HEIGHT_LEN = 32; /* bits */
  85410. FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_DEPTH_LEN = 32; /* bits */
  85411. FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_COLORS_LEN = 32; /* bits */
  85412. FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_DATA_LENGTH_LEN = 32; /* bits */
  85413. FLAC_API const unsigned FLAC__STREAM_METADATA_IS_LAST_LEN = 1; /* bits */
  85414. FLAC_API const unsigned FLAC__STREAM_METADATA_TYPE_LEN = 7; /* bits */
  85415. FLAC_API const unsigned FLAC__STREAM_METADATA_LENGTH_LEN = 24; /* bits */
  85416. FLAC_API const unsigned FLAC__FRAME_HEADER_SYNC = 0x3ffe;
  85417. FLAC_API const unsigned FLAC__FRAME_HEADER_SYNC_LEN = 14; /* bits */
  85418. FLAC_API const unsigned FLAC__FRAME_HEADER_RESERVED_LEN = 1; /* bits */
  85419. FLAC_API const unsigned FLAC__FRAME_HEADER_BLOCKING_STRATEGY_LEN = 1; /* bits */
  85420. FLAC_API const unsigned FLAC__FRAME_HEADER_BLOCK_SIZE_LEN = 4; /* bits */
  85421. FLAC_API const unsigned FLAC__FRAME_HEADER_SAMPLE_RATE_LEN = 4; /* bits */
  85422. FLAC_API const unsigned FLAC__FRAME_HEADER_CHANNEL_ASSIGNMENT_LEN = 4; /* bits */
  85423. FLAC_API const unsigned FLAC__FRAME_HEADER_BITS_PER_SAMPLE_LEN = 3; /* bits */
  85424. FLAC_API const unsigned FLAC__FRAME_HEADER_ZERO_PAD_LEN = 1; /* bits */
  85425. FLAC_API const unsigned FLAC__FRAME_HEADER_CRC_LEN = 8; /* bits */
  85426. FLAC_API const unsigned FLAC__FRAME_FOOTER_CRC_LEN = 16; /* bits */
  85427. FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_TYPE_LEN = 2; /* bits */
  85428. FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ORDER_LEN = 4; /* bits */
  85429. FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_PARAMETER_LEN = 4; /* bits */
  85430. FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_PARAMETER_LEN = 5; /* bits */
  85431. FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_RAW_LEN = 5; /* bits */
  85432. FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ESCAPE_PARAMETER = 15; /* == (1<<FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_PARAMETER_LEN)-1 */
  85433. FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_ESCAPE_PARAMETER = 31; /* == (1<<FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_PARAMETER_LEN)-1 */
  85434. FLAC_API const char * const FLAC__EntropyCodingMethodTypeString[] = {
  85435. "PARTITIONED_RICE",
  85436. "PARTITIONED_RICE2"
  85437. };
  85438. FLAC_API const unsigned FLAC__SUBFRAME_LPC_QLP_COEFF_PRECISION_LEN = 4; /* bits */
  85439. FLAC_API const unsigned FLAC__SUBFRAME_LPC_QLP_SHIFT_LEN = 5; /* bits */
  85440. FLAC_API const unsigned FLAC__SUBFRAME_ZERO_PAD_LEN = 1; /* bits */
  85441. FLAC_API const unsigned FLAC__SUBFRAME_TYPE_LEN = 6; /* bits */
  85442. FLAC_API const unsigned FLAC__SUBFRAME_WASTED_BITS_FLAG_LEN = 1; /* bits */
  85443. FLAC_API const unsigned FLAC__SUBFRAME_TYPE_CONSTANT_BYTE_ALIGNED_MASK = 0x00;
  85444. FLAC_API const unsigned FLAC__SUBFRAME_TYPE_VERBATIM_BYTE_ALIGNED_MASK = 0x02;
  85445. FLAC_API const unsigned FLAC__SUBFRAME_TYPE_FIXED_BYTE_ALIGNED_MASK = 0x10;
  85446. FLAC_API const unsigned FLAC__SUBFRAME_TYPE_LPC_BYTE_ALIGNED_MASK = 0x40;
  85447. FLAC_API const char * const FLAC__SubframeTypeString[] = {
  85448. "CONSTANT",
  85449. "VERBATIM",
  85450. "FIXED",
  85451. "LPC"
  85452. };
  85453. FLAC_API const char * const FLAC__ChannelAssignmentString[] = {
  85454. "INDEPENDENT",
  85455. "LEFT_SIDE",
  85456. "RIGHT_SIDE",
  85457. "MID_SIDE"
  85458. };
  85459. FLAC_API const char * const FLAC__FrameNumberTypeString[] = {
  85460. "FRAME_NUMBER_TYPE_FRAME_NUMBER",
  85461. "FRAME_NUMBER_TYPE_SAMPLE_NUMBER"
  85462. };
  85463. FLAC_API const char * const FLAC__MetadataTypeString[] = {
  85464. "STREAMINFO",
  85465. "PADDING",
  85466. "APPLICATION",
  85467. "SEEKTABLE",
  85468. "VORBIS_COMMENT",
  85469. "CUESHEET",
  85470. "PICTURE"
  85471. };
  85472. FLAC_API const char * const FLAC__StreamMetadata_Picture_TypeString[] = {
  85473. "Other",
  85474. "32x32 pixels 'file icon' (PNG only)",
  85475. "Other file icon",
  85476. "Cover (front)",
  85477. "Cover (back)",
  85478. "Leaflet page",
  85479. "Media (e.g. label side of CD)",
  85480. "Lead artist/lead performer/soloist",
  85481. "Artist/performer",
  85482. "Conductor",
  85483. "Band/Orchestra",
  85484. "Composer",
  85485. "Lyricist/text writer",
  85486. "Recording Location",
  85487. "During recording",
  85488. "During performance",
  85489. "Movie/video screen capture",
  85490. "A bright coloured fish",
  85491. "Illustration",
  85492. "Band/artist logotype",
  85493. "Publisher/Studio logotype"
  85494. };
  85495. FLAC_API FLAC__bool FLAC__format_sample_rate_is_valid(unsigned sample_rate)
  85496. {
  85497. if(sample_rate == 0 || sample_rate > FLAC__MAX_SAMPLE_RATE) {
  85498. return false;
  85499. }
  85500. else
  85501. return true;
  85502. }
  85503. FLAC_API FLAC__bool FLAC__format_sample_rate_is_subset(unsigned sample_rate)
  85504. {
  85505. if(
  85506. !FLAC__format_sample_rate_is_valid(sample_rate) ||
  85507. (
  85508. sample_rate >= (1u << 16) &&
  85509. !(sample_rate % 1000 == 0 || sample_rate % 10 == 0)
  85510. )
  85511. ) {
  85512. return false;
  85513. }
  85514. else
  85515. return true;
  85516. }
  85517. FLAC_API FLAC__bool FLAC__format_seektable_is_legal(const FLAC__StreamMetadata_SeekTable *seek_table)
  85518. {
  85519. unsigned i;
  85520. FLAC__uint64 prev_sample_number = 0;
  85521. FLAC__bool got_prev = false;
  85522. FLAC__ASSERT(0 != seek_table);
  85523. for(i = 0; i < seek_table->num_points; i++) {
  85524. if(got_prev) {
  85525. if(
  85526. seek_table->points[i].sample_number != FLAC__STREAM_METADATA_SEEKPOINT_PLACEHOLDER &&
  85527. seek_table->points[i].sample_number <= prev_sample_number
  85528. )
  85529. return false;
  85530. }
  85531. prev_sample_number = seek_table->points[i].sample_number;
  85532. got_prev = true;
  85533. }
  85534. return true;
  85535. }
  85536. static int seekpoint_compare_(const FLAC__StreamMetadata_SeekPoint *l, const FLAC__StreamMetadata_SeekPoint *r)
  85537. {
  85538. if(l->sample_number == r->sample_number)
  85539. return 0;
  85540. else if(l->sample_number < r->sample_number)
  85541. return -1;
  85542. else
  85543. return 1;
  85544. }
  85545. FLAC_API unsigned FLAC__format_seektable_sort(FLAC__StreamMetadata_SeekTable *seek_table)
  85546. {
  85547. unsigned i, j;
  85548. FLAC__bool first;
  85549. FLAC__ASSERT(0 != seek_table);
  85550. qsort(seek_table->points, seek_table->num_points, sizeof(FLAC__StreamMetadata_SeekPoint), (int (*)(const void *, const void *))seekpoint_compare_);
  85551. first = true;
  85552. for(i = j = 0; i < seek_table->num_points; i++) {
  85553. if(seek_table->points[i].sample_number != FLAC__STREAM_METADATA_SEEKPOINT_PLACEHOLDER) {
  85554. if(!first) {
  85555. if(seek_table->points[i].sample_number == seek_table->points[j-1].sample_number)
  85556. continue;
  85557. }
  85558. }
  85559. first = false;
  85560. seek_table->points[j++] = seek_table->points[i];
  85561. }
  85562. for(i = j; i < seek_table->num_points; i++) {
  85563. seek_table->points[i].sample_number = FLAC__STREAM_METADATA_SEEKPOINT_PLACEHOLDER;
  85564. seek_table->points[i].stream_offset = 0;
  85565. seek_table->points[i].frame_samples = 0;
  85566. }
  85567. return j;
  85568. }
  85569. static FLaC__INLINE unsigned utf8len_(const FLAC__byte *utf8)
  85570. {
  85571. FLAC__ASSERT(0 != utf8);
  85572. if ((utf8[0] & 0x80) == 0) {
  85573. return 1;
  85574. }
  85575. else if ((utf8[0] & 0xE0) == 0xC0 && (utf8[1] & 0xC0) == 0x80) {
  85576. if ((utf8[0] & 0xFE) == 0xC0) /* overlong sequence check */
  85577. return 0;
  85578. return 2;
  85579. }
  85580. else if ((utf8[0] & 0xF0) == 0xE0 && (utf8[1] & 0xC0) == 0x80 && (utf8[2] & 0xC0) == 0x80) {
  85581. if (utf8[0] == 0xE0 && (utf8[1] & 0xE0) == 0x80) /* overlong sequence check */
  85582. return 0;
  85583. if (utf8[0] == 0xED && (utf8[1] & 0xE0) == 0xA0) /* D800-DFFF */
  85584. return 0;
  85585. if (utf8[0] == 0xEF && utf8[1] == 0xBF && (utf8[2] & 0xFE) == 0xBE) /* FFFE-FFFF */
  85586. return 0;
  85587. return 3;
  85588. }
  85589. else if ((utf8[0] & 0xF8) == 0xF0 && (utf8[1] & 0xC0) == 0x80 && (utf8[2] & 0xC0) == 0x80 && (utf8[3] & 0xC0) == 0x80) {
  85590. if (utf8[0] == 0xF0 && (utf8[1] & 0xF0) == 0x80) /* overlong sequence check */
  85591. return 0;
  85592. return 4;
  85593. }
  85594. else if ((utf8[0] & 0xFC) == 0xF8 && (utf8[1] & 0xC0) == 0x80 && (utf8[2] & 0xC0) == 0x80 && (utf8[3] & 0xC0) == 0x80 && (utf8[4] & 0xC0) == 0x80) {
  85595. if (utf8[0] == 0xF8 && (utf8[1] & 0xF8) == 0x80) /* overlong sequence check */
  85596. return 0;
  85597. return 5;
  85598. }
  85599. 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) {
  85600. if (utf8[0] == 0xFC && (utf8[1] & 0xFC) == 0x80) /* overlong sequence check */
  85601. return 0;
  85602. return 6;
  85603. }
  85604. else {
  85605. return 0;
  85606. }
  85607. }
  85608. FLAC_API FLAC__bool FLAC__format_vorbiscomment_entry_name_is_legal(const char *name)
  85609. {
  85610. char c;
  85611. for(c = *name; c; c = *(++name))
  85612. if(c < 0x20 || c == 0x3d || c > 0x7d)
  85613. return false;
  85614. return true;
  85615. }
  85616. FLAC_API FLAC__bool FLAC__format_vorbiscomment_entry_value_is_legal(const FLAC__byte *value, unsigned length)
  85617. {
  85618. if(length == (unsigned)(-1)) {
  85619. while(*value) {
  85620. unsigned n = utf8len_(value);
  85621. if(n == 0)
  85622. return false;
  85623. value += n;
  85624. }
  85625. }
  85626. else {
  85627. const FLAC__byte *end = value + length;
  85628. while(value < end) {
  85629. unsigned n = utf8len_(value);
  85630. if(n == 0)
  85631. return false;
  85632. value += n;
  85633. }
  85634. if(value != end)
  85635. return false;
  85636. }
  85637. return true;
  85638. }
  85639. FLAC_API FLAC__bool FLAC__format_vorbiscomment_entry_is_legal(const FLAC__byte *entry, unsigned length)
  85640. {
  85641. const FLAC__byte *s, *end;
  85642. for(s = entry, end = s + length; s < end && *s != '='; s++) {
  85643. if(*s < 0x20 || *s > 0x7D)
  85644. return false;
  85645. }
  85646. if(s == end)
  85647. return false;
  85648. s++; /* skip '=' */
  85649. while(s < end) {
  85650. unsigned n = utf8len_(s);
  85651. if(n == 0)
  85652. return false;
  85653. s += n;
  85654. }
  85655. if(s != end)
  85656. return false;
  85657. return true;
  85658. }
  85659. FLAC_API FLAC__bool FLAC__format_cuesheet_is_legal(const FLAC__StreamMetadata_CueSheet *cue_sheet, FLAC__bool check_cd_da_subset, const char **violation)
  85660. {
  85661. unsigned i, j;
  85662. if(check_cd_da_subset) {
  85663. if(cue_sheet->lead_in < 2 * 44100) {
  85664. if(violation) *violation = "CD-DA cue sheet must have a lead-in length of at least 2 seconds";
  85665. return false;
  85666. }
  85667. if(cue_sheet->lead_in % 588 != 0) {
  85668. if(violation) *violation = "CD-DA cue sheet lead-in length must be evenly divisible by 588 samples";
  85669. return false;
  85670. }
  85671. }
  85672. if(cue_sheet->num_tracks == 0) {
  85673. if(violation) *violation = "cue sheet must have at least one track (the lead-out)";
  85674. return false;
  85675. }
  85676. if(check_cd_da_subset && cue_sheet->tracks[cue_sheet->num_tracks-1].number != 170) {
  85677. if(violation) *violation = "CD-DA cue sheet must have a lead-out track number 170 (0xAA)";
  85678. return false;
  85679. }
  85680. for(i = 0; i < cue_sheet->num_tracks; i++) {
  85681. if(cue_sheet->tracks[i].number == 0) {
  85682. if(violation) *violation = "cue sheet may not have a track number 0";
  85683. return false;
  85684. }
  85685. if(check_cd_da_subset) {
  85686. if(!((cue_sheet->tracks[i].number >= 1 && cue_sheet->tracks[i].number <= 99) || cue_sheet->tracks[i].number == 170)) {
  85687. if(violation) *violation = "CD-DA cue sheet track number must be 1-99 or 170";
  85688. return false;
  85689. }
  85690. }
  85691. if(check_cd_da_subset && cue_sheet->tracks[i].offset % 588 != 0) {
  85692. if(violation) {
  85693. if(i == cue_sheet->num_tracks-1) /* the lead-out track... */
  85694. *violation = "CD-DA cue sheet lead-out offset must be evenly divisible by 588 samples";
  85695. else
  85696. *violation = "CD-DA cue sheet track offset must be evenly divisible by 588 samples";
  85697. }
  85698. return false;
  85699. }
  85700. if(i < cue_sheet->num_tracks - 1) {
  85701. if(cue_sheet->tracks[i].num_indices == 0) {
  85702. if(violation) *violation = "cue sheet track must have at least one index point";
  85703. return false;
  85704. }
  85705. if(cue_sheet->tracks[i].indices[0].number > 1) {
  85706. if(violation) *violation = "cue sheet track's first index number must be 0 or 1";
  85707. return false;
  85708. }
  85709. }
  85710. for(j = 0; j < cue_sheet->tracks[i].num_indices; j++) {
  85711. if(check_cd_da_subset && cue_sheet->tracks[i].indices[j].offset % 588 != 0) {
  85712. if(violation) *violation = "CD-DA cue sheet track index offset must be evenly divisible by 588 samples";
  85713. return false;
  85714. }
  85715. if(j > 0) {
  85716. if(cue_sheet->tracks[i].indices[j].number != cue_sheet->tracks[i].indices[j-1].number + 1) {
  85717. if(violation) *violation = "cue sheet track index numbers must increase by 1";
  85718. return false;
  85719. }
  85720. }
  85721. }
  85722. }
  85723. return true;
  85724. }
  85725. FLAC_API FLAC__bool FLAC__format_picture_is_legal(const FLAC__StreamMetadata_Picture *picture, const char **violation)
  85726. {
  85727. char *p;
  85728. FLAC__byte *b;
  85729. for(p = picture->mime_type; *p; p++) {
  85730. if(*p < 0x20 || *p > 0x7e) {
  85731. if(violation) *violation = "MIME type string must contain only printable ASCII characters (0x20-0x7e)";
  85732. return false;
  85733. }
  85734. }
  85735. for(b = picture->description; *b; ) {
  85736. unsigned n = utf8len_(b);
  85737. if(n == 0) {
  85738. if(violation) *violation = "description string must be valid UTF-8";
  85739. return false;
  85740. }
  85741. b += n;
  85742. }
  85743. return true;
  85744. }
  85745. unsigned FLAC__format_get_max_rice_partition_order(unsigned blocksize, unsigned predictor_order)
  85746. {
  85747. return
  85748. FLAC__format_get_max_rice_partition_order_from_blocksize_limited_max_and_predictor_order(
  85749. FLAC__format_get_max_rice_partition_order_from_blocksize(blocksize),
  85750. blocksize,
  85751. predictor_order
  85752. );
  85753. }
  85754. unsigned FLAC__format_get_max_rice_partition_order_from_blocksize(unsigned blocksize)
  85755. {
  85756. unsigned max_rice_partition_order = 0;
  85757. while(!(blocksize & 1)) {
  85758. max_rice_partition_order++;
  85759. blocksize >>= 1;
  85760. }
  85761. return min(FLAC__MAX_RICE_PARTITION_ORDER, max_rice_partition_order);
  85762. }
  85763. unsigned FLAC__format_get_max_rice_partition_order_from_blocksize_limited_max_and_predictor_order(unsigned limit, unsigned blocksize, unsigned predictor_order)
  85764. {
  85765. unsigned max_rice_partition_order = limit;
  85766. while(max_rice_partition_order > 0 && (blocksize >> max_rice_partition_order) <= predictor_order)
  85767. max_rice_partition_order--;
  85768. FLAC__ASSERT(
  85769. (max_rice_partition_order == 0 && blocksize >= predictor_order) ||
  85770. (max_rice_partition_order > 0 && blocksize >> max_rice_partition_order > predictor_order)
  85771. );
  85772. return max_rice_partition_order;
  85773. }
  85774. void FLAC__format_entropy_coding_method_partitioned_rice_contents_init(FLAC__EntropyCodingMethod_PartitionedRiceContents *object)
  85775. {
  85776. FLAC__ASSERT(0 != object);
  85777. object->parameters = 0;
  85778. object->raw_bits = 0;
  85779. object->capacity_by_order = 0;
  85780. }
  85781. void FLAC__format_entropy_coding_method_partitioned_rice_contents_clear(FLAC__EntropyCodingMethod_PartitionedRiceContents *object)
  85782. {
  85783. FLAC__ASSERT(0 != object);
  85784. if(0 != object->parameters)
  85785. free(object->parameters);
  85786. if(0 != object->raw_bits)
  85787. free(object->raw_bits);
  85788. FLAC__format_entropy_coding_method_partitioned_rice_contents_init(object);
  85789. }
  85790. FLAC__bool FLAC__format_entropy_coding_method_partitioned_rice_contents_ensure_size(FLAC__EntropyCodingMethod_PartitionedRiceContents *object, unsigned max_partition_order)
  85791. {
  85792. FLAC__ASSERT(0 != object);
  85793. FLAC__ASSERT(object->capacity_by_order > 0 || (0 == object->parameters && 0 == object->raw_bits));
  85794. if(object->capacity_by_order < max_partition_order) {
  85795. if(0 == (object->parameters = (unsigned*)realloc(object->parameters, sizeof(unsigned)*(1 << max_partition_order))))
  85796. return false;
  85797. if(0 == (object->raw_bits = (unsigned*)realloc(object->raw_bits, sizeof(unsigned)*(1 << max_partition_order))))
  85798. return false;
  85799. memset(object->raw_bits, 0, sizeof(unsigned)*(1 << max_partition_order));
  85800. object->capacity_by_order = max_partition_order;
  85801. }
  85802. return true;
  85803. }
  85804. #endif
  85805. /********* End of inlined file: format.c *********/
  85806. /********* Start of inlined file: lpc_flac.c *********/
  85807. /********* Start of inlined file: juce_FlacHeader.h *********/
  85808. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  85809. // tasks..
  85810. #define VERSION "1.2.1"
  85811. #define FLAC__NO_DLL 1
  85812. #if JUCE_MSVC
  85813. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  85814. #endif
  85815. #if JUCE_MAC
  85816. #define FLAC__SYS_DARWIN 1
  85817. #endif
  85818. /********* End of inlined file: juce_FlacHeader.h *********/
  85819. #if JUCE_USE_FLAC
  85820. #if HAVE_CONFIG_H
  85821. # include <config.h>
  85822. #endif
  85823. #include <math.h>
  85824. /********* Start of inlined file: lpc.h *********/
  85825. #ifndef FLAC__PRIVATE__LPC_H
  85826. #define FLAC__PRIVATE__LPC_H
  85827. #ifdef HAVE_CONFIG_H
  85828. #include <config.h>
  85829. #endif
  85830. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  85831. void FLAC__lpc_window_data(const FLAC__int32 in[], const FLAC__real window[], FLAC__real out[], unsigned data_len);
  85832. void FLAC__lpc_compute_autocorrelation(const FLAC__real data[], unsigned data_len, unsigned lag, FLAC__real autoc[]);
  85833. #ifndef FLAC__NO_ASM
  85834. # ifdef FLAC__CPU_IA32
  85835. # ifdef FLAC__HAS_NASM
  85836. void FLAC__lpc_compute_autocorrelation_asm_ia32(const FLAC__real data[], unsigned data_len, unsigned lag, FLAC__real autoc[]);
  85837. void FLAC__lpc_compute_autocorrelation_asm_ia32_sse_lag_4(const FLAC__real data[], unsigned data_len, unsigned lag, FLAC__real autoc[]);
  85838. void FLAC__lpc_compute_autocorrelation_asm_ia32_sse_lag_8(const FLAC__real data[], unsigned data_len, unsigned lag, FLAC__real autoc[]);
  85839. void FLAC__lpc_compute_autocorrelation_asm_ia32_sse_lag_12(const FLAC__real data[], unsigned data_len, unsigned lag, FLAC__real autoc[]);
  85840. void FLAC__lpc_compute_autocorrelation_asm_ia32_3dnow(const FLAC__real data[], unsigned data_len, unsigned lag, FLAC__real autoc[]);
  85841. # endif
  85842. # endif
  85843. #endif
  85844. void FLAC__lpc_compute_lp_coefficients(const FLAC__real autoc[], unsigned *max_order, FLAC__real lp_coeff[][FLAC__MAX_LPC_ORDER], FLAC__double error[]);
  85845. int FLAC__lpc_quantize_coefficients(const FLAC__real lp_coeff[], unsigned order, unsigned precision, FLAC__int32 qlp_coeff[], int *shift);
  85846. 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[]);
  85847. 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[]);
  85848. #ifndef FLAC__NO_ASM
  85849. # ifdef FLAC__CPU_IA32
  85850. # ifdef FLAC__HAS_NASM
  85851. 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[]);
  85852. 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[]);
  85853. # endif
  85854. # endif
  85855. #endif
  85856. #endif /* !defined FLAC__INTEGER_ONLY_LIBRARY */
  85857. 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[]);
  85858. 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[]);
  85859. #ifndef FLAC__NO_ASM
  85860. # ifdef FLAC__CPU_IA32
  85861. # ifdef FLAC__HAS_NASM
  85862. 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[]);
  85863. 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[]);
  85864. # endif /* FLAC__HAS_NASM */
  85865. # elif defined FLAC__CPU_PPC
  85866. 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[]);
  85867. 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[]);
  85868. # endif/* FLAC__CPU_IA32 || FLAC__CPU_PPC */
  85869. #endif /* FLAC__NO_ASM */
  85870. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  85871. FLAC__double FLAC__lpc_compute_expected_bits_per_residual_sample(FLAC__double lpc_error, unsigned total_samples);
  85872. FLAC__double FLAC__lpc_compute_expected_bits_per_residual_sample_with_error_scale(FLAC__double lpc_error, FLAC__double error_scale);
  85873. unsigned FLAC__lpc_compute_best_order(const FLAC__double lpc_error[], unsigned max_order, unsigned total_samples, unsigned overhead_bits_per_order);
  85874. #endif /* !defined FLAC__INTEGER_ONLY_LIBRARY */
  85875. #endif
  85876. /********* End of inlined file: lpc.h *********/
  85877. #if defined DEBUG || defined FLAC__OVERFLOW_DETECT || defined FLAC__OVERFLOW_DETECT_VERBOSE
  85878. #include <stdio.h>
  85879. #endif
  85880. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  85881. #ifndef M_LN2
  85882. #define M_LN2 0.69314718055994530942
  85883. #endif
  85884. #define FLAC__LPC_UNROLLED_FILTER_LOOPS
  85885. void FLAC__lpc_window_data(const FLAC__int32 in[], const FLAC__real window[], FLAC__real out[], unsigned data_len)
  85886. {
  85887. unsigned i;
  85888. for(i = 0; i < data_len; i++)
  85889. out[i] = in[i] * window[i];
  85890. }
  85891. void FLAC__lpc_compute_autocorrelation(const FLAC__real data[], unsigned data_len, unsigned lag, FLAC__real autoc[])
  85892. {
  85893. #if 0
  85894. FLAC__real d;
  85895. unsigned i;
  85896. FLAC__ASSERT(lag > 0);
  85897. FLAC__ASSERT(lag <= data_len);
  85898. while(lag--) {
  85899. for(i = lag, d = 0.0; i < data_len; i++)
  85900. d += data[i] * data[i - lag];
  85901. autoc[lag] = d;
  85902. }
  85903. #endif
  85904. FLAC__real d;
  85905. unsigned sample, coeff;
  85906. const unsigned limit = data_len - lag;
  85907. FLAC__ASSERT(lag > 0);
  85908. FLAC__ASSERT(lag <= data_len);
  85909. for(coeff = 0; coeff < lag; coeff++)
  85910. autoc[coeff] = 0.0;
  85911. for(sample = 0; sample <= limit; sample++) {
  85912. d = data[sample];
  85913. for(coeff = 0; coeff < lag; coeff++)
  85914. autoc[coeff] += d * data[sample+coeff];
  85915. }
  85916. for(; sample < data_len; sample++) {
  85917. d = data[sample];
  85918. for(coeff = 0; coeff < data_len - sample; coeff++)
  85919. autoc[coeff] += d * data[sample+coeff];
  85920. }
  85921. }
  85922. void FLAC__lpc_compute_lp_coefficients(const FLAC__real autoc[], unsigned *max_order, FLAC__real lp_coeff[][FLAC__MAX_LPC_ORDER], FLAC__double error[])
  85923. {
  85924. unsigned i, j;
  85925. FLAC__double r, err, ref[FLAC__MAX_LPC_ORDER], lpc[FLAC__MAX_LPC_ORDER];
  85926. FLAC__ASSERT(0 != max_order);
  85927. FLAC__ASSERT(0 < *max_order);
  85928. FLAC__ASSERT(*max_order <= FLAC__MAX_LPC_ORDER);
  85929. FLAC__ASSERT(autoc[0] != 0.0);
  85930. err = autoc[0];
  85931. for(i = 0; i < *max_order; i++) {
  85932. r = -autoc[i+1];
  85933. for(j = 0; j < i; j++)
  85934. r -= lpc[j] * autoc[i-j];
  85935. ref[i] = (r/=err);
  85936. lpc[i]=r;
  85937. for(j = 0; j < (i>>1); j++) {
  85938. FLAC__double tmp = lpc[j];
  85939. lpc[j] += r * lpc[i-1-j];
  85940. lpc[i-1-j] += r * tmp;
  85941. }
  85942. if(i & 1)
  85943. lpc[j] += lpc[j] * r;
  85944. err *= (1.0 - r * r);
  85945. for(j = 0; j <= i; j++)
  85946. lp_coeff[i][j] = (FLAC__real)(-lpc[j]); /* negate FIR filter coeff to get predictor coeff */
  85947. error[i] = err;
  85948. if(err == 0.0) {
  85949. *max_order = i+1;
  85950. return;
  85951. }
  85952. }
  85953. }
  85954. int FLAC__lpc_quantize_coefficients(const FLAC__real lp_coeff[], unsigned order, unsigned precision, FLAC__int32 qlp_coeff[], int *shift)
  85955. {
  85956. unsigned i;
  85957. FLAC__double cmax;
  85958. FLAC__int32 qmax, qmin;
  85959. FLAC__ASSERT(precision > 0);
  85960. FLAC__ASSERT(precision >= FLAC__MIN_QLP_COEFF_PRECISION);
  85961. precision--;
  85962. qmax = 1 << precision;
  85963. qmin = -qmax;
  85964. qmax--;
  85965. cmax = 0.0;
  85966. for(i = 0; i < order; i++) {
  85967. const FLAC__double d = fabs(lp_coeff[i]);
  85968. if(d > cmax)
  85969. cmax = d;
  85970. }
  85971. if(cmax <= 0.0) {
  85972. return 2;
  85973. }
  85974. else {
  85975. const int max_shiftlimit = (1 << (FLAC__SUBFRAME_LPC_QLP_SHIFT_LEN-1)) - 1;
  85976. const int min_shiftlimit = -max_shiftlimit - 1;
  85977. int log2cmax;
  85978. (void)frexp(cmax, &log2cmax);
  85979. log2cmax--;
  85980. *shift = (int)precision - log2cmax - 1;
  85981. if(*shift > max_shiftlimit)
  85982. *shift = max_shiftlimit;
  85983. else if(*shift < min_shiftlimit)
  85984. return 1;
  85985. }
  85986. if(*shift >= 0) {
  85987. FLAC__double error = 0.0;
  85988. FLAC__int32 q;
  85989. for(i = 0; i < order; i++) {
  85990. error += lp_coeff[i] * (1 << *shift);
  85991. #if 1 /* unfortunately lround() is C99 */
  85992. if(error >= 0.0)
  85993. q = (FLAC__int32)(error + 0.5);
  85994. else
  85995. q = (FLAC__int32)(error - 0.5);
  85996. #else
  85997. q = lround(error);
  85998. #endif
  85999. #ifdef FLAC__OVERFLOW_DETECT
  86000. if(q > qmax+1) /* we expect q==qmax+1 occasionally due to rounding */
  86001. 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]);
  86002. else if(q < qmin)
  86003. 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]);
  86004. #endif
  86005. if(q > qmax)
  86006. q = qmax;
  86007. else if(q < qmin)
  86008. q = qmin;
  86009. error -= q;
  86010. qlp_coeff[i] = q;
  86011. }
  86012. }
  86013. else {
  86014. const int nshift = -(*shift);
  86015. FLAC__double error = 0.0;
  86016. FLAC__int32 q;
  86017. #ifdef DEBUG
  86018. fprintf(stderr,"FLAC__lpc_quantize_coefficients: negative shift=%d order=%u cmax=%f\n", *shift, order, cmax);
  86019. #endif
  86020. for(i = 0; i < order; i++) {
  86021. error += lp_coeff[i] / (1 << nshift);
  86022. #if 1 /* unfortunately lround() is C99 */
  86023. if(error >= 0.0)
  86024. q = (FLAC__int32)(error + 0.5);
  86025. else
  86026. q = (FLAC__int32)(error - 0.5);
  86027. #else
  86028. q = lround(error);
  86029. #endif
  86030. #ifdef FLAC__OVERFLOW_DETECT
  86031. if(q > qmax+1) /* we expect q==qmax+1 occasionally due to rounding */
  86032. 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]);
  86033. else if(q < qmin)
  86034. 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]);
  86035. #endif
  86036. if(q > qmax)
  86037. q = qmax;
  86038. else if(q < qmin)
  86039. q = qmin;
  86040. error -= q;
  86041. qlp_coeff[i] = q;
  86042. }
  86043. *shift = 0;
  86044. }
  86045. return 0;
  86046. }
  86047. 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[])
  86048. #if defined(FLAC__OVERFLOW_DETECT) || !defined(FLAC__LPC_UNROLLED_FILTER_LOOPS)
  86049. {
  86050. FLAC__int64 sumo;
  86051. unsigned i, j;
  86052. FLAC__int32 sum;
  86053. const FLAC__int32 *history;
  86054. #ifdef FLAC__OVERFLOW_DETECT_VERBOSE
  86055. fprintf(stderr,"FLAC__lpc_compute_residual_from_qlp_coefficients: data_len=%d, order=%u, lpq=%d",data_len,order,lp_quantization);
  86056. for(i=0;i<order;i++)
  86057. fprintf(stderr,", q[%u]=%d",i,qlp_coeff[i]);
  86058. fprintf(stderr,"\n");
  86059. #endif
  86060. FLAC__ASSERT(order > 0);
  86061. for(i = 0; i < data_len; i++) {
  86062. sumo = 0;
  86063. sum = 0;
  86064. history = data;
  86065. for(j = 0; j < order; j++) {
  86066. sum += qlp_coeff[j] * (*(--history));
  86067. sumo += (FLAC__int64)qlp_coeff[j] * (FLAC__int64)(*history);
  86068. #if defined _MSC_VER
  86069. if(sumo > 2147483647I64 || sumo < -2147483648I64)
  86070. 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);
  86071. #else
  86072. if(sumo > 2147483647ll || sumo < -2147483648ll)
  86073. 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);
  86074. #endif
  86075. }
  86076. *(residual++) = *(data++) - (sum >> lp_quantization);
  86077. }
  86078. }
  86079. #else /* fully unrolled version for normal use */
  86080. {
  86081. int i;
  86082. FLAC__int32 sum;
  86083. FLAC__ASSERT(order > 0);
  86084. FLAC__ASSERT(order <= 32);
  86085. if(order <= 12) {
  86086. if(order > 8) {
  86087. if(order > 10) {
  86088. if(order == 12) {
  86089. for(i = 0; i < (int)data_len; i++) {
  86090. sum = 0;
  86091. sum += qlp_coeff[11] * data[i-12];
  86092. sum += qlp_coeff[10] * data[i-11];
  86093. sum += qlp_coeff[9] * data[i-10];
  86094. sum += qlp_coeff[8] * data[i-9];
  86095. sum += qlp_coeff[7] * data[i-8];
  86096. sum += qlp_coeff[6] * data[i-7];
  86097. sum += qlp_coeff[5] * data[i-6];
  86098. sum += qlp_coeff[4] * data[i-5];
  86099. sum += qlp_coeff[3] * data[i-4];
  86100. sum += qlp_coeff[2] * data[i-3];
  86101. sum += qlp_coeff[1] * data[i-2];
  86102. sum += qlp_coeff[0] * data[i-1];
  86103. residual[i] = data[i] - (sum >> lp_quantization);
  86104. }
  86105. }
  86106. else { /* order == 11 */
  86107. for(i = 0; i < (int)data_len; i++) {
  86108. sum = 0;
  86109. sum += qlp_coeff[10] * data[i-11];
  86110. sum += qlp_coeff[9] * data[i-10];
  86111. sum += qlp_coeff[8] * data[i-9];
  86112. sum += qlp_coeff[7] * data[i-8];
  86113. sum += qlp_coeff[6] * data[i-7];
  86114. sum += qlp_coeff[5] * data[i-6];
  86115. sum += qlp_coeff[4] * data[i-5];
  86116. sum += qlp_coeff[3] * data[i-4];
  86117. sum += qlp_coeff[2] * data[i-3];
  86118. sum += qlp_coeff[1] * data[i-2];
  86119. sum += qlp_coeff[0] * data[i-1];
  86120. residual[i] = data[i] - (sum >> lp_quantization);
  86121. }
  86122. }
  86123. }
  86124. else {
  86125. if(order == 10) {
  86126. for(i = 0; i < (int)data_len; i++) {
  86127. sum = 0;
  86128. sum += qlp_coeff[9] * data[i-10];
  86129. sum += qlp_coeff[8] * data[i-9];
  86130. sum += qlp_coeff[7] * data[i-8];
  86131. sum += qlp_coeff[6] * data[i-7];
  86132. sum += qlp_coeff[5] * data[i-6];
  86133. sum += qlp_coeff[4] * data[i-5];
  86134. sum += qlp_coeff[3] * data[i-4];
  86135. sum += qlp_coeff[2] * data[i-3];
  86136. sum += qlp_coeff[1] * data[i-2];
  86137. sum += qlp_coeff[0] * data[i-1];
  86138. residual[i] = data[i] - (sum >> lp_quantization);
  86139. }
  86140. }
  86141. else { /* order == 9 */
  86142. for(i = 0; i < (int)data_len; i++) {
  86143. sum = 0;
  86144. sum += qlp_coeff[8] * data[i-9];
  86145. sum += qlp_coeff[7] * data[i-8];
  86146. sum += qlp_coeff[6] * data[i-7];
  86147. sum += qlp_coeff[5] * data[i-6];
  86148. sum += qlp_coeff[4] * data[i-5];
  86149. sum += qlp_coeff[3] * data[i-4];
  86150. sum += qlp_coeff[2] * data[i-3];
  86151. sum += qlp_coeff[1] * data[i-2];
  86152. sum += qlp_coeff[0] * data[i-1];
  86153. residual[i] = data[i] - (sum >> lp_quantization);
  86154. }
  86155. }
  86156. }
  86157. }
  86158. else if(order > 4) {
  86159. if(order > 6) {
  86160. if(order == 8) {
  86161. for(i = 0; i < (int)data_len; i++) {
  86162. sum = 0;
  86163. sum += qlp_coeff[7] * data[i-8];
  86164. sum += qlp_coeff[6] * data[i-7];
  86165. sum += qlp_coeff[5] * data[i-6];
  86166. sum += qlp_coeff[4] * data[i-5];
  86167. sum += qlp_coeff[3] * data[i-4];
  86168. sum += qlp_coeff[2] * data[i-3];
  86169. sum += qlp_coeff[1] * data[i-2];
  86170. sum += qlp_coeff[0] * data[i-1];
  86171. residual[i] = data[i] - (sum >> lp_quantization);
  86172. }
  86173. }
  86174. else { /* order == 7 */
  86175. for(i = 0; i < (int)data_len; i++) {
  86176. sum = 0;
  86177. sum += qlp_coeff[6] * data[i-7];
  86178. sum += qlp_coeff[5] * data[i-6];
  86179. sum += qlp_coeff[4] * data[i-5];
  86180. sum += qlp_coeff[3] * data[i-4];
  86181. sum += qlp_coeff[2] * data[i-3];
  86182. sum += qlp_coeff[1] * data[i-2];
  86183. sum += qlp_coeff[0] * data[i-1];
  86184. residual[i] = data[i] - (sum >> lp_quantization);
  86185. }
  86186. }
  86187. }
  86188. else {
  86189. if(order == 6) {
  86190. for(i = 0; i < (int)data_len; i++) {
  86191. sum = 0;
  86192. sum += qlp_coeff[5] * data[i-6];
  86193. sum += qlp_coeff[4] * data[i-5];
  86194. sum += qlp_coeff[3] * data[i-4];
  86195. sum += qlp_coeff[2] * data[i-3];
  86196. sum += qlp_coeff[1] * data[i-2];
  86197. sum += qlp_coeff[0] * data[i-1];
  86198. residual[i] = data[i] - (sum >> lp_quantization);
  86199. }
  86200. }
  86201. else { /* order == 5 */
  86202. for(i = 0; i < (int)data_len; i++) {
  86203. sum = 0;
  86204. sum += qlp_coeff[4] * data[i-5];
  86205. sum += qlp_coeff[3] * data[i-4];
  86206. sum += qlp_coeff[2] * data[i-3];
  86207. sum += qlp_coeff[1] * data[i-2];
  86208. sum += qlp_coeff[0] * data[i-1];
  86209. residual[i] = data[i] - (sum >> lp_quantization);
  86210. }
  86211. }
  86212. }
  86213. }
  86214. else {
  86215. if(order > 2) {
  86216. if(order == 4) {
  86217. for(i = 0; i < (int)data_len; i++) {
  86218. sum = 0;
  86219. sum += qlp_coeff[3] * data[i-4];
  86220. sum += qlp_coeff[2] * data[i-3];
  86221. sum += qlp_coeff[1] * data[i-2];
  86222. sum += qlp_coeff[0] * data[i-1];
  86223. residual[i] = data[i] - (sum >> lp_quantization);
  86224. }
  86225. }
  86226. else { /* order == 3 */
  86227. for(i = 0; i < (int)data_len; i++) {
  86228. sum = 0;
  86229. sum += qlp_coeff[2] * data[i-3];
  86230. sum += qlp_coeff[1] * data[i-2];
  86231. sum += qlp_coeff[0] * data[i-1];
  86232. residual[i] = data[i] - (sum >> lp_quantization);
  86233. }
  86234. }
  86235. }
  86236. else {
  86237. if(order == 2) {
  86238. for(i = 0; i < (int)data_len; i++) {
  86239. sum = 0;
  86240. sum += qlp_coeff[1] * data[i-2];
  86241. sum += qlp_coeff[0] * data[i-1];
  86242. residual[i] = data[i] - (sum >> lp_quantization);
  86243. }
  86244. }
  86245. else { /* order == 1 */
  86246. for(i = 0; i < (int)data_len; i++)
  86247. residual[i] = data[i] - ((qlp_coeff[0] * data[i-1]) >> lp_quantization);
  86248. }
  86249. }
  86250. }
  86251. }
  86252. else { /* order > 12 */
  86253. for(i = 0; i < (int)data_len; i++) {
  86254. sum = 0;
  86255. switch(order) {
  86256. case 32: sum += qlp_coeff[31] * data[i-32];
  86257. case 31: sum += qlp_coeff[30] * data[i-31];
  86258. case 30: sum += qlp_coeff[29] * data[i-30];
  86259. case 29: sum += qlp_coeff[28] * data[i-29];
  86260. case 28: sum += qlp_coeff[27] * data[i-28];
  86261. case 27: sum += qlp_coeff[26] * data[i-27];
  86262. case 26: sum += qlp_coeff[25] * data[i-26];
  86263. case 25: sum += qlp_coeff[24] * data[i-25];
  86264. case 24: sum += qlp_coeff[23] * data[i-24];
  86265. case 23: sum += qlp_coeff[22] * data[i-23];
  86266. case 22: sum += qlp_coeff[21] * data[i-22];
  86267. case 21: sum += qlp_coeff[20] * data[i-21];
  86268. case 20: sum += qlp_coeff[19] * data[i-20];
  86269. case 19: sum += qlp_coeff[18] * data[i-19];
  86270. case 18: sum += qlp_coeff[17] * data[i-18];
  86271. case 17: sum += qlp_coeff[16] * data[i-17];
  86272. case 16: sum += qlp_coeff[15] * data[i-16];
  86273. case 15: sum += qlp_coeff[14] * data[i-15];
  86274. case 14: sum += qlp_coeff[13] * data[i-14];
  86275. case 13: sum += qlp_coeff[12] * data[i-13];
  86276. sum += qlp_coeff[11] * data[i-12];
  86277. sum += qlp_coeff[10] * data[i-11];
  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. }
  86289. residual[i] = data[i] - (sum >> lp_quantization);
  86290. }
  86291. }
  86292. }
  86293. #endif
  86294. 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[])
  86295. #if defined(FLAC__OVERFLOW_DETECT) || !defined(FLAC__LPC_UNROLLED_FILTER_LOOPS)
  86296. {
  86297. unsigned i, j;
  86298. FLAC__int64 sum;
  86299. const FLAC__int32 *history;
  86300. #ifdef FLAC__OVERFLOW_DETECT_VERBOSE
  86301. fprintf(stderr,"FLAC__lpc_compute_residual_from_qlp_coefficients_wide: data_len=%d, order=%u, lpq=%d",data_len,order,lp_quantization);
  86302. for(i=0;i<order;i++)
  86303. fprintf(stderr,", q[%u]=%d",i,qlp_coeff[i]);
  86304. fprintf(stderr,"\n");
  86305. #endif
  86306. FLAC__ASSERT(order > 0);
  86307. for(i = 0; i < data_len; i++) {
  86308. sum = 0;
  86309. history = data;
  86310. for(j = 0; j < order; j++)
  86311. sum += (FLAC__int64)qlp_coeff[j] * (FLAC__int64)(*(--history));
  86312. if(FLAC__bitmath_silog2_wide(sum >> lp_quantization) > 32) {
  86313. #if defined _MSC_VER
  86314. fprintf(stderr,"FLAC__lpc_compute_residual_from_qlp_coefficients_wide: OVERFLOW, i=%u, sum=%I64d\n", i, sum >> lp_quantization);
  86315. #else
  86316. fprintf(stderr,"FLAC__lpc_compute_residual_from_qlp_coefficients_wide: OVERFLOW, i=%u, sum=%lld\n", i, (long long)(sum >> lp_quantization));
  86317. #endif
  86318. break;
  86319. }
  86320. if(FLAC__bitmath_silog2_wide((FLAC__int64)(*data) - (sum >> lp_quantization)) > 32) {
  86321. #if defined _MSC_VER
  86322. 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));
  86323. #else
  86324. 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)));
  86325. #endif
  86326. break;
  86327. }
  86328. *(residual++) = *(data++) - (FLAC__int32)(sum >> lp_quantization);
  86329. }
  86330. }
  86331. #else /* fully unrolled version for normal use */
  86332. {
  86333. int i;
  86334. FLAC__int64 sum;
  86335. FLAC__ASSERT(order > 0);
  86336. FLAC__ASSERT(order <= 32);
  86337. if(order <= 12) {
  86338. if(order > 8) {
  86339. if(order > 10) {
  86340. if(order == 12) {
  86341. for(i = 0; i < (int)data_len; i++) {
  86342. sum = 0;
  86343. sum += qlp_coeff[11] * (FLAC__int64)data[i-12];
  86344. sum += qlp_coeff[10] * (FLAC__int64)data[i-11];
  86345. sum += qlp_coeff[9] * (FLAC__int64)data[i-10];
  86346. sum += qlp_coeff[8] * (FLAC__int64)data[i-9];
  86347. sum += qlp_coeff[7] * (FLAC__int64)data[i-8];
  86348. sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
  86349. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  86350. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  86351. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  86352. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  86353. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  86354. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  86355. residual[i] = data[i] - (FLAC__int32)(sum >> lp_quantization);
  86356. }
  86357. }
  86358. else { /* order == 11 */
  86359. for(i = 0; i < (int)data_len; i++) {
  86360. sum = 0;
  86361. sum += qlp_coeff[10] * (FLAC__int64)data[i-11];
  86362. sum += qlp_coeff[9] * (FLAC__int64)data[i-10];
  86363. sum += qlp_coeff[8] * (FLAC__int64)data[i-9];
  86364. sum += qlp_coeff[7] * (FLAC__int64)data[i-8];
  86365. sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
  86366. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  86367. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  86368. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  86369. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  86370. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  86371. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  86372. residual[i] = data[i] - (FLAC__int32)(sum >> lp_quantization);
  86373. }
  86374. }
  86375. }
  86376. else {
  86377. if(order == 10) {
  86378. for(i = 0; i < (int)data_len; i++) {
  86379. sum = 0;
  86380. sum += qlp_coeff[9] * (FLAC__int64)data[i-10];
  86381. sum += qlp_coeff[8] * (FLAC__int64)data[i-9];
  86382. sum += qlp_coeff[7] * (FLAC__int64)data[i-8];
  86383. sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
  86384. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  86385. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  86386. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  86387. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  86388. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  86389. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  86390. residual[i] = data[i] - (FLAC__int32)(sum >> lp_quantization);
  86391. }
  86392. }
  86393. else { /* order == 9 */
  86394. for(i = 0; i < (int)data_len; i++) {
  86395. sum = 0;
  86396. sum += qlp_coeff[8] * (FLAC__int64)data[i-9];
  86397. sum += qlp_coeff[7] * (FLAC__int64)data[i-8];
  86398. sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
  86399. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  86400. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  86401. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  86402. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  86403. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  86404. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  86405. residual[i] = data[i] - (FLAC__int32)(sum >> lp_quantization);
  86406. }
  86407. }
  86408. }
  86409. }
  86410. else if(order > 4) {
  86411. if(order > 6) {
  86412. if(order == 8) {
  86413. for(i = 0; i < (int)data_len; i++) {
  86414. sum = 0;
  86415. sum += qlp_coeff[7] * (FLAC__int64)data[i-8];
  86416. sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
  86417. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  86418. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  86419. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  86420. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  86421. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  86422. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  86423. residual[i] = data[i] - (FLAC__int32)(sum >> lp_quantization);
  86424. }
  86425. }
  86426. else { /* order == 7 */
  86427. for(i = 0; i < (int)data_len; i++) {
  86428. sum = 0;
  86429. sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
  86430. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  86431. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  86432. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  86433. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  86434. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  86435. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  86436. residual[i] = data[i] - (FLAC__int32)(sum >> lp_quantization);
  86437. }
  86438. }
  86439. }
  86440. else {
  86441. if(order == 6) {
  86442. for(i = 0; i < (int)data_len; i++) {
  86443. sum = 0;
  86444. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  86445. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  86446. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  86447. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  86448. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  86449. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  86450. residual[i] = data[i] - (FLAC__int32)(sum >> lp_quantization);
  86451. }
  86452. }
  86453. else { /* order == 5 */
  86454. for(i = 0; i < (int)data_len; i++) {
  86455. sum = 0;
  86456. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  86457. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  86458. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  86459. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  86460. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  86461. residual[i] = data[i] - (FLAC__int32)(sum >> lp_quantization);
  86462. }
  86463. }
  86464. }
  86465. }
  86466. else {
  86467. if(order > 2) {
  86468. if(order == 4) {
  86469. for(i = 0; i < (int)data_len; i++) {
  86470. sum = 0;
  86471. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  86472. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  86473. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  86474. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  86475. residual[i] = data[i] - (FLAC__int32)(sum >> lp_quantization);
  86476. }
  86477. }
  86478. else { /* order == 3 */
  86479. for(i = 0; i < (int)data_len; i++) {
  86480. sum = 0;
  86481. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  86482. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  86483. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  86484. residual[i] = data[i] - (FLAC__int32)(sum >> lp_quantization);
  86485. }
  86486. }
  86487. }
  86488. else {
  86489. if(order == 2) {
  86490. for(i = 0; i < (int)data_len; i++) {
  86491. sum = 0;
  86492. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  86493. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  86494. residual[i] = data[i] - (FLAC__int32)(sum >> lp_quantization);
  86495. }
  86496. }
  86497. else { /* order == 1 */
  86498. for(i = 0; i < (int)data_len; i++)
  86499. residual[i] = data[i] - (FLAC__int32)((qlp_coeff[0] * (FLAC__int64)data[i-1]) >> lp_quantization);
  86500. }
  86501. }
  86502. }
  86503. }
  86504. else { /* order > 12 */
  86505. for(i = 0; i < (int)data_len; i++) {
  86506. sum = 0;
  86507. switch(order) {
  86508. case 32: sum += qlp_coeff[31] * (FLAC__int64)data[i-32];
  86509. case 31: sum += qlp_coeff[30] * (FLAC__int64)data[i-31];
  86510. case 30: sum += qlp_coeff[29] * (FLAC__int64)data[i-30];
  86511. case 29: sum += qlp_coeff[28] * (FLAC__int64)data[i-29];
  86512. case 28: sum += qlp_coeff[27] * (FLAC__int64)data[i-28];
  86513. case 27: sum += qlp_coeff[26] * (FLAC__int64)data[i-27];
  86514. case 26: sum += qlp_coeff[25] * (FLAC__int64)data[i-26];
  86515. case 25: sum += qlp_coeff[24] * (FLAC__int64)data[i-25];
  86516. case 24: sum += qlp_coeff[23] * (FLAC__int64)data[i-24];
  86517. case 23: sum += qlp_coeff[22] * (FLAC__int64)data[i-23];
  86518. case 22: sum += qlp_coeff[21] * (FLAC__int64)data[i-22];
  86519. case 21: sum += qlp_coeff[20] * (FLAC__int64)data[i-21];
  86520. case 20: sum += qlp_coeff[19] * (FLAC__int64)data[i-20];
  86521. case 19: sum += qlp_coeff[18] * (FLAC__int64)data[i-19];
  86522. case 18: sum += qlp_coeff[17] * (FLAC__int64)data[i-18];
  86523. case 17: sum += qlp_coeff[16] * (FLAC__int64)data[i-17];
  86524. case 16: sum += qlp_coeff[15] * (FLAC__int64)data[i-16];
  86525. case 15: sum += qlp_coeff[14] * (FLAC__int64)data[i-15];
  86526. case 14: sum += qlp_coeff[13] * (FLAC__int64)data[i-14];
  86527. case 13: sum += qlp_coeff[12] * (FLAC__int64)data[i-13];
  86528. sum += qlp_coeff[11] * (FLAC__int64)data[i-12];
  86529. sum += qlp_coeff[10] * (FLAC__int64)data[i-11];
  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. }
  86541. residual[i] = data[i] - (FLAC__int32)(sum >> lp_quantization);
  86542. }
  86543. }
  86544. }
  86545. #endif
  86546. #endif /* !defined FLAC__INTEGER_ONLY_LIBRARY */
  86547. 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[])
  86548. #if defined(FLAC__OVERFLOW_DETECT) || !defined(FLAC__LPC_UNROLLED_FILTER_LOOPS)
  86549. {
  86550. FLAC__int64 sumo;
  86551. unsigned i, j;
  86552. FLAC__int32 sum;
  86553. const FLAC__int32 *r = residual, *history;
  86554. #ifdef FLAC__OVERFLOW_DETECT_VERBOSE
  86555. fprintf(stderr,"FLAC__lpc_restore_signal: data_len=%d, order=%u, lpq=%d",data_len,order,lp_quantization);
  86556. for(i=0;i<order;i++)
  86557. fprintf(stderr,", q[%u]=%d",i,qlp_coeff[i]);
  86558. fprintf(stderr,"\n");
  86559. #endif
  86560. FLAC__ASSERT(order > 0);
  86561. for(i = 0; i < data_len; i++) {
  86562. sumo = 0;
  86563. sum = 0;
  86564. history = data;
  86565. for(j = 0; j < order; j++) {
  86566. sum += qlp_coeff[j] * (*(--history));
  86567. sumo += (FLAC__int64)qlp_coeff[j] * (FLAC__int64)(*history);
  86568. #if defined _MSC_VER
  86569. if(sumo > 2147483647I64 || sumo < -2147483648I64)
  86570. 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);
  86571. #else
  86572. if(sumo > 2147483647ll || sumo < -2147483648ll)
  86573. 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);
  86574. #endif
  86575. }
  86576. *(data++) = *(r++) + (sum >> lp_quantization);
  86577. }
  86578. }
  86579. #else /* fully unrolled version for normal use */
  86580. {
  86581. int i;
  86582. FLAC__int32 sum;
  86583. FLAC__ASSERT(order > 0);
  86584. FLAC__ASSERT(order <= 32);
  86585. if(order <= 12) {
  86586. if(order > 8) {
  86587. if(order > 10) {
  86588. if(order == 12) {
  86589. for(i = 0; i < (int)data_len; i++) {
  86590. sum = 0;
  86591. sum += qlp_coeff[11] * data[i-12];
  86592. sum += qlp_coeff[10] * data[i-11];
  86593. sum += qlp_coeff[9] * data[i-10];
  86594. sum += qlp_coeff[8] * data[i-9];
  86595. sum += qlp_coeff[7] * data[i-8];
  86596. sum += qlp_coeff[6] * data[i-7];
  86597. sum += qlp_coeff[5] * data[i-6];
  86598. sum += qlp_coeff[4] * data[i-5];
  86599. sum += qlp_coeff[3] * data[i-4];
  86600. sum += qlp_coeff[2] * data[i-3];
  86601. sum += qlp_coeff[1] * data[i-2];
  86602. sum += qlp_coeff[0] * data[i-1];
  86603. data[i] = residual[i] + (sum >> lp_quantization);
  86604. }
  86605. }
  86606. else { /* order == 11 */
  86607. for(i = 0; i < (int)data_len; i++) {
  86608. sum = 0;
  86609. sum += qlp_coeff[10] * data[i-11];
  86610. sum += qlp_coeff[9] * data[i-10];
  86611. sum += qlp_coeff[8] * data[i-9];
  86612. sum += qlp_coeff[7] * data[i-8];
  86613. sum += qlp_coeff[6] * data[i-7];
  86614. sum += qlp_coeff[5] * data[i-6];
  86615. sum += qlp_coeff[4] * data[i-5];
  86616. sum += qlp_coeff[3] * data[i-4];
  86617. sum += qlp_coeff[2] * data[i-3];
  86618. sum += qlp_coeff[1] * data[i-2];
  86619. sum += qlp_coeff[0] * data[i-1];
  86620. data[i] = residual[i] + (sum >> lp_quantization);
  86621. }
  86622. }
  86623. }
  86624. else {
  86625. if(order == 10) {
  86626. for(i = 0; i < (int)data_len; i++) {
  86627. sum = 0;
  86628. sum += qlp_coeff[9] * data[i-10];
  86629. sum += qlp_coeff[8] * data[i-9];
  86630. sum += qlp_coeff[7] * data[i-8];
  86631. sum += qlp_coeff[6] * data[i-7];
  86632. sum += qlp_coeff[5] * data[i-6];
  86633. sum += qlp_coeff[4] * data[i-5];
  86634. sum += qlp_coeff[3] * data[i-4];
  86635. sum += qlp_coeff[2] * data[i-3];
  86636. sum += qlp_coeff[1] * data[i-2];
  86637. sum += qlp_coeff[0] * data[i-1];
  86638. data[i] = residual[i] + (sum >> lp_quantization);
  86639. }
  86640. }
  86641. else { /* order == 9 */
  86642. for(i = 0; i < (int)data_len; i++) {
  86643. sum = 0;
  86644. sum += qlp_coeff[8] * data[i-9];
  86645. sum += qlp_coeff[7] * data[i-8];
  86646. sum += qlp_coeff[6] * data[i-7];
  86647. sum += qlp_coeff[5] * data[i-6];
  86648. sum += qlp_coeff[4] * data[i-5];
  86649. sum += qlp_coeff[3] * data[i-4];
  86650. sum += qlp_coeff[2] * data[i-3];
  86651. sum += qlp_coeff[1] * data[i-2];
  86652. sum += qlp_coeff[0] * data[i-1];
  86653. data[i] = residual[i] + (sum >> lp_quantization);
  86654. }
  86655. }
  86656. }
  86657. }
  86658. else if(order > 4) {
  86659. if(order > 6) {
  86660. if(order == 8) {
  86661. for(i = 0; i < (int)data_len; i++) {
  86662. sum = 0;
  86663. sum += qlp_coeff[7] * data[i-8];
  86664. sum += qlp_coeff[6] * data[i-7];
  86665. sum += qlp_coeff[5] * data[i-6];
  86666. sum += qlp_coeff[4] * data[i-5];
  86667. sum += qlp_coeff[3] * data[i-4];
  86668. sum += qlp_coeff[2] * data[i-3];
  86669. sum += qlp_coeff[1] * data[i-2];
  86670. sum += qlp_coeff[0] * data[i-1];
  86671. data[i] = residual[i] + (sum >> lp_quantization);
  86672. }
  86673. }
  86674. else { /* order == 7 */
  86675. for(i = 0; i < (int)data_len; i++) {
  86676. sum = 0;
  86677. sum += qlp_coeff[6] * data[i-7];
  86678. sum += qlp_coeff[5] * data[i-6];
  86679. sum += qlp_coeff[4] * data[i-5];
  86680. sum += qlp_coeff[3] * data[i-4];
  86681. sum += qlp_coeff[2] * data[i-3];
  86682. sum += qlp_coeff[1] * data[i-2];
  86683. sum += qlp_coeff[0] * data[i-1];
  86684. data[i] = residual[i] + (sum >> lp_quantization);
  86685. }
  86686. }
  86687. }
  86688. else {
  86689. if(order == 6) {
  86690. for(i = 0; i < (int)data_len; i++) {
  86691. sum = 0;
  86692. sum += qlp_coeff[5] * data[i-6];
  86693. sum += qlp_coeff[4] * data[i-5];
  86694. sum += qlp_coeff[3] * data[i-4];
  86695. sum += qlp_coeff[2] * data[i-3];
  86696. sum += qlp_coeff[1] * data[i-2];
  86697. sum += qlp_coeff[0] * data[i-1];
  86698. data[i] = residual[i] + (sum >> lp_quantization);
  86699. }
  86700. }
  86701. else { /* order == 5 */
  86702. for(i = 0; i < (int)data_len; i++) {
  86703. sum = 0;
  86704. sum += qlp_coeff[4] * data[i-5];
  86705. sum += qlp_coeff[3] * data[i-4];
  86706. sum += qlp_coeff[2] * data[i-3];
  86707. sum += qlp_coeff[1] * data[i-2];
  86708. sum += qlp_coeff[0] * data[i-1];
  86709. data[i] = residual[i] + (sum >> lp_quantization);
  86710. }
  86711. }
  86712. }
  86713. }
  86714. else {
  86715. if(order > 2) {
  86716. if(order == 4) {
  86717. for(i = 0; i < (int)data_len; i++) {
  86718. sum = 0;
  86719. sum += qlp_coeff[3] * data[i-4];
  86720. sum += qlp_coeff[2] * data[i-3];
  86721. sum += qlp_coeff[1] * data[i-2];
  86722. sum += qlp_coeff[0] * data[i-1];
  86723. data[i] = residual[i] + (sum >> lp_quantization);
  86724. }
  86725. }
  86726. else { /* order == 3 */
  86727. for(i = 0; i < (int)data_len; i++) {
  86728. sum = 0;
  86729. sum += qlp_coeff[2] * data[i-3];
  86730. sum += qlp_coeff[1] * data[i-2];
  86731. sum += qlp_coeff[0] * data[i-1];
  86732. data[i] = residual[i] + (sum >> lp_quantization);
  86733. }
  86734. }
  86735. }
  86736. else {
  86737. if(order == 2) {
  86738. for(i = 0; i < (int)data_len; i++) {
  86739. sum = 0;
  86740. sum += qlp_coeff[1] * data[i-2];
  86741. sum += qlp_coeff[0] * data[i-1];
  86742. data[i] = residual[i] + (sum >> lp_quantization);
  86743. }
  86744. }
  86745. else { /* order == 1 */
  86746. for(i = 0; i < (int)data_len; i++)
  86747. data[i] = residual[i] + ((qlp_coeff[0] * data[i-1]) >> lp_quantization);
  86748. }
  86749. }
  86750. }
  86751. }
  86752. else { /* order > 12 */
  86753. for(i = 0; i < (int)data_len; i++) {
  86754. sum = 0;
  86755. switch(order) {
  86756. case 32: sum += qlp_coeff[31] * data[i-32];
  86757. case 31: sum += qlp_coeff[30] * data[i-31];
  86758. case 30: sum += qlp_coeff[29] * data[i-30];
  86759. case 29: sum += qlp_coeff[28] * data[i-29];
  86760. case 28: sum += qlp_coeff[27] * data[i-28];
  86761. case 27: sum += qlp_coeff[26] * data[i-27];
  86762. case 26: sum += qlp_coeff[25] * data[i-26];
  86763. case 25: sum += qlp_coeff[24] * data[i-25];
  86764. case 24: sum += qlp_coeff[23] * data[i-24];
  86765. case 23: sum += qlp_coeff[22] * data[i-23];
  86766. case 22: sum += qlp_coeff[21] * data[i-22];
  86767. case 21: sum += qlp_coeff[20] * data[i-21];
  86768. case 20: sum += qlp_coeff[19] * data[i-20];
  86769. case 19: sum += qlp_coeff[18] * data[i-19];
  86770. case 18: sum += qlp_coeff[17] * data[i-18];
  86771. case 17: sum += qlp_coeff[16] * data[i-17];
  86772. case 16: sum += qlp_coeff[15] * data[i-16];
  86773. case 15: sum += qlp_coeff[14] * data[i-15];
  86774. case 14: sum += qlp_coeff[13] * data[i-14];
  86775. case 13: sum += qlp_coeff[12] * data[i-13];
  86776. sum += qlp_coeff[11] * data[i-12];
  86777. sum += qlp_coeff[10] * data[i-11];
  86778. sum += qlp_coeff[ 9] * data[i-10];
  86779. sum += qlp_coeff[ 8] * data[i- 9];
  86780. sum += qlp_coeff[ 7] * data[i- 8];
  86781. sum += qlp_coeff[ 6] * data[i- 7];
  86782. sum += qlp_coeff[ 5] * data[i- 6];
  86783. sum += qlp_coeff[ 4] * data[i- 5];
  86784. sum += qlp_coeff[ 3] * data[i- 4];
  86785. sum += qlp_coeff[ 2] * data[i- 3];
  86786. sum += qlp_coeff[ 1] * data[i- 2];
  86787. sum += qlp_coeff[ 0] * data[i- 1];
  86788. }
  86789. data[i] = residual[i] + (sum >> lp_quantization);
  86790. }
  86791. }
  86792. }
  86793. #endif
  86794. 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[])
  86795. #if defined(FLAC__OVERFLOW_DETECT) || !defined(FLAC__LPC_UNROLLED_FILTER_LOOPS)
  86796. {
  86797. unsigned i, j;
  86798. FLAC__int64 sum;
  86799. const FLAC__int32 *r = residual, *history;
  86800. #ifdef FLAC__OVERFLOW_DETECT_VERBOSE
  86801. fprintf(stderr,"FLAC__lpc_restore_signal_wide: data_len=%d, order=%u, lpq=%d",data_len,order,lp_quantization);
  86802. for(i=0;i<order;i++)
  86803. fprintf(stderr,", q[%u]=%d",i,qlp_coeff[i]);
  86804. fprintf(stderr,"\n");
  86805. #endif
  86806. FLAC__ASSERT(order > 0);
  86807. for(i = 0; i < data_len; i++) {
  86808. sum = 0;
  86809. history = data;
  86810. for(j = 0; j < order; j++)
  86811. sum += (FLAC__int64)qlp_coeff[j] * (FLAC__int64)(*(--history));
  86812. if(FLAC__bitmath_silog2_wide(sum >> lp_quantization) > 32) {
  86813. #ifdef _MSC_VER
  86814. fprintf(stderr,"FLAC__lpc_restore_signal_wide: OVERFLOW, i=%u, sum=%I64d\n", i, sum >> lp_quantization);
  86815. #else
  86816. fprintf(stderr,"FLAC__lpc_restore_signal_wide: OVERFLOW, i=%u, sum=%lld\n", i, (long long)(sum >> lp_quantization));
  86817. #endif
  86818. break;
  86819. }
  86820. if(FLAC__bitmath_silog2_wide((FLAC__int64)(*r) + (sum >> lp_quantization)) > 32) {
  86821. #ifdef _MSC_VER
  86822. 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));
  86823. #else
  86824. 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)));
  86825. #endif
  86826. break;
  86827. }
  86828. *(data++) = *(r++) + (FLAC__int32)(sum >> lp_quantization);
  86829. }
  86830. }
  86831. #else /* fully unrolled version for normal use */
  86832. {
  86833. int i;
  86834. FLAC__int64 sum;
  86835. FLAC__ASSERT(order > 0);
  86836. FLAC__ASSERT(order <= 32);
  86837. if(order <= 12) {
  86838. if(order > 8) {
  86839. if(order > 10) {
  86840. if(order == 12) {
  86841. for(i = 0; i < (int)data_len; i++) {
  86842. sum = 0;
  86843. sum += qlp_coeff[11] * (FLAC__int64)data[i-12];
  86844. sum += qlp_coeff[10] * (FLAC__int64)data[i-11];
  86845. sum += qlp_coeff[9] * (FLAC__int64)data[i-10];
  86846. sum += qlp_coeff[8] * (FLAC__int64)data[i-9];
  86847. sum += qlp_coeff[7] * (FLAC__int64)data[i-8];
  86848. sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
  86849. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  86850. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  86851. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  86852. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  86853. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  86854. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  86855. data[i] = residual[i] + (FLAC__int32)(sum >> lp_quantization);
  86856. }
  86857. }
  86858. else { /* order == 11 */
  86859. for(i = 0; i < (int)data_len; i++) {
  86860. sum = 0;
  86861. sum += qlp_coeff[10] * (FLAC__int64)data[i-11];
  86862. sum += qlp_coeff[9] * (FLAC__int64)data[i-10];
  86863. sum += qlp_coeff[8] * (FLAC__int64)data[i-9];
  86864. sum += qlp_coeff[7] * (FLAC__int64)data[i-8];
  86865. sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
  86866. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  86867. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  86868. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  86869. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  86870. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  86871. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  86872. data[i] = residual[i] + (FLAC__int32)(sum >> lp_quantization);
  86873. }
  86874. }
  86875. }
  86876. else {
  86877. if(order == 10) {
  86878. for(i = 0; i < (int)data_len; i++) {
  86879. sum = 0;
  86880. sum += qlp_coeff[9] * (FLAC__int64)data[i-10];
  86881. sum += qlp_coeff[8] * (FLAC__int64)data[i-9];
  86882. sum += qlp_coeff[7] * (FLAC__int64)data[i-8];
  86883. sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
  86884. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  86885. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  86886. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  86887. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  86888. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  86889. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  86890. data[i] = residual[i] + (FLAC__int32)(sum >> lp_quantization);
  86891. }
  86892. }
  86893. else { /* order == 9 */
  86894. for(i = 0; i < (int)data_len; i++) {
  86895. sum = 0;
  86896. sum += qlp_coeff[8] * (FLAC__int64)data[i-9];
  86897. sum += qlp_coeff[7] * (FLAC__int64)data[i-8];
  86898. sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
  86899. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  86900. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  86901. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  86902. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  86903. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  86904. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  86905. data[i] = residual[i] + (FLAC__int32)(sum >> lp_quantization);
  86906. }
  86907. }
  86908. }
  86909. }
  86910. else if(order > 4) {
  86911. if(order > 6) {
  86912. if(order == 8) {
  86913. for(i = 0; i < (int)data_len; i++) {
  86914. sum = 0;
  86915. sum += qlp_coeff[7] * (FLAC__int64)data[i-8];
  86916. sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
  86917. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  86918. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  86919. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  86920. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  86921. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  86922. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  86923. data[i] = residual[i] + (FLAC__int32)(sum >> lp_quantization);
  86924. }
  86925. }
  86926. else { /* order == 7 */
  86927. for(i = 0; i < (int)data_len; i++) {
  86928. sum = 0;
  86929. sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
  86930. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  86931. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  86932. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  86933. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  86934. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  86935. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  86936. data[i] = residual[i] + (FLAC__int32)(sum >> lp_quantization);
  86937. }
  86938. }
  86939. }
  86940. else {
  86941. if(order == 6) {
  86942. for(i = 0; i < (int)data_len; i++) {
  86943. sum = 0;
  86944. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  86945. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  86946. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  86947. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  86948. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  86949. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  86950. data[i] = residual[i] + (FLAC__int32)(sum >> lp_quantization);
  86951. }
  86952. }
  86953. else { /* order == 5 */
  86954. for(i = 0; i < (int)data_len; i++) {
  86955. sum = 0;
  86956. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  86957. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  86958. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  86959. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  86960. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  86961. data[i] = residual[i] + (FLAC__int32)(sum >> lp_quantization);
  86962. }
  86963. }
  86964. }
  86965. }
  86966. else {
  86967. if(order > 2) {
  86968. if(order == 4) {
  86969. for(i = 0; i < (int)data_len; i++) {
  86970. sum = 0;
  86971. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  86972. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  86973. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  86974. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  86975. data[i] = residual[i] + (FLAC__int32)(sum >> lp_quantization);
  86976. }
  86977. }
  86978. else { /* order == 3 */
  86979. for(i = 0; i < (int)data_len; i++) {
  86980. sum = 0;
  86981. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  86982. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  86983. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  86984. data[i] = residual[i] + (FLAC__int32)(sum >> lp_quantization);
  86985. }
  86986. }
  86987. }
  86988. else {
  86989. if(order == 2) {
  86990. for(i = 0; i < (int)data_len; i++) {
  86991. sum = 0;
  86992. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  86993. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  86994. data[i] = residual[i] + (FLAC__int32)(sum >> lp_quantization);
  86995. }
  86996. }
  86997. else { /* order == 1 */
  86998. for(i = 0; i < (int)data_len; i++)
  86999. data[i] = residual[i] + (FLAC__int32)((qlp_coeff[0] * (FLAC__int64)data[i-1]) >> lp_quantization);
  87000. }
  87001. }
  87002. }
  87003. }
  87004. else { /* order > 12 */
  87005. for(i = 0; i < (int)data_len; i++) {
  87006. sum = 0;
  87007. switch(order) {
  87008. case 32: sum += qlp_coeff[31] * (FLAC__int64)data[i-32];
  87009. case 31: sum += qlp_coeff[30] * (FLAC__int64)data[i-31];
  87010. case 30: sum += qlp_coeff[29] * (FLAC__int64)data[i-30];
  87011. case 29: sum += qlp_coeff[28] * (FLAC__int64)data[i-29];
  87012. case 28: sum += qlp_coeff[27] * (FLAC__int64)data[i-28];
  87013. case 27: sum += qlp_coeff[26] * (FLAC__int64)data[i-27];
  87014. case 26: sum += qlp_coeff[25] * (FLAC__int64)data[i-26];
  87015. case 25: sum += qlp_coeff[24] * (FLAC__int64)data[i-25];
  87016. case 24: sum += qlp_coeff[23] * (FLAC__int64)data[i-24];
  87017. case 23: sum += qlp_coeff[22] * (FLAC__int64)data[i-23];
  87018. case 22: sum += qlp_coeff[21] * (FLAC__int64)data[i-22];
  87019. case 21: sum += qlp_coeff[20] * (FLAC__int64)data[i-21];
  87020. case 20: sum += qlp_coeff[19] * (FLAC__int64)data[i-20];
  87021. case 19: sum += qlp_coeff[18] * (FLAC__int64)data[i-19];
  87022. case 18: sum += qlp_coeff[17] * (FLAC__int64)data[i-18];
  87023. case 17: sum += qlp_coeff[16] * (FLAC__int64)data[i-17];
  87024. case 16: sum += qlp_coeff[15] * (FLAC__int64)data[i-16];
  87025. case 15: sum += qlp_coeff[14] * (FLAC__int64)data[i-15];
  87026. case 14: sum += qlp_coeff[13] * (FLAC__int64)data[i-14];
  87027. case 13: sum += qlp_coeff[12] * (FLAC__int64)data[i-13];
  87028. sum += qlp_coeff[11] * (FLAC__int64)data[i-12];
  87029. sum += qlp_coeff[10] * (FLAC__int64)data[i-11];
  87030. sum += qlp_coeff[ 9] * (FLAC__int64)data[i-10];
  87031. sum += qlp_coeff[ 8] * (FLAC__int64)data[i- 9];
  87032. sum += qlp_coeff[ 7] * (FLAC__int64)data[i- 8];
  87033. sum += qlp_coeff[ 6] * (FLAC__int64)data[i- 7];
  87034. sum += qlp_coeff[ 5] * (FLAC__int64)data[i- 6];
  87035. sum += qlp_coeff[ 4] * (FLAC__int64)data[i- 5];
  87036. sum += qlp_coeff[ 3] * (FLAC__int64)data[i- 4];
  87037. sum += qlp_coeff[ 2] * (FLAC__int64)data[i- 3];
  87038. sum += qlp_coeff[ 1] * (FLAC__int64)data[i- 2];
  87039. sum += qlp_coeff[ 0] * (FLAC__int64)data[i- 1];
  87040. }
  87041. data[i] = residual[i] + (FLAC__int32)(sum >> lp_quantization);
  87042. }
  87043. }
  87044. }
  87045. #endif
  87046. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  87047. FLAC__double FLAC__lpc_compute_expected_bits_per_residual_sample(FLAC__double lpc_error, unsigned total_samples)
  87048. {
  87049. FLAC__double error_scale;
  87050. FLAC__ASSERT(total_samples > 0);
  87051. error_scale = 0.5 * M_LN2 * M_LN2 / (FLAC__double)total_samples;
  87052. return FLAC__lpc_compute_expected_bits_per_residual_sample_with_error_scale(lpc_error, error_scale);
  87053. }
  87054. FLAC__double FLAC__lpc_compute_expected_bits_per_residual_sample_with_error_scale(FLAC__double lpc_error, FLAC__double error_scale)
  87055. {
  87056. if(lpc_error > 0.0) {
  87057. FLAC__double bps = (FLAC__double)0.5 * log(error_scale * lpc_error) / M_LN2;
  87058. if(bps >= 0.0)
  87059. return bps;
  87060. else
  87061. return 0.0;
  87062. }
  87063. else if(lpc_error < 0.0) { /* error should not be negative but can happen due to inadequate floating-point resolution */
  87064. return 1e32;
  87065. }
  87066. else {
  87067. return 0.0;
  87068. }
  87069. }
  87070. unsigned FLAC__lpc_compute_best_order(const FLAC__double lpc_error[], unsigned max_order, unsigned total_samples, unsigned overhead_bits_per_order)
  87071. {
  87072. 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 */
  87073. FLAC__double bits, best_bits, error_scale;
  87074. FLAC__ASSERT(max_order > 0);
  87075. FLAC__ASSERT(total_samples > 0);
  87076. error_scale = 0.5 * M_LN2 * M_LN2 / (FLAC__double)total_samples;
  87077. best_index = 0;
  87078. best_bits = (unsigned)(-1);
  87079. for(index = 0, order = 1; index < max_order; index++, order++) {
  87080. 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);
  87081. if(bits < best_bits) {
  87082. best_index = index;
  87083. best_bits = bits;
  87084. }
  87085. }
  87086. return best_index+1; /* +1 since index of lpc_error[] is order-1 */
  87087. }
  87088. #endif /* !defined FLAC__INTEGER_ONLY_LIBRARY */
  87089. #endif
  87090. /********* End of inlined file: lpc_flac.c *********/
  87091. /********* Start of inlined file: md5.c *********/
  87092. /********* Start of inlined file: juce_FlacHeader.h *********/
  87093. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  87094. // tasks..
  87095. #define VERSION "1.2.1"
  87096. #define FLAC__NO_DLL 1
  87097. #if JUCE_MSVC
  87098. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  87099. #endif
  87100. #if JUCE_MAC
  87101. #define FLAC__SYS_DARWIN 1
  87102. #endif
  87103. /********* End of inlined file: juce_FlacHeader.h *********/
  87104. #if JUCE_USE_FLAC
  87105. #if HAVE_CONFIG_H
  87106. # include <config.h>
  87107. #endif
  87108. #include <stdlib.h> /* for malloc() */
  87109. #include <string.h> /* for memcpy() */
  87110. /********* Start of inlined file: md5.h *********/
  87111. #ifndef FLAC__PRIVATE__MD5_H
  87112. #define FLAC__PRIVATE__MD5_H
  87113. typedef struct {
  87114. FLAC__uint32 in[16];
  87115. FLAC__uint32 buf[4];
  87116. FLAC__uint32 bytes[2];
  87117. FLAC__byte *internal_buf;
  87118. size_t capacity;
  87119. } FLAC__MD5Context;
  87120. void FLAC__MD5Init(FLAC__MD5Context *context);
  87121. void FLAC__MD5Final(FLAC__byte digest[16], FLAC__MD5Context *context);
  87122. FLAC__bool FLAC__MD5Accumulate(FLAC__MD5Context *ctx, const FLAC__int32 * const signal[], unsigned channels, unsigned samples, unsigned bytes_per_sample);
  87123. #endif
  87124. /********* End of inlined file: md5.h *********/
  87125. #ifndef FLaC__INLINE
  87126. #define FLaC__INLINE
  87127. #endif
  87128. #define F1(x, y, z) (z ^ (x & (y ^ z)))
  87129. #define F2(x, y, z) F1(z, x, y)
  87130. #define F3(x, y, z) (x ^ y ^ z)
  87131. #define F4(x, y, z) (y ^ (x | ~z))
  87132. #define MD5STEP(f,w,x,y,z,in,s) \
  87133. (w += f(x,y,z) + in, w = (w<<s | w>>(32-s)) + x)
  87134. static void FLAC__MD5Transform(FLAC__uint32 buf[4], FLAC__uint32 const in[16])
  87135. {
  87136. register FLAC__uint32 a, b, c, d;
  87137. a = buf[0];
  87138. b = buf[1];
  87139. c = buf[2];
  87140. d = buf[3];
  87141. MD5STEP(F1, a, b, c, d, in[0] + 0xd76aa478, 7);
  87142. MD5STEP(F1, d, a, b, c, in[1] + 0xe8c7b756, 12);
  87143. MD5STEP(F1, c, d, a, b, in[2] + 0x242070db, 17);
  87144. MD5STEP(F1, b, c, d, a, in[3] + 0xc1bdceee, 22);
  87145. MD5STEP(F1, a, b, c, d, in[4] + 0xf57c0faf, 7);
  87146. MD5STEP(F1, d, a, b, c, in[5] + 0x4787c62a, 12);
  87147. MD5STEP(F1, c, d, a, b, in[6] + 0xa8304613, 17);
  87148. MD5STEP(F1, b, c, d, a, in[7] + 0xfd469501, 22);
  87149. MD5STEP(F1, a, b, c, d, in[8] + 0x698098d8, 7);
  87150. MD5STEP(F1, d, a, b, c, in[9] + 0x8b44f7af, 12);
  87151. MD5STEP(F1, c, d, a, b, in[10] + 0xffff5bb1, 17);
  87152. MD5STEP(F1, b, c, d, a, in[11] + 0x895cd7be, 22);
  87153. MD5STEP(F1, a, b, c, d, in[12] + 0x6b901122, 7);
  87154. MD5STEP(F1, d, a, b, c, in[13] + 0xfd987193, 12);
  87155. MD5STEP(F1, c, d, a, b, in[14] + 0xa679438e, 17);
  87156. MD5STEP(F1, b, c, d, a, in[15] + 0x49b40821, 22);
  87157. MD5STEP(F2, a, b, c, d, in[1] + 0xf61e2562, 5);
  87158. MD5STEP(F2, d, a, b, c, in[6] + 0xc040b340, 9);
  87159. MD5STEP(F2, c, d, a, b, in[11] + 0x265e5a51, 14);
  87160. MD5STEP(F2, b, c, d, a, in[0] + 0xe9b6c7aa, 20);
  87161. MD5STEP(F2, a, b, c, d, in[5] + 0xd62f105d, 5);
  87162. MD5STEP(F2, d, a, b, c, in[10] + 0x02441453, 9);
  87163. MD5STEP(F2, c, d, a, b, in[15] + 0xd8a1e681, 14);
  87164. MD5STEP(F2, b, c, d, a, in[4] + 0xe7d3fbc8, 20);
  87165. MD5STEP(F2, a, b, c, d, in[9] + 0x21e1cde6, 5);
  87166. MD5STEP(F2, d, a, b, c, in[14] + 0xc33707d6, 9);
  87167. MD5STEP(F2, c, d, a, b, in[3] + 0xf4d50d87, 14);
  87168. MD5STEP(F2, b, c, d, a, in[8] + 0x455a14ed, 20);
  87169. MD5STEP(F2, a, b, c, d, in[13] + 0xa9e3e905, 5);
  87170. MD5STEP(F2, d, a, b, c, in[2] + 0xfcefa3f8, 9);
  87171. MD5STEP(F2, c, d, a, b, in[7] + 0x676f02d9, 14);
  87172. MD5STEP(F2, b, c, d, a, in[12] + 0x8d2a4c8a, 20);
  87173. MD5STEP(F3, a, b, c, d, in[5] + 0xfffa3942, 4);
  87174. MD5STEP(F3, d, a, b, c, in[8] + 0x8771f681, 11);
  87175. MD5STEP(F3, c, d, a, b, in[11] + 0x6d9d6122, 16);
  87176. MD5STEP(F3, b, c, d, a, in[14] + 0xfde5380c, 23);
  87177. MD5STEP(F3, a, b, c, d, in[1] + 0xa4beea44, 4);
  87178. MD5STEP(F3, d, a, b, c, in[4] + 0x4bdecfa9, 11);
  87179. MD5STEP(F3, c, d, a, b, in[7] + 0xf6bb4b60, 16);
  87180. MD5STEP(F3, b, c, d, a, in[10] + 0xbebfbc70, 23);
  87181. MD5STEP(F3, a, b, c, d, in[13] + 0x289b7ec6, 4);
  87182. MD5STEP(F3, d, a, b, c, in[0] + 0xeaa127fa, 11);
  87183. MD5STEP(F3, c, d, a, b, in[3] + 0xd4ef3085, 16);
  87184. MD5STEP(F3, b, c, d, a, in[6] + 0x04881d05, 23);
  87185. MD5STEP(F3, a, b, c, d, in[9] + 0xd9d4d039, 4);
  87186. MD5STEP(F3, d, a, b, c, in[12] + 0xe6db99e5, 11);
  87187. MD5STEP(F3, c, d, a, b, in[15] + 0x1fa27cf8, 16);
  87188. MD5STEP(F3, b, c, d, a, in[2] + 0xc4ac5665, 23);
  87189. MD5STEP(F4, a, b, c, d, in[0] + 0xf4292244, 6);
  87190. MD5STEP(F4, d, a, b, c, in[7] + 0x432aff97, 10);
  87191. MD5STEP(F4, c, d, a, b, in[14] + 0xab9423a7, 15);
  87192. MD5STEP(F4, b, c, d, a, in[5] + 0xfc93a039, 21);
  87193. MD5STEP(F4, a, b, c, d, in[12] + 0x655b59c3, 6);
  87194. MD5STEP(F4, d, a, b, c, in[3] + 0x8f0ccc92, 10);
  87195. MD5STEP(F4, c, d, a, b, in[10] + 0xffeff47d, 15);
  87196. MD5STEP(F4, b, c, d, a, in[1] + 0x85845dd1, 21);
  87197. MD5STEP(F4, a, b, c, d, in[8] + 0x6fa87e4f, 6);
  87198. MD5STEP(F4, d, a, b, c, in[15] + 0xfe2ce6e0, 10);
  87199. MD5STEP(F4, c, d, a, b, in[6] + 0xa3014314, 15);
  87200. MD5STEP(F4, b, c, d, a, in[13] + 0x4e0811a1, 21);
  87201. MD5STEP(F4, a, b, c, d, in[4] + 0xf7537e82, 6);
  87202. MD5STEP(F4, d, a, b, c, in[11] + 0xbd3af235, 10);
  87203. MD5STEP(F4, c, d, a, b, in[2] + 0x2ad7d2bb, 15);
  87204. MD5STEP(F4, b, c, d, a, in[9] + 0xeb86d391, 21);
  87205. buf[0] += a;
  87206. buf[1] += b;
  87207. buf[2] += c;
  87208. buf[3] += d;
  87209. }
  87210. #if WORDS_BIGENDIAN
  87211. //@@@@@@ OPT: use bswap/intrinsics
  87212. static void byteSwap(FLAC__uint32 *buf, unsigned words)
  87213. {
  87214. register FLAC__uint32 x;
  87215. do {
  87216. x = *buf;
  87217. x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff);
  87218. *buf++ = (x >> 16) | (x << 16);
  87219. } while (--words);
  87220. }
  87221. static void byteSwapX16(FLAC__uint32 *buf)
  87222. {
  87223. register FLAC__uint32 x;
  87224. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  87225. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  87226. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  87227. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  87228. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  87229. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  87230. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  87231. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  87232. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  87233. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  87234. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  87235. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  87236. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  87237. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  87238. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  87239. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf = (x >> 16) | (x << 16);
  87240. }
  87241. #else
  87242. #define byteSwap(buf, words)
  87243. #define byteSwapX16(buf)
  87244. #endif
  87245. static void FLAC__MD5Update(FLAC__MD5Context *ctx, FLAC__byte const *buf, unsigned len)
  87246. {
  87247. FLAC__uint32 t;
  87248. t = ctx->bytes[0];
  87249. if ((ctx->bytes[0] = t + len) < t)
  87250. ctx->bytes[1]++; /* Carry from low to high */
  87251. t = 64 - (t & 0x3f); /* Space available in ctx->in (at least 1) */
  87252. if (t > len) {
  87253. memcpy((FLAC__byte *)ctx->in + 64 - t, buf, len);
  87254. return;
  87255. }
  87256. memcpy((FLAC__byte *)ctx->in + 64 - t, buf, t);
  87257. byteSwapX16(ctx->in);
  87258. FLAC__MD5Transform(ctx->buf, ctx->in);
  87259. buf += t;
  87260. len -= t;
  87261. while (len >= 64) {
  87262. memcpy(ctx->in, buf, 64);
  87263. byteSwapX16(ctx->in);
  87264. FLAC__MD5Transform(ctx->buf, ctx->in);
  87265. buf += 64;
  87266. len -= 64;
  87267. }
  87268. memcpy(ctx->in, buf, len);
  87269. }
  87270. void FLAC__MD5Init(FLAC__MD5Context *ctx)
  87271. {
  87272. ctx->buf[0] = 0x67452301;
  87273. ctx->buf[1] = 0xefcdab89;
  87274. ctx->buf[2] = 0x98badcfe;
  87275. ctx->buf[3] = 0x10325476;
  87276. ctx->bytes[0] = 0;
  87277. ctx->bytes[1] = 0;
  87278. ctx->internal_buf = 0;
  87279. ctx->capacity = 0;
  87280. }
  87281. void FLAC__MD5Final(FLAC__byte digest[16], FLAC__MD5Context *ctx)
  87282. {
  87283. int count = ctx->bytes[0] & 0x3f; /* Number of bytes in ctx->in */
  87284. FLAC__byte *p = (FLAC__byte *)ctx->in + count;
  87285. *p++ = 0x80;
  87286. count = 56 - 1 - count;
  87287. if (count < 0) { /* Padding forces an extra block */
  87288. memset(p, 0, count + 8);
  87289. byteSwapX16(ctx->in);
  87290. FLAC__MD5Transform(ctx->buf, ctx->in);
  87291. p = (FLAC__byte *)ctx->in;
  87292. count = 56;
  87293. }
  87294. memset(p, 0, count);
  87295. byteSwap(ctx->in, 14);
  87296. ctx->in[14] = ctx->bytes[0] << 3;
  87297. ctx->in[15] = ctx->bytes[1] << 3 | ctx->bytes[0] >> 29;
  87298. FLAC__MD5Transform(ctx->buf, ctx->in);
  87299. byteSwap(ctx->buf, 4);
  87300. memcpy(digest, ctx->buf, 16);
  87301. memset(ctx, 0, sizeof(ctx)); /* In case it's sensitive */
  87302. if(0 != ctx->internal_buf) {
  87303. free(ctx->internal_buf);
  87304. ctx->internal_buf = 0;
  87305. ctx->capacity = 0;
  87306. }
  87307. }
  87308. static void format_input_(FLAC__byte *buf, const FLAC__int32 * const signal[], unsigned channels, unsigned samples, unsigned bytes_per_sample)
  87309. {
  87310. unsigned channel, sample;
  87311. register FLAC__int32 a_word;
  87312. register FLAC__byte *buf_ = buf;
  87313. #if WORDS_BIGENDIAN
  87314. #else
  87315. if(channels == 2 && bytes_per_sample == 2) {
  87316. FLAC__int16 *buf1_ = ((FLAC__int16*)buf_) + 1;
  87317. memcpy(buf_, signal[0], sizeof(FLAC__int32) * samples);
  87318. for(sample = 0; sample < samples; sample++, buf1_+=2)
  87319. *buf1_ = (FLAC__int16)signal[1][sample];
  87320. }
  87321. else if(channels == 1 && bytes_per_sample == 2) {
  87322. FLAC__int16 *buf1_ = (FLAC__int16*)buf_;
  87323. for(sample = 0; sample < samples; sample++)
  87324. *buf1_++ = (FLAC__int16)signal[0][sample];
  87325. }
  87326. else
  87327. #endif
  87328. if(bytes_per_sample == 2) {
  87329. if(channels == 2) {
  87330. for(sample = 0; sample < samples; sample++) {
  87331. a_word = signal[0][sample];
  87332. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  87333. *buf_++ = (FLAC__byte)a_word;
  87334. a_word = signal[1][sample];
  87335. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  87336. *buf_++ = (FLAC__byte)a_word;
  87337. }
  87338. }
  87339. else if(channels == 1) {
  87340. for(sample = 0; sample < samples; sample++) {
  87341. a_word = signal[0][sample];
  87342. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  87343. *buf_++ = (FLAC__byte)a_word;
  87344. }
  87345. }
  87346. else {
  87347. for(sample = 0; sample < samples; sample++) {
  87348. for(channel = 0; channel < channels; channel++) {
  87349. a_word = signal[channel][sample];
  87350. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  87351. *buf_++ = (FLAC__byte)a_word;
  87352. }
  87353. }
  87354. }
  87355. }
  87356. else if(bytes_per_sample == 3) {
  87357. if(channels == 2) {
  87358. for(sample = 0; sample < samples; sample++) {
  87359. a_word = signal[0][sample];
  87360. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  87361. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  87362. *buf_++ = (FLAC__byte)a_word;
  87363. a_word = signal[1][sample];
  87364. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  87365. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  87366. *buf_++ = (FLAC__byte)a_word;
  87367. }
  87368. }
  87369. else if(channels == 1) {
  87370. for(sample = 0; sample < samples; sample++) {
  87371. a_word = signal[0][sample];
  87372. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  87373. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  87374. *buf_++ = (FLAC__byte)a_word;
  87375. }
  87376. }
  87377. else {
  87378. for(sample = 0; sample < samples; sample++) {
  87379. for(channel = 0; channel < channels; channel++) {
  87380. a_word = signal[channel][sample];
  87381. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  87382. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  87383. *buf_++ = (FLAC__byte)a_word;
  87384. }
  87385. }
  87386. }
  87387. }
  87388. else if(bytes_per_sample == 1) {
  87389. if(channels == 2) {
  87390. for(sample = 0; sample < samples; sample++) {
  87391. a_word = signal[0][sample];
  87392. *buf_++ = (FLAC__byte)a_word;
  87393. a_word = signal[1][sample];
  87394. *buf_++ = (FLAC__byte)a_word;
  87395. }
  87396. }
  87397. else if(channels == 1) {
  87398. for(sample = 0; sample < samples; sample++) {
  87399. a_word = signal[0][sample];
  87400. *buf_++ = (FLAC__byte)a_word;
  87401. }
  87402. }
  87403. else {
  87404. for(sample = 0; sample < samples; sample++) {
  87405. for(channel = 0; channel < channels; channel++) {
  87406. a_word = signal[channel][sample];
  87407. *buf_++ = (FLAC__byte)a_word;
  87408. }
  87409. }
  87410. }
  87411. }
  87412. else { /* bytes_per_sample == 4, maybe optimize more later */
  87413. for(sample = 0; sample < samples; sample++) {
  87414. for(channel = 0; channel < channels; channel++) {
  87415. a_word = signal[channel][sample];
  87416. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  87417. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  87418. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  87419. *buf_++ = (FLAC__byte)a_word;
  87420. }
  87421. }
  87422. }
  87423. }
  87424. FLAC__bool FLAC__MD5Accumulate(FLAC__MD5Context *ctx, const FLAC__int32 * const signal[], unsigned channels, unsigned samples, unsigned bytes_per_sample)
  87425. {
  87426. const size_t bytes_needed = (size_t)channels * (size_t)samples * (size_t)bytes_per_sample;
  87427. if((size_t)channels > SIZE_MAX / (size_t)bytes_per_sample)
  87428. return false;
  87429. if((size_t)channels * (size_t)bytes_per_sample > SIZE_MAX / (size_t)samples)
  87430. return false;
  87431. if(ctx->capacity < bytes_needed) {
  87432. FLAC__byte *tmp = (FLAC__byte*)realloc(ctx->internal_buf, bytes_needed);
  87433. if(0 == tmp) {
  87434. free(ctx->internal_buf);
  87435. if(0 == (ctx->internal_buf = (FLAC__byte*)safe_malloc_(bytes_needed)))
  87436. return false;
  87437. }
  87438. ctx->internal_buf = tmp;
  87439. ctx->capacity = bytes_needed;
  87440. }
  87441. format_input_(ctx->internal_buf, signal, channels, samples, bytes_per_sample);
  87442. FLAC__MD5Update(ctx, ctx->internal_buf, bytes_needed);
  87443. return true;
  87444. }
  87445. #endif
  87446. /********* End of inlined file: md5.c *********/
  87447. /********* Start of inlined file: memory.c *********/
  87448. /********* Start of inlined file: juce_FlacHeader.h *********/
  87449. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  87450. // tasks..
  87451. #define VERSION "1.2.1"
  87452. #define FLAC__NO_DLL 1
  87453. #if JUCE_MSVC
  87454. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  87455. #endif
  87456. #if JUCE_MAC
  87457. #define FLAC__SYS_DARWIN 1
  87458. #endif
  87459. /********* End of inlined file: juce_FlacHeader.h *********/
  87460. #if JUCE_USE_FLAC
  87461. #if HAVE_CONFIG_H
  87462. # include <config.h>
  87463. #endif
  87464. /********* Start of inlined file: memory.h *********/
  87465. #ifndef FLAC__PRIVATE__MEMORY_H
  87466. #define FLAC__PRIVATE__MEMORY_H
  87467. #ifdef HAVE_CONFIG_H
  87468. #include <config.h>
  87469. #endif
  87470. #include <stdlib.h> /* for size_t */
  87471. void *FLAC__memory_alloc_aligned(size_t bytes, void **aligned_address);
  87472. FLAC__bool FLAC__memory_alloc_aligned_int32_array(unsigned elements, FLAC__int32 **unaligned_pointer, FLAC__int32 **aligned_pointer);
  87473. FLAC__bool FLAC__memory_alloc_aligned_uint32_array(unsigned elements, FLAC__uint32 **unaligned_pointer, FLAC__uint32 **aligned_pointer);
  87474. FLAC__bool FLAC__memory_alloc_aligned_uint64_array(unsigned elements, FLAC__uint64 **unaligned_pointer, FLAC__uint64 **aligned_pointer);
  87475. FLAC__bool FLAC__memory_alloc_aligned_unsigned_array(unsigned elements, unsigned **unaligned_pointer, unsigned **aligned_pointer);
  87476. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  87477. FLAC__bool FLAC__memory_alloc_aligned_real_array(unsigned elements, FLAC__real **unaligned_pointer, FLAC__real **aligned_pointer);
  87478. #endif
  87479. #endif
  87480. /********* End of inlined file: memory.h *********/
  87481. void *FLAC__memory_alloc_aligned(size_t bytes, void **aligned_address)
  87482. {
  87483. void *x;
  87484. FLAC__ASSERT(0 != aligned_address);
  87485. #ifdef FLAC__ALIGN_MALLOC_DATA
  87486. x = safe_malloc_add_2op_(bytes, /*+*/31);
  87487. #ifdef SIZEOF_VOIDP
  87488. #if SIZEOF_VOIDP == 4
  87489. *aligned_address = (void*)(((unsigned)x + 31) & -32);
  87490. #elif SIZEOF_VOIDP == 8
  87491. *aligned_address = (void*)(((FLAC__uint64)x + 31) & (FLAC__uint64)(-((FLAC__int64)32)));
  87492. #else
  87493. # error Unsupported sizeof(void*)
  87494. #endif
  87495. #else
  87496. if(sizeof(void*) == sizeof(unsigned))
  87497. *aligned_address = (void*)(((unsigned)x + 31) & -32);
  87498. else if(sizeof(void*) == sizeof(FLAC__uint64))
  87499. *aligned_address = (void*)(((FLAC__uint64)x + 31) & (FLAC__uint64)(-((FLAC__int64)32)));
  87500. else
  87501. return 0;
  87502. #endif
  87503. #else
  87504. x = safe_malloc_(bytes);
  87505. *aligned_address = x;
  87506. #endif
  87507. return x;
  87508. }
  87509. FLAC__bool FLAC__memory_alloc_aligned_int32_array(unsigned elements, FLAC__int32 **unaligned_pointer, FLAC__int32 **aligned_pointer)
  87510. {
  87511. FLAC__int32 *pu; /* unaligned pointer */
  87512. union { /* union needed to comply with C99 pointer aliasing rules */
  87513. FLAC__int32 *pa; /* aligned pointer */
  87514. void *pv; /* aligned pointer alias */
  87515. } u;
  87516. FLAC__ASSERT(elements > 0);
  87517. FLAC__ASSERT(0 != unaligned_pointer);
  87518. FLAC__ASSERT(0 != aligned_pointer);
  87519. FLAC__ASSERT(unaligned_pointer != aligned_pointer);
  87520. pu = (FLAC__int32*)FLAC__memory_alloc_aligned(sizeof(*pu) * (size_t)elements, &u.pv);
  87521. if(0 == pu) {
  87522. return false;
  87523. }
  87524. else {
  87525. if(*unaligned_pointer != 0)
  87526. free(*unaligned_pointer);
  87527. *unaligned_pointer = pu;
  87528. *aligned_pointer = u.pa;
  87529. return true;
  87530. }
  87531. }
  87532. FLAC__bool FLAC__memory_alloc_aligned_uint32_array(unsigned elements, FLAC__uint32 **unaligned_pointer, FLAC__uint32 **aligned_pointer)
  87533. {
  87534. FLAC__uint32 *pu; /* unaligned pointer */
  87535. union { /* union needed to comply with C99 pointer aliasing rules */
  87536. FLAC__uint32 *pa; /* aligned pointer */
  87537. void *pv; /* aligned pointer alias */
  87538. } u;
  87539. FLAC__ASSERT(elements > 0);
  87540. FLAC__ASSERT(0 != unaligned_pointer);
  87541. FLAC__ASSERT(0 != aligned_pointer);
  87542. FLAC__ASSERT(unaligned_pointer != aligned_pointer);
  87543. pu = (FLAC__uint32*)FLAC__memory_alloc_aligned(sizeof(*pu) * elements, &u.pv);
  87544. if(0 == pu) {
  87545. return false;
  87546. }
  87547. else {
  87548. if(*unaligned_pointer != 0)
  87549. free(*unaligned_pointer);
  87550. *unaligned_pointer = pu;
  87551. *aligned_pointer = u.pa;
  87552. return true;
  87553. }
  87554. }
  87555. FLAC__bool FLAC__memory_alloc_aligned_uint64_array(unsigned elements, FLAC__uint64 **unaligned_pointer, FLAC__uint64 **aligned_pointer)
  87556. {
  87557. FLAC__uint64 *pu; /* unaligned pointer */
  87558. union { /* union needed to comply with C99 pointer aliasing rules */
  87559. FLAC__uint64 *pa; /* aligned pointer */
  87560. void *pv; /* aligned pointer alias */
  87561. } u;
  87562. FLAC__ASSERT(elements > 0);
  87563. FLAC__ASSERT(0 != unaligned_pointer);
  87564. FLAC__ASSERT(0 != aligned_pointer);
  87565. FLAC__ASSERT(unaligned_pointer != aligned_pointer);
  87566. pu = (FLAC__uint64*)FLAC__memory_alloc_aligned(sizeof(*pu) * elements, &u.pv);
  87567. if(0 == pu) {
  87568. return false;
  87569. }
  87570. else {
  87571. if(*unaligned_pointer != 0)
  87572. free(*unaligned_pointer);
  87573. *unaligned_pointer = pu;
  87574. *aligned_pointer = u.pa;
  87575. return true;
  87576. }
  87577. }
  87578. FLAC__bool FLAC__memory_alloc_aligned_unsigned_array(unsigned elements, unsigned **unaligned_pointer, unsigned **aligned_pointer)
  87579. {
  87580. unsigned *pu; /* unaligned pointer */
  87581. union { /* union needed to comply with C99 pointer aliasing rules */
  87582. unsigned *pa; /* aligned pointer */
  87583. void *pv; /* aligned pointer alias */
  87584. } u;
  87585. FLAC__ASSERT(elements > 0);
  87586. FLAC__ASSERT(0 != unaligned_pointer);
  87587. FLAC__ASSERT(0 != aligned_pointer);
  87588. FLAC__ASSERT(unaligned_pointer != aligned_pointer);
  87589. pu = (unsigned*)FLAC__memory_alloc_aligned(sizeof(*pu) * elements, &u.pv);
  87590. if(0 == pu) {
  87591. return false;
  87592. }
  87593. else {
  87594. if(*unaligned_pointer != 0)
  87595. free(*unaligned_pointer);
  87596. *unaligned_pointer = pu;
  87597. *aligned_pointer = u.pa;
  87598. return true;
  87599. }
  87600. }
  87601. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  87602. FLAC__bool FLAC__memory_alloc_aligned_real_array(unsigned elements, FLAC__real **unaligned_pointer, FLAC__real **aligned_pointer)
  87603. {
  87604. FLAC__real *pu; /* unaligned pointer */
  87605. union { /* union needed to comply with C99 pointer aliasing rules */
  87606. FLAC__real *pa; /* aligned pointer */
  87607. void *pv; /* aligned pointer alias */
  87608. } u;
  87609. FLAC__ASSERT(elements > 0);
  87610. FLAC__ASSERT(0 != unaligned_pointer);
  87611. FLAC__ASSERT(0 != aligned_pointer);
  87612. FLAC__ASSERT(unaligned_pointer != aligned_pointer);
  87613. pu = (FLAC__real*)FLAC__memory_alloc_aligned(sizeof(*pu) * elements, &u.pv);
  87614. if(0 == pu) {
  87615. return false;
  87616. }
  87617. else {
  87618. if(*unaligned_pointer != 0)
  87619. free(*unaligned_pointer);
  87620. *unaligned_pointer = pu;
  87621. *aligned_pointer = u.pa;
  87622. return true;
  87623. }
  87624. }
  87625. #endif
  87626. #endif
  87627. /********* End of inlined file: memory.c *********/
  87628. /********* Start of inlined file: stream_decoder.c *********/
  87629. /********* Start of inlined file: juce_FlacHeader.h *********/
  87630. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  87631. // tasks..
  87632. #define VERSION "1.2.1"
  87633. #define FLAC__NO_DLL 1
  87634. #if JUCE_MSVC
  87635. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  87636. #endif
  87637. #if JUCE_MAC
  87638. #define FLAC__SYS_DARWIN 1
  87639. #endif
  87640. /********* End of inlined file: juce_FlacHeader.h *********/
  87641. #if JUCE_USE_FLAC
  87642. #if HAVE_CONFIG_H
  87643. # include <config.h>
  87644. #endif
  87645. #if defined _MSC_VER || defined __MINGW32__
  87646. #include <io.h> /* for _setmode() */
  87647. #include <fcntl.h> /* for _O_BINARY */
  87648. #endif
  87649. #if defined __CYGWIN__ || defined __EMX__
  87650. #include <io.h> /* for setmode(), O_BINARY */
  87651. #include <fcntl.h> /* for _O_BINARY */
  87652. #endif
  87653. #include <stdio.h>
  87654. #include <stdlib.h> /* for malloc() */
  87655. #include <string.h> /* for memset/memcpy() */
  87656. #include <sys/stat.h> /* for stat() */
  87657. #include <sys/types.h> /* for off_t */
  87658. #if defined _MSC_VER || defined __BORLANDC__ || defined __MINGW32__
  87659. #if _MSC_VER <= 1600 || defined __BORLANDC__ /* @@@ [2G limit] */
  87660. #define fseeko fseek
  87661. #define ftello ftell
  87662. #endif
  87663. #endif
  87664. /********* Start of inlined file: stream_decoder.h *********/
  87665. #ifndef FLAC__PROTECTED__STREAM_DECODER_H
  87666. #define FLAC__PROTECTED__STREAM_DECODER_H
  87667. #if FLAC__HAS_OGG
  87668. #include "include/private/ogg_decoder_aspect.h"
  87669. #endif
  87670. typedef struct FLAC__StreamDecoderProtected {
  87671. FLAC__StreamDecoderState state;
  87672. unsigned channels;
  87673. FLAC__ChannelAssignment channel_assignment;
  87674. unsigned bits_per_sample;
  87675. unsigned sample_rate; /* in Hz */
  87676. unsigned blocksize; /* in samples (per channel) */
  87677. FLAC__bool md5_checking; /* if true, generate MD5 signature of decoded data and compare against signature in the STREAMINFO metadata block */
  87678. #if FLAC__HAS_OGG
  87679. FLAC__OggDecoderAspect ogg_decoder_aspect;
  87680. #endif
  87681. } FLAC__StreamDecoderProtected;
  87682. unsigned FLAC__stream_decoder_get_input_bytes_unconsumed(const FLAC__StreamDecoder *decoder);
  87683. #endif
  87684. /********* End of inlined file: stream_decoder.h *********/
  87685. #ifdef max
  87686. #undef max
  87687. #endif
  87688. #define max(a,b) ((a)>(b)?(a):(b))
  87689. #ifdef _MSC_VER
  87690. #define FLAC__U64L(x) x
  87691. #else
  87692. #define FLAC__U64L(x) x##LLU
  87693. #endif
  87694. FLAC_API int FLAC_API_SUPPORTS_OGG_FLAC =
  87695. #if FLAC__HAS_OGG
  87696. 1
  87697. #else
  87698. 0
  87699. #endif
  87700. ;
  87701. static FLAC__byte ID3V2_TAG_[3] = { 'I', 'D', '3' };
  87702. static void set_defaults_dec(FLAC__StreamDecoder *decoder);
  87703. static FILE *get_binary_stdin_(void);
  87704. static FLAC__bool allocate_output_(FLAC__StreamDecoder *decoder, unsigned size, unsigned channels);
  87705. static FLAC__bool has_id_filtered_(FLAC__StreamDecoder *decoder, FLAC__byte *id);
  87706. static FLAC__bool find_metadata_(FLAC__StreamDecoder *decoder);
  87707. static FLAC__bool read_metadata_(FLAC__StreamDecoder *decoder);
  87708. static FLAC__bool read_metadata_streaminfo_(FLAC__StreamDecoder *decoder, FLAC__bool is_last, unsigned length);
  87709. static FLAC__bool read_metadata_seektable_(FLAC__StreamDecoder *decoder, FLAC__bool is_last, unsigned length);
  87710. static FLAC__bool read_metadata_vorbiscomment_(FLAC__StreamDecoder *decoder, FLAC__StreamMetadata_VorbisComment *obj);
  87711. static FLAC__bool read_metadata_cuesheet_(FLAC__StreamDecoder *decoder, FLAC__StreamMetadata_CueSheet *obj);
  87712. static FLAC__bool read_metadata_picture_(FLAC__StreamDecoder *decoder, FLAC__StreamMetadata_Picture *obj);
  87713. static FLAC__bool skip_id3v2_tag_(FLAC__StreamDecoder *decoder);
  87714. static FLAC__bool frame_sync_(FLAC__StreamDecoder *decoder);
  87715. static FLAC__bool read_frame_(FLAC__StreamDecoder *decoder, FLAC__bool *got_a_frame, FLAC__bool do_full_decode);
  87716. static FLAC__bool read_frame_header_(FLAC__StreamDecoder *decoder);
  87717. static FLAC__bool read_subframe_(FLAC__StreamDecoder *decoder, unsigned channel, unsigned bps, FLAC__bool do_full_decode);
  87718. static FLAC__bool read_subframe_constant_(FLAC__StreamDecoder *decoder, unsigned channel, unsigned bps, FLAC__bool do_full_decode);
  87719. static FLAC__bool read_subframe_fixed_(FLAC__StreamDecoder *decoder, unsigned channel, unsigned bps, const unsigned order, FLAC__bool do_full_decode);
  87720. static FLAC__bool read_subframe_lpc_(FLAC__StreamDecoder *decoder, unsigned channel, unsigned bps, const unsigned order, FLAC__bool do_full_decode);
  87721. static FLAC__bool read_subframe_verbatim_(FLAC__StreamDecoder *decoder, unsigned channel, unsigned bps, FLAC__bool do_full_decode);
  87722. 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);
  87723. static FLAC__bool read_zero_padding_(FLAC__StreamDecoder *decoder);
  87724. static FLAC__bool read_callback_(FLAC__byte buffer[], size_t *bytes, void *client_data);
  87725. #if FLAC__HAS_OGG
  87726. static FLAC__StreamDecoderReadStatus read_callback_ogg_aspect_(const FLAC__StreamDecoder *decoder, FLAC__byte buffer[], size_t *bytes);
  87727. static FLAC__OggDecoderAspectReadStatus read_callback_proxy_(const void *void_decoder, FLAC__byte buffer[], size_t *bytes, void *client_data);
  87728. #endif
  87729. static FLAC__StreamDecoderWriteStatus write_audio_frame_to_client_(FLAC__StreamDecoder *decoder, const FLAC__Frame *frame, const FLAC__int32 * const buffer[]);
  87730. static void send_error_to_client_(const FLAC__StreamDecoder *decoder, FLAC__StreamDecoderErrorStatus status);
  87731. static FLAC__bool seek_to_absolute_sample_(FLAC__StreamDecoder *decoder, FLAC__uint64 stream_length, FLAC__uint64 target_sample);
  87732. #if FLAC__HAS_OGG
  87733. static FLAC__bool seek_to_absolute_sample_ogg_(FLAC__StreamDecoder *decoder, FLAC__uint64 stream_length, FLAC__uint64 target_sample);
  87734. #endif
  87735. static FLAC__StreamDecoderReadStatus file_read_callback_dec (const FLAC__StreamDecoder *decoder, FLAC__byte buffer[], size_t *bytes, void *client_data);
  87736. static FLAC__StreamDecoderSeekStatus file_seek_callback_dec (const FLAC__StreamDecoder *decoder, FLAC__uint64 absolute_byte_offset, void *client_data);
  87737. static FLAC__StreamDecoderTellStatus file_tell_callback_dec (const FLAC__StreamDecoder *decoder, FLAC__uint64 *absolute_byte_offset, void *client_data);
  87738. static FLAC__StreamDecoderLengthStatus file_length_callback_(const FLAC__StreamDecoder *decoder, FLAC__uint64 *stream_length, void *client_data);
  87739. static FLAC__bool file_eof_callback_(const FLAC__StreamDecoder *decoder, void *client_data);
  87740. typedef struct FLAC__StreamDecoderPrivate {
  87741. #if FLAC__HAS_OGG
  87742. FLAC__bool is_ogg;
  87743. #endif
  87744. FLAC__StreamDecoderReadCallback read_callback;
  87745. FLAC__StreamDecoderSeekCallback seek_callback;
  87746. FLAC__StreamDecoderTellCallback tell_callback;
  87747. FLAC__StreamDecoderLengthCallback length_callback;
  87748. FLAC__StreamDecoderEofCallback eof_callback;
  87749. FLAC__StreamDecoderWriteCallback write_callback;
  87750. FLAC__StreamDecoderMetadataCallback metadata_callback;
  87751. FLAC__StreamDecoderErrorCallback error_callback;
  87752. 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[]);
  87753. 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[]);
  87754. 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[]);
  87755. 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[]);
  87756. FLAC__bool (*local_bitreader_read_rice_signed_block)(FLAC__BitReader *br, int* vals, unsigned nvals, unsigned parameter);
  87757. void *client_data;
  87758. FILE *file; /* only used if FLAC__stream_decoder_init_file()/FLAC__stream_decoder_init_file() called, else NULL */
  87759. FLAC__BitReader *input;
  87760. FLAC__int32 *output[FLAC__MAX_CHANNELS];
  87761. FLAC__int32 *residual[FLAC__MAX_CHANNELS]; /* WATCHOUT: these are the aligned pointers; the real pointers that should be free()'d are residual_unaligned[] below */
  87762. FLAC__EntropyCodingMethod_PartitionedRiceContents partitioned_rice_contents[FLAC__MAX_CHANNELS];
  87763. unsigned output_capacity, output_channels;
  87764. FLAC__uint32 fixed_block_size, next_fixed_block_size;
  87765. FLAC__uint64 samples_decoded;
  87766. FLAC__bool has_stream_info, has_seek_table;
  87767. FLAC__StreamMetadata stream_info;
  87768. FLAC__StreamMetadata seek_table;
  87769. FLAC__bool metadata_filter[128]; /* MAGIC number 128 == total number of metadata block types == 1 << 7 */
  87770. FLAC__byte *metadata_filter_ids;
  87771. size_t metadata_filter_ids_count, metadata_filter_ids_capacity; /* units for both are IDs, not bytes */
  87772. FLAC__Frame frame;
  87773. FLAC__bool cached; /* true if there is a byte in lookahead */
  87774. FLAC__CPUInfo cpuinfo;
  87775. FLAC__byte header_warmup[2]; /* contains the sync code and reserved bits */
  87776. FLAC__byte lookahead; /* temp storage when we need to look ahead one byte in the stream */
  87777. FLAC__int32 *residual_unaligned[FLAC__MAX_CHANNELS];
  87778. 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 */
  87779. FLAC__bool internal_reset_hack; /* used only during init() so we can call reset to set up the decoder without rewinding the input */
  87780. FLAC__bool is_seeking;
  87781. FLAC__MD5Context md5context;
  87782. FLAC__byte computed_md5sum[16]; /* this is the sum we computed from the decoded data */
  87783. FLAC__Frame last_frame; /* holds the info of the last frame we seeked to */
  87784. FLAC__uint64 first_frame_offset; /* hint to the seek routine of where in the stream the first audio frame starts */
  87785. FLAC__uint64 target_sample;
  87786. unsigned unparseable_frame_count; /* used to tell whether we're decoding a future version of FLAC or just got a bad sync */
  87787. #if FLAC__HAS_OGG
  87788. FLAC__bool got_a_frame; /* hack needed in Ogg FLAC seek routine to check when process_single() actually writes a frame */
  87789. #endif
  87790. } FLAC__StreamDecoderPrivate;
  87791. FLAC_API const char * const FLAC__StreamDecoderStateString[] = {
  87792. "FLAC__STREAM_DECODER_SEARCH_FOR_METADATA",
  87793. "FLAC__STREAM_DECODER_READ_METADATA",
  87794. "FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC",
  87795. "FLAC__STREAM_DECODER_READ_FRAME",
  87796. "FLAC__STREAM_DECODER_END_OF_STREAM",
  87797. "FLAC__STREAM_DECODER_OGG_ERROR",
  87798. "FLAC__STREAM_DECODER_SEEK_ERROR",
  87799. "FLAC__STREAM_DECODER_ABORTED",
  87800. "FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR",
  87801. "FLAC__STREAM_DECODER_UNINITIALIZED"
  87802. };
  87803. FLAC_API const char * const FLAC__StreamDecoderInitStatusString[] = {
  87804. "FLAC__STREAM_DECODER_INIT_STATUS_OK",
  87805. "FLAC__STREAM_DECODER_INIT_STATUS_UNSUPPORTED_CONTAINER",
  87806. "FLAC__STREAM_DECODER_INIT_STATUS_INVALID_CALLBACKS",
  87807. "FLAC__STREAM_DECODER_INIT_STATUS_MEMORY_ALLOCATION_ERROR",
  87808. "FLAC__STREAM_DECODER_INIT_STATUS_ERROR_OPENING_FILE",
  87809. "FLAC__STREAM_DECODER_INIT_STATUS_ALREADY_INITIALIZED"
  87810. };
  87811. FLAC_API const char * const FLAC__StreamDecoderReadStatusString[] = {
  87812. "FLAC__STREAM_DECODER_READ_STATUS_CONTINUE",
  87813. "FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM",
  87814. "FLAC__STREAM_DECODER_READ_STATUS_ABORT"
  87815. };
  87816. FLAC_API const char * const FLAC__StreamDecoderSeekStatusString[] = {
  87817. "FLAC__STREAM_DECODER_SEEK_STATUS_OK",
  87818. "FLAC__STREAM_DECODER_SEEK_STATUS_ERROR",
  87819. "FLAC__STREAM_DECODER_SEEK_STATUS_UNSUPPORTED"
  87820. };
  87821. FLAC_API const char * const FLAC__StreamDecoderTellStatusString[] = {
  87822. "FLAC__STREAM_DECODER_TELL_STATUS_OK",
  87823. "FLAC__STREAM_DECODER_TELL_STATUS_ERROR",
  87824. "FLAC__STREAM_DECODER_TELL_STATUS_UNSUPPORTED"
  87825. };
  87826. FLAC_API const char * const FLAC__StreamDecoderLengthStatusString[] = {
  87827. "FLAC__STREAM_DECODER_LENGTH_STATUS_OK",
  87828. "FLAC__STREAM_DECODER_LENGTH_STATUS_ERROR",
  87829. "FLAC__STREAM_DECODER_LENGTH_STATUS_UNSUPPORTED"
  87830. };
  87831. FLAC_API const char * const FLAC__StreamDecoderWriteStatusString[] = {
  87832. "FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE",
  87833. "FLAC__STREAM_DECODER_WRITE_STATUS_ABORT"
  87834. };
  87835. FLAC_API const char * const FLAC__StreamDecoderErrorStatusString[] = {
  87836. "FLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC",
  87837. "FLAC__STREAM_DECODER_ERROR_STATUS_BAD_HEADER",
  87838. "FLAC__STREAM_DECODER_ERROR_STATUS_FRAME_CRC_MISMATCH",
  87839. "FLAC__STREAM_DECODER_ERROR_STATUS_UNPARSEABLE_STREAM"
  87840. };
  87841. FLAC_API FLAC__StreamDecoder *FLAC__stream_decoder_new(void)
  87842. {
  87843. FLAC__StreamDecoder *decoder;
  87844. unsigned i;
  87845. FLAC__ASSERT(sizeof(int) >= 4); /* we want to die right away if this is not true */
  87846. decoder = (FLAC__StreamDecoder*)calloc(1, sizeof(FLAC__StreamDecoder));
  87847. if(decoder == 0) {
  87848. return 0;
  87849. }
  87850. decoder->protected_ = (FLAC__StreamDecoderProtected*)calloc(1, sizeof(FLAC__StreamDecoderProtected));
  87851. if(decoder->protected_ == 0) {
  87852. free(decoder);
  87853. return 0;
  87854. }
  87855. decoder->private_ = (FLAC__StreamDecoderPrivate*)calloc(1, sizeof(FLAC__StreamDecoderPrivate));
  87856. if(decoder->private_ == 0) {
  87857. free(decoder->protected_);
  87858. free(decoder);
  87859. return 0;
  87860. }
  87861. decoder->private_->input = FLAC__bitreader_new();
  87862. if(decoder->private_->input == 0) {
  87863. free(decoder->private_);
  87864. free(decoder->protected_);
  87865. free(decoder);
  87866. return 0;
  87867. }
  87868. decoder->private_->metadata_filter_ids_capacity = 16;
  87869. if(0 == (decoder->private_->metadata_filter_ids = (FLAC__byte*)malloc((FLAC__STREAM_METADATA_APPLICATION_ID_LEN/8) * decoder->private_->metadata_filter_ids_capacity))) {
  87870. FLAC__bitreader_delete(decoder->private_->input);
  87871. free(decoder->private_);
  87872. free(decoder->protected_);
  87873. free(decoder);
  87874. return 0;
  87875. }
  87876. for(i = 0; i < FLAC__MAX_CHANNELS; i++) {
  87877. decoder->private_->output[i] = 0;
  87878. decoder->private_->residual_unaligned[i] = decoder->private_->residual[i] = 0;
  87879. }
  87880. decoder->private_->output_capacity = 0;
  87881. decoder->private_->output_channels = 0;
  87882. decoder->private_->has_seek_table = false;
  87883. for(i = 0; i < FLAC__MAX_CHANNELS; i++)
  87884. FLAC__format_entropy_coding_method_partitioned_rice_contents_init(&decoder->private_->partitioned_rice_contents[i]);
  87885. decoder->private_->file = 0;
  87886. set_defaults_dec(decoder);
  87887. decoder->protected_->state = FLAC__STREAM_DECODER_UNINITIALIZED;
  87888. return decoder;
  87889. }
  87890. FLAC_API void FLAC__stream_decoder_delete(FLAC__StreamDecoder *decoder)
  87891. {
  87892. unsigned i;
  87893. FLAC__ASSERT(0 != decoder);
  87894. FLAC__ASSERT(0 != decoder->protected_);
  87895. FLAC__ASSERT(0 != decoder->private_);
  87896. FLAC__ASSERT(0 != decoder->private_->input);
  87897. (void)FLAC__stream_decoder_finish(decoder);
  87898. if(0 != decoder->private_->metadata_filter_ids)
  87899. free(decoder->private_->metadata_filter_ids);
  87900. FLAC__bitreader_delete(decoder->private_->input);
  87901. for(i = 0; i < FLAC__MAX_CHANNELS; i++)
  87902. FLAC__format_entropy_coding_method_partitioned_rice_contents_clear(&decoder->private_->partitioned_rice_contents[i]);
  87903. free(decoder->private_);
  87904. free(decoder->protected_);
  87905. free(decoder);
  87906. }
  87907. static FLAC__StreamDecoderInitStatus init_stream_internal_dec(
  87908. FLAC__StreamDecoder *decoder,
  87909. FLAC__StreamDecoderReadCallback read_callback,
  87910. FLAC__StreamDecoderSeekCallback seek_callback,
  87911. FLAC__StreamDecoderTellCallback tell_callback,
  87912. FLAC__StreamDecoderLengthCallback length_callback,
  87913. FLAC__StreamDecoderEofCallback eof_callback,
  87914. FLAC__StreamDecoderWriteCallback write_callback,
  87915. FLAC__StreamDecoderMetadataCallback metadata_callback,
  87916. FLAC__StreamDecoderErrorCallback error_callback,
  87917. void *client_data,
  87918. FLAC__bool is_ogg
  87919. )
  87920. {
  87921. FLAC__ASSERT(0 != decoder);
  87922. if(decoder->protected_->state != FLAC__STREAM_DECODER_UNINITIALIZED)
  87923. return FLAC__STREAM_DECODER_INIT_STATUS_ALREADY_INITIALIZED;
  87924. #if !FLAC__HAS_OGG
  87925. if(is_ogg)
  87926. return FLAC__STREAM_DECODER_INIT_STATUS_UNSUPPORTED_CONTAINER;
  87927. #endif
  87928. if(
  87929. 0 == read_callback ||
  87930. 0 == write_callback ||
  87931. 0 == error_callback ||
  87932. (seek_callback && (0 == tell_callback || 0 == length_callback || 0 == eof_callback))
  87933. )
  87934. return FLAC__STREAM_DECODER_INIT_STATUS_INVALID_CALLBACKS;
  87935. #if FLAC__HAS_OGG
  87936. decoder->private_->is_ogg = is_ogg;
  87937. if(is_ogg && !FLAC__ogg_decoder_aspect_init(&decoder->protected_->ogg_decoder_aspect))
  87938. return decoder->protected_->state = FLAC__STREAM_DECODER_OGG_ERROR;
  87939. #endif
  87940. FLAC__cpu_info(&decoder->private_->cpuinfo);
  87941. decoder->private_->local_lpc_restore_signal = FLAC__lpc_restore_signal;
  87942. decoder->private_->local_lpc_restore_signal_64bit = FLAC__lpc_restore_signal_wide;
  87943. decoder->private_->local_lpc_restore_signal_16bit = FLAC__lpc_restore_signal;
  87944. decoder->private_->local_lpc_restore_signal_16bit_order8 = FLAC__lpc_restore_signal;
  87945. decoder->private_->local_bitreader_read_rice_signed_block = FLAC__bitreader_read_rice_signed_block;
  87946. #ifndef FLAC__NO_ASM
  87947. if(decoder->private_->cpuinfo.use_asm) {
  87948. #ifdef FLAC__CPU_IA32
  87949. FLAC__ASSERT(decoder->private_->cpuinfo.type == FLAC__CPUINFO_TYPE_IA32);
  87950. #ifdef FLAC__HAS_NASM
  87951. #if 1 /*@@@@@@ OPT: not clearly faster, needs more testing */
  87952. if(decoder->private_->cpuinfo.data.ia32.bswap)
  87953. decoder->private_->local_bitreader_read_rice_signed_block = FLAC__bitreader_read_rice_signed_block_asm_ia32_bswap;
  87954. #endif
  87955. if(decoder->private_->cpuinfo.data.ia32.mmx) {
  87956. decoder->private_->local_lpc_restore_signal = FLAC__lpc_restore_signal_asm_ia32;
  87957. decoder->private_->local_lpc_restore_signal_16bit = FLAC__lpc_restore_signal_asm_ia32_mmx;
  87958. decoder->private_->local_lpc_restore_signal_16bit_order8 = FLAC__lpc_restore_signal_asm_ia32_mmx;
  87959. }
  87960. else {
  87961. decoder->private_->local_lpc_restore_signal = FLAC__lpc_restore_signal_asm_ia32;
  87962. decoder->private_->local_lpc_restore_signal_16bit = FLAC__lpc_restore_signal_asm_ia32;
  87963. decoder->private_->local_lpc_restore_signal_16bit_order8 = FLAC__lpc_restore_signal_asm_ia32;
  87964. }
  87965. #endif
  87966. #elif defined FLAC__CPU_PPC
  87967. FLAC__ASSERT(decoder->private_->cpuinfo.type == FLAC__CPUINFO_TYPE_PPC);
  87968. if(decoder->private_->cpuinfo.data.ppc.altivec) {
  87969. decoder->private_->local_lpc_restore_signal_16bit = FLAC__lpc_restore_signal_asm_ppc_altivec_16;
  87970. decoder->private_->local_lpc_restore_signal_16bit_order8 = FLAC__lpc_restore_signal_asm_ppc_altivec_16_order8;
  87971. }
  87972. #endif
  87973. }
  87974. #endif
  87975. if(!FLAC__bitreader_init(decoder->private_->input, decoder->private_->cpuinfo, read_callback_, decoder)) {
  87976. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  87977. return FLAC__STREAM_DECODER_INIT_STATUS_MEMORY_ALLOCATION_ERROR;
  87978. }
  87979. decoder->private_->read_callback = read_callback;
  87980. decoder->private_->seek_callback = seek_callback;
  87981. decoder->private_->tell_callback = tell_callback;
  87982. decoder->private_->length_callback = length_callback;
  87983. decoder->private_->eof_callback = eof_callback;
  87984. decoder->private_->write_callback = write_callback;
  87985. decoder->private_->metadata_callback = metadata_callback;
  87986. decoder->private_->error_callback = error_callback;
  87987. decoder->private_->client_data = client_data;
  87988. decoder->private_->fixed_block_size = decoder->private_->next_fixed_block_size = 0;
  87989. decoder->private_->samples_decoded = 0;
  87990. decoder->private_->has_stream_info = false;
  87991. decoder->private_->cached = false;
  87992. decoder->private_->do_md5_checking = decoder->protected_->md5_checking;
  87993. decoder->private_->is_seeking = false;
  87994. decoder->private_->internal_reset_hack = true; /* so the following reset does not try to rewind the input */
  87995. if(!FLAC__stream_decoder_reset(decoder)) {
  87996. return FLAC__STREAM_DECODER_INIT_STATUS_MEMORY_ALLOCATION_ERROR;
  87997. }
  87998. return FLAC__STREAM_DECODER_INIT_STATUS_OK;
  87999. }
  88000. FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_stream(
  88001. FLAC__StreamDecoder *decoder,
  88002. FLAC__StreamDecoderReadCallback read_callback,
  88003. FLAC__StreamDecoderSeekCallback seek_callback,
  88004. FLAC__StreamDecoderTellCallback tell_callback,
  88005. FLAC__StreamDecoderLengthCallback length_callback,
  88006. FLAC__StreamDecoderEofCallback eof_callback,
  88007. FLAC__StreamDecoderWriteCallback write_callback,
  88008. FLAC__StreamDecoderMetadataCallback metadata_callback,
  88009. FLAC__StreamDecoderErrorCallback error_callback,
  88010. void *client_data
  88011. )
  88012. {
  88013. return init_stream_internal_dec(
  88014. decoder,
  88015. read_callback,
  88016. seek_callback,
  88017. tell_callback,
  88018. length_callback,
  88019. eof_callback,
  88020. write_callback,
  88021. metadata_callback,
  88022. error_callback,
  88023. client_data,
  88024. false
  88025. );
  88026. }
  88027. FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_ogg_stream(
  88028. FLAC__StreamDecoder *decoder,
  88029. FLAC__StreamDecoderReadCallback read_callback,
  88030. FLAC__StreamDecoderSeekCallback seek_callback,
  88031. FLAC__StreamDecoderTellCallback tell_callback,
  88032. FLAC__StreamDecoderLengthCallback length_callback,
  88033. FLAC__StreamDecoderEofCallback eof_callback,
  88034. FLAC__StreamDecoderWriteCallback write_callback,
  88035. FLAC__StreamDecoderMetadataCallback metadata_callback,
  88036. FLAC__StreamDecoderErrorCallback error_callback,
  88037. void *client_data
  88038. )
  88039. {
  88040. return init_stream_internal_dec(
  88041. decoder,
  88042. read_callback,
  88043. seek_callback,
  88044. tell_callback,
  88045. length_callback,
  88046. eof_callback,
  88047. write_callback,
  88048. metadata_callback,
  88049. error_callback,
  88050. client_data,
  88051. true
  88052. );
  88053. }
  88054. static FLAC__StreamDecoderInitStatus init_FILE_internal_(
  88055. FLAC__StreamDecoder *decoder,
  88056. FILE *file,
  88057. FLAC__StreamDecoderWriteCallback write_callback,
  88058. FLAC__StreamDecoderMetadataCallback metadata_callback,
  88059. FLAC__StreamDecoderErrorCallback error_callback,
  88060. void *client_data,
  88061. FLAC__bool is_ogg
  88062. )
  88063. {
  88064. FLAC__ASSERT(0 != decoder);
  88065. FLAC__ASSERT(0 != file);
  88066. if(decoder->protected_->state != FLAC__STREAM_DECODER_UNINITIALIZED)
  88067. return (FLAC__StreamDecoderInitStatus) (decoder->protected_->state = (FLAC__StreamDecoderState) FLAC__STREAM_DECODER_INIT_STATUS_ALREADY_INITIALIZED);
  88068. if(0 == write_callback || 0 == error_callback)
  88069. return (FLAC__StreamDecoderInitStatus) (decoder->protected_->state = (FLAC__StreamDecoderState) FLAC__STREAM_DECODER_INIT_STATUS_INVALID_CALLBACKS);
  88070. if(file == stdin)
  88071. file = get_binary_stdin_(); /* just to be safe */
  88072. decoder->private_->file = file;
  88073. return init_stream_internal_dec(
  88074. decoder,
  88075. file_read_callback_dec,
  88076. decoder->private_->file == stdin? 0: file_seek_callback_dec,
  88077. decoder->private_->file == stdin? 0: file_tell_callback_dec,
  88078. decoder->private_->file == stdin? 0: file_length_callback_,
  88079. file_eof_callback_,
  88080. write_callback,
  88081. metadata_callback,
  88082. error_callback,
  88083. client_data,
  88084. is_ogg
  88085. );
  88086. }
  88087. FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_FILE(
  88088. FLAC__StreamDecoder *decoder,
  88089. FILE *file,
  88090. FLAC__StreamDecoderWriteCallback write_callback,
  88091. FLAC__StreamDecoderMetadataCallback metadata_callback,
  88092. FLAC__StreamDecoderErrorCallback error_callback,
  88093. void *client_data
  88094. )
  88095. {
  88096. return init_FILE_internal_(decoder, file, write_callback, metadata_callback, error_callback, client_data, /*is_ogg=*/false);
  88097. }
  88098. FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_ogg_FILE(
  88099. FLAC__StreamDecoder *decoder,
  88100. FILE *file,
  88101. FLAC__StreamDecoderWriteCallback write_callback,
  88102. FLAC__StreamDecoderMetadataCallback metadata_callback,
  88103. FLAC__StreamDecoderErrorCallback error_callback,
  88104. void *client_data
  88105. )
  88106. {
  88107. return init_FILE_internal_(decoder, file, write_callback, metadata_callback, error_callback, client_data, /*is_ogg=*/true);
  88108. }
  88109. static FLAC__StreamDecoderInitStatus init_file_internal_(
  88110. FLAC__StreamDecoder *decoder,
  88111. const char *filename,
  88112. FLAC__StreamDecoderWriteCallback write_callback,
  88113. FLAC__StreamDecoderMetadataCallback metadata_callback,
  88114. FLAC__StreamDecoderErrorCallback error_callback,
  88115. void *client_data,
  88116. FLAC__bool is_ogg
  88117. )
  88118. {
  88119. FILE *file;
  88120. FLAC__ASSERT(0 != decoder);
  88121. if(decoder->protected_->state != FLAC__STREAM_DECODER_UNINITIALIZED)
  88122. return (FLAC__StreamDecoderInitStatus) (decoder->protected_->state = (FLAC__StreamDecoderState) FLAC__STREAM_DECODER_INIT_STATUS_ALREADY_INITIALIZED);
  88123. if(0 == write_callback || 0 == error_callback)
  88124. return (FLAC__StreamDecoderInitStatus) (decoder->protected_->state = (FLAC__StreamDecoderState) FLAC__STREAM_DECODER_INIT_STATUS_INVALID_CALLBACKS);
  88125. file = filename? fopen(filename, "rb") : stdin;
  88126. if(0 == file)
  88127. return FLAC__STREAM_DECODER_INIT_STATUS_ERROR_OPENING_FILE;
  88128. return init_FILE_internal_(decoder, file, write_callback, metadata_callback, error_callback, client_data, is_ogg);
  88129. }
  88130. FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_file(
  88131. FLAC__StreamDecoder *decoder,
  88132. const char *filename,
  88133. FLAC__StreamDecoderWriteCallback write_callback,
  88134. FLAC__StreamDecoderMetadataCallback metadata_callback,
  88135. FLAC__StreamDecoderErrorCallback error_callback,
  88136. void *client_data
  88137. )
  88138. {
  88139. return init_file_internal_(decoder, filename, write_callback, metadata_callback, error_callback, client_data, /*is_ogg=*/false);
  88140. }
  88141. FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_ogg_file(
  88142. FLAC__StreamDecoder *decoder,
  88143. const char *filename,
  88144. FLAC__StreamDecoderWriteCallback write_callback,
  88145. FLAC__StreamDecoderMetadataCallback metadata_callback,
  88146. FLAC__StreamDecoderErrorCallback error_callback,
  88147. void *client_data
  88148. )
  88149. {
  88150. return init_file_internal_(decoder, filename, write_callback, metadata_callback, error_callback, client_data, /*is_ogg=*/true);
  88151. }
  88152. FLAC_API FLAC__bool FLAC__stream_decoder_finish(FLAC__StreamDecoder *decoder)
  88153. {
  88154. FLAC__bool md5_failed = false;
  88155. unsigned i;
  88156. FLAC__ASSERT(0 != decoder);
  88157. FLAC__ASSERT(0 != decoder->private_);
  88158. FLAC__ASSERT(0 != decoder->protected_);
  88159. if(decoder->protected_->state == FLAC__STREAM_DECODER_UNINITIALIZED)
  88160. return true;
  88161. FLAC__MD5Final(decoder->private_->computed_md5sum, &decoder->private_->md5context);
  88162. if(decoder->private_->has_seek_table && 0 != decoder->private_->seek_table.data.seek_table.points) {
  88163. free(decoder->private_->seek_table.data.seek_table.points);
  88164. decoder->private_->seek_table.data.seek_table.points = 0;
  88165. decoder->private_->has_seek_table = false;
  88166. }
  88167. FLAC__bitreader_free(decoder->private_->input);
  88168. for(i = 0; i < FLAC__MAX_CHANNELS; i++) {
  88169. if(0 != decoder->private_->output[i]) {
  88170. free(decoder->private_->output[i]-4);
  88171. decoder->private_->output[i] = 0;
  88172. }
  88173. if(0 != decoder->private_->residual_unaligned[i]) {
  88174. free(decoder->private_->residual_unaligned[i]);
  88175. decoder->private_->residual_unaligned[i] = decoder->private_->residual[i] = 0;
  88176. }
  88177. }
  88178. decoder->private_->output_capacity = 0;
  88179. decoder->private_->output_channels = 0;
  88180. #if FLAC__HAS_OGG
  88181. if(decoder->private_->is_ogg)
  88182. FLAC__ogg_decoder_aspect_finish(&decoder->protected_->ogg_decoder_aspect);
  88183. #endif
  88184. if(0 != decoder->private_->file) {
  88185. if(decoder->private_->file != stdin)
  88186. fclose(decoder->private_->file);
  88187. decoder->private_->file = 0;
  88188. }
  88189. if(decoder->private_->do_md5_checking) {
  88190. if(memcmp(decoder->private_->stream_info.data.stream_info.md5sum, decoder->private_->computed_md5sum, 16))
  88191. md5_failed = true;
  88192. }
  88193. decoder->private_->is_seeking = false;
  88194. set_defaults_dec(decoder);
  88195. decoder->protected_->state = FLAC__STREAM_DECODER_UNINITIALIZED;
  88196. return !md5_failed;
  88197. }
  88198. FLAC_API FLAC__bool FLAC__stream_decoder_set_ogg_serial_number(FLAC__StreamDecoder *decoder, long value)
  88199. {
  88200. FLAC__ASSERT(0 != decoder);
  88201. FLAC__ASSERT(0 != decoder->private_);
  88202. FLAC__ASSERT(0 != decoder->protected_);
  88203. if(decoder->protected_->state != FLAC__STREAM_DECODER_UNINITIALIZED)
  88204. return false;
  88205. #if FLAC__HAS_OGG
  88206. FLAC__ogg_decoder_aspect_set_serial_number(&decoder->protected_->ogg_decoder_aspect, value);
  88207. return true;
  88208. #else
  88209. (void)value;
  88210. return false;
  88211. #endif
  88212. }
  88213. FLAC_API FLAC__bool FLAC__stream_decoder_set_md5_checking(FLAC__StreamDecoder *decoder, FLAC__bool value)
  88214. {
  88215. FLAC__ASSERT(0 != decoder);
  88216. FLAC__ASSERT(0 != decoder->protected_);
  88217. if(decoder->protected_->state != FLAC__STREAM_DECODER_UNINITIALIZED)
  88218. return false;
  88219. decoder->protected_->md5_checking = value;
  88220. return true;
  88221. }
  88222. FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_respond(FLAC__StreamDecoder *decoder, FLAC__MetadataType type)
  88223. {
  88224. FLAC__ASSERT(0 != decoder);
  88225. FLAC__ASSERT(0 != decoder->private_);
  88226. FLAC__ASSERT(0 != decoder->protected_);
  88227. FLAC__ASSERT((unsigned)type <= FLAC__MAX_METADATA_TYPE_CODE);
  88228. if((unsigned)type > FLAC__MAX_METADATA_TYPE_CODE)
  88229. return false;
  88230. if(decoder->protected_->state != FLAC__STREAM_DECODER_UNINITIALIZED)
  88231. return false;
  88232. decoder->private_->metadata_filter[type] = true;
  88233. if(type == FLAC__METADATA_TYPE_APPLICATION)
  88234. decoder->private_->metadata_filter_ids_count = 0;
  88235. return true;
  88236. }
  88237. FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_respond_application(FLAC__StreamDecoder *decoder, const FLAC__byte id[4])
  88238. {
  88239. FLAC__ASSERT(0 != decoder);
  88240. FLAC__ASSERT(0 != decoder->private_);
  88241. FLAC__ASSERT(0 != decoder->protected_);
  88242. FLAC__ASSERT(0 != id);
  88243. if(decoder->protected_->state != FLAC__STREAM_DECODER_UNINITIALIZED)
  88244. return false;
  88245. if(decoder->private_->metadata_filter[FLAC__METADATA_TYPE_APPLICATION])
  88246. return true;
  88247. FLAC__ASSERT(0 != decoder->private_->metadata_filter_ids);
  88248. if(decoder->private_->metadata_filter_ids_count == decoder->private_->metadata_filter_ids_capacity) {
  88249. 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))) {
  88250. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  88251. return false;
  88252. }
  88253. decoder->private_->metadata_filter_ids_capacity *= 2;
  88254. }
  88255. 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));
  88256. decoder->private_->metadata_filter_ids_count++;
  88257. return true;
  88258. }
  88259. FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_respond_all(FLAC__StreamDecoder *decoder)
  88260. {
  88261. unsigned i;
  88262. FLAC__ASSERT(0 != decoder);
  88263. FLAC__ASSERT(0 != decoder->private_);
  88264. FLAC__ASSERT(0 != decoder->protected_);
  88265. if(decoder->protected_->state != FLAC__STREAM_DECODER_UNINITIALIZED)
  88266. return false;
  88267. for(i = 0; i < sizeof(decoder->private_->metadata_filter) / sizeof(decoder->private_->metadata_filter[0]); i++)
  88268. decoder->private_->metadata_filter[i] = true;
  88269. decoder->private_->metadata_filter_ids_count = 0;
  88270. return true;
  88271. }
  88272. FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_ignore(FLAC__StreamDecoder *decoder, FLAC__MetadataType type)
  88273. {
  88274. FLAC__ASSERT(0 != decoder);
  88275. FLAC__ASSERT(0 != decoder->private_);
  88276. FLAC__ASSERT(0 != decoder->protected_);
  88277. FLAC__ASSERT((unsigned)type <= FLAC__MAX_METADATA_TYPE_CODE);
  88278. if((unsigned)type > FLAC__MAX_METADATA_TYPE_CODE)
  88279. return false;
  88280. if(decoder->protected_->state != FLAC__STREAM_DECODER_UNINITIALIZED)
  88281. return false;
  88282. decoder->private_->metadata_filter[type] = false;
  88283. if(type == FLAC__METADATA_TYPE_APPLICATION)
  88284. decoder->private_->metadata_filter_ids_count = 0;
  88285. return true;
  88286. }
  88287. FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_ignore_application(FLAC__StreamDecoder *decoder, const FLAC__byte id[4])
  88288. {
  88289. FLAC__ASSERT(0 != decoder);
  88290. FLAC__ASSERT(0 != decoder->private_);
  88291. FLAC__ASSERT(0 != decoder->protected_);
  88292. FLAC__ASSERT(0 != id);
  88293. if(decoder->protected_->state != FLAC__STREAM_DECODER_UNINITIALIZED)
  88294. return false;
  88295. if(!decoder->private_->metadata_filter[FLAC__METADATA_TYPE_APPLICATION])
  88296. return true;
  88297. FLAC__ASSERT(0 != decoder->private_->metadata_filter_ids);
  88298. if(decoder->private_->metadata_filter_ids_count == decoder->private_->metadata_filter_ids_capacity) {
  88299. 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))) {
  88300. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  88301. return false;
  88302. }
  88303. decoder->private_->metadata_filter_ids_capacity *= 2;
  88304. }
  88305. 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));
  88306. decoder->private_->metadata_filter_ids_count++;
  88307. return true;
  88308. }
  88309. FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_ignore_all(FLAC__StreamDecoder *decoder)
  88310. {
  88311. FLAC__ASSERT(0 != decoder);
  88312. FLAC__ASSERT(0 != decoder->private_);
  88313. FLAC__ASSERT(0 != decoder->protected_);
  88314. if(decoder->protected_->state != FLAC__STREAM_DECODER_UNINITIALIZED)
  88315. return false;
  88316. memset(decoder->private_->metadata_filter, 0, sizeof(decoder->private_->metadata_filter));
  88317. decoder->private_->metadata_filter_ids_count = 0;
  88318. return true;
  88319. }
  88320. FLAC_API FLAC__StreamDecoderState FLAC__stream_decoder_get_state(const FLAC__StreamDecoder *decoder)
  88321. {
  88322. FLAC__ASSERT(0 != decoder);
  88323. FLAC__ASSERT(0 != decoder->protected_);
  88324. return decoder->protected_->state;
  88325. }
  88326. FLAC_API const char *FLAC__stream_decoder_get_resolved_state_string(const FLAC__StreamDecoder *decoder)
  88327. {
  88328. return FLAC__StreamDecoderStateString[decoder->protected_->state];
  88329. }
  88330. FLAC_API FLAC__bool FLAC__stream_decoder_get_md5_checking(const FLAC__StreamDecoder *decoder)
  88331. {
  88332. FLAC__ASSERT(0 != decoder);
  88333. FLAC__ASSERT(0 != decoder->protected_);
  88334. return decoder->protected_->md5_checking;
  88335. }
  88336. FLAC_API FLAC__uint64 FLAC__stream_decoder_get_total_samples(const FLAC__StreamDecoder *decoder)
  88337. {
  88338. FLAC__ASSERT(0 != decoder);
  88339. FLAC__ASSERT(0 != decoder->protected_);
  88340. return decoder->private_->has_stream_info? decoder->private_->stream_info.data.stream_info.total_samples : 0;
  88341. }
  88342. FLAC_API unsigned FLAC__stream_decoder_get_channels(const FLAC__StreamDecoder *decoder)
  88343. {
  88344. FLAC__ASSERT(0 != decoder);
  88345. FLAC__ASSERT(0 != decoder->protected_);
  88346. return decoder->protected_->channels;
  88347. }
  88348. FLAC_API FLAC__ChannelAssignment FLAC__stream_decoder_get_channel_assignment(const FLAC__StreamDecoder *decoder)
  88349. {
  88350. FLAC__ASSERT(0 != decoder);
  88351. FLAC__ASSERT(0 != decoder->protected_);
  88352. return decoder->protected_->channel_assignment;
  88353. }
  88354. FLAC_API unsigned FLAC__stream_decoder_get_bits_per_sample(const FLAC__StreamDecoder *decoder)
  88355. {
  88356. FLAC__ASSERT(0 != decoder);
  88357. FLAC__ASSERT(0 != decoder->protected_);
  88358. return decoder->protected_->bits_per_sample;
  88359. }
  88360. FLAC_API unsigned FLAC__stream_decoder_get_sample_rate(const FLAC__StreamDecoder *decoder)
  88361. {
  88362. FLAC__ASSERT(0 != decoder);
  88363. FLAC__ASSERT(0 != decoder->protected_);
  88364. return decoder->protected_->sample_rate;
  88365. }
  88366. FLAC_API unsigned FLAC__stream_decoder_get_blocksize(const FLAC__StreamDecoder *decoder)
  88367. {
  88368. FLAC__ASSERT(0 != decoder);
  88369. FLAC__ASSERT(0 != decoder->protected_);
  88370. return decoder->protected_->blocksize;
  88371. }
  88372. FLAC_API FLAC__bool FLAC__stream_decoder_get_decode_position(const FLAC__StreamDecoder *decoder, FLAC__uint64 *position)
  88373. {
  88374. FLAC__ASSERT(0 != decoder);
  88375. FLAC__ASSERT(0 != decoder->private_);
  88376. FLAC__ASSERT(0 != position);
  88377. #if FLAC__HAS_OGG
  88378. if(decoder->private_->is_ogg)
  88379. return false;
  88380. #endif
  88381. if(0 == decoder->private_->tell_callback)
  88382. return false;
  88383. if(decoder->private_->tell_callback(decoder, position, decoder->private_->client_data) != FLAC__STREAM_DECODER_TELL_STATUS_OK)
  88384. return false;
  88385. if(!FLAC__bitreader_is_consumed_byte_aligned(decoder->private_->input))
  88386. return false;
  88387. FLAC__ASSERT(*position >= FLAC__stream_decoder_get_input_bytes_unconsumed(decoder));
  88388. *position -= FLAC__stream_decoder_get_input_bytes_unconsumed(decoder);
  88389. return true;
  88390. }
  88391. FLAC_API FLAC__bool FLAC__stream_decoder_flush(FLAC__StreamDecoder *decoder)
  88392. {
  88393. FLAC__ASSERT(0 != decoder);
  88394. FLAC__ASSERT(0 != decoder->private_);
  88395. FLAC__ASSERT(0 != decoder->protected_);
  88396. decoder->private_->samples_decoded = 0;
  88397. decoder->private_->do_md5_checking = false;
  88398. #if FLAC__HAS_OGG
  88399. if(decoder->private_->is_ogg)
  88400. FLAC__ogg_decoder_aspect_flush(&decoder->protected_->ogg_decoder_aspect);
  88401. #endif
  88402. if(!FLAC__bitreader_clear(decoder->private_->input)) {
  88403. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  88404. return false;
  88405. }
  88406. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  88407. return true;
  88408. }
  88409. FLAC_API FLAC__bool FLAC__stream_decoder_reset(FLAC__StreamDecoder *decoder)
  88410. {
  88411. FLAC__ASSERT(0 != decoder);
  88412. FLAC__ASSERT(0 != decoder->private_);
  88413. FLAC__ASSERT(0 != decoder->protected_);
  88414. if(!FLAC__stream_decoder_flush(decoder)) {
  88415. return false;
  88416. }
  88417. #if FLAC__HAS_OGG
  88418. if(decoder->private_->is_ogg)
  88419. FLAC__ogg_decoder_aspect_reset(&decoder->protected_->ogg_decoder_aspect);
  88420. #endif
  88421. if(!decoder->private_->internal_reset_hack) {
  88422. if(decoder->private_->file == stdin)
  88423. return false; /* can't rewind stdin, reset fails */
  88424. if(decoder->private_->seek_callback && decoder->private_->seek_callback(decoder, 0, decoder->private_->client_data) == FLAC__STREAM_DECODER_SEEK_STATUS_ERROR)
  88425. return false; /* seekable and seek fails, reset fails */
  88426. }
  88427. else
  88428. decoder->private_->internal_reset_hack = false;
  88429. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_METADATA;
  88430. decoder->private_->has_stream_info = false;
  88431. if(decoder->private_->has_seek_table && 0 != decoder->private_->seek_table.data.seek_table.points) {
  88432. free(decoder->private_->seek_table.data.seek_table.points);
  88433. decoder->private_->seek_table.data.seek_table.points = 0;
  88434. decoder->private_->has_seek_table = false;
  88435. }
  88436. decoder->private_->do_md5_checking = decoder->protected_->md5_checking;
  88437. decoder->private_->fixed_block_size = decoder->private_->next_fixed_block_size = 0;
  88438. FLAC__MD5Init(&decoder->private_->md5context);
  88439. decoder->private_->first_frame_offset = 0;
  88440. decoder->private_->unparseable_frame_count = 0;
  88441. return true;
  88442. }
  88443. FLAC_API FLAC__bool FLAC__stream_decoder_process_single(FLAC__StreamDecoder *decoder)
  88444. {
  88445. FLAC__bool got_a_frame;
  88446. FLAC__ASSERT(0 != decoder);
  88447. FLAC__ASSERT(0 != decoder->protected_);
  88448. while(1) {
  88449. switch(decoder->protected_->state) {
  88450. case FLAC__STREAM_DECODER_SEARCH_FOR_METADATA:
  88451. if(!find_metadata_(decoder))
  88452. return false; /* above function sets the status for us */
  88453. break;
  88454. case FLAC__STREAM_DECODER_READ_METADATA:
  88455. if(!read_metadata_(decoder))
  88456. return false; /* above function sets the status for us */
  88457. else
  88458. return true;
  88459. case FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC:
  88460. if(!frame_sync_(decoder))
  88461. return true; /* above function sets the status for us */
  88462. break;
  88463. case FLAC__STREAM_DECODER_READ_FRAME:
  88464. if(!read_frame_(decoder, &got_a_frame, /*do_full_decode=*/true))
  88465. return false; /* above function sets the status for us */
  88466. if(got_a_frame)
  88467. return true; /* above function sets the status for us */
  88468. break;
  88469. case FLAC__STREAM_DECODER_END_OF_STREAM:
  88470. case FLAC__STREAM_DECODER_ABORTED:
  88471. return true;
  88472. default:
  88473. FLAC__ASSERT(0);
  88474. return false;
  88475. }
  88476. }
  88477. }
  88478. FLAC_API FLAC__bool FLAC__stream_decoder_process_until_end_of_metadata(FLAC__StreamDecoder *decoder)
  88479. {
  88480. FLAC__ASSERT(0 != decoder);
  88481. FLAC__ASSERT(0 != decoder->protected_);
  88482. while(1) {
  88483. switch(decoder->protected_->state) {
  88484. case FLAC__STREAM_DECODER_SEARCH_FOR_METADATA:
  88485. if(!find_metadata_(decoder))
  88486. return false; /* above function sets the status for us */
  88487. break;
  88488. case FLAC__STREAM_DECODER_READ_METADATA:
  88489. if(!read_metadata_(decoder))
  88490. return false; /* above function sets the status for us */
  88491. break;
  88492. case FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC:
  88493. case FLAC__STREAM_DECODER_READ_FRAME:
  88494. case FLAC__STREAM_DECODER_END_OF_STREAM:
  88495. case FLAC__STREAM_DECODER_ABORTED:
  88496. return true;
  88497. default:
  88498. FLAC__ASSERT(0);
  88499. return false;
  88500. }
  88501. }
  88502. }
  88503. FLAC_API FLAC__bool FLAC__stream_decoder_process_until_end_of_stream(FLAC__StreamDecoder *decoder)
  88504. {
  88505. FLAC__bool dummy;
  88506. FLAC__ASSERT(0 != decoder);
  88507. FLAC__ASSERT(0 != decoder->protected_);
  88508. while(1) {
  88509. switch(decoder->protected_->state) {
  88510. case FLAC__STREAM_DECODER_SEARCH_FOR_METADATA:
  88511. if(!find_metadata_(decoder))
  88512. return false; /* above function sets the status for us */
  88513. break;
  88514. case FLAC__STREAM_DECODER_READ_METADATA:
  88515. if(!read_metadata_(decoder))
  88516. return false; /* above function sets the status for us */
  88517. break;
  88518. case FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC:
  88519. if(!frame_sync_(decoder))
  88520. return true; /* above function sets the status for us */
  88521. break;
  88522. case FLAC__STREAM_DECODER_READ_FRAME:
  88523. if(!read_frame_(decoder, &dummy, /*do_full_decode=*/true))
  88524. return false; /* above function sets the status for us */
  88525. break;
  88526. case FLAC__STREAM_DECODER_END_OF_STREAM:
  88527. case FLAC__STREAM_DECODER_ABORTED:
  88528. return true;
  88529. default:
  88530. FLAC__ASSERT(0);
  88531. return false;
  88532. }
  88533. }
  88534. }
  88535. FLAC_API FLAC__bool FLAC__stream_decoder_skip_single_frame(FLAC__StreamDecoder *decoder)
  88536. {
  88537. FLAC__bool got_a_frame;
  88538. FLAC__ASSERT(0 != decoder);
  88539. FLAC__ASSERT(0 != decoder->protected_);
  88540. while(1) {
  88541. switch(decoder->protected_->state) {
  88542. case FLAC__STREAM_DECODER_SEARCH_FOR_METADATA:
  88543. case FLAC__STREAM_DECODER_READ_METADATA:
  88544. return false; /* above function sets the status for us */
  88545. case FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC:
  88546. if(!frame_sync_(decoder))
  88547. return true; /* above function sets the status for us */
  88548. break;
  88549. case FLAC__STREAM_DECODER_READ_FRAME:
  88550. if(!read_frame_(decoder, &got_a_frame, /*do_full_decode=*/false))
  88551. return false; /* above function sets the status for us */
  88552. if(got_a_frame)
  88553. return true; /* above function sets the status for us */
  88554. break;
  88555. case FLAC__STREAM_DECODER_END_OF_STREAM:
  88556. case FLAC__STREAM_DECODER_ABORTED:
  88557. return true;
  88558. default:
  88559. FLAC__ASSERT(0);
  88560. return false;
  88561. }
  88562. }
  88563. }
  88564. FLAC_API FLAC__bool FLAC__stream_decoder_seek_absolute(FLAC__StreamDecoder *decoder, FLAC__uint64 sample)
  88565. {
  88566. FLAC__uint64 length;
  88567. FLAC__ASSERT(0 != decoder);
  88568. if(
  88569. decoder->protected_->state != FLAC__STREAM_DECODER_SEARCH_FOR_METADATA &&
  88570. decoder->protected_->state != FLAC__STREAM_DECODER_READ_METADATA &&
  88571. decoder->protected_->state != FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC &&
  88572. decoder->protected_->state != FLAC__STREAM_DECODER_READ_FRAME &&
  88573. decoder->protected_->state != FLAC__STREAM_DECODER_END_OF_STREAM
  88574. )
  88575. return false;
  88576. if(0 == decoder->private_->seek_callback)
  88577. return false;
  88578. FLAC__ASSERT(decoder->private_->seek_callback);
  88579. FLAC__ASSERT(decoder->private_->tell_callback);
  88580. FLAC__ASSERT(decoder->private_->length_callback);
  88581. FLAC__ASSERT(decoder->private_->eof_callback);
  88582. if(FLAC__stream_decoder_get_total_samples(decoder) > 0 && sample >= FLAC__stream_decoder_get_total_samples(decoder))
  88583. return false;
  88584. decoder->private_->is_seeking = true;
  88585. decoder->private_->do_md5_checking = false;
  88586. if(decoder->private_->length_callback(decoder, &length, decoder->private_->client_data) != FLAC__STREAM_DECODER_LENGTH_STATUS_OK) {
  88587. decoder->private_->is_seeking = false;
  88588. return false;
  88589. }
  88590. if(
  88591. decoder->protected_->state == FLAC__STREAM_DECODER_SEARCH_FOR_METADATA ||
  88592. decoder->protected_->state == FLAC__STREAM_DECODER_READ_METADATA
  88593. ) {
  88594. if(!FLAC__stream_decoder_process_until_end_of_metadata(decoder)) {
  88595. decoder->private_->is_seeking = false;
  88596. return false;
  88597. }
  88598. if(FLAC__stream_decoder_get_total_samples(decoder) > 0 && sample >= FLAC__stream_decoder_get_total_samples(decoder)) {
  88599. decoder->private_->is_seeking = false;
  88600. return false;
  88601. }
  88602. }
  88603. {
  88604. const FLAC__bool ok =
  88605. #if FLAC__HAS_OGG
  88606. decoder->private_->is_ogg?
  88607. seek_to_absolute_sample_ogg_(decoder, length, sample) :
  88608. #endif
  88609. seek_to_absolute_sample_(decoder, length, sample)
  88610. ;
  88611. decoder->private_->is_seeking = false;
  88612. return ok;
  88613. }
  88614. }
  88615. unsigned FLAC__stream_decoder_get_input_bytes_unconsumed(const FLAC__StreamDecoder *decoder)
  88616. {
  88617. FLAC__ASSERT(0 != decoder);
  88618. FLAC__ASSERT(FLAC__bitreader_is_consumed_byte_aligned(decoder->private_->input));
  88619. FLAC__ASSERT(!(FLAC__bitreader_get_input_bits_unconsumed(decoder->private_->input) & 7));
  88620. return FLAC__bitreader_get_input_bits_unconsumed(decoder->private_->input) / 8;
  88621. }
  88622. void set_defaults_dec(FLAC__StreamDecoder *decoder)
  88623. {
  88624. #if FLAC__HAS_OGG
  88625. decoder->private_->is_ogg = false;
  88626. #endif
  88627. decoder->private_->read_callback = 0;
  88628. decoder->private_->seek_callback = 0;
  88629. decoder->private_->tell_callback = 0;
  88630. decoder->private_->length_callback = 0;
  88631. decoder->private_->eof_callback = 0;
  88632. decoder->private_->write_callback = 0;
  88633. decoder->private_->metadata_callback = 0;
  88634. decoder->private_->error_callback = 0;
  88635. decoder->private_->client_data = 0;
  88636. memset(decoder->private_->metadata_filter, 0, sizeof(decoder->private_->metadata_filter));
  88637. decoder->private_->metadata_filter[FLAC__METADATA_TYPE_STREAMINFO] = true;
  88638. decoder->private_->metadata_filter_ids_count = 0;
  88639. decoder->protected_->md5_checking = false;
  88640. #if FLAC__HAS_OGG
  88641. FLAC__ogg_decoder_aspect_set_defaults(&decoder->protected_->ogg_decoder_aspect);
  88642. #endif
  88643. }
  88644. FILE *get_binary_stdin_(void)
  88645. {
  88646. #if defined _MSC_VER || defined __MINGW32__
  88647. _setmode(_fileno(stdin), _O_BINARY);
  88648. #elif defined __CYGWIN__
  88649. setmode(_fileno(stdin), _O_BINARY);
  88650. #elif defined __EMX__
  88651. setmode(fileno(stdin), O_BINARY);
  88652. #endif
  88653. return stdin;
  88654. }
  88655. FLAC__bool allocate_output_(FLAC__StreamDecoder *decoder, unsigned size, unsigned channels)
  88656. {
  88657. unsigned i;
  88658. FLAC__int32 *tmp;
  88659. if(size <= decoder->private_->output_capacity && channels <= decoder->private_->output_channels)
  88660. return true;
  88661. for(i = 0; i < FLAC__MAX_CHANNELS; i++) {
  88662. if(0 != decoder->private_->output[i]) {
  88663. free(decoder->private_->output[i]-4);
  88664. decoder->private_->output[i] = 0;
  88665. }
  88666. if(0 != decoder->private_->residual_unaligned[i]) {
  88667. free(decoder->private_->residual_unaligned[i]);
  88668. decoder->private_->residual_unaligned[i] = decoder->private_->residual[i] = 0;
  88669. }
  88670. }
  88671. for(i = 0; i < channels; i++) {
  88672. tmp = (FLAC__int32*)safe_malloc_muladd2_(sizeof(FLAC__int32), /*times (*/size, /*+*/4/*)*/);
  88673. if(tmp == 0) {
  88674. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  88675. return false;
  88676. }
  88677. memset(tmp, 0, sizeof(FLAC__int32)*4);
  88678. decoder->private_->output[i] = tmp + 4;
  88679. if(!FLAC__memory_alloc_aligned_int32_array(size, &decoder->private_->residual_unaligned[i], &decoder->private_->residual[i])) {
  88680. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  88681. return false;
  88682. }
  88683. }
  88684. decoder->private_->output_capacity = size;
  88685. decoder->private_->output_channels = channels;
  88686. return true;
  88687. }
  88688. FLAC__bool has_id_filtered_(FLAC__StreamDecoder *decoder, FLAC__byte *id)
  88689. {
  88690. size_t i;
  88691. FLAC__ASSERT(0 != decoder);
  88692. FLAC__ASSERT(0 != decoder->private_);
  88693. for(i = 0; i < decoder->private_->metadata_filter_ids_count; i++)
  88694. if(0 == memcmp(decoder->private_->metadata_filter_ids + i * (FLAC__STREAM_METADATA_APPLICATION_ID_LEN/8), id, (FLAC__STREAM_METADATA_APPLICATION_ID_LEN/8)))
  88695. return true;
  88696. return false;
  88697. }
  88698. FLAC__bool find_metadata_(FLAC__StreamDecoder *decoder)
  88699. {
  88700. FLAC__uint32 x;
  88701. unsigned i, id_;
  88702. FLAC__bool first = true;
  88703. FLAC__ASSERT(FLAC__bitreader_is_consumed_byte_aligned(decoder->private_->input));
  88704. for(i = id_ = 0; i < 4; ) {
  88705. if(decoder->private_->cached) {
  88706. x = (FLAC__uint32)decoder->private_->lookahead;
  88707. decoder->private_->cached = false;
  88708. }
  88709. else {
  88710. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, 8))
  88711. return false; /* read_callback_ sets the state for us */
  88712. }
  88713. if(x == FLAC__STREAM_SYNC_STRING[i]) {
  88714. first = true;
  88715. i++;
  88716. id_ = 0;
  88717. continue;
  88718. }
  88719. if(x == ID3V2_TAG_[id_]) {
  88720. id_++;
  88721. i = 0;
  88722. if(id_ == 3) {
  88723. if(!skip_id3v2_tag_(decoder))
  88724. return false; /* skip_id3v2_tag_ sets the state for us */
  88725. }
  88726. continue;
  88727. }
  88728. id_ = 0;
  88729. if(x == 0xff) { /* MAGIC NUMBER for the first 8 frame sync bits */
  88730. decoder->private_->header_warmup[0] = (FLAC__byte)x;
  88731. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, 8))
  88732. return false; /* read_callback_ sets the state for us */
  88733. if(x == 0xff) { /* MAGIC NUMBER for the first 8 frame sync bits */
  88734. decoder->private_->lookahead = (FLAC__byte)x;
  88735. decoder->private_->cached = true;
  88736. }
  88737. else if(x >> 2 == 0x3e) { /* MAGIC NUMBER for the last 6 sync bits */
  88738. decoder->private_->header_warmup[1] = (FLAC__byte)x;
  88739. decoder->protected_->state = FLAC__STREAM_DECODER_READ_FRAME;
  88740. return true;
  88741. }
  88742. }
  88743. i = 0;
  88744. if(first) {
  88745. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC);
  88746. first = false;
  88747. }
  88748. }
  88749. decoder->protected_->state = FLAC__STREAM_DECODER_READ_METADATA;
  88750. return true;
  88751. }
  88752. FLAC__bool read_metadata_(FLAC__StreamDecoder *decoder)
  88753. {
  88754. FLAC__bool is_last;
  88755. FLAC__uint32 i, x, type, length;
  88756. FLAC__ASSERT(FLAC__bitreader_is_consumed_byte_aligned(decoder->private_->input));
  88757. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_IS_LAST_LEN))
  88758. return false; /* read_callback_ sets the state for us */
  88759. is_last = x? true : false;
  88760. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &type, FLAC__STREAM_METADATA_TYPE_LEN))
  88761. return false; /* read_callback_ sets the state for us */
  88762. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &length, FLAC__STREAM_METADATA_LENGTH_LEN))
  88763. return false; /* read_callback_ sets the state for us */
  88764. if(type == FLAC__METADATA_TYPE_STREAMINFO) {
  88765. if(!read_metadata_streaminfo_(decoder, is_last, length))
  88766. return false;
  88767. decoder->private_->has_stream_info = true;
  88768. 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))
  88769. decoder->private_->do_md5_checking = false;
  88770. if(!decoder->private_->is_seeking && decoder->private_->metadata_filter[FLAC__METADATA_TYPE_STREAMINFO] && decoder->private_->metadata_callback)
  88771. decoder->private_->metadata_callback(decoder, &decoder->private_->stream_info, decoder->private_->client_data);
  88772. }
  88773. else if(type == FLAC__METADATA_TYPE_SEEKTABLE) {
  88774. if(!read_metadata_seektable_(decoder, is_last, length))
  88775. return false;
  88776. decoder->private_->has_seek_table = true;
  88777. if(!decoder->private_->is_seeking && decoder->private_->metadata_filter[FLAC__METADATA_TYPE_SEEKTABLE] && decoder->private_->metadata_callback)
  88778. decoder->private_->metadata_callback(decoder, &decoder->private_->seek_table, decoder->private_->client_data);
  88779. }
  88780. else {
  88781. FLAC__bool skip_it = !decoder->private_->metadata_filter[type];
  88782. unsigned real_length = length;
  88783. FLAC__StreamMetadata block;
  88784. block.is_last = is_last;
  88785. block.type = (FLAC__MetadataType)type;
  88786. block.length = length;
  88787. if(type == FLAC__METADATA_TYPE_APPLICATION) {
  88788. if(!FLAC__bitreader_read_byte_block_aligned_no_crc(decoder->private_->input, block.data.application.id, FLAC__STREAM_METADATA_APPLICATION_ID_LEN/8))
  88789. return false; /* read_callback_ sets the state for us */
  88790. if(real_length < FLAC__STREAM_METADATA_APPLICATION_ID_LEN/8) { /* underflow check */
  88791. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;/*@@@@@@ maybe wrong error? need to resync?*/
  88792. return false;
  88793. }
  88794. real_length -= FLAC__STREAM_METADATA_APPLICATION_ID_LEN/8;
  88795. if(decoder->private_->metadata_filter_ids_count > 0 && has_id_filtered_(decoder, block.data.application.id))
  88796. skip_it = !skip_it;
  88797. }
  88798. if(skip_it) {
  88799. if(!FLAC__bitreader_skip_byte_block_aligned_no_crc(decoder->private_->input, real_length))
  88800. return false; /* read_callback_ sets the state for us */
  88801. }
  88802. else {
  88803. switch(type) {
  88804. case FLAC__METADATA_TYPE_PADDING:
  88805. if(!FLAC__bitreader_skip_byte_block_aligned_no_crc(decoder->private_->input, real_length))
  88806. return false; /* read_callback_ sets the state for us */
  88807. break;
  88808. case FLAC__METADATA_TYPE_APPLICATION:
  88809. if(real_length > 0) {
  88810. if(0 == (block.data.application.data = (FLAC__byte*)malloc(real_length))) {
  88811. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  88812. return false;
  88813. }
  88814. if(!FLAC__bitreader_read_byte_block_aligned_no_crc(decoder->private_->input, block.data.application.data, real_length))
  88815. return false; /* read_callback_ sets the state for us */
  88816. }
  88817. else
  88818. block.data.application.data = 0;
  88819. break;
  88820. case FLAC__METADATA_TYPE_VORBIS_COMMENT:
  88821. if(!read_metadata_vorbiscomment_(decoder, &block.data.vorbis_comment))
  88822. return false;
  88823. break;
  88824. case FLAC__METADATA_TYPE_CUESHEET:
  88825. if(!read_metadata_cuesheet_(decoder, &block.data.cue_sheet))
  88826. return false;
  88827. break;
  88828. case FLAC__METADATA_TYPE_PICTURE:
  88829. if(!read_metadata_picture_(decoder, &block.data.picture))
  88830. return false;
  88831. break;
  88832. case FLAC__METADATA_TYPE_STREAMINFO:
  88833. case FLAC__METADATA_TYPE_SEEKTABLE:
  88834. FLAC__ASSERT(0);
  88835. break;
  88836. default:
  88837. if(real_length > 0) {
  88838. if(0 == (block.data.unknown.data = (FLAC__byte*)malloc(real_length))) {
  88839. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  88840. return false;
  88841. }
  88842. if(!FLAC__bitreader_read_byte_block_aligned_no_crc(decoder->private_->input, block.data.unknown.data, real_length))
  88843. return false; /* read_callback_ sets the state for us */
  88844. }
  88845. else
  88846. block.data.unknown.data = 0;
  88847. break;
  88848. }
  88849. if(!decoder->private_->is_seeking && decoder->private_->metadata_callback)
  88850. decoder->private_->metadata_callback(decoder, &block, decoder->private_->client_data);
  88851. switch(type) {
  88852. case FLAC__METADATA_TYPE_PADDING:
  88853. break;
  88854. case FLAC__METADATA_TYPE_APPLICATION:
  88855. if(0 != block.data.application.data)
  88856. free(block.data.application.data);
  88857. break;
  88858. case FLAC__METADATA_TYPE_VORBIS_COMMENT:
  88859. if(0 != block.data.vorbis_comment.vendor_string.entry)
  88860. free(block.data.vorbis_comment.vendor_string.entry);
  88861. if(block.data.vorbis_comment.num_comments > 0)
  88862. for(i = 0; i < block.data.vorbis_comment.num_comments; i++)
  88863. if(0 != block.data.vorbis_comment.comments[i].entry)
  88864. free(block.data.vorbis_comment.comments[i].entry);
  88865. if(0 != block.data.vorbis_comment.comments)
  88866. free(block.data.vorbis_comment.comments);
  88867. break;
  88868. case FLAC__METADATA_TYPE_CUESHEET:
  88869. if(block.data.cue_sheet.num_tracks > 0)
  88870. for(i = 0; i < block.data.cue_sheet.num_tracks; i++)
  88871. if(0 != block.data.cue_sheet.tracks[i].indices)
  88872. free(block.data.cue_sheet.tracks[i].indices);
  88873. if(0 != block.data.cue_sheet.tracks)
  88874. free(block.data.cue_sheet.tracks);
  88875. break;
  88876. case FLAC__METADATA_TYPE_PICTURE:
  88877. if(0 != block.data.picture.mime_type)
  88878. free(block.data.picture.mime_type);
  88879. if(0 != block.data.picture.description)
  88880. free(block.data.picture.description);
  88881. if(0 != block.data.picture.data)
  88882. free(block.data.picture.data);
  88883. break;
  88884. case FLAC__METADATA_TYPE_STREAMINFO:
  88885. case FLAC__METADATA_TYPE_SEEKTABLE:
  88886. FLAC__ASSERT(0);
  88887. default:
  88888. if(0 != block.data.unknown.data)
  88889. free(block.data.unknown.data);
  88890. break;
  88891. }
  88892. }
  88893. }
  88894. if(is_last) {
  88895. if(!FLAC__stream_decoder_get_decode_position(decoder, &decoder->private_->first_frame_offset))
  88896. decoder->private_->first_frame_offset = 0;
  88897. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  88898. }
  88899. return true;
  88900. }
  88901. FLAC__bool read_metadata_streaminfo_(FLAC__StreamDecoder *decoder, FLAC__bool is_last, unsigned length)
  88902. {
  88903. FLAC__uint32 x;
  88904. unsigned bits, used_bits = 0;
  88905. FLAC__ASSERT(FLAC__bitreader_is_consumed_byte_aligned(decoder->private_->input));
  88906. decoder->private_->stream_info.type = FLAC__METADATA_TYPE_STREAMINFO;
  88907. decoder->private_->stream_info.is_last = is_last;
  88908. decoder->private_->stream_info.length = length;
  88909. bits = FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN;
  88910. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, bits))
  88911. return false; /* read_callback_ sets the state for us */
  88912. decoder->private_->stream_info.data.stream_info.min_blocksize = x;
  88913. used_bits += bits;
  88914. bits = FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN;
  88915. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN))
  88916. return false; /* read_callback_ sets the state for us */
  88917. decoder->private_->stream_info.data.stream_info.max_blocksize = x;
  88918. used_bits += bits;
  88919. bits = FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN;
  88920. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN))
  88921. return false; /* read_callback_ sets the state for us */
  88922. decoder->private_->stream_info.data.stream_info.min_framesize = x;
  88923. used_bits += bits;
  88924. bits = FLAC__STREAM_METADATA_STREAMINFO_MAX_FRAME_SIZE_LEN;
  88925. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_STREAMINFO_MAX_FRAME_SIZE_LEN))
  88926. return false; /* read_callback_ sets the state for us */
  88927. decoder->private_->stream_info.data.stream_info.max_framesize = x;
  88928. used_bits += bits;
  88929. bits = FLAC__STREAM_METADATA_STREAMINFO_SAMPLE_RATE_LEN;
  88930. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_STREAMINFO_SAMPLE_RATE_LEN))
  88931. return false; /* read_callback_ sets the state for us */
  88932. decoder->private_->stream_info.data.stream_info.sample_rate = x;
  88933. used_bits += bits;
  88934. bits = FLAC__STREAM_METADATA_STREAMINFO_CHANNELS_LEN;
  88935. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_STREAMINFO_CHANNELS_LEN))
  88936. return false; /* read_callback_ sets the state for us */
  88937. decoder->private_->stream_info.data.stream_info.channels = x+1;
  88938. used_bits += bits;
  88939. bits = FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN;
  88940. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN))
  88941. return false; /* read_callback_ sets the state for us */
  88942. decoder->private_->stream_info.data.stream_info.bits_per_sample = x+1;
  88943. used_bits += bits;
  88944. bits = FLAC__STREAM_METADATA_STREAMINFO_TOTAL_SAMPLES_LEN;
  88945. 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))
  88946. return false; /* read_callback_ sets the state for us */
  88947. used_bits += bits;
  88948. if(!FLAC__bitreader_read_byte_block_aligned_no_crc(decoder->private_->input, decoder->private_->stream_info.data.stream_info.md5sum, 16))
  88949. return false; /* read_callback_ sets the state for us */
  88950. used_bits += 16*8;
  88951. FLAC__ASSERT(used_bits % 8 == 0);
  88952. length -= (used_bits / 8);
  88953. if(!FLAC__bitreader_skip_byte_block_aligned_no_crc(decoder->private_->input, length))
  88954. return false; /* read_callback_ sets the state for us */
  88955. return true;
  88956. }
  88957. FLAC__bool read_metadata_seektable_(FLAC__StreamDecoder *decoder, FLAC__bool is_last, unsigned length)
  88958. {
  88959. FLAC__uint32 i, x;
  88960. FLAC__uint64 xx;
  88961. FLAC__ASSERT(FLAC__bitreader_is_consumed_byte_aligned(decoder->private_->input));
  88962. decoder->private_->seek_table.type = FLAC__METADATA_TYPE_SEEKTABLE;
  88963. decoder->private_->seek_table.is_last = is_last;
  88964. decoder->private_->seek_table.length = length;
  88965. decoder->private_->seek_table.data.seek_table.num_points = length / FLAC__STREAM_METADATA_SEEKPOINT_LENGTH;
  88966. 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)))) {
  88967. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  88968. return false;
  88969. }
  88970. for(i = 0; i < decoder->private_->seek_table.data.seek_table.num_points; i++) {
  88971. if(!FLAC__bitreader_read_raw_uint64(decoder->private_->input, &xx, FLAC__STREAM_METADATA_SEEKPOINT_SAMPLE_NUMBER_LEN))
  88972. return false; /* read_callback_ sets the state for us */
  88973. decoder->private_->seek_table.data.seek_table.points[i].sample_number = xx;
  88974. if(!FLAC__bitreader_read_raw_uint64(decoder->private_->input, &xx, FLAC__STREAM_METADATA_SEEKPOINT_STREAM_OFFSET_LEN))
  88975. return false; /* read_callback_ sets the state for us */
  88976. decoder->private_->seek_table.data.seek_table.points[i].stream_offset = xx;
  88977. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_SEEKPOINT_FRAME_SAMPLES_LEN))
  88978. return false; /* read_callback_ sets the state for us */
  88979. decoder->private_->seek_table.data.seek_table.points[i].frame_samples = x;
  88980. }
  88981. length -= (decoder->private_->seek_table.data.seek_table.num_points * FLAC__STREAM_METADATA_SEEKPOINT_LENGTH);
  88982. if(length > 0) {
  88983. if(!FLAC__bitreader_skip_byte_block_aligned_no_crc(decoder->private_->input, length))
  88984. return false; /* read_callback_ sets the state for us */
  88985. }
  88986. return true;
  88987. }
  88988. FLAC__bool read_metadata_vorbiscomment_(FLAC__StreamDecoder *decoder, FLAC__StreamMetadata_VorbisComment *obj)
  88989. {
  88990. FLAC__uint32 i;
  88991. FLAC__ASSERT(FLAC__bitreader_is_consumed_byte_aligned(decoder->private_->input));
  88992. FLAC__ASSERT(FLAC__STREAM_METADATA_VORBIS_COMMENT_ENTRY_LENGTH_LEN == 32);
  88993. if(!FLAC__bitreader_read_uint32_little_endian(decoder->private_->input, &obj->vendor_string.length))
  88994. return false; /* read_callback_ sets the state for us */
  88995. if(obj->vendor_string.length > 0) {
  88996. if(0 == (obj->vendor_string.entry = (FLAC__byte*)safe_malloc_add_2op_(obj->vendor_string.length, /*+*/1))) {
  88997. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  88998. return false;
  88999. }
  89000. if(!FLAC__bitreader_read_byte_block_aligned_no_crc(decoder->private_->input, obj->vendor_string.entry, obj->vendor_string.length))
  89001. return false; /* read_callback_ sets the state for us */
  89002. obj->vendor_string.entry[obj->vendor_string.length] = '\0';
  89003. }
  89004. else
  89005. obj->vendor_string.entry = 0;
  89006. FLAC__ASSERT(FLAC__STREAM_METADATA_VORBIS_COMMENT_NUM_COMMENTS_LEN == 32);
  89007. if(!FLAC__bitreader_read_uint32_little_endian(decoder->private_->input, &obj->num_comments))
  89008. return false; /* read_callback_ sets the state for us */
  89009. if(obj->num_comments > 0) {
  89010. if(0 == (obj->comments = (FLAC__StreamMetadata_VorbisComment_Entry*)safe_malloc_mul_2op_(obj->num_comments, /*times*/sizeof(FLAC__StreamMetadata_VorbisComment_Entry)))) {
  89011. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  89012. return false;
  89013. }
  89014. for(i = 0; i < obj->num_comments; i++) {
  89015. FLAC__ASSERT(FLAC__STREAM_METADATA_VORBIS_COMMENT_ENTRY_LENGTH_LEN == 32);
  89016. if(!FLAC__bitreader_read_uint32_little_endian(decoder->private_->input, &obj->comments[i].length))
  89017. return false; /* read_callback_ sets the state for us */
  89018. if(obj->comments[i].length > 0) {
  89019. if(0 == (obj->comments[i].entry = (FLAC__byte*)safe_malloc_add_2op_(obj->comments[i].length, /*+*/1))) {
  89020. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  89021. return false;
  89022. }
  89023. if(!FLAC__bitreader_read_byte_block_aligned_no_crc(decoder->private_->input, obj->comments[i].entry, obj->comments[i].length))
  89024. return false; /* read_callback_ sets the state for us */
  89025. obj->comments[i].entry[obj->comments[i].length] = '\0';
  89026. }
  89027. else
  89028. obj->comments[i].entry = 0;
  89029. }
  89030. }
  89031. else {
  89032. obj->comments = 0;
  89033. }
  89034. return true;
  89035. }
  89036. FLAC__bool read_metadata_cuesheet_(FLAC__StreamDecoder *decoder, FLAC__StreamMetadata_CueSheet *obj)
  89037. {
  89038. FLAC__uint32 i, j, x;
  89039. FLAC__ASSERT(FLAC__bitreader_is_consumed_byte_aligned(decoder->private_->input));
  89040. memset(obj, 0, sizeof(FLAC__StreamMetadata_CueSheet));
  89041. FLAC__ASSERT(FLAC__STREAM_METADATA_CUESHEET_MEDIA_CATALOG_NUMBER_LEN % 8 == 0);
  89042. 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))
  89043. return false; /* read_callback_ sets the state for us */
  89044. if(!FLAC__bitreader_read_raw_uint64(decoder->private_->input, &obj->lead_in, FLAC__STREAM_METADATA_CUESHEET_LEAD_IN_LEN))
  89045. return false; /* read_callback_ sets the state for us */
  89046. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_CUESHEET_IS_CD_LEN))
  89047. return false; /* read_callback_ sets the state for us */
  89048. obj->is_cd = x? true : false;
  89049. if(!FLAC__bitreader_skip_bits_no_crc(decoder->private_->input, FLAC__STREAM_METADATA_CUESHEET_RESERVED_LEN))
  89050. return false; /* read_callback_ sets the state for us */
  89051. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_CUESHEET_NUM_TRACKS_LEN))
  89052. return false; /* read_callback_ sets the state for us */
  89053. obj->num_tracks = x;
  89054. if(obj->num_tracks > 0) {
  89055. if(0 == (obj->tracks = (FLAC__StreamMetadata_CueSheet_Track*)safe_calloc_(obj->num_tracks, sizeof(FLAC__StreamMetadata_CueSheet_Track)))) {
  89056. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  89057. return false;
  89058. }
  89059. for(i = 0; i < obj->num_tracks; i++) {
  89060. FLAC__StreamMetadata_CueSheet_Track *track = &obj->tracks[i];
  89061. if(!FLAC__bitreader_read_raw_uint64(decoder->private_->input, &track->offset, FLAC__STREAM_METADATA_CUESHEET_TRACK_OFFSET_LEN))
  89062. return false; /* read_callback_ sets the state for us */
  89063. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_CUESHEET_TRACK_NUMBER_LEN))
  89064. return false; /* read_callback_ sets the state for us */
  89065. track->number = (FLAC__byte)x;
  89066. FLAC__ASSERT(FLAC__STREAM_METADATA_CUESHEET_TRACK_ISRC_LEN % 8 == 0);
  89067. if(!FLAC__bitreader_read_byte_block_aligned_no_crc(decoder->private_->input, (FLAC__byte*)track->isrc, FLAC__STREAM_METADATA_CUESHEET_TRACK_ISRC_LEN/8))
  89068. return false; /* read_callback_ sets the state for us */
  89069. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_CUESHEET_TRACK_TYPE_LEN))
  89070. return false; /* read_callback_ sets the state for us */
  89071. track->type = x;
  89072. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_CUESHEET_TRACK_PRE_EMPHASIS_LEN))
  89073. return false; /* read_callback_ sets the state for us */
  89074. track->pre_emphasis = x;
  89075. if(!FLAC__bitreader_skip_bits_no_crc(decoder->private_->input, FLAC__STREAM_METADATA_CUESHEET_TRACK_RESERVED_LEN))
  89076. return false; /* read_callback_ sets the state for us */
  89077. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_CUESHEET_TRACK_NUM_INDICES_LEN))
  89078. return false; /* read_callback_ sets the state for us */
  89079. track->num_indices = (FLAC__byte)x;
  89080. if(track->num_indices > 0) {
  89081. if(0 == (track->indices = (FLAC__StreamMetadata_CueSheet_Index*)safe_calloc_(track->num_indices, sizeof(FLAC__StreamMetadata_CueSheet_Index)))) {
  89082. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  89083. return false;
  89084. }
  89085. for(j = 0; j < track->num_indices; j++) {
  89086. FLAC__StreamMetadata_CueSheet_Index *index = &track->indices[j];
  89087. if(!FLAC__bitreader_read_raw_uint64(decoder->private_->input, &index->offset, FLAC__STREAM_METADATA_CUESHEET_INDEX_OFFSET_LEN))
  89088. return false; /* read_callback_ sets the state for us */
  89089. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_CUESHEET_INDEX_NUMBER_LEN))
  89090. return false; /* read_callback_ sets the state for us */
  89091. index->number = (FLAC__byte)x;
  89092. if(!FLAC__bitreader_skip_bits_no_crc(decoder->private_->input, FLAC__STREAM_METADATA_CUESHEET_INDEX_RESERVED_LEN))
  89093. return false; /* read_callback_ sets the state for us */
  89094. }
  89095. }
  89096. }
  89097. }
  89098. return true;
  89099. }
  89100. FLAC__bool read_metadata_picture_(FLAC__StreamDecoder *decoder, FLAC__StreamMetadata_Picture *obj)
  89101. {
  89102. FLAC__uint32 x;
  89103. FLAC__ASSERT(FLAC__bitreader_is_consumed_byte_aligned(decoder->private_->input));
  89104. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_PICTURE_TYPE_LEN))
  89105. return false; /* read_callback_ sets the state for us */
  89106. obj->type = (FLAC__StreamMetadata_Picture_Type) x;
  89107. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_PICTURE_MIME_TYPE_LENGTH_LEN))
  89108. return false; /* read_callback_ sets the state for us */
  89109. if(0 == (obj->mime_type = (char*)safe_malloc_add_2op_(x, /*+*/1))) {
  89110. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  89111. return false;
  89112. }
  89113. if(x > 0) {
  89114. if(!FLAC__bitreader_read_byte_block_aligned_no_crc(decoder->private_->input, (FLAC__byte*)obj->mime_type, x))
  89115. return false; /* read_callback_ sets the state for us */
  89116. }
  89117. obj->mime_type[x] = '\0';
  89118. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_PICTURE_DESCRIPTION_LENGTH_LEN))
  89119. return false; /* read_callback_ sets the state for us */
  89120. if(0 == (obj->description = (FLAC__byte*)safe_malloc_add_2op_(x, /*+*/1))) {
  89121. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  89122. return false;
  89123. }
  89124. if(x > 0) {
  89125. if(!FLAC__bitreader_read_byte_block_aligned_no_crc(decoder->private_->input, obj->description, x))
  89126. return false; /* read_callback_ sets the state for us */
  89127. }
  89128. obj->description[x] = '\0';
  89129. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &obj->width, FLAC__STREAM_METADATA_PICTURE_WIDTH_LEN))
  89130. return false; /* read_callback_ sets the state for us */
  89131. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &obj->height, FLAC__STREAM_METADATA_PICTURE_HEIGHT_LEN))
  89132. return false; /* read_callback_ sets the state for us */
  89133. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &obj->depth, FLAC__STREAM_METADATA_PICTURE_DEPTH_LEN))
  89134. return false; /* read_callback_ sets the state for us */
  89135. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &obj->colors, FLAC__STREAM_METADATA_PICTURE_COLORS_LEN))
  89136. return false; /* read_callback_ sets the state for us */
  89137. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &(obj->data_length), FLAC__STREAM_METADATA_PICTURE_DATA_LENGTH_LEN))
  89138. return false; /* read_callback_ sets the state for us */
  89139. if(0 == (obj->data = (FLAC__byte*)safe_malloc_(obj->data_length))) {
  89140. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  89141. return false;
  89142. }
  89143. if(obj->data_length > 0) {
  89144. if(!FLAC__bitreader_read_byte_block_aligned_no_crc(decoder->private_->input, obj->data, obj->data_length))
  89145. return false; /* read_callback_ sets the state for us */
  89146. }
  89147. return true;
  89148. }
  89149. FLAC__bool skip_id3v2_tag_(FLAC__StreamDecoder *decoder)
  89150. {
  89151. FLAC__uint32 x;
  89152. unsigned i, skip;
  89153. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, 24))
  89154. return false; /* read_callback_ sets the state for us */
  89155. skip = 0;
  89156. for(i = 0; i < 4; i++) {
  89157. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, 8))
  89158. return false; /* read_callback_ sets the state for us */
  89159. skip <<= 7;
  89160. skip |= (x & 0x7f);
  89161. }
  89162. if(!FLAC__bitreader_skip_byte_block_aligned_no_crc(decoder->private_->input, skip))
  89163. return false; /* read_callback_ sets the state for us */
  89164. return true;
  89165. }
  89166. FLAC__bool frame_sync_(FLAC__StreamDecoder *decoder)
  89167. {
  89168. FLAC__uint32 x;
  89169. FLAC__bool first = true;
  89170. if(FLAC__stream_decoder_get_total_samples(decoder) > 0) {
  89171. if(decoder->private_->samples_decoded >= FLAC__stream_decoder_get_total_samples(decoder)) {
  89172. decoder->protected_->state = FLAC__STREAM_DECODER_END_OF_STREAM;
  89173. return true;
  89174. }
  89175. }
  89176. if(!FLAC__bitreader_is_consumed_byte_aligned(decoder->private_->input)) {
  89177. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__bitreader_bits_left_for_byte_alignment(decoder->private_->input)))
  89178. return false; /* read_callback_ sets the state for us */
  89179. }
  89180. while(1) {
  89181. if(decoder->private_->cached) {
  89182. x = (FLAC__uint32)decoder->private_->lookahead;
  89183. decoder->private_->cached = false;
  89184. }
  89185. else {
  89186. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, 8))
  89187. return false; /* read_callback_ sets the state for us */
  89188. }
  89189. if(x == 0xff) { /* MAGIC NUMBER for the first 8 frame sync bits */
  89190. decoder->private_->header_warmup[0] = (FLAC__byte)x;
  89191. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, 8))
  89192. return false; /* read_callback_ sets the state for us */
  89193. if(x == 0xff) { /* MAGIC NUMBER for the first 8 frame sync bits */
  89194. decoder->private_->lookahead = (FLAC__byte)x;
  89195. decoder->private_->cached = true;
  89196. }
  89197. else if(x >> 2 == 0x3e) { /* MAGIC NUMBER for the last 6 sync bits */
  89198. decoder->private_->header_warmup[1] = (FLAC__byte)x;
  89199. decoder->protected_->state = FLAC__STREAM_DECODER_READ_FRAME;
  89200. return true;
  89201. }
  89202. }
  89203. if(first) {
  89204. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC);
  89205. first = false;
  89206. }
  89207. }
  89208. return true;
  89209. }
  89210. FLAC__bool read_frame_(FLAC__StreamDecoder *decoder, FLAC__bool *got_a_frame, FLAC__bool do_full_decode)
  89211. {
  89212. unsigned channel;
  89213. unsigned i;
  89214. FLAC__int32 mid, side;
  89215. unsigned frame_crc; /* the one we calculate from the input stream */
  89216. FLAC__uint32 x;
  89217. *got_a_frame = false;
  89218. frame_crc = 0;
  89219. frame_crc = FLAC__CRC16_UPDATE(decoder->private_->header_warmup[0], frame_crc);
  89220. frame_crc = FLAC__CRC16_UPDATE(decoder->private_->header_warmup[1], frame_crc);
  89221. FLAC__bitreader_reset_read_crc16(decoder->private_->input, (FLAC__uint16)frame_crc);
  89222. if(!read_frame_header_(decoder))
  89223. return false;
  89224. if(decoder->protected_->state == FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC) /* means we didn't sync on a valid header */
  89225. return true;
  89226. if(!allocate_output_(decoder, decoder->private_->frame.header.blocksize, decoder->private_->frame.header.channels))
  89227. return false;
  89228. for(channel = 0; channel < decoder->private_->frame.header.channels; channel++) {
  89229. unsigned bps = decoder->private_->frame.header.bits_per_sample;
  89230. switch(decoder->private_->frame.header.channel_assignment) {
  89231. case FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT:
  89232. break;
  89233. case FLAC__CHANNEL_ASSIGNMENT_LEFT_SIDE:
  89234. FLAC__ASSERT(decoder->private_->frame.header.channels == 2);
  89235. if(channel == 1)
  89236. bps++;
  89237. break;
  89238. case FLAC__CHANNEL_ASSIGNMENT_RIGHT_SIDE:
  89239. FLAC__ASSERT(decoder->private_->frame.header.channels == 2);
  89240. if(channel == 0)
  89241. bps++;
  89242. break;
  89243. case FLAC__CHANNEL_ASSIGNMENT_MID_SIDE:
  89244. FLAC__ASSERT(decoder->private_->frame.header.channels == 2);
  89245. if(channel == 1)
  89246. bps++;
  89247. break;
  89248. default:
  89249. FLAC__ASSERT(0);
  89250. }
  89251. if(!read_subframe_(decoder, channel, bps, do_full_decode))
  89252. return false;
  89253. if(decoder->protected_->state == FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC) /* means bad sync or got corruption */
  89254. return true;
  89255. }
  89256. if(!read_zero_padding_(decoder))
  89257. return false;
  89258. 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) */
  89259. return true;
  89260. frame_crc = FLAC__bitreader_get_read_crc16(decoder->private_->input);
  89261. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__FRAME_FOOTER_CRC_LEN))
  89262. return false; /* read_callback_ sets the state for us */
  89263. if(frame_crc == x) {
  89264. if(do_full_decode) {
  89265. switch(decoder->private_->frame.header.channel_assignment) {
  89266. case FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT:
  89267. break;
  89268. case FLAC__CHANNEL_ASSIGNMENT_LEFT_SIDE:
  89269. FLAC__ASSERT(decoder->private_->frame.header.channels == 2);
  89270. for(i = 0; i < decoder->private_->frame.header.blocksize; i++)
  89271. decoder->private_->output[1][i] = decoder->private_->output[0][i] - decoder->private_->output[1][i];
  89272. break;
  89273. case FLAC__CHANNEL_ASSIGNMENT_RIGHT_SIDE:
  89274. FLAC__ASSERT(decoder->private_->frame.header.channels == 2);
  89275. for(i = 0; i < decoder->private_->frame.header.blocksize; i++)
  89276. decoder->private_->output[0][i] += decoder->private_->output[1][i];
  89277. break;
  89278. case FLAC__CHANNEL_ASSIGNMENT_MID_SIDE:
  89279. FLAC__ASSERT(decoder->private_->frame.header.channels == 2);
  89280. for(i = 0; i < decoder->private_->frame.header.blocksize; i++) {
  89281. #if 1
  89282. mid = decoder->private_->output[0][i];
  89283. side = decoder->private_->output[1][i];
  89284. mid <<= 1;
  89285. mid |= (side & 1); /* i.e. if 'side' is odd... */
  89286. decoder->private_->output[0][i] = (mid + side) >> 1;
  89287. decoder->private_->output[1][i] = (mid - side) >> 1;
  89288. #else
  89289. mid = (decoder->private_->output[0][i] << 1) | (decoder->private_->output[1][i] & 1); /* i.e. if 'side' is odd... */
  89290. decoder->private_->output[0][i] = (mid + decoder->private_->output[1][i]) >> 1;
  89291. decoder->private_->output[1][i] = (mid - decoder->private_->output[1][i]) >> 1;
  89292. #endif
  89293. }
  89294. break;
  89295. default:
  89296. FLAC__ASSERT(0);
  89297. break;
  89298. }
  89299. }
  89300. }
  89301. else {
  89302. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_FRAME_CRC_MISMATCH);
  89303. if(do_full_decode) {
  89304. for(channel = 0; channel < decoder->private_->frame.header.channels; channel++) {
  89305. memset(decoder->private_->output[channel], 0, sizeof(FLAC__int32) * decoder->private_->frame.header.blocksize);
  89306. }
  89307. }
  89308. }
  89309. *got_a_frame = true;
  89310. if(decoder->private_->next_fixed_block_size)
  89311. decoder->private_->fixed_block_size = decoder->private_->next_fixed_block_size;
  89312. decoder->protected_->channels = decoder->private_->frame.header.channels;
  89313. decoder->protected_->channel_assignment = decoder->private_->frame.header.channel_assignment;
  89314. decoder->protected_->bits_per_sample = decoder->private_->frame.header.bits_per_sample;
  89315. decoder->protected_->sample_rate = decoder->private_->frame.header.sample_rate;
  89316. decoder->protected_->blocksize = decoder->private_->frame.header.blocksize;
  89317. FLAC__ASSERT(decoder->private_->frame.header.number_type == FLAC__FRAME_NUMBER_TYPE_SAMPLE_NUMBER);
  89318. decoder->private_->samples_decoded = decoder->private_->frame.header.number.sample_number + decoder->private_->frame.header.blocksize;
  89319. if(do_full_decode) {
  89320. if(write_audio_frame_to_client_(decoder, &decoder->private_->frame, (const FLAC__int32 * const *)decoder->private_->output) != FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE)
  89321. return false;
  89322. }
  89323. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  89324. return true;
  89325. }
  89326. FLAC__bool read_frame_header_(FLAC__StreamDecoder *decoder)
  89327. {
  89328. FLAC__uint32 x;
  89329. FLAC__uint64 xx;
  89330. unsigned i, blocksize_hint = 0, sample_rate_hint = 0;
  89331. FLAC__byte crc8, raw_header[16]; /* MAGIC NUMBER based on the maximum frame header size, including CRC */
  89332. unsigned raw_header_len;
  89333. FLAC__bool is_unparseable = false;
  89334. FLAC__ASSERT(FLAC__bitreader_is_consumed_byte_aligned(decoder->private_->input));
  89335. raw_header[0] = decoder->private_->header_warmup[0];
  89336. raw_header[1] = decoder->private_->header_warmup[1];
  89337. raw_header_len = 2;
  89338. if(raw_header[1] & 0x02) /* MAGIC NUMBER */
  89339. is_unparseable = true;
  89340. for(i = 0; i < 2; i++) {
  89341. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, 8))
  89342. return false; /* read_callback_ sets the state for us */
  89343. if(x == 0xff) { /* MAGIC NUMBER for the first 8 frame sync bits */
  89344. decoder->private_->lookahead = (FLAC__byte)x;
  89345. decoder->private_->cached = true;
  89346. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_BAD_HEADER);
  89347. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  89348. return true;
  89349. }
  89350. raw_header[raw_header_len++] = (FLAC__byte)x;
  89351. }
  89352. switch(x = raw_header[2] >> 4) {
  89353. case 0:
  89354. is_unparseable = true;
  89355. break;
  89356. case 1:
  89357. decoder->private_->frame.header.blocksize = 192;
  89358. break;
  89359. case 2:
  89360. case 3:
  89361. case 4:
  89362. case 5:
  89363. decoder->private_->frame.header.blocksize = 576 << (x-2);
  89364. break;
  89365. case 6:
  89366. case 7:
  89367. blocksize_hint = x;
  89368. break;
  89369. case 8:
  89370. case 9:
  89371. case 10:
  89372. case 11:
  89373. case 12:
  89374. case 13:
  89375. case 14:
  89376. case 15:
  89377. decoder->private_->frame.header.blocksize = 256 << (x-8);
  89378. break;
  89379. default:
  89380. FLAC__ASSERT(0);
  89381. break;
  89382. }
  89383. switch(x = raw_header[2] & 0x0f) {
  89384. case 0:
  89385. if(decoder->private_->has_stream_info)
  89386. decoder->private_->frame.header.sample_rate = decoder->private_->stream_info.data.stream_info.sample_rate;
  89387. else
  89388. is_unparseable = true;
  89389. break;
  89390. case 1:
  89391. decoder->private_->frame.header.sample_rate = 88200;
  89392. break;
  89393. case 2:
  89394. decoder->private_->frame.header.sample_rate = 176400;
  89395. break;
  89396. case 3:
  89397. decoder->private_->frame.header.sample_rate = 192000;
  89398. break;
  89399. case 4:
  89400. decoder->private_->frame.header.sample_rate = 8000;
  89401. break;
  89402. case 5:
  89403. decoder->private_->frame.header.sample_rate = 16000;
  89404. break;
  89405. case 6:
  89406. decoder->private_->frame.header.sample_rate = 22050;
  89407. break;
  89408. case 7:
  89409. decoder->private_->frame.header.sample_rate = 24000;
  89410. break;
  89411. case 8:
  89412. decoder->private_->frame.header.sample_rate = 32000;
  89413. break;
  89414. case 9:
  89415. decoder->private_->frame.header.sample_rate = 44100;
  89416. break;
  89417. case 10:
  89418. decoder->private_->frame.header.sample_rate = 48000;
  89419. break;
  89420. case 11:
  89421. decoder->private_->frame.header.sample_rate = 96000;
  89422. break;
  89423. case 12:
  89424. case 13:
  89425. case 14:
  89426. sample_rate_hint = x;
  89427. break;
  89428. case 15:
  89429. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_BAD_HEADER);
  89430. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  89431. return true;
  89432. default:
  89433. FLAC__ASSERT(0);
  89434. }
  89435. x = (unsigned)(raw_header[3] >> 4);
  89436. if(x & 8) {
  89437. decoder->private_->frame.header.channels = 2;
  89438. switch(x & 7) {
  89439. case 0:
  89440. decoder->private_->frame.header.channel_assignment = FLAC__CHANNEL_ASSIGNMENT_LEFT_SIDE;
  89441. break;
  89442. case 1:
  89443. decoder->private_->frame.header.channel_assignment = FLAC__CHANNEL_ASSIGNMENT_RIGHT_SIDE;
  89444. break;
  89445. case 2:
  89446. decoder->private_->frame.header.channel_assignment = FLAC__CHANNEL_ASSIGNMENT_MID_SIDE;
  89447. break;
  89448. default:
  89449. is_unparseable = true;
  89450. break;
  89451. }
  89452. }
  89453. else {
  89454. decoder->private_->frame.header.channels = (unsigned)x + 1;
  89455. decoder->private_->frame.header.channel_assignment = FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT;
  89456. }
  89457. switch(x = (unsigned)(raw_header[3] & 0x0e) >> 1) {
  89458. case 0:
  89459. if(decoder->private_->has_stream_info)
  89460. decoder->private_->frame.header.bits_per_sample = decoder->private_->stream_info.data.stream_info.bits_per_sample;
  89461. else
  89462. is_unparseable = true;
  89463. break;
  89464. case 1:
  89465. decoder->private_->frame.header.bits_per_sample = 8;
  89466. break;
  89467. case 2:
  89468. decoder->private_->frame.header.bits_per_sample = 12;
  89469. break;
  89470. case 4:
  89471. decoder->private_->frame.header.bits_per_sample = 16;
  89472. break;
  89473. case 5:
  89474. decoder->private_->frame.header.bits_per_sample = 20;
  89475. break;
  89476. case 6:
  89477. decoder->private_->frame.header.bits_per_sample = 24;
  89478. break;
  89479. case 3:
  89480. case 7:
  89481. is_unparseable = true;
  89482. break;
  89483. default:
  89484. FLAC__ASSERT(0);
  89485. break;
  89486. }
  89487. if(raw_header[3] & 0x01) /* MAGIC NUMBER */
  89488. is_unparseable = true;
  89489. if(
  89490. raw_header[1] & 0x01 ||
  89491. (decoder->private_->has_stream_info && decoder->private_->stream_info.data.stream_info.min_blocksize != decoder->private_->stream_info.data.stream_info.max_blocksize)
  89492. ) { /* variable blocksize */
  89493. if(!FLAC__bitreader_read_utf8_uint64(decoder->private_->input, &xx, raw_header, &raw_header_len))
  89494. return false; /* read_callback_ sets the state for us */
  89495. if(xx == FLAC__U64L(0xffffffffffffffff)) { /* i.e. non-UTF8 code... */
  89496. decoder->private_->lookahead = raw_header[raw_header_len-1]; /* back up as much as we can */
  89497. decoder->private_->cached = true;
  89498. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_BAD_HEADER);
  89499. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  89500. return true;
  89501. }
  89502. decoder->private_->frame.header.number_type = FLAC__FRAME_NUMBER_TYPE_SAMPLE_NUMBER;
  89503. decoder->private_->frame.header.number.sample_number = xx;
  89504. }
  89505. else { /* fixed blocksize */
  89506. if(!FLAC__bitreader_read_utf8_uint32(decoder->private_->input, &x, raw_header, &raw_header_len))
  89507. return false; /* read_callback_ sets the state for us */
  89508. if(x == 0xffffffff) { /* i.e. non-UTF8 code... */
  89509. decoder->private_->lookahead = raw_header[raw_header_len-1]; /* back up as much as we can */
  89510. decoder->private_->cached = true;
  89511. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_BAD_HEADER);
  89512. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  89513. return true;
  89514. }
  89515. decoder->private_->frame.header.number_type = FLAC__FRAME_NUMBER_TYPE_FRAME_NUMBER;
  89516. decoder->private_->frame.header.number.frame_number = x;
  89517. }
  89518. if(blocksize_hint) {
  89519. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, 8))
  89520. return false; /* read_callback_ sets the state for us */
  89521. raw_header[raw_header_len++] = (FLAC__byte)x;
  89522. if(blocksize_hint == 7) {
  89523. FLAC__uint32 _x;
  89524. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &_x, 8))
  89525. return false; /* read_callback_ sets the state for us */
  89526. raw_header[raw_header_len++] = (FLAC__byte)_x;
  89527. x = (x << 8) | _x;
  89528. }
  89529. decoder->private_->frame.header.blocksize = x+1;
  89530. }
  89531. if(sample_rate_hint) {
  89532. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, 8))
  89533. return false; /* read_callback_ sets the state for us */
  89534. raw_header[raw_header_len++] = (FLAC__byte)x;
  89535. if(sample_rate_hint != 12) {
  89536. FLAC__uint32 _x;
  89537. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &_x, 8))
  89538. return false; /* read_callback_ sets the state for us */
  89539. raw_header[raw_header_len++] = (FLAC__byte)_x;
  89540. x = (x << 8) | _x;
  89541. }
  89542. if(sample_rate_hint == 12)
  89543. decoder->private_->frame.header.sample_rate = x*1000;
  89544. else if(sample_rate_hint == 13)
  89545. decoder->private_->frame.header.sample_rate = x;
  89546. else
  89547. decoder->private_->frame.header.sample_rate = x*10;
  89548. }
  89549. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, 8))
  89550. return false; /* read_callback_ sets the state for us */
  89551. crc8 = (FLAC__byte)x;
  89552. if(FLAC__crc8(raw_header, raw_header_len) != crc8) {
  89553. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_BAD_HEADER);
  89554. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  89555. return true;
  89556. }
  89557. decoder->private_->next_fixed_block_size = 0;
  89558. if(decoder->private_->frame.header.number_type == FLAC__FRAME_NUMBER_TYPE_FRAME_NUMBER) {
  89559. x = decoder->private_->frame.header.number.frame_number;
  89560. decoder->private_->frame.header.number_type = FLAC__FRAME_NUMBER_TYPE_SAMPLE_NUMBER;
  89561. if(decoder->private_->fixed_block_size)
  89562. decoder->private_->frame.header.number.sample_number = (FLAC__uint64)decoder->private_->fixed_block_size * (FLAC__uint64)x;
  89563. else if(decoder->private_->has_stream_info) {
  89564. if(decoder->private_->stream_info.data.stream_info.min_blocksize == decoder->private_->stream_info.data.stream_info.max_blocksize) {
  89565. decoder->private_->frame.header.number.sample_number = (FLAC__uint64)decoder->private_->stream_info.data.stream_info.min_blocksize * (FLAC__uint64)x;
  89566. decoder->private_->next_fixed_block_size = decoder->private_->stream_info.data.stream_info.max_blocksize;
  89567. }
  89568. else
  89569. is_unparseable = true;
  89570. }
  89571. else if(x == 0) {
  89572. decoder->private_->frame.header.number.sample_number = 0;
  89573. decoder->private_->next_fixed_block_size = decoder->private_->frame.header.blocksize;
  89574. }
  89575. else {
  89576. decoder->private_->frame.header.number.sample_number = (FLAC__uint64)decoder->private_->frame.header.blocksize * (FLAC__uint64)x;
  89577. }
  89578. }
  89579. if(is_unparseable) {
  89580. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_UNPARSEABLE_STREAM);
  89581. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  89582. return true;
  89583. }
  89584. return true;
  89585. }
  89586. FLAC__bool read_subframe_(FLAC__StreamDecoder *decoder, unsigned channel, unsigned bps, FLAC__bool do_full_decode)
  89587. {
  89588. FLAC__uint32 x;
  89589. FLAC__bool wasted_bits;
  89590. unsigned i;
  89591. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, 8)) /* MAGIC NUMBER */
  89592. return false; /* read_callback_ sets the state for us */
  89593. wasted_bits = (x & 1);
  89594. x &= 0xfe;
  89595. if(wasted_bits) {
  89596. unsigned u;
  89597. if(!FLAC__bitreader_read_unary_unsigned(decoder->private_->input, &u))
  89598. return false; /* read_callback_ sets the state for us */
  89599. decoder->private_->frame.subframes[channel].wasted_bits = u+1;
  89600. bps -= decoder->private_->frame.subframes[channel].wasted_bits;
  89601. }
  89602. else
  89603. decoder->private_->frame.subframes[channel].wasted_bits = 0;
  89604. if(x & 0x80) {
  89605. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC);
  89606. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  89607. return true;
  89608. }
  89609. else if(x == 0) {
  89610. if(!read_subframe_constant_(decoder, channel, bps, do_full_decode))
  89611. return false;
  89612. }
  89613. else if(x == 2) {
  89614. if(!read_subframe_verbatim_(decoder, channel, bps, do_full_decode))
  89615. return false;
  89616. }
  89617. else if(x < 16) {
  89618. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_UNPARSEABLE_STREAM);
  89619. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  89620. return true;
  89621. }
  89622. else if(x <= 24) {
  89623. if(!read_subframe_fixed_(decoder, channel, bps, (x>>1)&7, do_full_decode))
  89624. return false;
  89625. if(decoder->protected_->state == FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC) /* means bad sync or got corruption */
  89626. return true;
  89627. }
  89628. else if(x < 64) {
  89629. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_UNPARSEABLE_STREAM);
  89630. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  89631. return true;
  89632. }
  89633. else {
  89634. if(!read_subframe_lpc_(decoder, channel, bps, ((x>>1)&31)+1, do_full_decode))
  89635. return false;
  89636. if(decoder->protected_->state == FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC) /* means bad sync or got corruption */
  89637. return true;
  89638. }
  89639. if(wasted_bits && do_full_decode) {
  89640. x = decoder->private_->frame.subframes[channel].wasted_bits;
  89641. for(i = 0; i < decoder->private_->frame.header.blocksize; i++)
  89642. decoder->private_->output[channel][i] <<= x;
  89643. }
  89644. return true;
  89645. }
  89646. FLAC__bool read_subframe_constant_(FLAC__StreamDecoder *decoder, unsigned channel, unsigned bps, FLAC__bool do_full_decode)
  89647. {
  89648. FLAC__Subframe_Constant *subframe = &decoder->private_->frame.subframes[channel].data.constant;
  89649. FLAC__int32 x;
  89650. unsigned i;
  89651. FLAC__int32 *output = decoder->private_->output[channel];
  89652. decoder->private_->frame.subframes[channel].type = FLAC__SUBFRAME_TYPE_CONSTANT;
  89653. if(!FLAC__bitreader_read_raw_int32(decoder->private_->input, &x, bps))
  89654. return false; /* read_callback_ sets the state for us */
  89655. subframe->value = x;
  89656. if(do_full_decode) {
  89657. for(i = 0; i < decoder->private_->frame.header.blocksize; i++)
  89658. output[i] = x;
  89659. }
  89660. return true;
  89661. }
  89662. FLAC__bool read_subframe_fixed_(FLAC__StreamDecoder *decoder, unsigned channel, unsigned bps, const unsigned order, FLAC__bool do_full_decode)
  89663. {
  89664. FLAC__Subframe_Fixed *subframe = &decoder->private_->frame.subframes[channel].data.fixed;
  89665. FLAC__int32 i32;
  89666. FLAC__uint32 u32;
  89667. unsigned u;
  89668. decoder->private_->frame.subframes[channel].type = FLAC__SUBFRAME_TYPE_FIXED;
  89669. subframe->residual = decoder->private_->residual[channel];
  89670. subframe->order = order;
  89671. for(u = 0; u < order; u++) {
  89672. if(!FLAC__bitreader_read_raw_int32(decoder->private_->input, &i32, bps))
  89673. return false; /* read_callback_ sets the state for us */
  89674. subframe->warmup[u] = i32;
  89675. }
  89676. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &u32, FLAC__ENTROPY_CODING_METHOD_TYPE_LEN))
  89677. return false; /* read_callback_ sets the state for us */
  89678. subframe->entropy_coding_method.type = (FLAC__EntropyCodingMethodType)u32;
  89679. switch(subframe->entropy_coding_method.type) {
  89680. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE:
  89681. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2:
  89682. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &u32, FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ORDER_LEN))
  89683. return false; /* read_callback_ sets the state for us */
  89684. subframe->entropy_coding_method.data.partitioned_rice.order = u32;
  89685. subframe->entropy_coding_method.data.partitioned_rice.contents = &decoder->private_->partitioned_rice_contents[channel];
  89686. break;
  89687. default:
  89688. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_UNPARSEABLE_STREAM);
  89689. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  89690. return true;
  89691. }
  89692. switch(subframe->entropy_coding_method.type) {
  89693. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE:
  89694. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2:
  89695. 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))
  89696. return false;
  89697. break;
  89698. default:
  89699. FLAC__ASSERT(0);
  89700. }
  89701. if(do_full_decode) {
  89702. memcpy(decoder->private_->output[channel], subframe->warmup, sizeof(FLAC__int32) * order);
  89703. FLAC__fixed_restore_signal(decoder->private_->residual[channel], decoder->private_->frame.header.blocksize-order, order, decoder->private_->output[channel]+order);
  89704. }
  89705. return true;
  89706. }
  89707. FLAC__bool read_subframe_lpc_(FLAC__StreamDecoder *decoder, unsigned channel, unsigned bps, const unsigned order, FLAC__bool do_full_decode)
  89708. {
  89709. FLAC__Subframe_LPC *subframe = &decoder->private_->frame.subframes[channel].data.lpc;
  89710. FLAC__int32 i32;
  89711. FLAC__uint32 u32;
  89712. unsigned u;
  89713. decoder->private_->frame.subframes[channel].type = FLAC__SUBFRAME_TYPE_LPC;
  89714. subframe->residual = decoder->private_->residual[channel];
  89715. subframe->order = order;
  89716. for(u = 0; u < order; u++) {
  89717. if(!FLAC__bitreader_read_raw_int32(decoder->private_->input, &i32, bps))
  89718. return false; /* read_callback_ sets the state for us */
  89719. subframe->warmup[u] = i32;
  89720. }
  89721. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &u32, FLAC__SUBFRAME_LPC_QLP_COEFF_PRECISION_LEN))
  89722. return false; /* read_callback_ sets the state for us */
  89723. if(u32 == (1u << FLAC__SUBFRAME_LPC_QLP_COEFF_PRECISION_LEN) - 1) {
  89724. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC);
  89725. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  89726. return true;
  89727. }
  89728. subframe->qlp_coeff_precision = u32+1;
  89729. if(!FLAC__bitreader_read_raw_int32(decoder->private_->input, &i32, FLAC__SUBFRAME_LPC_QLP_SHIFT_LEN))
  89730. return false; /* read_callback_ sets the state for us */
  89731. subframe->quantization_level = i32;
  89732. for(u = 0; u < order; u++) {
  89733. if(!FLAC__bitreader_read_raw_int32(decoder->private_->input, &i32, subframe->qlp_coeff_precision))
  89734. return false; /* read_callback_ sets the state for us */
  89735. subframe->qlp_coeff[u] = i32;
  89736. }
  89737. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &u32, FLAC__ENTROPY_CODING_METHOD_TYPE_LEN))
  89738. return false; /* read_callback_ sets the state for us */
  89739. subframe->entropy_coding_method.type = (FLAC__EntropyCodingMethodType)u32;
  89740. switch(subframe->entropy_coding_method.type) {
  89741. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE:
  89742. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2:
  89743. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &u32, FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ORDER_LEN))
  89744. return false; /* read_callback_ sets the state for us */
  89745. subframe->entropy_coding_method.data.partitioned_rice.order = u32;
  89746. subframe->entropy_coding_method.data.partitioned_rice.contents = &decoder->private_->partitioned_rice_contents[channel];
  89747. break;
  89748. default:
  89749. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_UNPARSEABLE_STREAM);
  89750. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  89751. return true;
  89752. }
  89753. switch(subframe->entropy_coding_method.type) {
  89754. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE:
  89755. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2:
  89756. 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))
  89757. return false;
  89758. break;
  89759. default:
  89760. FLAC__ASSERT(0);
  89761. }
  89762. if(do_full_decode) {
  89763. memcpy(decoder->private_->output[channel], subframe->warmup, sizeof(FLAC__int32) * order);
  89764. if(bps + subframe->qlp_coeff_precision + FLAC__bitmath_ilog2(order) <= 32)
  89765. if(bps <= 16 && subframe->qlp_coeff_precision <= 16) {
  89766. if(order <= 8)
  89767. 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);
  89768. else
  89769. 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);
  89770. }
  89771. else
  89772. 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);
  89773. else
  89774. 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);
  89775. }
  89776. return true;
  89777. }
  89778. FLAC__bool read_subframe_verbatim_(FLAC__StreamDecoder *decoder, unsigned channel, unsigned bps, FLAC__bool do_full_decode)
  89779. {
  89780. FLAC__Subframe_Verbatim *subframe = &decoder->private_->frame.subframes[channel].data.verbatim;
  89781. FLAC__int32 x, *residual = decoder->private_->residual[channel];
  89782. unsigned i;
  89783. decoder->private_->frame.subframes[channel].type = FLAC__SUBFRAME_TYPE_VERBATIM;
  89784. subframe->data = residual;
  89785. for(i = 0; i < decoder->private_->frame.header.blocksize; i++) {
  89786. if(!FLAC__bitreader_read_raw_int32(decoder->private_->input, &x, bps))
  89787. return false; /* read_callback_ sets the state for us */
  89788. residual[i] = x;
  89789. }
  89790. if(do_full_decode)
  89791. memcpy(decoder->private_->output[channel], subframe->data, sizeof(FLAC__int32) * decoder->private_->frame.header.blocksize);
  89792. return true;
  89793. }
  89794. 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)
  89795. {
  89796. FLAC__uint32 rice_parameter;
  89797. int i;
  89798. unsigned partition, sample, u;
  89799. const unsigned partitions = 1u << partition_order;
  89800. const unsigned partition_samples = partition_order > 0? decoder->private_->frame.header.blocksize >> partition_order : decoder->private_->frame.header.blocksize - predictor_order;
  89801. const unsigned plen = is_extended? FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_PARAMETER_LEN : FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_PARAMETER_LEN;
  89802. const unsigned pesc = is_extended? FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_ESCAPE_PARAMETER : FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ESCAPE_PARAMETER;
  89803. if(partition_order == 0) {
  89804. if(decoder->private_->frame.header.blocksize < predictor_order) {
  89805. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC);
  89806. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  89807. return true;
  89808. }
  89809. }
  89810. else {
  89811. if(partition_samples < predictor_order) {
  89812. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC);
  89813. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  89814. return true;
  89815. }
  89816. }
  89817. if(!FLAC__format_entropy_coding_method_partitioned_rice_contents_ensure_size(partitioned_rice_contents, max(6, partition_order))) {
  89818. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  89819. return false;
  89820. }
  89821. sample = 0;
  89822. for(partition = 0; partition < partitions; partition++) {
  89823. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &rice_parameter, plen))
  89824. return false; /* read_callback_ sets the state for us */
  89825. partitioned_rice_contents->parameters[partition] = rice_parameter;
  89826. if(rice_parameter < pesc) {
  89827. partitioned_rice_contents->raw_bits[partition] = 0;
  89828. u = (partition_order == 0 || partition > 0)? partition_samples : partition_samples - predictor_order;
  89829. if(!decoder->private_->local_bitreader_read_rice_signed_block(decoder->private_->input, (int*) residual + sample, u, rice_parameter))
  89830. return false; /* read_callback_ sets the state for us */
  89831. sample += u;
  89832. }
  89833. else {
  89834. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &rice_parameter, FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_RAW_LEN))
  89835. return false; /* read_callback_ sets the state for us */
  89836. partitioned_rice_contents->raw_bits[partition] = rice_parameter;
  89837. for(u = (partition_order == 0 || partition > 0)? 0 : predictor_order; u < partition_samples; u++, sample++) {
  89838. if(!FLAC__bitreader_read_raw_int32(decoder->private_->input, (FLAC__int32*) &i, rice_parameter))
  89839. return false; /* read_callback_ sets the state for us */
  89840. residual[sample] = i;
  89841. }
  89842. }
  89843. }
  89844. return true;
  89845. }
  89846. FLAC__bool read_zero_padding_(FLAC__StreamDecoder *decoder)
  89847. {
  89848. if(!FLAC__bitreader_is_consumed_byte_aligned(decoder->private_->input)) {
  89849. FLAC__uint32 zero = 0;
  89850. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &zero, FLAC__bitreader_bits_left_for_byte_alignment(decoder->private_->input)))
  89851. return false; /* read_callback_ sets the state for us */
  89852. if(zero != 0) {
  89853. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC);
  89854. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  89855. }
  89856. }
  89857. return true;
  89858. }
  89859. FLAC__bool read_callback_(FLAC__byte buffer[], size_t *bytes, void *client_data)
  89860. {
  89861. FLAC__StreamDecoder *decoder = (FLAC__StreamDecoder *)client_data;
  89862. if(
  89863. #if FLAC__HAS_OGG
  89864. !decoder->private_->is_ogg &&
  89865. #endif
  89866. decoder->private_->eof_callback && decoder->private_->eof_callback(decoder, decoder->private_->client_data)
  89867. ) {
  89868. *bytes = 0;
  89869. decoder->protected_->state = FLAC__STREAM_DECODER_END_OF_STREAM;
  89870. return false;
  89871. }
  89872. else if(*bytes > 0) {
  89873. if(decoder->private_->is_seeking && decoder->private_->unparseable_frame_count > 20) {
  89874. decoder->protected_->state = FLAC__STREAM_DECODER_ABORTED;
  89875. return false;
  89876. }
  89877. else {
  89878. const FLAC__StreamDecoderReadStatus status =
  89879. #if FLAC__HAS_OGG
  89880. decoder->private_->is_ogg?
  89881. read_callback_ogg_aspect_(decoder, buffer, bytes) :
  89882. #endif
  89883. decoder->private_->read_callback(decoder, buffer, bytes, decoder->private_->client_data)
  89884. ;
  89885. if(status == FLAC__STREAM_DECODER_READ_STATUS_ABORT) {
  89886. decoder->protected_->state = FLAC__STREAM_DECODER_ABORTED;
  89887. return false;
  89888. }
  89889. else if(*bytes == 0) {
  89890. if(
  89891. status == FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM ||
  89892. (
  89893. #if FLAC__HAS_OGG
  89894. !decoder->private_->is_ogg &&
  89895. #endif
  89896. decoder->private_->eof_callback && decoder->private_->eof_callback(decoder, decoder->private_->client_data)
  89897. )
  89898. ) {
  89899. decoder->protected_->state = FLAC__STREAM_DECODER_END_OF_STREAM;
  89900. return false;
  89901. }
  89902. else
  89903. return true;
  89904. }
  89905. else
  89906. return true;
  89907. }
  89908. }
  89909. else {
  89910. decoder->protected_->state = FLAC__STREAM_DECODER_ABORTED;
  89911. return false;
  89912. }
  89913. }
  89914. #if FLAC__HAS_OGG
  89915. FLAC__StreamDecoderReadStatus read_callback_ogg_aspect_(const FLAC__StreamDecoder *decoder, FLAC__byte buffer[], size_t *bytes)
  89916. {
  89917. switch(FLAC__ogg_decoder_aspect_read_callback_wrapper(&decoder->protected_->ogg_decoder_aspect, buffer, bytes, read_callback_proxy_, decoder, decoder->private_->client_data)) {
  89918. case FLAC__OGG_DECODER_ASPECT_READ_STATUS_OK:
  89919. return FLAC__STREAM_DECODER_READ_STATUS_CONTINUE;
  89920. case FLAC__OGG_DECODER_ASPECT_READ_STATUS_LOST_SYNC:
  89921. return FLAC__STREAM_DECODER_READ_STATUS_CONTINUE;
  89922. case FLAC__OGG_DECODER_ASPECT_READ_STATUS_END_OF_STREAM:
  89923. return FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM;
  89924. case FLAC__OGG_DECODER_ASPECT_READ_STATUS_NOT_FLAC:
  89925. case FLAC__OGG_DECODER_ASPECT_READ_STATUS_UNSUPPORTED_MAPPING_VERSION:
  89926. case FLAC__OGG_DECODER_ASPECT_READ_STATUS_ABORT:
  89927. case FLAC__OGG_DECODER_ASPECT_READ_STATUS_ERROR:
  89928. case FLAC__OGG_DECODER_ASPECT_READ_STATUS_MEMORY_ALLOCATION_ERROR:
  89929. return FLAC__STREAM_DECODER_READ_STATUS_ABORT;
  89930. default:
  89931. FLAC__ASSERT(0);
  89932. return FLAC__STREAM_DECODER_READ_STATUS_ABORT;
  89933. }
  89934. }
  89935. FLAC__OggDecoderAspectReadStatus read_callback_proxy_(const void *void_decoder, FLAC__byte buffer[], size_t *bytes, void *client_data)
  89936. {
  89937. FLAC__StreamDecoder *decoder = (FLAC__StreamDecoder*)void_decoder;
  89938. switch(decoder->private_->read_callback(decoder, buffer, bytes, client_data)) {
  89939. case FLAC__STREAM_DECODER_READ_STATUS_CONTINUE:
  89940. return FLAC__OGG_DECODER_ASPECT_READ_STATUS_OK;
  89941. case FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM:
  89942. return FLAC__OGG_DECODER_ASPECT_READ_STATUS_END_OF_STREAM;
  89943. case FLAC__STREAM_DECODER_READ_STATUS_ABORT:
  89944. return FLAC__OGG_DECODER_ASPECT_READ_STATUS_ABORT;
  89945. default:
  89946. FLAC__ASSERT(0);
  89947. return FLAC__OGG_DECODER_ASPECT_READ_STATUS_ABORT;
  89948. }
  89949. }
  89950. #endif
  89951. FLAC__StreamDecoderWriteStatus write_audio_frame_to_client_(FLAC__StreamDecoder *decoder, const FLAC__Frame *frame, const FLAC__int32 * const buffer[])
  89952. {
  89953. if(decoder->private_->is_seeking) {
  89954. FLAC__uint64 this_frame_sample = frame->header.number.sample_number;
  89955. FLAC__uint64 next_frame_sample = this_frame_sample + (FLAC__uint64)frame->header.blocksize;
  89956. FLAC__uint64 target_sample = decoder->private_->target_sample;
  89957. FLAC__ASSERT(frame->header.number_type == FLAC__FRAME_NUMBER_TYPE_SAMPLE_NUMBER);
  89958. #if FLAC__HAS_OGG
  89959. decoder->private_->got_a_frame = true;
  89960. #endif
  89961. decoder->private_->last_frame = *frame; /* save the frame */
  89962. if(this_frame_sample <= target_sample && target_sample < next_frame_sample) { /* we hit our target frame */
  89963. unsigned delta = (unsigned)(target_sample - this_frame_sample);
  89964. decoder->private_->is_seeking = false;
  89965. if(delta > 0) {
  89966. unsigned channel;
  89967. const FLAC__int32 *newbuffer[FLAC__MAX_CHANNELS];
  89968. for(channel = 0; channel < frame->header.channels; channel++)
  89969. newbuffer[channel] = buffer[channel] + delta;
  89970. decoder->private_->last_frame.header.blocksize -= delta;
  89971. decoder->private_->last_frame.header.number.sample_number += (FLAC__uint64)delta;
  89972. return decoder->private_->write_callback(decoder, &decoder->private_->last_frame, newbuffer, decoder->private_->client_data);
  89973. }
  89974. else {
  89975. return decoder->private_->write_callback(decoder, frame, buffer, decoder->private_->client_data);
  89976. }
  89977. }
  89978. return FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE;
  89979. }
  89980. if(!decoder->private_->has_stream_info)
  89981. decoder->private_->do_md5_checking = false;
  89982. if(decoder->private_->do_md5_checking) {
  89983. if(!FLAC__MD5Accumulate(&decoder->private_->md5context, buffer, frame->header.channels, frame->header.blocksize, (frame->header.bits_per_sample+7) / 8))
  89984. return FLAC__STREAM_DECODER_WRITE_STATUS_ABORT;
  89985. }
  89986. return decoder->private_->write_callback(decoder, frame, buffer, decoder->private_->client_data);
  89987. }
  89988. void send_error_to_client_(const FLAC__StreamDecoder *decoder, FLAC__StreamDecoderErrorStatus status)
  89989. {
  89990. if(!decoder->private_->is_seeking)
  89991. decoder->private_->error_callback(decoder, status, decoder->private_->client_data);
  89992. else if(status == FLAC__STREAM_DECODER_ERROR_STATUS_UNPARSEABLE_STREAM)
  89993. decoder->private_->unparseable_frame_count++;
  89994. }
  89995. FLAC__bool seek_to_absolute_sample_(FLAC__StreamDecoder *decoder, FLAC__uint64 stream_length, FLAC__uint64 target_sample)
  89996. {
  89997. FLAC__uint64 first_frame_offset = decoder->private_->first_frame_offset, lower_bound, upper_bound, lower_bound_sample, upper_bound_sample, this_frame_sample;
  89998. FLAC__int64 pos = -1;
  89999. int i;
  90000. unsigned approx_bytes_per_frame;
  90001. FLAC__bool first_seek = true;
  90002. const FLAC__uint64 total_samples = FLAC__stream_decoder_get_total_samples(decoder);
  90003. const unsigned min_blocksize = decoder->private_->stream_info.data.stream_info.min_blocksize;
  90004. const unsigned max_blocksize = decoder->private_->stream_info.data.stream_info.max_blocksize;
  90005. const unsigned max_framesize = decoder->private_->stream_info.data.stream_info.max_framesize;
  90006. const unsigned min_framesize = decoder->private_->stream_info.data.stream_info.min_framesize;
  90007. unsigned channels = FLAC__stream_decoder_get_channels(decoder);
  90008. unsigned bps = FLAC__stream_decoder_get_bits_per_sample(decoder);
  90009. const FLAC__StreamMetadata_SeekTable *seek_table = decoder->private_->has_seek_table? &decoder->private_->seek_table.data.seek_table : 0;
  90010. if(channels == 0)
  90011. channels = decoder->private_->stream_info.data.stream_info.channels;
  90012. if(bps == 0)
  90013. bps = decoder->private_->stream_info.data.stream_info.bits_per_sample;
  90014. if(max_framesize > 0)
  90015. approx_bytes_per_frame = (max_framesize + min_framesize) / 2 + 1;
  90016. else if(min_blocksize == max_blocksize && min_blocksize > 0) {
  90017. approx_bytes_per_frame = min_blocksize * channels * bps/8 + 64;
  90018. }
  90019. else
  90020. approx_bytes_per_frame = 4096 * channels * bps/8 + 64;
  90021. lower_bound = first_frame_offset;
  90022. lower_bound_sample = 0;
  90023. upper_bound = stream_length;
  90024. upper_bound_sample = total_samples > 0 ? total_samples : target_sample /*estimate it*/;
  90025. if(seek_table) {
  90026. FLAC__uint64 new_lower_bound = lower_bound;
  90027. FLAC__uint64 new_upper_bound = upper_bound;
  90028. FLAC__uint64 new_lower_bound_sample = lower_bound_sample;
  90029. FLAC__uint64 new_upper_bound_sample = upper_bound_sample;
  90030. for(i = (int)seek_table->num_points - 1; i >= 0; i--) {
  90031. if(
  90032. seek_table->points[i].sample_number != FLAC__STREAM_METADATA_SEEKPOINT_PLACEHOLDER &&
  90033. seek_table->points[i].frame_samples > 0 && /* defense against bad seekpoints */
  90034. (total_samples <= 0 || seek_table->points[i].sample_number < total_samples) && /* defense against bad seekpoints */
  90035. seek_table->points[i].sample_number <= target_sample
  90036. )
  90037. break;
  90038. }
  90039. if(i >= 0) { /* i.e. we found a suitable seek point... */
  90040. new_lower_bound = first_frame_offset + seek_table->points[i].stream_offset;
  90041. new_lower_bound_sample = seek_table->points[i].sample_number;
  90042. }
  90043. for(i = 0; i < (int)seek_table->num_points; i++) {
  90044. if(
  90045. seek_table->points[i].sample_number != FLAC__STREAM_METADATA_SEEKPOINT_PLACEHOLDER &&
  90046. seek_table->points[i].frame_samples > 0 && /* defense against bad seekpoints */
  90047. (total_samples <= 0 || seek_table->points[i].sample_number < total_samples) && /* defense against bad seekpoints */
  90048. seek_table->points[i].sample_number > target_sample
  90049. )
  90050. break;
  90051. }
  90052. if(i < (int)seek_table->num_points) { /* i.e. we found a suitable seek point... */
  90053. new_upper_bound = first_frame_offset + seek_table->points[i].stream_offset;
  90054. new_upper_bound_sample = seek_table->points[i].sample_number;
  90055. }
  90056. if(new_upper_bound >= new_lower_bound) {
  90057. lower_bound = new_lower_bound;
  90058. upper_bound = new_upper_bound;
  90059. lower_bound_sample = new_lower_bound_sample;
  90060. upper_bound_sample = new_upper_bound_sample;
  90061. }
  90062. }
  90063. FLAC__ASSERT(upper_bound_sample >= lower_bound_sample);
  90064. if(upper_bound_sample == lower_bound_sample)
  90065. upper_bound_sample++;
  90066. decoder->private_->target_sample = target_sample;
  90067. while(1) {
  90068. if (lower_bound_sample >= upper_bound_sample || lower_bound > upper_bound) {
  90069. decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR;
  90070. return false;
  90071. }
  90072. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  90073. #if defined _MSC_VER || defined __MINGW32__
  90074. 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;
  90075. #else
  90076. 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;
  90077. #endif
  90078. #else
  90079. if(upper_bound - lower_bound < 0xffffffff)
  90080. 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;
  90081. else /* @@@ WATCHOUT, ~2TB limit */
  90082. 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;
  90083. #endif
  90084. if(pos >= (FLAC__int64)upper_bound)
  90085. pos = (FLAC__int64)upper_bound - 1;
  90086. if(pos < (FLAC__int64)lower_bound)
  90087. pos = (FLAC__int64)lower_bound;
  90088. if(decoder->private_->seek_callback(decoder, (FLAC__uint64)pos, decoder->private_->client_data) != FLAC__STREAM_DECODER_SEEK_STATUS_OK) {
  90089. decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR;
  90090. return false;
  90091. }
  90092. if(!FLAC__stream_decoder_flush(decoder)) {
  90093. return false;
  90094. }
  90095. decoder->private_->unparseable_frame_count = 0;
  90096. if(!FLAC__stream_decoder_process_single(decoder)) {
  90097. decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR;
  90098. return false;
  90099. }
  90100. #if 0
  90101. if(decoder->protected_->state != FLAC__SEEKABLE_STREAM_DECODER_SEEKING && decoder->protected_->state != FLAC__STREAM_DECODER_END_OF_STREAM)
  90102. break;
  90103. #endif
  90104. if(!decoder->private_->is_seeking)
  90105. break;
  90106. FLAC__ASSERT(decoder->private_->last_frame.header.number_type == FLAC__FRAME_NUMBER_TYPE_SAMPLE_NUMBER);
  90107. this_frame_sample = decoder->private_->last_frame.header.number.sample_number;
  90108. if (0 == decoder->private_->samples_decoded || (this_frame_sample + decoder->private_->last_frame.header.blocksize >= upper_bound_sample && !first_seek)) {
  90109. if (pos == (FLAC__int64)lower_bound) {
  90110. decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR;
  90111. return false;
  90112. }
  90113. approx_bytes_per_frame = approx_bytes_per_frame? approx_bytes_per_frame * 2 : 16;
  90114. continue;
  90115. }
  90116. first_seek = false;
  90117. if (this_frame_sample < lower_bound_sample) {
  90118. decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR;
  90119. return false;
  90120. }
  90121. if(target_sample < this_frame_sample) {
  90122. upper_bound_sample = this_frame_sample + decoder->private_->last_frame.header.blocksize;
  90123. if(!FLAC__stream_decoder_get_decode_position(decoder, &upper_bound)) {
  90124. decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR;
  90125. return false;
  90126. }
  90127. approx_bytes_per_frame = (unsigned)(2 * (upper_bound - pos) / 3 + 16);
  90128. }
  90129. else { /* target_sample >= this_frame_sample + this frame's blocksize */
  90130. lower_bound_sample = this_frame_sample + decoder->private_->last_frame.header.blocksize;
  90131. if(!FLAC__stream_decoder_get_decode_position(decoder, &lower_bound)) {
  90132. decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR;
  90133. return false;
  90134. }
  90135. approx_bytes_per_frame = (unsigned)(2 * (lower_bound - pos) / 3 + 16);
  90136. }
  90137. }
  90138. return true;
  90139. }
  90140. #if FLAC__HAS_OGG
  90141. FLAC__bool seek_to_absolute_sample_ogg_(FLAC__StreamDecoder *decoder, FLAC__uint64 stream_length, FLAC__uint64 target_sample)
  90142. {
  90143. FLAC__uint64 left_pos = 0, right_pos = stream_length;
  90144. FLAC__uint64 left_sample = 0, right_sample = FLAC__stream_decoder_get_total_samples(decoder);
  90145. FLAC__uint64 this_frame_sample = (FLAC__uint64)0 - 1;
  90146. FLAC__uint64 pos = 0; /* only initialized to avoid compiler warning */
  90147. FLAC__bool did_a_seek;
  90148. unsigned iteration = 0;
  90149. unsigned BINARY_SEARCH_AFTER_ITERATION = 2;
  90150. static const FLAC__uint64 LINEAR_SEARCH_WITHIN_SAMPLES = FLAC__MAX_BLOCK_SIZE * 2;
  90151. if(right_sample == 0) {
  90152. right_sample = (FLAC__uint64)(-1);
  90153. BINARY_SEARCH_AFTER_ITERATION = 0;
  90154. }
  90155. decoder->private_->target_sample = target_sample;
  90156. for( ; ; iteration++) {
  90157. if (iteration == 0 || this_frame_sample > target_sample || target_sample - this_frame_sample > LINEAR_SEARCH_WITHIN_SAMPLES) {
  90158. if (iteration >= BINARY_SEARCH_AFTER_ITERATION) {
  90159. pos = (right_pos + left_pos) / 2;
  90160. }
  90161. else {
  90162. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  90163. #if defined _MSC_VER || defined __MINGW32__
  90164. 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));
  90165. #else
  90166. pos = (FLAC__uint64)((FLAC__double)(target_sample - left_sample) / (FLAC__double)(right_sample - left_sample) * (FLAC__double)(right_pos - left_pos));
  90167. #endif
  90168. #else
  90169. if ((target_sample-left_sample <= 0xffffffff) && (right_pos-left_pos <= 0xffffffff))
  90170. pos = (FLAC__int64)(((target_sample-left_sample) * (right_pos-left_pos)) / (right_sample-left_sample));
  90171. else /* @@@ WATCHOUT, ~2TB limit */
  90172. pos = (FLAC__int64)((((target_sample-left_sample)>>8) * ((right_pos-left_pos)>>8)) / ((right_sample-left_sample)>>16));
  90173. #endif
  90174. }
  90175. if(decoder->private_->seek_callback((FLAC__StreamDecoder*)decoder, (FLAC__uint64)pos, decoder->private_->client_data) != FLAC__STREAM_DECODER_SEEK_STATUS_OK) {
  90176. decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR;
  90177. return false;
  90178. }
  90179. if(!FLAC__stream_decoder_flush(decoder)) {
  90180. return false;
  90181. }
  90182. did_a_seek = true;
  90183. }
  90184. else
  90185. did_a_seek = false;
  90186. decoder->private_->got_a_frame = false;
  90187. if(!FLAC__stream_decoder_process_single(decoder)) {
  90188. decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR;
  90189. return false;
  90190. }
  90191. if(!decoder->private_->got_a_frame) {
  90192. if(did_a_seek) {
  90193. right_pos = pos;
  90194. BINARY_SEARCH_AFTER_ITERATION = 0;
  90195. }
  90196. else {
  90197. decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR;
  90198. return false;
  90199. }
  90200. }
  90201. else if(!decoder->private_->is_seeking) {
  90202. break;
  90203. }
  90204. else {
  90205. this_frame_sample = decoder->private_->last_frame.header.number.sample_number;
  90206. FLAC__ASSERT(decoder->private_->last_frame.header.number_type == FLAC__FRAME_NUMBER_TYPE_SAMPLE_NUMBER);
  90207. if (did_a_seek) {
  90208. if (this_frame_sample <= target_sample) {
  90209. FLAC__ASSERT(this_frame_sample != target_sample);
  90210. left_sample = this_frame_sample;
  90211. if (left_pos == pos) {
  90212. decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR;
  90213. return false;
  90214. }
  90215. left_pos = pos;
  90216. }
  90217. else if(this_frame_sample > target_sample) {
  90218. right_sample = this_frame_sample;
  90219. if (right_pos == pos) {
  90220. decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR;
  90221. return false;
  90222. }
  90223. right_pos = pos;
  90224. }
  90225. }
  90226. }
  90227. }
  90228. return true;
  90229. }
  90230. #endif
  90231. FLAC__StreamDecoderReadStatus file_read_callback_dec(const FLAC__StreamDecoder *decoder, FLAC__byte buffer[], size_t *bytes, void *client_data)
  90232. {
  90233. (void)client_data;
  90234. if(*bytes > 0) {
  90235. *bytes = fread(buffer, sizeof(FLAC__byte), *bytes, decoder->private_->file);
  90236. if(ferror(decoder->private_->file))
  90237. return FLAC__STREAM_DECODER_READ_STATUS_ABORT;
  90238. else if(*bytes == 0)
  90239. return FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM;
  90240. else
  90241. return FLAC__STREAM_DECODER_READ_STATUS_CONTINUE;
  90242. }
  90243. else
  90244. return FLAC__STREAM_DECODER_READ_STATUS_ABORT; /* abort to avoid a deadlock */
  90245. }
  90246. FLAC__StreamDecoderSeekStatus file_seek_callback_dec(const FLAC__StreamDecoder *decoder, FLAC__uint64 absolute_byte_offset, void *client_data)
  90247. {
  90248. (void)client_data;
  90249. if(decoder->private_->file == stdin)
  90250. return FLAC__STREAM_DECODER_SEEK_STATUS_UNSUPPORTED;
  90251. else if(fseeko(decoder->private_->file, (off_t)absolute_byte_offset, SEEK_SET) < 0)
  90252. return FLAC__STREAM_DECODER_SEEK_STATUS_ERROR;
  90253. else
  90254. return FLAC__STREAM_DECODER_SEEK_STATUS_OK;
  90255. }
  90256. FLAC__StreamDecoderTellStatus file_tell_callback_dec(const FLAC__StreamDecoder *decoder, FLAC__uint64 *absolute_byte_offset, void *client_data)
  90257. {
  90258. off_t pos;
  90259. (void)client_data;
  90260. if(decoder->private_->file == stdin)
  90261. return FLAC__STREAM_DECODER_TELL_STATUS_UNSUPPORTED;
  90262. else if((pos = ftello(decoder->private_->file)) < 0)
  90263. return FLAC__STREAM_DECODER_TELL_STATUS_ERROR;
  90264. else {
  90265. *absolute_byte_offset = (FLAC__uint64)pos;
  90266. return FLAC__STREAM_DECODER_TELL_STATUS_OK;
  90267. }
  90268. }
  90269. FLAC__StreamDecoderLengthStatus file_length_callback_(const FLAC__StreamDecoder *decoder, FLAC__uint64 *stream_length, void *client_data)
  90270. {
  90271. struct stat filestats;
  90272. (void)client_data;
  90273. if(decoder->private_->file == stdin)
  90274. return FLAC__STREAM_DECODER_LENGTH_STATUS_UNSUPPORTED;
  90275. else if(fstat(fileno(decoder->private_->file), &filestats) != 0)
  90276. return FLAC__STREAM_DECODER_LENGTH_STATUS_ERROR;
  90277. else {
  90278. *stream_length = (FLAC__uint64)filestats.st_size;
  90279. return FLAC__STREAM_DECODER_LENGTH_STATUS_OK;
  90280. }
  90281. }
  90282. FLAC__bool file_eof_callback_(const FLAC__StreamDecoder *decoder, void *client_data)
  90283. {
  90284. (void)client_data;
  90285. return feof(decoder->private_->file)? true : false;
  90286. }
  90287. #endif
  90288. /********* End of inlined file: stream_decoder.c *********/
  90289. /********* Start of inlined file: stream_encoder.c *********/
  90290. /********* Start of inlined file: juce_FlacHeader.h *********/
  90291. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  90292. // tasks..
  90293. #define VERSION "1.2.1"
  90294. #define FLAC__NO_DLL 1
  90295. #if JUCE_MSVC
  90296. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  90297. #endif
  90298. #if JUCE_MAC
  90299. #define FLAC__SYS_DARWIN 1
  90300. #endif
  90301. /********* End of inlined file: juce_FlacHeader.h *********/
  90302. #if JUCE_USE_FLAC
  90303. #if HAVE_CONFIG_H
  90304. # include <config.h>
  90305. #endif
  90306. #if defined _MSC_VER || defined __MINGW32__
  90307. #include <io.h> /* for _setmode() */
  90308. #include <fcntl.h> /* for _O_BINARY */
  90309. #endif
  90310. #if defined __CYGWIN__ || defined __EMX__
  90311. #include <io.h> /* for setmode(), O_BINARY */
  90312. #include <fcntl.h> /* for _O_BINARY */
  90313. #endif
  90314. #include <limits.h>
  90315. #include <stdio.h>
  90316. #include <stdlib.h> /* for malloc() */
  90317. #include <string.h> /* for memcpy() */
  90318. #include <sys/types.h> /* for off_t */
  90319. #if defined _MSC_VER || defined __BORLANDC__ || defined __MINGW32__
  90320. #if _MSC_VER <= 1600 || defined __BORLANDC__ /* @@@ [2G limit] */
  90321. #define fseeko fseek
  90322. #define ftello ftell
  90323. #endif
  90324. #endif
  90325. /********* Start of inlined file: stream_encoder.h *********/
  90326. #ifndef FLAC__PROTECTED__STREAM_ENCODER_H
  90327. #define FLAC__PROTECTED__STREAM_ENCODER_H
  90328. #if FLAC__HAS_OGG
  90329. #include "private/ogg_encoder_aspect.h"
  90330. #endif
  90331. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  90332. #define FLAC__MAX_APODIZATION_FUNCTIONS 32
  90333. typedef enum {
  90334. FLAC__APODIZATION_BARTLETT,
  90335. FLAC__APODIZATION_BARTLETT_HANN,
  90336. FLAC__APODIZATION_BLACKMAN,
  90337. FLAC__APODIZATION_BLACKMAN_HARRIS_4TERM_92DB_SIDELOBE,
  90338. FLAC__APODIZATION_CONNES,
  90339. FLAC__APODIZATION_FLATTOP,
  90340. FLAC__APODIZATION_GAUSS,
  90341. FLAC__APODIZATION_HAMMING,
  90342. FLAC__APODIZATION_HANN,
  90343. FLAC__APODIZATION_KAISER_BESSEL,
  90344. FLAC__APODIZATION_NUTTALL,
  90345. FLAC__APODIZATION_RECTANGLE,
  90346. FLAC__APODIZATION_TRIANGLE,
  90347. FLAC__APODIZATION_TUKEY,
  90348. FLAC__APODIZATION_WELCH
  90349. } FLAC__ApodizationFunction;
  90350. typedef struct {
  90351. FLAC__ApodizationFunction type;
  90352. union {
  90353. struct {
  90354. FLAC__real stddev;
  90355. } gauss;
  90356. struct {
  90357. FLAC__real p;
  90358. } tukey;
  90359. } parameters;
  90360. } FLAC__ApodizationSpecification;
  90361. #endif // #ifndef FLAC__INTEGER_ONLY_LIBRARY
  90362. typedef struct FLAC__StreamEncoderProtected {
  90363. FLAC__StreamEncoderState state;
  90364. FLAC__bool verify;
  90365. FLAC__bool streamable_subset;
  90366. FLAC__bool do_md5;
  90367. FLAC__bool do_mid_side_stereo;
  90368. FLAC__bool loose_mid_side_stereo;
  90369. unsigned channels;
  90370. unsigned bits_per_sample;
  90371. unsigned sample_rate;
  90372. unsigned blocksize;
  90373. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  90374. unsigned num_apodizations;
  90375. FLAC__ApodizationSpecification apodizations[FLAC__MAX_APODIZATION_FUNCTIONS];
  90376. #endif
  90377. unsigned max_lpc_order;
  90378. unsigned qlp_coeff_precision;
  90379. FLAC__bool do_qlp_coeff_prec_search;
  90380. FLAC__bool do_exhaustive_model_search;
  90381. FLAC__bool do_escape_coding;
  90382. unsigned min_residual_partition_order;
  90383. unsigned max_residual_partition_order;
  90384. unsigned rice_parameter_search_dist;
  90385. FLAC__uint64 total_samples_estimate;
  90386. FLAC__StreamMetadata **metadata;
  90387. unsigned num_metadata_blocks;
  90388. FLAC__uint64 streaminfo_offset, seektable_offset, audio_offset;
  90389. #if FLAC__HAS_OGG
  90390. FLAC__OggEncoderAspect ogg_encoder_aspect;
  90391. #endif
  90392. } FLAC__StreamEncoderProtected;
  90393. #endif
  90394. /********* End of inlined file: stream_encoder.h *********/
  90395. #if FLAC__HAS_OGG
  90396. #include "include/private/ogg_helper.h"
  90397. #include "include/private/ogg_mapping.h"
  90398. #endif
  90399. /********* Start of inlined file: stream_encoder_framing.h *********/
  90400. #ifndef FLAC__PRIVATE__STREAM_ENCODER_FRAMING_H
  90401. #define FLAC__PRIVATE__STREAM_ENCODER_FRAMING_H
  90402. FLAC__bool FLAC__add_metadata_block(const FLAC__StreamMetadata *metadata, FLAC__BitWriter *bw);
  90403. FLAC__bool FLAC__frame_add_header(const FLAC__FrameHeader *header, FLAC__BitWriter *bw);
  90404. FLAC__bool FLAC__subframe_add_constant(const FLAC__Subframe_Constant *subframe, unsigned subframe_bps, unsigned wasted_bits, FLAC__BitWriter *bw);
  90405. FLAC__bool FLAC__subframe_add_fixed(const FLAC__Subframe_Fixed *subframe, unsigned residual_samples, unsigned subframe_bps, unsigned wasted_bits, FLAC__BitWriter *bw);
  90406. FLAC__bool FLAC__subframe_add_lpc(const FLAC__Subframe_LPC *subframe, unsigned residual_samples, unsigned subframe_bps, unsigned wasted_bits, FLAC__BitWriter *bw);
  90407. FLAC__bool FLAC__subframe_add_verbatim(const FLAC__Subframe_Verbatim *subframe, unsigned samples, unsigned subframe_bps, unsigned wasted_bits, FLAC__BitWriter *bw);
  90408. #endif
  90409. /********* End of inlined file: stream_encoder_framing.h *********/
  90410. /********* Start of inlined file: window.h *********/
  90411. #ifndef FLAC__PRIVATE__WINDOW_H
  90412. #define FLAC__PRIVATE__WINDOW_H
  90413. #ifdef HAVE_CONFIG_H
  90414. #include <config.h>
  90415. #endif
  90416. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  90417. void FLAC__window_bartlett(FLAC__real *window, const FLAC__int32 L);
  90418. void FLAC__window_bartlett_hann(FLAC__real *window, const FLAC__int32 L);
  90419. void FLAC__window_blackman(FLAC__real *window, const FLAC__int32 L);
  90420. void FLAC__window_blackman_harris_4term_92db_sidelobe(FLAC__real *window, const FLAC__int32 L);
  90421. void FLAC__window_connes(FLAC__real *window, const FLAC__int32 L);
  90422. void FLAC__window_flattop(FLAC__real *window, const FLAC__int32 L);
  90423. void FLAC__window_gauss(FLAC__real *window, const FLAC__int32 L, const FLAC__real stddev); /* 0.0 < stddev <= 0.5 */
  90424. void FLAC__window_hamming(FLAC__real *window, const FLAC__int32 L);
  90425. void FLAC__window_hann(FLAC__real *window, const FLAC__int32 L);
  90426. void FLAC__window_kaiser_bessel(FLAC__real *window, const FLAC__int32 L);
  90427. void FLAC__window_nuttall(FLAC__real *window, const FLAC__int32 L);
  90428. void FLAC__window_rectangle(FLAC__real *window, const FLAC__int32 L);
  90429. void FLAC__window_triangle(FLAC__real *window, const FLAC__int32 L);
  90430. void FLAC__window_tukey(FLAC__real *window, const FLAC__int32 L, const FLAC__real p);
  90431. void FLAC__window_welch(FLAC__real *window, const FLAC__int32 L);
  90432. #endif /* !defined FLAC__INTEGER_ONLY_LIBRARY */
  90433. #endif
  90434. /********* End of inlined file: window.h *********/
  90435. #ifndef FLaC__INLINE
  90436. #define FLaC__INLINE
  90437. #endif
  90438. #ifdef min
  90439. #undef min
  90440. #endif
  90441. #define min(x,y) ((x)<(y)?(x):(y))
  90442. #ifdef max
  90443. #undef max
  90444. #endif
  90445. #define max(x,y) ((x)>(y)?(x):(y))
  90446. #undef EXACT_RICE_BITS_CALCULATION
  90447. #undef ENABLE_RICE_PARAMETER_SEARCH
  90448. typedef struct {
  90449. FLAC__int32 *data[FLAC__MAX_CHANNELS];
  90450. unsigned size; /* of each data[] in samples */
  90451. unsigned tail;
  90452. } verify_input_fifo;
  90453. typedef struct {
  90454. const FLAC__byte *data;
  90455. unsigned capacity;
  90456. unsigned bytes;
  90457. } verify_output;
  90458. typedef enum {
  90459. ENCODER_IN_MAGIC = 0,
  90460. ENCODER_IN_METADATA = 1,
  90461. ENCODER_IN_AUDIO = 2
  90462. } EncoderStateHint;
  90463. static struct CompressionLevels {
  90464. FLAC__bool do_mid_side_stereo;
  90465. FLAC__bool loose_mid_side_stereo;
  90466. unsigned max_lpc_order;
  90467. unsigned qlp_coeff_precision;
  90468. FLAC__bool do_qlp_coeff_prec_search;
  90469. FLAC__bool do_escape_coding;
  90470. FLAC__bool do_exhaustive_model_search;
  90471. unsigned min_residual_partition_order;
  90472. unsigned max_residual_partition_order;
  90473. unsigned rice_parameter_search_dist;
  90474. } compression_levels_[] = {
  90475. { false, false, 0, 0, false, false, false, 0, 3, 0 },
  90476. { true , true , 0, 0, false, false, false, 0, 3, 0 },
  90477. { true , false, 0, 0, false, false, false, 0, 3, 0 },
  90478. { false, false, 6, 0, false, false, false, 0, 4, 0 },
  90479. { true , true , 8, 0, false, false, false, 0, 4, 0 },
  90480. { true , false, 8, 0, false, false, false, 0, 5, 0 },
  90481. { true , false, 8, 0, false, false, false, 0, 6, 0 },
  90482. { true , false, 8, 0, false, false, true , 0, 6, 0 },
  90483. { true , false, 12, 0, false, false, true , 0, 6, 0 }
  90484. };
  90485. static void set_defaults_enc(FLAC__StreamEncoder *encoder);
  90486. static void free_(FLAC__StreamEncoder *encoder);
  90487. static FLAC__bool resize_buffers_(FLAC__StreamEncoder *encoder, unsigned new_blocksize);
  90488. static FLAC__bool write_bitbuffer_(FLAC__StreamEncoder *encoder, unsigned samples, FLAC__bool is_last_block);
  90489. static FLAC__StreamEncoderWriteStatus write_frame_(FLAC__StreamEncoder *encoder, const FLAC__byte buffer[], size_t bytes, unsigned samples, FLAC__bool is_last_block);
  90490. static void update_metadata_(const FLAC__StreamEncoder *encoder);
  90491. #if FLAC__HAS_OGG
  90492. static void update_ogg_metadata_(FLAC__StreamEncoder *encoder);
  90493. #endif
  90494. static FLAC__bool process_frame_(FLAC__StreamEncoder *encoder, FLAC__bool is_fractional_block, FLAC__bool is_last_block);
  90495. static FLAC__bool process_subframes_(FLAC__StreamEncoder *encoder, FLAC__bool is_fractional_block);
  90496. static FLAC__bool process_subframe_(
  90497. FLAC__StreamEncoder *encoder,
  90498. unsigned min_partition_order,
  90499. unsigned max_partition_order,
  90500. const FLAC__FrameHeader *frame_header,
  90501. unsigned subframe_bps,
  90502. const FLAC__int32 integer_signal[],
  90503. FLAC__Subframe *subframe[2],
  90504. FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents[2],
  90505. FLAC__int32 *residual[2],
  90506. unsigned *best_subframe,
  90507. unsigned *best_bits
  90508. );
  90509. static FLAC__bool add_subframe_(
  90510. FLAC__StreamEncoder *encoder,
  90511. unsigned blocksize,
  90512. unsigned subframe_bps,
  90513. const FLAC__Subframe *subframe,
  90514. FLAC__BitWriter *frame
  90515. );
  90516. static unsigned evaluate_constant_subframe_(
  90517. FLAC__StreamEncoder *encoder,
  90518. const FLAC__int32 signal,
  90519. unsigned blocksize,
  90520. unsigned subframe_bps,
  90521. FLAC__Subframe *subframe
  90522. );
  90523. static unsigned evaluate_fixed_subframe_(
  90524. FLAC__StreamEncoder *encoder,
  90525. const FLAC__int32 signal[],
  90526. FLAC__int32 residual[],
  90527. FLAC__uint64 abs_residual_partition_sums[],
  90528. unsigned raw_bits_per_partition[],
  90529. unsigned blocksize,
  90530. unsigned subframe_bps,
  90531. unsigned order,
  90532. unsigned rice_parameter,
  90533. unsigned rice_parameter_limit,
  90534. unsigned min_partition_order,
  90535. unsigned max_partition_order,
  90536. FLAC__bool do_escape_coding,
  90537. unsigned rice_parameter_search_dist,
  90538. FLAC__Subframe *subframe,
  90539. FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents
  90540. );
  90541. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  90542. static unsigned evaluate_lpc_subframe_(
  90543. FLAC__StreamEncoder *encoder,
  90544. const FLAC__int32 signal[],
  90545. FLAC__int32 residual[],
  90546. FLAC__uint64 abs_residual_partition_sums[],
  90547. unsigned raw_bits_per_partition[],
  90548. const FLAC__real lp_coeff[],
  90549. unsigned blocksize,
  90550. unsigned subframe_bps,
  90551. unsigned order,
  90552. unsigned qlp_coeff_precision,
  90553. unsigned rice_parameter,
  90554. unsigned rice_parameter_limit,
  90555. unsigned min_partition_order,
  90556. unsigned max_partition_order,
  90557. FLAC__bool do_escape_coding,
  90558. unsigned rice_parameter_search_dist,
  90559. FLAC__Subframe *subframe,
  90560. FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents
  90561. );
  90562. #endif
  90563. static unsigned evaluate_verbatim_subframe_(
  90564. FLAC__StreamEncoder *encoder,
  90565. const FLAC__int32 signal[],
  90566. unsigned blocksize,
  90567. unsigned subframe_bps,
  90568. FLAC__Subframe *subframe
  90569. );
  90570. static unsigned find_best_partition_order_(
  90571. struct FLAC__StreamEncoderPrivate *private_,
  90572. const FLAC__int32 residual[],
  90573. FLAC__uint64 abs_residual_partition_sums[],
  90574. unsigned raw_bits_per_partition[],
  90575. unsigned residual_samples,
  90576. unsigned predictor_order,
  90577. unsigned rice_parameter,
  90578. unsigned rice_parameter_limit,
  90579. unsigned min_partition_order,
  90580. unsigned max_partition_order,
  90581. unsigned bps,
  90582. FLAC__bool do_escape_coding,
  90583. unsigned rice_parameter_search_dist,
  90584. FLAC__EntropyCodingMethod *best_ecm
  90585. );
  90586. static void precompute_partition_info_sums_(
  90587. const FLAC__int32 residual[],
  90588. FLAC__uint64 abs_residual_partition_sums[],
  90589. unsigned residual_samples,
  90590. unsigned predictor_order,
  90591. unsigned min_partition_order,
  90592. unsigned max_partition_order,
  90593. unsigned bps
  90594. );
  90595. static void precompute_partition_info_escapes_(
  90596. const FLAC__int32 residual[],
  90597. unsigned raw_bits_per_partition[],
  90598. unsigned residual_samples,
  90599. unsigned predictor_order,
  90600. unsigned min_partition_order,
  90601. unsigned max_partition_order
  90602. );
  90603. static FLAC__bool set_partitioned_rice_(
  90604. #ifdef EXACT_RICE_BITS_CALCULATION
  90605. const FLAC__int32 residual[],
  90606. #endif
  90607. const FLAC__uint64 abs_residual_partition_sums[],
  90608. const unsigned raw_bits_per_partition[],
  90609. const unsigned residual_samples,
  90610. const unsigned predictor_order,
  90611. const unsigned suggested_rice_parameter,
  90612. const unsigned rice_parameter_limit,
  90613. const unsigned rice_parameter_search_dist,
  90614. const unsigned partition_order,
  90615. const FLAC__bool search_for_escapes,
  90616. FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents,
  90617. unsigned *bits
  90618. );
  90619. static unsigned get_wasted_bits_(FLAC__int32 signal[], unsigned samples);
  90620. static void append_to_verify_fifo_(
  90621. verify_input_fifo *fifo,
  90622. const FLAC__int32 * const input[],
  90623. unsigned input_offset,
  90624. unsigned channels,
  90625. unsigned wide_samples
  90626. );
  90627. static void append_to_verify_fifo_interleaved_(
  90628. verify_input_fifo *fifo,
  90629. const FLAC__int32 input[],
  90630. unsigned input_offset,
  90631. unsigned channels,
  90632. unsigned wide_samples
  90633. );
  90634. static FLAC__StreamDecoderReadStatus verify_read_callback_(const FLAC__StreamDecoder *decoder, FLAC__byte buffer[], size_t *bytes, void *client_data);
  90635. static FLAC__StreamDecoderWriteStatus verify_write_callback_(const FLAC__StreamDecoder *decoder, const FLAC__Frame *frame, const FLAC__int32 * const buffer[], void *client_data);
  90636. static void verify_metadata_callback_(const FLAC__StreamDecoder *decoder, const FLAC__StreamMetadata *metadata, void *client_data);
  90637. static void verify_error_callback_(const FLAC__StreamDecoder *decoder, FLAC__StreamDecoderErrorStatus status, void *client_data);
  90638. static FLAC__StreamEncoderReadStatus file_read_callback_enc(const FLAC__StreamEncoder *encoder, FLAC__byte buffer[], size_t *bytes, void *client_data);
  90639. static FLAC__StreamEncoderSeekStatus file_seek_callback_enc(const FLAC__StreamEncoder *encoder, FLAC__uint64 absolute_byte_offset, void *client_data);
  90640. static FLAC__StreamEncoderTellStatus file_tell_callback_enc(const FLAC__StreamEncoder *encoder, FLAC__uint64 *absolute_byte_offset, void *client_data);
  90641. 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);
  90642. static FILE *get_binary_stdout_(void);
  90643. typedef struct FLAC__StreamEncoderPrivate {
  90644. unsigned input_capacity; /* current size (in samples) of the signal and residual buffers */
  90645. FLAC__int32 *integer_signal[FLAC__MAX_CHANNELS]; /* the integer version of the input signal */
  90646. FLAC__int32 *integer_signal_mid_side[2]; /* the integer version of the mid-side input signal (stereo only) */
  90647. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  90648. FLAC__real *real_signal[FLAC__MAX_CHANNELS]; /* (@@@ currently unused) the floating-point version of the input signal */
  90649. FLAC__real *real_signal_mid_side[2]; /* (@@@ currently unused) the floating-point version of the mid-side input signal (stereo only) */
  90650. FLAC__real *window[FLAC__MAX_APODIZATION_FUNCTIONS]; /* the pre-computed floating-point window for each apodization function */
  90651. FLAC__real *windowed_signal; /* the integer_signal[] * current window[] */
  90652. #endif
  90653. unsigned subframe_bps[FLAC__MAX_CHANNELS]; /* the effective bits per sample of the input signal (stream bps - wasted bits) */
  90654. unsigned subframe_bps_mid_side[2]; /* the effective bits per sample of the mid-side input signal (stream bps - wasted bits + 0/1) */
  90655. FLAC__int32 *residual_workspace[FLAC__MAX_CHANNELS][2]; /* each channel has a candidate and best workspace where the subframe residual signals will be stored */
  90656. FLAC__int32 *residual_workspace_mid_side[2][2];
  90657. FLAC__Subframe subframe_workspace[FLAC__MAX_CHANNELS][2];
  90658. FLAC__Subframe subframe_workspace_mid_side[2][2];
  90659. FLAC__Subframe *subframe_workspace_ptr[FLAC__MAX_CHANNELS][2];
  90660. FLAC__Subframe *subframe_workspace_ptr_mid_side[2][2];
  90661. FLAC__EntropyCodingMethod_PartitionedRiceContents partitioned_rice_contents_workspace[FLAC__MAX_CHANNELS][2];
  90662. FLAC__EntropyCodingMethod_PartitionedRiceContents partitioned_rice_contents_workspace_mid_side[FLAC__MAX_CHANNELS][2];
  90663. FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents_workspace_ptr[FLAC__MAX_CHANNELS][2];
  90664. FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents_workspace_ptr_mid_side[FLAC__MAX_CHANNELS][2];
  90665. unsigned best_subframe[FLAC__MAX_CHANNELS]; /* index (0 or 1) into 2nd dimension of the above workspaces */
  90666. unsigned best_subframe_mid_side[2];
  90667. unsigned best_subframe_bits[FLAC__MAX_CHANNELS]; /* size in bits of the best subframe for each channel */
  90668. unsigned best_subframe_bits_mid_side[2];
  90669. FLAC__uint64 *abs_residual_partition_sums; /* workspace where the sum of abs(candidate residual) for each partition is stored */
  90670. unsigned *raw_bits_per_partition; /* workspace where the sum of silog2(candidate residual) for each partition is stored */
  90671. FLAC__BitWriter *frame; /* the current frame being worked on */
  90672. unsigned loose_mid_side_stereo_frames; /* rounded number of frames the encoder will use before trying both independent and mid/side frames again */
  90673. unsigned loose_mid_side_stereo_frame_count; /* number of frames using the current channel assignment */
  90674. FLAC__ChannelAssignment last_channel_assignment;
  90675. FLAC__StreamMetadata streaminfo; /* scratchpad for STREAMINFO as it is built */
  90676. FLAC__StreamMetadata_SeekTable *seek_table; /* pointer into encoder->protected_->metadata_ where the seek table is */
  90677. unsigned current_sample_number;
  90678. unsigned current_frame_number;
  90679. FLAC__MD5Context md5context;
  90680. FLAC__CPUInfo cpuinfo;
  90681. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  90682. unsigned (*local_fixed_compute_best_predictor)(const FLAC__int32 data[], unsigned data_len, FLAC__float residual_bits_per_sample[FLAC__MAX_FIXED_ORDER+1]);
  90683. #else
  90684. unsigned (*local_fixed_compute_best_predictor)(const FLAC__int32 data[], unsigned data_len, FLAC__fixedpoint residual_bits_per_sample[FLAC__MAX_FIXED_ORDER+1]);
  90685. #endif
  90686. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  90687. void (*local_lpc_compute_autocorrelation)(const FLAC__real data[], unsigned data_len, unsigned lag, FLAC__real autoc[]);
  90688. 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[]);
  90689. 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[]);
  90690. 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[]);
  90691. #endif
  90692. FLAC__bool use_wide_by_block; /* use slow 64-bit versions of some functions because of the block size */
  90693. FLAC__bool use_wide_by_partition; /* use slow 64-bit versions of some functions because of the min partition order and blocksize */
  90694. FLAC__bool use_wide_by_order; /* use slow 64-bit versions of some functions because of the lpc order */
  90695. FLAC__bool disable_constant_subframes;
  90696. FLAC__bool disable_fixed_subframes;
  90697. FLAC__bool disable_verbatim_subframes;
  90698. #if FLAC__HAS_OGG
  90699. FLAC__bool is_ogg;
  90700. #endif
  90701. FLAC__StreamEncoderReadCallback read_callback; /* currently only needed for Ogg FLAC */
  90702. FLAC__StreamEncoderSeekCallback seek_callback;
  90703. FLAC__StreamEncoderTellCallback tell_callback;
  90704. FLAC__StreamEncoderWriteCallback write_callback;
  90705. FLAC__StreamEncoderMetadataCallback metadata_callback;
  90706. FLAC__StreamEncoderProgressCallback progress_callback;
  90707. void *client_data;
  90708. unsigned first_seekpoint_to_check;
  90709. FILE *file; /* only used when encoding to a file */
  90710. FLAC__uint64 bytes_written;
  90711. FLAC__uint64 samples_written;
  90712. unsigned frames_written;
  90713. unsigned total_frames_estimate;
  90714. FLAC__int32 *integer_signal_unaligned[FLAC__MAX_CHANNELS];
  90715. FLAC__int32 *integer_signal_mid_side_unaligned[2];
  90716. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  90717. FLAC__real *real_signal_unaligned[FLAC__MAX_CHANNELS]; /* (@@@ currently unused) */
  90718. FLAC__real *real_signal_mid_side_unaligned[2]; /* (@@@ currently unused) */
  90719. FLAC__real *window_unaligned[FLAC__MAX_APODIZATION_FUNCTIONS];
  90720. FLAC__real *windowed_signal_unaligned;
  90721. #endif
  90722. FLAC__int32 *residual_workspace_unaligned[FLAC__MAX_CHANNELS][2];
  90723. FLAC__int32 *residual_workspace_mid_side_unaligned[2][2];
  90724. FLAC__uint64 *abs_residual_partition_sums_unaligned;
  90725. unsigned *raw_bits_per_partition_unaligned;
  90726. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  90727. FLAC__real lp_coeff[FLAC__MAX_LPC_ORDER][FLAC__MAX_LPC_ORDER]; /* from process_subframe_() */
  90728. #endif
  90729. FLAC__EntropyCodingMethod_PartitionedRiceContents partitioned_rice_contents_extra[2]; /* from find_best_partition_order_() */
  90730. struct {
  90731. FLAC__StreamDecoder *decoder;
  90732. EncoderStateHint state_hint;
  90733. FLAC__bool needs_magic_hack;
  90734. verify_input_fifo input_fifo;
  90735. verify_output output;
  90736. struct {
  90737. FLAC__uint64 absolute_sample;
  90738. unsigned frame_number;
  90739. unsigned channel;
  90740. unsigned sample;
  90741. FLAC__int32 expected;
  90742. FLAC__int32 got;
  90743. } error_stats;
  90744. } verify;
  90745. FLAC__bool is_being_deleted; /* if true, call to ..._finish() from ..._delete() will not call the callbacks */
  90746. } FLAC__StreamEncoderPrivate;
  90747. FLAC_API const char * const FLAC__StreamEncoderStateString[] = {
  90748. "FLAC__STREAM_ENCODER_OK",
  90749. "FLAC__STREAM_ENCODER_UNINITIALIZED",
  90750. "FLAC__STREAM_ENCODER_OGG_ERROR",
  90751. "FLAC__STREAM_ENCODER_VERIFY_DECODER_ERROR",
  90752. "FLAC__STREAM_ENCODER_VERIFY_MISMATCH_IN_AUDIO_DATA",
  90753. "FLAC__STREAM_ENCODER_CLIENT_ERROR",
  90754. "FLAC__STREAM_ENCODER_IO_ERROR",
  90755. "FLAC__STREAM_ENCODER_FRAMING_ERROR",
  90756. "FLAC__STREAM_ENCODER_MEMORY_ALLOCATION_ERROR"
  90757. };
  90758. FLAC_API const char * const FLAC__StreamEncoderInitStatusString[] = {
  90759. "FLAC__STREAM_ENCODER_INIT_STATUS_OK",
  90760. "FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR",
  90761. "FLAC__STREAM_ENCODER_INIT_STATUS_UNSUPPORTED_CONTAINER",
  90762. "FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_CALLBACKS",
  90763. "FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_NUMBER_OF_CHANNELS",
  90764. "FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_BITS_PER_SAMPLE",
  90765. "FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_SAMPLE_RATE",
  90766. "FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_BLOCK_SIZE",
  90767. "FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_MAX_LPC_ORDER",
  90768. "FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_QLP_COEFF_PRECISION",
  90769. "FLAC__STREAM_ENCODER_INIT_STATUS_BLOCK_SIZE_TOO_SMALL_FOR_LPC_ORDER",
  90770. "FLAC__STREAM_ENCODER_INIT_STATUS_NOT_STREAMABLE",
  90771. "FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA",
  90772. "FLAC__STREAM_ENCODER_INIT_STATUS_ALREADY_INITIALIZED"
  90773. };
  90774. FLAC_API const char * const FLAC__treamEncoderReadStatusString[] = {
  90775. "FLAC__STREAM_ENCODER_READ_STATUS_CONTINUE",
  90776. "FLAC__STREAM_ENCODER_READ_STATUS_END_OF_STREAM",
  90777. "FLAC__STREAM_ENCODER_READ_STATUS_ABORT",
  90778. "FLAC__STREAM_ENCODER_READ_STATUS_UNSUPPORTED"
  90779. };
  90780. FLAC_API const char * const FLAC__StreamEncoderWriteStatusString[] = {
  90781. "FLAC__STREAM_ENCODER_WRITE_STATUS_OK",
  90782. "FLAC__STREAM_ENCODER_WRITE_STATUS_FATAL_ERROR"
  90783. };
  90784. FLAC_API const char * const FLAC__StreamEncoderSeekStatusString[] = {
  90785. "FLAC__STREAM_ENCODER_SEEK_STATUS_OK",
  90786. "FLAC__STREAM_ENCODER_SEEK_STATUS_ERROR",
  90787. "FLAC__STREAM_ENCODER_SEEK_STATUS_UNSUPPORTED"
  90788. };
  90789. FLAC_API const char * const FLAC__StreamEncoderTellStatusString[] = {
  90790. "FLAC__STREAM_ENCODER_TELL_STATUS_OK",
  90791. "FLAC__STREAM_ENCODER_TELL_STATUS_ERROR",
  90792. "FLAC__STREAM_ENCODER_TELL_STATUS_UNSUPPORTED"
  90793. };
  90794. static const unsigned OVERREAD_ = 1;
  90795. FLAC_API FLAC__StreamEncoder *FLAC__stream_encoder_new(void)
  90796. {
  90797. FLAC__StreamEncoder *encoder;
  90798. unsigned i;
  90799. FLAC__ASSERT(sizeof(int) >= 4); /* we want to die right away if this is not true */
  90800. encoder = (FLAC__StreamEncoder*)calloc(1, sizeof(FLAC__StreamEncoder));
  90801. if(encoder == 0) {
  90802. return 0;
  90803. }
  90804. encoder->protected_ = (FLAC__StreamEncoderProtected*)calloc(1, sizeof(FLAC__StreamEncoderProtected));
  90805. if(encoder->protected_ == 0) {
  90806. free(encoder);
  90807. return 0;
  90808. }
  90809. encoder->private_ = (FLAC__StreamEncoderPrivate*)calloc(1, sizeof(FLAC__StreamEncoderPrivate));
  90810. if(encoder->private_ == 0) {
  90811. free(encoder->protected_);
  90812. free(encoder);
  90813. return 0;
  90814. }
  90815. encoder->private_->frame = FLAC__bitwriter_new();
  90816. if(encoder->private_->frame == 0) {
  90817. free(encoder->private_);
  90818. free(encoder->protected_);
  90819. free(encoder);
  90820. return 0;
  90821. }
  90822. encoder->private_->file = 0;
  90823. set_defaults_enc(encoder);
  90824. encoder->private_->is_being_deleted = false;
  90825. for(i = 0; i < FLAC__MAX_CHANNELS; i++) {
  90826. encoder->private_->subframe_workspace_ptr[i][0] = &encoder->private_->subframe_workspace[i][0];
  90827. encoder->private_->subframe_workspace_ptr[i][1] = &encoder->private_->subframe_workspace[i][1];
  90828. }
  90829. for(i = 0; i < 2; i++) {
  90830. encoder->private_->subframe_workspace_ptr_mid_side[i][0] = &encoder->private_->subframe_workspace_mid_side[i][0];
  90831. encoder->private_->subframe_workspace_ptr_mid_side[i][1] = &encoder->private_->subframe_workspace_mid_side[i][1];
  90832. }
  90833. for(i = 0; i < FLAC__MAX_CHANNELS; i++) {
  90834. encoder->private_->partitioned_rice_contents_workspace_ptr[i][0] = &encoder->private_->partitioned_rice_contents_workspace[i][0];
  90835. encoder->private_->partitioned_rice_contents_workspace_ptr[i][1] = &encoder->private_->partitioned_rice_contents_workspace[i][1];
  90836. }
  90837. for(i = 0; i < 2; i++) {
  90838. encoder->private_->partitioned_rice_contents_workspace_ptr_mid_side[i][0] = &encoder->private_->partitioned_rice_contents_workspace_mid_side[i][0];
  90839. encoder->private_->partitioned_rice_contents_workspace_ptr_mid_side[i][1] = &encoder->private_->partitioned_rice_contents_workspace_mid_side[i][1];
  90840. }
  90841. for(i = 0; i < FLAC__MAX_CHANNELS; i++) {
  90842. FLAC__format_entropy_coding_method_partitioned_rice_contents_init(&encoder->private_->partitioned_rice_contents_workspace[i][0]);
  90843. FLAC__format_entropy_coding_method_partitioned_rice_contents_init(&encoder->private_->partitioned_rice_contents_workspace[i][1]);
  90844. }
  90845. for(i = 0; i < 2; i++) {
  90846. FLAC__format_entropy_coding_method_partitioned_rice_contents_init(&encoder->private_->partitioned_rice_contents_workspace_mid_side[i][0]);
  90847. FLAC__format_entropy_coding_method_partitioned_rice_contents_init(&encoder->private_->partitioned_rice_contents_workspace_mid_side[i][1]);
  90848. }
  90849. for(i = 0; i < 2; i++)
  90850. FLAC__format_entropy_coding_method_partitioned_rice_contents_init(&encoder->private_->partitioned_rice_contents_extra[i]);
  90851. encoder->protected_->state = FLAC__STREAM_ENCODER_UNINITIALIZED;
  90852. return encoder;
  90853. }
  90854. FLAC_API void FLAC__stream_encoder_delete(FLAC__StreamEncoder *encoder)
  90855. {
  90856. unsigned i;
  90857. FLAC__ASSERT(0 != encoder);
  90858. FLAC__ASSERT(0 != encoder->protected_);
  90859. FLAC__ASSERT(0 != encoder->private_);
  90860. FLAC__ASSERT(0 != encoder->private_->frame);
  90861. encoder->private_->is_being_deleted = true;
  90862. (void)FLAC__stream_encoder_finish(encoder);
  90863. if(0 != encoder->private_->verify.decoder)
  90864. FLAC__stream_decoder_delete(encoder->private_->verify.decoder);
  90865. for(i = 0; i < FLAC__MAX_CHANNELS; i++) {
  90866. FLAC__format_entropy_coding_method_partitioned_rice_contents_clear(&encoder->private_->partitioned_rice_contents_workspace[i][0]);
  90867. FLAC__format_entropy_coding_method_partitioned_rice_contents_clear(&encoder->private_->partitioned_rice_contents_workspace[i][1]);
  90868. }
  90869. for(i = 0; i < 2; i++) {
  90870. FLAC__format_entropy_coding_method_partitioned_rice_contents_clear(&encoder->private_->partitioned_rice_contents_workspace_mid_side[i][0]);
  90871. FLAC__format_entropy_coding_method_partitioned_rice_contents_clear(&encoder->private_->partitioned_rice_contents_workspace_mid_side[i][1]);
  90872. }
  90873. for(i = 0; i < 2; i++)
  90874. FLAC__format_entropy_coding_method_partitioned_rice_contents_clear(&encoder->private_->partitioned_rice_contents_extra[i]);
  90875. FLAC__bitwriter_delete(encoder->private_->frame);
  90876. free(encoder->private_);
  90877. free(encoder->protected_);
  90878. free(encoder);
  90879. }
  90880. static FLAC__StreamEncoderInitStatus init_stream_internal_enc(
  90881. FLAC__StreamEncoder *encoder,
  90882. FLAC__StreamEncoderReadCallback read_callback,
  90883. FLAC__StreamEncoderWriteCallback write_callback,
  90884. FLAC__StreamEncoderSeekCallback seek_callback,
  90885. FLAC__StreamEncoderTellCallback tell_callback,
  90886. FLAC__StreamEncoderMetadataCallback metadata_callback,
  90887. void *client_data,
  90888. FLAC__bool is_ogg
  90889. )
  90890. {
  90891. unsigned i;
  90892. FLAC__bool metadata_has_seektable, metadata_has_vorbis_comment, metadata_picture_has_type1, metadata_picture_has_type2;
  90893. FLAC__ASSERT(0 != encoder);
  90894. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90895. return FLAC__STREAM_ENCODER_INIT_STATUS_ALREADY_INITIALIZED;
  90896. #if !FLAC__HAS_OGG
  90897. if(is_ogg)
  90898. return FLAC__STREAM_ENCODER_INIT_STATUS_UNSUPPORTED_CONTAINER;
  90899. #endif
  90900. if(0 == write_callback || (seek_callback && 0 == tell_callback))
  90901. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_CALLBACKS;
  90902. if(encoder->protected_->channels == 0 || encoder->protected_->channels > FLAC__MAX_CHANNELS)
  90903. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_NUMBER_OF_CHANNELS;
  90904. if(encoder->protected_->channels != 2) {
  90905. encoder->protected_->do_mid_side_stereo = false;
  90906. encoder->protected_->loose_mid_side_stereo = false;
  90907. }
  90908. else if(!encoder->protected_->do_mid_side_stereo)
  90909. encoder->protected_->loose_mid_side_stereo = false;
  90910. if(encoder->protected_->bits_per_sample >= 32)
  90911. encoder->protected_->do_mid_side_stereo = false; /* since we currenty do 32-bit math, the side channel would have 33 bps and overflow */
  90912. if(encoder->protected_->bits_per_sample < FLAC__MIN_BITS_PER_SAMPLE || encoder->protected_->bits_per_sample > FLAC__REFERENCE_CODEC_MAX_BITS_PER_SAMPLE)
  90913. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_BITS_PER_SAMPLE;
  90914. if(!FLAC__format_sample_rate_is_valid(encoder->protected_->sample_rate))
  90915. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_SAMPLE_RATE;
  90916. if(encoder->protected_->blocksize == 0) {
  90917. if(encoder->protected_->max_lpc_order == 0)
  90918. encoder->protected_->blocksize = 1152;
  90919. else
  90920. encoder->protected_->blocksize = 4096;
  90921. }
  90922. if(encoder->protected_->blocksize < FLAC__MIN_BLOCK_SIZE || encoder->protected_->blocksize > FLAC__MAX_BLOCK_SIZE)
  90923. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_BLOCK_SIZE;
  90924. if(encoder->protected_->max_lpc_order > FLAC__MAX_LPC_ORDER)
  90925. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_MAX_LPC_ORDER;
  90926. if(encoder->protected_->blocksize < encoder->protected_->max_lpc_order)
  90927. return FLAC__STREAM_ENCODER_INIT_STATUS_BLOCK_SIZE_TOO_SMALL_FOR_LPC_ORDER;
  90928. if(encoder->protected_->qlp_coeff_precision == 0) {
  90929. if(encoder->protected_->bits_per_sample < 16) {
  90930. encoder->protected_->qlp_coeff_precision = max(FLAC__MIN_QLP_COEFF_PRECISION, 2 + encoder->protected_->bits_per_sample / 2);
  90931. }
  90932. else if(encoder->protected_->bits_per_sample == 16) {
  90933. if(encoder->protected_->blocksize <= 192)
  90934. encoder->protected_->qlp_coeff_precision = 7;
  90935. else if(encoder->protected_->blocksize <= 384)
  90936. encoder->protected_->qlp_coeff_precision = 8;
  90937. else if(encoder->protected_->blocksize <= 576)
  90938. encoder->protected_->qlp_coeff_precision = 9;
  90939. else if(encoder->protected_->blocksize <= 1152)
  90940. encoder->protected_->qlp_coeff_precision = 10;
  90941. else if(encoder->protected_->blocksize <= 2304)
  90942. encoder->protected_->qlp_coeff_precision = 11;
  90943. else if(encoder->protected_->blocksize <= 4608)
  90944. encoder->protected_->qlp_coeff_precision = 12;
  90945. else
  90946. encoder->protected_->qlp_coeff_precision = 13;
  90947. }
  90948. else {
  90949. if(encoder->protected_->blocksize <= 384)
  90950. encoder->protected_->qlp_coeff_precision = FLAC__MAX_QLP_COEFF_PRECISION-2;
  90951. else if(encoder->protected_->blocksize <= 1152)
  90952. encoder->protected_->qlp_coeff_precision = FLAC__MAX_QLP_COEFF_PRECISION-1;
  90953. else
  90954. encoder->protected_->qlp_coeff_precision = FLAC__MAX_QLP_COEFF_PRECISION;
  90955. }
  90956. FLAC__ASSERT(encoder->protected_->qlp_coeff_precision <= FLAC__MAX_QLP_COEFF_PRECISION);
  90957. }
  90958. else if(encoder->protected_->qlp_coeff_precision < FLAC__MIN_QLP_COEFF_PRECISION || encoder->protected_->qlp_coeff_precision > FLAC__MAX_QLP_COEFF_PRECISION)
  90959. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_QLP_COEFF_PRECISION;
  90960. if(encoder->protected_->streamable_subset) {
  90961. if(
  90962. encoder->protected_->blocksize != 192 &&
  90963. encoder->protected_->blocksize != 576 &&
  90964. encoder->protected_->blocksize != 1152 &&
  90965. encoder->protected_->blocksize != 2304 &&
  90966. encoder->protected_->blocksize != 4608 &&
  90967. encoder->protected_->blocksize != 256 &&
  90968. encoder->protected_->blocksize != 512 &&
  90969. encoder->protected_->blocksize != 1024 &&
  90970. encoder->protected_->blocksize != 2048 &&
  90971. encoder->protected_->blocksize != 4096 &&
  90972. encoder->protected_->blocksize != 8192 &&
  90973. encoder->protected_->blocksize != 16384
  90974. )
  90975. return FLAC__STREAM_ENCODER_INIT_STATUS_NOT_STREAMABLE;
  90976. if(!FLAC__format_sample_rate_is_subset(encoder->protected_->sample_rate))
  90977. return FLAC__STREAM_ENCODER_INIT_STATUS_NOT_STREAMABLE;
  90978. if(
  90979. encoder->protected_->bits_per_sample != 8 &&
  90980. encoder->protected_->bits_per_sample != 12 &&
  90981. encoder->protected_->bits_per_sample != 16 &&
  90982. encoder->protected_->bits_per_sample != 20 &&
  90983. encoder->protected_->bits_per_sample != 24
  90984. )
  90985. return FLAC__STREAM_ENCODER_INIT_STATUS_NOT_STREAMABLE;
  90986. if(encoder->protected_->max_residual_partition_order > FLAC__SUBSET_MAX_RICE_PARTITION_ORDER)
  90987. return FLAC__STREAM_ENCODER_INIT_STATUS_NOT_STREAMABLE;
  90988. if(
  90989. encoder->protected_->sample_rate <= 48000 &&
  90990. (
  90991. encoder->protected_->blocksize > FLAC__SUBSET_MAX_BLOCK_SIZE_48000HZ ||
  90992. encoder->protected_->max_lpc_order > FLAC__SUBSET_MAX_LPC_ORDER_48000HZ
  90993. )
  90994. ) {
  90995. return FLAC__STREAM_ENCODER_INIT_STATUS_NOT_STREAMABLE;
  90996. }
  90997. }
  90998. if(encoder->protected_->max_residual_partition_order >= (1u << FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ORDER_LEN))
  90999. encoder->protected_->max_residual_partition_order = (1u << FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ORDER_LEN) - 1;
  91000. if(encoder->protected_->min_residual_partition_order >= encoder->protected_->max_residual_partition_order)
  91001. encoder->protected_->min_residual_partition_order = encoder->protected_->max_residual_partition_order;
  91002. #if FLAC__HAS_OGG
  91003. if(is_ogg && 0 != encoder->protected_->metadata && encoder->protected_->num_metadata_blocks > 1) {
  91004. unsigned i;
  91005. for(i = 1; i < encoder->protected_->num_metadata_blocks; i++) {
  91006. if(0 != encoder->protected_->metadata[i] && encoder->protected_->metadata[i]->type == FLAC__METADATA_TYPE_VORBIS_COMMENT) {
  91007. FLAC__StreamMetadata *vc = encoder->protected_->metadata[i];
  91008. for( ; i > 0; i--)
  91009. encoder->protected_->metadata[i] = encoder->protected_->metadata[i-1];
  91010. encoder->protected_->metadata[0] = vc;
  91011. break;
  91012. }
  91013. }
  91014. }
  91015. #endif
  91016. if(0 != encoder->protected_->metadata && encoder->protected_->num_metadata_blocks > 0) {
  91017. unsigned i;
  91018. for(i = 0; i < encoder->protected_->num_metadata_blocks; i++) {
  91019. if(0 != encoder->protected_->metadata[i] && encoder->protected_->metadata[i]->type == FLAC__METADATA_TYPE_SEEKTABLE) {
  91020. encoder->private_->seek_table = &encoder->protected_->metadata[i]->data.seek_table;
  91021. break; /* take only the first one */
  91022. }
  91023. }
  91024. }
  91025. if(0 == encoder->protected_->metadata && encoder->protected_->num_metadata_blocks > 0)
  91026. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA;
  91027. metadata_has_seektable = false;
  91028. metadata_has_vorbis_comment = false;
  91029. metadata_picture_has_type1 = false;
  91030. metadata_picture_has_type2 = false;
  91031. for(i = 0; i < encoder->protected_->num_metadata_blocks; i++) {
  91032. const FLAC__StreamMetadata *m = encoder->protected_->metadata[i];
  91033. if(m->type == FLAC__METADATA_TYPE_STREAMINFO)
  91034. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA;
  91035. else if(m->type == FLAC__METADATA_TYPE_SEEKTABLE) {
  91036. if(metadata_has_seektable) /* only one is allowed */
  91037. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA;
  91038. metadata_has_seektable = true;
  91039. if(!FLAC__format_seektable_is_legal(&m->data.seek_table))
  91040. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA;
  91041. }
  91042. else if(m->type == FLAC__METADATA_TYPE_VORBIS_COMMENT) {
  91043. if(metadata_has_vorbis_comment) /* only one is allowed */
  91044. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA;
  91045. metadata_has_vorbis_comment = true;
  91046. }
  91047. else if(m->type == FLAC__METADATA_TYPE_CUESHEET) {
  91048. if(!FLAC__format_cuesheet_is_legal(&m->data.cue_sheet, m->data.cue_sheet.is_cd, /*violation=*/0))
  91049. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA;
  91050. }
  91051. else if(m->type == FLAC__METADATA_TYPE_PICTURE) {
  91052. if(!FLAC__format_picture_is_legal(&m->data.picture, /*violation=*/0))
  91053. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA;
  91054. if(m->data.picture.type == FLAC__STREAM_METADATA_PICTURE_TYPE_FILE_ICON_STANDARD) {
  91055. if(metadata_picture_has_type1) /* there should only be 1 per stream */
  91056. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA;
  91057. metadata_picture_has_type1 = true;
  91058. if(
  91059. m->data.picture.type == FLAC__STREAM_METADATA_PICTURE_TYPE_FILE_ICON_STANDARD &&
  91060. (
  91061. (strcmp(m->data.picture.mime_type, "image/png") && strcmp(m->data.picture.mime_type, "-->")) ||
  91062. m->data.picture.width != 32 ||
  91063. m->data.picture.height != 32
  91064. )
  91065. )
  91066. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA;
  91067. }
  91068. else if(m->data.picture.type == FLAC__STREAM_METADATA_PICTURE_TYPE_FILE_ICON) {
  91069. if(metadata_picture_has_type2) /* there should only be 1 per stream */
  91070. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA;
  91071. metadata_picture_has_type2 = true;
  91072. }
  91073. }
  91074. }
  91075. encoder->private_->input_capacity = 0;
  91076. for(i = 0; i < encoder->protected_->channels; i++) {
  91077. encoder->private_->integer_signal_unaligned[i] = encoder->private_->integer_signal[i] = 0;
  91078. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  91079. encoder->private_->real_signal_unaligned[i] = encoder->private_->real_signal[i] = 0;
  91080. #endif
  91081. }
  91082. for(i = 0; i < 2; i++) {
  91083. encoder->private_->integer_signal_mid_side_unaligned[i] = encoder->private_->integer_signal_mid_side[i] = 0;
  91084. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  91085. encoder->private_->real_signal_mid_side_unaligned[i] = encoder->private_->real_signal_mid_side[i] = 0;
  91086. #endif
  91087. }
  91088. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  91089. for(i = 0; i < encoder->protected_->num_apodizations; i++)
  91090. encoder->private_->window_unaligned[i] = encoder->private_->window[i] = 0;
  91091. encoder->private_->windowed_signal_unaligned = encoder->private_->windowed_signal = 0;
  91092. #endif
  91093. for(i = 0; i < encoder->protected_->channels; i++) {
  91094. encoder->private_->residual_workspace_unaligned[i][0] = encoder->private_->residual_workspace[i][0] = 0;
  91095. encoder->private_->residual_workspace_unaligned[i][1] = encoder->private_->residual_workspace[i][1] = 0;
  91096. encoder->private_->best_subframe[i] = 0;
  91097. }
  91098. for(i = 0; i < 2; i++) {
  91099. encoder->private_->residual_workspace_mid_side_unaligned[i][0] = encoder->private_->residual_workspace_mid_side[i][0] = 0;
  91100. encoder->private_->residual_workspace_mid_side_unaligned[i][1] = encoder->private_->residual_workspace_mid_side[i][1] = 0;
  91101. encoder->private_->best_subframe_mid_side[i] = 0;
  91102. }
  91103. encoder->private_->abs_residual_partition_sums_unaligned = encoder->private_->abs_residual_partition_sums = 0;
  91104. encoder->private_->raw_bits_per_partition_unaligned = encoder->private_->raw_bits_per_partition = 0;
  91105. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  91106. encoder->private_->loose_mid_side_stereo_frames = (unsigned)((FLAC__double)encoder->protected_->sample_rate * 0.4 / (FLAC__double)encoder->protected_->blocksize + 0.5);
  91107. #else
  91108. FLAC__ASSERT(FLAC__MAX_SAMPLE_RATE <= 655350);
  91109. FLAC__ASSERT(FLAC__MAX_BLOCK_SIZE <= 65535);
  91110. FLAC__ASSERT(encoder->protected_->sample_rate <= 655350);
  91111. FLAC__ASSERT(encoder->protected_->blocksize <= 65535);
  91112. 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);
  91113. #endif
  91114. if(encoder->private_->loose_mid_side_stereo_frames == 0)
  91115. encoder->private_->loose_mid_side_stereo_frames = 1;
  91116. encoder->private_->loose_mid_side_stereo_frame_count = 0;
  91117. encoder->private_->current_sample_number = 0;
  91118. encoder->private_->current_frame_number = 0;
  91119. encoder->private_->use_wide_by_block = (encoder->protected_->bits_per_sample + FLAC__bitmath_ilog2(encoder->protected_->blocksize)+1 > 30);
  91120. 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? */
  91121. encoder->private_->use_wide_by_partition = (false); /*@@@ need to set this */
  91122. FLAC__cpu_info(&encoder->private_->cpuinfo);
  91123. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  91124. encoder->private_->local_lpc_compute_autocorrelation = FLAC__lpc_compute_autocorrelation;
  91125. #endif
  91126. encoder->private_->local_fixed_compute_best_predictor = FLAC__fixed_compute_best_predictor;
  91127. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  91128. encoder->private_->local_lpc_compute_residual_from_qlp_coefficients = FLAC__lpc_compute_residual_from_qlp_coefficients;
  91129. encoder->private_->local_lpc_compute_residual_from_qlp_coefficients_64bit = FLAC__lpc_compute_residual_from_qlp_coefficients_wide;
  91130. encoder->private_->local_lpc_compute_residual_from_qlp_coefficients_16bit = FLAC__lpc_compute_residual_from_qlp_coefficients;
  91131. #endif
  91132. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  91133. # ifndef FLAC__NO_ASM
  91134. if(encoder->private_->cpuinfo.use_asm) {
  91135. # ifdef FLAC__CPU_IA32
  91136. FLAC__ASSERT(encoder->private_->cpuinfo.type == FLAC__CPUINFO_TYPE_IA32);
  91137. # ifdef FLAC__HAS_NASM
  91138. if(encoder->private_->cpuinfo.data.ia32.sse) {
  91139. if(encoder->protected_->max_lpc_order < 4)
  91140. encoder->private_->local_lpc_compute_autocorrelation = FLAC__lpc_compute_autocorrelation_asm_ia32_sse_lag_4;
  91141. else if(encoder->protected_->max_lpc_order < 8)
  91142. encoder->private_->local_lpc_compute_autocorrelation = FLAC__lpc_compute_autocorrelation_asm_ia32_sse_lag_8;
  91143. else if(encoder->protected_->max_lpc_order < 12)
  91144. encoder->private_->local_lpc_compute_autocorrelation = FLAC__lpc_compute_autocorrelation_asm_ia32_sse_lag_12;
  91145. else
  91146. encoder->private_->local_lpc_compute_autocorrelation = FLAC__lpc_compute_autocorrelation_asm_ia32;
  91147. }
  91148. else if(encoder->private_->cpuinfo.data.ia32._3dnow)
  91149. encoder->private_->local_lpc_compute_autocorrelation = FLAC__lpc_compute_autocorrelation_asm_ia32_3dnow;
  91150. else
  91151. encoder->private_->local_lpc_compute_autocorrelation = FLAC__lpc_compute_autocorrelation_asm_ia32;
  91152. if(encoder->private_->cpuinfo.data.ia32.mmx) {
  91153. encoder->private_->local_lpc_compute_residual_from_qlp_coefficients = FLAC__lpc_compute_residual_from_qlp_coefficients_asm_ia32;
  91154. encoder->private_->local_lpc_compute_residual_from_qlp_coefficients_16bit = FLAC__lpc_compute_residual_from_qlp_coefficients_asm_ia32_mmx;
  91155. }
  91156. else {
  91157. encoder->private_->local_lpc_compute_residual_from_qlp_coefficients = FLAC__lpc_compute_residual_from_qlp_coefficients_asm_ia32;
  91158. encoder->private_->local_lpc_compute_residual_from_qlp_coefficients_16bit = FLAC__lpc_compute_residual_from_qlp_coefficients_asm_ia32;
  91159. }
  91160. if(encoder->private_->cpuinfo.data.ia32.mmx && encoder->private_->cpuinfo.data.ia32.cmov)
  91161. encoder->private_->local_fixed_compute_best_predictor = FLAC__fixed_compute_best_predictor_asm_ia32_mmx_cmov;
  91162. # endif /* FLAC__HAS_NASM */
  91163. # endif /* FLAC__CPU_IA32 */
  91164. }
  91165. # endif /* !FLAC__NO_ASM */
  91166. #endif /* !FLAC__INTEGER_ONLY_LIBRARY */
  91167. if(encoder->private_->use_wide_by_block) {
  91168. encoder->private_->local_fixed_compute_best_predictor = FLAC__fixed_compute_best_predictor_wide;
  91169. }
  91170. encoder->protected_->state = FLAC__STREAM_ENCODER_OK;
  91171. #if FLAC__HAS_OGG
  91172. encoder->private_->is_ogg = is_ogg;
  91173. if(is_ogg && !FLAC__ogg_encoder_aspect_init(&encoder->protected_->ogg_encoder_aspect)) {
  91174. encoder->protected_->state = FLAC__STREAM_ENCODER_OGG_ERROR;
  91175. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  91176. }
  91177. #endif
  91178. encoder->private_->read_callback = read_callback;
  91179. encoder->private_->write_callback = write_callback;
  91180. encoder->private_->seek_callback = seek_callback;
  91181. encoder->private_->tell_callback = tell_callback;
  91182. encoder->private_->metadata_callback = metadata_callback;
  91183. encoder->private_->client_data = client_data;
  91184. if(!resize_buffers_(encoder, encoder->protected_->blocksize)) {
  91185. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  91186. }
  91187. if(!FLAC__bitwriter_init(encoder->private_->frame)) {
  91188. encoder->protected_->state = FLAC__STREAM_ENCODER_MEMORY_ALLOCATION_ERROR;
  91189. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  91190. }
  91191. if(encoder->protected_->verify) {
  91192. encoder->private_->verify.input_fifo.size = encoder->protected_->blocksize+OVERREAD_;
  91193. for(i = 0; i < encoder->protected_->channels; i++) {
  91194. 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))) {
  91195. encoder->protected_->state = FLAC__STREAM_ENCODER_MEMORY_ALLOCATION_ERROR;
  91196. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  91197. }
  91198. }
  91199. encoder->private_->verify.input_fifo.tail = 0;
  91200. encoder->private_->verify.decoder = FLAC__stream_decoder_new();
  91201. if(0 == encoder->private_->verify.decoder) {
  91202. encoder->protected_->state = FLAC__STREAM_ENCODER_VERIFY_DECODER_ERROR;
  91203. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  91204. }
  91205. 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) {
  91206. encoder->protected_->state = FLAC__STREAM_ENCODER_VERIFY_DECODER_ERROR;
  91207. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  91208. }
  91209. }
  91210. encoder->private_->verify.error_stats.absolute_sample = 0;
  91211. encoder->private_->verify.error_stats.frame_number = 0;
  91212. encoder->private_->verify.error_stats.channel = 0;
  91213. encoder->private_->verify.error_stats.sample = 0;
  91214. encoder->private_->verify.error_stats.expected = 0;
  91215. encoder->private_->verify.error_stats.got = 0;
  91216. encoder->private_->first_seekpoint_to_check = 0;
  91217. encoder->private_->samples_written = 0;
  91218. encoder->protected_->streaminfo_offset = 0;
  91219. encoder->protected_->seektable_offset = 0;
  91220. encoder->protected_->audio_offset = 0;
  91221. if(encoder->protected_->verify)
  91222. encoder->private_->verify.state_hint = ENCODER_IN_MAGIC;
  91223. if(!FLAC__bitwriter_write_raw_uint32(encoder->private_->frame, FLAC__STREAM_SYNC, FLAC__STREAM_SYNC_LEN)) {
  91224. encoder->protected_->state = FLAC__STREAM_ENCODER_FRAMING_ERROR;
  91225. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  91226. }
  91227. if(!write_bitbuffer_(encoder, 0, /*is_last_block=*/false)) {
  91228. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  91229. }
  91230. if(encoder->protected_->verify)
  91231. encoder->private_->verify.state_hint = ENCODER_IN_METADATA;
  91232. encoder->private_->streaminfo.type = FLAC__METADATA_TYPE_STREAMINFO;
  91233. encoder->private_->streaminfo.is_last = false; /* we will have at a minimum a VORBIS_COMMENT afterwards */
  91234. encoder->private_->streaminfo.length = FLAC__STREAM_METADATA_STREAMINFO_LENGTH;
  91235. encoder->private_->streaminfo.data.stream_info.min_blocksize = encoder->protected_->blocksize; /* this encoder uses the same blocksize for the whole stream */
  91236. encoder->private_->streaminfo.data.stream_info.max_blocksize = encoder->protected_->blocksize;
  91237. encoder->private_->streaminfo.data.stream_info.min_framesize = 0; /* we don't know this yet; have to fill it in later */
  91238. encoder->private_->streaminfo.data.stream_info.max_framesize = 0; /* we don't know this yet; have to fill it in later */
  91239. encoder->private_->streaminfo.data.stream_info.sample_rate = encoder->protected_->sample_rate;
  91240. encoder->private_->streaminfo.data.stream_info.channels = encoder->protected_->channels;
  91241. encoder->private_->streaminfo.data.stream_info.bits_per_sample = encoder->protected_->bits_per_sample;
  91242. encoder->private_->streaminfo.data.stream_info.total_samples = encoder->protected_->total_samples_estimate; /* we will replace this later with the real total */
  91243. memset(encoder->private_->streaminfo.data.stream_info.md5sum, 0, 16); /* we don't know this yet; have to fill it in later */
  91244. if(encoder->protected_->do_md5)
  91245. FLAC__MD5Init(&encoder->private_->md5context);
  91246. if(!FLAC__add_metadata_block(&encoder->private_->streaminfo, encoder->private_->frame)) {
  91247. encoder->protected_->state = FLAC__STREAM_ENCODER_FRAMING_ERROR;
  91248. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  91249. }
  91250. if(!write_bitbuffer_(encoder, 0, /*is_last_block=*/false)) {
  91251. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  91252. }
  91253. encoder->private_->streaminfo.data.stream_info.min_framesize = (1u << FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN) - 1;
  91254. encoder->private_->streaminfo.data.stream_info.total_samples = 0;
  91255. if(!metadata_has_vorbis_comment) {
  91256. FLAC__StreamMetadata vorbis_comment;
  91257. vorbis_comment.type = FLAC__METADATA_TYPE_VORBIS_COMMENT;
  91258. vorbis_comment.is_last = (encoder->protected_->num_metadata_blocks == 0);
  91259. vorbis_comment.length = 4 + 4; /* MAGIC NUMBER */
  91260. vorbis_comment.data.vorbis_comment.vendor_string.length = 0;
  91261. vorbis_comment.data.vorbis_comment.vendor_string.entry = 0;
  91262. vorbis_comment.data.vorbis_comment.num_comments = 0;
  91263. vorbis_comment.data.vorbis_comment.comments = 0;
  91264. if(!FLAC__add_metadata_block(&vorbis_comment, encoder->private_->frame)) {
  91265. encoder->protected_->state = FLAC__STREAM_ENCODER_FRAMING_ERROR;
  91266. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  91267. }
  91268. if(!write_bitbuffer_(encoder, 0, /*is_last_block=*/false)) {
  91269. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  91270. }
  91271. }
  91272. for(i = 0; i < encoder->protected_->num_metadata_blocks; i++) {
  91273. encoder->protected_->metadata[i]->is_last = (i == encoder->protected_->num_metadata_blocks - 1);
  91274. if(!FLAC__add_metadata_block(encoder->protected_->metadata[i], encoder->private_->frame)) {
  91275. encoder->protected_->state = FLAC__STREAM_ENCODER_FRAMING_ERROR;
  91276. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  91277. }
  91278. if(!write_bitbuffer_(encoder, 0, /*is_last_block=*/false)) {
  91279. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  91280. }
  91281. }
  91282. 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 */
  91283. encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
  91284. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  91285. }
  91286. if(encoder->protected_->verify)
  91287. encoder->private_->verify.state_hint = ENCODER_IN_AUDIO;
  91288. return FLAC__STREAM_ENCODER_INIT_STATUS_OK;
  91289. }
  91290. FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_stream(
  91291. FLAC__StreamEncoder *encoder,
  91292. FLAC__StreamEncoderWriteCallback write_callback,
  91293. FLAC__StreamEncoderSeekCallback seek_callback,
  91294. FLAC__StreamEncoderTellCallback tell_callback,
  91295. FLAC__StreamEncoderMetadataCallback metadata_callback,
  91296. void *client_data
  91297. )
  91298. {
  91299. return init_stream_internal_enc(
  91300. encoder,
  91301. 0,
  91302. write_callback,
  91303. seek_callback,
  91304. tell_callback,
  91305. metadata_callback,
  91306. client_data,
  91307. false
  91308. );
  91309. }
  91310. FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_ogg_stream(
  91311. FLAC__StreamEncoder *encoder,
  91312. FLAC__StreamEncoderReadCallback read_callback,
  91313. FLAC__StreamEncoderWriteCallback write_callback,
  91314. FLAC__StreamEncoderSeekCallback seek_callback,
  91315. FLAC__StreamEncoderTellCallback tell_callback,
  91316. FLAC__StreamEncoderMetadataCallback metadata_callback,
  91317. void *client_data
  91318. )
  91319. {
  91320. return init_stream_internal_enc(
  91321. encoder,
  91322. read_callback,
  91323. write_callback,
  91324. seek_callback,
  91325. tell_callback,
  91326. metadata_callback,
  91327. client_data,
  91328. true
  91329. );
  91330. }
  91331. static FLAC__StreamEncoderInitStatus init_FILE_internal_enc(
  91332. FLAC__StreamEncoder *encoder,
  91333. FILE *file,
  91334. FLAC__StreamEncoderProgressCallback progress_callback,
  91335. void *client_data,
  91336. FLAC__bool is_ogg
  91337. )
  91338. {
  91339. FLAC__StreamEncoderInitStatus init_status;
  91340. FLAC__ASSERT(0 != encoder);
  91341. FLAC__ASSERT(0 != file);
  91342. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  91343. return FLAC__STREAM_ENCODER_INIT_STATUS_ALREADY_INITIALIZED;
  91344. if(file == 0) {
  91345. encoder->protected_->state = FLAC__STREAM_ENCODER_IO_ERROR;
  91346. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  91347. }
  91348. if(file == stdout)
  91349. file = get_binary_stdout_(); /* just to be safe */
  91350. encoder->private_->file = file;
  91351. encoder->private_->progress_callback = progress_callback;
  91352. encoder->private_->bytes_written = 0;
  91353. encoder->private_->samples_written = 0;
  91354. encoder->private_->frames_written = 0;
  91355. init_status = init_stream_internal_enc(
  91356. encoder,
  91357. encoder->private_->file == stdout? 0 : is_ogg? file_read_callback_enc : 0,
  91358. file_write_callback_,
  91359. encoder->private_->file == stdout? 0 : file_seek_callback_enc,
  91360. encoder->private_->file == stdout? 0 : file_tell_callback_enc,
  91361. 0,
  91362. client_data,
  91363. is_ogg
  91364. );
  91365. if(init_status != FLAC__STREAM_ENCODER_INIT_STATUS_OK) {
  91366. return init_status;
  91367. }
  91368. {
  91369. unsigned blocksize = FLAC__stream_encoder_get_blocksize(encoder);
  91370. FLAC__ASSERT(blocksize != 0);
  91371. encoder->private_->total_frames_estimate = (unsigned)((FLAC__stream_encoder_get_total_samples_estimate(encoder) + blocksize - 1) / blocksize);
  91372. }
  91373. return init_status;
  91374. }
  91375. FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_FILE(
  91376. FLAC__StreamEncoder *encoder,
  91377. FILE *file,
  91378. FLAC__StreamEncoderProgressCallback progress_callback,
  91379. void *client_data
  91380. )
  91381. {
  91382. return init_FILE_internal_enc(encoder, file, progress_callback, client_data, /*is_ogg=*/false);
  91383. }
  91384. FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_ogg_FILE(
  91385. FLAC__StreamEncoder *encoder,
  91386. FILE *file,
  91387. FLAC__StreamEncoderProgressCallback progress_callback,
  91388. void *client_data
  91389. )
  91390. {
  91391. return init_FILE_internal_enc(encoder, file, progress_callback, client_data, /*is_ogg=*/true);
  91392. }
  91393. static FLAC__StreamEncoderInitStatus init_file_internal_enc(
  91394. FLAC__StreamEncoder *encoder,
  91395. const char *filename,
  91396. FLAC__StreamEncoderProgressCallback progress_callback,
  91397. void *client_data,
  91398. FLAC__bool is_ogg
  91399. )
  91400. {
  91401. FILE *file;
  91402. FLAC__ASSERT(0 != encoder);
  91403. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  91404. return FLAC__STREAM_ENCODER_INIT_STATUS_ALREADY_INITIALIZED;
  91405. file = filename? fopen(filename, "w+b") : stdout;
  91406. if(file == 0) {
  91407. encoder->protected_->state = FLAC__STREAM_ENCODER_IO_ERROR;
  91408. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  91409. }
  91410. return init_FILE_internal_enc(encoder, file, progress_callback, client_data, is_ogg);
  91411. }
  91412. FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_file(
  91413. FLAC__StreamEncoder *encoder,
  91414. const char *filename,
  91415. FLAC__StreamEncoderProgressCallback progress_callback,
  91416. void *client_data
  91417. )
  91418. {
  91419. return init_file_internal_enc(encoder, filename, progress_callback, client_data, /*is_ogg=*/false);
  91420. }
  91421. FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_ogg_file(
  91422. FLAC__StreamEncoder *encoder,
  91423. const char *filename,
  91424. FLAC__StreamEncoderProgressCallback progress_callback,
  91425. void *client_data
  91426. )
  91427. {
  91428. return init_file_internal_enc(encoder, filename, progress_callback, client_data, /*is_ogg=*/true);
  91429. }
  91430. FLAC_API FLAC__bool FLAC__stream_encoder_finish(FLAC__StreamEncoder *encoder)
  91431. {
  91432. FLAC__bool error = false;
  91433. FLAC__ASSERT(0 != encoder);
  91434. FLAC__ASSERT(0 != encoder->private_);
  91435. FLAC__ASSERT(0 != encoder->protected_);
  91436. if(encoder->protected_->state == FLAC__STREAM_ENCODER_UNINITIALIZED)
  91437. return true;
  91438. if(encoder->protected_->state == FLAC__STREAM_ENCODER_OK && !encoder->private_->is_being_deleted) {
  91439. if(encoder->private_->current_sample_number != 0) {
  91440. const FLAC__bool is_fractional_block = encoder->protected_->blocksize != encoder->private_->current_sample_number;
  91441. encoder->protected_->blocksize = encoder->private_->current_sample_number;
  91442. if(!process_frame_(encoder, is_fractional_block, /*is_last_block=*/true))
  91443. error = true;
  91444. }
  91445. }
  91446. if(encoder->protected_->do_md5)
  91447. FLAC__MD5Final(encoder->private_->streaminfo.data.stream_info.md5sum, &encoder->private_->md5context);
  91448. if(!encoder->private_->is_being_deleted) {
  91449. if(encoder->protected_->state == FLAC__STREAM_ENCODER_OK) {
  91450. if(encoder->private_->seek_callback) {
  91451. #if FLAC__HAS_OGG
  91452. if(encoder->private_->is_ogg)
  91453. update_ogg_metadata_(encoder);
  91454. else
  91455. #endif
  91456. update_metadata_(encoder);
  91457. if(encoder->protected_->state != FLAC__STREAM_ENCODER_OK)
  91458. error = true;
  91459. }
  91460. if(encoder->private_->metadata_callback)
  91461. encoder->private_->metadata_callback(encoder, &encoder->private_->streaminfo, encoder->private_->client_data);
  91462. }
  91463. if(encoder->protected_->verify && 0 != encoder->private_->verify.decoder && !FLAC__stream_decoder_finish(encoder->private_->verify.decoder)) {
  91464. if(!error)
  91465. encoder->protected_->state = FLAC__STREAM_ENCODER_VERIFY_MISMATCH_IN_AUDIO_DATA;
  91466. error = true;
  91467. }
  91468. }
  91469. if(0 != encoder->private_->file) {
  91470. if(encoder->private_->file != stdout)
  91471. fclose(encoder->private_->file);
  91472. encoder->private_->file = 0;
  91473. }
  91474. #if FLAC__HAS_OGG
  91475. if(encoder->private_->is_ogg)
  91476. FLAC__ogg_encoder_aspect_finish(&encoder->protected_->ogg_encoder_aspect);
  91477. #endif
  91478. free_(encoder);
  91479. set_defaults_enc(encoder);
  91480. if(!error)
  91481. encoder->protected_->state = FLAC__STREAM_ENCODER_UNINITIALIZED;
  91482. return !error;
  91483. }
  91484. FLAC_API FLAC__bool FLAC__stream_encoder_set_ogg_serial_number(FLAC__StreamEncoder *encoder, long value)
  91485. {
  91486. FLAC__ASSERT(0 != encoder);
  91487. FLAC__ASSERT(0 != encoder->private_);
  91488. FLAC__ASSERT(0 != encoder->protected_);
  91489. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  91490. return false;
  91491. #if FLAC__HAS_OGG
  91492. FLAC__ogg_encoder_aspect_set_serial_number(&encoder->protected_->ogg_encoder_aspect, value);
  91493. return true;
  91494. #else
  91495. (void)value;
  91496. return false;
  91497. #endif
  91498. }
  91499. FLAC_API FLAC__bool FLAC__stream_encoder_set_verify(FLAC__StreamEncoder *encoder, FLAC__bool value)
  91500. {
  91501. FLAC__ASSERT(0 != encoder);
  91502. FLAC__ASSERT(0 != encoder->private_);
  91503. FLAC__ASSERT(0 != encoder->protected_);
  91504. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  91505. return false;
  91506. #ifndef FLAC__MANDATORY_VERIFY_WHILE_ENCODING
  91507. encoder->protected_->verify = value;
  91508. #endif
  91509. return true;
  91510. }
  91511. FLAC_API FLAC__bool FLAC__stream_encoder_set_streamable_subset(FLAC__StreamEncoder *encoder, FLAC__bool value)
  91512. {
  91513. FLAC__ASSERT(0 != encoder);
  91514. FLAC__ASSERT(0 != encoder->private_);
  91515. FLAC__ASSERT(0 != encoder->protected_);
  91516. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  91517. return false;
  91518. encoder->protected_->streamable_subset = value;
  91519. return true;
  91520. }
  91521. FLAC_API FLAC__bool FLAC__stream_encoder_set_do_md5(FLAC__StreamEncoder *encoder, FLAC__bool value)
  91522. {
  91523. FLAC__ASSERT(0 != encoder);
  91524. FLAC__ASSERT(0 != encoder->private_);
  91525. FLAC__ASSERT(0 != encoder->protected_);
  91526. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  91527. return false;
  91528. encoder->protected_->do_md5 = value;
  91529. return true;
  91530. }
  91531. FLAC_API FLAC__bool FLAC__stream_encoder_set_channels(FLAC__StreamEncoder *encoder, unsigned value)
  91532. {
  91533. FLAC__ASSERT(0 != encoder);
  91534. FLAC__ASSERT(0 != encoder->private_);
  91535. FLAC__ASSERT(0 != encoder->protected_);
  91536. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  91537. return false;
  91538. encoder->protected_->channels = value;
  91539. return true;
  91540. }
  91541. FLAC_API FLAC__bool FLAC__stream_encoder_set_bits_per_sample(FLAC__StreamEncoder *encoder, unsigned value)
  91542. {
  91543. FLAC__ASSERT(0 != encoder);
  91544. FLAC__ASSERT(0 != encoder->private_);
  91545. FLAC__ASSERT(0 != encoder->protected_);
  91546. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  91547. return false;
  91548. encoder->protected_->bits_per_sample = value;
  91549. return true;
  91550. }
  91551. FLAC_API FLAC__bool FLAC__stream_encoder_set_sample_rate(FLAC__StreamEncoder *encoder, unsigned value)
  91552. {
  91553. FLAC__ASSERT(0 != encoder);
  91554. FLAC__ASSERT(0 != encoder->private_);
  91555. FLAC__ASSERT(0 != encoder->protected_);
  91556. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  91557. return false;
  91558. encoder->protected_->sample_rate = value;
  91559. return true;
  91560. }
  91561. FLAC_API FLAC__bool FLAC__stream_encoder_set_compression_level(FLAC__StreamEncoder *encoder, unsigned value)
  91562. {
  91563. FLAC__bool ok = true;
  91564. FLAC__ASSERT(0 != encoder);
  91565. FLAC__ASSERT(0 != encoder->private_);
  91566. FLAC__ASSERT(0 != encoder->protected_);
  91567. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  91568. return false;
  91569. if(value >= sizeof(compression_levels_)/sizeof(compression_levels_[0]))
  91570. value = sizeof(compression_levels_)/sizeof(compression_levels_[0]) - 1;
  91571. ok &= FLAC__stream_encoder_set_do_mid_side_stereo (encoder, compression_levels_[value].do_mid_side_stereo);
  91572. ok &= FLAC__stream_encoder_set_loose_mid_side_stereo (encoder, compression_levels_[value].loose_mid_side_stereo);
  91573. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  91574. #if 0
  91575. ok &= FLAC__stream_encoder_set_apodization (encoder, compression_levels_[value].apodization);
  91576. #else
  91577. encoder->protected_->num_apodizations = 1;
  91578. encoder->protected_->apodizations[0].type = FLAC__APODIZATION_TUKEY;
  91579. encoder->protected_->apodizations[0].parameters.tukey.p = 0.5;
  91580. #endif
  91581. #endif
  91582. ok &= FLAC__stream_encoder_set_max_lpc_order (encoder, compression_levels_[value].max_lpc_order);
  91583. ok &= FLAC__stream_encoder_set_qlp_coeff_precision (encoder, compression_levels_[value].qlp_coeff_precision);
  91584. ok &= FLAC__stream_encoder_set_do_qlp_coeff_prec_search (encoder, compression_levels_[value].do_qlp_coeff_prec_search);
  91585. ok &= FLAC__stream_encoder_set_do_escape_coding (encoder, compression_levels_[value].do_escape_coding);
  91586. ok &= FLAC__stream_encoder_set_do_exhaustive_model_search (encoder, compression_levels_[value].do_exhaustive_model_search);
  91587. ok &= FLAC__stream_encoder_set_min_residual_partition_order(encoder, compression_levels_[value].min_residual_partition_order);
  91588. ok &= FLAC__stream_encoder_set_max_residual_partition_order(encoder, compression_levels_[value].max_residual_partition_order);
  91589. ok &= FLAC__stream_encoder_set_rice_parameter_search_dist (encoder, compression_levels_[value].rice_parameter_search_dist);
  91590. return ok;
  91591. }
  91592. FLAC_API FLAC__bool FLAC__stream_encoder_set_blocksize(FLAC__StreamEncoder *encoder, unsigned value)
  91593. {
  91594. FLAC__ASSERT(0 != encoder);
  91595. FLAC__ASSERT(0 != encoder->private_);
  91596. FLAC__ASSERT(0 != encoder->protected_);
  91597. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  91598. return false;
  91599. encoder->protected_->blocksize = value;
  91600. return true;
  91601. }
  91602. FLAC_API FLAC__bool FLAC__stream_encoder_set_do_mid_side_stereo(FLAC__StreamEncoder *encoder, FLAC__bool value)
  91603. {
  91604. FLAC__ASSERT(0 != encoder);
  91605. FLAC__ASSERT(0 != encoder->private_);
  91606. FLAC__ASSERT(0 != encoder->protected_);
  91607. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  91608. return false;
  91609. encoder->protected_->do_mid_side_stereo = value;
  91610. return true;
  91611. }
  91612. FLAC_API FLAC__bool FLAC__stream_encoder_set_loose_mid_side_stereo(FLAC__StreamEncoder *encoder, FLAC__bool value)
  91613. {
  91614. FLAC__ASSERT(0 != encoder);
  91615. FLAC__ASSERT(0 != encoder->private_);
  91616. FLAC__ASSERT(0 != encoder->protected_);
  91617. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  91618. return false;
  91619. encoder->protected_->loose_mid_side_stereo = value;
  91620. return true;
  91621. }
  91622. FLAC_API FLAC__bool FLAC__stream_encoder_set_apodization(FLAC__StreamEncoder *encoder, const char *specification)
  91623. {
  91624. FLAC__ASSERT(0 != encoder);
  91625. FLAC__ASSERT(0 != encoder->private_);
  91626. FLAC__ASSERT(0 != encoder->protected_);
  91627. FLAC__ASSERT(0 != specification);
  91628. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  91629. return false;
  91630. #ifdef FLAC__INTEGER_ONLY_LIBRARY
  91631. (void)specification; /* silently ignore since we haven't integerized; will always use a rectangular window */
  91632. #else
  91633. encoder->protected_->num_apodizations = 0;
  91634. while(1) {
  91635. const char *s = strchr(specification, ';');
  91636. const size_t n = s? (size_t)(s - specification) : strlen(specification);
  91637. if (n==8 && 0 == strncmp("bartlett" , specification, n))
  91638. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_BARTLETT;
  91639. else if(n==13 && 0 == strncmp("bartlett_hann", specification, n))
  91640. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_BARTLETT_HANN;
  91641. else if(n==8 && 0 == strncmp("blackman" , specification, n))
  91642. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_BLACKMAN;
  91643. else if(n==26 && 0 == strncmp("blackman_harris_4term_92db", specification, n))
  91644. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_BLACKMAN_HARRIS_4TERM_92DB_SIDELOBE;
  91645. else if(n==6 && 0 == strncmp("connes" , specification, n))
  91646. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_CONNES;
  91647. else if(n==7 && 0 == strncmp("flattop" , specification, n))
  91648. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_FLATTOP;
  91649. else if(n>7 && 0 == strncmp("gauss(" , specification, 6)) {
  91650. FLAC__real stddev = (FLAC__real)strtod(specification+6, 0);
  91651. if (stddev > 0.0 && stddev <= 0.5) {
  91652. encoder->protected_->apodizations[encoder->protected_->num_apodizations].parameters.gauss.stddev = stddev;
  91653. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_GAUSS;
  91654. }
  91655. }
  91656. else if(n==7 && 0 == strncmp("hamming" , specification, n))
  91657. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_HAMMING;
  91658. else if(n==4 && 0 == strncmp("hann" , specification, n))
  91659. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_HANN;
  91660. else if(n==13 && 0 == strncmp("kaiser_bessel", specification, n))
  91661. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_KAISER_BESSEL;
  91662. else if(n==7 && 0 == strncmp("nuttall" , specification, n))
  91663. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_NUTTALL;
  91664. else if(n==9 && 0 == strncmp("rectangle" , specification, n))
  91665. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_RECTANGLE;
  91666. else if(n==8 && 0 == strncmp("triangle" , specification, n))
  91667. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_TRIANGLE;
  91668. else if(n>7 && 0 == strncmp("tukey(" , specification, 6)) {
  91669. FLAC__real p = (FLAC__real)strtod(specification+6, 0);
  91670. if (p >= 0.0 && p <= 1.0) {
  91671. encoder->protected_->apodizations[encoder->protected_->num_apodizations].parameters.tukey.p = p;
  91672. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_TUKEY;
  91673. }
  91674. }
  91675. else if(n==5 && 0 == strncmp("welch" , specification, n))
  91676. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_WELCH;
  91677. if (encoder->protected_->num_apodizations == 32)
  91678. break;
  91679. if (s)
  91680. specification = s+1;
  91681. else
  91682. break;
  91683. }
  91684. if(encoder->protected_->num_apodizations == 0) {
  91685. encoder->protected_->num_apodizations = 1;
  91686. encoder->protected_->apodizations[0].type = FLAC__APODIZATION_TUKEY;
  91687. encoder->protected_->apodizations[0].parameters.tukey.p = 0.5;
  91688. }
  91689. #endif
  91690. return true;
  91691. }
  91692. FLAC_API FLAC__bool FLAC__stream_encoder_set_max_lpc_order(FLAC__StreamEncoder *encoder, unsigned value)
  91693. {
  91694. FLAC__ASSERT(0 != encoder);
  91695. FLAC__ASSERT(0 != encoder->private_);
  91696. FLAC__ASSERT(0 != encoder->protected_);
  91697. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  91698. return false;
  91699. encoder->protected_->max_lpc_order = value;
  91700. return true;
  91701. }
  91702. FLAC_API FLAC__bool FLAC__stream_encoder_set_qlp_coeff_precision(FLAC__StreamEncoder *encoder, unsigned value)
  91703. {
  91704. FLAC__ASSERT(0 != encoder);
  91705. FLAC__ASSERT(0 != encoder->private_);
  91706. FLAC__ASSERT(0 != encoder->protected_);
  91707. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  91708. return false;
  91709. encoder->protected_->qlp_coeff_precision = value;
  91710. return true;
  91711. }
  91712. FLAC_API FLAC__bool FLAC__stream_encoder_set_do_qlp_coeff_prec_search(FLAC__StreamEncoder *encoder, FLAC__bool value)
  91713. {
  91714. FLAC__ASSERT(0 != encoder);
  91715. FLAC__ASSERT(0 != encoder->private_);
  91716. FLAC__ASSERT(0 != encoder->protected_);
  91717. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  91718. return false;
  91719. encoder->protected_->do_qlp_coeff_prec_search = value;
  91720. return true;
  91721. }
  91722. FLAC_API FLAC__bool FLAC__stream_encoder_set_do_escape_coding(FLAC__StreamEncoder *encoder, FLAC__bool value)
  91723. {
  91724. FLAC__ASSERT(0 != encoder);
  91725. FLAC__ASSERT(0 != encoder->private_);
  91726. FLAC__ASSERT(0 != encoder->protected_);
  91727. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  91728. return false;
  91729. #if 0
  91730. encoder->protected_->do_escape_coding = value;
  91731. #else
  91732. (void)value;
  91733. #endif
  91734. return true;
  91735. }
  91736. FLAC_API FLAC__bool FLAC__stream_encoder_set_do_exhaustive_model_search(FLAC__StreamEncoder *encoder, FLAC__bool value)
  91737. {
  91738. FLAC__ASSERT(0 != encoder);
  91739. FLAC__ASSERT(0 != encoder->private_);
  91740. FLAC__ASSERT(0 != encoder->protected_);
  91741. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  91742. return false;
  91743. encoder->protected_->do_exhaustive_model_search = value;
  91744. return true;
  91745. }
  91746. FLAC_API FLAC__bool FLAC__stream_encoder_set_min_residual_partition_order(FLAC__StreamEncoder *encoder, unsigned value)
  91747. {
  91748. FLAC__ASSERT(0 != encoder);
  91749. FLAC__ASSERT(0 != encoder->private_);
  91750. FLAC__ASSERT(0 != encoder->protected_);
  91751. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  91752. return false;
  91753. encoder->protected_->min_residual_partition_order = value;
  91754. return true;
  91755. }
  91756. FLAC_API FLAC__bool FLAC__stream_encoder_set_max_residual_partition_order(FLAC__StreamEncoder *encoder, unsigned value)
  91757. {
  91758. FLAC__ASSERT(0 != encoder);
  91759. FLAC__ASSERT(0 != encoder->private_);
  91760. FLAC__ASSERT(0 != encoder->protected_);
  91761. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  91762. return false;
  91763. encoder->protected_->max_residual_partition_order = value;
  91764. return true;
  91765. }
  91766. FLAC_API FLAC__bool FLAC__stream_encoder_set_rice_parameter_search_dist(FLAC__StreamEncoder *encoder, unsigned value)
  91767. {
  91768. FLAC__ASSERT(0 != encoder);
  91769. FLAC__ASSERT(0 != encoder->private_);
  91770. FLAC__ASSERT(0 != encoder->protected_);
  91771. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  91772. return false;
  91773. #if 0
  91774. encoder->protected_->rice_parameter_search_dist = value;
  91775. #else
  91776. (void)value;
  91777. #endif
  91778. return true;
  91779. }
  91780. FLAC_API FLAC__bool FLAC__stream_encoder_set_total_samples_estimate(FLAC__StreamEncoder *encoder, FLAC__uint64 value)
  91781. {
  91782. FLAC__ASSERT(0 != encoder);
  91783. FLAC__ASSERT(0 != encoder->private_);
  91784. FLAC__ASSERT(0 != encoder->protected_);
  91785. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  91786. return false;
  91787. encoder->protected_->total_samples_estimate = value;
  91788. return true;
  91789. }
  91790. FLAC_API FLAC__bool FLAC__stream_encoder_set_metadata(FLAC__StreamEncoder *encoder, FLAC__StreamMetadata **metadata, unsigned num_blocks)
  91791. {
  91792. FLAC__ASSERT(0 != encoder);
  91793. FLAC__ASSERT(0 != encoder->private_);
  91794. FLAC__ASSERT(0 != encoder->protected_);
  91795. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  91796. return false;
  91797. if(0 == metadata)
  91798. num_blocks = 0;
  91799. if(0 == num_blocks)
  91800. metadata = 0;
  91801. if(encoder->protected_->metadata) {
  91802. free(encoder->protected_->metadata);
  91803. encoder->protected_->metadata = 0;
  91804. encoder->protected_->num_metadata_blocks = 0;
  91805. }
  91806. if(num_blocks) {
  91807. FLAC__StreamMetadata **m;
  91808. if(0 == (m = (FLAC__StreamMetadata**)safe_malloc_mul_2op_(sizeof(m[0]), /*times*/num_blocks)))
  91809. return false;
  91810. memcpy(m, metadata, sizeof(m[0]) * num_blocks);
  91811. encoder->protected_->metadata = m;
  91812. encoder->protected_->num_metadata_blocks = num_blocks;
  91813. }
  91814. #if FLAC__HAS_OGG
  91815. if(!FLAC__ogg_encoder_aspect_set_num_metadata(&encoder->protected_->ogg_encoder_aspect, num_blocks))
  91816. return false;
  91817. #endif
  91818. return true;
  91819. }
  91820. FLAC_API FLAC__bool FLAC__stream_encoder_disable_constant_subframes(FLAC__StreamEncoder *encoder, FLAC__bool value)
  91821. {
  91822. FLAC__ASSERT(0 != encoder);
  91823. FLAC__ASSERT(0 != encoder->private_);
  91824. FLAC__ASSERT(0 != encoder->protected_);
  91825. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  91826. return false;
  91827. encoder->private_->disable_constant_subframes = value;
  91828. return true;
  91829. }
  91830. FLAC_API FLAC__bool FLAC__stream_encoder_disable_fixed_subframes(FLAC__StreamEncoder *encoder, FLAC__bool value)
  91831. {
  91832. FLAC__ASSERT(0 != encoder);
  91833. FLAC__ASSERT(0 != encoder->private_);
  91834. FLAC__ASSERT(0 != encoder->protected_);
  91835. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  91836. return false;
  91837. encoder->private_->disable_fixed_subframes = value;
  91838. return true;
  91839. }
  91840. FLAC_API FLAC__bool FLAC__stream_encoder_disable_verbatim_subframes(FLAC__StreamEncoder *encoder, FLAC__bool value)
  91841. {
  91842. FLAC__ASSERT(0 != encoder);
  91843. FLAC__ASSERT(0 != encoder->private_);
  91844. FLAC__ASSERT(0 != encoder->protected_);
  91845. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  91846. return false;
  91847. encoder->private_->disable_verbatim_subframes = value;
  91848. return true;
  91849. }
  91850. FLAC_API FLAC__StreamEncoderState FLAC__stream_encoder_get_state(const FLAC__StreamEncoder *encoder)
  91851. {
  91852. FLAC__ASSERT(0 != encoder);
  91853. FLAC__ASSERT(0 != encoder->private_);
  91854. FLAC__ASSERT(0 != encoder->protected_);
  91855. return encoder->protected_->state;
  91856. }
  91857. FLAC_API FLAC__StreamDecoderState FLAC__stream_encoder_get_verify_decoder_state(const FLAC__StreamEncoder *encoder)
  91858. {
  91859. FLAC__ASSERT(0 != encoder);
  91860. FLAC__ASSERT(0 != encoder->private_);
  91861. FLAC__ASSERT(0 != encoder->protected_);
  91862. if(encoder->protected_->verify)
  91863. return FLAC__stream_decoder_get_state(encoder->private_->verify.decoder);
  91864. else
  91865. return FLAC__STREAM_DECODER_UNINITIALIZED;
  91866. }
  91867. FLAC_API const char *FLAC__stream_encoder_get_resolved_state_string(const FLAC__StreamEncoder *encoder)
  91868. {
  91869. FLAC__ASSERT(0 != encoder);
  91870. FLAC__ASSERT(0 != encoder->private_);
  91871. FLAC__ASSERT(0 != encoder->protected_);
  91872. if(encoder->protected_->state != FLAC__STREAM_ENCODER_VERIFY_DECODER_ERROR)
  91873. return FLAC__StreamEncoderStateString[encoder->protected_->state];
  91874. else
  91875. return FLAC__stream_decoder_get_resolved_state_string(encoder->private_->verify.decoder);
  91876. }
  91877. 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)
  91878. {
  91879. FLAC__ASSERT(0 != encoder);
  91880. FLAC__ASSERT(0 != encoder->private_);
  91881. FLAC__ASSERT(0 != encoder->protected_);
  91882. if(0 != absolute_sample)
  91883. *absolute_sample = encoder->private_->verify.error_stats.absolute_sample;
  91884. if(0 != frame_number)
  91885. *frame_number = encoder->private_->verify.error_stats.frame_number;
  91886. if(0 != channel)
  91887. *channel = encoder->private_->verify.error_stats.channel;
  91888. if(0 != sample)
  91889. *sample = encoder->private_->verify.error_stats.sample;
  91890. if(0 != expected)
  91891. *expected = encoder->private_->verify.error_stats.expected;
  91892. if(0 != got)
  91893. *got = encoder->private_->verify.error_stats.got;
  91894. }
  91895. FLAC_API FLAC__bool FLAC__stream_encoder_get_verify(const FLAC__StreamEncoder *encoder)
  91896. {
  91897. FLAC__ASSERT(0 != encoder);
  91898. FLAC__ASSERT(0 != encoder->private_);
  91899. FLAC__ASSERT(0 != encoder->protected_);
  91900. return encoder->protected_->verify;
  91901. }
  91902. FLAC_API FLAC__bool FLAC__stream_encoder_get_streamable_subset(const FLAC__StreamEncoder *encoder)
  91903. {
  91904. FLAC__ASSERT(0 != encoder);
  91905. FLAC__ASSERT(0 != encoder->private_);
  91906. FLAC__ASSERT(0 != encoder->protected_);
  91907. return encoder->protected_->streamable_subset;
  91908. }
  91909. FLAC_API FLAC__bool FLAC__stream_encoder_get_do_md5(const FLAC__StreamEncoder *encoder)
  91910. {
  91911. FLAC__ASSERT(0 != encoder);
  91912. FLAC__ASSERT(0 != encoder->private_);
  91913. FLAC__ASSERT(0 != encoder->protected_);
  91914. return encoder->protected_->do_md5;
  91915. }
  91916. FLAC_API unsigned FLAC__stream_encoder_get_channels(const FLAC__StreamEncoder *encoder)
  91917. {
  91918. FLAC__ASSERT(0 != encoder);
  91919. FLAC__ASSERT(0 != encoder->private_);
  91920. FLAC__ASSERT(0 != encoder->protected_);
  91921. return encoder->protected_->channels;
  91922. }
  91923. FLAC_API unsigned FLAC__stream_encoder_get_bits_per_sample(const FLAC__StreamEncoder *encoder)
  91924. {
  91925. FLAC__ASSERT(0 != encoder);
  91926. FLAC__ASSERT(0 != encoder->private_);
  91927. FLAC__ASSERT(0 != encoder->protected_);
  91928. return encoder->protected_->bits_per_sample;
  91929. }
  91930. FLAC_API unsigned FLAC__stream_encoder_get_sample_rate(const FLAC__StreamEncoder *encoder)
  91931. {
  91932. FLAC__ASSERT(0 != encoder);
  91933. FLAC__ASSERT(0 != encoder->private_);
  91934. FLAC__ASSERT(0 != encoder->protected_);
  91935. return encoder->protected_->sample_rate;
  91936. }
  91937. FLAC_API unsigned FLAC__stream_encoder_get_blocksize(const FLAC__StreamEncoder *encoder)
  91938. {
  91939. FLAC__ASSERT(0 != encoder);
  91940. FLAC__ASSERT(0 != encoder->private_);
  91941. FLAC__ASSERT(0 != encoder->protected_);
  91942. return encoder->protected_->blocksize;
  91943. }
  91944. FLAC_API FLAC__bool FLAC__stream_encoder_get_do_mid_side_stereo(const FLAC__StreamEncoder *encoder)
  91945. {
  91946. FLAC__ASSERT(0 != encoder);
  91947. FLAC__ASSERT(0 != encoder->private_);
  91948. FLAC__ASSERT(0 != encoder->protected_);
  91949. return encoder->protected_->do_mid_side_stereo;
  91950. }
  91951. FLAC_API FLAC__bool FLAC__stream_encoder_get_loose_mid_side_stereo(const FLAC__StreamEncoder *encoder)
  91952. {
  91953. FLAC__ASSERT(0 != encoder);
  91954. FLAC__ASSERT(0 != encoder->private_);
  91955. FLAC__ASSERT(0 != encoder->protected_);
  91956. return encoder->protected_->loose_mid_side_stereo;
  91957. }
  91958. FLAC_API unsigned FLAC__stream_encoder_get_max_lpc_order(const FLAC__StreamEncoder *encoder)
  91959. {
  91960. FLAC__ASSERT(0 != encoder);
  91961. FLAC__ASSERT(0 != encoder->private_);
  91962. FLAC__ASSERT(0 != encoder->protected_);
  91963. return encoder->protected_->max_lpc_order;
  91964. }
  91965. FLAC_API unsigned FLAC__stream_encoder_get_qlp_coeff_precision(const FLAC__StreamEncoder *encoder)
  91966. {
  91967. FLAC__ASSERT(0 != encoder);
  91968. FLAC__ASSERT(0 != encoder->private_);
  91969. FLAC__ASSERT(0 != encoder->protected_);
  91970. return encoder->protected_->qlp_coeff_precision;
  91971. }
  91972. FLAC_API FLAC__bool FLAC__stream_encoder_get_do_qlp_coeff_prec_search(const FLAC__StreamEncoder *encoder)
  91973. {
  91974. FLAC__ASSERT(0 != encoder);
  91975. FLAC__ASSERT(0 != encoder->private_);
  91976. FLAC__ASSERT(0 != encoder->protected_);
  91977. return encoder->protected_->do_qlp_coeff_prec_search;
  91978. }
  91979. FLAC_API FLAC__bool FLAC__stream_encoder_get_do_escape_coding(const FLAC__StreamEncoder *encoder)
  91980. {
  91981. FLAC__ASSERT(0 != encoder);
  91982. FLAC__ASSERT(0 != encoder->private_);
  91983. FLAC__ASSERT(0 != encoder->protected_);
  91984. return encoder->protected_->do_escape_coding;
  91985. }
  91986. FLAC_API FLAC__bool FLAC__stream_encoder_get_do_exhaustive_model_search(const FLAC__StreamEncoder *encoder)
  91987. {
  91988. FLAC__ASSERT(0 != encoder);
  91989. FLAC__ASSERT(0 != encoder->private_);
  91990. FLAC__ASSERT(0 != encoder->protected_);
  91991. return encoder->protected_->do_exhaustive_model_search;
  91992. }
  91993. FLAC_API unsigned FLAC__stream_encoder_get_min_residual_partition_order(const FLAC__StreamEncoder *encoder)
  91994. {
  91995. FLAC__ASSERT(0 != encoder);
  91996. FLAC__ASSERT(0 != encoder->private_);
  91997. FLAC__ASSERT(0 != encoder->protected_);
  91998. return encoder->protected_->min_residual_partition_order;
  91999. }
  92000. FLAC_API unsigned FLAC__stream_encoder_get_max_residual_partition_order(const FLAC__StreamEncoder *encoder)
  92001. {
  92002. FLAC__ASSERT(0 != encoder);
  92003. FLAC__ASSERT(0 != encoder->private_);
  92004. FLAC__ASSERT(0 != encoder->protected_);
  92005. return encoder->protected_->max_residual_partition_order;
  92006. }
  92007. FLAC_API unsigned FLAC__stream_encoder_get_rice_parameter_search_dist(const FLAC__StreamEncoder *encoder)
  92008. {
  92009. FLAC__ASSERT(0 != encoder);
  92010. FLAC__ASSERT(0 != encoder->private_);
  92011. FLAC__ASSERT(0 != encoder->protected_);
  92012. return encoder->protected_->rice_parameter_search_dist;
  92013. }
  92014. FLAC_API FLAC__uint64 FLAC__stream_encoder_get_total_samples_estimate(const FLAC__StreamEncoder *encoder)
  92015. {
  92016. FLAC__ASSERT(0 != encoder);
  92017. FLAC__ASSERT(0 != encoder->private_);
  92018. FLAC__ASSERT(0 != encoder->protected_);
  92019. return encoder->protected_->total_samples_estimate;
  92020. }
  92021. FLAC_API FLAC__bool FLAC__stream_encoder_process(FLAC__StreamEncoder *encoder, const FLAC__int32 * const buffer[], unsigned samples)
  92022. {
  92023. unsigned i, j = 0, channel;
  92024. const unsigned channels = encoder->protected_->channels, blocksize = encoder->protected_->blocksize;
  92025. FLAC__ASSERT(0 != encoder);
  92026. FLAC__ASSERT(0 != encoder->private_);
  92027. FLAC__ASSERT(0 != encoder->protected_);
  92028. FLAC__ASSERT(encoder->protected_->state == FLAC__STREAM_ENCODER_OK);
  92029. do {
  92030. const unsigned n = min(blocksize+OVERREAD_-encoder->private_->current_sample_number, samples-j);
  92031. if(encoder->protected_->verify)
  92032. append_to_verify_fifo_(&encoder->private_->verify.input_fifo, buffer, j, channels, n);
  92033. for(channel = 0; channel < channels; channel++)
  92034. memcpy(&encoder->private_->integer_signal[channel][encoder->private_->current_sample_number], &buffer[channel][j], sizeof(buffer[channel][0]) * n);
  92035. if(encoder->protected_->do_mid_side_stereo) {
  92036. FLAC__ASSERT(channels == 2);
  92037. for(i = encoder->private_->current_sample_number; i <= blocksize && j < samples; i++, j++) {
  92038. encoder->private_->integer_signal_mid_side[1][i] = buffer[0][j] - buffer[1][j];
  92039. 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' ! */
  92040. }
  92041. }
  92042. else
  92043. j += n;
  92044. encoder->private_->current_sample_number += n;
  92045. if(encoder->private_->current_sample_number > blocksize) {
  92046. FLAC__ASSERT(encoder->private_->current_sample_number == blocksize+OVERREAD_);
  92047. FLAC__ASSERT(OVERREAD_ == 1); /* assert we only overread 1 sample which simplifies the rest of the code below */
  92048. if(!process_frame_(encoder, /*is_fractional_block=*/false, /*is_last_block=*/false))
  92049. return false;
  92050. for(channel = 0; channel < channels; channel++)
  92051. encoder->private_->integer_signal[channel][0] = encoder->private_->integer_signal[channel][blocksize];
  92052. if(encoder->protected_->do_mid_side_stereo) {
  92053. encoder->private_->integer_signal_mid_side[0][0] = encoder->private_->integer_signal_mid_side[0][blocksize];
  92054. encoder->private_->integer_signal_mid_side[1][0] = encoder->private_->integer_signal_mid_side[1][blocksize];
  92055. }
  92056. encoder->private_->current_sample_number = 1;
  92057. }
  92058. } while(j < samples);
  92059. return true;
  92060. }
  92061. FLAC_API FLAC__bool FLAC__stream_encoder_process_interleaved(FLAC__StreamEncoder *encoder, const FLAC__int32 buffer[], unsigned samples)
  92062. {
  92063. unsigned i, j, k, channel;
  92064. FLAC__int32 x, mid, side;
  92065. const unsigned channels = encoder->protected_->channels, blocksize = encoder->protected_->blocksize;
  92066. FLAC__ASSERT(0 != encoder);
  92067. FLAC__ASSERT(0 != encoder->private_);
  92068. FLAC__ASSERT(0 != encoder->protected_);
  92069. FLAC__ASSERT(encoder->protected_->state == FLAC__STREAM_ENCODER_OK);
  92070. j = k = 0;
  92071. if(encoder->protected_->do_mid_side_stereo && channels == 2) {
  92072. do {
  92073. if(encoder->protected_->verify)
  92074. append_to_verify_fifo_interleaved_(&encoder->private_->verify.input_fifo, buffer, j, channels, min(blocksize+OVERREAD_-encoder->private_->current_sample_number, samples-j));
  92075. for(i = encoder->private_->current_sample_number; i <= blocksize && j < samples; i++, j++) {
  92076. encoder->private_->integer_signal[0][i] = mid = side = buffer[k++];
  92077. x = buffer[k++];
  92078. encoder->private_->integer_signal[1][i] = x;
  92079. mid += x;
  92080. side -= x;
  92081. mid >>= 1; /* NOTE: not the same as 'mid = (left + right) / 2' ! */
  92082. encoder->private_->integer_signal_mid_side[1][i] = side;
  92083. encoder->private_->integer_signal_mid_side[0][i] = mid;
  92084. }
  92085. encoder->private_->current_sample_number = i;
  92086. if(i > blocksize) {
  92087. if(!process_frame_(encoder, /*is_fractional_block=*/false, /*is_last_block=*/false))
  92088. return false;
  92089. /* move unprocessed overread samples to beginnings of arrays */
  92090. FLAC__ASSERT(i == blocksize+OVERREAD_);
  92091. FLAC__ASSERT(OVERREAD_ == 1); /* assert we only overread 1 sample which simplifies the rest of the code below */
  92092. encoder->private_->integer_signal[0][0] = encoder->private_->integer_signal[0][blocksize];
  92093. encoder->private_->integer_signal[1][0] = encoder->private_->integer_signal[1][blocksize];
  92094. encoder->private_->integer_signal_mid_side[0][0] = encoder->private_->integer_signal_mid_side[0][blocksize];
  92095. encoder->private_->integer_signal_mid_side[1][0] = encoder->private_->integer_signal_mid_side[1][blocksize];
  92096. encoder->private_->current_sample_number = 1;
  92097. }
  92098. } while(j < samples);
  92099. }
  92100. else {
  92101. do {
  92102. if(encoder->protected_->verify)
  92103. append_to_verify_fifo_interleaved_(&encoder->private_->verify.input_fifo, buffer, j, channels, min(blocksize+OVERREAD_-encoder->private_->current_sample_number, samples-j));
  92104. for(i = encoder->private_->current_sample_number; i <= blocksize && j < samples; i++, j++) {
  92105. for(channel = 0; channel < channels; channel++)
  92106. encoder->private_->integer_signal[channel][i] = buffer[k++];
  92107. }
  92108. encoder->private_->current_sample_number = i;
  92109. if(i > blocksize) {
  92110. if(!process_frame_(encoder, /*is_fractional_block=*/false, /*is_last_block=*/false))
  92111. return false;
  92112. /* move unprocessed overread samples to beginnings of arrays */
  92113. FLAC__ASSERT(i == blocksize+OVERREAD_);
  92114. FLAC__ASSERT(OVERREAD_ == 1); /* assert we only overread 1 sample which simplifies the rest of the code below */
  92115. for(channel = 0; channel < channels; channel++)
  92116. encoder->private_->integer_signal[channel][0] = encoder->private_->integer_signal[channel][blocksize];
  92117. encoder->private_->current_sample_number = 1;
  92118. }
  92119. } while(j < samples);
  92120. }
  92121. return true;
  92122. }
  92123. void set_defaults_enc(FLAC__StreamEncoder *encoder)
  92124. {
  92125. FLAC__ASSERT(0 != encoder);
  92126. #ifdef FLAC__MANDATORY_VERIFY_WHILE_ENCODING
  92127. encoder->protected_->verify = true;
  92128. #else
  92129. encoder->protected_->verify = false;
  92130. #endif
  92131. encoder->protected_->streamable_subset = true;
  92132. encoder->protected_->do_md5 = true;
  92133. encoder->protected_->do_mid_side_stereo = false;
  92134. encoder->protected_->loose_mid_side_stereo = false;
  92135. encoder->protected_->channels = 2;
  92136. encoder->protected_->bits_per_sample = 16;
  92137. encoder->protected_->sample_rate = 44100;
  92138. encoder->protected_->blocksize = 0;
  92139. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  92140. encoder->protected_->num_apodizations = 1;
  92141. encoder->protected_->apodizations[0].type = FLAC__APODIZATION_TUKEY;
  92142. encoder->protected_->apodizations[0].parameters.tukey.p = 0.5;
  92143. #endif
  92144. encoder->protected_->max_lpc_order = 0;
  92145. encoder->protected_->qlp_coeff_precision = 0;
  92146. encoder->protected_->do_qlp_coeff_prec_search = false;
  92147. encoder->protected_->do_exhaustive_model_search = false;
  92148. encoder->protected_->do_escape_coding = false;
  92149. encoder->protected_->min_residual_partition_order = 0;
  92150. encoder->protected_->max_residual_partition_order = 0;
  92151. encoder->protected_->rice_parameter_search_dist = 0;
  92152. encoder->protected_->total_samples_estimate = 0;
  92153. encoder->protected_->metadata = 0;
  92154. encoder->protected_->num_metadata_blocks = 0;
  92155. encoder->private_->seek_table = 0;
  92156. encoder->private_->disable_constant_subframes = false;
  92157. encoder->private_->disable_fixed_subframes = false;
  92158. encoder->private_->disable_verbatim_subframes = false;
  92159. #if FLAC__HAS_OGG
  92160. encoder->private_->is_ogg = false;
  92161. #endif
  92162. encoder->private_->read_callback = 0;
  92163. encoder->private_->write_callback = 0;
  92164. encoder->private_->seek_callback = 0;
  92165. encoder->private_->tell_callback = 0;
  92166. encoder->private_->metadata_callback = 0;
  92167. encoder->private_->progress_callback = 0;
  92168. encoder->private_->client_data = 0;
  92169. #if FLAC__HAS_OGG
  92170. FLAC__ogg_encoder_aspect_set_defaults(&encoder->protected_->ogg_encoder_aspect);
  92171. #endif
  92172. }
  92173. void free_(FLAC__StreamEncoder *encoder)
  92174. {
  92175. unsigned i, channel;
  92176. FLAC__ASSERT(0 != encoder);
  92177. if(encoder->protected_->metadata) {
  92178. free(encoder->protected_->metadata);
  92179. encoder->protected_->metadata = 0;
  92180. encoder->protected_->num_metadata_blocks = 0;
  92181. }
  92182. for(i = 0; i < encoder->protected_->channels; i++) {
  92183. if(0 != encoder->private_->integer_signal_unaligned[i]) {
  92184. free(encoder->private_->integer_signal_unaligned[i]);
  92185. encoder->private_->integer_signal_unaligned[i] = 0;
  92186. }
  92187. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  92188. if(0 != encoder->private_->real_signal_unaligned[i]) {
  92189. free(encoder->private_->real_signal_unaligned[i]);
  92190. encoder->private_->real_signal_unaligned[i] = 0;
  92191. }
  92192. #endif
  92193. }
  92194. for(i = 0; i < 2; i++) {
  92195. if(0 != encoder->private_->integer_signal_mid_side_unaligned[i]) {
  92196. free(encoder->private_->integer_signal_mid_side_unaligned[i]);
  92197. encoder->private_->integer_signal_mid_side_unaligned[i] = 0;
  92198. }
  92199. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  92200. if(0 != encoder->private_->real_signal_mid_side_unaligned[i]) {
  92201. free(encoder->private_->real_signal_mid_side_unaligned[i]);
  92202. encoder->private_->real_signal_mid_side_unaligned[i] = 0;
  92203. }
  92204. #endif
  92205. }
  92206. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  92207. for(i = 0; i < encoder->protected_->num_apodizations; i++) {
  92208. if(0 != encoder->private_->window_unaligned[i]) {
  92209. free(encoder->private_->window_unaligned[i]);
  92210. encoder->private_->window_unaligned[i] = 0;
  92211. }
  92212. }
  92213. if(0 != encoder->private_->windowed_signal_unaligned) {
  92214. free(encoder->private_->windowed_signal_unaligned);
  92215. encoder->private_->windowed_signal_unaligned = 0;
  92216. }
  92217. #endif
  92218. for(channel = 0; channel < encoder->protected_->channels; channel++) {
  92219. for(i = 0; i < 2; i++) {
  92220. if(0 != encoder->private_->residual_workspace_unaligned[channel][i]) {
  92221. free(encoder->private_->residual_workspace_unaligned[channel][i]);
  92222. encoder->private_->residual_workspace_unaligned[channel][i] = 0;
  92223. }
  92224. }
  92225. }
  92226. for(channel = 0; channel < 2; channel++) {
  92227. for(i = 0; i < 2; i++) {
  92228. if(0 != encoder->private_->residual_workspace_mid_side_unaligned[channel][i]) {
  92229. free(encoder->private_->residual_workspace_mid_side_unaligned[channel][i]);
  92230. encoder->private_->residual_workspace_mid_side_unaligned[channel][i] = 0;
  92231. }
  92232. }
  92233. }
  92234. if(0 != encoder->private_->abs_residual_partition_sums_unaligned) {
  92235. free(encoder->private_->abs_residual_partition_sums_unaligned);
  92236. encoder->private_->abs_residual_partition_sums_unaligned = 0;
  92237. }
  92238. if(0 != encoder->private_->raw_bits_per_partition_unaligned) {
  92239. free(encoder->private_->raw_bits_per_partition_unaligned);
  92240. encoder->private_->raw_bits_per_partition_unaligned = 0;
  92241. }
  92242. if(encoder->protected_->verify) {
  92243. for(i = 0; i < encoder->protected_->channels; i++) {
  92244. if(0 != encoder->private_->verify.input_fifo.data[i]) {
  92245. free(encoder->private_->verify.input_fifo.data[i]);
  92246. encoder->private_->verify.input_fifo.data[i] = 0;
  92247. }
  92248. }
  92249. }
  92250. FLAC__bitwriter_free(encoder->private_->frame);
  92251. }
  92252. FLAC__bool resize_buffers_(FLAC__StreamEncoder *encoder, unsigned new_blocksize)
  92253. {
  92254. FLAC__bool ok;
  92255. unsigned i, channel;
  92256. FLAC__ASSERT(new_blocksize > 0);
  92257. FLAC__ASSERT(encoder->protected_->state == FLAC__STREAM_ENCODER_OK);
  92258. FLAC__ASSERT(encoder->private_->current_sample_number == 0);
  92259. if(new_blocksize <= encoder->private_->input_capacity)
  92260. return true;
  92261. ok = true;
  92262. for(i = 0; ok && i < encoder->protected_->channels; i++) {
  92263. ok = ok && FLAC__memory_alloc_aligned_int32_array(new_blocksize+4+OVERREAD_, &encoder->private_->integer_signal_unaligned[i], &encoder->private_->integer_signal[i]);
  92264. memset(encoder->private_->integer_signal[i], 0, sizeof(FLAC__int32)*4);
  92265. encoder->private_->integer_signal[i] += 4;
  92266. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  92267. #if 0 /* @@@ currently unused */
  92268. if(encoder->protected_->max_lpc_order > 0)
  92269. ok = ok && FLAC__memory_alloc_aligned_real_array(new_blocksize+OVERREAD_, &encoder->private_->real_signal_unaligned[i], &encoder->private_->real_signal[i]);
  92270. #endif
  92271. #endif
  92272. }
  92273. for(i = 0; ok && i < 2; i++) {
  92274. 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]);
  92275. memset(encoder->private_->integer_signal_mid_side[i], 0, sizeof(FLAC__int32)*4);
  92276. encoder->private_->integer_signal_mid_side[i] += 4;
  92277. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  92278. #if 0 /* @@@ currently unused */
  92279. if(encoder->protected_->max_lpc_order > 0)
  92280. 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]);
  92281. #endif
  92282. #endif
  92283. }
  92284. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  92285. if(ok && encoder->protected_->max_lpc_order > 0) {
  92286. for(i = 0; ok && i < encoder->protected_->num_apodizations; i++)
  92287. ok = ok && FLAC__memory_alloc_aligned_real_array(new_blocksize, &encoder->private_->window_unaligned[i], &encoder->private_->window[i]);
  92288. ok = ok && FLAC__memory_alloc_aligned_real_array(new_blocksize, &encoder->private_->windowed_signal_unaligned, &encoder->private_->windowed_signal);
  92289. }
  92290. #endif
  92291. for(channel = 0; ok && channel < encoder->protected_->channels; channel++) {
  92292. for(i = 0; ok && i < 2; i++) {
  92293. ok = ok && FLAC__memory_alloc_aligned_int32_array(new_blocksize, &encoder->private_->residual_workspace_unaligned[channel][i], &encoder->private_->residual_workspace[channel][i]);
  92294. }
  92295. }
  92296. for(channel = 0; ok && channel < 2; channel++) {
  92297. for(i = 0; ok && i < 2; i++) {
  92298. 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]);
  92299. }
  92300. }
  92301. ok = ok && FLAC__memory_alloc_aligned_uint64_array(new_blocksize * 2, &encoder->private_->abs_residual_partition_sums_unaligned, &encoder->private_->abs_residual_partition_sums);
  92302. if(encoder->protected_->do_escape_coding)
  92303. ok = ok && FLAC__memory_alloc_aligned_unsigned_array(new_blocksize * 2, &encoder->private_->raw_bits_per_partition_unaligned, &encoder->private_->raw_bits_per_partition);
  92304. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  92305. if(ok && new_blocksize != encoder->private_->input_capacity && encoder->protected_->max_lpc_order > 0) {
  92306. for(i = 0; ok && i < encoder->protected_->num_apodizations; i++) {
  92307. switch(encoder->protected_->apodizations[i].type) {
  92308. case FLAC__APODIZATION_BARTLETT:
  92309. FLAC__window_bartlett(encoder->private_->window[i], new_blocksize);
  92310. break;
  92311. case FLAC__APODIZATION_BARTLETT_HANN:
  92312. FLAC__window_bartlett_hann(encoder->private_->window[i], new_blocksize);
  92313. break;
  92314. case FLAC__APODIZATION_BLACKMAN:
  92315. FLAC__window_blackman(encoder->private_->window[i], new_blocksize);
  92316. break;
  92317. case FLAC__APODIZATION_BLACKMAN_HARRIS_4TERM_92DB_SIDELOBE:
  92318. FLAC__window_blackman_harris_4term_92db_sidelobe(encoder->private_->window[i], new_blocksize);
  92319. break;
  92320. case FLAC__APODIZATION_CONNES:
  92321. FLAC__window_connes(encoder->private_->window[i], new_blocksize);
  92322. break;
  92323. case FLAC__APODIZATION_FLATTOP:
  92324. FLAC__window_flattop(encoder->private_->window[i], new_blocksize);
  92325. break;
  92326. case FLAC__APODIZATION_GAUSS:
  92327. FLAC__window_gauss(encoder->private_->window[i], new_blocksize, encoder->protected_->apodizations[i].parameters.gauss.stddev);
  92328. break;
  92329. case FLAC__APODIZATION_HAMMING:
  92330. FLAC__window_hamming(encoder->private_->window[i], new_blocksize);
  92331. break;
  92332. case FLAC__APODIZATION_HANN:
  92333. FLAC__window_hann(encoder->private_->window[i], new_blocksize);
  92334. break;
  92335. case FLAC__APODIZATION_KAISER_BESSEL:
  92336. FLAC__window_kaiser_bessel(encoder->private_->window[i], new_blocksize);
  92337. break;
  92338. case FLAC__APODIZATION_NUTTALL:
  92339. FLAC__window_nuttall(encoder->private_->window[i], new_blocksize);
  92340. break;
  92341. case FLAC__APODIZATION_RECTANGLE:
  92342. FLAC__window_rectangle(encoder->private_->window[i], new_blocksize);
  92343. break;
  92344. case FLAC__APODIZATION_TRIANGLE:
  92345. FLAC__window_triangle(encoder->private_->window[i], new_blocksize);
  92346. break;
  92347. case FLAC__APODIZATION_TUKEY:
  92348. FLAC__window_tukey(encoder->private_->window[i], new_blocksize, encoder->protected_->apodizations[i].parameters.tukey.p);
  92349. break;
  92350. case FLAC__APODIZATION_WELCH:
  92351. FLAC__window_welch(encoder->private_->window[i], new_blocksize);
  92352. break;
  92353. default:
  92354. FLAC__ASSERT(0);
  92355. FLAC__window_hann(encoder->private_->window[i], new_blocksize);
  92356. break;
  92357. }
  92358. }
  92359. }
  92360. #endif
  92361. if(ok)
  92362. encoder->private_->input_capacity = new_blocksize;
  92363. else
  92364. encoder->protected_->state = FLAC__STREAM_ENCODER_MEMORY_ALLOCATION_ERROR;
  92365. return ok;
  92366. }
  92367. FLAC__bool write_bitbuffer_(FLAC__StreamEncoder *encoder, unsigned samples, FLAC__bool is_last_block)
  92368. {
  92369. const FLAC__byte *buffer;
  92370. size_t bytes;
  92371. FLAC__ASSERT(FLAC__bitwriter_is_byte_aligned(encoder->private_->frame));
  92372. if(!FLAC__bitwriter_get_buffer(encoder->private_->frame, &buffer, &bytes)) {
  92373. encoder->protected_->state = FLAC__STREAM_ENCODER_MEMORY_ALLOCATION_ERROR;
  92374. return false;
  92375. }
  92376. if(encoder->protected_->verify) {
  92377. encoder->private_->verify.output.data = buffer;
  92378. encoder->private_->verify.output.bytes = bytes;
  92379. if(encoder->private_->verify.state_hint == ENCODER_IN_MAGIC) {
  92380. encoder->private_->verify.needs_magic_hack = true;
  92381. }
  92382. else {
  92383. if(!FLAC__stream_decoder_process_single(encoder->private_->verify.decoder)) {
  92384. FLAC__bitwriter_release_buffer(encoder->private_->frame);
  92385. FLAC__bitwriter_clear(encoder->private_->frame);
  92386. if(encoder->protected_->state != FLAC__STREAM_ENCODER_VERIFY_MISMATCH_IN_AUDIO_DATA)
  92387. encoder->protected_->state = FLAC__STREAM_ENCODER_VERIFY_DECODER_ERROR;
  92388. return false;
  92389. }
  92390. }
  92391. }
  92392. if(write_frame_(encoder, buffer, bytes, samples, is_last_block) != FLAC__STREAM_ENCODER_WRITE_STATUS_OK) {
  92393. FLAC__bitwriter_release_buffer(encoder->private_->frame);
  92394. FLAC__bitwriter_clear(encoder->private_->frame);
  92395. encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
  92396. return false;
  92397. }
  92398. FLAC__bitwriter_release_buffer(encoder->private_->frame);
  92399. FLAC__bitwriter_clear(encoder->private_->frame);
  92400. if(samples > 0) {
  92401. encoder->private_->streaminfo.data.stream_info.min_framesize = min(bytes, encoder->private_->streaminfo.data.stream_info.min_framesize);
  92402. encoder->private_->streaminfo.data.stream_info.max_framesize = max(bytes, encoder->private_->streaminfo.data.stream_info.max_framesize);
  92403. }
  92404. return true;
  92405. }
  92406. FLAC__StreamEncoderWriteStatus write_frame_(FLAC__StreamEncoder *encoder, const FLAC__byte buffer[], size_t bytes, unsigned samples, FLAC__bool is_last_block)
  92407. {
  92408. FLAC__StreamEncoderWriteStatus status;
  92409. FLAC__uint64 output_position = 0;
  92410. if(encoder->private_->tell_callback && encoder->private_->tell_callback(encoder, &output_position, encoder->private_->client_data) == FLAC__STREAM_ENCODER_TELL_STATUS_ERROR) {
  92411. encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
  92412. return FLAC__STREAM_ENCODER_WRITE_STATUS_FATAL_ERROR;
  92413. }
  92414. if(samples == 0) {
  92415. FLAC__MetadataType type = (FLAC__MetadataType) (buffer[0] & 0x7f);
  92416. if(type == FLAC__METADATA_TYPE_STREAMINFO)
  92417. encoder->protected_->streaminfo_offset = output_position;
  92418. else if(type == FLAC__METADATA_TYPE_SEEKTABLE && encoder->protected_->seektable_offset == 0)
  92419. encoder->protected_->seektable_offset = output_position;
  92420. }
  92421. if(0 != encoder->private_->seek_table && encoder->protected_->audio_offset > 0 && encoder->private_->seek_table->num_points > 0) {
  92422. const unsigned blocksize = FLAC__stream_encoder_get_blocksize(encoder);
  92423. const FLAC__uint64 frame_first_sample = encoder->private_->samples_written;
  92424. const FLAC__uint64 frame_last_sample = frame_first_sample + (FLAC__uint64)blocksize - 1;
  92425. FLAC__uint64 test_sample;
  92426. unsigned i;
  92427. for(i = encoder->private_->first_seekpoint_to_check; i < encoder->private_->seek_table->num_points; i++) {
  92428. test_sample = encoder->private_->seek_table->points[i].sample_number;
  92429. if(test_sample > frame_last_sample) {
  92430. break;
  92431. }
  92432. else if(test_sample >= frame_first_sample) {
  92433. encoder->private_->seek_table->points[i].sample_number = frame_first_sample;
  92434. encoder->private_->seek_table->points[i].stream_offset = output_position - encoder->protected_->audio_offset;
  92435. encoder->private_->seek_table->points[i].frame_samples = blocksize;
  92436. encoder->private_->first_seekpoint_to_check++;
  92437. }
  92438. else {
  92439. encoder->private_->first_seekpoint_to_check++;
  92440. }
  92441. }
  92442. }
  92443. #if FLAC__HAS_OGG
  92444. if(encoder->private_->is_ogg) {
  92445. status = FLAC__ogg_encoder_aspect_write_callback_wrapper(
  92446. &encoder->protected_->ogg_encoder_aspect,
  92447. buffer,
  92448. bytes,
  92449. samples,
  92450. encoder->private_->current_frame_number,
  92451. is_last_block,
  92452. (FLAC__OggEncoderAspectWriteCallbackProxy)encoder->private_->write_callback,
  92453. encoder,
  92454. encoder->private_->client_data
  92455. );
  92456. }
  92457. else
  92458. #endif
  92459. status = encoder->private_->write_callback(encoder, buffer, bytes, samples, encoder->private_->current_frame_number, encoder->private_->client_data);
  92460. if(status == FLAC__STREAM_ENCODER_WRITE_STATUS_OK) {
  92461. encoder->private_->bytes_written += bytes;
  92462. encoder->private_->samples_written += samples;
  92463. encoder->private_->frames_written = max(encoder->private_->frames_written, encoder->private_->current_frame_number+1);
  92464. }
  92465. else
  92466. encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
  92467. return status;
  92468. }
  92469. void update_metadata_(const FLAC__StreamEncoder *encoder)
  92470. {
  92471. FLAC__byte b[max(6, FLAC__STREAM_METADATA_SEEKPOINT_LENGTH)];
  92472. const FLAC__StreamMetadata *metadata = &encoder->private_->streaminfo;
  92473. const FLAC__uint64 samples = metadata->data.stream_info.total_samples;
  92474. const unsigned min_framesize = metadata->data.stream_info.min_framesize;
  92475. const unsigned max_framesize = metadata->data.stream_info.max_framesize;
  92476. const unsigned bps = metadata->data.stream_info.bits_per_sample;
  92477. FLAC__StreamEncoderSeekStatus seek_status;
  92478. FLAC__ASSERT(metadata->type == FLAC__METADATA_TYPE_STREAMINFO);
  92479. {
  92480. const unsigned md5_offset =
  92481. FLAC__STREAM_METADATA_HEADER_LENGTH +
  92482. (
  92483. FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN +
  92484. FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN +
  92485. FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN +
  92486. FLAC__STREAM_METADATA_STREAMINFO_MAX_FRAME_SIZE_LEN +
  92487. FLAC__STREAM_METADATA_STREAMINFO_SAMPLE_RATE_LEN +
  92488. FLAC__STREAM_METADATA_STREAMINFO_CHANNELS_LEN +
  92489. FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN +
  92490. FLAC__STREAM_METADATA_STREAMINFO_TOTAL_SAMPLES_LEN
  92491. ) / 8;
  92492. if((seek_status = encoder->private_->seek_callback(encoder, encoder->protected_->streaminfo_offset + md5_offset, encoder->private_->client_data)) != FLAC__STREAM_ENCODER_SEEK_STATUS_OK) {
  92493. if(seek_status == FLAC__STREAM_ENCODER_SEEK_STATUS_ERROR)
  92494. encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
  92495. return;
  92496. }
  92497. if(encoder->private_->write_callback(encoder, metadata->data.stream_info.md5sum, 16, 0, 0, encoder->private_->client_data) != FLAC__STREAM_ENCODER_WRITE_STATUS_OK) {
  92498. encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
  92499. return;
  92500. }
  92501. }
  92502. {
  92503. const unsigned total_samples_byte_offset =
  92504. FLAC__STREAM_METADATA_HEADER_LENGTH +
  92505. (
  92506. FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN +
  92507. FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN +
  92508. FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN +
  92509. FLAC__STREAM_METADATA_STREAMINFO_MAX_FRAME_SIZE_LEN +
  92510. FLAC__STREAM_METADATA_STREAMINFO_SAMPLE_RATE_LEN +
  92511. FLAC__STREAM_METADATA_STREAMINFO_CHANNELS_LEN +
  92512. FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN
  92513. - 4
  92514. ) / 8;
  92515. b[0] = ((FLAC__byte)(bps-1) << 4) | (FLAC__byte)((samples >> 32) & 0x0F);
  92516. b[1] = (FLAC__byte)((samples >> 24) & 0xFF);
  92517. b[2] = (FLAC__byte)((samples >> 16) & 0xFF);
  92518. b[3] = (FLAC__byte)((samples >> 8) & 0xFF);
  92519. b[4] = (FLAC__byte)(samples & 0xFF);
  92520. 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) {
  92521. if(seek_status == FLAC__STREAM_ENCODER_SEEK_STATUS_ERROR)
  92522. encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
  92523. return;
  92524. }
  92525. if(encoder->private_->write_callback(encoder, b, 5, 0, 0, encoder->private_->client_data) != FLAC__STREAM_ENCODER_WRITE_STATUS_OK) {
  92526. encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
  92527. return;
  92528. }
  92529. }
  92530. {
  92531. const unsigned min_framesize_offset =
  92532. FLAC__STREAM_METADATA_HEADER_LENGTH +
  92533. (
  92534. FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN +
  92535. FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN
  92536. ) / 8;
  92537. b[0] = (FLAC__byte)((min_framesize >> 16) & 0xFF);
  92538. b[1] = (FLAC__byte)((min_framesize >> 8) & 0xFF);
  92539. b[2] = (FLAC__byte)(min_framesize & 0xFF);
  92540. b[3] = (FLAC__byte)((max_framesize >> 16) & 0xFF);
  92541. b[4] = (FLAC__byte)((max_framesize >> 8) & 0xFF);
  92542. b[5] = (FLAC__byte)(max_framesize & 0xFF);
  92543. 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) {
  92544. if(seek_status == FLAC__STREAM_ENCODER_SEEK_STATUS_ERROR)
  92545. encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
  92546. return;
  92547. }
  92548. if(encoder->private_->write_callback(encoder, b, 6, 0, 0, encoder->private_->client_data) != FLAC__STREAM_ENCODER_WRITE_STATUS_OK) {
  92549. encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
  92550. return;
  92551. }
  92552. }
  92553. if(0 != encoder->private_->seek_table && encoder->private_->seek_table->num_points > 0 && encoder->protected_->seektable_offset > 0) {
  92554. unsigned i;
  92555. FLAC__format_seektable_sort(encoder->private_->seek_table);
  92556. FLAC__ASSERT(FLAC__format_seektable_is_legal(encoder->private_->seek_table));
  92557. 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) {
  92558. if(seek_status == FLAC__STREAM_ENCODER_SEEK_STATUS_ERROR)
  92559. encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
  92560. return;
  92561. }
  92562. for(i = 0; i < encoder->private_->seek_table->num_points; i++) {
  92563. FLAC__uint64 xx;
  92564. unsigned x;
  92565. xx = encoder->private_->seek_table->points[i].sample_number;
  92566. b[7] = (FLAC__byte)xx; xx >>= 8;
  92567. b[6] = (FLAC__byte)xx; xx >>= 8;
  92568. b[5] = (FLAC__byte)xx; xx >>= 8;
  92569. b[4] = (FLAC__byte)xx; xx >>= 8;
  92570. b[3] = (FLAC__byte)xx; xx >>= 8;
  92571. b[2] = (FLAC__byte)xx; xx >>= 8;
  92572. b[1] = (FLAC__byte)xx; xx >>= 8;
  92573. b[0] = (FLAC__byte)xx; xx >>= 8;
  92574. xx = encoder->private_->seek_table->points[i].stream_offset;
  92575. b[15] = (FLAC__byte)xx; xx >>= 8;
  92576. b[14] = (FLAC__byte)xx; xx >>= 8;
  92577. b[13] = (FLAC__byte)xx; xx >>= 8;
  92578. b[12] = (FLAC__byte)xx; xx >>= 8;
  92579. b[11] = (FLAC__byte)xx; xx >>= 8;
  92580. b[10] = (FLAC__byte)xx; xx >>= 8;
  92581. b[9] = (FLAC__byte)xx; xx >>= 8;
  92582. b[8] = (FLAC__byte)xx; xx >>= 8;
  92583. x = encoder->private_->seek_table->points[i].frame_samples;
  92584. b[17] = (FLAC__byte)x; x >>= 8;
  92585. b[16] = (FLAC__byte)x; x >>= 8;
  92586. if(encoder->private_->write_callback(encoder, b, 18, 0, 0, encoder->private_->client_data) != FLAC__STREAM_ENCODER_WRITE_STATUS_OK) {
  92587. encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
  92588. return;
  92589. }
  92590. }
  92591. }
  92592. }
  92593. #if FLAC__HAS_OGG
  92594. void update_ogg_metadata_(FLAC__StreamEncoder *encoder)
  92595. {
  92596. static const unsigned FIRST_OGG_PACKET_STREAMINFO_PREFIX_LENGTH =
  92597. FLAC__OGG_MAPPING_PACKET_TYPE_LENGTH +
  92598. FLAC__OGG_MAPPING_MAGIC_LENGTH +
  92599. FLAC__OGG_MAPPING_VERSION_MAJOR_LENGTH +
  92600. FLAC__OGG_MAPPING_VERSION_MINOR_LENGTH +
  92601. FLAC__OGG_MAPPING_NUM_HEADERS_LENGTH +
  92602. FLAC__STREAM_SYNC_LENGTH
  92603. ;
  92604. FLAC__byte b[max(6, FLAC__STREAM_METADATA_SEEKPOINT_LENGTH)];
  92605. const FLAC__StreamMetadata *metadata = &encoder->private_->streaminfo;
  92606. const FLAC__uint64 samples = metadata->data.stream_info.total_samples;
  92607. const unsigned min_framesize = metadata->data.stream_info.min_framesize;
  92608. const unsigned max_framesize = metadata->data.stream_info.max_framesize;
  92609. ogg_page page;
  92610. FLAC__ASSERT(metadata->type == FLAC__METADATA_TYPE_STREAMINFO);
  92611. FLAC__ASSERT(0 != encoder->private_->seek_callback);
  92612. if(encoder->private_->seek_callback(encoder, 0, encoder->private_->client_data) == FLAC__STREAM_ENCODER_SEEK_STATUS_UNSUPPORTED)
  92613. return;
  92614. simple_ogg_page__init(&page);
  92615. if(!simple_ogg_page__get_at(encoder, encoder->protected_->streaminfo_offset, &page, encoder->private_->seek_callback, encoder->private_->read_callback, encoder->private_->client_data)) {
  92616. simple_ogg_page__clear(&page);
  92617. return; /* state already set */
  92618. }
  92619. {
  92620. const unsigned md5_offset =
  92621. FIRST_OGG_PACKET_STREAMINFO_PREFIX_LENGTH +
  92622. FLAC__STREAM_METADATA_HEADER_LENGTH +
  92623. (
  92624. FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN +
  92625. FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN +
  92626. FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN +
  92627. FLAC__STREAM_METADATA_STREAMINFO_MAX_FRAME_SIZE_LEN +
  92628. FLAC__STREAM_METADATA_STREAMINFO_SAMPLE_RATE_LEN +
  92629. FLAC__STREAM_METADATA_STREAMINFO_CHANNELS_LEN +
  92630. FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN +
  92631. FLAC__STREAM_METADATA_STREAMINFO_TOTAL_SAMPLES_LEN
  92632. ) / 8;
  92633. if(md5_offset + 16 > (unsigned)page.body_len) {
  92634. encoder->protected_->state = FLAC__STREAM_ENCODER_OGG_ERROR;
  92635. simple_ogg_page__clear(&page);
  92636. return;
  92637. }
  92638. memcpy(page.body + md5_offset, metadata->data.stream_info.md5sum, 16);
  92639. }
  92640. {
  92641. const unsigned total_samples_byte_offset =
  92642. FIRST_OGG_PACKET_STREAMINFO_PREFIX_LENGTH +
  92643. FLAC__STREAM_METADATA_HEADER_LENGTH +
  92644. (
  92645. FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN +
  92646. FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN +
  92647. FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN +
  92648. FLAC__STREAM_METADATA_STREAMINFO_MAX_FRAME_SIZE_LEN +
  92649. FLAC__STREAM_METADATA_STREAMINFO_SAMPLE_RATE_LEN +
  92650. FLAC__STREAM_METADATA_STREAMINFO_CHANNELS_LEN +
  92651. FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN
  92652. - 4
  92653. ) / 8;
  92654. if(total_samples_byte_offset + 5 > (unsigned)page.body_len) {
  92655. encoder->protected_->state = FLAC__STREAM_ENCODER_OGG_ERROR;
  92656. simple_ogg_page__clear(&page);
  92657. return;
  92658. }
  92659. b[0] = (FLAC__byte)page.body[total_samples_byte_offset] & 0xF0;
  92660. b[0] |= (FLAC__byte)((samples >> 32) & 0x0F);
  92661. b[1] = (FLAC__byte)((samples >> 24) & 0xFF);
  92662. b[2] = (FLAC__byte)((samples >> 16) & 0xFF);
  92663. b[3] = (FLAC__byte)((samples >> 8) & 0xFF);
  92664. b[4] = (FLAC__byte)(samples & 0xFF);
  92665. memcpy(page.body + total_samples_byte_offset, b, 5);
  92666. }
  92667. {
  92668. const unsigned min_framesize_offset =
  92669. FIRST_OGG_PACKET_STREAMINFO_PREFIX_LENGTH +
  92670. FLAC__STREAM_METADATA_HEADER_LENGTH +
  92671. (
  92672. FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN +
  92673. FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN
  92674. ) / 8;
  92675. if(min_framesize_offset + 6 > (unsigned)page.body_len) {
  92676. encoder->protected_->state = FLAC__STREAM_ENCODER_OGG_ERROR;
  92677. simple_ogg_page__clear(&page);
  92678. return;
  92679. }
  92680. b[0] = (FLAC__byte)((min_framesize >> 16) & 0xFF);
  92681. b[1] = (FLAC__byte)((min_framesize >> 8) & 0xFF);
  92682. b[2] = (FLAC__byte)(min_framesize & 0xFF);
  92683. b[3] = (FLAC__byte)((max_framesize >> 16) & 0xFF);
  92684. b[4] = (FLAC__byte)((max_framesize >> 8) & 0xFF);
  92685. b[5] = (FLAC__byte)(max_framesize & 0xFF);
  92686. memcpy(page.body + min_framesize_offset, b, 6);
  92687. }
  92688. if(!simple_ogg_page__set_at(encoder, encoder->protected_->streaminfo_offset, &page, encoder->private_->seek_callback, encoder->private_->write_callback, encoder->private_->client_data)) {
  92689. simple_ogg_page__clear(&page);
  92690. return; /* state already set */
  92691. }
  92692. simple_ogg_page__clear(&page);
  92693. if(0 != encoder->private_->seek_table && encoder->private_->seek_table->num_points > 0 && encoder->protected_->seektable_offset > 0) {
  92694. unsigned i;
  92695. FLAC__byte *p;
  92696. FLAC__format_seektable_sort(encoder->private_->seek_table);
  92697. FLAC__ASSERT(FLAC__format_seektable_is_legal(encoder->private_->seek_table));
  92698. simple_ogg_page__init(&page);
  92699. if(!simple_ogg_page__get_at(encoder, encoder->protected_->seektable_offset, &page, encoder->private_->seek_callback, encoder->private_->read_callback, encoder->private_->client_data)) {
  92700. simple_ogg_page__clear(&page);
  92701. return; /* state already set */
  92702. }
  92703. if((FLAC__STREAM_METADATA_HEADER_LENGTH + 18*encoder->private_->seek_table->num_points) != (unsigned)page.body_len) {
  92704. encoder->protected_->state = FLAC__STREAM_ENCODER_OGG_ERROR;
  92705. simple_ogg_page__clear(&page);
  92706. return;
  92707. }
  92708. for(i = 0, p = page.body + FLAC__STREAM_METADATA_HEADER_LENGTH; i < encoder->private_->seek_table->num_points; i++, p += 18) {
  92709. FLAC__uint64 xx;
  92710. unsigned x;
  92711. xx = encoder->private_->seek_table->points[i].sample_number;
  92712. b[7] = (FLAC__byte)xx; xx >>= 8;
  92713. b[6] = (FLAC__byte)xx; xx >>= 8;
  92714. b[5] = (FLAC__byte)xx; xx >>= 8;
  92715. b[4] = (FLAC__byte)xx; xx >>= 8;
  92716. b[3] = (FLAC__byte)xx; xx >>= 8;
  92717. b[2] = (FLAC__byte)xx; xx >>= 8;
  92718. b[1] = (FLAC__byte)xx; xx >>= 8;
  92719. b[0] = (FLAC__byte)xx; xx >>= 8;
  92720. xx = encoder->private_->seek_table->points[i].stream_offset;
  92721. b[15] = (FLAC__byte)xx; xx >>= 8;
  92722. b[14] = (FLAC__byte)xx; xx >>= 8;
  92723. b[13] = (FLAC__byte)xx; xx >>= 8;
  92724. b[12] = (FLAC__byte)xx; xx >>= 8;
  92725. b[11] = (FLAC__byte)xx; xx >>= 8;
  92726. b[10] = (FLAC__byte)xx; xx >>= 8;
  92727. b[9] = (FLAC__byte)xx; xx >>= 8;
  92728. b[8] = (FLAC__byte)xx; xx >>= 8;
  92729. x = encoder->private_->seek_table->points[i].frame_samples;
  92730. b[17] = (FLAC__byte)x; x >>= 8;
  92731. b[16] = (FLAC__byte)x; x >>= 8;
  92732. memcpy(p, b, 18);
  92733. }
  92734. if(!simple_ogg_page__set_at(encoder, encoder->protected_->seektable_offset, &page, encoder->private_->seek_callback, encoder->private_->write_callback, encoder->private_->client_data)) {
  92735. simple_ogg_page__clear(&page);
  92736. return; /* state already set */
  92737. }
  92738. simple_ogg_page__clear(&page);
  92739. }
  92740. }
  92741. #endif
  92742. FLAC__bool process_frame_(FLAC__StreamEncoder *encoder, FLAC__bool is_fractional_block, FLAC__bool is_last_block)
  92743. {
  92744. FLAC__uint16 crc;
  92745. FLAC__ASSERT(encoder->protected_->state == FLAC__STREAM_ENCODER_OK);
  92746. 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)) {
  92747. encoder->protected_->state = FLAC__STREAM_ENCODER_MEMORY_ALLOCATION_ERROR;
  92748. return false;
  92749. }
  92750. if(!process_subframes_(encoder, is_fractional_block)) {
  92751. return false;
  92752. }
  92753. if(!FLAC__bitwriter_zero_pad_to_byte_boundary(encoder->private_->frame)) {
  92754. encoder->protected_->state = FLAC__STREAM_ENCODER_MEMORY_ALLOCATION_ERROR;
  92755. return false;
  92756. }
  92757. FLAC__ASSERT(FLAC__bitwriter_is_byte_aligned(encoder->private_->frame));
  92758. if(
  92759. !FLAC__bitwriter_get_write_crc16(encoder->private_->frame, &crc) ||
  92760. !FLAC__bitwriter_write_raw_uint32(encoder->private_->frame, crc, FLAC__FRAME_FOOTER_CRC_LEN)
  92761. ) {
  92762. encoder->protected_->state = FLAC__STREAM_ENCODER_MEMORY_ALLOCATION_ERROR;
  92763. return false;
  92764. }
  92765. if(!write_bitbuffer_(encoder, encoder->protected_->blocksize, is_last_block)) {
  92766. return false;
  92767. }
  92768. encoder->private_->current_sample_number = 0;
  92769. encoder->private_->current_frame_number++;
  92770. encoder->private_->streaminfo.data.stream_info.total_samples += (FLAC__uint64)encoder->protected_->blocksize;
  92771. return true;
  92772. }
  92773. FLAC__bool process_subframes_(FLAC__StreamEncoder *encoder, FLAC__bool is_fractional_block)
  92774. {
  92775. FLAC__FrameHeader frame_header;
  92776. unsigned channel, min_partition_order = encoder->protected_->min_residual_partition_order, max_partition_order;
  92777. FLAC__bool do_independent, do_mid_side;
  92778. if(is_fractional_block) {
  92779. max_partition_order = 0;
  92780. }
  92781. else {
  92782. max_partition_order = FLAC__format_get_max_rice_partition_order_from_blocksize(encoder->protected_->blocksize);
  92783. max_partition_order = min(max_partition_order, encoder->protected_->max_residual_partition_order);
  92784. }
  92785. min_partition_order = min(min_partition_order, max_partition_order);
  92786. frame_header.blocksize = encoder->protected_->blocksize;
  92787. frame_header.sample_rate = encoder->protected_->sample_rate;
  92788. frame_header.channels = encoder->protected_->channels;
  92789. frame_header.channel_assignment = FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT; /* the default unless the encoder determines otherwise */
  92790. frame_header.bits_per_sample = encoder->protected_->bits_per_sample;
  92791. frame_header.number_type = FLAC__FRAME_NUMBER_TYPE_FRAME_NUMBER;
  92792. frame_header.number.frame_number = encoder->private_->current_frame_number;
  92793. if(encoder->protected_->do_mid_side_stereo) {
  92794. if(encoder->protected_->loose_mid_side_stereo) {
  92795. if(encoder->private_->loose_mid_side_stereo_frame_count == 0) {
  92796. do_independent = true;
  92797. do_mid_side = true;
  92798. }
  92799. else {
  92800. do_independent = (encoder->private_->last_channel_assignment == FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT);
  92801. do_mid_side = !do_independent;
  92802. }
  92803. }
  92804. else {
  92805. do_independent = true;
  92806. do_mid_side = true;
  92807. }
  92808. }
  92809. else {
  92810. do_independent = true;
  92811. do_mid_side = false;
  92812. }
  92813. FLAC__ASSERT(do_independent || do_mid_side);
  92814. if(do_independent) {
  92815. for(channel = 0; channel < encoder->protected_->channels; channel++) {
  92816. const unsigned w = get_wasted_bits_(encoder->private_->integer_signal[channel], encoder->protected_->blocksize);
  92817. encoder->private_->subframe_workspace[channel][0].wasted_bits = encoder->private_->subframe_workspace[channel][1].wasted_bits = w;
  92818. encoder->private_->subframe_bps[channel] = encoder->protected_->bits_per_sample - w;
  92819. }
  92820. }
  92821. if(do_mid_side) {
  92822. FLAC__ASSERT(encoder->protected_->channels == 2);
  92823. for(channel = 0; channel < 2; channel++) {
  92824. const unsigned w = get_wasted_bits_(encoder->private_->integer_signal_mid_side[channel], encoder->protected_->blocksize);
  92825. encoder->private_->subframe_workspace_mid_side[channel][0].wasted_bits = encoder->private_->subframe_workspace_mid_side[channel][1].wasted_bits = w;
  92826. encoder->private_->subframe_bps_mid_side[channel] = encoder->protected_->bits_per_sample - w + (channel==0? 0:1);
  92827. }
  92828. }
  92829. if(do_independent) {
  92830. for(channel = 0; channel < encoder->protected_->channels; channel++) {
  92831. if(!
  92832. process_subframe_(
  92833. encoder,
  92834. min_partition_order,
  92835. max_partition_order,
  92836. &frame_header,
  92837. encoder->private_->subframe_bps[channel],
  92838. encoder->private_->integer_signal[channel],
  92839. encoder->private_->subframe_workspace_ptr[channel],
  92840. encoder->private_->partitioned_rice_contents_workspace_ptr[channel],
  92841. encoder->private_->residual_workspace[channel],
  92842. encoder->private_->best_subframe+channel,
  92843. encoder->private_->best_subframe_bits+channel
  92844. )
  92845. )
  92846. return false;
  92847. }
  92848. }
  92849. if(do_mid_side) {
  92850. FLAC__ASSERT(encoder->protected_->channels == 2);
  92851. for(channel = 0; channel < 2; channel++) {
  92852. if(!
  92853. process_subframe_(
  92854. encoder,
  92855. min_partition_order,
  92856. max_partition_order,
  92857. &frame_header,
  92858. encoder->private_->subframe_bps_mid_side[channel],
  92859. encoder->private_->integer_signal_mid_side[channel],
  92860. encoder->private_->subframe_workspace_ptr_mid_side[channel],
  92861. encoder->private_->partitioned_rice_contents_workspace_ptr_mid_side[channel],
  92862. encoder->private_->residual_workspace_mid_side[channel],
  92863. encoder->private_->best_subframe_mid_side+channel,
  92864. encoder->private_->best_subframe_bits_mid_side+channel
  92865. )
  92866. )
  92867. return false;
  92868. }
  92869. }
  92870. if(do_mid_side) {
  92871. unsigned left_bps = 0, right_bps = 0; /* initialized only to prevent superfluous compiler warning */
  92872. FLAC__Subframe *left_subframe = 0, *right_subframe = 0; /* initialized only to prevent superfluous compiler warning */
  92873. FLAC__ChannelAssignment channel_assignment;
  92874. FLAC__ASSERT(encoder->protected_->channels == 2);
  92875. if(encoder->protected_->loose_mid_side_stereo && encoder->private_->loose_mid_side_stereo_frame_count > 0) {
  92876. channel_assignment = (encoder->private_->last_channel_assignment == FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT? FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT : FLAC__CHANNEL_ASSIGNMENT_MID_SIDE);
  92877. }
  92878. else {
  92879. unsigned bits[4]; /* WATCHOUT - indexed by FLAC__ChannelAssignment */
  92880. unsigned min_bits;
  92881. int ca;
  92882. FLAC__ASSERT(FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT == 0);
  92883. FLAC__ASSERT(FLAC__CHANNEL_ASSIGNMENT_LEFT_SIDE == 1);
  92884. FLAC__ASSERT(FLAC__CHANNEL_ASSIGNMENT_RIGHT_SIDE == 2);
  92885. FLAC__ASSERT(FLAC__CHANNEL_ASSIGNMENT_MID_SIDE == 3);
  92886. FLAC__ASSERT(do_independent && do_mid_side);
  92887. bits[FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT] = encoder->private_->best_subframe_bits [0] + encoder->private_->best_subframe_bits [1];
  92888. bits[FLAC__CHANNEL_ASSIGNMENT_LEFT_SIDE ] = encoder->private_->best_subframe_bits [0] + encoder->private_->best_subframe_bits_mid_side[1];
  92889. bits[FLAC__CHANNEL_ASSIGNMENT_RIGHT_SIDE ] = encoder->private_->best_subframe_bits [1] + encoder->private_->best_subframe_bits_mid_side[1];
  92890. bits[FLAC__CHANNEL_ASSIGNMENT_MID_SIDE ] = encoder->private_->best_subframe_bits_mid_side[0] + encoder->private_->best_subframe_bits_mid_side[1];
  92891. channel_assignment = FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT;
  92892. min_bits = bits[channel_assignment];
  92893. for(ca = 1; ca <= 3; ca++) {
  92894. if(bits[ca] < min_bits) {
  92895. min_bits = bits[ca];
  92896. channel_assignment = (FLAC__ChannelAssignment)ca;
  92897. }
  92898. }
  92899. }
  92900. frame_header.channel_assignment = channel_assignment;
  92901. if(!FLAC__frame_add_header(&frame_header, encoder->private_->frame)) {
  92902. encoder->protected_->state = FLAC__STREAM_ENCODER_FRAMING_ERROR;
  92903. return false;
  92904. }
  92905. switch(channel_assignment) {
  92906. case FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT:
  92907. left_subframe = &encoder->private_->subframe_workspace [0][encoder->private_->best_subframe [0]];
  92908. right_subframe = &encoder->private_->subframe_workspace [1][encoder->private_->best_subframe [1]];
  92909. break;
  92910. case FLAC__CHANNEL_ASSIGNMENT_LEFT_SIDE:
  92911. left_subframe = &encoder->private_->subframe_workspace [0][encoder->private_->best_subframe [0]];
  92912. right_subframe = &encoder->private_->subframe_workspace_mid_side[1][encoder->private_->best_subframe_mid_side[1]];
  92913. break;
  92914. case FLAC__CHANNEL_ASSIGNMENT_RIGHT_SIDE:
  92915. left_subframe = &encoder->private_->subframe_workspace_mid_side[1][encoder->private_->best_subframe_mid_side[1]];
  92916. right_subframe = &encoder->private_->subframe_workspace [1][encoder->private_->best_subframe [1]];
  92917. break;
  92918. case FLAC__CHANNEL_ASSIGNMENT_MID_SIDE:
  92919. left_subframe = &encoder->private_->subframe_workspace_mid_side[0][encoder->private_->best_subframe_mid_side[0]];
  92920. right_subframe = &encoder->private_->subframe_workspace_mid_side[1][encoder->private_->best_subframe_mid_side[1]];
  92921. break;
  92922. default:
  92923. FLAC__ASSERT(0);
  92924. }
  92925. switch(channel_assignment) {
  92926. case FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT:
  92927. left_bps = encoder->private_->subframe_bps [0];
  92928. right_bps = encoder->private_->subframe_bps [1];
  92929. break;
  92930. case FLAC__CHANNEL_ASSIGNMENT_LEFT_SIDE:
  92931. left_bps = encoder->private_->subframe_bps [0];
  92932. right_bps = encoder->private_->subframe_bps_mid_side[1];
  92933. break;
  92934. case FLAC__CHANNEL_ASSIGNMENT_RIGHT_SIDE:
  92935. left_bps = encoder->private_->subframe_bps_mid_side[1];
  92936. right_bps = encoder->private_->subframe_bps [1];
  92937. break;
  92938. case FLAC__CHANNEL_ASSIGNMENT_MID_SIDE:
  92939. left_bps = encoder->private_->subframe_bps_mid_side[0];
  92940. right_bps = encoder->private_->subframe_bps_mid_side[1];
  92941. break;
  92942. default:
  92943. FLAC__ASSERT(0);
  92944. }
  92945. if(!add_subframe_(encoder, frame_header.blocksize, left_bps , left_subframe , encoder->private_->frame))
  92946. return false;
  92947. if(!add_subframe_(encoder, frame_header.blocksize, right_bps, right_subframe, encoder->private_->frame))
  92948. return false;
  92949. }
  92950. else {
  92951. if(!FLAC__frame_add_header(&frame_header, encoder->private_->frame)) {
  92952. encoder->protected_->state = FLAC__STREAM_ENCODER_FRAMING_ERROR;
  92953. return false;
  92954. }
  92955. for(channel = 0; channel < encoder->protected_->channels; channel++) {
  92956. 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)) {
  92957. return false;
  92958. }
  92959. }
  92960. }
  92961. if(encoder->protected_->loose_mid_side_stereo) {
  92962. encoder->private_->loose_mid_side_stereo_frame_count++;
  92963. if(encoder->private_->loose_mid_side_stereo_frame_count >= encoder->private_->loose_mid_side_stereo_frames)
  92964. encoder->private_->loose_mid_side_stereo_frame_count = 0;
  92965. }
  92966. encoder->private_->last_channel_assignment = frame_header.channel_assignment;
  92967. return true;
  92968. }
  92969. FLAC__bool process_subframe_(
  92970. FLAC__StreamEncoder *encoder,
  92971. unsigned min_partition_order,
  92972. unsigned max_partition_order,
  92973. const FLAC__FrameHeader *frame_header,
  92974. unsigned subframe_bps,
  92975. const FLAC__int32 integer_signal[],
  92976. FLAC__Subframe *subframe[2],
  92977. FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents[2],
  92978. FLAC__int32 *residual[2],
  92979. unsigned *best_subframe,
  92980. unsigned *best_bits
  92981. )
  92982. {
  92983. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  92984. FLAC__float fixed_residual_bits_per_sample[FLAC__MAX_FIXED_ORDER+1];
  92985. #else
  92986. FLAC__fixedpoint fixed_residual_bits_per_sample[FLAC__MAX_FIXED_ORDER+1];
  92987. #endif
  92988. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  92989. FLAC__double lpc_residual_bits_per_sample;
  92990. 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 */
  92991. FLAC__double lpc_error[FLAC__MAX_LPC_ORDER];
  92992. unsigned min_lpc_order, max_lpc_order, lpc_order;
  92993. unsigned min_qlp_coeff_precision, max_qlp_coeff_precision, qlp_coeff_precision;
  92994. #endif
  92995. unsigned min_fixed_order, max_fixed_order, guess_fixed_order, fixed_order;
  92996. unsigned rice_parameter;
  92997. unsigned _candidate_bits, _best_bits;
  92998. unsigned _best_subframe;
  92999. 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;
  93000. FLAC__ASSERT(frame_header->blocksize > 0);
  93001. _best_subframe = 0;
  93002. if(encoder->private_->disable_verbatim_subframes && frame_header->blocksize >= FLAC__MAX_FIXED_ORDER)
  93003. _best_bits = UINT_MAX;
  93004. else
  93005. _best_bits = evaluate_verbatim_subframe_(encoder, integer_signal, frame_header->blocksize, subframe_bps, subframe[_best_subframe]);
  93006. if(frame_header->blocksize >= FLAC__MAX_FIXED_ORDER) {
  93007. unsigned signal_is_constant = false;
  93008. 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);
  93009. if(
  93010. !encoder->private_->disable_constant_subframes &&
  93011. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  93012. fixed_residual_bits_per_sample[1] == 0.0
  93013. #else
  93014. fixed_residual_bits_per_sample[1] == FLAC__FP_ZERO
  93015. #endif
  93016. ) {
  93017. unsigned i;
  93018. signal_is_constant = true;
  93019. for(i = 1; i < frame_header->blocksize; i++) {
  93020. if(integer_signal[0] != integer_signal[i]) {
  93021. signal_is_constant = false;
  93022. break;
  93023. }
  93024. }
  93025. }
  93026. if(signal_is_constant) {
  93027. _candidate_bits = evaluate_constant_subframe_(encoder, integer_signal[0], frame_header->blocksize, subframe_bps, subframe[!_best_subframe]);
  93028. if(_candidate_bits < _best_bits) {
  93029. _best_subframe = !_best_subframe;
  93030. _best_bits = _candidate_bits;
  93031. }
  93032. }
  93033. else {
  93034. if(!encoder->private_->disable_fixed_subframes || (encoder->protected_->max_lpc_order == 0 && _best_bits == UINT_MAX)) {
  93035. if(encoder->protected_->do_exhaustive_model_search) {
  93036. min_fixed_order = 0;
  93037. max_fixed_order = FLAC__MAX_FIXED_ORDER;
  93038. }
  93039. else {
  93040. min_fixed_order = max_fixed_order = guess_fixed_order;
  93041. }
  93042. if(max_fixed_order >= frame_header->blocksize)
  93043. max_fixed_order = frame_header->blocksize - 1;
  93044. for(fixed_order = min_fixed_order; fixed_order <= max_fixed_order; fixed_order++) {
  93045. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  93046. if(fixed_residual_bits_per_sample[fixed_order] >= (FLAC__float)subframe_bps)
  93047. continue; /* don't even try */
  93048. 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 */
  93049. #else
  93050. if(FLAC__fixedpoint_trunc(fixed_residual_bits_per_sample[fixed_order]) >= (int)subframe_bps)
  93051. continue; /* don't even try */
  93052. 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 */
  93053. #endif
  93054. rice_parameter++; /* to account for the signed->unsigned conversion during rice coding */
  93055. if(rice_parameter >= rice_parameter_limit) {
  93056. #ifdef DEBUG_VERBOSE
  93057. fprintf(stderr, "clipping rice_parameter (%u -> %u) @0\n", rice_parameter, rice_parameter_limit - 1);
  93058. #endif
  93059. rice_parameter = rice_parameter_limit - 1;
  93060. }
  93061. _candidate_bits =
  93062. evaluate_fixed_subframe_(
  93063. encoder,
  93064. integer_signal,
  93065. residual[!_best_subframe],
  93066. encoder->private_->abs_residual_partition_sums,
  93067. encoder->private_->raw_bits_per_partition,
  93068. frame_header->blocksize,
  93069. subframe_bps,
  93070. fixed_order,
  93071. rice_parameter,
  93072. rice_parameter_limit,
  93073. min_partition_order,
  93074. max_partition_order,
  93075. encoder->protected_->do_escape_coding,
  93076. encoder->protected_->rice_parameter_search_dist,
  93077. subframe[!_best_subframe],
  93078. partitioned_rice_contents[!_best_subframe]
  93079. );
  93080. if(_candidate_bits < _best_bits) {
  93081. _best_subframe = !_best_subframe;
  93082. _best_bits = _candidate_bits;
  93083. }
  93084. }
  93085. }
  93086. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  93087. if(encoder->protected_->max_lpc_order > 0) {
  93088. if(encoder->protected_->max_lpc_order >= frame_header->blocksize)
  93089. max_lpc_order = frame_header->blocksize-1;
  93090. else
  93091. max_lpc_order = encoder->protected_->max_lpc_order;
  93092. if(max_lpc_order > 0) {
  93093. unsigned a;
  93094. for (a = 0; a < encoder->protected_->num_apodizations; a++) {
  93095. FLAC__lpc_window_data(integer_signal, encoder->private_->window[a], encoder->private_->windowed_signal, frame_header->blocksize);
  93096. encoder->private_->local_lpc_compute_autocorrelation(encoder->private_->windowed_signal, frame_header->blocksize, max_lpc_order+1, autoc);
  93097. if(autoc[0] != 0.0) {
  93098. FLAC__lpc_compute_lp_coefficients(autoc, &max_lpc_order, encoder->private_->lp_coeff, lpc_error);
  93099. if(encoder->protected_->do_exhaustive_model_search) {
  93100. min_lpc_order = 1;
  93101. }
  93102. else {
  93103. const unsigned guess_lpc_order =
  93104. FLAC__lpc_compute_best_order(
  93105. lpc_error,
  93106. max_lpc_order,
  93107. frame_header->blocksize,
  93108. subframe_bps + (
  93109. encoder->protected_->do_qlp_coeff_prec_search?
  93110. FLAC__MIN_QLP_COEFF_PRECISION : /* have to guess; use the min possible size to avoid accidentally favoring lower orders */
  93111. encoder->protected_->qlp_coeff_precision
  93112. )
  93113. );
  93114. min_lpc_order = max_lpc_order = guess_lpc_order;
  93115. }
  93116. if(max_lpc_order >= frame_header->blocksize)
  93117. max_lpc_order = frame_header->blocksize - 1;
  93118. for(lpc_order = min_lpc_order; lpc_order <= max_lpc_order; lpc_order++) {
  93119. lpc_residual_bits_per_sample = FLAC__lpc_compute_expected_bits_per_residual_sample(lpc_error[lpc_order-1], frame_header->blocksize-lpc_order);
  93120. if(lpc_residual_bits_per_sample >= (FLAC__double)subframe_bps)
  93121. continue; /* don't even try */
  93122. rice_parameter = (lpc_residual_bits_per_sample > 0.0)? (unsigned)(lpc_residual_bits_per_sample+0.5) : 0; /* 0.5 is for rounding */
  93123. rice_parameter++; /* to account for the signed->unsigned conversion during rice coding */
  93124. if(rice_parameter >= rice_parameter_limit) {
  93125. #ifdef DEBUG_VERBOSE
  93126. fprintf(stderr, "clipping rice_parameter (%u -> %u) @1\n", rice_parameter, rice_parameter_limit - 1);
  93127. #endif
  93128. rice_parameter = rice_parameter_limit - 1;
  93129. }
  93130. if(encoder->protected_->do_qlp_coeff_prec_search) {
  93131. min_qlp_coeff_precision = FLAC__MIN_QLP_COEFF_PRECISION;
  93132. if(subframe_bps <= 17) {
  93133. max_qlp_coeff_precision = min(32 - subframe_bps - lpc_order, FLAC__MAX_QLP_COEFF_PRECISION);
  93134. max_qlp_coeff_precision = max(max_qlp_coeff_precision, min_qlp_coeff_precision);
  93135. }
  93136. else
  93137. max_qlp_coeff_precision = FLAC__MAX_QLP_COEFF_PRECISION;
  93138. }
  93139. else {
  93140. min_qlp_coeff_precision = max_qlp_coeff_precision = encoder->protected_->qlp_coeff_precision;
  93141. }
  93142. for(qlp_coeff_precision = min_qlp_coeff_precision; qlp_coeff_precision <= max_qlp_coeff_precision; qlp_coeff_precision++) {
  93143. _candidate_bits =
  93144. evaluate_lpc_subframe_(
  93145. encoder,
  93146. integer_signal,
  93147. residual[!_best_subframe],
  93148. encoder->private_->abs_residual_partition_sums,
  93149. encoder->private_->raw_bits_per_partition,
  93150. encoder->private_->lp_coeff[lpc_order-1],
  93151. frame_header->blocksize,
  93152. subframe_bps,
  93153. lpc_order,
  93154. qlp_coeff_precision,
  93155. rice_parameter,
  93156. rice_parameter_limit,
  93157. min_partition_order,
  93158. max_partition_order,
  93159. encoder->protected_->do_escape_coding,
  93160. encoder->protected_->rice_parameter_search_dist,
  93161. subframe[!_best_subframe],
  93162. partitioned_rice_contents[!_best_subframe]
  93163. );
  93164. if(_candidate_bits > 0) { /* if == 0, there was a problem quantizing the lpcoeffs */
  93165. if(_candidate_bits < _best_bits) {
  93166. _best_subframe = !_best_subframe;
  93167. _best_bits = _candidate_bits;
  93168. }
  93169. }
  93170. }
  93171. }
  93172. }
  93173. }
  93174. }
  93175. }
  93176. #endif /* !defined FLAC__INTEGER_ONLY_LIBRARY */
  93177. }
  93178. }
  93179. if(_best_bits == UINT_MAX) {
  93180. FLAC__ASSERT(_best_subframe == 0);
  93181. _best_bits = evaluate_verbatim_subframe_(encoder, integer_signal, frame_header->blocksize, subframe_bps, subframe[_best_subframe]);
  93182. }
  93183. *best_subframe = _best_subframe;
  93184. *best_bits = _best_bits;
  93185. return true;
  93186. }
  93187. FLAC__bool add_subframe_(
  93188. FLAC__StreamEncoder *encoder,
  93189. unsigned blocksize,
  93190. unsigned subframe_bps,
  93191. const FLAC__Subframe *subframe,
  93192. FLAC__BitWriter *frame
  93193. )
  93194. {
  93195. switch(subframe->type) {
  93196. case FLAC__SUBFRAME_TYPE_CONSTANT:
  93197. if(!FLAC__subframe_add_constant(&(subframe->data.constant), subframe_bps, subframe->wasted_bits, frame)) {
  93198. encoder->protected_->state = FLAC__STREAM_ENCODER_FRAMING_ERROR;
  93199. return false;
  93200. }
  93201. break;
  93202. case FLAC__SUBFRAME_TYPE_FIXED:
  93203. if(!FLAC__subframe_add_fixed(&(subframe->data.fixed), blocksize - subframe->data.fixed.order, subframe_bps, subframe->wasted_bits, frame)) {
  93204. encoder->protected_->state = FLAC__STREAM_ENCODER_FRAMING_ERROR;
  93205. return false;
  93206. }
  93207. break;
  93208. case FLAC__SUBFRAME_TYPE_LPC:
  93209. if(!FLAC__subframe_add_lpc(&(subframe->data.lpc), blocksize - subframe->data.lpc.order, subframe_bps, subframe->wasted_bits, frame)) {
  93210. encoder->protected_->state = FLAC__STREAM_ENCODER_FRAMING_ERROR;
  93211. return false;
  93212. }
  93213. break;
  93214. case FLAC__SUBFRAME_TYPE_VERBATIM:
  93215. if(!FLAC__subframe_add_verbatim(&(subframe->data.verbatim), blocksize, subframe_bps, subframe->wasted_bits, frame)) {
  93216. encoder->protected_->state = FLAC__STREAM_ENCODER_FRAMING_ERROR;
  93217. return false;
  93218. }
  93219. break;
  93220. default:
  93221. FLAC__ASSERT(0);
  93222. }
  93223. return true;
  93224. }
  93225. #define SPOTCHECK_ESTIMATE 0
  93226. #if SPOTCHECK_ESTIMATE
  93227. static void spotcheck_subframe_estimate_(
  93228. FLAC__StreamEncoder *encoder,
  93229. unsigned blocksize,
  93230. unsigned subframe_bps,
  93231. const FLAC__Subframe *subframe,
  93232. unsigned estimate
  93233. )
  93234. {
  93235. FLAC__bool ret;
  93236. FLAC__BitWriter *frame = FLAC__bitwriter_new();
  93237. if(frame == 0) {
  93238. fprintf(stderr, "EST: can't allocate frame\n");
  93239. return;
  93240. }
  93241. if(!FLAC__bitwriter_init(frame)) {
  93242. fprintf(stderr, "EST: can't init frame\n");
  93243. return;
  93244. }
  93245. ret = add_subframe_(encoder, blocksize, subframe_bps, subframe, frame);
  93246. FLAC__ASSERT(ret);
  93247. {
  93248. const unsigned actual = FLAC__bitwriter_get_input_bits_unconsumed(frame);
  93249. if(estimate != actual)
  93250. 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);
  93251. }
  93252. FLAC__bitwriter_delete(frame);
  93253. }
  93254. #endif
  93255. unsigned evaluate_constant_subframe_(
  93256. FLAC__StreamEncoder *encoder,
  93257. const FLAC__int32 signal,
  93258. unsigned blocksize,
  93259. unsigned subframe_bps,
  93260. FLAC__Subframe *subframe
  93261. )
  93262. {
  93263. unsigned estimate;
  93264. subframe->type = FLAC__SUBFRAME_TYPE_CONSTANT;
  93265. subframe->data.constant.value = signal;
  93266. estimate = FLAC__SUBFRAME_ZERO_PAD_LEN + FLAC__SUBFRAME_TYPE_LEN + FLAC__SUBFRAME_WASTED_BITS_FLAG_LEN + subframe->wasted_bits + subframe_bps;
  93267. #if SPOTCHECK_ESTIMATE
  93268. spotcheck_subframe_estimate_(encoder, blocksize, subframe_bps, subframe, estimate);
  93269. #else
  93270. (void)encoder, (void)blocksize;
  93271. #endif
  93272. return estimate;
  93273. }
  93274. unsigned evaluate_fixed_subframe_(
  93275. FLAC__StreamEncoder *encoder,
  93276. const FLAC__int32 signal[],
  93277. FLAC__int32 residual[],
  93278. FLAC__uint64 abs_residual_partition_sums[],
  93279. unsigned raw_bits_per_partition[],
  93280. unsigned blocksize,
  93281. unsigned subframe_bps,
  93282. unsigned order,
  93283. unsigned rice_parameter,
  93284. unsigned rice_parameter_limit,
  93285. unsigned min_partition_order,
  93286. unsigned max_partition_order,
  93287. FLAC__bool do_escape_coding,
  93288. unsigned rice_parameter_search_dist,
  93289. FLAC__Subframe *subframe,
  93290. FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents
  93291. )
  93292. {
  93293. unsigned i, residual_bits, estimate;
  93294. const unsigned residual_samples = blocksize - order;
  93295. FLAC__fixed_compute_residual(signal+order, residual_samples, order, residual);
  93296. subframe->type = FLAC__SUBFRAME_TYPE_FIXED;
  93297. subframe->data.fixed.entropy_coding_method.type = FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE;
  93298. subframe->data.fixed.entropy_coding_method.data.partitioned_rice.contents = partitioned_rice_contents;
  93299. subframe->data.fixed.residual = residual;
  93300. residual_bits =
  93301. find_best_partition_order_(
  93302. encoder->private_,
  93303. residual,
  93304. abs_residual_partition_sums,
  93305. raw_bits_per_partition,
  93306. residual_samples,
  93307. order,
  93308. rice_parameter,
  93309. rice_parameter_limit,
  93310. min_partition_order,
  93311. max_partition_order,
  93312. subframe_bps,
  93313. do_escape_coding,
  93314. rice_parameter_search_dist,
  93315. &subframe->data.fixed.entropy_coding_method
  93316. );
  93317. subframe->data.fixed.order = order;
  93318. for(i = 0; i < order; i++)
  93319. subframe->data.fixed.warmup[i] = signal[i];
  93320. estimate = FLAC__SUBFRAME_ZERO_PAD_LEN + FLAC__SUBFRAME_TYPE_LEN + FLAC__SUBFRAME_WASTED_BITS_FLAG_LEN + subframe->wasted_bits + (order * subframe_bps) + residual_bits;
  93321. #if SPOTCHECK_ESTIMATE
  93322. spotcheck_subframe_estimate_(encoder, blocksize, subframe_bps, subframe, estimate);
  93323. #endif
  93324. return estimate;
  93325. }
  93326. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  93327. unsigned evaluate_lpc_subframe_(
  93328. FLAC__StreamEncoder *encoder,
  93329. const FLAC__int32 signal[],
  93330. FLAC__int32 residual[],
  93331. FLAC__uint64 abs_residual_partition_sums[],
  93332. unsigned raw_bits_per_partition[],
  93333. const FLAC__real lp_coeff[],
  93334. unsigned blocksize,
  93335. unsigned subframe_bps,
  93336. unsigned order,
  93337. unsigned qlp_coeff_precision,
  93338. unsigned rice_parameter,
  93339. unsigned rice_parameter_limit,
  93340. unsigned min_partition_order,
  93341. unsigned max_partition_order,
  93342. FLAC__bool do_escape_coding,
  93343. unsigned rice_parameter_search_dist,
  93344. FLAC__Subframe *subframe,
  93345. FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents
  93346. )
  93347. {
  93348. FLAC__int32 qlp_coeff[FLAC__MAX_LPC_ORDER];
  93349. unsigned i, residual_bits, estimate;
  93350. int quantization, ret;
  93351. const unsigned residual_samples = blocksize - order;
  93352. if(subframe_bps <= 16) {
  93353. FLAC__ASSERT(order > 0);
  93354. FLAC__ASSERT(order <= FLAC__MAX_LPC_ORDER);
  93355. qlp_coeff_precision = min(qlp_coeff_precision, 32 - subframe_bps - FLAC__bitmath_ilog2(order));
  93356. }
  93357. ret = FLAC__lpc_quantize_coefficients(lp_coeff, order, qlp_coeff_precision, qlp_coeff, &quantization);
  93358. if(ret != 0)
  93359. return 0; /* this is a hack to indicate to the caller that we can't do lp at this order on this subframe */
  93360. if(subframe_bps + qlp_coeff_precision + FLAC__bitmath_ilog2(order) <= 32)
  93361. if(subframe_bps <= 16 && qlp_coeff_precision <= 16)
  93362. encoder->private_->local_lpc_compute_residual_from_qlp_coefficients_16bit(signal+order, residual_samples, qlp_coeff, order, quantization, residual);
  93363. else
  93364. encoder->private_->local_lpc_compute_residual_from_qlp_coefficients(signal+order, residual_samples, qlp_coeff, order, quantization, residual);
  93365. else
  93366. encoder->private_->local_lpc_compute_residual_from_qlp_coefficients_64bit(signal+order, residual_samples, qlp_coeff, order, quantization, residual);
  93367. subframe->type = FLAC__SUBFRAME_TYPE_LPC;
  93368. subframe->data.lpc.entropy_coding_method.type = FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE;
  93369. subframe->data.lpc.entropy_coding_method.data.partitioned_rice.contents = partitioned_rice_contents;
  93370. subframe->data.lpc.residual = residual;
  93371. residual_bits =
  93372. find_best_partition_order_(
  93373. encoder->private_,
  93374. residual,
  93375. abs_residual_partition_sums,
  93376. raw_bits_per_partition,
  93377. residual_samples,
  93378. order,
  93379. rice_parameter,
  93380. rice_parameter_limit,
  93381. min_partition_order,
  93382. max_partition_order,
  93383. subframe_bps,
  93384. do_escape_coding,
  93385. rice_parameter_search_dist,
  93386. &subframe->data.lpc.entropy_coding_method
  93387. );
  93388. subframe->data.lpc.order = order;
  93389. subframe->data.lpc.qlp_coeff_precision = qlp_coeff_precision;
  93390. subframe->data.lpc.quantization_level = quantization;
  93391. memcpy(subframe->data.lpc.qlp_coeff, qlp_coeff, sizeof(FLAC__int32)*FLAC__MAX_LPC_ORDER);
  93392. for(i = 0; i < order; i++)
  93393. subframe->data.lpc.warmup[i] = signal[i];
  93394. 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;
  93395. #if SPOTCHECK_ESTIMATE
  93396. spotcheck_subframe_estimate_(encoder, blocksize, subframe_bps, subframe, estimate);
  93397. #endif
  93398. return estimate;
  93399. }
  93400. #endif
  93401. unsigned evaluate_verbatim_subframe_(
  93402. FLAC__StreamEncoder *encoder,
  93403. const FLAC__int32 signal[],
  93404. unsigned blocksize,
  93405. unsigned subframe_bps,
  93406. FLAC__Subframe *subframe
  93407. )
  93408. {
  93409. unsigned estimate;
  93410. subframe->type = FLAC__SUBFRAME_TYPE_VERBATIM;
  93411. subframe->data.verbatim.data = signal;
  93412. estimate = FLAC__SUBFRAME_ZERO_PAD_LEN + FLAC__SUBFRAME_TYPE_LEN + FLAC__SUBFRAME_WASTED_BITS_FLAG_LEN + subframe->wasted_bits + (blocksize * subframe_bps);
  93413. #if SPOTCHECK_ESTIMATE
  93414. spotcheck_subframe_estimate_(encoder, blocksize, subframe_bps, subframe, estimate);
  93415. #else
  93416. (void)encoder;
  93417. #endif
  93418. return estimate;
  93419. }
  93420. unsigned find_best_partition_order_(
  93421. FLAC__StreamEncoderPrivate *private_,
  93422. const FLAC__int32 residual[],
  93423. FLAC__uint64 abs_residual_partition_sums[],
  93424. unsigned raw_bits_per_partition[],
  93425. unsigned residual_samples,
  93426. unsigned predictor_order,
  93427. unsigned rice_parameter,
  93428. unsigned rice_parameter_limit,
  93429. unsigned min_partition_order,
  93430. unsigned max_partition_order,
  93431. unsigned bps,
  93432. FLAC__bool do_escape_coding,
  93433. unsigned rice_parameter_search_dist,
  93434. FLAC__EntropyCodingMethod *best_ecm
  93435. )
  93436. {
  93437. unsigned residual_bits, best_residual_bits = 0;
  93438. unsigned best_parameters_index = 0;
  93439. unsigned best_partition_order = 0;
  93440. const unsigned blocksize = residual_samples + predictor_order;
  93441. max_partition_order = FLAC__format_get_max_rice_partition_order_from_blocksize_limited_max_and_predictor_order(max_partition_order, blocksize, predictor_order);
  93442. min_partition_order = min(min_partition_order, max_partition_order);
  93443. precompute_partition_info_sums_(residual, abs_residual_partition_sums, residual_samples, predictor_order, min_partition_order, max_partition_order, bps);
  93444. if(do_escape_coding)
  93445. precompute_partition_info_escapes_(residual, raw_bits_per_partition, residual_samples, predictor_order, min_partition_order, max_partition_order);
  93446. {
  93447. int partition_order;
  93448. unsigned sum;
  93449. for(partition_order = (int)max_partition_order, sum = 0; partition_order >= (int)min_partition_order; partition_order--) {
  93450. if(!
  93451. set_partitioned_rice_(
  93452. #ifdef EXACT_RICE_BITS_CALCULATION
  93453. residual,
  93454. #endif
  93455. abs_residual_partition_sums+sum,
  93456. raw_bits_per_partition+sum,
  93457. residual_samples,
  93458. predictor_order,
  93459. rice_parameter,
  93460. rice_parameter_limit,
  93461. rice_parameter_search_dist,
  93462. (unsigned)partition_order,
  93463. do_escape_coding,
  93464. &private_->partitioned_rice_contents_extra[!best_parameters_index],
  93465. &residual_bits
  93466. )
  93467. )
  93468. {
  93469. FLAC__ASSERT(best_residual_bits != 0);
  93470. break;
  93471. }
  93472. sum += 1u << partition_order;
  93473. if(best_residual_bits == 0 || residual_bits < best_residual_bits) {
  93474. best_residual_bits = residual_bits;
  93475. best_parameters_index = !best_parameters_index;
  93476. best_partition_order = partition_order;
  93477. }
  93478. }
  93479. }
  93480. best_ecm->data.partitioned_rice.order = best_partition_order;
  93481. {
  93482. FLAC__EntropyCodingMethod_PartitionedRiceContents* prc = (FLAC__EntropyCodingMethod_PartitionedRiceContents*)best_ecm->data.partitioned_rice.contents;
  93483. unsigned partition;
  93484. FLAC__format_entropy_coding_method_partitioned_rice_contents_ensure_size(prc, max(6, best_partition_order));
  93485. memcpy(prc->parameters, private_->partitioned_rice_contents_extra[best_parameters_index].parameters, sizeof(unsigned)*(1<<(best_partition_order)));
  93486. if(do_escape_coding)
  93487. memcpy(prc->raw_bits, private_->partitioned_rice_contents_extra[best_parameters_index].raw_bits, sizeof(unsigned)*(1<<(best_partition_order)));
  93488. for(partition = 0; partition < (1u<<best_partition_order); partition++) {
  93489. if(prc->parameters[partition] >= FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ESCAPE_PARAMETER) {
  93490. best_ecm->type = FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2;
  93491. break;
  93492. }
  93493. }
  93494. }
  93495. return best_residual_bits;
  93496. }
  93497. #if defined(FLAC__CPU_IA32) && !defined FLAC__NO_ASM && defined FLAC__HAS_NASM
  93498. extern void precompute_partition_info_sums_32bit_asm_ia32_(
  93499. const FLAC__int32 residual[],
  93500. FLAC__uint64 abs_residual_partition_sums[],
  93501. unsigned blocksize,
  93502. unsigned predictor_order,
  93503. unsigned min_partition_order,
  93504. unsigned max_partition_order
  93505. );
  93506. #endif
  93507. void precompute_partition_info_sums_(
  93508. const FLAC__int32 residual[],
  93509. FLAC__uint64 abs_residual_partition_sums[],
  93510. unsigned residual_samples,
  93511. unsigned predictor_order,
  93512. unsigned min_partition_order,
  93513. unsigned max_partition_order,
  93514. unsigned bps
  93515. )
  93516. {
  93517. const unsigned default_partition_samples = (residual_samples + predictor_order) >> max_partition_order;
  93518. unsigned partitions = 1u << max_partition_order;
  93519. FLAC__ASSERT(default_partition_samples > predictor_order);
  93520. #if defined(FLAC__CPU_IA32) && !defined FLAC__NO_ASM && defined FLAC__HAS_NASM
  93521. if(FLAC__bitmath_ilog2(default_partition_samples) + bps < 32) {
  93522. precompute_partition_info_sums_32bit_asm_ia32_(residual, abs_residual_partition_sums, residual_samples + predictor_order, predictor_order, min_partition_order, max_partition_order);
  93523. return;
  93524. }
  93525. #endif
  93526. {
  93527. unsigned partition, residual_sample, end = (unsigned)(-(int)predictor_order);
  93528. if(FLAC__bitmath_ilog2(default_partition_samples) + bps < 32) {
  93529. FLAC__uint32 abs_residual_partition_sum;
  93530. for(partition = residual_sample = 0; partition < partitions; partition++) {
  93531. end += default_partition_samples;
  93532. abs_residual_partition_sum = 0;
  93533. for( ; residual_sample < end; residual_sample++)
  93534. abs_residual_partition_sum += abs(residual[residual_sample]); /* abs(INT_MIN) is undefined, but if the residual is INT_MIN we have bigger problems */
  93535. abs_residual_partition_sums[partition] = abs_residual_partition_sum;
  93536. }
  93537. }
  93538. else { /* have to pessimistically use 64 bits for accumulator */
  93539. FLAC__uint64 abs_residual_partition_sum;
  93540. for(partition = residual_sample = 0; partition < partitions; partition++) {
  93541. end += default_partition_samples;
  93542. abs_residual_partition_sum = 0;
  93543. for( ; residual_sample < end; residual_sample++)
  93544. abs_residual_partition_sum += abs(residual[residual_sample]); /* abs(INT_MIN) is undefined, but if the residual is INT_MIN we have bigger problems */
  93545. abs_residual_partition_sums[partition] = abs_residual_partition_sum;
  93546. }
  93547. }
  93548. }
  93549. {
  93550. unsigned from_partition = 0, to_partition = partitions;
  93551. int partition_order;
  93552. for(partition_order = (int)max_partition_order - 1; partition_order >= (int)min_partition_order; partition_order--) {
  93553. unsigned i;
  93554. partitions >>= 1;
  93555. for(i = 0; i < partitions; i++) {
  93556. abs_residual_partition_sums[to_partition++] =
  93557. abs_residual_partition_sums[from_partition ] +
  93558. abs_residual_partition_sums[from_partition+1];
  93559. from_partition += 2;
  93560. }
  93561. }
  93562. }
  93563. }
  93564. void precompute_partition_info_escapes_(
  93565. const FLAC__int32 residual[],
  93566. unsigned raw_bits_per_partition[],
  93567. unsigned residual_samples,
  93568. unsigned predictor_order,
  93569. unsigned min_partition_order,
  93570. unsigned max_partition_order
  93571. )
  93572. {
  93573. int partition_order;
  93574. unsigned from_partition, to_partition = 0;
  93575. const unsigned blocksize = residual_samples + predictor_order;
  93576. for(partition_order = (int)max_partition_order; partition_order >= 0; partition_order--) {
  93577. FLAC__int32 r;
  93578. FLAC__uint32 rmax;
  93579. unsigned partition, partition_sample, partition_samples, residual_sample;
  93580. const unsigned partitions = 1u << partition_order;
  93581. const unsigned default_partition_samples = blocksize >> partition_order;
  93582. FLAC__ASSERT(default_partition_samples > predictor_order);
  93583. for(partition = residual_sample = 0; partition < partitions; partition++) {
  93584. partition_samples = default_partition_samples;
  93585. if(partition == 0)
  93586. partition_samples -= predictor_order;
  93587. rmax = 0;
  93588. for(partition_sample = 0; partition_sample < partition_samples; partition_sample++) {
  93589. r = residual[residual_sample++];
  93590. if(r < 0)
  93591. rmax |= ~r;
  93592. else
  93593. rmax |= r;
  93594. }
  93595. raw_bits_per_partition[partition] = rmax? FLAC__bitmath_ilog2(rmax) + 2 : 1;
  93596. }
  93597. to_partition = partitions;
  93598. break; /*@@@ yuck, should remove the 'for' loop instead */
  93599. }
  93600. for(from_partition = 0, --partition_order; partition_order >= (int)min_partition_order; partition_order--) {
  93601. unsigned m;
  93602. unsigned i;
  93603. const unsigned partitions = 1u << partition_order;
  93604. for(i = 0; i < partitions; i++) {
  93605. m = raw_bits_per_partition[from_partition];
  93606. from_partition++;
  93607. raw_bits_per_partition[to_partition] = max(m, raw_bits_per_partition[from_partition]);
  93608. from_partition++;
  93609. to_partition++;
  93610. }
  93611. }
  93612. }
  93613. #ifdef EXACT_RICE_BITS_CALCULATION
  93614. static FLaC__INLINE unsigned count_rice_bits_in_partition_(
  93615. const unsigned rice_parameter,
  93616. const unsigned partition_samples,
  93617. const FLAC__int32 *residual
  93618. )
  93619. {
  93620. unsigned i, partition_bits =
  93621. 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 */
  93622. (1+rice_parameter) * partition_samples /* 1 for unary stop bit + rice_parameter for the binary portion */
  93623. ;
  93624. for(i = 0; i < partition_samples; i++)
  93625. partition_bits += ( (FLAC__uint32)((residual[i]<<1)^(residual[i]>>31)) >> rice_parameter );
  93626. return partition_bits;
  93627. }
  93628. #else
  93629. static FLaC__INLINE unsigned count_rice_bits_in_partition_(
  93630. const unsigned rice_parameter,
  93631. const unsigned partition_samples,
  93632. const FLAC__uint64 abs_residual_partition_sum
  93633. )
  93634. {
  93635. return
  93636. 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 */
  93637. (1+rice_parameter) * partition_samples + /* 1 for unary stop bit + rice_parameter for the binary portion */
  93638. (
  93639. rice_parameter?
  93640. (unsigned)(abs_residual_partition_sum >> (rice_parameter-1)) /* rice_parameter-1 because the real coder sign-folds instead of using a sign bit */
  93641. : (unsigned)(abs_residual_partition_sum << 1) /* can't shift by negative number, so reverse */
  93642. )
  93643. - (partition_samples >> 1)
  93644. ;
  93645. }
  93646. #endif
  93647. FLAC__bool set_partitioned_rice_(
  93648. #ifdef EXACT_RICE_BITS_CALCULATION
  93649. const FLAC__int32 residual[],
  93650. #endif
  93651. const FLAC__uint64 abs_residual_partition_sums[],
  93652. const unsigned raw_bits_per_partition[],
  93653. const unsigned residual_samples,
  93654. const unsigned predictor_order,
  93655. const unsigned suggested_rice_parameter,
  93656. const unsigned rice_parameter_limit,
  93657. const unsigned rice_parameter_search_dist,
  93658. const unsigned partition_order,
  93659. const FLAC__bool search_for_escapes,
  93660. FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents,
  93661. unsigned *bits
  93662. )
  93663. {
  93664. unsigned rice_parameter, partition_bits;
  93665. unsigned best_partition_bits, best_rice_parameter = 0;
  93666. unsigned bits_ = FLAC__ENTROPY_CODING_METHOD_TYPE_LEN + FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ORDER_LEN;
  93667. unsigned *parameters, *raw_bits;
  93668. #ifdef ENABLE_RICE_PARAMETER_SEARCH
  93669. unsigned min_rice_parameter, max_rice_parameter;
  93670. #else
  93671. (void)rice_parameter_search_dist;
  93672. #endif
  93673. FLAC__ASSERT(suggested_rice_parameter < FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_ESCAPE_PARAMETER);
  93674. FLAC__ASSERT(rice_parameter_limit <= FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_ESCAPE_PARAMETER);
  93675. FLAC__format_entropy_coding_method_partitioned_rice_contents_ensure_size(partitioned_rice_contents, max(6, partition_order));
  93676. parameters = partitioned_rice_contents->parameters;
  93677. raw_bits = partitioned_rice_contents->raw_bits;
  93678. if(partition_order == 0) {
  93679. best_partition_bits = (unsigned)(-1);
  93680. #ifdef ENABLE_RICE_PARAMETER_SEARCH
  93681. if(rice_parameter_search_dist) {
  93682. if(suggested_rice_parameter < rice_parameter_search_dist)
  93683. min_rice_parameter = 0;
  93684. else
  93685. min_rice_parameter = suggested_rice_parameter - rice_parameter_search_dist;
  93686. max_rice_parameter = suggested_rice_parameter + rice_parameter_search_dist;
  93687. if(max_rice_parameter >= rice_parameter_limit) {
  93688. #ifdef DEBUG_VERBOSE
  93689. fprintf(stderr, "clipping rice_parameter (%u -> %u) @5\n", max_rice_parameter, rice_parameter_limit - 1);
  93690. #endif
  93691. max_rice_parameter = rice_parameter_limit - 1;
  93692. }
  93693. }
  93694. else
  93695. min_rice_parameter = max_rice_parameter = suggested_rice_parameter;
  93696. for(rice_parameter = min_rice_parameter; rice_parameter <= max_rice_parameter; rice_parameter++) {
  93697. #else
  93698. rice_parameter = suggested_rice_parameter;
  93699. #endif
  93700. #ifdef EXACT_RICE_BITS_CALCULATION
  93701. partition_bits = count_rice_bits_in_partition_(rice_parameter, residual_samples, residual);
  93702. #else
  93703. partition_bits = count_rice_bits_in_partition_(rice_parameter, residual_samples, abs_residual_partition_sums[0]);
  93704. #endif
  93705. if(partition_bits < best_partition_bits) {
  93706. best_rice_parameter = rice_parameter;
  93707. best_partition_bits = partition_bits;
  93708. }
  93709. #ifdef ENABLE_RICE_PARAMETER_SEARCH
  93710. }
  93711. #endif
  93712. if(search_for_escapes) {
  93713. 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;
  93714. if(partition_bits <= best_partition_bits) {
  93715. raw_bits[0] = raw_bits_per_partition[0];
  93716. best_rice_parameter = 0; /* will be converted to appropriate escape parameter later */
  93717. best_partition_bits = partition_bits;
  93718. }
  93719. else
  93720. raw_bits[0] = 0;
  93721. }
  93722. parameters[0] = best_rice_parameter;
  93723. bits_ += best_partition_bits;
  93724. }
  93725. else {
  93726. unsigned partition, residual_sample;
  93727. unsigned partition_samples;
  93728. FLAC__uint64 mean, k;
  93729. const unsigned partitions = 1u << partition_order;
  93730. for(partition = residual_sample = 0; partition < partitions; partition++) {
  93731. partition_samples = (residual_samples+predictor_order) >> partition_order;
  93732. if(partition == 0) {
  93733. if(partition_samples <= predictor_order)
  93734. return false;
  93735. else
  93736. partition_samples -= predictor_order;
  93737. }
  93738. mean = abs_residual_partition_sums[partition];
  93739. for(rice_parameter = 0, k = partition_samples; k < mean; rice_parameter++, k <<= 1)
  93740. ;
  93741. if(rice_parameter >= rice_parameter_limit) {
  93742. #ifdef DEBUG_VERBOSE
  93743. fprintf(stderr, "clipping rice_parameter (%u -> %u) @6\n", rice_parameter, rice_parameter_limit - 1);
  93744. #endif
  93745. rice_parameter = rice_parameter_limit - 1;
  93746. }
  93747. best_partition_bits = (unsigned)(-1);
  93748. #ifdef ENABLE_RICE_PARAMETER_SEARCH
  93749. if(rice_parameter_search_dist) {
  93750. if(rice_parameter < rice_parameter_search_dist)
  93751. min_rice_parameter = 0;
  93752. else
  93753. min_rice_parameter = rice_parameter - rice_parameter_search_dist;
  93754. max_rice_parameter = rice_parameter + rice_parameter_search_dist;
  93755. if(max_rice_parameter >= rice_parameter_limit) {
  93756. #ifdef DEBUG_VERBOSE
  93757. fprintf(stderr, "clipping rice_parameter (%u -> %u) @7\n", max_rice_parameter, rice_parameter_limit - 1);
  93758. #endif
  93759. max_rice_parameter = rice_parameter_limit - 1;
  93760. }
  93761. }
  93762. else
  93763. min_rice_parameter = max_rice_parameter = rice_parameter;
  93764. for(rice_parameter = min_rice_parameter; rice_parameter <= max_rice_parameter; rice_parameter++) {
  93765. #endif
  93766. #ifdef EXACT_RICE_BITS_CALCULATION
  93767. partition_bits = count_rice_bits_in_partition_(rice_parameter, partition_samples, residual+residual_sample);
  93768. #else
  93769. partition_bits = count_rice_bits_in_partition_(rice_parameter, partition_samples, abs_residual_partition_sums[partition]);
  93770. #endif
  93771. if(partition_bits < best_partition_bits) {
  93772. best_rice_parameter = rice_parameter;
  93773. best_partition_bits = partition_bits;
  93774. }
  93775. #ifdef ENABLE_RICE_PARAMETER_SEARCH
  93776. }
  93777. #endif
  93778. if(search_for_escapes) {
  93779. 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;
  93780. if(partition_bits <= best_partition_bits) {
  93781. raw_bits[partition] = raw_bits_per_partition[partition];
  93782. best_rice_parameter = 0; /* will be converted to appropriate escape parameter later */
  93783. best_partition_bits = partition_bits;
  93784. }
  93785. else
  93786. raw_bits[partition] = 0;
  93787. }
  93788. parameters[partition] = best_rice_parameter;
  93789. bits_ += best_partition_bits;
  93790. residual_sample += partition_samples;
  93791. }
  93792. }
  93793. *bits = bits_;
  93794. return true;
  93795. }
  93796. unsigned get_wasted_bits_(FLAC__int32 signal[], unsigned samples)
  93797. {
  93798. unsigned i, shift;
  93799. FLAC__int32 x = 0;
  93800. for(i = 0; i < samples && !(x&1); i++)
  93801. x |= signal[i];
  93802. if(x == 0) {
  93803. shift = 0;
  93804. }
  93805. else {
  93806. for(shift = 0; !(x&1); shift++)
  93807. x >>= 1;
  93808. }
  93809. if(shift > 0) {
  93810. for(i = 0; i < samples; i++)
  93811. signal[i] >>= shift;
  93812. }
  93813. return shift;
  93814. }
  93815. void append_to_verify_fifo_(verify_input_fifo *fifo, const FLAC__int32 * const input[], unsigned input_offset, unsigned channels, unsigned wide_samples)
  93816. {
  93817. unsigned channel;
  93818. for(channel = 0; channel < channels; channel++)
  93819. memcpy(&fifo->data[channel][fifo->tail], &input[channel][input_offset], sizeof(FLAC__int32) * wide_samples);
  93820. fifo->tail += wide_samples;
  93821. FLAC__ASSERT(fifo->tail <= fifo->size);
  93822. }
  93823. void append_to_verify_fifo_interleaved_(verify_input_fifo *fifo, const FLAC__int32 input[], unsigned input_offset, unsigned channels, unsigned wide_samples)
  93824. {
  93825. unsigned channel;
  93826. unsigned sample, wide_sample;
  93827. unsigned tail = fifo->tail;
  93828. sample = input_offset * channels;
  93829. for(wide_sample = 0; wide_sample < wide_samples; wide_sample++) {
  93830. for(channel = 0; channel < channels; channel++)
  93831. fifo->data[channel][tail] = input[sample++];
  93832. tail++;
  93833. }
  93834. fifo->tail = tail;
  93835. FLAC__ASSERT(fifo->tail <= fifo->size);
  93836. }
  93837. FLAC__StreamDecoderReadStatus verify_read_callback_(const FLAC__StreamDecoder *decoder, FLAC__byte buffer[], size_t *bytes, void *client_data)
  93838. {
  93839. FLAC__StreamEncoder *encoder = (FLAC__StreamEncoder*)client_data;
  93840. const size_t encoded_bytes = encoder->private_->verify.output.bytes;
  93841. (void)decoder;
  93842. if(encoder->private_->verify.needs_magic_hack) {
  93843. FLAC__ASSERT(*bytes >= FLAC__STREAM_SYNC_LENGTH);
  93844. *bytes = FLAC__STREAM_SYNC_LENGTH;
  93845. memcpy(buffer, FLAC__STREAM_SYNC_STRING, *bytes);
  93846. encoder->private_->verify.needs_magic_hack = false;
  93847. }
  93848. else {
  93849. if(encoded_bytes == 0) {
  93850. FLAC__ASSERT(0);
  93851. return FLAC__STREAM_DECODER_READ_STATUS_ABORT;
  93852. }
  93853. else if(encoded_bytes < *bytes)
  93854. *bytes = encoded_bytes;
  93855. memcpy(buffer, encoder->private_->verify.output.data, *bytes);
  93856. encoder->private_->verify.output.data += *bytes;
  93857. encoder->private_->verify.output.bytes -= *bytes;
  93858. }
  93859. return FLAC__STREAM_DECODER_READ_STATUS_CONTINUE;
  93860. }
  93861. FLAC__StreamDecoderWriteStatus verify_write_callback_(const FLAC__StreamDecoder *decoder, const FLAC__Frame *frame, const FLAC__int32 * const buffer[], void *client_data)
  93862. {
  93863. FLAC__StreamEncoder *encoder = (FLAC__StreamEncoder *)client_data;
  93864. unsigned channel;
  93865. const unsigned channels = frame->header.channels;
  93866. const unsigned blocksize = frame->header.blocksize;
  93867. const unsigned bytes_per_block = sizeof(FLAC__int32) * blocksize;
  93868. (void)decoder;
  93869. for(channel = 0; channel < channels; channel++) {
  93870. if(0 != memcmp(buffer[channel], encoder->private_->verify.input_fifo.data[channel], bytes_per_block)) {
  93871. unsigned i, sample = 0;
  93872. FLAC__int32 expect = 0, got = 0;
  93873. for(i = 0; i < blocksize; i++) {
  93874. if(buffer[channel][i] != encoder->private_->verify.input_fifo.data[channel][i]) {
  93875. sample = i;
  93876. expect = (FLAC__int32)encoder->private_->verify.input_fifo.data[channel][i];
  93877. got = (FLAC__int32)buffer[channel][i];
  93878. break;
  93879. }
  93880. }
  93881. FLAC__ASSERT(i < blocksize);
  93882. FLAC__ASSERT(frame->header.number_type == FLAC__FRAME_NUMBER_TYPE_SAMPLE_NUMBER);
  93883. encoder->private_->verify.error_stats.absolute_sample = frame->header.number.sample_number + sample;
  93884. encoder->private_->verify.error_stats.frame_number = (unsigned)(frame->header.number.sample_number / blocksize);
  93885. encoder->private_->verify.error_stats.channel = channel;
  93886. encoder->private_->verify.error_stats.sample = sample;
  93887. encoder->private_->verify.error_stats.expected = expect;
  93888. encoder->private_->verify.error_stats.got = got;
  93889. encoder->protected_->state = FLAC__STREAM_ENCODER_VERIFY_MISMATCH_IN_AUDIO_DATA;
  93890. return FLAC__STREAM_DECODER_WRITE_STATUS_ABORT;
  93891. }
  93892. }
  93893. encoder->private_->verify.input_fifo.tail -= blocksize;
  93894. FLAC__ASSERT(encoder->private_->verify.input_fifo.tail <= OVERREAD_);
  93895. for(channel = 0; channel < channels; channel++)
  93896. 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]));
  93897. return FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE;
  93898. }
  93899. void verify_metadata_callback_(const FLAC__StreamDecoder *decoder, const FLAC__StreamMetadata *metadata, void *client_data)
  93900. {
  93901. (void)decoder, (void)metadata, (void)client_data;
  93902. }
  93903. void verify_error_callback_(const FLAC__StreamDecoder *decoder, FLAC__StreamDecoderErrorStatus status, void *client_data)
  93904. {
  93905. FLAC__StreamEncoder *encoder = (FLAC__StreamEncoder*)client_data;
  93906. (void)decoder, (void)status;
  93907. encoder->protected_->state = FLAC__STREAM_ENCODER_VERIFY_DECODER_ERROR;
  93908. }
  93909. FLAC__StreamEncoderReadStatus file_read_callback_enc(const FLAC__StreamEncoder *encoder, FLAC__byte buffer[], size_t *bytes, void *client_data)
  93910. {
  93911. (void)client_data;
  93912. *bytes = fread(buffer, 1, *bytes, encoder->private_->file);
  93913. if (*bytes == 0) {
  93914. if (feof(encoder->private_->file))
  93915. return FLAC__STREAM_ENCODER_READ_STATUS_END_OF_STREAM;
  93916. else if (ferror(encoder->private_->file))
  93917. return FLAC__STREAM_ENCODER_READ_STATUS_ABORT;
  93918. }
  93919. return FLAC__STREAM_ENCODER_READ_STATUS_CONTINUE;
  93920. }
  93921. FLAC__StreamEncoderSeekStatus file_seek_callback_enc(const FLAC__StreamEncoder *encoder, FLAC__uint64 absolute_byte_offset, void *client_data)
  93922. {
  93923. (void)client_data;
  93924. if(fseeko(encoder->private_->file, (off_t)absolute_byte_offset, SEEK_SET) < 0)
  93925. return FLAC__STREAM_ENCODER_SEEK_STATUS_ERROR;
  93926. else
  93927. return FLAC__STREAM_ENCODER_SEEK_STATUS_OK;
  93928. }
  93929. FLAC__StreamEncoderTellStatus file_tell_callback_enc(const FLAC__StreamEncoder *encoder, FLAC__uint64 *absolute_byte_offset, void *client_data)
  93930. {
  93931. off_t offset;
  93932. (void)client_data;
  93933. offset = ftello(encoder->private_->file);
  93934. if(offset < 0) {
  93935. return FLAC__STREAM_ENCODER_TELL_STATUS_ERROR;
  93936. }
  93937. else {
  93938. *absolute_byte_offset = (FLAC__uint64)offset;
  93939. return FLAC__STREAM_ENCODER_TELL_STATUS_OK;
  93940. }
  93941. }
  93942. #ifdef FLAC__VALGRIND_TESTING
  93943. static size_t local__fwrite(const void *ptr, size_t size, size_t nmemb, FILE *stream)
  93944. {
  93945. size_t ret = fwrite(ptr, size, nmemb, stream);
  93946. if(!ferror(stream))
  93947. fflush(stream);
  93948. return ret;
  93949. }
  93950. #else
  93951. #define local__fwrite fwrite
  93952. #endif
  93953. FLAC__StreamEncoderWriteStatus file_write_callback_(const FLAC__StreamEncoder *encoder, const FLAC__byte buffer[], size_t bytes, unsigned samples, unsigned current_frame, void *client_data)
  93954. {
  93955. (void)client_data, (void)current_frame;
  93956. if(local__fwrite(buffer, sizeof(FLAC__byte), bytes, encoder->private_->file) == bytes) {
  93957. FLAC__bool call_it = 0 != encoder->private_->progress_callback && (
  93958. #if FLAC__HAS_OGG
  93959. encoder->private_->is_ogg? true :
  93960. #endif
  93961. samples > 0
  93962. );
  93963. if(call_it) {
  93964. 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);
  93965. }
  93966. return FLAC__STREAM_ENCODER_WRITE_STATUS_OK;
  93967. }
  93968. else
  93969. return FLAC__STREAM_ENCODER_WRITE_STATUS_FATAL_ERROR;
  93970. }
  93971. FILE *get_binary_stdout_(void)
  93972. {
  93973. #if defined _MSC_VER || defined __MINGW32__
  93974. _setmode(_fileno(stdout), _O_BINARY);
  93975. #elif defined __CYGWIN__
  93976. setmode(_fileno(stdout), _O_BINARY);
  93977. #elif defined __EMX__
  93978. setmode(fileno(stdout), O_BINARY);
  93979. #endif
  93980. return stdout;
  93981. }
  93982. #endif
  93983. /********* End of inlined file: stream_encoder.c *********/
  93984. /********* Start of inlined file: stream_encoder_framing.c *********/
  93985. /********* Start of inlined file: juce_FlacHeader.h *********/
  93986. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  93987. // tasks..
  93988. #define VERSION "1.2.1"
  93989. #define FLAC__NO_DLL 1
  93990. #if JUCE_MSVC
  93991. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  93992. #endif
  93993. #if JUCE_MAC
  93994. #define FLAC__SYS_DARWIN 1
  93995. #endif
  93996. /********* End of inlined file: juce_FlacHeader.h *********/
  93997. #if JUCE_USE_FLAC
  93998. #if HAVE_CONFIG_H
  93999. # include <config.h>
  94000. #endif
  94001. #include <stdio.h>
  94002. #include <string.h> /* for strlen() */
  94003. #ifdef max
  94004. #undef max
  94005. #endif
  94006. #define max(x,y) ((x)>(y)?(x):(y))
  94007. static FLAC__bool add_entropy_coding_method_(FLAC__BitWriter *bw, const FLAC__EntropyCodingMethod *method);
  94008. 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);
  94009. FLAC__bool FLAC__add_metadata_block(const FLAC__StreamMetadata *metadata, FLAC__BitWriter *bw)
  94010. {
  94011. unsigned i, j;
  94012. const unsigned vendor_string_length = (unsigned)strlen(FLAC__VENDOR_STRING);
  94013. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->is_last, FLAC__STREAM_METADATA_IS_LAST_LEN))
  94014. return false;
  94015. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->type, FLAC__STREAM_METADATA_TYPE_LEN))
  94016. return false;
  94017. i = metadata->length;
  94018. if(metadata->type == FLAC__METADATA_TYPE_VORBIS_COMMENT) {
  94019. FLAC__ASSERT(metadata->data.vorbis_comment.vendor_string.length == 0 || 0 != metadata->data.vorbis_comment.vendor_string.entry);
  94020. i -= metadata->data.vorbis_comment.vendor_string.length;
  94021. i += vendor_string_length;
  94022. }
  94023. FLAC__ASSERT(i < (1u << FLAC__STREAM_METADATA_LENGTH_LEN));
  94024. if(!FLAC__bitwriter_write_raw_uint32(bw, i, FLAC__STREAM_METADATA_LENGTH_LEN))
  94025. return false;
  94026. switch(metadata->type) {
  94027. case FLAC__METADATA_TYPE_STREAMINFO:
  94028. FLAC__ASSERT(metadata->data.stream_info.min_blocksize < (1u << FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN));
  94029. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.stream_info.min_blocksize, FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN))
  94030. return false;
  94031. FLAC__ASSERT(metadata->data.stream_info.max_blocksize < (1u << FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN));
  94032. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.stream_info.max_blocksize, FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN))
  94033. return false;
  94034. FLAC__ASSERT(metadata->data.stream_info.min_framesize < (1u << FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN));
  94035. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.stream_info.min_framesize, FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN))
  94036. return false;
  94037. FLAC__ASSERT(metadata->data.stream_info.max_framesize < (1u << FLAC__STREAM_METADATA_STREAMINFO_MAX_FRAME_SIZE_LEN));
  94038. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.stream_info.max_framesize, FLAC__STREAM_METADATA_STREAMINFO_MAX_FRAME_SIZE_LEN))
  94039. return false;
  94040. FLAC__ASSERT(FLAC__format_sample_rate_is_valid(metadata->data.stream_info.sample_rate));
  94041. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.stream_info.sample_rate, FLAC__STREAM_METADATA_STREAMINFO_SAMPLE_RATE_LEN))
  94042. return false;
  94043. FLAC__ASSERT(metadata->data.stream_info.channels > 0);
  94044. FLAC__ASSERT(metadata->data.stream_info.channels <= (1u << FLAC__STREAM_METADATA_STREAMINFO_CHANNELS_LEN));
  94045. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.stream_info.channels-1, FLAC__STREAM_METADATA_STREAMINFO_CHANNELS_LEN))
  94046. return false;
  94047. FLAC__ASSERT(metadata->data.stream_info.bits_per_sample > 0);
  94048. FLAC__ASSERT(metadata->data.stream_info.bits_per_sample <= (1u << FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN));
  94049. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.stream_info.bits_per_sample-1, FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN))
  94050. return false;
  94051. if(!FLAC__bitwriter_write_raw_uint64(bw, metadata->data.stream_info.total_samples, FLAC__STREAM_METADATA_STREAMINFO_TOTAL_SAMPLES_LEN))
  94052. return false;
  94053. if(!FLAC__bitwriter_write_byte_block(bw, metadata->data.stream_info.md5sum, 16))
  94054. return false;
  94055. break;
  94056. case FLAC__METADATA_TYPE_PADDING:
  94057. if(!FLAC__bitwriter_write_zeroes(bw, metadata->length * 8))
  94058. return false;
  94059. break;
  94060. case FLAC__METADATA_TYPE_APPLICATION:
  94061. if(!FLAC__bitwriter_write_byte_block(bw, metadata->data.application.id, FLAC__STREAM_METADATA_APPLICATION_ID_LEN / 8))
  94062. return false;
  94063. if(!FLAC__bitwriter_write_byte_block(bw, metadata->data.application.data, metadata->length - (FLAC__STREAM_METADATA_APPLICATION_ID_LEN / 8)))
  94064. return false;
  94065. break;
  94066. case FLAC__METADATA_TYPE_SEEKTABLE:
  94067. for(i = 0; i < metadata->data.seek_table.num_points; i++) {
  94068. if(!FLAC__bitwriter_write_raw_uint64(bw, metadata->data.seek_table.points[i].sample_number, FLAC__STREAM_METADATA_SEEKPOINT_SAMPLE_NUMBER_LEN))
  94069. return false;
  94070. if(!FLAC__bitwriter_write_raw_uint64(bw, metadata->data.seek_table.points[i].stream_offset, FLAC__STREAM_METADATA_SEEKPOINT_STREAM_OFFSET_LEN))
  94071. return false;
  94072. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.seek_table.points[i].frame_samples, FLAC__STREAM_METADATA_SEEKPOINT_FRAME_SAMPLES_LEN))
  94073. return false;
  94074. }
  94075. break;
  94076. case FLAC__METADATA_TYPE_VORBIS_COMMENT:
  94077. if(!FLAC__bitwriter_write_raw_uint32_little_endian(bw, vendor_string_length))
  94078. return false;
  94079. if(!FLAC__bitwriter_write_byte_block(bw, (const FLAC__byte*)FLAC__VENDOR_STRING, vendor_string_length))
  94080. return false;
  94081. if(!FLAC__bitwriter_write_raw_uint32_little_endian(bw, metadata->data.vorbis_comment.num_comments))
  94082. return false;
  94083. for(i = 0; i < metadata->data.vorbis_comment.num_comments; i++) {
  94084. if(!FLAC__bitwriter_write_raw_uint32_little_endian(bw, metadata->data.vorbis_comment.comments[i].length))
  94085. return false;
  94086. if(!FLAC__bitwriter_write_byte_block(bw, metadata->data.vorbis_comment.comments[i].entry, metadata->data.vorbis_comment.comments[i].length))
  94087. return false;
  94088. }
  94089. break;
  94090. case FLAC__METADATA_TYPE_CUESHEET:
  94091. FLAC__ASSERT(FLAC__STREAM_METADATA_CUESHEET_MEDIA_CATALOG_NUMBER_LEN % 8 == 0);
  94092. 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))
  94093. return false;
  94094. if(!FLAC__bitwriter_write_raw_uint64(bw, metadata->data.cue_sheet.lead_in, FLAC__STREAM_METADATA_CUESHEET_LEAD_IN_LEN))
  94095. return false;
  94096. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.cue_sheet.is_cd? 1 : 0, FLAC__STREAM_METADATA_CUESHEET_IS_CD_LEN))
  94097. return false;
  94098. if(!FLAC__bitwriter_write_zeroes(bw, FLAC__STREAM_METADATA_CUESHEET_RESERVED_LEN))
  94099. return false;
  94100. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.cue_sheet.num_tracks, FLAC__STREAM_METADATA_CUESHEET_NUM_TRACKS_LEN))
  94101. return false;
  94102. for(i = 0; i < metadata->data.cue_sheet.num_tracks; i++) {
  94103. const FLAC__StreamMetadata_CueSheet_Track *track = metadata->data.cue_sheet.tracks + i;
  94104. if(!FLAC__bitwriter_write_raw_uint64(bw, track->offset, FLAC__STREAM_METADATA_CUESHEET_TRACK_OFFSET_LEN))
  94105. return false;
  94106. if(!FLAC__bitwriter_write_raw_uint32(bw, track->number, FLAC__STREAM_METADATA_CUESHEET_TRACK_NUMBER_LEN))
  94107. return false;
  94108. FLAC__ASSERT(FLAC__STREAM_METADATA_CUESHEET_TRACK_ISRC_LEN % 8 == 0);
  94109. if(!FLAC__bitwriter_write_byte_block(bw, (const FLAC__byte*)track->isrc, FLAC__STREAM_METADATA_CUESHEET_TRACK_ISRC_LEN/8))
  94110. return false;
  94111. if(!FLAC__bitwriter_write_raw_uint32(bw, track->type, FLAC__STREAM_METADATA_CUESHEET_TRACK_TYPE_LEN))
  94112. return false;
  94113. if(!FLAC__bitwriter_write_raw_uint32(bw, track->pre_emphasis, FLAC__STREAM_METADATA_CUESHEET_TRACK_PRE_EMPHASIS_LEN))
  94114. return false;
  94115. if(!FLAC__bitwriter_write_zeroes(bw, FLAC__STREAM_METADATA_CUESHEET_TRACK_RESERVED_LEN))
  94116. return false;
  94117. if(!FLAC__bitwriter_write_raw_uint32(bw, track->num_indices, FLAC__STREAM_METADATA_CUESHEET_TRACK_NUM_INDICES_LEN))
  94118. return false;
  94119. for(j = 0; j < track->num_indices; j++) {
  94120. const FLAC__StreamMetadata_CueSheet_Index *index = track->indices + j;
  94121. if(!FLAC__bitwriter_write_raw_uint64(bw, index->offset, FLAC__STREAM_METADATA_CUESHEET_INDEX_OFFSET_LEN))
  94122. return false;
  94123. if(!FLAC__bitwriter_write_raw_uint32(bw, index->number, FLAC__STREAM_METADATA_CUESHEET_INDEX_NUMBER_LEN))
  94124. return false;
  94125. if(!FLAC__bitwriter_write_zeroes(bw, FLAC__STREAM_METADATA_CUESHEET_INDEX_RESERVED_LEN))
  94126. return false;
  94127. }
  94128. }
  94129. break;
  94130. case FLAC__METADATA_TYPE_PICTURE:
  94131. {
  94132. size_t len;
  94133. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.picture.type, FLAC__STREAM_METADATA_PICTURE_TYPE_LEN))
  94134. return false;
  94135. len = strlen(metadata->data.picture.mime_type);
  94136. if(!FLAC__bitwriter_write_raw_uint32(bw, len, FLAC__STREAM_METADATA_PICTURE_MIME_TYPE_LENGTH_LEN))
  94137. return false;
  94138. if(!FLAC__bitwriter_write_byte_block(bw, (const FLAC__byte*)metadata->data.picture.mime_type, len))
  94139. return false;
  94140. len = strlen((const char *)metadata->data.picture.description);
  94141. if(!FLAC__bitwriter_write_raw_uint32(bw, len, FLAC__STREAM_METADATA_PICTURE_DESCRIPTION_LENGTH_LEN))
  94142. return false;
  94143. if(!FLAC__bitwriter_write_byte_block(bw, metadata->data.picture.description, len))
  94144. return false;
  94145. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.picture.width, FLAC__STREAM_METADATA_PICTURE_WIDTH_LEN))
  94146. return false;
  94147. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.picture.height, FLAC__STREAM_METADATA_PICTURE_HEIGHT_LEN))
  94148. return false;
  94149. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.picture.depth, FLAC__STREAM_METADATA_PICTURE_DEPTH_LEN))
  94150. return false;
  94151. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.picture.colors, FLAC__STREAM_METADATA_PICTURE_COLORS_LEN))
  94152. return false;
  94153. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.picture.data_length, FLAC__STREAM_METADATA_PICTURE_DATA_LENGTH_LEN))
  94154. return false;
  94155. if(!FLAC__bitwriter_write_byte_block(bw, metadata->data.picture.data, metadata->data.picture.data_length))
  94156. return false;
  94157. }
  94158. break;
  94159. default:
  94160. if(!FLAC__bitwriter_write_byte_block(bw, metadata->data.unknown.data, metadata->length))
  94161. return false;
  94162. break;
  94163. }
  94164. FLAC__ASSERT(FLAC__bitwriter_is_byte_aligned(bw));
  94165. return true;
  94166. }
  94167. FLAC__bool FLAC__frame_add_header(const FLAC__FrameHeader *header, FLAC__BitWriter *bw)
  94168. {
  94169. unsigned u, blocksize_hint, sample_rate_hint;
  94170. FLAC__byte crc;
  94171. FLAC__ASSERT(FLAC__bitwriter_is_byte_aligned(bw));
  94172. if(!FLAC__bitwriter_write_raw_uint32(bw, FLAC__FRAME_HEADER_SYNC, FLAC__FRAME_HEADER_SYNC_LEN))
  94173. return false;
  94174. if(!FLAC__bitwriter_write_raw_uint32(bw, 0, FLAC__FRAME_HEADER_RESERVED_LEN))
  94175. return false;
  94176. if(!FLAC__bitwriter_write_raw_uint32(bw, (header->number_type == FLAC__FRAME_NUMBER_TYPE_FRAME_NUMBER)? 0 : 1, FLAC__FRAME_HEADER_BLOCKING_STRATEGY_LEN))
  94177. return false;
  94178. FLAC__ASSERT(header->blocksize > 0 && header->blocksize <= FLAC__MAX_BLOCK_SIZE);
  94179. FLAC__ASSERT(FLAC__MAX_BLOCK_SIZE <= 65535u);
  94180. blocksize_hint = 0;
  94181. switch(header->blocksize) {
  94182. case 192: u = 1; break;
  94183. case 576: u = 2; break;
  94184. case 1152: u = 3; break;
  94185. case 2304: u = 4; break;
  94186. case 4608: u = 5; break;
  94187. case 256: u = 8; break;
  94188. case 512: u = 9; break;
  94189. case 1024: u = 10; break;
  94190. case 2048: u = 11; break;
  94191. case 4096: u = 12; break;
  94192. case 8192: u = 13; break;
  94193. case 16384: u = 14; break;
  94194. case 32768: u = 15; break;
  94195. default:
  94196. if(header->blocksize <= 0x100)
  94197. blocksize_hint = u = 6;
  94198. else
  94199. blocksize_hint = u = 7;
  94200. break;
  94201. }
  94202. if(!FLAC__bitwriter_write_raw_uint32(bw, u, FLAC__FRAME_HEADER_BLOCK_SIZE_LEN))
  94203. return false;
  94204. FLAC__ASSERT(FLAC__format_sample_rate_is_valid(header->sample_rate));
  94205. sample_rate_hint = 0;
  94206. switch(header->sample_rate) {
  94207. case 88200: u = 1; break;
  94208. case 176400: u = 2; break;
  94209. case 192000: u = 3; break;
  94210. case 8000: u = 4; break;
  94211. case 16000: u = 5; break;
  94212. case 22050: u = 6; break;
  94213. case 24000: u = 7; break;
  94214. case 32000: u = 8; break;
  94215. case 44100: u = 9; break;
  94216. case 48000: u = 10; break;
  94217. case 96000: u = 11; break;
  94218. default:
  94219. if(header->sample_rate <= 255000 && header->sample_rate % 1000 == 0)
  94220. sample_rate_hint = u = 12;
  94221. else if(header->sample_rate % 10 == 0)
  94222. sample_rate_hint = u = 14;
  94223. else if(header->sample_rate <= 0xffff)
  94224. sample_rate_hint = u = 13;
  94225. else
  94226. u = 0;
  94227. break;
  94228. }
  94229. if(!FLAC__bitwriter_write_raw_uint32(bw, u, FLAC__FRAME_HEADER_SAMPLE_RATE_LEN))
  94230. return false;
  94231. FLAC__ASSERT(header->channels > 0 && header->channels <= (1u << FLAC__STREAM_METADATA_STREAMINFO_CHANNELS_LEN) && header->channels <= FLAC__MAX_CHANNELS);
  94232. switch(header->channel_assignment) {
  94233. case FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT:
  94234. u = header->channels - 1;
  94235. break;
  94236. case FLAC__CHANNEL_ASSIGNMENT_LEFT_SIDE:
  94237. FLAC__ASSERT(header->channels == 2);
  94238. u = 8;
  94239. break;
  94240. case FLAC__CHANNEL_ASSIGNMENT_RIGHT_SIDE:
  94241. FLAC__ASSERT(header->channels == 2);
  94242. u = 9;
  94243. break;
  94244. case FLAC__CHANNEL_ASSIGNMENT_MID_SIDE:
  94245. FLAC__ASSERT(header->channels == 2);
  94246. u = 10;
  94247. break;
  94248. default:
  94249. FLAC__ASSERT(0);
  94250. }
  94251. if(!FLAC__bitwriter_write_raw_uint32(bw, u, FLAC__FRAME_HEADER_CHANNEL_ASSIGNMENT_LEN))
  94252. return false;
  94253. FLAC__ASSERT(header->bits_per_sample > 0 && header->bits_per_sample <= (1u << FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN));
  94254. switch(header->bits_per_sample) {
  94255. case 8 : u = 1; break;
  94256. case 12: u = 2; break;
  94257. case 16: u = 4; break;
  94258. case 20: u = 5; break;
  94259. case 24: u = 6; break;
  94260. default: u = 0; break;
  94261. }
  94262. if(!FLAC__bitwriter_write_raw_uint32(bw, u, FLAC__FRAME_HEADER_BITS_PER_SAMPLE_LEN))
  94263. return false;
  94264. if(!FLAC__bitwriter_write_raw_uint32(bw, 0, FLAC__FRAME_HEADER_ZERO_PAD_LEN))
  94265. return false;
  94266. if(header->number_type == FLAC__FRAME_NUMBER_TYPE_FRAME_NUMBER) {
  94267. if(!FLAC__bitwriter_write_utf8_uint32(bw, header->number.frame_number))
  94268. return false;
  94269. }
  94270. else {
  94271. if(!FLAC__bitwriter_write_utf8_uint64(bw, header->number.sample_number))
  94272. return false;
  94273. }
  94274. if(blocksize_hint)
  94275. if(!FLAC__bitwriter_write_raw_uint32(bw, header->blocksize-1, (blocksize_hint==6)? 8:16))
  94276. return false;
  94277. switch(sample_rate_hint) {
  94278. case 12:
  94279. if(!FLAC__bitwriter_write_raw_uint32(bw, header->sample_rate / 1000, 8))
  94280. return false;
  94281. break;
  94282. case 13:
  94283. if(!FLAC__bitwriter_write_raw_uint32(bw, header->sample_rate, 16))
  94284. return false;
  94285. break;
  94286. case 14:
  94287. if(!FLAC__bitwriter_write_raw_uint32(bw, header->sample_rate / 10, 16))
  94288. return false;
  94289. break;
  94290. }
  94291. if(!FLAC__bitwriter_get_write_crc8(bw, &crc))
  94292. return false;
  94293. if(!FLAC__bitwriter_write_raw_uint32(bw, crc, FLAC__FRAME_HEADER_CRC_LEN))
  94294. return false;
  94295. return true;
  94296. }
  94297. FLAC__bool FLAC__subframe_add_constant(const FLAC__Subframe_Constant *subframe, unsigned subframe_bps, unsigned wasted_bits, FLAC__BitWriter *bw)
  94298. {
  94299. FLAC__bool ok;
  94300. ok =
  94301. 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) &&
  94302. (wasted_bits? FLAC__bitwriter_write_unary_unsigned(bw, wasted_bits-1) : true) &&
  94303. FLAC__bitwriter_write_raw_int32(bw, subframe->value, subframe_bps)
  94304. ;
  94305. return ok;
  94306. }
  94307. FLAC__bool FLAC__subframe_add_fixed(const FLAC__Subframe_Fixed *subframe, unsigned residual_samples, unsigned subframe_bps, unsigned wasted_bits, FLAC__BitWriter *bw)
  94308. {
  94309. unsigned i;
  94310. 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))
  94311. return false;
  94312. if(wasted_bits)
  94313. if(!FLAC__bitwriter_write_unary_unsigned(bw, wasted_bits-1))
  94314. return false;
  94315. for(i = 0; i < subframe->order; i++)
  94316. if(!FLAC__bitwriter_write_raw_int32(bw, subframe->warmup[i], subframe_bps))
  94317. return false;
  94318. if(!add_entropy_coding_method_(bw, &subframe->entropy_coding_method))
  94319. return false;
  94320. switch(subframe->entropy_coding_method.type) {
  94321. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE:
  94322. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2:
  94323. if(!add_residual_partitioned_rice_(
  94324. bw,
  94325. subframe->residual,
  94326. residual_samples,
  94327. subframe->order,
  94328. subframe->entropy_coding_method.data.partitioned_rice.contents->parameters,
  94329. subframe->entropy_coding_method.data.partitioned_rice.contents->raw_bits,
  94330. subframe->entropy_coding_method.data.partitioned_rice.order,
  94331. subframe->entropy_coding_method.type == FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2
  94332. ))
  94333. return false;
  94334. break;
  94335. default:
  94336. FLAC__ASSERT(0);
  94337. }
  94338. return true;
  94339. }
  94340. FLAC__bool FLAC__subframe_add_lpc(const FLAC__Subframe_LPC *subframe, unsigned residual_samples, unsigned subframe_bps, unsigned wasted_bits, FLAC__BitWriter *bw)
  94341. {
  94342. unsigned i;
  94343. 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))
  94344. return false;
  94345. if(wasted_bits)
  94346. if(!FLAC__bitwriter_write_unary_unsigned(bw, wasted_bits-1))
  94347. return false;
  94348. for(i = 0; i < subframe->order; i++)
  94349. if(!FLAC__bitwriter_write_raw_int32(bw, subframe->warmup[i], subframe_bps))
  94350. return false;
  94351. if(!FLAC__bitwriter_write_raw_uint32(bw, subframe->qlp_coeff_precision-1, FLAC__SUBFRAME_LPC_QLP_COEFF_PRECISION_LEN))
  94352. return false;
  94353. if(!FLAC__bitwriter_write_raw_int32(bw, subframe->quantization_level, FLAC__SUBFRAME_LPC_QLP_SHIFT_LEN))
  94354. return false;
  94355. for(i = 0; i < subframe->order; i++)
  94356. if(!FLAC__bitwriter_write_raw_int32(bw, subframe->qlp_coeff[i], subframe->qlp_coeff_precision))
  94357. return false;
  94358. if(!add_entropy_coding_method_(bw, &subframe->entropy_coding_method))
  94359. return false;
  94360. switch(subframe->entropy_coding_method.type) {
  94361. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE:
  94362. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2:
  94363. if(!add_residual_partitioned_rice_(
  94364. bw,
  94365. subframe->residual,
  94366. residual_samples,
  94367. subframe->order,
  94368. subframe->entropy_coding_method.data.partitioned_rice.contents->parameters,
  94369. subframe->entropy_coding_method.data.partitioned_rice.contents->raw_bits,
  94370. subframe->entropy_coding_method.data.partitioned_rice.order,
  94371. subframe->entropy_coding_method.type == FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2
  94372. ))
  94373. return false;
  94374. break;
  94375. default:
  94376. FLAC__ASSERT(0);
  94377. }
  94378. return true;
  94379. }
  94380. FLAC__bool FLAC__subframe_add_verbatim(const FLAC__Subframe_Verbatim *subframe, unsigned samples, unsigned subframe_bps, unsigned wasted_bits, FLAC__BitWriter *bw)
  94381. {
  94382. unsigned i;
  94383. const FLAC__int32 *signal = subframe->data;
  94384. 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))
  94385. return false;
  94386. if(wasted_bits)
  94387. if(!FLAC__bitwriter_write_unary_unsigned(bw, wasted_bits-1))
  94388. return false;
  94389. for(i = 0; i < samples; i++)
  94390. if(!FLAC__bitwriter_write_raw_int32(bw, signal[i], subframe_bps))
  94391. return false;
  94392. return true;
  94393. }
  94394. FLAC__bool add_entropy_coding_method_(FLAC__BitWriter *bw, const FLAC__EntropyCodingMethod *method)
  94395. {
  94396. if(!FLAC__bitwriter_write_raw_uint32(bw, method->type, FLAC__ENTROPY_CODING_METHOD_TYPE_LEN))
  94397. return false;
  94398. switch(method->type) {
  94399. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE:
  94400. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2:
  94401. if(!FLAC__bitwriter_write_raw_uint32(bw, method->data.partitioned_rice.order, FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ORDER_LEN))
  94402. return false;
  94403. break;
  94404. default:
  94405. FLAC__ASSERT(0);
  94406. }
  94407. return true;
  94408. }
  94409. 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)
  94410. {
  94411. const unsigned plen = is_extended? FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_PARAMETER_LEN : FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_PARAMETER_LEN;
  94412. const unsigned pesc = is_extended? FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_ESCAPE_PARAMETER : FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ESCAPE_PARAMETER;
  94413. if(partition_order == 0) {
  94414. unsigned i;
  94415. if(raw_bits[0] == 0) {
  94416. if(!FLAC__bitwriter_write_raw_uint32(bw, rice_parameters[0], plen))
  94417. return false;
  94418. if(!FLAC__bitwriter_write_rice_signed_block(bw, residual, residual_samples, rice_parameters[0]))
  94419. return false;
  94420. }
  94421. else {
  94422. FLAC__ASSERT(rice_parameters[0] == 0);
  94423. if(!FLAC__bitwriter_write_raw_uint32(bw, pesc, plen))
  94424. return false;
  94425. if(!FLAC__bitwriter_write_raw_uint32(bw, raw_bits[0], FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_RAW_LEN))
  94426. return false;
  94427. for(i = 0; i < residual_samples; i++) {
  94428. if(!FLAC__bitwriter_write_raw_int32(bw, residual[i], raw_bits[0]))
  94429. return false;
  94430. }
  94431. }
  94432. return true;
  94433. }
  94434. else {
  94435. unsigned i, j, k = 0, k_last = 0;
  94436. unsigned partition_samples;
  94437. const unsigned default_partition_samples = (residual_samples+predictor_order) >> partition_order;
  94438. for(i = 0; i < (1u<<partition_order); i++) {
  94439. partition_samples = default_partition_samples;
  94440. if(i == 0)
  94441. partition_samples -= predictor_order;
  94442. k += partition_samples;
  94443. if(raw_bits[i] == 0) {
  94444. if(!FLAC__bitwriter_write_raw_uint32(bw, rice_parameters[i], plen))
  94445. return false;
  94446. if(!FLAC__bitwriter_write_rice_signed_block(bw, residual+k_last, k-k_last, rice_parameters[i]))
  94447. return false;
  94448. }
  94449. else {
  94450. if(!FLAC__bitwriter_write_raw_uint32(bw, pesc, plen))
  94451. return false;
  94452. if(!FLAC__bitwriter_write_raw_uint32(bw, raw_bits[i], FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_RAW_LEN))
  94453. return false;
  94454. for(j = k_last; j < k; j++) {
  94455. if(!FLAC__bitwriter_write_raw_int32(bw, residual[j], raw_bits[i]))
  94456. return false;
  94457. }
  94458. }
  94459. k_last = k;
  94460. }
  94461. return true;
  94462. }
  94463. }
  94464. #endif
  94465. /********* End of inlined file: stream_encoder_framing.c *********/
  94466. /********* Start of inlined file: window_flac.c *********/
  94467. /********* Start of inlined file: juce_FlacHeader.h *********/
  94468. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  94469. // tasks..
  94470. #define VERSION "1.2.1"
  94471. #define FLAC__NO_DLL 1
  94472. #if JUCE_MSVC
  94473. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  94474. #endif
  94475. #if JUCE_MAC
  94476. #define FLAC__SYS_DARWIN 1
  94477. #endif
  94478. /********* End of inlined file: juce_FlacHeader.h *********/
  94479. #if JUCE_USE_FLAC
  94480. #if HAVE_CONFIG_H
  94481. # include <config.h>
  94482. #endif
  94483. #include <math.h>
  94484. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  94485. #ifndef M_PI
  94486. #define M_PI 3.14159265358979323846
  94487. #endif
  94488. void FLAC__window_bartlett(FLAC__real *window, const FLAC__int32 L)
  94489. {
  94490. const FLAC__int32 N = L - 1;
  94491. FLAC__int32 n;
  94492. if (L & 1) {
  94493. for (n = 0; n <= N/2; n++)
  94494. window[n] = 2.0f * n / (float)N;
  94495. for (; n <= N; n++)
  94496. window[n] = 2.0f - 2.0f * n / (float)N;
  94497. }
  94498. else {
  94499. for (n = 0; n <= L/2-1; n++)
  94500. window[n] = 2.0f * n / (float)N;
  94501. for (; n <= N; n++)
  94502. window[n] = 2.0f - 2.0f * (N-n) / (float)N;
  94503. }
  94504. }
  94505. void FLAC__window_bartlett_hann(FLAC__real *window, const FLAC__int32 L)
  94506. {
  94507. const FLAC__int32 N = L - 1;
  94508. FLAC__int32 n;
  94509. for (n = 0; n < L; n++)
  94510. 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)));
  94511. }
  94512. void FLAC__window_blackman(FLAC__real *window, const FLAC__int32 L)
  94513. {
  94514. const FLAC__int32 N = L - 1;
  94515. FLAC__int32 n;
  94516. for (n = 0; n < L; n++)
  94517. window[n] = (FLAC__real)(0.42f - 0.5f * cos(2.0f * M_PI * n / N) + 0.08f * cos(4.0f * M_PI * n / N));
  94518. }
  94519. void FLAC__window_blackman_harris_4term_92db_sidelobe(FLAC__real *window, const FLAC__int32 L)
  94520. {
  94521. const FLAC__int32 N = L - 1;
  94522. FLAC__int32 n;
  94523. for (n = 0; n <= N; n++)
  94524. 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));
  94525. }
  94526. void FLAC__window_connes(FLAC__real *window, const FLAC__int32 L)
  94527. {
  94528. const FLAC__int32 N = L - 1;
  94529. const double N2 = (double)N / 2.;
  94530. FLAC__int32 n;
  94531. for (n = 0; n <= N; n++) {
  94532. double k = ((double)n - N2) / N2;
  94533. k = 1.0f - k * k;
  94534. window[n] = (FLAC__real)(k * k);
  94535. }
  94536. }
  94537. void FLAC__window_flattop(FLAC__real *window, const FLAC__int32 L)
  94538. {
  94539. const FLAC__int32 N = L - 1;
  94540. FLAC__int32 n;
  94541. for (n = 0; n < L; n++)
  94542. 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));
  94543. }
  94544. void FLAC__window_gauss(FLAC__real *window, const FLAC__int32 L, const FLAC__real stddev)
  94545. {
  94546. const FLAC__int32 N = L - 1;
  94547. const double N2 = (double)N / 2.;
  94548. FLAC__int32 n;
  94549. for (n = 0; n <= N; n++) {
  94550. const double k = ((double)n - N2) / (stddev * N2);
  94551. window[n] = (FLAC__real)exp(-0.5f * k * k);
  94552. }
  94553. }
  94554. void FLAC__window_hamming(FLAC__real *window, const FLAC__int32 L)
  94555. {
  94556. const FLAC__int32 N = L - 1;
  94557. FLAC__int32 n;
  94558. for (n = 0; n < L; n++)
  94559. window[n] = (FLAC__real)(0.54f - 0.46f * cos(2.0f * M_PI * n / N));
  94560. }
  94561. void FLAC__window_hann(FLAC__real *window, const FLAC__int32 L)
  94562. {
  94563. const FLAC__int32 N = L - 1;
  94564. FLAC__int32 n;
  94565. for (n = 0; n < L; n++)
  94566. window[n] = (FLAC__real)(0.5f - 0.5f * cos(2.0f * M_PI * n / N));
  94567. }
  94568. void FLAC__window_kaiser_bessel(FLAC__real *window, const FLAC__int32 L)
  94569. {
  94570. const FLAC__int32 N = L - 1;
  94571. FLAC__int32 n;
  94572. for (n = 0; n < L; n++)
  94573. 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));
  94574. }
  94575. void FLAC__window_nuttall(FLAC__real *window, const FLAC__int32 L)
  94576. {
  94577. const FLAC__int32 N = L - 1;
  94578. FLAC__int32 n;
  94579. for (n = 0; n < L; n++)
  94580. 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));
  94581. }
  94582. void FLAC__window_rectangle(FLAC__real *window, const FLAC__int32 L)
  94583. {
  94584. FLAC__int32 n;
  94585. for (n = 0; n < L; n++)
  94586. window[n] = 1.0f;
  94587. }
  94588. void FLAC__window_triangle(FLAC__real *window, const FLAC__int32 L)
  94589. {
  94590. FLAC__int32 n;
  94591. if (L & 1) {
  94592. for (n = 1; n <= L+1/2; n++)
  94593. window[n-1] = 2.0f * n / ((float)L + 1.0f);
  94594. for (; n <= L; n++)
  94595. window[n-1] = - (float)(2 * (L - n + 1)) / ((float)L + 1.0f);
  94596. }
  94597. else {
  94598. for (n = 1; n <= L/2; n++)
  94599. window[n-1] = 2.0f * n / (float)L;
  94600. for (; n <= L; n++)
  94601. window[n-1] = ((float)(2 * (L - n)) + 1.0f) / (float)L;
  94602. }
  94603. }
  94604. void FLAC__window_tukey(FLAC__real *window, const FLAC__int32 L, const FLAC__real p)
  94605. {
  94606. if (p <= 0.0)
  94607. FLAC__window_rectangle(window, L);
  94608. else if (p >= 1.0)
  94609. FLAC__window_hann(window, L);
  94610. else {
  94611. const FLAC__int32 Np = (FLAC__int32)(p / 2.0f * L) - 1;
  94612. FLAC__int32 n;
  94613. FLAC__window_rectangle(window, L);
  94614. if (Np > 0) {
  94615. for (n = 0; n <= Np; n++) {
  94616. window[n] = (FLAC__real)(0.5f - 0.5f * cos(M_PI * n / Np));
  94617. window[L-Np-1+n] = (FLAC__real)(0.5f - 0.5f * cos(M_PI * (n+Np) / Np));
  94618. }
  94619. }
  94620. }
  94621. }
  94622. void FLAC__window_welch(FLAC__real *window, const FLAC__int32 L)
  94623. {
  94624. const FLAC__int32 N = L - 1;
  94625. const double N2 = (double)N / 2.;
  94626. FLAC__int32 n;
  94627. for (n = 0; n <= N; n++) {
  94628. const double k = ((double)n - N2) / N2;
  94629. window[n] = (FLAC__real)(1.0f - k * k);
  94630. }
  94631. }
  94632. #endif /* !defined FLAC__INTEGER_ONLY_LIBRARY */
  94633. #endif
  94634. /********* End of inlined file: window_flac.c *********/
  94635. #else
  94636. #include <FLAC/all.h>
  94637. #endif
  94638. }
  94639. #ifdef _MSC_VER
  94640. #pragma warning (pop)
  94641. #endif
  94642. BEGIN_JUCE_NAMESPACE
  94643. using namespace FlacNamespace;
  94644. static const char* const flacFormatName = "FLAC file";
  94645. static const tchar* const flacExtensions[] = { T(".flac"), 0 };
  94646. class FlacReader : public AudioFormatReader
  94647. {
  94648. FLAC__StreamDecoder* decoder;
  94649. AudioSampleBuffer reservoir;
  94650. int reservoirStart, samplesInReservoir;
  94651. bool ok, scanningForLength;
  94652. public:
  94653. FlacReader (InputStream* const in)
  94654. : AudioFormatReader (in, TRANS (flacFormatName)),
  94655. reservoir (2, 0),
  94656. reservoirStart (0),
  94657. samplesInReservoir (0),
  94658. scanningForLength (false)
  94659. {
  94660. using namespace FlacNamespace;
  94661. lengthInSamples = 0;
  94662. decoder = FLAC__stream_decoder_new();
  94663. ok = FLAC__stream_decoder_init_stream (decoder,
  94664. readCallback_, seekCallback_, tellCallback_, lengthCallback_,
  94665. eofCallback_, writeCallback_, metadataCallback_, errorCallback_,
  94666. (void*) this) == FLAC__STREAM_DECODER_INIT_STATUS_OK;
  94667. if (ok)
  94668. {
  94669. FLAC__stream_decoder_process_until_end_of_metadata (decoder);
  94670. if (lengthInSamples == 0 && sampleRate > 0)
  94671. {
  94672. // the length hasn't been stored in the metadata, so we'll need to
  94673. // work it out the length the hard way, by scanning the whole file..
  94674. scanningForLength = true;
  94675. FLAC__stream_decoder_process_until_end_of_stream (decoder);
  94676. scanningForLength = false;
  94677. const int64 tempLength = lengthInSamples;
  94678. FLAC__stream_decoder_reset (decoder);
  94679. FLAC__stream_decoder_process_until_end_of_metadata (decoder);
  94680. lengthInSamples = tempLength;
  94681. }
  94682. }
  94683. }
  94684. ~FlacReader()
  94685. {
  94686. FLAC__stream_decoder_delete (decoder);
  94687. }
  94688. void useMetadata (const FLAC__StreamMetadata_StreamInfo& info)
  94689. {
  94690. sampleRate = info.sample_rate;
  94691. bitsPerSample = info.bits_per_sample;
  94692. lengthInSamples = (unsigned int) info.total_samples;
  94693. numChannels = info.channels;
  94694. reservoir.setSize (numChannels, 2 * info.max_blocksize, false, false, true);
  94695. }
  94696. // returns the number of samples read
  94697. bool readSamples (int** destSamples, int numDestChannels, int startOffsetInDestBuffer,
  94698. int64 startSampleInFile, int numSamples)
  94699. {
  94700. using namespace FlacNamespace;
  94701. if (! ok)
  94702. return false;
  94703. while (numSamples > 0)
  94704. {
  94705. if (startSampleInFile >= reservoirStart
  94706. && startSampleInFile < reservoirStart + samplesInReservoir)
  94707. {
  94708. const int num = (int) jmin ((int64) numSamples,
  94709. reservoirStart + samplesInReservoir - startSampleInFile);
  94710. jassert (num > 0);
  94711. for (int i = jmin (numDestChannels, reservoir.getNumChannels()); --i >= 0;)
  94712. if (destSamples[i] != 0)
  94713. memcpy (destSamples[i] + startOffsetInDestBuffer,
  94714. reservoir.getSampleData (i, (int) (startSampleInFile - reservoirStart)),
  94715. sizeof (int) * num);
  94716. startOffsetInDestBuffer += num;
  94717. startSampleInFile += num;
  94718. numSamples -= num;
  94719. }
  94720. else
  94721. {
  94722. if (startSampleInFile >= (int) lengthInSamples)
  94723. {
  94724. samplesInReservoir = 0;
  94725. }
  94726. else if (startSampleInFile < reservoirStart
  94727. || startSampleInFile > reservoirStart + jmax (samplesInReservoir, 511))
  94728. {
  94729. // had some problems with flac crashing if the read pos is aligned more
  94730. // accurately than this. Probably fixed in newer versions of the library, though.
  94731. reservoirStart = (int) (startSampleInFile & ~511);
  94732. samplesInReservoir = 0;
  94733. FLAC__stream_decoder_seek_absolute (decoder, (FLAC__uint64) reservoirStart);
  94734. }
  94735. else
  94736. {
  94737. reservoirStart += samplesInReservoir;
  94738. samplesInReservoir = 0;
  94739. FLAC__stream_decoder_process_single (decoder);
  94740. }
  94741. if (samplesInReservoir == 0)
  94742. break;
  94743. }
  94744. }
  94745. if (numSamples > 0)
  94746. {
  94747. for (int i = numDestChannels; --i >= 0;)
  94748. if (destSamples[i] != 0)
  94749. zeromem (destSamples[i] + startOffsetInDestBuffer,
  94750. sizeof (int) * numSamples);
  94751. }
  94752. return true;
  94753. }
  94754. void useSamples (const FLAC__int32* const buffer[], int numSamples)
  94755. {
  94756. if (scanningForLength)
  94757. {
  94758. lengthInSamples += numSamples;
  94759. }
  94760. else
  94761. {
  94762. if (numSamples > reservoir.getNumSamples())
  94763. reservoir.setSize (numChannels, numSamples, false, false, true);
  94764. const int bitsToShift = 32 - bitsPerSample;
  94765. for (int i = 0; i < (int) numChannels; ++i)
  94766. {
  94767. const FLAC__int32* src = buffer[i];
  94768. int n = i;
  94769. while (src == 0 && n > 0)
  94770. src = buffer [--n];
  94771. if (src != 0)
  94772. {
  94773. int* dest = (int*) reservoir.getSampleData(i);
  94774. for (int j = 0; j < numSamples; ++j)
  94775. dest[j] = src[j] << bitsToShift;
  94776. }
  94777. }
  94778. samplesInReservoir = numSamples;
  94779. }
  94780. }
  94781. static FLAC__StreamDecoderReadStatus readCallback_ (const FLAC__StreamDecoder*, FLAC__byte buffer[], size_t* bytes, void* client_data)
  94782. {
  94783. *bytes = (unsigned int) ((const FlacReader*) client_data)->input->read (buffer, (int) *bytes);
  94784. return FLAC__STREAM_DECODER_READ_STATUS_CONTINUE;
  94785. }
  94786. static FLAC__StreamDecoderSeekStatus seekCallback_ (const FLAC__StreamDecoder*, FLAC__uint64 absolute_byte_offset, void* client_data)
  94787. {
  94788. ((const FlacReader*) client_data)->input->setPosition ((int) absolute_byte_offset);
  94789. return FLAC__STREAM_DECODER_SEEK_STATUS_OK;
  94790. }
  94791. static FLAC__StreamDecoderTellStatus tellCallback_ (const FLAC__StreamDecoder*, FLAC__uint64* absolute_byte_offset, void* client_data)
  94792. {
  94793. *absolute_byte_offset = ((const FlacReader*) client_data)->input->getPosition();
  94794. return FLAC__STREAM_DECODER_TELL_STATUS_OK;
  94795. }
  94796. static FLAC__StreamDecoderLengthStatus lengthCallback_ (const FLAC__StreamDecoder*, FLAC__uint64* stream_length, void* client_data)
  94797. {
  94798. *stream_length = ((const FlacReader*) client_data)->input->getTotalLength();
  94799. return FLAC__STREAM_DECODER_LENGTH_STATUS_OK;
  94800. }
  94801. static FLAC__bool eofCallback_ (const FLAC__StreamDecoder*, void* client_data)
  94802. {
  94803. return ((const FlacReader*) client_data)->input->isExhausted();
  94804. }
  94805. static FLAC__StreamDecoderWriteStatus writeCallback_ (const FLAC__StreamDecoder*,
  94806. const FLAC__Frame* frame,
  94807. const FLAC__int32* const buffer[],
  94808. void* client_data)
  94809. {
  94810. ((FlacReader*) client_data)->useSamples (buffer, frame->header.blocksize);
  94811. return FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE;
  94812. }
  94813. static void metadataCallback_ (const FLAC__StreamDecoder*,
  94814. const FLAC__StreamMetadata* metadata,
  94815. void* client_data)
  94816. {
  94817. ((FlacReader*) client_data)->useMetadata (metadata->data.stream_info);
  94818. }
  94819. static void errorCallback_ (const FLAC__StreamDecoder*, FLAC__StreamDecoderErrorStatus, void*)
  94820. {
  94821. }
  94822. juce_UseDebuggingNewOperator
  94823. };
  94824. class FlacWriter : public AudioFormatWriter
  94825. {
  94826. FLAC__StreamEncoder* encoder;
  94827. MemoryBlock temp;
  94828. public:
  94829. bool ok;
  94830. FlacWriter (OutputStream* const out,
  94831. const double sampleRate_,
  94832. const int numChannels_,
  94833. const int bitsPerSample_)
  94834. : AudioFormatWriter (out, TRANS (flacFormatName),
  94835. sampleRate_,
  94836. numChannels_,
  94837. bitsPerSample_)
  94838. {
  94839. using namespace FlacNamespace;
  94840. encoder = FLAC__stream_encoder_new();
  94841. FLAC__stream_encoder_set_do_mid_side_stereo (encoder, numChannels == 2);
  94842. FLAC__stream_encoder_set_loose_mid_side_stereo (encoder, numChannels == 2);
  94843. FLAC__stream_encoder_set_channels (encoder, numChannels);
  94844. FLAC__stream_encoder_set_bits_per_sample (encoder, jmin ((unsigned int) 24, bitsPerSample));
  94845. FLAC__stream_encoder_set_sample_rate (encoder, (unsigned int) sampleRate);
  94846. FLAC__stream_encoder_set_blocksize (encoder, 2048);
  94847. FLAC__stream_encoder_set_do_escape_coding (encoder, true);
  94848. ok = FLAC__stream_encoder_init_stream (encoder,
  94849. encodeWriteCallback, encodeSeekCallback,
  94850. encodeTellCallback, encodeMetadataCallback,
  94851. (void*) this) == FLAC__STREAM_ENCODER_INIT_STATUS_OK;
  94852. }
  94853. ~FlacWriter()
  94854. {
  94855. if (ok)
  94856. {
  94857. FLAC__stream_encoder_finish (encoder);
  94858. output->flush();
  94859. }
  94860. else
  94861. {
  94862. output = 0; // to stop the base class deleting this, as it needs to be returned
  94863. // to the caller of createWriter()
  94864. }
  94865. FLAC__stream_encoder_delete (encoder);
  94866. }
  94867. bool write (const int** samplesToWrite, int numSamples)
  94868. {
  94869. if (! ok)
  94870. return false;
  94871. int* buf[3];
  94872. const int bitsToShift = 32 - bitsPerSample;
  94873. if (bitsToShift > 0)
  94874. {
  94875. const int numChannelsToWrite = (samplesToWrite[1] == 0) ? 1 : 2;
  94876. temp.setSize (sizeof (int) * numSamples * numChannelsToWrite);
  94877. buf[0] = (int*) temp.getData();
  94878. buf[1] = buf[0] + numSamples;
  94879. buf[2] = 0;
  94880. for (int i = numChannelsToWrite; --i >= 0;)
  94881. {
  94882. if (samplesToWrite[i] != 0)
  94883. {
  94884. for (int j = 0; j < numSamples; ++j)
  94885. buf [i][j] = (samplesToWrite [i][j] >> bitsToShift);
  94886. }
  94887. }
  94888. samplesToWrite = (const int**) buf;
  94889. }
  94890. return FLAC__stream_encoder_process (encoder,
  94891. (const FLAC__int32**) samplesToWrite,
  94892. numSamples) != 0;
  94893. }
  94894. bool writeData (const void* const data, const int size) const
  94895. {
  94896. return output->write (data, size);
  94897. }
  94898. static void packUint32 (FLAC__uint32 val, FLAC__byte* b, const int bytes)
  94899. {
  94900. b += bytes;
  94901. for (int i = 0; i < bytes; ++i)
  94902. {
  94903. *(--b) = (FLAC__byte) (val & 0xff);
  94904. val >>= 8;
  94905. }
  94906. }
  94907. void writeMetaData (const FLAC__StreamMetadata* metadata)
  94908. {
  94909. using namespace FlacNamespace;
  94910. const FLAC__StreamMetadata_StreamInfo& info = metadata->data.stream_info;
  94911. unsigned char buffer [FLAC__STREAM_METADATA_STREAMINFO_LENGTH];
  94912. const unsigned int channelsMinus1 = info.channels - 1;
  94913. const unsigned int bitsMinus1 = info.bits_per_sample - 1;
  94914. packUint32 (info.min_blocksize, buffer, 2);
  94915. packUint32 (info.max_blocksize, buffer + 2, 2);
  94916. packUint32 (info.min_framesize, buffer + 4, 3);
  94917. packUint32 (info.max_framesize, buffer + 7, 3);
  94918. buffer[10] = (uint8) ((info.sample_rate >> 12) & 0xff);
  94919. buffer[11] = (uint8) ((info.sample_rate >> 4) & 0xff);
  94920. buffer[12] = (uint8) (((info.sample_rate & 0x0f) << 4) | (channelsMinus1 << 1) | (bitsMinus1 >> 4));
  94921. buffer[13] = (FLAC__byte) (((bitsMinus1 & 0x0f) << 4) | (unsigned int) ((info.total_samples >> 32) & 0x0f));
  94922. packUint32 ((FLAC__uint32) info.total_samples, buffer + 14, 4);
  94923. memcpy (buffer + 18, info.md5sum, 16);
  94924. const bool seekOk = output->setPosition (4);
  94925. (void) seekOk;
  94926. // if this fails, you've given it an output stream that can't seek! It needs
  94927. // to be able to seek back to write the header
  94928. jassert (seekOk);
  94929. output->writeIntBigEndian (FLAC__STREAM_METADATA_STREAMINFO_LENGTH);
  94930. output->write (buffer, FLAC__STREAM_METADATA_STREAMINFO_LENGTH);
  94931. }
  94932. static FLAC__StreamEncoderWriteStatus encodeWriteCallback (const FLAC__StreamEncoder*,
  94933. const FLAC__byte buffer[],
  94934. size_t bytes,
  94935. unsigned int /*samples*/,
  94936. unsigned int /*current_frame*/,
  94937. void* client_data)
  94938. {
  94939. using namespace FlacNamespace;
  94940. return ((FlacWriter*) client_data)->writeData (buffer, (int) bytes)
  94941. ? FLAC__STREAM_ENCODER_WRITE_STATUS_OK
  94942. : FLAC__STREAM_ENCODER_WRITE_STATUS_FATAL_ERROR;
  94943. }
  94944. static FLAC__StreamEncoderSeekStatus encodeSeekCallback (const FLAC__StreamEncoder*, FLAC__uint64, void*)
  94945. {
  94946. return FLAC__STREAM_ENCODER_SEEK_STATUS_UNSUPPORTED;
  94947. }
  94948. static FLAC__StreamEncoderTellStatus encodeTellCallback (const FLAC__StreamEncoder*, FLAC__uint64* absolute_byte_offset, void* client_data)
  94949. {
  94950. if (client_data == 0)
  94951. return FLAC__STREAM_ENCODER_TELL_STATUS_UNSUPPORTED;
  94952. *absolute_byte_offset = (FLAC__uint64) ((FlacWriter*) client_data)->output->getPosition();
  94953. return FLAC__STREAM_ENCODER_TELL_STATUS_OK;
  94954. }
  94955. static void encodeMetadataCallback (const FLAC__StreamEncoder*,
  94956. const FLAC__StreamMetadata* metadata,
  94957. void* client_data)
  94958. {
  94959. ((FlacWriter*) client_data)->writeMetaData (metadata);
  94960. }
  94961. juce_UseDebuggingNewOperator
  94962. };
  94963. FlacAudioFormat::FlacAudioFormat()
  94964. : AudioFormat (TRANS (flacFormatName), (const tchar**) flacExtensions)
  94965. {
  94966. }
  94967. FlacAudioFormat::~FlacAudioFormat()
  94968. {
  94969. }
  94970. const Array <int> FlacAudioFormat::getPossibleSampleRates()
  94971. {
  94972. const int rates[] = { 22050, 32000, 44100, 48000, 88200, 96000, 0 };
  94973. return Array <int> (rates);
  94974. }
  94975. const Array <int> FlacAudioFormat::getPossibleBitDepths()
  94976. {
  94977. const int depths[] = { 16, 24, 0 };
  94978. return Array <int> (depths);
  94979. }
  94980. bool FlacAudioFormat::canDoStereo()
  94981. {
  94982. return true;
  94983. }
  94984. bool FlacAudioFormat::canDoMono()
  94985. {
  94986. return true;
  94987. }
  94988. bool FlacAudioFormat::isCompressed()
  94989. {
  94990. return true;
  94991. }
  94992. AudioFormatReader* FlacAudioFormat::createReaderFor (InputStream* in,
  94993. const bool deleteStreamIfOpeningFails)
  94994. {
  94995. ScopedPointer <FlacReader> r (new FlacReader (in));
  94996. if (r->sampleRate != 0)
  94997. return r.release();
  94998. if (! deleteStreamIfOpeningFails)
  94999. r->input = 0;
  95000. return 0;
  95001. }
  95002. AudioFormatWriter* FlacAudioFormat::createWriterFor (OutputStream* out,
  95003. double sampleRate,
  95004. unsigned int numberOfChannels,
  95005. int bitsPerSample,
  95006. const StringPairArray& /*metadataValues*/,
  95007. int /*qualityOptionIndex*/)
  95008. {
  95009. if (getPossibleBitDepths().contains (bitsPerSample))
  95010. {
  95011. ScopedPointer <FlacWriter> w (new FlacWriter (out,
  95012. sampleRate,
  95013. numberOfChannels,
  95014. bitsPerSample));
  95015. if (w->ok)
  95016. return w.release();
  95017. }
  95018. return 0;
  95019. }
  95020. END_JUCE_NAMESPACE
  95021. #endif
  95022. /********* End of inlined file: juce_FlacAudioFormat.cpp *********/
  95023. /********* Start of inlined file: juce_OggVorbisAudioFormat.cpp *********/
  95024. #if JUCE_USE_OGGVORBIS
  95025. #if JUCE_MAC
  95026. #define __MACOSX__ 1
  95027. #endif
  95028. namespace OggVorbisNamespace
  95029. {
  95030. #if JUCE_INCLUDE_OGGVORBIS_CODE
  95031. /********* Start of inlined file: vorbisenc.h *********/
  95032. #ifndef _OV_ENC_H_
  95033. #define _OV_ENC_H_
  95034. #ifdef __cplusplus
  95035. extern "C"
  95036. {
  95037. #endif /* __cplusplus */
  95038. /********* Start of inlined file: codec.h *********/
  95039. #ifndef _vorbis_codec_h_
  95040. #define _vorbis_codec_h_
  95041. #ifdef __cplusplus
  95042. extern "C"
  95043. {
  95044. #endif /* __cplusplus */
  95045. /********* Start of inlined file: ogg.h *********/
  95046. #ifndef _OGG_H
  95047. #define _OGG_H
  95048. #ifdef __cplusplus
  95049. extern "C" {
  95050. #endif
  95051. /********* Start of inlined file: os_types.h *********/
  95052. #ifndef _OS_TYPES_H
  95053. #define _OS_TYPES_H
  95054. #define _ogg_malloc malloc
  95055. #define _ogg_calloc calloc
  95056. #define _ogg_realloc realloc
  95057. #define _ogg_free free
  95058. #if defined(_WIN32)
  95059. # if defined(__CYGWIN__)
  95060. # include <_G_config.h>
  95061. typedef _G_int64_t ogg_int64_t;
  95062. typedef _G_int32_t ogg_int32_t;
  95063. typedef _G_uint32_t ogg_uint32_t;
  95064. typedef _G_int16_t ogg_int16_t;
  95065. typedef _G_uint16_t ogg_uint16_t;
  95066. # elif defined(__MINGW32__)
  95067. typedef short ogg_int16_t;
  95068. typedef unsigned short ogg_uint16_t;
  95069. typedef int ogg_int32_t;
  95070. typedef unsigned int ogg_uint32_t;
  95071. typedef long long ogg_int64_t;
  95072. typedef unsigned long long ogg_uint64_t;
  95073. # elif defined(__MWERKS__)
  95074. typedef long long ogg_int64_t;
  95075. typedef int ogg_int32_t;
  95076. typedef unsigned int ogg_uint32_t;
  95077. typedef short ogg_int16_t;
  95078. typedef unsigned short ogg_uint16_t;
  95079. # else
  95080. typedef __int64 ogg_int64_t;
  95081. typedef __int32 ogg_int32_t;
  95082. typedef unsigned __int32 ogg_uint32_t;
  95083. typedef __int16 ogg_int16_t;
  95084. typedef unsigned __int16 ogg_uint16_t;
  95085. # endif
  95086. #elif defined(__MACOS__)
  95087. # include <sys/types.h>
  95088. typedef SInt16 ogg_int16_t;
  95089. typedef UInt16 ogg_uint16_t;
  95090. typedef SInt32 ogg_int32_t;
  95091. typedef UInt32 ogg_uint32_t;
  95092. typedef SInt64 ogg_int64_t;
  95093. #elif defined(__MACOSX__) /* MacOS X Framework build */
  95094. # include <sys/types.h>
  95095. typedef int16_t ogg_int16_t;
  95096. typedef u_int16_t ogg_uint16_t;
  95097. typedef int32_t ogg_int32_t;
  95098. typedef u_int32_t ogg_uint32_t;
  95099. typedef int64_t ogg_int64_t;
  95100. #elif defined(__BEOS__)
  95101. # include <inttypes.h>
  95102. typedef int16_t ogg_int16_t;
  95103. typedef u_int16_t ogg_uint16_t;
  95104. typedef int32_t ogg_int32_t;
  95105. typedef u_int32_t ogg_uint32_t;
  95106. typedef int64_t ogg_int64_t;
  95107. #elif defined (__EMX__)
  95108. typedef short ogg_int16_t;
  95109. typedef unsigned short ogg_uint16_t;
  95110. typedef int ogg_int32_t;
  95111. typedef unsigned int ogg_uint32_t;
  95112. typedef long long ogg_int64_t;
  95113. #elif defined (DJGPP)
  95114. typedef short ogg_int16_t;
  95115. typedef int ogg_int32_t;
  95116. typedef unsigned int ogg_uint32_t;
  95117. typedef long long ogg_int64_t;
  95118. #elif defined(R5900)
  95119. typedef long ogg_int64_t;
  95120. typedef int ogg_int32_t;
  95121. typedef unsigned ogg_uint32_t;
  95122. typedef short ogg_int16_t;
  95123. #elif defined(__SYMBIAN32__)
  95124. typedef signed short ogg_int16_t;
  95125. typedef unsigned short ogg_uint16_t;
  95126. typedef signed int ogg_int32_t;
  95127. typedef unsigned int ogg_uint32_t;
  95128. typedef long long int ogg_int64_t;
  95129. #else
  95130. # include <sys/types.h>
  95131. /********* Start of inlined file: config_types.h *********/
  95132. #ifndef __CONFIG_TYPES_H__
  95133. #define __CONFIG_TYPES_H__
  95134. typedef int16_t ogg_int16_t;
  95135. typedef unsigned short ogg_uint16_t;
  95136. typedef int32_t ogg_int32_t;
  95137. typedef unsigned int ogg_uint32_t;
  95138. typedef int64_t ogg_int64_t;
  95139. #endif
  95140. /********* End of inlined file: config_types.h *********/
  95141. #endif
  95142. #endif /* _OS_TYPES_H */
  95143. /********* End of inlined file: os_types.h *********/
  95144. typedef struct {
  95145. long endbyte;
  95146. int endbit;
  95147. unsigned char *buffer;
  95148. unsigned char *ptr;
  95149. long storage;
  95150. } oggpack_buffer;
  95151. typedef struct {
  95152. unsigned char *header;
  95153. long header_len;
  95154. unsigned char *body;
  95155. long body_len;
  95156. } ogg_page;
  95157. ogg_uint32_t ogg_bitreverse(ogg_uint32_t x){
  95158. x= ((x>>16)&0x0000ffffUL) | ((x<<16)&0xffff0000UL);
  95159. x= ((x>> 8)&0x00ff00ffUL) | ((x<< 8)&0xff00ff00UL);
  95160. x= ((x>> 4)&0x0f0f0f0fUL) | ((x<< 4)&0xf0f0f0f0UL);
  95161. x= ((x>> 2)&0x33333333UL) | ((x<< 2)&0xccccccccUL);
  95162. return((x>> 1)&0x55555555UL) | ((x<< 1)&0xaaaaaaaaUL);
  95163. }
  95164. typedef struct {
  95165. unsigned char *body_data; /* bytes from packet bodies */
  95166. long body_storage; /* storage elements allocated */
  95167. long body_fill; /* elements stored; fill mark */
  95168. long body_returned; /* elements of fill returned */
  95169. int *lacing_vals; /* The values that will go to the segment table */
  95170. ogg_int64_t *granule_vals; /* granulepos values for headers. Not compact
  95171. this way, but it is simple coupled to the
  95172. lacing fifo */
  95173. long lacing_storage;
  95174. long lacing_fill;
  95175. long lacing_packet;
  95176. long lacing_returned;
  95177. unsigned char header[282]; /* working space for header encode */
  95178. int header_fill;
  95179. int e_o_s; /* set when we have buffered the last packet in the
  95180. logical bitstream */
  95181. int b_o_s; /* set after we've written the initial page
  95182. of a logical bitstream */
  95183. long serialno;
  95184. long pageno;
  95185. ogg_int64_t packetno; /* sequence number for decode; the framing
  95186. knows where there's a hole in the data,
  95187. but we need coupling so that the codec
  95188. (which is in a seperate abstraction
  95189. layer) also knows about the gap */
  95190. ogg_int64_t granulepos;
  95191. } ogg_stream_state;
  95192. typedef struct {
  95193. unsigned char *packet;
  95194. long bytes;
  95195. long b_o_s;
  95196. long e_o_s;
  95197. ogg_int64_t granulepos;
  95198. ogg_int64_t packetno; /* sequence number for decode; the framing
  95199. knows where there's a hole in the data,
  95200. but we need coupling so that the codec
  95201. (which is in a seperate abstraction
  95202. layer) also knows about the gap */
  95203. } ogg_packet;
  95204. typedef struct {
  95205. unsigned char *data;
  95206. int storage;
  95207. int fill;
  95208. int returned;
  95209. int unsynced;
  95210. int headerbytes;
  95211. int bodybytes;
  95212. } ogg_sync_state;
  95213. extern void oggpack_writeinit(oggpack_buffer *b);
  95214. extern void oggpack_writetrunc(oggpack_buffer *b,long bits);
  95215. extern void oggpack_writealign(oggpack_buffer *b);
  95216. extern void oggpack_writecopy(oggpack_buffer *b,void *source,long bits);
  95217. extern void oggpack_reset(oggpack_buffer *b);
  95218. extern void oggpack_writeclear(oggpack_buffer *b);
  95219. extern void oggpack_readinit(oggpack_buffer *b,unsigned char *buf,int bytes);
  95220. extern void oggpack_write(oggpack_buffer *b,unsigned long value,int bits);
  95221. extern long oggpack_look(oggpack_buffer *b,int bits);
  95222. extern long oggpack_look1(oggpack_buffer *b);
  95223. extern void oggpack_adv(oggpack_buffer *b,int bits);
  95224. extern void oggpack_adv1(oggpack_buffer *b);
  95225. extern long oggpack_read(oggpack_buffer *b,int bits);
  95226. extern long oggpack_read1(oggpack_buffer *b);
  95227. extern long oggpack_bytes(oggpack_buffer *b);
  95228. extern long oggpack_bits(oggpack_buffer *b);
  95229. extern unsigned char *oggpack_get_buffer(oggpack_buffer *b);
  95230. extern void oggpackB_writeinit(oggpack_buffer *b);
  95231. extern void oggpackB_writetrunc(oggpack_buffer *b,long bits);
  95232. extern void oggpackB_writealign(oggpack_buffer *b);
  95233. extern void oggpackB_writecopy(oggpack_buffer *b,void *source,long bits);
  95234. extern void oggpackB_reset(oggpack_buffer *b);
  95235. extern void oggpackB_writeclear(oggpack_buffer *b);
  95236. extern void oggpackB_readinit(oggpack_buffer *b,unsigned char *buf,int bytes);
  95237. extern void oggpackB_write(oggpack_buffer *b,unsigned long value,int bits);
  95238. extern long oggpackB_look(oggpack_buffer *b,int bits);
  95239. extern long oggpackB_look1(oggpack_buffer *b);
  95240. extern void oggpackB_adv(oggpack_buffer *b,int bits);
  95241. extern void oggpackB_adv1(oggpack_buffer *b);
  95242. extern long oggpackB_read(oggpack_buffer *b,int bits);
  95243. extern long oggpackB_read1(oggpack_buffer *b);
  95244. extern long oggpackB_bytes(oggpack_buffer *b);
  95245. extern long oggpackB_bits(oggpack_buffer *b);
  95246. extern unsigned char *oggpackB_get_buffer(oggpack_buffer *b);
  95247. extern int ogg_stream_packetin(ogg_stream_state *os, ogg_packet *op);
  95248. extern int ogg_stream_pageout(ogg_stream_state *os, ogg_page *og);
  95249. extern int ogg_stream_flush(ogg_stream_state *os, ogg_page *og);
  95250. extern int ogg_sync_init(ogg_sync_state *oy);
  95251. extern int ogg_sync_clear(ogg_sync_state *oy);
  95252. extern int ogg_sync_reset(ogg_sync_state *oy);
  95253. extern int ogg_sync_destroy(ogg_sync_state *oy);
  95254. extern char *ogg_sync_buffer(ogg_sync_state *oy, long size);
  95255. extern int ogg_sync_wrote(ogg_sync_state *oy, long bytes);
  95256. extern long ogg_sync_pageseek(ogg_sync_state *oy,ogg_page *og);
  95257. extern int ogg_sync_pageout(ogg_sync_state *oy, ogg_page *og);
  95258. extern int ogg_stream_pagein(ogg_stream_state *os, ogg_page *og);
  95259. extern int ogg_stream_packetout(ogg_stream_state *os,ogg_packet *op);
  95260. extern int ogg_stream_packetpeek(ogg_stream_state *os,ogg_packet *op);
  95261. extern int ogg_stream_init(ogg_stream_state *os,int serialno);
  95262. extern int ogg_stream_clear(ogg_stream_state *os);
  95263. extern int ogg_stream_reset(ogg_stream_state *os);
  95264. extern int ogg_stream_reset_serialno(ogg_stream_state *os,int serialno);
  95265. extern int ogg_stream_destroy(ogg_stream_state *os);
  95266. extern int ogg_stream_eos(ogg_stream_state *os);
  95267. extern void ogg_page_checksum_set(ogg_page *og);
  95268. extern int ogg_page_version(ogg_page *og);
  95269. extern int ogg_page_continued(ogg_page *og);
  95270. extern int ogg_page_bos(ogg_page *og);
  95271. extern int ogg_page_eos(ogg_page *og);
  95272. extern ogg_int64_t ogg_page_granulepos(ogg_page *og);
  95273. extern int ogg_page_serialno(ogg_page *og);
  95274. extern long ogg_page_pageno(ogg_page *og);
  95275. extern int ogg_page_packets(ogg_page *og);
  95276. extern void ogg_packet_clear(ogg_packet *op);
  95277. #ifdef __cplusplus
  95278. }
  95279. #endif
  95280. #endif /* _OGG_H */
  95281. /********* End of inlined file: ogg.h *********/
  95282. typedef struct vorbis_info{
  95283. int version;
  95284. int channels;
  95285. long rate;
  95286. long bitrate_upper;
  95287. long bitrate_nominal;
  95288. long bitrate_lower;
  95289. long bitrate_window;
  95290. void *codec_setup;
  95291. } vorbis_info;
  95292. typedef struct vorbis_dsp_state{
  95293. int analysisp;
  95294. vorbis_info *vi;
  95295. float **pcm;
  95296. float **pcmret;
  95297. int pcm_storage;
  95298. int pcm_current;
  95299. int pcm_returned;
  95300. int preextrapolate;
  95301. int eofflag;
  95302. long lW;
  95303. long W;
  95304. long nW;
  95305. long centerW;
  95306. ogg_int64_t granulepos;
  95307. ogg_int64_t sequence;
  95308. ogg_int64_t glue_bits;
  95309. ogg_int64_t time_bits;
  95310. ogg_int64_t floor_bits;
  95311. ogg_int64_t res_bits;
  95312. void *backend_state;
  95313. } vorbis_dsp_state;
  95314. typedef struct vorbis_block{
  95315. float **pcm; /* this is a pointer into local storage */
  95316. oggpack_buffer opb;
  95317. long lW;
  95318. long W;
  95319. long nW;
  95320. int pcmend;
  95321. int mode;
  95322. int eofflag;
  95323. ogg_int64_t granulepos;
  95324. ogg_int64_t sequence;
  95325. vorbis_dsp_state *vd; /* For read-only access of configuration */
  95326. void *localstore;
  95327. long localtop;
  95328. long localalloc;
  95329. long totaluse;
  95330. struct alloc_chain *reap;
  95331. long glue_bits;
  95332. long time_bits;
  95333. long floor_bits;
  95334. long res_bits;
  95335. void *internal;
  95336. } vorbis_block;
  95337. struct alloc_chain{
  95338. void *ptr;
  95339. struct alloc_chain *next;
  95340. };
  95341. typedef struct vorbis_comment{
  95342. char **user_comments;
  95343. int *comment_lengths;
  95344. int comments;
  95345. char *vendor;
  95346. } vorbis_comment;
  95347. extern void vorbis_info_init(vorbis_info *vi);
  95348. extern void vorbis_info_clear(vorbis_info *vi);
  95349. extern int vorbis_info_blocksize(vorbis_info *vi,int zo);
  95350. extern void vorbis_comment_init(vorbis_comment *vc);
  95351. extern void vorbis_comment_add(vorbis_comment *vc, char *comment);
  95352. extern void vorbis_comment_add_tag(vorbis_comment *vc,
  95353. const char *tag, char *contents);
  95354. extern char *vorbis_comment_query(vorbis_comment *vc, char *tag, int count);
  95355. extern int vorbis_comment_query_count(vorbis_comment *vc, char *tag);
  95356. extern void vorbis_comment_clear(vorbis_comment *vc);
  95357. extern int vorbis_block_init(vorbis_dsp_state *v, vorbis_block *vb);
  95358. extern int vorbis_block_clear(vorbis_block *vb);
  95359. extern void vorbis_dsp_clear(vorbis_dsp_state *v);
  95360. extern double vorbis_granule_time(vorbis_dsp_state *v,
  95361. ogg_int64_t granulepos);
  95362. extern int vorbis_analysis_init(vorbis_dsp_state *v,vorbis_info *vi);
  95363. extern int vorbis_commentheader_out(vorbis_comment *vc, ogg_packet *op);
  95364. extern int vorbis_analysis_headerout(vorbis_dsp_state *v,
  95365. vorbis_comment *vc,
  95366. ogg_packet *op,
  95367. ogg_packet *op_comm,
  95368. ogg_packet *op_code);
  95369. extern float **vorbis_analysis_buffer(vorbis_dsp_state *v,int vals);
  95370. extern int vorbis_analysis_wrote(vorbis_dsp_state *v,int vals);
  95371. extern int vorbis_analysis_blockout(vorbis_dsp_state *v,vorbis_block *vb);
  95372. extern int vorbis_analysis(vorbis_block *vb,ogg_packet *op);
  95373. extern int vorbis_bitrate_addblock(vorbis_block *vb);
  95374. extern int vorbis_bitrate_flushpacket(vorbis_dsp_state *vd,
  95375. ogg_packet *op);
  95376. extern int vorbis_synthesis_headerin(vorbis_info *vi,vorbis_comment *vc,
  95377. ogg_packet *op);
  95378. extern int vorbis_synthesis_init(vorbis_dsp_state *v,vorbis_info *vi);
  95379. extern int vorbis_synthesis_restart(vorbis_dsp_state *v);
  95380. extern int vorbis_synthesis(vorbis_block *vb,ogg_packet *op);
  95381. extern int vorbis_synthesis_trackonly(vorbis_block *vb,ogg_packet *op);
  95382. extern int vorbis_synthesis_blockin(vorbis_dsp_state *v,vorbis_block *vb);
  95383. extern int vorbis_synthesis_pcmout(vorbis_dsp_state *v,float ***pcm);
  95384. extern int vorbis_synthesis_lapout(vorbis_dsp_state *v,float ***pcm);
  95385. extern int vorbis_synthesis_read(vorbis_dsp_state *v,int samples);
  95386. extern long vorbis_packet_blocksize(vorbis_info *vi,ogg_packet *op);
  95387. extern int vorbis_synthesis_halfrate(vorbis_info *v,int flag);
  95388. extern int vorbis_synthesis_halfrate_p(vorbis_info *v);
  95389. #define OV_FALSE -1
  95390. #define OV_EOF -2
  95391. #define OV_HOLE -3
  95392. #define OV_EREAD -128
  95393. #define OV_EFAULT -129
  95394. #define OV_EIMPL -130
  95395. #define OV_EINVAL -131
  95396. #define OV_ENOTVORBIS -132
  95397. #define OV_EBADHEADER -133
  95398. #define OV_EVERSION -134
  95399. #define OV_ENOTAUDIO -135
  95400. #define OV_EBADPACKET -136
  95401. #define OV_EBADLINK -137
  95402. #define OV_ENOSEEK -138
  95403. #ifdef __cplusplus
  95404. }
  95405. #endif /* __cplusplus */
  95406. #endif
  95407. /********* End of inlined file: codec.h *********/
  95408. extern int vorbis_encode_init(vorbis_info *vi,
  95409. long channels,
  95410. long rate,
  95411. long max_bitrate,
  95412. long nominal_bitrate,
  95413. long min_bitrate);
  95414. extern int vorbis_encode_setup_managed(vorbis_info *vi,
  95415. long channels,
  95416. long rate,
  95417. long max_bitrate,
  95418. long nominal_bitrate,
  95419. long min_bitrate);
  95420. extern int vorbis_encode_setup_vbr(vorbis_info *vi,
  95421. long channels,
  95422. long rate,
  95423. float quality /* quality level from 0. (lo) to 1. (hi) */
  95424. );
  95425. extern int vorbis_encode_init_vbr(vorbis_info *vi,
  95426. long channels,
  95427. long rate,
  95428. float base_quality /* quality level from 0. (lo) to 1. (hi) */
  95429. );
  95430. extern int vorbis_encode_setup_init(vorbis_info *vi);
  95431. extern int vorbis_encode_ctl(vorbis_info *vi,int number,void *arg);
  95432. #define OV_ECTL_RATEMANAGE_GET 0x10
  95433. #define OV_ECTL_RATEMANAGE_SET 0x11
  95434. #define OV_ECTL_RATEMANAGE_AVG 0x12
  95435. #define OV_ECTL_RATEMANAGE_HARD 0x13
  95436. struct ovectl_ratemanage_arg {
  95437. int management_active;
  95438. long bitrate_hard_min;
  95439. long bitrate_hard_max;
  95440. double bitrate_hard_window;
  95441. long bitrate_av_lo;
  95442. long bitrate_av_hi;
  95443. double bitrate_av_window;
  95444. double bitrate_av_window_center;
  95445. };
  95446. #define OV_ECTL_RATEMANAGE2_GET 0x14
  95447. #define OV_ECTL_RATEMANAGE2_SET 0x15
  95448. struct ovectl_ratemanage2_arg {
  95449. int management_active;
  95450. long bitrate_limit_min_kbps;
  95451. long bitrate_limit_max_kbps;
  95452. long bitrate_limit_reservoir_bits;
  95453. double bitrate_limit_reservoir_bias;
  95454. long bitrate_average_kbps;
  95455. double bitrate_average_damping;
  95456. };
  95457. #define OV_ECTL_LOWPASS_GET 0x20
  95458. #define OV_ECTL_LOWPASS_SET 0x21
  95459. #define OV_ECTL_IBLOCK_GET 0x30
  95460. #define OV_ECTL_IBLOCK_SET 0x31
  95461. #ifdef __cplusplus
  95462. }
  95463. #endif /* __cplusplus */
  95464. #endif
  95465. /********* End of inlined file: vorbisenc.h *********/
  95466. /********* Start of inlined file: vorbisfile.h *********/
  95467. #ifndef _OV_FILE_H_
  95468. #define _OV_FILE_H_
  95469. #ifdef __cplusplus
  95470. extern "C"
  95471. {
  95472. #endif /* __cplusplus */
  95473. #include <stdio.h>
  95474. typedef struct {
  95475. size_t (*read_func) (void *ptr, size_t size, size_t nmemb, void *datasource);
  95476. int (*seek_func) (void *datasource, ogg_int64_t offset, int whence);
  95477. int (*close_func) (void *datasource);
  95478. long (*tell_func) (void *datasource);
  95479. } ov_callbacks;
  95480. #define NOTOPEN 0
  95481. #define PARTOPEN 1
  95482. #define OPENED 2
  95483. #define STREAMSET 3
  95484. #define INITSET 4
  95485. typedef struct OggVorbis_File {
  95486. void *datasource; /* Pointer to a FILE *, etc. */
  95487. int seekable;
  95488. ogg_int64_t offset;
  95489. ogg_int64_t end;
  95490. ogg_sync_state oy;
  95491. int links;
  95492. ogg_int64_t *offsets;
  95493. ogg_int64_t *dataoffsets;
  95494. long *serialnos;
  95495. ogg_int64_t *pcmlengths; /* overloaded to maintain binary
  95496. compatability; x2 size, stores both
  95497. beginning and end values */
  95498. vorbis_info *vi;
  95499. vorbis_comment *vc;
  95500. ogg_int64_t pcm_offset;
  95501. int ready_state;
  95502. long current_serialno;
  95503. int current_link;
  95504. double bittrack;
  95505. double samptrack;
  95506. ogg_stream_state os; /* take physical pages, weld into a logical
  95507. stream of packets */
  95508. vorbis_dsp_state vd; /* central working state for the packet->PCM decoder */
  95509. vorbis_block vb; /* local working space for packet->PCM decode */
  95510. ov_callbacks callbacks;
  95511. } OggVorbis_File;
  95512. extern int ov_clear(OggVorbis_File *vf);
  95513. extern int ov_open(FILE *f,OggVorbis_File *vf,char *initial,long ibytes);
  95514. extern int ov_open_callbacks(void *datasource, OggVorbis_File *vf,
  95515. char *initial, long ibytes, ov_callbacks callbacks);
  95516. extern int ov_test(FILE *f,OggVorbis_File *vf,char *initial,long ibytes);
  95517. extern int ov_test_callbacks(void *datasource, OggVorbis_File *vf,
  95518. char *initial, long ibytes, ov_callbacks callbacks);
  95519. extern int ov_test_open(OggVorbis_File *vf);
  95520. extern long ov_bitrate(OggVorbis_File *vf,int i);
  95521. extern long ov_bitrate_instant(OggVorbis_File *vf);
  95522. extern long ov_streams(OggVorbis_File *vf);
  95523. extern long ov_seekable(OggVorbis_File *vf);
  95524. extern long ov_serialnumber(OggVorbis_File *vf,int i);
  95525. extern ogg_int64_t ov_raw_total(OggVorbis_File *vf,int i);
  95526. extern ogg_int64_t ov_pcm_total(OggVorbis_File *vf,int i);
  95527. extern double ov_time_total(OggVorbis_File *vf,int i);
  95528. extern int ov_raw_seek(OggVorbis_File *vf,ogg_int64_t pos);
  95529. extern int ov_pcm_seek(OggVorbis_File *vf,ogg_int64_t pos);
  95530. extern int ov_pcm_seek_page(OggVorbis_File *vf,ogg_int64_t pos);
  95531. extern int ov_time_seek(OggVorbis_File *vf,double pos);
  95532. extern int ov_time_seek_page(OggVorbis_File *vf,double pos);
  95533. extern int ov_raw_seek_lap(OggVorbis_File *vf,ogg_int64_t pos);
  95534. extern int ov_pcm_seek_lap(OggVorbis_File *vf,ogg_int64_t pos);
  95535. extern int ov_pcm_seek_page_lap(OggVorbis_File *vf,ogg_int64_t pos);
  95536. extern int ov_time_seek_lap(OggVorbis_File *vf,double pos);
  95537. extern int ov_time_seek_page_lap(OggVorbis_File *vf,double pos);
  95538. extern ogg_int64_t ov_raw_tell(OggVorbis_File *vf);
  95539. extern ogg_int64_t ov_pcm_tell(OggVorbis_File *vf);
  95540. extern double ov_time_tell(OggVorbis_File *vf);
  95541. extern vorbis_info *ov_info(OggVorbis_File *vf,int link);
  95542. extern vorbis_comment *ov_comment(OggVorbis_File *vf,int link);
  95543. extern long ov_read_float(OggVorbis_File *vf,float ***pcm_channels,int samples,
  95544. int *bitstream);
  95545. extern long ov_read(OggVorbis_File *vf,char *buffer,int length,
  95546. int bigendianp,int word,int sgned,int *bitstream);
  95547. extern int ov_crosslap(OggVorbis_File *vf1,OggVorbis_File *vf2);
  95548. extern int ov_halfrate(OggVorbis_File *vf,int flag);
  95549. extern int ov_halfrate_p(OggVorbis_File *vf);
  95550. #ifdef __cplusplus
  95551. }
  95552. #endif /* __cplusplus */
  95553. #endif
  95554. /********* End of inlined file: vorbisfile.h *********/
  95555. /********* Start of inlined file: bitwise.c *********/
  95556. /********* Start of inlined file: juce_OggVorbisHeader.h *********/
  95557. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  95558. // tasks..
  95559. #if JUCE_MSVC
  95560. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  95561. #endif
  95562. /********* End of inlined file: juce_OggVorbisHeader.h *********/
  95563. #if JUCE_USE_OGGVORBIS
  95564. #include <string.h>
  95565. #include <stdlib.h>
  95566. #define BUFFER_INCREMENT 256
  95567. static const unsigned long mask[]=
  95568. {0x00000000,0x00000001,0x00000003,0x00000007,0x0000000f,
  95569. 0x0000001f,0x0000003f,0x0000007f,0x000000ff,0x000001ff,
  95570. 0x000003ff,0x000007ff,0x00000fff,0x00001fff,0x00003fff,
  95571. 0x00007fff,0x0000ffff,0x0001ffff,0x0003ffff,0x0007ffff,
  95572. 0x000fffff,0x001fffff,0x003fffff,0x007fffff,0x00ffffff,
  95573. 0x01ffffff,0x03ffffff,0x07ffffff,0x0fffffff,0x1fffffff,
  95574. 0x3fffffff,0x7fffffff,0xffffffff };
  95575. static const unsigned int mask8B[]=
  95576. {0x00,0x80,0xc0,0xe0,0xf0,0xf8,0xfc,0xfe,0xff};
  95577. void oggpack_writeinit(oggpack_buffer *b){
  95578. memset(b,0,sizeof(*b));
  95579. b->ptr=b->buffer=(unsigned char*) _ogg_malloc(BUFFER_INCREMENT);
  95580. b->buffer[0]='\0';
  95581. b->storage=BUFFER_INCREMENT;
  95582. }
  95583. void oggpackB_writeinit(oggpack_buffer *b){
  95584. oggpack_writeinit(b);
  95585. }
  95586. void oggpack_writetrunc(oggpack_buffer *b,long bits){
  95587. long bytes=bits>>3;
  95588. bits-=bytes*8;
  95589. b->ptr=b->buffer+bytes;
  95590. b->endbit=bits;
  95591. b->endbyte=bytes;
  95592. *b->ptr&=mask[bits];
  95593. }
  95594. void oggpackB_writetrunc(oggpack_buffer *b,long bits){
  95595. long bytes=bits>>3;
  95596. bits-=bytes*8;
  95597. b->ptr=b->buffer+bytes;
  95598. b->endbit=bits;
  95599. b->endbyte=bytes;
  95600. *b->ptr&=mask8B[bits];
  95601. }
  95602. void oggpack_write(oggpack_buffer *b,unsigned long value,int bits){
  95603. if(b->endbyte+4>=b->storage){
  95604. b->buffer=(unsigned char*) _ogg_realloc(b->buffer,b->storage+BUFFER_INCREMENT);
  95605. b->storage+=BUFFER_INCREMENT;
  95606. b->ptr=b->buffer+b->endbyte;
  95607. }
  95608. value&=mask[bits];
  95609. bits+=b->endbit;
  95610. b->ptr[0]|=value<<b->endbit;
  95611. if(bits>=8){
  95612. b->ptr[1]=(unsigned char)(value>>(8-b->endbit));
  95613. if(bits>=16){
  95614. b->ptr[2]=(unsigned char)(value>>(16-b->endbit));
  95615. if(bits>=24){
  95616. b->ptr[3]=(unsigned char)(value>>(24-b->endbit));
  95617. if(bits>=32){
  95618. if(b->endbit)
  95619. b->ptr[4]=(unsigned char)(value>>(32-b->endbit));
  95620. else
  95621. b->ptr[4]=0;
  95622. }
  95623. }
  95624. }
  95625. }
  95626. b->endbyte+=bits/8;
  95627. b->ptr+=bits/8;
  95628. b->endbit=bits&7;
  95629. }
  95630. void oggpackB_write(oggpack_buffer *b,unsigned long value,int bits){
  95631. if(b->endbyte+4>=b->storage){
  95632. b->buffer=(unsigned char*) _ogg_realloc(b->buffer,b->storage+BUFFER_INCREMENT);
  95633. b->storage+=BUFFER_INCREMENT;
  95634. b->ptr=b->buffer+b->endbyte;
  95635. }
  95636. value=(value&mask[bits])<<(32-bits);
  95637. bits+=b->endbit;
  95638. b->ptr[0]|=value>>(24+b->endbit);
  95639. if(bits>=8){
  95640. b->ptr[1]=(unsigned char)(value>>(16+b->endbit));
  95641. if(bits>=16){
  95642. b->ptr[2]=(unsigned char)(value>>(8+b->endbit));
  95643. if(bits>=24){
  95644. b->ptr[3]=(unsigned char)(value>>(b->endbit));
  95645. if(bits>=32){
  95646. if(b->endbit)
  95647. b->ptr[4]=(unsigned char)(value<<(8-b->endbit));
  95648. else
  95649. b->ptr[4]=0;
  95650. }
  95651. }
  95652. }
  95653. }
  95654. b->endbyte+=bits/8;
  95655. b->ptr+=bits/8;
  95656. b->endbit=bits&7;
  95657. }
  95658. void oggpack_writealign(oggpack_buffer *b){
  95659. int bits=8-b->endbit;
  95660. if(bits<8)
  95661. oggpack_write(b,0,bits);
  95662. }
  95663. void oggpackB_writealign(oggpack_buffer *b){
  95664. int bits=8-b->endbit;
  95665. if(bits<8)
  95666. oggpackB_write(b,0,bits);
  95667. }
  95668. static void oggpack_writecopy_helper(oggpack_buffer *b,
  95669. void *source,
  95670. long bits,
  95671. void (*w)(oggpack_buffer *,
  95672. unsigned long,
  95673. int),
  95674. int msb){
  95675. unsigned char *ptr=(unsigned char *)source;
  95676. long bytes=bits/8;
  95677. bits-=bytes*8;
  95678. if(b->endbit){
  95679. int i;
  95680. for(i=0;i<bytes;i++)
  95681. w(b,(unsigned long)(ptr[i]),8);
  95682. }else{
  95683. if(b->endbyte+bytes+1>=b->storage){
  95684. b->storage=b->endbyte+bytes+BUFFER_INCREMENT;
  95685. b->buffer=(unsigned char*) _ogg_realloc(b->buffer,b->storage);
  95686. b->ptr=b->buffer+b->endbyte;
  95687. }
  95688. memmove(b->ptr,source,bytes);
  95689. b->ptr+=bytes;
  95690. b->endbyte+=bytes;
  95691. *b->ptr=0;
  95692. }
  95693. if(bits){
  95694. if(msb)
  95695. w(b,(unsigned long)(ptr[bytes]>>(8-bits)),bits);
  95696. else
  95697. w(b,(unsigned long)(ptr[bytes]),bits);
  95698. }
  95699. }
  95700. void oggpack_writecopy(oggpack_buffer *b,void *source,long bits){
  95701. oggpack_writecopy_helper(b,source,bits,oggpack_write,0);
  95702. }
  95703. void oggpackB_writecopy(oggpack_buffer *b,void *source,long bits){
  95704. oggpack_writecopy_helper(b,source,bits,oggpackB_write,1);
  95705. }
  95706. void oggpack_reset(oggpack_buffer *b){
  95707. b->ptr=b->buffer;
  95708. b->buffer[0]=0;
  95709. b->endbit=b->endbyte=0;
  95710. }
  95711. void oggpackB_reset(oggpack_buffer *b){
  95712. oggpack_reset(b);
  95713. }
  95714. void oggpack_writeclear(oggpack_buffer *b){
  95715. _ogg_free(b->buffer);
  95716. memset(b,0,sizeof(*b));
  95717. }
  95718. void oggpackB_writeclear(oggpack_buffer *b){
  95719. oggpack_writeclear(b);
  95720. }
  95721. void oggpack_readinit(oggpack_buffer *b,unsigned char *buf,int bytes){
  95722. memset(b,0,sizeof(*b));
  95723. b->buffer=b->ptr=buf;
  95724. b->storage=bytes;
  95725. }
  95726. void oggpackB_readinit(oggpack_buffer *b,unsigned char *buf,int bytes){
  95727. oggpack_readinit(b,buf,bytes);
  95728. }
  95729. long oggpack_look(oggpack_buffer *b,int bits){
  95730. unsigned long ret;
  95731. unsigned long m=mask[bits];
  95732. bits+=b->endbit;
  95733. if(b->endbyte+4>=b->storage){
  95734. if(b->endbyte*8+bits>b->storage*8)return(-1);
  95735. }
  95736. ret=b->ptr[0]>>b->endbit;
  95737. if(bits>8){
  95738. ret|=b->ptr[1]<<(8-b->endbit);
  95739. if(bits>16){
  95740. ret|=b->ptr[2]<<(16-b->endbit);
  95741. if(bits>24){
  95742. ret|=b->ptr[3]<<(24-b->endbit);
  95743. if(bits>32 && b->endbit)
  95744. ret|=b->ptr[4]<<(32-b->endbit);
  95745. }
  95746. }
  95747. }
  95748. return(m&ret);
  95749. }
  95750. long oggpackB_look(oggpack_buffer *b,int bits){
  95751. unsigned long ret;
  95752. int m=32-bits;
  95753. bits+=b->endbit;
  95754. if(b->endbyte+4>=b->storage){
  95755. if(b->endbyte*8+bits>b->storage*8)return(-1);
  95756. }
  95757. ret=b->ptr[0]<<(24+b->endbit);
  95758. if(bits>8){
  95759. ret|=b->ptr[1]<<(16+b->endbit);
  95760. if(bits>16){
  95761. ret|=b->ptr[2]<<(8+b->endbit);
  95762. if(bits>24){
  95763. ret|=b->ptr[3]<<(b->endbit);
  95764. if(bits>32 && b->endbit)
  95765. ret|=b->ptr[4]>>(8-b->endbit);
  95766. }
  95767. }
  95768. }
  95769. return ((ret&0xffffffff)>>(m>>1))>>((m+1)>>1);
  95770. }
  95771. long oggpack_look1(oggpack_buffer *b){
  95772. if(b->endbyte>=b->storage)return(-1);
  95773. return((b->ptr[0]>>b->endbit)&1);
  95774. }
  95775. long oggpackB_look1(oggpack_buffer *b){
  95776. if(b->endbyte>=b->storage)return(-1);
  95777. return((b->ptr[0]>>(7-b->endbit))&1);
  95778. }
  95779. void oggpack_adv(oggpack_buffer *b,int bits){
  95780. bits+=b->endbit;
  95781. b->ptr+=bits/8;
  95782. b->endbyte+=bits/8;
  95783. b->endbit=bits&7;
  95784. }
  95785. void oggpackB_adv(oggpack_buffer *b,int bits){
  95786. oggpack_adv(b,bits);
  95787. }
  95788. void oggpack_adv1(oggpack_buffer *b){
  95789. if(++(b->endbit)>7){
  95790. b->endbit=0;
  95791. b->ptr++;
  95792. b->endbyte++;
  95793. }
  95794. }
  95795. void oggpackB_adv1(oggpack_buffer *b){
  95796. oggpack_adv1(b);
  95797. }
  95798. long oggpack_read(oggpack_buffer *b,int bits){
  95799. long ret;
  95800. unsigned long m=mask[bits];
  95801. bits+=b->endbit;
  95802. if(b->endbyte+4>=b->storage){
  95803. ret=-1L;
  95804. if(b->endbyte*8+bits>b->storage*8)goto overflow;
  95805. }
  95806. ret=b->ptr[0]>>b->endbit;
  95807. if(bits>8){
  95808. ret|=b->ptr[1]<<(8-b->endbit);
  95809. if(bits>16){
  95810. ret|=b->ptr[2]<<(16-b->endbit);
  95811. if(bits>24){
  95812. ret|=b->ptr[3]<<(24-b->endbit);
  95813. if(bits>32 && b->endbit){
  95814. ret|=b->ptr[4]<<(32-b->endbit);
  95815. }
  95816. }
  95817. }
  95818. }
  95819. ret&=m;
  95820. overflow:
  95821. b->ptr+=bits/8;
  95822. b->endbyte+=bits/8;
  95823. b->endbit=bits&7;
  95824. return(ret);
  95825. }
  95826. long oggpackB_read(oggpack_buffer *b,int bits){
  95827. long ret;
  95828. long m=32-bits;
  95829. bits+=b->endbit;
  95830. if(b->endbyte+4>=b->storage){
  95831. ret=-1L;
  95832. if(b->endbyte*8+bits>b->storage*8)goto overflow;
  95833. }
  95834. ret=b->ptr[0]<<(24+b->endbit);
  95835. if(bits>8){
  95836. ret|=b->ptr[1]<<(16+b->endbit);
  95837. if(bits>16){
  95838. ret|=b->ptr[2]<<(8+b->endbit);
  95839. if(bits>24){
  95840. ret|=b->ptr[3]<<(b->endbit);
  95841. if(bits>32 && b->endbit)
  95842. ret|=b->ptr[4]>>(8-b->endbit);
  95843. }
  95844. }
  95845. }
  95846. ret=((ret&0xffffffffUL)>>(m>>1))>>((m+1)>>1);
  95847. overflow:
  95848. b->ptr+=bits/8;
  95849. b->endbyte+=bits/8;
  95850. b->endbit=bits&7;
  95851. return(ret);
  95852. }
  95853. long oggpack_read1(oggpack_buffer *b){
  95854. long ret;
  95855. if(b->endbyte>=b->storage){
  95856. ret=-1L;
  95857. goto overflow;
  95858. }
  95859. ret=(b->ptr[0]>>b->endbit)&1;
  95860. overflow:
  95861. b->endbit++;
  95862. if(b->endbit>7){
  95863. b->endbit=0;
  95864. b->ptr++;
  95865. b->endbyte++;
  95866. }
  95867. return(ret);
  95868. }
  95869. long oggpackB_read1(oggpack_buffer *b){
  95870. long ret;
  95871. if(b->endbyte>=b->storage){
  95872. ret=-1L;
  95873. goto overflow;
  95874. }
  95875. ret=(b->ptr[0]>>(7-b->endbit))&1;
  95876. overflow:
  95877. b->endbit++;
  95878. if(b->endbit>7){
  95879. b->endbit=0;
  95880. b->ptr++;
  95881. b->endbyte++;
  95882. }
  95883. return(ret);
  95884. }
  95885. long oggpack_bytes(oggpack_buffer *b){
  95886. return(b->endbyte+(b->endbit+7)/8);
  95887. }
  95888. long oggpack_bits(oggpack_buffer *b){
  95889. return(b->endbyte*8+b->endbit);
  95890. }
  95891. long oggpackB_bytes(oggpack_buffer *b){
  95892. return oggpack_bytes(b);
  95893. }
  95894. long oggpackB_bits(oggpack_buffer *b){
  95895. return oggpack_bits(b);
  95896. }
  95897. unsigned char *oggpack_get_buffer(oggpack_buffer *b){
  95898. return(b->buffer);
  95899. }
  95900. unsigned char *oggpackB_get_buffer(oggpack_buffer *b){
  95901. return oggpack_get_buffer(b);
  95902. }
  95903. #ifdef _V_SELFTEST
  95904. #include <stdio.h>
  95905. static int ilog(unsigned int v){
  95906. int ret=0;
  95907. while(v){
  95908. ret++;
  95909. v>>=1;
  95910. }
  95911. return(ret);
  95912. }
  95913. oggpack_buffer o;
  95914. oggpack_buffer r;
  95915. void report(char *in){
  95916. fprintf(stderr,"%s",in);
  95917. exit(1);
  95918. }
  95919. void cliptest(unsigned long *b,int vals,int bits,int *comp,int compsize){
  95920. long bytes,i;
  95921. unsigned char *buffer;
  95922. oggpack_reset(&o);
  95923. for(i=0;i<vals;i++)
  95924. oggpack_write(&o,b[i],bits?bits:ilog(b[i]));
  95925. buffer=oggpack_get_buffer(&o);
  95926. bytes=oggpack_bytes(&o);
  95927. if(bytes!=compsize)report("wrong number of bytes!\n");
  95928. for(i=0;i<bytes;i++)if(buffer[i]!=comp[i]){
  95929. for(i=0;i<bytes;i++)fprintf(stderr,"%x %x\n",(int)buffer[i],(int)comp[i]);
  95930. report("wrote incorrect value!\n");
  95931. }
  95932. oggpack_readinit(&r,buffer,bytes);
  95933. for(i=0;i<vals;i++){
  95934. int tbit=bits?bits:ilog(b[i]);
  95935. if(oggpack_look(&r,tbit)==-1)
  95936. report("out of data!\n");
  95937. if(oggpack_look(&r,tbit)!=(b[i]&mask[tbit]))
  95938. report("looked at incorrect value!\n");
  95939. if(tbit==1)
  95940. if(oggpack_look1(&r)!=(b[i]&mask[tbit]))
  95941. report("looked at single bit incorrect value!\n");
  95942. if(tbit==1){
  95943. if(oggpack_read1(&r)!=(b[i]&mask[tbit]))
  95944. report("read incorrect single bit value!\n");
  95945. }else{
  95946. if(oggpack_read(&r,tbit)!=(b[i]&mask[tbit]))
  95947. report("read incorrect value!\n");
  95948. }
  95949. }
  95950. if(oggpack_bytes(&r)!=bytes)report("leftover bytes after read!\n");
  95951. }
  95952. void cliptestB(unsigned long *b,int vals,int bits,int *comp,int compsize){
  95953. long bytes,i;
  95954. unsigned char *buffer;
  95955. oggpackB_reset(&o);
  95956. for(i=0;i<vals;i++)
  95957. oggpackB_write(&o,b[i],bits?bits:ilog(b[i]));
  95958. buffer=oggpackB_get_buffer(&o);
  95959. bytes=oggpackB_bytes(&o);
  95960. if(bytes!=compsize)report("wrong number of bytes!\n");
  95961. for(i=0;i<bytes;i++)if(buffer[i]!=comp[i]){
  95962. for(i=0;i<bytes;i++)fprintf(stderr,"%x %x\n",(int)buffer[i],(int)comp[i]);
  95963. report("wrote incorrect value!\n");
  95964. }
  95965. oggpackB_readinit(&r,buffer,bytes);
  95966. for(i=0;i<vals;i++){
  95967. int tbit=bits?bits:ilog(b[i]);
  95968. if(oggpackB_look(&r,tbit)==-1)
  95969. report("out of data!\n");
  95970. if(oggpackB_look(&r,tbit)!=(b[i]&mask[tbit]))
  95971. report("looked at incorrect value!\n");
  95972. if(tbit==1)
  95973. if(oggpackB_look1(&r)!=(b[i]&mask[tbit]))
  95974. report("looked at single bit incorrect value!\n");
  95975. if(tbit==1){
  95976. if(oggpackB_read1(&r)!=(b[i]&mask[tbit]))
  95977. report("read incorrect single bit value!\n");
  95978. }else{
  95979. if(oggpackB_read(&r,tbit)!=(b[i]&mask[tbit]))
  95980. report("read incorrect value!\n");
  95981. }
  95982. }
  95983. if(oggpackB_bytes(&r)!=bytes)report("leftover bytes after read!\n");
  95984. }
  95985. int main(void){
  95986. unsigned char *buffer;
  95987. long bytes,i;
  95988. static unsigned long testbuffer1[]=
  95989. {18,12,103948,4325,543,76,432,52,3,65,4,56,32,42,34,21,1,23,32,546,456,7,
  95990. 567,56,8,8,55,3,52,342,341,4,265,7,67,86,2199,21,7,1,5,1,4};
  95991. int test1size=43;
  95992. static unsigned long testbuffer2[]=
  95993. {216531625L,1237861823,56732452,131,3212421,12325343,34547562,12313212,
  95994. 1233432,534,5,346435231,14436467,7869299,76326614,167548585,
  95995. 85525151,0,12321,1,349528352};
  95996. int test2size=21;
  95997. static unsigned long testbuffer3[]=
  95998. {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,
  95999. 0,1,30,1,1,1,0,0,1,0,0,0,12,0,11,0,1,0,0,1};
  96000. int test3size=56;
  96001. static unsigned long large[]=
  96002. {2136531625L,2137861823,56732452,131,3212421,12325343,34547562,12313212,
  96003. 1233432,534,5,2146435231,14436467,7869299,76326614,167548585,
  96004. 85525151,0,12321,1,2146528352};
  96005. int onesize=33;
  96006. static int one[33]={146,25,44,151,195,15,153,176,233,131,196,65,85,172,47,40,
  96007. 34,242,223,136,35,222,211,86,171,50,225,135,214,75,172,
  96008. 223,4};
  96009. static int oneB[33]={150,101,131,33,203,15,204,216,105,193,156,65,84,85,222,
  96010. 8,139,145,227,126,34,55,244,171,85,100,39,195,173,18,
  96011. 245,251,128};
  96012. int twosize=6;
  96013. static int two[6]={61,255,255,251,231,29};
  96014. static int twoB[6]={247,63,255,253,249,120};
  96015. int threesize=54;
  96016. static int three[54]={169,2,232,252,91,132,156,36,89,13,123,176,144,32,254,
  96017. 142,224,85,59,121,144,79,124,23,67,90,90,216,79,23,83,
  96018. 58,135,196,61,55,129,183,54,101,100,170,37,127,126,10,
  96019. 100,52,4,14,18,86,77,1};
  96020. static int threeB[54]={206,128,42,153,57,8,183,251,13,89,36,30,32,144,183,
  96021. 130,59,240,121,59,85,223,19,228,180,134,33,107,74,98,
  96022. 233,253,196,135,63,2,110,114,50,155,90,127,37,170,104,
  96023. 200,20,254,4,58,106,176,144,0};
  96024. int foursize=38;
  96025. static int four[38]={18,6,163,252,97,194,104,131,32,1,7,82,137,42,129,11,72,
  96026. 132,60,220,112,8,196,109,64,179,86,9,137,195,208,122,169,
  96027. 28,2,133,0,1};
  96028. static int fourB[38]={36,48,102,83,243,24,52,7,4,35,132,10,145,21,2,93,2,41,
  96029. 1,219,184,16,33,184,54,149,170,132,18,30,29,98,229,67,
  96030. 129,10,4,32};
  96031. int fivesize=45;
  96032. static int five[45]={169,2,126,139,144,172,30,4,80,72,240,59,130,218,73,62,
  96033. 241,24,210,44,4,20,0,248,116,49,135,100,110,130,181,169,
  96034. 84,75,159,2,1,0,132,192,8,0,0,18,22};
  96035. static int fiveB[45]={1,84,145,111,245,100,128,8,56,36,40,71,126,78,213,226,
  96036. 124,105,12,0,133,128,0,162,233,242,67,152,77,205,77,
  96037. 172,150,169,129,79,128,0,6,4,32,0,27,9,0};
  96038. int sixsize=7;
  96039. static int six[7]={17,177,170,242,169,19,148};
  96040. static int sixB[7]={136,141,85,79,149,200,41};
  96041. oggpack_writeinit(&o);
  96042. fprintf(stderr,"\nSmall preclipped packing (LSb): ");
  96043. cliptest(testbuffer1,test1size,0,one,onesize);
  96044. fprintf(stderr,"ok.");
  96045. fprintf(stderr,"\nNull bit call (LSb): ");
  96046. cliptest(testbuffer3,test3size,0,two,twosize);
  96047. fprintf(stderr,"ok.");
  96048. fprintf(stderr,"\nLarge preclipped packing (LSb): ");
  96049. cliptest(testbuffer2,test2size,0,three,threesize);
  96050. fprintf(stderr,"ok.");
  96051. fprintf(stderr,"\n32 bit preclipped packing (LSb): ");
  96052. oggpack_reset(&o);
  96053. for(i=0;i<test2size;i++)
  96054. oggpack_write(&o,large[i],32);
  96055. buffer=oggpack_get_buffer(&o);
  96056. bytes=oggpack_bytes(&o);
  96057. oggpack_readinit(&r,buffer,bytes);
  96058. for(i=0;i<test2size;i++){
  96059. if(oggpack_look(&r,32)==-1)report("out of data. failed!");
  96060. if(oggpack_look(&r,32)!=large[i]){
  96061. fprintf(stderr,"%ld != %ld (%lx!=%lx):",oggpack_look(&r,32),large[i],
  96062. oggpack_look(&r,32),large[i]);
  96063. report("read incorrect value!\n");
  96064. }
  96065. oggpack_adv(&r,32);
  96066. }
  96067. if(oggpack_bytes(&r)!=bytes)report("leftover bytes after read!\n");
  96068. fprintf(stderr,"ok.");
  96069. fprintf(stderr,"\nSmall unclipped packing (LSb): ");
  96070. cliptest(testbuffer1,test1size,7,four,foursize);
  96071. fprintf(stderr,"ok.");
  96072. fprintf(stderr,"\nLarge unclipped packing (LSb): ");
  96073. cliptest(testbuffer2,test2size,17,five,fivesize);
  96074. fprintf(stderr,"ok.");
  96075. fprintf(stderr,"\nSingle bit unclipped packing (LSb): ");
  96076. cliptest(testbuffer3,test3size,1,six,sixsize);
  96077. fprintf(stderr,"ok.");
  96078. fprintf(stderr,"\nTesting read past end (LSb): ");
  96079. oggpack_readinit(&r,"\0\0\0\0\0\0\0\0",8);
  96080. for(i=0;i<64;i++){
  96081. if(oggpack_read(&r,1)!=0){
  96082. fprintf(stderr,"failed; got -1 prematurely.\n");
  96083. exit(1);
  96084. }
  96085. }
  96086. if(oggpack_look(&r,1)!=-1 ||
  96087. oggpack_read(&r,1)!=-1){
  96088. fprintf(stderr,"failed; read past end without -1.\n");
  96089. exit(1);
  96090. }
  96091. oggpack_readinit(&r,"\0\0\0\0\0\0\0\0",8);
  96092. if(oggpack_read(&r,30)!=0 || oggpack_read(&r,16)!=0){
  96093. fprintf(stderr,"failed 2; got -1 prematurely.\n");
  96094. exit(1);
  96095. }
  96096. if(oggpack_look(&r,18)!=0 ||
  96097. oggpack_look(&r,18)!=0){
  96098. fprintf(stderr,"failed 3; got -1 prematurely.\n");
  96099. exit(1);
  96100. }
  96101. if(oggpack_look(&r,19)!=-1 ||
  96102. oggpack_look(&r,19)!=-1){
  96103. fprintf(stderr,"failed; read past end without -1.\n");
  96104. exit(1);
  96105. }
  96106. if(oggpack_look(&r,32)!=-1 ||
  96107. oggpack_look(&r,32)!=-1){
  96108. fprintf(stderr,"failed; read past end without -1.\n");
  96109. exit(1);
  96110. }
  96111. oggpack_writeclear(&o);
  96112. fprintf(stderr,"ok.\n");
  96113. oggpackB_writeinit(&o);
  96114. fprintf(stderr,"\nSmall preclipped packing (MSb): ");
  96115. cliptestB(testbuffer1,test1size,0,oneB,onesize);
  96116. fprintf(stderr,"ok.");
  96117. fprintf(stderr,"\nNull bit call (MSb): ");
  96118. cliptestB(testbuffer3,test3size,0,twoB,twosize);
  96119. fprintf(stderr,"ok.");
  96120. fprintf(stderr,"\nLarge preclipped packing (MSb): ");
  96121. cliptestB(testbuffer2,test2size,0,threeB,threesize);
  96122. fprintf(stderr,"ok.");
  96123. fprintf(stderr,"\n32 bit preclipped packing (MSb): ");
  96124. oggpackB_reset(&o);
  96125. for(i=0;i<test2size;i++)
  96126. oggpackB_write(&o,large[i],32);
  96127. buffer=oggpackB_get_buffer(&o);
  96128. bytes=oggpackB_bytes(&o);
  96129. oggpackB_readinit(&r,buffer,bytes);
  96130. for(i=0;i<test2size;i++){
  96131. if(oggpackB_look(&r,32)==-1)report("out of data. failed!");
  96132. if(oggpackB_look(&r,32)!=large[i]){
  96133. fprintf(stderr,"%ld != %ld (%lx!=%lx):",oggpackB_look(&r,32),large[i],
  96134. oggpackB_look(&r,32),large[i]);
  96135. report("read incorrect value!\n");
  96136. }
  96137. oggpackB_adv(&r,32);
  96138. }
  96139. if(oggpackB_bytes(&r)!=bytes)report("leftover bytes after read!\n");
  96140. fprintf(stderr,"ok.");
  96141. fprintf(stderr,"\nSmall unclipped packing (MSb): ");
  96142. cliptestB(testbuffer1,test1size,7,fourB,foursize);
  96143. fprintf(stderr,"ok.");
  96144. fprintf(stderr,"\nLarge unclipped packing (MSb): ");
  96145. cliptestB(testbuffer2,test2size,17,fiveB,fivesize);
  96146. fprintf(stderr,"ok.");
  96147. fprintf(stderr,"\nSingle bit unclipped packing (MSb): ");
  96148. cliptestB(testbuffer3,test3size,1,sixB,sixsize);
  96149. fprintf(stderr,"ok.");
  96150. fprintf(stderr,"\nTesting read past end (MSb): ");
  96151. oggpackB_readinit(&r,"\0\0\0\0\0\0\0\0",8);
  96152. for(i=0;i<64;i++){
  96153. if(oggpackB_read(&r,1)!=0){
  96154. fprintf(stderr,"failed; got -1 prematurely.\n");
  96155. exit(1);
  96156. }
  96157. }
  96158. if(oggpackB_look(&r,1)!=-1 ||
  96159. oggpackB_read(&r,1)!=-1){
  96160. fprintf(stderr,"failed; read past end without -1.\n");
  96161. exit(1);
  96162. }
  96163. oggpackB_readinit(&r,"\0\0\0\0\0\0\0\0",8);
  96164. if(oggpackB_read(&r,30)!=0 || oggpackB_read(&r,16)!=0){
  96165. fprintf(stderr,"failed 2; got -1 prematurely.\n");
  96166. exit(1);
  96167. }
  96168. if(oggpackB_look(&r,18)!=0 ||
  96169. oggpackB_look(&r,18)!=0){
  96170. fprintf(stderr,"failed 3; got -1 prematurely.\n");
  96171. exit(1);
  96172. }
  96173. if(oggpackB_look(&r,19)!=-1 ||
  96174. oggpackB_look(&r,19)!=-1){
  96175. fprintf(stderr,"failed; read past end without -1.\n");
  96176. exit(1);
  96177. }
  96178. if(oggpackB_look(&r,32)!=-1 ||
  96179. oggpackB_look(&r,32)!=-1){
  96180. fprintf(stderr,"failed; read past end without -1.\n");
  96181. exit(1);
  96182. }
  96183. oggpackB_writeclear(&o);
  96184. fprintf(stderr,"ok.\n\n");
  96185. return(0);
  96186. }
  96187. #endif /* _V_SELFTEST */
  96188. #undef BUFFER_INCREMENT
  96189. #endif
  96190. /********* End of inlined file: bitwise.c *********/
  96191. /********* Start of inlined file: framing.c *********/
  96192. /********* Start of inlined file: juce_OggVorbisHeader.h *********/
  96193. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  96194. // tasks..
  96195. #if JUCE_MSVC
  96196. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  96197. #endif
  96198. /********* End of inlined file: juce_OggVorbisHeader.h *********/
  96199. #if JUCE_USE_OGGVORBIS
  96200. #include <stdlib.h>
  96201. #include <string.h>
  96202. int ogg_page_version(ogg_page *og){
  96203. return((int)(og->header[4]));
  96204. }
  96205. int ogg_page_continued(ogg_page *og){
  96206. return((int)(og->header[5]&0x01));
  96207. }
  96208. int ogg_page_bos(ogg_page *og){
  96209. return((int)(og->header[5]&0x02));
  96210. }
  96211. int ogg_page_eos(ogg_page *og){
  96212. return((int)(og->header[5]&0x04));
  96213. }
  96214. ogg_int64_t ogg_page_granulepos(ogg_page *og){
  96215. unsigned char *page=og->header;
  96216. ogg_int64_t granulepos=page[13]&(0xff);
  96217. granulepos= (granulepos<<8)|(page[12]&0xff);
  96218. granulepos= (granulepos<<8)|(page[11]&0xff);
  96219. granulepos= (granulepos<<8)|(page[10]&0xff);
  96220. granulepos= (granulepos<<8)|(page[9]&0xff);
  96221. granulepos= (granulepos<<8)|(page[8]&0xff);
  96222. granulepos= (granulepos<<8)|(page[7]&0xff);
  96223. granulepos= (granulepos<<8)|(page[6]&0xff);
  96224. return(granulepos);
  96225. }
  96226. int ogg_page_serialno(ogg_page *og){
  96227. return(og->header[14] |
  96228. (og->header[15]<<8) |
  96229. (og->header[16]<<16) |
  96230. (og->header[17]<<24));
  96231. }
  96232. long ogg_page_pageno(ogg_page *og){
  96233. return(og->header[18] |
  96234. (og->header[19]<<8) |
  96235. (og->header[20]<<16) |
  96236. (og->header[21]<<24));
  96237. }
  96238. int ogg_page_packets(ogg_page *og){
  96239. int i,n=og->header[26],count=0;
  96240. for(i=0;i<n;i++)
  96241. if(og->header[27+i]<255)count++;
  96242. return(count);
  96243. }
  96244. #if 0
  96245. static ogg_uint32_t _ogg_crc_entry(unsigned long index){
  96246. int i;
  96247. unsigned long r;
  96248. r = index << 24;
  96249. for (i=0; i<8; i++)
  96250. if (r & 0x80000000UL)
  96251. r = (r << 1) ^ 0x04c11db7; /* The same as the ethernet generator
  96252. polynomial, although we use an
  96253. unreflected alg and an init/final
  96254. of 0, not 0xffffffff */
  96255. else
  96256. r<<=1;
  96257. return (r & 0xffffffffUL);
  96258. }
  96259. #endif
  96260. static const ogg_uint32_t crc_lookup[256]={
  96261. 0x00000000,0x04c11db7,0x09823b6e,0x0d4326d9,
  96262. 0x130476dc,0x17c56b6b,0x1a864db2,0x1e475005,
  96263. 0x2608edb8,0x22c9f00f,0x2f8ad6d6,0x2b4bcb61,
  96264. 0x350c9b64,0x31cd86d3,0x3c8ea00a,0x384fbdbd,
  96265. 0x4c11db70,0x48d0c6c7,0x4593e01e,0x4152fda9,
  96266. 0x5f15adac,0x5bd4b01b,0x569796c2,0x52568b75,
  96267. 0x6a1936c8,0x6ed82b7f,0x639b0da6,0x675a1011,
  96268. 0x791d4014,0x7ddc5da3,0x709f7b7a,0x745e66cd,
  96269. 0x9823b6e0,0x9ce2ab57,0x91a18d8e,0x95609039,
  96270. 0x8b27c03c,0x8fe6dd8b,0x82a5fb52,0x8664e6e5,
  96271. 0xbe2b5b58,0xbaea46ef,0xb7a96036,0xb3687d81,
  96272. 0xad2f2d84,0xa9ee3033,0xa4ad16ea,0xa06c0b5d,
  96273. 0xd4326d90,0xd0f37027,0xddb056fe,0xd9714b49,
  96274. 0xc7361b4c,0xc3f706fb,0xceb42022,0xca753d95,
  96275. 0xf23a8028,0xf6fb9d9f,0xfbb8bb46,0xff79a6f1,
  96276. 0xe13ef6f4,0xe5ffeb43,0xe8bccd9a,0xec7dd02d,
  96277. 0x34867077,0x30476dc0,0x3d044b19,0x39c556ae,
  96278. 0x278206ab,0x23431b1c,0x2e003dc5,0x2ac12072,
  96279. 0x128e9dcf,0x164f8078,0x1b0ca6a1,0x1fcdbb16,
  96280. 0x018aeb13,0x054bf6a4,0x0808d07d,0x0cc9cdca,
  96281. 0x7897ab07,0x7c56b6b0,0x71159069,0x75d48dde,
  96282. 0x6b93dddb,0x6f52c06c,0x6211e6b5,0x66d0fb02,
  96283. 0x5e9f46bf,0x5a5e5b08,0x571d7dd1,0x53dc6066,
  96284. 0x4d9b3063,0x495a2dd4,0x44190b0d,0x40d816ba,
  96285. 0xaca5c697,0xa864db20,0xa527fdf9,0xa1e6e04e,
  96286. 0xbfa1b04b,0xbb60adfc,0xb6238b25,0xb2e29692,
  96287. 0x8aad2b2f,0x8e6c3698,0x832f1041,0x87ee0df6,
  96288. 0x99a95df3,0x9d684044,0x902b669d,0x94ea7b2a,
  96289. 0xe0b41de7,0xe4750050,0xe9362689,0xedf73b3e,
  96290. 0xf3b06b3b,0xf771768c,0xfa325055,0xfef34de2,
  96291. 0xc6bcf05f,0xc27dede8,0xcf3ecb31,0xcbffd686,
  96292. 0xd5b88683,0xd1799b34,0xdc3abded,0xd8fba05a,
  96293. 0x690ce0ee,0x6dcdfd59,0x608edb80,0x644fc637,
  96294. 0x7a089632,0x7ec98b85,0x738aad5c,0x774bb0eb,
  96295. 0x4f040d56,0x4bc510e1,0x46863638,0x42472b8f,
  96296. 0x5c007b8a,0x58c1663d,0x558240e4,0x51435d53,
  96297. 0x251d3b9e,0x21dc2629,0x2c9f00f0,0x285e1d47,
  96298. 0x36194d42,0x32d850f5,0x3f9b762c,0x3b5a6b9b,
  96299. 0x0315d626,0x07d4cb91,0x0a97ed48,0x0e56f0ff,
  96300. 0x1011a0fa,0x14d0bd4d,0x19939b94,0x1d528623,
  96301. 0xf12f560e,0xf5ee4bb9,0xf8ad6d60,0xfc6c70d7,
  96302. 0xe22b20d2,0xe6ea3d65,0xeba91bbc,0xef68060b,
  96303. 0xd727bbb6,0xd3e6a601,0xdea580d8,0xda649d6f,
  96304. 0xc423cd6a,0xc0e2d0dd,0xcda1f604,0xc960ebb3,
  96305. 0xbd3e8d7e,0xb9ff90c9,0xb4bcb610,0xb07daba7,
  96306. 0xae3afba2,0xaafbe615,0xa7b8c0cc,0xa379dd7b,
  96307. 0x9b3660c6,0x9ff77d71,0x92b45ba8,0x9675461f,
  96308. 0x8832161a,0x8cf30bad,0x81b02d74,0x857130c3,
  96309. 0x5d8a9099,0x594b8d2e,0x5408abf7,0x50c9b640,
  96310. 0x4e8ee645,0x4a4ffbf2,0x470cdd2b,0x43cdc09c,
  96311. 0x7b827d21,0x7f436096,0x7200464f,0x76c15bf8,
  96312. 0x68860bfd,0x6c47164a,0x61043093,0x65c52d24,
  96313. 0x119b4be9,0x155a565e,0x18197087,0x1cd86d30,
  96314. 0x029f3d35,0x065e2082,0x0b1d065b,0x0fdc1bec,
  96315. 0x3793a651,0x3352bbe6,0x3e119d3f,0x3ad08088,
  96316. 0x2497d08d,0x2056cd3a,0x2d15ebe3,0x29d4f654,
  96317. 0xc5a92679,0xc1683bce,0xcc2b1d17,0xc8ea00a0,
  96318. 0xd6ad50a5,0xd26c4d12,0xdf2f6bcb,0xdbee767c,
  96319. 0xe3a1cbc1,0xe760d676,0xea23f0af,0xeee2ed18,
  96320. 0xf0a5bd1d,0xf464a0aa,0xf9278673,0xfde69bc4,
  96321. 0x89b8fd09,0x8d79e0be,0x803ac667,0x84fbdbd0,
  96322. 0x9abc8bd5,0x9e7d9662,0x933eb0bb,0x97ffad0c,
  96323. 0xafb010b1,0xab710d06,0xa6322bdf,0xa2f33668,
  96324. 0xbcb4666d,0xb8757bda,0xb5365d03,0xb1f740b4};
  96325. int ogg_stream_init(ogg_stream_state *os,int serialno){
  96326. if(os){
  96327. memset(os,0,sizeof(*os));
  96328. os->body_storage=16*1024;
  96329. os->body_data=(unsigned char*) _ogg_malloc(os->body_storage*sizeof(*os->body_data));
  96330. os->lacing_storage=1024;
  96331. os->lacing_vals=(int*) _ogg_malloc(os->lacing_storage*sizeof(*os->lacing_vals));
  96332. os->granule_vals=(ogg_int64_t*) _ogg_malloc(os->lacing_storage*sizeof(*os->granule_vals));
  96333. os->serialno=serialno;
  96334. return(0);
  96335. }
  96336. return(-1);
  96337. }
  96338. int ogg_stream_clear(ogg_stream_state *os){
  96339. if(os){
  96340. if(os->body_data)_ogg_free(os->body_data);
  96341. if(os->lacing_vals)_ogg_free(os->lacing_vals);
  96342. if(os->granule_vals)_ogg_free(os->granule_vals);
  96343. memset(os,0,sizeof(*os));
  96344. }
  96345. return(0);
  96346. }
  96347. int ogg_stream_destroy(ogg_stream_state *os){
  96348. if(os){
  96349. ogg_stream_clear(os);
  96350. _ogg_free(os);
  96351. }
  96352. return(0);
  96353. }
  96354. static void _os_body_expand(ogg_stream_state *os,int needed){
  96355. if(os->body_storage<=os->body_fill+needed){
  96356. os->body_storage+=(needed+1024);
  96357. os->body_data=(unsigned char*) _ogg_realloc(os->body_data,os->body_storage*sizeof(*os->body_data));
  96358. }
  96359. }
  96360. static void _os_lacing_expand(ogg_stream_state *os,int needed){
  96361. if(os->lacing_storage<=os->lacing_fill+needed){
  96362. os->lacing_storage+=(needed+32);
  96363. os->lacing_vals=(int*)_ogg_realloc(os->lacing_vals,os->lacing_storage*sizeof(*os->lacing_vals));
  96364. os->granule_vals=(ogg_int64_t*)_ogg_realloc(os->granule_vals,os->lacing_storage*sizeof(*os->granule_vals));
  96365. }
  96366. }
  96367. void ogg_page_checksum_set(ogg_page *og){
  96368. if(og){
  96369. ogg_uint32_t crc_reg=0;
  96370. int i;
  96371. og->header[22]=0;
  96372. og->header[23]=0;
  96373. og->header[24]=0;
  96374. og->header[25]=0;
  96375. for(i=0;i<og->header_len;i++)
  96376. crc_reg=(crc_reg<<8)^crc_lookup[((crc_reg >> 24)&0xff)^og->header[i]];
  96377. for(i=0;i<og->body_len;i++)
  96378. crc_reg=(crc_reg<<8)^crc_lookup[((crc_reg >> 24)&0xff)^og->body[i]];
  96379. og->header[22]=(unsigned char)(crc_reg&0xff);
  96380. og->header[23]=(unsigned char)((crc_reg>>8)&0xff);
  96381. og->header[24]=(unsigned char)((crc_reg>>16)&0xff);
  96382. og->header[25]=(unsigned char)((crc_reg>>24)&0xff);
  96383. }
  96384. }
  96385. int ogg_stream_packetin(ogg_stream_state *os,ogg_packet *op){
  96386. int lacing_vals=op->bytes/255+1,i;
  96387. if(os->body_returned){
  96388. os->body_fill-=os->body_returned;
  96389. if(os->body_fill)
  96390. memmove(os->body_data,os->body_data+os->body_returned,
  96391. os->body_fill);
  96392. os->body_returned=0;
  96393. }
  96394. _os_body_expand(os,op->bytes);
  96395. _os_lacing_expand(os,lacing_vals);
  96396. memcpy(os->body_data+os->body_fill,op->packet,op->bytes);
  96397. os->body_fill+=op->bytes;
  96398. for(i=0;i<lacing_vals-1;i++){
  96399. os->lacing_vals[os->lacing_fill+i]=255;
  96400. os->granule_vals[os->lacing_fill+i]=os->granulepos;
  96401. }
  96402. os->lacing_vals[os->lacing_fill+i]=(op->bytes)%255;
  96403. os->granulepos=os->granule_vals[os->lacing_fill+i]=op->granulepos;
  96404. os->lacing_vals[os->lacing_fill]|= 0x100;
  96405. os->lacing_fill+=lacing_vals;
  96406. os->packetno++;
  96407. if(op->e_o_s)os->e_o_s=1;
  96408. return(0);
  96409. }
  96410. int ogg_stream_flush(ogg_stream_state *os,ogg_page *og){
  96411. int i;
  96412. int vals=0;
  96413. int maxvals=(os->lacing_fill>255?255:os->lacing_fill);
  96414. int bytes=0;
  96415. long acc=0;
  96416. ogg_int64_t granule_pos=-1;
  96417. if(maxvals==0)return(0);
  96418. if(os->b_o_s==0){ /* 'initial header page' case */
  96419. granule_pos=0;
  96420. for(vals=0;vals<maxvals;vals++){
  96421. if((os->lacing_vals[vals]&0x0ff)<255){
  96422. vals++;
  96423. break;
  96424. }
  96425. }
  96426. }else{
  96427. for(vals=0;vals<maxvals;vals++){
  96428. if(acc>4096)break;
  96429. acc+=os->lacing_vals[vals]&0x0ff;
  96430. if((os->lacing_vals[vals]&0xff)<255)
  96431. granule_pos=os->granule_vals[vals];
  96432. }
  96433. }
  96434. memcpy(os->header,"OggS",4);
  96435. os->header[4]=0x00;
  96436. os->header[5]=0x00;
  96437. if((os->lacing_vals[0]&0x100)==0)os->header[5]|=0x01;
  96438. if(os->b_o_s==0)os->header[5]|=0x02;
  96439. if(os->e_o_s && os->lacing_fill==vals)os->header[5]|=0x04;
  96440. os->b_o_s=1;
  96441. for(i=6;i<14;i++){
  96442. os->header[i]=(unsigned char)(granule_pos&0xff);
  96443. granule_pos>>=8;
  96444. }
  96445. {
  96446. long serialno=os->serialno;
  96447. for(i=14;i<18;i++){
  96448. os->header[i]=(unsigned char)(serialno&0xff);
  96449. serialno>>=8;
  96450. }
  96451. }
  96452. if(os->pageno==-1)os->pageno=0; /* because someone called
  96453. stream_reset; this would be a
  96454. strange thing to do in an
  96455. encode stream, but it has
  96456. plausible uses */
  96457. {
  96458. long pageno=os->pageno++;
  96459. for(i=18;i<22;i++){
  96460. os->header[i]=(unsigned char)(pageno&0xff);
  96461. pageno>>=8;
  96462. }
  96463. }
  96464. os->header[22]=0;
  96465. os->header[23]=0;
  96466. os->header[24]=0;
  96467. os->header[25]=0;
  96468. os->header[26]=(unsigned char)(vals&0xff);
  96469. for(i=0;i<vals;i++)
  96470. bytes+=os->header[i+27]=(unsigned char)(os->lacing_vals[i]&0xff);
  96471. og->header=os->header;
  96472. og->header_len=os->header_fill=vals+27;
  96473. og->body=os->body_data+os->body_returned;
  96474. og->body_len=bytes;
  96475. os->lacing_fill-=vals;
  96476. memmove(os->lacing_vals,os->lacing_vals+vals,os->lacing_fill*sizeof(*os->lacing_vals));
  96477. memmove(os->granule_vals,os->granule_vals+vals,os->lacing_fill*sizeof(*os->granule_vals));
  96478. os->body_returned+=bytes;
  96479. ogg_page_checksum_set(og);
  96480. return(1);
  96481. }
  96482. int ogg_stream_pageout(ogg_stream_state *os, ogg_page *og){
  96483. if((os->e_o_s&&os->lacing_fill) || /* 'were done, now flush' case */
  96484. os->body_fill-os->body_returned > 4096 ||/* 'page nominal size' case */
  96485. os->lacing_fill>=255 || /* 'segment table full' case */
  96486. (os->lacing_fill&&!os->b_o_s)){ /* 'initial header page' case */
  96487. return(ogg_stream_flush(os,og));
  96488. }
  96489. return(0);
  96490. }
  96491. int ogg_stream_eos(ogg_stream_state *os){
  96492. return os->e_o_s;
  96493. }
  96494. int ogg_sync_init(ogg_sync_state *oy){
  96495. if(oy){
  96496. memset(oy,0,sizeof(*oy));
  96497. }
  96498. return(0);
  96499. }
  96500. int ogg_sync_clear(ogg_sync_state *oy){
  96501. if(oy){
  96502. if(oy->data)_ogg_free(oy->data);
  96503. ogg_sync_init(oy);
  96504. }
  96505. return(0);
  96506. }
  96507. int ogg_sync_destroy(ogg_sync_state *oy){
  96508. if(oy){
  96509. ogg_sync_clear(oy);
  96510. _ogg_free(oy);
  96511. }
  96512. return(0);
  96513. }
  96514. char *ogg_sync_buffer(ogg_sync_state *oy, long size){
  96515. if(oy->returned){
  96516. oy->fill-=oy->returned;
  96517. if(oy->fill>0)
  96518. memmove(oy->data,oy->data+oy->returned,oy->fill);
  96519. oy->returned=0;
  96520. }
  96521. if(size>oy->storage-oy->fill){
  96522. long newsize=size+oy->fill+4096; /* an extra page to be nice */
  96523. if(oy->data)
  96524. oy->data=(unsigned char*) _ogg_realloc(oy->data,newsize);
  96525. else
  96526. oy->data=(unsigned char*) _ogg_malloc(newsize);
  96527. oy->storage=newsize;
  96528. }
  96529. return((char *)oy->data+oy->fill);
  96530. }
  96531. int ogg_sync_wrote(ogg_sync_state *oy, long bytes){
  96532. if(oy->fill+bytes>oy->storage)return(-1);
  96533. oy->fill+=bytes;
  96534. return(0);
  96535. }
  96536. long ogg_sync_pageseek(ogg_sync_state *oy,ogg_page *og){
  96537. unsigned char *page=oy->data+oy->returned;
  96538. unsigned char *next;
  96539. long bytes=oy->fill-oy->returned;
  96540. if(oy->headerbytes==0){
  96541. int headerbytes,i;
  96542. if(bytes<27)return(0); /* not enough for a header */
  96543. if(memcmp(page,"OggS",4))goto sync_fail;
  96544. headerbytes=page[26]+27;
  96545. if(bytes<headerbytes)return(0); /* not enough for header + seg table */
  96546. for(i=0;i<page[26];i++)
  96547. oy->bodybytes+=page[27+i];
  96548. oy->headerbytes=headerbytes;
  96549. }
  96550. if(oy->bodybytes+oy->headerbytes>bytes)return(0);
  96551. {
  96552. char chksum[4];
  96553. ogg_page log;
  96554. memcpy(chksum,page+22,4);
  96555. memset(page+22,0,4);
  96556. log.header=page;
  96557. log.header_len=oy->headerbytes;
  96558. log.body=page+oy->headerbytes;
  96559. log.body_len=oy->bodybytes;
  96560. ogg_page_checksum_set(&log);
  96561. if(memcmp(chksum,page+22,4)){
  96562. memcpy(page+22,chksum,4);
  96563. goto sync_fail;
  96564. }
  96565. }
  96566. {
  96567. unsigned char *page=oy->data+oy->returned;
  96568. long bytes;
  96569. if(og){
  96570. og->header=page;
  96571. og->header_len=oy->headerbytes;
  96572. og->body=page+oy->headerbytes;
  96573. og->body_len=oy->bodybytes;
  96574. }
  96575. oy->unsynced=0;
  96576. oy->returned+=(bytes=oy->headerbytes+oy->bodybytes);
  96577. oy->headerbytes=0;
  96578. oy->bodybytes=0;
  96579. return(bytes);
  96580. }
  96581. sync_fail:
  96582. oy->headerbytes=0;
  96583. oy->bodybytes=0;
  96584. next=(unsigned char*)memchr(page+1,'O',bytes-1);
  96585. if(!next)
  96586. next=oy->data+oy->fill;
  96587. oy->returned=next-oy->data;
  96588. return(-(next-page));
  96589. }
  96590. int ogg_sync_pageout(ogg_sync_state *oy, ogg_page *og){
  96591. for(;;){
  96592. long ret=ogg_sync_pageseek(oy,og);
  96593. if(ret>0){
  96594. return(1);
  96595. }
  96596. if(ret==0){
  96597. return(0);
  96598. }
  96599. if(!oy->unsynced){
  96600. oy->unsynced=1;
  96601. return(-1);
  96602. }
  96603. }
  96604. }
  96605. int ogg_stream_pagein(ogg_stream_state *os, ogg_page *og){
  96606. unsigned char *header=og->header;
  96607. unsigned char *body=og->body;
  96608. long bodysize=og->body_len;
  96609. int segptr=0;
  96610. int version=ogg_page_version(og);
  96611. int continued=ogg_page_continued(og);
  96612. int bos=ogg_page_bos(og);
  96613. int eos=ogg_page_eos(og);
  96614. ogg_int64_t granulepos=ogg_page_granulepos(og);
  96615. int serialno=ogg_page_serialno(og);
  96616. long pageno=ogg_page_pageno(og);
  96617. int segments=header[26];
  96618. {
  96619. long lr=os->lacing_returned;
  96620. long br=os->body_returned;
  96621. if(br){
  96622. os->body_fill-=br;
  96623. if(os->body_fill)
  96624. memmove(os->body_data,os->body_data+br,os->body_fill);
  96625. os->body_returned=0;
  96626. }
  96627. if(lr){
  96628. if(os->lacing_fill-lr){
  96629. memmove(os->lacing_vals,os->lacing_vals+lr,
  96630. (os->lacing_fill-lr)*sizeof(*os->lacing_vals));
  96631. memmove(os->granule_vals,os->granule_vals+lr,
  96632. (os->lacing_fill-lr)*sizeof(*os->granule_vals));
  96633. }
  96634. os->lacing_fill-=lr;
  96635. os->lacing_packet-=lr;
  96636. os->lacing_returned=0;
  96637. }
  96638. }
  96639. if(serialno!=os->serialno)return(-1);
  96640. if(version>0)return(-1);
  96641. _os_lacing_expand(os,segments+1);
  96642. if(pageno!=os->pageno){
  96643. int i;
  96644. for(i=os->lacing_packet;i<os->lacing_fill;i++)
  96645. os->body_fill-=os->lacing_vals[i]&0xff;
  96646. os->lacing_fill=os->lacing_packet;
  96647. if(os->pageno!=-1){
  96648. os->lacing_vals[os->lacing_fill++]=0x400;
  96649. os->lacing_packet++;
  96650. }
  96651. }
  96652. if(continued){
  96653. if(os->lacing_fill<1 ||
  96654. os->lacing_vals[os->lacing_fill-1]==0x400){
  96655. bos=0;
  96656. for(;segptr<segments;segptr++){
  96657. int val=header[27+segptr];
  96658. body+=val;
  96659. bodysize-=val;
  96660. if(val<255){
  96661. segptr++;
  96662. break;
  96663. }
  96664. }
  96665. }
  96666. }
  96667. if(bodysize){
  96668. _os_body_expand(os,bodysize);
  96669. memcpy(os->body_data+os->body_fill,body,bodysize);
  96670. os->body_fill+=bodysize;
  96671. }
  96672. {
  96673. int saved=-1;
  96674. while(segptr<segments){
  96675. int val=header[27+segptr];
  96676. os->lacing_vals[os->lacing_fill]=val;
  96677. os->granule_vals[os->lacing_fill]=-1;
  96678. if(bos){
  96679. os->lacing_vals[os->lacing_fill]|=0x100;
  96680. bos=0;
  96681. }
  96682. if(val<255)saved=os->lacing_fill;
  96683. os->lacing_fill++;
  96684. segptr++;
  96685. if(val<255)os->lacing_packet=os->lacing_fill;
  96686. }
  96687. if(saved!=-1){
  96688. os->granule_vals[saved]=granulepos;
  96689. }
  96690. }
  96691. if(eos){
  96692. os->e_o_s=1;
  96693. if(os->lacing_fill>0)
  96694. os->lacing_vals[os->lacing_fill-1]|=0x200;
  96695. }
  96696. os->pageno=pageno+1;
  96697. return(0);
  96698. }
  96699. int ogg_sync_reset(ogg_sync_state *oy){
  96700. oy->fill=0;
  96701. oy->returned=0;
  96702. oy->unsynced=0;
  96703. oy->headerbytes=0;
  96704. oy->bodybytes=0;
  96705. return(0);
  96706. }
  96707. int ogg_stream_reset(ogg_stream_state *os){
  96708. os->body_fill=0;
  96709. os->body_returned=0;
  96710. os->lacing_fill=0;
  96711. os->lacing_packet=0;
  96712. os->lacing_returned=0;
  96713. os->header_fill=0;
  96714. os->e_o_s=0;
  96715. os->b_o_s=0;
  96716. os->pageno=-1;
  96717. os->packetno=0;
  96718. os->granulepos=0;
  96719. return(0);
  96720. }
  96721. int ogg_stream_reset_serialno(ogg_stream_state *os,int serialno){
  96722. ogg_stream_reset(os);
  96723. os->serialno=serialno;
  96724. return(0);
  96725. }
  96726. static int _packetout(ogg_stream_state *os,ogg_packet *op,int adv){
  96727. int ptr=os->lacing_returned;
  96728. if(os->lacing_packet<=ptr)return(0);
  96729. if(os->lacing_vals[ptr]&0x400){
  96730. os->lacing_returned++;
  96731. os->packetno++;
  96732. return(-1);
  96733. }
  96734. if(!op && !adv)return(1); /* just using peek as an inexpensive way
  96735. to ask if there's a whole packet
  96736. waiting */
  96737. {
  96738. int size=os->lacing_vals[ptr]&0xff;
  96739. int bytes=size;
  96740. int eos=os->lacing_vals[ptr]&0x200; /* last packet of the stream? */
  96741. int bos=os->lacing_vals[ptr]&0x100; /* first packet of the stream? */
  96742. while(size==255){
  96743. int val=os->lacing_vals[++ptr];
  96744. size=val&0xff;
  96745. if(val&0x200)eos=0x200;
  96746. bytes+=size;
  96747. }
  96748. if(op){
  96749. op->e_o_s=eos;
  96750. op->b_o_s=bos;
  96751. op->packet=os->body_data+os->body_returned;
  96752. op->packetno=os->packetno;
  96753. op->granulepos=os->granule_vals[ptr];
  96754. op->bytes=bytes;
  96755. }
  96756. if(adv){
  96757. os->body_returned+=bytes;
  96758. os->lacing_returned=ptr+1;
  96759. os->packetno++;
  96760. }
  96761. }
  96762. return(1);
  96763. }
  96764. int ogg_stream_packetout(ogg_stream_state *os,ogg_packet *op){
  96765. return _packetout(os,op,1);
  96766. }
  96767. int ogg_stream_packetpeek(ogg_stream_state *os,ogg_packet *op){
  96768. return _packetout(os,op,0);
  96769. }
  96770. void ogg_packet_clear(ogg_packet *op) {
  96771. _ogg_free(op->packet);
  96772. memset(op, 0, sizeof(*op));
  96773. }
  96774. #ifdef _V_SELFTEST
  96775. #include <stdio.h>
  96776. ogg_stream_state os_en, os_de;
  96777. ogg_sync_state oy;
  96778. void checkpacket(ogg_packet *op,int len, int no, int pos){
  96779. long j;
  96780. static int sequence=0;
  96781. static int lastno=0;
  96782. if(op->bytes!=len){
  96783. fprintf(stderr,"incorrect packet length!\n");
  96784. exit(1);
  96785. }
  96786. if(op->granulepos!=pos){
  96787. fprintf(stderr,"incorrect packet position!\n");
  96788. exit(1);
  96789. }
  96790. if(no==0){
  96791. sequence=0;
  96792. }else{
  96793. sequence++;
  96794. if(no>lastno+1)
  96795. sequence++;
  96796. }
  96797. lastno=no;
  96798. if(op->packetno!=sequence){
  96799. fprintf(stderr,"incorrect packet sequence %ld != %d\n",
  96800. (long)(op->packetno),sequence);
  96801. exit(1);
  96802. }
  96803. for(j=0;j<op->bytes;j++)
  96804. if(op->packet[j]!=((j+no)&0xff)){
  96805. fprintf(stderr,"body data mismatch (1) at pos %ld: %x!=%lx!\n\n",
  96806. j,op->packet[j],(j+no)&0xff);
  96807. exit(1);
  96808. }
  96809. }
  96810. void check_page(unsigned char *data,const int *header,ogg_page *og){
  96811. long j;
  96812. for(j=0;j<og->body_len;j++)
  96813. if(og->body[j]!=data[j]){
  96814. fprintf(stderr,"body data mismatch (2) at pos %ld: %x!=%x!\n\n",
  96815. j,data[j],og->body[j]);
  96816. exit(1);
  96817. }
  96818. for(j=0;j<og->header_len;j++){
  96819. if(og->header[j]!=header[j]){
  96820. fprintf(stderr,"header content mismatch at pos %ld:\n",j);
  96821. for(j=0;j<header[26]+27;j++)
  96822. fprintf(stderr," (%ld)%02x:%02x",j,header[j],og->header[j]);
  96823. fprintf(stderr,"\n");
  96824. exit(1);
  96825. }
  96826. }
  96827. if(og->header_len!=header[26]+27){
  96828. fprintf(stderr,"header length incorrect! (%ld!=%d)\n",
  96829. og->header_len,header[26]+27);
  96830. exit(1);
  96831. }
  96832. }
  96833. void print_header(ogg_page *og){
  96834. int j;
  96835. fprintf(stderr,"\nHEADER:\n");
  96836. fprintf(stderr," capture: %c %c %c %c version: %d flags: %x\n",
  96837. og->header[0],og->header[1],og->header[2],og->header[3],
  96838. (int)og->header[4],(int)og->header[5]);
  96839. fprintf(stderr," granulepos: %d serialno: %d pageno: %ld\n",
  96840. (og->header[9]<<24)|(og->header[8]<<16)|
  96841. (og->header[7]<<8)|og->header[6],
  96842. (og->header[17]<<24)|(og->header[16]<<16)|
  96843. (og->header[15]<<8)|og->header[14],
  96844. ((long)(og->header[21])<<24)|(og->header[20]<<16)|
  96845. (og->header[19]<<8)|og->header[18]);
  96846. fprintf(stderr," checksum: %02x:%02x:%02x:%02x\n segments: %d (",
  96847. (int)og->header[22],(int)og->header[23],
  96848. (int)og->header[24],(int)og->header[25],
  96849. (int)og->header[26]);
  96850. for(j=27;j<og->header_len;j++)
  96851. fprintf(stderr,"%d ",(int)og->header[j]);
  96852. fprintf(stderr,")\n\n");
  96853. }
  96854. void copy_page(ogg_page *og){
  96855. unsigned char *temp=_ogg_malloc(og->header_len);
  96856. memcpy(temp,og->header,og->header_len);
  96857. og->header=temp;
  96858. temp=_ogg_malloc(og->body_len);
  96859. memcpy(temp,og->body,og->body_len);
  96860. og->body=temp;
  96861. }
  96862. void free_page(ogg_page *og){
  96863. _ogg_free (og->header);
  96864. _ogg_free (og->body);
  96865. }
  96866. void error(void){
  96867. fprintf(stderr,"error!\n");
  96868. exit(1);
  96869. }
  96870. const int head1_0[] = {0x4f,0x67,0x67,0x53,0,0x06,
  96871. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  96872. 0x01,0x02,0x03,0x04,0,0,0,0,
  96873. 0x15,0xed,0xec,0x91,
  96874. 1,
  96875. 17};
  96876. const int head1_1[] = {0x4f,0x67,0x67,0x53,0,0x02,
  96877. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  96878. 0x01,0x02,0x03,0x04,0,0,0,0,
  96879. 0x59,0x10,0x6c,0x2c,
  96880. 1,
  96881. 17};
  96882. const int head2_1[] = {0x4f,0x67,0x67,0x53,0,0x04,
  96883. 0x07,0x18,0x00,0x00,0x00,0x00,0x00,0x00,
  96884. 0x01,0x02,0x03,0x04,1,0,0,0,
  96885. 0x89,0x33,0x85,0xce,
  96886. 13,
  96887. 254,255,0,255,1,255,245,255,255,0,
  96888. 255,255,90};
  96889. const int head1_2[] = {0x4f,0x67,0x67,0x53,0,0x02,
  96890. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  96891. 0x01,0x02,0x03,0x04,0,0,0,0,
  96892. 0xff,0x7b,0x23,0x17,
  96893. 1,
  96894. 0};
  96895. const int head2_2[] = {0x4f,0x67,0x67,0x53,0,0x04,
  96896. 0x07,0x28,0x00,0x00,0x00,0x00,0x00,0x00,
  96897. 0x01,0x02,0x03,0x04,1,0,0,0,
  96898. 0x5c,0x3f,0x66,0xcb,
  96899. 17,
  96900. 17,254,255,0,0,255,1,0,255,245,255,255,0,
  96901. 255,255,90,0};
  96902. const int head1_3[] = {0x4f,0x67,0x67,0x53,0,0x02,
  96903. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  96904. 0x01,0x02,0x03,0x04,0,0,0,0,
  96905. 0x01,0x27,0x31,0xaa,
  96906. 18,
  96907. 255,255,255,255,255,255,255,255,
  96908. 255,255,255,255,255,255,255,255,255,10};
  96909. const int head2_3[] = {0x4f,0x67,0x67,0x53,0,0x04,
  96910. 0x07,0x08,0x00,0x00,0x00,0x00,0x00,0x00,
  96911. 0x01,0x02,0x03,0x04,1,0,0,0,
  96912. 0x7f,0x4e,0x8a,0xd2,
  96913. 4,
  96914. 255,4,255,0};
  96915. const int head1_4[] = {0x4f,0x67,0x67,0x53,0,0x02,
  96916. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  96917. 0x01,0x02,0x03,0x04,0,0,0,0,
  96918. 0xff,0x7b,0x23,0x17,
  96919. 1,
  96920. 0};
  96921. const int head2_4[] = {0x4f,0x67,0x67,0x53,0,0x00,
  96922. 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
  96923. 0x01,0x02,0x03,0x04,1,0,0,0,
  96924. 0x54,0x05,0x51,0xc8,
  96925. 17,
  96926. 255,255,255,255,255,255,255,255,
  96927. 255,255,255,255,255,255,255,255,255};
  96928. const int head3_4[] = {0x4f,0x67,0x67,0x53,0,0x05,
  96929. 0x07,0x0c,0x00,0x00,0x00,0x00,0x00,0x00,
  96930. 0x01,0x02,0x03,0x04,2,0,0,0,
  96931. 0xc8,0xc3,0xcb,0xed,
  96932. 5,
  96933. 10,255,4,255,0};
  96934. const int head1_5[] = {0x4f,0x67,0x67,0x53,0,0x02,
  96935. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  96936. 0x01,0x02,0x03,0x04,0,0,0,0,
  96937. 0xff,0x7b,0x23,0x17,
  96938. 1,
  96939. 0};
  96940. const int head2_5[] = {0x4f,0x67,0x67,0x53,0,0x00,
  96941. 0x07,0xfc,0x03,0x00,0x00,0x00,0x00,0x00,
  96942. 0x01,0x02,0x03,0x04,1,0,0,0,
  96943. 0xed,0x2a,0x2e,0xa7,
  96944. 255,
  96945. 10,10,10,10,10,10,10,10,
  96946. 10,10,10,10,10,10,10,10,
  96947. 10,10,10,10,10,10,10,10,
  96948. 10,10,10,10,10,10,10,10,
  96949. 10,10,10,10,10,10,10,10,
  96950. 10,10,10,10,10,10,10,10,
  96951. 10,10,10,10,10,10,10,10,
  96952. 10,10,10,10,10,10,10,10,
  96953. 10,10,10,10,10,10,10,10,
  96954. 10,10,10,10,10,10,10,10,
  96955. 10,10,10,10,10,10,10,10,
  96956. 10,10,10,10,10,10,10,10,
  96957. 10,10,10,10,10,10,10,10,
  96958. 10,10,10,10,10,10,10,10,
  96959. 10,10,10,10,10,10,10,10,
  96960. 10,10,10,10,10,10,10,10,
  96961. 10,10,10,10,10,10,10,10,
  96962. 10,10,10,10,10,10,10,10,
  96963. 10,10,10,10,10,10,10,10,
  96964. 10,10,10,10,10,10,10,10,
  96965. 10,10,10,10,10,10,10,10,
  96966. 10,10,10,10,10,10,10,10,
  96967. 10,10,10,10,10,10,10,10,
  96968. 10,10,10,10,10,10,10,10,
  96969. 10,10,10,10,10,10,10,10,
  96970. 10,10,10,10,10,10,10,10,
  96971. 10,10,10,10,10,10,10,10,
  96972. 10,10,10,10,10,10,10,10,
  96973. 10,10,10,10,10,10,10,10,
  96974. 10,10,10,10,10,10,10,10,
  96975. 10,10,10,10,10,10,10,10,
  96976. 10,10,10,10,10,10,10};
  96977. const int head3_5[] = {0x4f,0x67,0x67,0x53,0,0x04,
  96978. 0x07,0x00,0x04,0x00,0x00,0x00,0x00,0x00,
  96979. 0x01,0x02,0x03,0x04,2,0,0,0,
  96980. 0x6c,0x3b,0x82,0x3d,
  96981. 1,
  96982. 50};
  96983. const int head1_6[] = {0x4f,0x67,0x67,0x53,0,0x02,
  96984. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  96985. 0x01,0x02,0x03,0x04,0,0,0,0,
  96986. 0xff,0x7b,0x23,0x17,
  96987. 1,
  96988. 0};
  96989. const int head2_6[] = {0x4f,0x67,0x67,0x53,0,0x00,
  96990. 0x07,0x04,0x00,0x00,0x00,0x00,0x00,0x00,
  96991. 0x01,0x02,0x03,0x04,1,0,0,0,
  96992. 0x3c,0xd9,0x4d,0x3f,
  96993. 17,
  96994. 100,255,255,255,255,255,255,255,255,
  96995. 255,255,255,255,255,255,255,255};
  96996. const int head3_6[] = {0x4f,0x67,0x67,0x53,0,0x01,
  96997. 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
  96998. 0x01,0x02,0x03,0x04,2,0,0,0,
  96999. 0x01,0xd2,0xe5,0xe5,
  97000. 17,
  97001. 255,255,255,255,255,255,255,255,
  97002. 255,255,255,255,255,255,255,255,255};
  97003. const int head4_6[] = {0x4f,0x67,0x67,0x53,0,0x05,
  97004. 0x07,0x10,0x00,0x00,0x00,0x00,0x00,0x00,
  97005. 0x01,0x02,0x03,0x04,3,0,0,0,
  97006. 0xef,0xdd,0x88,0xde,
  97007. 7,
  97008. 255,255,75,255,4,255,0};
  97009. const int head1_7[] = {0x4f,0x67,0x67,0x53,0,0x02,
  97010. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  97011. 0x01,0x02,0x03,0x04,0,0,0,0,
  97012. 0xff,0x7b,0x23,0x17,
  97013. 1,
  97014. 0};
  97015. const int head2_7[] = {0x4f,0x67,0x67,0x53,0,0x00,
  97016. 0x07,0x04,0x00,0x00,0x00,0x00,0x00,0x00,
  97017. 0x01,0x02,0x03,0x04,1,0,0,0,
  97018. 0x3c,0xd9,0x4d,0x3f,
  97019. 17,
  97020. 100,255,255,255,255,255,255,255,255,
  97021. 255,255,255,255,255,255,255,255};
  97022. const int head3_7[] = {0x4f,0x67,0x67,0x53,0,0x05,
  97023. 0x07,0x08,0x00,0x00,0x00,0x00,0x00,0x00,
  97024. 0x01,0x02,0x03,0x04,2,0,0,0,
  97025. 0xd4,0xe0,0x60,0xe5,
  97026. 1,0};
  97027. void test_pack(const int *pl, const int **headers, int byteskip,
  97028. int pageskip, int packetskip){
  97029. unsigned char *data=_ogg_malloc(1024*1024); /* for scripted test cases only */
  97030. long inptr=0;
  97031. long outptr=0;
  97032. long deptr=0;
  97033. long depacket=0;
  97034. long granule_pos=7,pageno=0;
  97035. int i,j,packets,pageout=pageskip;
  97036. int eosflag=0;
  97037. int bosflag=0;
  97038. int byteskipcount=0;
  97039. ogg_stream_reset(&os_en);
  97040. ogg_stream_reset(&os_de);
  97041. ogg_sync_reset(&oy);
  97042. for(packets=0;packets<packetskip;packets++)
  97043. depacket+=pl[packets];
  97044. for(packets=0;;packets++)if(pl[packets]==-1)break;
  97045. for(i=0;i<packets;i++){
  97046. ogg_packet op;
  97047. int len=pl[i];
  97048. op.packet=data+inptr;
  97049. op.bytes=len;
  97050. op.e_o_s=(pl[i+1]<0?1:0);
  97051. op.granulepos=granule_pos;
  97052. granule_pos+=1024;
  97053. for(j=0;j<len;j++)data[inptr++]=i+j;
  97054. ogg_stream_packetin(&os_en,&op);
  97055. {
  97056. ogg_page og;
  97057. while(ogg_stream_pageout(&os_en,&og)){
  97058. fprintf(stderr,"%ld, ",pageno);
  97059. if(headers[pageno]==NULL){
  97060. fprintf(stderr,"coded too many pages!\n");
  97061. exit(1);
  97062. }
  97063. check_page(data+outptr,headers[pageno],&og);
  97064. outptr+=og.body_len;
  97065. pageno++;
  97066. if(pageskip){
  97067. bosflag=1;
  97068. pageskip--;
  97069. deptr+=og.body_len;
  97070. }
  97071. {
  97072. ogg_page og_de;
  97073. ogg_packet op_de,op_de2;
  97074. char *buf=ogg_sync_buffer(&oy,og.header_len+og.body_len);
  97075. char *next=buf;
  97076. byteskipcount+=og.header_len;
  97077. if(byteskipcount>byteskip){
  97078. memcpy(next,og.header,byteskipcount-byteskip);
  97079. next+=byteskipcount-byteskip;
  97080. byteskipcount=byteskip;
  97081. }
  97082. byteskipcount+=og.body_len;
  97083. if(byteskipcount>byteskip){
  97084. memcpy(next,og.body,byteskipcount-byteskip);
  97085. next+=byteskipcount-byteskip;
  97086. byteskipcount=byteskip;
  97087. }
  97088. ogg_sync_wrote(&oy,next-buf);
  97089. while(1){
  97090. int ret=ogg_sync_pageout(&oy,&og_de);
  97091. if(ret==0)break;
  97092. if(ret<0)continue;
  97093. fprintf(stderr,"(%ld), ",pageout);
  97094. check_page(data+deptr,headers[pageout],&og_de);
  97095. deptr+=og_de.body_len;
  97096. pageout++;
  97097. ogg_stream_pagein(&os_de,&og_de);
  97098. while(ogg_stream_packetpeek(&os_de,&op_de2)>0){
  97099. ogg_stream_packetpeek(&os_de,NULL);
  97100. ogg_stream_packetout(&os_de,&op_de); /* just catching them all */
  97101. if(memcmp(&op_de,&op_de2,sizeof(op_de))){
  97102. fprintf(stderr,"packetout != packetpeek! pos=%ld\n",
  97103. depacket);
  97104. exit(1);
  97105. }
  97106. if(memcmp(data+depacket,op_de.packet,op_de.bytes)){
  97107. fprintf(stderr,"packet data mismatch in decode! pos=%ld\n",
  97108. depacket);
  97109. exit(1);
  97110. }
  97111. if(bosflag==0 && op_de.b_o_s==0){
  97112. fprintf(stderr,"b_o_s flag not set on packet!\n");
  97113. exit(1);
  97114. }
  97115. if(bosflag && op_de.b_o_s){
  97116. fprintf(stderr,"b_o_s flag incorrectly set on packet!\n");
  97117. exit(1);
  97118. }
  97119. bosflag=1;
  97120. depacket+=op_de.bytes;
  97121. if(eosflag){
  97122. fprintf(stderr,"Multiple decoded packets with eos flag!\n");
  97123. exit(1);
  97124. }
  97125. if(op_de.e_o_s)eosflag=1;
  97126. if(op_de.granulepos!=-1){
  97127. fprintf(stderr," granule:%ld ",(long)op_de.granulepos);
  97128. }
  97129. }
  97130. }
  97131. }
  97132. }
  97133. }
  97134. }
  97135. _ogg_free(data);
  97136. if(headers[pageno]!=NULL){
  97137. fprintf(stderr,"did not write last page!\n");
  97138. exit(1);
  97139. }
  97140. if(headers[pageout]!=NULL){
  97141. fprintf(stderr,"did not decode last page!\n");
  97142. exit(1);
  97143. }
  97144. if(inptr!=outptr){
  97145. fprintf(stderr,"encoded page data incomplete!\n");
  97146. exit(1);
  97147. }
  97148. if(inptr!=deptr){
  97149. fprintf(stderr,"decoded page data incomplete!\n");
  97150. exit(1);
  97151. }
  97152. if(inptr!=depacket){
  97153. fprintf(stderr,"decoded packet data incomplete!\n");
  97154. exit(1);
  97155. }
  97156. if(!eosflag){
  97157. fprintf(stderr,"Never got a packet with EOS set!\n");
  97158. exit(1);
  97159. }
  97160. fprintf(stderr,"ok.\n");
  97161. }
  97162. int main(void){
  97163. ogg_stream_init(&os_en,0x04030201);
  97164. ogg_stream_init(&os_de,0x04030201);
  97165. ogg_sync_init(&oy);
  97166. {
  97167. const int packets[]={17, -1};
  97168. const int *headret[]={head1_0,NULL};
  97169. fprintf(stderr,"testing single page encoding... ");
  97170. test_pack(packets,headret,0,0,0);
  97171. }
  97172. {
  97173. const int packets[]={17, 254, 255, 256, 500, 510, 600, -1};
  97174. const int *headret[]={head1_1,head2_1,NULL};
  97175. fprintf(stderr,"testing basic page encoding... ");
  97176. test_pack(packets,headret,0,0,0);
  97177. }
  97178. {
  97179. const int packets[]={0,17, 254, 255, 0, 256, 0, 500, 510, 600, 0, -1};
  97180. const int *headret[]={head1_2,head2_2,NULL};
  97181. fprintf(stderr,"testing basic nil packets... ");
  97182. test_pack(packets,headret,0,0,0);
  97183. }
  97184. {
  97185. const int packets[]={4345,259,255,-1};
  97186. const int *headret[]={head1_3,head2_3,NULL};
  97187. fprintf(stderr,"testing initial-packet lacing > 4k... ");
  97188. test_pack(packets,headret,0,0,0);
  97189. }
  97190. {
  97191. const int packets[]={0,4345,259,255,-1};
  97192. const int *headret[]={head1_4,head2_4,head3_4,NULL};
  97193. fprintf(stderr,"testing single packet page span... ");
  97194. test_pack(packets,headret,0,0,0);
  97195. }
  97196. {
  97197. const int packets[]={0,10,10,10,10,10,10,10,10,
  97198. 10,10,10,10,10,10,10,10,
  97199. 10,10,10,10,10,10,10,10,
  97200. 10,10,10,10,10,10,10,10,
  97201. 10,10,10,10,10,10,10,10,
  97202. 10,10,10,10,10,10,10,10,
  97203. 10,10,10,10,10,10,10,10,
  97204. 10,10,10,10,10,10,10,10,
  97205. 10,10,10,10,10,10,10,10,
  97206. 10,10,10,10,10,10,10,10,
  97207. 10,10,10,10,10,10,10,10,
  97208. 10,10,10,10,10,10,10,10,
  97209. 10,10,10,10,10,10,10,10,
  97210. 10,10,10,10,10,10,10,10,
  97211. 10,10,10,10,10,10,10,10,
  97212. 10,10,10,10,10,10,10,10,
  97213. 10,10,10,10,10,10,10,10,
  97214. 10,10,10,10,10,10,10,10,
  97215. 10,10,10,10,10,10,10,10,
  97216. 10,10,10,10,10,10,10,10,
  97217. 10,10,10,10,10,10,10,10,
  97218. 10,10,10,10,10,10,10,10,
  97219. 10,10,10,10,10,10,10,10,
  97220. 10,10,10,10,10,10,10,10,
  97221. 10,10,10,10,10,10,10,10,
  97222. 10,10,10,10,10,10,10,10,
  97223. 10,10,10,10,10,10,10,10,
  97224. 10,10,10,10,10,10,10,10,
  97225. 10,10,10,10,10,10,10,10,
  97226. 10,10,10,10,10,10,10,10,
  97227. 10,10,10,10,10,10,10,10,
  97228. 10,10,10,10,10,10,10,50,-1};
  97229. const int *headret[]={head1_5,head2_5,head3_5,NULL};
  97230. fprintf(stderr,"testing max packet segments... ");
  97231. test_pack(packets,headret,0,0,0);
  97232. }
  97233. {
  97234. const int packets[]={0,100,9000,259,255,-1};
  97235. const int *headret[]={head1_6,head2_6,head3_6,head4_6,NULL};
  97236. fprintf(stderr,"testing very large packets... ");
  97237. test_pack(packets,headret,0,0,0);
  97238. }
  97239. {
  97240. const int packets[]={0,100,9000,259,255,-1};
  97241. const int *headret[]={head1_6,head2_6,head3_6,head4_6,NULL};
  97242. fprintf(stderr,"testing continuation resync in very large packets... ");
  97243. test_pack(packets,headret,100,2,3);
  97244. }
  97245. {
  97246. const int packets[]={0,100,4080,-1};
  97247. const int *headret[]={head1_7,head2_7,head3_7,NULL};
  97248. fprintf(stderr,"testing zero data page (1 nil packet)... ");
  97249. test_pack(packets,headret,0,0,0);
  97250. }
  97251. {
  97252. unsigned char *data=_ogg_malloc(1024*1024);
  97253. int pl[]={0,100,4079,2956,2057,76,34,912,0,234,1000,1000,1000,300,-1};
  97254. int inptr=0,i,j;
  97255. ogg_page og[5];
  97256. ogg_stream_reset(&os_en);
  97257. for(i=0;pl[i]!=-1;i++){
  97258. ogg_packet op;
  97259. int len=pl[i];
  97260. op.packet=data+inptr;
  97261. op.bytes=len;
  97262. op.e_o_s=(pl[i+1]<0?1:0);
  97263. op.granulepos=(i+1)*1000;
  97264. for(j=0;j<len;j++)data[inptr++]=i+j;
  97265. ogg_stream_packetin(&os_en,&op);
  97266. }
  97267. _ogg_free(data);
  97268. for(i=0;i<5;i++){
  97269. if(ogg_stream_pageout(&os_en,&og[i])==0){
  97270. fprintf(stderr,"Too few pages output building sync tests!\n");
  97271. exit(1);
  97272. }
  97273. copy_page(&og[i]);
  97274. }
  97275. {
  97276. ogg_page temp;
  97277. ogg_packet test;
  97278. fprintf(stderr,"Testing loss of pages... ");
  97279. ogg_sync_reset(&oy);
  97280. ogg_stream_reset(&os_de);
  97281. for(i=0;i<5;i++){
  97282. memcpy(ogg_sync_buffer(&oy,og[i].header_len),og[i].header,
  97283. og[i].header_len);
  97284. ogg_sync_wrote(&oy,og[i].header_len);
  97285. memcpy(ogg_sync_buffer(&oy,og[i].body_len),og[i].body,og[i].body_len);
  97286. ogg_sync_wrote(&oy,og[i].body_len);
  97287. }
  97288. ogg_sync_pageout(&oy,&temp);
  97289. ogg_stream_pagein(&os_de,&temp);
  97290. ogg_sync_pageout(&oy,&temp);
  97291. ogg_stream_pagein(&os_de,&temp);
  97292. ogg_sync_pageout(&oy,&temp);
  97293. ogg_sync_pageout(&oy,&temp);
  97294. ogg_stream_pagein(&os_de,&temp);
  97295. if(ogg_stream_packetout(&os_de,&test)!=1)error();
  97296. checkpacket(&test,0,0,0);
  97297. if(ogg_stream_packetout(&os_de,&test)!=1)error();
  97298. checkpacket(&test,100,1,-1);
  97299. if(ogg_stream_packetout(&os_de,&test)!=1)error();
  97300. checkpacket(&test,4079,2,3000);
  97301. if(ogg_stream_packetout(&os_de,&test)!=-1){
  97302. fprintf(stderr,"Error: loss of page did not return error\n");
  97303. exit(1);
  97304. }
  97305. if(ogg_stream_packetout(&os_de,&test)!=1)error();
  97306. checkpacket(&test,76,5,-1);
  97307. if(ogg_stream_packetout(&os_de,&test)!=1)error();
  97308. checkpacket(&test,34,6,-1);
  97309. fprintf(stderr,"ok.\n");
  97310. }
  97311. {
  97312. ogg_page temp;
  97313. ogg_packet test;
  97314. fprintf(stderr,"Testing loss of pages (rollback required)... ");
  97315. ogg_sync_reset(&oy);
  97316. ogg_stream_reset(&os_de);
  97317. for(i=0;i<5;i++){
  97318. memcpy(ogg_sync_buffer(&oy,og[i].header_len),og[i].header,
  97319. og[i].header_len);
  97320. ogg_sync_wrote(&oy,og[i].header_len);
  97321. memcpy(ogg_sync_buffer(&oy,og[i].body_len),og[i].body,og[i].body_len);
  97322. ogg_sync_wrote(&oy,og[i].body_len);
  97323. }
  97324. ogg_sync_pageout(&oy,&temp);
  97325. ogg_stream_pagein(&os_de,&temp);
  97326. ogg_sync_pageout(&oy,&temp);
  97327. ogg_stream_pagein(&os_de,&temp);
  97328. ogg_sync_pageout(&oy,&temp);
  97329. ogg_stream_pagein(&os_de,&temp);
  97330. ogg_sync_pageout(&oy,&temp);
  97331. ogg_sync_pageout(&oy,&temp);
  97332. ogg_stream_pagein(&os_de,&temp);
  97333. if(ogg_stream_packetout(&os_de,&test)!=1)error();
  97334. checkpacket(&test,0,0,0);
  97335. if(ogg_stream_packetout(&os_de,&test)!=1)error();
  97336. checkpacket(&test,100,1,-1);
  97337. if(ogg_stream_packetout(&os_de,&test)!=1)error();
  97338. checkpacket(&test,4079,2,3000);
  97339. if(ogg_stream_packetout(&os_de,&test)!=1)error();
  97340. checkpacket(&test,2956,3,4000);
  97341. if(ogg_stream_packetout(&os_de,&test)!=-1){
  97342. fprintf(stderr,"Error: loss of page did not return error\n");
  97343. exit(1);
  97344. }
  97345. if(ogg_stream_packetout(&os_de,&test)!=1)error();
  97346. checkpacket(&test,300,13,14000);
  97347. fprintf(stderr,"ok.\n");
  97348. }
  97349. {
  97350. ogg_page og_de;
  97351. fprintf(stderr,"Testing sync on partial inputs... ");
  97352. ogg_sync_reset(&oy);
  97353. memcpy(ogg_sync_buffer(&oy,og[1].header_len),og[1].header,
  97354. 3);
  97355. ogg_sync_wrote(&oy,3);
  97356. if(ogg_sync_pageout(&oy,&og_de)>0)error();
  97357. memcpy(ogg_sync_buffer(&oy,og[1].header_len),og[1].header+3,
  97358. 20);
  97359. ogg_sync_wrote(&oy,20);
  97360. if(ogg_sync_pageout(&oy,&og_de)>0)error();
  97361. memcpy(ogg_sync_buffer(&oy,og[1].header_len),og[1].header+23,
  97362. 5);
  97363. ogg_sync_wrote(&oy,5);
  97364. if(ogg_sync_pageout(&oy,&og_de)>0)error();
  97365. memcpy(ogg_sync_buffer(&oy,og[1].header_len),og[1].header+28,
  97366. og[1].header_len-28);
  97367. ogg_sync_wrote(&oy,og[1].header_len-28);
  97368. if(ogg_sync_pageout(&oy,&og_de)>0)error();
  97369. memcpy(ogg_sync_buffer(&oy,og[1].body_len),og[1].body,1000);
  97370. ogg_sync_wrote(&oy,1000);
  97371. if(ogg_sync_pageout(&oy,&og_de)>0)error();
  97372. memcpy(ogg_sync_buffer(&oy,og[1].body_len),og[1].body+1000,
  97373. og[1].body_len-1000);
  97374. ogg_sync_wrote(&oy,og[1].body_len-1000);
  97375. if(ogg_sync_pageout(&oy,&og_de)<=0)error();
  97376. fprintf(stderr,"ok.\n");
  97377. }
  97378. {
  97379. ogg_page og_de;
  97380. fprintf(stderr,"Testing sync on 1+partial inputs... ");
  97381. ogg_sync_reset(&oy);
  97382. memcpy(ogg_sync_buffer(&oy,og[1].header_len),og[1].header,
  97383. og[1].header_len);
  97384. ogg_sync_wrote(&oy,og[1].header_len);
  97385. memcpy(ogg_sync_buffer(&oy,og[1].body_len),og[1].body,
  97386. og[1].body_len);
  97387. ogg_sync_wrote(&oy,og[1].body_len);
  97388. memcpy(ogg_sync_buffer(&oy,og[1].header_len),og[1].header,
  97389. 20);
  97390. ogg_sync_wrote(&oy,20);
  97391. if(ogg_sync_pageout(&oy,&og_de)<=0)error();
  97392. if(ogg_sync_pageout(&oy,&og_de)>0)error();
  97393. memcpy(ogg_sync_buffer(&oy,og[1].header_len),og[1].header+20,
  97394. og[1].header_len-20);
  97395. ogg_sync_wrote(&oy,og[1].header_len-20);
  97396. memcpy(ogg_sync_buffer(&oy,og[1].body_len),og[1].body,
  97397. og[1].body_len);
  97398. ogg_sync_wrote(&oy,og[1].body_len);
  97399. if(ogg_sync_pageout(&oy,&og_de)<=0)error();
  97400. fprintf(stderr,"ok.\n");
  97401. }
  97402. {
  97403. ogg_page og_de;
  97404. fprintf(stderr,"Testing search for capture... ");
  97405. ogg_sync_reset(&oy);
  97406. memcpy(ogg_sync_buffer(&oy,og[1].body_len),og[1].body,
  97407. og[1].body_len);
  97408. ogg_sync_wrote(&oy,og[1].body_len);
  97409. memcpy(ogg_sync_buffer(&oy,og[1].header_len),og[1].header,
  97410. og[1].header_len);
  97411. ogg_sync_wrote(&oy,og[1].header_len);
  97412. memcpy(ogg_sync_buffer(&oy,og[1].body_len),og[1].body,
  97413. og[1].body_len);
  97414. ogg_sync_wrote(&oy,og[1].body_len);
  97415. memcpy(ogg_sync_buffer(&oy,og[2].header_len),og[2].header,
  97416. 20);
  97417. ogg_sync_wrote(&oy,20);
  97418. if(ogg_sync_pageout(&oy,&og_de)>0)error();
  97419. if(ogg_sync_pageout(&oy,&og_de)<=0)error();
  97420. if(ogg_sync_pageout(&oy,&og_de)>0)error();
  97421. memcpy(ogg_sync_buffer(&oy,og[2].header_len),og[2].header+20,
  97422. og[2].header_len-20);
  97423. ogg_sync_wrote(&oy,og[2].header_len-20);
  97424. memcpy(ogg_sync_buffer(&oy,og[2].body_len),og[2].body,
  97425. og[2].body_len);
  97426. ogg_sync_wrote(&oy,og[2].body_len);
  97427. if(ogg_sync_pageout(&oy,&og_de)<=0)error();
  97428. fprintf(stderr,"ok.\n");
  97429. }
  97430. {
  97431. ogg_page og_de;
  97432. fprintf(stderr,"Testing recapture... ");
  97433. ogg_sync_reset(&oy);
  97434. memcpy(ogg_sync_buffer(&oy,og[1].header_len),og[1].header,
  97435. og[1].header_len);
  97436. ogg_sync_wrote(&oy,og[1].header_len);
  97437. memcpy(ogg_sync_buffer(&oy,og[1].body_len),og[1].body,
  97438. og[1].body_len);
  97439. ogg_sync_wrote(&oy,og[1].body_len);
  97440. memcpy(ogg_sync_buffer(&oy,og[2].header_len),og[2].header,
  97441. og[2].header_len);
  97442. ogg_sync_wrote(&oy,og[2].header_len);
  97443. memcpy(ogg_sync_buffer(&oy,og[2].header_len),og[2].header,
  97444. og[2].header_len);
  97445. ogg_sync_wrote(&oy,og[2].header_len);
  97446. if(ogg_sync_pageout(&oy,&og_de)<=0)error();
  97447. memcpy(ogg_sync_buffer(&oy,og[2].body_len),og[2].body,
  97448. og[2].body_len-5);
  97449. ogg_sync_wrote(&oy,og[2].body_len-5);
  97450. memcpy(ogg_sync_buffer(&oy,og[3].header_len),og[3].header,
  97451. og[3].header_len);
  97452. ogg_sync_wrote(&oy,og[3].header_len);
  97453. memcpy(ogg_sync_buffer(&oy,og[3].body_len),og[3].body,
  97454. og[3].body_len);
  97455. ogg_sync_wrote(&oy,og[3].body_len);
  97456. if(ogg_sync_pageout(&oy,&og_de)>0)error();
  97457. if(ogg_sync_pageout(&oy,&og_de)<=0)error();
  97458. fprintf(stderr,"ok.\n");
  97459. }
  97460. {
  97461. for(i=0;i<5;i++){
  97462. free_page(&og[i]);
  97463. }
  97464. }
  97465. }
  97466. return(0);
  97467. }
  97468. #endif
  97469. #endif
  97470. /********* End of inlined file: framing.c *********/
  97471. /********* Start of inlined file: analysis.c *********/
  97472. /********* Start of inlined file: juce_OggVorbisHeader.h *********/
  97473. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  97474. // tasks..
  97475. #if JUCE_MSVC
  97476. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  97477. #endif
  97478. /********* End of inlined file: juce_OggVorbisHeader.h *********/
  97479. #if JUCE_USE_OGGVORBIS
  97480. #include <stdio.h>
  97481. #include <string.h>
  97482. #include <math.h>
  97483. /********* Start of inlined file: codec_internal.h *********/
  97484. #ifndef _V_CODECI_H_
  97485. #define _V_CODECI_H_
  97486. /********* Start of inlined file: envelope.h *********/
  97487. #ifndef _V_ENVELOPE_
  97488. #define _V_ENVELOPE_
  97489. /********* Start of inlined file: mdct.h *********/
  97490. #ifndef _OGG_mdct_H_
  97491. #define _OGG_mdct_H_
  97492. #ifdef MDCT_INTEGERIZED
  97493. #define DATA_TYPE int
  97494. #define REG_TYPE register int
  97495. #define TRIGBITS 14
  97496. #define cPI3_8 6270
  97497. #define cPI2_8 11585
  97498. #define cPI1_8 15137
  97499. #define FLOAT_CONV(x) ((int)((x)*(1<<TRIGBITS)+.5))
  97500. #define MULT_NORM(x) ((x)>>TRIGBITS)
  97501. #define HALVE(x) ((x)>>1)
  97502. #else
  97503. #define DATA_TYPE float
  97504. #define REG_TYPE float
  97505. #define cPI3_8 .38268343236508977175F
  97506. #define cPI2_8 .70710678118654752441F
  97507. #define cPI1_8 .92387953251128675613F
  97508. #define FLOAT_CONV(x) (x)
  97509. #define MULT_NORM(x) (x)
  97510. #define HALVE(x) ((x)*.5f)
  97511. #endif
  97512. typedef struct {
  97513. int n;
  97514. int log2n;
  97515. DATA_TYPE *trig;
  97516. int *bitrev;
  97517. DATA_TYPE scale;
  97518. } mdct_lookup;
  97519. extern void mdct_init(mdct_lookup *lookup,int n);
  97520. extern void mdct_clear(mdct_lookup *l);
  97521. extern void mdct_forward(mdct_lookup *init, DATA_TYPE *in, DATA_TYPE *out);
  97522. extern void mdct_backward(mdct_lookup *init, DATA_TYPE *in, DATA_TYPE *out);
  97523. #endif
  97524. /********* End of inlined file: mdct.h *********/
  97525. #define VE_PRE 16
  97526. #define VE_WIN 4
  97527. #define VE_POST 2
  97528. #define VE_AMP (VE_PRE+VE_POST-1)
  97529. #define VE_BANDS 7
  97530. #define VE_NEARDC 15
  97531. #define VE_MINSTRETCH 2 /* a bit less than short block */
  97532. #define VE_MAXSTRETCH 12 /* one-third full block */
  97533. typedef struct {
  97534. float ampbuf[VE_AMP];
  97535. int ampptr;
  97536. float nearDC[VE_NEARDC];
  97537. float nearDC_acc;
  97538. float nearDC_partialacc;
  97539. int nearptr;
  97540. } envelope_filter_state;
  97541. typedef struct {
  97542. int begin;
  97543. int end;
  97544. float *window;
  97545. float total;
  97546. } envelope_band;
  97547. typedef struct {
  97548. int ch;
  97549. int winlength;
  97550. int searchstep;
  97551. float minenergy;
  97552. mdct_lookup mdct;
  97553. float *mdct_win;
  97554. envelope_band band[VE_BANDS];
  97555. envelope_filter_state *filter;
  97556. int stretch;
  97557. int *mark;
  97558. long storage;
  97559. long current;
  97560. long curmark;
  97561. long cursor;
  97562. } envelope_lookup;
  97563. extern void _ve_envelope_init(envelope_lookup *e,vorbis_info *vi);
  97564. extern void _ve_envelope_clear(envelope_lookup *e);
  97565. extern long _ve_envelope_search(vorbis_dsp_state *v);
  97566. extern void _ve_envelope_shift(envelope_lookup *e,long shift);
  97567. extern int _ve_envelope_mark(vorbis_dsp_state *v);
  97568. #endif
  97569. /********* End of inlined file: envelope.h *********/
  97570. /********* Start of inlined file: codebook.h *********/
  97571. #ifndef _V_CODEBOOK_H_
  97572. #define _V_CODEBOOK_H_
  97573. typedef struct static_codebook{
  97574. long dim; /* codebook dimensions (elements per vector) */
  97575. long entries; /* codebook entries */
  97576. long *lengthlist; /* codeword lengths in bits */
  97577. int maptype; /* 0=none
  97578. 1=implicitly populated values from map column
  97579. 2=listed arbitrary values */
  97580. long q_min; /* packed 32 bit float; quant value 0 maps to minval */
  97581. long q_delta; /* packed 32 bit float; val 1 - val 0 == delta */
  97582. int q_quant; /* bits: 0 < quant <= 16 */
  97583. int q_sequencep; /* bitflag */
  97584. long *quantlist; /* map == 1: (int)(entries^(1/dim)) element column map
  97585. map == 2: list of dim*entries quantized entry vals
  97586. */
  97587. struct encode_aux_nearestmatch *nearest_tree;
  97588. struct encode_aux_threshmatch *thresh_tree;
  97589. struct encode_aux_pigeonhole *pigeon_tree;
  97590. int allocedp;
  97591. } static_codebook;
  97592. typedef struct encode_aux_nearestmatch{
  97593. long *ptr0;
  97594. long *ptr1;
  97595. long *p; /* decision points (each is an entry) */
  97596. long *q; /* decision points (each is an entry) */
  97597. long aux; /* number of tree entries */
  97598. long alloc;
  97599. } encode_aux_nearestmatch;
  97600. typedef struct encode_aux_threshmatch{
  97601. float *quantthresh;
  97602. long *quantmap;
  97603. int quantvals;
  97604. int threshvals;
  97605. } encode_aux_threshmatch;
  97606. typedef struct encode_aux_pigeonhole{
  97607. float min;
  97608. float del;
  97609. int mapentries;
  97610. int quantvals;
  97611. long *pigeonmap;
  97612. long fittotal;
  97613. long *fitlist;
  97614. long *fitmap;
  97615. long *fitlength;
  97616. } encode_aux_pigeonhole;
  97617. typedef struct codebook{
  97618. long dim; /* codebook dimensions (elements per vector) */
  97619. long entries; /* codebook entries */
  97620. long used_entries; /* populated codebook entries */
  97621. const static_codebook *c;
  97622. float *valuelist; /* list of dim*entries actual entry values */
  97623. ogg_uint32_t *codelist; /* list of bitstream codewords for each entry */
  97624. int *dec_index; /* only used if sparseness collapsed */
  97625. char *dec_codelengths;
  97626. ogg_uint32_t *dec_firsttable;
  97627. int dec_firsttablen;
  97628. int dec_maxlength;
  97629. } codebook;
  97630. extern void vorbis_staticbook_clear(static_codebook *b);
  97631. extern void vorbis_staticbook_destroy(static_codebook *b);
  97632. extern int vorbis_book_init_encode(codebook *dest,const static_codebook *source);
  97633. extern int vorbis_book_init_decode(codebook *dest,const static_codebook *source);
  97634. extern void vorbis_book_clear(codebook *b);
  97635. extern float *_book_unquantize(const static_codebook *b,int n,int *map);
  97636. extern float *_book_logdist(const static_codebook *b,float *vals);
  97637. extern float _float32_unpack(long val);
  97638. extern long _float32_pack(float val);
  97639. extern int _best(codebook *book, float *a, int step);
  97640. extern int _ilog(unsigned int v);
  97641. extern long _book_maptype1_quantvals(const static_codebook *b);
  97642. extern int vorbis_book_besterror(codebook *book,float *a,int step,int addmul);
  97643. extern long vorbis_book_codeword(codebook *book,int entry);
  97644. extern long vorbis_book_codelen(codebook *book,int entry);
  97645. extern int vorbis_staticbook_pack(const static_codebook *c,oggpack_buffer *b);
  97646. extern int vorbis_staticbook_unpack(oggpack_buffer *b,static_codebook *c);
  97647. extern int vorbis_book_encode(codebook *book, int a, oggpack_buffer *b);
  97648. extern int vorbis_book_errorv(codebook *book, float *a);
  97649. extern int vorbis_book_encodev(codebook *book, int best,float *a,
  97650. oggpack_buffer *b);
  97651. extern long vorbis_book_decode(codebook *book, oggpack_buffer *b);
  97652. extern long vorbis_book_decodevs_add(codebook *book, float *a,
  97653. oggpack_buffer *b,int n);
  97654. extern long vorbis_book_decodev_set(codebook *book, float *a,
  97655. oggpack_buffer *b,int n);
  97656. extern long vorbis_book_decodev_add(codebook *book, float *a,
  97657. oggpack_buffer *b,int n);
  97658. extern long vorbis_book_decodevv_add(codebook *book, float **a,
  97659. long off,int ch,
  97660. oggpack_buffer *b,int n);
  97661. #endif
  97662. /********* End of inlined file: codebook.h *********/
  97663. #define BLOCKTYPE_IMPULSE 0
  97664. #define BLOCKTYPE_PADDING 1
  97665. #define BLOCKTYPE_TRANSITION 0
  97666. #define BLOCKTYPE_LONG 1
  97667. #define PACKETBLOBS 15
  97668. typedef struct vorbis_block_internal{
  97669. float **pcmdelay; /* this is a pointer into local storage */
  97670. float ampmax;
  97671. int blocktype;
  97672. oggpack_buffer *packetblob[PACKETBLOBS]; /* initialized, must be freed;
  97673. blob [PACKETBLOBS/2] points to
  97674. the oggpack_buffer in the
  97675. main vorbis_block */
  97676. } vorbis_block_internal;
  97677. typedef void vorbis_look_floor;
  97678. typedef void vorbis_look_residue;
  97679. typedef void vorbis_look_transform;
  97680. typedef struct {
  97681. int blockflag;
  97682. int windowtype;
  97683. int transformtype;
  97684. int mapping;
  97685. } vorbis_info_mode;
  97686. typedef void vorbis_info_floor;
  97687. typedef void vorbis_info_residue;
  97688. typedef void vorbis_info_mapping;
  97689. /********* Start of inlined file: psy.h *********/
  97690. #ifndef _V_PSY_H_
  97691. #define _V_PSY_H_
  97692. /********* Start of inlined file: smallft.h *********/
  97693. #ifndef _V_SMFT_H_
  97694. #define _V_SMFT_H_
  97695. typedef struct {
  97696. int n;
  97697. float *trigcache;
  97698. int *splitcache;
  97699. } drft_lookup;
  97700. extern void drft_forward(drft_lookup *l,float *data);
  97701. extern void drft_backward(drft_lookup *l,float *data);
  97702. extern void drft_init(drft_lookup *l,int n);
  97703. extern void drft_clear(drft_lookup *l);
  97704. #endif
  97705. /********* End of inlined file: smallft.h *********/
  97706. /********* Start of inlined file: backends.h *********/
  97707. #ifndef _vorbis_backend_h_
  97708. #define _vorbis_backend_h_
  97709. typedef struct{
  97710. void (*pack) (vorbis_info_floor *,oggpack_buffer *);
  97711. vorbis_info_floor *(*unpack)(vorbis_info *,oggpack_buffer *);
  97712. vorbis_look_floor *(*look) (vorbis_dsp_state *,vorbis_info_floor *);
  97713. void (*free_info) (vorbis_info_floor *);
  97714. void (*free_look) (vorbis_look_floor *);
  97715. void *(*inverse1) (struct vorbis_block *,vorbis_look_floor *);
  97716. int (*inverse2) (struct vorbis_block *,vorbis_look_floor *,
  97717. void *buffer,float *);
  97718. } vorbis_func_floor;
  97719. typedef struct{
  97720. int order;
  97721. long rate;
  97722. long barkmap;
  97723. int ampbits;
  97724. int ampdB;
  97725. int numbooks; /* <= 16 */
  97726. int books[16];
  97727. float lessthan; /* encode-only config setting hacks for libvorbis */
  97728. float greaterthan; /* encode-only config setting hacks for libvorbis */
  97729. } vorbis_info_floor0;
  97730. #define VIF_POSIT 63
  97731. #define VIF_CLASS 16
  97732. #define VIF_PARTS 31
  97733. typedef struct{
  97734. int partitions; /* 0 to 31 */
  97735. int partitionclass[VIF_PARTS]; /* 0 to 15 */
  97736. int class_dim[VIF_CLASS]; /* 1 to 8 */
  97737. int class_subs[VIF_CLASS]; /* 0,1,2,3 (bits: 1<<n poss) */
  97738. int class_book[VIF_CLASS]; /* subs ^ dim entries */
  97739. int class_subbook[VIF_CLASS][8]; /* [VIF_CLASS][subs] */
  97740. int mult; /* 1 2 3 or 4 */
  97741. int postlist[VIF_POSIT+2]; /* first two implicit */
  97742. float maxover;
  97743. float maxunder;
  97744. float maxerr;
  97745. float twofitweight;
  97746. float twofitatten;
  97747. int n;
  97748. } vorbis_info_floor1;
  97749. typedef struct{
  97750. void (*pack) (vorbis_info_residue *,oggpack_buffer *);
  97751. vorbis_info_residue *(*unpack)(vorbis_info *,oggpack_buffer *);
  97752. vorbis_look_residue *(*look) (vorbis_dsp_state *,
  97753. vorbis_info_residue *);
  97754. void (*free_info) (vorbis_info_residue *);
  97755. void (*free_look) (vorbis_look_residue *);
  97756. long **(*classx) (struct vorbis_block *,vorbis_look_residue *,
  97757. float **,int *,int);
  97758. int (*forward) (oggpack_buffer *,struct vorbis_block *,
  97759. vorbis_look_residue *,
  97760. float **,float **,int *,int,long **);
  97761. int (*inverse) (struct vorbis_block *,vorbis_look_residue *,
  97762. float **,int *,int);
  97763. } vorbis_func_residue;
  97764. typedef struct vorbis_info_residue0{
  97765. long begin;
  97766. long end;
  97767. int grouping; /* group n vectors per partition */
  97768. int partitions; /* possible codebooks for a partition */
  97769. int groupbook; /* huffbook for partitioning */
  97770. int secondstages[64]; /* expanded out to pointers in lookup */
  97771. int booklist[256]; /* list of second stage books */
  97772. float classmetric1[64];
  97773. float classmetric2[64];
  97774. } vorbis_info_residue0;
  97775. typedef struct{
  97776. void (*pack) (vorbis_info *,vorbis_info_mapping *,
  97777. oggpack_buffer *);
  97778. vorbis_info_mapping *(*unpack)(vorbis_info *,oggpack_buffer *);
  97779. void (*free_info) (vorbis_info_mapping *);
  97780. int (*forward) (struct vorbis_block *vb);
  97781. int (*inverse) (struct vorbis_block *vb,vorbis_info_mapping *);
  97782. } vorbis_func_mapping;
  97783. typedef struct vorbis_info_mapping0{
  97784. int submaps; /* <= 16 */
  97785. int chmuxlist[256]; /* up to 256 channels in a Vorbis stream */
  97786. int floorsubmap[16]; /* [mux] submap to floors */
  97787. int residuesubmap[16]; /* [mux] submap to residue */
  97788. int coupling_steps;
  97789. int coupling_mag[256];
  97790. int coupling_ang[256];
  97791. } vorbis_info_mapping0;
  97792. #endif
  97793. /********* End of inlined file: backends.h *********/
  97794. #ifndef EHMER_MAX
  97795. #define EHMER_MAX 56
  97796. #endif
  97797. #define P_BANDS 17 /* 62Hz to 16kHz */
  97798. #define P_LEVELS 8 /* 30dB to 100dB */
  97799. #define P_LEVEL_0 30. /* 30 dB */
  97800. #define P_NOISECURVES 3
  97801. #define NOISE_COMPAND_LEVELS 40
  97802. typedef struct vorbis_info_psy{
  97803. int blockflag;
  97804. float ath_adjatt;
  97805. float ath_maxatt;
  97806. float tone_masteratt[P_NOISECURVES];
  97807. float tone_centerboost;
  97808. float tone_decay;
  97809. float tone_abs_limit;
  97810. float toneatt[P_BANDS];
  97811. int noisemaskp;
  97812. float noisemaxsupp;
  97813. float noisewindowlo;
  97814. float noisewindowhi;
  97815. int noisewindowlomin;
  97816. int noisewindowhimin;
  97817. int noisewindowfixed;
  97818. float noiseoff[P_NOISECURVES][P_BANDS];
  97819. float noisecompand[NOISE_COMPAND_LEVELS];
  97820. float max_curve_dB;
  97821. int normal_channel_p;
  97822. int normal_point_p;
  97823. int normal_start;
  97824. int normal_partition;
  97825. double normal_thresh;
  97826. } vorbis_info_psy;
  97827. typedef struct{
  97828. int eighth_octave_lines;
  97829. float preecho_thresh[VE_BANDS];
  97830. float postecho_thresh[VE_BANDS];
  97831. float stretch_penalty;
  97832. float preecho_minenergy;
  97833. float ampmax_att_per_sec;
  97834. int coupling_pkHz[PACKETBLOBS];
  97835. int coupling_pointlimit[2][PACKETBLOBS];
  97836. int coupling_prepointamp[PACKETBLOBS];
  97837. int coupling_postpointamp[PACKETBLOBS];
  97838. int sliding_lowpass[2][PACKETBLOBS];
  97839. } vorbis_info_psy_global;
  97840. typedef struct {
  97841. float ampmax;
  97842. int channels;
  97843. vorbis_info_psy_global *gi;
  97844. int coupling_pointlimit[2][P_NOISECURVES];
  97845. } vorbis_look_psy_global;
  97846. typedef struct {
  97847. int n;
  97848. struct vorbis_info_psy *vi;
  97849. float ***tonecurves;
  97850. float **noiseoffset;
  97851. float *ath;
  97852. long *octave; /* in n.ocshift format */
  97853. long *bark;
  97854. long firstoc;
  97855. long shiftoc;
  97856. int eighth_octave_lines; /* power of two, please */
  97857. int total_octave_lines;
  97858. long rate; /* cache it */
  97859. float m_val; /* Masking compensation value */
  97860. } vorbis_look_psy;
  97861. extern void _vp_psy_init(vorbis_look_psy *p,vorbis_info_psy *vi,
  97862. vorbis_info_psy_global *gi,int n,long rate);
  97863. extern void _vp_psy_clear(vorbis_look_psy *p);
  97864. extern void *_vi_psy_dup(void *source);
  97865. extern void _vi_psy_free(vorbis_info_psy *i);
  97866. extern vorbis_info_psy *_vi_psy_copy(vorbis_info_psy *i);
  97867. extern void _vp_remove_floor(vorbis_look_psy *p,
  97868. float *mdct,
  97869. int *icodedflr,
  97870. float *residue,
  97871. int sliding_lowpass);
  97872. extern void _vp_noisemask(vorbis_look_psy *p,
  97873. float *logmdct,
  97874. float *logmask);
  97875. extern void _vp_tonemask(vorbis_look_psy *p,
  97876. float *logfft,
  97877. float *logmask,
  97878. float global_specmax,
  97879. float local_specmax);
  97880. extern void _vp_offset_and_mix(vorbis_look_psy *p,
  97881. float *noise,
  97882. float *tone,
  97883. int offset_select,
  97884. float *logmask,
  97885. float *mdct,
  97886. float *logmdct);
  97887. extern float _vp_ampmax_decay(float amp,vorbis_dsp_state *vd);
  97888. extern float **_vp_quantize_couple_memo(vorbis_block *vb,
  97889. vorbis_info_psy_global *g,
  97890. vorbis_look_psy *p,
  97891. vorbis_info_mapping0 *vi,
  97892. float **mdct);
  97893. extern void _vp_couple(int blobno,
  97894. vorbis_info_psy_global *g,
  97895. vorbis_look_psy *p,
  97896. vorbis_info_mapping0 *vi,
  97897. float **res,
  97898. float **mag_memo,
  97899. int **mag_sort,
  97900. int **ifloor,
  97901. int *nonzero,
  97902. int sliding_lowpass);
  97903. extern void _vp_noise_normalize(vorbis_look_psy *p,
  97904. float *in,float *out,int *sortedindex);
  97905. extern void _vp_noise_normalize_sort(vorbis_look_psy *p,
  97906. float *magnitudes,int *sortedindex);
  97907. extern int **_vp_quantize_couple_sort(vorbis_block *vb,
  97908. vorbis_look_psy *p,
  97909. vorbis_info_mapping0 *vi,
  97910. float **mags);
  97911. extern void hf_reduction(vorbis_info_psy_global *g,
  97912. vorbis_look_psy *p,
  97913. vorbis_info_mapping0 *vi,
  97914. float **mdct);
  97915. #endif
  97916. /********* End of inlined file: psy.h *********/
  97917. /********* Start of inlined file: bitrate.h *********/
  97918. #ifndef _V_BITRATE_H_
  97919. #define _V_BITRATE_H_
  97920. /********* Start of inlined file: os.h *********/
  97921. #ifndef _OS_H
  97922. #define _OS_H
  97923. #ifdef HAVE_CONFIG_H
  97924. #include "config.h"
  97925. #endif
  97926. #include <math.h>
  97927. /********* Start of inlined file: misc.h *********/
  97928. #ifndef _V_RANDOM_H_
  97929. #define _V_RANDOM_H_
  97930. extern int analysis_noisy;
  97931. extern void *_vorbis_block_alloc(vorbis_block *vb,long bytes);
  97932. extern void _vorbis_block_ripcord(vorbis_block *vb);
  97933. extern void _analysis_output(char *base,int i,float *v,int n,int bark,int dB,
  97934. ogg_int64_t off);
  97935. #ifdef DEBUG_MALLOC
  97936. #define _VDBG_GRAPHFILE "malloc.m"
  97937. extern void *_VDBG_malloc(void *ptr,long bytes,char *file,long line);
  97938. extern void _VDBG_free(void *ptr,char *file,long line);
  97939. #ifndef MISC_C
  97940. #undef _ogg_malloc
  97941. #undef _ogg_calloc
  97942. #undef _ogg_realloc
  97943. #undef _ogg_free
  97944. #define _ogg_malloc(x) _VDBG_malloc(NULL,(x),__FILE__,__LINE__)
  97945. #define _ogg_calloc(x,y) _VDBG_malloc(NULL,(x)*(y),__FILE__,__LINE__)
  97946. #define _ogg_realloc(x,y) _VDBG_malloc((x),(y),__FILE__,__LINE__)
  97947. #define _ogg_free(x) _VDBG_free((x),__FILE__,__LINE__)
  97948. #endif
  97949. #endif
  97950. #endif
  97951. /********* End of inlined file: misc.h *********/
  97952. #ifndef _V_IFDEFJAIL_H_
  97953. # define _V_IFDEFJAIL_H_
  97954. # ifdef __GNUC__
  97955. # define STIN static __inline__
  97956. # elif _WIN32
  97957. # define STIN static __inline
  97958. # else
  97959. # define STIN static
  97960. # endif
  97961. #ifdef DJGPP
  97962. # define rint(x) (floor((x)+0.5f))
  97963. #endif
  97964. #ifndef M_PI
  97965. # define M_PI (3.1415926536f)
  97966. #endif
  97967. #if defined(_WIN32) && !defined(__SYMBIAN32__)
  97968. # include <malloc.h>
  97969. # define rint(x) (floor((x)+0.5f))
  97970. # define NO_FLOAT_MATH_LIB
  97971. # define FAST_HYPOT(a, b) sqrt((a)*(a) + (b)*(b))
  97972. #endif
  97973. #if defined(__SYMBIAN32__) && defined(__WINS__)
  97974. void *_alloca(size_t size);
  97975. # define alloca _alloca
  97976. #endif
  97977. #ifndef FAST_HYPOT
  97978. # define FAST_HYPOT hypot
  97979. #endif
  97980. #endif
  97981. #ifdef HAVE_ALLOCA_H
  97982. # include <alloca.h>
  97983. #endif
  97984. #ifdef USE_MEMORY_H
  97985. # include <memory.h>
  97986. #endif
  97987. #ifndef min
  97988. # define min(x,y) ((x)>(y)?(y):(x))
  97989. #endif
  97990. #ifndef max
  97991. # define max(x,y) ((x)<(y)?(y):(x))
  97992. #endif
  97993. #if defined(__i386__) && defined(__GNUC__) && !defined(__BEOS__)
  97994. # define VORBIS_FPU_CONTROL
  97995. typedef ogg_int16_t vorbis_fpu_control;
  97996. static inline void vorbis_fpu_setround(vorbis_fpu_control *fpu){
  97997. ogg_int16_t ret;
  97998. ogg_int16_t temp;
  97999. __asm__ __volatile__("fnstcw %0\n\t"
  98000. "movw %0,%%dx\n\t"
  98001. "orw $62463,%%dx\n\t"
  98002. "movw %%dx,%1\n\t"
  98003. "fldcw %1\n\t":"=m"(ret):"m"(temp): "dx");
  98004. *fpu=ret;
  98005. }
  98006. static inline void vorbis_fpu_restore(vorbis_fpu_control fpu){
  98007. __asm__ __volatile__("fldcw %0":: "m"(fpu));
  98008. }
  98009. static inline int vorbis_ftoi(double f){ /* yes, double! Otherwise,
  98010. we get extra fst/fld to
  98011. truncate precision */
  98012. int i;
  98013. __asm__("fistl %0": "=m"(i) : "t"(f));
  98014. return(i);
  98015. }
  98016. #endif
  98017. #if defined(_WIN32) && defined(_X86_) && !defined(__GNUC__) && !defined(__BORLANDC__)
  98018. # define VORBIS_FPU_CONTROL
  98019. typedef ogg_int16_t vorbis_fpu_control;
  98020. static __inline int vorbis_ftoi(double f){
  98021. int i;
  98022. __asm{
  98023. fld f
  98024. fistp i
  98025. }
  98026. return i;
  98027. }
  98028. static __inline void vorbis_fpu_setround(vorbis_fpu_control *fpu){
  98029. }
  98030. static __inline void vorbis_fpu_restore(vorbis_fpu_control fpu){
  98031. }
  98032. #endif
  98033. #ifndef VORBIS_FPU_CONTROL
  98034. typedef int vorbis_fpu_control;
  98035. static int vorbis_ftoi(double f){
  98036. return (int)(f+.5);
  98037. }
  98038. # define vorbis_fpu_setround(vorbis_fpu_control) {}
  98039. # define vorbis_fpu_restore(vorbis_fpu_control) {}
  98040. #endif
  98041. #endif /* _OS_H */
  98042. /********* End of inlined file: os.h *********/
  98043. typedef struct bitrate_manager_state {
  98044. int managed;
  98045. long avg_reservoir;
  98046. long minmax_reservoir;
  98047. long avg_bitsper;
  98048. long min_bitsper;
  98049. long max_bitsper;
  98050. long short_per_long;
  98051. double avgfloat;
  98052. vorbis_block *vb;
  98053. int choice;
  98054. } bitrate_manager_state;
  98055. typedef struct bitrate_manager_info{
  98056. long avg_rate;
  98057. long min_rate;
  98058. long max_rate;
  98059. long reservoir_bits;
  98060. double reservoir_bias;
  98061. double slew_damp;
  98062. } bitrate_manager_info;
  98063. extern void vorbis_bitrate_init(vorbis_info *vi,bitrate_manager_state *bs);
  98064. extern void vorbis_bitrate_clear(bitrate_manager_state *bs);
  98065. extern int vorbis_bitrate_managed(vorbis_block *vb);
  98066. extern int vorbis_bitrate_addblock(vorbis_block *vb);
  98067. extern int vorbis_bitrate_flushpacket(vorbis_dsp_state *vd, ogg_packet *op);
  98068. #endif
  98069. /********* End of inlined file: bitrate.h *********/
  98070. static int ilog(unsigned int v){
  98071. int ret=0;
  98072. while(v){
  98073. ret++;
  98074. v>>=1;
  98075. }
  98076. return(ret);
  98077. }
  98078. static int ilog2(unsigned int v){
  98079. int ret=0;
  98080. if(v)--v;
  98081. while(v){
  98082. ret++;
  98083. v>>=1;
  98084. }
  98085. return(ret);
  98086. }
  98087. typedef struct private_state {
  98088. envelope_lookup *ve; /* envelope lookup */
  98089. int window[2];
  98090. vorbis_look_transform **transform[2]; /* block, type */
  98091. drft_lookup fft_look[2];
  98092. int modebits;
  98093. vorbis_look_floor **flr;
  98094. vorbis_look_residue **residue;
  98095. vorbis_look_psy *psy;
  98096. vorbis_look_psy_global *psy_g_look;
  98097. unsigned char *header;
  98098. unsigned char *header1;
  98099. unsigned char *header2;
  98100. bitrate_manager_state bms;
  98101. ogg_int64_t sample_count;
  98102. } private_state;
  98103. /********* Start of inlined file: highlevel.h *********/
  98104. typedef struct highlevel_byblocktype {
  98105. double tone_mask_setting;
  98106. double tone_peaklimit_setting;
  98107. double noise_bias_setting;
  98108. double noise_compand_setting;
  98109. } highlevel_byblocktype;
  98110. typedef struct highlevel_encode_setup {
  98111. void *setup;
  98112. int set_in_stone;
  98113. double base_setting;
  98114. double long_setting;
  98115. double short_setting;
  98116. double impulse_noisetune;
  98117. int managed;
  98118. long bitrate_min;
  98119. long bitrate_av;
  98120. double bitrate_av_damp;
  98121. long bitrate_max;
  98122. long bitrate_reservoir;
  98123. double bitrate_reservoir_bias;
  98124. int impulse_block_p;
  98125. int noise_normalize_p;
  98126. double stereo_point_setting;
  98127. double lowpass_kHz;
  98128. double ath_floating_dB;
  98129. double ath_absolute_dB;
  98130. double amplitude_track_dBpersec;
  98131. double trigger_setting;
  98132. highlevel_byblocktype block[4]; /* padding, impulse, transition, long */
  98133. } highlevel_encode_setup;
  98134. /********* End of inlined file: highlevel.h *********/
  98135. typedef struct codec_setup_info {
  98136. long blocksizes[2];
  98137. int modes;
  98138. int maps;
  98139. int floors;
  98140. int residues;
  98141. int books;
  98142. int psys; /* encode only */
  98143. vorbis_info_mode *mode_param[64];
  98144. int map_type[64];
  98145. vorbis_info_mapping *map_param[64];
  98146. int floor_type[64];
  98147. vorbis_info_floor *floor_param[64];
  98148. int residue_type[64];
  98149. vorbis_info_residue *residue_param[64];
  98150. static_codebook *book_param[256];
  98151. codebook *fullbooks;
  98152. vorbis_info_psy *psy_param[4]; /* encode only */
  98153. vorbis_info_psy_global psy_g_param;
  98154. bitrate_manager_info bi;
  98155. highlevel_encode_setup hi; /* used only by vorbisenc.c. It's a
  98156. highly redundant structure, but
  98157. improves clarity of program flow. */
  98158. int halfrate_flag; /* painless downsample for decode */
  98159. } codec_setup_info;
  98160. extern vorbis_look_psy_global *_vp_global_look(vorbis_info *vi);
  98161. extern void _vp_global_free(vorbis_look_psy_global *look);
  98162. #endif
  98163. /********* End of inlined file: codec_internal.h *********/
  98164. /********* Start of inlined file: registry.h *********/
  98165. #ifndef _V_REG_H_
  98166. #define _V_REG_H_
  98167. #define VI_TRANSFORMB 1
  98168. #define VI_WINDOWB 1
  98169. #define VI_TIMEB 1
  98170. #define VI_FLOORB 2
  98171. #define VI_RESB 3
  98172. #define VI_MAPB 1
  98173. extern vorbis_func_floor *_floor_P[];
  98174. extern vorbis_func_residue *_residue_P[];
  98175. extern vorbis_func_mapping *_mapping_P[];
  98176. #endif
  98177. /********* End of inlined file: registry.h *********/
  98178. /********* Start of inlined file: scales.h *********/
  98179. #ifndef _V_SCALES_H_
  98180. #define _V_SCALES_H_
  98181. #include <math.h>
  98182. #define VORBIS_IEEE_FLOAT32 1
  98183. #ifdef VORBIS_IEEE_FLOAT32
  98184. static float unitnorm(float x){
  98185. union {
  98186. ogg_uint32_t i;
  98187. float f;
  98188. } ix;
  98189. ix.f = x;
  98190. ix.i = (ix.i & 0x80000000U) | (0x3f800000U);
  98191. return ix.f;
  98192. }
  98193. static float todB(const float *x){
  98194. union {
  98195. ogg_uint32_t i;
  98196. float f;
  98197. } ix;
  98198. ix.f = *x;
  98199. ix.i = ix.i&0x7fffffff;
  98200. return (float)(ix.i * 7.17711438e-7f -764.6161886f);
  98201. }
  98202. #define todB_nn(x) todB(x)
  98203. #else
  98204. static float unitnorm(float x){
  98205. if(x<0)return(-1.f);
  98206. return(1.f);
  98207. }
  98208. #define todB(x) (*(x)==0?-400.f:log(*(x)**(x))*4.34294480f)
  98209. #define todB_nn(x) (*(x)==0.f?-400.f:log(*(x))*8.6858896f)
  98210. #endif
  98211. #define fromdB(x) (exp((x)*.11512925f))
  98212. #define toBARK(n) (13.1f*atan(.00074f*(n))+2.24f*atan((n)*(n)*1.85e-8f)+1e-4f*(n))
  98213. #define fromBARK(z) (102.f*(z)-2.f*pow(z,2.f)+.4f*pow(z,3.f)+pow(1.46f,z)-1.f)
  98214. #define toMEL(n) (log(1.f+(n)*.001f)*1442.695f)
  98215. #define fromMEL(m) (1000.f*exp((m)/1442.695f)-1000.f)
  98216. #define toOC(n) (log(n)*1.442695f-5.965784f)
  98217. #define fromOC(o) (exp(((o)+5.965784f)*.693147f))
  98218. #endif
  98219. /********* End of inlined file: scales.h *********/
  98220. int analysis_noisy=1;
  98221. int vorbis_analysis(vorbis_block *vb, ogg_packet *op){
  98222. int ret,i;
  98223. vorbis_block_internal *vbi=(vorbis_block_internal *)vb->internal;
  98224. vb->glue_bits=0;
  98225. vb->time_bits=0;
  98226. vb->floor_bits=0;
  98227. vb->res_bits=0;
  98228. for(i=0;i<PACKETBLOBS;i++)
  98229. oggpack_reset(vbi->packetblob[i]);
  98230. if((ret=_mapping_P[0]->forward(vb)))
  98231. return(ret);
  98232. if(op){
  98233. if(vorbis_bitrate_managed(vb))
  98234. return(OV_EINVAL);
  98235. op->packet=oggpack_get_buffer(&vb->opb);
  98236. op->bytes=oggpack_bytes(&vb->opb);
  98237. op->b_o_s=0;
  98238. op->e_o_s=vb->eofflag;
  98239. op->granulepos=vb->granulepos;
  98240. op->packetno=vb->sequence; /* for sake of completeness */
  98241. }
  98242. return(0);
  98243. }
  98244. void _analysis_output_always(const char *base,int i,float *v,int n,int bark,int dB,ogg_int64_t off){
  98245. int j;
  98246. FILE *of;
  98247. char buffer[80];
  98248. sprintf(buffer,"%s_%d.m",base,i);
  98249. of=fopen(buffer,"w");
  98250. if(!of)perror("failed to open data dump file");
  98251. for(j=0;j<n;j++){
  98252. if(bark){
  98253. float b=toBARK((4000.f*j/n)+.25);
  98254. fprintf(of,"%f ",b);
  98255. }else
  98256. if(off!=0)
  98257. fprintf(of,"%f ",(double)(j+off)/8000.);
  98258. else
  98259. fprintf(of,"%f ",(double)j);
  98260. if(dB){
  98261. float val;
  98262. if(v[j]==0.)
  98263. val=-140.;
  98264. else
  98265. val=todB(v+j);
  98266. fprintf(of,"%f\n",val);
  98267. }else{
  98268. fprintf(of,"%f\n",v[j]);
  98269. }
  98270. }
  98271. fclose(of);
  98272. }
  98273. void _analysis_output(char *base,int i,float *v,int n,int bark,int dB,
  98274. ogg_int64_t off){
  98275. if(analysis_noisy)_analysis_output_always(base,i,v,n,bark,dB,off);
  98276. }
  98277. #endif
  98278. /********* End of inlined file: analysis.c *********/
  98279. /********* Start of inlined file: bitrate.c *********/
  98280. /********* Start of inlined file: juce_OggVorbisHeader.h *********/
  98281. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  98282. // tasks..
  98283. #if JUCE_MSVC
  98284. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  98285. #endif
  98286. /********* End of inlined file: juce_OggVorbisHeader.h *********/
  98287. #if JUCE_USE_OGGVORBIS
  98288. #include <stdlib.h>
  98289. #include <string.h>
  98290. #include <math.h>
  98291. void vorbis_bitrate_init(vorbis_info *vi,bitrate_manager_state *bm){
  98292. codec_setup_info *ci=(codec_setup_info *)vi->codec_setup;
  98293. bitrate_manager_info *bi=&ci->bi;
  98294. memset(bm,0,sizeof(*bm));
  98295. if(bi && (bi->reservoir_bits>0)){
  98296. long ratesamples=vi->rate;
  98297. int halfsamples=ci->blocksizes[0]>>1;
  98298. bm->short_per_long=ci->blocksizes[1]/ci->blocksizes[0];
  98299. bm->managed=1;
  98300. bm->avg_bitsper= rint(1.*bi->avg_rate*halfsamples/ratesamples);
  98301. bm->min_bitsper= rint(1.*bi->min_rate*halfsamples/ratesamples);
  98302. bm->max_bitsper= rint(1.*bi->max_rate*halfsamples/ratesamples);
  98303. bm->avgfloat=PACKETBLOBS/2;
  98304. {
  98305. long desired_fill=bi->reservoir_bits*bi->reservoir_bias;
  98306. bm->minmax_reservoir=desired_fill;
  98307. bm->avg_reservoir=desired_fill;
  98308. }
  98309. }
  98310. }
  98311. void vorbis_bitrate_clear(bitrate_manager_state *bm){
  98312. memset(bm,0,sizeof(*bm));
  98313. return;
  98314. }
  98315. int vorbis_bitrate_managed(vorbis_block *vb){
  98316. vorbis_dsp_state *vd=vb->vd;
  98317. private_state *b=(private_state*)vd->backend_state;
  98318. bitrate_manager_state *bm=&b->bms;
  98319. if(bm && bm->managed)return(1);
  98320. return(0);
  98321. }
  98322. int vorbis_bitrate_addblock(vorbis_block *vb){
  98323. vorbis_block_internal *vbi=(vorbis_block_internal*)vb->internal;
  98324. vorbis_dsp_state *vd=vb->vd;
  98325. private_state *b=(private_state*)vd->backend_state;
  98326. bitrate_manager_state *bm=&b->bms;
  98327. vorbis_info *vi=vd->vi;
  98328. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  98329. bitrate_manager_info *bi=&ci->bi;
  98330. int choice=rint(bm->avgfloat);
  98331. long this_bits=oggpack_bytes(vbi->packetblob[choice])*8;
  98332. long min_target_bits=(vb->W?bm->min_bitsper*bm->short_per_long:bm->min_bitsper);
  98333. long max_target_bits=(vb->W?bm->max_bitsper*bm->short_per_long:bm->max_bitsper);
  98334. int samples=ci->blocksizes[vb->W]>>1;
  98335. long desired_fill=bi->reservoir_bits*bi->reservoir_bias;
  98336. if(!bm->managed){
  98337. if(bm->vb)return(-1); /* one has been submitted without
  98338. being claimed */
  98339. bm->vb=vb;
  98340. return(0);
  98341. }
  98342. bm->vb=vb;
  98343. if(bm->avg_bitsper>0){
  98344. double slew=0.;
  98345. long avg_target_bits=(vb->W?bm->avg_bitsper*bm->short_per_long:bm->avg_bitsper);
  98346. double slewlimit= 15./bi->slew_damp;
  98347. if(bm->avg_reservoir+(this_bits-avg_target_bits)>desired_fill){
  98348. while(choice>0 && this_bits>avg_target_bits &&
  98349. bm->avg_reservoir+(this_bits-avg_target_bits)>desired_fill){
  98350. choice--;
  98351. this_bits=oggpack_bytes(vbi->packetblob[choice])*8;
  98352. }
  98353. }else if(bm->avg_reservoir+(this_bits-avg_target_bits)<desired_fill){
  98354. while(choice+1<PACKETBLOBS && this_bits<avg_target_bits &&
  98355. bm->avg_reservoir+(this_bits-avg_target_bits)<desired_fill){
  98356. choice++;
  98357. this_bits=oggpack_bytes(vbi->packetblob[choice])*8;
  98358. }
  98359. }
  98360. slew=rint(choice-bm->avgfloat)/samples*vi->rate;
  98361. if(slew<-slewlimit)slew=-slewlimit;
  98362. if(slew>slewlimit)slew=slewlimit;
  98363. choice=rint(bm->avgfloat+= slew/vi->rate*samples);
  98364. this_bits=oggpack_bytes(vbi->packetblob[choice])*8;
  98365. }
  98366. if(bm->min_bitsper>0){
  98367. if(this_bits<min_target_bits){
  98368. while(bm->minmax_reservoir-(min_target_bits-this_bits)<0){
  98369. choice++;
  98370. if(choice>=PACKETBLOBS)break;
  98371. this_bits=oggpack_bytes(vbi->packetblob[choice])*8;
  98372. }
  98373. }
  98374. }
  98375. if(bm->max_bitsper>0){
  98376. if(this_bits>max_target_bits){
  98377. while(bm->minmax_reservoir+(this_bits-max_target_bits)>bi->reservoir_bits){
  98378. choice--;
  98379. if(choice<0)break;
  98380. this_bits=oggpack_bytes(vbi->packetblob[choice])*8;
  98381. }
  98382. }
  98383. }
  98384. if(choice<0){
  98385. long maxsize=(max_target_bits+(bi->reservoir_bits-bm->minmax_reservoir))/8;
  98386. bm->choice=choice=0;
  98387. if(oggpack_bytes(vbi->packetblob[choice])>maxsize){
  98388. oggpack_writetrunc(vbi->packetblob[choice],maxsize*8);
  98389. this_bits=oggpack_bytes(vbi->packetblob[choice])*8;
  98390. }
  98391. }else{
  98392. long minsize=(min_target_bits-bm->minmax_reservoir+7)/8;
  98393. if(choice>=PACKETBLOBS)
  98394. choice=PACKETBLOBS-1;
  98395. bm->choice=choice;
  98396. minsize-=oggpack_bytes(vbi->packetblob[choice]);
  98397. while(minsize-->0)oggpack_write(vbi->packetblob[choice],0,8);
  98398. this_bits=oggpack_bytes(vbi->packetblob[choice])*8;
  98399. }
  98400. if(bm->min_bitsper>0 || bm->max_bitsper>0){
  98401. if(max_target_bits>0 && this_bits>max_target_bits){
  98402. bm->minmax_reservoir+=(this_bits-max_target_bits);
  98403. }else if(min_target_bits>0 && this_bits<min_target_bits){
  98404. bm->minmax_reservoir+=(this_bits-min_target_bits);
  98405. }else{
  98406. if(bm->minmax_reservoir>desired_fill){
  98407. if(max_target_bits>0){ /* logical bulletproofing against initialization state */
  98408. bm->minmax_reservoir+=(this_bits-max_target_bits);
  98409. if(bm->minmax_reservoir<desired_fill)bm->minmax_reservoir=desired_fill;
  98410. }else{
  98411. bm->minmax_reservoir=desired_fill;
  98412. }
  98413. }else{
  98414. if(min_target_bits>0){ /* logical bulletproofing against initialization state */
  98415. bm->minmax_reservoir+=(this_bits-min_target_bits);
  98416. if(bm->minmax_reservoir>desired_fill)bm->minmax_reservoir=desired_fill;
  98417. }else{
  98418. bm->minmax_reservoir=desired_fill;
  98419. }
  98420. }
  98421. }
  98422. }
  98423. if(bm->avg_bitsper>0){
  98424. long avg_target_bits=(vb->W?bm->avg_bitsper*bm->short_per_long:bm->avg_bitsper);
  98425. bm->avg_reservoir+=this_bits-avg_target_bits;
  98426. }
  98427. return(0);
  98428. }
  98429. int vorbis_bitrate_flushpacket(vorbis_dsp_state *vd,ogg_packet *op){
  98430. private_state *b=(private_state*)vd->backend_state;
  98431. bitrate_manager_state *bm=&b->bms;
  98432. vorbis_block *vb=bm->vb;
  98433. int choice=PACKETBLOBS/2;
  98434. if(!vb)return 0;
  98435. if(op){
  98436. vorbis_block_internal *vbi=(vorbis_block_internal*)vb->internal;
  98437. if(vorbis_bitrate_managed(vb))
  98438. choice=bm->choice;
  98439. op->packet=oggpack_get_buffer(vbi->packetblob[choice]);
  98440. op->bytes=oggpack_bytes(vbi->packetblob[choice]);
  98441. op->b_o_s=0;
  98442. op->e_o_s=vb->eofflag;
  98443. op->granulepos=vb->granulepos;
  98444. op->packetno=vb->sequence; /* for sake of completeness */
  98445. }
  98446. bm->vb=0;
  98447. return(1);
  98448. }
  98449. #endif
  98450. /********* End of inlined file: bitrate.c *********/
  98451. /********* Start of inlined file: block.c *********/
  98452. /********* Start of inlined file: juce_OggVorbisHeader.h *********/
  98453. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  98454. // tasks..
  98455. #if JUCE_MSVC
  98456. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  98457. #endif
  98458. /********* End of inlined file: juce_OggVorbisHeader.h *********/
  98459. #if JUCE_USE_OGGVORBIS
  98460. #include <stdio.h>
  98461. #include <stdlib.h>
  98462. #include <string.h>
  98463. /********* Start of inlined file: window.h *********/
  98464. #ifndef _V_WINDOW_
  98465. #define _V_WINDOW_
  98466. extern float *_vorbis_window_get(int n);
  98467. extern void _vorbis_apply_window(float *d,int *winno,long *blocksizes,
  98468. int lW,int W,int nW);
  98469. #endif
  98470. /********* End of inlined file: window.h *********/
  98471. /********* Start of inlined file: lpc.h *********/
  98472. #ifndef _V_LPC_H_
  98473. #define _V_LPC_H_
  98474. extern float vorbis_lpc_from_data(float *data,float *lpc,int n,int m);
  98475. extern void vorbis_lpc_predict(float *coeff,float *prime,int m,
  98476. float *data,long n);
  98477. #endif
  98478. /********* End of inlined file: lpc.h *********/
  98479. #ifndef WORD_ALIGN
  98480. #define WORD_ALIGN 8
  98481. #endif
  98482. int vorbis_block_init(vorbis_dsp_state *v, vorbis_block *vb){
  98483. int i;
  98484. memset(vb,0,sizeof(*vb));
  98485. vb->vd=v;
  98486. vb->localalloc=0;
  98487. vb->localstore=NULL;
  98488. if(v->analysisp){
  98489. vorbis_block_internal *vbi=(vorbis_block_internal*)
  98490. (vb->internal=(vorbis_block_internal*)_ogg_calloc(1,sizeof(vorbis_block_internal)));
  98491. vbi->ampmax=-9999;
  98492. for(i=0;i<PACKETBLOBS;i++){
  98493. if(i==PACKETBLOBS/2){
  98494. vbi->packetblob[i]=&vb->opb;
  98495. }else{
  98496. vbi->packetblob[i]=
  98497. (oggpack_buffer*) _ogg_calloc(1,sizeof(oggpack_buffer));
  98498. }
  98499. oggpack_writeinit(vbi->packetblob[i]);
  98500. }
  98501. }
  98502. return(0);
  98503. }
  98504. void *_vorbis_block_alloc(vorbis_block *vb,long bytes){
  98505. bytes=(bytes+(WORD_ALIGN-1)) & ~(WORD_ALIGN-1);
  98506. if(bytes+vb->localtop>vb->localalloc){
  98507. if(vb->localstore){
  98508. struct alloc_chain *link=(struct alloc_chain*)_ogg_malloc(sizeof(*link));
  98509. vb->totaluse+=vb->localtop;
  98510. link->next=vb->reap;
  98511. link->ptr=vb->localstore;
  98512. vb->reap=link;
  98513. }
  98514. vb->localalloc=bytes;
  98515. vb->localstore=_ogg_malloc(vb->localalloc);
  98516. vb->localtop=0;
  98517. }
  98518. {
  98519. void *ret=(void *)(((char *)vb->localstore)+vb->localtop);
  98520. vb->localtop+=bytes;
  98521. return ret;
  98522. }
  98523. }
  98524. void _vorbis_block_ripcord(vorbis_block *vb){
  98525. struct alloc_chain *reap=vb->reap;
  98526. while(reap){
  98527. struct alloc_chain *next=reap->next;
  98528. _ogg_free(reap->ptr);
  98529. memset(reap,0,sizeof(*reap));
  98530. _ogg_free(reap);
  98531. reap=next;
  98532. }
  98533. if(vb->totaluse){
  98534. vb->localstore=_ogg_realloc(vb->localstore,vb->totaluse+vb->localalloc);
  98535. vb->localalloc+=vb->totaluse;
  98536. vb->totaluse=0;
  98537. }
  98538. vb->localtop=0;
  98539. vb->reap=NULL;
  98540. }
  98541. int vorbis_block_clear(vorbis_block *vb){
  98542. int i;
  98543. vorbis_block_internal *vbi=(vorbis_block_internal*)vb->internal;
  98544. _vorbis_block_ripcord(vb);
  98545. if(vb->localstore)_ogg_free(vb->localstore);
  98546. if(vbi){
  98547. for(i=0;i<PACKETBLOBS;i++){
  98548. oggpack_writeclear(vbi->packetblob[i]);
  98549. if(i!=PACKETBLOBS/2)_ogg_free(vbi->packetblob[i]);
  98550. }
  98551. _ogg_free(vbi);
  98552. }
  98553. memset(vb,0,sizeof(*vb));
  98554. return(0);
  98555. }
  98556. static int _vds_shared_init(vorbis_dsp_state *v,vorbis_info *vi,int encp){
  98557. int i;
  98558. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  98559. private_state *b=NULL;
  98560. int hs;
  98561. if(ci==NULL) return 1;
  98562. hs=ci->halfrate_flag;
  98563. memset(v,0,sizeof(*v));
  98564. b=(private_state*) (v->backend_state=(private_state*)_ogg_calloc(1,sizeof(*b)));
  98565. v->vi=vi;
  98566. b->modebits=ilog2(ci->modes);
  98567. b->transform[0]=(vorbis_look_transform**)_ogg_calloc(VI_TRANSFORMB,sizeof(*b->transform[0]));
  98568. b->transform[1]=(vorbis_look_transform**)_ogg_calloc(VI_TRANSFORMB,sizeof(*b->transform[1]));
  98569. b->transform[0][0]=_ogg_calloc(1,sizeof(mdct_lookup));
  98570. b->transform[1][0]=_ogg_calloc(1,sizeof(mdct_lookup));
  98571. mdct_init((mdct_lookup*)b->transform[0][0],ci->blocksizes[0]>>hs);
  98572. mdct_init((mdct_lookup*)b->transform[1][0],ci->blocksizes[1]>>hs);
  98573. b->window[0]=ilog2(ci->blocksizes[0])-6;
  98574. b->window[1]=ilog2(ci->blocksizes[1])-6;
  98575. if(encp){ /* encode/decode differ here */
  98576. drft_init(&b->fft_look[0],ci->blocksizes[0]);
  98577. drft_init(&b->fft_look[1],ci->blocksizes[1]);
  98578. if(!ci->fullbooks){
  98579. ci->fullbooks=(codebook*) _ogg_calloc(ci->books,sizeof(*ci->fullbooks));
  98580. for(i=0;i<ci->books;i++)
  98581. vorbis_book_init_encode(ci->fullbooks+i,ci->book_param[i]);
  98582. }
  98583. b->psy=(vorbis_look_psy*)_ogg_calloc(ci->psys,sizeof(*b->psy));
  98584. for(i=0;i<ci->psys;i++){
  98585. _vp_psy_init(b->psy+i,
  98586. ci->psy_param[i],
  98587. &ci->psy_g_param,
  98588. ci->blocksizes[ci->psy_param[i]->blockflag]/2,
  98589. vi->rate);
  98590. }
  98591. v->analysisp=1;
  98592. }else{
  98593. if(!ci->fullbooks){
  98594. ci->fullbooks=(codebook*) _ogg_calloc(ci->books,sizeof(*ci->fullbooks));
  98595. for(i=0;i<ci->books;i++){
  98596. vorbis_book_init_decode(ci->fullbooks+i,ci->book_param[i]);
  98597. vorbis_staticbook_destroy(ci->book_param[i]);
  98598. ci->book_param[i]=NULL;
  98599. }
  98600. }
  98601. }
  98602. v->pcm_storage=ci->blocksizes[1];
  98603. v->pcm=(float**)_ogg_malloc(vi->channels*sizeof(*v->pcm));
  98604. v->pcmret=(float**)_ogg_malloc(vi->channels*sizeof(*v->pcmret));
  98605. {
  98606. int i;
  98607. for(i=0;i<vi->channels;i++)
  98608. v->pcm[i]=(float*)_ogg_calloc(v->pcm_storage,sizeof(*v->pcm[i]));
  98609. }
  98610. v->lW=0; /* previous window size */
  98611. v->W=0; /* current window size */
  98612. v->centerW=ci->blocksizes[1]/2;
  98613. v->pcm_current=v->centerW;
  98614. b->flr=(vorbis_look_floor**)_ogg_calloc(ci->floors,sizeof(*b->flr));
  98615. b->residue=(vorbis_look_residue**)_ogg_calloc(ci->residues,sizeof(*b->residue));
  98616. for(i=0;i<ci->floors;i++)
  98617. b->flr[i]=_floor_P[ci->floor_type[i]]->
  98618. look(v,ci->floor_param[i]);
  98619. for(i=0;i<ci->residues;i++)
  98620. b->residue[i]=_residue_P[ci->residue_type[i]]->
  98621. look(v,ci->residue_param[i]);
  98622. return 0;
  98623. }
  98624. int vorbis_analysis_init(vorbis_dsp_state *v,vorbis_info *vi){
  98625. private_state *b=NULL;
  98626. if(_vds_shared_init(v,vi,1))return 1;
  98627. b=(private_state*)v->backend_state;
  98628. b->psy_g_look=_vp_global_look(vi);
  98629. b->ve=(envelope_lookup*)_ogg_calloc(1,sizeof(*b->ve));
  98630. _ve_envelope_init(b->ve,vi);
  98631. vorbis_bitrate_init(vi,&b->bms);
  98632. v->sequence=3;
  98633. return(0);
  98634. }
  98635. void vorbis_dsp_clear(vorbis_dsp_state *v){
  98636. int i;
  98637. if(v){
  98638. vorbis_info *vi=v->vi;
  98639. codec_setup_info *ci=(codec_setup_info*)(vi?vi->codec_setup:NULL);
  98640. private_state *b=(private_state*)v->backend_state;
  98641. if(b){
  98642. if(b->ve){
  98643. _ve_envelope_clear(b->ve);
  98644. _ogg_free(b->ve);
  98645. }
  98646. if(b->transform[0]){
  98647. mdct_clear((mdct_lookup*) b->transform[0][0]);
  98648. _ogg_free(b->transform[0][0]);
  98649. _ogg_free(b->transform[0]);
  98650. }
  98651. if(b->transform[1]){
  98652. mdct_clear((mdct_lookup*) b->transform[1][0]);
  98653. _ogg_free(b->transform[1][0]);
  98654. _ogg_free(b->transform[1]);
  98655. }
  98656. if(b->flr){
  98657. for(i=0;i<ci->floors;i++)
  98658. _floor_P[ci->floor_type[i]]->
  98659. free_look(b->flr[i]);
  98660. _ogg_free(b->flr);
  98661. }
  98662. if(b->residue){
  98663. for(i=0;i<ci->residues;i++)
  98664. _residue_P[ci->residue_type[i]]->
  98665. free_look(b->residue[i]);
  98666. _ogg_free(b->residue);
  98667. }
  98668. if(b->psy){
  98669. for(i=0;i<ci->psys;i++)
  98670. _vp_psy_clear(b->psy+i);
  98671. _ogg_free(b->psy);
  98672. }
  98673. if(b->psy_g_look)_vp_global_free(b->psy_g_look);
  98674. vorbis_bitrate_clear(&b->bms);
  98675. drft_clear(&b->fft_look[0]);
  98676. drft_clear(&b->fft_look[1]);
  98677. }
  98678. if(v->pcm){
  98679. for(i=0;i<vi->channels;i++)
  98680. if(v->pcm[i])_ogg_free(v->pcm[i]);
  98681. _ogg_free(v->pcm);
  98682. if(v->pcmret)_ogg_free(v->pcmret);
  98683. }
  98684. if(b){
  98685. if(b->header)_ogg_free(b->header);
  98686. if(b->header1)_ogg_free(b->header1);
  98687. if(b->header2)_ogg_free(b->header2);
  98688. _ogg_free(b);
  98689. }
  98690. memset(v,0,sizeof(*v));
  98691. }
  98692. }
  98693. float **vorbis_analysis_buffer(vorbis_dsp_state *v, int vals){
  98694. int i;
  98695. vorbis_info *vi=v->vi;
  98696. private_state *b=(private_state*)v->backend_state;
  98697. if(b->header)_ogg_free(b->header);b->header=NULL;
  98698. if(b->header1)_ogg_free(b->header1);b->header1=NULL;
  98699. if(b->header2)_ogg_free(b->header2);b->header2=NULL;
  98700. if(v->pcm_current+vals>=v->pcm_storage){
  98701. v->pcm_storage=v->pcm_current+vals*2;
  98702. for(i=0;i<vi->channels;i++){
  98703. v->pcm[i]=(float*)_ogg_realloc(v->pcm[i],v->pcm_storage*sizeof(*v->pcm[i]));
  98704. }
  98705. }
  98706. for(i=0;i<vi->channels;i++)
  98707. v->pcmret[i]=v->pcm[i]+v->pcm_current;
  98708. return(v->pcmret);
  98709. }
  98710. static void _preextrapolate_helper(vorbis_dsp_state *v){
  98711. int i;
  98712. int order=32;
  98713. float *lpc=(float*)alloca(order*sizeof(*lpc));
  98714. float *work=(float*)alloca(v->pcm_current*sizeof(*work));
  98715. long j;
  98716. v->preextrapolate=1;
  98717. if(v->pcm_current-v->centerW>order*2){ /* safety */
  98718. for(i=0;i<v->vi->channels;i++){
  98719. for(j=0;j<v->pcm_current;j++)
  98720. work[j]=v->pcm[i][v->pcm_current-j-1];
  98721. vorbis_lpc_from_data(work,lpc,v->pcm_current-v->centerW,order);
  98722. vorbis_lpc_predict(lpc,work+v->pcm_current-v->centerW-order,
  98723. order,
  98724. work+v->pcm_current-v->centerW,
  98725. v->centerW);
  98726. for(j=0;j<v->pcm_current;j++)
  98727. v->pcm[i][v->pcm_current-j-1]=work[j];
  98728. }
  98729. }
  98730. }
  98731. int vorbis_analysis_wrote(vorbis_dsp_state *v, int vals){
  98732. vorbis_info *vi=v->vi;
  98733. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  98734. if(vals<=0){
  98735. int order=32;
  98736. int i;
  98737. float *lpc=(float*) alloca(order*sizeof(*lpc));
  98738. if(!v->preextrapolate)
  98739. _preextrapolate_helper(v);
  98740. vorbis_analysis_buffer(v,ci->blocksizes[1]*3);
  98741. v->eofflag=v->pcm_current;
  98742. v->pcm_current+=ci->blocksizes[1]*3;
  98743. for(i=0;i<vi->channels;i++){
  98744. if(v->eofflag>order*2){
  98745. long n;
  98746. n=v->eofflag;
  98747. if(n>ci->blocksizes[1])n=ci->blocksizes[1];
  98748. vorbis_lpc_from_data(v->pcm[i]+v->eofflag-n,lpc,n,order);
  98749. vorbis_lpc_predict(lpc,v->pcm[i]+v->eofflag-order,order,
  98750. v->pcm[i]+v->eofflag,v->pcm_current-v->eofflag);
  98751. }else{
  98752. memset(v->pcm[i]+v->eofflag,0,
  98753. (v->pcm_current-v->eofflag)*sizeof(*v->pcm[i]));
  98754. }
  98755. }
  98756. }else{
  98757. if(v->pcm_current+vals>v->pcm_storage)
  98758. return(OV_EINVAL);
  98759. v->pcm_current+=vals;
  98760. if(!v->preextrapolate && v->pcm_current-v->centerW>ci->blocksizes[1])
  98761. _preextrapolate_helper(v);
  98762. }
  98763. return(0);
  98764. }
  98765. int vorbis_analysis_blockout(vorbis_dsp_state *v,vorbis_block *vb){
  98766. int i;
  98767. vorbis_info *vi=v->vi;
  98768. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  98769. private_state *b=(private_state*)v->backend_state;
  98770. vorbis_look_psy_global *g=b->psy_g_look;
  98771. long beginW=v->centerW-ci->blocksizes[v->W]/2,centerNext;
  98772. vorbis_block_internal *vbi=(vorbis_block_internal *)vb->internal;
  98773. if(!v->preextrapolate)return(0);
  98774. if(v->eofflag==-1)return(0);
  98775. {
  98776. long bp=_ve_envelope_search(v);
  98777. if(bp==-1){
  98778. if(v->eofflag==0)return(0); /* not enough data currently to search for a
  98779. full long block */
  98780. v->nW=0;
  98781. }else{
  98782. if(ci->blocksizes[0]==ci->blocksizes[1])
  98783. v->nW=0;
  98784. else
  98785. v->nW=bp;
  98786. }
  98787. }
  98788. centerNext=v->centerW+ci->blocksizes[v->W]/4+ci->blocksizes[v->nW]/4;
  98789. {
  98790. long blockbound=centerNext+ci->blocksizes[v->nW]/2;
  98791. if(v->pcm_current<blockbound)return(0); /* not enough data yet;
  98792. although this check is
  98793. less strict that the
  98794. _ve_envelope_search,
  98795. the search is not run
  98796. if we only use one
  98797. block size */
  98798. }
  98799. _vorbis_block_ripcord(vb);
  98800. vb->lW=v->lW;
  98801. vb->W=v->W;
  98802. vb->nW=v->nW;
  98803. if(v->W){
  98804. if(!v->lW || !v->nW){
  98805. vbi->blocktype=BLOCKTYPE_TRANSITION;
  98806. }else{
  98807. vbi->blocktype=BLOCKTYPE_LONG;
  98808. }
  98809. }else{
  98810. if(_ve_envelope_mark(v)){
  98811. vbi->blocktype=BLOCKTYPE_IMPULSE;
  98812. }else{
  98813. vbi->blocktype=BLOCKTYPE_PADDING;
  98814. }
  98815. }
  98816. vb->vd=v;
  98817. vb->sequence=v->sequence++;
  98818. vb->granulepos=v->granulepos;
  98819. vb->pcmend=ci->blocksizes[v->W];
  98820. if(vbi->ampmax>g->ampmax)g->ampmax=vbi->ampmax;
  98821. g->ampmax=_vp_ampmax_decay(g->ampmax,v);
  98822. vbi->ampmax=g->ampmax;
  98823. vb->pcm=(float**)_vorbis_block_alloc(vb,sizeof(*vb->pcm)*vi->channels);
  98824. vbi->pcmdelay=(float**)_vorbis_block_alloc(vb,sizeof(*vbi->pcmdelay)*vi->channels);
  98825. for(i=0;i<vi->channels;i++){
  98826. vbi->pcmdelay[i]=
  98827. (float*) _vorbis_block_alloc(vb,(vb->pcmend+beginW)*sizeof(*vbi->pcmdelay[i]));
  98828. memcpy(vbi->pcmdelay[i],v->pcm[i],(vb->pcmend+beginW)*sizeof(*vbi->pcmdelay[i]));
  98829. vb->pcm[i]=vbi->pcmdelay[i]+beginW;
  98830. }
  98831. if(v->eofflag){
  98832. if(v->centerW>=v->eofflag){
  98833. v->eofflag=-1;
  98834. vb->eofflag=1;
  98835. return(1);
  98836. }
  98837. }
  98838. {
  98839. int new_centerNext=ci->blocksizes[1]/2;
  98840. int movementW=centerNext-new_centerNext;
  98841. if(movementW>0){
  98842. _ve_envelope_shift(b->ve,movementW);
  98843. v->pcm_current-=movementW;
  98844. for(i=0;i<vi->channels;i++)
  98845. memmove(v->pcm[i],v->pcm[i]+movementW,
  98846. v->pcm_current*sizeof(*v->pcm[i]));
  98847. v->lW=v->W;
  98848. v->W=v->nW;
  98849. v->centerW=new_centerNext;
  98850. if(v->eofflag){
  98851. v->eofflag-=movementW;
  98852. if(v->eofflag<=0)v->eofflag=-1;
  98853. if(v->centerW>=v->eofflag){
  98854. v->granulepos+=movementW-(v->centerW-v->eofflag);
  98855. }else{
  98856. v->granulepos+=movementW;
  98857. }
  98858. }else{
  98859. v->granulepos+=movementW;
  98860. }
  98861. }
  98862. }
  98863. return(1);
  98864. }
  98865. int vorbis_synthesis_restart(vorbis_dsp_state *v){
  98866. vorbis_info *vi=v->vi;
  98867. codec_setup_info *ci;
  98868. int hs;
  98869. if(!v->backend_state)return -1;
  98870. if(!vi)return -1;
  98871. ci=(codec_setup_info*) vi->codec_setup;
  98872. if(!ci)return -1;
  98873. hs=ci->halfrate_flag;
  98874. v->centerW=ci->blocksizes[1]>>(hs+1);
  98875. v->pcm_current=v->centerW>>hs;
  98876. v->pcm_returned=-1;
  98877. v->granulepos=-1;
  98878. v->sequence=-1;
  98879. v->eofflag=0;
  98880. ((private_state *)(v->backend_state))->sample_count=-1;
  98881. return(0);
  98882. }
  98883. int vorbis_synthesis_init(vorbis_dsp_state *v,vorbis_info *vi){
  98884. if(_vds_shared_init(v,vi,0)) return 1;
  98885. vorbis_synthesis_restart(v);
  98886. return 0;
  98887. }
  98888. int vorbis_synthesis_blockin(vorbis_dsp_state *v,vorbis_block *vb){
  98889. vorbis_info *vi=v->vi;
  98890. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  98891. private_state *b=(private_state*)v->backend_state;
  98892. int hs=ci->halfrate_flag;
  98893. int i,j;
  98894. if(!vb)return(OV_EINVAL);
  98895. if(v->pcm_current>v->pcm_returned && v->pcm_returned!=-1)return(OV_EINVAL);
  98896. v->lW=v->W;
  98897. v->W=vb->W;
  98898. v->nW=-1;
  98899. if((v->sequence==-1)||
  98900. (v->sequence+1 != vb->sequence)){
  98901. v->granulepos=-1; /* out of sequence; lose count */
  98902. b->sample_count=-1;
  98903. }
  98904. v->sequence=vb->sequence;
  98905. if(vb->pcm){ /* no pcm to process if vorbis_synthesis_trackonly
  98906. was called on block */
  98907. int n=ci->blocksizes[v->W]>>(hs+1);
  98908. int n0=ci->blocksizes[0]>>(hs+1);
  98909. int n1=ci->blocksizes[1]>>(hs+1);
  98910. int thisCenter;
  98911. int prevCenter;
  98912. v->glue_bits+=vb->glue_bits;
  98913. v->time_bits+=vb->time_bits;
  98914. v->floor_bits+=vb->floor_bits;
  98915. v->res_bits+=vb->res_bits;
  98916. if(v->centerW){
  98917. thisCenter=n1;
  98918. prevCenter=0;
  98919. }else{
  98920. thisCenter=0;
  98921. prevCenter=n1;
  98922. }
  98923. for(j=0;j<vi->channels;j++){
  98924. if(v->lW){
  98925. if(v->W){
  98926. float *w=_vorbis_window_get(b->window[1]-hs);
  98927. float *pcm=v->pcm[j]+prevCenter;
  98928. float *p=vb->pcm[j];
  98929. for(i=0;i<n1;i++)
  98930. pcm[i]=pcm[i]*w[n1-i-1] + p[i]*w[i];
  98931. }else{
  98932. float *w=_vorbis_window_get(b->window[0]-hs);
  98933. float *pcm=v->pcm[j]+prevCenter+n1/2-n0/2;
  98934. float *p=vb->pcm[j];
  98935. for(i=0;i<n0;i++)
  98936. pcm[i]=pcm[i]*w[n0-i-1] +p[i]*w[i];
  98937. }
  98938. }else{
  98939. if(v->W){
  98940. float *w=_vorbis_window_get(b->window[0]-hs);
  98941. float *pcm=v->pcm[j]+prevCenter;
  98942. float *p=vb->pcm[j]+n1/2-n0/2;
  98943. for(i=0;i<n0;i++)
  98944. pcm[i]=pcm[i]*w[n0-i-1] +p[i]*w[i];
  98945. for(;i<n1/2+n0/2;i++)
  98946. pcm[i]=p[i];
  98947. }else{
  98948. float *w=_vorbis_window_get(b->window[0]-hs);
  98949. float *pcm=v->pcm[j]+prevCenter;
  98950. float *p=vb->pcm[j];
  98951. for(i=0;i<n0;i++)
  98952. pcm[i]=pcm[i]*w[n0-i-1] +p[i]*w[i];
  98953. }
  98954. }
  98955. {
  98956. float *pcm=v->pcm[j]+thisCenter;
  98957. float *p=vb->pcm[j]+n;
  98958. for(i=0;i<n;i++)
  98959. pcm[i]=p[i];
  98960. }
  98961. }
  98962. if(v->centerW)
  98963. v->centerW=0;
  98964. else
  98965. v->centerW=n1;
  98966. if(v->pcm_returned==-1){
  98967. v->pcm_returned=thisCenter;
  98968. v->pcm_current=thisCenter;
  98969. }else{
  98970. v->pcm_returned=prevCenter;
  98971. v->pcm_current=prevCenter+
  98972. ((ci->blocksizes[v->lW]/4+
  98973. ci->blocksizes[v->W]/4)>>hs);
  98974. }
  98975. }
  98976. if(b->sample_count==-1){
  98977. b->sample_count=0;
  98978. }else{
  98979. b->sample_count+=ci->blocksizes[v->lW]/4+ci->blocksizes[v->W]/4;
  98980. }
  98981. if(v->granulepos==-1){
  98982. if(vb->granulepos!=-1){ /* only set if we have a position to set to */
  98983. v->granulepos=vb->granulepos;
  98984. if(b->sample_count>v->granulepos){
  98985. if(vb->eofflag){
  98986. v->pcm_current-=(b->sample_count-v->granulepos)>>hs;
  98987. }else{
  98988. v->pcm_returned+=(b->sample_count-v->granulepos)>>hs;
  98989. if(v->pcm_returned>v->pcm_current)
  98990. v->pcm_returned=v->pcm_current;
  98991. }
  98992. }
  98993. }
  98994. }else{
  98995. v->granulepos+=ci->blocksizes[v->lW]/4+ci->blocksizes[v->W]/4;
  98996. if(vb->granulepos!=-1 && v->granulepos!=vb->granulepos){
  98997. if(v->granulepos>vb->granulepos){
  98998. long extra=v->granulepos-vb->granulepos;
  98999. if(extra)
  99000. if(vb->eofflag){
  99001. v->pcm_current-=extra>>hs;
  99002. } /* else {Shouldn't happen *unless* the bitstream is out of
  99003. spec. Either way, believe the bitstream } */
  99004. } /* else {Shouldn't happen *unless* the bitstream is out of
  99005. spec. Either way, believe the bitstream } */
  99006. v->granulepos=vb->granulepos;
  99007. }
  99008. }
  99009. if(vb->eofflag)v->eofflag=1;
  99010. return(0);
  99011. }
  99012. int vorbis_synthesis_pcmout(vorbis_dsp_state *v,float ***pcm){
  99013. vorbis_info *vi=v->vi;
  99014. if(v->pcm_returned>-1 && v->pcm_returned<v->pcm_current){
  99015. if(pcm){
  99016. int i;
  99017. for(i=0;i<vi->channels;i++)
  99018. v->pcmret[i]=v->pcm[i]+v->pcm_returned;
  99019. *pcm=v->pcmret;
  99020. }
  99021. return(v->pcm_current-v->pcm_returned);
  99022. }
  99023. return(0);
  99024. }
  99025. int vorbis_synthesis_read(vorbis_dsp_state *v,int n){
  99026. if(n && v->pcm_returned+n>v->pcm_current)return(OV_EINVAL);
  99027. v->pcm_returned+=n;
  99028. return(0);
  99029. }
  99030. int vorbis_synthesis_lapout(vorbis_dsp_state *v,float ***pcm){
  99031. vorbis_info *vi=v->vi;
  99032. codec_setup_info *ci=(codec_setup_info *)vi->codec_setup;
  99033. int hs=ci->halfrate_flag;
  99034. int n=ci->blocksizes[v->W]>>(hs+1);
  99035. int n0=ci->blocksizes[0]>>(hs+1);
  99036. int n1=ci->blocksizes[1]>>(hs+1);
  99037. int i,j;
  99038. if(v->pcm_returned<0)return 0;
  99039. if(v->centerW==n1){
  99040. for(j=0;j<vi->channels;j++){
  99041. float *p=v->pcm[j];
  99042. for(i=0;i<n1;i++){
  99043. float temp=p[i];
  99044. p[i]=p[i+n1];
  99045. p[i+n1]=temp;
  99046. }
  99047. }
  99048. v->pcm_current-=n1;
  99049. v->pcm_returned-=n1;
  99050. v->centerW=0;
  99051. }
  99052. if((v->lW^v->W)==1){
  99053. for(j=0;j<vi->channels;j++){
  99054. float *s=v->pcm[j];
  99055. float *d=v->pcm[j]+(n1-n0)/2;
  99056. for(i=(n1+n0)/2-1;i>=0;--i)
  99057. d[i]=s[i];
  99058. }
  99059. v->pcm_returned+=(n1-n0)/2;
  99060. v->pcm_current+=(n1-n0)/2;
  99061. }else{
  99062. if(v->lW==0){
  99063. for(j=0;j<vi->channels;j++){
  99064. float *s=v->pcm[j];
  99065. float *d=v->pcm[j]+n1-n0;
  99066. for(i=n0-1;i>=0;--i)
  99067. d[i]=s[i];
  99068. }
  99069. v->pcm_returned+=n1-n0;
  99070. v->pcm_current+=n1-n0;
  99071. }
  99072. }
  99073. if(pcm){
  99074. int i;
  99075. for(i=0;i<vi->channels;i++)
  99076. v->pcmret[i]=v->pcm[i]+v->pcm_returned;
  99077. *pcm=v->pcmret;
  99078. }
  99079. return(n1+n-v->pcm_returned);
  99080. }
  99081. float *vorbis_window(vorbis_dsp_state *v,int W){
  99082. vorbis_info *vi=v->vi;
  99083. codec_setup_info *ci=(codec_setup_info*) vi->codec_setup;
  99084. int hs=ci->halfrate_flag;
  99085. private_state *b=(private_state*)v->backend_state;
  99086. if(b->window[W]-1<0)return NULL;
  99087. return _vorbis_window_get(b->window[W]-hs);
  99088. }
  99089. #endif
  99090. /********* End of inlined file: block.c *********/
  99091. /********* Start of inlined file: codebook.c *********/
  99092. /********* Start of inlined file: juce_OggVorbisHeader.h *********/
  99093. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  99094. // tasks..
  99095. #if JUCE_MSVC
  99096. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  99097. #endif
  99098. /********* End of inlined file: juce_OggVorbisHeader.h *********/
  99099. #if JUCE_USE_OGGVORBIS
  99100. #include <stdlib.h>
  99101. #include <string.h>
  99102. #include <math.h>
  99103. int vorbis_staticbook_pack(const static_codebook *c,oggpack_buffer *opb){
  99104. long i,j;
  99105. int ordered=0;
  99106. oggpack_write(opb,0x564342,24);
  99107. oggpack_write(opb,c->dim,16);
  99108. oggpack_write(opb,c->entries,24);
  99109. for(i=1;i<c->entries;i++)
  99110. if(c->lengthlist[i-1]==0 || c->lengthlist[i]<c->lengthlist[i-1])break;
  99111. if(i==c->entries)ordered=1;
  99112. if(ordered){
  99113. long count=0;
  99114. oggpack_write(opb,1,1); /* ordered */
  99115. oggpack_write(opb,c->lengthlist[0]-1,5); /* 1 to 32 */
  99116. for(i=1;i<c->entries;i++){
  99117. long thisx=c->lengthlist[i];
  99118. long last=c->lengthlist[i-1];
  99119. if(thisx>last){
  99120. for(j=last;j<thisx;j++){
  99121. oggpack_write(opb,i-count,_ilog(c->entries-count));
  99122. count=i;
  99123. }
  99124. }
  99125. }
  99126. oggpack_write(opb,i-count,_ilog(c->entries-count));
  99127. }else{
  99128. oggpack_write(opb,0,1); /* unordered */
  99129. for(i=0;i<c->entries;i++)
  99130. if(c->lengthlist[i]==0)break;
  99131. if(i==c->entries){
  99132. oggpack_write(opb,0,1); /* no unused entries */
  99133. for(i=0;i<c->entries;i++)
  99134. oggpack_write(opb,c->lengthlist[i]-1,5);
  99135. }else{
  99136. oggpack_write(opb,1,1); /* we have unused entries; thus we tag */
  99137. for(i=0;i<c->entries;i++){
  99138. if(c->lengthlist[i]==0){
  99139. oggpack_write(opb,0,1);
  99140. }else{
  99141. oggpack_write(opb,1,1);
  99142. oggpack_write(opb,c->lengthlist[i]-1,5);
  99143. }
  99144. }
  99145. }
  99146. }
  99147. oggpack_write(opb,c->maptype,4);
  99148. switch(c->maptype){
  99149. case 0:
  99150. break;
  99151. case 1:case 2:
  99152. if(!c->quantlist){
  99153. return(-1);
  99154. }
  99155. oggpack_write(opb,c->q_min,32);
  99156. oggpack_write(opb,c->q_delta,32);
  99157. oggpack_write(opb,c->q_quant-1,4);
  99158. oggpack_write(opb,c->q_sequencep,1);
  99159. {
  99160. int quantvals;
  99161. switch(c->maptype){
  99162. case 1:
  99163. quantvals=_book_maptype1_quantvals(c);
  99164. break;
  99165. case 2:
  99166. quantvals=c->entries*c->dim;
  99167. break;
  99168. default: /* NOT_REACHABLE */
  99169. quantvals=-1;
  99170. }
  99171. for(i=0;i<quantvals;i++)
  99172. oggpack_write(opb,labs(c->quantlist[i]),c->q_quant);
  99173. }
  99174. break;
  99175. default:
  99176. return(-1);
  99177. }
  99178. return(0);
  99179. }
  99180. int vorbis_staticbook_unpack(oggpack_buffer *opb,static_codebook *s){
  99181. long i,j;
  99182. memset(s,0,sizeof(*s));
  99183. s->allocedp=1;
  99184. if(oggpack_read(opb,24)!=0x564342)goto _eofout;
  99185. s->dim=oggpack_read(opb,16);
  99186. s->entries=oggpack_read(opb,24);
  99187. if(s->entries==-1)goto _eofout;
  99188. switch((int)oggpack_read(opb,1)){
  99189. case 0:
  99190. s->lengthlist=(long*)_ogg_malloc(sizeof(*s->lengthlist)*s->entries);
  99191. if(oggpack_read(opb,1)){
  99192. for(i=0;i<s->entries;i++){
  99193. if(oggpack_read(opb,1)){
  99194. long num=oggpack_read(opb,5);
  99195. if(num==-1)goto _eofout;
  99196. s->lengthlist[i]=num+1;
  99197. }else
  99198. s->lengthlist[i]=0;
  99199. }
  99200. }else{
  99201. for(i=0;i<s->entries;i++){
  99202. long num=oggpack_read(opb,5);
  99203. if(num==-1)goto _eofout;
  99204. s->lengthlist[i]=num+1;
  99205. }
  99206. }
  99207. break;
  99208. case 1:
  99209. {
  99210. long length=oggpack_read(opb,5)+1;
  99211. s->lengthlist=(long*)_ogg_malloc(sizeof(*s->lengthlist)*s->entries);
  99212. for(i=0;i<s->entries;){
  99213. long num=oggpack_read(opb,_ilog(s->entries-i));
  99214. if(num==-1)goto _eofout;
  99215. for(j=0;j<num && i<s->entries;j++,i++)
  99216. s->lengthlist[i]=length;
  99217. length++;
  99218. }
  99219. }
  99220. break;
  99221. default:
  99222. return(-1);
  99223. }
  99224. switch((s->maptype=oggpack_read(opb,4))){
  99225. case 0:
  99226. break;
  99227. case 1: case 2:
  99228. s->q_min=oggpack_read(opb,32);
  99229. s->q_delta=oggpack_read(opb,32);
  99230. s->q_quant=oggpack_read(opb,4)+1;
  99231. s->q_sequencep=oggpack_read(opb,1);
  99232. {
  99233. int quantvals=0;
  99234. switch(s->maptype){
  99235. case 1:
  99236. quantvals=_book_maptype1_quantvals(s);
  99237. break;
  99238. case 2:
  99239. quantvals=s->entries*s->dim;
  99240. break;
  99241. }
  99242. s->quantlist=(long*)_ogg_malloc(sizeof(*s->quantlist)*quantvals);
  99243. for(i=0;i<quantvals;i++)
  99244. s->quantlist[i]=oggpack_read(opb,s->q_quant);
  99245. if(quantvals&&s->quantlist[quantvals-1]==-1)goto _eofout;
  99246. }
  99247. break;
  99248. default:
  99249. goto _errout;
  99250. }
  99251. return(0);
  99252. _errout:
  99253. _eofout:
  99254. vorbis_staticbook_clear(s);
  99255. return(-1);
  99256. }
  99257. int vorbis_book_encode(codebook *book, int a, oggpack_buffer *b){
  99258. oggpack_write(b,book->codelist[a],book->c->lengthlist[a]);
  99259. return(book->c->lengthlist[a]);
  99260. }
  99261. int vorbis_book_errorv(codebook *book,float *a){
  99262. int dim=book->dim,k;
  99263. int best=_best(book,a,1);
  99264. for(k=0;k<dim;k++)
  99265. a[k]=(book->valuelist+best*dim)[k];
  99266. return(best);
  99267. }
  99268. int vorbis_book_encodev(codebook *book,int best,float *a,oggpack_buffer *b){
  99269. int k,dim=book->dim;
  99270. for(k=0;k<dim;k++)
  99271. a[k]=(book->valuelist+best*dim)[k];
  99272. return(vorbis_book_encode(book,best,b));
  99273. }
  99274. STIN long decode_packed_entry_number(codebook *book, oggpack_buffer *b){
  99275. int read=book->dec_maxlength;
  99276. long lo,hi;
  99277. long lok = oggpack_look(b,book->dec_firsttablen);
  99278. if (lok >= 0) {
  99279. long entry = book->dec_firsttable[lok];
  99280. if(entry&0x80000000UL){
  99281. lo=(entry>>15)&0x7fff;
  99282. hi=book->used_entries-(entry&0x7fff);
  99283. }else{
  99284. oggpack_adv(b, book->dec_codelengths[entry-1]);
  99285. return(entry-1);
  99286. }
  99287. }else{
  99288. lo=0;
  99289. hi=book->used_entries;
  99290. }
  99291. lok = oggpack_look(b, read);
  99292. while(lok<0 && read>1)
  99293. lok = oggpack_look(b, --read);
  99294. if(lok<0)return -1;
  99295. {
  99296. ogg_uint32_t testword=ogg_bitreverse((ogg_uint32_t)lok);
  99297. while(hi-lo>1){
  99298. long p=(hi-lo)>>1;
  99299. long test=book->codelist[lo+p]>testword;
  99300. lo+=p&(test-1);
  99301. hi-=p&(-test);
  99302. }
  99303. if(book->dec_codelengths[lo]<=read){
  99304. oggpack_adv(b, book->dec_codelengths[lo]);
  99305. return(lo);
  99306. }
  99307. }
  99308. oggpack_adv(b, read);
  99309. return(-1);
  99310. }
  99311. long vorbis_book_decode(codebook *book, oggpack_buffer *b){
  99312. long packed_entry=decode_packed_entry_number(book,b);
  99313. if(packed_entry>=0)
  99314. return(book->dec_index[packed_entry]);
  99315. return(packed_entry);
  99316. }
  99317. long vorbis_book_decodevs_add(codebook *book,float *a,oggpack_buffer *b,int n){
  99318. int step=n/book->dim;
  99319. long *entry = (long*)alloca(sizeof(*entry)*step);
  99320. float **t = (float**)alloca(sizeof(*t)*step);
  99321. int i,j,o;
  99322. for (i = 0; i < step; i++) {
  99323. entry[i]=decode_packed_entry_number(book,b);
  99324. if(entry[i]==-1)return(-1);
  99325. t[i] = book->valuelist+entry[i]*book->dim;
  99326. }
  99327. for(i=0,o=0;i<book->dim;i++,o+=step)
  99328. for (j=0;j<step;j++)
  99329. a[o+j]+=t[j][i];
  99330. return(0);
  99331. }
  99332. long vorbis_book_decodev_add(codebook *book,float *a,oggpack_buffer *b,int n){
  99333. int i,j,entry;
  99334. float *t;
  99335. if(book->dim>8){
  99336. for(i=0;i<n;){
  99337. entry = decode_packed_entry_number(book,b);
  99338. if(entry==-1)return(-1);
  99339. t = book->valuelist+entry*book->dim;
  99340. for (j=0;j<book->dim;)
  99341. a[i++]+=t[j++];
  99342. }
  99343. }else{
  99344. for(i=0;i<n;){
  99345. entry = decode_packed_entry_number(book,b);
  99346. if(entry==-1)return(-1);
  99347. t = book->valuelist+entry*book->dim;
  99348. j=0;
  99349. switch((int)book->dim){
  99350. case 8:
  99351. a[i++]+=t[j++];
  99352. case 7:
  99353. a[i++]+=t[j++];
  99354. case 6:
  99355. a[i++]+=t[j++];
  99356. case 5:
  99357. a[i++]+=t[j++];
  99358. case 4:
  99359. a[i++]+=t[j++];
  99360. case 3:
  99361. a[i++]+=t[j++];
  99362. case 2:
  99363. a[i++]+=t[j++];
  99364. case 1:
  99365. a[i++]+=t[j++];
  99366. case 0:
  99367. break;
  99368. }
  99369. }
  99370. }
  99371. return(0);
  99372. }
  99373. long vorbis_book_decodev_set(codebook *book,float *a,oggpack_buffer *b,int n){
  99374. int i,j,entry;
  99375. float *t;
  99376. for(i=0;i<n;){
  99377. entry = decode_packed_entry_number(book,b);
  99378. if(entry==-1)return(-1);
  99379. t = book->valuelist+entry*book->dim;
  99380. for (j=0;j<book->dim;)
  99381. a[i++]=t[j++];
  99382. }
  99383. return(0);
  99384. }
  99385. long vorbis_book_decodevv_add(codebook *book,float **a,long offset,int ch,
  99386. oggpack_buffer *b,int n){
  99387. long i,j,entry;
  99388. int chptr=0;
  99389. for(i=offset/ch;i<(offset+n)/ch;){
  99390. entry = decode_packed_entry_number(book,b);
  99391. if(entry==-1)return(-1);
  99392. {
  99393. const float *t = book->valuelist+entry*book->dim;
  99394. for (j=0;j<book->dim;j++){
  99395. a[chptr++][i]+=t[j];
  99396. if(chptr==ch){
  99397. chptr=0;
  99398. i++;
  99399. }
  99400. }
  99401. }
  99402. }
  99403. return(0);
  99404. }
  99405. #ifdef _V_SELFTEST
  99406. #include <stdio.h>
  99407. #include "vorbis/book/lsp20_0.vqh"
  99408. #include "vorbis/book/res0a_13.vqh"
  99409. #define TESTSIZE 40
  99410. float test1[TESTSIZE]={
  99411. 0.105939f,
  99412. 0.215373f,
  99413. 0.429117f,
  99414. 0.587974f,
  99415. 0.181173f,
  99416. 0.296583f,
  99417. 0.515707f,
  99418. 0.715261f,
  99419. 0.162327f,
  99420. 0.263834f,
  99421. 0.342876f,
  99422. 0.406025f,
  99423. 0.103571f,
  99424. 0.223561f,
  99425. 0.368513f,
  99426. 0.540313f,
  99427. 0.136672f,
  99428. 0.395882f,
  99429. 0.587183f,
  99430. 0.652476f,
  99431. 0.114338f,
  99432. 0.417300f,
  99433. 0.525486f,
  99434. 0.698679f,
  99435. 0.147492f,
  99436. 0.324481f,
  99437. 0.643089f,
  99438. 0.757582f,
  99439. 0.139556f,
  99440. 0.215795f,
  99441. 0.324559f,
  99442. 0.399387f,
  99443. 0.120236f,
  99444. 0.267420f,
  99445. 0.446940f,
  99446. 0.608760f,
  99447. 0.115587f,
  99448. 0.287234f,
  99449. 0.571081f,
  99450. 0.708603f,
  99451. };
  99452. float test3[TESTSIZE]={
  99453. 0,1,-2,3,4,-5,6,7,8,9,
  99454. 8,-2,7,-1,4,6,8,3,1,-9,
  99455. 10,11,12,13,14,15,26,17,18,19,
  99456. 30,-25,-30,-1,-5,-32,4,3,-2,0};
  99457. static_codebook *testlist[]={&_vq_book_lsp20_0,
  99458. &_vq_book_res0a_13,NULL};
  99459. float *testvec[]={test1,test3};
  99460. int main(){
  99461. oggpack_buffer write;
  99462. oggpack_buffer read;
  99463. long ptr=0,i;
  99464. oggpack_writeinit(&write);
  99465. fprintf(stderr,"Testing codebook abstraction...:\n");
  99466. while(testlist[ptr]){
  99467. codebook c;
  99468. static_codebook s;
  99469. float *qv=alloca(sizeof(*qv)*TESTSIZE);
  99470. float *iv=alloca(sizeof(*iv)*TESTSIZE);
  99471. memcpy(qv,testvec[ptr],sizeof(*qv)*TESTSIZE);
  99472. memset(iv,0,sizeof(*iv)*TESTSIZE);
  99473. fprintf(stderr,"\tpacking/coding %ld... ",ptr);
  99474. oggpack_reset(&write);
  99475. vorbis_book_init_encode(&c,testlist[ptr]); /* get it into memory
  99476. we can write */
  99477. vorbis_staticbook_pack(testlist[ptr],&write);
  99478. fprintf(stderr,"Codebook size %ld bytes... ",oggpack_bytes(&write));
  99479. for(i=0;i<TESTSIZE;i+=c.dim){
  99480. int best=_best(&c,qv+i,1);
  99481. vorbis_book_encodev(&c,best,qv+i,&write);
  99482. }
  99483. vorbis_book_clear(&c);
  99484. fprintf(stderr,"OK.\n");
  99485. fprintf(stderr,"\tunpacking/decoding %ld... ",ptr);
  99486. oggpack_readinit(&read,oggpack_get_buffer(&write),oggpack_bytes(&write));
  99487. if(vorbis_staticbook_unpack(&read,&s)){
  99488. fprintf(stderr,"Error unpacking codebook.\n");
  99489. exit(1);
  99490. }
  99491. if(vorbis_book_init_decode(&c,&s)){
  99492. fprintf(stderr,"Error initializing codebook.\n");
  99493. exit(1);
  99494. }
  99495. for(i=0;i<TESTSIZE;i+=c.dim)
  99496. if(vorbis_book_decodev_set(&c,iv+i,&read,c.dim)==-1){
  99497. fprintf(stderr,"Error reading codebook test data (EOP).\n");
  99498. exit(1);
  99499. }
  99500. for(i=0;i<TESTSIZE;i++)
  99501. if(fabs(qv[i]-iv[i])>.000001){
  99502. fprintf(stderr,"read (%g) != written (%g) at position (%ld)\n",
  99503. iv[i],qv[i],i);
  99504. exit(1);
  99505. }
  99506. fprintf(stderr,"OK\n");
  99507. ptr++;
  99508. }
  99509. exit(0);
  99510. }
  99511. #endif
  99512. #endif
  99513. /********* End of inlined file: codebook.c *********/
  99514. /********* Start of inlined file: envelope.c *********/
  99515. /********* Start of inlined file: juce_OggVorbisHeader.h *********/
  99516. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  99517. // tasks..
  99518. #if JUCE_MSVC
  99519. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  99520. #endif
  99521. /********* End of inlined file: juce_OggVorbisHeader.h *********/
  99522. #if JUCE_USE_OGGVORBIS
  99523. #include <stdlib.h>
  99524. #include <string.h>
  99525. #include <stdio.h>
  99526. #include <math.h>
  99527. void _ve_envelope_init(envelope_lookup *e,vorbis_info *vi){
  99528. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  99529. vorbis_info_psy_global *gi=&ci->psy_g_param;
  99530. int ch=vi->channels;
  99531. int i,j;
  99532. int n=e->winlength=128;
  99533. e->searchstep=64; /* not random */
  99534. e->minenergy=gi->preecho_minenergy;
  99535. e->ch=ch;
  99536. e->storage=128;
  99537. e->cursor=ci->blocksizes[1]/2;
  99538. e->mdct_win=(float*)_ogg_calloc(n,sizeof(*e->mdct_win));
  99539. mdct_init(&e->mdct,n);
  99540. for(i=0;i<n;i++){
  99541. e->mdct_win[i]=sin(i/(n-1.)*M_PI);
  99542. e->mdct_win[i]*=e->mdct_win[i];
  99543. }
  99544. e->band[0].begin=2; e->band[0].end=4;
  99545. e->band[1].begin=4; e->band[1].end=5;
  99546. e->band[2].begin=6; e->band[2].end=6;
  99547. e->band[3].begin=9; e->band[3].end=8;
  99548. e->band[4].begin=13; e->band[4].end=8;
  99549. e->band[5].begin=17; e->band[5].end=8;
  99550. e->band[6].begin=22; e->band[6].end=8;
  99551. for(j=0;j<VE_BANDS;j++){
  99552. n=e->band[j].end;
  99553. e->band[j].window=(float*)_ogg_malloc(n*sizeof(*e->band[0].window));
  99554. for(i=0;i<n;i++){
  99555. e->band[j].window[i]=sin((i+.5)/n*M_PI);
  99556. e->band[j].total+=e->band[j].window[i];
  99557. }
  99558. e->band[j].total=1./e->band[j].total;
  99559. }
  99560. e->filter=(envelope_filter_state*)_ogg_calloc(VE_BANDS*ch,sizeof(*e->filter));
  99561. e->mark=(int*)_ogg_calloc(e->storage,sizeof(*e->mark));
  99562. }
  99563. void _ve_envelope_clear(envelope_lookup *e){
  99564. int i;
  99565. mdct_clear(&e->mdct);
  99566. for(i=0;i<VE_BANDS;i++)
  99567. _ogg_free(e->band[i].window);
  99568. _ogg_free(e->mdct_win);
  99569. _ogg_free(e->filter);
  99570. _ogg_free(e->mark);
  99571. memset(e,0,sizeof(*e));
  99572. }
  99573. static int _ve_amp(envelope_lookup *ve,
  99574. vorbis_info_psy_global *gi,
  99575. float *data,
  99576. envelope_band *bands,
  99577. envelope_filter_state *filters,
  99578. long pos){
  99579. long n=ve->winlength;
  99580. int ret=0;
  99581. long i,j;
  99582. float decay;
  99583. float minV=ve->minenergy;
  99584. float *vec=(float*) alloca(n*sizeof(*vec));
  99585. int stretch=max(VE_MINSTRETCH,ve->stretch/2);
  99586. float penalty=gi->stretch_penalty-(ve->stretch/2-VE_MINSTRETCH);
  99587. if(penalty<0.f)penalty=0.f;
  99588. if(penalty>gi->stretch_penalty)penalty=gi->stretch_penalty;
  99589. for(i=0;i<n;i++)
  99590. vec[i]=data[i]*ve->mdct_win[i];
  99591. mdct_forward(&ve->mdct,vec,vec);
  99592. {
  99593. float temp=vec[0]*vec[0]+.7*vec[1]*vec[1]+.2*vec[2]*vec[2];
  99594. int ptr=filters->nearptr;
  99595. if(ptr==0){
  99596. decay=filters->nearDC_acc=filters->nearDC_partialacc+temp;
  99597. filters->nearDC_partialacc=temp;
  99598. }else{
  99599. decay=filters->nearDC_acc+=temp;
  99600. filters->nearDC_partialacc+=temp;
  99601. }
  99602. filters->nearDC_acc-=filters->nearDC[ptr];
  99603. filters->nearDC[ptr]=temp;
  99604. decay*=(1./(VE_NEARDC+1));
  99605. filters->nearptr++;
  99606. if(filters->nearptr>=VE_NEARDC)filters->nearptr=0;
  99607. decay=todB(&decay)*.5-15.f;
  99608. }
  99609. for(i=0;i<n/2;i+=2){
  99610. float val=vec[i]*vec[i]+vec[i+1]*vec[i+1];
  99611. val=todB(&val)*.5f;
  99612. if(val<decay)val=decay;
  99613. if(val<minV)val=minV;
  99614. vec[i>>1]=val;
  99615. decay-=8.;
  99616. }
  99617. for(j=0;j<VE_BANDS;j++){
  99618. float acc=0.;
  99619. float valmax,valmin;
  99620. for(i=0;i<bands[j].end;i++)
  99621. acc+=vec[i+bands[j].begin]*bands[j].window[i];
  99622. acc*=bands[j].total;
  99623. {
  99624. int p,thisx=filters[j].ampptr;
  99625. float postmax,postmin,premax=-99999.f,premin=99999.f;
  99626. p=thisx;
  99627. p--;
  99628. if(p<0)p+=VE_AMP;
  99629. postmax=max(acc,filters[j].ampbuf[p]);
  99630. postmin=min(acc,filters[j].ampbuf[p]);
  99631. for(i=0;i<stretch;i++){
  99632. p--;
  99633. if(p<0)p+=VE_AMP;
  99634. premax=max(premax,filters[j].ampbuf[p]);
  99635. premin=min(premin,filters[j].ampbuf[p]);
  99636. }
  99637. valmin=postmin-premin;
  99638. valmax=postmax-premax;
  99639. filters[j].ampbuf[thisx]=acc;
  99640. filters[j].ampptr++;
  99641. if(filters[j].ampptr>=VE_AMP)filters[j].ampptr=0;
  99642. }
  99643. if(valmax>gi->preecho_thresh[j]+penalty){
  99644. ret|=1;
  99645. ret|=4;
  99646. }
  99647. if(valmin<gi->postecho_thresh[j]-penalty)ret|=2;
  99648. }
  99649. return(ret);
  99650. }
  99651. #if 0
  99652. static int seq=0;
  99653. static ogg_int64_t totalshift=-1024;
  99654. #endif
  99655. long _ve_envelope_search(vorbis_dsp_state *v){
  99656. vorbis_info *vi=v->vi;
  99657. codec_setup_info *ci=(codec_setup_info *)vi->codec_setup;
  99658. vorbis_info_psy_global *gi=&ci->psy_g_param;
  99659. envelope_lookup *ve=((private_state *)(v->backend_state))->ve;
  99660. long i,j;
  99661. int first=ve->current/ve->searchstep;
  99662. int last=v->pcm_current/ve->searchstep-VE_WIN;
  99663. if(first<0)first=0;
  99664. if(last+VE_WIN+VE_POST>ve->storage){
  99665. ve->storage=last+VE_WIN+VE_POST; /* be sure */
  99666. ve->mark=(int*)_ogg_realloc(ve->mark,ve->storage*sizeof(*ve->mark));
  99667. }
  99668. for(j=first;j<last;j++){
  99669. int ret=0;
  99670. ve->stretch++;
  99671. if(ve->stretch>VE_MAXSTRETCH*2)
  99672. ve->stretch=VE_MAXSTRETCH*2;
  99673. for(i=0;i<ve->ch;i++){
  99674. float *pcm=v->pcm[i]+ve->searchstep*(j);
  99675. ret|=_ve_amp(ve,gi,pcm,ve->band,ve->filter+i*VE_BANDS,j);
  99676. }
  99677. ve->mark[j+VE_POST]=0;
  99678. if(ret&1){
  99679. ve->mark[j]=1;
  99680. ve->mark[j+1]=1;
  99681. }
  99682. if(ret&2){
  99683. ve->mark[j]=1;
  99684. if(j>0)ve->mark[j-1]=1;
  99685. }
  99686. if(ret&4)ve->stretch=-1;
  99687. }
  99688. ve->current=last*ve->searchstep;
  99689. {
  99690. long centerW=v->centerW;
  99691. long testW=
  99692. centerW+
  99693. ci->blocksizes[v->W]/4+
  99694. ci->blocksizes[1]/2+
  99695. ci->blocksizes[0]/4;
  99696. j=ve->cursor;
  99697. while(j<ve->current-(ve->searchstep)){/* account for postecho
  99698. working back one window */
  99699. if(j>=testW)return(1);
  99700. ve->cursor=j;
  99701. if(ve->mark[j/ve->searchstep]){
  99702. if(j>centerW){
  99703. #if 0
  99704. if(j>ve->curmark){
  99705. float *marker=alloca(v->pcm_current*sizeof(*marker));
  99706. int l,m;
  99707. memset(marker,0,sizeof(*marker)*v->pcm_current);
  99708. fprintf(stderr,"mark! seq=%d, cursor:%fs time:%fs\n",
  99709. seq,
  99710. (totalshift+ve->cursor)/44100.,
  99711. (totalshift+j)/44100.);
  99712. _analysis_output_always("pcmL",seq,v->pcm[0],v->pcm_current,0,0,totalshift);
  99713. _analysis_output_always("pcmR",seq,v->pcm[1],v->pcm_current,0,0,totalshift);
  99714. _analysis_output_always("markL",seq,v->pcm[0],j,0,0,totalshift);
  99715. _analysis_output_always("markR",seq,v->pcm[1],j,0,0,totalshift);
  99716. for(m=0;m<VE_BANDS;m++){
  99717. char buf[80];
  99718. sprintf(buf,"delL%d",m);
  99719. for(l=0;l<last;l++)marker[l*ve->searchstep]=ve->filter[m].markers[l]*.1;
  99720. _analysis_output_always(buf,seq,marker,v->pcm_current,0,0,totalshift);
  99721. }
  99722. for(m=0;m<VE_BANDS;m++){
  99723. char buf[80];
  99724. sprintf(buf,"delR%d",m);
  99725. for(l=0;l<last;l++)marker[l*ve->searchstep]=ve->filter[m+VE_BANDS].markers[l]*.1;
  99726. _analysis_output_always(buf,seq,marker,v->pcm_current,0,0,totalshift);
  99727. }
  99728. for(l=0;l<last;l++)marker[l*ve->searchstep]=ve->mark[l]*.4;
  99729. _analysis_output_always("mark",seq,marker,v->pcm_current,0,0,totalshift);
  99730. seq++;
  99731. }
  99732. #endif
  99733. ve->curmark=j;
  99734. if(j>=testW)return(1);
  99735. return(0);
  99736. }
  99737. }
  99738. j+=ve->searchstep;
  99739. }
  99740. }
  99741. return(-1);
  99742. }
  99743. int _ve_envelope_mark(vorbis_dsp_state *v){
  99744. envelope_lookup *ve=((private_state *)(v->backend_state))->ve;
  99745. vorbis_info *vi=v->vi;
  99746. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  99747. long centerW=v->centerW;
  99748. long beginW=centerW-ci->blocksizes[v->W]/4;
  99749. long endW=centerW+ci->blocksizes[v->W]/4;
  99750. if(v->W){
  99751. beginW-=ci->blocksizes[v->lW]/4;
  99752. endW+=ci->blocksizes[v->nW]/4;
  99753. }else{
  99754. beginW-=ci->blocksizes[0]/4;
  99755. endW+=ci->blocksizes[0]/4;
  99756. }
  99757. if(ve->curmark>=beginW && ve->curmark<endW)return(1);
  99758. {
  99759. long first=beginW/ve->searchstep;
  99760. long last=endW/ve->searchstep;
  99761. long i;
  99762. for(i=first;i<last;i++)
  99763. if(ve->mark[i])return(1);
  99764. }
  99765. return(0);
  99766. }
  99767. void _ve_envelope_shift(envelope_lookup *e,long shift){
  99768. int smallsize=e->current/e->searchstep+VE_POST; /* adjust for placing marks
  99769. ahead of ve->current */
  99770. int smallshift=shift/e->searchstep;
  99771. memmove(e->mark,e->mark+smallshift,(smallsize-smallshift)*sizeof(*e->mark));
  99772. #if 0
  99773. for(i=0;i<VE_BANDS*e->ch;i++)
  99774. memmove(e->filter[i].markers,
  99775. e->filter[i].markers+smallshift,
  99776. (1024-smallshift)*sizeof(*(*e->filter).markers));
  99777. totalshift+=shift;
  99778. #endif
  99779. e->current-=shift;
  99780. if(e->curmark>=0)
  99781. e->curmark-=shift;
  99782. e->cursor-=shift;
  99783. }
  99784. #endif
  99785. /********* End of inlined file: envelope.c *********/
  99786. /********* Start of inlined file: floor0.c *********/
  99787. /********* Start of inlined file: juce_OggVorbisHeader.h *********/
  99788. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  99789. // tasks..
  99790. #if JUCE_MSVC
  99791. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  99792. #endif
  99793. /********* End of inlined file: juce_OggVorbisHeader.h *********/
  99794. #if JUCE_USE_OGGVORBIS
  99795. #include <stdlib.h>
  99796. #include <string.h>
  99797. #include <math.h>
  99798. /********* Start of inlined file: lsp.h *********/
  99799. #ifndef _V_LSP_H_
  99800. #define _V_LSP_H_
  99801. extern int vorbis_lpc_to_lsp(float *lpc,float *lsp,int m);
  99802. extern void vorbis_lsp_to_curve(float *curve,int *map,int n,int ln,
  99803. float *lsp,int m,
  99804. float amp,float ampoffset);
  99805. #endif
  99806. /********* End of inlined file: lsp.h *********/
  99807. #include <stdio.h>
  99808. typedef struct {
  99809. int ln;
  99810. int m;
  99811. int **linearmap;
  99812. int n[2];
  99813. vorbis_info_floor0 *vi;
  99814. long bits;
  99815. long frames;
  99816. } vorbis_look_floor0;
  99817. static void floor0_free_info(vorbis_info_floor *i){
  99818. vorbis_info_floor0 *info=(vorbis_info_floor0 *)i;
  99819. if(info){
  99820. memset(info,0,sizeof(*info));
  99821. _ogg_free(info);
  99822. }
  99823. }
  99824. static void floor0_free_look(vorbis_look_floor *i){
  99825. vorbis_look_floor0 *look=(vorbis_look_floor0 *)i;
  99826. if(look){
  99827. if(look->linearmap){
  99828. if(look->linearmap[0])_ogg_free(look->linearmap[0]);
  99829. if(look->linearmap[1])_ogg_free(look->linearmap[1]);
  99830. _ogg_free(look->linearmap);
  99831. }
  99832. memset(look,0,sizeof(*look));
  99833. _ogg_free(look);
  99834. }
  99835. }
  99836. static vorbis_info_floor *floor0_unpack (vorbis_info *vi,oggpack_buffer *opb){
  99837. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  99838. int j;
  99839. vorbis_info_floor0 *info=(vorbis_info_floor0*)_ogg_malloc(sizeof(*info));
  99840. info->order=oggpack_read(opb,8);
  99841. info->rate=oggpack_read(opb,16);
  99842. info->barkmap=oggpack_read(opb,16);
  99843. info->ampbits=oggpack_read(opb,6);
  99844. info->ampdB=oggpack_read(opb,8);
  99845. info->numbooks=oggpack_read(opb,4)+1;
  99846. if(info->order<1)goto err_out;
  99847. if(info->rate<1)goto err_out;
  99848. if(info->barkmap<1)goto err_out;
  99849. if(info->numbooks<1)goto err_out;
  99850. for(j=0;j<info->numbooks;j++){
  99851. info->books[j]=oggpack_read(opb,8);
  99852. if(info->books[j]<0 || info->books[j]>=ci->books)goto err_out;
  99853. }
  99854. return(info);
  99855. err_out:
  99856. floor0_free_info(info);
  99857. return(NULL);
  99858. }
  99859. static void floor0_map_lazy_init(vorbis_block *vb,
  99860. vorbis_info_floor *infoX,
  99861. vorbis_look_floor0 *look){
  99862. if(!look->linearmap[vb->W]){
  99863. vorbis_dsp_state *vd=vb->vd;
  99864. vorbis_info *vi=vd->vi;
  99865. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  99866. vorbis_info_floor0 *info=(vorbis_info_floor0 *)infoX;
  99867. int W=vb->W;
  99868. int n=ci->blocksizes[W]/2,j;
  99869. float scale=look->ln/toBARK(info->rate/2.f);
  99870. look->linearmap[W]=(int*)_ogg_malloc((n+1)*sizeof(**look->linearmap));
  99871. for(j=0;j<n;j++){
  99872. int val=floor( toBARK((info->rate/2.f)/n*j)
  99873. *scale); /* bark numbers represent band edges */
  99874. if(val>=look->ln)val=look->ln-1; /* guard against the approximation */
  99875. look->linearmap[W][j]=val;
  99876. }
  99877. look->linearmap[W][j]=-1;
  99878. look->n[W]=n;
  99879. }
  99880. }
  99881. static vorbis_look_floor *floor0_look(vorbis_dsp_state *vd,
  99882. vorbis_info_floor *i){
  99883. vorbis_info_floor0 *info=(vorbis_info_floor0*)i;
  99884. vorbis_look_floor0 *look=(vorbis_look_floor0*)_ogg_calloc(1,sizeof(*look));
  99885. look->m=info->order;
  99886. look->ln=info->barkmap;
  99887. look->vi=info;
  99888. look->linearmap=(int**)_ogg_calloc(2,sizeof(*look->linearmap));
  99889. return look;
  99890. }
  99891. static void *floor0_inverse1(vorbis_block *vb,vorbis_look_floor *i){
  99892. vorbis_look_floor0 *look=(vorbis_look_floor0 *)i;
  99893. vorbis_info_floor0 *info=look->vi;
  99894. int j,k;
  99895. int ampraw=oggpack_read(&vb->opb,info->ampbits);
  99896. if(ampraw>0){ /* also handles the -1 out of data case */
  99897. long maxval=(1<<info->ampbits)-1;
  99898. float amp=(float)ampraw/maxval*info->ampdB;
  99899. int booknum=oggpack_read(&vb->opb,_ilog(info->numbooks));
  99900. if(booknum!=-1 && booknum<info->numbooks){ /* be paranoid */
  99901. codec_setup_info *ci=(codec_setup_info *)vb->vd->vi->codec_setup;
  99902. codebook *b=ci->fullbooks+info->books[booknum];
  99903. float last=0.f;
  99904. float *lsp=(float*)_vorbis_block_alloc(vb,sizeof(*lsp)*(look->m+b->dim+1));
  99905. for(j=0;j<look->m;j+=b->dim)
  99906. if(vorbis_book_decodev_set(b,lsp+j,&vb->opb,b->dim)==-1)goto eop;
  99907. for(j=0;j<look->m;){
  99908. for(k=0;k<b->dim;k++,j++)lsp[j]+=last;
  99909. last=lsp[j-1];
  99910. }
  99911. lsp[look->m]=amp;
  99912. return(lsp);
  99913. }
  99914. }
  99915. eop:
  99916. return(NULL);
  99917. }
  99918. static int floor0_inverse2(vorbis_block *vb,vorbis_look_floor *i,
  99919. void *memo,float *out){
  99920. vorbis_look_floor0 *look=(vorbis_look_floor0 *)i;
  99921. vorbis_info_floor0 *info=look->vi;
  99922. floor0_map_lazy_init(vb,info,look);
  99923. if(memo){
  99924. float *lsp=(float *)memo;
  99925. float amp=lsp[look->m];
  99926. vorbis_lsp_to_curve(out,
  99927. look->linearmap[vb->W],
  99928. look->n[vb->W],
  99929. look->ln,
  99930. lsp,look->m,amp,(float)info->ampdB);
  99931. return(1);
  99932. }
  99933. memset(out,0,sizeof(*out)*look->n[vb->W]);
  99934. return(0);
  99935. }
  99936. vorbis_func_floor floor0_exportbundle={
  99937. NULL,&floor0_unpack,&floor0_look,&floor0_free_info,
  99938. &floor0_free_look,&floor0_inverse1,&floor0_inverse2
  99939. };
  99940. #endif
  99941. /********* End of inlined file: floor0.c *********/
  99942. /********* Start of inlined file: floor1.c *********/
  99943. /********* Start of inlined file: juce_OggVorbisHeader.h *********/
  99944. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  99945. // tasks..
  99946. #if JUCE_MSVC
  99947. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  99948. #endif
  99949. /********* End of inlined file: juce_OggVorbisHeader.h *********/
  99950. #if JUCE_USE_OGGVORBIS
  99951. #include <stdlib.h>
  99952. #include <string.h>
  99953. #include <math.h>
  99954. #include <stdio.h>
  99955. #define floor1_rangedB 140 /* floor 1 fixed at -140dB to 0dB range */
  99956. typedef struct {
  99957. int sorted_index[VIF_POSIT+2];
  99958. int forward_index[VIF_POSIT+2];
  99959. int reverse_index[VIF_POSIT+2];
  99960. int hineighbor[VIF_POSIT];
  99961. int loneighbor[VIF_POSIT];
  99962. int posts;
  99963. int n;
  99964. int quant_q;
  99965. vorbis_info_floor1 *vi;
  99966. long phrasebits;
  99967. long postbits;
  99968. long frames;
  99969. } vorbis_look_floor1;
  99970. typedef struct lsfit_acc{
  99971. long x0;
  99972. long x1;
  99973. long xa;
  99974. long ya;
  99975. long x2a;
  99976. long y2a;
  99977. long xya;
  99978. long an;
  99979. } lsfit_acc;
  99980. static void floor1_free_info(vorbis_info_floor *i){
  99981. vorbis_info_floor1 *info=(vorbis_info_floor1 *)i;
  99982. if(info){
  99983. memset(info,0,sizeof(*info));
  99984. _ogg_free(info);
  99985. }
  99986. }
  99987. static void floor1_free_look(vorbis_look_floor *i){
  99988. vorbis_look_floor1 *look=(vorbis_look_floor1 *)i;
  99989. if(look){
  99990. memset(look,0,sizeof(*look));
  99991. _ogg_free(look);
  99992. }
  99993. }
  99994. static void floor1_pack (vorbis_info_floor *i,oggpack_buffer *opb){
  99995. vorbis_info_floor1 *info=(vorbis_info_floor1 *)i;
  99996. int j,k;
  99997. int count=0;
  99998. int rangebits;
  99999. int maxposit=info->postlist[1];
  100000. int maxclass=-1;
  100001. oggpack_write(opb,info->partitions,5); /* only 0 to 31 legal */
  100002. for(j=0;j<info->partitions;j++){
  100003. oggpack_write(opb,info->partitionclass[j],4); /* only 0 to 15 legal */
  100004. if(maxclass<info->partitionclass[j])maxclass=info->partitionclass[j];
  100005. }
  100006. for(j=0;j<maxclass+1;j++){
  100007. oggpack_write(opb,info->class_dim[j]-1,3); /* 1 to 8 */
  100008. oggpack_write(opb,info->class_subs[j],2); /* 0 to 3 */
  100009. if(info->class_subs[j])oggpack_write(opb,info->class_book[j],8);
  100010. for(k=0;k<(1<<info->class_subs[j]);k++)
  100011. oggpack_write(opb,info->class_subbook[j][k]+1,8);
  100012. }
  100013. oggpack_write(opb,info->mult-1,2); /* only 1,2,3,4 legal now */
  100014. oggpack_write(opb,ilog2(maxposit),4);
  100015. rangebits=ilog2(maxposit);
  100016. for(j=0,k=0;j<info->partitions;j++){
  100017. count+=info->class_dim[info->partitionclass[j]];
  100018. for(;k<count;k++)
  100019. oggpack_write(opb,info->postlist[k+2],rangebits);
  100020. }
  100021. }
  100022. static vorbis_info_floor *floor1_unpack (vorbis_info *vi,oggpack_buffer *opb){
  100023. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  100024. int j,k,count=0,maxclass=-1,rangebits;
  100025. vorbis_info_floor1 *info=(vorbis_info_floor1*)_ogg_calloc(1,sizeof(*info));
  100026. info->partitions=oggpack_read(opb,5); /* only 0 to 31 legal */
  100027. for(j=0;j<info->partitions;j++){
  100028. info->partitionclass[j]=oggpack_read(opb,4); /* only 0 to 15 legal */
  100029. if(maxclass<info->partitionclass[j])maxclass=info->partitionclass[j];
  100030. }
  100031. for(j=0;j<maxclass+1;j++){
  100032. info->class_dim[j]=oggpack_read(opb,3)+1; /* 1 to 8 */
  100033. info->class_subs[j]=oggpack_read(opb,2); /* 0,1,2,3 bits */
  100034. if(info->class_subs[j]<0)
  100035. goto err_out;
  100036. if(info->class_subs[j])info->class_book[j]=oggpack_read(opb,8);
  100037. if(info->class_book[j]<0 || info->class_book[j]>=ci->books)
  100038. goto err_out;
  100039. for(k=0;k<(1<<info->class_subs[j]);k++){
  100040. info->class_subbook[j][k]=oggpack_read(opb,8)-1;
  100041. if(info->class_subbook[j][k]<-1 || info->class_subbook[j][k]>=ci->books)
  100042. goto err_out;
  100043. }
  100044. }
  100045. info->mult=oggpack_read(opb,2)+1; /* only 1,2,3,4 legal now */
  100046. rangebits=oggpack_read(opb,4);
  100047. for(j=0,k=0;j<info->partitions;j++){
  100048. count+=info->class_dim[info->partitionclass[j]];
  100049. for(;k<count;k++){
  100050. int t=info->postlist[k+2]=oggpack_read(opb,rangebits);
  100051. if(t<0 || t>=(1<<rangebits))
  100052. goto err_out;
  100053. }
  100054. }
  100055. info->postlist[0]=0;
  100056. info->postlist[1]=1<<rangebits;
  100057. return(info);
  100058. err_out:
  100059. floor1_free_info(info);
  100060. return(NULL);
  100061. }
  100062. static int icomp(const void *a,const void *b){
  100063. return(**(int **)a-**(int **)b);
  100064. }
  100065. static vorbis_look_floor *floor1_look(vorbis_dsp_state *vd,
  100066. vorbis_info_floor *in){
  100067. int *sortpointer[VIF_POSIT+2];
  100068. vorbis_info_floor1 *info=(vorbis_info_floor1*)in;
  100069. vorbis_look_floor1 *look=(vorbis_look_floor1*)_ogg_calloc(1,sizeof(*look));
  100070. int i,j,n=0;
  100071. look->vi=info;
  100072. look->n=info->postlist[1];
  100073. for(i=0;i<info->partitions;i++)n+=info->class_dim[info->partitionclass[i]];
  100074. n+=2;
  100075. look->posts=n;
  100076. for(i=0;i<n;i++)sortpointer[i]=info->postlist+i;
  100077. qsort(sortpointer,n,sizeof(*sortpointer),icomp);
  100078. for(i=0;i<n;i++)look->forward_index[i]=sortpointer[i]-info->postlist;
  100079. for(i=0;i<n;i++)look->reverse_index[look->forward_index[i]]=i;
  100080. for(i=0;i<n;i++)look->sorted_index[i]=info->postlist[look->forward_index[i]];
  100081. switch(info->mult){
  100082. case 1: /* 1024 -> 256 */
  100083. look->quant_q=256;
  100084. break;
  100085. case 2: /* 1024 -> 128 */
  100086. look->quant_q=128;
  100087. break;
  100088. case 3: /* 1024 -> 86 */
  100089. look->quant_q=86;
  100090. break;
  100091. case 4: /* 1024 -> 64 */
  100092. look->quant_q=64;
  100093. break;
  100094. }
  100095. for(i=0;i<n-2;i++){
  100096. int lo=0;
  100097. int hi=1;
  100098. int lx=0;
  100099. int hx=look->n;
  100100. int currentx=info->postlist[i+2];
  100101. for(j=0;j<i+2;j++){
  100102. int x=info->postlist[j];
  100103. if(x>lx && x<currentx){
  100104. lo=j;
  100105. lx=x;
  100106. }
  100107. if(x<hx && x>currentx){
  100108. hi=j;
  100109. hx=x;
  100110. }
  100111. }
  100112. look->loneighbor[i]=lo;
  100113. look->hineighbor[i]=hi;
  100114. }
  100115. return(look);
  100116. }
  100117. static int render_point(int x0,int x1,int y0,int y1,int x){
  100118. y0&=0x7fff; /* mask off flag */
  100119. y1&=0x7fff;
  100120. {
  100121. int dy=y1-y0;
  100122. int adx=x1-x0;
  100123. int ady=abs(dy);
  100124. int err=ady*(x-x0);
  100125. int off=err/adx;
  100126. if(dy<0)return(y0-off);
  100127. return(y0+off);
  100128. }
  100129. }
  100130. static int vorbis_dBquant(const float *x){
  100131. int i= *x*7.3142857f+1023.5f;
  100132. if(i>1023)return(1023);
  100133. if(i<0)return(0);
  100134. return i;
  100135. }
  100136. static float FLOOR1_fromdB_LOOKUP[256]={
  100137. 1.0649863e-07F, 1.1341951e-07F, 1.2079015e-07F, 1.2863978e-07F,
  100138. 1.3699951e-07F, 1.4590251e-07F, 1.5538408e-07F, 1.6548181e-07F,
  100139. 1.7623575e-07F, 1.8768855e-07F, 1.9988561e-07F, 2.128753e-07F,
  100140. 2.2670913e-07F, 2.4144197e-07F, 2.5713223e-07F, 2.7384213e-07F,
  100141. 2.9163793e-07F, 3.1059021e-07F, 3.3077411e-07F, 3.5226968e-07F,
  100142. 3.7516214e-07F, 3.9954229e-07F, 4.2550680e-07F, 4.5315863e-07F,
  100143. 4.8260743e-07F, 5.1396998e-07F, 5.4737065e-07F, 5.8294187e-07F,
  100144. 6.2082472e-07F, 6.6116941e-07F, 7.0413592e-07F, 7.4989464e-07F,
  100145. 7.9862701e-07F, 8.5052630e-07F, 9.0579828e-07F, 9.6466216e-07F,
  100146. 1.0273513e-06F, 1.0941144e-06F, 1.1652161e-06F, 1.2409384e-06F,
  100147. 1.3215816e-06F, 1.4074654e-06F, 1.4989305e-06F, 1.5963394e-06F,
  100148. 1.7000785e-06F, 1.8105592e-06F, 1.9282195e-06F, 2.0535261e-06F,
  100149. 2.1869758e-06F, 2.3290978e-06F, 2.4804557e-06F, 2.6416497e-06F,
  100150. 2.8133190e-06F, 2.9961443e-06F, 3.1908506e-06F, 3.3982101e-06F,
  100151. 3.6190449e-06F, 3.8542308e-06F, 4.1047004e-06F, 4.3714470e-06F,
  100152. 4.6555282e-06F, 4.9580707e-06F, 5.2802740e-06F, 5.6234160e-06F,
  100153. 5.9888572e-06F, 6.3780469e-06F, 6.7925283e-06F, 7.2339451e-06F,
  100154. 7.7040476e-06F, 8.2047000e-06F, 8.7378876e-06F, 9.3057248e-06F,
  100155. 9.9104632e-06F, 1.0554501e-05F, 1.1240392e-05F, 1.1970856e-05F,
  100156. 1.2748789e-05F, 1.3577278e-05F, 1.4459606e-05F, 1.5399272e-05F,
  100157. 1.6400004e-05F, 1.7465768e-05F, 1.8600792e-05F, 1.9809576e-05F,
  100158. 2.1096914e-05F, 2.2467911e-05F, 2.3928002e-05F, 2.5482978e-05F,
  100159. 2.7139006e-05F, 2.8902651e-05F, 3.0780908e-05F, 3.2781225e-05F,
  100160. 3.4911534e-05F, 3.7180282e-05F, 3.9596466e-05F, 4.2169667e-05F,
  100161. 4.4910090e-05F, 4.7828601e-05F, 5.0936773e-05F, 5.4246931e-05F,
  100162. 5.7772202e-05F, 6.1526565e-05F, 6.5524908e-05F, 6.9783085e-05F,
  100163. 7.4317983e-05F, 7.9147585e-05F, 8.4291040e-05F, 8.9768747e-05F,
  100164. 9.5602426e-05F, 0.00010181521F, 0.00010843174F, 0.00011547824F,
  100165. 0.00012298267F, 0.00013097477F, 0.00013948625F, 0.00014855085F,
  100166. 0.00015820453F, 0.00016848555F, 0.00017943469F, 0.00019109536F,
  100167. 0.00020351382F, 0.00021673929F, 0.00023082423F, 0.00024582449F,
  100168. 0.00026179955F, 0.00027881276F, 0.00029693158F, 0.00031622787F,
  100169. 0.00033677814F, 0.00035866388F, 0.00038197188F, 0.00040679456F,
  100170. 0.00043323036F, 0.00046138411F, 0.00049136745F, 0.00052329927F,
  100171. 0.00055730621F, 0.00059352311F, 0.00063209358F, 0.00067317058F,
  100172. 0.00071691700F, 0.00076350630F, 0.00081312324F, 0.00086596457F,
  100173. 0.00092223983F, 0.00098217216F, 0.0010459992F, 0.0011139742F,
  100174. 0.0011863665F, 0.0012634633F, 0.0013455702F, 0.0014330129F,
  100175. 0.0015261382F, 0.0016253153F, 0.0017309374F, 0.0018434235F,
  100176. 0.0019632195F, 0.0020908006F, 0.0022266726F, 0.0023713743F,
  100177. 0.0025254795F, 0.0026895994F, 0.0028643847F, 0.0030505286F,
  100178. 0.0032487691F, 0.0034598925F, 0.0036847358F, 0.0039241906F,
  100179. 0.0041792066F, 0.0044507950F, 0.0047400328F, 0.0050480668F,
  100180. 0.0053761186F, 0.0057254891F, 0.0060975636F, 0.0064938176F,
  100181. 0.0069158225F, 0.0073652516F, 0.0078438871F, 0.0083536271F,
  100182. 0.0088964928F, 0.009474637F, 0.010090352F, 0.010746080F,
  100183. 0.011444421F, 0.012188144F, 0.012980198F, 0.013823725F,
  100184. 0.014722068F, 0.015678791F, 0.016697687F, 0.017782797F,
  100185. 0.018938423F, 0.020169149F, 0.021479854F, 0.022875735F,
  100186. 0.024362330F, 0.025945531F, 0.027631618F, 0.029427276F,
  100187. 0.031339626F, 0.033376252F, 0.035545228F, 0.037855157F,
  100188. 0.040315199F, 0.042935108F, 0.045725273F, 0.048696758F,
  100189. 0.051861348F, 0.055231591F, 0.058820850F, 0.062643361F,
  100190. 0.066714279F, 0.071049749F, 0.075666962F, 0.080584227F,
  100191. 0.085821044F, 0.091398179F, 0.097337747F, 0.10366330F,
  100192. 0.11039993F, 0.11757434F, 0.12521498F, 0.13335215F,
  100193. 0.14201813F, 0.15124727F, 0.16107617F, 0.17154380F,
  100194. 0.18269168F, 0.19456402F, 0.20720788F, 0.22067342F,
  100195. 0.23501402F, 0.25028656F, 0.26655159F, 0.28387361F,
  100196. 0.30232132F, 0.32196786F, 0.34289114F, 0.36517414F,
  100197. 0.38890521F, 0.41417847F, 0.44109412F, 0.46975890F,
  100198. 0.50028648F, 0.53279791F, 0.56742212F, 0.60429640F,
  100199. 0.64356699F, 0.68538959F, 0.72993007F, 0.77736504F,
  100200. 0.82788260F, 0.88168307F, 0.9389798F, 1.F,
  100201. };
  100202. static void render_line(int x0,int x1,int y0,int y1,float *d){
  100203. int dy=y1-y0;
  100204. int adx=x1-x0;
  100205. int ady=abs(dy);
  100206. int base=dy/adx;
  100207. int sy=(dy<0?base-1:base+1);
  100208. int x=x0;
  100209. int y=y0;
  100210. int err=0;
  100211. ady-=abs(base*adx);
  100212. d[x]*=FLOOR1_fromdB_LOOKUP[y];
  100213. while(++x<x1){
  100214. err=err+ady;
  100215. if(err>=adx){
  100216. err-=adx;
  100217. y+=sy;
  100218. }else{
  100219. y+=base;
  100220. }
  100221. d[x]*=FLOOR1_fromdB_LOOKUP[y];
  100222. }
  100223. }
  100224. static void render_line0(int x0,int x1,int y0,int y1,int *d){
  100225. int dy=y1-y0;
  100226. int adx=x1-x0;
  100227. int ady=abs(dy);
  100228. int base=dy/adx;
  100229. int sy=(dy<0?base-1:base+1);
  100230. int x=x0;
  100231. int y=y0;
  100232. int err=0;
  100233. ady-=abs(base*adx);
  100234. d[x]=y;
  100235. while(++x<x1){
  100236. err=err+ady;
  100237. if(err>=adx){
  100238. err-=adx;
  100239. y+=sy;
  100240. }else{
  100241. y+=base;
  100242. }
  100243. d[x]=y;
  100244. }
  100245. }
  100246. static int accumulate_fit(const float *flr,const float *mdct,
  100247. int x0, int x1,lsfit_acc *a,
  100248. int n,vorbis_info_floor1 *info){
  100249. long i;
  100250. 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;
  100251. memset(a,0,sizeof(*a));
  100252. a->x0=x0;
  100253. a->x1=x1;
  100254. if(x1>=n)x1=n-1;
  100255. for(i=x0;i<=x1;i++){
  100256. int quantized=vorbis_dBquant(flr+i);
  100257. if(quantized){
  100258. if(mdct[i]+info->twofitatten>=flr[i]){
  100259. xa += i;
  100260. ya += quantized;
  100261. x2a += i*i;
  100262. y2a += quantized*quantized;
  100263. xya += i*quantized;
  100264. na++;
  100265. }else{
  100266. xb += i;
  100267. yb += quantized;
  100268. x2b += i*i;
  100269. y2b += quantized*quantized;
  100270. xyb += i*quantized;
  100271. nb++;
  100272. }
  100273. }
  100274. }
  100275. xb+=xa;
  100276. yb+=ya;
  100277. x2b+=x2a;
  100278. y2b+=y2a;
  100279. xyb+=xya;
  100280. nb+=na;
  100281. {
  100282. int weight=nb*info->twofitweight/(na+1);
  100283. a->xa=xa*weight+xb;
  100284. a->ya=ya*weight+yb;
  100285. a->x2a=x2a*weight+x2b;
  100286. a->y2a=y2a*weight+y2b;
  100287. a->xya=xya*weight+xyb;
  100288. a->an=na*weight+nb;
  100289. }
  100290. return(na);
  100291. }
  100292. static void fit_line(lsfit_acc *a,int fits,int *y0,int *y1){
  100293. long x=0,y=0,x2=0,y2=0,xy=0,an=0,i;
  100294. long x0=a[0].x0;
  100295. long x1=a[fits-1].x1;
  100296. for(i=0;i<fits;i++){
  100297. x+=a[i].xa;
  100298. y+=a[i].ya;
  100299. x2+=a[i].x2a;
  100300. y2+=a[i].y2a;
  100301. xy+=a[i].xya;
  100302. an+=a[i].an;
  100303. }
  100304. if(*y0>=0){
  100305. x+= x0;
  100306. y+= *y0;
  100307. x2+= x0 * x0;
  100308. y2+= *y0 * *y0;
  100309. xy+= *y0 * x0;
  100310. an++;
  100311. }
  100312. if(*y1>=0){
  100313. x+= x1;
  100314. y+= *y1;
  100315. x2+= x1 * x1;
  100316. y2+= *y1 * *y1;
  100317. xy+= *y1 * x1;
  100318. an++;
  100319. }
  100320. if(an){
  100321. double fx=x;
  100322. double fy=y;
  100323. double fx2=x2;
  100324. double fxy=xy;
  100325. double denom=1./(an*fx2-fx*fx);
  100326. double a=(fy*fx2-fxy*fx)*denom;
  100327. double b=(an*fxy-fx*fy)*denom;
  100328. *y0=rint(a+b*x0);
  100329. *y1=rint(a+b*x1);
  100330. if(*y0>1023)*y0=1023;
  100331. if(*y1>1023)*y1=1023;
  100332. if(*y0<0)*y0=0;
  100333. if(*y1<0)*y1=0;
  100334. }else{
  100335. *y0=0;
  100336. *y1=0;
  100337. }
  100338. }
  100339. static int inspect_error(int x0,int x1,int y0,int y1,const float *mask,
  100340. const float *mdct,
  100341. vorbis_info_floor1 *info){
  100342. int dy=y1-y0;
  100343. int adx=x1-x0;
  100344. int ady=abs(dy);
  100345. int base=dy/adx;
  100346. int sy=(dy<0?base-1:base+1);
  100347. int x=x0;
  100348. int y=y0;
  100349. int err=0;
  100350. int val=vorbis_dBquant(mask+x);
  100351. int mse=0;
  100352. int n=0;
  100353. ady-=abs(base*adx);
  100354. mse=(y-val);
  100355. mse*=mse;
  100356. n++;
  100357. if(mdct[x]+info->twofitatten>=mask[x]){
  100358. if(y+info->maxover<val)return(1);
  100359. if(y-info->maxunder>val)return(1);
  100360. }
  100361. while(++x<x1){
  100362. err=err+ady;
  100363. if(err>=adx){
  100364. err-=adx;
  100365. y+=sy;
  100366. }else{
  100367. y+=base;
  100368. }
  100369. val=vorbis_dBquant(mask+x);
  100370. mse+=((y-val)*(y-val));
  100371. n++;
  100372. if(mdct[x]+info->twofitatten>=mask[x]){
  100373. if(val){
  100374. if(y+info->maxover<val)return(1);
  100375. if(y-info->maxunder>val)return(1);
  100376. }
  100377. }
  100378. }
  100379. if(info->maxover*info->maxover/n>info->maxerr)return(0);
  100380. if(info->maxunder*info->maxunder/n>info->maxerr)return(0);
  100381. if(mse/n>info->maxerr)return(1);
  100382. return(0);
  100383. }
  100384. static int post_Y(int *A,int *B,int pos){
  100385. if(A[pos]<0)
  100386. return B[pos];
  100387. if(B[pos]<0)
  100388. return A[pos];
  100389. return (A[pos]+B[pos])>>1;
  100390. }
  100391. int *floor1_fit(vorbis_block *vb,void *look_,
  100392. const float *logmdct, /* in */
  100393. const float *logmask){
  100394. long i,j;
  100395. vorbis_look_floor1 *look = (vorbis_look_floor1*) look_;
  100396. vorbis_info_floor1 *info=look->vi;
  100397. long n=look->n;
  100398. long posts=look->posts;
  100399. long nonzero=0;
  100400. lsfit_acc fits[VIF_POSIT+1];
  100401. int fit_valueA[VIF_POSIT+2]; /* index by range list position */
  100402. int fit_valueB[VIF_POSIT+2]; /* index by range list position */
  100403. int loneighbor[VIF_POSIT+2]; /* sorted index of range list position (+2) */
  100404. int hineighbor[VIF_POSIT+2];
  100405. int *output=NULL;
  100406. int memo[VIF_POSIT+2];
  100407. for(i=0;i<posts;i++)fit_valueA[i]=-200; /* mark all unused */
  100408. for(i=0;i<posts;i++)fit_valueB[i]=-200; /* mark all unused */
  100409. for(i=0;i<posts;i++)loneighbor[i]=0; /* 0 for the implicit 0 post */
  100410. for(i=0;i<posts;i++)hineighbor[i]=1; /* 1 for the implicit post at n */
  100411. for(i=0;i<posts;i++)memo[i]=-1; /* no neighbor yet */
  100412. if(posts==0){
  100413. nonzero+=accumulate_fit(logmask,logmdct,0,n,fits,n,info);
  100414. }else{
  100415. for(i=0;i<posts-1;i++)
  100416. nonzero+=accumulate_fit(logmask,logmdct,look->sorted_index[i],
  100417. look->sorted_index[i+1],fits+i,
  100418. n,info);
  100419. }
  100420. if(nonzero){
  100421. int y0=-200;
  100422. int y1=-200;
  100423. fit_line(fits,posts-1,&y0,&y1);
  100424. fit_valueA[0]=y0;
  100425. fit_valueB[0]=y0;
  100426. fit_valueB[1]=y1;
  100427. fit_valueA[1]=y1;
  100428. for(i=2;i<posts;i++){
  100429. int sortpos=look->reverse_index[i];
  100430. int ln=loneighbor[sortpos];
  100431. int hn=hineighbor[sortpos];
  100432. if(memo[ln]!=hn){
  100433. int lsortpos=look->reverse_index[ln];
  100434. int hsortpos=look->reverse_index[hn];
  100435. memo[ln]=hn;
  100436. {
  100437. int lx=info->postlist[ln];
  100438. int hx=info->postlist[hn];
  100439. int ly=post_Y(fit_valueA,fit_valueB,ln);
  100440. int hy=post_Y(fit_valueA,fit_valueB,hn);
  100441. if(ly==-1 || hy==-1){
  100442. exit(1);
  100443. }
  100444. if(inspect_error(lx,hx,ly,hy,logmask,logmdct,info)){
  100445. int ly0=-200;
  100446. int ly1=-200;
  100447. int hy0=-200;
  100448. int hy1=-200;
  100449. fit_line(fits+lsortpos,sortpos-lsortpos,&ly0,&ly1);
  100450. fit_line(fits+sortpos,hsortpos-sortpos,&hy0,&hy1);
  100451. fit_valueB[ln]=ly0;
  100452. if(ln==0)fit_valueA[ln]=ly0;
  100453. fit_valueA[i]=ly1;
  100454. fit_valueB[i]=hy0;
  100455. fit_valueA[hn]=hy1;
  100456. if(hn==1)fit_valueB[hn]=hy1;
  100457. if(ly1>=0 || hy0>=0){
  100458. for(j=sortpos-1;j>=0;j--)
  100459. if(hineighbor[j]==hn)
  100460. hineighbor[j]=i;
  100461. else
  100462. break;
  100463. for(j=sortpos+1;j<posts;j++)
  100464. if(loneighbor[j]==ln)
  100465. loneighbor[j]=i;
  100466. else
  100467. break;
  100468. }
  100469. }else{
  100470. fit_valueA[i]=-200;
  100471. fit_valueB[i]=-200;
  100472. }
  100473. }
  100474. }
  100475. }
  100476. output=(int*)_vorbis_block_alloc(vb,sizeof(*output)*posts);
  100477. output[0]=post_Y(fit_valueA,fit_valueB,0);
  100478. output[1]=post_Y(fit_valueA,fit_valueB,1);
  100479. for(i=2;i<posts;i++){
  100480. int ln=look->loneighbor[i-2];
  100481. int hn=look->hineighbor[i-2];
  100482. int x0=info->postlist[ln];
  100483. int x1=info->postlist[hn];
  100484. int y0=output[ln];
  100485. int y1=output[hn];
  100486. int predicted=render_point(x0,x1,y0,y1,info->postlist[i]);
  100487. int vx=post_Y(fit_valueA,fit_valueB,i);
  100488. if(vx>=0 && predicted!=vx){
  100489. output[i]=vx;
  100490. }else{
  100491. output[i]= predicted|0x8000;
  100492. }
  100493. }
  100494. }
  100495. return(output);
  100496. }
  100497. int *floor1_interpolate_fit(vorbis_block *vb,void *look_,
  100498. int *A,int *B,
  100499. int del){
  100500. long i;
  100501. vorbis_look_floor1* look = (vorbis_look_floor1*) look_;
  100502. long posts=look->posts;
  100503. int *output=NULL;
  100504. if(A && B){
  100505. output=(int*)_vorbis_block_alloc(vb,sizeof(*output)*posts);
  100506. for(i=0;i<posts;i++){
  100507. output[i]=((65536-del)*(A[i]&0x7fff)+del*(B[i]&0x7fff)+32768)>>16;
  100508. if(A[i]&0x8000 && B[i]&0x8000)output[i]|=0x8000;
  100509. }
  100510. }
  100511. return(output);
  100512. }
  100513. int floor1_encode(oggpack_buffer *opb,vorbis_block *vb,
  100514. void*look_,
  100515. int *post,int *ilogmask){
  100516. long i,j;
  100517. vorbis_look_floor1 *look = (vorbis_look_floor1 *) look_;
  100518. vorbis_info_floor1 *info=look->vi;
  100519. long posts=look->posts;
  100520. codec_setup_info *ci=(codec_setup_info*)vb->vd->vi->codec_setup;
  100521. int out[VIF_POSIT+2];
  100522. static_codebook **sbooks=ci->book_param;
  100523. codebook *books=ci->fullbooks;
  100524. static long seq=0;
  100525. if(post){
  100526. for(i=0;i<posts;i++){
  100527. int val=post[i]&0x7fff;
  100528. switch(info->mult){
  100529. case 1: /* 1024 -> 256 */
  100530. val>>=2;
  100531. break;
  100532. case 2: /* 1024 -> 128 */
  100533. val>>=3;
  100534. break;
  100535. case 3: /* 1024 -> 86 */
  100536. val/=12;
  100537. break;
  100538. case 4: /* 1024 -> 64 */
  100539. val>>=4;
  100540. break;
  100541. }
  100542. post[i]=val | (post[i]&0x8000);
  100543. }
  100544. out[0]=post[0];
  100545. out[1]=post[1];
  100546. for(i=2;i<posts;i++){
  100547. int ln=look->loneighbor[i-2];
  100548. int hn=look->hineighbor[i-2];
  100549. int x0=info->postlist[ln];
  100550. int x1=info->postlist[hn];
  100551. int y0=post[ln];
  100552. int y1=post[hn];
  100553. int predicted=render_point(x0,x1,y0,y1,info->postlist[i]);
  100554. if((post[i]&0x8000) || (predicted==post[i])){
  100555. post[i]=predicted|0x8000; /* in case there was roundoff jitter
  100556. in interpolation */
  100557. out[i]=0;
  100558. }else{
  100559. int headroom=(look->quant_q-predicted<predicted?
  100560. look->quant_q-predicted:predicted);
  100561. int val=post[i]-predicted;
  100562. if(val<0)
  100563. if(val<-headroom)
  100564. val=headroom-val-1;
  100565. else
  100566. val=-1-(val<<1);
  100567. else
  100568. if(val>=headroom)
  100569. val= val+headroom;
  100570. else
  100571. val<<=1;
  100572. out[i]=val;
  100573. post[ln]&=0x7fff;
  100574. post[hn]&=0x7fff;
  100575. }
  100576. }
  100577. oggpack_write(opb,1,1);
  100578. look->frames++;
  100579. look->postbits+=ilog(look->quant_q-1)*2;
  100580. oggpack_write(opb,out[0],ilog(look->quant_q-1));
  100581. oggpack_write(opb,out[1],ilog(look->quant_q-1));
  100582. for(i=0,j=2;i<info->partitions;i++){
  100583. int classx=info->partitionclass[i];
  100584. int cdim=info->class_dim[classx];
  100585. int csubbits=info->class_subs[classx];
  100586. int csub=1<<csubbits;
  100587. int bookas[8]={0,0,0,0,0,0,0,0};
  100588. int cval=0;
  100589. int cshift=0;
  100590. int k,l;
  100591. if(csubbits){
  100592. int maxval[8];
  100593. for(k=0;k<csub;k++){
  100594. int booknum=info->class_subbook[classx][k];
  100595. if(booknum<0){
  100596. maxval[k]=1;
  100597. }else{
  100598. maxval[k]=sbooks[info->class_subbook[classx][k]]->entries;
  100599. }
  100600. }
  100601. for(k=0;k<cdim;k++){
  100602. for(l=0;l<csub;l++){
  100603. int val=out[j+k];
  100604. if(val<maxval[l]){
  100605. bookas[k]=l;
  100606. break;
  100607. }
  100608. }
  100609. cval|= bookas[k]<<cshift;
  100610. cshift+=csubbits;
  100611. }
  100612. look->phrasebits+=
  100613. vorbis_book_encode(books+info->class_book[classx],cval,opb);
  100614. #ifdef TRAIN_FLOOR1
  100615. {
  100616. FILE *of;
  100617. char buffer[80];
  100618. sprintf(buffer,"line_%dx%ld_class%d.vqd",
  100619. vb->pcmend/2,posts-2,class);
  100620. of=fopen(buffer,"a");
  100621. fprintf(of,"%d\n",cval);
  100622. fclose(of);
  100623. }
  100624. #endif
  100625. }
  100626. for(k=0;k<cdim;k++){
  100627. int book=info->class_subbook[classx][bookas[k]];
  100628. if(book>=0){
  100629. if(out[j+k]<(books+book)->entries)
  100630. look->postbits+=vorbis_book_encode(books+book,
  100631. out[j+k],opb);
  100632. #ifdef TRAIN_FLOOR1
  100633. {
  100634. FILE *of;
  100635. char buffer[80];
  100636. sprintf(buffer,"line_%dx%ld_%dsub%d.vqd",
  100637. vb->pcmend/2,posts-2,class,bookas[k]);
  100638. of=fopen(buffer,"a");
  100639. fprintf(of,"%d\n",out[j+k]);
  100640. fclose(of);
  100641. }
  100642. #endif
  100643. }
  100644. }
  100645. j+=cdim;
  100646. }
  100647. {
  100648. int hx=0;
  100649. int lx=0;
  100650. int ly=post[0]*info->mult;
  100651. for(j=1;j<look->posts;j++){
  100652. int current=look->forward_index[j];
  100653. int hy=post[current]&0x7fff;
  100654. if(hy==post[current]){
  100655. hy*=info->mult;
  100656. hx=info->postlist[current];
  100657. render_line0(lx,hx,ly,hy,ilogmask);
  100658. lx=hx;
  100659. ly=hy;
  100660. }
  100661. }
  100662. for(j=hx;j<vb->pcmend/2;j++)ilogmask[j]=ly; /* be certain */
  100663. seq++;
  100664. return(1);
  100665. }
  100666. }else{
  100667. oggpack_write(opb,0,1);
  100668. memset(ilogmask,0,vb->pcmend/2*sizeof(*ilogmask));
  100669. seq++;
  100670. return(0);
  100671. }
  100672. }
  100673. static void *floor1_inverse1(vorbis_block *vb,vorbis_look_floor *in){
  100674. vorbis_look_floor1 *look=(vorbis_look_floor1 *)in;
  100675. vorbis_info_floor1 *info=look->vi;
  100676. codec_setup_info *ci=(codec_setup_info*)vb->vd->vi->codec_setup;
  100677. int i,j,k;
  100678. codebook *books=ci->fullbooks;
  100679. if(oggpack_read(&vb->opb,1)==1){
  100680. int *fit_value=(int*)_vorbis_block_alloc(vb,(look->posts)*sizeof(*fit_value));
  100681. fit_value[0]=oggpack_read(&vb->opb,ilog(look->quant_q-1));
  100682. fit_value[1]=oggpack_read(&vb->opb,ilog(look->quant_q-1));
  100683. for(i=0,j=2;i<info->partitions;i++){
  100684. int classx=info->partitionclass[i];
  100685. int cdim=info->class_dim[classx];
  100686. int csubbits=info->class_subs[classx];
  100687. int csub=1<<csubbits;
  100688. int cval=0;
  100689. if(csubbits){
  100690. cval=vorbis_book_decode(books+info->class_book[classx],&vb->opb);
  100691. if(cval==-1)goto eop;
  100692. }
  100693. for(k=0;k<cdim;k++){
  100694. int book=info->class_subbook[classx][cval&(csub-1)];
  100695. cval>>=csubbits;
  100696. if(book>=0){
  100697. if((fit_value[j+k]=vorbis_book_decode(books+book,&vb->opb))==-1)
  100698. goto eop;
  100699. }else{
  100700. fit_value[j+k]=0;
  100701. }
  100702. }
  100703. j+=cdim;
  100704. }
  100705. for(i=2;i<look->posts;i++){
  100706. int predicted=render_point(info->postlist[look->loneighbor[i-2]],
  100707. info->postlist[look->hineighbor[i-2]],
  100708. fit_value[look->loneighbor[i-2]],
  100709. fit_value[look->hineighbor[i-2]],
  100710. info->postlist[i]);
  100711. int hiroom=look->quant_q-predicted;
  100712. int loroom=predicted;
  100713. int room=(hiroom<loroom?hiroom:loroom)<<1;
  100714. int val=fit_value[i];
  100715. if(val){
  100716. if(val>=room){
  100717. if(hiroom>loroom){
  100718. val = val-loroom;
  100719. }else{
  100720. val = -1-(val-hiroom);
  100721. }
  100722. }else{
  100723. if(val&1){
  100724. val= -((val+1)>>1);
  100725. }else{
  100726. val>>=1;
  100727. }
  100728. }
  100729. fit_value[i]=val+predicted;
  100730. fit_value[look->loneighbor[i-2]]&=0x7fff;
  100731. fit_value[look->hineighbor[i-2]]&=0x7fff;
  100732. }else{
  100733. fit_value[i]=predicted|0x8000;
  100734. }
  100735. }
  100736. return(fit_value);
  100737. }
  100738. eop:
  100739. return(NULL);
  100740. }
  100741. static int floor1_inverse2(vorbis_block *vb,vorbis_look_floor *in,void *memo,
  100742. float *out){
  100743. vorbis_look_floor1 *look=(vorbis_look_floor1 *)in;
  100744. vorbis_info_floor1 *info=look->vi;
  100745. codec_setup_info *ci=(codec_setup_info*)vb->vd->vi->codec_setup;
  100746. int n=ci->blocksizes[vb->W]/2;
  100747. int j;
  100748. if(memo){
  100749. int *fit_value=(int *)memo;
  100750. int hx=0;
  100751. int lx=0;
  100752. int ly=fit_value[0]*info->mult;
  100753. for(j=1;j<look->posts;j++){
  100754. int current=look->forward_index[j];
  100755. int hy=fit_value[current]&0x7fff;
  100756. if(hy==fit_value[current]){
  100757. hy*=info->mult;
  100758. hx=info->postlist[current];
  100759. render_line(lx,hx,ly,hy,out);
  100760. lx=hx;
  100761. ly=hy;
  100762. }
  100763. }
  100764. for(j=hx;j<n;j++)out[j]*=FLOOR1_fromdB_LOOKUP[ly]; /* be certain */
  100765. return(1);
  100766. }
  100767. memset(out,0,sizeof(*out)*n);
  100768. return(0);
  100769. }
  100770. vorbis_func_floor floor1_exportbundle={
  100771. &floor1_pack,&floor1_unpack,&floor1_look,&floor1_free_info,
  100772. &floor1_free_look,&floor1_inverse1,&floor1_inverse2
  100773. };
  100774. #endif
  100775. /********* End of inlined file: floor1.c *********/
  100776. /********* Start of inlined file: info.c *********/
  100777. /********* Start of inlined file: juce_OggVorbisHeader.h *********/
  100778. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  100779. // tasks..
  100780. #if JUCE_MSVC
  100781. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  100782. #endif
  100783. /********* End of inlined file: juce_OggVorbisHeader.h *********/
  100784. #if JUCE_USE_OGGVORBIS
  100785. #include <stdlib.h>
  100786. #include <string.h>
  100787. #include <ctype.h>
  100788. static void _v_writestring(oggpack_buffer *o, const char *s, int bytes){
  100789. while(bytes--){
  100790. oggpack_write(o,*s++,8);
  100791. }
  100792. }
  100793. static void _v_readstring(oggpack_buffer *o,char *buf,int bytes){
  100794. while(bytes--){
  100795. *buf++=oggpack_read(o,8);
  100796. }
  100797. }
  100798. void vorbis_comment_init(vorbis_comment *vc){
  100799. memset(vc,0,sizeof(*vc));
  100800. }
  100801. void vorbis_comment_add(vorbis_comment *vc,char *comment){
  100802. vc->user_comments=(char**)_ogg_realloc(vc->user_comments,
  100803. (vc->comments+2)*sizeof(*vc->user_comments));
  100804. vc->comment_lengths=(int*)_ogg_realloc(vc->comment_lengths,
  100805. (vc->comments+2)*sizeof(*vc->comment_lengths));
  100806. vc->comment_lengths[vc->comments]=strlen(comment);
  100807. vc->user_comments[vc->comments]=(char*)_ogg_malloc(vc->comment_lengths[vc->comments]+1);
  100808. strcpy(vc->user_comments[vc->comments], comment);
  100809. vc->comments++;
  100810. vc->user_comments[vc->comments]=NULL;
  100811. }
  100812. void vorbis_comment_add_tag(vorbis_comment *vc, const char *tag, char *contents){
  100813. char *comment=(char*)alloca(strlen(tag)+strlen(contents)+2); /* +2 for = and \0 */
  100814. strcpy(comment, tag);
  100815. strcat(comment, "=");
  100816. strcat(comment, contents);
  100817. vorbis_comment_add(vc, comment);
  100818. }
  100819. static int tagcompare(const char *s1, const char *s2, int n){
  100820. int c=0;
  100821. while(c < n){
  100822. if(toupper(s1[c]) != toupper(s2[c]))
  100823. return !0;
  100824. c++;
  100825. }
  100826. return 0;
  100827. }
  100828. char *vorbis_comment_query(vorbis_comment *vc, char *tag, int count){
  100829. long i;
  100830. int found = 0;
  100831. int taglen = strlen(tag)+1; /* +1 for the = we append */
  100832. char *fulltag = (char*)alloca(taglen+ 1);
  100833. strcpy(fulltag, tag);
  100834. strcat(fulltag, "=");
  100835. for(i=0;i<vc->comments;i++){
  100836. if(!tagcompare(vc->user_comments[i], fulltag, taglen)){
  100837. if(count == found)
  100838. return vc->user_comments[i] + taglen;
  100839. else
  100840. found++;
  100841. }
  100842. }
  100843. return NULL; /* didn't find anything */
  100844. }
  100845. int vorbis_comment_query_count(vorbis_comment *vc, char *tag){
  100846. int i,count=0;
  100847. int taglen = strlen(tag)+1; /* +1 for the = we append */
  100848. char *fulltag = (char*)alloca(taglen+1);
  100849. strcpy(fulltag,tag);
  100850. strcat(fulltag, "=");
  100851. for(i=0;i<vc->comments;i++){
  100852. if(!tagcompare(vc->user_comments[i], fulltag, taglen))
  100853. count++;
  100854. }
  100855. return count;
  100856. }
  100857. void vorbis_comment_clear(vorbis_comment *vc){
  100858. if(vc){
  100859. long i;
  100860. for(i=0;i<vc->comments;i++)
  100861. if(vc->user_comments[i])_ogg_free(vc->user_comments[i]);
  100862. if(vc->user_comments)_ogg_free(vc->user_comments);
  100863. if(vc->comment_lengths)_ogg_free(vc->comment_lengths);
  100864. if(vc->vendor)_ogg_free(vc->vendor);
  100865. }
  100866. memset(vc,0,sizeof(*vc));
  100867. }
  100868. int vorbis_info_blocksize(vorbis_info *vi,int zo){
  100869. codec_setup_info *ci = (codec_setup_info*)vi->codec_setup;
  100870. return ci ? ci->blocksizes[zo] : -1;
  100871. }
  100872. void vorbis_info_init(vorbis_info *vi){
  100873. memset(vi,0,sizeof(*vi));
  100874. vi->codec_setup=_ogg_calloc(1,sizeof(codec_setup_info));
  100875. }
  100876. void vorbis_info_clear(vorbis_info *vi){
  100877. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  100878. int i;
  100879. if(ci){
  100880. for(i=0;i<ci->modes;i++)
  100881. if(ci->mode_param[i])_ogg_free(ci->mode_param[i]);
  100882. for(i=0;i<ci->maps;i++) /* unpack does the range checking */
  100883. _mapping_P[ci->map_type[i]]->free_info(ci->map_param[i]);
  100884. for(i=0;i<ci->floors;i++) /* unpack does the range checking */
  100885. _floor_P[ci->floor_type[i]]->free_info(ci->floor_param[i]);
  100886. for(i=0;i<ci->residues;i++) /* unpack does the range checking */
  100887. _residue_P[ci->residue_type[i]]->free_info(ci->residue_param[i]);
  100888. for(i=0;i<ci->books;i++){
  100889. if(ci->book_param[i]){
  100890. vorbis_staticbook_destroy(ci->book_param[i]);
  100891. }
  100892. if(ci->fullbooks)
  100893. vorbis_book_clear(ci->fullbooks+i);
  100894. }
  100895. if(ci->fullbooks)
  100896. _ogg_free(ci->fullbooks);
  100897. for(i=0;i<ci->psys;i++)
  100898. _vi_psy_free(ci->psy_param[i]);
  100899. _ogg_free(ci);
  100900. }
  100901. memset(vi,0,sizeof(*vi));
  100902. }
  100903. static int _vorbis_unpack_info(vorbis_info *vi,oggpack_buffer *opb){
  100904. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  100905. if(!ci)return(OV_EFAULT);
  100906. vi->version=oggpack_read(opb,32);
  100907. if(vi->version!=0)return(OV_EVERSION);
  100908. vi->channels=oggpack_read(opb,8);
  100909. vi->rate=oggpack_read(opb,32);
  100910. vi->bitrate_upper=oggpack_read(opb,32);
  100911. vi->bitrate_nominal=oggpack_read(opb,32);
  100912. vi->bitrate_lower=oggpack_read(opb,32);
  100913. ci->blocksizes[0]=1<<oggpack_read(opb,4);
  100914. ci->blocksizes[1]=1<<oggpack_read(opb,4);
  100915. if(vi->rate<1)goto err_out;
  100916. if(vi->channels<1)goto err_out;
  100917. if(ci->blocksizes[0]<8)goto err_out;
  100918. if(ci->blocksizes[1]<ci->blocksizes[0])goto err_out;
  100919. if(oggpack_read(opb,1)!=1)goto err_out; /* EOP check */
  100920. return(0);
  100921. err_out:
  100922. vorbis_info_clear(vi);
  100923. return(OV_EBADHEADER);
  100924. }
  100925. static int _vorbis_unpack_comment(vorbis_comment *vc,oggpack_buffer *opb){
  100926. int i;
  100927. int vendorlen=oggpack_read(opb,32);
  100928. if(vendorlen<0)goto err_out;
  100929. vc->vendor=(char*)_ogg_calloc(vendorlen+1,1);
  100930. _v_readstring(opb,vc->vendor,vendorlen);
  100931. vc->comments=oggpack_read(opb,32);
  100932. if(vc->comments<0)goto err_out;
  100933. vc->user_comments=(char**)_ogg_calloc(vc->comments+1,sizeof(*vc->user_comments));
  100934. vc->comment_lengths=(int*)_ogg_calloc(vc->comments+1, sizeof(*vc->comment_lengths));
  100935. for(i=0;i<vc->comments;i++){
  100936. int len=oggpack_read(opb,32);
  100937. if(len<0)goto err_out;
  100938. vc->comment_lengths[i]=len;
  100939. vc->user_comments[i]=(char*)_ogg_calloc(len+1,1);
  100940. _v_readstring(opb,vc->user_comments[i],len);
  100941. }
  100942. if(oggpack_read(opb,1)!=1)goto err_out; /* EOP check */
  100943. return(0);
  100944. err_out:
  100945. vorbis_comment_clear(vc);
  100946. return(OV_EBADHEADER);
  100947. }
  100948. static int _vorbis_unpack_books(vorbis_info *vi,oggpack_buffer *opb){
  100949. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  100950. int i;
  100951. if(!ci)return(OV_EFAULT);
  100952. ci->books=oggpack_read(opb,8)+1;
  100953. for(i=0;i<ci->books;i++){
  100954. ci->book_param[i]=(static_codebook*)_ogg_calloc(1,sizeof(*ci->book_param[i]));
  100955. if(vorbis_staticbook_unpack(opb,ci->book_param[i]))goto err_out;
  100956. }
  100957. {
  100958. int times=oggpack_read(opb,6)+1;
  100959. for(i=0;i<times;i++){
  100960. int test=oggpack_read(opb,16);
  100961. if(test<0 || test>=VI_TIMEB)goto err_out;
  100962. }
  100963. }
  100964. ci->floors=oggpack_read(opb,6)+1;
  100965. for(i=0;i<ci->floors;i++){
  100966. ci->floor_type[i]=oggpack_read(opb,16);
  100967. if(ci->floor_type[i]<0 || ci->floor_type[i]>=VI_FLOORB)goto err_out;
  100968. ci->floor_param[i]=_floor_P[ci->floor_type[i]]->unpack(vi,opb);
  100969. if(!ci->floor_param[i])goto err_out;
  100970. }
  100971. ci->residues=oggpack_read(opb,6)+1;
  100972. for(i=0;i<ci->residues;i++){
  100973. ci->residue_type[i]=oggpack_read(opb,16);
  100974. if(ci->residue_type[i]<0 || ci->residue_type[i]>=VI_RESB)goto err_out;
  100975. ci->residue_param[i]=_residue_P[ci->residue_type[i]]->unpack(vi,opb);
  100976. if(!ci->residue_param[i])goto err_out;
  100977. }
  100978. ci->maps=oggpack_read(opb,6)+1;
  100979. for(i=0;i<ci->maps;i++){
  100980. ci->map_type[i]=oggpack_read(opb,16);
  100981. if(ci->map_type[i]<0 || ci->map_type[i]>=VI_MAPB)goto err_out;
  100982. ci->map_param[i]=_mapping_P[ci->map_type[i]]->unpack(vi,opb);
  100983. if(!ci->map_param[i])goto err_out;
  100984. }
  100985. ci->modes=oggpack_read(opb,6)+1;
  100986. for(i=0;i<ci->modes;i++){
  100987. ci->mode_param[i]=(vorbis_info_mode*)_ogg_calloc(1,sizeof(*ci->mode_param[i]));
  100988. ci->mode_param[i]->blockflag=oggpack_read(opb,1);
  100989. ci->mode_param[i]->windowtype=oggpack_read(opb,16);
  100990. ci->mode_param[i]->transformtype=oggpack_read(opb,16);
  100991. ci->mode_param[i]->mapping=oggpack_read(opb,8);
  100992. if(ci->mode_param[i]->windowtype>=VI_WINDOWB)goto err_out;
  100993. if(ci->mode_param[i]->transformtype>=VI_WINDOWB)goto err_out;
  100994. if(ci->mode_param[i]->mapping>=ci->maps)goto err_out;
  100995. }
  100996. if(oggpack_read(opb,1)!=1)goto err_out; /* top level EOP check */
  100997. return(0);
  100998. err_out:
  100999. vorbis_info_clear(vi);
  101000. return(OV_EBADHEADER);
  101001. }
  101002. int vorbis_synthesis_headerin(vorbis_info *vi,vorbis_comment *vc,ogg_packet *op){
  101003. oggpack_buffer opb;
  101004. if(op){
  101005. oggpack_readinit(&opb,op->packet,op->bytes);
  101006. {
  101007. char buffer[6];
  101008. int packtype=oggpack_read(&opb,8);
  101009. memset(buffer,0,6);
  101010. _v_readstring(&opb,buffer,6);
  101011. if(memcmp(buffer,"vorbis",6)){
  101012. return(OV_ENOTVORBIS);
  101013. }
  101014. switch(packtype){
  101015. case 0x01: /* least significant *bit* is read first */
  101016. if(!op->b_o_s){
  101017. return(OV_EBADHEADER);
  101018. }
  101019. if(vi->rate!=0){
  101020. return(OV_EBADHEADER);
  101021. }
  101022. return(_vorbis_unpack_info(vi,&opb));
  101023. case 0x03: /* least significant *bit* is read first */
  101024. if(vi->rate==0){
  101025. return(OV_EBADHEADER);
  101026. }
  101027. return(_vorbis_unpack_comment(vc,&opb));
  101028. case 0x05: /* least significant *bit* is read first */
  101029. if(vi->rate==0 || vc->vendor==NULL){
  101030. return(OV_EBADHEADER);
  101031. }
  101032. return(_vorbis_unpack_books(vi,&opb));
  101033. default:
  101034. return(OV_EBADHEADER);
  101035. break;
  101036. }
  101037. }
  101038. }
  101039. return(OV_EBADHEADER);
  101040. }
  101041. static int _vorbis_pack_info(oggpack_buffer *opb,vorbis_info *vi){
  101042. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  101043. if(!ci)return(OV_EFAULT);
  101044. oggpack_write(opb,0x01,8);
  101045. _v_writestring(opb,"vorbis", 6);
  101046. oggpack_write(opb,0x00,32);
  101047. oggpack_write(opb,vi->channels,8);
  101048. oggpack_write(opb,vi->rate,32);
  101049. oggpack_write(opb,vi->bitrate_upper,32);
  101050. oggpack_write(opb,vi->bitrate_nominal,32);
  101051. oggpack_write(opb,vi->bitrate_lower,32);
  101052. oggpack_write(opb,ilog2(ci->blocksizes[0]),4);
  101053. oggpack_write(opb,ilog2(ci->blocksizes[1]),4);
  101054. oggpack_write(opb,1,1);
  101055. return(0);
  101056. }
  101057. static int _vorbis_pack_comment(oggpack_buffer *opb,vorbis_comment *vc){
  101058. char temp[]="Xiph.Org libVorbis I 20050304";
  101059. int bytes = strlen(temp);
  101060. oggpack_write(opb,0x03,8);
  101061. _v_writestring(opb,"vorbis", 6);
  101062. oggpack_write(opb,bytes,32);
  101063. _v_writestring(opb,temp, bytes);
  101064. oggpack_write(opb,vc->comments,32);
  101065. if(vc->comments){
  101066. int i;
  101067. for(i=0;i<vc->comments;i++){
  101068. if(vc->user_comments[i]){
  101069. oggpack_write(opb,vc->comment_lengths[i],32);
  101070. _v_writestring(opb,vc->user_comments[i], vc->comment_lengths[i]);
  101071. }else{
  101072. oggpack_write(opb,0,32);
  101073. }
  101074. }
  101075. }
  101076. oggpack_write(opb,1,1);
  101077. return(0);
  101078. }
  101079. static int _vorbis_pack_books(oggpack_buffer *opb,vorbis_info *vi){
  101080. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  101081. int i;
  101082. if(!ci)return(OV_EFAULT);
  101083. oggpack_write(opb,0x05,8);
  101084. _v_writestring(opb,"vorbis", 6);
  101085. oggpack_write(opb,ci->books-1,8);
  101086. for(i=0;i<ci->books;i++)
  101087. if(vorbis_staticbook_pack(ci->book_param[i],opb))goto err_out;
  101088. oggpack_write(opb,0,6);
  101089. oggpack_write(opb,0,16);
  101090. oggpack_write(opb,ci->floors-1,6);
  101091. for(i=0;i<ci->floors;i++){
  101092. oggpack_write(opb,ci->floor_type[i],16);
  101093. if(_floor_P[ci->floor_type[i]]->pack)
  101094. _floor_P[ci->floor_type[i]]->pack(ci->floor_param[i],opb);
  101095. else
  101096. goto err_out;
  101097. }
  101098. oggpack_write(opb,ci->residues-1,6);
  101099. for(i=0;i<ci->residues;i++){
  101100. oggpack_write(opb,ci->residue_type[i],16);
  101101. _residue_P[ci->residue_type[i]]->pack(ci->residue_param[i],opb);
  101102. }
  101103. oggpack_write(opb,ci->maps-1,6);
  101104. for(i=0;i<ci->maps;i++){
  101105. oggpack_write(opb,ci->map_type[i],16);
  101106. _mapping_P[ci->map_type[i]]->pack(vi,ci->map_param[i],opb);
  101107. }
  101108. oggpack_write(opb,ci->modes-1,6);
  101109. for(i=0;i<ci->modes;i++){
  101110. oggpack_write(opb,ci->mode_param[i]->blockflag,1);
  101111. oggpack_write(opb,ci->mode_param[i]->windowtype,16);
  101112. oggpack_write(opb,ci->mode_param[i]->transformtype,16);
  101113. oggpack_write(opb,ci->mode_param[i]->mapping,8);
  101114. }
  101115. oggpack_write(opb,1,1);
  101116. return(0);
  101117. err_out:
  101118. return(-1);
  101119. }
  101120. int vorbis_commentheader_out(vorbis_comment *vc,
  101121. ogg_packet *op){
  101122. oggpack_buffer opb;
  101123. oggpack_writeinit(&opb);
  101124. if(_vorbis_pack_comment(&opb,vc)) return OV_EIMPL;
  101125. op->packet = (unsigned char*) _ogg_malloc(oggpack_bytes(&opb));
  101126. memcpy(op->packet, opb.buffer, oggpack_bytes(&opb));
  101127. op->bytes=oggpack_bytes(&opb);
  101128. op->b_o_s=0;
  101129. op->e_o_s=0;
  101130. op->granulepos=0;
  101131. op->packetno=1;
  101132. return 0;
  101133. }
  101134. int vorbis_analysis_headerout(vorbis_dsp_state *v,
  101135. vorbis_comment *vc,
  101136. ogg_packet *op,
  101137. ogg_packet *op_comm,
  101138. ogg_packet *op_code){
  101139. int ret=OV_EIMPL;
  101140. vorbis_info *vi=v->vi;
  101141. oggpack_buffer opb;
  101142. private_state *b=(private_state*)v->backend_state;
  101143. if(!b){
  101144. ret=OV_EFAULT;
  101145. goto err_out;
  101146. }
  101147. oggpack_writeinit(&opb);
  101148. if(_vorbis_pack_info(&opb,vi))goto err_out;
  101149. if(b->header)_ogg_free(b->header);
  101150. b->header=(unsigned char*) _ogg_malloc(oggpack_bytes(&opb));
  101151. memcpy(b->header,opb.buffer,oggpack_bytes(&opb));
  101152. op->packet=b->header;
  101153. op->bytes=oggpack_bytes(&opb);
  101154. op->b_o_s=1;
  101155. op->e_o_s=0;
  101156. op->granulepos=0;
  101157. op->packetno=0;
  101158. oggpack_reset(&opb);
  101159. if(_vorbis_pack_comment(&opb,vc))goto err_out;
  101160. if(b->header1)_ogg_free(b->header1);
  101161. b->header1=(unsigned char*) _ogg_malloc(oggpack_bytes(&opb));
  101162. memcpy(b->header1,opb.buffer,oggpack_bytes(&opb));
  101163. op_comm->packet=b->header1;
  101164. op_comm->bytes=oggpack_bytes(&opb);
  101165. op_comm->b_o_s=0;
  101166. op_comm->e_o_s=0;
  101167. op_comm->granulepos=0;
  101168. op_comm->packetno=1;
  101169. oggpack_reset(&opb);
  101170. if(_vorbis_pack_books(&opb,vi))goto err_out;
  101171. if(b->header2)_ogg_free(b->header2);
  101172. b->header2=(unsigned char*) _ogg_malloc(oggpack_bytes(&opb));
  101173. memcpy(b->header2,opb.buffer,oggpack_bytes(&opb));
  101174. op_code->packet=b->header2;
  101175. op_code->bytes=oggpack_bytes(&opb);
  101176. op_code->b_o_s=0;
  101177. op_code->e_o_s=0;
  101178. op_code->granulepos=0;
  101179. op_code->packetno=2;
  101180. oggpack_writeclear(&opb);
  101181. return(0);
  101182. err_out:
  101183. oggpack_writeclear(&opb);
  101184. memset(op,0,sizeof(*op));
  101185. memset(op_comm,0,sizeof(*op_comm));
  101186. memset(op_code,0,sizeof(*op_code));
  101187. if(b->header)_ogg_free(b->header);
  101188. if(b->header1)_ogg_free(b->header1);
  101189. if(b->header2)_ogg_free(b->header2);
  101190. b->header=NULL;
  101191. b->header1=NULL;
  101192. b->header2=NULL;
  101193. return(ret);
  101194. }
  101195. double vorbis_granule_time(vorbis_dsp_state *v,ogg_int64_t granulepos){
  101196. if(granulepos>=0)
  101197. return((double)granulepos/v->vi->rate);
  101198. return(-1);
  101199. }
  101200. #endif
  101201. /********* End of inlined file: info.c *********/
  101202. /********* Start of inlined file: lpc.c *********/
  101203. /********* Start of inlined file: juce_OggVorbisHeader.h *********/
  101204. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  101205. // tasks..
  101206. #if JUCE_MSVC
  101207. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  101208. #endif
  101209. /********* End of inlined file: juce_OggVorbisHeader.h *********/
  101210. #if JUCE_USE_OGGVORBIS
  101211. #include <stdlib.h>
  101212. #include <string.h>
  101213. #include <math.h>
  101214. float vorbis_lpc_from_data(float *data,float *lpci,int n,int m){
  101215. double *aut=(double*)alloca(sizeof(*aut)*(m+1));
  101216. double *lpc=(double*)alloca(sizeof(*lpc)*(m));
  101217. double error;
  101218. int i,j;
  101219. j=m+1;
  101220. while(j--){
  101221. double d=0; /* double needed for accumulator depth */
  101222. for(i=j;i<n;i++)d+=(double)data[i]*data[i-j];
  101223. aut[j]=d;
  101224. }
  101225. error=aut[0];
  101226. for(i=0;i<m;i++){
  101227. double r= -aut[i+1];
  101228. if(error==0){
  101229. memset(lpci,0,m*sizeof(*lpci));
  101230. return 0;
  101231. }
  101232. for(j=0;j<i;j++)r-=lpc[j]*aut[i-j];
  101233. r/=error;
  101234. lpc[i]=r;
  101235. for(j=0;j<i/2;j++){
  101236. double tmp=lpc[j];
  101237. lpc[j]+=r*lpc[i-1-j];
  101238. lpc[i-1-j]+=r*tmp;
  101239. }
  101240. if(i%2)lpc[j]+=lpc[j]*r;
  101241. error*=1.f-r*r;
  101242. }
  101243. for(j=0;j<m;j++)lpci[j]=(float)lpc[j];
  101244. return error;
  101245. }
  101246. void vorbis_lpc_predict(float *coeff,float *prime,int m,
  101247. float *data,long n){
  101248. long i,j,o,p;
  101249. float y;
  101250. float *work=(float*)alloca(sizeof(*work)*(m+n));
  101251. if(!prime)
  101252. for(i=0;i<m;i++)
  101253. work[i]=0.f;
  101254. else
  101255. for(i=0;i<m;i++)
  101256. work[i]=prime[i];
  101257. for(i=0;i<n;i++){
  101258. y=0;
  101259. o=i;
  101260. p=m;
  101261. for(j=0;j<m;j++)
  101262. y-=work[o++]*coeff[--p];
  101263. data[i]=work[o]=y;
  101264. }
  101265. }
  101266. #endif
  101267. /********* End of inlined file: lpc.c *********/
  101268. /********* Start of inlined file: lsp.c *********/
  101269. /********* Start of inlined file: juce_OggVorbisHeader.h *********/
  101270. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  101271. // tasks..
  101272. #if JUCE_MSVC
  101273. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  101274. #endif
  101275. /********* End of inlined file: juce_OggVorbisHeader.h *********/
  101276. #if JUCE_USE_OGGVORBIS
  101277. #include <math.h>
  101278. #include <string.h>
  101279. #include <stdlib.h>
  101280. /********* Start of inlined file: lookup.h *********/
  101281. #ifndef _V_LOOKUP_H_
  101282. #ifdef FLOAT_LOOKUP
  101283. extern float vorbis_coslook(float a);
  101284. extern float vorbis_invsqlook(float a);
  101285. extern float vorbis_invsq2explook(int a);
  101286. extern float vorbis_fromdBlook(float a);
  101287. #endif
  101288. #ifdef INT_LOOKUP
  101289. extern long vorbis_invsqlook_i(long a,long e);
  101290. extern long vorbis_coslook_i(long a);
  101291. extern float vorbis_fromdBlook_i(long a);
  101292. #endif
  101293. #endif
  101294. /********* End of inlined file: lookup.h *********/
  101295. #define FLOAT_LOOKUP
  101296. #undef INT_LOOKUP
  101297. #ifdef FLOAT_LOOKUP
  101298. /********* Start of inlined file: lookup.c *********/
  101299. /********* Start of inlined file: juce_OggVorbisHeader.h *********/
  101300. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  101301. // tasks..
  101302. #if JUCE_MSVC
  101303. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  101304. #endif
  101305. /********* End of inlined file: juce_OggVorbisHeader.h *********/
  101306. #if JUCE_USE_OGGVORBIS
  101307. #include <math.h>
  101308. /********* Start of inlined file: lookup.h *********/
  101309. #ifndef _V_LOOKUP_H_
  101310. #ifdef FLOAT_LOOKUP
  101311. extern float vorbis_coslook(float a);
  101312. extern float vorbis_invsqlook(float a);
  101313. extern float vorbis_invsq2explook(int a);
  101314. extern float vorbis_fromdBlook(float a);
  101315. #endif
  101316. #ifdef INT_LOOKUP
  101317. extern long vorbis_invsqlook_i(long a,long e);
  101318. extern long vorbis_coslook_i(long a);
  101319. extern float vorbis_fromdBlook_i(long a);
  101320. #endif
  101321. #endif
  101322. /********* End of inlined file: lookup.h *********/
  101323. /********* Start of inlined file: lookup_data.h *********/
  101324. #ifndef _V_LOOKUP_DATA_H_
  101325. #ifdef FLOAT_LOOKUP
  101326. #define COS_LOOKUP_SZ 128
  101327. static float COS_LOOKUP[COS_LOOKUP_SZ+1]={
  101328. +1.0000000000000f,+0.9996988186962f,+0.9987954562052f,+0.9972904566787f,
  101329. +0.9951847266722f,+0.9924795345987f,+0.9891765099648f,+0.9852776423889f,
  101330. +0.9807852804032f,+0.9757021300385f,+0.9700312531945f,+0.9637760657954f,
  101331. +0.9569403357322f,+0.9495281805930f,+0.9415440651830f,+0.9329927988347f,
  101332. +0.9238795325113f,+0.9142097557035f,+0.9039892931234f,+0.8932243011955f,
  101333. +0.8819212643484f,+0.8700869911087f,+0.8577286100003f,+0.8448535652497f,
  101334. +0.8314696123025f,+0.8175848131516f,+0.8032075314806f,+0.7883464276266f,
  101335. +0.7730104533627f,+0.7572088465065f,+0.7409511253550f,+0.7242470829515f,
  101336. +0.7071067811865f,+0.6895405447371f,+0.6715589548470f,+0.6531728429538f,
  101337. +0.6343932841636f,+0.6152315905806f,+0.5956993044924f,+0.5758081914178f,
  101338. +0.5555702330196f,+0.5349976198871f,+0.5141027441932f,+0.4928981922298f,
  101339. +0.4713967368260f,+0.4496113296546f,+0.4275550934303f,+0.4052413140050f,
  101340. +0.3826834323651f,+0.3598950365350f,+0.3368898533922f,+0.3136817403989f,
  101341. +0.2902846772545f,+0.2667127574749f,+0.2429801799033f,+0.2191012401569f,
  101342. +0.1950903220161f,+0.1709618887603f,+0.1467304744554f,+0.1224106751992f,
  101343. +0.0980171403296f,+0.0735645635997f,+0.0490676743274f,+0.0245412285229f,
  101344. +0.0000000000000f,-0.0245412285229f,-0.0490676743274f,-0.0735645635997f,
  101345. -0.0980171403296f,-0.1224106751992f,-0.1467304744554f,-0.1709618887603f,
  101346. -0.1950903220161f,-0.2191012401569f,-0.2429801799033f,-0.2667127574749f,
  101347. -0.2902846772545f,-0.3136817403989f,-0.3368898533922f,-0.3598950365350f,
  101348. -0.3826834323651f,-0.4052413140050f,-0.4275550934303f,-0.4496113296546f,
  101349. -0.4713967368260f,-0.4928981922298f,-0.5141027441932f,-0.5349976198871f,
  101350. -0.5555702330196f,-0.5758081914178f,-0.5956993044924f,-0.6152315905806f,
  101351. -0.6343932841636f,-0.6531728429538f,-0.6715589548470f,-0.6895405447371f,
  101352. -0.7071067811865f,-0.7242470829515f,-0.7409511253550f,-0.7572088465065f,
  101353. -0.7730104533627f,-0.7883464276266f,-0.8032075314806f,-0.8175848131516f,
  101354. -0.8314696123025f,-0.8448535652497f,-0.8577286100003f,-0.8700869911087f,
  101355. -0.8819212643484f,-0.8932243011955f,-0.9039892931234f,-0.9142097557035f,
  101356. -0.9238795325113f,-0.9329927988347f,-0.9415440651830f,-0.9495281805930f,
  101357. -0.9569403357322f,-0.9637760657954f,-0.9700312531945f,-0.9757021300385f,
  101358. -0.9807852804032f,-0.9852776423889f,-0.9891765099648f,-0.9924795345987f,
  101359. -0.9951847266722f,-0.9972904566787f,-0.9987954562052f,-0.9996988186962f,
  101360. -1.0000000000000f,
  101361. };
  101362. #define INVSQ_LOOKUP_SZ 32
  101363. static float INVSQ_LOOKUP[INVSQ_LOOKUP_SZ+1]={
  101364. 1.414213562373f,1.392621247646f,1.371988681140f,1.352246807566f,
  101365. 1.333333333333f,1.315191898443f,1.297771369046f,1.281025230441f,
  101366. 1.264911064067f,1.249390095109f,1.234426799697f,1.219988562661f,
  101367. 1.206045378311f,1.192569588000f,1.179535649239f,1.166919931983f,
  101368. 1.154700538379f,1.142857142857f,1.131370849898f,1.120224067222f,
  101369. 1.109400392450f,1.098884511590f,1.088662107904f,1.078719779941f,
  101370. 1.069044967650f,1.059625885652f,1.050451462878f,1.041511287847f,
  101371. 1.032795558989f,1.024295039463f,1.016001016002f,1.007905261358f,
  101372. 1.000000000000f,
  101373. };
  101374. #define INVSQ2EXP_LOOKUP_MIN (-32)
  101375. #define INVSQ2EXP_LOOKUP_MAX 32
  101376. static float INVSQ2EXP_LOOKUP[INVSQ2EXP_LOOKUP_MAX-\
  101377. INVSQ2EXP_LOOKUP_MIN+1]={
  101378. 65536.f, 46340.95001f, 32768.f, 23170.47501f,
  101379. 16384.f, 11585.2375f, 8192.f, 5792.618751f,
  101380. 4096.f, 2896.309376f, 2048.f, 1448.154688f,
  101381. 1024.f, 724.0773439f, 512.f, 362.038672f,
  101382. 256.f, 181.019336f, 128.f, 90.50966799f,
  101383. 64.f, 45.254834f, 32.f, 22.627417f,
  101384. 16.f, 11.3137085f, 8.f, 5.656854249f,
  101385. 4.f, 2.828427125f, 2.f, 1.414213562f,
  101386. 1.f, 0.7071067812f, 0.5f, 0.3535533906f,
  101387. 0.25f, 0.1767766953f, 0.125f, 0.08838834765f,
  101388. 0.0625f, 0.04419417382f, 0.03125f, 0.02209708691f,
  101389. 0.015625f, 0.01104854346f, 0.0078125f, 0.005524271728f,
  101390. 0.00390625f, 0.002762135864f, 0.001953125f, 0.001381067932f,
  101391. 0.0009765625f, 0.000690533966f, 0.00048828125f, 0.000345266983f,
  101392. 0.000244140625f,0.0001726334915f,0.0001220703125f,8.631674575e-05f,
  101393. 6.103515625e-05f,4.315837288e-05f,3.051757812e-05f,2.157918644e-05f,
  101394. 1.525878906e-05f,
  101395. };
  101396. #endif
  101397. #define FROMdB_LOOKUP_SZ 35
  101398. #define FROMdB2_LOOKUP_SZ 32
  101399. #define FROMdB_SHIFT 5
  101400. #define FROMdB2_SHIFT 3
  101401. #define FROMdB2_MASK 31
  101402. static float FROMdB_LOOKUP[FROMdB_LOOKUP_SZ]={
  101403. 1.f, 0.6309573445f, 0.3981071706f, 0.2511886432f,
  101404. 0.1584893192f, 0.1f, 0.06309573445f, 0.03981071706f,
  101405. 0.02511886432f, 0.01584893192f, 0.01f, 0.006309573445f,
  101406. 0.003981071706f, 0.002511886432f, 0.001584893192f, 0.001f,
  101407. 0.0006309573445f,0.0003981071706f,0.0002511886432f,0.0001584893192f,
  101408. 0.0001f,6.309573445e-05f,3.981071706e-05f,2.511886432e-05f,
  101409. 1.584893192e-05f, 1e-05f,6.309573445e-06f,3.981071706e-06f,
  101410. 2.511886432e-06f,1.584893192e-06f, 1e-06f,6.309573445e-07f,
  101411. 3.981071706e-07f,2.511886432e-07f,1.584893192e-07f,
  101412. };
  101413. static float FROMdB2_LOOKUP[FROMdB2_LOOKUP_SZ]={
  101414. 0.9928302478f, 0.9786445908f, 0.9646616199f, 0.9508784391f,
  101415. 0.9372921937f, 0.92390007f, 0.9106992942f, 0.8976871324f,
  101416. 0.8848608897f, 0.8722179097f, 0.8597555737f, 0.8474713009f,
  101417. 0.835362547f, 0.8234268041f, 0.8116616003f, 0.8000644989f,
  101418. 0.7886330981f, 0.7773650302f, 0.7662579617f, 0.755309592f,
  101419. 0.7445176537f, 0.7338799116f, 0.7233941627f, 0.7130582353f,
  101420. 0.7028699885f, 0.6928273125f, 0.6829281272f, 0.6731703824f,
  101421. 0.6635520573f, 0.6540711597f, 0.6447257262f, 0.6355138211f,
  101422. };
  101423. #ifdef INT_LOOKUP
  101424. #define INVSQ_LOOKUP_I_SHIFT 10
  101425. #define INVSQ_LOOKUP_I_MASK 1023
  101426. static long INVSQ_LOOKUP_I[64+1]={
  101427. 92682l, 91966l, 91267l, 90583l,
  101428. 89915l, 89261l, 88621l, 87995l,
  101429. 87381l, 86781l, 86192l, 85616l,
  101430. 85051l, 84497l, 83953l, 83420l,
  101431. 82897l, 82384l, 81880l, 81385l,
  101432. 80899l, 80422l, 79953l, 79492l,
  101433. 79039l, 78594l, 78156l, 77726l,
  101434. 77302l, 76885l, 76475l, 76072l,
  101435. 75674l, 75283l, 74898l, 74519l,
  101436. 74146l, 73778l, 73415l, 73058l,
  101437. 72706l, 72359l, 72016l, 71679l,
  101438. 71347l, 71019l, 70695l, 70376l,
  101439. 70061l, 69750l, 69444l, 69141l,
  101440. 68842l, 68548l, 68256l, 67969l,
  101441. 67685l, 67405l, 67128l, 66855l,
  101442. 66585l, 66318l, 66054l, 65794l,
  101443. 65536l,
  101444. };
  101445. #define COS_LOOKUP_I_SHIFT 9
  101446. #define COS_LOOKUP_I_MASK 511
  101447. #define COS_LOOKUP_I_SZ 128
  101448. static long COS_LOOKUP_I[COS_LOOKUP_I_SZ+1]={
  101449. 16384l, 16379l, 16364l, 16340l,
  101450. 16305l, 16261l, 16207l, 16143l,
  101451. 16069l, 15986l, 15893l, 15791l,
  101452. 15679l, 15557l, 15426l, 15286l,
  101453. 15137l, 14978l, 14811l, 14635l,
  101454. 14449l, 14256l, 14053l, 13842l,
  101455. 13623l, 13395l, 13160l, 12916l,
  101456. 12665l, 12406l, 12140l, 11866l,
  101457. 11585l, 11297l, 11003l, 10702l,
  101458. 10394l, 10080l, 9760l, 9434l,
  101459. 9102l, 8765l, 8423l, 8076l,
  101460. 7723l, 7366l, 7005l, 6639l,
  101461. 6270l, 5897l, 5520l, 5139l,
  101462. 4756l, 4370l, 3981l, 3590l,
  101463. 3196l, 2801l, 2404l, 2006l,
  101464. 1606l, 1205l, 804l, 402l,
  101465. 0l, -401l, -803l, -1204l,
  101466. -1605l, -2005l, -2403l, -2800l,
  101467. -3195l, -3589l, -3980l, -4369l,
  101468. -4755l, -5138l, -5519l, -5896l,
  101469. -6269l, -6638l, -7004l, -7365l,
  101470. -7722l, -8075l, -8422l, -8764l,
  101471. -9101l, -9433l, -9759l, -10079l,
  101472. -10393l, -10701l, -11002l, -11296l,
  101473. -11584l, -11865l, -12139l, -12405l,
  101474. -12664l, -12915l, -13159l, -13394l,
  101475. -13622l, -13841l, -14052l, -14255l,
  101476. -14448l, -14634l, -14810l, -14977l,
  101477. -15136l, -15285l, -15425l, -15556l,
  101478. -15678l, -15790l, -15892l, -15985l,
  101479. -16068l, -16142l, -16206l, -16260l,
  101480. -16304l, -16339l, -16363l, -16378l,
  101481. -16383l,
  101482. };
  101483. #endif
  101484. #endif
  101485. /********* End of inlined file: lookup_data.h *********/
  101486. #ifdef FLOAT_LOOKUP
  101487. float vorbis_coslook(float a){
  101488. double d=a*(.31830989*(float)COS_LOOKUP_SZ);
  101489. int i=vorbis_ftoi(d-.5);
  101490. return COS_LOOKUP[i]+ (d-i)*(COS_LOOKUP[i+1]-COS_LOOKUP[i]);
  101491. }
  101492. float vorbis_invsqlook(float a){
  101493. double d=a*(2.f*(float)INVSQ_LOOKUP_SZ)-(float)INVSQ_LOOKUP_SZ;
  101494. int i=vorbis_ftoi(d-.5f);
  101495. return INVSQ_LOOKUP[i]+ (d-i)*(INVSQ_LOOKUP[i+1]-INVSQ_LOOKUP[i]);
  101496. }
  101497. float vorbis_invsq2explook(int a){
  101498. return INVSQ2EXP_LOOKUP[a-INVSQ2EXP_LOOKUP_MIN];
  101499. }
  101500. #include <stdio.h>
  101501. float vorbis_fromdBlook(float a){
  101502. int i=vorbis_ftoi(a*((float)(-(1<<FROMdB2_SHIFT)))-.5f);
  101503. return (i<0)?1.f:
  101504. ((i>=(FROMdB_LOOKUP_SZ<<FROMdB_SHIFT))?0.f:
  101505. FROMdB_LOOKUP[i>>FROMdB_SHIFT]*FROMdB2_LOOKUP[i&FROMdB2_MASK]);
  101506. }
  101507. #endif
  101508. #ifdef INT_LOOKUP
  101509. long vorbis_invsqlook_i(long a,long e){
  101510. long i=(a&0x7fff)>>(INVSQ_LOOKUP_I_SHIFT-1);
  101511. long d=(a&INVSQ_LOOKUP_I_MASK)<<(16-INVSQ_LOOKUP_I_SHIFT); /* 0.16 */
  101512. long val=INVSQ_LOOKUP_I[i]- /* 1.16 */
  101513. (((INVSQ_LOOKUP_I[i]-INVSQ_LOOKUP_I[i+1])* /* 0.16 */
  101514. d)>>16); /* result 1.16 */
  101515. e+=32;
  101516. if(e&1)val=(val*5792)>>13; /* multiply val by 1/sqrt(2) */
  101517. e=(e>>1)-8;
  101518. return(val>>e);
  101519. }
  101520. float vorbis_fromdBlook_i(long a){
  101521. int i=(-a)>>(12-FROMdB2_SHIFT);
  101522. return (i<0)?1.f:
  101523. ((i>=(FROMdB_LOOKUP_SZ<<FROMdB_SHIFT))?0.f:
  101524. FROMdB_LOOKUP[i>>FROMdB_SHIFT]*FROMdB2_LOOKUP[i&FROMdB2_MASK]);
  101525. }
  101526. long vorbis_coslook_i(long a){
  101527. int i=a>>COS_LOOKUP_I_SHIFT;
  101528. int d=a&COS_LOOKUP_I_MASK;
  101529. return COS_LOOKUP_I[i]- ((d*(COS_LOOKUP_I[i]-COS_LOOKUP_I[i+1]))>>
  101530. COS_LOOKUP_I_SHIFT);
  101531. }
  101532. #endif
  101533. #endif
  101534. /********* End of inlined file: lookup.c *********/
  101535. void vorbis_lsp_to_curve(float *curve,int *map,int n,int ln,float *lsp,int m,
  101536. float amp,float ampoffset){
  101537. int i;
  101538. float wdel=M_PI/ln;
  101539. vorbis_fpu_control fpu;
  101540. (void) fpu; // to avoid an unused variable warning
  101541. vorbis_fpu_setround(&fpu);
  101542. for(i=0;i<m;i++)lsp[i]=vorbis_coslook(lsp[i]);
  101543. i=0;
  101544. while(i<n){
  101545. int k=map[i];
  101546. int qexp;
  101547. float p=.7071067812f;
  101548. float q=.7071067812f;
  101549. float w=vorbis_coslook(wdel*k);
  101550. float *ftmp=lsp;
  101551. int c=m>>1;
  101552. do{
  101553. q*=ftmp[0]-w;
  101554. p*=ftmp[1]-w;
  101555. ftmp+=2;
  101556. }while(--c);
  101557. if(m&1){
  101558. q*=ftmp[0]-w;
  101559. q*=q;
  101560. p*=p*(1.f-w*w);
  101561. }else{
  101562. q*=q*(1.f+w);
  101563. p*=p*(1.f-w);
  101564. }
  101565. q=frexp(p+q,&qexp);
  101566. q=vorbis_fromdBlook(amp*
  101567. vorbis_invsqlook(q)*
  101568. vorbis_invsq2explook(qexp+m)-
  101569. ampoffset);
  101570. do{
  101571. curve[i++]*=q;
  101572. }while(map[i]==k);
  101573. }
  101574. vorbis_fpu_restore(fpu);
  101575. }
  101576. #else
  101577. #ifdef INT_LOOKUP
  101578. /********* Start of inlined file: lookup.c *********/
  101579. /********* Start of inlined file: juce_OggVorbisHeader.h *********/
  101580. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  101581. // tasks..
  101582. #if JUCE_MSVC
  101583. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  101584. #endif
  101585. /********* End of inlined file: juce_OggVorbisHeader.h *********/
  101586. #if JUCE_USE_OGGVORBIS
  101587. #include <math.h>
  101588. /********* Start of inlined file: lookup.h *********/
  101589. #ifndef _V_LOOKUP_H_
  101590. #ifdef FLOAT_LOOKUP
  101591. extern float vorbis_coslook(float a);
  101592. extern float vorbis_invsqlook(float a);
  101593. extern float vorbis_invsq2explook(int a);
  101594. extern float vorbis_fromdBlook(float a);
  101595. #endif
  101596. #ifdef INT_LOOKUP
  101597. extern long vorbis_invsqlook_i(long a,long e);
  101598. extern long vorbis_coslook_i(long a);
  101599. extern float vorbis_fromdBlook_i(long a);
  101600. #endif
  101601. #endif
  101602. /********* End of inlined file: lookup.h *********/
  101603. /********* Start of inlined file: lookup_data.h *********/
  101604. #ifndef _V_LOOKUP_DATA_H_
  101605. #ifdef FLOAT_LOOKUP
  101606. #define COS_LOOKUP_SZ 128
  101607. static float COS_LOOKUP[COS_LOOKUP_SZ+1]={
  101608. +1.0000000000000f,+0.9996988186962f,+0.9987954562052f,+0.9972904566787f,
  101609. +0.9951847266722f,+0.9924795345987f,+0.9891765099648f,+0.9852776423889f,
  101610. +0.9807852804032f,+0.9757021300385f,+0.9700312531945f,+0.9637760657954f,
  101611. +0.9569403357322f,+0.9495281805930f,+0.9415440651830f,+0.9329927988347f,
  101612. +0.9238795325113f,+0.9142097557035f,+0.9039892931234f,+0.8932243011955f,
  101613. +0.8819212643484f,+0.8700869911087f,+0.8577286100003f,+0.8448535652497f,
  101614. +0.8314696123025f,+0.8175848131516f,+0.8032075314806f,+0.7883464276266f,
  101615. +0.7730104533627f,+0.7572088465065f,+0.7409511253550f,+0.7242470829515f,
  101616. +0.7071067811865f,+0.6895405447371f,+0.6715589548470f,+0.6531728429538f,
  101617. +0.6343932841636f,+0.6152315905806f,+0.5956993044924f,+0.5758081914178f,
  101618. +0.5555702330196f,+0.5349976198871f,+0.5141027441932f,+0.4928981922298f,
  101619. +0.4713967368260f,+0.4496113296546f,+0.4275550934303f,+0.4052413140050f,
  101620. +0.3826834323651f,+0.3598950365350f,+0.3368898533922f,+0.3136817403989f,
  101621. +0.2902846772545f,+0.2667127574749f,+0.2429801799033f,+0.2191012401569f,
  101622. +0.1950903220161f,+0.1709618887603f,+0.1467304744554f,+0.1224106751992f,
  101623. +0.0980171403296f,+0.0735645635997f,+0.0490676743274f,+0.0245412285229f,
  101624. +0.0000000000000f,-0.0245412285229f,-0.0490676743274f,-0.0735645635997f,
  101625. -0.0980171403296f,-0.1224106751992f,-0.1467304744554f,-0.1709618887603f,
  101626. -0.1950903220161f,-0.2191012401569f,-0.2429801799033f,-0.2667127574749f,
  101627. -0.2902846772545f,-0.3136817403989f,-0.3368898533922f,-0.3598950365350f,
  101628. -0.3826834323651f,-0.4052413140050f,-0.4275550934303f,-0.4496113296546f,
  101629. -0.4713967368260f,-0.4928981922298f,-0.5141027441932f,-0.5349976198871f,
  101630. -0.5555702330196f,-0.5758081914178f,-0.5956993044924f,-0.6152315905806f,
  101631. -0.6343932841636f,-0.6531728429538f,-0.6715589548470f,-0.6895405447371f,
  101632. -0.7071067811865f,-0.7242470829515f,-0.7409511253550f,-0.7572088465065f,
  101633. -0.7730104533627f,-0.7883464276266f,-0.8032075314806f,-0.8175848131516f,
  101634. -0.8314696123025f,-0.8448535652497f,-0.8577286100003f,-0.8700869911087f,
  101635. -0.8819212643484f,-0.8932243011955f,-0.9039892931234f,-0.9142097557035f,
  101636. -0.9238795325113f,-0.9329927988347f,-0.9415440651830f,-0.9495281805930f,
  101637. -0.9569403357322f,-0.9637760657954f,-0.9700312531945f,-0.9757021300385f,
  101638. -0.9807852804032f,-0.9852776423889f,-0.9891765099648f,-0.9924795345987f,
  101639. -0.9951847266722f,-0.9972904566787f,-0.9987954562052f,-0.9996988186962f,
  101640. -1.0000000000000f,
  101641. };
  101642. #define INVSQ_LOOKUP_SZ 32
  101643. static float INVSQ_LOOKUP[INVSQ_LOOKUP_SZ+1]={
  101644. 1.414213562373f,1.392621247646f,1.371988681140f,1.352246807566f,
  101645. 1.333333333333f,1.315191898443f,1.297771369046f,1.281025230441f,
  101646. 1.264911064067f,1.249390095109f,1.234426799697f,1.219988562661f,
  101647. 1.206045378311f,1.192569588000f,1.179535649239f,1.166919931983f,
  101648. 1.154700538379f,1.142857142857f,1.131370849898f,1.120224067222f,
  101649. 1.109400392450f,1.098884511590f,1.088662107904f,1.078719779941f,
  101650. 1.069044967650f,1.059625885652f,1.050451462878f,1.041511287847f,
  101651. 1.032795558989f,1.024295039463f,1.016001016002f,1.007905261358f,
  101652. 1.000000000000f,
  101653. };
  101654. #define INVSQ2EXP_LOOKUP_MIN (-32)
  101655. #define INVSQ2EXP_LOOKUP_MAX 32
  101656. static float INVSQ2EXP_LOOKUP[INVSQ2EXP_LOOKUP_MAX-\
  101657. INVSQ2EXP_LOOKUP_MIN+1]={
  101658. 65536.f, 46340.95001f, 32768.f, 23170.47501f,
  101659. 16384.f, 11585.2375f, 8192.f, 5792.618751f,
  101660. 4096.f, 2896.309376f, 2048.f, 1448.154688f,
  101661. 1024.f, 724.0773439f, 512.f, 362.038672f,
  101662. 256.f, 181.019336f, 128.f, 90.50966799f,
  101663. 64.f, 45.254834f, 32.f, 22.627417f,
  101664. 16.f, 11.3137085f, 8.f, 5.656854249f,
  101665. 4.f, 2.828427125f, 2.f, 1.414213562f,
  101666. 1.f, 0.7071067812f, 0.5f, 0.3535533906f,
  101667. 0.25f, 0.1767766953f, 0.125f, 0.08838834765f,
  101668. 0.0625f, 0.04419417382f, 0.03125f, 0.02209708691f,
  101669. 0.015625f, 0.01104854346f, 0.0078125f, 0.005524271728f,
  101670. 0.00390625f, 0.002762135864f, 0.001953125f, 0.001381067932f,
  101671. 0.0009765625f, 0.000690533966f, 0.00048828125f, 0.000345266983f,
  101672. 0.000244140625f,0.0001726334915f,0.0001220703125f,8.631674575e-05f,
  101673. 6.103515625e-05f,4.315837288e-05f,3.051757812e-05f,2.157918644e-05f,
  101674. 1.525878906e-05f,
  101675. };
  101676. #endif
  101677. #define FROMdB_LOOKUP_SZ 35
  101678. #define FROMdB2_LOOKUP_SZ 32
  101679. #define FROMdB_SHIFT 5
  101680. #define FROMdB2_SHIFT 3
  101681. #define FROMdB2_MASK 31
  101682. static float FROMdB_LOOKUP[FROMdB_LOOKUP_SZ]={
  101683. 1.f, 0.6309573445f, 0.3981071706f, 0.2511886432f,
  101684. 0.1584893192f, 0.1f, 0.06309573445f, 0.03981071706f,
  101685. 0.02511886432f, 0.01584893192f, 0.01f, 0.006309573445f,
  101686. 0.003981071706f, 0.002511886432f, 0.001584893192f, 0.001f,
  101687. 0.0006309573445f,0.0003981071706f,0.0002511886432f,0.0001584893192f,
  101688. 0.0001f,6.309573445e-05f,3.981071706e-05f,2.511886432e-05f,
  101689. 1.584893192e-05f, 1e-05f,6.309573445e-06f,3.981071706e-06f,
  101690. 2.511886432e-06f,1.584893192e-06f, 1e-06f,6.309573445e-07f,
  101691. 3.981071706e-07f,2.511886432e-07f,1.584893192e-07f,
  101692. };
  101693. static float FROMdB2_LOOKUP[FROMdB2_LOOKUP_SZ]={
  101694. 0.9928302478f, 0.9786445908f, 0.9646616199f, 0.9508784391f,
  101695. 0.9372921937f, 0.92390007f, 0.9106992942f, 0.8976871324f,
  101696. 0.8848608897f, 0.8722179097f, 0.8597555737f, 0.8474713009f,
  101697. 0.835362547f, 0.8234268041f, 0.8116616003f, 0.8000644989f,
  101698. 0.7886330981f, 0.7773650302f, 0.7662579617f, 0.755309592f,
  101699. 0.7445176537f, 0.7338799116f, 0.7233941627f, 0.7130582353f,
  101700. 0.7028699885f, 0.6928273125f, 0.6829281272f, 0.6731703824f,
  101701. 0.6635520573f, 0.6540711597f, 0.6447257262f, 0.6355138211f,
  101702. };
  101703. #ifdef INT_LOOKUP
  101704. #define INVSQ_LOOKUP_I_SHIFT 10
  101705. #define INVSQ_LOOKUP_I_MASK 1023
  101706. static long INVSQ_LOOKUP_I[64+1]={
  101707. 92682l, 91966l, 91267l, 90583l,
  101708. 89915l, 89261l, 88621l, 87995l,
  101709. 87381l, 86781l, 86192l, 85616l,
  101710. 85051l, 84497l, 83953l, 83420l,
  101711. 82897l, 82384l, 81880l, 81385l,
  101712. 80899l, 80422l, 79953l, 79492l,
  101713. 79039l, 78594l, 78156l, 77726l,
  101714. 77302l, 76885l, 76475l, 76072l,
  101715. 75674l, 75283l, 74898l, 74519l,
  101716. 74146l, 73778l, 73415l, 73058l,
  101717. 72706l, 72359l, 72016l, 71679l,
  101718. 71347l, 71019l, 70695l, 70376l,
  101719. 70061l, 69750l, 69444l, 69141l,
  101720. 68842l, 68548l, 68256l, 67969l,
  101721. 67685l, 67405l, 67128l, 66855l,
  101722. 66585l, 66318l, 66054l, 65794l,
  101723. 65536l,
  101724. };
  101725. #define COS_LOOKUP_I_SHIFT 9
  101726. #define COS_LOOKUP_I_MASK 511
  101727. #define COS_LOOKUP_I_SZ 128
  101728. static long COS_LOOKUP_I[COS_LOOKUP_I_SZ+1]={
  101729. 16384l, 16379l, 16364l, 16340l,
  101730. 16305l, 16261l, 16207l, 16143l,
  101731. 16069l, 15986l, 15893l, 15791l,
  101732. 15679l, 15557l, 15426l, 15286l,
  101733. 15137l, 14978l, 14811l, 14635l,
  101734. 14449l, 14256l, 14053l, 13842l,
  101735. 13623l, 13395l, 13160l, 12916l,
  101736. 12665l, 12406l, 12140l, 11866l,
  101737. 11585l, 11297l, 11003l, 10702l,
  101738. 10394l, 10080l, 9760l, 9434l,
  101739. 9102l, 8765l, 8423l, 8076l,
  101740. 7723l, 7366l, 7005l, 6639l,
  101741. 6270l, 5897l, 5520l, 5139l,
  101742. 4756l, 4370l, 3981l, 3590l,
  101743. 3196l, 2801l, 2404l, 2006l,
  101744. 1606l, 1205l, 804l, 402l,
  101745. 0l, -401l, -803l, -1204l,
  101746. -1605l, -2005l, -2403l, -2800l,
  101747. -3195l, -3589l, -3980l, -4369l,
  101748. -4755l, -5138l, -5519l, -5896l,
  101749. -6269l, -6638l, -7004l, -7365l,
  101750. -7722l, -8075l, -8422l, -8764l,
  101751. -9101l, -9433l, -9759l, -10079l,
  101752. -10393l, -10701l, -11002l, -11296l,
  101753. -11584l, -11865l, -12139l, -12405l,
  101754. -12664l, -12915l, -13159l, -13394l,
  101755. -13622l, -13841l, -14052l, -14255l,
  101756. -14448l, -14634l, -14810l, -14977l,
  101757. -15136l, -15285l, -15425l, -15556l,
  101758. -15678l, -15790l, -15892l, -15985l,
  101759. -16068l, -16142l, -16206l, -16260l,
  101760. -16304l, -16339l, -16363l, -16378l,
  101761. -16383l,
  101762. };
  101763. #endif
  101764. #endif
  101765. /********* End of inlined file: lookup_data.h *********/
  101766. #ifdef FLOAT_LOOKUP
  101767. float vorbis_coslook(float a){
  101768. double d=a*(.31830989*(float)COS_LOOKUP_SZ);
  101769. int i=vorbis_ftoi(d-.5);
  101770. return COS_LOOKUP[i]+ (d-i)*(COS_LOOKUP[i+1]-COS_LOOKUP[i]);
  101771. }
  101772. float vorbis_invsqlook(float a){
  101773. double d=a*(2.f*(float)INVSQ_LOOKUP_SZ)-(float)INVSQ_LOOKUP_SZ;
  101774. int i=vorbis_ftoi(d-.5f);
  101775. return INVSQ_LOOKUP[i]+ (d-i)*(INVSQ_LOOKUP[i+1]-INVSQ_LOOKUP[i]);
  101776. }
  101777. float vorbis_invsq2explook(int a){
  101778. return INVSQ2EXP_LOOKUP[a-INVSQ2EXP_LOOKUP_MIN];
  101779. }
  101780. #include <stdio.h>
  101781. float vorbis_fromdBlook(float a){
  101782. int i=vorbis_ftoi(a*((float)(-(1<<FROMdB2_SHIFT)))-.5f);
  101783. return (i<0)?1.f:
  101784. ((i>=(FROMdB_LOOKUP_SZ<<FROMdB_SHIFT))?0.f:
  101785. FROMdB_LOOKUP[i>>FROMdB_SHIFT]*FROMdB2_LOOKUP[i&FROMdB2_MASK]);
  101786. }
  101787. #endif
  101788. #ifdef INT_LOOKUP
  101789. long vorbis_invsqlook_i(long a,long e){
  101790. long i=(a&0x7fff)>>(INVSQ_LOOKUP_I_SHIFT-1);
  101791. long d=(a&INVSQ_LOOKUP_I_MASK)<<(16-INVSQ_LOOKUP_I_SHIFT); /* 0.16 */
  101792. long val=INVSQ_LOOKUP_I[i]- /* 1.16 */
  101793. (((INVSQ_LOOKUP_I[i]-INVSQ_LOOKUP_I[i+1])* /* 0.16 */
  101794. d)>>16); /* result 1.16 */
  101795. e+=32;
  101796. if(e&1)val=(val*5792)>>13; /* multiply val by 1/sqrt(2) */
  101797. e=(e>>1)-8;
  101798. return(val>>e);
  101799. }
  101800. float vorbis_fromdBlook_i(long a){
  101801. int i=(-a)>>(12-FROMdB2_SHIFT);
  101802. return (i<0)?1.f:
  101803. ((i>=(FROMdB_LOOKUP_SZ<<FROMdB_SHIFT))?0.f:
  101804. FROMdB_LOOKUP[i>>FROMdB_SHIFT]*FROMdB2_LOOKUP[i&FROMdB2_MASK]);
  101805. }
  101806. long vorbis_coslook_i(long a){
  101807. int i=a>>COS_LOOKUP_I_SHIFT;
  101808. int d=a&COS_LOOKUP_I_MASK;
  101809. return COS_LOOKUP_I[i]- ((d*(COS_LOOKUP_I[i]-COS_LOOKUP_I[i+1]))>>
  101810. COS_LOOKUP_I_SHIFT);
  101811. }
  101812. #endif
  101813. #endif
  101814. /********* End of inlined file: lookup.c *********/
  101815. static int MLOOP_1[64]={
  101816. 0,10,11,11, 12,12,12,12, 13,13,13,13, 13,13,13,13,
  101817. 14,14,14,14, 14,14,14,14, 14,14,14,14, 14,14,14,14,
  101818. 15,15,15,15, 15,15,15,15, 15,15,15,15, 15,15,15,15,
  101819. 15,15,15,15, 15,15,15,15, 15,15,15,15, 15,15,15,15,
  101820. };
  101821. static int MLOOP_2[64]={
  101822. 0,4,5,5, 6,6,6,6, 7,7,7,7, 7,7,7,7,
  101823. 8,8,8,8, 8,8,8,8, 8,8,8,8, 8,8,8,8,
  101824. 9,9,9,9, 9,9,9,9, 9,9,9,9, 9,9,9,9,
  101825. 9,9,9,9, 9,9,9,9, 9,9,9,9, 9,9,9,9,
  101826. };
  101827. static int MLOOP_3[8]={0,1,2,2,3,3,3,3};
  101828. void vorbis_lsp_to_curve(float *curve,int *map,int n,int ln,float *lsp,int m,
  101829. float amp,float ampoffset){
  101830. int i;
  101831. int ampoffseti=rint(ampoffset*4096.f);
  101832. int ampi=rint(amp*16.f);
  101833. long *ilsp=alloca(m*sizeof(*ilsp));
  101834. for(i=0;i<m;i++)ilsp[i]=vorbis_coslook_i(lsp[i]/M_PI*65536.f+.5f);
  101835. i=0;
  101836. while(i<n){
  101837. int j,k=map[i];
  101838. unsigned long pi=46341; /* 2**-.5 in 0.16 */
  101839. unsigned long qi=46341;
  101840. int qexp=0,shift;
  101841. long wi=vorbis_coslook_i(k*65536/ln);
  101842. qi*=labs(ilsp[0]-wi);
  101843. pi*=labs(ilsp[1]-wi);
  101844. for(j=3;j<m;j+=2){
  101845. if(!(shift=MLOOP_1[(pi|qi)>>25]))
  101846. if(!(shift=MLOOP_2[(pi|qi)>>19]))
  101847. shift=MLOOP_3[(pi|qi)>>16];
  101848. qi=(qi>>shift)*labs(ilsp[j-1]-wi);
  101849. pi=(pi>>shift)*labs(ilsp[j]-wi);
  101850. qexp+=shift;
  101851. }
  101852. if(!(shift=MLOOP_1[(pi|qi)>>25]))
  101853. if(!(shift=MLOOP_2[(pi|qi)>>19]))
  101854. shift=MLOOP_3[(pi|qi)>>16];
  101855. if(m&1){
  101856. qi=(qi>>shift)*labs(ilsp[j-1]-wi);
  101857. pi=(pi>>shift)<<14;
  101858. qexp+=shift;
  101859. if(!(shift=MLOOP_1[(pi|qi)>>25]))
  101860. if(!(shift=MLOOP_2[(pi|qi)>>19]))
  101861. shift=MLOOP_3[(pi|qi)>>16];
  101862. pi>>=shift;
  101863. qi>>=shift;
  101864. qexp+=shift-14*((m+1)>>1);
  101865. pi=((pi*pi)>>16);
  101866. qi=((qi*qi)>>16);
  101867. qexp=qexp*2+m;
  101868. pi*=(1<<14)-((wi*wi)>>14);
  101869. qi+=pi>>14;
  101870. }else{
  101871. pi>>=shift;
  101872. qi>>=shift;
  101873. qexp+=shift-7*m;
  101874. pi=((pi*pi)>>16);
  101875. qi=((qi*qi)>>16);
  101876. qexp=qexp*2+m;
  101877. pi*=(1<<14)-wi;
  101878. qi*=(1<<14)+wi;
  101879. qi=(qi+pi)>>14;
  101880. }
  101881. if(qi&0xffff0000){ /* checks for 1.xxxxxxxxxxxxxxxx */
  101882. qi>>=1; qexp++;
  101883. }else
  101884. while(qi && !(qi&0x8000)){ /* checks for 0.0xxxxxxxxxxxxxxx or less*/
  101885. qi<<=1; qexp--;
  101886. }
  101887. amp=vorbis_fromdBlook_i(ampi* /* n.4 */
  101888. vorbis_invsqlook_i(qi,qexp)-
  101889. ampoffseti); /* 8.12[0] */
  101890. curve[i]*=amp;
  101891. while(map[++i]==k)curve[i]*=amp;
  101892. }
  101893. }
  101894. #else
  101895. void vorbis_lsp_to_curve(float *curve,int *map,int n,int ln,float *lsp,int m,
  101896. float amp,float ampoffset){
  101897. int i;
  101898. float wdel=M_PI/ln;
  101899. for(i=0;i<m;i++)lsp[i]=2.f*cos(lsp[i]);
  101900. i=0;
  101901. while(i<n){
  101902. int j,k=map[i];
  101903. float p=.5f;
  101904. float q=.5f;
  101905. float w=2.f*cos(wdel*k);
  101906. for(j=1;j<m;j+=2){
  101907. q *= w-lsp[j-1];
  101908. p *= w-lsp[j];
  101909. }
  101910. if(j==m){
  101911. q*=w-lsp[j-1];
  101912. p*=p*(4.f-w*w);
  101913. q*=q;
  101914. }else{
  101915. p*=p*(2.f-w);
  101916. q*=q*(2.f+w);
  101917. }
  101918. q=fromdB(amp/sqrt(p+q)-ampoffset);
  101919. curve[i]*=q;
  101920. while(map[++i]==k)curve[i]*=q;
  101921. }
  101922. }
  101923. #endif
  101924. #endif
  101925. static void cheby(float *g, int ord) {
  101926. int i, j;
  101927. g[0] *= .5f;
  101928. for(i=2; i<= ord; i++) {
  101929. for(j=ord; j >= i; j--) {
  101930. g[j-2] -= g[j];
  101931. g[j] += g[j];
  101932. }
  101933. }
  101934. }
  101935. static int comp(const void *a,const void *b){
  101936. return (*(float *)a<*(float *)b)-(*(float *)a>*(float *)b);
  101937. }
  101938. #define EPSILON 10e-7
  101939. static int Laguerre_With_Deflation(float *a,int ord,float *r){
  101940. int i,m;
  101941. double lastdelta=0.f;
  101942. double *defl=(double*)alloca(sizeof(*defl)*(ord+1));
  101943. for(i=0;i<=ord;i++)defl[i]=a[i];
  101944. for(m=ord;m>0;m--){
  101945. double newx=0.f,delta;
  101946. while(1){
  101947. double p=defl[m],pp=0.f,ppp=0.f,denom;
  101948. for(i=m;i>0;i--){
  101949. ppp = newx*ppp + pp;
  101950. pp = newx*pp + p;
  101951. p = newx*p + defl[i-1];
  101952. }
  101953. denom=(m-1) * ((m-1)*pp*pp - m*p*ppp);
  101954. if(denom<0)
  101955. return(-1); /* complex root! The LPC generator handed us a bad filter */
  101956. if(pp>0){
  101957. denom = pp + sqrt(denom);
  101958. if(denom<EPSILON)denom=EPSILON;
  101959. }else{
  101960. denom = pp - sqrt(denom);
  101961. if(denom>-(EPSILON))denom=-(EPSILON);
  101962. }
  101963. delta = m*p/denom;
  101964. newx -= delta;
  101965. if(delta<0.f)delta*=-1;
  101966. if(fabs(delta/newx)<10e-12)break;
  101967. lastdelta=delta;
  101968. }
  101969. r[m-1]=newx;
  101970. for(i=m;i>0;i--)
  101971. defl[i-1]+=newx*defl[i];
  101972. defl++;
  101973. }
  101974. return(0);
  101975. }
  101976. static int Newton_Raphson(float *a,int ord,float *r){
  101977. int i, k, count=0;
  101978. double error=1.f;
  101979. double *root=(double*)alloca(ord*sizeof(*root));
  101980. for(i=0; i<ord;i++) root[i] = r[i];
  101981. while(error>1e-20){
  101982. error=0;
  101983. for(i=0; i<ord; i++) { /* Update each point. */
  101984. double pp=0.,delta;
  101985. double rooti=root[i];
  101986. double p=a[ord];
  101987. for(k=ord-1; k>= 0; k--) {
  101988. pp= pp* rooti + p;
  101989. p = p * rooti + a[k];
  101990. }
  101991. delta = p/pp;
  101992. root[i] -= delta;
  101993. error+= delta*delta;
  101994. }
  101995. if(count>40)return(-1);
  101996. count++;
  101997. }
  101998. for(i=0; i<ord;i++) r[i] = root[i];
  101999. return(0);
  102000. }
  102001. int vorbis_lpc_to_lsp(float *lpc,float *lsp,int m){
  102002. int order2=(m+1)>>1;
  102003. int g1_order,g2_order;
  102004. float *g1=(float*)alloca(sizeof(*g1)*(order2+1));
  102005. float *g2=(float*)alloca(sizeof(*g2)*(order2+1));
  102006. float *g1r=(float*)alloca(sizeof(*g1r)*(order2+1));
  102007. float *g2r=(float*)alloca(sizeof(*g2r)*(order2+1));
  102008. int i;
  102009. g1_order=(m+1)>>1;
  102010. g2_order=(m) >>1;
  102011. g1[g1_order] = 1.f;
  102012. for(i=1;i<=g1_order;i++) g1[g1_order-i] = lpc[i-1]+lpc[m-i];
  102013. g2[g2_order] = 1.f;
  102014. for(i=1;i<=g2_order;i++) g2[g2_order-i] = lpc[i-1]-lpc[m-i];
  102015. if(g1_order>g2_order){
  102016. for(i=2; i<=g2_order;i++) g2[g2_order-i] += g2[g2_order-i+2];
  102017. }else{
  102018. for(i=1; i<=g1_order;i++) g1[g1_order-i] -= g1[g1_order-i+1];
  102019. for(i=1; i<=g2_order;i++) g2[g2_order-i] += g2[g2_order-i+1];
  102020. }
  102021. cheby(g1,g1_order);
  102022. cheby(g2,g2_order);
  102023. if(Laguerre_With_Deflation(g1,g1_order,g1r) ||
  102024. Laguerre_With_Deflation(g2,g2_order,g2r))
  102025. return(-1);
  102026. Newton_Raphson(g1,g1_order,g1r); /* if it fails, it leaves g1r alone */
  102027. Newton_Raphson(g2,g2_order,g2r); /* if it fails, it leaves g2r alone */
  102028. qsort(g1r,g1_order,sizeof(*g1r),comp);
  102029. qsort(g2r,g2_order,sizeof(*g2r),comp);
  102030. for(i=0;i<g1_order;i++)
  102031. lsp[i*2] = acos(g1r[i]);
  102032. for(i=0;i<g2_order;i++)
  102033. lsp[i*2+1] = acos(g2r[i]);
  102034. return(0);
  102035. }
  102036. #endif
  102037. /********* End of inlined file: lsp.c *********/
  102038. /********* Start of inlined file: mapping0.c *********/
  102039. /********* Start of inlined file: juce_OggVorbisHeader.h *********/
  102040. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  102041. // tasks..
  102042. #if JUCE_MSVC
  102043. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  102044. #endif
  102045. /********* End of inlined file: juce_OggVorbisHeader.h *********/
  102046. #if JUCE_USE_OGGVORBIS
  102047. #include <stdlib.h>
  102048. #include <stdio.h>
  102049. #include <string.h>
  102050. #include <math.h>
  102051. static void mapping0_free_info(vorbis_info_mapping *i){
  102052. vorbis_info_mapping0 *info=(vorbis_info_mapping0 *)i;
  102053. if(info){
  102054. memset(info,0,sizeof(*info));
  102055. _ogg_free(info);
  102056. }
  102057. }
  102058. static int ilog3(unsigned int v){
  102059. int ret=0;
  102060. if(v)--v;
  102061. while(v){
  102062. ret++;
  102063. v>>=1;
  102064. }
  102065. return(ret);
  102066. }
  102067. static void mapping0_pack(vorbis_info *vi,vorbis_info_mapping *vm,
  102068. oggpack_buffer *opb){
  102069. int i;
  102070. vorbis_info_mapping0 *info=(vorbis_info_mapping0 *)vm;
  102071. if(info->submaps>1){
  102072. oggpack_write(opb,1,1);
  102073. oggpack_write(opb,info->submaps-1,4);
  102074. }else
  102075. oggpack_write(opb,0,1);
  102076. if(info->coupling_steps>0){
  102077. oggpack_write(opb,1,1);
  102078. oggpack_write(opb,info->coupling_steps-1,8);
  102079. for(i=0;i<info->coupling_steps;i++){
  102080. oggpack_write(opb,info->coupling_mag[i],ilog3(vi->channels));
  102081. oggpack_write(opb,info->coupling_ang[i],ilog3(vi->channels));
  102082. }
  102083. }else
  102084. oggpack_write(opb,0,1);
  102085. oggpack_write(opb,0,2); /* 2,3:reserved */
  102086. if(info->submaps>1){
  102087. for(i=0;i<vi->channels;i++)
  102088. oggpack_write(opb,info->chmuxlist[i],4);
  102089. }
  102090. for(i=0;i<info->submaps;i++){
  102091. oggpack_write(opb,0,8); /* time submap unused */
  102092. oggpack_write(opb,info->floorsubmap[i],8);
  102093. oggpack_write(opb,info->residuesubmap[i],8);
  102094. }
  102095. }
  102096. static vorbis_info_mapping *mapping0_unpack(vorbis_info *vi,oggpack_buffer *opb){
  102097. int i;
  102098. vorbis_info_mapping0 *info=(vorbis_info_mapping0*)_ogg_calloc(1,sizeof(*info));
  102099. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  102100. memset(info,0,sizeof(*info));
  102101. if(oggpack_read(opb,1))
  102102. info->submaps=oggpack_read(opb,4)+1;
  102103. else
  102104. info->submaps=1;
  102105. if(oggpack_read(opb,1)){
  102106. info->coupling_steps=oggpack_read(opb,8)+1;
  102107. for(i=0;i<info->coupling_steps;i++){
  102108. int testM=info->coupling_mag[i]=oggpack_read(opb,ilog3(vi->channels));
  102109. int testA=info->coupling_ang[i]=oggpack_read(opb,ilog3(vi->channels));
  102110. if(testM<0 ||
  102111. testA<0 ||
  102112. testM==testA ||
  102113. testM>=vi->channels ||
  102114. testA>=vi->channels) goto err_out;
  102115. }
  102116. }
  102117. if(oggpack_read(opb,2)>0)goto err_out; /* 2,3:reserved */
  102118. if(info->submaps>1){
  102119. for(i=0;i<vi->channels;i++){
  102120. info->chmuxlist[i]=oggpack_read(opb,4);
  102121. if(info->chmuxlist[i]>=info->submaps)goto err_out;
  102122. }
  102123. }
  102124. for(i=0;i<info->submaps;i++){
  102125. oggpack_read(opb,8); /* time submap unused */
  102126. info->floorsubmap[i]=oggpack_read(opb,8);
  102127. if(info->floorsubmap[i]>=ci->floors)goto err_out;
  102128. info->residuesubmap[i]=oggpack_read(opb,8);
  102129. if(info->residuesubmap[i]>=ci->residues)goto err_out;
  102130. }
  102131. return info;
  102132. err_out:
  102133. mapping0_free_info(info);
  102134. return(NULL);
  102135. }
  102136. #if 0
  102137. static long seq=0;
  102138. static ogg_int64_t total=0;
  102139. static float FLOOR1_fromdB_LOOKUP[256]={
  102140. 1.0649863e-07F, 1.1341951e-07F, 1.2079015e-07F, 1.2863978e-07F,
  102141. 1.3699951e-07F, 1.4590251e-07F, 1.5538408e-07F, 1.6548181e-07F,
  102142. 1.7623575e-07F, 1.8768855e-07F, 1.9988561e-07F, 2.128753e-07F,
  102143. 2.2670913e-07F, 2.4144197e-07F, 2.5713223e-07F, 2.7384213e-07F,
  102144. 2.9163793e-07F, 3.1059021e-07F, 3.3077411e-07F, 3.5226968e-07F,
  102145. 3.7516214e-07F, 3.9954229e-07F, 4.2550680e-07F, 4.5315863e-07F,
  102146. 4.8260743e-07F, 5.1396998e-07F, 5.4737065e-07F, 5.8294187e-07F,
  102147. 6.2082472e-07F, 6.6116941e-07F, 7.0413592e-07F, 7.4989464e-07F,
  102148. 7.9862701e-07F, 8.5052630e-07F, 9.0579828e-07F, 9.6466216e-07F,
  102149. 1.0273513e-06F, 1.0941144e-06F, 1.1652161e-06F, 1.2409384e-06F,
  102150. 1.3215816e-06F, 1.4074654e-06F, 1.4989305e-06F, 1.5963394e-06F,
  102151. 1.7000785e-06F, 1.8105592e-06F, 1.9282195e-06F, 2.0535261e-06F,
  102152. 2.1869758e-06F, 2.3290978e-06F, 2.4804557e-06F, 2.6416497e-06F,
  102153. 2.8133190e-06F, 2.9961443e-06F, 3.1908506e-06F, 3.3982101e-06F,
  102154. 3.6190449e-06F, 3.8542308e-06F, 4.1047004e-06F, 4.3714470e-06F,
  102155. 4.6555282e-06F, 4.9580707e-06F, 5.2802740e-06F, 5.6234160e-06F,
  102156. 5.9888572e-06F, 6.3780469e-06F, 6.7925283e-06F, 7.2339451e-06F,
  102157. 7.7040476e-06F, 8.2047000e-06F, 8.7378876e-06F, 9.3057248e-06F,
  102158. 9.9104632e-06F, 1.0554501e-05F, 1.1240392e-05F, 1.1970856e-05F,
  102159. 1.2748789e-05F, 1.3577278e-05F, 1.4459606e-05F, 1.5399272e-05F,
  102160. 1.6400004e-05F, 1.7465768e-05F, 1.8600792e-05F, 1.9809576e-05F,
  102161. 2.1096914e-05F, 2.2467911e-05F, 2.3928002e-05F, 2.5482978e-05F,
  102162. 2.7139006e-05F, 2.8902651e-05F, 3.0780908e-05F, 3.2781225e-05F,
  102163. 3.4911534e-05F, 3.7180282e-05F, 3.9596466e-05F, 4.2169667e-05F,
  102164. 4.4910090e-05F, 4.7828601e-05F, 5.0936773e-05F, 5.4246931e-05F,
  102165. 5.7772202e-05F, 6.1526565e-05F, 6.5524908e-05F, 6.9783085e-05F,
  102166. 7.4317983e-05F, 7.9147585e-05F, 8.4291040e-05F, 8.9768747e-05F,
  102167. 9.5602426e-05F, 0.00010181521F, 0.00010843174F, 0.00011547824F,
  102168. 0.00012298267F, 0.00013097477F, 0.00013948625F, 0.00014855085F,
  102169. 0.00015820453F, 0.00016848555F, 0.00017943469F, 0.00019109536F,
  102170. 0.00020351382F, 0.00021673929F, 0.00023082423F, 0.00024582449F,
  102171. 0.00026179955F, 0.00027881276F, 0.00029693158F, 0.00031622787F,
  102172. 0.00033677814F, 0.00035866388F, 0.00038197188F, 0.00040679456F,
  102173. 0.00043323036F, 0.00046138411F, 0.00049136745F, 0.00052329927F,
  102174. 0.00055730621F, 0.00059352311F, 0.00063209358F, 0.00067317058F,
  102175. 0.00071691700F, 0.00076350630F, 0.00081312324F, 0.00086596457F,
  102176. 0.00092223983F, 0.00098217216F, 0.0010459992F, 0.0011139742F,
  102177. 0.0011863665F, 0.0012634633F, 0.0013455702F, 0.0014330129F,
  102178. 0.0015261382F, 0.0016253153F, 0.0017309374F, 0.0018434235F,
  102179. 0.0019632195F, 0.0020908006F, 0.0022266726F, 0.0023713743F,
  102180. 0.0025254795F, 0.0026895994F, 0.0028643847F, 0.0030505286F,
  102181. 0.0032487691F, 0.0034598925F, 0.0036847358F, 0.0039241906F,
  102182. 0.0041792066F, 0.0044507950F, 0.0047400328F, 0.0050480668F,
  102183. 0.0053761186F, 0.0057254891F, 0.0060975636F, 0.0064938176F,
  102184. 0.0069158225F, 0.0073652516F, 0.0078438871F, 0.0083536271F,
  102185. 0.0088964928F, 0.009474637F, 0.010090352F, 0.010746080F,
  102186. 0.011444421F, 0.012188144F, 0.012980198F, 0.013823725F,
  102187. 0.014722068F, 0.015678791F, 0.016697687F, 0.017782797F,
  102188. 0.018938423F, 0.020169149F, 0.021479854F, 0.022875735F,
  102189. 0.024362330F, 0.025945531F, 0.027631618F, 0.029427276F,
  102190. 0.031339626F, 0.033376252F, 0.035545228F, 0.037855157F,
  102191. 0.040315199F, 0.042935108F, 0.045725273F, 0.048696758F,
  102192. 0.051861348F, 0.055231591F, 0.058820850F, 0.062643361F,
  102193. 0.066714279F, 0.071049749F, 0.075666962F, 0.080584227F,
  102194. 0.085821044F, 0.091398179F, 0.097337747F, 0.10366330F,
  102195. 0.11039993F, 0.11757434F, 0.12521498F, 0.13335215F,
  102196. 0.14201813F, 0.15124727F, 0.16107617F, 0.17154380F,
  102197. 0.18269168F, 0.19456402F, 0.20720788F, 0.22067342F,
  102198. 0.23501402F, 0.25028656F, 0.26655159F, 0.28387361F,
  102199. 0.30232132F, 0.32196786F, 0.34289114F, 0.36517414F,
  102200. 0.38890521F, 0.41417847F, 0.44109412F, 0.46975890F,
  102201. 0.50028648F, 0.53279791F, 0.56742212F, 0.60429640F,
  102202. 0.64356699F, 0.68538959F, 0.72993007F, 0.77736504F,
  102203. 0.82788260F, 0.88168307F, 0.9389798F, 1.F,
  102204. };
  102205. #endif
  102206. extern int *floor1_fit(vorbis_block *vb,void *look,
  102207. const float *logmdct, /* in */
  102208. const float *logmask);
  102209. extern int *floor1_interpolate_fit(vorbis_block *vb,void *look,
  102210. int *A,int *B,
  102211. int del);
  102212. extern int floor1_encode(oggpack_buffer *opb,vorbis_block *vb,
  102213. void*look,
  102214. int *post,int *ilogmask);
  102215. static int mapping0_forward(vorbis_block *vb){
  102216. vorbis_dsp_state *vd=vb->vd;
  102217. vorbis_info *vi=vd->vi;
  102218. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  102219. private_state *b=(private_state*)vb->vd->backend_state;
  102220. vorbis_block_internal *vbi=(vorbis_block_internal *)vb->internal;
  102221. int n=vb->pcmend;
  102222. int i,j,k;
  102223. int *nonzero = (int*) alloca(sizeof(*nonzero)*vi->channels);
  102224. float **gmdct = (float**) _vorbis_block_alloc(vb,vi->channels*sizeof(*gmdct));
  102225. int **ilogmaskch= (int**) _vorbis_block_alloc(vb,vi->channels*sizeof(*ilogmaskch));
  102226. int ***floor_posts = (int***) _vorbis_block_alloc(vb,vi->channels*sizeof(*floor_posts));
  102227. float global_ampmax=vbi->ampmax;
  102228. float *local_ampmax=(float*)alloca(sizeof(*local_ampmax)*vi->channels);
  102229. int blocktype=vbi->blocktype;
  102230. int modenumber=vb->W;
  102231. vorbis_info_mapping0 *info=(vorbis_info_mapping0*)ci->map_param[modenumber];
  102232. vorbis_look_psy *psy_look=
  102233. b->psy+blocktype+(vb->W?2:0);
  102234. vb->mode=modenumber;
  102235. for(i=0;i<vi->channels;i++){
  102236. float scale=4.f/n;
  102237. float scale_dB;
  102238. float *pcm =vb->pcm[i];
  102239. float *logfft =pcm;
  102240. gmdct[i]=(float*)_vorbis_block_alloc(vb,n/2*sizeof(**gmdct));
  102241. scale_dB=todB(&scale) + .345; /* + .345 is a hack; the original
  102242. todB estimation used on IEEE 754
  102243. compliant machines had a bug that
  102244. returned dB values about a third
  102245. of a decibel too high. The bug
  102246. was harmless because tunings
  102247. implicitly took that into
  102248. account. However, fixing the bug
  102249. in the estimator requires
  102250. changing all the tunings as well.
  102251. For now, it's easier to sync
  102252. things back up here, and
  102253. recalibrate the tunings in the
  102254. next major model upgrade. */
  102255. #if 0
  102256. if(vi->channels==2)
  102257. if(i==0)
  102258. _analysis_output("pcmL",seq,pcm,n,0,0,total-n/2);
  102259. else
  102260. _analysis_output("pcmR",seq,pcm,n,0,0,total-n/2);
  102261. #endif
  102262. _vorbis_apply_window(pcm,b->window,ci->blocksizes,vb->lW,vb->W,vb->nW);
  102263. #if 0
  102264. if(vi->channels==2)
  102265. if(i==0)
  102266. _analysis_output("windowedL",seq,pcm,n,0,0,total-n/2);
  102267. else
  102268. _analysis_output("windowedR",seq,pcm,n,0,0,total-n/2);
  102269. #endif
  102270. mdct_forward((mdct_lookup*) b->transform[vb->W][0],pcm,gmdct[i]);
  102271. drft_forward(&b->fft_look[vb->W],pcm);
  102272. logfft[0]=scale_dB+todB(pcm) + .345; /* + .345 is a hack; the
  102273. original todB estimation used on
  102274. IEEE 754 compliant machines had a
  102275. bug that returned dB values about
  102276. a third of a decibel too high.
  102277. The bug was harmless because
  102278. tunings implicitly took that into
  102279. account. However, fixing the bug
  102280. in the estimator requires
  102281. changing all the tunings as well.
  102282. For now, it's easier to sync
  102283. things back up here, and
  102284. recalibrate the tunings in the
  102285. next major model upgrade. */
  102286. local_ampmax[i]=logfft[0];
  102287. for(j=1;j<n-1;j+=2){
  102288. float temp=pcm[j]*pcm[j]+pcm[j+1]*pcm[j+1];
  102289. temp=logfft[(j+1)>>1]=scale_dB+.5f*todB(&temp) + .345; /* +
  102290. .345 is a hack; the original todB
  102291. estimation used on IEEE 754
  102292. compliant machines had a bug that
  102293. returned dB values about a third
  102294. of a decibel too high. The bug
  102295. was harmless because tunings
  102296. implicitly took that into
  102297. account. However, fixing the bug
  102298. in the estimator requires
  102299. changing all the tunings as well.
  102300. For now, it's easier to sync
  102301. things back up here, and
  102302. recalibrate the tunings in the
  102303. next major model upgrade. */
  102304. if(temp>local_ampmax[i])local_ampmax[i]=temp;
  102305. }
  102306. if(local_ampmax[i]>0.f)local_ampmax[i]=0.f;
  102307. if(local_ampmax[i]>global_ampmax)global_ampmax=local_ampmax[i];
  102308. #if 0
  102309. if(vi->channels==2){
  102310. if(i==0){
  102311. _analysis_output("fftL",seq,logfft,n/2,1,0,0);
  102312. }else{
  102313. _analysis_output("fftR",seq,logfft,n/2,1,0,0);
  102314. }
  102315. }
  102316. #endif
  102317. }
  102318. {
  102319. float *noise = (float*) _vorbis_block_alloc(vb,n/2*sizeof(*noise));
  102320. float *tone = (float*) _vorbis_block_alloc(vb,n/2*sizeof(*tone));
  102321. for(i=0;i<vi->channels;i++){
  102322. int submap=info->chmuxlist[i];
  102323. float *mdct =gmdct[i];
  102324. float *logfft =vb->pcm[i];
  102325. float *logmdct =logfft+n/2;
  102326. float *logmask =logfft;
  102327. vb->mode=modenumber;
  102328. floor_posts[i]=(int**) _vorbis_block_alloc(vb,PACKETBLOBS*sizeof(**floor_posts));
  102329. memset(floor_posts[i],0,sizeof(**floor_posts)*PACKETBLOBS);
  102330. for(j=0;j<n/2;j++)
  102331. logmdct[j]=todB(mdct+j) + .345; /* + .345 is a hack; the original
  102332. todB estimation used on IEEE 754
  102333. compliant machines had a bug that
  102334. returned dB values about a third
  102335. of a decibel too high. The bug
  102336. was harmless because tunings
  102337. implicitly took that into
  102338. account. However, fixing the bug
  102339. in the estimator requires
  102340. changing all the tunings as well.
  102341. For now, it's easier to sync
  102342. things back up here, and
  102343. recalibrate the tunings in the
  102344. next major model upgrade. */
  102345. #if 0
  102346. if(vi->channels==2){
  102347. if(i==0)
  102348. _analysis_output("mdctL",seq,logmdct,n/2,1,0,0);
  102349. else
  102350. _analysis_output("mdctR",seq,logmdct,n/2,1,0,0);
  102351. }else{
  102352. _analysis_output("mdct",seq,logmdct,n/2,1,0,0);
  102353. }
  102354. #endif
  102355. _vp_noisemask(psy_look,
  102356. logmdct,
  102357. noise); /* noise does not have by-frequency offset
  102358. bias applied yet */
  102359. #if 0
  102360. if(vi->channels==2){
  102361. if(i==0)
  102362. _analysis_output("noiseL",seq,noise,n/2,1,0,0);
  102363. else
  102364. _analysis_output("noiseR",seq,noise,n/2,1,0,0);
  102365. }
  102366. #endif
  102367. _vp_tonemask(psy_look,
  102368. logfft,
  102369. tone,
  102370. global_ampmax,
  102371. local_ampmax[i]);
  102372. #if 0
  102373. if(vi->channels==2){
  102374. if(i==0)
  102375. _analysis_output("toneL",seq,tone,n/2,1,0,0);
  102376. else
  102377. _analysis_output("toneR",seq,tone,n/2,1,0,0);
  102378. }
  102379. #endif
  102380. #if 0
  102381. {
  102382. float aotuv[psy_look->n];
  102383. #endif
  102384. _vp_offset_and_mix(psy_look,
  102385. noise,
  102386. tone,
  102387. 1,
  102388. logmask,
  102389. mdct,
  102390. logmdct);
  102391. #if 0
  102392. if(vi->channels==2){
  102393. if(i==0)
  102394. _analysis_output("aotuvM1_L",seq,aotuv,psy_look->n,1,1,0);
  102395. else
  102396. _analysis_output("aotuvM1_R",seq,aotuv,psy_look->n,1,1,0);
  102397. }
  102398. }
  102399. #endif
  102400. #if 0
  102401. if(vi->channels==2){
  102402. if(i==0)
  102403. _analysis_output("mask1L",seq,logmask,n/2,1,0,0);
  102404. else
  102405. _analysis_output("mask1R",seq,logmask,n/2,1,0,0);
  102406. }
  102407. #endif
  102408. if(ci->floor_type[info->floorsubmap[submap]]!=1)return(-1);
  102409. floor_posts[i][PACKETBLOBS/2]=
  102410. floor1_fit(vb,b->flr[info->floorsubmap[submap]],
  102411. logmdct,
  102412. logmask);
  102413. if(vorbis_bitrate_managed(vb) && floor_posts[i][PACKETBLOBS/2]){
  102414. _vp_offset_and_mix(psy_look,
  102415. noise,
  102416. tone,
  102417. 2,
  102418. logmask,
  102419. mdct,
  102420. logmdct);
  102421. #if 0
  102422. if(vi->channels==2){
  102423. if(i==0)
  102424. _analysis_output("mask2L",seq,logmask,n/2,1,0,0);
  102425. else
  102426. _analysis_output("mask2R",seq,logmask,n/2,1,0,0);
  102427. }
  102428. #endif
  102429. floor_posts[i][PACKETBLOBS-1]=
  102430. floor1_fit(vb,b->flr[info->floorsubmap[submap]],
  102431. logmdct,
  102432. logmask);
  102433. _vp_offset_and_mix(psy_look,
  102434. noise,
  102435. tone,
  102436. 0,
  102437. logmask,
  102438. mdct,
  102439. logmdct);
  102440. #if 0
  102441. if(vi->channels==2)
  102442. if(i==0)
  102443. _analysis_output("mask0L",seq,logmask,n/2,1,0,0);
  102444. else
  102445. _analysis_output("mask0R",seq,logmask,n/2,1,0,0);
  102446. #endif
  102447. floor_posts[i][0]=
  102448. floor1_fit(vb,b->flr[info->floorsubmap[submap]],
  102449. logmdct,
  102450. logmask);
  102451. for(k=1;k<PACKETBLOBS/2;k++)
  102452. floor_posts[i][k]=
  102453. floor1_interpolate_fit(vb,b->flr[info->floorsubmap[submap]],
  102454. floor_posts[i][0],
  102455. floor_posts[i][PACKETBLOBS/2],
  102456. k*65536/(PACKETBLOBS/2));
  102457. for(k=PACKETBLOBS/2+1;k<PACKETBLOBS-1;k++)
  102458. floor_posts[i][k]=
  102459. floor1_interpolate_fit(vb,b->flr[info->floorsubmap[submap]],
  102460. floor_posts[i][PACKETBLOBS/2],
  102461. floor_posts[i][PACKETBLOBS-1],
  102462. (k-PACKETBLOBS/2)*65536/(PACKETBLOBS/2));
  102463. }
  102464. }
  102465. }
  102466. vbi->ampmax=global_ampmax;
  102467. {
  102468. float **res_bundle=(float**) alloca(sizeof(*res_bundle)*vi->channels);
  102469. float **couple_bundle=(float**) alloca(sizeof(*couple_bundle)*vi->channels);
  102470. int *zerobundle=(int*) alloca(sizeof(*zerobundle)*vi->channels);
  102471. int **sortindex=(int**) alloca(sizeof(*sortindex)*vi->channels);
  102472. float **mag_memo;
  102473. int **mag_sort;
  102474. if(info->coupling_steps){
  102475. mag_memo=_vp_quantize_couple_memo(vb,
  102476. &ci->psy_g_param,
  102477. psy_look,
  102478. info,
  102479. gmdct);
  102480. mag_sort=_vp_quantize_couple_sort(vb,
  102481. psy_look,
  102482. info,
  102483. mag_memo);
  102484. hf_reduction(&ci->psy_g_param,
  102485. psy_look,
  102486. info,
  102487. mag_memo);
  102488. }
  102489. memset(sortindex,0,sizeof(*sortindex)*vi->channels);
  102490. if(psy_look->vi->normal_channel_p){
  102491. for(i=0;i<vi->channels;i++){
  102492. float *mdct =gmdct[i];
  102493. sortindex[i]=(int*) alloca(sizeof(**sortindex)*n/2);
  102494. _vp_noise_normalize_sort(psy_look,mdct,sortindex[i]);
  102495. }
  102496. }
  102497. for(k=(vorbis_bitrate_managed(vb)?0:PACKETBLOBS/2);
  102498. k<=(vorbis_bitrate_managed(vb)?PACKETBLOBS-1:PACKETBLOBS/2);
  102499. k++){
  102500. oggpack_buffer *opb=vbi->packetblob[k];
  102501. oggpack_write(opb,0,1);
  102502. oggpack_write(opb,modenumber,b->modebits);
  102503. if(vb->W){
  102504. oggpack_write(opb,vb->lW,1);
  102505. oggpack_write(opb,vb->nW,1);
  102506. }
  102507. for(i=0;i<vi->channels;i++){
  102508. int submap=info->chmuxlist[i];
  102509. float *mdct =gmdct[i];
  102510. float *res =vb->pcm[i];
  102511. int *ilogmask=ilogmaskch[i]=
  102512. (int*) _vorbis_block_alloc(vb,n/2*sizeof(**gmdct));
  102513. nonzero[i]=floor1_encode(opb,vb,b->flr[info->floorsubmap[submap]],
  102514. floor_posts[i][k],
  102515. ilogmask);
  102516. #if 0
  102517. {
  102518. char buf[80];
  102519. sprintf(buf,"maskI%c%d",i?'R':'L',k);
  102520. float work[n/2];
  102521. for(j=0;j<n/2;j++)
  102522. work[j]=FLOOR1_fromdB_LOOKUP[ilogmask[j]];
  102523. _analysis_output(buf,seq,work,n/2,1,1,0);
  102524. }
  102525. #endif
  102526. _vp_remove_floor(psy_look,
  102527. mdct,
  102528. ilogmask,
  102529. res,
  102530. ci->psy_g_param.sliding_lowpass[vb->W][k]);
  102531. _vp_noise_normalize(psy_look,res,res+n/2,sortindex[i]);
  102532. #if 0
  102533. {
  102534. char buf[80];
  102535. float work[n/2];
  102536. for(j=0;j<n/2;j++)
  102537. work[j]=FLOOR1_fromdB_LOOKUP[ilogmask[j]]*(res+n/2)[j];
  102538. sprintf(buf,"resI%c%d",i?'R':'L',k);
  102539. _analysis_output(buf,seq,work,n/2,1,1,0);
  102540. }
  102541. #endif
  102542. }
  102543. if(info->coupling_steps){
  102544. _vp_couple(k,
  102545. &ci->psy_g_param,
  102546. psy_look,
  102547. info,
  102548. vb->pcm,
  102549. mag_memo,
  102550. mag_sort,
  102551. ilogmaskch,
  102552. nonzero,
  102553. ci->psy_g_param.sliding_lowpass[vb->W][k]);
  102554. }
  102555. for(i=0;i<info->submaps;i++){
  102556. int ch_in_bundle=0;
  102557. long **classifications;
  102558. int resnum=info->residuesubmap[i];
  102559. for(j=0;j<vi->channels;j++){
  102560. if(info->chmuxlist[j]==i){
  102561. zerobundle[ch_in_bundle]=0;
  102562. if(nonzero[j])zerobundle[ch_in_bundle]=1;
  102563. res_bundle[ch_in_bundle]=vb->pcm[j];
  102564. couple_bundle[ch_in_bundle++]=vb->pcm[j]+n/2;
  102565. }
  102566. }
  102567. classifications=_residue_P[ci->residue_type[resnum]]->
  102568. classx(vb,b->residue[resnum],couple_bundle,zerobundle,ch_in_bundle);
  102569. _residue_P[ci->residue_type[resnum]]->
  102570. forward(opb,vb,b->residue[resnum],
  102571. couple_bundle,NULL,zerobundle,ch_in_bundle,classifications);
  102572. }
  102573. }
  102574. }
  102575. #if 0
  102576. seq++;
  102577. total+=ci->blocksizes[vb->W]/4+ci->blocksizes[vb->nW]/4;
  102578. #endif
  102579. return(0);
  102580. }
  102581. static int mapping0_inverse(vorbis_block *vb,vorbis_info_mapping *l){
  102582. vorbis_dsp_state *vd=vb->vd;
  102583. vorbis_info *vi=vd->vi;
  102584. codec_setup_info *ci=(codec_setup_info*) vi->codec_setup;
  102585. private_state *b=(private_state*)vd->backend_state;
  102586. vorbis_info_mapping0 *info=(vorbis_info_mapping0 *)l;
  102587. int i,j;
  102588. long n=vb->pcmend=ci->blocksizes[vb->W];
  102589. float **pcmbundle=(float**) alloca(sizeof(*pcmbundle)*vi->channels);
  102590. int *zerobundle=(int*) alloca(sizeof(*zerobundle)*vi->channels);
  102591. int *nonzero =(int*) alloca(sizeof(*nonzero)*vi->channels);
  102592. void **floormemo=(void**) alloca(sizeof(*floormemo)*vi->channels);
  102593. for(i=0;i<vi->channels;i++){
  102594. int submap=info->chmuxlist[i];
  102595. floormemo[i]=_floor_P[ci->floor_type[info->floorsubmap[submap]]]->
  102596. inverse1(vb,b->flr[info->floorsubmap[submap]]);
  102597. if(floormemo[i])
  102598. nonzero[i]=1;
  102599. else
  102600. nonzero[i]=0;
  102601. memset(vb->pcm[i],0,sizeof(*vb->pcm[i])*n/2);
  102602. }
  102603. for(i=0;i<info->coupling_steps;i++){
  102604. if(nonzero[info->coupling_mag[i]] ||
  102605. nonzero[info->coupling_ang[i]]){
  102606. nonzero[info->coupling_mag[i]]=1;
  102607. nonzero[info->coupling_ang[i]]=1;
  102608. }
  102609. }
  102610. for(i=0;i<info->submaps;i++){
  102611. int ch_in_bundle=0;
  102612. for(j=0;j<vi->channels;j++){
  102613. if(info->chmuxlist[j]==i){
  102614. if(nonzero[j])
  102615. zerobundle[ch_in_bundle]=1;
  102616. else
  102617. zerobundle[ch_in_bundle]=0;
  102618. pcmbundle[ch_in_bundle++]=vb->pcm[j];
  102619. }
  102620. }
  102621. _residue_P[ci->residue_type[info->residuesubmap[i]]]->
  102622. inverse(vb,b->residue[info->residuesubmap[i]],
  102623. pcmbundle,zerobundle,ch_in_bundle);
  102624. }
  102625. for(i=info->coupling_steps-1;i>=0;i--){
  102626. float *pcmM=vb->pcm[info->coupling_mag[i]];
  102627. float *pcmA=vb->pcm[info->coupling_ang[i]];
  102628. for(j=0;j<n/2;j++){
  102629. float mag=pcmM[j];
  102630. float ang=pcmA[j];
  102631. if(mag>0)
  102632. if(ang>0){
  102633. pcmM[j]=mag;
  102634. pcmA[j]=mag-ang;
  102635. }else{
  102636. pcmA[j]=mag;
  102637. pcmM[j]=mag+ang;
  102638. }
  102639. else
  102640. if(ang>0){
  102641. pcmM[j]=mag;
  102642. pcmA[j]=mag+ang;
  102643. }else{
  102644. pcmA[j]=mag;
  102645. pcmM[j]=mag-ang;
  102646. }
  102647. }
  102648. }
  102649. for(i=0;i<vi->channels;i++){
  102650. float *pcm=vb->pcm[i];
  102651. int submap=info->chmuxlist[i];
  102652. _floor_P[ci->floor_type[info->floorsubmap[submap]]]->
  102653. inverse2(vb,b->flr[info->floorsubmap[submap]],
  102654. floormemo[i],pcm);
  102655. }
  102656. for(i=0;i<vi->channels;i++){
  102657. float *pcm=vb->pcm[i];
  102658. mdct_backward((mdct_lookup*) b->transform[vb->W][0],pcm,pcm);
  102659. }
  102660. return(0);
  102661. }
  102662. vorbis_func_mapping mapping0_exportbundle={
  102663. &mapping0_pack,
  102664. &mapping0_unpack,
  102665. &mapping0_free_info,
  102666. &mapping0_forward,
  102667. &mapping0_inverse
  102668. };
  102669. #endif
  102670. /********* End of inlined file: mapping0.c *********/
  102671. /********* Start of inlined file: mdct.c *********/
  102672. /********* Start of inlined file: juce_OggVorbisHeader.h *********/
  102673. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  102674. // tasks..
  102675. #if JUCE_MSVC
  102676. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  102677. #endif
  102678. /********* End of inlined file: juce_OggVorbisHeader.h *********/
  102679. #if JUCE_USE_OGGVORBIS
  102680. #include <stdio.h>
  102681. #include <stdlib.h>
  102682. #include <string.h>
  102683. #include <math.h>
  102684. void mdct_init(mdct_lookup *lookup,int n){
  102685. int *bitrev=(int*) _ogg_malloc(sizeof(*bitrev)*(n/4));
  102686. DATA_TYPE *T=(DATA_TYPE*) _ogg_malloc(sizeof(*T)*(n+n/4));
  102687. int i;
  102688. int n2=n>>1;
  102689. int log2n=lookup->log2n=rint(log((float)n)/log(2.f));
  102690. lookup->n=n;
  102691. lookup->trig=T;
  102692. lookup->bitrev=bitrev;
  102693. for(i=0;i<n/4;i++){
  102694. T[i*2]=FLOAT_CONV(cos((M_PI/n)*(4*i)));
  102695. T[i*2+1]=FLOAT_CONV(-sin((M_PI/n)*(4*i)));
  102696. T[n2+i*2]=FLOAT_CONV(cos((M_PI/(2*n))*(2*i+1)));
  102697. T[n2+i*2+1]=FLOAT_CONV(sin((M_PI/(2*n))*(2*i+1)));
  102698. }
  102699. for(i=0;i<n/8;i++){
  102700. T[n+i*2]=FLOAT_CONV(cos((M_PI/n)*(4*i+2))*.5);
  102701. T[n+i*2+1]=FLOAT_CONV(-sin((M_PI/n)*(4*i+2))*.5);
  102702. }
  102703. {
  102704. int mask=(1<<(log2n-1))-1,i,j;
  102705. int msb=1<<(log2n-2);
  102706. for(i=0;i<n/8;i++){
  102707. int acc=0;
  102708. for(j=0;msb>>j;j++)
  102709. if((msb>>j)&i)acc|=1<<j;
  102710. bitrev[i*2]=((~acc)&mask)-1;
  102711. bitrev[i*2+1]=acc;
  102712. }
  102713. }
  102714. lookup->scale=FLOAT_CONV(4.f/n);
  102715. }
  102716. STIN void mdct_butterfly_8(DATA_TYPE *x){
  102717. REG_TYPE r0 = x[6] + x[2];
  102718. REG_TYPE r1 = x[6] - x[2];
  102719. REG_TYPE r2 = x[4] + x[0];
  102720. REG_TYPE r3 = x[4] - x[0];
  102721. x[6] = r0 + r2;
  102722. x[4] = r0 - r2;
  102723. r0 = x[5] - x[1];
  102724. r2 = x[7] - x[3];
  102725. x[0] = r1 + r0;
  102726. x[2] = r1 - r0;
  102727. r0 = x[5] + x[1];
  102728. r1 = x[7] + x[3];
  102729. x[3] = r2 + r3;
  102730. x[1] = r2 - r3;
  102731. x[7] = r1 + r0;
  102732. x[5] = r1 - r0;
  102733. }
  102734. STIN void mdct_butterfly_16(DATA_TYPE *x){
  102735. REG_TYPE r0 = x[1] - x[9];
  102736. REG_TYPE r1 = x[0] - x[8];
  102737. x[8] += x[0];
  102738. x[9] += x[1];
  102739. x[0] = MULT_NORM((r0 + r1) * cPI2_8);
  102740. x[1] = MULT_NORM((r0 - r1) * cPI2_8);
  102741. r0 = x[3] - x[11];
  102742. r1 = x[10] - x[2];
  102743. x[10] += x[2];
  102744. x[11] += x[3];
  102745. x[2] = r0;
  102746. x[3] = r1;
  102747. r0 = x[12] - x[4];
  102748. r1 = x[13] - x[5];
  102749. x[12] += x[4];
  102750. x[13] += x[5];
  102751. x[4] = MULT_NORM((r0 - r1) * cPI2_8);
  102752. x[5] = MULT_NORM((r0 + r1) * cPI2_8);
  102753. r0 = x[14] - x[6];
  102754. r1 = x[15] - x[7];
  102755. x[14] += x[6];
  102756. x[15] += x[7];
  102757. x[6] = r0;
  102758. x[7] = r1;
  102759. mdct_butterfly_8(x);
  102760. mdct_butterfly_8(x+8);
  102761. }
  102762. STIN void mdct_butterfly_32(DATA_TYPE *x){
  102763. REG_TYPE r0 = x[30] - x[14];
  102764. REG_TYPE r1 = x[31] - x[15];
  102765. x[30] += x[14];
  102766. x[31] += x[15];
  102767. x[14] = r0;
  102768. x[15] = r1;
  102769. r0 = x[28] - x[12];
  102770. r1 = x[29] - x[13];
  102771. x[28] += x[12];
  102772. x[29] += x[13];
  102773. x[12] = MULT_NORM( r0 * cPI1_8 - r1 * cPI3_8 );
  102774. x[13] = MULT_NORM( r0 * cPI3_8 + r1 * cPI1_8 );
  102775. r0 = x[26] - x[10];
  102776. r1 = x[27] - x[11];
  102777. x[26] += x[10];
  102778. x[27] += x[11];
  102779. x[10] = MULT_NORM(( r0 - r1 ) * cPI2_8);
  102780. x[11] = MULT_NORM(( r0 + r1 ) * cPI2_8);
  102781. r0 = x[24] - x[8];
  102782. r1 = x[25] - x[9];
  102783. x[24] += x[8];
  102784. x[25] += x[9];
  102785. x[8] = MULT_NORM( r0 * cPI3_8 - r1 * cPI1_8 );
  102786. x[9] = MULT_NORM( r1 * cPI3_8 + r0 * cPI1_8 );
  102787. r0 = x[22] - x[6];
  102788. r1 = x[7] - x[23];
  102789. x[22] += x[6];
  102790. x[23] += x[7];
  102791. x[6] = r1;
  102792. x[7] = r0;
  102793. r0 = x[4] - x[20];
  102794. r1 = x[5] - x[21];
  102795. x[20] += x[4];
  102796. x[21] += x[5];
  102797. x[4] = MULT_NORM( r1 * cPI1_8 + r0 * cPI3_8 );
  102798. x[5] = MULT_NORM( r1 * cPI3_8 - r0 * cPI1_8 );
  102799. r0 = x[2] - x[18];
  102800. r1 = x[3] - x[19];
  102801. x[18] += x[2];
  102802. x[19] += x[3];
  102803. x[2] = MULT_NORM(( r1 + r0 ) * cPI2_8);
  102804. x[3] = MULT_NORM(( r1 - r0 ) * cPI2_8);
  102805. r0 = x[0] - x[16];
  102806. r1 = x[1] - x[17];
  102807. x[16] += x[0];
  102808. x[17] += x[1];
  102809. x[0] = MULT_NORM( r1 * cPI3_8 + r0 * cPI1_8 );
  102810. x[1] = MULT_NORM( r1 * cPI1_8 - r0 * cPI3_8 );
  102811. mdct_butterfly_16(x);
  102812. mdct_butterfly_16(x+16);
  102813. }
  102814. STIN void mdct_butterfly_first(DATA_TYPE *T,
  102815. DATA_TYPE *x,
  102816. int points){
  102817. DATA_TYPE *x1 = x + points - 8;
  102818. DATA_TYPE *x2 = x + (points>>1) - 8;
  102819. REG_TYPE r0;
  102820. REG_TYPE r1;
  102821. do{
  102822. r0 = x1[6] - x2[6];
  102823. r1 = x1[7] - x2[7];
  102824. x1[6] += x2[6];
  102825. x1[7] += x2[7];
  102826. x2[6] = MULT_NORM(r1 * T[1] + r0 * T[0]);
  102827. x2[7] = MULT_NORM(r1 * T[0] - r0 * T[1]);
  102828. r0 = x1[4] - x2[4];
  102829. r1 = x1[5] - x2[5];
  102830. x1[4] += x2[4];
  102831. x1[5] += x2[5];
  102832. x2[4] = MULT_NORM(r1 * T[5] + r0 * T[4]);
  102833. x2[5] = MULT_NORM(r1 * T[4] - r0 * T[5]);
  102834. r0 = x1[2] - x2[2];
  102835. r1 = x1[3] - x2[3];
  102836. x1[2] += x2[2];
  102837. x1[3] += x2[3];
  102838. x2[2] = MULT_NORM(r1 * T[9] + r0 * T[8]);
  102839. x2[3] = MULT_NORM(r1 * T[8] - r0 * T[9]);
  102840. r0 = x1[0] - x2[0];
  102841. r1 = x1[1] - x2[1];
  102842. x1[0] += x2[0];
  102843. x1[1] += x2[1];
  102844. x2[0] = MULT_NORM(r1 * T[13] + r0 * T[12]);
  102845. x2[1] = MULT_NORM(r1 * T[12] - r0 * T[13]);
  102846. x1-=8;
  102847. x2-=8;
  102848. T+=16;
  102849. }while(x2>=x);
  102850. }
  102851. STIN void mdct_butterfly_generic(DATA_TYPE *T,
  102852. DATA_TYPE *x,
  102853. int points,
  102854. int trigint){
  102855. DATA_TYPE *x1 = x + points - 8;
  102856. DATA_TYPE *x2 = x + (points>>1) - 8;
  102857. REG_TYPE r0;
  102858. REG_TYPE r1;
  102859. do{
  102860. r0 = x1[6] - x2[6];
  102861. r1 = x1[7] - x2[7];
  102862. x1[6] += x2[6];
  102863. x1[7] += x2[7];
  102864. x2[6] = MULT_NORM(r1 * T[1] + r0 * T[0]);
  102865. x2[7] = MULT_NORM(r1 * T[0] - r0 * T[1]);
  102866. T+=trigint;
  102867. r0 = x1[4] - x2[4];
  102868. r1 = x1[5] - x2[5];
  102869. x1[4] += x2[4];
  102870. x1[5] += x2[5];
  102871. x2[4] = MULT_NORM(r1 * T[1] + r0 * T[0]);
  102872. x2[5] = MULT_NORM(r1 * T[0] - r0 * T[1]);
  102873. T+=trigint;
  102874. r0 = x1[2] - x2[2];
  102875. r1 = x1[3] - x2[3];
  102876. x1[2] += x2[2];
  102877. x1[3] += x2[3];
  102878. x2[2] = MULT_NORM(r1 * T[1] + r0 * T[0]);
  102879. x2[3] = MULT_NORM(r1 * T[0] - r0 * T[1]);
  102880. T+=trigint;
  102881. r0 = x1[0] - x2[0];
  102882. r1 = x1[1] - x2[1];
  102883. x1[0] += x2[0];
  102884. x1[1] += x2[1];
  102885. x2[0] = MULT_NORM(r1 * T[1] + r0 * T[0]);
  102886. x2[1] = MULT_NORM(r1 * T[0] - r0 * T[1]);
  102887. T+=trigint;
  102888. x1-=8;
  102889. x2-=8;
  102890. }while(x2>=x);
  102891. }
  102892. STIN void mdct_butterflies(mdct_lookup *init,
  102893. DATA_TYPE *x,
  102894. int points){
  102895. DATA_TYPE *T=init->trig;
  102896. int stages=init->log2n-5;
  102897. int i,j;
  102898. if(--stages>0){
  102899. mdct_butterfly_first(T,x,points);
  102900. }
  102901. for(i=1;--stages>0;i++){
  102902. for(j=0;j<(1<<i);j++)
  102903. mdct_butterfly_generic(T,x+(points>>i)*j,points>>i,4<<i);
  102904. }
  102905. for(j=0;j<points;j+=32)
  102906. mdct_butterfly_32(x+j);
  102907. }
  102908. void mdct_clear(mdct_lookup *l){
  102909. if(l){
  102910. if(l->trig)_ogg_free(l->trig);
  102911. if(l->bitrev)_ogg_free(l->bitrev);
  102912. memset(l,0,sizeof(*l));
  102913. }
  102914. }
  102915. STIN void mdct_bitreverse(mdct_lookup *init,
  102916. DATA_TYPE *x){
  102917. int n = init->n;
  102918. int *bit = init->bitrev;
  102919. DATA_TYPE *w0 = x;
  102920. DATA_TYPE *w1 = x = w0+(n>>1);
  102921. DATA_TYPE *T = init->trig+n;
  102922. do{
  102923. DATA_TYPE *x0 = x+bit[0];
  102924. DATA_TYPE *x1 = x+bit[1];
  102925. REG_TYPE r0 = x0[1] - x1[1];
  102926. REG_TYPE r1 = x0[0] + x1[0];
  102927. REG_TYPE r2 = MULT_NORM(r1 * T[0] + r0 * T[1]);
  102928. REG_TYPE r3 = MULT_NORM(r1 * T[1] - r0 * T[0]);
  102929. w1 -= 4;
  102930. r0 = HALVE(x0[1] + x1[1]);
  102931. r1 = HALVE(x0[0] - x1[0]);
  102932. w0[0] = r0 + r2;
  102933. w1[2] = r0 - r2;
  102934. w0[1] = r1 + r3;
  102935. w1[3] = r3 - r1;
  102936. x0 = x+bit[2];
  102937. x1 = x+bit[3];
  102938. r0 = x0[1] - x1[1];
  102939. r1 = x0[0] + x1[0];
  102940. r2 = MULT_NORM(r1 * T[2] + r0 * T[3]);
  102941. r3 = MULT_NORM(r1 * T[3] - r0 * T[2]);
  102942. r0 = HALVE(x0[1] + x1[1]);
  102943. r1 = HALVE(x0[0] - x1[0]);
  102944. w0[2] = r0 + r2;
  102945. w1[0] = r0 - r2;
  102946. w0[3] = r1 + r3;
  102947. w1[1] = r3 - r1;
  102948. T += 4;
  102949. bit += 4;
  102950. w0 += 4;
  102951. }while(w0<w1);
  102952. }
  102953. void mdct_backward(mdct_lookup *init, DATA_TYPE *in, DATA_TYPE *out){
  102954. int n=init->n;
  102955. int n2=n>>1;
  102956. int n4=n>>2;
  102957. DATA_TYPE *iX = in+n2-7;
  102958. DATA_TYPE *oX = out+n2+n4;
  102959. DATA_TYPE *T = init->trig+n4;
  102960. do{
  102961. oX -= 4;
  102962. oX[0] = MULT_NORM(-iX[2] * T[3] - iX[0] * T[2]);
  102963. oX[1] = MULT_NORM (iX[0] * T[3] - iX[2] * T[2]);
  102964. oX[2] = MULT_NORM(-iX[6] * T[1] - iX[4] * T[0]);
  102965. oX[3] = MULT_NORM (iX[4] * T[1] - iX[6] * T[0]);
  102966. iX -= 8;
  102967. T += 4;
  102968. }while(iX>=in);
  102969. iX = in+n2-8;
  102970. oX = out+n2+n4;
  102971. T = init->trig+n4;
  102972. do{
  102973. T -= 4;
  102974. oX[0] = MULT_NORM (iX[4] * T[3] + iX[6] * T[2]);
  102975. oX[1] = MULT_NORM (iX[4] * T[2] - iX[6] * T[3]);
  102976. oX[2] = MULT_NORM (iX[0] * T[1] + iX[2] * T[0]);
  102977. oX[3] = MULT_NORM (iX[0] * T[0] - iX[2] * T[1]);
  102978. iX -= 8;
  102979. oX += 4;
  102980. }while(iX>=in);
  102981. mdct_butterflies(init,out+n2,n2);
  102982. mdct_bitreverse(init,out);
  102983. {
  102984. DATA_TYPE *oX1=out+n2+n4;
  102985. DATA_TYPE *oX2=out+n2+n4;
  102986. DATA_TYPE *iX =out;
  102987. T =init->trig+n2;
  102988. do{
  102989. oX1-=4;
  102990. oX1[3] = MULT_NORM (iX[0] * T[1] - iX[1] * T[0]);
  102991. oX2[0] = -MULT_NORM (iX[0] * T[0] + iX[1] * T[1]);
  102992. oX1[2] = MULT_NORM (iX[2] * T[3] - iX[3] * T[2]);
  102993. oX2[1] = -MULT_NORM (iX[2] * T[2] + iX[3] * T[3]);
  102994. oX1[1] = MULT_NORM (iX[4] * T[5] - iX[5] * T[4]);
  102995. oX2[2] = -MULT_NORM (iX[4] * T[4] + iX[5] * T[5]);
  102996. oX1[0] = MULT_NORM (iX[6] * T[7] - iX[7] * T[6]);
  102997. oX2[3] = -MULT_NORM (iX[6] * T[6] + iX[7] * T[7]);
  102998. oX2+=4;
  102999. iX += 8;
  103000. T += 8;
  103001. }while(iX<oX1);
  103002. iX=out+n2+n4;
  103003. oX1=out+n4;
  103004. oX2=oX1;
  103005. do{
  103006. oX1-=4;
  103007. iX-=4;
  103008. oX2[0] = -(oX1[3] = iX[3]);
  103009. oX2[1] = -(oX1[2] = iX[2]);
  103010. oX2[2] = -(oX1[1] = iX[1]);
  103011. oX2[3] = -(oX1[0] = iX[0]);
  103012. oX2+=4;
  103013. }while(oX2<iX);
  103014. iX=out+n2+n4;
  103015. oX1=out+n2+n4;
  103016. oX2=out+n2;
  103017. do{
  103018. oX1-=4;
  103019. oX1[0]= iX[3];
  103020. oX1[1]= iX[2];
  103021. oX1[2]= iX[1];
  103022. oX1[3]= iX[0];
  103023. iX+=4;
  103024. }while(oX1>oX2);
  103025. }
  103026. }
  103027. void mdct_forward(mdct_lookup *init, DATA_TYPE *in, DATA_TYPE *out){
  103028. int n=init->n;
  103029. int n2=n>>1;
  103030. int n4=n>>2;
  103031. int n8=n>>3;
  103032. DATA_TYPE *w=(DATA_TYPE*) alloca(n*sizeof(*w)); /* forward needs working space */
  103033. DATA_TYPE *w2=w+n2;
  103034. REG_TYPE r0;
  103035. REG_TYPE r1;
  103036. DATA_TYPE *x0=in+n2+n4;
  103037. DATA_TYPE *x1=x0+1;
  103038. DATA_TYPE *T=init->trig+n2;
  103039. int i=0;
  103040. for(i=0;i<n8;i+=2){
  103041. x0 -=4;
  103042. T-=2;
  103043. r0= x0[2] + x1[0];
  103044. r1= x0[0] + x1[2];
  103045. w2[i]= MULT_NORM(r1*T[1] + r0*T[0]);
  103046. w2[i+1]= MULT_NORM(r1*T[0] - r0*T[1]);
  103047. x1 +=4;
  103048. }
  103049. x1=in+1;
  103050. for(;i<n2-n8;i+=2){
  103051. T-=2;
  103052. x0 -=4;
  103053. r0= x0[2] - x1[0];
  103054. r1= x0[0] - x1[2];
  103055. w2[i]= MULT_NORM(r1*T[1] + r0*T[0]);
  103056. w2[i+1]= MULT_NORM(r1*T[0] - r0*T[1]);
  103057. x1 +=4;
  103058. }
  103059. x0=in+n;
  103060. for(;i<n2;i+=2){
  103061. T-=2;
  103062. x0 -=4;
  103063. r0= -x0[2] - x1[0];
  103064. r1= -x0[0] - x1[2];
  103065. w2[i]= MULT_NORM(r1*T[1] + r0*T[0]);
  103066. w2[i+1]= MULT_NORM(r1*T[0] - r0*T[1]);
  103067. x1 +=4;
  103068. }
  103069. mdct_butterflies(init,w+n2,n2);
  103070. mdct_bitreverse(init,w);
  103071. T=init->trig+n2;
  103072. x0=out+n2;
  103073. for(i=0;i<n4;i++){
  103074. x0--;
  103075. out[i] =MULT_NORM((w[0]*T[0]+w[1]*T[1])*init->scale);
  103076. x0[0] =MULT_NORM((w[0]*T[1]-w[1]*T[0])*init->scale);
  103077. w+=2;
  103078. T+=2;
  103079. }
  103080. }
  103081. #endif
  103082. /********* End of inlined file: mdct.c *********/
  103083. /********* Start of inlined file: psy.c *********/
  103084. /********* Start of inlined file: juce_OggVorbisHeader.h *********/
  103085. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  103086. // tasks..
  103087. #if JUCE_MSVC
  103088. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  103089. #endif
  103090. /********* End of inlined file: juce_OggVorbisHeader.h *********/
  103091. #if JUCE_USE_OGGVORBIS
  103092. #include <stdlib.h>
  103093. #include <math.h>
  103094. #include <string.h>
  103095. /********* Start of inlined file: masking.h *********/
  103096. #ifndef _V_MASKING_H_
  103097. #define _V_MASKING_H_
  103098. #define MAX_ATH 88
  103099. static float ATH[]={
  103100. -51, -52, -53, -54, -55, -56, -57, -58,
  103101. -59, -60, -61, -62, -63, -64, -65, -66,
  103102. -67, -68, -69, -70, -71, -72, -73, -74,
  103103. -75, -76, -77, -78, -80, -81, -82, -83,
  103104. -84, -85, -86, -87, -88, -88, -89, -89,
  103105. -90, -91, -91, -92, -93, -94, -95, -96,
  103106. -96, -97, -98, -98, -99, -99,-100,-100,
  103107. -101,-102,-103,-104,-106,-107,-107,-107,
  103108. -107,-105,-103,-102,-101, -99, -98, -96,
  103109. -95, -95, -96, -97, -96, -95, -93, -90,
  103110. -80, -70, -50, -40, -30, -30, -30, -30
  103111. };
  103112. #define EHMER_OFFSET 16
  103113. #define EHMER_MAX 56
  103114. static float tonemasks[P_BANDS][6][EHMER_MAX]={
  103115. {{ -60, -60, -60, -60, -60, -60, -60, -60,
  103116. -60, -60, -60, -60, -62, -62, -65, -73,
  103117. -69, -68, -68, -67, -70, -70, -72, -74,
  103118. -75, -79, -79, -80, -83, -88, -93, -100,
  103119. -110, -999, -999, -999, -999, -999, -999, -999,
  103120. -999, -999, -999, -999, -999, -999, -999, -999,
  103121. -999, -999, -999, -999, -999, -999, -999, -999},
  103122. { -48, -48, -48, -48, -48, -48, -48, -48,
  103123. -48, -48, -48, -48, -48, -53, -61, -66,
  103124. -66, -68, -67, -70, -76, -76, -72, -73,
  103125. -75, -76, -78, -79, -83, -88, -93, -100,
  103126. -110, -999, -999, -999, -999, -999, -999, -999,
  103127. -999, -999, -999, -999, -999, -999, -999, -999,
  103128. -999, -999, -999, -999, -999, -999, -999, -999},
  103129. { -37, -37, -37, -37, -37, -37, -37, -37,
  103130. -38, -40, -42, -46, -48, -53, -55, -62,
  103131. -65, -58, -56, -56, -61, -60, -65, -67,
  103132. -69, -71, -77, -77, -78, -80, -82, -84,
  103133. -88, -93, -98, -106, -112, -999, -999, -999,
  103134. -999, -999, -999, -999, -999, -999, -999, -999,
  103135. -999, -999, -999, -999, -999, -999, -999, -999},
  103136. { -25, -25, -25, -25, -25, -25, -25, -25,
  103137. -25, -26, -27, -29, -32, -38, -48, -52,
  103138. -52, -50, -48, -48, -51, -52, -54, -60,
  103139. -67, -67, -66, -68, -69, -73, -73, -76,
  103140. -80, -81, -81, -85, -85, -86, -88, -93,
  103141. -100, -110, -999, -999, -999, -999, -999, -999,
  103142. -999, -999, -999, -999, -999, -999, -999, -999},
  103143. { -16, -16, -16, -16, -16, -16, -16, -16,
  103144. -17, -19, -20, -22, -26, -28, -31, -40,
  103145. -47, -39, -39, -40, -42, -43, -47, -51,
  103146. -57, -52, -55, -55, -60, -58, -62, -63,
  103147. -70, -67, -69, -72, -73, -77, -80, -82,
  103148. -83, -87, -90, -94, -98, -104, -115, -999,
  103149. -999, -999, -999, -999, -999, -999, -999, -999},
  103150. { -8, -8, -8, -8, -8, -8, -8, -8,
  103151. -8, -8, -10, -11, -15, -19, -25, -30,
  103152. -34, -31, -30, -31, -29, -32, -35, -42,
  103153. -48, -42, -44, -46, -50, -50, -51, -52,
  103154. -59, -54, -55, -55, -58, -62, -63, -66,
  103155. -72, -73, -76, -75, -78, -80, -80, -81,
  103156. -84, -88, -90, -94, -98, -101, -106, -110}},
  103157. {{ -66, -66, -66, -66, -66, -66, -66, -66,
  103158. -66, -66, -66, -66, -66, -67, -67, -67,
  103159. -76, -72, -71, -74, -76, -76, -75, -78,
  103160. -79, -79, -81, -83, -86, -89, -93, -97,
  103161. -100, -105, -110, -999, -999, -999, -999, -999,
  103162. -999, -999, -999, -999, -999, -999, -999, -999,
  103163. -999, -999, -999, -999, -999, -999, -999, -999},
  103164. { -47, -47, -47, -47, -47, -47, -47, -47,
  103165. -47, -47, -47, -48, -51, -55, -59, -66,
  103166. -66, -66, -67, -66, -68, -69, -70, -74,
  103167. -79, -77, -77, -78, -80, -81, -82, -84,
  103168. -86, -88, -91, -95, -100, -108, -116, -999,
  103169. -999, -999, -999, -999, -999, -999, -999, -999,
  103170. -999, -999, -999, -999, -999, -999, -999, -999},
  103171. { -36, -36, -36, -36, -36, -36, -36, -36,
  103172. -36, -37, -37, -41, -44, -48, -51, -58,
  103173. -62, -60, -57, -59, -59, -60, -63, -65,
  103174. -72, -71, -70, -72, -74, -77, -76, -78,
  103175. -81, -81, -80, -83, -86, -91, -96, -100,
  103176. -105, -110, -999, -999, -999, -999, -999, -999,
  103177. -999, -999, -999, -999, -999, -999, -999, -999},
  103178. { -28, -28, -28, -28, -28, -28, -28, -28,
  103179. -28, -30, -32, -32, -33, -35, -41, -49,
  103180. -50, -49, -47, -48, -48, -52, -51, -57,
  103181. -65, -61, -59, -61, -64, -69, -70, -74,
  103182. -77, -77, -78, -81, -84, -85, -87, -90,
  103183. -92, -96, -100, -107, -112, -999, -999, -999,
  103184. -999, -999, -999, -999, -999, -999, -999, -999},
  103185. { -19, -19, -19, -19, -19, -19, -19, -19,
  103186. -20, -21, -23, -27, -30, -35, -36, -41,
  103187. -46, -44, -42, -40, -41, -41, -43, -48,
  103188. -55, -53, -52, -53, -56, -59, -58, -60,
  103189. -67, -66, -69, -71, -72, -75, -79, -81,
  103190. -84, -87, -90, -93, -97, -101, -107, -114,
  103191. -999, -999, -999, -999, -999, -999, -999, -999},
  103192. { -9, -9, -9, -9, -9, -9, -9, -9,
  103193. -11, -12, -12, -15, -16, -20, -23, -30,
  103194. -37, -34, -33, -34, -31, -32, -32, -38,
  103195. -47, -44, -41, -40, -47, -49, -46, -46,
  103196. -58, -50, -50, -54, -58, -62, -64, -67,
  103197. -67, -70, -72, -76, -79, -83, -87, -91,
  103198. -96, -100, -104, -110, -999, -999, -999, -999}},
  103199. {{ -62, -62, -62, -62, -62, -62, -62, -62,
  103200. -62, -62, -63, -64, -66, -67, -66, -68,
  103201. -75, -72, -76, -75, -76, -78, -79, -82,
  103202. -84, -85, -90, -94, -101, -110, -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. { -59, -59, -59, -59, -59, -59, -59, -59,
  103207. -59, -59, -59, -60, -60, -61, -63, -66,
  103208. -71, -68, -70, -70, -71, -72, -72, -75,
  103209. -81, -78, -79, -82, -83, -86, -90, -97,
  103210. -103, -113, -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. { -53, -53, -53, -53, -53, -53, -53, -53,
  103214. -53, -54, -55, -57, -56, -57, -55, -61,
  103215. -65, -60, -60, -62, -63, -63, -66, -68,
  103216. -74, -73, -75, -75, -78, -80, -80, -82,
  103217. -85, -90, -96, -101, -108, -999, -999, -999,
  103218. -999, -999, -999, -999, -999, -999, -999, -999,
  103219. -999, -999, -999, -999, -999, -999, -999, -999},
  103220. { -46, -46, -46, -46, -46, -46, -46, -46,
  103221. -46, -46, -47, -47, -47, -47, -48, -51,
  103222. -57, -51, -49, -50, -51, -53, -54, -59,
  103223. -66, -60, -62, -67, -67, -70, -72, -75,
  103224. -76, -78, -81, -85, -88, -94, -97, -104,
  103225. -112, -999, -999, -999, -999, -999, -999, -999,
  103226. -999, -999, -999, -999, -999, -999, -999, -999},
  103227. { -36, -36, -36, -36, -36, -36, -36, -36,
  103228. -39, -41, -42, -42, -39, -38, -41, -43,
  103229. -52, -44, -40, -39, -37, -37, -40, -47,
  103230. -54, -50, -48, -50, -55, -61, -59, -62,
  103231. -66, -66, -66, -69, -69, -73, -74, -74,
  103232. -75, -77, -79, -82, -87, -91, -95, -100,
  103233. -108, -115, -999, -999, -999, -999, -999, -999},
  103234. { -28, -26, -24, -22, -20, -20, -23, -29,
  103235. -30, -31, -28, -27, -28, -28, -28, -35,
  103236. -40, -33, -32, -29, -30, -30, -30, -37,
  103237. -45, -41, -37, -38, -45, -47, -47, -48,
  103238. -53, -49, -48, -50, -49, -49, -51, -52,
  103239. -58, -56, -57, -56, -60, -61, -62, -70,
  103240. -72, -74, -78, -83, -88, -93, -100, -106}},
  103241. {{-999, -999, -999, -999, -999, -999, -999, -999,
  103242. -999, -110, -105, -100, -95, -91, -87, -83,
  103243. -80, -78, -76, -78, -78, -81, -83, -85,
  103244. -86, -85, -86, -87, -90, -97, -107, -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, -110, -105, -100, -95, -90,
  103249. -85, -81, -77, -73, -70, -67, -67, -68,
  103250. -75, -73, -70, -69, -70, -72, -75, -79,
  103251. -84, -83, -84, -86, -88, -89, -89, -93,
  103252. -98, -105, -112, -999, -999, -999, -999, -999,
  103253. -999, -999, -999, -999, -999, -999, -999, -999,
  103254. -999, -999, -999, -999, -999, -999, -999, -999},
  103255. {-105, -100, -95, -90, -85, -80, -76, -71,
  103256. -68, -68, -65, -63, -63, -62, -62, -64,
  103257. -65, -64, -61, -62, -63, -64, -66, -68,
  103258. -73, -73, -74, -75, -76, -81, -83, -85,
  103259. -88, -89, -92, -95, -100, -108, -999, -999,
  103260. -999, -999, -999, -999, -999, -999, -999, -999,
  103261. -999, -999, -999, -999, -999, -999, -999, -999},
  103262. { -80, -75, -71, -68, -65, -63, -62, -61,
  103263. -61, -61, -61, -59, -56, -57, -53, -50,
  103264. -58, -52, -50, -50, -52, -53, -54, -58,
  103265. -67, -63, -67, -68, -72, -75, -78, -80,
  103266. -81, -81, -82, -85, -89, -90, -93, -97,
  103267. -101, -107, -114, -999, -999, -999, -999, -999,
  103268. -999, -999, -999, -999, -999, -999, -999, -999},
  103269. { -65, -61, -59, -57, -56, -55, -55, -56,
  103270. -56, -57, -55, -53, -52, -47, -44, -44,
  103271. -50, -44, -41, -39, -39, -42, -40, -46,
  103272. -51, -49, -50, -53, -54, -63, -60, -61,
  103273. -62, -66, -66, -66, -70, -73, -74, -75,
  103274. -76, -75, -79, -85, -89, -91, -96, -102,
  103275. -110, -999, -999, -999, -999, -999, -999, -999},
  103276. { -52, -50, -49, -49, -48, -48, -48, -49,
  103277. -50, -50, -49, -46, -43, -39, -35, -33,
  103278. -38, -36, -32, -29, -32, -32, -32, -35,
  103279. -44, -39, -38, -38, -46, -50, -45, -46,
  103280. -53, -50, -50, -50, -54, -54, -53, -53,
  103281. -56, -57, -59, -66, -70, -72, -74, -79,
  103282. -83, -85, -90, -97, -114, -999, -999, -999}},
  103283. {{-999, -999, -999, -999, -999, -999, -110, -105,
  103284. -100, -95, -90, -86, -80, -75, -75, -79,
  103285. -80, -79, -80, -81, -82, -88, -95, -103,
  103286. -110, -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, -108, -103, -98, -93,
  103291. -88, -83, -79, -78, -75, -71, -67, -68,
  103292. -73, -73, -72, -73, -75, -77, -80, -82,
  103293. -88, -93, -100, -107, -114, -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, -110, -105, -101, -96, -90,
  103298. -86, -81, -77, -73, -69, -66, -61, -62,
  103299. -66, -64, -62, -65, -66, -70, -72, -76,
  103300. -81, -80, -84, -90, -95, -102, -110, -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, -107, -103, -97, -92, -88,
  103305. -83, -79, -74, -70, -66, -59, -53, -58,
  103306. -62, -55, -54, -54, -54, -58, -61, -62,
  103307. -72, -70, -72, -75, -78, -80, -81, -80,
  103308. -83, -83, -88, -93, -100, -107, -115, -999,
  103309. -999, -999, -999, -999, -999, -999, -999, -999,
  103310. -999, -999, -999, -999, -999, -999, -999, -999},
  103311. {-999, -999, -999, -105, -100, -95, -90, -85,
  103312. -80, -75, -70, -66, -62, -56, -48, -44,
  103313. -48, -46, -46, -43, -46, -48, -48, -51,
  103314. -58, -58, -59, -60, -62, -62, -61, -61,
  103315. -65, -64, -65, -68, -70, -74, -75, -78,
  103316. -81, -86, -95, -110, -999, -999, -999, -999,
  103317. -999, -999, -999, -999, -999, -999, -999, -999},
  103318. {-999, -999, -105, -100, -95, -90, -85, -80,
  103319. -75, -70, -65, -61, -55, -49, -39, -33,
  103320. -40, -35, -32, -38, -40, -33, -35, -37,
  103321. -46, -41, -45, -44, -46, -42, -45, -46,
  103322. -52, -50, -50, -50, -54, -54, -55, -57,
  103323. -62, -64, -66, -68, -70, -76, -81, -90,
  103324. -100, -110, -999, -999, -999, -999, -999, -999}},
  103325. {{-999, -999, -999, -999, -999, -999, -999, -999,
  103326. -105, -98, -90, -85, -82, -83, -80, -78,
  103327. -84, -79, -80, -83, -87, -89, -91, -93,
  103328. -99, -106, -117, -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, -999, -999, -999, -999, -999, -999,
  103333. -105, -98, -90, -85, -80, -75, -70, -68,
  103334. -74, -72, -74, -77, -80, -82, -85, -87,
  103335. -92, -89, -91, -95, -100, -106, -112, -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, -999, -999, -999, -999, -999, -999,
  103340. -105, -98, -90, -83, -75, -71, -63, -64,
  103341. -67, -62, -64, -67, -70, -73, -77, -81,
  103342. -84, -83, -85, -89, -90, -93, -98, -104,
  103343. -109, -114, -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, -999, -999, -999, -999, -999, -999,
  103347. -103, -96, -88, -81, -75, -68, -58, -54,
  103348. -56, -54, -56, -56, -58, -60, -63, -66,
  103349. -74, -69, -72, -72, -75, -74, -77, -81,
  103350. -81, -82, -84, -87, -93, -96, -99, -104,
  103351. -110, -999, -999, -999, -999, -999, -999, -999,
  103352. -999, -999, -999, -999, -999, -999, -999, -999},
  103353. {-999, -999, -999, -999, -999, -108, -102, -96,
  103354. -91, -85, -80, -74, -68, -60, -51, -46,
  103355. -48, -46, -43, -45, -47, -47, -49, -48,
  103356. -56, -53, -55, -58, -57, -63, -58, -60,
  103357. -66, -64, -67, -70, -70, -74, -77, -84,
  103358. -86, -89, -91, -93, -94, -101, -109, -118,
  103359. -999, -999, -999, -999, -999, -999, -999, -999},
  103360. {-999, -999, -999, -108, -103, -98, -93, -88,
  103361. -83, -78, -73, -68, -60, -53, -44, -35,
  103362. -38, -38, -34, -34, -36, -40, -41, -44,
  103363. -51, -45, -46, -47, -46, -54, -50, -49,
  103364. -50, -50, -50, -51, -54, -57, -58, -60,
  103365. -66, -66, -66, -64, -65, -68, -77, -82,
  103366. -87, -95, -110, -999, -999, -999, -999, -999}},
  103367. {{-999, -999, -999, -999, -999, -999, -999, -999,
  103368. -107, -102, -97, -92, -87, -83, -78, -75,
  103369. -82, -79, -83, -85, -89, -92, -95, -98,
  103370. -101, -105, -109, -113, -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, -999, -999, -999, -999, -106,
  103375. -100, -95, -90, -86, -81, -78, -74, -69,
  103376. -74, -74, -76, -79, -83, -84, -86, -89,
  103377. -92, -97, -93, -100, -103, -107, -110, -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, -999, -999, -999, -106, -100,
  103382. -95, -90, -87, -83, -80, -75, -69, -60,
  103383. -66, -66, -68, -70, -74, -78, -79, -81,
  103384. -81, -83, -84, -87, -93, -96, -99, -103,
  103385. -107, -110, -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, -999, -999, -108, -103, -98,
  103389. -93, -89, -85, -82, -78, -71, -62, -55,
  103390. -58, -58, -54, -54, -55, -59, -61, -62,
  103391. -70, -66, -66, -67, -70, -72, -75, -78,
  103392. -84, -84, -84, -88, -91, -90, -95, -98,
  103393. -102, -103, -106, -110, -999, -999, -999, -999,
  103394. -999, -999, -999, -999, -999, -999, -999, -999},
  103395. {-999, -999, -999, -999, -108, -103, -98, -94,
  103396. -90, -87, -82, -79, -73, -67, -58, -47,
  103397. -50, -45, -41, -45, -48, -44, -44, -49,
  103398. -54, -51, -48, -47, -49, -50, -51, -57,
  103399. -58, -60, -63, -69, -70, -69, -71, -74,
  103400. -78, -82, -90, -95, -101, -105, -110, -999,
  103401. -999, -999, -999, -999, -999, -999, -999, -999},
  103402. {-999, -999, -999, -105, -101, -97, -93, -90,
  103403. -85, -80, -77, -72, -65, -56, -48, -37,
  103404. -40, -36, -34, -40, -50, -47, -38, -41,
  103405. -47, -38, -35, -39, -38, -43, -40, -45,
  103406. -50, -45, -44, -47, -50, -55, -48, -48,
  103407. -52, -66, -70, -76, -82, -90, -97, -105,
  103408. -110, -999, -999, -999, -999, -999, -999, -999}},
  103409. {{-999, -999, -999, -999, -999, -999, -999, -999,
  103410. -999, -108, -103, -98, -93, -86, -79, -76,
  103411. -83, -81, -85, -87, -89, -93, -98, -102,
  103412. -107, -112, -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, -999, -999, -999,
  103417. -999, -108, -103, -98, -93, -86, -79, -71,
  103418. -77, -74, -77, -79, -81, -84, -85, -90,
  103419. -92, -93, -92, -98, -101, -108, -112, -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, -999, -999, -999,
  103424. -108, -103, -98, -93, -87, -78, -68, -65,
  103425. -66, -62, -65, -67, -70, -73, -75, -78,
  103426. -82, -82, -83, -84, -91, -93, -98, -102,
  103427. -106, -110, -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, -999, -999, -999, -999,
  103431. -105, -100, -95, -90, -82, -74, -62, -57,
  103432. -58, -56, -51, -52, -52, -54, -54, -58,
  103433. -66, -59, -60, -63, -66, -69, -73, -79,
  103434. -83, -84, -80, -81, -81, -82, -88, -92,
  103435. -98, -105, -113, -999, -999, -999, -999, -999,
  103436. -999, -999, -999, -999, -999, -999, -999, -999},
  103437. {-999, -999, -999, -999, -999, -999, -999, -107,
  103438. -102, -97, -92, -84, -79, -69, -57, -47,
  103439. -52, -47, -44, -45, -50, -52, -42, -42,
  103440. -53, -43, -43, -48, -51, -56, -55, -52,
  103441. -57, -59, -61, -62, -67, -71, -78, -83,
  103442. -86, -94, -98, -103, -110, -999, -999, -999,
  103443. -999, -999, -999, -999, -999, -999, -999, -999},
  103444. {-999, -999, -999, -999, -999, -999, -105, -100,
  103445. -95, -90, -84, -78, -70, -61, -51, -41,
  103446. -40, -38, -40, -46, -52, -51, -41, -40,
  103447. -46, -40, -38, -38, -41, -46, -41, -46,
  103448. -47, -43, -43, -45, -41, -45, -56, -67,
  103449. -68, -83, -87, -90, -95, -102, -107, -113,
  103450. -999, -999, -999, -999, -999, -999, -999, -999}},
  103451. {{-999, -999, -999, -999, -999, -999, -999, -999,
  103452. -999, -109, -105, -101, -96, -91, -84, -77,
  103453. -82, -82, -85, -89, -94, -100, -106, -110,
  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, -999, -999, -999, -999, -999,
  103459. -999, -106, -103, -98, -92, -85, -80, -71,
  103460. -75, -72, -76, -80, -84, -86, -89, -93,
  103461. -100, -107, -113, -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, -999, -999, -999, -999, -107,
  103466. -104, -101, -97, -92, -88, -84, -80, -64,
  103467. -66, -63, -64, -66, -69, -73, -77, -83,
  103468. -83, -86, -91, -98, -104, -111, -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, -999, -999, -999, -999, -107,
  103473. -104, -101, -97, -92, -90, -84, -74, -57,
  103474. -58, -52, -55, -54, -50, -52, -50, -52,
  103475. -63, -62, -69, -76, -77, -78, -78, -79,
  103476. -82, -88, -94, -100, -106, -111, -999, -999,
  103477. -999, -999, -999, -999, -999, -999, -999, -999,
  103478. -999, -999, -999, -999, -999, -999, -999, -999},
  103479. {-999, -999, -999, -999, -999, -999, -106, -102,
  103480. -98, -95, -90, -85, -83, -78, -70, -50,
  103481. -50, -41, -44, -49, -47, -50, -50, -44,
  103482. -55, -46, -47, -48, -48, -54, -49, -49,
  103483. -58, -62, -71, -81, -87, -92, -97, -102,
  103484. -108, -114, -999, -999, -999, -999, -999, -999,
  103485. -999, -999, -999, -999, -999, -999, -999, -999},
  103486. {-999, -999, -999, -999, -999, -999, -106, -102,
  103487. -98, -95, -90, -85, -83, -78, -70, -45,
  103488. -43, -41, -47, -50, -51, -50, -49, -45,
  103489. -47, -41, -44, -41, -39, -43, -38, -37,
  103490. -40, -41, -44, -50, -58, -65, -73, -79,
  103491. -85, -92, -97, -101, -105, -109, -113, -999,
  103492. -999, -999, -999, -999, -999, -999, -999, -999}},
  103493. {{-999, -999, -999, -999, -999, -999, -999, -999,
  103494. -999, -999, -999, -107, -100, -95, -87, -81,
  103495. -85, -83, -88, -93, -100, -107, -114, -999,
  103496. -999, -999, -999, -999, -999, -999, -999, -999,
  103497. -999, -999, -999, -999, -999, -999, -999, -999,
  103498. -999, -999, -999, -999, -999, -999, -999, -999,
  103499. -999, -999, -999, -999, -999, -999, -999, -999},
  103500. {-999, -999, -999, -999, -999, -999, -999, -999,
  103501. -999, -999, -107, -101, -95, -88, -83, -76,
  103502. -73, -72, -79, -84, -90, -95, -100, -105,
  103503. -110, -115, -999, -999, -999, -999, -999, -999,
  103504. -999, -999, -999, -999, -999, -999, -999, -999,
  103505. -999, -999, -999, -999, -999, -999, -999, -999,
  103506. -999, -999, -999, -999, -999, -999, -999, -999},
  103507. {-999, -999, -999, -999, -999, -999, -999, -999,
  103508. -999, -999, -104, -98, -92, -87, -81, -70,
  103509. -65, -62, -67, -71, -74, -80, -85, -91,
  103510. -95, -99, -103, -108, -111, -114, -999, -999,
  103511. -999, -999, -999, -999, -999, -999, -999, -999,
  103512. -999, -999, -999, -999, -999, -999, -999, -999,
  103513. -999, -999, -999, -999, -999, -999, -999, -999},
  103514. {-999, -999, -999, -999, -999, -999, -999, -999,
  103515. -999, -999, -103, -97, -90, -85, -76, -60,
  103516. -56, -54, -60, -62, -61, -56, -63, -65,
  103517. -73, -74, -77, -75, -78, -81, -86, -87,
  103518. -88, -91, -94, -98, -103, -110, -999, -999,
  103519. -999, -999, -999, -999, -999, -999, -999, -999,
  103520. -999, -999, -999, -999, -999, -999, -999, -999},
  103521. {-999, -999, -999, -999, -999, -999, -999, -105,
  103522. -100, -97, -92, -86, -81, -79, -70, -57,
  103523. -51, -47, -51, -58, -60, -56, -53, -50,
  103524. -58, -52, -50, -50, -53, -55, -64, -69,
  103525. -71, -85, -82, -78, -81, -85, -95, -102,
  103526. -112, -999, -999, -999, -999, -999, -999, -999,
  103527. -999, -999, -999, -999, -999, -999, -999, -999},
  103528. {-999, -999, -999, -999, -999, -999, -999, -105,
  103529. -100, -97, -92, -85, -83, -79, -72, -49,
  103530. -40, -43, -43, -54, -56, -51, -50, -40,
  103531. -43, -38, -36, -35, -37, -38, -37, -44,
  103532. -54, -60, -57, -60, -70, -75, -84, -92,
  103533. -103, -112, -999, -999, -999, -999, -999, -999,
  103534. -999, -999, -999, -999, -999, -999, -999, -999}},
  103535. {{-999, -999, -999, -999, -999, -999, -999, -999,
  103536. -999, -999, -999, -110, -102, -95, -89, -82,
  103537. -83, -84, -90, -92, -99, -107, -113, -999,
  103538. -999, -999, -999, -999, -999, -999, -999, -999,
  103539. -999, -999, -999, -999, -999, -999, -999, -999,
  103540. -999, -999, -999, -999, -999, -999, -999, -999,
  103541. -999, -999, -999, -999, -999, -999, -999, -999},
  103542. {-999, -999, -999, -999, -999, -999, -999, -999,
  103543. -999, -999, -107, -101, -95, -89, -83, -72,
  103544. -74, -78, -85, -88, -88, -90, -92, -98,
  103545. -105, -111, -999, -999, -999, -999, -999, -999,
  103546. -999, -999, -999, -999, -999, -999, -999, -999,
  103547. -999, -999, -999, -999, -999, -999, -999, -999,
  103548. -999, -999, -999, -999, -999, -999, -999, -999},
  103549. {-999, -999, -999, -999, -999, -999, -999, -999,
  103550. -999, -109, -103, -97, -93, -87, -81, -70,
  103551. -70, -67, -75, -73, -76, -79, -81, -83,
  103552. -88, -89, -97, -103, -110, -999, -999, -999,
  103553. -999, -999, -999, -999, -999, -999, -999, -999,
  103554. -999, -999, -999, -999, -999, -999, -999, -999,
  103555. -999, -999, -999, -999, -999, -999, -999, -999},
  103556. {-999, -999, -999, -999, -999, -999, -999, -999,
  103557. -999, -107, -100, -94, -88, -83, -75, -63,
  103558. -59, -59, -63, -66, -60, -62, -67, -67,
  103559. -77, -76, -81, -88, -86, -92, -96, -102,
  103560. -109, -116, -999, -999, -999, -999, -999, -999,
  103561. -999, -999, -999, -999, -999, -999, -999, -999,
  103562. -999, -999, -999, -999, -999, -999, -999, -999},
  103563. {-999, -999, -999, -999, -999, -999, -999, -999,
  103564. -999, -105, -98, -92, -86, -81, -73, -56,
  103565. -52, -47, -55, -60, -58, -52, -51, -45,
  103566. -49, -50, -53, -54, -61, -71, -70, -69,
  103567. -78, -79, -87, -90, -96, -104, -112, -999,
  103568. -999, -999, -999, -999, -999, -999, -999, -999,
  103569. -999, -999, -999, -999, -999, -999, -999, -999},
  103570. {-999, -999, -999, -999, -999, -999, -999, -999,
  103571. -999, -103, -96, -90, -86, -78, -70, -51,
  103572. -42, -47, -48, -55, -54, -54, -53, -42,
  103573. -35, -28, -33, -38, -37, -44, -47, -49,
  103574. -54, -63, -68, -78, -82, -89, -94, -99,
  103575. -104, -109, -114, -999, -999, -999, -999, -999,
  103576. -999, -999, -999, -999, -999, -999, -999, -999}},
  103577. {{-999, -999, -999, -999, -999, -999, -999, -999,
  103578. -999, -999, -999, -999, -110, -100, -90, -79,
  103579. -85, -81, -82, -82, -89, -94, -99, -103,
  103580. -109, -115, -999, -999, -999, -999, -999, -999,
  103581. -999, -999, -999, -999, -999, -999, -999, -999,
  103582. -999, -999, -999, -999, -999, -999, -999, -999,
  103583. -999, -999, -999, -999, -999, -999, -999, -999},
  103584. {-999, -999, -999, -999, -999, -999, -999, -999,
  103585. -999, -999, -999, -999, -105, -97, -85, -72,
  103586. -74, -70, -70, -70, -76, -85, -91, -93,
  103587. -97, -103, -109, -115, -999, -999, -999, -999,
  103588. -999, -999, -999, -999, -999, -999, -999, -999,
  103589. -999, -999, -999, -999, -999, -999, -999, -999,
  103590. -999, -999, -999, -999, -999, -999, -999, -999},
  103591. {-999, -999, -999, -999, -999, -999, -999, -999,
  103592. -999, -999, -999, -999, -112, -93, -81, -68,
  103593. -62, -60, -60, -57, -63, -70, -77, -82,
  103594. -90, -93, -98, -104, -109, -113, -999, -999,
  103595. -999, -999, -999, -999, -999, -999, -999, -999,
  103596. -999, -999, -999, -999, -999, -999, -999, -999,
  103597. -999, -999, -999, -999, -999, -999, -999, -999},
  103598. {-999, -999, -999, -999, -999, -999, -999, -999,
  103599. -999, -999, -999, -113, -100, -93, -84, -63,
  103600. -58, -48, -53, -54, -52, -52, -57, -64,
  103601. -66, -76, -83, -81, -85, -85, -90, -95,
  103602. -98, -101, -103, -106, -108, -111, -999, -999,
  103603. -999, -999, -999, -999, -999, -999, -999, -999,
  103604. -999, -999, -999, -999, -999, -999, -999, -999},
  103605. {-999, -999, -999, -999, -999, -999, -999, -999,
  103606. -999, -999, -999, -105, -95, -86, -74, -53,
  103607. -50, -38, -43, -49, -43, -42, -39, -39,
  103608. -46, -52, -57, -56, -72, -69, -74, -81,
  103609. -87, -92, -94, -97, -99, -102, -105, -108,
  103610. -999, -999, -999, -999, -999, -999, -999, -999,
  103611. -999, -999, -999, -999, -999, -999, -999, -999},
  103612. {-999, -999, -999, -999, -999, -999, -999, -999,
  103613. -999, -999, -108, -99, -90, -76, -66, -45,
  103614. -43, -41, -44, -47, -43, -47, -40, -30,
  103615. -31, -31, -39, -33, -40, -41, -43, -53,
  103616. -59, -70, -73, -77, -79, -82, -84, -87,
  103617. -999, -999, -999, -999, -999, -999, -999, -999,
  103618. -999, -999, -999, -999, -999, -999, -999, -999}},
  103619. {{-999, -999, -999, -999, -999, -999, -999, -999,
  103620. -999, -999, -999, -999, -999, -110, -91, -76,
  103621. -75, -85, -93, -98, -104, -110, -999, -999,
  103622. -999, -999, -999, -999, -999, -999, -999, -999,
  103623. -999, -999, -999, -999, -999, -999, -999, -999,
  103624. -999, -999, -999, -999, -999, -999, -999, -999,
  103625. -999, -999, -999, -999, -999, -999, -999, -999},
  103626. {-999, -999, -999, -999, -999, -999, -999, -999,
  103627. -999, -999, -999, -999, -999, -110, -91, -70,
  103628. -70, -75, -86, -89, -94, -98, -101, -106,
  103629. -110, -999, -999, -999, -999, -999, -999, -999,
  103630. -999, -999, -999, -999, -999, -999, -999, -999,
  103631. -999, -999, -999, -999, -999, -999, -999, -999,
  103632. -999, -999, -999, -999, -999, -999, -999, -999},
  103633. {-999, -999, -999, -999, -999, -999, -999, -999,
  103634. -999, -999, -999, -999, -110, -95, -80, -60,
  103635. -65, -64, -74, -83, -88, -91, -95, -99,
  103636. -103, -107, -110, -999, -999, -999, -999, -999,
  103637. -999, -999, -999, -999, -999, -999, -999, -999,
  103638. -999, -999, -999, -999, -999, -999, -999, -999,
  103639. -999, -999, -999, -999, -999, -999, -999, -999},
  103640. {-999, -999, -999, -999, -999, -999, -999, -999,
  103641. -999, -999, -999, -999, -110, -95, -80, -58,
  103642. -55, -49, -66, -68, -71, -78, -78, -80,
  103643. -88, -85, -89, -97, -100, -105, -110, -999,
  103644. -999, -999, -999, -999, -999, -999, -999, -999,
  103645. -999, -999, -999, -999, -999, -999, -999, -999,
  103646. -999, -999, -999, -999, -999, -999, -999, -999},
  103647. {-999, -999, -999, -999, -999, -999, -999, -999,
  103648. -999, -999, -999, -999, -110, -95, -80, -53,
  103649. -52, -41, -59, -59, -49, -58, -56, -63,
  103650. -86, -79, -90, -93, -98, -103, -107, -112,
  103651. -999, -999, -999, -999, -999, -999, -999, -999,
  103652. -999, -999, -999, -999, -999, -999, -999, -999,
  103653. -999, -999, -999, -999, -999, -999, -999, -999},
  103654. {-999, -999, -999, -999, -999, -999, -999, -999,
  103655. -999, -999, -999, -110, -97, -91, -73, -45,
  103656. -40, -33, -53, -61, -49, -54, -50, -50,
  103657. -60, -52, -67, -74, -81, -92, -96, -100,
  103658. -105, -110, -999, -999, -999, -999, -999, -999,
  103659. -999, -999, -999, -999, -999, -999, -999, -999,
  103660. -999, -999, -999, -999, -999, -999, -999, -999}},
  103661. {{-999, -999, -999, -999, -999, -999, -999, -999,
  103662. -999, -999, -999, -113, -106, -99, -92, -77,
  103663. -80, -88, -97, -106, -115, -999, -999, -999,
  103664. -999, -999, -999, -999, -999, -999, -999, -999,
  103665. -999, -999, -999, -999, -999, -999, -999, -999,
  103666. -999, -999, -999, -999, -999, -999, -999, -999,
  103667. -999, -999, -999, -999, -999, -999, -999, -999},
  103668. {-999, -999, -999, -999, -999, -999, -999, -999,
  103669. -999, -999, -116, -109, -102, -95, -89, -74,
  103670. -72, -88, -87, -95, -102, -109, -116, -999,
  103671. -999, -999, -999, -999, -999, -999, -999, -999,
  103672. -999, -999, -999, -999, -999, -999, -999, -999,
  103673. -999, -999, -999, -999, -999, -999, -999, -999,
  103674. -999, -999, -999, -999, -999, -999, -999, -999},
  103675. {-999, -999, -999, -999, -999, -999, -999, -999,
  103676. -999, -999, -116, -109, -102, -95, -89, -75,
  103677. -66, -74, -77, -78, -86, -87, -90, -96,
  103678. -105, -115, -999, -999, -999, -999, -999, -999,
  103679. -999, -999, -999, -999, -999, -999, -999, -999,
  103680. -999, -999, -999, -999, -999, -999, -999, -999,
  103681. -999, -999, -999, -999, -999, -999, -999, -999},
  103682. {-999, -999, -999, -999, -999, -999, -999, -999,
  103683. -999, -999, -115, -108, -101, -94, -88, -66,
  103684. -56, -61, -70, -65, -78, -72, -83, -84,
  103685. -93, -98, -105, -110, -999, -999, -999, -999,
  103686. -999, -999, -999, -999, -999, -999, -999, -999,
  103687. -999, -999, -999, -999, -999, -999, -999, -999,
  103688. -999, -999, -999, -999, -999, -999, -999, -999},
  103689. {-999, -999, -999, -999, -999, -999, -999, -999,
  103690. -999, -999, -110, -105, -95, -89, -82, -57,
  103691. -52, -52, -59, -56, -59, -58, -69, -67,
  103692. -88, -82, -82, -89, -94, -100, -108, -999,
  103693. -999, -999, -999, -999, -999, -999, -999, -999,
  103694. -999, -999, -999, -999, -999, -999, -999, -999,
  103695. -999, -999, -999, -999, -999, -999, -999, -999},
  103696. {-999, -999, -999, -999, -999, -999, -999, -999,
  103697. -999, -110, -101, -96, -90, -83, -77, -54,
  103698. -43, -38, -50, -48, -52, -48, -42, -42,
  103699. -51, -52, -53, -59, -65, -71, -78, -85,
  103700. -95, -999, -999, -999, -999, -999, -999, -999,
  103701. -999, -999, -999, -999, -999, -999, -999, -999,
  103702. -999, -999, -999, -999, -999, -999, -999, -999}},
  103703. {{-999, -999, -999, -999, -999, -999, -999, -999,
  103704. -999, -999, -999, -999, -120, -105, -86, -68,
  103705. -78, -79, -90, -100, -110, -999, -999, -999,
  103706. -999, -999, -999, -999, -999, -999, -999, -999,
  103707. -999, -999, -999, -999, -999, -999, -999, -999,
  103708. -999, -999, -999, -999, -999, -999, -999, -999,
  103709. -999, -999, -999, -999, -999, -999, -999, -999},
  103710. {-999, -999, -999, -999, -999, -999, -999, -999,
  103711. -999, -999, -999, -999, -120, -105, -86, -66,
  103712. -73, -77, -88, -96, -105, -115, -999, -999,
  103713. -999, -999, -999, -999, -999, -999, -999, -999,
  103714. -999, -999, -999, -999, -999, -999, -999, -999,
  103715. -999, -999, -999, -999, -999, -999, -999, -999,
  103716. -999, -999, -999, -999, -999, -999, -999, -999},
  103717. {-999, -999, -999, -999, -999, -999, -999, -999,
  103718. -999, -999, -999, -120, -105, -92, -80, -61,
  103719. -64, -68, -80, -87, -92, -100, -110, -999,
  103720. -999, -999, -999, -999, -999, -999, -999, -999,
  103721. -999, -999, -999, -999, -999, -999, -999, -999,
  103722. -999, -999, -999, -999, -999, -999, -999, -999,
  103723. -999, -999, -999, -999, -999, -999, -999, -999},
  103724. {-999, -999, -999, -999, -999, -999, -999, -999,
  103725. -999, -999, -999, -120, -104, -91, -79, -52,
  103726. -60, -54, -64, -69, -77, -80, -82, -84,
  103727. -85, -87, -88, -90, -999, -999, -999, -999,
  103728. -999, -999, -999, -999, -999, -999, -999, -999,
  103729. -999, -999, -999, -999, -999, -999, -999, -999,
  103730. -999, -999, -999, -999, -999, -999, -999, -999},
  103731. {-999, -999, -999, -999, -999, -999, -999, -999,
  103732. -999, -999, -999, -118, -100, -87, -77, -49,
  103733. -50, -44, -58, -61, -61, -67, -65, -62,
  103734. -62, -62, -65, -68, -999, -999, -999, -999,
  103735. -999, -999, -999, -999, -999, -999, -999, -999,
  103736. -999, -999, -999, -999, -999, -999, -999, -999,
  103737. -999, -999, -999, -999, -999, -999, -999, -999},
  103738. {-999, -999, -999, -999, -999, -999, -999, -999,
  103739. -999, -999, -999, -115, -98, -84, -62, -49,
  103740. -44, -38, -46, -49, -49, -46, -39, -37,
  103741. -39, -40, -42, -43, -999, -999, -999, -999,
  103742. -999, -999, -999, -999, -999, -999, -999, -999,
  103743. -999, -999, -999, -999, -999, -999, -999, -999,
  103744. -999, -999, -999, -999, -999, -999, -999, -999}},
  103745. {{-999, -999, -999, -999, -999, -999, -999, -999,
  103746. -999, -999, -999, -999, -999, -110, -88, -74,
  103747. -77, -82, -82, -85, -90, -94, -99, -104,
  103748. -999, -999, -999, -999, -999, -999, -999, -999,
  103749. -999, -999, -999, -999, -999, -999, -999, -999,
  103750. -999, -999, -999, -999, -999, -999, -999, -999,
  103751. -999, -999, -999, -999, -999, -999, -999, -999},
  103752. {-999, -999, -999, -999, -999, -999, -999, -999,
  103753. -999, -999, -999, -999, -999, -110, -88, -66,
  103754. -70, -81, -80, -81, -84, -88, -91, -93,
  103755. -999, -999, -999, -999, -999, -999, -999, -999,
  103756. -999, -999, -999, -999, -999, -999, -999, -999,
  103757. -999, -999, -999, -999, -999, -999, -999, -999,
  103758. -999, -999, -999, -999, -999, -999, -999, -999},
  103759. {-999, -999, -999, -999, -999, -999, -999, -999,
  103760. -999, -999, -999, -999, -999, -110, -88, -61,
  103761. -63, -70, -71, -74, -77, -80, -83, -85,
  103762. -999, -999, -999, -999, -999, -999, -999, -999,
  103763. -999, -999, -999, -999, -999, -999, -999, -999,
  103764. -999, -999, -999, -999, -999, -999, -999, -999,
  103765. -999, -999, -999, -999, -999, -999, -999, -999},
  103766. {-999, -999, -999, -999, -999, -999, -999, -999,
  103767. -999, -999, -999, -999, -999, -110, -86, -62,
  103768. -63, -62, -62, -58, -52, -50, -50, -52,
  103769. -54, -999, -999, -999, -999, -999, -999, -999,
  103770. -999, -999, -999, -999, -999, -999, -999, -999,
  103771. -999, -999, -999, -999, -999, -999, -999, -999,
  103772. -999, -999, -999, -999, -999, -999, -999, -999},
  103773. {-999, -999, -999, -999, -999, -999, -999, -999,
  103774. -999, -999, -999, -999, -118, -108, -84, -53,
  103775. -50, -50, -50, -55, -47, -45, -40, -40,
  103776. -40, -999, -999, -999, -999, -999, -999, -999,
  103777. -999, -999, -999, -999, -999, -999, -999, -999,
  103778. -999, -999, -999, -999, -999, -999, -999, -999,
  103779. -999, -999, -999, -999, -999, -999, -999, -999},
  103780. {-999, -999, -999, -999, -999, -999, -999, -999,
  103781. -999, -999, -999, -999, -118, -100, -73, -43,
  103782. -37, -42, -43, -53, -38, -37, -35, -35,
  103783. -38, -999, -999, -999, -999, -999, -999, -999,
  103784. -999, -999, -999, -999, -999, -999, -999, -999,
  103785. -999, -999, -999, -999, -999, -999, -999, -999,
  103786. -999, -999, -999, -999, -999, -999, -999, -999}},
  103787. {{-999, -999, -999, -999, -999, -999, -999, -999,
  103788. -999, -999, -999, -110, -100, -91, -84, -74,
  103789. -80, -80, -80, -80, -80, -999, -999, -999,
  103790. -999, -999, -999, -999, -999, -999, -999, -999,
  103791. -999, -999, -999, -999, -999, -999, -999, -999,
  103792. -999, -999, -999, -999, -999, -999, -999, -999,
  103793. -999, -999, -999, -999, -999, -999, -999, -999},
  103794. {-999, -999, -999, -999, -999, -999, -999, -999,
  103795. -999, -999, -999, -110, -100, -91, -84, -74,
  103796. -68, -68, -68, -68, -68, -999, -999, -999,
  103797. -999, -999, -999, -999, -999, -999, -999, -999,
  103798. -999, -999, -999, -999, -999, -999, -999, -999,
  103799. -999, -999, -999, -999, -999, -999, -999, -999,
  103800. -999, -999, -999, -999, -999, -999, -999, -999},
  103801. {-999, -999, -999, -999, -999, -999, -999, -999,
  103802. -999, -999, -999, -110, -100, -86, -78, -70,
  103803. -60, -45, -30, -21, -999, -999, -999, -999,
  103804. -999, -999, -999, -999, -999, -999, -999, -999,
  103805. -999, -999, -999, -999, -999, -999, -999, -999,
  103806. -999, -999, -999, -999, -999, -999, -999, -999,
  103807. -999, -999, -999, -999, -999, -999, -999, -999},
  103808. {-999, -999, -999, -999, -999, -999, -999, -999,
  103809. -999, -999, -999, -110, -100, -87, -78, -67,
  103810. -48, -38, -29, -21, -999, -999, -999, -999,
  103811. -999, -999, -999, -999, -999, -999, -999, -999,
  103812. -999, -999, -999, -999, -999, -999, -999, -999,
  103813. -999, -999, -999, -999, -999, -999, -999, -999,
  103814. -999, -999, -999, -999, -999, -999, -999, -999},
  103815. {-999, -999, -999, -999, -999, -999, -999, -999,
  103816. -999, -999, -999, -110, -100, -86, -69, -56,
  103817. -45, -35, -33, -29, -999, -999, -999, -999,
  103818. -999, -999, -999, -999, -999, -999, -999, -999,
  103819. -999, -999, -999, -999, -999, -999, -999, -999,
  103820. -999, -999, -999, -999, -999, -999, -999, -999,
  103821. -999, -999, -999, -999, -999, -999, -999, -999},
  103822. {-999, -999, -999, -999, -999, -999, -999, -999,
  103823. -999, -999, -999, -110, -100, -83, -71, -48,
  103824. -27, -38, -37, -34, -999, -999, -999, -999,
  103825. -999, -999, -999, -999, -999, -999, -999, -999,
  103826. -999, -999, -999, -999, -999, -999, -999, -999,
  103827. -999, -999, -999, -999, -999, -999, -999, -999,
  103828. -999, -999, -999, -999, -999, -999, -999, -999}}
  103829. };
  103830. #endif
  103831. /********* End of inlined file: masking.h *********/
  103832. #define NEGINF -9999.f
  103833. static double stereo_threshholds[]={0.0, .5, 1.0, 1.5, 2.5, 4.5, 8.5, 16.5, 9e10};
  103834. static double stereo_threshholds_limited[]={0.0, .5, 1.0, 1.5, 2.0, 2.5, 4.5, 8.5, 9e10};
  103835. vorbis_look_psy_global *_vp_global_look(vorbis_info *vi){
  103836. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  103837. vorbis_info_psy_global *gi=&ci->psy_g_param;
  103838. vorbis_look_psy_global *look=(vorbis_look_psy_global*)_ogg_calloc(1,sizeof(*look));
  103839. look->channels=vi->channels;
  103840. look->ampmax=-9999.;
  103841. look->gi=gi;
  103842. return(look);
  103843. }
  103844. void _vp_global_free(vorbis_look_psy_global *look){
  103845. if(look){
  103846. memset(look,0,sizeof(*look));
  103847. _ogg_free(look);
  103848. }
  103849. }
  103850. void _vi_gpsy_free(vorbis_info_psy_global *i){
  103851. if(i){
  103852. memset(i,0,sizeof(*i));
  103853. _ogg_free(i);
  103854. }
  103855. }
  103856. void _vi_psy_free(vorbis_info_psy *i){
  103857. if(i){
  103858. memset(i,0,sizeof(*i));
  103859. _ogg_free(i);
  103860. }
  103861. }
  103862. static void min_curve(float *c,
  103863. float *c2){
  103864. int i;
  103865. for(i=0;i<EHMER_MAX;i++)if(c2[i]<c[i])c[i]=c2[i];
  103866. }
  103867. static void max_curve(float *c,
  103868. float *c2){
  103869. int i;
  103870. for(i=0;i<EHMER_MAX;i++)if(c2[i]>c[i])c[i]=c2[i];
  103871. }
  103872. static void attenuate_curve(float *c,float att){
  103873. int i;
  103874. for(i=0;i<EHMER_MAX;i++)
  103875. c[i]+=att;
  103876. }
  103877. static float ***setup_tone_curves(float curveatt_dB[P_BANDS],float binHz,int n,
  103878. float center_boost, float center_decay_rate){
  103879. int i,j,k,m;
  103880. float ath[EHMER_MAX];
  103881. float workc[P_BANDS][P_LEVELS][EHMER_MAX];
  103882. float athc[P_LEVELS][EHMER_MAX];
  103883. float *brute_buffer=(float*) alloca(n*sizeof(*brute_buffer));
  103884. float ***ret=(float***) _ogg_malloc(sizeof(*ret)*P_BANDS);
  103885. memset(workc,0,sizeof(workc));
  103886. for(i=0;i<P_BANDS;i++){
  103887. int ath_offset=i*4;
  103888. for(j=0;j<EHMER_MAX;j++){
  103889. float min=999.;
  103890. for(k=0;k<4;k++)
  103891. if(j+k+ath_offset<MAX_ATH){
  103892. if(min>ATH[j+k+ath_offset])min=ATH[j+k+ath_offset];
  103893. }else{
  103894. if(min>ATH[MAX_ATH-1])min=ATH[MAX_ATH-1];
  103895. }
  103896. ath[j]=min;
  103897. }
  103898. for(j=0;j<6;j++)
  103899. memcpy(workc[i][j+2],tonemasks[i][j],EHMER_MAX*sizeof(*tonemasks[i][j]));
  103900. memcpy(workc[i][0],tonemasks[i][0],EHMER_MAX*sizeof(*tonemasks[i][0]));
  103901. memcpy(workc[i][1],tonemasks[i][0],EHMER_MAX*sizeof(*tonemasks[i][0]));
  103902. for(j=0;j<P_LEVELS;j++){
  103903. for(k=0;k<EHMER_MAX;k++){
  103904. float adj=center_boost+abs(EHMER_OFFSET-k)*center_decay_rate;
  103905. if(adj<0. && center_boost>0)adj=0.;
  103906. if(adj>0. && center_boost<0)adj=0.;
  103907. workc[i][j][k]+=adj;
  103908. }
  103909. }
  103910. for(j=0;j<P_LEVELS;j++){
  103911. attenuate_curve(workc[i][j],curveatt_dB[i]+100.-(j<2?2:j)*10.-P_LEVEL_0);
  103912. memcpy(athc[j],ath,EHMER_MAX*sizeof(**athc));
  103913. attenuate_curve(athc[j],+100.-j*10.f-P_LEVEL_0);
  103914. max_curve(athc[j],workc[i][j]);
  103915. }
  103916. for(j=1;j<P_LEVELS;j++){
  103917. min_curve(athc[j],athc[j-1]);
  103918. min_curve(workc[i][j],athc[j]);
  103919. }
  103920. }
  103921. for(i=0;i<P_BANDS;i++){
  103922. int hi_curve,lo_curve,bin;
  103923. ret[i]=(float**)_ogg_malloc(sizeof(**ret)*P_LEVELS);
  103924. bin=floor(fromOC(i*.5)/binHz);
  103925. lo_curve= ceil(toOC(bin*binHz+1)*2);
  103926. hi_curve= floor(toOC((bin+1)*binHz)*2);
  103927. if(lo_curve>i)lo_curve=i;
  103928. if(lo_curve<0)lo_curve=0;
  103929. if(hi_curve>=P_BANDS)hi_curve=P_BANDS-1;
  103930. for(m=0;m<P_LEVELS;m++){
  103931. ret[i][m]=(float*)_ogg_malloc(sizeof(***ret)*(EHMER_MAX+2));
  103932. for(j=0;j<n;j++)brute_buffer[j]=999.;
  103933. for(k=lo_curve;k<=hi_curve;k++){
  103934. int l=0;
  103935. for(j=0;j<EHMER_MAX;j++){
  103936. int lo_bin= fromOC(j*.125+k*.5-2.0625)/binHz;
  103937. int hi_bin= fromOC(j*.125+k*.5-1.9375)/binHz+1;
  103938. if(lo_bin<0)lo_bin=0;
  103939. if(lo_bin>n)lo_bin=n;
  103940. if(lo_bin<l)l=lo_bin;
  103941. if(hi_bin<0)hi_bin=0;
  103942. if(hi_bin>n)hi_bin=n;
  103943. for(;l<hi_bin && l<n;l++)
  103944. if(brute_buffer[l]>workc[k][m][j])
  103945. brute_buffer[l]=workc[k][m][j];
  103946. }
  103947. for(;l<n;l++)
  103948. if(brute_buffer[l]>workc[k][m][EHMER_MAX-1])
  103949. brute_buffer[l]=workc[k][m][EHMER_MAX-1];
  103950. }
  103951. if(i+1<P_BANDS){
  103952. int l=0;
  103953. k=i+1;
  103954. for(j=0;j<EHMER_MAX;j++){
  103955. int lo_bin= fromOC(j*.125+i*.5-2.0625)/binHz;
  103956. int hi_bin= fromOC(j*.125+i*.5-1.9375)/binHz+1;
  103957. if(lo_bin<0)lo_bin=0;
  103958. if(lo_bin>n)lo_bin=n;
  103959. if(lo_bin<l)l=lo_bin;
  103960. if(hi_bin<0)hi_bin=0;
  103961. if(hi_bin>n)hi_bin=n;
  103962. for(;l<hi_bin && l<n;l++)
  103963. if(brute_buffer[l]>workc[k][m][j])
  103964. brute_buffer[l]=workc[k][m][j];
  103965. }
  103966. for(;l<n;l++)
  103967. if(brute_buffer[l]>workc[k][m][EHMER_MAX-1])
  103968. brute_buffer[l]=workc[k][m][EHMER_MAX-1];
  103969. }
  103970. for(j=0;j<EHMER_MAX;j++){
  103971. int bin=fromOC(j*.125+i*.5-2.)/binHz;
  103972. if(bin<0){
  103973. ret[i][m][j+2]=-999.;
  103974. }else{
  103975. if(bin>=n){
  103976. ret[i][m][j+2]=-999.;
  103977. }else{
  103978. ret[i][m][j+2]=brute_buffer[bin];
  103979. }
  103980. }
  103981. }
  103982. for(j=0;j<EHMER_OFFSET;j++)
  103983. if(ret[i][m][j+2]>-200.f)break;
  103984. ret[i][m][0]=j;
  103985. for(j=EHMER_MAX-1;j>EHMER_OFFSET+1;j--)
  103986. if(ret[i][m][j+2]>-200.f)
  103987. break;
  103988. ret[i][m][1]=j;
  103989. }
  103990. }
  103991. return(ret);
  103992. }
  103993. void _vp_psy_init(vorbis_look_psy *p,vorbis_info_psy *vi,
  103994. vorbis_info_psy_global *gi,int n,long rate){
  103995. long i,j,lo=-99,hi=1;
  103996. long maxoc;
  103997. memset(p,0,sizeof(*p));
  103998. p->eighth_octave_lines=gi->eighth_octave_lines;
  103999. p->shiftoc=rint(log(gi->eighth_octave_lines*8.f)/log(2.f))-1;
  104000. p->firstoc=toOC(.25f*rate*.5/n)*(1<<(p->shiftoc+1))-gi->eighth_octave_lines;
  104001. maxoc=toOC((n+.25f)*rate*.5/n)*(1<<(p->shiftoc+1))+.5f;
  104002. p->total_octave_lines=maxoc-p->firstoc+1;
  104003. p->ath=(float*)_ogg_malloc(n*sizeof(*p->ath));
  104004. p->octave=(long*)_ogg_malloc(n*sizeof(*p->octave));
  104005. p->bark=(long*)_ogg_malloc(n*sizeof(*p->bark));
  104006. p->vi=vi;
  104007. p->n=n;
  104008. p->rate=rate;
  104009. p->m_val = 1.;
  104010. if(rate < 26000) p->m_val = 0;
  104011. else if(rate < 38000) p->m_val = .94; /* 32kHz */
  104012. else if(rate > 46000) p->m_val = 1.275; /* 48kHz */
  104013. for(i=0,j=0;i<MAX_ATH-1;i++){
  104014. int endpos=rint(fromOC((i+1)*.125-2.)*2*n/rate);
  104015. float base=ATH[i];
  104016. if(j<endpos){
  104017. float delta=(ATH[i+1]-base)/(endpos-j);
  104018. for(;j<endpos && j<n;j++){
  104019. p->ath[j]=base+100.;
  104020. base+=delta;
  104021. }
  104022. }
  104023. }
  104024. for(i=0;i<n;i++){
  104025. float bark=toBARK(rate/(2*n)*i);
  104026. for(;lo+vi->noisewindowlomin<i &&
  104027. toBARK(rate/(2*n)*lo)<(bark-vi->noisewindowlo);lo++);
  104028. for(;hi<=n && (hi<i+vi->noisewindowhimin ||
  104029. toBARK(rate/(2*n)*hi)<(bark+vi->noisewindowhi));hi++);
  104030. p->bark[i]=((lo-1)<<16)+(hi-1);
  104031. }
  104032. for(i=0;i<n;i++)
  104033. p->octave[i]=toOC((i+.25f)*.5*rate/n)*(1<<(p->shiftoc+1))+.5f;
  104034. p->tonecurves=setup_tone_curves(vi->toneatt,rate*.5/n,n,
  104035. vi->tone_centerboost,vi->tone_decay);
  104036. p->noiseoffset=(float**)_ogg_malloc(P_NOISECURVES*sizeof(*p->noiseoffset));
  104037. for(i=0;i<P_NOISECURVES;i++)
  104038. p->noiseoffset[i]=(float*)_ogg_malloc(n*sizeof(**p->noiseoffset));
  104039. for(i=0;i<n;i++){
  104040. float halfoc=toOC((i+.5)*rate/(2.*n))*2.;
  104041. int inthalfoc;
  104042. float del;
  104043. if(halfoc<0)halfoc=0;
  104044. if(halfoc>=P_BANDS-1)halfoc=P_BANDS-1;
  104045. inthalfoc=(int)halfoc;
  104046. del=halfoc-inthalfoc;
  104047. for(j=0;j<P_NOISECURVES;j++)
  104048. p->noiseoffset[j][i]=
  104049. p->vi->noiseoff[j][inthalfoc]*(1.-del) +
  104050. p->vi->noiseoff[j][inthalfoc+1]*del;
  104051. }
  104052. #if 0
  104053. {
  104054. static int ls=0;
  104055. _analysis_output_always("noiseoff0",ls,p->noiseoffset[0],n,1,0,0);
  104056. _analysis_output_always("noiseoff1",ls,p->noiseoffset[1],n,1,0,0);
  104057. _analysis_output_always("noiseoff2",ls++,p->noiseoffset[2],n,1,0,0);
  104058. }
  104059. #endif
  104060. }
  104061. void _vp_psy_clear(vorbis_look_psy *p){
  104062. int i,j;
  104063. if(p){
  104064. if(p->ath)_ogg_free(p->ath);
  104065. if(p->octave)_ogg_free(p->octave);
  104066. if(p->bark)_ogg_free(p->bark);
  104067. if(p->tonecurves){
  104068. for(i=0;i<P_BANDS;i++){
  104069. for(j=0;j<P_LEVELS;j++){
  104070. _ogg_free(p->tonecurves[i][j]);
  104071. }
  104072. _ogg_free(p->tonecurves[i]);
  104073. }
  104074. _ogg_free(p->tonecurves);
  104075. }
  104076. if(p->noiseoffset){
  104077. for(i=0;i<P_NOISECURVES;i++){
  104078. _ogg_free(p->noiseoffset[i]);
  104079. }
  104080. _ogg_free(p->noiseoffset);
  104081. }
  104082. memset(p,0,sizeof(*p));
  104083. }
  104084. }
  104085. static void seed_curve(float *seed,
  104086. const float **curves,
  104087. float amp,
  104088. int oc, int n,
  104089. int linesper,float dBoffset){
  104090. int i,post1;
  104091. int seedptr;
  104092. const float *posts,*curve;
  104093. int choice=(int)((amp+dBoffset-P_LEVEL_0)*.1f);
  104094. choice=max(choice,0);
  104095. choice=min(choice,P_LEVELS-1);
  104096. posts=curves[choice];
  104097. curve=posts+2;
  104098. post1=(int)posts[1];
  104099. seedptr=oc+(posts[0]-EHMER_OFFSET)*linesper-(linesper>>1);
  104100. for(i=posts[0];i<post1;i++){
  104101. if(seedptr>0){
  104102. float lin=amp+curve[i];
  104103. if(seed[seedptr]<lin)seed[seedptr]=lin;
  104104. }
  104105. seedptr+=linesper;
  104106. if(seedptr>=n)break;
  104107. }
  104108. }
  104109. static void seed_loop(vorbis_look_psy *p,
  104110. const float ***curves,
  104111. const float *f,
  104112. const float *flr,
  104113. float *seed,
  104114. float specmax){
  104115. vorbis_info_psy *vi=p->vi;
  104116. long n=p->n,i;
  104117. float dBoffset=vi->max_curve_dB-specmax;
  104118. for(i=0;i<n;i++){
  104119. float max=f[i];
  104120. long oc=p->octave[i];
  104121. while(i+1<n && p->octave[i+1]==oc){
  104122. i++;
  104123. if(f[i]>max)max=f[i];
  104124. }
  104125. if(max+6.f>flr[i]){
  104126. oc=oc>>p->shiftoc;
  104127. if(oc>=P_BANDS)oc=P_BANDS-1;
  104128. if(oc<0)oc=0;
  104129. seed_curve(seed,
  104130. curves[oc],
  104131. max,
  104132. p->octave[i]-p->firstoc,
  104133. p->total_octave_lines,
  104134. p->eighth_octave_lines,
  104135. dBoffset);
  104136. }
  104137. }
  104138. }
  104139. static void seed_chase(float *seeds, int linesper, long n){
  104140. long *posstack=(long*)alloca(n*sizeof(*posstack));
  104141. float *ampstack=(float*)alloca(n*sizeof(*ampstack));
  104142. long stack=0;
  104143. long pos=0;
  104144. long i;
  104145. for(i=0;i<n;i++){
  104146. if(stack<2){
  104147. posstack[stack]=i;
  104148. ampstack[stack++]=seeds[i];
  104149. }else{
  104150. while(1){
  104151. if(seeds[i]<ampstack[stack-1]){
  104152. posstack[stack]=i;
  104153. ampstack[stack++]=seeds[i];
  104154. break;
  104155. }else{
  104156. if(i<posstack[stack-1]+linesper){
  104157. if(stack>1 && ampstack[stack-1]<=ampstack[stack-2] &&
  104158. i<posstack[stack-2]+linesper){
  104159. stack--;
  104160. continue;
  104161. }
  104162. }
  104163. posstack[stack]=i;
  104164. ampstack[stack++]=seeds[i];
  104165. break;
  104166. }
  104167. }
  104168. }
  104169. }
  104170. for(i=0;i<stack;i++){
  104171. long endpos;
  104172. if(i<stack-1 && ampstack[i+1]>ampstack[i]){
  104173. endpos=posstack[i+1];
  104174. }else{
  104175. endpos=posstack[i]+linesper+1; /* +1 is important, else bin 0 is
  104176. discarded in short frames */
  104177. }
  104178. if(endpos>n)endpos=n;
  104179. for(;pos<endpos;pos++)
  104180. seeds[pos]=ampstack[i];
  104181. }
  104182. }
  104183. #include<stdio.h>
  104184. static void max_seeds(vorbis_look_psy *p,
  104185. float *seed,
  104186. float *flr){
  104187. long n=p->total_octave_lines;
  104188. int linesper=p->eighth_octave_lines;
  104189. long linpos=0;
  104190. long pos;
  104191. seed_chase(seed,linesper,n); /* for masking */
  104192. pos=p->octave[0]-p->firstoc-(linesper>>1);
  104193. while(linpos+1<p->n){
  104194. float minV=seed[pos];
  104195. long end=((p->octave[linpos]+p->octave[linpos+1])>>1)-p->firstoc;
  104196. if(minV>p->vi->tone_abs_limit)minV=p->vi->tone_abs_limit;
  104197. while(pos+1<=end){
  104198. pos++;
  104199. if((seed[pos]>NEGINF && seed[pos]<minV) || minV==NEGINF)
  104200. minV=seed[pos];
  104201. }
  104202. end=pos+p->firstoc;
  104203. for(;linpos<p->n && p->octave[linpos]<=end;linpos++)
  104204. if(flr[linpos]<minV)flr[linpos]=minV;
  104205. }
  104206. {
  104207. float minV=seed[p->total_octave_lines-1];
  104208. for(;linpos<p->n;linpos++)
  104209. if(flr[linpos]<minV)flr[linpos]=minV;
  104210. }
  104211. }
  104212. static void bark_noise_hybridmp(int n,const long *b,
  104213. const float *f,
  104214. float *noise,
  104215. const float offset,
  104216. const int fixed){
  104217. float *N=(float*) alloca(n*sizeof(*N));
  104218. float *X=(float*) alloca(n*sizeof(*N));
  104219. float *XX=(float*) alloca(n*sizeof(*N));
  104220. float *Y=(float*) alloca(n*sizeof(*N));
  104221. float *XY=(float*) alloca(n*sizeof(*N));
  104222. float tN, tX, tXX, tY, tXY;
  104223. int i;
  104224. int lo, hi;
  104225. float R, A, B, D;
  104226. float w, x, y;
  104227. tN = tX = tXX = tY = tXY = 0.f;
  104228. y = f[0] + offset;
  104229. if (y < 1.f) y = 1.f;
  104230. w = y * y * .5;
  104231. tN += w;
  104232. tX += w;
  104233. tY += w * y;
  104234. N[0] = tN;
  104235. X[0] = tX;
  104236. XX[0] = tXX;
  104237. Y[0] = tY;
  104238. XY[0] = tXY;
  104239. for (i = 1, x = 1.f; i < n; i++, x += 1.f) {
  104240. y = f[i] + offset;
  104241. if (y < 1.f) y = 1.f;
  104242. w = y * y;
  104243. tN += w;
  104244. tX += w * x;
  104245. tXX += w * x * x;
  104246. tY += w * y;
  104247. tXY += w * x * y;
  104248. N[i] = tN;
  104249. X[i] = tX;
  104250. XX[i] = tXX;
  104251. Y[i] = tY;
  104252. XY[i] = tXY;
  104253. }
  104254. for (i = 0, x = 0.f;; i++, x += 1.f) {
  104255. lo = b[i] >> 16;
  104256. if( lo>=0 ) break;
  104257. hi = b[i] & 0xffff;
  104258. tN = N[hi] + N[-lo];
  104259. tX = X[hi] - X[-lo];
  104260. tXX = XX[hi] + XX[-lo];
  104261. tY = Y[hi] + Y[-lo];
  104262. tXY = XY[hi] - XY[-lo];
  104263. A = tY * tXX - tX * tXY;
  104264. B = tN * tXY - tX * tY;
  104265. D = tN * tXX - tX * tX;
  104266. R = (A + x * B) / D;
  104267. if (R < 0.f)
  104268. R = 0.f;
  104269. noise[i] = R - offset;
  104270. }
  104271. for ( ;; i++, x += 1.f) {
  104272. lo = b[i] >> 16;
  104273. hi = b[i] & 0xffff;
  104274. if(hi>=n)break;
  104275. tN = N[hi] - N[lo];
  104276. tX = X[hi] - X[lo];
  104277. tXX = XX[hi] - XX[lo];
  104278. tY = Y[hi] - Y[lo];
  104279. tXY = XY[hi] - XY[lo];
  104280. A = tY * tXX - tX * tXY;
  104281. B = tN * tXY - tX * tY;
  104282. D = tN * tXX - tX * tX;
  104283. R = (A + x * B) / D;
  104284. if (R < 0.f) R = 0.f;
  104285. noise[i] = R - offset;
  104286. }
  104287. for ( ; i < n; i++, x += 1.f) {
  104288. R = (A + x * B) / D;
  104289. if (R < 0.f) R = 0.f;
  104290. noise[i] = R - offset;
  104291. }
  104292. if (fixed <= 0) return;
  104293. for (i = 0, x = 0.f;; i++, x += 1.f) {
  104294. hi = i + fixed / 2;
  104295. lo = hi - fixed;
  104296. if(lo>=0)break;
  104297. tN = N[hi] + N[-lo];
  104298. tX = X[hi] - X[-lo];
  104299. tXX = XX[hi] + XX[-lo];
  104300. tY = Y[hi] + Y[-lo];
  104301. tXY = XY[hi] - XY[-lo];
  104302. A = tY * tXX - tX * tXY;
  104303. B = tN * tXY - tX * tY;
  104304. D = tN * tXX - tX * tX;
  104305. R = (A + x * B) / D;
  104306. if (R - offset < noise[i]) noise[i] = R - offset;
  104307. }
  104308. for ( ;; i++, x += 1.f) {
  104309. hi = i + fixed / 2;
  104310. lo = hi - fixed;
  104311. if(hi>=n)break;
  104312. tN = N[hi] - N[lo];
  104313. tX = X[hi] - X[lo];
  104314. tXX = XX[hi] - XX[lo];
  104315. tY = Y[hi] - Y[lo];
  104316. tXY = XY[hi] - XY[lo];
  104317. A = tY * tXX - tX * tXY;
  104318. B = tN * tXY - tX * tY;
  104319. D = tN * tXX - tX * tX;
  104320. R = (A + x * B) / D;
  104321. if (R - offset < noise[i]) noise[i] = R - offset;
  104322. }
  104323. for ( ; i < n; i++, x += 1.f) {
  104324. R = (A + x * B) / D;
  104325. if (R - offset < noise[i]) noise[i] = R - offset;
  104326. }
  104327. }
  104328. static float FLOOR1_fromdB_INV_LOOKUP[256]={
  104329. 0.F, 8.81683e+06F, 8.27882e+06F, 7.77365e+06F,
  104330. 7.29930e+06F, 6.85389e+06F, 6.43567e+06F, 6.04296e+06F,
  104331. 5.67422e+06F, 5.32798e+06F, 5.00286e+06F, 4.69759e+06F,
  104332. 4.41094e+06F, 4.14178e+06F, 3.88905e+06F, 3.65174e+06F,
  104333. 3.42891e+06F, 3.21968e+06F, 3.02321e+06F, 2.83873e+06F,
  104334. 2.66551e+06F, 2.50286e+06F, 2.35014e+06F, 2.20673e+06F,
  104335. 2.07208e+06F, 1.94564e+06F, 1.82692e+06F, 1.71544e+06F,
  104336. 1.61076e+06F, 1.51247e+06F, 1.42018e+06F, 1.33352e+06F,
  104337. 1.25215e+06F, 1.17574e+06F, 1.10400e+06F, 1.03663e+06F,
  104338. 973377.F, 913981.F, 858210.F, 805842.F,
  104339. 756669.F, 710497.F, 667142.F, 626433.F,
  104340. 588208.F, 552316.F, 518613.F, 486967.F,
  104341. 457252.F, 429351.F, 403152.F, 378551.F,
  104342. 355452.F, 333762.F, 313396.F, 294273.F,
  104343. 276316.F, 259455.F, 243623.F, 228757.F,
  104344. 214798.F, 201691.F, 189384.F, 177828.F,
  104345. 166977.F, 156788.F, 147221.F, 138237.F,
  104346. 129802.F, 121881.F, 114444.F, 107461.F,
  104347. 100903.F, 94746.3F, 88964.9F, 83536.2F,
  104348. 78438.8F, 73652.5F, 69158.2F, 64938.1F,
  104349. 60975.6F, 57254.9F, 53761.2F, 50480.6F,
  104350. 47400.3F, 44507.9F, 41792.0F, 39241.9F,
  104351. 36847.3F, 34598.9F, 32487.7F, 30505.3F,
  104352. 28643.8F, 26896.0F, 25254.8F, 23713.7F,
  104353. 22266.7F, 20908.0F, 19632.2F, 18434.2F,
  104354. 17309.4F, 16253.1F, 15261.4F, 14330.1F,
  104355. 13455.7F, 12634.6F, 11863.7F, 11139.7F,
  104356. 10460.0F, 9821.72F, 9222.39F, 8659.64F,
  104357. 8131.23F, 7635.06F, 7169.17F, 6731.70F,
  104358. 6320.93F, 5935.23F, 5573.06F, 5232.99F,
  104359. 4913.67F, 4613.84F, 4332.30F, 4067.94F,
  104360. 3819.72F, 3586.64F, 3367.78F, 3162.28F,
  104361. 2969.31F, 2788.13F, 2617.99F, 2458.24F,
  104362. 2308.24F, 2167.39F, 2035.14F, 1910.95F,
  104363. 1794.35F, 1684.85F, 1582.04F, 1485.51F,
  104364. 1394.86F, 1309.75F, 1229.83F, 1154.78F,
  104365. 1084.32F, 1018.15F, 956.024F, 897.687F,
  104366. 842.910F, 791.475F, 743.179F, 697.830F,
  104367. 655.249F, 615.265F, 577.722F, 542.469F,
  104368. 509.367F, 478.286F, 449.101F, 421.696F,
  104369. 395.964F, 371.803F, 349.115F, 327.812F,
  104370. 307.809F, 289.026F, 271.390F, 254.830F,
  104371. 239.280F, 224.679F, 210.969F, 198.096F,
  104372. 186.008F, 174.658F, 164.000F, 153.993F,
  104373. 144.596F, 135.773F, 127.488F, 119.708F,
  104374. 112.404F, 105.545F, 99.1046F, 93.0572F,
  104375. 87.3788F, 82.0469F, 77.0404F, 72.3394F,
  104376. 67.9252F, 63.7804F, 59.8885F, 56.2341F,
  104377. 52.8027F, 49.5807F, 46.5553F, 43.7144F,
  104378. 41.0470F, 38.5423F, 36.1904F, 33.9821F,
  104379. 31.9085F, 29.9614F, 28.1332F, 26.4165F,
  104380. 24.8045F, 23.2910F, 21.8697F, 20.5352F,
  104381. 19.2822F, 18.1056F, 17.0008F, 15.9634F,
  104382. 14.9893F, 14.0746F, 13.2158F, 12.4094F,
  104383. 11.6522F, 10.9411F, 10.2735F, 9.64662F,
  104384. 9.05798F, 8.50526F, 7.98626F, 7.49894F,
  104385. 7.04135F, 6.61169F, 6.20824F, 5.82941F,
  104386. 5.47370F, 5.13970F, 4.82607F, 4.53158F,
  104387. 4.25507F, 3.99542F, 3.75162F, 3.52269F,
  104388. 3.30774F, 3.10590F, 2.91638F, 2.73842F,
  104389. 2.57132F, 2.41442F, 2.26709F, 2.12875F,
  104390. 1.99885F, 1.87688F, 1.76236F, 1.65482F,
  104391. 1.55384F, 1.45902F, 1.36999F, 1.28640F,
  104392. 1.20790F, 1.13419F, 1.06499F, 1.F
  104393. };
  104394. void _vp_remove_floor(vorbis_look_psy *p,
  104395. float *mdct,
  104396. int *codedflr,
  104397. float *residue,
  104398. int sliding_lowpass){
  104399. int i,n=p->n;
  104400. if(sliding_lowpass>n)sliding_lowpass=n;
  104401. for(i=0;i<sliding_lowpass;i++){
  104402. residue[i]=
  104403. mdct[i]*FLOOR1_fromdB_INV_LOOKUP[codedflr[i]];
  104404. }
  104405. for(;i<n;i++)
  104406. residue[i]=0.;
  104407. }
  104408. void _vp_noisemask(vorbis_look_psy *p,
  104409. float *logmdct,
  104410. float *logmask){
  104411. int i,n=p->n;
  104412. float *work=(float*) alloca(n*sizeof(*work));
  104413. bark_noise_hybridmp(n,p->bark,logmdct,logmask,
  104414. 140.,-1);
  104415. for(i=0;i<n;i++)work[i]=logmdct[i]-logmask[i];
  104416. bark_noise_hybridmp(n,p->bark,work,logmask,0.,
  104417. p->vi->noisewindowfixed);
  104418. for(i=0;i<n;i++)work[i]=logmdct[i]-work[i];
  104419. #if 0
  104420. {
  104421. static int seq=0;
  104422. float work2[n];
  104423. for(i=0;i<n;i++){
  104424. work2[i]=logmask[i]+work[i];
  104425. }
  104426. if(seq&1)
  104427. _analysis_output("median2R",seq/2,work,n,1,0,0);
  104428. else
  104429. _analysis_output("median2L",seq/2,work,n,1,0,0);
  104430. if(seq&1)
  104431. _analysis_output("envelope2R",seq/2,work2,n,1,0,0);
  104432. else
  104433. _analysis_output("envelope2L",seq/2,work2,n,1,0,0);
  104434. seq++;
  104435. }
  104436. #endif
  104437. for(i=0;i<n;i++){
  104438. int dB=logmask[i]+.5;
  104439. if(dB>=NOISE_COMPAND_LEVELS)dB=NOISE_COMPAND_LEVELS-1;
  104440. if(dB<0)dB=0;
  104441. logmask[i]= work[i]+p->vi->noisecompand[dB];
  104442. }
  104443. }
  104444. void _vp_tonemask(vorbis_look_psy *p,
  104445. float *logfft,
  104446. float *logmask,
  104447. float global_specmax,
  104448. float local_specmax){
  104449. int i,n=p->n;
  104450. float *seed=(float*) alloca(sizeof(*seed)*p->total_octave_lines);
  104451. float att=local_specmax+p->vi->ath_adjatt;
  104452. for(i=0;i<p->total_octave_lines;i++)seed[i]=NEGINF;
  104453. if(att<p->vi->ath_maxatt)att=p->vi->ath_maxatt;
  104454. for(i=0;i<n;i++)
  104455. logmask[i]=p->ath[i]+att;
  104456. seed_loop(p,(const float ***)p->tonecurves,logfft,logmask,seed,global_specmax);
  104457. max_seeds(p,seed,logmask);
  104458. }
  104459. void _vp_offset_and_mix(vorbis_look_psy *p,
  104460. float *noise,
  104461. float *tone,
  104462. int offset_select,
  104463. float *logmask,
  104464. float *mdct,
  104465. float *logmdct){
  104466. int i,n=p->n;
  104467. float de, coeffi, cx;/* AoTuV */
  104468. float toneatt=p->vi->tone_masteratt[offset_select];
  104469. cx = p->m_val;
  104470. for(i=0;i<n;i++){
  104471. float val= noise[i]+p->noiseoffset[offset_select][i];
  104472. if(val>p->vi->noisemaxsupp)val=p->vi->noisemaxsupp;
  104473. logmask[i]=max(val,tone[i]+toneatt);
  104474. if(offset_select == 1) {
  104475. coeffi = -17.2; /* coeffi is a -17.2dB threshold */
  104476. val = val - logmdct[i]; /* val == mdct line value relative to floor in dB */
  104477. if(val > coeffi){
  104478. de = 1.0-((val-coeffi)*0.005*cx);
  104479. if(de < 0) de = 0.0001;
  104480. }else
  104481. de = 1.0-((val-coeffi)*0.0003*cx);
  104482. mdct[i] *= de;
  104483. }
  104484. }
  104485. }
  104486. float _vp_ampmax_decay(float amp,vorbis_dsp_state *vd){
  104487. vorbis_info *vi=vd->vi;
  104488. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  104489. vorbis_info_psy_global *gi=&ci->psy_g_param;
  104490. int n=ci->blocksizes[vd->W]/2;
  104491. float secs=(float)n/vi->rate;
  104492. amp+=secs*gi->ampmax_att_per_sec;
  104493. if(amp<-9999)amp=-9999;
  104494. return(amp);
  104495. }
  104496. static void couple_lossless(float A, float B,
  104497. float *qA, float *qB){
  104498. int test1=fabs(*qA)>fabs(*qB);
  104499. test1-= fabs(*qA)<fabs(*qB);
  104500. if(!test1)test1=((fabs(A)>fabs(B))<<1)-1;
  104501. if(test1==1){
  104502. *qB=(*qA>0.f?*qA-*qB:*qB-*qA);
  104503. }else{
  104504. float temp=*qB;
  104505. *qB=(*qB>0.f?*qA-*qB:*qB-*qA);
  104506. *qA=temp;
  104507. }
  104508. if(*qB>fabs(*qA)*1.9999f){
  104509. *qB= -fabs(*qA)*2.f;
  104510. *qA= -*qA;
  104511. }
  104512. }
  104513. static float hypot_lookup[32]={
  104514. -0.009935, -0.011245, -0.012726, -0.014397,
  104515. -0.016282, -0.018407, -0.020800, -0.023494,
  104516. -0.026522, -0.029923, -0.033737, -0.038010,
  104517. -0.042787, -0.048121, -0.054064, -0.060671,
  104518. -0.068000, -0.076109, -0.085054, -0.094892,
  104519. -0.105675, -0.117451, -0.130260, -0.144134,
  104520. -0.159093, -0.175146, -0.192286, -0.210490,
  104521. -0.229718, -0.249913, -0.271001, -0.292893};
  104522. static void precomputed_couple_point(float premag,
  104523. int floorA,int floorB,
  104524. float *mag, float *ang){
  104525. int test=(floorA>floorB)-1;
  104526. int offset=31-abs(floorA-floorB);
  104527. float floormag=hypot_lookup[((offset<0)-1)&offset]+1.f;
  104528. floormag*=FLOOR1_fromdB_INV_LOOKUP[(floorB&test)|(floorA&(~test))];
  104529. *mag=premag*floormag;
  104530. *ang=0.f;
  104531. }
  104532. static float dipole_hypot(float a, float b){
  104533. if(a>0.){
  104534. if(b>0.)return sqrt(a*a+b*b);
  104535. if(a>-b)return sqrt(a*a-b*b);
  104536. return -sqrt(b*b-a*a);
  104537. }
  104538. if(b<0.)return -sqrt(a*a+b*b);
  104539. if(-a>b)return -sqrt(a*a-b*b);
  104540. return sqrt(b*b-a*a);
  104541. }
  104542. static float round_hypot(float a, float b){
  104543. if(a>0.){
  104544. if(b>0.)return sqrt(a*a+b*b);
  104545. if(a>-b)return sqrt(a*a+b*b);
  104546. return -sqrt(b*b+a*a);
  104547. }
  104548. if(b<0.)return -sqrt(a*a+b*b);
  104549. if(-a>b)return -sqrt(a*a+b*b);
  104550. return sqrt(b*b+a*a);
  104551. }
  104552. float **_vp_quantize_couple_memo(vorbis_block *vb,
  104553. vorbis_info_psy_global *g,
  104554. vorbis_look_psy *p,
  104555. vorbis_info_mapping0 *vi,
  104556. float **mdct){
  104557. int i,j,n=p->n;
  104558. float **ret=(float**) _vorbis_block_alloc(vb,vi->coupling_steps*sizeof(*ret));
  104559. int limit=g->coupling_pointlimit[p->vi->blockflag][PACKETBLOBS/2];
  104560. for(i=0;i<vi->coupling_steps;i++){
  104561. float *mdctM=mdct[vi->coupling_mag[i]];
  104562. float *mdctA=mdct[vi->coupling_ang[i]];
  104563. ret[i]=(float*) _vorbis_block_alloc(vb,n*sizeof(**ret));
  104564. for(j=0;j<limit;j++)
  104565. ret[i][j]=dipole_hypot(mdctM[j],mdctA[j]);
  104566. for(;j<n;j++)
  104567. ret[i][j]=round_hypot(mdctM[j],mdctA[j]);
  104568. }
  104569. return(ret);
  104570. }
  104571. static int apsort(const void *a, const void *b){
  104572. float f1=fabs(**(float**)a);
  104573. float f2=fabs(**(float**)b);
  104574. return (f1<f2)-(f1>f2);
  104575. }
  104576. int **_vp_quantize_couple_sort(vorbis_block *vb,
  104577. vorbis_look_psy *p,
  104578. vorbis_info_mapping0 *vi,
  104579. float **mags){
  104580. if(p->vi->normal_point_p){
  104581. int i,j,k,n=p->n;
  104582. int **ret=(int**) _vorbis_block_alloc(vb,vi->coupling_steps*sizeof(*ret));
  104583. int partition=p->vi->normal_partition;
  104584. float **work=(float**) alloca(sizeof(*work)*partition);
  104585. for(i=0;i<vi->coupling_steps;i++){
  104586. ret[i]=(int*) _vorbis_block_alloc(vb,n*sizeof(**ret));
  104587. for(j=0;j<n;j+=partition){
  104588. for(k=0;k<partition;k++)work[k]=mags[i]+k+j;
  104589. qsort(work,partition,sizeof(*work),apsort);
  104590. for(k=0;k<partition;k++)ret[i][k+j]=work[k]-mags[i];
  104591. }
  104592. }
  104593. return(ret);
  104594. }
  104595. return(NULL);
  104596. }
  104597. void _vp_noise_normalize_sort(vorbis_look_psy *p,
  104598. float *magnitudes,int *sortedindex){
  104599. int i,j,n=p->n;
  104600. vorbis_info_psy *vi=p->vi;
  104601. int partition=vi->normal_partition;
  104602. float **work=(float**) alloca(sizeof(*work)*partition);
  104603. int start=vi->normal_start;
  104604. for(j=start;j<n;j+=partition){
  104605. if(j+partition>n)partition=n-j;
  104606. for(i=0;i<partition;i++)work[i]=magnitudes+i+j;
  104607. qsort(work,partition,sizeof(*work),apsort);
  104608. for(i=0;i<partition;i++){
  104609. sortedindex[i+j-start]=work[i]-magnitudes;
  104610. }
  104611. }
  104612. }
  104613. void _vp_noise_normalize(vorbis_look_psy *p,
  104614. float *in,float *out,int *sortedindex){
  104615. int flag=0,i,j=0,n=p->n;
  104616. vorbis_info_psy *vi=p->vi;
  104617. int partition=vi->normal_partition;
  104618. int start=vi->normal_start;
  104619. if(start>n)start=n;
  104620. if(vi->normal_channel_p){
  104621. for(;j<start;j++)
  104622. out[j]=rint(in[j]);
  104623. for(;j+partition<=n;j+=partition){
  104624. float acc=0.;
  104625. int k;
  104626. for(i=j;i<j+partition;i++)
  104627. acc+=in[i]*in[i];
  104628. for(i=0;i<partition;i++){
  104629. k=sortedindex[i+j-start];
  104630. if(in[k]*in[k]>=.25f){
  104631. out[k]=rint(in[k]);
  104632. acc-=in[k]*in[k];
  104633. flag=1;
  104634. }else{
  104635. if(acc<vi->normal_thresh)break;
  104636. out[k]=unitnorm(in[k]);
  104637. acc-=1.;
  104638. }
  104639. }
  104640. for(;i<partition;i++){
  104641. k=sortedindex[i+j-start];
  104642. out[k]=0.;
  104643. }
  104644. }
  104645. }
  104646. for(;j<n;j++)
  104647. out[j]=rint(in[j]);
  104648. }
  104649. void _vp_couple(int blobno,
  104650. vorbis_info_psy_global *g,
  104651. vorbis_look_psy *p,
  104652. vorbis_info_mapping0 *vi,
  104653. float **res,
  104654. float **mag_memo,
  104655. int **mag_sort,
  104656. int **ifloor,
  104657. int *nonzero,
  104658. int sliding_lowpass){
  104659. int i,j,k,n=p->n;
  104660. for(i=0;i<vi->coupling_steps;i++){
  104661. if(nonzero[vi->coupling_mag[i]] ||
  104662. nonzero[vi->coupling_ang[i]]){
  104663. float *rM=res[vi->coupling_mag[i]];
  104664. float *rA=res[vi->coupling_ang[i]];
  104665. float *qM=rM+n;
  104666. float *qA=rA+n;
  104667. int *floorM=ifloor[vi->coupling_mag[i]];
  104668. int *floorA=ifloor[vi->coupling_ang[i]];
  104669. float prepoint=stereo_threshholds[g->coupling_prepointamp[blobno]];
  104670. float postpoint=stereo_threshholds[g->coupling_postpointamp[blobno]];
  104671. int partition=(p->vi->normal_point_p?p->vi->normal_partition:p->n);
  104672. int limit=g->coupling_pointlimit[p->vi->blockflag][blobno];
  104673. int pointlimit=limit;
  104674. nonzero[vi->coupling_mag[i]]=1;
  104675. nonzero[vi->coupling_ang[i]]=1;
  104676. if(n > 1000)
  104677. postpoint=stereo_threshholds_limited[g->coupling_postpointamp[blobno]];
  104678. for(j=0;j<p->n;j+=partition){
  104679. float acc=0.f;
  104680. for(k=0;k<partition;k++){
  104681. int l=k+j;
  104682. if(l<sliding_lowpass){
  104683. if((l>=limit && fabs(rM[l])<postpoint && fabs(rA[l])<postpoint) ||
  104684. (fabs(rM[l])<prepoint && fabs(rA[l])<prepoint)){
  104685. precomputed_couple_point(mag_memo[i][l],
  104686. floorM[l],floorA[l],
  104687. qM+l,qA+l);
  104688. if(rint(qM[l])==0.f)acc+=qM[l]*qM[l];
  104689. }else{
  104690. couple_lossless(rM[l],rA[l],qM+l,qA+l);
  104691. }
  104692. }else{
  104693. qM[l]=0.;
  104694. qA[l]=0.;
  104695. }
  104696. }
  104697. if(p->vi->normal_point_p){
  104698. for(k=0;k<partition && acc>=p->vi->normal_thresh;k++){
  104699. int l=mag_sort[i][j+k];
  104700. if(l<sliding_lowpass && l>=pointlimit && rint(qM[l])==0.f){
  104701. qM[l]=unitnorm(qM[l]);
  104702. acc-=1.f;
  104703. }
  104704. }
  104705. }
  104706. }
  104707. }
  104708. }
  104709. }
  104710. void hf_reduction(vorbis_info_psy_global *g,
  104711. vorbis_look_psy *p,
  104712. vorbis_info_mapping0 *vi,
  104713. float **mdct){
  104714. int i,j,n=p->n, de=0.3*p->m_val;
  104715. int limit=g->coupling_pointlimit[p->vi->blockflag][PACKETBLOBS/2];
  104716. for(i=0; i<vi->coupling_steps; i++){
  104717. for(j=limit; j<n; j++)
  104718. mdct[i][j] *= (1.0 - de*((float)(j-limit) / (float)(n-limit)));
  104719. }
  104720. }
  104721. #endif
  104722. /********* End of inlined file: psy.c *********/
  104723. /********* Start of inlined file: registry.c *********/
  104724. /********* Start of inlined file: juce_OggVorbisHeader.h *********/
  104725. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  104726. // tasks..
  104727. #if JUCE_MSVC
  104728. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  104729. #endif
  104730. /********* End of inlined file: juce_OggVorbisHeader.h *********/
  104731. #if JUCE_USE_OGGVORBIS
  104732. extern vorbis_func_floor floor0_exportbundle;
  104733. extern vorbis_func_floor floor1_exportbundle;
  104734. extern vorbis_func_residue residue0_exportbundle;
  104735. extern vorbis_func_residue residue1_exportbundle;
  104736. extern vorbis_func_residue residue2_exportbundle;
  104737. extern vorbis_func_mapping mapping0_exportbundle;
  104738. vorbis_func_floor *_floor_P[]={
  104739. &floor0_exportbundle,
  104740. &floor1_exportbundle,
  104741. };
  104742. vorbis_func_residue *_residue_P[]={
  104743. &residue0_exportbundle,
  104744. &residue1_exportbundle,
  104745. &residue2_exportbundle,
  104746. };
  104747. vorbis_func_mapping *_mapping_P[]={
  104748. &mapping0_exportbundle,
  104749. };
  104750. #endif
  104751. /********* End of inlined file: registry.c *********/
  104752. /********* Start of inlined file: res0.c *********/
  104753. /********* Start of inlined file: juce_OggVorbisHeader.h *********/
  104754. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  104755. // tasks..
  104756. #if JUCE_MSVC
  104757. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  104758. #endif
  104759. /********* End of inlined file: juce_OggVorbisHeader.h *********/
  104760. #if JUCE_USE_OGGVORBIS
  104761. #include <stdlib.h>
  104762. #include <string.h>
  104763. #include <math.h>
  104764. #if defined(TRAIN_RES) || defined (TRAIN_RESAUX)
  104765. #include <stdio.h>
  104766. #endif
  104767. typedef struct {
  104768. vorbis_info_residue0 *info;
  104769. int parts;
  104770. int stages;
  104771. codebook *fullbooks;
  104772. codebook *phrasebook;
  104773. codebook ***partbooks;
  104774. int partvals;
  104775. int **decodemap;
  104776. long postbits;
  104777. long phrasebits;
  104778. long frames;
  104779. #if defined(TRAIN_RES) || defined(TRAIN_RESAUX)
  104780. int train_seq;
  104781. long *training_data[8][64];
  104782. float training_max[8][64];
  104783. float training_min[8][64];
  104784. float tmin;
  104785. float tmax;
  104786. #endif
  104787. } vorbis_look_residue0;
  104788. void res0_free_info(vorbis_info_residue *i){
  104789. vorbis_info_residue0 *info=(vorbis_info_residue0 *)i;
  104790. if(info){
  104791. memset(info,0,sizeof(*info));
  104792. _ogg_free(info);
  104793. }
  104794. }
  104795. void res0_free_look(vorbis_look_residue *i){
  104796. int j;
  104797. if(i){
  104798. vorbis_look_residue0 *look=(vorbis_look_residue0 *)i;
  104799. #ifdef TRAIN_RES
  104800. {
  104801. int j,k,l;
  104802. for(j=0;j<look->parts;j++){
  104803. for(k=0;k<8;k++)
  104804. if(look->training_data[k][j]){
  104805. char buffer[80];
  104806. FILE *of;
  104807. codebook *statebook=look->partbooks[j][k];
  104808. sprintf(buffer,"res_part%d_pass%d.vqd",j,k);
  104809. of=fopen(buffer,"a");
  104810. for(l=0;l<statebook->entries;l++)
  104811. fprintf(of,"%d:%ld\n",l,look->training_data[k][j][l]);
  104812. fclose(of);
  104813. _ogg_free(look->training_data[k][j]);
  104814. look->training_data[k][j]=NULL;
  104815. }
  104816. }
  104817. }
  104818. fprintf(stderr,"min/max residue: %g::%g\n",look->tmin,look->tmax);
  104819. #endif
  104820. for(j=0;j<look->parts;j++)
  104821. if(look->partbooks[j])_ogg_free(look->partbooks[j]);
  104822. _ogg_free(look->partbooks);
  104823. for(j=0;j<look->partvals;j++)
  104824. _ogg_free(look->decodemap[j]);
  104825. _ogg_free(look->decodemap);
  104826. memset(look,0,sizeof(*look));
  104827. _ogg_free(look);
  104828. }
  104829. }
  104830. static int icount(unsigned int v){
  104831. int ret=0;
  104832. while(v){
  104833. ret+=v&1;
  104834. v>>=1;
  104835. }
  104836. return(ret);
  104837. }
  104838. void res0_pack(vorbis_info_residue *vr,oggpack_buffer *opb){
  104839. vorbis_info_residue0 *info=(vorbis_info_residue0 *)vr;
  104840. int j,acc=0;
  104841. oggpack_write(opb,info->begin,24);
  104842. oggpack_write(opb,info->end,24);
  104843. oggpack_write(opb,info->grouping-1,24); /* residue vectors to group and
  104844. code with a partitioned book */
  104845. oggpack_write(opb,info->partitions-1,6); /* possible partition choices */
  104846. oggpack_write(opb,info->groupbook,8); /* group huffman book */
  104847. for(j=0;j<info->partitions;j++){
  104848. if(ilog(info->secondstages[j])>3){
  104849. oggpack_write(opb,info->secondstages[j],3);
  104850. oggpack_write(opb,1,1);
  104851. oggpack_write(opb,info->secondstages[j]>>3,5);
  104852. }else
  104853. oggpack_write(opb,info->secondstages[j],4); /* trailing zero */
  104854. acc+=icount(info->secondstages[j]);
  104855. }
  104856. for(j=0;j<acc;j++)
  104857. oggpack_write(opb,info->booklist[j],8);
  104858. }
  104859. vorbis_info_residue *res0_unpack(vorbis_info *vi,oggpack_buffer *opb){
  104860. int j,acc=0;
  104861. vorbis_info_residue0 *info=(vorbis_info_residue0*) _ogg_calloc(1,sizeof(*info));
  104862. codec_setup_info *ci=(codec_setup_info*) vi->codec_setup;
  104863. info->begin=oggpack_read(opb,24);
  104864. info->end=oggpack_read(opb,24);
  104865. info->grouping=oggpack_read(opb,24)+1;
  104866. info->partitions=oggpack_read(opb,6)+1;
  104867. info->groupbook=oggpack_read(opb,8);
  104868. for(j=0;j<info->partitions;j++){
  104869. int cascade=oggpack_read(opb,3);
  104870. if(oggpack_read(opb,1))
  104871. cascade|=(oggpack_read(opb,5)<<3);
  104872. info->secondstages[j]=cascade;
  104873. acc+=icount(cascade);
  104874. }
  104875. for(j=0;j<acc;j++)
  104876. info->booklist[j]=oggpack_read(opb,8);
  104877. if(info->groupbook>=ci->books)goto errout;
  104878. for(j=0;j<acc;j++)
  104879. if(info->booklist[j]>=ci->books)goto errout;
  104880. return(info);
  104881. errout:
  104882. res0_free_info(info);
  104883. return(NULL);
  104884. }
  104885. vorbis_look_residue *res0_look(vorbis_dsp_state *vd,
  104886. vorbis_info_residue *vr){
  104887. vorbis_info_residue0 *info=(vorbis_info_residue0 *)vr;
  104888. vorbis_look_residue0 *look=(vorbis_look_residue0 *)_ogg_calloc(1,sizeof(*look));
  104889. codec_setup_info *ci=(codec_setup_info*)vd->vi->codec_setup;
  104890. int j,k,acc=0;
  104891. int dim;
  104892. int maxstage=0;
  104893. look->info=info;
  104894. look->parts=info->partitions;
  104895. look->fullbooks=ci->fullbooks;
  104896. look->phrasebook=ci->fullbooks+info->groupbook;
  104897. dim=look->phrasebook->dim;
  104898. look->partbooks=(codebook***)_ogg_calloc(look->parts,sizeof(*look->partbooks));
  104899. for(j=0;j<look->parts;j++){
  104900. int stages=ilog(info->secondstages[j]);
  104901. if(stages){
  104902. if(stages>maxstage)maxstage=stages;
  104903. look->partbooks[j]=(codebook**) _ogg_calloc(stages,sizeof(*look->partbooks[j]));
  104904. for(k=0;k<stages;k++)
  104905. if(info->secondstages[j]&(1<<k)){
  104906. look->partbooks[j][k]=ci->fullbooks+info->booklist[acc++];
  104907. #ifdef TRAIN_RES
  104908. look->training_data[k][j]=_ogg_calloc(look->partbooks[j][k]->entries,
  104909. sizeof(***look->training_data));
  104910. #endif
  104911. }
  104912. }
  104913. }
  104914. look->partvals=rint(pow((float)look->parts,(float)dim));
  104915. look->stages=maxstage;
  104916. look->decodemap=(int**)_ogg_malloc(look->partvals*sizeof(*look->decodemap));
  104917. for(j=0;j<look->partvals;j++){
  104918. long val=j;
  104919. long mult=look->partvals/look->parts;
  104920. look->decodemap[j]=(int*)_ogg_malloc(dim*sizeof(*look->decodemap[j]));
  104921. for(k=0;k<dim;k++){
  104922. long deco=val/mult;
  104923. val-=deco*mult;
  104924. mult/=look->parts;
  104925. look->decodemap[j][k]=deco;
  104926. }
  104927. }
  104928. #if defined(TRAIN_RES) || defined (TRAIN_RESAUX)
  104929. {
  104930. static int train_seq=0;
  104931. look->train_seq=train_seq++;
  104932. }
  104933. #endif
  104934. return(look);
  104935. }
  104936. static int local_book_besterror(codebook *book,float *a){
  104937. int dim=book->dim,i,k,o;
  104938. int best=0;
  104939. encode_aux_threshmatch *tt=book->c->thresh_tree;
  104940. for(k=0,o=dim;k<dim;++k){
  104941. float val=a[--o];
  104942. i=tt->threshvals>>1;
  104943. if(val<tt->quantthresh[i]){
  104944. if(val<tt->quantthresh[i-1]){
  104945. for(--i;i>0;--i)
  104946. if(val>=tt->quantthresh[i-1])
  104947. break;
  104948. }
  104949. }else{
  104950. for(++i;i<tt->threshvals-1;++i)
  104951. if(val<tt->quantthresh[i])break;
  104952. }
  104953. best=(best*tt->quantvals)+tt->quantmap[i];
  104954. }
  104955. if(book->c->lengthlist[best]<=0){
  104956. const static_codebook *c=book->c;
  104957. int i,j;
  104958. float bestf=0.f;
  104959. float *e=book->valuelist;
  104960. best=-1;
  104961. for(i=0;i<book->entries;i++){
  104962. if(c->lengthlist[i]>0){
  104963. float thisx=0.f;
  104964. for(j=0;j<dim;j++){
  104965. float val=(e[j]-a[j]);
  104966. thisx+=val*val;
  104967. }
  104968. if(best==-1 || thisx<bestf){
  104969. bestf=thisx;
  104970. best=i;
  104971. }
  104972. }
  104973. e+=dim;
  104974. }
  104975. }
  104976. {
  104977. float *ptr=book->valuelist+best*dim;
  104978. for(i=0;i<dim;i++)
  104979. *a++ -= *ptr++;
  104980. }
  104981. return(best);
  104982. }
  104983. static int _encodepart(oggpack_buffer *opb,float *vec, int n,
  104984. codebook *book,long *acc){
  104985. int i,bits=0;
  104986. int dim=book->dim;
  104987. int step=n/dim;
  104988. for(i=0;i<step;i++){
  104989. int entry=local_book_besterror(book,vec+i*dim);
  104990. #ifdef TRAIN_RES
  104991. acc[entry]++;
  104992. #endif
  104993. bits+=vorbis_book_encode(book,entry,opb);
  104994. }
  104995. return(bits);
  104996. }
  104997. static long **_01class(vorbis_block *vb,vorbis_look_residue *vl,
  104998. float **in,int ch){
  104999. long i,j,k;
  105000. vorbis_look_residue0 *look=(vorbis_look_residue0 *)vl;
  105001. vorbis_info_residue0 *info=look->info;
  105002. int samples_per_partition=info->grouping;
  105003. int possible_partitions=info->partitions;
  105004. int n=info->end-info->begin;
  105005. int partvals=n/samples_per_partition;
  105006. long **partword=(long**)_vorbis_block_alloc(vb,ch*sizeof(*partword));
  105007. float scale=100./samples_per_partition;
  105008. for(i=0;i<ch;i++){
  105009. partword[i]=(long*)_vorbis_block_alloc(vb,n/samples_per_partition*sizeof(*partword[i]));
  105010. memset(partword[i],0,n/samples_per_partition*sizeof(*partword[i]));
  105011. }
  105012. for(i=0;i<partvals;i++){
  105013. int offset=i*samples_per_partition+info->begin;
  105014. for(j=0;j<ch;j++){
  105015. float max=0.;
  105016. float ent=0.;
  105017. for(k=0;k<samples_per_partition;k++){
  105018. if(fabs(in[j][offset+k])>max)max=fabs(in[j][offset+k]);
  105019. ent+=fabs(rint(in[j][offset+k]));
  105020. }
  105021. ent*=scale;
  105022. for(k=0;k<possible_partitions-1;k++)
  105023. if(max<=info->classmetric1[k] &&
  105024. (info->classmetric2[k]<0 || (int)ent<info->classmetric2[k]))
  105025. break;
  105026. partword[j][i]=k;
  105027. }
  105028. }
  105029. #ifdef TRAIN_RESAUX
  105030. {
  105031. FILE *of;
  105032. char buffer[80];
  105033. for(i=0;i<ch;i++){
  105034. sprintf(buffer,"resaux_%d.vqd",look->train_seq);
  105035. of=fopen(buffer,"a");
  105036. for(j=0;j<partvals;j++)
  105037. fprintf(of,"%ld, ",partword[i][j]);
  105038. fprintf(of,"\n");
  105039. fclose(of);
  105040. }
  105041. }
  105042. #endif
  105043. look->frames++;
  105044. return(partword);
  105045. }
  105046. static long **_2class(vorbis_block *vb,vorbis_look_residue *vl,float **in,
  105047. int ch){
  105048. long i,j,k,l;
  105049. vorbis_look_residue0 *look=(vorbis_look_residue0 *)vl;
  105050. vorbis_info_residue0 *info=look->info;
  105051. int samples_per_partition=info->grouping;
  105052. int possible_partitions=info->partitions;
  105053. int n=info->end-info->begin;
  105054. int partvals=n/samples_per_partition;
  105055. long **partword=(long**)_vorbis_block_alloc(vb,sizeof(*partword));
  105056. #if defined(TRAIN_RES) || defined (TRAIN_RESAUX)
  105057. FILE *of;
  105058. char buffer[80];
  105059. #endif
  105060. partword[0]=(long*)_vorbis_block_alloc(vb,n*ch/samples_per_partition*sizeof(*partword[0]));
  105061. memset(partword[0],0,n*ch/samples_per_partition*sizeof(*partword[0]));
  105062. for(i=0,l=info->begin/ch;i<partvals;i++){
  105063. float magmax=0.f;
  105064. float angmax=0.f;
  105065. for(j=0;j<samples_per_partition;j+=ch){
  105066. if(fabs(in[0][l])>magmax)magmax=fabs(in[0][l]);
  105067. for(k=1;k<ch;k++)
  105068. if(fabs(in[k][l])>angmax)angmax=fabs(in[k][l]);
  105069. l++;
  105070. }
  105071. for(j=0;j<possible_partitions-1;j++)
  105072. if(magmax<=info->classmetric1[j] &&
  105073. angmax<=info->classmetric2[j])
  105074. break;
  105075. partword[0][i]=j;
  105076. }
  105077. #ifdef TRAIN_RESAUX
  105078. sprintf(buffer,"resaux_%d.vqd",look->train_seq);
  105079. of=fopen(buffer,"a");
  105080. for(i=0;i<partvals;i++)
  105081. fprintf(of,"%ld, ",partword[0][i]);
  105082. fprintf(of,"\n");
  105083. fclose(of);
  105084. #endif
  105085. look->frames++;
  105086. return(partword);
  105087. }
  105088. static int _01forward(oggpack_buffer *opb,
  105089. vorbis_block *vb,vorbis_look_residue *vl,
  105090. float **in,int ch,
  105091. long **partword,
  105092. int (*encode)(oggpack_buffer *,float *,int,
  105093. codebook *,long *)){
  105094. long i,j,k,s;
  105095. vorbis_look_residue0 *look=(vorbis_look_residue0 *)vl;
  105096. vorbis_info_residue0 *info=look->info;
  105097. int samples_per_partition=info->grouping;
  105098. int possible_partitions=info->partitions;
  105099. int partitions_per_word=look->phrasebook->dim;
  105100. int n=info->end-info->begin;
  105101. int partvals=n/samples_per_partition;
  105102. long resbits[128];
  105103. long resvals[128];
  105104. #ifdef TRAIN_RES
  105105. for(i=0;i<ch;i++)
  105106. for(j=info->begin;j<info->end;j++){
  105107. if(in[i][j]>look->tmax)look->tmax=in[i][j];
  105108. if(in[i][j]<look->tmin)look->tmin=in[i][j];
  105109. }
  105110. #endif
  105111. memset(resbits,0,sizeof(resbits));
  105112. memset(resvals,0,sizeof(resvals));
  105113. for(s=0;s<look->stages;s++){
  105114. for(i=0;i<partvals;){
  105115. if(s==0){
  105116. for(j=0;j<ch;j++){
  105117. long val=partword[j][i];
  105118. for(k=1;k<partitions_per_word;k++){
  105119. val*=possible_partitions;
  105120. if(i+k<partvals)
  105121. val+=partword[j][i+k];
  105122. }
  105123. if(val<look->phrasebook->entries)
  105124. look->phrasebits+=vorbis_book_encode(look->phrasebook,val,opb);
  105125. #if 0 /*def TRAIN_RES*/
  105126. else
  105127. fprintf(stderr,"!");
  105128. #endif
  105129. }
  105130. }
  105131. for(k=0;k<partitions_per_word && i<partvals;k++,i++){
  105132. long offset=i*samples_per_partition+info->begin;
  105133. for(j=0;j<ch;j++){
  105134. if(s==0)resvals[partword[j][i]]+=samples_per_partition;
  105135. if(info->secondstages[partword[j][i]]&(1<<s)){
  105136. codebook *statebook=look->partbooks[partword[j][i]][s];
  105137. if(statebook){
  105138. int ret;
  105139. long *accumulator=NULL;
  105140. #ifdef TRAIN_RES
  105141. accumulator=look->training_data[s][partword[j][i]];
  105142. {
  105143. int l;
  105144. float *samples=in[j]+offset;
  105145. for(l=0;l<samples_per_partition;l++){
  105146. if(samples[l]<look->training_min[s][partword[j][i]])
  105147. look->training_min[s][partword[j][i]]=samples[l];
  105148. if(samples[l]>look->training_max[s][partword[j][i]])
  105149. look->training_max[s][partword[j][i]]=samples[l];
  105150. }
  105151. }
  105152. #endif
  105153. ret=encode(opb,in[j]+offset,samples_per_partition,
  105154. statebook,accumulator);
  105155. look->postbits+=ret;
  105156. resbits[partword[j][i]]+=ret;
  105157. }
  105158. }
  105159. }
  105160. }
  105161. }
  105162. }
  105163. return(0);
  105164. }
  105165. static int _01inverse(vorbis_block *vb,vorbis_look_residue *vl,
  105166. float **in,int ch,
  105167. long (*decodepart)(codebook *, float *,
  105168. oggpack_buffer *,int)){
  105169. long i,j,k,l,s;
  105170. vorbis_look_residue0 *look=(vorbis_look_residue0 *)vl;
  105171. vorbis_info_residue0 *info=look->info;
  105172. int samples_per_partition=info->grouping;
  105173. int partitions_per_word=look->phrasebook->dim;
  105174. int n=info->end-info->begin;
  105175. int partvals=n/samples_per_partition;
  105176. int partwords=(partvals+partitions_per_word-1)/partitions_per_word;
  105177. int ***partword=(int***)alloca(ch*sizeof(*partword));
  105178. for(j=0;j<ch;j++)
  105179. partword[j]=(int**)_vorbis_block_alloc(vb,partwords*sizeof(*partword[j]));
  105180. for(s=0;s<look->stages;s++){
  105181. for(i=0,l=0;i<partvals;l++){
  105182. if(s==0){
  105183. for(j=0;j<ch;j++){
  105184. int temp=vorbis_book_decode(look->phrasebook,&vb->opb);
  105185. if(temp==-1)goto eopbreak;
  105186. partword[j][l]=look->decodemap[temp];
  105187. if(partword[j][l]==NULL)goto errout;
  105188. }
  105189. }
  105190. for(k=0;k<partitions_per_word && i<partvals;k++,i++)
  105191. for(j=0;j<ch;j++){
  105192. long offset=info->begin+i*samples_per_partition;
  105193. if(info->secondstages[partword[j][l][k]]&(1<<s)){
  105194. codebook *stagebook=look->partbooks[partword[j][l][k]][s];
  105195. if(stagebook){
  105196. if(decodepart(stagebook,in[j]+offset,&vb->opb,
  105197. samples_per_partition)==-1)goto eopbreak;
  105198. }
  105199. }
  105200. }
  105201. }
  105202. }
  105203. errout:
  105204. eopbreak:
  105205. return(0);
  105206. }
  105207. #if 0
  105208. long **res0_class(vorbis_block *vb,vorbis_look_residue *vl,
  105209. float **in,int *nonzero,int ch){
  105210. int i,used=0;
  105211. for(i=0;i<ch;i++)
  105212. if(nonzero[i])
  105213. in[used++]=in[i];
  105214. if(used)
  105215. return(_01class(vb,vl,in,used));
  105216. else
  105217. return(0);
  105218. }
  105219. int res0_forward(vorbis_block *vb,vorbis_look_residue *vl,
  105220. float **in,float **out,int *nonzero,int ch,
  105221. long **partword){
  105222. int i,j,used=0,n=vb->pcmend/2;
  105223. for(i=0;i<ch;i++)
  105224. if(nonzero[i]){
  105225. if(out)
  105226. for(j=0;j<n;j++)
  105227. out[i][j]+=in[i][j];
  105228. in[used++]=in[i];
  105229. }
  105230. if(used){
  105231. int ret=_01forward(vb,vl,in,used,partword,
  105232. _interleaved_encodepart);
  105233. if(out){
  105234. used=0;
  105235. for(i=0;i<ch;i++)
  105236. if(nonzero[i]){
  105237. for(j=0;j<n;j++)
  105238. out[i][j]-=in[used][j];
  105239. used++;
  105240. }
  105241. }
  105242. return(ret);
  105243. }else{
  105244. return(0);
  105245. }
  105246. }
  105247. #endif
  105248. int res0_inverse(vorbis_block *vb,vorbis_look_residue *vl,
  105249. float **in,int *nonzero,int ch){
  105250. int i,used=0;
  105251. for(i=0;i<ch;i++)
  105252. if(nonzero[i])
  105253. in[used++]=in[i];
  105254. if(used)
  105255. return(_01inverse(vb,vl,in,used,vorbis_book_decodevs_add));
  105256. else
  105257. return(0);
  105258. }
  105259. int res1_forward(oggpack_buffer *opb,vorbis_block *vb,vorbis_look_residue *vl,
  105260. float **in,float **out,int *nonzero,int ch,
  105261. long **partword){
  105262. int i,j,used=0,n=vb->pcmend/2;
  105263. for(i=0;i<ch;i++)
  105264. if(nonzero[i]){
  105265. if(out)
  105266. for(j=0;j<n;j++)
  105267. out[i][j]+=in[i][j];
  105268. in[used++]=in[i];
  105269. }
  105270. if(used){
  105271. int ret=_01forward(opb,vb,vl,in,used,partword,_encodepart);
  105272. if(out){
  105273. used=0;
  105274. for(i=0;i<ch;i++)
  105275. if(nonzero[i]){
  105276. for(j=0;j<n;j++)
  105277. out[i][j]-=in[used][j];
  105278. used++;
  105279. }
  105280. }
  105281. return(ret);
  105282. }else{
  105283. return(0);
  105284. }
  105285. }
  105286. long **res1_class(vorbis_block *vb,vorbis_look_residue *vl,
  105287. float **in,int *nonzero,int ch){
  105288. int i,used=0;
  105289. for(i=0;i<ch;i++)
  105290. if(nonzero[i])
  105291. in[used++]=in[i];
  105292. if(used)
  105293. return(_01class(vb,vl,in,used));
  105294. else
  105295. return(0);
  105296. }
  105297. int res1_inverse(vorbis_block *vb,vorbis_look_residue *vl,
  105298. float **in,int *nonzero,int ch){
  105299. int i,used=0;
  105300. for(i=0;i<ch;i++)
  105301. if(nonzero[i])
  105302. in[used++]=in[i];
  105303. if(used)
  105304. return(_01inverse(vb,vl,in,used,vorbis_book_decodev_add));
  105305. else
  105306. return(0);
  105307. }
  105308. long **res2_class(vorbis_block *vb,vorbis_look_residue *vl,
  105309. float **in,int *nonzero,int ch){
  105310. int i,used=0;
  105311. for(i=0;i<ch;i++)
  105312. if(nonzero[i])used++;
  105313. if(used)
  105314. return(_2class(vb,vl,in,ch));
  105315. else
  105316. return(0);
  105317. }
  105318. int res2_forward(oggpack_buffer *opb,
  105319. vorbis_block *vb,vorbis_look_residue *vl,
  105320. float **in,float **out,int *nonzero,int ch,
  105321. long **partword){
  105322. long i,j,k,n=vb->pcmend/2,used=0;
  105323. float *work=(float*)_vorbis_block_alloc(vb,ch*n*sizeof(*work));
  105324. for(i=0;i<ch;i++){
  105325. float *pcm=in[i];
  105326. if(nonzero[i])used++;
  105327. for(j=0,k=i;j<n;j++,k+=ch)
  105328. work[k]=pcm[j];
  105329. }
  105330. if(used){
  105331. int ret=_01forward(opb,vb,vl,&work,1,partword,_encodepart);
  105332. if(out){
  105333. for(i=0;i<ch;i++){
  105334. float *pcm=in[i];
  105335. float *sofar=out[i];
  105336. for(j=0,k=i;j<n;j++,k+=ch)
  105337. sofar[j]+=pcm[j]-work[k];
  105338. }
  105339. }
  105340. return(ret);
  105341. }else{
  105342. return(0);
  105343. }
  105344. }
  105345. int res2_inverse(vorbis_block *vb,vorbis_look_residue *vl,
  105346. float **in,int *nonzero,int ch){
  105347. long i,k,l,s;
  105348. vorbis_look_residue0 *look=(vorbis_look_residue0 *)vl;
  105349. vorbis_info_residue0 *info=look->info;
  105350. int samples_per_partition=info->grouping;
  105351. int partitions_per_word=look->phrasebook->dim;
  105352. int n=info->end-info->begin;
  105353. int partvals=n/samples_per_partition;
  105354. int partwords=(partvals+partitions_per_word-1)/partitions_per_word;
  105355. int **partword=(int**)_vorbis_block_alloc(vb,partwords*sizeof(*partword));
  105356. for(i=0;i<ch;i++)if(nonzero[i])break;
  105357. if(i==ch)return(0); /* no nonzero vectors */
  105358. for(s=0;s<look->stages;s++){
  105359. for(i=0,l=0;i<partvals;l++){
  105360. if(s==0){
  105361. int temp=vorbis_book_decode(look->phrasebook,&vb->opb);
  105362. if(temp==-1)goto eopbreak;
  105363. partword[l]=look->decodemap[temp];
  105364. if(partword[l]==NULL)goto errout;
  105365. }
  105366. for(k=0;k<partitions_per_word && i<partvals;k++,i++)
  105367. if(info->secondstages[partword[l][k]]&(1<<s)){
  105368. codebook *stagebook=look->partbooks[partword[l][k]][s];
  105369. if(stagebook){
  105370. if(vorbis_book_decodevv_add(stagebook,in,
  105371. i*samples_per_partition+info->begin,ch,
  105372. &vb->opb,samples_per_partition)==-1)
  105373. goto eopbreak;
  105374. }
  105375. }
  105376. }
  105377. }
  105378. errout:
  105379. eopbreak:
  105380. return(0);
  105381. }
  105382. vorbis_func_residue residue0_exportbundle={
  105383. NULL,
  105384. &res0_unpack,
  105385. &res0_look,
  105386. &res0_free_info,
  105387. &res0_free_look,
  105388. NULL,
  105389. NULL,
  105390. &res0_inverse
  105391. };
  105392. vorbis_func_residue residue1_exportbundle={
  105393. &res0_pack,
  105394. &res0_unpack,
  105395. &res0_look,
  105396. &res0_free_info,
  105397. &res0_free_look,
  105398. &res1_class,
  105399. &res1_forward,
  105400. &res1_inverse
  105401. };
  105402. vorbis_func_residue residue2_exportbundle={
  105403. &res0_pack,
  105404. &res0_unpack,
  105405. &res0_look,
  105406. &res0_free_info,
  105407. &res0_free_look,
  105408. &res2_class,
  105409. &res2_forward,
  105410. &res2_inverse
  105411. };
  105412. #endif
  105413. /********* End of inlined file: res0.c *********/
  105414. /********* Start of inlined file: sharedbook.c *********/
  105415. /********* Start of inlined file: juce_OggVorbisHeader.h *********/
  105416. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  105417. // tasks..
  105418. #if JUCE_MSVC
  105419. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  105420. #endif
  105421. /********* End of inlined file: juce_OggVorbisHeader.h *********/
  105422. #if JUCE_USE_OGGVORBIS
  105423. #include <stdlib.h>
  105424. #include <math.h>
  105425. #include <string.h>
  105426. int _ilog(unsigned int v){
  105427. int ret=0;
  105428. while(v){
  105429. ret++;
  105430. v>>=1;
  105431. }
  105432. return(ret);
  105433. }
  105434. #define VQ_FEXP 10
  105435. #define VQ_FMAN 21
  105436. #define VQ_FEXP_BIAS 768 /* bias toward values smaller than 1. */
  105437. long _float32_pack(float val){
  105438. int sign=0;
  105439. long exp;
  105440. long mant;
  105441. if(val<0){
  105442. sign=0x80000000;
  105443. val= -val;
  105444. }
  105445. exp= floor(log(val)/log(2.f));
  105446. mant=rint(ldexp(val,(VQ_FMAN-1)-exp));
  105447. exp=(exp+VQ_FEXP_BIAS)<<VQ_FMAN;
  105448. return(sign|exp|mant);
  105449. }
  105450. float _float32_unpack(long val){
  105451. double mant=val&0x1fffff;
  105452. int sign=val&0x80000000;
  105453. long exp =(val&0x7fe00000L)>>VQ_FMAN;
  105454. if(sign)mant= -mant;
  105455. return(ldexp(mant,exp-(VQ_FMAN-1)-VQ_FEXP_BIAS));
  105456. }
  105457. ogg_uint32_t *_make_words(long *l,long n,long sparsecount){
  105458. long i,j,count=0;
  105459. ogg_uint32_t marker[33];
  105460. ogg_uint32_t *r=(ogg_uint32_t*)_ogg_malloc((sparsecount?sparsecount:n)*sizeof(*r));
  105461. memset(marker,0,sizeof(marker));
  105462. for(i=0;i<n;i++){
  105463. long length=l[i];
  105464. if(length>0){
  105465. ogg_uint32_t entry=marker[length];
  105466. if(length<32 && (entry>>length)){
  105467. _ogg_free(r);
  105468. return(NULL);
  105469. }
  105470. r[count++]=entry;
  105471. {
  105472. for(j=length;j>0;j--){
  105473. if(marker[j]&1){
  105474. if(j==1)
  105475. marker[1]++;
  105476. else
  105477. marker[j]=marker[j-1]<<1;
  105478. break; /* invariant says next upper marker would already
  105479. have been moved if it was on the same path */
  105480. }
  105481. marker[j]++;
  105482. }
  105483. }
  105484. for(j=length+1;j<33;j++)
  105485. if((marker[j]>>1) == entry){
  105486. entry=marker[j];
  105487. marker[j]=marker[j-1]<<1;
  105488. }else
  105489. break;
  105490. }else
  105491. if(sparsecount==0)count++;
  105492. }
  105493. for(i=0,count=0;i<n;i++){
  105494. ogg_uint32_t temp=0;
  105495. for(j=0;j<l[i];j++){
  105496. temp<<=1;
  105497. temp|=(r[count]>>j)&1;
  105498. }
  105499. if(sparsecount){
  105500. if(l[i])
  105501. r[count++]=temp;
  105502. }else
  105503. r[count++]=temp;
  105504. }
  105505. return(r);
  105506. }
  105507. long _book_maptype1_quantvals(const static_codebook *b){
  105508. long vals=floor(pow((float)b->entries,1.f/b->dim));
  105509. while(1){
  105510. long acc=1;
  105511. long acc1=1;
  105512. int i;
  105513. for(i=0;i<b->dim;i++){
  105514. acc*=vals;
  105515. acc1*=vals+1;
  105516. }
  105517. if(acc<=b->entries && acc1>b->entries){
  105518. return(vals);
  105519. }else{
  105520. if(acc>b->entries){
  105521. vals--;
  105522. }else{
  105523. vals++;
  105524. }
  105525. }
  105526. }
  105527. }
  105528. float *_book_unquantize(const static_codebook *b,int n,int *sparsemap){
  105529. long j,k,count=0;
  105530. if(b->maptype==1 || b->maptype==2){
  105531. int quantvals;
  105532. float mindel=_float32_unpack(b->q_min);
  105533. float delta=_float32_unpack(b->q_delta);
  105534. float *r=(float*)_ogg_calloc(n*b->dim,sizeof(*r));
  105535. switch(b->maptype){
  105536. case 1:
  105537. quantvals=_book_maptype1_quantvals(b);
  105538. for(j=0;j<b->entries;j++){
  105539. if((sparsemap && b->lengthlist[j]) || !sparsemap){
  105540. float last=0.f;
  105541. int indexdiv=1;
  105542. for(k=0;k<b->dim;k++){
  105543. int index= (j/indexdiv)%quantvals;
  105544. float val=b->quantlist[index];
  105545. val=fabs(val)*delta+mindel+last;
  105546. if(b->q_sequencep)last=val;
  105547. if(sparsemap)
  105548. r[sparsemap[count]*b->dim+k]=val;
  105549. else
  105550. r[count*b->dim+k]=val;
  105551. indexdiv*=quantvals;
  105552. }
  105553. count++;
  105554. }
  105555. }
  105556. break;
  105557. case 2:
  105558. for(j=0;j<b->entries;j++){
  105559. if((sparsemap && b->lengthlist[j]) || !sparsemap){
  105560. float last=0.f;
  105561. for(k=0;k<b->dim;k++){
  105562. float val=b->quantlist[j*b->dim+k];
  105563. val=fabs(val)*delta+mindel+last;
  105564. if(b->q_sequencep)last=val;
  105565. if(sparsemap)
  105566. r[sparsemap[count]*b->dim+k]=val;
  105567. else
  105568. r[count*b->dim+k]=val;
  105569. }
  105570. count++;
  105571. }
  105572. }
  105573. break;
  105574. }
  105575. return(r);
  105576. }
  105577. return(NULL);
  105578. }
  105579. void vorbis_staticbook_clear(static_codebook *b){
  105580. if(b->allocedp){
  105581. if(b->quantlist)_ogg_free(b->quantlist);
  105582. if(b->lengthlist)_ogg_free(b->lengthlist);
  105583. if(b->nearest_tree){
  105584. _ogg_free(b->nearest_tree->ptr0);
  105585. _ogg_free(b->nearest_tree->ptr1);
  105586. _ogg_free(b->nearest_tree->p);
  105587. _ogg_free(b->nearest_tree->q);
  105588. memset(b->nearest_tree,0,sizeof(*b->nearest_tree));
  105589. _ogg_free(b->nearest_tree);
  105590. }
  105591. if(b->thresh_tree){
  105592. _ogg_free(b->thresh_tree->quantthresh);
  105593. _ogg_free(b->thresh_tree->quantmap);
  105594. memset(b->thresh_tree,0,sizeof(*b->thresh_tree));
  105595. _ogg_free(b->thresh_tree);
  105596. }
  105597. memset(b,0,sizeof(*b));
  105598. }
  105599. }
  105600. void vorbis_staticbook_destroy(static_codebook *b){
  105601. if(b->allocedp){
  105602. vorbis_staticbook_clear(b);
  105603. _ogg_free(b);
  105604. }
  105605. }
  105606. void vorbis_book_clear(codebook *b){
  105607. if(b->valuelist)_ogg_free(b->valuelist);
  105608. if(b->codelist)_ogg_free(b->codelist);
  105609. if(b->dec_index)_ogg_free(b->dec_index);
  105610. if(b->dec_codelengths)_ogg_free(b->dec_codelengths);
  105611. if(b->dec_firsttable)_ogg_free(b->dec_firsttable);
  105612. memset(b,0,sizeof(*b));
  105613. }
  105614. int vorbis_book_init_encode(codebook *c,const static_codebook *s){
  105615. memset(c,0,sizeof(*c));
  105616. c->c=s;
  105617. c->entries=s->entries;
  105618. c->used_entries=s->entries;
  105619. c->dim=s->dim;
  105620. c->codelist=_make_words(s->lengthlist,s->entries,0);
  105621. c->valuelist=_book_unquantize(s,s->entries,NULL);
  105622. return(0);
  105623. }
  105624. static int sort32a(const void *a,const void *b){
  105625. return ( **(ogg_uint32_t **)a>**(ogg_uint32_t **)b)-
  105626. ( **(ogg_uint32_t **)a<**(ogg_uint32_t **)b);
  105627. }
  105628. int vorbis_book_init_decode(codebook *c,const static_codebook *s){
  105629. int i,j,n=0,tabn;
  105630. int *sortindex;
  105631. memset(c,0,sizeof(*c));
  105632. for(i=0;i<s->entries;i++)
  105633. if(s->lengthlist[i]>0)
  105634. n++;
  105635. c->entries=s->entries;
  105636. c->used_entries=n;
  105637. c->dim=s->dim;
  105638. {
  105639. ogg_uint32_t *codes=_make_words(s->lengthlist,s->entries,c->used_entries);
  105640. ogg_uint32_t **codep=(ogg_uint32_t**)alloca(sizeof(*codep)*n);
  105641. if(codes==NULL)goto err_out;
  105642. for(i=0;i<n;i++){
  105643. codes[i]=ogg_bitreverse(codes[i]);
  105644. codep[i]=codes+i;
  105645. }
  105646. qsort(codep,n,sizeof(*codep),sort32a);
  105647. sortindex=(int*)alloca(n*sizeof(*sortindex));
  105648. c->codelist=(ogg_uint32_t*)_ogg_malloc(n*sizeof(*c->codelist));
  105649. for(i=0;i<n;i++){
  105650. int position=codep[i]-codes;
  105651. sortindex[position]=i;
  105652. }
  105653. for(i=0;i<n;i++)
  105654. c->codelist[sortindex[i]]=codes[i];
  105655. _ogg_free(codes);
  105656. }
  105657. c->valuelist=_book_unquantize(s,n,sortindex);
  105658. c->dec_index=(int*)_ogg_malloc(n*sizeof(*c->dec_index));
  105659. for(n=0,i=0;i<s->entries;i++)
  105660. if(s->lengthlist[i]>0)
  105661. c->dec_index[sortindex[n++]]=i;
  105662. c->dec_codelengths=(char*)_ogg_malloc(n*sizeof(*c->dec_codelengths));
  105663. for(n=0,i=0;i<s->entries;i++)
  105664. if(s->lengthlist[i]>0)
  105665. c->dec_codelengths[sortindex[n++]]=s->lengthlist[i];
  105666. c->dec_firsttablen=_ilog(c->used_entries)-4; /* this is magic */
  105667. if(c->dec_firsttablen<5)c->dec_firsttablen=5;
  105668. if(c->dec_firsttablen>8)c->dec_firsttablen=8;
  105669. tabn=1<<c->dec_firsttablen;
  105670. c->dec_firsttable=(ogg_uint32_t*)_ogg_calloc(tabn,sizeof(*c->dec_firsttable));
  105671. c->dec_maxlength=0;
  105672. for(i=0;i<n;i++){
  105673. if(c->dec_maxlength<c->dec_codelengths[i])
  105674. c->dec_maxlength=c->dec_codelengths[i];
  105675. if(c->dec_codelengths[i]<=c->dec_firsttablen){
  105676. ogg_uint32_t orig=ogg_bitreverse(c->codelist[i]);
  105677. for(j=0;j<(1<<(c->dec_firsttablen-c->dec_codelengths[i]));j++)
  105678. c->dec_firsttable[orig|(j<<c->dec_codelengths[i])]=i+1;
  105679. }
  105680. }
  105681. {
  105682. ogg_uint32_t mask=0xfffffffeUL<<(31-c->dec_firsttablen);
  105683. long lo=0,hi=0;
  105684. for(i=0;i<tabn;i++){
  105685. ogg_uint32_t word=i<<(32-c->dec_firsttablen);
  105686. if(c->dec_firsttable[ogg_bitreverse(word)]==0){
  105687. while((lo+1)<n && c->codelist[lo+1]<=word)lo++;
  105688. while( hi<n && word>=(c->codelist[hi]&mask))hi++;
  105689. {
  105690. unsigned long loval=lo;
  105691. unsigned long hival=n-hi;
  105692. if(loval>0x7fff)loval=0x7fff;
  105693. if(hival>0x7fff)hival=0x7fff;
  105694. c->dec_firsttable[ogg_bitreverse(word)]=
  105695. 0x80000000UL | (loval<<15) | hival;
  105696. }
  105697. }
  105698. }
  105699. }
  105700. return(0);
  105701. err_out:
  105702. vorbis_book_clear(c);
  105703. return(-1);
  105704. }
  105705. static float _dist(int el,float *ref, float *b,int step){
  105706. int i;
  105707. float acc=0.f;
  105708. for(i=0;i<el;i++){
  105709. float val=(ref[i]-b[i*step]);
  105710. acc+=val*val;
  105711. }
  105712. return(acc);
  105713. }
  105714. int _best(codebook *book, float *a, int step){
  105715. encode_aux_threshmatch *tt=book->c->thresh_tree;
  105716. #if 0
  105717. encode_aux_nearestmatch *nt=book->c->nearest_tree;
  105718. encode_aux_pigeonhole *pt=book->c->pigeon_tree;
  105719. #endif
  105720. int dim=book->dim;
  105721. int k,o;
  105722. if(tt){
  105723. int index=0,i;
  105724. for(k=0,o=step*(dim-1);k<dim;k++,o-=step){
  105725. i=tt->threshvals>>1;
  105726. if(a[o]<tt->quantthresh[i]){
  105727. for(;i>0;i--)
  105728. if(a[o]>=tt->quantthresh[i-1])
  105729. break;
  105730. }else{
  105731. for(i++;i<tt->threshvals-1;i++)
  105732. if(a[o]<tt->quantthresh[i])break;
  105733. }
  105734. index=(index*tt->quantvals)+tt->quantmap[i];
  105735. }
  105736. if(book->c->lengthlist[index]>0) /* is this unused? If so, we'll
  105737. use a decision tree after all
  105738. and fall through*/
  105739. return(index);
  105740. }
  105741. #if 0
  105742. if(pt){
  105743. const static_codebook *c=book->c;
  105744. int i,besti=-1;
  105745. float best=0.f;
  105746. int entry=0;
  105747. if(c->q_sequencep){
  105748. int pv;
  105749. long mul=1;
  105750. float qlast=0;
  105751. for(k=0,o=0;k<dim;k++,o+=step){
  105752. pv=(int)((a[o]-qlast-pt->min)/pt->del);
  105753. if(pv<0 || pv>=pt->mapentries)break;
  105754. entry+=pt->pigeonmap[pv]*mul;
  105755. mul*=pt->quantvals;
  105756. qlast+=pv*pt->del+pt->min;
  105757. }
  105758. }else{
  105759. for(k=0,o=step*(dim-1);k<dim;k++,o-=step){
  105760. int pv=(int)((a[o]-pt->min)/pt->del);
  105761. if(pv<0 || pv>=pt->mapentries)break;
  105762. entry=entry*pt->quantvals+pt->pigeonmap[pv];
  105763. }
  105764. }
  105765. if(k==dim && pt->fitlength[entry]){
  105766. long *list=pt->fitlist+pt->fitmap[entry];
  105767. for(i=0;i<pt->fitlength[entry];i++){
  105768. float this=_dist(dim,book->valuelist+list[i]*dim,a,step);
  105769. if(besti==-1 || this<best){
  105770. best=this;
  105771. besti=list[i];
  105772. }
  105773. }
  105774. return(besti);
  105775. }
  105776. }
  105777. if(nt){
  105778. while(1){
  105779. float c=0.f;
  105780. float *p=book->valuelist+nt->p[ptr];
  105781. float *q=book->valuelist+nt->q[ptr];
  105782. for(k=0,o=0;k<dim;k++,o+=step)
  105783. c+=(p[k]-q[k])*(a[o]-(p[k]+q[k])*.5);
  105784. if(c>0.f) /* in A */
  105785. ptr= -nt->ptr0[ptr];
  105786. else /* in B */
  105787. ptr= -nt->ptr1[ptr];
  105788. if(ptr<=0)break;
  105789. }
  105790. return(-ptr);
  105791. }
  105792. #endif
  105793. {
  105794. const static_codebook *c=book->c;
  105795. int i,besti=-1;
  105796. float best=0.f;
  105797. float *e=book->valuelist;
  105798. for(i=0;i<book->entries;i++){
  105799. if(c->lengthlist[i]>0){
  105800. float thisx=_dist(dim,e,a,step);
  105801. if(besti==-1 || thisx<best){
  105802. best=thisx;
  105803. besti=i;
  105804. }
  105805. }
  105806. e+=dim;
  105807. }
  105808. return(besti);
  105809. }
  105810. }
  105811. long vorbis_book_codeword(codebook *book,int entry){
  105812. if(book->c) /* only use with encode; decode optimizations are
  105813. allowed to break this */
  105814. return book->codelist[entry];
  105815. return -1;
  105816. }
  105817. long vorbis_book_codelen(codebook *book,int entry){
  105818. if(book->c) /* only use with encode; decode optimizations are
  105819. allowed to break this */
  105820. return book->c->lengthlist[entry];
  105821. return -1;
  105822. }
  105823. #ifdef _V_SELFTEST
  105824. #include <stdio.h>
  105825. static long full_quantlist1[]={0,1,2,3, 4,5,6,7, 8,3,6,1};
  105826. static long partial_quantlist1[]={0,7,2};
  105827. static_codebook test1={
  105828. 4,16,
  105829. NULL,
  105830. 0,
  105831. 0,0,0,0,
  105832. NULL,
  105833. NULL,NULL
  105834. };
  105835. static float *test1_result=NULL;
  105836. static_codebook test2={
  105837. 4,3,
  105838. NULL,
  105839. 2,
  105840. -533200896,1611661312,4,0,
  105841. full_quantlist1,
  105842. NULL,NULL
  105843. };
  105844. static float test2_result[]={-3,-2,-1,0, 1,2,3,4, 5,0,3,-2};
  105845. static_codebook test3={
  105846. 4,3,
  105847. NULL,
  105848. 2,
  105849. -533200896,1611661312,4,1,
  105850. full_quantlist1,
  105851. NULL,NULL
  105852. };
  105853. static float test3_result[]={-3,-5,-6,-6, 1,3,6,10, 5,5,8,6};
  105854. static_codebook test4={
  105855. 3,27,
  105856. NULL,
  105857. 1,
  105858. -533200896,1611661312,4,0,
  105859. partial_quantlist1,
  105860. NULL,NULL
  105861. };
  105862. static float test4_result[]={-3,-3,-3, 4,-3,-3, -1,-3,-3,
  105863. -3, 4,-3, 4, 4,-3, -1, 4,-3,
  105864. -3,-1,-3, 4,-1,-3, -1,-1,-3,
  105865. -3,-3, 4, 4,-3, 4, -1,-3, 4,
  105866. -3, 4, 4, 4, 4, 4, -1, 4, 4,
  105867. -3,-1, 4, 4,-1, 4, -1,-1, 4,
  105868. -3,-3,-1, 4,-3,-1, -1,-3,-1,
  105869. -3, 4,-1, 4, 4,-1, -1, 4,-1,
  105870. -3,-1,-1, 4,-1,-1, -1,-1,-1};
  105871. static_codebook test5={
  105872. 3,27,
  105873. NULL,
  105874. 1,
  105875. -533200896,1611661312,4,1,
  105876. partial_quantlist1,
  105877. NULL,NULL
  105878. };
  105879. static float test5_result[]={-3,-6,-9, 4, 1,-2, -1,-4,-7,
  105880. -3, 1,-2, 4, 8, 5, -1, 3, 0,
  105881. -3,-4,-7, 4, 3, 0, -1,-2,-5,
  105882. -3,-6,-2, 4, 1, 5, -1,-4, 0,
  105883. -3, 1, 5, 4, 8,12, -1, 3, 7,
  105884. -3,-4, 0, 4, 3, 7, -1,-2, 2,
  105885. -3,-6,-7, 4, 1, 0, -1,-4,-5,
  105886. -3, 1, 0, 4, 8, 7, -1, 3, 2,
  105887. -3,-4,-5, 4, 3, 2, -1,-2,-3};
  105888. void run_test(static_codebook *b,float *comp){
  105889. float *out=_book_unquantize(b,b->entries,NULL);
  105890. int i;
  105891. if(comp){
  105892. if(!out){
  105893. fprintf(stderr,"_book_unquantize incorrectly returned NULL\n");
  105894. exit(1);
  105895. }
  105896. for(i=0;i<b->entries*b->dim;i++)
  105897. if(fabs(out[i]-comp[i])>.0001){
  105898. fprintf(stderr,"disagreement in unquantized and reference data:\n"
  105899. "position %d, %g != %g\n",i,out[i],comp[i]);
  105900. exit(1);
  105901. }
  105902. }else{
  105903. if(out){
  105904. fprintf(stderr,"_book_unquantize returned a value array: \n"
  105905. " correct result should have been NULL\n");
  105906. exit(1);
  105907. }
  105908. }
  105909. }
  105910. int main(){
  105911. fprintf(stderr,"Dequant test 1... ");
  105912. run_test(&test1,test1_result);
  105913. fprintf(stderr,"OK\nDequant test 2... ");
  105914. run_test(&test2,test2_result);
  105915. fprintf(stderr,"OK\nDequant test 3... ");
  105916. run_test(&test3,test3_result);
  105917. fprintf(stderr,"OK\nDequant test 4... ");
  105918. run_test(&test4,test4_result);
  105919. fprintf(stderr,"OK\nDequant test 5... ");
  105920. run_test(&test5,test5_result);
  105921. fprintf(stderr,"OK\n\n");
  105922. return(0);
  105923. }
  105924. #endif
  105925. #endif
  105926. /********* End of inlined file: sharedbook.c *********/
  105927. /********* Start of inlined file: smallft.c *********/
  105928. /********* Start of inlined file: juce_OggVorbisHeader.h *********/
  105929. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  105930. // tasks..
  105931. #if JUCE_MSVC
  105932. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  105933. #endif
  105934. /********* End of inlined file: juce_OggVorbisHeader.h *********/
  105935. #if JUCE_USE_OGGVORBIS
  105936. #include <stdlib.h>
  105937. #include <string.h>
  105938. #include <math.h>
  105939. static void drfti1(int n, float *wa, int *ifac){
  105940. static int ntryh[4] = { 4,2,3,5 };
  105941. static float tpi = 6.28318530717958648f;
  105942. float arg,argh,argld,fi;
  105943. int ntry=0,i,j=-1;
  105944. int k1, l1, l2, ib;
  105945. int ld, ii, ip, is, nq, nr;
  105946. int ido, ipm, nfm1;
  105947. int nl=n;
  105948. int nf=0;
  105949. L101:
  105950. j++;
  105951. if (j < 4)
  105952. ntry=ntryh[j];
  105953. else
  105954. ntry+=2;
  105955. L104:
  105956. nq=nl/ntry;
  105957. nr=nl-ntry*nq;
  105958. if (nr!=0) goto L101;
  105959. nf++;
  105960. ifac[nf+1]=ntry;
  105961. nl=nq;
  105962. if(ntry!=2)goto L107;
  105963. if(nf==1)goto L107;
  105964. for (i=1;i<nf;i++){
  105965. ib=nf-i+1;
  105966. ifac[ib+1]=ifac[ib];
  105967. }
  105968. ifac[2] = 2;
  105969. L107:
  105970. if(nl!=1)goto L104;
  105971. ifac[0]=n;
  105972. ifac[1]=nf;
  105973. argh=tpi/n;
  105974. is=0;
  105975. nfm1=nf-1;
  105976. l1=1;
  105977. if(nfm1==0)return;
  105978. for (k1=0;k1<nfm1;k1++){
  105979. ip=ifac[k1+2];
  105980. ld=0;
  105981. l2=l1*ip;
  105982. ido=n/l2;
  105983. ipm=ip-1;
  105984. for (j=0;j<ipm;j++){
  105985. ld+=l1;
  105986. i=is;
  105987. argld=(float)ld*argh;
  105988. fi=0.f;
  105989. for (ii=2;ii<ido;ii+=2){
  105990. fi+=1.f;
  105991. arg=fi*argld;
  105992. wa[i++]=cos(arg);
  105993. wa[i++]=sin(arg);
  105994. }
  105995. is+=ido;
  105996. }
  105997. l1=l2;
  105998. }
  105999. }
  106000. static void fdrffti(int n, float *wsave, int *ifac){
  106001. if (n == 1) return;
  106002. drfti1(n, wsave+n, ifac);
  106003. }
  106004. static void dradf2(int ido,int l1,float *cc,float *ch,float *wa1){
  106005. int i,k;
  106006. float ti2,tr2;
  106007. int t0,t1,t2,t3,t4,t5,t6;
  106008. t1=0;
  106009. t0=(t2=l1*ido);
  106010. t3=ido<<1;
  106011. for(k=0;k<l1;k++){
  106012. ch[t1<<1]=cc[t1]+cc[t2];
  106013. ch[(t1<<1)+t3-1]=cc[t1]-cc[t2];
  106014. t1+=ido;
  106015. t2+=ido;
  106016. }
  106017. if(ido<2)return;
  106018. if(ido==2)goto L105;
  106019. t1=0;
  106020. t2=t0;
  106021. for(k=0;k<l1;k++){
  106022. t3=t2;
  106023. t4=(t1<<1)+(ido<<1);
  106024. t5=t1;
  106025. t6=t1+t1;
  106026. for(i=2;i<ido;i+=2){
  106027. t3+=2;
  106028. t4-=2;
  106029. t5+=2;
  106030. t6+=2;
  106031. tr2=wa1[i-2]*cc[t3-1]+wa1[i-1]*cc[t3];
  106032. ti2=wa1[i-2]*cc[t3]-wa1[i-1]*cc[t3-1];
  106033. ch[t6]=cc[t5]+ti2;
  106034. ch[t4]=ti2-cc[t5];
  106035. ch[t6-1]=cc[t5-1]+tr2;
  106036. ch[t4-1]=cc[t5-1]-tr2;
  106037. }
  106038. t1+=ido;
  106039. t2+=ido;
  106040. }
  106041. if(ido%2==1)return;
  106042. L105:
  106043. t3=(t2=(t1=ido)-1);
  106044. t2+=t0;
  106045. for(k=0;k<l1;k++){
  106046. ch[t1]=-cc[t2];
  106047. ch[t1-1]=cc[t3];
  106048. t1+=ido<<1;
  106049. t2+=ido;
  106050. t3+=ido;
  106051. }
  106052. }
  106053. static void dradf4(int ido,int l1,float *cc,float *ch,float *wa1,
  106054. float *wa2,float *wa3){
  106055. static float hsqt2 = .70710678118654752f;
  106056. int i,k,t0,t1,t2,t3,t4,t5,t6;
  106057. float ci2,ci3,ci4,cr2,cr3,cr4,ti1,ti2,ti3,ti4,tr1,tr2,tr3,tr4;
  106058. t0=l1*ido;
  106059. t1=t0;
  106060. t4=t1<<1;
  106061. t2=t1+(t1<<1);
  106062. t3=0;
  106063. for(k=0;k<l1;k++){
  106064. tr1=cc[t1]+cc[t2];
  106065. tr2=cc[t3]+cc[t4];
  106066. ch[t5=t3<<2]=tr1+tr2;
  106067. ch[(ido<<2)+t5-1]=tr2-tr1;
  106068. ch[(t5+=(ido<<1))-1]=cc[t3]-cc[t4];
  106069. ch[t5]=cc[t2]-cc[t1];
  106070. t1+=ido;
  106071. t2+=ido;
  106072. t3+=ido;
  106073. t4+=ido;
  106074. }
  106075. if(ido<2)return;
  106076. if(ido==2)goto L105;
  106077. t1=0;
  106078. for(k=0;k<l1;k++){
  106079. t2=t1;
  106080. t4=t1<<2;
  106081. t5=(t6=ido<<1)+t4;
  106082. for(i=2;i<ido;i+=2){
  106083. t3=(t2+=2);
  106084. t4+=2;
  106085. t5-=2;
  106086. t3+=t0;
  106087. cr2=wa1[i-2]*cc[t3-1]+wa1[i-1]*cc[t3];
  106088. ci2=wa1[i-2]*cc[t3]-wa1[i-1]*cc[t3-1];
  106089. t3+=t0;
  106090. cr3=wa2[i-2]*cc[t3-1]+wa2[i-1]*cc[t3];
  106091. ci3=wa2[i-2]*cc[t3]-wa2[i-1]*cc[t3-1];
  106092. t3+=t0;
  106093. cr4=wa3[i-2]*cc[t3-1]+wa3[i-1]*cc[t3];
  106094. ci4=wa3[i-2]*cc[t3]-wa3[i-1]*cc[t3-1];
  106095. tr1=cr2+cr4;
  106096. tr4=cr4-cr2;
  106097. ti1=ci2+ci4;
  106098. ti4=ci2-ci4;
  106099. ti2=cc[t2]+ci3;
  106100. ti3=cc[t2]-ci3;
  106101. tr2=cc[t2-1]+cr3;
  106102. tr3=cc[t2-1]-cr3;
  106103. ch[t4-1]=tr1+tr2;
  106104. ch[t4]=ti1+ti2;
  106105. ch[t5-1]=tr3-ti4;
  106106. ch[t5]=tr4-ti3;
  106107. ch[t4+t6-1]=ti4+tr3;
  106108. ch[t4+t6]=tr4+ti3;
  106109. ch[t5+t6-1]=tr2-tr1;
  106110. ch[t5+t6]=ti1-ti2;
  106111. }
  106112. t1+=ido;
  106113. }
  106114. if(ido&1)return;
  106115. L105:
  106116. t2=(t1=t0+ido-1)+(t0<<1);
  106117. t3=ido<<2;
  106118. t4=ido;
  106119. t5=ido<<1;
  106120. t6=ido;
  106121. for(k=0;k<l1;k++){
  106122. ti1=-hsqt2*(cc[t1]+cc[t2]);
  106123. tr1=hsqt2*(cc[t1]-cc[t2]);
  106124. ch[t4-1]=tr1+cc[t6-1];
  106125. ch[t4+t5-1]=cc[t6-1]-tr1;
  106126. ch[t4]=ti1-cc[t1+t0];
  106127. ch[t4+t5]=ti1+cc[t1+t0];
  106128. t1+=ido;
  106129. t2+=ido;
  106130. t4+=t3;
  106131. t6+=ido;
  106132. }
  106133. }
  106134. static void dradfg(int ido,int ip,int l1,int idl1,float *cc,float *c1,
  106135. float *c2,float *ch,float *ch2,float *wa){
  106136. static float tpi=6.283185307179586f;
  106137. int idij,ipph,i,j,k,l,ic,ik,is;
  106138. int t0,t1,t2,t3,t4,t5,t6,t7,t8,t9,t10;
  106139. float dc2,ai1,ai2,ar1,ar2,ds2;
  106140. int nbd;
  106141. float dcp,arg,dsp,ar1h,ar2h;
  106142. int idp2,ipp2;
  106143. arg=tpi/(float)ip;
  106144. dcp=cos(arg);
  106145. dsp=sin(arg);
  106146. ipph=(ip+1)>>1;
  106147. ipp2=ip;
  106148. idp2=ido;
  106149. nbd=(ido-1)>>1;
  106150. t0=l1*ido;
  106151. t10=ip*ido;
  106152. if(ido==1)goto L119;
  106153. for(ik=0;ik<idl1;ik++)ch2[ik]=c2[ik];
  106154. t1=0;
  106155. for(j=1;j<ip;j++){
  106156. t1+=t0;
  106157. t2=t1;
  106158. for(k=0;k<l1;k++){
  106159. ch[t2]=c1[t2];
  106160. t2+=ido;
  106161. }
  106162. }
  106163. is=-ido;
  106164. t1=0;
  106165. if(nbd>l1){
  106166. for(j=1;j<ip;j++){
  106167. t1+=t0;
  106168. is+=ido;
  106169. t2= -ido+t1;
  106170. for(k=0;k<l1;k++){
  106171. idij=is-1;
  106172. t2+=ido;
  106173. t3=t2;
  106174. for(i=2;i<ido;i+=2){
  106175. idij+=2;
  106176. t3+=2;
  106177. ch[t3-1]=wa[idij-1]*c1[t3-1]+wa[idij]*c1[t3];
  106178. ch[t3]=wa[idij-1]*c1[t3]-wa[idij]*c1[t3-1];
  106179. }
  106180. }
  106181. }
  106182. }else{
  106183. for(j=1;j<ip;j++){
  106184. is+=ido;
  106185. idij=is-1;
  106186. t1+=t0;
  106187. t2=t1;
  106188. for(i=2;i<ido;i+=2){
  106189. idij+=2;
  106190. t2+=2;
  106191. t3=t2;
  106192. for(k=0;k<l1;k++){
  106193. ch[t3-1]=wa[idij-1]*c1[t3-1]+wa[idij]*c1[t3];
  106194. ch[t3]=wa[idij-1]*c1[t3]-wa[idij]*c1[t3-1];
  106195. t3+=ido;
  106196. }
  106197. }
  106198. }
  106199. }
  106200. t1=0;
  106201. t2=ipp2*t0;
  106202. if(nbd<l1){
  106203. for(j=1;j<ipph;j++){
  106204. t1+=t0;
  106205. t2-=t0;
  106206. t3=t1;
  106207. t4=t2;
  106208. for(i=2;i<ido;i+=2){
  106209. t3+=2;
  106210. t4+=2;
  106211. t5=t3-ido;
  106212. t6=t4-ido;
  106213. for(k=0;k<l1;k++){
  106214. t5+=ido;
  106215. t6+=ido;
  106216. c1[t5-1]=ch[t5-1]+ch[t6-1];
  106217. c1[t6-1]=ch[t5]-ch[t6];
  106218. c1[t5]=ch[t5]+ch[t6];
  106219. c1[t6]=ch[t6-1]-ch[t5-1];
  106220. }
  106221. }
  106222. }
  106223. }else{
  106224. for(j=1;j<ipph;j++){
  106225. t1+=t0;
  106226. t2-=t0;
  106227. t3=t1;
  106228. t4=t2;
  106229. for(k=0;k<l1;k++){
  106230. t5=t3;
  106231. t6=t4;
  106232. for(i=2;i<ido;i+=2){
  106233. t5+=2;
  106234. t6+=2;
  106235. c1[t5-1]=ch[t5-1]+ch[t6-1];
  106236. c1[t6-1]=ch[t5]-ch[t6];
  106237. c1[t5]=ch[t5]+ch[t6];
  106238. c1[t6]=ch[t6-1]-ch[t5-1];
  106239. }
  106240. t3+=ido;
  106241. t4+=ido;
  106242. }
  106243. }
  106244. }
  106245. L119:
  106246. for(ik=0;ik<idl1;ik++)c2[ik]=ch2[ik];
  106247. t1=0;
  106248. t2=ipp2*idl1;
  106249. for(j=1;j<ipph;j++){
  106250. t1+=t0;
  106251. t2-=t0;
  106252. t3=t1-ido;
  106253. t4=t2-ido;
  106254. for(k=0;k<l1;k++){
  106255. t3+=ido;
  106256. t4+=ido;
  106257. c1[t3]=ch[t3]+ch[t4];
  106258. c1[t4]=ch[t4]-ch[t3];
  106259. }
  106260. }
  106261. ar1=1.f;
  106262. ai1=0.f;
  106263. t1=0;
  106264. t2=ipp2*idl1;
  106265. t3=(ip-1)*idl1;
  106266. for(l=1;l<ipph;l++){
  106267. t1+=idl1;
  106268. t2-=idl1;
  106269. ar1h=dcp*ar1-dsp*ai1;
  106270. ai1=dcp*ai1+dsp*ar1;
  106271. ar1=ar1h;
  106272. t4=t1;
  106273. t5=t2;
  106274. t6=t3;
  106275. t7=idl1;
  106276. for(ik=0;ik<idl1;ik++){
  106277. ch2[t4++]=c2[ik]+ar1*c2[t7++];
  106278. ch2[t5++]=ai1*c2[t6++];
  106279. }
  106280. dc2=ar1;
  106281. ds2=ai1;
  106282. ar2=ar1;
  106283. ai2=ai1;
  106284. t4=idl1;
  106285. t5=(ipp2-1)*idl1;
  106286. for(j=2;j<ipph;j++){
  106287. t4+=idl1;
  106288. t5-=idl1;
  106289. ar2h=dc2*ar2-ds2*ai2;
  106290. ai2=dc2*ai2+ds2*ar2;
  106291. ar2=ar2h;
  106292. t6=t1;
  106293. t7=t2;
  106294. t8=t4;
  106295. t9=t5;
  106296. for(ik=0;ik<idl1;ik++){
  106297. ch2[t6++]+=ar2*c2[t8++];
  106298. ch2[t7++]+=ai2*c2[t9++];
  106299. }
  106300. }
  106301. }
  106302. t1=0;
  106303. for(j=1;j<ipph;j++){
  106304. t1+=idl1;
  106305. t2=t1;
  106306. for(ik=0;ik<idl1;ik++)ch2[ik]+=c2[t2++];
  106307. }
  106308. if(ido<l1)goto L132;
  106309. t1=0;
  106310. t2=0;
  106311. for(k=0;k<l1;k++){
  106312. t3=t1;
  106313. t4=t2;
  106314. for(i=0;i<ido;i++)cc[t4++]=ch[t3++];
  106315. t1+=ido;
  106316. t2+=t10;
  106317. }
  106318. goto L135;
  106319. L132:
  106320. for(i=0;i<ido;i++){
  106321. t1=i;
  106322. t2=i;
  106323. for(k=0;k<l1;k++){
  106324. cc[t2]=ch[t1];
  106325. t1+=ido;
  106326. t2+=t10;
  106327. }
  106328. }
  106329. L135:
  106330. t1=0;
  106331. t2=ido<<1;
  106332. t3=0;
  106333. t4=ipp2*t0;
  106334. for(j=1;j<ipph;j++){
  106335. t1+=t2;
  106336. t3+=t0;
  106337. t4-=t0;
  106338. t5=t1;
  106339. t6=t3;
  106340. t7=t4;
  106341. for(k=0;k<l1;k++){
  106342. cc[t5-1]=ch[t6];
  106343. cc[t5]=ch[t7];
  106344. t5+=t10;
  106345. t6+=ido;
  106346. t7+=ido;
  106347. }
  106348. }
  106349. if(ido==1)return;
  106350. if(nbd<l1)goto L141;
  106351. t1=-ido;
  106352. t3=0;
  106353. t4=0;
  106354. t5=ipp2*t0;
  106355. for(j=1;j<ipph;j++){
  106356. t1+=t2;
  106357. t3+=t2;
  106358. t4+=t0;
  106359. t5-=t0;
  106360. t6=t1;
  106361. t7=t3;
  106362. t8=t4;
  106363. t9=t5;
  106364. for(k=0;k<l1;k++){
  106365. for(i=2;i<ido;i+=2){
  106366. ic=idp2-i;
  106367. cc[i+t7-1]=ch[i+t8-1]+ch[i+t9-1];
  106368. cc[ic+t6-1]=ch[i+t8-1]-ch[i+t9-1];
  106369. cc[i+t7]=ch[i+t8]+ch[i+t9];
  106370. cc[ic+t6]=ch[i+t9]-ch[i+t8];
  106371. }
  106372. t6+=t10;
  106373. t7+=t10;
  106374. t8+=ido;
  106375. t9+=ido;
  106376. }
  106377. }
  106378. return;
  106379. L141:
  106380. t1=-ido;
  106381. t3=0;
  106382. t4=0;
  106383. t5=ipp2*t0;
  106384. for(j=1;j<ipph;j++){
  106385. t1+=t2;
  106386. t3+=t2;
  106387. t4+=t0;
  106388. t5-=t0;
  106389. for(i=2;i<ido;i+=2){
  106390. t6=idp2+t1-i;
  106391. t7=i+t3;
  106392. t8=i+t4;
  106393. t9=i+t5;
  106394. for(k=0;k<l1;k++){
  106395. cc[t7-1]=ch[t8-1]+ch[t9-1];
  106396. cc[t6-1]=ch[t8-1]-ch[t9-1];
  106397. cc[t7]=ch[t8]+ch[t9];
  106398. cc[t6]=ch[t9]-ch[t8];
  106399. t6+=t10;
  106400. t7+=t10;
  106401. t8+=ido;
  106402. t9+=ido;
  106403. }
  106404. }
  106405. }
  106406. }
  106407. static void drftf1(int n,float *c,float *ch,float *wa,int *ifac){
  106408. int i,k1,l1,l2;
  106409. int na,kh,nf;
  106410. int ip,iw,ido,idl1,ix2,ix3;
  106411. nf=ifac[1];
  106412. na=1;
  106413. l2=n;
  106414. iw=n;
  106415. for(k1=0;k1<nf;k1++){
  106416. kh=nf-k1;
  106417. ip=ifac[kh+1];
  106418. l1=l2/ip;
  106419. ido=n/l2;
  106420. idl1=ido*l1;
  106421. iw-=(ip-1)*ido;
  106422. na=1-na;
  106423. if(ip!=4)goto L102;
  106424. ix2=iw+ido;
  106425. ix3=ix2+ido;
  106426. if(na!=0)
  106427. dradf4(ido,l1,ch,c,wa+iw-1,wa+ix2-1,wa+ix3-1);
  106428. else
  106429. dradf4(ido,l1,c,ch,wa+iw-1,wa+ix2-1,wa+ix3-1);
  106430. goto L110;
  106431. L102:
  106432. if(ip!=2)goto L104;
  106433. if(na!=0)goto L103;
  106434. dradf2(ido,l1,c,ch,wa+iw-1);
  106435. goto L110;
  106436. L103:
  106437. dradf2(ido,l1,ch,c,wa+iw-1);
  106438. goto L110;
  106439. L104:
  106440. if(ido==1)na=1-na;
  106441. if(na!=0)goto L109;
  106442. dradfg(ido,ip,l1,idl1,c,c,c,ch,ch,wa+iw-1);
  106443. na=1;
  106444. goto L110;
  106445. L109:
  106446. dradfg(ido,ip,l1,idl1,ch,ch,ch,c,c,wa+iw-1);
  106447. na=0;
  106448. L110:
  106449. l2=l1;
  106450. }
  106451. if(na==1)return;
  106452. for(i=0;i<n;i++)c[i]=ch[i];
  106453. }
  106454. static void dradb2(int ido,int l1,float *cc,float *ch,float *wa1){
  106455. int i,k,t0,t1,t2,t3,t4,t5,t6;
  106456. float ti2,tr2;
  106457. t0=l1*ido;
  106458. t1=0;
  106459. t2=0;
  106460. t3=(ido<<1)-1;
  106461. for(k=0;k<l1;k++){
  106462. ch[t1]=cc[t2]+cc[t3+t2];
  106463. ch[t1+t0]=cc[t2]-cc[t3+t2];
  106464. t2=(t1+=ido)<<1;
  106465. }
  106466. if(ido<2)return;
  106467. if(ido==2)goto L105;
  106468. t1=0;
  106469. t2=0;
  106470. for(k=0;k<l1;k++){
  106471. t3=t1;
  106472. t5=(t4=t2)+(ido<<1);
  106473. t6=t0+t1;
  106474. for(i=2;i<ido;i+=2){
  106475. t3+=2;
  106476. t4+=2;
  106477. t5-=2;
  106478. t6+=2;
  106479. ch[t3-1]=cc[t4-1]+cc[t5-1];
  106480. tr2=cc[t4-1]-cc[t5-1];
  106481. ch[t3]=cc[t4]-cc[t5];
  106482. ti2=cc[t4]+cc[t5];
  106483. ch[t6-1]=wa1[i-2]*tr2-wa1[i-1]*ti2;
  106484. ch[t6]=wa1[i-2]*ti2+wa1[i-1]*tr2;
  106485. }
  106486. t2=(t1+=ido)<<1;
  106487. }
  106488. if(ido%2==1)return;
  106489. L105:
  106490. t1=ido-1;
  106491. t2=ido-1;
  106492. for(k=0;k<l1;k++){
  106493. ch[t1]=cc[t2]+cc[t2];
  106494. ch[t1+t0]=-(cc[t2+1]+cc[t2+1]);
  106495. t1+=ido;
  106496. t2+=ido<<1;
  106497. }
  106498. }
  106499. static void dradb3(int ido,int l1,float *cc,float *ch,float *wa1,
  106500. float *wa2){
  106501. static float taur = -.5f;
  106502. static float taui = .8660254037844386f;
  106503. int i,k,t0,t1,t2,t3,t4,t5,t6,t7,t8,t9,t10;
  106504. float ci2,ci3,di2,di3,cr2,cr3,dr2,dr3,ti2,tr2;
  106505. t0=l1*ido;
  106506. t1=0;
  106507. t2=t0<<1;
  106508. t3=ido<<1;
  106509. t4=ido+(ido<<1);
  106510. t5=0;
  106511. for(k=0;k<l1;k++){
  106512. tr2=cc[t3-1]+cc[t3-1];
  106513. cr2=cc[t5]+(taur*tr2);
  106514. ch[t1]=cc[t5]+tr2;
  106515. ci3=taui*(cc[t3]+cc[t3]);
  106516. ch[t1+t0]=cr2-ci3;
  106517. ch[t1+t2]=cr2+ci3;
  106518. t1+=ido;
  106519. t3+=t4;
  106520. t5+=t4;
  106521. }
  106522. if(ido==1)return;
  106523. t1=0;
  106524. t3=ido<<1;
  106525. for(k=0;k<l1;k++){
  106526. t7=t1+(t1<<1);
  106527. t6=(t5=t7+t3);
  106528. t8=t1;
  106529. t10=(t9=t1+t0)+t0;
  106530. for(i=2;i<ido;i+=2){
  106531. t5+=2;
  106532. t6-=2;
  106533. t7+=2;
  106534. t8+=2;
  106535. t9+=2;
  106536. t10+=2;
  106537. tr2=cc[t5-1]+cc[t6-1];
  106538. cr2=cc[t7-1]+(taur*tr2);
  106539. ch[t8-1]=cc[t7-1]+tr2;
  106540. ti2=cc[t5]-cc[t6];
  106541. ci2=cc[t7]+(taur*ti2);
  106542. ch[t8]=cc[t7]+ti2;
  106543. cr3=taui*(cc[t5-1]-cc[t6-1]);
  106544. ci3=taui*(cc[t5]+cc[t6]);
  106545. dr2=cr2-ci3;
  106546. dr3=cr2+ci3;
  106547. di2=ci2+cr3;
  106548. di3=ci2-cr3;
  106549. ch[t9-1]=wa1[i-2]*dr2-wa1[i-1]*di2;
  106550. ch[t9]=wa1[i-2]*di2+wa1[i-1]*dr2;
  106551. ch[t10-1]=wa2[i-2]*dr3-wa2[i-1]*di3;
  106552. ch[t10]=wa2[i-2]*di3+wa2[i-1]*dr3;
  106553. }
  106554. t1+=ido;
  106555. }
  106556. }
  106557. static void dradb4(int ido,int l1,float *cc,float *ch,float *wa1,
  106558. float *wa2,float *wa3){
  106559. static float sqrt2=1.414213562373095f;
  106560. int i,k,t0,t1,t2,t3,t4,t5,t6,t7,t8;
  106561. float ci2,ci3,ci4,cr2,cr3,cr4,ti1,ti2,ti3,ti4,tr1,tr2,tr3,tr4;
  106562. t0=l1*ido;
  106563. t1=0;
  106564. t2=ido<<2;
  106565. t3=0;
  106566. t6=ido<<1;
  106567. for(k=0;k<l1;k++){
  106568. t4=t3+t6;
  106569. t5=t1;
  106570. tr3=cc[t4-1]+cc[t4-1];
  106571. tr4=cc[t4]+cc[t4];
  106572. tr1=cc[t3]-cc[(t4+=t6)-1];
  106573. tr2=cc[t3]+cc[t4-1];
  106574. ch[t5]=tr2+tr3;
  106575. ch[t5+=t0]=tr1-tr4;
  106576. ch[t5+=t0]=tr2-tr3;
  106577. ch[t5+=t0]=tr1+tr4;
  106578. t1+=ido;
  106579. t3+=t2;
  106580. }
  106581. if(ido<2)return;
  106582. if(ido==2)goto L105;
  106583. t1=0;
  106584. for(k=0;k<l1;k++){
  106585. t5=(t4=(t3=(t2=t1<<2)+t6))+t6;
  106586. t7=t1;
  106587. for(i=2;i<ido;i+=2){
  106588. t2+=2;
  106589. t3+=2;
  106590. t4-=2;
  106591. t5-=2;
  106592. t7+=2;
  106593. ti1=cc[t2]+cc[t5];
  106594. ti2=cc[t2]-cc[t5];
  106595. ti3=cc[t3]-cc[t4];
  106596. tr4=cc[t3]+cc[t4];
  106597. tr1=cc[t2-1]-cc[t5-1];
  106598. tr2=cc[t2-1]+cc[t5-1];
  106599. ti4=cc[t3-1]-cc[t4-1];
  106600. tr3=cc[t3-1]+cc[t4-1];
  106601. ch[t7-1]=tr2+tr3;
  106602. cr3=tr2-tr3;
  106603. ch[t7]=ti2+ti3;
  106604. ci3=ti2-ti3;
  106605. cr2=tr1-tr4;
  106606. cr4=tr1+tr4;
  106607. ci2=ti1+ti4;
  106608. ci4=ti1-ti4;
  106609. ch[(t8=t7+t0)-1]=wa1[i-2]*cr2-wa1[i-1]*ci2;
  106610. ch[t8]=wa1[i-2]*ci2+wa1[i-1]*cr2;
  106611. ch[(t8+=t0)-1]=wa2[i-2]*cr3-wa2[i-1]*ci3;
  106612. ch[t8]=wa2[i-2]*ci3+wa2[i-1]*cr3;
  106613. ch[(t8+=t0)-1]=wa3[i-2]*cr4-wa3[i-1]*ci4;
  106614. ch[t8]=wa3[i-2]*ci4+wa3[i-1]*cr4;
  106615. }
  106616. t1+=ido;
  106617. }
  106618. if(ido%2 == 1)return;
  106619. L105:
  106620. t1=ido;
  106621. t2=ido<<2;
  106622. t3=ido-1;
  106623. t4=ido+(ido<<1);
  106624. for(k=0;k<l1;k++){
  106625. t5=t3;
  106626. ti1=cc[t1]+cc[t4];
  106627. ti2=cc[t4]-cc[t1];
  106628. tr1=cc[t1-1]-cc[t4-1];
  106629. tr2=cc[t1-1]+cc[t4-1];
  106630. ch[t5]=tr2+tr2;
  106631. ch[t5+=t0]=sqrt2*(tr1-ti1);
  106632. ch[t5+=t0]=ti2+ti2;
  106633. ch[t5+=t0]=-sqrt2*(tr1+ti1);
  106634. t3+=ido;
  106635. t1+=t2;
  106636. t4+=t2;
  106637. }
  106638. }
  106639. static void dradbg(int ido,int ip,int l1,int idl1,float *cc,float *c1,
  106640. float *c2,float *ch,float *ch2,float *wa){
  106641. static float tpi=6.283185307179586f;
  106642. int idij,ipph,i,j,k,l,ik,is,t0,t1,t2,t3,t4,t5,t6,t7,t8,t9,t10,
  106643. t11,t12;
  106644. float dc2,ai1,ai2,ar1,ar2,ds2;
  106645. int nbd;
  106646. float dcp,arg,dsp,ar1h,ar2h;
  106647. int ipp2;
  106648. t10=ip*ido;
  106649. t0=l1*ido;
  106650. arg=tpi/(float)ip;
  106651. dcp=cos(arg);
  106652. dsp=sin(arg);
  106653. nbd=(ido-1)>>1;
  106654. ipp2=ip;
  106655. ipph=(ip+1)>>1;
  106656. if(ido<l1)goto L103;
  106657. t1=0;
  106658. t2=0;
  106659. for(k=0;k<l1;k++){
  106660. t3=t1;
  106661. t4=t2;
  106662. for(i=0;i<ido;i++){
  106663. ch[t3]=cc[t4];
  106664. t3++;
  106665. t4++;
  106666. }
  106667. t1+=ido;
  106668. t2+=t10;
  106669. }
  106670. goto L106;
  106671. L103:
  106672. t1=0;
  106673. for(i=0;i<ido;i++){
  106674. t2=t1;
  106675. t3=t1;
  106676. for(k=0;k<l1;k++){
  106677. ch[t2]=cc[t3];
  106678. t2+=ido;
  106679. t3+=t10;
  106680. }
  106681. t1++;
  106682. }
  106683. L106:
  106684. t1=0;
  106685. t2=ipp2*t0;
  106686. t7=(t5=ido<<1);
  106687. for(j=1;j<ipph;j++){
  106688. t1+=t0;
  106689. t2-=t0;
  106690. t3=t1;
  106691. t4=t2;
  106692. t6=t5;
  106693. for(k=0;k<l1;k++){
  106694. ch[t3]=cc[t6-1]+cc[t6-1];
  106695. ch[t4]=cc[t6]+cc[t6];
  106696. t3+=ido;
  106697. t4+=ido;
  106698. t6+=t10;
  106699. }
  106700. t5+=t7;
  106701. }
  106702. if (ido == 1)goto L116;
  106703. if(nbd<l1)goto L112;
  106704. t1=0;
  106705. t2=ipp2*t0;
  106706. t7=0;
  106707. for(j=1;j<ipph;j++){
  106708. t1+=t0;
  106709. t2-=t0;
  106710. t3=t1;
  106711. t4=t2;
  106712. t7+=(ido<<1);
  106713. t8=t7;
  106714. for(k=0;k<l1;k++){
  106715. t5=t3;
  106716. t6=t4;
  106717. t9=t8;
  106718. t11=t8;
  106719. for(i=2;i<ido;i+=2){
  106720. t5+=2;
  106721. t6+=2;
  106722. t9+=2;
  106723. t11-=2;
  106724. ch[t5-1]=cc[t9-1]+cc[t11-1];
  106725. ch[t6-1]=cc[t9-1]-cc[t11-1];
  106726. ch[t5]=cc[t9]-cc[t11];
  106727. ch[t6]=cc[t9]+cc[t11];
  106728. }
  106729. t3+=ido;
  106730. t4+=ido;
  106731. t8+=t10;
  106732. }
  106733. }
  106734. goto L116;
  106735. L112:
  106736. t1=0;
  106737. t2=ipp2*t0;
  106738. t7=0;
  106739. for(j=1;j<ipph;j++){
  106740. t1+=t0;
  106741. t2-=t0;
  106742. t3=t1;
  106743. t4=t2;
  106744. t7+=(ido<<1);
  106745. t8=t7;
  106746. t9=t7;
  106747. for(i=2;i<ido;i+=2){
  106748. t3+=2;
  106749. t4+=2;
  106750. t8+=2;
  106751. t9-=2;
  106752. t5=t3;
  106753. t6=t4;
  106754. t11=t8;
  106755. t12=t9;
  106756. for(k=0;k<l1;k++){
  106757. ch[t5-1]=cc[t11-1]+cc[t12-1];
  106758. ch[t6-1]=cc[t11-1]-cc[t12-1];
  106759. ch[t5]=cc[t11]-cc[t12];
  106760. ch[t6]=cc[t11]+cc[t12];
  106761. t5+=ido;
  106762. t6+=ido;
  106763. t11+=t10;
  106764. t12+=t10;
  106765. }
  106766. }
  106767. }
  106768. L116:
  106769. ar1=1.f;
  106770. ai1=0.f;
  106771. t1=0;
  106772. t9=(t2=ipp2*idl1);
  106773. t3=(ip-1)*idl1;
  106774. for(l=1;l<ipph;l++){
  106775. t1+=idl1;
  106776. t2-=idl1;
  106777. ar1h=dcp*ar1-dsp*ai1;
  106778. ai1=dcp*ai1+dsp*ar1;
  106779. ar1=ar1h;
  106780. t4=t1;
  106781. t5=t2;
  106782. t6=0;
  106783. t7=idl1;
  106784. t8=t3;
  106785. for(ik=0;ik<idl1;ik++){
  106786. c2[t4++]=ch2[t6++]+ar1*ch2[t7++];
  106787. c2[t5++]=ai1*ch2[t8++];
  106788. }
  106789. dc2=ar1;
  106790. ds2=ai1;
  106791. ar2=ar1;
  106792. ai2=ai1;
  106793. t6=idl1;
  106794. t7=t9-idl1;
  106795. for(j=2;j<ipph;j++){
  106796. t6+=idl1;
  106797. t7-=idl1;
  106798. ar2h=dc2*ar2-ds2*ai2;
  106799. ai2=dc2*ai2+ds2*ar2;
  106800. ar2=ar2h;
  106801. t4=t1;
  106802. t5=t2;
  106803. t11=t6;
  106804. t12=t7;
  106805. for(ik=0;ik<idl1;ik++){
  106806. c2[t4++]+=ar2*ch2[t11++];
  106807. c2[t5++]+=ai2*ch2[t12++];
  106808. }
  106809. }
  106810. }
  106811. t1=0;
  106812. for(j=1;j<ipph;j++){
  106813. t1+=idl1;
  106814. t2=t1;
  106815. for(ik=0;ik<idl1;ik++)ch2[ik]+=ch2[t2++];
  106816. }
  106817. t1=0;
  106818. t2=ipp2*t0;
  106819. for(j=1;j<ipph;j++){
  106820. t1+=t0;
  106821. t2-=t0;
  106822. t3=t1;
  106823. t4=t2;
  106824. for(k=0;k<l1;k++){
  106825. ch[t3]=c1[t3]-c1[t4];
  106826. ch[t4]=c1[t3]+c1[t4];
  106827. t3+=ido;
  106828. t4+=ido;
  106829. }
  106830. }
  106831. if(ido==1)goto L132;
  106832. if(nbd<l1)goto L128;
  106833. t1=0;
  106834. t2=ipp2*t0;
  106835. for(j=1;j<ipph;j++){
  106836. t1+=t0;
  106837. t2-=t0;
  106838. t3=t1;
  106839. t4=t2;
  106840. for(k=0;k<l1;k++){
  106841. t5=t3;
  106842. t6=t4;
  106843. for(i=2;i<ido;i+=2){
  106844. t5+=2;
  106845. t6+=2;
  106846. ch[t5-1]=c1[t5-1]-c1[t6];
  106847. ch[t6-1]=c1[t5-1]+c1[t6];
  106848. ch[t5]=c1[t5]+c1[t6-1];
  106849. ch[t6]=c1[t5]-c1[t6-1];
  106850. }
  106851. t3+=ido;
  106852. t4+=ido;
  106853. }
  106854. }
  106855. goto L132;
  106856. L128:
  106857. t1=0;
  106858. t2=ipp2*t0;
  106859. for(j=1;j<ipph;j++){
  106860. t1+=t0;
  106861. t2-=t0;
  106862. t3=t1;
  106863. t4=t2;
  106864. for(i=2;i<ido;i+=2){
  106865. t3+=2;
  106866. t4+=2;
  106867. t5=t3;
  106868. t6=t4;
  106869. for(k=0;k<l1;k++){
  106870. ch[t5-1]=c1[t5-1]-c1[t6];
  106871. ch[t6-1]=c1[t5-1]+c1[t6];
  106872. ch[t5]=c1[t5]+c1[t6-1];
  106873. ch[t6]=c1[t5]-c1[t6-1];
  106874. t5+=ido;
  106875. t6+=ido;
  106876. }
  106877. }
  106878. }
  106879. L132:
  106880. if(ido==1)return;
  106881. for(ik=0;ik<idl1;ik++)c2[ik]=ch2[ik];
  106882. t1=0;
  106883. for(j=1;j<ip;j++){
  106884. t2=(t1+=t0);
  106885. for(k=0;k<l1;k++){
  106886. c1[t2]=ch[t2];
  106887. t2+=ido;
  106888. }
  106889. }
  106890. if(nbd>l1)goto L139;
  106891. is= -ido-1;
  106892. t1=0;
  106893. for(j=1;j<ip;j++){
  106894. is+=ido;
  106895. t1+=t0;
  106896. idij=is;
  106897. t2=t1;
  106898. for(i=2;i<ido;i+=2){
  106899. t2+=2;
  106900. idij+=2;
  106901. t3=t2;
  106902. for(k=0;k<l1;k++){
  106903. c1[t3-1]=wa[idij-1]*ch[t3-1]-wa[idij]*ch[t3];
  106904. c1[t3]=wa[idij-1]*ch[t3]+wa[idij]*ch[t3-1];
  106905. t3+=ido;
  106906. }
  106907. }
  106908. }
  106909. return;
  106910. L139:
  106911. is= -ido-1;
  106912. t1=0;
  106913. for(j=1;j<ip;j++){
  106914. is+=ido;
  106915. t1+=t0;
  106916. t2=t1;
  106917. for(k=0;k<l1;k++){
  106918. idij=is;
  106919. t3=t2;
  106920. for(i=2;i<ido;i+=2){
  106921. idij+=2;
  106922. t3+=2;
  106923. c1[t3-1]=wa[idij-1]*ch[t3-1]-wa[idij]*ch[t3];
  106924. c1[t3]=wa[idij-1]*ch[t3]+wa[idij]*ch[t3-1];
  106925. }
  106926. t2+=ido;
  106927. }
  106928. }
  106929. }
  106930. static void drftb1(int n, float *c, float *ch, float *wa, int *ifac){
  106931. int i,k1,l1,l2;
  106932. int na;
  106933. int nf,ip,iw,ix2,ix3,ido,idl1;
  106934. nf=ifac[1];
  106935. na=0;
  106936. l1=1;
  106937. iw=1;
  106938. for(k1=0;k1<nf;k1++){
  106939. ip=ifac[k1 + 2];
  106940. l2=ip*l1;
  106941. ido=n/l2;
  106942. idl1=ido*l1;
  106943. if(ip!=4)goto L103;
  106944. ix2=iw+ido;
  106945. ix3=ix2+ido;
  106946. if(na!=0)
  106947. dradb4(ido,l1,ch,c,wa+iw-1,wa+ix2-1,wa+ix3-1);
  106948. else
  106949. dradb4(ido,l1,c,ch,wa+iw-1,wa+ix2-1,wa+ix3-1);
  106950. na=1-na;
  106951. goto L115;
  106952. L103:
  106953. if(ip!=2)goto L106;
  106954. if(na!=0)
  106955. dradb2(ido,l1,ch,c,wa+iw-1);
  106956. else
  106957. dradb2(ido,l1,c,ch,wa+iw-1);
  106958. na=1-na;
  106959. goto L115;
  106960. L106:
  106961. if(ip!=3)goto L109;
  106962. ix2=iw+ido;
  106963. if(na!=0)
  106964. dradb3(ido,l1,ch,c,wa+iw-1,wa+ix2-1);
  106965. else
  106966. dradb3(ido,l1,c,ch,wa+iw-1,wa+ix2-1);
  106967. na=1-na;
  106968. goto L115;
  106969. L109:
  106970. if(na!=0)
  106971. dradbg(ido,ip,l1,idl1,ch,ch,ch,c,c,wa+iw-1);
  106972. else
  106973. dradbg(ido,ip,l1,idl1,c,c,c,ch,ch,wa+iw-1);
  106974. if(ido==1)na=1-na;
  106975. L115:
  106976. l1=l2;
  106977. iw+=(ip-1)*ido;
  106978. }
  106979. if(na==0)return;
  106980. for(i=0;i<n;i++)c[i]=ch[i];
  106981. }
  106982. void drft_forward(drft_lookup *l,float *data){
  106983. if(l->n==1)return;
  106984. drftf1(l->n,data,l->trigcache,l->trigcache+l->n,l->splitcache);
  106985. }
  106986. void drft_backward(drft_lookup *l,float *data){
  106987. if (l->n==1)return;
  106988. drftb1(l->n,data,l->trigcache,l->trigcache+l->n,l->splitcache);
  106989. }
  106990. void drft_init(drft_lookup *l,int n){
  106991. l->n=n;
  106992. l->trigcache=(float*)_ogg_calloc(3*n,sizeof(*l->trigcache));
  106993. l->splitcache=(int*)_ogg_calloc(32,sizeof(*l->splitcache));
  106994. fdrffti(n, l->trigcache, l->splitcache);
  106995. }
  106996. void drft_clear(drft_lookup *l){
  106997. if(l){
  106998. if(l->trigcache)_ogg_free(l->trigcache);
  106999. if(l->splitcache)_ogg_free(l->splitcache);
  107000. memset(l,0,sizeof(*l));
  107001. }
  107002. }
  107003. #endif
  107004. /********* End of inlined file: smallft.c *********/
  107005. /********* Start of inlined file: synthesis.c *********/
  107006. /********* Start of inlined file: juce_OggVorbisHeader.h *********/
  107007. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  107008. // tasks..
  107009. #if JUCE_MSVC
  107010. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  107011. #endif
  107012. /********* End of inlined file: juce_OggVorbisHeader.h *********/
  107013. #if JUCE_USE_OGGVORBIS
  107014. #include <stdio.h>
  107015. int vorbis_synthesis(vorbis_block *vb,ogg_packet *op){
  107016. vorbis_dsp_state *vd=vb->vd;
  107017. private_state *b=(private_state*)vd->backend_state;
  107018. vorbis_info *vi=vd->vi;
  107019. codec_setup_info *ci=(codec_setup_info*) vi->codec_setup;
  107020. oggpack_buffer *opb=&vb->opb;
  107021. int type,mode,i;
  107022. _vorbis_block_ripcord(vb);
  107023. oggpack_readinit(opb,op->packet,op->bytes);
  107024. if(oggpack_read(opb,1)!=0){
  107025. return(OV_ENOTAUDIO);
  107026. }
  107027. mode=oggpack_read(opb,b->modebits);
  107028. if(mode==-1)return(OV_EBADPACKET);
  107029. vb->mode=mode;
  107030. vb->W=ci->mode_param[mode]->blockflag;
  107031. if(vb->W){
  107032. vb->lW=oggpack_read(opb,1);
  107033. vb->nW=oggpack_read(opb,1);
  107034. if(vb->nW==-1) return(OV_EBADPACKET);
  107035. }else{
  107036. vb->lW=0;
  107037. vb->nW=0;
  107038. }
  107039. vb->granulepos=op->granulepos;
  107040. vb->sequence=op->packetno;
  107041. vb->eofflag=op->e_o_s;
  107042. vb->pcmend=ci->blocksizes[vb->W];
  107043. vb->pcm=(float**)_vorbis_block_alloc(vb,sizeof(*vb->pcm)*vi->channels);
  107044. for(i=0;i<vi->channels;i++)
  107045. vb->pcm[i]=(float*)_vorbis_block_alloc(vb,vb->pcmend*sizeof(*vb->pcm[i]));
  107046. type=ci->map_type[ci->mode_param[mode]->mapping];
  107047. return(_mapping_P[type]->inverse(vb,ci->map_param[ci->mode_param[mode]->
  107048. mapping]));
  107049. }
  107050. int vorbis_synthesis_trackonly(vorbis_block *vb,ogg_packet *op){
  107051. vorbis_dsp_state *vd=vb->vd;
  107052. private_state *b=(private_state*)vd->backend_state;
  107053. vorbis_info *vi=vd->vi;
  107054. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  107055. oggpack_buffer *opb=&vb->opb;
  107056. int mode;
  107057. _vorbis_block_ripcord(vb);
  107058. oggpack_readinit(opb,op->packet,op->bytes);
  107059. if(oggpack_read(opb,1)!=0){
  107060. return(OV_ENOTAUDIO);
  107061. }
  107062. mode=oggpack_read(opb,b->modebits);
  107063. if(mode==-1)return(OV_EBADPACKET);
  107064. vb->mode=mode;
  107065. vb->W=ci->mode_param[mode]->blockflag;
  107066. if(vb->W){
  107067. vb->lW=oggpack_read(opb,1);
  107068. vb->nW=oggpack_read(opb,1);
  107069. if(vb->nW==-1) return(OV_EBADPACKET);
  107070. }else{
  107071. vb->lW=0;
  107072. vb->nW=0;
  107073. }
  107074. vb->granulepos=op->granulepos;
  107075. vb->sequence=op->packetno;
  107076. vb->eofflag=op->e_o_s;
  107077. vb->pcmend=0;
  107078. vb->pcm=NULL;
  107079. return(0);
  107080. }
  107081. long vorbis_packet_blocksize(vorbis_info *vi,ogg_packet *op){
  107082. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  107083. oggpack_buffer opb;
  107084. int mode;
  107085. oggpack_readinit(&opb,op->packet,op->bytes);
  107086. if(oggpack_read(&opb,1)!=0){
  107087. return(OV_ENOTAUDIO);
  107088. }
  107089. {
  107090. int modebits=0;
  107091. int v=ci->modes;
  107092. while(v>1){
  107093. modebits++;
  107094. v>>=1;
  107095. }
  107096. mode=oggpack_read(&opb,modebits);
  107097. }
  107098. if(mode==-1)return(OV_EBADPACKET);
  107099. return(ci->blocksizes[ci->mode_param[mode]->blockflag]);
  107100. }
  107101. int vorbis_synthesis_halfrate(vorbis_info *vi,int flag){
  107102. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  107103. if(ci->blocksizes[0]<=64 && flag)return -1;
  107104. ci->halfrate_flag=(flag?1:0);
  107105. return 0;
  107106. }
  107107. int vorbis_synthesis_halfrate_p(vorbis_info *vi){
  107108. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  107109. return ci->halfrate_flag;
  107110. }
  107111. #endif
  107112. /********* End of inlined file: synthesis.c *********/
  107113. /********* Start of inlined file: vorbisenc.c *********/
  107114. /********* Start of inlined file: juce_OggVorbisHeader.h *********/
  107115. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  107116. // tasks..
  107117. #if JUCE_MSVC
  107118. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  107119. #endif
  107120. /********* End of inlined file: juce_OggVorbisHeader.h *********/
  107121. #if JUCE_USE_OGGVORBIS
  107122. #include <stdlib.h>
  107123. #include <string.h>
  107124. #include <math.h>
  107125. typedef struct {
  107126. static_codebook *books[12][3];
  107127. } static_bookblock;
  107128. typedef struct {
  107129. int res_type;
  107130. int limit_type; /* 0 lowpass limited, 1 point stereo limited */
  107131. vorbis_info_residue0 *res;
  107132. static_codebook *book_aux;
  107133. static_codebook *book_aux_managed;
  107134. static_bookblock *books_base;
  107135. static_bookblock *books_base_managed;
  107136. } vorbis_residue_template;
  107137. typedef struct {
  107138. vorbis_info_mapping0 *map;
  107139. vorbis_residue_template *res;
  107140. } vorbis_mapping_template;
  107141. typedef struct vp_adjblock{
  107142. int block[P_BANDS];
  107143. } vp_adjblock;
  107144. typedef struct {
  107145. int data[NOISE_COMPAND_LEVELS];
  107146. } compandblock;
  107147. typedef struct {
  107148. int att[P_NOISECURVES];
  107149. float boost;
  107150. float decay;
  107151. } att3;
  107152. typedef struct { int data[P_NOISECURVES]; } adj3;
  107153. typedef struct {
  107154. int pre[PACKETBLOBS];
  107155. int post[PACKETBLOBS];
  107156. float kHz[PACKETBLOBS];
  107157. float lowpasskHz[PACKETBLOBS];
  107158. } adj_stereo;
  107159. typedef struct {
  107160. int lo;
  107161. int hi;
  107162. int fixed;
  107163. } noiseguard;
  107164. typedef struct {
  107165. int data[P_NOISECURVES][17];
  107166. } noise3;
  107167. typedef struct {
  107168. int mappings;
  107169. double *rate_mapping;
  107170. double *quality_mapping;
  107171. int coupling_restriction;
  107172. long samplerate_min_restriction;
  107173. long samplerate_max_restriction;
  107174. int *blocksize_short;
  107175. int *blocksize_long;
  107176. att3 *psy_tone_masteratt;
  107177. int *psy_tone_0dB;
  107178. int *psy_tone_dBsuppress;
  107179. vp_adjblock *psy_tone_adj_impulse;
  107180. vp_adjblock *psy_tone_adj_long;
  107181. vp_adjblock *psy_tone_adj_other;
  107182. noiseguard *psy_noiseguards;
  107183. noise3 *psy_noise_bias_impulse;
  107184. noise3 *psy_noise_bias_padding;
  107185. noise3 *psy_noise_bias_trans;
  107186. noise3 *psy_noise_bias_long;
  107187. int *psy_noise_dBsuppress;
  107188. compandblock *psy_noise_compand;
  107189. double *psy_noise_compand_short_mapping;
  107190. double *psy_noise_compand_long_mapping;
  107191. int *psy_noise_normal_start[2];
  107192. int *psy_noise_normal_partition[2];
  107193. double *psy_noise_normal_thresh;
  107194. int *psy_ath_float;
  107195. int *psy_ath_abs;
  107196. double *psy_lowpass;
  107197. vorbis_info_psy_global *global_params;
  107198. double *global_mapping;
  107199. adj_stereo *stereo_modes;
  107200. static_codebook ***floor_books;
  107201. vorbis_info_floor1 *floor_params;
  107202. int *floor_short_mapping;
  107203. int *floor_long_mapping;
  107204. vorbis_mapping_template *maps;
  107205. } ve_setup_data_template;
  107206. static vorbis_info_mode _mode_template[2]={
  107207. {0,0,0,0},
  107208. {1,0,0,1}
  107209. };
  107210. static vorbis_info_mapping0 _map_nominal[2]={
  107211. {1, {0,0}, {0}, {0}, 1,{0},{1}},
  107212. {1, {0,0}, {1}, {1}, 1,{0},{1}}
  107213. };
  107214. /********* Start of inlined file: setup_44.h *********/
  107215. /********* Start of inlined file: floor_all.h *********/
  107216. /********* Start of inlined file: floor_books.h *********/
  107217. static long _huff_lengthlist_line_256x7_0sub1[] = {
  107218. 0, 2, 3, 3, 3, 3, 4, 3, 4,
  107219. };
  107220. static static_codebook _huff_book_line_256x7_0sub1 = {
  107221. 1, 9,
  107222. _huff_lengthlist_line_256x7_0sub1,
  107223. 0, 0, 0, 0, 0,
  107224. NULL,
  107225. NULL,
  107226. NULL,
  107227. NULL,
  107228. 0
  107229. };
  107230. static long _huff_lengthlist_line_256x7_0sub2[] = {
  107231. 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 4, 3, 4, 3, 5, 3,
  107232. 6, 3, 6, 4, 6, 4, 7, 5, 7,
  107233. };
  107234. static static_codebook _huff_book_line_256x7_0sub2 = {
  107235. 1, 25,
  107236. _huff_lengthlist_line_256x7_0sub2,
  107237. 0, 0, 0, 0, 0,
  107238. NULL,
  107239. NULL,
  107240. NULL,
  107241. NULL,
  107242. 0
  107243. };
  107244. static long _huff_lengthlist_line_256x7_0sub3[] = {
  107245. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107246. 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 5, 2, 5, 3, 5, 3,
  107247. 6, 3, 6, 4, 7, 6, 7, 8, 7, 9, 8, 9, 9, 9,10, 9,
  107248. 11,13,11,13,10,10,13,13,13,13,13,13,12,12,12,12,
  107249. };
  107250. static static_codebook _huff_book_line_256x7_0sub3 = {
  107251. 1, 64,
  107252. _huff_lengthlist_line_256x7_0sub3,
  107253. 0, 0, 0, 0, 0,
  107254. NULL,
  107255. NULL,
  107256. NULL,
  107257. NULL,
  107258. 0
  107259. };
  107260. static long _huff_lengthlist_line_256x7_1sub1[] = {
  107261. 0, 3, 3, 3, 3, 2, 4, 3, 4,
  107262. };
  107263. static static_codebook _huff_book_line_256x7_1sub1 = {
  107264. 1, 9,
  107265. _huff_lengthlist_line_256x7_1sub1,
  107266. 0, 0, 0, 0, 0,
  107267. NULL,
  107268. NULL,
  107269. NULL,
  107270. NULL,
  107271. 0
  107272. };
  107273. static long _huff_lengthlist_line_256x7_1sub2[] = {
  107274. 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 3, 3, 4, 3, 4, 4,
  107275. 5, 4, 6, 5, 6, 7, 6, 8, 8,
  107276. };
  107277. static static_codebook _huff_book_line_256x7_1sub2 = {
  107278. 1, 25,
  107279. _huff_lengthlist_line_256x7_1sub2,
  107280. 0, 0, 0, 0, 0,
  107281. NULL,
  107282. NULL,
  107283. NULL,
  107284. NULL,
  107285. 0
  107286. };
  107287. static long _huff_lengthlist_line_256x7_1sub3[] = {
  107288. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107289. 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 2, 4, 3, 6, 3, 7,
  107290. 3, 8, 5, 8, 6, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  107291. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 7,
  107292. };
  107293. static static_codebook _huff_book_line_256x7_1sub3 = {
  107294. 1, 64,
  107295. _huff_lengthlist_line_256x7_1sub3,
  107296. 0, 0, 0, 0, 0,
  107297. NULL,
  107298. NULL,
  107299. NULL,
  107300. NULL,
  107301. 0
  107302. };
  107303. static long _huff_lengthlist_line_256x7_class0[] = {
  107304. 7, 5, 5, 9, 9, 6, 6, 9,12, 8, 7, 8,11, 8, 9,15,
  107305. 6, 3, 3, 7, 7, 4, 3, 6, 9, 6, 5, 6, 8, 6, 8,15,
  107306. 8, 5, 5, 9, 8, 5, 4, 6,10, 7, 5, 5,11, 8, 7,15,
  107307. 14,15,13,13,13,13, 8,11,15,10, 7, 6,11, 9,10,15,
  107308. };
  107309. static static_codebook _huff_book_line_256x7_class0 = {
  107310. 1, 64,
  107311. _huff_lengthlist_line_256x7_class0,
  107312. 0, 0, 0, 0, 0,
  107313. NULL,
  107314. NULL,
  107315. NULL,
  107316. NULL,
  107317. 0
  107318. };
  107319. static long _huff_lengthlist_line_256x7_class1[] = {
  107320. 5, 6, 8,15, 6, 9,10,15,10,11,12,15,15,15,15,15,
  107321. 4, 6, 7,15, 6, 7, 8,15, 9, 8, 9,15,15,15,15,15,
  107322. 6, 8, 9,15, 7, 7, 8,15,10, 9,10,15,15,15,15,15,
  107323. 15,13,15,15,15,10,11,15,15,13,13,15,15,15,15,15,
  107324. 4, 6, 7,15, 6, 8, 9,15,10,10,12,15,15,15,15,15,
  107325. 2, 5, 6,15, 5, 6, 7,15, 8, 6, 7,15,15,15,15,15,
  107326. 5, 6, 8,15, 5, 6, 7,15, 9, 6, 7,15,15,15,15,15,
  107327. 14,12,13,15,12,10,11,15,15,15,15,15,15,15,15,15,
  107328. 7, 8, 9,15, 9,10,10,15,15,14,14,15,15,15,15,15,
  107329. 5, 6, 7,15, 7, 8, 9,15,12, 9,10,15,15,15,15,15,
  107330. 7, 7, 9,15, 7, 7, 8,15,12, 8, 9,15,15,15,15,15,
  107331. 13,13,14,15,12,11,12,15,15,15,15,15,15,15,15,15,
  107332. 15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,
  107333. 13,13,13,15,15,15,15,15,15,15,15,15,15,15,15,15,
  107334. 15,12,13,15,15,12,13,15,15,14,15,15,15,15,15,15,
  107335. 15,15,15,15,15,15,13,15,15,15,15,15,15,15,15,15,
  107336. };
  107337. static static_codebook _huff_book_line_256x7_class1 = {
  107338. 1, 256,
  107339. _huff_lengthlist_line_256x7_class1,
  107340. 0, 0, 0, 0, 0,
  107341. NULL,
  107342. NULL,
  107343. NULL,
  107344. NULL,
  107345. 0
  107346. };
  107347. static long _huff_lengthlist_line_512x17_0sub0[] = {
  107348. 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
  107349. 5, 6, 5, 6, 6, 6, 6, 5, 6, 6, 7, 6, 7, 6, 7, 6,
  107350. 7, 6, 8, 7, 8, 7, 8, 7, 8, 7, 8, 7, 9, 7, 9, 7,
  107351. 9, 7, 9, 8, 9, 8,10, 8,10, 8,10, 7,10, 6,10, 8,
  107352. 10, 8,11, 7,10, 7,11, 8,11,11,12,12,11,11,12,11,
  107353. 13,11,13,11,13,12,15,12,13,13,14,14,14,14,14,15,
  107354. 15,15,16,14,17,19,19,18,18,18,18,18,18,18,18,18,
  107355. 18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,
  107356. };
  107357. static static_codebook _huff_book_line_512x17_0sub0 = {
  107358. 1, 128,
  107359. _huff_lengthlist_line_512x17_0sub0,
  107360. 0, 0, 0, 0, 0,
  107361. NULL,
  107362. NULL,
  107363. NULL,
  107364. NULL,
  107365. 0
  107366. };
  107367. static long _huff_lengthlist_line_512x17_1sub0[] = {
  107368. 2, 4, 5, 4, 5, 4, 5, 4, 5, 5, 5, 5, 5, 5, 6, 5,
  107369. 6, 5, 6, 6, 7, 6, 7, 6, 8, 7, 8, 7, 8, 7, 8, 7,
  107370. };
  107371. static static_codebook _huff_book_line_512x17_1sub0 = {
  107372. 1, 32,
  107373. _huff_lengthlist_line_512x17_1sub0,
  107374. 0, 0, 0, 0, 0,
  107375. NULL,
  107376. NULL,
  107377. NULL,
  107378. NULL,
  107379. 0
  107380. };
  107381. static long _huff_lengthlist_line_512x17_1sub1[] = {
  107382. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107383. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107384. 4, 3, 5, 3, 5, 4, 5, 4, 5, 4, 5, 5, 5, 5, 6, 5,
  107385. 6, 5, 7, 5, 8, 6, 8, 6, 8, 6, 8, 6, 8, 7, 9, 7,
  107386. 9, 7,11, 9,11,11,12,11,14,12,14,16,14,16,13,16,
  107387. 14,16,12,15,13,16,14,16,13,14,12,15,13,15,13,13,
  107388. 13,15,12,14,14,15,13,15,12,15,15,15,15,15,15,15,
  107389. 15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,
  107390. };
  107391. static static_codebook _huff_book_line_512x17_1sub1 = {
  107392. 1, 128,
  107393. _huff_lengthlist_line_512x17_1sub1,
  107394. 0, 0, 0, 0, 0,
  107395. NULL,
  107396. NULL,
  107397. NULL,
  107398. NULL,
  107399. 0
  107400. };
  107401. static long _huff_lengthlist_line_512x17_2sub1[] = {
  107402. 0, 4, 5, 4, 4, 4, 5, 4, 4, 4, 5, 4, 5, 4, 5, 3,
  107403. 5, 3,
  107404. };
  107405. static static_codebook _huff_book_line_512x17_2sub1 = {
  107406. 1, 18,
  107407. _huff_lengthlist_line_512x17_2sub1,
  107408. 0, 0, 0, 0, 0,
  107409. NULL,
  107410. NULL,
  107411. NULL,
  107412. NULL,
  107413. 0
  107414. };
  107415. static long _huff_lengthlist_line_512x17_2sub2[] = {
  107416. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107417. 0, 0, 4, 3, 4, 3, 4, 4, 5, 4, 5, 4, 6, 4, 6, 5,
  107418. 6, 5, 7, 5, 7, 6, 8, 6, 8, 6, 8, 7, 8, 7, 9, 7,
  107419. 9, 8,
  107420. };
  107421. static static_codebook _huff_book_line_512x17_2sub2 = {
  107422. 1, 50,
  107423. _huff_lengthlist_line_512x17_2sub2,
  107424. 0, 0, 0, 0, 0,
  107425. NULL,
  107426. NULL,
  107427. NULL,
  107428. NULL,
  107429. 0
  107430. };
  107431. static long _huff_lengthlist_line_512x17_2sub3[] = {
  107432. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107433. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107434. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107435. 0, 0, 3, 3, 3, 3, 4, 3, 4, 4, 5, 5, 6, 6, 7, 7,
  107436. 7, 8, 8,11, 8, 9, 9, 9,10,11,11,11, 9,10,10,11,
  107437. 11,11,11,10,10,10,10,10,10,10,10,10,10,10,10,10,
  107438. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  107439. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  107440. };
  107441. static static_codebook _huff_book_line_512x17_2sub3 = {
  107442. 1, 128,
  107443. _huff_lengthlist_line_512x17_2sub3,
  107444. 0, 0, 0, 0, 0,
  107445. NULL,
  107446. NULL,
  107447. NULL,
  107448. NULL,
  107449. 0
  107450. };
  107451. static long _huff_lengthlist_line_512x17_3sub1[] = {
  107452. 0, 4, 4, 4, 4, 4, 4, 3, 4, 4, 4, 4, 4, 5, 4, 5,
  107453. 5, 5,
  107454. };
  107455. static static_codebook _huff_book_line_512x17_3sub1 = {
  107456. 1, 18,
  107457. _huff_lengthlist_line_512x17_3sub1,
  107458. 0, 0, 0, 0, 0,
  107459. NULL,
  107460. NULL,
  107461. NULL,
  107462. NULL,
  107463. 0
  107464. };
  107465. static long _huff_lengthlist_line_512x17_3sub2[] = {
  107466. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107467. 0, 0, 2, 3, 3, 4, 3, 5, 4, 6, 4, 6, 5, 7, 6, 7,
  107468. 6, 8, 6, 8, 7, 9, 8,10, 8,12, 9,13,10,15,10,15,
  107469. 11,14,
  107470. };
  107471. static static_codebook _huff_book_line_512x17_3sub2 = {
  107472. 1, 50,
  107473. _huff_lengthlist_line_512x17_3sub2,
  107474. 0, 0, 0, 0, 0,
  107475. NULL,
  107476. NULL,
  107477. NULL,
  107478. NULL,
  107479. 0
  107480. };
  107481. static long _huff_lengthlist_line_512x17_3sub3[] = {
  107482. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107483. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107484. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107485. 0, 0, 4, 8, 4, 8, 4, 8, 4, 8, 5, 8, 5, 8, 6, 8,
  107486. 4, 8, 4, 8, 5, 8, 5, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  107487. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  107488. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  107489. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  107490. };
  107491. static static_codebook _huff_book_line_512x17_3sub3 = {
  107492. 1, 128,
  107493. _huff_lengthlist_line_512x17_3sub3,
  107494. 0, 0, 0, 0, 0,
  107495. NULL,
  107496. NULL,
  107497. NULL,
  107498. NULL,
  107499. 0
  107500. };
  107501. static long _huff_lengthlist_line_512x17_class1[] = {
  107502. 1, 2, 3, 6, 5, 4, 7, 7,
  107503. };
  107504. static static_codebook _huff_book_line_512x17_class1 = {
  107505. 1, 8,
  107506. _huff_lengthlist_line_512x17_class1,
  107507. 0, 0, 0, 0, 0,
  107508. NULL,
  107509. NULL,
  107510. NULL,
  107511. NULL,
  107512. 0
  107513. };
  107514. static long _huff_lengthlist_line_512x17_class2[] = {
  107515. 3, 3, 3,14, 5, 4, 4,11, 8, 6, 6,10,17,12,11,17,
  107516. 6, 5, 5,15, 5, 3, 4,11, 8, 5, 5, 8,16, 9,10,14,
  107517. 10, 8, 9,17, 8, 6, 6,13,10, 7, 7,10,16,11,13,14,
  107518. 17,17,17,17,17,16,16,16,16,15,16,16,16,16,16,16,
  107519. };
  107520. static static_codebook _huff_book_line_512x17_class2 = {
  107521. 1, 64,
  107522. _huff_lengthlist_line_512x17_class2,
  107523. 0, 0, 0, 0, 0,
  107524. NULL,
  107525. NULL,
  107526. NULL,
  107527. NULL,
  107528. 0
  107529. };
  107530. static long _huff_lengthlist_line_512x17_class3[] = {
  107531. 2, 4, 6,17, 4, 5, 7,17, 8, 7,10,17,17,17,17,17,
  107532. 3, 4, 6,15, 3, 3, 6,15, 7, 6, 9,17,17,17,17,17,
  107533. 6, 8,10,17, 6, 6, 8,16, 9, 8,10,17,17,15,16,17,
  107534. 17,17,17,17,12,15,15,16,12,15,15,16,16,16,16,16,
  107535. };
  107536. static static_codebook _huff_book_line_512x17_class3 = {
  107537. 1, 64,
  107538. _huff_lengthlist_line_512x17_class3,
  107539. 0, 0, 0, 0, 0,
  107540. NULL,
  107541. NULL,
  107542. NULL,
  107543. NULL,
  107544. 0
  107545. };
  107546. static long _huff_lengthlist_line_128x4_class0[] = {
  107547. 7, 7, 7,11, 6, 6, 7,11, 7, 6, 6,10,12,10,10,13,
  107548. 7, 7, 8,11, 7, 7, 7,11, 7, 6, 7,10,11,10,10,13,
  107549. 10,10, 9,12, 9, 9, 9,11, 8, 8, 8,11,13,11,10,14,
  107550. 15,15,14,15,15,14,13,14,15,12,12,17,17,17,17,17,
  107551. 7, 7, 6, 9, 6, 6, 6, 9, 7, 6, 6, 8,11,11,10,12,
  107552. 7, 7, 7, 9, 7, 6, 6, 9, 7, 6, 6, 9,13,10,10,11,
  107553. 10, 9, 8,10, 9, 8, 8,10, 8, 8, 7, 9,13,12,10,11,
  107554. 17,14,14,13,15,14,12,13,17,13,12,15,17,17,14,17,
  107555. 7, 6, 6, 7, 6, 6, 5, 7, 6, 6, 6, 6,11, 9, 9, 9,
  107556. 7, 7, 6, 7, 7, 6, 6, 7, 6, 6, 6, 6,10, 9, 8, 9,
  107557. 10, 9, 8, 8, 9, 8, 7, 8, 8, 7, 6, 8,11,10, 9,10,
  107558. 17,17,12,15,15,15,12,14,14,14,10,12,15,13,12,13,
  107559. 11,10, 8,10,11,10, 8, 8,10, 9, 7, 7,10, 9, 9,11,
  107560. 11,11, 9,10,11,10, 8, 9,10, 8, 6, 8,10, 9, 9,11,
  107561. 14,13,10,12,12,11,10,10, 8, 7, 8,10,10,11,11,12,
  107562. 17,17,15,17,17,17,17,17,17,13,12,17,17,17,14,17,
  107563. };
  107564. static static_codebook _huff_book_line_128x4_class0 = {
  107565. 1, 256,
  107566. _huff_lengthlist_line_128x4_class0,
  107567. 0, 0, 0, 0, 0,
  107568. NULL,
  107569. NULL,
  107570. NULL,
  107571. NULL,
  107572. 0
  107573. };
  107574. static long _huff_lengthlist_line_128x4_0sub0[] = {
  107575. 2, 2, 2, 2,
  107576. };
  107577. static static_codebook _huff_book_line_128x4_0sub0 = {
  107578. 1, 4,
  107579. _huff_lengthlist_line_128x4_0sub0,
  107580. 0, 0, 0, 0, 0,
  107581. NULL,
  107582. NULL,
  107583. NULL,
  107584. NULL,
  107585. 0
  107586. };
  107587. static long _huff_lengthlist_line_128x4_0sub1[] = {
  107588. 0, 0, 0, 0, 3, 2, 3, 2, 3, 3,
  107589. };
  107590. static static_codebook _huff_book_line_128x4_0sub1 = {
  107591. 1, 10,
  107592. _huff_lengthlist_line_128x4_0sub1,
  107593. 0, 0, 0, 0, 0,
  107594. NULL,
  107595. NULL,
  107596. NULL,
  107597. NULL,
  107598. 0
  107599. };
  107600. static long _huff_lengthlist_line_128x4_0sub2[] = {
  107601. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 3, 4, 3, 4, 3,
  107602. 4, 4, 5, 4, 5, 4, 6, 5, 6,
  107603. };
  107604. static static_codebook _huff_book_line_128x4_0sub2 = {
  107605. 1, 25,
  107606. _huff_lengthlist_line_128x4_0sub2,
  107607. 0, 0, 0, 0, 0,
  107608. NULL,
  107609. NULL,
  107610. NULL,
  107611. NULL,
  107612. 0
  107613. };
  107614. static long _huff_lengthlist_line_128x4_0sub3[] = {
  107615. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107616. 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 4, 3, 5, 3, 5, 3,
  107617. 5, 4, 6, 5, 6, 5, 7, 6, 6, 7, 7, 9, 9,11,11,16,
  107618. 11,14,10,11,11,13,16,15,15,15,15,15,15,15,15,15,
  107619. };
  107620. static static_codebook _huff_book_line_128x4_0sub3 = {
  107621. 1, 64,
  107622. _huff_lengthlist_line_128x4_0sub3,
  107623. 0, 0, 0, 0, 0,
  107624. NULL,
  107625. NULL,
  107626. NULL,
  107627. NULL,
  107628. 0
  107629. };
  107630. static long _huff_lengthlist_line_256x4_class0[] = {
  107631. 6, 7, 7,12, 6, 6, 7,12, 7, 6, 6,10,15,12,11,13,
  107632. 7, 7, 8,13, 7, 7, 8,12, 7, 7, 7,11,12,12,11,13,
  107633. 10, 9, 9,11, 9, 9, 9,10,10, 8, 8,12,14,12,12,14,
  107634. 11,11,12,14,11,12,11,15,15,12,13,15,15,15,15,15,
  107635. 6, 6, 7,10, 6, 6, 6,11, 7, 6, 6, 9,14,12,11,13,
  107636. 7, 7, 7,10, 6, 6, 7, 9, 7, 7, 6,10,13,12,10,12,
  107637. 9, 9, 9,11, 9, 9, 8, 9, 9, 8, 8,10,13,12,10,12,
  107638. 12,12,11,13,12,12,11,12,15,13,12,15,15,15,14,14,
  107639. 6, 6, 6, 8, 6, 6, 5, 6, 7, 7, 6, 5,11,10, 9, 8,
  107640. 7, 6, 6, 7, 6, 6, 5, 6, 7, 7, 6, 6,11,10, 9, 8,
  107641. 8, 8, 8, 9, 8, 8, 7, 8, 8, 8, 6, 7,11,10, 9, 9,
  107642. 14,11,10,14,14,11,10,15,13,11, 9,11,15,12,12,11,
  107643. 11, 9, 8, 8,10, 9, 8, 9,11,10, 9, 8,12,11,12,11,
  107644. 13,10, 8, 9,11,10, 8, 9,10, 9, 8, 9,10, 8,12,12,
  107645. 15,11,10,10,13,11,10,10, 8, 8, 7,12,10, 9,11,12,
  107646. 15,12,11,15,13,11,11,15,12,14,11,13,15,15,13,13,
  107647. };
  107648. static static_codebook _huff_book_line_256x4_class0 = {
  107649. 1, 256,
  107650. _huff_lengthlist_line_256x4_class0,
  107651. 0, 0, 0, 0, 0,
  107652. NULL,
  107653. NULL,
  107654. NULL,
  107655. NULL,
  107656. 0
  107657. };
  107658. static long _huff_lengthlist_line_256x4_0sub0[] = {
  107659. 2, 2, 2, 2,
  107660. };
  107661. static static_codebook _huff_book_line_256x4_0sub0 = {
  107662. 1, 4,
  107663. _huff_lengthlist_line_256x4_0sub0,
  107664. 0, 0, 0, 0, 0,
  107665. NULL,
  107666. NULL,
  107667. NULL,
  107668. NULL,
  107669. 0
  107670. };
  107671. static long _huff_lengthlist_line_256x4_0sub1[] = {
  107672. 0, 0, 0, 0, 2, 2, 3, 3, 3, 3,
  107673. };
  107674. static static_codebook _huff_book_line_256x4_0sub1 = {
  107675. 1, 10,
  107676. _huff_lengthlist_line_256x4_0sub1,
  107677. 0, 0, 0, 0, 0,
  107678. NULL,
  107679. NULL,
  107680. NULL,
  107681. NULL,
  107682. 0
  107683. };
  107684. static long _huff_lengthlist_line_256x4_0sub2[] = {
  107685. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 3, 4, 3, 4, 3,
  107686. 5, 3, 5, 4, 5, 4, 6, 4, 6,
  107687. };
  107688. static static_codebook _huff_book_line_256x4_0sub2 = {
  107689. 1, 25,
  107690. _huff_lengthlist_line_256x4_0sub2,
  107691. 0, 0, 0, 0, 0,
  107692. NULL,
  107693. NULL,
  107694. NULL,
  107695. NULL,
  107696. 0
  107697. };
  107698. static long _huff_lengthlist_line_256x4_0sub3[] = {
  107699. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107700. 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 4, 3, 5, 3, 5, 3,
  107701. 6, 4, 7, 4, 7, 5, 7, 6, 7, 6, 7, 8,10,13,13,13,
  107702. 13,13,13,13,13,13,13,13,13,13,13,12,12,12,12,12,
  107703. };
  107704. static static_codebook _huff_book_line_256x4_0sub3 = {
  107705. 1, 64,
  107706. _huff_lengthlist_line_256x4_0sub3,
  107707. 0, 0, 0, 0, 0,
  107708. NULL,
  107709. NULL,
  107710. NULL,
  107711. NULL,
  107712. 0
  107713. };
  107714. static long _huff_lengthlist_line_128x7_class0[] = {
  107715. 10, 7, 8,13, 9, 6, 7,11,10, 8, 8,12,17,17,17,17,
  107716. 7, 5, 5, 9, 6, 4, 4, 8, 8, 5, 5, 8,16,14,13,16,
  107717. 7, 5, 5, 7, 6, 3, 3, 5, 8, 5, 4, 7,14,12,12,15,
  107718. 10, 7, 8, 9, 7, 5, 5, 6, 9, 6, 5, 5,15,12, 9,10,
  107719. };
  107720. static static_codebook _huff_book_line_128x7_class0 = {
  107721. 1, 64,
  107722. _huff_lengthlist_line_128x7_class0,
  107723. 0, 0, 0, 0, 0,
  107724. NULL,
  107725. NULL,
  107726. NULL,
  107727. NULL,
  107728. 0
  107729. };
  107730. static long _huff_lengthlist_line_128x7_class1[] = {
  107731. 8,13,17,17, 8,11,17,17,11,13,17,17,17,17,17,17,
  107732. 6,10,16,17, 6,10,15,17, 8,10,16,17,17,17,17,17,
  107733. 9,13,15,17, 8,11,17,17,10,12,17,17,17,17,17,17,
  107734. 17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,
  107735. 6,11,15,17, 7,10,15,17, 8,10,17,17,17,15,17,17,
  107736. 4, 8,13,17, 4, 7,13,17, 6, 8,15,17,16,15,17,17,
  107737. 6,11,15,17, 6, 9,13,17, 8,10,17,17,15,17,17,17,
  107738. 16,17,17,17,12,14,15,17,13,14,15,17,17,17,17,17,
  107739. 5,10,14,17, 5, 9,14,17, 7, 9,15,17,15,15,17,17,
  107740. 3, 7,12,17, 3, 6,11,17, 5, 7,13,17,12,12,17,17,
  107741. 5, 9,14,17, 3, 7,11,17, 5, 8,13,17,13,11,16,17,
  107742. 12,17,17,17, 9,14,15,17,10,11,14,17,16,14,17,17,
  107743. 8,12,17,17, 8,12,17,17,10,12,17,17,17,17,17,17,
  107744. 5,10,17,17, 5, 9,15,17, 7, 9,17,17,13,13,17,17,
  107745. 7,11,17,17, 6,10,15,17, 7, 9,15,17,12,11,17,17,
  107746. 12,15,17,17,11,14,17,17,11,10,15,17,17,16,17,17,
  107747. };
  107748. static static_codebook _huff_book_line_128x7_class1 = {
  107749. 1, 256,
  107750. _huff_lengthlist_line_128x7_class1,
  107751. 0, 0, 0, 0, 0,
  107752. NULL,
  107753. NULL,
  107754. NULL,
  107755. NULL,
  107756. 0
  107757. };
  107758. static long _huff_lengthlist_line_128x7_0sub1[] = {
  107759. 0, 3, 3, 3, 3, 3, 3, 3, 3,
  107760. };
  107761. static static_codebook _huff_book_line_128x7_0sub1 = {
  107762. 1, 9,
  107763. _huff_lengthlist_line_128x7_0sub1,
  107764. 0, 0, 0, 0, 0,
  107765. NULL,
  107766. NULL,
  107767. NULL,
  107768. NULL,
  107769. 0
  107770. };
  107771. static long _huff_lengthlist_line_128x7_0sub2[] = {
  107772. 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 3, 3, 4, 4, 4, 4,
  107773. 5, 4, 5, 4, 5, 4, 6, 4, 6,
  107774. };
  107775. static static_codebook _huff_book_line_128x7_0sub2 = {
  107776. 1, 25,
  107777. _huff_lengthlist_line_128x7_0sub2,
  107778. 0, 0, 0, 0, 0,
  107779. NULL,
  107780. NULL,
  107781. NULL,
  107782. NULL,
  107783. 0
  107784. };
  107785. static long _huff_lengthlist_line_128x7_0sub3[] = {
  107786. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107787. 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 5, 3, 5, 3, 5, 4,
  107788. 5, 4, 5, 5, 5, 5, 6, 5, 6, 5, 6, 5, 6, 5, 6, 5,
  107789. 7, 8, 9,11,13,13,13,13,13,13,13,13,13,13,13,13,
  107790. };
  107791. static static_codebook _huff_book_line_128x7_0sub3 = {
  107792. 1, 64,
  107793. _huff_lengthlist_line_128x7_0sub3,
  107794. 0, 0, 0, 0, 0,
  107795. NULL,
  107796. NULL,
  107797. NULL,
  107798. NULL,
  107799. 0
  107800. };
  107801. static long _huff_lengthlist_line_128x7_1sub1[] = {
  107802. 0, 3, 3, 2, 3, 3, 4, 3, 4,
  107803. };
  107804. static static_codebook _huff_book_line_128x7_1sub1 = {
  107805. 1, 9,
  107806. _huff_lengthlist_line_128x7_1sub1,
  107807. 0, 0, 0, 0, 0,
  107808. NULL,
  107809. NULL,
  107810. NULL,
  107811. NULL,
  107812. 0
  107813. };
  107814. static long _huff_lengthlist_line_128x7_1sub2[] = {
  107815. 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 4, 3, 6, 3, 6, 3,
  107816. 6, 3, 7, 3, 8, 4, 9, 4, 9,
  107817. };
  107818. static static_codebook _huff_book_line_128x7_1sub2 = {
  107819. 1, 25,
  107820. _huff_lengthlist_line_128x7_1sub2,
  107821. 0, 0, 0, 0, 0,
  107822. NULL,
  107823. NULL,
  107824. NULL,
  107825. NULL,
  107826. 0
  107827. };
  107828. static long _huff_lengthlist_line_128x7_1sub3[] = {
  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, 1, 7, 2, 7, 3, 8, 4,
  107831. 9, 5, 9, 8,10,11,11,12,14,14,14,14,14,14,14,14,
  107832. 14,14,14,14,14,14,14,14,14,14,14,14,13,13,13,13,
  107833. };
  107834. static static_codebook _huff_book_line_128x7_1sub3 = {
  107835. 1, 64,
  107836. _huff_lengthlist_line_128x7_1sub3,
  107837. 0, 0, 0, 0, 0,
  107838. NULL,
  107839. NULL,
  107840. NULL,
  107841. NULL,
  107842. 0
  107843. };
  107844. static long _huff_lengthlist_line_128x11_class1[] = {
  107845. 1, 6, 3, 7, 2, 4, 5, 7,
  107846. };
  107847. static static_codebook _huff_book_line_128x11_class1 = {
  107848. 1, 8,
  107849. _huff_lengthlist_line_128x11_class1,
  107850. 0, 0, 0, 0, 0,
  107851. NULL,
  107852. NULL,
  107853. NULL,
  107854. NULL,
  107855. 0
  107856. };
  107857. static long _huff_lengthlist_line_128x11_class2[] = {
  107858. 1, 6,12,16, 4,12,15,16, 9,15,16,16,16,16,16,16,
  107859. 2, 5,11,16, 5,11,13,16, 9,13,16,16,16,16,16,16,
  107860. 4, 8,12,16, 5, 9,12,16, 9,13,15,16,16,16,16,16,
  107861. 15,16,16,16,11,14,13,16,12,15,16,16,16,16,16,15,
  107862. };
  107863. static static_codebook _huff_book_line_128x11_class2 = {
  107864. 1, 64,
  107865. _huff_lengthlist_line_128x11_class2,
  107866. 0, 0, 0, 0, 0,
  107867. NULL,
  107868. NULL,
  107869. NULL,
  107870. NULL,
  107871. 0
  107872. };
  107873. static long _huff_lengthlist_line_128x11_class3[] = {
  107874. 7, 6, 9,17, 7, 6, 8,17,12, 9,11,16,16,16,16,16,
  107875. 5, 4, 7,16, 5, 3, 6,14, 9, 6, 8,15,16,16,16,16,
  107876. 5, 4, 6,13, 3, 2, 4,11, 7, 4, 6,13,16,11,10,14,
  107877. 12,12,12,16, 9, 7,10,15,12, 9,11,16,16,15,15,16,
  107878. };
  107879. static static_codebook _huff_book_line_128x11_class3 = {
  107880. 1, 64,
  107881. _huff_lengthlist_line_128x11_class3,
  107882. 0, 0, 0, 0, 0,
  107883. NULL,
  107884. NULL,
  107885. NULL,
  107886. NULL,
  107887. 0
  107888. };
  107889. static long _huff_lengthlist_line_128x11_0sub0[] = {
  107890. 5, 5, 5, 5, 5, 5, 6, 5, 6, 5, 6, 5, 6, 5, 6, 5,
  107891. 6, 5, 6, 5, 6, 5, 6, 5, 6, 5, 6, 6, 6, 6, 7, 6,
  107892. 7, 6, 7, 6, 7, 6, 7, 6, 7, 6, 8, 6, 8, 6, 8, 7,
  107893. 8, 7, 8, 7, 8, 7, 9, 7, 9, 8, 9, 8, 9, 8,10, 8,
  107894. 10, 9,10, 9,10, 9,11, 9,11, 9,10,10,11,10,11,10,
  107895. 11,11,11,11,11,11,12,13,14,14,14,15,15,16,16,16,
  107896. 17,15,16,15,16,16,17,17,16,17,17,17,17,17,17,17,
  107897. 17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,
  107898. };
  107899. static static_codebook _huff_book_line_128x11_0sub0 = {
  107900. 1, 128,
  107901. _huff_lengthlist_line_128x11_0sub0,
  107902. 0, 0, 0, 0, 0,
  107903. NULL,
  107904. NULL,
  107905. NULL,
  107906. NULL,
  107907. 0
  107908. };
  107909. static long _huff_lengthlist_line_128x11_1sub0[] = {
  107910. 2, 5, 5, 5, 5, 5, 5, 4, 5, 5, 5, 5, 5, 5, 5, 5,
  107911. 6, 5, 6, 5, 6, 5, 7, 6, 7, 6, 7, 6, 8, 6, 8, 6,
  107912. };
  107913. static static_codebook _huff_book_line_128x11_1sub0 = {
  107914. 1, 32,
  107915. _huff_lengthlist_line_128x11_1sub0,
  107916. 0, 0, 0, 0, 0,
  107917. NULL,
  107918. NULL,
  107919. NULL,
  107920. NULL,
  107921. 0
  107922. };
  107923. static long _huff_lengthlist_line_128x11_1sub1[] = {
  107924. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107925. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107926. 5, 3, 5, 3, 6, 4, 6, 4, 7, 4, 7, 4, 7, 4, 8, 4,
  107927. 8, 4, 9, 5, 9, 5, 9, 5, 9, 6,10, 6,10, 6,11, 7,
  107928. 10, 7,10, 8,11, 9,11, 9,11,10,11,11,12,11,11,12,
  107929. 15,15,12,14,11,14,12,14,11,14,13,14,12,14,11,14,
  107930. 11,14,12,14,11,14,11,14,13,13,14,14,14,14,14,14,
  107931. 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,
  107932. };
  107933. static static_codebook _huff_book_line_128x11_1sub1 = {
  107934. 1, 128,
  107935. _huff_lengthlist_line_128x11_1sub1,
  107936. 0, 0, 0, 0, 0,
  107937. NULL,
  107938. NULL,
  107939. NULL,
  107940. NULL,
  107941. 0
  107942. };
  107943. static long _huff_lengthlist_line_128x11_2sub1[] = {
  107944. 0, 4, 5, 4, 5, 4, 5, 3, 5, 3, 5, 3, 5, 4, 4, 4,
  107945. 5, 5,
  107946. };
  107947. static static_codebook _huff_book_line_128x11_2sub1 = {
  107948. 1, 18,
  107949. _huff_lengthlist_line_128x11_2sub1,
  107950. 0, 0, 0, 0, 0,
  107951. NULL,
  107952. NULL,
  107953. NULL,
  107954. NULL,
  107955. 0
  107956. };
  107957. static long _huff_lengthlist_line_128x11_2sub2[] = {
  107958. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107959. 0, 0, 3, 3, 3, 4, 4, 4, 4, 5, 4, 5, 4, 6, 5, 7,
  107960. 5, 7, 6, 8, 6, 8, 6, 9, 7, 9, 7,10, 7, 9, 8,11,
  107961. 8,11,
  107962. };
  107963. static static_codebook _huff_book_line_128x11_2sub2 = {
  107964. 1, 50,
  107965. _huff_lengthlist_line_128x11_2sub2,
  107966. 0, 0, 0, 0, 0,
  107967. NULL,
  107968. NULL,
  107969. NULL,
  107970. NULL,
  107971. 0
  107972. };
  107973. static long _huff_lengthlist_line_128x11_2sub3[] = {
  107974. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107975. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107976. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107977. 0, 0, 4, 8, 3, 8, 4, 8, 4, 8, 6, 8, 5, 8, 4, 8,
  107978. 4, 8, 6, 8, 7, 8, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  107979. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  107980. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  107981. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  107982. };
  107983. static static_codebook _huff_book_line_128x11_2sub3 = {
  107984. 1, 128,
  107985. _huff_lengthlist_line_128x11_2sub3,
  107986. 0, 0, 0, 0, 0,
  107987. NULL,
  107988. NULL,
  107989. NULL,
  107990. NULL,
  107991. 0
  107992. };
  107993. static long _huff_lengthlist_line_128x11_3sub1[] = {
  107994. 0, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 5, 4,
  107995. 5, 4,
  107996. };
  107997. static static_codebook _huff_book_line_128x11_3sub1 = {
  107998. 1, 18,
  107999. _huff_lengthlist_line_128x11_3sub1,
  108000. 0, 0, 0, 0, 0,
  108001. NULL,
  108002. NULL,
  108003. NULL,
  108004. NULL,
  108005. 0
  108006. };
  108007. static long _huff_lengthlist_line_128x11_3sub2[] = {
  108008. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108009. 0, 0, 5, 3, 5, 4, 6, 4, 6, 4, 7, 4, 7, 4, 8, 4,
  108010. 8, 4, 9, 4, 9, 4,10, 4,10, 5,10, 5,11, 5,12, 6,
  108011. 12, 6,
  108012. };
  108013. static static_codebook _huff_book_line_128x11_3sub2 = {
  108014. 1, 50,
  108015. _huff_lengthlist_line_128x11_3sub2,
  108016. 0, 0, 0, 0, 0,
  108017. NULL,
  108018. NULL,
  108019. NULL,
  108020. NULL,
  108021. 0
  108022. };
  108023. static long _huff_lengthlist_line_128x11_3sub3[] = {
  108024. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108025. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108026. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108027. 0, 0, 7, 1, 6, 3, 7, 3, 8, 4, 8, 5, 8, 8, 8, 9,
  108028. 7, 8, 8, 7, 7, 7, 8, 9,10, 9, 9,10,10,10,10,10,
  108029. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  108030. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  108031. 10,10,10,10,10,10,10,10,10,10,10,10,10,10, 9, 9,
  108032. };
  108033. static static_codebook _huff_book_line_128x11_3sub3 = {
  108034. 1, 128,
  108035. _huff_lengthlist_line_128x11_3sub3,
  108036. 0, 0, 0, 0, 0,
  108037. NULL,
  108038. NULL,
  108039. NULL,
  108040. NULL,
  108041. 0
  108042. };
  108043. static long _huff_lengthlist_line_128x17_class1[] = {
  108044. 1, 3, 4, 7, 2, 5, 6, 7,
  108045. };
  108046. static static_codebook _huff_book_line_128x17_class1 = {
  108047. 1, 8,
  108048. _huff_lengthlist_line_128x17_class1,
  108049. 0, 0, 0, 0, 0,
  108050. NULL,
  108051. NULL,
  108052. NULL,
  108053. NULL,
  108054. 0
  108055. };
  108056. static long _huff_lengthlist_line_128x17_class2[] = {
  108057. 1, 4,10,19, 3, 8,13,19, 7,12,19,19,19,19,19,19,
  108058. 2, 6,11,19, 8,13,19,19, 9,11,19,19,19,19,19,19,
  108059. 6, 7,13,19, 9,13,19,19,10,13,18,18,18,18,18,18,
  108060. 18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,
  108061. };
  108062. static static_codebook _huff_book_line_128x17_class2 = {
  108063. 1, 64,
  108064. _huff_lengthlist_line_128x17_class2,
  108065. 0, 0, 0, 0, 0,
  108066. NULL,
  108067. NULL,
  108068. NULL,
  108069. NULL,
  108070. 0
  108071. };
  108072. static long _huff_lengthlist_line_128x17_class3[] = {
  108073. 3, 6,10,17, 4, 8,11,20, 8,10,11,20,20,20,20,20,
  108074. 2, 4, 8,18, 4, 6, 8,17, 7, 8,10,20,20,17,20,20,
  108075. 3, 5, 8,17, 3, 4, 6,17, 8, 8,10,17,17,12,16,20,
  108076. 13,13,15,20,10,10,12,20,15,14,15,20,20,20,19,19,
  108077. };
  108078. static static_codebook _huff_book_line_128x17_class3 = {
  108079. 1, 64,
  108080. _huff_lengthlist_line_128x17_class3,
  108081. 0, 0, 0, 0, 0,
  108082. NULL,
  108083. NULL,
  108084. NULL,
  108085. NULL,
  108086. 0
  108087. };
  108088. static long _huff_lengthlist_line_128x17_0sub0[] = {
  108089. 5, 5, 6, 5, 6, 5, 6, 5, 6, 5, 6, 5, 6, 5, 6, 5,
  108090. 7, 5, 7, 5, 7, 5, 7, 5, 7, 5, 7, 5, 8, 5, 8, 5,
  108091. 8, 5, 8, 5, 8, 6, 8, 6, 8, 6, 9, 6, 9, 6, 9, 6,
  108092. 9, 6, 9, 7, 9, 7, 9, 7, 9, 7,10, 7,10, 8,10, 8,
  108093. 10, 8,10, 8,10, 8,11, 8,11, 8,11, 8,11, 8,11, 9,
  108094. 12, 9,12, 9,12, 9,12, 9,12,10,12,10,13,11,13,11,
  108095. 14,12,14,13,15,14,16,14,17,15,18,16,20,20,20,20,
  108096. 20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,
  108097. };
  108098. static static_codebook _huff_book_line_128x17_0sub0 = {
  108099. 1, 128,
  108100. _huff_lengthlist_line_128x17_0sub0,
  108101. 0, 0, 0, 0, 0,
  108102. NULL,
  108103. NULL,
  108104. NULL,
  108105. NULL,
  108106. 0
  108107. };
  108108. static long _huff_lengthlist_line_128x17_1sub0[] = {
  108109. 2, 5, 5, 4, 5, 4, 5, 4, 5, 5, 5, 5, 5, 5, 6, 5,
  108110. 6, 5, 6, 5, 7, 6, 7, 6, 7, 6, 8, 6, 9, 7, 9, 7,
  108111. };
  108112. static static_codebook _huff_book_line_128x17_1sub0 = {
  108113. 1, 32,
  108114. _huff_lengthlist_line_128x17_1sub0,
  108115. 0, 0, 0, 0, 0,
  108116. NULL,
  108117. NULL,
  108118. NULL,
  108119. NULL,
  108120. 0
  108121. };
  108122. static long _huff_lengthlist_line_128x17_1sub1[] = {
  108123. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108124. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108125. 4, 3, 5, 3, 5, 3, 6, 3, 6, 4, 6, 4, 7, 4, 7, 5,
  108126. 8, 5, 8, 6, 9, 7, 9, 7, 9, 8,10, 9,10, 9,11,10,
  108127. 11,11,11,11,11,11,12,12,12,13,12,13,12,14,12,15,
  108128. 12,14,12,16,13,17,13,17,14,17,14,16,13,17,14,17,
  108129. 14,17,15,17,15,15,16,17,17,17,17,17,17,17,17,17,
  108130. 17,17,17,17,17,17,16,16,16,16,16,16,16,16,16,16,
  108131. };
  108132. static static_codebook _huff_book_line_128x17_1sub1 = {
  108133. 1, 128,
  108134. _huff_lengthlist_line_128x17_1sub1,
  108135. 0, 0, 0, 0, 0,
  108136. NULL,
  108137. NULL,
  108138. NULL,
  108139. NULL,
  108140. 0
  108141. };
  108142. static long _huff_lengthlist_line_128x17_2sub1[] = {
  108143. 0, 4, 5, 4, 6, 4, 8, 3, 9, 3, 9, 2, 9, 3, 8, 4,
  108144. 9, 4,
  108145. };
  108146. static static_codebook _huff_book_line_128x17_2sub1 = {
  108147. 1, 18,
  108148. _huff_lengthlist_line_128x17_2sub1,
  108149. 0, 0, 0, 0, 0,
  108150. NULL,
  108151. NULL,
  108152. NULL,
  108153. NULL,
  108154. 0
  108155. };
  108156. static long _huff_lengthlist_line_128x17_2sub2[] = {
  108157. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108158. 0, 0, 5, 1, 5, 3, 5, 3, 5, 4, 7, 5,10, 7,10, 7,
  108159. 12,10,14,10,14, 9,14,11,14,14,14,13,13,13,13,13,
  108160. 13,13,
  108161. };
  108162. static static_codebook _huff_book_line_128x17_2sub2 = {
  108163. 1, 50,
  108164. _huff_lengthlist_line_128x17_2sub2,
  108165. 0, 0, 0, 0, 0,
  108166. NULL,
  108167. NULL,
  108168. NULL,
  108169. NULL,
  108170. 0
  108171. };
  108172. static long _huff_lengthlist_line_128x17_2sub3[] = {
  108173. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108174. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108175. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108176. 0, 0, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  108177. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 6, 6,
  108178. 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
  108179. 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
  108180. 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
  108181. };
  108182. static static_codebook _huff_book_line_128x17_2sub3 = {
  108183. 1, 128,
  108184. _huff_lengthlist_line_128x17_2sub3,
  108185. 0, 0, 0, 0, 0,
  108186. NULL,
  108187. NULL,
  108188. NULL,
  108189. NULL,
  108190. 0
  108191. };
  108192. static long _huff_lengthlist_line_128x17_3sub1[] = {
  108193. 0, 4, 4, 4, 4, 4, 4, 4, 5, 3, 5, 3, 5, 4, 6, 4,
  108194. 6, 4,
  108195. };
  108196. static static_codebook _huff_book_line_128x17_3sub1 = {
  108197. 1, 18,
  108198. _huff_lengthlist_line_128x17_3sub1,
  108199. 0, 0, 0, 0, 0,
  108200. NULL,
  108201. NULL,
  108202. NULL,
  108203. NULL,
  108204. 0
  108205. };
  108206. static long _huff_lengthlist_line_128x17_3sub2[] = {
  108207. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108208. 0, 0, 5, 3, 6, 3, 6, 4, 7, 4, 7, 4, 7, 4, 8, 4,
  108209. 8, 4, 8, 4, 8, 4, 9, 4, 9, 5,10, 5,10, 7,10, 8,
  108210. 10, 8,
  108211. };
  108212. static static_codebook _huff_book_line_128x17_3sub2 = {
  108213. 1, 50,
  108214. _huff_lengthlist_line_128x17_3sub2,
  108215. 0, 0, 0, 0, 0,
  108216. NULL,
  108217. NULL,
  108218. NULL,
  108219. NULL,
  108220. 0
  108221. };
  108222. static long _huff_lengthlist_line_128x17_3sub3[] = {
  108223. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108224. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108225. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108226. 0, 0, 3, 2, 4, 3, 4, 4, 4, 5, 4, 7, 5, 8, 5,11,
  108227. 6,10, 6,12, 7,12, 7,12, 8,12, 8,12,10,12,12,12,
  108228. 12,12,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  108229. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  108230. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  108231. };
  108232. static static_codebook _huff_book_line_128x17_3sub3 = {
  108233. 1, 128,
  108234. _huff_lengthlist_line_128x17_3sub3,
  108235. 0, 0, 0, 0, 0,
  108236. NULL,
  108237. NULL,
  108238. NULL,
  108239. NULL,
  108240. 0
  108241. };
  108242. static long _huff_lengthlist_line_1024x27_class1[] = {
  108243. 2,10, 8,14, 7,12,11,14, 1, 5, 3, 7, 4, 9, 7,13,
  108244. };
  108245. static static_codebook _huff_book_line_1024x27_class1 = {
  108246. 1, 16,
  108247. _huff_lengthlist_line_1024x27_class1,
  108248. 0, 0, 0, 0, 0,
  108249. NULL,
  108250. NULL,
  108251. NULL,
  108252. NULL,
  108253. 0
  108254. };
  108255. static long _huff_lengthlist_line_1024x27_class2[] = {
  108256. 1, 4, 2, 6, 3, 7, 5, 7,
  108257. };
  108258. static static_codebook _huff_book_line_1024x27_class2 = {
  108259. 1, 8,
  108260. _huff_lengthlist_line_1024x27_class2,
  108261. 0, 0, 0, 0, 0,
  108262. NULL,
  108263. NULL,
  108264. NULL,
  108265. NULL,
  108266. 0
  108267. };
  108268. static long _huff_lengthlist_line_1024x27_class3[] = {
  108269. 1, 5, 7,21, 5, 8, 9,21,10, 9,12,20,20,16,20,20,
  108270. 4, 8, 9,20, 6, 8, 9,20,11,11,13,20,20,15,17,20,
  108271. 9,11,14,20, 8,10,15,20,11,13,15,20,20,20,20,20,
  108272. 20,20,20,20,13,20,20,20,18,18,20,20,20,20,20,20,
  108273. 3, 6, 8,20, 6, 7, 9,20,10, 9,12,20,20,20,20,20,
  108274. 5, 7, 9,20, 6, 6, 9,20,10, 9,12,20,20,20,20,20,
  108275. 8,10,13,20, 8, 9,12,20,11,10,12,20,20,20,20,20,
  108276. 18,20,20,20,15,17,18,20,18,17,18,20,20,20,20,20,
  108277. 7,10,12,20, 8, 9,11,20,14,13,14,20,20,20,20,20,
  108278. 6, 9,12,20, 7, 8,11,20,12,11,13,20,20,20,20,20,
  108279. 9,11,15,20, 8,10,14,20,12,11,14,20,20,20,20,20,
  108280. 20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,
  108281. 11,16,18,20,15,15,17,20,20,17,20,20,20,20,20,20,
  108282. 9,14,16,20,12,12,15,20,17,15,18,20,20,20,20,20,
  108283. 16,19,18,20,15,16,20,20,17,17,20,20,20,20,20,20,
  108284. 20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,
  108285. };
  108286. static static_codebook _huff_book_line_1024x27_class3 = {
  108287. 1, 256,
  108288. _huff_lengthlist_line_1024x27_class3,
  108289. 0, 0, 0, 0, 0,
  108290. NULL,
  108291. NULL,
  108292. NULL,
  108293. NULL,
  108294. 0
  108295. };
  108296. static long _huff_lengthlist_line_1024x27_class4[] = {
  108297. 2, 3, 7,13, 4, 4, 7,15, 8, 6, 9,17,21,16,15,21,
  108298. 2, 5, 7,11, 5, 5, 7,14, 9, 7,10,16,17,15,16,21,
  108299. 4, 7,10,17, 7, 7, 9,15,11, 9,11,16,21,18,15,21,
  108300. 18,21,21,21,15,17,17,19,21,19,18,20,21,21,21,20,
  108301. };
  108302. static static_codebook _huff_book_line_1024x27_class4 = {
  108303. 1, 64,
  108304. _huff_lengthlist_line_1024x27_class4,
  108305. 0, 0, 0, 0, 0,
  108306. NULL,
  108307. NULL,
  108308. NULL,
  108309. NULL,
  108310. 0
  108311. };
  108312. static long _huff_lengthlist_line_1024x27_0sub0[] = {
  108313. 5, 5, 5, 5, 6, 5, 6, 5, 6, 5, 6, 5, 6, 5, 6, 5,
  108314. 6, 5, 6, 5, 6, 5, 6, 5, 7, 5, 7, 5, 7, 5, 7, 5,
  108315. 8, 6, 8, 6, 8, 6, 9, 6, 9, 6,10, 6,10, 6,11, 6,
  108316. 11, 7,11, 7,12, 7,12, 7,12, 7,12, 7,12, 7,12, 7,
  108317. 12, 7,12, 8,13, 8,12, 8,12, 8,13, 8,13, 9,13, 9,
  108318. 13, 9,13, 9,12,10,12,10,13,10,14,11,14,12,14,13,
  108319. 14,13,14,14,15,16,15,15,15,14,15,17,21,22,22,21,
  108320. 22,22,22,22,22,22,21,21,21,21,21,21,21,21,21,21,
  108321. };
  108322. static static_codebook _huff_book_line_1024x27_0sub0 = {
  108323. 1, 128,
  108324. _huff_lengthlist_line_1024x27_0sub0,
  108325. 0, 0, 0, 0, 0,
  108326. NULL,
  108327. NULL,
  108328. NULL,
  108329. NULL,
  108330. 0
  108331. };
  108332. static long _huff_lengthlist_line_1024x27_1sub0[] = {
  108333. 2, 5, 5, 4, 5, 4, 5, 4, 5, 4, 6, 5, 6, 5, 6, 5,
  108334. 6, 5, 7, 5, 7, 6, 8, 6, 8, 6, 8, 6, 9, 6, 9, 6,
  108335. };
  108336. static static_codebook _huff_book_line_1024x27_1sub0 = {
  108337. 1, 32,
  108338. _huff_lengthlist_line_1024x27_1sub0,
  108339. 0, 0, 0, 0, 0,
  108340. NULL,
  108341. NULL,
  108342. NULL,
  108343. NULL,
  108344. 0
  108345. };
  108346. static long _huff_lengthlist_line_1024x27_1sub1[] = {
  108347. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108348. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108349. 8, 5, 8, 4, 9, 4, 9, 4, 9, 4, 9, 4, 9, 4, 9, 4,
  108350. 9, 4, 9, 4, 9, 4, 8, 4, 8, 4, 9, 5, 9, 5, 9, 5,
  108351. 9, 5, 9, 6,10, 6,10, 7,10, 8,11, 9,11,11,12,13,
  108352. 12,14,13,15,13,15,14,16,14,17,15,17,15,15,16,16,
  108353. 15,16,16,16,15,18,16,15,17,17,19,19,19,19,19,19,
  108354. 19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,
  108355. };
  108356. static static_codebook _huff_book_line_1024x27_1sub1 = {
  108357. 1, 128,
  108358. _huff_lengthlist_line_1024x27_1sub1,
  108359. 0, 0, 0, 0, 0,
  108360. NULL,
  108361. NULL,
  108362. NULL,
  108363. NULL,
  108364. 0
  108365. };
  108366. static long _huff_lengthlist_line_1024x27_2sub0[] = {
  108367. 1, 5, 5, 5, 5, 5, 5, 5, 6, 5, 6, 5, 6, 5, 6, 5,
  108368. 6, 6, 7, 7, 7, 7, 8, 7, 8, 8, 9, 8,10, 9,10, 9,
  108369. };
  108370. static static_codebook _huff_book_line_1024x27_2sub0 = {
  108371. 1, 32,
  108372. _huff_lengthlist_line_1024x27_2sub0,
  108373. 0, 0, 0, 0, 0,
  108374. NULL,
  108375. NULL,
  108376. NULL,
  108377. NULL,
  108378. 0
  108379. };
  108380. static long _huff_lengthlist_line_1024x27_2sub1[] = {
  108381. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108382. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108383. 4, 3, 4, 3, 4, 4, 5, 4, 5, 4, 5, 5, 6, 5, 6, 5,
  108384. 7, 5, 7, 6, 7, 6, 8, 7, 8, 7, 8, 7, 9, 8, 9, 9,
  108385. 9, 9,10,10,10,11, 9,12, 9,12, 9,15,10,14, 9,13,
  108386. 10,13,10,12,10,12,10,13,10,12,11,13,11,14,12,13,
  108387. 13,14,14,13,14,15,14,16,13,13,14,16,16,16,16,16,
  108388. 16,16,16,16,16,16,16,16,16,16,16,16,16,16,15,15,
  108389. };
  108390. static static_codebook _huff_book_line_1024x27_2sub1 = {
  108391. 1, 128,
  108392. _huff_lengthlist_line_1024x27_2sub1,
  108393. 0, 0, 0, 0, 0,
  108394. NULL,
  108395. NULL,
  108396. NULL,
  108397. NULL,
  108398. 0
  108399. };
  108400. static long _huff_lengthlist_line_1024x27_3sub1[] = {
  108401. 0, 4, 5, 4, 5, 3, 5, 3, 5, 3, 5, 4, 4, 4, 4, 5,
  108402. 5, 5,
  108403. };
  108404. static static_codebook _huff_book_line_1024x27_3sub1 = {
  108405. 1, 18,
  108406. _huff_lengthlist_line_1024x27_3sub1,
  108407. 0, 0, 0, 0, 0,
  108408. NULL,
  108409. NULL,
  108410. NULL,
  108411. NULL,
  108412. 0
  108413. };
  108414. static long _huff_lengthlist_line_1024x27_3sub2[] = {
  108415. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108416. 0, 0, 3, 3, 4, 3, 4, 4, 4, 4, 5, 5, 5, 5, 5, 6,
  108417. 5, 7, 5, 8, 6, 8, 6, 9, 7,10, 7,10, 8,10, 8,11,
  108418. 9,11,
  108419. };
  108420. static static_codebook _huff_book_line_1024x27_3sub2 = {
  108421. 1, 50,
  108422. _huff_lengthlist_line_1024x27_3sub2,
  108423. 0, 0, 0, 0, 0,
  108424. NULL,
  108425. NULL,
  108426. NULL,
  108427. NULL,
  108428. 0
  108429. };
  108430. static long _huff_lengthlist_line_1024x27_3sub3[] = {
  108431. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108432. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108433. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108434. 0, 0, 3, 7, 3, 8, 3,10, 3, 8, 3, 9, 3, 8, 4, 9,
  108435. 4, 9, 5, 9, 6,10, 6, 9, 7,11, 7,12, 9,13,10,13,
  108436. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  108437. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  108438. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  108439. };
  108440. static static_codebook _huff_book_line_1024x27_3sub3 = {
  108441. 1, 128,
  108442. _huff_lengthlist_line_1024x27_3sub3,
  108443. 0, 0, 0, 0, 0,
  108444. NULL,
  108445. NULL,
  108446. NULL,
  108447. NULL,
  108448. 0
  108449. };
  108450. static long _huff_lengthlist_line_1024x27_4sub1[] = {
  108451. 0, 4, 5, 4, 5, 4, 5, 4, 5, 3, 5, 3, 5, 3, 5, 4,
  108452. 5, 4,
  108453. };
  108454. static static_codebook _huff_book_line_1024x27_4sub1 = {
  108455. 1, 18,
  108456. _huff_lengthlist_line_1024x27_4sub1,
  108457. 0, 0, 0, 0, 0,
  108458. NULL,
  108459. NULL,
  108460. NULL,
  108461. NULL,
  108462. 0
  108463. };
  108464. static long _huff_lengthlist_line_1024x27_4sub2[] = {
  108465. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108466. 0, 0, 4, 2, 4, 2, 5, 3, 5, 4, 6, 6, 6, 7, 7, 8,
  108467. 7, 8, 7, 8, 7, 9, 8, 9, 8, 9, 8,10, 8,11, 9,12,
  108468. 9,12,
  108469. };
  108470. static static_codebook _huff_book_line_1024x27_4sub2 = {
  108471. 1, 50,
  108472. _huff_lengthlist_line_1024x27_4sub2,
  108473. 0, 0, 0, 0, 0,
  108474. NULL,
  108475. NULL,
  108476. NULL,
  108477. NULL,
  108478. 0
  108479. };
  108480. static long _huff_lengthlist_line_1024x27_4sub3[] = {
  108481. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108482. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108483. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108484. 0, 0, 2, 5, 2, 6, 3, 6, 4, 7, 4, 7, 5, 9, 5,11,
  108485. 6,11, 6,11, 7,11, 6,11, 6,11, 9,11, 8,11,11,11,
  108486. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  108487. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  108488. 11,11,11,11,11,11,11,11,11,11,10,10,10,10,10,10,
  108489. };
  108490. static static_codebook _huff_book_line_1024x27_4sub3 = {
  108491. 1, 128,
  108492. _huff_lengthlist_line_1024x27_4sub3,
  108493. 0, 0, 0, 0, 0,
  108494. NULL,
  108495. NULL,
  108496. NULL,
  108497. NULL,
  108498. 0
  108499. };
  108500. static long _huff_lengthlist_line_2048x27_class1[] = {
  108501. 2, 6, 8, 9, 7,11,13,13, 1, 3, 5, 5, 6, 6,12,10,
  108502. };
  108503. static static_codebook _huff_book_line_2048x27_class1 = {
  108504. 1, 16,
  108505. _huff_lengthlist_line_2048x27_class1,
  108506. 0, 0, 0, 0, 0,
  108507. NULL,
  108508. NULL,
  108509. NULL,
  108510. NULL,
  108511. 0
  108512. };
  108513. static long _huff_lengthlist_line_2048x27_class2[] = {
  108514. 1, 2, 3, 6, 4, 7, 5, 7,
  108515. };
  108516. static static_codebook _huff_book_line_2048x27_class2 = {
  108517. 1, 8,
  108518. _huff_lengthlist_line_2048x27_class2,
  108519. 0, 0, 0, 0, 0,
  108520. NULL,
  108521. NULL,
  108522. NULL,
  108523. NULL,
  108524. 0
  108525. };
  108526. static long _huff_lengthlist_line_2048x27_class3[] = {
  108527. 3, 3, 6,16, 5, 5, 7,16, 9, 8,11,16,16,16,16,16,
  108528. 5, 5, 8,16, 5, 5, 7,16, 8, 7, 9,16,16,16,16,16,
  108529. 9, 9,12,16, 6, 8,11,16, 9,10,11,16,16,16,16,16,
  108530. 16,16,16,16,13,16,16,16,15,16,16,16,16,16,16,16,
  108531. 5, 4, 7,16, 6, 5, 8,16, 9, 8,10,16,16,16,16,16,
  108532. 5, 5, 7,15, 5, 4, 6,15, 7, 6, 8,16,16,16,16,16,
  108533. 9, 9,11,15, 7, 7, 9,16, 8, 8, 9,16,16,16,16,16,
  108534. 16,16,16,16,15,15,15,16,15,15,14,16,16,16,16,16,
  108535. 8, 8,11,16, 8, 9,10,16,11,10,14,16,16,16,16,16,
  108536. 6, 8,10,16, 6, 7,10,16, 8, 8,11,16,14,16,16,16,
  108537. 10,11,14,16, 9, 9,11,16,10,10,11,16,16,16,16,16,
  108538. 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,
  108539. 16,16,16,16,15,16,16,16,16,16,16,16,16,16,16,16,
  108540. 12,16,15,16,12,14,16,16,16,16,16,16,16,16,16,16,
  108541. 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,
  108542. 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,
  108543. };
  108544. static static_codebook _huff_book_line_2048x27_class3 = {
  108545. 1, 256,
  108546. _huff_lengthlist_line_2048x27_class3,
  108547. 0, 0, 0, 0, 0,
  108548. NULL,
  108549. NULL,
  108550. NULL,
  108551. NULL,
  108552. 0
  108553. };
  108554. static long _huff_lengthlist_line_2048x27_class4[] = {
  108555. 2, 4, 7,13, 4, 5, 7,15, 8, 7,10,16,16,14,16,16,
  108556. 2, 4, 7,16, 3, 4, 7,14, 8, 8,10,16,16,16,15,16,
  108557. 6, 8,11,16, 7, 7, 9,16,11, 9,13,16,16,16,15,16,
  108558. 16,16,16,16,14,16,16,16,16,16,16,16,16,16,16,16,
  108559. };
  108560. static static_codebook _huff_book_line_2048x27_class4 = {
  108561. 1, 64,
  108562. _huff_lengthlist_line_2048x27_class4,
  108563. 0, 0, 0, 0, 0,
  108564. NULL,
  108565. NULL,
  108566. NULL,
  108567. NULL,
  108568. 0
  108569. };
  108570. static long _huff_lengthlist_line_2048x27_0sub0[] = {
  108571. 5, 5, 5, 5, 5, 5, 6, 5, 6, 5, 6, 5, 6, 5, 6, 5,
  108572. 6, 5, 7, 5, 7, 5, 7, 5, 8, 5, 8, 5, 8, 5, 9, 5,
  108573. 9, 6,10, 6,10, 6,11, 6,11, 6,11, 6,11, 6,11, 6,
  108574. 11, 6,11, 6,12, 7,11, 7,11, 7,11, 7,11, 7,10, 7,
  108575. 11, 7,11, 7,12, 7,11, 8,11, 8,11, 8,11, 8,13, 8,
  108576. 12, 9,11, 9,11, 9,11,10,12,10,12, 9,12,10,12,11,
  108577. 14,12,16,12,12,11,14,16,17,17,17,17,17,17,17,17,
  108578. 17,17,17,17,17,17,17,17,17,17,17,17,16,16,16,16,
  108579. };
  108580. static static_codebook _huff_book_line_2048x27_0sub0 = {
  108581. 1, 128,
  108582. _huff_lengthlist_line_2048x27_0sub0,
  108583. 0, 0, 0, 0, 0,
  108584. NULL,
  108585. NULL,
  108586. NULL,
  108587. NULL,
  108588. 0
  108589. };
  108590. static long _huff_lengthlist_line_2048x27_1sub0[] = {
  108591. 4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5,
  108592. 5, 5, 6, 6, 6, 6, 6, 6, 7, 6, 7, 6, 7, 6, 7, 6,
  108593. };
  108594. static static_codebook _huff_book_line_2048x27_1sub0 = {
  108595. 1, 32,
  108596. _huff_lengthlist_line_2048x27_1sub0,
  108597. 0, 0, 0, 0, 0,
  108598. NULL,
  108599. NULL,
  108600. NULL,
  108601. NULL,
  108602. 0
  108603. };
  108604. static long _huff_lengthlist_line_2048x27_1sub1[] = {
  108605. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108606. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108607. 6, 5, 7, 5, 7, 4, 7, 4, 8, 4, 8, 4, 8, 4, 8, 3,
  108608. 8, 4, 9, 4, 9, 4, 9, 4, 9, 4, 9, 5, 9, 5, 9, 6,
  108609. 9, 7, 9, 8, 9, 9, 9,10, 9,11, 9,14, 9,15,10,15,
  108610. 10,15,10,15,10,15,11,15,10,14,12,14,11,14,13,14,
  108611. 13,15,15,15,12,15,15,15,13,15,13,15,13,15,15,15,
  108612. 15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,14,
  108613. };
  108614. static static_codebook _huff_book_line_2048x27_1sub1 = {
  108615. 1, 128,
  108616. _huff_lengthlist_line_2048x27_1sub1,
  108617. 0, 0, 0, 0, 0,
  108618. NULL,
  108619. NULL,
  108620. NULL,
  108621. NULL,
  108622. 0
  108623. };
  108624. static long _huff_lengthlist_line_2048x27_2sub0[] = {
  108625. 2, 4, 5, 4, 5, 4, 5, 4, 5, 5, 5, 5, 5, 5, 6, 5,
  108626. 6, 5, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8,
  108627. };
  108628. static static_codebook _huff_book_line_2048x27_2sub0 = {
  108629. 1, 32,
  108630. _huff_lengthlist_line_2048x27_2sub0,
  108631. 0, 0, 0, 0, 0,
  108632. NULL,
  108633. NULL,
  108634. NULL,
  108635. NULL,
  108636. 0
  108637. };
  108638. static long _huff_lengthlist_line_2048x27_2sub1[] = {
  108639. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108640. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108641. 3, 4, 3, 4, 3, 4, 4, 5, 4, 5, 5, 5, 6, 6, 6, 7,
  108642. 6, 8, 6, 8, 6, 9, 7,10, 7,10, 7,10, 7,12, 7,12,
  108643. 7,12, 9,12,11,12,10,12,10,12,11,12,12,12,10,12,
  108644. 10,12,10,12, 9,12,11,12,12,12,12,12,11,12,11,12,
  108645. 12,12,12,12,12,12,12,12,10,10,12,12,12,12,12,10,
  108646. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  108647. };
  108648. static static_codebook _huff_book_line_2048x27_2sub1 = {
  108649. 1, 128,
  108650. _huff_lengthlist_line_2048x27_2sub1,
  108651. 0, 0, 0, 0, 0,
  108652. NULL,
  108653. NULL,
  108654. NULL,
  108655. NULL,
  108656. 0
  108657. };
  108658. static long _huff_lengthlist_line_2048x27_3sub1[] = {
  108659. 0, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
  108660. 5, 5,
  108661. };
  108662. static static_codebook _huff_book_line_2048x27_3sub1 = {
  108663. 1, 18,
  108664. _huff_lengthlist_line_2048x27_3sub1,
  108665. 0, 0, 0, 0, 0,
  108666. NULL,
  108667. NULL,
  108668. NULL,
  108669. NULL,
  108670. 0
  108671. };
  108672. static long _huff_lengthlist_line_2048x27_3sub2[] = {
  108673. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108674. 0, 0, 3, 3, 3, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 6,
  108675. 6, 7, 6, 7, 6, 8, 6, 9, 7, 9, 7, 9, 9,11, 9,12,
  108676. 10,12,
  108677. };
  108678. static static_codebook _huff_book_line_2048x27_3sub2 = {
  108679. 1, 50,
  108680. _huff_lengthlist_line_2048x27_3sub2,
  108681. 0, 0, 0, 0, 0,
  108682. NULL,
  108683. NULL,
  108684. NULL,
  108685. NULL,
  108686. 0
  108687. };
  108688. static long _huff_lengthlist_line_2048x27_3sub3[] = {
  108689. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108690. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108691. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108692. 0, 0, 3, 6, 3, 7, 3, 7, 5, 7, 7, 7, 7, 7, 6, 7,
  108693. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  108694. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  108695. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  108696. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  108697. };
  108698. static static_codebook _huff_book_line_2048x27_3sub3 = {
  108699. 1, 128,
  108700. _huff_lengthlist_line_2048x27_3sub3,
  108701. 0, 0, 0, 0, 0,
  108702. NULL,
  108703. NULL,
  108704. NULL,
  108705. NULL,
  108706. 0
  108707. };
  108708. static long _huff_lengthlist_line_2048x27_4sub1[] = {
  108709. 0, 3, 4, 4, 4, 4, 4, 4, 4, 4, 5, 4, 5, 4, 5, 4,
  108710. 4, 5,
  108711. };
  108712. static static_codebook _huff_book_line_2048x27_4sub1 = {
  108713. 1, 18,
  108714. _huff_lengthlist_line_2048x27_4sub1,
  108715. 0, 0, 0, 0, 0,
  108716. NULL,
  108717. NULL,
  108718. NULL,
  108719. NULL,
  108720. 0
  108721. };
  108722. static long _huff_lengthlist_line_2048x27_4sub2[] = {
  108723. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108724. 0, 0, 3, 2, 4, 3, 4, 4, 4, 5, 5, 6, 5, 6, 5, 7,
  108725. 6, 6, 6, 7, 7, 7, 8, 9, 9, 9,12,10,11,10,10,12,
  108726. 10,10,
  108727. };
  108728. static static_codebook _huff_book_line_2048x27_4sub2 = {
  108729. 1, 50,
  108730. _huff_lengthlist_line_2048x27_4sub2,
  108731. 0, 0, 0, 0, 0,
  108732. NULL,
  108733. NULL,
  108734. NULL,
  108735. NULL,
  108736. 0
  108737. };
  108738. static long _huff_lengthlist_line_2048x27_4sub3[] = {
  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, 3, 6, 5, 7, 5, 7, 7, 7, 7, 7, 5, 7, 5, 7,
  108743. 5, 7, 5, 7, 7, 7, 7, 7, 4, 7, 7, 7, 7, 7, 7, 7,
  108744. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  108745. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  108746. 7, 7, 7, 7, 7, 7, 7, 6, 6, 6, 6, 6, 6, 6, 6, 6,
  108747. };
  108748. static static_codebook _huff_book_line_2048x27_4sub3 = {
  108749. 1, 128,
  108750. _huff_lengthlist_line_2048x27_4sub3,
  108751. 0, 0, 0, 0, 0,
  108752. NULL,
  108753. NULL,
  108754. NULL,
  108755. NULL,
  108756. 0
  108757. };
  108758. static long _huff_lengthlist_line_256x4low_class0[] = {
  108759. 4, 5, 6,11, 5, 5, 6,10, 7, 7, 6, 6,14,13, 9, 9,
  108760. 6, 6, 6,10, 6, 6, 6, 9, 8, 7, 7, 9,14,12, 8,11,
  108761. 8, 7, 7,11, 8, 8, 7,11, 9, 9, 7, 9,13,11, 9,13,
  108762. 19,19,18,19,15,16,16,19,11,11,10,13,10,10, 9,15,
  108763. 5, 5, 6,13, 6, 6, 6,11, 8, 7, 6, 7,14,11,10,11,
  108764. 6, 6, 6,12, 7, 6, 6,11, 8, 7, 7,11,13,11, 9,11,
  108765. 9, 7, 6,12, 8, 7, 6,12, 9, 8, 8,11,13,10, 7,13,
  108766. 19,19,17,19,17,14,14,19,12,10, 8,12,13,10, 9,16,
  108767. 7, 8, 7,12, 7, 7, 7,11, 8, 7, 7, 8,12,12,11,11,
  108768. 8, 8, 7,12, 8, 7, 6,11, 8, 7, 7,10,10,11,10,11,
  108769. 9, 8, 8,13, 9, 8, 7,12,10, 9, 7,11, 9, 8, 7,11,
  108770. 18,18,15,18,18,16,17,18,15,11,10,18,11, 9, 9,18,
  108771. 16,16,13,16,12,11,10,16,12,11, 9, 6,15,12,11,13,
  108772. 16,16,14,14,13,11,12,16,12, 9, 9,13,13,10,10,12,
  108773. 17,18,17,17,14,15,14,16,14,12,14,15,12,10,11,12,
  108774. 18,18,18,18,18,18,18,18,18,12,13,18,16,11, 9,18,
  108775. };
  108776. static static_codebook _huff_book_line_256x4low_class0 = {
  108777. 1, 256,
  108778. _huff_lengthlist_line_256x4low_class0,
  108779. 0, 0, 0, 0, 0,
  108780. NULL,
  108781. NULL,
  108782. NULL,
  108783. NULL,
  108784. 0
  108785. };
  108786. static long _huff_lengthlist_line_256x4low_0sub0[] = {
  108787. 1, 3, 2, 3,
  108788. };
  108789. static static_codebook _huff_book_line_256x4low_0sub0 = {
  108790. 1, 4,
  108791. _huff_lengthlist_line_256x4low_0sub0,
  108792. 0, 0, 0, 0, 0,
  108793. NULL,
  108794. NULL,
  108795. NULL,
  108796. NULL,
  108797. 0
  108798. };
  108799. static long _huff_lengthlist_line_256x4low_0sub1[] = {
  108800. 0, 0, 0, 0, 2, 3, 2, 3, 3, 3,
  108801. };
  108802. static static_codebook _huff_book_line_256x4low_0sub1 = {
  108803. 1, 10,
  108804. _huff_lengthlist_line_256x4low_0sub1,
  108805. 0, 0, 0, 0, 0,
  108806. NULL,
  108807. NULL,
  108808. NULL,
  108809. NULL,
  108810. 0
  108811. };
  108812. static long _huff_lengthlist_line_256x4low_0sub2[] = {
  108813. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 3, 3, 4, 3, 4,
  108814. 4, 4, 4, 4, 5, 5, 5, 6, 6,
  108815. };
  108816. static static_codebook _huff_book_line_256x4low_0sub2 = {
  108817. 1, 25,
  108818. _huff_lengthlist_line_256x4low_0sub2,
  108819. 0, 0, 0, 0, 0,
  108820. NULL,
  108821. NULL,
  108822. NULL,
  108823. NULL,
  108824. 0
  108825. };
  108826. static long _huff_lengthlist_line_256x4low_0sub3[] = {
  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, 3, 4, 2, 4, 3, 5, 4,
  108829. 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 7, 7, 8, 6, 9,
  108830. 7,12,11,16,13,16,12,15,13,15,12,14,12,15,15,15,
  108831. };
  108832. static static_codebook _huff_book_line_256x4low_0sub3 = {
  108833. 1, 64,
  108834. _huff_lengthlist_line_256x4low_0sub3,
  108835. 0, 0, 0, 0, 0,
  108836. NULL,
  108837. NULL,
  108838. NULL,
  108839. NULL,
  108840. 0
  108841. };
  108842. /********* End of inlined file: floor_books.h *********/
  108843. static static_codebook *_floor_128x4_books[]={
  108844. &_huff_book_line_128x4_class0,
  108845. &_huff_book_line_128x4_0sub0,
  108846. &_huff_book_line_128x4_0sub1,
  108847. &_huff_book_line_128x4_0sub2,
  108848. &_huff_book_line_128x4_0sub3,
  108849. };
  108850. static static_codebook *_floor_256x4_books[]={
  108851. &_huff_book_line_256x4_class0,
  108852. &_huff_book_line_256x4_0sub0,
  108853. &_huff_book_line_256x4_0sub1,
  108854. &_huff_book_line_256x4_0sub2,
  108855. &_huff_book_line_256x4_0sub3,
  108856. };
  108857. static static_codebook *_floor_128x7_books[]={
  108858. &_huff_book_line_128x7_class0,
  108859. &_huff_book_line_128x7_class1,
  108860. &_huff_book_line_128x7_0sub1,
  108861. &_huff_book_line_128x7_0sub2,
  108862. &_huff_book_line_128x7_0sub3,
  108863. &_huff_book_line_128x7_1sub1,
  108864. &_huff_book_line_128x7_1sub2,
  108865. &_huff_book_line_128x7_1sub3,
  108866. };
  108867. static static_codebook *_floor_256x7_books[]={
  108868. &_huff_book_line_256x7_class0,
  108869. &_huff_book_line_256x7_class1,
  108870. &_huff_book_line_256x7_0sub1,
  108871. &_huff_book_line_256x7_0sub2,
  108872. &_huff_book_line_256x7_0sub3,
  108873. &_huff_book_line_256x7_1sub1,
  108874. &_huff_book_line_256x7_1sub2,
  108875. &_huff_book_line_256x7_1sub3,
  108876. };
  108877. static static_codebook *_floor_128x11_books[]={
  108878. &_huff_book_line_128x11_class1,
  108879. &_huff_book_line_128x11_class2,
  108880. &_huff_book_line_128x11_class3,
  108881. &_huff_book_line_128x11_0sub0,
  108882. &_huff_book_line_128x11_1sub0,
  108883. &_huff_book_line_128x11_1sub1,
  108884. &_huff_book_line_128x11_2sub1,
  108885. &_huff_book_line_128x11_2sub2,
  108886. &_huff_book_line_128x11_2sub3,
  108887. &_huff_book_line_128x11_3sub1,
  108888. &_huff_book_line_128x11_3sub2,
  108889. &_huff_book_line_128x11_3sub3,
  108890. };
  108891. static static_codebook *_floor_128x17_books[]={
  108892. &_huff_book_line_128x17_class1,
  108893. &_huff_book_line_128x17_class2,
  108894. &_huff_book_line_128x17_class3,
  108895. &_huff_book_line_128x17_0sub0,
  108896. &_huff_book_line_128x17_1sub0,
  108897. &_huff_book_line_128x17_1sub1,
  108898. &_huff_book_line_128x17_2sub1,
  108899. &_huff_book_line_128x17_2sub2,
  108900. &_huff_book_line_128x17_2sub3,
  108901. &_huff_book_line_128x17_3sub1,
  108902. &_huff_book_line_128x17_3sub2,
  108903. &_huff_book_line_128x17_3sub3,
  108904. };
  108905. static static_codebook *_floor_256x4low_books[]={
  108906. &_huff_book_line_256x4low_class0,
  108907. &_huff_book_line_256x4low_0sub0,
  108908. &_huff_book_line_256x4low_0sub1,
  108909. &_huff_book_line_256x4low_0sub2,
  108910. &_huff_book_line_256x4low_0sub3,
  108911. };
  108912. static static_codebook *_floor_1024x27_books[]={
  108913. &_huff_book_line_1024x27_class1,
  108914. &_huff_book_line_1024x27_class2,
  108915. &_huff_book_line_1024x27_class3,
  108916. &_huff_book_line_1024x27_class4,
  108917. &_huff_book_line_1024x27_0sub0,
  108918. &_huff_book_line_1024x27_1sub0,
  108919. &_huff_book_line_1024x27_1sub1,
  108920. &_huff_book_line_1024x27_2sub0,
  108921. &_huff_book_line_1024x27_2sub1,
  108922. &_huff_book_line_1024x27_3sub1,
  108923. &_huff_book_line_1024x27_3sub2,
  108924. &_huff_book_line_1024x27_3sub3,
  108925. &_huff_book_line_1024x27_4sub1,
  108926. &_huff_book_line_1024x27_4sub2,
  108927. &_huff_book_line_1024x27_4sub3,
  108928. };
  108929. static static_codebook *_floor_2048x27_books[]={
  108930. &_huff_book_line_2048x27_class1,
  108931. &_huff_book_line_2048x27_class2,
  108932. &_huff_book_line_2048x27_class3,
  108933. &_huff_book_line_2048x27_class4,
  108934. &_huff_book_line_2048x27_0sub0,
  108935. &_huff_book_line_2048x27_1sub0,
  108936. &_huff_book_line_2048x27_1sub1,
  108937. &_huff_book_line_2048x27_2sub0,
  108938. &_huff_book_line_2048x27_2sub1,
  108939. &_huff_book_line_2048x27_3sub1,
  108940. &_huff_book_line_2048x27_3sub2,
  108941. &_huff_book_line_2048x27_3sub3,
  108942. &_huff_book_line_2048x27_4sub1,
  108943. &_huff_book_line_2048x27_4sub2,
  108944. &_huff_book_line_2048x27_4sub3,
  108945. };
  108946. static static_codebook *_floor_512x17_books[]={
  108947. &_huff_book_line_512x17_class1,
  108948. &_huff_book_line_512x17_class2,
  108949. &_huff_book_line_512x17_class3,
  108950. &_huff_book_line_512x17_0sub0,
  108951. &_huff_book_line_512x17_1sub0,
  108952. &_huff_book_line_512x17_1sub1,
  108953. &_huff_book_line_512x17_2sub1,
  108954. &_huff_book_line_512x17_2sub2,
  108955. &_huff_book_line_512x17_2sub3,
  108956. &_huff_book_line_512x17_3sub1,
  108957. &_huff_book_line_512x17_3sub2,
  108958. &_huff_book_line_512x17_3sub3,
  108959. };
  108960. static static_codebook **_floor_books[10]={
  108961. _floor_128x4_books,
  108962. _floor_256x4_books,
  108963. _floor_128x7_books,
  108964. _floor_256x7_books,
  108965. _floor_128x11_books,
  108966. _floor_128x17_books,
  108967. _floor_256x4low_books,
  108968. _floor_1024x27_books,
  108969. _floor_2048x27_books,
  108970. _floor_512x17_books,
  108971. };
  108972. static vorbis_info_floor1 _floor[10]={
  108973. {
  108974. 1,{0},{4},{2},{0},
  108975. {{1,2,3,4}},
  108976. 4,{0,128, 33,8,16,70},
  108977. 60,30,500, 1.,18., -1
  108978. },
  108979. {
  108980. 1,{0},{4},{2},{0},
  108981. {{1,2,3,4}},
  108982. 4,{0,256, 66,16,32,140},
  108983. 60,30,500, 1.,18., -1
  108984. },
  108985. {
  108986. 2,{0,1},{3,4},{2,2},{0,1},
  108987. {{-1,2,3,4},{-1,5,6,7}},
  108988. 4,{0,128, 14,4,58, 2,8,28,90},
  108989. 60,30,500, 1.,18., -1
  108990. },
  108991. {
  108992. 2,{0,1},{3,4},{2,2},{0,1},
  108993. {{-1,2,3,4},{-1,5,6,7}},
  108994. 4,{0,256, 28,8,116, 4,16,56,180},
  108995. 60,30,500, 1.,18., -1
  108996. },
  108997. {
  108998. 4,{0,1,2,3},{2,3,3,3},{0,1,2,2},{-1,0,1,2},
  108999. {{3},{4,5},{-1,6,7,8},{-1,9,10,11}},
  109000. 2,{0,128, 8,33, 4,16,70, 2,6,12, 23,46,90},
  109001. 60,30,500, 1,18., -1
  109002. },
  109003. {
  109004. 6,{0,1,1,2,3,3},{2,3,3,3},{0,1,2,2},{-1,0,1,2},
  109005. {{3},{4,5},{-1,6,7,8},{-1,9,10,11}},
  109006. 2,{0,128, 12,46, 4,8,16, 23,33,70, 2,6,10, 14,19,28, 39,58,90},
  109007. 60,30,500, 1,18., -1
  109008. },
  109009. {
  109010. 1,{0},{4},{2},{0},
  109011. {{1,2,3,4}},
  109012. 4,{0,256, 66,16,32,140},
  109013. 60,30,500, 1.,18., -1
  109014. },
  109015. {
  109016. 8,{0,1,2,2,3,3,4,4},{3,4,3,4,3},{0,1,1,2,2},{-1,0,1,2,3},
  109017. {{4},{5,6},{7,8},{-1,9,10,11},{-1,12,13,14}},
  109018. 2,{0,1024, 93,23,372, 6,46,186,750, 14,33,65, 130,260,556,
  109019. 3,10,18,28, 39,55,79,111, 158,220,312, 464,650,850},
  109020. 60,30,500, 3,18., -1 /* lowpass */
  109021. },
  109022. {
  109023. 8,{0,1,2,2,3,3,4,4},{3,4,3,4,3},{0,1,1,2,2},{-1,0,1,2,3},
  109024. {{4},{5,6},{7,8},{-1,9,10,11},{-1,12,13,14}},
  109025. 2,{0,2048, 186,46,744, 12,92,372,1500, 28,66,130, 260,520,1112,
  109026. 6,20,36,56, 78,110,158,222, 316,440,624, 928,1300,1700},
  109027. 60,30,500, 3,18., -1 /* lowpass */
  109028. },
  109029. {
  109030. 6,{0,1,1,2,3,3},{2,3,3,3},{0,1,2,2},{-1,0,1,2},
  109031. {{3},{4,5},{-1,6,7,8},{-1,9,10,11}},
  109032. 2,{0,512, 46,186, 16,33,65, 93,130,278,
  109033. 7,23,39, 55,79,110, 156,232,360},
  109034. 60,30,500, 1,18., -1 /* lowpass! */
  109035. },
  109036. };
  109037. /********* End of inlined file: floor_all.h *********/
  109038. /********* Start of inlined file: residue_44.h *********/
  109039. /********* Start of inlined file: res_books_stereo.h *********/
  109040. static long _vq_quantlist__16c0_s_p1_0[] = {
  109041. 1,
  109042. 0,
  109043. 2,
  109044. };
  109045. static long _vq_lengthlist__16c0_s_p1_0[] = {
  109046. 1, 4, 4, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0, 0, 0, 0,
  109047. 0, 0, 5, 7, 7, 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, 5, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9,10, 0, 0, 0,
  109052. 0, 0, 0, 7, 9,10, 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, 5, 8, 8, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0,
  109057. 0, 0, 0, 0, 7, 9, 9, 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, 5, 8, 8, 0, 0, 0, 0,
  109092. 0, 0, 8,10,10, 0, 0, 0, 0, 0, 0, 8,10,10, 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, 7,10,10, 0, 0, 0,
  109097. 0, 0, 0, 9, 9,12, 0, 0, 0, 0, 0, 0,10,12,11, 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, 7,10,10, 0, 0,
  109102. 0, 0, 0, 0, 9,12,10, 0, 0, 0, 0, 0, 0,10,11,12,
  109103. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109104. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109105. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109106. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109107. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109108. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109109. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109110. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109111. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109112. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109113. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109114. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109115. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109116. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109117. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109118. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109119. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109120. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109121. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109122. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109123. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109124. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109125. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109126. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109127. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109128. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109129. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109130. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109131. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109132. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109133. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109134. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109135. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109136. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109137. 0, 0, 5, 8, 8, 0, 0, 0, 0, 0, 0, 8,10,10, 0, 0,
  109138. 0, 0, 0, 0, 8,10,10, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109139. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109140. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109141. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109142. 0, 0, 0, 7,10,10, 0, 0, 0, 0, 0, 0,10,12,11, 0,
  109143. 0, 0, 0, 0, 0, 9,10,12, 0, 0, 0, 0, 0, 0, 0, 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, 7,10,10, 0, 0, 0, 0, 0, 0,10,11,12,
  109148. 0, 0, 0, 0, 0, 0, 9,12, 9, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109184. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109185. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109186. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109187. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109188. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109189. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109190. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109191. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109192. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109193. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109194. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109195. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109196. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109197. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109198. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109199. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109200. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109201. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109202. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109203. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109204. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109205. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109206. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109207. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109208. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109209. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109210. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109211. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109212. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109213. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109214. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109215. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109216. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109217. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109218. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109219. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109220. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109221. 0, 0, 0, 0, 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109255. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109256. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109257. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109258. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109259. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109260. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109261. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109262. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109263. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109264. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109265. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109266. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109267. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109268. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109269. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109270. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109271. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109272. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109273. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109274. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109275. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109276. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109277. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109278. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109279. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109280. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109281. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109282. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109283. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109284. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109285. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109286. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109287. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109288. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109289. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109290. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109291. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109292. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109293. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109294. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109295. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109296. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109297. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109298. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109299. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109300. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109301. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109302. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109303. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109304. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109305. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109306. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109307. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109308. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109309. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109310. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109311. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109312. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109313. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109314. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109315. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109316. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109317. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109318. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109319. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109320. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109321. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109322. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109323. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109324. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109325. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109326. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109327. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109328. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109329. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109330. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109331. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109332. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109333. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109334. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109335. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109336. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109337. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109338. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109339. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109340. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109341. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109342. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109343. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109344. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109345. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109346. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109347. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109348. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109349. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109350. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109351. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109352. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109353. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109354. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109355. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109356. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109357. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109358. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109359. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109360. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109361. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109362. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109363. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109364. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109365. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109366. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109367. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109368. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109369. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109370. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109371. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109372. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109373. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109374. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109375. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109376. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109377. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109378. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109379. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109380. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109381. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109382. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109383. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109384. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109385. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109386. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109387. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109388. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109389. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109390. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109391. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109392. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109393. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109394. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109395. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109396. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109397. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109398. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109399. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109400. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109401. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109402. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109403. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109404. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109405. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109406. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109407. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109408. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109409. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109410. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109411. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109412. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109413. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109414. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109415. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109416. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109417. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109418. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109419. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109420. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109421. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109422. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109423. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109424. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109425. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109426. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109427. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109428. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109429. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109430. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109431. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109432. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109433. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109434. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109435. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109436. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109437. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109438. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109439. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109440. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109441. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109442. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109443. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109444. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109445. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109446. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109447. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109448. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109449. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109450. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109451. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109452. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109453. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109454. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109455. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109456. 0,
  109457. };
  109458. static float _vq_quantthresh__16c0_s_p1_0[] = {
  109459. -0.5, 0.5,
  109460. };
  109461. static long _vq_quantmap__16c0_s_p1_0[] = {
  109462. 1, 0, 2,
  109463. };
  109464. static encode_aux_threshmatch _vq_auxt__16c0_s_p1_0 = {
  109465. _vq_quantthresh__16c0_s_p1_0,
  109466. _vq_quantmap__16c0_s_p1_0,
  109467. 3,
  109468. 3
  109469. };
  109470. static static_codebook _16c0_s_p1_0 = {
  109471. 8, 6561,
  109472. _vq_lengthlist__16c0_s_p1_0,
  109473. 1, -535822336, 1611661312, 2, 0,
  109474. _vq_quantlist__16c0_s_p1_0,
  109475. NULL,
  109476. &_vq_auxt__16c0_s_p1_0,
  109477. NULL,
  109478. 0
  109479. };
  109480. static long _vq_quantlist__16c0_s_p2_0[] = {
  109481. 2,
  109482. 1,
  109483. 3,
  109484. 0,
  109485. 4,
  109486. };
  109487. static long _vq_lengthlist__16c0_s_p2_0[] = {
  109488. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109489. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109490. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109491. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109492. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109493. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109494. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109495. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109496. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109497. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109498. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109499. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109500. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109501. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109502. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109503. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109504. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109505. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109506. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109507. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109508. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109509. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109510. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109511. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109512. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109513. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109514. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109515. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109516. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109517. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109518. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109519. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109520. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109521. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109522. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109523. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109524. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109525. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109526. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109527. 0,
  109528. };
  109529. static float _vq_quantthresh__16c0_s_p2_0[] = {
  109530. -1.5, -0.5, 0.5, 1.5,
  109531. };
  109532. static long _vq_quantmap__16c0_s_p2_0[] = {
  109533. 3, 1, 0, 2, 4,
  109534. };
  109535. static encode_aux_threshmatch _vq_auxt__16c0_s_p2_0 = {
  109536. _vq_quantthresh__16c0_s_p2_0,
  109537. _vq_quantmap__16c0_s_p2_0,
  109538. 5,
  109539. 5
  109540. };
  109541. static static_codebook _16c0_s_p2_0 = {
  109542. 4, 625,
  109543. _vq_lengthlist__16c0_s_p2_0,
  109544. 1, -533725184, 1611661312, 3, 0,
  109545. _vq_quantlist__16c0_s_p2_0,
  109546. NULL,
  109547. &_vq_auxt__16c0_s_p2_0,
  109548. NULL,
  109549. 0
  109550. };
  109551. static long _vq_quantlist__16c0_s_p3_0[] = {
  109552. 2,
  109553. 1,
  109554. 3,
  109555. 0,
  109556. 4,
  109557. };
  109558. static long _vq_lengthlist__16c0_s_p3_0[] = {
  109559. 1, 4, 4, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109560. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 6, 6, 7, 6, 0, 0,
  109561. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109562. 0, 0, 4, 6, 6, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109563. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 6, 6, 9, 9,
  109564. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109565. 0, 0, 0, 0, 6, 6, 6, 9, 9, 0, 0, 0, 0, 0, 0, 0,
  109566. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109567. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109568. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109569. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109570. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109571. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109572. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109573. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109574. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109575. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109576. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109577. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109578. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109579. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109580. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109581. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109582. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109583. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109584. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109585. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109586. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109587. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109588. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109589. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109590. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109591. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109592. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109593. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109594. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109595. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109596. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109597. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109598. 0,
  109599. };
  109600. static float _vq_quantthresh__16c0_s_p3_0[] = {
  109601. -1.5, -0.5, 0.5, 1.5,
  109602. };
  109603. static long _vq_quantmap__16c0_s_p3_0[] = {
  109604. 3, 1, 0, 2, 4,
  109605. };
  109606. static encode_aux_threshmatch _vq_auxt__16c0_s_p3_0 = {
  109607. _vq_quantthresh__16c0_s_p3_0,
  109608. _vq_quantmap__16c0_s_p3_0,
  109609. 5,
  109610. 5
  109611. };
  109612. static static_codebook _16c0_s_p3_0 = {
  109613. 4, 625,
  109614. _vq_lengthlist__16c0_s_p3_0,
  109615. 1, -533725184, 1611661312, 3, 0,
  109616. _vq_quantlist__16c0_s_p3_0,
  109617. NULL,
  109618. &_vq_auxt__16c0_s_p3_0,
  109619. NULL,
  109620. 0
  109621. };
  109622. static long _vq_quantlist__16c0_s_p4_0[] = {
  109623. 4,
  109624. 3,
  109625. 5,
  109626. 2,
  109627. 6,
  109628. 1,
  109629. 7,
  109630. 0,
  109631. 8,
  109632. };
  109633. static long _vq_lengthlist__16c0_s_p4_0[] = {
  109634. 1, 3, 2, 7, 8, 0, 0, 0, 0, 0, 0, 0, 6, 6, 0, 0,
  109635. 0, 0, 0, 0, 0, 6, 6, 0, 0, 0, 0, 0, 0, 0, 7, 7,
  109636. 0, 0, 0, 0, 0, 0, 0, 7, 7, 0, 0, 0, 0, 0, 0, 0,
  109637. 8, 8, 0, 0, 0, 0, 0, 0, 0, 8, 8, 0, 0, 0, 0, 0,
  109638. 0, 0, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109639. 0,
  109640. };
  109641. static float _vq_quantthresh__16c0_s_p4_0[] = {
  109642. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  109643. };
  109644. static long _vq_quantmap__16c0_s_p4_0[] = {
  109645. 7, 5, 3, 1, 0, 2, 4, 6,
  109646. 8,
  109647. };
  109648. static encode_aux_threshmatch _vq_auxt__16c0_s_p4_0 = {
  109649. _vq_quantthresh__16c0_s_p4_0,
  109650. _vq_quantmap__16c0_s_p4_0,
  109651. 9,
  109652. 9
  109653. };
  109654. static static_codebook _16c0_s_p4_0 = {
  109655. 2, 81,
  109656. _vq_lengthlist__16c0_s_p4_0,
  109657. 1, -531628032, 1611661312, 4, 0,
  109658. _vq_quantlist__16c0_s_p4_0,
  109659. NULL,
  109660. &_vq_auxt__16c0_s_p4_0,
  109661. NULL,
  109662. 0
  109663. };
  109664. static long _vq_quantlist__16c0_s_p5_0[] = {
  109665. 4,
  109666. 3,
  109667. 5,
  109668. 2,
  109669. 6,
  109670. 1,
  109671. 7,
  109672. 0,
  109673. 8,
  109674. };
  109675. static long _vq_lengthlist__16c0_s_p5_0[] = {
  109676. 1, 3, 3, 6, 6, 6, 6, 8, 8, 0, 0, 0, 7, 7, 7, 7,
  109677. 8, 8, 0, 0, 0, 7, 7, 7, 7, 8, 8, 0, 0, 0, 7, 7,
  109678. 8, 8, 9, 9, 0, 0, 0, 7, 7, 8, 8, 9, 9, 0, 0, 0,
  109679. 8, 9, 8, 8,10,10, 0, 0, 0, 8, 8, 8, 8,10,10, 0,
  109680. 0, 0,10,10, 9, 9,10,10, 0, 0, 0, 0, 0, 9, 9,10,
  109681. 10,
  109682. };
  109683. static float _vq_quantthresh__16c0_s_p5_0[] = {
  109684. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  109685. };
  109686. static long _vq_quantmap__16c0_s_p5_0[] = {
  109687. 7, 5, 3, 1, 0, 2, 4, 6,
  109688. 8,
  109689. };
  109690. static encode_aux_threshmatch _vq_auxt__16c0_s_p5_0 = {
  109691. _vq_quantthresh__16c0_s_p5_0,
  109692. _vq_quantmap__16c0_s_p5_0,
  109693. 9,
  109694. 9
  109695. };
  109696. static static_codebook _16c0_s_p5_0 = {
  109697. 2, 81,
  109698. _vq_lengthlist__16c0_s_p5_0,
  109699. 1, -531628032, 1611661312, 4, 0,
  109700. _vq_quantlist__16c0_s_p5_0,
  109701. NULL,
  109702. &_vq_auxt__16c0_s_p5_0,
  109703. NULL,
  109704. 0
  109705. };
  109706. static long _vq_quantlist__16c0_s_p6_0[] = {
  109707. 8,
  109708. 7,
  109709. 9,
  109710. 6,
  109711. 10,
  109712. 5,
  109713. 11,
  109714. 4,
  109715. 12,
  109716. 3,
  109717. 13,
  109718. 2,
  109719. 14,
  109720. 1,
  109721. 15,
  109722. 0,
  109723. 16,
  109724. };
  109725. static long _vq_lengthlist__16c0_s_p6_0[] = {
  109726. 1, 3, 4, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,10,10,11,
  109727. 11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,10,11,
  109728. 11,11, 0, 0, 0, 6, 6, 8, 8, 9, 9, 9, 9,10,10,11,
  109729. 11,11,11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,
  109730. 11,11,12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,
  109731. 10,11,11,12,12, 0, 0, 0, 8, 8, 9, 9,10,10,10,10,
  109732. 11,11,12,12,12,12, 0, 0, 0, 8, 8, 9, 9,10,10,10,
  109733. 10,11,11,12,12,12,13, 0, 0, 0, 9, 9, 9, 9,10,10,
  109734. 10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0,10,10,10,
  109735. 10,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9, 9,
  109736. 10,10,11,11,12,12,13,13,13,13, 0, 0, 0, 0, 0, 9,
  109737. 9,10,10,11,11,12,12,13,13,13,14, 0, 0, 0, 0, 0,
  109738. 10,10,10,11,11,11,12,12,13,13,13,14, 0, 0, 0, 0,
  109739. 0, 0, 0,10,10,11,11,12,12,13,13,14,14, 0, 0, 0,
  109740. 0, 0, 0, 0,11,11,12,12,13,13,13,13,14,14, 0, 0,
  109741. 0, 0, 0, 0, 0,11,11,12,12,12,13,13,14,15,14, 0,
  109742. 0, 0, 0, 0, 0, 0,12,12,12,12,13,13,13,14,14,15,
  109743. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,13,13,14,13,14,
  109744. 14,
  109745. };
  109746. static float _vq_quantthresh__16c0_s_p6_0[] = {
  109747. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  109748. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  109749. };
  109750. static long _vq_quantmap__16c0_s_p6_0[] = {
  109751. 15, 13, 11, 9, 7, 5, 3, 1,
  109752. 0, 2, 4, 6, 8, 10, 12, 14,
  109753. 16,
  109754. };
  109755. static encode_aux_threshmatch _vq_auxt__16c0_s_p6_0 = {
  109756. _vq_quantthresh__16c0_s_p6_0,
  109757. _vq_quantmap__16c0_s_p6_0,
  109758. 17,
  109759. 17
  109760. };
  109761. static static_codebook _16c0_s_p6_0 = {
  109762. 2, 289,
  109763. _vq_lengthlist__16c0_s_p6_0,
  109764. 1, -529530880, 1611661312, 5, 0,
  109765. _vq_quantlist__16c0_s_p6_0,
  109766. NULL,
  109767. &_vq_auxt__16c0_s_p6_0,
  109768. NULL,
  109769. 0
  109770. };
  109771. static long _vq_quantlist__16c0_s_p7_0[] = {
  109772. 1,
  109773. 0,
  109774. 2,
  109775. };
  109776. static long _vq_lengthlist__16c0_s_p7_0[] = {
  109777. 1, 4, 4, 6, 6, 6, 7, 6, 6, 4, 7, 7,11,10,10,11,
  109778. 11,10, 4, 7, 7,10,10,10,11,10,10, 6,10,10,11,11,
  109779. 11,11,11,10, 6, 9, 9,11,12,12,11, 9, 9, 6, 9,10,
  109780. 11,12,12,11, 9,10, 7,11,11,11,11,11,12,13,12, 6,
  109781. 9,10,11,10,10,12,13,13, 6,10, 9,11,10,10,11,12,
  109782. 13,
  109783. };
  109784. static float _vq_quantthresh__16c0_s_p7_0[] = {
  109785. -5.5, 5.5,
  109786. };
  109787. static long _vq_quantmap__16c0_s_p7_0[] = {
  109788. 1, 0, 2,
  109789. };
  109790. static encode_aux_threshmatch _vq_auxt__16c0_s_p7_0 = {
  109791. _vq_quantthresh__16c0_s_p7_0,
  109792. _vq_quantmap__16c0_s_p7_0,
  109793. 3,
  109794. 3
  109795. };
  109796. static static_codebook _16c0_s_p7_0 = {
  109797. 4, 81,
  109798. _vq_lengthlist__16c0_s_p7_0,
  109799. 1, -529137664, 1618345984, 2, 0,
  109800. _vq_quantlist__16c0_s_p7_0,
  109801. NULL,
  109802. &_vq_auxt__16c0_s_p7_0,
  109803. NULL,
  109804. 0
  109805. };
  109806. static long _vq_quantlist__16c0_s_p7_1[] = {
  109807. 5,
  109808. 4,
  109809. 6,
  109810. 3,
  109811. 7,
  109812. 2,
  109813. 8,
  109814. 1,
  109815. 9,
  109816. 0,
  109817. 10,
  109818. };
  109819. static long _vq_lengthlist__16c0_s_p7_1[] = {
  109820. 1, 3, 4, 6, 6, 7, 7, 8, 8, 8, 8,10,10,10, 7, 7,
  109821. 8, 8, 8, 9, 9, 9,10,10,10, 6, 7, 8, 8, 8, 8, 9,
  109822. 8,10,10,10, 7, 7, 8, 8, 9, 9, 9, 9,10,10,10, 7,
  109823. 7, 8, 8, 9, 9, 8, 9,10,10,10, 8, 8, 9, 9, 9, 9,
  109824. 9, 9,11,11,11, 8, 8, 9, 9, 9, 9, 9,10,10,11,11,
  109825. 9, 9, 9, 9, 9, 9, 9,10,11,11,11,10,11, 9, 9, 9,
  109826. 9,10, 9,11,11,11,10,11,10,10, 9, 9,10,10,11,11,
  109827. 11,11,11, 9, 9, 9, 9,10,10,
  109828. };
  109829. static float _vq_quantthresh__16c0_s_p7_1[] = {
  109830. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  109831. 3.5, 4.5,
  109832. };
  109833. static long _vq_quantmap__16c0_s_p7_1[] = {
  109834. 9, 7, 5, 3, 1, 0, 2, 4,
  109835. 6, 8, 10,
  109836. };
  109837. static encode_aux_threshmatch _vq_auxt__16c0_s_p7_1 = {
  109838. _vq_quantthresh__16c0_s_p7_1,
  109839. _vq_quantmap__16c0_s_p7_1,
  109840. 11,
  109841. 11
  109842. };
  109843. static static_codebook _16c0_s_p7_1 = {
  109844. 2, 121,
  109845. _vq_lengthlist__16c0_s_p7_1,
  109846. 1, -531365888, 1611661312, 4, 0,
  109847. _vq_quantlist__16c0_s_p7_1,
  109848. NULL,
  109849. &_vq_auxt__16c0_s_p7_1,
  109850. NULL,
  109851. 0
  109852. };
  109853. static long _vq_quantlist__16c0_s_p8_0[] = {
  109854. 6,
  109855. 5,
  109856. 7,
  109857. 4,
  109858. 8,
  109859. 3,
  109860. 9,
  109861. 2,
  109862. 10,
  109863. 1,
  109864. 11,
  109865. 0,
  109866. 12,
  109867. };
  109868. static long _vq_lengthlist__16c0_s_p8_0[] = {
  109869. 1, 4, 4, 7, 7, 7, 7, 7, 6, 8, 8,10,10, 6, 5, 6,
  109870. 8, 8, 8, 8, 8, 8, 8, 9,10,10, 7, 6, 6, 8, 8, 8,
  109871. 8, 8, 8, 8, 8,10,10, 0, 8, 8, 8, 8, 9, 8, 9, 9,
  109872. 9,10,10,10, 0, 9, 8, 8, 8, 9, 9, 8, 8, 9, 9,10,
  109873. 10, 0,12,11, 8, 8, 9, 9, 9, 9,10,10,11,10, 0,12,
  109874. 13, 8, 8, 9,10, 9, 9,11,11,11,12, 0, 0, 0, 8, 8,
  109875. 8, 8,10, 9,12,13,12,14, 0, 0, 0, 8, 8, 8, 9,10,
  109876. 10,12,12,13,14, 0, 0, 0,13,13, 9, 9,11,11, 0, 0,
  109877. 14, 0, 0, 0, 0,14,14,10,10,12,11,12,14,14,14, 0,
  109878. 0, 0, 0, 0,11,11,13,13,14,13,14,14, 0, 0, 0, 0,
  109879. 0,12,13,13,12,13,14,14,14,
  109880. };
  109881. static float _vq_quantthresh__16c0_s_p8_0[] = {
  109882. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  109883. 12.5, 17.5, 22.5, 27.5,
  109884. };
  109885. static long _vq_quantmap__16c0_s_p8_0[] = {
  109886. 11, 9, 7, 5, 3, 1, 0, 2,
  109887. 4, 6, 8, 10, 12,
  109888. };
  109889. static encode_aux_threshmatch _vq_auxt__16c0_s_p8_0 = {
  109890. _vq_quantthresh__16c0_s_p8_0,
  109891. _vq_quantmap__16c0_s_p8_0,
  109892. 13,
  109893. 13
  109894. };
  109895. static static_codebook _16c0_s_p8_0 = {
  109896. 2, 169,
  109897. _vq_lengthlist__16c0_s_p8_0,
  109898. 1, -526516224, 1616117760, 4, 0,
  109899. _vq_quantlist__16c0_s_p8_0,
  109900. NULL,
  109901. &_vq_auxt__16c0_s_p8_0,
  109902. NULL,
  109903. 0
  109904. };
  109905. static long _vq_quantlist__16c0_s_p8_1[] = {
  109906. 2,
  109907. 1,
  109908. 3,
  109909. 0,
  109910. 4,
  109911. };
  109912. static long _vq_lengthlist__16c0_s_p8_1[] = {
  109913. 1, 4, 3, 5, 5, 7, 7, 7, 6, 6, 7, 7, 7, 5, 5, 7,
  109914. 7, 7, 6, 6, 7, 7, 7, 6, 6,
  109915. };
  109916. static float _vq_quantthresh__16c0_s_p8_1[] = {
  109917. -1.5, -0.5, 0.5, 1.5,
  109918. };
  109919. static long _vq_quantmap__16c0_s_p8_1[] = {
  109920. 3, 1, 0, 2, 4,
  109921. };
  109922. static encode_aux_threshmatch _vq_auxt__16c0_s_p8_1 = {
  109923. _vq_quantthresh__16c0_s_p8_1,
  109924. _vq_quantmap__16c0_s_p8_1,
  109925. 5,
  109926. 5
  109927. };
  109928. static static_codebook _16c0_s_p8_1 = {
  109929. 2, 25,
  109930. _vq_lengthlist__16c0_s_p8_1,
  109931. 1, -533725184, 1611661312, 3, 0,
  109932. _vq_quantlist__16c0_s_p8_1,
  109933. NULL,
  109934. &_vq_auxt__16c0_s_p8_1,
  109935. NULL,
  109936. 0
  109937. };
  109938. static long _vq_quantlist__16c0_s_p9_0[] = {
  109939. 1,
  109940. 0,
  109941. 2,
  109942. };
  109943. static long _vq_lengthlist__16c0_s_p9_0[] = {
  109944. 1, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  109945. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  109946. 8, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  109947. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  109948. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  109949. 7,
  109950. };
  109951. static float _vq_quantthresh__16c0_s_p9_0[] = {
  109952. -157.5, 157.5,
  109953. };
  109954. static long _vq_quantmap__16c0_s_p9_0[] = {
  109955. 1, 0, 2,
  109956. };
  109957. static encode_aux_threshmatch _vq_auxt__16c0_s_p9_0 = {
  109958. _vq_quantthresh__16c0_s_p9_0,
  109959. _vq_quantmap__16c0_s_p9_0,
  109960. 3,
  109961. 3
  109962. };
  109963. static static_codebook _16c0_s_p9_0 = {
  109964. 4, 81,
  109965. _vq_lengthlist__16c0_s_p9_0,
  109966. 1, -518803456, 1628680192, 2, 0,
  109967. _vq_quantlist__16c0_s_p9_0,
  109968. NULL,
  109969. &_vq_auxt__16c0_s_p9_0,
  109970. NULL,
  109971. 0
  109972. };
  109973. static long _vq_quantlist__16c0_s_p9_1[] = {
  109974. 7,
  109975. 6,
  109976. 8,
  109977. 5,
  109978. 9,
  109979. 4,
  109980. 10,
  109981. 3,
  109982. 11,
  109983. 2,
  109984. 12,
  109985. 1,
  109986. 13,
  109987. 0,
  109988. 14,
  109989. };
  109990. static long _vq_lengthlist__16c0_s_p9_1[] = {
  109991. 1, 5, 5, 5, 5, 9,11,11,10,10,10,10,10,10,10, 7,
  109992. 6, 6, 6, 6,10,10,10,10,10,10,10,10,10,10, 7, 6,
  109993. 6, 6, 6,10, 9,10,10,10,10,10,10,10,10,10, 7, 7,
  109994. 8, 9,10,10,10,10,10,10,10,10,10,10,10, 8, 7,10,
  109995. 10,10, 9,10,10,10,10,10,10,10,10,10,10,10,10,10,
  109996. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  109997. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  109998. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  109999. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  110000. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  110001. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  110002. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  110003. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  110004. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  110005. 10,
  110006. };
  110007. static float _vq_quantthresh__16c0_s_p9_1[] = {
  110008. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  110009. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  110010. };
  110011. static long _vq_quantmap__16c0_s_p9_1[] = {
  110012. 13, 11, 9, 7, 5, 3, 1, 0,
  110013. 2, 4, 6, 8, 10, 12, 14,
  110014. };
  110015. static encode_aux_threshmatch _vq_auxt__16c0_s_p9_1 = {
  110016. _vq_quantthresh__16c0_s_p9_1,
  110017. _vq_quantmap__16c0_s_p9_1,
  110018. 15,
  110019. 15
  110020. };
  110021. static static_codebook _16c0_s_p9_1 = {
  110022. 2, 225,
  110023. _vq_lengthlist__16c0_s_p9_1,
  110024. 1, -520986624, 1620377600, 4, 0,
  110025. _vq_quantlist__16c0_s_p9_1,
  110026. NULL,
  110027. &_vq_auxt__16c0_s_p9_1,
  110028. NULL,
  110029. 0
  110030. };
  110031. static long _vq_quantlist__16c0_s_p9_2[] = {
  110032. 10,
  110033. 9,
  110034. 11,
  110035. 8,
  110036. 12,
  110037. 7,
  110038. 13,
  110039. 6,
  110040. 14,
  110041. 5,
  110042. 15,
  110043. 4,
  110044. 16,
  110045. 3,
  110046. 17,
  110047. 2,
  110048. 18,
  110049. 1,
  110050. 19,
  110051. 0,
  110052. 20,
  110053. };
  110054. static long _vq_lengthlist__16c0_s_p9_2[] = {
  110055. 1, 5, 5, 7, 8, 8, 7, 9, 9, 9,12,12,11,12,12,10,
  110056. 10,11,12,12,12,11,12,12, 8, 9, 8, 7, 9,10,10,11,
  110057. 11,10,11,12,10,12,10,12,12,12,11,12,11, 9, 8, 8,
  110058. 9,10, 9, 8, 9,10,12,12,11,11,12,11,10,11,12,11,
  110059. 12,12, 8, 9, 9, 9,10,11,12,11,12,11,11,11,11,12,
  110060. 12,11,11,12,12,11,11, 9, 9, 8, 9, 9,11, 9, 9,10,
  110061. 9,11,11,11,11,12,11,11,10,12,12,12, 9,12,11,10,
  110062. 11,11,11,11,12,12,12,11,11,11,12,10,12,12,12,10,
  110063. 10, 9,10, 9,10,10, 9, 9, 9,10,10,12,10,11,11, 9,
  110064. 11,11,10,11,11,11,10,10,10, 9, 9,10,10, 9, 9,10,
  110065. 11,11,10,11,10,11,10,11,11,10,11,11,11,10, 9,10,
  110066. 10, 9,10, 9, 9,11, 9, 9,11,10,10,11,11,10,10,11,
  110067. 10,11, 8, 9,11,11,10, 9,10,11,11,10,11,11,10,10,
  110068. 10,11,10, 9,10,10,11, 9,10,10, 9,11,10,10,10,10,
  110069. 11,10,11,11, 9,11,10,11,10,10,11,11,10,10,10, 9,
  110070. 10,10,11,11,11, 9,10,10,10,10,10,11,10,10,10, 9,
  110071. 10,10,11,10,10,10,10,10, 9,10,11,10,10,10,10,11,
  110072. 11,11,10,10,10,10,10,11,10,11,10,11,10,10,10, 9,
  110073. 11,11,10,10,10,11,11,10,10,10,10,10,10,10,10,11,
  110074. 11, 9,10,10,10,11,10,11,10,10,10,11, 9,10,11,10,
  110075. 11,10,10, 9,10,10,10,11,10,11,10,10,10,10,10,11,
  110076. 11,10,11,11,10,10,11,11,10, 9, 9,10,10,10,10,10,
  110077. 9,11, 9,10,10,10,11,11,10,10,10,10,11,11,11,10,
  110078. 9, 9,10,10,11,10,10,10,10,10,11,11,11,10,10,10,
  110079. 11,11,11, 9,10,10,10,10, 9,10, 9,10,11,10,11,10,
  110080. 10,11,11,10,11,11,11,11,11,10,11,10,10,10, 9,11,
  110081. 11,10,11,11,11,11,11,11,11,11,11,10,11,10,10,10,
  110082. 10,11,10,10,11, 9,10,10,10,
  110083. };
  110084. static float _vq_quantthresh__16c0_s_p9_2[] = {
  110085. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  110086. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  110087. 6.5, 7.5, 8.5, 9.5,
  110088. };
  110089. static long _vq_quantmap__16c0_s_p9_2[] = {
  110090. 19, 17, 15, 13, 11, 9, 7, 5,
  110091. 3, 1, 0, 2, 4, 6, 8, 10,
  110092. 12, 14, 16, 18, 20,
  110093. };
  110094. static encode_aux_threshmatch _vq_auxt__16c0_s_p9_2 = {
  110095. _vq_quantthresh__16c0_s_p9_2,
  110096. _vq_quantmap__16c0_s_p9_2,
  110097. 21,
  110098. 21
  110099. };
  110100. static static_codebook _16c0_s_p9_2 = {
  110101. 2, 441,
  110102. _vq_lengthlist__16c0_s_p9_2,
  110103. 1, -529268736, 1611661312, 5, 0,
  110104. _vq_quantlist__16c0_s_p9_2,
  110105. NULL,
  110106. &_vq_auxt__16c0_s_p9_2,
  110107. NULL,
  110108. 0
  110109. };
  110110. static long _huff_lengthlist__16c0_s_single[] = {
  110111. 3, 4,19, 7, 9, 7, 8,11, 9,12, 4, 1,19, 6, 7, 7,
  110112. 8,10,11,13,18,18,18,18,18,18,18,18,18,18, 8, 6,
  110113. 18, 8, 9, 9,11,12,14,18, 9, 6,18, 9, 7, 8, 9,11,
  110114. 12,18, 7, 6,18, 8, 7, 7, 7, 9,11,17, 8, 8,18, 9,
  110115. 7, 6, 6, 8,11,17,10,10,18,12, 9, 8, 7, 9,12,18,
  110116. 13,15,18,15,13,11,10,11,15,18,14,18,18,18,18,18,
  110117. 16,16,18,18,
  110118. };
  110119. static static_codebook _huff_book__16c0_s_single = {
  110120. 2, 100,
  110121. _huff_lengthlist__16c0_s_single,
  110122. 0, 0, 0, 0, 0,
  110123. NULL,
  110124. NULL,
  110125. NULL,
  110126. NULL,
  110127. 0
  110128. };
  110129. static long _huff_lengthlist__16c1_s_long[] = {
  110130. 2, 5,20, 7,10, 7, 8,10,11,11, 4, 2,20, 5, 8, 6,
  110131. 7, 9,10,10,20,20,20,20,19,19,19,19,19,19, 7, 5,
  110132. 19, 6,10, 7, 9,11,13,17,11, 8,19,10, 7, 7, 8,10,
  110133. 11,15, 7, 5,19, 7, 7, 5, 6, 9,11,16, 7, 6,19, 8,
  110134. 7, 6, 6, 7, 9,13, 9, 9,19,11, 9, 8, 6, 7, 8,13,
  110135. 12,14,19,16,13,10, 9, 8, 9,13,14,17,19,18,18,17,
  110136. 12,11,11,13,
  110137. };
  110138. static static_codebook _huff_book__16c1_s_long = {
  110139. 2, 100,
  110140. _huff_lengthlist__16c1_s_long,
  110141. 0, 0, 0, 0, 0,
  110142. NULL,
  110143. NULL,
  110144. NULL,
  110145. NULL,
  110146. 0
  110147. };
  110148. static long _vq_quantlist__16c1_s_p1_0[] = {
  110149. 1,
  110150. 0,
  110151. 2,
  110152. };
  110153. static long _vq_lengthlist__16c1_s_p1_0[] = {
  110154. 1, 5, 5, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0, 0, 0, 0,
  110155. 0, 0, 5, 7, 7, 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, 5, 8, 7, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0, 0,
  110160. 0, 0, 0, 7, 8, 9, 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, 5, 7, 8, 0, 0, 0, 0, 0, 0, 7, 9, 8, 0, 0,
  110165. 0, 0, 0, 0, 7, 9, 9, 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, 5, 8, 7, 0, 0, 0, 0,
  110200. 0, 0, 8, 9, 9, 0, 0, 0, 0, 0, 0, 7, 9, 9, 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, 7, 9, 9, 0, 0, 0,
  110205. 0, 0, 0, 9, 9,11, 0, 0, 0, 0, 0, 0, 9,11,10, 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, 7, 9, 9, 0, 0,
  110210. 0, 0, 0, 0, 8,11, 9, 0, 0, 0, 0, 0, 0, 9,10,11,
  110211. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110212. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110213. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110214. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110215. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110216. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110217. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110218. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110219. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110220. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110221. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110222. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110223. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110224. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110225. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110226. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110227. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110228. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110229. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110230. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110231. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110232. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110233. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110234. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110235. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110236. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110237. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110238. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110239. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110240. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110241. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110242. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110243. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110244. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110245. 0, 0, 5, 7, 8, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0,
  110246. 0, 0, 0, 0, 8, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110247. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110248. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110249. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110250. 0, 0, 0, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,11,10, 0,
  110251. 0, 0, 0, 0, 0, 8, 9,11, 0, 0, 0, 0, 0, 0, 0, 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, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,10,11,
  110256. 0, 0, 0, 0, 0, 0, 9,11, 9, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110292. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110293. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110294. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110295. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110296. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110297. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110298. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110299. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110300. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110301. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110302. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110303. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110304. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110305. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110306. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110307. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110308. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110309. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110310. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110311. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110312. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110313. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110314. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110315. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110316. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110317. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110318. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110319. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110320. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110321. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110322. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110323. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110324. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110325. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110326. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110327. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110328. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110329. 0, 0, 0, 0, 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110363. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110364. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110365. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110366. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110367. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110368. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110369. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110370. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110371. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110372. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110373. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110374. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110375. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110376. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110377. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110378. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110379. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110380. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110381. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110382. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110383. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110384. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110385. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110386. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110387. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110388. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110389. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110390. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110391. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110392. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110393. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110394. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110395. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110396. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110397. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110398. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110399. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110400. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110401. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110402. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110403. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110404. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110405. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110406. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110407. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110408. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110409. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110410. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110411. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110412. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110413. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110414. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110415. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110416. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110417. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110418. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110419. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110420. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110421. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110422. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110423. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110424. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110425. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110426. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110427. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110428. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110429. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110430. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110431. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110432. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110433. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110434. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110435. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110436. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110437. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110438. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110439. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110440. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110441. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110442. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110443. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110444. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110445. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110446. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110447. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110448. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110449. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110450. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110451. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110452. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110453. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110454. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110455. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110456. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110457. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110458. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110459. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110460. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110461. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110462. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110463. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110464. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110465. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110466. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110467. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110468. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110469. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110470. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110471. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110472. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110473. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110474. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110475. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110476. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110477. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110478. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110479. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110480. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110481. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110482. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110483. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110484. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110485. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110486. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110487. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110488. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110489. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110490. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110491. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110492. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110493. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110494. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110495. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110496. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110497. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110498. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110499. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110500. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110501. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110502. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110503. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110504. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110505. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110506. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110507. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110508. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110509. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110510. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110511. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110512. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110513. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110514. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110515. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110516. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110517. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110518. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110519. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110520. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110521. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110522. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110523. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110524. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110525. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110526. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110527. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110528. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110529. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110530. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110531. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110532. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110533. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110534. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110535. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110536. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110537. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110538. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110539. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110540. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110541. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110542. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110543. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110544. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110545. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110546. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110547. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110548. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110549. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110550. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110551. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110552. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110553. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110554. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110555. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110556. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110557. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110558. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110559. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110560. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110561. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110562. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110563. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110564. 0,
  110565. };
  110566. static float _vq_quantthresh__16c1_s_p1_0[] = {
  110567. -0.5, 0.5,
  110568. };
  110569. static long _vq_quantmap__16c1_s_p1_0[] = {
  110570. 1, 0, 2,
  110571. };
  110572. static encode_aux_threshmatch _vq_auxt__16c1_s_p1_0 = {
  110573. _vq_quantthresh__16c1_s_p1_0,
  110574. _vq_quantmap__16c1_s_p1_0,
  110575. 3,
  110576. 3
  110577. };
  110578. static static_codebook _16c1_s_p1_0 = {
  110579. 8, 6561,
  110580. _vq_lengthlist__16c1_s_p1_0,
  110581. 1, -535822336, 1611661312, 2, 0,
  110582. _vq_quantlist__16c1_s_p1_0,
  110583. NULL,
  110584. &_vq_auxt__16c1_s_p1_0,
  110585. NULL,
  110586. 0
  110587. };
  110588. static long _vq_quantlist__16c1_s_p2_0[] = {
  110589. 2,
  110590. 1,
  110591. 3,
  110592. 0,
  110593. 4,
  110594. };
  110595. static long _vq_lengthlist__16c1_s_p2_0[] = {
  110596. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110597. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110598. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110599. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110600. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110601. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110602. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110603. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110604. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110605. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110606. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110607. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110608. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110609. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110610. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110611. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110612. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110613. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110614. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110615. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110616. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110617. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110618. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110619. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110620. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110621. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110622. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110623. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110624. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110625. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110626. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110627. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110628. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110629. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110630. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110631. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110632. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110633. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110634. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110635. 0,
  110636. };
  110637. static float _vq_quantthresh__16c1_s_p2_0[] = {
  110638. -1.5, -0.5, 0.5, 1.5,
  110639. };
  110640. static long _vq_quantmap__16c1_s_p2_0[] = {
  110641. 3, 1, 0, 2, 4,
  110642. };
  110643. static encode_aux_threshmatch _vq_auxt__16c1_s_p2_0 = {
  110644. _vq_quantthresh__16c1_s_p2_0,
  110645. _vq_quantmap__16c1_s_p2_0,
  110646. 5,
  110647. 5
  110648. };
  110649. static static_codebook _16c1_s_p2_0 = {
  110650. 4, 625,
  110651. _vq_lengthlist__16c1_s_p2_0,
  110652. 1, -533725184, 1611661312, 3, 0,
  110653. _vq_quantlist__16c1_s_p2_0,
  110654. NULL,
  110655. &_vq_auxt__16c1_s_p2_0,
  110656. NULL,
  110657. 0
  110658. };
  110659. static long _vq_quantlist__16c1_s_p3_0[] = {
  110660. 2,
  110661. 1,
  110662. 3,
  110663. 0,
  110664. 4,
  110665. };
  110666. static long _vq_lengthlist__16c1_s_p3_0[] = {
  110667. 1, 4, 4, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110668. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 5, 5, 7, 7, 0, 0,
  110669. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110670. 0, 0, 4, 5, 5, 7, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110671. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 7, 7, 9, 9,
  110672. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110673. 0, 0, 0, 0, 6, 7, 7, 9, 9, 0, 0, 0, 0, 0, 0, 0,
  110674. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110675. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110676. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110677. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110678. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110679. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110680. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110681. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110682. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110683. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110684. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110685. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110686. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110687. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110688. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110689. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110690. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110691. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110692. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110693. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110694. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110695. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110696. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110697. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110698. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110699. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110700. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110701. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110702. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110703. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110704. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110705. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110706. 0,
  110707. };
  110708. static float _vq_quantthresh__16c1_s_p3_0[] = {
  110709. -1.5, -0.5, 0.5, 1.5,
  110710. };
  110711. static long _vq_quantmap__16c1_s_p3_0[] = {
  110712. 3, 1, 0, 2, 4,
  110713. };
  110714. static encode_aux_threshmatch _vq_auxt__16c1_s_p3_0 = {
  110715. _vq_quantthresh__16c1_s_p3_0,
  110716. _vq_quantmap__16c1_s_p3_0,
  110717. 5,
  110718. 5
  110719. };
  110720. static static_codebook _16c1_s_p3_0 = {
  110721. 4, 625,
  110722. _vq_lengthlist__16c1_s_p3_0,
  110723. 1, -533725184, 1611661312, 3, 0,
  110724. _vq_quantlist__16c1_s_p3_0,
  110725. NULL,
  110726. &_vq_auxt__16c1_s_p3_0,
  110727. NULL,
  110728. 0
  110729. };
  110730. static long _vq_quantlist__16c1_s_p4_0[] = {
  110731. 4,
  110732. 3,
  110733. 5,
  110734. 2,
  110735. 6,
  110736. 1,
  110737. 7,
  110738. 0,
  110739. 8,
  110740. };
  110741. static long _vq_lengthlist__16c1_s_p4_0[] = {
  110742. 1, 2, 3, 7, 7, 0, 0, 0, 0, 0, 0, 0, 6, 6, 0, 0,
  110743. 0, 0, 0, 0, 0, 6, 6, 0, 0, 0, 0, 0, 0, 0, 7, 7,
  110744. 0, 0, 0, 0, 0, 0, 0, 7, 7, 0, 0, 0, 0, 0, 0, 0,
  110745. 8, 8, 0, 0, 0, 0, 0, 0, 0, 8, 9, 0, 0, 0, 0, 0,
  110746. 0, 0,10,10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110747. 0,
  110748. };
  110749. static float _vq_quantthresh__16c1_s_p4_0[] = {
  110750. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  110751. };
  110752. static long _vq_quantmap__16c1_s_p4_0[] = {
  110753. 7, 5, 3, 1, 0, 2, 4, 6,
  110754. 8,
  110755. };
  110756. static encode_aux_threshmatch _vq_auxt__16c1_s_p4_0 = {
  110757. _vq_quantthresh__16c1_s_p4_0,
  110758. _vq_quantmap__16c1_s_p4_0,
  110759. 9,
  110760. 9
  110761. };
  110762. static static_codebook _16c1_s_p4_0 = {
  110763. 2, 81,
  110764. _vq_lengthlist__16c1_s_p4_0,
  110765. 1, -531628032, 1611661312, 4, 0,
  110766. _vq_quantlist__16c1_s_p4_0,
  110767. NULL,
  110768. &_vq_auxt__16c1_s_p4_0,
  110769. NULL,
  110770. 0
  110771. };
  110772. static long _vq_quantlist__16c1_s_p5_0[] = {
  110773. 4,
  110774. 3,
  110775. 5,
  110776. 2,
  110777. 6,
  110778. 1,
  110779. 7,
  110780. 0,
  110781. 8,
  110782. };
  110783. static long _vq_lengthlist__16c1_s_p5_0[] = {
  110784. 1, 3, 3, 5, 5, 6, 6, 8, 8, 0, 0, 0, 7, 7, 7, 7,
  110785. 9, 9, 0, 0, 0, 7, 7, 7, 7, 9, 9, 0, 0, 0, 8, 8,
  110786. 8, 8, 9, 9, 0, 0, 0, 8, 8, 8, 8,10,10, 0, 0, 0,
  110787. 9, 9, 8, 8,10,10, 0, 0, 0, 9, 9, 8, 8,10,10, 0,
  110788. 0, 0,10,10, 9, 9,10,10, 0, 0, 0, 0, 0, 9, 9,10,
  110789. 10,
  110790. };
  110791. static float _vq_quantthresh__16c1_s_p5_0[] = {
  110792. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  110793. };
  110794. static long _vq_quantmap__16c1_s_p5_0[] = {
  110795. 7, 5, 3, 1, 0, 2, 4, 6,
  110796. 8,
  110797. };
  110798. static encode_aux_threshmatch _vq_auxt__16c1_s_p5_0 = {
  110799. _vq_quantthresh__16c1_s_p5_0,
  110800. _vq_quantmap__16c1_s_p5_0,
  110801. 9,
  110802. 9
  110803. };
  110804. static static_codebook _16c1_s_p5_0 = {
  110805. 2, 81,
  110806. _vq_lengthlist__16c1_s_p5_0,
  110807. 1, -531628032, 1611661312, 4, 0,
  110808. _vq_quantlist__16c1_s_p5_0,
  110809. NULL,
  110810. &_vq_auxt__16c1_s_p5_0,
  110811. NULL,
  110812. 0
  110813. };
  110814. static long _vq_quantlist__16c1_s_p6_0[] = {
  110815. 8,
  110816. 7,
  110817. 9,
  110818. 6,
  110819. 10,
  110820. 5,
  110821. 11,
  110822. 4,
  110823. 12,
  110824. 3,
  110825. 13,
  110826. 2,
  110827. 14,
  110828. 1,
  110829. 15,
  110830. 0,
  110831. 16,
  110832. };
  110833. static long _vq_lengthlist__16c1_s_p6_0[] = {
  110834. 1, 3, 3, 6, 6, 8, 8, 9, 9, 9, 9,10,10,11,11,12,
  110835. 12, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,11,11,
  110836. 12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,11,
  110837. 11,12,12, 0, 0, 0, 8, 8, 8, 9,10, 9,10,10,10,10,
  110838. 11,11,12,12, 0, 0, 0, 8, 8, 9, 9,10,10,10,10,11,
  110839. 11,11,12,12,12, 0, 0, 0, 8, 8, 9, 9,10,10,10,10,
  110840. 11,11,12,12,12,12, 0, 0, 0, 8, 8, 9, 9,10,10,10,
  110841. 10,11,11,12,12,13,13, 0, 0, 0, 9, 9, 9, 9,10,10,
  110842. 10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9, 9,10,
  110843. 10,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9, 9,
  110844. 10,10,11,11,12,12,12,12,13,13, 0, 0, 0, 0, 0, 9,
  110845. 9,10,10,11,11,12,12,12,12,13,13, 0, 0, 0, 0, 0,
  110846. 10,10,11,10,11,11,12,12,13,13,13,13, 0, 0, 0, 0,
  110847. 0, 0, 0,10,10,11,11,12,12,13,13,13,13, 0, 0, 0,
  110848. 0, 0, 0, 0,11,11,12,12,12,12,13,13,14,14, 0, 0,
  110849. 0, 0, 0, 0, 0,11,11,12,12,12,12,13,13,14,14, 0,
  110850. 0, 0, 0, 0, 0, 0,12,12,12,12,13,13,13,13,14,14,
  110851. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,13,13,13,13,14,
  110852. 14,
  110853. };
  110854. static float _vq_quantthresh__16c1_s_p6_0[] = {
  110855. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  110856. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  110857. };
  110858. static long _vq_quantmap__16c1_s_p6_0[] = {
  110859. 15, 13, 11, 9, 7, 5, 3, 1,
  110860. 0, 2, 4, 6, 8, 10, 12, 14,
  110861. 16,
  110862. };
  110863. static encode_aux_threshmatch _vq_auxt__16c1_s_p6_0 = {
  110864. _vq_quantthresh__16c1_s_p6_0,
  110865. _vq_quantmap__16c1_s_p6_0,
  110866. 17,
  110867. 17
  110868. };
  110869. static static_codebook _16c1_s_p6_0 = {
  110870. 2, 289,
  110871. _vq_lengthlist__16c1_s_p6_0,
  110872. 1, -529530880, 1611661312, 5, 0,
  110873. _vq_quantlist__16c1_s_p6_0,
  110874. NULL,
  110875. &_vq_auxt__16c1_s_p6_0,
  110876. NULL,
  110877. 0
  110878. };
  110879. static long _vq_quantlist__16c1_s_p7_0[] = {
  110880. 1,
  110881. 0,
  110882. 2,
  110883. };
  110884. static long _vq_lengthlist__16c1_s_p7_0[] = {
  110885. 1, 4, 4, 6, 6, 6, 7, 6, 6, 4, 7, 7,10, 9,10,10,
  110886. 10, 9, 4, 7, 7,10,10,10,11,10,10, 6,10,10,11,11,
  110887. 11,11,10,10, 6,10, 9,11,11,11,11,10,10, 6,10,10,
  110888. 11,11,11,11,10,10, 7,11,11,11,11,11,12,12,11, 6,
  110889. 10,10,11,10,10,11,11,11, 6,10,10,10,11,10,11,11,
  110890. 11,
  110891. };
  110892. static float _vq_quantthresh__16c1_s_p7_0[] = {
  110893. -5.5, 5.5,
  110894. };
  110895. static long _vq_quantmap__16c1_s_p7_0[] = {
  110896. 1, 0, 2,
  110897. };
  110898. static encode_aux_threshmatch _vq_auxt__16c1_s_p7_0 = {
  110899. _vq_quantthresh__16c1_s_p7_0,
  110900. _vq_quantmap__16c1_s_p7_0,
  110901. 3,
  110902. 3
  110903. };
  110904. static static_codebook _16c1_s_p7_0 = {
  110905. 4, 81,
  110906. _vq_lengthlist__16c1_s_p7_0,
  110907. 1, -529137664, 1618345984, 2, 0,
  110908. _vq_quantlist__16c1_s_p7_0,
  110909. NULL,
  110910. &_vq_auxt__16c1_s_p7_0,
  110911. NULL,
  110912. 0
  110913. };
  110914. static long _vq_quantlist__16c1_s_p7_1[] = {
  110915. 5,
  110916. 4,
  110917. 6,
  110918. 3,
  110919. 7,
  110920. 2,
  110921. 8,
  110922. 1,
  110923. 9,
  110924. 0,
  110925. 10,
  110926. };
  110927. static long _vq_lengthlist__16c1_s_p7_1[] = {
  110928. 2, 3, 3, 5, 6, 7, 7, 7, 7, 8, 8,10,10,10, 6, 6,
  110929. 7, 7, 8, 8, 8, 8,10,10,10, 6, 6, 7, 7, 8, 8, 8,
  110930. 8,10,10,10, 7, 7, 7, 7, 8, 8, 8, 8,10,10,10, 7,
  110931. 7, 7, 7, 8, 8, 8, 8,10,10,10, 7, 7, 8, 8, 8, 8,
  110932. 8, 8,10,10,10, 7, 7, 8, 8, 8, 8, 8, 8,10,10,10,
  110933. 8, 8, 8, 8, 8, 8, 9, 9,10,10,10,10,10, 8, 8, 8,
  110934. 8, 9, 9,10,10,10,10,10, 9, 9, 8, 8, 9, 9,10,10,
  110935. 10,10,10, 8, 8, 8, 8, 9, 9,
  110936. };
  110937. static float _vq_quantthresh__16c1_s_p7_1[] = {
  110938. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  110939. 3.5, 4.5,
  110940. };
  110941. static long _vq_quantmap__16c1_s_p7_1[] = {
  110942. 9, 7, 5, 3, 1, 0, 2, 4,
  110943. 6, 8, 10,
  110944. };
  110945. static encode_aux_threshmatch _vq_auxt__16c1_s_p7_1 = {
  110946. _vq_quantthresh__16c1_s_p7_1,
  110947. _vq_quantmap__16c1_s_p7_1,
  110948. 11,
  110949. 11
  110950. };
  110951. static static_codebook _16c1_s_p7_1 = {
  110952. 2, 121,
  110953. _vq_lengthlist__16c1_s_p7_1,
  110954. 1, -531365888, 1611661312, 4, 0,
  110955. _vq_quantlist__16c1_s_p7_1,
  110956. NULL,
  110957. &_vq_auxt__16c1_s_p7_1,
  110958. NULL,
  110959. 0
  110960. };
  110961. static long _vq_quantlist__16c1_s_p8_0[] = {
  110962. 6,
  110963. 5,
  110964. 7,
  110965. 4,
  110966. 8,
  110967. 3,
  110968. 9,
  110969. 2,
  110970. 10,
  110971. 1,
  110972. 11,
  110973. 0,
  110974. 12,
  110975. };
  110976. static long _vq_lengthlist__16c1_s_p8_0[] = {
  110977. 1, 4, 4, 6, 6, 7, 7, 7, 7, 8, 8, 9, 9, 6, 5, 5,
  110978. 7, 8, 8, 9, 8, 8, 9, 9,10,11, 6, 5, 5, 8, 8, 9,
  110979. 9, 8, 8, 9,10,10,11, 0, 8, 8, 8, 9, 9, 9, 9, 9,
  110980. 10,10,11,11, 0, 9, 9, 9, 8, 9, 9, 9, 9,10,10,11,
  110981. 11, 0,13,13, 9, 9,10,10,10,10,11,11,12,12, 0,14,
  110982. 13, 9, 9,10,10,10,10,11,11,12,12, 0, 0, 0,10,10,
  110983. 9, 9,11,11,12,12,13,12, 0, 0, 0,10,10, 9, 9,10,
  110984. 10,12,12,13,13, 0, 0, 0,13,14,11,10,11,11,12,12,
  110985. 13,14, 0, 0, 0,14,14,10,10,11,11,12,12,13,13, 0,
  110986. 0, 0, 0, 0,12,12,12,12,13,13,14,15, 0, 0, 0, 0,
  110987. 0,12,12,12,12,13,13,14,15,
  110988. };
  110989. static float _vq_quantthresh__16c1_s_p8_0[] = {
  110990. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  110991. 12.5, 17.5, 22.5, 27.5,
  110992. };
  110993. static long _vq_quantmap__16c1_s_p8_0[] = {
  110994. 11, 9, 7, 5, 3, 1, 0, 2,
  110995. 4, 6, 8, 10, 12,
  110996. };
  110997. static encode_aux_threshmatch _vq_auxt__16c1_s_p8_0 = {
  110998. _vq_quantthresh__16c1_s_p8_0,
  110999. _vq_quantmap__16c1_s_p8_0,
  111000. 13,
  111001. 13
  111002. };
  111003. static static_codebook _16c1_s_p8_0 = {
  111004. 2, 169,
  111005. _vq_lengthlist__16c1_s_p8_0,
  111006. 1, -526516224, 1616117760, 4, 0,
  111007. _vq_quantlist__16c1_s_p8_0,
  111008. NULL,
  111009. &_vq_auxt__16c1_s_p8_0,
  111010. NULL,
  111011. 0
  111012. };
  111013. static long _vq_quantlist__16c1_s_p8_1[] = {
  111014. 2,
  111015. 1,
  111016. 3,
  111017. 0,
  111018. 4,
  111019. };
  111020. static long _vq_lengthlist__16c1_s_p8_1[] = {
  111021. 2, 3, 3, 5, 5, 6, 6, 6, 5, 5, 6, 6, 6, 5, 5, 6,
  111022. 6, 6, 5, 5, 6, 6, 6, 5, 5,
  111023. };
  111024. static float _vq_quantthresh__16c1_s_p8_1[] = {
  111025. -1.5, -0.5, 0.5, 1.5,
  111026. };
  111027. static long _vq_quantmap__16c1_s_p8_1[] = {
  111028. 3, 1, 0, 2, 4,
  111029. };
  111030. static encode_aux_threshmatch _vq_auxt__16c1_s_p8_1 = {
  111031. _vq_quantthresh__16c1_s_p8_1,
  111032. _vq_quantmap__16c1_s_p8_1,
  111033. 5,
  111034. 5
  111035. };
  111036. static static_codebook _16c1_s_p8_1 = {
  111037. 2, 25,
  111038. _vq_lengthlist__16c1_s_p8_1,
  111039. 1, -533725184, 1611661312, 3, 0,
  111040. _vq_quantlist__16c1_s_p8_1,
  111041. NULL,
  111042. &_vq_auxt__16c1_s_p8_1,
  111043. NULL,
  111044. 0
  111045. };
  111046. static long _vq_quantlist__16c1_s_p9_0[] = {
  111047. 6,
  111048. 5,
  111049. 7,
  111050. 4,
  111051. 8,
  111052. 3,
  111053. 9,
  111054. 2,
  111055. 10,
  111056. 1,
  111057. 11,
  111058. 0,
  111059. 12,
  111060. };
  111061. static long _vq_lengthlist__16c1_s_p9_0[] = {
  111062. 1, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  111063. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  111064. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  111065. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  111066. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  111067. 9, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  111068. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  111069. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  111070. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  111071. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  111072. 8, 8, 8, 8, 8, 8, 8, 8, 8,
  111073. };
  111074. static float _vq_quantthresh__16c1_s_p9_0[] = {
  111075. -1732.5, -1417.5, -1102.5, -787.5, -472.5, -157.5, 157.5, 472.5,
  111076. 787.5, 1102.5, 1417.5, 1732.5,
  111077. };
  111078. static long _vq_quantmap__16c1_s_p9_0[] = {
  111079. 11, 9, 7, 5, 3, 1, 0, 2,
  111080. 4, 6, 8, 10, 12,
  111081. };
  111082. static encode_aux_threshmatch _vq_auxt__16c1_s_p9_0 = {
  111083. _vq_quantthresh__16c1_s_p9_0,
  111084. _vq_quantmap__16c1_s_p9_0,
  111085. 13,
  111086. 13
  111087. };
  111088. static static_codebook _16c1_s_p9_0 = {
  111089. 2, 169,
  111090. _vq_lengthlist__16c1_s_p9_0,
  111091. 1, -513964032, 1628680192, 4, 0,
  111092. _vq_quantlist__16c1_s_p9_0,
  111093. NULL,
  111094. &_vq_auxt__16c1_s_p9_0,
  111095. NULL,
  111096. 0
  111097. };
  111098. static long _vq_quantlist__16c1_s_p9_1[] = {
  111099. 7,
  111100. 6,
  111101. 8,
  111102. 5,
  111103. 9,
  111104. 4,
  111105. 10,
  111106. 3,
  111107. 11,
  111108. 2,
  111109. 12,
  111110. 1,
  111111. 13,
  111112. 0,
  111113. 14,
  111114. };
  111115. static long _vq_lengthlist__16c1_s_p9_1[] = {
  111116. 1, 4, 4, 4, 4, 8, 8,12,13,14,14,14,14,14,14, 6,
  111117. 6, 6, 6, 6,10, 9,14,14,14,14,14,14,14,14, 7, 6,
  111118. 5, 6, 6,10, 9,12,13,13,13,13,13,13,13,13, 7, 7,
  111119. 9, 9,11,11,12,13,13,13,13,13,13,13,13, 7, 7, 8,
  111120. 8,11,12,13,13,13,13,13,13,13,13,13,12,12,10,10,
  111121. 13,12,13,13,13,13,13,13,13,13,13,12,12,10,10,13,
  111122. 13,13,13,13,13,13,13,13,13,13,13,13,13,12,13,12,
  111123. 13,13,13,13,13,13,13,13,13,13,13,13,12,13,13,13,
  111124. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  111125. 13,13,13,13,13,13,13,13,13,13,13,13,12,13,13,13,
  111126. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  111127. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  111128. 13,13,13,13,13,13,13,13,13,12,13,13,13,13,13,13,
  111129. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  111130. 13,
  111131. };
  111132. static float _vq_quantthresh__16c1_s_p9_1[] = {
  111133. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  111134. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  111135. };
  111136. static long _vq_quantmap__16c1_s_p9_1[] = {
  111137. 13, 11, 9, 7, 5, 3, 1, 0,
  111138. 2, 4, 6, 8, 10, 12, 14,
  111139. };
  111140. static encode_aux_threshmatch _vq_auxt__16c1_s_p9_1 = {
  111141. _vq_quantthresh__16c1_s_p9_1,
  111142. _vq_quantmap__16c1_s_p9_1,
  111143. 15,
  111144. 15
  111145. };
  111146. static static_codebook _16c1_s_p9_1 = {
  111147. 2, 225,
  111148. _vq_lengthlist__16c1_s_p9_1,
  111149. 1, -520986624, 1620377600, 4, 0,
  111150. _vq_quantlist__16c1_s_p9_1,
  111151. NULL,
  111152. &_vq_auxt__16c1_s_p9_1,
  111153. NULL,
  111154. 0
  111155. };
  111156. static long _vq_quantlist__16c1_s_p9_2[] = {
  111157. 10,
  111158. 9,
  111159. 11,
  111160. 8,
  111161. 12,
  111162. 7,
  111163. 13,
  111164. 6,
  111165. 14,
  111166. 5,
  111167. 15,
  111168. 4,
  111169. 16,
  111170. 3,
  111171. 17,
  111172. 2,
  111173. 18,
  111174. 1,
  111175. 19,
  111176. 0,
  111177. 20,
  111178. };
  111179. static long _vq_lengthlist__16c1_s_p9_2[] = {
  111180. 1, 4, 4, 6, 6, 7, 7, 8, 7, 8, 8, 9, 9, 9, 9,10,
  111181. 10,10, 9,10,10,11,12,12, 8, 8, 8, 8, 9, 9, 9, 9,
  111182. 10,10,10,10,10,11,11,10,12,11,11,13,11, 7, 7, 8,
  111183. 8, 8, 8, 9, 9, 9,10,10,10,10, 9,10,10,11,11,12,
  111184. 11,11, 8, 8, 8, 8, 9, 9,10,10,10,10,11,11,11,11,
  111185. 11,11,11,12,11,12,12, 8, 8, 9, 9, 9, 9, 9,10,10,
  111186. 10,10,10,10,11,11,11,11,11,11,12,11, 9, 9, 9, 9,
  111187. 10,10,10,10,11,10,11,11,11,11,11,11,12,12,12,12,
  111188. 11, 9, 9, 9, 9,10,10,10,10,11,11,11,11,11,11,11,
  111189. 11,11,12,12,12,13, 9,10,10, 9,11,10,10,10,10,11,
  111190. 11,11,11,11,10,11,12,11,12,12,11,12,11,10, 9,10,
  111191. 10,11,10,11,11,11,11,11,11,11,11,11,12,12,11,12,
  111192. 12,12,10,10,10,11,10,11,11,11,11,11,11,11,11,11,
  111193. 11,11,12,13,12,12,11, 9,10,10,11,11,10,11,11,11,
  111194. 12,11,11,11,11,11,12,12,13,13,12,13,10,10,12,10,
  111195. 11,11,11,11,11,11,11,11,11,12,12,11,13,12,12,12,
  111196. 12,13,12,11,11,11,11,11,11,12,11,12,11,11,11,11,
  111197. 12,12,13,12,11,12,12,11,11,11,11,11,12,11,11,11,
  111198. 11,12,11,11,12,11,12,13,13,12,12,12,12,11,11,11,
  111199. 11,11,12,11,11,12,11,12,11,11,11,11,13,12,12,12,
  111200. 12,13,11,11,11,12,12,11,11,11,12,11,12,12,12,11,
  111201. 12,13,12,11,11,12,12,11,12,11,11,11,12,12,11,12,
  111202. 11,11,11,12,12,12,12,13,12,13,12,12,12,12,11,11,
  111203. 12,11,11,11,11,11,11,12,12,12,13,12,11,13,13,12,
  111204. 12,11,12,10,11,11,11,11,12,11,12,12,11,12,12,13,
  111205. 12,12,13,12,12,12,12,12,11,12,12,12,11,12,11,11,
  111206. 11,12,13,12,13,13,13,13,13,12,13,13,12,12,13,11,
  111207. 11,11,11,11,12,11,11,12,11,
  111208. };
  111209. static float _vq_quantthresh__16c1_s_p9_2[] = {
  111210. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  111211. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  111212. 6.5, 7.5, 8.5, 9.5,
  111213. };
  111214. static long _vq_quantmap__16c1_s_p9_2[] = {
  111215. 19, 17, 15, 13, 11, 9, 7, 5,
  111216. 3, 1, 0, 2, 4, 6, 8, 10,
  111217. 12, 14, 16, 18, 20,
  111218. };
  111219. static encode_aux_threshmatch _vq_auxt__16c1_s_p9_2 = {
  111220. _vq_quantthresh__16c1_s_p9_2,
  111221. _vq_quantmap__16c1_s_p9_2,
  111222. 21,
  111223. 21
  111224. };
  111225. static static_codebook _16c1_s_p9_2 = {
  111226. 2, 441,
  111227. _vq_lengthlist__16c1_s_p9_2,
  111228. 1, -529268736, 1611661312, 5, 0,
  111229. _vq_quantlist__16c1_s_p9_2,
  111230. NULL,
  111231. &_vq_auxt__16c1_s_p9_2,
  111232. NULL,
  111233. 0
  111234. };
  111235. static long _huff_lengthlist__16c1_s_short[] = {
  111236. 5, 6,17, 8,12, 9,10,10,12,13, 5, 2,17, 4, 9, 5,
  111237. 7, 8,11,13,16,16,16,16,16,16,16,16,16,16, 6, 4,
  111238. 16, 5,10, 5, 7,10,14,16,13, 9,16,11, 8, 7, 8, 9,
  111239. 13,16, 7, 4,16, 5, 7, 4, 6, 8,11,13, 8, 6,16, 7,
  111240. 8, 5, 5, 7, 9,13, 9, 8,16, 9, 8, 6, 6, 7, 9,13,
  111241. 11,11,16,10,10, 7, 7, 7, 9,13,13,13,16,13,13, 9,
  111242. 9, 9,10,13,
  111243. };
  111244. static static_codebook _huff_book__16c1_s_short = {
  111245. 2, 100,
  111246. _huff_lengthlist__16c1_s_short,
  111247. 0, 0, 0, 0, 0,
  111248. NULL,
  111249. NULL,
  111250. NULL,
  111251. NULL,
  111252. 0
  111253. };
  111254. static long _huff_lengthlist__16c2_s_long[] = {
  111255. 4, 7, 9, 9, 9, 8, 9,10,15,19, 5, 4, 5, 6, 7, 7,
  111256. 8, 9,14,16, 6, 5, 4, 5, 6, 7, 8,10,12,19, 7, 6,
  111257. 5, 4, 5, 6, 7, 9,11,18, 8, 7, 6, 5, 5, 5, 7, 9,
  111258. 10,17, 8, 7, 7, 5, 5, 5, 6, 7,12,18, 8, 8, 8, 7,
  111259. 7, 5, 5, 7,12,18, 8, 9,10, 9, 9, 7, 6, 7,12,17,
  111260. 14,18,16,16,15,12,11,10,12,18,15,17,18,18,18,15,
  111261. 14,14,16,18,
  111262. };
  111263. static static_codebook _huff_book__16c2_s_long = {
  111264. 2, 100,
  111265. _huff_lengthlist__16c2_s_long,
  111266. 0, 0, 0, 0, 0,
  111267. NULL,
  111268. NULL,
  111269. NULL,
  111270. NULL,
  111271. 0
  111272. };
  111273. static long _vq_quantlist__16c2_s_p1_0[] = {
  111274. 1,
  111275. 0,
  111276. 2,
  111277. };
  111278. static long _vq_lengthlist__16c2_s_p1_0[] = {
  111279. 1, 3, 3, 0, 0, 0, 0, 0, 0, 4, 5, 5, 0, 0, 0, 0,
  111280. 0, 0, 4, 5, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111281. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111282. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111283. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111284. 0,
  111285. };
  111286. static float _vq_quantthresh__16c2_s_p1_0[] = {
  111287. -0.5, 0.5,
  111288. };
  111289. static long _vq_quantmap__16c2_s_p1_0[] = {
  111290. 1, 0, 2,
  111291. };
  111292. static encode_aux_threshmatch _vq_auxt__16c2_s_p1_0 = {
  111293. _vq_quantthresh__16c2_s_p1_0,
  111294. _vq_quantmap__16c2_s_p1_0,
  111295. 3,
  111296. 3
  111297. };
  111298. static static_codebook _16c2_s_p1_0 = {
  111299. 4, 81,
  111300. _vq_lengthlist__16c2_s_p1_0,
  111301. 1, -535822336, 1611661312, 2, 0,
  111302. _vq_quantlist__16c2_s_p1_0,
  111303. NULL,
  111304. &_vq_auxt__16c2_s_p1_0,
  111305. NULL,
  111306. 0
  111307. };
  111308. static long _vq_quantlist__16c2_s_p2_0[] = {
  111309. 2,
  111310. 1,
  111311. 3,
  111312. 0,
  111313. 4,
  111314. };
  111315. static long _vq_lengthlist__16c2_s_p2_0[] = {
  111316. 2, 4, 3, 7, 7, 0, 0, 0, 7, 8, 0, 0, 0, 8, 8, 0,
  111317. 0, 0, 8, 8, 0, 0, 0, 8, 8, 4, 5, 4, 8, 8, 0, 0,
  111318. 0, 8, 8, 0, 0, 0, 8, 8, 0, 0, 0, 9, 9, 0, 0, 0,
  111319. 9, 9, 4, 4, 5, 8, 8, 0, 0, 0, 8, 8, 0, 0, 0, 8,
  111320. 8, 0, 0, 0, 9, 9, 0, 0, 0, 9, 9, 7, 8, 8,10,10,
  111321. 0, 0, 0,12,11, 0, 0, 0,11,11, 0, 0, 0,14,13, 0,
  111322. 0, 0,14,13, 7, 8, 8, 9,10, 0, 0, 0,11,12, 0, 0,
  111323. 0,11,11, 0, 0, 0,14,14, 0, 0, 0,13,14, 0, 0, 0,
  111324. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111325. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111326. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111327. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111328. 0, 0, 0, 0, 0, 0, 0, 0, 8, 8, 8,11,11, 0, 0, 0,
  111329. 11,11, 0, 0, 0,12,11, 0, 0, 0,12,12, 0, 0, 0,13,
  111330. 13, 8, 8, 8,11,11, 0, 0, 0,11,11, 0, 0, 0,11,12,
  111331. 0, 0, 0,12,13, 0, 0, 0,13,13, 0, 0, 0, 0, 0, 0,
  111332. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111333. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111334. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111335. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111336. 0, 0, 0, 0, 0, 8, 8, 8,12,11, 0, 0, 0,12,11, 0,
  111337. 0, 0,11,11, 0, 0, 0,13,13, 0, 0, 0,13,12, 8, 8,
  111338. 8,11,12, 0, 0, 0,11,12, 0, 0, 0,11,11, 0, 0, 0,
  111339. 13,13, 0, 0, 0,12,13, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111340. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111341. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111342. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111343. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111344. 0, 0, 8, 9, 9,14,13, 0, 0, 0,13,12, 0, 0, 0,13,
  111345. 13, 0, 0, 0,13,12, 0, 0, 0,13,13, 8, 9, 9,13,14,
  111346. 0, 0, 0,12,13, 0, 0, 0,13,13, 0, 0, 0,12,13, 0,
  111347. 0, 0,13,13, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111348. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111349. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111350. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111351. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8,
  111352. 9, 9,14,13, 0, 0, 0,13,13, 0, 0, 0,13,12, 0, 0,
  111353. 0,13,13, 0, 0, 0,13,12, 8, 9, 9,14,14, 0, 0, 0,
  111354. 13,13, 0, 0, 0,12,13, 0, 0, 0,13,13, 0, 0, 0,12,
  111355. 13,
  111356. };
  111357. static float _vq_quantthresh__16c2_s_p2_0[] = {
  111358. -1.5, -0.5, 0.5, 1.5,
  111359. };
  111360. static long _vq_quantmap__16c2_s_p2_0[] = {
  111361. 3, 1, 0, 2, 4,
  111362. };
  111363. static encode_aux_threshmatch _vq_auxt__16c2_s_p2_0 = {
  111364. _vq_quantthresh__16c2_s_p2_0,
  111365. _vq_quantmap__16c2_s_p2_0,
  111366. 5,
  111367. 5
  111368. };
  111369. static static_codebook _16c2_s_p2_0 = {
  111370. 4, 625,
  111371. _vq_lengthlist__16c2_s_p2_0,
  111372. 1, -533725184, 1611661312, 3, 0,
  111373. _vq_quantlist__16c2_s_p2_0,
  111374. NULL,
  111375. &_vq_auxt__16c2_s_p2_0,
  111376. NULL,
  111377. 0
  111378. };
  111379. static long _vq_quantlist__16c2_s_p3_0[] = {
  111380. 4,
  111381. 3,
  111382. 5,
  111383. 2,
  111384. 6,
  111385. 1,
  111386. 7,
  111387. 0,
  111388. 8,
  111389. };
  111390. static long _vq_lengthlist__16c2_s_p3_0[] = {
  111391. 1, 3, 3, 6, 6, 7, 7, 8, 8, 0, 0, 0, 6, 6, 7, 7,
  111392. 9, 9, 0, 0, 0, 6, 6, 7, 7, 9, 9, 0, 0, 0, 7, 7,
  111393. 8, 8,10,10, 0, 0, 0, 7, 7, 8, 8,10,10, 0, 0, 0,
  111394. 7, 7, 9, 9,10,10, 0, 0, 0, 7, 7, 9, 9,10,10, 0,
  111395. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111396. 0,
  111397. };
  111398. static float _vq_quantthresh__16c2_s_p3_0[] = {
  111399. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  111400. };
  111401. static long _vq_quantmap__16c2_s_p3_0[] = {
  111402. 7, 5, 3, 1, 0, 2, 4, 6,
  111403. 8,
  111404. };
  111405. static encode_aux_threshmatch _vq_auxt__16c2_s_p3_0 = {
  111406. _vq_quantthresh__16c2_s_p3_0,
  111407. _vq_quantmap__16c2_s_p3_0,
  111408. 9,
  111409. 9
  111410. };
  111411. static static_codebook _16c2_s_p3_0 = {
  111412. 2, 81,
  111413. _vq_lengthlist__16c2_s_p3_0,
  111414. 1, -531628032, 1611661312, 4, 0,
  111415. _vq_quantlist__16c2_s_p3_0,
  111416. NULL,
  111417. &_vq_auxt__16c2_s_p3_0,
  111418. NULL,
  111419. 0
  111420. };
  111421. static long _vq_quantlist__16c2_s_p4_0[] = {
  111422. 8,
  111423. 7,
  111424. 9,
  111425. 6,
  111426. 10,
  111427. 5,
  111428. 11,
  111429. 4,
  111430. 12,
  111431. 3,
  111432. 13,
  111433. 2,
  111434. 14,
  111435. 1,
  111436. 15,
  111437. 0,
  111438. 16,
  111439. };
  111440. static long _vq_lengthlist__16c2_s_p4_0[] = {
  111441. 2, 3, 3, 5, 5, 6, 6, 7, 7, 7, 7, 8, 8, 9, 9,10,
  111442. 10, 0, 0, 0, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,10,10,
  111443. 11,11, 0, 0, 0, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,10,
  111444. 10,10,11, 0, 0, 0, 6, 6, 8, 8, 8, 8, 9, 9,10,10,
  111445. 10,11,11,11, 0, 0, 0, 6, 6, 8, 8, 9, 9, 9, 9,10,
  111446. 10,11,11,11,11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,
  111447. 10,10,11,11,12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9,
  111448. 9,10,10,11,11,12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9,
  111449. 10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 8, 8, 9,
  111450. 9,10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 0, 0,
  111451. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111452. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111453. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111454. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111455. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111456. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111457. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111458. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111459. 0,
  111460. };
  111461. static float _vq_quantthresh__16c2_s_p4_0[] = {
  111462. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  111463. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  111464. };
  111465. static long _vq_quantmap__16c2_s_p4_0[] = {
  111466. 15, 13, 11, 9, 7, 5, 3, 1,
  111467. 0, 2, 4, 6, 8, 10, 12, 14,
  111468. 16,
  111469. };
  111470. static encode_aux_threshmatch _vq_auxt__16c2_s_p4_0 = {
  111471. _vq_quantthresh__16c2_s_p4_0,
  111472. _vq_quantmap__16c2_s_p4_0,
  111473. 17,
  111474. 17
  111475. };
  111476. static static_codebook _16c2_s_p4_0 = {
  111477. 2, 289,
  111478. _vq_lengthlist__16c2_s_p4_0,
  111479. 1, -529530880, 1611661312, 5, 0,
  111480. _vq_quantlist__16c2_s_p4_0,
  111481. NULL,
  111482. &_vq_auxt__16c2_s_p4_0,
  111483. NULL,
  111484. 0
  111485. };
  111486. static long _vq_quantlist__16c2_s_p5_0[] = {
  111487. 1,
  111488. 0,
  111489. 2,
  111490. };
  111491. static long _vq_lengthlist__16c2_s_p5_0[] = {
  111492. 1, 4, 4, 5, 7, 7, 6, 7, 7, 4, 6, 6,10,10,10,10,
  111493. 10,10, 4, 7, 6,10,10,10,10,10,10, 5, 9, 9, 9,12,
  111494. 11,10,11,12, 7,10,10,12,12,12,12,12,12, 7,10,10,
  111495. 11,12,12,12,12,13, 6,10,10,10,12,12,10,12,12, 7,
  111496. 10,10,11,13,12,12,12,12, 7,10,10,11,12,12,12,12,
  111497. 12,
  111498. };
  111499. static float _vq_quantthresh__16c2_s_p5_0[] = {
  111500. -5.5, 5.5,
  111501. };
  111502. static long _vq_quantmap__16c2_s_p5_0[] = {
  111503. 1, 0, 2,
  111504. };
  111505. static encode_aux_threshmatch _vq_auxt__16c2_s_p5_0 = {
  111506. _vq_quantthresh__16c2_s_p5_0,
  111507. _vq_quantmap__16c2_s_p5_0,
  111508. 3,
  111509. 3
  111510. };
  111511. static static_codebook _16c2_s_p5_0 = {
  111512. 4, 81,
  111513. _vq_lengthlist__16c2_s_p5_0,
  111514. 1, -529137664, 1618345984, 2, 0,
  111515. _vq_quantlist__16c2_s_p5_0,
  111516. NULL,
  111517. &_vq_auxt__16c2_s_p5_0,
  111518. NULL,
  111519. 0
  111520. };
  111521. static long _vq_quantlist__16c2_s_p5_1[] = {
  111522. 5,
  111523. 4,
  111524. 6,
  111525. 3,
  111526. 7,
  111527. 2,
  111528. 8,
  111529. 1,
  111530. 9,
  111531. 0,
  111532. 10,
  111533. };
  111534. static long _vq_lengthlist__16c2_s_p5_1[] = {
  111535. 2, 3, 3, 6, 6, 7, 7, 7, 7, 8, 8,11,11,11, 6, 6,
  111536. 7, 7, 8, 8, 8, 8,11,11,11, 6, 6, 7, 7, 8, 8, 8,
  111537. 8,11,11,11, 6, 6, 8, 8, 8, 8, 9, 9,11,11,11, 6,
  111538. 6, 8, 8, 8, 8, 9, 9,11,11,11, 7, 7, 8, 8, 8, 8,
  111539. 8, 8,11,11,11, 7, 7, 8, 8, 8, 8, 8, 9,11,11,11,
  111540. 8, 8, 8, 8, 8, 8, 8, 8,11,11,11,11,11, 8, 8, 8,
  111541. 8, 8, 8,11,11,11,11,11, 8, 8, 8, 8, 8, 8,11,11,
  111542. 11,11,11, 7, 7, 8, 8, 8, 8,
  111543. };
  111544. static float _vq_quantthresh__16c2_s_p5_1[] = {
  111545. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  111546. 3.5, 4.5,
  111547. };
  111548. static long _vq_quantmap__16c2_s_p5_1[] = {
  111549. 9, 7, 5, 3, 1, 0, 2, 4,
  111550. 6, 8, 10,
  111551. };
  111552. static encode_aux_threshmatch _vq_auxt__16c2_s_p5_1 = {
  111553. _vq_quantthresh__16c2_s_p5_1,
  111554. _vq_quantmap__16c2_s_p5_1,
  111555. 11,
  111556. 11
  111557. };
  111558. static static_codebook _16c2_s_p5_1 = {
  111559. 2, 121,
  111560. _vq_lengthlist__16c2_s_p5_1,
  111561. 1, -531365888, 1611661312, 4, 0,
  111562. _vq_quantlist__16c2_s_p5_1,
  111563. NULL,
  111564. &_vq_auxt__16c2_s_p5_1,
  111565. NULL,
  111566. 0
  111567. };
  111568. static long _vq_quantlist__16c2_s_p6_0[] = {
  111569. 6,
  111570. 5,
  111571. 7,
  111572. 4,
  111573. 8,
  111574. 3,
  111575. 9,
  111576. 2,
  111577. 10,
  111578. 1,
  111579. 11,
  111580. 0,
  111581. 12,
  111582. };
  111583. static long _vq_lengthlist__16c2_s_p6_0[] = {
  111584. 1, 4, 4, 7, 6, 8, 8, 9, 9,10,10,11,11, 5, 5, 5,
  111585. 7, 7, 9, 9, 9, 9,11,11,12,12, 6, 5, 5, 7, 7, 9,
  111586. 9,10,10,11,11,12,12, 0, 6, 6, 7, 7, 9, 9,10,10,
  111587. 11,11,12,12, 0, 7, 7, 7, 7, 9, 9,10,10,11,12,12,
  111588. 12, 0,11,11, 8, 8,10,10,11,11,12,12,13,13, 0,11,
  111589. 12, 8, 8,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0,
  111590. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111591. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111592. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111593. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111594. 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111595. };
  111596. static float _vq_quantthresh__16c2_s_p6_0[] = {
  111597. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  111598. 12.5, 17.5, 22.5, 27.5,
  111599. };
  111600. static long _vq_quantmap__16c2_s_p6_0[] = {
  111601. 11, 9, 7, 5, 3, 1, 0, 2,
  111602. 4, 6, 8, 10, 12,
  111603. };
  111604. static encode_aux_threshmatch _vq_auxt__16c2_s_p6_0 = {
  111605. _vq_quantthresh__16c2_s_p6_0,
  111606. _vq_quantmap__16c2_s_p6_0,
  111607. 13,
  111608. 13
  111609. };
  111610. static static_codebook _16c2_s_p6_0 = {
  111611. 2, 169,
  111612. _vq_lengthlist__16c2_s_p6_0,
  111613. 1, -526516224, 1616117760, 4, 0,
  111614. _vq_quantlist__16c2_s_p6_0,
  111615. NULL,
  111616. &_vq_auxt__16c2_s_p6_0,
  111617. NULL,
  111618. 0
  111619. };
  111620. static long _vq_quantlist__16c2_s_p6_1[] = {
  111621. 2,
  111622. 1,
  111623. 3,
  111624. 0,
  111625. 4,
  111626. };
  111627. static long _vq_lengthlist__16c2_s_p6_1[] = {
  111628. 2, 3, 3, 5, 5, 6, 6, 6, 5, 5, 6, 6, 6, 5, 5, 6,
  111629. 6, 6, 5, 5, 6, 6, 6, 5, 5,
  111630. };
  111631. static float _vq_quantthresh__16c2_s_p6_1[] = {
  111632. -1.5, -0.5, 0.5, 1.5,
  111633. };
  111634. static long _vq_quantmap__16c2_s_p6_1[] = {
  111635. 3, 1, 0, 2, 4,
  111636. };
  111637. static encode_aux_threshmatch _vq_auxt__16c2_s_p6_1 = {
  111638. _vq_quantthresh__16c2_s_p6_1,
  111639. _vq_quantmap__16c2_s_p6_1,
  111640. 5,
  111641. 5
  111642. };
  111643. static static_codebook _16c2_s_p6_1 = {
  111644. 2, 25,
  111645. _vq_lengthlist__16c2_s_p6_1,
  111646. 1, -533725184, 1611661312, 3, 0,
  111647. _vq_quantlist__16c2_s_p6_1,
  111648. NULL,
  111649. &_vq_auxt__16c2_s_p6_1,
  111650. NULL,
  111651. 0
  111652. };
  111653. static long _vq_quantlist__16c2_s_p7_0[] = {
  111654. 6,
  111655. 5,
  111656. 7,
  111657. 4,
  111658. 8,
  111659. 3,
  111660. 9,
  111661. 2,
  111662. 10,
  111663. 1,
  111664. 11,
  111665. 0,
  111666. 12,
  111667. };
  111668. static long _vq_lengthlist__16c2_s_p7_0[] = {
  111669. 1, 4, 4, 7, 7, 8, 8, 9, 9,10,10,11,11, 5, 5, 5,
  111670. 8, 8, 9, 9,10,10,11,11,12,12, 6, 5, 5, 8, 8, 9,
  111671. 9,10,10,11,11,12,13,18, 6, 6, 7, 7, 9, 9,10,10,
  111672. 12,12,13,13,18, 6, 6, 7, 7, 9, 9,10,10,12,12,13,
  111673. 13,18,11,10, 8, 8,10,10,11,11,12,12,13,13,18,11,
  111674. 11, 8, 8,10,10,11,11,12,13,13,13,18,18,18,10,11,
  111675. 11,11,12,12,13,13,14,14,18,18,18,11,11,11,11,12,
  111676. 12,13,13,14,14,18,18,18,14,14,12,12,12,12,14,14,
  111677. 15,14,18,18,18,15,15,11,12,12,12,13,13,15,15,18,
  111678. 18,18,18,18,13,13,13,13,13,14,17,16,18,18,18,18,
  111679. 18,13,14,13,13,14,13,15,14,
  111680. };
  111681. static float _vq_quantthresh__16c2_s_p7_0[] = {
  111682. -60.5, -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5,
  111683. 27.5, 38.5, 49.5, 60.5,
  111684. };
  111685. static long _vq_quantmap__16c2_s_p7_0[] = {
  111686. 11, 9, 7, 5, 3, 1, 0, 2,
  111687. 4, 6, 8, 10, 12,
  111688. };
  111689. static encode_aux_threshmatch _vq_auxt__16c2_s_p7_0 = {
  111690. _vq_quantthresh__16c2_s_p7_0,
  111691. _vq_quantmap__16c2_s_p7_0,
  111692. 13,
  111693. 13
  111694. };
  111695. static static_codebook _16c2_s_p7_0 = {
  111696. 2, 169,
  111697. _vq_lengthlist__16c2_s_p7_0,
  111698. 1, -523206656, 1618345984, 4, 0,
  111699. _vq_quantlist__16c2_s_p7_0,
  111700. NULL,
  111701. &_vq_auxt__16c2_s_p7_0,
  111702. NULL,
  111703. 0
  111704. };
  111705. static long _vq_quantlist__16c2_s_p7_1[] = {
  111706. 5,
  111707. 4,
  111708. 6,
  111709. 3,
  111710. 7,
  111711. 2,
  111712. 8,
  111713. 1,
  111714. 9,
  111715. 0,
  111716. 10,
  111717. };
  111718. static long _vq_lengthlist__16c2_s_p7_1[] = {
  111719. 2, 4, 4, 6, 6, 7, 7, 7, 7, 7, 7, 9, 9, 9, 6, 6,
  111720. 7, 7, 8, 8, 8, 8, 9, 9, 9, 6, 6, 7, 7, 8, 8, 8,
  111721. 8, 9, 9, 9, 7, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 7,
  111722. 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 7, 7, 7, 7, 8, 8,
  111723. 8, 8, 9, 9, 9, 7, 7, 7, 7, 7, 7, 8, 8, 9, 9, 9,
  111724. 7, 7, 8, 8, 7, 7, 8, 8, 9, 9, 9, 9, 9, 7, 7, 7,
  111725. 7, 8, 8, 9, 9, 9, 9, 9, 8, 8, 7, 7, 8, 8, 9, 9,
  111726. 9, 9, 9, 7, 7, 7, 7, 8, 8,
  111727. };
  111728. static float _vq_quantthresh__16c2_s_p7_1[] = {
  111729. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  111730. 3.5, 4.5,
  111731. };
  111732. static long _vq_quantmap__16c2_s_p7_1[] = {
  111733. 9, 7, 5, 3, 1, 0, 2, 4,
  111734. 6, 8, 10,
  111735. };
  111736. static encode_aux_threshmatch _vq_auxt__16c2_s_p7_1 = {
  111737. _vq_quantthresh__16c2_s_p7_1,
  111738. _vq_quantmap__16c2_s_p7_1,
  111739. 11,
  111740. 11
  111741. };
  111742. static static_codebook _16c2_s_p7_1 = {
  111743. 2, 121,
  111744. _vq_lengthlist__16c2_s_p7_1,
  111745. 1, -531365888, 1611661312, 4, 0,
  111746. _vq_quantlist__16c2_s_p7_1,
  111747. NULL,
  111748. &_vq_auxt__16c2_s_p7_1,
  111749. NULL,
  111750. 0
  111751. };
  111752. static long _vq_quantlist__16c2_s_p8_0[] = {
  111753. 7,
  111754. 6,
  111755. 8,
  111756. 5,
  111757. 9,
  111758. 4,
  111759. 10,
  111760. 3,
  111761. 11,
  111762. 2,
  111763. 12,
  111764. 1,
  111765. 13,
  111766. 0,
  111767. 14,
  111768. };
  111769. static long _vq_lengthlist__16c2_s_p8_0[] = {
  111770. 1, 4, 4, 7, 6, 7, 7, 6, 6, 8, 8, 9, 9,10,10, 6,
  111771. 6, 6, 8, 8, 9, 8, 8, 8, 9, 9,11,10,11,11, 7, 6,
  111772. 6, 8, 8, 9, 8, 7, 7, 9, 9,10,10,12,11,14, 8, 8,
  111773. 8, 9, 9, 9, 9, 9,10, 9,10,10,11,13,14, 8, 8, 8,
  111774. 8, 9, 9, 8, 8, 9, 9,10,10,11,12,14,13,11, 9, 9,
  111775. 9, 9, 9, 9, 9,10,11,10,13,12,14,11,13, 8, 9, 9,
  111776. 9, 9, 9,10,10,11,10,13,12,14,14,14, 8, 9, 9, 9,
  111777. 11,11,11,11,11,12,13,13,14,14,14, 9, 8, 9, 9,10,
  111778. 10,12,10,11,12,12,14,14,14,14,11,12,10,10,12,12,
  111779. 12,12,13,14,12,12,14,14,14,12,12, 9,10,11,11,12,
  111780. 14,12,14,14,14,14,14,14,14,14,11,11,12,11,12,14,
  111781. 14,14,14,14,14,14,14,14,14,12,11,11,11,11,14,14,
  111782. 14,14,14,14,14,14,14,14,14,14,13,12,14,14,14,14,
  111783. 14,14,14,14,14,14,14,14,14,12,12,12,13,14,14,13,
  111784. 13,
  111785. };
  111786. static float _vq_quantthresh__16c2_s_p8_0[] = {
  111787. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  111788. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  111789. };
  111790. static long _vq_quantmap__16c2_s_p8_0[] = {
  111791. 13, 11, 9, 7, 5, 3, 1, 0,
  111792. 2, 4, 6, 8, 10, 12, 14,
  111793. };
  111794. static encode_aux_threshmatch _vq_auxt__16c2_s_p8_0 = {
  111795. _vq_quantthresh__16c2_s_p8_0,
  111796. _vq_quantmap__16c2_s_p8_0,
  111797. 15,
  111798. 15
  111799. };
  111800. static static_codebook _16c2_s_p8_0 = {
  111801. 2, 225,
  111802. _vq_lengthlist__16c2_s_p8_0,
  111803. 1, -520986624, 1620377600, 4, 0,
  111804. _vq_quantlist__16c2_s_p8_0,
  111805. NULL,
  111806. &_vq_auxt__16c2_s_p8_0,
  111807. NULL,
  111808. 0
  111809. };
  111810. static long _vq_quantlist__16c2_s_p8_1[] = {
  111811. 10,
  111812. 9,
  111813. 11,
  111814. 8,
  111815. 12,
  111816. 7,
  111817. 13,
  111818. 6,
  111819. 14,
  111820. 5,
  111821. 15,
  111822. 4,
  111823. 16,
  111824. 3,
  111825. 17,
  111826. 2,
  111827. 18,
  111828. 1,
  111829. 19,
  111830. 0,
  111831. 20,
  111832. };
  111833. static long _vq_lengthlist__16c2_s_p8_1[] = {
  111834. 2, 4, 4, 6, 6, 7, 7, 7, 7, 8, 7, 8, 8, 8, 8, 8,
  111835. 8, 8, 8, 8, 8,11,12,11, 7, 7, 8, 8, 8, 8, 9, 9,
  111836. 9, 9, 9, 9, 9, 9, 9,10, 9, 9,11,11,10, 7, 7, 8,
  111837. 8, 8, 8, 9, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,11,
  111838. 11,11, 8, 7, 8, 8, 9, 9, 9, 9, 9, 9,10,10, 9,10,
  111839. 10, 9,10,10,11,11,12, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  111840. 9, 9, 9,10, 9,10,10,10,10,11,11,11, 8, 8, 9, 9,
  111841. 9, 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,11,11,
  111842. 11, 8, 8, 9, 8, 9, 9, 9, 9,10, 9, 9, 9,10,10,10,
  111843. 10, 9,10,11,11,11, 9, 9, 9, 9,10, 9, 9, 9,10,10,
  111844. 9,10, 9,10,10,10,10,10,11,12,11,11,11, 9, 9, 9,
  111845. 9, 9,10,10, 9,10,10,10,10,10,10,10,10,12,11,13,
  111846. 13,11, 9, 9, 9, 9,10,10, 9,10,10,10,10,11,10,10,
  111847. 10,10,11,12,11,12,11, 9, 9, 9,10,10, 9,10,10,10,
  111848. 10,10,10,10,10,10,10,11,11,11,12,11, 9,10,10,10,
  111849. 10,10,10,10,10,10,10,10,10,10,10,10,11,12,12,12,
  111850. 11,11,11,10, 9,10,10,10,10,10,10,10,10,11,10,10,
  111851. 10,11,11,11,11,11,11,11,10,10,10,11,10,10,10,10,
  111852. 10,10,10,10,10,10,11,11,11,11,12,12,11,10,10,10,
  111853. 10,10,10,10,10,11,10,10,10,11,10,12,11,11,12,11,
  111854. 11,11,10,10,10,10,10,11,10,10,10,10,10,11,10,10,
  111855. 11,11,11,12,11,12,11,11,12,10,10,10,10,10,10,10,
  111856. 11,10,10,11,10,12,11,11,11,12,11,11,11,11,10,10,
  111857. 10,10,10,10,10,11,11,11,10,11,12,11,11,11,12,11,
  111858. 12,11,12,10,11,10,10,10,10,11,10,10,10,10,10,10,
  111859. 12,11,11,11,11,11,12,12,10,10,10,10,10,11,10,10,
  111860. 11,10,11,11,11,11,11,11,11,11,11,11,11,11,12,11,
  111861. 10,11,10,10,10,10,10,10,10,
  111862. };
  111863. static float _vq_quantthresh__16c2_s_p8_1[] = {
  111864. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  111865. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  111866. 6.5, 7.5, 8.5, 9.5,
  111867. };
  111868. static long _vq_quantmap__16c2_s_p8_1[] = {
  111869. 19, 17, 15, 13, 11, 9, 7, 5,
  111870. 3, 1, 0, 2, 4, 6, 8, 10,
  111871. 12, 14, 16, 18, 20,
  111872. };
  111873. static encode_aux_threshmatch _vq_auxt__16c2_s_p8_1 = {
  111874. _vq_quantthresh__16c2_s_p8_1,
  111875. _vq_quantmap__16c2_s_p8_1,
  111876. 21,
  111877. 21
  111878. };
  111879. static static_codebook _16c2_s_p8_1 = {
  111880. 2, 441,
  111881. _vq_lengthlist__16c2_s_p8_1,
  111882. 1, -529268736, 1611661312, 5, 0,
  111883. _vq_quantlist__16c2_s_p8_1,
  111884. NULL,
  111885. &_vq_auxt__16c2_s_p8_1,
  111886. NULL,
  111887. 0
  111888. };
  111889. static long _vq_quantlist__16c2_s_p9_0[] = {
  111890. 6,
  111891. 5,
  111892. 7,
  111893. 4,
  111894. 8,
  111895. 3,
  111896. 9,
  111897. 2,
  111898. 10,
  111899. 1,
  111900. 11,
  111901. 0,
  111902. 12,
  111903. };
  111904. static long _vq_lengthlist__16c2_s_p9_0[] = {
  111905. 1, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  111906. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  111907. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  111908. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  111909. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  111910. 9, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  111911. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  111912. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  111913. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  111914. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  111915. 8, 8, 8, 8, 8, 8, 8, 8, 8,
  111916. };
  111917. static float _vq_quantthresh__16c2_s_p9_0[] = {
  111918. -5120.5, -4189.5, -3258.5, -2327.5, -1396.5, -465.5, 465.5, 1396.5,
  111919. 2327.5, 3258.5, 4189.5, 5120.5,
  111920. };
  111921. static long _vq_quantmap__16c2_s_p9_0[] = {
  111922. 11, 9, 7, 5, 3, 1, 0, 2,
  111923. 4, 6, 8, 10, 12,
  111924. };
  111925. static encode_aux_threshmatch _vq_auxt__16c2_s_p9_0 = {
  111926. _vq_quantthresh__16c2_s_p9_0,
  111927. _vq_quantmap__16c2_s_p9_0,
  111928. 13,
  111929. 13
  111930. };
  111931. static static_codebook _16c2_s_p9_0 = {
  111932. 2, 169,
  111933. _vq_lengthlist__16c2_s_p9_0,
  111934. 1, -510275072, 1631393792, 4, 0,
  111935. _vq_quantlist__16c2_s_p9_0,
  111936. NULL,
  111937. &_vq_auxt__16c2_s_p9_0,
  111938. NULL,
  111939. 0
  111940. };
  111941. static long _vq_quantlist__16c2_s_p9_1[] = {
  111942. 8,
  111943. 7,
  111944. 9,
  111945. 6,
  111946. 10,
  111947. 5,
  111948. 11,
  111949. 4,
  111950. 12,
  111951. 3,
  111952. 13,
  111953. 2,
  111954. 14,
  111955. 1,
  111956. 15,
  111957. 0,
  111958. 16,
  111959. };
  111960. static long _vq_lengthlist__16c2_s_p9_1[] = {
  111961. 1, 5, 5, 9, 8, 7, 7, 7, 6,10,11,11,11,11,11,11,
  111962. 11, 8, 7, 6, 8, 8,10, 9,10,10,10, 9,11,10,10,10,
  111963. 10,10, 8, 6, 6, 8, 8, 9, 8, 9, 8, 9,10,10,10,10,
  111964. 10,10,10,10, 8,10, 9, 9, 9, 9,10,10,10,10,10,10,
  111965. 10,10,10,10,10, 8, 9, 9, 9,10,10, 9,10,10,10,10,
  111966. 10,10,10,10,10,10,10,10, 9, 8, 9, 9,10,10,10,10,
  111967. 10,10,10,10,10,10,10,10, 9, 8, 8, 9, 9,10,10,10,
  111968. 10,10,10,10,10,10,10,10,10,10, 9,10, 9, 9,10,10,
  111969. 10,10,10,10,10,10,10,10,10,10,10, 9, 8, 9, 9,10,
  111970. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10, 9,
  111971. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  111972. 8,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  111973. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  111974. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  111975. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  111976. 10,10,10,10, 9,10, 9,10,10,10,10,10,10,10,10,10,
  111977. 10,10,10,10,10,10,10,10,10, 9,10,10,10,10,10,10,
  111978. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  111979. 10,
  111980. };
  111981. static float _vq_quantthresh__16c2_s_p9_1[] = {
  111982. -367.5, -318.5, -269.5, -220.5, -171.5, -122.5, -73.5, -24.5,
  111983. 24.5, 73.5, 122.5, 171.5, 220.5, 269.5, 318.5, 367.5,
  111984. };
  111985. static long _vq_quantmap__16c2_s_p9_1[] = {
  111986. 15, 13, 11, 9, 7, 5, 3, 1,
  111987. 0, 2, 4, 6, 8, 10, 12, 14,
  111988. 16,
  111989. };
  111990. static encode_aux_threshmatch _vq_auxt__16c2_s_p9_1 = {
  111991. _vq_quantthresh__16c2_s_p9_1,
  111992. _vq_quantmap__16c2_s_p9_1,
  111993. 17,
  111994. 17
  111995. };
  111996. static static_codebook _16c2_s_p9_1 = {
  111997. 2, 289,
  111998. _vq_lengthlist__16c2_s_p9_1,
  111999. 1, -518488064, 1622704128, 5, 0,
  112000. _vq_quantlist__16c2_s_p9_1,
  112001. NULL,
  112002. &_vq_auxt__16c2_s_p9_1,
  112003. NULL,
  112004. 0
  112005. };
  112006. static long _vq_quantlist__16c2_s_p9_2[] = {
  112007. 13,
  112008. 12,
  112009. 14,
  112010. 11,
  112011. 15,
  112012. 10,
  112013. 16,
  112014. 9,
  112015. 17,
  112016. 8,
  112017. 18,
  112018. 7,
  112019. 19,
  112020. 6,
  112021. 20,
  112022. 5,
  112023. 21,
  112024. 4,
  112025. 22,
  112026. 3,
  112027. 23,
  112028. 2,
  112029. 24,
  112030. 1,
  112031. 25,
  112032. 0,
  112033. 26,
  112034. };
  112035. static long _vq_lengthlist__16c2_s_p9_2[] = {
  112036. 1, 4, 4, 5, 5, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7,
  112037. 7, 7, 7, 7, 8, 7, 8, 7, 7, 4, 4,
  112038. };
  112039. static float _vq_quantthresh__16c2_s_p9_2[] = {
  112040. -12.5, -11.5, -10.5, -9.5, -8.5, -7.5, -6.5, -5.5,
  112041. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  112042. 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5, 10.5,
  112043. 11.5, 12.5,
  112044. };
  112045. static long _vq_quantmap__16c2_s_p9_2[] = {
  112046. 25, 23, 21, 19, 17, 15, 13, 11,
  112047. 9, 7, 5, 3, 1, 0, 2, 4,
  112048. 6, 8, 10, 12, 14, 16, 18, 20,
  112049. 22, 24, 26,
  112050. };
  112051. static encode_aux_threshmatch _vq_auxt__16c2_s_p9_2 = {
  112052. _vq_quantthresh__16c2_s_p9_2,
  112053. _vq_quantmap__16c2_s_p9_2,
  112054. 27,
  112055. 27
  112056. };
  112057. static static_codebook _16c2_s_p9_2 = {
  112058. 1, 27,
  112059. _vq_lengthlist__16c2_s_p9_2,
  112060. 1, -528875520, 1611661312, 5, 0,
  112061. _vq_quantlist__16c2_s_p9_2,
  112062. NULL,
  112063. &_vq_auxt__16c2_s_p9_2,
  112064. NULL,
  112065. 0
  112066. };
  112067. static long _huff_lengthlist__16c2_s_short[] = {
  112068. 7,10,11,11,11,14,15,15,17,14, 8, 6, 7, 7, 8, 9,
  112069. 11,11,14,17, 9, 6, 6, 6, 7, 7,10,11,15,16, 9, 6,
  112070. 6, 4, 4, 5, 8, 9,12,16,10, 6, 6, 4, 4, 4, 6, 9,
  112071. 13,16,10, 7, 6, 5, 4, 3, 5, 7,13,16,11, 9, 8, 7,
  112072. 6, 5, 5, 6,12,15,10,10,10, 9, 7, 6, 6, 7,11,15,
  112073. 13,13,13,13,11,10,10, 9,12,16,16,16,16,14,16,15,
  112074. 15,12,14,14,
  112075. };
  112076. static static_codebook _huff_book__16c2_s_short = {
  112077. 2, 100,
  112078. _huff_lengthlist__16c2_s_short,
  112079. 0, 0, 0, 0, 0,
  112080. NULL,
  112081. NULL,
  112082. NULL,
  112083. NULL,
  112084. 0
  112085. };
  112086. static long _vq_quantlist__8c0_s_p1_0[] = {
  112087. 1,
  112088. 0,
  112089. 2,
  112090. };
  112091. static long _vq_lengthlist__8c0_s_p1_0[] = {
  112092. 1, 5, 4, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0, 0, 0, 0,
  112093. 0, 0, 5, 7, 7, 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, 5, 8, 8, 0, 0, 0, 0, 0, 0, 7, 8, 9, 0, 0, 0,
  112098. 0, 0, 0, 7, 8, 9, 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, 5, 8, 8, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0,
  112103. 0, 0, 0, 0, 7, 9, 8, 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, 5, 8, 8, 0, 0, 0, 0,
  112138. 0, 0, 8,10,10, 0, 0, 0, 0, 0, 0, 8, 9, 9, 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, 7,10, 9, 0, 0, 0,
  112143. 0, 0, 0, 8, 9,11, 0, 0, 0, 0, 0, 0, 9,11,11, 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, 7, 9,10, 0, 0,
  112148. 0, 0, 0, 0, 9,11,10, 0, 0, 0, 0, 0, 0, 9,11,11,
  112149. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112150. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112151. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112152. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112153. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112154. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112155. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112156. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112157. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112158. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112159. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112160. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112161. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112162. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112163. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112164. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112165. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112166. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112167. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112168. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112169. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112170. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112171. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112172. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112173. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112174. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112175. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112176. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112177. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112178. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112179. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112180. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112181. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112182. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112183. 0, 0, 5, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0, 0,
  112184. 0, 0, 0, 0, 8, 9,10, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112185. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112186. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112187. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112188. 0, 0, 0, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,11,11, 0,
  112189. 0, 0, 0, 0, 0, 9,10,11, 0, 0, 0, 0, 0, 0, 0, 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, 7, 9,10, 0, 0, 0, 0, 0, 0, 9,11,11,
  112194. 0, 0, 0, 0, 0, 0, 8,11, 9, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112230. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112231. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112232. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112233. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112234. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112235. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112236. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112237. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112238. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112239. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112240. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112241. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112242. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112243. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112244. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112245. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112246. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112247. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112248. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112249. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112250. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112251. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112252. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112253. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112254. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112255. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112256. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112257. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112258. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112259. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112260. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112261. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112262. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112263. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112264. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112265. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112266. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112267. 0, 0, 0, 0, 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112301. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112302. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112303. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112304. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112305. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112306. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112307. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112308. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112309. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112310. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112311. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112312. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112313. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112314. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112315. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112316. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112317. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112318. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112319. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112320. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112321. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112322. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112323. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112324. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112325. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112326. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112327. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112328. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112329. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112330. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112331. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112332. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112333. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112334. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112335. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112336. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112337. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112338. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112339. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112340. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112341. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112342. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112343. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112344. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112345. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112346. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112347. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112348. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112349. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112350. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112351. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112352. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112353. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112354. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112355. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112356. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112357. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112358. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112359. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112360. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112361. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112362. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112363. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112364. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112365. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112366. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112367. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112368. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112369. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112370. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112371. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112372. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112373. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112374. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112375. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112376. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112377. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112378. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112379. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112380. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112381. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112382. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112383. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112384. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112385. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112386. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112387. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112388. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112389. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112390. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112391. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112392. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112393. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112394. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112395. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112396. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112397. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112398. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112399. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112400. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112401. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112402. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112403. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112404. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112405. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112406. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112407. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112408. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112409. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112410. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112411. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112412. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112413. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112414. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112415. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112416. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112417. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112418. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112419. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112420. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112421. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112422. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112423. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112424. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112425. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112426. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112427. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112428. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112429. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112430. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112431. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112432. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112433. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112434. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112435. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112436. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112437. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112438. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112439. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112440. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112441. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112442. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112443. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112444. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112445. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112446. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112447. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112448. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112449. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112450. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112451. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112452. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112453. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112454. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112455. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112456. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112457. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112458. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112459. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112460. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112461. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112462. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112463. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112464. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112465. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112466. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112467. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112468. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112469. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112470. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112471. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112472. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112473. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112474. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112475. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112476. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112477. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112478. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112479. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112480. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112481. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112482. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112483. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112484. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112485. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112486. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112487. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112488. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112489. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112490. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112491. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112492. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112493. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112494. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112495. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112496. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112497. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112498. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112499. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112500. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112501. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112502. 0,
  112503. };
  112504. static float _vq_quantthresh__8c0_s_p1_0[] = {
  112505. -0.5, 0.5,
  112506. };
  112507. static long _vq_quantmap__8c0_s_p1_0[] = {
  112508. 1, 0, 2,
  112509. };
  112510. static encode_aux_threshmatch _vq_auxt__8c0_s_p1_0 = {
  112511. _vq_quantthresh__8c0_s_p1_0,
  112512. _vq_quantmap__8c0_s_p1_0,
  112513. 3,
  112514. 3
  112515. };
  112516. static static_codebook _8c0_s_p1_0 = {
  112517. 8, 6561,
  112518. _vq_lengthlist__8c0_s_p1_0,
  112519. 1, -535822336, 1611661312, 2, 0,
  112520. _vq_quantlist__8c0_s_p1_0,
  112521. NULL,
  112522. &_vq_auxt__8c0_s_p1_0,
  112523. NULL,
  112524. 0
  112525. };
  112526. static long _vq_quantlist__8c0_s_p2_0[] = {
  112527. 2,
  112528. 1,
  112529. 3,
  112530. 0,
  112531. 4,
  112532. };
  112533. static long _vq_lengthlist__8c0_s_p2_0[] = {
  112534. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112535. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112536. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112537. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112538. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112539. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112540. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112541. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112542. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112543. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112544. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112545. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112546. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112547. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112548. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112549. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112550. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112551. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112552. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112553. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112554. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112555. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112556. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112557. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112558. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112559. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112560. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112561. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112562. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112563. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112564. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112565. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112566. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112567. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112568. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112569. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112570. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112571. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112572. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112573. 0,
  112574. };
  112575. static float _vq_quantthresh__8c0_s_p2_0[] = {
  112576. -1.5, -0.5, 0.5, 1.5,
  112577. };
  112578. static long _vq_quantmap__8c0_s_p2_0[] = {
  112579. 3, 1, 0, 2, 4,
  112580. };
  112581. static encode_aux_threshmatch _vq_auxt__8c0_s_p2_0 = {
  112582. _vq_quantthresh__8c0_s_p2_0,
  112583. _vq_quantmap__8c0_s_p2_0,
  112584. 5,
  112585. 5
  112586. };
  112587. static static_codebook _8c0_s_p2_0 = {
  112588. 4, 625,
  112589. _vq_lengthlist__8c0_s_p2_0,
  112590. 1, -533725184, 1611661312, 3, 0,
  112591. _vq_quantlist__8c0_s_p2_0,
  112592. NULL,
  112593. &_vq_auxt__8c0_s_p2_0,
  112594. NULL,
  112595. 0
  112596. };
  112597. static long _vq_quantlist__8c0_s_p3_0[] = {
  112598. 2,
  112599. 1,
  112600. 3,
  112601. 0,
  112602. 4,
  112603. };
  112604. static long _vq_lengthlist__8c0_s_p3_0[] = {
  112605. 1, 4, 4, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112606. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 5, 6, 7, 7, 0, 0,
  112607. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112608. 0, 0, 4, 5, 5, 7, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112609. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 7, 7, 8, 8,
  112610. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112611. 0, 0, 0, 0, 6, 7, 7, 8, 8, 0, 0, 0, 0, 0, 0, 0,
  112612. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112613. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112614. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112615. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112616. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112617. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112618. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112619. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112620. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112621. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112622. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112623. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112624. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112625. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112626. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112627. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112628. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112629. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112630. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112631. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112632. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112633. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112634. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112635. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112636. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112637. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112638. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112639. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112640. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112641. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112642. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112643. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112644. 0,
  112645. };
  112646. static float _vq_quantthresh__8c0_s_p3_0[] = {
  112647. -1.5, -0.5, 0.5, 1.5,
  112648. };
  112649. static long _vq_quantmap__8c0_s_p3_0[] = {
  112650. 3, 1, 0, 2, 4,
  112651. };
  112652. static encode_aux_threshmatch _vq_auxt__8c0_s_p3_0 = {
  112653. _vq_quantthresh__8c0_s_p3_0,
  112654. _vq_quantmap__8c0_s_p3_0,
  112655. 5,
  112656. 5
  112657. };
  112658. static static_codebook _8c0_s_p3_0 = {
  112659. 4, 625,
  112660. _vq_lengthlist__8c0_s_p3_0,
  112661. 1, -533725184, 1611661312, 3, 0,
  112662. _vq_quantlist__8c0_s_p3_0,
  112663. NULL,
  112664. &_vq_auxt__8c0_s_p3_0,
  112665. NULL,
  112666. 0
  112667. };
  112668. static long _vq_quantlist__8c0_s_p4_0[] = {
  112669. 4,
  112670. 3,
  112671. 5,
  112672. 2,
  112673. 6,
  112674. 1,
  112675. 7,
  112676. 0,
  112677. 8,
  112678. };
  112679. static long _vq_lengthlist__8c0_s_p4_0[] = {
  112680. 1, 2, 3, 7, 7, 0, 0, 0, 0, 0, 0, 0, 6, 6, 0, 0,
  112681. 0, 0, 0, 0, 0, 6, 6, 0, 0, 0, 0, 0, 0, 0, 7, 7,
  112682. 0, 0, 0, 0, 0, 0, 0, 7, 7, 0, 0, 0, 0, 0, 0, 0,
  112683. 8, 8, 0, 0, 0, 0, 0, 0, 0, 9, 8, 0, 0, 0, 0, 0,
  112684. 0, 0,10,10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112685. 0,
  112686. };
  112687. static float _vq_quantthresh__8c0_s_p4_0[] = {
  112688. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  112689. };
  112690. static long _vq_quantmap__8c0_s_p4_0[] = {
  112691. 7, 5, 3, 1, 0, 2, 4, 6,
  112692. 8,
  112693. };
  112694. static encode_aux_threshmatch _vq_auxt__8c0_s_p4_0 = {
  112695. _vq_quantthresh__8c0_s_p4_0,
  112696. _vq_quantmap__8c0_s_p4_0,
  112697. 9,
  112698. 9
  112699. };
  112700. static static_codebook _8c0_s_p4_0 = {
  112701. 2, 81,
  112702. _vq_lengthlist__8c0_s_p4_0,
  112703. 1, -531628032, 1611661312, 4, 0,
  112704. _vq_quantlist__8c0_s_p4_0,
  112705. NULL,
  112706. &_vq_auxt__8c0_s_p4_0,
  112707. NULL,
  112708. 0
  112709. };
  112710. static long _vq_quantlist__8c0_s_p5_0[] = {
  112711. 4,
  112712. 3,
  112713. 5,
  112714. 2,
  112715. 6,
  112716. 1,
  112717. 7,
  112718. 0,
  112719. 8,
  112720. };
  112721. static long _vq_lengthlist__8c0_s_p5_0[] = {
  112722. 1, 3, 3, 5, 5, 7, 6, 8, 8, 0, 0, 0, 7, 7, 7, 7,
  112723. 8, 8, 0, 0, 0, 7, 7, 7, 7, 8, 9, 0, 0, 0, 8, 8,
  112724. 8, 8, 9, 9, 0, 0, 0, 8, 8, 8, 8, 9, 9, 0, 0, 0,
  112725. 9, 9, 8, 8,10,10, 0, 0, 0, 9, 9, 8, 8,10,10, 0,
  112726. 0, 0,10,10, 9, 9,10,10, 0, 0, 0, 0, 0, 9, 9,10,
  112727. 10,
  112728. };
  112729. static float _vq_quantthresh__8c0_s_p5_0[] = {
  112730. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  112731. };
  112732. static long _vq_quantmap__8c0_s_p5_0[] = {
  112733. 7, 5, 3, 1, 0, 2, 4, 6,
  112734. 8,
  112735. };
  112736. static encode_aux_threshmatch _vq_auxt__8c0_s_p5_0 = {
  112737. _vq_quantthresh__8c0_s_p5_0,
  112738. _vq_quantmap__8c0_s_p5_0,
  112739. 9,
  112740. 9
  112741. };
  112742. static static_codebook _8c0_s_p5_0 = {
  112743. 2, 81,
  112744. _vq_lengthlist__8c0_s_p5_0,
  112745. 1, -531628032, 1611661312, 4, 0,
  112746. _vq_quantlist__8c0_s_p5_0,
  112747. NULL,
  112748. &_vq_auxt__8c0_s_p5_0,
  112749. NULL,
  112750. 0
  112751. };
  112752. static long _vq_quantlist__8c0_s_p6_0[] = {
  112753. 8,
  112754. 7,
  112755. 9,
  112756. 6,
  112757. 10,
  112758. 5,
  112759. 11,
  112760. 4,
  112761. 12,
  112762. 3,
  112763. 13,
  112764. 2,
  112765. 14,
  112766. 1,
  112767. 15,
  112768. 0,
  112769. 16,
  112770. };
  112771. static long _vq_lengthlist__8c0_s_p6_0[] = {
  112772. 1, 3, 3, 6, 6, 8, 8, 9, 9, 8, 8,10, 9,10,10,11,
  112773. 11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,11,11,
  112774. 11,12, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,11,
  112775. 11,12,11, 0, 0, 0, 8, 8, 9, 9,10,10, 9, 9,10,10,
  112776. 11,11,12,12, 0, 0, 0, 8, 8, 9, 9,10,10, 9, 9,11,
  112777. 10,11,11,12,12, 0, 0, 0, 9, 9, 9, 9,10,10,10,10,
  112778. 11,11,11,12,12,12, 0, 0, 0, 9, 9, 9, 9,10,10,10,
  112779. 10,11,11,12,12,13,13, 0, 0, 0,10,10,10,10,11,11,
  112780. 10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0,10, 9,10,
  112781. 11,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9, 9,
  112782. 10, 9,10,11,12,12,13,13,14,13, 0, 0, 0, 0, 0, 9,
  112783. 9, 9,10,10,10,11,11,13,12,13,13, 0, 0, 0, 0, 0,
  112784. 10,10,10,10,11,11,12,12,13,13,14,14, 0, 0, 0, 0,
  112785. 0, 0, 0,10,10,11,11,12,12,13,13,13,14, 0, 0, 0,
  112786. 0, 0, 0, 0,11,11,11,11,12,12,13,14,14,14, 0, 0,
  112787. 0, 0, 0, 0, 0,11,11,11,11,12,12,13,13,14,13, 0,
  112788. 0, 0, 0, 0, 0, 0,11,11,12,12,13,13,14,14,14,14,
  112789. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,12,12,13,13,14,
  112790. 14,
  112791. };
  112792. static float _vq_quantthresh__8c0_s_p6_0[] = {
  112793. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  112794. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  112795. };
  112796. static long _vq_quantmap__8c0_s_p6_0[] = {
  112797. 15, 13, 11, 9, 7, 5, 3, 1,
  112798. 0, 2, 4, 6, 8, 10, 12, 14,
  112799. 16,
  112800. };
  112801. static encode_aux_threshmatch _vq_auxt__8c0_s_p6_0 = {
  112802. _vq_quantthresh__8c0_s_p6_0,
  112803. _vq_quantmap__8c0_s_p6_0,
  112804. 17,
  112805. 17
  112806. };
  112807. static static_codebook _8c0_s_p6_0 = {
  112808. 2, 289,
  112809. _vq_lengthlist__8c0_s_p6_0,
  112810. 1, -529530880, 1611661312, 5, 0,
  112811. _vq_quantlist__8c0_s_p6_0,
  112812. NULL,
  112813. &_vq_auxt__8c0_s_p6_0,
  112814. NULL,
  112815. 0
  112816. };
  112817. static long _vq_quantlist__8c0_s_p7_0[] = {
  112818. 1,
  112819. 0,
  112820. 2,
  112821. };
  112822. static long _vq_lengthlist__8c0_s_p7_0[] = {
  112823. 1, 4, 4, 7, 6, 6, 7, 6, 6, 4, 7, 7,11, 9,10,12,
  112824. 9,10, 4, 7, 7,10,10,10,11, 9, 9, 6,11,10,11,11,
  112825. 12,11,11,11, 6,10,10,11,11,12,11,10,10, 6, 9,10,
  112826. 11,11,11,11,10,10, 7,10,11,12,11,11,12,11,12, 6,
  112827. 9, 9,10, 9, 9,11,10,10, 6, 9, 9,10,10,10,11,10,
  112828. 10,
  112829. };
  112830. static float _vq_quantthresh__8c0_s_p7_0[] = {
  112831. -5.5, 5.5,
  112832. };
  112833. static long _vq_quantmap__8c0_s_p7_0[] = {
  112834. 1, 0, 2,
  112835. };
  112836. static encode_aux_threshmatch _vq_auxt__8c0_s_p7_0 = {
  112837. _vq_quantthresh__8c0_s_p7_0,
  112838. _vq_quantmap__8c0_s_p7_0,
  112839. 3,
  112840. 3
  112841. };
  112842. static static_codebook _8c0_s_p7_0 = {
  112843. 4, 81,
  112844. _vq_lengthlist__8c0_s_p7_0,
  112845. 1, -529137664, 1618345984, 2, 0,
  112846. _vq_quantlist__8c0_s_p7_0,
  112847. NULL,
  112848. &_vq_auxt__8c0_s_p7_0,
  112849. NULL,
  112850. 0
  112851. };
  112852. static long _vq_quantlist__8c0_s_p7_1[] = {
  112853. 5,
  112854. 4,
  112855. 6,
  112856. 3,
  112857. 7,
  112858. 2,
  112859. 8,
  112860. 1,
  112861. 9,
  112862. 0,
  112863. 10,
  112864. };
  112865. static long _vq_lengthlist__8c0_s_p7_1[] = {
  112866. 1, 3, 3, 6, 6, 8, 8, 9, 9, 9, 9,10,10,10, 7, 7,
  112867. 8, 8, 9, 9, 9, 9,10,10, 9, 7, 7, 8, 8, 9, 9, 9,
  112868. 9,10,10,10, 8, 8, 9, 9, 9, 9, 9, 9,10,10,10, 8,
  112869. 8, 9, 9, 9, 9, 8, 9,10,10,10, 8, 8, 9, 9, 9,10,
  112870. 10,10,10,10,10, 9, 9, 9, 9, 9, 9,10,10,11,10,11,
  112871. 9, 9, 9, 9,10,10,10,10,11,11,11,10,10, 9, 9,10,
  112872. 10,10, 9,11,10,10,10,10,10,10, 9, 9,10,10,11,11,
  112873. 10,10,10, 9, 9, 9,10,10,10,
  112874. };
  112875. static float _vq_quantthresh__8c0_s_p7_1[] = {
  112876. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  112877. 3.5, 4.5,
  112878. };
  112879. static long _vq_quantmap__8c0_s_p7_1[] = {
  112880. 9, 7, 5, 3, 1, 0, 2, 4,
  112881. 6, 8, 10,
  112882. };
  112883. static encode_aux_threshmatch _vq_auxt__8c0_s_p7_1 = {
  112884. _vq_quantthresh__8c0_s_p7_1,
  112885. _vq_quantmap__8c0_s_p7_1,
  112886. 11,
  112887. 11
  112888. };
  112889. static static_codebook _8c0_s_p7_1 = {
  112890. 2, 121,
  112891. _vq_lengthlist__8c0_s_p7_1,
  112892. 1, -531365888, 1611661312, 4, 0,
  112893. _vq_quantlist__8c0_s_p7_1,
  112894. NULL,
  112895. &_vq_auxt__8c0_s_p7_1,
  112896. NULL,
  112897. 0
  112898. };
  112899. static long _vq_quantlist__8c0_s_p8_0[] = {
  112900. 6,
  112901. 5,
  112902. 7,
  112903. 4,
  112904. 8,
  112905. 3,
  112906. 9,
  112907. 2,
  112908. 10,
  112909. 1,
  112910. 11,
  112911. 0,
  112912. 12,
  112913. };
  112914. static long _vq_lengthlist__8c0_s_p8_0[] = {
  112915. 1, 4, 4, 7, 6, 7, 7, 7, 7, 8, 8, 9, 9, 7, 6, 6,
  112916. 7, 7, 8, 8, 7, 7, 8, 9,10,10, 7, 6, 6, 7, 7, 8,
  112917. 7, 7, 7, 9, 9,10,12, 0, 8, 8, 8, 8, 8, 9, 8, 8,
  112918. 9, 9,10,10, 0, 8, 8, 8, 8, 8, 9, 8, 9, 9, 9,11,
  112919. 10, 0, 0,13, 9, 8, 9, 9, 9, 9,10,10,11,11, 0,13,
  112920. 0, 9, 9, 9, 9, 9, 9,11,10,11,11, 0, 0, 0, 8, 9,
  112921. 10, 9,10,10,13,11,12,12, 0, 0, 0, 8, 9, 9, 9,10,
  112922. 10,13,12,12,13, 0, 0, 0,12, 0,10,10,12,11,10,11,
  112923. 12,12, 0, 0, 0,13,13,10,10,10,11,12, 0,13, 0, 0,
  112924. 0, 0, 0, 0,13,11, 0,12,12,12,13,12, 0, 0, 0, 0,
  112925. 0, 0,13,13,11,13,13,11,12,
  112926. };
  112927. static float _vq_quantthresh__8c0_s_p8_0[] = {
  112928. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  112929. 12.5, 17.5, 22.5, 27.5,
  112930. };
  112931. static long _vq_quantmap__8c0_s_p8_0[] = {
  112932. 11, 9, 7, 5, 3, 1, 0, 2,
  112933. 4, 6, 8, 10, 12,
  112934. };
  112935. static encode_aux_threshmatch _vq_auxt__8c0_s_p8_0 = {
  112936. _vq_quantthresh__8c0_s_p8_0,
  112937. _vq_quantmap__8c0_s_p8_0,
  112938. 13,
  112939. 13
  112940. };
  112941. static static_codebook _8c0_s_p8_0 = {
  112942. 2, 169,
  112943. _vq_lengthlist__8c0_s_p8_0,
  112944. 1, -526516224, 1616117760, 4, 0,
  112945. _vq_quantlist__8c0_s_p8_0,
  112946. NULL,
  112947. &_vq_auxt__8c0_s_p8_0,
  112948. NULL,
  112949. 0
  112950. };
  112951. static long _vq_quantlist__8c0_s_p8_1[] = {
  112952. 2,
  112953. 1,
  112954. 3,
  112955. 0,
  112956. 4,
  112957. };
  112958. static long _vq_lengthlist__8c0_s_p8_1[] = {
  112959. 1, 3, 4, 5, 5, 7, 6, 6, 6, 5, 7, 7, 7, 6, 6, 7,
  112960. 7, 7, 6, 6, 7, 7, 7, 6, 6,
  112961. };
  112962. static float _vq_quantthresh__8c0_s_p8_1[] = {
  112963. -1.5, -0.5, 0.5, 1.5,
  112964. };
  112965. static long _vq_quantmap__8c0_s_p8_1[] = {
  112966. 3, 1, 0, 2, 4,
  112967. };
  112968. static encode_aux_threshmatch _vq_auxt__8c0_s_p8_1 = {
  112969. _vq_quantthresh__8c0_s_p8_1,
  112970. _vq_quantmap__8c0_s_p8_1,
  112971. 5,
  112972. 5
  112973. };
  112974. static static_codebook _8c0_s_p8_1 = {
  112975. 2, 25,
  112976. _vq_lengthlist__8c0_s_p8_1,
  112977. 1, -533725184, 1611661312, 3, 0,
  112978. _vq_quantlist__8c0_s_p8_1,
  112979. NULL,
  112980. &_vq_auxt__8c0_s_p8_1,
  112981. NULL,
  112982. 0
  112983. };
  112984. static long _vq_quantlist__8c0_s_p9_0[] = {
  112985. 1,
  112986. 0,
  112987. 2,
  112988. };
  112989. static long _vq_lengthlist__8c0_s_p9_0[] = {
  112990. 1, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  112991. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  112992. 8, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  112993. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  112994. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  112995. 7,
  112996. };
  112997. static float _vq_quantthresh__8c0_s_p9_0[] = {
  112998. -157.5, 157.5,
  112999. };
  113000. static long _vq_quantmap__8c0_s_p9_0[] = {
  113001. 1, 0, 2,
  113002. };
  113003. static encode_aux_threshmatch _vq_auxt__8c0_s_p9_0 = {
  113004. _vq_quantthresh__8c0_s_p9_0,
  113005. _vq_quantmap__8c0_s_p9_0,
  113006. 3,
  113007. 3
  113008. };
  113009. static static_codebook _8c0_s_p9_0 = {
  113010. 4, 81,
  113011. _vq_lengthlist__8c0_s_p9_0,
  113012. 1, -518803456, 1628680192, 2, 0,
  113013. _vq_quantlist__8c0_s_p9_0,
  113014. NULL,
  113015. &_vq_auxt__8c0_s_p9_0,
  113016. NULL,
  113017. 0
  113018. };
  113019. static long _vq_quantlist__8c0_s_p9_1[] = {
  113020. 7,
  113021. 6,
  113022. 8,
  113023. 5,
  113024. 9,
  113025. 4,
  113026. 10,
  113027. 3,
  113028. 11,
  113029. 2,
  113030. 12,
  113031. 1,
  113032. 13,
  113033. 0,
  113034. 14,
  113035. };
  113036. static long _vq_lengthlist__8c0_s_p9_1[] = {
  113037. 1, 4, 4, 5, 5,10, 8,11,11,11,11,11,11,11,11, 6,
  113038. 6, 6, 7, 6,11,10,11,11,11,11,11,11,11,11, 7, 5,
  113039. 6, 6, 6, 8, 7,11,11,11,11,11,11,11,11,11, 7, 8,
  113040. 8, 8, 9, 9,11,11,11,11,11,11,11,11,11, 9, 8, 7,
  113041. 8, 9,11,11,11,11,11,11,11,11,11,11,11,10,11,11,
  113042. 11,11,11,11,11,11,11,11,11,11,11,11,11,10,11,11,
  113043. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  113044. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  113045. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  113046. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  113047. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  113048. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  113049. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  113050. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  113051. 11,
  113052. };
  113053. static float _vq_quantthresh__8c0_s_p9_1[] = {
  113054. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  113055. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  113056. };
  113057. static long _vq_quantmap__8c0_s_p9_1[] = {
  113058. 13, 11, 9, 7, 5, 3, 1, 0,
  113059. 2, 4, 6, 8, 10, 12, 14,
  113060. };
  113061. static encode_aux_threshmatch _vq_auxt__8c0_s_p9_1 = {
  113062. _vq_quantthresh__8c0_s_p9_1,
  113063. _vq_quantmap__8c0_s_p9_1,
  113064. 15,
  113065. 15
  113066. };
  113067. static static_codebook _8c0_s_p9_1 = {
  113068. 2, 225,
  113069. _vq_lengthlist__8c0_s_p9_1,
  113070. 1, -520986624, 1620377600, 4, 0,
  113071. _vq_quantlist__8c0_s_p9_1,
  113072. NULL,
  113073. &_vq_auxt__8c0_s_p9_1,
  113074. NULL,
  113075. 0
  113076. };
  113077. static long _vq_quantlist__8c0_s_p9_2[] = {
  113078. 10,
  113079. 9,
  113080. 11,
  113081. 8,
  113082. 12,
  113083. 7,
  113084. 13,
  113085. 6,
  113086. 14,
  113087. 5,
  113088. 15,
  113089. 4,
  113090. 16,
  113091. 3,
  113092. 17,
  113093. 2,
  113094. 18,
  113095. 1,
  113096. 19,
  113097. 0,
  113098. 20,
  113099. };
  113100. static long _vq_lengthlist__8c0_s_p9_2[] = {
  113101. 1, 5, 5, 7, 7, 8, 7, 8, 8,10,10, 9, 9,10,10,10,
  113102. 11,11,10,12,11,12,12,12, 9, 8, 8, 8, 8, 8, 9,10,
  113103. 10,10,10,11,11,11,10,11,11,12,12,11,12, 8, 8, 7,
  113104. 7, 8, 9,10,10,10, 9,10,10, 9,10,10,11,11,11,11,
  113105. 11,11, 9, 9, 9, 9, 8, 9,10,10,11,10,10,11,11,12,
  113106. 10,10,12,12,11,11,10, 9, 9,10, 8, 9,10,10,10, 9,
  113107. 10,10,11,11,10,11,10,10,10,12,12,12, 9,10, 9,10,
  113108. 9, 9,10,10,11,11,11,11,10,10,10,11,12,11,12,11,
  113109. 12,10,11,10,11, 9,10, 9,10, 9,10,10, 9,10,10,11,
  113110. 10,11,11,11,11,12,11, 9,10,10,10,10,11,11,11,11,
  113111. 11,10,11,11,11,11,10,12,10,12,12,11,12,10,10,11,
  113112. 10, 9,11,10,11, 9,10,11,10,10,10,11,11,11,11,12,
  113113. 12,10, 9, 9,11,10, 9,12,11,10,12,12,11,11,11,11,
  113114. 10,11,11,12,11,10,12, 9,11,10,11,10,10,11,10,11,
  113115. 9,10,10,10,11,12,11,11,12,11,10,10,11,11, 9,10,
  113116. 10,12,10,11,10,10,10, 9,10,10,10,10, 9,10,10,11,
  113117. 11,11,11,12,11,10,10,10,10,11,11,10,11,11, 9,11,
  113118. 10,12,10,12,11,10,11,10,10,10,11,10,10,11,11,10,
  113119. 11,10,10,10,10,11,11,12,10,10,10,11,10,11,12,11,
  113120. 10,11,10,10,11,11,10,12,10, 9,10,10,11,11,11,10,
  113121. 12,10,10,11,11,11,10,10,11,10,10,10,11,10,11,10,
  113122. 12,11,11,10,10,10,12,10,10,11, 9,10,11,11,11,10,
  113123. 10,11,10,10, 9,11,11,12,12,11,12,11,11,11,11,11,
  113124. 11, 9,10,11,10,12,10,10,10,10,11,10,10,11,10,10,
  113125. 12,10,10,10,10,10, 9,12,10,10,10,10,12, 9,11,10,
  113126. 10,11,10,12,12,10,12,12,12,10,10,10,10, 9,10,11,
  113127. 10,10,12,10,10,12,11,10,11,10,10,12,11,10,12,10,
  113128. 10,11, 9,11,10, 9,10, 9,10,
  113129. };
  113130. static float _vq_quantthresh__8c0_s_p9_2[] = {
  113131. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  113132. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  113133. 6.5, 7.5, 8.5, 9.5,
  113134. };
  113135. static long _vq_quantmap__8c0_s_p9_2[] = {
  113136. 19, 17, 15, 13, 11, 9, 7, 5,
  113137. 3, 1, 0, 2, 4, 6, 8, 10,
  113138. 12, 14, 16, 18, 20,
  113139. };
  113140. static encode_aux_threshmatch _vq_auxt__8c0_s_p9_2 = {
  113141. _vq_quantthresh__8c0_s_p9_2,
  113142. _vq_quantmap__8c0_s_p9_2,
  113143. 21,
  113144. 21
  113145. };
  113146. static static_codebook _8c0_s_p9_2 = {
  113147. 2, 441,
  113148. _vq_lengthlist__8c0_s_p9_2,
  113149. 1, -529268736, 1611661312, 5, 0,
  113150. _vq_quantlist__8c0_s_p9_2,
  113151. NULL,
  113152. &_vq_auxt__8c0_s_p9_2,
  113153. NULL,
  113154. 0
  113155. };
  113156. static long _huff_lengthlist__8c0_s_single[] = {
  113157. 4, 5,18, 7,10, 6, 7, 8, 9,10, 5, 2,18, 5, 7, 5,
  113158. 6, 7, 8,11,17,17,17,17,17,17,17,17,17,17, 7, 4,
  113159. 17, 6, 9, 6, 8,10,12,15,11, 7,17, 9, 6, 6, 7, 9,
  113160. 11,15, 6, 4,17, 6, 6, 4, 5, 8,11,16, 6, 6,17, 8,
  113161. 6, 5, 6, 9,13,16, 8, 9,17,11, 9, 8, 8,11,13,17,
  113162. 9,12,17,15,14,13,12,13,14,17,12,15,17,17,17,17,
  113163. 17,16,17,17,
  113164. };
  113165. static static_codebook _huff_book__8c0_s_single = {
  113166. 2, 100,
  113167. _huff_lengthlist__8c0_s_single,
  113168. 0, 0, 0, 0, 0,
  113169. NULL,
  113170. NULL,
  113171. NULL,
  113172. NULL,
  113173. 0
  113174. };
  113175. static long _vq_quantlist__8c1_s_p1_0[] = {
  113176. 1,
  113177. 0,
  113178. 2,
  113179. };
  113180. static long _vq_lengthlist__8c1_s_p1_0[] = {
  113181. 1, 5, 5, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0, 0, 0, 0,
  113182. 0, 0, 5, 7, 7, 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, 5, 8, 7, 0, 0, 0, 0, 0, 0, 7, 8, 9, 0, 0, 0,
  113187. 0, 0, 0, 7, 8, 9, 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, 5, 7, 8, 0, 0, 0, 0, 0, 0, 7, 9, 8, 0, 0,
  113192. 0, 0, 0, 0, 7, 9, 8, 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, 5, 8, 8, 0, 0, 0, 0,
  113227. 0, 0, 8, 9, 9, 0, 0, 0, 0, 0, 0, 8, 9, 9, 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, 7, 9, 9, 0, 0, 0,
  113232. 0, 0, 0, 8, 8,10, 0, 0, 0, 0, 0, 0, 9,10,10, 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, 7, 9, 9, 0, 0,
  113237. 0, 0, 0, 0, 8,10, 9, 0, 0, 0, 0, 0, 0, 9,10,10,
  113238. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113239. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113240. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113241. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113242. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113243. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113244. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113245. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113246. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113247. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113248. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113249. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113250. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113251. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113252. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113253. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113254. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113255. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113256. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113257. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113258. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113259. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113260. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113261. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113262. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113263. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113264. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113265. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113266. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113267. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113268. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113269. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113270. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113271. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113272. 0, 0, 5, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0, 0,
  113273. 0, 0, 0, 0, 8, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113274. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113275. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113276. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113277. 0, 0, 0, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,10,10, 0,
  113278. 0, 0, 0, 0, 0, 8, 9,10, 0, 0, 0, 0, 0, 0, 0, 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, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,10,10,
  113283. 0, 0, 0, 0, 0, 0, 8,10, 8, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113319. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113320. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113321. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113322. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113323. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113324. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113325. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113326. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113327. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113328. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113329. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113330. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113331. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113332. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113333. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113334. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113335. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113336. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113337. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113338. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113339. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113340. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113341. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113342. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113343. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113344. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113345. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113346. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113347. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113348. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113349. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113350. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113351. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113352. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113353. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113354. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113355. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113356. 0, 0, 0, 0, 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113390. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113391. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113392. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113393. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113394. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113395. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113396. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113397. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113398. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113399. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113400. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113401. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113402. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113403. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113404. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113405. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113406. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113407. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113408. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113409. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113410. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113411. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113412. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113413. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113414. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113415. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113416. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113417. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113418. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113419. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113420. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113421. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113422. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113423. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113424. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113425. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113426. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113427. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113428. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113429. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113430. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113431. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113432. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113433. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113434. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113435. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113436. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113437. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113438. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113439. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113440. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113441. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113442. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113443. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113444. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113445. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113446. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113447. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113448. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113449. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113450. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113451. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113452. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113453. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113454. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113455. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113456. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113457. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113458. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113459. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113460. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113461. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113462. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113463. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113464. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113465. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113466. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113467. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113468. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113469. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113470. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113471. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113472. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113473. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113474. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113475. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113476. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113477. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113478. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113479. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113480. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113481. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113482. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113483. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113484. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113485. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113486. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113487. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113488. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113489. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113490. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113491. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113492. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113493. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113494. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113495. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113496. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113497. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113498. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113499. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113500. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113501. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113502. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113503. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113504. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113505. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113506. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113507. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113508. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113509. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113510. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113511. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113512. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113513. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113514. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113515. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113516. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113517. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113518. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113519. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113520. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113521. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113522. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113523. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113524. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113525. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113526. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113527. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113528. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113529. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113530. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113531. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113532. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113533. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113534. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113535. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113536. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113537. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113538. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113539. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113540. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113541. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113542. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113543. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113544. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113545. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113546. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113547. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113548. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113549. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113550. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113551. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113552. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113553. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113554. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113555. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113556. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113557. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113558. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113559. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113560. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113561. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113562. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113563. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113564. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113565. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113566. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113567. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113568. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113569. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113570. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113571. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113572. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113573. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113574. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113575. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113576. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113577. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113578. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113579. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113580. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113581. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113582. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113583. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113584. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113585. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113586. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113587. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113588. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113589. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113590. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113591. 0,
  113592. };
  113593. static float _vq_quantthresh__8c1_s_p1_0[] = {
  113594. -0.5, 0.5,
  113595. };
  113596. static long _vq_quantmap__8c1_s_p1_0[] = {
  113597. 1, 0, 2,
  113598. };
  113599. static encode_aux_threshmatch _vq_auxt__8c1_s_p1_0 = {
  113600. _vq_quantthresh__8c1_s_p1_0,
  113601. _vq_quantmap__8c1_s_p1_0,
  113602. 3,
  113603. 3
  113604. };
  113605. static static_codebook _8c1_s_p1_0 = {
  113606. 8, 6561,
  113607. _vq_lengthlist__8c1_s_p1_0,
  113608. 1, -535822336, 1611661312, 2, 0,
  113609. _vq_quantlist__8c1_s_p1_0,
  113610. NULL,
  113611. &_vq_auxt__8c1_s_p1_0,
  113612. NULL,
  113613. 0
  113614. };
  113615. static long _vq_quantlist__8c1_s_p2_0[] = {
  113616. 2,
  113617. 1,
  113618. 3,
  113619. 0,
  113620. 4,
  113621. };
  113622. static long _vq_lengthlist__8c1_s_p2_0[] = {
  113623. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113624. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113625. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113626. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113627. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113628. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113629. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113630. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113631. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113632. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113633. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113634. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113635. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113636. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113637. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113638. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113639. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113640. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113641. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113642. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113643. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113644. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113645. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113646. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113647. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113648. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113649. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113650. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113651. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113652. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113653. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113654. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113655. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113656. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113657. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113658. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113659. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113660. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113661. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113662. 0,
  113663. };
  113664. static float _vq_quantthresh__8c1_s_p2_0[] = {
  113665. -1.5, -0.5, 0.5, 1.5,
  113666. };
  113667. static long _vq_quantmap__8c1_s_p2_0[] = {
  113668. 3, 1, 0, 2, 4,
  113669. };
  113670. static encode_aux_threshmatch _vq_auxt__8c1_s_p2_0 = {
  113671. _vq_quantthresh__8c1_s_p2_0,
  113672. _vq_quantmap__8c1_s_p2_0,
  113673. 5,
  113674. 5
  113675. };
  113676. static static_codebook _8c1_s_p2_0 = {
  113677. 4, 625,
  113678. _vq_lengthlist__8c1_s_p2_0,
  113679. 1, -533725184, 1611661312, 3, 0,
  113680. _vq_quantlist__8c1_s_p2_0,
  113681. NULL,
  113682. &_vq_auxt__8c1_s_p2_0,
  113683. NULL,
  113684. 0
  113685. };
  113686. static long _vq_quantlist__8c1_s_p3_0[] = {
  113687. 2,
  113688. 1,
  113689. 3,
  113690. 0,
  113691. 4,
  113692. };
  113693. static long _vq_lengthlist__8c1_s_p3_0[] = {
  113694. 2, 4, 4, 5, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113695. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 4, 4, 6, 6, 0, 0,
  113696. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113697. 0, 0, 4, 4, 4, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113698. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 6, 6, 7, 7,
  113699. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113700. 0, 0, 0, 0, 6, 6, 6, 7, 7, 0, 0, 0, 0, 0, 0, 0,
  113701. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113702. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113703. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113704. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113705. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113706. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113707. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113708. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113709. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113710. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113711. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113712. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113713. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113714. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113715. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113716. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113717. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113718. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113719. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113720. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113721. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113722. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113723. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113724. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113725. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113726. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113727. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113728. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113729. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113730. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113731. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113732. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113733. 0,
  113734. };
  113735. static float _vq_quantthresh__8c1_s_p3_0[] = {
  113736. -1.5, -0.5, 0.5, 1.5,
  113737. };
  113738. static long _vq_quantmap__8c1_s_p3_0[] = {
  113739. 3, 1, 0, 2, 4,
  113740. };
  113741. static encode_aux_threshmatch _vq_auxt__8c1_s_p3_0 = {
  113742. _vq_quantthresh__8c1_s_p3_0,
  113743. _vq_quantmap__8c1_s_p3_0,
  113744. 5,
  113745. 5
  113746. };
  113747. static static_codebook _8c1_s_p3_0 = {
  113748. 4, 625,
  113749. _vq_lengthlist__8c1_s_p3_0,
  113750. 1, -533725184, 1611661312, 3, 0,
  113751. _vq_quantlist__8c1_s_p3_0,
  113752. NULL,
  113753. &_vq_auxt__8c1_s_p3_0,
  113754. NULL,
  113755. 0
  113756. };
  113757. static long _vq_quantlist__8c1_s_p4_0[] = {
  113758. 4,
  113759. 3,
  113760. 5,
  113761. 2,
  113762. 6,
  113763. 1,
  113764. 7,
  113765. 0,
  113766. 8,
  113767. };
  113768. static long _vq_lengthlist__8c1_s_p4_0[] = {
  113769. 1, 2, 3, 7, 7, 0, 0, 0, 0, 0, 0, 0, 6, 6, 0, 0,
  113770. 0, 0, 0, 0, 0, 6, 6, 0, 0, 0, 0, 0, 0, 0, 7, 7,
  113771. 0, 0, 0, 0, 0, 0, 0, 7, 7, 0, 0, 0, 0, 0, 0, 0,
  113772. 8, 8, 0, 0, 0, 0, 0, 0, 0, 9, 8, 0, 0, 0, 0, 0,
  113773. 0, 0,10,10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113774. 0,
  113775. };
  113776. static float _vq_quantthresh__8c1_s_p4_0[] = {
  113777. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  113778. };
  113779. static long _vq_quantmap__8c1_s_p4_0[] = {
  113780. 7, 5, 3, 1, 0, 2, 4, 6,
  113781. 8,
  113782. };
  113783. static encode_aux_threshmatch _vq_auxt__8c1_s_p4_0 = {
  113784. _vq_quantthresh__8c1_s_p4_0,
  113785. _vq_quantmap__8c1_s_p4_0,
  113786. 9,
  113787. 9
  113788. };
  113789. static static_codebook _8c1_s_p4_0 = {
  113790. 2, 81,
  113791. _vq_lengthlist__8c1_s_p4_0,
  113792. 1, -531628032, 1611661312, 4, 0,
  113793. _vq_quantlist__8c1_s_p4_0,
  113794. NULL,
  113795. &_vq_auxt__8c1_s_p4_0,
  113796. NULL,
  113797. 0
  113798. };
  113799. static long _vq_quantlist__8c1_s_p5_0[] = {
  113800. 4,
  113801. 3,
  113802. 5,
  113803. 2,
  113804. 6,
  113805. 1,
  113806. 7,
  113807. 0,
  113808. 8,
  113809. };
  113810. static long _vq_lengthlist__8c1_s_p5_0[] = {
  113811. 1, 3, 3, 4, 5, 6, 6, 8, 8, 0, 0, 0, 8, 8, 7, 7,
  113812. 9, 9, 0, 0, 0, 8, 8, 7, 7, 9, 9, 0, 0, 0, 9,10,
  113813. 8, 8, 9, 9, 0, 0, 0,10,10, 8, 8, 9, 9, 0, 0, 0,
  113814. 11,10, 8, 8,10,10, 0, 0, 0,11,11, 8, 8,10,10, 0,
  113815. 0, 0,12,12, 9, 9,10,10, 0, 0, 0, 0, 0, 9, 9,10,
  113816. 10,
  113817. };
  113818. static float _vq_quantthresh__8c1_s_p5_0[] = {
  113819. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  113820. };
  113821. static long _vq_quantmap__8c1_s_p5_0[] = {
  113822. 7, 5, 3, 1, 0, 2, 4, 6,
  113823. 8,
  113824. };
  113825. static encode_aux_threshmatch _vq_auxt__8c1_s_p5_0 = {
  113826. _vq_quantthresh__8c1_s_p5_0,
  113827. _vq_quantmap__8c1_s_p5_0,
  113828. 9,
  113829. 9
  113830. };
  113831. static static_codebook _8c1_s_p5_0 = {
  113832. 2, 81,
  113833. _vq_lengthlist__8c1_s_p5_0,
  113834. 1, -531628032, 1611661312, 4, 0,
  113835. _vq_quantlist__8c1_s_p5_0,
  113836. NULL,
  113837. &_vq_auxt__8c1_s_p5_0,
  113838. NULL,
  113839. 0
  113840. };
  113841. static long _vq_quantlist__8c1_s_p6_0[] = {
  113842. 8,
  113843. 7,
  113844. 9,
  113845. 6,
  113846. 10,
  113847. 5,
  113848. 11,
  113849. 4,
  113850. 12,
  113851. 3,
  113852. 13,
  113853. 2,
  113854. 14,
  113855. 1,
  113856. 15,
  113857. 0,
  113858. 16,
  113859. };
  113860. static long _vq_lengthlist__8c1_s_p6_0[] = {
  113861. 1, 3, 3, 5, 5, 8, 8, 8, 8, 9, 9,10,10,11,11,11,
  113862. 11, 0, 0, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,11,
  113863. 12,12, 0, 0, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,
  113864. 11,12,12, 0, 0, 0, 9, 9, 8, 8,10,10,10,10,11,11,
  113865. 12,12,12,12, 0, 0, 0, 9, 9, 8, 8,10,10,10,10,11,
  113866. 11,12,12,12,12, 0, 0, 0,10,10, 9, 9,10,10,10,10,
  113867. 11,11,12,12,13,13, 0, 0, 0,10,10, 9, 9,10,10,10,
  113868. 10,11,11,12,12,13,13, 0, 0, 0,11,11, 9, 9,10,10,
  113869. 10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9, 9,10,
  113870. 10,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9, 9,
  113871. 10,10,11,11,12,12,12,12,13,13, 0, 0, 0, 0, 0, 9,
  113872. 9,10,10,11,11,12,11,12,12,13,13, 0, 0, 0, 0, 0,
  113873. 10,10,11,11,11,11,12,12,13,12,13,13, 0, 0, 0, 0,
  113874. 0, 0, 0,11,10,11,11,12,12,13,13,13,13, 0, 0, 0,
  113875. 0, 0, 0, 0,11,11,12,12,12,12,13,13,13,14, 0, 0,
  113876. 0, 0, 0, 0, 0,11,11,12,12,12,12,13,13,14,13, 0,
  113877. 0, 0, 0, 0, 0, 0,12,12,12,12,13,13,13,13,14,14,
  113878. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,13,13,13,13,14,
  113879. 14,
  113880. };
  113881. static float _vq_quantthresh__8c1_s_p6_0[] = {
  113882. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  113883. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  113884. };
  113885. static long _vq_quantmap__8c1_s_p6_0[] = {
  113886. 15, 13, 11, 9, 7, 5, 3, 1,
  113887. 0, 2, 4, 6, 8, 10, 12, 14,
  113888. 16,
  113889. };
  113890. static encode_aux_threshmatch _vq_auxt__8c1_s_p6_0 = {
  113891. _vq_quantthresh__8c1_s_p6_0,
  113892. _vq_quantmap__8c1_s_p6_0,
  113893. 17,
  113894. 17
  113895. };
  113896. static static_codebook _8c1_s_p6_0 = {
  113897. 2, 289,
  113898. _vq_lengthlist__8c1_s_p6_0,
  113899. 1, -529530880, 1611661312, 5, 0,
  113900. _vq_quantlist__8c1_s_p6_0,
  113901. NULL,
  113902. &_vq_auxt__8c1_s_p6_0,
  113903. NULL,
  113904. 0
  113905. };
  113906. static long _vq_quantlist__8c1_s_p7_0[] = {
  113907. 1,
  113908. 0,
  113909. 2,
  113910. };
  113911. static long _vq_lengthlist__8c1_s_p7_0[] = {
  113912. 1, 4, 4, 6, 6, 6, 7, 6, 6, 4, 7, 7,10, 9, 9,10,
  113913. 9, 9, 5, 7, 7,10, 9, 9,10, 9, 9, 6,10,10,10,10,
  113914. 10,11,10,10, 6, 9, 9,10, 9,10,11,10,10, 6, 9, 9,
  113915. 10, 9, 9,11, 9,10, 7,10,10,11,11,11,11,10,10, 6,
  113916. 9, 9,10,10,10,11, 9, 9, 6, 9, 9,10,10,10,10, 9,
  113917. 9,
  113918. };
  113919. static float _vq_quantthresh__8c1_s_p7_0[] = {
  113920. -5.5, 5.5,
  113921. };
  113922. static long _vq_quantmap__8c1_s_p7_0[] = {
  113923. 1, 0, 2,
  113924. };
  113925. static encode_aux_threshmatch _vq_auxt__8c1_s_p7_0 = {
  113926. _vq_quantthresh__8c1_s_p7_0,
  113927. _vq_quantmap__8c1_s_p7_0,
  113928. 3,
  113929. 3
  113930. };
  113931. static static_codebook _8c1_s_p7_0 = {
  113932. 4, 81,
  113933. _vq_lengthlist__8c1_s_p7_0,
  113934. 1, -529137664, 1618345984, 2, 0,
  113935. _vq_quantlist__8c1_s_p7_0,
  113936. NULL,
  113937. &_vq_auxt__8c1_s_p7_0,
  113938. NULL,
  113939. 0
  113940. };
  113941. static long _vq_quantlist__8c1_s_p7_1[] = {
  113942. 5,
  113943. 4,
  113944. 6,
  113945. 3,
  113946. 7,
  113947. 2,
  113948. 8,
  113949. 1,
  113950. 9,
  113951. 0,
  113952. 10,
  113953. };
  113954. static long _vq_lengthlist__8c1_s_p7_1[] = {
  113955. 2, 3, 3, 5, 5, 7, 7, 7, 7, 7, 7,10,10, 9, 7, 7,
  113956. 7, 7, 8, 8, 8, 8, 9, 9, 9, 7, 7, 7, 7, 8, 8, 8,
  113957. 8,10,10,10, 7, 7, 7, 7, 8, 8, 8, 8,10,10,10, 7,
  113958. 7, 7, 7, 8, 8, 8, 8,10,10,10, 8, 8, 8, 8, 8, 8,
  113959. 8, 8,10,10,10, 8, 8, 8, 8, 8, 8, 8, 8,10,10,10,
  113960. 8, 8, 8, 8, 8, 8, 8, 8,10,10,10,10,10, 8, 8, 8,
  113961. 8, 8, 8,10,10,10,10,10, 8, 8, 8, 8, 8, 8,10,10,
  113962. 10,10,10, 8, 8, 8, 8, 8, 8,
  113963. };
  113964. static float _vq_quantthresh__8c1_s_p7_1[] = {
  113965. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  113966. 3.5, 4.5,
  113967. };
  113968. static long _vq_quantmap__8c1_s_p7_1[] = {
  113969. 9, 7, 5, 3, 1, 0, 2, 4,
  113970. 6, 8, 10,
  113971. };
  113972. static encode_aux_threshmatch _vq_auxt__8c1_s_p7_1 = {
  113973. _vq_quantthresh__8c1_s_p7_1,
  113974. _vq_quantmap__8c1_s_p7_1,
  113975. 11,
  113976. 11
  113977. };
  113978. static static_codebook _8c1_s_p7_1 = {
  113979. 2, 121,
  113980. _vq_lengthlist__8c1_s_p7_1,
  113981. 1, -531365888, 1611661312, 4, 0,
  113982. _vq_quantlist__8c1_s_p7_1,
  113983. NULL,
  113984. &_vq_auxt__8c1_s_p7_1,
  113985. NULL,
  113986. 0
  113987. };
  113988. static long _vq_quantlist__8c1_s_p8_0[] = {
  113989. 6,
  113990. 5,
  113991. 7,
  113992. 4,
  113993. 8,
  113994. 3,
  113995. 9,
  113996. 2,
  113997. 10,
  113998. 1,
  113999. 11,
  114000. 0,
  114001. 12,
  114002. };
  114003. static long _vq_lengthlist__8c1_s_p8_0[] = {
  114004. 1, 4, 4, 6, 6, 8, 8, 8, 8, 9, 9,10,10, 7, 5, 5,
  114005. 7, 7, 8, 8, 8, 8, 9,10,11,11, 7, 5, 5, 7, 7, 8,
  114006. 8, 9, 9,10,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  114007. 9,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,
  114008. 11, 0,12,12, 9, 9, 9, 9,10, 9,10,11,11,11, 0,13,
  114009. 12, 9, 8, 9, 9,10,10,11,11,12,11, 0, 0, 0, 9, 9,
  114010. 9, 9,10,10,11,11,12,12, 0, 0, 0,10,10, 9, 9,10,
  114011. 10,11,11,12,12, 0, 0, 0,13,13,10,10,11,11,12,11,
  114012. 13,12, 0, 0, 0,14,14,10,10,11,10,11,11,12,12, 0,
  114013. 0, 0, 0, 0,12,12,11,11,12,12,13,13, 0, 0, 0, 0,
  114014. 0,12,12,11,10,12,11,13,12,
  114015. };
  114016. static float _vq_quantthresh__8c1_s_p8_0[] = {
  114017. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  114018. 12.5, 17.5, 22.5, 27.5,
  114019. };
  114020. static long _vq_quantmap__8c1_s_p8_0[] = {
  114021. 11, 9, 7, 5, 3, 1, 0, 2,
  114022. 4, 6, 8, 10, 12,
  114023. };
  114024. static encode_aux_threshmatch _vq_auxt__8c1_s_p8_0 = {
  114025. _vq_quantthresh__8c1_s_p8_0,
  114026. _vq_quantmap__8c1_s_p8_0,
  114027. 13,
  114028. 13
  114029. };
  114030. static static_codebook _8c1_s_p8_0 = {
  114031. 2, 169,
  114032. _vq_lengthlist__8c1_s_p8_0,
  114033. 1, -526516224, 1616117760, 4, 0,
  114034. _vq_quantlist__8c1_s_p8_0,
  114035. NULL,
  114036. &_vq_auxt__8c1_s_p8_0,
  114037. NULL,
  114038. 0
  114039. };
  114040. static long _vq_quantlist__8c1_s_p8_1[] = {
  114041. 2,
  114042. 1,
  114043. 3,
  114044. 0,
  114045. 4,
  114046. };
  114047. static long _vq_lengthlist__8c1_s_p8_1[] = {
  114048. 2, 3, 3, 5, 5, 6, 6, 6, 5, 5, 6, 6, 6, 5, 5, 6,
  114049. 6, 6, 5, 5, 6, 6, 6, 5, 5,
  114050. };
  114051. static float _vq_quantthresh__8c1_s_p8_1[] = {
  114052. -1.5, -0.5, 0.5, 1.5,
  114053. };
  114054. static long _vq_quantmap__8c1_s_p8_1[] = {
  114055. 3, 1, 0, 2, 4,
  114056. };
  114057. static encode_aux_threshmatch _vq_auxt__8c1_s_p8_1 = {
  114058. _vq_quantthresh__8c1_s_p8_1,
  114059. _vq_quantmap__8c1_s_p8_1,
  114060. 5,
  114061. 5
  114062. };
  114063. static static_codebook _8c1_s_p8_1 = {
  114064. 2, 25,
  114065. _vq_lengthlist__8c1_s_p8_1,
  114066. 1, -533725184, 1611661312, 3, 0,
  114067. _vq_quantlist__8c1_s_p8_1,
  114068. NULL,
  114069. &_vq_auxt__8c1_s_p8_1,
  114070. NULL,
  114071. 0
  114072. };
  114073. static long _vq_quantlist__8c1_s_p9_0[] = {
  114074. 6,
  114075. 5,
  114076. 7,
  114077. 4,
  114078. 8,
  114079. 3,
  114080. 9,
  114081. 2,
  114082. 10,
  114083. 1,
  114084. 11,
  114085. 0,
  114086. 12,
  114087. };
  114088. static long _vq_lengthlist__8c1_s_p9_0[] = {
  114089. 1, 3, 3,10,10,10,10,10,10,10,10,10,10, 5, 6, 6,
  114090. 10,10,10,10,10,10,10,10,10,10, 6, 7, 8,10,10,10,
  114091. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  114092. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  114093. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  114094. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  114095. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  114096. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  114097. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  114098. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  114099. 10,10,10,10,10, 9, 9, 9, 9,
  114100. };
  114101. static float _vq_quantthresh__8c1_s_p9_0[] = {
  114102. -1732.5, -1417.5, -1102.5, -787.5, -472.5, -157.5, 157.5, 472.5,
  114103. 787.5, 1102.5, 1417.5, 1732.5,
  114104. };
  114105. static long _vq_quantmap__8c1_s_p9_0[] = {
  114106. 11, 9, 7, 5, 3, 1, 0, 2,
  114107. 4, 6, 8, 10, 12,
  114108. };
  114109. static encode_aux_threshmatch _vq_auxt__8c1_s_p9_0 = {
  114110. _vq_quantthresh__8c1_s_p9_0,
  114111. _vq_quantmap__8c1_s_p9_0,
  114112. 13,
  114113. 13
  114114. };
  114115. static static_codebook _8c1_s_p9_0 = {
  114116. 2, 169,
  114117. _vq_lengthlist__8c1_s_p9_0,
  114118. 1, -513964032, 1628680192, 4, 0,
  114119. _vq_quantlist__8c1_s_p9_0,
  114120. NULL,
  114121. &_vq_auxt__8c1_s_p9_0,
  114122. NULL,
  114123. 0
  114124. };
  114125. static long _vq_quantlist__8c1_s_p9_1[] = {
  114126. 7,
  114127. 6,
  114128. 8,
  114129. 5,
  114130. 9,
  114131. 4,
  114132. 10,
  114133. 3,
  114134. 11,
  114135. 2,
  114136. 12,
  114137. 1,
  114138. 13,
  114139. 0,
  114140. 14,
  114141. };
  114142. static long _vq_lengthlist__8c1_s_p9_1[] = {
  114143. 1, 4, 4, 5, 5, 7, 7, 9, 9,11,11,12,12,13,13, 6,
  114144. 5, 5, 6, 6, 9, 9,10,10,12,12,12,13,15,14, 6, 5,
  114145. 5, 7, 7, 9, 9,10,10,12,12,12,13,14,13,17, 7, 7,
  114146. 8, 8,10,10,11,11,12,13,13,13,13,13,17, 7, 7, 8,
  114147. 8,10,10,11,11,13,13,13,13,14,14,17,11,11, 9, 9,
  114148. 11,11,12,12,12,13,13,14,15,13,17,12,12, 9, 9,11,
  114149. 11,12,12,13,13,13,13,14,16,17,17,17,11,12,12,12,
  114150. 13,13,13,14,15,14,15,15,17,17,17,12,12,11,11,13,
  114151. 13,14,14,15,14,15,15,17,17,17,15,15,13,13,14,14,
  114152. 15,14,15,15,16,15,17,17,17,15,15,13,13,13,14,14,
  114153. 15,15,15,15,16,17,17,17,17,16,14,15,14,14,15,14,
  114154. 14,15,15,15,17,17,17,17,17,14,14,16,14,15,15,15,
  114155. 15,15,15,17,17,17,17,17,17,16,16,15,17,15,15,14,
  114156. 17,15,17,16,17,17,17,17,16,15,14,15,15,15,15,15,
  114157. 15,
  114158. };
  114159. static float _vq_quantthresh__8c1_s_p9_1[] = {
  114160. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  114161. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  114162. };
  114163. static long _vq_quantmap__8c1_s_p9_1[] = {
  114164. 13, 11, 9, 7, 5, 3, 1, 0,
  114165. 2, 4, 6, 8, 10, 12, 14,
  114166. };
  114167. static encode_aux_threshmatch _vq_auxt__8c1_s_p9_1 = {
  114168. _vq_quantthresh__8c1_s_p9_1,
  114169. _vq_quantmap__8c1_s_p9_1,
  114170. 15,
  114171. 15
  114172. };
  114173. static static_codebook _8c1_s_p9_1 = {
  114174. 2, 225,
  114175. _vq_lengthlist__8c1_s_p9_1,
  114176. 1, -520986624, 1620377600, 4, 0,
  114177. _vq_quantlist__8c1_s_p9_1,
  114178. NULL,
  114179. &_vq_auxt__8c1_s_p9_1,
  114180. NULL,
  114181. 0
  114182. };
  114183. static long _vq_quantlist__8c1_s_p9_2[] = {
  114184. 10,
  114185. 9,
  114186. 11,
  114187. 8,
  114188. 12,
  114189. 7,
  114190. 13,
  114191. 6,
  114192. 14,
  114193. 5,
  114194. 15,
  114195. 4,
  114196. 16,
  114197. 3,
  114198. 17,
  114199. 2,
  114200. 18,
  114201. 1,
  114202. 19,
  114203. 0,
  114204. 20,
  114205. };
  114206. static long _vq_lengthlist__8c1_s_p9_2[] = {
  114207. 2, 4, 4, 6, 6, 7, 7, 8, 8, 8, 8, 9, 8, 9, 9, 9,
  114208. 9, 9, 9, 9, 9,11,11,12, 7, 7, 7, 7, 8, 8, 9, 9,
  114209. 9, 9,10,10,10,10,10,10,10,10,11,11,11, 7, 7, 7,
  114210. 7, 8, 8, 9, 8, 9, 9, 9, 9, 9, 9,10,10,10,10,11,
  114211. 11,12, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9,10,10,10,10,
  114212. 10,10,10,10,11,11,11, 7, 7, 8, 8, 8, 8, 9, 9, 9,
  114213. 9,10,10,10,10,10,10,10,10,11,11,11, 8, 8, 8, 8,
  114214. 9, 9, 9, 9, 9, 9,10,10,10,10,10,10,10,10,11,11,
  114215. 11, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9,10,10,10,10,10,
  114216. 10,10,10,11,12,11, 9, 9, 8, 9, 9, 9, 9, 9,10,10,
  114217. 10,10,10,10,10,10,10,10,11,11,11,11,11, 8, 8, 9,
  114218. 9, 9, 9,10,10,10,10,10,10,10,10,10,10,11,12,11,
  114219. 12,11, 9, 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,
  114220. 10,10,11,11,11,11,11, 9, 9, 9, 9,10,10,10,10,10,
  114221. 10,10,10,10,10,10,10,12,11,12,11,11, 9, 9, 9,10,
  114222. 10,10,10,10,10,10,10,10,10,10,10,10,12,11,11,11,
  114223. 11,11,11,10,10,10,10,10,10,10,10,10,10,10,10,10,
  114224. 11,11,11,12,11,11,12,11,10,10,10,10,10,10,10,10,
  114225. 10,10,10,10,11,10,11,11,11,11,11,11,11,10,10,10,
  114226. 10,10,10,10,10,10,10,10,10,10,10,11,11,12,11,12,
  114227. 11,11,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  114228. 11,11,12,11,12,11,11,11,11,10,10,10,10,10,10,10,
  114229. 10,10,10,10,10,11,11,12,11,11,12,11,11,12,10,10,
  114230. 11,10,10,10,10,10,10,10,10,10,11,11,11,11,11,11,
  114231. 11,11,11,10,10,10,10,10,10,10,10,10,10,10,10,12,
  114232. 12,11,12,11,11,12,12,12,11,11,10,10,10,10,10,10,
  114233. 10,10,10,11,12,12,11,12,12,11,12,11,11,11,11,10,
  114234. 10,10,10,10,10,10,10,10,10,
  114235. };
  114236. static float _vq_quantthresh__8c1_s_p9_2[] = {
  114237. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  114238. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  114239. 6.5, 7.5, 8.5, 9.5,
  114240. };
  114241. static long _vq_quantmap__8c1_s_p9_2[] = {
  114242. 19, 17, 15, 13, 11, 9, 7, 5,
  114243. 3, 1, 0, 2, 4, 6, 8, 10,
  114244. 12, 14, 16, 18, 20,
  114245. };
  114246. static encode_aux_threshmatch _vq_auxt__8c1_s_p9_2 = {
  114247. _vq_quantthresh__8c1_s_p9_2,
  114248. _vq_quantmap__8c1_s_p9_2,
  114249. 21,
  114250. 21
  114251. };
  114252. static static_codebook _8c1_s_p9_2 = {
  114253. 2, 441,
  114254. _vq_lengthlist__8c1_s_p9_2,
  114255. 1, -529268736, 1611661312, 5, 0,
  114256. _vq_quantlist__8c1_s_p9_2,
  114257. NULL,
  114258. &_vq_auxt__8c1_s_p9_2,
  114259. NULL,
  114260. 0
  114261. };
  114262. static long _huff_lengthlist__8c1_s_single[] = {
  114263. 4, 6,18, 8,11, 8, 8, 9, 9,10, 4, 4,18, 5, 9, 5,
  114264. 6, 7, 8,10,18,18,18,18,17,17,17,17,17,17, 7, 5,
  114265. 17, 6,11, 6, 7, 8, 9,12,12, 9,17,12, 8, 8, 9,10,
  114266. 10,13, 7, 5,17, 6, 8, 4, 5, 6, 8,10, 6, 5,17, 6,
  114267. 8, 5, 4, 5, 7, 9, 7, 7,17, 8, 9, 6, 5, 5, 6, 8,
  114268. 8, 8,17, 9,11, 8, 6, 6, 6, 7, 9,10,17,12,12,10,
  114269. 9, 7, 7, 8,
  114270. };
  114271. static static_codebook _huff_book__8c1_s_single = {
  114272. 2, 100,
  114273. _huff_lengthlist__8c1_s_single,
  114274. 0, 0, 0, 0, 0,
  114275. NULL,
  114276. NULL,
  114277. NULL,
  114278. NULL,
  114279. 0
  114280. };
  114281. static long _huff_lengthlist__44c2_s_long[] = {
  114282. 6, 6,12,10,10,10, 9,10,12,12, 6, 1,10, 5, 6, 6,
  114283. 7, 9,11,14,12, 9, 8,11, 7, 8, 9,11,13,15,10, 5,
  114284. 12, 7, 8, 7, 9,12,14,15,10, 6, 7, 8, 5, 6, 7, 9,
  114285. 12,14, 9, 6, 8, 7, 6, 6, 7, 9,12,12, 9, 7, 9, 9,
  114286. 7, 6, 6, 7,10,10,10, 9,10,11, 8, 7, 6, 6, 8,10,
  114287. 12,11,13,13,11,10, 8, 8, 8,10,11,13,15,15,14,13,
  114288. 10, 8, 8, 9,
  114289. };
  114290. static static_codebook _huff_book__44c2_s_long = {
  114291. 2, 100,
  114292. _huff_lengthlist__44c2_s_long,
  114293. 0, 0, 0, 0, 0,
  114294. NULL,
  114295. NULL,
  114296. NULL,
  114297. NULL,
  114298. 0
  114299. };
  114300. static long _vq_quantlist__44c2_s_p1_0[] = {
  114301. 1,
  114302. 0,
  114303. 2,
  114304. };
  114305. static long _vq_lengthlist__44c2_s_p1_0[] = {
  114306. 2, 4, 4, 0, 0, 0, 0, 0, 0, 5, 6, 6, 0, 0, 0, 0,
  114307. 0, 0, 5, 6, 7, 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, 5, 7, 7, 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0, 0,
  114312. 0, 0, 0, 6, 8, 8, 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, 5, 7, 7, 0, 0, 0, 0, 0, 0, 6, 8, 7, 0, 0,
  114317. 0, 0, 0, 0, 7, 8, 8, 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, 5, 7, 7, 0, 0, 0, 0,
  114352. 0, 0, 7, 8, 8, 0, 0, 0, 0, 0, 0, 7, 8, 8, 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, 7, 8, 8, 0, 0, 0,
  114357. 0, 0, 0, 8, 9, 9, 0, 0, 0, 0, 0, 0, 8, 9, 9, 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, 6, 8, 8, 0, 0,
  114362. 0, 0, 0, 0, 8, 9, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9,
  114363. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114364. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114365. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114366. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114367. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114368. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114369. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114370. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114371. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114372. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114373. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114374. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114375. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114376. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114377. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114378. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114379. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114380. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114381. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114382. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114383. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114384. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114385. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114386. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114387. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114388. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114389. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114390. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114391. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114392. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114393. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114394. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114395. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114396. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114397. 0, 0, 4, 7, 7, 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0,
  114398. 0, 0, 0, 0, 7, 8, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114399. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114400. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114401. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114402. 0, 0, 0, 6, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0,
  114403. 0, 0, 0, 0, 0, 8, 8, 9, 0, 0, 0, 0, 0, 0, 0, 0,
  114404. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114405. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114406. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114407. 0, 0, 0, 0, 7, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9,
  114408. 0, 0, 0, 0, 0, 0, 8, 9, 9, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114414. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114415. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114416. 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114422. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114423. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114430. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114431. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114444. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114445. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114446. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114447. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114448. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114449. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114450. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114451. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114452. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114453. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114454. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114455. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114456. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114457. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114458. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114459. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114460. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114461. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114462. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114463. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114464. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114465. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114466. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114467. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114468. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114469. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114470. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114471. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114472. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114473. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114474. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114475. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114476. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114477. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114478. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114479. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114480. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114481. 0, 0, 0, 0, 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114515. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114516. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114517. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114518. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114519. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114520. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114521. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114522. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114523. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114524. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114525. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114526. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114527. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114528. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114529. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114530. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114531. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114532. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114533. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114534. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114535. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114536. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114537. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114538. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114539. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114540. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114541. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114542. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114543. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114544. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114545. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114546. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114547. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114548. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114549. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114550. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114551. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114552. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114553. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114554. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114555. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114556. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114557. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114558. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114559. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114560. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114561. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114562. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114563. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114564. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114565. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114566. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114567. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114568. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114569. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114570. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114571. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114572. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114573. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114574. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114575. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114576. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114577. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114578. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114579. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114580. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114581. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114582. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114583. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114584. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114585. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114586. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114587. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114588. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114589. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114590. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114591. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114592. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114593. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114594. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114595. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114596. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114597. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114598. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114599. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114600. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114601. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114602. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114603. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114604. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114605. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114606. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114607. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114608. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114609. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114610. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114611. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114612. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114613. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114614. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114615. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114616. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114617. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114618. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114619. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114620. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114621. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114622. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114623. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114624. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114625. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114626. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114627. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114628. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114629. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114630. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114631. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114632. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114633. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114634. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114635. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114636. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114637. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114638. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114639. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114640. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114641. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114642. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114643. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114644. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114645. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114646. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114647. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114648. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114649. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114650. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114651. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114652. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114653. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114654. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114655. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114656. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114657. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114658. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114659. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114660. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114661. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114662. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114663. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114664. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114665. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114666. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114667. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114668. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114669. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114670. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114671. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114672. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114673. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114674. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114675. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114676. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114677. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114678. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114679. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114680. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114681. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114682. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114683. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114684. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114685. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114686. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114687. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114688. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114689. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114690. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114691. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114692. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114693. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114694. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114695. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114696. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114697. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114698. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114699. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114700. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114701. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114702. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114703. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114704. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114705. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114706. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114707. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114708. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114709. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114710. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114711. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114712. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114713. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114714. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114715. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114716. 0,
  114717. };
  114718. static float _vq_quantthresh__44c2_s_p1_0[] = {
  114719. -0.5, 0.5,
  114720. };
  114721. static long _vq_quantmap__44c2_s_p1_0[] = {
  114722. 1, 0, 2,
  114723. };
  114724. static encode_aux_threshmatch _vq_auxt__44c2_s_p1_0 = {
  114725. _vq_quantthresh__44c2_s_p1_0,
  114726. _vq_quantmap__44c2_s_p1_0,
  114727. 3,
  114728. 3
  114729. };
  114730. static static_codebook _44c2_s_p1_0 = {
  114731. 8, 6561,
  114732. _vq_lengthlist__44c2_s_p1_0,
  114733. 1, -535822336, 1611661312, 2, 0,
  114734. _vq_quantlist__44c2_s_p1_0,
  114735. NULL,
  114736. &_vq_auxt__44c2_s_p1_0,
  114737. NULL,
  114738. 0
  114739. };
  114740. static long _vq_quantlist__44c2_s_p2_0[] = {
  114741. 2,
  114742. 1,
  114743. 3,
  114744. 0,
  114745. 4,
  114746. };
  114747. static long _vq_lengthlist__44c2_s_p2_0[] = {
  114748. 1, 4, 4, 0, 0, 0, 7, 7, 0, 0, 0, 7, 7, 0, 0, 0,
  114749. 8, 8, 0, 0, 0, 0, 0, 0, 0, 4, 6, 6, 0, 0, 0, 8,
  114750. 8, 0, 0, 0, 8, 8, 0, 0, 0, 9, 9, 0, 0, 0, 0, 0,
  114751. 0, 0, 4, 6, 6, 0, 0, 0, 8, 8, 0, 0, 0, 8, 8, 0,
  114752. 0, 0, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114753. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114754. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114755. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114756. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114757. 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0, 0,11,11, 0, 0,
  114758. 0,11,11, 0, 0, 0,12,11, 0, 0, 0, 0, 0, 0, 0, 7,
  114759. 8, 8, 0, 0, 0,10,11, 0, 0, 0,11,11, 0, 0, 0,11,
  114760. 12, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114761. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114762. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114763. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114764. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114765. 0, 0, 0, 6, 8, 8, 0, 0, 0,11,11, 0, 0, 0,11,11,
  114766. 0, 0, 0,12,12, 0, 0, 0, 0, 0, 0, 0, 6, 8, 8, 0,
  114767. 0, 0,10,11, 0, 0, 0,10,11, 0, 0, 0,11,11, 0, 0,
  114768. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114769. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114770. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114771. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114772. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114773. 8, 9, 9, 0, 0, 0,11,12, 0, 0, 0,11,12, 0, 0, 0,
  114774. 12,11, 0, 0, 0, 0, 0, 0, 0, 8,10, 9, 0, 0, 0,12,
  114775. 11, 0, 0, 0,12,11, 0, 0, 0,11,12, 0, 0, 0, 0, 0,
  114776. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114777. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114778. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114779. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114780. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114781. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114782. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114783. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114784. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114785. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114786. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114787. 0,
  114788. };
  114789. static float _vq_quantthresh__44c2_s_p2_0[] = {
  114790. -1.5, -0.5, 0.5, 1.5,
  114791. };
  114792. static long _vq_quantmap__44c2_s_p2_0[] = {
  114793. 3, 1, 0, 2, 4,
  114794. };
  114795. static encode_aux_threshmatch _vq_auxt__44c2_s_p2_0 = {
  114796. _vq_quantthresh__44c2_s_p2_0,
  114797. _vq_quantmap__44c2_s_p2_0,
  114798. 5,
  114799. 5
  114800. };
  114801. static static_codebook _44c2_s_p2_0 = {
  114802. 4, 625,
  114803. _vq_lengthlist__44c2_s_p2_0,
  114804. 1, -533725184, 1611661312, 3, 0,
  114805. _vq_quantlist__44c2_s_p2_0,
  114806. NULL,
  114807. &_vq_auxt__44c2_s_p2_0,
  114808. NULL,
  114809. 0
  114810. };
  114811. static long _vq_quantlist__44c2_s_p3_0[] = {
  114812. 2,
  114813. 1,
  114814. 3,
  114815. 0,
  114816. 4,
  114817. };
  114818. static long _vq_lengthlist__44c2_s_p3_0[] = {
  114819. 2, 4, 3, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114820. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 4, 4, 6, 6, 0, 0,
  114821. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114822. 0, 0, 4, 4, 4, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114823. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 6, 6, 9, 9,
  114824. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114825. 0, 0, 0, 0, 6, 6, 7, 9, 9, 0, 0, 0, 0, 0, 0, 0,
  114826. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114827. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114828. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114829. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114830. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114831. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114832. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114833. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114834. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114835. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114836. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114837. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114838. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114839. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114840. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114841. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114842. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114843. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114844. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114845. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114846. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114847. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114848. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114849. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114850. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114851. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114852. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114853. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114854. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114855. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114856. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114857. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114858. 0,
  114859. };
  114860. static float _vq_quantthresh__44c2_s_p3_0[] = {
  114861. -1.5, -0.5, 0.5, 1.5,
  114862. };
  114863. static long _vq_quantmap__44c2_s_p3_0[] = {
  114864. 3, 1, 0, 2, 4,
  114865. };
  114866. static encode_aux_threshmatch _vq_auxt__44c2_s_p3_0 = {
  114867. _vq_quantthresh__44c2_s_p3_0,
  114868. _vq_quantmap__44c2_s_p3_0,
  114869. 5,
  114870. 5
  114871. };
  114872. static static_codebook _44c2_s_p3_0 = {
  114873. 4, 625,
  114874. _vq_lengthlist__44c2_s_p3_0,
  114875. 1, -533725184, 1611661312, 3, 0,
  114876. _vq_quantlist__44c2_s_p3_0,
  114877. NULL,
  114878. &_vq_auxt__44c2_s_p3_0,
  114879. NULL,
  114880. 0
  114881. };
  114882. static long _vq_quantlist__44c2_s_p4_0[] = {
  114883. 4,
  114884. 3,
  114885. 5,
  114886. 2,
  114887. 6,
  114888. 1,
  114889. 7,
  114890. 0,
  114891. 8,
  114892. };
  114893. static long _vq_lengthlist__44c2_s_p4_0[] = {
  114894. 1, 3, 3, 6, 6, 0, 0, 0, 0, 0, 6, 6, 6, 6, 0, 0,
  114895. 0, 0, 0, 6, 6, 6, 6, 0, 0, 0, 0, 0, 7, 7, 6, 6,
  114896. 0, 0, 0, 0, 0, 0, 0, 6, 7, 0, 0, 0, 0, 0, 0, 0,
  114897. 7, 8, 0, 0, 0, 0, 0, 0, 0, 8, 8, 0, 0, 0, 0, 0,
  114898. 0, 0, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114899. 0,
  114900. };
  114901. static float _vq_quantthresh__44c2_s_p4_0[] = {
  114902. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  114903. };
  114904. static long _vq_quantmap__44c2_s_p4_0[] = {
  114905. 7, 5, 3, 1, 0, 2, 4, 6,
  114906. 8,
  114907. };
  114908. static encode_aux_threshmatch _vq_auxt__44c2_s_p4_0 = {
  114909. _vq_quantthresh__44c2_s_p4_0,
  114910. _vq_quantmap__44c2_s_p4_0,
  114911. 9,
  114912. 9
  114913. };
  114914. static static_codebook _44c2_s_p4_0 = {
  114915. 2, 81,
  114916. _vq_lengthlist__44c2_s_p4_0,
  114917. 1, -531628032, 1611661312, 4, 0,
  114918. _vq_quantlist__44c2_s_p4_0,
  114919. NULL,
  114920. &_vq_auxt__44c2_s_p4_0,
  114921. NULL,
  114922. 0
  114923. };
  114924. static long _vq_quantlist__44c2_s_p5_0[] = {
  114925. 4,
  114926. 3,
  114927. 5,
  114928. 2,
  114929. 6,
  114930. 1,
  114931. 7,
  114932. 0,
  114933. 8,
  114934. };
  114935. static long _vq_lengthlist__44c2_s_p5_0[] = {
  114936. 1, 3, 3, 6, 6, 7, 7, 9, 9, 0, 7, 7, 7, 7, 7, 7,
  114937. 9, 9, 0, 7, 7, 7, 7, 7, 7, 9, 9, 0, 8, 8, 7, 7,
  114938. 8, 8,10,10, 0, 0, 0, 7, 7, 8, 8,10,10, 0, 0, 0,
  114939. 9, 9, 8, 8,10,10, 0, 0, 0, 9, 9, 8, 8,10,10, 0,
  114940. 0, 0,10,10, 9, 9,11,11, 0, 0, 0, 0, 0, 9, 9,11,
  114941. 11,
  114942. };
  114943. static float _vq_quantthresh__44c2_s_p5_0[] = {
  114944. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  114945. };
  114946. static long _vq_quantmap__44c2_s_p5_0[] = {
  114947. 7, 5, 3, 1, 0, 2, 4, 6,
  114948. 8,
  114949. };
  114950. static encode_aux_threshmatch _vq_auxt__44c2_s_p5_0 = {
  114951. _vq_quantthresh__44c2_s_p5_0,
  114952. _vq_quantmap__44c2_s_p5_0,
  114953. 9,
  114954. 9
  114955. };
  114956. static static_codebook _44c2_s_p5_0 = {
  114957. 2, 81,
  114958. _vq_lengthlist__44c2_s_p5_0,
  114959. 1, -531628032, 1611661312, 4, 0,
  114960. _vq_quantlist__44c2_s_p5_0,
  114961. NULL,
  114962. &_vq_auxt__44c2_s_p5_0,
  114963. NULL,
  114964. 0
  114965. };
  114966. static long _vq_quantlist__44c2_s_p6_0[] = {
  114967. 8,
  114968. 7,
  114969. 9,
  114970. 6,
  114971. 10,
  114972. 5,
  114973. 11,
  114974. 4,
  114975. 12,
  114976. 3,
  114977. 13,
  114978. 2,
  114979. 14,
  114980. 1,
  114981. 15,
  114982. 0,
  114983. 16,
  114984. };
  114985. static long _vq_lengthlist__44c2_s_p6_0[] = {
  114986. 1, 4, 3, 6, 6, 8, 8, 9, 9, 9, 9, 9, 9,10,10,11,
  114987. 11, 0, 7, 7, 7, 7, 8, 8, 9, 9, 9, 9,10,10,11,11,
  114988. 12,11, 0, 7, 7, 7, 7, 8, 8, 9, 9, 9, 9,10,10,11,
  114989. 11,11,12, 0, 8, 8, 7, 7, 9, 9,10,10, 9, 9,10,10,
  114990. 11,11,12,12, 0, 0, 0, 7, 7, 9, 9,10,10,10, 9,10,
  114991. 10,11,11,12,12, 0, 0, 0, 8, 8, 9, 9,10,10,10,10,
  114992. 11,11,11,11,12,12, 0, 0, 0, 8, 8, 9, 9,10,10,10,
  114993. 10,11,11,12,12,12,12, 0, 0, 0, 9, 9, 9, 9,10,10,
  114994. 10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 9, 9,10,
  114995. 10,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9, 9,
  114996. 10,10,11,11,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9,
  114997. 9,10,10,11,11,11,11,12,12,13,13, 0, 0, 0, 0, 0,
  114998. 10,10,10,10,11,11,12,12,13,12,13,13, 0, 0, 0, 0,
  114999. 0, 0, 0,10,10,11,11,12,12,13,13,13,13, 0, 0, 0,
  115000. 0, 0, 0, 0,11,11,12,12,12,12,13,13,13,14, 0, 0,
  115001. 0, 0, 0, 0, 0,11,11,12,12,12,12,13,13,13,14, 0,
  115002. 0, 0, 0, 0, 0, 0,12,12,12,12,13,13,13,13,14,14,
  115003. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,13,13,13,13,14,
  115004. 14,
  115005. };
  115006. static float _vq_quantthresh__44c2_s_p6_0[] = {
  115007. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  115008. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  115009. };
  115010. static long _vq_quantmap__44c2_s_p6_0[] = {
  115011. 15, 13, 11, 9, 7, 5, 3, 1,
  115012. 0, 2, 4, 6, 8, 10, 12, 14,
  115013. 16,
  115014. };
  115015. static encode_aux_threshmatch _vq_auxt__44c2_s_p6_0 = {
  115016. _vq_quantthresh__44c2_s_p6_0,
  115017. _vq_quantmap__44c2_s_p6_0,
  115018. 17,
  115019. 17
  115020. };
  115021. static static_codebook _44c2_s_p6_0 = {
  115022. 2, 289,
  115023. _vq_lengthlist__44c2_s_p6_0,
  115024. 1, -529530880, 1611661312, 5, 0,
  115025. _vq_quantlist__44c2_s_p6_0,
  115026. NULL,
  115027. &_vq_auxt__44c2_s_p6_0,
  115028. NULL,
  115029. 0
  115030. };
  115031. static long _vq_quantlist__44c2_s_p7_0[] = {
  115032. 1,
  115033. 0,
  115034. 2,
  115035. };
  115036. static long _vq_lengthlist__44c2_s_p7_0[] = {
  115037. 1, 4, 4, 7, 6, 6, 7, 6, 6, 4, 7, 7,10, 9, 9,11,
  115038. 9, 9, 4, 7, 7,10, 9, 9,10, 9, 9, 7,10,10,11,10,
  115039. 11,11,10,11, 6, 9, 9,11,10,10,11,10,10, 6, 9, 9,
  115040. 11,10,11,11,10,10, 7,11,10,11,11,11,12,11,11, 6,
  115041. 9, 9,11,10,10,11,11,10, 6, 9, 9,11,10,10,12,10,
  115042. 11,
  115043. };
  115044. static float _vq_quantthresh__44c2_s_p7_0[] = {
  115045. -5.5, 5.5,
  115046. };
  115047. static long _vq_quantmap__44c2_s_p7_0[] = {
  115048. 1, 0, 2,
  115049. };
  115050. static encode_aux_threshmatch _vq_auxt__44c2_s_p7_0 = {
  115051. _vq_quantthresh__44c2_s_p7_0,
  115052. _vq_quantmap__44c2_s_p7_0,
  115053. 3,
  115054. 3
  115055. };
  115056. static static_codebook _44c2_s_p7_0 = {
  115057. 4, 81,
  115058. _vq_lengthlist__44c2_s_p7_0,
  115059. 1, -529137664, 1618345984, 2, 0,
  115060. _vq_quantlist__44c2_s_p7_0,
  115061. NULL,
  115062. &_vq_auxt__44c2_s_p7_0,
  115063. NULL,
  115064. 0
  115065. };
  115066. static long _vq_quantlist__44c2_s_p7_1[] = {
  115067. 5,
  115068. 4,
  115069. 6,
  115070. 3,
  115071. 7,
  115072. 2,
  115073. 8,
  115074. 1,
  115075. 9,
  115076. 0,
  115077. 10,
  115078. };
  115079. static long _vq_lengthlist__44c2_s_p7_1[] = {
  115080. 2, 3, 4, 6, 6, 7, 7, 7, 7, 7, 7, 9, 7, 7, 6, 6,
  115081. 7, 7, 8, 8, 8, 8, 9, 6, 6, 6, 6, 7, 7, 8, 8, 8,
  115082. 8,10, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8,10,10,10, 7,
  115083. 7, 7, 7, 8, 8, 8, 8,10,10,10, 7, 7, 8, 8, 8, 8,
  115084. 8, 8,10,10,10, 7, 8, 8, 8, 8, 8, 8, 8,10,10,10,
  115085. 8, 8, 8, 8, 8, 8, 8, 8,10,10,10,10,10, 8, 8, 8,
  115086. 8, 8, 8,10,10,10,10,10, 9, 9, 8, 8, 8, 8,10,10,
  115087. 10,10,10, 8, 8, 8, 8, 8, 8,
  115088. };
  115089. static float _vq_quantthresh__44c2_s_p7_1[] = {
  115090. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  115091. 3.5, 4.5,
  115092. };
  115093. static long _vq_quantmap__44c2_s_p7_1[] = {
  115094. 9, 7, 5, 3, 1, 0, 2, 4,
  115095. 6, 8, 10,
  115096. };
  115097. static encode_aux_threshmatch _vq_auxt__44c2_s_p7_1 = {
  115098. _vq_quantthresh__44c2_s_p7_1,
  115099. _vq_quantmap__44c2_s_p7_1,
  115100. 11,
  115101. 11
  115102. };
  115103. static static_codebook _44c2_s_p7_1 = {
  115104. 2, 121,
  115105. _vq_lengthlist__44c2_s_p7_1,
  115106. 1, -531365888, 1611661312, 4, 0,
  115107. _vq_quantlist__44c2_s_p7_1,
  115108. NULL,
  115109. &_vq_auxt__44c2_s_p7_1,
  115110. NULL,
  115111. 0
  115112. };
  115113. static long _vq_quantlist__44c2_s_p8_0[] = {
  115114. 6,
  115115. 5,
  115116. 7,
  115117. 4,
  115118. 8,
  115119. 3,
  115120. 9,
  115121. 2,
  115122. 10,
  115123. 1,
  115124. 11,
  115125. 0,
  115126. 12,
  115127. };
  115128. static long _vq_lengthlist__44c2_s_p8_0[] = {
  115129. 1, 4, 4, 6, 6, 7, 7, 7, 7, 8, 8, 9, 9, 6, 5, 5,
  115130. 7, 7, 8, 8, 8, 8, 9, 9,10,10, 7, 6, 5, 7, 7, 8,
  115131. 8, 8, 8, 9, 9,10,10, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  115132. 10,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,
  115133. 11, 0,12,12, 9, 9,10,10,10,10,11,11,11,11, 0,13,
  115134. 13, 9, 9,10,10,10,10,11,11,12,12, 0, 0, 0,10,10,
  115135. 10,10,11,11,12,12,12,13, 0, 0, 0,10,10,10,10,11,
  115136. 11,12,12,12,12, 0, 0, 0,14,14,10,11,11,11,12,12,
  115137. 13,13, 0, 0, 0,14,14,11,10,11,11,13,12,13,13, 0,
  115138. 0, 0, 0, 0,12,12,11,12,13,12,14,14, 0, 0, 0, 0,
  115139. 0,12,12,12,12,13,12,14,14,
  115140. };
  115141. static float _vq_quantthresh__44c2_s_p8_0[] = {
  115142. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  115143. 12.5, 17.5, 22.5, 27.5,
  115144. };
  115145. static long _vq_quantmap__44c2_s_p8_0[] = {
  115146. 11, 9, 7, 5, 3, 1, 0, 2,
  115147. 4, 6, 8, 10, 12,
  115148. };
  115149. static encode_aux_threshmatch _vq_auxt__44c2_s_p8_0 = {
  115150. _vq_quantthresh__44c2_s_p8_0,
  115151. _vq_quantmap__44c2_s_p8_0,
  115152. 13,
  115153. 13
  115154. };
  115155. static static_codebook _44c2_s_p8_0 = {
  115156. 2, 169,
  115157. _vq_lengthlist__44c2_s_p8_0,
  115158. 1, -526516224, 1616117760, 4, 0,
  115159. _vq_quantlist__44c2_s_p8_0,
  115160. NULL,
  115161. &_vq_auxt__44c2_s_p8_0,
  115162. NULL,
  115163. 0
  115164. };
  115165. static long _vq_quantlist__44c2_s_p8_1[] = {
  115166. 2,
  115167. 1,
  115168. 3,
  115169. 0,
  115170. 4,
  115171. };
  115172. static long _vq_lengthlist__44c2_s_p8_1[] = {
  115173. 2, 4, 4, 5, 4, 6, 5, 5, 5, 5, 6, 5, 5, 5, 5, 6,
  115174. 5, 5, 5, 5, 6, 6, 6, 5, 5,
  115175. };
  115176. static float _vq_quantthresh__44c2_s_p8_1[] = {
  115177. -1.5, -0.5, 0.5, 1.5,
  115178. };
  115179. static long _vq_quantmap__44c2_s_p8_1[] = {
  115180. 3, 1, 0, 2, 4,
  115181. };
  115182. static encode_aux_threshmatch _vq_auxt__44c2_s_p8_1 = {
  115183. _vq_quantthresh__44c2_s_p8_1,
  115184. _vq_quantmap__44c2_s_p8_1,
  115185. 5,
  115186. 5
  115187. };
  115188. static static_codebook _44c2_s_p8_1 = {
  115189. 2, 25,
  115190. _vq_lengthlist__44c2_s_p8_1,
  115191. 1, -533725184, 1611661312, 3, 0,
  115192. _vq_quantlist__44c2_s_p8_1,
  115193. NULL,
  115194. &_vq_auxt__44c2_s_p8_1,
  115195. NULL,
  115196. 0
  115197. };
  115198. static long _vq_quantlist__44c2_s_p9_0[] = {
  115199. 6,
  115200. 5,
  115201. 7,
  115202. 4,
  115203. 8,
  115204. 3,
  115205. 9,
  115206. 2,
  115207. 10,
  115208. 1,
  115209. 11,
  115210. 0,
  115211. 12,
  115212. };
  115213. static long _vq_lengthlist__44c2_s_p9_0[] = {
  115214. 1, 5, 4,12,12,12,12,12,12,12,12,12,12, 4, 9, 8,
  115215. 11,11,11,11,11,11,11,11,11,11, 2, 8, 7,11,11,11,
  115216. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  115217. 11,11,11,11,11,11,10,11,11,11,11,11,11,11,11,11,
  115218. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  115219. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  115220. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  115221. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  115222. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  115223. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  115224. 11,11,11,11,11,11,11,11,11,
  115225. };
  115226. static float _vq_quantthresh__44c2_s_p9_0[] = {
  115227. -1215.5, -994.5, -773.5, -552.5, -331.5, -110.5, 110.5, 331.5,
  115228. 552.5, 773.5, 994.5, 1215.5,
  115229. };
  115230. static long _vq_quantmap__44c2_s_p9_0[] = {
  115231. 11, 9, 7, 5, 3, 1, 0, 2,
  115232. 4, 6, 8, 10, 12,
  115233. };
  115234. static encode_aux_threshmatch _vq_auxt__44c2_s_p9_0 = {
  115235. _vq_quantthresh__44c2_s_p9_0,
  115236. _vq_quantmap__44c2_s_p9_0,
  115237. 13,
  115238. 13
  115239. };
  115240. static static_codebook _44c2_s_p9_0 = {
  115241. 2, 169,
  115242. _vq_lengthlist__44c2_s_p9_0,
  115243. 1, -514541568, 1627103232, 4, 0,
  115244. _vq_quantlist__44c2_s_p9_0,
  115245. NULL,
  115246. &_vq_auxt__44c2_s_p9_0,
  115247. NULL,
  115248. 0
  115249. };
  115250. static long _vq_quantlist__44c2_s_p9_1[] = {
  115251. 6,
  115252. 5,
  115253. 7,
  115254. 4,
  115255. 8,
  115256. 3,
  115257. 9,
  115258. 2,
  115259. 10,
  115260. 1,
  115261. 11,
  115262. 0,
  115263. 12,
  115264. };
  115265. static long _vq_lengthlist__44c2_s_p9_1[] = {
  115266. 1, 4, 4, 6, 6, 7, 6, 8, 8,10, 9,10,10, 6, 5, 5,
  115267. 7, 7, 8, 7,10, 9,11,11,12,13, 6, 5, 5, 7, 7, 8,
  115268. 8,10,10,11,11,13,13,18, 8, 8, 8, 8, 9, 9,10,10,
  115269. 12,12,12,13,18, 8, 8, 8, 8, 9, 9,10,10,12,12,13,
  115270. 13,18,11,11, 8, 8,10,10,11,11,12,11,13,12,18,11,
  115271. 11, 9, 7,10,10,11,11,11,12,12,13,17,17,17,10,10,
  115272. 11,11,12,12,12,10,12,12,17,17,17,11,10,11,10,13,
  115273. 12,11,12,12,12,17,17,17,15,14,11,11,12,11,13,10,
  115274. 13,12,17,17,17,14,14,12,10,11,11,13,13,13,13,17,
  115275. 17,16,17,16,13,13,12,10,13,10,14,13,17,16,17,16,
  115276. 17,13,12,12,10,13,11,14,14,
  115277. };
  115278. static float _vq_quantthresh__44c2_s_p9_1[] = {
  115279. -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5, 25.5,
  115280. 42.5, 59.5, 76.5, 93.5,
  115281. };
  115282. static long _vq_quantmap__44c2_s_p9_1[] = {
  115283. 11, 9, 7, 5, 3, 1, 0, 2,
  115284. 4, 6, 8, 10, 12,
  115285. };
  115286. static encode_aux_threshmatch _vq_auxt__44c2_s_p9_1 = {
  115287. _vq_quantthresh__44c2_s_p9_1,
  115288. _vq_quantmap__44c2_s_p9_1,
  115289. 13,
  115290. 13
  115291. };
  115292. static static_codebook _44c2_s_p9_1 = {
  115293. 2, 169,
  115294. _vq_lengthlist__44c2_s_p9_1,
  115295. 1, -522616832, 1620115456, 4, 0,
  115296. _vq_quantlist__44c2_s_p9_1,
  115297. NULL,
  115298. &_vq_auxt__44c2_s_p9_1,
  115299. NULL,
  115300. 0
  115301. };
  115302. static long _vq_quantlist__44c2_s_p9_2[] = {
  115303. 8,
  115304. 7,
  115305. 9,
  115306. 6,
  115307. 10,
  115308. 5,
  115309. 11,
  115310. 4,
  115311. 12,
  115312. 3,
  115313. 13,
  115314. 2,
  115315. 14,
  115316. 1,
  115317. 15,
  115318. 0,
  115319. 16,
  115320. };
  115321. static long _vq_lengthlist__44c2_s_p9_2[] = {
  115322. 2, 4, 4, 6, 6, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8,
  115323. 8,10, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9,
  115324. 9, 9,10, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 9, 9, 9,
  115325. 9, 9, 9,10, 8, 8, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9,
  115326. 9, 9, 9, 9,10,10,10, 8, 7, 8, 8, 8, 8, 9, 9, 9,
  115327. 9, 9, 9, 9, 9,10,11,11, 8, 8, 8, 8, 9, 9, 9, 9,
  115328. 9, 9,10, 9, 9, 9,10,11,10, 8, 8, 8, 8, 9, 9, 9,
  115329. 9, 9, 9, 9,10,10,10,10,11,10, 8, 8, 9, 9, 9, 9,
  115330. 9, 9,10, 9, 9,10, 9,10,11,10,11,11,11, 8, 8, 9,
  115331. 9, 9, 9, 9, 9, 9, 9,10,10,11,11,11,11,11, 9, 9,
  115332. 9, 9, 9, 9,10, 9, 9, 9,10,10,11,11,11,11,11, 9,
  115333. 9, 9, 9, 9, 9, 9, 9, 9,10, 9,10,11,11,11,11,11,
  115334. 9, 9, 9, 9,10,10, 9, 9, 9,10,10,10,11,11,11,11,
  115335. 11,11,11, 9, 9, 9,10, 9, 9,10,10,10,10,11,11,10,
  115336. 11,11,11,11,10, 9,10,10, 9, 9, 9, 9,10,10,11,10,
  115337. 11,11,11,11,11, 9, 9, 9, 9,10, 9,10,10,10,10,11,
  115338. 10,11,11,11,11,11,10,10, 9, 9,10, 9,10,10,10,10,
  115339. 10,10,10,11,11,11,11,11,11, 9, 9,10, 9,10, 9,10,
  115340. 10,
  115341. };
  115342. static float _vq_quantthresh__44c2_s_p9_2[] = {
  115343. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  115344. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  115345. };
  115346. static long _vq_quantmap__44c2_s_p9_2[] = {
  115347. 15, 13, 11, 9, 7, 5, 3, 1,
  115348. 0, 2, 4, 6, 8, 10, 12, 14,
  115349. 16,
  115350. };
  115351. static encode_aux_threshmatch _vq_auxt__44c2_s_p9_2 = {
  115352. _vq_quantthresh__44c2_s_p9_2,
  115353. _vq_quantmap__44c2_s_p9_2,
  115354. 17,
  115355. 17
  115356. };
  115357. static static_codebook _44c2_s_p9_2 = {
  115358. 2, 289,
  115359. _vq_lengthlist__44c2_s_p9_2,
  115360. 1, -529530880, 1611661312, 5, 0,
  115361. _vq_quantlist__44c2_s_p9_2,
  115362. NULL,
  115363. &_vq_auxt__44c2_s_p9_2,
  115364. NULL,
  115365. 0
  115366. };
  115367. static long _huff_lengthlist__44c2_s_short[] = {
  115368. 11, 9,13,12,12,11,12,12,13,15, 8, 2,11, 4, 8, 5,
  115369. 7,10,12,15,13, 7,10, 9, 8, 8,10,13,17,17,11, 4,
  115370. 12, 5, 9, 5, 8,11,14,16,12, 6, 8, 7, 6, 6, 8,11,
  115371. 13,16,11, 4, 9, 5, 6, 4, 6,10,13,16,11, 6,11, 7,
  115372. 7, 6, 7,10,13,15,13, 9,12, 9, 8, 6, 8,10,12,14,
  115373. 14,10,10, 8, 6, 5, 6, 9,11,13,15,11,11, 9, 6, 5,
  115374. 6, 8, 9,12,
  115375. };
  115376. static static_codebook _huff_book__44c2_s_short = {
  115377. 2, 100,
  115378. _huff_lengthlist__44c2_s_short,
  115379. 0, 0, 0, 0, 0,
  115380. NULL,
  115381. NULL,
  115382. NULL,
  115383. NULL,
  115384. 0
  115385. };
  115386. static long _huff_lengthlist__44c3_s_long[] = {
  115387. 5, 6,11,11,11,11,10,10,12,11, 5, 2,11, 5, 6, 6,
  115388. 7, 9,11,13,13,10, 7,11, 6, 7, 8, 9,10,12,11, 5,
  115389. 11, 6, 8, 7, 9,11,14,15,11, 6, 6, 8, 4, 5, 7, 8,
  115390. 10,13,10, 5, 7, 7, 5, 5, 6, 8,10,11,10, 7, 7, 8,
  115391. 6, 5, 5, 7, 9, 9,11, 8, 8,11, 8, 7, 6, 6, 7, 9,
  115392. 12,11,10,13, 9, 9, 7, 7, 7, 9,11,13,12,15,12,11,
  115393. 9, 8, 8, 8,
  115394. };
  115395. static static_codebook _huff_book__44c3_s_long = {
  115396. 2, 100,
  115397. _huff_lengthlist__44c3_s_long,
  115398. 0, 0, 0, 0, 0,
  115399. NULL,
  115400. NULL,
  115401. NULL,
  115402. NULL,
  115403. 0
  115404. };
  115405. static long _vq_quantlist__44c3_s_p1_0[] = {
  115406. 1,
  115407. 0,
  115408. 2,
  115409. };
  115410. static long _vq_lengthlist__44c3_s_p1_0[] = {
  115411. 2, 4, 4, 0, 0, 0, 0, 0, 0, 5, 6, 6, 0, 0, 0, 0,
  115412. 0, 0, 5, 6, 6, 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, 5, 7, 7, 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0, 0,
  115417. 0, 0, 0, 6, 7, 8, 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, 5, 7, 7, 0, 0, 0, 0, 0, 0, 6, 8, 7, 0, 0,
  115422. 0, 0, 0, 0, 7, 8, 8, 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, 5, 7, 7, 0, 0, 0, 0,
  115457. 0, 0, 7, 8, 8, 0, 0, 0, 0, 0, 0, 7, 8, 8, 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, 7, 8, 8, 0, 0, 0,
  115462. 0, 0, 0, 8, 8, 9, 0, 0, 0, 0, 0, 0, 8, 9, 9, 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, 6, 8, 8, 0, 0,
  115467. 0, 0, 0, 0, 7, 9, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9,
  115468. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115469. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115470. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115471. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115472. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115473. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115474. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115475. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115476. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115477. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115478. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115479. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115480. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115481. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115482. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115483. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115484. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115485. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115486. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115487. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115488. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115489. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115490. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115491. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115492. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115493. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115494. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115495. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115496. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115497. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115498. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115499. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115500. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115501. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115502. 0, 0, 5, 7, 7, 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0,
  115503. 0, 0, 0, 0, 7, 8, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115504. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115505. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115506. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115507. 0, 0, 0, 6, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0,
  115508. 0, 0, 0, 0, 0, 7, 8, 9, 0, 0, 0, 0, 0, 0, 0, 0,
  115509. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115510. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115511. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115512. 0, 0, 0, 0, 6, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9,
  115513. 0, 0, 0, 0, 0, 0, 8, 9, 8, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115519. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115520. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115521. 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115527. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115528. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115535. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115536. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115549. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115550. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115551. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115552. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115553. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115554. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115555. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115556. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115557. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115558. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115559. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115560. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115561. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115562. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115563. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115564. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115565. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115566. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115567. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115568. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115569. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115570. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115571. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115572. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115573. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115574. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115575. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115576. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115577. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115578. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115579. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115580. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115581. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115582. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115583. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115584. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115585. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115586. 0, 0, 0, 0, 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115620. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115621. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115622. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115623. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115624. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115625. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115626. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115627. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115628. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115629. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115630. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115631. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115632. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115633. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115634. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115635. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115636. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115637. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115638. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115639. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115640. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115641. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115642. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115643. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115644. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115645. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115646. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115647. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115648. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115649. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115650. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115651. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115652. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115653. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115654. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115655. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115656. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115657. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115658. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115659. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115660. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115661. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115662. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115663. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115664. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115665. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115666. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115667. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115668. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115669. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115670. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115671. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115672. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115673. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115674. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115675. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115676. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115677. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115678. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115679. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115680. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115681. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115682. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115683. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115684. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115685. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115686. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115687. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115688. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115689. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115690. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115691. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115692. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115693. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115694. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115695. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115696. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115697. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115698. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115699. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115700. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115701. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115702. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115703. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115704. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115705. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115706. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115707. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115708. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115709. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115710. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115711. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115712. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115713. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115714. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115715. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115716. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115717. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115718. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115719. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115720. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115721. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115722. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115723. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115724. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115725. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115726. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115727. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115728. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115729. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115730. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115731. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115732. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115733. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115734. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115735. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115736. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115737. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115738. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115739. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115740. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115741. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115742. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115743. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115744. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115745. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115746. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115747. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115748. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115749. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115750. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115751. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115752. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115753. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115754. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115755. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115756. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115757. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115758. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115759. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115760. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115761. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115762. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115763. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115764. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115765. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115766. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115767. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115768. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115769. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115770. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115771. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115772. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115773. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115774. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115775. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115776. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115777. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115778. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115779. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115780. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115781. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115782. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115783. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115784. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115785. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115786. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115787. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115788. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115789. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115790. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115791. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115792. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115793. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115794. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115795. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115796. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115797. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115798. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115799. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115800. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115801. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115802. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115803. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115804. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115805. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115806. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115807. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115808. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115809. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115810. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115811. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115812. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115813. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115814. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115815. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115816. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115817. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115818. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115819. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115820. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115821. 0,
  115822. };
  115823. static float _vq_quantthresh__44c3_s_p1_0[] = {
  115824. -0.5, 0.5,
  115825. };
  115826. static long _vq_quantmap__44c3_s_p1_0[] = {
  115827. 1, 0, 2,
  115828. };
  115829. static encode_aux_threshmatch _vq_auxt__44c3_s_p1_0 = {
  115830. _vq_quantthresh__44c3_s_p1_0,
  115831. _vq_quantmap__44c3_s_p1_0,
  115832. 3,
  115833. 3
  115834. };
  115835. static static_codebook _44c3_s_p1_0 = {
  115836. 8, 6561,
  115837. _vq_lengthlist__44c3_s_p1_0,
  115838. 1, -535822336, 1611661312, 2, 0,
  115839. _vq_quantlist__44c3_s_p1_0,
  115840. NULL,
  115841. &_vq_auxt__44c3_s_p1_0,
  115842. NULL,
  115843. 0
  115844. };
  115845. static long _vq_quantlist__44c3_s_p2_0[] = {
  115846. 2,
  115847. 1,
  115848. 3,
  115849. 0,
  115850. 4,
  115851. };
  115852. static long _vq_lengthlist__44c3_s_p2_0[] = {
  115853. 2, 5, 5, 0, 0, 0, 5, 5, 0, 0, 0, 5, 5, 0, 0, 0,
  115854. 7, 8, 0, 0, 0, 0, 0, 0, 0, 5, 6, 6, 0, 0, 0, 7,
  115855. 7, 0, 0, 0, 7, 7, 0, 0, 0,10,10, 0, 0, 0, 0, 0,
  115856. 0, 0, 5, 6, 6, 0, 0, 0, 7, 7, 0, 0, 0, 7, 7, 0,
  115857. 0, 0,10,10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115858. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115859. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115860. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115861. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115862. 0, 0, 0, 0, 0, 0, 5, 7, 7, 0, 0, 0, 7, 7, 0, 0,
  115863. 0, 7, 7, 0, 0, 0, 9, 9, 0, 0, 0, 0, 0, 0, 0, 5,
  115864. 7, 7, 0, 0, 0, 7, 7, 0, 0, 0, 7, 7, 0, 0, 0, 9,
  115865. 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115866. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115867. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115868. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115869. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115870. 0, 0, 0, 5, 7, 7, 0, 0, 0, 7, 7, 0, 0, 0, 7, 7,
  115871. 0, 0, 0, 9, 9, 0, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0,
  115872. 0, 0, 7, 7, 0, 0, 0, 7, 7, 0, 0, 0, 9, 9, 0, 0,
  115873. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115874. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115875. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115876. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115877. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115878. 8,10,10, 0, 0, 0, 9, 9, 0, 0, 0, 9, 9, 0, 0, 0,
  115879. 10,10, 0, 0, 0, 0, 0, 0, 0, 8,10,10, 0, 0, 0, 9,
  115880. 9, 0, 0, 0, 9, 9, 0, 0, 0,10,10, 0, 0, 0, 0, 0,
  115881. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115882. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115883. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115884. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115885. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115886. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115887. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115888. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115889. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115890. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115891. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115892. 0,
  115893. };
  115894. static float _vq_quantthresh__44c3_s_p2_0[] = {
  115895. -1.5, -0.5, 0.5, 1.5,
  115896. };
  115897. static long _vq_quantmap__44c3_s_p2_0[] = {
  115898. 3, 1, 0, 2, 4,
  115899. };
  115900. static encode_aux_threshmatch _vq_auxt__44c3_s_p2_0 = {
  115901. _vq_quantthresh__44c3_s_p2_0,
  115902. _vq_quantmap__44c3_s_p2_0,
  115903. 5,
  115904. 5
  115905. };
  115906. static static_codebook _44c3_s_p2_0 = {
  115907. 4, 625,
  115908. _vq_lengthlist__44c3_s_p2_0,
  115909. 1, -533725184, 1611661312, 3, 0,
  115910. _vq_quantlist__44c3_s_p2_0,
  115911. NULL,
  115912. &_vq_auxt__44c3_s_p2_0,
  115913. NULL,
  115914. 0
  115915. };
  115916. static long _vq_quantlist__44c3_s_p3_0[] = {
  115917. 2,
  115918. 1,
  115919. 3,
  115920. 0,
  115921. 4,
  115922. };
  115923. static long _vq_lengthlist__44c3_s_p3_0[] = {
  115924. 2, 4, 3, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115925. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 4, 4, 6, 6, 0, 0,
  115926. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115927. 0, 0, 4, 4, 4, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115928. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 6, 6, 9, 9,
  115929. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115930. 0, 0, 0, 0, 6, 6, 7, 9, 9, 0, 0, 0, 0, 0, 0, 0,
  115931. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115932. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115933. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115934. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115935. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115936. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115937. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115938. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115939. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115940. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115941. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115942. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115943. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115944. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115945. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115946. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115947. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115948. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115949. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115950. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115951. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115952. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115953. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115954. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115955. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115956. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115957. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115958. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115959. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115960. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115961. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115962. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115963. 0,
  115964. };
  115965. static float _vq_quantthresh__44c3_s_p3_0[] = {
  115966. -1.5, -0.5, 0.5, 1.5,
  115967. };
  115968. static long _vq_quantmap__44c3_s_p3_0[] = {
  115969. 3, 1, 0, 2, 4,
  115970. };
  115971. static encode_aux_threshmatch _vq_auxt__44c3_s_p3_0 = {
  115972. _vq_quantthresh__44c3_s_p3_0,
  115973. _vq_quantmap__44c3_s_p3_0,
  115974. 5,
  115975. 5
  115976. };
  115977. static static_codebook _44c3_s_p3_0 = {
  115978. 4, 625,
  115979. _vq_lengthlist__44c3_s_p3_0,
  115980. 1, -533725184, 1611661312, 3, 0,
  115981. _vq_quantlist__44c3_s_p3_0,
  115982. NULL,
  115983. &_vq_auxt__44c3_s_p3_0,
  115984. NULL,
  115985. 0
  115986. };
  115987. static long _vq_quantlist__44c3_s_p4_0[] = {
  115988. 4,
  115989. 3,
  115990. 5,
  115991. 2,
  115992. 6,
  115993. 1,
  115994. 7,
  115995. 0,
  115996. 8,
  115997. };
  115998. static long _vq_lengthlist__44c3_s_p4_0[] = {
  115999. 2, 3, 3, 6, 6, 0, 0, 0, 0, 0, 4, 4, 6, 6, 0, 0,
  116000. 0, 0, 0, 4, 4, 6, 6, 0, 0, 0, 0, 0, 5, 5, 6, 6,
  116001. 0, 0, 0, 0, 0, 0, 0, 6, 6, 0, 0, 0, 0, 0, 0, 0,
  116002. 7, 8, 0, 0, 0, 0, 0, 0, 0, 7, 7, 0, 0, 0, 0, 0,
  116003. 0, 0, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116004. 0,
  116005. };
  116006. static float _vq_quantthresh__44c3_s_p4_0[] = {
  116007. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  116008. };
  116009. static long _vq_quantmap__44c3_s_p4_0[] = {
  116010. 7, 5, 3, 1, 0, 2, 4, 6,
  116011. 8,
  116012. };
  116013. static encode_aux_threshmatch _vq_auxt__44c3_s_p4_0 = {
  116014. _vq_quantthresh__44c3_s_p4_0,
  116015. _vq_quantmap__44c3_s_p4_0,
  116016. 9,
  116017. 9
  116018. };
  116019. static static_codebook _44c3_s_p4_0 = {
  116020. 2, 81,
  116021. _vq_lengthlist__44c3_s_p4_0,
  116022. 1, -531628032, 1611661312, 4, 0,
  116023. _vq_quantlist__44c3_s_p4_0,
  116024. NULL,
  116025. &_vq_auxt__44c3_s_p4_0,
  116026. NULL,
  116027. 0
  116028. };
  116029. static long _vq_quantlist__44c3_s_p5_0[] = {
  116030. 4,
  116031. 3,
  116032. 5,
  116033. 2,
  116034. 6,
  116035. 1,
  116036. 7,
  116037. 0,
  116038. 8,
  116039. };
  116040. static long _vq_lengthlist__44c3_s_p5_0[] = {
  116041. 1, 3, 4, 6, 6, 7, 7, 9, 9, 0, 5, 5, 7, 7, 7, 8,
  116042. 9, 9, 0, 5, 5, 7, 7, 8, 8, 9, 9, 0, 7, 7, 8, 8,
  116043. 8, 8,10,10, 0, 0, 0, 8, 8, 8, 8,10,10, 0, 0, 0,
  116044. 9, 9, 9, 9,10,10, 0, 0, 0, 9, 9, 9, 9,10,10, 0,
  116045. 0, 0,10,10,10,10,11,11, 0, 0, 0, 0, 0,10,10,11,
  116046. 11,
  116047. };
  116048. static float _vq_quantthresh__44c3_s_p5_0[] = {
  116049. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  116050. };
  116051. static long _vq_quantmap__44c3_s_p5_0[] = {
  116052. 7, 5, 3, 1, 0, 2, 4, 6,
  116053. 8,
  116054. };
  116055. static encode_aux_threshmatch _vq_auxt__44c3_s_p5_0 = {
  116056. _vq_quantthresh__44c3_s_p5_0,
  116057. _vq_quantmap__44c3_s_p5_0,
  116058. 9,
  116059. 9
  116060. };
  116061. static static_codebook _44c3_s_p5_0 = {
  116062. 2, 81,
  116063. _vq_lengthlist__44c3_s_p5_0,
  116064. 1, -531628032, 1611661312, 4, 0,
  116065. _vq_quantlist__44c3_s_p5_0,
  116066. NULL,
  116067. &_vq_auxt__44c3_s_p5_0,
  116068. NULL,
  116069. 0
  116070. };
  116071. static long _vq_quantlist__44c3_s_p6_0[] = {
  116072. 8,
  116073. 7,
  116074. 9,
  116075. 6,
  116076. 10,
  116077. 5,
  116078. 11,
  116079. 4,
  116080. 12,
  116081. 3,
  116082. 13,
  116083. 2,
  116084. 14,
  116085. 1,
  116086. 15,
  116087. 0,
  116088. 16,
  116089. };
  116090. static long _vq_lengthlist__44c3_s_p6_0[] = {
  116091. 2, 3, 3, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,10,10,11,
  116092. 10, 0, 5, 5, 7, 7, 8, 8, 9, 9, 9, 9,10,10,10,10,
  116093. 11,11, 0, 5, 5, 7, 7, 8, 8, 9, 9, 9, 9,10,10,10,
  116094. 10,11,11, 0, 6, 6, 7, 7, 8, 8, 9, 9, 9, 9,10,10,
  116095. 11,11,11,11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,
  116096. 10,11,11,11,12, 0, 0, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  116097. 10,10,11,11,12,12, 0, 0, 0, 8, 8, 8, 8, 9, 9, 9,
  116098. 9,10,10,11,11,12,12, 0, 0, 0, 9, 9, 9, 9,10,10,
  116099. 10,10,11,10,11,11,12,12, 0, 0, 0, 0, 0, 9, 9,10,
  116100. 10,10,10,11,11,11,11,12,12, 0, 0, 0, 0, 0, 9, 8,
  116101. 9, 9,10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 8,
  116102. 8, 9, 9,10,10,11,11,12,11,12,12, 0, 0, 0, 0, 0,
  116103. 9,10,10,10,11,11,11,11,12,12,13,13, 0, 0, 0, 0,
  116104. 0, 0, 0,10,10,10,10,11,11,12,12,13,13, 0, 0, 0,
  116105. 0, 0, 0, 0,11,11,11,11,12,12,12,12,13,13, 0, 0,
  116106. 0, 0, 0, 0, 0,11,11,11,11,12,12,12,12,13,13, 0,
  116107. 0, 0, 0, 0, 0, 0,11,11,12,12,12,12,13,13,13,13,
  116108. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,12,12,13,13,13,
  116109. 13,
  116110. };
  116111. static float _vq_quantthresh__44c3_s_p6_0[] = {
  116112. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  116113. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  116114. };
  116115. static long _vq_quantmap__44c3_s_p6_0[] = {
  116116. 15, 13, 11, 9, 7, 5, 3, 1,
  116117. 0, 2, 4, 6, 8, 10, 12, 14,
  116118. 16,
  116119. };
  116120. static encode_aux_threshmatch _vq_auxt__44c3_s_p6_0 = {
  116121. _vq_quantthresh__44c3_s_p6_0,
  116122. _vq_quantmap__44c3_s_p6_0,
  116123. 17,
  116124. 17
  116125. };
  116126. static static_codebook _44c3_s_p6_0 = {
  116127. 2, 289,
  116128. _vq_lengthlist__44c3_s_p6_0,
  116129. 1, -529530880, 1611661312, 5, 0,
  116130. _vq_quantlist__44c3_s_p6_0,
  116131. NULL,
  116132. &_vq_auxt__44c3_s_p6_0,
  116133. NULL,
  116134. 0
  116135. };
  116136. static long _vq_quantlist__44c3_s_p7_0[] = {
  116137. 1,
  116138. 0,
  116139. 2,
  116140. };
  116141. static long _vq_lengthlist__44c3_s_p7_0[] = {
  116142. 1, 4, 4, 7, 6, 6, 7, 6, 6, 4, 7, 7,10, 9, 9,11,
  116143. 9, 9, 4, 7, 7,10, 9, 9,11, 9, 9, 7,10,10,11,11,
  116144. 10,12,11,11, 6, 9, 9,11,10,10,11,10,10, 6, 9, 9,
  116145. 11,10,10,11,10,10, 7,11,11,11,11,11,12,11,11, 6,
  116146. 9, 9,11,10,10,11,10,10, 6, 9, 9,11,10,10,11,10,
  116147. 10,
  116148. };
  116149. static float _vq_quantthresh__44c3_s_p7_0[] = {
  116150. -5.5, 5.5,
  116151. };
  116152. static long _vq_quantmap__44c3_s_p7_0[] = {
  116153. 1, 0, 2,
  116154. };
  116155. static encode_aux_threshmatch _vq_auxt__44c3_s_p7_0 = {
  116156. _vq_quantthresh__44c3_s_p7_0,
  116157. _vq_quantmap__44c3_s_p7_0,
  116158. 3,
  116159. 3
  116160. };
  116161. static static_codebook _44c3_s_p7_0 = {
  116162. 4, 81,
  116163. _vq_lengthlist__44c3_s_p7_0,
  116164. 1, -529137664, 1618345984, 2, 0,
  116165. _vq_quantlist__44c3_s_p7_0,
  116166. NULL,
  116167. &_vq_auxt__44c3_s_p7_0,
  116168. NULL,
  116169. 0
  116170. };
  116171. static long _vq_quantlist__44c3_s_p7_1[] = {
  116172. 5,
  116173. 4,
  116174. 6,
  116175. 3,
  116176. 7,
  116177. 2,
  116178. 8,
  116179. 1,
  116180. 9,
  116181. 0,
  116182. 10,
  116183. };
  116184. static long _vq_lengthlist__44c3_s_p7_1[] = {
  116185. 2, 4, 4, 6, 6, 7, 7, 7, 7, 8, 8,10, 5, 5, 6, 6,
  116186. 7, 7, 8, 8, 8, 8,10, 5, 5, 6, 6, 7, 7, 8, 8, 8,
  116187. 8,10, 6, 6, 7, 7, 8, 8, 8, 8, 8, 8,10,10,10, 7,
  116188. 7, 8, 7, 8, 8, 8, 8,10,10,10, 8, 8, 8, 8, 8, 8,
  116189. 8, 8,10,10,10, 7, 8, 8, 8, 8, 8, 8, 8,10,10,10,
  116190. 8, 8, 8, 8, 8, 8, 8, 8,10,10,10,10,10, 8, 8, 8,
  116191. 8, 8, 8,10,10,10,10,10, 9, 9, 8, 8, 9, 8,10,10,
  116192. 10,10,10, 8, 8, 8, 8, 8, 8,
  116193. };
  116194. static float _vq_quantthresh__44c3_s_p7_1[] = {
  116195. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  116196. 3.5, 4.5,
  116197. };
  116198. static long _vq_quantmap__44c3_s_p7_1[] = {
  116199. 9, 7, 5, 3, 1, 0, 2, 4,
  116200. 6, 8, 10,
  116201. };
  116202. static encode_aux_threshmatch _vq_auxt__44c3_s_p7_1 = {
  116203. _vq_quantthresh__44c3_s_p7_1,
  116204. _vq_quantmap__44c3_s_p7_1,
  116205. 11,
  116206. 11
  116207. };
  116208. static static_codebook _44c3_s_p7_1 = {
  116209. 2, 121,
  116210. _vq_lengthlist__44c3_s_p7_1,
  116211. 1, -531365888, 1611661312, 4, 0,
  116212. _vq_quantlist__44c3_s_p7_1,
  116213. NULL,
  116214. &_vq_auxt__44c3_s_p7_1,
  116215. NULL,
  116216. 0
  116217. };
  116218. static long _vq_quantlist__44c3_s_p8_0[] = {
  116219. 6,
  116220. 5,
  116221. 7,
  116222. 4,
  116223. 8,
  116224. 3,
  116225. 9,
  116226. 2,
  116227. 10,
  116228. 1,
  116229. 11,
  116230. 0,
  116231. 12,
  116232. };
  116233. static long _vq_lengthlist__44c3_s_p8_0[] = {
  116234. 1, 4, 4, 6, 6, 7, 7, 8, 8, 9, 9,10,10, 6, 5, 5,
  116235. 7, 7, 8, 8, 8, 8, 9, 9,10,10, 7, 5, 5, 7, 7, 8,
  116236. 8, 8, 8, 9, 9,11,10, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  116237. 10,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,
  116238. 11, 0,12,12, 9, 9,10,10,10,10,11,11,11,12, 0,13,
  116239. 13, 9, 9,10,10,10,10,11,11,12,12, 0, 0, 0,10,10,
  116240. 10,10,11,11,12,12,12,12, 0, 0, 0,10,10,10,10,11,
  116241. 11,12,12,12,12, 0, 0, 0,14,14,11,11,11,11,12,12,
  116242. 13,13, 0, 0, 0,14,14,11,11,11,11,12,12,13,13, 0,
  116243. 0, 0, 0, 0,12,12,12,12,13,13,14,13, 0, 0, 0, 0,
  116244. 0,13,13,12,12,13,12,14,13,
  116245. };
  116246. static float _vq_quantthresh__44c3_s_p8_0[] = {
  116247. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  116248. 12.5, 17.5, 22.5, 27.5,
  116249. };
  116250. static long _vq_quantmap__44c3_s_p8_0[] = {
  116251. 11, 9, 7, 5, 3, 1, 0, 2,
  116252. 4, 6, 8, 10, 12,
  116253. };
  116254. static encode_aux_threshmatch _vq_auxt__44c3_s_p8_0 = {
  116255. _vq_quantthresh__44c3_s_p8_0,
  116256. _vq_quantmap__44c3_s_p8_0,
  116257. 13,
  116258. 13
  116259. };
  116260. static static_codebook _44c3_s_p8_0 = {
  116261. 2, 169,
  116262. _vq_lengthlist__44c3_s_p8_0,
  116263. 1, -526516224, 1616117760, 4, 0,
  116264. _vq_quantlist__44c3_s_p8_0,
  116265. NULL,
  116266. &_vq_auxt__44c3_s_p8_0,
  116267. NULL,
  116268. 0
  116269. };
  116270. static long _vq_quantlist__44c3_s_p8_1[] = {
  116271. 2,
  116272. 1,
  116273. 3,
  116274. 0,
  116275. 4,
  116276. };
  116277. static long _vq_lengthlist__44c3_s_p8_1[] = {
  116278. 2, 4, 4, 5, 5, 6, 5, 5, 5, 5, 6, 4, 5, 5, 5, 6,
  116279. 5, 5, 5, 5, 6, 6, 6, 5, 5,
  116280. };
  116281. static float _vq_quantthresh__44c3_s_p8_1[] = {
  116282. -1.5, -0.5, 0.5, 1.5,
  116283. };
  116284. static long _vq_quantmap__44c3_s_p8_1[] = {
  116285. 3, 1, 0, 2, 4,
  116286. };
  116287. static encode_aux_threshmatch _vq_auxt__44c3_s_p8_1 = {
  116288. _vq_quantthresh__44c3_s_p8_1,
  116289. _vq_quantmap__44c3_s_p8_1,
  116290. 5,
  116291. 5
  116292. };
  116293. static static_codebook _44c3_s_p8_1 = {
  116294. 2, 25,
  116295. _vq_lengthlist__44c3_s_p8_1,
  116296. 1, -533725184, 1611661312, 3, 0,
  116297. _vq_quantlist__44c3_s_p8_1,
  116298. NULL,
  116299. &_vq_auxt__44c3_s_p8_1,
  116300. NULL,
  116301. 0
  116302. };
  116303. static long _vq_quantlist__44c3_s_p9_0[] = {
  116304. 6,
  116305. 5,
  116306. 7,
  116307. 4,
  116308. 8,
  116309. 3,
  116310. 9,
  116311. 2,
  116312. 10,
  116313. 1,
  116314. 11,
  116315. 0,
  116316. 12,
  116317. };
  116318. static long _vq_lengthlist__44c3_s_p9_0[] = {
  116319. 1, 4, 4,12,12,12,12,12,12,12,12,12,12, 4, 9, 8,
  116320. 12,12,12,12,12,12,12,12,12,12, 2, 9, 7,12,12,12,
  116321. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  116322. 12,12,12,12,12,12,11,12,12,12,12,12,12,12,12,12,
  116323. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  116324. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  116325. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  116326. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  116327. 12,12,12,12,12,12,12,12,12,12,11,11,11,11,11,11,
  116328. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  116329. 11,11,11,11,11,11,11,11,11,
  116330. };
  116331. static float _vq_quantthresh__44c3_s_p9_0[] = {
  116332. -1402.5, -1147.5, -892.5, -637.5, -382.5, -127.5, 127.5, 382.5,
  116333. 637.5, 892.5, 1147.5, 1402.5,
  116334. };
  116335. static long _vq_quantmap__44c3_s_p9_0[] = {
  116336. 11, 9, 7, 5, 3, 1, 0, 2,
  116337. 4, 6, 8, 10, 12,
  116338. };
  116339. static encode_aux_threshmatch _vq_auxt__44c3_s_p9_0 = {
  116340. _vq_quantthresh__44c3_s_p9_0,
  116341. _vq_quantmap__44c3_s_p9_0,
  116342. 13,
  116343. 13
  116344. };
  116345. static static_codebook _44c3_s_p9_0 = {
  116346. 2, 169,
  116347. _vq_lengthlist__44c3_s_p9_0,
  116348. 1, -514332672, 1627381760, 4, 0,
  116349. _vq_quantlist__44c3_s_p9_0,
  116350. NULL,
  116351. &_vq_auxt__44c3_s_p9_0,
  116352. NULL,
  116353. 0
  116354. };
  116355. static long _vq_quantlist__44c3_s_p9_1[] = {
  116356. 7,
  116357. 6,
  116358. 8,
  116359. 5,
  116360. 9,
  116361. 4,
  116362. 10,
  116363. 3,
  116364. 11,
  116365. 2,
  116366. 12,
  116367. 1,
  116368. 13,
  116369. 0,
  116370. 14,
  116371. };
  116372. static long _vq_lengthlist__44c3_s_p9_1[] = {
  116373. 1, 4, 4, 6, 6, 7, 7, 8, 7, 9, 9,10,10,10,10, 6,
  116374. 5, 5, 7, 7, 8, 8,10, 8,11,10,12,12,13,13, 6, 5,
  116375. 5, 7, 7, 8, 8,10, 9,11,11,12,12,13,12,18, 8, 8,
  116376. 8, 8, 9, 9,10, 9,11,10,12,12,13,13,18, 8, 8, 8,
  116377. 8, 9, 9,10,10,11,11,13,12,14,13,18,11,11, 9, 9,
  116378. 10,10,11,11,11,12,13,12,13,14,18,11,11, 9, 8,11,
  116379. 10,11,11,11,11,12,12,14,13,18,18,18,10,11,10,11,
  116380. 12,12,12,12,13,12,14,13,18,18,18,10,11,11, 9,12,
  116381. 11,12,12,12,13,13,13,18,18,17,14,14,11,11,12,12,
  116382. 13,12,14,12,14,13,18,18,18,14,14,11,10,12, 9,12,
  116383. 13,13,13,13,13,18,18,17,16,18,13,13,12,12,13,11,
  116384. 14,12,14,14,17,18,18,17,18,13,12,13,10,12,11,14,
  116385. 14,14,14,17,18,18,18,18,15,16,12,12,13,10,14,12,
  116386. 14,15,18,18,18,16,17,16,14,12,11,13,10,13,13,14,
  116387. 15,
  116388. };
  116389. static float _vq_quantthresh__44c3_s_p9_1[] = {
  116390. -110.5, -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5,
  116391. 25.5, 42.5, 59.5, 76.5, 93.5, 110.5,
  116392. };
  116393. static long _vq_quantmap__44c3_s_p9_1[] = {
  116394. 13, 11, 9, 7, 5, 3, 1, 0,
  116395. 2, 4, 6, 8, 10, 12, 14,
  116396. };
  116397. static encode_aux_threshmatch _vq_auxt__44c3_s_p9_1 = {
  116398. _vq_quantthresh__44c3_s_p9_1,
  116399. _vq_quantmap__44c3_s_p9_1,
  116400. 15,
  116401. 15
  116402. };
  116403. static static_codebook _44c3_s_p9_1 = {
  116404. 2, 225,
  116405. _vq_lengthlist__44c3_s_p9_1,
  116406. 1, -522338304, 1620115456, 4, 0,
  116407. _vq_quantlist__44c3_s_p9_1,
  116408. NULL,
  116409. &_vq_auxt__44c3_s_p9_1,
  116410. NULL,
  116411. 0
  116412. };
  116413. static long _vq_quantlist__44c3_s_p9_2[] = {
  116414. 8,
  116415. 7,
  116416. 9,
  116417. 6,
  116418. 10,
  116419. 5,
  116420. 11,
  116421. 4,
  116422. 12,
  116423. 3,
  116424. 13,
  116425. 2,
  116426. 14,
  116427. 1,
  116428. 15,
  116429. 0,
  116430. 16,
  116431. };
  116432. static long _vq_lengthlist__44c3_s_p9_2[] = {
  116433. 2, 5, 5, 6, 6, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8,
  116434. 8,10, 6, 6, 7, 7, 8, 7, 8, 8, 8, 8, 8, 9, 9, 9,
  116435. 9, 9,10, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9,
  116436. 9, 9, 9,10, 7, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9,
  116437. 9, 9, 9, 9,10,10,10, 7, 7, 8, 8, 8, 9, 9, 9, 9,
  116438. 9, 9, 9, 9, 9,11,11,11, 8, 8, 8, 8, 9, 9, 9, 9,
  116439. 9, 9, 9, 9, 9, 9,10,10,10, 8, 8, 8, 8, 9, 9, 9,
  116440. 9, 9, 9, 9, 9, 9, 9,10,10,10, 8, 9, 9, 9, 9, 9,
  116441. 9, 9, 9, 9, 9, 9,10, 9,10,10,10,11,11, 9, 9, 9,
  116442. 9, 9, 9, 9, 9, 9, 9, 9, 9,11,10,11,11,11, 9, 9,
  116443. 9, 9, 9, 9,10,10, 9, 9,10, 9,11,10,11,11,11, 9,
  116444. 9, 9, 9, 9, 9, 9, 9,10,10,10, 9,11,11,11,11,11,
  116445. 9, 9, 9, 9,10,10, 9, 9, 9, 9,10, 9,11,11,11,11,
  116446. 11,11,11, 9, 9, 9, 9, 9, 9,10,10,10,10,11,11,11,
  116447. 11,11,11,11,10, 9,10,10, 9,10, 9, 9,10, 9,11,10,
  116448. 10,11,11,11,11, 9,10, 9, 9, 9, 9,10,10,10,10,11,
  116449. 11,11,11,11,11,10,10,10, 9, 9,10, 9,10, 9,10,10,
  116450. 10,10,11,11,11,11,11,11,11, 9, 9, 9, 9, 9,10,10,
  116451. 10,
  116452. };
  116453. static float _vq_quantthresh__44c3_s_p9_2[] = {
  116454. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  116455. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  116456. };
  116457. static long _vq_quantmap__44c3_s_p9_2[] = {
  116458. 15, 13, 11, 9, 7, 5, 3, 1,
  116459. 0, 2, 4, 6, 8, 10, 12, 14,
  116460. 16,
  116461. };
  116462. static encode_aux_threshmatch _vq_auxt__44c3_s_p9_2 = {
  116463. _vq_quantthresh__44c3_s_p9_2,
  116464. _vq_quantmap__44c3_s_p9_2,
  116465. 17,
  116466. 17
  116467. };
  116468. static static_codebook _44c3_s_p9_2 = {
  116469. 2, 289,
  116470. _vq_lengthlist__44c3_s_p9_2,
  116471. 1, -529530880, 1611661312, 5, 0,
  116472. _vq_quantlist__44c3_s_p9_2,
  116473. NULL,
  116474. &_vq_auxt__44c3_s_p9_2,
  116475. NULL,
  116476. 0
  116477. };
  116478. static long _huff_lengthlist__44c3_s_short[] = {
  116479. 10, 9,13,11,14,10,12,13,13,14, 7, 2,12, 5,10, 5,
  116480. 7,10,12,14,12, 6, 9, 8, 7, 7, 9,11,13,16,10, 4,
  116481. 12, 5,10, 6, 8,12,14,16,12, 6, 8, 7, 6, 5, 7,11,
  116482. 12,16,10, 4, 8, 5, 6, 4, 6, 9,13,16,10, 6,10, 7,
  116483. 7, 6, 7, 9,13,15,12, 9,11, 9, 8, 6, 7,10,12,14,
  116484. 14,11,10, 9, 6, 5, 6, 9,11,13,15,13,11,10, 6, 5,
  116485. 6, 8, 9,11,
  116486. };
  116487. static static_codebook _huff_book__44c3_s_short = {
  116488. 2, 100,
  116489. _huff_lengthlist__44c3_s_short,
  116490. 0, 0, 0, 0, 0,
  116491. NULL,
  116492. NULL,
  116493. NULL,
  116494. NULL,
  116495. 0
  116496. };
  116497. static long _huff_lengthlist__44c4_s_long[] = {
  116498. 4, 7,11,11,11,11,10,11,12,11, 5, 2,11, 5, 6, 6,
  116499. 7, 9,11,12,11, 9, 6,10, 6, 7, 8, 9,10,11,11, 5,
  116500. 11, 7, 8, 8, 9,11,13,14,11, 6, 5, 8, 4, 5, 7, 8,
  116501. 10,11,10, 6, 7, 7, 5, 5, 6, 8, 9,11,10, 7, 8, 9,
  116502. 6, 6, 6, 7, 8, 9,11, 9, 9,11, 7, 7, 6, 6, 7, 9,
  116503. 12,12,10,13, 9, 8, 7, 7, 7, 8,11,13,11,14,11,10,
  116504. 9, 8, 7, 7,
  116505. };
  116506. static static_codebook _huff_book__44c4_s_long = {
  116507. 2, 100,
  116508. _huff_lengthlist__44c4_s_long,
  116509. 0, 0, 0, 0, 0,
  116510. NULL,
  116511. NULL,
  116512. NULL,
  116513. NULL,
  116514. 0
  116515. };
  116516. static long _vq_quantlist__44c4_s_p1_0[] = {
  116517. 1,
  116518. 0,
  116519. 2,
  116520. };
  116521. static long _vq_lengthlist__44c4_s_p1_0[] = {
  116522. 2, 4, 4, 0, 0, 0, 0, 0, 0, 5, 6, 6, 0, 0, 0, 0,
  116523. 0, 0, 5, 6, 7, 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, 5, 7, 7, 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0, 0,
  116528. 0, 0, 0, 6, 8, 8, 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, 5, 7, 7, 0, 0, 0, 0, 0, 0, 6, 8, 7, 0, 0,
  116533. 0, 0, 0, 0, 7, 8, 8, 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, 5, 7, 7, 0, 0, 0, 0,
  116568. 0, 0, 7, 8, 8, 0, 0, 0, 0, 0, 0, 7, 8, 8, 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, 7, 8, 8, 0, 0, 0,
  116573. 0, 0, 0, 8, 9, 9, 0, 0, 0, 0, 0, 0, 8, 9, 9, 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, 6, 8, 8, 0, 0,
  116578. 0, 0, 0, 0, 8, 9, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9,
  116579. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116580. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116581. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116582. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116583. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116584. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116585. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116586. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116587. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116588. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116589. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116590. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116591. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116592. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116593. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116594. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116595. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116596. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116597. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116598. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116599. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116600. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116601. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116602. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116603. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116604. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116605. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116606. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116607. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116608. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116609. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116610. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116611. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116612. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116613. 0, 0, 4, 7, 7, 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0,
  116614. 0, 0, 0, 0, 7, 8, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116615. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116616. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116617. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116618. 0, 0, 0, 6, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0,
  116619. 0, 0, 0, 0, 0, 8, 8, 9, 0, 0, 0, 0, 0, 0, 0, 0,
  116620. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116621. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116622. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116623. 0, 0, 0, 0, 7, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9,
  116624. 0, 0, 0, 0, 0, 0, 8, 9, 9, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116630. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116631. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116632. 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116638. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116639. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116646. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116647. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116660. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116661. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116662. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116663. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116664. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116665. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116666. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116667. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116668. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116669. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116670. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116671. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116672. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116673. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116674. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116675. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116676. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116677. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116678. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116679. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116680. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116681. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116682. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116683. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116684. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116685. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116686. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116687. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116688. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116689. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116690. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116691. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116692. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116693. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116694. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116695. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116696. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116697. 0, 0, 0, 0, 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116731. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116732. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116733. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116734. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116735. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116736. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116737. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116738. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116739. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116740. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116741. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116742. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116743. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116744. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116745. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116746. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116747. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116748. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116749. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116750. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116751. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116752. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116753. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116754. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116755. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116756. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116757. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116758. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116759. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116760. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116761. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116762. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116763. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116764. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116765. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116766. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116767. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116768. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116769. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116770. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116771. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116772. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116773. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116774. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116775. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116776. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116777. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116778. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116779. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116780. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116781. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116782. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116783. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116784. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116785. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116786. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116787. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116788. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116789. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116790. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116791. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116792. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116793. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116794. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116795. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116796. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116797. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116798. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116799. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116800. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116801. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116802. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116803. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116804. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116805. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116806. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116807. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116808. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116809. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116810. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116811. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116812. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116813. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116814. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116815. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116816. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116817. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116818. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116819. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116820. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116821. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116822. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116823. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116824. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116825. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116826. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116827. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116828. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116829. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116830. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116831. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116832. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116833. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116834. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116835. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116836. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116837. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116838. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116839. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116840. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116841. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116842. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116843. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116844. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116845. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116846. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116847. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116848. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116849. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116850. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116851. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116852. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116853. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116854. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116855. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116856. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116857. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116858. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116859. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116860. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116861. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116862. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116863. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116864. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116865. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116866. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116867. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116868. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116869. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116870. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116871. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116872. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116873. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116874. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116875. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116876. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116877. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116878. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116879. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116880. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116881. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116882. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116883. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116884. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116885. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116886. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116887. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116888. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116889. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116890. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116891. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116892. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116893. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116894. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116895. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116896. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116897. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116898. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116899. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116900. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116901. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116902. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116903. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116904. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116905. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116906. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116907. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116908. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116909. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116910. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116911. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116912. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116913. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116914. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116915. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116916. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116917. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116918. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116919. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116920. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116921. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116922. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116923. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116924. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116925. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116926. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116927. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116928. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116929. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116930. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116931. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116932. 0,
  116933. };
  116934. static float _vq_quantthresh__44c4_s_p1_0[] = {
  116935. -0.5, 0.5,
  116936. };
  116937. static long _vq_quantmap__44c4_s_p1_0[] = {
  116938. 1, 0, 2,
  116939. };
  116940. static encode_aux_threshmatch _vq_auxt__44c4_s_p1_0 = {
  116941. _vq_quantthresh__44c4_s_p1_0,
  116942. _vq_quantmap__44c4_s_p1_0,
  116943. 3,
  116944. 3
  116945. };
  116946. static static_codebook _44c4_s_p1_0 = {
  116947. 8, 6561,
  116948. _vq_lengthlist__44c4_s_p1_0,
  116949. 1, -535822336, 1611661312, 2, 0,
  116950. _vq_quantlist__44c4_s_p1_0,
  116951. NULL,
  116952. &_vq_auxt__44c4_s_p1_0,
  116953. NULL,
  116954. 0
  116955. };
  116956. static long _vq_quantlist__44c4_s_p2_0[] = {
  116957. 2,
  116958. 1,
  116959. 3,
  116960. 0,
  116961. 4,
  116962. };
  116963. static long _vq_lengthlist__44c4_s_p2_0[] = {
  116964. 2, 5, 5, 0, 0, 0, 5, 5, 0, 0, 0, 5, 5, 0, 0, 0,
  116965. 7, 7, 0, 0, 0, 0, 0, 0, 0, 5, 6, 6, 0, 0, 0, 7,
  116966. 7, 0, 0, 0, 7, 7, 0, 0, 0,10,10, 0, 0, 0, 0, 0,
  116967. 0, 0, 5, 6, 6, 0, 0, 0, 7, 7, 0, 0, 0, 7, 7, 0,
  116968. 0, 0,10,10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116969. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116970. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116971. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116972. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116973. 0, 0, 0, 0, 0, 0, 5, 8, 7, 0, 0, 0, 7, 7, 0, 0,
  116974. 0, 7, 7, 0, 0, 0, 9, 9, 0, 0, 0, 0, 0, 0, 0, 5,
  116975. 7, 8, 0, 0, 0, 7, 7, 0, 0, 0, 7, 7, 0, 0, 0, 9,
  116976. 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116977. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116978. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116979. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116980. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116981. 0, 0, 0, 5, 7, 7, 0, 0, 0, 7, 7, 0, 0, 0, 7, 7,
  116982. 0, 0, 0, 9, 9, 0, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0,
  116983. 0, 0, 7, 7, 0, 0, 0, 7, 7, 0, 0, 0, 9, 9, 0, 0,
  116984. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116985. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116986. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116987. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116988. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116989. 7,10,10, 0, 0, 0, 9, 9, 0, 0, 0, 9, 9, 0, 0, 0,
  116990. 10,10, 0, 0, 0, 0, 0, 0, 0, 8,10,10, 0, 0, 0, 9,
  116991. 9, 0, 0, 0, 9, 9, 0, 0, 0,10,10, 0, 0, 0, 0, 0,
  116992. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116993. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116994. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116995. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116996. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116997. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116998. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116999. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117000. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117001. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117002. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117003. 0,
  117004. };
  117005. static float _vq_quantthresh__44c4_s_p2_0[] = {
  117006. -1.5, -0.5, 0.5, 1.5,
  117007. };
  117008. static long _vq_quantmap__44c4_s_p2_0[] = {
  117009. 3, 1, 0, 2, 4,
  117010. };
  117011. static encode_aux_threshmatch _vq_auxt__44c4_s_p2_0 = {
  117012. _vq_quantthresh__44c4_s_p2_0,
  117013. _vq_quantmap__44c4_s_p2_0,
  117014. 5,
  117015. 5
  117016. };
  117017. static static_codebook _44c4_s_p2_0 = {
  117018. 4, 625,
  117019. _vq_lengthlist__44c4_s_p2_0,
  117020. 1, -533725184, 1611661312, 3, 0,
  117021. _vq_quantlist__44c4_s_p2_0,
  117022. NULL,
  117023. &_vq_auxt__44c4_s_p2_0,
  117024. NULL,
  117025. 0
  117026. };
  117027. static long _vq_quantlist__44c4_s_p3_0[] = {
  117028. 2,
  117029. 1,
  117030. 3,
  117031. 0,
  117032. 4,
  117033. };
  117034. static long _vq_lengthlist__44c4_s_p3_0[] = {
  117035. 2, 3, 3, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117036. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 5, 4, 6, 6, 0, 0,
  117037. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117038. 0, 0, 4, 4, 5, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117039. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 6, 6, 9, 9,
  117040. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117041. 0, 0, 0, 0, 6, 6, 7, 9, 9, 0, 0, 0, 0, 0, 0, 0,
  117042. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117043. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117044. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117045. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117046. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117047. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117048. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117049. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117050. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117051. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117052. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117053. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117054. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117055. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117056. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117057. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117058. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117059. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117060. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117061. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117062. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117063. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117064. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117065. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117066. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117067. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117068. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117069. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117070. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117071. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117072. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117073. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117074. 0,
  117075. };
  117076. static float _vq_quantthresh__44c4_s_p3_0[] = {
  117077. -1.5, -0.5, 0.5, 1.5,
  117078. };
  117079. static long _vq_quantmap__44c4_s_p3_0[] = {
  117080. 3, 1, 0, 2, 4,
  117081. };
  117082. static encode_aux_threshmatch _vq_auxt__44c4_s_p3_0 = {
  117083. _vq_quantthresh__44c4_s_p3_0,
  117084. _vq_quantmap__44c4_s_p3_0,
  117085. 5,
  117086. 5
  117087. };
  117088. static static_codebook _44c4_s_p3_0 = {
  117089. 4, 625,
  117090. _vq_lengthlist__44c4_s_p3_0,
  117091. 1, -533725184, 1611661312, 3, 0,
  117092. _vq_quantlist__44c4_s_p3_0,
  117093. NULL,
  117094. &_vq_auxt__44c4_s_p3_0,
  117095. NULL,
  117096. 0
  117097. };
  117098. static long _vq_quantlist__44c4_s_p4_0[] = {
  117099. 4,
  117100. 3,
  117101. 5,
  117102. 2,
  117103. 6,
  117104. 1,
  117105. 7,
  117106. 0,
  117107. 8,
  117108. };
  117109. static long _vq_lengthlist__44c4_s_p4_0[] = {
  117110. 2, 3, 3, 6, 6, 0, 0, 0, 0, 0, 4, 4, 6, 6, 0, 0,
  117111. 0, 0, 0, 4, 4, 6, 6, 0, 0, 0, 0, 0, 5, 5, 6, 6,
  117112. 0, 0, 0, 0, 0, 0, 0, 6, 6, 0, 0, 0, 0, 0, 0, 0,
  117113. 7, 8, 0, 0, 0, 0, 0, 0, 0, 7, 7, 0, 0, 0, 0, 0,
  117114. 0, 0, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117115. 0,
  117116. };
  117117. static float _vq_quantthresh__44c4_s_p4_0[] = {
  117118. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  117119. };
  117120. static long _vq_quantmap__44c4_s_p4_0[] = {
  117121. 7, 5, 3, 1, 0, 2, 4, 6,
  117122. 8,
  117123. };
  117124. static encode_aux_threshmatch _vq_auxt__44c4_s_p4_0 = {
  117125. _vq_quantthresh__44c4_s_p4_0,
  117126. _vq_quantmap__44c4_s_p4_0,
  117127. 9,
  117128. 9
  117129. };
  117130. static static_codebook _44c4_s_p4_0 = {
  117131. 2, 81,
  117132. _vq_lengthlist__44c4_s_p4_0,
  117133. 1, -531628032, 1611661312, 4, 0,
  117134. _vq_quantlist__44c4_s_p4_0,
  117135. NULL,
  117136. &_vq_auxt__44c4_s_p4_0,
  117137. NULL,
  117138. 0
  117139. };
  117140. static long _vq_quantlist__44c4_s_p5_0[] = {
  117141. 4,
  117142. 3,
  117143. 5,
  117144. 2,
  117145. 6,
  117146. 1,
  117147. 7,
  117148. 0,
  117149. 8,
  117150. };
  117151. static long _vq_lengthlist__44c4_s_p5_0[] = {
  117152. 2, 3, 3, 6, 6, 7, 7, 9, 9, 0, 4, 4, 6, 6, 7, 7,
  117153. 9, 9, 0, 4, 5, 6, 6, 7, 7, 9, 9, 0, 6, 6, 7, 7,
  117154. 8, 8,10,10, 0, 0, 0, 7, 7, 8, 8,10, 9, 0, 0, 0,
  117155. 9, 8, 8, 8,10,10, 0, 0, 0, 8, 8, 8, 8,10,10, 0,
  117156. 0, 0,10,10, 9, 9,11,11, 0, 0, 0, 0, 0, 9, 9,10,
  117157. 10,
  117158. };
  117159. static float _vq_quantthresh__44c4_s_p5_0[] = {
  117160. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  117161. };
  117162. static long _vq_quantmap__44c4_s_p5_0[] = {
  117163. 7, 5, 3, 1, 0, 2, 4, 6,
  117164. 8,
  117165. };
  117166. static encode_aux_threshmatch _vq_auxt__44c4_s_p5_0 = {
  117167. _vq_quantthresh__44c4_s_p5_0,
  117168. _vq_quantmap__44c4_s_p5_0,
  117169. 9,
  117170. 9
  117171. };
  117172. static static_codebook _44c4_s_p5_0 = {
  117173. 2, 81,
  117174. _vq_lengthlist__44c4_s_p5_0,
  117175. 1, -531628032, 1611661312, 4, 0,
  117176. _vq_quantlist__44c4_s_p5_0,
  117177. NULL,
  117178. &_vq_auxt__44c4_s_p5_0,
  117179. NULL,
  117180. 0
  117181. };
  117182. static long _vq_quantlist__44c4_s_p6_0[] = {
  117183. 8,
  117184. 7,
  117185. 9,
  117186. 6,
  117187. 10,
  117188. 5,
  117189. 11,
  117190. 4,
  117191. 12,
  117192. 3,
  117193. 13,
  117194. 2,
  117195. 14,
  117196. 1,
  117197. 15,
  117198. 0,
  117199. 16,
  117200. };
  117201. static long _vq_lengthlist__44c4_s_p6_0[] = {
  117202. 2, 4, 4, 6, 6, 8, 8, 9, 9, 8, 8, 9, 9,10,10,11,
  117203. 11, 0, 4, 4, 6, 6, 8, 8, 9, 9, 9, 9,10,10,11,11,
  117204. 11,11, 0, 4, 4, 7, 6, 8, 8, 9, 9, 9, 9,10,10,11,
  117205. 11,11,11, 0, 6, 6, 7, 7, 8, 8, 9, 9, 9, 9,10,10,
  117206. 11,11,11,12, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,
  117207. 10,11,11,12,12, 0, 0, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  117208. 10,10,11,11,12,12, 0, 0, 0, 8, 8, 8, 8, 9, 9, 9,
  117209. 9,10,10,11,11,12,12, 0, 0, 0, 9, 9, 9, 9,10,10,
  117210. 10,10,11,11,11,11,12,12, 0, 0, 0, 0, 0, 9, 9,10,
  117211. 10,10,10,11,11,11,11,12,12, 0, 0, 0, 0, 0, 9, 9,
  117212. 9,10,10,10,11,11,11,11,12,12, 0, 0, 0, 0, 0, 9,
  117213. 9, 9, 9,10,10,11,11,11,12,12,12, 0, 0, 0, 0, 0,
  117214. 10,10,10,10,11,11,11,11,12,12,13,12, 0, 0, 0, 0,
  117215. 0, 0, 0,10,10,11,11,11,11,12,12,12,12, 0, 0, 0,
  117216. 0, 0, 0, 0,11,11,11,11,12,12,12,12,13,13, 0, 0,
  117217. 0, 0, 0, 0, 0,11,11,11,11,12,12,12,12,13,13, 0,
  117218. 0, 0, 0, 0, 0, 0,12,12,12,12,12,12,13,13,13,13,
  117219. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,12,12,12,13,13,
  117220. 13,
  117221. };
  117222. static float _vq_quantthresh__44c4_s_p6_0[] = {
  117223. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  117224. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  117225. };
  117226. static long _vq_quantmap__44c4_s_p6_0[] = {
  117227. 15, 13, 11, 9, 7, 5, 3, 1,
  117228. 0, 2, 4, 6, 8, 10, 12, 14,
  117229. 16,
  117230. };
  117231. static encode_aux_threshmatch _vq_auxt__44c4_s_p6_0 = {
  117232. _vq_quantthresh__44c4_s_p6_0,
  117233. _vq_quantmap__44c4_s_p6_0,
  117234. 17,
  117235. 17
  117236. };
  117237. static static_codebook _44c4_s_p6_0 = {
  117238. 2, 289,
  117239. _vq_lengthlist__44c4_s_p6_0,
  117240. 1, -529530880, 1611661312, 5, 0,
  117241. _vq_quantlist__44c4_s_p6_0,
  117242. NULL,
  117243. &_vq_auxt__44c4_s_p6_0,
  117244. NULL,
  117245. 0
  117246. };
  117247. static long _vq_quantlist__44c4_s_p7_0[] = {
  117248. 1,
  117249. 0,
  117250. 2,
  117251. };
  117252. static long _vq_lengthlist__44c4_s_p7_0[] = {
  117253. 1, 4, 4, 7, 6, 6, 7, 6, 6, 4, 7, 7,10, 9, 9,11,
  117254. 9, 9, 4, 7, 7,10, 9, 9,11, 9, 9, 7,10,10,11,11,
  117255. 10,11,11,11, 6, 9, 9,11,10,10,11,10,10, 6, 9, 9,
  117256. 11,10,10,11,10,10, 7,11,11,12,11,11,12,11,11, 6,
  117257. 9, 9,11,10,10,11,10,10, 6, 9, 9,11,10,10,11,10,
  117258. 10,
  117259. };
  117260. static float _vq_quantthresh__44c4_s_p7_0[] = {
  117261. -5.5, 5.5,
  117262. };
  117263. static long _vq_quantmap__44c4_s_p7_0[] = {
  117264. 1, 0, 2,
  117265. };
  117266. static encode_aux_threshmatch _vq_auxt__44c4_s_p7_0 = {
  117267. _vq_quantthresh__44c4_s_p7_0,
  117268. _vq_quantmap__44c4_s_p7_0,
  117269. 3,
  117270. 3
  117271. };
  117272. static static_codebook _44c4_s_p7_0 = {
  117273. 4, 81,
  117274. _vq_lengthlist__44c4_s_p7_0,
  117275. 1, -529137664, 1618345984, 2, 0,
  117276. _vq_quantlist__44c4_s_p7_0,
  117277. NULL,
  117278. &_vq_auxt__44c4_s_p7_0,
  117279. NULL,
  117280. 0
  117281. };
  117282. static long _vq_quantlist__44c4_s_p7_1[] = {
  117283. 5,
  117284. 4,
  117285. 6,
  117286. 3,
  117287. 7,
  117288. 2,
  117289. 8,
  117290. 1,
  117291. 9,
  117292. 0,
  117293. 10,
  117294. };
  117295. static long _vq_lengthlist__44c4_s_p7_1[] = {
  117296. 2, 4, 4, 6, 6, 7, 7, 7, 7, 8, 8,10, 5, 5, 6, 6,
  117297. 7, 7, 8, 8, 8, 8,10, 5, 5, 6, 6, 7, 7, 8, 8, 8,
  117298. 8,10, 6, 6, 7, 7, 8, 8, 8, 8, 8, 8,10,10,10, 7,
  117299. 7, 8, 8, 8, 8, 8, 8,10,10,10, 8, 7, 8, 8, 8, 8,
  117300. 8, 8,10,10,10, 7, 7, 8, 8, 8, 8, 8, 8,10,10,10,
  117301. 8, 8, 8, 8, 8, 8, 8, 8,10,10,10,10,10, 8, 8, 8,
  117302. 8, 8, 8,10,10,10,10,10, 9, 9, 8, 8, 9, 8,10,10,
  117303. 10,10,10, 8, 8, 8, 8, 9, 9,
  117304. };
  117305. static float _vq_quantthresh__44c4_s_p7_1[] = {
  117306. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  117307. 3.5, 4.5,
  117308. };
  117309. static long _vq_quantmap__44c4_s_p7_1[] = {
  117310. 9, 7, 5, 3, 1, 0, 2, 4,
  117311. 6, 8, 10,
  117312. };
  117313. static encode_aux_threshmatch _vq_auxt__44c4_s_p7_1 = {
  117314. _vq_quantthresh__44c4_s_p7_1,
  117315. _vq_quantmap__44c4_s_p7_1,
  117316. 11,
  117317. 11
  117318. };
  117319. static static_codebook _44c4_s_p7_1 = {
  117320. 2, 121,
  117321. _vq_lengthlist__44c4_s_p7_1,
  117322. 1, -531365888, 1611661312, 4, 0,
  117323. _vq_quantlist__44c4_s_p7_1,
  117324. NULL,
  117325. &_vq_auxt__44c4_s_p7_1,
  117326. NULL,
  117327. 0
  117328. };
  117329. static long _vq_quantlist__44c4_s_p8_0[] = {
  117330. 6,
  117331. 5,
  117332. 7,
  117333. 4,
  117334. 8,
  117335. 3,
  117336. 9,
  117337. 2,
  117338. 10,
  117339. 1,
  117340. 11,
  117341. 0,
  117342. 12,
  117343. };
  117344. static long _vq_lengthlist__44c4_s_p8_0[] = {
  117345. 1, 4, 4, 6, 6, 7, 7, 8, 8, 9, 9,10,10, 6, 5, 5,
  117346. 7, 7, 8, 8, 8, 8, 9,10,11,11, 7, 5, 5, 7, 7, 8,
  117347. 8, 9, 9,10,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  117348. 10,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,
  117349. 11, 0,12,12, 9, 9, 9, 9,10,10,10,10,11,11, 0,13,
  117350. 13, 9, 9,10, 9,10,10,11,11,11,12, 0, 0, 0,10,10,
  117351. 10,10,10,10,11,11,12,12, 0, 0, 0,10,10,10,10,10,
  117352. 10,11,11,12,12, 0, 0, 0,14,14,11,11,11,11,12,12,
  117353. 12,12, 0, 0, 0,14,14,11,11,11,11,12,12,12,13, 0,
  117354. 0, 0, 0, 0,12,12,12,12,12,12,13,13, 0, 0, 0, 0,
  117355. 0,13,12,12,12,12,12,13,13,
  117356. };
  117357. static float _vq_quantthresh__44c4_s_p8_0[] = {
  117358. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  117359. 12.5, 17.5, 22.5, 27.5,
  117360. };
  117361. static long _vq_quantmap__44c4_s_p8_0[] = {
  117362. 11, 9, 7, 5, 3, 1, 0, 2,
  117363. 4, 6, 8, 10, 12,
  117364. };
  117365. static encode_aux_threshmatch _vq_auxt__44c4_s_p8_0 = {
  117366. _vq_quantthresh__44c4_s_p8_0,
  117367. _vq_quantmap__44c4_s_p8_0,
  117368. 13,
  117369. 13
  117370. };
  117371. static static_codebook _44c4_s_p8_0 = {
  117372. 2, 169,
  117373. _vq_lengthlist__44c4_s_p8_0,
  117374. 1, -526516224, 1616117760, 4, 0,
  117375. _vq_quantlist__44c4_s_p8_0,
  117376. NULL,
  117377. &_vq_auxt__44c4_s_p8_0,
  117378. NULL,
  117379. 0
  117380. };
  117381. static long _vq_quantlist__44c4_s_p8_1[] = {
  117382. 2,
  117383. 1,
  117384. 3,
  117385. 0,
  117386. 4,
  117387. };
  117388. static long _vq_lengthlist__44c4_s_p8_1[] = {
  117389. 2, 4, 4, 5, 5, 6, 5, 5, 5, 5, 6, 5, 4, 5, 5, 6,
  117390. 5, 5, 5, 5, 6, 6, 6, 5, 5,
  117391. };
  117392. static float _vq_quantthresh__44c4_s_p8_1[] = {
  117393. -1.5, -0.5, 0.5, 1.5,
  117394. };
  117395. static long _vq_quantmap__44c4_s_p8_1[] = {
  117396. 3, 1, 0, 2, 4,
  117397. };
  117398. static encode_aux_threshmatch _vq_auxt__44c4_s_p8_1 = {
  117399. _vq_quantthresh__44c4_s_p8_1,
  117400. _vq_quantmap__44c4_s_p8_1,
  117401. 5,
  117402. 5
  117403. };
  117404. static static_codebook _44c4_s_p8_1 = {
  117405. 2, 25,
  117406. _vq_lengthlist__44c4_s_p8_1,
  117407. 1, -533725184, 1611661312, 3, 0,
  117408. _vq_quantlist__44c4_s_p8_1,
  117409. NULL,
  117410. &_vq_auxt__44c4_s_p8_1,
  117411. NULL,
  117412. 0
  117413. };
  117414. static long _vq_quantlist__44c4_s_p9_0[] = {
  117415. 6,
  117416. 5,
  117417. 7,
  117418. 4,
  117419. 8,
  117420. 3,
  117421. 9,
  117422. 2,
  117423. 10,
  117424. 1,
  117425. 11,
  117426. 0,
  117427. 12,
  117428. };
  117429. static long _vq_lengthlist__44c4_s_p9_0[] = {
  117430. 1, 3, 3,12,12,12,12,12,12,12,12,12,12, 4, 7, 7,
  117431. 12,12,12,12,12,12,12,12,12,12, 3, 8, 8,12,12,12,
  117432. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  117433. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  117434. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  117435. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  117436. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  117437. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  117438. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  117439. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  117440. 12,12,12,12,12,12,12,12,12,
  117441. };
  117442. static float _vq_quantthresh__44c4_s_p9_0[] = {
  117443. -1732.5, -1417.5, -1102.5, -787.5, -472.5, -157.5, 157.5, 472.5,
  117444. 787.5, 1102.5, 1417.5, 1732.5,
  117445. };
  117446. static long _vq_quantmap__44c4_s_p9_0[] = {
  117447. 11, 9, 7, 5, 3, 1, 0, 2,
  117448. 4, 6, 8, 10, 12,
  117449. };
  117450. static encode_aux_threshmatch _vq_auxt__44c4_s_p9_0 = {
  117451. _vq_quantthresh__44c4_s_p9_0,
  117452. _vq_quantmap__44c4_s_p9_0,
  117453. 13,
  117454. 13
  117455. };
  117456. static static_codebook _44c4_s_p9_0 = {
  117457. 2, 169,
  117458. _vq_lengthlist__44c4_s_p9_0,
  117459. 1, -513964032, 1628680192, 4, 0,
  117460. _vq_quantlist__44c4_s_p9_0,
  117461. NULL,
  117462. &_vq_auxt__44c4_s_p9_0,
  117463. NULL,
  117464. 0
  117465. };
  117466. static long _vq_quantlist__44c4_s_p9_1[] = {
  117467. 7,
  117468. 6,
  117469. 8,
  117470. 5,
  117471. 9,
  117472. 4,
  117473. 10,
  117474. 3,
  117475. 11,
  117476. 2,
  117477. 12,
  117478. 1,
  117479. 13,
  117480. 0,
  117481. 14,
  117482. };
  117483. static long _vq_lengthlist__44c4_s_p9_1[] = {
  117484. 1, 4, 4, 5, 5, 7, 7, 9, 8,10, 9,10,10,10,10, 6,
  117485. 5, 5, 7, 7, 9, 8,10, 9,11,10,12,12,13,13, 6, 5,
  117486. 5, 7, 7, 9, 9,10,10,11,11,12,12,12,13,19, 8, 8,
  117487. 8, 8, 9, 9,10,10,12,11,12,12,13,13,19, 8, 8, 8,
  117488. 8, 9, 9,11,11,12,12,13,13,13,13,19,12,12, 9, 9,
  117489. 11,11,11,11,12,11,13,12,13,13,18,12,12, 9, 9,11,
  117490. 10,11,11,12,12,12,13,13,14,19,18,18,11,11,11,11,
  117491. 12,12,13,12,13,13,14,14,16,18,18,11,11,11,10,12,
  117492. 11,13,13,13,13,13,14,17,18,18,14,15,11,12,12,13,
  117493. 13,13,13,14,14,14,18,18,18,15,15,12,10,13,10,13,
  117494. 13,13,13,13,14,18,17,18,17,18,12,13,12,13,13,13,
  117495. 14,14,16,14,18,17,18,18,17,13,12,13,10,12,12,14,
  117496. 14,14,14,17,18,18,18,18,14,15,12,12,13,12,14,14,
  117497. 15,15,18,18,18,17,18,15,14,12,11,12,12,14,14,14,
  117498. 15,
  117499. };
  117500. static float _vq_quantthresh__44c4_s_p9_1[] = {
  117501. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  117502. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  117503. };
  117504. static long _vq_quantmap__44c4_s_p9_1[] = {
  117505. 13, 11, 9, 7, 5, 3, 1, 0,
  117506. 2, 4, 6, 8, 10, 12, 14,
  117507. };
  117508. static encode_aux_threshmatch _vq_auxt__44c4_s_p9_1 = {
  117509. _vq_quantthresh__44c4_s_p9_1,
  117510. _vq_quantmap__44c4_s_p9_1,
  117511. 15,
  117512. 15
  117513. };
  117514. static static_codebook _44c4_s_p9_1 = {
  117515. 2, 225,
  117516. _vq_lengthlist__44c4_s_p9_1,
  117517. 1, -520986624, 1620377600, 4, 0,
  117518. _vq_quantlist__44c4_s_p9_1,
  117519. NULL,
  117520. &_vq_auxt__44c4_s_p9_1,
  117521. NULL,
  117522. 0
  117523. };
  117524. static long _vq_quantlist__44c4_s_p9_2[] = {
  117525. 10,
  117526. 9,
  117527. 11,
  117528. 8,
  117529. 12,
  117530. 7,
  117531. 13,
  117532. 6,
  117533. 14,
  117534. 5,
  117535. 15,
  117536. 4,
  117537. 16,
  117538. 3,
  117539. 17,
  117540. 2,
  117541. 18,
  117542. 1,
  117543. 19,
  117544. 0,
  117545. 20,
  117546. };
  117547. static long _vq_lengthlist__44c4_s_p9_2[] = {
  117548. 2, 5, 5, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8,
  117549. 8, 9, 9, 9, 9,11, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,
  117550. 9, 9, 9, 9, 9, 9,10,10,10,10,11, 6, 6, 7, 7, 8,
  117551. 8, 8, 8, 9, 9, 9, 9, 9, 9,10, 9,10,10,10,10,11,
  117552. 7, 7, 7, 7, 8, 8, 9, 9, 9, 9, 9, 9, 9,10,10,10,
  117553. 10,10,10,10,12,11,11, 7, 7, 8, 8, 9, 9, 9, 9, 9,
  117554. 9,10,10,10,10,10,10,10,10,12,11,12, 8, 8, 8, 8,
  117555. 9, 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,11,11,
  117556. 11, 8, 8, 8, 8, 9, 9, 9, 9,10,10,10,10,10,10,10,
  117557. 10,10,10,11,11,12, 9, 9, 9, 9, 9, 9,10, 9,10,10,
  117558. 10,10,10,10,10,10,10,10,11,11,11,11,11, 9, 9, 9,
  117559. 9,10,10,10,10,10,10,10,10,10,10,10,10,11,12,11,
  117560. 11,11, 9, 9, 9,10,10,10,10,10,10,10,10,10,10,10,
  117561. 10,10,11,11,11,11,11, 9, 9, 9, 9,10,10,10,10,10,
  117562. 10,10,10,10,10,10,10,11,11,11,12,12,10,10,10,10,
  117563. 10,10,10,10,10,10,10,10,10,10,10,10,11,12,11,12,
  117564. 11,11,11, 9,10,10,10,10,10,10,10,10,10,10,10,10,
  117565. 10,11,12,11,11,11,11,11,10,10,10,10,10,10,10,10,
  117566. 10,10,10,10,10,10,11,11,11,12,11,11,11,10,10,10,
  117567. 10,10,10,10,10,10,10,10,10,10,10,12,11,11,12,11,
  117568. 11,11,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  117569. 11,11,11,11,11,11,11,11,11,10,10,10,10,10,10,10,
  117570. 10,10,10,10,10,11,11,11,11,12,12,11,11,11,11,11,
  117571. 11,11,10,10,10,10,10,10,10,10,12,12,12,11,11,11,
  117572. 12,11,11,11,10,10,10,10,10,10,10,10,10,10,10,12,
  117573. 11,12,12,12,12,12,11,12,11,11,10,10,10,10,10,10,
  117574. 10,10,10,10,12,12,12,12,11,11,11,11,11,11,11,10,
  117575. 10,10,10,10,10,10,10,10,10,
  117576. };
  117577. static float _vq_quantthresh__44c4_s_p9_2[] = {
  117578. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  117579. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  117580. 6.5, 7.5, 8.5, 9.5,
  117581. };
  117582. static long _vq_quantmap__44c4_s_p9_2[] = {
  117583. 19, 17, 15, 13, 11, 9, 7, 5,
  117584. 3, 1, 0, 2, 4, 6, 8, 10,
  117585. 12, 14, 16, 18, 20,
  117586. };
  117587. static encode_aux_threshmatch _vq_auxt__44c4_s_p9_2 = {
  117588. _vq_quantthresh__44c4_s_p9_2,
  117589. _vq_quantmap__44c4_s_p9_2,
  117590. 21,
  117591. 21
  117592. };
  117593. static static_codebook _44c4_s_p9_2 = {
  117594. 2, 441,
  117595. _vq_lengthlist__44c4_s_p9_2,
  117596. 1, -529268736, 1611661312, 5, 0,
  117597. _vq_quantlist__44c4_s_p9_2,
  117598. NULL,
  117599. &_vq_auxt__44c4_s_p9_2,
  117600. NULL,
  117601. 0
  117602. };
  117603. static long _huff_lengthlist__44c4_s_short[] = {
  117604. 4, 7,14,10,15,10,12,15,16,15, 4, 2,11, 5,10, 6,
  117605. 8,11,14,14,14,10, 7,11, 6, 8,10,11,13,15, 9, 4,
  117606. 11, 5, 9, 6, 9,12,14,15,14, 9, 6, 9, 4, 5, 7,10,
  117607. 12,13, 9, 5, 7, 6, 5, 5, 7,10,13,13,10, 8, 9, 8,
  117608. 7, 6, 8,10,14,14,13,11,10,10, 7, 7, 8,11,14,15,
  117609. 13,12, 9, 9, 6, 5, 7,10,14,17,15,13,11,10, 6, 6,
  117610. 7, 9,12,17,
  117611. };
  117612. static static_codebook _huff_book__44c4_s_short = {
  117613. 2, 100,
  117614. _huff_lengthlist__44c4_s_short,
  117615. 0, 0, 0, 0, 0,
  117616. NULL,
  117617. NULL,
  117618. NULL,
  117619. NULL,
  117620. 0
  117621. };
  117622. static long _huff_lengthlist__44c5_s_long[] = {
  117623. 3, 8, 9,13,10,12,12,12,12,12, 6, 4, 6, 8, 6, 8,
  117624. 10,10,11,12, 8, 5, 4,10, 4, 7, 8, 9,10,11,13, 8,
  117625. 10, 8, 9, 9,11,12,13,14,10, 6, 4, 9, 3, 5, 6, 8,
  117626. 10,11,11, 8, 6, 9, 5, 5, 6, 7, 9,11,12, 9, 7,11,
  117627. 6, 6, 6, 7, 8,10,12,11, 9,12, 7, 7, 6, 6, 7, 9,
  117628. 13,12,10,13, 9, 8, 7, 7, 7, 8,11,15,11,15,11,10,
  117629. 9, 8, 7, 7,
  117630. };
  117631. static static_codebook _huff_book__44c5_s_long = {
  117632. 2, 100,
  117633. _huff_lengthlist__44c5_s_long,
  117634. 0, 0, 0, 0, 0,
  117635. NULL,
  117636. NULL,
  117637. NULL,
  117638. NULL,
  117639. 0
  117640. };
  117641. static long _vq_quantlist__44c5_s_p1_0[] = {
  117642. 1,
  117643. 0,
  117644. 2,
  117645. };
  117646. static long _vq_lengthlist__44c5_s_p1_0[] = {
  117647. 2, 4, 4, 0, 0, 0, 0, 0, 0, 4, 7, 7, 0, 0, 0, 0,
  117648. 0, 0, 4, 6, 7, 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, 5, 7, 7, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0, 0,
  117653. 0, 0, 0, 7, 8, 9, 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, 4, 7, 7, 0, 0, 0, 0, 0, 0, 7, 9, 8, 0, 0,
  117658. 0, 0, 0, 0, 7, 9, 9, 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, 4, 7, 7, 0, 0, 0, 0,
  117693. 0, 0, 7, 9, 9, 0, 0, 0, 0, 0, 0, 7, 9, 9, 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, 7, 9, 9, 0, 0, 0,
  117698. 0, 0, 0, 9,10,11, 0, 0, 0, 0, 0, 0, 9,10,10, 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, 7, 9, 9, 0, 0,
  117703. 0, 0, 0, 0, 8,10, 9, 0, 0, 0, 0, 0, 0, 9,10,11,
  117704. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117705. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117706. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117707. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117708. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117709. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117710. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117711. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117712. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117713. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117714. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117715. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117716. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117717. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117718. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117719. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117720. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117721. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117722. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117723. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117724. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117725. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117726. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117727. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117728. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117729. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117730. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117731. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117732. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117733. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117734. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117735. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117736. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117737. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117738. 0, 0, 4, 7, 7, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0,
  117739. 0, 0, 0, 0, 7, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117740. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117741. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117742. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117743. 0, 0, 0, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,11,10, 0,
  117744. 0, 0, 0, 0, 0, 8, 9,10, 0, 0, 0, 0, 0, 0, 0, 0,
  117745. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117746. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117747. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117748. 0, 0, 0, 0, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,10,10,
  117749. 0, 0, 0, 0, 0, 0, 9,11,10, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117755. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117756. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117757. 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117763. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117764. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117771. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117772. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117785. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117786. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117787. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117788. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117789. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117790. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117791. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117792. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117793. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117794. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117795. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117796. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117797. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117798. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117799. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117800. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117801. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117802. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117803. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117804. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117805. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117806. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117807. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117808. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117809. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117810. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117811. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117812. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117813. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117814. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117815. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117816. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117817. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117818. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117819. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117820. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117821. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117822. 0, 0, 0, 0, 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117856. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117857. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117858. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117859. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117860. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117861. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117862. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117863. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117864. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117865. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117866. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117867. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117868. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117869. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117870. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117871. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117872. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117873. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117874. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117875. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117876. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117877. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117878. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117879. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117880. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117881. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117882. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117883. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117884. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117885. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117886. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117887. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117888. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117889. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117890. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117891. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117892. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117893. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117894. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117895. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117896. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117897. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117898. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117899. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117900. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117901. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117902. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117903. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117904. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117905. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117906. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117907. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117908. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117909. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117910. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117911. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117912. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117913. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117914. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117915. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117916. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117917. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117918. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117919. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117920. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117921. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117922. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117923. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117924. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117925. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117926. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117927. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117928. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117929. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117930. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117931. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117932. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117933. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117934. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117935. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117936. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117937. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117938. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117939. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117940. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117941. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117942. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117943. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117944. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117945. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117946. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117947. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117948. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117949. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117950. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117951. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117952. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117953. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117954. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117955. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117956. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117957. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117958. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117959. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117960. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117961. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117962. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117963. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117964. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117965. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117966. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117967. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117968. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117969. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117970. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117971. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117972. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117973. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117974. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117975. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117976. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117977. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117978. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117979. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117980. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117981. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117982. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117983. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117984. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117985. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117986. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117987. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117988. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117989. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117990. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117991. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117992. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117993. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117994. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117995. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117996. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117997. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117998. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117999. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118000. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118001. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118002. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118003. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118004. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118005. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118006. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118007. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118008. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118009. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118010. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118011. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118012. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118013. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118014. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118015. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118016. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118017. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118018. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118019. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118020. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118021. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118022. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118023. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118024. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118025. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118026. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118027. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118028. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118029. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118030. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118031. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118032. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118033. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118034. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118035. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118036. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118037. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118038. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118039. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118040. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118041. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118042. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118043. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118044. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118045. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118046. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118047. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118048. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118049. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118050. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118051. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118052. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118053. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118054. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118055. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118056. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118057. 0,
  118058. };
  118059. static float _vq_quantthresh__44c5_s_p1_0[] = {
  118060. -0.5, 0.5,
  118061. };
  118062. static long _vq_quantmap__44c5_s_p1_0[] = {
  118063. 1, 0, 2,
  118064. };
  118065. static encode_aux_threshmatch _vq_auxt__44c5_s_p1_0 = {
  118066. _vq_quantthresh__44c5_s_p1_0,
  118067. _vq_quantmap__44c5_s_p1_0,
  118068. 3,
  118069. 3
  118070. };
  118071. static static_codebook _44c5_s_p1_0 = {
  118072. 8, 6561,
  118073. _vq_lengthlist__44c5_s_p1_0,
  118074. 1, -535822336, 1611661312, 2, 0,
  118075. _vq_quantlist__44c5_s_p1_0,
  118076. NULL,
  118077. &_vq_auxt__44c5_s_p1_0,
  118078. NULL,
  118079. 0
  118080. };
  118081. static long _vq_quantlist__44c5_s_p2_0[] = {
  118082. 2,
  118083. 1,
  118084. 3,
  118085. 0,
  118086. 4,
  118087. };
  118088. static long _vq_lengthlist__44c5_s_p2_0[] = {
  118089. 2, 4, 4, 0, 0, 0, 5, 5, 0, 0, 0, 5, 5, 0, 0, 0,
  118090. 8, 7, 0, 0, 0, 0, 0, 0, 0, 4, 6, 6, 0, 0, 0, 8,
  118091. 8, 0, 0, 0, 8, 7, 0, 0, 0,10,10, 0, 0, 0, 0, 0,
  118092. 0, 0, 4, 6, 6, 0, 0, 0, 8, 8, 0, 0, 0, 7, 8, 0,
  118093. 0, 0,10,10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118094. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118095. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118096. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118097. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118098. 0, 0, 0, 0, 0, 0, 5, 8, 7, 0, 0, 0, 8, 8, 0, 0,
  118099. 0, 8, 8, 0, 0, 0,10,10, 0, 0, 0, 0, 0, 0, 0, 5,
  118100. 7, 8, 0, 0, 0, 8, 8, 0, 0, 0, 8, 8, 0, 0, 0,10,
  118101. 10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118102. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118103. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118104. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118105. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118106. 0, 0, 0, 5, 8, 8, 0, 0, 0, 8, 8, 0, 0, 0, 8, 8,
  118107. 0, 0, 0,10,10, 0, 0, 0, 0, 0, 0, 0, 5, 8, 8, 0,
  118108. 0, 0, 8, 8, 0, 0, 0, 8, 8, 0, 0, 0,10,10, 0, 0,
  118109. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118110. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118111. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118112. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118113. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118114. 8,10,10, 0, 0, 0,10,10, 0, 0, 0, 9,10, 0, 0, 0,
  118115. 11,10, 0, 0, 0, 0, 0, 0, 0, 8,10,10, 0, 0, 0,10,
  118116. 10, 0, 0, 0,10,10, 0, 0, 0,10,11, 0, 0, 0, 0, 0,
  118117. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118118. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118119. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118120. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118121. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118122. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118123. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118124. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118125. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118126. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118127. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118128. 0,
  118129. };
  118130. static float _vq_quantthresh__44c5_s_p2_0[] = {
  118131. -1.5, -0.5, 0.5, 1.5,
  118132. };
  118133. static long _vq_quantmap__44c5_s_p2_0[] = {
  118134. 3, 1, 0, 2, 4,
  118135. };
  118136. static encode_aux_threshmatch _vq_auxt__44c5_s_p2_0 = {
  118137. _vq_quantthresh__44c5_s_p2_0,
  118138. _vq_quantmap__44c5_s_p2_0,
  118139. 5,
  118140. 5
  118141. };
  118142. static static_codebook _44c5_s_p2_0 = {
  118143. 4, 625,
  118144. _vq_lengthlist__44c5_s_p2_0,
  118145. 1, -533725184, 1611661312, 3, 0,
  118146. _vq_quantlist__44c5_s_p2_0,
  118147. NULL,
  118148. &_vq_auxt__44c5_s_p2_0,
  118149. NULL,
  118150. 0
  118151. };
  118152. static long _vq_quantlist__44c5_s_p3_0[] = {
  118153. 2,
  118154. 1,
  118155. 3,
  118156. 0,
  118157. 4,
  118158. };
  118159. static long _vq_lengthlist__44c5_s_p3_0[] = {
  118160. 2, 4, 3, 5, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118161. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 5, 5, 6, 6, 0, 0,
  118162. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118163. 0, 0, 3, 5, 5, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118164. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 6, 6, 8, 8,
  118165. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118166. 0, 0, 0, 0, 5, 6, 6, 8, 8, 0, 0, 0, 0, 0, 0, 0,
  118167. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118168. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118169. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118170. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118171. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118172. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118173. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118174. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118175. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118176. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118177. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118178. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118179. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118180. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118181. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118182. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118183. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118184. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118185. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118186. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118187. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118188. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118189. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118190. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118191. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118192. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118193. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118194. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118195. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118196. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118197. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118198. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118199. 0,
  118200. };
  118201. static float _vq_quantthresh__44c5_s_p3_0[] = {
  118202. -1.5, -0.5, 0.5, 1.5,
  118203. };
  118204. static long _vq_quantmap__44c5_s_p3_0[] = {
  118205. 3, 1, 0, 2, 4,
  118206. };
  118207. static encode_aux_threshmatch _vq_auxt__44c5_s_p3_0 = {
  118208. _vq_quantthresh__44c5_s_p3_0,
  118209. _vq_quantmap__44c5_s_p3_0,
  118210. 5,
  118211. 5
  118212. };
  118213. static static_codebook _44c5_s_p3_0 = {
  118214. 4, 625,
  118215. _vq_lengthlist__44c5_s_p3_0,
  118216. 1, -533725184, 1611661312, 3, 0,
  118217. _vq_quantlist__44c5_s_p3_0,
  118218. NULL,
  118219. &_vq_auxt__44c5_s_p3_0,
  118220. NULL,
  118221. 0
  118222. };
  118223. static long _vq_quantlist__44c5_s_p4_0[] = {
  118224. 4,
  118225. 3,
  118226. 5,
  118227. 2,
  118228. 6,
  118229. 1,
  118230. 7,
  118231. 0,
  118232. 8,
  118233. };
  118234. static long _vq_lengthlist__44c5_s_p4_0[] = {
  118235. 2, 3, 3, 6, 6, 0, 0, 0, 0, 0, 4, 4, 6, 6, 0, 0,
  118236. 0, 0, 0, 4, 4, 6, 6, 0, 0, 0, 0, 0, 5, 5, 6, 6,
  118237. 0, 0, 0, 0, 0, 0, 0, 6, 6, 0, 0, 0, 0, 0, 0, 0,
  118238. 7, 7, 0, 0, 0, 0, 0, 0, 0, 8, 7, 0, 0, 0, 0, 0,
  118239. 0, 0, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118240. 0,
  118241. };
  118242. static float _vq_quantthresh__44c5_s_p4_0[] = {
  118243. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  118244. };
  118245. static long _vq_quantmap__44c5_s_p4_0[] = {
  118246. 7, 5, 3, 1, 0, 2, 4, 6,
  118247. 8,
  118248. };
  118249. static encode_aux_threshmatch _vq_auxt__44c5_s_p4_0 = {
  118250. _vq_quantthresh__44c5_s_p4_0,
  118251. _vq_quantmap__44c5_s_p4_0,
  118252. 9,
  118253. 9
  118254. };
  118255. static static_codebook _44c5_s_p4_0 = {
  118256. 2, 81,
  118257. _vq_lengthlist__44c5_s_p4_0,
  118258. 1, -531628032, 1611661312, 4, 0,
  118259. _vq_quantlist__44c5_s_p4_0,
  118260. NULL,
  118261. &_vq_auxt__44c5_s_p4_0,
  118262. NULL,
  118263. 0
  118264. };
  118265. static long _vq_quantlist__44c5_s_p5_0[] = {
  118266. 4,
  118267. 3,
  118268. 5,
  118269. 2,
  118270. 6,
  118271. 1,
  118272. 7,
  118273. 0,
  118274. 8,
  118275. };
  118276. static long _vq_lengthlist__44c5_s_p5_0[] = {
  118277. 2, 4, 3, 6, 6, 7, 7, 9, 9, 0, 4, 4, 6, 6, 7, 7,
  118278. 9, 9, 0, 4, 4, 6, 6, 7, 7, 9, 9, 0, 6, 6, 7, 7,
  118279. 7, 7, 9, 9, 0, 0, 0, 7, 6, 7, 7, 9, 9, 0, 0, 0,
  118280. 8, 8, 8, 8,10,10, 0, 0, 0, 8, 8, 8, 8,10,10, 0,
  118281. 0, 0, 9, 9, 9, 9,10,10, 0, 0, 0, 0, 0, 9, 9,10,
  118282. 10,
  118283. };
  118284. static float _vq_quantthresh__44c5_s_p5_0[] = {
  118285. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  118286. };
  118287. static long _vq_quantmap__44c5_s_p5_0[] = {
  118288. 7, 5, 3, 1, 0, 2, 4, 6,
  118289. 8,
  118290. };
  118291. static encode_aux_threshmatch _vq_auxt__44c5_s_p5_0 = {
  118292. _vq_quantthresh__44c5_s_p5_0,
  118293. _vq_quantmap__44c5_s_p5_0,
  118294. 9,
  118295. 9
  118296. };
  118297. static static_codebook _44c5_s_p5_0 = {
  118298. 2, 81,
  118299. _vq_lengthlist__44c5_s_p5_0,
  118300. 1, -531628032, 1611661312, 4, 0,
  118301. _vq_quantlist__44c5_s_p5_0,
  118302. NULL,
  118303. &_vq_auxt__44c5_s_p5_0,
  118304. NULL,
  118305. 0
  118306. };
  118307. static long _vq_quantlist__44c5_s_p6_0[] = {
  118308. 8,
  118309. 7,
  118310. 9,
  118311. 6,
  118312. 10,
  118313. 5,
  118314. 11,
  118315. 4,
  118316. 12,
  118317. 3,
  118318. 13,
  118319. 2,
  118320. 14,
  118321. 1,
  118322. 15,
  118323. 0,
  118324. 16,
  118325. };
  118326. static long _vq_lengthlist__44c5_s_p6_0[] = {
  118327. 2, 4, 4, 6, 6, 8, 8, 9, 9, 9, 9,10,10,10,10,11,
  118328. 11, 0, 4, 4, 6, 6, 8, 8, 9, 9, 9, 9,10,10,11,11,
  118329. 12,12, 0, 4, 4, 6, 6, 8, 8, 9, 9, 9, 9,10,10,11,
  118330. 11,12,12, 0, 6, 6, 7, 7, 8, 8, 9, 9, 9, 9,10,10,
  118331. 11,11,12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,
  118332. 10,11,11,12,12, 0, 0, 0, 7, 7, 9, 9,10,10,10,10,
  118333. 11,11,11,11,12,12, 0, 0, 0, 7, 7, 8, 9,10,10,10,
  118334. 10,11,11,11,11,12,12, 0, 0, 0, 8, 8, 9, 9,10,10,
  118335. 10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 9, 9,10,
  118336. 10,10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 9, 9,
  118337. 10,10,10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 9,
  118338. 9, 9,10,10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0,
  118339. 10,10,10,10,11,11,11,12,12,12,13,13, 0, 0, 0, 0,
  118340. 0, 0, 0,10,10,11,11,11,11,12,12,13,13, 0, 0, 0,
  118341. 0, 0, 0, 0,11,11,11,11,12,12,12,13,13,13, 0, 0,
  118342. 0, 0, 0, 0, 0,11,11,11,11,12,12,12,12,13,13, 0,
  118343. 0, 0, 0, 0, 0, 0,12,12,12,12,13,12,13,13,13,13,
  118344. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,12,12,13,13,13,
  118345. 13,
  118346. };
  118347. static float _vq_quantthresh__44c5_s_p6_0[] = {
  118348. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  118349. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  118350. };
  118351. static long _vq_quantmap__44c5_s_p6_0[] = {
  118352. 15, 13, 11, 9, 7, 5, 3, 1,
  118353. 0, 2, 4, 6, 8, 10, 12, 14,
  118354. 16,
  118355. };
  118356. static encode_aux_threshmatch _vq_auxt__44c5_s_p6_0 = {
  118357. _vq_quantthresh__44c5_s_p6_0,
  118358. _vq_quantmap__44c5_s_p6_0,
  118359. 17,
  118360. 17
  118361. };
  118362. static static_codebook _44c5_s_p6_0 = {
  118363. 2, 289,
  118364. _vq_lengthlist__44c5_s_p6_0,
  118365. 1, -529530880, 1611661312, 5, 0,
  118366. _vq_quantlist__44c5_s_p6_0,
  118367. NULL,
  118368. &_vq_auxt__44c5_s_p6_0,
  118369. NULL,
  118370. 0
  118371. };
  118372. static long _vq_quantlist__44c5_s_p7_0[] = {
  118373. 1,
  118374. 0,
  118375. 2,
  118376. };
  118377. static long _vq_lengthlist__44c5_s_p7_0[] = {
  118378. 1, 4, 4, 7, 6, 6, 7, 6, 6, 4, 7, 7,10, 9, 9,11,
  118379. 9, 9, 4, 7, 7,10, 9, 9,11, 9, 9, 7,10,10,11,11,
  118380. 10,11,11,11, 6, 9, 9,11,10,10,11,10,10, 6, 9, 9,
  118381. 11,10,10,11,10,10, 7,11,11,12,11,11,12,11,11, 6,
  118382. 9, 9,11,10,10,11,10,10, 6, 9, 9,11,10,10,11,10,
  118383. 10,
  118384. };
  118385. static float _vq_quantthresh__44c5_s_p7_0[] = {
  118386. -5.5, 5.5,
  118387. };
  118388. static long _vq_quantmap__44c5_s_p7_0[] = {
  118389. 1, 0, 2,
  118390. };
  118391. static encode_aux_threshmatch _vq_auxt__44c5_s_p7_0 = {
  118392. _vq_quantthresh__44c5_s_p7_0,
  118393. _vq_quantmap__44c5_s_p7_0,
  118394. 3,
  118395. 3
  118396. };
  118397. static static_codebook _44c5_s_p7_0 = {
  118398. 4, 81,
  118399. _vq_lengthlist__44c5_s_p7_0,
  118400. 1, -529137664, 1618345984, 2, 0,
  118401. _vq_quantlist__44c5_s_p7_0,
  118402. NULL,
  118403. &_vq_auxt__44c5_s_p7_0,
  118404. NULL,
  118405. 0
  118406. };
  118407. static long _vq_quantlist__44c5_s_p7_1[] = {
  118408. 5,
  118409. 4,
  118410. 6,
  118411. 3,
  118412. 7,
  118413. 2,
  118414. 8,
  118415. 1,
  118416. 9,
  118417. 0,
  118418. 10,
  118419. };
  118420. static long _vq_lengthlist__44c5_s_p7_1[] = {
  118421. 2, 4, 4, 6, 6, 7, 7, 8, 8, 8, 8,10, 5, 5, 6, 6,
  118422. 7, 7, 8, 8, 8, 8,10, 5, 5, 6, 6, 7, 7, 8, 8, 8,
  118423. 8,10, 6, 6, 7, 7, 8, 8, 8, 8, 8, 8,10,10,10, 7,
  118424. 7, 8, 8, 8, 8, 8, 8,10,10,10, 7, 7, 8, 8, 8, 8,
  118425. 8, 8,10,10,10, 7, 7, 8, 8, 8, 8, 8, 8,10,10,10,
  118426. 8, 8, 8, 8, 8, 8, 8, 9,10,10,10,10,10, 8, 8, 8,
  118427. 8, 8, 8,10,10,10,10,10, 9, 9, 8, 8, 8, 8,10,10,
  118428. 10,10,10, 8, 8, 8, 8, 8, 8,
  118429. };
  118430. static float _vq_quantthresh__44c5_s_p7_1[] = {
  118431. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  118432. 3.5, 4.5,
  118433. };
  118434. static long _vq_quantmap__44c5_s_p7_1[] = {
  118435. 9, 7, 5, 3, 1, 0, 2, 4,
  118436. 6, 8, 10,
  118437. };
  118438. static encode_aux_threshmatch _vq_auxt__44c5_s_p7_1 = {
  118439. _vq_quantthresh__44c5_s_p7_1,
  118440. _vq_quantmap__44c5_s_p7_1,
  118441. 11,
  118442. 11
  118443. };
  118444. static static_codebook _44c5_s_p7_1 = {
  118445. 2, 121,
  118446. _vq_lengthlist__44c5_s_p7_1,
  118447. 1, -531365888, 1611661312, 4, 0,
  118448. _vq_quantlist__44c5_s_p7_1,
  118449. NULL,
  118450. &_vq_auxt__44c5_s_p7_1,
  118451. NULL,
  118452. 0
  118453. };
  118454. static long _vq_quantlist__44c5_s_p8_0[] = {
  118455. 6,
  118456. 5,
  118457. 7,
  118458. 4,
  118459. 8,
  118460. 3,
  118461. 9,
  118462. 2,
  118463. 10,
  118464. 1,
  118465. 11,
  118466. 0,
  118467. 12,
  118468. };
  118469. static long _vq_lengthlist__44c5_s_p8_0[] = {
  118470. 1, 4, 4, 6, 6, 7, 7, 8, 8, 9, 9,10,10, 6, 5, 5,
  118471. 7, 7, 8, 8, 8, 9,10,10,10,10, 7, 5, 5, 7, 7, 8,
  118472. 8, 9, 9,10,10,10,10, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  118473. 10,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,
  118474. 11, 0,12,12, 9, 9, 9,10,10,10,10,10,11,11, 0,13,
  118475. 13, 9, 9, 9, 9,10,10,11,11,11,11, 0, 0, 0,10,10,
  118476. 10,10,10,10,11,11,11,11, 0, 0, 0,10,10,10,10,10,
  118477. 10,11,11,12,12, 0, 0, 0,14,14,11,11,11,11,12,12,
  118478. 12,12, 0, 0, 0,14,14,11,11,11,11,12,12,12,12, 0,
  118479. 0, 0, 0, 0,12,12,12,12,12,12,13,13, 0, 0, 0, 0,
  118480. 0,12,12,12,12,12,12,13,13,
  118481. };
  118482. static float _vq_quantthresh__44c5_s_p8_0[] = {
  118483. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  118484. 12.5, 17.5, 22.5, 27.5,
  118485. };
  118486. static long _vq_quantmap__44c5_s_p8_0[] = {
  118487. 11, 9, 7, 5, 3, 1, 0, 2,
  118488. 4, 6, 8, 10, 12,
  118489. };
  118490. static encode_aux_threshmatch _vq_auxt__44c5_s_p8_0 = {
  118491. _vq_quantthresh__44c5_s_p8_0,
  118492. _vq_quantmap__44c5_s_p8_0,
  118493. 13,
  118494. 13
  118495. };
  118496. static static_codebook _44c5_s_p8_0 = {
  118497. 2, 169,
  118498. _vq_lengthlist__44c5_s_p8_0,
  118499. 1, -526516224, 1616117760, 4, 0,
  118500. _vq_quantlist__44c5_s_p8_0,
  118501. NULL,
  118502. &_vq_auxt__44c5_s_p8_0,
  118503. NULL,
  118504. 0
  118505. };
  118506. static long _vq_quantlist__44c5_s_p8_1[] = {
  118507. 2,
  118508. 1,
  118509. 3,
  118510. 0,
  118511. 4,
  118512. };
  118513. static long _vq_lengthlist__44c5_s_p8_1[] = {
  118514. 2, 4, 4, 5, 5, 6, 5, 5, 5, 5, 6, 4, 5, 5, 5, 6,
  118515. 5, 5, 5, 5, 6, 6, 6, 5, 5,
  118516. };
  118517. static float _vq_quantthresh__44c5_s_p8_1[] = {
  118518. -1.5, -0.5, 0.5, 1.5,
  118519. };
  118520. static long _vq_quantmap__44c5_s_p8_1[] = {
  118521. 3, 1, 0, 2, 4,
  118522. };
  118523. static encode_aux_threshmatch _vq_auxt__44c5_s_p8_1 = {
  118524. _vq_quantthresh__44c5_s_p8_1,
  118525. _vq_quantmap__44c5_s_p8_1,
  118526. 5,
  118527. 5
  118528. };
  118529. static static_codebook _44c5_s_p8_1 = {
  118530. 2, 25,
  118531. _vq_lengthlist__44c5_s_p8_1,
  118532. 1, -533725184, 1611661312, 3, 0,
  118533. _vq_quantlist__44c5_s_p8_1,
  118534. NULL,
  118535. &_vq_auxt__44c5_s_p8_1,
  118536. NULL,
  118537. 0
  118538. };
  118539. static long _vq_quantlist__44c5_s_p9_0[] = {
  118540. 7,
  118541. 6,
  118542. 8,
  118543. 5,
  118544. 9,
  118545. 4,
  118546. 10,
  118547. 3,
  118548. 11,
  118549. 2,
  118550. 12,
  118551. 1,
  118552. 13,
  118553. 0,
  118554. 14,
  118555. };
  118556. static long _vq_lengthlist__44c5_s_p9_0[] = {
  118557. 1, 3, 3,13,13,13,13,13,13,13,13,13,13,13,13, 4,
  118558. 7, 7,13,13,13,13,13,13,13,13,13,13,13,13, 3, 8,
  118559. 6,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  118560. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  118561. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  118562. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  118563. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  118564. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  118565. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  118566. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  118567. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  118568. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  118569. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  118570. 13,13,13,13,13,13,13,13,13,12,12,12,12,12,12,12,
  118571. 12,
  118572. };
  118573. static float _vq_quantthresh__44c5_s_p9_0[] = {
  118574. -2320.5, -1963.5, -1606.5, -1249.5, -892.5, -535.5, -178.5, 178.5,
  118575. 535.5, 892.5, 1249.5, 1606.5, 1963.5, 2320.5,
  118576. };
  118577. static long _vq_quantmap__44c5_s_p9_0[] = {
  118578. 13, 11, 9, 7, 5, 3, 1, 0,
  118579. 2, 4, 6, 8, 10, 12, 14,
  118580. };
  118581. static encode_aux_threshmatch _vq_auxt__44c5_s_p9_0 = {
  118582. _vq_quantthresh__44c5_s_p9_0,
  118583. _vq_quantmap__44c5_s_p9_0,
  118584. 15,
  118585. 15
  118586. };
  118587. static static_codebook _44c5_s_p9_0 = {
  118588. 2, 225,
  118589. _vq_lengthlist__44c5_s_p9_0,
  118590. 1, -512522752, 1628852224, 4, 0,
  118591. _vq_quantlist__44c5_s_p9_0,
  118592. NULL,
  118593. &_vq_auxt__44c5_s_p9_0,
  118594. NULL,
  118595. 0
  118596. };
  118597. static long _vq_quantlist__44c5_s_p9_1[] = {
  118598. 8,
  118599. 7,
  118600. 9,
  118601. 6,
  118602. 10,
  118603. 5,
  118604. 11,
  118605. 4,
  118606. 12,
  118607. 3,
  118608. 13,
  118609. 2,
  118610. 14,
  118611. 1,
  118612. 15,
  118613. 0,
  118614. 16,
  118615. };
  118616. static long _vq_lengthlist__44c5_s_p9_1[] = {
  118617. 1, 4, 4, 5, 5, 7, 7, 9, 8,10, 9,10,10,11,10,11,
  118618. 11, 6, 5, 5, 7, 7, 8, 9,10,10,11,10,12,11,12,11,
  118619. 13,12, 6, 5, 5, 7, 7, 9, 9,10,10,11,11,12,12,13,
  118620. 12,13,13,18, 8, 8, 8, 8, 9, 9,10,11,11,11,12,11,
  118621. 13,11,13,12,18, 8, 8, 8, 8,10,10,11,11,12,12,13,
  118622. 13,13,13,13,14,18,12,12, 9, 9,11,11,11,11,12,12,
  118623. 13,12,13,12,13,13,20,13,12, 9, 9,11,11,11,11,12,
  118624. 12,13,13,13,14,14,13,20,18,19,11,12,11,11,12,12,
  118625. 13,13,13,13,13,13,14,13,18,19,19,12,11,11,11,12,
  118626. 12,13,12,13,13,13,14,14,13,18,17,19,14,15,12,12,
  118627. 12,13,13,13,14,14,14,14,14,14,19,19,19,16,15,12,
  118628. 11,13,12,14,14,14,13,13,14,14,14,19,18,19,18,19,
  118629. 13,13,13,13,14,14,14,13,14,14,14,14,18,17,19,19,
  118630. 19,13,13,13,11,13,11,13,14,14,14,14,14,19,17,17,
  118631. 18,18,16,16,13,13,13,13,14,13,15,15,14,14,19,19,
  118632. 17,17,18,16,16,13,11,14,10,13,12,14,14,14,14,19,
  118633. 19,19,19,19,18,17,13,14,13,11,14,13,14,14,15,15,
  118634. 19,19,19,17,19,18,18,14,13,12,11,14,11,15,15,15,
  118635. 15,
  118636. };
  118637. static float _vq_quantthresh__44c5_s_p9_1[] = {
  118638. -157.5, -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5,
  118639. 10.5, 31.5, 52.5, 73.5, 94.5, 115.5, 136.5, 157.5,
  118640. };
  118641. static long _vq_quantmap__44c5_s_p9_1[] = {
  118642. 15, 13, 11, 9, 7, 5, 3, 1,
  118643. 0, 2, 4, 6, 8, 10, 12, 14,
  118644. 16,
  118645. };
  118646. static encode_aux_threshmatch _vq_auxt__44c5_s_p9_1 = {
  118647. _vq_quantthresh__44c5_s_p9_1,
  118648. _vq_quantmap__44c5_s_p9_1,
  118649. 17,
  118650. 17
  118651. };
  118652. static static_codebook _44c5_s_p9_1 = {
  118653. 2, 289,
  118654. _vq_lengthlist__44c5_s_p9_1,
  118655. 1, -520814592, 1620377600, 5, 0,
  118656. _vq_quantlist__44c5_s_p9_1,
  118657. NULL,
  118658. &_vq_auxt__44c5_s_p9_1,
  118659. NULL,
  118660. 0
  118661. };
  118662. static long _vq_quantlist__44c5_s_p9_2[] = {
  118663. 10,
  118664. 9,
  118665. 11,
  118666. 8,
  118667. 12,
  118668. 7,
  118669. 13,
  118670. 6,
  118671. 14,
  118672. 5,
  118673. 15,
  118674. 4,
  118675. 16,
  118676. 3,
  118677. 17,
  118678. 2,
  118679. 18,
  118680. 1,
  118681. 19,
  118682. 0,
  118683. 20,
  118684. };
  118685. static long _vq_lengthlist__44c5_s_p9_2[] = {
  118686. 3, 5, 5, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8,
  118687. 8, 8, 8, 8, 9,11, 5, 6, 7, 7, 8, 7, 8, 8, 8, 8,
  118688. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,11, 5, 5, 7, 7, 7,
  118689. 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,11,
  118690. 7, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9,
  118691. 9,10, 9,10,11,11,11, 7, 7, 8, 8, 8, 8, 9, 9, 9,
  118692. 9, 9, 9,10,10,10,10,10,10,11,11,11, 8, 8, 8, 8,
  118693. 9, 9, 9, 9, 9, 9, 9,10,10,10,10,10,10,10,11,11,
  118694. 11, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9,10,10,10,10,10,
  118695. 10,10,10,11,11,11, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  118696. 10,10,10,10,10,10,10,10,11,11,11,11,11, 9, 9, 9,
  118697. 9, 9, 9,10, 9,10,10,10,10,10,10,10,10,11,11,11,
  118698. 11,11, 9, 9, 9, 9, 9, 9,10,10,10,10,10,10,10,10,
  118699. 10,10,11,11,11,11,11, 9, 9, 9, 9, 9, 9,10,10,10,
  118700. 10,10,10,10,10,10,10,11,11,11,11,11, 9, 9,10, 9,
  118701. 10,10,10,10,10,10,10,10,10,10,10,10,11,11,11,11,
  118702. 11,11,11, 9, 9,10,10,10,10,10,10,10,10,10,10,10,
  118703. 10,11,11,11,11,11,11,11,10,10,10,10,10,10,10,10,
  118704. 10,10,10,10,10,10,11,11,11,11,11,11,11,10,10,10,
  118705. 10,10,10,10,10,10,10,10,10,10,10,11,11,11,11,11,
  118706. 11,11,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  118707. 11,11,11,11,11,11,11,11,11,10,10,10,10,10,10,10,
  118708. 10,10,10,10,10,11,11,11,11,11,11,11,11,11,10,10,
  118709. 10,10,10,10,10,10,10,10,10,10,11,11,11,11,11,11,
  118710. 11,11,11,10,10,10,10,10,10,10,10,10,10,10,10,11,
  118711. 11,11,11,11,11,11,11,11,10,10,10,10,10,10,10,10,
  118712. 10,10,10,10,11,11,11,11,11,11,11,11,11,11,11,10,
  118713. 10,10,10,10,10,10,10,10,10,
  118714. };
  118715. static float _vq_quantthresh__44c5_s_p9_2[] = {
  118716. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  118717. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  118718. 6.5, 7.5, 8.5, 9.5,
  118719. };
  118720. static long _vq_quantmap__44c5_s_p9_2[] = {
  118721. 19, 17, 15, 13, 11, 9, 7, 5,
  118722. 3, 1, 0, 2, 4, 6, 8, 10,
  118723. 12, 14, 16, 18, 20,
  118724. };
  118725. static encode_aux_threshmatch _vq_auxt__44c5_s_p9_2 = {
  118726. _vq_quantthresh__44c5_s_p9_2,
  118727. _vq_quantmap__44c5_s_p9_2,
  118728. 21,
  118729. 21
  118730. };
  118731. static static_codebook _44c5_s_p9_2 = {
  118732. 2, 441,
  118733. _vq_lengthlist__44c5_s_p9_2,
  118734. 1, -529268736, 1611661312, 5, 0,
  118735. _vq_quantlist__44c5_s_p9_2,
  118736. NULL,
  118737. &_vq_auxt__44c5_s_p9_2,
  118738. NULL,
  118739. 0
  118740. };
  118741. static long _huff_lengthlist__44c5_s_short[] = {
  118742. 5, 8,10,14,11,11,12,16,15,17, 5, 5, 7, 9, 7, 8,
  118743. 10,13,17,17, 7, 5, 5,10, 5, 7, 8,11,13,15,10, 8,
  118744. 10, 8, 8, 8,11,15,18,18, 8, 5, 5, 8, 3, 4, 6,10,
  118745. 14,16, 9, 7, 6, 7, 4, 3, 5, 9,14,18,10, 9, 8,10,
  118746. 6, 5, 6, 9,14,18,12,12,11,12, 8, 7, 8,11,14,18,
  118747. 14,13,12,10, 7, 5, 6, 9,14,18,14,14,13,10, 6, 5,
  118748. 6, 8,11,16,
  118749. };
  118750. static static_codebook _huff_book__44c5_s_short = {
  118751. 2, 100,
  118752. _huff_lengthlist__44c5_s_short,
  118753. 0, 0, 0, 0, 0,
  118754. NULL,
  118755. NULL,
  118756. NULL,
  118757. NULL,
  118758. 0
  118759. };
  118760. static long _huff_lengthlist__44c6_s_long[] = {
  118761. 3, 8,11,13,14,14,13,13,16,14, 6, 3, 4, 7, 9, 9,
  118762. 10,11,14,13,10, 4, 3, 5, 7, 7, 9,10,13,15,12, 7,
  118763. 4, 4, 6, 6, 8,10,13,15,12, 8, 6, 6, 6, 6, 8,10,
  118764. 13,14,11, 9, 7, 6, 6, 6, 7, 8,12,11,13,10, 9, 8,
  118765. 7, 6, 6, 7,11,11,13,11,10, 9, 9, 7, 7, 6,10,11,
  118766. 13,13,13,13,13,11, 9, 8,10,12,12,15,15,16,15,12,
  118767. 11,10,10,12,
  118768. };
  118769. static static_codebook _huff_book__44c6_s_long = {
  118770. 2, 100,
  118771. _huff_lengthlist__44c6_s_long,
  118772. 0, 0, 0, 0, 0,
  118773. NULL,
  118774. NULL,
  118775. NULL,
  118776. NULL,
  118777. 0
  118778. };
  118779. static long _vq_quantlist__44c6_s_p1_0[] = {
  118780. 1,
  118781. 0,
  118782. 2,
  118783. };
  118784. static long _vq_lengthlist__44c6_s_p1_0[] = {
  118785. 1, 5, 5, 0, 5, 5, 0, 5, 5, 5, 8, 7, 0, 9, 9, 0,
  118786. 9, 8, 5, 7, 8, 0, 9, 9, 0, 8, 9, 0, 0, 0, 0, 0,
  118787. 0, 0, 0, 0, 5, 9, 8, 0, 8, 8, 0, 8, 8, 5, 8, 9,
  118788. 0, 8, 8, 0, 8, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5,
  118789. 9, 9, 0, 8, 8, 0, 8, 8, 5, 9, 9, 0, 8, 8, 0, 8,
  118790. 8,
  118791. };
  118792. static float _vq_quantthresh__44c6_s_p1_0[] = {
  118793. -0.5, 0.5,
  118794. };
  118795. static long _vq_quantmap__44c6_s_p1_0[] = {
  118796. 1, 0, 2,
  118797. };
  118798. static encode_aux_threshmatch _vq_auxt__44c6_s_p1_0 = {
  118799. _vq_quantthresh__44c6_s_p1_0,
  118800. _vq_quantmap__44c6_s_p1_0,
  118801. 3,
  118802. 3
  118803. };
  118804. static static_codebook _44c6_s_p1_0 = {
  118805. 4, 81,
  118806. _vq_lengthlist__44c6_s_p1_0,
  118807. 1, -535822336, 1611661312, 2, 0,
  118808. _vq_quantlist__44c6_s_p1_0,
  118809. NULL,
  118810. &_vq_auxt__44c6_s_p1_0,
  118811. NULL,
  118812. 0
  118813. };
  118814. static long _vq_quantlist__44c6_s_p2_0[] = {
  118815. 2,
  118816. 1,
  118817. 3,
  118818. 0,
  118819. 4,
  118820. };
  118821. static long _vq_lengthlist__44c6_s_p2_0[] = {
  118822. 3, 5, 5, 8, 8, 0, 5, 5, 8, 8, 0, 5, 5, 8, 8, 0,
  118823. 7, 7, 9, 9, 0, 0, 0, 9, 9, 5, 7, 7, 9, 9, 0, 8,
  118824. 8,10,10, 0, 8, 7,10, 9, 0,10,10,11,11, 0, 0, 0,
  118825. 11,11, 5, 7, 7, 9, 9, 0, 8, 8,10,10, 0, 7, 8, 9,
  118826. 10, 0,10,10,11,11, 0, 0, 0,11,11, 8, 9, 9,11,11,
  118827. 0,11,11,12,12, 0,11,10,12,12, 0,13,14,14,14, 0,
  118828. 0, 0,14,13, 8, 9, 9,11,11, 0,11,11,12,12, 0,10,
  118829. 11,12,12, 0,14,13,14,14, 0, 0, 0,13,14, 0, 0, 0,
  118830. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118831. 0, 0, 0, 0, 0, 0, 5, 8, 7,11,10, 0, 7, 7,10,10,
  118832. 0, 7, 7,10,10, 0, 9, 9,11,10, 0, 0, 0,11,11, 5,
  118833. 7, 8,10,11, 0, 7, 7,10,10, 0, 7, 7,10,10, 0, 9,
  118834. 9,10,11, 0, 0, 0,11,11, 8,10, 9,12,12, 0,10,10,
  118835. 12,12, 0,10,10,12,12, 0,12,12,13,13, 0, 0, 0,13,
  118836. 13, 8, 9,10,12,12, 0,10,10,11,12, 0,10,10,12,12,
  118837. 0,12,12,13,13, 0, 0, 0,13,13, 0, 0, 0, 0, 0, 0,
  118838. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118839. 0, 0, 0, 5, 8, 8,11,11, 0, 7, 7,10,10, 0, 7, 7,
  118840. 10,10, 0, 9, 9,10,11, 0, 0, 0,11,10, 5, 8, 8,11,
  118841. 11, 0, 7, 7,10,10, 0, 7, 7,10,10, 0, 9, 9,11,11,
  118842. 0, 0, 0,10,11, 8,10,10,12,12, 0,10,10,12,12, 0,
  118843. 10,10,12,12, 0,12,13,13,13, 0, 0, 0,14,13, 8,10,
  118844. 10,12,12, 0,10,10,12,12, 0,10,10,12,12, 0,13,12,
  118845. 13,13, 0, 0, 0,13,13, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118846. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118847. 7,10,10,14,13, 0, 9, 9,13,12, 0, 9, 9,12,12, 0,
  118848. 10,10,12,12, 0, 0, 0,12,12, 7,10,10,13,14, 0, 9,
  118849. 9,12,13, 0, 9, 9,12,12, 0,10,10,12,12, 0, 0, 0,
  118850. 12,12, 9,11,11,14,13, 0,11,10,14,13, 0,11,11,13,
  118851. 13, 0,12,12,13,13, 0, 0, 0,13,13, 9,11,11,13,14,
  118852. 0,10,11,13,14, 0,11,11,13,13, 0,12,12,13,13, 0,
  118853. 0, 0,13,13, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118854. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118855. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118856. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118857. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9,
  118858. 11,11,14,14, 0,11,11,13,13, 0,11,10,13,13, 0,12,
  118859. 12,13,13, 0, 0, 0,13,13, 9,11,11,14,14, 0,11,11,
  118860. 13,13, 0,10,11,13,13, 0,12,12,14,13, 0, 0, 0,13,
  118861. 13,
  118862. };
  118863. static float _vq_quantthresh__44c6_s_p2_0[] = {
  118864. -1.5, -0.5, 0.5, 1.5,
  118865. };
  118866. static long _vq_quantmap__44c6_s_p2_0[] = {
  118867. 3, 1, 0, 2, 4,
  118868. };
  118869. static encode_aux_threshmatch _vq_auxt__44c6_s_p2_0 = {
  118870. _vq_quantthresh__44c6_s_p2_0,
  118871. _vq_quantmap__44c6_s_p2_0,
  118872. 5,
  118873. 5
  118874. };
  118875. static static_codebook _44c6_s_p2_0 = {
  118876. 4, 625,
  118877. _vq_lengthlist__44c6_s_p2_0,
  118878. 1, -533725184, 1611661312, 3, 0,
  118879. _vq_quantlist__44c6_s_p2_0,
  118880. NULL,
  118881. &_vq_auxt__44c6_s_p2_0,
  118882. NULL,
  118883. 0
  118884. };
  118885. static long _vq_quantlist__44c6_s_p3_0[] = {
  118886. 4,
  118887. 3,
  118888. 5,
  118889. 2,
  118890. 6,
  118891. 1,
  118892. 7,
  118893. 0,
  118894. 8,
  118895. };
  118896. static long _vq_lengthlist__44c6_s_p3_0[] = {
  118897. 2, 3, 4, 6, 6, 7, 7, 9, 9, 0, 4, 4, 6, 6, 7, 7,
  118898. 9,10, 0, 4, 4, 6, 6, 7, 7,10, 9, 0, 5, 5, 7, 7,
  118899. 8, 8,10,10, 0, 0, 0, 7, 6, 8, 8,10,10, 0, 0, 0,
  118900. 7, 7, 9, 9,11,11, 0, 0, 0, 7, 7, 9, 9,11,11, 0,
  118901. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118902. 0,
  118903. };
  118904. static float _vq_quantthresh__44c6_s_p3_0[] = {
  118905. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  118906. };
  118907. static long _vq_quantmap__44c6_s_p3_0[] = {
  118908. 7, 5, 3, 1, 0, 2, 4, 6,
  118909. 8,
  118910. };
  118911. static encode_aux_threshmatch _vq_auxt__44c6_s_p3_0 = {
  118912. _vq_quantthresh__44c6_s_p3_0,
  118913. _vq_quantmap__44c6_s_p3_0,
  118914. 9,
  118915. 9
  118916. };
  118917. static static_codebook _44c6_s_p3_0 = {
  118918. 2, 81,
  118919. _vq_lengthlist__44c6_s_p3_0,
  118920. 1, -531628032, 1611661312, 4, 0,
  118921. _vq_quantlist__44c6_s_p3_0,
  118922. NULL,
  118923. &_vq_auxt__44c6_s_p3_0,
  118924. NULL,
  118925. 0
  118926. };
  118927. static long _vq_quantlist__44c6_s_p4_0[] = {
  118928. 8,
  118929. 7,
  118930. 9,
  118931. 6,
  118932. 10,
  118933. 5,
  118934. 11,
  118935. 4,
  118936. 12,
  118937. 3,
  118938. 13,
  118939. 2,
  118940. 14,
  118941. 1,
  118942. 15,
  118943. 0,
  118944. 16,
  118945. };
  118946. static long _vq_lengthlist__44c6_s_p4_0[] = {
  118947. 2, 4, 4, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9, 9,10,10,
  118948. 10, 0, 4, 4, 6, 6, 8, 8, 9, 9, 9, 9,10,10,10,10,
  118949. 11,11, 0, 4, 4, 6, 6, 8, 8, 9, 9, 9, 9,10,10,10,
  118950. 10,11,11, 0, 6, 6, 7, 7, 8, 8, 9, 9, 9, 9,10,10,
  118951. 11,11,11,11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,
  118952. 10,11,11,11,11, 0, 0, 0, 7, 7, 9, 9,10,10,10,10,
  118953. 11,11,11,11,12,12, 0, 0, 0, 7, 7, 9, 9,10,10,10,
  118954. 10,11,11,11,11,12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9,
  118955. 10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 8, 8, 9,
  118956. 9,10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 0, 0,
  118957. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118958. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118959. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118960. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118961. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118962. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118963. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118964. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118965. 0,
  118966. };
  118967. static float _vq_quantthresh__44c6_s_p4_0[] = {
  118968. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  118969. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  118970. };
  118971. static long _vq_quantmap__44c6_s_p4_0[] = {
  118972. 15, 13, 11, 9, 7, 5, 3, 1,
  118973. 0, 2, 4, 6, 8, 10, 12, 14,
  118974. 16,
  118975. };
  118976. static encode_aux_threshmatch _vq_auxt__44c6_s_p4_0 = {
  118977. _vq_quantthresh__44c6_s_p4_0,
  118978. _vq_quantmap__44c6_s_p4_0,
  118979. 17,
  118980. 17
  118981. };
  118982. static static_codebook _44c6_s_p4_0 = {
  118983. 2, 289,
  118984. _vq_lengthlist__44c6_s_p4_0,
  118985. 1, -529530880, 1611661312, 5, 0,
  118986. _vq_quantlist__44c6_s_p4_0,
  118987. NULL,
  118988. &_vq_auxt__44c6_s_p4_0,
  118989. NULL,
  118990. 0
  118991. };
  118992. static long _vq_quantlist__44c6_s_p5_0[] = {
  118993. 1,
  118994. 0,
  118995. 2,
  118996. };
  118997. static long _vq_lengthlist__44c6_s_p5_0[] = {
  118998. 1, 4, 4, 5, 7, 7, 6, 7, 7, 4, 6, 6, 9, 9,10,10,
  118999. 10, 9, 4, 6, 6, 9,10, 9,10, 9,10, 6, 9, 9,10,12,
  119000. 11,10,11,11, 7,10, 9,11,12,12,12,12,12, 7,10,10,
  119001. 11,12,12,12,12,12, 6,10,10,10,12,12,11,12,12, 7,
  119002. 9,10,11,12,12,12,12,12, 7,10, 9,12,12,12,12,12,
  119003. 12,
  119004. };
  119005. static float _vq_quantthresh__44c6_s_p5_0[] = {
  119006. -5.5, 5.5,
  119007. };
  119008. static long _vq_quantmap__44c6_s_p5_0[] = {
  119009. 1, 0, 2,
  119010. };
  119011. static encode_aux_threshmatch _vq_auxt__44c6_s_p5_0 = {
  119012. _vq_quantthresh__44c6_s_p5_0,
  119013. _vq_quantmap__44c6_s_p5_0,
  119014. 3,
  119015. 3
  119016. };
  119017. static static_codebook _44c6_s_p5_0 = {
  119018. 4, 81,
  119019. _vq_lengthlist__44c6_s_p5_0,
  119020. 1, -529137664, 1618345984, 2, 0,
  119021. _vq_quantlist__44c6_s_p5_0,
  119022. NULL,
  119023. &_vq_auxt__44c6_s_p5_0,
  119024. NULL,
  119025. 0
  119026. };
  119027. static long _vq_quantlist__44c6_s_p5_1[] = {
  119028. 5,
  119029. 4,
  119030. 6,
  119031. 3,
  119032. 7,
  119033. 2,
  119034. 8,
  119035. 1,
  119036. 9,
  119037. 0,
  119038. 10,
  119039. };
  119040. static long _vq_lengthlist__44c6_s_p5_1[] = {
  119041. 3, 5, 4, 6, 6, 7, 7, 8, 8, 8, 8,11, 4, 4, 6, 6,
  119042. 7, 7, 8, 8, 8, 8,11, 4, 4, 6, 6, 7, 7, 8, 8, 8,
  119043. 8,11, 6, 6, 6, 6, 8, 8, 8, 8, 9, 9,11,11,11, 6,
  119044. 6, 7, 8, 8, 8, 8, 9,11,11,11, 7, 7, 8, 8, 8, 8,
  119045. 8, 8,11,11,11, 7, 7, 8, 8, 8, 8, 8, 8,11,11,11,
  119046. 8, 8, 8, 8, 8, 8, 8, 8,11,11,11,10,10, 8, 8, 8,
  119047. 8, 8, 8,11,11,11,10,10, 8, 8, 8, 8, 8, 8,11,11,
  119048. 11,10,10, 7, 7, 8, 8, 8, 8,
  119049. };
  119050. static float _vq_quantthresh__44c6_s_p5_1[] = {
  119051. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  119052. 3.5, 4.5,
  119053. };
  119054. static long _vq_quantmap__44c6_s_p5_1[] = {
  119055. 9, 7, 5, 3, 1, 0, 2, 4,
  119056. 6, 8, 10,
  119057. };
  119058. static encode_aux_threshmatch _vq_auxt__44c6_s_p5_1 = {
  119059. _vq_quantthresh__44c6_s_p5_1,
  119060. _vq_quantmap__44c6_s_p5_1,
  119061. 11,
  119062. 11
  119063. };
  119064. static static_codebook _44c6_s_p5_1 = {
  119065. 2, 121,
  119066. _vq_lengthlist__44c6_s_p5_1,
  119067. 1, -531365888, 1611661312, 4, 0,
  119068. _vq_quantlist__44c6_s_p5_1,
  119069. NULL,
  119070. &_vq_auxt__44c6_s_p5_1,
  119071. NULL,
  119072. 0
  119073. };
  119074. static long _vq_quantlist__44c6_s_p6_0[] = {
  119075. 6,
  119076. 5,
  119077. 7,
  119078. 4,
  119079. 8,
  119080. 3,
  119081. 9,
  119082. 2,
  119083. 10,
  119084. 1,
  119085. 11,
  119086. 0,
  119087. 12,
  119088. };
  119089. static long _vq_lengthlist__44c6_s_p6_0[] = {
  119090. 1, 4, 4, 6, 6, 8, 8, 8, 8,10, 9,10,10, 6, 5, 5,
  119091. 7, 7, 9, 9, 9, 9,10,10,11,11, 6, 5, 5, 7, 7, 9,
  119092. 9,10, 9,11,10,11,11, 0, 6, 6, 7, 7, 9, 9,10,10,
  119093. 11,11,12,12, 0, 7, 7, 7, 7, 9, 9,10,10,11,11,12,
  119094. 12, 0,11,11, 8, 8,10,10,11,11,12,12,12,12, 0,11,
  119095. 12, 9, 8,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0,
  119096. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119097. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119098. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119099. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119100. 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119101. };
  119102. static float _vq_quantthresh__44c6_s_p6_0[] = {
  119103. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  119104. 12.5, 17.5, 22.5, 27.5,
  119105. };
  119106. static long _vq_quantmap__44c6_s_p6_0[] = {
  119107. 11, 9, 7, 5, 3, 1, 0, 2,
  119108. 4, 6, 8, 10, 12,
  119109. };
  119110. static encode_aux_threshmatch _vq_auxt__44c6_s_p6_0 = {
  119111. _vq_quantthresh__44c6_s_p6_0,
  119112. _vq_quantmap__44c6_s_p6_0,
  119113. 13,
  119114. 13
  119115. };
  119116. static static_codebook _44c6_s_p6_0 = {
  119117. 2, 169,
  119118. _vq_lengthlist__44c6_s_p6_0,
  119119. 1, -526516224, 1616117760, 4, 0,
  119120. _vq_quantlist__44c6_s_p6_0,
  119121. NULL,
  119122. &_vq_auxt__44c6_s_p6_0,
  119123. NULL,
  119124. 0
  119125. };
  119126. static long _vq_quantlist__44c6_s_p6_1[] = {
  119127. 2,
  119128. 1,
  119129. 3,
  119130. 0,
  119131. 4,
  119132. };
  119133. static long _vq_lengthlist__44c6_s_p6_1[] = {
  119134. 3, 4, 4, 5, 5, 5, 4, 4, 5, 5, 5, 4, 4, 5, 5, 6,
  119135. 5, 5, 5, 5, 6, 6, 6, 5, 5,
  119136. };
  119137. static float _vq_quantthresh__44c6_s_p6_1[] = {
  119138. -1.5, -0.5, 0.5, 1.5,
  119139. };
  119140. static long _vq_quantmap__44c6_s_p6_1[] = {
  119141. 3, 1, 0, 2, 4,
  119142. };
  119143. static encode_aux_threshmatch _vq_auxt__44c6_s_p6_1 = {
  119144. _vq_quantthresh__44c6_s_p6_1,
  119145. _vq_quantmap__44c6_s_p6_1,
  119146. 5,
  119147. 5
  119148. };
  119149. static static_codebook _44c6_s_p6_1 = {
  119150. 2, 25,
  119151. _vq_lengthlist__44c6_s_p6_1,
  119152. 1, -533725184, 1611661312, 3, 0,
  119153. _vq_quantlist__44c6_s_p6_1,
  119154. NULL,
  119155. &_vq_auxt__44c6_s_p6_1,
  119156. NULL,
  119157. 0
  119158. };
  119159. static long _vq_quantlist__44c6_s_p7_0[] = {
  119160. 6,
  119161. 5,
  119162. 7,
  119163. 4,
  119164. 8,
  119165. 3,
  119166. 9,
  119167. 2,
  119168. 10,
  119169. 1,
  119170. 11,
  119171. 0,
  119172. 12,
  119173. };
  119174. static long _vq_lengthlist__44c6_s_p7_0[] = {
  119175. 1, 4, 4, 6, 6, 8, 8, 8, 8,10,10,11,10, 6, 5, 5,
  119176. 7, 7, 8, 8, 9, 9,10,10,12,11, 6, 5, 5, 7, 7, 8,
  119177. 8, 9, 9,10,10,12,11,21, 7, 7, 7, 7, 9, 9,10,10,
  119178. 11,11,12,12,21, 7, 7, 7, 7, 9, 9,10,10,11,11,12,
  119179. 12,21,12,12, 9, 9,10,10,11,11,11,11,12,12,21,12,
  119180. 12, 9, 9,10,10,11,11,12,12,12,12,21,21,21,11,11,
  119181. 10,10,11,12,12,12,13,13,21,21,21,11,11,10,10,12,
  119182. 12,12,12,13,13,21,21,21,15,15,11,11,12,12,13,13,
  119183. 13,13,21,21,21,15,16,11,11,12,12,13,13,14,14,21,
  119184. 21,21,21,20,13,13,13,13,13,13,14,14,20,20,20,20,
  119185. 20,13,13,13,13,13,13,14,14,
  119186. };
  119187. static float _vq_quantthresh__44c6_s_p7_0[] = {
  119188. -60.5, -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5,
  119189. 27.5, 38.5, 49.5, 60.5,
  119190. };
  119191. static long _vq_quantmap__44c6_s_p7_0[] = {
  119192. 11, 9, 7, 5, 3, 1, 0, 2,
  119193. 4, 6, 8, 10, 12,
  119194. };
  119195. static encode_aux_threshmatch _vq_auxt__44c6_s_p7_0 = {
  119196. _vq_quantthresh__44c6_s_p7_0,
  119197. _vq_quantmap__44c6_s_p7_0,
  119198. 13,
  119199. 13
  119200. };
  119201. static static_codebook _44c6_s_p7_0 = {
  119202. 2, 169,
  119203. _vq_lengthlist__44c6_s_p7_0,
  119204. 1, -523206656, 1618345984, 4, 0,
  119205. _vq_quantlist__44c6_s_p7_0,
  119206. NULL,
  119207. &_vq_auxt__44c6_s_p7_0,
  119208. NULL,
  119209. 0
  119210. };
  119211. static long _vq_quantlist__44c6_s_p7_1[] = {
  119212. 5,
  119213. 4,
  119214. 6,
  119215. 3,
  119216. 7,
  119217. 2,
  119218. 8,
  119219. 1,
  119220. 9,
  119221. 0,
  119222. 10,
  119223. };
  119224. static long _vq_lengthlist__44c6_s_p7_1[] = {
  119225. 3, 5, 5, 6, 6, 7, 7, 7, 7, 7, 7, 9, 5, 5, 6, 6,
  119226. 7, 7, 7, 7, 8, 7, 8, 5, 5, 6, 6, 7, 7, 7, 7, 7,
  119227. 7, 9, 6, 6, 7, 7, 7, 7, 8, 7, 7, 8, 9, 9, 9, 7,
  119228. 7, 7, 7, 7, 7, 7, 8, 9, 9, 9, 7, 7, 7, 7, 8, 8,
  119229. 8, 8, 9, 9, 9, 7, 7, 7, 7, 7, 7, 8, 8, 9, 9, 9,
  119230. 8, 8, 8, 8, 7, 7, 8, 8, 9, 9, 9, 9, 8, 8, 8, 7,
  119231. 7, 8, 8, 9, 9, 9, 8, 8, 8, 8, 7, 7, 8, 8, 9, 9,
  119232. 9, 8, 8, 7, 7, 7, 7, 8, 8,
  119233. };
  119234. static float _vq_quantthresh__44c6_s_p7_1[] = {
  119235. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  119236. 3.5, 4.5,
  119237. };
  119238. static long _vq_quantmap__44c6_s_p7_1[] = {
  119239. 9, 7, 5, 3, 1, 0, 2, 4,
  119240. 6, 8, 10,
  119241. };
  119242. static encode_aux_threshmatch _vq_auxt__44c6_s_p7_1 = {
  119243. _vq_quantthresh__44c6_s_p7_1,
  119244. _vq_quantmap__44c6_s_p7_1,
  119245. 11,
  119246. 11
  119247. };
  119248. static static_codebook _44c6_s_p7_1 = {
  119249. 2, 121,
  119250. _vq_lengthlist__44c6_s_p7_1,
  119251. 1, -531365888, 1611661312, 4, 0,
  119252. _vq_quantlist__44c6_s_p7_1,
  119253. NULL,
  119254. &_vq_auxt__44c6_s_p7_1,
  119255. NULL,
  119256. 0
  119257. };
  119258. static long _vq_quantlist__44c6_s_p8_0[] = {
  119259. 7,
  119260. 6,
  119261. 8,
  119262. 5,
  119263. 9,
  119264. 4,
  119265. 10,
  119266. 3,
  119267. 11,
  119268. 2,
  119269. 12,
  119270. 1,
  119271. 13,
  119272. 0,
  119273. 14,
  119274. };
  119275. static long _vq_lengthlist__44c6_s_p8_0[] = {
  119276. 1, 4, 4, 7, 7, 8, 8, 7, 7, 8, 7, 9, 8,10, 9, 6,
  119277. 5, 5, 8, 8, 9, 9, 8, 8, 9, 9,11,10,11,10, 6, 5,
  119278. 5, 8, 8, 9, 9, 8, 8, 9, 9,10,10,11,11,18, 8, 8,
  119279. 9, 8,10,10, 9, 9,10,10,10,10,11,10,18, 8, 8, 9,
  119280. 9,10,10, 9, 9,10,10,11,11,12,12,18,12,13, 9,10,
  119281. 10,10, 9,10,10,10,11,11,12,11,18,13,13, 9, 9,10,
  119282. 10,10,10,10,10,11,11,12,12,18,18,18,10,10, 9, 9,
  119283. 11,11,11,11,11,12,12,12,18,18,18,10, 9,10, 9,11,
  119284. 10,11,11,11,11,13,12,18,18,18,14,13,10,10,11,11,
  119285. 12,12,12,12,12,12,18,18,18,14,13,10,10,11,10,12,
  119286. 12,12,12,12,12,18,18,18,18,18,12,12,11,11,12,12,
  119287. 13,13,13,14,18,18,18,18,18,12,12,11,11,12,11,13,
  119288. 13,14,13,18,18,18,18,18,16,16,11,12,12,13,13,13,
  119289. 14,13,18,18,18,18,18,16,15,12,11,12,11,13,11,15,
  119290. 14,
  119291. };
  119292. static float _vq_quantthresh__44c6_s_p8_0[] = {
  119293. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  119294. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  119295. };
  119296. static long _vq_quantmap__44c6_s_p8_0[] = {
  119297. 13, 11, 9, 7, 5, 3, 1, 0,
  119298. 2, 4, 6, 8, 10, 12, 14,
  119299. };
  119300. static encode_aux_threshmatch _vq_auxt__44c6_s_p8_0 = {
  119301. _vq_quantthresh__44c6_s_p8_0,
  119302. _vq_quantmap__44c6_s_p8_0,
  119303. 15,
  119304. 15
  119305. };
  119306. static static_codebook _44c6_s_p8_0 = {
  119307. 2, 225,
  119308. _vq_lengthlist__44c6_s_p8_0,
  119309. 1, -520986624, 1620377600, 4, 0,
  119310. _vq_quantlist__44c6_s_p8_0,
  119311. NULL,
  119312. &_vq_auxt__44c6_s_p8_0,
  119313. NULL,
  119314. 0
  119315. };
  119316. static long _vq_quantlist__44c6_s_p8_1[] = {
  119317. 10,
  119318. 9,
  119319. 11,
  119320. 8,
  119321. 12,
  119322. 7,
  119323. 13,
  119324. 6,
  119325. 14,
  119326. 5,
  119327. 15,
  119328. 4,
  119329. 16,
  119330. 3,
  119331. 17,
  119332. 2,
  119333. 18,
  119334. 1,
  119335. 19,
  119336. 0,
  119337. 20,
  119338. };
  119339. static long _vq_lengthlist__44c6_s_p8_1[] = {
  119340. 3, 5, 5, 6, 6, 7, 7, 7, 7, 8, 7, 8, 8, 8, 8, 8,
  119341. 8, 8, 8, 8, 8,10, 6, 6, 7, 7, 8, 8, 8, 8, 8, 8,
  119342. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10, 6, 6, 7, 7, 8,
  119343. 8, 8, 8, 8, 8, 9, 8, 9, 9, 9, 9, 9, 9, 9, 9,10,
  119344. 7, 7, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  119345. 9, 9, 9, 9,10,11,11, 8, 7, 8, 8, 8, 9, 9, 9, 9,
  119346. 9, 9, 9, 9, 9, 9, 9, 9, 9,11,11,11, 8, 8, 8, 8,
  119347. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,11,11,
  119348. 11, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  119349. 9, 9, 9,11,11,11, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  119350. 9, 9, 9, 9, 9, 9, 9, 9,11,11,11,11,11, 9, 9, 9,
  119351. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10, 9,11,11,11,
  119352. 11,11, 9, 9, 9, 9, 9, 9,10, 9, 9,10, 9,10, 9, 9,
  119353. 10, 9,11,11,11,11,11, 9, 9, 9, 9, 9, 9, 9,10,10,
  119354. 10,10, 9,10,10, 9,10,11,11,11,11,11, 9, 9, 9, 9,
  119355. 10,10,10, 9,10,10,10,10, 9,10,10, 9,11,11,11,11,
  119356. 11,11,11, 9, 9, 9, 9,10,10,10,10, 9,10,10,10,10,
  119357. 10,11,11,11,11,11,11,11,10, 9,10,10,10,10,10,10,
  119358. 10, 9,10, 9,10,10,11,11,11,11,11,11,11,10, 9,10,
  119359. 9,10,10, 9,10,10,10,10,10,10,10,11,11,11,11,11,
  119360. 11,11,10,10,10,10,10,10,10, 9,10,10,10,10,10, 9,
  119361. 11,11,11,11,11,11,11,11,11,10,10,10,10,10,10,10,
  119362. 10,10,10,10,10,11,11,11,11,11,11,11,11,11,10,10,
  119363. 10,10,10,10,10,10,10,10,10,10,11,11,11,11,11,11,
  119364. 11,11,11,10,10,10,10,10,10,10,10,10, 9,10,10,11,
  119365. 11,11,11,11,11,11,11,11,10,10,10, 9,10,10,10,10,
  119366. 10,10,10,10,10,11,11,11,11,11,11,11,11,10,11, 9,
  119367. 10,10,10,10,10,10,10,10,10,
  119368. };
  119369. static float _vq_quantthresh__44c6_s_p8_1[] = {
  119370. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  119371. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  119372. 6.5, 7.5, 8.5, 9.5,
  119373. };
  119374. static long _vq_quantmap__44c6_s_p8_1[] = {
  119375. 19, 17, 15, 13, 11, 9, 7, 5,
  119376. 3, 1, 0, 2, 4, 6, 8, 10,
  119377. 12, 14, 16, 18, 20,
  119378. };
  119379. static encode_aux_threshmatch _vq_auxt__44c6_s_p8_1 = {
  119380. _vq_quantthresh__44c6_s_p8_1,
  119381. _vq_quantmap__44c6_s_p8_1,
  119382. 21,
  119383. 21
  119384. };
  119385. static static_codebook _44c6_s_p8_1 = {
  119386. 2, 441,
  119387. _vq_lengthlist__44c6_s_p8_1,
  119388. 1, -529268736, 1611661312, 5, 0,
  119389. _vq_quantlist__44c6_s_p8_1,
  119390. NULL,
  119391. &_vq_auxt__44c6_s_p8_1,
  119392. NULL,
  119393. 0
  119394. };
  119395. static long _vq_quantlist__44c6_s_p9_0[] = {
  119396. 6,
  119397. 5,
  119398. 7,
  119399. 4,
  119400. 8,
  119401. 3,
  119402. 9,
  119403. 2,
  119404. 10,
  119405. 1,
  119406. 11,
  119407. 0,
  119408. 12,
  119409. };
  119410. static long _vq_lengthlist__44c6_s_p9_0[] = {
  119411. 1, 3, 3,11,11,11,11,11,11,11,11,11,11, 4, 7, 7,
  119412. 11,11,11,11,11,11,11,11,11,11, 5, 8, 9,11,11,11,
  119413. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  119414. 11,11,11,11,11,10,10,10,10,10,10,10,10,10,10,10,
  119415. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  119416. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  119417. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  119418. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  119419. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  119420. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  119421. 10,10,10,10,10,10,10,10,10,
  119422. };
  119423. static float _vq_quantthresh__44c6_s_p9_0[] = {
  119424. -3503.5, -2866.5, -2229.5, -1592.5, -955.5, -318.5, 318.5, 955.5,
  119425. 1592.5, 2229.5, 2866.5, 3503.5,
  119426. };
  119427. static long _vq_quantmap__44c6_s_p9_0[] = {
  119428. 11, 9, 7, 5, 3, 1, 0, 2,
  119429. 4, 6, 8, 10, 12,
  119430. };
  119431. static encode_aux_threshmatch _vq_auxt__44c6_s_p9_0 = {
  119432. _vq_quantthresh__44c6_s_p9_0,
  119433. _vq_quantmap__44c6_s_p9_0,
  119434. 13,
  119435. 13
  119436. };
  119437. static static_codebook _44c6_s_p9_0 = {
  119438. 2, 169,
  119439. _vq_lengthlist__44c6_s_p9_0,
  119440. 1, -511845376, 1630791680, 4, 0,
  119441. _vq_quantlist__44c6_s_p9_0,
  119442. NULL,
  119443. &_vq_auxt__44c6_s_p9_0,
  119444. NULL,
  119445. 0
  119446. };
  119447. static long _vq_quantlist__44c6_s_p9_1[] = {
  119448. 6,
  119449. 5,
  119450. 7,
  119451. 4,
  119452. 8,
  119453. 3,
  119454. 9,
  119455. 2,
  119456. 10,
  119457. 1,
  119458. 11,
  119459. 0,
  119460. 12,
  119461. };
  119462. static long _vq_lengthlist__44c6_s_p9_1[] = {
  119463. 1, 4, 4, 7, 7, 7, 7, 7, 6, 8, 8, 8, 8, 6, 6, 6,
  119464. 8, 8, 8, 8, 8, 7, 9, 8,10,10, 5, 6, 6, 8, 8, 9,
  119465. 9, 8, 8,10,10,10,10,16, 9, 9, 9, 9, 9, 9, 9, 8,
  119466. 10, 9,11,11,16, 8, 9, 9, 9, 9, 9, 9, 9,10,10,11,
  119467. 11,16,13,13, 9, 9,10, 9, 9,10,11,11,11,12,16,13,
  119468. 14, 9, 8,10, 8, 9, 9,10,10,12,11,16,14,16, 9, 9,
  119469. 9, 9,11,11,12,11,12,11,16,16,16, 9, 7, 9, 6,11,
  119470. 11,11,10,11,11,16,16,16,11,12, 9,10,11,11,12,11,
  119471. 13,13,16,16,16,12,11,10, 7,12,10,12,12,12,12,16,
  119472. 16,15,16,16,10,11,10,11,13,13,14,12,16,16,16,15,
  119473. 15,12,10,11,11,13,11,12,13,
  119474. };
  119475. static float _vq_quantthresh__44c6_s_p9_1[] = {
  119476. -269.5, -220.5, -171.5, -122.5, -73.5, -24.5, 24.5, 73.5,
  119477. 122.5, 171.5, 220.5, 269.5,
  119478. };
  119479. static long _vq_quantmap__44c6_s_p9_1[] = {
  119480. 11, 9, 7, 5, 3, 1, 0, 2,
  119481. 4, 6, 8, 10, 12,
  119482. };
  119483. static encode_aux_threshmatch _vq_auxt__44c6_s_p9_1 = {
  119484. _vq_quantthresh__44c6_s_p9_1,
  119485. _vq_quantmap__44c6_s_p9_1,
  119486. 13,
  119487. 13
  119488. };
  119489. static static_codebook _44c6_s_p9_1 = {
  119490. 2, 169,
  119491. _vq_lengthlist__44c6_s_p9_1,
  119492. 1, -518889472, 1622704128, 4, 0,
  119493. _vq_quantlist__44c6_s_p9_1,
  119494. NULL,
  119495. &_vq_auxt__44c6_s_p9_1,
  119496. NULL,
  119497. 0
  119498. };
  119499. static long _vq_quantlist__44c6_s_p9_2[] = {
  119500. 24,
  119501. 23,
  119502. 25,
  119503. 22,
  119504. 26,
  119505. 21,
  119506. 27,
  119507. 20,
  119508. 28,
  119509. 19,
  119510. 29,
  119511. 18,
  119512. 30,
  119513. 17,
  119514. 31,
  119515. 16,
  119516. 32,
  119517. 15,
  119518. 33,
  119519. 14,
  119520. 34,
  119521. 13,
  119522. 35,
  119523. 12,
  119524. 36,
  119525. 11,
  119526. 37,
  119527. 10,
  119528. 38,
  119529. 9,
  119530. 39,
  119531. 8,
  119532. 40,
  119533. 7,
  119534. 41,
  119535. 6,
  119536. 42,
  119537. 5,
  119538. 43,
  119539. 4,
  119540. 44,
  119541. 3,
  119542. 45,
  119543. 2,
  119544. 46,
  119545. 1,
  119546. 47,
  119547. 0,
  119548. 48,
  119549. };
  119550. static long _vq_lengthlist__44c6_s_p9_2[] = {
  119551. 2, 4, 3, 4, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6, 6,
  119552. 6, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  119553. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  119554. 7,
  119555. };
  119556. static float _vq_quantthresh__44c6_s_p9_2[] = {
  119557. -23.5, -22.5, -21.5, -20.5, -19.5, -18.5, -17.5, -16.5,
  119558. -15.5, -14.5, -13.5, -12.5, -11.5, -10.5, -9.5, -8.5,
  119559. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  119560. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  119561. 8.5, 9.5, 10.5, 11.5, 12.5, 13.5, 14.5, 15.5,
  119562. 16.5, 17.5, 18.5, 19.5, 20.5, 21.5, 22.5, 23.5,
  119563. };
  119564. static long _vq_quantmap__44c6_s_p9_2[] = {
  119565. 47, 45, 43, 41, 39, 37, 35, 33,
  119566. 31, 29, 27, 25, 23, 21, 19, 17,
  119567. 15, 13, 11, 9, 7, 5, 3, 1,
  119568. 0, 2, 4, 6, 8, 10, 12, 14,
  119569. 16, 18, 20, 22, 24, 26, 28, 30,
  119570. 32, 34, 36, 38, 40, 42, 44, 46,
  119571. 48,
  119572. };
  119573. static encode_aux_threshmatch _vq_auxt__44c6_s_p9_2 = {
  119574. _vq_quantthresh__44c6_s_p9_2,
  119575. _vq_quantmap__44c6_s_p9_2,
  119576. 49,
  119577. 49
  119578. };
  119579. static static_codebook _44c6_s_p9_2 = {
  119580. 1, 49,
  119581. _vq_lengthlist__44c6_s_p9_2,
  119582. 1, -526909440, 1611661312, 6, 0,
  119583. _vq_quantlist__44c6_s_p9_2,
  119584. NULL,
  119585. &_vq_auxt__44c6_s_p9_2,
  119586. NULL,
  119587. 0
  119588. };
  119589. static long _huff_lengthlist__44c6_s_short[] = {
  119590. 3, 9,11,11,13,14,19,17,17,19, 5, 4, 5, 8,10,10,
  119591. 13,16,18,19, 7, 4, 4, 5, 8, 9,12,14,17,19, 8, 6,
  119592. 5, 5, 7, 7,10,13,16,18,10, 8, 7, 6, 5, 5, 8,11,
  119593. 17,19,11, 9, 7, 7, 5, 4, 5, 8,17,19,13,11, 8, 7,
  119594. 7, 5, 5, 7,16,18,14,13, 8, 6, 6, 5, 5, 7,16,18,
  119595. 18,16,10, 8, 8, 7, 7, 9,16,18,18,18,12,10,10, 9,
  119596. 9,10,17,18,
  119597. };
  119598. static static_codebook _huff_book__44c6_s_short = {
  119599. 2, 100,
  119600. _huff_lengthlist__44c6_s_short,
  119601. 0, 0, 0, 0, 0,
  119602. NULL,
  119603. NULL,
  119604. NULL,
  119605. NULL,
  119606. 0
  119607. };
  119608. static long _huff_lengthlist__44c7_s_long[] = {
  119609. 3, 8,11,13,15,14,14,13,15,14, 6, 4, 5, 7, 9,10,
  119610. 11,11,14,13,10, 4, 3, 5, 7, 8, 9,10,13,13,12, 7,
  119611. 4, 4, 5, 6, 8, 9,12,14,13, 9, 6, 5, 5, 6, 8, 9,
  119612. 12,14,12, 9, 7, 6, 5, 5, 6, 8,11,11,12,11, 9, 8,
  119613. 7, 6, 6, 7,10,11,13,11,10, 9, 8, 7, 6, 6, 9,11,
  119614. 13,13,12,12,12,10, 9, 8, 9,11,12,14,15,15,14,12,
  119615. 11,10,10,12,
  119616. };
  119617. static static_codebook _huff_book__44c7_s_long = {
  119618. 2, 100,
  119619. _huff_lengthlist__44c7_s_long,
  119620. 0, 0, 0, 0, 0,
  119621. NULL,
  119622. NULL,
  119623. NULL,
  119624. NULL,
  119625. 0
  119626. };
  119627. static long _vq_quantlist__44c7_s_p1_0[] = {
  119628. 1,
  119629. 0,
  119630. 2,
  119631. };
  119632. static long _vq_lengthlist__44c7_s_p1_0[] = {
  119633. 1, 5, 5, 0, 5, 5, 0, 5, 5, 5, 8, 7, 0, 9, 9, 0,
  119634. 9, 8, 5, 7, 8, 0, 9, 9, 0, 8, 9, 0, 0, 0, 0, 0,
  119635. 0, 0, 0, 0, 5, 9, 9, 0, 8, 8, 0, 8, 8, 5, 8, 9,
  119636. 0, 8, 8, 0, 8, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5,
  119637. 9, 9, 0, 8, 8, 0, 8, 8, 5, 8, 9, 0, 8, 8, 0, 8,
  119638. 8,
  119639. };
  119640. static float _vq_quantthresh__44c7_s_p1_0[] = {
  119641. -0.5, 0.5,
  119642. };
  119643. static long _vq_quantmap__44c7_s_p1_0[] = {
  119644. 1, 0, 2,
  119645. };
  119646. static encode_aux_threshmatch _vq_auxt__44c7_s_p1_0 = {
  119647. _vq_quantthresh__44c7_s_p1_0,
  119648. _vq_quantmap__44c7_s_p1_0,
  119649. 3,
  119650. 3
  119651. };
  119652. static static_codebook _44c7_s_p1_0 = {
  119653. 4, 81,
  119654. _vq_lengthlist__44c7_s_p1_0,
  119655. 1, -535822336, 1611661312, 2, 0,
  119656. _vq_quantlist__44c7_s_p1_0,
  119657. NULL,
  119658. &_vq_auxt__44c7_s_p1_0,
  119659. NULL,
  119660. 0
  119661. };
  119662. static long _vq_quantlist__44c7_s_p2_0[] = {
  119663. 2,
  119664. 1,
  119665. 3,
  119666. 0,
  119667. 4,
  119668. };
  119669. static long _vq_lengthlist__44c7_s_p2_0[] = {
  119670. 3, 5, 5, 8, 8, 0, 5, 5, 8, 8, 0, 5, 5, 8, 8, 0,
  119671. 7, 7, 9, 9, 0, 0, 0, 9, 9, 5, 7, 7, 9, 9, 0, 8,
  119672. 8,10,10, 0, 8, 7,10, 9, 0,10,10,11,11, 0, 0, 0,
  119673. 11,11, 5, 7, 7, 9, 9, 0, 8, 8,10,10, 0, 7, 8, 9,
  119674. 10, 0,10,10,11,11, 0, 0, 0,11,11, 8, 9, 9,11,10,
  119675. 0,11,11,12,12, 0,11,10,12,12, 0,13,14,14,14, 0,
  119676. 0, 0,14,13, 8, 9, 9,10,11, 0,11,11,12,12, 0,10,
  119677. 11,12,12, 0,13,13,14,14, 0, 0, 0,13,14, 0, 0, 0,
  119678. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119679. 0, 0, 0, 0, 0, 0, 5, 8, 7,11,10, 0, 7, 7,10,10,
  119680. 0, 7, 7,10,10, 0, 9, 9,11,10, 0, 0, 0,11,11, 5,
  119681. 7, 8,10,11, 0, 7, 7,10,10, 0, 7, 7,10,10, 0, 9,
  119682. 9,10,11, 0, 0, 0,11,11, 8,10, 9,12,12, 0,10,10,
  119683. 12,12, 0,10,10,12,12, 0,12,12,13,13, 0, 0, 0,13,
  119684. 13, 8, 9,10,12,12, 0,10,10,12,12, 0,10,10,11,12,
  119685. 0,12,12,13,13, 0, 0, 0,13,13, 0, 0, 0, 0, 0, 0,
  119686. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119687. 0, 0, 0, 5, 8, 8,11,11, 0, 7, 7,10,10, 0, 7, 7,
  119688. 10,10, 0, 9, 9,10,11, 0, 0, 0,11,10, 5, 8, 8,10,
  119689. 11, 0, 7, 7,10,10, 0, 7, 7,10,10, 0, 9, 9,11,10,
  119690. 0, 0, 0,10,11, 9,10,10,12,12, 0,10,10,12,12, 0,
  119691. 10,10,12,12, 0,12,13,13,13, 0, 0, 0,13,12, 9,10,
  119692. 10,12,12, 0,10,10,12,12, 0,10,10,12,12, 0,13,12,
  119693. 13,13, 0, 0, 0,12,13, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119694. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119695. 7,10,10,14,13, 0, 9, 9,12,12, 0, 9, 9,12,12, 0,
  119696. 10,10,12,12, 0, 0, 0,12,12, 7,10,10,13,14, 0, 9,
  119697. 9,12,13, 0, 9, 9,12,12, 0,10,10,12,12, 0, 0, 0,
  119698. 12,12, 9,11,11,14,13, 0,11,10,13,12, 0,11,11,13,
  119699. 13, 0,12,12,13,13, 0, 0, 0,13,13, 9,11,11,13,14,
  119700. 0,10,11,12,13, 0,11,11,13,13, 0,12,12,13,13, 0,
  119701. 0, 0,13,13, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119702. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119703. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119704. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119705. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9,
  119706. 11,11,14,14, 0,10,11,13,13, 0,11,10,13,13, 0,12,
  119707. 12,13,13, 0, 0, 0,13,12, 9,11,11,14,14, 0,11,10,
  119708. 13,13, 0,10,11,13,13, 0,12,12,14,13, 0, 0, 0,13,
  119709. 13,
  119710. };
  119711. static float _vq_quantthresh__44c7_s_p2_0[] = {
  119712. -1.5, -0.5, 0.5, 1.5,
  119713. };
  119714. static long _vq_quantmap__44c7_s_p2_0[] = {
  119715. 3, 1, 0, 2, 4,
  119716. };
  119717. static encode_aux_threshmatch _vq_auxt__44c7_s_p2_0 = {
  119718. _vq_quantthresh__44c7_s_p2_0,
  119719. _vq_quantmap__44c7_s_p2_0,
  119720. 5,
  119721. 5
  119722. };
  119723. static static_codebook _44c7_s_p2_0 = {
  119724. 4, 625,
  119725. _vq_lengthlist__44c7_s_p2_0,
  119726. 1, -533725184, 1611661312, 3, 0,
  119727. _vq_quantlist__44c7_s_p2_0,
  119728. NULL,
  119729. &_vq_auxt__44c7_s_p2_0,
  119730. NULL,
  119731. 0
  119732. };
  119733. static long _vq_quantlist__44c7_s_p3_0[] = {
  119734. 4,
  119735. 3,
  119736. 5,
  119737. 2,
  119738. 6,
  119739. 1,
  119740. 7,
  119741. 0,
  119742. 8,
  119743. };
  119744. static long _vq_lengthlist__44c7_s_p3_0[] = {
  119745. 2, 4, 4, 5, 5, 7, 7, 9, 9, 0, 4, 4, 6, 6, 7, 7,
  119746. 9, 9, 0, 4, 4, 6, 6, 7, 7, 9, 9, 0, 5, 5, 6, 6,
  119747. 8, 8,10,10, 0, 0, 0, 6, 6, 8, 8,10,10, 0, 0, 0,
  119748. 7, 7, 9, 9,10,10, 0, 0, 0, 7, 7, 8, 8,10,10, 0,
  119749. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119750. 0,
  119751. };
  119752. static float _vq_quantthresh__44c7_s_p3_0[] = {
  119753. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  119754. };
  119755. static long _vq_quantmap__44c7_s_p3_0[] = {
  119756. 7, 5, 3, 1, 0, 2, 4, 6,
  119757. 8,
  119758. };
  119759. static encode_aux_threshmatch _vq_auxt__44c7_s_p3_0 = {
  119760. _vq_quantthresh__44c7_s_p3_0,
  119761. _vq_quantmap__44c7_s_p3_0,
  119762. 9,
  119763. 9
  119764. };
  119765. static static_codebook _44c7_s_p3_0 = {
  119766. 2, 81,
  119767. _vq_lengthlist__44c7_s_p3_0,
  119768. 1, -531628032, 1611661312, 4, 0,
  119769. _vq_quantlist__44c7_s_p3_0,
  119770. NULL,
  119771. &_vq_auxt__44c7_s_p3_0,
  119772. NULL,
  119773. 0
  119774. };
  119775. static long _vq_quantlist__44c7_s_p4_0[] = {
  119776. 8,
  119777. 7,
  119778. 9,
  119779. 6,
  119780. 10,
  119781. 5,
  119782. 11,
  119783. 4,
  119784. 12,
  119785. 3,
  119786. 13,
  119787. 2,
  119788. 14,
  119789. 1,
  119790. 15,
  119791. 0,
  119792. 16,
  119793. };
  119794. static long _vq_lengthlist__44c7_s_p4_0[] = {
  119795. 3, 4, 4, 5, 5, 7, 7, 8, 8, 8, 8, 9, 9,10,10,11,
  119796. 11, 0, 4, 4, 6, 6, 7, 7, 8, 8, 9, 9,10,10,11,11,
  119797. 12,12, 0, 4, 4, 6, 6, 7, 7, 8, 8, 9, 9,10,10,11,
  119798. 11,12,12, 0, 5, 5, 6, 6, 8, 8, 9, 9, 9, 9,10,10,
  119799. 11,12,12,12, 0, 0, 0, 6, 6, 8, 7, 9, 9, 9, 9,10,
  119800. 10,11,11,12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9,10,10,
  119801. 11,11,12,12,13,12, 0, 0, 0, 7, 7, 8, 8, 9, 9,10,
  119802. 10,11,11,12,12,12,13, 0, 0, 0, 7, 7, 8, 8, 9, 9,
  119803. 10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 8, 8, 9,
  119804. 9,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 0, 0,
  119805. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119806. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119807. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119808. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119809. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119810. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119811. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119812. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119813. 0,
  119814. };
  119815. static float _vq_quantthresh__44c7_s_p4_0[] = {
  119816. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  119817. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  119818. };
  119819. static long _vq_quantmap__44c7_s_p4_0[] = {
  119820. 15, 13, 11, 9, 7, 5, 3, 1,
  119821. 0, 2, 4, 6, 8, 10, 12, 14,
  119822. 16,
  119823. };
  119824. static encode_aux_threshmatch _vq_auxt__44c7_s_p4_0 = {
  119825. _vq_quantthresh__44c7_s_p4_0,
  119826. _vq_quantmap__44c7_s_p4_0,
  119827. 17,
  119828. 17
  119829. };
  119830. static static_codebook _44c7_s_p4_0 = {
  119831. 2, 289,
  119832. _vq_lengthlist__44c7_s_p4_0,
  119833. 1, -529530880, 1611661312, 5, 0,
  119834. _vq_quantlist__44c7_s_p4_0,
  119835. NULL,
  119836. &_vq_auxt__44c7_s_p4_0,
  119837. NULL,
  119838. 0
  119839. };
  119840. static long _vq_quantlist__44c7_s_p5_0[] = {
  119841. 1,
  119842. 0,
  119843. 2,
  119844. };
  119845. static long _vq_lengthlist__44c7_s_p5_0[] = {
  119846. 1, 4, 4, 5, 7, 7, 6, 7, 7, 4, 6, 7,10,10,10,10,
  119847. 10, 9, 4, 6, 6,10,10,10,10, 9,10, 5,10,10, 9,11,
  119848. 12,10,11,12, 7,10,10,11,12,12,12,12,12, 7,10,10,
  119849. 11,12,12,12,12,12, 6,10,10,10,12,12,11,12,12, 7,
  119850. 10,10,12,12,12,12,11,12, 7,10,10,11,12,12,12,12,
  119851. 12,
  119852. };
  119853. static float _vq_quantthresh__44c7_s_p5_0[] = {
  119854. -5.5, 5.5,
  119855. };
  119856. static long _vq_quantmap__44c7_s_p5_0[] = {
  119857. 1, 0, 2,
  119858. };
  119859. static encode_aux_threshmatch _vq_auxt__44c7_s_p5_0 = {
  119860. _vq_quantthresh__44c7_s_p5_0,
  119861. _vq_quantmap__44c7_s_p5_0,
  119862. 3,
  119863. 3
  119864. };
  119865. static static_codebook _44c7_s_p5_0 = {
  119866. 4, 81,
  119867. _vq_lengthlist__44c7_s_p5_0,
  119868. 1, -529137664, 1618345984, 2, 0,
  119869. _vq_quantlist__44c7_s_p5_0,
  119870. NULL,
  119871. &_vq_auxt__44c7_s_p5_0,
  119872. NULL,
  119873. 0
  119874. };
  119875. static long _vq_quantlist__44c7_s_p5_1[] = {
  119876. 5,
  119877. 4,
  119878. 6,
  119879. 3,
  119880. 7,
  119881. 2,
  119882. 8,
  119883. 1,
  119884. 9,
  119885. 0,
  119886. 10,
  119887. };
  119888. static long _vq_lengthlist__44c7_s_p5_1[] = {
  119889. 3, 5, 5, 6, 6, 7, 7, 8, 8, 8, 8,11, 4, 4, 6, 6,
  119890. 7, 7, 8, 8, 9, 9,11, 4, 4, 6, 6, 7, 7, 8, 8, 9,
  119891. 9,12, 5, 5, 6, 6, 7, 7, 9, 9, 9, 9,12,12,12, 6,
  119892. 6, 7, 7, 9, 9, 9, 9,11,11,11, 7, 7, 7, 7, 8, 8,
  119893. 9, 9,11,11,11, 7, 7, 7, 7, 8, 8, 9, 9,11,11,11,
  119894. 7, 7, 8, 8, 8, 8, 9, 9,11,11,11,11,11, 8, 8, 8,
  119895. 8, 8, 9,11,11,11,11,11, 8, 8, 8, 8, 8, 8,11,11,
  119896. 11,11,11, 7, 7, 8, 8, 8, 8,
  119897. };
  119898. static float _vq_quantthresh__44c7_s_p5_1[] = {
  119899. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  119900. 3.5, 4.5,
  119901. };
  119902. static long _vq_quantmap__44c7_s_p5_1[] = {
  119903. 9, 7, 5, 3, 1, 0, 2, 4,
  119904. 6, 8, 10,
  119905. };
  119906. static encode_aux_threshmatch _vq_auxt__44c7_s_p5_1 = {
  119907. _vq_quantthresh__44c7_s_p5_1,
  119908. _vq_quantmap__44c7_s_p5_1,
  119909. 11,
  119910. 11
  119911. };
  119912. static static_codebook _44c7_s_p5_1 = {
  119913. 2, 121,
  119914. _vq_lengthlist__44c7_s_p5_1,
  119915. 1, -531365888, 1611661312, 4, 0,
  119916. _vq_quantlist__44c7_s_p5_1,
  119917. NULL,
  119918. &_vq_auxt__44c7_s_p5_1,
  119919. NULL,
  119920. 0
  119921. };
  119922. static long _vq_quantlist__44c7_s_p6_0[] = {
  119923. 6,
  119924. 5,
  119925. 7,
  119926. 4,
  119927. 8,
  119928. 3,
  119929. 9,
  119930. 2,
  119931. 10,
  119932. 1,
  119933. 11,
  119934. 0,
  119935. 12,
  119936. };
  119937. static long _vq_lengthlist__44c7_s_p6_0[] = {
  119938. 1, 4, 4, 6, 6, 7, 7, 8, 7, 9, 8,10,10, 6, 5, 5,
  119939. 7, 7, 8, 8, 9, 9, 9,10,11,11, 7, 5, 5, 7, 7, 8,
  119940. 8, 9, 9,10,10,11,11, 0, 7, 7, 7, 7, 9, 8, 9, 9,
  119941. 10,10,11,11, 0, 8, 8, 7, 7, 8, 9, 9, 9,10,10,11,
  119942. 11, 0,11,11, 9, 9,10,10,11,10,11,11,12,12, 0,12,
  119943. 12, 9, 9,10,10,11,11,11,11,12,12, 0, 0, 0, 0, 0,
  119944. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119945. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119946. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119947. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119948. 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119949. };
  119950. static float _vq_quantthresh__44c7_s_p6_0[] = {
  119951. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  119952. 12.5, 17.5, 22.5, 27.5,
  119953. };
  119954. static long _vq_quantmap__44c7_s_p6_0[] = {
  119955. 11, 9, 7, 5, 3, 1, 0, 2,
  119956. 4, 6, 8, 10, 12,
  119957. };
  119958. static encode_aux_threshmatch _vq_auxt__44c7_s_p6_0 = {
  119959. _vq_quantthresh__44c7_s_p6_0,
  119960. _vq_quantmap__44c7_s_p6_0,
  119961. 13,
  119962. 13
  119963. };
  119964. static static_codebook _44c7_s_p6_0 = {
  119965. 2, 169,
  119966. _vq_lengthlist__44c7_s_p6_0,
  119967. 1, -526516224, 1616117760, 4, 0,
  119968. _vq_quantlist__44c7_s_p6_0,
  119969. NULL,
  119970. &_vq_auxt__44c7_s_p6_0,
  119971. NULL,
  119972. 0
  119973. };
  119974. static long _vq_quantlist__44c7_s_p6_1[] = {
  119975. 2,
  119976. 1,
  119977. 3,
  119978. 0,
  119979. 4,
  119980. };
  119981. static long _vq_lengthlist__44c7_s_p6_1[] = {
  119982. 3, 4, 4, 5, 5, 5, 4, 4, 5, 5, 5, 4, 4, 5, 5, 6,
  119983. 5, 5, 5, 5, 6, 6, 6, 5, 5,
  119984. };
  119985. static float _vq_quantthresh__44c7_s_p6_1[] = {
  119986. -1.5, -0.5, 0.5, 1.5,
  119987. };
  119988. static long _vq_quantmap__44c7_s_p6_1[] = {
  119989. 3, 1, 0, 2, 4,
  119990. };
  119991. static encode_aux_threshmatch _vq_auxt__44c7_s_p6_1 = {
  119992. _vq_quantthresh__44c7_s_p6_1,
  119993. _vq_quantmap__44c7_s_p6_1,
  119994. 5,
  119995. 5
  119996. };
  119997. static static_codebook _44c7_s_p6_1 = {
  119998. 2, 25,
  119999. _vq_lengthlist__44c7_s_p6_1,
  120000. 1, -533725184, 1611661312, 3, 0,
  120001. _vq_quantlist__44c7_s_p6_1,
  120002. NULL,
  120003. &_vq_auxt__44c7_s_p6_1,
  120004. NULL,
  120005. 0
  120006. };
  120007. static long _vq_quantlist__44c7_s_p7_0[] = {
  120008. 6,
  120009. 5,
  120010. 7,
  120011. 4,
  120012. 8,
  120013. 3,
  120014. 9,
  120015. 2,
  120016. 10,
  120017. 1,
  120018. 11,
  120019. 0,
  120020. 12,
  120021. };
  120022. static long _vq_lengthlist__44c7_s_p7_0[] = {
  120023. 1, 4, 4, 6, 6, 7, 8, 9, 9,10,10,12,11, 6, 5, 5,
  120024. 7, 7, 8, 8, 9,10,11,11,12,12, 7, 5, 5, 7, 7, 8,
  120025. 8,10,10,11,11,12,12,20, 7, 7, 7, 7, 8, 9,10,10,
  120026. 11,11,12,13,20, 7, 7, 7, 7, 9, 9,10,10,11,12,13,
  120027. 13,20,11,11, 8, 8, 9, 9,11,11,12,12,13,13,20,11,
  120028. 11, 8, 8, 9, 9,11,11,12,12,13,13,20,20,20,10,10,
  120029. 10,10,12,12,13,13,13,13,20,20,20,10,10,10,10,12,
  120030. 12,13,13,13,14,20,20,20,14,14,11,11,12,12,13,13,
  120031. 14,14,20,20,20,14,14,11,11,12,12,13,13,14,14,20,
  120032. 20,20,20,19,13,13,13,13,14,14,15,14,19,19,19,19,
  120033. 19,13,13,13,13,14,14,15,15,
  120034. };
  120035. static float _vq_quantthresh__44c7_s_p7_0[] = {
  120036. -60.5, -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5,
  120037. 27.5, 38.5, 49.5, 60.5,
  120038. };
  120039. static long _vq_quantmap__44c7_s_p7_0[] = {
  120040. 11, 9, 7, 5, 3, 1, 0, 2,
  120041. 4, 6, 8, 10, 12,
  120042. };
  120043. static encode_aux_threshmatch _vq_auxt__44c7_s_p7_0 = {
  120044. _vq_quantthresh__44c7_s_p7_0,
  120045. _vq_quantmap__44c7_s_p7_0,
  120046. 13,
  120047. 13
  120048. };
  120049. static static_codebook _44c7_s_p7_0 = {
  120050. 2, 169,
  120051. _vq_lengthlist__44c7_s_p7_0,
  120052. 1, -523206656, 1618345984, 4, 0,
  120053. _vq_quantlist__44c7_s_p7_0,
  120054. NULL,
  120055. &_vq_auxt__44c7_s_p7_0,
  120056. NULL,
  120057. 0
  120058. };
  120059. static long _vq_quantlist__44c7_s_p7_1[] = {
  120060. 5,
  120061. 4,
  120062. 6,
  120063. 3,
  120064. 7,
  120065. 2,
  120066. 8,
  120067. 1,
  120068. 9,
  120069. 0,
  120070. 10,
  120071. };
  120072. static long _vq_lengthlist__44c7_s_p7_1[] = {
  120073. 4, 5, 5, 6, 6, 7, 7, 7, 7, 7, 7, 8, 6, 6, 7, 7,
  120074. 7, 7, 7, 7, 7, 7, 8, 6, 6, 6, 7, 7, 7, 7, 7, 7,
  120075. 7, 8, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 7,
  120076. 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 7, 7, 7, 7, 7, 7,
  120077. 7, 7, 8, 8, 8, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8,
  120078. 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 7, 7, 7,
  120079. 7, 7, 7, 8, 8, 8, 8, 8, 7, 7, 7, 7, 7, 7, 8, 8,
  120080. 8, 8, 8, 7, 7, 7, 7, 7, 7,
  120081. };
  120082. static float _vq_quantthresh__44c7_s_p7_1[] = {
  120083. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  120084. 3.5, 4.5,
  120085. };
  120086. static long _vq_quantmap__44c7_s_p7_1[] = {
  120087. 9, 7, 5, 3, 1, 0, 2, 4,
  120088. 6, 8, 10,
  120089. };
  120090. static encode_aux_threshmatch _vq_auxt__44c7_s_p7_1 = {
  120091. _vq_quantthresh__44c7_s_p7_1,
  120092. _vq_quantmap__44c7_s_p7_1,
  120093. 11,
  120094. 11
  120095. };
  120096. static static_codebook _44c7_s_p7_1 = {
  120097. 2, 121,
  120098. _vq_lengthlist__44c7_s_p7_1,
  120099. 1, -531365888, 1611661312, 4, 0,
  120100. _vq_quantlist__44c7_s_p7_1,
  120101. NULL,
  120102. &_vq_auxt__44c7_s_p7_1,
  120103. NULL,
  120104. 0
  120105. };
  120106. static long _vq_quantlist__44c7_s_p8_0[] = {
  120107. 7,
  120108. 6,
  120109. 8,
  120110. 5,
  120111. 9,
  120112. 4,
  120113. 10,
  120114. 3,
  120115. 11,
  120116. 2,
  120117. 12,
  120118. 1,
  120119. 13,
  120120. 0,
  120121. 14,
  120122. };
  120123. static long _vq_lengthlist__44c7_s_p8_0[] = {
  120124. 1, 4, 4, 7, 7, 8, 8, 8, 7, 9, 8, 9, 9,10,10, 6,
  120125. 5, 5, 7, 7, 9, 9, 8, 8,10, 9,11,10,12,11, 6, 5,
  120126. 5, 8, 7, 9, 9, 8, 8,10,10,11,11,12,11,19, 8, 8,
  120127. 8, 8,10,10, 9, 9,10,10,11,11,12,11,19, 8, 8, 8,
  120128. 8,10,10, 9, 9,10,10,11,11,12,12,19,12,12, 9, 9,
  120129. 10,10, 9,10,10,10,11,11,12,12,19,12,12, 9, 9,10,
  120130. 10,10,10,10,10,12,12,12,12,19,19,19, 9, 9, 9, 9,
  120131. 11,10,11,11,12,11,13,13,19,19,19, 9, 9, 9, 9,11,
  120132. 10,11,11,11,12,13,13,19,19,19,13,13,10,10,11,11,
  120133. 12,12,12,12,13,12,19,19,19,14,13,10,10,11,11,12,
  120134. 12,12,13,13,13,19,19,19,19,19,12,12,12,11,12,13,
  120135. 14,13,13,13,19,19,19,19,19,12,12,12,11,12,12,13,
  120136. 14,13,14,19,19,19,19,19,16,16,12,13,12,13,13,14,
  120137. 15,14,19,18,18,18,18,16,15,12,11,12,11,14,12,14,
  120138. 14,
  120139. };
  120140. static float _vq_quantthresh__44c7_s_p8_0[] = {
  120141. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  120142. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  120143. };
  120144. static long _vq_quantmap__44c7_s_p8_0[] = {
  120145. 13, 11, 9, 7, 5, 3, 1, 0,
  120146. 2, 4, 6, 8, 10, 12, 14,
  120147. };
  120148. static encode_aux_threshmatch _vq_auxt__44c7_s_p8_0 = {
  120149. _vq_quantthresh__44c7_s_p8_0,
  120150. _vq_quantmap__44c7_s_p8_0,
  120151. 15,
  120152. 15
  120153. };
  120154. static static_codebook _44c7_s_p8_0 = {
  120155. 2, 225,
  120156. _vq_lengthlist__44c7_s_p8_0,
  120157. 1, -520986624, 1620377600, 4, 0,
  120158. _vq_quantlist__44c7_s_p8_0,
  120159. NULL,
  120160. &_vq_auxt__44c7_s_p8_0,
  120161. NULL,
  120162. 0
  120163. };
  120164. static long _vq_quantlist__44c7_s_p8_1[] = {
  120165. 10,
  120166. 9,
  120167. 11,
  120168. 8,
  120169. 12,
  120170. 7,
  120171. 13,
  120172. 6,
  120173. 14,
  120174. 5,
  120175. 15,
  120176. 4,
  120177. 16,
  120178. 3,
  120179. 17,
  120180. 2,
  120181. 18,
  120182. 1,
  120183. 19,
  120184. 0,
  120185. 20,
  120186. };
  120187. static long _vq_lengthlist__44c7_s_p8_1[] = {
  120188. 3, 5, 5, 7, 6, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  120189. 8, 8, 8, 8, 8,10, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,
  120190. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10, 6, 6, 7, 7, 8,
  120191. 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,
  120192. 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  120193. 9, 9, 9, 9,10,10,10, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  120194. 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10,10, 8, 8, 8, 9,
  120195. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10,
  120196. 10, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  120197. 9, 9, 9,10,10,10, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  120198. 9, 9, 9, 9, 9, 9, 9, 9,10,11,10,10,10, 9, 9, 9,
  120199. 9, 9, 9, 9, 9, 9, 9,10, 9, 9,10, 9, 9,10,11,10,
  120200. 11,10, 9, 9, 9, 9, 9, 9, 9,10,10,10, 9,10, 9, 9,
  120201. 9, 9,11,10,11,10,10, 9, 9, 9, 9, 9, 9,10, 9, 9,
  120202. 10, 9, 9,10, 9, 9,10,11,10,10,11,10, 9, 9, 9, 9,
  120203. 9,10,10, 9,10,10,10,10, 9,10,10,10,10,10,10,11,
  120204. 11,11,10, 9, 9, 9,10,10,10,10,10,10,10,10,10,10,
  120205. 10,10,10,11,11,10,10,10,10,10,10,10,10,10,10,10,
  120206. 10, 9,10,10, 9,10,11,11,10,11,10,11,10, 9,10,10,
  120207. 9,10,10,10,10,10,10,10,10,10,10,11,11,11,11,10,
  120208. 11,11,10,10,10,10,10,10, 9,10, 9,10,10, 9,10, 9,
  120209. 10,10,10,11,10,11,10,11,11,10,10,10,10,10,10, 9,
  120210. 10,10,10,10,10,10,10,11,10,10,10,10,10,10,10,10,
  120211. 10,10,10,10,10,10,10,10,10,10,10,10,10,11,10,11,
  120212. 11,10,10,10,10, 9, 9,10,10, 9, 9,10, 9,10,10,10,
  120213. 10,11,11,10,10,10,10,10,10,10, 9, 9,10,10,10, 9,
  120214. 9,10,10,10,10,10,11,10,11,10,10,10,10,10,10, 9,
  120215. 10,10,10,10,10,10,10,10,10,
  120216. };
  120217. static float _vq_quantthresh__44c7_s_p8_1[] = {
  120218. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  120219. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  120220. 6.5, 7.5, 8.5, 9.5,
  120221. };
  120222. static long _vq_quantmap__44c7_s_p8_1[] = {
  120223. 19, 17, 15, 13, 11, 9, 7, 5,
  120224. 3, 1, 0, 2, 4, 6, 8, 10,
  120225. 12, 14, 16, 18, 20,
  120226. };
  120227. static encode_aux_threshmatch _vq_auxt__44c7_s_p8_1 = {
  120228. _vq_quantthresh__44c7_s_p8_1,
  120229. _vq_quantmap__44c7_s_p8_1,
  120230. 21,
  120231. 21
  120232. };
  120233. static static_codebook _44c7_s_p8_1 = {
  120234. 2, 441,
  120235. _vq_lengthlist__44c7_s_p8_1,
  120236. 1, -529268736, 1611661312, 5, 0,
  120237. _vq_quantlist__44c7_s_p8_1,
  120238. NULL,
  120239. &_vq_auxt__44c7_s_p8_1,
  120240. NULL,
  120241. 0
  120242. };
  120243. static long _vq_quantlist__44c7_s_p9_0[] = {
  120244. 6,
  120245. 5,
  120246. 7,
  120247. 4,
  120248. 8,
  120249. 3,
  120250. 9,
  120251. 2,
  120252. 10,
  120253. 1,
  120254. 11,
  120255. 0,
  120256. 12,
  120257. };
  120258. static long _vq_lengthlist__44c7_s_p9_0[] = {
  120259. 1, 3, 3,11,11,11,11,11,11,11,11,11,11, 4, 6, 6,
  120260. 11,11,11,11,11,11,11,11,11,11, 4, 7, 7,11,11,11,
  120261. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  120262. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  120263. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  120264. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  120265. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  120266. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  120267. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  120268. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  120269. 11,11,11,11,11,11,11,11,11,
  120270. };
  120271. static float _vq_quantthresh__44c7_s_p9_0[] = {
  120272. -3503.5, -2866.5, -2229.5, -1592.5, -955.5, -318.5, 318.5, 955.5,
  120273. 1592.5, 2229.5, 2866.5, 3503.5,
  120274. };
  120275. static long _vq_quantmap__44c7_s_p9_0[] = {
  120276. 11, 9, 7, 5, 3, 1, 0, 2,
  120277. 4, 6, 8, 10, 12,
  120278. };
  120279. static encode_aux_threshmatch _vq_auxt__44c7_s_p9_0 = {
  120280. _vq_quantthresh__44c7_s_p9_0,
  120281. _vq_quantmap__44c7_s_p9_0,
  120282. 13,
  120283. 13
  120284. };
  120285. static static_codebook _44c7_s_p9_0 = {
  120286. 2, 169,
  120287. _vq_lengthlist__44c7_s_p9_0,
  120288. 1, -511845376, 1630791680, 4, 0,
  120289. _vq_quantlist__44c7_s_p9_0,
  120290. NULL,
  120291. &_vq_auxt__44c7_s_p9_0,
  120292. NULL,
  120293. 0
  120294. };
  120295. static long _vq_quantlist__44c7_s_p9_1[] = {
  120296. 6,
  120297. 5,
  120298. 7,
  120299. 4,
  120300. 8,
  120301. 3,
  120302. 9,
  120303. 2,
  120304. 10,
  120305. 1,
  120306. 11,
  120307. 0,
  120308. 12,
  120309. };
  120310. static long _vq_lengthlist__44c7_s_p9_1[] = {
  120311. 1, 4, 4, 7, 7, 7, 7, 7, 6, 8, 8, 8, 8, 6, 6, 6,
  120312. 8, 8, 9, 8, 8, 7, 9, 8,11,10, 5, 6, 6, 8, 8, 9,
  120313. 8, 8, 8,10, 9,11,11,16, 8, 8, 9, 8, 9, 9, 9, 8,
  120314. 10, 9,11,10,16, 8, 8, 9, 9,10,10, 9, 9,10,10,11,
  120315. 11,16,13,13, 9, 9,10,10, 9,10,11,11,12,11,16,13,
  120316. 13, 9, 8,10, 9,10,10,10,10,11,11,16,14,16, 8, 9,
  120317. 9, 9,11,10,11,11,12,11,16,16,16, 9, 7,10, 7,11,
  120318. 10,11,11,12,11,16,16,16,12,12, 9,10,11,11,12,11,
  120319. 12,12,16,16,16,12,10,10, 7,11, 8,12,11,12,12,16,
  120320. 16,15,16,16,11,12,10,10,12,11,12,12,16,16,16,15,
  120321. 15,11,11,10,10,12,12,12,12,
  120322. };
  120323. static float _vq_quantthresh__44c7_s_p9_1[] = {
  120324. -269.5, -220.5, -171.5, -122.5, -73.5, -24.5, 24.5, 73.5,
  120325. 122.5, 171.5, 220.5, 269.5,
  120326. };
  120327. static long _vq_quantmap__44c7_s_p9_1[] = {
  120328. 11, 9, 7, 5, 3, 1, 0, 2,
  120329. 4, 6, 8, 10, 12,
  120330. };
  120331. static encode_aux_threshmatch _vq_auxt__44c7_s_p9_1 = {
  120332. _vq_quantthresh__44c7_s_p9_1,
  120333. _vq_quantmap__44c7_s_p9_1,
  120334. 13,
  120335. 13
  120336. };
  120337. static static_codebook _44c7_s_p9_1 = {
  120338. 2, 169,
  120339. _vq_lengthlist__44c7_s_p9_1,
  120340. 1, -518889472, 1622704128, 4, 0,
  120341. _vq_quantlist__44c7_s_p9_1,
  120342. NULL,
  120343. &_vq_auxt__44c7_s_p9_1,
  120344. NULL,
  120345. 0
  120346. };
  120347. static long _vq_quantlist__44c7_s_p9_2[] = {
  120348. 24,
  120349. 23,
  120350. 25,
  120351. 22,
  120352. 26,
  120353. 21,
  120354. 27,
  120355. 20,
  120356. 28,
  120357. 19,
  120358. 29,
  120359. 18,
  120360. 30,
  120361. 17,
  120362. 31,
  120363. 16,
  120364. 32,
  120365. 15,
  120366. 33,
  120367. 14,
  120368. 34,
  120369. 13,
  120370. 35,
  120371. 12,
  120372. 36,
  120373. 11,
  120374. 37,
  120375. 10,
  120376. 38,
  120377. 9,
  120378. 39,
  120379. 8,
  120380. 40,
  120381. 7,
  120382. 41,
  120383. 6,
  120384. 42,
  120385. 5,
  120386. 43,
  120387. 4,
  120388. 44,
  120389. 3,
  120390. 45,
  120391. 2,
  120392. 46,
  120393. 1,
  120394. 47,
  120395. 0,
  120396. 48,
  120397. };
  120398. static long _vq_lengthlist__44c7_s_p9_2[] = {
  120399. 2, 4, 3, 4, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6, 6,
  120400. 6, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  120401. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  120402. 7,
  120403. };
  120404. static float _vq_quantthresh__44c7_s_p9_2[] = {
  120405. -23.5, -22.5, -21.5, -20.5, -19.5, -18.5, -17.5, -16.5,
  120406. -15.5, -14.5, -13.5, -12.5, -11.5, -10.5, -9.5, -8.5,
  120407. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  120408. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  120409. 8.5, 9.5, 10.5, 11.5, 12.5, 13.5, 14.5, 15.5,
  120410. 16.5, 17.5, 18.5, 19.5, 20.5, 21.5, 22.5, 23.5,
  120411. };
  120412. static long _vq_quantmap__44c7_s_p9_2[] = {
  120413. 47, 45, 43, 41, 39, 37, 35, 33,
  120414. 31, 29, 27, 25, 23, 21, 19, 17,
  120415. 15, 13, 11, 9, 7, 5, 3, 1,
  120416. 0, 2, 4, 6, 8, 10, 12, 14,
  120417. 16, 18, 20, 22, 24, 26, 28, 30,
  120418. 32, 34, 36, 38, 40, 42, 44, 46,
  120419. 48,
  120420. };
  120421. static encode_aux_threshmatch _vq_auxt__44c7_s_p9_2 = {
  120422. _vq_quantthresh__44c7_s_p9_2,
  120423. _vq_quantmap__44c7_s_p9_2,
  120424. 49,
  120425. 49
  120426. };
  120427. static static_codebook _44c7_s_p9_2 = {
  120428. 1, 49,
  120429. _vq_lengthlist__44c7_s_p9_2,
  120430. 1, -526909440, 1611661312, 6, 0,
  120431. _vq_quantlist__44c7_s_p9_2,
  120432. NULL,
  120433. &_vq_auxt__44c7_s_p9_2,
  120434. NULL,
  120435. 0
  120436. };
  120437. static long _huff_lengthlist__44c7_s_short[] = {
  120438. 4,11,12,14,15,15,17,17,18,18, 5, 6, 6, 8, 9,10,
  120439. 13,17,18,19, 7, 5, 4, 6, 8, 9,11,15,19,19, 8, 6,
  120440. 5, 5, 6, 7,11,14,16,17, 9, 7, 7, 6, 7, 7,10,13,
  120441. 15,19,10, 8, 7, 6, 7, 6, 7, 9,14,16,12,10, 9, 7,
  120442. 7, 6, 4, 5,10,15,14,13,11, 7, 6, 6, 4, 2, 7,13,
  120443. 16,16,15, 9, 8, 8, 8, 6, 9,13,19,19,17,12,11,10,
  120444. 10, 9,11,14,
  120445. };
  120446. static static_codebook _huff_book__44c7_s_short = {
  120447. 2, 100,
  120448. _huff_lengthlist__44c7_s_short,
  120449. 0, 0, 0, 0, 0,
  120450. NULL,
  120451. NULL,
  120452. NULL,
  120453. NULL,
  120454. 0
  120455. };
  120456. static long _huff_lengthlist__44c8_s_long[] = {
  120457. 3, 8,12,13,14,14,14,13,14,14, 6, 4, 5, 8,10,10,
  120458. 11,11,14,13, 9, 5, 4, 5, 7, 8, 9,10,13,13,12, 7,
  120459. 5, 4, 5, 6, 8, 9,12,13,13, 9, 6, 5, 5, 5, 7, 9,
  120460. 11,14,12,10, 7, 6, 5, 4, 6, 7,10,11,12,11, 9, 8,
  120461. 7, 5, 5, 6,10,10,13,12,10, 9, 8, 6, 6, 5, 8,10,
  120462. 14,13,12,12,11,10, 9, 7, 8,10,12,13,14,14,13,12,
  120463. 11, 9, 9,10,
  120464. };
  120465. static static_codebook _huff_book__44c8_s_long = {
  120466. 2, 100,
  120467. _huff_lengthlist__44c8_s_long,
  120468. 0, 0, 0, 0, 0,
  120469. NULL,
  120470. NULL,
  120471. NULL,
  120472. NULL,
  120473. 0
  120474. };
  120475. static long _vq_quantlist__44c8_s_p1_0[] = {
  120476. 1,
  120477. 0,
  120478. 2,
  120479. };
  120480. static long _vq_lengthlist__44c8_s_p1_0[] = {
  120481. 1, 5, 5, 0, 5, 5, 0, 5, 5, 5, 7, 7, 0, 9, 8, 0,
  120482. 9, 8, 6, 7, 7, 0, 8, 9, 0, 8, 9, 0, 0, 0, 0, 0,
  120483. 0, 0, 0, 0, 5, 9, 8, 0, 8, 8, 0, 8, 8, 5, 8, 9,
  120484. 0, 8, 8, 0, 8, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5,
  120485. 9, 8, 0, 8, 8, 0, 8, 8, 5, 8, 9, 0, 8, 8, 0, 8,
  120486. 8,
  120487. };
  120488. static float _vq_quantthresh__44c8_s_p1_0[] = {
  120489. -0.5, 0.5,
  120490. };
  120491. static long _vq_quantmap__44c8_s_p1_0[] = {
  120492. 1, 0, 2,
  120493. };
  120494. static encode_aux_threshmatch _vq_auxt__44c8_s_p1_0 = {
  120495. _vq_quantthresh__44c8_s_p1_0,
  120496. _vq_quantmap__44c8_s_p1_0,
  120497. 3,
  120498. 3
  120499. };
  120500. static static_codebook _44c8_s_p1_0 = {
  120501. 4, 81,
  120502. _vq_lengthlist__44c8_s_p1_0,
  120503. 1, -535822336, 1611661312, 2, 0,
  120504. _vq_quantlist__44c8_s_p1_0,
  120505. NULL,
  120506. &_vq_auxt__44c8_s_p1_0,
  120507. NULL,
  120508. 0
  120509. };
  120510. static long _vq_quantlist__44c8_s_p2_0[] = {
  120511. 2,
  120512. 1,
  120513. 3,
  120514. 0,
  120515. 4,
  120516. };
  120517. static long _vq_lengthlist__44c8_s_p2_0[] = {
  120518. 3, 5, 5, 8, 8, 0, 5, 5, 8, 8, 0, 5, 5, 8, 8, 0,
  120519. 7, 7, 9, 9, 0, 0, 0, 9, 9, 5, 7, 7, 9, 9, 0, 8,
  120520. 7,10, 9, 0, 8, 7,10, 9, 0,10,10,11,11, 0, 0, 0,
  120521. 11,11, 5, 7, 7, 9, 9, 0, 7, 8, 9,10, 0, 7, 8, 9,
  120522. 10, 0,10,10,11,11, 0, 0, 0,11,11, 8, 9, 9,11,10,
  120523. 0,11,10,12,11, 0,11,10,12,12, 0,13,13,14,14, 0,
  120524. 0, 0,14,13, 8, 9, 9,10,11, 0,10,11,12,12, 0,10,
  120525. 11,12,12, 0,13,13,14,14, 0, 0, 0,13,14, 0, 0, 0,
  120526. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120527. 0, 0, 0, 0, 0, 0, 5, 8, 7,11,10, 0, 7, 7,10,10,
  120528. 0, 7, 7,10,10, 0, 9, 9,10,10, 0, 0, 0,11,10, 5,
  120529. 7, 8,10,11, 0, 7, 7,10,10, 0, 7, 7,10,10, 0, 9,
  120530. 9,10,10, 0, 0, 0,10,10, 8,10, 9,12,12, 0,10,10,
  120531. 12,11, 0,10,10,12,12, 0,12,12,13,12, 0, 0, 0,13,
  120532. 12, 8, 9,10,12,12, 0,10,10,11,12, 0,10,10,11,12,
  120533. 0,12,12,13,13, 0, 0, 0,12,13, 0, 0, 0, 0, 0, 0,
  120534. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120535. 0, 0, 0, 6, 8, 7,11,10, 0, 7, 7,10,10, 0, 7, 7,
  120536. 10,10, 0, 9, 9,10,11, 0, 0, 0,10,10, 6, 7, 8,10,
  120537. 11, 0, 7, 7,10,10, 0, 7, 7,10,10, 0, 9, 9,10,10,
  120538. 0, 0, 0,10,10, 9,10, 9,12,12, 0,10,10,12,12, 0,
  120539. 10,10,12,11, 0,12,12,13,13, 0, 0, 0,13,12, 8, 9,
  120540. 10,12,12, 0,10,10,12,12, 0,10,10,11,12, 0,12,12,
  120541. 13,13, 0, 0, 0,12,13, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120542. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120543. 7,10,10,13,13, 0, 9, 9,12,12, 0, 9, 9,12,12, 0,
  120544. 10,10,12,12, 0, 0, 0,12,12, 7,10,10,13,13, 0, 9,
  120545. 9,12,12, 0, 9, 9,12,12, 0,10,10,12,12, 0, 0, 0,
  120546. 12,12, 9,11,11,14,13, 0,10,10,13,12, 0,11,10,13,
  120547. 12, 0,12,12,13,12, 0, 0, 0,13,13, 9,11,11,13,14,
  120548. 0,10,11,12,13, 0,10,11,13,13, 0,12,12,12,13, 0,
  120549. 0, 0,13,13, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120550. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120551. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120552. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120553. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9,
  120554. 11,11,14,14, 0,10,11,13,13, 0,11,10,13,13, 0,11,
  120555. 12,13,13, 0, 0, 0,13,12, 9,11,11,14,14, 0,11,10,
  120556. 13,13, 0,10,11,13,13, 0,12,12,13,13, 0, 0, 0,12,
  120557. 13,
  120558. };
  120559. static float _vq_quantthresh__44c8_s_p2_0[] = {
  120560. -1.5, -0.5, 0.5, 1.5,
  120561. };
  120562. static long _vq_quantmap__44c8_s_p2_0[] = {
  120563. 3, 1, 0, 2, 4,
  120564. };
  120565. static encode_aux_threshmatch _vq_auxt__44c8_s_p2_0 = {
  120566. _vq_quantthresh__44c8_s_p2_0,
  120567. _vq_quantmap__44c8_s_p2_0,
  120568. 5,
  120569. 5
  120570. };
  120571. static static_codebook _44c8_s_p2_0 = {
  120572. 4, 625,
  120573. _vq_lengthlist__44c8_s_p2_0,
  120574. 1, -533725184, 1611661312, 3, 0,
  120575. _vq_quantlist__44c8_s_p2_0,
  120576. NULL,
  120577. &_vq_auxt__44c8_s_p2_0,
  120578. NULL,
  120579. 0
  120580. };
  120581. static long _vq_quantlist__44c8_s_p3_0[] = {
  120582. 4,
  120583. 3,
  120584. 5,
  120585. 2,
  120586. 6,
  120587. 1,
  120588. 7,
  120589. 0,
  120590. 8,
  120591. };
  120592. static long _vq_lengthlist__44c8_s_p3_0[] = {
  120593. 2, 4, 4, 5, 5, 7, 7, 9, 9, 0, 4, 4, 6, 6, 7, 7,
  120594. 9, 9, 0, 4, 4, 6, 6, 7, 7, 9, 9, 0, 5, 5, 6, 6,
  120595. 8, 8,10,10, 0, 0, 0, 6, 6, 8, 8,10,10, 0, 0, 0,
  120596. 7, 7, 9, 9,10,10, 0, 0, 0, 7, 7, 8, 8,10,10, 0,
  120597. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120598. 0,
  120599. };
  120600. static float _vq_quantthresh__44c8_s_p3_0[] = {
  120601. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  120602. };
  120603. static long _vq_quantmap__44c8_s_p3_0[] = {
  120604. 7, 5, 3, 1, 0, 2, 4, 6,
  120605. 8,
  120606. };
  120607. static encode_aux_threshmatch _vq_auxt__44c8_s_p3_0 = {
  120608. _vq_quantthresh__44c8_s_p3_0,
  120609. _vq_quantmap__44c8_s_p3_0,
  120610. 9,
  120611. 9
  120612. };
  120613. static static_codebook _44c8_s_p3_0 = {
  120614. 2, 81,
  120615. _vq_lengthlist__44c8_s_p3_0,
  120616. 1, -531628032, 1611661312, 4, 0,
  120617. _vq_quantlist__44c8_s_p3_0,
  120618. NULL,
  120619. &_vq_auxt__44c8_s_p3_0,
  120620. NULL,
  120621. 0
  120622. };
  120623. static long _vq_quantlist__44c8_s_p4_0[] = {
  120624. 8,
  120625. 7,
  120626. 9,
  120627. 6,
  120628. 10,
  120629. 5,
  120630. 11,
  120631. 4,
  120632. 12,
  120633. 3,
  120634. 13,
  120635. 2,
  120636. 14,
  120637. 1,
  120638. 15,
  120639. 0,
  120640. 16,
  120641. };
  120642. static long _vq_lengthlist__44c8_s_p4_0[] = {
  120643. 3, 4, 4, 5, 5, 7, 7, 8, 8, 8, 8, 9, 9,10,10,11,
  120644. 11, 0, 4, 4, 6, 6, 7, 7, 8, 8, 9, 8,10,10,11,11,
  120645. 11,11, 0, 4, 4, 6, 6, 7, 7, 8, 8, 9, 9,10,10,11,
  120646. 11,11,11, 0, 6, 5, 6, 6, 7, 7, 9, 9, 9, 9,10,10,
  120647. 11,11,12,12, 0, 0, 0, 6, 6, 7, 7, 9, 9, 9, 9,10,
  120648. 10,11,11,12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9,10,10,
  120649. 11,11,11,12,12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9,10,
  120650. 10,11,11,11,12,12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9,
  120651. 10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 8, 8, 9,
  120652. 9,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 0, 0,
  120653. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120654. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120655. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120656. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120657. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120658. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120659. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120660. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120661. 0,
  120662. };
  120663. static float _vq_quantthresh__44c8_s_p4_0[] = {
  120664. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  120665. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  120666. };
  120667. static long _vq_quantmap__44c8_s_p4_0[] = {
  120668. 15, 13, 11, 9, 7, 5, 3, 1,
  120669. 0, 2, 4, 6, 8, 10, 12, 14,
  120670. 16,
  120671. };
  120672. static encode_aux_threshmatch _vq_auxt__44c8_s_p4_0 = {
  120673. _vq_quantthresh__44c8_s_p4_0,
  120674. _vq_quantmap__44c8_s_p4_0,
  120675. 17,
  120676. 17
  120677. };
  120678. static static_codebook _44c8_s_p4_0 = {
  120679. 2, 289,
  120680. _vq_lengthlist__44c8_s_p4_0,
  120681. 1, -529530880, 1611661312, 5, 0,
  120682. _vq_quantlist__44c8_s_p4_0,
  120683. NULL,
  120684. &_vq_auxt__44c8_s_p4_0,
  120685. NULL,
  120686. 0
  120687. };
  120688. static long _vq_quantlist__44c8_s_p5_0[] = {
  120689. 1,
  120690. 0,
  120691. 2,
  120692. };
  120693. static long _vq_lengthlist__44c8_s_p5_0[] = {
  120694. 1, 4, 4, 5, 7, 7, 6, 7, 7, 4, 7, 6,10,10,10,10,
  120695. 10,10, 4, 6, 6,10,10,10,10, 9,10, 5,10,10, 9,11,
  120696. 11,10,11,11, 7,10,10,11,12,12,12,12,12, 7,10,10,
  120697. 11,12,12,12,12,12, 6,10,10,10,12,12,10,12,12, 7,
  120698. 10,10,11,12,12,12,12,12, 7,10,10,11,12,12,12,12,
  120699. 12,
  120700. };
  120701. static float _vq_quantthresh__44c8_s_p5_0[] = {
  120702. -5.5, 5.5,
  120703. };
  120704. static long _vq_quantmap__44c8_s_p5_0[] = {
  120705. 1, 0, 2,
  120706. };
  120707. static encode_aux_threshmatch _vq_auxt__44c8_s_p5_0 = {
  120708. _vq_quantthresh__44c8_s_p5_0,
  120709. _vq_quantmap__44c8_s_p5_0,
  120710. 3,
  120711. 3
  120712. };
  120713. static static_codebook _44c8_s_p5_0 = {
  120714. 4, 81,
  120715. _vq_lengthlist__44c8_s_p5_0,
  120716. 1, -529137664, 1618345984, 2, 0,
  120717. _vq_quantlist__44c8_s_p5_0,
  120718. NULL,
  120719. &_vq_auxt__44c8_s_p5_0,
  120720. NULL,
  120721. 0
  120722. };
  120723. static long _vq_quantlist__44c8_s_p5_1[] = {
  120724. 5,
  120725. 4,
  120726. 6,
  120727. 3,
  120728. 7,
  120729. 2,
  120730. 8,
  120731. 1,
  120732. 9,
  120733. 0,
  120734. 10,
  120735. };
  120736. static long _vq_lengthlist__44c8_s_p5_1[] = {
  120737. 3, 5, 5, 6, 6, 7, 7, 8, 8, 8, 8,11, 4, 5, 6, 6,
  120738. 7, 7, 8, 8, 8, 8,11, 5, 5, 6, 6, 7, 7, 8, 8, 8,
  120739. 9,12, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9,12,12,12, 6,
  120740. 6, 7, 7, 8, 8, 9, 9,11,11,11, 6, 6, 7, 7, 8, 8,
  120741. 8, 8,11,11,11, 6, 6, 7, 7, 8, 8, 8, 8,11,11,11,
  120742. 7, 7, 7, 8, 8, 8, 8, 8,11,11,11,11,11, 7, 7, 8,
  120743. 8, 8, 8,11,11,11,11,11, 7, 7, 7, 7, 8, 8,11,11,
  120744. 11,11,11, 7, 7, 7, 7, 8, 8,
  120745. };
  120746. static float _vq_quantthresh__44c8_s_p5_1[] = {
  120747. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  120748. 3.5, 4.5,
  120749. };
  120750. static long _vq_quantmap__44c8_s_p5_1[] = {
  120751. 9, 7, 5, 3, 1, 0, 2, 4,
  120752. 6, 8, 10,
  120753. };
  120754. static encode_aux_threshmatch _vq_auxt__44c8_s_p5_1 = {
  120755. _vq_quantthresh__44c8_s_p5_1,
  120756. _vq_quantmap__44c8_s_p5_1,
  120757. 11,
  120758. 11
  120759. };
  120760. static static_codebook _44c8_s_p5_1 = {
  120761. 2, 121,
  120762. _vq_lengthlist__44c8_s_p5_1,
  120763. 1, -531365888, 1611661312, 4, 0,
  120764. _vq_quantlist__44c8_s_p5_1,
  120765. NULL,
  120766. &_vq_auxt__44c8_s_p5_1,
  120767. NULL,
  120768. 0
  120769. };
  120770. static long _vq_quantlist__44c8_s_p6_0[] = {
  120771. 6,
  120772. 5,
  120773. 7,
  120774. 4,
  120775. 8,
  120776. 3,
  120777. 9,
  120778. 2,
  120779. 10,
  120780. 1,
  120781. 11,
  120782. 0,
  120783. 12,
  120784. };
  120785. static long _vq_lengthlist__44c8_s_p6_0[] = {
  120786. 1, 4, 4, 6, 6, 7, 7, 8, 8, 9, 9,10,10, 6, 5, 5,
  120787. 7, 7, 8, 8, 9, 9,10,10,11,11, 6, 5, 5, 7, 7, 8,
  120788. 8, 9, 9,10,10,11,11, 0, 7, 7, 7, 7, 9, 9,10,10,
  120789. 10,10,11,11, 0, 7, 7, 7, 7, 9, 9,10,10,10,10,11,
  120790. 11, 0,11,11, 9, 9,10,10,11,11,11,11,12,12, 0,12,
  120791. 12, 9, 9,10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0,
  120792. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120793. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120794. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120795. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120796. 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120797. };
  120798. static float _vq_quantthresh__44c8_s_p6_0[] = {
  120799. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  120800. 12.5, 17.5, 22.5, 27.5,
  120801. };
  120802. static long _vq_quantmap__44c8_s_p6_0[] = {
  120803. 11, 9, 7, 5, 3, 1, 0, 2,
  120804. 4, 6, 8, 10, 12,
  120805. };
  120806. static encode_aux_threshmatch _vq_auxt__44c8_s_p6_0 = {
  120807. _vq_quantthresh__44c8_s_p6_0,
  120808. _vq_quantmap__44c8_s_p6_0,
  120809. 13,
  120810. 13
  120811. };
  120812. static static_codebook _44c8_s_p6_0 = {
  120813. 2, 169,
  120814. _vq_lengthlist__44c8_s_p6_0,
  120815. 1, -526516224, 1616117760, 4, 0,
  120816. _vq_quantlist__44c8_s_p6_0,
  120817. NULL,
  120818. &_vq_auxt__44c8_s_p6_0,
  120819. NULL,
  120820. 0
  120821. };
  120822. static long _vq_quantlist__44c8_s_p6_1[] = {
  120823. 2,
  120824. 1,
  120825. 3,
  120826. 0,
  120827. 4,
  120828. };
  120829. static long _vq_lengthlist__44c8_s_p6_1[] = {
  120830. 3, 4, 4, 5, 5, 5, 4, 4, 5, 5, 5, 4, 4, 5, 5, 6,
  120831. 5, 5, 5, 5, 6, 6, 6, 5, 5,
  120832. };
  120833. static float _vq_quantthresh__44c8_s_p6_1[] = {
  120834. -1.5, -0.5, 0.5, 1.5,
  120835. };
  120836. static long _vq_quantmap__44c8_s_p6_1[] = {
  120837. 3, 1, 0, 2, 4,
  120838. };
  120839. static encode_aux_threshmatch _vq_auxt__44c8_s_p6_1 = {
  120840. _vq_quantthresh__44c8_s_p6_1,
  120841. _vq_quantmap__44c8_s_p6_1,
  120842. 5,
  120843. 5
  120844. };
  120845. static static_codebook _44c8_s_p6_1 = {
  120846. 2, 25,
  120847. _vq_lengthlist__44c8_s_p6_1,
  120848. 1, -533725184, 1611661312, 3, 0,
  120849. _vq_quantlist__44c8_s_p6_1,
  120850. NULL,
  120851. &_vq_auxt__44c8_s_p6_1,
  120852. NULL,
  120853. 0
  120854. };
  120855. static long _vq_quantlist__44c8_s_p7_0[] = {
  120856. 6,
  120857. 5,
  120858. 7,
  120859. 4,
  120860. 8,
  120861. 3,
  120862. 9,
  120863. 2,
  120864. 10,
  120865. 1,
  120866. 11,
  120867. 0,
  120868. 12,
  120869. };
  120870. static long _vq_lengthlist__44c8_s_p7_0[] = {
  120871. 1, 4, 4, 6, 6, 8, 7, 9, 9,10,10,12,12, 6, 5, 5,
  120872. 7, 7, 8, 8,10,10,11,11,12,12, 7, 5, 5, 7, 7, 8,
  120873. 8,10,10,11,11,12,12,21, 7, 7, 7, 7, 8, 9,10,10,
  120874. 11,11,12,12,21, 7, 7, 7, 7, 9, 9,10,10,12,12,13,
  120875. 13,21,11,11, 8, 8, 9, 9,11,11,12,12,13,13,21,11,
  120876. 11, 8, 8, 9, 9,11,11,12,12,13,13,21,21,21,10,10,
  120877. 10,10,11,11,12,13,13,13,21,21,21,10,10,10,10,11,
  120878. 11,13,13,14,13,21,21,21,13,13,11,11,12,12,13,13,
  120879. 14,14,21,21,21,14,14,11,11,12,12,13,13,14,14,21,
  120880. 21,21,21,20,13,13,13,12,14,14,16,15,20,20,20,20,
  120881. 20,13,13,13,13,14,13,15,15,
  120882. };
  120883. static float _vq_quantthresh__44c8_s_p7_0[] = {
  120884. -60.5, -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5,
  120885. 27.5, 38.5, 49.5, 60.5,
  120886. };
  120887. static long _vq_quantmap__44c8_s_p7_0[] = {
  120888. 11, 9, 7, 5, 3, 1, 0, 2,
  120889. 4, 6, 8, 10, 12,
  120890. };
  120891. static encode_aux_threshmatch _vq_auxt__44c8_s_p7_0 = {
  120892. _vq_quantthresh__44c8_s_p7_0,
  120893. _vq_quantmap__44c8_s_p7_0,
  120894. 13,
  120895. 13
  120896. };
  120897. static static_codebook _44c8_s_p7_0 = {
  120898. 2, 169,
  120899. _vq_lengthlist__44c8_s_p7_0,
  120900. 1, -523206656, 1618345984, 4, 0,
  120901. _vq_quantlist__44c8_s_p7_0,
  120902. NULL,
  120903. &_vq_auxt__44c8_s_p7_0,
  120904. NULL,
  120905. 0
  120906. };
  120907. static long _vq_quantlist__44c8_s_p7_1[] = {
  120908. 5,
  120909. 4,
  120910. 6,
  120911. 3,
  120912. 7,
  120913. 2,
  120914. 8,
  120915. 1,
  120916. 9,
  120917. 0,
  120918. 10,
  120919. };
  120920. static long _vq_lengthlist__44c8_s_p7_1[] = {
  120921. 4, 5, 6, 6, 6, 7, 7, 7, 7, 7, 7, 8, 6, 6, 6, 7,
  120922. 7, 7, 7, 7, 7, 7, 8, 6, 6, 6, 6, 7, 7, 7, 7, 7,
  120923. 7, 8, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 7,
  120924. 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 7, 7, 7, 7, 7, 7,
  120925. 7, 7, 8, 8, 8, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8,
  120926. 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 7, 7, 7,
  120927. 7, 7, 7, 8, 8, 8, 8, 8, 7, 7, 7, 7, 7, 7, 8, 8,
  120928. 8, 8, 8, 7, 7, 7, 7, 7, 7,
  120929. };
  120930. static float _vq_quantthresh__44c8_s_p7_1[] = {
  120931. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  120932. 3.5, 4.5,
  120933. };
  120934. static long _vq_quantmap__44c8_s_p7_1[] = {
  120935. 9, 7, 5, 3, 1, 0, 2, 4,
  120936. 6, 8, 10,
  120937. };
  120938. static encode_aux_threshmatch _vq_auxt__44c8_s_p7_1 = {
  120939. _vq_quantthresh__44c8_s_p7_1,
  120940. _vq_quantmap__44c8_s_p7_1,
  120941. 11,
  120942. 11
  120943. };
  120944. static static_codebook _44c8_s_p7_1 = {
  120945. 2, 121,
  120946. _vq_lengthlist__44c8_s_p7_1,
  120947. 1, -531365888, 1611661312, 4, 0,
  120948. _vq_quantlist__44c8_s_p7_1,
  120949. NULL,
  120950. &_vq_auxt__44c8_s_p7_1,
  120951. NULL,
  120952. 0
  120953. };
  120954. static long _vq_quantlist__44c8_s_p8_0[] = {
  120955. 7,
  120956. 6,
  120957. 8,
  120958. 5,
  120959. 9,
  120960. 4,
  120961. 10,
  120962. 3,
  120963. 11,
  120964. 2,
  120965. 12,
  120966. 1,
  120967. 13,
  120968. 0,
  120969. 14,
  120970. };
  120971. static long _vq_lengthlist__44c8_s_p8_0[] = {
  120972. 1, 4, 4, 7, 6, 8, 8, 8, 7, 9, 8,10,10,11,10, 6,
  120973. 5, 5, 7, 7, 9, 9, 8, 8,10,10,11,11,12,11, 6, 5,
  120974. 5, 7, 7, 9, 9, 9, 9,10,10,11,11,12,12,20, 8, 8,
  120975. 8, 8, 9, 9, 9, 9,10,10,11,11,12,12,20, 8, 8, 8,
  120976. 8,10, 9, 9, 9,10,10,11,11,12,12,20,12,12, 9, 9,
  120977. 10,10,10,10,10,11,12,12,12,12,20,12,12, 9, 9,10,
  120978. 10,10,10,11,11,12,12,13,13,20,20,20, 9, 9, 9, 9,
  120979. 11,10,11,11,12,12,12,13,20,19,19, 9, 9, 9, 9,11,
  120980. 11,11,12,12,12,13,13,19,19,19,13,13,10,10,11,11,
  120981. 12,12,13,13,13,13,19,19,19,14,13,11,10,11,11,12,
  120982. 12,12,13,13,13,19,19,19,19,19,12,12,12,12,13,13,
  120983. 13,13,14,13,19,19,19,19,19,12,12,12,11,12,12,13,
  120984. 14,14,14,19,19,19,19,19,16,15,13,12,13,13,13,14,
  120985. 14,14,19,19,19,19,19,17,17,13,12,13,11,14,13,15,
  120986. 15,
  120987. };
  120988. static float _vq_quantthresh__44c8_s_p8_0[] = {
  120989. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  120990. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  120991. };
  120992. static long _vq_quantmap__44c8_s_p8_0[] = {
  120993. 13, 11, 9, 7, 5, 3, 1, 0,
  120994. 2, 4, 6, 8, 10, 12, 14,
  120995. };
  120996. static encode_aux_threshmatch _vq_auxt__44c8_s_p8_0 = {
  120997. _vq_quantthresh__44c8_s_p8_0,
  120998. _vq_quantmap__44c8_s_p8_0,
  120999. 15,
  121000. 15
  121001. };
  121002. static static_codebook _44c8_s_p8_0 = {
  121003. 2, 225,
  121004. _vq_lengthlist__44c8_s_p8_0,
  121005. 1, -520986624, 1620377600, 4, 0,
  121006. _vq_quantlist__44c8_s_p8_0,
  121007. NULL,
  121008. &_vq_auxt__44c8_s_p8_0,
  121009. NULL,
  121010. 0
  121011. };
  121012. static long _vq_quantlist__44c8_s_p8_1[] = {
  121013. 10,
  121014. 9,
  121015. 11,
  121016. 8,
  121017. 12,
  121018. 7,
  121019. 13,
  121020. 6,
  121021. 14,
  121022. 5,
  121023. 15,
  121024. 4,
  121025. 16,
  121026. 3,
  121027. 17,
  121028. 2,
  121029. 18,
  121030. 1,
  121031. 19,
  121032. 0,
  121033. 20,
  121034. };
  121035. static long _vq_lengthlist__44c8_s_p8_1[] = {
  121036. 4, 5, 5, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  121037. 8, 8, 8, 8, 8,10, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,
  121038. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10, 6, 6, 7, 7, 8,
  121039. 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,
  121040. 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  121041. 9, 9, 9, 9,10,10,10, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  121042. 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10,10, 8, 8, 8, 9,
  121043. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10,
  121044. 10, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  121045. 9, 9, 9,10,10,10, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  121046. 9, 9, 9, 9, 9, 9, 9, 9,10,10,10,10,10, 9, 9, 9,
  121047. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10,10,
  121048. 10,10, 9, 9, 9, 9, 9, 9, 9, 9,10, 9, 9, 9, 9, 9,
  121049. 9, 9,10,10,10,10,10, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  121050. 9, 9, 9, 9, 9, 9, 9,10,10,10,10,10, 9, 9, 9, 9,
  121051. 9, 9, 9, 9,10,10,10, 9, 9, 9, 9, 9,10,10,10,10,
  121052. 10,10,10, 9, 9, 9, 9, 9,10,10,10, 9, 9, 9, 9, 9,
  121053. 9,10,10,10,10,10,10,10, 9,10,10, 9,10,10,10,10,
  121054. 9,10, 9,10,10, 9,10,10,10,10,10,10,10, 9,10,10,
  121055. 10,10,10,10, 9, 9,10,10, 9,10,10,10,10,10,10,10,
  121056. 10,10,10,10,10,10,10,10, 9, 9, 9,10, 9, 9, 9, 9,
  121057. 10,10,10,10,10,10,10,10,10,10,10,10,10,10, 9, 9,
  121058. 10, 9,10, 9,10,10,10,10,10,10,10,10,10,10,10,10,
  121059. 10,10,10,10, 9, 9,10, 9, 9, 9,10,10,10,10,10,10,
  121060. 10,10,10,10,10, 9, 9, 9, 9, 9, 9,10, 9, 9,10,10,
  121061. 10,10,10,10,10,10,10,10,10,10,10,10,10, 9,10, 9,
  121062. 9,10, 9, 9,10,10,10,10,10,10,10,10,10,10,10,10,
  121063. 10, 9, 9,10,10, 9,10, 9, 9,
  121064. };
  121065. static float _vq_quantthresh__44c8_s_p8_1[] = {
  121066. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  121067. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  121068. 6.5, 7.5, 8.5, 9.5,
  121069. };
  121070. static long _vq_quantmap__44c8_s_p8_1[] = {
  121071. 19, 17, 15, 13, 11, 9, 7, 5,
  121072. 3, 1, 0, 2, 4, 6, 8, 10,
  121073. 12, 14, 16, 18, 20,
  121074. };
  121075. static encode_aux_threshmatch _vq_auxt__44c8_s_p8_1 = {
  121076. _vq_quantthresh__44c8_s_p8_1,
  121077. _vq_quantmap__44c8_s_p8_1,
  121078. 21,
  121079. 21
  121080. };
  121081. static static_codebook _44c8_s_p8_1 = {
  121082. 2, 441,
  121083. _vq_lengthlist__44c8_s_p8_1,
  121084. 1, -529268736, 1611661312, 5, 0,
  121085. _vq_quantlist__44c8_s_p8_1,
  121086. NULL,
  121087. &_vq_auxt__44c8_s_p8_1,
  121088. NULL,
  121089. 0
  121090. };
  121091. static long _vq_quantlist__44c8_s_p9_0[] = {
  121092. 8,
  121093. 7,
  121094. 9,
  121095. 6,
  121096. 10,
  121097. 5,
  121098. 11,
  121099. 4,
  121100. 12,
  121101. 3,
  121102. 13,
  121103. 2,
  121104. 14,
  121105. 1,
  121106. 15,
  121107. 0,
  121108. 16,
  121109. };
  121110. static long _vq_lengthlist__44c8_s_p9_0[] = {
  121111. 1, 4, 3,11,11,11,11,11,11,11,11,11,11,11,11,11,
  121112. 11, 4, 7, 7,11,11,11,11,11,11,11,11,11,11,11,11,
  121113. 11,11, 4, 8,11,11,11,11,11,11,11,11,11,11,11,11,
  121114. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  121115. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  121116. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  121117. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  121118. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  121119. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  121120. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  121121. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  121122. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  121123. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  121124. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  121125. 11,11,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  121126. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  121127. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  121128. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  121129. 10,
  121130. };
  121131. static float _vq_quantthresh__44c8_s_p9_0[] = {
  121132. -6982.5, -6051.5, -5120.5, -4189.5, -3258.5, -2327.5, -1396.5, -465.5,
  121133. 465.5, 1396.5, 2327.5, 3258.5, 4189.5, 5120.5, 6051.5, 6982.5,
  121134. };
  121135. static long _vq_quantmap__44c8_s_p9_0[] = {
  121136. 15, 13, 11, 9, 7, 5, 3, 1,
  121137. 0, 2, 4, 6, 8, 10, 12, 14,
  121138. 16,
  121139. };
  121140. static encode_aux_threshmatch _vq_auxt__44c8_s_p9_0 = {
  121141. _vq_quantthresh__44c8_s_p9_0,
  121142. _vq_quantmap__44c8_s_p9_0,
  121143. 17,
  121144. 17
  121145. };
  121146. static static_codebook _44c8_s_p9_0 = {
  121147. 2, 289,
  121148. _vq_lengthlist__44c8_s_p9_0,
  121149. 1, -509798400, 1631393792, 5, 0,
  121150. _vq_quantlist__44c8_s_p9_0,
  121151. NULL,
  121152. &_vq_auxt__44c8_s_p9_0,
  121153. NULL,
  121154. 0
  121155. };
  121156. static long _vq_quantlist__44c8_s_p9_1[] = {
  121157. 9,
  121158. 8,
  121159. 10,
  121160. 7,
  121161. 11,
  121162. 6,
  121163. 12,
  121164. 5,
  121165. 13,
  121166. 4,
  121167. 14,
  121168. 3,
  121169. 15,
  121170. 2,
  121171. 16,
  121172. 1,
  121173. 17,
  121174. 0,
  121175. 18,
  121176. };
  121177. static long _vq_lengthlist__44c8_s_p9_1[] = {
  121178. 1, 4, 4, 7, 6, 7, 7, 7, 7, 8, 8, 9, 9,10,10,10,
  121179. 10,11,11, 6, 6, 6, 8, 8, 9, 8, 8, 7,10, 8,11,10,
  121180. 12,11,12,12,13,13, 5, 5, 6, 8, 8, 9, 9, 8, 8,10,
  121181. 9,11,11,12,12,13,13,13,13,17, 8, 8, 9, 9, 9, 9,
  121182. 9, 9,10, 9,12,10,12,12,13,12,13,13,17, 9, 8, 9,
  121183. 9, 9, 9, 9, 9,10,10,12,12,12,12,13,13,13,13,17,
  121184. 13,13, 9, 9,10,10,10,10,11,11,12,11,13,12,13,13,
  121185. 14,15,17,13,13, 9, 8,10, 9,10,10,11,11,12,12,14,
  121186. 13,15,13,14,15,17,17,17, 9,10, 9,10,11,11,12,12,
  121187. 12,12,13,13,14,14,15,15,17,17,17, 9, 8, 9, 8,11,
  121188. 11,12,12,12,12,14,13,14,14,14,15,17,17,17,12,14,
  121189. 9,10,11,11,12,12,14,13,13,14,15,13,15,15,17,17,
  121190. 17,13,11,10, 8,11, 9,13,12,13,13,13,13,13,14,14,
  121191. 14,17,17,17,17,17,11,12,11,11,13,13,14,13,15,14,
  121192. 13,15,16,15,17,17,17,17,17,11,11,12, 8,13,12,14,
  121193. 13,17,14,15,14,15,14,17,17,17,17,17,15,15,12,12,
  121194. 12,12,13,14,14,14,15,14,17,14,17,17,17,17,17,16,
  121195. 17,12,12,13,12,13,13,14,14,14,14,14,14,17,17,17,
  121196. 17,17,17,17,14,14,13,12,13,13,15,15,14,13,15,17,
  121197. 17,17,17,17,17,17,17,13,14,13,13,13,13,14,15,15,
  121198. 15,14,15,17,17,17,17,17,17,17,16,15,13,14,13,13,
  121199. 14,14,15,14,14,16,17,17,17,17,17,17,17,16,16,13,
  121200. 14,13,13,14,14,15,14,15,14,
  121201. };
  121202. static float _vq_quantthresh__44c8_s_p9_1[] = {
  121203. -416.5, -367.5, -318.5, -269.5, -220.5, -171.5, -122.5, -73.5,
  121204. -24.5, 24.5, 73.5, 122.5, 171.5, 220.5, 269.5, 318.5,
  121205. 367.5, 416.5,
  121206. };
  121207. static long _vq_quantmap__44c8_s_p9_1[] = {
  121208. 17, 15, 13, 11, 9, 7, 5, 3,
  121209. 1, 0, 2, 4, 6, 8, 10, 12,
  121210. 14, 16, 18,
  121211. };
  121212. static encode_aux_threshmatch _vq_auxt__44c8_s_p9_1 = {
  121213. _vq_quantthresh__44c8_s_p9_1,
  121214. _vq_quantmap__44c8_s_p9_1,
  121215. 19,
  121216. 19
  121217. };
  121218. static static_codebook _44c8_s_p9_1 = {
  121219. 2, 361,
  121220. _vq_lengthlist__44c8_s_p9_1,
  121221. 1, -518287360, 1622704128, 5, 0,
  121222. _vq_quantlist__44c8_s_p9_1,
  121223. NULL,
  121224. &_vq_auxt__44c8_s_p9_1,
  121225. NULL,
  121226. 0
  121227. };
  121228. static long _vq_quantlist__44c8_s_p9_2[] = {
  121229. 24,
  121230. 23,
  121231. 25,
  121232. 22,
  121233. 26,
  121234. 21,
  121235. 27,
  121236. 20,
  121237. 28,
  121238. 19,
  121239. 29,
  121240. 18,
  121241. 30,
  121242. 17,
  121243. 31,
  121244. 16,
  121245. 32,
  121246. 15,
  121247. 33,
  121248. 14,
  121249. 34,
  121250. 13,
  121251. 35,
  121252. 12,
  121253. 36,
  121254. 11,
  121255. 37,
  121256. 10,
  121257. 38,
  121258. 9,
  121259. 39,
  121260. 8,
  121261. 40,
  121262. 7,
  121263. 41,
  121264. 6,
  121265. 42,
  121266. 5,
  121267. 43,
  121268. 4,
  121269. 44,
  121270. 3,
  121271. 45,
  121272. 2,
  121273. 46,
  121274. 1,
  121275. 47,
  121276. 0,
  121277. 48,
  121278. };
  121279. static long _vq_lengthlist__44c8_s_p9_2[] = {
  121280. 2, 4, 4, 4, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6,
  121281. 6, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  121282. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  121283. 7,
  121284. };
  121285. static float _vq_quantthresh__44c8_s_p9_2[] = {
  121286. -23.5, -22.5, -21.5, -20.5, -19.5, -18.5, -17.5, -16.5,
  121287. -15.5, -14.5, -13.5, -12.5, -11.5, -10.5, -9.5, -8.5,
  121288. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  121289. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  121290. 8.5, 9.5, 10.5, 11.5, 12.5, 13.5, 14.5, 15.5,
  121291. 16.5, 17.5, 18.5, 19.5, 20.5, 21.5, 22.5, 23.5,
  121292. };
  121293. static long _vq_quantmap__44c8_s_p9_2[] = {
  121294. 47, 45, 43, 41, 39, 37, 35, 33,
  121295. 31, 29, 27, 25, 23, 21, 19, 17,
  121296. 15, 13, 11, 9, 7, 5, 3, 1,
  121297. 0, 2, 4, 6, 8, 10, 12, 14,
  121298. 16, 18, 20, 22, 24, 26, 28, 30,
  121299. 32, 34, 36, 38, 40, 42, 44, 46,
  121300. 48,
  121301. };
  121302. static encode_aux_threshmatch _vq_auxt__44c8_s_p9_2 = {
  121303. _vq_quantthresh__44c8_s_p9_2,
  121304. _vq_quantmap__44c8_s_p9_2,
  121305. 49,
  121306. 49
  121307. };
  121308. static static_codebook _44c8_s_p9_2 = {
  121309. 1, 49,
  121310. _vq_lengthlist__44c8_s_p9_2,
  121311. 1, -526909440, 1611661312, 6, 0,
  121312. _vq_quantlist__44c8_s_p9_2,
  121313. NULL,
  121314. &_vq_auxt__44c8_s_p9_2,
  121315. NULL,
  121316. 0
  121317. };
  121318. static long _huff_lengthlist__44c8_s_short[] = {
  121319. 4,11,13,14,15,15,18,17,19,17, 5, 6, 8, 9,10,10,
  121320. 12,15,19,19, 6, 6, 6, 6, 8, 8,11,14,18,19, 8, 6,
  121321. 5, 4, 6, 7,10,13,16,17, 9, 7, 6, 5, 6, 7, 9,12,
  121322. 15,19,10, 8, 7, 6, 6, 6, 7, 9,13,15,12,10, 9, 8,
  121323. 7, 6, 4, 5,10,15,13,13,11, 8, 6, 6, 4, 2, 7,12,
  121324. 17,15,16,10, 8, 8, 7, 6, 9,12,19,18,17,13,11,10,
  121325. 10, 9,11,14,
  121326. };
  121327. static static_codebook _huff_book__44c8_s_short = {
  121328. 2, 100,
  121329. _huff_lengthlist__44c8_s_short,
  121330. 0, 0, 0, 0, 0,
  121331. NULL,
  121332. NULL,
  121333. NULL,
  121334. NULL,
  121335. 0
  121336. };
  121337. static long _huff_lengthlist__44c9_s_long[] = {
  121338. 3, 8,12,14,15,15,15,13,15,15, 6, 5, 8,10,12,12,
  121339. 13,12,14,13,10, 6, 5, 6, 8, 9,11,11,13,13,13, 8,
  121340. 5, 4, 5, 6, 8,10,11,13,14,10, 7, 5, 4, 5, 7, 9,
  121341. 11,12,13,11, 8, 6, 5, 4, 5, 7, 9,11,12,11,10, 8,
  121342. 7, 5, 4, 5, 9,10,13,13,11,10, 8, 6, 5, 4, 7, 9,
  121343. 15,14,13,12,10, 9, 8, 7, 8, 9,12,12,14,13,12,11,
  121344. 10, 9, 8, 9,
  121345. };
  121346. static static_codebook _huff_book__44c9_s_long = {
  121347. 2, 100,
  121348. _huff_lengthlist__44c9_s_long,
  121349. 0, 0, 0, 0, 0,
  121350. NULL,
  121351. NULL,
  121352. NULL,
  121353. NULL,
  121354. 0
  121355. };
  121356. static long _vq_quantlist__44c9_s_p1_0[] = {
  121357. 1,
  121358. 0,
  121359. 2,
  121360. };
  121361. static long _vq_lengthlist__44c9_s_p1_0[] = {
  121362. 1, 5, 5, 0, 5, 5, 0, 5, 5, 6, 8, 8, 0, 9, 8, 0,
  121363. 9, 8, 6, 8, 8, 0, 8, 9, 0, 8, 9, 0, 0, 0, 0, 0,
  121364. 0, 0, 0, 0, 5, 8, 8, 0, 7, 7, 0, 8, 8, 5, 8, 8,
  121365. 0, 7, 8, 0, 8, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5,
  121366. 9, 8, 0, 8, 8, 0, 7, 7, 5, 8, 9, 0, 8, 8, 0, 7,
  121367. 7,
  121368. };
  121369. static float _vq_quantthresh__44c9_s_p1_0[] = {
  121370. -0.5, 0.5,
  121371. };
  121372. static long _vq_quantmap__44c9_s_p1_0[] = {
  121373. 1, 0, 2,
  121374. };
  121375. static encode_aux_threshmatch _vq_auxt__44c9_s_p1_0 = {
  121376. _vq_quantthresh__44c9_s_p1_0,
  121377. _vq_quantmap__44c9_s_p1_0,
  121378. 3,
  121379. 3
  121380. };
  121381. static static_codebook _44c9_s_p1_0 = {
  121382. 4, 81,
  121383. _vq_lengthlist__44c9_s_p1_0,
  121384. 1, -535822336, 1611661312, 2, 0,
  121385. _vq_quantlist__44c9_s_p1_0,
  121386. NULL,
  121387. &_vq_auxt__44c9_s_p1_0,
  121388. NULL,
  121389. 0
  121390. };
  121391. static long _vq_quantlist__44c9_s_p2_0[] = {
  121392. 2,
  121393. 1,
  121394. 3,
  121395. 0,
  121396. 4,
  121397. };
  121398. static long _vq_lengthlist__44c9_s_p2_0[] = {
  121399. 3, 5, 5, 8, 8, 0, 5, 5, 8, 8, 0, 5, 5, 8, 8, 0,
  121400. 7, 7, 9, 9, 0, 0, 0, 9, 9, 6, 7, 7, 9, 8, 0, 8,
  121401. 8, 9, 9, 0, 8, 7, 9, 9, 0, 9,10,10,10, 0, 0, 0,
  121402. 11,10, 6, 7, 7, 8, 9, 0, 8, 8, 9, 9, 0, 7, 8, 9,
  121403. 9, 0,10, 9,11,10, 0, 0, 0,10,10, 8, 9, 8,10,10,
  121404. 0,10,10,12,11, 0,10,10,11,11, 0,12,13,13,13, 0,
  121405. 0, 0,13,12, 8, 8, 9,10,10, 0,10,10,11,12, 0,10,
  121406. 10,11,11, 0,13,12,13,13, 0, 0, 0,13,13, 0, 0, 0,
  121407. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121408. 0, 0, 0, 0, 0, 0, 6, 8, 7,10,10, 0, 7, 7,10, 9,
  121409. 0, 7, 7,10,10, 0, 9, 9,10,10, 0, 0, 0,10,10, 6,
  121410. 7, 8,10,10, 0, 7, 7, 9,10, 0, 7, 7,10,10, 0, 9,
  121411. 9,10,10, 0, 0, 0,10,10, 8, 9, 9,11,11, 0,10,10,
  121412. 11,11, 0,10,10,11,11, 0,12,12,12,12, 0, 0, 0,12,
  121413. 12, 8, 9,10,11,11, 0, 9,10,11,11, 0,10,10,11,11,
  121414. 0,12,12,12,12, 0, 0, 0,12,12, 0, 0, 0, 0, 0, 0,
  121415. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121416. 0, 0, 0, 5, 8, 7,10,10, 0, 7, 7,10,10, 0, 7, 7,
  121417. 10, 9, 0, 9, 9,10,10, 0, 0, 0,10,10, 6, 7, 8,10,
  121418. 10, 0, 7, 7,10,10, 0, 7, 7, 9,10, 0, 9, 9,10,10,
  121419. 0, 0, 0,10,10, 8,10, 9,12,11, 0,10,10,12,11, 0,
  121420. 10, 9,11,11, 0,11,12,12,12, 0, 0, 0,12,12, 8, 9,
  121421. 10,11,12, 0,10,10,11,11, 0, 9,10,11,11, 0,12,11,
  121422. 12,12, 0, 0, 0,12,12, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121423. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121424. 7,10, 9,12,12, 0, 9, 9,12,11, 0, 9, 9,11,11, 0,
  121425. 10,10,12,11, 0, 0, 0,11,12, 7, 9,10,12,12, 0, 9,
  121426. 9,11,12, 0, 9, 9,11,11, 0,10,10,11,12, 0, 0, 0,
  121427. 11,11, 9,11,10,13,12, 0,10,10,12,12, 0,10,10,12,
  121428. 12, 0,11,11,12,12, 0, 0, 0,13,12, 9,10,11,12,13,
  121429. 0,10,10,12,12, 0,10,10,12,12, 0,11,12,12,12, 0,
  121430. 0, 0,12,13, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121431. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121432. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121433. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121434. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9,
  121435. 11,10,13,13, 0,10,10,12,12, 0,10,10,12,12, 0,11,
  121436. 12,12,12, 0, 0, 0,12,12, 9,10,11,13,13, 0,10,10,
  121437. 12,12, 0,10,10,12,12, 0,12,11,13,12, 0, 0, 0,12,
  121438. 12,
  121439. };
  121440. static float _vq_quantthresh__44c9_s_p2_0[] = {
  121441. -1.5, -0.5, 0.5, 1.5,
  121442. };
  121443. static long _vq_quantmap__44c9_s_p2_0[] = {
  121444. 3, 1, 0, 2, 4,
  121445. };
  121446. static encode_aux_threshmatch _vq_auxt__44c9_s_p2_0 = {
  121447. _vq_quantthresh__44c9_s_p2_0,
  121448. _vq_quantmap__44c9_s_p2_0,
  121449. 5,
  121450. 5
  121451. };
  121452. static static_codebook _44c9_s_p2_0 = {
  121453. 4, 625,
  121454. _vq_lengthlist__44c9_s_p2_0,
  121455. 1, -533725184, 1611661312, 3, 0,
  121456. _vq_quantlist__44c9_s_p2_0,
  121457. NULL,
  121458. &_vq_auxt__44c9_s_p2_0,
  121459. NULL,
  121460. 0
  121461. };
  121462. static long _vq_quantlist__44c9_s_p3_0[] = {
  121463. 4,
  121464. 3,
  121465. 5,
  121466. 2,
  121467. 6,
  121468. 1,
  121469. 7,
  121470. 0,
  121471. 8,
  121472. };
  121473. static long _vq_lengthlist__44c9_s_p3_0[] = {
  121474. 3, 4, 4, 5, 5, 6, 6, 8, 8, 0, 4, 4, 5, 5, 6, 7,
  121475. 8, 8, 0, 4, 4, 5, 5, 7, 7, 8, 8, 0, 5, 5, 6, 6,
  121476. 7, 7, 9, 9, 0, 0, 0, 6, 6, 7, 7, 9, 9, 0, 0, 0,
  121477. 7, 7, 8, 8, 9, 9, 0, 0, 0, 7, 7, 8, 8, 9, 9, 0,
  121478. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121479. 0,
  121480. };
  121481. static float _vq_quantthresh__44c9_s_p3_0[] = {
  121482. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  121483. };
  121484. static long _vq_quantmap__44c9_s_p3_0[] = {
  121485. 7, 5, 3, 1, 0, 2, 4, 6,
  121486. 8,
  121487. };
  121488. static encode_aux_threshmatch _vq_auxt__44c9_s_p3_0 = {
  121489. _vq_quantthresh__44c9_s_p3_0,
  121490. _vq_quantmap__44c9_s_p3_0,
  121491. 9,
  121492. 9
  121493. };
  121494. static static_codebook _44c9_s_p3_0 = {
  121495. 2, 81,
  121496. _vq_lengthlist__44c9_s_p3_0,
  121497. 1, -531628032, 1611661312, 4, 0,
  121498. _vq_quantlist__44c9_s_p3_0,
  121499. NULL,
  121500. &_vq_auxt__44c9_s_p3_0,
  121501. NULL,
  121502. 0
  121503. };
  121504. static long _vq_quantlist__44c9_s_p4_0[] = {
  121505. 8,
  121506. 7,
  121507. 9,
  121508. 6,
  121509. 10,
  121510. 5,
  121511. 11,
  121512. 4,
  121513. 12,
  121514. 3,
  121515. 13,
  121516. 2,
  121517. 14,
  121518. 1,
  121519. 15,
  121520. 0,
  121521. 16,
  121522. };
  121523. static long _vq_lengthlist__44c9_s_p4_0[] = {
  121524. 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9,10,10,10,
  121525. 10, 0, 5, 4, 5, 5, 7, 7, 8, 8, 8, 8, 9, 9,10,10,
  121526. 11,11, 0, 5, 5, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,10,
  121527. 10,11,11, 0, 6, 5, 6, 6, 7, 7, 8, 8, 9, 9,10,10,
  121528. 11,11,11,12, 0, 0, 0, 6, 6, 7, 7, 8, 8, 9, 9,10,
  121529. 10,11,11,12,12, 0, 0, 0, 7, 7, 7, 7, 9, 9, 9, 9,
  121530. 10,10,11,11,12,12, 0, 0, 0, 7, 7, 7, 8, 9, 9, 9,
  121531. 9,10,10,11,11,12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9,
  121532. 10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 8, 8, 9,
  121533. 9,10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 0, 0,
  121534. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121535. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121536. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121537. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121538. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121539. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121540. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121541. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121542. 0,
  121543. };
  121544. static float _vq_quantthresh__44c9_s_p4_0[] = {
  121545. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  121546. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  121547. };
  121548. static long _vq_quantmap__44c9_s_p4_0[] = {
  121549. 15, 13, 11, 9, 7, 5, 3, 1,
  121550. 0, 2, 4, 6, 8, 10, 12, 14,
  121551. 16,
  121552. };
  121553. static encode_aux_threshmatch _vq_auxt__44c9_s_p4_0 = {
  121554. _vq_quantthresh__44c9_s_p4_0,
  121555. _vq_quantmap__44c9_s_p4_0,
  121556. 17,
  121557. 17
  121558. };
  121559. static static_codebook _44c9_s_p4_0 = {
  121560. 2, 289,
  121561. _vq_lengthlist__44c9_s_p4_0,
  121562. 1, -529530880, 1611661312, 5, 0,
  121563. _vq_quantlist__44c9_s_p4_0,
  121564. NULL,
  121565. &_vq_auxt__44c9_s_p4_0,
  121566. NULL,
  121567. 0
  121568. };
  121569. static long _vq_quantlist__44c9_s_p5_0[] = {
  121570. 1,
  121571. 0,
  121572. 2,
  121573. };
  121574. static long _vq_lengthlist__44c9_s_p5_0[] = {
  121575. 1, 4, 4, 5, 7, 7, 6, 7, 7, 4, 7, 6, 9,10,10,10,
  121576. 10, 9, 4, 6, 7, 9,10,10,10, 9,10, 5, 9, 9, 9,11,
  121577. 11,10,11,11, 7,10, 9,11,12,11,12,12,12, 7, 9,10,
  121578. 11,11,12,12,12,12, 6,10,10,10,12,12,10,12,11, 7,
  121579. 10,10,11,12,12,11,12,12, 7,10,10,11,12,12,12,12,
  121580. 12,
  121581. };
  121582. static float _vq_quantthresh__44c9_s_p5_0[] = {
  121583. -5.5, 5.5,
  121584. };
  121585. static long _vq_quantmap__44c9_s_p5_0[] = {
  121586. 1, 0, 2,
  121587. };
  121588. static encode_aux_threshmatch _vq_auxt__44c9_s_p5_0 = {
  121589. _vq_quantthresh__44c9_s_p5_0,
  121590. _vq_quantmap__44c9_s_p5_0,
  121591. 3,
  121592. 3
  121593. };
  121594. static static_codebook _44c9_s_p5_0 = {
  121595. 4, 81,
  121596. _vq_lengthlist__44c9_s_p5_0,
  121597. 1, -529137664, 1618345984, 2, 0,
  121598. _vq_quantlist__44c9_s_p5_0,
  121599. NULL,
  121600. &_vq_auxt__44c9_s_p5_0,
  121601. NULL,
  121602. 0
  121603. };
  121604. static long _vq_quantlist__44c9_s_p5_1[] = {
  121605. 5,
  121606. 4,
  121607. 6,
  121608. 3,
  121609. 7,
  121610. 2,
  121611. 8,
  121612. 1,
  121613. 9,
  121614. 0,
  121615. 10,
  121616. };
  121617. static long _vq_lengthlist__44c9_s_p5_1[] = {
  121618. 4, 5, 5, 6, 6, 7, 7, 7, 7, 7, 7,11, 5, 5, 6, 6,
  121619. 7, 7, 7, 7, 8, 8,11, 5, 5, 6, 6, 7, 7, 7, 7, 8,
  121620. 8,11, 5, 5, 6, 6, 7, 7, 8, 8, 8, 8,11,11,11, 6,
  121621. 6, 7, 7, 7, 8, 8, 8,11,11,11, 6, 6, 7, 7, 7, 8,
  121622. 8, 8,11,11,11, 6, 6, 7, 7, 7, 7, 8, 8,11,11,11,
  121623. 7, 7, 7, 7, 7, 7, 8, 8,11,11,11,10,10, 7, 7, 7,
  121624. 7, 8, 8,11,11,11,11,11, 7, 7, 7, 7, 7, 7,11,11,
  121625. 11,11,11, 7, 7, 7, 7, 7, 7,
  121626. };
  121627. static float _vq_quantthresh__44c9_s_p5_1[] = {
  121628. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  121629. 3.5, 4.5,
  121630. };
  121631. static long _vq_quantmap__44c9_s_p5_1[] = {
  121632. 9, 7, 5, 3, 1, 0, 2, 4,
  121633. 6, 8, 10,
  121634. };
  121635. static encode_aux_threshmatch _vq_auxt__44c9_s_p5_1 = {
  121636. _vq_quantthresh__44c9_s_p5_1,
  121637. _vq_quantmap__44c9_s_p5_1,
  121638. 11,
  121639. 11
  121640. };
  121641. static static_codebook _44c9_s_p5_1 = {
  121642. 2, 121,
  121643. _vq_lengthlist__44c9_s_p5_1,
  121644. 1, -531365888, 1611661312, 4, 0,
  121645. _vq_quantlist__44c9_s_p5_1,
  121646. NULL,
  121647. &_vq_auxt__44c9_s_p5_1,
  121648. NULL,
  121649. 0
  121650. };
  121651. static long _vq_quantlist__44c9_s_p6_0[] = {
  121652. 6,
  121653. 5,
  121654. 7,
  121655. 4,
  121656. 8,
  121657. 3,
  121658. 9,
  121659. 2,
  121660. 10,
  121661. 1,
  121662. 11,
  121663. 0,
  121664. 12,
  121665. };
  121666. static long _vq_lengthlist__44c9_s_p6_0[] = {
  121667. 2, 4, 4, 6, 6, 7, 7, 7, 7, 8, 8, 9, 9, 5, 4, 4,
  121668. 6, 6, 8, 8, 9, 9, 9, 9,10,10, 6, 4, 4, 6, 6, 8,
  121669. 8, 9, 9, 9, 9,10,10, 0, 6, 6, 7, 7, 8, 8, 9, 9,
  121670. 10,10,11,11, 0, 6, 6, 7, 7, 8, 8, 9, 9,10,10,11,
  121671. 11, 0,10,10, 8, 8, 9, 9,10,10,11,11,12,12, 0,11,
  121672. 11, 8, 8, 9, 9,10,10,11,11,12,12, 0, 0, 0, 0, 0,
  121673. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121674. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121675. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121676. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121677. 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121678. };
  121679. static float _vq_quantthresh__44c9_s_p6_0[] = {
  121680. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  121681. 12.5, 17.5, 22.5, 27.5,
  121682. };
  121683. static long _vq_quantmap__44c9_s_p6_0[] = {
  121684. 11, 9, 7, 5, 3, 1, 0, 2,
  121685. 4, 6, 8, 10, 12,
  121686. };
  121687. static encode_aux_threshmatch _vq_auxt__44c9_s_p6_0 = {
  121688. _vq_quantthresh__44c9_s_p6_0,
  121689. _vq_quantmap__44c9_s_p6_0,
  121690. 13,
  121691. 13
  121692. };
  121693. static static_codebook _44c9_s_p6_0 = {
  121694. 2, 169,
  121695. _vq_lengthlist__44c9_s_p6_0,
  121696. 1, -526516224, 1616117760, 4, 0,
  121697. _vq_quantlist__44c9_s_p6_0,
  121698. NULL,
  121699. &_vq_auxt__44c9_s_p6_0,
  121700. NULL,
  121701. 0
  121702. };
  121703. static long _vq_quantlist__44c9_s_p6_1[] = {
  121704. 2,
  121705. 1,
  121706. 3,
  121707. 0,
  121708. 4,
  121709. };
  121710. static long _vq_lengthlist__44c9_s_p6_1[] = {
  121711. 4, 4, 4, 5, 5, 5, 4, 4, 5, 5, 5, 4, 4, 5, 5, 5,
  121712. 5, 5, 5, 5, 5, 5, 5, 5, 5,
  121713. };
  121714. static float _vq_quantthresh__44c9_s_p6_1[] = {
  121715. -1.5, -0.5, 0.5, 1.5,
  121716. };
  121717. static long _vq_quantmap__44c9_s_p6_1[] = {
  121718. 3, 1, 0, 2, 4,
  121719. };
  121720. static encode_aux_threshmatch _vq_auxt__44c9_s_p6_1 = {
  121721. _vq_quantthresh__44c9_s_p6_1,
  121722. _vq_quantmap__44c9_s_p6_1,
  121723. 5,
  121724. 5
  121725. };
  121726. static static_codebook _44c9_s_p6_1 = {
  121727. 2, 25,
  121728. _vq_lengthlist__44c9_s_p6_1,
  121729. 1, -533725184, 1611661312, 3, 0,
  121730. _vq_quantlist__44c9_s_p6_1,
  121731. NULL,
  121732. &_vq_auxt__44c9_s_p6_1,
  121733. NULL,
  121734. 0
  121735. };
  121736. static long _vq_quantlist__44c9_s_p7_0[] = {
  121737. 6,
  121738. 5,
  121739. 7,
  121740. 4,
  121741. 8,
  121742. 3,
  121743. 9,
  121744. 2,
  121745. 10,
  121746. 1,
  121747. 11,
  121748. 0,
  121749. 12,
  121750. };
  121751. static long _vq_lengthlist__44c9_s_p7_0[] = {
  121752. 2, 4, 4, 6, 6, 7, 7, 8, 8,10,10,11,11, 6, 4, 4,
  121753. 6, 6, 8, 8, 9, 9,10,10,12,12, 6, 4, 5, 6, 6, 8,
  121754. 8, 9, 9,10,10,12,12,20, 6, 6, 6, 6, 8, 8, 9,10,
  121755. 11,11,12,12,20, 6, 6, 6, 6, 8, 8,10,10,11,11,12,
  121756. 12,20,10,10, 7, 7, 9, 9,10,10,11,11,12,12,20,11,
  121757. 11, 7, 7, 9, 9,10,10,11,11,12,12,20,20,20, 9, 9,
  121758. 9, 9,11,11,12,12,13,13,20,20,20, 9, 9, 9, 9,11,
  121759. 11,12,12,13,13,20,20,20,13,13,10,10,11,11,12,13,
  121760. 13,13,20,20,20,13,13,10,10,11,11,12,13,13,13,20,
  121761. 20,20,20,19,12,12,12,12,13,13,14,15,19,19,19,19,
  121762. 19,12,12,12,12,13,13,14,14,
  121763. };
  121764. static float _vq_quantthresh__44c9_s_p7_0[] = {
  121765. -60.5, -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5,
  121766. 27.5, 38.5, 49.5, 60.5,
  121767. };
  121768. static long _vq_quantmap__44c9_s_p7_0[] = {
  121769. 11, 9, 7, 5, 3, 1, 0, 2,
  121770. 4, 6, 8, 10, 12,
  121771. };
  121772. static encode_aux_threshmatch _vq_auxt__44c9_s_p7_0 = {
  121773. _vq_quantthresh__44c9_s_p7_0,
  121774. _vq_quantmap__44c9_s_p7_0,
  121775. 13,
  121776. 13
  121777. };
  121778. static static_codebook _44c9_s_p7_0 = {
  121779. 2, 169,
  121780. _vq_lengthlist__44c9_s_p7_0,
  121781. 1, -523206656, 1618345984, 4, 0,
  121782. _vq_quantlist__44c9_s_p7_0,
  121783. NULL,
  121784. &_vq_auxt__44c9_s_p7_0,
  121785. NULL,
  121786. 0
  121787. };
  121788. static long _vq_quantlist__44c9_s_p7_1[] = {
  121789. 5,
  121790. 4,
  121791. 6,
  121792. 3,
  121793. 7,
  121794. 2,
  121795. 8,
  121796. 1,
  121797. 9,
  121798. 0,
  121799. 10,
  121800. };
  121801. static long _vq_lengthlist__44c9_s_p7_1[] = {
  121802. 5, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 6, 6, 6, 6,
  121803. 7, 7, 7, 7, 7, 7, 7, 6, 6, 6, 6, 7, 7, 7, 7, 7,
  121804. 7, 8, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 8, 8, 8, 6,
  121805. 6, 7, 7, 7, 7, 7, 7, 8, 8, 8, 7, 7, 7, 7, 7, 7,
  121806. 7, 7, 8, 8, 8, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8,
  121807. 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 7, 7, 7,
  121808. 7, 7, 7, 8, 8, 8, 8, 8, 7, 7, 7, 7, 7, 7, 8, 8,
  121809. 8, 8, 8, 7, 7, 7, 7, 7, 7,
  121810. };
  121811. static float _vq_quantthresh__44c9_s_p7_1[] = {
  121812. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  121813. 3.5, 4.5,
  121814. };
  121815. static long _vq_quantmap__44c9_s_p7_1[] = {
  121816. 9, 7, 5, 3, 1, 0, 2, 4,
  121817. 6, 8, 10,
  121818. };
  121819. static encode_aux_threshmatch _vq_auxt__44c9_s_p7_1 = {
  121820. _vq_quantthresh__44c9_s_p7_1,
  121821. _vq_quantmap__44c9_s_p7_1,
  121822. 11,
  121823. 11
  121824. };
  121825. static static_codebook _44c9_s_p7_1 = {
  121826. 2, 121,
  121827. _vq_lengthlist__44c9_s_p7_1,
  121828. 1, -531365888, 1611661312, 4, 0,
  121829. _vq_quantlist__44c9_s_p7_1,
  121830. NULL,
  121831. &_vq_auxt__44c9_s_p7_1,
  121832. NULL,
  121833. 0
  121834. };
  121835. static long _vq_quantlist__44c9_s_p8_0[] = {
  121836. 7,
  121837. 6,
  121838. 8,
  121839. 5,
  121840. 9,
  121841. 4,
  121842. 10,
  121843. 3,
  121844. 11,
  121845. 2,
  121846. 12,
  121847. 1,
  121848. 13,
  121849. 0,
  121850. 14,
  121851. };
  121852. static long _vq_lengthlist__44c9_s_p8_0[] = {
  121853. 1, 4, 4, 7, 6, 8, 8, 8, 8, 9, 9,10,10,11,10, 6,
  121854. 5, 5, 7, 7, 9, 9, 8, 9,10,10,11,11,12,12, 6, 5,
  121855. 5, 7, 7, 9, 9, 9, 9,10,10,11,11,12,12,21, 7, 8,
  121856. 8, 8, 9, 9, 9, 9,10,10,11,11,12,12,21, 8, 8, 8,
  121857. 8, 9, 9, 9, 9,10,10,11,11,12,12,21,11,12, 9, 9,
  121858. 10,10,10,10,10,11,11,12,12,12,21,12,12, 9, 8,10,
  121859. 10,10,10,11,11,12,12,13,13,21,21,21, 9, 9, 9, 9,
  121860. 11,11,11,11,12,12,12,13,21,20,20, 9, 9, 9, 9,10,
  121861. 11,11,11,12,12,13,13,20,20,20,13,13,10,10,11,11,
  121862. 12,12,13,13,13,13,20,20,20,13,13,10,10,11,11,12,
  121863. 12,13,13,13,13,20,20,20,20,20,12,12,12,12,12,12,
  121864. 13,13,14,14,20,20,20,20,20,12,12,12,11,13,12,13,
  121865. 13,14,14,20,20,20,20,20,15,16,13,12,13,13,14,13,
  121866. 14,14,20,20,20,20,20,16,15,12,12,13,12,14,13,14,
  121867. 14,
  121868. };
  121869. static float _vq_quantthresh__44c9_s_p8_0[] = {
  121870. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  121871. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  121872. };
  121873. static long _vq_quantmap__44c9_s_p8_0[] = {
  121874. 13, 11, 9, 7, 5, 3, 1, 0,
  121875. 2, 4, 6, 8, 10, 12, 14,
  121876. };
  121877. static encode_aux_threshmatch _vq_auxt__44c9_s_p8_0 = {
  121878. _vq_quantthresh__44c9_s_p8_0,
  121879. _vq_quantmap__44c9_s_p8_0,
  121880. 15,
  121881. 15
  121882. };
  121883. static static_codebook _44c9_s_p8_0 = {
  121884. 2, 225,
  121885. _vq_lengthlist__44c9_s_p8_0,
  121886. 1, -520986624, 1620377600, 4, 0,
  121887. _vq_quantlist__44c9_s_p8_0,
  121888. NULL,
  121889. &_vq_auxt__44c9_s_p8_0,
  121890. NULL,
  121891. 0
  121892. };
  121893. static long _vq_quantlist__44c9_s_p8_1[] = {
  121894. 10,
  121895. 9,
  121896. 11,
  121897. 8,
  121898. 12,
  121899. 7,
  121900. 13,
  121901. 6,
  121902. 14,
  121903. 5,
  121904. 15,
  121905. 4,
  121906. 16,
  121907. 3,
  121908. 17,
  121909. 2,
  121910. 18,
  121911. 1,
  121912. 19,
  121913. 0,
  121914. 20,
  121915. };
  121916. static long _vq_lengthlist__44c9_s_p8_1[] = {
  121917. 4, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  121918. 8, 8, 8, 8, 8,10, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,
  121919. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10, 6, 6, 7, 7, 8,
  121920. 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,
  121921. 7, 7, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  121922. 9, 9, 9, 9,10,10,10, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  121923. 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10,10, 8, 8, 8, 8,
  121924. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10,
  121925. 10, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  121926. 9, 9, 9,10,10,10, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  121927. 9, 9, 9, 9, 9, 9, 9, 9,10,10,10,10,10, 9, 9, 9,
  121928. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10,10,
  121929. 10,10, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  121930. 9, 9,10,10,10,10,10, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  121931. 9, 9, 9, 9, 9, 9, 9,10,10,10,10,10, 9, 9, 9, 9,
  121932. 9, 9, 9, 9, 9, 9, 9, 9,10, 9, 9, 9,10,10,10,10,
  121933. 10,10,10, 9, 9, 9, 9, 9, 9,10, 9, 9, 9, 9, 9, 9,
  121934. 9,10,10,10,10,10,10,10, 9, 9, 9,10,10,10,10,10,
  121935. 9, 9, 9, 9, 9, 9,10,10,10,10,10,10,10, 9, 9,10,
  121936. 9,10, 9, 9, 9, 9, 9, 9, 9, 9,10,10,10,10,10,10,
  121937. 10,10,10,10, 9, 9,10,10, 9, 9, 9, 9, 9, 9, 9, 9,
  121938. 10,10,10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9,
  121939. 9, 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,10,10,
  121940. 10,10, 9, 9,10, 9, 9, 9, 9, 9,10,10,10,10,10,10,
  121941. 10,10,10,10,10, 9, 9,10,10, 9, 9,10, 9, 9, 9,10,
  121942. 10,10,10,10,10,10,10,10,10,10, 9, 9,10, 9, 9, 9,
  121943. 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,10,10, 9,
  121944. 9, 9, 9,10, 9, 9, 9, 9, 9,
  121945. };
  121946. static float _vq_quantthresh__44c9_s_p8_1[] = {
  121947. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  121948. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  121949. 6.5, 7.5, 8.5, 9.5,
  121950. };
  121951. static long _vq_quantmap__44c9_s_p8_1[] = {
  121952. 19, 17, 15, 13, 11, 9, 7, 5,
  121953. 3, 1, 0, 2, 4, 6, 8, 10,
  121954. 12, 14, 16, 18, 20,
  121955. };
  121956. static encode_aux_threshmatch _vq_auxt__44c9_s_p8_1 = {
  121957. _vq_quantthresh__44c9_s_p8_1,
  121958. _vq_quantmap__44c9_s_p8_1,
  121959. 21,
  121960. 21
  121961. };
  121962. static static_codebook _44c9_s_p8_1 = {
  121963. 2, 441,
  121964. _vq_lengthlist__44c9_s_p8_1,
  121965. 1, -529268736, 1611661312, 5, 0,
  121966. _vq_quantlist__44c9_s_p8_1,
  121967. NULL,
  121968. &_vq_auxt__44c9_s_p8_1,
  121969. NULL,
  121970. 0
  121971. };
  121972. static long _vq_quantlist__44c9_s_p9_0[] = {
  121973. 9,
  121974. 8,
  121975. 10,
  121976. 7,
  121977. 11,
  121978. 6,
  121979. 12,
  121980. 5,
  121981. 13,
  121982. 4,
  121983. 14,
  121984. 3,
  121985. 15,
  121986. 2,
  121987. 16,
  121988. 1,
  121989. 17,
  121990. 0,
  121991. 18,
  121992. };
  121993. static long _vq_lengthlist__44c9_s_p9_0[] = {
  121994. 1, 4, 3,12,12,12,12,12,12,12,12,12,12,12,12,12,
  121995. 12,12,12, 4, 5, 6,12,12,12,12,12,12,12,12,12,12,
  121996. 12,12,12,12,12,12, 4, 6, 6,12,12,12,12,12,12,12,
  121997. 12,12,12,12,12,12,12,12,12,12,12,11,12,12,12,12,
  121998. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  121999. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  122000. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  122001. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  122002. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  122003. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  122004. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  122005. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  122006. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  122007. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  122008. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  122009. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  122010. 12,12,12,12,12,12,12,12,12,12,11,11,11,11,11,11,
  122011. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122012. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122013. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122014. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122015. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122016. 11,11,11,11,11,11,11,11,11,
  122017. };
  122018. static float _vq_quantthresh__44c9_s_p9_0[] = {
  122019. -7913.5, -6982.5, -6051.5, -5120.5, -4189.5, -3258.5, -2327.5, -1396.5,
  122020. -465.5, 465.5, 1396.5, 2327.5, 3258.5, 4189.5, 5120.5, 6051.5,
  122021. 6982.5, 7913.5,
  122022. };
  122023. static long _vq_quantmap__44c9_s_p9_0[] = {
  122024. 17, 15, 13, 11, 9, 7, 5, 3,
  122025. 1, 0, 2, 4, 6, 8, 10, 12,
  122026. 14, 16, 18,
  122027. };
  122028. static encode_aux_threshmatch _vq_auxt__44c9_s_p9_0 = {
  122029. _vq_quantthresh__44c9_s_p9_0,
  122030. _vq_quantmap__44c9_s_p9_0,
  122031. 19,
  122032. 19
  122033. };
  122034. static static_codebook _44c9_s_p9_0 = {
  122035. 2, 361,
  122036. _vq_lengthlist__44c9_s_p9_0,
  122037. 1, -508535424, 1631393792, 5, 0,
  122038. _vq_quantlist__44c9_s_p9_0,
  122039. NULL,
  122040. &_vq_auxt__44c9_s_p9_0,
  122041. NULL,
  122042. 0
  122043. };
  122044. static long _vq_quantlist__44c9_s_p9_1[] = {
  122045. 9,
  122046. 8,
  122047. 10,
  122048. 7,
  122049. 11,
  122050. 6,
  122051. 12,
  122052. 5,
  122053. 13,
  122054. 4,
  122055. 14,
  122056. 3,
  122057. 15,
  122058. 2,
  122059. 16,
  122060. 1,
  122061. 17,
  122062. 0,
  122063. 18,
  122064. };
  122065. static long _vq_lengthlist__44c9_s_p9_1[] = {
  122066. 1, 4, 4, 7, 7, 7, 7, 8, 7, 9, 8, 9, 9,10,10,11,
  122067. 11,11,11, 6, 5, 5, 8, 8, 9, 9, 9, 8,10, 9,11,10,
  122068. 12,12,13,12,13,13, 5, 5, 5, 8, 8, 9, 9, 9, 9,10,
  122069. 10,11,11,12,12,13,12,13,13,17, 8, 8, 9, 9, 9, 9,
  122070. 9, 9,10,10,12,11,13,12,13,13,13,13,18, 8, 8, 9,
  122071. 9, 9, 9, 9, 9,11,11,12,12,13,13,13,13,13,13,17,
  122072. 13,12, 9, 9,10,10,10,10,11,11,12,12,12,13,13,13,
  122073. 14,14,18,13,12, 9, 9,10,10,10,10,11,11,12,12,13,
  122074. 13,13,14,14,14,17,18,18,10,10,10,10,11,11,11,12,
  122075. 12,12,14,13,14,13,13,14,18,18,18,10, 9,10, 9,11,
  122076. 11,12,12,12,12,13,13,15,14,14,14,18,18,16,13,14,
  122077. 10,11,11,11,12,13,13,13,13,14,13,13,14,14,18,18,
  122078. 18,14,12,11, 9,11,10,13,12,13,13,13,14,14,14,13,
  122079. 14,18,18,17,18,18,11,12,12,12,13,13,14,13,14,14,
  122080. 13,14,14,14,18,18,18,18,17,12,10,12, 9,13,11,13,
  122081. 14,14,14,14,14,15,14,18,18,17,17,18,14,15,12,13,
  122082. 13,13,14,13,14,14,15,14,15,14,18,17,18,18,18,15,
  122083. 15,12,10,14,10,14,14,13,13,14,14,14,14,18,16,18,
  122084. 18,18,18,17,14,14,13,14,14,13,13,14,14,14,15,15,
  122085. 18,18,18,18,17,17,17,14,14,14,12,14,13,14,14,15,
  122086. 14,15,14,18,18,18,18,18,18,18,17,16,13,13,13,14,
  122087. 14,14,14,15,16,15,18,18,18,18,18,18,18,17,17,13,
  122088. 13,13,13,14,13,14,15,15,15,
  122089. };
  122090. static float _vq_quantthresh__44c9_s_p9_1[] = {
  122091. -416.5, -367.5, -318.5, -269.5, -220.5, -171.5, -122.5, -73.5,
  122092. -24.5, 24.5, 73.5, 122.5, 171.5, 220.5, 269.5, 318.5,
  122093. 367.5, 416.5,
  122094. };
  122095. static long _vq_quantmap__44c9_s_p9_1[] = {
  122096. 17, 15, 13, 11, 9, 7, 5, 3,
  122097. 1, 0, 2, 4, 6, 8, 10, 12,
  122098. 14, 16, 18,
  122099. };
  122100. static encode_aux_threshmatch _vq_auxt__44c9_s_p9_1 = {
  122101. _vq_quantthresh__44c9_s_p9_1,
  122102. _vq_quantmap__44c9_s_p9_1,
  122103. 19,
  122104. 19
  122105. };
  122106. static static_codebook _44c9_s_p9_1 = {
  122107. 2, 361,
  122108. _vq_lengthlist__44c9_s_p9_1,
  122109. 1, -518287360, 1622704128, 5, 0,
  122110. _vq_quantlist__44c9_s_p9_1,
  122111. NULL,
  122112. &_vq_auxt__44c9_s_p9_1,
  122113. NULL,
  122114. 0
  122115. };
  122116. static long _vq_quantlist__44c9_s_p9_2[] = {
  122117. 24,
  122118. 23,
  122119. 25,
  122120. 22,
  122121. 26,
  122122. 21,
  122123. 27,
  122124. 20,
  122125. 28,
  122126. 19,
  122127. 29,
  122128. 18,
  122129. 30,
  122130. 17,
  122131. 31,
  122132. 16,
  122133. 32,
  122134. 15,
  122135. 33,
  122136. 14,
  122137. 34,
  122138. 13,
  122139. 35,
  122140. 12,
  122141. 36,
  122142. 11,
  122143. 37,
  122144. 10,
  122145. 38,
  122146. 9,
  122147. 39,
  122148. 8,
  122149. 40,
  122150. 7,
  122151. 41,
  122152. 6,
  122153. 42,
  122154. 5,
  122155. 43,
  122156. 4,
  122157. 44,
  122158. 3,
  122159. 45,
  122160. 2,
  122161. 46,
  122162. 1,
  122163. 47,
  122164. 0,
  122165. 48,
  122166. };
  122167. static long _vq_lengthlist__44c9_s_p9_2[] = {
  122168. 2, 4, 4, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6,
  122169. 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7,
  122170. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  122171. 7,
  122172. };
  122173. static float _vq_quantthresh__44c9_s_p9_2[] = {
  122174. -23.5, -22.5, -21.5, -20.5, -19.5, -18.5, -17.5, -16.5,
  122175. -15.5, -14.5, -13.5, -12.5, -11.5, -10.5, -9.5, -8.5,
  122176. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  122177. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  122178. 8.5, 9.5, 10.5, 11.5, 12.5, 13.5, 14.5, 15.5,
  122179. 16.5, 17.5, 18.5, 19.5, 20.5, 21.5, 22.5, 23.5,
  122180. };
  122181. static long _vq_quantmap__44c9_s_p9_2[] = {
  122182. 47, 45, 43, 41, 39, 37, 35, 33,
  122183. 31, 29, 27, 25, 23, 21, 19, 17,
  122184. 15, 13, 11, 9, 7, 5, 3, 1,
  122185. 0, 2, 4, 6, 8, 10, 12, 14,
  122186. 16, 18, 20, 22, 24, 26, 28, 30,
  122187. 32, 34, 36, 38, 40, 42, 44, 46,
  122188. 48,
  122189. };
  122190. static encode_aux_threshmatch _vq_auxt__44c9_s_p9_2 = {
  122191. _vq_quantthresh__44c9_s_p9_2,
  122192. _vq_quantmap__44c9_s_p9_2,
  122193. 49,
  122194. 49
  122195. };
  122196. static static_codebook _44c9_s_p9_2 = {
  122197. 1, 49,
  122198. _vq_lengthlist__44c9_s_p9_2,
  122199. 1, -526909440, 1611661312, 6, 0,
  122200. _vq_quantlist__44c9_s_p9_2,
  122201. NULL,
  122202. &_vq_auxt__44c9_s_p9_2,
  122203. NULL,
  122204. 0
  122205. };
  122206. static long _huff_lengthlist__44c9_s_short[] = {
  122207. 5,13,18,16,17,17,19,18,19,19, 5, 7,10,11,12,12,
  122208. 13,16,17,18, 6, 6, 7, 7, 9, 9,10,14,17,19, 8, 7,
  122209. 6, 5, 6, 7, 9,12,19,17, 8, 7, 7, 6, 5, 6, 8,11,
  122210. 15,19, 9, 8, 7, 6, 5, 5, 6, 8,13,15,11,10, 8, 8,
  122211. 7, 5, 4, 4,10,14,12,13,11, 9, 7, 6, 4, 2, 6,12,
  122212. 18,16,16,13, 8, 7, 7, 5, 8,13,16,17,18,15,11, 9,
  122213. 9, 8,10,13,
  122214. };
  122215. static static_codebook _huff_book__44c9_s_short = {
  122216. 2, 100,
  122217. _huff_lengthlist__44c9_s_short,
  122218. 0, 0, 0, 0, 0,
  122219. NULL,
  122220. NULL,
  122221. NULL,
  122222. NULL,
  122223. 0
  122224. };
  122225. static long _huff_lengthlist__44c0_s_long[] = {
  122226. 5, 4, 8, 9, 8, 9,10,12,15, 4, 1, 5, 5, 6, 8,11,
  122227. 12,12, 8, 5, 8, 9, 9,11,13,12,12, 9, 5, 8, 5, 7,
  122228. 9,12,13,13, 8, 6, 8, 7, 7, 9,11,11,11, 9, 7, 9,
  122229. 7, 7, 7, 7,10,12,10,10,11, 9, 8, 7, 7, 9,11,11,
  122230. 12,13,12,11, 9, 8, 9,11,13,16,16,15,15,12,10,11,
  122231. 12,
  122232. };
  122233. static static_codebook _huff_book__44c0_s_long = {
  122234. 2, 81,
  122235. _huff_lengthlist__44c0_s_long,
  122236. 0, 0, 0, 0, 0,
  122237. NULL,
  122238. NULL,
  122239. NULL,
  122240. NULL,
  122241. 0
  122242. };
  122243. static long _vq_quantlist__44c0_s_p1_0[] = {
  122244. 1,
  122245. 0,
  122246. 2,
  122247. };
  122248. static long _vq_lengthlist__44c0_s_p1_0[] = {
  122249. 1, 5, 5, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0, 0, 0, 0,
  122250. 0, 0, 5, 7, 7, 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, 5, 8, 7, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0, 0,
  122255. 0, 0, 0, 7, 9, 9, 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, 5, 7, 7, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0,
  122260. 0, 0, 0, 0, 7, 9, 9, 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, 5, 7, 7, 0, 0, 0, 0,
  122295. 0, 0, 8,10, 9, 0, 0, 0, 0, 0, 0, 7, 9, 9, 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, 7, 9, 9, 0, 0, 0,
  122300. 0, 0, 0, 9,10,11, 0, 0, 0, 0, 0, 0, 9,11,10, 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, 7, 9, 9, 0, 0,
  122305. 0, 0, 0, 0, 9,11, 9, 0, 0, 0, 0, 0, 0, 9,10,11,
  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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122316. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122317. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122318. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122319. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122320. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122321. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122322. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122323. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122324. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122325. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122326. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122327. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122328. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122329. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122330. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122331. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122332. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122333. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122334. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122335. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122336. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122337. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122338. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122339. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122340. 0, 0, 5, 7, 7, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0,
  122341. 0, 0, 0, 0, 8, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122342. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122343. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122344. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122345. 0, 0, 0, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,11,10, 0,
  122346. 0, 0, 0, 0, 0, 9, 9,11, 0, 0, 0, 0, 0, 0, 0, 0,
  122347. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122348. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122349. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122350. 0, 0, 0, 0, 7, 9,10, 0, 0, 0, 0, 0, 0, 9,10,11,
  122351. 0, 0, 0, 0, 0, 0, 9,11,10, 0, 0, 0, 0, 0, 0, 0,
  122352. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122353. 0, 0, 0, 0, 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122387. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122388. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122389. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122390. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122391. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122392. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122393. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122394. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122395. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122396. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122397. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122398. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122399. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122400. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122401. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122402. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122403. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122404. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122405. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122406. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122407. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122408. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122409. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122410. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122411. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122412. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122413. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122414. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122415. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122416. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122417. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122418. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122419. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122420. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122421. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122422. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122423. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122424. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122425. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122426. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122427. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122428. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122429. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122430. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122431. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122432. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122433. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122434. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122435. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122436. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122437. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122438. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122439. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122440. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122441. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122442. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122443. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122444. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122445. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122446. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122447. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122448. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122449. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122450. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122451. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122452. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122453. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122454. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122455. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122456. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122457. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122458. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122459. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122460. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122461. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122462. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122463. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122464. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122465. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122466. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122467. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122468. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122469. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122470. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122471. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122472. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122473. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122474. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122475. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122476. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122477. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122478. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122479. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122480. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122481. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122482. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122483. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122484. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122485. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122486. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122487. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122488. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122489. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122490. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122491. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122492. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122493. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122494. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122495. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122496. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122497. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122498. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122499. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122500. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122501. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122502. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122503. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122504. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122505. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122506. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122507. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122508. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122509. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122510. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122511. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122512. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122513. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122514. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122515. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122516. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122517. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122518. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122519. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122520. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122521. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122522. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122523. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122524. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122525. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122526. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122527. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122528. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122529. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122530. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122531. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122532. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122533. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122534. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122535. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122536. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122537. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122538. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122539. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122540. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122541. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122542. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122543. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122544. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122545. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122546. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122547. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122548. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122549. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122550. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122551. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122552. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122553. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122554. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122555. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122556. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122557. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122558. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122559. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122560. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122561. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122562. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122563. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122564. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122565. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122566. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122567. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122568. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122569. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122570. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122571. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122572. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122573. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122574. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122575. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122576. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122577. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122578. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122579. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122580. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122581. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122582. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122583. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122584. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122585. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122586. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122587. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122588. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122589. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122590. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122591. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122592. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122593. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122594. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122595. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122596. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122597. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122598. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122599. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122600. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122601. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122602. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122603. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122604. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122605. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122606. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122607. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122608. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122609. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122610. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122611. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122612. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122613. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122614. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122615. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122616. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122617. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122618. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122619. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122620. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122621. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122622. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122623. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122624. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122625. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122626. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122627. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122628. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122629. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122630. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122631. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122632. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122633. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122634. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122635. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122636. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122637. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122638. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122639. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122640. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122641. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122642. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122643. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122644. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122645. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122646. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122647. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122648. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122649. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122650. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122651. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122652. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122653. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122654. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122655. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122656. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122657. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122658. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122659. 0,
  122660. };
  122661. static float _vq_quantthresh__44c0_s_p1_0[] = {
  122662. -0.5, 0.5,
  122663. };
  122664. static long _vq_quantmap__44c0_s_p1_0[] = {
  122665. 1, 0, 2,
  122666. };
  122667. static encode_aux_threshmatch _vq_auxt__44c0_s_p1_0 = {
  122668. _vq_quantthresh__44c0_s_p1_0,
  122669. _vq_quantmap__44c0_s_p1_0,
  122670. 3,
  122671. 3
  122672. };
  122673. static static_codebook _44c0_s_p1_0 = {
  122674. 8, 6561,
  122675. _vq_lengthlist__44c0_s_p1_0,
  122676. 1, -535822336, 1611661312, 2, 0,
  122677. _vq_quantlist__44c0_s_p1_0,
  122678. NULL,
  122679. &_vq_auxt__44c0_s_p1_0,
  122680. NULL,
  122681. 0
  122682. };
  122683. static long _vq_quantlist__44c0_s_p2_0[] = {
  122684. 2,
  122685. 1,
  122686. 3,
  122687. 0,
  122688. 4,
  122689. };
  122690. static long _vq_lengthlist__44c0_s_p2_0[] = {
  122691. 1, 4, 4, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122692. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 5, 5, 7, 6, 0, 0,
  122693. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122694. 0, 0, 4, 5, 6, 7, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122695. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 7, 7, 9, 9,
  122696. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122697. 0, 0, 0, 0, 6, 7, 7, 9, 9, 0, 0, 0, 0, 0, 0, 0,
  122698. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122699. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122700. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122701. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122702. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122703. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122704. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122705. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122706. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122707. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122708. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122709. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122710. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122711. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122712. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122713. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122714. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122715. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122716. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122717. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122718. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122719. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122720. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122721. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122722. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122723. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122724. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122725. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122726. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122727. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122728. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122729. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122730. 0,
  122731. };
  122732. static float _vq_quantthresh__44c0_s_p2_0[] = {
  122733. -1.5, -0.5, 0.5, 1.5,
  122734. };
  122735. static long _vq_quantmap__44c0_s_p2_0[] = {
  122736. 3, 1, 0, 2, 4,
  122737. };
  122738. static encode_aux_threshmatch _vq_auxt__44c0_s_p2_0 = {
  122739. _vq_quantthresh__44c0_s_p2_0,
  122740. _vq_quantmap__44c0_s_p2_0,
  122741. 5,
  122742. 5
  122743. };
  122744. static static_codebook _44c0_s_p2_0 = {
  122745. 4, 625,
  122746. _vq_lengthlist__44c0_s_p2_0,
  122747. 1, -533725184, 1611661312, 3, 0,
  122748. _vq_quantlist__44c0_s_p2_0,
  122749. NULL,
  122750. &_vq_auxt__44c0_s_p2_0,
  122751. NULL,
  122752. 0
  122753. };
  122754. static long _vq_quantlist__44c0_s_p3_0[] = {
  122755. 4,
  122756. 3,
  122757. 5,
  122758. 2,
  122759. 6,
  122760. 1,
  122761. 7,
  122762. 0,
  122763. 8,
  122764. };
  122765. static long _vq_lengthlist__44c0_s_p3_0[] = {
  122766. 1, 3, 2, 8, 7, 0, 0, 0, 0, 0, 0, 0, 6, 6, 0, 0,
  122767. 0, 0, 0, 0, 0, 6, 6, 0, 0, 0, 0, 0, 0, 0, 7, 7,
  122768. 0, 0, 0, 0, 0, 0, 0, 7, 7, 0, 0, 0, 0, 0, 0, 0,
  122769. 8, 8, 0, 0, 0, 0, 0, 0, 0, 8, 8, 0, 0, 0, 0, 0,
  122770. 0, 0, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122771. 0,
  122772. };
  122773. static float _vq_quantthresh__44c0_s_p3_0[] = {
  122774. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  122775. };
  122776. static long _vq_quantmap__44c0_s_p3_0[] = {
  122777. 7, 5, 3, 1, 0, 2, 4, 6,
  122778. 8,
  122779. };
  122780. static encode_aux_threshmatch _vq_auxt__44c0_s_p3_0 = {
  122781. _vq_quantthresh__44c0_s_p3_0,
  122782. _vq_quantmap__44c0_s_p3_0,
  122783. 9,
  122784. 9
  122785. };
  122786. static static_codebook _44c0_s_p3_0 = {
  122787. 2, 81,
  122788. _vq_lengthlist__44c0_s_p3_0,
  122789. 1, -531628032, 1611661312, 4, 0,
  122790. _vq_quantlist__44c0_s_p3_0,
  122791. NULL,
  122792. &_vq_auxt__44c0_s_p3_0,
  122793. NULL,
  122794. 0
  122795. };
  122796. static long _vq_quantlist__44c0_s_p4_0[] = {
  122797. 4,
  122798. 3,
  122799. 5,
  122800. 2,
  122801. 6,
  122802. 1,
  122803. 7,
  122804. 0,
  122805. 8,
  122806. };
  122807. static long _vq_lengthlist__44c0_s_p4_0[] = {
  122808. 1, 3, 3, 6, 6, 6, 6, 8, 8, 0, 0, 0, 7, 7, 7, 7,
  122809. 9, 9, 0, 0, 0, 7, 7, 7, 7, 9, 9, 0, 0, 0, 7, 7,
  122810. 7, 8, 9, 9, 0, 0, 0, 7, 7, 7, 7, 9, 9, 0, 0, 0,
  122811. 9, 9, 8, 8,10,10, 0, 0, 0, 8, 9, 8, 8,10,10, 0,
  122812. 0, 0,10,10, 9, 9,10,10, 0, 0, 0, 0, 0, 9, 9,10,
  122813. 10,
  122814. };
  122815. static float _vq_quantthresh__44c0_s_p4_0[] = {
  122816. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  122817. };
  122818. static long _vq_quantmap__44c0_s_p4_0[] = {
  122819. 7, 5, 3, 1, 0, 2, 4, 6,
  122820. 8,
  122821. };
  122822. static encode_aux_threshmatch _vq_auxt__44c0_s_p4_0 = {
  122823. _vq_quantthresh__44c0_s_p4_0,
  122824. _vq_quantmap__44c0_s_p4_0,
  122825. 9,
  122826. 9
  122827. };
  122828. static static_codebook _44c0_s_p4_0 = {
  122829. 2, 81,
  122830. _vq_lengthlist__44c0_s_p4_0,
  122831. 1, -531628032, 1611661312, 4, 0,
  122832. _vq_quantlist__44c0_s_p4_0,
  122833. NULL,
  122834. &_vq_auxt__44c0_s_p4_0,
  122835. NULL,
  122836. 0
  122837. };
  122838. static long _vq_quantlist__44c0_s_p5_0[] = {
  122839. 8,
  122840. 7,
  122841. 9,
  122842. 6,
  122843. 10,
  122844. 5,
  122845. 11,
  122846. 4,
  122847. 12,
  122848. 3,
  122849. 13,
  122850. 2,
  122851. 14,
  122852. 1,
  122853. 15,
  122854. 0,
  122855. 16,
  122856. };
  122857. static long _vq_lengthlist__44c0_s_p5_0[] = {
  122858. 1, 4, 3, 6, 6, 8, 7, 8, 8, 8, 8, 9, 9,10,10,11,
  122859. 11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9, 9,10,10,10,
  122860. 11,11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,10,
  122861. 10,11,11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,
  122862. 11,11,11,11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,
  122863. 10,11,11,11,11, 0, 0, 0, 8, 8, 9, 9, 9, 9,10,10,
  122864. 10,10,11,11,12,12, 0, 0, 0, 8, 8, 9, 9, 9, 9,10,
  122865. 10,10,10,11,11,12,12, 0, 0, 0, 9, 9, 9, 9,10,10,
  122866. 10,10,11,11,11,12,12,12, 0, 0, 0, 0, 0, 9, 9,10,
  122867. 10,10,10,11,11,11,11,12,12, 0, 0, 0, 0, 0, 9, 9,
  122868. 10,10,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9,
  122869. 9,10,10,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0,
  122870. 10,10,11,11,11,11,11,12,12,12,13,13, 0, 0, 0, 0,
  122871. 0, 0, 0,11,10,11,11,11,11,12,12,13,13, 0, 0, 0,
  122872. 0, 0, 0, 0,11,11,12,11,12,12,12,12,13,13, 0, 0,
  122873. 0, 0, 0, 0, 0,11,11,11,12,12,12,12,13,13,13, 0,
  122874. 0, 0, 0, 0, 0, 0,12,12,12,12,12,13,13,13,14,14,
  122875. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,12,12,13,13,14,
  122876. 14,
  122877. };
  122878. static float _vq_quantthresh__44c0_s_p5_0[] = {
  122879. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  122880. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  122881. };
  122882. static long _vq_quantmap__44c0_s_p5_0[] = {
  122883. 15, 13, 11, 9, 7, 5, 3, 1,
  122884. 0, 2, 4, 6, 8, 10, 12, 14,
  122885. 16,
  122886. };
  122887. static encode_aux_threshmatch _vq_auxt__44c0_s_p5_0 = {
  122888. _vq_quantthresh__44c0_s_p5_0,
  122889. _vq_quantmap__44c0_s_p5_0,
  122890. 17,
  122891. 17
  122892. };
  122893. static static_codebook _44c0_s_p5_0 = {
  122894. 2, 289,
  122895. _vq_lengthlist__44c0_s_p5_0,
  122896. 1, -529530880, 1611661312, 5, 0,
  122897. _vq_quantlist__44c0_s_p5_0,
  122898. NULL,
  122899. &_vq_auxt__44c0_s_p5_0,
  122900. NULL,
  122901. 0
  122902. };
  122903. static long _vq_quantlist__44c0_s_p6_0[] = {
  122904. 1,
  122905. 0,
  122906. 2,
  122907. };
  122908. static long _vq_lengthlist__44c0_s_p6_0[] = {
  122909. 1, 4, 4, 7, 6, 6, 7, 6, 6, 4, 7, 7,10, 9, 9,10,
  122910. 9, 9, 4, 6, 7,10, 9, 9,11, 9, 9, 7,10,10,11,11,
  122911. 11,12,10,11, 6, 9, 9,11,10,11,11,10,10, 6, 9, 9,
  122912. 11,10,11,11,10,10, 7,11,10,12,11,11,11,11,11, 7,
  122913. 9, 9,10,10,10,11,11,10, 6, 9, 9,11,10,10,11,10,
  122914. 10,
  122915. };
  122916. static float _vq_quantthresh__44c0_s_p6_0[] = {
  122917. -5.5, 5.5,
  122918. };
  122919. static long _vq_quantmap__44c0_s_p6_0[] = {
  122920. 1, 0, 2,
  122921. };
  122922. static encode_aux_threshmatch _vq_auxt__44c0_s_p6_0 = {
  122923. _vq_quantthresh__44c0_s_p6_0,
  122924. _vq_quantmap__44c0_s_p6_0,
  122925. 3,
  122926. 3
  122927. };
  122928. static static_codebook _44c0_s_p6_0 = {
  122929. 4, 81,
  122930. _vq_lengthlist__44c0_s_p6_0,
  122931. 1, -529137664, 1618345984, 2, 0,
  122932. _vq_quantlist__44c0_s_p6_0,
  122933. NULL,
  122934. &_vq_auxt__44c0_s_p6_0,
  122935. NULL,
  122936. 0
  122937. };
  122938. static long _vq_quantlist__44c0_s_p6_1[] = {
  122939. 5,
  122940. 4,
  122941. 6,
  122942. 3,
  122943. 7,
  122944. 2,
  122945. 8,
  122946. 1,
  122947. 9,
  122948. 0,
  122949. 10,
  122950. };
  122951. static long _vq_lengthlist__44c0_s_p6_1[] = {
  122952. 2, 3, 3, 6, 6, 7, 7, 7, 7, 7, 8,10,10,10, 6, 6,
  122953. 7, 7, 8, 8, 8, 8,10,10,10, 6, 6, 7, 7, 8, 8, 8,
  122954. 8,10,10,10, 7, 7, 7, 7, 8, 8, 8, 8,10,10,10, 7,
  122955. 7, 7, 7, 8, 8, 8, 8,10,10,10, 8, 7, 8, 8, 8, 8,
  122956. 8, 8,10,10,10, 7, 7, 8, 8, 8, 8, 8, 8,10,10,10,
  122957. 8, 8, 8, 8, 8, 8, 8, 8,10,10,10,10,10, 8, 8, 8,
  122958. 8, 8, 8,10,10,10,10,10, 9, 9, 8, 8, 8, 8,10,10,
  122959. 10,10,10, 8, 8, 8, 8, 8, 8,
  122960. };
  122961. static float _vq_quantthresh__44c0_s_p6_1[] = {
  122962. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  122963. 3.5, 4.5,
  122964. };
  122965. static long _vq_quantmap__44c0_s_p6_1[] = {
  122966. 9, 7, 5, 3, 1, 0, 2, 4,
  122967. 6, 8, 10,
  122968. };
  122969. static encode_aux_threshmatch _vq_auxt__44c0_s_p6_1 = {
  122970. _vq_quantthresh__44c0_s_p6_1,
  122971. _vq_quantmap__44c0_s_p6_1,
  122972. 11,
  122973. 11
  122974. };
  122975. static static_codebook _44c0_s_p6_1 = {
  122976. 2, 121,
  122977. _vq_lengthlist__44c0_s_p6_1,
  122978. 1, -531365888, 1611661312, 4, 0,
  122979. _vq_quantlist__44c0_s_p6_1,
  122980. NULL,
  122981. &_vq_auxt__44c0_s_p6_1,
  122982. NULL,
  122983. 0
  122984. };
  122985. static long _vq_quantlist__44c0_s_p7_0[] = {
  122986. 6,
  122987. 5,
  122988. 7,
  122989. 4,
  122990. 8,
  122991. 3,
  122992. 9,
  122993. 2,
  122994. 10,
  122995. 1,
  122996. 11,
  122997. 0,
  122998. 12,
  122999. };
  123000. static long _vq_lengthlist__44c0_s_p7_0[] = {
  123001. 1, 4, 4, 6, 6, 7, 7, 7, 7, 8, 8, 9, 9, 7, 5, 5,
  123002. 7, 7, 8, 8, 8, 8, 9, 9,10,10, 7, 5, 6, 7, 7, 8,
  123003. 8, 8, 8, 9, 9,10,10, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  123004. 10,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,
  123005. 11, 0,12,12, 9, 9,10,10,10,10,11,11,11,11, 0,13,
  123006. 13, 9, 9, 9, 9,10,10,11,11,11,12, 0, 0, 0,10,10,
  123007. 10,10,11,11,11,11,12,12, 0, 0, 0,10,10, 9, 9,11,
  123008. 11,11,12,12,12, 0, 0, 0,13,13,10,10,11,11,12,12,
  123009. 13,13, 0, 0, 0,14,14,10,10,11,11,12,12,13,13, 0,
  123010. 0, 0, 0, 0,11,11,11,11,13,12,13,13, 0, 0, 0, 0,
  123011. 0,12,12,11,11,12,12,13,13,
  123012. };
  123013. static float _vq_quantthresh__44c0_s_p7_0[] = {
  123014. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  123015. 12.5, 17.5, 22.5, 27.5,
  123016. };
  123017. static long _vq_quantmap__44c0_s_p7_0[] = {
  123018. 11, 9, 7, 5, 3, 1, 0, 2,
  123019. 4, 6, 8, 10, 12,
  123020. };
  123021. static encode_aux_threshmatch _vq_auxt__44c0_s_p7_0 = {
  123022. _vq_quantthresh__44c0_s_p7_0,
  123023. _vq_quantmap__44c0_s_p7_0,
  123024. 13,
  123025. 13
  123026. };
  123027. static static_codebook _44c0_s_p7_0 = {
  123028. 2, 169,
  123029. _vq_lengthlist__44c0_s_p7_0,
  123030. 1, -526516224, 1616117760, 4, 0,
  123031. _vq_quantlist__44c0_s_p7_0,
  123032. NULL,
  123033. &_vq_auxt__44c0_s_p7_0,
  123034. NULL,
  123035. 0
  123036. };
  123037. static long _vq_quantlist__44c0_s_p7_1[] = {
  123038. 2,
  123039. 1,
  123040. 3,
  123041. 0,
  123042. 4,
  123043. };
  123044. static long _vq_lengthlist__44c0_s_p7_1[] = {
  123045. 2, 3, 3, 5, 5, 6, 6, 6, 5, 5, 6, 6, 6, 5, 5, 6,
  123046. 6, 6, 5, 5, 6, 6, 6, 5, 5,
  123047. };
  123048. static float _vq_quantthresh__44c0_s_p7_1[] = {
  123049. -1.5, -0.5, 0.5, 1.5,
  123050. };
  123051. static long _vq_quantmap__44c0_s_p7_1[] = {
  123052. 3, 1, 0, 2, 4,
  123053. };
  123054. static encode_aux_threshmatch _vq_auxt__44c0_s_p7_1 = {
  123055. _vq_quantthresh__44c0_s_p7_1,
  123056. _vq_quantmap__44c0_s_p7_1,
  123057. 5,
  123058. 5
  123059. };
  123060. static static_codebook _44c0_s_p7_1 = {
  123061. 2, 25,
  123062. _vq_lengthlist__44c0_s_p7_1,
  123063. 1, -533725184, 1611661312, 3, 0,
  123064. _vq_quantlist__44c0_s_p7_1,
  123065. NULL,
  123066. &_vq_auxt__44c0_s_p7_1,
  123067. NULL,
  123068. 0
  123069. };
  123070. static long _vq_quantlist__44c0_s_p8_0[] = {
  123071. 2,
  123072. 1,
  123073. 3,
  123074. 0,
  123075. 4,
  123076. };
  123077. static long _vq_lengthlist__44c0_s_p8_0[] = {
  123078. 1, 5, 5,10,10, 6, 9, 8,10,10, 6,10, 9,10,10,10,
  123079. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  123080. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  123081. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  123082. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  123083. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  123084. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  123085. 10,10,10,10,10,10,10,10,10,10,10,10,10, 8,10,10,
  123086. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  123087. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  123088. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  123089. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  123090. 10,10,10,10,10,10,10,10,11,11,11,11,11,11,11,11,
  123091. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  123092. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  123093. 11,11,11,11,11,11,11,11,11,11,10,11,11,11,11,11,
  123094. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  123095. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  123096. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  123097. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  123098. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  123099. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  123100. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  123101. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  123102. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  123103. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  123104. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  123105. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  123106. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  123107. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  123108. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  123109. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  123110. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  123111. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  123112. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  123113. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  123114. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  123115. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  123116. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  123117. 11,
  123118. };
  123119. static float _vq_quantthresh__44c0_s_p8_0[] = {
  123120. -331.5, -110.5, 110.5, 331.5,
  123121. };
  123122. static long _vq_quantmap__44c0_s_p8_0[] = {
  123123. 3, 1, 0, 2, 4,
  123124. };
  123125. static encode_aux_threshmatch _vq_auxt__44c0_s_p8_0 = {
  123126. _vq_quantthresh__44c0_s_p8_0,
  123127. _vq_quantmap__44c0_s_p8_0,
  123128. 5,
  123129. 5
  123130. };
  123131. static static_codebook _44c0_s_p8_0 = {
  123132. 4, 625,
  123133. _vq_lengthlist__44c0_s_p8_0,
  123134. 1, -518283264, 1627103232, 3, 0,
  123135. _vq_quantlist__44c0_s_p8_0,
  123136. NULL,
  123137. &_vq_auxt__44c0_s_p8_0,
  123138. NULL,
  123139. 0
  123140. };
  123141. static long _vq_quantlist__44c0_s_p8_1[] = {
  123142. 6,
  123143. 5,
  123144. 7,
  123145. 4,
  123146. 8,
  123147. 3,
  123148. 9,
  123149. 2,
  123150. 10,
  123151. 1,
  123152. 11,
  123153. 0,
  123154. 12,
  123155. };
  123156. static long _vq_lengthlist__44c0_s_p8_1[] = {
  123157. 1, 4, 4, 6, 6, 7, 7, 9, 9,11,12,13,12, 6, 5, 5,
  123158. 7, 7, 8, 8,10, 9,12,12,12,12, 6, 5, 5, 7, 7, 8,
  123159. 8,10, 9,12,11,11,13,16, 7, 7, 8, 8, 9, 9,10,10,
  123160. 12,12,13,12,16, 7, 7, 8, 7, 9, 9,10,10,11,12,12,
  123161. 13,16,10,10, 8, 8,10,10,11,12,12,12,13,13,16,11,
  123162. 10, 8, 7,11,10,11,11,12,11,13,13,16,16,16,10,10,
  123163. 10,10,11,11,13,12,13,13,16,16,16,11, 9,11, 9,15,
  123164. 13,12,13,13,13,16,16,16,15,13,11,11,12,13,12,12,
  123165. 14,13,16,16,16,14,13,11,11,13,12,14,13,13,13,16,
  123166. 16,16,16,16,13,13,13,12,14,13,14,14,16,16,16,16,
  123167. 16,13,13,12,12,14,14,15,13,
  123168. };
  123169. static float _vq_quantthresh__44c0_s_p8_1[] = {
  123170. -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5, 25.5,
  123171. 42.5, 59.5, 76.5, 93.5,
  123172. };
  123173. static long _vq_quantmap__44c0_s_p8_1[] = {
  123174. 11, 9, 7, 5, 3, 1, 0, 2,
  123175. 4, 6, 8, 10, 12,
  123176. };
  123177. static encode_aux_threshmatch _vq_auxt__44c0_s_p8_1 = {
  123178. _vq_quantthresh__44c0_s_p8_1,
  123179. _vq_quantmap__44c0_s_p8_1,
  123180. 13,
  123181. 13
  123182. };
  123183. static static_codebook _44c0_s_p8_1 = {
  123184. 2, 169,
  123185. _vq_lengthlist__44c0_s_p8_1,
  123186. 1, -522616832, 1620115456, 4, 0,
  123187. _vq_quantlist__44c0_s_p8_1,
  123188. NULL,
  123189. &_vq_auxt__44c0_s_p8_1,
  123190. NULL,
  123191. 0
  123192. };
  123193. static long _vq_quantlist__44c0_s_p8_2[] = {
  123194. 8,
  123195. 7,
  123196. 9,
  123197. 6,
  123198. 10,
  123199. 5,
  123200. 11,
  123201. 4,
  123202. 12,
  123203. 3,
  123204. 13,
  123205. 2,
  123206. 14,
  123207. 1,
  123208. 15,
  123209. 0,
  123210. 16,
  123211. };
  123212. static long _vq_lengthlist__44c0_s_p8_2[] = {
  123213. 2, 4, 4, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8,
  123214. 8,10,10,10, 7, 7, 7, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  123215. 9, 9,10,10,10, 7, 7, 7, 7, 8, 8, 9, 9, 9, 9, 9,
  123216. 9, 9, 9,10,10,10, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9,
  123217. 9,10, 9, 9,10,10,10, 7, 7, 8, 8, 9, 8, 9, 9, 9,
  123218. 9,10, 9, 9,10,10,10,10, 8, 8, 8, 8, 9, 8, 9, 9,
  123219. 9, 9, 9,10, 9,10,10,10,10, 7, 7, 8, 8, 9, 9, 9,
  123220. 9, 9, 9,10, 9,10,10,10,10,10, 8, 8, 8, 9, 9, 9,
  123221. 9, 9, 9, 9,10,10,10, 9,11,10,10,10,10, 8, 8, 9,
  123222. 9, 9, 9, 9,10, 9, 9, 9,10,10,10,10,11,11, 9, 9,
  123223. 9, 9, 9, 9, 9, 9,10, 9, 9,10,11,10,10,11,11, 9,
  123224. 9, 9, 9, 9, 9, 9, 9, 9, 9,10, 9,11,11,10,11,11,
  123225. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10, 9,11,10,10,11,
  123226. 11,11,11, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10,10,
  123227. 11,11,11,11, 9,10, 9,10, 9, 9, 9, 9,10, 9,10,11,
  123228. 10,11,10,10,10,10,10, 9, 9, 9,10, 9, 9, 9,10,11,
  123229. 11,10,11,11,10,11,10,10,10, 9, 9, 9, 9,10, 9, 9,
  123230. 10,11,10,11,11,11,11,10,11,10,10, 9,10, 9, 9, 9,
  123231. 10,
  123232. };
  123233. static float _vq_quantthresh__44c0_s_p8_2[] = {
  123234. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  123235. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  123236. };
  123237. static long _vq_quantmap__44c0_s_p8_2[] = {
  123238. 15, 13, 11, 9, 7, 5, 3, 1,
  123239. 0, 2, 4, 6, 8, 10, 12, 14,
  123240. 16,
  123241. };
  123242. static encode_aux_threshmatch _vq_auxt__44c0_s_p8_2 = {
  123243. _vq_quantthresh__44c0_s_p8_2,
  123244. _vq_quantmap__44c0_s_p8_2,
  123245. 17,
  123246. 17
  123247. };
  123248. static static_codebook _44c0_s_p8_2 = {
  123249. 2, 289,
  123250. _vq_lengthlist__44c0_s_p8_2,
  123251. 1, -529530880, 1611661312, 5, 0,
  123252. _vq_quantlist__44c0_s_p8_2,
  123253. NULL,
  123254. &_vq_auxt__44c0_s_p8_2,
  123255. NULL,
  123256. 0
  123257. };
  123258. static long _huff_lengthlist__44c0_s_short[] = {
  123259. 9, 8,12,11,12,13,14,14,16, 6, 1, 5, 6, 6, 9,12,
  123260. 14,17, 9, 4, 5, 9, 7, 9,13,15,16, 8, 5, 8, 6, 8,
  123261. 10,13,17,17, 9, 6, 7, 7, 8, 9,13,15,17,11, 8, 9,
  123262. 9, 9,10,12,16,16,13, 7, 8, 7, 7, 9,12,14,15,13,
  123263. 6, 7, 5, 5, 7,10,13,13,14, 7, 8, 5, 6, 7, 9,10,
  123264. 12,
  123265. };
  123266. static static_codebook _huff_book__44c0_s_short = {
  123267. 2, 81,
  123268. _huff_lengthlist__44c0_s_short,
  123269. 0, 0, 0, 0, 0,
  123270. NULL,
  123271. NULL,
  123272. NULL,
  123273. NULL,
  123274. 0
  123275. };
  123276. static long _huff_lengthlist__44c0_sm_long[] = {
  123277. 5, 4, 9,10, 9,10,11,12,13, 4, 1, 5, 7, 7, 9,11,
  123278. 12,14, 8, 5, 7, 9, 8,10,13,13,13,10, 7, 9, 4, 6,
  123279. 7,10,12,14, 9, 6, 7, 6, 6, 7,10,12,12, 9, 8, 9,
  123280. 7, 6, 7, 8,11,12,11,11,11, 9, 8, 7, 8,10,12,12,
  123281. 13,14,12,11, 9, 9, 9,12,12,17,17,15,16,12,10,11,
  123282. 13,
  123283. };
  123284. static static_codebook _huff_book__44c0_sm_long = {
  123285. 2, 81,
  123286. _huff_lengthlist__44c0_sm_long,
  123287. 0, 0, 0, 0, 0,
  123288. NULL,
  123289. NULL,
  123290. NULL,
  123291. NULL,
  123292. 0
  123293. };
  123294. static long _vq_quantlist__44c0_sm_p1_0[] = {
  123295. 1,
  123296. 0,
  123297. 2,
  123298. };
  123299. static long _vq_lengthlist__44c0_sm_p1_0[] = {
  123300. 1, 5, 5, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0, 0, 0, 0,
  123301. 0, 0, 5, 7, 7, 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, 5, 8, 7, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0, 0,
  123306. 0, 0, 0, 7, 8, 9, 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, 5, 7, 7, 0, 0, 0, 0, 0, 0, 7, 9, 8, 0, 0,
  123311. 0, 0, 0, 0, 7, 9, 9, 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, 5, 8, 7, 0, 0, 0, 0,
  123346. 0, 0, 8, 9, 9, 0, 0, 0, 0, 0, 0, 8, 9, 9, 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, 7, 9, 9, 0, 0, 0,
  123351. 0, 0, 0, 9,10,10, 0, 0, 0, 0, 0, 0, 9,10,10, 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, 7, 9, 9, 0, 0,
  123356. 0, 0, 0, 0, 8,10, 9, 0, 0, 0, 0, 0, 0, 9,10,10,
  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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123367. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123368. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123369. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123370. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123371. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123372. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123373. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123374. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123375. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123376. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123377. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123378. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123379. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123380. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123381. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123382. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123383. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123384. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123385. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123386. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123387. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123388. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123389. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123390. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123391. 0, 0, 5, 7, 8, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0,
  123392. 0, 0, 0, 0, 8, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123393. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123394. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123395. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123396. 0, 0, 0, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,10,10, 0,
  123397. 0, 0, 0, 0, 0, 9, 9,10, 0, 0, 0, 0, 0, 0, 0, 0,
  123398. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123399. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123400. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123401. 0, 0, 0, 0, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,10,10,
  123402. 0, 0, 0, 0, 0, 0, 9,10,10, 0, 0, 0, 0, 0, 0, 0,
  123403. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123404. 0, 0, 0, 0, 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123438. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123439. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123440. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123441. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123442. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123443. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123444. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123445. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123446. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123447. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123448. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123449. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123450. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123451. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123452. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123453. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123454. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123455. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123456. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123457. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123458. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123459. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123460. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123461. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123462. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123463. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123464. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123465. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123466. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123467. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123468. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123469. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123470. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123471. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123472. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123473. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123474. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123475. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123476. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123477. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123478. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123479. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123480. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123481. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123482. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123483. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123484. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123485. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123486. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123487. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123488. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123489. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123490. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123491. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123492. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123493. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123494. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123495. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123496. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123497. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123498. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123499. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123500. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123501. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123502. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123503. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123504. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123505. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123506. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123507. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123508. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123509. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123510. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123511. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123512. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123513. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123514. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123515. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123516. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123517. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123518. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123519. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123520. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123521. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123522. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123523. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123524. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123525. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123526. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123527. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123528. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123529. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123530. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123531. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123532. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123533. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123534. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123535. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123536. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123537. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123538. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123539. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123540. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123541. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123542. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123543. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123544. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123545. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123546. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123547. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123548. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123549. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123550. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123551. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123552. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123553. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123554. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123555. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123556. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123557. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123558. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123559. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123560. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123561. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123562. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123563. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123564. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123565. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123566. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123567. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123568. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123569. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123570. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123571. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123572. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123573. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123574. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123575. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123576. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123577. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123578. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123579. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123580. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123581. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123582. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123583. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123584. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123585. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123586. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123587. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123588. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123589. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123590. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123591. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123592. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123593. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123594. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123595. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123596. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123597. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123598. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123599. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123600. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123601. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123602. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123603. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123604. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123605. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123606. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123607. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123608. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123609. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123610. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123611. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123612. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123613. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123614. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123615. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123616. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123617. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123618. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123619. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123620. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123621. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123622. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123623. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123624. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123625. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123626. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123627. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123628. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123629. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123630. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123631. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123632. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123633. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123634. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123635. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123636. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123637. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123638. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123639. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123640. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123641. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123642. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123643. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123644. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123645. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123646. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123647. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123648. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123649. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123650. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123651. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123652. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123653. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123654. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123655. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123656. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123657. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123658. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123659. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123660. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123661. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123662. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123663. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123664. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123665. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123666. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123667. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123668. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123669. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123670. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123671. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123672. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123673. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123674. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123675. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123676. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123677. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123678. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123679. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123680. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123681. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123682. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123683. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123684. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123685. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123686. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123687. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123688. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123689. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123690. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123691. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123692. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123693. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123694. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123695. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123696. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123697. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123698. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123699. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123700. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123701. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123702. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123703. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123704. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123705. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123706. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123707. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123708. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123709. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123710. 0,
  123711. };
  123712. static float _vq_quantthresh__44c0_sm_p1_0[] = {
  123713. -0.5, 0.5,
  123714. };
  123715. static long _vq_quantmap__44c0_sm_p1_0[] = {
  123716. 1, 0, 2,
  123717. };
  123718. static encode_aux_threshmatch _vq_auxt__44c0_sm_p1_0 = {
  123719. _vq_quantthresh__44c0_sm_p1_0,
  123720. _vq_quantmap__44c0_sm_p1_0,
  123721. 3,
  123722. 3
  123723. };
  123724. static static_codebook _44c0_sm_p1_0 = {
  123725. 8, 6561,
  123726. _vq_lengthlist__44c0_sm_p1_0,
  123727. 1, -535822336, 1611661312, 2, 0,
  123728. _vq_quantlist__44c0_sm_p1_0,
  123729. NULL,
  123730. &_vq_auxt__44c0_sm_p1_0,
  123731. NULL,
  123732. 0
  123733. };
  123734. static long _vq_quantlist__44c0_sm_p2_0[] = {
  123735. 2,
  123736. 1,
  123737. 3,
  123738. 0,
  123739. 4,
  123740. };
  123741. static long _vq_lengthlist__44c0_sm_p2_0[] = {
  123742. 1, 4, 4, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123743. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 5, 5, 7, 7, 0, 0,
  123744. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123745. 0, 0, 4, 5, 5, 7, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123746. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 7, 7, 9, 9,
  123747. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123748. 0, 0, 0, 0, 7, 7, 7, 9, 9, 0, 0, 0, 0, 0, 0, 0,
  123749. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123750. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123751. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123752. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123753. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123754. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123755. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123756. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123757. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123758. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123759. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123760. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123761. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123762. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123763. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123764. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123765. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123766. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123767. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123768. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123769. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123770. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123771. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123772. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123773. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123774. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123775. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123776. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123777. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123778. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123779. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123780. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123781. 0,
  123782. };
  123783. static float _vq_quantthresh__44c0_sm_p2_0[] = {
  123784. -1.5, -0.5, 0.5, 1.5,
  123785. };
  123786. static long _vq_quantmap__44c0_sm_p2_0[] = {
  123787. 3, 1, 0, 2, 4,
  123788. };
  123789. static encode_aux_threshmatch _vq_auxt__44c0_sm_p2_0 = {
  123790. _vq_quantthresh__44c0_sm_p2_0,
  123791. _vq_quantmap__44c0_sm_p2_0,
  123792. 5,
  123793. 5
  123794. };
  123795. static static_codebook _44c0_sm_p2_0 = {
  123796. 4, 625,
  123797. _vq_lengthlist__44c0_sm_p2_0,
  123798. 1, -533725184, 1611661312, 3, 0,
  123799. _vq_quantlist__44c0_sm_p2_0,
  123800. NULL,
  123801. &_vq_auxt__44c0_sm_p2_0,
  123802. NULL,
  123803. 0
  123804. };
  123805. static long _vq_quantlist__44c0_sm_p3_0[] = {
  123806. 4,
  123807. 3,
  123808. 5,
  123809. 2,
  123810. 6,
  123811. 1,
  123812. 7,
  123813. 0,
  123814. 8,
  123815. };
  123816. static long _vq_lengthlist__44c0_sm_p3_0[] = {
  123817. 1, 3, 3, 7, 7, 0, 0, 0, 0, 0, 5, 4, 7, 7, 0, 0,
  123818. 0, 0, 0, 5, 5, 7, 7, 0, 0, 0, 0, 0, 6, 7, 8, 8,
  123819. 0, 0, 0, 0, 0, 0, 0, 8, 8, 0, 0, 0, 0, 0, 0, 0,
  123820. 9,10, 0, 0, 0, 0, 0, 0, 0, 9, 9, 0, 0, 0, 0, 0,
  123821. 0, 0,11,11, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123822. 0,
  123823. };
  123824. static float _vq_quantthresh__44c0_sm_p3_0[] = {
  123825. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  123826. };
  123827. static long _vq_quantmap__44c0_sm_p3_0[] = {
  123828. 7, 5, 3, 1, 0, 2, 4, 6,
  123829. 8,
  123830. };
  123831. static encode_aux_threshmatch _vq_auxt__44c0_sm_p3_0 = {
  123832. _vq_quantthresh__44c0_sm_p3_0,
  123833. _vq_quantmap__44c0_sm_p3_0,
  123834. 9,
  123835. 9
  123836. };
  123837. static static_codebook _44c0_sm_p3_0 = {
  123838. 2, 81,
  123839. _vq_lengthlist__44c0_sm_p3_0,
  123840. 1, -531628032, 1611661312, 4, 0,
  123841. _vq_quantlist__44c0_sm_p3_0,
  123842. NULL,
  123843. &_vq_auxt__44c0_sm_p3_0,
  123844. NULL,
  123845. 0
  123846. };
  123847. static long _vq_quantlist__44c0_sm_p4_0[] = {
  123848. 4,
  123849. 3,
  123850. 5,
  123851. 2,
  123852. 6,
  123853. 1,
  123854. 7,
  123855. 0,
  123856. 8,
  123857. };
  123858. static long _vq_lengthlist__44c0_sm_p4_0[] = {
  123859. 1, 4, 3, 6, 6, 7, 7, 9, 9, 0, 5, 5, 7, 7, 8, 7,
  123860. 9, 9, 0, 5, 5, 7, 7, 8, 8, 9, 9, 0, 7, 7, 8, 8,
  123861. 8, 8,10,10, 0, 0, 0, 8, 8, 8, 8,10,10, 0, 0, 0,
  123862. 9, 9, 9, 9,11,11, 0, 0, 0, 9, 9, 9, 9,11,11, 0,
  123863. 0, 0,10,10,10,10,11,11, 0, 0, 0, 0, 0, 9, 9,11,
  123864. 11,
  123865. };
  123866. static float _vq_quantthresh__44c0_sm_p4_0[] = {
  123867. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  123868. };
  123869. static long _vq_quantmap__44c0_sm_p4_0[] = {
  123870. 7, 5, 3, 1, 0, 2, 4, 6,
  123871. 8,
  123872. };
  123873. static encode_aux_threshmatch _vq_auxt__44c0_sm_p4_0 = {
  123874. _vq_quantthresh__44c0_sm_p4_0,
  123875. _vq_quantmap__44c0_sm_p4_0,
  123876. 9,
  123877. 9
  123878. };
  123879. static static_codebook _44c0_sm_p4_0 = {
  123880. 2, 81,
  123881. _vq_lengthlist__44c0_sm_p4_0,
  123882. 1, -531628032, 1611661312, 4, 0,
  123883. _vq_quantlist__44c0_sm_p4_0,
  123884. NULL,
  123885. &_vq_auxt__44c0_sm_p4_0,
  123886. NULL,
  123887. 0
  123888. };
  123889. static long _vq_quantlist__44c0_sm_p5_0[] = {
  123890. 8,
  123891. 7,
  123892. 9,
  123893. 6,
  123894. 10,
  123895. 5,
  123896. 11,
  123897. 4,
  123898. 12,
  123899. 3,
  123900. 13,
  123901. 2,
  123902. 14,
  123903. 1,
  123904. 15,
  123905. 0,
  123906. 16,
  123907. };
  123908. static long _vq_lengthlist__44c0_sm_p5_0[] = {
  123909. 1, 4, 4, 6, 6, 8, 8, 8, 8, 8, 8, 9, 9,10,10,11,
  123910. 11, 0, 6, 6, 7, 7, 8, 8, 9, 9, 9, 9,10,10,10,11,
  123911. 11,11, 0, 5, 6, 7, 7, 8, 8, 9, 9, 9, 9,10,10,10,
  123912. 11,11,11, 0, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9,10,10,
  123913. 11,11,12,12, 0, 0, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,
  123914. 10,11,11,12,12, 0, 0, 0, 8, 8, 9, 9,10,10,10,10,
  123915. 11,11,11,11,12,12, 0, 0, 0, 8, 8, 9, 9,10,10,10,
  123916. 10,11,11,11,11,12,12, 0, 0, 0, 9, 9, 9, 9,10,10,
  123917. 10,10,11,11,12,12,12,13, 0, 0, 0, 0, 0, 9, 9,10,
  123918. 10,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9, 9,
  123919. 10,10,11,11,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9,
  123920. 9,10,10,11,10,11,11,12,12,13,13, 0, 0, 0, 0, 0,
  123921. 10,10,10,10,11,11,12,12,12,13,13,13, 0, 0, 0, 0,
  123922. 0, 0, 0,10,10,11,11,12,12,12,13,13,13, 0, 0, 0,
  123923. 0, 0, 0, 0,11,11,12,12,12,12,13,13,14,14, 0, 0,
  123924. 0, 0, 0, 0, 0,11,11,12,11,12,12,13,13,13,13, 0,
  123925. 0, 0, 0, 0, 0, 0,12,12,12,12,13,13,13,13,14,14,
  123926. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,12,12,13,13,14,
  123927. 14,
  123928. };
  123929. static float _vq_quantthresh__44c0_sm_p5_0[] = {
  123930. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  123931. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  123932. };
  123933. static long _vq_quantmap__44c0_sm_p5_0[] = {
  123934. 15, 13, 11, 9, 7, 5, 3, 1,
  123935. 0, 2, 4, 6, 8, 10, 12, 14,
  123936. 16,
  123937. };
  123938. static encode_aux_threshmatch _vq_auxt__44c0_sm_p5_0 = {
  123939. _vq_quantthresh__44c0_sm_p5_0,
  123940. _vq_quantmap__44c0_sm_p5_0,
  123941. 17,
  123942. 17
  123943. };
  123944. static static_codebook _44c0_sm_p5_0 = {
  123945. 2, 289,
  123946. _vq_lengthlist__44c0_sm_p5_0,
  123947. 1, -529530880, 1611661312, 5, 0,
  123948. _vq_quantlist__44c0_sm_p5_0,
  123949. NULL,
  123950. &_vq_auxt__44c0_sm_p5_0,
  123951. NULL,
  123952. 0
  123953. };
  123954. static long _vq_quantlist__44c0_sm_p6_0[] = {
  123955. 1,
  123956. 0,
  123957. 2,
  123958. };
  123959. static long _vq_lengthlist__44c0_sm_p6_0[] = {
  123960. 1, 4, 4, 7, 6, 6, 7, 6, 6, 4, 7, 7,10, 9, 9,11,
  123961. 9, 9, 4, 7, 7,10, 9, 9,11, 9, 9, 7,10,10,10,11,
  123962. 11,11,10,10, 6, 9, 9,11,11,10,11,10,10, 6, 9, 9,
  123963. 11,10,11,11,10,10, 7,11,10,11,11,11,11,11,11, 6,
  123964. 9, 9,11,10,10,11,11,10, 6, 9, 9,11,10,10,11,10,
  123965. 11,
  123966. };
  123967. static float _vq_quantthresh__44c0_sm_p6_0[] = {
  123968. -5.5, 5.5,
  123969. };
  123970. static long _vq_quantmap__44c0_sm_p6_0[] = {
  123971. 1, 0, 2,
  123972. };
  123973. static encode_aux_threshmatch _vq_auxt__44c0_sm_p6_0 = {
  123974. _vq_quantthresh__44c0_sm_p6_0,
  123975. _vq_quantmap__44c0_sm_p6_0,
  123976. 3,
  123977. 3
  123978. };
  123979. static static_codebook _44c0_sm_p6_0 = {
  123980. 4, 81,
  123981. _vq_lengthlist__44c0_sm_p6_0,
  123982. 1, -529137664, 1618345984, 2, 0,
  123983. _vq_quantlist__44c0_sm_p6_0,
  123984. NULL,
  123985. &_vq_auxt__44c0_sm_p6_0,
  123986. NULL,
  123987. 0
  123988. };
  123989. static long _vq_quantlist__44c0_sm_p6_1[] = {
  123990. 5,
  123991. 4,
  123992. 6,
  123993. 3,
  123994. 7,
  123995. 2,
  123996. 8,
  123997. 1,
  123998. 9,
  123999. 0,
  124000. 10,
  124001. };
  124002. static long _vq_lengthlist__44c0_sm_p6_1[] = {
  124003. 2, 4, 4, 6, 6, 7, 7, 7, 7, 7, 8, 9, 5, 5, 6, 6,
  124004. 7, 7, 8, 8, 8, 8, 9, 5, 5, 6, 6, 7, 7, 8, 8, 8,
  124005. 8,10, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8,10,10,10, 7,
  124006. 7, 7, 7, 8, 8, 8, 8,10,10,10, 8, 8, 8, 8, 8, 8,
  124007. 8, 8,10,10,10, 8, 8, 8, 8, 8, 8, 8, 8,10,10,10,
  124008. 8, 8, 8, 8, 8, 8, 8, 8,10,10,10,10,10, 8, 8, 8,
  124009. 8, 8, 8,10,10,10,10,10, 9, 9, 8, 8, 8, 8,10,10,
  124010. 10,10,10, 8, 8, 8, 8, 8, 8,
  124011. };
  124012. static float _vq_quantthresh__44c0_sm_p6_1[] = {
  124013. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  124014. 3.5, 4.5,
  124015. };
  124016. static long _vq_quantmap__44c0_sm_p6_1[] = {
  124017. 9, 7, 5, 3, 1, 0, 2, 4,
  124018. 6, 8, 10,
  124019. };
  124020. static encode_aux_threshmatch _vq_auxt__44c0_sm_p6_1 = {
  124021. _vq_quantthresh__44c0_sm_p6_1,
  124022. _vq_quantmap__44c0_sm_p6_1,
  124023. 11,
  124024. 11
  124025. };
  124026. static static_codebook _44c0_sm_p6_1 = {
  124027. 2, 121,
  124028. _vq_lengthlist__44c0_sm_p6_1,
  124029. 1, -531365888, 1611661312, 4, 0,
  124030. _vq_quantlist__44c0_sm_p6_1,
  124031. NULL,
  124032. &_vq_auxt__44c0_sm_p6_1,
  124033. NULL,
  124034. 0
  124035. };
  124036. static long _vq_quantlist__44c0_sm_p7_0[] = {
  124037. 6,
  124038. 5,
  124039. 7,
  124040. 4,
  124041. 8,
  124042. 3,
  124043. 9,
  124044. 2,
  124045. 10,
  124046. 1,
  124047. 11,
  124048. 0,
  124049. 12,
  124050. };
  124051. static long _vq_lengthlist__44c0_sm_p7_0[] = {
  124052. 1, 4, 4, 6, 6, 7, 7, 7, 7, 8, 8, 9, 9, 7, 5, 5,
  124053. 7, 7, 8, 8, 8, 8, 9, 9,10,10, 7, 6, 5, 7, 7, 8,
  124054. 8, 8, 8, 9, 9,10,10, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  124055. 10,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,
  124056. 11, 0,12,12, 9, 9,10,10,10,10,11,11,11,11, 0,13,
  124057. 13, 9, 9, 9, 9,10,10,11,11,11,12, 0, 0, 0, 9,10,
  124058. 10,10,11,11,12,11,12,12, 0, 0, 0,10,10, 9, 9,11,
  124059. 11,12,12,12,12, 0, 0, 0,13,13,10,10,11,11,12,12,
  124060. 13,13, 0, 0, 0,14,14,10,10,11,11,12,12,13,13, 0,
  124061. 0, 0, 0, 0,11,12,11,11,13,12,13,13, 0, 0, 0, 0,
  124062. 0,12,12,11,11,13,12,14,14,
  124063. };
  124064. static float _vq_quantthresh__44c0_sm_p7_0[] = {
  124065. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  124066. 12.5, 17.5, 22.5, 27.5,
  124067. };
  124068. static long _vq_quantmap__44c0_sm_p7_0[] = {
  124069. 11, 9, 7, 5, 3, 1, 0, 2,
  124070. 4, 6, 8, 10, 12,
  124071. };
  124072. static encode_aux_threshmatch _vq_auxt__44c0_sm_p7_0 = {
  124073. _vq_quantthresh__44c0_sm_p7_0,
  124074. _vq_quantmap__44c0_sm_p7_0,
  124075. 13,
  124076. 13
  124077. };
  124078. static static_codebook _44c0_sm_p7_0 = {
  124079. 2, 169,
  124080. _vq_lengthlist__44c0_sm_p7_0,
  124081. 1, -526516224, 1616117760, 4, 0,
  124082. _vq_quantlist__44c0_sm_p7_0,
  124083. NULL,
  124084. &_vq_auxt__44c0_sm_p7_0,
  124085. NULL,
  124086. 0
  124087. };
  124088. static long _vq_quantlist__44c0_sm_p7_1[] = {
  124089. 2,
  124090. 1,
  124091. 3,
  124092. 0,
  124093. 4,
  124094. };
  124095. static long _vq_lengthlist__44c0_sm_p7_1[] = {
  124096. 2, 4, 4, 4, 4, 6, 5, 5, 5, 5, 6, 5, 5, 5, 5, 6,
  124097. 6, 6, 5, 5, 6, 6, 6, 5, 5,
  124098. };
  124099. static float _vq_quantthresh__44c0_sm_p7_1[] = {
  124100. -1.5, -0.5, 0.5, 1.5,
  124101. };
  124102. static long _vq_quantmap__44c0_sm_p7_1[] = {
  124103. 3, 1, 0, 2, 4,
  124104. };
  124105. static encode_aux_threshmatch _vq_auxt__44c0_sm_p7_1 = {
  124106. _vq_quantthresh__44c0_sm_p7_1,
  124107. _vq_quantmap__44c0_sm_p7_1,
  124108. 5,
  124109. 5
  124110. };
  124111. static static_codebook _44c0_sm_p7_1 = {
  124112. 2, 25,
  124113. _vq_lengthlist__44c0_sm_p7_1,
  124114. 1, -533725184, 1611661312, 3, 0,
  124115. _vq_quantlist__44c0_sm_p7_1,
  124116. NULL,
  124117. &_vq_auxt__44c0_sm_p7_1,
  124118. NULL,
  124119. 0
  124120. };
  124121. static long _vq_quantlist__44c0_sm_p8_0[] = {
  124122. 4,
  124123. 3,
  124124. 5,
  124125. 2,
  124126. 6,
  124127. 1,
  124128. 7,
  124129. 0,
  124130. 8,
  124131. };
  124132. static long _vq_lengthlist__44c0_sm_p8_0[] = {
  124133. 1, 3, 3,11,11,11,11,11,11, 3, 7, 6,11,11,11,11,
  124134. 11,11, 4, 8, 7,11,11,11,11,11,11,11,11,11,11,11,
  124135. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  124136. 11,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  124137. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  124138. 12,
  124139. };
  124140. static float _vq_quantthresh__44c0_sm_p8_0[] = {
  124141. -773.5, -552.5, -331.5, -110.5, 110.5, 331.5, 552.5, 773.5,
  124142. };
  124143. static long _vq_quantmap__44c0_sm_p8_0[] = {
  124144. 7, 5, 3, 1, 0, 2, 4, 6,
  124145. 8,
  124146. };
  124147. static encode_aux_threshmatch _vq_auxt__44c0_sm_p8_0 = {
  124148. _vq_quantthresh__44c0_sm_p8_0,
  124149. _vq_quantmap__44c0_sm_p8_0,
  124150. 9,
  124151. 9
  124152. };
  124153. static static_codebook _44c0_sm_p8_0 = {
  124154. 2, 81,
  124155. _vq_lengthlist__44c0_sm_p8_0,
  124156. 1, -516186112, 1627103232, 4, 0,
  124157. _vq_quantlist__44c0_sm_p8_0,
  124158. NULL,
  124159. &_vq_auxt__44c0_sm_p8_0,
  124160. NULL,
  124161. 0
  124162. };
  124163. static long _vq_quantlist__44c0_sm_p8_1[] = {
  124164. 6,
  124165. 5,
  124166. 7,
  124167. 4,
  124168. 8,
  124169. 3,
  124170. 9,
  124171. 2,
  124172. 10,
  124173. 1,
  124174. 11,
  124175. 0,
  124176. 12,
  124177. };
  124178. static long _vq_lengthlist__44c0_sm_p8_1[] = {
  124179. 1, 4, 4, 6, 6, 7, 7, 9, 9,10,11,12,12, 6, 5, 5,
  124180. 7, 7, 8, 8,10,10,12,11,12,12, 6, 5, 5, 7, 7, 8,
  124181. 8,10,10,12,11,12,12,17, 7, 7, 8, 8, 9, 9,10,10,
  124182. 12,12,13,13,18, 7, 7, 8, 7, 9, 9,10,10,12,12,12,
  124183. 13,19,10,10, 8, 8,10,10,11,11,12,12,13,14,19,11,
  124184. 10, 8, 7,10,10,11,11,12,12,13,12,19,19,19,10,10,
  124185. 10,10,11,11,12,12,13,13,19,19,19,11, 9,11, 9,14,
  124186. 12,13,12,13,13,19,20,18,13,14,11,11,12,12,13,13,
  124187. 14,13,20,20,20,15,13,11,10,13,11,13,13,14,13,20,
  124188. 20,20,20,20,13,14,12,12,13,13,13,13,20,20,20,20,
  124189. 20,13,13,12,12,16,13,15,13,
  124190. };
  124191. static float _vq_quantthresh__44c0_sm_p8_1[] = {
  124192. -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5, 25.5,
  124193. 42.5, 59.5, 76.5, 93.5,
  124194. };
  124195. static long _vq_quantmap__44c0_sm_p8_1[] = {
  124196. 11, 9, 7, 5, 3, 1, 0, 2,
  124197. 4, 6, 8, 10, 12,
  124198. };
  124199. static encode_aux_threshmatch _vq_auxt__44c0_sm_p8_1 = {
  124200. _vq_quantthresh__44c0_sm_p8_1,
  124201. _vq_quantmap__44c0_sm_p8_1,
  124202. 13,
  124203. 13
  124204. };
  124205. static static_codebook _44c0_sm_p8_1 = {
  124206. 2, 169,
  124207. _vq_lengthlist__44c0_sm_p8_1,
  124208. 1, -522616832, 1620115456, 4, 0,
  124209. _vq_quantlist__44c0_sm_p8_1,
  124210. NULL,
  124211. &_vq_auxt__44c0_sm_p8_1,
  124212. NULL,
  124213. 0
  124214. };
  124215. static long _vq_quantlist__44c0_sm_p8_2[] = {
  124216. 8,
  124217. 7,
  124218. 9,
  124219. 6,
  124220. 10,
  124221. 5,
  124222. 11,
  124223. 4,
  124224. 12,
  124225. 3,
  124226. 13,
  124227. 2,
  124228. 14,
  124229. 1,
  124230. 15,
  124231. 0,
  124232. 16,
  124233. };
  124234. static long _vq_lengthlist__44c0_sm_p8_2[] = {
  124235. 2, 5, 5, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8,
  124236. 8,10, 6, 6, 7, 7, 7, 7, 8, 8, 9, 9, 9, 9, 9, 9,
  124237. 9, 9,10, 6, 6, 7, 7, 8, 7, 8, 8, 9, 9, 9, 9, 9,
  124238. 9, 9, 9,10, 7, 7, 7, 7, 8, 8, 8, 9, 9, 9, 9, 9,
  124239. 9, 9, 9, 9,10,10,10, 7, 7, 8, 8, 9, 8, 9, 9, 9,
  124240. 9,10, 9, 9,10,10,10,11, 8, 8, 8, 8, 9, 9, 9, 9,
  124241. 9, 9, 9,10, 9,10,10,10,10, 8, 8, 8, 8, 9, 9, 9,
  124242. 9, 9, 9, 9, 9,10,10,11,10,10, 8, 8, 9, 9, 9, 9,
  124243. 9, 9, 9, 9, 9, 9,10,10,10,10,10,11,11, 8, 8, 9,
  124244. 9, 9, 9, 9, 9, 9, 9, 9,10,11,11,11,11,11, 9, 9,
  124245. 9, 9, 9, 9, 9, 9,10, 9,10, 9,11,11,10,11,11, 9,
  124246. 9, 9, 9, 9, 9, 9, 9, 9, 9,10, 9,11,11,10,11,11,
  124247. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10, 9,11,10,11,11,
  124248. 11,11,11, 9, 9,10, 9, 9, 9, 9, 9, 9, 9,10,11,10,
  124249. 11,11,11,11,10,10,10,10, 9, 9, 9, 9, 9, 9,10,11,
  124250. 11,11,11,11,11, 9,10, 9, 9, 9, 9, 9, 9, 9, 9,11,
  124251. 11,10,11,11,11,10,10,10, 9, 9, 9, 9, 9, 9, 9, 9,
  124252. 10,11,10,11,11,11,11,11,11, 9, 9, 9, 9, 9, 9, 9,
  124253. 9,
  124254. };
  124255. static float _vq_quantthresh__44c0_sm_p8_2[] = {
  124256. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  124257. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  124258. };
  124259. static long _vq_quantmap__44c0_sm_p8_2[] = {
  124260. 15, 13, 11, 9, 7, 5, 3, 1,
  124261. 0, 2, 4, 6, 8, 10, 12, 14,
  124262. 16,
  124263. };
  124264. static encode_aux_threshmatch _vq_auxt__44c0_sm_p8_2 = {
  124265. _vq_quantthresh__44c0_sm_p8_2,
  124266. _vq_quantmap__44c0_sm_p8_2,
  124267. 17,
  124268. 17
  124269. };
  124270. static static_codebook _44c0_sm_p8_2 = {
  124271. 2, 289,
  124272. _vq_lengthlist__44c0_sm_p8_2,
  124273. 1, -529530880, 1611661312, 5, 0,
  124274. _vq_quantlist__44c0_sm_p8_2,
  124275. NULL,
  124276. &_vq_auxt__44c0_sm_p8_2,
  124277. NULL,
  124278. 0
  124279. };
  124280. static long _huff_lengthlist__44c0_sm_short[] = {
  124281. 6, 6,12,13,13,14,16,17,17, 4, 2, 5, 8, 7, 9,12,
  124282. 15,15, 9, 4, 5, 9, 7, 9,12,16,18,11, 6, 7, 4, 6,
  124283. 8,11,14,18,10, 5, 6, 5, 5, 7,10,14,17,10, 5, 7,
  124284. 7, 6, 7,10,13,16,11, 5, 7, 7, 7, 8,10,12,15,13,
  124285. 6, 7, 5, 5, 7, 9,12,13,16, 8, 9, 6, 6, 7, 9,10,
  124286. 12,
  124287. };
  124288. static static_codebook _huff_book__44c0_sm_short = {
  124289. 2, 81,
  124290. _huff_lengthlist__44c0_sm_short,
  124291. 0, 0, 0, 0, 0,
  124292. NULL,
  124293. NULL,
  124294. NULL,
  124295. NULL,
  124296. 0
  124297. };
  124298. static long _huff_lengthlist__44c1_s_long[] = {
  124299. 5, 5, 9,10, 9, 9,10,11,12, 5, 1, 5, 6, 6, 7,10,
  124300. 12,14, 9, 5, 6, 8, 8,10,12,14,14,10, 5, 8, 5, 6,
  124301. 8,11,13,14, 9, 5, 7, 6, 6, 8,10,12,11, 9, 7, 9,
  124302. 7, 6, 6, 7,10,10,10, 9,12, 9, 8, 7, 7,10,12,11,
  124303. 11,13,12,10, 9, 8, 9,11,11,14,15,15,13,11, 9, 9,
  124304. 11,
  124305. };
  124306. static static_codebook _huff_book__44c1_s_long = {
  124307. 2, 81,
  124308. _huff_lengthlist__44c1_s_long,
  124309. 0, 0, 0, 0, 0,
  124310. NULL,
  124311. NULL,
  124312. NULL,
  124313. NULL,
  124314. 0
  124315. };
  124316. static long _vq_quantlist__44c1_s_p1_0[] = {
  124317. 1,
  124318. 0,
  124319. 2,
  124320. };
  124321. static long _vq_lengthlist__44c1_s_p1_0[] = {
  124322. 2, 4, 4, 0, 0, 0, 0, 0, 0, 5, 7, 6, 0, 0, 0, 0,
  124323. 0, 0, 5, 6, 7, 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, 5, 7, 7, 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0, 0,
  124328. 0, 0, 0, 7, 8, 8, 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, 5, 7, 7, 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0,
  124333. 0, 0, 0, 0, 7, 8, 8, 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, 4, 7, 7, 0, 0, 0, 0,
  124368. 0, 0, 7, 8, 8, 0, 0, 0, 0, 0, 0, 7, 8, 8, 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, 7, 8, 8, 0, 0, 0,
  124373. 0, 0, 0, 8, 9,10, 0, 0, 0, 0, 0, 0, 8, 9, 9, 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, 6, 8, 8, 0, 0,
  124378. 0, 0, 0, 0, 8, 9, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9,
  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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124389. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124390. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124391. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124392. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124393. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124394. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124395. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124396. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124397. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124398. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124399. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124400. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124401. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124402. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124403. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124404. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124405. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124406. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124407. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124408. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124409. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124410. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124411. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124412. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124413. 0, 0, 4, 7, 7, 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0,
  124414. 0, 0, 0, 0, 7, 8, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124415. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124416. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124417. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124418. 0, 0, 0, 6, 8, 8, 0, 0, 0, 0, 0, 0, 8,10, 9, 0,
  124419. 0, 0, 0, 0, 0, 8, 8, 9, 0, 0, 0, 0, 0, 0, 0, 0,
  124420. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124421. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124422. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124423. 0, 0, 0, 0, 7, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9,
  124424. 0, 0, 0, 0, 0, 0, 8, 9, 9, 0, 0, 0, 0, 0, 0, 0,
  124425. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124426. 0, 0, 0, 0, 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124460. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124461. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124462. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124463. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124464. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124465. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124466. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124467. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124468. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124469. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124470. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124471. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124472. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124473. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124474. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124475. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124476. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124477. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124478. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124479. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124480. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124481. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124482. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124483. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124484. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124485. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124486. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124487. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124488. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124489. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124490. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124491. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124492. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124493. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124494. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124495. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124496. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124497. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124498. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124499. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124500. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124501. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124502. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124503. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124504. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124505. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124506. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124507. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124508. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124509. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124510. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124511. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124512. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124513. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124514. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124515. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124516. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124517. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124518. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124519. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124520. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124521. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124522. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124523. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124524. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124525. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124526. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124527. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124528. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124529. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124530. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124531. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124532. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124533. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124534. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124535. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124536. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124537. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124538. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124539. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124540. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124541. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124542. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124543. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124544. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124545. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124546. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124547. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124548. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124549. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124550. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124551. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124552. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124553. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124554. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124555. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124556. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124557. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124558. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124559. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124560. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124561. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124562. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124563. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124564. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124565. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124566. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124567. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124568. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124569. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124570. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124571. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124572. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124573. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124574. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124575. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124576. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124577. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124578. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124579. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124580. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124581. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124582. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124583. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124584. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124585. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124586. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124587. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124588. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124589. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124590. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124591. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124592. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124593. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124594. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124595. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124596. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124597. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124598. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124599. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124600. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124601. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124602. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124603. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124604. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124605. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124606. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124607. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124608. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124609. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124610. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124611. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124612. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124613. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124614. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124615. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124616. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124617. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124618. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124619. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124620. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124621. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124622. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124623. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124624. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124625. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124626. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124627. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124628. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124629. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124630. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124631. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124632. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124633. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124634. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124635. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124636. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124637. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124638. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124639. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124640. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124641. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124642. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124643. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124644. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124645. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124646. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124647. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124648. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124649. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124650. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124651. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124652. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124653. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124654. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124655. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124656. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124657. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124658. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124659. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124660. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124661. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124662. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124663. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124664. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124665. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124666. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124667. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124668. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124669. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124670. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124671. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124672. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124673. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124674. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124675. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124676. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124677. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124678. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124679. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124680. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124681. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124682. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124683. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124684. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124685. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124686. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124687. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124688. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124689. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124690. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124691. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124692. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124693. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124694. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124695. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124696. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124697. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124698. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124699. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124700. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124701. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124702. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124703. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124704. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124705. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124706. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124707. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124708. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124709. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124710. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124711. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124712. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124713. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124714. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124715. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124716. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124717. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124718. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124719. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124720. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124721. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124722. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124723. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124724. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124725. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124726. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124727. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124728. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124729. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124730. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124731. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124732. 0,
  124733. };
  124734. static float _vq_quantthresh__44c1_s_p1_0[] = {
  124735. -0.5, 0.5,
  124736. };
  124737. static long _vq_quantmap__44c1_s_p1_0[] = {
  124738. 1, 0, 2,
  124739. };
  124740. static encode_aux_threshmatch _vq_auxt__44c1_s_p1_0 = {
  124741. _vq_quantthresh__44c1_s_p1_0,
  124742. _vq_quantmap__44c1_s_p1_0,
  124743. 3,
  124744. 3
  124745. };
  124746. static static_codebook _44c1_s_p1_0 = {
  124747. 8, 6561,
  124748. _vq_lengthlist__44c1_s_p1_0,
  124749. 1, -535822336, 1611661312, 2, 0,
  124750. _vq_quantlist__44c1_s_p1_0,
  124751. NULL,
  124752. &_vq_auxt__44c1_s_p1_0,
  124753. NULL,
  124754. 0
  124755. };
  124756. static long _vq_quantlist__44c1_s_p2_0[] = {
  124757. 2,
  124758. 1,
  124759. 3,
  124760. 0,
  124761. 4,
  124762. };
  124763. static long _vq_lengthlist__44c1_s_p2_0[] = {
  124764. 2, 3, 4, 6, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124765. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 4, 4, 6, 6, 0, 0,
  124766. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124767. 0, 0, 4, 4, 5, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124768. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 6, 6, 8, 8,
  124769. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124770. 0, 0, 0, 0, 6, 6, 6, 8, 8, 0, 0, 0, 0, 0, 0, 0,
  124771. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124772. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124773. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124774. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124775. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124776. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124777. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124778. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124779. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124780. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124781. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124782. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124783. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124784. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124785. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124786. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124787. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124788. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124789. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124790. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124791. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124792. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124793. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124794. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124795. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124796. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124797. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124798. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124799. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124800. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124801. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124802. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124803. 0,
  124804. };
  124805. static float _vq_quantthresh__44c1_s_p2_0[] = {
  124806. -1.5, -0.5, 0.5, 1.5,
  124807. };
  124808. static long _vq_quantmap__44c1_s_p2_0[] = {
  124809. 3, 1, 0, 2, 4,
  124810. };
  124811. static encode_aux_threshmatch _vq_auxt__44c1_s_p2_0 = {
  124812. _vq_quantthresh__44c1_s_p2_0,
  124813. _vq_quantmap__44c1_s_p2_0,
  124814. 5,
  124815. 5
  124816. };
  124817. static static_codebook _44c1_s_p2_0 = {
  124818. 4, 625,
  124819. _vq_lengthlist__44c1_s_p2_0,
  124820. 1, -533725184, 1611661312, 3, 0,
  124821. _vq_quantlist__44c1_s_p2_0,
  124822. NULL,
  124823. &_vq_auxt__44c1_s_p2_0,
  124824. NULL,
  124825. 0
  124826. };
  124827. static long _vq_quantlist__44c1_s_p3_0[] = {
  124828. 4,
  124829. 3,
  124830. 5,
  124831. 2,
  124832. 6,
  124833. 1,
  124834. 7,
  124835. 0,
  124836. 8,
  124837. };
  124838. static long _vq_lengthlist__44c1_s_p3_0[] = {
  124839. 1, 3, 2, 7, 7, 0, 0, 0, 0, 0,13,13, 6, 6, 0, 0,
  124840. 0, 0, 0,12, 0, 6, 6, 0, 0, 0, 0, 0, 0, 0, 7, 7,
  124841. 0, 0, 0, 0, 0, 0, 0, 7, 7, 0, 0, 0, 0, 0, 0, 0,
  124842. 8, 9, 0, 0, 0, 0, 0, 0, 0, 8, 8, 0, 0, 0, 0, 0,
  124843. 0, 0,11,10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124844. 0,
  124845. };
  124846. static float _vq_quantthresh__44c1_s_p3_0[] = {
  124847. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  124848. };
  124849. static long _vq_quantmap__44c1_s_p3_0[] = {
  124850. 7, 5, 3, 1, 0, 2, 4, 6,
  124851. 8,
  124852. };
  124853. static encode_aux_threshmatch _vq_auxt__44c1_s_p3_0 = {
  124854. _vq_quantthresh__44c1_s_p3_0,
  124855. _vq_quantmap__44c1_s_p3_0,
  124856. 9,
  124857. 9
  124858. };
  124859. static static_codebook _44c1_s_p3_0 = {
  124860. 2, 81,
  124861. _vq_lengthlist__44c1_s_p3_0,
  124862. 1, -531628032, 1611661312, 4, 0,
  124863. _vq_quantlist__44c1_s_p3_0,
  124864. NULL,
  124865. &_vq_auxt__44c1_s_p3_0,
  124866. NULL,
  124867. 0
  124868. };
  124869. static long _vq_quantlist__44c1_s_p4_0[] = {
  124870. 4,
  124871. 3,
  124872. 5,
  124873. 2,
  124874. 6,
  124875. 1,
  124876. 7,
  124877. 0,
  124878. 8,
  124879. };
  124880. static long _vq_lengthlist__44c1_s_p4_0[] = {
  124881. 1, 3, 3, 6, 5, 6, 6, 8, 8, 0, 0, 0, 7, 7, 7, 7,
  124882. 9, 9, 0, 0, 0, 7, 7, 7, 7, 9, 9, 0, 0, 0, 7, 7,
  124883. 8, 8,10,10, 0, 0, 0, 7, 7, 8, 8,10,10, 0, 0, 0,
  124884. 9, 9, 8, 8,10,10, 0, 0, 0, 8, 8, 8, 8,10,10, 0,
  124885. 0, 0,10,10, 9, 9,11,11, 0, 0, 0, 0, 0, 9, 9,11,
  124886. 11,
  124887. };
  124888. static float _vq_quantthresh__44c1_s_p4_0[] = {
  124889. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  124890. };
  124891. static long _vq_quantmap__44c1_s_p4_0[] = {
  124892. 7, 5, 3, 1, 0, 2, 4, 6,
  124893. 8,
  124894. };
  124895. static encode_aux_threshmatch _vq_auxt__44c1_s_p4_0 = {
  124896. _vq_quantthresh__44c1_s_p4_0,
  124897. _vq_quantmap__44c1_s_p4_0,
  124898. 9,
  124899. 9
  124900. };
  124901. static static_codebook _44c1_s_p4_0 = {
  124902. 2, 81,
  124903. _vq_lengthlist__44c1_s_p4_0,
  124904. 1, -531628032, 1611661312, 4, 0,
  124905. _vq_quantlist__44c1_s_p4_0,
  124906. NULL,
  124907. &_vq_auxt__44c1_s_p4_0,
  124908. NULL,
  124909. 0
  124910. };
  124911. static long _vq_quantlist__44c1_s_p5_0[] = {
  124912. 8,
  124913. 7,
  124914. 9,
  124915. 6,
  124916. 10,
  124917. 5,
  124918. 11,
  124919. 4,
  124920. 12,
  124921. 3,
  124922. 13,
  124923. 2,
  124924. 14,
  124925. 1,
  124926. 15,
  124927. 0,
  124928. 16,
  124929. };
  124930. static long _vq_lengthlist__44c1_s_p5_0[] = {
  124931. 1, 4, 3, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,10,10,11,
  124932. 11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,10,10,
  124933. 11,11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,10,
  124934. 10,11,11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,
  124935. 11,11,11,11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,
  124936. 10,11,11,12,11, 0, 0, 0, 8, 8, 9, 9, 9,10,10,10,
  124937. 10,10,11,11,12,12, 0, 0, 0, 8, 8, 9, 9,10, 9,10,
  124938. 10,10,10,11,11,12,12, 0, 0, 0, 9, 9, 9, 9,10,10,
  124939. 10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 9, 9,10,
  124940. 10,10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 9, 9,
  124941. 10,10,10,11,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9,
  124942. 9,10,10,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0,
  124943. 10,10,10,10,11,11,12,12,12,12,13,13, 0, 0, 0, 0,
  124944. 0, 0, 0,10,10,11,11,12,12,12,12,13,13, 0, 0, 0,
  124945. 0, 0, 0, 0,11,11,12,12,12,12,13,13,13,13, 0, 0,
  124946. 0, 0, 0, 0, 0,11,11,11,11,12,12,13,13,13,13, 0,
  124947. 0, 0, 0, 0, 0, 0,12,12,12,12,12,12,13,13,14,14,
  124948. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,12,12,13,13,14,
  124949. 14,
  124950. };
  124951. static float _vq_quantthresh__44c1_s_p5_0[] = {
  124952. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  124953. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  124954. };
  124955. static long _vq_quantmap__44c1_s_p5_0[] = {
  124956. 15, 13, 11, 9, 7, 5, 3, 1,
  124957. 0, 2, 4, 6, 8, 10, 12, 14,
  124958. 16,
  124959. };
  124960. static encode_aux_threshmatch _vq_auxt__44c1_s_p5_0 = {
  124961. _vq_quantthresh__44c1_s_p5_0,
  124962. _vq_quantmap__44c1_s_p5_0,
  124963. 17,
  124964. 17
  124965. };
  124966. static static_codebook _44c1_s_p5_0 = {
  124967. 2, 289,
  124968. _vq_lengthlist__44c1_s_p5_0,
  124969. 1, -529530880, 1611661312, 5, 0,
  124970. _vq_quantlist__44c1_s_p5_0,
  124971. NULL,
  124972. &_vq_auxt__44c1_s_p5_0,
  124973. NULL,
  124974. 0
  124975. };
  124976. static long _vq_quantlist__44c1_s_p6_0[] = {
  124977. 1,
  124978. 0,
  124979. 2,
  124980. };
  124981. static long _vq_lengthlist__44c1_s_p6_0[] = {
  124982. 1, 4, 4, 7, 6, 6, 7, 6, 6, 4, 7, 7,10, 9, 9,11,
  124983. 9, 9, 4, 7, 7,10, 9, 9,11, 9, 9, 6,10,10,11,11,
  124984. 11,11,10,10, 6, 9, 9,11,10,10,11,10,10, 6, 9, 9,
  124985. 11,10,11,11,10,10, 7,11,10,11,11,11,12,11,11, 7,
  124986. 9, 9,11,10,10,11,11,10, 6, 9, 9,10,10,10,12,10,
  124987. 11,
  124988. };
  124989. static float _vq_quantthresh__44c1_s_p6_0[] = {
  124990. -5.5, 5.5,
  124991. };
  124992. static long _vq_quantmap__44c1_s_p6_0[] = {
  124993. 1, 0, 2,
  124994. };
  124995. static encode_aux_threshmatch _vq_auxt__44c1_s_p6_0 = {
  124996. _vq_quantthresh__44c1_s_p6_0,
  124997. _vq_quantmap__44c1_s_p6_0,
  124998. 3,
  124999. 3
  125000. };
  125001. static static_codebook _44c1_s_p6_0 = {
  125002. 4, 81,
  125003. _vq_lengthlist__44c1_s_p6_0,
  125004. 1, -529137664, 1618345984, 2, 0,
  125005. _vq_quantlist__44c1_s_p6_0,
  125006. NULL,
  125007. &_vq_auxt__44c1_s_p6_0,
  125008. NULL,
  125009. 0
  125010. };
  125011. static long _vq_quantlist__44c1_s_p6_1[] = {
  125012. 5,
  125013. 4,
  125014. 6,
  125015. 3,
  125016. 7,
  125017. 2,
  125018. 8,
  125019. 1,
  125020. 9,
  125021. 0,
  125022. 10,
  125023. };
  125024. static long _vq_lengthlist__44c1_s_p6_1[] = {
  125025. 2, 3, 3, 6, 6, 7, 7, 7, 7, 8, 8,10,10,10, 6, 6,
  125026. 7, 7, 8, 8, 8, 8,10,10,10, 6, 6, 7, 7, 8, 8, 8,
  125027. 8,10,10,10, 7, 7, 7, 7, 8, 8, 8, 8,10,10,10, 7,
  125028. 7, 7, 7, 8, 8, 8, 8,10,10,10, 7, 7, 8, 8, 8, 8,
  125029. 8, 8,10,10,10, 7, 7, 8, 8, 8, 8, 8, 8,10,10,10,
  125030. 8, 8, 8, 8, 8, 8, 8, 8,10,10,10,10,10, 8, 8, 8,
  125031. 8, 8, 8,10,10,10,10,10, 9, 9, 8, 8, 8, 8,10,10,
  125032. 10,10,10, 8, 8, 8, 8, 8, 8,
  125033. };
  125034. static float _vq_quantthresh__44c1_s_p6_1[] = {
  125035. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  125036. 3.5, 4.5,
  125037. };
  125038. static long _vq_quantmap__44c1_s_p6_1[] = {
  125039. 9, 7, 5, 3, 1, 0, 2, 4,
  125040. 6, 8, 10,
  125041. };
  125042. static encode_aux_threshmatch _vq_auxt__44c1_s_p6_1 = {
  125043. _vq_quantthresh__44c1_s_p6_1,
  125044. _vq_quantmap__44c1_s_p6_1,
  125045. 11,
  125046. 11
  125047. };
  125048. static static_codebook _44c1_s_p6_1 = {
  125049. 2, 121,
  125050. _vq_lengthlist__44c1_s_p6_1,
  125051. 1, -531365888, 1611661312, 4, 0,
  125052. _vq_quantlist__44c1_s_p6_1,
  125053. NULL,
  125054. &_vq_auxt__44c1_s_p6_1,
  125055. NULL,
  125056. 0
  125057. };
  125058. static long _vq_quantlist__44c1_s_p7_0[] = {
  125059. 6,
  125060. 5,
  125061. 7,
  125062. 4,
  125063. 8,
  125064. 3,
  125065. 9,
  125066. 2,
  125067. 10,
  125068. 1,
  125069. 11,
  125070. 0,
  125071. 12,
  125072. };
  125073. static long _vq_lengthlist__44c1_s_p7_0[] = {
  125074. 1, 4, 4, 6, 6, 7, 7, 7, 7, 8, 8,10, 9, 7, 5, 6,
  125075. 7, 7, 8, 8, 8, 8, 9, 9,10,10, 7, 5, 5, 7, 7, 8,
  125076. 8, 8, 8, 9, 9,10,10, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  125077. 10,10,11,10, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,
  125078. 11, 0,12,12, 9, 9, 9,10,10,10,11,11,11,11, 0,13,
  125079. 13, 9, 9, 9, 9,10,10,11,11,11,11, 0, 0, 0,10,10,
  125080. 10,10,11,11,12,11,12,12, 0, 0, 0,10,10,10, 9,11,
  125081. 11,12,11,13,12, 0, 0, 0,13,13,10,10,11,11,12,12,
  125082. 13,13, 0, 0, 0,14,14,10,10,11,11,12,12,13,13, 0,
  125083. 0, 0, 0, 0,11,12,11,11,12,12,14,13, 0, 0, 0, 0,
  125084. 0,12,11,11,11,13,10,14,13,
  125085. };
  125086. static float _vq_quantthresh__44c1_s_p7_0[] = {
  125087. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  125088. 12.5, 17.5, 22.5, 27.5,
  125089. };
  125090. static long _vq_quantmap__44c1_s_p7_0[] = {
  125091. 11, 9, 7, 5, 3, 1, 0, 2,
  125092. 4, 6, 8, 10, 12,
  125093. };
  125094. static encode_aux_threshmatch _vq_auxt__44c1_s_p7_0 = {
  125095. _vq_quantthresh__44c1_s_p7_0,
  125096. _vq_quantmap__44c1_s_p7_0,
  125097. 13,
  125098. 13
  125099. };
  125100. static static_codebook _44c1_s_p7_0 = {
  125101. 2, 169,
  125102. _vq_lengthlist__44c1_s_p7_0,
  125103. 1, -526516224, 1616117760, 4, 0,
  125104. _vq_quantlist__44c1_s_p7_0,
  125105. NULL,
  125106. &_vq_auxt__44c1_s_p7_0,
  125107. NULL,
  125108. 0
  125109. };
  125110. static long _vq_quantlist__44c1_s_p7_1[] = {
  125111. 2,
  125112. 1,
  125113. 3,
  125114. 0,
  125115. 4,
  125116. };
  125117. static long _vq_lengthlist__44c1_s_p7_1[] = {
  125118. 2, 3, 3, 5, 5, 6, 6, 6, 5, 5, 6, 6, 6, 5, 5, 6,
  125119. 6, 6, 5, 5, 6, 6, 6, 5, 5,
  125120. };
  125121. static float _vq_quantthresh__44c1_s_p7_1[] = {
  125122. -1.5, -0.5, 0.5, 1.5,
  125123. };
  125124. static long _vq_quantmap__44c1_s_p7_1[] = {
  125125. 3, 1, 0, 2, 4,
  125126. };
  125127. static encode_aux_threshmatch _vq_auxt__44c1_s_p7_1 = {
  125128. _vq_quantthresh__44c1_s_p7_1,
  125129. _vq_quantmap__44c1_s_p7_1,
  125130. 5,
  125131. 5
  125132. };
  125133. static static_codebook _44c1_s_p7_1 = {
  125134. 2, 25,
  125135. _vq_lengthlist__44c1_s_p7_1,
  125136. 1, -533725184, 1611661312, 3, 0,
  125137. _vq_quantlist__44c1_s_p7_1,
  125138. NULL,
  125139. &_vq_auxt__44c1_s_p7_1,
  125140. NULL,
  125141. 0
  125142. };
  125143. static long _vq_quantlist__44c1_s_p8_0[] = {
  125144. 6,
  125145. 5,
  125146. 7,
  125147. 4,
  125148. 8,
  125149. 3,
  125150. 9,
  125151. 2,
  125152. 10,
  125153. 1,
  125154. 11,
  125155. 0,
  125156. 12,
  125157. };
  125158. static long _vq_lengthlist__44c1_s_p8_0[] = {
  125159. 1, 4, 3,10,10,10,10,10,10,10,10,10,10, 4, 8, 6,
  125160. 10,10,10,10,10,10,10,10,10,10, 4, 8, 7,10,10,10,
  125161. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  125162. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  125163. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  125164. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  125165. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  125166. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  125167. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  125168. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  125169. 10,10,10,10,10,10,10,10,10,
  125170. };
  125171. static float _vq_quantthresh__44c1_s_p8_0[] = {
  125172. -1215.5, -994.5, -773.5, -552.5, -331.5, -110.5, 110.5, 331.5,
  125173. 552.5, 773.5, 994.5, 1215.5,
  125174. };
  125175. static long _vq_quantmap__44c1_s_p8_0[] = {
  125176. 11, 9, 7, 5, 3, 1, 0, 2,
  125177. 4, 6, 8, 10, 12,
  125178. };
  125179. static encode_aux_threshmatch _vq_auxt__44c1_s_p8_0 = {
  125180. _vq_quantthresh__44c1_s_p8_0,
  125181. _vq_quantmap__44c1_s_p8_0,
  125182. 13,
  125183. 13
  125184. };
  125185. static static_codebook _44c1_s_p8_0 = {
  125186. 2, 169,
  125187. _vq_lengthlist__44c1_s_p8_0,
  125188. 1, -514541568, 1627103232, 4, 0,
  125189. _vq_quantlist__44c1_s_p8_0,
  125190. NULL,
  125191. &_vq_auxt__44c1_s_p8_0,
  125192. NULL,
  125193. 0
  125194. };
  125195. static long _vq_quantlist__44c1_s_p8_1[] = {
  125196. 6,
  125197. 5,
  125198. 7,
  125199. 4,
  125200. 8,
  125201. 3,
  125202. 9,
  125203. 2,
  125204. 10,
  125205. 1,
  125206. 11,
  125207. 0,
  125208. 12,
  125209. };
  125210. static long _vq_lengthlist__44c1_s_p8_1[] = {
  125211. 1, 4, 4, 6, 5, 7, 7, 9, 9,10,10,12,12, 6, 5, 5,
  125212. 7, 7, 8, 8,10,10,12,11,12,12, 6, 5, 5, 7, 7, 8,
  125213. 8,10,10,11,11,12,12,15, 7, 7, 8, 8, 9, 9,11,11,
  125214. 12,12,13,12,15, 8, 8, 8, 7, 9, 9,10,10,12,12,13,
  125215. 13,16,11,10, 8, 8,10,10,11,11,12,12,13,13,16,11,
  125216. 11, 9, 8,11,10,11,11,12,12,13,12,16,16,16,10,11,
  125217. 10,11,12,12,12,12,13,13,16,16,16,11, 9,11, 9,14,
  125218. 12,12,12,13,13,16,16,16,12,14,11,12,12,12,13,13,
  125219. 14,13,16,16,16,15,13,12,10,13,10,13,14,13,13,16,
  125220. 16,16,16,16,13,14,12,13,13,12,13,13,16,16,16,16,
  125221. 16,13,12,12,11,14,12,15,13,
  125222. };
  125223. static float _vq_quantthresh__44c1_s_p8_1[] = {
  125224. -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5, 25.5,
  125225. 42.5, 59.5, 76.5, 93.5,
  125226. };
  125227. static long _vq_quantmap__44c1_s_p8_1[] = {
  125228. 11, 9, 7, 5, 3, 1, 0, 2,
  125229. 4, 6, 8, 10, 12,
  125230. };
  125231. static encode_aux_threshmatch _vq_auxt__44c1_s_p8_1 = {
  125232. _vq_quantthresh__44c1_s_p8_1,
  125233. _vq_quantmap__44c1_s_p8_1,
  125234. 13,
  125235. 13
  125236. };
  125237. static static_codebook _44c1_s_p8_1 = {
  125238. 2, 169,
  125239. _vq_lengthlist__44c1_s_p8_1,
  125240. 1, -522616832, 1620115456, 4, 0,
  125241. _vq_quantlist__44c1_s_p8_1,
  125242. NULL,
  125243. &_vq_auxt__44c1_s_p8_1,
  125244. NULL,
  125245. 0
  125246. };
  125247. static long _vq_quantlist__44c1_s_p8_2[] = {
  125248. 8,
  125249. 7,
  125250. 9,
  125251. 6,
  125252. 10,
  125253. 5,
  125254. 11,
  125255. 4,
  125256. 12,
  125257. 3,
  125258. 13,
  125259. 2,
  125260. 14,
  125261. 1,
  125262. 15,
  125263. 0,
  125264. 16,
  125265. };
  125266. static long _vq_lengthlist__44c1_s_p8_2[] = {
  125267. 2, 4, 4, 6, 6, 6, 6, 7, 7, 8, 8, 8, 8, 8, 8, 8,
  125268. 8,10,10,10, 7, 7, 7, 7, 8, 8, 9, 9, 9, 9, 9, 9,
  125269. 9, 9,10,10,10, 7, 7, 8, 7, 8, 8, 9, 9, 9, 9, 9,
  125270. 9, 9, 9,10,10,10, 7, 7, 8, 8, 8, 9, 9, 9, 9, 9,
  125271. 9,10, 9, 9,10,10,10, 7, 7, 8, 8, 9, 8, 9, 9, 9,
  125272. 9,10, 9, 9,10,10,11,11, 8, 8, 8, 8, 9, 9, 9, 9,
  125273. 9, 9,10, 9, 9,10,10,10,10, 8, 8, 8, 8, 9, 9, 9,
  125274. 9, 9, 9, 9, 9,10,10,11,11,11, 8, 8, 9, 9, 9, 9,
  125275. 9, 9, 9, 9, 9, 9,10,10,10,10,11,11,11, 8, 8, 9,
  125276. 9, 9, 9,10, 9, 9, 9, 9, 9,11,11,11,11,11, 9, 9,
  125277. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,11,10,10,11,11, 9,
  125278. 9, 9, 9, 9, 9, 9, 9, 9,10,10,10,10,11,10,11,11,
  125279. 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10, 9,10,10,11,11,
  125280. 11,11,11, 9, 9, 9,10, 9, 9, 9, 9, 9, 9,10,11,11,
  125281. 11,11,11,11,10,10,10,10, 9, 9, 9, 9, 9, 9,10,11,
  125282. 11,11,11,11,11, 9,10, 9, 9, 9, 9,10, 9, 9, 9,11,
  125283. 11,11,11,11,11,11,10,10, 9, 9, 9, 9, 9, 9,10, 9,
  125284. 11,11,10,11,11,11,11,10,11, 9, 9, 9, 9, 9, 9, 9,
  125285. 9,
  125286. };
  125287. static float _vq_quantthresh__44c1_s_p8_2[] = {
  125288. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  125289. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  125290. };
  125291. static long _vq_quantmap__44c1_s_p8_2[] = {
  125292. 15, 13, 11, 9, 7, 5, 3, 1,
  125293. 0, 2, 4, 6, 8, 10, 12, 14,
  125294. 16,
  125295. };
  125296. static encode_aux_threshmatch _vq_auxt__44c1_s_p8_2 = {
  125297. _vq_quantthresh__44c1_s_p8_2,
  125298. _vq_quantmap__44c1_s_p8_2,
  125299. 17,
  125300. 17
  125301. };
  125302. static static_codebook _44c1_s_p8_2 = {
  125303. 2, 289,
  125304. _vq_lengthlist__44c1_s_p8_2,
  125305. 1, -529530880, 1611661312, 5, 0,
  125306. _vq_quantlist__44c1_s_p8_2,
  125307. NULL,
  125308. &_vq_auxt__44c1_s_p8_2,
  125309. NULL,
  125310. 0
  125311. };
  125312. static long _huff_lengthlist__44c1_s_short[] = {
  125313. 6, 8,13,12,13,14,15,16,16, 4, 2, 4, 7, 6, 8,11,
  125314. 13,15,10, 4, 4, 8, 6, 8,11,14,17,11, 5, 6, 5, 6,
  125315. 8,12,14,17,11, 5, 5, 6, 5, 7,10,13,16,12, 6, 7,
  125316. 8, 7, 8,10,13,15,13, 8, 8, 7, 7, 8,10,12,15,15,
  125317. 7, 7, 5, 5, 7, 9,12,14,15, 8, 8, 6, 6, 7, 8,10,
  125318. 11,
  125319. };
  125320. static static_codebook _huff_book__44c1_s_short = {
  125321. 2, 81,
  125322. _huff_lengthlist__44c1_s_short,
  125323. 0, 0, 0, 0, 0,
  125324. NULL,
  125325. NULL,
  125326. NULL,
  125327. NULL,
  125328. 0
  125329. };
  125330. static long _huff_lengthlist__44c1_sm_long[] = {
  125331. 5, 4, 8,10, 9, 9,10,11,12, 4, 2, 5, 6, 6, 8,10,
  125332. 11,13, 8, 4, 6, 8, 7, 9,12,12,14,10, 6, 8, 4, 5,
  125333. 6, 9,11,12, 9, 5, 6, 5, 5, 6, 9,11,11, 9, 7, 9,
  125334. 6, 5, 5, 7,10,10,10, 9,11, 8, 7, 6, 7, 9,11,11,
  125335. 12,13,10,10, 9, 8, 9,11,11,15,15,12,13,11, 9,10,
  125336. 11,
  125337. };
  125338. static static_codebook _huff_book__44c1_sm_long = {
  125339. 2, 81,
  125340. _huff_lengthlist__44c1_sm_long,
  125341. 0, 0, 0, 0, 0,
  125342. NULL,
  125343. NULL,
  125344. NULL,
  125345. NULL,
  125346. 0
  125347. };
  125348. static long _vq_quantlist__44c1_sm_p1_0[] = {
  125349. 1,
  125350. 0,
  125351. 2,
  125352. };
  125353. static long _vq_lengthlist__44c1_sm_p1_0[] = {
  125354. 1, 5, 5, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0, 0, 0, 0,
  125355. 0, 0, 5, 7, 7, 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, 5, 8, 7, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0, 0,
  125360. 0, 0, 0, 7, 8, 9, 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, 5, 7, 7, 0, 0, 0, 0, 0, 0, 7, 9, 8, 0, 0,
  125365. 0, 0, 0, 0, 7, 9, 9, 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, 5, 8, 7, 0, 0, 0, 0,
  125400. 0, 0, 8, 9, 9, 0, 0, 0, 0, 0, 0, 8, 9, 9, 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, 7, 9, 9, 0, 0, 0,
  125405. 0, 0, 0, 9, 9,10, 0, 0, 0, 0, 0, 0, 9,10,10, 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, 7, 9, 9, 0, 0,
  125410. 0, 0, 0, 0, 8,10, 9, 0, 0, 0, 0, 0, 0, 9,10,10,
  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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125421. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125422. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125423. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125424. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125425. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125426. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125427. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125428. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125429. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125430. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125431. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125432. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125433. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125434. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125435. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125436. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125437. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125438. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125439. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125440. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125441. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125442. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125443. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125444. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125445. 0, 0, 5, 7, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0, 0,
  125446. 0, 0, 0, 0, 8, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125447. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125448. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125449. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125450. 0, 0, 0, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,10,10, 0,
  125451. 0, 0, 0, 0, 0, 8, 9,10, 0, 0, 0, 0, 0, 0, 0, 0,
  125452. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125453. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125454. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125455. 0, 0, 0, 0, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,10,10,
  125456. 0, 0, 0, 0, 0, 0, 9,10, 9, 0, 0, 0, 0, 0, 0, 0,
  125457. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125458. 0, 0, 0, 0, 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125492. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125493. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125494. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125495. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125496. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125497. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125498. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125499. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125500. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125501. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125502. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125503. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125504. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125505. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125506. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125507. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125508. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125509. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125510. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125511. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125512. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125513. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125514. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125515. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125516. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125517. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125518. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125519. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125520. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125521. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125522. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125523. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125524. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125525. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125526. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125527. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125528. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125529. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125530. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125531. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125532. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125533. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125534. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125535. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125536. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125537. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125538. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125539. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125540. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125541. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125542. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125543. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125544. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125545. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125546. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125547. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125548. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125549. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125550. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125551. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125552. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125553. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125554. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125555. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125556. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125557. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125558. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125559. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125560. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125561. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125562. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125563. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125564. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125565. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125566. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125567. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125568. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125569. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125570. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125571. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125572. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125573. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125574. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125575. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125576. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125577. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125578. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125579. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125580. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125581. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125582. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125583. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125584. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125585. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125586. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125587. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125588. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125589. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125590. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125591. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125592. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125593. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125594. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125595. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125596. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125597. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125598. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125599. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125600. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125601. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125602. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125603. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125604. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125605. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125606. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125607. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125608. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125609. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125610. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125611. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125612. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125613. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125614. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125615. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125616. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125617. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125618. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125619. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125620. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125621. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125622. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125623. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125624. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125625. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125626. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125627. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125628. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125629. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125630. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125631. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125632. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125633. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125634. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125635. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125636. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125637. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125638. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125639. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125640. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125641. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125642. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125643. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125644. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125645. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125646. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125647. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125648. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125649. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125650. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125651. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125652. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125653. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125654. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125655. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125656. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125657. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125658. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125659. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125660. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125661. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125662. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125663. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125664. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125665. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125666. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125667. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125668. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125669. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125670. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125671. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125672. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125673. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125674. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125675. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125676. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125677. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125678. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125679. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125680. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125681. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125682. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125683. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125684. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125685. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125686. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125687. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125688. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125689. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125690. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125691. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125692. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125693. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125694. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125695. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125696. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125697. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125698. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125699. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125700. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125701. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125702. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125703. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125704. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125705. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125706. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125707. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125708. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125709. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125710. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125711. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125712. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125713. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125714. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125715. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125716. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125717. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125718. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125719. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125720. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125721. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125722. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125723. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125724. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125725. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125726. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125727. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125728. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125729. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125730. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125731. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125732. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125733. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125734. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125735. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125736. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125737. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125738. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125739. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125740. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125741. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125742. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125743. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125744. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125745. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125746. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125747. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125748. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125749. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125750. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125751. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125752. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125753. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125754. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125755. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125756. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125757. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125758. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125759. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125760. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125761. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125762. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125763. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125764. 0,
  125765. };
  125766. static float _vq_quantthresh__44c1_sm_p1_0[] = {
  125767. -0.5, 0.5,
  125768. };
  125769. static long _vq_quantmap__44c1_sm_p1_0[] = {
  125770. 1, 0, 2,
  125771. };
  125772. static encode_aux_threshmatch _vq_auxt__44c1_sm_p1_0 = {
  125773. _vq_quantthresh__44c1_sm_p1_0,
  125774. _vq_quantmap__44c1_sm_p1_0,
  125775. 3,
  125776. 3
  125777. };
  125778. static static_codebook _44c1_sm_p1_0 = {
  125779. 8, 6561,
  125780. _vq_lengthlist__44c1_sm_p1_0,
  125781. 1, -535822336, 1611661312, 2, 0,
  125782. _vq_quantlist__44c1_sm_p1_0,
  125783. NULL,
  125784. &_vq_auxt__44c1_sm_p1_0,
  125785. NULL,
  125786. 0
  125787. };
  125788. static long _vq_quantlist__44c1_sm_p2_0[] = {
  125789. 2,
  125790. 1,
  125791. 3,
  125792. 0,
  125793. 4,
  125794. };
  125795. static long _vq_lengthlist__44c1_sm_p2_0[] = {
  125796. 2, 3, 4, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125797. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 4, 4, 6, 6, 0, 0,
  125798. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125799. 0, 0, 4, 4, 4, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125800. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 6, 6, 9, 9,
  125801. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125802. 0, 0, 0, 0, 6, 6, 7, 9, 9, 0, 0, 0, 0, 0, 0, 0,
  125803. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125804. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125805. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125806. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125807. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125808. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125809. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125810. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125811. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125812. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125813. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125814. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125815. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125816. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125817. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125818. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125819. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125820. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125821. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125822. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125823. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125824. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125825. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125826. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125827. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125828. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125829. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125830. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125831. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125832. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125833. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125834. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125835. 0,
  125836. };
  125837. static float _vq_quantthresh__44c1_sm_p2_0[] = {
  125838. -1.5, -0.5, 0.5, 1.5,
  125839. };
  125840. static long _vq_quantmap__44c1_sm_p2_0[] = {
  125841. 3, 1, 0, 2, 4,
  125842. };
  125843. static encode_aux_threshmatch _vq_auxt__44c1_sm_p2_0 = {
  125844. _vq_quantthresh__44c1_sm_p2_0,
  125845. _vq_quantmap__44c1_sm_p2_0,
  125846. 5,
  125847. 5
  125848. };
  125849. static static_codebook _44c1_sm_p2_0 = {
  125850. 4, 625,
  125851. _vq_lengthlist__44c1_sm_p2_0,
  125852. 1, -533725184, 1611661312, 3, 0,
  125853. _vq_quantlist__44c1_sm_p2_0,
  125854. NULL,
  125855. &_vq_auxt__44c1_sm_p2_0,
  125856. NULL,
  125857. 0
  125858. };
  125859. static long _vq_quantlist__44c1_sm_p3_0[] = {
  125860. 4,
  125861. 3,
  125862. 5,
  125863. 2,
  125864. 6,
  125865. 1,
  125866. 7,
  125867. 0,
  125868. 8,
  125869. };
  125870. static long _vq_lengthlist__44c1_sm_p3_0[] = {
  125871. 1, 3, 3, 7, 7, 0, 0, 0, 0, 0, 5, 5, 6, 6, 0, 0,
  125872. 0, 0, 0, 5, 5, 7, 7, 0, 0, 0, 0, 0, 7, 7, 7, 7,
  125873. 0, 0, 0, 0, 0, 0, 0, 7, 7, 0, 0, 0, 0, 0, 0, 0,
  125874. 8, 9, 0, 0, 0, 0, 0, 0, 0, 8, 8, 0, 0, 0, 0, 0,
  125875. 0, 0,10,10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125876. 0,
  125877. };
  125878. static float _vq_quantthresh__44c1_sm_p3_0[] = {
  125879. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  125880. };
  125881. static long _vq_quantmap__44c1_sm_p3_0[] = {
  125882. 7, 5, 3, 1, 0, 2, 4, 6,
  125883. 8,
  125884. };
  125885. static encode_aux_threshmatch _vq_auxt__44c1_sm_p3_0 = {
  125886. _vq_quantthresh__44c1_sm_p3_0,
  125887. _vq_quantmap__44c1_sm_p3_0,
  125888. 9,
  125889. 9
  125890. };
  125891. static static_codebook _44c1_sm_p3_0 = {
  125892. 2, 81,
  125893. _vq_lengthlist__44c1_sm_p3_0,
  125894. 1, -531628032, 1611661312, 4, 0,
  125895. _vq_quantlist__44c1_sm_p3_0,
  125896. NULL,
  125897. &_vq_auxt__44c1_sm_p3_0,
  125898. NULL,
  125899. 0
  125900. };
  125901. static long _vq_quantlist__44c1_sm_p4_0[] = {
  125902. 4,
  125903. 3,
  125904. 5,
  125905. 2,
  125906. 6,
  125907. 1,
  125908. 7,
  125909. 0,
  125910. 8,
  125911. };
  125912. static long _vq_lengthlist__44c1_sm_p4_0[] = {
  125913. 1, 3, 3, 6, 6, 7, 7, 9, 9, 0, 6, 6, 7, 7, 8, 8,
  125914. 9, 9, 0, 6, 6, 7, 7, 8, 8, 9, 9, 0, 7, 7, 8, 8,
  125915. 8, 8,10,10, 0, 0, 0, 8, 8, 8, 8,10,10, 0, 0, 0,
  125916. 8, 8, 9, 9,11,11, 0, 0, 0, 9, 9, 9, 9,11,11, 0,
  125917. 0, 0,10,10,10,10,11,11, 0, 0, 0, 0, 0, 9, 9,11,
  125918. 11,
  125919. };
  125920. static float _vq_quantthresh__44c1_sm_p4_0[] = {
  125921. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  125922. };
  125923. static long _vq_quantmap__44c1_sm_p4_0[] = {
  125924. 7, 5, 3, 1, 0, 2, 4, 6,
  125925. 8,
  125926. };
  125927. static encode_aux_threshmatch _vq_auxt__44c1_sm_p4_0 = {
  125928. _vq_quantthresh__44c1_sm_p4_0,
  125929. _vq_quantmap__44c1_sm_p4_0,
  125930. 9,
  125931. 9
  125932. };
  125933. static static_codebook _44c1_sm_p4_0 = {
  125934. 2, 81,
  125935. _vq_lengthlist__44c1_sm_p4_0,
  125936. 1, -531628032, 1611661312, 4, 0,
  125937. _vq_quantlist__44c1_sm_p4_0,
  125938. NULL,
  125939. &_vq_auxt__44c1_sm_p4_0,
  125940. NULL,
  125941. 0
  125942. };
  125943. static long _vq_quantlist__44c1_sm_p5_0[] = {
  125944. 8,
  125945. 7,
  125946. 9,
  125947. 6,
  125948. 10,
  125949. 5,
  125950. 11,
  125951. 4,
  125952. 12,
  125953. 3,
  125954. 13,
  125955. 2,
  125956. 14,
  125957. 1,
  125958. 15,
  125959. 0,
  125960. 16,
  125961. };
  125962. static long _vq_lengthlist__44c1_sm_p5_0[] = {
  125963. 2, 3, 3, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,10,10,11,
  125964. 11, 0, 5, 5, 6, 6, 8, 8, 9, 9, 9, 9,10,10,10,10,
  125965. 11,11, 0, 5, 5, 6, 6, 8, 8, 9, 9, 9, 9,10,10,10,
  125966. 10,11,11, 0, 7, 7, 7, 7, 8, 8, 9, 9, 9, 9,10,10,
  125967. 11,11,12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,
  125968. 10,11,11,12,12, 0, 0, 0, 8, 8, 8, 8, 9, 9,10,10,
  125969. 10,11,11,11,12,12, 0, 0, 0, 8, 8, 8, 8, 9, 9,10,
  125970. 10,10,10,11,11,12,12, 0, 0, 0, 9, 9, 9, 9,10,10,
  125971. 10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 9, 9,10,
  125972. 10,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9, 9,
  125973. 9, 9,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9,
  125974. 9, 9, 9,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0,
  125975. 9, 9,10,10,11,11,12,12,12,12,13,13, 0, 0, 0, 0,
  125976. 0, 0, 0,10,10,11,11,12,12,12,12,13,13, 0, 0, 0,
  125977. 0, 0, 0, 0,11,11,11,11,12,12,13,13,13,13, 0, 0,
  125978. 0, 0, 0, 0, 0,11,11,11,11,12,12,13,13,13,13, 0,
  125979. 0, 0, 0, 0, 0, 0,11,11,12,12,12,12,13,13,14,14,
  125980. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,12,12,13,13,14,
  125981. 14,
  125982. };
  125983. static float _vq_quantthresh__44c1_sm_p5_0[] = {
  125984. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  125985. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  125986. };
  125987. static long _vq_quantmap__44c1_sm_p5_0[] = {
  125988. 15, 13, 11, 9, 7, 5, 3, 1,
  125989. 0, 2, 4, 6, 8, 10, 12, 14,
  125990. 16,
  125991. };
  125992. static encode_aux_threshmatch _vq_auxt__44c1_sm_p5_0 = {
  125993. _vq_quantthresh__44c1_sm_p5_0,
  125994. _vq_quantmap__44c1_sm_p5_0,
  125995. 17,
  125996. 17
  125997. };
  125998. static static_codebook _44c1_sm_p5_0 = {
  125999. 2, 289,
  126000. _vq_lengthlist__44c1_sm_p5_0,
  126001. 1, -529530880, 1611661312, 5, 0,
  126002. _vq_quantlist__44c1_sm_p5_0,
  126003. NULL,
  126004. &_vq_auxt__44c1_sm_p5_0,
  126005. NULL,
  126006. 0
  126007. };
  126008. static long _vq_quantlist__44c1_sm_p6_0[] = {
  126009. 1,
  126010. 0,
  126011. 2,
  126012. };
  126013. static long _vq_lengthlist__44c1_sm_p6_0[] = {
  126014. 1, 4, 4, 7, 6, 6, 7, 6, 6, 4, 7, 7,10, 9, 9,11,
  126015. 9, 9, 4, 7, 7,10, 9, 9,11, 9, 9, 7,10,10,10,11,
  126016. 11,11,10,10, 6, 9, 9,11,11,10,11,10,10, 6, 9, 9,
  126017. 11,10,11,11,10,10, 7,11,11,11,11,11,11,11,11, 6,
  126018. 9, 9,11,10,10,11,11,10, 6, 9, 9,10,10,10,11,10,
  126019. 11,
  126020. };
  126021. static float _vq_quantthresh__44c1_sm_p6_0[] = {
  126022. -5.5, 5.5,
  126023. };
  126024. static long _vq_quantmap__44c1_sm_p6_0[] = {
  126025. 1, 0, 2,
  126026. };
  126027. static encode_aux_threshmatch _vq_auxt__44c1_sm_p6_0 = {
  126028. _vq_quantthresh__44c1_sm_p6_0,
  126029. _vq_quantmap__44c1_sm_p6_0,
  126030. 3,
  126031. 3
  126032. };
  126033. static static_codebook _44c1_sm_p6_0 = {
  126034. 4, 81,
  126035. _vq_lengthlist__44c1_sm_p6_0,
  126036. 1, -529137664, 1618345984, 2, 0,
  126037. _vq_quantlist__44c1_sm_p6_0,
  126038. NULL,
  126039. &_vq_auxt__44c1_sm_p6_0,
  126040. NULL,
  126041. 0
  126042. };
  126043. static long _vq_quantlist__44c1_sm_p6_1[] = {
  126044. 5,
  126045. 4,
  126046. 6,
  126047. 3,
  126048. 7,
  126049. 2,
  126050. 8,
  126051. 1,
  126052. 9,
  126053. 0,
  126054. 10,
  126055. };
  126056. static long _vq_lengthlist__44c1_sm_p6_1[] = {
  126057. 2, 4, 4, 6, 6, 7, 7, 7, 7, 8, 8,10, 5, 5, 6, 6,
  126058. 7, 7, 8, 8, 8, 8,10, 5, 5, 6, 6, 7, 7, 8, 8, 8,
  126059. 8,10, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8,10,10,10, 7,
  126060. 7, 7, 7, 8, 8, 8, 8,10,10,10, 7, 7, 8, 8, 8, 8,
  126061. 8, 8,10,10,10, 7, 7, 8, 8, 8, 8, 8, 8,10,10,10,
  126062. 8, 8, 8, 8, 8, 8, 9, 8,10,10,10,10,10, 8, 8, 8,
  126063. 8, 8, 8,10,10,10,10,10, 9, 9, 8, 8, 8, 8,10,10,
  126064. 10,10,10, 8, 8, 8, 8, 8, 8,
  126065. };
  126066. static float _vq_quantthresh__44c1_sm_p6_1[] = {
  126067. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  126068. 3.5, 4.5,
  126069. };
  126070. static long _vq_quantmap__44c1_sm_p6_1[] = {
  126071. 9, 7, 5, 3, 1, 0, 2, 4,
  126072. 6, 8, 10,
  126073. };
  126074. static encode_aux_threshmatch _vq_auxt__44c1_sm_p6_1 = {
  126075. _vq_quantthresh__44c1_sm_p6_1,
  126076. _vq_quantmap__44c1_sm_p6_1,
  126077. 11,
  126078. 11
  126079. };
  126080. static static_codebook _44c1_sm_p6_1 = {
  126081. 2, 121,
  126082. _vq_lengthlist__44c1_sm_p6_1,
  126083. 1, -531365888, 1611661312, 4, 0,
  126084. _vq_quantlist__44c1_sm_p6_1,
  126085. NULL,
  126086. &_vq_auxt__44c1_sm_p6_1,
  126087. NULL,
  126088. 0
  126089. };
  126090. static long _vq_quantlist__44c1_sm_p7_0[] = {
  126091. 6,
  126092. 5,
  126093. 7,
  126094. 4,
  126095. 8,
  126096. 3,
  126097. 9,
  126098. 2,
  126099. 10,
  126100. 1,
  126101. 11,
  126102. 0,
  126103. 12,
  126104. };
  126105. static long _vq_lengthlist__44c1_sm_p7_0[] = {
  126106. 1, 4, 4, 6, 6, 7, 7, 7, 7, 8, 8, 9, 9, 7, 5, 5,
  126107. 7, 7, 8, 8, 8, 8, 9, 9,10,10, 7, 5, 6, 7, 7, 8,
  126108. 8, 8, 8, 9, 9,11,10, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  126109. 10,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,
  126110. 11, 0,12,12, 9, 9,10,10,10,10,11,11,11,11, 0,13,
  126111. 13, 9, 9, 9, 9,10,10,11,11,12,12, 0, 0, 0, 9,10,
  126112. 9,10,11,11,12,11,13,12, 0, 0, 0,10,10, 9, 9,11,
  126113. 11,12,12,13,12, 0, 0, 0,13,13,10,10,11,11,12,12,
  126114. 13,13, 0, 0, 0,14,14,10,10,11,11,12,12,13,13, 0,
  126115. 0, 0, 0, 0,11,12,11,11,12,13,14,13, 0, 0, 0, 0,
  126116. 0,12,12,11,11,13,12,14,13,
  126117. };
  126118. static float _vq_quantthresh__44c1_sm_p7_0[] = {
  126119. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  126120. 12.5, 17.5, 22.5, 27.5,
  126121. };
  126122. static long _vq_quantmap__44c1_sm_p7_0[] = {
  126123. 11, 9, 7, 5, 3, 1, 0, 2,
  126124. 4, 6, 8, 10, 12,
  126125. };
  126126. static encode_aux_threshmatch _vq_auxt__44c1_sm_p7_0 = {
  126127. _vq_quantthresh__44c1_sm_p7_0,
  126128. _vq_quantmap__44c1_sm_p7_0,
  126129. 13,
  126130. 13
  126131. };
  126132. static static_codebook _44c1_sm_p7_0 = {
  126133. 2, 169,
  126134. _vq_lengthlist__44c1_sm_p7_0,
  126135. 1, -526516224, 1616117760, 4, 0,
  126136. _vq_quantlist__44c1_sm_p7_0,
  126137. NULL,
  126138. &_vq_auxt__44c1_sm_p7_0,
  126139. NULL,
  126140. 0
  126141. };
  126142. static long _vq_quantlist__44c1_sm_p7_1[] = {
  126143. 2,
  126144. 1,
  126145. 3,
  126146. 0,
  126147. 4,
  126148. };
  126149. static long _vq_lengthlist__44c1_sm_p7_1[] = {
  126150. 2, 4, 4, 4, 5, 6, 5, 5, 5, 5, 6, 5, 5, 5, 5, 6,
  126151. 5, 5, 5, 5, 6, 6, 6, 5, 5,
  126152. };
  126153. static float _vq_quantthresh__44c1_sm_p7_1[] = {
  126154. -1.5, -0.5, 0.5, 1.5,
  126155. };
  126156. static long _vq_quantmap__44c1_sm_p7_1[] = {
  126157. 3, 1, 0, 2, 4,
  126158. };
  126159. static encode_aux_threshmatch _vq_auxt__44c1_sm_p7_1 = {
  126160. _vq_quantthresh__44c1_sm_p7_1,
  126161. _vq_quantmap__44c1_sm_p7_1,
  126162. 5,
  126163. 5
  126164. };
  126165. static static_codebook _44c1_sm_p7_1 = {
  126166. 2, 25,
  126167. _vq_lengthlist__44c1_sm_p7_1,
  126168. 1, -533725184, 1611661312, 3, 0,
  126169. _vq_quantlist__44c1_sm_p7_1,
  126170. NULL,
  126171. &_vq_auxt__44c1_sm_p7_1,
  126172. NULL,
  126173. 0
  126174. };
  126175. static long _vq_quantlist__44c1_sm_p8_0[] = {
  126176. 6,
  126177. 5,
  126178. 7,
  126179. 4,
  126180. 8,
  126181. 3,
  126182. 9,
  126183. 2,
  126184. 10,
  126185. 1,
  126186. 11,
  126187. 0,
  126188. 12,
  126189. };
  126190. static long _vq_lengthlist__44c1_sm_p8_0[] = {
  126191. 1, 3, 3,13,13,13,13,13,13,13,13,13,13, 3, 6, 6,
  126192. 13,13,13,13,13,13,13,13,13,13, 4, 8, 7,13,13,13,
  126193. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  126194. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  126195. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  126196. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  126197. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  126198. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  126199. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  126200. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  126201. 13,13,13,13,13,13,13,13,13,
  126202. };
  126203. static float _vq_quantthresh__44c1_sm_p8_0[] = {
  126204. -1215.5, -994.5, -773.5, -552.5, -331.5, -110.5, 110.5, 331.5,
  126205. 552.5, 773.5, 994.5, 1215.5,
  126206. };
  126207. static long _vq_quantmap__44c1_sm_p8_0[] = {
  126208. 11, 9, 7, 5, 3, 1, 0, 2,
  126209. 4, 6, 8, 10, 12,
  126210. };
  126211. static encode_aux_threshmatch _vq_auxt__44c1_sm_p8_0 = {
  126212. _vq_quantthresh__44c1_sm_p8_0,
  126213. _vq_quantmap__44c1_sm_p8_0,
  126214. 13,
  126215. 13
  126216. };
  126217. static static_codebook _44c1_sm_p8_0 = {
  126218. 2, 169,
  126219. _vq_lengthlist__44c1_sm_p8_0,
  126220. 1, -514541568, 1627103232, 4, 0,
  126221. _vq_quantlist__44c1_sm_p8_0,
  126222. NULL,
  126223. &_vq_auxt__44c1_sm_p8_0,
  126224. NULL,
  126225. 0
  126226. };
  126227. static long _vq_quantlist__44c1_sm_p8_1[] = {
  126228. 6,
  126229. 5,
  126230. 7,
  126231. 4,
  126232. 8,
  126233. 3,
  126234. 9,
  126235. 2,
  126236. 10,
  126237. 1,
  126238. 11,
  126239. 0,
  126240. 12,
  126241. };
  126242. static long _vq_lengthlist__44c1_sm_p8_1[] = {
  126243. 1, 4, 4, 6, 6, 7, 7, 9, 9,10,11,12,12, 6, 5, 5,
  126244. 7, 7, 8, 7,10,10,11,11,12,12, 6, 5, 5, 7, 7, 8,
  126245. 8,10,10,11,11,12,12,16, 7, 7, 8, 8, 9, 9,11,11,
  126246. 12,12,13,13,17, 7, 7, 8, 7, 9, 9,11,10,12,12,13,
  126247. 13,19,11,10, 8, 8,10,10,11,11,12,12,13,13,19,11,
  126248. 11, 9, 7,11,10,11,11,12,12,13,12,19,19,19,10,10,
  126249. 10,10,11,12,12,12,13,14,18,19,19,11, 9,11, 9,13,
  126250. 12,12,12,13,13,19,20,19,13,15,11,11,12,12,13,13,
  126251. 14,13,18,19,20,15,13,12,10,13,10,13,13,13,14,20,
  126252. 20,20,20,20,13,14,12,12,13,12,13,13,20,20,20,20,
  126253. 20,13,12,12,12,14,12,14,13,
  126254. };
  126255. static float _vq_quantthresh__44c1_sm_p8_1[] = {
  126256. -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5, 25.5,
  126257. 42.5, 59.5, 76.5, 93.5,
  126258. };
  126259. static long _vq_quantmap__44c1_sm_p8_1[] = {
  126260. 11, 9, 7, 5, 3, 1, 0, 2,
  126261. 4, 6, 8, 10, 12,
  126262. };
  126263. static encode_aux_threshmatch _vq_auxt__44c1_sm_p8_1 = {
  126264. _vq_quantthresh__44c1_sm_p8_1,
  126265. _vq_quantmap__44c1_sm_p8_1,
  126266. 13,
  126267. 13
  126268. };
  126269. static static_codebook _44c1_sm_p8_1 = {
  126270. 2, 169,
  126271. _vq_lengthlist__44c1_sm_p8_1,
  126272. 1, -522616832, 1620115456, 4, 0,
  126273. _vq_quantlist__44c1_sm_p8_1,
  126274. NULL,
  126275. &_vq_auxt__44c1_sm_p8_1,
  126276. NULL,
  126277. 0
  126278. };
  126279. static long _vq_quantlist__44c1_sm_p8_2[] = {
  126280. 8,
  126281. 7,
  126282. 9,
  126283. 6,
  126284. 10,
  126285. 5,
  126286. 11,
  126287. 4,
  126288. 12,
  126289. 3,
  126290. 13,
  126291. 2,
  126292. 14,
  126293. 1,
  126294. 15,
  126295. 0,
  126296. 16,
  126297. };
  126298. static long _vq_lengthlist__44c1_sm_p8_2[] = {
  126299. 2, 5, 5, 6, 6, 7, 6, 7, 7, 8, 8, 8, 8, 8, 8, 8,
  126300. 8,10, 6, 6, 7, 7, 7, 7, 8, 8, 9, 9, 9, 9, 9, 9,
  126301. 9, 9,10, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  126302. 9, 9, 9,10, 7, 7, 7, 7, 8, 8, 8, 9, 9, 9, 9, 9,
  126303. 9, 9, 9, 9,10,10,10, 7, 7, 8, 8, 9, 9, 9, 9, 9,
  126304. 9, 9, 9, 9, 9,10,11,11, 8, 8, 8, 8, 9, 9, 9, 9,
  126305. 9, 9,10,10, 9,10,10,10,10, 8, 8, 8, 8, 9, 9, 9,
  126306. 9, 9, 9, 9, 9,10,10,11,10,10, 8, 8, 9, 9, 9, 9,
  126307. 9, 9, 9, 9, 9, 9,10, 9,10,10,10,11,11, 8, 8, 9,
  126308. 9, 9, 9, 9, 9, 9, 9, 9, 9,11,11,11,11,11, 9, 9,
  126309. 9, 9, 9, 9, 9, 9,10, 9,10, 9,11,11,11,11,11, 9,
  126310. 8, 9, 9, 9, 9, 9, 9, 9,10,10, 9,11,11,10,11,11,
  126311. 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10, 9,11,11,11,11,
  126312. 11,11,11, 9, 9,10, 9, 9, 9, 9,10, 9,10,10,11,10,
  126313. 11,11,11,11, 9,10,10,10, 9, 9, 9, 9, 9, 9,10,11,
  126314. 11,11,11,11,11, 9, 9, 9, 9, 9, 9, 9, 9,10, 9,11,
  126315. 11,10,11,11,11,11,10,10, 9, 9, 9, 9, 9, 9,10, 9,
  126316. 10,11,10,11,11,11,11,11,11, 9, 9,10, 9, 9, 9, 9,
  126317. 9,
  126318. };
  126319. static float _vq_quantthresh__44c1_sm_p8_2[] = {
  126320. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  126321. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  126322. };
  126323. static long _vq_quantmap__44c1_sm_p8_2[] = {
  126324. 15, 13, 11, 9, 7, 5, 3, 1,
  126325. 0, 2, 4, 6, 8, 10, 12, 14,
  126326. 16,
  126327. };
  126328. static encode_aux_threshmatch _vq_auxt__44c1_sm_p8_2 = {
  126329. _vq_quantthresh__44c1_sm_p8_2,
  126330. _vq_quantmap__44c1_sm_p8_2,
  126331. 17,
  126332. 17
  126333. };
  126334. static static_codebook _44c1_sm_p8_2 = {
  126335. 2, 289,
  126336. _vq_lengthlist__44c1_sm_p8_2,
  126337. 1, -529530880, 1611661312, 5, 0,
  126338. _vq_quantlist__44c1_sm_p8_2,
  126339. NULL,
  126340. &_vq_auxt__44c1_sm_p8_2,
  126341. NULL,
  126342. 0
  126343. };
  126344. static long _huff_lengthlist__44c1_sm_short[] = {
  126345. 4, 7,13,14,14,15,16,18,18, 4, 2, 5, 8, 7, 9,12,
  126346. 15,15,10, 4, 5,10, 6, 8,11,15,17,12, 5, 7, 5, 6,
  126347. 8,11,14,17,11, 5, 6, 6, 5, 6, 9,13,17,12, 6, 7,
  126348. 6, 5, 6, 8,12,14,14, 7, 8, 6, 6, 7, 9,11,14,14,
  126349. 8, 9, 6, 5, 6, 9,11,13,16,10,10, 7, 6, 7, 8,10,
  126350. 11,
  126351. };
  126352. static static_codebook _huff_book__44c1_sm_short = {
  126353. 2, 81,
  126354. _huff_lengthlist__44c1_sm_short,
  126355. 0, 0, 0, 0, 0,
  126356. NULL,
  126357. NULL,
  126358. NULL,
  126359. NULL,
  126360. 0
  126361. };
  126362. static long _huff_lengthlist__44cn1_s_long[] = {
  126363. 4, 4, 7, 8, 7, 8,10,12,17, 3, 1, 6, 6, 7, 8,10,
  126364. 12,15, 7, 6, 9, 9, 9,11,12,14,17, 8, 6, 9, 6, 7,
  126365. 9,11,13,17, 7, 6, 9, 7, 7, 8, 9,12,15, 8, 8,10,
  126366. 8, 7, 7, 7,10,14, 9,10,12,10, 8, 8, 8,10,14,11,
  126367. 13,15,13,12,11,11,12,16,17,18,18,19,20,18,16,16,
  126368. 20,
  126369. };
  126370. static static_codebook _huff_book__44cn1_s_long = {
  126371. 2, 81,
  126372. _huff_lengthlist__44cn1_s_long,
  126373. 0, 0, 0, 0, 0,
  126374. NULL,
  126375. NULL,
  126376. NULL,
  126377. NULL,
  126378. 0
  126379. };
  126380. static long _vq_quantlist__44cn1_s_p1_0[] = {
  126381. 1,
  126382. 0,
  126383. 2,
  126384. };
  126385. static long _vq_lengthlist__44cn1_s_p1_0[] = {
  126386. 1, 4, 4, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0, 0, 0, 0,
  126387. 0, 0, 5, 7, 7, 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, 5, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0, 0, 0,
  126392. 0, 0, 0, 7, 9,10, 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, 5, 8, 8, 0, 0, 0, 0, 0, 0, 7,10, 9, 0, 0,
  126397. 0, 0, 0, 0, 8,10, 9, 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, 5, 8, 8, 0, 0, 0, 0,
  126432. 0, 0, 8,10,10, 0, 0, 0, 0, 0, 0, 8, 9,10, 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, 7,10,10, 0, 0, 0,
  126437. 0, 0, 0, 9, 9,11, 0, 0, 0, 0, 0, 0,10,11,11, 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, 7,10,10, 0, 0,
  126442. 0, 0, 0, 0, 9,11, 9, 0, 0, 0, 0, 0, 0,10,11,11,
  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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126453. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126454. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126455. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126456. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126457. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126458. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126459. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126460. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126461. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126462. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126463. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126464. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126465. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126466. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126467. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126468. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126469. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126470. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126471. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126472. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126473. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126474. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126475. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126476. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126477. 0, 0, 5, 8, 8, 0, 0, 0, 0, 0, 0, 8,10,10, 0, 0,
  126478. 0, 0, 0, 0, 8,10,10, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126479. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126480. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126481. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126482. 0, 0, 0, 7,10,10, 0, 0, 0, 0, 0, 0,10,11,11, 0,
  126483. 0, 0, 0, 0, 0, 9, 9,11, 0, 0, 0, 0, 0, 0, 0, 0,
  126484. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126485. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126486. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126487. 0, 0, 0, 0, 7,10,10, 0, 0, 0, 0, 0, 0,10,11,11,
  126488. 0, 0, 0, 0, 0, 0, 9,11, 9, 0, 0, 0, 0, 0, 0, 0,
  126489. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126490. 0, 0, 0, 0, 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126524. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126525. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126526. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126527. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126528. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126529. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126530. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126531. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126532. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126533. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126534. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126535. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126536. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126537. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126538. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126539. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126540. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126541. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126542. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126543. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126544. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126545. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126546. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126547. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126548. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126549. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126550. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126551. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126552. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126553. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126554. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126555. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126556. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126557. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126558. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126559. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126560. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126561. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126562. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126563. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126564. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126565. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126566. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126567. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126568. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126569. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126570. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126571. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126572. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126573. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126574. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126575. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126576. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126577. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126578. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126579. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126580. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126581. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126582. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126583. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126584. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126585. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126586. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126587. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126588. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126589. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126590. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126591. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126592. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126593. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126594. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126595. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126596. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126597. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126598. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126599. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126600. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126601. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126602. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126603. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126604. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126605. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126606. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126607. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126608. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126609. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126610. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126611. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126612. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126613. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126614. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126615. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126616. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126617. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126618. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126619. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126620. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126621. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126622. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126623. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126624. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126625. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126626. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126627. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126628. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126629. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126630. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126631. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126632. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126633. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126634. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126635. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126636. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126637. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126638. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126639. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126640. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126641. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126642. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126643. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126644. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126645. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126646. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126647. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126648. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126649. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126650. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126651. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126652. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126653. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126654. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126655. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126656. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126657. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126658. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126659. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126660. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126661. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126662. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126663. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126664. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126665. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126666. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126667. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126668. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126669. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126670. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126671. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126672. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126673. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126674. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126675. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126676. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126677. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126678. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126679. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126680. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126681. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126682. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126683. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126684. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126685. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126686. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126687. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126688. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126689. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126690. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126691. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126692. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126693. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126694. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126695. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126696. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126697. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126698. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126699. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126700. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126701. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126702. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126703. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126704. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126705. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126706. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126707. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126708. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126709. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126710. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126711. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126712. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126713. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126714. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126715. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126716. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126717. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126718. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126719. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126720. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126721. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126722. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126723. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126724. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126725. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126726. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126727. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126728. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126729. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126730. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126731. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126732. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126733. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126734. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126735. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126736. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126737. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126738. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126739. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126740. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126741. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126742. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126743. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126744. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126745. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126746. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126747. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126748. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126749. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126750. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126751. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126752. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126753. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126754. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126755. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126756. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126757. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126758. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126759. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126760. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126761. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126762. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126763. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126764. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126765. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126766. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126767. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126768. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126769. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126770. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126771. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126772. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126773. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126774. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126775. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126776. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126777. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126778. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126779. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126780. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126781. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126782. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126783. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126784. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126785. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126786. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126787. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126788. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126789. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126790. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126791. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126792. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126793. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126794. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126795. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126796. 0,
  126797. };
  126798. static float _vq_quantthresh__44cn1_s_p1_0[] = {
  126799. -0.5, 0.5,
  126800. };
  126801. static long _vq_quantmap__44cn1_s_p1_0[] = {
  126802. 1, 0, 2,
  126803. };
  126804. static encode_aux_threshmatch _vq_auxt__44cn1_s_p1_0 = {
  126805. _vq_quantthresh__44cn1_s_p1_0,
  126806. _vq_quantmap__44cn1_s_p1_0,
  126807. 3,
  126808. 3
  126809. };
  126810. static static_codebook _44cn1_s_p1_0 = {
  126811. 8, 6561,
  126812. _vq_lengthlist__44cn1_s_p1_0,
  126813. 1, -535822336, 1611661312, 2, 0,
  126814. _vq_quantlist__44cn1_s_p1_0,
  126815. NULL,
  126816. &_vq_auxt__44cn1_s_p1_0,
  126817. NULL,
  126818. 0
  126819. };
  126820. static long _vq_quantlist__44cn1_s_p2_0[] = {
  126821. 2,
  126822. 1,
  126823. 3,
  126824. 0,
  126825. 4,
  126826. };
  126827. static long _vq_lengthlist__44cn1_s_p2_0[] = {
  126828. 1, 4, 4, 7, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126829. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 5, 5, 7, 7, 0, 0,
  126830. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126831. 0, 0, 4, 5, 5, 7, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126832. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 7, 7, 9, 9,
  126833. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126834. 0, 0, 0, 0, 6, 7, 7, 9, 9, 0, 0, 0, 0, 0, 0, 0,
  126835. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126836. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126837. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126838. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126839. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126840. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126841. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126842. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126843. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126844. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126845. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126846. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126847. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126848. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126849. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126850. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126851. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126852. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126853. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126854. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126855. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126856. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126857. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126858. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126859. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126860. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126861. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126862. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126863. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126864. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126865. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126866. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126867. 0,
  126868. };
  126869. static float _vq_quantthresh__44cn1_s_p2_0[] = {
  126870. -1.5, -0.5, 0.5, 1.5,
  126871. };
  126872. static long _vq_quantmap__44cn1_s_p2_0[] = {
  126873. 3, 1, 0, 2, 4,
  126874. };
  126875. static encode_aux_threshmatch _vq_auxt__44cn1_s_p2_0 = {
  126876. _vq_quantthresh__44cn1_s_p2_0,
  126877. _vq_quantmap__44cn1_s_p2_0,
  126878. 5,
  126879. 5
  126880. };
  126881. static static_codebook _44cn1_s_p2_0 = {
  126882. 4, 625,
  126883. _vq_lengthlist__44cn1_s_p2_0,
  126884. 1, -533725184, 1611661312, 3, 0,
  126885. _vq_quantlist__44cn1_s_p2_0,
  126886. NULL,
  126887. &_vq_auxt__44cn1_s_p2_0,
  126888. NULL,
  126889. 0
  126890. };
  126891. static long _vq_quantlist__44cn1_s_p3_0[] = {
  126892. 4,
  126893. 3,
  126894. 5,
  126895. 2,
  126896. 6,
  126897. 1,
  126898. 7,
  126899. 0,
  126900. 8,
  126901. };
  126902. static long _vq_lengthlist__44cn1_s_p3_0[] = {
  126903. 1, 2, 3, 7, 7, 0, 0, 0, 0, 0, 0, 0, 6, 6, 0, 0,
  126904. 0, 0, 0, 0, 0, 6, 6, 0, 0, 0, 0, 0, 0, 0, 7, 7,
  126905. 0, 0, 0, 0, 0, 0, 0, 7, 7, 0, 0, 0, 0, 0, 0, 0,
  126906. 9, 8, 0, 0, 0, 0, 0, 0, 0, 8, 8, 0, 0, 0, 0, 0,
  126907. 0, 0,10,10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126908. 0,
  126909. };
  126910. static float _vq_quantthresh__44cn1_s_p3_0[] = {
  126911. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  126912. };
  126913. static long _vq_quantmap__44cn1_s_p3_0[] = {
  126914. 7, 5, 3, 1, 0, 2, 4, 6,
  126915. 8,
  126916. };
  126917. static encode_aux_threshmatch _vq_auxt__44cn1_s_p3_0 = {
  126918. _vq_quantthresh__44cn1_s_p3_0,
  126919. _vq_quantmap__44cn1_s_p3_0,
  126920. 9,
  126921. 9
  126922. };
  126923. static static_codebook _44cn1_s_p3_0 = {
  126924. 2, 81,
  126925. _vq_lengthlist__44cn1_s_p3_0,
  126926. 1, -531628032, 1611661312, 4, 0,
  126927. _vq_quantlist__44cn1_s_p3_0,
  126928. NULL,
  126929. &_vq_auxt__44cn1_s_p3_0,
  126930. NULL,
  126931. 0
  126932. };
  126933. static long _vq_quantlist__44cn1_s_p4_0[] = {
  126934. 4,
  126935. 3,
  126936. 5,
  126937. 2,
  126938. 6,
  126939. 1,
  126940. 7,
  126941. 0,
  126942. 8,
  126943. };
  126944. static long _vq_lengthlist__44cn1_s_p4_0[] = {
  126945. 1, 3, 3, 6, 6, 6, 6, 8, 8, 0, 0, 0, 6, 6, 7, 7,
  126946. 9, 9, 0, 0, 0, 6, 6, 7, 7, 9, 9, 0, 0, 0, 7, 7,
  126947. 8, 8,10,10, 0, 0, 0, 7, 7, 8, 8,10,10, 0, 0, 0,
  126948. 9, 9, 9, 9,10,10, 0, 0, 0, 9, 9, 9, 9,10,10, 0,
  126949. 0, 0,10,10,10,10,11,11, 0, 0, 0, 0, 0,10,10,11,
  126950. 11,
  126951. };
  126952. static float _vq_quantthresh__44cn1_s_p4_0[] = {
  126953. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  126954. };
  126955. static long _vq_quantmap__44cn1_s_p4_0[] = {
  126956. 7, 5, 3, 1, 0, 2, 4, 6,
  126957. 8,
  126958. };
  126959. static encode_aux_threshmatch _vq_auxt__44cn1_s_p4_0 = {
  126960. _vq_quantthresh__44cn1_s_p4_0,
  126961. _vq_quantmap__44cn1_s_p4_0,
  126962. 9,
  126963. 9
  126964. };
  126965. static static_codebook _44cn1_s_p4_0 = {
  126966. 2, 81,
  126967. _vq_lengthlist__44cn1_s_p4_0,
  126968. 1, -531628032, 1611661312, 4, 0,
  126969. _vq_quantlist__44cn1_s_p4_0,
  126970. NULL,
  126971. &_vq_auxt__44cn1_s_p4_0,
  126972. NULL,
  126973. 0
  126974. };
  126975. static long _vq_quantlist__44cn1_s_p5_0[] = {
  126976. 8,
  126977. 7,
  126978. 9,
  126979. 6,
  126980. 10,
  126981. 5,
  126982. 11,
  126983. 4,
  126984. 12,
  126985. 3,
  126986. 13,
  126987. 2,
  126988. 14,
  126989. 1,
  126990. 15,
  126991. 0,
  126992. 16,
  126993. };
  126994. static long _vq_lengthlist__44cn1_s_p5_0[] = {
  126995. 1, 4, 3, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,10,10,10,
  126996. 10, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,10,10,
  126997. 11,11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,10,
  126998. 10,11,11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,
  126999. 11,11,11,12, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,
  127000. 10,11,11,11,11, 0, 0, 0, 8, 8, 9, 9, 9, 9,10,10,
  127001. 10,10,11,11,12,12, 0, 0, 0, 8, 8, 9, 9, 9, 9,10,
  127002. 10,10,11,11,11,12,12, 0, 0, 0, 9, 9,10, 9,10,10,
  127003. 10,10,11,11,11,11,12,12, 0, 0, 0, 0, 0, 9, 9,10,
  127004. 10,10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 9, 9,
  127005. 10,10,10,11,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9,
  127006. 9,10,10,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0,
  127007. 10,10,11,10,11,11,11,12,13,12,13,13, 0, 0, 0, 0,
  127008. 0, 0, 0,11,10,11,11,12,12,12,12,13,13, 0, 0, 0,
  127009. 0, 0, 0, 0,11,11,12,12,12,12,13,13,13,14, 0, 0,
  127010. 0, 0, 0, 0, 0,11,11,12,12,12,12,13,13,13,14, 0,
  127011. 0, 0, 0, 0, 0, 0,12,12,12,13,13,13,13,13,14,14,
  127012. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,13,12,13,13,14,
  127013. 14,
  127014. };
  127015. static float _vq_quantthresh__44cn1_s_p5_0[] = {
  127016. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  127017. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  127018. };
  127019. static long _vq_quantmap__44cn1_s_p5_0[] = {
  127020. 15, 13, 11, 9, 7, 5, 3, 1,
  127021. 0, 2, 4, 6, 8, 10, 12, 14,
  127022. 16,
  127023. };
  127024. static encode_aux_threshmatch _vq_auxt__44cn1_s_p5_0 = {
  127025. _vq_quantthresh__44cn1_s_p5_0,
  127026. _vq_quantmap__44cn1_s_p5_0,
  127027. 17,
  127028. 17
  127029. };
  127030. static static_codebook _44cn1_s_p5_0 = {
  127031. 2, 289,
  127032. _vq_lengthlist__44cn1_s_p5_0,
  127033. 1, -529530880, 1611661312, 5, 0,
  127034. _vq_quantlist__44cn1_s_p5_0,
  127035. NULL,
  127036. &_vq_auxt__44cn1_s_p5_0,
  127037. NULL,
  127038. 0
  127039. };
  127040. static long _vq_quantlist__44cn1_s_p6_0[] = {
  127041. 1,
  127042. 0,
  127043. 2,
  127044. };
  127045. static long _vq_lengthlist__44cn1_s_p6_0[] = {
  127046. 1, 4, 4, 7, 6, 6, 7, 6, 6, 4, 6, 6,10, 9, 9,11,
  127047. 9, 9, 4, 6, 6,10, 9, 9,10, 9, 9, 7,10,10,11,11,
  127048. 11,12,11,11, 7, 9, 9,11,11,10,11,10,10, 7, 9, 9,
  127049. 11,10,11,11,10,10, 7,10,10,11,11,11,12,11,11, 7,
  127050. 9, 9,11,10,10,11,10,10, 7, 9, 9,11,10,10,11,10,
  127051. 10,
  127052. };
  127053. static float _vq_quantthresh__44cn1_s_p6_0[] = {
  127054. -5.5, 5.5,
  127055. };
  127056. static long _vq_quantmap__44cn1_s_p6_0[] = {
  127057. 1, 0, 2,
  127058. };
  127059. static encode_aux_threshmatch _vq_auxt__44cn1_s_p6_0 = {
  127060. _vq_quantthresh__44cn1_s_p6_0,
  127061. _vq_quantmap__44cn1_s_p6_0,
  127062. 3,
  127063. 3
  127064. };
  127065. static static_codebook _44cn1_s_p6_0 = {
  127066. 4, 81,
  127067. _vq_lengthlist__44cn1_s_p6_0,
  127068. 1, -529137664, 1618345984, 2, 0,
  127069. _vq_quantlist__44cn1_s_p6_0,
  127070. NULL,
  127071. &_vq_auxt__44cn1_s_p6_0,
  127072. NULL,
  127073. 0
  127074. };
  127075. static long _vq_quantlist__44cn1_s_p6_1[] = {
  127076. 5,
  127077. 4,
  127078. 6,
  127079. 3,
  127080. 7,
  127081. 2,
  127082. 8,
  127083. 1,
  127084. 9,
  127085. 0,
  127086. 10,
  127087. };
  127088. static long _vq_lengthlist__44cn1_s_p6_1[] = {
  127089. 1, 4, 4, 6, 6, 7, 7, 8, 8, 8, 8,10,10,10, 7, 6,
  127090. 8, 8, 8, 8, 8, 8,10,10,10, 7, 6, 7, 7, 8, 8, 8,
  127091. 8,10,10,10, 7, 7, 8, 8, 8, 8, 8, 8,10,10,10, 7,
  127092. 7, 8, 8, 8, 8, 8, 8,10,10,10, 8, 8, 8, 8, 9, 9,
  127093. 9, 9,10,10,10, 8, 8, 8, 8, 9, 9, 9, 9,10,10,10,
  127094. 9, 9, 9, 9, 9, 9, 9, 9,10,10,10,10,10, 9, 9, 9,
  127095. 9, 9, 9,10,10,10,10,10, 9, 9, 9, 9, 9, 9,10,10,
  127096. 10,10,10, 9, 9, 9, 9, 9, 9,
  127097. };
  127098. static float _vq_quantthresh__44cn1_s_p6_1[] = {
  127099. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  127100. 3.5, 4.5,
  127101. };
  127102. static long _vq_quantmap__44cn1_s_p6_1[] = {
  127103. 9, 7, 5, 3, 1, 0, 2, 4,
  127104. 6, 8, 10,
  127105. };
  127106. static encode_aux_threshmatch _vq_auxt__44cn1_s_p6_1 = {
  127107. _vq_quantthresh__44cn1_s_p6_1,
  127108. _vq_quantmap__44cn1_s_p6_1,
  127109. 11,
  127110. 11
  127111. };
  127112. static static_codebook _44cn1_s_p6_1 = {
  127113. 2, 121,
  127114. _vq_lengthlist__44cn1_s_p6_1,
  127115. 1, -531365888, 1611661312, 4, 0,
  127116. _vq_quantlist__44cn1_s_p6_1,
  127117. NULL,
  127118. &_vq_auxt__44cn1_s_p6_1,
  127119. NULL,
  127120. 0
  127121. };
  127122. static long _vq_quantlist__44cn1_s_p7_0[] = {
  127123. 6,
  127124. 5,
  127125. 7,
  127126. 4,
  127127. 8,
  127128. 3,
  127129. 9,
  127130. 2,
  127131. 10,
  127132. 1,
  127133. 11,
  127134. 0,
  127135. 12,
  127136. };
  127137. static long _vq_lengthlist__44cn1_s_p7_0[] = {
  127138. 1, 4, 4, 6, 6, 7, 7, 8, 8, 9, 9,10,10, 6, 5, 5,
  127139. 7, 7, 8, 8, 8, 8, 9, 9,11,11, 7, 5, 5, 7, 7, 8,
  127140. 8, 8, 8, 9,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  127141. 10,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,
  127142. 11, 0,12,12, 9, 9, 9,10,10,10,11,11,11,12, 0,13,
  127143. 13, 9, 9, 9, 9,10,10,11,11,11,12, 0, 0, 0,10,10,
  127144. 10,10,11,11,12,12,12,13, 0, 0, 0,10,10,10,10,11,
  127145. 11,12,12,13,12, 0, 0, 0,14,14,11,10,11,12,12,13,
  127146. 13,14, 0, 0, 0,15,15,11,11,12,11,12,12,14,13, 0,
  127147. 0, 0, 0, 0,12,12,12,12,13,13,14,14, 0, 0, 0, 0,
  127148. 0,13,13,12,12,13,13,13,14,
  127149. };
  127150. static float _vq_quantthresh__44cn1_s_p7_0[] = {
  127151. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  127152. 12.5, 17.5, 22.5, 27.5,
  127153. };
  127154. static long _vq_quantmap__44cn1_s_p7_0[] = {
  127155. 11, 9, 7, 5, 3, 1, 0, 2,
  127156. 4, 6, 8, 10, 12,
  127157. };
  127158. static encode_aux_threshmatch _vq_auxt__44cn1_s_p7_0 = {
  127159. _vq_quantthresh__44cn1_s_p7_0,
  127160. _vq_quantmap__44cn1_s_p7_0,
  127161. 13,
  127162. 13
  127163. };
  127164. static static_codebook _44cn1_s_p7_0 = {
  127165. 2, 169,
  127166. _vq_lengthlist__44cn1_s_p7_0,
  127167. 1, -526516224, 1616117760, 4, 0,
  127168. _vq_quantlist__44cn1_s_p7_0,
  127169. NULL,
  127170. &_vq_auxt__44cn1_s_p7_0,
  127171. NULL,
  127172. 0
  127173. };
  127174. static long _vq_quantlist__44cn1_s_p7_1[] = {
  127175. 2,
  127176. 1,
  127177. 3,
  127178. 0,
  127179. 4,
  127180. };
  127181. static long _vq_lengthlist__44cn1_s_p7_1[] = {
  127182. 2, 3, 3, 5, 5, 6, 6, 6, 5, 5, 6, 6, 6, 5, 5, 6,
  127183. 6, 6, 5, 5, 6, 6, 6, 5, 5,
  127184. };
  127185. static float _vq_quantthresh__44cn1_s_p7_1[] = {
  127186. -1.5, -0.5, 0.5, 1.5,
  127187. };
  127188. static long _vq_quantmap__44cn1_s_p7_1[] = {
  127189. 3, 1, 0, 2, 4,
  127190. };
  127191. static encode_aux_threshmatch _vq_auxt__44cn1_s_p7_1 = {
  127192. _vq_quantthresh__44cn1_s_p7_1,
  127193. _vq_quantmap__44cn1_s_p7_1,
  127194. 5,
  127195. 5
  127196. };
  127197. static static_codebook _44cn1_s_p7_1 = {
  127198. 2, 25,
  127199. _vq_lengthlist__44cn1_s_p7_1,
  127200. 1, -533725184, 1611661312, 3, 0,
  127201. _vq_quantlist__44cn1_s_p7_1,
  127202. NULL,
  127203. &_vq_auxt__44cn1_s_p7_1,
  127204. NULL,
  127205. 0
  127206. };
  127207. static long _vq_quantlist__44cn1_s_p8_0[] = {
  127208. 2,
  127209. 1,
  127210. 3,
  127211. 0,
  127212. 4,
  127213. };
  127214. static long _vq_lengthlist__44cn1_s_p8_0[] = {
  127215. 1, 7, 7,11,11, 8,11,11,11,11, 4,11, 3,11,11,11,
  127216. 11,11,11,11,11,11,11,11,11,11,11,10,11,11,11,11,
  127217. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  127218. 11,11,11,10,11,11,11,11,11,11,11,11,11,11,11,11,
  127219. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  127220. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  127221. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  127222. 11,11,11,11,11,11,11,11,11,11,11,11,11, 7,11,11,
  127223. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  127224. 11,11,11,11,11,11,10,11,11,11,11,11,11,11,11,11,
  127225. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,10,
  127226. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  127227. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  127228. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  127229. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  127230. 11,11,11,11,11,11,11,11,11,11, 8,11,11,11,11,11,
  127231. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  127232. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  127233. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  127234. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  127235. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  127236. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  127237. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  127238. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  127239. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  127240. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  127241. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  127242. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  127243. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  127244. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  127245. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  127246. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  127247. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  127248. 11,11,11,11,11,11,11,12,12,12,12,12,12,12,12,12,
  127249. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  127250. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  127251. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  127252. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  127253. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  127254. 12,
  127255. };
  127256. static float _vq_quantthresh__44cn1_s_p8_0[] = {
  127257. -331.5, -110.5, 110.5, 331.5,
  127258. };
  127259. static long _vq_quantmap__44cn1_s_p8_0[] = {
  127260. 3, 1, 0, 2, 4,
  127261. };
  127262. static encode_aux_threshmatch _vq_auxt__44cn1_s_p8_0 = {
  127263. _vq_quantthresh__44cn1_s_p8_0,
  127264. _vq_quantmap__44cn1_s_p8_0,
  127265. 5,
  127266. 5
  127267. };
  127268. static static_codebook _44cn1_s_p8_0 = {
  127269. 4, 625,
  127270. _vq_lengthlist__44cn1_s_p8_0,
  127271. 1, -518283264, 1627103232, 3, 0,
  127272. _vq_quantlist__44cn1_s_p8_0,
  127273. NULL,
  127274. &_vq_auxt__44cn1_s_p8_0,
  127275. NULL,
  127276. 0
  127277. };
  127278. static long _vq_quantlist__44cn1_s_p8_1[] = {
  127279. 6,
  127280. 5,
  127281. 7,
  127282. 4,
  127283. 8,
  127284. 3,
  127285. 9,
  127286. 2,
  127287. 10,
  127288. 1,
  127289. 11,
  127290. 0,
  127291. 12,
  127292. };
  127293. static long _vq_lengthlist__44cn1_s_p8_1[] = {
  127294. 1, 4, 4, 6, 6, 8, 8, 9,10,10,11,11,11, 6, 5, 5,
  127295. 7, 7, 8, 8, 9,10, 9,11,11,12, 5, 5, 5, 7, 7, 8,
  127296. 9,10,10,12,12,14,13,15, 7, 7, 8, 8, 9,10,11,11,
  127297. 10,12,10,11,15, 7, 8, 8, 8, 9, 9,11,11,13,12,12,
  127298. 13,15,10,10, 8, 8,10,10,12,12,11,14,10,10,15,11,
  127299. 11, 8, 8,10,10,12,13,13,14,15,13,15,15,15,10,10,
  127300. 10,10,12,12,13,12,13,10,15,15,15,10,10,11,10,13,
  127301. 11,13,13,15,13,15,15,15,13,13,10,11,11,11,12,10,
  127302. 14,11,15,15,14,14,13,10,10,12,11,13,13,14,14,15,
  127303. 15,15,15,15,11,11,11,11,12,11,15,12,15,15,15,15,
  127304. 15,12,12,11,11,14,12,13,14,
  127305. };
  127306. static float _vq_quantthresh__44cn1_s_p8_1[] = {
  127307. -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5, 25.5,
  127308. 42.5, 59.5, 76.5, 93.5,
  127309. };
  127310. static long _vq_quantmap__44cn1_s_p8_1[] = {
  127311. 11, 9, 7, 5, 3, 1, 0, 2,
  127312. 4, 6, 8, 10, 12,
  127313. };
  127314. static encode_aux_threshmatch _vq_auxt__44cn1_s_p8_1 = {
  127315. _vq_quantthresh__44cn1_s_p8_1,
  127316. _vq_quantmap__44cn1_s_p8_1,
  127317. 13,
  127318. 13
  127319. };
  127320. static static_codebook _44cn1_s_p8_1 = {
  127321. 2, 169,
  127322. _vq_lengthlist__44cn1_s_p8_1,
  127323. 1, -522616832, 1620115456, 4, 0,
  127324. _vq_quantlist__44cn1_s_p8_1,
  127325. NULL,
  127326. &_vq_auxt__44cn1_s_p8_1,
  127327. NULL,
  127328. 0
  127329. };
  127330. static long _vq_quantlist__44cn1_s_p8_2[] = {
  127331. 8,
  127332. 7,
  127333. 9,
  127334. 6,
  127335. 10,
  127336. 5,
  127337. 11,
  127338. 4,
  127339. 12,
  127340. 3,
  127341. 13,
  127342. 2,
  127343. 14,
  127344. 1,
  127345. 15,
  127346. 0,
  127347. 16,
  127348. };
  127349. static long _vq_lengthlist__44cn1_s_p8_2[] = {
  127350. 3, 4, 3, 6, 6, 7, 7, 8, 8, 9, 9, 9, 9, 9, 9, 9,
  127351. 9,10,11,11, 6, 6, 7, 7, 8, 8, 9, 9, 9, 9, 9, 9,
  127352. 9, 9,10,10,10, 6, 6, 7, 7, 8, 8, 9, 9, 9, 9, 9,
  127353. 9, 9, 9,10,10,10, 7, 7, 7, 8, 8, 8, 9, 9, 9, 9,
  127354. 9, 9,10, 9,10,11,10, 7, 6, 7, 7, 8, 8, 9, 9, 9,
  127355. 9, 9, 9, 9,10,10,10,11, 7, 7, 8, 8, 8, 8, 9, 9,
  127356. 9, 9, 9, 9, 9, 9,10,10,10, 7, 7, 8, 8, 8, 8, 9,
  127357. 9, 9, 9, 9, 9, 9,10,11,11,11, 8, 8, 8, 8, 8, 8,
  127358. 9, 9, 9, 9, 9, 9, 9, 9,11,10,10,11,11, 8, 8, 8,
  127359. 9, 9, 9, 9, 9, 9,10, 9,10,10,10,10,11,11, 9, 9,
  127360. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,11,11,10,11,11, 9,
  127361. 9, 9, 9, 9, 9, 9, 9, 9,10,10,10,10,11,10,11,11,
  127362. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,11,10,10,11,
  127363. 11,11,11, 9, 9, 9, 9, 9, 9, 9, 9,10,10,10,11,11,
  127364. 10,11,11,11, 9,10,10, 9, 9, 9, 9, 9, 9, 9,10,11,
  127365. 11,11,11,11,11, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,11,
  127366. 11,11,11,11,11,11,10,10, 9, 9, 9, 9, 9, 9, 9, 9,
  127367. 11,11,11,10,11,11,11,11,11, 9, 9, 9,10, 9, 9, 9,
  127368. 9,
  127369. };
  127370. static float _vq_quantthresh__44cn1_s_p8_2[] = {
  127371. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  127372. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  127373. };
  127374. static long _vq_quantmap__44cn1_s_p8_2[] = {
  127375. 15, 13, 11, 9, 7, 5, 3, 1,
  127376. 0, 2, 4, 6, 8, 10, 12, 14,
  127377. 16,
  127378. };
  127379. static encode_aux_threshmatch _vq_auxt__44cn1_s_p8_2 = {
  127380. _vq_quantthresh__44cn1_s_p8_2,
  127381. _vq_quantmap__44cn1_s_p8_2,
  127382. 17,
  127383. 17
  127384. };
  127385. static static_codebook _44cn1_s_p8_2 = {
  127386. 2, 289,
  127387. _vq_lengthlist__44cn1_s_p8_2,
  127388. 1, -529530880, 1611661312, 5, 0,
  127389. _vq_quantlist__44cn1_s_p8_2,
  127390. NULL,
  127391. &_vq_auxt__44cn1_s_p8_2,
  127392. NULL,
  127393. 0
  127394. };
  127395. static long _huff_lengthlist__44cn1_s_short[] = {
  127396. 10, 9,12,15,12,13,16,14,16, 7, 1, 5,14, 7,10,13,
  127397. 16,16, 9, 4, 6,16, 8,11,16,16,16,14, 4, 7,16, 9,
  127398. 12,14,16,16,10, 5, 7,14, 9,12,14,15,15,13, 8, 9,
  127399. 14,10,12,13,14,15,13, 9, 9, 7, 6, 8,11,12,12,14,
  127400. 8, 8, 5, 4, 5, 8,11,12,16,10,10, 6, 5, 6, 8, 9,
  127401. 10,
  127402. };
  127403. static static_codebook _huff_book__44cn1_s_short = {
  127404. 2, 81,
  127405. _huff_lengthlist__44cn1_s_short,
  127406. 0, 0, 0, 0, 0,
  127407. NULL,
  127408. NULL,
  127409. NULL,
  127410. NULL,
  127411. 0
  127412. };
  127413. static long _huff_lengthlist__44cn1_sm_long[] = {
  127414. 3, 3, 8, 8, 8, 8,10,12,14, 3, 2, 6, 7, 7, 8,10,
  127415. 12,16, 7, 6, 7, 9, 8,10,12,14,16, 8, 6, 8, 4, 5,
  127416. 7, 9,11,13, 7, 6, 8, 5, 6, 7, 9,11,14, 8, 8,10,
  127417. 7, 7, 6, 8,10,13, 9,11,12, 9, 9, 7, 8,10,12,10,
  127418. 13,15,11,11,10, 9,10,13,13,16,17,14,15,14,13,14,
  127419. 17,
  127420. };
  127421. static static_codebook _huff_book__44cn1_sm_long = {
  127422. 2, 81,
  127423. _huff_lengthlist__44cn1_sm_long,
  127424. 0, 0, 0, 0, 0,
  127425. NULL,
  127426. NULL,
  127427. NULL,
  127428. NULL,
  127429. 0
  127430. };
  127431. static long _vq_quantlist__44cn1_sm_p1_0[] = {
  127432. 1,
  127433. 0,
  127434. 2,
  127435. };
  127436. static long _vq_lengthlist__44cn1_sm_p1_0[] = {
  127437. 1, 4, 5, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0, 0, 0, 0,
  127438. 0, 0, 5, 7, 7, 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, 5, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0, 0, 0,
  127443. 0, 0, 0, 7, 8, 9, 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, 5, 8, 8, 0, 0, 0, 0, 0, 0, 7, 9, 8, 0, 0,
  127448. 0, 0, 0, 0, 8, 9, 9, 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, 5, 8, 8, 0, 0, 0, 0,
  127483. 0, 0, 8,10, 9, 0, 0, 0, 0, 0, 0, 8, 9, 9, 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, 7,10, 9, 0, 0, 0,
  127488. 0, 0, 0, 9, 9,10, 0, 0, 0, 0, 0, 0, 9,10,10, 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, 7, 9, 9, 0, 0,
  127493. 0, 0, 0, 0, 8,10, 9, 0, 0, 0, 0, 0, 0, 9,10,10,
  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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127504. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127505. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127506. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127507. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127508. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127509. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127510. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127511. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127512. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127513. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127514. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127515. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127516. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127517. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127518. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127519. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127520. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127521. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127522. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127523. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127524. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127525. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127526. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127527. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127528. 0, 0, 5, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0, 0,
  127529. 0, 0, 0, 0, 8, 9,10, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127530. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127531. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127532. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127533. 0, 0, 0, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,10,10, 0,
  127534. 0, 0, 0, 0, 0, 8, 9,10, 0, 0, 0, 0, 0, 0, 0, 0,
  127535. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127536. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127537. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127538. 0, 0, 0, 0, 7, 9,10, 0, 0, 0, 0, 0, 0, 9,10,10,
  127539. 0, 0, 0, 0, 0, 0, 9,10, 9, 0, 0, 0, 0, 0, 0, 0,
  127540. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127541. 0, 0, 0, 0, 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127575. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127576. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127577. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127578. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127579. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127580. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127581. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127582. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127583. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127584. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127585. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127586. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127587. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127588. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127589. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127590. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127591. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127592. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127593. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127594. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127595. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127596. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127597. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127598. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127599. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127600. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127601. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127602. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127603. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127604. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127605. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127606. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127607. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127608. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127609. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127610. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127611. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127612. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127613. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127614. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127615. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127616. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127617. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127618. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127619. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127620. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127621. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127622. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127623. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127624. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127625. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127626. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127627. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127628. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127629. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127630. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127631. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127632. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127633. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127634. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127635. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127636. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127637. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127638. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127639. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127640. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127641. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127642. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127643. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127644. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127645. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127646. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127647. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127648. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127649. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127650. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127651. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127652. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127653. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127654. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127655. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127656. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127657. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127658. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127659. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127660. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127661. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127662. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127663. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127664. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127665. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127666. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127667. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127668. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127669. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127670. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127671. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127672. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127673. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127674. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127675. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127676. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127677. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127678. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127679. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127680. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127681. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127682. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127683. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127684. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127685. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127686. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127687. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127688. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127689. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127690. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127691. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127692. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127693. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127694. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127695. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127696. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127697. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127698. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127699. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127700. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127701. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127702. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127703. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127704. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127705. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127706. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127707. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127708. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127709. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127710. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127711. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127712. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127713. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127714. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127715. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127716. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127717. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127718. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127719. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127720. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127721. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127722. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127723. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127724. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127725. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127726. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127727. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127728. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127729. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127730. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127731. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127732. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127733. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127734. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127735. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127736. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127737. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127738. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127739. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127740. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127741. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127742. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127743. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127744. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127745. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127746. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127747. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127748. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127749. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127750. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127751. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127752. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127753. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127754. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127755. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127756. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127757. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127758. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127759. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127760. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127761. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127762. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127763. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127764. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127765. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127766. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127767. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127768. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127769. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127770. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127771. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127772. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127773. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127774. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127775. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127776. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127777. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127778. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127779. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127780. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127781. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127782. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127783. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127784. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127785. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127786. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127787. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127788. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127789. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127790. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127791. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127792. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127793. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127794. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127795. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127796. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127797. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127798. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127799. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127800. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127801. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127802. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127803. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127804. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127805. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127806. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127807. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127808. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127809. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127810. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127811. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127812. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127813. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127814. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127815. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127816. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127817. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127818. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127819. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127820. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127821. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127822. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127823. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127824. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127825. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127826. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127827. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127828. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127829. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127830. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127831. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127832. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127833. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127834. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127835. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127836. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127837. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127838. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127839. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127840. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127841. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127842. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127843. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127844. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127845. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127846. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127847. 0,
  127848. };
  127849. static float _vq_quantthresh__44cn1_sm_p1_0[] = {
  127850. -0.5, 0.5,
  127851. };
  127852. static long _vq_quantmap__44cn1_sm_p1_0[] = {
  127853. 1, 0, 2,
  127854. };
  127855. static encode_aux_threshmatch _vq_auxt__44cn1_sm_p1_0 = {
  127856. _vq_quantthresh__44cn1_sm_p1_0,
  127857. _vq_quantmap__44cn1_sm_p1_0,
  127858. 3,
  127859. 3
  127860. };
  127861. static static_codebook _44cn1_sm_p1_0 = {
  127862. 8, 6561,
  127863. _vq_lengthlist__44cn1_sm_p1_0,
  127864. 1, -535822336, 1611661312, 2, 0,
  127865. _vq_quantlist__44cn1_sm_p1_0,
  127866. NULL,
  127867. &_vq_auxt__44cn1_sm_p1_0,
  127868. NULL,
  127869. 0
  127870. };
  127871. static long _vq_quantlist__44cn1_sm_p2_0[] = {
  127872. 2,
  127873. 1,
  127874. 3,
  127875. 0,
  127876. 4,
  127877. };
  127878. static long _vq_lengthlist__44cn1_sm_p2_0[] = {
  127879. 1, 4, 4, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127880. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 5, 5, 7, 7, 0, 0,
  127881. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127882. 0, 0, 4, 5, 5, 7, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127883. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 7, 7, 9, 9,
  127884. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127885. 0, 0, 0, 0, 7, 7, 7, 9, 9, 0, 0, 0, 0, 0, 0, 0,
  127886. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127887. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127888. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127889. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127890. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127891. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127892. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127893. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127894. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127895. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127896. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127897. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127898. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127899. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127900. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127901. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127902. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127903. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127904. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127905. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127906. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127907. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127908. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127909. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127910. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127911. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127912. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127913. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127914. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127915. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127916. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127917. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127918. 0,
  127919. };
  127920. static float _vq_quantthresh__44cn1_sm_p2_0[] = {
  127921. -1.5, -0.5, 0.5, 1.5,
  127922. };
  127923. static long _vq_quantmap__44cn1_sm_p2_0[] = {
  127924. 3, 1, 0, 2, 4,
  127925. };
  127926. static encode_aux_threshmatch _vq_auxt__44cn1_sm_p2_0 = {
  127927. _vq_quantthresh__44cn1_sm_p2_0,
  127928. _vq_quantmap__44cn1_sm_p2_0,
  127929. 5,
  127930. 5
  127931. };
  127932. static static_codebook _44cn1_sm_p2_0 = {
  127933. 4, 625,
  127934. _vq_lengthlist__44cn1_sm_p2_0,
  127935. 1, -533725184, 1611661312, 3, 0,
  127936. _vq_quantlist__44cn1_sm_p2_0,
  127937. NULL,
  127938. &_vq_auxt__44cn1_sm_p2_0,
  127939. NULL,
  127940. 0
  127941. };
  127942. static long _vq_quantlist__44cn1_sm_p3_0[] = {
  127943. 4,
  127944. 3,
  127945. 5,
  127946. 2,
  127947. 6,
  127948. 1,
  127949. 7,
  127950. 0,
  127951. 8,
  127952. };
  127953. static long _vq_lengthlist__44cn1_sm_p3_0[] = {
  127954. 1, 3, 4, 7, 7, 0, 0, 0, 0, 0, 4, 4, 7, 7, 0, 0,
  127955. 0, 0, 0, 4, 5, 7, 7, 0, 0, 0, 0, 0, 6, 7, 8, 8,
  127956. 0, 0, 0, 0, 0, 0, 0, 8, 8, 0, 0, 0, 0, 0, 0, 0,
  127957. 9, 9, 0, 0, 0, 0, 0, 0, 0,10, 9, 0, 0, 0, 0, 0,
  127958. 0, 0,11,11, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127959. 0,
  127960. };
  127961. static float _vq_quantthresh__44cn1_sm_p3_0[] = {
  127962. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  127963. };
  127964. static long _vq_quantmap__44cn1_sm_p3_0[] = {
  127965. 7, 5, 3, 1, 0, 2, 4, 6,
  127966. 8,
  127967. };
  127968. static encode_aux_threshmatch _vq_auxt__44cn1_sm_p3_0 = {
  127969. _vq_quantthresh__44cn1_sm_p3_0,
  127970. _vq_quantmap__44cn1_sm_p3_0,
  127971. 9,
  127972. 9
  127973. };
  127974. static static_codebook _44cn1_sm_p3_0 = {
  127975. 2, 81,
  127976. _vq_lengthlist__44cn1_sm_p3_0,
  127977. 1, -531628032, 1611661312, 4, 0,
  127978. _vq_quantlist__44cn1_sm_p3_0,
  127979. NULL,
  127980. &_vq_auxt__44cn1_sm_p3_0,
  127981. NULL,
  127982. 0
  127983. };
  127984. static long _vq_quantlist__44cn1_sm_p4_0[] = {
  127985. 4,
  127986. 3,
  127987. 5,
  127988. 2,
  127989. 6,
  127990. 1,
  127991. 7,
  127992. 0,
  127993. 8,
  127994. };
  127995. static long _vq_lengthlist__44cn1_sm_p4_0[] = {
  127996. 1, 4, 3, 6, 6, 7, 7, 9, 9, 0, 5, 5, 7, 7, 8, 7,
  127997. 9, 9, 0, 5, 5, 7, 7, 8, 8, 9, 9, 0, 7, 7, 8, 8,
  127998. 8, 8,10,10, 0, 0, 0, 8, 8, 8, 8,10,10, 0, 0, 0,
  127999. 9, 9, 9, 9,10,10, 0, 0, 0, 9, 9, 9, 9,10,10, 0,
  128000. 0, 0,10,10,10,10,11,11, 0, 0, 0, 0, 0,10,10,11,
  128001. 11,
  128002. };
  128003. static float _vq_quantthresh__44cn1_sm_p4_0[] = {
  128004. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  128005. };
  128006. static long _vq_quantmap__44cn1_sm_p4_0[] = {
  128007. 7, 5, 3, 1, 0, 2, 4, 6,
  128008. 8,
  128009. };
  128010. static encode_aux_threshmatch _vq_auxt__44cn1_sm_p4_0 = {
  128011. _vq_quantthresh__44cn1_sm_p4_0,
  128012. _vq_quantmap__44cn1_sm_p4_0,
  128013. 9,
  128014. 9
  128015. };
  128016. static static_codebook _44cn1_sm_p4_0 = {
  128017. 2, 81,
  128018. _vq_lengthlist__44cn1_sm_p4_0,
  128019. 1, -531628032, 1611661312, 4, 0,
  128020. _vq_quantlist__44cn1_sm_p4_0,
  128021. NULL,
  128022. &_vq_auxt__44cn1_sm_p4_0,
  128023. NULL,
  128024. 0
  128025. };
  128026. static long _vq_quantlist__44cn1_sm_p5_0[] = {
  128027. 8,
  128028. 7,
  128029. 9,
  128030. 6,
  128031. 10,
  128032. 5,
  128033. 11,
  128034. 4,
  128035. 12,
  128036. 3,
  128037. 13,
  128038. 2,
  128039. 14,
  128040. 1,
  128041. 15,
  128042. 0,
  128043. 16,
  128044. };
  128045. static long _vq_lengthlist__44cn1_sm_p5_0[] = {
  128046. 1, 4, 4, 6, 6, 8, 8, 9, 9, 8, 8, 9, 9,10,10,11,
  128047. 11, 0, 6, 6, 7, 7, 8, 8, 9, 9, 9, 9,10,10,11,11,
  128048. 12,12, 0, 6, 5, 7, 7, 8, 8, 9, 9, 9, 9,10,10,11,
  128049. 11,12,12, 0, 7, 7, 7, 7, 8, 8, 9, 9, 9, 9,10,10,
  128050. 11,11,12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9,10,10,11,
  128051. 11,11,11,12,12, 0, 0, 0, 8, 8, 9, 9,10,10,10,10,
  128052. 11,11,12,12,12,12, 0, 0, 0, 8, 8, 9, 9,10,10,10,
  128053. 10,11,11,12,12,12,12, 0, 0, 0, 9, 9, 9, 9,10,10,
  128054. 10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9, 9,10,
  128055. 10,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9, 9,
  128056. 10,10,11,11,12,12,13,13,13,13, 0, 0, 0, 0, 0, 9,
  128057. 9,10,10,11,11,12,12,12,13,13,13, 0, 0, 0, 0, 0,
  128058. 10,10,11,11,11,11,12,12,13,13,14,14, 0, 0, 0, 0,
  128059. 0, 0, 0,11,11,11,11,12,12,13,13,14,14, 0, 0, 0,
  128060. 0, 0, 0, 0,11,11,12,12,13,13,13,13,14,14, 0, 0,
  128061. 0, 0, 0, 0, 0,11,11,12,12,13,13,13,13,14,14, 0,
  128062. 0, 0, 0, 0, 0, 0,12,12,12,13,13,13,14,14,14,14,
  128063. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,13,13,14,14,14,
  128064. 14,
  128065. };
  128066. static float _vq_quantthresh__44cn1_sm_p5_0[] = {
  128067. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  128068. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  128069. };
  128070. static long _vq_quantmap__44cn1_sm_p5_0[] = {
  128071. 15, 13, 11, 9, 7, 5, 3, 1,
  128072. 0, 2, 4, 6, 8, 10, 12, 14,
  128073. 16,
  128074. };
  128075. static encode_aux_threshmatch _vq_auxt__44cn1_sm_p5_0 = {
  128076. _vq_quantthresh__44cn1_sm_p5_0,
  128077. _vq_quantmap__44cn1_sm_p5_0,
  128078. 17,
  128079. 17
  128080. };
  128081. static static_codebook _44cn1_sm_p5_0 = {
  128082. 2, 289,
  128083. _vq_lengthlist__44cn1_sm_p5_0,
  128084. 1, -529530880, 1611661312, 5, 0,
  128085. _vq_quantlist__44cn1_sm_p5_0,
  128086. NULL,
  128087. &_vq_auxt__44cn1_sm_p5_0,
  128088. NULL,
  128089. 0
  128090. };
  128091. static long _vq_quantlist__44cn1_sm_p6_0[] = {
  128092. 1,
  128093. 0,
  128094. 2,
  128095. };
  128096. static long _vq_lengthlist__44cn1_sm_p6_0[] = {
  128097. 1, 4, 4, 7, 6, 6, 7, 6, 6, 4, 7, 6,10, 9, 9,11,
  128098. 9, 9, 4, 6, 7,10, 9, 9,11, 9, 9, 7,10,10,10,11,
  128099. 11,11,11,10, 6, 9, 9,11,10,10,11,10,10, 6, 9, 9,
  128100. 11,10,11,11,10,10, 7,11,11,11,11,11,12,11,11, 7,
  128101. 9, 9,11,10,10,12,10,10, 7, 9, 9,11,10,10,11,10,
  128102. 10,
  128103. };
  128104. static float _vq_quantthresh__44cn1_sm_p6_0[] = {
  128105. -5.5, 5.5,
  128106. };
  128107. static long _vq_quantmap__44cn1_sm_p6_0[] = {
  128108. 1, 0, 2,
  128109. };
  128110. static encode_aux_threshmatch _vq_auxt__44cn1_sm_p6_0 = {
  128111. _vq_quantthresh__44cn1_sm_p6_0,
  128112. _vq_quantmap__44cn1_sm_p6_0,
  128113. 3,
  128114. 3
  128115. };
  128116. static static_codebook _44cn1_sm_p6_0 = {
  128117. 4, 81,
  128118. _vq_lengthlist__44cn1_sm_p6_0,
  128119. 1, -529137664, 1618345984, 2, 0,
  128120. _vq_quantlist__44cn1_sm_p6_0,
  128121. NULL,
  128122. &_vq_auxt__44cn1_sm_p6_0,
  128123. NULL,
  128124. 0
  128125. };
  128126. static long _vq_quantlist__44cn1_sm_p6_1[] = {
  128127. 5,
  128128. 4,
  128129. 6,
  128130. 3,
  128131. 7,
  128132. 2,
  128133. 8,
  128134. 1,
  128135. 9,
  128136. 0,
  128137. 10,
  128138. };
  128139. static long _vq_lengthlist__44cn1_sm_p6_1[] = {
  128140. 2, 4, 4, 5, 5, 7, 7, 7, 7, 8, 8,10, 5, 5, 6, 6,
  128141. 7, 7, 8, 8, 8, 8,10, 5, 5, 6, 6, 7, 7, 8, 8, 8,
  128142. 8,10, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8,10,10,10, 7,
  128143. 7, 7, 7, 8, 8, 8, 8,10,10,10, 8, 8, 8, 8, 8, 8,
  128144. 8, 8,10,10,10, 8, 8, 8, 8, 8, 8, 8, 8,10,10,10,
  128145. 8, 8, 8, 8, 8, 8, 9, 9,10,10,10,10,10, 8, 8, 8,
  128146. 8, 9, 9,10,10,10,10,10, 9, 9, 9, 9, 8, 9,10,10,
  128147. 10,10,10, 8, 9, 8, 8, 9, 8,
  128148. };
  128149. static float _vq_quantthresh__44cn1_sm_p6_1[] = {
  128150. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  128151. 3.5, 4.5,
  128152. };
  128153. static long _vq_quantmap__44cn1_sm_p6_1[] = {
  128154. 9, 7, 5, 3, 1, 0, 2, 4,
  128155. 6, 8, 10,
  128156. };
  128157. static encode_aux_threshmatch _vq_auxt__44cn1_sm_p6_1 = {
  128158. _vq_quantthresh__44cn1_sm_p6_1,
  128159. _vq_quantmap__44cn1_sm_p6_1,
  128160. 11,
  128161. 11
  128162. };
  128163. static static_codebook _44cn1_sm_p6_1 = {
  128164. 2, 121,
  128165. _vq_lengthlist__44cn1_sm_p6_1,
  128166. 1, -531365888, 1611661312, 4, 0,
  128167. _vq_quantlist__44cn1_sm_p6_1,
  128168. NULL,
  128169. &_vq_auxt__44cn1_sm_p6_1,
  128170. NULL,
  128171. 0
  128172. };
  128173. static long _vq_quantlist__44cn1_sm_p7_0[] = {
  128174. 6,
  128175. 5,
  128176. 7,
  128177. 4,
  128178. 8,
  128179. 3,
  128180. 9,
  128181. 2,
  128182. 10,
  128183. 1,
  128184. 11,
  128185. 0,
  128186. 12,
  128187. };
  128188. static long _vq_lengthlist__44cn1_sm_p7_0[] = {
  128189. 1, 4, 4, 6, 6, 7, 7, 7, 7, 9, 9,10,10, 7, 5, 5,
  128190. 7, 7, 8, 8, 8, 8,10, 9,11,10, 7, 5, 5, 7, 7, 8,
  128191. 8, 8, 8, 9,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  128192. 10,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,
  128193. 11, 0,12,12, 9, 9, 9,10,10,10,11,11,12,12, 0,13,
  128194. 13, 9, 9, 9, 9,10,10,11,11,12,12, 0, 0, 0,10,10,
  128195. 10,10,11,11,12,12,12,13, 0, 0, 0,10,10,10,10,11,
  128196. 11,12,12,12,12, 0, 0, 0,14,14,11,11,11,11,12,13,
  128197. 13,13, 0, 0, 0,14,14,11,10,11,11,12,12,13,13, 0,
  128198. 0, 0, 0, 0,12,12,12,12,13,13,13,14, 0, 0, 0, 0,
  128199. 0,13,12,12,12,13,13,13,14,
  128200. };
  128201. static float _vq_quantthresh__44cn1_sm_p7_0[] = {
  128202. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  128203. 12.5, 17.5, 22.5, 27.5,
  128204. };
  128205. static long _vq_quantmap__44cn1_sm_p7_0[] = {
  128206. 11, 9, 7, 5, 3, 1, 0, 2,
  128207. 4, 6, 8, 10, 12,
  128208. };
  128209. static encode_aux_threshmatch _vq_auxt__44cn1_sm_p7_0 = {
  128210. _vq_quantthresh__44cn1_sm_p7_0,
  128211. _vq_quantmap__44cn1_sm_p7_0,
  128212. 13,
  128213. 13
  128214. };
  128215. static static_codebook _44cn1_sm_p7_0 = {
  128216. 2, 169,
  128217. _vq_lengthlist__44cn1_sm_p7_0,
  128218. 1, -526516224, 1616117760, 4, 0,
  128219. _vq_quantlist__44cn1_sm_p7_0,
  128220. NULL,
  128221. &_vq_auxt__44cn1_sm_p7_0,
  128222. NULL,
  128223. 0
  128224. };
  128225. static long _vq_quantlist__44cn1_sm_p7_1[] = {
  128226. 2,
  128227. 1,
  128228. 3,
  128229. 0,
  128230. 4,
  128231. };
  128232. static long _vq_lengthlist__44cn1_sm_p7_1[] = {
  128233. 2, 4, 4, 4, 5, 6, 5, 5, 5, 5, 6, 5, 5, 5, 5, 6,
  128234. 5, 5, 5, 5, 6, 6, 6, 5, 5,
  128235. };
  128236. static float _vq_quantthresh__44cn1_sm_p7_1[] = {
  128237. -1.5, -0.5, 0.5, 1.5,
  128238. };
  128239. static long _vq_quantmap__44cn1_sm_p7_1[] = {
  128240. 3, 1, 0, 2, 4,
  128241. };
  128242. static encode_aux_threshmatch _vq_auxt__44cn1_sm_p7_1 = {
  128243. _vq_quantthresh__44cn1_sm_p7_1,
  128244. _vq_quantmap__44cn1_sm_p7_1,
  128245. 5,
  128246. 5
  128247. };
  128248. static static_codebook _44cn1_sm_p7_1 = {
  128249. 2, 25,
  128250. _vq_lengthlist__44cn1_sm_p7_1,
  128251. 1, -533725184, 1611661312, 3, 0,
  128252. _vq_quantlist__44cn1_sm_p7_1,
  128253. NULL,
  128254. &_vq_auxt__44cn1_sm_p7_1,
  128255. NULL,
  128256. 0
  128257. };
  128258. static long _vq_quantlist__44cn1_sm_p8_0[] = {
  128259. 4,
  128260. 3,
  128261. 5,
  128262. 2,
  128263. 6,
  128264. 1,
  128265. 7,
  128266. 0,
  128267. 8,
  128268. };
  128269. static long _vq_lengthlist__44cn1_sm_p8_0[] = {
  128270. 1, 4, 4,12,11,13,13,14,14, 4, 7, 7,11,13,14,14,
  128271. 14,14, 3, 8, 3,14,14,14,14,14,14,14,10,12,14,14,
  128272. 14,14,14,14,14,14, 5,14, 8,14,14,14,14,14,12,14,
  128273. 13,14,14,14,14,14,14,14,13,14,10,14,14,14,14,14,
  128274. 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,
  128275. 14,
  128276. };
  128277. static float _vq_quantthresh__44cn1_sm_p8_0[] = {
  128278. -773.5, -552.5, -331.5, -110.5, 110.5, 331.5, 552.5, 773.5,
  128279. };
  128280. static long _vq_quantmap__44cn1_sm_p8_0[] = {
  128281. 7, 5, 3, 1, 0, 2, 4, 6,
  128282. 8,
  128283. };
  128284. static encode_aux_threshmatch _vq_auxt__44cn1_sm_p8_0 = {
  128285. _vq_quantthresh__44cn1_sm_p8_0,
  128286. _vq_quantmap__44cn1_sm_p8_0,
  128287. 9,
  128288. 9
  128289. };
  128290. static static_codebook _44cn1_sm_p8_0 = {
  128291. 2, 81,
  128292. _vq_lengthlist__44cn1_sm_p8_0,
  128293. 1, -516186112, 1627103232, 4, 0,
  128294. _vq_quantlist__44cn1_sm_p8_0,
  128295. NULL,
  128296. &_vq_auxt__44cn1_sm_p8_0,
  128297. NULL,
  128298. 0
  128299. };
  128300. static long _vq_quantlist__44cn1_sm_p8_1[] = {
  128301. 6,
  128302. 5,
  128303. 7,
  128304. 4,
  128305. 8,
  128306. 3,
  128307. 9,
  128308. 2,
  128309. 10,
  128310. 1,
  128311. 11,
  128312. 0,
  128313. 12,
  128314. };
  128315. static long _vq_lengthlist__44cn1_sm_p8_1[] = {
  128316. 1, 4, 4, 6, 6, 8, 8, 9, 9,10,11,11,11, 6, 5, 5,
  128317. 7, 7, 8, 8,10,10,10,11,11,11, 6, 5, 5, 7, 7, 8,
  128318. 8,10,10,11,12,12,12,14, 7, 7, 7, 8, 9, 9,11,11,
  128319. 11,12,11,12,17, 7, 7, 8, 7, 9, 9,11,11,12,12,12,
  128320. 12,14,11,11, 8, 8,10,10,11,12,12,13,11,12,14,11,
  128321. 11, 8, 8,10,10,11,12,12,13,13,12,14,15,14,10,10,
  128322. 10,10,11,12,12,12,12,11,14,13,16,10,10,10, 9,12,
  128323. 11,12,12,13,14,14,15,14,14,13,10,10,11,11,12,11,
  128324. 13,11,14,12,15,13,14,11,10,12,10,12,12,13,13,13,
  128325. 13,14,15,15,12,12,11,11,12,11,13,12,14,14,14,14,
  128326. 17,12,12,11,10,13,11,13,13,
  128327. };
  128328. static float _vq_quantthresh__44cn1_sm_p8_1[] = {
  128329. -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5, 25.5,
  128330. 42.5, 59.5, 76.5, 93.5,
  128331. };
  128332. static long _vq_quantmap__44cn1_sm_p8_1[] = {
  128333. 11, 9, 7, 5, 3, 1, 0, 2,
  128334. 4, 6, 8, 10, 12,
  128335. };
  128336. static encode_aux_threshmatch _vq_auxt__44cn1_sm_p8_1 = {
  128337. _vq_quantthresh__44cn1_sm_p8_1,
  128338. _vq_quantmap__44cn1_sm_p8_1,
  128339. 13,
  128340. 13
  128341. };
  128342. static static_codebook _44cn1_sm_p8_1 = {
  128343. 2, 169,
  128344. _vq_lengthlist__44cn1_sm_p8_1,
  128345. 1, -522616832, 1620115456, 4, 0,
  128346. _vq_quantlist__44cn1_sm_p8_1,
  128347. NULL,
  128348. &_vq_auxt__44cn1_sm_p8_1,
  128349. NULL,
  128350. 0
  128351. };
  128352. static long _vq_quantlist__44cn1_sm_p8_2[] = {
  128353. 8,
  128354. 7,
  128355. 9,
  128356. 6,
  128357. 10,
  128358. 5,
  128359. 11,
  128360. 4,
  128361. 12,
  128362. 3,
  128363. 13,
  128364. 2,
  128365. 14,
  128366. 1,
  128367. 15,
  128368. 0,
  128369. 16,
  128370. };
  128371. static long _vq_lengthlist__44cn1_sm_p8_2[] = {
  128372. 3, 4, 4, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  128373. 9,10, 6, 6, 6, 6, 7, 7, 8, 8, 8, 9, 9, 9, 9, 9,
  128374. 9, 9,10, 6, 6, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9, 9,
  128375. 9, 9, 9,10, 7, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9,
  128376. 9, 9, 9, 9,10,10,10, 7, 7, 7, 8, 8, 8, 9, 9, 9,
  128377. 9, 9, 9, 9, 9,10,10,10, 8, 8, 8, 8, 8, 8, 9, 9,
  128378. 9, 9, 9, 9, 9, 9,10,10,10, 8, 8, 8, 8, 8, 8, 9,
  128379. 9, 9, 9, 9, 9, 9, 9,11,10,11, 8, 8, 8, 8, 8, 8,
  128380. 9, 9, 9, 9, 9, 9, 9, 9,10,10,10,11,11, 8, 8, 8,
  128381. 8, 9, 9, 9, 9, 9, 9, 9, 9,11,10,11,11,11, 9, 9,
  128382. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,11,10,11,11, 9,
  128383. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,11,11,10,11,11,
  128384. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,11,10,11,11,
  128385. 11,11,11, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,11,11,
  128386. 11,11,11,11, 9,10,10,10, 9, 9, 9, 9, 9, 9,11,10,
  128387. 11,11,11,11,11, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,11,
  128388. 11,11,11,11,11,11,10,10, 9, 9, 9, 9, 9, 9, 9, 9,
  128389. 10,11,11,11,11,11,11,11,11, 9, 9, 9, 9, 9, 9, 9,
  128390. 9,
  128391. };
  128392. static float _vq_quantthresh__44cn1_sm_p8_2[] = {
  128393. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  128394. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  128395. };
  128396. static long _vq_quantmap__44cn1_sm_p8_2[] = {
  128397. 15, 13, 11, 9, 7, 5, 3, 1,
  128398. 0, 2, 4, 6, 8, 10, 12, 14,
  128399. 16,
  128400. };
  128401. static encode_aux_threshmatch _vq_auxt__44cn1_sm_p8_2 = {
  128402. _vq_quantthresh__44cn1_sm_p8_2,
  128403. _vq_quantmap__44cn1_sm_p8_2,
  128404. 17,
  128405. 17
  128406. };
  128407. static static_codebook _44cn1_sm_p8_2 = {
  128408. 2, 289,
  128409. _vq_lengthlist__44cn1_sm_p8_2,
  128410. 1, -529530880, 1611661312, 5, 0,
  128411. _vq_quantlist__44cn1_sm_p8_2,
  128412. NULL,
  128413. &_vq_auxt__44cn1_sm_p8_2,
  128414. NULL,
  128415. 0
  128416. };
  128417. static long _huff_lengthlist__44cn1_sm_short[] = {
  128418. 5, 6,12,14,12,14,16,17,18, 4, 2, 5,11, 7,10,12,
  128419. 14,15, 9, 4, 5,11, 7,10,13,15,18,15, 6, 7, 5, 6,
  128420. 8,11,13,16,11, 5, 6, 5, 5, 6, 9,13,15,12, 5, 7,
  128421. 6, 5, 6, 9,12,14,12, 6, 7, 8, 6, 7, 9,12,13,14,
  128422. 8, 8, 7, 5, 5, 8,10,12,16, 9, 9, 8, 6, 6, 7, 9,
  128423. 9,
  128424. };
  128425. static static_codebook _huff_book__44cn1_sm_short = {
  128426. 2, 81,
  128427. _huff_lengthlist__44cn1_sm_short,
  128428. 0, 0, 0, 0, 0,
  128429. NULL,
  128430. NULL,
  128431. NULL,
  128432. NULL,
  128433. 0
  128434. };
  128435. /********* End of inlined file: res_books_stereo.h *********/
  128436. static vorbis_info_residue0 _residue_44_low={
  128437. 0,-1, -1, 9,-1,
  128438. {0},
  128439. {-1},
  128440. { .5, 1.5, 2.5, 2.5, 4.5, 8.5, 16.5, 32.5},
  128441. { .5, .5, .5, 999., 4.5, 8.5, 16.5, 32.5},
  128442. };
  128443. static vorbis_info_residue0 _residue_44_mid={
  128444. 0,-1, -1, 10,-1,
  128445. {0},
  128446. {-1},
  128447. { .5, 1.5, 1.5, 2.5, 2.5, 4.5, 8.5, 16.5, 32.5},
  128448. { .5, .5, 999., .5, 999., 4.5, 8.5, 16.5, 32.5},
  128449. };
  128450. static vorbis_info_residue0 _residue_44_high={
  128451. 0,-1, -1, 10,-1,
  128452. {0},
  128453. {-1},
  128454. { .5, 1.5, 2.5, 4.5, 8.5, 16.5, 32.5, 71.5,157.5},
  128455. { .5, 1.5, 2.5, 3.5, 4.5, 8.5, 16.5, 71.5,157.5},
  128456. };
  128457. static static_bookblock _resbook_44s_n1={
  128458. {
  128459. {0},{0,0,&_44cn1_s_p1_0},{0,0,&_44cn1_s_p2_0},
  128460. {0,0,&_44cn1_s_p3_0},{0,0,&_44cn1_s_p4_0},{0,0,&_44cn1_s_p5_0},
  128461. {&_44cn1_s_p6_0,&_44cn1_s_p6_1},{&_44cn1_s_p7_0,&_44cn1_s_p7_1},
  128462. {&_44cn1_s_p8_0,&_44cn1_s_p8_1,&_44cn1_s_p8_2}
  128463. }
  128464. };
  128465. static static_bookblock _resbook_44sm_n1={
  128466. {
  128467. {0},{0,0,&_44cn1_sm_p1_0},{0,0,&_44cn1_sm_p2_0},
  128468. {0,0,&_44cn1_sm_p3_0},{0,0,&_44cn1_sm_p4_0},{0,0,&_44cn1_sm_p5_0},
  128469. {&_44cn1_sm_p6_0,&_44cn1_sm_p6_1},{&_44cn1_sm_p7_0,&_44cn1_sm_p7_1},
  128470. {&_44cn1_sm_p8_0,&_44cn1_sm_p8_1,&_44cn1_sm_p8_2}
  128471. }
  128472. };
  128473. static static_bookblock _resbook_44s_0={
  128474. {
  128475. {0},{0,0,&_44c0_s_p1_0},{0,0,&_44c0_s_p2_0},
  128476. {0,0,&_44c0_s_p3_0},{0,0,&_44c0_s_p4_0},{0,0,&_44c0_s_p5_0},
  128477. {&_44c0_s_p6_0,&_44c0_s_p6_1},{&_44c0_s_p7_0,&_44c0_s_p7_1},
  128478. {&_44c0_s_p8_0,&_44c0_s_p8_1,&_44c0_s_p8_2}
  128479. }
  128480. };
  128481. static static_bookblock _resbook_44sm_0={
  128482. {
  128483. {0},{0,0,&_44c0_sm_p1_0},{0,0,&_44c0_sm_p2_0},
  128484. {0,0,&_44c0_sm_p3_0},{0,0,&_44c0_sm_p4_0},{0,0,&_44c0_sm_p5_0},
  128485. {&_44c0_sm_p6_0,&_44c0_sm_p6_1},{&_44c0_sm_p7_0,&_44c0_sm_p7_1},
  128486. {&_44c0_sm_p8_0,&_44c0_sm_p8_1,&_44c0_sm_p8_2}
  128487. }
  128488. };
  128489. static static_bookblock _resbook_44s_1={
  128490. {
  128491. {0},{0,0,&_44c1_s_p1_0},{0,0,&_44c1_s_p2_0},
  128492. {0,0,&_44c1_s_p3_0},{0,0,&_44c1_s_p4_0},{0,0,&_44c1_s_p5_0},
  128493. {&_44c1_s_p6_0,&_44c1_s_p6_1},{&_44c1_s_p7_0,&_44c1_s_p7_1},
  128494. {&_44c1_s_p8_0,&_44c1_s_p8_1,&_44c1_s_p8_2}
  128495. }
  128496. };
  128497. static static_bookblock _resbook_44sm_1={
  128498. {
  128499. {0},{0,0,&_44c1_sm_p1_0},{0,0,&_44c1_sm_p2_0},
  128500. {0,0,&_44c1_sm_p3_0},{0,0,&_44c1_sm_p4_0},{0,0,&_44c1_sm_p5_0},
  128501. {&_44c1_sm_p6_0,&_44c1_sm_p6_1},{&_44c1_sm_p7_0,&_44c1_sm_p7_1},
  128502. {&_44c1_sm_p8_0,&_44c1_sm_p8_1,&_44c1_sm_p8_2}
  128503. }
  128504. };
  128505. static static_bookblock _resbook_44s_2={
  128506. {
  128507. {0},{0,0,&_44c2_s_p1_0},{0,0,&_44c2_s_p2_0},{0,0,&_44c2_s_p3_0},
  128508. {0,0,&_44c2_s_p4_0},{0,0,&_44c2_s_p5_0},{0,0,&_44c2_s_p6_0},
  128509. {&_44c2_s_p7_0,&_44c2_s_p7_1},{&_44c2_s_p8_0,&_44c2_s_p8_1},
  128510. {&_44c2_s_p9_0,&_44c2_s_p9_1,&_44c2_s_p9_2}
  128511. }
  128512. };
  128513. static static_bookblock _resbook_44s_3={
  128514. {
  128515. {0},{0,0,&_44c3_s_p1_0},{0,0,&_44c3_s_p2_0},{0,0,&_44c3_s_p3_0},
  128516. {0,0,&_44c3_s_p4_0},{0,0,&_44c3_s_p5_0},{0,0,&_44c3_s_p6_0},
  128517. {&_44c3_s_p7_0,&_44c3_s_p7_1},{&_44c3_s_p8_0,&_44c3_s_p8_1},
  128518. {&_44c3_s_p9_0,&_44c3_s_p9_1,&_44c3_s_p9_2}
  128519. }
  128520. };
  128521. static static_bookblock _resbook_44s_4={
  128522. {
  128523. {0},{0,0,&_44c4_s_p1_0},{0,0,&_44c4_s_p2_0},{0,0,&_44c4_s_p3_0},
  128524. {0,0,&_44c4_s_p4_0},{0,0,&_44c4_s_p5_0},{0,0,&_44c4_s_p6_0},
  128525. {&_44c4_s_p7_0,&_44c4_s_p7_1},{&_44c4_s_p8_0,&_44c4_s_p8_1},
  128526. {&_44c4_s_p9_0,&_44c4_s_p9_1,&_44c4_s_p9_2}
  128527. }
  128528. };
  128529. static static_bookblock _resbook_44s_5={
  128530. {
  128531. {0},{0,0,&_44c5_s_p1_0},{0,0,&_44c5_s_p2_0},{0,0,&_44c5_s_p3_0},
  128532. {0,0,&_44c5_s_p4_0},{0,0,&_44c5_s_p5_0},{0,0,&_44c5_s_p6_0},
  128533. {&_44c5_s_p7_0,&_44c5_s_p7_1},{&_44c5_s_p8_0,&_44c5_s_p8_1},
  128534. {&_44c5_s_p9_0,&_44c5_s_p9_1,&_44c5_s_p9_2}
  128535. }
  128536. };
  128537. static static_bookblock _resbook_44s_6={
  128538. {
  128539. {0},{0,0,&_44c6_s_p1_0},{0,0,&_44c6_s_p2_0},{0,0,&_44c6_s_p3_0},
  128540. {0,0,&_44c6_s_p4_0},
  128541. {&_44c6_s_p5_0,&_44c6_s_p5_1},
  128542. {&_44c6_s_p6_0,&_44c6_s_p6_1},
  128543. {&_44c6_s_p7_0,&_44c6_s_p7_1},
  128544. {&_44c6_s_p8_0,&_44c6_s_p8_1},
  128545. {&_44c6_s_p9_0,&_44c6_s_p9_1,&_44c6_s_p9_2}
  128546. }
  128547. };
  128548. static static_bookblock _resbook_44s_7={
  128549. {
  128550. {0},{0,0,&_44c7_s_p1_0},{0,0,&_44c7_s_p2_0},{0,0,&_44c7_s_p3_0},
  128551. {0,0,&_44c7_s_p4_0},
  128552. {&_44c7_s_p5_0,&_44c7_s_p5_1},
  128553. {&_44c7_s_p6_0,&_44c7_s_p6_1},
  128554. {&_44c7_s_p7_0,&_44c7_s_p7_1},
  128555. {&_44c7_s_p8_0,&_44c7_s_p8_1},
  128556. {&_44c7_s_p9_0,&_44c7_s_p9_1,&_44c7_s_p9_2}
  128557. }
  128558. };
  128559. static static_bookblock _resbook_44s_8={
  128560. {
  128561. {0},{0,0,&_44c8_s_p1_0},{0,0,&_44c8_s_p2_0},{0,0,&_44c8_s_p3_0},
  128562. {0,0,&_44c8_s_p4_0},
  128563. {&_44c8_s_p5_0,&_44c8_s_p5_1},
  128564. {&_44c8_s_p6_0,&_44c8_s_p6_1},
  128565. {&_44c8_s_p7_0,&_44c8_s_p7_1},
  128566. {&_44c8_s_p8_0,&_44c8_s_p8_1},
  128567. {&_44c8_s_p9_0,&_44c8_s_p9_1,&_44c8_s_p9_2}
  128568. }
  128569. };
  128570. static static_bookblock _resbook_44s_9={
  128571. {
  128572. {0},{0,0,&_44c9_s_p1_0},{0,0,&_44c9_s_p2_0},{0,0,&_44c9_s_p3_0},
  128573. {0,0,&_44c9_s_p4_0},
  128574. {&_44c9_s_p5_0,&_44c9_s_p5_1},
  128575. {&_44c9_s_p6_0,&_44c9_s_p6_1},
  128576. {&_44c9_s_p7_0,&_44c9_s_p7_1},
  128577. {&_44c9_s_p8_0,&_44c9_s_p8_1},
  128578. {&_44c9_s_p9_0,&_44c9_s_p9_1,&_44c9_s_p9_2}
  128579. }
  128580. };
  128581. static vorbis_residue_template _res_44s_n1[]={
  128582. {2,0, &_residue_44_low,
  128583. &_huff_book__44cn1_s_short,&_huff_book__44cn1_sm_short,
  128584. &_resbook_44s_n1,&_resbook_44sm_n1},
  128585. {2,0, &_residue_44_low,
  128586. &_huff_book__44cn1_s_long,&_huff_book__44cn1_sm_long,
  128587. &_resbook_44s_n1,&_resbook_44sm_n1}
  128588. };
  128589. static vorbis_residue_template _res_44s_0[]={
  128590. {2,0, &_residue_44_low,
  128591. &_huff_book__44c0_s_short,&_huff_book__44c0_sm_short,
  128592. &_resbook_44s_0,&_resbook_44sm_0},
  128593. {2,0, &_residue_44_low,
  128594. &_huff_book__44c0_s_long,&_huff_book__44c0_sm_long,
  128595. &_resbook_44s_0,&_resbook_44sm_0}
  128596. };
  128597. static vorbis_residue_template _res_44s_1[]={
  128598. {2,0, &_residue_44_low,
  128599. &_huff_book__44c1_s_short,&_huff_book__44c1_sm_short,
  128600. &_resbook_44s_1,&_resbook_44sm_1},
  128601. {2,0, &_residue_44_low,
  128602. &_huff_book__44c1_s_long,&_huff_book__44c1_sm_long,
  128603. &_resbook_44s_1,&_resbook_44sm_1}
  128604. };
  128605. static vorbis_residue_template _res_44s_2[]={
  128606. {2,0, &_residue_44_mid,
  128607. &_huff_book__44c2_s_short,&_huff_book__44c2_s_short,
  128608. &_resbook_44s_2,&_resbook_44s_2},
  128609. {2,0, &_residue_44_mid,
  128610. &_huff_book__44c2_s_long,&_huff_book__44c2_s_long,
  128611. &_resbook_44s_2,&_resbook_44s_2}
  128612. };
  128613. static vorbis_residue_template _res_44s_3[]={
  128614. {2,0, &_residue_44_mid,
  128615. &_huff_book__44c3_s_short,&_huff_book__44c3_s_short,
  128616. &_resbook_44s_3,&_resbook_44s_3},
  128617. {2,0, &_residue_44_mid,
  128618. &_huff_book__44c3_s_long,&_huff_book__44c3_s_long,
  128619. &_resbook_44s_3,&_resbook_44s_3}
  128620. };
  128621. static vorbis_residue_template _res_44s_4[]={
  128622. {2,0, &_residue_44_mid,
  128623. &_huff_book__44c4_s_short,&_huff_book__44c4_s_short,
  128624. &_resbook_44s_4,&_resbook_44s_4},
  128625. {2,0, &_residue_44_mid,
  128626. &_huff_book__44c4_s_long,&_huff_book__44c4_s_long,
  128627. &_resbook_44s_4,&_resbook_44s_4}
  128628. };
  128629. static vorbis_residue_template _res_44s_5[]={
  128630. {2,0, &_residue_44_mid,
  128631. &_huff_book__44c5_s_short,&_huff_book__44c5_s_short,
  128632. &_resbook_44s_5,&_resbook_44s_5},
  128633. {2,0, &_residue_44_mid,
  128634. &_huff_book__44c5_s_long,&_huff_book__44c5_s_long,
  128635. &_resbook_44s_5,&_resbook_44s_5}
  128636. };
  128637. static vorbis_residue_template _res_44s_6[]={
  128638. {2,0, &_residue_44_high,
  128639. &_huff_book__44c6_s_short,&_huff_book__44c6_s_short,
  128640. &_resbook_44s_6,&_resbook_44s_6},
  128641. {2,0, &_residue_44_high,
  128642. &_huff_book__44c6_s_long,&_huff_book__44c6_s_long,
  128643. &_resbook_44s_6,&_resbook_44s_6}
  128644. };
  128645. static vorbis_residue_template _res_44s_7[]={
  128646. {2,0, &_residue_44_high,
  128647. &_huff_book__44c7_s_short,&_huff_book__44c7_s_short,
  128648. &_resbook_44s_7,&_resbook_44s_7},
  128649. {2,0, &_residue_44_high,
  128650. &_huff_book__44c7_s_long,&_huff_book__44c7_s_long,
  128651. &_resbook_44s_7,&_resbook_44s_7}
  128652. };
  128653. static vorbis_residue_template _res_44s_8[]={
  128654. {2,0, &_residue_44_high,
  128655. &_huff_book__44c8_s_short,&_huff_book__44c8_s_short,
  128656. &_resbook_44s_8,&_resbook_44s_8},
  128657. {2,0, &_residue_44_high,
  128658. &_huff_book__44c8_s_long,&_huff_book__44c8_s_long,
  128659. &_resbook_44s_8,&_resbook_44s_8}
  128660. };
  128661. static vorbis_residue_template _res_44s_9[]={
  128662. {2,0, &_residue_44_high,
  128663. &_huff_book__44c9_s_short,&_huff_book__44c9_s_short,
  128664. &_resbook_44s_9,&_resbook_44s_9},
  128665. {2,0, &_residue_44_high,
  128666. &_huff_book__44c9_s_long,&_huff_book__44c9_s_long,
  128667. &_resbook_44s_9,&_resbook_44s_9}
  128668. };
  128669. static vorbis_mapping_template _mapres_template_44_stereo[]={
  128670. { _map_nominal, _res_44s_n1 }, /* -1 */
  128671. { _map_nominal, _res_44s_0 }, /* 0 */
  128672. { _map_nominal, _res_44s_1 }, /* 1 */
  128673. { _map_nominal, _res_44s_2 }, /* 2 */
  128674. { _map_nominal, _res_44s_3 }, /* 3 */
  128675. { _map_nominal, _res_44s_4 }, /* 4 */
  128676. { _map_nominal, _res_44s_5 }, /* 5 */
  128677. { _map_nominal, _res_44s_6 }, /* 6 */
  128678. { _map_nominal, _res_44s_7 }, /* 7 */
  128679. { _map_nominal, _res_44s_8 }, /* 8 */
  128680. { _map_nominal, _res_44s_9 }, /* 9 */
  128681. };
  128682. /********* End of inlined file: residue_44.h *********/
  128683. /********* Start of inlined file: psych_44.h *********/
  128684. static vorbis_info_psy_global _psy_global_44[5]={
  128685. {8, /* lines per eighth octave */
  128686. {20.f,14.f,12.f,12.f,12.f,12.f,12.f},
  128687. {-60.f,-30.f,-40.f,-40.f,-40.f,-40.f,-40.f}, 2,-75.f,
  128688. -6.f,
  128689. {99.},{{99.},{99.}},{0},{0},{{0.},{0.}}
  128690. },
  128691. {8, /* lines per eighth octave */
  128692. {14.f,10.f,10.f,10.f,10.f,10.f,10.f},
  128693. {-40.f,-30.f,-25.f,-25.f,-25.f,-25.f,-25.f}, 2,-80.f,
  128694. -6.f,
  128695. {99.},{{99.},{99.}},{0},{0},{{0.},{0.}}
  128696. },
  128697. {8, /* lines per eighth octave */
  128698. {12.f,10.f,10.f,10.f,10.f,10.f,10.f},
  128699. {-20.f,-20.f,-15.f,-15.f,-15.f,-15.f,-15.f}, 0,-80.f,
  128700. -6.f,
  128701. {99.},{{99.},{99.}},{0},{0},{{0.},{0.}}
  128702. },
  128703. {8, /* lines per eighth octave */
  128704. {10.f,8.f,8.f,8.f,8.f,8.f,8.f},
  128705. {-20.f,-15.f,-12.f,-12.f,-12.f,-12.f,-12.f}, 0,-80.f,
  128706. -6.f,
  128707. {99.},{{99.},{99.}},{0},{0},{{0.},{0.}}
  128708. },
  128709. {8, /* lines per eighth octave */
  128710. {10.f,6.f,6.f,6.f,6.f,6.f,6.f},
  128711. {-15.f,-15.f,-12.f,-12.f,-12.f,-12.f,-12.f}, 0,-85.f,
  128712. -6.f,
  128713. {99.},{{99.},{99.}},{0},{0},{{0.},{0.}}
  128714. },
  128715. };
  128716. static compandblock _psy_compand_44[6]={
  128717. {{
  128718. 0, 1, 2, 3, 4, 5, 6, 7, /* 7dB */
  128719. 8, 9,10,11,12,13,14, 15, /* 15dB */
  128720. 16,17,18,19,20,21,22, 23, /* 23dB */
  128721. 24,25,26,27,28,29,30, 31, /* 31dB */
  128722. 32,33,34,35,36,37,38, 39, /* 39dB */
  128723. }},
  128724. {{
  128725. 0, 1, 2, 3, 4, 5, 6, 6, /* 7dB */
  128726. 7, 7, 7, 7, 6, 6, 6, 7, /* 15dB */
  128727. 7, 8, 9,10,11,12,13, 14, /* 23dB */
  128728. 15,16,17,17,17,18,18, 19, /* 31dB */
  128729. 19,19,20,21,22,23,24, 25, /* 39dB */
  128730. }},
  128731. {{
  128732. 0, 1, 2, 3, 4, 5, 5, 5, /* 7dB */
  128733. 6, 6, 6, 5, 4, 4, 4, 4, /* 15dB */
  128734. 4, 4, 5, 5, 5, 6, 6, 6, /* 23dB */
  128735. 7, 7, 7, 8, 8, 8, 9, 10, /* 31dB */
  128736. 11,12,13,14,15,16,17, 18, /* 39dB */
  128737. }},
  128738. {{
  128739. 0, 1, 2, 3, 4, 5, 6, 7, /* 7dB */
  128740. 8, 9,10,11,12,13,14, 15, /* 15dB */
  128741. 16,17,18,19,20,21,22, 23, /* 23dB */
  128742. 24,25,26,27,28,29,30, 31, /* 31dB */
  128743. 32,33,34,35,36,37,38, 39, /* 39dB */
  128744. }},
  128745. {{
  128746. 0, 1, 2, 3, 4, 5, 6, 7, /* 7dB */
  128747. 8, 9,10,11,12,12,13, 13, /* 15dB */
  128748. 13,14,14,14,15,15,15, 15, /* 23dB */
  128749. 16,16,17,17,17,18,18, 19, /* 31dB */
  128750. 19,19,20,21,22,23,24, 25, /* 39dB */
  128751. }},
  128752. {{
  128753. 0, 1, 2, 3, 4, 5, 6, 7, /* 7dB */
  128754. 8, 8, 7, 6, 5, 4, 4, 4, /* 15dB */
  128755. 4, 4, 5, 5, 5, 6, 6, 6, /* 23dB */
  128756. 7, 7, 7, 8, 8, 8, 9, 10, /* 31dB */
  128757. 11,12,13,14,15,16,17, 18, /* 39dB */
  128758. }}
  128759. };
  128760. static vp_adjblock _vp_tonemask_adj_longblock[12]={
  128761. {{ -3, -8,-13,-15,-10,-10,-10,-10,-10,-10,-10, 0, 0, 0, 0, 0, 0}}, /* -1 */
  128762. {{ -4,-10,-14,-16,-15,-14,-13,-12,-12,-12,-11, -1, -1, -1, -1, -1, 0}}, /* 0 */
  128763. {{ -6,-12,-14,-16,-15,-15,-14,-13,-13,-12,-12, -2, -2, -1, -1, -1, 0}}, /* 1 */
  128764. {{-12,-13,-14,-16,-16,-16,-15,-14,-13,-12,-12, -6, -3, -1, -1, -1, 0}}, /* 2 */
  128765. {{-15,-15,-15,-16,-16,-16,-16,-14,-13,-13,-13,-10, -4, -2, -1, -1, 0}}, /* 3 */
  128766. /* 4 */
  128767. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-13,-11, -7 -3, -1, -1 , 0}}, /* 4 */
  128768. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-13,-11, -7 -3, -1, -1 , 0}}, /* 5 */
  128769. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-14,-12, -8, -4, -2, -2, 0}}, /* 6 */
  128770. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-14,-12, -9, -4, -2, -2, 0}}, /* 7 */
  128771. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-14,-12, -9, -4, -2, -2, 0}}, /* 8 */
  128772. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-14,-12, -9, -4, -2, -2, 0}}, /* 9 */
  128773. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-14,-12, -9, -4, -2, -2, 0}}, /* 10 */
  128774. };
  128775. static vp_adjblock _vp_tonemask_adj_otherblock[12]={
  128776. {{ -3, -8,-13,-15,-10,-10, -9, -9, -9, -9, -9, 1, 1, 1, 1, 1, 1}}, /* -1 */
  128777. {{ -4,-10,-14,-16,-14,-13,-12,-12,-11,-11,-10, 0, 0, 0, 0, 0, 0}}, /* 0 */
  128778. {{ -6,-12,-14,-16,-15,-15,-14,-13,-13,-12,-12, -2, -2, -1, 0, 0, 0}}, /* 1 */
  128779. {{-12,-13,-14,-16,-16,-16,-15,-14,-13,-12,-12, -5, -2, -1, 0, 0, 0}}, /* 2 */
  128780. {{-15,-15,-15,-16,-16,-16,-16,-14,-13,-13,-13,-10, -4, -2, 0, 0, 0}}, /* 3 */
  128781. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-13,-11, -7 -3, -1, -1 , 0}}, /* 4 */
  128782. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-13,-11, -7 -3, -1, -1 , 0}}, /* 5 */
  128783. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-14,-12, -8, -4, -2, -2, 0}}, /* 6 */
  128784. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-14,-12, -9, -4, -2, -2, 0}}, /* 7 */
  128785. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-14,-12, -9, -4, -2, -2, 0}}, /* 8 */
  128786. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-14,-12, -9, -4, -2, -2, 0}}, /* 9 */
  128787. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-14,-12, -9, -4, -2, -2, 0}}, /* 10 */
  128788. };
  128789. static noise3 _psy_noisebias_trans[12]={
  128790. {{{-10,-10,-10,-10,-10, -4, 0, 0, 4, 8, 8, 8, 8, 10, 12, 14, 20},
  128791. {-30,-30,-30,-30,-26,-20,-16, -8, -6, -6, -2, 2, 2, 3, 6, 6, 15},
  128792. {-30,-30,-30,-30,-30,-24,-20,-14,-10, -6, -8, -8, -6, -6, -6, -4, -2}}},
  128793. {{{-15,-15,-15,-15,-15,-12, -6, -4, 0, 2, 4, 4, 5, 5, 5, 8, 10},
  128794. {-30,-30,-30,-30,-26,-22,-20,-14, -8, -4, 0, 0, 0, 0, 2, 3, 6},
  128795. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -6, -6, -6, -6, -4, -4, -4, -2}}},
  128796. {{{-15,-15,-15,-15,-15,-12,-10, -8, 0, 2, 4, 4, 5, 5, 5, 8, 10},
  128797. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -4, -2, -2, -2, -2, 0, 1, 4},
  128798. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -8, -8, -8, -8, -6, -6, -6, -4}}},
  128799. {{{-15,-15,-15,-15,-15,-12,-10, -8, 0, 2, 2, 2, 4, 4, 5, 6, 10},
  128800. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -4, -3, -3, -3, -2, -1, 0, 3},
  128801. {-30,-30,-30,-30,-26,-22,-20,-14,-10,-10,-10,-10,-10, -8, -8, -7, -4}}},
  128802. {{{-15,-15,-15,-15,-15,-12,-10, -8, 0, 2, 2, 2, 4, 4, 4, 5, 8},
  128803. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -4, -3, -3, -3, -3, -2, 0, 2},
  128804. {-30,-30,-30,-30,-26,-22,-20,-14,-10,-10,-10,-10,-10, -8, -8, -8, -4}}},
  128805. {{{-20,-20,-20,-20,-20,-18,-14, -8, -1, 1, 1, 1, 2, 3, 3, 4, 7},
  128806. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -4, -3, -3, -3, -3, -2, -1, 1},
  128807. {-30,-30,-30,-30,-26,-22,-20,-14,-10,-10,-10,-10,-10, -8, -8, -8, -4}}},
  128808. {{{-24,-24,-24,-24,-20,-18,-14, -8, -1, 1, 1, 1, 2, 3, 3, 4, 7},
  128809. {-32,-32,-32,-32,-28,-24,-22,-16,-12, -6, -4, -4, -4, -4, -3, -1, 0},
  128810. {-34,-34,-34,-34,-30,-24,-24,-18,-14,-12,-12,-12,-12,-10,-10, -9, -5}}},
  128811. {{{-24,-24,-24,-24,-20,-18,-14, -8, -1, 1, 1, 1, 2, 3, 3, 4, 7},
  128812. {-32,-32,-32,-32,-28,-24,-24,-18,-14, -8, -6, -6, -6, -6, -5, -2, 0},
  128813. {-34,-34,-34,-34,-30,-26,-26,-24,-22,-19,-19,-19,-19,-18,-17,-16,-12}}},
  128814. {{{-24,-24,-24,-24,-20,-18,-14, -8, -1, 1, 1, 1, 2, 3, 3, 4, 7},
  128815. {-32,-32,-32,-32,-28,-24,-24,-24,-18,-14,-12,-10,-10,-10, -8, -6, -2},
  128816. {-34,-34,-34,-34,-30,-26,-26,-26,-24,-24,-24,-24,-24,-24,-24,-20,-16}}},
  128817. {{{-24,-24,-24,-24,-22,-20,-15,-10, -8, -2, 0, 0, 0, 1, 2, 3, 7},
  128818. {-36,-36,-36,-36,-30,-30,-30,-24,-20,-16,-16,-16,-16,-14,-12,-10, -7},
  128819. {-36,-36,-36,-36,-34,-30,-28,-26,-24,-30,-30,-30,-30,-30,-30,-24,-20}}},
  128820. {{{-28,-28,-28,-28,-28,-28,-28,-20,-14, -8, -4, -4, -4, -4, -4, -2, 2},
  128821. {-38,-38,-38,-38,-36,-34,-34,-30,-24,-20,-20,-20,-20,-18,-16,-12,-10},
  128822. {-40,-40,-40,-40,-40,-40,-40,-38,-35,-35,-35,-35,-35,-35,-35,-35,-30}}},
  128823. {{{-30,-30,-30,-30,-30,-30,-30,-28,-20,-14,-14,-14,-14,-14,-14,-12,-10},
  128824. {-40,-40,-40,-40,-40,-40,-40,-40,-35,-30,-30,-30,-30,-30,-30,-30,-20},
  128825. {-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40}}},
  128826. };
  128827. static noise3 _psy_noisebias_long[12]={
  128828. {{{-10,-10,-10,-10,-10, -4, 0, 0, 0, 6, 6, 6, 6, 10, 10, 12, 20},
  128829. {-20,-20,-20,-20,-20,-20,-10, -2, 0, 0, 0, 0, 0, 2, 4, 6, 15},
  128830. {-20,-20,-20,-20,-20,-20,-20,-10, -6, -6, -6, -6, -6, -4, -4, -4, -2}}},
  128831. {{{-10,-10,-10,-10,-10,-10, -8, 2, 2, 2, 4, 4, 5, 5, 5, 8, 10},
  128832. {-20,-20,-20,-20,-20,-20,-20,-14, -6, 0, 0, 0, 0, 0, 2, 3, 6},
  128833. {-20,-20,-20,-20,-20,-20,-20,-14, -8, -6, -6, -6, -6, -4, -4, -4, -2}}},
  128834. {{{-10,-10,-10,-10,-10,-10, -8, -4, 0, 2, 4, 4, 5, 5, 5, 8, 10},
  128835. {-20,-20,-20,-20,-20,-20,-20,-14,-10, -4, -2, -2, -2, -2, 0, 1, 4},
  128836. {-20,-20,-20,-20,-20,-20,-20,-14,-10, -8, -8, -8, -8, -6, -6, -6, -4}}},
  128837. {{{-10,-10,-10,-10,-10,-10,-10, -8, 0, 2, 2, 2, 4, 4, 5, 6, 10},
  128838. {-20,-20,-20,-20,-20,-20,-20,-14,-10, -4, -3, -3, -3, -2, -1, 0, 3},
  128839. {-20,-20,-20,-20,-20,-20,-20,-14,-10,-10,-10,-10,-10, -8, -8, -8, -4}}},
  128840. {{{-10,-10,-10,-10,-10,-10,-10, -8, 0, 2, 2, 2, 4, 4, 4, 5, 8},
  128841. {-20,-20,-20,-20,-20,-20,-20,-14,-10, -4, -3, -3, -3, -3, -2, 0, 2},
  128842. {-20,-20,-20,-20,-20,-20,-20,-14,-10,-10,-10,-10,-10, -8, -8, -8, -5}}},
  128843. {{{-15,-15,-15,-15,-15,-15,-15,-10, -4, 1, 1, 1, 2, 3, 3, 4, 7},
  128844. {-20,-20,-20,-20,-20,-20,-20,-14,-10, -4, -3, -3, -3, -3, -2, -1, 1},
  128845. {-20,-20,-20,-20,-20,-20,-20,-14,-10,-10,-10,-10,-10, -8, -8, -8, -7}}},
  128846. {{{-15,-15,-15,-15,-15,-15,-15,-10, -4, 1, 1, 1, 2, 3, 3, 4, 7},
  128847. {-22,-22,-22,-22,-22,-22,-22,-16,-12, -6, -4, -4, -4, -4, -3, -1, 0},
  128848. {-24,-24,-24,-24,-24,-24,-24,-18,-14,-12,-12,-12,-12,-10,-10, -9, -8}}},
  128849. {{{-15,-15,-15,-15,-15,-15,-15,-10, -4, 1, 1, 1, 2, 3, 3, 4, 7},
  128850. {-24,-24,-24,-24,-24,-24,-24,-18,-14, -8, -6, -6, -6, -6, -5, -2, 0},
  128851. {-26,-26,-26,-26,-26,-26,-26,-18,-16,-15,-15,-15,-15,-13,-13,-12,-10}}},
  128852. {{{-15,-15,-15,-15,-15,-15,-15,-10, -4, 1, 1, 1, 2, 3, 3, 4, 7},
  128853. {-24,-24,-24,-24,-24,-24,-24,-18,-14,-10, -8, -8, -8, -8, -6, -4, 0},
  128854. {-26,-26,-26,-26,-26,-26,-26,-22,-20,-19,-19,-19,-19,-18,-17,-16,-12}}},
  128855. {{{-15,-15,-15,-15,-15,-15,-15,-10, -4, 0, 0, 0, 0, 1, 2, 3, 7},
  128856. {-26,-26,-26,-26,-26,-26,-26,-20,-16,-12,-10,-10,-10,-10, -8, -6, -2},
  128857. {-28,-28,-28,-28,-28,-28,-28,-26,-24,-24,-24,-24,-24,-24,-24,-20,-16}}},
  128858. {{{-22,-22,-22,-22,-22,-22,-22,-18,-14, -8, -4, -4, -4, -4, -4, -2, 2},
  128859. {-26,-26,-26,-26,-26,-26,-26,-22,-18,-16,-16,-16,-16,-14,-12,-10, -7},
  128860. {-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-24,-20}}},
  128861. {{{-24,-24,-24,-24,-24,-24,-24,-24,-24,-18,-14,-14,-14,-14,-14,-12,-10},
  128862. {-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-20},
  128863. {-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40}}},
  128864. };
  128865. static noise3 _psy_noisebias_impulse[12]={
  128866. {{{-10,-10,-10,-10,-10, -4, 0, 0, 4, 8, 8, 8, 8, 10, 12, 14, 20},
  128867. {-30,-30,-30,-30,-26,-20,-16, -8, -6, -6, -2, 2, 2, 3, 6, 6, 15},
  128868. {-30,-30,-30,-30,-30,-24,-20,-14,-10, -6, -8, -8, -6, -6, -6, -4, -2}}},
  128869. {{{-10,-10,-10,-10,-10, -4, 0, 0, 4, 4, 8, 8, 8, 10, 12, 14, 20},
  128870. {-30,-30,-30,-30,-26,-22,-20,-14, -6, -2, 0, 0, 0, 0, 2, 3, 6},
  128871. {-30,-30,-30,-30,-30,-24,-20,-14,-10, -6, -8, -8, -6, -6, -6, -4, -2}}},
  128872. {{{-12,-12,-12,-12,-12, -8, -6, -4, 0, 4, 4, 4, 4, 10, 12, 14, 20},
  128873. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -6, -4, -4, -2, -2, -2, -2, 2},
  128874. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -8,-10,-10, -8, -8, -8, -6, -4}}},
  128875. {{{-14,-14,-14,-14,-14,-10, -8, -6, -2, 2, 2, 2, 2, 8, 10, 10, 16},
  128876. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -6, -6, -6, -4, -4, -4, -2, 0},
  128877. {-30,-30,-30,-30,-26,-22,-20,-14,-10,-10,-10,-10,-10,-10,-10, -8, -4}}},
  128878. {{{-14,-14,-14,-14,-14,-10, -8, -6, -2, 2, 2, 2, 2, 6, 8, 8, 14},
  128879. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -6, -6, -6, -4, -4, -4, -2, 0},
  128880. {-30,-30,-30,-30,-26,-22,-20,-14,-10,-10,-10,-10,-10,-10,-10, -8, -4}}},
  128881. {{{-16,-16,-16,-16,-16,-12,-10, -6, -2, 0, 0, 0, 0, 4, 6, 6, 12},
  128882. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -6, -6, -6, -4, -4, -4, -2, 0},
  128883. {-30,-30,-30,-30,-26,-22,-20,-14,-10,-10,-10,-10,-10,-10,-10, -8, -4}}},
  128884. {{{-20,-20,-20,-20,-20,-18,-14,-10, -4, 0, 0, 0, 0, 4, 4, 6, 11},
  128885. {-32,-32,-32,-32,-28,-24,-22,-16,-10, -6, -8, -8, -6, -6, -6, -4, -2},
  128886. {-34,-34,-34,-34,-30,-26,-24,-18,-14,-12,-12,-12,-12,-12,-10, -9, -5}}},
  128887. {{{-20,-20,-20,-20,-20,-18,-14,-10, -4, 0, 0, 0, 0, 4, 4, 6, 11},
  128888. {-34,-34,-34,-34,-30,-30,-30,-24,-16,-16,-16,-16,-16,-16,-14,-14,-12},
  128889. {-36,-36,-36,-36,-36,-34,-28,-24,-20,-20,-20,-20,-20,-20,-20,-18,-16}}},
  128890. {{{-22,-22,-22,-22,-22,-20,-14,-10, -6, 0, 0, 0, 0, 4, 4, 6, 11},
  128891. {-34,-34,-34,-34,-30,-30,-30,-30,-26,-26,-26,-26,-26,-26,-26,-24,-22},
  128892. {-40,-40,-40,-40,-40,-40,-40,-32,-30,-30,-30,-30,-30,-30,-30,-30,-24}}},
  128893. {{{-24,-24,-24,-24,-24,-22,-14,-10, -6, -1, -1, -1, -1, 3, 3, 5, 10},
  128894. {-34,-34,-34,-34,-34,-32,-32,-30,-26,-26,-26,-26,-26,-26,-26,-26,-24},
  128895. {-40,-40,-40,-40,-40,-40,-40,-32,-30,-30,-30,-30,-30,-30,-30,-30,-24}}},
  128896. {{{-28,-28,-28,-28,-28,-28,-28,-20,-14, -8, -4, -4, -4, -4, -4, -2, 2},
  128897. {-36,-36,-36,-36,-34,-32,-32,-30,-26,-26,-26,-26,-26,-26,-26,-26,-26},
  128898. {-40,-40,-40,-40,-40,-40,-40,-32,-30,-30,-30,-30,-30,-30,-30,-24,-20}}},
  128899. {{{-30,-30,-30,-30,-30,-26,-24,-24,-24,-20,-16,-16,-16,-16,-16,-14,-12},
  128900. {-40,-40,-40,-40,-40,-40,-40,-40,-35,-30,-30,-30,-30,-30,-30,-30,-26},
  128901. {-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40}}},
  128902. };
  128903. static noise3 _psy_noisebias_padding[12]={
  128904. {{{-10,-10,-10,-10,-10, -4, 0, 0, 4, 8, 8, 8, 8, 10, 12, 14, 20},
  128905. {-30,-30,-30,-30,-26,-20,-16, -8, -6, -6, -2, 2, 2, 3, 6, 6, 15},
  128906. {-30,-30,-30,-30,-30,-24,-20,-14,-10, -6, -8, -8, -6, -6, -6, -4, -2}}},
  128907. {{{-10,-10,-10,-10,-10, -4, 0, 0, 4, 8, 8, 8, 8, 10, 12, 14, 20},
  128908. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -4, -2, 2, 3, 6, 6, 8, 10},
  128909. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -4, -4, -4, -4, -4, -2, 0, 2}}},
  128910. {{{-12,-12,-12,-12,-12, -8, -6, -4, 0, 4, 4, 4, 4, 10, 12, 14, 20},
  128911. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -4, 0, 0, 0, 2, 2, 4, 8},
  128912. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -6, -6, -6, -6, -6, -4, -2, 0}}},
  128913. {{{-14,-14,-14,-14,-14,-10, -8, -6, -2, 2, 2, 2, 2, 8, 10, 10, 16},
  128914. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -6, -1, -1, -1, 0, 0, 2, 6},
  128915. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -8, -8, -8, -8, -8, -6, -4, -2}}},
  128916. {{{-14,-14,-14,-14,-14,-10, -8, -6, -2, 2, 2, 2, 2, 6, 8, 8, 14},
  128917. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -6, -1, -1, -1, 0, 0, 2, 6},
  128918. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -8, -8, -8, -8, -8, -6, -4, -2}}},
  128919. {{{-16,-16,-16,-16,-16,-12,-10, -6, -2, 0, 0, 0, 0, 4, 6, 6, 12},
  128920. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -6, -1, -1, -1, -1, 0, 2, 6},
  128921. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -8, -8, -8, -8, -8, -6, -4, -2}}},
  128922. {{{-20,-20,-20,-20,-20,-18,-14,-10, -4, 0, 0, 0, 0, 4, 6, 6, 12},
  128923. {-32,-32,-32,-32,-28,-24,-22,-16,-12, -6, -3, -3, -3, -3, -2, 0, 4},
  128924. {-34,-34,-34,-34,-30,-26,-24,-18,-14,-10,-10,-10,-10,-10, -8, -5, -3}}},
  128925. {{{-20,-20,-20,-20,-20,-18,-14,-10, -4, 0, 0, 0, 0, 4, 6, 6, 12},
  128926. {-34,-34,-34,-34,-30,-30,-24,-20,-14, -8, -4, -4, -4, -4, -3, -1, 4},
  128927. {-34,-34,-34,-34,-34,-30,-26,-20,-16,-13,-13,-13,-13,-13,-11, -8, -6}}},
  128928. {{{-20,-20,-20,-20,-20,-18,-14,-10, -4, 0, 0, 0, 0, 4, 6, 6, 12},
  128929. {-34,-34,-34,-34,-30,-30,-30,-24,-16,-10, -8, -6, -6, -6, -5, -3, 1},
  128930. {-34,-34,-34,-34,-32,-32,-28,-22,-18,-16,-16,-16,-16,-16,-14,-12,-10}}},
  128931. {{{-22,-22,-22,-22,-22,-20,-14,-10, -4, 0, 0, 0, 0, 3, 5, 5, 11},
  128932. {-34,-34,-34,-34,-30,-30,-30,-24,-16,-12,-10, -8, -8, -8, -7, -5, -2},
  128933. {-36,-36,-36,-36,-36,-34,-28,-22,-20,-20,-20,-20,-20,-20,-20,-16,-14}}},
  128934. {{{-28,-28,-28,-28,-28,-28,-28,-20,-14, -8, -2, -2, -2, -2, 0, 2, 6},
  128935. {-36,-36,-36,-36,-34,-32,-32,-24,-16,-12,-12,-12,-12,-12,-10, -8, -5},
  128936. {-40,-40,-40,-40,-40,-40,-40,-32,-26,-24,-24,-24,-24,-24,-24,-20,-18}}},
  128937. {{{-30,-30,-30,-30,-30,-26,-24,-24,-24,-20,-12,-12,-12,-12,-12,-10, -8},
  128938. {-40,-40,-40,-40,-40,-40,-40,-40,-35,-30,-25,-25,-25,-25,-25,-25,-15},
  128939. {-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40}}},
  128940. };
  128941. static noiseguard _psy_noiseguards_44[4]={
  128942. {3,3,15},
  128943. {3,3,15},
  128944. {10,10,100},
  128945. {10,10,100},
  128946. };
  128947. static int _psy_tone_suppress[12]={
  128948. -20,-20,-20,-20,-20,-24,-30,-40,-40,-45,-45,-45,
  128949. };
  128950. static int _psy_tone_0dB[12]={
  128951. 90,90,95,95,95,95,105,105,105,105,105,105,
  128952. };
  128953. static int _psy_noise_suppress[12]={
  128954. -20,-20,-24,-24,-24,-24,-30,-40,-40,-45,-45,-45,
  128955. };
  128956. static vorbis_info_psy _psy_info_template={
  128957. -1,
  128958. -140.,-140.,
  128959. {0.f,0.f,0.f}, 0.,0., -40.f, {0.},
  128960. 1, -0.f, .5f, .5f, 0,0,0,
  128961. {{-1},{-1},{-1}},{-1},105.f,
  128962. 0,0,-1,-1,0.,
  128963. };
  128964. static int _psy_ath_floater[12]={
  128965. -100,-100,-100,-100,-100,-100,-105,-105,-105,-105,-110,-120,
  128966. };
  128967. static int _psy_ath_abs[12]={
  128968. -130,-130,-130,-130,-140,-140,-140,-140,-140,-140,-140,-150,
  128969. };
  128970. static adj_stereo _psy_stereo_modes_44[12]={
  128971. {{ 4, 4, 4, 4, 4, 4, 4, 3, 2, 2, 1, 0, 0, 0, 0},
  128972. { 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 5, 4, 3},
  128973. { 1, 2, 3, 4, 4, 4, 4, 4, 4, 5, 6, 7, 8, 8, 8},
  128974. { 12,12.5, 13,13.5, 14,14.5, 15, 99, 99, 99, 99, 99, 99, 99, 99}},
  128975. {{ 4, 4, 4, 4, 4, 4, 4, 3, 2, 1, 0, 0, 0, 0, 0},
  128976. { 8, 8, 8, 8, 6, 6, 5, 5, 5, 5, 5, 5, 5, 4, 3},
  128977. { 1, 2, 3, 4, 4, 5, 6, 6, 6, 6, 6, 8, 8, 8, 8},
  128978. { 12,12.5, 13,13.5, 14,14.5, 15, 99, 99, 99, 99, 99, 99, 99, 99}},
  128979. {{ 3, 3, 3, 3, 3, 3, 3, 3, 2, 1, 0, 0, 0, 0, 0},
  128980. { 8, 8, 8, 8, 6, 6, 5, 5, 5, 5, 5, 5, 5, 4, 3},
  128981. { 1, 2, 3, 4, 4, 5, 6, 6, 6, 6, 6, 8, 8, 8, 8},
  128982. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  128983. {{ 3, 3, 3, 3, 3, 3, 3, 2, 1, 1, 0, 0, 0, 0, 0},
  128984. { 8, 8, 6, 6, 5, 5, 4, 4, 4, 4, 4, 4, 3, 2, 1},
  128985. { 3, 4, 4, 5, 5, 6, 6, 6, 6, 6, 6, 8, 8, 8, 8},
  128986. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  128987. {{ 2, 2, 2, 2, 2, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0},
  128988. { 5, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 3, 2, 1},
  128989. { 4, 4, 5, 6, 6, 6, 6, 6, 8, 8, 10, 10, 10, 10, 10},
  128990. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  128991. {{ 2, 2, 2, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  128992. { 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 3, 3, 2, 1, 0},
  128993. { 6, 6, 6, 8, 8, 8, 8, 8, 8, 8, 10, 10, 10, 10, 10},
  128994. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  128995. {{ 2, 2, 2, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  128996. { 3, 3, 3, 3, 3, 2, 2, 2, 2, 2, 2, 0, 0, 0, 0},
  128997. { 6, 7, 8, 8, 8, 10, 10, 12, 12, 12, 12, 12, 12, 12, 12},
  128998. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  128999. {{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  129000. { 3, 3, 3, 2, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  129001. { 8, 8, 8, 10, 10, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12},
  129002. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  129003. {{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  129004. { 3, 3, 3, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  129005. { 8, 8, 10, 10, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12},
  129006. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  129007. {{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  129008. { 2, 2, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  129009. { 8, 10, 10, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12},
  129010. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  129011. {{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  129012. { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  129013. { 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4},
  129014. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  129015. {{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  129016. { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  129017. { 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4},
  129018. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  129019. };
  129020. static att3 _psy_tone_masteratt_44[12]={
  129021. {{ 35, 21, 9}, 0, 0}, /* -1 */
  129022. {{ 30, 20, 8}, -2, 1.25}, /* 0 */
  129023. /* 1 */
  129024. {{ 25, 12, 2}, 0, 0}, /* 1 */
  129025. /* 2 */
  129026. {{ 20, 9, -3}, 0, 0}, /* 2 */
  129027. {{ 20, 9, -4}, 0, 0}, /* 3 */
  129028. {{ 20, 9, -4}, 0, 0}, /* 4 */
  129029. {{ 20, 6, -6}, 0, 0}, /* 5 */
  129030. {{ 20, 3, -10}, 0, 0}, /* 6 */
  129031. {{ 18, 1, -14}, 0, 0}, /* 7 */
  129032. {{ 18, 0, -16}, 0, 0}, /* 8 */
  129033. {{ 18, -2, -16}, 0, 0}, /* 9 */
  129034. {{ 12, -2, -20}, 0, 0}, /* 10 */
  129035. };
  129036. static double _psy_lowpass_44[12]={
  129037. 13.9,15.1,15.8,16.5,17.2,18.9,20.1,48.,999.,999.,999.,999.
  129038. };
  129039. static int _noise_start_short_44[11]={
  129040. 32,16,16,16,32,9999,9999,9999,9999,9999,9999
  129041. };
  129042. static int _noise_start_long_44[11]={
  129043. 256,128,128,256,512,9999,9999,9999,9999,9999,9999
  129044. };
  129045. static int _noise_part_short_44[11]={
  129046. 8,8,8,8,8,8,8,8,8,8,8
  129047. };
  129048. static int _noise_part_long_44[11]={
  129049. 32,32,32,32,32,32,32,32,32,32,32
  129050. };
  129051. static double _noise_thresh_44[11]={
  129052. .2,.2,.2,.4,.6,9999.,9999.,9999.,9999.,9999.,9999.,
  129053. };
  129054. static double _noise_thresh_5only[2]={
  129055. .5,.5,
  129056. };
  129057. /********* End of inlined file: psych_44.h *********/
  129058. static double rate_mapping_44_stereo[12]={
  129059. 22500.,32000.,40000.,48000.,56000.,64000.,
  129060. 80000.,96000.,112000.,128000.,160000.,250001.
  129061. };
  129062. static double quality_mapping_44[12]={
  129063. -.1,.0,.1,.2,.3,.4,.5,.6,.7,.8,.9,1.0
  129064. };
  129065. static int blocksize_short_44[11]={
  129066. 512,256,256,256,256,256,256,256,256,256,256
  129067. };
  129068. static int blocksize_long_44[11]={
  129069. 4096,2048,2048,2048,2048,2048,2048,2048,2048,2048,2048
  129070. };
  129071. static double _psy_compand_short_mapping[12]={
  129072. 0.5, 1., 1., 1.3, 1.6, 2., 2., 2., 2., 2., 2., 2.
  129073. };
  129074. static double _psy_compand_long_mapping[12]={
  129075. 3.5, 4., 4., 4.3, 4.6, 5., 5., 5., 5., 5., 5., 5.
  129076. };
  129077. static double _global_mapping_44[12]={
  129078. 0., 1., 1., 1.5, 2., 2., 2.5, 2.7, 3.0, 3.7, 4., 4.
  129079. };
  129080. static int _floor_short_mapping_44[11]={
  129081. 1,0,0,2,2,4,5,5,5,5,5
  129082. };
  129083. static int _floor_long_mapping_44[11]={
  129084. 8,7,7,7,7,7,7,7,7,7,7
  129085. };
  129086. ve_setup_data_template ve_setup_44_stereo={
  129087. 11,
  129088. rate_mapping_44_stereo,
  129089. quality_mapping_44,
  129090. 2,
  129091. 40000,
  129092. 50000,
  129093. blocksize_short_44,
  129094. blocksize_long_44,
  129095. _psy_tone_masteratt_44,
  129096. _psy_tone_0dB,
  129097. _psy_tone_suppress,
  129098. _vp_tonemask_adj_otherblock,
  129099. _vp_tonemask_adj_longblock,
  129100. _vp_tonemask_adj_otherblock,
  129101. _psy_noiseguards_44,
  129102. _psy_noisebias_impulse,
  129103. _psy_noisebias_padding,
  129104. _psy_noisebias_trans,
  129105. _psy_noisebias_long,
  129106. _psy_noise_suppress,
  129107. _psy_compand_44,
  129108. _psy_compand_short_mapping,
  129109. _psy_compand_long_mapping,
  129110. {_noise_start_short_44,_noise_start_long_44},
  129111. {_noise_part_short_44,_noise_part_long_44},
  129112. _noise_thresh_44,
  129113. _psy_ath_floater,
  129114. _psy_ath_abs,
  129115. _psy_lowpass_44,
  129116. _psy_global_44,
  129117. _global_mapping_44,
  129118. _psy_stereo_modes_44,
  129119. _floor_books,
  129120. _floor,
  129121. _floor_short_mapping_44,
  129122. _floor_long_mapping_44,
  129123. _mapres_template_44_stereo
  129124. };
  129125. /********* End of inlined file: setup_44.h *********/
  129126. /********* Start of inlined file: setup_44u.h *********/
  129127. /********* Start of inlined file: residue_44u.h *********/
  129128. /********* Start of inlined file: res_books_uncoupled.h *********/
  129129. static long _vq_quantlist__16u0__p1_0[] = {
  129130. 1,
  129131. 0,
  129132. 2,
  129133. };
  129134. static long _vq_lengthlist__16u0__p1_0[] = {
  129135. 1, 4, 4, 5, 7, 7, 5, 7, 8, 5, 8, 8, 8,10,10, 8,
  129136. 10,11, 5, 8, 8, 8,10,10, 8,10,10, 4, 9, 9, 9,12,
  129137. 11, 8,11,11, 8,12,11,10,12,14,10,13,13, 7,11,11,
  129138. 10,14,12,11,14,14, 4, 9, 9, 8,11,11, 9,11,12, 7,
  129139. 11,11,10,13,14,10,12,14, 8,11,12,10,14,14,10,13,
  129140. 12,
  129141. };
  129142. static float _vq_quantthresh__16u0__p1_0[] = {
  129143. -0.5, 0.5,
  129144. };
  129145. static long _vq_quantmap__16u0__p1_0[] = {
  129146. 1, 0, 2,
  129147. };
  129148. static encode_aux_threshmatch _vq_auxt__16u0__p1_0 = {
  129149. _vq_quantthresh__16u0__p1_0,
  129150. _vq_quantmap__16u0__p1_0,
  129151. 3,
  129152. 3
  129153. };
  129154. static static_codebook _16u0__p1_0 = {
  129155. 4, 81,
  129156. _vq_lengthlist__16u0__p1_0,
  129157. 1, -535822336, 1611661312, 2, 0,
  129158. _vq_quantlist__16u0__p1_0,
  129159. NULL,
  129160. &_vq_auxt__16u0__p1_0,
  129161. NULL,
  129162. 0
  129163. };
  129164. static long _vq_quantlist__16u0__p2_0[] = {
  129165. 1,
  129166. 0,
  129167. 2,
  129168. };
  129169. static long _vq_lengthlist__16u0__p2_0[] = {
  129170. 2, 4, 4, 5, 6, 6, 5, 6, 6, 5, 7, 7, 7, 8, 9, 7,
  129171. 8, 9, 5, 7, 7, 7, 9, 8, 7, 9, 7, 4, 7, 7, 7, 9,
  129172. 9, 7, 8, 8, 6, 9, 8, 7, 8,11, 9,11,10, 6, 8, 9,
  129173. 8,11, 8, 9,10,11, 4, 7, 7, 7, 8, 8, 7, 9, 9, 6,
  129174. 9, 8, 9,11,10, 8, 8,11, 6, 8, 9, 9,10,11, 8,11,
  129175. 8,
  129176. };
  129177. static float _vq_quantthresh__16u0__p2_0[] = {
  129178. -0.5, 0.5,
  129179. };
  129180. static long _vq_quantmap__16u0__p2_0[] = {
  129181. 1, 0, 2,
  129182. };
  129183. static encode_aux_threshmatch _vq_auxt__16u0__p2_0 = {
  129184. _vq_quantthresh__16u0__p2_0,
  129185. _vq_quantmap__16u0__p2_0,
  129186. 3,
  129187. 3
  129188. };
  129189. static static_codebook _16u0__p2_0 = {
  129190. 4, 81,
  129191. _vq_lengthlist__16u0__p2_0,
  129192. 1, -535822336, 1611661312, 2, 0,
  129193. _vq_quantlist__16u0__p2_0,
  129194. NULL,
  129195. &_vq_auxt__16u0__p2_0,
  129196. NULL,
  129197. 0
  129198. };
  129199. static long _vq_quantlist__16u0__p3_0[] = {
  129200. 2,
  129201. 1,
  129202. 3,
  129203. 0,
  129204. 4,
  129205. };
  129206. static long _vq_lengthlist__16u0__p3_0[] = {
  129207. 1, 5, 5, 7, 7, 6, 7, 7, 8, 8, 6, 7, 8, 8, 8, 8,
  129208. 9, 9,11,11, 8, 9, 9,11,11, 6, 9, 8,10,10, 8,10,
  129209. 10,11,11, 8,10,10,11,11,10,11,10,13,12, 9,11,10,
  129210. 13,13, 6, 8, 9,10,10, 8,10,10,11,11, 8,10,10,11,
  129211. 11, 9,10,11,13,12,10,10,11,12,12, 8,11,11,14,13,
  129212. 10,12,11,15,13, 9,12,11,15,14,12,14,13,16,14,12,
  129213. 13,13,17,14, 8,11,11,13,14, 9,11,12,14,15,10,11,
  129214. 12,13,15,11,13,13,14,16,12,13,14,14,16, 5, 9, 9,
  129215. 11,11, 9,11,11,12,12, 8,11,11,12,12,11,12,12,15,
  129216. 14,10,12,12,15,15, 8,11,11,13,12,10,12,12,13,13,
  129217. 10,12,12,14,13,12,12,13,14,15,11,13,13,17,16, 7,
  129218. 11,11,13,13,10,12,12,14,13,10,12,12,13,14,12,13,
  129219. 12,15,14,11,13,13,15,14, 9,12,12,16,15,11,13,13,
  129220. 17,16,10,13,13,16,16,13,14,15,15,16,13,15,14,19,
  129221. 17, 9,12,12,14,16,11,13,13,15,16,10,13,13,17,16,
  129222. 13,14,13,17,15,12,15,15,16,17, 5, 9, 9,11,11, 8,
  129223. 11,11,13,12, 9,11,11,12,12,10,12,12,14,15,11,12,
  129224. 12,14,14, 7,11,10,13,12,10,12,12,14,13,10,11,12,
  129225. 13,13,11,13,13,15,16,12,12,13,15,15, 7,11,11,13,
  129226. 13,10,13,13,14,14,10,12,12,13,13,11,13,13,16,15,
  129227. 12,13,13,15,14, 9,12,12,15,15,10,13,13,17,16,11,
  129228. 12,13,15,15,12,15,14,18,18,13,14,14,16,17, 9,12,
  129229. 12,15,16,10,13,13,15,16,11,13,13,15,16,13,15,15,
  129230. 17,17,13,15,14,16,15, 7,11,11,15,16,10,13,12,16,
  129231. 17,10,12,13,15,17,15,16,16,18,17,13,15,15,17,18,
  129232. 8,12,12,16,16,11,13,14,17,18,11,13,13,18,16,15,
  129233. 17,16,17,19,14,15,15,17,16, 8,12,12,16,15,11,14,
  129234. 13,18,17,11,13,14,18,17,15,16,16,18,17,13,16,16,
  129235. 18,18,11,15,14,18,17,13,14,15,18, 0,12,15,15, 0,
  129236. 17,17,16,17,17,18,14,16,18,18, 0,11,14,14,17, 0,
  129237. 12,15,14,17,19,12,15,14,18, 0,15,18,16, 0,17,14,
  129238. 18,16,18, 0, 7,11,11,16,15,10,12,12,18,16,10,13,
  129239. 13,16,15,13,15,14,17,17,14,16,16,19,18, 8,12,12,
  129240. 16,16,11,13,13,18,16,11,13,14,17,16,14,15,15,19,
  129241. 18,15,16,16, 0,19, 8,12,12,16,17,11,13,13,17,17,
  129242. 11,14,13,17,17,13,15,15,17,19,15,17,17,19, 0,11,
  129243. 14,15,19,17,12,15,16,18,18,12,14,15,19,17,14,16,
  129244. 17, 0,18,16,16,19,17, 0,11,14,14,18,19,12,15,14,
  129245. 17,17,13,16,14,17,16,14,17,16,18,18,15,18,15, 0,
  129246. 18,
  129247. };
  129248. static float _vq_quantthresh__16u0__p3_0[] = {
  129249. -1.5, -0.5, 0.5, 1.5,
  129250. };
  129251. static long _vq_quantmap__16u0__p3_0[] = {
  129252. 3, 1, 0, 2, 4,
  129253. };
  129254. static encode_aux_threshmatch _vq_auxt__16u0__p3_0 = {
  129255. _vq_quantthresh__16u0__p3_0,
  129256. _vq_quantmap__16u0__p3_0,
  129257. 5,
  129258. 5
  129259. };
  129260. static static_codebook _16u0__p3_0 = {
  129261. 4, 625,
  129262. _vq_lengthlist__16u0__p3_0,
  129263. 1, -533725184, 1611661312, 3, 0,
  129264. _vq_quantlist__16u0__p3_0,
  129265. NULL,
  129266. &_vq_auxt__16u0__p3_0,
  129267. NULL,
  129268. 0
  129269. };
  129270. static long _vq_quantlist__16u0__p4_0[] = {
  129271. 2,
  129272. 1,
  129273. 3,
  129274. 0,
  129275. 4,
  129276. };
  129277. static long _vq_lengthlist__16u0__p4_0[] = {
  129278. 3, 5, 5, 8, 8, 6, 6, 6, 9, 9, 6, 6, 6, 9, 9, 9,
  129279. 10, 9,11,11, 9, 9, 9,11,11, 6, 7, 7,10,10, 7, 7,
  129280. 8,10,10, 7, 7, 8,10,10,10,10,10,11,12, 9,10,10,
  129281. 11,12, 6, 7, 7,10,10, 7, 8, 7,10,10, 7, 8, 7,10,
  129282. 10,10,11,10,12,11,10,10,10,13,10, 9,10,10,12,12,
  129283. 10,11,10,14,12, 9,11,11,13,13,11,12,13,13,13,11,
  129284. 12,12,15,13, 9,10,10,12,13, 9,11,10,12,13,10,10,
  129285. 11,12,13,11,12,12,12,13,11,12,12,13,13, 5, 7, 7,
  129286. 10,10, 7, 8, 8,10,10, 7, 8, 8,10,10,10,11,10,12,
  129287. 13,10,10,11,12,12, 6, 8, 8,11,10, 7, 8, 9,10,12,
  129288. 8, 9, 9,11,11,11,10,11,11,12,10,11,11,13,12, 7,
  129289. 8, 8,10,11, 8, 9, 8,11,10, 8, 9, 9,11,11,10,12,
  129290. 10,13,11,10,11,11,13,13,10,11,10,14,13,10,10,11,
  129291. 13,13,10,12,11,14,13,12,11,13,12,13,13,12,13,14,
  129292. 14,10,11,11,13,13,10,11,10,12,13,10,12,12,12,14,
  129293. 12,12,12,14,12,12,13,12,17,15, 5, 7, 7,10,10, 7,
  129294. 8, 8,10,10, 7, 8, 8,11,10,10,10,11,12,12,10,11,
  129295. 11,12,13, 6, 8, 8,11,10, 8, 9, 9,11,11, 7, 8, 9,
  129296. 10,11,11,11,11,12,12,10,10,11,12,13, 6, 8, 8,10,
  129297. 11, 8, 9, 9,11,11, 7, 9, 7,11,10,10,12,12,13,13,
  129298. 11,11,10,13,11, 9,11,10,14,13,11,11,11,15,13,10,
  129299. 10,11,13,13,12,13,13,14,14,12,11,12,12,13,10,11,
  129300. 11,12,13,10,11,12,13,13,10,11,10,13,12,12,12,13,
  129301. 14, 0,12,13,11,13,11, 8,10,10,13,13,10,11,11,14,
  129302. 13,10,11,11,13,12,13,14,14,14,15,12,12,12,15,14,
  129303. 9,11,10,13,12,10,10,11,13,14,11,11,11,15,12,13,
  129304. 12,14,15,16,13,13,13,14,13, 9,11,11,12,12,10,12,
  129305. 11,13,13,10,11,11,13,14,13,13,13,15,15,13,13,14,
  129306. 17,15,11,12,12,14,14,10,11,12,13,15,12,13,13, 0,
  129307. 15,13,11,14,12,16,14,16,14, 0,15,11,12,12,14,16,
  129308. 11,13,12,16,15,12,13,13,14,15,12,14,12,15,13,15,
  129309. 14,14,16,16, 8,10,10,13,13,10,11,10,13,14,10,11,
  129310. 11,13,13,13,13,12,14,14,14,13,13,16,17, 9,10,10,
  129311. 12,14,10,12,11,14,13,10,11,12,13,14,12,12,12,15,
  129312. 15,13,13,13,14,14, 9,10,10,13,13,10,11,12,12,14,
  129313. 10,11,10,13,13,13,13,13,14,16,13,13,13,14,14,11,
  129314. 12,13,15,13,12,14,13,14,16,12,12,13,13,14,13,14,
  129315. 14,17,15,13,12,17,13,16,11,12,13,14,15,12,13,14,
  129316. 14,17,11,12,11,14,14,13,16,14,16, 0,14,15,11,15,
  129317. 11,
  129318. };
  129319. static float _vq_quantthresh__16u0__p4_0[] = {
  129320. -1.5, -0.5, 0.5, 1.5,
  129321. };
  129322. static long _vq_quantmap__16u0__p4_0[] = {
  129323. 3, 1, 0, 2, 4,
  129324. };
  129325. static encode_aux_threshmatch _vq_auxt__16u0__p4_0 = {
  129326. _vq_quantthresh__16u0__p4_0,
  129327. _vq_quantmap__16u0__p4_0,
  129328. 5,
  129329. 5
  129330. };
  129331. static static_codebook _16u0__p4_0 = {
  129332. 4, 625,
  129333. _vq_lengthlist__16u0__p4_0,
  129334. 1, -533725184, 1611661312, 3, 0,
  129335. _vq_quantlist__16u0__p4_0,
  129336. NULL,
  129337. &_vq_auxt__16u0__p4_0,
  129338. NULL,
  129339. 0
  129340. };
  129341. static long _vq_quantlist__16u0__p5_0[] = {
  129342. 4,
  129343. 3,
  129344. 5,
  129345. 2,
  129346. 6,
  129347. 1,
  129348. 7,
  129349. 0,
  129350. 8,
  129351. };
  129352. static long _vq_lengthlist__16u0__p5_0[] = {
  129353. 1, 4, 4, 7, 7, 7, 7, 9, 9, 4, 6, 6, 8, 8, 8, 8,
  129354. 9, 9, 4, 6, 6, 8, 8, 8, 8, 9, 9, 7, 8, 8, 9, 9,
  129355. 9, 9,11,10, 7, 8, 8, 9, 9, 9, 9,10,11, 7, 8, 8,
  129356. 9, 9,10,10,11,11, 7, 8, 8, 9, 9,10,10,11,11, 9,
  129357. 9, 9,10,10,11,11,12,12, 9, 9, 9,10,10,11,11,12,
  129358. 12,
  129359. };
  129360. static float _vq_quantthresh__16u0__p5_0[] = {
  129361. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  129362. };
  129363. static long _vq_quantmap__16u0__p5_0[] = {
  129364. 7, 5, 3, 1, 0, 2, 4, 6,
  129365. 8,
  129366. };
  129367. static encode_aux_threshmatch _vq_auxt__16u0__p5_0 = {
  129368. _vq_quantthresh__16u0__p5_0,
  129369. _vq_quantmap__16u0__p5_0,
  129370. 9,
  129371. 9
  129372. };
  129373. static static_codebook _16u0__p5_0 = {
  129374. 2, 81,
  129375. _vq_lengthlist__16u0__p5_0,
  129376. 1, -531628032, 1611661312, 4, 0,
  129377. _vq_quantlist__16u0__p5_0,
  129378. NULL,
  129379. &_vq_auxt__16u0__p5_0,
  129380. NULL,
  129381. 0
  129382. };
  129383. static long _vq_quantlist__16u0__p6_0[] = {
  129384. 6,
  129385. 5,
  129386. 7,
  129387. 4,
  129388. 8,
  129389. 3,
  129390. 9,
  129391. 2,
  129392. 10,
  129393. 1,
  129394. 11,
  129395. 0,
  129396. 12,
  129397. };
  129398. static long _vq_lengthlist__16u0__p6_0[] = {
  129399. 1, 4, 4, 7, 7,10,10,12,12,13,13,18,17, 3, 6, 6,
  129400. 9, 9,11,11,13,13,14,14,18,17, 3, 6, 6, 9, 9,11,
  129401. 11,13,13,14,14,17,18, 7, 9, 9,11,11,13,13,14,14,
  129402. 15,15, 0, 0, 7, 9, 9,11,11,13,13,14,14,15,16,19,
  129403. 18,10,11,11,13,13,14,14,16,15,17,18, 0, 0,10,11,
  129404. 11,13,13,14,14,15,15,16,18, 0, 0,11,13,13,14,14,
  129405. 15,15,17,17, 0,19, 0, 0,11,13,13,14,14,14,15,16,
  129406. 18, 0,19, 0, 0,13,14,14,15,15,18,17,18,18, 0,19,
  129407. 0, 0,13,14,14,15,16,16,16,18,18,19, 0, 0, 0,16,
  129408. 17,17, 0,17,19,19, 0,19, 0, 0, 0, 0,16,19,16,17,
  129409. 18, 0,19, 0, 0, 0, 0, 0, 0,
  129410. };
  129411. static float _vq_quantthresh__16u0__p6_0[] = {
  129412. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  129413. 12.5, 17.5, 22.5, 27.5,
  129414. };
  129415. static long _vq_quantmap__16u0__p6_0[] = {
  129416. 11, 9, 7, 5, 3, 1, 0, 2,
  129417. 4, 6, 8, 10, 12,
  129418. };
  129419. static encode_aux_threshmatch _vq_auxt__16u0__p6_0 = {
  129420. _vq_quantthresh__16u0__p6_0,
  129421. _vq_quantmap__16u0__p6_0,
  129422. 13,
  129423. 13
  129424. };
  129425. static static_codebook _16u0__p6_0 = {
  129426. 2, 169,
  129427. _vq_lengthlist__16u0__p6_0,
  129428. 1, -526516224, 1616117760, 4, 0,
  129429. _vq_quantlist__16u0__p6_0,
  129430. NULL,
  129431. &_vq_auxt__16u0__p6_0,
  129432. NULL,
  129433. 0
  129434. };
  129435. static long _vq_quantlist__16u0__p6_1[] = {
  129436. 2,
  129437. 1,
  129438. 3,
  129439. 0,
  129440. 4,
  129441. };
  129442. static long _vq_lengthlist__16u0__p6_1[] = {
  129443. 1, 4, 5, 6, 6, 4, 6, 6, 6, 6, 4, 6, 6, 6, 6, 6,
  129444. 6, 6, 7, 7, 6, 6, 6, 7, 7,
  129445. };
  129446. static float _vq_quantthresh__16u0__p6_1[] = {
  129447. -1.5, -0.5, 0.5, 1.5,
  129448. };
  129449. static long _vq_quantmap__16u0__p6_1[] = {
  129450. 3, 1, 0, 2, 4,
  129451. };
  129452. static encode_aux_threshmatch _vq_auxt__16u0__p6_1 = {
  129453. _vq_quantthresh__16u0__p6_1,
  129454. _vq_quantmap__16u0__p6_1,
  129455. 5,
  129456. 5
  129457. };
  129458. static static_codebook _16u0__p6_1 = {
  129459. 2, 25,
  129460. _vq_lengthlist__16u0__p6_1,
  129461. 1, -533725184, 1611661312, 3, 0,
  129462. _vq_quantlist__16u0__p6_1,
  129463. NULL,
  129464. &_vq_auxt__16u0__p6_1,
  129465. NULL,
  129466. 0
  129467. };
  129468. static long _vq_quantlist__16u0__p7_0[] = {
  129469. 1,
  129470. 0,
  129471. 2,
  129472. };
  129473. static long _vq_lengthlist__16u0__p7_0[] = {
  129474. 1, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  129475. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  129476. 8, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  129477. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  129478. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  129479. 7,
  129480. };
  129481. static float _vq_quantthresh__16u0__p7_0[] = {
  129482. -157.5, 157.5,
  129483. };
  129484. static long _vq_quantmap__16u0__p7_0[] = {
  129485. 1, 0, 2,
  129486. };
  129487. static encode_aux_threshmatch _vq_auxt__16u0__p7_0 = {
  129488. _vq_quantthresh__16u0__p7_0,
  129489. _vq_quantmap__16u0__p7_0,
  129490. 3,
  129491. 3
  129492. };
  129493. static static_codebook _16u0__p7_0 = {
  129494. 4, 81,
  129495. _vq_lengthlist__16u0__p7_0,
  129496. 1, -518803456, 1628680192, 2, 0,
  129497. _vq_quantlist__16u0__p7_0,
  129498. NULL,
  129499. &_vq_auxt__16u0__p7_0,
  129500. NULL,
  129501. 0
  129502. };
  129503. static long _vq_quantlist__16u0__p7_1[] = {
  129504. 7,
  129505. 6,
  129506. 8,
  129507. 5,
  129508. 9,
  129509. 4,
  129510. 10,
  129511. 3,
  129512. 11,
  129513. 2,
  129514. 12,
  129515. 1,
  129516. 13,
  129517. 0,
  129518. 14,
  129519. };
  129520. static long _vq_lengthlist__16u0__p7_1[] = {
  129521. 1, 5, 5, 6, 5, 9,10,11,11,10,10,10,10,10,10, 5,
  129522. 8, 8, 8,10,10,10,10,10,10,10,10,10,10,10, 5, 8,
  129523. 9, 9, 9,10,10,10,10,10,10,10,10,10,10, 5,10, 8,
  129524. 10,10,10,10,10,10,10,10,10,10,10,10, 4, 8, 9,10,
  129525. 10,10,10,10,10,10,10,10,10,10,10, 9,10,10,10,10,
  129526. 10,10,10,10,10,10,10,10,10,10, 9,10,10,10,10,10,
  129527. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  129528. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  129529. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  129530. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  129531. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  129532. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  129533. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  129534. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  129535. 10,
  129536. };
  129537. static float _vq_quantthresh__16u0__p7_1[] = {
  129538. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  129539. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  129540. };
  129541. static long _vq_quantmap__16u0__p7_1[] = {
  129542. 13, 11, 9, 7, 5, 3, 1, 0,
  129543. 2, 4, 6, 8, 10, 12, 14,
  129544. };
  129545. static encode_aux_threshmatch _vq_auxt__16u0__p7_1 = {
  129546. _vq_quantthresh__16u0__p7_1,
  129547. _vq_quantmap__16u0__p7_1,
  129548. 15,
  129549. 15
  129550. };
  129551. static static_codebook _16u0__p7_1 = {
  129552. 2, 225,
  129553. _vq_lengthlist__16u0__p7_1,
  129554. 1, -520986624, 1620377600, 4, 0,
  129555. _vq_quantlist__16u0__p7_1,
  129556. NULL,
  129557. &_vq_auxt__16u0__p7_1,
  129558. NULL,
  129559. 0
  129560. };
  129561. static long _vq_quantlist__16u0__p7_2[] = {
  129562. 10,
  129563. 9,
  129564. 11,
  129565. 8,
  129566. 12,
  129567. 7,
  129568. 13,
  129569. 6,
  129570. 14,
  129571. 5,
  129572. 15,
  129573. 4,
  129574. 16,
  129575. 3,
  129576. 17,
  129577. 2,
  129578. 18,
  129579. 1,
  129580. 19,
  129581. 0,
  129582. 20,
  129583. };
  129584. static long _vq_lengthlist__16u0__p7_2[] = {
  129585. 1, 6, 6, 7, 8, 7, 7,10, 9,10, 9,11,10, 9,11,10,
  129586. 9, 9, 9, 9,10, 6, 8, 7, 9, 9, 8, 8,10,10, 9,11,
  129587. 11,12,12,10, 9,11, 9,12,10, 9, 6, 9, 8, 9,12, 8,
  129588. 8,11, 9,11,11,12,11,12,12,10,11,11,10,10,11, 7,
  129589. 10, 9, 9, 9, 9, 9,10, 9,10, 9,10,10,12,10,10,10,
  129590. 11,12,10,10, 7, 9, 9, 9,10, 9, 9,10,10, 9, 9, 9,
  129591. 11,11,10,10,10,10, 9, 9,12, 7, 9,10, 9,11, 9,10,
  129592. 9,10,11,11,11,10,11,12, 9,12,11,10,10,10, 7, 9,
  129593. 9, 9, 9,10,12,10, 9,11,12,10,11,12,12,11, 9,10,
  129594. 11,10,11, 7, 9,10,10,11,10, 9,10,11,11,11,10,12,
  129595. 12,12,11,11,10,11,11,12, 8, 9,10,12,11,10,10,12,
  129596. 12,12,12,12,10,11,11, 9,11,10,12,11,11, 8, 9,10,
  129597. 10,11,12,11,11,10,10,10,12,12,12, 9,10,12,12,12,
  129598. 12,12, 8,10,11,10,10,12, 9,11,12,12,11,12,12,12,
  129599. 12,10,12,10,10,10,10, 8,12,11,11,11,10,10,11,12,
  129600. 12,12,12,11,12,12,12,11,11,11,12,10, 9,10,10,12,
  129601. 10,12,10,12,12,10,10,10,11,12,12,12,11,12,12,12,
  129602. 11,10,11,12,12,12,11,12,12,11,12,12,11,12,12,12,
  129603. 12,11,12,12,10,10,10,10,11,11,12,11,12,12,12,12,
  129604. 12,12,12,11,12,11,10,11,11,12,11,11, 9,10,10,10,
  129605. 12,10,10,11, 9,11,12,11,12,11,12,12,10,11,10,12,
  129606. 9, 9, 9,12,11,10,11,10,12,10,12,10,12,12,12,11,
  129607. 11,11,11,11,10, 9,10,10,11,10,11,11,12,11,10,11,
  129608. 12,12,12,11,11, 9,12,10,12, 9,10,12,10,10,11,10,
  129609. 11,11,12,11,10,11,10,11,11,11,11,12,11,11,10, 9,
  129610. 10,10,10, 9,11,11,10, 9,12,10,11,12,11,12,12,11,
  129611. 12,11,12,11,10,11,10,12,11,12,11,12,11,12,10,11,
  129612. 10,10,12,11,10,11,11,11,10,
  129613. };
  129614. static float _vq_quantthresh__16u0__p7_2[] = {
  129615. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  129616. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  129617. 6.5, 7.5, 8.5, 9.5,
  129618. };
  129619. static long _vq_quantmap__16u0__p7_2[] = {
  129620. 19, 17, 15, 13, 11, 9, 7, 5,
  129621. 3, 1, 0, 2, 4, 6, 8, 10,
  129622. 12, 14, 16, 18, 20,
  129623. };
  129624. static encode_aux_threshmatch _vq_auxt__16u0__p7_2 = {
  129625. _vq_quantthresh__16u0__p7_2,
  129626. _vq_quantmap__16u0__p7_2,
  129627. 21,
  129628. 21
  129629. };
  129630. static static_codebook _16u0__p7_2 = {
  129631. 2, 441,
  129632. _vq_lengthlist__16u0__p7_2,
  129633. 1, -529268736, 1611661312, 5, 0,
  129634. _vq_quantlist__16u0__p7_2,
  129635. NULL,
  129636. &_vq_auxt__16u0__p7_2,
  129637. NULL,
  129638. 0
  129639. };
  129640. static long _huff_lengthlist__16u0__single[] = {
  129641. 3, 5, 8, 7,14, 8, 9,19, 5, 2, 5, 5, 9, 6, 9,19,
  129642. 8, 4, 5, 7, 8, 9,13,19, 7, 4, 6, 5, 9, 6, 9,19,
  129643. 12, 8, 7, 9,10,11,13,19, 8, 5, 8, 6, 9, 6, 7,19,
  129644. 8, 8,10, 7, 7, 4, 5,19,12,17,19,15,18,13,11,18,
  129645. };
  129646. static static_codebook _huff_book__16u0__single = {
  129647. 2, 64,
  129648. _huff_lengthlist__16u0__single,
  129649. 0, 0, 0, 0, 0,
  129650. NULL,
  129651. NULL,
  129652. NULL,
  129653. NULL,
  129654. 0
  129655. };
  129656. static long _huff_lengthlist__16u1__long[] = {
  129657. 3, 6,10, 8,12, 8,14, 8,14,19, 5, 3, 5, 5, 7, 6,
  129658. 11, 7,16,19, 7, 5, 6, 7, 7, 9,11,12,19,19, 6, 4,
  129659. 7, 5, 7, 6,10, 7,18,18, 8, 6, 7, 7, 7, 7, 8, 9,
  129660. 18,18, 7, 5, 8, 5, 7, 5, 8, 6,18,18,12, 9,10, 9,
  129661. 9, 9, 8, 9,18,18, 8, 7,10, 6, 8, 5, 6, 4,11,18,
  129662. 11,15,16,12,11, 8, 8, 6, 9,18,14,18,18,18,16,16,
  129663. 16,13,16,18,
  129664. };
  129665. static static_codebook _huff_book__16u1__long = {
  129666. 2, 100,
  129667. _huff_lengthlist__16u1__long,
  129668. 0, 0, 0, 0, 0,
  129669. NULL,
  129670. NULL,
  129671. NULL,
  129672. NULL,
  129673. 0
  129674. };
  129675. static long _vq_quantlist__16u1__p1_0[] = {
  129676. 1,
  129677. 0,
  129678. 2,
  129679. };
  129680. static long _vq_lengthlist__16u1__p1_0[] = {
  129681. 1, 4, 4, 5, 7, 7, 5, 7, 7, 5, 8, 7, 7,10,10, 7,
  129682. 9,10, 5, 7, 8, 7,10, 9, 7,10,10, 5, 8, 8, 8,10,
  129683. 10, 8,10,10, 7,10,10,10,11,12,10,12,13, 7,10,10,
  129684. 9,13,11,10,12,13, 5, 8, 8, 8,10,10, 8,10,10, 7,
  129685. 10,10,10,12,12, 9,11,12, 7,10,11,10,12,12,10,13,
  129686. 11,
  129687. };
  129688. static float _vq_quantthresh__16u1__p1_0[] = {
  129689. -0.5, 0.5,
  129690. };
  129691. static long _vq_quantmap__16u1__p1_0[] = {
  129692. 1, 0, 2,
  129693. };
  129694. static encode_aux_threshmatch _vq_auxt__16u1__p1_0 = {
  129695. _vq_quantthresh__16u1__p1_0,
  129696. _vq_quantmap__16u1__p1_0,
  129697. 3,
  129698. 3
  129699. };
  129700. static static_codebook _16u1__p1_0 = {
  129701. 4, 81,
  129702. _vq_lengthlist__16u1__p1_0,
  129703. 1, -535822336, 1611661312, 2, 0,
  129704. _vq_quantlist__16u1__p1_0,
  129705. NULL,
  129706. &_vq_auxt__16u1__p1_0,
  129707. NULL,
  129708. 0
  129709. };
  129710. static long _vq_quantlist__16u1__p2_0[] = {
  129711. 1,
  129712. 0,
  129713. 2,
  129714. };
  129715. static long _vq_lengthlist__16u1__p2_0[] = {
  129716. 3, 4, 4, 5, 6, 6, 5, 6, 6, 5, 6, 6, 6, 7, 8, 6,
  129717. 7, 8, 5, 6, 6, 6, 8, 7, 6, 8, 7, 5, 6, 6, 6, 8,
  129718. 8, 6, 8, 8, 6, 8, 8, 7, 7,10, 8, 9, 9, 6, 8, 8,
  129719. 7, 9, 8, 8, 9,10, 5, 6, 6, 6, 8, 8, 7, 8, 8, 6,
  129720. 8, 8, 8,10, 9, 7, 8, 9, 6, 8, 8, 8, 9, 9, 7,10,
  129721. 8,
  129722. };
  129723. static float _vq_quantthresh__16u1__p2_0[] = {
  129724. -0.5, 0.5,
  129725. };
  129726. static long _vq_quantmap__16u1__p2_0[] = {
  129727. 1, 0, 2,
  129728. };
  129729. static encode_aux_threshmatch _vq_auxt__16u1__p2_0 = {
  129730. _vq_quantthresh__16u1__p2_0,
  129731. _vq_quantmap__16u1__p2_0,
  129732. 3,
  129733. 3
  129734. };
  129735. static static_codebook _16u1__p2_0 = {
  129736. 4, 81,
  129737. _vq_lengthlist__16u1__p2_0,
  129738. 1, -535822336, 1611661312, 2, 0,
  129739. _vq_quantlist__16u1__p2_0,
  129740. NULL,
  129741. &_vq_auxt__16u1__p2_0,
  129742. NULL,
  129743. 0
  129744. };
  129745. static long _vq_quantlist__16u1__p3_0[] = {
  129746. 2,
  129747. 1,
  129748. 3,
  129749. 0,
  129750. 4,
  129751. };
  129752. static long _vq_lengthlist__16u1__p3_0[] = {
  129753. 1, 5, 5, 8, 8, 6, 7, 7, 9, 9, 5, 7, 7, 9, 9, 9,
  129754. 10, 9,11,11, 9, 9,10,11,11, 6, 8, 8,10,10, 8, 9,
  129755. 10,11,11, 8, 9,10,11,11,10,11,11,12,13,10,11,11,
  129756. 13,13, 6, 8, 8,10,10, 8,10, 9,11,11, 8,10, 9,11,
  129757. 11,10,11,11,13,13,10,11,11,13,12, 9,11,11,14,13,
  129758. 10,12,12,15,14,10,12,11,14,13,12,13,13,15,15,12,
  129759. 13,13,16,14, 9,11,11,13,14,10,11,12,14,14,10,12,
  129760. 12,14,15,12,13,13,14,15,12,13,14,15,16, 5, 8, 8,
  129761. 11,11, 8,10,10,12,12, 8,10,10,12,12,11,12,12,14,
  129762. 14,11,12,12,14,14, 8,10,10,12,12, 9,11,12,12,13,
  129763. 10,12,12,13,13,12,12,13,14,15,11,13,13,15,15, 7,
  129764. 10,10,12,12, 9,12,11,13,12,10,11,12,13,13,12,13,
  129765. 12,15,14,11,12,13,15,15,10,12,12,15,14,11,13,13,
  129766. 16,15,11,13,13,16,15,14,13,14,15,16,13,15,15,17,
  129767. 17,10,12,12,14,15,11,12,12,15,15,11,13,13,15,16,
  129768. 13,15,13,16,15,13,15,15,16,17, 5, 8, 8,11,11, 8,
  129769. 10,10,12,12, 8,10,10,12,12,11,12,12,14,14,11,12,
  129770. 12,14,14, 7,10,10,12,12,10,12,12,14,13, 9,11,12,
  129771. 12,13,12,13,13,15,15,12,12,13,13,15, 7,10,10,12,
  129772. 13,10,11,12,13,13,10,12,11,13,13,11,13,13,15,15,
  129773. 12,13,12,15,14, 9,12,12,15,14,11,13,13,15,15,11,
  129774. 12,13,15,15,13,14,14,17,19,13,13,14,16,16,10,12,
  129775. 12,14,15,11,13,13,15,16,11,13,12,16,15,13,15,15,
  129776. 17,18,14,15,13,16,15, 8,11,11,15,14,10,12,12,16,
  129777. 15,10,12,12,16,16,14,15,15,18,17,13,14,15,16,18,
  129778. 9,12,12,15,15,11,12,14,16,17,11,13,13,16,15,15,
  129779. 15,15,17,18,14,15,16,17,17, 9,12,12,15,15,11,14,
  129780. 13,16,16,11,13,13,16,16,15,16,15,17,18,14,16,15,
  129781. 17,16,12,14,14,17,16,12,14,15,18,17,13,15,15,17,
  129782. 17,15,15,18,16,20,15,16,17,18,18,11,14,14,16,17,
  129783. 13,15,14,18,17,13,15,15,17,17,15,17,15,18,17,15,
  129784. 17,16,19,18, 8,11,11,14,15,10,12,12,15,15,10,12,
  129785. 12,16,16,13,14,14,17,16,14,15,15,17,17, 9,12,12,
  129786. 15,16,11,13,13,16,16,11,12,13,16,16,14,16,15,20,
  129787. 17,14,16,16,17,17, 9,12,12,15,16,11,13,13,16,17,
  129788. 11,13,13,17,16,14,15,15,17,18,15,15,15,18,18,11,
  129789. 14,14,17,16,13,15,15,17,17,13,14,14,18,17,15,16,
  129790. 16,18,19,15,15,17,17,19,11,14,14,16,17,13,15,14,
  129791. 17,19,13,15,14,18,17,15,17,16,18,18,15,17,15,18,
  129792. 16,
  129793. };
  129794. static float _vq_quantthresh__16u1__p3_0[] = {
  129795. -1.5, -0.5, 0.5, 1.5,
  129796. };
  129797. static long _vq_quantmap__16u1__p3_0[] = {
  129798. 3, 1, 0, 2, 4,
  129799. };
  129800. static encode_aux_threshmatch _vq_auxt__16u1__p3_0 = {
  129801. _vq_quantthresh__16u1__p3_0,
  129802. _vq_quantmap__16u1__p3_0,
  129803. 5,
  129804. 5
  129805. };
  129806. static static_codebook _16u1__p3_0 = {
  129807. 4, 625,
  129808. _vq_lengthlist__16u1__p3_0,
  129809. 1, -533725184, 1611661312, 3, 0,
  129810. _vq_quantlist__16u1__p3_0,
  129811. NULL,
  129812. &_vq_auxt__16u1__p3_0,
  129813. NULL,
  129814. 0
  129815. };
  129816. static long _vq_quantlist__16u1__p4_0[] = {
  129817. 2,
  129818. 1,
  129819. 3,
  129820. 0,
  129821. 4,
  129822. };
  129823. static long _vq_lengthlist__16u1__p4_0[] = {
  129824. 4, 5, 5, 8, 8, 6, 6, 7, 9, 9, 6, 6, 6, 9, 9, 9,
  129825. 10, 9,11,11, 9, 9,10,11,11, 6, 7, 7,10, 9, 7, 7,
  129826. 8, 9,10, 7, 7, 8,10,10,10,10,10,10,12, 9, 9,10,
  129827. 11,12, 6, 7, 7, 9, 9, 7, 8, 7,10,10, 7, 8, 7,10,
  129828. 10, 9,10, 9,12,11,10,10, 9,12,10, 9,10,10,12,11,
  129829. 10,10,10,12,12, 9,10,10,12,12,12,11,12,13,13,11,
  129830. 11,12,12,13, 9,10,10,11,12, 9,10,10,12,12,10,10,
  129831. 10,12,12,11,12,11,14,13,11,12,12,14,13, 5, 7, 7,
  129832. 10,10, 7, 8, 8,10,10, 7, 8, 7,10,10,10,10,10,12,
  129833. 12,10,10,10,12,12, 6, 8, 7,10,10, 7, 7, 9,10,11,
  129834. 8, 9, 9,11,10,10,10,11,11,13,10,10,11,12,13, 6,
  129835. 8, 8,10,10, 7, 9, 8,11,10, 8, 9, 9,10,11,10,11,
  129836. 10,13,11,10,11,10,12,12,10,11,10,12,11,10,10,10,
  129837. 12,13,10,11,11,13,12,11,11,13,11,14,12,12,13,14,
  129838. 14, 9,10,10,12,13,10,11,10,13,12,10,11,11,12,13,
  129839. 11,12,11,14,12,12,13,13,15,14, 5, 7, 7,10,10, 7,
  129840. 7, 8,10,10, 7, 8, 8,10,10,10,10,10,11,12,10,10,
  129841. 10,12,12, 7, 8, 8,10,10, 8, 9, 8,11,10, 7, 8, 9,
  129842. 10,11,10,11,11,12,12,10,10,11,11,13, 7, 7, 8,10,
  129843. 10, 8, 8, 9,10,11, 7, 9, 7,11,10,10,11,11,13,12,
  129844. 11,11,10,13,11, 9,10,10,12,12,10,11,11,13,12,10,
  129845. 10,11,12,12,12,13,13,14,14,11,11,12,12,14,10,10,
  129846. 11,12,12,10,11,11,12,13,10,10,10,13,12,12,13,13,
  129847. 15,14,12,13,10,14,11, 8,10,10,12,12,10,11,10,13,
  129848. 13, 9,10,10,12,12,12,13,13,15,14,11,12,12,13,13,
  129849. 9,10,10,13,12,10,10,11,13,13,10,11,10,13,12,12,
  129850. 12,13,14,15,12,13,12,15,13, 9,10,10,12,13,10,11,
  129851. 10,13,12,10,10,11,12,13,12,14,12,15,13,12,12,13,
  129852. 14,15,11,12,11,14,13,11,11,12,14,15,12,13,12,15,
  129853. 14,13,11,15,11,16,13,14,14,16,15,11,12,12,14,14,
  129854. 11,12,11,14,13,12,12,13,14,15,13,14,12,16,12,14,
  129855. 14,14,15,15, 8,10,10,12,12, 9,10,10,12,12,10,10,
  129856. 11,13,13,11,12,12,13,13,12,13,13,14,15, 9,10,10,
  129857. 13,12,10,11,11,13,12,10,10,11,13,13,12,13,12,15,
  129858. 14,12,12,13,13,16, 9, 9,10,12,13,10,10,11,12,13,
  129859. 10,11,10,13,13,12,12,13,13,15,13,13,12,15,13,11,
  129860. 12,12,14,14,12,13,12,15,14,11,11,12,13,14,14,14,
  129861. 14,16,15,13,12,15,12,16,11,11,12,13,14,12,13,13,
  129862. 14,15,10,12,11,14,13,14,15,14,16,16,13,14,11,15,
  129863. 11,
  129864. };
  129865. static float _vq_quantthresh__16u1__p4_0[] = {
  129866. -1.5, -0.5, 0.5, 1.5,
  129867. };
  129868. static long _vq_quantmap__16u1__p4_0[] = {
  129869. 3, 1, 0, 2, 4,
  129870. };
  129871. static encode_aux_threshmatch _vq_auxt__16u1__p4_0 = {
  129872. _vq_quantthresh__16u1__p4_0,
  129873. _vq_quantmap__16u1__p4_0,
  129874. 5,
  129875. 5
  129876. };
  129877. static static_codebook _16u1__p4_0 = {
  129878. 4, 625,
  129879. _vq_lengthlist__16u1__p4_0,
  129880. 1, -533725184, 1611661312, 3, 0,
  129881. _vq_quantlist__16u1__p4_0,
  129882. NULL,
  129883. &_vq_auxt__16u1__p4_0,
  129884. NULL,
  129885. 0
  129886. };
  129887. static long _vq_quantlist__16u1__p5_0[] = {
  129888. 4,
  129889. 3,
  129890. 5,
  129891. 2,
  129892. 6,
  129893. 1,
  129894. 7,
  129895. 0,
  129896. 8,
  129897. };
  129898. static long _vq_lengthlist__16u1__p5_0[] = {
  129899. 1, 4, 4, 7, 7, 7, 7, 9, 9, 4, 6, 6, 8, 8, 8, 8,
  129900. 10,10, 4, 5, 6, 8, 8, 8, 8,10,10, 7, 8, 8, 9, 9,
  129901. 9, 9,11,11, 7, 8, 8, 9, 9, 9, 9,11,11, 7, 8, 8,
  129902. 10, 9,11,11,12,11, 7, 8, 8, 9, 9,11,11,12,12, 9,
  129903. 10,10,11,11,12,12,13,12, 9,10,10,11,11,12,12,12,
  129904. 13,
  129905. };
  129906. static float _vq_quantthresh__16u1__p5_0[] = {
  129907. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  129908. };
  129909. static long _vq_quantmap__16u1__p5_0[] = {
  129910. 7, 5, 3, 1, 0, 2, 4, 6,
  129911. 8,
  129912. };
  129913. static encode_aux_threshmatch _vq_auxt__16u1__p5_0 = {
  129914. _vq_quantthresh__16u1__p5_0,
  129915. _vq_quantmap__16u1__p5_0,
  129916. 9,
  129917. 9
  129918. };
  129919. static static_codebook _16u1__p5_0 = {
  129920. 2, 81,
  129921. _vq_lengthlist__16u1__p5_0,
  129922. 1, -531628032, 1611661312, 4, 0,
  129923. _vq_quantlist__16u1__p5_0,
  129924. NULL,
  129925. &_vq_auxt__16u1__p5_0,
  129926. NULL,
  129927. 0
  129928. };
  129929. static long _vq_quantlist__16u1__p6_0[] = {
  129930. 4,
  129931. 3,
  129932. 5,
  129933. 2,
  129934. 6,
  129935. 1,
  129936. 7,
  129937. 0,
  129938. 8,
  129939. };
  129940. static long _vq_lengthlist__16u1__p6_0[] = {
  129941. 3, 4, 4, 6, 6, 7, 7, 9, 9, 4, 4, 4, 6, 6, 8, 8,
  129942. 9, 9, 4, 4, 4, 6, 6, 7, 7, 9, 9, 6, 6, 6, 7, 7,
  129943. 8, 8,10, 9, 6, 6, 6, 7, 7, 8, 8, 9,10, 7, 8, 7,
  129944. 8, 8, 9, 9,10,10, 7, 8, 8, 8, 8, 9, 9,10,10, 9,
  129945. 9, 9,10,10,10,10,11,11, 9, 9, 9,10,10,10,10,11,
  129946. 11,
  129947. };
  129948. static float _vq_quantthresh__16u1__p6_0[] = {
  129949. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  129950. };
  129951. static long _vq_quantmap__16u1__p6_0[] = {
  129952. 7, 5, 3, 1, 0, 2, 4, 6,
  129953. 8,
  129954. };
  129955. static encode_aux_threshmatch _vq_auxt__16u1__p6_0 = {
  129956. _vq_quantthresh__16u1__p6_0,
  129957. _vq_quantmap__16u1__p6_0,
  129958. 9,
  129959. 9
  129960. };
  129961. static static_codebook _16u1__p6_0 = {
  129962. 2, 81,
  129963. _vq_lengthlist__16u1__p6_0,
  129964. 1, -531628032, 1611661312, 4, 0,
  129965. _vq_quantlist__16u1__p6_0,
  129966. NULL,
  129967. &_vq_auxt__16u1__p6_0,
  129968. NULL,
  129969. 0
  129970. };
  129971. static long _vq_quantlist__16u1__p7_0[] = {
  129972. 1,
  129973. 0,
  129974. 2,
  129975. };
  129976. static long _vq_lengthlist__16u1__p7_0[] = {
  129977. 1, 4, 4, 4, 8, 8, 4, 8, 8, 5,11, 9, 8,12,11, 8,
  129978. 12,11, 5,10,11, 8,11,12, 8,11,12, 4,11,11,11,14,
  129979. 13,10,13,13, 8,14,13,12,14,16,12,16,15, 8,14,14,
  129980. 13,16,14,12,15,16, 4,11,11,10,14,13,11,14,14, 8,
  129981. 15,14,12,15,15,12,14,16, 8,14,14,11,16,15,12,15,
  129982. 13,
  129983. };
  129984. static float _vq_quantthresh__16u1__p7_0[] = {
  129985. -5.5, 5.5,
  129986. };
  129987. static long _vq_quantmap__16u1__p7_0[] = {
  129988. 1, 0, 2,
  129989. };
  129990. static encode_aux_threshmatch _vq_auxt__16u1__p7_0 = {
  129991. _vq_quantthresh__16u1__p7_0,
  129992. _vq_quantmap__16u1__p7_0,
  129993. 3,
  129994. 3
  129995. };
  129996. static static_codebook _16u1__p7_0 = {
  129997. 4, 81,
  129998. _vq_lengthlist__16u1__p7_0,
  129999. 1, -529137664, 1618345984, 2, 0,
  130000. _vq_quantlist__16u1__p7_0,
  130001. NULL,
  130002. &_vq_auxt__16u1__p7_0,
  130003. NULL,
  130004. 0
  130005. };
  130006. static long _vq_quantlist__16u1__p7_1[] = {
  130007. 5,
  130008. 4,
  130009. 6,
  130010. 3,
  130011. 7,
  130012. 2,
  130013. 8,
  130014. 1,
  130015. 9,
  130016. 0,
  130017. 10,
  130018. };
  130019. static long _vq_lengthlist__16u1__p7_1[] = {
  130020. 2, 4, 4, 6, 6, 7, 7, 8, 8, 8, 8, 4, 6, 5, 7, 7,
  130021. 8, 8, 8, 8, 8, 8, 4, 5, 6, 7, 7, 8, 8, 8, 8, 8,
  130022. 8, 6, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 6, 7, 7, 8,
  130023. 8, 8, 8, 9, 9, 9, 9, 7, 8, 8, 8, 8, 9, 9, 9,10,
  130024. 9,10, 7, 8, 8, 8, 8, 9, 9, 9, 9,10, 9, 8, 8, 8,
  130025. 9, 9,10,10,10,10,10,10, 8, 8, 8, 9, 9, 9, 9,10,
  130026. 10,10,10, 8, 8, 8, 9, 9, 9,10,10,10,10,10, 8, 8,
  130027. 8, 9, 9,10,10,10,10,10,10,
  130028. };
  130029. static float _vq_quantthresh__16u1__p7_1[] = {
  130030. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  130031. 3.5, 4.5,
  130032. };
  130033. static long _vq_quantmap__16u1__p7_1[] = {
  130034. 9, 7, 5, 3, 1, 0, 2, 4,
  130035. 6, 8, 10,
  130036. };
  130037. static encode_aux_threshmatch _vq_auxt__16u1__p7_1 = {
  130038. _vq_quantthresh__16u1__p7_1,
  130039. _vq_quantmap__16u1__p7_1,
  130040. 11,
  130041. 11
  130042. };
  130043. static static_codebook _16u1__p7_1 = {
  130044. 2, 121,
  130045. _vq_lengthlist__16u1__p7_1,
  130046. 1, -531365888, 1611661312, 4, 0,
  130047. _vq_quantlist__16u1__p7_1,
  130048. NULL,
  130049. &_vq_auxt__16u1__p7_1,
  130050. NULL,
  130051. 0
  130052. };
  130053. static long _vq_quantlist__16u1__p8_0[] = {
  130054. 5,
  130055. 4,
  130056. 6,
  130057. 3,
  130058. 7,
  130059. 2,
  130060. 8,
  130061. 1,
  130062. 9,
  130063. 0,
  130064. 10,
  130065. };
  130066. static long _vq_lengthlist__16u1__p8_0[] = {
  130067. 1, 4, 4, 5, 5, 8, 8,10,10,12,12, 4, 7, 7, 8, 8,
  130068. 9, 9,12,11,14,13, 4, 7, 7, 7, 8, 9,10,11,11,13,
  130069. 12, 5, 8, 8, 9, 9,11,11,12,13,15,14, 5, 7, 8, 9,
  130070. 9,11,11,13,13,17,15, 8, 9,10,11,11,12,13,17,14,
  130071. 17,16, 8,10, 9,11,11,12,12,13,15,15,17,10,11,11,
  130072. 12,13,14,15,15,16,16,17, 9,11,11,12,12,14,15,17,
  130073. 15,15,16,11,14,12,14,15,16,15,16,16,16,15,11,13,
  130074. 13,14,14,15,15,16,16,15,16,
  130075. };
  130076. static float _vq_quantthresh__16u1__p8_0[] = {
  130077. -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5, 27.5,
  130078. 38.5, 49.5,
  130079. };
  130080. static long _vq_quantmap__16u1__p8_0[] = {
  130081. 9, 7, 5, 3, 1, 0, 2, 4,
  130082. 6, 8, 10,
  130083. };
  130084. static encode_aux_threshmatch _vq_auxt__16u1__p8_0 = {
  130085. _vq_quantthresh__16u1__p8_0,
  130086. _vq_quantmap__16u1__p8_0,
  130087. 11,
  130088. 11
  130089. };
  130090. static static_codebook _16u1__p8_0 = {
  130091. 2, 121,
  130092. _vq_lengthlist__16u1__p8_0,
  130093. 1, -524582912, 1618345984, 4, 0,
  130094. _vq_quantlist__16u1__p8_0,
  130095. NULL,
  130096. &_vq_auxt__16u1__p8_0,
  130097. NULL,
  130098. 0
  130099. };
  130100. static long _vq_quantlist__16u1__p8_1[] = {
  130101. 5,
  130102. 4,
  130103. 6,
  130104. 3,
  130105. 7,
  130106. 2,
  130107. 8,
  130108. 1,
  130109. 9,
  130110. 0,
  130111. 10,
  130112. };
  130113. static long _vq_lengthlist__16u1__p8_1[] = {
  130114. 2, 5, 5, 6, 6, 7, 7, 8, 8, 8, 8, 4, 6, 6, 7, 7,
  130115. 8, 7, 8, 8, 8, 8, 4, 6, 6, 7, 7, 7, 7, 8, 8, 8,
  130116. 8, 6, 7, 7, 7, 7, 8, 8, 8, 8, 8, 9, 6, 7, 7, 7,
  130117. 7, 8, 8, 8, 8, 9, 9, 7, 7, 7, 8, 8, 8, 8, 9, 9,
  130118. 9, 9, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 8, 8, 8,
  130119. 8, 8, 9, 9, 9, 9, 9, 9, 8, 8, 8, 8, 8, 9, 9, 9,
  130120. 9, 9, 9, 8, 8, 8, 9, 8, 9, 9, 9, 9, 9, 9, 8, 8,
  130121. 8, 9, 9, 9, 9, 9, 9, 9, 9,
  130122. };
  130123. static float _vq_quantthresh__16u1__p8_1[] = {
  130124. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  130125. 3.5, 4.5,
  130126. };
  130127. static long _vq_quantmap__16u1__p8_1[] = {
  130128. 9, 7, 5, 3, 1, 0, 2, 4,
  130129. 6, 8, 10,
  130130. };
  130131. static encode_aux_threshmatch _vq_auxt__16u1__p8_1 = {
  130132. _vq_quantthresh__16u1__p8_1,
  130133. _vq_quantmap__16u1__p8_1,
  130134. 11,
  130135. 11
  130136. };
  130137. static static_codebook _16u1__p8_1 = {
  130138. 2, 121,
  130139. _vq_lengthlist__16u1__p8_1,
  130140. 1, -531365888, 1611661312, 4, 0,
  130141. _vq_quantlist__16u1__p8_1,
  130142. NULL,
  130143. &_vq_auxt__16u1__p8_1,
  130144. NULL,
  130145. 0
  130146. };
  130147. static long _vq_quantlist__16u1__p9_0[] = {
  130148. 7,
  130149. 6,
  130150. 8,
  130151. 5,
  130152. 9,
  130153. 4,
  130154. 10,
  130155. 3,
  130156. 11,
  130157. 2,
  130158. 12,
  130159. 1,
  130160. 13,
  130161. 0,
  130162. 14,
  130163. };
  130164. static long _vq_lengthlist__16u1__p9_0[] = {
  130165. 1, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  130166. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  130167. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  130168. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  130169. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  130170. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  130171. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  130172. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  130173. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  130174. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  130175. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  130176. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  130177. 9, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  130178. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  130179. 8,
  130180. };
  130181. static float _vq_quantthresh__16u1__p9_0[] = {
  130182. -1657.5, -1402.5, -1147.5, -892.5, -637.5, -382.5, -127.5, 127.5,
  130183. 382.5, 637.5, 892.5, 1147.5, 1402.5, 1657.5,
  130184. };
  130185. static long _vq_quantmap__16u1__p9_0[] = {
  130186. 13, 11, 9, 7, 5, 3, 1, 0,
  130187. 2, 4, 6, 8, 10, 12, 14,
  130188. };
  130189. static encode_aux_threshmatch _vq_auxt__16u1__p9_0 = {
  130190. _vq_quantthresh__16u1__p9_0,
  130191. _vq_quantmap__16u1__p9_0,
  130192. 15,
  130193. 15
  130194. };
  130195. static static_codebook _16u1__p9_0 = {
  130196. 2, 225,
  130197. _vq_lengthlist__16u1__p9_0,
  130198. 1, -514071552, 1627381760, 4, 0,
  130199. _vq_quantlist__16u1__p9_0,
  130200. NULL,
  130201. &_vq_auxt__16u1__p9_0,
  130202. NULL,
  130203. 0
  130204. };
  130205. static long _vq_quantlist__16u1__p9_1[] = {
  130206. 7,
  130207. 6,
  130208. 8,
  130209. 5,
  130210. 9,
  130211. 4,
  130212. 10,
  130213. 3,
  130214. 11,
  130215. 2,
  130216. 12,
  130217. 1,
  130218. 13,
  130219. 0,
  130220. 14,
  130221. };
  130222. static long _vq_lengthlist__16u1__p9_1[] = {
  130223. 1, 6, 5, 9, 9,10,10, 6, 7, 9, 9,10,10,10,10, 5,
  130224. 10, 8,10, 8,10,10, 8, 8,10, 9,10,10,10,10, 5, 8,
  130225. 9,10,10,10,10, 8,10,10,10,10,10,10,10, 9,10,10,
  130226. 10,10,10,10, 9, 9,10,10,10,10,10,10, 9, 9, 8, 9,
  130227. 10,10,10, 9,10,10,10,10,10,10,10,10,10,10,10,10,
  130228. 10,10,10,10,10,10,10,10,10,10,10, 8,10,10,10,10,
  130229. 10,10,10,10,10,10,10,10,10, 6, 8, 8,10,10,10, 8,
  130230. 10,10,10,10,10,10,10,10, 5, 8, 8,10,10,10, 9, 9,
  130231. 10,10,10,10,10,10,10,10, 9,10,10,10,10,10,10,10,
  130232. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  130233. 10,10,10,10,10,10,10,10, 9, 9, 9, 9, 9, 9, 9, 9,
  130234. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  130235. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  130236. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  130237. 9,
  130238. };
  130239. static float _vq_quantthresh__16u1__p9_1[] = {
  130240. -110.5, -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5,
  130241. 25.5, 42.5, 59.5, 76.5, 93.5, 110.5,
  130242. };
  130243. static long _vq_quantmap__16u1__p9_1[] = {
  130244. 13, 11, 9, 7, 5, 3, 1, 0,
  130245. 2, 4, 6, 8, 10, 12, 14,
  130246. };
  130247. static encode_aux_threshmatch _vq_auxt__16u1__p9_1 = {
  130248. _vq_quantthresh__16u1__p9_1,
  130249. _vq_quantmap__16u1__p9_1,
  130250. 15,
  130251. 15
  130252. };
  130253. static static_codebook _16u1__p9_1 = {
  130254. 2, 225,
  130255. _vq_lengthlist__16u1__p9_1,
  130256. 1, -522338304, 1620115456, 4, 0,
  130257. _vq_quantlist__16u1__p9_1,
  130258. NULL,
  130259. &_vq_auxt__16u1__p9_1,
  130260. NULL,
  130261. 0
  130262. };
  130263. static long _vq_quantlist__16u1__p9_2[] = {
  130264. 8,
  130265. 7,
  130266. 9,
  130267. 6,
  130268. 10,
  130269. 5,
  130270. 11,
  130271. 4,
  130272. 12,
  130273. 3,
  130274. 13,
  130275. 2,
  130276. 14,
  130277. 1,
  130278. 15,
  130279. 0,
  130280. 16,
  130281. };
  130282. static long _vq_lengthlist__16u1__p9_2[] = {
  130283. 1, 6, 6, 7, 8, 8,11,10, 9, 9,11, 9,10, 9,11,11,
  130284. 9, 6, 7, 6,11, 8,11, 9,10,10,11, 9,11,10,10,10,
  130285. 11, 9, 5, 7, 7, 8, 8,10,11, 8, 8,11, 9, 9,10,11,
  130286. 9,10,11, 8, 9, 6, 8, 8, 9, 9,10,10,11,11,11, 9,
  130287. 11,10, 9,11, 8, 8, 8, 9, 8, 9,10,11, 9, 9,11,11,
  130288. 10, 9, 9,11,10, 8,11, 8, 9, 8,11, 9,10, 9,10,11,
  130289. 11,10,10, 9,10,10, 8, 8, 9,10,10,10, 9,11, 9,10,
  130290. 11,11,11,11,10, 9,11, 9, 9,11,11,10, 8,11,11,11,
  130291. 9,10,10,11,10,11,11, 9,11,10, 9,11,10,10,10,10,
  130292. 9,11,10,11,10, 9, 9,10,11, 9, 8,10,11,11,10,10,
  130293. 11, 9,11,10,11,11,10,11, 9, 9, 8,10, 8, 9,11, 9,
  130294. 8,10,10, 9,11,10,11,10,11, 9,11, 8,10,11,11,11,
  130295. 11,10,10,11,11,11,11,10,11,11,10, 9, 8,10,10, 9,
  130296. 11,10,11,11,11, 9, 9, 9,11,11,11,10,10, 9, 9,10,
  130297. 9,11,11,11,11, 8,10,11,10,11,11,10,11,11, 9, 9,
  130298. 9,10, 9,11, 9,11,11,11,11,11,10,11,11,10,11,10,
  130299. 11,11, 9,11,10,11,10, 9,10, 9,10,10,11,11,11,11,
  130300. 9,10, 9,10,11,11,10,11,11,11,11,11,11,10,11,11,
  130301. 10,
  130302. };
  130303. static float _vq_quantthresh__16u1__p9_2[] = {
  130304. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  130305. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  130306. };
  130307. static long _vq_quantmap__16u1__p9_2[] = {
  130308. 15, 13, 11, 9, 7, 5, 3, 1,
  130309. 0, 2, 4, 6, 8, 10, 12, 14,
  130310. 16,
  130311. };
  130312. static encode_aux_threshmatch _vq_auxt__16u1__p9_2 = {
  130313. _vq_quantthresh__16u1__p9_2,
  130314. _vq_quantmap__16u1__p9_2,
  130315. 17,
  130316. 17
  130317. };
  130318. static static_codebook _16u1__p9_2 = {
  130319. 2, 289,
  130320. _vq_lengthlist__16u1__p9_2,
  130321. 1, -529530880, 1611661312, 5, 0,
  130322. _vq_quantlist__16u1__p9_2,
  130323. NULL,
  130324. &_vq_auxt__16u1__p9_2,
  130325. NULL,
  130326. 0
  130327. };
  130328. static long _huff_lengthlist__16u1__short[] = {
  130329. 5, 7,10, 9,11,10,15,11,13,16, 6, 4, 6, 6, 7, 7,
  130330. 10, 9,12,16,10, 6, 5, 6, 6, 7,10,11,16,16, 9, 6,
  130331. 7, 6, 7, 7,10, 8,14,16,11, 6, 5, 4, 5, 6, 8, 9,
  130332. 15,16, 9, 6, 6, 5, 6, 6, 9, 8,14,16,12, 7, 6, 6,
  130333. 5, 6, 6, 7,13,16, 8, 6, 7, 6, 5, 5, 4, 4,11,16,
  130334. 9, 8, 9, 9, 7, 7, 6, 5,13,16,14,14,16,15,16,15,
  130335. 16,16,16,16,
  130336. };
  130337. static static_codebook _huff_book__16u1__short = {
  130338. 2, 100,
  130339. _huff_lengthlist__16u1__short,
  130340. 0, 0, 0, 0, 0,
  130341. NULL,
  130342. NULL,
  130343. NULL,
  130344. NULL,
  130345. 0
  130346. };
  130347. static long _huff_lengthlist__16u2__long[] = {
  130348. 5, 7,10,10,10,11,11,13,18,19, 6, 5, 5, 6, 7, 8,
  130349. 9,12,19,19, 8, 5, 4, 4, 6, 7, 9,13,19,19, 8, 5,
  130350. 4, 4, 5, 6, 8,12,17,19, 7, 5, 5, 4, 4, 5, 7,12,
  130351. 18,18, 8, 7, 7, 6, 5, 5, 6,10,18,18, 9, 9, 9, 8,
  130352. 6, 5, 6, 9,18,18,11,13,13,13, 8, 7, 7, 9,16,18,
  130353. 13,17,18,16,11, 9, 9, 9,17,18,15,18,18,18,15,13,
  130354. 13,14,18,18,
  130355. };
  130356. static static_codebook _huff_book__16u2__long = {
  130357. 2, 100,
  130358. _huff_lengthlist__16u2__long,
  130359. 0, 0, 0, 0, 0,
  130360. NULL,
  130361. NULL,
  130362. NULL,
  130363. NULL,
  130364. 0
  130365. };
  130366. static long _huff_lengthlist__16u2__short[] = {
  130367. 8,11,12,12,14,15,16,16,16,16, 9, 7, 7, 8, 9,11,
  130368. 13,14,16,16,13, 7, 6, 6, 7, 9,12,13,15,16,15, 7,
  130369. 6, 5, 4, 6,10,11,14,16,12, 8, 7, 4, 2, 4, 7,10,
  130370. 14,16,11, 9, 7, 5, 3, 4, 6, 9,14,16,11,10, 9, 7,
  130371. 5, 5, 6, 9,16,16,10,10, 9, 8, 6, 6, 7,10,16,16,
  130372. 11,11,11,10,10,10,11,14,16,16,16,14,14,13,14,16,
  130373. 16,16,16,16,
  130374. };
  130375. static static_codebook _huff_book__16u2__short = {
  130376. 2, 100,
  130377. _huff_lengthlist__16u2__short,
  130378. 0, 0, 0, 0, 0,
  130379. NULL,
  130380. NULL,
  130381. NULL,
  130382. NULL,
  130383. 0
  130384. };
  130385. static long _vq_quantlist__16u2_p1_0[] = {
  130386. 1,
  130387. 0,
  130388. 2,
  130389. };
  130390. static long _vq_lengthlist__16u2_p1_0[] = {
  130391. 1, 5, 5, 5, 7, 7, 5, 7, 7, 5, 7, 7, 7, 9, 9, 7,
  130392. 9, 9, 5, 7, 7, 7, 9, 9, 7, 9, 9, 5, 7, 7, 8, 9,
  130393. 9, 7, 9, 9, 7, 9, 9, 9,10,10, 9,10,10, 7, 9, 9,
  130394. 9,10,10, 9,10,11, 5, 7, 8, 8, 9, 9, 8, 9, 9, 7,
  130395. 9, 9, 9,10,10, 9, 9,10, 7, 9, 9, 9,10,10, 9,11,
  130396. 10,
  130397. };
  130398. static float _vq_quantthresh__16u2_p1_0[] = {
  130399. -0.5, 0.5,
  130400. };
  130401. static long _vq_quantmap__16u2_p1_0[] = {
  130402. 1, 0, 2,
  130403. };
  130404. static encode_aux_threshmatch _vq_auxt__16u2_p1_0 = {
  130405. _vq_quantthresh__16u2_p1_0,
  130406. _vq_quantmap__16u2_p1_0,
  130407. 3,
  130408. 3
  130409. };
  130410. static static_codebook _16u2_p1_0 = {
  130411. 4, 81,
  130412. _vq_lengthlist__16u2_p1_0,
  130413. 1, -535822336, 1611661312, 2, 0,
  130414. _vq_quantlist__16u2_p1_0,
  130415. NULL,
  130416. &_vq_auxt__16u2_p1_0,
  130417. NULL,
  130418. 0
  130419. };
  130420. static long _vq_quantlist__16u2_p2_0[] = {
  130421. 2,
  130422. 1,
  130423. 3,
  130424. 0,
  130425. 4,
  130426. };
  130427. static long _vq_lengthlist__16u2_p2_0[] = {
  130428. 3, 5, 5, 8, 8, 5, 7, 7, 9, 9, 5, 7, 7, 9, 9, 9,
  130429. 10, 9,11,11, 9, 9, 9,11,11, 5, 7, 7, 9, 9, 7, 8,
  130430. 8,10,10, 7, 8, 8,10,10,10,10,10,12,12, 9,10,10,
  130431. 11,12, 5, 7, 7, 9, 9, 7, 8, 8,10,10, 7, 8, 8,10,
  130432. 10, 9,10,10,12,11,10,10,10,12,12, 9,10,10,12,12,
  130433. 10,11,10,13,12, 9,10,10,12,12,12,12,12,14,14,11,
  130434. 12,12,13,14, 9,10,10,12,12, 9,10,10,12,12,10,10,
  130435. 10,12,12,11,12,12,14,13,12,13,12,14,14, 5, 7, 7,
  130436. 9, 9, 7, 8, 8,10,10, 7, 8, 8,10,10,10,11,10,12,
  130437. 12,10,10,11,12,12, 7, 8, 8,10,10, 8, 9, 9,11,11,
  130438. 8, 9, 9,11,11,11,11,11,12,13,10,11,11,12,13, 7,
  130439. 8, 8,10,10, 8, 9, 8,11,10, 8, 9, 9,11,11,10,11,
  130440. 10,13,12,10,11,11,13,13, 9,11,10,13,13,10,11,11,
  130441. 13,13,10,11,11,13,13,12,12,13,13,15,12,12,13,14,
  130442. 15, 9,10,10,12,12,10,11,10,13,12,10,11,11,13,13,
  130443. 11,13,11,14,13,12,13,13,15,15, 5, 7, 7, 9, 9, 7,
  130444. 8, 8,10,10, 7, 8, 8,10,10,10,10,10,12,12,10,10,
  130445. 11,12,12, 7, 8, 8,10,10, 8, 9, 9,11,11, 8, 8, 9,
  130446. 10,11,10,11,11,13,13,10,10,11,12,13, 7, 8, 8,10,
  130447. 11, 8, 9, 9,11,11, 8, 9, 9,11,11,10,11,11,13,12,
  130448. 11,11,11,13,12, 9,10,10,12,12,10,11,11,13,13,10,
  130449. 10,11,12,13,12,13,13,15,14,11,11,13,12,14,10,10,
  130450. 11,13,13,10,11,11,13,13,10,11,11,13,13,12,13,13,
  130451. 14,14,12,13,12,14,13, 8,10, 9,12,12, 9,11,10,13,
  130452. 13, 9,10,10,12,13,12,13,13,14,14,12,12,13,14,14,
  130453. 9,11,10,13,13,10,11,11,13,13,10,11,11,13,13,12,
  130454. 13,13,15,15,13,13,13,14,15, 9,10,10,12,13,10,11,
  130455. 10,13,12,10,11,11,13,13,12,13,12,15,14,13,13,13,
  130456. 14,15,11,12,12,15,14,12,12,13,15,15,12,13,13,15,
  130457. 14,14,13,15,14,16,13,14,15,16,16,11,12,12,14,14,
  130458. 11,12,12,15,14,12,13,13,15,15,13,14,13,16,14,14,
  130459. 14,14,16,16, 8, 9, 9,12,12, 9,10,10,13,12, 9,10,
  130460. 10,13,13,12,12,12,14,14,12,12,13,15,15, 9,10,10,
  130461. 13,12,10,11,11,13,13,10,10,11,13,14,12,13,13,15,
  130462. 15,12,12,13,14,15, 9,10,10,13,13,10,11,11,13,13,
  130463. 10,11,11,13,13,12,13,13,14,14,13,14,13,15,14,11,
  130464. 12,12,14,14,12,13,13,15,14,11,12,12,14,15,14,14,
  130465. 14,16,15,13,12,14,14,16,11,12,13,14,15,12,13,13,
  130466. 14,16,12,13,12,15,14,13,15,14,16,16,14,15,13,16,
  130467. 13,
  130468. };
  130469. static float _vq_quantthresh__16u2_p2_0[] = {
  130470. -1.5, -0.5, 0.5, 1.5,
  130471. };
  130472. static long _vq_quantmap__16u2_p2_0[] = {
  130473. 3, 1, 0, 2, 4,
  130474. };
  130475. static encode_aux_threshmatch _vq_auxt__16u2_p2_0 = {
  130476. _vq_quantthresh__16u2_p2_0,
  130477. _vq_quantmap__16u2_p2_0,
  130478. 5,
  130479. 5
  130480. };
  130481. static static_codebook _16u2_p2_0 = {
  130482. 4, 625,
  130483. _vq_lengthlist__16u2_p2_0,
  130484. 1, -533725184, 1611661312, 3, 0,
  130485. _vq_quantlist__16u2_p2_0,
  130486. NULL,
  130487. &_vq_auxt__16u2_p2_0,
  130488. NULL,
  130489. 0
  130490. };
  130491. static long _vq_quantlist__16u2_p3_0[] = {
  130492. 4,
  130493. 3,
  130494. 5,
  130495. 2,
  130496. 6,
  130497. 1,
  130498. 7,
  130499. 0,
  130500. 8,
  130501. };
  130502. static long _vq_lengthlist__16u2_p3_0[] = {
  130503. 2, 4, 4, 6, 6, 7, 7, 9, 9, 4, 5, 5, 6, 6, 8, 7,
  130504. 9, 9, 4, 5, 5, 6, 6, 7, 8, 9, 9, 6, 6, 6, 7, 7,
  130505. 8, 8,10,10, 6, 6, 6, 7, 7, 8, 8, 9,10, 7, 8, 7,
  130506. 8, 8, 9, 9,10,10, 7, 8, 8, 8, 8, 9, 9,10,10, 9,
  130507. 9, 9,10, 9,10,10,11,11, 9, 9, 9,10,10,10,10,11,
  130508. 11,
  130509. };
  130510. static float _vq_quantthresh__16u2_p3_0[] = {
  130511. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  130512. };
  130513. static long _vq_quantmap__16u2_p3_0[] = {
  130514. 7, 5, 3, 1, 0, 2, 4, 6,
  130515. 8,
  130516. };
  130517. static encode_aux_threshmatch _vq_auxt__16u2_p3_0 = {
  130518. _vq_quantthresh__16u2_p3_0,
  130519. _vq_quantmap__16u2_p3_0,
  130520. 9,
  130521. 9
  130522. };
  130523. static static_codebook _16u2_p3_0 = {
  130524. 2, 81,
  130525. _vq_lengthlist__16u2_p3_0,
  130526. 1, -531628032, 1611661312, 4, 0,
  130527. _vq_quantlist__16u2_p3_0,
  130528. NULL,
  130529. &_vq_auxt__16u2_p3_0,
  130530. NULL,
  130531. 0
  130532. };
  130533. static long _vq_quantlist__16u2_p4_0[] = {
  130534. 8,
  130535. 7,
  130536. 9,
  130537. 6,
  130538. 10,
  130539. 5,
  130540. 11,
  130541. 4,
  130542. 12,
  130543. 3,
  130544. 13,
  130545. 2,
  130546. 14,
  130547. 1,
  130548. 15,
  130549. 0,
  130550. 16,
  130551. };
  130552. static long _vq_lengthlist__16u2_p4_0[] = {
  130553. 2, 4, 4, 6, 6, 7, 7, 8, 8, 9, 9,10,10,11,11,11,
  130554. 11, 5, 5, 5, 7, 7, 8, 8, 9, 9, 9, 9,10,10,11,11,
  130555. 12,11, 5, 5, 5, 7, 7, 8, 8, 9, 9, 9, 9,10,10,11,
  130556. 11,12,12, 6, 7, 7, 7, 7, 8, 8, 9, 9, 9, 9,10,10,
  130557. 11,11,12,12, 6, 7, 7, 7, 7, 8, 8, 9, 9, 9, 9,10,
  130558. 10,11,11,12,12, 7, 8, 8, 8, 8, 9, 9, 9, 9,10,10,
  130559. 11,11,12,12,12,12, 7, 8, 8, 8, 8, 9, 9, 9, 9,10,
  130560. 10,11,11,11,12,12,12, 9, 9, 9, 9, 9, 9,10,10,10,
  130561. 10,10,11,11,12,12,13,13, 8, 9, 9, 9, 9,10, 9,10,
  130562. 10,10,10,11,11,12,12,13,13, 9, 9, 9, 9, 9,10,10,
  130563. 10,10,11,11,11,12,12,12,13,13, 9, 9, 9, 9, 9,10,
  130564. 10,10,10,11,11,12,11,12,12,13,13,10,10,10,10,10,
  130565. 11,11,11,11,11,12,12,12,12,13,13,14,10,10,10,10,
  130566. 10,11,11,11,11,12,11,12,12,13,12,13,13,11,11,11,
  130567. 11,11,12,12,12,12,12,12,13,13,13,13,14,14,11,11,
  130568. 11,11,11,12,12,12,12,12,12,13,12,13,13,14,14,11,
  130569. 12,12,12,12,12,12,13,13,13,13,13,13,14,14,14,14,
  130570. 11,12,12,12,12,12,12,13,13,13,13,14,13,14,14,14,
  130571. 14,
  130572. };
  130573. static float _vq_quantthresh__16u2_p4_0[] = {
  130574. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  130575. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  130576. };
  130577. static long _vq_quantmap__16u2_p4_0[] = {
  130578. 15, 13, 11, 9, 7, 5, 3, 1,
  130579. 0, 2, 4, 6, 8, 10, 12, 14,
  130580. 16,
  130581. };
  130582. static encode_aux_threshmatch _vq_auxt__16u2_p4_0 = {
  130583. _vq_quantthresh__16u2_p4_0,
  130584. _vq_quantmap__16u2_p4_0,
  130585. 17,
  130586. 17
  130587. };
  130588. static static_codebook _16u2_p4_0 = {
  130589. 2, 289,
  130590. _vq_lengthlist__16u2_p4_0,
  130591. 1, -529530880, 1611661312, 5, 0,
  130592. _vq_quantlist__16u2_p4_0,
  130593. NULL,
  130594. &_vq_auxt__16u2_p4_0,
  130595. NULL,
  130596. 0
  130597. };
  130598. static long _vq_quantlist__16u2_p5_0[] = {
  130599. 1,
  130600. 0,
  130601. 2,
  130602. };
  130603. static long _vq_lengthlist__16u2_p5_0[] = {
  130604. 1, 4, 4, 5, 7, 7, 5, 7, 7, 5, 9, 8, 7,10, 9, 7,
  130605. 10, 9, 5, 8, 9, 7, 9,10, 7, 9,10, 4, 9, 9, 9,11,
  130606. 11, 8,11,11, 7,11,11,10,10,13,10,14,13, 7,11,11,
  130607. 10,13,11,10,13,14, 5, 9, 9, 8,11,11, 9,11,11, 7,
  130608. 11,11,10,14,13,10,12,14, 7,11,11,10,13,13,10,13,
  130609. 10,
  130610. };
  130611. static float _vq_quantthresh__16u2_p5_0[] = {
  130612. -5.5, 5.5,
  130613. };
  130614. static long _vq_quantmap__16u2_p5_0[] = {
  130615. 1, 0, 2,
  130616. };
  130617. static encode_aux_threshmatch _vq_auxt__16u2_p5_0 = {
  130618. _vq_quantthresh__16u2_p5_0,
  130619. _vq_quantmap__16u2_p5_0,
  130620. 3,
  130621. 3
  130622. };
  130623. static static_codebook _16u2_p5_0 = {
  130624. 4, 81,
  130625. _vq_lengthlist__16u2_p5_0,
  130626. 1, -529137664, 1618345984, 2, 0,
  130627. _vq_quantlist__16u2_p5_0,
  130628. NULL,
  130629. &_vq_auxt__16u2_p5_0,
  130630. NULL,
  130631. 0
  130632. };
  130633. static long _vq_quantlist__16u2_p5_1[] = {
  130634. 5,
  130635. 4,
  130636. 6,
  130637. 3,
  130638. 7,
  130639. 2,
  130640. 8,
  130641. 1,
  130642. 9,
  130643. 0,
  130644. 10,
  130645. };
  130646. static long _vq_lengthlist__16u2_p5_1[] = {
  130647. 2, 5, 5, 6, 6, 7, 7, 8, 8, 8, 8, 5, 5, 5, 7, 7,
  130648. 7, 7, 8, 8, 8, 8, 5, 5, 6, 7, 7, 7, 7, 8, 8, 8,
  130649. 8, 6, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 6, 7, 7, 7,
  130650. 7, 8, 8, 8, 8, 8, 8, 7, 7, 7, 8, 8, 8, 8, 9, 9,
  130651. 9, 9, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 8, 8, 8,
  130652. 8, 8, 9, 9, 9, 9, 9, 9, 8, 8, 8, 8, 8, 9, 9, 9,
  130653. 9, 9, 9, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 8, 8,
  130654. 8, 8, 8, 9, 9, 9, 9, 9, 9,
  130655. };
  130656. static float _vq_quantthresh__16u2_p5_1[] = {
  130657. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  130658. 3.5, 4.5,
  130659. };
  130660. static long _vq_quantmap__16u2_p5_1[] = {
  130661. 9, 7, 5, 3, 1, 0, 2, 4,
  130662. 6, 8, 10,
  130663. };
  130664. static encode_aux_threshmatch _vq_auxt__16u2_p5_1 = {
  130665. _vq_quantthresh__16u2_p5_1,
  130666. _vq_quantmap__16u2_p5_1,
  130667. 11,
  130668. 11
  130669. };
  130670. static static_codebook _16u2_p5_1 = {
  130671. 2, 121,
  130672. _vq_lengthlist__16u2_p5_1,
  130673. 1, -531365888, 1611661312, 4, 0,
  130674. _vq_quantlist__16u2_p5_1,
  130675. NULL,
  130676. &_vq_auxt__16u2_p5_1,
  130677. NULL,
  130678. 0
  130679. };
  130680. static long _vq_quantlist__16u2_p6_0[] = {
  130681. 6,
  130682. 5,
  130683. 7,
  130684. 4,
  130685. 8,
  130686. 3,
  130687. 9,
  130688. 2,
  130689. 10,
  130690. 1,
  130691. 11,
  130692. 0,
  130693. 12,
  130694. };
  130695. static long _vq_lengthlist__16u2_p6_0[] = {
  130696. 1, 4, 4, 7, 7, 8, 8, 8, 8, 9, 9,10,10, 4, 6, 6,
  130697. 8, 8, 9, 9, 9, 9,10,10,12,11, 4, 6, 6, 8, 8, 9,
  130698. 9, 9, 9,10,10,11,12, 7, 8, 8, 9, 9,10,10,10,10,
  130699. 12,12,13,12, 7, 8, 8, 9, 9,10,10,10,10,11,12,12,
  130700. 12, 8, 9, 9,10,10,11,11,11,11,12,12,13,13, 8, 9,
  130701. 9,10,10,11,11,11,11,12,13,13,13, 8, 9, 9,10,10,
  130702. 11,11,12,12,13,13,14,14, 8, 9, 9,10,10,11,11,12,
  130703. 12,13,13,14,14, 9,10,10,11,12,13,12,13,14,14,14,
  130704. 14,14, 9,10,10,11,12,12,13,13,13,14,14,14,14,10,
  130705. 11,11,12,12,13,13,14,14,15,15,15,15,10,11,11,12,
  130706. 12,13,13,14,14,14,14,15,15,
  130707. };
  130708. static float _vq_quantthresh__16u2_p6_0[] = {
  130709. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  130710. 12.5, 17.5, 22.5, 27.5,
  130711. };
  130712. static long _vq_quantmap__16u2_p6_0[] = {
  130713. 11, 9, 7, 5, 3, 1, 0, 2,
  130714. 4, 6, 8, 10, 12,
  130715. };
  130716. static encode_aux_threshmatch _vq_auxt__16u2_p6_0 = {
  130717. _vq_quantthresh__16u2_p6_0,
  130718. _vq_quantmap__16u2_p6_0,
  130719. 13,
  130720. 13
  130721. };
  130722. static static_codebook _16u2_p6_0 = {
  130723. 2, 169,
  130724. _vq_lengthlist__16u2_p6_0,
  130725. 1, -526516224, 1616117760, 4, 0,
  130726. _vq_quantlist__16u2_p6_0,
  130727. NULL,
  130728. &_vq_auxt__16u2_p6_0,
  130729. NULL,
  130730. 0
  130731. };
  130732. static long _vq_quantlist__16u2_p6_1[] = {
  130733. 2,
  130734. 1,
  130735. 3,
  130736. 0,
  130737. 4,
  130738. };
  130739. static long _vq_lengthlist__16u2_p6_1[] = {
  130740. 2, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
  130741. 5, 5, 6, 6, 5, 5, 5, 6, 6,
  130742. };
  130743. static float _vq_quantthresh__16u2_p6_1[] = {
  130744. -1.5, -0.5, 0.5, 1.5,
  130745. };
  130746. static long _vq_quantmap__16u2_p6_1[] = {
  130747. 3, 1, 0, 2, 4,
  130748. };
  130749. static encode_aux_threshmatch _vq_auxt__16u2_p6_1 = {
  130750. _vq_quantthresh__16u2_p6_1,
  130751. _vq_quantmap__16u2_p6_1,
  130752. 5,
  130753. 5
  130754. };
  130755. static static_codebook _16u2_p6_1 = {
  130756. 2, 25,
  130757. _vq_lengthlist__16u2_p6_1,
  130758. 1, -533725184, 1611661312, 3, 0,
  130759. _vq_quantlist__16u2_p6_1,
  130760. NULL,
  130761. &_vq_auxt__16u2_p6_1,
  130762. NULL,
  130763. 0
  130764. };
  130765. static long _vq_quantlist__16u2_p7_0[] = {
  130766. 6,
  130767. 5,
  130768. 7,
  130769. 4,
  130770. 8,
  130771. 3,
  130772. 9,
  130773. 2,
  130774. 10,
  130775. 1,
  130776. 11,
  130777. 0,
  130778. 12,
  130779. };
  130780. static long _vq_lengthlist__16u2_p7_0[] = {
  130781. 1, 4, 4, 7, 7, 7, 7, 8, 8, 9, 9,10,10, 4, 6, 6,
  130782. 9, 9, 9, 9, 9, 9,10,10,11,11, 4, 6, 6, 8, 9, 9,
  130783. 9, 9, 9,10,11,12,11, 7, 8, 9,10,10,10,10,11,10,
  130784. 11,12,12,13, 7, 9, 9,10,10,10,10,10,10,11,12,13,
  130785. 13, 7, 9, 8,10,10,11,11,11,12,12,13,13,14, 7, 9,
  130786. 9,10,10,11,11,11,12,13,13,13,13, 8, 9, 9,10,11,
  130787. 11,12,12,12,13,13,13,13, 8, 9, 9,10,11,11,11,12,
  130788. 12,13,13,14,14, 9,10,10,12,11,12,13,13,13,14,13,
  130789. 13,13, 9,10,10,11,11,12,12,13,14,13,13,14,13,10,
  130790. 11,11,12,13,14,14,14,15,14,14,14,14,10,11,11,12,
  130791. 12,13,13,13,14,14,14,15,14,
  130792. };
  130793. static float _vq_quantthresh__16u2_p7_0[] = {
  130794. -60.5, -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5,
  130795. 27.5, 38.5, 49.5, 60.5,
  130796. };
  130797. static long _vq_quantmap__16u2_p7_0[] = {
  130798. 11, 9, 7, 5, 3, 1, 0, 2,
  130799. 4, 6, 8, 10, 12,
  130800. };
  130801. static encode_aux_threshmatch _vq_auxt__16u2_p7_0 = {
  130802. _vq_quantthresh__16u2_p7_0,
  130803. _vq_quantmap__16u2_p7_0,
  130804. 13,
  130805. 13
  130806. };
  130807. static static_codebook _16u2_p7_0 = {
  130808. 2, 169,
  130809. _vq_lengthlist__16u2_p7_0,
  130810. 1, -523206656, 1618345984, 4, 0,
  130811. _vq_quantlist__16u2_p7_0,
  130812. NULL,
  130813. &_vq_auxt__16u2_p7_0,
  130814. NULL,
  130815. 0
  130816. };
  130817. static long _vq_quantlist__16u2_p7_1[] = {
  130818. 5,
  130819. 4,
  130820. 6,
  130821. 3,
  130822. 7,
  130823. 2,
  130824. 8,
  130825. 1,
  130826. 9,
  130827. 0,
  130828. 10,
  130829. };
  130830. static long _vq_lengthlist__16u2_p7_1[] = {
  130831. 3, 5, 5, 6, 6, 7, 7, 7, 7, 7, 7, 5, 6, 6, 7, 7,
  130832. 7, 7, 7, 7, 8, 8, 5, 6, 6, 6, 6, 7, 7, 7, 7, 8,
  130833. 8, 6, 6, 7, 7, 7, 8, 7, 8, 8, 8, 8, 6, 7, 7, 7,
  130834. 7, 7, 7, 8, 8, 8, 8, 7, 7, 7, 7, 7, 8, 8, 8, 8,
  130835. 8, 8, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 7, 7, 7,
  130836. 8, 8, 8, 8, 8, 8, 8, 8, 7, 7, 7, 8, 8, 8, 8, 8,
  130837. 8, 8, 8, 7, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 7, 8,
  130838. 8, 8, 8, 8, 8, 8, 8, 8, 8,
  130839. };
  130840. static float _vq_quantthresh__16u2_p7_1[] = {
  130841. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  130842. 3.5, 4.5,
  130843. };
  130844. static long _vq_quantmap__16u2_p7_1[] = {
  130845. 9, 7, 5, 3, 1, 0, 2, 4,
  130846. 6, 8, 10,
  130847. };
  130848. static encode_aux_threshmatch _vq_auxt__16u2_p7_1 = {
  130849. _vq_quantthresh__16u2_p7_1,
  130850. _vq_quantmap__16u2_p7_1,
  130851. 11,
  130852. 11
  130853. };
  130854. static static_codebook _16u2_p7_1 = {
  130855. 2, 121,
  130856. _vq_lengthlist__16u2_p7_1,
  130857. 1, -531365888, 1611661312, 4, 0,
  130858. _vq_quantlist__16u2_p7_1,
  130859. NULL,
  130860. &_vq_auxt__16u2_p7_1,
  130861. NULL,
  130862. 0
  130863. };
  130864. static long _vq_quantlist__16u2_p8_0[] = {
  130865. 7,
  130866. 6,
  130867. 8,
  130868. 5,
  130869. 9,
  130870. 4,
  130871. 10,
  130872. 3,
  130873. 11,
  130874. 2,
  130875. 12,
  130876. 1,
  130877. 13,
  130878. 0,
  130879. 14,
  130880. };
  130881. static long _vq_lengthlist__16u2_p8_0[] = {
  130882. 1, 5, 5, 7, 7, 8, 8, 7, 7, 8, 8,10, 9,11,11, 4,
  130883. 6, 6, 8, 8,10, 9, 9, 8, 9, 9,10,10,12,14, 4, 6,
  130884. 7, 8, 9, 9,10, 9, 8, 9, 9,10,12,12,11, 7, 8, 8,
  130885. 10,10,10,10, 9, 9,10,10,11,13,13,12, 7, 8, 8, 9,
  130886. 11,11,10, 9, 9,11,10,12,11,11,14, 8, 9, 9,11,10,
  130887. 11,11,10,10,11,11,13,12,14,12, 8, 9, 9,11,12,11,
  130888. 11,10,10,12,11,12,12,12,14, 7, 8, 8, 9, 9,10,10,
  130889. 10,11,12,11,13,13,14,12, 7, 8, 9, 9, 9,10,10,11,
  130890. 11,11,12,12,14,14,14, 8,10, 9,10,11,11,11,11,14,
  130891. 12,12,13,14,14,13, 9, 9, 9,10,11,11,11,12,12,12,
  130892. 14,12,14,13,14,10,10,10,12,11,12,11,14,13,14,13,
  130893. 14,14,13,14, 9,10,10,11,12,11,13,12,13,13,14,14,
  130894. 14,13,14,10,13,13,12,12,11,12,14,13,14,13,14,12,
  130895. 14,13,10,11,11,12,11,12,12,14,14,14,13,14,14,14,
  130896. 14,
  130897. };
  130898. static float _vq_quantthresh__16u2_p8_0[] = {
  130899. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  130900. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  130901. };
  130902. static long _vq_quantmap__16u2_p8_0[] = {
  130903. 13, 11, 9, 7, 5, 3, 1, 0,
  130904. 2, 4, 6, 8, 10, 12, 14,
  130905. };
  130906. static encode_aux_threshmatch _vq_auxt__16u2_p8_0 = {
  130907. _vq_quantthresh__16u2_p8_0,
  130908. _vq_quantmap__16u2_p8_0,
  130909. 15,
  130910. 15
  130911. };
  130912. static static_codebook _16u2_p8_0 = {
  130913. 2, 225,
  130914. _vq_lengthlist__16u2_p8_0,
  130915. 1, -520986624, 1620377600, 4, 0,
  130916. _vq_quantlist__16u2_p8_0,
  130917. NULL,
  130918. &_vq_auxt__16u2_p8_0,
  130919. NULL,
  130920. 0
  130921. };
  130922. static long _vq_quantlist__16u2_p8_1[] = {
  130923. 10,
  130924. 9,
  130925. 11,
  130926. 8,
  130927. 12,
  130928. 7,
  130929. 13,
  130930. 6,
  130931. 14,
  130932. 5,
  130933. 15,
  130934. 4,
  130935. 16,
  130936. 3,
  130937. 17,
  130938. 2,
  130939. 18,
  130940. 1,
  130941. 19,
  130942. 0,
  130943. 20,
  130944. };
  130945. static long _vq_lengthlist__16u2_p8_1[] = {
  130946. 2, 5, 5, 7, 7, 8, 8, 8, 8, 9, 9,10, 9,10, 9, 9,
  130947. 9,10,10,10,10, 5, 6, 6, 7, 7, 8, 8, 9, 9, 9, 9,
  130948. 10, 9,10,10,10,10,10,10,11,10, 5, 6, 6, 7, 7, 8,
  130949. 8, 8, 9, 9,10,10,10,10,10,10,10,10,10,10,10, 7,
  130950. 7, 7, 8, 8, 9, 8, 9, 9,10, 9,10,10,10,10,10,10,
  130951. 11,10,11,10, 7, 7, 7, 8, 8, 8, 9, 9, 9,10, 9,10,
  130952. 10,10,10,10,10,10,10,10,10, 8, 8, 8, 9, 9, 9, 9,
  130953. 10, 9,10,10,10,10,10,10,10,11,10,10,11,10, 8, 8,
  130954. 8, 8, 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,11,
  130955. 11,10,10, 8, 9, 9, 9, 9, 9, 9,10,10,10,10,10,10,
  130956. 11,10,11,10,11,10,11,10, 8, 9, 9, 9, 9, 9,10,10,
  130957. 10,10,10,10,10,10,10,10,11,11,10,10,10, 9,10, 9,
  130958. 9,10,10,10,11,10,10,10,10,10,10,10,10,11,11,11,
  130959. 11,11, 9, 9, 9,10, 9,10,10,10,10,10,10,11,10,11,
  130960. 10,11,11,11,11,10,10, 9,10, 9,10,10,10,10,11,10,
  130961. 10,10,10,10,11,10,11,10,11,10,10,11, 9,10,10,10,
  130962. 10,10,10,10,10,10,11,10,10,11,11,10,11,11,11,11,
  130963. 11, 9, 9,10,10,10,10,10,11,10,10,11,10,10,11,10,
  130964. 10,11,11,11,11,11, 9,10,10,10,10,10,10,10,11,10,
  130965. 11,10,11,10,11,11,11,11,11,10,11,10,10,10,10,10,
  130966. 10,10,10,10,11,11,11,11,11,11,11,11,11,10,11,11,
  130967. 10,10,10,10,10,11,10,10,10,11,10,11,11,11,11,10,
  130968. 12,11,11,11,10,10,10,10,10,10,11,10,10,10,11,11,
  130969. 12,11,11,11,11,11,11,11,11,11,10,10,10,11,10,11,
  130970. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,10,
  130971. 10,10,11,10,11,10,10,11,11,11,11,11,11,11,11,11,
  130972. 11,11,11,10,10,10,10,10,10,10,11,11,10,11,11,10,
  130973. 11,11,10,11,11,11,10,11,11,
  130974. };
  130975. static float _vq_quantthresh__16u2_p8_1[] = {
  130976. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  130977. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  130978. 6.5, 7.5, 8.5, 9.5,
  130979. };
  130980. static long _vq_quantmap__16u2_p8_1[] = {
  130981. 19, 17, 15, 13, 11, 9, 7, 5,
  130982. 3, 1, 0, 2, 4, 6, 8, 10,
  130983. 12, 14, 16, 18, 20,
  130984. };
  130985. static encode_aux_threshmatch _vq_auxt__16u2_p8_1 = {
  130986. _vq_quantthresh__16u2_p8_1,
  130987. _vq_quantmap__16u2_p8_1,
  130988. 21,
  130989. 21
  130990. };
  130991. static static_codebook _16u2_p8_1 = {
  130992. 2, 441,
  130993. _vq_lengthlist__16u2_p8_1,
  130994. 1, -529268736, 1611661312, 5, 0,
  130995. _vq_quantlist__16u2_p8_1,
  130996. NULL,
  130997. &_vq_auxt__16u2_p8_1,
  130998. NULL,
  130999. 0
  131000. };
  131001. static long _vq_quantlist__16u2_p9_0[] = {
  131002. 5586,
  131003. 4655,
  131004. 6517,
  131005. 3724,
  131006. 7448,
  131007. 2793,
  131008. 8379,
  131009. 1862,
  131010. 9310,
  131011. 931,
  131012. 10241,
  131013. 0,
  131014. 11172,
  131015. 5521,
  131016. 5651,
  131017. };
  131018. static long _vq_lengthlist__16u2_p9_0[] = {
  131019. 1,10,10,10,10,10,10,10,10,10,10,10,10, 5, 4,10,
  131020. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  131021. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  131022. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  131023. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  131024. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  131025. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  131026. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  131027. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  131028. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  131029. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  131030. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  131031. 10,10,10, 4,10,10,10,10,10,10,10,10,10,10,10,10,
  131032. 6, 6, 5,10,10,10,10, 9, 9, 9, 9, 9, 9, 9, 9, 5,
  131033. 5,
  131034. };
  131035. static float _vq_quantthresh__16u2_p9_0[] = {
  131036. -5120.5, -4189.5, -3258.5, -2327.5, -1396.5, -498, -32.5, 32.5,
  131037. 498, 1396.5, 2327.5, 3258.5, 4189.5, 5120.5,
  131038. };
  131039. static long _vq_quantmap__16u2_p9_0[] = {
  131040. 11, 9, 7, 5, 3, 1, 13, 0,
  131041. 14, 2, 4, 6, 8, 10, 12,
  131042. };
  131043. static encode_aux_threshmatch _vq_auxt__16u2_p9_0 = {
  131044. _vq_quantthresh__16u2_p9_0,
  131045. _vq_quantmap__16u2_p9_0,
  131046. 15,
  131047. 15
  131048. };
  131049. static static_codebook _16u2_p9_0 = {
  131050. 2, 225,
  131051. _vq_lengthlist__16u2_p9_0,
  131052. 1, -510275072, 1611661312, 14, 0,
  131053. _vq_quantlist__16u2_p9_0,
  131054. NULL,
  131055. &_vq_auxt__16u2_p9_0,
  131056. NULL,
  131057. 0
  131058. };
  131059. static long _vq_quantlist__16u2_p9_1[] = {
  131060. 392,
  131061. 343,
  131062. 441,
  131063. 294,
  131064. 490,
  131065. 245,
  131066. 539,
  131067. 196,
  131068. 588,
  131069. 147,
  131070. 637,
  131071. 98,
  131072. 686,
  131073. 49,
  131074. 735,
  131075. 0,
  131076. 784,
  131077. 388,
  131078. 396,
  131079. };
  131080. static long _vq_lengthlist__16u2_p9_1[] = {
  131081. 1,12,10,12,10,12,10,12,11,12,12,12,12,12,12,12,
  131082. 12, 5, 5, 9,10,12,11,11,12,12,12,12,12,12,12,12,
  131083. 12,12,12,12,10, 9, 9,11, 9,11,11,12,11,12,12,12,
  131084. 12,12,12,12,12,12,12, 8, 8,10,11, 9,12,11,12,12,
  131085. 12,12,12,12,12,12,12,12,12,12, 9, 8,10,11,12,11,
  131086. 12,11,12,12,12,12,12,12,12,12,12,12,12, 8, 9,11,
  131087. 11,10,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  131088. 9,10,11,12,11,12,11,12,12,12,12,12,12,12,12,12,
  131089. 12,12,12, 9, 9,11,12,12,12,12,12,12,12,12,12,12,
  131090. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  131091. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  131092. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  131093. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  131094. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  131095. 12,12,12,12,11,11,11,11,11,11,11,11,11,11,11,11,
  131096. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131097. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131098. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131099. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131100. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131101. 11,11,11, 5, 8, 9, 9, 8,11, 9,11,11,11,11,11,11,
  131102. 11,11,11,11, 5, 5, 4, 8, 8, 8, 8,10, 9,10,10,11,
  131103. 11,11,11,11,11,11,11, 5, 4,
  131104. };
  131105. static float _vq_quantthresh__16u2_p9_1[] = {
  131106. -367.5, -318.5, -269.5, -220.5, -171.5, -122.5, -73.5, -26.5,
  131107. -2, 2, 26.5, 73.5, 122.5, 171.5, 220.5, 269.5,
  131108. 318.5, 367.5,
  131109. };
  131110. static long _vq_quantmap__16u2_p9_1[] = {
  131111. 15, 13, 11, 9, 7, 5, 3, 1,
  131112. 17, 0, 18, 2, 4, 6, 8, 10,
  131113. 12, 14, 16,
  131114. };
  131115. static encode_aux_threshmatch _vq_auxt__16u2_p9_1 = {
  131116. _vq_quantthresh__16u2_p9_1,
  131117. _vq_quantmap__16u2_p9_1,
  131118. 19,
  131119. 19
  131120. };
  131121. static static_codebook _16u2_p9_1 = {
  131122. 2, 361,
  131123. _vq_lengthlist__16u2_p9_1,
  131124. 1, -518488064, 1611661312, 10, 0,
  131125. _vq_quantlist__16u2_p9_1,
  131126. NULL,
  131127. &_vq_auxt__16u2_p9_1,
  131128. NULL,
  131129. 0
  131130. };
  131131. static long _vq_quantlist__16u2_p9_2[] = {
  131132. 24,
  131133. 23,
  131134. 25,
  131135. 22,
  131136. 26,
  131137. 21,
  131138. 27,
  131139. 20,
  131140. 28,
  131141. 19,
  131142. 29,
  131143. 18,
  131144. 30,
  131145. 17,
  131146. 31,
  131147. 16,
  131148. 32,
  131149. 15,
  131150. 33,
  131151. 14,
  131152. 34,
  131153. 13,
  131154. 35,
  131155. 12,
  131156. 36,
  131157. 11,
  131158. 37,
  131159. 10,
  131160. 38,
  131161. 9,
  131162. 39,
  131163. 8,
  131164. 40,
  131165. 7,
  131166. 41,
  131167. 6,
  131168. 42,
  131169. 5,
  131170. 43,
  131171. 4,
  131172. 44,
  131173. 3,
  131174. 45,
  131175. 2,
  131176. 46,
  131177. 1,
  131178. 47,
  131179. 0,
  131180. 48,
  131181. };
  131182. static long _vq_lengthlist__16u2_p9_2[] = {
  131183. 1, 3, 3, 4, 7, 7, 7, 8, 7, 7, 7, 7, 8, 8, 8, 8,
  131184. 7, 8, 8, 8, 8, 8, 8, 8, 8, 8, 7, 9, 9, 8, 9, 9,
  131185. 9, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,12,12,10,
  131186. 11,
  131187. };
  131188. static float _vq_quantthresh__16u2_p9_2[] = {
  131189. -23.5, -22.5, -21.5, -20.5, -19.5, -18.5, -17.5, -16.5,
  131190. -15.5, -14.5, -13.5, -12.5, -11.5, -10.5, -9.5, -8.5,
  131191. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  131192. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  131193. 8.5, 9.5, 10.5, 11.5, 12.5, 13.5, 14.5, 15.5,
  131194. 16.5, 17.5, 18.5, 19.5, 20.5, 21.5, 22.5, 23.5,
  131195. };
  131196. static long _vq_quantmap__16u2_p9_2[] = {
  131197. 47, 45, 43, 41, 39, 37, 35, 33,
  131198. 31, 29, 27, 25, 23, 21, 19, 17,
  131199. 15, 13, 11, 9, 7, 5, 3, 1,
  131200. 0, 2, 4, 6, 8, 10, 12, 14,
  131201. 16, 18, 20, 22, 24, 26, 28, 30,
  131202. 32, 34, 36, 38, 40, 42, 44, 46,
  131203. 48,
  131204. };
  131205. static encode_aux_threshmatch _vq_auxt__16u2_p9_2 = {
  131206. _vq_quantthresh__16u2_p9_2,
  131207. _vq_quantmap__16u2_p9_2,
  131208. 49,
  131209. 49
  131210. };
  131211. static static_codebook _16u2_p9_2 = {
  131212. 1, 49,
  131213. _vq_lengthlist__16u2_p9_2,
  131214. 1, -526909440, 1611661312, 6, 0,
  131215. _vq_quantlist__16u2_p9_2,
  131216. NULL,
  131217. &_vq_auxt__16u2_p9_2,
  131218. NULL,
  131219. 0
  131220. };
  131221. static long _vq_quantlist__8u0__p1_0[] = {
  131222. 1,
  131223. 0,
  131224. 2,
  131225. };
  131226. static long _vq_lengthlist__8u0__p1_0[] = {
  131227. 1, 4, 4, 5, 7, 7, 5, 7, 7, 5, 8, 8, 8,10,10, 7,
  131228. 10,10, 5, 8, 8, 7,10,10, 8,10,10, 4, 9, 8, 8,11,
  131229. 11, 8,11,11, 7,11,11,10,11,13,10,13,13, 7,11,11,
  131230. 10,13,12,10,13,13, 5, 9, 8, 8,11,11, 8,11,11, 7,
  131231. 11,11, 9,13,13,10,12,13, 7,11,11,10,13,13,10,13,
  131232. 11,
  131233. };
  131234. static float _vq_quantthresh__8u0__p1_0[] = {
  131235. -0.5, 0.5,
  131236. };
  131237. static long _vq_quantmap__8u0__p1_0[] = {
  131238. 1, 0, 2,
  131239. };
  131240. static encode_aux_threshmatch _vq_auxt__8u0__p1_0 = {
  131241. _vq_quantthresh__8u0__p1_0,
  131242. _vq_quantmap__8u0__p1_0,
  131243. 3,
  131244. 3
  131245. };
  131246. static static_codebook _8u0__p1_0 = {
  131247. 4, 81,
  131248. _vq_lengthlist__8u0__p1_0,
  131249. 1, -535822336, 1611661312, 2, 0,
  131250. _vq_quantlist__8u0__p1_0,
  131251. NULL,
  131252. &_vq_auxt__8u0__p1_0,
  131253. NULL,
  131254. 0
  131255. };
  131256. static long _vq_quantlist__8u0__p2_0[] = {
  131257. 1,
  131258. 0,
  131259. 2,
  131260. };
  131261. static long _vq_lengthlist__8u0__p2_0[] = {
  131262. 2, 4, 4, 5, 6, 6, 5, 6, 6, 5, 7, 7, 6, 7, 8, 6,
  131263. 7, 8, 5, 7, 7, 6, 8, 8, 7, 9, 7, 5, 7, 7, 7, 9,
  131264. 9, 7, 8, 8, 6, 9, 8, 7, 7,10, 8,10,10, 6, 8, 8,
  131265. 8,10, 8, 8,10,10, 5, 7, 7, 7, 8, 8, 7, 8, 9, 6,
  131266. 8, 8, 8,10,10, 8, 8,10, 6, 8, 9, 8,10,10, 7,10,
  131267. 8,
  131268. };
  131269. static float _vq_quantthresh__8u0__p2_0[] = {
  131270. -0.5, 0.5,
  131271. };
  131272. static long _vq_quantmap__8u0__p2_0[] = {
  131273. 1, 0, 2,
  131274. };
  131275. static encode_aux_threshmatch _vq_auxt__8u0__p2_0 = {
  131276. _vq_quantthresh__8u0__p2_0,
  131277. _vq_quantmap__8u0__p2_0,
  131278. 3,
  131279. 3
  131280. };
  131281. static static_codebook _8u0__p2_0 = {
  131282. 4, 81,
  131283. _vq_lengthlist__8u0__p2_0,
  131284. 1, -535822336, 1611661312, 2, 0,
  131285. _vq_quantlist__8u0__p2_0,
  131286. NULL,
  131287. &_vq_auxt__8u0__p2_0,
  131288. NULL,
  131289. 0
  131290. };
  131291. static long _vq_quantlist__8u0__p3_0[] = {
  131292. 2,
  131293. 1,
  131294. 3,
  131295. 0,
  131296. 4,
  131297. };
  131298. static long _vq_lengthlist__8u0__p3_0[] = {
  131299. 1, 5, 5, 7, 7, 6, 7, 7, 9, 9, 6, 7, 7, 9, 9, 8,
  131300. 10, 9,11,11, 8, 9, 9,11,11, 6, 8, 8,10,10, 8,10,
  131301. 10,11,11, 8,10,10,11,11,10,11,11,12,12,10,11,11,
  131302. 12,13, 6, 8, 8,10,10, 8,10,10,11,11, 8,10,10,11,
  131303. 11, 9,10,11,12,12,10,11,11,12,12, 8,11,11,14,13,
  131304. 10,12,11,15,13,10,12,11,14,14,12,13,12,16,14,12,
  131305. 14,12,16,15, 8,11,11,13,14,10,11,12,13,15,10,11,
  131306. 12,13,15,11,12,13,14,15,12,12,14,14,16, 5, 8, 8,
  131307. 11,11, 9,11,11,12,12, 8,10,11,12,12,11,12,12,15,
  131308. 14,11,12,12,14,14, 7,11,10,13,12,10,11,12,13,14,
  131309. 10,12,12,14,13,12,13,13,14,15,12,13,13,15,15, 7,
  131310. 10,11,12,13,10,12,11,14,13,10,12,13,13,15,12,13,
  131311. 12,14,14,11,13,13,15,16, 9,12,12,15,14,11,13,13,
  131312. 15,16,11,13,13,16,16,13,14,15,15,15,12,14,15,17,
  131313. 16, 9,12,12,14,15,11,13,13,15,16,11,13,13,16,18,
  131314. 13,14,14,17,16,13,15,15,17,18, 5, 8, 9,11,11, 8,
  131315. 11,11,12,12, 8,10,11,12,12,11,12,12,14,14,11,12,
  131316. 12,14,15, 7,11,10,12,13,10,12,12,14,13,10,11,12,
  131317. 13,14,11,13,13,15,14,12,13,13,14,15, 7,10,11,13,
  131318. 13,10,12,12,13,14,10,12,12,13,13,11,13,13,16,16,
  131319. 12,13,13,15,14, 9,12,12,16,15,10,13,13,15,15,11,
  131320. 13,13,17,15,12,15,15,18,17,13,14,14,15,16, 9,12,
  131321. 12,15,15,11,13,13,15,16,11,13,13,15,15,12,15,15,
  131322. 16,16,13,15,14,17,15, 7,11,11,15,15,10,13,13,16,
  131323. 15,10,13,13,15,16,14,15,15,17,19,13,15,14,15,18,
  131324. 9,12,12,16,16,11,13,14,17,16,11,13,13,17,16,15,
  131325. 15,16,17,19,13,15,16, 0,18, 9,12,12,16,15,11,14,
  131326. 13,17,17,11,13,14,16,16,15,16,16,19,18,13,15,15,
  131327. 17,19,11,14,14,19,16,12,14,15, 0,18,12,16,15,18,
  131328. 17,15,15,18,16,19,14,15,17,19,19,11,14,14,18,19,
  131329. 13,15,14,19,19,12,16,15,18,17,15,17,15, 0,16,14,
  131330. 17,16,19, 0, 7,11,11,14,14,10,12,12,15,15,10,13,
  131331. 13,16,15,13,15,15,17, 0,14,15,15,16,19, 9,12,12,
  131332. 16,16,11,14,14,16,16,11,13,13,16,16,14,17,16,19,
  131333. 0,14,18,17,17,19, 9,12,12,15,16,11,13,13,15,17,
  131334. 12,14,13,19,16,13,15,15,17,19,15,17,16,17,19,11,
  131335. 14,14,19,16,12,15,15,19,17,13,14,15,17,19,14,16,
  131336. 17,19,19,16,15,16,17,19,11,15,14,16,16,12,15,15,
  131337. 19, 0,12,14,15,19,19,14,16,16, 0,18,15,19,14,18,
  131338. 16,
  131339. };
  131340. static float _vq_quantthresh__8u0__p3_0[] = {
  131341. -1.5, -0.5, 0.5, 1.5,
  131342. };
  131343. static long _vq_quantmap__8u0__p3_0[] = {
  131344. 3, 1, 0, 2, 4,
  131345. };
  131346. static encode_aux_threshmatch _vq_auxt__8u0__p3_0 = {
  131347. _vq_quantthresh__8u0__p3_0,
  131348. _vq_quantmap__8u0__p3_0,
  131349. 5,
  131350. 5
  131351. };
  131352. static static_codebook _8u0__p3_0 = {
  131353. 4, 625,
  131354. _vq_lengthlist__8u0__p3_0,
  131355. 1, -533725184, 1611661312, 3, 0,
  131356. _vq_quantlist__8u0__p3_0,
  131357. NULL,
  131358. &_vq_auxt__8u0__p3_0,
  131359. NULL,
  131360. 0
  131361. };
  131362. static long _vq_quantlist__8u0__p4_0[] = {
  131363. 2,
  131364. 1,
  131365. 3,
  131366. 0,
  131367. 4,
  131368. };
  131369. static long _vq_lengthlist__8u0__p4_0[] = {
  131370. 3, 5, 5, 8, 8, 5, 6, 7, 9, 9, 6, 7, 6, 9, 9, 9,
  131371. 9, 9,10,11, 9, 9, 9,11,10, 6, 7, 7,10,10, 7, 7,
  131372. 8,10,10, 7, 8, 8,10,10,10,10,10,10,11, 9,10,10,
  131373. 11,12, 6, 7, 7,10,10, 7, 8, 8,10,10, 7, 8, 7,10,
  131374. 10, 9,10,10,12,11,10,10,10,11,10, 9,10,10,12,11,
  131375. 10,10,10,13,11, 9,10,10,12,12,11,11,12,12,13,11,
  131376. 11,11,12,13, 9,10,10,12,12,10,10,11,12,12,10,10,
  131377. 11,12,12,11,11,11,13,13,11,12,12,13,13, 5, 7, 7,
  131378. 10,10, 7, 8, 8,10,10, 7, 8, 8,10,10,10,11,11,12,
  131379. 12,10,11,10,12,12, 7, 8, 8,11,11, 7, 8, 9,10,11,
  131380. 8, 9, 9,11,11,11,10,11,10,12,10,11,11,12,13, 7,
  131381. 8, 8,10,11, 8, 9, 8,12,10, 8, 9, 9,11,12,10,11,
  131382. 10,13,11,10,11,11,13,12, 9,11,10,13,12,10,10,11,
  131383. 12,12,10,11,11,13,13,12,10,13,11,14,11,12,12,15,
  131384. 13, 9,11,11,13,13,10,11,11,13,12,10,11,11,12,14,
  131385. 12,13,11,14,12,12,12,12,14,14, 5, 7, 7,10,10, 7,
  131386. 8, 8,10,10, 7, 8, 8,11,10,10,11,11,12,12,10,11,
  131387. 10,12,12, 7, 8, 8,10,11, 8, 9, 9,12,11, 8, 8, 9,
  131388. 10,11,10,11,11,12,13,11,10,11,11,13, 6, 8, 8,10,
  131389. 11, 8, 9, 9,11,11, 7, 9, 7,11,10,10,11,11,12,12,
  131390. 10,11,10,13,10, 9,11,10,13,12,10,12,11,13,13,10,
  131391. 10,11,12,13,11,12,13,15,14,11,11,13,12,13, 9,10,
  131392. 11,12,13,10,11,11,12,13,10,11,10,13,12,12,13,13,
  131393. 13,14,12,12,11,14,11, 8,10,10,12,13,10,11,11,13,
  131394. 13,10,11,10,13,13,12,13,14,15,14,12,12,12,14,13,
  131395. 9,10,10,13,12,10,10,12,13,13,10,11,11,15,12,12,
  131396. 12,13,15,14,12,13,13,15,13, 9,10,11,12,13,10,12,
  131397. 10,13,12,10,11,11,12,13,12,14,12,15,13,12,12,12,
  131398. 15,14,11,12,11,14,13,11,11,12,14,14,12,13,13,14,
  131399. 13,13,11,15,11,15,14,14,14,16,15,11,12,12,13,14,
  131400. 11,13,11,14,14,12,12,13,14,15,12,14,12,15,12,13,
  131401. 15,14,16,15, 8,10,10,12,12,10,10,10,12,13,10,11,
  131402. 11,13,13,12,12,12,13,14,13,13,13,15,15, 9,10,10,
  131403. 12,12,10,11,11,13,12,10,10,11,13,13,12,12,12,14,
  131404. 14,12,12,13,15,14, 9,10,10,13,12,10,10,12,12,13,
  131405. 10,11,10,13,13,12,13,13,14,14,12,13,12,14,13,11,
  131406. 12,12,14,13,12,13,12,14,14,10,12,12,14,14,14,14,
  131407. 14,16,14,13,12,14,12,15,10,12,12,14,15,12,13,13,
  131408. 14,16,11,12,11,15,14,13,14,14,14,15,13,14,11,14,
  131409. 12,
  131410. };
  131411. static float _vq_quantthresh__8u0__p4_0[] = {
  131412. -1.5, -0.5, 0.5, 1.5,
  131413. };
  131414. static long _vq_quantmap__8u0__p4_0[] = {
  131415. 3, 1, 0, 2, 4,
  131416. };
  131417. static encode_aux_threshmatch _vq_auxt__8u0__p4_0 = {
  131418. _vq_quantthresh__8u0__p4_0,
  131419. _vq_quantmap__8u0__p4_0,
  131420. 5,
  131421. 5
  131422. };
  131423. static static_codebook _8u0__p4_0 = {
  131424. 4, 625,
  131425. _vq_lengthlist__8u0__p4_0,
  131426. 1, -533725184, 1611661312, 3, 0,
  131427. _vq_quantlist__8u0__p4_0,
  131428. NULL,
  131429. &_vq_auxt__8u0__p4_0,
  131430. NULL,
  131431. 0
  131432. };
  131433. static long _vq_quantlist__8u0__p5_0[] = {
  131434. 4,
  131435. 3,
  131436. 5,
  131437. 2,
  131438. 6,
  131439. 1,
  131440. 7,
  131441. 0,
  131442. 8,
  131443. };
  131444. static long _vq_lengthlist__8u0__p5_0[] = {
  131445. 1, 4, 4, 7, 7, 7, 7, 9, 9, 4, 6, 6, 8, 7, 8, 8,
  131446. 10,10, 4, 6, 6, 8, 8, 8, 8,10,10, 6, 8, 8, 9, 9,
  131447. 9, 9,11,11, 7, 8, 8, 9, 9, 9, 9,11,11, 7, 8, 8,
  131448. 9, 9,10,10,12,11, 7, 8, 8, 9, 9,10,10,11,11, 9,
  131449. 10,10,11,11,11,12,12,12, 9,10,10,11,11,12,12,12,
  131450. 12,
  131451. };
  131452. static float _vq_quantthresh__8u0__p5_0[] = {
  131453. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  131454. };
  131455. static long _vq_quantmap__8u0__p5_0[] = {
  131456. 7, 5, 3, 1, 0, 2, 4, 6,
  131457. 8,
  131458. };
  131459. static encode_aux_threshmatch _vq_auxt__8u0__p5_0 = {
  131460. _vq_quantthresh__8u0__p5_0,
  131461. _vq_quantmap__8u0__p5_0,
  131462. 9,
  131463. 9
  131464. };
  131465. static static_codebook _8u0__p5_0 = {
  131466. 2, 81,
  131467. _vq_lengthlist__8u0__p5_0,
  131468. 1, -531628032, 1611661312, 4, 0,
  131469. _vq_quantlist__8u0__p5_0,
  131470. NULL,
  131471. &_vq_auxt__8u0__p5_0,
  131472. NULL,
  131473. 0
  131474. };
  131475. static long _vq_quantlist__8u0__p6_0[] = {
  131476. 6,
  131477. 5,
  131478. 7,
  131479. 4,
  131480. 8,
  131481. 3,
  131482. 9,
  131483. 2,
  131484. 10,
  131485. 1,
  131486. 11,
  131487. 0,
  131488. 12,
  131489. };
  131490. static long _vq_lengthlist__8u0__p6_0[] = {
  131491. 1, 4, 4, 7, 7, 9, 9,11,11,12,12,16,16, 3, 6, 6,
  131492. 9, 9,11,11,12,12,13,14,18,16, 3, 6, 7, 9, 9,11,
  131493. 11,13,12,14,14,17,16, 7, 9, 9,11,11,12,12,14,14,
  131494. 14,14,17,16, 7, 9, 9,11,11,13,12,13,13,14,14,17,
  131495. 0, 9,11,11,12,13,14,14,14,13,15,14,17,17, 9,11,
  131496. 11,12,12,14,14,13,14,14,15, 0, 0,11,12,12,15,14,
  131497. 15,14,15,14,15,16,17, 0,11,12,13,13,13,14,14,15,
  131498. 14,15,15, 0, 0,12,14,14,15,15,14,16,15,15,17,16,
  131499. 0,18,13,14,14,15,14,15,14,15,16,17,16, 0, 0,17,
  131500. 17,18, 0,16,18,16, 0, 0, 0,17, 0, 0,16, 0, 0,16,
  131501. 16, 0,15, 0,17, 0, 0, 0, 0,
  131502. };
  131503. static float _vq_quantthresh__8u0__p6_0[] = {
  131504. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  131505. 12.5, 17.5, 22.5, 27.5,
  131506. };
  131507. static long _vq_quantmap__8u0__p6_0[] = {
  131508. 11, 9, 7, 5, 3, 1, 0, 2,
  131509. 4, 6, 8, 10, 12,
  131510. };
  131511. static encode_aux_threshmatch _vq_auxt__8u0__p6_0 = {
  131512. _vq_quantthresh__8u0__p6_0,
  131513. _vq_quantmap__8u0__p6_0,
  131514. 13,
  131515. 13
  131516. };
  131517. static static_codebook _8u0__p6_0 = {
  131518. 2, 169,
  131519. _vq_lengthlist__8u0__p6_0,
  131520. 1, -526516224, 1616117760, 4, 0,
  131521. _vq_quantlist__8u0__p6_0,
  131522. NULL,
  131523. &_vq_auxt__8u0__p6_0,
  131524. NULL,
  131525. 0
  131526. };
  131527. static long _vq_quantlist__8u0__p6_1[] = {
  131528. 2,
  131529. 1,
  131530. 3,
  131531. 0,
  131532. 4,
  131533. };
  131534. static long _vq_lengthlist__8u0__p6_1[] = {
  131535. 1, 4, 4, 6, 6, 4, 6, 5, 7, 7, 4, 5, 6, 7, 7, 6,
  131536. 7, 7, 7, 7, 6, 7, 7, 7, 7,
  131537. };
  131538. static float _vq_quantthresh__8u0__p6_1[] = {
  131539. -1.5, -0.5, 0.5, 1.5,
  131540. };
  131541. static long _vq_quantmap__8u0__p6_1[] = {
  131542. 3, 1, 0, 2, 4,
  131543. };
  131544. static encode_aux_threshmatch _vq_auxt__8u0__p6_1 = {
  131545. _vq_quantthresh__8u0__p6_1,
  131546. _vq_quantmap__8u0__p6_1,
  131547. 5,
  131548. 5
  131549. };
  131550. static static_codebook _8u0__p6_1 = {
  131551. 2, 25,
  131552. _vq_lengthlist__8u0__p6_1,
  131553. 1, -533725184, 1611661312, 3, 0,
  131554. _vq_quantlist__8u0__p6_1,
  131555. NULL,
  131556. &_vq_auxt__8u0__p6_1,
  131557. NULL,
  131558. 0
  131559. };
  131560. static long _vq_quantlist__8u0__p7_0[] = {
  131561. 1,
  131562. 0,
  131563. 2,
  131564. };
  131565. static long _vq_lengthlist__8u0__p7_0[] = {
  131566. 1, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  131567. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  131568. 8, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  131569. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  131570. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  131571. 7,
  131572. };
  131573. static float _vq_quantthresh__8u0__p7_0[] = {
  131574. -157.5, 157.5,
  131575. };
  131576. static long _vq_quantmap__8u0__p7_0[] = {
  131577. 1, 0, 2,
  131578. };
  131579. static encode_aux_threshmatch _vq_auxt__8u0__p7_0 = {
  131580. _vq_quantthresh__8u0__p7_0,
  131581. _vq_quantmap__8u0__p7_0,
  131582. 3,
  131583. 3
  131584. };
  131585. static static_codebook _8u0__p7_0 = {
  131586. 4, 81,
  131587. _vq_lengthlist__8u0__p7_0,
  131588. 1, -518803456, 1628680192, 2, 0,
  131589. _vq_quantlist__8u0__p7_0,
  131590. NULL,
  131591. &_vq_auxt__8u0__p7_0,
  131592. NULL,
  131593. 0
  131594. };
  131595. static long _vq_quantlist__8u0__p7_1[] = {
  131596. 7,
  131597. 6,
  131598. 8,
  131599. 5,
  131600. 9,
  131601. 4,
  131602. 10,
  131603. 3,
  131604. 11,
  131605. 2,
  131606. 12,
  131607. 1,
  131608. 13,
  131609. 0,
  131610. 14,
  131611. };
  131612. static long _vq_lengthlist__8u0__p7_1[] = {
  131613. 1, 5, 5, 5, 5,10,10,11,11,11,11,11,11,11,11, 5,
  131614. 7, 6, 8, 8, 9,10,11,11,11,11,11,11,11,11, 6, 6,
  131615. 7, 9, 7,11,10,11,11,11,11,11,11,11,11, 5, 6, 6,
  131616. 11, 8,11,11,11,11,11,11,11,11,11,11, 5, 6, 6, 9,
  131617. 10,11,10,11,11,11,11,11,11,11,11, 7,10,10,11,11,
  131618. 11,11,11,11,11,11,11,11,11,11, 7,11, 8,11,11,11,
  131619. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131620. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131621. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131622. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131623. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131624. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131625. 11,11,11,11,11,11,11,11,11,11,11,10,10,10,10,10,
  131626. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  131627. 10,
  131628. };
  131629. static float _vq_quantthresh__8u0__p7_1[] = {
  131630. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  131631. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  131632. };
  131633. static long _vq_quantmap__8u0__p7_1[] = {
  131634. 13, 11, 9, 7, 5, 3, 1, 0,
  131635. 2, 4, 6, 8, 10, 12, 14,
  131636. };
  131637. static encode_aux_threshmatch _vq_auxt__8u0__p7_1 = {
  131638. _vq_quantthresh__8u0__p7_1,
  131639. _vq_quantmap__8u0__p7_1,
  131640. 15,
  131641. 15
  131642. };
  131643. static static_codebook _8u0__p7_1 = {
  131644. 2, 225,
  131645. _vq_lengthlist__8u0__p7_1,
  131646. 1, -520986624, 1620377600, 4, 0,
  131647. _vq_quantlist__8u0__p7_1,
  131648. NULL,
  131649. &_vq_auxt__8u0__p7_1,
  131650. NULL,
  131651. 0
  131652. };
  131653. static long _vq_quantlist__8u0__p7_2[] = {
  131654. 10,
  131655. 9,
  131656. 11,
  131657. 8,
  131658. 12,
  131659. 7,
  131660. 13,
  131661. 6,
  131662. 14,
  131663. 5,
  131664. 15,
  131665. 4,
  131666. 16,
  131667. 3,
  131668. 17,
  131669. 2,
  131670. 18,
  131671. 1,
  131672. 19,
  131673. 0,
  131674. 20,
  131675. };
  131676. static long _vq_lengthlist__8u0__p7_2[] = {
  131677. 1, 6, 5, 7, 7, 9, 9, 9, 9,10,12,12,10,11,11,10,
  131678. 11,11,11,10,11, 6, 8, 8, 9, 9,10,10, 9,10,11,11,
  131679. 10,11,11,11,11,10,11,11,11,11, 6, 7, 8, 9, 9, 9,
  131680. 10,11,10,11,12,11,10,11,11,11,11,11,11,12,10, 8,
  131681. 9, 9,10, 9,10,10, 9,10,10,10,10,10, 9,10,10,10,
  131682. 10, 9,10,10, 9, 9, 9, 9,10,10, 9, 9,10,10,11,10,
  131683. 9,12,10,11,10, 9,10,10,10, 8, 9, 9,10, 9,10, 9,
  131684. 9,10,10, 9,10, 9,11,10,10,10,10,10, 9,10, 8, 8,
  131685. 9, 9,10, 9,11, 9, 8, 9, 9,10,11,10,10,10,11,12,
  131686. 9, 9,11, 8, 9, 8,11,10,11,10,10, 9,11,10,10,10,
  131687. 10,10,10,10,11,11,11,11, 8, 9, 9, 9,10,10,10,11,
  131688. 11,12,11,12,11,10,10,10,12,11,11,11,10, 8,10, 9,
  131689. 11,10,10,11,12,10,11,12,11,11,12,11,12,12,10,11,
  131690. 11,10, 9, 9,10,11,12,10,10,10,11,10,11,11,10,12,
  131691. 12,10,11,10,11,12,10, 9,10,10,11,10,11,11,11,11,
  131692. 11,12,11,11,11, 9,11,10,11,10,11,10, 9, 9,10,11,
  131693. 11,11,10,10,11,12,12,11,12,11,11,11,12,12,12,12,
  131694. 11, 9,11,11,12,10,11,11,11,11,11,11,12,11,11,12,
  131695. 11,11,11,10,11,11, 9,11,10,11,11,11,10,10,10,11,
  131696. 11,11,12,10,11,10,11,11,11,11,12, 9,11,10,11,11,
  131697. 10,10,11,11, 9,11,11,12,10,10,10,10,10,11,11,10,
  131698. 9,10,11,11,12,11,10,10,12,11,11,12,11,12,11,11,
  131699. 10,10,11,11,10,12,11,10,11,10,11,10,10,10,11,11,
  131700. 10,10,11,11,11,11,10,10,10,12,11,11,11,11,10, 9,
  131701. 10,11,11,11,12,11,11,11,12,10,11,11,11, 9,10,11,
  131702. 11,11,11,11,11,10,10,11,11,12,11,10,11,12,11,10,
  131703. 10,11, 9,10,11,11,11,11,11,10,11,11,10,12,11,11,
  131704. 11,12,11,11,11,10,10,11,11,
  131705. };
  131706. static float _vq_quantthresh__8u0__p7_2[] = {
  131707. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  131708. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  131709. 6.5, 7.5, 8.5, 9.5,
  131710. };
  131711. static long _vq_quantmap__8u0__p7_2[] = {
  131712. 19, 17, 15, 13, 11, 9, 7, 5,
  131713. 3, 1, 0, 2, 4, 6, 8, 10,
  131714. 12, 14, 16, 18, 20,
  131715. };
  131716. static encode_aux_threshmatch _vq_auxt__8u0__p7_2 = {
  131717. _vq_quantthresh__8u0__p7_2,
  131718. _vq_quantmap__8u0__p7_2,
  131719. 21,
  131720. 21
  131721. };
  131722. static static_codebook _8u0__p7_2 = {
  131723. 2, 441,
  131724. _vq_lengthlist__8u0__p7_2,
  131725. 1, -529268736, 1611661312, 5, 0,
  131726. _vq_quantlist__8u0__p7_2,
  131727. NULL,
  131728. &_vq_auxt__8u0__p7_2,
  131729. NULL,
  131730. 0
  131731. };
  131732. static long _huff_lengthlist__8u0__single[] = {
  131733. 4, 7,11, 9,12, 8, 7,10, 6, 4, 5, 5, 7, 5, 6,16,
  131734. 9, 5, 5, 6, 7, 7, 9,16, 7, 4, 6, 5, 7, 5, 7,17,
  131735. 10, 7, 7, 8, 7, 7, 8,18, 7, 5, 6, 4, 5, 4, 5,15,
  131736. 7, 6, 7, 5, 6, 4, 5,15,12,13,18,12,17,11, 9,17,
  131737. };
  131738. static static_codebook _huff_book__8u0__single = {
  131739. 2, 64,
  131740. _huff_lengthlist__8u0__single,
  131741. 0, 0, 0, 0, 0,
  131742. NULL,
  131743. NULL,
  131744. NULL,
  131745. NULL,
  131746. 0
  131747. };
  131748. static long _vq_quantlist__8u1__p1_0[] = {
  131749. 1,
  131750. 0,
  131751. 2,
  131752. };
  131753. static long _vq_lengthlist__8u1__p1_0[] = {
  131754. 1, 4, 4, 5, 7, 7, 5, 7, 7, 5, 8, 8, 7, 9,10, 7,
  131755. 9, 9, 5, 8, 8, 7,10, 9, 7, 9, 9, 5, 8, 8, 8,10,
  131756. 10, 8,10,10, 7,10,10, 9,10,12,10,12,12, 7,10,10,
  131757. 9,12,11,10,12,12, 5, 8, 8, 8,10,10, 8,10,10, 7,
  131758. 10,10,10,12,12, 9,11,12, 7,10,10,10,12,12, 9,12,
  131759. 10,
  131760. };
  131761. static float _vq_quantthresh__8u1__p1_0[] = {
  131762. -0.5, 0.5,
  131763. };
  131764. static long _vq_quantmap__8u1__p1_0[] = {
  131765. 1, 0, 2,
  131766. };
  131767. static encode_aux_threshmatch _vq_auxt__8u1__p1_0 = {
  131768. _vq_quantthresh__8u1__p1_0,
  131769. _vq_quantmap__8u1__p1_0,
  131770. 3,
  131771. 3
  131772. };
  131773. static static_codebook _8u1__p1_0 = {
  131774. 4, 81,
  131775. _vq_lengthlist__8u1__p1_0,
  131776. 1, -535822336, 1611661312, 2, 0,
  131777. _vq_quantlist__8u1__p1_0,
  131778. NULL,
  131779. &_vq_auxt__8u1__p1_0,
  131780. NULL,
  131781. 0
  131782. };
  131783. static long _vq_quantlist__8u1__p2_0[] = {
  131784. 1,
  131785. 0,
  131786. 2,
  131787. };
  131788. static long _vq_lengthlist__8u1__p2_0[] = {
  131789. 3, 4, 5, 5, 6, 6, 5, 6, 6, 5, 7, 6, 6, 7, 8, 6,
  131790. 7, 8, 5, 6, 6, 6, 8, 7, 6, 8, 7, 5, 6, 6, 7, 8,
  131791. 8, 6, 7, 7, 6, 8, 7, 7, 7, 9, 8, 9, 9, 6, 7, 8,
  131792. 7, 9, 7, 8, 9, 9, 5, 6, 6, 6, 7, 7, 7, 8, 8, 6,
  131793. 8, 7, 8, 9, 9, 7, 7, 9, 6, 7, 8, 8, 9, 9, 7, 9,
  131794. 7,
  131795. };
  131796. static float _vq_quantthresh__8u1__p2_0[] = {
  131797. -0.5, 0.5,
  131798. };
  131799. static long _vq_quantmap__8u1__p2_0[] = {
  131800. 1, 0, 2,
  131801. };
  131802. static encode_aux_threshmatch _vq_auxt__8u1__p2_0 = {
  131803. _vq_quantthresh__8u1__p2_0,
  131804. _vq_quantmap__8u1__p2_0,
  131805. 3,
  131806. 3
  131807. };
  131808. static static_codebook _8u1__p2_0 = {
  131809. 4, 81,
  131810. _vq_lengthlist__8u1__p2_0,
  131811. 1, -535822336, 1611661312, 2, 0,
  131812. _vq_quantlist__8u1__p2_0,
  131813. NULL,
  131814. &_vq_auxt__8u1__p2_0,
  131815. NULL,
  131816. 0
  131817. };
  131818. static long _vq_quantlist__8u1__p3_0[] = {
  131819. 2,
  131820. 1,
  131821. 3,
  131822. 0,
  131823. 4,
  131824. };
  131825. static long _vq_lengthlist__8u1__p3_0[] = {
  131826. 1, 5, 5, 7, 7, 6, 7, 7, 9, 9, 6, 7, 7, 9, 9, 8,
  131827. 10, 9,11,11, 9, 9, 9,11,11, 6, 8, 8,10,10, 8,10,
  131828. 10,11,11, 8, 9,10,11,11,10,11,11,12,12,10,11,11,
  131829. 12,13, 6, 8, 8,10,10, 8,10, 9,11,11, 8,10, 9,11,
  131830. 11,10,11,11,12,12,10,11,11,12,12, 9,11,11,14,13,
  131831. 10,12,11,14,14,10,12,11,14,13,12,13,13,15,14,12,
  131832. 13,13,15,14, 8,11,11,13,14,10,11,12,13,15,10,11,
  131833. 12,14,14,12,13,13,14,15,12,13,13,14,15, 5, 8, 8,
  131834. 11,11, 8,10,10,12,12, 8,10,10,12,12,11,12,12,14,
  131835. 13,11,12,12,13,14, 8,10,10,12,12, 9,11,12,13,14,
  131836. 10,12,12,13,13,12,12,13,14,14,11,13,13,15,15, 7,
  131837. 10,10,12,12, 9,12,11,14,12,10,11,12,13,14,12,13,
  131838. 12,14,14,12,13,13,15,16,10,12,12,15,14,11,12,13,
  131839. 15,15,11,13,13,15,16,14,14,15,15,16,13,14,15,17,
  131840. 15, 9,12,12,14,15,11,13,12,15,15,11,13,13,15,15,
  131841. 13,14,13,15,14,13,14,14,17, 0, 5, 8, 8,11,11, 8,
  131842. 10,10,12,12, 8,10,10,12,12,11,12,12,14,14,11,12,
  131843. 12,14,14, 7,10,10,12,12,10,12,12,13,13, 9,11,12,
  131844. 12,13,11,12,13,15,15,11,12,13,14,15, 8,10,10,12,
  131845. 12,10,12,11,13,13,10,12,11,13,13,11,13,13,15,14,
  131846. 12,13,12,15,13, 9,12,12,14,14,11,13,13,16,15,11,
  131847. 12,13,16,15,13,14,15,16,16,13,13,15,15,16,10,12,
  131848. 12,15,14,11,13,13,14,16,11,13,13,15,16,13,15,15,
  131849. 16,17,13,15,14,16,15, 8,11,11,14,15,10,12,12,15,
  131850. 15,10,12,12,15,16,14,15,15,16,17,13,14,14,16,16,
  131851. 9,12,12,15,15,11,13,14,15,17,11,13,13,15,16,14,
  131852. 15,16,19,17,13,15,15, 0,17, 9,12,12,15,15,11,14,
  131853. 13,16,15,11,13,13,15,16,15,15,15,18,17,13,15,15,
  131854. 17,17,11,15,14,18,16,12,14,15,17,17,12,15,15,18,
  131855. 18,15,15,16,15,19,14,16,16, 0, 0,11,14,14,16,17,
  131856. 12,15,14,18,17,12,15,15,18,18,15,17,15,18,16,14,
  131857. 16,16,18,18, 7,11,11,14,14,10,12,12,15,15,10,12,
  131858. 13,15,15,13,14,15,16,16,14,15,15,18,18, 9,12,12,
  131859. 15,15,11,13,13,16,15,11,12,13,16,16,14,15,15,17,
  131860. 16,15,16,16,17,17, 9,12,12,15,15,11,13,13,15,17,
  131861. 11,14,13,16,15,13,15,15,17,17,15,15,15,18,17,11,
  131862. 14,14,17,15,12,14,15,17,18,13,13,15,17,17,14,16,
  131863. 16,19,18,16,15,17,17, 0,11,14,14,17,17,12,15,15,
  131864. 18, 0,12,15,14,18,16,14,17,17,19, 0,16,18,15, 0,
  131865. 16,
  131866. };
  131867. static float _vq_quantthresh__8u1__p3_0[] = {
  131868. -1.5, -0.5, 0.5, 1.5,
  131869. };
  131870. static long _vq_quantmap__8u1__p3_0[] = {
  131871. 3, 1, 0, 2, 4,
  131872. };
  131873. static encode_aux_threshmatch _vq_auxt__8u1__p3_0 = {
  131874. _vq_quantthresh__8u1__p3_0,
  131875. _vq_quantmap__8u1__p3_0,
  131876. 5,
  131877. 5
  131878. };
  131879. static static_codebook _8u1__p3_0 = {
  131880. 4, 625,
  131881. _vq_lengthlist__8u1__p3_0,
  131882. 1, -533725184, 1611661312, 3, 0,
  131883. _vq_quantlist__8u1__p3_0,
  131884. NULL,
  131885. &_vq_auxt__8u1__p3_0,
  131886. NULL,
  131887. 0
  131888. };
  131889. static long _vq_quantlist__8u1__p4_0[] = {
  131890. 2,
  131891. 1,
  131892. 3,
  131893. 0,
  131894. 4,
  131895. };
  131896. static long _vq_lengthlist__8u1__p4_0[] = {
  131897. 4, 5, 5, 9, 9, 6, 7, 7, 9, 9, 6, 7, 7, 9, 9, 9,
  131898. 9, 9,11,11, 9, 9, 9,11,11, 6, 7, 7, 9, 9, 7, 7,
  131899. 8, 9,10, 7, 7, 8, 9,10, 9, 9,10,10,11, 9, 9,10,
  131900. 10,12, 6, 7, 7, 9, 9, 7, 8, 7,10, 9, 7, 8, 7,10,
  131901. 9, 9,10, 9,12,11,10,10, 9,12,10, 9,10,10,12,11,
  131902. 9,10,10,12,11, 9,10,10,12,12,11,11,12,12,13,11,
  131903. 11,12,12,13, 9, 9,10,12,11, 9,10,10,12,12,10,10,
  131904. 10,12,12,11,12,11,13,12,11,12,11,13,12, 6, 7, 7,
  131905. 9, 9, 7, 8, 8,10,10, 7, 8, 7,10, 9,10,10,10,12,
  131906. 12,10,10,10,12,11, 7, 8, 7,10,10, 7, 7, 9,10,11,
  131907. 8, 9, 9,11,10,10,10,11,10,12,10,10,11,12,12, 7,
  131908. 8, 8,10,10, 7, 9, 8,11,10, 8, 8, 9,11,11,10,11,
  131909. 10,12,11,10,11,11,12,12, 9,10,10,12,12, 9,10,10,
  131910. 12,12,10,11,11,13,12,11,10,12,10,14,12,12,12,13,
  131911. 14, 9,10,10,12,12, 9,11,10,12,12,10,11,11,12,12,
  131912. 11,12,11,14,12,12,12,12,14,14, 5, 7, 7, 9, 9, 7,
  131913. 7, 7, 9,10, 7, 8, 8,10,10,10,10,10,11,11,10,10,
  131914. 10,12,12, 7, 8, 8,10,10, 8, 9, 8,11,10, 7, 8, 9,
  131915. 10,11,10,10,10,11,12,10,10,11,11,13, 6, 7, 8,10,
  131916. 10, 8, 9, 9,10,10, 7, 9, 7,11,10,10,11,10,12,12,
  131917. 10,11,10,12,10, 9,10,10,12,12,10,11,11,13,12, 9,
  131918. 10,10,12,12,12,12,12,14,13,11,11,12,11,14, 9,10,
  131919. 10,11,12,10,11,11,12,13, 9,10,10,12,12,12,12,12,
  131920. 14,13,11,12,10,14,11, 9, 9,10,11,12, 9,10,10,12,
  131921. 12, 9,10,10,12,12,12,12,12,14,14,11,12,12,13,12,
  131922. 9,10, 9,12,12, 9,10,11,12,13,10,11,10,13,11,12,
  131923. 12,13,13,14,12,12,12,13,13, 9,10,10,12,12,10,11,
  131924. 10,13,12,10,10,11,12,13,12,13,12,14,13,12,12,12,
  131925. 13,14,11,12,11,14,13,10,10,11,13,13,12,12,12,14,
  131926. 13,12,10,14,10,15,13,14,14,14,14,11,11,12,13,14,
  131927. 10,12,11,13,13,12,12,12,13,15,12,13,11,15,12,13,
  131928. 13,14,14,14, 9,10, 9,12,12, 9,10,10,12,12,10,10,
  131929. 10,12,12,11,11,12,12,13,12,12,12,14,14, 9,10,10,
  131930. 12,12,10,11,10,13,12,10,10,11,12,13,12,12,12,14,
  131931. 13,12,12,13,13,14, 9,10,10,12,13,10,10,11,11,12,
  131932. 9,11,10,13,12,12,12,12,13,14,12,13,12,14,13,11,
  131933. 12,11,13,13,12,13,12,14,13,10,11,12,13,13,13,13,
  131934. 13,14,15,12,11,14,12,14,11,11,12,12,13,12,12,12,
  131935. 13,14,10,12,10,14,13,13,13,13,14,15,12,14,11,15,
  131936. 10,
  131937. };
  131938. static float _vq_quantthresh__8u1__p4_0[] = {
  131939. -1.5, -0.5, 0.5, 1.5,
  131940. };
  131941. static long _vq_quantmap__8u1__p4_0[] = {
  131942. 3, 1, 0, 2, 4,
  131943. };
  131944. static encode_aux_threshmatch _vq_auxt__8u1__p4_0 = {
  131945. _vq_quantthresh__8u1__p4_0,
  131946. _vq_quantmap__8u1__p4_0,
  131947. 5,
  131948. 5
  131949. };
  131950. static static_codebook _8u1__p4_0 = {
  131951. 4, 625,
  131952. _vq_lengthlist__8u1__p4_0,
  131953. 1, -533725184, 1611661312, 3, 0,
  131954. _vq_quantlist__8u1__p4_0,
  131955. NULL,
  131956. &_vq_auxt__8u1__p4_0,
  131957. NULL,
  131958. 0
  131959. };
  131960. static long _vq_quantlist__8u1__p5_0[] = {
  131961. 4,
  131962. 3,
  131963. 5,
  131964. 2,
  131965. 6,
  131966. 1,
  131967. 7,
  131968. 0,
  131969. 8,
  131970. };
  131971. static long _vq_lengthlist__8u1__p5_0[] = {
  131972. 1, 4, 4, 7, 7, 7, 7, 9, 9, 4, 6, 5, 8, 7, 8, 8,
  131973. 10,10, 4, 6, 6, 8, 8, 8, 8,10,10, 7, 8, 8, 9, 9,
  131974. 9, 9,11,11, 7, 8, 8, 9, 9, 9, 9,11,11, 8, 8, 8,
  131975. 9, 9,10,10,12,11, 8, 8, 8, 9, 9,10,10,11,11, 9,
  131976. 10,10,11,11,11,11,13,12, 9,10,10,11,11,12,12,12,
  131977. 13,
  131978. };
  131979. static float _vq_quantthresh__8u1__p5_0[] = {
  131980. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  131981. };
  131982. static long _vq_quantmap__8u1__p5_0[] = {
  131983. 7, 5, 3, 1, 0, 2, 4, 6,
  131984. 8,
  131985. };
  131986. static encode_aux_threshmatch _vq_auxt__8u1__p5_0 = {
  131987. _vq_quantthresh__8u1__p5_0,
  131988. _vq_quantmap__8u1__p5_0,
  131989. 9,
  131990. 9
  131991. };
  131992. static static_codebook _8u1__p5_0 = {
  131993. 2, 81,
  131994. _vq_lengthlist__8u1__p5_0,
  131995. 1, -531628032, 1611661312, 4, 0,
  131996. _vq_quantlist__8u1__p5_0,
  131997. NULL,
  131998. &_vq_auxt__8u1__p5_0,
  131999. NULL,
  132000. 0
  132001. };
  132002. static long _vq_quantlist__8u1__p6_0[] = {
  132003. 4,
  132004. 3,
  132005. 5,
  132006. 2,
  132007. 6,
  132008. 1,
  132009. 7,
  132010. 0,
  132011. 8,
  132012. };
  132013. static long _vq_lengthlist__8u1__p6_0[] = {
  132014. 3, 4, 4, 6, 6, 7, 7, 9, 9, 4, 4, 5, 6, 6, 7, 7,
  132015. 9, 9, 4, 4, 4, 6, 6, 7, 7, 9, 9, 6, 6, 6, 7, 7,
  132016. 8, 8, 9, 9, 6, 6, 6, 7, 7, 8, 8, 9, 9, 7, 7, 7,
  132017. 8, 8, 8, 9,10,10, 7, 7, 7, 8, 8, 9, 8,10,10, 9,
  132018. 9, 9, 9, 9,10,10,10,10, 9, 9, 9, 9, 9,10,10,10,
  132019. 10,
  132020. };
  132021. static float _vq_quantthresh__8u1__p6_0[] = {
  132022. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  132023. };
  132024. static long _vq_quantmap__8u1__p6_0[] = {
  132025. 7, 5, 3, 1, 0, 2, 4, 6,
  132026. 8,
  132027. };
  132028. static encode_aux_threshmatch _vq_auxt__8u1__p6_0 = {
  132029. _vq_quantthresh__8u1__p6_0,
  132030. _vq_quantmap__8u1__p6_0,
  132031. 9,
  132032. 9
  132033. };
  132034. static static_codebook _8u1__p6_0 = {
  132035. 2, 81,
  132036. _vq_lengthlist__8u1__p6_0,
  132037. 1, -531628032, 1611661312, 4, 0,
  132038. _vq_quantlist__8u1__p6_0,
  132039. NULL,
  132040. &_vq_auxt__8u1__p6_0,
  132041. NULL,
  132042. 0
  132043. };
  132044. static long _vq_quantlist__8u1__p7_0[] = {
  132045. 1,
  132046. 0,
  132047. 2,
  132048. };
  132049. static long _vq_lengthlist__8u1__p7_0[] = {
  132050. 1, 4, 4, 5, 7, 7, 5, 7, 7, 5, 9, 9, 8,10,10, 8,
  132051. 10,10, 5, 9, 9, 7,10,10, 8,10,10, 4,10,10, 9,12,
  132052. 12, 9,11,11, 7,12,11,10,11,13,10,13,13, 7,12,12,
  132053. 10,13,12,10,13,13, 4,10,10, 9,12,12, 9,12,12, 7,
  132054. 12,12,10,13,13,10,12,13, 7,11,12,10,13,13,10,13,
  132055. 11,
  132056. };
  132057. static float _vq_quantthresh__8u1__p7_0[] = {
  132058. -5.5, 5.5,
  132059. };
  132060. static long _vq_quantmap__8u1__p7_0[] = {
  132061. 1, 0, 2,
  132062. };
  132063. static encode_aux_threshmatch _vq_auxt__8u1__p7_0 = {
  132064. _vq_quantthresh__8u1__p7_0,
  132065. _vq_quantmap__8u1__p7_0,
  132066. 3,
  132067. 3
  132068. };
  132069. static static_codebook _8u1__p7_0 = {
  132070. 4, 81,
  132071. _vq_lengthlist__8u1__p7_0,
  132072. 1, -529137664, 1618345984, 2, 0,
  132073. _vq_quantlist__8u1__p7_0,
  132074. NULL,
  132075. &_vq_auxt__8u1__p7_0,
  132076. NULL,
  132077. 0
  132078. };
  132079. static long _vq_quantlist__8u1__p7_1[] = {
  132080. 5,
  132081. 4,
  132082. 6,
  132083. 3,
  132084. 7,
  132085. 2,
  132086. 8,
  132087. 1,
  132088. 9,
  132089. 0,
  132090. 10,
  132091. };
  132092. static long _vq_lengthlist__8u1__p7_1[] = {
  132093. 2, 4, 4, 6, 6, 7, 7, 8, 8, 8, 8, 4, 5, 5, 7, 7,
  132094. 8, 8, 9, 9, 9, 9, 4, 5, 5, 7, 7, 8, 8, 9, 9, 9,
  132095. 9, 6, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 6, 7, 7, 8,
  132096. 8, 8, 8, 9, 9, 9, 9, 8, 8, 8, 8, 8, 9, 9, 9, 9,
  132097. 9, 9, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 8, 9, 9,
  132098. 9, 9, 9, 9,10,10,10,10, 8, 9, 9, 9, 9, 9, 9,10,
  132099. 10,10,10, 8, 9, 9, 9, 9, 9, 9,10,10,10,10, 8, 9,
  132100. 9, 9, 9, 9, 9,10,10,10,10,
  132101. };
  132102. static float _vq_quantthresh__8u1__p7_1[] = {
  132103. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  132104. 3.5, 4.5,
  132105. };
  132106. static long _vq_quantmap__8u1__p7_1[] = {
  132107. 9, 7, 5, 3, 1, 0, 2, 4,
  132108. 6, 8, 10,
  132109. };
  132110. static encode_aux_threshmatch _vq_auxt__8u1__p7_1 = {
  132111. _vq_quantthresh__8u1__p7_1,
  132112. _vq_quantmap__8u1__p7_1,
  132113. 11,
  132114. 11
  132115. };
  132116. static static_codebook _8u1__p7_1 = {
  132117. 2, 121,
  132118. _vq_lengthlist__8u1__p7_1,
  132119. 1, -531365888, 1611661312, 4, 0,
  132120. _vq_quantlist__8u1__p7_1,
  132121. NULL,
  132122. &_vq_auxt__8u1__p7_1,
  132123. NULL,
  132124. 0
  132125. };
  132126. static long _vq_quantlist__8u1__p8_0[] = {
  132127. 5,
  132128. 4,
  132129. 6,
  132130. 3,
  132131. 7,
  132132. 2,
  132133. 8,
  132134. 1,
  132135. 9,
  132136. 0,
  132137. 10,
  132138. };
  132139. static long _vq_lengthlist__8u1__p8_0[] = {
  132140. 1, 4, 4, 6, 6, 8, 8,10,10,11,11, 4, 6, 6, 7, 7,
  132141. 9, 9,11,11,13,12, 4, 6, 6, 7, 7, 9, 9,11,11,12,
  132142. 12, 6, 7, 7, 9, 9,11,11,12,12,13,13, 6, 7, 7, 9,
  132143. 9,11,11,12,12,13,13, 8, 9, 9,11,11,12,12,13,13,
  132144. 14,14, 8, 9, 9,11,11,12,12,13,13,14,14, 9,11,11,
  132145. 12,12,13,13,14,14,15,15, 9,11,11,12,12,13,13,14,
  132146. 14,15,14,11,12,12,13,13,14,14,15,15,16,16,11,12,
  132147. 12,13,13,14,14,15,15,15,15,
  132148. };
  132149. static float _vq_quantthresh__8u1__p8_0[] = {
  132150. -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5, 27.5,
  132151. 38.5, 49.5,
  132152. };
  132153. static long _vq_quantmap__8u1__p8_0[] = {
  132154. 9, 7, 5, 3, 1, 0, 2, 4,
  132155. 6, 8, 10,
  132156. };
  132157. static encode_aux_threshmatch _vq_auxt__8u1__p8_0 = {
  132158. _vq_quantthresh__8u1__p8_0,
  132159. _vq_quantmap__8u1__p8_0,
  132160. 11,
  132161. 11
  132162. };
  132163. static static_codebook _8u1__p8_0 = {
  132164. 2, 121,
  132165. _vq_lengthlist__8u1__p8_0,
  132166. 1, -524582912, 1618345984, 4, 0,
  132167. _vq_quantlist__8u1__p8_0,
  132168. NULL,
  132169. &_vq_auxt__8u1__p8_0,
  132170. NULL,
  132171. 0
  132172. };
  132173. static long _vq_quantlist__8u1__p8_1[] = {
  132174. 5,
  132175. 4,
  132176. 6,
  132177. 3,
  132178. 7,
  132179. 2,
  132180. 8,
  132181. 1,
  132182. 9,
  132183. 0,
  132184. 10,
  132185. };
  132186. static long _vq_lengthlist__8u1__p8_1[] = {
  132187. 2, 5, 5, 6, 6, 7, 7, 7, 7, 8, 8, 5, 6, 6, 7, 7,
  132188. 7, 7, 8, 8, 8, 8, 5, 6, 6, 7, 7, 7, 7, 8, 8, 8,
  132189. 8, 6, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 6, 7, 7, 7,
  132190. 7, 8, 8, 8, 8, 8, 8, 7, 7, 7, 8, 8, 8, 8, 8, 8,
  132191. 8, 8, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  132192. 8, 8, 8, 8, 9, 8, 9, 9, 7, 8, 8, 8, 8, 8, 8, 9,
  132193. 8, 9, 9, 8, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 8, 8,
  132194. 8, 8, 8, 8, 8, 9, 9, 9, 9,
  132195. };
  132196. static float _vq_quantthresh__8u1__p8_1[] = {
  132197. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  132198. 3.5, 4.5,
  132199. };
  132200. static long _vq_quantmap__8u1__p8_1[] = {
  132201. 9, 7, 5, 3, 1, 0, 2, 4,
  132202. 6, 8, 10,
  132203. };
  132204. static encode_aux_threshmatch _vq_auxt__8u1__p8_1 = {
  132205. _vq_quantthresh__8u1__p8_1,
  132206. _vq_quantmap__8u1__p8_1,
  132207. 11,
  132208. 11
  132209. };
  132210. static static_codebook _8u1__p8_1 = {
  132211. 2, 121,
  132212. _vq_lengthlist__8u1__p8_1,
  132213. 1, -531365888, 1611661312, 4, 0,
  132214. _vq_quantlist__8u1__p8_1,
  132215. NULL,
  132216. &_vq_auxt__8u1__p8_1,
  132217. NULL,
  132218. 0
  132219. };
  132220. static long _vq_quantlist__8u1__p9_0[] = {
  132221. 7,
  132222. 6,
  132223. 8,
  132224. 5,
  132225. 9,
  132226. 4,
  132227. 10,
  132228. 3,
  132229. 11,
  132230. 2,
  132231. 12,
  132232. 1,
  132233. 13,
  132234. 0,
  132235. 14,
  132236. };
  132237. static long _vq_lengthlist__8u1__p9_0[] = {
  132238. 1, 4, 4,11,11,11,11,11,11,11,11,11,11,11,11, 3,
  132239. 11, 8,11,11,11,11,11,11,11,11,11,11,11,11, 3, 9,
  132240. 9,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132241. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132242. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132243. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132244. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132245. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132246. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132247. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132248. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132249. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132250. 11,11,11,11,11,11,11,11,11,11,10,10,10,10,10,10,
  132251. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  132252. 10,
  132253. };
  132254. static float _vq_quantthresh__8u1__p9_0[] = {
  132255. -1657.5, -1402.5, -1147.5, -892.5, -637.5, -382.5, -127.5, 127.5,
  132256. 382.5, 637.5, 892.5, 1147.5, 1402.5, 1657.5,
  132257. };
  132258. static long _vq_quantmap__8u1__p9_0[] = {
  132259. 13, 11, 9, 7, 5, 3, 1, 0,
  132260. 2, 4, 6, 8, 10, 12, 14,
  132261. };
  132262. static encode_aux_threshmatch _vq_auxt__8u1__p9_0 = {
  132263. _vq_quantthresh__8u1__p9_0,
  132264. _vq_quantmap__8u1__p9_0,
  132265. 15,
  132266. 15
  132267. };
  132268. static static_codebook _8u1__p9_0 = {
  132269. 2, 225,
  132270. _vq_lengthlist__8u1__p9_0,
  132271. 1, -514071552, 1627381760, 4, 0,
  132272. _vq_quantlist__8u1__p9_0,
  132273. NULL,
  132274. &_vq_auxt__8u1__p9_0,
  132275. NULL,
  132276. 0
  132277. };
  132278. static long _vq_quantlist__8u1__p9_1[] = {
  132279. 7,
  132280. 6,
  132281. 8,
  132282. 5,
  132283. 9,
  132284. 4,
  132285. 10,
  132286. 3,
  132287. 11,
  132288. 2,
  132289. 12,
  132290. 1,
  132291. 13,
  132292. 0,
  132293. 14,
  132294. };
  132295. static long _vq_lengthlist__8u1__p9_1[] = {
  132296. 1, 4, 4, 7, 7, 9, 9, 7, 7, 8, 8,10,10,11,11, 4,
  132297. 7, 7, 9, 9,10,10, 8, 8,10,10,10,11,10,11, 4, 7,
  132298. 7, 9, 9,10,10, 8, 8,10, 9,11,11,11,11, 7, 9, 9,
  132299. 12,12,11,12,10,10,11,10,12,11,11,11, 7, 9, 9,11,
  132300. 11,13,12, 9, 9,11,10,11,11,12,11, 9,10,10,12,12,
  132301. 14,14,10,10,11,12,12,11,11,11, 9,10,11,11,13,14,
  132302. 13,10,11,11,11,12,11,12,12, 7, 8, 8,10, 9,11,10,
  132303. 11,12,12,11,12,14,12,13, 7, 8, 8, 9,10,10,11,12,
  132304. 12,12,11,12,12,12,13, 9, 9, 9,11,11,13,12,12,12,
  132305. 12,11,12,12,13,12, 8,10,10,11,10,11,12,12,12,12,
  132306. 12,12,14,12,12, 9,11,11,11,12,12,12,12,13,13,12,
  132307. 12,13,13,12,10,11,11,12,11,12,12,12,11,12,13,12,
  132308. 12,12,13,11,11,12,12,12,13,12,12,11,12,13,13,12,
  132309. 12,13,12,11,12,12,13,13,12,13,12,13,13,13,13,14,
  132310. 13,
  132311. };
  132312. static float _vq_quantthresh__8u1__p9_1[] = {
  132313. -110.5, -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5,
  132314. 25.5, 42.5, 59.5, 76.5, 93.5, 110.5,
  132315. };
  132316. static long _vq_quantmap__8u1__p9_1[] = {
  132317. 13, 11, 9, 7, 5, 3, 1, 0,
  132318. 2, 4, 6, 8, 10, 12, 14,
  132319. };
  132320. static encode_aux_threshmatch _vq_auxt__8u1__p9_1 = {
  132321. _vq_quantthresh__8u1__p9_1,
  132322. _vq_quantmap__8u1__p9_1,
  132323. 15,
  132324. 15
  132325. };
  132326. static static_codebook _8u1__p9_1 = {
  132327. 2, 225,
  132328. _vq_lengthlist__8u1__p9_1,
  132329. 1, -522338304, 1620115456, 4, 0,
  132330. _vq_quantlist__8u1__p9_1,
  132331. NULL,
  132332. &_vq_auxt__8u1__p9_1,
  132333. NULL,
  132334. 0
  132335. };
  132336. static long _vq_quantlist__8u1__p9_2[] = {
  132337. 8,
  132338. 7,
  132339. 9,
  132340. 6,
  132341. 10,
  132342. 5,
  132343. 11,
  132344. 4,
  132345. 12,
  132346. 3,
  132347. 13,
  132348. 2,
  132349. 14,
  132350. 1,
  132351. 15,
  132352. 0,
  132353. 16,
  132354. };
  132355. static long _vq_lengthlist__8u1__p9_2[] = {
  132356. 2, 5, 4, 6, 6, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  132357. 9, 5, 6, 6, 7, 7, 8, 8, 9, 8, 9, 9, 9, 9, 9, 9,
  132358. 9, 9, 5, 6, 6, 7, 7, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  132359. 9, 9, 9, 7, 7, 7, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9,
  132360. 9,10,10, 9, 7, 7, 7, 8, 8, 9, 9, 9, 9, 9, 9, 9,
  132361. 9, 9, 9,10,10, 8, 8, 8, 9, 9, 9, 9,10,10,10, 9,
  132362. 10,10,10,10,10,10, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9,
  132363. 10,10,10,10,10,10,10, 9, 9, 9, 9, 9, 9, 9, 9,10,
  132364. 10,10,10,10,10,10,10,10, 9, 9, 9, 9, 9,10,10,10,
  132365. 10,10,10,10,10,10,10,10,10, 9, 9, 9, 9, 9, 9,10,
  132366. 10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9, 9,10,
  132367. 10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9,10,
  132368. 10,10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9,
  132369. 9,10,10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9,
  132370. 10,10,10,10,10,10,10,10,10,10,10,10,10,10, 9,10,
  132371. 9, 9, 9,10,10,10,10,10,10,10,10,10,10,10,10, 9,
  132372. 10, 9,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  132373. 9, 9,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  132374. 10,
  132375. };
  132376. static float _vq_quantthresh__8u1__p9_2[] = {
  132377. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  132378. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  132379. };
  132380. static long _vq_quantmap__8u1__p9_2[] = {
  132381. 15, 13, 11, 9, 7, 5, 3, 1,
  132382. 0, 2, 4, 6, 8, 10, 12, 14,
  132383. 16,
  132384. };
  132385. static encode_aux_threshmatch _vq_auxt__8u1__p9_2 = {
  132386. _vq_quantthresh__8u1__p9_2,
  132387. _vq_quantmap__8u1__p9_2,
  132388. 17,
  132389. 17
  132390. };
  132391. static static_codebook _8u1__p9_2 = {
  132392. 2, 289,
  132393. _vq_lengthlist__8u1__p9_2,
  132394. 1, -529530880, 1611661312, 5, 0,
  132395. _vq_quantlist__8u1__p9_2,
  132396. NULL,
  132397. &_vq_auxt__8u1__p9_2,
  132398. NULL,
  132399. 0
  132400. };
  132401. static long _huff_lengthlist__8u1__single[] = {
  132402. 4, 7,13, 9,15, 9,16, 8,10,13, 7, 5, 8, 6, 9, 7,
  132403. 10, 7,10,11,11, 6, 7, 8, 8, 9, 9, 9,12,16, 8, 5,
  132404. 8, 6, 8, 6, 9, 7,10,12,11, 7, 7, 7, 6, 7, 7, 7,
  132405. 11,15, 7, 5, 8, 6, 7, 5, 7, 6, 9,13,13, 9, 9, 8,
  132406. 6, 6, 5, 5, 9,14, 8, 6, 8, 6, 6, 4, 5, 3, 5,13,
  132407. 9, 9,11, 8,10, 7, 8, 4, 5,12,11,16,17,15,17,12,
  132408. 13, 8, 8,15,
  132409. };
  132410. static static_codebook _huff_book__8u1__single = {
  132411. 2, 100,
  132412. _huff_lengthlist__8u1__single,
  132413. 0, 0, 0, 0, 0,
  132414. NULL,
  132415. NULL,
  132416. NULL,
  132417. NULL,
  132418. 0
  132419. };
  132420. static long _huff_lengthlist__44u0__long[] = {
  132421. 5, 8,13,10,17,11,11,15, 7, 2, 4, 5, 8, 7, 9,16,
  132422. 13, 4, 3, 5, 6, 8,11,20,10, 4, 5, 5, 7, 6, 8,18,
  132423. 15, 7, 6, 7, 8,10,14,20,10, 6, 7, 6, 9, 7, 8,17,
  132424. 9, 8,10, 8,10, 5, 4,11,12,17,19,14,16,10, 7,12,
  132425. };
  132426. static static_codebook _huff_book__44u0__long = {
  132427. 2, 64,
  132428. _huff_lengthlist__44u0__long,
  132429. 0, 0, 0, 0, 0,
  132430. NULL,
  132431. NULL,
  132432. NULL,
  132433. NULL,
  132434. 0
  132435. };
  132436. static long _vq_quantlist__44u0__p1_0[] = {
  132437. 1,
  132438. 0,
  132439. 2,
  132440. };
  132441. static long _vq_lengthlist__44u0__p1_0[] = {
  132442. 1, 4, 4, 5, 8, 7, 5, 7, 8, 5, 8, 8, 8,11,11, 8,
  132443. 10,10, 5, 8, 8, 8,11,10, 8,11,11, 4, 8, 8, 8,11,
  132444. 11, 8,11,11, 8,12,11,11,13,13,11,13,14, 7,11,11,
  132445. 10,13,12,11,13,14, 4, 8, 8, 8,11,11, 8,11,12, 8,
  132446. 11,11,11,13,13,10,12,13, 8,11,11,11,14,13,11,14,
  132447. 13,
  132448. };
  132449. static float _vq_quantthresh__44u0__p1_0[] = {
  132450. -0.5, 0.5,
  132451. };
  132452. static long _vq_quantmap__44u0__p1_0[] = {
  132453. 1, 0, 2,
  132454. };
  132455. static encode_aux_threshmatch _vq_auxt__44u0__p1_0 = {
  132456. _vq_quantthresh__44u0__p1_0,
  132457. _vq_quantmap__44u0__p1_0,
  132458. 3,
  132459. 3
  132460. };
  132461. static static_codebook _44u0__p1_0 = {
  132462. 4, 81,
  132463. _vq_lengthlist__44u0__p1_0,
  132464. 1, -535822336, 1611661312, 2, 0,
  132465. _vq_quantlist__44u0__p1_0,
  132466. NULL,
  132467. &_vq_auxt__44u0__p1_0,
  132468. NULL,
  132469. 0
  132470. };
  132471. static long _vq_quantlist__44u0__p2_0[] = {
  132472. 1,
  132473. 0,
  132474. 2,
  132475. };
  132476. static long _vq_lengthlist__44u0__p2_0[] = {
  132477. 2, 4, 4, 5, 6, 6, 5, 6, 6, 5, 7, 7, 7, 8, 8, 6,
  132478. 8, 8, 5, 7, 7, 6, 8, 8, 7, 8, 8, 4, 7, 7, 7, 8,
  132479. 8, 7, 8, 8, 7, 8, 8, 8, 9,10, 8,10,10, 6, 8, 8,
  132480. 8,10, 8, 8,10,10, 5, 7, 7, 7, 8, 8, 7, 8, 8, 6,
  132481. 8, 8, 8,10,10, 8, 8,10, 6, 8, 8, 8,10,10, 8,10,
  132482. 9,
  132483. };
  132484. static float _vq_quantthresh__44u0__p2_0[] = {
  132485. -0.5, 0.5,
  132486. };
  132487. static long _vq_quantmap__44u0__p2_0[] = {
  132488. 1, 0, 2,
  132489. };
  132490. static encode_aux_threshmatch _vq_auxt__44u0__p2_0 = {
  132491. _vq_quantthresh__44u0__p2_0,
  132492. _vq_quantmap__44u0__p2_0,
  132493. 3,
  132494. 3
  132495. };
  132496. static static_codebook _44u0__p2_0 = {
  132497. 4, 81,
  132498. _vq_lengthlist__44u0__p2_0,
  132499. 1, -535822336, 1611661312, 2, 0,
  132500. _vq_quantlist__44u0__p2_0,
  132501. NULL,
  132502. &_vq_auxt__44u0__p2_0,
  132503. NULL,
  132504. 0
  132505. };
  132506. static long _vq_quantlist__44u0__p3_0[] = {
  132507. 2,
  132508. 1,
  132509. 3,
  132510. 0,
  132511. 4,
  132512. };
  132513. static long _vq_lengthlist__44u0__p3_0[] = {
  132514. 1, 5, 5, 8, 8, 5, 8, 7, 9, 9, 5, 7, 8, 9, 9, 9,
  132515. 10, 9,12,12, 9, 9,10,12,12, 6, 8, 8,11,10, 8,10,
  132516. 10,11,11, 8, 9,10,11,11,10,11,11,14,13,10,11,11,
  132517. 13,13, 5, 8, 8,10,10, 8,10,10,11,11, 8,10,10,11,
  132518. 11,10,11,11,13,13,10,11,11,13,13, 9,11,11,15,14,
  132519. 10,12,12,15,14,10,12,11,15,14,13,14,14,16,16,12,
  132520. 14,13,17,15, 9,11,11,14,15,10,11,12,14,16,10,11,
  132521. 12,14,16,12,13,14,16,16,13,13,15,15,18, 5, 8, 8,
  132522. 11,11, 8,10,10,12,12, 8,10,10,12,13,11,12,12,14,
  132523. 14,11,12,12,15,15, 8,10,10,13,13,10,12,12,13,13,
  132524. 10,12,12,14,14,12,13,13,15,15,12,13,13,16,16, 7,
  132525. 10,10,12,12,10,12,11,13,13,10,12,12,13,14,12,13,
  132526. 12,15,14,12,13,13,16,16,10,12,12,17,16,12,13,13,
  132527. 16,15,11,13,13,17,17,15,15,15,16,17,14,15,15,19,
  132528. 19,10,12,12,15,16,11,13,12,15,18,11,13,13,16,16,
  132529. 14,15,15,17,17,14,15,15,17,19, 5, 8, 8,11,11, 8,
  132530. 10,10,12,12, 8,10,10,12,12,11,12,12,16,15,11,12,
  132531. 12,14,15, 7,10,10,13,13,10,12,12,14,13,10,11,12,
  132532. 13,13,12,13,13,16,16,12,12,13,15,15, 8,10,10,13,
  132533. 13,10,12,12,14,14,10,12,12,13,13,12,13,13,16,16,
  132534. 12,13,13,15,15,10,12,12,16,15,11,13,13,17,16,11,
  132535. 12,13,16,15,13,15,15,19,17,14,15,14,17,16,10,12,
  132536. 12,16,16,11,13,13,16,17,12,13,13,15,17,14,15,15,
  132537. 17,19,14,15,15,17,17, 8,11,11,16,16,10,13,12,17,
  132538. 17,10,12,13,16,16,15,17,16,20,19,14,15,17,18,19,
  132539. 9,12,12,16,17,11,13,14,17,18,11,13,13,19,18,16,
  132540. 17,18,19,19,15,16,16,19,19, 9,12,12,16,17,11,14,
  132541. 13,18,17,11,13,13,17,17,16,17,16,20,19,14,16,16,
  132542. 18,18,12,15,15,19,17,14,15,16, 0,20,13,15,16,20,
  132543. 17,18,16,20, 0, 0,15,16,19,20, 0,12,15,14,18,19,
  132544. 13,16,15,20,19,13,16,15,20,18,17,18,17, 0,20,16,
  132545. 17,16, 0, 0, 8,11,11,16,15,10,12,12,17,17,10,13,
  132546. 13,17,16,14,16,15,18,20,15,16,16,19,19, 9,12,12,
  132547. 16,16,11,13,13,17,16,11,13,14,17,18,15,15,16,20,
  132548. 20,16,16,17,19,19, 9,13,12,16,17,11,14,13,17,17,
  132549. 11,14,14,18,17,14,16,15,18,19,16,17,18,18,19,12,
  132550. 14,15,19,18,13,15,16,18, 0,13,14,15, 0, 0,16,16,
  132551. 17,20, 0,17,17,20,20, 0,12,15,15,19,20,13,15,15,
  132552. 0, 0,14,16,15, 0, 0,15,18,16, 0, 0,17,18,16, 0,
  132553. 19,
  132554. };
  132555. static float _vq_quantthresh__44u0__p3_0[] = {
  132556. -1.5, -0.5, 0.5, 1.5,
  132557. };
  132558. static long _vq_quantmap__44u0__p3_0[] = {
  132559. 3, 1, 0, 2, 4,
  132560. };
  132561. static encode_aux_threshmatch _vq_auxt__44u0__p3_0 = {
  132562. _vq_quantthresh__44u0__p3_0,
  132563. _vq_quantmap__44u0__p3_0,
  132564. 5,
  132565. 5
  132566. };
  132567. static static_codebook _44u0__p3_0 = {
  132568. 4, 625,
  132569. _vq_lengthlist__44u0__p3_0,
  132570. 1, -533725184, 1611661312, 3, 0,
  132571. _vq_quantlist__44u0__p3_0,
  132572. NULL,
  132573. &_vq_auxt__44u0__p3_0,
  132574. NULL,
  132575. 0
  132576. };
  132577. static long _vq_quantlist__44u0__p4_0[] = {
  132578. 2,
  132579. 1,
  132580. 3,
  132581. 0,
  132582. 4,
  132583. };
  132584. static long _vq_lengthlist__44u0__p4_0[] = {
  132585. 4, 5, 5, 9, 9, 5, 6, 6, 9, 9, 5, 6, 6, 9, 9, 9,
  132586. 10, 9,12,12, 9, 9,10,12,12, 5, 7, 7,10,10, 7, 7,
  132587. 8,10,10, 6, 7, 8,10,10,10,10,10,11,13,10, 9,10,
  132588. 12,13, 5, 7, 7,10,10, 6, 8, 7,10,10, 7, 8, 7,10,
  132589. 10, 9,10,10,12,12,10,10,10,13,11, 9,10,10,13,13,
  132590. 10,11,10,13,13,10,10,10,13,13,12,12,13,14,14,12,
  132591. 12,13,14,14, 9,10,10,13,13,10,10,10,13,13,10,10,
  132592. 10,13,13,12,13,12,15,14,12,13,12,15,15, 5, 7, 6,
  132593. 10,10, 7, 8, 8,10,10, 7, 8, 8,10,10,10,11,10,13,
  132594. 13,10,10,10,12,12, 7, 8, 8,11,10, 8, 8, 9,10,11,
  132595. 8, 9, 9,11,11,11,10,11,11,14,11,11,11,13,13, 6,
  132596. 8, 8,10,10, 7, 9, 8,11,10, 8, 9, 9,11,11,10,11,
  132597. 10,14,11,10,11,11,13,13,10,11,11,14,13,10,10,11,
  132598. 14,13,10,11,11,14,14,12,11,13,12,16,13,14,14,15,
  132599. 15,10,10,11,13,14,10,11,10,14,13,10,11,11,14,14,
  132600. 12,13,12,15,13,13,13,14,15,16, 5, 7, 7,10,10, 7,
  132601. 8, 8,10,10, 7, 8, 8,10,10,10,10,10,13,13,10,10,
  132602. 11,12,13, 6, 8, 8,11,10, 8, 9, 9,11,11, 7, 8, 9,
  132603. 10,11,10,11,11,13,13,10,10,11,11,13, 6, 8, 8,10,
  132604. 11, 8, 9, 9,11,11, 8, 9, 8,12,10,10,11,11,13,13,
  132605. 10,11,10,14,11,10,10,10,14,13,10,11,11,14,13,10,
  132606. 10,11,13,13,12,14,14,16,16,12,12,13,13,15,10,11,
  132607. 11,13,14,10,11,11,14,15,10,11,10,13,13,13,14,13,
  132608. 16,16,12,13,11,15,12, 9,10,10,13,13,10,11,11,14,
  132609. 13,10,10,11,13,14,13,14,13,16,16,13,13,13,15,16,
  132610. 9,10,10,13,13,10,10,11,13,14,10,11,11,15,13,13,
  132611. 13,14,14,18,13,13,14,16,15, 9,10,10,13,14,10,11,
  132612. 10,14,13,10,11,11,13,14,13,14,13,16,15,13,13,14,
  132613. 15,16,12,13,12,16,14,11,11,13,15,15,13,14,13,16,
  132614. 15,15,12,16,12,17,14,15,15,17,17,12,13,13,14,16,
  132615. 11,13,11,16,15,12,13,14,15,16,14,15,13, 0,14,14,
  132616. 16,16, 0, 0, 9,10,10,13,13,10,11,10,14,14,10,11,
  132617. 11,13,13,12,13,13,14,16,13,14,14,16,16, 9,10,10,
  132618. 14,14,11,11,11,14,13,10,10,11,14,14,13,13,13,16,
  132619. 16,13,13,14,14,17, 9,10,10,13,14,10,11,11,13,15,
  132620. 10,11,10,14,14,13,13,13,14,17,13,14,13,17,14,12,
  132621. 13,13,16,14,13,14,13,16,15,12,12,13,15,16,15,15,
  132622. 16,18,16,15,13,15,14, 0,12,12,13,14,16,13,13,14,
  132623. 15,16,11,12,11,16,14,15,16,16,17,17,14,15,12,17,
  132624. 12,
  132625. };
  132626. static float _vq_quantthresh__44u0__p4_0[] = {
  132627. -1.5, -0.5, 0.5, 1.5,
  132628. };
  132629. static long _vq_quantmap__44u0__p4_0[] = {
  132630. 3, 1, 0, 2, 4,
  132631. };
  132632. static encode_aux_threshmatch _vq_auxt__44u0__p4_0 = {
  132633. _vq_quantthresh__44u0__p4_0,
  132634. _vq_quantmap__44u0__p4_0,
  132635. 5,
  132636. 5
  132637. };
  132638. static static_codebook _44u0__p4_0 = {
  132639. 4, 625,
  132640. _vq_lengthlist__44u0__p4_0,
  132641. 1, -533725184, 1611661312, 3, 0,
  132642. _vq_quantlist__44u0__p4_0,
  132643. NULL,
  132644. &_vq_auxt__44u0__p4_0,
  132645. NULL,
  132646. 0
  132647. };
  132648. static long _vq_quantlist__44u0__p5_0[] = {
  132649. 4,
  132650. 3,
  132651. 5,
  132652. 2,
  132653. 6,
  132654. 1,
  132655. 7,
  132656. 0,
  132657. 8,
  132658. };
  132659. static long _vq_lengthlist__44u0__p5_0[] = {
  132660. 1, 4, 4, 7, 7, 7, 7, 9, 9, 4, 6, 6, 8, 8, 8, 8,
  132661. 9, 9, 4, 6, 6, 8, 8, 8, 8, 9, 9, 7, 8, 8, 9, 9,
  132662. 9, 9,11,10, 7, 8, 8, 9, 9, 9, 9,10,10, 7, 8, 8,
  132663. 9, 9,10,10,11,11, 7, 8, 8, 9, 9,10,10,11,11, 9,
  132664. 9, 9,10,10,11,11,12,12, 9, 9, 9,10,11,11,11,12,
  132665. 12,
  132666. };
  132667. static float _vq_quantthresh__44u0__p5_0[] = {
  132668. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  132669. };
  132670. static long _vq_quantmap__44u0__p5_0[] = {
  132671. 7, 5, 3, 1, 0, 2, 4, 6,
  132672. 8,
  132673. };
  132674. static encode_aux_threshmatch _vq_auxt__44u0__p5_0 = {
  132675. _vq_quantthresh__44u0__p5_0,
  132676. _vq_quantmap__44u0__p5_0,
  132677. 9,
  132678. 9
  132679. };
  132680. static static_codebook _44u0__p5_0 = {
  132681. 2, 81,
  132682. _vq_lengthlist__44u0__p5_0,
  132683. 1, -531628032, 1611661312, 4, 0,
  132684. _vq_quantlist__44u0__p5_0,
  132685. NULL,
  132686. &_vq_auxt__44u0__p5_0,
  132687. NULL,
  132688. 0
  132689. };
  132690. static long _vq_quantlist__44u0__p6_0[] = {
  132691. 6,
  132692. 5,
  132693. 7,
  132694. 4,
  132695. 8,
  132696. 3,
  132697. 9,
  132698. 2,
  132699. 10,
  132700. 1,
  132701. 11,
  132702. 0,
  132703. 12,
  132704. };
  132705. static long _vq_lengthlist__44u0__p6_0[] = {
  132706. 1, 4, 4, 6, 6, 8, 8,10, 9,11,10,14,13, 4, 6, 5,
  132707. 8, 8, 9, 9,11,10,11,11,14,14, 4, 5, 6, 8, 8, 9,
  132708. 9,10,10,11,11,14,14, 6, 8, 8, 9, 9,10,10,11,11,
  132709. 12,12,16,15, 7, 8, 8, 9, 9,10,10,11,11,12,12,15,
  132710. 15, 9,10,10,10,10,11,11,12,12,12,12,15,15, 9,10,
  132711. 9,10,11,11,11,12,12,12,13,15,15,10,10,11,11,11,
  132712. 12,12,13,12,13,13,16,15,10,11,11,11,11,12,12,13,
  132713. 12,13,13,16,17,11,11,12,12,12,13,13,13,14,14,15,
  132714. 17,17,11,11,12,12,12,13,13,13,14,14,14,16,18,14,
  132715. 15,15,15,15,16,16,16,16,17,18, 0, 0,14,15,15,15,
  132716. 15,17,16,17,18,17,17,18, 0,
  132717. };
  132718. static float _vq_quantthresh__44u0__p6_0[] = {
  132719. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  132720. 12.5, 17.5, 22.5, 27.5,
  132721. };
  132722. static long _vq_quantmap__44u0__p6_0[] = {
  132723. 11, 9, 7, 5, 3, 1, 0, 2,
  132724. 4, 6, 8, 10, 12,
  132725. };
  132726. static encode_aux_threshmatch _vq_auxt__44u0__p6_0 = {
  132727. _vq_quantthresh__44u0__p6_0,
  132728. _vq_quantmap__44u0__p6_0,
  132729. 13,
  132730. 13
  132731. };
  132732. static static_codebook _44u0__p6_0 = {
  132733. 2, 169,
  132734. _vq_lengthlist__44u0__p6_0,
  132735. 1, -526516224, 1616117760, 4, 0,
  132736. _vq_quantlist__44u0__p6_0,
  132737. NULL,
  132738. &_vq_auxt__44u0__p6_0,
  132739. NULL,
  132740. 0
  132741. };
  132742. static long _vq_quantlist__44u0__p6_1[] = {
  132743. 2,
  132744. 1,
  132745. 3,
  132746. 0,
  132747. 4,
  132748. };
  132749. static long _vq_lengthlist__44u0__p6_1[] = {
  132750. 2, 4, 4, 5, 5, 4, 5, 5, 5, 5, 4, 5, 5, 5, 5, 5,
  132751. 6, 6, 6, 6, 5, 6, 6, 6, 6,
  132752. };
  132753. static float _vq_quantthresh__44u0__p6_1[] = {
  132754. -1.5, -0.5, 0.5, 1.5,
  132755. };
  132756. static long _vq_quantmap__44u0__p6_1[] = {
  132757. 3, 1, 0, 2, 4,
  132758. };
  132759. static encode_aux_threshmatch _vq_auxt__44u0__p6_1 = {
  132760. _vq_quantthresh__44u0__p6_1,
  132761. _vq_quantmap__44u0__p6_1,
  132762. 5,
  132763. 5
  132764. };
  132765. static static_codebook _44u0__p6_1 = {
  132766. 2, 25,
  132767. _vq_lengthlist__44u0__p6_1,
  132768. 1, -533725184, 1611661312, 3, 0,
  132769. _vq_quantlist__44u0__p6_1,
  132770. NULL,
  132771. &_vq_auxt__44u0__p6_1,
  132772. NULL,
  132773. 0
  132774. };
  132775. static long _vq_quantlist__44u0__p7_0[] = {
  132776. 2,
  132777. 1,
  132778. 3,
  132779. 0,
  132780. 4,
  132781. };
  132782. static long _vq_lengthlist__44u0__p7_0[] = {
  132783. 1, 4, 4,11,11, 9,11,11,11,11,11,11,11,11,11,11,
  132784. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132785. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132786. 11,11, 9,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132787. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132788. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132789. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132790. 11,11,11,11,11,11,11,11,11,11,11,11,11,10,11,11,
  132791. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132792. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132793. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132794. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132795. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132796. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132797. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132798. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132799. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132800. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132801. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132802. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132803. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132804. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132805. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132806. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132807. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132808. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132809. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132810. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132811. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132812. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132813. 11,11,11,11,11,11,10,10,10,10,10,10,10,10,10,10,
  132814. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  132815. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  132816. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  132817. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  132818. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  132819. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  132820. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  132821. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  132822. 10,
  132823. };
  132824. static float _vq_quantthresh__44u0__p7_0[] = {
  132825. -253.5, -84.5, 84.5, 253.5,
  132826. };
  132827. static long _vq_quantmap__44u0__p7_0[] = {
  132828. 3, 1, 0, 2, 4,
  132829. };
  132830. static encode_aux_threshmatch _vq_auxt__44u0__p7_0 = {
  132831. _vq_quantthresh__44u0__p7_0,
  132832. _vq_quantmap__44u0__p7_0,
  132833. 5,
  132834. 5
  132835. };
  132836. static static_codebook _44u0__p7_0 = {
  132837. 4, 625,
  132838. _vq_lengthlist__44u0__p7_0,
  132839. 1, -518709248, 1626677248, 3, 0,
  132840. _vq_quantlist__44u0__p7_0,
  132841. NULL,
  132842. &_vq_auxt__44u0__p7_0,
  132843. NULL,
  132844. 0
  132845. };
  132846. static long _vq_quantlist__44u0__p7_1[] = {
  132847. 6,
  132848. 5,
  132849. 7,
  132850. 4,
  132851. 8,
  132852. 3,
  132853. 9,
  132854. 2,
  132855. 10,
  132856. 1,
  132857. 11,
  132858. 0,
  132859. 12,
  132860. };
  132861. static long _vq_lengthlist__44u0__p7_1[] = {
  132862. 1, 4, 4, 6, 6, 6, 6, 7, 7, 8, 8, 9, 9, 5, 7, 7,
  132863. 8, 7, 7, 7, 9, 8,10, 9,10,11, 5, 7, 7, 8, 8, 7,
  132864. 7, 8, 9,10,10,11,11, 6, 8, 8, 9, 9, 9, 9,11,10,
  132865. 12,12,15,12, 6, 8, 8, 9, 9, 9, 9,11,11,12,11,14,
  132866. 12, 7, 8, 8,10,10,12,12,13,13,13,15,13,13, 7, 8,
  132867. 8,10,10,11,11,13,12,14,15,15,15, 9,10,10,11,12,
  132868. 13,13,14,15,14,15,14,15, 8,10,10,12,12,14,14,15,
  132869. 14,14,15,15,14,10,12,12,14,14,15,14,15,15,15,14,
  132870. 15,15,10,12,12,13,14,15,14,15,15,14,15,15,15,12,
  132871. 15,13,15,14,15,15,15,15,15,15,15,15,13,13,15,15,
  132872. 15,15,15,15,15,15,15,15,15,
  132873. };
  132874. static float _vq_quantthresh__44u0__p7_1[] = {
  132875. -71.5, -58.5, -45.5, -32.5, -19.5, -6.5, 6.5, 19.5,
  132876. 32.5, 45.5, 58.5, 71.5,
  132877. };
  132878. static long _vq_quantmap__44u0__p7_1[] = {
  132879. 11, 9, 7, 5, 3, 1, 0, 2,
  132880. 4, 6, 8, 10, 12,
  132881. };
  132882. static encode_aux_threshmatch _vq_auxt__44u0__p7_1 = {
  132883. _vq_quantthresh__44u0__p7_1,
  132884. _vq_quantmap__44u0__p7_1,
  132885. 13,
  132886. 13
  132887. };
  132888. static static_codebook _44u0__p7_1 = {
  132889. 2, 169,
  132890. _vq_lengthlist__44u0__p7_1,
  132891. 1, -523010048, 1618608128, 4, 0,
  132892. _vq_quantlist__44u0__p7_1,
  132893. NULL,
  132894. &_vq_auxt__44u0__p7_1,
  132895. NULL,
  132896. 0
  132897. };
  132898. static long _vq_quantlist__44u0__p7_2[] = {
  132899. 6,
  132900. 5,
  132901. 7,
  132902. 4,
  132903. 8,
  132904. 3,
  132905. 9,
  132906. 2,
  132907. 10,
  132908. 1,
  132909. 11,
  132910. 0,
  132911. 12,
  132912. };
  132913. static long _vq_lengthlist__44u0__p7_2[] = {
  132914. 2, 5, 4, 6, 6, 7, 7, 8, 8, 8, 8, 9, 8, 5, 5, 6,
  132915. 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 5, 6, 5, 7, 7, 8,
  132916. 8, 8, 8, 9, 9, 9, 9, 6, 7, 7, 8, 8, 8, 8, 9, 8,
  132917. 9, 9, 9, 9, 6, 7, 7, 8, 7, 8, 8, 9, 9, 9, 9, 9,
  132918. 9, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 7, 8,
  132919. 8, 9, 8, 9, 8, 9, 9, 9, 9, 9, 9, 8, 9, 8, 9, 9,
  132920. 9, 9, 9, 9, 9, 9,10,10, 8, 8, 9, 9, 9, 9, 9, 9,
  132921. 9, 9,10, 9,10, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  132922. 9, 9, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  132923. 9, 9, 9, 9, 9, 9, 9, 9,10,10,10, 9, 9, 9, 9, 9,
  132924. 9, 9, 9,10, 9, 9,10,10, 9,
  132925. };
  132926. static float _vq_quantthresh__44u0__p7_2[] = {
  132927. -5.5, -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5,
  132928. 2.5, 3.5, 4.5, 5.5,
  132929. };
  132930. static long _vq_quantmap__44u0__p7_2[] = {
  132931. 11, 9, 7, 5, 3, 1, 0, 2,
  132932. 4, 6, 8, 10, 12,
  132933. };
  132934. static encode_aux_threshmatch _vq_auxt__44u0__p7_2 = {
  132935. _vq_quantthresh__44u0__p7_2,
  132936. _vq_quantmap__44u0__p7_2,
  132937. 13,
  132938. 13
  132939. };
  132940. static static_codebook _44u0__p7_2 = {
  132941. 2, 169,
  132942. _vq_lengthlist__44u0__p7_2,
  132943. 1, -531103744, 1611661312, 4, 0,
  132944. _vq_quantlist__44u0__p7_2,
  132945. NULL,
  132946. &_vq_auxt__44u0__p7_2,
  132947. NULL,
  132948. 0
  132949. };
  132950. static long _huff_lengthlist__44u0__short[] = {
  132951. 12,13,14,13,17,12,15,17, 5, 5, 6,10,10,11,15,16,
  132952. 4, 3, 3, 7, 5, 7,10,16, 7, 7, 7,10, 9,11,12,16,
  132953. 6, 5, 5, 9, 5, 6,10,16, 8, 7, 7, 9, 6, 7, 9,16,
  132954. 11, 7, 3, 6, 4, 5, 8,16,12, 9, 4, 8, 5, 7, 9,16,
  132955. };
  132956. static static_codebook _huff_book__44u0__short = {
  132957. 2, 64,
  132958. _huff_lengthlist__44u0__short,
  132959. 0, 0, 0, 0, 0,
  132960. NULL,
  132961. NULL,
  132962. NULL,
  132963. NULL,
  132964. 0
  132965. };
  132966. static long _huff_lengthlist__44u1__long[] = {
  132967. 5, 8,13,10,17,11,11,15, 7, 2, 4, 5, 8, 7, 9,16,
  132968. 13, 4, 3, 5, 6, 8,11,20,10, 4, 5, 5, 7, 6, 8,18,
  132969. 15, 7, 6, 7, 8,10,14,20,10, 6, 7, 6, 9, 7, 8,17,
  132970. 9, 8,10, 8,10, 5, 4,11,12,17,19,14,16,10, 7,12,
  132971. };
  132972. static static_codebook _huff_book__44u1__long = {
  132973. 2, 64,
  132974. _huff_lengthlist__44u1__long,
  132975. 0, 0, 0, 0, 0,
  132976. NULL,
  132977. NULL,
  132978. NULL,
  132979. NULL,
  132980. 0
  132981. };
  132982. static long _vq_quantlist__44u1__p1_0[] = {
  132983. 1,
  132984. 0,
  132985. 2,
  132986. };
  132987. static long _vq_lengthlist__44u1__p1_0[] = {
  132988. 1, 4, 4, 5, 8, 7, 5, 7, 8, 5, 8, 8, 8,11,11, 8,
  132989. 10,10, 5, 8, 8, 8,11,10, 8,11,11, 4, 8, 8, 8,11,
  132990. 11, 8,11,11, 8,12,11,11,13,13,11,13,14, 7,11,11,
  132991. 10,13,12,11,13,14, 4, 8, 8, 8,11,11, 8,11,12, 8,
  132992. 11,11,11,13,13,10,12,13, 8,11,11,11,14,13,11,14,
  132993. 13,
  132994. };
  132995. static float _vq_quantthresh__44u1__p1_0[] = {
  132996. -0.5, 0.5,
  132997. };
  132998. static long _vq_quantmap__44u1__p1_0[] = {
  132999. 1, 0, 2,
  133000. };
  133001. static encode_aux_threshmatch _vq_auxt__44u1__p1_0 = {
  133002. _vq_quantthresh__44u1__p1_0,
  133003. _vq_quantmap__44u1__p1_0,
  133004. 3,
  133005. 3
  133006. };
  133007. static static_codebook _44u1__p1_0 = {
  133008. 4, 81,
  133009. _vq_lengthlist__44u1__p1_0,
  133010. 1, -535822336, 1611661312, 2, 0,
  133011. _vq_quantlist__44u1__p1_0,
  133012. NULL,
  133013. &_vq_auxt__44u1__p1_0,
  133014. NULL,
  133015. 0
  133016. };
  133017. static long _vq_quantlist__44u1__p2_0[] = {
  133018. 1,
  133019. 0,
  133020. 2,
  133021. };
  133022. static long _vq_lengthlist__44u1__p2_0[] = {
  133023. 2, 4, 4, 5, 6, 6, 5, 6, 6, 5, 7, 7, 7, 8, 8, 6,
  133024. 8, 8, 5, 7, 7, 6, 8, 8, 7, 8, 8, 4, 7, 7, 7, 8,
  133025. 8, 7, 8, 8, 7, 8, 8, 8, 9,10, 8,10,10, 6, 8, 8,
  133026. 8,10, 8, 8,10,10, 5, 7, 7, 7, 8, 8, 7, 8, 8, 6,
  133027. 8, 8, 8,10,10, 8, 8,10, 6, 8, 8, 8,10,10, 8,10,
  133028. 9,
  133029. };
  133030. static float _vq_quantthresh__44u1__p2_0[] = {
  133031. -0.5, 0.5,
  133032. };
  133033. static long _vq_quantmap__44u1__p2_0[] = {
  133034. 1, 0, 2,
  133035. };
  133036. static encode_aux_threshmatch _vq_auxt__44u1__p2_0 = {
  133037. _vq_quantthresh__44u1__p2_0,
  133038. _vq_quantmap__44u1__p2_0,
  133039. 3,
  133040. 3
  133041. };
  133042. static static_codebook _44u1__p2_0 = {
  133043. 4, 81,
  133044. _vq_lengthlist__44u1__p2_0,
  133045. 1, -535822336, 1611661312, 2, 0,
  133046. _vq_quantlist__44u1__p2_0,
  133047. NULL,
  133048. &_vq_auxt__44u1__p2_0,
  133049. NULL,
  133050. 0
  133051. };
  133052. static long _vq_quantlist__44u1__p3_0[] = {
  133053. 2,
  133054. 1,
  133055. 3,
  133056. 0,
  133057. 4,
  133058. };
  133059. static long _vq_lengthlist__44u1__p3_0[] = {
  133060. 1, 5, 5, 8, 8, 5, 8, 7, 9, 9, 5, 7, 8, 9, 9, 9,
  133061. 10, 9,12,12, 9, 9,10,12,12, 6, 8, 8,11,10, 8,10,
  133062. 10,11,11, 8, 9,10,11,11,10,11,11,14,13,10,11,11,
  133063. 13,13, 5, 8, 8,10,10, 8,10,10,11,11, 8,10,10,11,
  133064. 11,10,11,11,13,13,10,11,11,13,13, 9,11,11,15,14,
  133065. 10,12,12,15,14,10,12,11,15,14,13,14,14,16,16,12,
  133066. 14,13,17,15, 9,11,11,14,15,10,11,12,14,16,10,11,
  133067. 12,14,16,12,13,14,16,16,13,13,15,15,18, 5, 8, 8,
  133068. 11,11, 8,10,10,12,12, 8,10,10,12,13,11,12,12,14,
  133069. 14,11,12,12,15,15, 8,10,10,13,13,10,12,12,13,13,
  133070. 10,12,12,14,14,12,13,13,15,15,12,13,13,16,16, 7,
  133071. 10,10,12,12,10,12,11,13,13,10,12,12,13,14,12,13,
  133072. 12,15,14,12,13,13,16,16,10,12,12,17,16,12,13,13,
  133073. 16,15,11,13,13,17,17,15,15,15,16,17,14,15,15,19,
  133074. 19,10,12,12,15,16,11,13,12,15,18,11,13,13,16,16,
  133075. 14,15,15,17,17,14,15,15,17,19, 5, 8, 8,11,11, 8,
  133076. 10,10,12,12, 8,10,10,12,12,11,12,12,16,15,11,12,
  133077. 12,14,15, 7,10,10,13,13,10,12,12,14,13,10,11,12,
  133078. 13,13,12,13,13,16,16,12,12,13,15,15, 8,10,10,13,
  133079. 13,10,12,12,14,14,10,12,12,13,13,12,13,13,16,16,
  133080. 12,13,13,15,15,10,12,12,16,15,11,13,13,17,16,11,
  133081. 12,13,16,15,13,15,15,19,17,14,15,14,17,16,10,12,
  133082. 12,16,16,11,13,13,16,17,12,13,13,15,17,14,15,15,
  133083. 17,19,14,15,15,17,17, 8,11,11,16,16,10,13,12,17,
  133084. 17,10,12,13,16,16,15,17,16,20,19,14,15,17,18,19,
  133085. 9,12,12,16,17,11,13,14,17,18,11,13,13,19,18,16,
  133086. 17,18,19,19,15,16,16,19,19, 9,12,12,16,17,11,14,
  133087. 13,18,17,11,13,13,17,17,16,17,16,20,19,14,16,16,
  133088. 18,18,12,15,15,19,17,14,15,16, 0,20,13,15,16,20,
  133089. 17,18,16,20, 0, 0,15,16,19,20, 0,12,15,14,18,19,
  133090. 13,16,15,20,19,13,16,15,20,18,17,18,17, 0,20,16,
  133091. 17,16, 0, 0, 8,11,11,16,15,10,12,12,17,17,10,13,
  133092. 13,17,16,14,16,15,18,20,15,16,16,19,19, 9,12,12,
  133093. 16,16,11,13,13,17,16,11,13,14,17,18,15,15,16,20,
  133094. 20,16,16,17,19,19, 9,13,12,16,17,11,14,13,17,17,
  133095. 11,14,14,18,17,14,16,15,18,19,16,17,18,18,19,12,
  133096. 14,15,19,18,13,15,16,18, 0,13,14,15, 0, 0,16,16,
  133097. 17,20, 0,17,17,20,20, 0,12,15,15,19,20,13,15,15,
  133098. 0, 0,14,16,15, 0, 0,15,18,16, 0, 0,17,18,16, 0,
  133099. 19,
  133100. };
  133101. static float _vq_quantthresh__44u1__p3_0[] = {
  133102. -1.5, -0.5, 0.5, 1.5,
  133103. };
  133104. static long _vq_quantmap__44u1__p3_0[] = {
  133105. 3, 1, 0, 2, 4,
  133106. };
  133107. static encode_aux_threshmatch _vq_auxt__44u1__p3_0 = {
  133108. _vq_quantthresh__44u1__p3_0,
  133109. _vq_quantmap__44u1__p3_0,
  133110. 5,
  133111. 5
  133112. };
  133113. static static_codebook _44u1__p3_0 = {
  133114. 4, 625,
  133115. _vq_lengthlist__44u1__p3_0,
  133116. 1, -533725184, 1611661312, 3, 0,
  133117. _vq_quantlist__44u1__p3_0,
  133118. NULL,
  133119. &_vq_auxt__44u1__p3_0,
  133120. NULL,
  133121. 0
  133122. };
  133123. static long _vq_quantlist__44u1__p4_0[] = {
  133124. 2,
  133125. 1,
  133126. 3,
  133127. 0,
  133128. 4,
  133129. };
  133130. static long _vq_lengthlist__44u1__p4_0[] = {
  133131. 4, 5, 5, 9, 9, 5, 6, 6, 9, 9, 5, 6, 6, 9, 9, 9,
  133132. 10, 9,12,12, 9, 9,10,12,12, 5, 7, 7,10,10, 7, 7,
  133133. 8,10,10, 6, 7, 8,10,10,10,10,10,11,13,10, 9,10,
  133134. 12,13, 5, 7, 7,10,10, 6, 8, 7,10,10, 7, 8, 7,10,
  133135. 10, 9,10,10,12,12,10,10,10,13,11, 9,10,10,13,13,
  133136. 10,11,10,13,13,10,10,10,13,13,12,12,13,14,14,12,
  133137. 12,13,14,14, 9,10,10,13,13,10,10,10,13,13,10,10,
  133138. 10,13,13,12,13,12,15,14,12,13,12,15,15, 5, 7, 6,
  133139. 10,10, 7, 8, 8,10,10, 7, 8, 8,10,10,10,11,10,13,
  133140. 13,10,10,10,12,12, 7, 8, 8,11,10, 8, 8, 9,10,11,
  133141. 8, 9, 9,11,11,11,10,11,11,14,11,11,11,13,13, 6,
  133142. 8, 8,10,10, 7, 9, 8,11,10, 8, 9, 9,11,11,10,11,
  133143. 10,14,11,10,11,11,13,13,10,11,11,14,13,10,10,11,
  133144. 14,13,10,11,11,14,14,12,11,13,12,16,13,14,14,15,
  133145. 15,10,10,11,13,14,10,11,10,14,13,10,11,11,14,14,
  133146. 12,13,12,15,13,13,13,14,15,16, 5, 7, 7,10,10, 7,
  133147. 8, 8,10,10, 7, 8, 8,10,10,10,10,10,13,13,10,10,
  133148. 11,12,13, 6, 8, 8,11,10, 8, 9, 9,11,11, 7, 8, 9,
  133149. 10,11,10,11,11,13,13,10,10,11,11,13, 6, 8, 8,10,
  133150. 11, 8, 9, 9,11,11, 8, 9, 8,12,10,10,11,11,13,13,
  133151. 10,11,10,14,11,10,10,10,14,13,10,11,11,14,13,10,
  133152. 10,11,13,13,12,14,14,16,16,12,12,13,13,15,10,11,
  133153. 11,13,14,10,11,11,14,15,10,11,10,13,13,13,14,13,
  133154. 16,16,12,13,11,15,12, 9,10,10,13,13,10,11,11,14,
  133155. 13,10,10,11,13,14,13,14,13,16,16,13,13,13,15,16,
  133156. 9,10,10,13,13,10,10,11,13,14,10,11,11,15,13,13,
  133157. 13,14,14,18,13,13,14,16,15, 9,10,10,13,14,10,11,
  133158. 10,14,13,10,11,11,13,14,13,14,13,16,15,13,13,14,
  133159. 15,16,12,13,12,16,14,11,11,13,15,15,13,14,13,16,
  133160. 15,15,12,16,12,17,14,15,15,17,17,12,13,13,14,16,
  133161. 11,13,11,16,15,12,13,14,15,16,14,15,13, 0,14,14,
  133162. 16,16, 0, 0, 9,10,10,13,13,10,11,10,14,14,10,11,
  133163. 11,13,13,12,13,13,14,16,13,14,14,16,16, 9,10,10,
  133164. 14,14,11,11,11,14,13,10,10,11,14,14,13,13,13,16,
  133165. 16,13,13,14,14,17, 9,10,10,13,14,10,11,11,13,15,
  133166. 10,11,10,14,14,13,13,13,14,17,13,14,13,17,14,12,
  133167. 13,13,16,14,13,14,13,16,15,12,12,13,15,16,15,15,
  133168. 16,18,16,15,13,15,14, 0,12,12,13,14,16,13,13,14,
  133169. 15,16,11,12,11,16,14,15,16,16,17,17,14,15,12,17,
  133170. 12,
  133171. };
  133172. static float _vq_quantthresh__44u1__p4_0[] = {
  133173. -1.5, -0.5, 0.5, 1.5,
  133174. };
  133175. static long _vq_quantmap__44u1__p4_0[] = {
  133176. 3, 1, 0, 2, 4,
  133177. };
  133178. static encode_aux_threshmatch _vq_auxt__44u1__p4_0 = {
  133179. _vq_quantthresh__44u1__p4_0,
  133180. _vq_quantmap__44u1__p4_0,
  133181. 5,
  133182. 5
  133183. };
  133184. static static_codebook _44u1__p4_0 = {
  133185. 4, 625,
  133186. _vq_lengthlist__44u1__p4_0,
  133187. 1, -533725184, 1611661312, 3, 0,
  133188. _vq_quantlist__44u1__p4_0,
  133189. NULL,
  133190. &_vq_auxt__44u1__p4_0,
  133191. NULL,
  133192. 0
  133193. };
  133194. static long _vq_quantlist__44u1__p5_0[] = {
  133195. 4,
  133196. 3,
  133197. 5,
  133198. 2,
  133199. 6,
  133200. 1,
  133201. 7,
  133202. 0,
  133203. 8,
  133204. };
  133205. static long _vq_lengthlist__44u1__p5_0[] = {
  133206. 1, 4, 4, 7, 7, 7, 7, 9, 9, 4, 6, 6, 8, 8, 8, 8,
  133207. 9, 9, 4, 6, 6, 8, 8, 8, 8, 9, 9, 7, 8, 8, 9, 9,
  133208. 9, 9,11,10, 7, 8, 8, 9, 9, 9, 9,10,10, 7, 8, 8,
  133209. 9, 9,10,10,11,11, 7, 8, 8, 9, 9,10,10,11,11, 9,
  133210. 9, 9,10,10,11,11,12,12, 9, 9, 9,10,11,11,11,12,
  133211. 12,
  133212. };
  133213. static float _vq_quantthresh__44u1__p5_0[] = {
  133214. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  133215. };
  133216. static long _vq_quantmap__44u1__p5_0[] = {
  133217. 7, 5, 3, 1, 0, 2, 4, 6,
  133218. 8,
  133219. };
  133220. static encode_aux_threshmatch _vq_auxt__44u1__p5_0 = {
  133221. _vq_quantthresh__44u1__p5_0,
  133222. _vq_quantmap__44u1__p5_0,
  133223. 9,
  133224. 9
  133225. };
  133226. static static_codebook _44u1__p5_0 = {
  133227. 2, 81,
  133228. _vq_lengthlist__44u1__p5_0,
  133229. 1, -531628032, 1611661312, 4, 0,
  133230. _vq_quantlist__44u1__p5_0,
  133231. NULL,
  133232. &_vq_auxt__44u1__p5_0,
  133233. NULL,
  133234. 0
  133235. };
  133236. static long _vq_quantlist__44u1__p6_0[] = {
  133237. 6,
  133238. 5,
  133239. 7,
  133240. 4,
  133241. 8,
  133242. 3,
  133243. 9,
  133244. 2,
  133245. 10,
  133246. 1,
  133247. 11,
  133248. 0,
  133249. 12,
  133250. };
  133251. static long _vq_lengthlist__44u1__p6_0[] = {
  133252. 1, 4, 4, 6, 6, 8, 8,10, 9,11,10,14,13, 4, 6, 5,
  133253. 8, 8, 9, 9,11,10,11,11,14,14, 4, 5, 6, 8, 8, 9,
  133254. 9,10,10,11,11,14,14, 6, 8, 8, 9, 9,10,10,11,11,
  133255. 12,12,16,15, 7, 8, 8, 9, 9,10,10,11,11,12,12,15,
  133256. 15, 9,10,10,10,10,11,11,12,12,12,12,15,15, 9,10,
  133257. 9,10,11,11,11,12,12,12,13,15,15,10,10,11,11,11,
  133258. 12,12,13,12,13,13,16,15,10,11,11,11,11,12,12,13,
  133259. 12,13,13,16,17,11,11,12,12,12,13,13,13,14,14,15,
  133260. 17,17,11,11,12,12,12,13,13,13,14,14,14,16,18,14,
  133261. 15,15,15,15,16,16,16,16,17,18, 0, 0,14,15,15,15,
  133262. 15,17,16,17,18,17,17,18, 0,
  133263. };
  133264. static float _vq_quantthresh__44u1__p6_0[] = {
  133265. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  133266. 12.5, 17.5, 22.5, 27.5,
  133267. };
  133268. static long _vq_quantmap__44u1__p6_0[] = {
  133269. 11, 9, 7, 5, 3, 1, 0, 2,
  133270. 4, 6, 8, 10, 12,
  133271. };
  133272. static encode_aux_threshmatch _vq_auxt__44u1__p6_0 = {
  133273. _vq_quantthresh__44u1__p6_0,
  133274. _vq_quantmap__44u1__p6_0,
  133275. 13,
  133276. 13
  133277. };
  133278. static static_codebook _44u1__p6_0 = {
  133279. 2, 169,
  133280. _vq_lengthlist__44u1__p6_0,
  133281. 1, -526516224, 1616117760, 4, 0,
  133282. _vq_quantlist__44u1__p6_0,
  133283. NULL,
  133284. &_vq_auxt__44u1__p6_0,
  133285. NULL,
  133286. 0
  133287. };
  133288. static long _vq_quantlist__44u1__p6_1[] = {
  133289. 2,
  133290. 1,
  133291. 3,
  133292. 0,
  133293. 4,
  133294. };
  133295. static long _vq_lengthlist__44u1__p6_1[] = {
  133296. 2, 4, 4, 5, 5, 4, 5, 5, 5, 5, 4, 5, 5, 5, 5, 5,
  133297. 6, 6, 6, 6, 5, 6, 6, 6, 6,
  133298. };
  133299. static float _vq_quantthresh__44u1__p6_1[] = {
  133300. -1.5, -0.5, 0.5, 1.5,
  133301. };
  133302. static long _vq_quantmap__44u1__p6_1[] = {
  133303. 3, 1, 0, 2, 4,
  133304. };
  133305. static encode_aux_threshmatch _vq_auxt__44u1__p6_1 = {
  133306. _vq_quantthresh__44u1__p6_1,
  133307. _vq_quantmap__44u1__p6_1,
  133308. 5,
  133309. 5
  133310. };
  133311. static static_codebook _44u1__p6_1 = {
  133312. 2, 25,
  133313. _vq_lengthlist__44u1__p6_1,
  133314. 1, -533725184, 1611661312, 3, 0,
  133315. _vq_quantlist__44u1__p6_1,
  133316. NULL,
  133317. &_vq_auxt__44u1__p6_1,
  133318. NULL,
  133319. 0
  133320. };
  133321. static long _vq_quantlist__44u1__p7_0[] = {
  133322. 3,
  133323. 2,
  133324. 4,
  133325. 1,
  133326. 5,
  133327. 0,
  133328. 6,
  133329. };
  133330. static long _vq_lengthlist__44u1__p7_0[] = {
  133331. 1, 3, 2, 9, 9, 7, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  133332. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  133333. 9, 9, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  133334. 8,
  133335. };
  133336. static float _vq_quantthresh__44u1__p7_0[] = {
  133337. -422.5, -253.5, -84.5, 84.5, 253.5, 422.5,
  133338. };
  133339. static long _vq_quantmap__44u1__p7_0[] = {
  133340. 5, 3, 1, 0, 2, 4, 6,
  133341. };
  133342. static encode_aux_threshmatch _vq_auxt__44u1__p7_0 = {
  133343. _vq_quantthresh__44u1__p7_0,
  133344. _vq_quantmap__44u1__p7_0,
  133345. 7,
  133346. 7
  133347. };
  133348. static static_codebook _44u1__p7_0 = {
  133349. 2, 49,
  133350. _vq_lengthlist__44u1__p7_0,
  133351. 1, -518017024, 1626677248, 3, 0,
  133352. _vq_quantlist__44u1__p7_0,
  133353. NULL,
  133354. &_vq_auxt__44u1__p7_0,
  133355. NULL,
  133356. 0
  133357. };
  133358. static long _vq_quantlist__44u1__p7_1[] = {
  133359. 6,
  133360. 5,
  133361. 7,
  133362. 4,
  133363. 8,
  133364. 3,
  133365. 9,
  133366. 2,
  133367. 10,
  133368. 1,
  133369. 11,
  133370. 0,
  133371. 12,
  133372. };
  133373. static long _vq_lengthlist__44u1__p7_1[] = {
  133374. 1, 4, 4, 6, 6, 6, 6, 7, 7, 8, 8, 9, 9, 5, 7, 7,
  133375. 8, 7, 7, 7, 9, 8,10, 9,10,11, 5, 7, 7, 8, 8, 7,
  133376. 7, 8, 9,10,10,11,11, 6, 8, 8, 9, 9, 9, 9,11,10,
  133377. 12,12,15,12, 6, 8, 8, 9, 9, 9, 9,11,11,12,11,14,
  133378. 12, 7, 8, 8,10,10,12,12,13,13,13,15,13,13, 7, 8,
  133379. 8,10,10,11,11,13,12,14,15,15,15, 9,10,10,11,12,
  133380. 13,13,14,15,14,15,14,15, 8,10,10,12,12,14,14,15,
  133381. 14,14,15,15,14,10,12,12,14,14,15,14,15,15,15,14,
  133382. 15,15,10,12,12,13,14,15,14,15,15,14,15,15,15,12,
  133383. 15,13,15,14,15,15,15,15,15,15,15,15,13,13,15,15,
  133384. 15,15,15,15,15,15,15,15,15,
  133385. };
  133386. static float _vq_quantthresh__44u1__p7_1[] = {
  133387. -71.5, -58.5, -45.5, -32.5, -19.5, -6.5, 6.5, 19.5,
  133388. 32.5, 45.5, 58.5, 71.5,
  133389. };
  133390. static long _vq_quantmap__44u1__p7_1[] = {
  133391. 11, 9, 7, 5, 3, 1, 0, 2,
  133392. 4, 6, 8, 10, 12,
  133393. };
  133394. static encode_aux_threshmatch _vq_auxt__44u1__p7_1 = {
  133395. _vq_quantthresh__44u1__p7_1,
  133396. _vq_quantmap__44u1__p7_1,
  133397. 13,
  133398. 13
  133399. };
  133400. static static_codebook _44u1__p7_1 = {
  133401. 2, 169,
  133402. _vq_lengthlist__44u1__p7_1,
  133403. 1, -523010048, 1618608128, 4, 0,
  133404. _vq_quantlist__44u1__p7_1,
  133405. NULL,
  133406. &_vq_auxt__44u1__p7_1,
  133407. NULL,
  133408. 0
  133409. };
  133410. static long _vq_quantlist__44u1__p7_2[] = {
  133411. 6,
  133412. 5,
  133413. 7,
  133414. 4,
  133415. 8,
  133416. 3,
  133417. 9,
  133418. 2,
  133419. 10,
  133420. 1,
  133421. 11,
  133422. 0,
  133423. 12,
  133424. };
  133425. static long _vq_lengthlist__44u1__p7_2[] = {
  133426. 2, 5, 4, 6, 6, 7, 7, 8, 8, 8, 8, 9, 8, 5, 5, 6,
  133427. 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 5, 6, 5, 7, 7, 8,
  133428. 8, 8, 8, 9, 9, 9, 9, 6, 7, 7, 8, 8, 8, 8, 9, 8,
  133429. 9, 9, 9, 9, 6, 7, 7, 8, 7, 8, 8, 9, 9, 9, 9, 9,
  133430. 9, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 7, 8,
  133431. 8, 9, 8, 9, 8, 9, 9, 9, 9, 9, 9, 8, 9, 8, 9, 9,
  133432. 9, 9, 9, 9, 9, 9,10,10, 8, 8, 9, 9, 9, 9, 9, 9,
  133433. 9, 9,10, 9,10, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  133434. 9, 9, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  133435. 9, 9, 9, 9, 9, 9, 9, 9,10,10,10, 9, 9, 9, 9, 9,
  133436. 9, 9, 9,10, 9, 9,10,10, 9,
  133437. };
  133438. static float _vq_quantthresh__44u1__p7_2[] = {
  133439. -5.5, -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5,
  133440. 2.5, 3.5, 4.5, 5.5,
  133441. };
  133442. static long _vq_quantmap__44u1__p7_2[] = {
  133443. 11, 9, 7, 5, 3, 1, 0, 2,
  133444. 4, 6, 8, 10, 12,
  133445. };
  133446. static encode_aux_threshmatch _vq_auxt__44u1__p7_2 = {
  133447. _vq_quantthresh__44u1__p7_2,
  133448. _vq_quantmap__44u1__p7_2,
  133449. 13,
  133450. 13
  133451. };
  133452. static static_codebook _44u1__p7_2 = {
  133453. 2, 169,
  133454. _vq_lengthlist__44u1__p7_2,
  133455. 1, -531103744, 1611661312, 4, 0,
  133456. _vq_quantlist__44u1__p7_2,
  133457. NULL,
  133458. &_vq_auxt__44u1__p7_2,
  133459. NULL,
  133460. 0
  133461. };
  133462. static long _huff_lengthlist__44u1__short[] = {
  133463. 12,13,14,13,17,12,15,17, 5, 5, 6,10,10,11,15,16,
  133464. 4, 3, 3, 7, 5, 7,10,16, 7, 7, 7,10, 9,11,12,16,
  133465. 6, 5, 5, 9, 5, 6,10,16, 8, 7, 7, 9, 6, 7, 9,16,
  133466. 11, 7, 3, 6, 4, 5, 8,16,12, 9, 4, 8, 5, 7, 9,16,
  133467. };
  133468. static static_codebook _huff_book__44u1__short = {
  133469. 2, 64,
  133470. _huff_lengthlist__44u1__short,
  133471. 0, 0, 0, 0, 0,
  133472. NULL,
  133473. NULL,
  133474. NULL,
  133475. NULL,
  133476. 0
  133477. };
  133478. static long _huff_lengthlist__44u2__long[] = {
  133479. 5, 9,14,12,15,13,10,13, 7, 4, 5, 6, 8, 7, 8,12,
  133480. 13, 4, 3, 5, 5, 6, 9,15,12, 6, 5, 6, 6, 6, 7,14,
  133481. 14, 7, 4, 6, 4, 6, 8,15,12, 6, 6, 5, 5, 5, 6,14,
  133482. 9, 7, 8, 6, 7, 5, 4,10,10,13,14,14,15,10, 6, 8,
  133483. };
  133484. static static_codebook _huff_book__44u2__long = {
  133485. 2, 64,
  133486. _huff_lengthlist__44u2__long,
  133487. 0, 0, 0, 0, 0,
  133488. NULL,
  133489. NULL,
  133490. NULL,
  133491. NULL,
  133492. 0
  133493. };
  133494. static long _vq_quantlist__44u2__p1_0[] = {
  133495. 1,
  133496. 0,
  133497. 2,
  133498. };
  133499. static long _vq_lengthlist__44u2__p1_0[] = {
  133500. 1, 4, 4, 5, 8, 7, 5, 7, 8, 5, 8, 8, 8,11,11, 8,
  133501. 10,11, 5, 8, 8, 8,11,10, 8,11,11, 4, 8, 8, 8,11,
  133502. 11, 8,11,11, 8,11,11,11,13,14,11,13,13, 7,11,11,
  133503. 10,13,12,11,14,14, 4, 8, 8, 8,11,11, 8,11,11, 8,
  133504. 11,11,11,14,13,10,12,13, 8,11,11,11,13,13,11,13,
  133505. 13,
  133506. };
  133507. static float _vq_quantthresh__44u2__p1_0[] = {
  133508. -0.5, 0.5,
  133509. };
  133510. static long _vq_quantmap__44u2__p1_0[] = {
  133511. 1, 0, 2,
  133512. };
  133513. static encode_aux_threshmatch _vq_auxt__44u2__p1_0 = {
  133514. _vq_quantthresh__44u2__p1_0,
  133515. _vq_quantmap__44u2__p1_0,
  133516. 3,
  133517. 3
  133518. };
  133519. static static_codebook _44u2__p1_0 = {
  133520. 4, 81,
  133521. _vq_lengthlist__44u2__p1_0,
  133522. 1, -535822336, 1611661312, 2, 0,
  133523. _vq_quantlist__44u2__p1_0,
  133524. NULL,
  133525. &_vq_auxt__44u2__p1_0,
  133526. NULL,
  133527. 0
  133528. };
  133529. static long _vq_quantlist__44u2__p2_0[] = {
  133530. 1,
  133531. 0,
  133532. 2,
  133533. };
  133534. static long _vq_lengthlist__44u2__p2_0[] = {
  133535. 2, 5, 5, 5, 6, 6, 5, 6, 6, 5, 6, 6, 7, 8, 8, 6,
  133536. 8, 8, 5, 6, 6, 6, 8, 7, 7, 8, 8, 5, 6, 6, 7, 8,
  133537. 8, 6, 8, 8, 6, 8, 8, 8, 9,10, 8,10,10, 6, 8, 8,
  133538. 7,10, 8, 8,10,10, 5, 6, 6, 6, 8, 8, 7, 8, 8, 6,
  133539. 8, 8, 8,10,10, 8, 8,10, 6, 8, 8, 8,10,10, 8,10,
  133540. 9,
  133541. };
  133542. static float _vq_quantthresh__44u2__p2_0[] = {
  133543. -0.5, 0.5,
  133544. };
  133545. static long _vq_quantmap__44u2__p2_0[] = {
  133546. 1, 0, 2,
  133547. };
  133548. static encode_aux_threshmatch _vq_auxt__44u2__p2_0 = {
  133549. _vq_quantthresh__44u2__p2_0,
  133550. _vq_quantmap__44u2__p2_0,
  133551. 3,
  133552. 3
  133553. };
  133554. static static_codebook _44u2__p2_0 = {
  133555. 4, 81,
  133556. _vq_lengthlist__44u2__p2_0,
  133557. 1, -535822336, 1611661312, 2, 0,
  133558. _vq_quantlist__44u2__p2_0,
  133559. NULL,
  133560. &_vq_auxt__44u2__p2_0,
  133561. NULL,
  133562. 0
  133563. };
  133564. static long _vq_quantlist__44u2__p3_0[] = {
  133565. 2,
  133566. 1,
  133567. 3,
  133568. 0,
  133569. 4,
  133570. };
  133571. static long _vq_lengthlist__44u2__p3_0[] = {
  133572. 2, 4, 4, 7, 8, 5, 7, 7, 9, 9, 5, 7, 7, 9, 9, 8,
  133573. 9, 9,12,11, 8, 9, 9,11,12, 5, 7, 7,10,10, 7, 9,
  133574. 9,11,11, 7, 9, 9,10,11,10,11,11,13,13, 9,10,11,
  133575. 12,13, 5, 7, 7,10,10, 7, 9, 9,11,10, 7, 9, 9,11,
  133576. 11, 9,11,10,13,13,10,11,11,13,13, 8,10,10,14,13,
  133577. 10,11,11,15,14, 9,11,11,15,14,13,14,13,16,14,12,
  133578. 13,13,15,16, 8,10,10,13,14, 9,11,11,14,15,10,11,
  133579. 11,14,15,12,13,13,15,15,12,13,14,15,16, 5, 7, 7,
  133580. 10,10, 7, 9, 9,11,11, 7, 9, 9,11,12,10,11,11,14,
  133581. 13,10,11,11,14,14, 7, 9, 9,12,12, 9,11,11,13,13,
  133582. 9,11,11,13,13,12,13,12,14,14,11,12,13,15,15, 7,
  133583. 9, 9,12,12, 8,11,10,13,12, 9,11,11,13,13,11,13,
  133584. 12,15,13,11,13,13,15,16, 9,12,11,15,15,11,12,12,
  133585. 16,15,11,12,13,16,16,13,14,15,16,15,13,15,15,17,
  133586. 17, 9,11,11,14,15,10,12,12,15,15,11,13,12,15,16,
  133587. 13,15,14,16,16,13,15,15,17,19, 5, 7, 7,10,10, 7,
  133588. 9, 9,12,11, 7, 9, 9,11,11,10,11,11,14,14,10,11,
  133589. 11,13,14, 7, 9, 9,12,12, 9,11,11,13,13, 9,10,11,
  133590. 12,13,11,13,12,16,15,11,12,12,14,15, 7, 9, 9,12,
  133591. 12, 9,11,11,13,13, 9,11,11,13,12,11,13,12,15,16,
  133592. 12,13,13,15,14, 9,11,11,15,14,11,13,12,16,15,10,
  133593. 11,12,15,15,13,14,14,18,17,13,14,14,15,17,10,11,
  133594. 11,14,15,11,13,12,15,17,11,13,12,15,16,13,15,14,
  133595. 18,17,14,15,15,16,18, 7,10,10,14,14,10,12,12,15,
  133596. 15,10,12,12,15,15,14,15,15,18,17,13,15,15,16,16,
  133597. 9,11,11,16,15,11,13,13,16,18,11,13,13,16,16,15,
  133598. 16,16, 0, 0,14,15,16,18,17, 9,11,11,15,15,10,13,
  133599. 12,17,16,11,12,13,16,17,14,15,16,19,19,14,15,15,
  133600. 0,20,12,14,14, 0, 0,13,14,16,19,18,13,15,16,20,
  133601. 17,16,18, 0, 0, 0,15,16,17,18,19,11,14,14, 0,19,
  133602. 12,15,14,17,17,13,15,15, 0, 0,16,17,15,20,19,15,
  133603. 17,16,19, 0, 8,10,10,14,15,10,12,11,15,15,10,11,
  133604. 12,16,15,13,14,14,19,17,14,15,15, 0, 0, 9,11,11,
  133605. 16,15,11,13,13,17,16,10,12,13,16,17,14,15,15,18,
  133606. 18,14,15,16,20,19, 9,12,12, 0,15,11,13,13,16,17,
  133607. 11,13,13,19,17,14,16,16,18,17,15,16,16,17,19,11,
  133608. 14,14,18,18,13,14,15, 0, 0,12,14,15,19,18,15,16,
  133609. 19, 0,19,15,16,19,19,17,12,14,14,16,19,13,15,15,
  133610. 0,17,13,15,14,18,18,15,16,15, 0,18,16,17,17, 0,
  133611. 0,
  133612. };
  133613. static float _vq_quantthresh__44u2__p3_0[] = {
  133614. -1.5, -0.5, 0.5, 1.5,
  133615. };
  133616. static long _vq_quantmap__44u2__p3_0[] = {
  133617. 3, 1, 0, 2, 4,
  133618. };
  133619. static encode_aux_threshmatch _vq_auxt__44u2__p3_0 = {
  133620. _vq_quantthresh__44u2__p3_0,
  133621. _vq_quantmap__44u2__p3_0,
  133622. 5,
  133623. 5
  133624. };
  133625. static static_codebook _44u2__p3_0 = {
  133626. 4, 625,
  133627. _vq_lengthlist__44u2__p3_0,
  133628. 1, -533725184, 1611661312, 3, 0,
  133629. _vq_quantlist__44u2__p3_0,
  133630. NULL,
  133631. &_vq_auxt__44u2__p3_0,
  133632. NULL,
  133633. 0
  133634. };
  133635. static long _vq_quantlist__44u2__p4_0[] = {
  133636. 2,
  133637. 1,
  133638. 3,
  133639. 0,
  133640. 4,
  133641. };
  133642. static long _vq_lengthlist__44u2__p4_0[] = {
  133643. 4, 5, 5, 8, 8, 5, 7, 6, 9, 9, 5, 6, 7, 9, 9, 9,
  133644. 9, 9,11,11, 9, 9, 9,11,11, 5, 7, 7, 9, 9, 7, 8,
  133645. 8,10,10, 7, 7, 8,10,10,10,10,10,11,12, 9,10,10,
  133646. 11,12, 5, 7, 7, 9, 9, 6, 8, 7,10,10, 7, 8, 8,10,
  133647. 10, 9,10,10,12,11, 9,10,10,12,11, 9,10,10,12,12,
  133648. 10,10,10,13,12, 9,10,10,12,13,12,12,12,14,14,11,
  133649. 12,12,13,14, 9,10,10,12,12, 9,10,10,12,13,10,10,
  133650. 10,12,13,11,12,12,14,13,12,12,12,14,13, 5, 7, 7,
  133651. 10, 9, 7, 8, 8,10,10, 7, 8, 8,10,10,10,10,10,12,
  133652. 12,10,10,10,12,12, 7, 8, 8,11,10, 8, 8, 9,11,11,
  133653. 8, 9, 9,11,11,10,11,11,12,13,10,11,11,13,13, 6,
  133654. 8, 8,10,10, 7, 9, 8,11,10, 8, 9, 9,11,11,10,11,
  133655. 10,13,11,10,11,11,13,13, 9,10,10,13,13,10,11,11,
  133656. 13,13,10,11,11,14,13,12,11,13,12,15,12,13,13,15,
  133657. 15, 9,10,10,12,13,10,11,10,13,13,10,11,11,13,13,
  133658. 12,13,11,15,13,12,13,13,15,15, 5, 7, 7, 9,10, 7,
  133659. 8, 8,10,10, 7, 8, 8,10,10,10,10,10,12,12,10,10,
  133660. 11,12,12, 6, 8, 8,10,10, 8, 9, 9,11,11, 7, 8, 9,
  133661. 10,11,10,11,11,13,13,10,10,11,11,13, 7, 8, 8,10,
  133662. 11, 8, 9, 9,11,11, 8, 9, 8,11,11,10,11,11,13,13,
  133663. 10,11,11,13,12, 9,10,10,13,12,10,11,11,14,13,10,
  133664. 10,11,13,13,12,13,13,15,15,12,11,13,12,14, 9,10,
  133665. 10,12,13,10,11,11,13,14,10,11,11,13,13,12,13,13,
  133666. 15,15,12,13,12,15,12, 8, 9, 9,12,12, 9,11,10,13,
  133667. 13, 9,10,10,13,13,12,13,13,15,15,12,12,12,14,14,
  133668. 9,10,10,13,13,10,11,11,13,14,10,11,11,14,12,13,
  133669. 13,14,14,16,12,13,13,15,14, 9,10,10,13,13,10,11,
  133670. 10,14,13,10,11,11,13,14,12,14,13,16,14,13,13,13,
  133671. 14,15,11,13,12,15,14,11,12,13,14,15,12,13,13,16,
  133672. 15,14,12,15,12,16,14,15,15,17,16,11,12,12,14,15,
  133673. 11,13,11,15,14,12,13,13,15,16,13,15,12,17,13,14,
  133674. 15,15,16,16, 8, 9, 9,12,12, 9,10,10,13,13, 9,10,
  133675. 10,13,13,12,13,12,14,14,12,13,13,15,15, 9,10,10,
  133676. 13,13,10,11,11,14,13,10,10,11,13,14,12,13,13,15,
  133677. 14,12,12,14,14,16, 9,10,10,13,13,10,11,11,13,14,
  133678. 10,11,11,14,13,13,13,13,15,15,13,14,13,16,14,11,
  133679. 12,12,14,14,12,13,13,16,15,11,12,13,14,15,14,15,
  133680. 15,16,16,14,13,15,13,17,11,12,12,14,15,12,13,13,
  133681. 15,16,11,13,12,15,15,14,15,14,16,16,14,15,12,17,
  133682. 13,
  133683. };
  133684. static float _vq_quantthresh__44u2__p4_0[] = {
  133685. -1.5, -0.5, 0.5, 1.5,
  133686. };
  133687. static long _vq_quantmap__44u2__p4_0[] = {
  133688. 3, 1, 0, 2, 4,
  133689. };
  133690. static encode_aux_threshmatch _vq_auxt__44u2__p4_0 = {
  133691. _vq_quantthresh__44u2__p4_0,
  133692. _vq_quantmap__44u2__p4_0,
  133693. 5,
  133694. 5
  133695. };
  133696. static static_codebook _44u2__p4_0 = {
  133697. 4, 625,
  133698. _vq_lengthlist__44u2__p4_0,
  133699. 1, -533725184, 1611661312, 3, 0,
  133700. _vq_quantlist__44u2__p4_0,
  133701. NULL,
  133702. &_vq_auxt__44u2__p4_0,
  133703. NULL,
  133704. 0
  133705. };
  133706. static long _vq_quantlist__44u2__p5_0[] = {
  133707. 4,
  133708. 3,
  133709. 5,
  133710. 2,
  133711. 6,
  133712. 1,
  133713. 7,
  133714. 0,
  133715. 8,
  133716. };
  133717. static long _vq_lengthlist__44u2__p5_0[] = {
  133718. 1, 4, 4, 7, 7, 8, 8, 9, 9, 4, 6, 5, 8, 8, 8, 8,
  133719. 10,10, 4, 5, 6, 8, 8, 8, 8,10,10, 7, 8, 8, 9, 9,
  133720. 9, 9,11,11, 7, 8, 8, 9, 9, 9, 9,11,11, 8, 8, 8,
  133721. 9, 9,10,11,12,12, 8, 8, 8, 9, 9,10,10,12,12,10,
  133722. 10,10,11,11,12,12,13,13,10,10,10,11,11,12,12,13,
  133723. 13,
  133724. };
  133725. static float _vq_quantthresh__44u2__p5_0[] = {
  133726. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  133727. };
  133728. static long _vq_quantmap__44u2__p5_0[] = {
  133729. 7, 5, 3, 1, 0, 2, 4, 6,
  133730. 8,
  133731. };
  133732. static encode_aux_threshmatch _vq_auxt__44u2__p5_0 = {
  133733. _vq_quantthresh__44u2__p5_0,
  133734. _vq_quantmap__44u2__p5_0,
  133735. 9,
  133736. 9
  133737. };
  133738. static static_codebook _44u2__p5_0 = {
  133739. 2, 81,
  133740. _vq_lengthlist__44u2__p5_0,
  133741. 1, -531628032, 1611661312, 4, 0,
  133742. _vq_quantlist__44u2__p5_0,
  133743. NULL,
  133744. &_vq_auxt__44u2__p5_0,
  133745. NULL,
  133746. 0
  133747. };
  133748. static long _vq_quantlist__44u2__p6_0[] = {
  133749. 6,
  133750. 5,
  133751. 7,
  133752. 4,
  133753. 8,
  133754. 3,
  133755. 9,
  133756. 2,
  133757. 10,
  133758. 1,
  133759. 11,
  133760. 0,
  133761. 12,
  133762. };
  133763. static long _vq_lengthlist__44u2__p6_0[] = {
  133764. 1, 4, 4, 6, 6, 8, 8,10,10,11,11,14,13, 4, 6, 5,
  133765. 8, 8, 9, 9,11,10,12,11,15,14, 4, 5, 6, 8, 8, 9,
  133766. 9,11,11,11,11,14,14, 6, 8, 8,10, 9,11,11,11,11,
  133767. 12,12,15,15, 6, 8, 8, 9, 9,11,11,11,12,12,12,15,
  133768. 15, 8,10,10,11,11,11,11,12,12,13,13,15,16, 8,10,
  133769. 10,11,11,11,11,12,12,13,13,16,16,10,11,11,12,12,
  133770. 12,12,13,13,13,13,17,16,10,11,11,12,12,12,12,13,
  133771. 13,13,14,16,17,11,12,12,13,13,13,13,14,14,15,14,
  133772. 18,17,11,12,12,13,13,13,13,14,14,14,15,19,18,14,
  133773. 15,15,15,15,16,16,18,19,18,18, 0, 0,14,15,15,16,
  133774. 15,17,17,16,18,17,18, 0, 0,
  133775. };
  133776. static float _vq_quantthresh__44u2__p6_0[] = {
  133777. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  133778. 12.5, 17.5, 22.5, 27.5,
  133779. };
  133780. static long _vq_quantmap__44u2__p6_0[] = {
  133781. 11, 9, 7, 5, 3, 1, 0, 2,
  133782. 4, 6, 8, 10, 12,
  133783. };
  133784. static encode_aux_threshmatch _vq_auxt__44u2__p6_0 = {
  133785. _vq_quantthresh__44u2__p6_0,
  133786. _vq_quantmap__44u2__p6_0,
  133787. 13,
  133788. 13
  133789. };
  133790. static static_codebook _44u2__p6_0 = {
  133791. 2, 169,
  133792. _vq_lengthlist__44u2__p6_0,
  133793. 1, -526516224, 1616117760, 4, 0,
  133794. _vq_quantlist__44u2__p6_0,
  133795. NULL,
  133796. &_vq_auxt__44u2__p6_0,
  133797. NULL,
  133798. 0
  133799. };
  133800. static long _vq_quantlist__44u2__p6_1[] = {
  133801. 2,
  133802. 1,
  133803. 3,
  133804. 0,
  133805. 4,
  133806. };
  133807. static long _vq_lengthlist__44u2__p6_1[] = {
  133808. 2, 4, 4, 5, 5, 4, 5, 5, 6, 5, 4, 5, 5, 5, 6, 5,
  133809. 6, 5, 6, 6, 5, 5, 6, 6, 6,
  133810. };
  133811. static float _vq_quantthresh__44u2__p6_1[] = {
  133812. -1.5, -0.5, 0.5, 1.5,
  133813. };
  133814. static long _vq_quantmap__44u2__p6_1[] = {
  133815. 3, 1, 0, 2, 4,
  133816. };
  133817. static encode_aux_threshmatch _vq_auxt__44u2__p6_1 = {
  133818. _vq_quantthresh__44u2__p6_1,
  133819. _vq_quantmap__44u2__p6_1,
  133820. 5,
  133821. 5
  133822. };
  133823. static static_codebook _44u2__p6_1 = {
  133824. 2, 25,
  133825. _vq_lengthlist__44u2__p6_1,
  133826. 1, -533725184, 1611661312, 3, 0,
  133827. _vq_quantlist__44u2__p6_1,
  133828. NULL,
  133829. &_vq_auxt__44u2__p6_1,
  133830. NULL,
  133831. 0
  133832. };
  133833. static long _vq_quantlist__44u2__p7_0[] = {
  133834. 4,
  133835. 3,
  133836. 5,
  133837. 2,
  133838. 6,
  133839. 1,
  133840. 7,
  133841. 0,
  133842. 8,
  133843. };
  133844. static long _vq_lengthlist__44u2__p7_0[] = {
  133845. 1, 3, 2,12,12,12,12,12,12, 4,12,12,12,12,12,12,
  133846. 12,12, 5,12,12,12,12,12,12,12,12,12,12,11,11,11,
  133847. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  133848. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  133849. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  133850. 11,
  133851. };
  133852. static float _vq_quantthresh__44u2__p7_0[] = {
  133853. -591.5, -422.5, -253.5, -84.5, 84.5, 253.5, 422.5, 591.5,
  133854. };
  133855. static long _vq_quantmap__44u2__p7_0[] = {
  133856. 7, 5, 3, 1, 0, 2, 4, 6,
  133857. 8,
  133858. };
  133859. static encode_aux_threshmatch _vq_auxt__44u2__p7_0 = {
  133860. _vq_quantthresh__44u2__p7_0,
  133861. _vq_quantmap__44u2__p7_0,
  133862. 9,
  133863. 9
  133864. };
  133865. static static_codebook _44u2__p7_0 = {
  133866. 2, 81,
  133867. _vq_lengthlist__44u2__p7_0,
  133868. 1, -516612096, 1626677248, 4, 0,
  133869. _vq_quantlist__44u2__p7_0,
  133870. NULL,
  133871. &_vq_auxt__44u2__p7_0,
  133872. NULL,
  133873. 0
  133874. };
  133875. static long _vq_quantlist__44u2__p7_1[] = {
  133876. 6,
  133877. 5,
  133878. 7,
  133879. 4,
  133880. 8,
  133881. 3,
  133882. 9,
  133883. 2,
  133884. 10,
  133885. 1,
  133886. 11,
  133887. 0,
  133888. 12,
  133889. };
  133890. static long _vq_lengthlist__44u2__p7_1[] = {
  133891. 1, 4, 4, 7, 6, 7, 6, 8, 7, 9, 7, 9, 8, 4, 7, 6,
  133892. 8, 8, 9, 8,10, 9,10,10,11,11, 4, 7, 7, 8, 8, 8,
  133893. 8, 9,10,11,11,11,11, 6, 8, 8,10,10,10,10,11,11,
  133894. 12,12,12,12, 7, 8, 8,10,10,10,10,11,11,12,12,13,
  133895. 13, 7, 9, 9,11,10,12,12,13,13,14,13,14,14, 7, 9,
  133896. 9,10,11,11,12,13,13,13,13,16,14, 9,10,10,12,12,
  133897. 13,13,14,14,15,16,15,16, 9,10,10,12,12,12,13,14,
  133898. 14,14,15,16,15,10,12,12,13,13,15,13,16,16,15,17,
  133899. 17,17,10,11,11,12,14,14,14,15,15,17,17,15,17,11,
  133900. 12,12,14,14,14,15,15,15,17,16,17,17,10,12,12,13,
  133901. 14,14,14,17,15,17,17,17,17,
  133902. };
  133903. static float _vq_quantthresh__44u2__p7_1[] = {
  133904. -71.5, -58.5, -45.5, -32.5, -19.5, -6.5, 6.5, 19.5,
  133905. 32.5, 45.5, 58.5, 71.5,
  133906. };
  133907. static long _vq_quantmap__44u2__p7_1[] = {
  133908. 11, 9, 7, 5, 3, 1, 0, 2,
  133909. 4, 6, 8, 10, 12,
  133910. };
  133911. static encode_aux_threshmatch _vq_auxt__44u2__p7_1 = {
  133912. _vq_quantthresh__44u2__p7_1,
  133913. _vq_quantmap__44u2__p7_1,
  133914. 13,
  133915. 13
  133916. };
  133917. static static_codebook _44u2__p7_1 = {
  133918. 2, 169,
  133919. _vq_lengthlist__44u2__p7_1,
  133920. 1, -523010048, 1618608128, 4, 0,
  133921. _vq_quantlist__44u2__p7_1,
  133922. NULL,
  133923. &_vq_auxt__44u2__p7_1,
  133924. NULL,
  133925. 0
  133926. };
  133927. static long _vq_quantlist__44u2__p7_2[] = {
  133928. 6,
  133929. 5,
  133930. 7,
  133931. 4,
  133932. 8,
  133933. 3,
  133934. 9,
  133935. 2,
  133936. 10,
  133937. 1,
  133938. 11,
  133939. 0,
  133940. 12,
  133941. };
  133942. static long _vq_lengthlist__44u2__p7_2[] = {
  133943. 2, 5, 5, 6, 6, 7, 7, 8, 7, 8, 8, 8, 8, 5, 6, 6,
  133944. 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 5, 6, 6, 7, 7, 8,
  133945. 7, 8, 8, 8, 8, 8, 8, 6, 7, 7, 7, 8, 8, 8, 8, 8,
  133946. 9, 9, 9, 9, 6, 7, 7, 8, 7, 8, 8, 9, 9, 9, 9, 9,
  133947. 9, 7, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 7, 8,
  133948. 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 8, 8, 8, 8, 9,
  133949. 9, 9, 9, 9, 9, 9, 9, 9, 8, 8, 8, 9, 9, 9, 9, 9,
  133950. 9, 9, 9, 9, 9, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  133951. 9, 9, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 8,
  133952. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 8, 9, 9, 9,
  133953. 9, 9, 9, 9, 9, 9, 9, 9, 9,
  133954. };
  133955. static float _vq_quantthresh__44u2__p7_2[] = {
  133956. -5.5, -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5,
  133957. 2.5, 3.5, 4.5, 5.5,
  133958. };
  133959. static long _vq_quantmap__44u2__p7_2[] = {
  133960. 11, 9, 7, 5, 3, 1, 0, 2,
  133961. 4, 6, 8, 10, 12,
  133962. };
  133963. static encode_aux_threshmatch _vq_auxt__44u2__p7_2 = {
  133964. _vq_quantthresh__44u2__p7_2,
  133965. _vq_quantmap__44u2__p7_2,
  133966. 13,
  133967. 13
  133968. };
  133969. static static_codebook _44u2__p7_2 = {
  133970. 2, 169,
  133971. _vq_lengthlist__44u2__p7_2,
  133972. 1, -531103744, 1611661312, 4, 0,
  133973. _vq_quantlist__44u2__p7_2,
  133974. NULL,
  133975. &_vq_auxt__44u2__p7_2,
  133976. NULL,
  133977. 0
  133978. };
  133979. static long _huff_lengthlist__44u2__short[] = {
  133980. 13,15,17,17,15,15,12,17,11, 9, 7,10,10, 9,12,17,
  133981. 10, 6, 3, 6, 5, 7,10,17,15,10, 6, 9, 8, 9,11,17,
  133982. 15, 8, 4, 7, 3, 5, 9,16,16,10, 5, 8, 4, 5, 8,16,
  133983. 13,11, 5, 8, 3, 3, 5,14,13,12, 7,10, 5, 5, 7,14,
  133984. };
  133985. static static_codebook _huff_book__44u2__short = {
  133986. 2, 64,
  133987. _huff_lengthlist__44u2__short,
  133988. 0, 0, 0, 0, 0,
  133989. NULL,
  133990. NULL,
  133991. NULL,
  133992. NULL,
  133993. 0
  133994. };
  133995. static long _huff_lengthlist__44u3__long[] = {
  133996. 6, 9,13,12,14,11,10,13, 8, 4, 5, 7, 8, 7, 8,12,
  133997. 11, 4, 3, 5, 5, 7, 9,14,11, 6, 5, 6, 6, 6, 7,13,
  133998. 13, 7, 5, 6, 4, 5, 7,14,11, 7, 6, 6, 5, 5, 6,13,
  133999. 9, 7, 8, 6, 7, 5, 3, 9, 9,12,13,12,14,10, 6, 7,
  134000. };
  134001. static static_codebook _huff_book__44u3__long = {
  134002. 2, 64,
  134003. _huff_lengthlist__44u3__long,
  134004. 0, 0, 0, 0, 0,
  134005. NULL,
  134006. NULL,
  134007. NULL,
  134008. NULL,
  134009. 0
  134010. };
  134011. static long _vq_quantlist__44u3__p1_0[] = {
  134012. 1,
  134013. 0,
  134014. 2,
  134015. };
  134016. static long _vq_lengthlist__44u3__p1_0[] = {
  134017. 1, 4, 4, 5, 8, 7, 5, 7, 8, 5, 8, 8, 8,10,11, 8,
  134018. 10,11, 5, 8, 8, 8,11,10, 8,11,11, 4, 8, 8, 8,11,
  134019. 11, 8,11,11, 8,11,11,11,13,14,11,14,14, 8,11,11,
  134020. 10,14,12,11,14,14, 4, 8, 8, 8,11,11, 8,11,11, 7,
  134021. 11,11,11,14,14,10,12,14, 8,11,11,11,14,14,11,14,
  134022. 13,
  134023. };
  134024. static float _vq_quantthresh__44u3__p1_0[] = {
  134025. -0.5, 0.5,
  134026. };
  134027. static long _vq_quantmap__44u3__p1_0[] = {
  134028. 1, 0, 2,
  134029. };
  134030. static encode_aux_threshmatch _vq_auxt__44u3__p1_0 = {
  134031. _vq_quantthresh__44u3__p1_0,
  134032. _vq_quantmap__44u3__p1_0,
  134033. 3,
  134034. 3
  134035. };
  134036. static static_codebook _44u3__p1_0 = {
  134037. 4, 81,
  134038. _vq_lengthlist__44u3__p1_0,
  134039. 1, -535822336, 1611661312, 2, 0,
  134040. _vq_quantlist__44u3__p1_0,
  134041. NULL,
  134042. &_vq_auxt__44u3__p1_0,
  134043. NULL,
  134044. 0
  134045. };
  134046. static long _vq_quantlist__44u3__p2_0[] = {
  134047. 1,
  134048. 0,
  134049. 2,
  134050. };
  134051. static long _vq_lengthlist__44u3__p2_0[] = {
  134052. 2, 5, 4, 5, 6, 6, 5, 6, 6, 5, 6, 6, 7, 8, 8, 6,
  134053. 8, 8, 5, 6, 6, 6, 8, 8, 7, 8, 8, 5, 7, 6, 7, 8,
  134054. 8, 6, 8, 8, 7, 8, 8, 8, 9,10, 8,10,10, 6, 8, 8,
  134055. 8,10, 8, 8,10,10, 5, 6, 6, 6, 8, 8, 7, 8, 8, 6,
  134056. 8, 8, 8,10,10, 8, 8,10, 7, 8, 8, 8,10,10, 8,10,
  134057. 9,
  134058. };
  134059. static float _vq_quantthresh__44u3__p2_0[] = {
  134060. -0.5, 0.5,
  134061. };
  134062. static long _vq_quantmap__44u3__p2_0[] = {
  134063. 1, 0, 2,
  134064. };
  134065. static encode_aux_threshmatch _vq_auxt__44u3__p2_0 = {
  134066. _vq_quantthresh__44u3__p2_0,
  134067. _vq_quantmap__44u3__p2_0,
  134068. 3,
  134069. 3
  134070. };
  134071. static static_codebook _44u3__p2_0 = {
  134072. 4, 81,
  134073. _vq_lengthlist__44u3__p2_0,
  134074. 1, -535822336, 1611661312, 2, 0,
  134075. _vq_quantlist__44u3__p2_0,
  134076. NULL,
  134077. &_vq_auxt__44u3__p2_0,
  134078. NULL,
  134079. 0
  134080. };
  134081. static long _vq_quantlist__44u3__p3_0[] = {
  134082. 2,
  134083. 1,
  134084. 3,
  134085. 0,
  134086. 4,
  134087. };
  134088. static long _vq_lengthlist__44u3__p3_0[] = {
  134089. 2, 4, 4, 7, 7, 5, 7, 7, 9, 9, 5, 7, 7, 9, 9, 8,
  134090. 9, 9,12,12, 8, 9, 9,11,12, 5, 7, 7,10,10, 7, 9,
  134091. 9,11,11, 7, 9, 9,10,11,10,11,11,13,13, 9,10,11,
  134092. 13,13, 5, 7, 7,10,10, 7, 9, 9,11,10, 7, 9, 9,11,
  134093. 11, 9,11,10,13,13,10,11,11,14,13, 8,10,10,14,13,
  134094. 10,11,11,15,14, 9,11,11,14,14,13,14,13,16,16,12,
  134095. 13,13,15,15, 8,10,10,13,14, 9,11,11,14,14,10,11,
  134096. 11,14,15,12,13,13,15,15,13,14,14,15,16, 5, 7, 7,
  134097. 10,10, 7, 9, 9,11,11, 7, 9, 9,11,12,10,11,11,14,
  134098. 14,10,11,11,14,14, 7, 9, 9,12,12, 9,11,11,13,13,
  134099. 9,11,11,13,13,12,12,13,15,15,11,12,13,15,16, 7,
  134100. 9, 9,11,11, 8,11,10,13,12, 9,11,11,13,13,11,13,
  134101. 12,15,13,11,13,13,15,16, 9,12,11,15,14,11,12,13,
  134102. 16,15,11,13,13,15,16,14,14,15,17,16,13,15,16, 0,
  134103. 17, 9,11,11,15,15,10,13,12,15,15,11,13,13,15,16,
  134104. 13,15,13,16,15,14,16,15, 0,19, 5, 7, 7,10,10, 7,
  134105. 9, 9,11,11, 7, 9, 9,11,11,10,12,11,14,14,10,11,
  134106. 12,14,14, 7, 9, 9,12,12, 9,11,11,14,13, 9,10,11,
  134107. 12,13,11,13,13,16,16,11,12,13,13,16, 7, 9, 9,12,
  134108. 12, 9,11,11,13,13, 9,11,11,13,13,11,13,13,15,15,
  134109. 12,13,12,15,14, 9,11,11,15,14,11,13,12,16,16,10,
  134110. 12,12,15,15,13,15,15,17,19,13,14,15,16,17,10,12,
  134111. 12,15,15,11,13,13,16,16,11,13,13,15,16,13,15,15,
  134112. 0, 0,14,15,15,16,16, 8,10,10,14,14,10,12,12,15,
  134113. 15,10,12,11,15,16,14,15,15,19,20,13,14,14,18,16,
  134114. 9,11,11,15,15,11,13,13,17,16,11,13,13,16,16,15,
  134115. 17,17,20,20,14,15,16,17,20, 9,11,11,15,15,10,13,
  134116. 12,16,15,11,13,13,15,17,14,16,15,18, 0,14,16,15,
  134117. 18,20,12,14,14, 0, 0,14,14,16, 0, 0,13,16,15, 0,
  134118. 0,17,17,18, 0, 0,16,17,19,19, 0,12,14,14,18, 0,
  134119. 12,16,14, 0,17,13,15,15,18, 0,16,18,17, 0,17,16,
  134120. 18,17, 0, 0, 7,10,10,14,14,10,12,11,15,15,10,12,
  134121. 12,16,15,13,15,15,18, 0,14,15,15,17, 0, 9,11,11,
  134122. 15,15,11,13,13,16,16,11,12,13,16,16,14,15,16,17,
  134123. 17,14,16,16,16,18, 9,11,12,16,16,11,13,13,17,17,
  134124. 11,14,13,20,17,15,16,16,19, 0,15,16,17, 0,19,11,
  134125. 13,14,17,16,14,15,15,20,18,13,14,15,17,19,16,18,
  134126. 18, 0,20,16,16,19,17, 0,12,15,14,17, 0,14,15,15,
  134127. 18,19,13,16,15,19,20,15,18,18, 0,20,17, 0,16, 0,
  134128. 0,
  134129. };
  134130. static float _vq_quantthresh__44u3__p3_0[] = {
  134131. -1.5, -0.5, 0.5, 1.5,
  134132. };
  134133. static long _vq_quantmap__44u3__p3_0[] = {
  134134. 3, 1, 0, 2, 4,
  134135. };
  134136. static encode_aux_threshmatch _vq_auxt__44u3__p3_0 = {
  134137. _vq_quantthresh__44u3__p3_0,
  134138. _vq_quantmap__44u3__p3_0,
  134139. 5,
  134140. 5
  134141. };
  134142. static static_codebook _44u3__p3_0 = {
  134143. 4, 625,
  134144. _vq_lengthlist__44u3__p3_0,
  134145. 1, -533725184, 1611661312, 3, 0,
  134146. _vq_quantlist__44u3__p3_0,
  134147. NULL,
  134148. &_vq_auxt__44u3__p3_0,
  134149. NULL,
  134150. 0
  134151. };
  134152. static long _vq_quantlist__44u3__p4_0[] = {
  134153. 2,
  134154. 1,
  134155. 3,
  134156. 0,
  134157. 4,
  134158. };
  134159. static long _vq_lengthlist__44u3__p4_0[] = {
  134160. 4, 5, 5, 8, 8, 5, 7, 6, 9, 9, 5, 6, 7, 9, 9, 9,
  134161. 9, 9,11,11, 9, 9, 9,11,11, 5, 7, 7, 9, 9, 7, 8,
  134162. 8,10,10, 7, 7, 8,10,10, 9,10,10,11,12, 9,10,10,
  134163. 11,12, 5, 7, 7, 9, 9, 7, 8, 7,10,10, 7, 8, 8,10,
  134164. 10, 9,10, 9,12,11, 9,10,10,12,11, 9,10, 9,12,12,
  134165. 9,10,10,13,12, 9,10,10,12,13,12,12,12,14,14,11,
  134166. 12,12,13,14, 9, 9,10,12,12, 9,10,10,12,12, 9,10,
  134167. 10,12,13,11,12,11,14,13,12,12,12,14,13, 5, 7, 7,
  134168. 9, 9, 7, 8, 8,10,10, 7, 8, 8,10,10,10,10,10,12,
  134169. 12, 9,10,10,12,12, 7, 8, 8,11,10, 8, 8, 9,11,11,
  134170. 8, 9, 9,11,11,11,11,11,12,13,10,11,11,13,13, 6,
  134171. 8, 8,10,10, 7, 9, 8,11,10, 8, 9, 9,11,11,10,11,
  134172. 10,13,11,10,11,11,13,13, 9,11,10,13,12,10,11,11,
  134173. 13,13,10,11,11,13,13,12,12,13,12,15,12,13,13,15,
  134174. 15, 9,10,10,12,13,10,11,10,13,12,10,11,11,13,14,
  134175. 12,13,11,15,13,12,13,13,15,15, 5, 7, 7, 9, 9, 7,
  134176. 8, 8,10,10, 7, 8, 8,10,10, 9,10,10,12,12,10,10,
  134177. 11,12,12, 6, 8, 8,10,10, 8, 9, 9,11,11, 7, 8, 9,
  134178. 10,11,10,11,11,13,13,10,10,11,11,13, 7, 8, 8,10,
  134179. 10, 8, 9, 9,11,11, 8, 9, 9,11,11,10,11,11,13,13,
  134180. 11,11,11,13,12, 9,10,10,13,12,10,11,11,14,13,10,
  134181. 10,11,12,13,12,13,13,15,15,12,11,13,13,14, 9,10,
  134182. 11,12,13,10,11,11,13,13,10,11,11,13,13,12,13,13,
  134183. 15,15,12,13,12,15,12, 8, 9, 9,12,12, 9,11,10,13,
  134184. 13, 9,10,10,13,13,12,13,13,15,14,12,12,12,14,13,
  134185. 9,10,10,13,12,10,11,11,13,13,10,11,11,14,12,13,
  134186. 13,14,14,16,12,13,13,15,15, 9,10,10,13,13,10,11,
  134187. 10,14,13,10,11,11,13,14,12,14,13,15,14,13,13,13,
  134188. 15,15,11,13,12,15,14,11,12,13,14,15,12,13,13,16,
  134189. 14,14,12,15,12,16,14,15,15,17,15,11,12,12,14,14,
  134190. 11,13,11,15,14,12,13,13,15,15,13,15,12,17,13,14,
  134191. 15,15,16,16, 8, 9, 9,12,12, 9,10,10,12,13, 9,10,
  134192. 10,13,13,12,12,12,14,14,12,13,13,15,15, 9,10,10,
  134193. 13,12,10,11,11,14,13,10,10,11,13,14,12,13,13,15,
  134194. 15,12,12,13,14,16, 9,10,10,13,13,10,11,11,13,14,
  134195. 10,11,11,14,13,12,13,13,14,15,13,14,13,16,14,11,
  134196. 12,12,14,14,12,13,13,15,14,11,12,13,14,15,14,15,
  134197. 15,16,16,13,13,15,13,16,11,12,12,14,15,12,13,13,
  134198. 14,15,11,13,12,15,14,14,15,15,16,16,14,15,12,16,
  134199. 13,
  134200. };
  134201. static float _vq_quantthresh__44u3__p4_0[] = {
  134202. -1.5, -0.5, 0.5, 1.5,
  134203. };
  134204. static long _vq_quantmap__44u3__p4_0[] = {
  134205. 3, 1, 0, 2, 4,
  134206. };
  134207. static encode_aux_threshmatch _vq_auxt__44u3__p4_0 = {
  134208. _vq_quantthresh__44u3__p4_0,
  134209. _vq_quantmap__44u3__p4_0,
  134210. 5,
  134211. 5
  134212. };
  134213. static static_codebook _44u3__p4_0 = {
  134214. 4, 625,
  134215. _vq_lengthlist__44u3__p4_0,
  134216. 1, -533725184, 1611661312, 3, 0,
  134217. _vq_quantlist__44u3__p4_0,
  134218. NULL,
  134219. &_vq_auxt__44u3__p4_0,
  134220. NULL,
  134221. 0
  134222. };
  134223. static long _vq_quantlist__44u3__p5_0[] = {
  134224. 4,
  134225. 3,
  134226. 5,
  134227. 2,
  134228. 6,
  134229. 1,
  134230. 7,
  134231. 0,
  134232. 8,
  134233. };
  134234. static long _vq_lengthlist__44u3__p5_0[] = {
  134235. 2, 3, 3, 6, 6, 7, 7, 9, 9, 4, 5, 5, 7, 7, 8, 8,
  134236. 10,10, 4, 5, 5, 7, 7, 8, 8,10,10, 6, 7, 7, 8, 8,
  134237. 9, 9,11,10, 6, 7, 7, 8, 8, 9, 9,10,10, 7, 8, 8,
  134238. 9, 9,10,10,11,11, 7, 8, 8, 9, 9,10,10,11,11, 9,
  134239. 10,10,11,10,11,11,12,12, 9,10,10,10,10,11,11,12,
  134240. 12,
  134241. };
  134242. static float _vq_quantthresh__44u3__p5_0[] = {
  134243. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  134244. };
  134245. static long _vq_quantmap__44u3__p5_0[] = {
  134246. 7, 5, 3, 1, 0, 2, 4, 6,
  134247. 8,
  134248. };
  134249. static encode_aux_threshmatch _vq_auxt__44u3__p5_0 = {
  134250. _vq_quantthresh__44u3__p5_0,
  134251. _vq_quantmap__44u3__p5_0,
  134252. 9,
  134253. 9
  134254. };
  134255. static static_codebook _44u3__p5_0 = {
  134256. 2, 81,
  134257. _vq_lengthlist__44u3__p5_0,
  134258. 1, -531628032, 1611661312, 4, 0,
  134259. _vq_quantlist__44u3__p5_0,
  134260. NULL,
  134261. &_vq_auxt__44u3__p5_0,
  134262. NULL,
  134263. 0
  134264. };
  134265. static long _vq_quantlist__44u3__p6_0[] = {
  134266. 6,
  134267. 5,
  134268. 7,
  134269. 4,
  134270. 8,
  134271. 3,
  134272. 9,
  134273. 2,
  134274. 10,
  134275. 1,
  134276. 11,
  134277. 0,
  134278. 12,
  134279. };
  134280. static long _vq_lengthlist__44u3__p6_0[] = {
  134281. 1, 4, 4, 6, 6, 8, 8, 9, 9,10,11,13,14, 4, 6, 5,
  134282. 8, 8, 9, 9,10,10,11,11,14,14, 4, 6, 6, 8, 8, 9,
  134283. 9,10,10,11,11,14,14, 6, 8, 8, 9, 9,10,10,11,11,
  134284. 12,12,15,15, 6, 8, 8, 9, 9,10,11,11,11,12,12,15,
  134285. 15, 8, 9, 9,11,10,11,11,12,12,13,13,15,16, 8, 9,
  134286. 9,10,11,11,11,12,12,13,13,16,16,10,10,11,11,11,
  134287. 12,12,13,13,13,14,17,16, 9,10,11,12,11,12,12,13,
  134288. 13,13,13,16,18,11,12,11,12,12,13,13,13,14,15,14,
  134289. 17,17,11,11,12,12,12,13,13,13,14,14,15,18,17,14,
  134290. 15,15,15,15,16,16,17,17,19,18, 0,20,14,15,14,15,
  134291. 15,16,16,16,17,18,16,20,18,
  134292. };
  134293. static float _vq_quantthresh__44u3__p6_0[] = {
  134294. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  134295. 12.5, 17.5, 22.5, 27.5,
  134296. };
  134297. static long _vq_quantmap__44u3__p6_0[] = {
  134298. 11, 9, 7, 5, 3, 1, 0, 2,
  134299. 4, 6, 8, 10, 12,
  134300. };
  134301. static encode_aux_threshmatch _vq_auxt__44u3__p6_0 = {
  134302. _vq_quantthresh__44u3__p6_0,
  134303. _vq_quantmap__44u3__p6_0,
  134304. 13,
  134305. 13
  134306. };
  134307. static static_codebook _44u3__p6_0 = {
  134308. 2, 169,
  134309. _vq_lengthlist__44u3__p6_0,
  134310. 1, -526516224, 1616117760, 4, 0,
  134311. _vq_quantlist__44u3__p6_0,
  134312. NULL,
  134313. &_vq_auxt__44u3__p6_0,
  134314. NULL,
  134315. 0
  134316. };
  134317. static long _vq_quantlist__44u3__p6_1[] = {
  134318. 2,
  134319. 1,
  134320. 3,
  134321. 0,
  134322. 4,
  134323. };
  134324. static long _vq_lengthlist__44u3__p6_1[] = {
  134325. 2, 4, 4, 5, 5, 4, 5, 5, 6, 5, 4, 5, 5, 5, 6, 5,
  134326. 6, 5, 6, 6, 5, 5, 6, 6, 6,
  134327. };
  134328. static float _vq_quantthresh__44u3__p6_1[] = {
  134329. -1.5, -0.5, 0.5, 1.5,
  134330. };
  134331. static long _vq_quantmap__44u3__p6_1[] = {
  134332. 3, 1, 0, 2, 4,
  134333. };
  134334. static encode_aux_threshmatch _vq_auxt__44u3__p6_1 = {
  134335. _vq_quantthresh__44u3__p6_1,
  134336. _vq_quantmap__44u3__p6_1,
  134337. 5,
  134338. 5
  134339. };
  134340. static static_codebook _44u3__p6_1 = {
  134341. 2, 25,
  134342. _vq_lengthlist__44u3__p6_1,
  134343. 1, -533725184, 1611661312, 3, 0,
  134344. _vq_quantlist__44u3__p6_1,
  134345. NULL,
  134346. &_vq_auxt__44u3__p6_1,
  134347. NULL,
  134348. 0
  134349. };
  134350. static long _vq_quantlist__44u3__p7_0[] = {
  134351. 4,
  134352. 3,
  134353. 5,
  134354. 2,
  134355. 6,
  134356. 1,
  134357. 7,
  134358. 0,
  134359. 8,
  134360. };
  134361. static long _vq_lengthlist__44u3__p7_0[] = {
  134362. 1, 3, 3,10,10,10,10,10,10, 4,10,10,10,10,10,10,
  134363. 10,10, 4,10,10,10,10,10,10,10,10,10,10, 9, 9, 9,
  134364. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  134365. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  134366. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  134367. 9,
  134368. };
  134369. static float _vq_quantthresh__44u3__p7_0[] = {
  134370. -892.5, -637.5, -382.5, -127.5, 127.5, 382.5, 637.5, 892.5,
  134371. };
  134372. static long _vq_quantmap__44u3__p7_0[] = {
  134373. 7, 5, 3, 1, 0, 2, 4, 6,
  134374. 8,
  134375. };
  134376. static encode_aux_threshmatch _vq_auxt__44u3__p7_0 = {
  134377. _vq_quantthresh__44u3__p7_0,
  134378. _vq_quantmap__44u3__p7_0,
  134379. 9,
  134380. 9
  134381. };
  134382. static static_codebook _44u3__p7_0 = {
  134383. 2, 81,
  134384. _vq_lengthlist__44u3__p7_0,
  134385. 1, -515907584, 1627381760, 4, 0,
  134386. _vq_quantlist__44u3__p7_0,
  134387. NULL,
  134388. &_vq_auxt__44u3__p7_0,
  134389. NULL,
  134390. 0
  134391. };
  134392. static long _vq_quantlist__44u3__p7_1[] = {
  134393. 7,
  134394. 6,
  134395. 8,
  134396. 5,
  134397. 9,
  134398. 4,
  134399. 10,
  134400. 3,
  134401. 11,
  134402. 2,
  134403. 12,
  134404. 1,
  134405. 13,
  134406. 0,
  134407. 14,
  134408. };
  134409. static long _vq_lengthlist__44u3__p7_1[] = {
  134410. 1, 4, 4, 6, 6, 7, 6, 8, 7, 9, 8,10, 9,11,11, 4,
  134411. 7, 7, 8, 7, 9, 9,10,10,11,11,11,11,12,12, 4, 7,
  134412. 7, 7, 7, 9, 9,10,10,11,11,12,12,12,11, 6, 8, 8,
  134413. 9, 9,10,10,11,11,12,12,13,12,13,13, 6, 8, 8, 9,
  134414. 9,10,11,11,11,12,12,13,14,13,13, 8, 9, 9,11,11,
  134415. 12,12,12,13,14,13,14,14,14,15, 8, 9, 9,11,11,11,
  134416. 12,13,14,13,14,15,17,14,15, 9,10,10,12,12,13,13,
  134417. 13,14,15,15,15,16,16,16, 9,11,11,12,12,13,13,14,
  134418. 14,14,15,16,16,16,16,10,12,12,13,13,14,14,15,15,
  134419. 15,16,17,17,17,17,10,12,11,13,13,15,14,15,14,16,
  134420. 17,16,16,16,16,11,13,12,14,14,14,14,15,16,17,16,
  134421. 17,17,17,17,11,13,12,14,14,14,15,17,16,17,17,17,
  134422. 17,17,17,12,13,13,15,16,15,16,17,17,16,16,17,17,
  134423. 17,17,12,13,13,15,15,15,16,17,17,17,16,17,16,17,
  134424. 17,
  134425. };
  134426. static float _vq_quantthresh__44u3__p7_1[] = {
  134427. -110.5, -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5,
  134428. 25.5, 42.5, 59.5, 76.5, 93.5, 110.5,
  134429. };
  134430. static long _vq_quantmap__44u3__p7_1[] = {
  134431. 13, 11, 9, 7, 5, 3, 1, 0,
  134432. 2, 4, 6, 8, 10, 12, 14,
  134433. };
  134434. static encode_aux_threshmatch _vq_auxt__44u3__p7_1 = {
  134435. _vq_quantthresh__44u3__p7_1,
  134436. _vq_quantmap__44u3__p7_1,
  134437. 15,
  134438. 15
  134439. };
  134440. static static_codebook _44u3__p7_1 = {
  134441. 2, 225,
  134442. _vq_lengthlist__44u3__p7_1,
  134443. 1, -522338304, 1620115456, 4, 0,
  134444. _vq_quantlist__44u3__p7_1,
  134445. NULL,
  134446. &_vq_auxt__44u3__p7_1,
  134447. NULL,
  134448. 0
  134449. };
  134450. static long _vq_quantlist__44u3__p7_2[] = {
  134451. 8,
  134452. 7,
  134453. 9,
  134454. 6,
  134455. 10,
  134456. 5,
  134457. 11,
  134458. 4,
  134459. 12,
  134460. 3,
  134461. 13,
  134462. 2,
  134463. 14,
  134464. 1,
  134465. 15,
  134466. 0,
  134467. 16,
  134468. };
  134469. static long _vq_lengthlist__44u3__p7_2[] = {
  134470. 2, 5, 5, 7, 6, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  134471. 9, 5, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  134472. 10,10, 5, 6, 6, 7, 7, 8, 8, 8, 8, 9, 8, 9, 9, 9,
  134473. 9,10, 9, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  134474. 10,10,10,10, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9,10,
  134475. 9,10,10,10,10, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  134476. 10,10,10,10,10,10, 7, 8, 8, 9, 8, 9, 9, 9, 9,10,
  134477. 9,10,10,10,10,10,10, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  134478. 9,10,10,10,10,10,10,10, 8, 9, 8, 9, 9, 9, 9,10,
  134479. 9,10,10,10,10,10,10,10,10, 9, 9, 9, 9, 9, 9,10,
  134480. 9,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9, 9,10,
  134481. 9,10,10,10,10,10,10,10,10,10,10, 9, 9, 9,10, 9,
  134482. 10,10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9,10,
  134483. 10,10,10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9,
  134484. 10,10,10,10,10,10,10,10,10,10,10,10,10,11, 9,10,
  134485. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,11, 9,
  134486. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  134487. 9,10,10,10,10,10,10,10,10,10,10,10,11,11,11,10,
  134488. 11,
  134489. };
  134490. static float _vq_quantthresh__44u3__p7_2[] = {
  134491. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  134492. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  134493. };
  134494. static long _vq_quantmap__44u3__p7_2[] = {
  134495. 15, 13, 11, 9, 7, 5, 3, 1,
  134496. 0, 2, 4, 6, 8, 10, 12, 14,
  134497. 16,
  134498. };
  134499. static encode_aux_threshmatch _vq_auxt__44u3__p7_2 = {
  134500. _vq_quantthresh__44u3__p7_2,
  134501. _vq_quantmap__44u3__p7_2,
  134502. 17,
  134503. 17
  134504. };
  134505. static static_codebook _44u3__p7_2 = {
  134506. 2, 289,
  134507. _vq_lengthlist__44u3__p7_2,
  134508. 1, -529530880, 1611661312, 5, 0,
  134509. _vq_quantlist__44u3__p7_2,
  134510. NULL,
  134511. &_vq_auxt__44u3__p7_2,
  134512. NULL,
  134513. 0
  134514. };
  134515. static long _huff_lengthlist__44u3__short[] = {
  134516. 14,14,14,15,13,15,12,16,10, 8, 7, 9, 9, 8,12,16,
  134517. 10, 5, 4, 6, 5, 6, 9,16,14, 8, 6, 8, 7, 8,10,16,
  134518. 14, 7, 4, 6, 3, 5, 8,16,15, 9, 5, 7, 4, 4, 7,16,
  134519. 13,10, 6, 7, 4, 3, 4,13,13,12, 7, 9, 5, 5, 6,12,
  134520. };
  134521. static static_codebook _huff_book__44u3__short = {
  134522. 2, 64,
  134523. _huff_lengthlist__44u3__short,
  134524. 0, 0, 0, 0, 0,
  134525. NULL,
  134526. NULL,
  134527. NULL,
  134528. NULL,
  134529. 0
  134530. };
  134531. static long _huff_lengthlist__44u4__long[] = {
  134532. 3, 8,12,12,13,12,11,13, 5, 4, 6, 7, 8, 8, 9,13,
  134533. 9, 5, 4, 5, 5, 7, 9,13, 9, 6, 5, 6, 6, 7, 8,12,
  134534. 12, 7, 5, 6, 4, 5, 8,13,11, 7, 6, 6, 5, 5, 6,12,
  134535. 10, 8, 8, 7, 7, 5, 3, 8,10,12,13,12,12, 9, 6, 7,
  134536. };
  134537. static static_codebook _huff_book__44u4__long = {
  134538. 2, 64,
  134539. _huff_lengthlist__44u4__long,
  134540. 0, 0, 0, 0, 0,
  134541. NULL,
  134542. NULL,
  134543. NULL,
  134544. NULL,
  134545. 0
  134546. };
  134547. static long _vq_quantlist__44u4__p1_0[] = {
  134548. 1,
  134549. 0,
  134550. 2,
  134551. };
  134552. static long _vq_lengthlist__44u4__p1_0[] = {
  134553. 1, 4, 4, 5, 8, 7, 5, 7, 8, 5, 8, 8, 8,10,11, 8,
  134554. 10,11, 5, 8, 8, 8,11,10, 8,11,11, 4, 8, 8, 8,11,
  134555. 11, 8,11,11, 8,11,11,11,13,14,11,15,14, 8,11,11,
  134556. 10,13,12,11,14,14, 4, 8, 8, 8,11,11, 8,11,11, 7,
  134557. 11,11,11,15,14,10,12,14, 8,11,11,11,14,14,11,14,
  134558. 13,
  134559. };
  134560. static float _vq_quantthresh__44u4__p1_0[] = {
  134561. -0.5, 0.5,
  134562. };
  134563. static long _vq_quantmap__44u4__p1_0[] = {
  134564. 1, 0, 2,
  134565. };
  134566. static encode_aux_threshmatch _vq_auxt__44u4__p1_0 = {
  134567. _vq_quantthresh__44u4__p1_0,
  134568. _vq_quantmap__44u4__p1_0,
  134569. 3,
  134570. 3
  134571. };
  134572. static static_codebook _44u4__p1_0 = {
  134573. 4, 81,
  134574. _vq_lengthlist__44u4__p1_0,
  134575. 1, -535822336, 1611661312, 2, 0,
  134576. _vq_quantlist__44u4__p1_0,
  134577. NULL,
  134578. &_vq_auxt__44u4__p1_0,
  134579. NULL,
  134580. 0
  134581. };
  134582. static long _vq_quantlist__44u4__p2_0[] = {
  134583. 1,
  134584. 0,
  134585. 2,
  134586. };
  134587. static long _vq_lengthlist__44u4__p2_0[] = {
  134588. 2, 5, 5, 5, 6, 6, 5, 6, 6, 5, 6, 6, 7, 8, 8, 6,
  134589. 8, 8, 5, 6, 6, 6, 8, 8, 7, 8, 8, 5, 7, 6, 6, 8,
  134590. 8, 6, 8, 8, 6, 8, 8, 8, 9,10, 8,10,10, 6, 8, 8,
  134591. 8,10, 8, 8,10,10, 5, 6, 6, 6, 8, 8, 6, 8, 8, 6,
  134592. 8, 8, 8,10,10, 8, 8,10, 6, 8, 8, 8,10,10, 8,10,
  134593. 9,
  134594. };
  134595. static float _vq_quantthresh__44u4__p2_0[] = {
  134596. -0.5, 0.5,
  134597. };
  134598. static long _vq_quantmap__44u4__p2_0[] = {
  134599. 1, 0, 2,
  134600. };
  134601. static encode_aux_threshmatch _vq_auxt__44u4__p2_0 = {
  134602. _vq_quantthresh__44u4__p2_0,
  134603. _vq_quantmap__44u4__p2_0,
  134604. 3,
  134605. 3
  134606. };
  134607. static static_codebook _44u4__p2_0 = {
  134608. 4, 81,
  134609. _vq_lengthlist__44u4__p2_0,
  134610. 1, -535822336, 1611661312, 2, 0,
  134611. _vq_quantlist__44u4__p2_0,
  134612. NULL,
  134613. &_vq_auxt__44u4__p2_0,
  134614. NULL,
  134615. 0
  134616. };
  134617. static long _vq_quantlist__44u4__p3_0[] = {
  134618. 2,
  134619. 1,
  134620. 3,
  134621. 0,
  134622. 4,
  134623. };
  134624. static long _vq_lengthlist__44u4__p3_0[] = {
  134625. 2, 4, 4, 8, 8, 5, 7, 7, 9, 9, 5, 7, 7, 9, 9, 8,
  134626. 10, 9,12,12, 8, 9,10,12,12, 5, 7, 7,10,10, 7, 9,
  134627. 9,11,11, 7, 9, 9,11,11,10,12,11,14,14, 9,10,11,
  134628. 13,14, 5, 7, 7,10,10, 7, 9, 9,11,11, 7, 9, 9,11,
  134629. 11, 9,11,10,14,13,10,11,11,14,14, 8,10,10,14,13,
  134630. 10,12,12,15,14, 9,11,11,15,14,13,14,14,17,17,12,
  134631. 14,14,16,16, 8,10,10,14,14, 9,11,11,14,15,10,12,
  134632. 12,14,15,12,14,13,16,16,13,14,15,15,18, 4, 7, 7,
  134633. 10,10, 7, 9, 9,12,11, 7, 9, 9,11,12,10,12,11,15,
  134634. 14,10,11,12,14,15, 7, 9, 9,12,12, 9,11,12,13,13,
  134635. 9,11,12,13,13,12,13,13,15,16,11,13,13,15,16, 7,
  134636. 9, 9,12,12, 9,11,10,13,12, 9,11,12,13,14,11,13,
  134637. 12,16,14,12,13,13,15,16,10,12,12,16,15,11,13,13,
  134638. 17,16,11,13,13,17,16,14,15,15,17,17,14,16,16,18,
  134639. 20, 9,11,11,15,16,11,13,12,16,16,11,13,13,16,17,
  134640. 14,15,14,18,16,14,16,16,17,20, 5, 7, 7,10,10, 7,
  134641. 9, 9,12,11, 7, 9,10,11,12,10,12,11,15,15,10,12,
  134642. 12,14,14, 7, 9, 9,12,12, 9,12,11,14,13, 9,10,11,
  134643. 12,13,12,13,14,16,16,11,12,13,14,16, 7, 9, 9,12,
  134644. 12, 9,12,11,13,13, 9,12,11,13,13,11,13,13,16,16,
  134645. 12,13,13,16,15, 9,11,11,16,14,11,13,13,16,16,11,
  134646. 12,13,16,16,14,16,16,17,17,13,14,15,16,17,10,12,
  134647. 12,15,15,11,13,13,16,17,11,13,13,16,16,14,16,15,
  134648. 19,19,14,15,15,17,18, 8,10,10,14,14,10,12,12,15,
  134649. 15,10,12,12,16,16,14,16,15,20,19,13,15,15,17,16,
  134650. 9,12,12,16,16,11,13,13,16,18,11,14,13,16,17,16,
  134651. 17,16,20, 0,15,16,18,18,20, 9,11,11,15,15,11,14,
  134652. 12,17,16,11,13,13,17,17,15,17,15,20,20,14,16,16,
  134653. 17, 0,13,15,14,18,16,14,15,16, 0,18,14,16,16, 0,
  134654. 0,18,16, 0, 0,20,16,18,18, 0, 0,12,14,14,17,18,
  134655. 13,15,14,20,18,14,16,15,19,19,16,20,16, 0,18,16,
  134656. 19,17,19, 0, 8,10,10,14,14,10,12,12,16,15,10,12,
  134657. 12,16,16,13,15,15,18,17,14,16,16,19, 0, 9,11,11,
  134658. 16,15,11,14,13,18,17,11,12,13,17,18,14,17,16,18,
  134659. 18,15,16,17,18,18, 9,12,12,16,16,11,13,13,16,18,
  134660. 11,14,13,17,17,15,16,16,18,20,16,17,17,20,20,12,
  134661. 14,14,18,17,14,16,16, 0,19,13,14,15,18, 0,16, 0,
  134662. 0, 0, 0,16,16, 0,19,20,13,15,14, 0, 0,14,16,16,
  134663. 18,19,14,16,15, 0,20,16,20,18, 0,20,17,20,17, 0,
  134664. 0,
  134665. };
  134666. static float _vq_quantthresh__44u4__p3_0[] = {
  134667. -1.5, -0.5, 0.5, 1.5,
  134668. };
  134669. static long _vq_quantmap__44u4__p3_0[] = {
  134670. 3, 1, 0, 2, 4,
  134671. };
  134672. static encode_aux_threshmatch _vq_auxt__44u4__p3_0 = {
  134673. _vq_quantthresh__44u4__p3_0,
  134674. _vq_quantmap__44u4__p3_0,
  134675. 5,
  134676. 5
  134677. };
  134678. static static_codebook _44u4__p3_0 = {
  134679. 4, 625,
  134680. _vq_lengthlist__44u4__p3_0,
  134681. 1, -533725184, 1611661312, 3, 0,
  134682. _vq_quantlist__44u4__p3_0,
  134683. NULL,
  134684. &_vq_auxt__44u4__p3_0,
  134685. NULL,
  134686. 0
  134687. };
  134688. static long _vq_quantlist__44u4__p4_0[] = {
  134689. 2,
  134690. 1,
  134691. 3,
  134692. 0,
  134693. 4,
  134694. };
  134695. static long _vq_lengthlist__44u4__p4_0[] = {
  134696. 4, 5, 5, 8, 8, 5, 7, 6, 9, 9, 5, 6, 7, 9, 9, 9,
  134697. 9, 9,11,11, 8, 9, 9,11,11, 5, 7, 7, 9, 9, 7, 8,
  134698. 8,10,10, 7, 7, 8,10,10, 9,10,10,11,12, 9,10,10,
  134699. 11,12, 5, 7, 7, 9, 9, 7, 8, 7,10,10, 7, 8, 8,10,
  134700. 10, 9,10,10,12,11, 9,10,10,12,11, 9,10, 9,12,12,
  134701. 9,10,10,13,12, 9,10,10,12,12,12,12,12,14,14,11,
  134702. 12,12,13,14, 9, 9,10,12,12, 9,10,10,13,13, 9,10,
  134703. 10,12,13,11,12,12,14,13,11,12,12,14,14, 5, 7, 7,
  134704. 9, 9, 7, 8, 8,10,10, 7, 8, 8,10,10,10,10,10,12,
  134705. 12, 9,10,10,12,12, 7, 8, 8,11,10, 8, 8, 9,11,11,
  134706. 8, 9, 9,11,11,11,11,11,12,13,10,11,11,13,13, 6,
  134707. 8, 8,10,10, 7, 9, 8,11,10, 8, 9, 9,11,11,10,11,
  134708. 10,13,11,10,11,11,13,13, 9,11,10,13,12,10,11,11,
  134709. 13,14,10,11,11,14,13,12,12,13,12,15,12,13,13,15,
  134710. 15, 9,10,10,12,13,10,11,10,13,12,10,11,11,13,14,
  134711. 12,13,11,15,13,13,13,13,15,15, 5, 7, 7, 9, 9, 7,
  134712. 8, 8,10,10, 7, 8, 8,10,10, 9,10,10,12,12,10,10,
  134713. 11,12,13, 6, 8, 8,10,10, 8, 9, 9,11,11, 7, 8, 9,
  134714. 10,11,10,11,11,13,13,10,10,11,11,13, 7, 8, 8,10,
  134715. 11, 8, 9, 9,11,11, 8, 9, 8,11,11,10,11,11,13,13,
  134716. 11,12,11,13,12, 9,10,10,13,12,10,11,11,14,13,10,
  134717. 10,11,12,13,12,13,13,15,15,12,11,13,13,14, 9,10,
  134718. 11,12,13,10,11,11,13,14,10,11,11,13,13,12,13,13,
  134719. 15,15,12,13,12,15,12, 8, 9, 9,12,12, 9,11,10,13,
  134720. 13, 9,10,10,13,13,12,13,13,15,15,12,12,12,14,14,
  134721. 9,10,10,13,13,10,11,11,13,14,10,11,11,14,13,13,
  134722. 13,14,14,16,13,13,13,15,15, 9,10,10,13,13,10,11,
  134723. 10,14,13,10,11,11,13,14,12,14,13,16,14,12,13,13,
  134724. 14,15,11,12,12,15,14,11,12,13,14,15,12,13,13,16,
  134725. 15,14,12,15,12,16,14,15,15,16,16,11,12,12,14,14,
  134726. 11,13,12,15,14,12,13,13,15,16,13,15,13,17,13,14,
  134727. 15,15,16,17, 8, 9, 9,12,12, 9,10,10,12,13, 9,10,
  134728. 10,13,13,12,12,12,14,14,12,13,13,15,15, 9,10,10,
  134729. 13,12,10,11,11,14,13,10,10,11,13,14,13,13,13,15,
  134730. 15,12,13,14,14,16, 9,10,10,13,13,10,11,11,13,14,
  134731. 10,11,11,14,14,13,13,13,15,15,13,14,13,16,14,11,
  134732. 12,12,15,14,12,13,13,16,15,11,12,13,14,15,14,15,
  134733. 15,17,16,13,13,15,13,16,11,12,13,14,15,13,13,13,
  134734. 15,16,11,13,12,15,14,14,15,15,16,16,14,15,12,17,
  134735. 13,
  134736. };
  134737. static float _vq_quantthresh__44u4__p4_0[] = {
  134738. -1.5, -0.5, 0.5, 1.5,
  134739. };
  134740. static long _vq_quantmap__44u4__p4_0[] = {
  134741. 3, 1, 0, 2, 4,
  134742. };
  134743. static encode_aux_threshmatch _vq_auxt__44u4__p4_0 = {
  134744. _vq_quantthresh__44u4__p4_0,
  134745. _vq_quantmap__44u4__p4_0,
  134746. 5,
  134747. 5
  134748. };
  134749. static static_codebook _44u4__p4_0 = {
  134750. 4, 625,
  134751. _vq_lengthlist__44u4__p4_0,
  134752. 1, -533725184, 1611661312, 3, 0,
  134753. _vq_quantlist__44u4__p4_0,
  134754. NULL,
  134755. &_vq_auxt__44u4__p4_0,
  134756. NULL,
  134757. 0
  134758. };
  134759. static long _vq_quantlist__44u4__p5_0[] = {
  134760. 4,
  134761. 3,
  134762. 5,
  134763. 2,
  134764. 6,
  134765. 1,
  134766. 7,
  134767. 0,
  134768. 8,
  134769. };
  134770. static long _vq_lengthlist__44u4__p5_0[] = {
  134771. 2, 3, 3, 6, 6, 7, 7, 9, 9, 4, 5, 5, 7, 7, 8, 8,
  134772. 10, 9, 4, 5, 5, 7, 7, 8, 8,10,10, 6, 7, 7, 8, 8,
  134773. 9, 9,11,10, 6, 7, 7, 8, 8, 9, 9,10,11, 7, 8, 8,
  134774. 9, 9,10,10,11,11, 7, 8, 8, 9, 9,10,10,11,11, 9,
  134775. 10,10,11,10,11,11,12,12, 9,10,10,10,11,11,11,12,
  134776. 12,
  134777. };
  134778. static float _vq_quantthresh__44u4__p5_0[] = {
  134779. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  134780. };
  134781. static long _vq_quantmap__44u4__p5_0[] = {
  134782. 7, 5, 3, 1, 0, 2, 4, 6,
  134783. 8,
  134784. };
  134785. static encode_aux_threshmatch _vq_auxt__44u4__p5_0 = {
  134786. _vq_quantthresh__44u4__p5_0,
  134787. _vq_quantmap__44u4__p5_0,
  134788. 9,
  134789. 9
  134790. };
  134791. static static_codebook _44u4__p5_0 = {
  134792. 2, 81,
  134793. _vq_lengthlist__44u4__p5_0,
  134794. 1, -531628032, 1611661312, 4, 0,
  134795. _vq_quantlist__44u4__p5_0,
  134796. NULL,
  134797. &_vq_auxt__44u4__p5_0,
  134798. NULL,
  134799. 0
  134800. };
  134801. static long _vq_quantlist__44u4__p6_0[] = {
  134802. 6,
  134803. 5,
  134804. 7,
  134805. 4,
  134806. 8,
  134807. 3,
  134808. 9,
  134809. 2,
  134810. 10,
  134811. 1,
  134812. 11,
  134813. 0,
  134814. 12,
  134815. };
  134816. static long _vq_lengthlist__44u4__p6_0[] = {
  134817. 1, 4, 4, 6, 6, 8, 8, 9, 9,11,10,13,13, 4, 6, 5,
  134818. 8, 8, 9, 9,10,10,11,11,14,14, 4, 6, 6, 8, 8, 9,
  134819. 9,10,10,11,11,14,14, 6, 8, 8, 9, 9,10,10,11,11,
  134820. 12,12,15,15, 6, 8, 8, 9, 9,10,11,11,11,12,12,15,
  134821. 15, 8, 9, 9,11,10,11,11,12,12,13,13,16,16, 8, 9,
  134822. 9,10,10,11,11,12,12,13,13,16,16,10,10,10,12,11,
  134823. 12,12,13,13,14,14,16,16,10,10,10,11,12,12,12,13,
  134824. 13,13,14,16,17,11,12,11,12,12,13,13,14,14,15,14,
  134825. 18,17,11,11,12,12,12,13,13,14,14,14,15,19,18,14,
  134826. 15,14,15,15,17,16,17,17,17,17,21, 0,14,15,15,16,
  134827. 16,16,16,17,17,18,17,20,21,
  134828. };
  134829. static float _vq_quantthresh__44u4__p6_0[] = {
  134830. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  134831. 12.5, 17.5, 22.5, 27.5,
  134832. };
  134833. static long _vq_quantmap__44u4__p6_0[] = {
  134834. 11, 9, 7, 5, 3, 1, 0, 2,
  134835. 4, 6, 8, 10, 12,
  134836. };
  134837. static encode_aux_threshmatch _vq_auxt__44u4__p6_0 = {
  134838. _vq_quantthresh__44u4__p6_0,
  134839. _vq_quantmap__44u4__p6_0,
  134840. 13,
  134841. 13
  134842. };
  134843. static static_codebook _44u4__p6_0 = {
  134844. 2, 169,
  134845. _vq_lengthlist__44u4__p6_0,
  134846. 1, -526516224, 1616117760, 4, 0,
  134847. _vq_quantlist__44u4__p6_0,
  134848. NULL,
  134849. &_vq_auxt__44u4__p6_0,
  134850. NULL,
  134851. 0
  134852. };
  134853. static long _vq_quantlist__44u4__p6_1[] = {
  134854. 2,
  134855. 1,
  134856. 3,
  134857. 0,
  134858. 4,
  134859. };
  134860. static long _vq_lengthlist__44u4__p6_1[] = {
  134861. 2, 4, 4, 5, 5, 4, 5, 5, 6, 5, 4, 5, 5, 5, 6, 5,
  134862. 6, 5, 6, 6, 5, 5, 6, 6, 6,
  134863. };
  134864. static float _vq_quantthresh__44u4__p6_1[] = {
  134865. -1.5, -0.5, 0.5, 1.5,
  134866. };
  134867. static long _vq_quantmap__44u4__p6_1[] = {
  134868. 3, 1, 0, 2, 4,
  134869. };
  134870. static encode_aux_threshmatch _vq_auxt__44u4__p6_1 = {
  134871. _vq_quantthresh__44u4__p6_1,
  134872. _vq_quantmap__44u4__p6_1,
  134873. 5,
  134874. 5
  134875. };
  134876. static static_codebook _44u4__p6_1 = {
  134877. 2, 25,
  134878. _vq_lengthlist__44u4__p6_1,
  134879. 1, -533725184, 1611661312, 3, 0,
  134880. _vq_quantlist__44u4__p6_1,
  134881. NULL,
  134882. &_vq_auxt__44u4__p6_1,
  134883. NULL,
  134884. 0
  134885. };
  134886. static long _vq_quantlist__44u4__p7_0[] = {
  134887. 6,
  134888. 5,
  134889. 7,
  134890. 4,
  134891. 8,
  134892. 3,
  134893. 9,
  134894. 2,
  134895. 10,
  134896. 1,
  134897. 11,
  134898. 0,
  134899. 12,
  134900. };
  134901. static long _vq_lengthlist__44u4__p7_0[] = {
  134902. 1, 3, 3,12,12,12,12,12,12,12,12,12,12, 3,12,11,
  134903. 12,12,12,12,12,12,12,12,12,12, 4,11,10,12,12,12,
  134904. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  134905. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  134906. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  134907. 12,12,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  134908. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  134909. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  134910. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  134911. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  134912. 11,11,11,11,11,11,11,11,11,
  134913. };
  134914. static float _vq_quantthresh__44u4__p7_0[] = {
  134915. -1402.5, -1147.5, -892.5, -637.5, -382.5, -127.5, 127.5, 382.5,
  134916. 637.5, 892.5, 1147.5, 1402.5,
  134917. };
  134918. static long _vq_quantmap__44u4__p7_0[] = {
  134919. 11, 9, 7, 5, 3, 1, 0, 2,
  134920. 4, 6, 8, 10, 12,
  134921. };
  134922. static encode_aux_threshmatch _vq_auxt__44u4__p7_0 = {
  134923. _vq_quantthresh__44u4__p7_0,
  134924. _vq_quantmap__44u4__p7_0,
  134925. 13,
  134926. 13
  134927. };
  134928. static static_codebook _44u4__p7_0 = {
  134929. 2, 169,
  134930. _vq_lengthlist__44u4__p7_0,
  134931. 1, -514332672, 1627381760, 4, 0,
  134932. _vq_quantlist__44u4__p7_0,
  134933. NULL,
  134934. &_vq_auxt__44u4__p7_0,
  134935. NULL,
  134936. 0
  134937. };
  134938. static long _vq_quantlist__44u4__p7_1[] = {
  134939. 7,
  134940. 6,
  134941. 8,
  134942. 5,
  134943. 9,
  134944. 4,
  134945. 10,
  134946. 3,
  134947. 11,
  134948. 2,
  134949. 12,
  134950. 1,
  134951. 13,
  134952. 0,
  134953. 14,
  134954. };
  134955. static long _vq_lengthlist__44u4__p7_1[] = {
  134956. 1, 4, 4, 6, 6, 7, 7, 9, 8,10, 8,10, 9,11,11, 4,
  134957. 7, 6, 8, 7, 9, 9,10,10,11,10,11,10,12,10, 4, 6,
  134958. 7, 8, 8, 9, 9,10,10,11,11,11,11,12,12, 6, 8, 8,
  134959. 10, 9,11,10,12,11,12,12,12,12,13,13, 6, 8, 8,10,
  134960. 10,10,11,11,11,12,12,13,12,13,13, 8, 9, 9,11,11,
  134961. 12,11,12,12,13,13,13,13,13,13, 8, 9, 9,11,11,11,
  134962. 12,12,12,13,13,13,13,13,13, 9,10,10,12,11,13,13,
  134963. 13,13,14,13,13,14,14,14, 9,10,11,11,12,12,13,13,
  134964. 13,13,13,14,15,14,14,10,11,11,12,12,13,13,14,14,
  134965. 14,14,14,15,16,16,10,11,11,12,13,13,13,13,15,14,
  134966. 14,15,16,15,16,10,12,12,13,13,14,14,14,15,15,15,
  134967. 15,15,15,16,11,12,12,13,13,14,14,14,15,15,15,16,
  134968. 15,17,16,11,12,12,13,13,13,15,15,14,16,16,16,16,
  134969. 16,17,11,12,12,13,13,14,14,15,14,15,15,17,17,16,
  134970. 16,
  134971. };
  134972. static float _vq_quantthresh__44u4__p7_1[] = {
  134973. -110.5, -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5,
  134974. 25.5, 42.5, 59.5, 76.5, 93.5, 110.5,
  134975. };
  134976. static long _vq_quantmap__44u4__p7_1[] = {
  134977. 13, 11, 9, 7, 5, 3, 1, 0,
  134978. 2, 4, 6, 8, 10, 12, 14,
  134979. };
  134980. static encode_aux_threshmatch _vq_auxt__44u4__p7_1 = {
  134981. _vq_quantthresh__44u4__p7_1,
  134982. _vq_quantmap__44u4__p7_1,
  134983. 15,
  134984. 15
  134985. };
  134986. static static_codebook _44u4__p7_1 = {
  134987. 2, 225,
  134988. _vq_lengthlist__44u4__p7_1,
  134989. 1, -522338304, 1620115456, 4, 0,
  134990. _vq_quantlist__44u4__p7_1,
  134991. NULL,
  134992. &_vq_auxt__44u4__p7_1,
  134993. NULL,
  134994. 0
  134995. };
  134996. static long _vq_quantlist__44u4__p7_2[] = {
  134997. 8,
  134998. 7,
  134999. 9,
  135000. 6,
  135001. 10,
  135002. 5,
  135003. 11,
  135004. 4,
  135005. 12,
  135006. 3,
  135007. 13,
  135008. 2,
  135009. 14,
  135010. 1,
  135011. 15,
  135012. 0,
  135013. 16,
  135014. };
  135015. static long _vq_lengthlist__44u4__p7_2[] = {
  135016. 2, 5, 5, 7, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  135017. 9, 5, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  135018. 9, 9, 5, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  135019. 9, 9, 9, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  135020. 10,10,10,10, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9,10,
  135021. 9,10, 9,10,10, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  135022. 10,10,10,10,10,10, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  135023. 9,10,10,10,10,10,10, 8, 9, 8, 9, 9, 9, 9, 9, 9,
  135024. 10,10,10,10,10,10,10,10, 8, 8, 8, 9, 9, 9, 9, 9,
  135025. 10,10,10,10,10,10,10,10,10, 9, 9, 9, 9, 9,10,10,
  135026. 10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9, 9,10,
  135027. 10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9,10,
  135028. 10,10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9,
  135029. 10,10,10,10,10,10,10,10,10,11,10,10,10, 9, 9, 9,
  135030. 10,10,10,10,10,10,10,10,10,10,10,10,10,10, 9, 9,
  135031. 9,10,10,10,10,10,10,10,10,10,10,10,10,10,10, 9,
  135032. 10, 9,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  135033. 9,10, 9,10,10,10,10,10,10,10,10,10,10,11,10,10,
  135034. 10,
  135035. };
  135036. static float _vq_quantthresh__44u4__p7_2[] = {
  135037. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  135038. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  135039. };
  135040. static long _vq_quantmap__44u4__p7_2[] = {
  135041. 15, 13, 11, 9, 7, 5, 3, 1,
  135042. 0, 2, 4, 6, 8, 10, 12, 14,
  135043. 16,
  135044. };
  135045. static encode_aux_threshmatch _vq_auxt__44u4__p7_2 = {
  135046. _vq_quantthresh__44u4__p7_2,
  135047. _vq_quantmap__44u4__p7_2,
  135048. 17,
  135049. 17
  135050. };
  135051. static static_codebook _44u4__p7_2 = {
  135052. 2, 289,
  135053. _vq_lengthlist__44u4__p7_2,
  135054. 1, -529530880, 1611661312, 5, 0,
  135055. _vq_quantlist__44u4__p7_2,
  135056. NULL,
  135057. &_vq_auxt__44u4__p7_2,
  135058. NULL,
  135059. 0
  135060. };
  135061. static long _huff_lengthlist__44u4__short[] = {
  135062. 14,17,15,17,16,14,13,16,10, 7, 7,10,13,10,15,16,
  135063. 9, 4, 4, 6, 5, 7, 9,16,12, 8, 7, 8, 8, 8,11,16,
  135064. 14, 7, 4, 6, 3, 5, 8,15,13, 8, 5, 7, 4, 5, 7,16,
  135065. 12, 9, 6, 8, 3, 3, 5,16,14,13, 7,10, 5, 5, 7,15,
  135066. };
  135067. static static_codebook _huff_book__44u4__short = {
  135068. 2, 64,
  135069. _huff_lengthlist__44u4__short,
  135070. 0, 0, 0, 0, 0,
  135071. NULL,
  135072. NULL,
  135073. NULL,
  135074. NULL,
  135075. 0
  135076. };
  135077. static long _huff_lengthlist__44u5__long[] = {
  135078. 3, 8,13,12,14,12,16,11,13,14, 5, 4, 5, 6, 7, 8,
  135079. 10, 9,12,15,10, 5, 5, 5, 6, 8, 9, 9,13,15,10, 5,
  135080. 5, 6, 6, 7, 8, 8,11,13,12, 7, 5, 6, 4, 6, 7, 7,
  135081. 11,14,11, 7, 7, 6, 6, 6, 7, 6,10,14,14, 9, 8, 8,
  135082. 6, 7, 7, 7,11,16,11, 8, 8, 7, 6, 6, 7, 4, 7,12,
  135083. 10,10,12,10,10, 9,10, 5, 6, 9,10,12,15,13,14,14,
  135084. 14, 8, 7, 8,
  135085. };
  135086. static static_codebook _huff_book__44u5__long = {
  135087. 2, 100,
  135088. _huff_lengthlist__44u5__long,
  135089. 0, 0, 0, 0, 0,
  135090. NULL,
  135091. NULL,
  135092. NULL,
  135093. NULL,
  135094. 0
  135095. };
  135096. static long _vq_quantlist__44u5__p1_0[] = {
  135097. 1,
  135098. 0,
  135099. 2,
  135100. };
  135101. static long _vq_lengthlist__44u5__p1_0[] = {
  135102. 1, 4, 4, 5, 8, 7, 5, 7, 7, 5, 8, 8, 8,10,10, 7,
  135103. 9,10, 5, 8, 8, 7,10, 9, 8,10,10, 5, 8, 8, 8,10,
  135104. 10, 8,10,10, 8,10,10,10,12,13,10,13,13, 7,10,10,
  135105. 10,13,11,10,13,13, 4, 8, 8, 8,11,10, 8,10,10, 7,
  135106. 10,10,10,13,13,10,11,13, 8,10,11,10,13,13,10,13,
  135107. 12,
  135108. };
  135109. static float _vq_quantthresh__44u5__p1_0[] = {
  135110. -0.5, 0.5,
  135111. };
  135112. static long _vq_quantmap__44u5__p1_0[] = {
  135113. 1, 0, 2,
  135114. };
  135115. static encode_aux_threshmatch _vq_auxt__44u5__p1_0 = {
  135116. _vq_quantthresh__44u5__p1_0,
  135117. _vq_quantmap__44u5__p1_0,
  135118. 3,
  135119. 3
  135120. };
  135121. static static_codebook _44u5__p1_0 = {
  135122. 4, 81,
  135123. _vq_lengthlist__44u5__p1_0,
  135124. 1, -535822336, 1611661312, 2, 0,
  135125. _vq_quantlist__44u5__p1_0,
  135126. NULL,
  135127. &_vq_auxt__44u5__p1_0,
  135128. NULL,
  135129. 0
  135130. };
  135131. static long _vq_quantlist__44u5__p2_0[] = {
  135132. 1,
  135133. 0,
  135134. 2,
  135135. };
  135136. static long _vq_lengthlist__44u5__p2_0[] = {
  135137. 3, 4, 4, 5, 6, 6, 5, 6, 6, 5, 6, 6, 6, 8, 8, 6,
  135138. 7, 8, 5, 6, 6, 6, 8, 7, 6, 8, 8, 5, 6, 6, 6, 8,
  135139. 8, 6, 8, 8, 6, 8, 8, 8, 9, 9, 8, 9, 9, 6, 8, 7,
  135140. 7, 9, 8, 8, 9, 9, 5, 6, 6, 6, 8, 7, 6, 8, 8, 6,
  135141. 8, 7, 8, 9, 9, 7, 8, 9, 6, 8, 8, 8, 9, 9, 8, 9,
  135142. 9,
  135143. };
  135144. static float _vq_quantthresh__44u5__p2_0[] = {
  135145. -0.5, 0.5,
  135146. };
  135147. static long _vq_quantmap__44u5__p2_0[] = {
  135148. 1, 0, 2,
  135149. };
  135150. static encode_aux_threshmatch _vq_auxt__44u5__p2_0 = {
  135151. _vq_quantthresh__44u5__p2_0,
  135152. _vq_quantmap__44u5__p2_0,
  135153. 3,
  135154. 3
  135155. };
  135156. static static_codebook _44u5__p2_0 = {
  135157. 4, 81,
  135158. _vq_lengthlist__44u5__p2_0,
  135159. 1, -535822336, 1611661312, 2, 0,
  135160. _vq_quantlist__44u5__p2_0,
  135161. NULL,
  135162. &_vq_auxt__44u5__p2_0,
  135163. NULL,
  135164. 0
  135165. };
  135166. static long _vq_quantlist__44u5__p3_0[] = {
  135167. 2,
  135168. 1,
  135169. 3,
  135170. 0,
  135171. 4,
  135172. };
  135173. static long _vq_lengthlist__44u5__p3_0[] = {
  135174. 2, 4, 5, 8, 8, 5, 7, 6, 9, 9, 5, 6, 7, 9, 9, 8,
  135175. 10, 9,13,12, 8, 9,10,12,12, 5, 7, 7,10,10, 7, 9,
  135176. 9,11,11, 6, 8, 9,11,11,10,11,11,14,14, 9,10,11,
  135177. 13,14, 5, 7, 7, 9,10, 7, 9, 8,11,11, 7, 9, 9,11,
  135178. 11, 9,11,10,14,13,10,11,11,14,14, 8,10,10,13,13,
  135179. 10,11,11,15,14, 9,11,11,14,14,13,14,14,17,16,12,
  135180. 13,13,15,16, 8,10,10,13,13, 9,11,11,14,15,10,11,
  135181. 11,14,15,12,14,13,16,16,13,15,14,15,17, 5, 7, 7,
  135182. 10,10, 7, 9, 9,11,11, 7, 9, 9,11,11,10,11,11,14,
  135183. 14,10,11,12,14,14, 7, 9, 9,12,11, 9,11,11,13,13,
  135184. 9,11,11,13,13,12,13,13,15,16,11,12,13,15,16, 6,
  135185. 9, 9,11,11, 8,11,10,13,12, 9,11,11,13,14,11,13,
  135186. 12,16,14,11,13,13,16,17,10,12,11,15,15,11,13,13,
  135187. 16,16,11,13,13,17,16,14,15,15,17,17,14,16,16,17,
  135188. 18, 9,11,11,14,15,10,12,12,15,15,11,13,13,16,17,
  135189. 13,15,13,17,15,14,15,16,18, 0, 5, 7, 7,10,10, 7,
  135190. 9, 9,11,11, 7, 9, 9,11,11,10,11,11,14,14,10,11,
  135191. 12,14,15, 6, 9, 9,12,11, 9,11,11,13,13, 8,10,11,
  135192. 12,13,11,13,13,16,15,11,12,13,14,15, 7, 9, 9,11,
  135193. 12, 9,11,11,13,13, 9,11,11,13,13,11,13,13,15,16,
  135194. 11,13,13,15,14, 9,11,11,15,14,11,13,13,17,15,10,
  135195. 12,12,15,15,14,16,16,17,17,13,13,15,15,17,10,11,
  135196. 12,15,15,11,13,13,16,16,11,13,13,15,15,14,15,15,
  135197. 18,18,14,15,15,17,17, 8,10,10,13,13,10,12,11,15,
  135198. 15,10,11,12,15,15,14,15,15,18,18,13,14,14,18,18,
  135199. 9,11,11,15,16,11,13,13,17,17,11,13,13,16,16,15,
  135200. 15,16,17, 0,14,15,17, 0, 0, 9,11,11,15,15,10,13,
  135201. 12,18,16,11,13,13,15,16,14,16,15,20,20,14,15,16,
  135202. 17, 0,13,14,14,20,16,14,15,16,19,18,14,15,15,19,
  135203. 0,18,16, 0,20,20,16,18,18, 0, 0,12,14,14,18,18,
  135204. 13,15,14,18,16,14,15,16,18,20,16,19,16, 0,17,17,
  135205. 18,18,19, 0, 8,10,10,14,14,10,11,11,14,15,10,11,
  135206. 12,15,15,13,15,14,19,17,13,15,15,17, 0, 9,11,11,
  135207. 16,15,11,13,13,16,16,10,12,13,15,17,14,16,16,18,
  135208. 18,14,15,15,18, 0, 9,11,11,15,15,11,13,13,16,17,
  135209. 11,13,13,18,17,14,18,16,18,18,15,17,17,18, 0,12,
  135210. 14,14,18,18,14,15,15,20, 0,13,14,15,17, 0,16,18,
  135211. 17, 0, 0,16,16, 0,17,20,12,14,14,18,18,14,16,15,
  135212. 0,18,14,16,15,18, 0,16,19,17, 0, 0,17,18,16, 0,
  135213. 0,
  135214. };
  135215. static float _vq_quantthresh__44u5__p3_0[] = {
  135216. -1.5, -0.5, 0.5, 1.5,
  135217. };
  135218. static long _vq_quantmap__44u5__p3_0[] = {
  135219. 3, 1, 0, 2, 4,
  135220. };
  135221. static encode_aux_threshmatch _vq_auxt__44u5__p3_0 = {
  135222. _vq_quantthresh__44u5__p3_0,
  135223. _vq_quantmap__44u5__p3_0,
  135224. 5,
  135225. 5
  135226. };
  135227. static static_codebook _44u5__p3_0 = {
  135228. 4, 625,
  135229. _vq_lengthlist__44u5__p3_0,
  135230. 1, -533725184, 1611661312, 3, 0,
  135231. _vq_quantlist__44u5__p3_0,
  135232. NULL,
  135233. &_vq_auxt__44u5__p3_0,
  135234. NULL,
  135235. 0
  135236. };
  135237. static long _vq_quantlist__44u5__p4_0[] = {
  135238. 2,
  135239. 1,
  135240. 3,
  135241. 0,
  135242. 4,
  135243. };
  135244. static long _vq_lengthlist__44u5__p4_0[] = {
  135245. 4, 5, 5, 8, 8, 6, 7, 6, 9, 9, 6, 6, 7, 9, 9, 8,
  135246. 9, 9,11,11, 8, 9, 9,11,11, 6, 7, 7, 9, 9, 7, 8,
  135247. 8,10,10, 6, 7, 8, 9,10, 9,10,10,11,12, 9, 9,10,
  135248. 11,12, 6, 7, 7, 9, 9, 6, 8, 7,10, 9, 7, 8, 8,10,
  135249. 10, 9,10, 9,12,11, 9,10,10,12,11, 8, 9, 9,12,11,
  135250. 9,10,10,12,12, 9,10,10,12,12,11,12,12,13,14,11,
  135251. 11,12,13,14, 8, 9, 9,11,12, 9,10,10,12,12, 9,10,
  135252. 10,12,12,11,12,11,14,13,11,12,12,13,13, 5, 7, 7,
  135253. 9, 9, 7, 8, 8,10,10, 7, 8, 8,10,10, 9,10,10,12,
  135254. 12, 9,10,10,12,12, 7, 8, 8,10,10, 8, 8, 9,10,11,
  135255. 8, 9, 9,11,11,10,10,11,11,13,10,11,11,12,13, 6,
  135256. 7, 8,10,10, 7, 9, 8,11,10, 8, 9, 9,11,11,10,11,
  135257. 10,13,11,10,11,11,12,12, 9,10,10,12,12,10,10,11,
  135258. 12,13,10,11,11,13,13,12,11,13,12,15,12,13,13,14,
  135259. 15, 9,10,10,12,12, 9,11,10,13,12,10,11,11,13,13,
  135260. 11,13,11,14,12,12,13,13,14,15, 5, 7, 7, 9, 9, 7,
  135261. 8, 8,10,10, 7, 8, 8,10,10, 9,10,10,12,12, 9,10,
  135262. 10,12,12, 6, 8, 7,10,10, 8, 9, 9,11,11, 7, 8, 9,
  135263. 10,11,10,11,11,12,12,10,10,11,11,13, 7, 8, 8,10,
  135264. 10, 8, 9, 9,11,11, 8, 9, 8,11,10,10,11,11,13,12,
  135265. 10,11,10,13,11, 9,10,10,12,12,10,11,11,13,12, 9,
  135266. 10,10,12,13,12,13,13,14,15,11,11,13,12,14, 9,10,
  135267. 10,12,12,10,11,11,13,13,10,11,10,13,12,12,13,13,
  135268. 14,14,12,13,11,14,12, 8, 9, 9,12,12, 9,10,10,12,
  135269. 12, 9,10,10,12,12,12,12,12,14,14,11,12,12,14,13,
  135270. 9,10,10,12,12,10,11,11,13,13,10,11,11,13,12,12,
  135271. 12,13,14,15,12,13,13,15,14, 9,10,10,12,12,10,11,
  135272. 10,13,12,10,11,11,12,13,12,13,12,15,13,12,13,13,
  135273. 14,15,11,12,12,14,13,11,12,12,14,15,12,13,13,15,
  135274. 14,13,12,14,12,16,13,14,14,15,15,11,11,12,14,14,
  135275. 11,12,11,14,13,12,13,13,14,15,13,14,12,16,12,14,
  135276. 14,15,16,16, 8, 9, 9,11,12, 9,10,10,12,12, 9,10,
  135277. 10,12,13,11,12,12,13,13,12,12,13,14,14, 9,10,10,
  135278. 12,12,10,11,10,13,12,10,10,11,12,13,12,13,13,15,
  135279. 14,12,12,13,13,15, 9,10,10,12,13,10,11,11,12,13,
  135280. 10,11,11,13,13,12,13,13,14,15,12,13,12,15,14,11,
  135281. 12,11,14,13,12,13,13,15,14,11,11,12,13,14,14,15,
  135282. 14,16,15,13,12,14,13,16,11,12,12,13,14,12,13,13,
  135283. 14,15,11,12,11,14,14,14,14,14,15,16,13,15,12,16,
  135284. 12,
  135285. };
  135286. static float _vq_quantthresh__44u5__p4_0[] = {
  135287. -1.5, -0.5, 0.5, 1.5,
  135288. };
  135289. static long _vq_quantmap__44u5__p4_0[] = {
  135290. 3, 1, 0, 2, 4,
  135291. };
  135292. static encode_aux_threshmatch _vq_auxt__44u5__p4_0 = {
  135293. _vq_quantthresh__44u5__p4_0,
  135294. _vq_quantmap__44u5__p4_0,
  135295. 5,
  135296. 5
  135297. };
  135298. static static_codebook _44u5__p4_0 = {
  135299. 4, 625,
  135300. _vq_lengthlist__44u5__p4_0,
  135301. 1, -533725184, 1611661312, 3, 0,
  135302. _vq_quantlist__44u5__p4_0,
  135303. NULL,
  135304. &_vq_auxt__44u5__p4_0,
  135305. NULL,
  135306. 0
  135307. };
  135308. static long _vq_quantlist__44u5__p5_0[] = {
  135309. 4,
  135310. 3,
  135311. 5,
  135312. 2,
  135313. 6,
  135314. 1,
  135315. 7,
  135316. 0,
  135317. 8,
  135318. };
  135319. static long _vq_lengthlist__44u5__p5_0[] = {
  135320. 2, 3, 3, 6, 6, 8, 8,10,10, 4, 5, 5, 8, 7, 8, 8,
  135321. 11,10, 3, 5, 5, 7, 8, 8, 8,10,11, 6, 8, 7,10, 9,
  135322. 10,10,11,11, 6, 7, 8, 9, 9, 9,10,11,12, 8, 8, 8,
  135323. 10,10,11,11,13,12, 8, 8, 9, 9,10,11,11,12,13,10,
  135324. 11,10,12,11,13,12,14,14,10,10,11,11,12,12,13,14,
  135325. 14,
  135326. };
  135327. static float _vq_quantthresh__44u5__p5_0[] = {
  135328. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  135329. };
  135330. static long _vq_quantmap__44u5__p5_0[] = {
  135331. 7, 5, 3, 1, 0, 2, 4, 6,
  135332. 8,
  135333. };
  135334. static encode_aux_threshmatch _vq_auxt__44u5__p5_0 = {
  135335. _vq_quantthresh__44u5__p5_0,
  135336. _vq_quantmap__44u5__p5_0,
  135337. 9,
  135338. 9
  135339. };
  135340. static static_codebook _44u5__p5_0 = {
  135341. 2, 81,
  135342. _vq_lengthlist__44u5__p5_0,
  135343. 1, -531628032, 1611661312, 4, 0,
  135344. _vq_quantlist__44u5__p5_0,
  135345. NULL,
  135346. &_vq_auxt__44u5__p5_0,
  135347. NULL,
  135348. 0
  135349. };
  135350. static long _vq_quantlist__44u5__p6_0[] = {
  135351. 4,
  135352. 3,
  135353. 5,
  135354. 2,
  135355. 6,
  135356. 1,
  135357. 7,
  135358. 0,
  135359. 8,
  135360. };
  135361. static long _vq_lengthlist__44u5__p6_0[] = {
  135362. 3, 4, 4, 5, 5, 7, 7, 9, 9, 4, 5, 4, 6, 6, 7, 7,
  135363. 9, 9, 4, 4, 5, 6, 6, 7, 7, 9, 9, 5, 6, 6, 7, 7,
  135364. 8, 8,10,10, 6, 6, 6, 7, 7, 8, 8,10,10, 7, 7, 7,
  135365. 8, 8, 9, 9,11,10, 7, 7, 7, 8, 8, 9, 9,10,11, 9,
  135366. 9, 9,10,10,11,10,11,11, 9, 9, 9,10,10,11,10,11,
  135367. 11,
  135368. };
  135369. static float _vq_quantthresh__44u5__p6_0[] = {
  135370. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  135371. };
  135372. static long _vq_quantmap__44u5__p6_0[] = {
  135373. 7, 5, 3, 1, 0, 2, 4, 6,
  135374. 8,
  135375. };
  135376. static encode_aux_threshmatch _vq_auxt__44u5__p6_0 = {
  135377. _vq_quantthresh__44u5__p6_0,
  135378. _vq_quantmap__44u5__p6_0,
  135379. 9,
  135380. 9
  135381. };
  135382. static static_codebook _44u5__p6_0 = {
  135383. 2, 81,
  135384. _vq_lengthlist__44u5__p6_0,
  135385. 1, -531628032, 1611661312, 4, 0,
  135386. _vq_quantlist__44u5__p6_0,
  135387. NULL,
  135388. &_vq_auxt__44u5__p6_0,
  135389. NULL,
  135390. 0
  135391. };
  135392. static long _vq_quantlist__44u5__p7_0[] = {
  135393. 1,
  135394. 0,
  135395. 2,
  135396. };
  135397. static long _vq_lengthlist__44u5__p7_0[] = {
  135398. 1, 4, 4, 5, 7, 7, 5, 7, 7, 5, 9, 9, 8,11,10, 7,
  135399. 11,10, 5, 9, 9, 7,10,10, 8,10,11, 4, 9, 9, 9,12,
  135400. 12, 9,12,12, 8,12,12,11,12,12,10,12,13, 7,12,12,
  135401. 11,12,12,10,12,13, 4, 9, 9, 9,12,12, 9,12,12, 7,
  135402. 12,11,10,13,13,11,12,12, 7,12,12,10,13,13,11,12,
  135403. 12,
  135404. };
  135405. static float _vq_quantthresh__44u5__p7_0[] = {
  135406. -5.5, 5.5,
  135407. };
  135408. static long _vq_quantmap__44u5__p7_0[] = {
  135409. 1, 0, 2,
  135410. };
  135411. static encode_aux_threshmatch _vq_auxt__44u5__p7_0 = {
  135412. _vq_quantthresh__44u5__p7_0,
  135413. _vq_quantmap__44u5__p7_0,
  135414. 3,
  135415. 3
  135416. };
  135417. static static_codebook _44u5__p7_0 = {
  135418. 4, 81,
  135419. _vq_lengthlist__44u5__p7_0,
  135420. 1, -529137664, 1618345984, 2, 0,
  135421. _vq_quantlist__44u5__p7_0,
  135422. NULL,
  135423. &_vq_auxt__44u5__p7_0,
  135424. NULL,
  135425. 0
  135426. };
  135427. static long _vq_quantlist__44u5__p7_1[] = {
  135428. 5,
  135429. 4,
  135430. 6,
  135431. 3,
  135432. 7,
  135433. 2,
  135434. 8,
  135435. 1,
  135436. 9,
  135437. 0,
  135438. 10,
  135439. };
  135440. static long _vq_lengthlist__44u5__p7_1[] = {
  135441. 2, 4, 4, 6, 6, 7, 7, 8, 8, 8, 8, 4, 5, 5, 7, 7,
  135442. 8, 8, 9, 8, 8, 9, 4, 5, 5, 7, 7, 8, 8, 9, 9, 8,
  135443. 9, 6, 7, 7, 8, 8, 9, 8, 9, 9, 9, 9, 6, 7, 7, 8,
  135444. 8, 9, 9, 9, 9, 9, 9, 7, 8, 8, 9, 9, 9, 9, 9, 9,
  135445. 9, 9, 7, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 8, 9, 9,
  135446. 9, 9, 9, 9,10,10,10,10, 8, 9, 9, 9, 9, 9, 9,10,
  135447. 10,10,10, 8, 9, 9, 9, 9, 9, 9,10,10,10,10, 8, 9,
  135448. 9, 9, 9, 9, 9,10,10,10,10,
  135449. };
  135450. static float _vq_quantthresh__44u5__p7_1[] = {
  135451. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  135452. 3.5, 4.5,
  135453. };
  135454. static long _vq_quantmap__44u5__p7_1[] = {
  135455. 9, 7, 5, 3, 1, 0, 2, 4,
  135456. 6, 8, 10,
  135457. };
  135458. static encode_aux_threshmatch _vq_auxt__44u5__p7_1 = {
  135459. _vq_quantthresh__44u5__p7_1,
  135460. _vq_quantmap__44u5__p7_1,
  135461. 11,
  135462. 11
  135463. };
  135464. static static_codebook _44u5__p7_1 = {
  135465. 2, 121,
  135466. _vq_lengthlist__44u5__p7_1,
  135467. 1, -531365888, 1611661312, 4, 0,
  135468. _vq_quantlist__44u5__p7_1,
  135469. NULL,
  135470. &_vq_auxt__44u5__p7_1,
  135471. NULL,
  135472. 0
  135473. };
  135474. static long _vq_quantlist__44u5__p8_0[] = {
  135475. 5,
  135476. 4,
  135477. 6,
  135478. 3,
  135479. 7,
  135480. 2,
  135481. 8,
  135482. 1,
  135483. 9,
  135484. 0,
  135485. 10,
  135486. };
  135487. static long _vq_lengthlist__44u5__p8_0[] = {
  135488. 1, 4, 4, 6, 6, 8, 8, 9, 9,10,10, 4, 6, 6, 7, 7,
  135489. 9, 9,10,10,11,11, 4, 6, 6, 7, 7, 9, 9,10,10,11,
  135490. 11, 6, 8, 7, 9, 9,10,10,11,11,13,12, 6, 8, 8, 9,
  135491. 9,10,10,11,11,12,13, 8, 9, 9,10,10,12,12,13,12,
  135492. 14,13, 8, 9, 9,10,10,12,12,13,13,14,14, 9,11,11,
  135493. 12,12,13,13,14,14,15,14, 9,11,11,12,12,13,13,14,
  135494. 14,15,14,11,12,12,13,13,14,14,15,14,15,14,11,11,
  135495. 12,13,13,14,14,14,14,15,15,
  135496. };
  135497. static float _vq_quantthresh__44u5__p8_0[] = {
  135498. -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5, 27.5,
  135499. 38.5, 49.5,
  135500. };
  135501. static long _vq_quantmap__44u5__p8_0[] = {
  135502. 9, 7, 5, 3, 1, 0, 2, 4,
  135503. 6, 8, 10,
  135504. };
  135505. static encode_aux_threshmatch _vq_auxt__44u5__p8_0 = {
  135506. _vq_quantthresh__44u5__p8_0,
  135507. _vq_quantmap__44u5__p8_0,
  135508. 11,
  135509. 11
  135510. };
  135511. static static_codebook _44u5__p8_0 = {
  135512. 2, 121,
  135513. _vq_lengthlist__44u5__p8_0,
  135514. 1, -524582912, 1618345984, 4, 0,
  135515. _vq_quantlist__44u5__p8_0,
  135516. NULL,
  135517. &_vq_auxt__44u5__p8_0,
  135518. NULL,
  135519. 0
  135520. };
  135521. static long _vq_quantlist__44u5__p8_1[] = {
  135522. 5,
  135523. 4,
  135524. 6,
  135525. 3,
  135526. 7,
  135527. 2,
  135528. 8,
  135529. 1,
  135530. 9,
  135531. 0,
  135532. 10,
  135533. };
  135534. static long _vq_lengthlist__44u5__p8_1[] = {
  135535. 3, 5, 5, 6, 6, 7, 7, 7, 7, 7, 7, 5, 6, 5, 7, 6,
  135536. 7, 7, 8, 8, 8, 8, 5, 5, 5, 6, 6, 7, 7, 8, 8, 8,
  135537. 8, 6, 7, 6, 7, 7, 8, 8, 8, 8, 8, 8, 6, 6, 7, 7,
  135538. 7, 8, 8, 8, 8, 8, 8, 7, 7, 7, 8, 8, 8, 8, 8, 8,
  135539. 8, 8, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 7, 8, 8,
  135540. 8, 8, 8, 8, 8, 8, 8, 8, 7, 8, 8, 8, 8, 8, 8, 8,
  135541. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  135542. 8, 8, 8, 8, 8, 8, 8, 8, 8,
  135543. };
  135544. static float _vq_quantthresh__44u5__p8_1[] = {
  135545. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  135546. 3.5, 4.5,
  135547. };
  135548. static long _vq_quantmap__44u5__p8_1[] = {
  135549. 9, 7, 5, 3, 1, 0, 2, 4,
  135550. 6, 8, 10,
  135551. };
  135552. static encode_aux_threshmatch _vq_auxt__44u5__p8_1 = {
  135553. _vq_quantthresh__44u5__p8_1,
  135554. _vq_quantmap__44u5__p8_1,
  135555. 11,
  135556. 11
  135557. };
  135558. static static_codebook _44u5__p8_1 = {
  135559. 2, 121,
  135560. _vq_lengthlist__44u5__p8_1,
  135561. 1, -531365888, 1611661312, 4, 0,
  135562. _vq_quantlist__44u5__p8_1,
  135563. NULL,
  135564. &_vq_auxt__44u5__p8_1,
  135565. NULL,
  135566. 0
  135567. };
  135568. static long _vq_quantlist__44u5__p9_0[] = {
  135569. 6,
  135570. 5,
  135571. 7,
  135572. 4,
  135573. 8,
  135574. 3,
  135575. 9,
  135576. 2,
  135577. 10,
  135578. 1,
  135579. 11,
  135580. 0,
  135581. 12,
  135582. };
  135583. static long _vq_lengthlist__44u5__p9_0[] = {
  135584. 1, 3, 2,12,10,13,13,13,13,13,13,13,13, 4, 9, 9,
  135585. 13,13,13,13,13,13,13,13,13,13, 5,10, 9,13,13,13,
  135586. 13,13,13,13,13,13,13,12,13,13,13,13,13,13,13,13,
  135587. 13,13,13,13,11,13,13,13,13,13,13,13,13,13,13,13,
  135588. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  135589. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  135590. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  135591. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  135592. 13,13,13,13,13,13,13,13,13,13,13,13,13,12,12,12,
  135593. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  135594. 12,12,12,12,12,12,12,12,12,
  135595. };
  135596. static float _vq_quantthresh__44u5__p9_0[] = {
  135597. -1402.5, -1147.5, -892.5, -637.5, -382.5, -127.5, 127.5, 382.5,
  135598. 637.5, 892.5, 1147.5, 1402.5,
  135599. };
  135600. static long _vq_quantmap__44u5__p9_0[] = {
  135601. 11, 9, 7, 5, 3, 1, 0, 2,
  135602. 4, 6, 8, 10, 12,
  135603. };
  135604. static encode_aux_threshmatch _vq_auxt__44u5__p9_0 = {
  135605. _vq_quantthresh__44u5__p9_0,
  135606. _vq_quantmap__44u5__p9_0,
  135607. 13,
  135608. 13
  135609. };
  135610. static static_codebook _44u5__p9_0 = {
  135611. 2, 169,
  135612. _vq_lengthlist__44u5__p9_0,
  135613. 1, -514332672, 1627381760, 4, 0,
  135614. _vq_quantlist__44u5__p9_0,
  135615. NULL,
  135616. &_vq_auxt__44u5__p9_0,
  135617. NULL,
  135618. 0
  135619. };
  135620. static long _vq_quantlist__44u5__p9_1[] = {
  135621. 7,
  135622. 6,
  135623. 8,
  135624. 5,
  135625. 9,
  135626. 4,
  135627. 10,
  135628. 3,
  135629. 11,
  135630. 2,
  135631. 12,
  135632. 1,
  135633. 13,
  135634. 0,
  135635. 14,
  135636. };
  135637. static long _vq_lengthlist__44u5__p9_1[] = {
  135638. 1, 4, 4, 7, 7, 8, 8, 8, 7, 8, 7, 9, 8, 9, 9, 4,
  135639. 7, 6, 9, 8,10,10, 9, 8, 9, 9, 9, 9, 9, 8, 5, 6,
  135640. 6, 8, 9,10,10, 9, 9, 9,10,10,10,10,11, 7, 8, 8,
  135641. 10,10,11,11,10,10,11,11,11,12,11,11, 7, 8, 8,10,
  135642. 10,11,11,10,10,11,11,12,11,11,11, 8, 9, 9,11,11,
  135643. 12,12,11,11,12,11,12,12,12,12, 8, 9,10,11,11,12,
  135644. 12,11,11,12,12,12,12,12,12, 8, 9, 9,10,10,12,11,
  135645. 12,12,12,12,12,12,12,13, 8, 9, 9,11,11,11,11,12,
  135646. 12,12,12,13,12,13,13, 9,10,10,11,11,12,12,12,13,
  135647. 12,13,13,13,14,13, 9,10,10,11,11,12,12,12,13,13,
  135648. 12,13,13,14,13, 9,11,10,12,11,13,12,12,13,13,13,
  135649. 13,13,13,14, 9,10,10,12,12,12,12,12,13,13,13,13,
  135650. 13,14,14,10,11,11,12,12,12,13,13,13,14,14,13,14,
  135651. 14,14,10,11,11,12,12,12,12,13,12,13,14,13,14,14,
  135652. 14,
  135653. };
  135654. static float _vq_quantthresh__44u5__p9_1[] = {
  135655. -110.5, -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5,
  135656. 25.5, 42.5, 59.5, 76.5, 93.5, 110.5,
  135657. };
  135658. static long _vq_quantmap__44u5__p9_1[] = {
  135659. 13, 11, 9, 7, 5, 3, 1, 0,
  135660. 2, 4, 6, 8, 10, 12, 14,
  135661. };
  135662. static encode_aux_threshmatch _vq_auxt__44u5__p9_1 = {
  135663. _vq_quantthresh__44u5__p9_1,
  135664. _vq_quantmap__44u5__p9_1,
  135665. 15,
  135666. 15
  135667. };
  135668. static static_codebook _44u5__p9_1 = {
  135669. 2, 225,
  135670. _vq_lengthlist__44u5__p9_1,
  135671. 1, -522338304, 1620115456, 4, 0,
  135672. _vq_quantlist__44u5__p9_1,
  135673. NULL,
  135674. &_vq_auxt__44u5__p9_1,
  135675. NULL,
  135676. 0
  135677. };
  135678. static long _vq_quantlist__44u5__p9_2[] = {
  135679. 8,
  135680. 7,
  135681. 9,
  135682. 6,
  135683. 10,
  135684. 5,
  135685. 11,
  135686. 4,
  135687. 12,
  135688. 3,
  135689. 13,
  135690. 2,
  135691. 14,
  135692. 1,
  135693. 15,
  135694. 0,
  135695. 16,
  135696. };
  135697. static long _vq_lengthlist__44u5__p9_2[] = {
  135698. 2, 5, 5, 7, 7, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  135699. 9, 5, 6, 6, 7, 7, 8, 8, 9, 8, 9, 9, 9, 9, 9, 9,
  135700. 9, 9, 5, 6, 6, 7, 7, 8, 8, 9, 8, 9, 9, 9, 9, 9,
  135701. 9, 9, 9, 7, 7, 7, 8, 8, 9, 8, 9, 9, 9, 9, 9, 9,
  135702. 9, 9, 9, 9, 7, 7, 7, 8, 8, 9, 8, 9, 9, 9, 9, 9,
  135703. 9, 9, 9, 9, 9, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9,
  135704. 9,10, 9,10,10,10, 8, 8, 8, 9, 8, 9, 9, 9, 9, 9,
  135705. 9, 9,10, 9,10, 9,10, 8, 9, 9, 9, 9, 9, 9, 9, 9,
  135706. 9,10, 9,10,10,10,10,10, 8, 9, 9, 9, 9, 9, 9,10,
  135707. 9,10, 9,10,10,10,10,10,10, 9, 9, 9, 9, 9,10, 9,
  135708. 10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9, 9, 9,
  135709. 9,10, 9,10, 9,10,10,10,10,10,10, 9, 9, 9, 9, 9,
  135710. 10,10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9,
  135711. 9, 9,10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9,
  135712. 9,10,10, 9,10,10,10,10,10,10,10,10,10,10, 9, 9,
  135713. 9, 9, 9,10,10,10,10,10,10,10,10,10,10,10,10, 9,
  135714. 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,10,10,10,
  135715. 9, 9, 9,10, 9,10,10,10,10,10,10,10,10,10,10,10,
  135716. 10,
  135717. };
  135718. static float _vq_quantthresh__44u5__p9_2[] = {
  135719. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  135720. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  135721. };
  135722. static long _vq_quantmap__44u5__p9_2[] = {
  135723. 15, 13, 11, 9, 7, 5, 3, 1,
  135724. 0, 2, 4, 6, 8, 10, 12, 14,
  135725. 16,
  135726. };
  135727. static encode_aux_threshmatch _vq_auxt__44u5__p9_2 = {
  135728. _vq_quantthresh__44u5__p9_2,
  135729. _vq_quantmap__44u5__p9_2,
  135730. 17,
  135731. 17
  135732. };
  135733. static static_codebook _44u5__p9_2 = {
  135734. 2, 289,
  135735. _vq_lengthlist__44u5__p9_2,
  135736. 1, -529530880, 1611661312, 5, 0,
  135737. _vq_quantlist__44u5__p9_2,
  135738. NULL,
  135739. &_vq_auxt__44u5__p9_2,
  135740. NULL,
  135741. 0
  135742. };
  135743. static long _huff_lengthlist__44u5__short[] = {
  135744. 4,10,17,13,17,13,17,17,17,17, 3, 6, 8, 9,11, 9,
  135745. 15,12,16,17, 6, 5, 5, 7, 7, 8,10,11,17,17, 7, 8,
  135746. 7, 9, 9,10,13,13,17,17, 8, 6, 5, 7, 4, 7, 5, 8,
  135747. 14,17, 9, 9, 8, 9, 7, 9, 8,10,16,17,12,10, 7, 8,
  135748. 4, 7, 4, 7,16,17,12,11, 9,10, 6, 9, 5, 7,14,17,
  135749. 14,13,10,15, 4, 8, 3, 5,14,17,17,14,11,15, 6,10,
  135750. 6, 8,15,17,
  135751. };
  135752. static static_codebook _huff_book__44u5__short = {
  135753. 2, 100,
  135754. _huff_lengthlist__44u5__short,
  135755. 0, 0, 0, 0, 0,
  135756. NULL,
  135757. NULL,
  135758. NULL,
  135759. NULL,
  135760. 0
  135761. };
  135762. static long _huff_lengthlist__44u6__long[] = {
  135763. 3, 9,14,13,14,13,16,12,13,14, 5, 4, 6, 6, 8, 9,
  135764. 11,10,12,15,10, 5, 5, 6, 6, 8,10,10,13,16,10, 6,
  135765. 6, 6, 6, 8, 9, 9,12,14,13, 7, 6, 6, 4, 6, 6, 7,
  135766. 11,14,10, 7, 7, 7, 6, 6, 6, 7,10,13,15,10, 9, 8,
  135767. 5, 6, 5, 6,10,14,10, 9, 8, 8, 6, 6, 5, 4, 6,11,
  135768. 11,11,12,11,10, 9, 9, 5, 5, 9,10,12,15,13,13,13,
  135769. 13, 8, 7, 7,
  135770. };
  135771. static static_codebook _huff_book__44u6__long = {
  135772. 2, 100,
  135773. _huff_lengthlist__44u6__long,
  135774. 0, 0, 0, 0, 0,
  135775. NULL,
  135776. NULL,
  135777. NULL,
  135778. NULL,
  135779. 0
  135780. };
  135781. static long _vq_quantlist__44u6__p1_0[] = {
  135782. 1,
  135783. 0,
  135784. 2,
  135785. };
  135786. static long _vq_lengthlist__44u6__p1_0[] = {
  135787. 1, 4, 4, 4, 8, 7, 5, 7, 7, 5, 8, 8, 8,10,10, 7,
  135788. 9,10, 5, 8, 8, 7,10, 9, 8,10,10, 5, 8, 8, 8,10,
  135789. 10, 8,10,10, 8,10,10,10,12,13,10,13,13, 7,10,10,
  135790. 10,13,11,10,13,13, 5, 8, 8, 8,11,10, 8,10,10, 7,
  135791. 10,10,10,13,13,10,11,13, 8,10,11,10,13,13,10,13,
  135792. 12,
  135793. };
  135794. static float _vq_quantthresh__44u6__p1_0[] = {
  135795. -0.5, 0.5,
  135796. };
  135797. static long _vq_quantmap__44u6__p1_0[] = {
  135798. 1, 0, 2,
  135799. };
  135800. static encode_aux_threshmatch _vq_auxt__44u6__p1_0 = {
  135801. _vq_quantthresh__44u6__p1_0,
  135802. _vq_quantmap__44u6__p1_0,
  135803. 3,
  135804. 3
  135805. };
  135806. static static_codebook _44u6__p1_0 = {
  135807. 4, 81,
  135808. _vq_lengthlist__44u6__p1_0,
  135809. 1, -535822336, 1611661312, 2, 0,
  135810. _vq_quantlist__44u6__p1_0,
  135811. NULL,
  135812. &_vq_auxt__44u6__p1_0,
  135813. NULL,
  135814. 0
  135815. };
  135816. static long _vq_quantlist__44u6__p2_0[] = {
  135817. 1,
  135818. 0,
  135819. 2,
  135820. };
  135821. static long _vq_lengthlist__44u6__p2_0[] = {
  135822. 3, 4, 4, 5, 6, 6, 5, 6, 6, 5, 6, 6, 6, 8, 8, 6,
  135823. 7, 8, 5, 6, 6, 6, 8, 7, 6, 8, 8, 5, 6, 6, 6, 8,
  135824. 8, 6, 8, 8, 6, 8, 8, 8, 9, 9, 8, 9, 9, 6, 7, 7,
  135825. 7, 9, 8, 8, 9, 9, 5, 6, 6, 6, 8, 7, 6, 8, 8, 6,
  135826. 8, 8, 8, 9, 9, 7, 8, 9, 6, 8, 8, 8, 9, 9, 8, 9,
  135827. 9,
  135828. };
  135829. static float _vq_quantthresh__44u6__p2_0[] = {
  135830. -0.5, 0.5,
  135831. };
  135832. static long _vq_quantmap__44u6__p2_0[] = {
  135833. 1, 0, 2,
  135834. };
  135835. static encode_aux_threshmatch _vq_auxt__44u6__p2_0 = {
  135836. _vq_quantthresh__44u6__p2_0,
  135837. _vq_quantmap__44u6__p2_0,
  135838. 3,
  135839. 3
  135840. };
  135841. static static_codebook _44u6__p2_0 = {
  135842. 4, 81,
  135843. _vq_lengthlist__44u6__p2_0,
  135844. 1, -535822336, 1611661312, 2, 0,
  135845. _vq_quantlist__44u6__p2_0,
  135846. NULL,
  135847. &_vq_auxt__44u6__p2_0,
  135848. NULL,
  135849. 0
  135850. };
  135851. static long _vq_quantlist__44u6__p3_0[] = {
  135852. 2,
  135853. 1,
  135854. 3,
  135855. 0,
  135856. 4,
  135857. };
  135858. static long _vq_lengthlist__44u6__p3_0[] = {
  135859. 2, 5, 4, 8, 8, 5, 7, 6, 9, 9, 5, 6, 7, 9, 9, 8,
  135860. 9, 9,13,12, 8, 9,10,12,13, 5, 7, 7,10, 9, 7, 9,
  135861. 9,11,11, 7, 8, 9,11,11,10,11,11,14,14, 9,10,11,
  135862. 13,14, 5, 7, 7, 9,10, 6, 9, 8,11,11, 7, 9, 9,11,
  135863. 11, 9,11,10,14,13,10,11,11,14,13, 8,10,10,13,13,
  135864. 10,11,11,15,15, 9,11,11,14,14,13,14,14,17,16,12,
  135865. 13,14,16,16, 8,10,10,13,14, 9,11,11,14,15,10,11,
  135866. 12,14,15,12,14,13,16,15,13,14,14,15,17, 5, 7, 7,
  135867. 10,10, 7, 9, 9,11,11, 7, 9, 9,11,11,10,12,11,14,
  135868. 14,10,11,11,14,14, 7, 9, 9,12,11, 9,11,11,13,13,
  135869. 9,11,11,13,13,11,13,13,14,15,11,12,13,15,16, 6,
  135870. 9, 9,11,12, 8,11,10,13,12, 9,11,11,13,14,11,13,
  135871. 12,16,14,11,13,13,15,16,10,12,11,14,15,11,13,13,
  135872. 15,17,11,13,13,17,16,15,15,16,17,16,14,15,16,18,
  135873. 0, 9,11,11,14,15,10,12,12,16,15,11,13,13,16,16,
  135874. 13,15,14,18,15,14,16,16, 0, 0, 5, 7, 7,10,10, 7,
  135875. 9, 9,11,11, 7, 9, 9,11,11,10,11,11,14,14,10,11,
  135876. 12,14,14, 6, 9, 9,11,11, 9,11,11,13,13, 8,10,11,
  135877. 12,13,11,13,13,16,15,11,12,13,14,16, 7, 9, 9,11,
  135878. 12, 9,11,11,13,13, 9,11,11,13,13,11,13,13,16,15,
  135879. 11,13,12,15,15, 9,11,11,15,14,11,13,13,17,16,10,
  135880. 12,13,15,16,14,16,16, 0,18,14,14,15,15,17,10,11,
  135881. 12,15,15,11,13,13,16,16,11,13,13,16,16,14,16,16,
  135882. 19,17,14,15,15,17,17, 8,10,10,14,14,10,12,11,15,
  135883. 15,10,11,12,16,15,14,15,15,18,20,13,14,16,17,18,
  135884. 9,11,11,15,16,11,13,13,17,17,11,13,13,17,16,15,
  135885. 16,16, 0, 0,15,16,16, 0, 0, 9,11,11,15,15,10,13,
  135886. 12,17,15,11,13,13,17,16,15,17,15,20,19,15,16,16,
  135887. 19, 0,13,15,14, 0,17,14,15,16, 0,20,15,16,16, 0,
  135888. 19,17,18, 0, 0, 0,16,17,18, 0, 0,12,14,14,19,18,
  135889. 13,15,14, 0,17,14,15,16,19,19,16,18,16, 0,19,19,
  135890. 20,17,20, 0, 8,10,10,13,14,10,11,11,15,15,10,12,
  135891. 12,15,16,14,15,14,19,16,14,15,15, 0,18, 9,11,11,
  135892. 16,15,11,13,13, 0,16,11,12,13,16,17,14,16,17, 0,
  135893. 19,15,16,16,18, 0, 9,11,11,15,16,11,13,13,16,16,
  135894. 11,14,13,18,17,15,16,16,18,20,15,17,19, 0, 0,12,
  135895. 14,14,17,17,14,16,15, 0, 0,13,14,15,19, 0,16,18,
  135896. 20, 0, 0,16,16,18,18, 0,12,14,14,17,20,14,16,16,
  135897. 19, 0,14,16,14, 0,20,16,20,17, 0, 0,17, 0,15, 0,
  135898. 19,
  135899. };
  135900. static float _vq_quantthresh__44u6__p3_0[] = {
  135901. -1.5, -0.5, 0.5, 1.5,
  135902. };
  135903. static long _vq_quantmap__44u6__p3_0[] = {
  135904. 3, 1, 0, 2, 4,
  135905. };
  135906. static encode_aux_threshmatch _vq_auxt__44u6__p3_0 = {
  135907. _vq_quantthresh__44u6__p3_0,
  135908. _vq_quantmap__44u6__p3_0,
  135909. 5,
  135910. 5
  135911. };
  135912. static static_codebook _44u6__p3_0 = {
  135913. 4, 625,
  135914. _vq_lengthlist__44u6__p3_0,
  135915. 1, -533725184, 1611661312, 3, 0,
  135916. _vq_quantlist__44u6__p3_0,
  135917. NULL,
  135918. &_vq_auxt__44u6__p3_0,
  135919. NULL,
  135920. 0
  135921. };
  135922. static long _vq_quantlist__44u6__p4_0[] = {
  135923. 2,
  135924. 1,
  135925. 3,
  135926. 0,
  135927. 4,
  135928. };
  135929. static long _vq_lengthlist__44u6__p4_0[] = {
  135930. 4, 5, 5, 8, 8, 6, 7, 6, 9, 9, 6, 6, 7, 9, 9, 8,
  135931. 9, 9,11,11, 8, 9, 9,11,11, 6, 7, 7, 9, 9, 7, 8,
  135932. 8,10,10, 7, 7, 8, 9,10, 9,10,10,11,11, 9, 9,10,
  135933. 11,12, 6, 7, 7, 9, 9, 7, 8, 7,10, 9, 7, 8, 8,10,
  135934. 10, 9,10, 9,12,11, 9,10,10,12,11, 8, 9, 9,11,11,
  135935. 9,10,10,12,12, 9,10,10,12,12,11,12,12,14,13,11,
  135936. 11,12,13,13, 8, 9, 9,11,11, 9,10,10,12,12, 9,10,
  135937. 10,12,12,11,12,11,13,12,11,12,12,13,13, 5, 7, 7,
  135938. 9, 9, 7, 8, 7,10,10, 7, 7, 8,10,10, 9,10,10,12,
  135939. 11, 9,10,10,11,12, 7, 8, 8,10,10, 8, 8, 9,11,11,
  135940. 8, 9, 9,11,11,10,10,11,12,13,10,10,11,12,12, 6,
  135941. 7, 7,10,10, 7, 9, 8,11,10, 8, 8, 9,10,11,10,11,
  135942. 10,13,11,10,11,11,12,12, 9,10,10,12,12,10,10,11,
  135943. 13,13,10,11,11,12,13,12,12,12,13,14,12,12,13,14,
  135944. 14, 9,10,10,12,12, 9,10,10,13,12,10,11,11,13,13,
  135945. 11,12,11,14,12,12,13,13,14,14, 6, 7, 7, 9, 9, 7,
  135946. 8, 7,10,10, 7, 8, 8,10,10, 9,10,10,12,11, 9,10,
  135947. 10,11,12, 6, 7, 7,10,10, 8, 9, 8,11,10, 7, 8, 9,
  135948. 10,11,10,11,11,12,12,10,10,11,11,13, 7, 8, 8,10,
  135949. 10, 8, 9, 9,11,11, 8, 9, 8,11,11,10,11,10,13,12,
  135950. 10,11,11,13,12, 9,10,10,12,12,10,11,11,13,12, 9,
  135951. 10,10,12,13,12,13,12,14,14,11,11,12,12,14, 9,10,
  135952. 10,12,12,10,11,11,13,13,10,11,10,13,12,12,12,12,
  135953. 14,14,12,13,12,14,13, 8, 9, 9,11,11, 9,10,10,12,
  135954. 12, 9,10,10,12,12,11,12,12,14,13,11,12,12,13,14,
  135955. 9,10,10,12,12,10,11,11,13,13,10,11,11,13,13,12,
  135956. 12,13,14,15,12,12,13,14,14, 9,10,10,12,12, 9,11,
  135957. 10,13,12,10,10,11,12,13,12,13,12,14,13,12,12,13,
  135958. 14,15,11,12,12,14,13,11,12,12,14,14,12,13,13,14,
  135959. 14,13,13,14,14,16,13,14,14,15,15,11,12,11,13,13,
  135960. 11,12,11,14,13,12,12,13,14,15,12,14,12,15,12,13,
  135961. 14,15,15,16, 8, 9, 9,11,11, 9,10,10,12,12, 9,10,
  135962. 10,12,12,11,12,12,14,13,11,12,12,13,13, 9,10,10,
  135963. 12,12,10,11,10,13,12, 9,10,11,12,13,12,13,12,14,
  135964. 14,12,12,13,13,14, 9,10,10,12,12,10,11,11,13,13,
  135965. 10,11,11,13,13,12,13,12,14,14,12,13,13,14,14,11,
  135966. 11,11,13,13,12,13,12,14,14,11,11,12,13,14,14,14,
  135967. 14,16,15,12,12,14,12,15,11,12,12,13,14,12,13,13,
  135968. 14,15,11,12,12,14,14,13,14,14,16,16,13,14,13,16,
  135969. 13,
  135970. };
  135971. static float _vq_quantthresh__44u6__p4_0[] = {
  135972. -1.5, -0.5, 0.5, 1.5,
  135973. };
  135974. static long _vq_quantmap__44u6__p4_0[] = {
  135975. 3, 1, 0, 2, 4,
  135976. };
  135977. static encode_aux_threshmatch _vq_auxt__44u6__p4_0 = {
  135978. _vq_quantthresh__44u6__p4_0,
  135979. _vq_quantmap__44u6__p4_0,
  135980. 5,
  135981. 5
  135982. };
  135983. static static_codebook _44u6__p4_0 = {
  135984. 4, 625,
  135985. _vq_lengthlist__44u6__p4_0,
  135986. 1, -533725184, 1611661312, 3, 0,
  135987. _vq_quantlist__44u6__p4_0,
  135988. NULL,
  135989. &_vq_auxt__44u6__p4_0,
  135990. NULL,
  135991. 0
  135992. };
  135993. static long _vq_quantlist__44u6__p5_0[] = {
  135994. 4,
  135995. 3,
  135996. 5,
  135997. 2,
  135998. 6,
  135999. 1,
  136000. 7,
  136001. 0,
  136002. 8,
  136003. };
  136004. static long _vq_lengthlist__44u6__p5_0[] = {
  136005. 2, 3, 3, 6, 6, 8, 8,10,10, 4, 5, 5, 8, 7, 8, 8,
  136006. 11,11, 3, 5, 5, 7, 8, 8, 8,11,11, 6, 8, 7, 9, 9,
  136007. 10, 9,12,11, 6, 7, 8, 9, 9, 9,10,11,12, 8, 8, 8,
  136008. 10, 9,12,11,13,13, 8, 8, 9, 9,10,11,12,13,13,10,
  136009. 11,11,12,12,13,13,14,14,10,10,11,11,12,13,13,14,
  136010. 14,
  136011. };
  136012. static float _vq_quantthresh__44u6__p5_0[] = {
  136013. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  136014. };
  136015. static long _vq_quantmap__44u6__p5_0[] = {
  136016. 7, 5, 3, 1, 0, 2, 4, 6,
  136017. 8,
  136018. };
  136019. static encode_aux_threshmatch _vq_auxt__44u6__p5_0 = {
  136020. _vq_quantthresh__44u6__p5_0,
  136021. _vq_quantmap__44u6__p5_0,
  136022. 9,
  136023. 9
  136024. };
  136025. static static_codebook _44u6__p5_0 = {
  136026. 2, 81,
  136027. _vq_lengthlist__44u6__p5_0,
  136028. 1, -531628032, 1611661312, 4, 0,
  136029. _vq_quantlist__44u6__p5_0,
  136030. NULL,
  136031. &_vq_auxt__44u6__p5_0,
  136032. NULL,
  136033. 0
  136034. };
  136035. static long _vq_quantlist__44u6__p6_0[] = {
  136036. 4,
  136037. 3,
  136038. 5,
  136039. 2,
  136040. 6,
  136041. 1,
  136042. 7,
  136043. 0,
  136044. 8,
  136045. };
  136046. static long _vq_lengthlist__44u6__p6_0[] = {
  136047. 3, 4, 4, 5, 5, 7, 7, 9, 9, 4, 5, 4, 6, 6, 7, 7,
  136048. 9, 9, 4, 4, 5, 6, 6, 7, 8, 9, 9, 5, 6, 6, 7, 7,
  136049. 8, 8,10,10, 5, 6, 6, 7, 7, 8, 8,10,10, 7, 8, 7,
  136050. 8, 8,10, 9,11,11, 7, 7, 8, 8, 8, 9,10,10,11, 9,
  136051. 9, 9,10,10,11,11,12,11, 9, 9, 9,10,10,11,11,11,
  136052. 12,
  136053. };
  136054. static float _vq_quantthresh__44u6__p6_0[] = {
  136055. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  136056. };
  136057. static long _vq_quantmap__44u6__p6_0[] = {
  136058. 7, 5, 3, 1, 0, 2, 4, 6,
  136059. 8,
  136060. };
  136061. static encode_aux_threshmatch _vq_auxt__44u6__p6_0 = {
  136062. _vq_quantthresh__44u6__p6_0,
  136063. _vq_quantmap__44u6__p6_0,
  136064. 9,
  136065. 9
  136066. };
  136067. static static_codebook _44u6__p6_0 = {
  136068. 2, 81,
  136069. _vq_lengthlist__44u6__p6_0,
  136070. 1, -531628032, 1611661312, 4, 0,
  136071. _vq_quantlist__44u6__p6_0,
  136072. NULL,
  136073. &_vq_auxt__44u6__p6_0,
  136074. NULL,
  136075. 0
  136076. };
  136077. static long _vq_quantlist__44u6__p7_0[] = {
  136078. 1,
  136079. 0,
  136080. 2,
  136081. };
  136082. static long _vq_lengthlist__44u6__p7_0[] = {
  136083. 1, 4, 4, 5, 7, 7, 5, 7, 7, 5, 9, 8, 7,10,10, 8,
  136084. 10,10, 5, 8, 9, 7,10,10, 7,10, 9, 4, 8, 8, 9,11,
  136085. 11, 8,11,11, 7,11,11,10,10,13,10,13,13, 7,11,11,
  136086. 10,13,12,10,13,13, 5, 9, 8, 8,11,11, 9,11,11, 7,
  136087. 11,11,10,13,13,10,12,13, 7,11,11,10,13,13, 9,13,
  136088. 10,
  136089. };
  136090. static float _vq_quantthresh__44u6__p7_0[] = {
  136091. -5.5, 5.5,
  136092. };
  136093. static long _vq_quantmap__44u6__p7_0[] = {
  136094. 1, 0, 2,
  136095. };
  136096. static encode_aux_threshmatch _vq_auxt__44u6__p7_0 = {
  136097. _vq_quantthresh__44u6__p7_0,
  136098. _vq_quantmap__44u6__p7_0,
  136099. 3,
  136100. 3
  136101. };
  136102. static static_codebook _44u6__p7_0 = {
  136103. 4, 81,
  136104. _vq_lengthlist__44u6__p7_0,
  136105. 1, -529137664, 1618345984, 2, 0,
  136106. _vq_quantlist__44u6__p7_0,
  136107. NULL,
  136108. &_vq_auxt__44u6__p7_0,
  136109. NULL,
  136110. 0
  136111. };
  136112. static long _vq_quantlist__44u6__p7_1[] = {
  136113. 5,
  136114. 4,
  136115. 6,
  136116. 3,
  136117. 7,
  136118. 2,
  136119. 8,
  136120. 1,
  136121. 9,
  136122. 0,
  136123. 10,
  136124. };
  136125. static long _vq_lengthlist__44u6__p7_1[] = {
  136126. 3, 4, 4, 6, 6, 7, 7, 8, 8, 8, 8, 4, 5, 5, 7, 6,
  136127. 8, 8, 8, 8, 8, 8, 4, 5, 5, 6, 7, 8, 8, 8, 8, 8,
  136128. 8, 6, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 6, 7, 7, 7,
  136129. 7, 8, 8, 8, 8, 8, 8, 7, 8, 8, 8, 8, 8, 8, 9, 9,
  136130. 9, 9, 7, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 8, 8, 8,
  136131. 8, 8, 9, 9, 9, 9, 9, 9, 8, 8, 8, 8, 8, 9, 9, 9,
  136132. 9, 9, 9, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 8, 8,
  136133. 8, 8, 8, 9, 9, 9, 9, 9, 9,
  136134. };
  136135. static float _vq_quantthresh__44u6__p7_1[] = {
  136136. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  136137. 3.5, 4.5,
  136138. };
  136139. static long _vq_quantmap__44u6__p7_1[] = {
  136140. 9, 7, 5, 3, 1, 0, 2, 4,
  136141. 6, 8, 10,
  136142. };
  136143. static encode_aux_threshmatch _vq_auxt__44u6__p7_1 = {
  136144. _vq_quantthresh__44u6__p7_1,
  136145. _vq_quantmap__44u6__p7_1,
  136146. 11,
  136147. 11
  136148. };
  136149. static static_codebook _44u6__p7_1 = {
  136150. 2, 121,
  136151. _vq_lengthlist__44u6__p7_1,
  136152. 1, -531365888, 1611661312, 4, 0,
  136153. _vq_quantlist__44u6__p7_1,
  136154. NULL,
  136155. &_vq_auxt__44u6__p7_1,
  136156. NULL,
  136157. 0
  136158. };
  136159. static long _vq_quantlist__44u6__p8_0[] = {
  136160. 5,
  136161. 4,
  136162. 6,
  136163. 3,
  136164. 7,
  136165. 2,
  136166. 8,
  136167. 1,
  136168. 9,
  136169. 0,
  136170. 10,
  136171. };
  136172. static long _vq_lengthlist__44u6__p8_0[] = {
  136173. 1, 4, 4, 6, 6, 8, 8, 9, 9,10,10, 4, 6, 6, 7, 7,
  136174. 9, 9,10,10,11,11, 4, 6, 6, 7, 7, 9, 9,10,10,11,
  136175. 11, 6, 8, 8, 9, 9,10,10,11,11,12,12, 6, 8, 8, 9,
  136176. 9,10,10,11,11,12,12, 8, 9, 9,10,10,11,11,12,12,
  136177. 13,13, 8, 9, 9,10,10,11,11,12,12,13,13,10,10,10,
  136178. 11,11,13,13,13,13,15,14, 9,10,10,12,11,12,13,13,
  136179. 13,14,15,11,12,12,13,13,13,13,15,14,15,15,11,11,
  136180. 12,13,13,14,14,14,15,15,15,
  136181. };
  136182. static float _vq_quantthresh__44u6__p8_0[] = {
  136183. -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5, 27.5,
  136184. 38.5, 49.5,
  136185. };
  136186. static long _vq_quantmap__44u6__p8_0[] = {
  136187. 9, 7, 5, 3, 1, 0, 2, 4,
  136188. 6, 8, 10,
  136189. };
  136190. static encode_aux_threshmatch _vq_auxt__44u6__p8_0 = {
  136191. _vq_quantthresh__44u6__p8_0,
  136192. _vq_quantmap__44u6__p8_0,
  136193. 11,
  136194. 11
  136195. };
  136196. static static_codebook _44u6__p8_0 = {
  136197. 2, 121,
  136198. _vq_lengthlist__44u6__p8_0,
  136199. 1, -524582912, 1618345984, 4, 0,
  136200. _vq_quantlist__44u6__p8_0,
  136201. NULL,
  136202. &_vq_auxt__44u6__p8_0,
  136203. NULL,
  136204. 0
  136205. };
  136206. static long _vq_quantlist__44u6__p8_1[] = {
  136207. 5,
  136208. 4,
  136209. 6,
  136210. 3,
  136211. 7,
  136212. 2,
  136213. 8,
  136214. 1,
  136215. 9,
  136216. 0,
  136217. 10,
  136218. };
  136219. static long _vq_lengthlist__44u6__p8_1[] = {
  136220. 3, 5, 5, 6, 6, 7, 7, 7, 7, 7, 7, 5, 6, 5, 7, 7,
  136221. 7, 7, 8, 7, 8, 8, 5, 5, 6, 6, 7, 7, 7, 7, 7, 8,
  136222. 8, 6, 7, 7, 7, 7, 8, 7, 8, 8, 8, 8, 6, 6, 7, 7,
  136223. 7, 7, 8, 8, 8, 8, 8, 7, 7, 7, 8, 8, 8, 8, 8, 8,
  136224. 8, 8, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 7, 7, 7,
  136225. 8, 8, 8, 8, 8, 8, 8, 8, 7, 8, 8, 8, 8, 8, 8, 8,
  136226. 8, 8, 8, 7, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 7, 8,
  136227. 8, 8, 8, 8, 8, 8, 8, 8, 8,
  136228. };
  136229. static float _vq_quantthresh__44u6__p8_1[] = {
  136230. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  136231. 3.5, 4.5,
  136232. };
  136233. static long _vq_quantmap__44u6__p8_1[] = {
  136234. 9, 7, 5, 3, 1, 0, 2, 4,
  136235. 6, 8, 10,
  136236. };
  136237. static encode_aux_threshmatch _vq_auxt__44u6__p8_1 = {
  136238. _vq_quantthresh__44u6__p8_1,
  136239. _vq_quantmap__44u6__p8_1,
  136240. 11,
  136241. 11
  136242. };
  136243. static static_codebook _44u6__p8_1 = {
  136244. 2, 121,
  136245. _vq_lengthlist__44u6__p8_1,
  136246. 1, -531365888, 1611661312, 4, 0,
  136247. _vq_quantlist__44u6__p8_1,
  136248. NULL,
  136249. &_vq_auxt__44u6__p8_1,
  136250. NULL,
  136251. 0
  136252. };
  136253. static long _vq_quantlist__44u6__p9_0[] = {
  136254. 7,
  136255. 6,
  136256. 8,
  136257. 5,
  136258. 9,
  136259. 4,
  136260. 10,
  136261. 3,
  136262. 11,
  136263. 2,
  136264. 12,
  136265. 1,
  136266. 13,
  136267. 0,
  136268. 14,
  136269. };
  136270. static long _vq_lengthlist__44u6__p9_0[] = {
  136271. 1, 3, 2, 9, 8,15,15,15,15,15,15,15,15,15,15, 4,
  136272. 8, 9,13,14,14,14,14,14,14,14,14,14,14,14, 5, 8,
  136273. 9,14,14,14,14,14,14,14,14,14,14,14,14,11,14,14,
  136274. 14,14,14,14,14,14,14,14,14,14,14,14,11,14,14,14,
  136275. 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,
  136276. 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,
  136277. 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,
  136278. 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,
  136279. 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,
  136280. 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,
  136281. 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,
  136282. 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,
  136283. 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,
  136284. 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,
  136285. 14,
  136286. };
  136287. static float _vq_quantthresh__44u6__p9_0[] = {
  136288. -1657.5, -1402.5, -1147.5, -892.5, -637.5, -382.5, -127.5, 127.5,
  136289. 382.5, 637.5, 892.5, 1147.5, 1402.5, 1657.5,
  136290. };
  136291. static long _vq_quantmap__44u6__p9_0[] = {
  136292. 13, 11, 9, 7, 5, 3, 1, 0,
  136293. 2, 4, 6, 8, 10, 12, 14,
  136294. };
  136295. static encode_aux_threshmatch _vq_auxt__44u6__p9_0 = {
  136296. _vq_quantthresh__44u6__p9_0,
  136297. _vq_quantmap__44u6__p9_0,
  136298. 15,
  136299. 15
  136300. };
  136301. static static_codebook _44u6__p9_0 = {
  136302. 2, 225,
  136303. _vq_lengthlist__44u6__p9_0,
  136304. 1, -514071552, 1627381760, 4, 0,
  136305. _vq_quantlist__44u6__p9_0,
  136306. NULL,
  136307. &_vq_auxt__44u6__p9_0,
  136308. NULL,
  136309. 0
  136310. };
  136311. static long _vq_quantlist__44u6__p9_1[] = {
  136312. 7,
  136313. 6,
  136314. 8,
  136315. 5,
  136316. 9,
  136317. 4,
  136318. 10,
  136319. 3,
  136320. 11,
  136321. 2,
  136322. 12,
  136323. 1,
  136324. 13,
  136325. 0,
  136326. 14,
  136327. };
  136328. static long _vq_lengthlist__44u6__p9_1[] = {
  136329. 1, 4, 4, 7, 7, 8, 9, 8, 8, 9, 8, 9, 8, 9, 9, 4,
  136330. 7, 6, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 4, 7,
  136331. 6, 9, 9,10,10, 9, 9,10,10,10,10,11,11, 7, 9, 8,
  136332. 10,10,11,11,10,10,11,11,11,11,11,11, 7, 8, 9,10,
  136333. 10,11,11,10,10,11,11,11,11,11,12, 8,10,10,11,11,
  136334. 12,12,11,11,12,12,12,12,13,12, 8,10,10,11,11,12,
  136335. 11,11,11,11,12,12,12,12,13, 8, 9, 9,11,10,11,11,
  136336. 12,12,12,12,13,12,13,12, 8, 9, 9,11,11,11,11,12,
  136337. 12,12,12,12,13,13,13, 9,10,10,11,12,12,12,12,12,
  136338. 13,13,13,13,13,13, 9,10,10,11,11,12,12,12,12,13,
  136339. 13,13,13,14,13,10,10,10,12,11,12,12,13,13,13,13,
  136340. 13,13,13,13,10,10,11,11,11,12,12,13,13,13,13,13,
  136341. 13,13,13,10,11,11,12,12,13,12,12,13,13,13,13,13,
  136342. 13,14,10,11,11,12,12,13,12,13,13,13,14,13,13,14,
  136343. 13,
  136344. };
  136345. static float _vq_quantthresh__44u6__p9_1[] = {
  136346. -110.5, -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5,
  136347. 25.5, 42.5, 59.5, 76.5, 93.5, 110.5,
  136348. };
  136349. static long _vq_quantmap__44u6__p9_1[] = {
  136350. 13, 11, 9, 7, 5, 3, 1, 0,
  136351. 2, 4, 6, 8, 10, 12, 14,
  136352. };
  136353. static encode_aux_threshmatch _vq_auxt__44u6__p9_1 = {
  136354. _vq_quantthresh__44u6__p9_1,
  136355. _vq_quantmap__44u6__p9_1,
  136356. 15,
  136357. 15
  136358. };
  136359. static static_codebook _44u6__p9_1 = {
  136360. 2, 225,
  136361. _vq_lengthlist__44u6__p9_1,
  136362. 1, -522338304, 1620115456, 4, 0,
  136363. _vq_quantlist__44u6__p9_1,
  136364. NULL,
  136365. &_vq_auxt__44u6__p9_1,
  136366. NULL,
  136367. 0
  136368. };
  136369. static long _vq_quantlist__44u6__p9_2[] = {
  136370. 8,
  136371. 7,
  136372. 9,
  136373. 6,
  136374. 10,
  136375. 5,
  136376. 11,
  136377. 4,
  136378. 12,
  136379. 3,
  136380. 13,
  136381. 2,
  136382. 14,
  136383. 1,
  136384. 15,
  136385. 0,
  136386. 16,
  136387. };
  136388. static long _vq_lengthlist__44u6__p9_2[] = {
  136389. 3, 5, 5, 7, 7, 8, 8, 8, 8, 8, 8, 9, 8, 8, 9, 9,
  136390. 9, 5, 6, 6, 7, 7, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9,
  136391. 9, 9, 5, 6, 6, 7, 7, 8, 8, 8, 8, 8, 8, 9, 9, 9,
  136392. 9, 9, 9, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  136393. 9, 9, 9, 9, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  136394. 9, 9, 9, 9, 9, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  136395. 9, 9, 9, 9, 9, 9, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  136396. 9, 9, 9, 9, 9, 9, 9, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  136397. 9, 9, 9, 9, 9, 9, 9, 9, 8, 8, 8, 9, 9, 9, 9, 9,
  136398. 9, 9, 9, 9, 9, 9, 9, 9, 9, 8, 9, 9, 9, 9, 9, 9,
  136399. 9, 9, 9, 9, 9, 9, 9, 9,10, 9, 8, 9, 9, 9, 9, 9,
  136400. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  136401. 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10, 9, 9, 9, 9, 9,
  136402. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10, 9, 9, 9,
  136403. 9, 9, 9, 9, 9, 9, 9, 9,10, 9, 9, 9,10, 9, 9, 9,
  136404. 9, 9, 9, 9, 9, 9, 9,10, 9, 9, 9,10, 9, 9,10, 9,
  136405. 9, 9, 9, 9, 9, 9, 9, 9,10,10,10, 9,10, 9,10,10,
  136406. 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10, 9,10,10, 9, 9,
  136407. 10,
  136408. };
  136409. static float _vq_quantthresh__44u6__p9_2[] = {
  136410. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  136411. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  136412. };
  136413. static long _vq_quantmap__44u6__p9_2[] = {
  136414. 15, 13, 11, 9, 7, 5, 3, 1,
  136415. 0, 2, 4, 6, 8, 10, 12, 14,
  136416. 16,
  136417. };
  136418. static encode_aux_threshmatch _vq_auxt__44u6__p9_2 = {
  136419. _vq_quantthresh__44u6__p9_2,
  136420. _vq_quantmap__44u6__p9_2,
  136421. 17,
  136422. 17
  136423. };
  136424. static static_codebook _44u6__p9_2 = {
  136425. 2, 289,
  136426. _vq_lengthlist__44u6__p9_2,
  136427. 1, -529530880, 1611661312, 5, 0,
  136428. _vq_quantlist__44u6__p9_2,
  136429. NULL,
  136430. &_vq_auxt__44u6__p9_2,
  136431. NULL,
  136432. 0
  136433. };
  136434. static long _huff_lengthlist__44u6__short[] = {
  136435. 4,11,16,13,17,13,17,16,17,17, 4, 7, 9, 9,13,10,
  136436. 16,12,16,17, 7, 6, 5, 7, 8, 9,12,12,16,17, 6, 9,
  136437. 7, 9,10,10,15,15,17,17, 6, 7, 5, 7, 5, 7, 7,10,
  136438. 16,17, 7, 9, 8, 9, 8,10,11,11,15,17, 7, 7, 7, 8,
  136439. 5, 8, 8, 9,15,17, 8, 7, 9, 9, 7, 8, 7, 2, 7,15,
  136440. 14,13,13,15, 5,10, 4, 3, 6,17,17,15,13,17, 7,11,
  136441. 7, 6, 9,16,
  136442. };
  136443. static static_codebook _huff_book__44u6__short = {
  136444. 2, 100,
  136445. _huff_lengthlist__44u6__short,
  136446. 0, 0, 0, 0, 0,
  136447. NULL,
  136448. NULL,
  136449. NULL,
  136450. NULL,
  136451. 0
  136452. };
  136453. static long _huff_lengthlist__44u7__long[] = {
  136454. 3, 9,14,13,15,14,16,13,13,14, 5, 5, 7, 7, 8, 9,
  136455. 11,10,12,15,10, 6, 5, 6, 6, 9,10,10,13,16,10, 6,
  136456. 6, 6, 6, 8, 9, 9,12,15,14, 7, 6, 6, 5, 6, 6, 8,
  136457. 12,15,10, 8, 7, 7, 6, 7, 7, 7,11,13,14,10, 9, 8,
  136458. 5, 6, 4, 5, 9,12,10, 9, 9, 8, 6, 6, 5, 3, 6,11,
  136459. 12,11,12,12,10, 9, 8, 5, 5, 8,10,11,15,13,13,13,
  136460. 12, 8, 6, 7,
  136461. };
  136462. static static_codebook _huff_book__44u7__long = {
  136463. 2, 100,
  136464. _huff_lengthlist__44u7__long,
  136465. 0, 0, 0, 0, 0,
  136466. NULL,
  136467. NULL,
  136468. NULL,
  136469. NULL,
  136470. 0
  136471. };
  136472. static long _vq_quantlist__44u7__p1_0[] = {
  136473. 1,
  136474. 0,
  136475. 2,
  136476. };
  136477. static long _vq_lengthlist__44u7__p1_0[] = {
  136478. 1, 4, 4, 4, 7, 7, 5, 7, 7, 5, 8, 8, 8,10,10, 7,
  136479. 10,10, 5, 8, 8, 7,10,10, 8,10,10, 5, 8, 8, 8,11,
  136480. 10, 8,10,10, 8,10,10,10,12,13,10,13,13, 7,10,10,
  136481. 10,13,12,10,13,13, 5, 8, 8, 8,11,10, 8,10,11, 7,
  136482. 10,10,10,13,13,10,12,13, 8,11,11,10,13,13,10,13,
  136483. 12,
  136484. };
  136485. static float _vq_quantthresh__44u7__p1_0[] = {
  136486. -0.5, 0.5,
  136487. };
  136488. static long _vq_quantmap__44u7__p1_0[] = {
  136489. 1, 0, 2,
  136490. };
  136491. static encode_aux_threshmatch _vq_auxt__44u7__p1_0 = {
  136492. _vq_quantthresh__44u7__p1_0,
  136493. _vq_quantmap__44u7__p1_0,
  136494. 3,
  136495. 3
  136496. };
  136497. static static_codebook _44u7__p1_0 = {
  136498. 4, 81,
  136499. _vq_lengthlist__44u7__p1_0,
  136500. 1, -535822336, 1611661312, 2, 0,
  136501. _vq_quantlist__44u7__p1_0,
  136502. NULL,
  136503. &_vq_auxt__44u7__p1_0,
  136504. NULL,
  136505. 0
  136506. };
  136507. static long _vq_quantlist__44u7__p2_0[] = {
  136508. 1,
  136509. 0,
  136510. 2,
  136511. };
  136512. static long _vq_lengthlist__44u7__p2_0[] = {
  136513. 3, 4, 4, 5, 6, 6, 5, 6, 6, 5, 6, 6, 6, 8, 8, 6,
  136514. 7, 8, 5, 6, 6, 6, 8, 7, 6, 8, 8, 5, 6, 6, 6, 8,
  136515. 7, 6, 8, 8, 6, 8, 8, 8, 9, 9, 8, 9, 9, 6, 8, 7,
  136516. 7, 9, 8, 8, 9, 9, 5, 6, 6, 6, 8, 7, 6, 8, 8, 6,
  136517. 8, 8, 8, 9, 9, 7, 8, 9, 6, 8, 8, 8, 9, 9, 8, 9,
  136518. 9,
  136519. };
  136520. static float _vq_quantthresh__44u7__p2_0[] = {
  136521. -0.5, 0.5,
  136522. };
  136523. static long _vq_quantmap__44u7__p2_0[] = {
  136524. 1, 0, 2,
  136525. };
  136526. static encode_aux_threshmatch _vq_auxt__44u7__p2_0 = {
  136527. _vq_quantthresh__44u7__p2_0,
  136528. _vq_quantmap__44u7__p2_0,
  136529. 3,
  136530. 3
  136531. };
  136532. static static_codebook _44u7__p2_0 = {
  136533. 4, 81,
  136534. _vq_lengthlist__44u7__p2_0,
  136535. 1, -535822336, 1611661312, 2, 0,
  136536. _vq_quantlist__44u7__p2_0,
  136537. NULL,
  136538. &_vq_auxt__44u7__p2_0,
  136539. NULL,
  136540. 0
  136541. };
  136542. static long _vq_quantlist__44u7__p3_0[] = {
  136543. 2,
  136544. 1,
  136545. 3,
  136546. 0,
  136547. 4,
  136548. };
  136549. static long _vq_lengthlist__44u7__p3_0[] = {
  136550. 2, 5, 4, 8, 8, 5, 7, 6, 9, 9, 5, 6, 7, 9, 9, 8,
  136551. 9, 9,13,12, 8, 9,10,12,13, 5, 7, 7,10, 9, 7, 9,
  136552. 9,11,11, 6, 8, 9,11,11,10,11,11,14,14, 9,10,11,
  136553. 13,14, 5, 7, 7, 9, 9, 7, 9, 8,11,11, 7, 9, 9,11,
  136554. 11, 9,11,10,14,13,10,11,11,14,14, 8,10,10,14,13,
  136555. 10,11,12,15,14, 9,11,11,15,14,13,14,14,16,16,12,
  136556. 13,14,17,16, 8,10,10,13,13, 9,11,11,14,15,10,11,
  136557. 12,14,15,12,14,13,16,16,13,14,15,15,17, 5, 7, 7,
  136558. 10,10, 7, 9, 9,11,11, 7, 9, 9,11,11,10,12,11,15,
  136559. 14,10,11,12,14,14, 7, 9, 9,12,12, 9,11,11,13,13,
  136560. 9,11,11,13,13,11,13,13,14,17,11,13,13,15,16, 6,
  136561. 9, 9,11,11, 8,11,10,13,12, 9,11,11,13,13,11,13,
  136562. 12,16,14,11,13,13,16,16,10,12,12,15,15,11,13,13,
  136563. 16,16,11,13,13,16,15,14,16,17,17,19,14,16,16,18,
  136564. 0, 9,11,11,14,15,10,13,12,16,15,11,13,13,16,16,
  136565. 14,15,14, 0,16,14,16,16,18, 0, 5, 7, 7,10,10, 7,
  136566. 9, 9,12,11, 7, 9, 9,11,12,10,11,11,15,14,10,11,
  136567. 12,14,14, 6, 9, 9,11,11, 9,11,11,13,13, 8,10,11,
  136568. 12,13,11,13,13,17,15,11,12,13,14,15, 7, 9, 9,11,
  136569. 12, 9,11,11,13,13, 9,11,11,13,13,11,13,12,16,16,
  136570. 11,13,13,15,14, 9,11,11,14,15,11,13,13,16,15,10,
  136571. 12,13,16,16,15,16,16, 0, 0,14,13,15,16,18,10,11,
  136572. 11,15,15,11,13,14,16,18,11,13,13,16,15,15,16,16,
  136573. 19, 0,14,15,15,16,16, 8,10,10,13,13,10,12,11,16,
  136574. 15,10,11,11,16,15,13,15,16,18, 0,13,14,15,17,17,
  136575. 9,11,11,15,15,11,13,13,16,18,11,13,13,16,17,15,
  136576. 16,16, 0, 0,15,18,16, 0,17, 9,11,11,15,15,11,13,
  136577. 12,17,15,11,13,14,16,17,15,18,15, 0,17,15,16,16,
  136578. 18,19,13,15,14, 0,18,14,16,16,19,18,14,16,15,19,
  136579. 19,16,18,19, 0, 0,16,17, 0, 0, 0,12,14,14,17,17,
  136580. 13,16,14, 0,18,14,16,15,18, 0,16,18,16,19,17,18,
  136581. 19,17, 0, 0, 8,10,10,14,14, 9,12,11,15,15,10,11,
  136582. 12,15,17,13,15,15,18,16,14,16,15,18,17, 9,11,11,
  136583. 16,15,11,13,13, 0,16,11,12,13,16,15,15,16,16, 0,
  136584. 17,15,15,16,18,17, 9,12,11,15,17,11,13,13,16,16,
  136585. 11,14,13,16,16,15,15,16,18,19,16,18,16, 0, 0,12,
  136586. 14,14, 0,16,14,16,16, 0,18,13,14,15,16, 0,17,16,
  136587. 18, 0, 0,16,16,17,19, 0,13,14,14,17, 0,14,17,16,
  136588. 0,19,14,15,15,18,19,17,16,18, 0, 0,15,19,16, 0,
  136589. 0,
  136590. };
  136591. static float _vq_quantthresh__44u7__p3_0[] = {
  136592. -1.5, -0.5, 0.5, 1.5,
  136593. };
  136594. static long _vq_quantmap__44u7__p3_0[] = {
  136595. 3, 1, 0, 2, 4,
  136596. };
  136597. static encode_aux_threshmatch _vq_auxt__44u7__p3_0 = {
  136598. _vq_quantthresh__44u7__p3_0,
  136599. _vq_quantmap__44u7__p3_0,
  136600. 5,
  136601. 5
  136602. };
  136603. static static_codebook _44u7__p3_0 = {
  136604. 4, 625,
  136605. _vq_lengthlist__44u7__p3_0,
  136606. 1, -533725184, 1611661312, 3, 0,
  136607. _vq_quantlist__44u7__p3_0,
  136608. NULL,
  136609. &_vq_auxt__44u7__p3_0,
  136610. NULL,
  136611. 0
  136612. };
  136613. static long _vq_quantlist__44u7__p4_0[] = {
  136614. 2,
  136615. 1,
  136616. 3,
  136617. 0,
  136618. 4,
  136619. };
  136620. static long _vq_lengthlist__44u7__p4_0[] = {
  136621. 4, 5, 5, 8, 8, 6, 7, 6, 9, 9, 6, 6, 7, 9, 9, 8,
  136622. 9, 9,11,11, 8, 9, 9,10,11, 6, 7, 7, 9, 9, 7, 8,
  136623. 8,10,10, 6, 7, 8, 9,10, 9,10,10,12,12, 9, 9,10,
  136624. 11,12, 6, 7, 7, 9, 9, 6, 8, 7,10, 9, 7, 8, 8,10,
  136625. 10, 9,10, 9,12,11, 9,10,10,12,11, 8, 9, 9,11,11,
  136626. 9,10,10,12,12, 9,10,10,12,12,11,12,12,13,14,11,
  136627. 11,12,13,13, 8, 9, 9,11,11, 9,10,10,12,11, 9,10,
  136628. 10,12,12,11,12,11,13,13,11,12,12,13,13, 6, 7, 7,
  136629. 9, 9, 7, 8, 7,10,10, 7, 7, 8,10,10, 9,10,10,12,
  136630. 11, 9,10,10,12,12, 7, 8, 8,10,10, 8, 8, 9,11,11,
  136631. 8, 9, 9,11,11,10,11,11,12,12,10,10,11,12,13, 6,
  136632. 7, 7,10,10, 7, 9, 8,11,10, 8, 8, 9,10,11,10,11,
  136633. 10,13,11,10,11,11,12,12, 9,10,10,12,12,10,10,11,
  136634. 13,13,10,11,11,13,12,12,12,13,13,14,12,12,13,14,
  136635. 14, 9,10,10,12,12, 9,10,10,12,12,10,11,11,13,13,
  136636. 11,12,11,14,12,12,13,13,14,14, 6, 7, 7, 9, 9, 7,
  136637. 8, 7,10,10, 7, 7, 8,10,10, 9,10,10,12,11, 9,10,
  136638. 10,11,12, 6, 7, 7,10,10, 8, 9, 8,11,10, 7, 8, 9,
  136639. 10,11,10,11,11,13,12,10,10,11,11,13, 7, 8, 8,10,
  136640. 10, 8, 9, 9,11,11, 8, 9, 9,11,11,10,11,10,13,12,
  136641. 10,11,11,12,12, 9,10,10,12,12,10,11,11,13,12, 9,
  136642. 10,10,12,13,12,13,12,14,14,11,11,12,12,14, 9,10,
  136643. 10,12,12,10,11,11,13,13,10,11,11,13,13,12,13,12,
  136644. 14,14,12,13,12,14,13, 8, 9, 9,11,11, 9,10,10,12,
  136645. 12, 9,10,10,12,12,11,12,12,14,13,11,12,12,13,13,
  136646. 9,10,10,12,12,10,11,11,13,13,10,11,11,13,12,12,
  136647. 13,13,14,14,12,12,13,14,14, 9,10,10,12,12, 9,11,
  136648. 10,13,12,10,10,11,12,13,11,13,12,14,13,12,12,13,
  136649. 14,14,11,12,12,13,13,11,12,13,14,14,12,13,13,14,
  136650. 14,13,13,14,14,16,13,14,14,16,16,11,11,11,13,13,
  136651. 11,12,11,14,13,12,12,13,14,15,13,14,12,16,13,14,
  136652. 14,14,15,16, 8, 9, 9,11,11, 9,10,10,12,12, 9,10,
  136653. 10,12,12,11,12,12,14,13,11,12,12,13,14, 9,10,10,
  136654. 12,12,10,11,10,13,12, 9,10,11,12,13,12,13,12,14,
  136655. 14,12,12,13,13,14, 9,10,10,12,12,10,11,11,12,13,
  136656. 10,11,11,13,13,12,13,12,14,14,12,13,13,14,14,11,
  136657. 12,12,13,13,12,13,12,14,14,11,11,12,13,14,13,15,
  136658. 14,16,15,13,12,14,13,16,11,12,12,13,13,12,13,13,
  136659. 14,14,12,12,12,14,14,13,14,14,15,15,13,14,13,16,
  136660. 14,
  136661. };
  136662. static float _vq_quantthresh__44u7__p4_0[] = {
  136663. -1.5, -0.5, 0.5, 1.5,
  136664. };
  136665. static long _vq_quantmap__44u7__p4_0[] = {
  136666. 3, 1, 0, 2, 4,
  136667. };
  136668. static encode_aux_threshmatch _vq_auxt__44u7__p4_0 = {
  136669. _vq_quantthresh__44u7__p4_0,
  136670. _vq_quantmap__44u7__p4_0,
  136671. 5,
  136672. 5
  136673. };
  136674. static static_codebook _44u7__p4_0 = {
  136675. 4, 625,
  136676. _vq_lengthlist__44u7__p4_0,
  136677. 1, -533725184, 1611661312, 3, 0,
  136678. _vq_quantlist__44u7__p4_0,
  136679. NULL,
  136680. &_vq_auxt__44u7__p4_0,
  136681. NULL,
  136682. 0
  136683. };
  136684. static long _vq_quantlist__44u7__p5_0[] = {
  136685. 4,
  136686. 3,
  136687. 5,
  136688. 2,
  136689. 6,
  136690. 1,
  136691. 7,
  136692. 0,
  136693. 8,
  136694. };
  136695. static long _vq_lengthlist__44u7__p5_0[] = {
  136696. 2, 3, 3, 6, 6, 7, 8,10,10, 4, 5, 5, 8, 7, 8, 8,
  136697. 11,11, 3, 5, 5, 7, 7, 8, 9,11,11, 6, 8, 7, 9, 9,
  136698. 10,10,12,12, 6, 7, 8, 9,10,10,10,12,12, 8, 8, 8,
  136699. 10,10,12,11,13,13, 8, 8, 9,10,10,11,11,13,13,10,
  136700. 11,11,12,12,13,13,14,14,10,11,11,12,12,13,13,14,
  136701. 14,
  136702. };
  136703. static float _vq_quantthresh__44u7__p5_0[] = {
  136704. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  136705. };
  136706. static long _vq_quantmap__44u7__p5_0[] = {
  136707. 7, 5, 3, 1, 0, 2, 4, 6,
  136708. 8,
  136709. };
  136710. static encode_aux_threshmatch _vq_auxt__44u7__p5_0 = {
  136711. _vq_quantthresh__44u7__p5_0,
  136712. _vq_quantmap__44u7__p5_0,
  136713. 9,
  136714. 9
  136715. };
  136716. static static_codebook _44u7__p5_0 = {
  136717. 2, 81,
  136718. _vq_lengthlist__44u7__p5_0,
  136719. 1, -531628032, 1611661312, 4, 0,
  136720. _vq_quantlist__44u7__p5_0,
  136721. NULL,
  136722. &_vq_auxt__44u7__p5_0,
  136723. NULL,
  136724. 0
  136725. };
  136726. static long _vq_quantlist__44u7__p6_0[] = {
  136727. 4,
  136728. 3,
  136729. 5,
  136730. 2,
  136731. 6,
  136732. 1,
  136733. 7,
  136734. 0,
  136735. 8,
  136736. };
  136737. static long _vq_lengthlist__44u7__p6_0[] = {
  136738. 3, 4, 4, 5, 5, 7, 7, 9, 9, 4, 5, 4, 6, 6, 8, 7,
  136739. 9, 9, 4, 4, 5, 6, 6, 7, 7, 9, 9, 5, 6, 6, 7, 7,
  136740. 8, 8,10,10, 5, 6, 6, 7, 7, 8, 8,10,10, 7, 8, 7,
  136741. 8, 8,10, 9,11,11, 7, 7, 8, 8, 8, 9,10,11,11, 9,
  136742. 9, 9,10,10,11,10,12,11, 9, 9, 9,10,10,11,11,11,
  136743. 12,
  136744. };
  136745. static float _vq_quantthresh__44u7__p6_0[] = {
  136746. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  136747. };
  136748. static long _vq_quantmap__44u7__p6_0[] = {
  136749. 7, 5, 3, 1, 0, 2, 4, 6,
  136750. 8,
  136751. };
  136752. static encode_aux_threshmatch _vq_auxt__44u7__p6_0 = {
  136753. _vq_quantthresh__44u7__p6_0,
  136754. _vq_quantmap__44u7__p6_0,
  136755. 9,
  136756. 9
  136757. };
  136758. static static_codebook _44u7__p6_0 = {
  136759. 2, 81,
  136760. _vq_lengthlist__44u7__p6_0,
  136761. 1, -531628032, 1611661312, 4, 0,
  136762. _vq_quantlist__44u7__p6_0,
  136763. NULL,
  136764. &_vq_auxt__44u7__p6_0,
  136765. NULL,
  136766. 0
  136767. };
  136768. static long _vq_quantlist__44u7__p7_0[] = {
  136769. 1,
  136770. 0,
  136771. 2,
  136772. };
  136773. static long _vq_lengthlist__44u7__p7_0[] = {
  136774. 1, 4, 4, 5, 7, 7, 5, 7, 7, 5, 9, 8, 8, 9, 9, 7,
  136775. 10,10, 5, 8, 9, 7, 9,10, 8, 9, 9, 4, 9, 9, 9,11,
  136776. 10, 8,10,10, 7,11,10,10,10,12,10,12,12, 7,10,10,
  136777. 10,12,11,10,12,12, 5, 9, 9, 8,10,10, 9,11,11, 7,
  136778. 11,10,10,12,12,10,11,12, 7,10,11,10,12,12,10,12,
  136779. 10,
  136780. };
  136781. static float _vq_quantthresh__44u7__p7_0[] = {
  136782. -5.5, 5.5,
  136783. };
  136784. static long _vq_quantmap__44u7__p7_0[] = {
  136785. 1, 0, 2,
  136786. };
  136787. static encode_aux_threshmatch _vq_auxt__44u7__p7_0 = {
  136788. _vq_quantthresh__44u7__p7_0,
  136789. _vq_quantmap__44u7__p7_0,
  136790. 3,
  136791. 3
  136792. };
  136793. static static_codebook _44u7__p7_0 = {
  136794. 4, 81,
  136795. _vq_lengthlist__44u7__p7_0,
  136796. 1, -529137664, 1618345984, 2, 0,
  136797. _vq_quantlist__44u7__p7_0,
  136798. NULL,
  136799. &_vq_auxt__44u7__p7_0,
  136800. NULL,
  136801. 0
  136802. };
  136803. static long _vq_quantlist__44u7__p7_1[] = {
  136804. 5,
  136805. 4,
  136806. 6,
  136807. 3,
  136808. 7,
  136809. 2,
  136810. 8,
  136811. 1,
  136812. 9,
  136813. 0,
  136814. 10,
  136815. };
  136816. static long _vq_lengthlist__44u7__p7_1[] = {
  136817. 3, 4, 4, 6, 6, 7, 7, 8, 8, 8, 8, 4, 5, 5, 6, 6,
  136818. 8, 7, 8, 8, 8, 8, 4, 5, 5, 6, 6, 7, 8, 8, 8, 8,
  136819. 8, 6, 7, 6, 7, 7, 8, 8, 9, 9, 9, 9, 6, 6, 7, 7,
  136820. 7, 8, 8, 9, 9, 9, 9, 7, 8, 7, 8, 8, 9, 9, 9, 9,
  136821. 9, 9, 7, 7, 8, 8, 8, 9, 9, 9, 9, 9, 9, 8, 8, 8,
  136822. 9, 9, 9, 9,10, 9, 9, 9, 8, 8, 8, 9, 9, 9, 9, 9,
  136823. 9, 9,10, 8, 8, 8, 9, 9, 9, 9,10, 9,10,10, 8, 8,
  136824. 8, 9, 9, 9, 9, 9,10,10,10,
  136825. };
  136826. static float _vq_quantthresh__44u7__p7_1[] = {
  136827. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  136828. 3.5, 4.5,
  136829. };
  136830. static long _vq_quantmap__44u7__p7_1[] = {
  136831. 9, 7, 5, 3, 1, 0, 2, 4,
  136832. 6, 8, 10,
  136833. };
  136834. static encode_aux_threshmatch _vq_auxt__44u7__p7_1 = {
  136835. _vq_quantthresh__44u7__p7_1,
  136836. _vq_quantmap__44u7__p7_1,
  136837. 11,
  136838. 11
  136839. };
  136840. static static_codebook _44u7__p7_1 = {
  136841. 2, 121,
  136842. _vq_lengthlist__44u7__p7_1,
  136843. 1, -531365888, 1611661312, 4, 0,
  136844. _vq_quantlist__44u7__p7_1,
  136845. NULL,
  136846. &_vq_auxt__44u7__p7_1,
  136847. NULL,
  136848. 0
  136849. };
  136850. static long _vq_quantlist__44u7__p8_0[] = {
  136851. 5,
  136852. 4,
  136853. 6,
  136854. 3,
  136855. 7,
  136856. 2,
  136857. 8,
  136858. 1,
  136859. 9,
  136860. 0,
  136861. 10,
  136862. };
  136863. static long _vq_lengthlist__44u7__p8_0[] = {
  136864. 1, 4, 4, 6, 6, 8, 8,10,10,11,11, 4, 6, 6, 7, 7,
  136865. 9, 9,11,10,12,12, 5, 6, 5, 7, 7, 9, 9,10,11,12,
  136866. 12, 6, 7, 7, 8, 8,10,10,11,11,13,13, 6, 7, 7, 8,
  136867. 8,10,10,11,12,13,13, 8, 9, 9,10,10,11,11,12,12,
  136868. 14,14, 8, 9, 9,10,10,11,11,12,12,14,14,10,10,10,
  136869. 11,11,13,12,14,14,15,15,10,10,10,12,12,13,13,14,
  136870. 14,15,15,11,12,12,13,13,14,14,15,14,16,15,11,12,
  136871. 12,13,13,14,14,15,15,15,16,
  136872. };
  136873. static float _vq_quantthresh__44u7__p8_0[] = {
  136874. -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5, 27.5,
  136875. 38.5, 49.5,
  136876. };
  136877. static long _vq_quantmap__44u7__p8_0[] = {
  136878. 9, 7, 5, 3, 1, 0, 2, 4,
  136879. 6, 8, 10,
  136880. };
  136881. static encode_aux_threshmatch _vq_auxt__44u7__p8_0 = {
  136882. _vq_quantthresh__44u7__p8_0,
  136883. _vq_quantmap__44u7__p8_0,
  136884. 11,
  136885. 11
  136886. };
  136887. static static_codebook _44u7__p8_0 = {
  136888. 2, 121,
  136889. _vq_lengthlist__44u7__p8_0,
  136890. 1, -524582912, 1618345984, 4, 0,
  136891. _vq_quantlist__44u7__p8_0,
  136892. NULL,
  136893. &_vq_auxt__44u7__p8_0,
  136894. NULL,
  136895. 0
  136896. };
  136897. static long _vq_quantlist__44u7__p8_1[] = {
  136898. 5,
  136899. 4,
  136900. 6,
  136901. 3,
  136902. 7,
  136903. 2,
  136904. 8,
  136905. 1,
  136906. 9,
  136907. 0,
  136908. 10,
  136909. };
  136910. static long _vq_lengthlist__44u7__p8_1[] = {
  136911. 4, 5, 5, 6, 6, 7, 7, 7, 7, 7, 7, 5, 6, 6, 7, 7,
  136912. 7, 7, 7, 7, 7, 7, 5, 6, 6, 6, 7, 7, 7, 7, 7, 7,
  136913. 7, 6, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 6, 7, 7, 7,
  136914. 7, 7, 7, 7, 7, 8, 8, 7, 7, 7, 7, 7, 8, 7, 8, 8,
  136915. 8, 8, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 7, 7, 7,
  136916. 7, 7, 8, 8, 8, 8, 8, 8, 7, 7, 7, 7, 7, 8, 8, 8,
  136917. 8, 8, 8, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 7, 7,
  136918. 7, 8, 8, 8, 8, 8, 8, 8, 8,
  136919. };
  136920. static float _vq_quantthresh__44u7__p8_1[] = {
  136921. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  136922. 3.5, 4.5,
  136923. };
  136924. static long _vq_quantmap__44u7__p8_1[] = {
  136925. 9, 7, 5, 3, 1, 0, 2, 4,
  136926. 6, 8, 10,
  136927. };
  136928. static encode_aux_threshmatch _vq_auxt__44u7__p8_1 = {
  136929. _vq_quantthresh__44u7__p8_1,
  136930. _vq_quantmap__44u7__p8_1,
  136931. 11,
  136932. 11
  136933. };
  136934. static static_codebook _44u7__p8_1 = {
  136935. 2, 121,
  136936. _vq_lengthlist__44u7__p8_1,
  136937. 1, -531365888, 1611661312, 4, 0,
  136938. _vq_quantlist__44u7__p8_1,
  136939. NULL,
  136940. &_vq_auxt__44u7__p8_1,
  136941. NULL,
  136942. 0
  136943. };
  136944. static long _vq_quantlist__44u7__p9_0[] = {
  136945. 5,
  136946. 4,
  136947. 6,
  136948. 3,
  136949. 7,
  136950. 2,
  136951. 8,
  136952. 1,
  136953. 9,
  136954. 0,
  136955. 10,
  136956. };
  136957. static long _vq_lengthlist__44u7__p9_0[] = {
  136958. 1, 3, 3,10,10,10,10,10,10,10,10, 4,10,10,10,10,
  136959. 10,10,10,10,10,10, 4,10,10,10,10,10,10,10,10,10,
  136960. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  136961. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  136962. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  136963. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  136964. 10,10,10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9,
  136965. 9, 9, 9, 9, 9, 9, 9, 9, 9,
  136966. };
  136967. static float _vq_quantthresh__44u7__p9_0[] = {
  136968. -2866.5, -2229.5, -1592.5, -955.5, -318.5, 318.5, 955.5, 1592.5,
  136969. 2229.5, 2866.5,
  136970. };
  136971. static long _vq_quantmap__44u7__p9_0[] = {
  136972. 9, 7, 5, 3, 1, 0, 2, 4,
  136973. 6, 8, 10,
  136974. };
  136975. static encode_aux_threshmatch _vq_auxt__44u7__p9_0 = {
  136976. _vq_quantthresh__44u7__p9_0,
  136977. _vq_quantmap__44u7__p9_0,
  136978. 11,
  136979. 11
  136980. };
  136981. static static_codebook _44u7__p9_0 = {
  136982. 2, 121,
  136983. _vq_lengthlist__44u7__p9_0,
  136984. 1, -512171520, 1630791680, 4, 0,
  136985. _vq_quantlist__44u7__p9_0,
  136986. NULL,
  136987. &_vq_auxt__44u7__p9_0,
  136988. NULL,
  136989. 0
  136990. };
  136991. static long _vq_quantlist__44u7__p9_1[] = {
  136992. 6,
  136993. 5,
  136994. 7,
  136995. 4,
  136996. 8,
  136997. 3,
  136998. 9,
  136999. 2,
  137000. 10,
  137001. 1,
  137002. 11,
  137003. 0,
  137004. 12,
  137005. };
  137006. static long _vq_lengthlist__44u7__p9_1[] = {
  137007. 1, 4, 4, 6, 5, 8, 6, 9, 8,10, 9,11,10, 4, 6, 6,
  137008. 8, 8, 9, 9,11,10,11,11,11,11, 4, 6, 6, 8, 8,10,
  137009. 9,11,11,11,11,11,12, 6, 8, 8,10,10,11,11,12,12,
  137010. 13,12,13,13, 6, 8, 8,10,10,11,11,12,12,12,13,14,
  137011. 13, 8,10,10,11,11,12,13,14,14,14,14,15,15, 8,10,
  137012. 10,11,12,12,13,13,14,14,14,14,15, 9,11,11,13,13,
  137013. 14,14,15,14,16,15,17,15, 9,11,11,12,13,14,14,15,
  137014. 14,15,15,15,16,10,12,12,13,14,15,15,15,15,16,17,
  137015. 16,17,10,13,12,13,14,14,16,16,16,16,15,16,17,11,
  137016. 13,13,14,15,14,17,15,16,17,17,17,17,11,13,13,14,
  137017. 15,15,15,15,17,17,16,17,16,
  137018. };
  137019. static float _vq_quantthresh__44u7__p9_1[] = {
  137020. -269.5, -220.5, -171.5, -122.5, -73.5, -24.5, 24.5, 73.5,
  137021. 122.5, 171.5, 220.5, 269.5,
  137022. };
  137023. static long _vq_quantmap__44u7__p9_1[] = {
  137024. 11, 9, 7, 5, 3, 1, 0, 2,
  137025. 4, 6, 8, 10, 12,
  137026. };
  137027. static encode_aux_threshmatch _vq_auxt__44u7__p9_1 = {
  137028. _vq_quantthresh__44u7__p9_1,
  137029. _vq_quantmap__44u7__p9_1,
  137030. 13,
  137031. 13
  137032. };
  137033. static static_codebook _44u7__p9_1 = {
  137034. 2, 169,
  137035. _vq_lengthlist__44u7__p9_1,
  137036. 1, -518889472, 1622704128, 4, 0,
  137037. _vq_quantlist__44u7__p9_1,
  137038. NULL,
  137039. &_vq_auxt__44u7__p9_1,
  137040. NULL,
  137041. 0
  137042. };
  137043. static long _vq_quantlist__44u7__p9_2[] = {
  137044. 24,
  137045. 23,
  137046. 25,
  137047. 22,
  137048. 26,
  137049. 21,
  137050. 27,
  137051. 20,
  137052. 28,
  137053. 19,
  137054. 29,
  137055. 18,
  137056. 30,
  137057. 17,
  137058. 31,
  137059. 16,
  137060. 32,
  137061. 15,
  137062. 33,
  137063. 14,
  137064. 34,
  137065. 13,
  137066. 35,
  137067. 12,
  137068. 36,
  137069. 11,
  137070. 37,
  137071. 10,
  137072. 38,
  137073. 9,
  137074. 39,
  137075. 8,
  137076. 40,
  137077. 7,
  137078. 41,
  137079. 6,
  137080. 42,
  137081. 5,
  137082. 43,
  137083. 4,
  137084. 44,
  137085. 3,
  137086. 45,
  137087. 2,
  137088. 46,
  137089. 1,
  137090. 47,
  137091. 0,
  137092. 48,
  137093. };
  137094. static long _vq_lengthlist__44u7__p9_2[] = {
  137095. 2, 4, 4, 4, 4, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6,
  137096. 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  137097. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8,
  137098. 8,
  137099. };
  137100. static float _vq_quantthresh__44u7__p9_2[] = {
  137101. -23.5, -22.5, -21.5, -20.5, -19.5, -18.5, -17.5, -16.5,
  137102. -15.5, -14.5, -13.5, -12.5, -11.5, -10.5, -9.5, -8.5,
  137103. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  137104. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  137105. 8.5, 9.5, 10.5, 11.5, 12.5, 13.5, 14.5, 15.5,
  137106. 16.5, 17.5, 18.5, 19.5, 20.5, 21.5, 22.5, 23.5,
  137107. };
  137108. static long _vq_quantmap__44u7__p9_2[] = {
  137109. 47, 45, 43, 41, 39, 37, 35, 33,
  137110. 31, 29, 27, 25, 23, 21, 19, 17,
  137111. 15, 13, 11, 9, 7, 5, 3, 1,
  137112. 0, 2, 4, 6, 8, 10, 12, 14,
  137113. 16, 18, 20, 22, 24, 26, 28, 30,
  137114. 32, 34, 36, 38, 40, 42, 44, 46,
  137115. 48,
  137116. };
  137117. static encode_aux_threshmatch _vq_auxt__44u7__p9_2 = {
  137118. _vq_quantthresh__44u7__p9_2,
  137119. _vq_quantmap__44u7__p9_2,
  137120. 49,
  137121. 49
  137122. };
  137123. static static_codebook _44u7__p9_2 = {
  137124. 1, 49,
  137125. _vq_lengthlist__44u7__p9_2,
  137126. 1, -526909440, 1611661312, 6, 0,
  137127. _vq_quantlist__44u7__p9_2,
  137128. NULL,
  137129. &_vq_auxt__44u7__p9_2,
  137130. NULL,
  137131. 0
  137132. };
  137133. static long _huff_lengthlist__44u7__short[] = {
  137134. 5,12,17,16,16,17,17,17,17,17, 4, 7,11,11,12, 9,
  137135. 17,10,17,17, 7, 7, 8, 9, 7, 9,11,10,15,17, 7, 9,
  137136. 10,11,10,12,14,12,16,17, 7, 8, 5, 7, 4, 7, 7, 8,
  137137. 16,16, 6,10, 9,10, 7,10,11,11,16,17, 6, 8, 8, 9,
  137138. 5, 7, 5, 8,16,17, 5, 5, 8, 7, 6, 7, 7, 6, 6,14,
  137139. 12,10,12,11, 7,11, 4, 4, 2, 7,17,15,15,15, 8,15,
  137140. 6, 8, 5, 9,
  137141. };
  137142. static static_codebook _huff_book__44u7__short = {
  137143. 2, 100,
  137144. _huff_lengthlist__44u7__short,
  137145. 0, 0, 0, 0, 0,
  137146. NULL,
  137147. NULL,
  137148. NULL,
  137149. NULL,
  137150. 0
  137151. };
  137152. static long _huff_lengthlist__44u8__long[] = {
  137153. 3, 9,13,14,14,15,14,14,15,15, 5, 4, 6, 8,10,12,
  137154. 12,14,15,15, 9, 5, 4, 5, 8,10,11,13,16,16,10, 7,
  137155. 4, 3, 5, 7, 9,11,13,13,10, 9, 7, 4, 4, 6, 8,10,
  137156. 12,14,13,11, 9, 6, 5, 5, 6, 8,12,14,13,11,10, 8,
  137157. 7, 6, 6, 7,10,14,13,11,12,10, 8, 7, 6, 6, 9,13,
  137158. 12,11,14,12,11, 9, 8, 7, 9,11,11,12,14,13,14,11,
  137159. 10, 8, 8, 9,
  137160. };
  137161. static static_codebook _huff_book__44u8__long = {
  137162. 2, 100,
  137163. _huff_lengthlist__44u8__long,
  137164. 0, 0, 0, 0, 0,
  137165. NULL,
  137166. NULL,
  137167. NULL,
  137168. NULL,
  137169. 0
  137170. };
  137171. static long _huff_lengthlist__44u8__short[] = {
  137172. 6,14,18,18,17,17,17,17,17,17, 4, 7, 9, 9,10,13,
  137173. 15,17,17,17, 6, 7, 5, 6, 8,11,16,17,16,17, 5, 7,
  137174. 5, 4, 6,10,14,17,17,17, 6, 6, 6, 5, 7,10,13,16,
  137175. 17,17, 7, 6, 7, 7, 7, 8, 7,10,15,16,12, 9, 9, 6,
  137176. 6, 5, 3, 5,11,15,14,14,13, 5, 5, 7, 3, 4, 8,15,
  137177. 17,17,13, 7, 7,10, 6, 6,10,15,17,17,16,10,11,14,
  137178. 10,10,15,17,
  137179. };
  137180. static static_codebook _huff_book__44u8__short = {
  137181. 2, 100,
  137182. _huff_lengthlist__44u8__short,
  137183. 0, 0, 0, 0, 0,
  137184. NULL,
  137185. NULL,
  137186. NULL,
  137187. NULL,
  137188. 0
  137189. };
  137190. static long _vq_quantlist__44u8_p1_0[] = {
  137191. 1,
  137192. 0,
  137193. 2,
  137194. };
  137195. static long _vq_lengthlist__44u8_p1_0[] = {
  137196. 1, 5, 5, 5, 7, 7, 5, 7, 7, 5, 7, 7, 8, 9, 9, 7,
  137197. 9, 9, 5, 7, 7, 7, 9, 9, 8, 9, 9, 5, 7, 7, 7, 9,
  137198. 9, 7, 9, 9, 7, 9, 9, 9,10,11, 9,11,10, 7, 9, 9,
  137199. 9,11,10, 9,10,11, 5, 7, 7, 7, 9, 9, 7, 9, 9, 7,
  137200. 9, 9, 9,11,10, 9,10,10, 8, 9, 9, 9,11,11, 9,11,
  137201. 10,
  137202. };
  137203. static float _vq_quantthresh__44u8_p1_0[] = {
  137204. -0.5, 0.5,
  137205. };
  137206. static long _vq_quantmap__44u8_p1_0[] = {
  137207. 1, 0, 2,
  137208. };
  137209. static encode_aux_threshmatch _vq_auxt__44u8_p1_0 = {
  137210. _vq_quantthresh__44u8_p1_0,
  137211. _vq_quantmap__44u8_p1_0,
  137212. 3,
  137213. 3
  137214. };
  137215. static static_codebook _44u8_p1_0 = {
  137216. 4, 81,
  137217. _vq_lengthlist__44u8_p1_0,
  137218. 1, -535822336, 1611661312, 2, 0,
  137219. _vq_quantlist__44u8_p1_0,
  137220. NULL,
  137221. &_vq_auxt__44u8_p1_0,
  137222. NULL,
  137223. 0
  137224. };
  137225. static long _vq_quantlist__44u8_p2_0[] = {
  137226. 2,
  137227. 1,
  137228. 3,
  137229. 0,
  137230. 4,
  137231. };
  137232. static long _vq_lengthlist__44u8_p2_0[] = {
  137233. 4, 5, 5, 8, 8, 5, 7, 6, 9, 9, 5, 6, 7, 9, 9, 8,
  137234. 9, 9,11,11, 8, 9, 9,11,11, 5, 7, 7, 9, 9, 7, 8,
  137235. 8,10,10, 7, 8, 8,10,10, 9,10,10,12,12, 9,10,10,
  137236. 11,12, 5, 7, 7, 9, 9, 7, 8, 7,10,10, 7, 8, 8,10,
  137237. 10, 9,10, 9,12,11, 9,10,10,12,12, 8, 9, 9,12,11,
  137238. 9,10,10,12,12, 9,10,10,12,12,11,12,12,14,14,11,
  137239. 11,12,13,14, 8, 9, 9,11,11, 9,10,10,12,12, 9,10,
  137240. 10,12,12,11,12,11,13,13,11,12,12,14,14, 5, 7, 7,
  137241. 9, 9, 7, 8, 8,10,10, 7, 8, 8,10,10, 9,10,10,12,
  137242. 12, 9,10,10,11,12, 7, 8, 8,10,10, 8, 9, 9,11,11,
  137243. 8, 9, 9,11,11,10,11,11,12,13,10,11,11,12,13, 6,
  137244. 8, 8,10,10, 8, 9, 8,11,10, 8, 9, 9,11,11,10,11,
  137245. 10,13,12,10,11,11,13,13, 9,10,10,12,12,10,11,11,
  137246. 13,13,10,11,11,13,13,12,12,13,13,14,12,13,13,14,
  137247. 14, 9,10,10,12,12,10,11,10,13,12,10,11,11,13,13,
  137248. 11,13,12,14,13,12,13,13,14,14, 5, 7, 7, 9, 9, 7,
  137249. 8, 8,10,10, 7, 8, 8,10,10, 9,10,10,12,12, 9,10,
  137250. 10,12,12, 7, 8, 8,10,10, 8, 9, 9,11,11, 8, 8, 9,
  137251. 10,11,10,11,11,13,13,10,10,11,12,13, 7, 8, 8,10,
  137252. 10, 8, 9, 9,11,11, 8, 9, 9,11,11,10,11,11,13,13,
  137253. 10,11,11,13,12, 9,10,10,12,12,10,11,11,13,13,10,
  137254. 10,11,12,13,12,13,13,14,14,12,12,13,13,14, 9,10,
  137255. 10,12,12,10,11,11,13,13,10,11,11,13,13,12,13,13,
  137256. 15,14,12,13,13,14,13, 8, 9, 9,11,11, 9,10,10,12,
  137257. 12, 9,10,10,12,12,12,12,12,14,13,11,12,12,14,14,
  137258. 9,10,10,12,12,10,11,11,13,13,10,11,11,13,13,12,
  137259. 13,13,14,15,12,13,13,14,15, 9,10,10,12,12,10,11,
  137260. 10,13,12,10,11,11,13,13,12,13,12,15,14,12,13,13,
  137261. 14,15,11,12,12,14,14,12,13,13,14,14,12,13,13,15,
  137262. 14,14,14,14,14,16,14,14,15,16,16,11,12,12,14,14,
  137263. 11,12,12,14,14,12,13,13,14,15,13,14,13,16,14,14,
  137264. 14,14,16,16, 8, 9, 9,11,11, 9,10,10,12,12, 9,10,
  137265. 10,12,12,11,12,12,14,13,11,12,12,14,14, 9,10,10,
  137266. 12,12,10,11,11,13,13,10,10,11,12,13,12,13,13,15,
  137267. 14,12,12,13,13,14, 9,10,10,12,12,10,11,11,13,13,
  137268. 10,11,11,13,13,12,13,13,14,14,12,13,13,15,14,11,
  137269. 12,12,14,13,12,13,13,15,14,11,12,12,13,14,14,15,
  137270. 14,16,15,13,13,14,13,16,11,12,12,14,14,12,13,13,
  137271. 14,15,12,13,12,15,14,14,14,14,16,15,14,15,13,16,
  137272. 14,
  137273. };
  137274. static float _vq_quantthresh__44u8_p2_0[] = {
  137275. -1.5, -0.5, 0.5, 1.5,
  137276. };
  137277. static long _vq_quantmap__44u8_p2_0[] = {
  137278. 3, 1, 0, 2, 4,
  137279. };
  137280. static encode_aux_threshmatch _vq_auxt__44u8_p2_0 = {
  137281. _vq_quantthresh__44u8_p2_0,
  137282. _vq_quantmap__44u8_p2_0,
  137283. 5,
  137284. 5
  137285. };
  137286. static static_codebook _44u8_p2_0 = {
  137287. 4, 625,
  137288. _vq_lengthlist__44u8_p2_0,
  137289. 1, -533725184, 1611661312, 3, 0,
  137290. _vq_quantlist__44u8_p2_0,
  137291. NULL,
  137292. &_vq_auxt__44u8_p2_0,
  137293. NULL,
  137294. 0
  137295. };
  137296. static long _vq_quantlist__44u8_p3_0[] = {
  137297. 4,
  137298. 3,
  137299. 5,
  137300. 2,
  137301. 6,
  137302. 1,
  137303. 7,
  137304. 0,
  137305. 8,
  137306. };
  137307. static long _vq_lengthlist__44u8_p3_0[] = {
  137308. 3, 4, 4, 5, 5, 7, 7, 9, 9, 4, 5, 4, 6, 6, 7, 7,
  137309. 9, 9, 4, 4, 5, 6, 6, 7, 7, 9, 9, 5, 6, 6, 7, 7,
  137310. 8, 8,10,10, 6, 6, 6, 7, 7, 8, 8,10,10, 7, 7, 7,
  137311. 8, 8, 9, 9,11,10, 7, 7, 7, 8, 8, 9, 9,10,11, 9,
  137312. 9, 9,10,10,11,10,12,11, 9, 9, 9, 9,10,11,11,11,
  137313. 12,
  137314. };
  137315. static float _vq_quantthresh__44u8_p3_0[] = {
  137316. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  137317. };
  137318. static long _vq_quantmap__44u8_p3_0[] = {
  137319. 7, 5, 3, 1, 0, 2, 4, 6,
  137320. 8,
  137321. };
  137322. static encode_aux_threshmatch _vq_auxt__44u8_p3_0 = {
  137323. _vq_quantthresh__44u8_p3_0,
  137324. _vq_quantmap__44u8_p3_0,
  137325. 9,
  137326. 9
  137327. };
  137328. static static_codebook _44u8_p3_0 = {
  137329. 2, 81,
  137330. _vq_lengthlist__44u8_p3_0,
  137331. 1, -531628032, 1611661312, 4, 0,
  137332. _vq_quantlist__44u8_p3_0,
  137333. NULL,
  137334. &_vq_auxt__44u8_p3_0,
  137335. NULL,
  137336. 0
  137337. };
  137338. static long _vq_quantlist__44u8_p4_0[] = {
  137339. 8,
  137340. 7,
  137341. 9,
  137342. 6,
  137343. 10,
  137344. 5,
  137345. 11,
  137346. 4,
  137347. 12,
  137348. 3,
  137349. 13,
  137350. 2,
  137351. 14,
  137352. 1,
  137353. 15,
  137354. 0,
  137355. 16,
  137356. };
  137357. static long _vq_lengthlist__44u8_p4_0[] = {
  137358. 4, 4, 4, 6, 6, 7, 7, 8, 8, 8, 8,10,10,11,11,11,
  137359. 11, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9,10,10,11,11,
  137360. 12,12, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9,10,10,11,
  137361. 11,12,12, 6, 6, 6, 7, 7, 8, 8, 9, 9, 9, 9,10,10,
  137362. 11,11,12,12, 6, 6, 6, 7, 7, 8, 8, 9, 9, 9, 9,10,
  137363. 10,11,11,12,12, 7, 7, 7, 8, 8, 9, 8,10, 9,10, 9,
  137364. 11,10,12,11,13,12, 7, 7, 7, 8, 8, 8, 9, 9,10, 9,
  137365. 10,10,11,11,12,12,13, 8, 8, 8, 9, 9, 9, 9,10,10,
  137366. 11,10,11,11,12,12,13,13, 8, 8, 8, 9, 9, 9,10,10,
  137367. 10,10,11,11,11,12,12,12,13, 8, 9, 9, 9, 9,10, 9,
  137368. 11,10,11,11,12,11,13,12,13,13, 8, 9, 9, 9, 9, 9,
  137369. 10,10,11,11,11,11,12,12,13,13,13,10,10,10,10,10,
  137370. 11,10,11,11,12,11,13,12,13,13,14,13,10,10,10,10,
  137371. 10,10,11,11,11,11,12,12,13,13,13,13,14,11,11,11,
  137372. 11,11,12,11,12,12,13,12,13,13,14,13,14,14,11,11,
  137373. 11,11,11,11,12,12,12,12,13,13,13,13,14,14,14,11,
  137374. 12,12,12,12,13,12,13,12,13,13,14,13,14,14,14,14,
  137375. 11,12,12,12,12,12,12,13,13,13,13,13,14,14,14,14,
  137376. 14,
  137377. };
  137378. static float _vq_quantthresh__44u8_p4_0[] = {
  137379. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  137380. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  137381. };
  137382. static long _vq_quantmap__44u8_p4_0[] = {
  137383. 15, 13, 11, 9, 7, 5, 3, 1,
  137384. 0, 2, 4, 6, 8, 10, 12, 14,
  137385. 16,
  137386. };
  137387. static encode_aux_threshmatch _vq_auxt__44u8_p4_0 = {
  137388. _vq_quantthresh__44u8_p4_0,
  137389. _vq_quantmap__44u8_p4_0,
  137390. 17,
  137391. 17
  137392. };
  137393. static static_codebook _44u8_p4_0 = {
  137394. 2, 289,
  137395. _vq_lengthlist__44u8_p4_0,
  137396. 1, -529530880, 1611661312, 5, 0,
  137397. _vq_quantlist__44u8_p4_0,
  137398. NULL,
  137399. &_vq_auxt__44u8_p4_0,
  137400. NULL,
  137401. 0
  137402. };
  137403. static long _vq_quantlist__44u8_p5_0[] = {
  137404. 1,
  137405. 0,
  137406. 2,
  137407. };
  137408. static long _vq_lengthlist__44u8_p5_0[] = {
  137409. 1, 4, 4, 5, 7, 7, 5, 7, 7, 5, 8, 8, 8, 9, 9, 7,
  137410. 9, 9, 5, 8, 8, 7, 9, 9, 8, 9, 9, 5, 8, 8, 8,10,
  137411. 10, 8,10,10, 7,10,10, 9,10,12, 9,12,11, 7,10,10,
  137412. 9,11,10, 9,11,12, 5, 8, 8, 8,10,10, 8,10,10, 7,
  137413. 10,10, 9,11,11, 9,10,11, 7,10,10, 9,11,11,10,12,
  137414. 10,
  137415. };
  137416. static float _vq_quantthresh__44u8_p5_0[] = {
  137417. -5.5, 5.5,
  137418. };
  137419. static long _vq_quantmap__44u8_p5_0[] = {
  137420. 1, 0, 2,
  137421. };
  137422. static encode_aux_threshmatch _vq_auxt__44u8_p5_0 = {
  137423. _vq_quantthresh__44u8_p5_0,
  137424. _vq_quantmap__44u8_p5_0,
  137425. 3,
  137426. 3
  137427. };
  137428. static static_codebook _44u8_p5_0 = {
  137429. 4, 81,
  137430. _vq_lengthlist__44u8_p5_0,
  137431. 1, -529137664, 1618345984, 2, 0,
  137432. _vq_quantlist__44u8_p5_0,
  137433. NULL,
  137434. &_vq_auxt__44u8_p5_0,
  137435. NULL,
  137436. 0
  137437. };
  137438. static long _vq_quantlist__44u8_p5_1[] = {
  137439. 5,
  137440. 4,
  137441. 6,
  137442. 3,
  137443. 7,
  137444. 2,
  137445. 8,
  137446. 1,
  137447. 9,
  137448. 0,
  137449. 10,
  137450. };
  137451. static long _vq_lengthlist__44u8_p5_1[] = {
  137452. 4, 5, 5, 6, 6, 7, 7, 7, 7, 8, 8, 5, 5, 5, 6, 6,
  137453. 7, 7, 8, 8, 8, 8, 5, 5, 5, 6, 6, 7, 7, 7, 8, 8,
  137454. 8, 6, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, 6, 6, 6, 7,
  137455. 7, 7, 7, 8, 8, 8, 8, 7, 7, 7, 7, 7, 8, 8, 8, 8,
  137456. 8, 8, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 7, 8, 7,
  137457. 8, 8, 8, 8, 8, 8, 8, 8, 7, 8, 8, 8, 8, 8, 8, 8,
  137458. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 9, 9, 8, 8,
  137459. 8, 8, 8, 8, 8, 8, 8, 9, 9,
  137460. };
  137461. static float _vq_quantthresh__44u8_p5_1[] = {
  137462. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  137463. 3.5, 4.5,
  137464. };
  137465. static long _vq_quantmap__44u8_p5_1[] = {
  137466. 9, 7, 5, 3, 1, 0, 2, 4,
  137467. 6, 8, 10,
  137468. };
  137469. static encode_aux_threshmatch _vq_auxt__44u8_p5_1 = {
  137470. _vq_quantthresh__44u8_p5_1,
  137471. _vq_quantmap__44u8_p5_1,
  137472. 11,
  137473. 11
  137474. };
  137475. static static_codebook _44u8_p5_1 = {
  137476. 2, 121,
  137477. _vq_lengthlist__44u8_p5_1,
  137478. 1, -531365888, 1611661312, 4, 0,
  137479. _vq_quantlist__44u8_p5_1,
  137480. NULL,
  137481. &_vq_auxt__44u8_p5_1,
  137482. NULL,
  137483. 0
  137484. };
  137485. static long _vq_quantlist__44u8_p6_0[] = {
  137486. 6,
  137487. 5,
  137488. 7,
  137489. 4,
  137490. 8,
  137491. 3,
  137492. 9,
  137493. 2,
  137494. 10,
  137495. 1,
  137496. 11,
  137497. 0,
  137498. 12,
  137499. };
  137500. static long _vq_lengthlist__44u8_p6_0[] = {
  137501. 2, 4, 4, 6, 6, 7, 7, 8, 8, 9, 9,10,10, 4, 6, 5,
  137502. 7, 7, 8, 8, 8, 8, 9, 9,10,10, 4, 6, 6, 7, 7, 8,
  137503. 8, 8, 8, 9, 9,10,10, 6, 7, 7, 7, 8, 8, 8, 8, 9,
  137504. 9,10,10,10, 6, 7, 7, 8, 8, 8, 8, 9, 8,10, 9,11,
  137505. 10, 7, 8, 8, 8, 8, 8, 9, 9, 9,10,10,11,11, 7, 8,
  137506. 8, 8, 8, 9, 8, 9, 9,10,10,11,11, 8, 8, 8, 9, 9,
  137507. 9, 9, 9,10,10,10,11,11, 8, 8, 8, 9, 9, 9, 9,10,
  137508. 9,10,10,11,11, 9, 9, 9, 9,10,10,10,10,10,10,11,
  137509. 11,12, 9, 9, 9,10, 9,10,10,10,10,11,10,12,11,10,
  137510. 10,10,10,10,11,11,11,11,11,12,12,12,10,10,10,10,
  137511. 11,11,11,11,11,12,11,12,12,
  137512. };
  137513. static float _vq_quantthresh__44u8_p6_0[] = {
  137514. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  137515. 12.5, 17.5, 22.5, 27.5,
  137516. };
  137517. static long _vq_quantmap__44u8_p6_0[] = {
  137518. 11, 9, 7, 5, 3, 1, 0, 2,
  137519. 4, 6, 8, 10, 12,
  137520. };
  137521. static encode_aux_threshmatch _vq_auxt__44u8_p6_0 = {
  137522. _vq_quantthresh__44u8_p6_0,
  137523. _vq_quantmap__44u8_p6_0,
  137524. 13,
  137525. 13
  137526. };
  137527. static static_codebook _44u8_p6_0 = {
  137528. 2, 169,
  137529. _vq_lengthlist__44u8_p6_0,
  137530. 1, -526516224, 1616117760, 4, 0,
  137531. _vq_quantlist__44u8_p6_0,
  137532. NULL,
  137533. &_vq_auxt__44u8_p6_0,
  137534. NULL,
  137535. 0
  137536. };
  137537. static long _vq_quantlist__44u8_p6_1[] = {
  137538. 2,
  137539. 1,
  137540. 3,
  137541. 0,
  137542. 4,
  137543. };
  137544. static long _vq_lengthlist__44u8_p6_1[] = {
  137545. 3, 4, 4, 5, 5, 4, 5, 5, 5, 5, 4, 5, 5, 5, 5, 5,
  137546. 5, 5, 5, 5, 5, 5, 5, 5, 5,
  137547. };
  137548. static float _vq_quantthresh__44u8_p6_1[] = {
  137549. -1.5, -0.5, 0.5, 1.5,
  137550. };
  137551. static long _vq_quantmap__44u8_p6_1[] = {
  137552. 3, 1, 0, 2, 4,
  137553. };
  137554. static encode_aux_threshmatch _vq_auxt__44u8_p6_1 = {
  137555. _vq_quantthresh__44u8_p6_1,
  137556. _vq_quantmap__44u8_p6_1,
  137557. 5,
  137558. 5
  137559. };
  137560. static static_codebook _44u8_p6_1 = {
  137561. 2, 25,
  137562. _vq_lengthlist__44u8_p6_1,
  137563. 1, -533725184, 1611661312, 3, 0,
  137564. _vq_quantlist__44u8_p6_1,
  137565. NULL,
  137566. &_vq_auxt__44u8_p6_1,
  137567. NULL,
  137568. 0
  137569. };
  137570. static long _vq_quantlist__44u8_p7_0[] = {
  137571. 6,
  137572. 5,
  137573. 7,
  137574. 4,
  137575. 8,
  137576. 3,
  137577. 9,
  137578. 2,
  137579. 10,
  137580. 1,
  137581. 11,
  137582. 0,
  137583. 12,
  137584. };
  137585. static long _vq_lengthlist__44u8_p7_0[] = {
  137586. 1, 4, 5, 6, 6, 7, 7, 8, 8,10,10,11,11, 5, 6, 6,
  137587. 7, 7, 8, 8, 9, 9,11,10,12,11, 5, 6, 6, 7, 7, 8,
  137588. 8, 9, 9,10,11,11,12, 6, 7, 7, 8, 8, 9, 9,10,10,
  137589. 11,11,12,12, 6, 7, 7, 8, 8, 9, 9,10,10,11,12,13,
  137590. 12, 7, 8, 8, 9, 9,10,10,11,11,12,12,13,13, 8, 8,
  137591. 8, 9, 9,10,10,11,11,12,12,13,13, 9, 9, 9,10,10,
  137592. 11,11,12,12,13,13,14,14, 9, 9, 9,10,10,11,11,12,
  137593. 12,13,13,14,14,10,11,11,12,11,13,12,13,13,14,14,
  137594. 15,15,10,11,11,11,12,12,13,13,14,14,14,15,15,11,
  137595. 12,12,13,13,14,13,15,14,15,15,16,15,11,11,12,13,
  137596. 13,13,14,14,14,15,15,15,16,
  137597. };
  137598. static float _vq_quantthresh__44u8_p7_0[] = {
  137599. -60.5, -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5,
  137600. 27.5, 38.5, 49.5, 60.5,
  137601. };
  137602. static long _vq_quantmap__44u8_p7_0[] = {
  137603. 11, 9, 7, 5, 3, 1, 0, 2,
  137604. 4, 6, 8, 10, 12,
  137605. };
  137606. static encode_aux_threshmatch _vq_auxt__44u8_p7_0 = {
  137607. _vq_quantthresh__44u8_p7_0,
  137608. _vq_quantmap__44u8_p7_0,
  137609. 13,
  137610. 13
  137611. };
  137612. static static_codebook _44u8_p7_0 = {
  137613. 2, 169,
  137614. _vq_lengthlist__44u8_p7_0,
  137615. 1, -523206656, 1618345984, 4, 0,
  137616. _vq_quantlist__44u8_p7_0,
  137617. NULL,
  137618. &_vq_auxt__44u8_p7_0,
  137619. NULL,
  137620. 0
  137621. };
  137622. static long _vq_quantlist__44u8_p7_1[] = {
  137623. 5,
  137624. 4,
  137625. 6,
  137626. 3,
  137627. 7,
  137628. 2,
  137629. 8,
  137630. 1,
  137631. 9,
  137632. 0,
  137633. 10,
  137634. };
  137635. static long _vq_lengthlist__44u8_p7_1[] = {
  137636. 4, 5, 5, 6, 6, 7, 7, 7, 7, 7, 7, 5, 6, 6, 7, 7,
  137637. 7, 7, 7, 7, 7, 7, 5, 6, 6, 7, 7, 7, 7, 7, 7, 7,
  137638. 7, 6, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 6, 7, 7, 7,
  137639. 7, 7, 7, 7, 7, 7, 8, 7, 7, 7, 7, 7, 7, 7, 8, 8,
  137640. 8, 8, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 7, 7, 7,
  137641. 8, 7, 8, 8, 8, 8, 8, 8, 7, 7, 7, 7, 7, 8, 8, 8,
  137642. 8, 8, 8, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 7, 7,
  137643. 7, 8, 8, 8, 8, 8, 8, 8, 8,
  137644. };
  137645. static float _vq_quantthresh__44u8_p7_1[] = {
  137646. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  137647. 3.5, 4.5,
  137648. };
  137649. static long _vq_quantmap__44u8_p7_1[] = {
  137650. 9, 7, 5, 3, 1, 0, 2, 4,
  137651. 6, 8, 10,
  137652. };
  137653. static encode_aux_threshmatch _vq_auxt__44u8_p7_1 = {
  137654. _vq_quantthresh__44u8_p7_1,
  137655. _vq_quantmap__44u8_p7_1,
  137656. 11,
  137657. 11
  137658. };
  137659. static static_codebook _44u8_p7_1 = {
  137660. 2, 121,
  137661. _vq_lengthlist__44u8_p7_1,
  137662. 1, -531365888, 1611661312, 4, 0,
  137663. _vq_quantlist__44u8_p7_1,
  137664. NULL,
  137665. &_vq_auxt__44u8_p7_1,
  137666. NULL,
  137667. 0
  137668. };
  137669. static long _vq_quantlist__44u8_p8_0[] = {
  137670. 7,
  137671. 6,
  137672. 8,
  137673. 5,
  137674. 9,
  137675. 4,
  137676. 10,
  137677. 3,
  137678. 11,
  137679. 2,
  137680. 12,
  137681. 1,
  137682. 13,
  137683. 0,
  137684. 14,
  137685. };
  137686. static long _vq_lengthlist__44u8_p8_0[] = {
  137687. 1, 4, 4, 7, 7, 8, 8, 8, 7, 9, 8,10, 9,11,10, 4,
  137688. 6, 6, 8, 8,10, 9, 9, 9,10,10,11,10,12,10, 4, 6,
  137689. 6, 8, 8,10,10, 9, 9,10,10,11,11,11,12, 7, 8, 8,
  137690. 10,10,11,11,11,10,12,11,12,12,13,11, 7, 8, 8,10,
  137691. 10,11,11,10,10,11,11,12,12,13,13, 8,10,10,11,11,
  137692. 12,11,12,11,13,12,13,12,14,13, 8,10, 9,11,11,12,
  137693. 12,12,12,12,12,13,13,14,13, 8, 9, 9,11,10,12,11,
  137694. 13,12,13,13,14,13,14,13, 8, 9, 9,10,11,12,12,12,
  137695. 12,13,13,14,15,14,14, 9,10,10,12,11,13,12,13,13,
  137696. 14,13,14,14,14,14, 9,10,10,12,12,12,12,13,13,14,
  137697. 14,14,15,14,14,10,11,11,13,12,13,12,14,14,14,14,
  137698. 14,14,15,15,10,11,11,12,12,13,13,14,14,14,15,15,
  137699. 14,16,15,11,12,12,13,12,14,14,14,13,15,14,15,15,
  137700. 15,17,11,12,12,13,13,14,14,14,15,15,14,15,15,14,
  137701. 17,
  137702. };
  137703. static float _vq_quantthresh__44u8_p8_0[] = {
  137704. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  137705. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  137706. };
  137707. static long _vq_quantmap__44u8_p8_0[] = {
  137708. 13, 11, 9, 7, 5, 3, 1, 0,
  137709. 2, 4, 6, 8, 10, 12, 14,
  137710. };
  137711. static encode_aux_threshmatch _vq_auxt__44u8_p8_0 = {
  137712. _vq_quantthresh__44u8_p8_0,
  137713. _vq_quantmap__44u8_p8_0,
  137714. 15,
  137715. 15
  137716. };
  137717. static static_codebook _44u8_p8_0 = {
  137718. 2, 225,
  137719. _vq_lengthlist__44u8_p8_0,
  137720. 1, -520986624, 1620377600, 4, 0,
  137721. _vq_quantlist__44u8_p8_0,
  137722. NULL,
  137723. &_vq_auxt__44u8_p8_0,
  137724. NULL,
  137725. 0
  137726. };
  137727. static long _vq_quantlist__44u8_p8_1[] = {
  137728. 10,
  137729. 9,
  137730. 11,
  137731. 8,
  137732. 12,
  137733. 7,
  137734. 13,
  137735. 6,
  137736. 14,
  137737. 5,
  137738. 15,
  137739. 4,
  137740. 16,
  137741. 3,
  137742. 17,
  137743. 2,
  137744. 18,
  137745. 1,
  137746. 19,
  137747. 0,
  137748. 20,
  137749. };
  137750. static long _vq_lengthlist__44u8_p8_1[] = {
  137751. 4, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9,
  137752. 9, 9, 9, 9, 9, 6, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,
  137753. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 5, 6, 6, 7, 7, 8,
  137754. 8, 9, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 7,
  137755. 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  137756. 9, 9, 9, 9, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  137757. 9, 9, 9, 9, 9, 9, 9, 9, 9, 8, 8, 8, 8, 8, 9, 9,
  137758. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10, 9,10, 8, 8,
  137759. 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10, 9,10,
  137760. 10, 9,10, 8, 9, 8, 9, 9, 9, 9, 9, 9, 9, 9,10, 9,
  137761. 10,10,10,10,10,10,10,10, 8, 9, 8, 9, 9, 9, 9, 9,
  137762. 9, 9, 9, 9, 9, 9,10,10,10,10, 9,10,10, 9, 9, 9,
  137763. 9, 9, 9, 9, 9, 9, 9, 9,10, 9,10,10,10,10,10,10,
  137764. 10,10, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10, 9,10,
  137765. 10,10,10,10,10,10,10, 9, 9, 9, 9, 9, 9, 9,10, 9,
  137766. 10,10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9,
  137767. 9, 9, 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,10,
  137768. 10, 9, 9, 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,
  137769. 10,10,10,10,10,10, 9, 9, 9, 9, 9, 9, 9,10,10,10,
  137770. 10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9, 9,
  137771. 9, 9,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  137772. 9, 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,10,10,
  137773. 10,10,10,10,10, 9, 9, 9,10, 9,10,10,10,10,10,10,
  137774. 10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9, 9,10,
  137775. 9,10,10,10,10,10,10,10,10,10,10,10,10,10,10, 9,
  137776. 9, 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,10,10,
  137777. 10,10,10,10, 9, 9, 9,10, 9,10, 9,10,10,10,10,10,
  137778. 10,10,10,10,10,10,10,10,10,
  137779. };
  137780. static float _vq_quantthresh__44u8_p8_1[] = {
  137781. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  137782. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  137783. 6.5, 7.5, 8.5, 9.5,
  137784. };
  137785. static long _vq_quantmap__44u8_p8_1[] = {
  137786. 19, 17, 15, 13, 11, 9, 7, 5,
  137787. 3, 1, 0, 2, 4, 6, 8, 10,
  137788. 12, 14, 16, 18, 20,
  137789. };
  137790. static encode_aux_threshmatch _vq_auxt__44u8_p8_1 = {
  137791. _vq_quantthresh__44u8_p8_1,
  137792. _vq_quantmap__44u8_p8_1,
  137793. 21,
  137794. 21
  137795. };
  137796. static static_codebook _44u8_p8_1 = {
  137797. 2, 441,
  137798. _vq_lengthlist__44u8_p8_1,
  137799. 1, -529268736, 1611661312, 5, 0,
  137800. _vq_quantlist__44u8_p8_1,
  137801. NULL,
  137802. &_vq_auxt__44u8_p8_1,
  137803. NULL,
  137804. 0
  137805. };
  137806. static long _vq_quantlist__44u8_p9_0[] = {
  137807. 4,
  137808. 3,
  137809. 5,
  137810. 2,
  137811. 6,
  137812. 1,
  137813. 7,
  137814. 0,
  137815. 8,
  137816. };
  137817. static long _vq_lengthlist__44u8_p9_0[] = {
  137818. 1, 3, 3, 9, 9, 9, 9, 9, 9, 4, 9, 9, 9, 9, 9, 9,
  137819. 9, 9, 5, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  137820. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  137821. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  137822. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 8, 8, 8,
  137823. 8,
  137824. };
  137825. static float _vq_quantthresh__44u8_p9_0[] = {
  137826. -3258.5, -2327.5, -1396.5, -465.5, 465.5, 1396.5, 2327.5, 3258.5,
  137827. };
  137828. static long _vq_quantmap__44u8_p9_0[] = {
  137829. 7, 5, 3, 1, 0, 2, 4, 6,
  137830. 8,
  137831. };
  137832. static encode_aux_threshmatch _vq_auxt__44u8_p9_0 = {
  137833. _vq_quantthresh__44u8_p9_0,
  137834. _vq_quantmap__44u8_p9_0,
  137835. 9,
  137836. 9
  137837. };
  137838. static static_codebook _44u8_p9_0 = {
  137839. 2, 81,
  137840. _vq_lengthlist__44u8_p9_0,
  137841. 1, -511895552, 1631393792, 4, 0,
  137842. _vq_quantlist__44u8_p9_0,
  137843. NULL,
  137844. &_vq_auxt__44u8_p9_0,
  137845. NULL,
  137846. 0
  137847. };
  137848. static long _vq_quantlist__44u8_p9_1[] = {
  137849. 9,
  137850. 8,
  137851. 10,
  137852. 7,
  137853. 11,
  137854. 6,
  137855. 12,
  137856. 5,
  137857. 13,
  137858. 4,
  137859. 14,
  137860. 3,
  137861. 15,
  137862. 2,
  137863. 16,
  137864. 1,
  137865. 17,
  137866. 0,
  137867. 18,
  137868. };
  137869. static long _vq_lengthlist__44u8_p9_1[] = {
  137870. 1, 4, 4, 7, 7, 8, 7, 8, 6, 9, 7,10, 8,11,10,11,
  137871. 11,11,11, 4, 7, 6, 9, 9,10, 9, 9, 9,10,10,11,10,
  137872. 11,10,11,11,13,11, 4, 7, 7, 9, 9, 9, 9, 9, 9,10,
  137873. 10,11,10,11,11,11,12,11,12, 7, 9, 8,11,11,11,11,
  137874. 10,10,11,11,12,12,12,12,12,12,14,13, 7, 8, 9,10,
  137875. 11,11,11,10,10,11,11,11,11,12,12,14,12,13,14, 8,
  137876. 9, 9,11,11,11,11,11,11,12,12,14,12,15,14,14,14,
  137877. 15,14, 8, 9, 9,11,11,11,11,12,11,12,12,13,13,13,
  137878. 13,13,13,14,14, 8, 9, 9,11,10,12,11,12,12,13,13,
  137879. 13,13,15,14,14,14,16,16, 8, 9, 9,10,11,11,12,12,
  137880. 12,13,13,13,14,14,14,15,16,15,15, 9,10,10,11,12,
  137881. 12,13,13,13,14,14,16,14,14,16,16,16,16,15, 9,10,
  137882. 10,11,11,12,13,13,14,15,14,16,14,15,16,16,16,16,
  137883. 15,10,11,11,12,13,13,14,15,15,15,15,15,16,15,16,
  137884. 15,16,15,15,10,11,11,13,13,14,13,13,15,14,15,15,
  137885. 16,15,15,15,16,15,16,10,12,12,14,14,14,14,14,16,
  137886. 16,15,15,15,16,16,16,16,16,16,11,12,12,14,14,14,
  137887. 14,15,15,16,15,16,15,16,15,16,16,16,16,12,12,13,
  137888. 14,14,15,16,16,16,16,16,16,15,16,16,16,16,16,16,
  137889. 12,13,13,14,14,14,14,15,16,15,16,16,16,16,16,16,
  137890. 16,16,16,12,13,14,14,14,16,15,16,15,16,16,16,16,
  137891. 16,16,16,16,16,16,12,14,13,14,15,15,15,16,15,16,
  137892. 16,15,16,16,16,16,16,16,16,
  137893. };
  137894. static float _vq_quantthresh__44u8_p9_1[] = {
  137895. -416.5, -367.5, -318.5, -269.5, -220.5, -171.5, -122.5, -73.5,
  137896. -24.5, 24.5, 73.5, 122.5, 171.5, 220.5, 269.5, 318.5,
  137897. 367.5, 416.5,
  137898. };
  137899. static long _vq_quantmap__44u8_p9_1[] = {
  137900. 17, 15, 13, 11, 9, 7, 5, 3,
  137901. 1, 0, 2, 4, 6, 8, 10, 12,
  137902. 14, 16, 18,
  137903. };
  137904. static encode_aux_threshmatch _vq_auxt__44u8_p9_1 = {
  137905. _vq_quantthresh__44u8_p9_1,
  137906. _vq_quantmap__44u8_p9_1,
  137907. 19,
  137908. 19
  137909. };
  137910. static static_codebook _44u8_p9_1 = {
  137911. 2, 361,
  137912. _vq_lengthlist__44u8_p9_1,
  137913. 1, -518287360, 1622704128, 5, 0,
  137914. _vq_quantlist__44u8_p9_1,
  137915. NULL,
  137916. &_vq_auxt__44u8_p9_1,
  137917. NULL,
  137918. 0
  137919. };
  137920. static long _vq_quantlist__44u8_p9_2[] = {
  137921. 24,
  137922. 23,
  137923. 25,
  137924. 22,
  137925. 26,
  137926. 21,
  137927. 27,
  137928. 20,
  137929. 28,
  137930. 19,
  137931. 29,
  137932. 18,
  137933. 30,
  137934. 17,
  137935. 31,
  137936. 16,
  137937. 32,
  137938. 15,
  137939. 33,
  137940. 14,
  137941. 34,
  137942. 13,
  137943. 35,
  137944. 12,
  137945. 36,
  137946. 11,
  137947. 37,
  137948. 10,
  137949. 38,
  137950. 9,
  137951. 39,
  137952. 8,
  137953. 40,
  137954. 7,
  137955. 41,
  137956. 6,
  137957. 42,
  137958. 5,
  137959. 43,
  137960. 4,
  137961. 44,
  137962. 3,
  137963. 45,
  137964. 2,
  137965. 46,
  137966. 1,
  137967. 47,
  137968. 0,
  137969. 48,
  137970. };
  137971. static long _vq_lengthlist__44u8_p9_2[] = {
  137972. 2, 3, 4, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6,
  137973. 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  137974. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  137975. 7,
  137976. };
  137977. static float _vq_quantthresh__44u8_p9_2[] = {
  137978. -23.5, -22.5, -21.5, -20.5, -19.5, -18.5, -17.5, -16.5,
  137979. -15.5, -14.5, -13.5, -12.5, -11.5, -10.5, -9.5, -8.5,
  137980. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  137981. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  137982. 8.5, 9.5, 10.5, 11.5, 12.5, 13.5, 14.5, 15.5,
  137983. 16.5, 17.5, 18.5, 19.5, 20.5, 21.5, 22.5, 23.5,
  137984. };
  137985. static long _vq_quantmap__44u8_p9_2[] = {
  137986. 47, 45, 43, 41, 39, 37, 35, 33,
  137987. 31, 29, 27, 25, 23, 21, 19, 17,
  137988. 15, 13, 11, 9, 7, 5, 3, 1,
  137989. 0, 2, 4, 6, 8, 10, 12, 14,
  137990. 16, 18, 20, 22, 24, 26, 28, 30,
  137991. 32, 34, 36, 38, 40, 42, 44, 46,
  137992. 48,
  137993. };
  137994. static encode_aux_threshmatch _vq_auxt__44u8_p9_2 = {
  137995. _vq_quantthresh__44u8_p9_2,
  137996. _vq_quantmap__44u8_p9_2,
  137997. 49,
  137998. 49
  137999. };
  138000. static static_codebook _44u8_p9_2 = {
  138001. 1, 49,
  138002. _vq_lengthlist__44u8_p9_2,
  138003. 1, -526909440, 1611661312, 6, 0,
  138004. _vq_quantlist__44u8_p9_2,
  138005. NULL,
  138006. &_vq_auxt__44u8_p9_2,
  138007. NULL,
  138008. 0
  138009. };
  138010. static long _huff_lengthlist__44u9__long[] = {
  138011. 3, 9,13,13,14,15,14,14,15,15, 5, 5, 9,10,12,12,
  138012. 13,14,16,15,10, 6, 6, 6, 8,11,12,13,16,15,11, 7,
  138013. 5, 3, 5, 8,10,12,15,15,10,10, 7, 4, 3, 5, 8,10,
  138014. 12,12,12,12, 9, 7, 5, 4, 6, 8,10,13,13,12,11, 9,
  138015. 7, 5, 5, 6, 9,12,14,12,12,10, 8, 6, 6, 6, 7,11,
  138016. 13,12,14,13,10, 8, 7, 7, 7,10,11,11,12,13,12,11,
  138017. 10, 8, 8, 9,
  138018. };
  138019. static static_codebook _huff_book__44u9__long = {
  138020. 2, 100,
  138021. _huff_lengthlist__44u9__long,
  138022. 0, 0, 0, 0, 0,
  138023. NULL,
  138024. NULL,
  138025. NULL,
  138026. NULL,
  138027. 0
  138028. };
  138029. static long _huff_lengthlist__44u9__short[] = {
  138030. 9,16,18,18,17,17,17,17,17,17, 5, 8,11,12,11,12,
  138031. 17,17,16,16, 6, 6, 8, 8, 9,10,14,15,16,16, 6, 7,
  138032. 7, 4, 6, 9,13,16,16,16, 6, 6, 7, 4, 5, 8,11,15,
  138033. 17,16, 7, 6, 7, 6, 6, 8, 9,10,14,16,11, 8, 8, 7,
  138034. 6, 6, 3, 4,10,15,14,12,12,10, 5, 6, 3, 3, 8,13,
  138035. 15,17,15,11, 6, 8, 6, 6, 9,14,17,15,15,12, 8,10,
  138036. 9, 9,12,15,
  138037. };
  138038. static static_codebook _huff_book__44u9__short = {
  138039. 2, 100,
  138040. _huff_lengthlist__44u9__short,
  138041. 0, 0, 0, 0, 0,
  138042. NULL,
  138043. NULL,
  138044. NULL,
  138045. NULL,
  138046. 0
  138047. };
  138048. static long _vq_quantlist__44u9_p1_0[] = {
  138049. 1,
  138050. 0,
  138051. 2,
  138052. };
  138053. static long _vq_lengthlist__44u9_p1_0[] = {
  138054. 1, 5, 5, 5, 7, 7, 5, 7, 7, 5, 7, 7, 7, 9, 9, 7,
  138055. 9, 9, 5, 7, 7, 7, 9, 9, 7, 9, 9, 5, 7, 7, 7, 9,
  138056. 9, 7, 9, 9, 8, 9, 9, 9,10,11, 9,11,11, 7, 9, 9,
  138057. 9,11,10, 9,11,11, 5, 7, 7, 7, 9, 9, 8, 9,10, 7,
  138058. 9, 9, 9,11,11, 9,10,11, 7, 9,10, 9,11,11, 9,11,
  138059. 10,
  138060. };
  138061. static float _vq_quantthresh__44u9_p1_0[] = {
  138062. -0.5, 0.5,
  138063. };
  138064. static long _vq_quantmap__44u9_p1_0[] = {
  138065. 1, 0, 2,
  138066. };
  138067. static encode_aux_threshmatch _vq_auxt__44u9_p1_0 = {
  138068. _vq_quantthresh__44u9_p1_0,
  138069. _vq_quantmap__44u9_p1_0,
  138070. 3,
  138071. 3
  138072. };
  138073. static static_codebook _44u9_p1_0 = {
  138074. 4, 81,
  138075. _vq_lengthlist__44u9_p1_0,
  138076. 1, -535822336, 1611661312, 2, 0,
  138077. _vq_quantlist__44u9_p1_0,
  138078. NULL,
  138079. &_vq_auxt__44u9_p1_0,
  138080. NULL,
  138081. 0
  138082. };
  138083. static long _vq_quantlist__44u9_p2_0[] = {
  138084. 2,
  138085. 1,
  138086. 3,
  138087. 0,
  138088. 4,
  138089. };
  138090. static long _vq_lengthlist__44u9_p2_0[] = {
  138091. 3, 5, 5, 8, 8, 5, 7, 7, 9, 9, 6, 7, 7, 9, 9, 8,
  138092. 9, 9,11,10, 8, 9, 9,11,11, 6, 7, 7, 9, 9, 7, 8,
  138093. 8,10,10, 7, 8, 8, 9,10, 9,10,10,11,11, 9, 9,10,
  138094. 11,11, 6, 7, 7, 9, 9, 7, 8, 8,10, 9, 7, 8, 8,10,
  138095. 10, 9,10, 9,11,11, 9,10,10,11,11, 8, 9, 9,11,11,
  138096. 9,10,10,12,11, 9,10,10,11,12,11,11,11,13,13,11,
  138097. 11,11,12,13, 8, 9, 9,11,11, 9,10,10,11,11, 9,10,
  138098. 10,12,11,11,12,11,13,12,11,11,12,13,13, 6, 7, 7,
  138099. 9, 9, 7, 8, 8,10,10, 7, 8, 8,10,10, 9,10,10,12,
  138100. 11, 9,10,10,11,12, 7, 8, 8,10,10, 8, 9, 9,11,11,
  138101. 8, 9, 9,10,10,10,11,11,12,12,10,10,11,12,12, 7,
  138102. 8, 8,10,10, 8, 9, 8,10,10, 8, 9, 9,10,10,10,11,
  138103. 10,12,11,10,10,11,12,12, 9,10,10,11,12,10,11,11,
  138104. 12,12,10,11,10,12,12,12,12,12,13,13,11,12,12,13,
  138105. 13, 9,10,10,11,11, 9,10,10,12,12,10,11,11,12,13,
  138106. 11,12,11,13,12,12,12,12,13,14, 6, 7, 7, 9, 9, 7,
  138107. 8, 8,10,10, 7, 8, 8,10,10, 9,10,10,11,11, 9,10,
  138108. 10,11,12, 7, 8, 8,10,10, 8, 9, 9,11,10, 8, 8, 9,
  138109. 10,10,10,11,10,12,12,10,10,11,11,12, 7, 8, 8,10,
  138110. 10, 8, 9, 9,10,10, 8, 9, 9,10,10,10,11,10,12,12,
  138111. 10,11,10,12,12, 9,10,10,12,11,10,11,11,12,12, 9,
  138112. 10,10,12,12,12,12,12,13,13,11,11,12,12,14, 9,10,
  138113. 10,11,12,10,11,11,12,12,10,11,11,12,12,11,12,12,
  138114. 14,14,12,12,12,13,13, 8, 9, 9,11,11, 9,10,10,12,
  138115. 11, 9,10,10,12,12,11,12,11,13,13,11,11,12,13,13,
  138116. 9,10,10,12,12,10,11,11,12,12,10,11,11,12,12,12,
  138117. 12,12,14,14,12,12,12,13,13, 9,10,10,12,11,10,11,
  138118. 10,12,12,10,11,11,12,12,11,12,12,14,13,12,12,12,
  138119. 13,14,11,12,11,13,13,11,12,12,13,13,12,12,12,14,
  138120. 14,13,13,13,13,15,13,13,14,15,15,11,11,11,13,13,
  138121. 11,12,11,13,13,11,12,12,13,13,12,13,12,15,13,13,
  138122. 13,14,14,15, 8, 9, 9,11,11, 9,10,10,11,12, 9,10,
  138123. 10,11,12,11,12,11,13,13,11,12,12,13,13, 9,10,10,
  138124. 11,12,10,11,10,12,12,10,10,11,12,13,12,12,12,14,
  138125. 13,11,12,12,13,14, 9,10,10,12,12,10,11,11,12,12,
  138126. 10,11,11,12,12,12,12,12,14,13,12,12,12,14,13,11,
  138127. 11,11,13,13,11,12,12,14,13,11,11,12,13,13,13,13,
  138128. 13,15,14,12,12,13,13,15,11,12,12,13,13,12,12,12,
  138129. 13,14,11,12,12,13,13,13,13,14,14,15,13,13,13,14,
  138130. 14,
  138131. };
  138132. static float _vq_quantthresh__44u9_p2_0[] = {
  138133. -1.5, -0.5, 0.5, 1.5,
  138134. };
  138135. static long _vq_quantmap__44u9_p2_0[] = {
  138136. 3, 1, 0, 2, 4,
  138137. };
  138138. static encode_aux_threshmatch _vq_auxt__44u9_p2_0 = {
  138139. _vq_quantthresh__44u9_p2_0,
  138140. _vq_quantmap__44u9_p2_0,
  138141. 5,
  138142. 5
  138143. };
  138144. static static_codebook _44u9_p2_0 = {
  138145. 4, 625,
  138146. _vq_lengthlist__44u9_p2_0,
  138147. 1, -533725184, 1611661312, 3, 0,
  138148. _vq_quantlist__44u9_p2_0,
  138149. NULL,
  138150. &_vq_auxt__44u9_p2_0,
  138151. NULL,
  138152. 0
  138153. };
  138154. static long _vq_quantlist__44u9_p3_0[] = {
  138155. 4,
  138156. 3,
  138157. 5,
  138158. 2,
  138159. 6,
  138160. 1,
  138161. 7,
  138162. 0,
  138163. 8,
  138164. };
  138165. static long _vq_lengthlist__44u9_p3_0[] = {
  138166. 3, 4, 4, 5, 5, 7, 7, 8, 8, 4, 5, 5, 6, 6, 7, 7,
  138167. 9, 9, 4, 4, 5, 6, 6, 7, 7, 9, 9, 5, 6, 6, 7, 7,
  138168. 8, 8, 9, 9, 5, 6, 6, 7, 7, 8, 8, 9, 9, 7, 7, 7,
  138169. 8, 8, 9, 9,10,10, 7, 7, 7, 8, 8, 9, 9,10,10, 8,
  138170. 9, 9,10, 9,10,10,11,11, 8, 9, 9, 9,10,10,10,11,
  138171. 11,
  138172. };
  138173. static float _vq_quantthresh__44u9_p3_0[] = {
  138174. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  138175. };
  138176. static long _vq_quantmap__44u9_p3_0[] = {
  138177. 7, 5, 3, 1, 0, 2, 4, 6,
  138178. 8,
  138179. };
  138180. static encode_aux_threshmatch _vq_auxt__44u9_p3_0 = {
  138181. _vq_quantthresh__44u9_p3_0,
  138182. _vq_quantmap__44u9_p3_0,
  138183. 9,
  138184. 9
  138185. };
  138186. static static_codebook _44u9_p3_0 = {
  138187. 2, 81,
  138188. _vq_lengthlist__44u9_p3_0,
  138189. 1, -531628032, 1611661312, 4, 0,
  138190. _vq_quantlist__44u9_p3_0,
  138191. NULL,
  138192. &_vq_auxt__44u9_p3_0,
  138193. NULL,
  138194. 0
  138195. };
  138196. static long _vq_quantlist__44u9_p4_0[] = {
  138197. 8,
  138198. 7,
  138199. 9,
  138200. 6,
  138201. 10,
  138202. 5,
  138203. 11,
  138204. 4,
  138205. 12,
  138206. 3,
  138207. 13,
  138208. 2,
  138209. 14,
  138210. 1,
  138211. 15,
  138212. 0,
  138213. 16,
  138214. };
  138215. static long _vq_lengthlist__44u9_p4_0[] = {
  138216. 4, 5, 5, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,10,10,11,
  138217. 11, 5, 5, 5, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,10,10,
  138218. 11,11, 5, 5, 5, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,10,
  138219. 10,11,11, 6, 6, 6, 7, 6, 7, 7, 8, 8, 9, 9,10,10,
  138220. 11,11,12,11, 6, 6, 6, 6, 7, 7, 7, 8, 8, 9, 9,10,
  138221. 10,11,11,11,12, 7, 7, 7, 7, 7, 8, 8, 9, 9, 9, 9,
  138222. 10,10,11,11,12,12, 7, 7, 7, 7, 7, 8, 8, 9, 9, 9,
  138223. 9,10,10,11,11,12,12, 8, 8, 8, 8, 8, 9, 8,10, 9,
  138224. 10,10,11,10,12,11,13,12, 8, 8, 8, 8, 8, 9, 9, 9,
  138225. 10,10,10,10,11,11,12,12,12, 8, 8, 8, 9, 9, 9, 9,
  138226. 10,10,11,10,12,11,12,12,13,12, 8, 8, 8, 9, 9, 9,
  138227. 9,10,10,10,11,11,11,12,12,12,13, 9, 9, 9,10,10,
  138228. 10,10,11,10,11,11,12,11,13,12,13,13, 9, 9,10,10,
  138229. 10,10,10,10,11,11,11,11,12,12,13,13,13,10,11,10,
  138230. 11,11,11,11,12,11,12,12,13,12,13,13,14,13,10,10,
  138231. 10,11,11,11,11,11,12,12,12,12,13,13,13,13,14,11,
  138232. 11,11,12,11,12,12,12,12,13,13,13,13,14,13,14,14,
  138233. 11,11,11,11,12,12,12,12,12,12,13,13,13,13,14,14,
  138234. 14,
  138235. };
  138236. static float _vq_quantthresh__44u9_p4_0[] = {
  138237. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  138238. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  138239. };
  138240. static long _vq_quantmap__44u9_p4_0[] = {
  138241. 15, 13, 11, 9, 7, 5, 3, 1,
  138242. 0, 2, 4, 6, 8, 10, 12, 14,
  138243. 16,
  138244. };
  138245. static encode_aux_threshmatch _vq_auxt__44u9_p4_0 = {
  138246. _vq_quantthresh__44u9_p4_0,
  138247. _vq_quantmap__44u9_p4_0,
  138248. 17,
  138249. 17
  138250. };
  138251. static static_codebook _44u9_p4_0 = {
  138252. 2, 289,
  138253. _vq_lengthlist__44u9_p4_0,
  138254. 1, -529530880, 1611661312, 5, 0,
  138255. _vq_quantlist__44u9_p4_0,
  138256. NULL,
  138257. &_vq_auxt__44u9_p4_0,
  138258. NULL,
  138259. 0
  138260. };
  138261. static long _vq_quantlist__44u9_p5_0[] = {
  138262. 1,
  138263. 0,
  138264. 2,
  138265. };
  138266. static long _vq_lengthlist__44u9_p5_0[] = {
  138267. 1, 4, 4, 5, 7, 7, 5, 7, 7, 5, 8, 8, 8, 9, 9, 7,
  138268. 9, 9, 5, 8, 8, 7, 9, 9, 8, 9, 9, 5, 8, 8, 8,10,
  138269. 10, 8,10,10, 7,10,10, 9,10,12, 9,11,11, 7,10,10,
  138270. 9,11,10, 9,11,12, 5, 8, 8, 8,10,10, 8,10,10, 7,
  138271. 10,10, 9,12,11, 9,10,11, 7,10,10, 9,11,11,10,12,
  138272. 10,
  138273. };
  138274. static float _vq_quantthresh__44u9_p5_0[] = {
  138275. -5.5, 5.5,
  138276. };
  138277. static long _vq_quantmap__44u9_p5_0[] = {
  138278. 1, 0, 2,
  138279. };
  138280. static encode_aux_threshmatch _vq_auxt__44u9_p5_0 = {
  138281. _vq_quantthresh__44u9_p5_0,
  138282. _vq_quantmap__44u9_p5_0,
  138283. 3,
  138284. 3
  138285. };
  138286. static static_codebook _44u9_p5_0 = {
  138287. 4, 81,
  138288. _vq_lengthlist__44u9_p5_0,
  138289. 1, -529137664, 1618345984, 2, 0,
  138290. _vq_quantlist__44u9_p5_0,
  138291. NULL,
  138292. &_vq_auxt__44u9_p5_0,
  138293. NULL,
  138294. 0
  138295. };
  138296. static long _vq_quantlist__44u9_p5_1[] = {
  138297. 5,
  138298. 4,
  138299. 6,
  138300. 3,
  138301. 7,
  138302. 2,
  138303. 8,
  138304. 1,
  138305. 9,
  138306. 0,
  138307. 10,
  138308. };
  138309. static long _vq_lengthlist__44u9_p5_1[] = {
  138310. 5, 5, 5, 6, 6, 7, 7, 7, 7, 7, 7, 5, 6, 6, 6, 6,
  138311. 7, 7, 7, 7, 8, 7, 5, 6, 6, 6, 6, 7, 7, 7, 7, 7,
  138312. 7, 6, 6, 6, 7, 7, 7, 7, 7, 7, 8, 8, 6, 6, 6, 7,
  138313. 7, 7, 7, 7, 7, 8, 8, 7, 7, 7, 7, 7, 8, 7, 8, 8,
  138314. 8, 8, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 7, 7, 7,
  138315. 8, 7, 8, 8, 8, 8, 8, 8, 7, 7, 7, 7, 8, 8, 8, 8,
  138316. 8, 8, 8, 7, 8, 7, 8, 8, 8, 8, 8, 8, 8, 8, 7, 8,
  138317. 8, 8, 8, 8, 8, 8, 8, 8, 8,
  138318. };
  138319. static float _vq_quantthresh__44u9_p5_1[] = {
  138320. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  138321. 3.5, 4.5,
  138322. };
  138323. static long _vq_quantmap__44u9_p5_1[] = {
  138324. 9, 7, 5, 3, 1, 0, 2, 4,
  138325. 6, 8, 10,
  138326. };
  138327. static encode_aux_threshmatch _vq_auxt__44u9_p5_1 = {
  138328. _vq_quantthresh__44u9_p5_1,
  138329. _vq_quantmap__44u9_p5_1,
  138330. 11,
  138331. 11
  138332. };
  138333. static static_codebook _44u9_p5_1 = {
  138334. 2, 121,
  138335. _vq_lengthlist__44u9_p5_1,
  138336. 1, -531365888, 1611661312, 4, 0,
  138337. _vq_quantlist__44u9_p5_1,
  138338. NULL,
  138339. &_vq_auxt__44u9_p5_1,
  138340. NULL,
  138341. 0
  138342. };
  138343. static long _vq_quantlist__44u9_p6_0[] = {
  138344. 6,
  138345. 5,
  138346. 7,
  138347. 4,
  138348. 8,
  138349. 3,
  138350. 9,
  138351. 2,
  138352. 10,
  138353. 1,
  138354. 11,
  138355. 0,
  138356. 12,
  138357. };
  138358. static long _vq_lengthlist__44u9_p6_0[] = {
  138359. 2, 4, 4, 6, 6, 7, 7, 8, 8, 9, 9,10,10, 4, 6, 5,
  138360. 7, 7, 8, 8, 8, 8, 9, 9,10,10, 4, 5, 6, 7, 7, 8,
  138361. 8, 8, 8, 9, 9,10,10, 6, 7, 7, 8, 8, 8, 8, 9, 9,
  138362. 10,10,10,10, 6, 7, 7, 8, 8, 8, 8, 9, 9,10,10,10,
  138363. 10, 7, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,11, 7, 8,
  138364. 8, 8, 8, 9, 9, 9, 9,10,10,11,11, 8, 8, 8, 9, 9,
  138365. 9, 9, 9,10,10,10,11,11, 8, 8, 8, 9, 9, 9, 9,10,
  138366. 9,10,10,11,11, 9, 9, 9,10,10,10,10,10,11,11,11,
  138367. 11,12, 9, 9, 9,10,10,10,10,10,10,11,10,12,11,10,
  138368. 10,10,10,10,11,11,11,11,11,12,12,12,10,10,10,10,
  138369. 10,11,11,11,11,12,11,12,12,
  138370. };
  138371. static float _vq_quantthresh__44u9_p6_0[] = {
  138372. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  138373. 12.5, 17.5, 22.5, 27.5,
  138374. };
  138375. static long _vq_quantmap__44u9_p6_0[] = {
  138376. 11, 9, 7, 5, 3, 1, 0, 2,
  138377. 4, 6, 8, 10, 12,
  138378. };
  138379. static encode_aux_threshmatch _vq_auxt__44u9_p6_0 = {
  138380. _vq_quantthresh__44u9_p6_0,
  138381. _vq_quantmap__44u9_p6_0,
  138382. 13,
  138383. 13
  138384. };
  138385. static static_codebook _44u9_p6_0 = {
  138386. 2, 169,
  138387. _vq_lengthlist__44u9_p6_0,
  138388. 1, -526516224, 1616117760, 4, 0,
  138389. _vq_quantlist__44u9_p6_0,
  138390. NULL,
  138391. &_vq_auxt__44u9_p6_0,
  138392. NULL,
  138393. 0
  138394. };
  138395. static long _vq_quantlist__44u9_p6_1[] = {
  138396. 2,
  138397. 1,
  138398. 3,
  138399. 0,
  138400. 4,
  138401. };
  138402. static long _vq_lengthlist__44u9_p6_1[] = {
  138403. 4, 4, 4, 5, 5, 4, 5, 4, 5, 5, 4, 4, 5, 5, 5, 5,
  138404. 5, 5, 5, 5, 5, 5, 5, 5, 5,
  138405. };
  138406. static float _vq_quantthresh__44u9_p6_1[] = {
  138407. -1.5, -0.5, 0.5, 1.5,
  138408. };
  138409. static long _vq_quantmap__44u9_p6_1[] = {
  138410. 3, 1, 0, 2, 4,
  138411. };
  138412. static encode_aux_threshmatch _vq_auxt__44u9_p6_1 = {
  138413. _vq_quantthresh__44u9_p6_1,
  138414. _vq_quantmap__44u9_p6_1,
  138415. 5,
  138416. 5
  138417. };
  138418. static static_codebook _44u9_p6_1 = {
  138419. 2, 25,
  138420. _vq_lengthlist__44u9_p6_1,
  138421. 1, -533725184, 1611661312, 3, 0,
  138422. _vq_quantlist__44u9_p6_1,
  138423. NULL,
  138424. &_vq_auxt__44u9_p6_1,
  138425. NULL,
  138426. 0
  138427. };
  138428. static long _vq_quantlist__44u9_p7_0[] = {
  138429. 6,
  138430. 5,
  138431. 7,
  138432. 4,
  138433. 8,
  138434. 3,
  138435. 9,
  138436. 2,
  138437. 10,
  138438. 1,
  138439. 11,
  138440. 0,
  138441. 12,
  138442. };
  138443. static long _vq_lengthlist__44u9_p7_0[] = {
  138444. 1, 4, 5, 6, 6, 7, 7, 8, 9,10,10,11,11, 5, 6, 6,
  138445. 7, 7, 8, 8, 9, 9,10,10,11,11, 5, 6, 6, 7, 7, 8,
  138446. 8, 9, 9,10,10,11,11, 6, 7, 7, 8, 8, 9, 9,10,10,
  138447. 11,11,12,12, 6, 7, 7, 8, 8, 9, 9,10,10,11,11,12,
  138448. 12, 8, 8, 8, 9, 9,10,10,11,11,12,12,13,13, 8, 8,
  138449. 8, 9, 9,10,10,11,11,12,12,13,13, 9, 9, 9,10,10,
  138450. 11,11,12,12,13,13,13,13, 9, 9, 9,10,10,11,11,12,
  138451. 12,13,13,14,14,10,10,10,11,11,12,12,13,13,14,13,
  138452. 15,14,10,10,10,11,11,12,12,13,13,14,14,14,14,11,
  138453. 11,12,12,12,13,13,14,14,14,14,15,15,11,11,12,12,
  138454. 12,13,13,14,14,14,15,15,15,
  138455. };
  138456. static float _vq_quantthresh__44u9_p7_0[] = {
  138457. -60.5, -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5,
  138458. 27.5, 38.5, 49.5, 60.5,
  138459. };
  138460. static long _vq_quantmap__44u9_p7_0[] = {
  138461. 11, 9, 7, 5, 3, 1, 0, 2,
  138462. 4, 6, 8, 10, 12,
  138463. };
  138464. static encode_aux_threshmatch _vq_auxt__44u9_p7_0 = {
  138465. _vq_quantthresh__44u9_p7_0,
  138466. _vq_quantmap__44u9_p7_0,
  138467. 13,
  138468. 13
  138469. };
  138470. static static_codebook _44u9_p7_0 = {
  138471. 2, 169,
  138472. _vq_lengthlist__44u9_p7_0,
  138473. 1, -523206656, 1618345984, 4, 0,
  138474. _vq_quantlist__44u9_p7_0,
  138475. NULL,
  138476. &_vq_auxt__44u9_p7_0,
  138477. NULL,
  138478. 0
  138479. };
  138480. static long _vq_quantlist__44u9_p7_1[] = {
  138481. 5,
  138482. 4,
  138483. 6,
  138484. 3,
  138485. 7,
  138486. 2,
  138487. 8,
  138488. 1,
  138489. 9,
  138490. 0,
  138491. 10,
  138492. };
  138493. static long _vq_lengthlist__44u9_p7_1[] = {
  138494. 5, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 6, 6, 6, 7, 7,
  138495. 7, 7, 7, 7, 7, 7, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7,
  138496. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 6, 7, 7, 7,
  138497. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  138498. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  138499. 7, 7, 7, 7, 8, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  138500. 7, 8, 8, 7, 7, 7, 7, 7, 7, 7, 8, 7, 8, 8, 7, 7,
  138501. 7, 7, 7, 7, 7, 8, 8, 8, 8,
  138502. };
  138503. static float _vq_quantthresh__44u9_p7_1[] = {
  138504. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  138505. 3.5, 4.5,
  138506. };
  138507. static long _vq_quantmap__44u9_p7_1[] = {
  138508. 9, 7, 5, 3, 1, 0, 2, 4,
  138509. 6, 8, 10,
  138510. };
  138511. static encode_aux_threshmatch _vq_auxt__44u9_p7_1 = {
  138512. _vq_quantthresh__44u9_p7_1,
  138513. _vq_quantmap__44u9_p7_1,
  138514. 11,
  138515. 11
  138516. };
  138517. static static_codebook _44u9_p7_1 = {
  138518. 2, 121,
  138519. _vq_lengthlist__44u9_p7_1,
  138520. 1, -531365888, 1611661312, 4, 0,
  138521. _vq_quantlist__44u9_p7_1,
  138522. NULL,
  138523. &_vq_auxt__44u9_p7_1,
  138524. NULL,
  138525. 0
  138526. };
  138527. static long _vq_quantlist__44u9_p8_0[] = {
  138528. 7,
  138529. 6,
  138530. 8,
  138531. 5,
  138532. 9,
  138533. 4,
  138534. 10,
  138535. 3,
  138536. 11,
  138537. 2,
  138538. 12,
  138539. 1,
  138540. 13,
  138541. 0,
  138542. 14,
  138543. };
  138544. static long _vq_lengthlist__44u9_p8_0[] = {
  138545. 1, 4, 4, 7, 7, 8, 8, 8, 8, 9, 9,10, 9,11,10, 4,
  138546. 6, 6, 8, 8, 9, 9, 9, 9,10,10,11,10,12,10, 4, 6,
  138547. 6, 8, 8, 9,10, 9, 9,10,10,11,11,12,12, 7, 8, 8,
  138548. 10,10,11,11,10,10,11,11,12,12,13,12, 7, 8, 8,10,
  138549. 10,11,11,10,10,11,11,12,12,12,13, 8,10, 9,11,11,
  138550. 12,12,11,11,12,12,13,13,14,13, 8, 9, 9,11,11,12,
  138551. 12,11,12,12,12,13,13,14,13, 8, 9, 9,10,10,12,11,
  138552. 13,12,13,13,14,13,15,14, 8, 9, 9,10,10,11,12,12,
  138553. 12,13,13,13,14,14,14, 9,10,10,12,11,13,12,13,13,
  138554. 14,13,14,14,14,15, 9,10,10,11,12,12,12,13,13,14,
  138555. 14,14,15,15,15,10,11,11,12,12,13,13,14,14,14,14,
  138556. 15,14,16,15,10,11,11,12,12,13,13,13,14,14,14,14,
  138557. 14,15,16,11,12,12,13,13,14,13,14,14,15,14,15,16,
  138558. 16,16,11,12,12,13,13,14,13,14,14,15,15,15,16,15,
  138559. 15,
  138560. };
  138561. static float _vq_quantthresh__44u9_p8_0[] = {
  138562. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  138563. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  138564. };
  138565. static long _vq_quantmap__44u9_p8_0[] = {
  138566. 13, 11, 9, 7, 5, 3, 1, 0,
  138567. 2, 4, 6, 8, 10, 12, 14,
  138568. };
  138569. static encode_aux_threshmatch _vq_auxt__44u9_p8_0 = {
  138570. _vq_quantthresh__44u9_p8_0,
  138571. _vq_quantmap__44u9_p8_0,
  138572. 15,
  138573. 15
  138574. };
  138575. static static_codebook _44u9_p8_0 = {
  138576. 2, 225,
  138577. _vq_lengthlist__44u9_p8_0,
  138578. 1, -520986624, 1620377600, 4, 0,
  138579. _vq_quantlist__44u9_p8_0,
  138580. NULL,
  138581. &_vq_auxt__44u9_p8_0,
  138582. NULL,
  138583. 0
  138584. };
  138585. static long _vq_quantlist__44u9_p8_1[] = {
  138586. 10,
  138587. 9,
  138588. 11,
  138589. 8,
  138590. 12,
  138591. 7,
  138592. 13,
  138593. 6,
  138594. 14,
  138595. 5,
  138596. 15,
  138597. 4,
  138598. 16,
  138599. 3,
  138600. 17,
  138601. 2,
  138602. 18,
  138603. 1,
  138604. 19,
  138605. 0,
  138606. 20,
  138607. };
  138608. static long _vq_lengthlist__44u9_p8_1[] = {
  138609. 4, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9,
  138610. 9, 9, 9, 9, 9, 6, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,
  138611. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 6, 6, 6, 7, 7, 8,
  138612. 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 7,
  138613. 7, 7, 8, 8, 8, 8, 9, 8, 9, 9, 9, 9, 9, 9, 9, 9,
  138614. 9, 9, 9, 9, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  138615. 9, 9, 9, 9, 9, 9, 9, 9, 9, 8, 8, 8, 8, 8, 9, 9,
  138616. 9, 9, 9, 9, 9, 9, 9, 9, 9,10, 9,10,10,10, 8, 8,
  138617. 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  138618. 9,10,10, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  138619. 10, 9,10, 9,10,10,10,10, 8, 8, 8, 9, 9, 9, 9, 9,
  138620. 9, 9, 9, 9, 9,10,10, 9,10,10,10,10,10, 9, 9, 9,
  138621. 9, 9, 9, 9, 9, 9, 9, 9,10, 9,10,10,10,10,10,10,
  138622. 10,10, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10,10,
  138623. 10,10,10,10,10,10,10, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  138624. 9, 9,10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9,
  138625. 9, 9, 9, 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,
  138626. 10, 9, 9, 9, 9, 9, 9, 9,10, 9,10,10,10,10,10,10,
  138627. 10,10,10,10,10,10, 9, 9, 9, 9, 9, 9, 9, 9,10,10,
  138628. 10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9, 9,
  138629. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  138630. 9, 9, 9, 9,10, 9, 9,10,10,10,10,10,10,10,10,10,
  138631. 10,10,10,10,10, 9, 9, 9,10, 9,10, 9,10,10,10,10,
  138632. 10,10,10,10,10,10,10,10,10,10, 9, 9, 9,10, 9,10,
  138633. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10, 9,
  138634. 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,10,10,10,
  138635. 10,10,10,10, 9, 9, 9,10,10,10,10,10,10,10,10,10,
  138636. 10,10,10,10,10,10,10,10,10,
  138637. };
  138638. static float _vq_quantthresh__44u9_p8_1[] = {
  138639. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  138640. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  138641. 6.5, 7.5, 8.5, 9.5,
  138642. };
  138643. static long _vq_quantmap__44u9_p8_1[] = {
  138644. 19, 17, 15, 13, 11, 9, 7, 5,
  138645. 3, 1, 0, 2, 4, 6, 8, 10,
  138646. 12, 14, 16, 18, 20,
  138647. };
  138648. static encode_aux_threshmatch _vq_auxt__44u9_p8_1 = {
  138649. _vq_quantthresh__44u9_p8_1,
  138650. _vq_quantmap__44u9_p8_1,
  138651. 21,
  138652. 21
  138653. };
  138654. static static_codebook _44u9_p8_1 = {
  138655. 2, 441,
  138656. _vq_lengthlist__44u9_p8_1,
  138657. 1, -529268736, 1611661312, 5, 0,
  138658. _vq_quantlist__44u9_p8_1,
  138659. NULL,
  138660. &_vq_auxt__44u9_p8_1,
  138661. NULL,
  138662. 0
  138663. };
  138664. static long _vq_quantlist__44u9_p9_0[] = {
  138665. 7,
  138666. 6,
  138667. 8,
  138668. 5,
  138669. 9,
  138670. 4,
  138671. 10,
  138672. 3,
  138673. 11,
  138674. 2,
  138675. 12,
  138676. 1,
  138677. 13,
  138678. 0,
  138679. 14,
  138680. };
  138681. static long _vq_lengthlist__44u9_p9_0[] = {
  138682. 1, 3, 3,11,11,11,11,11,11,11,11,11,11,11,11, 4,
  138683. 10,11,11,11,11,11,11,11,11,11,11,11,11,11, 4,10,
  138684. 10,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138685. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138686. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138687. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138688. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138689. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138690. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138691. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138692. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138693. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138694. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  138695. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  138696. 10,
  138697. };
  138698. static float _vq_quantthresh__44u9_p9_0[] = {
  138699. -6051.5, -5120.5, -4189.5, -3258.5, -2327.5, -1396.5, -465.5, 465.5,
  138700. 1396.5, 2327.5, 3258.5, 4189.5, 5120.5, 6051.5,
  138701. };
  138702. static long _vq_quantmap__44u9_p9_0[] = {
  138703. 13, 11, 9, 7, 5, 3, 1, 0,
  138704. 2, 4, 6, 8, 10, 12, 14,
  138705. };
  138706. static encode_aux_threshmatch _vq_auxt__44u9_p9_0 = {
  138707. _vq_quantthresh__44u9_p9_0,
  138708. _vq_quantmap__44u9_p9_0,
  138709. 15,
  138710. 15
  138711. };
  138712. static static_codebook _44u9_p9_0 = {
  138713. 2, 225,
  138714. _vq_lengthlist__44u9_p9_0,
  138715. 1, -510036736, 1631393792, 4, 0,
  138716. _vq_quantlist__44u9_p9_0,
  138717. NULL,
  138718. &_vq_auxt__44u9_p9_0,
  138719. NULL,
  138720. 0
  138721. };
  138722. static long _vq_quantlist__44u9_p9_1[] = {
  138723. 9,
  138724. 8,
  138725. 10,
  138726. 7,
  138727. 11,
  138728. 6,
  138729. 12,
  138730. 5,
  138731. 13,
  138732. 4,
  138733. 14,
  138734. 3,
  138735. 15,
  138736. 2,
  138737. 16,
  138738. 1,
  138739. 17,
  138740. 0,
  138741. 18,
  138742. };
  138743. static long _vq_lengthlist__44u9_p9_1[] = {
  138744. 1, 4, 4, 7, 7, 8, 7, 8, 7, 9, 8,10, 9,10,10,11,
  138745. 11,12,12, 4, 7, 6, 9, 9,10, 9, 9, 8,10,10,11,10,
  138746. 12,10,13,12,13,12, 4, 6, 6, 9, 9, 9, 9, 9, 9,10,
  138747. 10,11,11,11,12,12,12,12,12, 7, 9, 8,11,10,10,10,
  138748. 11,10,11,11,12,12,13,12,13,13,13,13, 7, 8, 9,10,
  138749. 10,11,11,10,10,11,11,11,12,13,13,13,13,14,14, 8,
  138750. 9, 9,11,11,12,11,12,12,13,12,12,13,13,14,15,14,
  138751. 14,14, 8, 9, 9,10,11,11,11,12,12,13,12,13,13,14,
  138752. 14,14,15,14,16, 8, 9, 9,11,10,12,12,12,12,15,13,
  138753. 13,13,17,14,15,15,15,14, 8, 9, 9,10,11,11,12,13,
  138754. 12,13,13,13,14,15,14,14,14,16,15, 9,11,10,12,12,
  138755. 13,13,13,13,14,14,16,15,14,14,14,15,15,17, 9,10,
  138756. 10,11,11,13,13,13,14,14,13,15,14,15,14,15,16,15,
  138757. 16,10,11,11,12,12,13,14,15,14,15,14,14,15,17,16,
  138758. 15,15,17,17,10,12,11,13,12,14,14,13,14,15,15,15,
  138759. 15,16,17,17,15,17,16,11,12,12,14,13,15,14,15,16,
  138760. 17,15,17,15,17,15,15,16,17,15,11,11,12,14,14,14,
  138761. 14,14,15,15,16,15,17,17,17,16,17,16,15,12,12,13,
  138762. 14,14,14,15,14,15,15,16,16,17,16,17,15,17,17,16,
  138763. 12,14,12,14,14,15,15,15,14,14,16,16,16,15,16,16,
  138764. 15,17,15,12,13,13,14,15,14,15,17,15,17,16,17,17,
  138765. 17,16,17,16,17,17,12,13,13,14,16,15,15,15,16,15,
  138766. 17,17,15,17,15,17,16,16,17,
  138767. };
  138768. static float _vq_quantthresh__44u9_p9_1[] = {
  138769. -416.5, -367.5, -318.5, -269.5, -220.5, -171.5, -122.5, -73.5,
  138770. -24.5, 24.5, 73.5, 122.5, 171.5, 220.5, 269.5, 318.5,
  138771. 367.5, 416.5,
  138772. };
  138773. static long _vq_quantmap__44u9_p9_1[] = {
  138774. 17, 15, 13, 11, 9, 7, 5, 3,
  138775. 1, 0, 2, 4, 6, 8, 10, 12,
  138776. 14, 16, 18,
  138777. };
  138778. static encode_aux_threshmatch _vq_auxt__44u9_p9_1 = {
  138779. _vq_quantthresh__44u9_p9_1,
  138780. _vq_quantmap__44u9_p9_1,
  138781. 19,
  138782. 19
  138783. };
  138784. static static_codebook _44u9_p9_1 = {
  138785. 2, 361,
  138786. _vq_lengthlist__44u9_p9_1,
  138787. 1, -518287360, 1622704128, 5, 0,
  138788. _vq_quantlist__44u9_p9_1,
  138789. NULL,
  138790. &_vq_auxt__44u9_p9_1,
  138791. NULL,
  138792. 0
  138793. };
  138794. static long _vq_quantlist__44u9_p9_2[] = {
  138795. 24,
  138796. 23,
  138797. 25,
  138798. 22,
  138799. 26,
  138800. 21,
  138801. 27,
  138802. 20,
  138803. 28,
  138804. 19,
  138805. 29,
  138806. 18,
  138807. 30,
  138808. 17,
  138809. 31,
  138810. 16,
  138811. 32,
  138812. 15,
  138813. 33,
  138814. 14,
  138815. 34,
  138816. 13,
  138817. 35,
  138818. 12,
  138819. 36,
  138820. 11,
  138821. 37,
  138822. 10,
  138823. 38,
  138824. 9,
  138825. 39,
  138826. 8,
  138827. 40,
  138828. 7,
  138829. 41,
  138830. 6,
  138831. 42,
  138832. 5,
  138833. 43,
  138834. 4,
  138835. 44,
  138836. 3,
  138837. 45,
  138838. 2,
  138839. 46,
  138840. 1,
  138841. 47,
  138842. 0,
  138843. 48,
  138844. };
  138845. static long _vq_lengthlist__44u9_p9_2[] = {
  138846. 2, 4, 4, 5, 4, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6,
  138847. 6, 6, 6, 7, 6, 7, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  138848. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  138849. 7,
  138850. };
  138851. static float _vq_quantthresh__44u9_p9_2[] = {
  138852. -23.5, -22.5, -21.5, -20.5, -19.5, -18.5, -17.5, -16.5,
  138853. -15.5, -14.5, -13.5, -12.5, -11.5, -10.5, -9.5, -8.5,
  138854. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  138855. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  138856. 8.5, 9.5, 10.5, 11.5, 12.5, 13.5, 14.5, 15.5,
  138857. 16.5, 17.5, 18.5, 19.5, 20.5, 21.5, 22.5, 23.5,
  138858. };
  138859. static long _vq_quantmap__44u9_p9_2[] = {
  138860. 47, 45, 43, 41, 39, 37, 35, 33,
  138861. 31, 29, 27, 25, 23, 21, 19, 17,
  138862. 15, 13, 11, 9, 7, 5, 3, 1,
  138863. 0, 2, 4, 6, 8, 10, 12, 14,
  138864. 16, 18, 20, 22, 24, 26, 28, 30,
  138865. 32, 34, 36, 38, 40, 42, 44, 46,
  138866. 48,
  138867. };
  138868. static encode_aux_threshmatch _vq_auxt__44u9_p9_2 = {
  138869. _vq_quantthresh__44u9_p9_2,
  138870. _vq_quantmap__44u9_p9_2,
  138871. 49,
  138872. 49
  138873. };
  138874. static static_codebook _44u9_p9_2 = {
  138875. 1, 49,
  138876. _vq_lengthlist__44u9_p9_2,
  138877. 1, -526909440, 1611661312, 6, 0,
  138878. _vq_quantlist__44u9_p9_2,
  138879. NULL,
  138880. &_vq_auxt__44u9_p9_2,
  138881. NULL,
  138882. 0
  138883. };
  138884. static long _huff_lengthlist__44un1__long[] = {
  138885. 5, 6,12, 9,14, 9, 9,19, 6, 1, 5, 5, 8, 7, 9,19,
  138886. 12, 4, 4, 7, 7, 9,11,18, 9, 5, 6, 6, 8, 7, 8,17,
  138887. 14, 8, 7, 8, 8,10,12,18, 9, 6, 8, 6, 8, 6, 8,18,
  138888. 9, 8,11, 8,11, 7, 5,15,16,18,18,18,17,15,11,18,
  138889. };
  138890. static static_codebook _huff_book__44un1__long = {
  138891. 2, 64,
  138892. _huff_lengthlist__44un1__long,
  138893. 0, 0, 0, 0, 0,
  138894. NULL,
  138895. NULL,
  138896. NULL,
  138897. NULL,
  138898. 0
  138899. };
  138900. static long _vq_quantlist__44un1__p1_0[] = {
  138901. 1,
  138902. 0,
  138903. 2,
  138904. };
  138905. static long _vq_lengthlist__44un1__p1_0[] = {
  138906. 1, 4, 4, 5, 8, 7, 5, 7, 8, 5, 8, 8, 8,10,11, 8,
  138907. 10,11, 5, 8, 8, 8,11,10, 8,11,10, 4, 9, 9, 8,11,
  138908. 11, 8,11,11, 8,12,11,10,12,14,11,13,13, 7,11,11,
  138909. 10,13,11,11,13,14, 4, 8, 9, 8,11,11, 8,11,12, 7,
  138910. 11,11,11,14,13,10,11,13, 8,11,12,11,13,13,10,14,
  138911. 12,
  138912. };
  138913. static float _vq_quantthresh__44un1__p1_0[] = {
  138914. -0.5, 0.5,
  138915. };
  138916. static long _vq_quantmap__44un1__p1_0[] = {
  138917. 1, 0, 2,
  138918. };
  138919. static encode_aux_threshmatch _vq_auxt__44un1__p1_0 = {
  138920. _vq_quantthresh__44un1__p1_0,
  138921. _vq_quantmap__44un1__p1_0,
  138922. 3,
  138923. 3
  138924. };
  138925. static static_codebook _44un1__p1_0 = {
  138926. 4, 81,
  138927. _vq_lengthlist__44un1__p1_0,
  138928. 1, -535822336, 1611661312, 2, 0,
  138929. _vq_quantlist__44un1__p1_0,
  138930. NULL,
  138931. &_vq_auxt__44un1__p1_0,
  138932. NULL,
  138933. 0
  138934. };
  138935. static long _vq_quantlist__44un1__p2_0[] = {
  138936. 1,
  138937. 0,
  138938. 2,
  138939. };
  138940. static long _vq_lengthlist__44un1__p2_0[] = {
  138941. 2, 4, 4, 5, 6, 6, 5, 6, 6, 5, 7, 7, 7, 8, 8, 6,
  138942. 7, 9, 5, 7, 7, 6, 8, 7, 7, 9, 8, 4, 7, 7, 7, 9,
  138943. 8, 7, 8, 8, 7, 9, 8, 8, 8,10, 9,10,10, 6, 8, 8,
  138944. 7,10, 8, 9,10,10, 5, 7, 7, 7, 8, 8, 7, 8, 9, 6,
  138945. 8, 8, 9,10,10, 7, 8,10, 6, 8, 9, 9,10,10, 8,10,
  138946. 8,
  138947. };
  138948. static float _vq_quantthresh__44un1__p2_0[] = {
  138949. -0.5, 0.5,
  138950. };
  138951. static long _vq_quantmap__44un1__p2_0[] = {
  138952. 1, 0, 2,
  138953. };
  138954. static encode_aux_threshmatch _vq_auxt__44un1__p2_0 = {
  138955. _vq_quantthresh__44un1__p2_0,
  138956. _vq_quantmap__44un1__p2_0,
  138957. 3,
  138958. 3
  138959. };
  138960. static static_codebook _44un1__p2_0 = {
  138961. 4, 81,
  138962. _vq_lengthlist__44un1__p2_0,
  138963. 1, -535822336, 1611661312, 2, 0,
  138964. _vq_quantlist__44un1__p2_0,
  138965. NULL,
  138966. &_vq_auxt__44un1__p2_0,
  138967. NULL,
  138968. 0
  138969. };
  138970. static long _vq_quantlist__44un1__p3_0[] = {
  138971. 2,
  138972. 1,
  138973. 3,
  138974. 0,
  138975. 4,
  138976. };
  138977. static long _vq_lengthlist__44un1__p3_0[] = {
  138978. 1, 5, 5, 8, 8, 5, 8, 7, 9, 9, 5, 7, 8, 9, 9, 9,
  138979. 10, 9,12,12, 9, 9,10,11,12, 6, 8, 8,10,10, 8,10,
  138980. 10,11,11, 8, 9,10,11,11,10,11,11,13,13,10,11,11,
  138981. 12,13, 6, 8, 8,10,10, 8,10, 9,11,11, 8,10,10,11,
  138982. 11,10,11,11,13,12,10,11,11,13,12, 9,11,11,15,13,
  138983. 10,12,11,15,13,10,11,11,15,14,12,14,13,16,15,12,
  138984. 13,13,17,16, 9,11,11,13,15,10,11,12,14,15,10,11,
  138985. 12,14,15,12,13,13,15,16,12,13,13,16,16, 5, 8, 8,
  138986. 11,11, 8,10,10,12,12, 8,10,10,12,12,11,12,12,14,
  138987. 14,11,12,12,14,14, 8,11,10,13,12,10,11,12,12,13,
  138988. 10,12,12,13,13,12,12,13,13,15,11,12,13,15,14, 7,
  138989. 10,10,12,12, 9,12,11,13,12,10,12,12,13,14,12,13,
  138990. 12,15,13,11,13,12,14,15,10,12,12,16,14,11,12,12,
  138991. 16,15,11,13,12,17,16,13,13,15,15,17,13,15,15,20,
  138992. 17,10,12,12,14,16,11,12,12,15,15,11,13,13,15,18,
  138993. 13,14,13,15,15,13,15,14,16,16, 5, 8, 8,11,11, 8,
  138994. 10,10,12,12, 8,10,10,12,12,11,12,12,14,14,11,12,
  138995. 12,14,15, 7,10,10,13,12,10,12,12,14,13, 9,10,12,
  138996. 12,13,11,13,13,15,15,11,12,13,13,15, 8,10,10,12,
  138997. 13,10,12,12,13,13,10,12,11,13,13,11,13,12,15,15,
  138998. 12,13,12,15,13,10,12,12,16,14,11,12,12,16,15,10,
  138999. 12,12,16,14,14,15,14,18,16,13,13,14,15,16,10,12,
  139000. 12,14,16,11,13,13,16,16,11,13,12,14,16,13,15,15,
  139001. 18,18,13,15,13,16,14, 8,11,11,16,16,10,13,13,17,
  139002. 16,10,12,12,16,15,14,16,15,20,17,13,14,14,17,17,
  139003. 9,12,12,16,16,11,13,14,16,17,11,13,13,16,16,15,
  139004. 15,19,18, 0,14,15,15,18,18, 9,12,12,17,16,11,13,
  139005. 12,17,16,11,12,13,15,17,15,16,15, 0,19,14,15,14,
  139006. 19,18,12,14,14, 0,16,13,14,14,19,18,13,15,16,17,
  139007. 16,15,15,17,18, 0,14,16,16,19, 0,12,14,14,16,18,
  139008. 13,15,13,17,18,13,15,14,17,18,15,18,14,18,18,16,
  139009. 17,16, 0,17, 8,11,11,15,15,10,12,12,16,16,10,13,
  139010. 13,16,16,13,15,14,17,17,14,15,17,17,18, 9,12,12,
  139011. 16,15,11,13,13,16,16,11,12,13,17,17,14,14,15,17,
  139012. 17,14,15,16, 0,18, 9,12,12,16,17,11,13,13,16,17,
  139013. 11,14,13,18,17,14,16,14,17,17,15,17,17,18,18,12,
  139014. 14,14, 0,16,13,15,15,19, 0,12,13,15, 0, 0,14,17,
  139015. 16,19, 0,16,15,18,18, 0,12,14,14,17, 0,13,14,14,
  139016. 17, 0,13,15,14, 0,18,15,16,16, 0,18,15,18,15, 0,
  139017. 17,
  139018. };
  139019. static float _vq_quantthresh__44un1__p3_0[] = {
  139020. -1.5, -0.5, 0.5, 1.5,
  139021. };
  139022. static long _vq_quantmap__44un1__p3_0[] = {
  139023. 3, 1, 0, 2, 4,
  139024. };
  139025. static encode_aux_threshmatch _vq_auxt__44un1__p3_0 = {
  139026. _vq_quantthresh__44un1__p3_0,
  139027. _vq_quantmap__44un1__p3_0,
  139028. 5,
  139029. 5
  139030. };
  139031. static static_codebook _44un1__p3_0 = {
  139032. 4, 625,
  139033. _vq_lengthlist__44un1__p3_0,
  139034. 1, -533725184, 1611661312, 3, 0,
  139035. _vq_quantlist__44un1__p3_0,
  139036. NULL,
  139037. &_vq_auxt__44un1__p3_0,
  139038. NULL,
  139039. 0
  139040. };
  139041. static long _vq_quantlist__44un1__p4_0[] = {
  139042. 2,
  139043. 1,
  139044. 3,
  139045. 0,
  139046. 4,
  139047. };
  139048. static long _vq_lengthlist__44un1__p4_0[] = {
  139049. 3, 5, 5, 9, 9, 5, 6, 6,10, 9, 5, 6, 6, 9,10,10,
  139050. 10,10,12,11, 9,10,10,12,12, 5, 7, 7,10,10, 7, 7,
  139051. 8,10,11, 7, 7, 8,10,11,10,10,11,11,13,10,10,11,
  139052. 11,13, 6, 7, 7,10,10, 7, 8, 7,11,10, 7, 8, 7,10,
  139053. 10,10,11, 9,13,11,10,11,10,13,11,10,10,10,14,13,
  139054. 10,11,11,14,13,10,10,11,13,14,12,12,13,15,15,12,
  139055. 12,13,13,14,10,10,10,12,13,10,11,10,13,13,10,11,
  139056. 11,13,13,12,13,12,14,13,12,13,13,14,13, 5, 7, 7,
  139057. 10,10, 7, 8, 8,11,10, 7, 8, 8,10,10,11,11,11,13,
  139058. 13,10,11,11,12,12, 7, 8, 8,11,11, 7, 8, 9,10,12,
  139059. 8, 9, 9,11,11,11,10,12,11,14,11,11,12,13,13, 6,
  139060. 8, 8,10,11, 7, 9, 7,12,10, 8, 9,10,11,12,10,12,
  139061. 10,14,11,11,12,11,13,13,10,11,11,14,14,10,10,11,
  139062. 13,14,11,12,12,15,13,12,11,14,12,16,12,13,14,15,
  139063. 16,10,10,11,13,14,10,11,10,14,12,11,12,12,13,14,
  139064. 12,13,11,15,12,14,14,14,15,15, 5, 7, 7,10,10, 7,
  139065. 8, 8,10,10, 7, 8, 8,10,11,10,11,10,12,12,10,11,
  139066. 11,12,13, 6, 8, 8,11,11, 8, 9, 9,12,11, 7, 7, 9,
  139067. 10,12,11,11,11,12,13,11,10,12,11,15, 7, 8, 8,11,
  139068. 11, 8, 9, 9,11,11, 7, 9, 8,12,10,11,12,11,13,12,
  139069. 11,12,10,15,11,10,11,10,14,12,11,12,11,14,13,10,
  139070. 10,11,13,14,13,13,13,17,15,12,11,14,12,15,10,10,
  139071. 11,13,14,11,12,12,14,14,10,11,10,14,13,13,14,13,
  139072. 16,17,12,14,11,16,12, 9,10,10,14,13,10,11,10,14,
  139073. 14,10,11,11,13,13,13,14,14,16,15,12,13,13,14,14,
  139074. 9,11,10,14,13,10,10,12,13,14,11,12,11,14,13,13,
  139075. 14,14,14,15,13,14,14,15,15, 9,10,11,13,14,10,11,
  139076. 10,15,13,11,11,12,12,15,13,14,12,15,14,13,13,14,
  139077. 14,15,12,13,12,16,14,11,11,12,15,14,13,15,13,16,
  139078. 14,13,12,15,12,17,15,16,15,16,16,12,12,13,13,15,
  139079. 11,13,11,15,14,13,13,14,15,17,13,14,12, 0,13,14,
  139080. 15,14,15, 0, 9,10,10,13,13,10,11,11,13,13,10,11,
  139081. 11,13,13,12,13,12,14,14,13,14,14,15,17, 9,10,10,
  139082. 13,13,11,12,11,15,12,10,10,11,13,16,13,14,13,15,
  139083. 14,13,13,14,15,16,10,10,11,13,14,11,11,12,13,14,
  139084. 10,12,11,14,14,13,13,13,14,15,13,15,13,16,15,12,
  139085. 13,12,15,13,12,15,13,15,15,11,11,13,14,15,15,15,
  139086. 15,15,17,13,12,14,13,17,12,12,14,14,15,13,13,14,
  139087. 14,16,11,13,11,16,15,14,16,16,17, 0,14,13,11,16,
  139088. 12,
  139089. };
  139090. static float _vq_quantthresh__44un1__p4_0[] = {
  139091. -1.5, -0.5, 0.5, 1.5,
  139092. };
  139093. static long _vq_quantmap__44un1__p4_0[] = {
  139094. 3, 1, 0, 2, 4,
  139095. };
  139096. static encode_aux_threshmatch _vq_auxt__44un1__p4_0 = {
  139097. _vq_quantthresh__44un1__p4_0,
  139098. _vq_quantmap__44un1__p4_0,
  139099. 5,
  139100. 5
  139101. };
  139102. static static_codebook _44un1__p4_0 = {
  139103. 4, 625,
  139104. _vq_lengthlist__44un1__p4_0,
  139105. 1, -533725184, 1611661312, 3, 0,
  139106. _vq_quantlist__44un1__p4_0,
  139107. NULL,
  139108. &_vq_auxt__44un1__p4_0,
  139109. NULL,
  139110. 0
  139111. };
  139112. static long _vq_quantlist__44un1__p5_0[] = {
  139113. 4,
  139114. 3,
  139115. 5,
  139116. 2,
  139117. 6,
  139118. 1,
  139119. 7,
  139120. 0,
  139121. 8,
  139122. };
  139123. static long _vq_lengthlist__44un1__p5_0[] = {
  139124. 1, 4, 4, 7, 7, 8, 8, 9, 9, 4, 6, 5, 8, 7, 8, 8,
  139125. 10, 9, 4, 6, 6, 8, 8, 8, 8,10,10, 7, 8, 7, 9, 9,
  139126. 9, 9,11,10, 7, 8, 8, 9, 9, 9, 9,10,11, 8, 8, 8,
  139127. 9, 9,10,10,11,11, 8, 8, 8, 9, 9,10,10,11,11, 9,
  139128. 10,10,11,10,11,11,12,12, 9,10,10,10,11,11,11,12,
  139129. 12,
  139130. };
  139131. static float _vq_quantthresh__44un1__p5_0[] = {
  139132. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  139133. };
  139134. static long _vq_quantmap__44un1__p5_0[] = {
  139135. 7, 5, 3, 1, 0, 2, 4, 6,
  139136. 8,
  139137. };
  139138. static encode_aux_threshmatch _vq_auxt__44un1__p5_0 = {
  139139. _vq_quantthresh__44un1__p5_0,
  139140. _vq_quantmap__44un1__p5_0,
  139141. 9,
  139142. 9
  139143. };
  139144. static static_codebook _44un1__p5_0 = {
  139145. 2, 81,
  139146. _vq_lengthlist__44un1__p5_0,
  139147. 1, -531628032, 1611661312, 4, 0,
  139148. _vq_quantlist__44un1__p5_0,
  139149. NULL,
  139150. &_vq_auxt__44un1__p5_0,
  139151. NULL,
  139152. 0
  139153. };
  139154. static long _vq_quantlist__44un1__p6_0[] = {
  139155. 6,
  139156. 5,
  139157. 7,
  139158. 4,
  139159. 8,
  139160. 3,
  139161. 9,
  139162. 2,
  139163. 10,
  139164. 1,
  139165. 11,
  139166. 0,
  139167. 12,
  139168. };
  139169. static long _vq_lengthlist__44un1__p6_0[] = {
  139170. 1, 4, 4, 6, 6, 8, 8,10,10,11,11,15,15, 4, 5, 5,
  139171. 8, 8, 9, 9,11,11,12,12,16,16, 4, 5, 6, 8, 8, 9,
  139172. 9,11,11,12,12,14,14, 7, 8, 8, 9, 9,10,10,11,12,
  139173. 13,13,16,17, 7, 8, 8, 9, 9,10,10,12,12,12,13,15,
  139174. 15, 9,10,10,10,10,11,11,12,12,13,13,15,16, 9, 9,
  139175. 9,10,10,11,11,13,12,13,13,17,17,10,11,11,11,12,
  139176. 12,12,13,13,14,15, 0,18,10,11,11,12,12,12,13,14,
  139177. 13,14,14,17,16,11,12,12,13,13,14,14,14,14,15,16,
  139178. 17,16,11,12,12,13,13,14,14,14,14,15,15,17,17,14,
  139179. 15,15,16,16,16,17,17,16, 0,17, 0,18,14,15,15,16,
  139180. 16, 0,15,18,18, 0,16, 0, 0,
  139181. };
  139182. static float _vq_quantthresh__44un1__p6_0[] = {
  139183. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  139184. 12.5, 17.5, 22.5, 27.5,
  139185. };
  139186. static long _vq_quantmap__44un1__p6_0[] = {
  139187. 11, 9, 7, 5, 3, 1, 0, 2,
  139188. 4, 6, 8, 10, 12,
  139189. };
  139190. static encode_aux_threshmatch _vq_auxt__44un1__p6_0 = {
  139191. _vq_quantthresh__44un1__p6_0,
  139192. _vq_quantmap__44un1__p6_0,
  139193. 13,
  139194. 13
  139195. };
  139196. static static_codebook _44un1__p6_0 = {
  139197. 2, 169,
  139198. _vq_lengthlist__44un1__p6_0,
  139199. 1, -526516224, 1616117760, 4, 0,
  139200. _vq_quantlist__44un1__p6_0,
  139201. NULL,
  139202. &_vq_auxt__44un1__p6_0,
  139203. NULL,
  139204. 0
  139205. };
  139206. static long _vq_quantlist__44un1__p6_1[] = {
  139207. 2,
  139208. 1,
  139209. 3,
  139210. 0,
  139211. 4,
  139212. };
  139213. static long _vq_lengthlist__44un1__p6_1[] = {
  139214. 2, 4, 4, 5, 5, 4, 5, 5, 5, 5, 4, 5, 5, 6, 5, 5,
  139215. 6, 5, 6, 6, 5, 6, 6, 6, 6,
  139216. };
  139217. static float _vq_quantthresh__44un1__p6_1[] = {
  139218. -1.5, -0.5, 0.5, 1.5,
  139219. };
  139220. static long _vq_quantmap__44un1__p6_1[] = {
  139221. 3, 1, 0, 2, 4,
  139222. };
  139223. static encode_aux_threshmatch _vq_auxt__44un1__p6_1 = {
  139224. _vq_quantthresh__44un1__p6_1,
  139225. _vq_quantmap__44un1__p6_1,
  139226. 5,
  139227. 5
  139228. };
  139229. static static_codebook _44un1__p6_1 = {
  139230. 2, 25,
  139231. _vq_lengthlist__44un1__p6_1,
  139232. 1, -533725184, 1611661312, 3, 0,
  139233. _vq_quantlist__44un1__p6_1,
  139234. NULL,
  139235. &_vq_auxt__44un1__p6_1,
  139236. NULL,
  139237. 0
  139238. };
  139239. static long _vq_quantlist__44un1__p7_0[] = {
  139240. 2,
  139241. 1,
  139242. 3,
  139243. 0,
  139244. 4,
  139245. };
  139246. static long _vq_lengthlist__44un1__p7_0[] = {
  139247. 1, 5, 3,11,11,11,11,11,11,11, 8,11,11,11,11,11,
  139248. 11,11,11,11,11,11,11,11,11,10,11,11,11,11,11,11,
  139249. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  139250. 11,11,10,11,11,11,11,11,11,11,11,11,11,11,11,11,
  139251. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  139252. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  139253. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  139254. 11,11,11,11,11,11,11,11,11,11,11,11,11, 8,11,11,
  139255. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  139256. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  139257. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,10,
  139258. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  139259. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  139260. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  139261. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  139262. 11,11,11,11,11,11,11,11,11,11, 7,11,11,11,11,11,
  139263. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  139264. 11,11,11,10,11,11,11,11,11,11,11,11,11,11,11,11,
  139265. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  139266. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  139267. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  139268. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  139269. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  139270. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  139271. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  139272. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  139273. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  139274. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  139275. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  139276. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  139277. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  139278. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  139279. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  139280. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  139281. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  139282. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  139283. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  139284. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  139285. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  139286. 10,
  139287. };
  139288. static float _vq_quantthresh__44un1__p7_0[] = {
  139289. -253.5, -84.5, 84.5, 253.5,
  139290. };
  139291. static long _vq_quantmap__44un1__p7_0[] = {
  139292. 3, 1, 0, 2, 4,
  139293. };
  139294. static encode_aux_threshmatch _vq_auxt__44un1__p7_0 = {
  139295. _vq_quantthresh__44un1__p7_0,
  139296. _vq_quantmap__44un1__p7_0,
  139297. 5,
  139298. 5
  139299. };
  139300. static static_codebook _44un1__p7_0 = {
  139301. 4, 625,
  139302. _vq_lengthlist__44un1__p7_0,
  139303. 1, -518709248, 1626677248, 3, 0,
  139304. _vq_quantlist__44un1__p7_0,
  139305. NULL,
  139306. &_vq_auxt__44un1__p7_0,
  139307. NULL,
  139308. 0
  139309. };
  139310. static long _vq_quantlist__44un1__p7_1[] = {
  139311. 6,
  139312. 5,
  139313. 7,
  139314. 4,
  139315. 8,
  139316. 3,
  139317. 9,
  139318. 2,
  139319. 10,
  139320. 1,
  139321. 11,
  139322. 0,
  139323. 12,
  139324. };
  139325. static long _vq_lengthlist__44un1__p7_1[] = {
  139326. 1, 4, 4, 6, 6, 6, 6, 9, 8, 9, 8, 8, 8, 5, 7, 7,
  139327. 7, 7, 8, 8, 8,10, 8,10, 8, 9, 5, 7, 7, 8, 7, 7,
  139328. 8,10,10,11,10,12,11, 7, 8, 8, 9, 9, 9,10,11,11,
  139329. 11,11,11,11, 7, 8, 8, 8, 9, 9, 9,10,10,10,11,11,
  139330. 12, 7, 8, 8, 9, 9,10,11,11,12,11,12,11,11, 7, 8,
  139331. 8, 9, 9,10,10,11,11,11,12,12,11, 8,10,10,10,10,
  139332. 11,11,14,11,12,12,12,13, 9,10,10,10,10,12,11,14,
  139333. 11,14,11,12,13,10,11,11,11,11,13,11,14,14,13,13,
  139334. 13,14,11,11,11,12,11,12,12,12,13,14,14,13,14,12,
  139335. 11,12,12,12,12,13,13,13,14,13,14,14,11,12,12,14,
  139336. 12,13,13,12,13,13,14,14,14,
  139337. };
  139338. static float _vq_quantthresh__44un1__p7_1[] = {
  139339. -71.5, -58.5, -45.5, -32.5, -19.5, -6.5, 6.5, 19.5,
  139340. 32.5, 45.5, 58.5, 71.5,
  139341. };
  139342. static long _vq_quantmap__44un1__p7_1[] = {
  139343. 11, 9, 7, 5, 3, 1, 0, 2,
  139344. 4, 6, 8, 10, 12,
  139345. };
  139346. static encode_aux_threshmatch _vq_auxt__44un1__p7_1 = {
  139347. _vq_quantthresh__44un1__p7_1,
  139348. _vq_quantmap__44un1__p7_1,
  139349. 13,
  139350. 13
  139351. };
  139352. static static_codebook _44un1__p7_1 = {
  139353. 2, 169,
  139354. _vq_lengthlist__44un1__p7_1,
  139355. 1, -523010048, 1618608128, 4, 0,
  139356. _vq_quantlist__44un1__p7_1,
  139357. NULL,
  139358. &_vq_auxt__44un1__p7_1,
  139359. NULL,
  139360. 0
  139361. };
  139362. static long _vq_quantlist__44un1__p7_2[] = {
  139363. 6,
  139364. 5,
  139365. 7,
  139366. 4,
  139367. 8,
  139368. 3,
  139369. 9,
  139370. 2,
  139371. 10,
  139372. 1,
  139373. 11,
  139374. 0,
  139375. 12,
  139376. };
  139377. static long _vq_lengthlist__44un1__p7_2[] = {
  139378. 3, 4, 4, 6, 6, 7, 7, 8, 8, 9, 9, 9, 8, 4, 5, 5,
  139379. 6, 6, 8, 8, 9, 8, 9, 9, 9, 9, 4, 5, 5, 7, 6, 8,
  139380. 8, 8, 8, 9, 8, 9, 8, 6, 7, 7, 7, 8, 8, 8, 9, 9,
  139381. 9, 9, 9, 9, 6, 7, 7, 7, 7, 8, 8, 9, 9, 9, 9, 9,
  139382. 9, 7, 8, 8, 8, 8, 9, 8, 9, 9,10, 9, 9,10, 7, 8,
  139383. 8, 8, 8, 9, 9, 9, 9, 9, 9,10,10, 8, 9, 9, 9, 9,
  139384. 9, 9, 9, 9,10,10, 9,10, 8, 9, 9, 9, 9, 9, 9, 9,
  139385. 9, 9, 9,10,10, 9, 9, 9,10, 9, 9,10, 9, 9,10,10,
  139386. 10,10, 9, 9, 9, 9, 9, 9, 9,10, 9,10,10,10,10, 9,
  139387. 9, 9,10, 9, 9,10,10, 9,10,10,10,10, 9, 9, 9,10,
  139388. 9, 9, 9,10,10,10,10,10,10,
  139389. };
  139390. static float _vq_quantthresh__44un1__p7_2[] = {
  139391. -5.5, -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5,
  139392. 2.5, 3.5, 4.5, 5.5,
  139393. };
  139394. static long _vq_quantmap__44un1__p7_2[] = {
  139395. 11, 9, 7, 5, 3, 1, 0, 2,
  139396. 4, 6, 8, 10, 12,
  139397. };
  139398. static encode_aux_threshmatch _vq_auxt__44un1__p7_2 = {
  139399. _vq_quantthresh__44un1__p7_2,
  139400. _vq_quantmap__44un1__p7_2,
  139401. 13,
  139402. 13
  139403. };
  139404. static static_codebook _44un1__p7_2 = {
  139405. 2, 169,
  139406. _vq_lengthlist__44un1__p7_2,
  139407. 1, -531103744, 1611661312, 4, 0,
  139408. _vq_quantlist__44un1__p7_2,
  139409. NULL,
  139410. &_vq_auxt__44un1__p7_2,
  139411. NULL,
  139412. 0
  139413. };
  139414. static long _huff_lengthlist__44un1__short[] = {
  139415. 12,12,14,12,14,14,14,14,12, 6, 6, 8, 9, 9,11,14,
  139416. 12, 4, 2, 6, 6, 7,11,14,13, 6, 5, 7, 8, 9,11,14,
  139417. 13, 8, 5, 8, 6, 8,12,14,12, 7, 7, 8, 8, 8,10,14,
  139418. 12, 6, 3, 4, 4, 4, 7,14,11, 7, 4, 6, 6, 6, 8,14,
  139419. };
  139420. static static_codebook _huff_book__44un1__short = {
  139421. 2, 64,
  139422. _huff_lengthlist__44un1__short,
  139423. 0, 0, 0, 0, 0,
  139424. NULL,
  139425. NULL,
  139426. NULL,
  139427. NULL,
  139428. 0
  139429. };
  139430. /********* End of inlined file: res_books_uncoupled.h *********/
  139431. static vorbis_info_residue0 _residue_44_low_un={
  139432. 0,-1, -1, 8,-1,
  139433. {0},
  139434. {-1},
  139435. { .5, 1.5, 1.5, 2.5, 2.5, 4.5, 28.5},
  139436. { -1, 25, -1, 45, -1, -1, -1}
  139437. };
  139438. static vorbis_info_residue0 _residue_44_mid_un={
  139439. 0,-1, -1, 10,-1,
  139440. {0},
  139441. {-1},
  139442. { .5, 1.5, 1.5, 2.5, 2.5, 4.5, 4.5, 16.5, 60.5},
  139443. { -1, 30, -1, 50, -1, 80, -1, -1, -1}
  139444. };
  139445. static vorbis_info_residue0 _residue_44_hi_un={
  139446. 0,-1, -1, 10,-1,
  139447. {0},
  139448. {-1},
  139449. { .5, 1.5, 2.5, 4.5, 8.5, 16.5, 32.5, 71.5,157.5},
  139450. { -1, -1, -1, -1, -1, -1, -1, -1, -1}
  139451. };
  139452. static vorbis_info_mapping0 _map_nominal_u[2]={
  139453. {1, {0,0}, {0}, {0}, 0,{0},{0}},
  139454. {1, {0,0}, {1}, {1}, 0,{0},{0}}
  139455. };
  139456. static static_bookblock _resbook_44u_n1={
  139457. {
  139458. {0},
  139459. {0,0,&_44un1__p1_0},
  139460. {0,0,&_44un1__p2_0},
  139461. {0,0,&_44un1__p3_0},
  139462. {0,0,&_44un1__p4_0},
  139463. {0,0,&_44un1__p5_0},
  139464. {&_44un1__p6_0,&_44un1__p6_1},
  139465. {&_44un1__p7_0,&_44un1__p7_1,&_44un1__p7_2}
  139466. }
  139467. };
  139468. static static_bookblock _resbook_44u_0={
  139469. {
  139470. {0},
  139471. {0,0,&_44u0__p1_0},
  139472. {0,0,&_44u0__p2_0},
  139473. {0,0,&_44u0__p3_0},
  139474. {0,0,&_44u0__p4_0},
  139475. {0,0,&_44u0__p5_0},
  139476. {&_44u0__p6_0,&_44u0__p6_1},
  139477. {&_44u0__p7_0,&_44u0__p7_1,&_44u0__p7_2}
  139478. }
  139479. };
  139480. static static_bookblock _resbook_44u_1={
  139481. {
  139482. {0},
  139483. {0,0,&_44u1__p1_0},
  139484. {0,0,&_44u1__p2_0},
  139485. {0,0,&_44u1__p3_0},
  139486. {0,0,&_44u1__p4_0},
  139487. {0,0,&_44u1__p5_0},
  139488. {&_44u1__p6_0,&_44u1__p6_1},
  139489. {&_44u1__p7_0,&_44u1__p7_1,&_44u1__p7_2}
  139490. }
  139491. };
  139492. static static_bookblock _resbook_44u_2={
  139493. {
  139494. {0},
  139495. {0,0,&_44u2__p1_0},
  139496. {0,0,&_44u2__p2_0},
  139497. {0,0,&_44u2__p3_0},
  139498. {0,0,&_44u2__p4_0},
  139499. {0,0,&_44u2__p5_0},
  139500. {&_44u2__p6_0,&_44u2__p6_1},
  139501. {&_44u2__p7_0,&_44u2__p7_1,&_44u2__p7_2}
  139502. }
  139503. };
  139504. static static_bookblock _resbook_44u_3={
  139505. {
  139506. {0},
  139507. {0,0,&_44u3__p1_0},
  139508. {0,0,&_44u3__p2_0},
  139509. {0,0,&_44u3__p3_0},
  139510. {0,0,&_44u3__p4_0},
  139511. {0,0,&_44u3__p5_0},
  139512. {&_44u3__p6_0,&_44u3__p6_1},
  139513. {&_44u3__p7_0,&_44u3__p7_1,&_44u3__p7_2}
  139514. }
  139515. };
  139516. static static_bookblock _resbook_44u_4={
  139517. {
  139518. {0},
  139519. {0,0,&_44u4__p1_0},
  139520. {0,0,&_44u4__p2_0},
  139521. {0,0,&_44u4__p3_0},
  139522. {0,0,&_44u4__p4_0},
  139523. {0,0,&_44u4__p5_0},
  139524. {&_44u4__p6_0,&_44u4__p6_1},
  139525. {&_44u4__p7_0,&_44u4__p7_1,&_44u4__p7_2}
  139526. }
  139527. };
  139528. static static_bookblock _resbook_44u_5={
  139529. {
  139530. {0},
  139531. {0,0,&_44u5__p1_0},
  139532. {0,0,&_44u5__p2_0},
  139533. {0,0,&_44u5__p3_0},
  139534. {0,0,&_44u5__p4_0},
  139535. {0,0,&_44u5__p5_0},
  139536. {0,0,&_44u5__p6_0},
  139537. {&_44u5__p7_0,&_44u5__p7_1},
  139538. {&_44u5__p8_0,&_44u5__p8_1},
  139539. {&_44u5__p9_0,&_44u5__p9_1,&_44u5__p9_2}
  139540. }
  139541. };
  139542. static static_bookblock _resbook_44u_6={
  139543. {
  139544. {0},
  139545. {0,0,&_44u6__p1_0},
  139546. {0,0,&_44u6__p2_0},
  139547. {0,0,&_44u6__p3_0},
  139548. {0,0,&_44u6__p4_0},
  139549. {0,0,&_44u6__p5_0},
  139550. {0,0,&_44u6__p6_0},
  139551. {&_44u6__p7_0,&_44u6__p7_1},
  139552. {&_44u6__p8_0,&_44u6__p8_1},
  139553. {&_44u6__p9_0,&_44u6__p9_1,&_44u6__p9_2}
  139554. }
  139555. };
  139556. static static_bookblock _resbook_44u_7={
  139557. {
  139558. {0},
  139559. {0,0,&_44u7__p1_0},
  139560. {0,0,&_44u7__p2_0},
  139561. {0,0,&_44u7__p3_0},
  139562. {0,0,&_44u7__p4_0},
  139563. {0,0,&_44u7__p5_0},
  139564. {0,0,&_44u7__p6_0},
  139565. {&_44u7__p7_0,&_44u7__p7_1},
  139566. {&_44u7__p8_0,&_44u7__p8_1},
  139567. {&_44u7__p9_0,&_44u7__p9_1,&_44u7__p9_2}
  139568. }
  139569. };
  139570. static static_bookblock _resbook_44u_8={
  139571. {
  139572. {0},
  139573. {0,0,&_44u8_p1_0},
  139574. {0,0,&_44u8_p2_0},
  139575. {0,0,&_44u8_p3_0},
  139576. {0,0,&_44u8_p4_0},
  139577. {&_44u8_p5_0,&_44u8_p5_1},
  139578. {&_44u8_p6_0,&_44u8_p6_1},
  139579. {&_44u8_p7_0,&_44u8_p7_1},
  139580. {&_44u8_p8_0,&_44u8_p8_1},
  139581. {&_44u8_p9_0,&_44u8_p9_1,&_44u8_p9_2}
  139582. }
  139583. };
  139584. static static_bookblock _resbook_44u_9={
  139585. {
  139586. {0},
  139587. {0,0,&_44u9_p1_0},
  139588. {0,0,&_44u9_p2_0},
  139589. {0,0,&_44u9_p3_0},
  139590. {0,0,&_44u9_p4_0},
  139591. {&_44u9_p5_0,&_44u9_p5_1},
  139592. {&_44u9_p6_0,&_44u9_p6_1},
  139593. {&_44u9_p7_0,&_44u9_p7_1},
  139594. {&_44u9_p8_0,&_44u9_p8_1},
  139595. {&_44u9_p9_0,&_44u9_p9_1,&_44u9_p9_2}
  139596. }
  139597. };
  139598. static vorbis_residue_template _res_44u_n1[]={
  139599. {1,0, &_residue_44_low_un,
  139600. &_huff_book__44un1__short,&_huff_book__44un1__short,
  139601. &_resbook_44u_n1,&_resbook_44u_n1},
  139602. {1,0, &_residue_44_low_un,
  139603. &_huff_book__44un1__long,&_huff_book__44un1__long,
  139604. &_resbook_44u_n1,&_resbook_44u_n1}
  139605. };
  139606. static vorbis_residue_template _res_44u_0[]={
  139607. {1,0, &_residue_44_low_un,
  139608. &_huff_book__44u0__short,&_huff_book__44u0__short,
  139609. &_resbook_44u_0,&_resbook_44u_0},
  139610. {1,0, &_residue_44_low_un,
  139611. &_huff_book__44u0__long,&_huff_book__44u0__long,
  139612. &_resbook_44u_0,&_resbook_44u_0}
  139613. };
  139614. static vorbis_residue_template _res_44u_1[]={
  139615. {1,0, &_residue_44_low_un,
  139616. &_huff_book__44u1__short,&_huff_book__44u1__short,
  139617. &_resbook_44u_1,&_resbook_44u_1},
  139618. {1,0, &_residue_44_low_un,
  139619. &_huff_book__44u1__long,&_huff_book__44u1__long,
  139620. &_resbook_44u_1,&_resbook_44u_1}
  139621. };
  139622. static vorbis_residue_template _res_44u_2[]={
  139623. {1,0, &_residue_44_low_un,
  139624. &_huff_book__44u2__short,&_huff_book__44u2__short,
  139625. &_resbook_44u_2,&_resbook_44u_2},
  139626. {1,0, &_residue_44_low_un,
  139627. &_huff_book__44u2__long,&_huff_book__44u2__long,
  139628. &_resbook_44u_2,&_resbook_44u_2}
  139629. };
  139630. static vorbis_residue_template _res_44u_3[]={
  139631. {1,0, &_residue_44_low_un,
  139632. &_huff_book__44u3__short,&_huff_book__44u3__short,
  139633. &_resbook_44u_3,&_resbook_44u_3},
  139634. {1,0, &_residue_44_low_un,
  139635. &_huff_book__44u3__long,&_huff_book__44u3__long,
  139636. &_resbook_44u_3,&_resbook_44u_3}
  139637. };
  139638. static vorbis_residue_template _res_44u_4[]={
  139639. {1,0, &_residue_44_low_un,
  139640. &_huff_book__44u4__short,&_huff_book__44u4__short,
  139641. &_resbook_44u_4,&_resbook_44u_4},
  139642. {1,0, &_residue_44_low_un,
  139643. &_huff_book__44u4__long,&_huff_book__44u4__long,
  139644. &_resbook_44u_4,&_resbook_44u_4}
  139645. };
  139646. static vorbis_residue_template _res_44u_5[]={
  139647. {1,0, &_residue_44_mid_un,
  139648. &_huff_book__44u5__short,&_huff_book__44u5__short,
  139649. &_resbook_44u_5,&_resbook_44u_5},
  139650. {1,0, &_residue_44_mid_un,
  139651. &_huff_book__44u5__long,&_huff_book__44u5__long,
  139652. &_resbook_44u_5,&_resbook_44u_5}
  139653. };
  139654. static vorbis_residue_template _res_44u_6[]={
  139655. {1,0, &_residue_44_mid_un,
  139656. &_huff_book__44u6__short,&_huff_book__44u6__short,
  139657. &_resbook_44u_6,&_resbook_44u_6},
  139658. {1,0, &_residue_44_mid_un,
  139659. &_huff_book__44u6__long,&_huff_book__44u6__long,
  139660. &_resbook_44u_6,&_resbook_44u_6}
  139661. };
  139662. static vorbis_residue_template _res_44u_7[]={
  139663. {1,0, &_residue_44_mid_un,
  139664. &_huff_book__44u7__short,&_huff_book__44u7__short,
  139665. &_resbook_44u_7,&_resbook_44u_7},
  139666. {1,0, &_residue_44_mid_un,
  139667. &_huff_book__44u7__long,&_huff_book__44u7__long,
  139668. &_resbook_44u_7,&_resbook_44u_7}
  139669. };
  139670. static vorbis_residue_template _res_44u_8[]={
  139671. {1,0, &_residue_44_hi_un,
  139672. &_huff_book__44u8__short,&_huff_book__44u8__short,
  139673. &_resbook_44u_8,&_resbook_44u_8},
  139674. {1,0, &_residue_44_hi_un,
  139675. &_huff_book__44u8__long,&_huff_book__44u8__long,
  139676. &_resbook_44u_8,&_resbook_44u_8}
  139677. };
  139678. static vorbis_residue_template _res_44u_9[]={
  139679. {1,0, &_residue_44_hi_un,
  139680. &_huff_book__44u9__short,&_huff_book__44u9__short,
  139681. &_resbook_44u_9,&_resbook_44u_9},
  139682. {1,0, &_residue_44_hi_un,
  139683. &_huff_book__44u9__long,&_huff_book__44u9__long,
  139684. &_resbook_44u_9,&_resbook_44u_9}
  139685. };
  139686. static vorbis_mapping_template _mapres_template_44_uncoupled[]={
  139687. { _map_nominal_u, _res_44u_n1 }, /* -1 */
  139688. { _map_nominal_u, _res_44u_0 }, /* 0 */
  139689. { _map_nominal_u, _res_44u_1 }, /* 1 */
  139690. { _map_nominal_u, _res_44u_2 }, /* 2 */
  139691. { _map_nominal_u, _res_44u_3 }, /* 3 */
  139692. { _map_nominal_u, _res_44u_4 }, /* 4 */
  139693. { _map_nominal_u, _res_44u_5 }, /* 5 */
  139694. { _map_nominal_u, _res_44u_6 }, /* 6 */
  139695. { _map_nominal_u, _res_44u_7 }, /* 7 */
  139696. { _map_nominal_u, _res_44u_8 }, /* 8 */
  139697. { _map_nominal_u, _res_44u_9 }, /* 9 */
  139698. };
  139699. /********* End of inlined file: residue_44u.h *********/
  139700. static double rate_mapping_44_un[12]={
  139701. 32000.,48000.,60000.,70000.,80000.,86000.,
  139702. 96000.,110000.,120000.,140000.,160000.,240001.
  139703. };
  139704. ve_setup_data_template ve_setup_44_uncoupled={
  139705. 11,
  139706. rate_mapping_44_un,
  139707. quality_mapping_44,
  139708. -1,
  139709. 40000,
  139710. 50000,
  139711. blocksize_short_44,
  139712. blocksize_long_44,
  139713. _psy_tone_masteratt_44,
  139714. _psy_tone_0dB,
  139715. _psy_tone_suppress,
  139716. _vp_tonemask_adj_otherblock,
  139717. _vp_tonemask_adj_longblock,
  139718. _vp_tonemask_adj_otherblock,
  139719. _psy_noiseguards_44,
  139720. _psy_noisebias_impulse,
  139721. _psy_noisebias_padding,
  139722. _psy_noisebias_trans,
  139723. _psy_noisebias_long,
  139724. _psy_noise_suppress,
  139725. _psy_compand_44,
  139726. _psy_compand_short_mapping,
  139727. _psy_compand_long_mapping,
  139728. {_noise_start_short_44,_noise_start_long_44},
  139729. {_noise_part_short_44,_noise_part_long_44},
  139730. _noise_thresh_44,
  139731. _psy_ath_floater,
  139732. _psy_ath_abs,
  139733. _psy_lowpass_44,
  139734. _psy_global_44,
  139735. _global_mapping_44,
  139736. NULL,
  139737. _floor_books,
  139738. _floor,
  139739. _floor_short_mapping_44,
  139740. _floor_long_mapping_44,
  139741. _mapres_template_44_uncoupled
  139742. };
  139743. /********* End of inlined file: setup_44u.h *********/
  139744. /********* Start of inlined file: setup_32.h *********/
  139745. static double rate_mapping_32[12]={
  139746. 18000.,28000.,35000.,45000.,56000.,60000.,
  139747. 75000.,90000.,100000.,115000.,150000.,190000.,
  139748. };
  139749. static double rate_mapping_32_un[12]={
  139750. 30000.,42000.,52000.,64000.,72000.,78000.,
  139751. 86000.,92000.,110000.,120000.,140000.,190000.,
  139752. };
  139753. static double _psy_lowpass_32[12]={
  139754. 12.3,13.,13.,14.,15.,99.,99.,99.,99.,99.,99.,99.
  139755. };
  139756. ve_setup_data_template ve_setup_32_stereo={
  139757. 11,
  139758. rate_mapping_32,
  139759. quality_mapping_44,
  139760. 2,
  139761. 26000,
  139762. 40000,
  139763. blocksize_short_44,
  139764. blocksize_long_44,
  139765. _psy_tone_masteratt_44,
  139766. _psy_tone_0dB,
  139767. _psy_tone_suppress,
  139768. _vp_tonemask_adj_otherblock,
  139769. _vp_tonemask_adj_longblock,
  139770. _vp_tonemask_adj_otherblock,
  139771. _psy_noiseguards_44,
  139772. _psy_noisebias_impulse,
  139773. _psy_noisebias_padding,
  139774. _psy_noisebias_trans,
  139775. _psy_noisebias_long,
  139776. _psy_noise_suppress,
  139777. _psy_compand_44,
  139778. _psy_compand_short_mapping,
  139779. _psy_compand_long_mapping,
  139780. {_noise_start_short_44,_noise_start_long_44},
  139781. {_noise_part_short_44,_noise_part_long_44},
  139782. _noise_thresh_44,
  139783. _psy_ath_floater,
  139784. _psy_ath_abs,
  139785. _psy_lowpass_32,
  139786. _psy_global_44,
  139787. _global_mapping_44,
  139788. _psy_stereo_modes_44,
  139789. _floor_books,
  139790. _floor,
  139791. _floor_short_mapping_44,
  139792. _floor_long_mapping_44,
  139793. _mapres_template_44_stereo
  139794. };
  139795. ve_setup_data_template ve_setup_32_uncoupled={
  139796. 11,
  139797. rate_mapping_32_un,
  139798. quality_mapping_44,
  139799. -1,
  139800. 26000,
  139801. 40000,
  139802. blocksize_short_44,
  139803. blocksize_long_44,
  139804. _psy_tone_masteratt_44,
  139805. _psy_tone_0dB,
  139806. _psy_tone_suppress,
  139807. _vp_tonemask_adj_otherblock,
  139808. _vp_tonemask_adj_longblock,
  139809. _vp_tonemask_adj_otherblock,
  139810. _psy_noiseguards_44,
  139811. _psy_noisebias_impulse,
  139812. _psy_noisebias_padding,
  139813. _psy_noisebias_trans,
  139814. _psy_noisebias_long,
  139815. _psy_noise_suppress,
  139816. _psy_compand_44,
  139817. _psy_compand_short_mapping,
  139818. _psy_compand_long_mapping,
  139819. {_noise_start_short_44,_noise_start_long_44},
  139820. {_noise_part_short_44,_noise_part_long_44},
  139821. _noise_thresh_44,
  139822. _psy_ath_floater,
  139823. _psy_ath_abs,
  139824. _psy_lowpass_32,
  139825. _psy_global_44,
  139826. _global_mapping_44,
  139827. NULL,
  139828. _floor_books,
  139829. _floor,
  139830. _floor_short_mapping_44,
  139831. _floor_long_mapping_44,
  139832. _mapres_template_44_uncoupled
  139833. };
  139834. /********* End of inlined file: setup_32.h *********/
  139835. /********* Start of inlined file: setup_8.h *********/
  139836. /********* Start of inlined file: psych_8.h *********/
  139837. static att3 _psy_tone_masteratt_8[3]={
  139838. {{ 32, 25, 12}, 0, 0}, /* 0 */
  139839. {{ 30, 25, 12}, 0, 0}, /* 0 */
  139840. {{ 20, 0, -14}, 0, 0}, /* 0 */
  139841. };
  139842. static vp_adjblock _vp_tonemask_adj_8[3]={
  139843. {{-15,-15,-15,-15,-10,-10, -6, 0, 0, 0, 0,10, 0, 0,99,99,99}}, /* 1 */
  139844. {{-15,-15,-15,-15,-10,-10, -6, 0, 0, 0, 0,10, 0, 0,99,99,99}}, /* 1 */
  139845. {{-15,-15,-15,-15,-10,-10, -6, 0, 0, 0, 0, 0, 0, 0,99,99,99}}, /* 1 */
  139846. };
  139847. static noise3 _psy_noisebias_8[3]={
  139848. {{{-10,-10,-10,-10, -5, -5, -5, 0, 4, 8, 8, 8, 10, 10, 99, 99, 99},
  139849. {-10,-10,-10,-10, -5, -5, -5, 0, 0, 4, 4, 4, 4, 4, 99, 99, 99},
  139850. {-30,-30,-30,-30,-30,-24,-20,-14,-10, -6, -8, -8, -6, -6, 99, 99, 99}}},
  139851. {{{-10,-10,-10,-10, -5, -5, -5, 0, 4, 8, 8, 8, 10, 10, 99, 99, 99},
  139852. {-10,-10,-10,-10,-10,-10, -5, -5, -5, 0, 0, 0, 0, 0, 99, 99, 99},
  139853. {-30,-30,-30,-30,-30,-24,-20,-14,-10, -6, -8, -8, -6, -6, 99, 99, 99}}},
  139854. {{{-15,-15,-15,-15,-15,-12,-10, -8, 0, 2, 4, 4, 5, 5, 99, 99, 99},
  139855. {-30,-30,-30,-30,-26,-22,-20,-14,-12,-12,-10,-10,-10,-10, 99, 99, 99},
  139856. {-30,-30,-30,-30,-26,-26,-26,-26,-26,-26,-26,-26,-26,-24, 99, 99, 99}}},
  139857. };
  139858. static adj_stereo _psy_stereo_modes_8[3]={
  139859. {{ 4, 4, 4, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3},
  139860. { 6, 5, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4},
  139861. { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
  139862. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  139863. {{ 4, 4, 4, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3},
  139864. { 6, 5, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4},
  139865. { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
  139866. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  139867. {{ 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3},
  139868. { 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4},
  139869. { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
  139870. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  139871. };
  139872. static noiseguard _psy_noiseguards_8[2]={
  139873. {10,10,-1},
  139874. {10,10,-1},
  139875. };
  139876. static compandblock _psy_compand_8[2]={
  139877. {{
  139878. 0, 1, 2, 3, 4, 5, 6, 7, /* 7dB */
  139879. 8, 8, 9, 9,10,10,11, 11, /* 15dB */
  139880. 12,12,13,13,14,14,15, 15, /* 23dB */
  139881. 16,16,17,17,17,18,18, 19, /* 31dB */
  139882. 19,19,20,21,22,23,24, 25, /* 39dB */
  139883. }},
  139884. {{
  139885. 0, 1, 2, 3, 4, 5, 6, 6, /* 7dB */
  139886. 7, 7, 6, 6, 5, 5, 4, 4, /* 15dB */
  139887. 3, 3, 3, 4, 5, 6, 7, 8, /* 23dB */
  139888. 9,10,11,12,13,14,15, 16, /* 31dB */
  139889. 17,18,19,20,21,22,23, 24, /* 39dB */
  139890. }},
  139891. };
  139892. static double _psy_lowpass_8[3]={3.,4.,4.};
  139893. static int _noise_start_8[2]={
  139894. 64,64,
  139895. };
  139896. static int _noise_part_8[2]={
  139897. 8,8,
  139898. };
  139899. static int _psy_ath_floater_8[3]={
  139900. -100,-100,-105,
  139901. };
  139902. static int _psy_ath_abs_8[3]={
  139903. -130,-130,-140,
  139904. };
  139905. /********* End of inlined file: psych_8.h *********/
  139906. /********* Start of inlined file: residue_8.h *********/
  139907. static static_bookblock _resbook_8s_0={
  139908. {
  139909. {0},{0,0,&_8c0_s_p1_0},{0,0,&_8c0_s_p2_0},{0,0,&_8c0_s_p3_0},
  139910. {0,0,&_8c0_s_p4_0},{0,0,&_8c0_s_p5_0},{0,0,&_8c0_s_p6_0},
  139911. {&_8c0_s_p7_0,&_8c0_s_p7_1},{&_8c0_s_p8_0,&_8c0_s_p8_1},
  139912. {&_8c0_s_p9_0,&_8c0_s_p9_1,&_8c0_s_p9_2}
  139913. }
  139914. };
  139915. static static_bookblock _resbook_8s_1={
  139916. {
  139917. {0},{0,0,&_8c1_s_p1_0},{0,0,&_8c1_s_p2_0},{0,0,&_8c1_s_p3_0},
  139918. {0,0,&_8c1_s_p4_0},{0,0,&_8c1_s_p5_0},{0,0,&_8c1_s_p6_0},
  139919. {&_8c1_s_p7_0,&_8c1_s_p7_1},{&_8c1_s_p8_0,&_8c1_s_p8_1},
  139920. {&_8c1_s_p9_0,&_8c1_s_p9_1,&_8c1_s_p9_2}
  139921. }
  139922. };
  139923. static vorbis_residue_template _res_8s_0[]={
  139924. {2,0, &_residue_44_mid,
  139925. &_huff_book__8c0_s_single,&_huff_book__8c0_s_single,
  139926. &_resbook_8s_0,&_resbook_8s_0},
  139927. };
  139928. static vorbis_residue_template _res_8s_1[]={
  139929. {2,0, &_residue_44_mid,
  139930. &_huff_book__8c1_s_single,&_huff_book__8c1_s_single,
  139931. &_resbook_8s_1,&_resbook_8s_1},
  139932. };
  139933. static vorbis_mapping_template _mapres_template_8_stereo[2]={
  139934. { _map_nominal, _res_8s_0 }, /* 0 */
  139935. { _map_nominal, _res_8s_1 }, /* 1 */
  139936. };
  139937. static static_bookblock _resbook_8u_0={
  139938. {
  139939. {0},
  139940. {0,0,&_8u0__p1_0},
  139941. {0,0,&_8u0__p2_0},
  139942. {0,0,&_8u0__p3_0},
  139943. {0,0,&_8u0__p4_0},
  139944. {0,0,&_8u0__p5_0},
  139945. {&_8u0__p6_0,&_8u0__p6_1},
  139946. {&_8u0__p7_0,&_8u0__p7_1,&_8u0__p7_2}
  139947. }
  139948. };
  139949. static static_bookblock _resbook_8u_1={
  139950. {
  139951. {0},
  139952. {0,0,&_8u1__p1_0},
  139953. {0,0,&_8u1__p2_0},
  139954. {0,0,&_8u1__p3_0},
  139955. {0,0,&_8u1__p4_0},
  139956. {0,0,&_8u1__p5_0},
  139957. {0,0,&_8u1__p6_0},
  139958. {&_8u1__p7_0,&_8u1__p7_1},
  139959. {&_8u1__p8_0,&_8u1__p8_1},
  139960. {&_8u1__p9_0,&_8u1__p9_1,&_8u1__p9_2}
  139961. }
  139962. };
  139963. static vorbis_residue_template _res_8u_0[]={
  139964. {1,0, &_residue_44_low_un,
  139965. &_huff_book__8u0__single,&_huff_book__8u0__single,
  139966. &_resbook_8u_0,&_resbook_8u_0},
  139967. };
  139968. static vorbis_residue_template _res_8u_1[]={
  139969. {1,0, &_residue_44_mid_un,
  139970. &_huff_book__8u1__single,&_huff_book__8u1__single,
  139971. &_resbook_8u_1,&_resbook_8u_1},
  139972. };
  139973. static vorbis_mapping_template _mapres_template_8_uncoupled[2]={
  139974. { _map_nominal_u, _res_8u_0 }, /* 0 */
  139975. { _map_nominal_u, _res_8u_1 }, /* 1 */
  139976. };
  139977. /********* End of inlined file: residue_8.h *********/
  139978. static int blocksize_8[2]={
  139979. 512,512
  139980. };
  139981. static int _floor_mapping_8[2]={
  139982. 6,6,
  139983. };
  139984. static double rate_mapping_8[3]={
  139985. 6000.,9000.,32000.,
  139986. };
  139987. static double rate_mapping_8_uncoupled[3]={
  139988. 8000.,14000.,42000.,
  139989. };
  139990. static double quality_mapping_8[3]={
  139991. -.1,.0,1.
  139992. };
  139993. static double _psy_compand_8_mapping[3]={ 0., 1., 1.};
  139994. static double _global_mapping_8[3]={ 1., 2., 3. };
  139995. ve_setup_data_template ve_setup_8_stereo={
  139996. 2,
  139997. rate_mapping_8,
  139998. quality_mapping_8,
  139999. 2,
  140000. 8000,
  140001. 9000,
  140002. blocksize_8,
  140003. blocksize_8,
  140004. _psy_tone_masteratt_8,
  140005. _psy_tone_0dB,
  140006. _psy_tone_suppress,
  140007. _vp_tonemask_adj_8,
  140008. NULL,
  140009. _vp_tonemask_adj_8,
  140010. _psy_noiseguards_8,
  140011. _psy_noisebias_8,
  140012. _psy_noisebias_8,
  140013. NULL,
  140014. NULL,
  140015. _psy_noise_suppress,
  140016. _psy_compand_8,
  140017. _psy_compand_8_mapping,
  140018. NULL,
  140019. {_noise_start_8,_noise_start_8},
  140020. {_noise_part_8,_noise_part_8},
  140021. _noise_thresh_5only,
  140022. _psy_ath_floater_8,
  140023. _psy_ath_abs_8,
  140024. _psy_lowpass_8,
  140025. _psy_global_44,
  140026. _global_mapping_8,
  140027. _psy_stereo_modes_8,
  140028. _floor_books,
  140029. _floor,
  140030. _floor_mapping_8,
  140031. NULL,
  140032. _mapres_template_8_stereo
  140033. };
  140034. ve_setup_data_template ve_setup_8_uncoupled={
  140035. 2,
  140036. rate_mapping_8_uncoupled,
  140037. quality_mapping_8,
  140038. -1,
  140039. 8000,
  140040. 9000,
  140041. blocksize_8,
  140042. blocksize_8,
  140043. _psy_tone_masteratt_8,
  140044. _psy_tone_0dB,
  140045. _psy_tone_suppress,
  140046. _vp_tonemask_adj_8,
  140047. NULL,
  140048. _vp_tonemask_adj_8,
  140049. _psy_noiseguards_8,
  140050. _psy_noisebias_8,
  140051. _psy_noisebias_8,
  140052. NULL,
  140053. NULL,
  140054. _psy_noise_suppress,
  140055. _psy_compand_8,
  140056. _psy_compand_8_mapping,
  140057. NULL,
  140058. {_noise_start_8,_noise_start_8},
  140059. {_noise_part_8,_noise_part_8},
  140060. _noise_thresh_5only,
  140061. _psy_ath_floater_8,
  140062. _psy_ath_abs_8,
  140063. _psy_lowpass_8,
  140064. _psy_global_44,
  140065. _global_mapping_8,
  140066. _psy_stereo_modes_8,
  140067. _floor_books,
  140068. _floor,
  140069. _floor_mapping_8,
  140070. NULL,
  140071. _mapres_template_8_uncoupled
  140072. };
  140073. /********* End of inlined file: setup_8.h *********/
  140074. /********* Start of inlined file: setup_11.h *********/
  140075. /********* Start of inlined file: psych_11.h *********/
  140076. static double _psy_lowpass_11[3]={4.5,5.5,30.,};
  140077. static att3 _psy_tone_masteratt_11[3]={
  140078. {{ 30, 25, 12}, 0, 0}, /* 0 */
  140079. {{ 30, 25, 12}, 0, 0}, /* 0 */
  140080. {{ 20, 0, -14}, 0, 0}, /* 0 */
  140081. };
  140082. static vp_adjblock _vp_tonemask_adj_11[3]={
  140083. {{-20,-20,-20,-20,-20,-16,-10, 0, 0, 0, 0,10, 2, 0,99,99,99}}, /* 0 */
  140084. {{-20,-20,-20,-20,-20,-16,-10, 0, 0, 0, 0, 5, 0, 0,99,99,99}}, /* 1 */
  140085. {{-20,-20,-20,-20,-20,-16,-10, 0, 0, 0, 0, 0, 0, 0,99,99,99}}, /* 2 */
  140086. };
  140087. static noise3 _psy_noisebias_11[3]={
  140088. {{{-10,-10,-10,-10, -5, -5, -5, 0, 4, 10, 10, 12, 12, 12, 99, 99, 99},
  140089. {-15,-15,-15,-15,-10,-10, -5, 0, 0, 4, 4, 5, 5, 10, 99, 99, 99},
  140090. {-30,-30,-30,-30,-30,-24,-20,-14,-10, -6, -8, -8, -6, -6, 99, 99, 99}}},
  140091. {{{-10,-10,-10,-10, -5, -5, -5, 0, 4, 10, 10, 12, 12, 12, 99, 99, 99},
  140092. {-15,-15,-15,-15,-10,-10, -5, -5, -5, 0, 0, 0, 0, 0, 99, 99, 99},
  140093. {-30,-30,-30,-30,-30,-24,-20,-14,-10, -6, -8, -8, -6, -6, 99, 99, 99}}},
  140094. {{{-15,-15,-15,-15,-15,-12,-10, -8, 0, 2, 4, 4, 5, 5, 99, 99, 99},
  140095. {-30,-30,-30,-30,-26,-22,-20,-14,-12,-12,-10,-10,-10,-10, 99, 99, 99},
  140096. {-30,-30,-30,-30,-26,-26,-26,-26,-26,-26,-26,-26,-26,-24, 99, 99, 99}}},
  140097. };
  140098. static double _noise_thresh_11[3]={ .3,.5,.5 };
  140099. /********* End of inlined file: psych_11.h *********/
  140100. static int blocksize_11[2]={
  140101. 512,512
  140102. };
  140103. static int _floor_mapping_11[2]={
  140104. 6,6,
  140105. };
  140106. static double rate_mapping_11[3]={
  140107. 8000.,13000.,44000.,
  140108. };
  140109. static double rate_mapping_11_uncoupled[3]={
  140110. 12000.,20000.,50000.,
  140111. };
  140112. static double quality_mapping_11[3]={
  140113. -.1,.0,1.
  140114. };
  140115. ve_setup_data_template ve_setup_11_stereo={
  140116. 2,
  140117. rate_mapping_11,
  140118. quality_mapping_11,
  140119. 2,
  140120. 9000,
  140121. 15000,
  140122. blocksize_11,
  140123. blocksize_11,
  140124. _psy_tone_masteratt_11,
  140125. _psy_tone_0dB,
  140126. _psy_tone_suppress,
  140127. _vp_tonemask_adj_11,
  140128. NULL,
  140129. _vp_tonemask_adj_11,
  140130. _psy_noiseguards_8,
  140131. _psy_noisebias_11,
  140132. _psy_noisebias_11,
  140133. NULL,
  140134. NULL,
  140135. _psy_noise_suppress,
  140136. _psy_compand_8,
  140137. _psy_compand_8_mapping,
  140138. NULL,
  140139. {_noise_start_8,_noise_start_8},
  140140. {_noise_part_8,_noise_part_8},
  140141. _noise_thresh_11,
  140142. _psy_ath_floater_8,
  140143. _psy_ath_abs_8,
  140144. _psy_lowpass_11,
  140145. _psy_global_44,
  140146. _global_mapping_8,
  140147. _psy_stereo_modes_8,
  140148. _floor_books,
  140149. _floor,
  140150. _floor_mapping_11,
  140151. NULL,
  140152. _mapres_template_8_stereo
  140153. };
  140154. ve_setup_data_template ve_setup_11_uncoupled={
  140155. 2,
  140156. rate_mapping_11_uncoupled,
  140157. quality_mapping_11,
  140158. -1,
  140159. 9000,
  140160. 15000,
  140161. blocksize_11,
  140162. blocksize_11,
  140163. _psy_tone_masteratt_11,
  140164. _psy_tone_0dB,
  140165. _psy_tone_suppress,
  140166. _vp_tonemask_adj_11,
  140167. NULL,
  140168. _vp_tonemask_adj_11,
  140169. _psy_noiseguards_8,
  140170. _psy_noisebias_11,
  140171. _psy_noisebias_11,
  140172. NULL,
  140173. NULL,
  140174. _psy_noise_suppress,
  140175. _psy_compand_8,
  140176. _psy_compand_8_mapping,
  140177. NULL,
  140178. {_noise_start_8,_noise_start_8},
  140179. {_noise_part_8,_noise_part_8},
  140180. _noise_thresh_11,
  140181. _psy_ath_floater_8,
  140182. _psy_ath_abs_8,
  140183. _psy_lowpass_11,
  140184. _psy_global_44,
  140185. _global_mapping_8,
  140186. _psy_stereo_modes_8,
  140187. _floor_books,
  140188. _floor,
  140189. _floor_mapping_11,
  140190. NULL,
  140191. _mapres_template_8_uncoupled
  140192. };
  140193. /********* End of inlined file: setup_11.h *********/
  140194. /********* Start of inlined file: setup_16.h *********/
  140195. /********* Start of inlined file: psych_16.h *********/
  140196. static adj_stereo _psy_stereo_modes_16[4]={
  140197. {{ 4, 4, 4, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3},
  140198. { 6, 5, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4},
  140199. { 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 4, 4},
  140200. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  140201. {{ 4, 4, 4, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3},
  140202. { 6, 5, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4},
  140203. { 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 4, 4, 4, 4, 4},
  140204. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  140205. {{ 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3},
  140206. { 5, 4, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3},
  140207. { 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4},
  140208. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  140209. {{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  140210. { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  140211. { 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8},
  140212. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  140213. };
  140214. static double _psy_lowpass_16[4]={6.5,8,30.,99.};
  140215. static att3 _psy_tone_masteratt_16[4]={
  140216. {{ 30, 25, 12}, 0, 0}, /* 0 */
  140217. {{ 25, 22, 12}, 0, 0}, /* 0 */
  140218. {{ 20, 12, 0}, 0, 0}, /* 0 */
  140219. {{ 15, 0, -14}, 0, 0}, /* 0 */
  140220. };
  140221. static vp_adjblock _vp_tonemask_adj_16[4]={
  140222. {{-20,-20,-20,-20,-20,-16,-10, 0, 0, 0, 0,10, 0, 0, 0, 0, 0}}, /* 0 */
  140223. {{-20,-20,-20,-20,-20,-16,-10, 0, 0, 0, 0,10, 0, 0, 0, 0, 0}}, /* 1 */
  140224. {{-20,-20,-20,-20,-20,-16,-10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}}, /* 2 */
  140225. {{-30,-30,-30,-30,-30,-26,-20,-10, -5, 0, 0, 0, 0, 0, 0, 0, 0}}, /* 2 */
  140226. };
  140227. static noise3 _psy_noisebias_16_short[4]={
  140228. {{{-15,-15,-15,-15,-15,-10,-10,-5, 4, 10, 10, 10, 10, 12, 12, 14, 20},
  140229. {-15,-15,-15,-15,-15,-10,-10, -5, 0, 0, 4, 5, 5, 6, 8, 8, 15},
  140230. {-30,-30,-30,-30,-30,-24,-20,-14,-10, -6, -8, -8, -6, -6, -6, -6, -6}}},
  140231. {{{-15,-15,-15,-15,-15,-10,-10,-5, 4, 6, 6, 6, 6, 8, 10, 12, 20},
  140232. {-15,-15,-15,-15,-15,-15,-15,-10, -5, -5, -5, 4, 5, 6, 8, 8, 15},
  140233. {-30,-30,-30,-30,-30,-24,-20,-14,-10,-10,-10,-10,-10,-10,-10,-10,-10}}},
  140234. {{{-15,-15,-15,-15,-15,-12,-10, -8, 0, 2, 4, 4, 5, 5, 5, 8, 12},
  140235. {-20,-20,-20,-20,-16,-12,-20,-14,-10,-10, -8, 0, 0, 0, 0, 2, 5},
  140236. {-30,-30,-30,-30,-26,-26,-26,-26,-26,-26,-26,-26,-26,-24,-20,-20,-20}}},
  140237. {{{-15,-15,-15,-15,-15,-12,-10, -8, -5, -5, -5, -5, -5, 0, 0, 0, 6},
  140238. {-30,-30,-30,-30,-26,-22,-20,-14,-12,-12,-10,-10,-10,-10,-10,-10, -6},
  140239. {-30,-30,-30,-30,-26,-26,-26,-26,-26,-26,-26,-26,-26,-24,-20,-20,-20}}},
  140240. };
  140241. static noise3 _psy_noisebias_16_impulse[4]={
  140242. {{{-15,-15,-15,-15,-15,-10,-10,-5, 4, 10, 10, 10, 10, 12, 12, 14, 20},
  140243. {-15,-15,-15,-15,-15,-10,-10, -5, 0, 0, 4, 5, 5, 6, 8, 8, 15},
  140244. {-30,-30,-30,-30,-30,-24,-20,-14,-10, -6, -8, -8, -6, -6, -6, -6, -6}}},
  140245. {{{-15,-15,-15,-15,-15,-10,-10,-5, 4, 4, 4, 4, 5, 5, 6, 8, 15},
  140246. {-15,-15,-15,-15,-15,-15,-15,-10, -5, -5, -5, 0, 0, 0, 0, 4, 10},
  140247. {-30,-30,-30,-30,-30,-24,-20,-14,-10,-10,-10,-10,-10,-10,-10,-10,-10}}},
  140248. {{{-15,-15,-15,-15,-15,-12,-10, -8, 0, 0, 0, 0, 0, 0, 0, 4, 10},
  140249. {-20,-20,-20,-20,-16,-12,-20,-14,-10,-10,-10,-10,-10,-10,-10, -7, -5},
  140250. {-30,-30,-30,-30,-26,-26,-26,-26,-26,-26,-26,-26,-26,-24,-20,-20,-20}}},
  140251. {{{-15,-15,-15,-15,-15,-12,-10, -8, -5, -5, -5, -5, -5, 0, 0, 0, 6},
  140252. {-30,-30,-30,-30,-26,-22,-20,-18,-18,-18,-20,-20,-20,-20,-20,-20,-16},
  140253. {-30,-30,-30,-30,-26,-26,-26,-26,-26,-26,-26,-26,-26,-24,-20,-20,-20}}},
  140254. };
  140255. static noise3 _psy_noisebias_16[4]={
  140256. {{{-10,-10,-10,-10, -5, -5, -5, 0, 4, 6, 8, 8, 10, 10, 10, 14, 20},
  140257. {-10,-10,-10,-10,-10, -5, -2, -2, 0, 0, 0, 4, 5, 6, 8, 8, 15},
  140258. {-30,-30,-30,-30,-30,-24,-20,-14,-10, -6, -8, -8, -6, -6, -6, -6, -6}}},
  140259. {{{-10,-10,-10,-10, -5, -5, -5, 0, 4, 6, 6, 6, 6, 8, 10, 12, 20},
  140260. {-15,-15,-15,-15,-15,-10, -5, -5, 0, 0, 0, 4, 5, 6, 8, 8, 15},
  140261. {-30,-30,-30,-30,-30,-24,-20,-14,-10, -6, -8, -8, -6, -6, -6, -6, -6}}},
  140262. {{{-15,-15,-15,-15,-15,-12,-10, -8, 0, 2, 4, 4, 5, 5, 5, 8, 12},
  140263. {-20,-20,-20,-20,-16,-12,-20,-10, -5, -5, 0, 0, 0, 0, 0, 2, 5},
  140264. {-30,-30,-30,-30,-26,-26,-26,-26,-26,-26,-26,-26,-26,-24,-20,-20,-20}}},
  140265. {{{-15,-15,-15,-15,-15,-12,-10, -8, -5, -5, -5, -5, -5, 0, 0, 0, 6},
  140266. {-30,-30,-30,-30,-26,-22,-20,-14,-12,-12,-10,-10,-10,-10,-10,-10, -6},
  140267. {-30,-30,-30,-30,-26,-26,-26,-26,-26,-26,-26,-26,-26,-24,-20,-20,-20}}},
  140268. };
  140269. static double _noise_thresh_16[4]={ .3,.5,.5,.5 };
  140270. static int _noise_start_16[3]={ 256,256,9999 };
  140271. static int _noise_part_16[4]={ 8,8,8,8 };
  140272. static int _psy_ath_floater_16[4]={
  140273. -100,-100,-100,-105,
  140274. };
  140275. static int _psy_ath_abs_16[4]={
  140276. -130,-130,-130,-140,
  140277. };
  140278. /********* End of inlined file: psych_16.h *********/
  140279. /********* Start of inlined file: residue_16.h *********/
  140280. static static_bookblock _resbook_16s_0={
  140281. {
  140282. {0},
  140283. {0,0,&_16c0_s_p1_0},
  140284. {0,0,&_16c0_s_p2_0},
  140285. {0,0,&_16c0_s_p3_0},
  140286. {0,0,&_16c0_s_p4_0},
  140287. {0,0,&_16c0_s_p5_0},
  140288. {0,0,&_16c0_s_p6_0},
  140289. {&_16c0_s_p7_0,&_16c0_s_p7_1},
  140290. {&_16c0_s_p8_0,&_16c0_s_p8_1},
  140291. {&_16c0_s_p9_0,&_16c0_s_p9_1,&_16c0_s_p9_2}
  140292. }
  140293. };
  140294. static static_bookblock _resbook_16s_1={
  140295. {
  140296. {0},
  140297. {0,0,&_16c1_s_p1_0},
  140298. {0,0,&_16c1_s_p2_0},
  140299. {0,0,&_16c1_s_p3_0},
  140300. {0,0,&_16c1_s_p4_0},
  140301. {0,0,&_16c1_s_p5_0},
  140302. {0,0,&_16c1_s_p6_0},
  140303. {&_16c1_s_p7_0,&_16c1_s_p7_1},
  140304. {&_16c1_s_p8_0,&_16c1_s_p8_1},
  140305. {&_16c1_s_p9_0,&_16c1_s_p9_1,&_16c1_s_p9_2}
  140306. }
  140307. };
  140308. static static_bookblock _resbook_16s_2={
  140309. {
  140310. {0},
  140311. {0,0,&_16c2_s_p1_0},
  140312. {0,0,&_16c2_s_p2_0},
  140313. {0,0,&_16c2_s_p3_0},
  140314. {0,0,&_16c2_s_p4_0},
  140315. {&_16c2_s_p5_0,&_16c2_s_p5_1},
  140316. {&_16c2_s_p6_0,&_16c2_s_p6_1},
  140317. {&_16c2_s_p7_0,&_16c2_s_p7_1},
  140318. {&_16c2_s_p8_0,&_16c2_s_p8_1},
  140319. {&_16c2_s_p9_0,&_16c2_s_p9_1,&_16c2_s_p9_2}
  140320. }
  140321. };
  140322. static vorbis_residue_template _res_16s_0[]={
  140323. {2,0, &_residue_44_mid,
  140324. &_huff_book__16c0_s_single,&_huff_book__16c0_s_single,
  140325. &_resbook_16s_0,&_resbook_16s_0},
  140326. };
  140327. static vorbis_residue_template _res_16s_1[]={
  140328. {2,0, &_residue_44_mid,
  140329. &_huff_book__16c1_s_short,&_huff_book__16c1_s_short,
  140330. &_resbook_16s_1,&_resbook_16s_1},
  140331. {2,0, &_residue_44_mid,
  140332. &_huff_book__16c1_s_long,&_huff_book__16c1_s_long,
  140333. &_resbook_16s_1,&_resbook_16s_1}
  140334. };
  140335. static vorbis_residue_template _res_16s_2[]={
  140336. {2,0, &_residue_44_high,
  140337. &_huff_book__16c2_s_short,&_huff_book__16c2_s_short,
  140338. &_resbook_16s_2,&_resbook_16s_2},
  140339. {2,0, &_residue_44_high,
  140340. &_huff_book__16c2_s_long,&_huff_book__16c2_s_long,
  140341. &_resbook_16s_2,&_resbook_16s_2}
  140342. };
  140343. static vorbis_mapping_template _mapres_template_16_stereo[3]={
  140344. { _map_nominal, _res_16s_0 }, /* 0 */
  140345. { _map_nominal, _res_16s_1 }, /* 1 */
  140346. { _map_nominal, _res_16s_2 }, /* 2 */
  140347. };
  140348. static static_bookblock _resbook_16u_0={
  140349. {
  140350. {0},
  140351. {0,0,&_16u0__p1_0},
  140352. {0,0,&_16u0__p2_0},
  140353. {0,0,&_16u0__p3_0},
  140354. {0,0,&_16u0__p4_0},
  140355. {0,0,&_16u0__p5_0},
  140356. {&_16u0__p6_0,&_16u0__p6_1},
  140357. {&_16u0__p7_0,&_16u0__p7_1,&_16u0__p7_2}
  140358. }
  140359. };
  140360. static static_bookblock _resbook_16u_1={
  140361. {
  140362. {0},
  140363. {0,0,&_16u1__p1_0},
  140364. {0,0,&_16u1__p2_0},
  140365. {0,0,&_16u1__p3_0},
  140366. {0,0,&_16u1__p4_0},
  140367. {0,0,&_16u1__p5_0},
  140368. {0,0,&_16u1__p6_0},
  140369. {&_16u1__p7_0,&_16u1__p7_1},
  140370. {&_16u1__p8_0,&_16u1__p8_1},
  140371. {&_16u1__p9_0,&_16u1__p9_1,&_16u1__p9_2}
  140372. }
  140373. };
  140374. static static_bookblock _resbook_16u_2={
  140375. {
  140376. {0},
  140377. {0,0,&_16u2_p1_0},
  140378. {0,0,&_16u2_p2_0},
  140379. {0,0,&_16u2_p3_0},
  140380. {0,0,&_16u2_p4_0},
  140381. {&_16u2_p5_0,&_16u2_p5_1},
  140382. {&_16u2_p6_0,&_16u2_p6_1},
  140383. {&_16u2_p7_0,&_16u2_p7_1},
  140384. {&_16u2_p8_0,&_16u2_p8_1},
  140385. {&_16u2_p9_0,&_16u2_p9_1,&_16u2_p9_2}
  140386. }
  140387. };
  140388. static vorbis_residue_template _res_16u_0[]={
  140389. {1,0, &_residue_44_low_un,
  140390. &_huff_book__16u0__single,&_huff_book__16u0__single,
  140391. &_resbook_16u_0,&_resbook_16u_0},
  140392. };
  140393. static vorbis_residue_template _res_16u_1[]={
  140394. {1,0, &_residue_44_mid_un,
  140395. &_huff_book__16u1__short,&_huff_book__16u1__short,
  140396. &_resbook_16u_1,&_resbook_16u_1},
  140397. {1,0, &_residue_44_mid_un,
  140398. &_huff_book__16u1__long,&_huff_book__16u1__long,
  140399. &_resbook_16u_1,&_resbook_16u_1}
  140400. };
  140401. static vorbis_residue_template _res_16u_2[]={
  140402. {1,0, &_residue_44_hi_un,
  140403. &_huff_book__16u2__short,&_huff_book__16u2__short,
  140404. &_resbook_16u_2,&_resbook_16u_2},
  140405. {1,0, &_residue_44_hi_un,
  140406. &_huff_book__16u2__long,&_huff_book__16u2__long,
  140407. &_resbook_16u_2,&_resbook_16u_2}
  140408. };
  140409. static vorbis_mapping_template _mapres_template_16_uncoupled[3]={
  140410. { _map_nominal_u, _res_16u_0 }, /* 0 */
  140411. { _map_nominal_u, _res_16u_1 }, /* 1 */
  140412. { _map_nominal_u, _res_16u_2 }, /* 2 */
  140413. };
  140414. /********* End of inlined file: residue_16.h *********/
  140415. static int blocksize_16_short[3]={
  140416. 1024,512,512
  140417. };
  140418. static int blocksize_16_long[3]={
  140419. 1024,1024,1024
  140420. };
  140421. static int _floor_mapping_16_short[3]={
  140422. 9,3,3
  140423. };
  140424. static int _floor_mapping_16[3]={
  140425. 9,9,9
  140426. };
  140427. static double rate_mapping_16[4]={
  140428. 12000.,20000.,44000.,86000.
  140429. };
  140430. static double rate_mapping_16_uncoupled[4]={
  140431. 16000.,28000.,64000.,100000.
  140432. };
  140433. static double _global_mapping_16[4]={ 1., 2., 3., 4. };
  140434. static double quality_mapping_16[4]={ -.1,.05,.5,1. };
  140435. static double _psy_compand_16_mapping[4]={ 0., .8, 1., 1.};
  140436. ve_setup_data_template ve_setup_16_stereo={
  140437. 3,
  140438. rate_mapping_16,
  140439. quality_mapping_16,
  140440. 2,
  140441. 15000,
  140442. 19000,
  140443. blocksize_16_short,
  140444. blocksize_16_long,
  140445. _psy_tone_masteratt_16,
  140446. _psy_tone_0dB,
  140447. _psy_tone_suppress,
  140448. _vp_tonemask_adj_16,
  140449. _vp_tonemask_adj_16,
  140450. _vp_tonemask_adj_16,
  140451. _psy_noiseguards_8,
  140452. _psy_noisebias_16_impulse,
  140453. _psy_noisebias_16_short,
  140454. _psy_noisebias_16_short,
  140455. _psy_noisebias_16,
  140456. _psy_noise_suppress,
  140457. _psy_compand_8,
  140458. _psy_compand_16_mapping,
  140459. _psy_compand_16_mapping,
  140460. {_noise_start_16,_noise_start_16},
  140461. { _noise_part_16, _noise_part_16},
  140462. _noise_thresh_16,
  140463. _psy_ath_floater_16,
  140464. _psy_ath_abs_16,
  140465. _psy_lowpass_16,
  140466. _psy_global_44,
  140467. _global_mapping_16,
  140468. _psy_stereo_modes_16,
  140469. _floor_books,
  140470. _floor,
  140471. _floor_mapping_16_short,
  140472. _floor_mapping_16,
  140473. _mapres_template_16_stereo
  140474. };
  140475. ve_setup_data_template ve_setup_16_uncoupled={
  140476. 3,
  140477. rate_mapping_16_uncoupled,
  140478. quality_mapping_16,
  140479. -1,
  140480. 15000,
  140481. 19000,
  140482. blocksize_16_short,
  140483. blocksize_16_long,
  140484. _psy_tone_masteratt_16,
  140485. _psy_tone_0dB,
  140486. _psy_tone_suppress,
  140487. _vp_tonemask_adj_16,
  140488. _vp_tonemask_adj_16,
  140489. _vp_tonemask_adj_16,
  140490. _psy_noiseguards_8,
  140491. _psy_noisebias_16_impulse,
  140492. _psy_noisebias_16_short,
  140493. _psy_noisebias_16_short,
  140494. _psy_noisebias_16,
  140495. _psy_noise_suppress,
  140496. _psy_compand_8,
  140497. _psy_compand_16_mapping,
  140498. _psy_compand_16_mapping,
  140499. {_noise_start_16,_noise_start_16},
  140500. { _noise_part_16, _noise_part_16},
  140501. _noise_thresh_16,
  140502. _psy_ath_floater_16,
  140503. _psy_ath_abs_16,
  140504. _psy_lowpass_16,
  140505. _psy_global_44,
  140506. _global_mapping_16,
  140507. _psy_stereo_modes_16,
  140508. _floor_books,
  140509. _floor,
  140510. _floor_mapping_16_short,
  140511. _floor_mapping_16,
  140512. _mapres_template_16_uncoupled
  140513. };
  140514. /********* End of inlined file: setup_16.h *********/
  140515. /********* Start of inlined file: setup_22.h *********/
  140516. static double rate_mapping_22[4]={
  140517. 15000.,20000.,44000.,86000.
  140518. };
  140519. static double rate_mapping_22_uncoupled[4]={
  140520. 16000.,28000.,50000.,90000.
  140521. };
  140522. static double _psy_lowpass_22[4]={9.5,11.,30.,99.};
  140523. ve_setup_data_template ve_setup_22_stereo={
  140524. 3,
  140525. rate_mapping_22,
  140526. quality_mapping_16,
  140527. 2,
  140528. 19000,
  140529. 26000,
  140530. blocksize_16_short,
  140531. blocksize_16_long,
  140532. _psy_tone_masteratt_16,
  140533. _psy_tone_0dB,
  140534. _psy_tone_suppress,
  140535. _vp_tonemask_adj_16,
  140536. _vp_tonemask_adj_16,
  140537. _vp_tonemask_adj_16,
  140538. _psy_noiseguards_8,
  140539. _psy_noisebias_16_impulse,
  140540. _psy_noisebias_16_short,
  140541. _psy_noisebias_16_short,
  140542. _psy_noisebias_16,
  140543. _psy_noise_suppress,
  140544. _psy_compand_8,
  140545. _psy_compand_8_mapping,
  140546. _psy_compand_8_mapping,
  140547. {_noise_start_16,_noise_start_16},
  140548. { _noise_part_16, _noise_part_16},
  140549. _noise_thresh_16,
  140550. _psy_ath_floater_16,
  140551. _psy_ath_abs_16,
  140552. _psy_lowpass_22,
  140553. _psy_global_44,
  140554. _global_mapping_16,
  140555. _psy_stereo_modes_16,
  140556. _floor_books,
  140557. _floor,
  140558. _floor_mapping_16_short,
  140559. _floor_mapping_16,
  140560. _mapres_template_16_stereo
  140561. };
  140562. ve_setup_data_template ve_setup_22_uncoupled={
  140563. 3,
  140564. rate_mapping_22_uncoupled,
  140565. quality_mapping_16,
  140566. -1,
  140567. 19000,
  140568. 26000,
  140569. blocksize_16_short,
  140570. blocksize_16_long,
  140571. _psy_tone_masteratt_16,
  140572. _psy_tone_0dB,
  140573. _psy_tone_suppress,
  140574. _vp_tonemask_adj_16,
  140575. _vp_tonemask_adj_16,
  140576. _vp_tonemask_adj_16,
  140577. _psy_noiseguards_8,
  140578. _psy_noisebias_16_impulse,
  140579. _psy_noisebias_16_short,
  140580. _psy_noisebias_16_short,
  140581. _psy_noisebias_16,
  140582. _psy_noise_suppress,
  140583. _psy_compand_8,
  140584. _psy_compand_8_mapping,
  140585. _psy_compand_8_mapping,
  140586. {_noise_start_16,_noise_start_16},
  140587. { _noise_part_16, _noise_part_16},
  140588. _noise_thresh_16,
  140589. _psy_ath_floater_16,
  140590. _psy_ath_abs_16,
  140591. _psy_lowpass_22,
  140592. _psy_global_44,
  140593. _global_mapping_16,
  140594. _psy_stereo_modes_16,
  140595. _floor_books,
  140596. _floor,
  140597. _floor_mapping_16_short,
  140598. _floor_mapping_16,
  140599. _mapres_template_16_uncoupled
  140600. };
  140601. /********* End of inlined file: setup_22.h *********/
  140602. /********* Start of inlined file: setup_X.h *********/
  140603. static double rate_mapping_X[12]={
  140604. -1.,-1.,-1.,-1.,-1.,-1.,
  140605. -1.,-1.,-1.,-1.,-1.,-1.
  140606. };
  140607. ve_setup_data_template ve_setup_X_stereo={
  140608. 11,
  140609. rate_mapping_X,
  140610. quality_mapping_44,
  140611. 2,
  140612. 50000,
  140613. 200000,
  140614. blocksize_short_44,
  140615. blocksize_long_44,
  140616. _psy_tone_masteratt_44,
  140617. _psy_tone_0dB,
  140618. _psy_tone_suppress,
  140619. _vp_tonemask_adj_otherblock,
  140620. _vp_tonemask_adj_longblock,
  140621. _vp_tonemask_adj_otherblock,
  140622. _psy_noiseguards_44,
  140623. _psy_noisebias_impulse,
  140624. _psy_noisebias_padding,
  140625. _psy_noisebias_trans,
  140626. _psy_noisebias_long,
  140627. _psy_noise_suppress,
  140628. _psy_compand_44,
  140629. _psy_compand_short_mapping,
  140630. _psy_compand_long_mapping,
  140631. {_noise_start_short_44,_noise_start_long_44},
  140632. {_noise_part_short_44,_noise_part_long_44},
  140633. _noise_thresh_44,
  140634. _psy_ath_floater,
  140635. _psy_ath_abs,
  140636. _psy_lowpass_44,
  140637. _psy_global_44,
  140638. _global_mapping_44,
  140639. _psy_stereo_modes_44,
  140640. _floor_books,
  140641. _floor,
  140642. _floor_short_mapping_44,
  140643. _floor_long_mapping_44,
  140644. _mapres_template_44_stereo
  140645. };
  140646. ve_setup_data_template ve_setup_X_uncoupled={
  140647. 11,
  140648. rate_mapping_X,
  140649. quality_mapping_44,
  140650. -1,
  140651. 50000,
  140652. 200000,
  140653. blocksize_short_44,
  140654. blocksize_long_44,
  140655. _psy_tone_masteratt_44,
  140656. _psy_tone_0dB,
  140657. _psy_tone_suppress,
  140658. _vp_tonemask_adj_otherblock,
  140659. _vp_tonemask_adj_longblock,
  140660. _vp_tonemask_adj_otherblock,
  140661. _psy_noiseguards_44,
  140662. _psy_noisebias_impulse,
  140663. _psy_noisebias_padding,
  140664. _psy_noisebias_trans,
  140665. _psy_noisebias_long,
  140666. _psy_noise_suppress,
  140667. _psy_compand_44,
  140668. _psy_compand_short_mapping,
  140669. _psy_compand_long_mapping,
  140670. {_noise_start_short_44,_noise_start_long_44},
  140671. {_noise_part_short_44,_noise_part_long_44},
  140672. _noise_thresh_44,
  140673. _psy_ath_floater,
  140674. _psy_ath_abs,
  140675. _psy_lowpass_44,
  140676. _psy_global_44,
  140677. _global_mapping_44,
  140678. NULL,
  140679. _floor_books,
  140680. _floor,
  140681. _floor_short_mapping_44,
  140682. _floor_long_mapping_44,
  140683. _mapres_template_44_uncoupled
  140684. };
  140685. ve_setup_data_template ve_setup_XX_stereo={
  140686. 2,
  140687. rate_mapping_X,
  140688. quality_mapping_8,
  140689. 2,
  140690. 0,
  140691. 8000,
  140692. blocksize_8,
  140693. blocksize_8,
  140694. _psy_tone_masteratt_8,
  140695. _psy_tone_0dB,
  140696. _psy_tone_suppress,
  140697. _vp_tonemask_adj_8,
  140698. NULL,
  140699. _vp_tonemask_adj_8,
  140700. _psy_noiseguards_8,
  140701. _psy_noisebias_8,
  140702. _psy_noisebias_8,
  140703. NULL,
  140704. NULL,
  140705. _psy_noise_suppress,
  140706. _psy_compand_8,
  140707. _psy_compand_8_mapping,
  140708. NULL,
  140709. {_noise_start_8,_noise_start_8},
  140710. {_noise_part_8,_noise_part_8},
  140711. _noise_thresh_5only,
  140712. _psy_ath_floater_8,
  140713. _psy_ath_abs_8,
  140714. _psy_lowpass_8,
  140715. _psy_global_44,
  140716. _global_mapping_8,
  140717. _psy_stereo_modes_8,
  140718. _floor_books,
  140719. _floor,
  140720. _floor_mapping_8,
  140721. NULL,
  140722. _mapres_template_8_stereo
  140723. };
  140724. ve_setup_data_template ve_setup_XX_uncoupled={
  140725. 2,
  140726. rate_mapping_X,
  140727. quality_mapping_8,
  140728. -1,
  140729. 0,
  140730. 8000,
  140731. blocksize_8,
  140732. blocksize_8,
  140733. _psy_tone_masteratt_8,
  140734. _psy_tone_0dB,
  140735. _psy_tone_suppress,
  140736. _vp_tonemask_adj_8,
  140737. NULL,
  140738. _vp_tonemask_adj_8,
  140739. _psy_noiseguards_8,
  140740. _psy_noisebias_8,
  140741. _psy_noisebias_8,
  140742. NULL,
  140743. NULL,
  140744. _psy_noise_suppress,
  140745. _psy_compand_8,
  140746. _psy_compand_8_mapping,
  140747. NULL,
  140748. {_noise_start_8,_noise_start_8},
  140749. {_noise_part_8,_noise_part_8},
  140750. _noise_thresh_5only,
  140751. _psy_ath_floater_8,
  140752. _psy_ath_abs_8,
  140753. _psy_lowpass_8,
  140754. _psy_global_44,
  140755. _global_mapping_8,
  140756. _psy_stereo_modes_8,
  140757. _floor_books,
  140758. _floor,
  140759. _floor_mapping_8,
  140760. NULL,
  140761. _mapres_template_8_uncoupled
  140762. };
  140763. /********* End of inlined file: setup_X.h *********/
  140764. static ve_setup_data_template *setup_list[]={
  140765. &ve_setup_44_stereo,
  140766. &ve_setup_44_uncoupled,
  140767. &ve_setup_32_stereo,
  140768. &ve_setup_32_uncoupled,
  140769. &ve_setup_22_stereo,
  140770. &ve_setup_22_uncoupled,
  140771. &ve_setup_16_stereo,
  140772. &ve_setup_16_uncoupled,
  140773. &ve_setup_11_stereo,
  140774. &ve_setup_11_uncoupled,
  140775. &ve_setup_8_stereo,
  140776. &ve_setup_8_uncoupled,
  140777. &ve_setup_X_stereo,
  140778. &ve_setup_X_uncoupled,
  140779. &ve_setup_XX_stereo,
  140780. &ve_setup_XX_uncoupled,
  140781. 0
  140782. };
  140783. static int vorbis_encode_toplevel_setup(vorbis_info *vi,int ch,long rate){
  140784. if(vi && vi->codec_setup){
  140785. vi->version=0;
  140786. vi->channels=ch;
  140787. vi->rate=rate;
  140788. return(0);
  140789. }
  140790. return(OV_EINVAL);
  140791. }
  140792. static void vorbis_encode_floor_setup(vorbis_info *vi,double s,int block,
  140793. static_codebook ***books,
  140794. vorbis_info_floor1 *in,
  140795. int *x){
  140796. int i,k,is=s;
  140797. vorbis_info_floor1 *f=(vorbis_info_floor1*) _ogg_calloc(1,sizeof(*f));
  140798. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  140799. memcpy(f,in+x[is],sizeof(*f));
  140800. f->n=ci->blocksizes[block]>>1;
  140801. {
  140802. int partitions=f->partitions;
  140803. int maxclass=-1;
  140804. int maxbook=-1;
  140805. for(i=0;i<partitions;i++)
  140806. if(f->partitionclass[i]>maxclass)maxclass=f->partitionclass[i];
  140807. for(i=0;i<=maxclass;i++){
  140808. if(f->class_book[i]>maxbook)maxbook=f->class_book[i];
  140809. f->class_book[i]+=ci->books;
  140810. for(k=0;k<(1<<f->class_subs[i]);k++){
  140811. if(f->class_subbook[i][k]>maxbook)maxbook=f->class_subbook[i][k];
  140812. if(f->class_subbook[i][k]>=0)f->class_subbook[i][k]+=ci->books;
  140813. }
  140814. }
  140815. for(i=0;i<=maxbook;i++)
  140816. ci->book_param[ci->books++]=books[x[is]][i];
  140817. }
  140818. ci->floor_type[ci->floors]=1;
  140819. ci->floor_param[ci->floors]=f;
  140820. ci->floors++;
  140821. return;
  140822. }
  140823. static void vorbis_encode_global_psych_setup(vorbis_info *vi,double s,
  140824. vorbis_info_psy_global *in,
  140825. double *x){
  140826. int i,is=s;
  140827. double ds=s-is;
  140828. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  140829. vorbis_info_psy_global *g=&ci->psy_g_param;
  140830. memcpy(g,in+(int)x[is],sizeof(*g));
  140831. ds=x[is]*(1.-ds)+x[is+1]*ds;
  140832. is=(int)ds;
  140833. ds-=is;
  140834. if(ds==0 && is>0){
  140835. is--;
  140836. ds=1.;
  140837. }
  140838. for(i=0;i<4;i++){
  140839. g->preecho_thresh[i]=in[is].preecho_thresh[i]*(1.-ds)+in[is+1].preecho_thresh[i]*ds;
  140840. g->postecho_thresh[i]=in[is].postecho_thresh[i]*(1.-ds)+in[is+1].postecho_thresh[i]*ds;
  140841. }
  140842. g->ampmax_att_per_sec=ci->hi.amplitude_track_dBpersec;
  140843. return;
  140844. }
  140845. static void vorbis_encode_global_stereo(vorbis_info *vi,
  140846. highlevel_encode_setup *hi,
  140847. adj_stereo *p){
  140848. float s=hi->stereo_point_setting;
  140849. int i,is=s;
  140850. double ds=s-is;
  140851. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  140852. vorbis_info_psy_global *g=&ci->psy_g_param;
  140853. if(p){
  140854. memcpy(g->coupling_prepointamp,p[is].pre,sizeof(*p[is].pre)*PACKETBLOBS);
  140855. memcpy(g->coupling_postpointamp,p[is].post,sizeof(*p[is].post)*PACKETBLOBS);
  140856. if(hi->managed){
  140857. for(i=0;i<PACKETBLOBS;i++){
  140858. float kHz=p[is].kHz[i]*(1.-ds)+p[is+1].kHz[i]*ds;
  140859. g->coupling_pointlimit[0][i]=kHz*1000./vi->rate*ci->blocksizes[0];
  140860. g->coupling_pointlimit[1][i]=kHz*1000./vi->rate*ci->blocksizes[1];
  140861. g->coupling_pkHz[i]=kHz;
  140862. kHz=p[is].lowpasskHz[i]*(1.-ds)+p[is+1].lowpasskHz[i]*ds;
  140863. g->sliding_lowpass[0][i]=kHz*1000./vi->rate*ci->blocksizes[0];
  140864. g->sliding_lowpass[1][i]=kHz*1000./vi->rate*ci->blocksizes[1];
  140865. }
  140866. }else{
  140867. float kHz=p[is].kHz[PACKETBLOBS/2]*(1.-ds)+p[is+1].kHz[PACKETBLOBS/2]*ds;
  140868. for(i=0;i<PACKETBLOBS;i++){
  140869. g->coupling_pointlimit[0][i]=kHz*1000./vi->rate*ci->blocksizes[0];
  140870. g->coupling_pointlimit[1][i]=kHz*1000./vi->rate*ci->blocksizes[1];
  140871. g->coupling_pkHz[i]=kHz;
  140872. }
  140873. kHz=p[is].lowpasskHz[PACKETBLOBS/2]*(1.-ds)+p[is+1].lowpasskHz[PACKETBLOBS/2]*ds;
  140874. for(i=0;i<PACKETBLOBS;i++){
  140875. g->sliding_lowpass[0][i]=kHz*1000./vi->rate*ci->blocksizes[0];
  140876. g->sliding_lowpass[1][i]=kHz*1000./vi->rate*ci->blocksizes[1];
  140877. }
  140878. }
  140879. }else{
  140880. for(i=0;i<PACKETBLOBS;i++){
  140881. g->sliding_lowpass[0][i]=ci->blocksizes[0];
  140882. g->sliding_lowpass[1][i]=ci->blocksizes[1];
  140883. }
  140884. }
  140885. return;
  140886. }
  140887. static void vorbis_encode_psyset_setup(vorbis_info *vi,double s,
  140888. int *nn_start,
  140889. int *nn_partition,
  140890. double *nn_thresh,
  140891. int block){
  140892. codec_setup_info *ci=(codec_setup_info*) vi->codec_setup;
  140893. vorbis_info_psy *p=ci->psy_param[block];
  140894. highlevel_encode_setup *hi=&ci->hi;
  140895. int is=s;
  140896. if(block>=ci->psys)
  140897. ci->psys=block+1;
  140898. if(!p){
  140899. p=(vorbis_info_psy*)_ogg_calloc(1,sizeof(*p));
  140900. ci->psy_param[block]=p;
  140901. }
  140902. memcpy(p,&_psy_info_template,sizeof(*p));
  140903. p->blockflag=block>>1;
  140904. if(hi->noise_normalize_p){
  140905. p->normal_channel_p=1;
  140906. p->normal_point_p=1;
  140907. p->normal_start=nn_start[is];
  140908. p->normal_partition=nn_partition[is];
  140909. p->normal_thresh=nn_thresh[is];
  140910. }
  140911. return;
  140912. }
  140913. static void vorbis_encode_tonemask_setup(vorbis_info *vi,double s,int block,
  140914. att3 *att,
  140915. int *max,
  140916. vp_adjblock *in){
  140917. int i,is=s;
  140918. double ds=s-is;
  140919. codec_setup_info *ci=(codec_setup_info*) vi->codec_setup;
  140920. vorbis_info_psy *p=ci->psy_param[block];
  140921. p->tone_masteratt[0]=att[is].att[0]*(1.-ds)+att[is+1].att[0]*ds;
  140922. p->tone_masteratt[1]=att[is].att[1]*(1.-ds)+att[is+1].att[1]*ds;
  140923. p->tone_masteratt[2]=att[is].att[2]*(1.-ds)+att[is+1].att[2]*ds;
  140924. p->tone_centerboost=att[is].boost*(1.-ds)+att[is+1].boost*ds;
  140925. p->tone_decay=att[is].decay*(1.-ds)+att[is+1].decay*ds;
  140926. p->max_curve_dB=max[is]*(1.-ds)+max[is+1]*ds;
  140927. for(i=0;i<P_BANDS;i++)
  140928. p->toneatt[i]=in[is].block[i]*(1.-ds)+in[is+1].block[i]*ds;
  140929. return;
  140930. }
  140931. static void vorbis_encode_compand_setup(vorbis_info *vi,double s,int block,
  140932. compandblock *in, double *x){
  140933. int i,is=s;
  140934. double ds=s-is;
  140935. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  140936. vorbis_info_psy *p=ci->psy_param[block];
  140937. ds=x[is]*(1.-ds)+x[is+1]*ds;
  140938. is=(int)ds;
  140939. ds-=is;
  140940. if(ds==0 && is>0){
  140941. is--;
  140942. ds=1.;
  140943. }
  140944. for(i=0;i<NOISE_COMPAND_LEVELS;i++)
  140945. p->noisecompand[i]=in[is].data[i]*(1.-ds)+in[is+1].data[i]*ds;
  140946. return;
  140947. }
  140948. static void vorbis_encode_peak_setup(vorbis_info *vi,double s,int block,
  140949. int *suppress){
  140950. int is=s;
  140951. double ds=s-is;
  140952. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  140953. vorbis_info_psy *p=ci->psy_param[block];
  140954. p->tone_abs_limit=suppress[is]*(1.-ds)+suppress[is+1]*ds;
  140955. return;
  140956. }
  140957. static void vorbis_encode_noisebias_setup(vorbis_info *vi,double s,int block,
  140958. int *suppress,
  140959. noise3 *in,
  140960. noiseguard *guard,
  140961. double userbias){
  140962. int i,is=s,j;
  140963. double ds=s-is;
  140964. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  140965. vorbis_info_psy *p=ci->psy_param[block];
  140966. p->noisemaxsupp=suppress[is]*(1.-ds)+suppress[is+1]*ds;
  140967. p->noisewindowlomin=guard[block].lo;
  140968. p->noisewindowhimin=guard[block].hi;
  140969. p->noisewindowfixed=guard[block].fixed;
  140970. for(j=0;j<P_NOISECURVES;j++)
  140971. for(i=0;i<P_BANDS;i++)
  140972. p->noiseoff[j][i]=in[is].data[j][i]*(1.-ds)+in[is+1].data[j][i]*ds;
  140973. for(j=0;j<P_NOISECURVES;j++){
  140974. float min=p->noiseoff[j][0]+6; /* the lowest it can go */
  140975. for(i=0;i<P_BANDS;i++){
  140976. p->noiseoff[j][i]+=userbias;
  140977. if(p->noiseoff[j][i]<min)p->noiseoff[j][i]=min;
  140978. }
  140979. }
  140980. return;
  140981. }
  140982. static void vorbis_encode_ath_setup(vorbis_info *vi,int block){
  140983. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  140984. vorbis_info_psy *p=ci->psy_param[block];
  140985. p->ath_adjatt=ci->hi.ath_floating_dB;
  140986. p->ath_maxatt=ci->hi.ath_absolute_dB;
  140987. return;
  140988. }
  140989. static int book_dup_or_new(codec_setup_info *ci,static_codebook *book){
  140990. int i;
  140991. for(i=0;i<ci->books;i++)
  140992. if(ci->book_param[i]==book)return(i);
  140993. return(ci->books++);
  140994. }
  140995. static void vorbis_encode_blocksize_setup(vorbis_info *vi,double s,
  140996. int *shortb,int *longb){
  140997. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  140998. int is=s;
  140999. int blockshort=shortb[is];
  141000. int blocklong=longb[is];
  141001. ci->blocksizes[0]=blockshort;
  141002. ci->blocksizes[1]=blocklong;
  141003. }
  141004. static void vorbis_encode_residue_setup(vorbis_info *vi,
  141005. int number, int block,
  141006. vorbis_residue_template *res){
  141007. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  141008. int i,n;
  141009. vorbis_info_residue0 *r=(vorbis_info_residue0*)(ci->residue_param[number]=
  141010. (vorbis_info_residue0*)_ogg_malloc(sizeof(*r)));
  141011. memcpy(r,res->res,sizeof(*r));
  141012. if(ci->residues<=number)ci->residues=number+1;
  141013. switch(ci->blocksizes[block]){
  141014. case 64:case 128:case 256:
  141015. r->grouping=16;
  141016. break;
  141017. default:
  141018. r->grouping=32;
  141019. break;
  141020. }
  141021. ci->residue_type[number]=res->res_type;
  141022. n=r->end=ci->blocksizes[block]>>1;
  141023. if(res->res_type==2)
  141024. n=r->end*=vi->channels;
  141025. {
  141026. int booklist=0,k;
  141027. if(ci->hi.managed){
  141028. for(i=0;i<r->partitions;i++)
  141029. for(k=0;k<3;k++)
  141030. if(res->books_base_managed->books[i][k])
  141031. r->secondstages[i]|=(1<<k);
  141032. r->groupbook=book_dup_or_new(ci,res->book_aux_managed);
  141033. ci->book_param[r->groupbook]=res->book_aux_managed;
  141034. for(i=0;i<r->partitions;i++){
  141035. for(k=0;k<3;k++){
  141036. if(res->books_base_managed->books[i][k]){
  141037. int bookid=book_dup_or_new(ci,res->books_base_managed->books[i][k]);
  141038. r->booklist[booklist++]=bookid;
  141039. ci->book_param[bookid]=res->books_base_managed->books[i][k];
  141040. }
  141041. }
  141042. }
  141043. }else{
  141044. for(i=0;i<r->partitions;i++)
  141045. for(k=0;k<3;k++)
  141046. if(res->books_base->books[i][k])
  141047. r->secondstages[i]|=(1<<k);
  141048. r->groupbook=book_dup_or_new(ci,res->book_aux);
  141049. ci->book_param[r->groupbook]=res->book_aux;
  141050. for(i=0;i<r->partitions;i++){
  141051. for(k=0;k<3;k++){
  141052. if(res->books_base->books[i][k]){
  141053. int bookid=book_dup_or_new(ci,res->books_base->books[i][k]);
  141054. r->booklist[booklist++]=bookid;
  141055. ci->book_param[bookid]=res->books_base->books[i][k];
  141056. }
  141057. }
  141058. }
  141059. }
  141060. }
  141061. {
  141062. double freq=ci->hi.lowpass_kHz*1000.;
  141063. vorbis_info_floor1 *f=(vorbis_info_floor1*)ci->floor_param[block]; /* by convention */
  141064. double nyq=vi->rate/2.;
  141065. long blocksize=ci->blocksizes[block]>>1;
  141066. if(freq>nyq)freq=nyq;
  141067. f->n=freq/nyq*blocksize;
  141068. if(res->limit_type){
  141069. if(ci->hi.managed)
  141070. freq=ci->psy_g_param.coupling_pkHz[PACKETBLOBS-1]*1000.;
  141071. else
  141072. freq=ci->psy_g_param.coupling_pkHz[PACKETBLOBS/2]*1000.;
  141073. if(freq>nyq)freq=nyq;
  141074. }
  141075. if(ci->residue_type[block]==2)
  141076. r->end=(int)((freq/nyq*blocksize*2)/r->grouping+.9)* /* round up only if we're well past */
  141077. r->grouping;
  141078. else
  141079. r->end=(int)((freq/nyq*blocksize)/r->grouping+.9)* /* round up only if we're well past */
  141080. r->grouping;
  141081. }
  141082. }
  141083. static void vorbis_encode_map_n_res_setup(vorbis_info *vi,double s,
  141084. vorbis_mapping_template *maps){
  141085. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  141086. int i,j,is=s,modes=2;
  141087. vorbis_info_mapping0 *map=maps[is].map;
  141088. vorbis_info_mode *mode=_mode_template;
  141089. vorbis_residue_template *res=maps[is].res;
  141090. if(ci->blocksizes[0]==ci->blocksizes[1])modes=1;
  141091. for(i=0;i<modes;i++){
  141092. ci->map_param[i]=_ogg_calloc(1,sizeof(*map));
  141093. ci->mode_param[i]=(vorbis_info_mode*)_ogg_calloc(1,sizeof(*mode));
  141094. memcpy(ci->mode_param[i],mode+i,sizeof(*_mode_template));
  141095. if(i>=ci->modes)ci->modes=i+1;
  141096. ci->map_type[i]=0;
  141097. memcpy(ci->map_param[i],map+i,sizeof(*map));
  141098. if(i>=ci->maps)ci->maps=i+1;
  141099. for(j=0;j<map[i].submaps;j++)
  141100. vorbis_encode_residue_setup(vi,map[i].residuesubmap[j],i
  141101. ,res+map[i].residuesubmap[j]);
  141102. }
  141103. }
  141104. static double setting_to_approx_bitrate(vorbis_info *vi){
  141105. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  141106. highlevel_encode_setup *hi=&ci->hi;
  141107. ve_setup_data_template *setup=(ve_setup_data_template *)hi->setup;
  141108. int is=hi->base_setting;
  141109. double ds=hi->base_setting-is;
  141110. int ch=vi->channels;
  141111. double *r=setup->rate_mapping;
  141112. if(r==NULL)
  141113. return(-1);
  141114. return((r[is]*(1.-ds)+r[is+1]*ds)*ch);
  141115. }
  141116. static void get_setup_template(vorbis_info *vi,
  141117. long ch,long srate,
  141118. double req,int q_or_bitrate){
  141119. int i=0,j;
  141120. codec_setup_info *ci=(codec_setup_info*) vi->codec_setup;
  141121. highlevel_encode_setup *hi=&ci->hi;
  141122. if(q_or_bitrate)req/=ch;
  141123. while(setup_list[i]){
  141124. if(setup_list[i]->coupling_restriction==-1 ||
  141125. setup_list[i]->coupling_restriction==ch){
  141126. if(srate>=setup_list[i]->samplerate_min_restriction &&
  141127. srate<=setup_list[i]->samplerate_max_restriction){
  141128. int mappings=setup_list[i]->mappings;
  141129. double *map=(q_or_bitrate?
  141130. setup_list[i]->rate_mapping:
  141131. setup_list[i]->quality_mapping);
  141132. if(req<map[0]){++i;continue;}
  141133. if(req>map[setup_list[i]->mappings]){++i;continue;}
  141134. for(j=0;j<mappings;j++)
  141135. if(req>=map[j] && req<map[j+1])break;
  141136. hi->setup=setup_list[i];
  141137. if(j==mappings)
  141138. hi->base_setting=j-.001;
  141139. else{
  141140. float low=map[j];
  141141. float high=map[j+1];
  141142. float del=(req-low)/(high-low);
  141143. hi->base_setting=j+del;
  141144. }
  141145. return;
  141146. }
  141147. }
  141148. i++;
  141149. }
  141150. hi->setup=NULL;
  141151. }
  141152. int vorbis_encode_setup_init(vorbis_info *vi){
  141153. int i0=0,singleblock=0;
  141154. codec_setup_info *ci=(codec_setup_info*) vi->codec_setup;
  141155. ve_setup_data_template *setup=NULL;
  141156. highlevel_encode_setup *hi=&ci->hi;
  141157. if(ci==NULL)return(OV_EINVAL);
  141158. if(!hi->impulse_block_p)i0=1;
  141159. if(hi->ath_floating_dB>-80)hi->ath_floating_dB=-80;
  141160. if(hi->ath_floating_dB<-200)hi->ath_floating_dB=-200;
  141161. if(hi->amplitude_track_dBpersec>0.)hi->amplitude_track_dBpersec=0.;
  141162. if(hi->amplitude_track_dBpersec<-99999.)hi->amplitude_track_dBpersec=-99999.;
  141163. setup=(ve_setup_data_template *)hi->setup;
  141164. if(setup==NULL)return(OV_EINVAL);
  141165. hi->set_in_stone=1;
  141166. vorbis_encode_blocksize_setup(vi,hi->base_setting,
  141167. setup->blocksize_short,
  141168. setup->blocksize_long);
  141169. if(ci->blocksizes[0]==ci->blocksizes[1])singleblock=1;
  141170. vorbis_encode_floor_setup(vi,hi->short_setting,0,
  141171. setup->floor_books,
  141172. setup->floor_params,
  141173. setup->floor_short_mapping);
  141174. if(!singleblock)
  141175. vorbis_encode_floor_setup(vi,hi->long_setting,1,
  141176. setup->floor_books,
  141177. setup->floor_params,
  141178. setup->floor_long_mapping);
  141179. vorbis_encode_global_psych_setup(vi,hi->trigger_setting,
  141180. setup->global_params,
  141181. setup->global_mapping);
  141182. vorbis_encode_global_stereo(vi,hi,setup->stereo_modes);
  141183. vorbis_encode_psyset_setup(vi,hi->short_setting,
  141184. setup->psy_noise_normal_start[0],
  141185. setup->psy_noise_normal_partition[0],
  141186. setup->psy_noise_normal_thresh,
  141187. 0);
  141188. vorbis_encode_psyset_setup(vi,hi->short_setting,
  141189. setup->psy_noise_normal_start[0],
  141190. setup->psy_noise_normal_partition[0],
  141191. setup->psy_noise_normal_thresh,
  141192. 1);
  141193. if(!singleblock){
  141194. vorbis_encode_psyset_setup(vi,hi->long_setting,
  141195. setup->psy_noise_normal_start[1],
  141196. setup->psy_noise_normal_partition[1],
  141197. setup->psy_noise_normal_thresh,
  141198. 2);
  141199. vorbis_encode_psyset_setup(vi,hi->long_setting,
  141200. setup->psy_noise_normal_start[1],
  141201. setup->psy_noise_normal_partition[1],
  141202. setup->psy_noise_normal_thresh,
  141203. 3);
  141204. }
  141205. vorbis_encode_tonemask_setup(vi,hi->block[i0].tone_mask_setting,0,
  141206. setup->psy_tone_masteratt,
  141207. setup->psy_tone_0dB,
  141208. setup->psy_tone_adj_impulse);
  141209. vorbis_encode_tonemask_setup(vi,hi->block[1].tone_mask_setting,1,
  141210. setup->psy_tone_masteratt,
  141211. setup->psy_tone_0dB,
  141212. setup->psy_tone_adj_other);
  141213. if(!singleblock){
  141214. vorbis_encode_tonemask_setup(vi,hi->block[2].tone_mask_setting,2,
  141215. setup->psy_tone_masteratt,
  141216. setup->psy_tone_0dB,
  141217. setup->psy_tone_adj_other);
  141218. vorbis_encode_tonemask_setup(vi,hi->block[3].tone_mask_setting,3,
  141219. setup->psy_tone_masteratt,
  141220. setup->psy_tone_0dB,
  141221. setup->psy_tone_adj_long);
  141222. }
  141223. vorbis_encode_compand_setup(vi,hi->block[i0].noise_compand_setting,0,
  141224. setup->psy_noise_compand,
  141225. setup->psy_noise_compand_short_mapping);
  141226. vorbis_encode_compand_setup(vi,hi->block[1].noise_compand_setting,1,
  141227. setup->psy_noise_compand,
  141228. setup->psy_noise_compand_short_mapping);
  141229. if(!singleblock){
  141230. vorbis_encode_compand_setup(vi,hi->block[2].noise_compand_setting,2,
  141231. setup->psy_noise_compand,
  141232. setup->psy_noise_compand_long_mapping);
  141233. vorbis_encode_compand_setup(vi,hi->block[3].noise_compand_setting,3,
  141234. setup->psy_noise_compand,
  141235. setup->psy_noise_compand_long_mapping);
  141236. }
  141237. vorbis_encode_peak_setup(vi,hi->block[i0].tone_peaklimit_setting,0,
  141238. setup->psy_tone_dBsuppress);
  141239. vorbis_encode_peak_setup(vi,hi->block[1].tone_peaklimit_setting,1,
  141240. setup->psy_tone_dBsuppress);
  141241. if(!singleblock){
  141242. vorbis_encode_peak_setup(vi,hi->block[2].tone_peaklimit_setting,2,
  141243. setup->psy_tone_dBsuppress);
  141244. vorbis_encode_peak_setup(vi,hi->block[3].tone_peaklimit_setting,3,
  141245. setup->psy_tone_dBsuppress);
  141246. }
  141247. vorbis_encode_noisebias_setup(vi,hi->block[i0].noise_bias_setting,0,
  141248. setup->psy_noise_dBsuppress,
  141249. setup->psy_noise_bias_impulse,
  141250. setup->psy_noiseguards,
  141251. (i0==0?hi->impulse_noisetune:0.));
  141252. vorbis_encode_noisebias_setup(vi,hi->block[1].noise_bias_setting,1,
  141253. setup->psy_noise_dBsuppress,
  141254. setup->psy_noise_bias_padding,
  141255. setup->psy_noiseguards,0.);
  141256. if(!singleblock){
  141257. vorbis_encode_noisebias_setup(vi,hi->block[2].noise_bias_setting,2,
  141258. setup->psy_noise_dBsuppress,
  141259. setup->psy_noise_bias_trans,
  141260. setup->psy_noiseguards,0.);
  141261. vorbis_encode_noisebias_setup(vi,hi->block[3].noise_bias_setting,3,
  141262. setup->psy_noise_dBsuppress,
  141263. setup->psy_noise_bias_long,
  141264. setup->psy_noiseguards,0.);
  141265. }
  141266. vorbis_encode_ath_setup(vi,0);
  141267. vorbis_encode_ath_setup(vi,1);
  141268. if(!singleblock){
  141269. vorbis_encode_ath_setup(vi,2);
  141270. vorbis_encode_ath_setup(vi,3);
  141271. }
  141272. vorbis_encode_map_n_res_setup(vi,hi->base_setting,setup->maps);
  141273. if(hi->bitrate_av>0)
  141274. vi->bitrate_nominal=hi->bitrate_av;
  141275. else{
  141276. vi->bitrate_nominal=setting_to_approx_bitrate(vi);
  141277. }
  141278. vi->bitrate_lower=hi->bitrate_min;
  141279. vi->bitrate_upper=hi->bitrate_max;
  141280. if(hi->bitrate_av)
  141281. vi->bitrate_window=(double)hi->bitrate_reservoir/hi->bitrate_av;
  141282. else
  141283. vi->bitrate_window=0.;
  141284. if(hi->managed){
  141285. ci->bi.avg_rate=hi->bitrate_av;
  141286. ci->bi.min_rate=hi->bitrate_min;
  141287. ci->bi.max_rate=hi->bitrate_max;
  141288. ci->bi.reservoir_bits=hi->bitrate_reservoir;
  141289. ci->bi.reservoir_bias=
  141290. hi->bitrate_reservoir_bias;
  141291. ci->bi.slew_damp=hi->bitrate_av_damp;
  141292. }
  141293. return(0);
  141294. }
  141295. static int vorbis_encode_setup_setting(vorbis_info *vi,
  141296. long channels,
  141297. long rate){
  141298. int ret=0,i,is;
  141299. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  141300. highlevel_encode_setup *hi=&ci->hi;
  141301. ve_setup_data_template *setup=(ve_setup_data_template*) hi->setup;
  141302. double ds;
  141303. ret=vorbis_encode_toplevel_setup(vi,channels,rate);
  141304. if(ret)return(ret);
  141305. is=hi->base_setting;
  141306. ds=hi->base_setting-is;
  141307. hi->short_setting=hi->base_setting;
  141308. hi->long_setting=hi->base_setting;
  141309. hi->managed=0;
  141310. hi->impulse_block_p=1;
  141311. hi->noise_normalize_p=1;
  141312. hi->stereo_point_setting=hi->base_setting;
  141313. hi->lowpass_kHz=
  141314. setup->psy_lowpass[is]*(1.-ds)+setup->psy_lowpass[is+1]*ds;
  141315. hi->ath_floating_dB=setup->psy_ath_float[is]*(1.-ds)+
  141316. setup->psy_ath_float[is+1]*ds;
  141317. hi->ath_absolute_dB=setup->psy_ath_abs[is]*(1.-ds)+
  141318. setup->psy_ath_abs[is+1]*ds;
  141319. hi->amplitude_track_dBpersec=-6.;
  141320. hi->trigger_setting=hi->base_setting;
  141321. for(i=0;i<4;i++){
  141322. hi->block[i].tone_mask_setting=hi->base_setting;
  141323. hi->block[i].tone_peaklimit_setting=hi->base_setting;
  141324. hi->block[i].noise_bias_setting=hi->base_setting;
  141325. hi->block[i].noise_compand_setting=hi->base_setting;
  141326. }
  141327. return(ret);
  141328. }
  141329. int vorbis_encode_setup_vbr(vorbis_info *vi,
  141330. long channels,
  141331. long rate,
  141332. float quality){
  141333. codec_setup_info *ci=(codec_setup_info*) vi->codec_setup;
  141334. highlevel_encode_setup *hi=&ci->hi;
  141335. quality+=.0000001;
  141336. if(quality>=1.)quality=.9999;
  141337. get_setup_template(vi,channels,rate,quality,0);
  141338. if(!hi->setup)return OV_EIMPL;
  141339. return vorbis_encode_setup_setting(vi,channels,rate);
  141340. }
  141341. int vorbis_encode_init_vbr(vorbis_info *vi,
  141342. long channels,
  141343. long rate,
  141344. float base_quality /* 0. to 1. */
  141345. ){
  141346. int ret=0;
  141347. ret=vorbis_encode_setup_vbr(vi,channels,rate,base_quality);
  141348. if(ret){
  141349. vorbis_info_clear(vi);
  141350. return ret;
  141351. }
  141352. ret=vorbis_encode_setup_init(vi);
  141353. if(ret)
  141354. vorbis_info_clear(vi);
  141355. return(ret);
  141356. }
  141357. int vorbis_encode_setup_managed(vorbis_info *vi,
  141358. long channels,
  141359. long rate,
  141360. long max_bitrate,
  141361. long nominal_bitrate,
  141362. long min_bitrate){
  141363. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  141364. highlevel_encode_setup *hi=&ci->hi;
  141365. double tnominal=nominal_bitrate;
  141366. int ret=0;
  141367. if(nominal_bitrate<=0.){
  141368. if(max_bitrate>0.){
  141369. if(min_bitrate>0.)
  141370. nominal_bitrate=(max_bitrate+min_bitrate)*.5;
  141371. else
  141372. nominal_bitrate=max_bitrate*.875;
  141373. }else{
  141374. if(min_bitrate>0.){
  141375. nominal_bitrate=min_bitrate;
  141376. }else{
  141377. return(OV_EINVAL);
  141378. }
  141379. }
  141380. }
  141381. get_setup_template(vi,channels,rate,nominal_bitrate,1);
  141382. if(!hi->setup)return OV_EIMPL;
  141383. ret=vorbis_encode_setup_setting(vi,channels,rate);
  141384. if(ret){
  141385. vorbis_info_clear(vi);
  141386. return ret;
  141387. }
  141388. hi->managed=1;
  141389. hi->bitrate_min=min_bitrate;
  141390. hi->bitrate_max=max_bitrate;
  141391. hi->bitrate_av=tnominal;
  141392. hi->bitrate_av_damp=1.5f; /* full range in no less than 1.5 second */
  141393. hi->bitrate_reservoir=nominal_bitrate*2;
  141394. hi->bitrate_reservoir_bias=.1; /* bias toward hoarding bits */
  141395. return(ret);
  141396. }
  141397. int vorbis_encode_init(vorbis_info *vi,
  141398. long channels,
  141399. long rate,
  141400. long max_bitrate,
  141401. long nominal_bitrate,
  141402. long min_bitrate){
  141403. int ret=vorbis_encode_setup_managed(vi,channels,rate,
  141404. max_bitrate,
  141405. nominal_bitrate,
  141406. min_bitrate);
  141407. if(ret){
  141408. vorbis_info_clear(vi);
  141409. return(ret);
  141410. }
  141411. ret=vorbis_encode_setup_init(vi);
  141412. if(ret)
  141413. vorbis_info_clear(vi);
  141414. return(ret);
  141415. }
  141416. int vorbis_encode_ctl(vorbis_info *vi,int number,void *arg){
  141417. if(vi){
  141418. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  141419. highlevel_encode_setup *hi=&ci->hi;
  141420. int setp=(number&0xf); /* a read request has a low nibble of 0 */
  141421. if(setp && hi->set_in_stone)return(OV_EINVAL);
  141422. switch(number){
  141423. case OV_ECTL_RATEMANAGE_GET:
  141424. {
  141425. struct ovectl_ratemanage_arg *ai=
  141426. (struct ovectl_ratemanage_arg *)arg;
  141427. ai->management_active=hi->managed;
  141428. ai->bitrate_hard_window=ai->bitrate_av_window=
  141429. (double)hi->bitrate_reservoir/vi->rate;
  141430. ai->bitrate_av_window_center=1.;
  141431. ai->bitrate_hard_min=hi->bitrate_min;
  141432. ai->bitrate_hard_max=hi->bitrate_max;
  141433. ai->bitrate_av_lo=hi->bitrate_av;
  141434. ai->bitrate_av_hi=hi->bitrate_av;
  141435. }
  141436. return(0);
  141437. case OV_ECTL_RATEMANAGE_SET:
  141438. {
  141439. struct ovectl_ratemanage_arg *ai=
  141440. (struct ovectl_ratemanage_arg *)arg;
  141441. if(ai==NULL){
  141442. hi->managed=0;
  141443. }else{
  141444. hi->managed=ai->management_active;
  141445. vorbis_encode_ctl(vi,OV_ECTL_RATEMANAGE_AVG,arg);
  141446. vorbis_encode_ctl(vi,OV_ECTL_RATEMANAGE_HARD,arg);
  141447. }
  141448. }
  141449. return 0;
  141450. case OV_ECTL_RATEMANAGE_AVG:
  141451. {
  141452. struct ovectl_ratemanage_arg *ai=
  141453. (struct ovectl_ratemanage_arg *)arg;
  141454. if(ai==NULL){
  141455. hi->bitrate_av=0;
  141456. }else{
  141457. hi->bitrate_av=(ai->bitrate_av_lo+ai->bitrate_av_hi)*.5;
  141458. }
  141459. }
  141460. return(0);
  141461. case OV_ECTL_RATEMANAGE_HARD:
  141462. {
  141463. struct ovectl_ratemanage_arg *ai=
  141464. (struct ovectl_ratemanage_arg *)arg;
  141465. if(ai==NULL){
  141466. hi->bitrate_min=0;
  141467. hi->bitrate_max=0;
  141468. }else{
  141469. hi->bitrate_min=ai->bitrate_hard_min;
  141470. hi->bitrate_max=ai->bitrate_hard_max;
  141471. hi->bitrate_reservoir=ai->bitrate_hard_window*
  141472. (hi->bitrate_max+hi->bitrate_min)*.5;
  141473. }
  141474. if(hi->bitrate_reservoir<128.)
  141475. hi->bitrate_reservoir=128.;
  141476. }
  141477. return(0);
  141478. case OV_ECTL_RATEMANAGE2_GET:
  141479. {
  141480. struct ovectl_ratemanage2_arg *ai=
  141481. (struct ovectl_ratemanage2_arg *)arg;
  141482. if(ai==NULL)return OV_EINVAL;
  141483. ai->management_active=hi->managed;
  141484. ai->bitrate_limit_min_kbps=hi->bitrate_min/1000;
  141485. ai->bitrate_limit_max_kbps=hi->bitrate_max/1000;
  141486. ai->bitrate_average_kbps=hi->bitrate_av/1000;
  141487. ai->bitrate_average_damping=hi->bitrate_av_damp;
  141488. ai->bitrate_limit_reservoir_bits=hi->bitrate_reservoir;
  141489. ai->bitrate_limit_reservoir_bias=hi->bitrate_reservoir_bias;
  141490. }
  141491. return (0);
  141492. case OV_ECTL_RATEMANAGE2_SET:
  141493. {
  141494. struct ovectl_ratemanage2_arg *ai=
  141495. (struct ovectl_ratemanage2_arg *)arg;
  141496. if(ai==NULL){
  141497. hi->managed=0;
  141498. }else{
  141499. if(ai->bitrate_limit_min_kbps>0 &&
  141500. ai->bitrate_average_kbps>0 &&
  141501. ai->bitrate_limit_min_kbps>ai->bitrate_average_kbps)
  141502. return OV_EINVAL;
  141503. if(ai->bitrate_limit_max_kbps>0 &&
  141504. ai->bitrate_average_kbps>0 &&
  141505. ai->bitrate_limit_max_kbps<ai->bitrate_average_kbps)
  141506. return OV_EINVAL;
  141507. if(ai->bitrate_limit_min_kbps>0 &&
  141508. ai->bitrate_limit_max_kbps>0 &&
  141509. ai->bitrate_limit_min_kbps>ai->bitrate_limit_max_kbps)
  141510. return OV_EINVAL;
  141511. if(ai->bitrate_average_damping <= 0.)
  141512. return OV_EINVAL;
  141513. if(ai->bitrate_limit_reservoir_bits < 0)
  141514. return OV_EINVAL;
  141515. if(ai->bitrate_limit_reservoir_bias < 0.)
  141516. return OV_EINVAL;
  141517. if(ai->bitrate_limit_reservoir_bias > 1.)
  141518. return OV_EINVAL;
  141519. hi->managed=ai->management_active;
  141520. hi->bitrate_min=ai->bitrate_limit_min_kbps * 1000;
  141521. hi->bitrate_max=ai->bitrate_limit_max_kbps * 1000;
  141522. hi->bitrate_av=ai->bitrate_average_kbps * 1000;
  141523. hi->bitrate_av_damp=ai->bitrate_average_damping;
  141524. hi->bitrate_reservoir=ai->bitrate_limit_reservoir_bits;
  141525. hi->bitrate_reservoir_bias=ai->bitrate_limit_reservoir_bias;
  141526. }
  141527. }
  141528. return 0;
  141529. case OV_ECTL_LOWPASS_GET:
  141530. {
  141531. double *farg=(double *)arg;
  141532. *farg=hi->lowpass_kHz;
  141533. }
  141534. return(0);
  141535. case OV_ECTL_LOWPASS_SET:
  141536. {
  141537. double *farg=(double *)arg;
  141538. hi->lowpass_kHz=*farg;
  141539. if(hi->lowpass_kHz<2.)hi->lowpass_kHz=2.;
  141540. if(hi->lowpass_kHz>99.)hi->lowpass_kHz=99.;
  141541. }
  141542. return(0);
  141543. case OV_ECTL_IBLOCK_GET:
  141544. {
  141545. double *farg=(double *)arg;
  141546. *farg=hi->impulse_noisetune;
  141547. }
  141548. return(0);
  141549. case OV_ECTL_IBLOCK_SET:
  141550. {
  141551. double *farg=(double *)arg;
  141552. hi->impulse_noisetune=*farg;
  141553. if(hi->impulse_noisetune>0.)hi->impulse_noisetune=0.;
  141554. if(hi->impulse_noisetune<-15.)hi->impulse_noisetune=-15.;
  141555. }
  141556. return(0);
  141557. }
  141558. return(OV_EIMPL);
  141559. }
  141560. return(OV_EINVAL);
  141561. }
  141562. #endif
  141563. /********* End of inlined file: vorbisenc.c *********/
  141564. /********* Start of inlined file: vorbisfile.c *********/
  141565. /********* Start of inlined file: juce_OggVorbisHeader.h *********/
  141566. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  141567. // tasks..
  141568. #if JUCE_MSVC
  141569. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  141570. #endif
  141571. /********* End of inlined file: juce_OggVorbisHeader.h *********/
  141572. #if JUCE_USE_OGGVORBIS
  141573. #include <stdlib.h>
  141574. #include <stdio.h>
  141575. #include <errno.h>
  141576. #include <string.h>
  141577. #include <math.h>
  141578. #define CHUNKSIZE 8500 /* a shade over 8k; anyone using pages well
  141579. over 8k gets what they deserve */
  141580. static long _get_data(OggVorbis_File *vf){
  141581. errno=0;
  141582. if(vf->datasource){
  141583. char *buffer=ogg_sync_buffer(&vf->oy,CHUNKSIZE);
  141584. long bytes=(vf->callbacks.read_func)(buffer,1,CHUNKSIZE,vf->datasource);
  141585. if(bytes>0)ogg_sync_wrote(&vf->oy,bytes);
  141586. if(bytes==0 && errno)return(-1);
  141587. return(bytes);
  141588. }else
  141589. return(0);
  141590. }
  141591. static void _seek_helper(OggVorbis_File *vf,ogg_int64_t offset){
  141592. if(vf->datasource){
  141593. (vf->callbacks.seek_func)(vf->datasource, offset, SEEK_SET);
  141594. vf->offset=offset;
  141595. ogg_sync_reset(&vf->oy);
  141596. }else{
  141597. return;
  141598. }
  141599. }
  141600. static ogg_int64_t _get_next_page(OggVorbis_File *vf,ogg_page *og,
  141601. ogg_int64_t boundary){
  141602. if(boundary>0)boundary+=vf->offset;
  141603. while(1){
  141604. long more;
  141605. if(boundary>0 && vf->offset>=boundary)return(OV_FALSE);
  141606. more=ogg_sync_pageseek(&vf->oy,og);
  141607. if(more<0){
  141608. vf->offset-=more;
  141609. }else{
  141610. if(more==0){
  141611. if(!boundary)return(OV_FALSE);
  141612. {
  141613. long ret=_get_data(vf);
  141614. if(ret==0)return(OV_EOF);
  141615. if(ret<0)return(OV_EREAD);
  141616. }
  141617. }else{
  141618. ogg_int64_t ret=vf->offset;
  141619. vf->offset+=more;
  141620. return(ret);
  141621. }
  141622. }
  141623. }
  141624. }
  141625. static ogg_int64_t _get_prev_page(OggVorbis_File *vf,ogg_page *og){
  141626. ogg_int64_t begin=vf->offset;
  141627. ogg_int64_t end=begin;
  141628. ogg_int64_t ret;
  141629. ogg_int64_t offset=-1;
  141630. while(offset==-1){
  141631. begin-=CHUNKSIZE;
  141632. if(begin<0)
  141633. begin=0;
  141634. _seek_helper(vf,begin);
  141635. while(vf->offset<end){
  141636. ret=_get_next_page(vf,og,end-vf->offset);
  141637. if(ret==OV_EREAD)return(OV_EREAD);
  141638. if(ret<0){
  141639. break;
  141640. }else{
  141641. offset=ret;
  141642. }
  141643. }
  141644. }
  141645. _seek_helper(vf,offset);
  141646. ret=_get_next_page(vf,og,CHUNKSIZE);
  141647. if(ret<0)
  141648. return(OV_EFAULT);
  141649. return(offset);
  141650. }
  141651. static int _bisect_forward_serialno(OggVorbis_File *vf,
  141652. ogg_int64_t begin,
  141653. ogg_int64_t searched,
  141654. ogg_int64_t end,
  141655. long currentno,
  141656. long m){
  141657. ogg_int64_t endsearched=end;
  141658. ogg_int64_t next=end;
  141659. ogg_page og;
  141660. ogg_int64_t ret;
  141661. while(searched<endsearched){
  141662. ogg_int64_t bisect;
  141663. if(endsearched-searched<CHUNKSIZE){
  141664. bisect=searched;
  141665. }else{
  141666. bisect=(searched+endsearched)/2;
  141667. }
  141668. _seek_helper(vf,bisect);
  141669. ret=_get_next_page(vf,&og,-1);
  141670. if(ret==OV_EREAD)return(OV_EREAD);
  141671. if(ret<0 || ogg_page_serialno(&og)!=currentno){
  141672. endsearched=bisect;
  141673. if(ret>=0)next=ret;
  141674. }else{
  141675. searched=ret+og.header_len+og.body_len;
  141676. }
  141677. }
  141678. _seek_helper(vf,next);
  141679. ret=_get_next_page(vf,&og,-1);
  141680. if(ret==OV_EREAD)return(OV_EREAD);
  141681. if(searched>=end || ret<0){
  141682. vf->links=m+1;
  141683. vf->offsets=(ogg_int64_t*)_ogg_malloc((vf->links+1)*sizeof(*vf->offsets));
  141684. vf->serialnos=(long*)_ogg_malloc(vf->links*sizeof(*vf->serialnos));
  141685. vf->offsets[m+1]=searched;
  141686. }else{
  141687. ret=_bisect_forward_serialno(vf,next,vf->offset,
  141688. end,ogg_page_serialno(&og),m+1);
  141689. if(ret==OV_EREAD)return(OV_EREAD);
  141690. }
  141691. vf->offsets[m]=begin;
  141692. vf->serialnos[m]=currentno;
  141693. return(0);
  141694. }
  141695. static int _fetch_headers(OggVorbis_File *vf,vorbis_info *vi,vorbis_comment *vc,
  141696. long *serialno,ogg_page *og_ptr){
  141697. ogg_page og;
  141698. ogg_packet op;
  141699. int i,ret;
  141700. if(!og_ptr){
  141701. ogg_int64_t llret=_get_next_page(vf,&og,CHUNKSIZE);
  141702. if(llret==OV_EREAD)return(OV_EREAD);
  141703. if(llret<0)return OV_ENOTVORBIS;
  141704. og_ptr=&og;
  141705. }
  141706. ogg_stream_reset_serialno(&vf->os,ogg_page_serialno(og_ptr));
  141707. if(serialno)*serialno=vf->os.serialno;
  141708. vf->ready_state=STREAMSET;
  141709. vorbis_info_init(vi);
  141710. vorbis_comment_init(vc);
  141711. i=0;
  141712. while(i<3){
  141713. ogg_stream_pagein(&vf->os,og_ptr);
  141714. while(i<3){
  141715. int result=ogg_stream_packetout(&vf->os,&op);
  141716. if(result==0)break;
  141717. if(result==-1){
  141718. ret=OV_EBADHEADER;
  141719. goto bail_header;
  141720. }
  141721. if((ret=vorbis_synthesis_headerin(vi,vc,&op))){
  141722. goto bail_header;
  141723. }
  141724. i++;
  141725. }
  141726. if(i<3)
  141727. if(_get_next_page(vf,og_ptr,CHUNKSIZE)<0){
  141728. ret=OV_EBADHEADER;
  141729. goto bail_header;
  141730. }
  141731. }
  141732. return 0;
  141733. bail_header:
  141734. vorbis_info_clear(vi);
  141735. vorbis_comment_clear(vc);
  141736. vf->ready_state=OPENED;
  141737. return ret;
  141738. }
  141739. static void _prefetch_all_headers(OggVorbis_File *vf, ogg_int64_t dataoffset){
  141740. ogg_page og;
  141741. int i;
  141742. ogg_int64_t ret;
  141743. vf->vi=(vorbis_info*) _ogg_realloc(vf->vi,vf->links*sizeof(*vf->vi));
  141744. vf->vc=(vorbis_comment*) _ogg_realloc(vf->vc,vf->links*sizeof(*vf->vc));
  141745. vf->dataoffsets=(ogg_int64_t*) _ogg_malloc(vf->links*sizeof(*vf->dataoffsets));
  141746. vf->pcmlengths=(ogg_int64_t*) _ogg_malloc(vf->links*2*sizeof(*vf->pcmlengths));
  141747. for(i=0;i<vf->links;i++){
  141748. if(i==0){
  141749. vf->dataoffsets[i]=dataoffset;
  141750. _seek_helper(vf,dataoffset);
  141751. }else{
  141752. _seek_helper(vf,vf->offsets[i]);
  141753. if(_fetch_headers(vf,vf->vi+i,vf->vc+i,NULL,NULL)<0){
  141754. vf->dataoffsets[i]=-1;
  141755. }else{
  141756. vf->dataoffsets[i]=vf->offset;
  141757. }
  141758. }
  141759. if(vf->dataoffsets[i]!=-1){
  141760. ogg_int64_t accumulated=0;
  141761. long lastblock=-1;
  141762. int result;
  141763. ogg_stream_reset_serialno(&vf->os,vf->serialnos[i]);
  141764. while(1){
  141765. ogg_packet op;
  141766. ret=_get_next_page(vf,&og,-1);
  141767. if(ret<0)
  141768. break;
  141769. if(ogg_page_serialno(&og)!=vf->serialnos[i])
  141770. break;
  141771. ogg_stream_pagein(&vf->os,&og);
  141772. while((result=ogg_stream_packetout(&vf->os,&op))){
  141773. if(result>0){ /* ignore holes */
  141774. long thisblock=vorbis_packet_blocksize(vf->vi+i,&op);
  141775. if(lastblock!=-1)
  141776. accumulated+=(lastblock+thisblock)>>2;
  141777. lastblock=thisblock;
  141778. }
  141779. }
  141780. if(ogg_page_granulepos(&og)!=-1){
  141781. accumulated= ogg_page_granulepos(&og)-accumulated;
  141782. break;
  141783. }
  141784. }
  141785. if(accumulated<0)accumulated=0;
  141786. vf->pcmlengths[i*2]=accumulated;
  141787. }
  141788. {
  141789. ogg_int64_t end=vf->offsets[i+1];
  141790. _seek_helper(vf,end);
  141791. while(1){
  141792. ret=_get_prev_page(vf,&og);
  141793. if(ret<0){
  141794. vorbis_info_clear(vf->vi+i);
  141795. vorbis_comment_clear(vf->vc+i);
  141796. break;
  141797. }
  141798. if(ogg_page_granulepos(&og)!=-1){
  141799. vf->pcmlengths[i*2+1]=ogg_page_granulepos(&og)-vf->pcmlengths[i*2];
  141800. break;
  141801. }
  141802. vf->offset=ret;
  141803. }
  141804. }
  141805. }
  141806. }
  141807. static int _make_decode_ready(OggVorbis_File *vf){
  141808. if(vf->ready_state>STREAMSET)return 0;
  141809. if(vf->ready_state<STREAMSET)return OV_EFAULT;
  141810. if(vf->seekable){
  141811. if(vorbis_synthesis_init(&vf->vd,vf->vi+vf->current_link))
  141812. return OV_EBADLINK;
  141813. }else{
  141814. if(vorbis_synthesis_init(&vf->vd,vf->vi))
  141815. return OV_EBADLINK;
  141816. }
  141817. vorbis_block_init(&vf->vd,&vf->vb);
  141818. vf->ready_state=INITSET;
  141819. vf->bittrack=0.f;
  141820. vf->samptrack=0.f;
  141821. return 0;
  141822. }
  141823. static int _open_seekable2(OggVorbis_File *vf){
  141824. long serialno=vf->current_serialno;
  141825. ogg_int64_t dataoffset=vf->offset, end;
  141826. ogg_page og;
  141827. (vf->callbacks.seek_func)(vf->datasource,0,SEEK_END);
  141828. vf->offset=vf->end=(vf->callbacks.tell_func)(vf->datasource);
  141829. end=_get_prev_page(vf,&og);
  141830. if(end<0)return(end);
  141831. if(ogg_page_serialno(&og)!=serialno){
  141832. if(_bisect_forward_serialno(vf,0,0,end+1,serialno,0)<0)return(OV_EREAD);
  141833. }else{
  141834. if(_bisect_forward_serialno(vf,0,end,end+1,serialno,0))return(OV_EREAD);
  141835. }
  141836. _prefetch_all_headers(vf,dataoffset);
  141837. return(ov_raw_seek(vf,0));
  141838. }
  141839. static void _decode_clear(OggVorbis_File *vf){
  141840. vorbis_dsp_clear(&vf->vd);
  141841. vorbis_block_clear(&vf->vb);
  141842. vf->ready_state=OPENED;
  141843. }
  141844. static int _fetch_and_process_packet(OggVorbis_File *vf,
  141845. ogg_packet *op_in,
  141846. int readp,
  141847. int spanp){
  141848. ogg_page og;
  141849. while(1){
  141850. if(vf->ready_state==INITSET){
  141851. while(1) {
  141852. ogg_packet op;
  141853. ogg_packet *op_ptr=(op_in?op_in:&op);
  141854. int result=ogg_stream_packetout(&vf->os,op_ptr);
  141855. ogg_int64_t granulepos;
  141856. op_in=NULL;
  141857. if(result==-1)return(OV_HOLE); /* hole in the data. */
  141858. if(result>0){
  141859. granulepos=op_ptr->granulepos;
  141860. if(!vorbis_synthesis(&vf->vb,op_ptr)){ /* lazy check for lazy
  141861. header handling. The
  141862. header packets aren't
  141863. audio, so if/when we
  141864. submit them,
  141865. vorbis_synthesis will
  141866. reject them */
  141867. {
  141868. int oldsamples=vorbis_synthesis_pcmout(&vf->vd,NULL);
  141869. if(oldsamples)return(OV_EFAULT);
  141870. vorbis_synthesis_blockin(&vf->vd,&vf->vb);
  141871. vf->samptrack+=vorbis_synthesis_pcmout(&vf->vd,NULL)-oldsamples;
  141872. vf->bittrack+=op_ptr->bytes*8;
  141873. }
  141874. if(granulepos!=-1 && !op_ptr->e_o_s){
  141875. int link=(vf->seekable?vf->current_link:0);
  141876. int i,samples;
  141877. if(vf->seekable && link>0)
  141878. granulepos-=vf->pcmlengths[link*2];
  141879. if(granulepos<0)granulepos=0; /* actually, this
  141880. shouldn't be possible
  141881. here unless the stream
  141882. is very broken */
  141883. samples=vorbis_synthesis_pcmout(&vf->vd,NULL);
  141884. granulepos-=samples;
  141885. for(i=0;i<link;i++)
  141886. granulepos+=vf->pcmlengths[i*2+1];
  141887. vf->pcm_offset=granulepos;
  141888. }
  141889. return(1);
  141890. }
  141891. }
  141892. else
  141893. break;
  141894. }
  141895. }
  141896. if(vf->ready_state>=OPENED){
  141897. ogg_int64_t ret;
  141898. if(!readp)return(0);
  141899. if((ret=_get_next_page(vf,&og,-1))<0){
  141900. return(OV_EOF); /* eof.
  141901. leave unitialized */
  141902. }
  141903. vf->bittrack+=og.header_len*8;
  141904. if(vf->ready_state==INITSET){
  141905. if(vf->current_serialno!=ogg_page_serialno(&og)){
  141906. if(!spanp)
  141907. return(OV_EOF);
  141908. _decode_clear(vf);
  141909. if(!vf->seekable){
  141910. vorbis_info_clear(vf->vi);
  141911. vorbis_comment_clear(vf->vc);
  141912. }
  141913. }
  141914. }
  141915. }
  141916. if(vf->ready_state!=INITSET){
  141917. int link;
  141918. if(vf->ready_state<STREAMSET){
  141919. if(vf->seekable){
  141920. vf->current_serialno=ogg_page_serialno(&og);
  141921. for(link=0;link<vf->links;link++)
  141922. if(vf->serialnos[link]==vf->current_serialno)break;
  141923. if(link==vf->links)return(OV_EBADLINK); /* sign of a bogus
  141924. stream. error out,
  141925. leave machine
  141926. uninitialized */
  141927. vf->current_link=link;
  141928. ogg_stream_reset_serialno(&vf->os,vf->current_serialno);
  141929. vf->ready_state=STREAMSET;
  141930. }else{
  141931. int ret=_fetch_headers(vf,vf->vi,vf->vc,&vf->current_serialno,&og);
  141932. if(ret)return(ret);
  141933. vf->current_link++;
  141934. link=0;
  141935. }
  141936. }
  141937. {
  141938. int ret=_make_decode_ready(vf);
  141939. if(ret<0)return ret;
  141940. }
  141941. }
  141942. ogg_stream_pagein(&vf->os,&og);
  141943. }
  141944. }
  141945. static int _fseek64_wrap(FILE *f,ogg_int64_t off,int whence){
  141946. if(f==NULL)return(-1);
  141947. return fseek(f,off,whence);
  141948. }
  141949. static int _ov_open1(void *f,OggVorbis_File *vf,char *initial,
  141950. long ibytes, ov_callbacks callbacks){
  141951. int offsettest=(f?callbacks.seek_func(f,0,SEEK_CUR):-1);
  141952. int ret;
  141953. memset(vf,0,sizeof(*vf));
  141954. vf->datasource=f;
  141955. vf->callbacks = callbacks;
  141956. ogg_sync_init(&vf->oy);
  141957. if(initial){
  141958. char *buffer=ogg_sync_buffer(&vf->oy,ibytes);
  141959. memcpy(buffer,initial,ibytes);
  141960. ogg_sync_wrote(&vf->oy,ibytes);
  141961. }
  141962. if(offsettest!=-1)vf->seekable=1;
  141963. vf->links=1;
  141964. vf->vi=(vorbis_info*) _ogg_calloc(vf->links,sizeof(*vf->vi));
  141965. vf->vc=(vorbis_comment*) _ogg_calloc(vf->links,sizeof(*vf->vc));
  141966. ogg_stream_init(&vf->os,-1); /* fill in the serialno later */
  141967. if((ret=_fetch_headers(vf,vf->vi,vf->vc,&vf->current_serialno,NULL))<0){
  141968. vf->datasource=NULL;
  141969. ov_clear(vf);
  141970. }else
  141971. vf->ready_state=PARTOPEN;
  141972. return(ret);
  141973. }
  141974. static int _ov_open2(OggVorbis_File *vf){
  141975. if(vf->ready_state != PARTOPEN) return OV_EINVAL;
  141976. vf->ready_state=OPENED;
  141977. if(vf->seekable){
  141978. int ret=_open_seekable2(vf);
  141979. if(ret){
  141980. vf->datasource=NULL;
  141981. ov_clear(vf);
  141982. }
  141983. return(ret);
  141984. }else
  141985. vf->ready_state=STREAMSET;
  141986. return 0;
  141987. }
  141988. int ov_clear(OggVorbis_File *vf){
  141989. if(vf){
  141990. vorbis_block_clear(&vf->vb);
  141991. vorbis_dsp_clear(&vf->vd);
  141992. ogg_stream_clear(&vf->os);
  141993. if(vf->vi && vf->links){
  141994. int i;
  141995. for(i=0;i<vf->links;i++){
  141996. vorbis_info_clear(vf->vi+i);
  141997. vorbis_comment_clear(vf->vc+i);
  141998. }
  141999. _ogg_free(vf->vi);
  142000. _ogg_free(vf->vc);
  142001. }
  142002. if(vf->dataoffsets)_ogg_free(vf->dataoffsets);
  142003. if(vf->pcmlengths)_ogg_free(vf->pcmlengths);
  142004. if(vf->serialnos)_ogg_free(vf->serialnos);
  142005. if(vf->offsets)_ogg_free(vf->offsets);
  142006. ogg_sync_clear(&vf->oy);
  142007. if(vf->datasource)(vf->callbacks.close_func)(vf->datasource);
  142008. memset(vf,0,sizeof(*vf));
  142009. }
  142010. #ifdef DEBUG_LEAKS
  142011. _VDBG_dump();
  142012. #endif
  142013. return(0);
  142014. }
  142015. int ov_open_callbacks(void *f,OggVorbis_File *vf,char *initial,long ibytes,
  142016. ov_callbacks callbacks){
  142017. int ret=_ov_open1(f,vf,initial,ibytes,callbacks);
  142018. if(ret)return ret;
  142019. return _ov_open2(vf);
  142020. }
  142021. int ov_open(FILE *f,OggVorbis_File *vf,char *initial,long ibytes){
  142022. ov_callbacks callbacks = {
  142023. (size_t (*)(void *, size_t, size_t, void *)) fread,
  142024. (int (*)(void *, ogg_int64_t, int)) _fseek64_wrap,
  142025. (int (*)(void *)) fclose,
  142026. (long (*)(void *)) ftell
  142027. };
  142028. return ov_open_callbacks((void *)f, vf, initial, ibytes, callbacks);
  142029. }
  142030. int ov_halfrate(OggVorbis_File *vf,int flag){
  142031. int i;
  142032. if(vf->vi==NULL)return OV_EINVAL;
  142033. if(!vf->seekable)return OV_EINVAL;
  142034. if(vf->ready_state>=STREAMSET)
  142035. _decode_clear(vf); /* clear out stream state; later on libvorbis
  142036. will be able to swap this on the fly, but
  142037. for now dumping the decode machine is needed
  142038. to reinit the MDCT lookups. 1.1 libvorbis
  142039. is planned to be able to switch on the fly */
  142040. for(i=0;i<vf->links;i++){
  142041. if(vorbis_synthesis_halfrate(vf->vi+i,flag)){
  142042. ov_halfrate(vf,0);
  142043. return OV_EINVAL;
  142044. }
  142045. }
  142046. return 0;
  142047. }
  142048. int ov_halfrate_p(OggVorbis_File *vf){
  142049. if(vf->vi==NULL)return OV_EINVAL;
  142050. return vorbis_synthesis_halfrate_p(vf->vi);
  142051. }
  142052. int ov_test_callbacks(void *f,OggVorbis_File *vf,char *initial,long ibytes,
  142053. ov_callbacks callbacks)
  142054. {
  142055. return _ov_open1(f,vf,initial,ibytes,callbacks);
  142056. }
  142057. int ov_test(FILE *f,OggVorbis_File *vf,char *initial,long ibytes){
  142058. ov_callbacks callbacks = {
  142059. (size_t (*)(void *, size_t, size_t, void *)) fread,
  142060. (int (*)(void *, ogg_int64_t, int)) _fseek64_wrap,
  142061. (int (*)(void *)) fclose,
  142062. (long (*)(void *)) ftell
  142063. };
  142064. return ov_test_callbacks((void *)f, vf, initial, ibytes, callbacks);
  142065. }
  142066. int ov_test_open(OggVorbis_File *vf){
  142067. if(vf->ready_state!=PARTOPEN)return(OV_EINVAL);
  142068. return _ov_open2(vf);
  142069. }
  142070. long ov_streams(OggVorbis_File *vf){
  142071. return vf->links;
  142072. }
  142073. long ov_seekable(OggVorbis_File *vf){
  142074. return vf->seekable;
  142075. }
  142076. long ov_bitrate(OggVorbis_File *vf,int i){
  142077. if(vf->ready_state<OPENED)return(OV_EINVAL);
  142078. if(i>=vf->links)return(OV_EINVAL);
  142079. if(!vf->seekable && i!=0)return(ov_bitrate(vf,0));
  142080. if(i<0){
  142081. ogg_int64_t bits=0;
  142082. int i;
  142083. float br;
  142084. for(i=0;i<vf->links;i++)
  142085. bits+=(vf->offsets[i+1]-vf->dataoffsets[i])*8;
  142086. br = bits/ov_time_total(vf,-1);
  142087. return(rint(br));
  142088. }else{
  142089. if(vf->seekable){
  142090. return(rint((vf->offsets[i+1]-vf->dataoffsets[i])*8/ov_time_total(vf,i)));
  142091. }else{
  142092. if(vf->vi[i].bitrate_nominal>0){
  142093. return vf->vi[i].bitrate_nominal;
  142094. }else{
  142095. if(vf->vi[i].bitrate_upper>0){
  142096. if(vf->vi[i].bitrate_lower>0){
  142097. return (vf->vi[i].bitrate_upper+vf->vi[i].bitrate_lower)/2;
  142098. }else{
  142099. return vf->vi[i].bitrate_upper;
  142100. }
  142101. }
  142102. return(OV_FALSE);
  142103. }
  142104. }
  142105. }
  142106. }
  142107. long ov_bitrate_instant(OggVorbis_File *vf){
  142108. int link=(vf->seekable?vf->current_link:0);
  142109. long ret;
  142110. if(vf->ready_state<OPENED)return(OV_EINVAL);
  142111. if(vf->samptrack==0)return(OV_FALSE);
  142112. ret=vf->bittrack/vf->samptrack*vf->vi[link].rate+.5;
  142113. vf->bittrack=0.f;
  142114. vf->samptrack=0.f;
  142115. return(ret);
  142116. }
  142117. long ov_serialnumber(OggVorbis_File *vf,int i){
  142118. if(i>=vf->links)return(ov_serialnumber(vf,vf->links-1));
  142119. if(!vf->seekable && i>=0)return(ov_serialnumber(vf,-1));
  142120. if(i<0){
  142121. return(vf->current_serialno);
  142122. }else{
  142123. return(vf->serialnos[i]);
  142124. }
  142125. }
  142126. ogg_int64_t ov_raw_total(OggVorbis_File *vf,int i){
  142127. if(vf->ready_state<OPENED)return(OV_EINVAL);
  142128. if(!vf->seekable || i>=vf->links)return(OV_EINVAL);
  142129. if(i<0){
  142130. ogg_int64_t acc=0;
  142131. int i;
  142132. for(i=0;i<vf->links;i++)
  142133. acc+=ov_raw_total(vf,i);
  142134. return(acc);
  142135. }else{
  142136. return(vf->offsets[i+1]-vf->offsets[i]);
  142137. }
  142138. }
  142139. ogg_int64_t ov_pcm_total(OggVorbis_File *vf,int i){
  142140. if(vf->ready_state<OPENED)return(OV_EINVAL);
  142141. if(!vf->seekable || i>=vf->links)return(OV_EINVAL);
  142142. if(i<0){
  142143. ogg_int64_t acc=0;
  142144. int i;
  142145. for(i=0;i<vf->links;i++)
  142146. acc+=ov_pcm_total(vf,i);
  142147. return(acc);
  142148. }else{
  142149. return(vf->pcmlengths[i*2+1]);
  142150. }
  142151. }
  142152. double ov_time_total(OggVorbis_File *vf,int i){
  142153. if(vf->ready_state<OPENED)return(OV_EINVAL);
  142154. if(!vf->seekable || i>=vf->links)return(OV_EINVAL);
  142155. if(i<0){
  142156. double acc=0;
  142157. int i;
  142158. for(i=0;i<vf->links;i++)
  142159. acc+=ov_time_total(vf,i);
  142160. return(acc);
  142161. }else{
  142162. return((double)(vf->pcmlengths[i*2+1])/vf->vi[i].rate);
  142163. }
  142164. }
  142165. int ov_raw_seek(OggVorbis_File *vf,ogg_int64_t pos){
  142166. ogg_stream_state work_os;
  142167. if(vf->ready_state<OPENED)return(OV_EINVAL);
  142168. if(!vf->seekable)
  142169. return(OV_ENOSEEK); /* don't dump machine if we can't seek */
  142170. if(pos<0 || pos>vf->end)return(OV_EINVAL);
  142171. vf->pcm_offset=-1;
  142172. ogg_stream_reset_serialno(&vf->os,
  142173. vf->current_serialno); /* must set serialno */
  142174. vorbis_synthesis_restart(&vf->vd);
  142175. _seek_helper(vf,pos);
  142176. {
  142177. ogg_page og;
  142178. ogg_packet op;
  142179. int lastblock=0;
  142180. int accblock=0;
  142181. int thisblock;
  142182. int eosflag;
  142183. ogg_stream_init(&work_os,vf->current_serialno); /* get the memory ready */
  142184. ogg_stream_reset(&work_os); /* eliminate the spurious OV_HOLE
  142185. return from not necessarily
  142186. starting from the beginning */
  142187. while(1){
  142188. if(vf->ready_state>=STREAMSET){
  142189. int result=ogg_stream_packetout(&work_os,&op);
  142190. if(result>0){
  142191. if(vf->vi[vf->current_link].codec_setup){
  142192. thisblock=vorbis_packet_blocksize(vf->vi+vf->current_link,&op);
  142193. if(thisblock<0){
  142194. ogg_stream_packetout(&vf->os,NULL);
  142195. thisblock=0;
  142196. }else{
  142197. if(eosflag)
  142198. ogg_stream_packetout(&vf->os,NULL);
  142199. else
  142200. if(lastblock)accblock+=(lastblock+thisblock)>>2;
  142201. }
  142202. if(op.granulepos!=-1){
  142203. int i,link=vf->current_link;
  142204. ogg_int64_t granulepos=op.granulepos-vf->pcmlengths[link*2];
  142205. if(granulepos<0)granulepos=0;
  142206. for(i=0;i<link;i++)
  142207. granulepos+=vf->pcmlengths[i*2+1];
  142208. vf->pcm_offset=granulepos-accblock;
  142209. break;
  142210. }
  142211. lastblock=thisblock;
  142212. continue;
  142213. }else
  142214. ogg_stream_packetout(&vf->os,NULL);
  142215. }
  142216. }
  142217. if(!lastblock){
  142218. if(_get_next_page(vf,&og,-1)<0){
  142219. vf->pcm_offset=ov_pcm_total(vf,-1);
  142220. break;
  142221. }
  142222. }else{
  142223. vf->pcm_offset=-1;
  142224. break;
  142225. }
  142226. if(vf->ready_state>=STREAMSET)
  142227. if(vf->current_serialno!=ogg_page_serialno(&og)){
  142228. _decode_clear(vf); /* clear out stream state */
  142229. ogg_stream_clear(&work_os);
  142230. }
  142231. if(vf->ready_state<STREAMSET){
  142232. int link;
  142233. vf->current_serialno=ogg_page_serialno(&og);
  142234. for(link=0;link<vf->links;link++)
  142235. if(vf->serialnos[link]==vf->current_serialno)break;
  142236. if(link==vf->links)goto seek_error; /* sign of a bogus stream.
  142237. error out, leave
  142238. machine uninitialized */
  142239. vf->current_link=link;
  142240. ogg_stream_reset_serialno(&vf->os,vf->current_serialno);
  142241. ogg_stream_reset_serialno(&work_os,vf->current_serialno);
  142242. vf->ready_state=STREAMSET;
  142243. }
  142244. ogg_stream_pagein(&vf->os,&og);
  142245. ogg_stream_pagein(&work_os,&og);
  142246. eosflag=ogg_page_eos(&og);
  142247. }
  142248. }
  142249. ogg_stream_clear(&work_os);
  142250. vf->bittrack=0.f;
  142251. vf->samptrack=0.f;
  142252. return(0);
  142253. seek_error:
  142254. vf->pcm_offset=-1;
  142255. ogg_stream_clear(&work_os);
  142256. _decode_clear(vf);
  142257. return OV_EBADLINK;
  142258. }
  142259. int ov_pcm_seek_page(OggVorbis_File *vf,ogg_int64_t pos){
  142260. int link=-1;
  142261. ogg_int64_t result=0;
  142262. ogg_int64_t total=ov_pcm_total(vf,-1);
  142263. if(vf->ready_state<OPENED)return(OV_EINVAL);
  142264. if(!vf->seekable)return(OV_ENOSEEK);
  142265. if(pos<0 || pos>total)return(OV_EINVAL);
  142266. for(link=vf->links-1;link>=0;link--){
  142267. total-=vf->pcmlengths[link*2+1];
  142268. if(pos>=total)break;
  142269. }
  142270. {
  142271. ogg_int64_t end=vf->offsets[link+1];
  142272. ogg_int64_t begin=vf->offsets[link];
  142273. ogg_int64_t begintime = vf->pcmlengths[link*2];
  142274. ogg_int64_t endtime = vf->pcmlengths[link*2+1]+begintime;
  142275. ogg_int64_t target=pos-total+begintime;
  142276. ogg_int64_t best=begin;
  142277. ogg_page og;
  142278. while(begin<end){
  142279. ogg_int64_t bisect;
  142280. if(end-begin<CHUNKSIZE){
  142281. bisect=begin;
  142282. }else{
  142283. bisect=begin +
  142284. (target-begintime)*(end-begin)/(endtime-begintime) - CHUNKSIZE;
  142285. if(bisect<=begin)
  142286. bisect=begin+1;
  142287. }
  142288. _seek_helper(vf,bisect);
  142289. while(begin<end){
  142290. result=_get_next_page(vf,&og,end-vf->offset);
  142291. if(result==OV_EREAD) goto seek_error;
  142292. if(result<0){
  142293. if(bisect<=begin+1)
  142294. end=begin; /* found it */
  142295. else{
  142296. if(bisect==0) goto seek_error;
  142297. bisect-=CHUNKSIZE;
  142298. if(bisect<=begin)bisect=begin+1;
  142299. _seek_helper(vf,bisect);
  142300. }
  142301. }else{
  142302. ogg_int64_t granulepos=ogg_page_granulepos(&og);
  142303. if(granulepos==-1)continue;
  142304. if(granulepos<target){
  142305. best=result; /* raw offset of packet with granulepos */
  142306. begin=vf->offset; /* raw offset of next page */
  142307. begintime=granulepos;
  142308. if(target-begintime>44100)break;
  142309. bisect=begin; /* *not* begin + 1 */
  142310. }else{
  142311. if(bisect<=begin+1)
  142312. end=begin; /* found it */
  142313. else{
  142314. if(end==vf->offset){ /* we're pretty close - we'd be stuck in */
  142315. end=result;
  142316. bisect-=CHUNKSIZE; /* an endless loop otherwise. */
  142317. if(bisect<=begin)bisect=begin+1;
  142318. _seek_helper(vf,bisect);
  142319. }else{
  142320. end=result;
  142321. endtime=granulepos;
  142322. break;
  142323. }
  142324. }
  142325. }
  142326. }
  142327. }
  142328. }
  142329. {
  142330. ogg_page og;
  142331. ogg_packet op;
  142332. _seek_helper(vf,best);
  142333. vf->pcm_offset=-1;
  142334. if(_get_next_page(vf,&og,-1)<0)return(OV_EOF); /* shouldn't happen */
  142335. if(link!=vf->current_link){
  142336. _decode_clear(vf);
  142337. vf->current_link=link;
  142338. vf->current_serialno=ogg_page_serialno(&og);
  142339. vf->ready_state=STREAMSET;
  142340. }else{
  142341. vorbis_synthesis_restart(&vf->vd);
  142342. }
  142343. ogg_stream_reset_serialno(&vf->os,vf->current_serialno);
  142344. ogg_stream_pagein(&vf->os,&og);
  142345. while(1){
  142346. result=ogg_stream_packetpeek(&vf->os,&op);
  142347. if(result==0){
  142348. _seek_helper(vf,best);
  142349. while(1){
  142350. result=_get_prev_page(vf,&og);
  142351. if(result<0) goto seek_error;
  142352. if(ogg_page_granulepos(&og)>-1 ||
  142353. !ogg_page_continued(&og)){
  142354. return ov_raw_seek(vf,result);
  142355. }
  142356. vf->offset=result;
  142357. }
  142358. }
  142359. if(result<0){
  142360. result = OV_EBADPACKET;
  142361. goto seek_error;
  142362. }
  142363. if(op.granulepos!=-1){
  142364. vf->pcm_offset=op.granulepos-vf->pcmlengths[vf->current_link*2];
  142365. if(vf->pcm_offset<0)vf->pcm_offset=0;
  142366. vf->pcm_offset+=total;
  142367. break;
  142368. }else
  142369. result=ogg_stream_packetout(&vf->os,NULL);
  142370. }
  142371. }
  142372. }
  142373. if(vf->pcm_offset>pos || pos>ov_pcm_total(vf,-1)){
  142374. result=OV_EFAULT;
  142375. goto seek_error;
  142376. }
  142377. vf->bittrack=0.f;
  142378. vf->samptrack=0.f;
  142379. return(0);
  142380. seek_error:
  142381. vf->pcm_offset=-1;
  142382. _decode_clear(vf);
  142383. return (int)result;
  142384. }
  142385. int ov_pcm_seek(OggVorbis_File *vf,ogg_int64_t pos){
  142386. int thisblock,lastblock=0;
  142387. int ret=ov_pcm_seek_page(vf,pos);
  142388. if(ret<0)return(ret);
  142389. if((ret=_make_decode_ready(vf)))return ret;
  142390. while(1){
  142391. ogg_packet op;
  142392. ogg_page og;
  142393. int ret=ogg_stream_packetpeek(&vf->os,&op);
  142394. if(ret>0){
  142395. thisblock=vorbis_packet_blocksize(vf->vi+vf->current_link,&op);
  142396. if(thisblock<0){
  142397. ogg_stream_packetout(&vf->os,NULL);
  142398. continue; /* non audio packet */
  142399. }
  142400. if(lastblock)vf->pcm_offset+=(lastblock+thisblock)>>2;
  142401. if(vf->pcm_offset+((thisblock+
  142402. vorbis_info_blocksize(vf->vi,1))>>2)>=pos)break;
  142403. ogg_stream_packetout(&vf->os,NULL);
  142404. vorbis_synthesis_trackonly(&vf->vb,&op); /* set up a vb with
  142405. only tracking, no
  142406. pcm_decode */
  142407. vorbis_synthesis_blockin(&vf->vd,&vf->vb);
  142408. if(op.granulepos>-1){
  142409. int i;
  142410. vf->pcm_offset=op.granulepos-vf->pcmlengths[vf->current_link*2];
  142411. if(vf->pcm_offset<0)vf->pcm_offset=0;
  142412. for(i=0;i<vf->current_link;i++)
  142413. vf->pcm_offset+=vf->pcmlengths[i*2+1];
  142414. }
  142415. lastblock=thisblock;
  142416. }else{
  142417. if(ret<0 && ret!=OV_HOLE)break;
  142418. if(_get_next_page(vf,&og,-1)<0)break;
  142419. if(vf->current_serialno!=ogg_page_serialno(&og))_decode_clear(vf);
  142420. if(vf->ready_state<STREAMSET){
  142421. int link;
  142422. vf->current_serialno=ogg_page_serialno(&og);
  142423. for(link=0;link<vf->links;link++)
  142424. if(vf->serialnos[link]==vf->current_serialno)break;
  142425. if(link==vf->links)return(OV_EBADLINK);
  142426. vf->current_link=link;
  142427. ogg_stream_reset_serialno(&vf->os,vf->current_serialno);
  142428. vf->ready_state=STREAMSET;
  142429. ret=_make_decode_ready(vf);
  142430. if(ret)return ret;
  142431. lastblock=0;
  142432. }
  142433. ogg_stream_pagein(&vf->os,&og);
  142434. }
  142435. }
  142436. vf->bittrack=0.f;
  142437. vf->samptrack=0.f;
  142438. while(vf->pcm_offset<pos){
  142439. ogg_int64_t target=pos-vf->pcm_offset;
  142440. long samples=vorbis_synthesis_pcmout(&vf->vd,NULL);
  142441. if(samples>target)samples=target;
  142442. vorbis_synthesis_read(&vf->vd,samples);
  142443. vf->pcm_offset+=samples;
  142444. if(samples<target)
  142445. if(_fetch_and_process_packet(vf,NULL,1,1)<=0)
  142446. vf->pcm_offset=ov_pcm_total(vf,-1); /* eof */
  142447. }
  142448. return 0;
  142449. }
  142450. int ov_time_seek(OggVorbis_File *vf,double seconds){
  142451. int link=-1;
  142452. ogg_int64_t pcm_total=ov_pcm_total(vf,-1);
  142453. double time_total=ov_time_total(vf,-1);
  142454. if(vf->ready_state<OPENED)return(OV_EINVAL);
  142455. if(!vf->seekable)return(OV_ENOSEEK);
  142456. if(seconds<0 || seconds>time_total)return(OV_EINVAL);
  142457. for(link=vf->links-1;link>=0;link--){
  142458. pcm_total-=vf->pcmlengths[link*2+1];
  142459. time_total-=ov_time_total(vf,link);
  142460. if(seconds>=time_total)break;
  142461. }
  142462. {
  142463. ogg_int64_t target=pcm_total+(seconds-time_total)*vf->vi[link].rate;
  142464. return(ov_pcm_seek(vf,target));
  142465. }
  142466. }
  142467. int ov_time_seek_page(OggVorbis_File *vf,double seconds){
  142468. int link=-1;
  142469. ogg_int64_t pcm_total=ov_pcm_total(vf,-1);
  142470. double time_total=ov_time_total(vf,-1);
  142471. if(vf->ready_state<OPENED)return(OV_EINVAL);
  142472. if(!vf->seekable)return(OV_ENOSEEK);
  142473. if(seconds<0 || seconds>time_total)return(OV_EINVAL);
  142474. for(link=vf->links-1;link>=0;link--){
  142475. pcm_total-=vf->pcmlengths[link*2+1];
  142476. time_total-=ov_time_total(vf,link);
  142477. if(seconds>=time_total)break;
  142478. }
  142479. {
  142480. ogg_int64_t target=pcm_total+(seconds-time_total)*vf->vi[link].rate;
  142481. return(ov_pcm_seek_page(vf,target));
  142482. }
  142483. }
  142484. ogg_int64_t ov_raw_tell(OggVorbis_File *vf){
  142485. if(vf->ready_state<OPENED)return(OV_EINVAL);
  142486. return(vf->offset);
  142487. }
  142488. ogg_int64_t ov_pcm_tell(OggVorbis_File *vf){
  142489. if(vf->ready_state<OPENED)return(OV_EINVAL);
  142490. return(vf->pcm_offset);
  142491. }
  142492. double ov_time_tell(OggVorbis_File *vf){
  142493. int link=0;
  142494. ogg_int64_t pcm_total=0;
  142495. double time_total=0.f;
  142496. if(vf->ready_state<OPENED)return(OV_EINVAL);
  142497. if(vf->seekable){
  142498. pcm_total=ov_pcm_total(vf,-1);
  142499. time_total=ov_time_total(vf,-1);
  142500. for(link=vf->links-1;link>=0;link--){
  142501. pcm_total-=vf->pcmlengths[link*2+1];
  142502. time_total-=ov_time_total(vf,link);
  142503. if(vf->pcm_offset>=pcm_total)break;
  142504. }
  142505. }
  142506. return((double)time_total+(double)(vf->pcm_offset-pcm_total)/vf->vi[link].rate);
  142507. }
  142508. vorbis_info *ov_info(OggVorbis_File *vf,int link){
  142509. if(vf->seekable){
  142510. if(link<0)
  142511. if(vf->ready_state>=STREAMSET)
  142512. return vf->vi+vf->current_link;
  142513. else
  142514. return vf->vi;
  142515. else
  142516. if(link>=vf->links)
  142517. return NULL;
  142518. else
  142519. return vf->vi+link;
  142520. }else{
  142521. return vf->vi;
  142522. }
  142523. }
  142524. vorbis_comment *ov_comment(OggVorbis_File *vf,int link){
  142525. if(vf->seekable){
  142526. if(link<0)
  142527. if(vf->ready_state>=STREAMSET)
  142528. return vf->vc+vf->current_link;
  142529. else
  142530. return vf->vc;
  142531. else
  142532. if(link>=vf->links)
  142533. return NULL;
  142534. else
  142535. return vf->vc+link;
  142536. }else{
  142537. return vf->vc;
  142538. }
  142539. }
  142540. static int host_is_big_endian() {
  142541. ogg_int32_t pattern = 0xfeedface; /* deadbeef */
  142542. unsigned char *bytewise = (unsigned char *)&pattern;
  142543. if (bytewise[0] == 0xfe) return 1;
  142544. return 0;
  142545. }
  142546. long ov_read(OggVorbis_File *vf,char *buffer,int length,
  142547. int bigendianp,int word,int sgned,int *bitstream){
  142548. int i,j;
  142549. int host_endian = host_is_big_endian();
  142550. float **pcm;
  142551. long samples;
  142552. if(vf->ready_state<OPENED)return(OV_EINVAL);
  142553. while(1){
  142554. if(vf->ready_state==INITSET){
  142555. samples=vorbis_synthesis_pcmout(&vf->vd,&pcm);
  142556. if(samples)break;
  142557. }
  142558. {
  142559. int ret=_fetch_and_process_packet(vf,NULL,1,1);
  142560. if(ret==OV_EOF)
  142561. return(0);
  142562. if(ret<=0)
  142563. return(ret);
  142564. }
  142565. }
  142566. if(samples>0){
  142567. long channels=ov_info(vf,-1)->channels;
  142568. long bytespersample=word * channels;
  142569. vorbis_fpu_control fpu;
  142570. (void) fpu; // (to avoid a warning about it being unused)
  142571. if(samples>length/bytespersample)samples=length/bytespersample;
  142572. if(samples <= 0)
  142573. return OV_EINVAL;
  142574. {
  142575. int val;
  142576. if(word==1){
  142577. int off=(sgned?0:128);
  142578. vorbis_fpu_setround(&fpu);
  142579. for(j=0;j<samples;j++)
  142580. for(i=0;i<channels;i++){
  142581. val=vorbis_ftoi(pcm[i][j]*128.f);
  142582. if(val>127)val=127;
  142583. else if(val<-128)val=-128;
  142584. *buffer++=val+off;
  142585. }
  142586. vorbis_fpu_restore(fpu);
  142587. }else{
  142588. int off=(sgned?0:32768);
  142589. if(host_endian==bigendianp){
  142590. if(sgned){
  142591. vorbis_fpu_setround(&fpu);
  142592. for(i=0;i<channels;i++) { /* It's faster in this order */
  142593. float *src=pcm[i];
  142594. short *dest=((short *)buffer)+i;
  142595. for(j=0;j<samples;j++) {
  142596. val=vorbis_ftoi(src[j]*32768.f);
  142597. if(val>32767)val=32767;
  142598. else if(val<-32768)val=-32768;
  142599. *dest=val;
  142600. dest+=channels;
  142601. }
  142602. }
  142603. vorbis_fpu_restore(fpu);
  142604. }else{
  142605. vorbis_fpu_setround(&fpu);
  142606. for(i=0;i<channels;i++) {
  142607. float *src=pcm[i];
  142608. short *dest=((short *)buffer)+i;
  142609. for(j=0;j<samples;j++) {
  142610. val=vorbis_ftoi(src[j]*32768.f);
  142611. if(val>32767)val=32767;
  142612. else if(val<-32768)val=-32768;
  142613. *dest=val+off;
  142614. dest+=channels;
  142615. }
  142616. }
  142617. vorbis_fpu_restore(fpu);
  142618. }
  142619. }else if(bigendianp){
  142620. vorbis_fpu_setround(&fpu);
  142621. for(j=0;j<samples;j++)
  142622. for(i=0;i<channels;i++){
  142623. val=vorbis_ftoi(pcm[i][j]*32768.f);
  142624. if(val>32767)val=32767;
  142625. else if(val<-32768)val=-32768;
  142626. val+=off;
  142627. *buffer++=(val>>8);
  142628. *buffer++=(val&0xff);
  142629. }
  142630. vorbis_fpu_restore(fpu);
  142631. }else{
  142632. int val;
  142633. vorbis_fpu_setround(&fpu);
  142634. for(j=0;j<samples;j++)
  142635. for(i=0;i<channels;i++){
  142636. val=vorbis_ftoi(pcm[i][j]*32768.f);
  142637. if(val>32767)val=32767;
  142638. else if(val<-32768)val=-32768;
  142639. val+=off;
  142640. *buffer++=(val&0xff);
  142641. *buffer++=(val>>8);
  142642. }
  142643. vorbis_fpu_restore(fpu);
  142644. }
  142645. }
  142646. }
  142647. vorbis_synthesis_read(&vf->vd,samples);
  142648. vf->pcm_offset+=samples;
  142649. if(bitstream)*bitstream=vf->current_link;
  142650. return(samples*bytespersample);
  142651. }else{
  142652. return(samples);
  142653. }
  142654. }
  142655. long ov_read_float(OggVorbis_File *vf,float ***pcm_channels,int length,
  142656. int *bitstream){
  142657. if(vf->ready_state<OPENED)return(OV_EINVAL);
  142658. while(1){
  142659. if(vf->ready_state==INITSET){
  142660. float **pcm;
  142661. long samples=vorbis_synthesis_pcmout(&vf->vd,&pcm);
  142662. if(samples){
  142663. if(pcm_channels)*pcm_channels=pcm;
  142664. if(samples>length)samples=length;
  142665. vorbis_synthesis_read(&vf->vd,samples);
  142666. vf->pcm_offset+=samples;
  142667. if(bitstream)*bitstream=vf->current_link;
  142668. return samples;
  142669. }
  142670. }
  142671. {
  142672. int ret=_fetch_and_process_packet(vf,NULL,1,1);
  142673. if(ret==OV_EOF)return(0);
  142674. if(ret<=0)return(ret);
  142675. }
  142676. }
  142677. }
  142678. extern float *vorbis_window(vorbis_dsp_state *v,int W);
  142679. extern void _analysis_output_always(const char *base,int i,float *v,int n,int bark,int dB,
  142680. ogg_int64_t off);
  142681. static void _ov_splice(float **pcm,float **lappcm,
  142682. int n1, int n2,
  142683. int ch1, int ch2,
  142684. float *w1, float *w2){
  142685. int i,j;
  142686. float *w=w1;
  142687. int n=n1;
  142688. if(n1>n2){
  142689. n=n2;
  142690. w=w2;
  142691. }
  142692. for(j=0;j<ch1 && j<ch2;j++){
  142693. float *s=lappcm[j];
  142694. float *d=pcm[j];
  142695. for(i=0;i<n;i++){
  142696. float wd=w[i]*w[i];
  142697. float ws=1.-wd;
  142698. d[i]=d[i]*wd + s[i]*ws;
  142699. }
  142700. }
  142701. for(;j<ch2;j++){
  142702. float *d=pcm[j];
  142703. for(i=0;i<n;i++){
  142704. float wd=w[i]*w[i];
  142705. d[i]=d[i]*wd;
  142706. }
  142707. }
  142708. }
  142709. static int _ov_initset(OggVorbis_File *vf){
  142710. while(1){
  142711. if(vf->ready_state==INITSET)break;
  142712. {
  142713. int ret=_fetch_and_process_packet(vf,NULL,1,0);
  142714. if(ret<0 && ret!=OV_HOLE)return(ret);
  142715. }
  142716. }
  142717. return 0;
  142718. }
  142719. static int _ov_initprime(OggVorbis_File *vf){
  142720. vorbis_dsp_state *vd=&vf->vd;
  142721. while(1){
  142722. if(vf->ready_state==INITSET)
  142723. if(vorbis_synthesis_pcmout(vd,NULL))break;
  142724. {
  142725. int ret=_fetch_and_process_packet(vf,NULL,1,0);
  142726. if(ret<0 && ret!=OV_HOLE)return(ret);
  142727. }
  142728. }
  142729. return 0;
  142730. }
  142731. static void _ov_getlap(OggVorbis_File *vf,vorbis_info *vi,vorbis_dsp_state *vd,
  142732. float **lappcm,int lapsize){
  142733. int lapcount=0,i;
  142734. float **pcm;
  142735. while(lapcount<lapsize){
  142736. int samples=vorbis_synthesis_pcmout(vd,&pcm);
  142737. if(samples){
  142738. if(samples>lapsize-lapcount)samples=lapsize-lapcount;
  142739. for(i=0;i<vi->channels;i++)
  142740. memcpy(lappcm[i]+lapcount,pcm[i],sizeof(**pcm)*samples);
  142741. lapcount+=samples;
  142742. vorbis_synthesis_read(vd,samples);
  142743. }else{
  142744. int ret=_fetch_and_process_packet(vf,NULL,1,0); /* do *not* span */
  142745. if(ret==OV_EOF)break;
  142746. }
  142747. }
  142748. if(lapcount<lapsize){
  142749. int samples=vorbis_synthesis_lapout(&vf->vd,&pcm);
  142750. if(samples==0){
  142751. for(i=0;i<vi->channels;i++)
  142752. memset(lappcm[i]+lapcount,0,sizeof(**pcm)*lapsize-lapcount);
  142753. lapcount=lapsize;
  142754. }else{
  142755. if(samples>lapsize-lapcount)samples=lapsize-lapcount;
  142756. for(i=0;i<vi->channels;i++)
  142757. memcpy(lappcm[i]+lapcount,pcm[i],sizeof(**pcm)*samples);
  142758. lapcount+=samples;
  142759. }
  142760. }
  142761. }
  142762. int ov_crosslap(OggVorbis_File *vf1, OggVorbis_File *vf2){
  142763. vorbis_info *vi1,*vi2;
  142764. float **lappcm;
  142765. float **pcm;
  142766. float *w1,*w2;
  142767. int n1,n2,i,ret,hs1,hs2;
  142768. if(vf1==vf2)return(0); /* degenerate case */
  142769. if(vf1->ready_state<OPENED)return(OV_EINVAL);
  142770. if(vf2->ready_state<OPENED)return(OV_EINVAL);
  142771. ret=_ov_initset(vf1);
  142772. if(ret)return(ret);
  142773. ret=_ov_initprime(vf2);
  142774. if(ret)return(ret);
  142775. vi1=ov_info(vf1,-1);
  142776. vi2=ov_info(vf2,-1);
  142777. hs1=ov_halfrate_p(vf1);
  142778. hs2=ov_halfrate_p(vf2);
  142779. lappcm=(float**) alloca(sizeof(*lappcm)*vi1->channels);
  142780. n1=vorbis_info_blocksize(vi1,0)>>(1+hs1);
  142781. n2=vorbis_info_blocksize(vi2,0)>>(1+hs2);
  142782. w1=vorbis_window(&vf1->vd,0);
  142783. w2=vorbis_window(&vf2->vd,0);
  142784. for(i=0;i<vi1->channels;i++)
  142785. lappcm[i]=(float*) alloca(sizeof(**lappcm)*n1);
  142786. _ov_getlap(vf1,vi1,&vf1->vd,lappcm,n1);
  142787. vorbis_synthesis_lapout(&vf2->vd,&pcm);
  142788. _analysis_output_always("pcmL",0,pcm[0],n1*2,0,0,0);
  142789. _analysis_output_always("pcmR",0,pcm[1],n1*2,0,0,0);
  142790. _ov_splice(pcm,lappcm,n1,n2,vi1->channels,vi2->channels,w1,w2);
  142791. return(0);
  142792. }
  142793. static int _ov_64_seek_lap(OggVorbis_File *vf,ogg_int64_t pos,
  142794. int (*localseek)(OggVorbis_File *,ogg_int64_t)){
  142795. vorbis_info *vi;
  142796. float **lappcm;
  142797. float **pcm;
  142798. float *w1,*w2;
  142799. int n1,n2,ch1,ch2,hs;
  142800. int i,ret;
  142801. if(vf->ready_state<OPENED)return(OV_EINVAL);
  142802. ret=_ov_initset(vf);
  142803. if(ret)return(ret);
  142804. vi=ov_info(vf,-1);
  142805. hs=ov_halfrate_p(vf);
  142806. ch1=vi->channels;
  142807. n1=vorbis_info_blocksize(vi,0)>>(1+hs);
  142808. w1=vorbis_window(&vf->vd,0); /* window arrays from libvorbis are
  142809. persistent; even if the decode state
  142810. from this link gets dumped, this
  142811. window array continues to exist */
  142812. lappcm=(float**) alloca(sizeof(*lappcm)*ch1);
  142813. for(i=0;i<ch1;i++)
  142814. lappcm[i]=(float*) alloca(sizeof(**lappcm)*n1);
  142815. _ov_getlap(vf,vi,&vf->vd,lappcm,n1);
  142816. ret=localseek(vf,pos);
  142817. if(ret)return ret;
  142818. ret=_ov_initprime(vf);
  142819. if(ret)return(ret);
  142820. vi=ov_info(vf,-1);
  142821. ch2=vi->channels;
  142822. n2=vorbis_info_blocksize(vi,0)>>(1+hs);
  142823. w2=vorbis_window(&vf->vd,0);
  142824. vorbis_synthesis_lapout(&vf->vd,&pcm);
  142825. _ov_splice(pcm,lappcm,n1,n2,ch1,ch2,w1,w2);
  142826. return(0);
  142827. }
  142828. int ov_raw_seek_lap(OggVorbis_File *vf,ogg_int64_t pos){
  142829. return _ov_64_seek_lap(vf,pos,ov_raw_seek);
  142830. }
  142831. int ov_pcm_seek_lap(OggVorbis_File *vf,ogg_int64_t pos){
  142832. return _ov_64_seek_lap(vf,pos,ov_pcm_seek);
  142833. }
  142834. int ov_pcm_seek_page_lap(OggVorbis_File *vf,ogg_int64_t pos){
  142835. return _ov_64_seek_lap(vf,pos,ov_pcm_seek_page);
  142836. }
  142837. static int _ov_d_seek_lap(OggVorbis_File *vf,double pos,
  142838. int (*localseek)(OggVorbis_File *,double)){
  142839. vorbis_info *vi;
  142840. float **lappcm;
  142841. float **pcm;
  142842. float *w1,*w2;
  142843. int n1,n2,ch1,ch2,hs;
  142844. int i,ret;
  142845. if(vf->ready_state<OPENED)return(OV_EINVAL);
  142846. ret=_ov_initset(vf);
  142847. if(ret)return(ret);
  142848. vi=ov_info(vf,-1);
  142849. hs=ov_halfrate_p(vf);
  142850. ch1=vi->channels;
  142851. n1=vorbis_info_blocksize(vi,0)>>(1+hs);
  142852. w1=vorbis_window(&vf->vd,0); /* window arrays from libvorbis are
  142853. persistent; even if the decode state
  142854. from this link gets dumped, this
  142855. window array continues to exist */
  142856. lappcm=(float**) alloca(sizeof(*lappcm)*ch1);
  142857. for(i=0;i<ch1;i++)
  142858. lappcm[i]=(float*) alloca(sizeof(**lappcm)*n1);
  142859. _ov_getlap(vf,vi,&vf->vd,lappcm,n1);
  142860. ret=localseek(vf,pos);
  142861. if(ret)return ret;
  142862. ret=_ov_initprime(vf);
  142863. if(ret)return(ret);
  142864. vi=ov_info(vf,-1);
  142865. ch2=vi->channels;
  142866. n2=vorbis_info_blocksize(vi,0)>>(1+hs);
  142867. w2=vorbis_window(&vf->vd,0);
  142868. vorbis_synthesis_lapout(&vf->vd,&pcm);
  142869. _ov_splice(pcm,lappcm,n1,n2,ch1,ch2,w1,w2);
  142870. return(0);
  142871. }
  142872. int ov_time_seek_lap(OggVorbis_File *vf,double pos){
  142873. return _ov_d_seek_lap(vf,pos,ov_time_seek);
  142874. }
  142875. int ov_time_seek_page_lap(OggVorbis_File *vf,double pos){
  142876. return _ov_d_seek_lap(vf,pos,ov_time_seek_page);
  142877. }
  142878. #endif
  142879. /********* End of inlined file: vorbisfile.c *********/
  142880. /********* Start of inlined file: window.c *********/
  142881. /********* Start of inlined file: juce_OggVorbisHeader.h *********/
  142882. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  142883. // tasks..
  142884. #if JUCE_MSVC
  142885. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  142886. #endif
  142887. /********* End of inlined file: juce_OggVorbisHeader.h *********/
  142888. #if JUCE_USE_OGGVORBIS
  142889. #include <stdlib.h>
  142890. #include <math.h>
  142891. static float vwin64[32] = {
  142892. 0.0009460463F, 0.0085006468F, 0.0235352254F, 0.0458950567F,
  142893. 0.0753351908F, 0.1115073077F, 0.1539457973F, 0.2020557475F,
  142894. 0.2551056759F, 0.3122276645F, 0.3724270287F, 0.4346027792F,
  142895. 0.4975789974F, 0.5601459521F, 0.6211085051F, 0.6793382689F,
  142896. 0.7338252629F, 0.7837245849F, 0.8283939355F, 0.8674186656F,
  142897. 0.9006222429F, 0.9280614787F, 0.9500073081F, 0.9669131782F,
  142898. 0.9793740220F, 0.9880792941F, 0.9937636139F, 0.9971582668F,
  142899. 0.9989462667F, 0.9997230082F, 0.9999638688F, 0.9999995525F,
  142900. };
  142901. static float vwin128[64] = {
  142902. 0.0002365472F, 0.0021280687F, 0.0059065254F, 0.0115626550F,
  142903. 0.0190823442F, 0.0284463735F, 0.0396300935F, 0.0526030430F,
  142904. 0.0673285281F, 0.0837631763F, 0.1018564887F, 0.1215504095F,
  142905. 0.1427789367F, 0.1654677960F, 0.1895342001F, 0.2148867160F,
  142906. 0.2414252576F, 0.2690412240F, 0.2976177952F, 0.3270303960F,
  142907. 0.3571473350F, 0.3878306189F, 0.4189369387F, 0.4503188188F,
  142908. 0.4818259135F, 0.5133064334F, 0.5446086751F, 0.5755826278F,
  142909. 0.6060816248F, 0.6359640047F, 0.6650947483F, 0.6933470543F,
  142910. 0.7206038179F, 0.7467589810F, 0.7717187213F, 0.7954024542F,
  142911. 0.8177436264F, 0.8386902831F, 0.8582053981F, 0.8762669622F,
  142912. 0.8928678298F, 0.9080153310F, 0.9217306608F, 0.9340480615F,
  142913. 0.9450138200F, 0.9546851041F, 0.9631286621F, 0.9704194171F,
  142914. 0.9766389810F, 0.9818741197F, 0.9862151938F, 0.9897546035F,
  142915. 0.9925852598F, 0.9947991032F, 0.9964856900F, 0.9977308602F,
  142916. 0.9986155015F, 0.9992144193F, 0.9995953200F, 0.9998179155F,
  142917. 0.9999331503F, 0.9999825563F, 0.9999977357F, 0.9999999720F,
  142918. };
  142919. static float vwin256[128] = {
  142920. 0.0000591390F, 0.0005321979F, 0.0014780301F, 0.0028960636F,
  142921. 0.0047854363F, 0.0071449926F, 0.0099732775F, 0.0132685298F,
  142922. 0.0170286741F, 0.0212513119F, 0.0259337111F, 0.0310727950F,
  142923. 0.0366651302F, 0.0427069140F, 0.0491939614F, 0.0561216907F,
  142924. 0.0634851102F, 0.0712788035F, 0.0794969160F, 0.0881331402F,
  142925. 0.0971807028F, 0.1066323515F, 0.1164803426F, 0.1267164297F,
  142926. 0.1373318534F, 0.1483173323F, 0.1596630553F, 0.1713586755F,
  142927. 0.1833933062F, 0.1957555184F, 0.2084333404F, 0.2214142599F,
  142928. 0.2346852280F, 0.2482326664F, 0.2620424757F, 0.2761000481F,
  142929. 0.2903902813F, 0.3048975959F, 0.3196059553F, 0.3344988887F,
  142930. 0.3495595160F, 0.3647705766F, 0.3801144597F, 0.3955732382F,
  142931. 0.4111287047F, 0.4267624093F, 0.4424557009F, 0.4581897696F,
  142932. 0.4739456913F, 0.4897044744F, 0.5054471075F, 0.5211546088F,
  142933. 0.5368080763F, 0.5523887395F, 0.5678780103F, 0.5832575361F,
  142934. 0.5985092508F, 0.6136154277F, 0.6285587300F, 0.6433222619F,
  142935. 0.6578896175F, 0.6722449294F, 0.6863729144F, 0.7002589187F,
  142936. 0.7138889597F, 0.7272497662F, 0.7403288154F, 0.7531143679F,
  142937. 0.7655954985F, 0.7777621249F, 0.7896050322F, 0.8011158947F,
  142938. 0.8122872932F, 0.8231127294F, 0.8335866365F, 0.8437043850F,
  142939. 0.8534622861F, 0.8628575905F, 0.8718884835F, 0.8805540765F,
  142940. 0.8888543947F, 0.8967903616F, 0.9043637797F, 0.9115773078F,
  142941. 0.9184344360F, 0.9249394562F, 0.9310974312F, 0.9369141608F,
  142942. 0.9423961446F, 0.9475505439F, 0.9523851406F, 0.9569082947F,
  142943. 0.9611289005F, 0.9650563408F, 0.9687004405F, 0.9720714191F,
  142944. 0.9751798427F, 0.9780365753F, 0.9806527301F, 0.9830396204F,
  142945. 0.9852087111F, 0.9871715701F, 0.9889398207F, 0.9905250941F,
  142946. 0.9919389832F, 0.9931929973F, 0.9942985174F, 0.9952667537F,
  142947. 0.9961087037F, 0.9968351119F, 0.9974564312F, 0.9979827858F,
  142948. 0.9984239359F, 0.9987892441F, 0.9990876435F, 0.9993276081F,
  142949. 0.9995171241F, 0.9996636648F, 0.9997741654F, 0.9998550016F,
  142950. 0.9999119692F, 0.9999502656F, 0.9999744742F, 0.9999885497F,
  142951. 0.9999958064F, 0.9999989077F, 0.9999998584F, 0.9999999983F,
  142952. };
  142953. static float vwin512[256] = {
  142954. 0.0000147849F, 0.0001330607F, 0.0003695946F, 0.0007243509F,
  142955. 0.0011972759F, 0.0017882983F, 0.0024973285F, 0.0033242588F,
  142956. 0.0042689632F, 0.0053312973F, 0.0065110982F, 0.0078081841F,
  142957. 0.0092223540F, 0.0107533880F, 0.0124010466F, 0.0141650703F,
  142958. 0.0160451800F, 0.0180410758F, 0.0201524373F, 0.0223789233F,
  142959. 0.0247201710F, 0.0271757958F, 0.0297453914F, 0.0324285286F,
  142960. 0.0352247556F, 0.0381335972F, 0.0411545545F, 0.0442871045F,
  142961. 0.0475306997F, 0.0508847676F, 0.0543487103F, 0.0579219038F,
  142962. 0.0616036982F, 0.0653934164F, 0.0692903546F, 0.0732937809F,
  142963. 0.0774029356F, 0.0816170305F, 0.0859352485F, 0.0903567428F,
  142964. 0.0948806375F, 0.0995060259F, 0.1042319712F, 0.1090575056F,
  142965. 0.1139816300F, 0.1190033137F, 0.1241214941F, 0.1293350764F,
  142966. 0.1346429333F, 0.1400439046F, 0.1455367974F, 0.1511203852F,
  142967. 0.1567934083F, 0.1625545735F, 0.1684025537F, 0.1743359881F,
  142968. 0.1803534820F, 0.1864536069F, 0.1926349000F, 0.1988958650F,
  142969. 0.2052349715F, 0.2116506555F, 0.2181413191F, 0.2247053313F,
  142970. 0.2313410275F, 0.2380467105F, 0.2448206500F, 0.2516610835F,
  142971. 0.2585662164F, 0.2655342226F, 0.2725632448F, 0.2796513950F,
  142972. 0.2867967551F, 0.2939973773F, 0.3012512852F, 0.3085564739F,
  142973. 0.3159109111F, 0.3233125375F, 0.3307592680F, 0.3382489922F,
  142974. 0.3457795756F, 0.3533488602F, 0.3609546657F, 0.3685947904F,
  142975. 0.3762670121F, 0.3839690896F, 0.3916987634F, 0.3994537572F,
  142976. 0.4072317788F, 0.4150305215F, 0.4228476653F, 0.4306808783F,
  142977. 0.4385278181F, 0.4463861329F, 0.4542534630F, 0.4621274424F,
  142978. 0.4700057001F, 0.4778858615F, 0.4857655502F, 0.4936423891F,
  142979. 0.5015140023F, 0.5093780165F, 0.5172320626F, 0.5250737772F,
  142980. 0.5329008043F, 0.5407107971F, 0.5485014192F, 0.5562703465F,
  142981. 0.5640152688F, 0.5717338914F, 0.5794239366F, 0.5870831457F,
  142982. 0.5947092801F, 0.6023001235F, 0.6098534829F, 0.6173671907F,
  142983. 0.6248391059F, 0.6322671161F, 0.6396491384F, 0.6469831217F,
  142984. 0.6542670475F, 0.6614989319F, 0.6686768267F, 0.6757988210F,
  142985. 0.6828630426F, 0.6898676592F, 0.6968108799F, 0.7036909564F,
  142986. 0.7105061843F, 0.7172549043F, 0.7239355032F, 0.7305464154F,
  142987. 0.7370861235F, 0.7435531598F, 0.7499461068F, 0.7562635986F,
  142988. 0.7625043214F, 0.7686670148F, 0.7747504721F, 0.7807535410F,
  142989. 0.7866751247F, 0.7925141825F, 0.7982697296F, 0.8039408387F,
  142990. 0.8095266395F, 0.8150263196F, 0.8204391248F, 0.8257643590F,
  142991. 0.8310013848F, 0.8361496236F, 0.8412085555F, 0.8461777194F,
  142992. 0.8510567129F, 0.8558451924F, 0.8605428730F, 0.8651495278F,
  142993. 0.8696649882F, 0.8740891432F, 0.8784219392F, 0.8826633797F,
  142994. 0.8868135244F, 0.8908724888F, 0.8948404441F, 0.8987176157F,
  142995. 0.9025042831F, 0.9062007791F, 0.9098074886F, 0.9133248482F,
  142996. 0.9167533451F, 0.9200935163F, 0.9233459472F, 0.9265112712F,
  142997. 0.9295901680F, 0.9325833632F, 0.9354916263F, 0.9383157705F,
  142998. 0.9410566504F, 0.9437151618F, 0.9462922398F, 0.9487888576F,
  142999. 0.9512060252F, 0.9535447882F, 0.9558062262F, 0.9579914516F,
  143000. 0.9601016078F, 0.9621378683F, 0.9641014348F, 0.9659935361F,
  143001. 0.9678154261F, 0.9695683830F, 0.9712537071F, 0.9728727198F,
  143002. 0.9744267618F, 0.9759171916F, 0.9773453842F, 0.9787127293F,
  143003. 0.9800206298F, 0.9812705006F, 0.9824637665F, 0.9836018613F,
  143004. 0.9846862258F, 0.9857183066F, 0.9866995544F, 0.9876314227F,
  143005. 0.9885153662F, 0.9893528393F, 0.9901452948F, 0.9908941823F,
  143006. 0.9916009470F, 0.9922670279F, 0.9928938570F, 0.9934828574F,
  143007. 0.9940354423F, 0.9945530133F, 0.9950369595F, 0.9954886562F,
  143008. 0.9959094633F, 0.9963007242F, 0.9966637649F, 0.9969998925F,
  143009. 0.9973103939F, 0.9975965351F, 0.9978595598F, 0.9981006885F,
  143010. 0.9983211172F, 0.9985220166F, 0.9987045311F, 0.9988697776F,
  143011. 0.9990188449F, 0.9991527924F, 0.9992726499F, 0.9993794157F,
  143012. 0.9994740570F, 0.9995575079F, 0.9996306699F, 0.9996944099F,
  143013. 0.9997495605F, 0.9997969190F, 0.9998372465F, 0.9998712678F,
  143014. 0.9998996704F, 0.9999231041F, 0.9999421807F, 0.9999574732F,
  143015. 0.9999695157F, 0.9999788026F, 0.9999857885F, 0.9999908879F,
  143016. 0.9999944746F, 0.9999968817F, 0.9999984010F, 0.9999992833F,
  143017. 0.9999997377F, 0.9999999317F, 0.9999999911F, 0.9999999999F,
  143018. };
  143019. static float vwin1024[512] = {
  143020. 0.0000036962F, 0.0000332659F, 0.0000924041F, 0.0001811086F,
  143021. 0.0002993761F, 0.0004472021F, 0.0006245811F, 0.0008315063F,
  143022. 0.0010679699F, 0.0013339631F, 0.0016294757F, 0.0019544965F,
  143023. 0.0023090133F, 0.0026930125F, 0.0031064797F, 0.0035493989F,
  143024. 0.0040217533F, 0.0045235250F, 0.0050546946F, 0.0056152418F,
  143025. 0.0062051451F, 0.0068243817F, 0.0074729278F, 0.0081507582F,
  143026. 0.0088578466F, 0.0095941655F, 0.0103596863F, 0.0111543789F,
  143027. 0.0119782122F, 0.0128311538F, 0.0137131701F, 0.0146242260F,
  143028. 0.0155642855F, 0.0165333111F, 0.0175312640F, 0.0185581042F,
  143029. 0.0196137903F, 0.0206982797F, 0.0218115284F, 0.0229534910F,
  143030. 0.0241241208F, 0.0253233698F, 0.0265511886F, 0.0278075263F,
  143031. 0.0290923308F, 0.0304055484F, 0.0317471241F, 0.0331170013F,
  143032. 0.0345151222F, 0.0359414274F, 0.0373958560F, 0.0388783456F,
  143033. 0.0403888325F, 0.0419272511F, 0.0434935347F, 0.0450876148F,
  143034. 0.0467094213F, 0.0483588828F, 0.0500359261F, 0.0517404765F,
  143035. 0.0534724575F, 0.0552317913F, 0.0570183983F, 0.0588321971F,
  143036. 0.0606731048F, 0.0625410369F, 0.0644359070F, 0.0663576272F,
  143037. 0.0683061077F, 0.0702812571F, 0.0722829821F, 0.0743111878F,
  143038. 0.0763657775F, 0.0784466526F, 0.0805537129F, 0.0826868561F,
  143039. 0.0848459782F, 0.0870309736F, 0.0892417345F, 0.0914781514F,
  143040. 0.0937401128F, 0.0960275056F, 0.0983402145F, 0.1006781223F,
  143041. 0.1030411101F, 0.1054290568F, 0.1078418397F, 0.1102793336F,
  143042. 0.1127414119F, 0.1152279457F, 0.1177388042F, 0.1202738544F,
  143043. 0.1228329618F, 0.1254159892F, 0.1280227980F, 0.1306532471F,
  143044. 0.1333071937F, 0.1359844927F, 0.1386849970F, 0.1414085575F,
  143045. 0.1441550230F, 0.1469242403F, 0.1497160539F, 0.1525303063F,
  143046. 0.1553668381F, 0.1582254875F, 0.1611060909F, 0.1640084822F,
  143047. 0.1669324936F, 0.1698779549F, 0.1728446939F, 0.1758325362F,
  143048. 0.1788413055F, 0.1818708232F, 0.1849209084F, 0.1879913785F,
  143049. 0.1910820485F, 0.1941927312F, 0.1973232376F, 0.2004733764F,
  143050. 0.2036429541F, 0.2068317752F, 0.2100396421F, 0.2132663552F,
  143051. 0.2165117125F, 0.2197755102F, 0.2230575422F, 0.2263576007F,
  143052. 0.2296754753F, 0.2330109540F, 0.2363638225F, 0.2397338646F,
  143053. 0.2431208619F, 0.2465245941F, 0.2499448389F, 0.2533813719F,
  143054. 0.2568339669F, 0.2603023956F, 0.2637864277F, 0.2672858312F,
  143055. 0.2708003718F, 0.2743298135F, 0.2778739186F, 0.2814324472F,
  143056. 0.2850051576F, 0.2885918065F, 0.2921921485F, 0.2958059366F,
  143057. 0.2994329219F, 0.3030728538F, 0.3067254799F, 0.3103905462F,
  143058. 0.3140677969F, 0.3177569747F, 0.3214578205F, 0.3251700736F,
  143059. 0.3288934718F, 0.3326277513F, 0.3363726468F, 0.3401278914F,
  143060. 0.3438932168F, 0.3476683533F, 0.3514530297F, 0.3552469734F,
  143061. 0.3590499106F, 0.3628615659F, 0.3666816630F, 0.3705099239F,
  143062. 0.3743460698F, 0.3781898204F, 0.3820408945F, 0.3858990095F,
  143063. 0.3897638820F, 0.3936352274F, 0.3975127601F, 0.4013961936F,
  143064. 0.4052852405F, 0.4091796123F, 0.4130790198F, 0.4169831732F,
  143065. 0.4208917815F, 0.4248045534F, 0.4287211965F, 0.4326414181F,
  143066. 0.4365649248F, 0.4404914225F, 0.4444206167F, 0.4483522125F,
  143067. 0.4522859146F, 0.4562214270F, 0.4601584538F, 0.4640966984F,
  143068. 0.4680358644F, 0.4719756548F, 0.4759157726F, 0.4798559209F,
  143069. 0.4837958024F, 0.4877351199F, 0.4916735765F, 0.4956108751F,
  143070. 0.4995467188F, 0.5034808109F, 0.5074128550F, 0.5113425550F,
  143071. 0.5152696149F, 0.5191937395F, 0.5231146336F, 0.5270320028F,
  143072. 0.5309455530F, 0.5348549910F, 0.5387600239F, 0.5426603597F,
  143073. 0.5465557070F, 0.5504457754F, 0.5543302752F, 0.5582089175F,
  143074. 0.5620814145F, 0.5659474793F, 0.5698068262F, 0.5736591704F,
  143075. 0.5775042283F, 0.5813417176F, 0.5851713571F, 0.5889928670F,
  143076. 0.5928059689F, 0.5966103856F, 0.6004058415F, 0.6041920626F,
  143077. 0.6079687761F, 0.6117357113F, 0.6154925986F, 0.6192391705F,
  143078. 0.6229751612F, 0.6267003064F, 0.6304143441F, 0.6341170137F,
  143079. 0.6378080569F, 0.6414872173F, 0.6451542405F, 0.6488088741F,
  143080. 0.6524508681F, 0.6560799742F, 0.6596959469F, 0.6632985424F,
  143081. 0.6668875197F, 0.6704626398F, 0.6740236662F, 0.6775703649F,
  143082. 0.6811025043F, 0.6846198554F, 0.6881221916F, 0.6916092892F,
  143083. 0.6950809269F, 0.6985368861F, 0.7019769510F, 0.7054009085F,
  143084. 0.7088085484F, 0.7121996632F, 0.7155740484F, 0.7189315023F,
  143085. 0.7222718263F, 0.7255948245F, 0.7289003043F, 0.7321880760F,
  143086. 0.7354579530F, 0.7387097518F, 0.7419432921F, 0.7451583966F,
  143087. 0.7483548915F, 0.7515326059F, 0.7546913723F, 0.7578310265F,
  143088. 0.7609514077F, 0.7640523581F, 0.7671337237F, 0.7701953535F,
  143089. 0.7732371001F, 0.7762588195F, 0.7792603711F, 0.7822416178F,
  143090. 0.7852024259F, 0.7881426654F, 0.7910622097F, 0.7939609356F,
  143091. 0.7968387237F, 0.7996954579F, 0.8025310261F, 0.8053453193F,
  143092. 0.8081382324F, 0.8109096638F, 0.8136595156F, 0.8163876936F,
  143093. 0.8190941071F, 0.8217786690F, 0.8244412960F, 0.8270819086F,
  143094. 0.8297004305F, 0.8322967896F, 0.8348709171F, 0.8374227481F,
  143095. 0.8399522213F, 0.8424592789F, 0.8449438672F, 0.8474059356F,
  143096. 0.8498454378F, 0.8522623306F, 0.8546565748F, 0.8570281348F,
  143097. 0.8593769787F, 0.8617030779F, 0.8640064080F, 0.8662869477F,
  143098. 0.8685446796F, 0.8707795899F, 0.8729916682F, 0.8751809079F,
  143099. 0.8773473059F, 0.8794908626F, 0.8816115819F, 0.8837094713F,
  143100. 0.8857845418F, 0.8878368079F, 0.8898662874F, 0.8918730019F,
  143101. 0.8938569760F, 0.8958182380F, 0.8977568194F, 0.8996727552F,
  143102. 0.9015660837F, 0.9034368465F, 0.9052850885F, 0.9071108577F,
  143103. 0.9089142057F, 0.9106951869F, 0.9124538591F, 0.9141902832F,
  143104. 0.9159045233F, 0.9175966464F, 0.9192667228F, 0.9209148257F,
  143105. 0.9225410313F, 0.9241454187F, 0.9257280701F, 0.9272890704F,
  143106. 0.9288285075F, 0.9303464720F, 0.9318430576F, 0.9333183603F,
  143107. 0.9347724792F, 0.9362055158F, 0.9376175745F, 0.9390087622F,
  143108. 0.9403791881F, 0.9417289644F, 0.9430582055F, 0.9443670283F,
  143109. 0.9456555521F, 0.9469238986F, 0.9481721917F, 0.9494005577F,
  143110. 0.9506091252F, 0.9517980248F, 0.9529673894F, 0.9541173540F,
  143111. 0.9552480557F, 0.9563596334F, 0.9574522282F, 0.9585259830F,
  143112. 0.9595810428F, 0.9606175542F, 0.9616356656F, 0.9626355274F,
  143113. 0.9636172915F, 0.9645811114F, 0.9655271425F, 0.9664555414F,
  143114. 0.9673664664F, 0.9682600774F, 0.9691365355F, 0.9699960034F,
  143115. 0.9708386448F, 0.9716646250F, 0.9724741103F, 0.9732672685F,
  143116. 0.9740442683F, 0.9748052795F, 0.9755504729F, 0.9762800205F,
  143117. 0.9769940950F, 0.9776928703F, 0.9783765210F, 0.9790452223F,
  143118. 0.9796991504F, 0.9803384823F, 0.9809633954F, 0.9815740679F,
  143119. 0.9821706784F, 0.9827534063F, 0.9833224312F, 0.9838779332F,
  143120. 0.9844200928F, 0.9849490910F, 0.9854651087F, 0.9859683274F,
  143121. 0.9864589286F, 0.9869370940F, 0.9874030054F, 0.9878568447F,
  143122. 0.9882987937F, 0.9887290343F, 0.9891477481F, 0.9895551169F,
  143123. 0.9899513220F, 0.9903365446F, 0.9907109658F, 0.9910747662F,
  143124. 0.9914281260F, 0.9917712252F, 0.9921042433F, 0.9924273593F,
  143125. 0.9927407516F, 0.9930445982F, 0.9933390763F, 0.9936243626F,
  143126. 0.9939006331F, 0.9941680631F, 0.9944268269F, 0.9946770982F,
  143127. 0.9949190498F, 0.9951528537F, 0.9953786808F, 0.9955967011F,
  143128. 0.9958070836F, 0.9960099963F, 0.9962056061F, 0.9963940787F,
  143129. 0.9965755786F, 0.9967502693F, 0.9969183129F, 0.9970798704F,
  143130. 0.9972351013F, 0.9973841640F, 0.9975272151F, 0.9976644103F,
  143131. 0.9977959036F, 0.9979218476F, 0.9980423932F, 0.9981576901F,
  143132. 0.9982678862F, 0.9983731278F, 0.9984735596F, 0.9985693247F,
  143133. 0.9986605645F, 0.9987474186F, 0.9988300248F, 0.9989085193F,
  143134. 0.9989830364F, 0.9990537085F, 0.9991206662F, 0.9991840382F,
  143135. 0.9992439513F, 0.9993005303F, 0.9993538982F, 0.9994041757F,
  143136. 0.9994514817F, 0.9994959330F, 0.9995376444F, 0.9995767286F,
  143137. 0.9996132960F, 0.9996474550F, 0.9996793121F, 0.9997089710F,
  143138. 0.9997365339F, 0.9997621003F, 0.9997857677F, 0.9998076311F,
  143139. 0.9998277836F, 0.9998463156F, 0.9998633155F, 0.9998788692F,
  143140. 0.9998930603F, 0.9999059701F, 0.9999176774F, 0.9999282586F,
  143141. 0.9999377880F, 0.9999463370F, 0.9999539749F, 0.9999607685F,
  143142. 0.9999667820F, 0.9999720773F, 0.9999767136F, 0.9999807479F,
  143143. 0.9999842344F, 0.9999872249F, 0.9999897688F, 0.9999919127F,
  143144. 0.9999937009F, 0.9999951749F, 0.9999963738F, 0.9999973342F,
  143145. 0.9999980900F, 0.9999986724F, 0.9999991103F, 0.9999994297F,
  143146. 0.9999996543F, 0.9999998049F, 0.9999999000F, 0.9999999552F,
  143147. 0.9999999836F, 0.9999999957F, 0.9999999994F, 1.0000000000F,
  143148. };
  143149. static float vwin2048[1024] = {
  143150. 0.0000009241F, 0.0000083165F, 0.0000231014F, 0.0000452785F,
  143151. 0.0000748476F, 0.0001118085F, 0.0001561608F, 0.0002079041F,
  143152. 0.0002670379F, 0.0003335617F, 0.0004074748F, 0.0004887765F,
  143153. 0.0005774661F, 0.0006735427F, 0.0007770054F, 0.0008878533F,
  143154. 0.0010060853F, 0.0011317002F, 0.0012646969F, 0.0014050742F,
  143155. 0.0015528307F, 0.0017079650F, 0.0018704756F, 0.0020403610F,
  143156. 0.0022176196F, 0.0024022497F, 0.0025942495F, 0.0027936173F,
  143157. 0.0030003511F, 0.0032144490F, 0.0034359088F, 0.0036647286F,
  143158. 0.0039009061F, 0.0041444391F, 0.0043953253F, 0.0046535621F,
  143159. 0.0049191472F, 0.0051920781F, 0.0054723520F, 0.0057599664F,
  143160. 0.0060549184F, 0.0063572052F, 0.0066668239F, 0.0069837715F,
  143161. 0.0073080449F, 0.0076396410F, 0.0079785566F, 0.0083247884F,
  143162. 0.0086783330F, 0.0090391871F, 0.0094073470F, 0.0097828092F,
  143163. 0.0101655700F, 0.0105556258F, 0.0109529726F, 0.0113576065F,
  143164. 0.0117695237F, 0.0121887200F, 0.0126151913F, 0.0130489335F,
  143165. 0.0134899422F, 0.0139382130F, 0.0143937415F, 0.0148565233F,
  143166. 0.0153265536F, 0.0158038279F, 0.0162883413F, 0.0167800889F,
  143167. 0.0172790660F, 0.0177852675F, 0.0182986882F, 0.0188193231F,
  143168. 0.0193471668F, 0.0198822141F, 0.0204244594F, 0.0209738974F,
  143169. 0.0215305225F, 0.0220943289F, 0.0226653109F, 0.0232434627F,
  143170. 0.0238287784F, 0.0244212519F, 0.0250208772F, 0.0256276481F,
  143171. 0.0262415582F, 0.0268626014F, 0.0274907711F, 0.0281260608F,
  143172. 0.0287684638F, 0.0294179736F, 0.0300745833F, 0.0307382859F,
  143173. 0.0314090747F, 0.0320869424F, 0.0327718819F, 0.0334638860F,
  143174. 0.0341629474F, 0.0348690586F, 0.0355822122F, 0.0363024004F,
  143175. 0.0370296157F, 0.0377638502F, 0.0385050960F, 0.0392533451F,
  143176. 0.0400085896F, 0.0407708211F, 0.0415400315F, 0.0423162123F,
  143177. 0.0430993552F, 0.0438894515F, 0.0446864926F, 0.0454904698F,
  143178. 0.0463013742F, 0.0471191969F, 0.0479439288F, 0.0487755607F,
  143179. 0.0496140836F, 0.0504594879F, 0.0513117642F, 0.0521709031F,
  143180. 0.0530368949F, 0.0539097297F, 0.0547893979F, 0.0556758894F,
  143181. 0.0565691941F, 0.0574693019F, 0.0583762026F, 0.0592898858F,
  143182. 0.0602103410F, 0.0611375576F, 0.0620715250F, 0.0630122324F,
  143183. 0.0639596688F, 0.0649138234F, 0.0658746848F, 0.0668422421F,
  143184. 0.0678164838F, 0.0687973985F, 0.0697849746F, 0.0707792005F,
  143185. 0.0717800645F, 0.0727875547F, 0.0738016591F, 0.0748223656F,
  143186. 0.0758496620F, 0.0768835359F, 0.0779239751F, 0.0789709668F,
  143187. 0.0800244985F, 0.0810845574F, 0.0821511306F, 0.0832242052F,
  143188. 0.0843037679F, 0.0853898056F, 0.0864823050F, 0.0875812525F,
  143189. 0.0886866347F, 0.0897984378F, 0.0909166480F, 0.0920412513F,
  143190. 0.0931722338F, 0.0943095813F, 0.0954532795F, 0.0966033140F,
  143191. 0.0977596702F, 0.0989223336F, 0.1000912894F, 0.1012665227F,
  143192. 0.1024480185F, 0.1036357616F, 0.1048297369F, 0.1060299290F,
  143193. 0.1072363224F, 0.1084489014F, 0.1096676504F, 0.1108925534F,
  143194. 0.1121235946F, 0.1133607577F, 0.1146040267F, 0.1158533850F,
  143195. 0.1171088163F, 0.1183703040F, 0.1196378312F, 0.1209113812F,
  143196. 0.1221909370F, 0.1234764815F, 0.1247679974F, 0.1260654674F,
  143197. 0.1273688740F, 0.1286781995F, 0.1299934263F, 0.1313145365F,
  143198. 0.1326415121F, 0.1339743349F, 0.1353129866F, 0.1366574490F,
  143199. 0.1380077035F, 0.1393637315F, 0.1407255141F, 0.1420930325F,
  143200. 0.1434662677F, 0.1448452004F, 0.1462298115F, 0.1476200814F,
  143201. 0.1490159906F, 0.1504175195F, 0.1518246482F, 0.1532373569F,
  143202. 0.1546556253F, 0.1560794333F, 0.1575087606F, 0.1589435866F,
  143203. 0.1603838909F, 0.1618296526F, 0.1632808509F, 0.1647374648F,
  143204. 0.1661994731F, 0.1676668546F, 0.1691395880F, 0.1706176516F,
  143205. 0.1721010238F, 0.1735896829F, 0.1750836068F, 0.1765827736F,
  143206. 0.1780871610F, 0.1795967468F, 0.1811115084F, 0.1826314234F,
  143207. 0.1841564689F, 0.1856866221F, 0.1872218600F, 0.1887621595F,
  143208. 0.1903074974F, 0.1918578503F, 0.1934131947F, 0.1949735068F,
  143209. 0.1965387630F, 0.1981089393F, 0.1996840117F, 0.2012639560F,
  143210. 0.2028487479F, 0.2044383630F, 0.2060327766F, 0.2076319642F,
  143211. 0.2092359007F, 0.2108445614F, 0.2124579211F, 0.2140759545F,
  143212. 0.2156986364F, 0.2173259411F, 0.2189578432F, 0.2205943168F,
  143213. 0.2222353361F, 0.2238808751F, 0.2255309076F, 0.2271854073F,
  143214. 0.2288443480F, 0.2305077030F, 0.2321754457F, 0.2338475493F,
  143215. 0.2355239869F, 0.2372047315F, 0.2388897560F, 0.2405790329F,
  143216. 0.2422725350F, 0.2439702347F, 0.2456721043F, 0.2473781159F,
  143217. 0.2490882418F, 0.2508024539F, 0.2525207240F, 0.2542430237F,
  143218. 0.2559693248F, 0.2576995986F, 0.2594338166F, 0.2611719498F,
  143219. 0.2629139695F, 0.2646598466F, 0.2664095520F, 0.2681630564F,
  143220. 0.2699203304F, 0.2716813445F, 0.2734460691F, 0.2752144744F,
  143221. 0.2769865307F, 0.2787622079F, 0.2805414760F, 0.2823243047F,
  143222. 0.2841106637F, 0.2859005227F, 0.2876938509F, 0.2894906179F,
  143223. 0.2912907928F, 0.2930943447F, 0.2949012426F, 0.2967114554F,
  143224. 0.2985249520F, 0.3003417009F, 0.3021616708F, 0.3039848301F,
  143225. 0.3058111471F, 0.3076405901F, 0.3094731273F, 0.3113087266F,
  143226. 0.3131473560F, 0.3149889833F, 0.3168335762F, 0.3186811024F,
  143227. 0.3205315294F, 0.3223848245F, 0.3242409552F, 0.3260998886F,
  143228. 0.3279615918F, 0.3298260319F, 0.3316931758F, 0.3335629903F,
  143229. 0.3354354423F, 0.3373104982F, 0.3391881247F, 0.3410682882F,
  143230. 0.3429509551F, 0.3448360917F, 0.3467236642F, 0.3486136387F,
  143231. 0.3505059811F, 0.3524006575F, 0.3542976336F, 0.3561968753F,
  143232. 0.3580983482F, 0.3600020179F, 0.3619078499F, 0.3638158096F,
  143233. 0.3657258625F, 0.3676379737F, 0.3695521086F, 0.3714682321F,
  143234. 0.3733863094F, 0.3753063055F, 0.3772281852F, 0.3791519134F,
  143235. 0.3810774548F, 0.3830047742F, 0.3849338362F, 0.3868646053F,
  143236. 0.3887970459F, 0.3907311227F, 0.3926667998F, 0.3946040417F,
  143237. 0.3965428125F, 0.3984830765F, 0.4004247978F, 0.4023679403F,
  143238. 0.4043124683F, 0.4062583455F, 0.4082055359F, 0.4101540034F,
  143239. 0.4121037117F, 0.4140546246F, 0.4160067058F, 0.4179599190F,
  143240. 0.4199142277F, 0.4218695956F, 0.4238259861F, 0.4257833627F,
  143241. 0.4277416888F, 0.4297009279F, 0.4316610433F, 0.4336219983F,
  143242. 0.4355837562F, 0.4375462803F, 0.4395095337F, 0.4414734797F,
  143243. 0.4434380815F, 0.4454033021F, 0.4473691046F, 0.4493354521F,
  143244. 0.4513023078F, 0.4532696345F, 0.4552373954F, 0.4572055533F,
  143245. 0.4591740713F, 0.4611429123F, 0.4631120393F, 0.4650814151F,
  143246. 0.4670510028F, 0.4690207650F, 0.4709906649F, 0.4729606651F,
  143247. 0.4749307287F, 0.4769008185F, 0.4788708972F, 0.4808409279F,
  143248. 0.4828108732F, 0.4847806962F, 0.4867503597F, 0.4887198264F,
  143249. 0.4906890593F, 0.4926580213F, 0.4946266753F, 0.4965949840F,
  143250. 0.4985629105F, 0.5005304176F, 0.5024974683F, 0.5044640255F,
  143251. 0.5064300522F, 0.5083955114F, 0.5103603659F, 0.5123245790F,
  143252. 0.5142881136F, 0.5162509328F, 0.5182129997F, 0.5201742774F,
  143253. 0.5221347290F, 0.5240943178F, 0.5260530070F, 0.5280107598F,
  143254. 0.5299675395F, 0.5319233095F, 0.5338780330F, 0.5358316736F,
  143255. 0.5377841946F, 0.5397355596F, 0.5416857320F, 0.5436346755F,
  143256. 0.5455823538F, 0.5475287304F, 0.5494737691F, 0.5514174337F,
  143257. 0.5533596881F, 0.5553004962F, 0.5572398218F, 0.5591776291F,
  143258. 0.5611138821F, 0.5630485449F, 0.5649815818F, 0.5669129570F,
  143259. 0.5688426349F, 0.5707705799F, 0.5726967564F, 0.5746211290F,
  143260. 0.5765436624F, 0.5784643212F, 0.5803830702F, 0.5822998743F,
  143261. 0.5842146984F, 0.5861275076F, 0.5880382669F, 0.5899469416F,
  143262. 0.5918534968F, 0.5937578981F, 0.5956601107F, 0.5975601004F,
  143263. 0.5994578326F, 0.6013532732F, 0.6032463880F, 0.6051371429F,
  143264. 0.6070255039F, 0.6089114372F, 0.6107949090F, 0.6126758856F,
  143265. 0.6145543334F, 0.6164302191F, 0.6183035092F, 0.6201741706F,
  143266. 0.6220421700F, 0.6239074745F, 0.6257700513F, 0.6276298674F,
  143267. 0.6294868903F, 0.6313410873F, 0.6331924262F, 0.6350408745F,
  143268. 0.6368864001F, 0.6387289710F, 0.6405685552F, 0.6424051209F,
  143269. 0.6442386364F, 0.6460690702F, 0.6478963910F, 0.6497205673F,
  143270. 0.6515415682F, 0.6533593625F, 0.6551739194F, 0.6569852082F,
  143271. 0.6587931984F, 0.6605978593F, 0.6623991609F, 0.6641970728F,
  143272. 0.6659915652F, 0.6677826081F, 0.6695701718F, 0.6713542268F,
  143273. 0.6731347437F, 0.6749116932F, 0.6766850461F, 0.6784547736F,
  143274. 0.6802208469F, 0.6819832374F, 0.6837419164F, 0.6854968559F,
  143275. 0.6872480275F, 0.6889954034F, 0.6907389556F, 0.6924786566F,
  143276. 0.6942144788F, 0.6959463950F, 0.6976743780F, 0.6993984008F,
  143277. 0.7011184365F, 0.7028344587F, 0.7045464407F, 0.7062543564F,
  143278. 0.7079581796F, 0.7096578844F, 0.7113534450F, 0.7130448359F,
  143279. 0.7147320316F, 0.7164150070F, 0.7180937371F, 0.7197681970F,
  143280. 0.7214383620F, 0.7231042077F, 0.7247657098F, 0.7264228443F,
  143281. 0.7280755871F, 0.7297239147F, 0.7313678035F, 0.7330072301F,
  143282. 0.7346421715F, 0.7362726046F, 0.7378985069F, 0.7395198556F,
  143283. 0.7411366285F, 0.7427488034F, 0.7443563584F, 0.7459592717F,
  143284. 0.7475575218F, 0.7491510873F, 0.7507399471F, 0.7523240803F,
  143285. 0.7539034661F, 0.7554780839F, 0.7570479136F, 0.7586129349F,
  143286. 0.7601731279F, 0.7617284730F, 0.7632789506F, 0.7648245416F,
  143287. 0.7663652267F, 0.7679009872F, 0.7694318044F, 0.7709576599F,
  143288. 0.7724785354F, 0.7739944130F, 0.7755052749F, 0.7770111035F,
  143289. 0.7785118815F, 0.7800075916F, 0.7814982170F, 0.7829837410F,
  143290. 0.7844641472F, 0.7859394191F, 0.7874095408F, 0.7888744965F,
  143291. 0.7903342706F, 0.7917888476F, 0.7932382124F, 0.7946823501F,
  143292. 0.7961212460F, 0.7975548855F, 0.7989832544F, 0.8004063386F,
  143293. 0.8018241244F, 0.8032365981F, 0.8046437463F, 0.8060455560F,
  143294. 0.8074420141F, 0.8088331080F, 0.8102188253F, 0.8115991536F,
  143295. 0.8129740810F, 0.8143435957F, 0.8157076861F, 0.8170663409F,
  143296. 0.8184195489F, 0.8197672994F, 0.8211095817F, 0.8224463853F,
  143297. 0.8237777001F, 0.8251035161F, 0.8264238235F, 0.8277386129F,
  143298. 0.8290478750F, 0.8303516008F, 0.8316497814F, 0.8329424083F,
  143299. 0.8342294731F, 0.8355109677F, 0.8367868841F, 0.8380572148F,
  143300. 0.8393219523F, 0.8405810893F, 0.8418346190F, 0.8430825345F,
  143301. 0.8443248294F, 0.8455614974F, 0.8467925323F, 0.8480179285F,
  143302. 0.8492376802F, 0.8504517822F, 0.8516602292F, 0.8528630164F,
  143303. 0.8540601391F, 0.8552515928F, 0.8564373733F, 0.8576174766F,
  143304. 0.8587918990F, 0.8599606368F, 0.8611236868F, 0.8622810460F,
  143305. 0.8634327113F, 0.8645786802F, 0.8657189504F, 0.8668535195F,
  143306. 0.8679823857F, 0.8691055472F, 0.8702230025F, 0.8713347503F,
  143307. 0.8724407896F, 0.8735411194F, 0.8746357394F, 0.8757246489F,
  143308. 0.8768078479F, 0.8778853364F, 0.8789571146F, 0.8800231832F,
  143309. 0.8810835427F, 0.8821381942F, 0.8831871387F, 0.8842303777F,
  143310. 0.8852679127F, 0.8862997456F, 0.8873258784F, 0.8883463132F,
  143311. 0.8893610527F, 0.8903700994F, 0.8913734562F, 0.8923711263F,
  143312. 0.8933631129F, 0.8943494196F, 0.8953300500F, 0.8963050083F,
  143313. 0.8972742985F, 0.8982379249F, 0.8991958922F, 0.9001482052F,
  143314. 0.9010948688F, 0.9020358883F, 0.9029712690F, 0.9039010165F,
  143315. 0.9048251367F, 0.9057436357F, 0.9066565195F, 0.9075637946F,
  143316. 0.9084654678F, 0.9093615456F, 0.9102520353F, 0.9111369440F,
  143317. 0.9120162792F, 0.9128900484F, 0.9137582595F, 0.9146209204F,
  143318. 0.9154780394F, 0.9163296248F, 0.9171756853F, 0.9180162296F,
  143319. 0.9188512667F, 0.9196808057F, 0.9205048559F, 0.9213234270F,
  143320. 0.9221365285F, 0.9229441704F, 0.9237463629F, 0.9245431160F,
  143321. 0.9253344404F, 0.9261203465F, 0.9269008453F, 0.9276759477F,
  143322. 0.9284456648F, 0.9292100080F, 0.9299689889F, 0.9307226190F,
  143323. 0.9314709103F, 0.9322138747F, 0.9329515245F, 0.9336838721F,
  143324. 0.9344109300F, 0.9351327108F, 0.9358492275F, 0.9365604931F,
  143325. 0.9372665208F, 0.9379673239F, 0.9386629160F, 0.9393533107F,
  143326. 0.9400385220F, 0.9407185637F, 0.9413934501F, 0.9420631954F,
  143327. 0.9427278141F, 0.9433873208F, 0.9440417304F, 0.9446910576F,
  143328. 0.9453353176F, 0.9459745255F, 0.9466086968F, 0.9472378469F,
  143329. 0.9478619915F, 0.9484811463F, 0.9490953274F, 0.9497045506F,
  143330. 0.9503088323F, 0.9509081888F, 0.9515026365F, 0.9520921921F,
  143331. 0.9526768723F, 0.9532566940F, 0.9538316742F, 0.9544018300F,
  143332. 0.9549671786F, 0.9555277375F, 0.9560835241F, 0.9566345562F,
  143333. 0.9571808513F, 0.9577224275F, 0.9582593027F, 0.9587914949F,
  143334. 0.9593190225F, 0.9598419038F, 0.9603601571F, 0.9608738012F,
  143335. 0.9613828546F, 0.9618873361F, 0.9623872646F, 0.9628826591F,
  143336. 0.9633735388F, 0.9638599227F, 0.9643418303F, 0.9648192808F,
  143337. 0.9652922939F, 0.9657608890F, 0.9662250860F, 0.9666849046F,
  143338. 0.9671403646F, 0.9675914861F, 0.9680382891F, 0.9684807937F,
  143339. 0.9689190202F, 0.9693529890F, 0.9697827203F, 0.9702082347F,
  143340. 0.9706295529F, 0.9710466953F, 0.9714596828F, 0.9718685362F,
  143341. 0.9722732762F, 0.9726739240F, 0.9730705005F, 0.9734630267F,
  143342. 0.9738515239F, 0.9742360134F, 0.9746165163F, 0.9749930540F,
  143343. 0.9753656481F, 0.9757343198F, 0.9760990909F, 0.9764599829F,
  143344. 0.9768170175F, 0.9771702164F, 0.9775196013F, 0.9778651941F,
  143345. 0.9782070167F, 0.9785450909F, 0.9788794388F, 0.9792100824F,
  143346. 0.9795370437F, 0.9798603449F, 0.9801800080F, 0.9804960554F,
  143347. 0.9808085092F, 0.9811173916F, 0.9814227251F, 0.9817245318F,
  143348. 0.9820228343F, 0.9823176549F, 0.9826090160F, 0.9828969402F,
  143349. 0.9831814498F, 0.9834625674F, 0.9837403156F, 0.9840147169F,
  143350. 0.9842857939F, 0.9845535692F, 0.9848180654F, 0.9850793052F,
  143351. 0.9853373113F, 0.9855921062F, 0.9858437127F, 0.9860921535F,
  143352. 0.9863374512F, 0.9865796287F, 0.9868187085F, 0.9870547136F,
  143353. 0.9872876664F, 0.9875175899F, 0.9877445067F, 0.9879684396F,
  143354. 0.9881894112F, 0.9884074444F, 0.9886225619F, 0.9888347863F,
  143355. 0.9890441404F, 0.9892506468F, 0.9894543284F, 0.9896552077F,
  143356. 0.9898533074F, 0.9900486502F, 0.9902412587F, 0.9904311555F,
  143357. 0.9906183633F, 0.9908029045F, 0.9909848019F, 0.9911640779F,
  143358. 0.9913407550F, 0.9915148557F, 0.9916864025F, 0.9918554179F,
  143359. 0.9920219241F, 0.9921859437F, 0.9923474989F, 0.9925066120F,
  143360. 0.9926633054F, 0.9928176012F, 0.9929695218F, 0.9931190891F,
  143361. 0.9932663254F, 0.9934112527F, 0.9935538932F, 0.9936942686F,
  143362. 0.9938324012F, 0.9939683126F, 0.9941020248F, 0.9942335597F,
  143363. 0.9943629388F, 0.9944901841F, 0.9946153170F, 0.9947383593F,
  143364. 0.9948593325F, 0.9949782579F, 0.9950951572F, 0.9952100516F,
  143365. 0.9953229625F, 0.9954339111F, 0.9955429186F, 0.9956500062F,
  143366. 0.9957551948F, 0.9958585056F, 0.9959599593F, 0.9960595769F,
  143367. 0.9961573792F, 0.9962533869F, 0.9963476206F, 0.9964401009F,
  143368. 0.9965308483F, 0.9966198833F, 0.9967072261F, 0.9967928971F,
  143369. 0.9968769164F, 0.9969593041F, 0.9970400804F, 0.9971192651F,
  143370. 0.9971968781F, 0.9972729391F, 0.9973474680F, 0.9974204842F,
  143371. 0.9974920074F, 0.9975620569F, 0.9976306521F, 0.9976978122F,
  143372. 0.9977635565F, 0.9978279039F, 0.9978908736F, 0.9979524842F,
  143373. 0.9980127547F, 0.9980717037F, 0.9981293499F, 0.9981857116F,
  143374. 0.9982408073F, 0.9982946554F, 0.9983472739F, 0.9983986810F,
  143375. 0.9984488947F, 0.9984979328F, 0.9985458132F, 0.9985925534F,
  143376. 0.9986381711F, 0.9986826838F, 0.9987261086F, 0.9987684630F,
  143377. 0.9988097640F, 0.9988500286F, 0.9988892738F, 0.9989275163F,
  143378. 0.9989647727F, 0.9990010597F, 0.9990363938F, 0.9990707911F,
  143379. 0.9991042679F, 0.9991368404F, 0.9991685244F, 0.9991993358F,
  143380. 0.9992292905F, 0.9992584038F, 0.9992866914F, 0.9993141686F,
  143381. 0.9993408506F, 0.9993667526F, 0.9993918895F, 0.9994162761F,
  143382. 0.9994399273F, 0.9994628576F, 0.9994850815F, 0.9995066133F,
  143383. 0.9995274672F, 0.9995476574F, 0.9995671978F, 0.9995861021F,
  143384. 0.9996043841F, 0.9996220573F, 0.9996391352F, 0.9996556310F,
  143385. 0.9996715579F, 0.9996869288F, 0.9997017568F, 0.9997160543F,
  143386. 0.9997298342F, 0.9997431088F, 0.9997558905F, 0.9997681914F,
  143387. 0.9997800236F, 0.9997913990F, 0.9998023292F, 0.9998128261F,
  143388. 0.9998229009F, 0.9998325650F, 0.9998418296F, 0.9998507058F,
  143389. 0.9998592044F, 0.9998673362F, 0.9998751117F, 0.9998825415F,
  143390. 0.9998896358F, 0.9998964047F, 0.9999028584F, 0.9999090066F,
  143391. 0.9999148590F, 0.9999204253F, 0.9999257148F, 0.9999307368F,
  143392. 0.9999355003F, 0.9999400144F, 0.9999442878F, 0.9999483293F,
  143393. 0.9999521472F, 0.9999557499F, 0.9999591457F, 0.9999623426F,
  143394. 0.9999653483F, 0.9999681708F, 0.9999708175F, 0.9999732959F,
  143395. 0.9999756132F, 0.9999777765F, 0.9999797928F, 0.9999816688F,
  143396. 0.9999834113F, 0.9999850266F, 0.9999865211F, 0.9999879009F,
  143397. 0.9999891721F, 0.9999903405F, 0.9999914118F, 0.9999923914F,
  143398. 0.9999932849F, 0.9999940972F, 0.9999948336F, 0.9999954989F,
  143399. 0.9999960978F, 0.9999966349F, 0.9999971146F, 0.9999975411F,
  143400. 0.9999979185F, 0.9999982507F, 0.9999985414F, 0.9999987944F,
  143401. 0.9999990129F, 0.9999992003F, 0.9999993596F, 0.9999994939F,
  143402. 0.9999996059F, 0.9999996981F, 0.9999997732F, 0.9999998333F,
  143403. 0.9999998805F, 0.9999999170F, 0.9999999444F, 0.9999999643F,
  143404. 0.9999999784F, 0.9999999878F, 0.9999999937F, 0.9999999972F,
  143405. 0.9999999990F, 0.9999999997F, 1.0000000000F, 1.0000000000F,
  143406. };
  143407. static float vwin4096[2048] = {
  143408. 0.0000002310F, 0.0000020791F, 0.0000057754F, 0.0000113197F,
  143409. 0.0000187121F, 0.0000279526F, 0.0000390412F, 0.0000519777F,
  143410. 0.0000667623F, 0.0000833949F, 0.0001018753F, 0.0001222036F,
  143411. 0.0001443798F, 0.0001684037F, 0.0001942754F, 0.0002219947F,
  143412. 0.0002515616F, 0.0002829761F, 0.0003162380F, 0.0003513472F,
  143413. 0.0003883038F, 0.0004271076F, 0.0004677584F, 0.0005102563F,
  143414. 0.0005546011F, 0.0006007928F, 0.0006488311F, 0.0006987160F,
  143415. 0.0007504474F, 0.0008040251F, 0.0008594490F, 0.0009167191F,
  143416. 0.0009758351F, 0.0010367969F, 0.0010996044F, 0.0011642574F,
  143417. 0.0012307558F, 0.0012990994F, 0.0013692880F, 0.0014413216F,
  143418. 0.0015151998F, 0.0015909226F, 0.0016684898F, 0.0017479011F,
  143419. 0.0018291565F, 0.0019122556F, 0.0019971983F, 0.0020839845F,
  143420. 0.0021726138F, 0.0022630861F, 0.0023554012F, 0.0024495588F,
  143421. 0.0025455588F, 0.0026434008F, 0.0027430847F, 0.0028446103F,
  143422. 0.0029479772F, 0.0030531853F, 0.0031602342F, 0.0032691238F,
  143423. 0.0033798538F, 0.0034924239F, 0.0036068338F, 0.0037230833F,
  143424. 0.0038411721F, 0.0039610999F, 0.0040828664F, 0.0042064714F,
  143425. 0.0043319145F, 0.0044591954F, 0.0045883139F, 0.0047192696F,
  143426. 0.0048520622F, 0.0049866914F, 0.0051231569F, 0.0052614583F,
  143427. 0.0054015953F, 0.0055435676F, 0.0056873748F, 0.0058330166F,
  143428. 0.0059804926F, 0.0061298026F, 0.0062809460F, 0.0064339226F,
  143429. 0.0065887320F, 0.0067453738F, 0.0069038476F, 0.0070641531F,
  143430. 0.0072262899F, 0.0073902575F, 0.0075560556F, 0.0077236838F,
  143431. 0.0078931417F, 0.0080644288F, 0.0082375447F, 0.0084124891F,
  143432. 0.0085892615F, 0.0087678614F, 0.0089482885F, 0.0091305422F,
  143433. 0.0093146223F, 0.0095005281F, 0.0096882592F, 0.0098778153F,
  143434. 0.0100691958F, 0.0102624002F, 0.0104574281F, 0.0106542791F,
  143435. 0.0108529525F, 0.0110534480F, 0.0112557651F, 0.0114599032F,
  143436. 0.0116658618F, 0.0118736405F, 0.0120832387F, 0.0122946560F,
  143437. 0.0125078917F, 0.0127229454F, 0.0129398166F, 0.0131585046F,
  143438. 0.0133790090F, 0.0136013292F, 0.0138254647F, 0.0140514149F,
  143439. 0.0142791792F, 0.0145087572F, 0.0147401481F, 0.0149733515F,
  143440. 0.0152083667F, 0.0154451932F, 0.0156838304F, 0.0159242777F,
  143441. 0.0161665345F, 0.0164106001F, 0.0166564741F, 0.0169041557F,
  143442. 0.0171536443F, 0.0174049393F, 0.0176580401F, 0.0179129461F,
  143443. 0.0181696565F, 0.0184281708F, 0.0186884883F, 0.0189506084F,
  143444. 0.0192145303F, 0.0194802535F, 0.0197477772F, 0.0200171008F,
  143445. 0.0202882236F, 0.0205611449F, 0.0208358639F, 0.0211123801F,
  143446. 0.0213906927F, 0.0216708011F, 0.0219527043F, 0.0222364019F,
  143447. 0.0225218930F, 0.0228091769F, 0.0230982529F, 0.0233891203F,
  143448. 0.0236817782F, 0.0239762259F, 0.0242724628F, 0.0245704880F,
  143449. 0.0248703007F, 0.0251719002F, 0.0254752858F, 0.0257804565F,
  143450. 0.0260874117F, 0.0263961506F, 0.0267066722F, 0.0270189760F,
  143451. 0.0273330609F, 0.0276489263F, 0.0279665712F, 0.0282859949F,
  143452. 0.0286071966F, 0.0289301753F, 0.0292549303F, 0.0295814607F,
  143453. 0.0299097656F, 0.0302398442F, 0.0305716957F, 0.0309053191F,
  143454. 0.0312407135F, 0.0315778782F, 0.0319168122F, 0.0322575145F,
  143455. 0.0325999844F, 0.0329442209F, 0.0332902231F, 0.0336379900F,
  143456. 0.0339875208F, 0.0343388146F, 0.0346918703F, 0.0350466871F,
  143457. 0.0354032640F, 0.0357616000F, 0.0361216943F, 0.0364835458F,
  143458. 0.0368471535F, 0.0372125166F, 0.0375796339F, 0.0379485046F,
  143459. 0.0383191276F, 0.0386915020F, 0.0390656267F, 0.0394415008F,
  143460. 0.0398191231F, 0.0401984927F, 0.0405796086F, 0.0409624698F,
  143461. 0.0413470751F, 0.0417334235F, 0.0421215141F, 0.0425113457F,
  143462. 0.0429029172F, 0.0432962277F, 0.0436912760F, 0.0440880610F,
  143463. 0.0444865817F, 0.0448868370F, 0.0452888257F, 0.0456925468F,
  143464. 0.0460979992F, 0.0465051816F, 0.0469140931F, 0.0473247325F,
  143465. 0.0477370986F, 0.0481511902F, 0.0485670064F, 0.0489845458F,
  143466. 0.0494038074F, 0.0498247899F, 0.0502474922F, 0.0506719131F,
  143467. 0.0510980514F, 0.0515259060F, 0.0519554756F, 0.0523867590F,
  143468. 0.0528197550F, 0.0532544624F, 0.0536908800F, 0.0541290066F,
  143469. 0.0545688408F, 0.0550103815F, 0.0554536274F, 0.0558985772F,
  143470. 0.0563452297F, 0.0567935837F, 0.0572436377F, 0.0576953907F,
  143471. 0.0581488412F, 0.0586039880F, 0.0590608297F, 0.0595193651F,
  143472. 0.0599795929F, 0.0604415117F, 0.0609051202F, 0.0613704170F,
  143473. 0.0618374009F, 0.0623060704F, 0.0627764243F, 0.0632484611F,
  143474. 0.0637221795F, 0.0641975781F, 0.0646746555F, 0.0651534104F,
  143475. 0.0656338413F, 0.0661159469F, 0.0665997257F, 0.0670851763F,
  143476. 0.0675722973F, 0.0680610873F, 0.0685515448F, 0.0690436684F,
  143477. 0.0695374567F, 0.0700329081F, 0.0705300213F, 0.0710287947F,
  143478. 0.0715292269F, 0.0720313163F, 0.0725350616F, 0.0730404612F,
  143479. 0.0735475136F, 0.0740562172F, 0.0745665707F, 0.0750785723F,
  143480. 0.0755922207F, 0.0761075143F, 0.0766244515F, 0.0771430307F,
  143481. 0.0776632505F, 0.0781851092F, 0.0787086052F, 0.0792337371F,
  143482. 0.0797605032F, 0.0802889018F, 0.0808189315F, 0.0813505905F,
  143483. 0.0818838773F, 0.0824187903F, 0.0829553277F, 0.0834934881F,
  143484. 0.0840332697F, 0.0845746708F, 0.0851176899F, 0.0856623252F,
  143485. 0.0862085751F, 0.0867564379F, 0.0873059119F, 0.0878569954F,
  143486. 0.0884096867F, 0.0889639840F, 0.0895198858F, 0.0900773902F,
  143487. 0.0906364955F, 0.0911972000F, 0.0917595019F, 0.0923233995F,
  143488. 0.0928888909F, 0.0934559745F, 0.0940246485F, 0.0945949110F,
  143489. 0.0951667604F, 0.0957401946F, 0.0963152121F, 0.0968918109F,
  143490. 0.0974699893F, 0.0980497454F, 0.0986310773F, 0.0992139832F,
  143491. 0.0997984614F, 0.1003845098F, 0.1009721267F, 0.1015613101F,
  143492. 0.1021520582F, 0.1027443692F, 0.1033382410F, 0.1039336718F,
  143493. 0.1045306597F, 0.1051292027F, 0.1057292990F, 0.1063309466F,
  143494. 0.1069341435F, 0.1075388878F, 0.1081451776F, 0.1087530108F,
  143495. 0.1093623856F, 0.1099732998F, 0.1105857516F, 0.1111997389F,
  143496. 0.1118152597F, 0.1124323121F, 0.1130508939F, 0.1136710032F,
  143497. 0.1142926379F, 0.1149157960F, 0.1155404755F, 0.1161666742F,
  143498. 0.1167943901F, 0.1174236211F, 0.1180543652F, 0.1186866202F,
  143499. 0.1193203841F, 0.1199556548F, 0.1205924300F, 0.1212307078F,
  143500. 0.1218704860F, 0.1225117624F, 0.1231545349F, 0.1237988013F,
  143501. 0.1244445596F, 0.1250918074F, 0.1257405427F, 0.1263907632F,
  143502. 0.1270424667F, 0.1276956512F, 0.1283503142F, 0.1290064537F,
  143503. 0.1296640674F, 0.1303231530F, 0.1309837084F, 0.1316457312F,
  143504. 0.1323092193F, 0.1329741703F, 0.1336405820F, 0.1343084520F,
  143505. 0.1349777782F, 0.1356485582F, 0.1363207897F, 0.1369944704F,
  143506. 0.1376695979F, 0.1383461700F, 0.1390241842F, 0.1397036384F,
  143507. 0.1403845300F, 0.1410668567F, 0.1417506162F, 0.1424358061F,
  143508. 0.1431224240F, 0.1438104674F, 0.1444999341F, 0.1451908216F,
  143509. 0.1458831274F, 0.1465768492F, 0.1472719844F, 0.1479685308F,
  143510. 0.1486664857F, 0.1493658468F, 0.1500666115F, 0.1507687775F,
  143511. 0.1514723422F, 0.1521773031F, 0.1528836577F, 0.1535914035F,
  143512. 0.1543005380F, 0.1550110587F, 0.1557229631F, 0.1564362485F,
  143513. 0.1571509124F, 0.1578669524F, 0.1585843657F, 0.1593031499F,
  143514. 0.1600233024F, 0.1607448205F, 0.1614677017F, 0.1621919433F,
  143515. 0.1629175428F, 0.1636444975F, 0.1643728047F, 0.1651024619F,
  143516. 0.1658334665F, 0.1665658156F, 0.1672995067F, 0.1680345371F,
  143517. 0.1687709041F, 0.1695086050F, 0.1702476372F, 0.1709879978F,
  143518. 0.1717296843F, 0.1724726938F, 0.1732170237F, 0.1739626711F,
  143519. 0.1747096335F, 0.1754579079F, 0.1762074916F, 0.1769583819F,
  143520. 0.1777105760F, 0.1784640710F, 0.1792188642F, 0.1799749529F,
  143521. 0.1807323340F, 0.1814910049F, 0.1822509628F, 0.1830122046F,
  143522. 0.1837747277F, 0.1845385292F, 0.1853036062F, 0.1860699558F,
  143523. 0.1868375751F, 0.1876064613F, 0.1883766114F, 0.1891480226F,
  143524. 0.1899206919F, 0.1906946164F, 0.1914697932F, 0.1922462194F,
  143525. 0.1930238919F, 0.1938028079F, 0.1945829643F, 0.1953643583F,
  143526. 0.1961469868F, 0.1969308468F, 0.1977159353F, 0.1985022494F,
  143527. 0.1992897859F, 0.2000785420F, 0.2008685145F, 0.2016597005F,
  143528. 0.2024520968F, 0.2032457005F, 0.2040405084F, 0.2048365175F,
  143529. 0.2056337247F, 0.2064321269F, 0.2072317211F, 0.2080325041F,
  143530. 0.2088344727F, 0.2096376240F, 0.2104419547F, 0.2112474618F,
  143531. 0.2120541420F, 0.2128619923F, 0.2136710094F, 0.2144811902F,
  143532. 0.2152925315F, 0.2161050301F, 0.2169186829F, 0.2177334866F,
  143533. 0.2185494381F, 0.2193665340F, 0.2201847712F, 0.2210041465F,
  143534. 0.2218246565F, 0.2226462981F, 0.2234690680F, 0.2242929629F,
  143535. 0.2251179796F, 0.2259441147F, 0.2267713650F, 0.2275997272F,
  143536. 0.2284291979F, 0.2292597739F, 0.2300914518F, 0.2309242283F,
  143537. 0.2317581001F, 0.2325930638F, 0.2334291160F, 0.2342662534F,
  143538. 0.2351044727F, 0.2359437703F, 0.2367841431F, 0.2376255875F,
  143539. 0.2384681001F, 0.2393116776F, 0.2401563165F, 0.2410020134F,
  143540. 0.2418487649F, 0.2426965675F, 0.2435454178F, 0.2443953122F,
  143541. 0.2452462474F, 0.2460982199F, 0.2469512262F, 0.2478052628F,
  143542. 0.2486603262F, 0.2495164129F, 0.2503735194F, 0.2512316421F,
  143543. 0.2520907776F, 0.2529509222F, 0.2538120726F, 0.2546742250F,
  143544. 0.2555373760F, 0.2564015219F, 0.2572666593F, 0.2581327845F,
  143545. 0.2589998939F, 0.2598679840F, 0.2607370510F, 0.2616070916F,
  143546. 0.2624781019F, 0.2633500783F, 0.2642230173F, 0.2650969152F,
  143547. 0.2659717684F, 0.2668475731F, 0.2677243257F, 0.2686020226F,
  143548. 0.2694806601F, 0.2703602344F, 0.2712407419F, 0.2721221789F,
  143549. 0.2730045417F, 0.2738878265F, 0.2747720297F, 0.2756571474F,
  143550. 0.2765431760F, 0.2774301117F, 0.2783179508F, 0.2792066895F,
  143551. 0.2800963240F, 0.2809868505F, 0.2818782654F, 0.2827705647F,
  143552. 0.2836637447F, 0.2845578016F, 0.2854527315F, 0.2863485307F,
  143553. 0.2872451953F, 0.2881427215F, 0.2890411055F, 0.2899403433F,
  143554. 0.2908404312F, 0.2917413654F, 0.2926431418F, 0.2935457567F,
  143555. 0.2944492061F, 0.2953534863F, 0.2962585932F, 0.2971645230F,
  143556. 0.2980712717F, 0.2989788356F, 0.2998872105F, 0.3007963927F,
  143557. 0.3017063781F, 0.3026171629F, 0.3035287430F, 0.3044411145F,
  143558. 0.3053542736F, 0.3062682161F, 0.3071829381F, 0.3080984356F,
  143559. 0.3090147047F, 0.3099317413F, 0.3108495414F, 0.3117681011F,
  143560. 0.3126874163F, 0.3136074830F, 0.3145282972F, 0.3154498548F,
  143561. 0.3163721517F, 0.3172951841F, 0.3182189477F, 0.3191434385F,
  143562. 0.3200686525F, 0.3209945856F, 0.3219212336F, 0.3228485927F,
  143563. 0.3237766585F, 0.3247054271F, 0.3256348943F, 0.3265650560F,
  143564. 0.3274959081F, 0.3284274465F, 0.3293596671F, 0.3302925657F,
  143565. 0.3312261382F, 0.3321603804F, 0.3330952882F, 0.3340308574F,
  143566. 0.3349670838F, 0.3359039634F, 0.3368414919F, 0.3377796651F,
  143567. 0.3387184789F, 0.3396579290F, 0.3405980113F, 0.3415387216F,
  143568. 0.3424800556F, 0.3434220091F, 0.3443645779F, 0.3453077578F,
  143569. 0.3462515446F, 0.3471959340F, 0.3481409217F, 0.3490865036F,
  143570. 0.3500326754F, 0.3509794328F, 0.3519267715F, 0.3528746873F,
  143571. 0.3538231759F, 0.3547722330F, 0.3557218544F, 0.3566720357F,
  143572. 0.3576227727F, 0.3585740610F, 0.3595258964F, 0.3604782745F,
  143573. 0.3614311910F, 0.3623846417F, 0.3633386221F, 0.3642931280F,
  143574. 0.3652481549F, 0.3662036987F, 0.3671597548F, 0.3681163191F,
  143575. 0.3690733870F, 0.3700309544F, 0.3709890167F, 0.3719475696F,
  143576. 0.3729066089F, 0.3738661299F, 0.3748261285F, 0.3757866002F,
  143577. 0.3767475406F, 0.3777089453F, 0.3786708100F, 0.3796331302F,
  143578. 0.3805959014F, 0.3815591194F, 0.3825227796F, 0.3834868777F,
  143579. 0.3844514093F, 0.3854163698F, 0.3863817549F, 0.3873475601F,
  143580. 0.3883137810F, 0.3892804131F, 0.3902474521F, 0.3912148933F,
  143581. 0.3921827325F, 0.3931509650F, 0.3941195865F, 0.3950885925F,
  143582. 0.3960579785F, 0.3970277400F, 0.3979978725F, 0.3989683716F,
  143583. 0.3999392328F, 0.4009104516F, 0.4018820234F, 0.4028539438F,
  143584. 0.4038262084F, 0.4047988125F, 0.4057717516F, 0.4067450214F,
  143585. 0.4077186172F, 0.4086925345F, 0.4096667688F, 0.4106413155F,
  143586. 0.4116161703F, 0.4125913284F, 0.4135667854F, 0.4145425368F,
  143587. 0.4155185780F, 0.4164949044F, 0.4174715116F, 0.4184483949F,
  143588. 0.4194255498F, 0.4204029718F, 0.4213806563F, 0.4223585987F,
  143589. 0.4233367946F, 0.4243152392F, 0.4252939281F, 0.4262728566F,
  143590. 0.4272520202F, 0.4282314144F, 0.4292110345F, 0.4301908760F,
  143591. 0.4311709343F, 0.4321512047F, 0.4331316828F, 0.4341123639F,
  143592. 0.4350932435F, 0.4360743168F, 0.4370555794F, 0.4380370267F,
  143593. 0.4390186540F, 0.4400004567F, 0.4409824303F, 0.4419645701F,
  143594. 0.4429468716F, 0.4439293300F, 0.4449119409F, 0.4458946996F,
  143595. 0.4468776014F, 0.4478606418F, 0.4488438162F, 0.4498271199F,
  143596. 0.4508105483F, 0.4517940967F, 0.4527777607F, 0.4537615355F,
  143597. 0.4547454165F, 0.4557293991F, 0.4567134786F, 0.4576976505F,
  143598. 0.4586819101F, 0.4596662527F, 0.4606506738F, 0.4616351687F,
  143599. 0.4626197328F, 0.4636043614F, 0.4645890499F, 0.4655737936F,
  143600. 0.4665585880F, 0.4675434284F, 0.4685283101F, 0.4695132286F,
  143601. 0.4704981791F, 0.4714831570F, 0.4724681577F, 0.4734531766F,
  143602. 0.4744382089F, 0.4754232501F, 0.4764082956F, 0.4773933406F,
  143603. 0.4783783806F, 0.4793634108F, 0.4803484267F, 0.4813334237F,
  143604. 0.4823183969F, 0.4833033419F, 0.4842882540F, 0.4852731285F,
  143605. 0.4862579608F, 0.4872427462F, 0.4882274802F, 0.4892121580F,
  143606. 0.4901967751F, 0.4911813267F, 0.4921658083F, 0.4931502151F,
  143607. 0.4941345427F, 0.4951187863F, 0.4961029412F, 0.4970870029F,
  143608. 0.4980709667F, 0.4990548280F, 0.5000385822F, 0.5010222245F,
  143609. 0.5020057505F, 0.5029891553F, 0.5039724345F, 0.5049555834F,
  143610. 0.5059385973F, 0.5069214716F, 0.5079042018F, 0.5088867831F,
  143611. 0.5098692110F, 0.5108514808F, 0.5118335879F, 0.5128155277F,
  143612. 0.5137972956F, 0.5147788869F, 0.5157602971F, 0.5167415215F,
  143613. 0.5177225555F, 0.5187033945F, 0.5196840339F, 0.5206644692F,
  143614. 0.5216446956F, 0.5226247086F, 0.5236045035F, 0.5245840759F,
  143615. 0.5255634211F, 0.5265425344F, 0.5275214114F, 0.5285000474F,
  143616. 0.5294784378F, 0.5304565781F, 0.5314344637F, 0.5324120899F,
  143617. 0.5333894522F, 0.5343665461F, 0.5353433670F, 0.5363199102F,
  143618. 0.5372961713F, 0.5382721457F, 0.5392478287F, 0.5402232159F,
  143619. 0.5411983027F, 0.5421730845F, 0.5431475569F, 0.5441217151F,
  143620. 0.5450955548F, 0.5460690714F, 0.5470422602F, 0.5480151169F,
  143621. 0.5489876368F, 0.5499598155F, 0.5509316484F, 0.5519031310F,
  143622. 0.5528742587F, 0.5538450271F, 0.5548154317F, 0.5557854680F,
  143623. 0.5567551314F, 0.5577244174F, 0.5586933216F, 0.5596618395F,
  143624. 0.5606299665F, 0.5615976983F, 0.5625650302F, 0.5635319580F,
  143625. 0.5644984770F, 0.5654645828F, 0.5664302709F, 0.5673955370F,
  143626. 0.5683603765F, 0.5693247850F, 0.5702887580F, 0.5712522912F,
  143627. 0.5722153800F, 0.5731780200F, 0.5741402069F, 0.5751019362F,
  143628. 0.5760632034F, 0.5770240042F, 0.5779843341F, 0.5789441889F,
  143629. 0.5799035639F, 0.5808624549F, 0.5818208575F, 0.5827787673F,
  143630. 0.5837361800F, 0.5846930910F, 0.5856494961F, 0.5866053910F,
  143631. 0.5875607712F, 0.5885156324F, 0.5894699703F, 0.5904237804F,
  143632. 0.5913770586F, 0.5923298004F, 0.5932820016F, 0.5942336578F,
  143633. 0.5951847646F, 0.5961353179F, 0.5970853132F, 0.5980347464F,
  143634. 0.5989836131F, 0.5999319090F, 0.6008796298F, 0.6018267713F,
  143635. 0.6027733292F, 0.6037192993F, 0.6046646773F, 0.6056094589F,
  143636. 0.6065536400F, 0.6074972162F, 0.6084401833F, 0.6093825372F,
  143637. 0.6103242736F, 0.6112653884F, 0.6122058772F, 0.6131457359F,
  143638. 0.6140849604F, 0.6150235464F, 0.6159614897F, 0.6168987862F,
  143639. 0.6178354318F, 0.6187714223F, 0.6197067535F, 0.6206414213F,
  143640. 0.6215754215F, 0.6225087501F, 0.6234414028F, 0.6243733757F,
  143641. 0.6253046646F, 0.6262352654F, 0.6271651739F, 0.6280943862F,
  143642. 0.6290228982F, 0.6299507057F, 0.6308778048F, 0.6318041913F,
  143643. 0.6327298612F, 0.6336548105F, 0.6345790352F, 0.6355025312F,
  143644. 0.6364252945F, 0.6373473211F, 0.6382686070F, 0.6391891483F,
  143645. 0.6401089409F, 0.6410279808F, 0.6419462642F, 0.6428637869F,
  143646. 0.6437805452F, 0.6446965350F, 0.6456117524F, 0.6465261935F,
  143647. 0.6474398544F, 0.6483527311F, 0.6492648197F, 0.6501761165F,
  143648. 0.6510866174F, 0.6519963186F, 0.6529052162F, 0.6538133064F,
  143649. 0.6547205854F, 0.6556270492F, 0.6565326941F, 0.6574375162F,
  143650. 0.6583415117F, 0.6592446769F, 0.6601470079F, 0.6610485009F,
  143651. 0.6619491521F, 0.6628489578F, 0.6637479143F, 0.6646460177F,
  143652. 0.6655432643F, 0.6664396505F, 0.6673351724F, 0.6682298264F,
  143653. 0.6691236087F, 0.6700165157F, 0.6709085436F, 0.6717996889F,
  143654. 0.6726899478F, 0.6735793167F, 0.6744677918F, 0.6753553697F,
  143655. 0.6762420466F, 0.6771278190F, 0.6780126832F, 0.6788966357F,
  143656. 0.6797796728F, 0.6806617909F, 0.6815429866F, 0.6824232562F,
  143657. 0.6833025961F, 0.6841810030F, 0.6850584731F, 0.6859350031F,
  143658. 0.6868105894F, 0.6876852284F, 0.6885589168F, 0.6894316510F,
  143659. 0.6903034275F, 0.6911742430F, 0.6920440939F, 0.6929129769F,
  143660. 0.6937808884F, 0.6946478251F, 0.6955137837F, 0.6963787606F,
  143661. 0.6972427525F, 0.6981057560F, 0.6989677678F, 0.6998287845F,
  143662. 0.7006888028F, 0.7015478194F, 0.7024058309F, 0.7032628340F,
  143663. 0.7041188254F, 0.7049738019F, 0.7058277601F, 0.7066806969F,
  143664. 0.7075326089F, 0.7083834929F, 0.7092333457F, 0.7100821640F,
  143665. 0.7109299447F, 0.7117766846F, 0.7126223804F, 0.7134670291F,
  143666. 0.7143106273F, 0.7151531721F, 0.7159946602F, 0.7168350885F,
  143667. 0.7176744539F, 0.7185127534F, 0.7193499837F, 0.7201861418F,
  143668. 0.7210212247F, 0.7218552293F, 0.7226881526F, 0.7235199914F,
  143669. 0.7243507428F, 0.7251804039F, 0.7260089715F, 0.7268364426F,
  143670. 0.7276628144F, 0.7284880839F, 0.7293122481F, 0.7301353040F,
  143671. 0.7309572487F, 0.7317780794F, 0.7325977930F, 0.7334163868F,
  143672. 0.7342338579F, 0.7350502033F, 0.7358654202F, 0.7366795059F,
  143673. 0.7374924573F, 0.7383042718F, 0.7391149465F, 0.7399244787F,
  143674. 0.7407328655F, 0.7415401041F, 0.7423461920F, 0.7431511261F,
  143675. 0.7439549040F, 0.7447575227F, 0.7455589797F, 0.7463592723F,
  143676. 0.7471583976F, 0.7479563532F, 0.7487531363F, 0.7495487443F,
  143677. 0.7503431745F, 0.7511364244F, 0.7519284913F, 0.7527193726F,
  143678. 0.7535090658F, 0.7542975683F, 0.7550848776F, 0.7558709910F,
  143679. 0.7566559062F, 0.7574396205F, 0.7582221314F, 0.7590034366F,
  143680. 0.7597835334F, 0.7605624194F, 0.7613400923F, 0.7621165495F,
  143681. 0.7628917886F, 0.7636658072F, 0.7644386030F, 0.7652101735F,
  143682. 0.7659805164F, 0.7667496292F, 0.7675175098F, 0.7682841556F,
  143683. 0.7690495645F, 0.7698137341F, 0.7705766622F, 0.7713383463F,
  143684. 0.7720987844F, 0.7728579741F, 0.7736159132F, 0.7743725994F,
  143685. 0.7751280306F, 0.7758822046F, 0.7766351192F, 0.7773867722F,
  143686. 0.7781371614F, 0.7788862848F, 0.7796341401F, 0.7803807253F,
  143687. 0.7811260383F, 0.7818700769F, 0.7826128392F, 0.7833543230F,
  143688. 0.7840945263F, 0.7848334471F, 0.7855710833F, 0.7863074330F,
  143689. 0.7870424941F, 0.7877762647F, 0.7885087428F, 0.7892399264F,
  143690. 0.7899698137F, 0.7906984026F, 0.7914256914F, 0.7921516780F,
  143691. 0.7928763607F, 0.7935997375F, 0.7943218065F, 0.7950425661F,
  143692. 0.7957620142F, 0.7964801492F, 0.7971969692F, 0.7979124724F,
  143693. 0.7986266570F, 0.7993395214F, 0.8000510638F, 0.8007612823F,
  143694. 0.8014701754F, 0.8021777413F, 0.8028839784F, 0.8035888849F,
  143695. 0.8042924592F, 0.8049946997F, 0.8056956048F, 0.8063951727F,
  143696. 0.8070934020F, 0.8077902910F, 0.8084858381F, 0.8091800419F,
  143697. 0.8098729007F, 0.8105644130F, 0.8112545774F, 0.8119433922F,
  143698. 0.8126308561F, 0.8133169676F, 0.8140017251F, 0.8146851272F,
  143699. 0.8153671726F, 0.8160478598F, 0.8167271874F, 0.8174051539F,
  143700. 0.8180817582F, 0.8187569986F, 0.8194308741F, 0.8201033831F,
  143701. 0.8207745244F, 0.8214442966F, 0.8221126986F, 0.8227797290F,
  143702. 0.8234453865F, 0.8241096700F, 0.8247725781F, 0.8254341097F,
  143703. 0.8260942636F, 0.8267530385F, 0.8274104334F, 0.8280664470F,
  143704. 0.8287210782F, 0.8293743259F, 0.8300261889F, 0.8306766662F,
  143705. 0.8313257566F, 0.8319734591F, 0.8326197727F, 0.8332646963F,
  143706. 0.8339082288F, 0.8345503692F, 0.8351911167F, 0.8358304700F,
  143707. 0.8364684284F, 0.8371049907F, 0.8377401562F, 0.8383739238F,
  143708. 0.8390062927F, 0.8396372618F, 0.8402668305F, 0.8408949977F,
  143709. 0.8415217626F, 0.8421471245F, 0.8427710823F, 0.8433936354F,
  143710. 0.8440147830F, 0.8446345242F, 0.8452528582F, 0.8458697844F,
  143711. 0.8464853020F, 0.8470994102F, 0.8477121084F, 0.8483233958F,
  143712. 0.8489332718F, 0.8495417356F, 0.8501487866F, 0.8507544243F,
  143713. 0.8513586479F, 0.8519614568F, 0.8525628505F, 0.8531628283F,
  143714. 0.8537613897F, 0.8543585341F, 0.8549542611F, 0.8555485699F,
  143715. 0.8561414603F, 0.8567329315F, 0.8573229832F, 0.8579116149F,
  143716. 0.8584988262F, 0.8590846165F, 0.8596689855F, 0.8602519327F,
  143717. 0.8608334577F, 0.8614135603F, 0.8619922399F, 0.8625694962F,
  143718. 0.8631453289F, 0.8637197377F, 0.8642927222F, 0.8648642821F,
  143719. 0.8654344172F, 0.8660031272F, 0.8665704118F, 0.8671362708F,
  143720. 0.8677007039F, 0.8682637109F, 0.8688252917F, 0.8693854460F,
  143721. 0.8699441737F, 0.8705014745F, 0.8710573485F, 0.8716117953F,
  143722. 0.8721648150F, 0.8727164073F, 0.8732665723F, 0.8738153098F,
  143723. 0.8743626197F, 0.8749085021F, 0.8754529569F, 0.8759959840F,
  143724. 0.8765375835F, 0.8770777553F, 0.8776164996F, 0.8781538162F,
  143725. 0.8786897054F, 0.8792241670F, 0.8797572013F, 0.8802888082F,
  143726. 0.8808189880F, 0.8813477407F, 0.8818750664F, 0.8824009653F,
  143727. 0.8829254375F, 0.8834484833F, 0.8839701028F, 0.8844902961F,
  143728. 0.8850090636F, 0.8855264054F, 0.8860423218F, 0.8865568131F,
  143729. 0.8870698794F, 0.8875815212F, 0.8880917386F, 0.8886005319F,
  143730. 0.8891079016F, 0.8896138479F, 0.8901183712F, 0.8906214719F,
  143731. 0.8911231503F, 0.8916234067F, 0.8921222417F, 0.8926196556F,
  143732. 0.8931156489F, 0.8936102219F, 0.8941033752F, 0.8945951092F,
  143733. 0.8950854244F, 0.8955743212F, 0.8960618003F, 0.8965478621F,
  143734. 0.8970325071F, 0.8975157359F, 0.8979975490F, 0.8984779471F,
  143735. 0.8989569307F, 0.8994345004F, 0.8999106568F, 0.9003854005F,
  143736. 0.9008587323F, 0.9013306526F, 0.9018011623F, 0.9022702619F,
  143737. 0.9027379521F, 0.9032042337F, 0.9036691074F, 0.9041325739F,
  143738. 0.9045946339F, 0.9050552882F, 0.9055145376F, 0.9059723828F,
  143739. 0.9064288246F, 0.9068838638F, 0.9073375013F, 0.9077897379F,
  143740. 0.9082405743F, 0.9086900115F, 0.9091380503F, 0.9095846917F,
  143741. 0.9100299364F, 0.9104737854F, 0.9109162397F, 0.9113573001F,
  143742. 0.9117969675F, 0.9122352430F, 0.9126721275F, 0.9131076219F,
  143743. 0.9135417273F, 0.9139744447F, 0.9144057750F, 0.9148357194F,
  143744. 0.9152642787F, 0.9156914542F, 0.9161172468F, 0.9165416576F,
  143745. 0.9169646877F, 0.9173863382F, 0.9178066102F, 0.9182255048F,
  143746. 0.9186430232F, 0.9190591665F, 0.9194739359F, 0.9198873324F,
  143747. 0.9202993574F, 0.9207100120F, 0.9211192973F, 0.9215272147F,
  143748. 0.9219337653F, 0.9223389504F, 0.9227427713F, 0.9231452290F,
  143749. 0.9235463251F, 0.9239460607F, 0.9243444371F, 0.9247414557F,
  143750. 0.9251371177F, 0.9255314245F, 0.9259243774F, 0.9263159778F,
  143751. 0.9267062270F, 0.9270951264F, 0.9274826774F, 0.9278688814F,
  143752. 0.9282537398F, 0.9286372540F, 0.9290194254F, 0.9294002555F,
  143753. 0.9297797458F, 0.9301578976F, 0.9305347125F, 0.9309101919F,
  143754. 0.9312843373F, 0.9316571503F, 0.9320286323F, 0.9323987849F,
  143755. 0.9327676097F, 0.9331351080F, 0.9335012816F, 0.9338661320F,
  143756. 0.9342296607F, 0.9345918694F, 0.9349527596F, 0.9353123330F,
  143757. 0.9356705911F, 0.9360275357F, 0.9363831683F, 0.9367374905F,
  143758. 0.9370905042F, 0.9374422108F, 0.9377926122F, 0.9381417099F,
  143759. 0.9384895057F, 0.9388360014F, 0.9391811985F, 0.9395250989F,
  143760. 0.9398677043F, 0.9402090165F, 0.9405490371F, 0.9408877680F,
  143761. 0.9412252110F, 0.9415613678F, 0.9418962402F, 0.9422298301F,
  143762. 0.9425621392F, 0.9428931695F, 0.9432229226F, 0.9435514005F,
  143763. 0.9438786050F, 0.9442045381F, 0.9445292014F, 0.9448525971F,
  143764. 0.9451747268F, 0.9454955926F, 0.9458151963F, 0.9461335399F,
  143765. 0.9464506253F, 0.9467664545F, 0.9470810293F, 0.9473943517F,
  143766. 0.9477064238F, 0.9480172474F, 0.9483268246F, 0.9486351573F,
  143767. 0.9489422475F, 0.9492480973F, 0.9495527087F, 0.9498560837F,
  143768. 0.9501582243F, 0.9504591325F, 0.9507588105F, 0.9510572603F,
  143769. 0.9513544839F, 0.9516504834F, 0.9519452609F, 0.9522388186F,
  143770. 0.9525311584F, 0.9528222826F, 0.9531121932F, 0.9534008923F,
  143771. 0.9536883821F, 0.9539746647F, 0.9542597424F, 0.9545436171F,
  143772. 0.9548262912F, 0.9551077667F, 0.9553880459F, 0.9556671309F,
  143773. 0.9559450239F, 0.9562217272F, 0.9564972429F, 0.9567715733F,
  143774. 0.9570447206F, 0.9573166871F, 0.9575874749F, 0.9578570863F,
  143775. 0.9581255236F, 0.9583927890F, 0.9586588849F, 0.9589238134F,
  143776. 0.9591875769F, 0.9594501777F, 0.9597116180F, 0.9599719003F,
  143777. 0.9602310267F, 0.9604889995F, 0.9607458213F, 0.9610014942F,
  143778. 0.9612560206F, 0.9615094028F, 0.9617616433F, 0.9620127443F,
  143779. 0.9622627083F, 0.9625115376F, 0.9627592345F, 0.9630058016F,
  143780. 0.9632512411F, 0.9634955555F, 0.9637387471F, 0.9639808185F,
  143781. 0.9642217720F, 0.9644616100F, 0.9647003349F, 0.9649379493F,
  143782. 0.9651744556F, 0.9654098561F, 0.9656441534F, 0.9658773499F,
  143783. 0.9661094480F, 0.9663404504F, 0.9665703593F, 0.9667991774F,
  143784. 0.9670269071F, 0.9672535509F, 0.9674791114F, 0.9677035909F,
  143785. 0.9679269921F, 0.9681493174F, 0.9683705694F, 0.9685907506F,
  143786. 0.9688098636F, 0.9690279108F, 0.9692448948F, 0.9694608182F,
  143787. 0.9696756836F, 0.9698894934F, 0.9701022503F, 0.9703139569F,
  143788. 0.9705246156F, 0.9707342291F, 0.9709428000F, 0.9711503309F,
  143789. 0.9713568243F, 0.9715622829F, 0.9717667093F, 0.9719701060F,
  143790. 0.9721724757F, 0.9723738210F, 0.9725741446F, 0.9727734490F,
  143791. 0.9729717369F, 0.9731690109F, 0.9733652737F, 0.9735605279F,
  143792. 0.9737547762F, 0.9739480212F, 0.9741402656F, 0.9743315120F,
  143793. 0.9745217631F, 0.9747110216F, 0.9748992901F, 0.9750865714F,
  143794. 0.9752728681F, 0.9754581829F, 0.9756425184F, 0.9758258775F,
  143795. 0.9760082627F, 0.9761896768F, 0.9763701224F, 0.9765496024F,
  143796. 0.9767281193F, 0.9769056760F, 0.9770822751F, 0.9772579193F,
  143797. 0.9774326114F, 0.9776063542F, 0.9777791502F, 0.9779510023F,
  143798. 0.9781219133F, 0.9782918858F, 0.9784609226F, 0.9786290264F,
  143799. 0.9787962000F, 0.9789624461F, 0.9791277676F, 0.9792921671F,
  143800. 0.9794556474F, 0.9796182113F, 0.9797798615F, 0.9799406009F,
  143801. 0.9801004321F, 0.9802593580F, 0.9804173813F, 0.9805745049F,
  143802. 0.9807307314F, 0.9808860637F, 0.9810405046F, 0.9811940568F,
  143803. 0.9813467232F, 0.9814985065F, 0.9816494095F, 0.9817994351F,
  143804. 0.9819485860F, 0.9820968650F, 0.9822442750F, 0.9823908186F,
  143805. 0.9825364988F, 0.9826813184F, 0.9828252801F, 0.9829683868F,
  143806. 0.9831106413F, 0.9832520463F, 0.9833926048F, 0.9835323195F,
  143807. 0.9836711932F, 0.9838092288F, 0.9839464291F, 0.9840827969F,
  143808. 0.9842183351F, 0.9843530464F, 0.9844869337F, 0.9846199998F,
  143809. 0.9847522475F, 0.9848836798F, 0.9850142993F, 0.9851441090F,
  143810. 0.9852731117F, 0.9854013101F, 0.9855287073F, 0.9856553058F,
  143811. 0.9857811087F, 0.9859061188F, 0.9860303388F, 0.9861537717F,
  143812. 0.9862764202F, 0.9863982872F, 0.9865193756F, 0.9866396882F,
  143813. 0.9867592277F, 0.9868779972F, 0.9869959993F, 0.9871132370F,
  143814. 0.9872297131F, 0.9873454304F, 0.9874603918F, 0.9875746001F,
  143815. 0.9876880581F, 0.9878007688F, 0.9879127348F, 0.9880239592F,
  143816. 0.9881344447F, 0.9882441941F, 0.9883532104F, 0.9884614962F,
  143817. 0.9885690546F, 0.9886758883F, 0.9887820001F, 0.9888873930F,
  143818. 0.9889920697F, 0.9890960331F, 0.9891992859F, 0.9893018312F,
  143819. 0.9894036716F, 0.9895048100F, 0.9896052493F, 0.9897049923F,
  143820. 0.9898040418F, 0.9899024006F, 0.9900000717F, 0.9900970577F,
  143821. 0.9901933616F, 0.9902889862F, 0.9903839343F, 0.9904782087F,
  143822. 0.9905718122F, 0.9906647477F, 0.9907570180F, 0.9908486259F,
  143823. 0.9909395742F, 0.9910298658F, 0.9911195034F, 0.9912084899F,
  143824. 0.9912968281F, 0.9913845208F, 0.9914715708F, 0.9915579810F,
  143825. 0.9916437540F, 0.9917288928F, 0.9918134001F, 0.9918972788F,
  143826. 0.9919805316F, 0.9920631613F, 0.9921451707F, 0.9922265626F,
  143827. 0.9923073399F, 0.9923875052F, 0.9924670615F, 0.9925460114F,
  143828. 0.9926243577F, 0.9927021033F, 0.9927792508F, 0.9928558032F,
  143829. 0.9929317631F, 0.9930071333F, 0.9930819167F, 0.9931561158F,
  143830. 0.9932297337F, 0.9933027728F, 0.9933752362F, 0.9934471264F,
  143831. 0.9935184462F, 0.9935891985F, 0.9936593859F, 0.9937290112F,
  143832. 0.9937980771F, 0.9938665864F, 0.9939345418F, 0.9940019460F,
  143833. 0.9940688018F, 0.9941351118F, 0.9942008789F, 0.9942661057F,
  143834. 0.9943307950F, 0.9943949494F, 0.9944585717F, 0.9945216645F,
  143835. 0.9945842307F, 0.9946462728F, 0.9947077936F, 0.9947687957F,
  143836. 0.9948292820F, 0.9948892550F, 0.9949487174F, 0.9950076719F,
  143837. 0.9950661212F, 0.9951240679F, 0.9951815148F, 0.9952384645F,
  143838. 0.9952949196F, 0.9953508828F, 0.9954063568F, 0.9954613442F,
  143839. 0.9955158476F, 0.9955698697F, 0.9956234132F, 0.9956764806F,
  143840. 0.9957290746F, 0.9957811978F, 0.9958328528F, 0.9958840423F,
  143841. 0.9959347688F, 0.9959850351F, 0.9960348435F, 0.9960841969F,
  143842. 0.9961330977F, 0.9961815486F, 0.9962295521F, 0.9962771108F,
  143843. 0.9963242274F, 0.9963709043F, 0.9964171441F, 0.9964629494F,
  143844. 0.9965083228F, 0.9965532668F, 0.9965977840F, 0.9966418768F,
  143845. 0.9966855479F, 0.9967287998F, 0.9967716350F, 0.9968140559F,
  143846. 0.9968560653F, 0.9968976655F, 0.9969388591F, 0.9969796485F,
  143847. 0.9970200363F, 0.9970600250F, 0.9970996170F, 0.9971388149F,
  143848. 0.9971776211F, 0.9972160380F, 0.9972540683F, 0.9972917142F,
  143849. 0.9973289783F, 0.9973658631F, 0.9974023709F, 0.9974385042F,
  143850. 0.9974742655F, 0.9975096571F, 0.9975446816F, 0.9975793413F,
  143851. 0.9976136386F, 0.9976475759F, 0.9976811557F, 0.9977143803F,
  143852. 0.9977472521F, 0.9977797736F, 0.9978119470F, 0.9978437748F,
  143853. 0.9978752593F, 0.9979064029F, 0.9979372079F, 0.9979676768F,
  143854. 0.9979978117F, 0.9980276151F, 0.9980570893F, 0.9980862367F,
  143855. 0.9981150595F, 0.9981435600F, 0.9981717406F, 0.9981996035F,
  143856. 0.9982271511F, 0.9982543856F, 0.9982813093F, 0.9983079246F,
  143857. 0.9983342336F, 0.9983602386F, 0.9983859418F, 0.9984113456F,
  143858. 0.9984364522F, 0.9984612638F, 0.9984857825F, 0.9985100108F,
  143859. 0.9985339507F, 0.9985576044F, 0.9985809743F, 0.9986040624F,
  143860. 0.9986268710F, 0.9986494022F, 0.9986716583F, 0.9986936413F,
  143861. 0.9987153535F, 0.9987367969F, 0.9987579738F, 0.9987788864F,
  143862. 0.9987995366F, 0.9988199267F, 0.9988400587F, 0.9988599348F,
  143863. 0.9988795572F, 0.9988989278F, 0.9989180487F, 0.9989369222F,
  143864. 0.9989555501F, 0.9989739347F, 0.9989920780F, 0.9990099820F,
  143865. 0.9990276487F, 0.9990450803F, 0.9990622787F, 0.9990792460F,
  143866. 0.9990959841F, 0.9991124952F, 0.9991287812F, 0.9991448440F,
  143867. 0.9991606858F, 0.9991763084F, 0.9991917139F, 0.9992069042F,
  143868. 0.9992218813F, 0.9992366471F, 0.9992512035F, 0.9992655525F,
  143869. 0.9992796961F, 0.9992936361F, 0.9993073744F, 0.9993209131F,
  143870. 0.9993342538F, 0.9993473987F, 0.9993603494F, 0.9993731080F,
  143871. 0.9993856762F, 0.9993980559F, 0.9994102490F, 0.9994222573F,
  143872. 0.9994340827F, 0.9994457269F, 0.9994571918F, 0.9994684793F,
  143873. 0.9994795910F, 0.9994905288F, 0.9995012945F, 0.9995118898F,
  143874. 0.9995223165F, 0.9995325765F, 0.9995426713F, 0.9995526029F,
  143875. 0.9995623728F, 0.9995719829F, 0.9995814349F, 0.9995907304F,
  143876. 0.9995998712F, 0.9996088590F, 0.9996176954F, 0.9996263821F,
  143877. 0.9996349208F, 0.9996433132F, 0.9996515609F, 0.9996596656F,
  143878. 0.9996676288F, 0.9996754522F, 0.9996831375F, 0.9996906862F,
  143879. 0.9996981000F, 0.9997053804F, 0.9997125290F, 0.9997195474F,
  143880. 0.9997264371F, 0.9997331998F, 0.9997398369F, 0.9997463500F,
  143881. 0.9997527406F, 0.9997590103F, 0.9997651606F, 0.9997711930F,
  143882. 0.9997771089F, 0.9997829098F, 0.9997885973F, 0.9997941728F,
  143883. 0.9997996378F, 0.9998049936F, 0.9998102419F, 0.9998153839F,
  143884. 0.9998204211F, 0.9998253550F, 0.9998301868F, 0.9998349182F,
  143885. 0.9998395503F, 0.9998440847F, 0.9998485226F, 0.9998528654F,
  143886. 0.9998571146F, 0.9998612713F, 0.9998653370F, 0.9998693130F,
  143887. 0.9998732007F, 0.9998770012F, 0.9998807159F, 0.9998843461F,
  143888. 0.9998878931F, 0.9998913581F, 0.9998947424F, 0.9998980473F,
  143889. 0.9999012740F, 0.9999044237F, 0.9999074976F, 0.9999104971F,
  143890. 0.9999134231F, 0.9999162771F, 0.9999190601F, 0.9999217733F,
  143891. 0.9999244179F, 0.9999269950F, 0.9999295058F, 0.9999319515F,
  143892. 0.9999343332F, 0.9999366519F, 0.9999389088F, 0.9999411050F,
  143893. 0.9999432416F, 0.9999453196F, 0.9999473402F, 0.9999493044F,
  143894. 0.9999512132F, 0.9999530677F, 0.9999548690F, 0.9999566180F,
  143895. 0.9999583157F, 0.9999599633F, 0.9999615616F, 0.9999631116F,
  143896. 0.9999646144F, 0.9999660709F, 0.9999674820F, 0.9999688487F,
  143897. 0.9999701719F, 0.9999714526F, 0.9999726917F, 0.9999738900F,
  143898. 0.9999750486F, 0.9999761682F, 0.9999772497F, 0.9999782941F,
  143899. 0.9999793021F, 0.9999802747F, 0.9999812126F, 0.9999821167F,
  143900. 0.9999829878F, 0.9999838268F, 0.9999846343F, 0.9999854113F,
  143901. 0.9999861584F, 0.9999868765F, 0.9999875664F, 0.9999882287F,
  143902. 0.9999888642F, 0.9999894736F, 0.9999900577F, 0.9999906172F,
  143903. 0.9999911528F, 0.9999916651F, 0.9999921548F, 0.9999926227F,
  143904. 0.9999930693F, 0.9999934954F, 0.9999939015F, 0.9999942883F,
  143905. 0.9999946564F, 0.9999950064F, 0.9999953390F, 0.9999956547F,
  143906. 0.9999959541F, 0.9999962377F, 0.9999965062F, 0.9999967601F,
  143907. 0.9999969998F, 0.9999972260F, 0.9999974392F, 0.9999976399F,
  143908. 0.9999978285F, 0.9999980056F, 0.9999981716F, 0.9999983271F,
  143909. 0.9999984724F, 0.9999986081F, 0.9999987345F, 0.9999988521F,
  143910. 0.9999989613F, 0.9999990625F, 0.9999991562F, 0.9999992426F,
  143911. 0.9999993223F, 0.9999993954F, 0.9999994625F, 0.9999995239F,
  143912. 0.9999995798F, 0.9999996307F, 0.9999996768F, 0.9999997184F,
  143913. 0.9999997559F, 0.9999997895F, 0.9999998195F, 0.9999998462F,
  143914. 0.9999998698F, 0.9999998906F, 0.9999999088F, 0.9999999246F,
  143915. 0.9999999383F, 0.9999999500F, 0.9999999600F, 0.9999999684F,
  143916. 0.9999999754F, 0.9999999811F, 0.9999999858F, 0.9999999896F,
  143917. 0.9999999925F, 0.9999999948F, 0.9999999965F, 0.9999999978F,
  143918. 0.9999999986F, 0.9999999992F, 0.9999999996F, 0.9999999998F,
  143919. 0.9999999999F, 1.0000000000F, 1.0000000000F, 1.0000000000F,
  143920. };
  143921. static float vwin8192[4096] = {
  143922. 0.0000000578F, 0.0000005198F, 0.0000014438F, 0.0000028299F,
  143923. 0.0000046780F, 0.0000069882F, 0.0000097604F, 0.0000129945F,
  143924. 0.0000166908F, 0.0000208490F, 0.0000254692F, 0.0000305515F,
  143925. 0.0000360958F, 0.0000421021F, 0.0000485704F, 0.0000555006F,
  143926. 0.0000628929F, 0.0000707472F, 0.0000790635F, 0.0000878417F,
  143927. 0.0000970820F, 0.0001067842F, 0.0001169483F, 0.0001275744F,
  143928. 0.0001386625F, 0.0001502126F, 0.0001622245F, 0.0001746984F,
  143929. 0.0001876343F, 0.0002010320F, 0.0002148917F, 0.0002292132F,
  143930. 0.0002439967F, 0.0002592421F, 0.0002749493F, 0.0002911184F,
  143931. 0.0003077493F, 0.0003248421F, 0.0003423967F, 0.0003604132F,
  143932. 0.0003788915F, 0.0003978316F, 0.0004172335F, 0.0004370971F,
  143933. 0.0004574226F, 0.0004782098F, 0.0004994587F, 0.0005211694F,
  143934. 0.0005433418F, 0.0005659759F, 0.0005890717F, 0.0006126292F,
  143935. 0.0006366484F, 0.0006611292F, 0.0006860716F, 0.0007114757F,
  143936. 0.0007373414F, 0.0007636687F, 0.0007904576F, 0.0008177080F,
  143937. 0.0008454200F, 0.0008735935F, 0.0009022285F, 0.0009313250F,
  143938. 0.0009608830F, 0.0009909025F, 0.0010213834F, 0.0010523257F,
  143939. 0.0010837295F, 0.0011155946F, 0.0011479211F, 0.0011807090F,
  143940. 0.0012139582F, 0.0012476687F, 0.0012818405F, 0.0013164736F,
  143941. 0.0013515679F, 0.0013871235F, 0.0014231402F, 0.0014596182F,
  143942. 0.0014965573F, 0.0015339576F, 0.0015718190F, 0.0016101415F,
  143943. 0.0016489251F, 0.0016881698F, 0.0017278754F, 0.0017680421F,
  143944. 0.0018086698F, 0.0018497584F, 0.0018913080F, 0.0019333185F,
  143945. 0.0019757898F, 0.0020187221F, 0.0020621151F, 0.0021059690F,
  143946. 0.0021502837F, 0.0021950591F, 0.0022402953F, 0.0022859921F,
  143947. 0.0023321497F, 0.0023787679F, 0.0024258467F, 0.0024733861F,
  143948. 0.0025213861F, 0.0025698466F, 0.0026187676F, 0.0026681491F,
  143949. 0.0027179911F, 0.0027682935F, 0.0028190562F, 0.0028702794F,
  143950. 0.0029219628F, 0.0029741066F, 0.0030267107F, 0.0030797749F,
  143951. 0.0031332994F, 0.0031872841F, 0.0032417289F, 0.0032966338F,
  143952. 0.0033519988F, 0.0034078238F, 0.0034641089F, 0.0035208539F,
  143953. 0.0035780589F, 0.0036357237F, 0.0036938485F, 0.0037524331F,
  143954. 0.0038114775F, 0.0038709817F, 0.0039309456F, 0.0039913692F,
  143955. 0.0040522524F, 0.0041135953F, 0.0041753978F, 0.0042376599F,
  143956. 0.0043003814F, 0.0043635624F, 0.0044272029F, 0.0044913028F,
  143957. 0.0045558620F, 0.0046208806F, 0.0046863585F, 0.0047522955F,
  143958. 0.0048186919F, 0.0048855473F, 0.0049528619F, 0.0050206356F,
  143959. 0.0050888684F, 0.0051575601F, 0.0052267108F, 0.0052963204F,
  143960. 0.0053663890F, 0.0054369163F, 0.0055079025F, 0.0055793474F,
  143961. 0.0056512510F, 0.0057236133F, 0.0057964342F, 0.0058697137F,
  143962. 0.0059434517F, 0.0060176482F, 0.0060923032F, 0.0061674166F,
  143963. 0.0062429883F, 0.0063190183F, 0.0063955066F, 0.0064724532F,
  143964. 0.0065498579F, 0.0066277207F, 0.0067060416F, 0.0067848205F,
  143965. 0.0068640575F, 0.0069437523F, 0.0070239051F, 0.0071045157F,
  143966. 0.0071855840F, 0.0072671102F, 0.0073490940F, 0.0074315355F,
  143967. 0.0075144345F, 0.0075977911F, 0.0076816052F, 0.0077658768F,
  143968. 0.0078506057F, 0.0079357920F, 0.0080214355F, 0.0081075363F,
  143969. 0.0081940943F, 0.0082811094F, 0.0083685816F, 0.0084565108F,
  143970. 0.0085448970F, 0.0086337401F, 0.0087230401F, 0.0088127969F,
  143971. 0.0089030104F, 0.0089936807F, 0.0090848076F, 0.0091763911F,
  143972. 0.0092684311F, 0.0093609276F, 0.0094538805F, 0.0095472898F,
  143973. 0.0096411554F, 0.0097354772F, 0.0098302552F, 0.0099254894F,
  143974. 0.0100211796F, 0.0101173259F, 0.0102139281F, 0.0103109863F,
  143975. 0.0104085002F, 0.0105064700F, 0.0106048955F, 0.0107037766F,
  143976. 0.0108031133F, 0.0109029056F, 0.0110031534F, 0.0111038565F,
  143977. 0.0112050151F, 0.0113066289F, 0.0114086980F, 0.0115112222F,
  143978. 0.0116142015F, 0.0117176359F, 0.0118215252F, 0.0119258695F,
  143979. 0.0120306686F, 0.0121359225F, 0.0122416312F, 0.0123477944F,
  143980. 0.0124544123F, 0.0125614847F, 0.0126690116F, 0.0127769928F,
  143981. 0.0128854284F, 0.0129943182F, 0.0131036623F, 0.0132134604F,
  143982. 0.0133237126F, 0.0134344188F, 0.0135455790F, 0.0136571929F,
  143983. 0.0137692607F, 0.0138817821F, 0.0139947572F, 0.0141081859F,
  143984. 0.0142220681F, 0.0143364037F, 0.0144511927F, 0.0145664350F,
  143985. 0.0146821304F, 0.0147982791F, 0.0149148808F, 0.0150319355F,
  143986. 0.0151494431F, 0.0152674036F, 0.0153858168F, 0.0155046828F,
  143987. 0.0156240014F, 0.0157437726F, 0.0158639962F, 0.0159846723F,
  143988. 0.0161058007F, 0.0162273814F, 0.0163494142F, 0.0164718991F,
  143989. 0.0165948361F, 0.0167182250F, 0.0168420658F, 0.0169663584F,
  143990. 0.0170911027F, 0.0172162987F, 0.0173419462F, 0.0174680452F,
  143991. 0.0175945956F, 0.0177215974F, 0.0178490504F, 0.0179769545F,
  143992. 0.0181053098F, 0.0182341160F, 0.0183633732F, 0.0184930812F,
  143993. 0.0186232399F, 0.0187538494F, 0.0188849094F, 0.0190164200F,
  143994. 0.0191483809F, 0.0192807923F, 0.0194136539F, 0.0195469656F,
  143995. 0.0196807275F, 0.0198149394F, 0.0199496012F, 0.0200847128F,
  143996. 0.0202202742F, 0.0203562853F, 0.0204927460F, 0.0206296561F,
  143997. 0.0207670157F, 0.0209048245F, 0.0210430826F, 0.0211817899F,
  143998. 0.0213209462F, 0.0214605515F, 0.0216006057F, 0.0217411086F,
  143999. 0.0218820603F, 0.0220234605F, 0.0221653093F, 0.0223076066F,
  144000. 0.0224503521F, 0.0225935459F, 0.0227371879F, 0.0228812779F,
  144001. 0.0230258160F, 0.0231708018F, 0.0233162355F, 0.0234621169F,
  144002. 0.0236084459F, 0.0237552224F, 0.0239024462F, 0.0240501175F,
  144003. 0.0241982359F, 0.0243468015F, 0.0244958141F, 0.0246452736F,
  144004. 0.0247951800F, 0.0249455331F, 0.0250963329F, 0.0252475792F,
  144005. 0.0253992720F, 0.0255514111F, 0.0257039965F, 0.0258570281F,
  144006. 0.0260105057F, 0.0261644293F, 0.0263187987F, 0.0264736139F,
  144007. 0.0266288747F, 0.0267845811F, 0.0269407330F, 0.0270973302F,
  144008. 0.0272543727F, 0.0274118604F, 0.0275697930F, 0.0277281707F,
  144009. 0.0278869932F, 0.0280462604F, 0.0282059723F, 0.0283661287F,
  144010. 0.0285267295F, 0.0286877747F, 0.0288492641F, 0.0290111976F,
  144011. 0.0291735751F, 0.0293363965F, 0.0294996617F, 0.0296633706F,
  144012. 0.0298275231F, 0.0299921190F, 0.0301571583F, 0.0303226409F,
  144013. 0.0304885667F, 0.0306549354F, 0.0308217472F, 0.0309890017F,
  144014. 0.0311566989F, 0.0313248388F, 0.0314934211F, 0.0316624459F,
  144015. 0.0318319128F, 0.0320018220F, 0.0321721732F, 0.0323429663F,
  144016. 0.0325142013F, 0.0326858779F, 0.0328579962F, 0.0330305559F,
  144017. 0.0332035570F, 0.0333769994F, 0.0335508829F, 0.0337252074F,
  144018. 0.0338999728F, 0.0340751790F, 0.0342508259F, 0.0344269134F,
  144019. 0.0346034412F, 0.0347804094F, 0.0349578178F, 0.0351356663F,
  144020. 0.0353139548F, 0.0354926831F, 0.0356718511F, 0.0358514588F,
  144021. 0.0360315059F, 0.0362119924F, 0.0363929182F, 0.0365742831F,
  144022. 0.0367560870F, 0.0369383297F, 0.0371210113F, 0.0373041315F,
  144023. 0.0374876902F, 0.0376716873F, 0.0378561226F, 0.0380409961F,
  144024. 0.0382263077F, 0.0384120571F, 0.0385982443F, 0.0387848691F,
  144025. 0.0389719315F, 0.0391594313F, 0.0393473683F, 0.0395357425F,
  144026. 0.0397245537F, 0.0399138017F, 0.0401034866F, 0.0402936080F,
  144027. 0.0404841660F, 0.0406751603F, 0.0408665909F, 0.0410584576F,
  144028. 0.0412507603F, 0.0414434988F, 0.0416366731F, 0.0418302829F,
  144029. 0.0420243282F, 0.0422188088F, 0.0424137246F, 0.0426090755F,
  144030. 0.0428048613F, 0.0430010819F, 0.0431977371F, 0.0433948269F,
  144031. 0.0435923511F, 0.0437903095F, 0.0439887020F, 0.0441875285F,
  144032. 0.0443867889F, 0.0445864830F, 0.0447866106F, 0.0449871717F,
  144033. 0.0451881661F, 0.0453895936F, 0.0455914542F, 0.0457937477F,
  144034. 0.0459964738F, 0.0461996326F, 0.0464032239F, 0.0466072475F,
  144035. 0.0468117032F, 0.0470165910F, 0.0472219107F, 0.0474276622F,
  144036. 0.0476338452F, 0.0478404597F, 0.0480475056F, 0.0482549827F,
  144037. 0.0484628907F, 0.0486712297F, 0.0488799994F, 0.0490891998F,
  144038. 0.0492988306F, 0.0495088917F, 0.0497193830F, 0.0499303043F,
  144039. 0.0501416554F, 0.0503534363F, 0.0505656468F, 0.0507782867F,
  144040. 0.0509913559F, 0.0512048542F, 0.0514187815F, 0.0516331376F,
  144041. 0.0518479225F, 0.0520631358F, 0.0522787775F, 0.0524948475F,
  144042. 0.0527113455F, 0.0529282715F, 0.0531456252F, 0.0533634066F,
  144043. 0.0535816154F, 0.0538002515F, 0.0540193148F, 0.0542388051F,
  144044. 0.0544587222F, 0.0546790660F, 0.0548998364F, 0.0551210331F,
  144045. 0.0553426561F, 0.0555647051F, 0.0557871801F, 0.0560100807F,
  144046. 0.0562334070F, 0.0564571587F, 0.0566813357F, 0.0569059378F,
  144047. 0.0571309649F, 0.0573564168F, 0.0575822933F, 0.0578085942F,
  144048. 0.0580353195F, 0.0582624689F, 0.0584900423F, 0.0587180396F,
  144049. 0.0589464605F, 0.0591753049F, 0.0594045726F, 0.0596342635F,
  144050. 0.0598643774F, 0.0600949141F, 0.0603258735F, 0.0605572555F,
  144051. 0.0607890597F, 0.0610212862F, 0.0612539346F, 0.0614870049F,
  144052. 0.0617204968F, 0.0619544103F, 0.0621887451F, 0.0624235010F,
  144053. 0.0626586780F, 0.0628942758F, 0.0631302942F, 0.0633667331F,
  144054. 0.0636035923F, 0.0638408717F, 0.0640785710F, 0.0643166901F,
  144055. 0.0645552288F, 0.0647941870F, 0.0650335645F, 0.0652733610F,
  144056. 0.0655135765F, 0.0657542108F, 0.0659952636F, 0.0662367348F,
  144057. 0.0664786242F, 0.0667209316F, 0.0669636570F, 0.0672068000F,
  144058. 0.0674503605F, 0.0676943384F, 0.0679387334F, 0.0681835454F,
  144059. 0.0684287742F, 0.0686744196F, 0.0689204814F, 0.0691669595F,
  144060. 0.0694138536F, 0.0696611637F, 0.0699088894F, 0.0701570307F,
  144061. 0.0704055873F, 0.0706545590F, 0.0709039458F, 0.0711537473F,
  144062. 0.0714039634F, 0.0716545939F, 0.0719056387F, 0.0721570975F,
  144063. 0.0724089702F, 0.0726612565F, 0.0729139563F, 0.0731670694F,
  144064. 0.0734205956F, 0.0736745347F, 0.0739288866F, 0.0741836510F,
  144065. 0.0744388277F, 0.0746944166F, 0.0749504175F, 0.0752068301F,
  144066. 0.0754636543F, 0.0757208899F, 0.0759785367F, 0.0762365946F,
  144067. 0.0764950632F, 0.0767539424F, 0.0770132320F, 0.0772729319F,
  144068. 0.0775330418F, 0.0777935616F, 0.0780544909F, 0.0783158298F,
  144069. 0.0785775778F, 0.0788397349F, 0.0791023009F, 0.0793652755F,
  144070. 0.0796286585F, 0.0798924498F, 0.0801566492F, 0.0804212564F,
  144071. 0.0806862712F, 0.0809516935F, 0.0812175231F, 0.0814837597F,
  144072. 0.0817504031F, 0.0820174532F, 0.0822849097F, 0.0825527724F,
  144073. 0.0828210412F, 0.0830897158F, 0.0833587960F, 0.0836282816F,
  144074. 0.0838981724F, 0.0841684682F, 0.0844391688F, 0.0847102740F,
  144075. 0.0849817835F, 0.0852536973F, 0.0855260150F, 0.0857987364F,
  144076. 0.0860718614F, 0.0863453897F, 0.0866193211F, 0.0868936554F,
  144077. 0.0871683924F, 0.0874435319F, 0.0877190737F, 0.0879950175F,
  144078. 0.0882713632F, 0.0885481105F, 0.0888252592F, 0.0891028091F,
  144079. 0.0893807600F, 0.0896591117F, 0.0899378639F, 0.0902170165F,
  144080. 0.0904965692F, 0.0907765218F, 0.0910568740F, 0.0913376258F,
  144081. 0.0916187767F, 0.0919003268F, 0.0921822756F, 0.0924646230F,
  144082. 0.0927473687F, 0.0930305126F, 0.0933140545F, 0.0935979940F,
  144083. 0.0938823310F, 0.0941670653F, 0.0944521966F, 0.0947377247F,
  144084. 0.0950236494F, 0.0953099704F, 0.0955966876F, 0.0958838007F,
  144085. 0.0961713094F, 0.0964592136F, 0.0967475131F, 0.0970362075F,
  144086. 0.0973252967F, 0.0976147805F, 0.0979046585F, 0.0981949307F,
  144087. 0.0984855967F, 0.0987766563F, 0.0990681093F, 0.0993599555F,
  144088. 0.0996521945F, 0.0999448263F, 0.1002378506F, 0.1005312671F,
  144089. 0.1008250755F, 0.1011192757F, 0.1014138675F, 0.1017088505F,
  144090. 0.1020042246F, 0.1022999895F, 0.1025961450F, 0.1028926909F,
  144091. 0.1031896268F, 0.1034869526F, 0.1037846680F, 0.1040827729F,
  144092. 0.1043812668F, 0.1046801497F, 0.1049794213F, 0.1052790813F,
  144093. 0.1055791294F, 0.1058795656F, 0.1061803894F, 0.1064816006F,
  144094. 0.1067831991F, 0.1070851846F, 0.1073875568F, 0.1076903155F,
  144095. 0.1079934604F, 0.1082969913F, 0.1086009079F, 0.1089052101F,
  144096. 0.1092098975F, 0.1095149699F, 0.1098204270F, 0.1101262687F,
  144097. 0.1104324946F, 0.1107391045F, 0.1110460982F, 0.1113534754F,
  144098. 0.1116612359F, 0.1119693793F, 0.1122779055F, 0.1125868142F,
  144099. 0.1128961052F, 0.1132057781F, 0.1135158328F, 0.1138262690F,
  144100. 0.1141370863F, 0.1144482847F, 0.1147598638F, 0.1150718233F,
  144101. 0.1153841631F, 0.1156968828F, 0.1160099822F, 0.1163234610F,
  144102. 0.1166373190F, 0.1169515559F, 0.1172661714F, 0.1175811654F,
  144103. 0.1178965374F, 0.1182122874F, 0.1185284149F, 0.1188449198F,
  144104. 0.1191618018F, 0.1194790606F, 0.1197966960F, 0.1201147076F,
  144105. 0.1204330953F, 0.1207518587F, 0.1210709976F, 0.1213905118F,
  144106. 0.1217104009F, 0.1220306647F, 0.1223513029F, 0.1226723153F,
  144107. 0.1229937016F, 0.1233154615F, 0.1236375948F, 0.1239601011F,
  144108. 0.1242829803F, 0.1246062319F, 0.1249298559F, 0.1252538518F,
  144109. 0.1255782195F, 0.1259029586F, 0.1262280689F, 0.1265535501F,
  144110. 0.1268794019F, 0.1272056241F, 0.1275322163F, 0.1278591784F,
  144111. 0.1281865099F, 0.1285142108F, 0.1288422805F, 0.1291707190F,
  144112. 0.1294995259F, 0.1298287009F, 0.1301582437F, 0.1304881542F,
  144113. 0.1308184319F, 0.1311490766F, 0.1314800881F, 0.1318114660F,
  144114. 0.1321432100F, 0.1324753200F, 0.1328077955F, 0.1331406364F,
  144115. 0.1334738422F, 0.1338074129F, 0.1341413479F, 0.1344756472F,
  144116. 0.1348103103F, 0.1351453370F, 0.1354807270F, 0.1358164801F,
  144117. 0.1361525959F, 0.1364890741F, 0.1368259145F, 0.1371631167F,
  144118. 0.1375006805F, 0.1378386056F, 0.1381768917F, 0.1385155384F,
  144119. 0.1388545456F, 0.1391939129F, 0.1395336400F, 0.1398737266F,
  144120. 0.1402141724F, 0.1405549772F, 0.1408961406F, 0.1412376623F,
  144121. 0.1415795421F, 0.1419217797F, 0.1422643746F, 0.1426073268F,
  144122. 0.1429506358F, 0.1432943013F, 0.1436383231F, 0.1439827008F,
  144123. 0.1443274342F, 0.1446725229F, 0.1450179667F, 0.1453637652F,
  144124. 0.1457099181F, 0.1460564252F, 0.1464032861F, 0.1467505006F,
  144125. 0.1470980682F, 0.1474459888F, 0.1477942620F, 0.1481428875F,
  144126. 0.1484918651F, 0.1488411942F, 0.1491908748F, 0.1495409065F,
  144127. 0.1498912889F, 0.1502420218F, 0.1505931048F, 0.1509445376F,
  144128. 0.1512963200F, 0.1516484516F, 0.1520009321F, 0.1523537612F,
  144129. 0.1527069385F, 0.1530604638F, 0.1534143368F, 0.1537685571F,
  144130. 0.1541231244F, 0.1544780384F, 0.1548332987F, 0.1551889052F,
  144131. 0.1555448574F, 0.1559011550F, 0.1562577978F, 0.1566147853F,
  144132. 0.1569721173F, 0.1573297935F, 0.1576878135F, 0.1580461771F,
  144133. 0.1584048838F, 0.1587639334F, 0.1591233255F, 0.1594830599F,
  144134. 0.1598431361F, 0.1602035540F, 0.1605643131F, 0.1609254131F,
  144135. 0.1612868537F, 0.1616486346F, 0.1620107555F, 0.1623732160F,
  144136. 0.1627360158F, 0.1630991545F, 0.1634626319F, 0.1638264476F,
  144137. 0.1641906013F, 0.1645550926F, 0.1649199212F, 0.1652850869F,
  144138. 0.1656505892F, 0.1660164278F, 0.1663826024F, 0.1667491127F,
  144139. 0.1671159583F, 0.1674831388F, 0.1678506541F, 0.1682185036F,
  144140. 0.1685866872F, 0.1689552044F, 0.1693240549F, 0.1696932384F,
  144141. 0.1700627545F, 0.1704326029F, 0.1708027833F, 0.1711732952F,
  144142. 0.1715441385F, 0.1719153127F, 0.1722868175F, 0.1726586526F,
  144143. 0.1730308176F, 0.1734033121F, 0.1737761359F, 0.1741492886F,
  144144. 0.1745227698F, 0.1748965792F, 0.1752707164F, 0.1756451812F,
  144145. 0.1760199731F, 0.1763950918F, 0.1767705370F, 0.1771463083F,
  144146. 0.1775224054F, 0.1778988279F, 0.1782755754F, 0.1786526477F,
  144147. 0.1790300444F, 0.1794077651F, 0.1797858094F, 0.1801641771F,
  144148. 0.1805428677F, 0.1809218810F, 0.1813012165F, 0.1816808739F,
  144149. 0.1820608528F, 0.1824411530F, 0.1828217739F, 0.1832027154F,
  144150. 0.1835839770F, 0.1839655584F, 0.1843474592F, 0.1847296790F,
  144151. 0.1851122175F, 0.1854950744F, 0.1858782492F, 0.1862617417F,
  144152. 0.1866455514F, 0.1870296780F, 0.1874141211F, 0.1877988804F,
  144153. 0.1881839555F, 0.1885693461F, 0.1889550517F, 0.1893410721F,
  144154. 0.1897274068F, 0.1901140555F, 0.1905010178F, 0.1908882933F,
  144155. 0.1912758818F, 0.1916637828F, 0.1920519959F, 0.1924405208F,
  144156. 0.1928293571F, 0.1932185044F, 0.1936079625F, 0.1939977308F,
  144157. 0.1943878091F, 0.1947781969F, 0.1951688939F, 0.1955598998F,
  144158. 0.1959512141F, 0.1963428364F, 0.1967347665F, 0.1971270038F,
  144159. 0.1975195482F, 0.1979123990F, 0.1983055561F, 0.1986990190F,
  144160. 0.1990927873F, 0.1994868607F, 0.1998812388F, 0.2002759212F,
  144161. 0.2006709075F, 0.2010661974F, 0.2014617904F, 0.2018576862F,
  144162. 0.2022538844F, 0.2026503847F, 0.2030471865F, 0.2034442897F,
  144163. 0.2038416937F, 0.2042393982F, 0.2046374028F, 0.2050357071F,
  144164. 0.2054343107F, 0.2058332133F, 0.2062324145F, 0.2066319138F,
  144165. 0.2070317110F, 0.2074318055F, 0.2078321970F, 0.2082328852F,
  144166. 0.2086338696F, 0.2090351498F, 0.2094367255F, 0.2098385962F,
  144167. 0.2102407617F, 0.2106432213F, 0.2110459749F, 0.2114490220F,
  144168. 0.2118523621F, 0.2122559950F, 0.2126599202F, 0.2130641373F,
  144169. 0.2134686459F, 0.2138734456F, 0.2142785361F, 0.2146839168F,
  144170. 0.2150895875F, 0.2154955478F, 0.2159017972F, 0.2163083353F,
  144171. 0.2167151617F, 0.2171222761F, 0.2175296780F, 0.2179373670F,
  144172. 0.2183453428F, 0.2187536049F, 0.2191621529F, 0.2195709864F,
  144173. 0.2199801051F, 0.2203895085F, 0.2207991961F, 0.2212091677F,
  144174. 0.2216194228F, 0.2220299610F, 0.2224407818F, 0.2228518850F,
  144175. 0.2232632699F, 0.2236749364F, 0.2240868839F, 0.2244991121F,
  144176. 0.2249116204F, 0.2253244086F, 0.2257374763F, 0.2261508229F,
  144177. 0.2265644481F, 0.2269783514F, 0.2273925326F, 0.2278069911F,
  144178. 0.2282217265F, 0.2286367384F, 0.2290520265F, 0.2294675902F,
  144179. 0.2298834292F, 0.2302995431F, 0.2307159314F, 0.2311325937F,
  144180. 0.2315495297F, 0.2319667388F, 0.2323842207F, 0.2328019749F,
  144181. 0.2332200011F, 0.2336382988F, 0.2340568675F, 0.2344757070F,
  144182. 0.2348948166F, 0.2353141961F, 0.2357338450F, 0.2361537629F,
  144183. 0.2365739493F, 0.2369944038F, 0.2374151261F, 0.2378361156F,
  144184. 0.2382573720F, 0.2386788948F, 0.2391006836F, 0.2395227380F,
  144185. 0.2399450575F, 0.2403676417F, 0.2407904902F, 0.2412136026F,
  144186. 0.2416369783F, 0.2420606171F, 0.2424845185F, 0.2429086820F,
  144187. 0.2433331072F, 0.2437577936F, 0.2441827409F, 0.2446079486F,
  144188. 0.2450334163F, 0.2454591435F, 0.2458851298F, 0.2463113747F,
  144189. 0.2467378779F, 0.2471646389F, 0.2475916573F, 0.2480189325F,
  144190. 0.2484464643F, 0.2488742521F, 0.2493022955F, 0.2497305940F,
  144191. 0.2501591473F, 0.2505879549F, 0.2510170163F, 0.2514463311F,
  144192. 0.2518758989F, 0.2523057193F, 0.2527357916F, 0.2531661157F,
  144193. 0.2535966909F, 0.2540275169F, 0.2544585931F, 0.2548899193F,
  144194. 0.2553214948F, 0.2557533193F, 0.2561853924F, 0.2566177135F,
  144195. 0.2570502822F, 0.2574830981F, 0.2579161608F, 0.2583494697F,
  144196. 0.2587830245F, 0.2592168246F, 0.2596508697F, 0.2600851593F,
  144197. 0.2605196929F, 0.2609544701F, 0.2613894904F, 0.2618247534F,
  144198. 0.2622602586F, 0.2626960055F, 0.2631319938F, 0.2635682230F,
  144199. 0.2640046925F, 0.2644414021F, 0.2648783511F, 0.2653155391F,
  144200. 0.2657529657F, 0.2661906305F, 0.2666285329F, 0.2670666725F,
  144201. 0.2675050489F, 0.2679436616F, 0.2683825101F, 0.2688215940F,
  144202. 0.2692609127F, 0.2697004660F, 0.2701402532F, 0.2705802739F,
  144203. 0.2710205278F, 0.2714610142F, 0.2719017327F, 0.2723426830F,
  144204. 0.2727838644F, 0.2732252766F, 0.2736669191F, 0.2741087914F,
  144205. 0.2745508930F, 0.2749932235F, 0.2754357824F, 0.2758785693F,
  144206. 0.2763215837F, 0.2767648251F, 0.2772082930F, 0.2776519870F,
  144207. 0.2780959066F, 0.2785400513F, 0.2789844207F, 0.2794290143F,
  144208. 0.2798738316F, 0.2803188722F, 0.2807641355F, 0.2812096211F,
  144209. 0.2816553286F, 0.2821012574F, 0.2825474071F, 0.2829937773F,
  144210. 0.2834403673F, 0.2838871768F, 0.2843342053F, 0.2847814523F,
  144211. 0.2852289174F, 0.2856765999F, 0.2861244996F, 0.2865726159F,
  144212. 0.2870209482F, 0.2874694962F, 0.2879182594F, 0.2883672372F,
  144213. 0.2888164293F, 0.2892658350F, 0.2897154540F, 0.2901652858F,
  144214. 0.2906153298F, 0.2910655856F, 0.2915160527F, 0.2919667306F,
  144215. 0.2924176189F, 0.2928687171F, 0.2933200246F, 0.2937715409F,
  144216. 0.2942232657F, 0.2946751984F, 0.2951273386F, 0.2955796856F,
  144217. 0.2960322391F, 0.2964849986F, 0.2969379636F, 0.2973911335F,
  144218. 0.2978445080F, 0.2982980864F, 0.2987518684F, 0.2992058534F,
  144219. 0.2996600409F, 0.3001144305F, 0.3005690217F, 0.3010238139F,
  144220. 0.3014788067F, 0.3019339995F, 0.3023893920F, 0.3028449835F,
  144221. 0.3033007736F, 0.3037567618F, 0.3042129477F, 0.3046693306F,
  144222. 0.3051259102F, 0.3055826859F, 0.3060396572F, 0.3064968236F,
  144223. 0.3069541847F, 0.3074117399F, 0.3078694887F, 0.3083274307F,
  144224. 0.3087855653F, 0.3092438920F, 0.3097024104F, 0.3101611199F,
  144225. 0.3106200200F, 0.3110791103F, 0.3115383902F, 0.3119978592F,
  144226. 0.3124575169F, 0.3129173627F, 0.3133773961F, 0.3138376166F,
  144227. 0.3142980238F, 0.3147586170F, 0.3152193959F, 0.3156803598F,
  144228. 0.3161415084F, 0.3166028410F, 0.3170643573F, 0.3175260566F,
  144229. 0.3179879384F, 0.3184500023F, 0.3189122478F, 0.3193746743F,
  144230. 0.3198372814F, 0.3203000685F, 0.3207630351F, 0.3212261807F,
  144231. 0.3216895048F, 0.3221530069F, 0.3226166865F, 0.3230805430F,
  144232. 0.3235445760F, 0.3240087849F, 0.3244731693F, 0.3249377285F,
  144233. 0.3254024622F, 0.3258673698F, 0.3263324507F, 0.3267977045F,
  144234. 0.3272631306F, 0.3277287286F, 0.3281944978F, 0.3286604379F,
  144235. 0.3291265482F, 0.3295928284F, 0.3300592777F, 0.3305258958F,
  144236. 0.3309926821F, 0.3314596361F, 0.3319267573F, 0.3323940451F,
  144237. 0.3328614990F, 0.3333291186F, 0.3337969033F, 0.3342648525F,
  144238. 0.3347329658F, 0.3352012427F, 0.3356696825F, 0.3361382849F,
  144239. 0.3366070492F, 0.3370759749F, 0.3375450616F, 0.3380143087F,
  144240. 0.3384837156F, 0.3389532819F, 0.3394230071F, 0.3398928905F,
  144241. 0.3403629317F, 0.3408331302F, 0.3413034854F, 0.3417739967F,
  144242. 0.3422446638F, 0.3427154860F, 0.3431864628F, 0.3436575938F,
  144243. 0.3441288782F, 0.3446003158F, 0.3450719058F, 0.3455436478F,
  144244. 0.3460155412F, 0.3464875856F, 0.3469597804F, 0.3474321250F,
  144245. 0.3479046189F, 0.3483772617F, 0.3488500527F, 0.3493229914F,
  144246. 0.3497960774F, 0.3502693100F, 0.3507426887F, 0.3512162131F,
  144247. 0.3516898825F, 0.3521636965F, 0.3526376545F, 0.3531117559F,
  144248. 0.3535860003F, 0.3540603870F, 0.3545349157F, 0.3550095856F,
  144249. 0.3554843964F, 0.3559593474F, 0.3564344381F, 0.3569096680F,
  144250. 0.3573850366F, 0.3578605432F, 0.3583361875F, 0.3588119687F,
  144251. 0.3592878865F, 0.3597639402F, 0.3602401293F, 0.3607164533F,
  144252. 0.3611929117F, 0.3616695038F, 0.3621462292F, 0.3626230873F,
  144253. 0.3631000776F, 0.3635771995F, 0.3640544525F, 0.3645318360F,
  144254. 0.3650093496F, 0.3654869926F, 0.3659647645F, 0.3664426648F,
  144255. 0.3669206930F, 0.3673988484F, 0.3678771306F, 0.3683555390F,
  144256. 0.3688340731F, 0.3693127322F, 0.3697915160F, 0.3702704237F,
  144257. 0.3707494549F, 0.3712286091F, 0.3717078857F, 0.3721872840F,
  144258. 0.3726668037F, 0.3731464441F, 0.3736262047F, 0.3741060850F,
  144259. 0.3745860843F, 0.3750662023F, 0.3755464382F, 0.3760267915F,
  144260. 0.3765072618F, 0.3769878484F, 0.3774685509F, 0.3779493686F,
  144261. 0.3784303010F, 0.3789113475F, 0.3793925076F, 0.3798737809F,
  144262. 0.3803551666F, 0.3808366642F, 0.3813182733F, 0.3817999932F,
  144263. 0.3822818234F, 0.3827637633F, 0.3832458124F, 0.3837279702F,
  144264. 0.3842102360F, 0.3846926093F, 0.3851750897F, 0.3856576764F,
  144265. 0.3861403690F, 0.3866231670F, 0.3871060696F, 0.3875890765F,
  144266. 0.3880721870F, 0.3885554007F, 0.3890387168F, 0.3895221349F,
  144267. 0.3900056544F, 0.3904892748F, 0.3909729955F, 0.3914568160F,
  144268. 0.3919407356F, 0.3924247539F, 0.3929088702F, 0.3933930841F,
  144269. 0.3938773949F, 0.3943618021F, 0.3948463052F, 0.3953309035F,
  144270. 0.3958155966F, 0.3963003838F, 0.3967852646F, 0.3972702385F,
  144271. 0.3977553048F, 0.3982404631F, 0.3987257127F, 0.3992110531F,
  144272. 0.3996964838F, 0.4001820041F, 0.4006676136F, 0.4011533116F,
  144273. 0.4016390976F, 0.4021249710F, 0.4026109313F, 0.4030969779F,
  144274. 0.4035831102F, 0.4040693277F, 0.4045556299F, 0.4050420160F,
  144275. 0.4055284857F, 0.4060150383F, 0.4065016732F, 0.4069883899F,
  144276. 0.4074751879F, 0.4079620665F, 0.4084490252F, 0.4089360635F,
  144277. 0.4094231807F, 0.4099103763F, 0.4103976498F, 0.4108850005F,
  144278. 0.4113724280F, 0.4118599315F, 0.4123475107F, 0.4128351648F,
  144279. 0.4133228934F, 0.4138106959F, 0.4142985716F, 0.4147865201F,
  144280. 0.4152745408F, 0.4157626330F, 0.4162507963F, 0.4167390301F,
  144281. 0.4172273337F, 0.4177157067F, 0.4182041484F, 0.4186926583F,
  144282. 0.4191812359F, 0.4196698805F, 0.4201585915F, 0.4206473685F,
  144283. 0.4211362108F, 0.4216251179F, 0.4221140892F, 0.4226031241F,
  144284. 0.4230922221F, 0.4235813826F, 0.4240706050F, 0.4245598887F,
  144285. 0.4250492332F, 0.4255386379F, 0.4260281022F, 0.4265176256F,
  144286. 0.4270072075F, 0.4274968473F, 0.4279865445F, 0.4284762984F,
  144287. 0.4289661086F, 0.4294559743F, 0.4299458951F, 0.4304358704F,
  144288. 0.4309258996F, 0.4314159822F, 0.4319061175F, 0.4323963050F,
  144289. 0.4328865441F, 0.4333768342F, 0.4338671749F, 0.4343575654F,
  144290. 0.4348480052F, 0.4353384938F, 0.4358290306F, 0.4363196149F,
  144291. 0.4368102463F, 0.4373009241F, 0.4377916478F, 0.4382824168F,
  144292. 0.4387732305F, 0.4392640884F, 0.4397549899F, 0.4402459343F,
  144293. 0.4407369212F, 0.4412279499F, 0.4417190198F, 0.4422101305F,
  144294. 0.4427012813F, 0.4431924717F, 0.4436837010F, 0.4441749686F,
  144295. 0.4446662742F, 0.4451576169F, 0.4456489963F, 0.4461404118F,
  144296. 0.4466318628F, 0.4471233487F, 0.4476148690F, 0.4481064230F,
  144297. 0.4485980103F, 0.4490896302F, 0.4495812821F, 0.4500729654F,
  144298. 0.4505646797F, 0.4510564243F, 0.4515481986F, 0.4520400021F,
  144299. 0.4525318341F, 0.4530236942F, 0.4535155816F, 0.4540074959F,
  144300. 0.4544994365F, 0.4549914028F, 0.4554833941F, 0.4559754100F,
  144301. 0.4564674499F, 0.4569595131F, 0.4574515991F, 0.4579437074F,
  144302. 0.4584358372F, 0.4589279881F, 0.4594201595F, 0.4599123508F,
  144303. 0.4604045615F, 0.4608967908F, 0.4613890383F, 0.4618813034F,
  144304. 0.4623735855F, 0.4628658841F, 0.4633581984F, 0.4638505281F,
  144305. 0.4643428724F, 0.4648352308F, 0.4653276028F, 0.4658199877F,
  144306. 0.4663123849F, 0.4668047940F, 0.4672972143F, 0.4677896451F,
  144307. 0.4682820861F, 0.4687745365F, 0.4692669958F, 0.4697594634F,
  144308. 0.4702519387F, 0.4707444211F, 0.4712369102F, 0.4717294052F,
  144309. 0.4722219056F, 0.4727144109F, 0.4732069204F, 0.4736994336F,
  144310. 0.4741919498F, 0.4746844686F, 0.4751769893F, 0.4756695113F,
  144311. 0.4761620341F, 0.4766545571F, 0.4771470797F, 0.4776396013F,
  144312. 0.4781321213F, 0.4786246392F, 0.4791171544F, 0.4796096663F,
  144313. 0.4801021744F, 0.4805946779F, 0.4810871765F, 0.4815796694F,
  144314. 0.4820721561F, 0.4825646360F, 0.4830571086F, 0.4835495732F,
  144315. 0.4840420293F, 0.4845344763F, 0.4850269136F, 0.4855193407F,
  144316. 0.4860117569F, 0.4865041617F, 0.4869965545F, 0.4874889347F,
  144317. 0.4879813018F, 0.4884736551F, 0.4889659941F, 0.4894583182F,
  144318. 0.4899506268F, 0.4904429193F, 0.4909351952F, 0.4914274538F,
  144319. 0.4919196947F, 0.4924119172F, 0.4929041207F, 0.4933963046F,
  144320. 0.4938884685F, 0.4943806116F, 0.4948727335F, 0.4953648335F,
  144321. 0.4958569110F, 0.4963489656F, 0.4968409965F, 0.4973330032F,
  144322. 0.4978249852F, 0.4983169419F, 0.4988088726F, 0.4993007768F,
  144323. 0.4997926539F, 0.5002845034F, 0.5007763247F, 0.5012681171F,
  144324. 0.5017598801F, 0.5022516132F, 0.5027433157F, 0.5032349871F,
  144325. 0.5037266268F, 0.5042182341F, 0.5047098086F, 0.5052013497F,
  144326. 0.5056928567F, 0.5061843292F, 0.5066757664F, 0.5071671679F,
  144327. 0.5076585330F, 0.5081498613F, 0.5086411520F, 0.5091324047F,
  144328. 0.5096236187F, 0.5101147934F, 0.5106059284F, 0.5110970230F,
  144329. 0.5115880766F, 0.5120790887F, 0.5125700587F, 0.5130609860F,
  144330. 0.5135518700F, 0.5140427102F, 0.5145335059F, 0.5150242566F,
  144331. 0.5155149618F, 0.5160056208F, 0.5164962331F, 0.5169867980F,
  144332. 0.5174773151F, 0.5179677837F, 0.5184582033F, 0.5189485733F,
  144333. 0.5194388931F, 0.5199291621F, 0.5204193798F, 0.5209095455F,
  144334. 0.5213996588F, 0.5218897190F, 0.5223797256F, 0.5228696779F,
  144335. 0.5233595755F, 0.5238494177F, 0.5243392039F, 0.5248289337F,
  144336. 0.5253186063F, 0.5258082213F, 0.5262977781F, 0.5267872760F,
  144337. 0.5272767146F, 0.5277660932F, 0.5282554112F, 0.5287446682F,
  144338. 0.5292338635F, 0.5297229965F, 0.5302120667F, 0.5307010736F,
  144339. 0.5311900164F, 0.5316788947F, 0.5321677079F, 0.5326564554F,
  144340. 0.5331451366F, 0.5336337511F, 0.5341222981F, 0.5346107771F,
  144341. 0.5350991876F, 0.5355875290F, 0.5360758007F, 0.5365640021F,
  144342. 0.5370521327F, 0.5375401920F, 0.5380281792F, 0.5385160939F,
  144343. 0.5390039355F, 0.5394917034F, 0.5399793971F, 0.5404670159F,
  144344. 0.5409545594F, 0.5414420269F, 0.5419294179F, 0.5424167318F,
  144345. 0.5429039680F, 0.5433911261F, 0.5438782053F, 0.5443652051F,
  144346. 0.5448521250F, 0.5453389644F, 0.5458257228F, 0.5463123995F,
  144347. 0.5467989940F, 0.5472855057F, 0.5477719341F, 0.5482582786F,
  144348. 0.5487445387F, 0.5492307137F, 0.5497168031F, 0.5502028063F,
  144349. 0.5506887228F, 0.5511745520F, 0.5516602934F, 0.5521459463F,
  144350. 0.5526315103F, 0.5531169847F, 0.5536023690F, 0.5540876626F,
  144351. 0.5545728649F, 0.5550579755F, 0.5555429937F, 0.5560279189F,
  144352. 0.5565127507F, 0.5569974884F, 0.5574821315F, 0.5579666794F,
  144353. 0.5584511316F, 0.5589354875F, 0.5594197465F, 0.5599039080F,
  144354. 0.5603879716F, 0.5608719367F, 0.5613558026F, 0.5618395689F,
  144355. 0.5623232350F, 0.5628068002F, 0.5632902642F, 0.5637736262F,
  144356. 0.5642568858F, 0.5647400423F, 0.5652230953F, 0.5657060442F,
  144357. 0.5661888883F, 0.5666716272F, 0.5671542603F, 0.5676367870F,
  144358. 0.5681192069F, 0.5686015192F, 0.5690837235F, 0.5695658192F,
  144359. 0.5700478058F, 0.5705296827F, 0.5710114494F, 0.5714931052F,
  144360. 0.5719746497F, 0.5724560822F, 0.5729374023F, 0.5734186094F,
  144361. 0.5738997029F, 0.5743806823F, 0.5748615470F, 0.5753422965F,
  144362. 0.5758229301F, 0.5763034475F, 0.5767838480F, 0.5772641310F,
  144363. 0.5777442960F, 0.5782243426F, 0.5787042700F, 0.5791840778F,
  144364. 0.5796637654F, 0.5801433322F, 0.5806227778F, 0.5811021016F,
  144365. 0.5815813029F, 0.5820603814F, 0.5825393363F, 0.5830181673F,
  144366. 0.5834968737F, 0.5839754549F, 0.5844539105F, 0.5849322399F,
  144367. 0.5854104425F, 0.5858885179F, 0.5863664653F, 0.5868442844F,
  144368. 0.5873219746F, 0.5877995353F, 0.5882769660F, 0.5887542661F,
  144369. 0.5892314351F, 0.5897084724F, 0.5901853776F, 0.5906621500F,
  144370. 0.5911387892F, 0.5916152945F, 0.5920916655F, 0.5925679016F,
  144371. 0.5930440022F, 0.5935199669F, 0.5939957950F, 0.5944714861F,
  144372. 0.5949470396F, 0.5954224550F, 0.5958977317F, 0.5963728692F,
  144373. 0.5968478669F, 0.5973227244F, 0.5977974411F, 0.5982720163F,
  144374. 0.5987464497F, 0.5992207407F, 0.5996948887F, 0.6001688932F,
  144375. 0.6006427537F, 0.6011164696F, 0.6015900405F, 0.6020634657F,
  144376. 0.6025367447F, 0.6030098770F, 0.6034828621F, 0.6039556995F,
  144377. 0.6044283885F, 0.6049009288F, 0.6053733196F, 0.6058455606F,
  144378. 0.6063176512F, 0.6067895909F, 0.6072613790F, 0.6077330152F,
  144379. 0.6082044989F, 0.6086758295F, 0.6091470065F, 0.6096180294F,
  144380. 0.6100888977F, 0.6105596108F, 0.6110301682F, 0.6115005694F,
  144381. 0.6119708139F, 0.6124409011F, 0.6129108305F, 0.6133806017F,
  144382. 0.6138502139F, 0.6143196669F, 0.6147889599F, 0.6152580926F,
  144383. 0.6157270643F, 0.6161958746F, 0.6166645230F, 0.6171330088F,
  144384. 0.6176013317F, 0.6180694910F, 0.6185374863F, 0.6190053171F,
  144385. 0.6194729827F, 0.6199404828F, 0.6204078167F, 0.6208749841F,
  144386. 0.6213419842F, 0.6218088168F, 0.6222754811F, 0.6227419768F,
  144387. 0.6232083032F, 0.6236744600F, 0.6241404465F, 0.6246062622F,
  144388. 0.6250719067F, 0.6255373795F, 0.6260026799F, 0.6264678076F,
  144389. 0.6269327619F, 0.6273975425F, 0.6278621487F, 0.6283265800F,
  144390. 0.6287908361F, 0.6292549163F, 0.6297188201F, 0.6301825471F,
  144391. 0.6306460966F, 0.6311094683F, 0.6315726617F, 0.6320356761F,
  144392. 0.6324985111F, 0.6329611662F, 0.6334236410F, 0.6338859348F,
  144393. 0.6343480472F, 0.6348099777F, 0.6352717257F, 0.6357332909F,
  144394. 0.6361946726F, 0.6366558704F, 0.6371168837F, 0.6375777122F,
  144395. 0.6380383552F, 0.6384988123F, 0.6389590830F, 0.6394191668F,
  144396. 0.6398790631F, 0.6403387716F, 0.6407982916F, 0.6412576228F,
  144397. 0.6417167645F, 0.6421757163F, 0.6426344778F, 0.6430930483F,
  144398. 0.6435514275F, 0.6440096149F, 0.6444676098F, 0.6449254119F,
  144399. 0.6453830207F, 0.6458404356F, 0.6462976562F, 0.6467546820F,
  144400. 0.6472115125F, 0.6476681472F, 0.6481245856F, 0.6485808273F,
  144401. 0.6490368717F, 0.6494927183F, 0.6499483667F, 0.6504038164F,
  144402. 0.6508590670F, 0.6513141178F, 0.6517689684F, 0.6522236185F,
  144403. 0.6526780673F, 0.6531323146F, 0.6535863598F, 0.6540402024F,
  144404. 0.6544938419F, 0.6549472779F, 0.6554005099F, 0.6558535373F,
  144405. 0.6563063598F, 0.6567589769F, 0.6572113880F, 0.6576635927F,
  144406. 0.6581155906F, 0.6585673810F, 0.6590189637F, 0.6594703380F,
  144407. 0.6599215035F, 0.6603724598F, 0.6608232064F, 0.6612737427F,
  144408. 0.6617240684F, 0.6621741829F, 0.6626240859F, 0.6630737767F,
  144409. 0.6635232550F, 0.6639725202F, 0.6644215720F, 0.6648704098F,
  144410. 0.6653190332F, 0.6657674417F, 0.6662156348F, 0.6666636121F,
  144411. 0.6671113731F, 0.6675589174F, 0.6680062445F, 0.6684533538F,
  144412. 0.6689002450F, 0.6693469177F, 0.6697933712F, 0.6702396052F,
  144413. 0.6706856193F, 0.6711314129F, 0.6715769855F, 0.6720223369F,
  144414. 0.6724674664F, 0.6729123736F, 0.6733570581F, 0.6738015194F,
  144415. 0.6742457570F, 0.6746897706F, 0.6751335596F, 0.6755771236F,
  144416. 0.6760204621F, 0.6764635747F, 0.6769064609F, 0.6773491204F,
  144417. 0.6777915525F, 0.6782337570F, 0.6786757332F, 0.6791174809F,
  144418. 0.6795589995F, 0.6800002886F, 0.6804413477F, 0.6808821765F,
  144419. 0.6813227743F, 0.6817631409F, 0.6822032758F, 0.6826431785F,
  144420. 0.6830828485F, 0.6835222855F, 0.6839614890F, 0.6844004585F,
  144421. 0.6848391936F, 0.6852776939F, 0.6857159589F, 0.6861539883F,
  144422. 0.6865917815F, 0.6870293381F, 0.6874666576F, 0.6879037398F,
  144423. 0.6883405840F, 0.6887771899F, 0.6892135571F, 0.6896496850F,
  144424. 0.6900855733F, 0.6905212216F, 0.6909566294F, 0.6913917963F,
  144425. 0.6918267218F, 0.6922614055F, 0.6926958471F, 0.6931300459F,
  144426. 0.6935640018F, 0.6939977141F, 0.6944311825F, 0.6948644066F,
  144427. 0.6952973859F, 0.6957301200F, 0.6961626085F, 0.6965948510F,
  144428. 0.6970268470F, 0.6974585961F, 0.6978900980F, 0.6983213521F,
  144429. 0.6987523580F, 0.6991831154F, 0.6996136238F, 0.7000438828F,
  144430. 0.7004738921F, 0.7009036510F, 0.7013331594F, 0.7017624166F,
  144431. 0.7021914224F, 0.7026201763F, 0.7030486779F, 0.7034769268F,
  144432. 0.7039049226F, 0.7043326648F, 0.7047601531F, 0.7051873870F,
  144433. 0.7056143662F, 0.7060410902F, 0.7064675586F, 0.7068937711F,
  144434. 0.7073197271F, 0.7077454264F, 0.7081708684F, 0.7085960529F,
  144435. 0.7090209793F, 0.7094456474F, 0.7098700566F, 0.7102942066F,
  144436. 0.7107180970F, 0.7111417274F, 0.7115650974F, 0.7119882066F,
  144437. 0.7124110545F, 0.7128336409F, 0.7132559653F, 0.7136780272F,
  144438. 0.7140998264F, 0.7145213624F, 0.7149426348F, 0.7153636433F,
  144439. 0.7157843874F, 0.7162048668F, 0.7166250810F, 0.7170450296F,
  144440. 0.7174647124F, 0.7178841289F, 0.7183032786F, 0.7187221613F,
  144441. 0.7191407765F, 0.7195591239F, 0.7199772030F, 0.7203950135F,
  144442. 0.7208125550F, 0.7212298271F, 0.7216468294F, 0.7220635616F,
  144443. 0.7224800233F, 0.7228962140F, 0.7233121335F, 0.7237277813F,
  144444. 0.7241431571F, 0.7245582604F, 0.7249730910F, 0.7253876484F,
  144445. 0.7258019322F, 0.7262159422F, 0.7266296778F, 0.7270431388F,
  144446. 0.7274563247F, 0.7278692353F, 0.7282818700F, 0.7286942287F,
  144447. 0.7291063108F, 0.7295181160F, 0.7299296440F, 0.7303408944F,
  144448. 0.7307518669F, 0.7311625609F, 0.7315729763F, 0.7319831126F,
  144449. 0.7323929695F, 0.7328025466F, 0.7332118435F, 0.7336208600F,
  144450. 0.7340295955F, 0.7344380499F, 0.7348462226F, 0.7352541134F,
  144451. 0.7356617220F, 0.7360690478F, 0.7364760907F, 0.7368828502F,
  144452. 0.7372893259F, 0.7376955176F, 0.7381014249F, 0.7385070475F,
  144453. 0.7389123849F, 0.7393174368F, 0.7397222029F, 0.7401266829F,
  144454. 0.7405308763F, 0.7409347829F, 0.7413384023F, 0.7417417341F,
  144455. 0.7421447780F, 0.7425475338F, 0.7429500009F, 0.7433521791F,
  144456. 0.7437540681F, 0.7441556674F, 0.7445569769F, 0.7449579960F,
  144457. 0.7453587245F, 0.7457591621F, 0.7461593084F, 0.7465591631F,
  144458. 0.7469587259F, 0.7473579963F, 0.7477569741F, 0.7481556590F,
  144459. 0.7485540506F, 0.7489521486F, 0.7493499526F, 0.7497474623F,
  144460. 0.7501446775F, 0.7505415977F, 0.7509382227F, 0.7513345521F,
  144461. 0.7517305856F, 0.7521263229F, 0.7525217636F, 0.7529169074F,
  144462. 0.7533117541F, 0.7537063032F, 0.7541005545F, 0.7544945076F,
  144463. 0.7548881623F, 0.7552815182F, 0.7556745749F, 0.7560673323F,
  144464. 0.7564597899F, 0.7568519474F, 0.7572438046F, 0.7576353611F,
  144465. 0.7580266166F, 0.7584175708F, 0.7588082235F, 0.7591985741F,
  144466. 0.7595886226F, 0.7599783685F, 0.7603678116F, 0.7607569515F,
  144467. 0.7611457879F, 0.7615343206F, 0.7619225493F, 0.7623104735F,
  144468. 0.7626980931F, 0.7630854078F, 0.7634724171F, 0.7638591209F,
  144469. 0.7642455188F, 0.7646316106F, 0.7650173959F, 0.7654028744F,
  144470. 0.7657880459F, 0.7661729100F, 0.7665574664F, 0.7669417150F,
  144471. 0.7673256553F, 0.7677092871F, 0.7680926100F, 0.7684756239F,
  144472. 0.7688583284F, 0.7692407232F, 0.7696228080F, 0.7700045826F,
  144473. 0.7703860467F, 0.7707671999F, 0.7711480420F, 0.7715285728F,
  144474. 0.7719087918F, 0.7722886989F, 0.7726682938F, 0.7730475762F,
  144475. 0.7734265458F, 0.7738052023F, 0.7741835454F, 0.7745615750F,
  144476. 0.7749392906F, 0.7753166921F, 0.7756937791F, 0.7760705514F,
  144477. 0.7764470087F, 0.7768231508F, 0.7771989773F, 0.7775744880F,
  144478. 0.7779496827F, 0.7783245610F, 0.7786991227F, 0.7790733676F,
  144479. 0.7794472953F, 0.7798209056F, 0.7801941982F, 0.7805671729F,
  144480. 0.7809398294F, 0.7813121675F, 0.7816841869F, 0.7820558873F,
  144481. 0.7824272684F, 0.7827983301F, 0.7831690720F, 0.7835394940F,
  144482. 0.7839095957F, 0.7842793768F, 0.7846488373F, 0.7850179767F,
  144483. 0.7853867948F, 0.7857552914F, 0.7861234663F, 0.7864913191F,
  144484. 0.7868588497F, 0.7872260578F, 0.7875929431F, 0.7879595055F,
  144485. 0.7883257445F, 0.7886916601F, 0.7890572520F, 0.7894225198F,
  144486. 0.7897874635F, 0.7901520827F, 0.7905163772F, 0.7908803468F,
  144487. 0.7912439912F, 0.7916073102F, 0.7919703035F, 0.7923329710F,
  144488. 0.7926953124F, 0.7930573274F, 0.7934190158F, 0.7937803774F,
  144489. 0.7941414120F, 0.7945021193F, 0.7948624991F, 0.7952225511F,
  144490. 0.7955822752F, 0.7959416711F, 0.7963007387F, 0.7966594775F,
  144491. 0.7970178875F, 0.7973759685F, 0.7977337201F, 0.7980911422F,
  144492. 0.7984482346F, 0.7988049970F, 0.7991614292F, 0.7995175310F,
  144493. 0.7998733022F, 0.8002287426F, 0.8005838519F, 0.8009386299F,
  144494. 0.8012930765F, 0.8016471914F, 0.8020009744F, 0.8023544253F,
  144495. 0.8027075438F, 0.8030603298F, 0.8034127831F, 0.8037649035F,
  144496. 0.8041166906F, 0.8044681445F, 0.8048192647F, 0.8051700512F,
  144497. 0.8055205038F, 0.8058706222F, 0.8062204062F, 0.8065698556F,
  144498. 0.8069189702F, 0.8072677499F, 0.8076161944F, 0.8079643036F,
  144499. 0.8083120772F, 0.8086595151F, 0.8090066170F, 0.8093533827F,
  144500. 0.8096998122F, 0.8100459051F, 0.8103916613F, 0.8107370806F,
  144501. 0.8110821628F, 0.8114269077F, 0.8117713151F, 0.8121153849F,
  144502. 0.8124591169F, 0.8128025108F, 0.8131455666F, 0.8134882839F,
  144503. 0.8138306627F, 0.8141727027F, 0.8145144038F, 0.8148557658F,
  144504. 0.8151967886F, 0.8155374718F, 0.8158778154F, 0.8162178192F,
  144505. 0.8165574830F, 0.8168968067F, 0.8172357900F, 0.8175744328F,
  144506. 0.8179127349F, 0.8182506962F, 0.8185883164F, 0.8189255955F,
  144507. 0.8192625332F, 0.8195991295F, 0.8199353840F, 0.8202712967F,
  144508. 0.8206068673F, 0.8209420958F, 0.8212769820F, 0.8216115256F,
  144509. 0.8219457266F, 0.8222795848F, 0.8226131000F, 0.8229462721F,
  144510. 0.8232791009F, 0.8236115863F, 0.8239437280F, 0.8242755260F,
  144511. 0.8246069801F, 0.8249380901F, 0.8252688559F, 0.8255992774F,
  144512. 0.8259293544F, 0.8262590867F, 0.8265884741F, 0.8269175167F,
  144513. 0.8272462141F, 0.8275745663F, 0.8279025732F, 0.8282302344F,
  144514. 0.8285575501F, 0.8288845199F, 0.8292111437F, 0.8295374215F,
  144515. 0.8298633530F, 0.8301889382F, 0.8305141768F, 0.8308390688F,
  144516. 0.8311636141F, 0.8314878124F, 0.8318116637F, 0.8321351678F,
  144517. 0.8324583246F, 0.8327811340F, 0.8331035957F, 0.8334257098F,
  144518. 0.8337474761F, 0.8340688944F, 0.8343899647F, 0.8347106867F,
  144519. 0.8350310605F, 0.8353510857F, 0.8356707624F, 0.8359900904F,
  144520. 0.8363090696F, 0.8366276999F, 0.8369459811F, 0.8372639131F,
  144521. 0.8375814958F, 0.8378987292F, 0.8382156130F, 0.8385321472F,
  144522. 0.8388483316F, 0.8391641662F, 0.8394796508F, 0.8397947853F,
  144523. 0.8401095697F, 0.8404240037F, 0.8407380873F, 0.8410518204F,
  144524. 0.8413652029F, 0.8416782347F, 0.8419909156F, 0.8423032456F,
  144525. 0.8426152245F, 0.8429268523F, 0.8432381289F, 0.8435490541F,
  144526. 0.8438596279F, 0.8441698502F, 0.8444797208F, 0.8447892396F,
  144527. 0.8450984067F, 0.8454072218F, 0.8457156849F, 0.8460237959F,
  144528. 0.8463315547F, 0.8466389612F, 0.8469460154F, 0.8472527170F,
  144529. 0.8475590661F, 0.8478650625F, 0.8481707063F, 0.8484759971F,
  144530. 0.8487809351F, 0.8490855201F, 0.8493897521F, 0.8496936308F,
  144531. 0.8499971564F, 0.8503003286F, 0.8506031474F, 0.8509056128F,
  144532. 0.8512077246F, 0.8515094828F, 0.8518108872F, 0.8521119379F,
  144533. 0.8524126348F, 0.8527129777F, 0.8530129666F, 0.8533126015F,
  144534. 0.8536118822F, 0.8539108087F, 0.8542093809F, 0.8545075988F,
  144535. 0.8548054623F, 0.8551029712F, 0.8554001257F, 0.8556969255F,
  144536. 0.8559933707F, 0.8562894611F, 0.8565851968F, 0.8568805775F,
  144537. 0.8571756034F, 0.8574702743F, 0.8577645902F, 0.8580585509F,
  144538. 0.8583521566F, 0.8586454070F, 0.8589383021F, 0.8592308420F,
  144539. 0.8595230265F, 0.8598148556F, 0.8601063292F, 0.8603974473F,
  144540. 0.8606882098F, 0.8609786167F, 0.8612686680F, 0.8615583636F,
  144541. 0.8618477034F, 0.8621366874F, 0.8624253156F, 0.8627135878F,
  144542. 0.8630015042F, 0.8632890646F, 0.8635762690F, 0.8638631173F,
  144543. 0.8641496096F, 0.8644357457F, 0.8647215257F, 0.8650069495F,
  144544. 0.8652920171F, 0.8655767283F, 0.8658610833F, 0.8661450820F,
  144545. 0.8664287243F, 0.8667120102F, 0.8669949397F, 0.8672775127F,
  144546. 0.8675597293F, 0.8678415894F, 0.8681230929F, 0.8684042398F,
  144547. 0.8686850302F, 0.8689654640F, 0.8692455412F, 0.8695252617F,
  144548. 0.8698046255F, 0.8700836327F, 0.8703622831F, 0.8706405768F,
  144549. 0.8709185138F, 0.8711960940F, 0.8714733174F, 0.8717501840F,
  144550. 0.8720266939F, 0.8723028469F, 0.8725786430F, 0.8728540824F,
  144551. 0.8731291648F, 0.8734038905F, 0.8736782592F, 0.8739522711F,
  144552. 0.8742259261F, 0.8744992242F, 0.8747721653F, 0.8750447496F,
  144553. 0.8753169770F, 0.8755888475F, 0.8758603611F, 0.8761315177F,
  144554. 0.8764023175F, 0.8766727603F, 0.8769428462F, 0.8772125752F,
  144555. 0.8774819474F, 0.8777509626F, 0.8780196209F, 0.8782879224F,
  144556. 0.8785558669F, 0.8788234546F, 0.8790906854F, 0.8793575594F,
  144557. 0.8796240765F, 0.8798902368F, 0.8801560403F, 0.8804214870F,
  144558. 0.8806865768F, 0.8809513099F, 0.8812156863F, 0.8814797059F,
  144559. 0.8817433687F, 0.8820066749F, 0.8822696243F, 0.8825322171F,
  144560. 0.8827944532F, 0.8830563327F, 0.8833178556F, 0.8835790219F,
  144561. 0.8838398316F, 0.8841002848F, 0.8843603815F, 0.8846201217F,
  144562. 0.8848795054F, 0.8851385327F, 0.8853972036F, 0.8856555182F,
  144563. 0.8859134764F, 0.8861710783F, 0.8864283239F, 0.8866852133F,
  144564. 0.8869417464F, 0.8871979234F, 0.8874537443F, 0.8877092090F,
  144565. 0.8879643177F, 0.8882190704F, 0.8884734671F, 0.8887275078F,
  144566. 0.8889811927F, 0.8892345216F, 0.8894874948F, 0.8897401122F,
  144567. 0.8899923738F, 0.8902442798F, 0.8904958301F, 0.8907470248F,
  144568. 0.8909978640F, 0.8912483477F, 0.8914984759F, 0.8917482487F,
  144569. 0.8919976662F, 0.8922467284F, 0.8924954353F, 0.8927437871F,
  144570. 0.8929917837F, 0.8932394252F, 0.8934867118F, 0.8937336433F,
  144571. 0.8939802199F, 0.8942264417F, 0.8944723087F, 0.8947178210F,
  144572. 0.8949629785F, 0.8952077815F, 0.8954522299F, 0.8956963239F,
  144573. 0.8959400634F, 0.8961834486F, 0.8964264795F, 0.8966691561F,
  144574. 0.8969114786F, 0.8971534470F, 0.8973950614F, 0.8976363219F,
  144575. 0.8978772284F, 0.8981177812F, 0.8983579802F, 0.8985978256F,
  144576. 0.8988373174F, 0.8990764556F, 0.8993152405F, 0.8995536720F,
  144577. 0.8997917502F, 0.9000294751F, 0.9002668470F, 0.9005038658F,
  144578. 0.9007405317F, 0.9009768446F, 0.9012128048F, 0.9014484123F,
  144579. 0.9016836671F, 0.9019185693F, 0.9021531191F, 0.9023873165F,
  144580. 0.9026211616F, 0.9028546546F, 0.9030877954F, 0.9033205841F,
  144581. 0.9035530210F, 0.9037851059F, 0.9040168392F, 0.9042482207F,
  144582. 0.9044792507F, 0.9047099293F, 0.9049402564F, 0.9051702323F,
  144583. 0.9053998569F, 0.9056291305F, 0.9058580531F, 0.9060866248F,
  144584. 0.9063148457F, 0.9065427159F, 0.9067702355F, 0.9069974046F,
  144585. 0.9072242233F, 0.9074506917F, 0.9076768100F, 0.9079025782F,
  144586. 0.9081279964F, 0.9083530647F, 0.9085777833F, 0.9088021523F,
  144587. 0.9090261717F, 0.9092498417F, 0.9094731623F, 0.9096961338F,
  144588. 0.9099187561F, 0.9101410295F, 0.9103629540F, 0.9105845297F,
  144589. 0.9108057568F, 0.9110266354F, 0.9112471656F, 0.9114673475F,
  144590. 0.9116871812F, 0.9119066668F, 0.9121258046F, 0.9123445945F,
  144591. 0.9125630367F, 0.9127811314F, 0.9129988786F, 0.9132162785F,
  144592. 0.9134333312F, 0.9136500368F, 0.9138663954F, 0.9140824073F,
  144593. 0.9142980724F, 0.9145133910F, 0.9147283632F, 0.9149429890F,
  144594. 0.9151572687F, 0.9153712023F, 0.9155847900F, 0.9157980319F,
  144595. 0.9160109282F, 0.9162234790F, 0.9164356844F, 0.9166475445F,
  144596. 0.9168590595F, 0.9170702296F, 0.9172810548F, 0.9174915354F,
  144597. 0.9177016714F, 0.9179114629F, 0.9181209102F, 0.9183300134F,
  144598. 0.9185387726F, 0.9187471879F, 0.9189552595F, 0.9191629876F,
  144599. 0.9193703723F, 0.9195774136F, 0.9197841119F, 0.9199904672F,
  144600. 0.9201964797F, 0.9204021495F, 0.9206074767F, 0.9208124616F,
  144601. 0.9210171043F, 0.9212214049F, 0.9214253636F, 0.9216289805F,
  144602. 0.9218322558F, 0.9220351896F, 0.9222377821F, 0.9224400335F,
  144603. 0.9226419439F, 0.9228435134F, 0.9230447423F, 0.9232456307F,
  144604. 0.9234461787F, 0.9236463865F, 0.9238462543F, 0.9240457822F,
  144605. 0.9242449704F, 0.9244438190F, 0.9246423282F, 0.9248404983F,
  144606. 0.9250383293F, 0.9252358214F, 0.9254329747F, 0.9256297896F,
  144607. 0.9258262660F, 0.9260224042F, 0.9262182044F, 0.9264136667F,
  144608. 0.9266087913F, 0.9268035783F, 0.9269980280F, 0.9271921405F,
  144609. 0.9273859160F, 0.9275793546F, 0.9277724566F, 0.9279652221F,
  144610. 0.9281576513F, 0.9283497443F, 0.9285415014F, 0.9287329227F,
  144611. 0.9289240084F, 0.9291147586F, 0.9293051737F, 0.9294952536F,
  144612. 0.9296849987F, 0.9298744091F, 0.9300634850F, 0.9302522266F,
  144613. 0.9304406340F, 0.9306287074F, 0.9308164471F, 0.9310038532F,
  144614. 0.9311909259F, 0.9313776654F, 0.9315640719F, 0.9317501455F,
  144615. 0.9319358865F, 0.9321212951F, 0.9323063713F, 0.9324911155F,
  144616. 0.9326755279F, 0.9328596085F, 0.9330433577F, 0.9332267756F,
  144617. 0.9334098623F, 0.9335926182F, 0.9337750434F, 0.9339571380F,
  144618. 0.9341389023F, 0.9343203366F, 0.9345014409F, 0.9346822155F,
  144619. 0.9348626606F, 0.9350427763F, 0.9352225630F, 0.9354020207F,
  144620. 0.9355811498F, 0.9357599503F, 0.9359384226F, 0.9361165667F,
  144621. 0.9362943830F, 0.9364718716F, 0.9366490327F, 0.9368258666F,
  144622. 0.9370023733F, 0.9371785533F, 0.9373544066F, 0.9375299335F,
  144623. 0.9377051341F, 0.9378800087F, 0.9380545576F, 0.9382287809F,
  144624. 0.9384026787F, 0.9385762515F, 0.9387494993F, 0.9389224223F,
  144625. 0.9390950209F, 0.9392672951F, 0.9394392453F, 0.9396108716F,
  144626. 0.9397821743F, 0.9399531536F, 0.9401238096F, 0.9402941427F,
  144627. 0.9404641530F, 0.9406338407F, 0.9408032061F, 0.9409722495F,
  144628. 0.9411409709F, 0.9413093707F, 0.9414774491F, 0.9416452062F,
  144629. 0.9418126424F, 0.9419797579F, 0.9421465528F, 0.9423130274F,
  144630. 0.9424791819F, 0.9426450166F, 0.9428105317F, 0.9429757274F,
  144631. 0.9431406039F, 0.9433051616F, 0.9434694005F, 0.9436333209F,
  144632. 0.9437969232F, 0.9439602074F, 0.9441231739F, 0.9442858229F,
  144633. 0.9444481545F, 0.9446101691F, 0.9447718669F, 0.9449332481F,
  144634. 0.9450943129F, 0.9452550617F, 0.9454154945F, 0.9455756118F,
  144635. 0.9457354136F, 0.9458949003F, 0.9460540721F, 0.9462129292F,
  144636. 0.9463714719F, 0.9465297003F, 0.9466876149F, 0.9468452157F,
  144637. 0.9470025031F, 0.9471594772F, 0.9473161384F, 0.9474724869F,
  144638. 0.9476285229F, 0.9477842466F, 0.9479396584F, 0.9480947585F,
  144639. 0.9482495470F, 0.9484040243F, 0.9485581906F, 0.9487120462F,
  144640. 0.9488655913F, 0.9490188262F, 0.9491717511F, 0.9493243662F,
  144641. 0.9494766718F, 0.9496286683F, 0.9497803557F, 0.9499317345F,
  144642. 0.9500828047F, 0.9502335668F, 0.9503840209F, 0.9505341673F,
  144643. 0.9506840062F, 0.9508335380F, 0.9509827629F, 0.9511316810F,
  144644. 0.9512802928F, 0.9514285984F, 0.9515765982F, 0.9517242923F,
  144645. 0.9518716810F, 0.9520187646F, 0.9521655434F, 0.9523120176F,
  144646. 0.9524581875F, 0.9526040534F, 0.9527496154F, 0.9528948739F,
  144647. 0.9530398292F, 0.9531844814F, 0.9533288310F, 0.9534728780F,
  144648. 0.9536166229F, 0.9537600659F, 0.9539032071F, 0.9540460470F,
  144649. 0.9541885858F, 0.9543308237F, 0.9544727611F, 0.9546143981F,
  144650. 0.9547557351F, 0.9548967723F, 0.9550375100F, 0.9551779485F,
  144651. 0.9553180881F, 0.9554579290F, 0.9555974714F, 0.9557367158F,
  144652. 0.9558756623F, 0.9560143112F, 0.9561526628F, 0.9562907174F,
  144653. 0.9564284752F, 0.9565659366F, 0.9567031017F, 0.9568399710F,
  144654. 0.9569765446F, 0.9571128229F, 0.9572488061F, 0.9573844944F,
  144655. 0.9575198883F, 0.9576549879F, 0.9577897936F, 0.9579243056F,
  144656. 0.9580585242F, 0.9581924497F, 0.9583260824F, 0.9584594226F,
  144657. 0.9585924705F, 0.9587252264F, 0.9588576906F, 0.9589898634F,
  144658. 0.9591217452F, 0.9592533360F, 0.9593846364F, 0.9595156465F,
  144659. 0.9596463666F, 0.9597767971F, 0.9599069382F, 0.9600367901F,
  144660. 0.9601663533F, 0.9602956279F, 0.9604246143F, 0.9605533128F,
  144661. 0.9606817236F, 0.9608098471F, 0.9609376835F, 0.9610652332F,
  144662. 0.9611924963F, 0.9613194733F, 0.9614461644F, 0.9615725699F,
  144663. 0.9616986901F, 0.9618245253F, 0.9619500757F, 0.9620753418F,
  144664. 0.9622003238F, 0.9623250219F, 0.9624494365F, 0.9625735679F,
  144665. 0.9626974163F, 0.9628209821F, 0.9629442656F, 0.9630672671F,
  144666. 0.9631899868F, 0.9633124251F, 0.9634345822F, 0.9635564585F,
  144667. 0.9636780543F, 0.9637993699F, 0.9639204056F, 0.9640411616F,
  144668. 0.9641616383F, 0.9642818359F, 0.9644017549F, 0.9645213955F,
  144669. 0.9646407579F, 0.9647598426F, 0.9648786497F, 0.9649971797F,
  144670. 0.9651154328F, 0.9652334092F, 0.9653511095F, 0.9654685337F,
  144671. 0.9655856823F, 0.9657025556F, 0.9658191538F, 0.9659354773F,
  144672. 0.9660515263F, 0.9661673013F, 0.9662828024F, 0.9663980300F,
  144673. 0.9665129845F, 0.9666276660F, 0.9667420750F, 0.9668562118F,
  144674. 0.9669700766F, 0.9670836698F, 0.9671969917F, 0.9673100425F,
  144675. 0.9674228227F, 0.9675353325F, 0.9676475722F, 0.9677595422F,
  144676. 0.9678712428F, 0.9679826742F, 0.9680938368F, 0.9682047309F,
  144677. 0.9683153569F, 0.9684257150F, 0.9685358056F, 0.9686456289F,
  144678. 0.9687551853F, 0.9688644752F, 0.9689734987F, 0.9690822564F,
  144679. 0.9691907483F, 0.9692989750F, 0.9694069367F, 0.9695146337F,
  144680. 0.9696220663F, 0.9697292349F, 0.9698361398F, 0.9699427813F,
  144681. 0.9700491597F, 0.9701552754F, 0.9702611286F, 0.9703667197F,
  144682. 0.9704720490F, 0.9705771169F, 0.9706819236F, 0.9707864695F,
  144683. 0.9708907549F, 0.9709947802F, 0.9710985456F, 0.9712020514F,
  144684. 0.9713052981F, 0.9714082859F, 0.9715110151F, 0.9716134862F,
  144685. 0.9717156993F, 0.9718176549F, 0.9719193532F, 0.9720207946F,
  144686. 0.9721219794F, 0.9722229080F, 0.9723235806F, 0.9724239976F,
  144687. 0.9725241593F, 0.9726240661F, 0.9727237183F, 0.9728231161F,
  144688. 0.9729222601F, 0.9730211503F, 0.9731197873F, 0.9732181713F,
  144689. 0.9733163027F, 0.9734141817F, 0.9735118088F, 0.9736091842F,
  144690. 0.9737063083F, 0.9738031814F, 0.9738998039F, 0.9739961760F,
  144691. 0.9740922981F, 0.9741881706F, 0.9742837938F, 0.9743791680F,
  144692. 0.9744742935F, 0.9745691707F, 0.9746637999F, 0.9747581814F,
  144693. 0.9748523157F, 0.9749462029F, 0.9750398435F, 0.9751332378F,
  144694. 0.9752263861F, 0.9753192887F, 0.9754119461F, 0.9755043585F,
  144695. 0.9755965262F, 0.9756884496F, 0.9757801291F, 0.9758715650F,
  144696. 0.9759627575F, 0.9760537071F, 0.9761444141F, 0.9762348789F,
  144697. 0.9763251016F, 0.9764150828F, 0.9765048228F, 0.9765943218F,
  144698. 0.9766835802F, 0.9767725984F, 0.9768613767F, 0.9769499154F,
  144699. 0.9770382149F, 0.9771262755F, 0.9772140976F, 0.9773016815F,
  144700. 0.9773890275F, 0.9774761360F, 0.9775630073F, 0.9776496418F,
  144701. 0.9777360398F, 0.9778222016F, 0.9779081277F, 0.9779938182F,
  144702. 0.9780792736F, 0.9781644943F, 0.9782494805F, 0.9783342326F,
  144703. 0.9784187509F, 0.9785030359F, 0.9785870877F, 0.9786709069F,
  144704. 0.9787544936F, 0.9788378484F, 0.9789209714F, 0.9790038631F,
  144705. 0.9790865238F, 0.9791689538F, 0.9792511535F, 0.9793331232F,
  144706. 0.9794148633F, 0.9794963742F, 0.9795776561F, 0.9796587094F,
  144707. 0.9797395345F, 0.9798201316F, 0.9799005013F, 0.9799806437F,
  144708. 0.9800605593F, 0.9801402483F, 0.9802197112F, 0.9802989483F,
  144709. 0.9803779600F, 0.9804567465F, 0.9805353082F, 0.9806136455F,
  144710. 0.9806917587F, 0.9807696482F, 0.9808473143F, 0.9809247574F,
  144711. 0.9810019778F, 0.9810789759F, 0.9811557519F, 0.9812323064F,
  144712. 0.9813086395F, 0.9813847517F, 0.9814606433F, 0.9815363147F,
  144713. 0.9816117662F, 0.9816869981F, 0.9817620108F, 0.9818368047F,
  144714. 0.9819113801F, 0.9819857374F, 0.9820598769F, 0.9821337989F,
  144715. 0.9822075038F, 0.9822809920F, 0.9823542638F, 0.9824273195F,
  144716. 0.9825001596F, 0.9825727843F, 0.9826451940F, 0.9827173891F,
  144717. 0.9827893700F, 0.9828611368F, 0.9829326901F, 0.9830040302F,
  144718. 0.9830751574F, 0.9831460720F, 0.9832167745F, 0.9832872652F,
  144719. 0.9833575444F, 0.9834276124F, 0.9834974697F, 0.9835671166F,
  144720. 0.9836365535F, 0.9837057806F, 0.9837747983F, 0.9838436071F,
  144721. 0.9839122072F, 0.9839805990F, 0.9840487829F, 0.9841167591F,
  144722. 0.9841845282F, 0.9842520903F, 0.9843194459F, 0.9843865953F,
  144723. 0.9844535389F, 0.9845202771F, 0.9845868101F, 0.9846531383F,
  144724. 0.9847192622F, 0.9847851820F, 0.9848508980F, 0.9849164108F,
  144725. 0.9849817205F, 0.9850468276F, 0.9851117324F, 0.9851764352F,
  144726. 0.9852409365F, 0.9853052366F, 0.9853693358F, 0.9854332344F,
  144727. 0.9854969330F, 0.9855604317F, 0.9856237309F, 0.9856868310F,
  144728. 0.9857497325F, 0.9858124355F, 0.9858749404F, 0.9859372477F,
  144729. 0.9859993577F, 0.9860612707F, 0.9861229871F, 0.9861845072F,
  144730. 0.9862458315F, 0.9863069601F, 0.9863678936F, 0.9864286322F,
  144731. 0.9864891764F, 0.9865495264F, 0.9866096826F, 0.9866696454F,
  144732. 0.9867294152F, 0.9867889922F, 0.9868483769F, 0.9869075695F,
  144733. 0.9869665706F, 0.9870253803F, 0.9870839991F, 0.9871424273F,
  144734. 0.9872006653F, 0.9872587135F, 0.9873165721F, 0.9873742415F,
  144735. 0.9874317222F, 0.9874890144F, 0.9875461185F, 0.9876030348F,
  144736. 0.9876597638F, 0.9877163057F, 0.9877726610F, 0.9878288300F,
  144737. 0.9878848130F, 0.9879406104F, 0.9879962225F, 0.9880516497F,
  144738. 0.9881068924F, 0.9881619509F, 0.9882168256F, 0.9882715168F,
  144739. 0.9883260249F, 0.9883803502F, 0.9884344931F, 0.9884884539F,
  144740. 0.9885422331F, 0.9885958309F, 0.9886492477F, 0.9887024838F,
  144741. 0.9887555397F, 0.9888084157F, 0.9888611120F, 0.9889136292F,
  144742. 0.9889659675F, 0.9890181273F, 0.9890701089F, 0.9891219128F,
  144743. 0.9891735392F, 0.9892249885F, 0.9892762610F, 0.9893273572F,
  144744. 0.9893782774F, 0.9894290219F, 0.9894795911F, 0.9895299853F,
  144745. 0.9895802049F, 0.9896302502F, 0.9896801217F, 0.9897298196F,
  144746. 0.9897793443F, 0.9898286961F, 0.9898778755F, 0.9899268828F,
  144747. 0.9899757183F, 0.9900243823F, 0.9900728753F, 0.9901211976F,
  144748. 0.9901693495F, 0.9902173314F, 0.9902651436F, 0.9903127865F,
  144749. 0.9903602605F, 0.9904075659F, 0.9904547031F, 0.9905016723F,
  144750. 0.9905484740F, 0.9905951086F, 0.9906415763F, 0.9906878775F,
  144751. 0.9907340126F, 0.9907799819F, 0.9908257858F, 0.9908714247F,
  144752. 0.9909168988F, 0.9909622086F, 0.9910073543F, 0.9910523364F,
  144753. 0.9910971552F, 0.9911418110F, 0.9911863042F, 0.9912306351F,
  144754. 0.9912748042F, 0.9913188117F, 0.9913626580F, 0.9914063435F,
  144755. 0.9914498684F, 0.9914932333F, 0.9915364383F, 0.9915794839F,
  144756. 0.9916223703F, 0.9916650981F, 0.9917076674F, 0.9917500787F,
  144757. 0.9917923323F, 0.9918344286F, 0.9918763679F, 0.9919181505F,
  144758. 0.9919597769F, 0.9920012473F, 0.9920425621F, 0.9920837217F,
  144759. 0.9921247263F, 0.9921655765F, 0.9922062724F, 0.9922468145F,
  144760. 0.9922872030F, 0.9923274385F, 0.9923675211F, 0.9924074513F,
  144761. 0.9924472294F, 0.9924868557F, 0.9925263306F, 0.9925656544F,
  144762. 0.9926048275F, 0.9926438503F, 0.9926827230F, 0.9927214461F,
  144763. 0.9927600199F, 0.9927984446F, 0.9928367208F, 0.9928748486F,
  144764. 0.9929128285F, 0.9929506608F, 0.9929883459F, 0.9930258841F,
  144765. 0.9930632757F, 0.9931005211F, 0.9931376207F, 0.9931745747F,
  144766. 0.9932113836F, 0.9932480476F, 0.9932845671F, 0.9933209425F,
  144767. 0.9933571742F, 0.9933932623F, 0.9934292074F, 0.9934650097F,
  144768. 0.9935006696F, 0.9935361874F, 0.9935715635F, 0.9936067982F,
  144769. 0.9936418919F, 0.9936768448F, 0.9937116574F, 0.9937463300F,
  144770. 0.9937808629F, 0.9938152565F, 0.9938495111F, 0.9938836271F,
  144771. 0.9939176047F, 0.9939514444F, 0.9939851465F, 0.9940187112F,
  144772. 0.9940521391F, 0.9940854303F, 0.9941185853F, 0.9941516044F,
  144773. 0.9941844879F, 0.9942172361F, 0.9942498495F, 0.9942823283F,
  144774. 0.9943146729F, 0.9943468836F, 0.9943789608F, 0.9944109047F,
  144775. 0.9944427158F, 0.9944743944F, 0.9945059408F, 0.9945373553F,
  144776. 0.9945686384F, 0.9945997902F, 0.9946308112F, 0.9946617017F,
  144777. 0.9946924621F, 0.9947230926F, 0.9947535937F, 0.9947839656F,
  144778. 0.9948142086F, 0.9948443232F, 0.9948743097F, 0.9949041683F,
  144779. 0.9949338995F, 0.9949635035F, 0.9949929807F, 0.9950223315F,
  144780. 0.9950515561F, 0.9950806549F, 0.9951096282F, 0.9951384764F,
  144781. 0.9951671998F, 0.9951957987F, 0.9952242735F, 0.9952526245F,
  144782. 0.9952808520F, 0.9953089564F, 0.9953369380F, 0.9953647971F,
  144783. 0.9953925340F, 0.9954201491F, 0.9954476428F, 0.9954750153F,
  144784. 0.9955022670F, 0.9955293981F, 0.9955564092F, 0.9955833003F,
  144785. 0.9956100720F, 0.9956367245F, 0.9956632582F, 0.9956896733F,
  144786. 0.9957159703F, 0.9957421494F, 0.9957682110F, 0.9957941553F,
  144787. 0.9958199828F, 0.9958456937F, 0.9958712884F, 0.9958967672F,
  144788. 0.9959221305F, 0.9959473784F, 0.9959725115F, 0.9959975300F,
  144789. 0.9960224342F, 0.9960472244F, 0.9960719011F, 0.9960964644F,
  144790. 0.9961209148F, 0.9961452525F, 0.9961694779F, 0.9961935913F,
  144791. 0.9962175930F, 0.9962414834F, 0.9962652627F, 0.9962889313F,
  144792. 0.9963124895F, 0.9963359377F, 0.9963592761F, 0.9963825051F,
  144793. 0.9964056250F, 0.9964286361F, 0.9964515387F, 0.9964743332F,
  144794. 0.9964970198F, 0.9965195990F, 0.9965420709F, 0.9965644360F,
  144795. 0.9965866946F, 0.9966088469F, 0.9966308932F, 0.9966528340F,
  144796. 0.9966746695F, 0.9966964001F, 0.9967180260F, 0.9967395475F,
  144797. 0.9967609651F, 0.9967822789F, 0.9968034894F, 0.9968245968F,
  144798. 0.9968456014F, 0.9968665036F, 0.9968873037F, 0.9969080019F,
  144799. 0.9969285987F, 0.9969490942F, 0.9969694889F, 0.9969897830F,
  144800. 0.9970099769F, 0.9970300708F, 0.9970500651F, 0.9970699601F,
  144801. 0.9970897561F, 0.9971094533F, 0.9971290522F, 0.9971485531F,
  144802. 0.9971679561F, 0.9971872617F, 0.9972064702F, 0.9972255818F,
  144803. 0.9972445968F, 0.9972635157F, 0.9972823386F, 0.9973010659F,
  144804. 0.9973196980F, 0.9973382350F, 0.9973566773F, 0.9973750253F,
  144805. 0.9973932791F, 0.9974114392F, 0.9974295059F, 0.9974474793F,
  144806. 0.9974653599F, 0.9974831480F, 0.9975008438F, 0.9975184476F,
  144807. 0.9975359598F, 0.9975533806F, 0.9975707104F, 0.9975879495F,
  144808. 0.9976050981F, 0.9976221566F, 0.9976391252F, 0.9976560043F,
  144809. 0.9976727941F, 0.9976894950F, 0.9977061073F, 0.9977226312F,
  144810. 0.9977390671F, 0.9977554152F, 0.9977716759F, 0.9977878495F,
  144811. 0.9978039361F, 0.9978199363F, 0.9978358501F, 0.9978516780F,
  144812. 0.9978674202F, 0.9978830771F, 0.9978986488F, 0.9979141358F,
  144813. 0.9979295383F, 0.9979448566F, 0.9979600909F, 0.9979752417F,
  144814. 0.9979903091F, 0.9980052936F, 0.9980201952F, 0.9980350145F,
  144815. 0.9980497515F, 0.9980644067F, 0.9980789804F, 0.9980934727F,
  144816. 0.9981078841F, 0.9981222147F, 0.9981364649F, 0.9981506350F,
  144817. 0.9981647253F, 0.9981787360F, 0.9981926674F, 0.9982065199F,
  144818. 0.9982202936F, 0.9982339890F, 0.9982476062F, 0.9982611456F,
  144819. 0.9982746074F, 0.9982879920F, 0.9983012996F, 0.9983145304F,
  144820. 0.9983276849F, 0.9983407632F, 0.9983537657F, 0.9983666926F,
  144821. 0.9983795442F, 0.9983923208F, 0.9984050226F, 0.9984176501F,
  144822. 0.9984302033F, 0.9984426827F, 0.9984550884F, 0.9984674208F,
  144823. 0.9984796802F, 0.9984918667F, 0.9985039808F, 0.9985160227F,
  144824. 0.9985279926F, 0.9985398909F, 0.9985517177F, 0.9985634734F,
  144825. 0.9985751583F, 0.9985867727F, 0.9985983167F, 0.9986097907F,
  144826. 0.9986211949F, 0.9986325297F, 0.9986437953F, 0.9986549919F,
  144827. 0.9986661199F, 0.9986771795F, 0.9986881710F, 0.9986990946F,
  144828. 0.9987099507F, 0.9987207394F, 0.9987314611F, 0.9987421161F,
  144829. 0.9987527045F, 0.9987632267F, 0.9987736829F, 0.9987840734F,
  144830. 0.9987943985F, 0.9988046584F, 0.9988148534F, 0.9988249838F,
  144831. 0.9988350498F, 0.9988450516F, 0.9988549897F, 0.9988648641F,
  144832. 0.9988746753F, 0.9988844233F, 0.9988941086F, 0.9989037313F,
  144833. 0.9989132918F, 0.9989227902F, 0.9989322269F, 0.9989416021F,
  144834. 0.9989509160F, 0.9989601690F, 0.9989693613F, 0.9989784931F,
  144835. 0.9989875647F, 0.9989965763F, 0.9990055283F, 0.9990144208F,
  144836. 0.9990232541F, 0.9990320286F, 0.9990407443F, 0.9990494016F,
  144837. 0.9990580008F, 0.9990665421F, 0.9990750257F, 0.9990834519F,
  144838. 0.9990918209F, 0.9991001331F, 0.9991083886F, 0.9991165877F,
  144839. 0.9991247307F, 0.9991328177F, 0.9991408491F, 0.9991488251F,
  144840. 0.9991567460F, 0.9991646119F, 0.9991724232F, 0.9991801801F,
  144841. 0.9991878828F, 0.9991955316F, 0.9992031267F, 0.9992106684F,
  144842. 0.9992181569F, 0.9992255925F, 0.9992329753F, 0.9992403057F,
  144843. 0.9992475839F, 0.9992548101F, 0.9992619846F, 0.9992691076F,
  144844. 0.9992761793F, 0.9992832001F, 0.9992901701F, 0.9992970895F,
  144845. 0.9993039587F, 0.9993107777F, 0.9993175470F, 0.9993242667F,
  144846. 0.9993309371F, 0.9993375583F, 0.9993441307F, 0.9993506545F,
  144847. 0.9993571298F, 0.9993635570F, 0.9993699362F, 0.9993762678F,
  144848. 0.9993825519F, 0.9993887887F, 0.9993949785F, 0.9994011216F,
  144849. 0.9994072181F, 0.9994132683F, 0.9994192725F, 0.9994252307F,
  144850. 0.9994311434F, 0.9994370107F, 0.9994428327F, 0.9994486099F,
  144851. 0.9994543423F, 0.9994600303F, 0.9994656739F, 0.9994712736F,
  144852. 0.9994768294F, 0.9994823417F, 0.9994878105F, 0.9994932363F,
  144853. 0.9994986191F, 0.9995039592F, 0.9995092568F, 0.9995145122F,
  144854. 0.9995197256F, 0.9995248971F, 0.9995300270F, 0.9995351156F,
  144855. 0.9995401630F, 0.9995451695F, 0.9995501352F, 0.9995550604F,
  144856. 0.9995599454F, 0.9995647903F, 0.9995695953F, 0.9995743607F,
  144857. 0.9995790866F, 0.9995837734F, 0.9995884211F, 0.9995930300F,
  144858. 0.9995976004F, 0.9996021324F, 0.9996066263F, 0.9996110822F,
  144859. 0.9996155004F, 0.9996198810F, 0.9996242244F, 0.9996285306F,
  144860. 0.9996327999F, 0.9996370326F, 0.9996412287F, 0.9996453886F,
  144861. 0.9996495125F, 0.9996536004F, 0.9996576527F, 0.9996616696F,
  144862. 0.9996656512F, 0.9996695977F, 0.9996735094F, 0.9996773865F,
  144863. 0.9996812291F, 0.9996850374F, 0.9996888118F, 0.9996925523F,
  144864. 0.9996962591F, 0.9996999325F, 0.9997035727F, 0.9997071798F,
  144865. 0.9997107541F, 0.9997142957F, 0.9997178049F, 0.9997212818F,
  144866. 0.9997247266F, 0.9997281396F, 0.9997315209F, 0.9997348708F,
  144867. 0.9997381893F, 0.9997414767F, 0.9997447333F, 0.9997479591F,
  144868. 0.9997511544F, 0.9997543194F, 0.9997574542F, 0.9997605591F,
  144869. 0.9997636342F, 0.9997666797F, 0.9997696958F, 0.9997726828F,
  144870. 0.9997756407F, 0.9997785698F, 0.9997814703F, 0.9997843423F,
  144871. 0.9997871860F, 0.9997900016F, 0.9997927894F, 0.9997955494F,
  144872. 0.9997982818F, 0.9998009869F, 0.9998036648F, 0.9998063157F,
  144873. 0.9998089398F, 0.9998115373F, 0.9998141082F, 0.9998166529F,
  144874. 0.9998191715F, 0.9998216642F, 0.9998241311F, 0.9998265724F,
  144875. 0.9998289884F, 0.9998313790F, 0.9998337447F, 0.9998360854F,
  144876. 0.9998384015F, 0.9998406930F, 0.9998429602F, 0.9998452031F,
  144877. 0.9998474221F, 0.9998496171F, 0.9998517885F, 0.9998539364F,
  144878. 0.9998560610F, 0.9998581624F, 0.9998602407F, 0.9998622962F,
  144879. 0.9998643291F, 0.9998663394F, 0.9998683274F, 0.9998702932F,
  144880. 0.9998722370F, 0.9998741589F, 0.9998760591F, 0.9998779378F,
  144881. 0.9998797952F, 0.9998816313F, 0.9998834464F, 0.9998852406F,
  144882. 0.9998870141F, 0.9998887670F, 0.9998904995F, 0.9998922117F,
  144883. 0.9998939039F, 0.9998955761F, 0.9998972285F, 0.9998988613F,
  144884. 0.9999004746F, 0.9999020686F, 0.9999036434F, 0.9999051992F,
  144885. 0.9999067362F, 0.9999082544F, 0.9999097541F, 0.9999112354F,
  144886. 0.9999126984F, 0.9999141433F, 0.9999155703F, 0.9999169794F,
  144887. 0.9999183709F, 0.9999197449F, 0.9999211014F, 0.9999224408F,
  144888. 0.9999237631F, 0.9999250684F, 0.9999263570F, 0.9999276289F,
  144889. 0.9999288843F, 0.9999301233F, 0.9999313461F, 0.9999325529F,
  144890. 0.9999337437F, 0.9999349187F, 0.9999360780F, 0.9999372218F,
  144891. 0.9999383503F, 0.9999394635F, 0.9999405616F, 0.9999416447F,
  144892. 0.9999427129F, 0.9999437665F, 0.9999448055F, 0.9999458301F,
  144893. 0.9999468404F, 0.9999478365F, 0.9999488185F, 0.9999497867F,
  144894. 0.9999507411F, 0.9999516819F, 0.9999526091F, 0.9999535230F,
  144895. 0.9999544236F, 0.9999553111F, 0.9999561856F, 0.9999570472F,
  144896. 0.9999578960F, 0.9999587323F, 0.9999595560F, 0.9999603674F,
  144897. 0.9999611666F, 0.9999619536F, 0.9999627286F, 0.9999634917F,
  144898. 0.9999642431F, 0.9999649828F, 0.9999657110F, 0.9999664278F,
  144899. 0.9999671334F, 0.9999678278F, 0.9999685111F, 0.9999691835F,
  144900. 0.9999698451F, 0.9999704960F, 0.9999711364F, 0.9999717662F,
  144901. 0.9999723858F, 0.9999729950F, 0.9999735942F, 0.9999741834F,
  144902. 0.9999747626F, 0.9999753321F, 0.9999758919F, 0.9999764421F,
  144903. 0.9999769828F, 0.9999775143F, 0.9999780364F, 0.9999785495F,
  144904. 0.9999790535F, 0.9999795485F, 0.9999800348F, 0.9999805124F,
  144905. 0.9999809813F, 0.9999814417F, 0.9999818938F, 0.9999823375F,
  144906. 0.9999827731F, 0.9999832005F, 0.9999836200F, 0.9999840316F,
  144907. 0.9999844353F, 0.9999848314F, 0.9999852199F, 0.9999856008F,
  144908. 0.9999859744F, 0.9999863407F, 0.9999866997F, 0.9999870516F,
  144909. 0.9999873965F, 0.9999877345F, 0.9999880656F, 0.9999883900F,
  144910. 0.9999887078F, 0.9999890190F, 0.9999893237F, 0.9999896220F,
  144911. 0.9999899140F, 0.9999901999F, 0.9999904796F, 0.9999907533F,
  144912. 0.9999910211F, 0.9999912830F, 0.9999915391F, 0.9999917896F,
  144913. 0.9999920345F, 0.9999922738F, 0.9999925077F, 0.9999927363F,
  144914. 0.9999929596F, 0.9999931777F, 0.9999933907F, 0.9999935987F,
  144915. 0.9999938018F, 0.9999940000F, 0.9999941934F, 0.9999943820F,
  144916. 0.9999945661F, 0.9999947456F, 0.9999949206F, 0.9999950912F,
  144917. 0.9999952575F, 0.9999954195F, 0.9999955773F, 0.9999957311F,
  144918. 0.9999958807F, 0.9999960265F, 0.9999961683F, 0.9999963063F,
  144919. 0.9999964405F, 0.9999965710F, 0.9999966979F, 0.9999968213F,
  144920. 0.9999969412F, 0.9999970576F, 0.9999971707F, 0.9999972805F,
  144921. 0.9999973871F, 0.9999974905F, 0.9999975909F, 0.9999976881F,
  144922. 0.9999977824F, 0.9999978738F, 0.9999979624F, 0.9999980481F,
  144923. 0.9999981311F, 0.9999982115F, 0.9999982892F, 0.9999983644F,
  144924. 0.9999984370F, 0.9999985072F, 0.9999985750F, 0.9999986405F,
  144925. 0.9999987037F, 0.9999987647F, 0.9999988235F, 0.9999988802F,
  144926. 0.9999989348F, 0.9999989873F, 0.9999990379F, 0.9999990866F,
  144927. 0.9999991334F, 0.9999991784F, 0.9999992217F, 0.9999992632F,
  144928. 0.9999993030F, 0.9999993411F, 0.9999993777F, 0.9999994128F,
  144929. 0.9999994463F, 0.9999994784F, 0.9999995091F, 0.9999995384F,
  144930. 0.9999995663F, 0.9999995930F, 0.9999996184F, 0.9999996426F,
  144931. 0.9999996657F, 0.9999996876F, 0.9999997084F, 0.9999997282F,
  144932. 0.9999997469F, 0.9999997647F, 0.9999997815F, 0.9999997973F,
  144933. 0.9999998123F, 0.9999998265F, 0.9999998398F, 0.9999998524F,
  144934. 0.9999998642F, 0.9999998753F, 0.9999998857F, 0.9999998954F,
  144935. 0.9999999045F, 0.9999999130F, 0.9999999209F, 0.9999999282F,
  144936. 0.9999999351F, 0.9999999414F, 0.9999999472F, 0.9999999526F,
  144937. 0.9999999576F, 0.9999999622F, 0.9999999664F, 0.9999999702F,
  144938. 0.9999999737F, 0.9999999769F, 0.9999999798F, 0.9999999824F,
  144939. 0.9999999847F, 0.9999999868F, 0.9999999887F, 0.9999999904F,
  144940. 0.9999999919F, 0.9999999932F, 0.9999999943F, 0.9999999953F,
  144941. 0.9999999961F, 0.9999999969F, 0.9999999975F, 0.9999999980F,
  144942. 0.9999999985F, 0.9999999988F, 0.9999999991F, 0.9999999993F,
  144943. 0.9999999995F, 0.9999999997F, 0.9999999998F, 0.9999999999F,
  144944. 0.9999999999F, 1.0000000000F, 1.0000000000F, 1.0000000000F,
  144945. 1.0000000000F, 1.0000000000F, 1.0000000000F, 1.0000000000F,
  144946. };
  144947. static float *vwin[8] = {
  144948. vwin64,
  144949. vwin128,
  144950. vwin256,
  144951. vwin512,
  144952. vwin1024,
  144953. vwin2048,
  144954. vwin4096,
  144955. vwin8192,
  144956. };
  144957. float *_vorbis_window_get(int n){
  144958. return vwin[n];
  144959. }
  144960. void _vorbis_apply_window(float *d,int *winno,long *blocksizes,
  144961. int lW,int W,int nW){
  144962. lW=(W?lW:0);
  144963. nW=(W?nW:0);
  144964. {
  144965. float *windowLW=vwin[winno[lW]];
  144966. float *windowNW=vwin[winno[nW]];
  144967. long n=blocksizes[W];
  144968. long ln=blocksizes[lW];
  144969. long rn=blocksizes[nW];
  144970. long leftbegin=n/4-ln/4;
  144971. long leftend=leftbegin+ln/2;
  144972. long rightbegin=n/2+n/4-rn/4;
  144973. long rightend=rightbegin+rn/2;
  144974. int i,p;
  144975. for(i=0;i<leftbegin;i++)
  144976. d[i]=0.f;
  144977. for(p=0;i<leftend;i++,p++)
  144978. d[i]*=windowLW[p];
  144979. for(i=rightbegin,p=rn/2-1;i<rightend;i++,p--)
  144980. d[i]*=windowNW[p];
  144981. for(;i<n;i++)
  144982. d[i]=0.f;
  144983. }
  144984. }
  144985. #endif
  144986. /********* End of inlined file: window.c *********/
  144987. #else
  144988. #include <vorbis/vorbisenc.h>
  144989. #include <vorbis/codec.h>
  144990. #include <vorbis/vorbisfile.h>
  144991. #endif
  144992. }
  144993. BEGIN_JUCE_NAMESPACE
  144994. using namespace OggVorbisNamespace;
  144995. static const char* const oggFormatName = "Ogg-Vorbis file";
  144996. static const tchar* const oggExtensions[] = { T(".ogg"), 0 };
  144997. class OggReader : public AudioFormatReader
  144998. {
  144999. OggVorbis_File ovFile;
  145000. ov_callbacks callbacks;
  145001. AudioSampleBuffer reservoir;
  145002. int reservoirStart, samplesInReservoir;
  145003. public:
  145004. OggReader (InputStream* const inp)
  145005. : AudioFormatReader (inp, TRANS (oggFormatName)),
  145006. reservoir (2, 4096),
  145007. reservoirStart (0),
  145008. samplesInReservoir (0)
  145009. {
  145010. sampleRate = 0;
  145011. usesFloatingPointData = true;
  145012. callbacks.read_func = &oggReadCallback;
  145013. callbacks.seek_func = &oggSeekCallback;
  145014. callbacks.close_func = &oggCloseCallback;
  145015. callbacks.tell_func = &oggTellCallback;
  145016. const int err = ov_open_callbacks (input, &ovFile, 0, 0, callbacks);
  145017. if (err == 0)
  145018. {
  145019. vorbis_info* info = ov_info (&ovFile, -1);
  145020. lengthInSamples = (uint32) ov_pcm_total (&ovFile, -1);
  145021. numChannels = info->channels;
  145022. bitsPerSample = 16;
  145023. sampleRate = info->rate;
  145024. reservoir.setSize (numChannels,
  145025. (int) jmin (lengthInSamples, (int64) reservoir.getNumSamples()));
  145026. }
  145027. }
  145028. ~OggReader()
  145029. {
  145030. ov_clear (&ovFile);
  145031. }
  145032. bool readSamples (int** destSamples, int numDestChannels, int startOffsetInDestBuffer,
  145033. int64 startSampleInFile, int numSamples)
  145034. {
  145035. while (numSamples > 0)
  145036. {
  145037. const int numAvailable = reservoirStart + samplesInReservoir - startSampleInFile;
  145038. if (startSampleInFile >= reservoirStart && numAvailable > 0)
  145039. {
  145040. // got a few samples overlapping, so use them before seeking..
  145041. const int numToUse = jmin (numSamples, numAvailable);
  145042. for (int i = jmin (numDestChannels, reservoir.getNumChannels()); --i >= 0;)
  145043. if (destSamples[i] != 0)
  145044. memcpy (destSamples[i] + startOffsetInDestBuffer,
  145045. reservoir.getSampleData (i, (int) (startSampleInFile - reservoirStart)),
  145046. sizeof (float) * numToUse);
  145047. startSampleInFile += numToUse;
  145048. numSamples -= numToUse;
  145049. startOffsetInDestBuffer += numToUse;
  145050. if (numSamples == 0)
  145051. break;
  145052. }
  145053. if (startSampleInFile < reservoirStart
  145054. || startSampleInFile + numSamples > reservoirStart + samplesInReservoir)
  145055. {
  145056. // buffer miss, so refill the reservoir
  145057. int bitStream = 0;
  145058. reservoirStart = jmax (0, (int) startSampleInFile);
  145059. samplesInReservoir = reservoir.getNumSamples();
  145060. if (reservoirStart != (int) ov_pcm_tell (&ovFile))
  145061. ov_pcm_seek (&ovFile, reservoirStart);
  145062. int offset = 0;
  145063. int numToRead = samplesInReservoir;
  145064. while (numToRead > 0)
  145065. {
  145066. float** dataIn = 0;
  145067. const int samps = ov_read_float (&ovFile, &dataIn, numToRead, &bitStream);
  145068. if (samps <= 0)
  145069. break;
  145070. jassert (samps <= numToRead);
  145071. for (int i = jmin ((int) numChannels, reservoir.getNumChannels()); --i >= 0;)
  145072. {
  145073. memcpy (reservoir.getSampleData (i, offset),
  145074. dataIn[i],
  145075. sizeof (float) * samps);
  145076. }
  145077. numToRead -= samps;
  145078. offset += samps;
  145079. }
  145080. if (numToRead > 0)
  145081. reservoir.clear (offset, numToRead);
  145082. }
  145083. }
  145084. if (numSamples > 0)
  145085. {
  145086. for (int i = numDestChannels; --i >= 0;)
  145087. if (destSamples[i] != 0)
  145088. zeromem (destSamples[i] + startOffsetInDestBuffer,
  145089. sizeof (int) * numSamples);
  145090. }
  145091. return true;
  145092. }
  145093. static size_t oggReadCallback (void* ptr, size_t size, size_t nmemb, void* datasource)
  145094. {
  145095. return (size_t) (((InputStream*) datasource)->read (ptr, (int) (size * nmemb)) / size);
  145096. }
  145097. static int oggSeekCallback (void* datasource, ogg_int64_t offset, int whence)
  145098. {
  145099. InputStream* const in = (InputStream*) datasource;
  145100. if (whence == SEEK_CUR)
  145101. offset += in->getPosition();
  145102. else if (whence == SEEK_END)
  145103. offset += in->getTotalLength();
  145104. in->setPosition (offset);
  145105. return 0;
  145106. }
  145107. static int oggCloseCallback (void*)
  145108. {
  145109. return 0;
  145110. }
  145111. static long oggTellCallback (void* datasource)
  145112. {
  145113. return (long) ((InputStream*) datasource)->getPosition();
  145114. }
  145115. juce_UseDebuggingNewOperator
  145116. };
  145117. class OggWriter : public AudioFormatWriter
  145118. {
  145119. ogg_stream_state os;
  145120. ogg_page og;
  145121. ogg_packet op;
  145122. vorbis_info vi;
  145123. vorbis_comment vc;
  145124. vorbis_dsp_state vd;
  145125. vorbis_block vb;
  145126. public:
  145127. bool ok;
  145128. OggWriter (OutputStream* const out,
  145129. const double sampleRate,
  145130. const int numChannels,
  145131. const int bitsPerSample,
  145132. const int qualityIndex)
  145133. : AudioFormatWriter (out, TRANS (oggFormatName),
  145134. sampleRate,
  145135. numChannels,
  145136. bitsPerSample)
  145137. {
  145138. ok = false;
  145139. vorbis_info_init (&vi);
  145140. if (vorbis_encode_init_vbr (&vi,
  145141. numChannels,
  145142. (int) sampleRate,
  145143. jlimit (0.0f, 1.0f, qualityIndex * 0.5f)) == 0)
  145144. {
  145145. vorbis_comment_init (&vc);
  145146. if (JUCEApplication::getInstance() != 0)
  145147. vorbis_comment_add_tag (&vc, "ENCODER",
  145148. (char*) (const char*) JUCEApplication::getInstance()->getApplicationName());
  145149. vorbis_analysis_init (&vd, &vi);
  145150. vorbis_block_init (&vd, &vb);
  145151. ogg_stream_init (&os, Random::getSystemRandom().nextInt());
  145152. ogg_packet header;
  145153. ogg_packet header_comm;
  145154. ogg_packet header_code;
  145155. vorbis_analysis_headerout (&vd, &vc, &header, &header_comm, &header_code);
  145156. ogg_stream_packetin (&os, &header);
  145157. ogg_stream_packetin (&os, &header_comm);
  145158. ogg_stream_packetin (&os, &header_code);
  145159. for (;;)
  145160. {
  145161. if (ogg_stream_flush (&os, &og) == 0)
  145162. break;
  145163. output->write (og.header, og.header_len);
  145164. output->write (og.body, og.body_len);
  145165. }
  145166. ok = true;
  145167. }
  145168. }
  145169. ~OggWriter()
  145170. {
  145171. if (ok)
  145172. {
  145173. // write a zero-length packet to show ogg that we're finished..
  145174. write (0, 0);
  145175. ogg_stream_clear (&os);
  145176. vorbis_block_clear (&vb);
  145177. vorbis_dsp_clear (&vd);
  145178. vorbis_comment_clear (&vc);
  145179. vorbis_info_clear (&vi);
  145180. output->flush();
  145181. }
  145182. else
  145183. {
  145184. vorbis_info_clear (&vi);
  145185. output = 0; // to stop the base class deleting this, as it needs to be returned
  145186. // to the caller of createWriter()
  145187. }
  145188. }
  145189. bool write (const int** samplesToWrite, int numSamples)
  145190. {
  145191. if (! ok)
  145192. return false;
  145193. if (numSamples > 0)
  145194. {
  145195. const double gain = 1.0 / 0x80000000u;
  145196. float** const vorbisBuffer = vorbis_analysis_buffer (&vd, numSamples);
  145197. for (int i = numChannels; --i >= 0;)
  145198. {
  145199. float* const dst = vorbisBuffer[i];
  145200. const int* const src = samplesToWrite [i];
  145201. if (src != 0 && dst != 0)
  145202. {
  145203. for (int j = 0; j < numSamples; ++j)
  145204. dst[j] = (float) (src[j] * gain);
  145205. }
  145206. }
  145207. }
  145208. vorbis_analysis_wrote (&vd, numSamples);
  145209. while (vorbis_analysis_blockout (&vd, &vb) == 1)
  145210. {
  145211. vorbis_analysis (&vb, 0);
  145212. vorbis_bitrate_addblock (&vb);
  145213. while (vorbis_bitrate_flushpacket (&vd, &op))
  145214. {
  145215. ogg_stream_packetin (&os, &op);
  145216. for (;;)
  145217. {
  145218. if (ogg_stream_pageout (&os, &og) == 0)
  145219. break;
  145220. output->write (og.header, og.header_len);
  145221. output->write (og.body, og.body_len);
  145222. if (ogg_page_eos (&og))
  145223. break;
  145224. }
  145225. }
  145226. }
  145227. return true;
  145228. }
  145229. juce_UseDebuggingNewOperator
  145230. };
  145231. OggVorbisAudioFormat::OggVorbisAudioFormat()
  145232. : AudioFormat (TRANS (oggFormatName), (const tchar**) oggExtensions)
  145233. {
  145234. }
  145235. OggVorbisAudioFormat::~OggVorbisAudioFormat()
  145236. {
  145237. }
  145238. const Array <int> OggVorbisAudioFormat::getPossibleSampleRates()
  145239. {
  145240. const int rates[] = { 22050, 32000, 44100, 48000, 0 };
  145241. return Array <int> (rates);
  145242. }
  145243. const Array <int> OggVorbisAudioFormat::getPossibleBitDepths()
  145244. {
  145245. Array <int> depths;
  145246. depths.add (32);
  145247. return depths;
  145248. }
  145249. bool OggVorbisAudioFormat::canDoStereo()
  145250. {
  145251. return true;
  145252. }
  145253. bool OggVorbisAudioFormat::canDoMono()
  145254. {
  145255. return true;
  145256. }
  145257. AudioFormatReader* OggVorbisAudioFormat::createReaderFor (InputStream* in,
  145258. const bool deleteStreamIfOpeningFails)
  145259. {
  145260. ScopedPointer <OggReader> r (new OggReader (in));
  145261. if (r->sampleRate != 0)
  145262. return r.release();
  145263. if (! deleteStreamIfOpeningFails)
  145264. r->input = 0;
  145265. return 0;
  145266. }
  145267. AudioFormatWriter* OggVorbisAudioFormat::createWriterFor (OutputStream* out,
  145268. double sampleRate,
  145269. unsigned int numChannels,
  145270. int bitsPerSample,
  145271. const StringPairArray& /*metadataValues*/,
  145272. int qualityOptionIndex)
  145273. {
  145274. ScopedPointer <OggWriter> w (new OggWriter (out,
  145275. sampleRate,
  145276. numChannels,
  145277. bitsPerSample,
  145278. qualityOptionIndex));
  145279. return w->ok ? w.release() : 0;
  145280. }
  145281. bool OggVorbisAudioFormat::isCompressed()
  145282. {
  145283. return true;
  145284. }
  145285. const StringArray OggVorbisAudioFormat::getQualityOptions()
  145286. {
  145287. StringArray s;
  145288. s.add ("Low Quality");
  145289. s.add ("Medium Quality");
  145290. s.add ("High Quality");
  145291. return s;
  145292. }
  145293. int OggVorbisAudioFormat::estimateOggFileQuality (const File& source)
  145294. {
  145295. FileInputStream* const in = source.createInputStream();
  145296. if (in != 0)
  145297. {
  145298. ScopedPointer <AudioFormatReader> r (createReaderFor (in, true));
  145299. if (r != 0)
  145300. {
  145301. const int64 numSamps = r->lengthInSamples;
  145302. r = 0;
  145303. const int64 fileNumSamps = source.getSize() / 4;
  145304. const double ratio = numSamps / (double) fileNumSamps;
  145305. if (ratio > 12.0)
  145306. return 0;
  145307. else if (ratio > 6.0)
  145308. return 1;
  145309. else
  145310. return 2;
  145311. }
  145312. }
  145313. return 1;
  145314. }
  145315. END_JUCE_NAMESPACE
  145316. #endif
  145317. /********* End of inlined file: juce_OggVorbisAudioFormat.cpp *********/
  145318. /********* Start of inlined file: juce_JPEGLoader.cpp *********/
  145319. #if JUCE_MSVC
  145320. #pragma warning (push)
  145321. #endif
  145322. namespace jpeglibNamespace
  145323. {
  145324. #if JUCE_INCLUDE_JPEGLIB_CODE
  145325. #if JUCE_MINGW
  145326. typedef unsigned char boolean;
  145327. #endif
  145328. extern "C"
  145329. {
  145330. #define JPEG_INTERNALS
  145331. #undef FAR
  145332. /********* Start of inlined file: jpeglib.h *********/
  145333. #ifndef JPEGLIB_H
  145334. #define JPEGLIB_H
  145335. #ifndef JCONFIG_INCLUDED /* in case jinclude.h already did */
  145336. /********* Start of inlined file: jconfig.h *********/
  145337. // disable all the warnings under MSVC
  145338. #ifdef _MSC_VER
  145339. #pragma warning (disable: 4996 4267 4100 4127 4702 4244)
  145340. #endif
  145341. #ifdef __BORLANDC__
  145342. #pragma warn -8057
  145343. #pragma warn -8019
  145344. #pragma warn -8004
  145345. #pragma warn -8008
  145346. #endif
  145347. #define HAVE_PROTOTYPES
  145348. #define HAVE_UNSIGNED_CHAR
  145349. #define HAVE_UNSIGNED_SHORT
  145350. #undef CHAR_IS_UNSIGNED
  145351. #define HAVE_STDDEF_H
  145352. #define HAVE_STDLIB_H
  145353. #undef NEED_BSD_STRINGS
  145354. #undef NEED_SYS_TYPES_H
  145355. #undef NEED_FAR_POINTERS /* we presume a 32-bit flat memory model */
  145356. #undef NEED_SHORT_EXTERNAL_NAMES
  145357. #undef INCOMPLETE_TYPES_BROKEN
  145358. #ifndef __RPCNDR_H__ /* don't conflict if rpcndr.h already read */
  145359. typedef unsigned char boolean;
  145360. #endif
  145361. #define HAVE_BOOLEAN /* prevent jmorecfg.h from redefining it */
  145362. #ifdef JPEG_INTERNALS
  145363. #undef RIGHT_SHIFT_IS_UNSIGNED
  145364. #endif /* JPEG_INTERNALS */
  145365. #ifdef JPEG_CJPEG_DJPEG
  145366. #define BMP_SUPPORTED /* BMP image file format */
  145367. #define GIF_SUPPORTED /* GIF image file format */
  145368. #define PPM_SUPPORTED /* PBMPLUS PPM/PGM image file format */
  145369. #undef RLE_SUPPORTED /* Utah RLE image file format */
  145370. #define TARGA_SUPPORTED /* Targa image file format */
  145371. #define TWO_FILE_COMMANDLINE /* optional */
  145372. #define USE_SETMODE /* Microsoft has setmode() */
  145373. #undef NEED_SIGNAL_CATCHER
  145374. #undef DONT_USE_B_MODE
  145375. #undef PROGRESS_REPORT /* optional */
  145376. #endif /* JPEG_CJPEG_DJPEG */
  145377. /********* End of inlined file: jconfig.h *********/
  145378. #endif
  145379. /********* Start of inlined file: jmorecfg.h *********/
  145380. #define BITS_IN_JSAMPLE 8 /* use 8 or 12 */
  145381. #define MAX_COMPONENTS 10 /* maximum number of image components */
  145382. #if BITS_IN_JSAMPLE == 8
  145383. #ifdef HAVE_UNSIGNED_CHAR
  145384. typedef unsigned char JSAMPLE;
  145385. #define GETJSAMPLE(value) ((int) (value))
  145386. #else /* not HAVE_UNSIGNED_CHAR */
  145387. typedef char JSAMPLE;
  145388. #ifdef CHAR_IS_UNSIGNED
  145389. #define GETJSAMPLE(value) ((int) (value))
  145390. #else
  145391. #define GETJSAMPLE(value) ((int) (value) & 0xFF)
  145392. #endif /* CHAR_IS_UNSIGNED */
  145393. #endif /* HAVE_UNSIGNED_CHAR */
  145394. #define MAXJSAMPLE 255
  145395. #define CENTERJSAMPLE 128
  145396. #endif /* BITS_IN_JSAMPLE == 8 */
  145397. #if BITS_IN_JSAMPLE == 12
  145398. typedef short JSAMPLE;
  145399. #define GETJSAMPLE(value) ((int) (value))
  145400. #define MAXJSAMPLE 4095
  145401. #define CENTERJSAMPLE 2048
  145402. #endif /* BITS_IN_JSAMPLE == 12 */
  145403. typedef short JCOEF;
  145404. #ifdef HAVE_UNSIGNED_CHAR
  145405. typedef unsigned char JOCTET;
  145406. #define GETJOCTET(value) (value)
  145407. #else /* not HAVE_UNSIGNED_CHAR */
  145408. typedef char JOCTET;
  145409. #ifdef CHAR_IS_UNSIGNED
  145410. #define GETJOCTET(value) (value)
  145411. #else
  145412. #define GETJOCTET(value) ((value) & 0xFF)
  145413. #endif /* CHAR_IS_UNSIGNED */
  145414. #endif /* HAVE_UNSIGNED_CHAR */
  145415. #ifdef HAVE_UNSIGNED_CHAR
  145416. typedef unsigned char UINT8;
  145417. #else /* not HAVE_UNSIGNED_CHAR */
  145418. #ifdef CHAR_IS_UNSIGNED
  145419. typedef char UINT8;
  145420. #else /* not CHAR_IS_UNSIGNED */
  145421. typedef short UINT8;
  145422. #endif /* CHAR_IS_UNSIGNED */
  145423. #endif /* HAVE_UNSIGNED_CHAR */
  145424. #ifdef HAVE_UNSIGNED_SHORT
  145425. typedef unsigned short UINT16;
  145426. #else /* not HAVE_UNSIGNED_SHORT */
  145427. typedef unsigned int UINT16;
  145428. #endif /* HAVE_UNSIGNED_SHORT */
  145429. #ifndef XMD_H /* X11/xmd.h correctly defines INT16 */
  145430. typedef short INT16;
  145431. #endif
  145432. #ifndef XMD_H /* X11/xmd.h correctly defines INT32 */
  145433. typedef long INT32;
  145434. #endif
  145435. typedef unsigned int JDIMENSION;
  145436. #define JPEG_MAX_DIMENSION 65500L /* a tad under 64K to prevent overflows */
  145437. #define METHODDEF(type) static type
  145438. #define LOCAL(type) static type
  145439. #define GLOBAL(type) type
  145440. #define EXTERN(type) extern type
  145441. #ifdef HAVE_PROTOTYPES
  145442. #define JMETHOD(type,methodname,arglist) type (*methodname) arglist
  145443. #else
  145444. #define JMETHOD(type,methodname,arglist) type (*methodname) ()
  145445. #endif
  145446. #ifdef NEED_FAR_POINTERS
  145447. #define FAR far
  145448. #else
  145449. #define FAR
  145450. #endif
  145451. #ifndef HAVE_BOOLEAN
  145452. typedef int boolean;
  145453. #endif
  145454. #ifndef FALSE /* in case these macros already exist */
  145455. #define FALSE 0 /* values of boolean */
  145456. #endif
  145457. #ifndef TRUE
  145458. #define TRUE 1
  145459. #endif
  145460. #ifdef JPEG_INTERNALS
  145461. #define JPEG_INTERNAL_OPTIONS
  145462. #endif
  145463. #ifdef JPEG_INTERNAL_OPTIONS
  145464. #define DCT_ISLOW_SUPPORTED /* slow but accurate integer algorithm */
  145465. #define DCT_IFAST_SUPPORTED /* faster, less accurate integer method */
  145466. #define DCT_FLOAT_SUPPORTED /* floating-point: accurate, fast on fast HW */
  145467. #undef C_ARITH_CODING_SUPPORTED /* Arithmetic coding back end? */
  145468. #define C_MULTISCAN_FILES_SUPPORTED /* Multiple-scan JPEG files? */
  145469. #define C_PROGRESSIVE_SUPPORTED /* Progressive JPEG? (Requires MULTISCAN)*/
  145470. #define ENTROPY_OPT_SUPPORTED /* Optimization of entropy coding parms? */
  145471. #define INPUT_SMOOTHING_SUPPORTED /* Input image smoothing option? */
  145472. #undef D_ARITH_CODING_SUPPORTED /* Arithmetic coding back end? */
  145473. #define D_MULTISCAN_FILES_SUPPORTED /* Multiple-scan JPEG files? */
  145474. #define D_PROGRESSIVE_SUPPORTED /* Progressive JPEG? (Requires MULTISCAN)*/
  145475. #define SAVE_MARKERS_SUPPORTED /* jpeg_save_markers() needed? */
  145476. #define BLOCK_SMOOTHING_SUPPORTED /* Block smoothing? (Progressive only) */
  145477. #define IDCT_SCALING_SUPPORTED /* Output rescaling via IDCT? */
  145478. #undef UPSAMPLE_SCALING_SUPPORTED /* Output rescaling at upsample stage? */
  145479. #define UPSAMPLE_MERGING_SUPPORTED /* Fast path for sloppy upsampling? */
  145480. #define QUANT_1PASS_SUPPORTED /* 1-pass color quantization? */
  145481. #define QUANT_2PASS_SUPPORTED /* 2-pass color quantization? */
  145482. #define RGB_RED 0 /* Offset of Red in an RGB scanline element */
  145483. #define RGB_GREEN 1 /* Offset of Green */
  145484. #define RGB_BLUE 2 /* Offset of Blue */
  145485. #define RGB_PIXELSIZE 3 /* JSAMPLEs per RGB scanline element */
  145486. #ifndef INLINE
  145487. #ifdef __GNUC__ /* for instance, GNU C knows about inline */
  145488. #define INLINE __inline__
  145489. #endif
  145490. #ifndef INLINE
  145491. #define INLINE /* default is to define it as empty */
  145492. #endif
  145493. #endif
  145494. #ifndef MULTIPLIER
  145495. #define MULTIPLIER int /* type for fastest integer multiply */
  145496. #endif
  145497. #ifndef FAST_FLOAT
  145498. #ifdef HAVE_PROTOTYPES
  145499. #define FAST_FLOAT float
  145500. #else
  145501. #define FAST_FLOAT double
  145502. #endif
  145503. #endif
  145504. #endif /* JPEG_INTERNAL_OPTIONS */
  145505. /********* End of inlined file: jmorecfg.h *********/
  145506. #define JPEG_LIB_VERSION 62 /* Version 6b */
  145507. #define DCTSIZE 8 /* The basic DCT block is 8x8 samples */
  145508. #define DCTSIZE2 64 /* DCTSIZE squared; # of elements in a block */
  145509. #define NUM_QUANT_TBLS 4 /* Quantization tables are numbered 0..3 */
  145510. #define NUM_HUFF_TBLS 4 /* Huffman tables are numbered 0..3 */
  145511. #define NUM_ARITH_TBLS 16 /* Arith-coding tables are numbered 0..15 */
  145512. #define MAX_COMPS_IN_SCAN 4 /* JPEG limit on # of components in one scan */
  145513. #define MAX_SAMP_FACTOR 4 /* JPEG limit on sampling factors */
  145514. #define C_MAX_BLOCKS_IN_MCU 10 /* compressor's limit on blocks per MCU */
  145515. #ifndef D_MAX_BLOCKS_IN_MCU
  145516. #define D_MAX_BLOCKS_IN_MCU 10 /* decompressor's limit on blocks per MCU */
  145517. #endif
  145518. typedef JSAMPLE FAR *JSAMPROW; /* ptr to one image row of pixel samples. */
  145519. typedef JSAMPROW *JSAMPARRAY; /* ptr to some rows (a 2-D sample array) */
  145520. typedef JSAMPARRAY *JSAMPIMAGE; /* a 3-D sample array: top index is color */
  145521. typedef JCOEF JBLOCK[DCTSIZE2]; /* one block of coefficients */
  145522. typedef JBLOCK FAR *JBLOCKROW; /* pointer to one row of coefficient blocks */
  145523. typedef JBLOCKROW *JBLOCKARRAY; /* a 2-D array of coefficient blocks */
  145524. typedef JBLOCKARRAY *JBLOCKIMAGE; /* a 3-D array of coefficient blocks */
  145525. typedef JCOEF FAR *JCOEFPTR; /* useful in a couple of places */
  145526. typedef struct {
  145527. UINT16 quantval[DCTSIZE2]; /* quantization step for each coefficient */
  145528. boolean sent_table; /* TRUE when table has been output */
  145529. } JQUANT_TBL;
  145530. typedef struct {
  145531. UINT8 bits[17]; /* bits[k] = # of symbols with codes of */
  145532. UINT8 huffval[256]; /* The symbols, in order of incr code length */
  145533. boolean sent_table; /* TRUE when table has been output */
  145534. } JHUFF_TBL;
  145535. typedef struct {
  145536. int component_id; /* identifier for this component (0..255) */
  145537. int component_index; /* its index in SOF or cinfo->comp_info[] */
  145538. int h_samp_factor; /* horizontal sampling factor (1..4) */
  145539. int v_samp_factor; /* vertical sampling factor (1..4) */
  145540. int quant_tbl_no; /* quantization table selector (0..3) */
  145541. int dc_tbl_no; /* DC entropy table selector (0..3) */
  145542. int ac_tbl_no; /* AC entropy table selector (0..3) */
  145543. JDIMENSION width_in_blocks;
  145544. JDIMENSION height_in_blocks;
  145545. int DCT_scaled_size;
  145546. JDIMENSION downsampled_width; /* actual width in samples */
  145547. JDIMENSION downsampled_height; /* actual height in samples */
  145548. boolean component_needed; /* do we need the value of this component? */
  145549. int MCU_width; /* number of blocks per MCU, horizontally */
  145550. int MCU_height; /* number of blocks per MCU, vertically */
  145551. int MCU_blocks; /* MCU_width * MCU_height */
  145552. int MCU_sample_width; /* MCU width in samples, MCU_width*DCT_scaled_size */
  145553. int last_col_width; /* # of non-dummy blocks across in last MCU */
  145554. int last_row_height; /* # of non-dummy blocks down in last MCU */
  145555. JQUANT_TBL * quant_table;
  145556. void * dct_table;
  145557. } jpeg_component_info;
  145558. typedef struct {
  145559. int comps_in_scan; /* number of components encoded in this scan */
  145560. int component_index[MAX_COMPS_IN_SCAN]; /* their SOF/comp_info[] indexes */
  145561. int Ss, Se; /* progressive JPEG spectral selection parms */
  145562. int Ah, Al; /* progressive JPEG successive approx. parms */
  145563. } jpeg_scan_info;
  145564. typedef struct jpeg_marker_struct FAR * jpeg_saved_marker_ptr;
  145565. struct jpeg_marker_struct {
  145566. jpeg_saved_marker_ptr next; /* next in list, or NULL */
  145567. UINT8 marker; /* marker code: JPEG_COM, or JPEG_APP0+n */
  145568. unsigned int original_length; /* # bytes of data in the file */
  145569. unsigned int data_length; /* # bytes of data saved at data[] */
  145570. JOCTET FAR * data; /* the data contained in the marker */
  145571. };
  145572. typedef enum {
  145573. JCS_UNKNOWN, /* error/unspecified */
  145574. JCS_GRAYSCALE, /* monochrome */
  145575. JCS_RGB, /* red/green/blue */
  145576. JCS_YCbCr, /* Y/Cb/Cr (also known as YUV) */
  145577. JCS_CMYK, /* C/M/Y/K */
  145578. JCS_YCCK /* Y/Cb/Cr/K */
  145579. } J_COLOR_SPACE;
  145580. typedef enum {
  145581. JDCT_ISLOW, /* slow but accurate integer algorithm */
  145582. JDCT_IFAST, /* faster, less accurate integer method */
  145583. JDCT_FLOAT /* floating-point: accurate, fast on fast HW */
  145584. } J_DCT_METHOD;
  145585. #ifndef JDCT_DEFAULT /* may be overridden in jconfig.h */
  145586. #define JDCT_DEFAULT JDCT_ISLOW
  145587. #endif
  145588. #ifndef JDCT_FASTEST /* may be overridden in jconfig.h */
  145589. #define JDCT_FASTEST JDCT_IFAST
  145590. #endif
  145591. typedef enum {
  145592. JDITHER_NONE, /* no dithering */
  145593. JDITHER_ORDERED, /* simple ordered dither */
  145594. JDITHER_FS /* Floyd-Steinberg error diffusion dither */
  145595. } J_DITHER_MODE;
  145596. #define jpeg_common_fields \
  145597. struct jpeg_error_mgr * err; /* Error handler module */\
  145598. struct jpeg_memory_mgr * mem; /* Memory manager module */\
  145599. struct jpeg_progress_mgr * progress; /* Progress monitor, or NULL if none */\
  145600. void * client_data; /* Available for use by application */\
  145601. boolean is_decompressor; /* So common code can tell which is which */\
  145602. int global_state /* For checking call sequence validity */
  145603. struct jpeg_common_struct {
  145604. jpeg_common_fields; /* Fields common to both master struct types */
  145605. };
  145606. typedef struct jpeg_common_struct * j_common_ptr;
  145607. typedef struct jpeg_compress_struct * j_compress_ptr;
  145608. typedef struct jpeg_decompress_struct * j_decompress_ptr;
  145609. struct jpeg_compress_struct {
  145610. jpeg_common_fields; /* Fields shared with jpeg_decompress_struct */
  145611. struct jpeg_destination_mgr * dest;
  145612. JDIMENSION image_width; /* input image width */
  145613. JDIMENSION image_height; /* input image height */
  145614. int input_components; /* # of color components in input image */
  145615. J_COLOR_SPACE in_color_space; /* colorspace of input image */
  145616. double input_gamma; /* image gamma of input image */
  145617. int data_precision; /* bits of precision in image data */
  145618. int num_components; /* # of color components in JPEG image */
  145619. J_COLOR_SPACE jpeg_color_space; /* colorspace of JPEG image */
  145620. jpeg_component_info * comp_info;
  145621. JQUANT_TBL * quant_tbl_ptrs[NUM_QUANT_TBLS];
  145622. JHUFF_TBL * dc_huff_tbl_ptrs[NUM_HUFF_TBLS];
  145623. JHUFF_TBL * ac_huff_tbl_ptrs[NUM_HUFF_TBLS];
  145624. UINT8 arith_dc_L[NUM_ARITH_TBLS]; /* L values for DC arith-coding tables */
  145625. UINT8 arith_dc_U[NUM_ARITH_TBLS]; /* U values for DC arith-coding tables */
  145626. UINT8 arith_ac_K[NUM_ARITH_TBLS]; /* Kx values for AC arith-coding tables */
  145627. int num_scans; /* # of entries in scan_info array */
  145628. const jpeg_scan_info * scan_info; /* script for multi-scan file, or NULL */
  145629. boolean raw_data_in; /* TRUE=caller supplies downsampled data */
  145630. boolean arith_code; /* TRUE=arithmetic coding, FALSE=Huffman */
  145631. boolean optimize_coding; /* TRUE=optimize entropy encoding parms */
  145632. boolean CCIR601_sampling; /* TRUE=first samples are cosited */
  145633. int smoothing_factor; /* 1..100, or 0 for no input smoothing */
  145634. J_DCT_METHOD dct_method; /* DCT algorithm selector */
  145635. unsigned int restart_interval; /* MCUs per restart, or 0 for no restart */
  145636. int restart_in_rows; /* if > 0, MCU rows per restart interval */
  145637. boolean write_JFIF_header; /* should a JFIF marker be written? */
  145638. UINT8 JFIF_major_version; /* What to write for the JFIF version number */
  145639. UINT8 JFIF_minor_version;
  145640. UINT8 density_unit; /* JFIF code for pixel size units */
  145641. UINT16 X_density; /* Horizontal pixel density */
  145642. UINT16 Y_density; /* Vertical pixel density */
  145643. boolean write_Adobe_marker; /* should an Adobe marker be written? */
  145644. JDIMENSION next_scanline; /* 0 .. image_height-1 */
  145645. boolean progressive_mode; /* TRUE if scan script uses progressive mode */
  145646. int max_h_samp_factor; /* largest h_samp_factor */
  145647. int max_v_samp_factor; /* largest v_samp_factor */
  145648. JDIMENSION total_iMCU_rows; /* # of iMCU rows to be input to coef ctlr */
  145649. int comps_in_scan; /* # of JPEG components in this scan */
  145650. jpeg_component_info * cur_comp_info[MAX_COMPS_IN_SCAN];
  145651. JDIMENSION MCUs_per_row; /* # of MCUs across the image */
  145652. JDIMENSION MCU_rows_in_scan; /* # of MCU rows in the image */
  145653. int blocks_in_MCU; /* # of DCT blocks per MCU */
  145654. int MCU_membership[C_MAX_BLOCKS_IN_MCU];
  145655. int Ss, Se, Ah, Al; /* progressive JPEG parameters for scan */
  145656. struct jpeg_comp_master * master;
  145657. struct jpeg_c_main_controller * main;
  145658. struct jpeg_c_prep_controller * prep;
  145659. struct jpeg_c_coef_controller * coef;
  145660. struct jpeg_marker_writer * marker;
  145661. struct jpeg_color_converter * cconvert;
  145662. struct jpeg_downsampler * downsample;
  145663. struct jpeg_forward_dct * fdct;
  145664. struct jpeg_entropy_encoder * entropy;
  145665. jpeg_scan_info * script_space; /* workspace for jpeg_simple_progression */
  145666. int script_space_size;
  145667. };
  145668. struct jpeg_decompress_struct {
  145669. jpeg_common_fields; /* Fields shared with jpeg_compress_struct */
  145670. struct jpeg_source_mgr * src;
  145671. JDIMENSION image_width; /* nominal image width (from SOF marker) */
  145672. JDIMENSION image_height; /* nominal image height */
  145673. int num_components; /* # of color components in JPEG image */
  145674. J_COLOR_SPACE jpeg_color_space; /* colorspace of JPEG image */
  145675. J_COLOR_SPACE out_color_space; /* colorspace for output */
  145676. unsigned int scale_num, scale_denom; /* fraction by which to scale image */
  145677. double output_gamma; /* image gamma wanted in output */
  145678. boolean buffered_image; /* TRUE=multiple output passes */
  145679. boolean raw_data_out; /* TRUE=downsampled data wanted */
  145680. J_DCT_METHOD dct_method; /* IDCT algorithm selector */
  145681. boolean do_fancy_upsampling; /* TRUE=apply fancy upsampling */
  145682. boolean do_block_smoothing; /* TRUE=apply interblock smoothing */
  145683. boolean quantize_colors; /* TRUE=colormapped output wanted */
  145684. J_DITHER_MODE dither_mode; /* type of color dithering to use */
  145685. boolean two_pass_quantize; /* TRUE=use two-pass color quantization */
  145686. int desired_number_of_colors; /* max # colors to use in created colormap */
  145687. boolean enable_1pass_quant; /* enable future use of 1-pass quantizer */
  145688. boolean enable_external_quant;/* enable future use of external colormap */
  145689. boolean enable_2pass_quant; /* enable future use of 2-pass quantizer */
  145690. JDIMENSION output_width; /* scaled image width */
  145691. JDIMENSION output_height; /* scaled image height */
  145692. int out_color_components; /* # of color components in out_color_space */
  145693. int output_components; /* # of color components returned */
  145694. int rec_outbuf_height; /* min recommended height of scanline buffer */
  145695. int actual_number_of_colors; /* number of entries in use */
  145696. JSAMPARRAY colormap; /* The color map as a 2-D pixel array */
  145697. JDIMENSION output_scanline; /* 0 .. output_height-1 */
  145698. int input_scan_number; /* Number of SOS markers seen so far */
  145699. JDIMENSION input_iMCU_row; /* Number of iMCU rows completed */
  145700. int output_scan_number; /* Nominal scan number being displayed */
  145701. JDIMENSION output_iMCU_row; /* Number of iMCU rows read */
  145702. int (*coef_bits)[DCTSIZE2]; /* -1 or current Al value for each coef */
  145703. JQUANT_TBL * quant_tbl_ptrs[NUM_QUANT_TBLS];
  145704. JHUFF_TBL * dc_huff_tbl_ptrs[NUM_HUFF_TBLS];
  145705. JHUFF_TBL * ac_huff_tbl_ptrs[NUM_HUFF_TBLS];
  145706. int data_precision; /* bits of precision in image data */
  145707. jpeg_component_info * comp_info;
  145708. boolean progressive_mode; /* TRUE if SOFn specifies progressive mode */
  145709. boolean arith_code; /* TRUE=arithmetic coding, FALSE=Huffman */
  145710. UINT8 arith_dc_L[NUM_ARITH_TBLS]; /* L values for DC arith-coding tables */
  145711. UINT8 arith_dc_U[NUM_ARITH_TBLS]; /* U values for DC arith-coding tables */
  145712. UINT8 arith_ac_K[NUM_ARITH_TBLS]; /* Kx values for AC arith-coding tables */
  145713. unsigned int restart_interval; /* MCUs per restart interval, or 0 for no restart */
  145714. boolean saw_JFIF_marker; /* TRUE iff a JFIF APP0 marker was found */
  145715. UINT8 JFIF_major_version; /* JFIF version number */
  145716. UINT8 JFIF_minor_version;
  145717. UINT8 density_unit; /* JFIF code for pixel size units */
  145718. UINT16 X_density; /* Horizontal pixel density */
  145719. UINT16 Y_density; /* Vertical pixel density */
  145720. boolean saw_Adobe_marker; /* TRUE iff an Adobe APP14 marker was found */
  145721. UINT8 Adobe_transform; /* Color transform code from Adobe marker */
  145722. boolean CCIR601_sampling; /* TRUE=first samples are cosited */
  145723. jpeg_saved_marker_ptr marker_list; /* Head of list of saved markers */
  145724. int max_h_samp_factor; /* largest h_samp_factor */
  145725. int max_v_samp_factor; /* largest v_samp_factor */
  145726. int min_DCT_scaled_size; /* smallest DCT_scaled_size of any component */
  145727. JDIMENSION total_iMCU_rows; /* # of iMCU rows in image */
  145728. JSAMPLE * sample_range_limit; /* table for fast range-limiting */
  145729. int comps_in_scan; /* # of JPEG components in this scan */
  145730. jpeg_component_info * cur_comp_info[MAX_COMPS_IN_SCAN];
  145731. JDIMENSION MCUs_per_row; /* # of MCUs across the image */
  145732. JDIMENSION MCU_rows_in_scan; /* # of MCU rows in the image */
  145733. int blocks_in_MCU; /* # of DCT blocks per MCU */
  145734. int MCU_membership[D_MAX_BLOCKS_IN_MCU];
  145735. int Ss, Se, Ah, Al; /* progressive JPEG parameters for scan */
  145736. int unread_marker;
  145737. struct jpeg_decomp_master * master;
  145738. struct jpeg_d_main_controller * main;
  145739. struct jpeg_d_coef_controller * coef;
  145740. struct jpeg_d_post_controller * post;
  145741. struct jpeg_input_controller * inputctl;
  145742. struct jpeg_marker_reader * marker;
  145743. struct jpeg_entropy_decoder * entropy;
  145744. struct jpeg_inverse_dct * idct;
  145745. struct jpeg_upsampler * upsample;
  145746. struct jpeg_color_deconverter * cconvert;
  145747. struct jpeg_color_quantizer * cquantize;
  145748. };
  145749. struct jpeg_error_mgr {
  145750. JMETHOD(void, error_exit, (j_common_ptr cinfo));
  145751. JMETHOD(void, emit_message, (j_common_ptr cinfo, int msg_level));
  145752. JMETHOD(void, output_message, (j_common_ptr cinfo));
  145753. JMETHOD(void, format_message, (j_common_ptr cinfo, char * buffer));
  145754. #define JMSG_LENGTH_MAX 200 /* recommended size of format_message buffer */
  145755. JMETHOD(void, reset_error_mgr, (j_common_ptr cinfo));
  145756. int msg_code;
  145757. #define JMSG_STR_PARM_MAX 80
  145758. union {
  145759. int i[8];
  145760. char s[JMSG_STR_PARM_MAX];
  145761. } msg_parm;
  145762. int trace_level; /* max msg_level that will be displayed */
  145763. long num_warnings; /* number of corrupt-data warnings */
  145764. const char * const * jpeg_message_table; /* Library errors */
  145765. int last_jpeg_message; /* Table contains strings 0..last_jpeg_message */
  145766. const char * const * addon_message_table; /* Non-library errors */
  145767. int first_addon_message; /* code for first string in addon table */
  145768. int last_addon_message; /* code for last string in addon table */
  145769. };
  145770. struct jpeg_progress_mgr {
  145771. JMETHOD(void, progress_monitor, (j_common_ptr cinfo));
  145772. long pass_counter; /* work units completed in this pass */
  145773. long pass_limit; /* total number of work units in this pass */
  145774. int completed_passes; /* passes completed so far */
  145775. int total_passes; /* total number of passes expected */
  145776. };
  145777. struct jpeg_destination_mgr {
  145778. JOCTET * next_output_byte; /* => next byte to write in buffer */
  145779. size_t free_in_buffer; /* # of byte spaces remaining in buffer */
  145780. JMETHOD(void, init_destination, (j_compress_ptr cinfo));
  145781. JMETHOD(boolean, empty_output_buffer, (j_compress_ptr cinfo));
  145782. JMETHOD(void, term_destination, (j_compress_ptr cinfo));
  145783. };
  145784. struct jpeg_source_mgr {
  145785. const JOCTET * next_input_byte; /* => next byte to read from buffer */
  145786. size_t bytes_in_buffer; /* # of bytes remaining in buffer */
  145787. JMETHOD(void, init_source, (j_decompress_ptr cinfo));
  145788. JMETHOD(boolean, fill_input_buffer, (j_decompress_ptr cinfo));
  145789. JMETHOD(void, skip_input_data, (j_decompress_ptr cinfo, long num_bytes));
  145790. JMETHOD(boolean, resync_to_restart, (j_decompress_ptr cinfo, int desired));
  145791. JMETHOD(void, term_source, (j_decompress_ptr cinfo));
  145792. };
  145793. #define JPOOL_PERMANENT 0 /* lasts until master record is destroyed */
  145794. #define JPOOL_IMAGE 1 /* lasts until done with image/datastream */
  145795. #define JPOOL_NUMPOOLS 2
  145796. typedef struct jvirt_sarray_control * jvirt_sarray_ptr;
  145797. typedef struct jvirt_barray_control * jvirt_barray_ptr;
  145798. struct jpeg_memory_mgr {
  145799. JMETHOD(void *, alloc_small, (j_common_ptr cinfo, int pool_id,
  145800. size_t sizeofobject));
  145801. JMETHOD(void FAR *, alloc_large, (j_common_ptr cinfo, int pool_id,
  145802. size_t sizeofobject));
  145803. JMETHOD(JSAMPARRAY, alloc_sarray, (j_common_ptr cinfo, int pool_id,
  145804. JDIMENSION samplesperrow,
  145805. JDIMENSION numrows));
  145806. JMETHOD(JBLOCKARRAY, alloc_barray, (j_common_ptr cinfo, int pool_id,
  145807. JDIMENSION blocksperrow,
  145808. JDIMENSION numrows));
  145809. JMETHOD(jvirt_sarray_ptr, request_virt_sarray, (j_common_ptr cinfo,
  145810. int pool_id,
  145811. boolean pre_zero,
  145812. JDIMENSION samplesperrow,
  145813. JDIMENSION numrows,
  145814. JDIMENSION maxaccess));
  145815. JMETHOD(jvirt_barray_ptr, request_virt_barray, (j_common_ptr cinfo,
  145816. int pool_id,
  145817. boolean pre_zero,
  145818. JDIMENSION blocksperrow,
  145819. JDIMENSION numrows,
  145820. JDIMENSION maxaccess));
  145821. JMETHOD(void, realize_virt_arrays, (j_common_ptr cinfo));
  145822. JMETHOD(JSAMPARRAY, access_virt_sarray, (j_common_ptr cinfo,
  145823. jvirt_sarray_ptr ptr,
  145824. JDIMENSION start_row,
  145825. JDIMENSION num_rows,
  145826. boolean writable));
  145827. JMETHOD(JBLOCKARRAY, access_virt_barray, (j_common_ptr cinfo,
  145828. jvirt_barray_ptr ptr,
  145829. JDIMENSION start_row,
  145830. JDIMENSION num_rows,
  145831. boolean writable));
  145832. JMETHOD(void, free_pool, (j_common_ptr cinfo, int pool_id));
  145833. JMETHOD(void, self_destruct, (j_common_ptr cinfo));
  145834. long max_memory_to_use;
  145835. long max_alloc_chunk;
  145836. };
  145837. typedef JMETHOD(boolean, jpeg_marker_parser_method, (j_decompress_ptr cinfo));
  145838. #ifdef HAVE_PROTOTYPES
  145839. #define JPP(arglist) arglist
  145840. #else
  145841. #define JPP(arglist) ()
  145842. #endif
  145843. #ifdef NEED_SHORT_EXTERNAL_NAMES
  145844. #define jpeg_std_error jStdError
  145845. #define jpeg_CreateCompress jCreaCompress
  145846. #define jpeg_CreateDecompress jCreaDecompress
  145847. #define jpeg_destroy_compress jDestCompress
  145848. #define jpeg_destroy_decompress jDestDecompress
  145849. #define jpeg_stdio_dest jStdDest
  145850. #define jpeg_stdio_src jStdSrc
  145851. #define jpeg_set_defaults jSetDefaults
  145852. #define jpeg_set_colorspace jSetColorspace
  145853. #define jpeg_default_colorspace jDefColorspace
  145854. #define jpeg_set_quality jSetQuality
  145855. #define jpeg_set_linear_quality jSetLQuality
  145856. #define jpeg_add_quant_table jAddQuantTable
  145857. #define jpeg_quality_scaling jQualityScaling
  145858. #define jpeg_simple_progression jSimProgress
  145859. #define jpeg_suppress_tables jSuppressTables
  145860. #define jpeg_alloc_quant_table jAlcQTable
  145861. #define jpeg_alloc_huff_table jAlcHTable
  145862. #define jpeg_start_compress jStrtCompress
  145863. #define jpeg_write_scanlines jWrtScanlines
  145864. #define jpeg_finish_compress jFinCompress
  145865. #define jpeg_write_raw_data jWrtRawData
  145866. #define jpeg_write_marker jWrtMarker
  145867. #define jpeg_write_m_header jWrtMHeader
  145868. #define jpeg_write_m_byte jWrtMByte
  145869. #define jpeg_write_tables jWrtTables
  145870. #define jpeg_read_header jReadHeader
  145871. #define jpeg_start_decompress jStrtDecompress
  145872. #define jpeg_read_scanlines jReadScanlines
  145873. #define jpeg_finish_decompress jFinDecompress
  145874. #define jpeg_read_raw_data jReadRawData
  145875. #define jpeg_has_multiple_scans jHasMultScn
  145876. #define jpeg_start_output jStrtOutput
  145877. #define jpeg_finish_output jFinOutput
  145878. #define jpeg_input_complete jInComplete
  145879. #define jpeg_new_colormap jNewCMap
  145880. #define jpeg_consume_input jConsumeInput
  145881. #define jpeg_calc_output_dimensions jCalcDimensions
  145882. #define jpeg_save_markers jSaveMarkers
  145883. #define jpeg_set_marker_processor jSetMarker
  145884. #define jpeg_read_coefficients jReadCoefs
  145885. #define jpeg_write_coefficients jWrtCoefs
  145886. #define jpeg_copy_critical_parameters jCopyCrit
  145887. #define jpeg_abort_compress jAbrtCompress
  145888. #define jpeg_abort_decompress jAbrtDecompress
  145889. #define jpeg_abort jAbort
  145890. #define jpeg_destroy jDestroy
  145891. #define jpeg_resync_to_restart jResyncRestart
  145892. #endif /* NEED_SHORT_EXTERNAL_NAMES */
  145893. EXTERN(struct jpeg_error_mgr *) jpeg_std_error
  145894. JPP((struct jpeg_error_mgr * err));
  145895. #define jpeg_create_compress(cinfo) \
  145896. jpeg_CreateCompress((cinfo), JPEG_LIB_VERSION, \
  145897. (size_t) sizeof(struct jpeg_compress_struct))
  145898. #define jpeg_create_decompress(cinfo) \
  145899. jpeg_CreateDecompress((cinfo), JPEG_LIB_VERSION, \
  145900. (size_t) sizeof(struct jpeg_decompress_struct))
  145901. EXTERN(void) jpeg_CreateCompress JPP((j_compress_ptr cinfo,
  145902. int version, size_t structsize));
  145903. EXTERN(void) jpeg_CreateDecompress JPP((j_decompress_ptr cinfo,
  145904. int version, size_t structsize));
  145905. EXTERN(void) jpeg_destroy_compress JPP((j_compress_ptr cinfo));
  145906. EXTERN(void) jpeg_destroy_decompress JPP((j_decompress_ptr cinfo));
  145907. EXTERN(void) jpeg_stdio_dest JPP((j_compress_ptr cinfo, FILE * outfile));
  145908. EXTERN(void) jpeg_stdio_src JPP((j_decompress_ptr cinfo, FILE * infile));
  145909. EXTERN(void) jpeg_set_defaults JPP((j_compress_ptr cinfo));
  145910. EXTERN(void) jpeg_set_colorspace JPP((j_compress_ptr cinfo,
  145911. J_COLOR_SPACE colorspace));
  145912. EXTERN(void) jpeg_default_colorspace JPP((j_compress_ptr cinfo));
  145913. EXTERN(void) jpeg_set_quality JPP((j_compress_ptr cinfo, int quality,
  145914. boolean force_baseline));
  145915. EXTERN(void) jpeg_set_linear_quality JPP((j_compress_ptr cinfo,
  145916. int scale_factor,
  145917. boolean force_baseline));
  145918. EXTERN(void) jpeg_add_quant_table JPP((j_compress_ptr cinfo, int which_tbl,
  145919. const unsigned int *basic_table,
  145920. int scale_factor,
  145921. boolean force_baseline));
  145922. EXTERN(int) jpeg_quality_scaling JPP((int quality));
  145923. EXTERN(void) jpeg_simple_progression JPP((j_compress_ptr cinfo));
  145924. EXTERN(void) jpeg_suppress_tables JPP((j_compress_ptr cinfo,
  145925. boolean suppress));
  145926. EXTERN(JQUANT_TBL *) jpeg_alloc_quant_table JPP((j_common_ptr cinfo));
  145927. EXTERN(JHUFF_TBL *) jpeg_alloc_huff_table JPP((j_common_ptr cinfo));
  145928. EXTERN(void) jpeg_start_compress JPP((j_compress_ptr cinfo,
  145929. boolean write_all_tables));
  145930. EXTERN(JDIMENSION) jpeg_write_scanlines JPP((j_compress_ptr cinfo,
  145931. JSAMPARRAY scanlines,
  145932. JDIMENSION num_lines));
  145933. EXTERN(void) jpeg_finish_compress JPP((j_compress_ptr cinfo));
  145934. EXTERN(JDIMENSION) jpeg_write_raw_data JPP((j_compress_ptr cinfo,
  145935. JSAMPIMAGE data,
  145936. JDIMENSION num_lines));
  145937. EXTERN(void) jpeg_write_marker
  145938. JPP((j_compress_ptr cinfo, int marker,
  145939. const JOCTET * dataptr, unsigned int datalen));
  145940. EXTERN(void) jpeg_write_m_header
  145941. JPP((j_compress_ptr cinfo, int marker, unsigned int datalen));
  145942. EXTERN(void) jpeg_write_m_byte
  145943. JPP((j_compress_ptr cinfo, int val));
  145944. EXTERN(void) jpeg_write_tables JPP((j_compress_ptr cinfo));
  145945. EXTERN(int) jpeg_read_header JPP((j_decompress_ptr cinfo,
  145946. boolean require_image));
  145947. #define JPEG_SUSPENDED 0 /* Suspended due to lack of input data */
  145948. #define JPEG_HEADER_OK 1 /* Found valid image datastream */
  145949. #define JPEG_HEADER_TABLES_ONLY 2 /* Found valid table-specs-only datastream */
  145950. EXTERN(boolean) jpeg_start_decompress JPP((j_decompress_ptr cinfo));
  145951. EXTERN(JDIMENSION) jpeg_read_scanlines JPP((j_decompress_ptr cinfo,
  145952. JSAMPARRAY scanlines,
  145953. JDIMENSION max_lines));
  145954. EXTERN(boolean) jpeg_finish_decompress JPP((j_decompress_ptr cinfo));
  145955. EXTERN(JDIMENSION) jpeg_read_raw_data JPP((j_decompress_ptr cinfo,
  145956. JSAMPIMAGE data,
  145957. JDIMENSION max_lines));
  145958. EXTERN(boolean) jpeg_has_multiple_scans JPP((j_decompress_ptr cinfo));
  145959. EXTERN(boolean) jpeg_start_output JPP((j_decompress_ptr cinfo,
  145960. int scan_number));
  145961. EXTERN(boolean) jpeg_finish_output JPP((j_decompress_ptr cinfo));
  145962. EXTERN(boolean) jpeg_input_complete JPP((j_decompress_ptr cinfo));
  145963. EXTERN(void) jpeg_new_colormap JPP((j_decompress_ptr cinfo));
  145964. EXTERN(int) jpeg_consume_input JPP((j_decompress_ptr cinfo));
  145965. #define JPEG_REACHED_SOS 1 /* Reached start of new scan */
  145966. #define JPEG_REACHED_EOI 2 /* Reached end of image */
  145967. #define JPEG_ROW_COMPLETED 3 /* Completed one iMCU row */
  145968. #define JPEG_SCAN_COMPLETED 4 /* Completed last iMCU row of a scan */
  145969. EXTERN(void) jpeg_calc_output_dimensions JPP((j_decompress_ptr cinfo));
  145970. EXTERN(void) jpeg_save_markers
  145971. JPP((j_decompress_ptr cinfo, int marker_code,
  145972. unsigned int length_limit));
  145973. EXTERN(void) jpeg_set_marker_processor
  145974. JPP((j_decompress_ptr cinfo, int marker_code,
  145975. jpeg_marker_parser_method routine));
  145976. EXTERN(jvirt_barray_ptr *) jpeg_read_coefficients JPP((j_decompress_ptr cinfo));
  145977. EXTERN(void) jpeg_write_coefficients JPP((j_compress_ptr cinfo,
  145978. jvirt_barray_ptr * coef_arrays));
  145979. EXTERN(void) jpeg_copy_critical_parameters JPP((j_decompress_ptr srcinfo,
  145980. j_compress_ptr dstinfo));
  145981. EXTERN(void) jpeg_abort_compress JPP((j_compress_ptr cinfo));
  145982. EXTERN(void) jpeg_abort_decompress JPP((j_decompress_ptr cinfo));
  145983. EXTERN(void) jpeg_abort JPP((j_common_ptr cinfo));
  145984. EXTERN(void) jpeg_destroy JPP((j_common_ptr cinfo));
  145985. EXTERN(boolean) jpeg_resync_to_restart JPP((j_decompress_ptr cinfo,
  145986. int desired));
  145987. #define JPEG_RST0 0xD0 /* RST0 marker code */
  145988. #define JPEG_EOI 0xD9 /* EOI marker code */
  145989. #define JPEG_APP0 0xE0 /* APP0 marker code */
  145990. #define JPEG_COM 0xFE /* COM marker code */
  145991. #ifdef INCOMPLETE_TYPES_BROKEN
  145992. #ifndef JPEG_INTERNALS /* will be defined in jpegint.h */
  145993. struct jvirt_sarray_control { long dummy; };
  145994. struct jvirt_barray_control { long dummy; };
  145995. struct jpeg_comp_master { long dummy; };
  145996. struct jpeg_c_main_controller { long dummy; };
  145997. struct jpeg_c_prep_controller { long dummy; };
  145998. struct jpeg_c_coef_controller { long dummy; };
  145999. struct jpeg_marker_writer { long dummy; };
  146000. struct jpeg_color_converter { long dummy; };
  146001. struct jpeg_downsampler { long dummy; };
  146002. struct jpeg_forward_dct { long dummy; };
  146003. struct jpeg_entropy_encoder { long dummy; };
  146004. struct jpeg_decomp_master { long dummy; };
  146005. struct jpeg_d_main_controller { long dummy; };
  146006. struct jpeg_d_coef_controller { long dummy; };
  146007. struct jpeg_d_post_controller { long dummy; };
  146008. struct jpeg_input_controller { long dummy; };
  146009. struct jpeg_marker_reader { long dummy; };
  146010. struct jpeg_entropy_decoder { long dummy; };
  146011. struct jpeg_inverse_dct { long dummy; };
  146012. struct jpeg_upsampler { long dummy; };
  146013. struct jpeg_color_deconverter { long dummy; };
  146014. struct jpeg_color_quantizer { long dummy; };
  146015. #endif /* JPEG_INTERNALS */
  146016. #endif /* INCOMPLETE_TYPES_BROKEN */
  146017. #ifdef JPEG_INTERNALS
  146018. /********* Start of inlined file: jpegint.h *********/
  146019. typedef enum { /* Operating modes for buffer controllers */
  146020. JBUF_PASS_THRU, /* Plain stripwise operation */
  146021. JBUF_SAVE_SOURCE, /* Run source subobject only, save output */
  146022. JBUF_CRANK_DEST, /* Run dest subobject only, using saved data */
  146023. JBUF_SAVE_AND_PASS /* Run both subobjects, save output */
  146024. } J_BUF_MODE;
  146025. #define CSTATE_START 100 /* after create_compress */
  146026. #define CSTATE_SCANNING 101 /* start_compress done, write_scanlines OK */
  146027. #define CSTATE_RAW_OK 102 /* start_compress done, write_raw_data OK */
  146028. #define CSTATE_WRCOEFS 103 /* jpeg_write_coefficients done */
  146029. #define DSTATE_START 200 /* after create_decompress */
  146030. #define DSTATE_INHEADER 201 /* reading header markers, no SOS yet */
  146031. #define DSTATE_READY 202 /* found SOS, ready for start_decompress */
  146032. #define DSTATE_PRELOAD 203 /* reading multiscan file in start_decompress*/
  146033. #define DSTATE_PRESCAN 204 /* performing dummy pass for 2-pass quant */
  146034. #define DSTATE_SCANNING 205 /* start_decompress done, read_scanlines OK */
  146035. #define DSTATE_RAW_OK 206 /* start_decompress done, read_raw_data OK */
  146036. #define DSTATE_BUFIMAGE 207 /* expecting jpeg_start_output */
  146037. #define DSTATE_BUFPOST 208 /* looking for SOS/EOI in jpeg_finish_output */
  146038. #define DSTATE_RDCOEFS 209 /* reading file in jpeg_read_coefficients */
  146039. #define DSTATE_STOPPING 210 /* looking for EOI in jpeg_finish_decompress */
  146040. struct jpeg_comp_master {
  146041. JMETHOD(void, prepare_for_pass, (j_compress_ptr cinfo));
  146042. JMETHOD(void, pass_startup, (j_compress_ptr cinfo));
  146043. JMETHOD(void, finish_pass, (j_compress_ptr cinfo));
  146044. boolean call_pass_startup; /* True if pass_startup must be called */
  146045. boolean is_last_pass; /* True during last pass */
  146046. };
  146047. struct jpeg_c_main_controller {
  146048. JMETHOD(void, start_pass, (j_compress_ptr cinfo, J_BUF_MODE pass_mode));
  146049. JMETHOD(void, process_data, (j_compress_ptr cinfo,
  146050. JSAMPARRAY input_buf, JDIMENSION *in_row_ctr,
  146051. JDIMENSION in_rows_avail));
  146052. };
  146053. struct jpeg_c_prep_controller {
  146054. JMETHOD(void, start_pass, (j_compress_ptr cinfo, J_BUF_MODE pass_mode));
  146055. JMETHOD(void, pre_process_data, (j_compress_ptr cinfo,
  146056. JSAMPARRAY input_buf,
  146057. JDIMENSION *in_row_ctr,
  146058. JDIMENSION in_rows_avail,
  146059. JSAMPIMAGE output_buf,
  146060. JDIMENSION *out_row_group_ctr,
  146061. JDIMENSION out_row_groups_avail));
  146062. };
  146063. struct jpeg_c_coef_controller {
  146064. JMETHOD(void, start_pass, (j_compress_ptr cinfo, J_BUF_MODE pass_mode));
  146065. JMETHOD(boolean, compress_data, (j_compress_ptr cinfo,
  146066. JSAMPIMAGE input_buf));
  146067. };
  146068. struct jpeg_color_converter {
  146069. JMETHOD(void, start_pass, (j_compress_ptr cinfo));
  146070. JMETHOD(void, color_convert, (j_compress_ptr cinfo,
  146071. JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
  146072. JDIMENSION output_row, int num_rows));
  146073. };
  146074. struct jpeg_downsampler {
  146075. JMETHOD(void, start_pass, (j_compress_ptr cinfo));
  146076. JMETHOD(void, downsample, (j_compress_ptr cinfo,
  146077. JSAMPIMAGE input_buf, JDIMENSION in_row_index,
  146078. JSAMPIMAGE output_buf,
  146079. JDIMENSION out_row_group_index));
  146080. boolean need_context_rows; /* TRUE if need rows above & below */
  146081. };
  146082. struct jpeg_forward_dct {
  146083. JMETHOD(void, start_pass, (j_compress_ptr cinfo));
  146084. JMETHOD(void, forward_DCT, (j_compress_ptr cinfo,
  146085. jpeg_component_info * compptr,
  146086. JSAMPARRAY sample_data, JBLOCKROW coef_blocks,
  146087. JDIMENSION start_row, JDIMENSION start_col,
  146088. JDIMENSION num_blocks));
  146089. };
  146090. struct jpeg_entropy_encoder {
  146091. JMETHOD(void, start_pass, (j_compress_ptr cinfo, boolean gather_statistics));
  146092. JMETHOD(boolean, encode_mcu, (j_compress_ptr cinfo, JBLOCKROW *MCU_data));
  146093. JMETHOD(void, finish_pass, (j_compress_ptr cinfo));
  146094. };
  146095. struct jpeg_marker_writer {
  146096. JMETHOD(void, write_file_header, (j_compress_ptr cinfo));
  146097. JMETHOD(void, write_frame_header, (j_compress_ptr cinfo));
  146098. JMETHOD(void, write_scan_header, (j_compress_ptr cinfo));
  146099. JMETHOD(void, write_file_trailer, (j_compress_ptr cinfo));
  146100. JMETHOD(void, write_tables_only, (j_compress_ptr cinfo));
  146101. JMETHOD(void, write_marker_header, (j_compress_ptr cinfo, int marker,
  146102. unsigned int datalen));
  146103. JMETHOD(void, write_marker_byte, (j_compress_ptr cinfo, int val));
  146104. };
  146105. struct jpeg_decomp_master {
  146106. JMETHOD(void, prepare_for_output_pass, (j_decompress_ptr cinfo));
  146107. JMETHOD(void, finish_output_pass, (j_decompress_ptr cinfo));
  146108. boolean is_dummy_pass; /* True during 1st pass for 2-pass quant */
  146109. };
  146110. struct jpeg_input_controller {
  146111. JMETHOD(int, consume_input, (j_decompress_ptr cinfo));
  146112. JMETHOD(void, reset_input_controller, (j_decompress_ptr cinfo));
  146113. JMETHOD(void, start_input_pass, (j_decompress_ptr cinfo));
  146114. JMETHOD(void, finish_input_pass, (j_decompress_ptr cinfo));
  146115. boolean has_multiple_scans; /* True if file has multiple scans */
  146116. boolean eoi_reached; /* True when EOI has been consumed */
  146117. };
  146118. struct jpeg_d_main_controller {
  146119. JMETHOD(void, start_pass, (j_decompress_ptr cinfo, J_BUF_MODE pass_mode));
  146120. JMETHOD(void, process_data, (j_decompress_ptr cinfo,
  146121. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  146122. JDIMENSION out_rows_avail));
  146123. };
  146124. struct jpeg_d_coef_controller {
  146125. JMETHOD(void, start_input_pass, (j_decompress_ptr cinfo));
  146126. JMETHOD(int, consume_data, (j_decompress_ptr cinfo));
  146127. JMETHOD(void, start_output_pass, (j_decompress_ptr cinfo));
  146128. JMETHOD(int, decompress_data, (j_decompress_ptr cinfo,
  146129. JSAMPIMAGE output_buf));
  146130. jvirt_barray_ptr *coef_arrays;
  146131. };
  146132. struct jpeg_d_post_controller {
  146133. JMETHOD(void, start_pass, (j_decompress_ptr cinfo, J_BUF_MODE pass_mode));
  146134. JMETHOD(void, post_process_data, (j_decompress_ptr cinfo,
  146135. JSAMPIMAGE input_buf,
  146136. JDIMENSION *in_row_group_ctr,
  146137. JDIMENSION in_row_groups_avail,
  146138. JSAMPARRAY output_buf,
  146139. JDIMENSION *out_row_ctr,
  146140. JDIMENSION out_rows_avail));
  146141. };
  146142. struct jpeg_marker_reader {
  146143. JMETHOD(void, reset_marker_reader, (j_decompress_ptr cinfo));
  146144. JMETHOD(int, read_markers, (j_decompress_ptr cinfo));
  146145. jpeg_marker_parser_method read_restart_marker;
  146146. boolean saw_SOI; /* found SOI? */
  146147. boolean saw_SOF; /* found SOF? */
  146148. int next_restart_num; /* next restart number expected (0-7) */
  146149. unsigned int discarded_bytes; /* # of bytes skipped looking for a marker */
  146150. };
  146151. struct jpeg_entropy_decoder {
  146152. JMETHOD(void, start_pass, (j_decompress_ptr cinfo));
  146153. JMETHOD(boolean, decode_mcu, (j_decompress_ptr cinfo,
  146154. JBLOCKROW *MCU_data));
  146155. boolean insufficient_data; /* set TRUE after emitting warning */
  146156. };
  146157. typedef JMETHOD(void, inverse_DCT_method_ptr,
  146158. (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  146159. JCOEFPTR coef_block,
  146160. JSAMPARRAY output_buf, JDIMENSION output_col));
  146161. struct jpeg_inverse_dct {
  146162. JMETHOD(void, start_pass, (j_decompress_ptr cinfo));
  146163. inverse_DCT_method_ptr inverse_DCT[MAX_COMPONENTS];
  146164. };
  146165. struct jpeg_upsampler {
  146166. JMETHOD(void, start_pass, (j_decompress_ptr cinfo));
  146167. JMETHOD(void, upsample, (j_decompress_ptr cinfo,
  146168. JSAMPIMAGE input_buf,
  146169. JDIMENSION *in_row_group_ctr,
  146170. JDIMENSION in_row_groups_avail,
  146171. JSAMPARRAY output_buf,
  146172. JDIMENSION *out_row_ctr,
  146173. JDIMENSION out_rows_avail));
  146174. boolean need_context_rows; /* TRUE if need rows above & below */
  146175. };
  146176. struct jpeg_color_deconverter {
  146177. JMETHOD(void, start_pass, (j_decompress_ptr cinfo));
  146178. JMETHOD(void, color_convert, (j_decompress_ptr cinfo,
  146179. JSAMPIMAGE input_buf, JDIMENSION input_row,
  146180. JSAMPARRAY output_buf, int num_rows));
  146181. };
  146182. struct jpeg_color_quantizer {
  146183. JMETHOD(void, start_pass, (j_decompress_ptr cinfo, boolean is_pre_scan));
  146184. JMETHOD(void, color_quantize, (j_decompress_ptr cinfo,
  146185. JSAMPARRAY input_buf, JSAMPARRAY output_buf,
  146186. int num_rows));
  146187. JMETHOD(void, finish_pass, (j_decompress_ptr cinfo));
  146188. JMETHOD(void, new_color_map, (j_decompress_ptr cinfo));
  146189. };
  146190. #undef MAX
  146191. #define MAX(a,b) ((a) > (b) ? (a) : (b))
  146192. #undef MIN
  146193. #define MIN(a,b) ((a) < (b) ? (a) : (b))
  146194. #ifdef RIGHT_SHIFT_IS_UNSIGNED
  146195. #define SHIFT_TEMPS INT32 shift_temp;
  146196. #define RIGHT_SHIFT(x,shft) \
  146197. ((shift_temp = (x)) < 0 ? \
  146198. (shift_temp >> (shft)) | ((~((INT32) 0)) << (32-(shft))) : \
  146199. (shift_temp >> (shft)))
  146200. #else
  146201. #define SHIFT_TEMPS
  146202. #define RIGHT_SHIFT(x,shft) ((x) >> (shft))
  146203. #endif
  146204. #ifdef NEED_SHORT_EXTERNAL_NAMES
  146205. #define jinit_compress_master jICompress
  146206. #define jinit_c_master_control jICMaster
  146207. #define jinit_c_main_controller jICMainC
  146208. #define jinit_c_prep_controller jICPrepC
  146209. #define jinit_c_coef_controller jICCoefC
  146210. #define jinit_color_converter jICColor
  146211. #define jinit_downsampler jIDownsampler
  146212. #define jinit_forward_dct jIFDCT
  146213. #define jinit_huff_encoder jIHEncoder
  146214. #define jinit_phuff_encoder jIPHEncoder
  146215. #define jinit_marker_writer jIMWriter
  146216. #define jinit_master_decompress jIDMaster
  146217. #define jinit_d_main_controller jIDMainC
  146218. #define jinit_d_coef_controller jIDCoefC
  146219. #define jinit_d_post_controller jIDPostC
  146220. #define jinit_input_controller jIInCtlr
  146221. #define jinit_marker_reader jIMReader
  146222. #define jinit_huff_decoder jIHDecoder
  146223. #define jinit_phuff_decoder jIPHDecoder
  146224. #define jinit_inverse_dct jIIDCT
  146225. #define jinit_upsampler jIUpsampler
  146226. #define jinit_color_deconverter jIDColor
  146227. #define jinit_1pass_quantizer jI1Quant
  146228. #define jinit_2pass_quantizer jI2Quant
  146229. #define jinit_merged_upsampler jIMUpsampler
  146230. #define jinit_memory_mgr jIMemMgr
  146231. #define jdiv_round_up jDivRound
  146232. #define jround_up jRound
  146233. #define jcopy_sample_rows jCopySamples
  146234. #define jcopy_block_row jCopyBlocks
  146235. #define jzero_far jZeroFar
  146236. #define jpeg_zigzag_order jZIGTable
  146237. #define jpeg_natural_order jZAGTable
  146238. #endif /* NEED_SHORT_EXTERNAL_NAMES */
  146239. EXTERN(void) jinit_compress_master JPP((j_compress_ptr cinfo));
  146240. EXTERN(void) jinit_c_master_control JPP((j_compress_ptr cinfo,
  146241. boolean transcode_only));
  146242. EXTERN(void) jinit_c_main_controller JPP((j_compress_ptr cinfo,
  146243. boolean need_full_buffer));
  146244. EXTERN(void) jinit_c_prep_controller JPP((j_compress_ptr cinfo,
  146245. boolean need_full_buffer));
  146246. EXTERN(void) jinit_c_coef_controller JPP((j_compress_ptr cinfo,
  146247. boolean need_full_buffer));
  146248. EXTERN(void) jinit_color_converter JPP((j_compress_ptr cinfo));
  146249. EXTERN(void) jinit_downsampler JPP((j_compress_ptr cinfo));
  146250. EXTERN(void) jinit_forward_dct JPP((j_compress_ptr cinfo));
  146251. EXTERN(void) jinit_huff_encoder JPP((j_compress_ptr cinfo));
  146252. EXTERN(void) jinit_phuff_encoder JPP((j_compress_ptr cinfo));
  146253. EXTERN(void) jinit_marker_writer JPP((j_compress_ptr cinfo));
  146254. EXTERN(void) jinit_master_decompress JPP((j_decompress_ptr cinfo));
  146255. EXTERN(void) jinit_d_main_controller JPP((j_decompress_ptr cinfo,
  146256. boolean need_full_buffer));
  146257. EXTERN(void) jinit_d_coef_controller JPP((j_decompress_ptr cinfo,
  146258. boolean need_full_buffer));
  146259. EXTERN(void) jinit_d_post_controller JPP((j_decompress_ptr cinfo,
  146260. boolean need_full_buffer));
  146261. EXTERN(void) jinit_input_controller JPP((j_decompress_ptr cinfo));
  146262. EXTERN(void) jinit_marker_reader JPP((j_decompress_ptr cinfo));
  146263. EXTERN(void) jinit_huff_decoder JPP((j_decompress_ptr cinfo));
  146264. EXTERN(void) jinit_phuff_decoder JPP((j_decompress_ptr cinfo));
  146265. EXTERN(void) jinit_inverse_dct JPP((j_decompress_ptr cinfo));
  146266. EXTERN(void) jinit_upsampler JPP((j_decompress_ptr cinfo));
  146267. EXTERN(void) jinit_color_deconverter JPP((j_decompress_ptr cinfo));
  146268. EXTERN(void) jinit_1pass_quantizer JPP((j_decompress_ptr cinfo));
  146269. EXTERN(void) jinit_2pass_quantizer JPP((j_decompress_ptr cinfo));
  146270. EXTERN(void) jinit_merged_upsampler JPP((j_decompress_ptr cinfo));
  146271. EXTERN(void) jinit_memory_mgr JPP((j_common_ptr cinfo));
  146272. EXTERN(long) jdiv_round_up JPP((long a, long b));
  146273. EXTERN(long) jround_up JPP((long a, long b));
  146274. EXTERN(void) jcopy_sample_rows JPP((JSAMPARRAY input_array, int source_row,
  146275. JSAMPARRAY output_array, int dest_row,
  146276. int num_rows, JDIMENSION num_cols));
  146277. EXTERN(void) jcopy_block_row JPP((JBLOCKROW input_row, JBLOCKROW output_row,
  146278. JDIMENSION num_blocks));
  146279. EXTERN(void) jzero_far JPP((void FAR * target, size_t bytestozero));
  146280. #if 0 /* This table is not actually needed in v6a */
  146281. extern const int jpeg_zigzag_order[]; /* natural coef order to zigzag order */
  146282. #endif
  146283. extern const int jpeg_natural_order[]; /* zigzag coef order to natural order */
  146284. #ifdef INCOMPLETE_TYPES_BROKEN
  146285. #ifndef AM_MEMORY_MANAGER /* only jmemmgr.c defines these */
  146286. struct jvirt_sarray_control { long dummy; };
  146287. struct jvirt_barray_control { long dummy; };
  146288. #endif
  146289. #endif /* INCOMPLETE_TYPES_BROKEN */
  146290. /********* End of inlined file: jpegint.h *********/
  146291. /********* Start of inlined file: jerror.h *********/
  146292. #ifndef JMESSAGE
  146293. #ifndef JERROR_H
  146294. #define JMAKE_ENUM_LIST
  146295. #else
  146296. #define JMESSAGE(code,string)
  146297. #endif /* JERROR_H */
  146298. #endif /* JMESSAGE */
  146299. #ifdef JMAKE_ENUM_LIST
  146300. typedef enum {
  146301. #define JMESSAGE(code,string) code ,
  146302. #endif /* JMAKE_ENUM_LIST */
  146303. JMESSAGE(JMSG_NOMESSAGE, "Bogus message code %d") /* Must be first entry! */
  146304. JMESSAGE(JERR_ARITH_NOTIMPL,
  146305. "Sorry, there are legal restrictions on arithmetic coding")
  146306. JMESSAGE(JERR_BAD_ALIGN_TYPE, "ALIGN_TYPE is wrong, please fix")
  146307. JMESSAGE(JERR_BAD_ALLOC_CHUNK, "MAX_ALLOC_CHUNK is wrong, please fix")
  146308. JMESSAGE(JERR_BAD_BUFFER_MODE, "Bogus buffer control mode")
  146309. JMESSAGE(JERR_BAD_COMPONENT_ID, "Invalid component ID %d in SOS")
  146310. JMESSAGE(JERR_BAD_DCT_COEF, "DCT coefficient out of range")
  146311. JMESSAGE(JERR_BAD_DCTSIZE, "IDCT output block size %d not supported")
  146312. JMESSAGE(JERR_BAD_HUFF_TABLE, "Bogus Huffman table definition")
  146313. JMESSAGE(JERR_BAD_IN_COLORSPACE, "Bogus input colorspace")
  146314. JMESSAGE(JERR_BAD_J_COLORSPACE, "Bogus JPEG colorspace")
  146315. JMESSAGE(JERR_BAD_LENGTH, "Bogus marker length")
  146316. JMESSAGE(JERR_BAD_LIB_VERSION,
  146317. "Wrong JPEG library version: library is %d, caller expects %d")
  146318. JMESSAGE(JERR_BAD_MCU_SIZE, "Sampling factors too large for interleaved scan")
  146319. JMESSAGE(JERR_BAD_POOL_ID, "Invalid memory pool code %d")
  146320. JMESSAGE(JERR_BAD_PRECISION, "Unsupported JPEG data precision %d")
  146321. JMESSAGE(JERR_BAD_PROGRESSION,
  146322. "Invalid progressive parameters Ss=%d Se=%d Ah=%d Al=%d")
  146323. JMESSAGE(JERR_BAD_PROG_SCRIPT,
  146324. "Invalid progressive parameters at scan script entry %d")
  146325. JMESSAGE(JERR_BAD_SAMPLING, "Bogus sampling factors")
  146326. JMESSAGE(JERR_BAD_SCAN_SCRIPT, "Invalid scan script at entry %d")
  146327. JMESSAGE(JERR_BAD_STATE, "Improper call to JPEG library in state %d")
  146328. JMESSAGE(JERR_BAD_STRUCT_SIZE,
  146329. "JPEG parameter struct mismatch: library thinks size is %u, caller expects %u")
  146330. JMESSAGE(JERR_BAD_VIRTUAL_ACCESS, "Bogus virtual array access")
  146331. JMESSAGE(JERR_BUFFER_SIZE, "Buffer passed to JPEG library is too small")
  146332. JMESSAGE(JERR_CANT_SUSPEND, "Suspension not allowed here")
  146333. JMESSAGE(JERR_CCIR601_NOTIMPL, "CCIR601 sampling not implemented yet")
  146334. JMESSAGE(JERR_COMPONENT_COUNT, "Too many color components: %d, max %d")
  146335. JMESSAGE(JERR_CONVERSION_NOTIMPL, "Unsupported color conversion request")
  146336. JMESSAGE(JERR_DAC_INDEX, "Bogus DAC index %d")
  146337. JMESSAGE(JERR_DAC_VALUE, "Bogus DAC value 0x%x")
  146338. JMESSAGE(JERR_DHT_INDEX, "Bogus DHT index %d")
  146339. JMESSAGE(JERR_DQT_INDEX, "Bogus DQT index %d")
  146340. JMESSAGE(JERR_EMPTY_IMAGE, "Empty JPEG image (DNL not supported)")
  146341. JMESSAGE(JERR_EMS_READ, "Read from EMS failed")
  146342. JMESSAGE(JERR_EMS_WRITE, "Write to EMS failed")
  146343. JMESSAGE(JERR_EOI_EXPECTED, "Didn't expect more than one scan")
  146344. JMESSAGE(JERR_FILE_READ, "Input file read error")
  146345. JMESSAGE(JERR_FILE_WRITE, "Output file write error --- out of disk space?")
  146346. JMESSAGE(JERR_FRACT_SAMPLE_NOTIMPL, "Fractional sampling not implemented yet")
  146347. JMESSAGE(JERR_HUFF_CLEN_OVERFLOW, "Huffman code size table overflow")
  146348. JMESSAGE(JERR_HUFF_MISSING_CODE, "Missing Huffman code table entry")
  146349. JMESSAGE(JERR_IMAGE_TOO_BIG, "Maximum supported image dimension is %u pixels")
  146350. JMESSAGE(JERR_INPUT_EMPTY, "Empty input file")
  146351. JMESSAGE(JERR_INPUT_EOF, "Premature end of input file")
  146352. JMESSAGE(JERR_MISMATCHED_QUANT_TABLE,
  146353. "Cannot transcode due to multiple use of quantization table %d")
  146354. JMESSAGE(JERR_MISSING_DATA, "Scan script does not transmit all data")
  146355. JMESSAGE(JERR_MODE_CHANGE, "Invalid color quantization mode change")
  146356. JMESSAGE(JERR_NOTIMPL, "Not implemented yet")
  146357. JMESSAGE(JERR_NOT_COMPILED, "Requested feature was omitted at compile time")
  146358. JMESSAGE(JERR_NO_BACKING_STORE, "Backing store not supported")
  146359. JMESSAGE(JERR_NO_HUFF_TABLE, "Huffman table 0x%02x was not defined")
  146360. JMESSAGE(JERR_NO_IMAGE, "JPEG datastream contains no image")
  146361. JMESSAGE(JERR_NO_QUANT_TABLE, "Quantization table 0x%02x was not defined")
  146362. JMESSAGE(JERR_NO_SOI, "Not a JPEG file: starts with 0x%02x 0x%02x")
  146363. JMESSAGE(JERR_OUT_OF_MEMORY, "Insufficient memory (case %d)")
  146364. JMESSAGE(JERR_QUANT_COMPONENTS,
  146365. "Cannot quantize more than %d color components")
  146366. JMESSAGE(JERR_QUANT_FEW_COLORS, "Cannot quantize to fewer than %d colors")
  146367. JMESSAGE(JERR_QUANT_MANY_COLORS, "Cannot quantize to more than %d colors")
  146368. JMESSAGE(JERR_SOF_DUPLICATE, "Invalid JPEG file structure: two SOF markers")
  146369. JMESSAGE(JERR_SOF_NO_SOS, "Invalid JPEG file structure: missing SOS marker")
  146370. JMESSAGE(JERR_SOF_UNSUPPORTED, "Unsupported JPEG process: SOF type 0x%02x")
  146371. JMESSAGE(JERR_SOI_DUPLICATE, "Invalid JPEG file structure: two SOI markers")
  146372. JMESSAGE(JERR_SOS_NO_SOF, "Invalid JPEG file structure: SOS before SOF")
  146373. JMESSAGE(JERR_TFILE_CREATE, "Failed to create temporary file %s")
  146374. JMESSAGE(JERR_TFILE_READ, "Read failed on temporary file")
  146375. JMESSAGE(JERR_TFILE_SEEK, "Seek failed on temporary file")
  146376. JMESSAGE(JERR_TFILE_WRITE,
  146377. "Write failed on temporary file --- out of disk space?")
  146378. JMESSAGE(JERR_TOO_LITTLE_DATA, "Application transferred too few scanlines")
  146379. JMESSAGE(JERR_UNKNOWN_MARKER, "Unsupported marker type 0x%02x")
  146380. JMESSAGE(JERR_VIRTUAL_BUG, "Virtual array controller messed up")
  146381. JMESSAGE(JERR_WIDTH_OVERFLOW, "Image too wide for this implementation")
  146382. JMESSAGE(JERR_XMS_READ, "Read from XMS failed")
  146383. JMESSAGE(JERR_XMS_WRITE, "Write to XMS failed")
  146384. JMESSAGE(JMSG_COPYRIGHT, JCOPYRIGHT)
  146385. JMESSAGE(JMSG_VERSION, JVERSION)
  146386. JMESSAGE(JTRC_16BIT_TABLES,
  146387. "Caution: quantization tables are too coarse for baseline JPEG")
  146388. JMESSAGE(JTRC_ADOBE,
  146389. "Adobe APP14 marker: version %d, flags 0x%04x 0x%04x, transform %d")
  146390. JMESSAGE(JTRC_APP0, "Unknown APP0 marker (not JFIF), length %u")
  146391. JMESSAGE(JTRC_APP14, "Unknown APP14 marker (not Adobe), length %u")
  146392. JMESSAGE(JTRC_DAC, "Define Arithmetic Table 0x%02x: 0x%02x")
  146393. JMESSAGE(JTRC_DHT, "Define Huffman Table 0x%02x")
  146394. JMESSAGE(JTRC_DQT, "Define Quantization Table %d precision %d")
  146395. JMESSAGE(JTRC_DRI, "Define Restart Interval %u")
  146396. JMESSAGE(JTRC_EMS_CLOSE, "Freed EMS handle %u")
  146397. JMESSAGE(JTRC_EMS_OPEN, "Obtained EMS handle %u")
  146398. JMESSAGE(JTRC_EOI, "End Of Image")
  146399. JMESSAGE(JTRC_HUFFBITS, " %3d %3d %3d %3d %3d %3d %3d %3d")
  146400. JMESSAGE(JTRC_JFIF, "JFIF APP0 marker: version %d.%02d, density %dx%d %d")
  146401. JMESSAGE(JTRC_JFIF_BADTHUMBNAILSIZE,
  146402. "Warning: thumbnail image size does not match data length %u")
  146403. JMESSAGE(JTRC_JFIF_EXTENSION,
  146404. "JFIF extension marker: type 0x%02x, length %u")
  146405. JMESSAGE(JTRC_JFIF_THUMBNAIL, " with %d x %d thumbnail image")
  146406. JMESSAGE(JTRC_MISC_MARKER, "Miscellaneous marker 0x%02x, length %u")
  146407. JMESSAGE(JTRC_PARMLESS_MARKER, "Unexpected marker 0x%02x")
  146408. JMESSAGE(JTRC_QUANTVALS, " %4u %4u %4u %4u %4u %4u %4u %4u")
  146409. JMESSAGE(JTRC_QUANT_3_NCOLORS, "Quantizing to %d = %d*%d*%d colors")
  146410. JMESSAGE(JTRC_QUANT_NCOLORS, "Quantizing to %d colors")
  146411. JMESSAGE(JTRC_QUANT_SELECTED, "Selected %d colors for quantization")
  146412. JMESSAGE(JTRC_RECOVERY_ACTION, "At marker 0x%02x, recovery action %d")
  146413. JMESSAGE(JTRC_RST, "RST%d")
  146414. JMESSAGE(JTRC_SMOOTH_NOTIMPL,
  146415. "Smoothing not supported with nonstandard sampling ratios")
  146416. JMESSAGE(JTRC_SOF, "Start Of Frame 0x%02x: width=%u, height=%u, components=%d")
  146417. JMESSAGE(JTRC_SOF_COMPONENT, " Component %d: %dhx%dv q=%d")
  146418. JMESSAGE(JTRC_SOI, "Start of Image")
  146419. JMESSAGE(JTRC_SOS, "Start Of Scan: %d components")
  146420. JMESSAGE(JTRC_SOS_COMPONENT, " Component %d: dc=%d ac=%d")
  146421. JMESSAGE(JTRC_SOS_PARAMS, " Ss=%d, Se=%d, Ah=%d, Al=%d")
  146422. JMESSAGE(JTRC_TFILE_CLOSE, "Closed temporary file %s")
  146423. JMESSAGE(JTRC_TFILE_OPEN, "Opened temporary file %s")
  146424. JMESSAGE(JTRC_THUMB_JPEG,
  146425. "JFIF extension marker: JPEG-compressed thumbnail image, length %u")
  146426. JMESSAGE(JTRC_THUMB_PALETTE,
  146427. "JFIF extension marker: palette thumbnail image, length %u")
  146428. JMESSAGE(JTRC_THUMB_RGB,
  146429. "JFIF extension marker: RGB thumbnail image, length %u")
  146430. JMESSAGE(JTRC_UNKNOWN_IDS,
  146431. "Unrecognized component IDs %d %d %d, assuming YCbCr")
  146432. JMESSAGE(JTRC_XMS_CLOSE, "Freed XMS handle %u")
  146433. JMESSAGE(JTRC_XMS_OPEN, "Obtained XMS handle %u")
  146434. JMESSAGE(JWRN_ADOBE_XFORM, "Unknown Adobe color transform code %d")
  146435. JMESSAGE(JWRN_BOGUS_PROGRESSION,
  146436. "Inconsistent progression sequence for component %d coefficient %d")
  146437. JMESSAGE(JWRN_EXTRANEOUS_DATA,
  146438. "Corrupt JPEG data: %u extraneous bytes before marker 0x%02x")
  146439. JMESSAGE(JWRN_HIT_MARKER, "Corrupt JPEG data: premature end of data segment")
  146440. JMESSAGE(JWRN_HUFF_BAD_CODE, "Corrupt JPEG data: bad Huffman code")
  146441. JMESSAGE(JWRN_JFIF_MAJOR, "Warning: unknown JFIF revision number %d.%02d")
  146442. JMESSAGE(JWRN_JPEG_EOF, "Premature end of JPEG file")
  146443. JMESSAGE(JWRN_MUST_RESYNC,
  146444. "Corrupt JPEG data: found marker 0x%02x instead of RST%d")
  146445. JMESSAGE(JWRN_NOT_SEQUENTIAL, "Invalid SOS parameters for sequential JPEG")
  146446. JMESSAGE(JWRN_TOO_MUCH_DATA, "Application transferred too many scanlines")
  146447. #ifdef JMAKE_ENUM_LIST
  146448. JMSG_LASTMSGCODE
  146449. } J_MESSAGE_CODE;
  146450. #undef JMAKE_ENUM_LIST
  146451. #endif /* JMAKE_ENUM_LIST */
  146452. #undef JMESSAGE
  146453. #ifndef JERROR_H
  146454. #define JERROR_H
  146455. #define ERREXIT(cinfo,code) \
  146456. ((cinfo)->err->msg_code = (code), \
  146457. (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
  146458. #define ERREXIT1(cinfo,code,p1) \
  146459. ((cinfo)->err->msg_code = (code), \
  146460. (cinfo)->err->msg_parm.i[0] = (p1), \
  146461. (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
  146462. #define ERREXIT2(cinfo,code,p1,p2) \
  146463. ((cinfo)->err->msg_code = (code), \
  146464. (cinfo)->err->msg_parm.i[0] = (p1), \
  146465. (cinfo)->err->msg_parm.i[1] = (p2), \
  146466. (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
  146467. #define ERREXIT3(cinfo,code,p1,p2,p3) \
  146468. ((cinfo)->err->msg_code = (code), \
  146469. (cinfo)->err->msg_parm.i[0] = (p1), \
  146470. (cinfo)->err->msg_parm.i[1] = (p2), \
  146471. (cinfo)->err->msg_parm.i[2] = (p3), \
  146472. (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
  146473. #define ERREXIT4(cinfo,code,p1,p2,p3,p4) \
  146474. ((cinfo)->err->msg_code = (code), \
  146475. (cinfo)->err->msg_parm.i[0] = (p1), \
  146476. (cinfo)->err->msg_parm.i[1] = (p2), \
  146477. (cinfo)->err->msg_parm.i[2] = (p3), \
  146478. (cinfo)->err->msg_parm.i[3] = (p4), \
  146479. (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
  146480. #define ERREXITS(cinfo,code,str) \
  146481. ((cinfo)->err->msg_code = (code), \
  146482. strncpy((cinfo)->err->msg_parm.s, (str), JMSG_STR_PARM_MAX), \
  146483. (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
  146484. #define MAKESTMT(stuff) do { stuff } while (0)
  146485. #define WARNMS(cinfo,code) \
  146486. ((cinfo)->err->msg_code = (code), \
  146487. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), -1))
  146488. #define WARNMS1(cinfo,code,p1) \
  146489. ((cinfo)->err->msg_code = (code), \
  146490. (cinfo)->err->msg_parm.i[0] = (p1), \
  146491. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), -1))
  146492. #define WARNMS2(cinfo,code,p1,p2) \
  146493. ((cinfo)->err->msg_code = (code), \
  146494. (cinfo)->err->msg_parm.i[0] = (p1), \
  146495. (cinfo)->err->msg_parm.i[1] = (p2), \
  146496. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), -1))
  146497. #define TRACEMS(cinfo,lvl,code) \
  146498. ((cinfo)->err->msg_code = (code), \
  146499. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)))
  146500. #define TRACEMS1(cinfo,lvl,code,p1) \
  146501. ((cinfo)->err->msg_code = (code), \
  146502. (cinfo)->err->msg_parm.i[0] = (p1), \
  146503. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)))
  146504. #define TRACEMS2(cinfo,lvl,code,p1,p2) \
  146505. ((cinfo)->err->msg_code = (code), \
  146506. (cinfo)->err->msg_parm.i[0] = (p1), \
  146507. (cinfo)->err->msg_parm.i[1] = (p2), \
  146508. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)))
  146509. #define TRACEMS3(cinfo,lvl,code,p1,p2,p3) \
  146510. MAKESTMT(int * _mp = (cinfo)->err->msg_parm.i; \
  146511. _mp[0] = (p1); _mp[1] = (p2); _mp[2] = (p3); \
  146512. (cinfo)->err->msg_code = (code); \
  146513. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)); )
  146514. #define TRACEMS4(cinfo,lvl,code,p1,p2,p3,p4) \
  146515. MAKESTMT(int * _mp = (cinfo)->err->msg_parm.i; \
  146516. _mp[0] = (p1); _mp[1] = (p2); _mp[2] = (p3); _mp[3] = (p4); \
  146517. (cinfo)->err->msg_code = (code); \
  146518. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)); )
  146519. #define TRACEMS5(cinfo,lvl,code,p1,p2,p3,p4,p5) \
  146520. MAKESTMT(int * _mp = (cinfo)->err->msg_parm.i; \
  146521. _mp[0] = (p1); _mp[1] = (p2); _mp[2] = (p3); _mp[3] = (p4); \
  146522. _mp[4] = (p5); \
  146523. (cinfo)->err->msg_code = (code); \
  146524. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)); )
  146525. #define TRACEMS8(cinfo,lvl,code,p1,p2,p3,p4,p5,p6,p7,p8) \
  146526. MAKESTMT(int * _mp = (cinfo)->err->msg_parm.i; \
  146527. _mp[0] = (p1); _mp[1] = (p2); _mp[2] = (p3); _mp[3] = (p4); \
  146528. _mp[4] = (p5); _mp[5] = (p6); _mp[6] = (p7); _mp[7] = (p8); \
  146529. (cinfo)->err->msg_code = (code); \
  146530. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)); )
  146531. #define TRACEMSS(cinfo,lvl,code,str) \
  146532. ((cinfo)->err->msg_code = (code), \
  146533. strncpy((cinfo)->err->msg_parm.s, (str), JMSG_STR_PARM_MAX), \
  146534. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)))
  146535. #endif /* JERROR_H */
  146536. /********* End of inlined file: jerror.h *********/
  146537. #endif
  146538. #endif /* JPEGLIB_H */
  146539. /********* End of inlined file: jpeglib.h *********/
  146540. /********* Start of inlined file: jcapimin.c *********/
  146541. #define JPEG_INTERNALS
  146542. /********* Start of inlined file: jinclude.h *********/
  146543. #ifndef __jinclude_h__
  146544. #define __jinclude_h__
  146545. /********* Start of inlined file: jconfig.h *********/
  146546. // disable all the warnings under MSVC
  146547. #ifdef _MSC_VER
  146548. #pragma warning (disable: 4996 4267 4100 4127 4702 4244)
  146549. #endif
  146550. #ifdef __BORLANDC__
  146551. #pragma warn -8057
  146552. #pragma warn -8019
  146553. #pragma warn -8004
  146554. #pragma warn -8008
  146555. #endif
  146556. #define HAVE_PROTOTYPES
  146557. #define HAVE_UNSIGNED_CHAR
  146558. #define HAVE_UNSIGNED_SHORT
  146559. #undef CHAR_IS_UNSIGNED
  146560. #define HAVE_STDDEF_H
  146561. #define HAVE_STDLIB_H
  146562. #undef NEED_BSD_STRINGS
  146563. #undef NEED_SYS_TYPES_H
  146564. #undef NEED_FAR_POINTERS /* we presume a 32-bit flat memory model */
  146565. #undef NEED_SHORT_EXTERNAL_NAMES
  146566. #undef INCOMPLETE_TYPES_BROKEN
  146567. #ifndef __RPCNDR_H__ /* don't conflict if rpcndr.h already read */
  146568. typedef unsigned char boolean;
  146569. #endif
  146570. #define HAVE_BOOLEAN /* prevent jmorecfg.h from redefining it */
  146571. #ifdef JPEG_INTERNALS
  146572. #undef RIGHT_SHIFT_IS_UNSIGNED
  146573. #endif /* JPEG_INTERNALS */
  146574. #ifdef JPEG_CJPEG_DJPEG
  146575. #define BMP_SUPPORTED /* BMP image file format */
  146576. #define GIF_SUPPORTED /* GIF image file format */
  146577. #define PPM_SUPPORTED /* PBMPLUS PPM/PGM image file format */
  146578. #undef RLE_SUPPORTED /* Utah RLE image file format */
  146579. #define TARGA_SUPPORTED /* Targa image file format */
  146580. #define TWO_FILE_COMMANDLINE /* optional */
  146581. #define USE_SETMODE /* Microsoft has setmode() */
  146582. #undef NEED_SIGNAL_CATCHER
  146583. #undef DONT_USE_B_MODE
  146584. #undef PROGRESS_REPORT /* optional */
  146585. #endif /* JPEG_CJPEG_DJPEG */
  146586. /********* End of inlined file: jconfig.h *********/
  146587. #define JCONFIG_INCLUDED /* so that jpeglib.h doesn't do it again */
  146588. #ifdef HAVE_STDDEF_H
  146589. #include <stddef.h>
  146590. #endif
  146591. #ifdef HAVE_STDLIB_H
  146592. #include <stdlib.h>
  146593. #endif
  146594. #ifdef NEED_SYS_TYPES_H
  146595. #include <sys/types.h>
  146596. #endif
  146597. #include <stdio.h>
  146598. #ifdef NEED_BSD_STRINGS
  146599. #include <strings.h>
  146600. #define MEMZERO(target,size) bzero((void *)(target), (size_t)(size))
  146601. #define MEMCOPY(dest,src,size) bcopy((const void *)(src), (void *)(dest), (size_t)(size))
  146602. #else /* not BSD, assume ANSI/SysV string lib */
  146603. #include <string.h>
  146604. #define MEMZERO(target,size) memset((void *)(target), 0, (size_t)(size))
  146605. #define MEMCOPY(dest,src,size) memcpy((void *)(dest), (const void *)(src), (size_t)(size))
  146606. #endif
  146607. #define SIZEOF(object) ((size_t) sizeof(object))
  146608. #define JFREAD(file,buf,sizeofbuf) \
  146609. ((size_t) fread((void *) (buf), (size_t) 1, (size_t) (sizeofbuf), (file)))
  146610. #define JFWRITE(file,buf,sizeofbuf) \
  146611. ((size_t) fwrite((const void *) (buf), (size_t) 1, (size_t) (sizeofbuf), (file)))
  146612. typedef enum { /* JPEG marker codes */
  146613. M_SOF0 = 0xc0,
  146614. M_SOF1 = 0xc1,
  146615. M_SOF2 = 0xc2,
  146616. M_SOF3 = 0xc3,
  146617. M_SOF5 = 0xc5,
  146618. M_SOF6 = 0xc6,
  146619. M_SOF7 = 0xc7,
  146620. M_JPG = 0xc8,
  146621. M_SOF9 = 0xc9,
  146622. M_SOF10 = 0xca,
  146623. M_SOF11 = 0xcb,
  146624. M_SOF13 = 0xcd,
  146625. M_SOF14 = 0xce,
  146626. M_SOF15 = 0xcf,
  146627. M_DHT = 0xc4,
  146628. M_DAC = 0xcc,
  146629. M_RST0 = 0xd0,
  146630. M_RST1 = 0xd1,
  146631. M_RST2 = 0xd2,
  146632. M_RST3 = 0xd3,
  146633. M_RST4 = 0xd4,
  146634. M_RST5 = 0xd5,
  146635. M_RST6 = 0xd6,
  146636. M_RST7 = 0xd7,
  146637. M_SOI = 0xd8,
  146638. M_EOI = 0xd9,
  146639. M_SOS = 0xda,
  146640. M_DQT = 0xdb,
  146641. M_DNL = 0xdc,
  146642. M_DRI = 0xdd,
  146643. M_DHP = 0xde,
  146644. M_EXP = 0xdf,
  146645. M_APP0 = 0xe0,
  146646. M_APP1 = 0xe1,
  146647. M_APP2 = 0xe2,
  146648. M_APP3 = 0xe3,
  146649. M_APP4 = 0xe4,
  146650. M_APP5 = 0xe5,
  146651. M_APP6 = 0xe6,
  146652. M_APP7 = 0xe7,
  146653. M_APP8 = 0xe8,
  146654. M_APP9 = 0xe9,
  146655. M_APP10 = 0xea,
  146656. M_APP11 = 0xeb,
  146657. M_APP12 = 0xec,
  146658. M_APP13 = 0xed,
  146659. M_APP14 = 0xee,
  146660. M_APP15 = 0xef,
  146661. M_JPG0 = 0xf0,
  146662. M_JPG13 = 0xfd,
  146663. M_COM = 0xfe,
  146664. M_TEM = 0x01,
  146665. M_ERROR = 0x100
  146666. } JPEG_MARKER;
  146667. #ifdef AVOID_TABLES
  146668. #define HUFF_EXTEND(x,s) ((x) < (1<<((s)-1)) ? (x) + (((-1)<<(s)) + 1) : (x))
  146669. #else
  146670. #define HUFF_EXTEND(x,s) ((x) < extend_test[s] ? (x) + extend_offset[s] : (x))
  146671. static const int extend_test[16] = /* entry n is 2**(n-1) */
  146672. { 0, 0x0001, 0x0002, 0x0004, 0x0008, 0x0010, 0x0020, 0x0040, 0x0080,
  146673. 0x0100, 0x0200, 0x0400, 0x0800, 0x1000, 0x2000, 0x4000 };
  146674. static const int extend_offset[16] = /* entry n is (-1 << n) + 1 */
  146675. { 0, ((-1)<<1) + 1, ((-1)<<2) + 1, ((-1)<<3) + 1, ((-1)<<4) + 1,
  146676. ((-1)<<5) + 1, ((-1)<<6) + 1, ((-1)<<7) + 1, ((-1)<<8) + 1,
  146677. ((-1)<<9) + 1, ((-1)<<10) + 1, ((-1)<<11) + 1, ((-1)<<12) + 1,
  146678. ((-1)<<13) + 1, ((-1)<<14) + 1, ((-1)<<15) + 1 };
  146679. #endif /* AVOID_TABLES */
  146680. #endif
  146681. /********* End of inlined file: jinclude.h *********/
  146682. GLOBAL(void)
  146683. jpeg_CreateCompress (j_compress_ptr cinfo, int version, size_t structsize)
  146684. {
  146685. int i;
  146686. cinfo->mem = NULL; /* so jpeg_destroy knows mem mgr not called */
  146687. if (version != JPEG_LIB_VERSION)
  146688. ERREXIT2(cinfo, JERR_BAD_LIB_VERSION, JPEG_LIB_VERSION, version);
  146689. if (structsize != SIZEOF(struct jpeg_compress_struct))
  146690. ERREXIT2(cinfo, JERR_BAD_STRUCT_SIZE,
  146691. (int) SIZEOF(struct jpeg_compress_struct), (int) structsize);
  146692. {
  146693. struct jpeg_error_mgr * err = cinfo->err;
  146694. void * client_data = cinfo->client_data; /* ignore Purify complaint here */
  146695. MEMZERO(cinfo, SIZEOF(struct jpeg_compress_struct));
  146696. cinfo->err = err;
  146697. cinfo->client_data = client_data;
  146698. }
  146699. cinfo->is_decompressor = FALSE;
  146700. jinit_memory_mgr((j_common_ptr) cinfo);
  146701. cinfo->progress = NULL;
  146702. cinfo->dest = NULL;
  146703. cinfo->comp_info = NULL;
  146704. for (i = 0; i < NUM_QUANT_TBLS; i++)
  146705. cinfo->quant_tbl_ptrs[i] = NULL;
  146706. for (i = 0; i < NUM_HUFF_TBLS; i++) {
  146707. cinfo->dc_huff_tbl_ptrs[i] = NULL;
  146708. cinfo->ac_huff_tbl_ptrs[i] = NULL;
  146709. }
  146710. cinfo->script_space = NULL;
  146711. cinfo->input_gamma = 1.0; /* in case application forgets */
  146712. cinfo->global_state = CSTATE_START;
  146713. }
  146714. GLOBAL(void)
  146715. jpeg_destroy_compress (j_compress_ptr cinfo)
  146716. {
  146717. jpeg_destroy((j_common_ptr) cinfo); /* use common routine */
  146718. }
  146719. GLOBAL(void)
  146720. jpeg_abort_compress (j_compress_ptr cinfo)
  146721. {
  146722. jpeg_abort((j_common_ptr) cinfo); /* use common routine */
  146723. }
  146724. GLOBAL(void)
  146725. jpeg_suppress_tables (j_compress_ptr cinfo, boolean suppress)
  146726. {
  146727. int i;
  146728. JQUANT_TBL * qtbl;
  146729. JHUFF_TBL * htbl;
  146730. for (i = 0; i < NUM_QUANT_TBLS; i++) {
  146731. if ((qtbl = cinfo->quant_tbl_ptrs[i]) != NULL)
  146732. qtbl->sent_table = suppress;
  146733. }
  146734. for (i = 0; i < NUM_HUFF_TBLS; i++) {
  146735. if ((htbl = cinfo->dc_huff_tbl_ptrs[i]) != NULL)
  146736. htbl->sent_table = suppress;
  146737. if ((htbl = cinfo->ac_huff_tbl_ptrs[i]) != NULL)
  146738. htbl->sent_table = suppress;
  146739. }
  146740. }
  146741. GLOBAL(void)
  146742. jpeg_finish_compress (j_compress_ptr cinfo)
  146743. {
  146744. JDIMENSION iMCU_row;
  146745. if (cinfo->global_state == CSTATE_SCANNING ||
  146746. cinfo->global_state == CSTATE_RAW_OK) {
  146747. if (cinfo->next_scanline < cinfo->image_height)
  146748. ERREXIT(cinfo, JERR_TOO_LITTLE_DATA);
  146749. (*cinfo->master->finish_pass) (cinfo);
  146750. } else if (cinfo->global_state != CSTATE_WRCOEFS)
  146751. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  146752. while (! cinfo->master->is_last_pass) {
  146753. (*cinfo->master->prepare_for_pass) (cinfo);
  146754. for (iMCU_row = 0; iMCU_row < cinfo->total_iMCU_rows; iMCU_row++) {
  146755. if (cinfo->progress != NULL) {
  146756. cinfo->progress->pass_counter = (long) iMCU_row;
  146757. cinfo->progress->pass_limit = (long) cinfo->total_iMCU_rows;
  146758. (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);
  146759. }
  146760. if (! (*cinfo->coef->compress_data) (cinfo, (JSAMPIMAGE) NULL))
  146761. ERREXIT(cinfo, JERR_CANT_SUSPEND);
  146762. }
  146763. (*cinfo->master->finish_pass) (cinfo);
  146764. }
  146765. (*cinfo->marker->write_file_trailer) (cinfo);
  146766. (*cinfo->dest->term_destination) (cinfo);
  146767. jpeg_abort((j_common_ptr) cinfo);
  146768. }
  146769. GLOBAL(void)
  146770. jpeg_write_marker (j_compress_ptr cinfo, int marker,
  146771. const JOCTET *dataptr, unsigned int datalen)
  146772. {
  146773. JMETHOD(void, write_marker_byte, (j_compress_ptr info, int val));
  146774. if (cinfo->next_scanline != 0 ||
  146775. (cinfo->global_state != CSTATE_SCANNING &&
  146776. cinfo->global_state != CSTATE_RAW_OK &&
  146777. cinfo->global_state != CSTATE_WRCOEFS))
  146778. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  146779. (*cinfo->marker->write_marker_header) (cinfo, marker, datalen);
  146780. write_marker_byte = cinfo->marker->write_marker_byte; /* copy for speed */
  146781. while (datalen--) {
  146782. (*write_marker_byte) (cinfo, *dataptr);
  146783. dataptr++;
  146784. }
  146785. }
  146786. GLOBAL(void)
  146787. jpeg_write_m_header (j_compress_ptr cinfo, int marker, unsigned int datalen)
  146788. {
  146789. if (cinfo->next_scanline != 0 ||
  146790. (cinfo->global_state != CSTATE_SCANNING &&
  146791. cinfo->global_state != CSTATE_RAW_OK &&
  146792. cinfo->global_state != CSTATE_WRCOEFS))
  146793. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  146794. (*cinfo->marker->write_marker_header) (cinfo, marker, datalen);
  146795. }
  146796. GLOBAL(void)
  146797. jpeg_write_m_byte (j_compress_ptr cinfo, int val)
  146798. {
  146799. (*cinfo->marker->write_marker_byte) (cinfo, val);
  146800. }
  146801. GLOBAL(void)
  146802. jpeg_write_tables (j_compress_ptr cinfo)
  146803. {
  146804. if (cinfo->global_state != CSTATE_START)
  146805. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  146806. (*cinfo->err->reset_error_mgr) ((j_common_ptr) cinfo);
  146807. (*cinfo->dest->init_destination) (cinfo);
  146808. jinit_marker_writer(cinfo);
  146809. (*cinfo->marker->write_tables_only) (cinfo);
  146810. (*cinfo->dest->term_destination) (cinfo);
  146811. }
  146812. /********* End of inlined file: jcapimin.c *********/
  146813. /********* Start of inlined file: jcapistd.c *********/
  146814. #define JPEG_INTERNALS
  146815. GLOBAL(void)
  146816. jpeg_start_compress (j_compress_ptr cinfo, boolean write_all_tables)
  146817. {
  146818. if (cinfo->global_state != CSTATE_START)
  146819. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  146820. if (write_all_tables)
  146821. jpeg_suppress_tables(cinfo, FALSE); /* mark all tables to be written */
  146822. (*cinfo->err->reset_error_mgr) ((j_common_ptr) cinfo);
  146823. (*cinfo->dest->init_destination) (cinfo);
  146824. jinit_compress_master(cinfo);
  146825. (*cinfo->master->prepare_for_pass) (cinfo);
  146826. cinfo->next_scanline = 0;
  146827. cinfo->global_state = (cinfo->raw_data_in ? CSTATE_RAW_OK : CSTATE_SCANNING);
  146828. }
  146829. GLOBAL(JDIMENSION)
  146830. jpeg_write_scanlines (j_compress_ptr cinfo, JSAMPARRAY scanlines,
  146831. JDIMENSION num_lines)
  146832. {
  146833. JDIMENSION row_ctr, rows_left;
  146834. if (cinfo->global_state != CSTATE_SCANNING)
  146835. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  146836. if (cinfo->next_scanline >= cinfo->image_height)
  146837. WARNMS(cinfo, JWRN_TOO_MUCH_DATA);
  146838. if (cinfo->progress != NULL) {
  146839. cinfo->progress->pass_counter = (long) cinfo->next_scanline;
  146840. cinfo->progress->pass_limit = (long) cinfo->image_height;
  146841. (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);
  146842. }
  146843. if (cinfo->master->call_pass_startup)
  146844. (*cinfo->master->pass_startup) (cinfo);
  146845. rows_left = cinfo->image_height - cinfo->next_scanline;
  146846. if (num_lines > rows_left)
  146847. num_lines = rows_left;
  146848. row_ctr = 0;
  146849. (*cinfo->main->process_data) (cinfo, scanlines, &row_ctr, num_lines);
  146850. cinfo->next_scanline += row_ctr;
  146851. return row_ctr;
  146852. }
  146853. GLOBAL(JDIMENSION)
  146854. jpeg_write_raw_data (j_compress_ptr cinfo, JSAMPIMAGE data,
  146855. JDIMENSION num_lines)
  146856. {
  146857. JDIMENSION lines_per_iMCU_row;
  146858. if (cinfo->global_state != CSTATE_RAW_OK)
  146859. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  146860. if (cinfo->next_scanline >= cinfo->image_height) {
  146861. WARNMS(cinfo, JWRN_TOO_MUCH_DATA);
  146862. return 0;
  146863. }
  146864. if (cinfo->progress != NULL) {
  146865. cinfo->progress->pass_counter = (long) cinfo->next_scanline;
  146866. cinfo->progress->pass_limit = (long) cinfo->image_height;
  146867. (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);
  146868. }
  146869. if (cinfo->master->call_pass_startup)
  146870. (*cinfo->master->pass_startup) (cinfo);
  146871. lines_per_iMCU_row = cinfo->max_v_samp_factor * DCTSIZE;
  146872. if (num_lines < lines_per_iMCU_row)
  146873. ERREXIT(cinfo, JERR_BUFFER_SIZE);
  146874. if (! (*cinfo->coef->compress_data) (cinfo, data)) {
  146875. return 0;
  146876. }
  146877. cinfo->next_scanline += lines_per_iMCU_row;
  146878. return lines_per_iMCU_row;
  146879. }
  146880. /********* End of inlined file: jcapistd.c *********/
  146881. /********* Start of inlined file: jccoefct.c *********/
  146882. #define JPEG_INTERNALS
  146883. #ifdef ENTROPY_OPT_SUPPORTED
  146884. #define FULL_COEF_BUFFER_SUPPORTED
  146885. #else
  146886. #ifdef C_MULTISCAN_FILES_SUPPORTED
  146887. #define FULL_COEF_BUFFER_SUPPORTED
  146888. #endif
  146889. #endif
  146890. typedef struct {
  146891. struct jpeg_c_coef_controller pub; /* public fields */
  146892. JDIMENSION iMCU_row_num; /* iMCU row # within image */
  146893. JDIMENSION mcu_ctr; /* counts MCUs processed in current row */
  146894. int MCU_vert_offset; /* counts MCU rows within iMCU row */
  146895. int MCU_rows_per_iMCU_row; /* number of such rows needed */
  146896. JBLOCKROW MCU_buffer[C_MAX_BLOCKS_IN_MCU];
  146897. jvirt_barray_ptr whole_image[MAX_COMPONENTS];
  146898. } my_coef_controller;
  146899. typedef my_coef_controller * my_coef_ptr;
  146900. METHODDEF(boolean) compress_data
  146901. JPP((j_compress_ptr cinfo, JSAMPIMAGE input_buf));
  146902. #ifdef FULL_COEF_BUFFER_SUPPORTED
  146903. METHODDEF(boolean) compress_first_pass
  146904. JPP((j_compress_ptr cinfo, JSAMPIMAGE input_buf));
  146905. METHODDEF(boolean) compress_output
  146906. JPP((j_compress_ptr cinfo, JSAMPIMAGE input_buf));
  146907. #endif
  146908. LOCAL(void)
  146909. start_iMCU_row (j_compress_ptr cinfo)
  146910. {
  146911. my_coef_ptr coef = (my_coef_ptr) cinfo->coef;
  146912. if (cinfo->comps_in_scan > 1) {
  146913. coef->MCU_rows_per_iMCU_row = 1;
  146914. } else {
  146915. if (coef->iMCU_row_num < (cinfo->total_iMCU_rows-1))
  146916. coef->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor;
  146917. else
  146918. coef->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height;
  146919. }
  146920. coef->mcu_ctr = 0;
  146921. coef->MCU_vert_offset = 0;
  146922. }
  146923. METHODDEF(void)
  146924. start_pass_coef (j_compress_ptr cinfo, J_BUF_MODE pass_mode)
  146925. {
  146926. my_coef_ptr coef = (my_coef_ptr) cinfo->coef;
  146927. coef->iMCU_row_num = 0;
  146928. start_iMCU_row(cinfo);
  146929. switch (pass_mode) {
  146930. case JBUF_PASS_THRU:
  146931. if (coef->whole_image[0] != NULL)
  146932. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  146933. coef->pub.compress_data = compress_data;
  146934. break;
  146935. #ifdef FULL_COEF_BUFFER_SUPPORTED
  146936. case JBUF_SAVE_AND_PASS:
  146937. if (coef->whole_image[0] == NULL)
  146938. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  146939. coef->pub.compress_data = compress_first_pass;
  146940. break;
  146941. case JBUF_CRANK_DEST:
  146942. if (coef->whole_image[0] == NULL)
  146943. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  146944. coef->pub.compress_data = compress_output;
  146945. break;
  146946. #endif
  146947. default:
  146948. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  146949. break;
  146950. }
  146951. }
  146952. METHODDEF(boolean)
  146953. compress_data (j_compress_ptr cinfo, JSAMPIMAGE input_buf)
  146954. {
  146955. my_coef_ptr coef = (my_coef_ptr) cinfo->coef;
  146956. JDIMENSION MCU_col_num; /* index of current MCU within row */
  146957. JDIMENSION last_MCU_col = cinfo->MCUs_per_row - 1;
  146958. JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
  146959. int blkn, bi, ci, yindex, yoffset, blockcnt;
  146960. JDIMENSION ypos, xpos;
  146961. jpeg_component_info *compptr;
  146962. for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row;
  146963. yoffset++) {
  146964. for (MCU_col_num = coef->mcu_ctr; MCU_col_num <= last_MCU_col;
  146965. MCU_col_num++) {
  146966. blkn = 0;
  146967. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  146968. compptr = cinfo->cur_comp_info[ci];
  146969. blockcnt = (MCU_col_num < last_MCU_col) ? compptr->MCU_width
  146970. : compptr->last_col_width;
  146971. xpos = MCU_col_num * compptr->MCU_sample_width;
  146972. ypos = yoffset * DCTSIZE; /* ypos == (yoffset+yindex) * DCTSIZE */
  146973. for (yindex = 0; yindex < compptr->MCU_height; yindex++) {
  146974. if (coef->iMCU_row_num < last_iMCU_row ||
  146975. yoffset+yindex < compptr->last_row_height) {
  146976. (*cinfo->fdct->forward_DCT) (cinfo, compptr,
  146977. input_buf[compptr->component_index],
  146978. coef->MCU_buffer[blkn],
  146979. ypos, xpos, (JDIMENSION) blockcnt);
  146980. if (blockcnt < compptr->MCU_width) {
  146981. jzero_far((void FAR *) coef->MCU_buffer[blkn + blockcnt],
  146982. (compptr->MCU_width - blockcnt) * SIZEOF(JBLOCK));
  146983. for (bi = blockcnt; bi < compptr->MCU_width; bi++) {
  146984. coef->MCU_buffer[blkn+bi][0][0] = coef->MCU_buffer[blkn+bi-1][0][0];
  146985. }
  146986. }
  146987. } else {
  146988. jzero_far((void FAR *) coef->MCU_buffer[blkn],
  146989. compptr->MCU_width * SIZEOF(JBLOCK));
  146990. for (bi = 0; bi < compptr->MCU_width; bi++) {
  146991. coef->MCU_buffer[blkn+bi][0][0] = coef->MCU_buffer[blkn-1][0][0];
  146992. }
  146993. }
  146994. blkn += compptr->MCU_width;
  146995. ypos += DCTSIZE;
  146996. }
  146997. }
  146998. if (! (*cinfo->entropy->encode_mcu) (cinfo, coef->MCU_buffer)) {
  146999. coef->MCU_vert_offset = yoffset;
  147000. coef->mcu_ctr = MCU_col_num;
  147001. return FALSE;
  147002. }
  147003. }
  147004. coef->mcu_ctr = 0;
  147005. }
  147006. coef->iMCU_row_num++;
  147007. start_iMCU_row(cinfo);
  147008. return TRUE;
  147009. }
  147010. #ifdef FULL_COEF_BUFFER_SUPPORTED
  147011. METHODDEF(boolean)
  147012. compress_first_pass (j_compress_ptr cinfo, JSAMPIMAGE input_buf)
  147013. {
  147014. my_coef_ptr coef = (my_coef_ptr) cinfo->coef;
  147015. JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
  147016. JDIMENSION blocks_across, MCUs_across, MCUindex;
  147017. int bi, ci, h_samp_factor, block_row, block_rows, ndummy;
  147018. JCOEF lastDC;
  147019. jpeg_component_info *compptr;
  147020. JBLOCKARRAY buffer;
  147021. JBLOCKROW thisblockrow, lastblockrow;
  147022. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  147023. ci++, compptr++) {
  147024. buffer = (*cinfo->mem->access_virt_barray)
  147025. ((j_common_ptr) cinfo, coef->whole_image[ci],
  147026. coef->iMCU_row_num * compptr->v_samp_factor,
  147027. (JDIMENSION) compptr->v_samp_factor, TRUE);
  147028. if (coef->iMCU_row_num < last_iMCU_row)
  147029. block_rows = compptr->v_samp_factor;
  147030. else {
  147031. block_rows = (int) (compptr->height_in_blocks % compptr->v_samp_factor);
  147032. if (block_rows == 0) block_rows = compptr->v_samp_factor;
  147033. }
  147034. blocks_across = compptr->width_in_blocks;
  147035. h_samp_factor = compptr->h_samp_factor;
  147036. ndummy = (int) (blocks_across % h_samp_factor);
  147037. if (ndummy > 0)
  147038. ndummy = h_samp_factor - ndummy;
  147039. for (block_row = 0; block_row < block_rows; block_row++) {
  147040. thisblockrow = buffer[block_row];
  147041. (*cinfo->fdct->forward_DCT) (cinfo, compptr,
  147042. input_buf[ci], thisblockrow,
  147043. (JDIMENSION) (block_row * DCTSIZE),
  147044. (JDIMENSION) 0, blocks_across);
  147045. if (ndummy > 0) {
  147046. thisblockrow += blocks_across; /* => first dummy block */
  147047. jzero_far((void FAR *) thisblockrow, ndummy * SIZEOF(JBLOCK));
  147048. lastDC = thisblockrow[-1][0];
  147049. for (bi = 0; bi < ndummy; bi++) {
  147050. thisblockrow[bi][0] = lastDC;
  147051. }
  147052. }
  147053. }
  147054. if (coef->iMCU_row_num == last_iMCU_row) {
  147055. blocks_across += ndummy; /* include lower right corner */
  147056. MCUs_across = blocks_across / h_samp_factor;
  147057. for (block_row = block_rows; block_row < compptr->v_samp_factor;
  147058. block_row++) {
  147059. thisblockrow = buffer[block_row];
  147060. lastblockrow = buffer[block_row-1];
  147061. jzero_far((void FAR *) thisblockrow,
  147062. (size_t) (blocks_across * SIZEOF(JBLOCK)));
  147063. for (MCUindex = 0; MCUindex < MCUs_across; MCUindex++) {
  147064. lastDC = lastblockrow[h_samp_factor-1][0];
  147065. for (bi = 0; bi < h_samp_factor; bi++) {
  147066. thisblockrow[bi][0] = lastDC;
  147067. }
  147068. thisblockrow += h_samp_factor; /* advance to next MCU in row */
  147069. lastblockrow += h_samp_factor;
  147070. }
  147071. }
  147072. }
  147073. }
  147074. return compress_output(cinfo, input_buf);
  147075. }
  147076. METHODDEF(boolean)
  147077. compress_output (j_compress_ptr cinfo, JSAMPIMAGE input_buf)
  147078. {
  147079. my_coef_ptr coef = (my_coef_ptr) cinfo->coef;
  147080. JDIMENSION MCU_col_num; /* index of current MCU within row */
  147081. int blkn, ci, xindex, yindex, yoffset;
  147082. JDIMENSION start_col;
  147083. JBLOCKARRAY buffer[MAX_COMPS_IN_SCAN];
  147084. JBLOCKROW buffer_ptr;
  147085. jpeg_component_info *compptr;
  147086. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  147087. compptr = cinfo->cur_comp_info[ci];
  147088. buffer[ci] = (*cinfo->mem->access_virt_barray)
  147089. ((j_common_ptr) cinfo, coef->whole_image[compptr->component_index],
  147090. coef->iMCU_row_num * compptr->v_samp_factor,
  147091. (JDIMENSION) compptr->v_samp_factor, FALSE);
  147092. }
  147093. for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row;
  147094. yoffset++) {
  147095. for (MCU_col_num = coef->mcu_ctr; MCU_col_num < cinfo->MCUs_per_row;
  147096. MCU_col_num++) {
  147097. blkn = 0; /* index of current DCT block within MCU */
  147098. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  147099. compptr = cinfo->cur_comp_info[ci];
  147100. start_col = MCU_col_num * compptr->MCU_width;
  147101. for (yindex = 0; yindex < compptr->MCU_height; yindex++) {
  147102. buffer_ptr = buffer[ci][yindex+yoffset] + start_col;
  147103. for (xindex = 0; xindex < compptr->MCU_width; xindex++) {
  147104. coef->MCU_buffer[blkn++] = buffer_ptr++;
  147105. }
  147106. }
  147107. }
  147108. if (! (*cinfo->entropy->encode_mcu) (cinfo, coef->MCU_buffer)) {
  147109. coef->MCU_vert_offset = yoffset;
  147110. coef->mcu_ctr = MCU_col_num;
  147111. return FALSE;
  147112. }
  147113. }
  147114. coef->mcu_ctr = 0;
  147115. }
  147116. coef->iMCU_row_num++;
  147117. start_iMCU_row(cinfo);
  147118. return TRUE;
  147119. }
  147120. #endif /* FULL_COEF_BUFFER_SUPPORTED */
  147121. GLOBAL(void)
  147122. jinit_c_coef_controller (j_compress_ptr cinfo, boolean need_full_buffer)
  147123. {
  147124. my_coef_ptr coef;
  147125. coef = (my_coef_ptr)
  147126. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  147127. SIZEOF(my_coef_controller));
  147128. cinfo->coef = (struct jpeg_c_coef_controller *) coef;
  147129. coef->pub.start_pass = start_pass_coef;
  147130. if (need_full_buffer) {
  147131. #ifdef FULL_COEF_BUFFER_SUPPORTED
  147132. int ci;
  147133. jpeg_component_info *compptr;
  147134. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  147135. ci++, compptr++) {
  147136. coef->whole_image[ci] = (*cinfo->mem->request_virt_barray)
  147137. ((j_common_ptr) cinfo, JPOOL_IMAGE, FALSE,
  147138. (JDIMENSION) jround_up((long) compptr->width_in_blocks,
  147139. (long) compptr->h_samp_factor),
  147140. (JDIMENSION) jround_up((long) compptr->height_in_blocks,
  147141. (long) compptr->v_samp_factor),
  147142. (JDIMENSION) compptr->v_samp_factor);
  147143. }
  147144. #else
  147145. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  147146. #endif
  147147. } else {
  147148. JBLOCKROW buffer;
  147149. int i;
  147150. buffer = (JBLOCKROW)
  147151. (*cinfo->mem->alloc_large) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  147152. C_MAX_BLOCKS_IN_MCU * SIZEOF(JBLOCK));
  147153. for (i = 0; i < C_MAX_BLOCKS_IN_MCU; i++) {
  147154. coef->MCU_buffer[i] = buffer + i;
  147155. }
  147156. coef->whole_image[0] = NULL; /* flag for no virtual arrays */
  147157. }
  147158. }
  147159. /********* End of inlined file: jccoefct.c *********/
  147160. /********* Start of inlined file: jccolor.c *********/
  147161. #define JPEG_INTERNALS
  147162. typedef struct {
  147163. struct jpeg_color_converter pub; /* public fields */
  147164. INT32 * rgb_ycc_tab; /* => table for RGB to YCbCr conversion */
  147165. } my_color_converter;
  147166. typedef my_color_converter * my_cconvert_ptr;
  147167. #define SCALEBITS 16 /* speediest right-shift on some machines */
  147168. #define CBCR_OFFSET ((INT32) CENTERJSAMPLE << SCALEBITS)
  147169. #define ONE_HALF ((INT32) 1 << (SCALEBITS-1))
  147170. #define FIX(x) ((INT32) ((x) * (1L<<SCALEBITS) + 0.5))
  147171. #define R_Y_OFF 0 /* offset to R => Y section */
  147172. #define G_Y_OFF (1*(MAXJSAMPLE+1)) /* offset to G => Y section */
  147173. #define B_Y_OFF (2*(MAXJSAMPLE+1)) /* etc. */
  147174. #define R_CB_OFF (3*(MAXJSAMPLE+1))
  147175. #define G_CB_OFF (4*(MAXJSAMPLE+1))
  147176. #define B_CB_OFF (5*(MAXJSAMPLE+1))
  147177. #define R_CR_OFF B_CB_OFF /* B=>Cb, R=>Cr are the same */
  147178. #define G_CR_OFF (6*(MAXJSAMPLE+1))
  147179. #define B_CR_OFF (7*(MAXJSAMPLE+1))
  147180. #define TABLE_SIZE (8*(MAXJSAMPLE+1))
  147181. METHODDEF(void)
  147182. rgb_ycc_start (j_compress_ptr cinfo)
  147183. {
  147184. my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert;
  147185. INT32 * rgb_ycc_tab;
  147186. INT32 i;
  147187. cconvert->rgb_ycc_tab = rgb_ycc_tab = (INT32 *)
  147188. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  147189. (TABLE_SIZE * SIZEOF(INT32)));
  147190. for (i = 0; i <= MAXJSAMPLE; i++) {
  147191. rgb_ycc_tab[i+R_Y_OFF] = FIX(0.29900) * i;
  147192. rgb_ycc_tab[i+G_Y_OFF] = FIX(0.58700) * i;
  147193. rgb_ycc_tab[i+B_Y_OFF] = FIX(0.11400) * i + ONE_HALF;
  147194. rgb_ycc_tab[i+R_CB_OFF] = (-FIX(0.16874)) * i;
  147195. rgb_ycc_tab[i+G_CB_OFF] = (-FIX(0.33126)) * i;
  147196. rgb_ycc_tab[i+B_CB_OFF] = FIX(0.50000) * i + CBCR_OFFSET + ONE_HALF-1;
  147197. rgb_ycc_tab[i+G_CR_OFF] = (-FIX(0.41869)) * i;
  147198. rgb_ycc_tab[i+B_CR_OFF] = (-FIX(0.08131)) * i;
  147199. }
  147200. }
  147201. METHODDEF(void)
  147202. rgb_ycc_convert (j_compress_ptr cinfo,
  147203. JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
  147204. JDIMENSION output_row, int num_rows)
  147205. {
  147206. my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert;
  147207. register int r, g, b;
  147208. register INT32 * ctab = cconvert->rgb_ycc_tab;
  147209. register JSAMPROW inptr;
  147210. register JSAMPROW outptr0, outptr1, outptr2;
  147211. register JDIMENSION col;
  147212. JDIMENSION num_cols = cinfo->image_width;
  147213. while (--num_rows >= 0) {
  147214. inptr = *input_buf++;
  147215. outptr0 = output_buf[0][output_row];
  147216. outptr1 = output_buf[1][output_row];
  147217. outptr2 = output_buf[2][output_row];
  147218. output_row++;
  147219. for (col = 0; col < num_cols; col++) {
  147220. r = GETJSAMPLE(inptr[RGB_RED]);
  147221. g = GETJSAMPLE(inptr[RGB_GREEN]);
  147222. b = GETJSAMPLE(inptr[RGB_BLUE]);
  147223. inptr += RGB_PIXELSIZE;
  147224. outptr0[col] = (JSAMPLE)
  147225. ((ctab[r+R_Y_OFF] + ctab[g+G_Y_OFF] + ctab[b+B_Y_OFF])
  147226. >> SCALEBITS);
  147227. outptr1[col] = (JSAMPLE)
  147228. ((ctab[r+R_CB_OFF] + ctab[g+G_CB_OFF] + ctab[b+B_CB_OFF])
  147229. >> SCALEBITS);
  147230. outptr2[col] = (JSAMPLE)
  147231. ((ctab[r+R_CR_OFF] + ctab[g+G_CR_OFF] + ctab[b+B_CR_OFF])
  147232. >> SCALEBITS);
  147233. }
  147234. }
  147235. }
  147236. METHODDEF(void)
  147237. rgb_gray_convert (j_compress_ptr cinfo,
  147238. JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
  147239. JDIMENSION output_row, int num_rows)
  147240. {
  147241. my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert;
  147242. register int r, g, b;
  147243. register INT32 * ctab = cconvert->rgb_ycc_tab;
  147244. register JSAMPROW inptr;
  147245. register JSAMPROW outptr;
  147246. register JDIMENSION col;
  147247. JDIMENSION num_cols = cinfo->image_width;
  147248. while (--num_rows >= 0) {
  147249. inptr = *input_buf++;
  147250. outptr = output_buf[0][output_row];
  147251. output_row++;
  147252. for (col = 0; col < num_cols; col++) {
  147253. r = GETJSAMPLE(inptr[RGB_RED]);
  147254. g = GETJSAMPLE(inptr[RGB_GREEN]);
  147255. b = GETJSAMPLE(inptr[RGB_BLUE]);
  147256. inptr += RGB_PIXELSIZE;
  147257. outptr[col] = (JSAMPLE)
  147258. ((ctab[r+R_Y_OFF] + ctab[g+G_Y_OFF] + ctab[b+B_Y_OFF])
  147259. >> SCALEBITS);
  147260. }
  147261. }
  147262. }
  147263. METHODDEF(void)
  147264. cmyk_ycck_convert (j_compress_ptr cinfo,
  147265. JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
  147266. JDIMENSION output_row, int num_rows)
  147267. {
  147268. my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert;
  147269. register int r, g, b;
  147270. register INT32 * ctab = cconvert->rgb_ycc_tab;
  147271. register JSAMPROW inptr;
  147272. register JSAMPROW outptr0, outptr1, outptr2, outptr3;
  147273. register JDIMENSION col;
  147274. JDIMENSION num_cols = cinfo->image_width;
  147275. while (--num_rows >= 0) {
  147276. inptr = *input_buf++;
  147277. outptr0 = output_buf[0][output_row];
  147278. outptr1 = output_buf[1][output_row];
  147279. outptr2 = output_buf[2][output_row];
  147280. outptr3 = output_buf[3][output_row];
  147281. output_row++;
  147282. for (col = 0; col < num_cols; col++) {
  147283. r = MAXJSAMPLE - GETJSAMPLE(inptr[0]);
  147284. g = MAXJSAMPLE - GETJSAMPLE(inptr[1]);
  147285. b = MAXJSAMPLE - GETJSAMPLE(inptr[2]);
  147286. outptr3[col] = inptr[3]; /* don't need GETJSAMPLE here */
  147287. inptr += 4;
  147288. outptr0[col] = (JSAMPLE)
  147289. ((ctab[r+R_Y_OFF] + ctab[g+G_Y_OFF] + ctab[b+B_Y_OFF])
  147290. >> SCALEBITS);
  147291. outptr1[col] = (JSAMPLE)
  147292. ((ctab[r+R_CB_OFF] + ctab[g+G_CB_OFF] + ctab[b+B_CB_OFF])
  147293. >> SCALEBITS);
  147294. outptr2[col] = (JSAMPLE)
  147295. ((ctab[r+R_CR_OFF] + ctab[g+G_CR_OFF] + ctab[b+B_CR_OFF])
  147296. >> SCALEBITS);
  147297. }
  147298. }
  147299. }
  147300. METHODDEF(void)
  147301. grayscale_convert (j_compress_ptr cinfo,
  147302. JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
  147303. JDIMENSION output_row, int num_rows)
  147304. {
  147305. register JSAMPROW inptr;
  147306. register JSAMPROW outptr;
  147307. register JDIMENSION col;
  147308. JDIMENSION num_cols = cinfo->image_width;
  147309. int instride = cinfo->input_components;
  147310. while (--num_rows >= 0) {
  147311. inptr = *input_buf++;
  147312. outptr = output_buf[0][output_row];
  147313. output_row++;
  147314. for (col = 0; col < num_cols; col++) {
  147315. outptr[col] = inptr[0]; /* don't need GETJSAMPLE() here */
  147316. inptr += instride;
  147317. }
  147318. }
  147319. }
  147320. METHODDEF(void)
  147321. null_convert (j_compress_ptr cinfo,
  147322. JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
  147323. JDIMENSION output_row, int num_rows)
  147324. {
  147325. register JSAMPROW inptr;
  147326. register JSAMPROW outptr;
  147327. register JDIMENSION col;
  147328. register int ci;
  147329. int nc = cinfo->num_components;
  147330. JDIMENSION num_cols = cinfo->image_width;
  147331. while (--num_rows >= 0) {
  147332. for (ci = 0; ci < nc; ci++) {
  147333. inptr = *input_buf;
  147334. outptr = output_buf[ci][output_row];
  147335. for (col = 0; col < num_cols; col++) {
  147336. outptr[col] = inptr[ci]; /* don't need GETJSAMPLE() here */
  147337. inptr += nc;
  147338. }
  147339. }
  147340. input_buf++;
  147341. output_row++;
  147342. }
  147343. }
  147344. METHODDEF(void)
  147345. null_method (j_compress_ptr cinfo)
  147346. {
  147347. }
  147348. GLOBAL(void)
  147349. jinit_color_converter (j_compress_ptr cinfo)
  147350. {
  147351. my_cconvert_ptr cconvert;
  147352. cconvert = (my_cconvert_ptr)
  147353. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  147354. SIZEOF(my_color_converter));
  147355. cinfo->cconvert = (struct jpeg_color_converter *) cconvert;
  147356. cconvert->pub.start_pass = null_method;
  147357. switch (cinfo->in_color_space) {
  147358. case JCS_GRAYSCALE:
  147359. if (cinfo->input_components != 1)
  147360. ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
  147361. break;
  147362. case JCS_RGB:
  147363. #if RGB_PIXELSIZE != 3
  147364. if (cinfo->input_components != RGB_PIXELSIZE)
  147365. ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
  147366. break;
  147367. #endif /* else share code with YCbCr */
  147368. case JCS_YCbCr:
  147369. if (cinfo->input_components != 3)
  147370. ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
  147371. break;
  147372. case JCS_CMYK:
  147373. case JCS_YCCK:
  147374. if (cinfo->input_components != 4)
  147375. ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
  147376. break;
  147377. default: /* JCS_UNKNOWN can be anything */
  147378. if (cinfo->input_components < 1)
  147379. ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
  147380. break;
  147381. }
  147382. switch (cinfo->jpeg_color_space) {
  147383. case JCS_GRAYSCALE:
  147384. if (cinfo->num_components != 1)
  147385. ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
  147386. if (cinfo->in_color_space == JCS_GRAYSCALE)
  147387. cconvert->pub.color_convert = grayscale_convert;
  147388. else if (cinfo->in_color_space == JCS_RGB) {
  147389. cconvert->pub.start_pass = rgb_ycc_start;
  147390. cconvert->pub.color_convert = rgb_gray_convert;
  147391. } else if (cinfo->in_color_space == JCS_YCbCr)
  147392. cconvert->pub.color_convert = grayscale_convert;
  147393. else
  147394. ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
  147395. break;
  147396. case JCS_RGB:
  147397. if (cinfo->num_components != 3)
  147398. ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
  147399. if (cinfo->in_color_space == JCS_RGB && RGB_PIXELSIZE == 3)
  147400. cconvert->pub.color_convert = null_convert;
  147401. else
  147402. ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
  147403. break;
  147404. case JCS_YCbCr:
  147405. if (cinfo->num_components != 3)
  147406. ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
  147407. if (cinfo->in_color_space == JCS_RGB) {
  147408. cconvert->pub.start_pass = rgb_ycc_start;
  147409. cconvert->pub.color_convert = rgb_ycc_convert;
  147410. } else if (cinfo->in_color_space == JCS_YCbCr)
  147411. cconvert->pub.color_convert = null_convert;
  147412. else
  147413. ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
  147414. break;
  147415. case JCS_CMYK:
  147416. if (cinfo->num_components != 4)
  147417. ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
  147418. if (cinfo->in_color_space == JCS_CMYK)
  147419. cconvert->pub.color_convert = null_convert;
  147420. else
  147421. ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
  147422. break;
  147423. case JCS_YCCK:
  147424. if (cinfo->num_components != 4)
  147425. ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
  147426. if (cinfo->in_color_space == JCS_CMYK) {
  147427. cconvert->pub.start_pass = rgb_ycc_start;
  147428. cconvert->pub.color_convert = cmyk_ycck_convert;
  147429. } else if (cinfo->in_color_space == JCS_YCCK)
  147430. cconvert->pub.color_convert = null_convert;
  147431. else
  147432. ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
  147433. break;
  147434. default: /* allow null conversion of JCS_UNKNOWN */
  147435. if (cinfo->jpeg_color_space != cinfo->in_color_space ||
  147436. cinfo->num_components != cinfo->input_components)
  147437. ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
  147438. cconvert->pub.color_convert = null_convert;
  147439. break;
  147440. }
  147441. }
  147442. /********* End of inlined file: jccolor.c *********/
  147443. #undef FIX
  147444. /********* Start of inlined file: jcdctmgr.c *********/
  147445. #define JPEG_INTERNALS
  147446. /********* Start of inlined file: jdct.h *********/
  147447. #ifndef __jdct_h__
  147448. #define __jdct_h__
  147449. #if BITS_IN_JSAMPLE == 8
  147450. typedef int DCTELEM; /* 16 or 32 bits is fine */
  147451. #else
  147452. typedef INT32 DCTELEM; /* must have 32 bits */
  147453. #endif
  147454. typedef JMETHOD(void, forward_DCT_method_ptr, (DCTELEM * data));
  147455. typedef JMETHOD(void, float_DCT_method_ptr, (FAST_FLOAT * data));
  147456. typedef MULTIPLIER ISLOW_MULT_TYPE; /* short or int, whichever is faster */
  147457. #if BITS_IN_JSAMPLE == 8
  147458. typedef MULTIPLIER IFAST_MULT_TYPE; /* 16 bits is OK, use short if faster */
  147459. #define IFAST_SCALE_BITS 2 /* fractional bits in scale factors */
  147460. #else
  147461. typedef INT32 IFAST_MULT_TYPE; /* need 32 bits for scaled quantizers */
  147462. #define IFAST_SCALE_BITS 13 /* fractional bits in scale factors */
  147463. #endif
  147464. typedef FAST_FLOAT FLOAT_MULT_TYPE; /* preferred floating type */
  147465. #define IDCT_range_limit(cinfo) ((cinfo)->sample_range_limit + CENTERJSAMPLE)
  147466. #define RANGE_MASK (MAXJSAMPLE * 4 + 3) /* 2 bits wider than legal samples */
  147467. #ifdef NEED_SHORT_EXTERNAL_NAMES
  147468. #define jpeg_fdct_islow jFDislow
  147469. #define jpeg_fdct_ifast jFDifast
  147470. #define jpeg_fdct_float jFDfloat
  147471. #define jpeg_idct_islow jRDislow
  147472. #define jpeg_idct_ifast jRDifast
  147473. #define jpeg_idct_float jRDfloat
  147474. #define jpeg_idct_4x4 jRD4x4
  147475. #define jpeg_idct_2x2 jRD2x2
  147476. #define jpeg_idct_1x1 jRD1x1
  147477. #endif /* NEED_SHORT_EXTERNAL_NAMES */
  147478. EXTERN(void) jpeg_fdct_islow JPP((DCTELEM * data));
  147479. EXTERN(void) jpeg_fdct_ifast JPP((DCTELEM * data));
  147480. EXTERN(void) jpeg_fdct_float JPP((FAST_FLOAT * data));
  147481. EXTERN(void) jpeg_idct_islow
  147482. JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
  147483. JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
  147484. EXTERN(void) jpeg_idct_ifast
  147485. JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
  147486. JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
  147487. EXTERN(void) jpeg_idct_float
  147488. JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
  147489. JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
  147490. EXTERN(void) jpeg_idct_4x4
  147491. JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
  147492. JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
  147493. EXTERN(void) jpeg_idct_2x2
  147494. JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
  147495. JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
  147496. EXTERN(void) jpeg_idct_1x1
  147497. JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
  147498. JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
  147499. #define ONE ((INT32) 1)
  147500. #define CONST_SCALE (ONE << CONST_BITS)
  147501. #define FIX(x) ((INT32) ((x) * CONST_SCALE + 0.5))
  147502. #define DESCALE(x,n) RIGHT_SHIFT((x) + (ONE << ((n)-1)), n)
  147503. #ifdef SHORTxSHORT_32 /* may work if 'int' is 32 bits */
  147504. #define MULTIPLY16C16(var,const) (((INT16) (var)) * ((INT16) (const)))
  147505. #endif
  147506. #ifdef SHORTxLCONST_32 /* known to work with Microsoft C 6.0 */
  147507. #define MULTIPLY16C16(var,const) (((INT16) (var)) * ((INT32) (const)))
  147508. #endif
  147509. #ifndef MULTIPLY16C16 /* default definition */
  147510. #define MULTIPLY16C16(var,const) ((var) * (const))
  147511. #endif
  147512. #ifdef SHORTxSHORT_32 /* may work if 'int' is 32 bits */
  147513. #define MULTIPLY16V16(var1,var2) (((INT16) (var1)) * ((INT16) (var2)))
  147514. #endif
  147515. #ifndef MULTIPLY16V16 /* default definition */
  147516. #define MULTIPLY16V16(var1,var2) ((var1) * (var2))
  147517. #endif
  147518. #endif
  147519. /********* End of inlined file: jdct.h *********/
  147520. typedef struct {
  147521. struct jpeg_forward_dct pub; /* public fields */
  147522. forward_DCT_method_ptr do_dct;
  147523. DCTELEM * divisors[NUM_QUANT_TBLS];
  147524. #ifdef DCT_FLOAT_SUPPORTED
  147525. float_DCT_method_ptr do_float_dct;
  147526. FAST_FLOAT * float_divisors[NUM_QUANT_TBLS];
  147527. #endif
  147528. } my_fdct_controller;
  147529. typedef my_fdct_controller * my_fdct_ptr;
  147530. METHODDEF(void)
  147531. start_pass_fdctmgr (j_compress_ptr cinfo)
  147532. {
  147533. my_fdct_ptr fdct = (my_fdct_ptr) cinfo->fdct;
  147534. int ci, qtblno, i;
  147535. jpeg_component_info *compptr;
  147536. JQUANT_TBL * qtbl;
  147537. DCTELEM * dtbl;
  147538. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  147539. ci++, compptr++) {
  147540. qtblno = compptr->quant_tbl_no;
  147541. if (qtblno < 0 || qtblno >= NUM_QUANT_TBLS ||
  147542. cinfo->quant_tbl_ptrs[qtblno] == NULL)
  147543. ERREXIT1(cinfo, JERR_NO_QUANT_TABLE, qtblno);
  147544. qtbl = cinfo->quant_tbl_ptrs[qtblno];
  147545. switch (cinfo->dct_method) {
  147546. #ifdef DCT_ISLOW_SUPPORTED
  147547. case JDCT_ISLOW:
  147548. if (fdct->divisors[qtblno] == NULL) {
  147549. fdct->divisors[qtblno] = (DCTELEM *)
  147550. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  147551. DCTSIZE2 * SIZEOF(DCTELEM));
  147552. }
  147553. dtbl = fdct->divisors[qtblno];
  147554. for (i = 0; i < DCTSIZE2; i++) {
  147555. dtbl[i] = ((DCTELEM) qtbl->quantval[i]) << 3;
  147556. }
  147557. break;
  147558. #endif
  147559. #ifdef DCT_IFAST_SUPPORTED
  147560. case JDCT_IFAST:
  147561. {
  147562. #define CONST_BITS 14
  147563. static const INT16 aanscales[DCTSIZE2] = {
  147564. 16384, 22725, 21407, 19266, 16384, 12873, 8867, 4520,
  147565. 22725, 31521, 29692, 26722, 22725, 17855, 12299, 6270,
  147566. 21407, 29692, 27969, 25172, 21407, 16819, 11585, 5906,
  147567. 19266, 26722, 25172, 22654, 19266, 15137, 10426, 5315,
  147568. 16384, 22725, 21407, 19266, 16384, 12873, 8867, 4520,
  147569. 12873, 17855, 16819, 15137, 12873, 10114, 6967, 3552,
  147570. 8867, 12299, 11585, 10426, 8867, 6967, 4799, 2446,
  147571. 4520, 6270, 5906, 5315, 4520, 3552, 2446, 1247
  147572. };
  147573. SHIFT_TEMPS
  147574. if (fdct->divisors[qtblno] == NULL) {
  147575. fdct->divisors[qtblno] = (DCTELEM *)
  147576. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  147577. DCTSIZE2 * SIZEOF(DCTELEM));
  147578. }
  147579. dtbl = fdct->divisors[qtblno];
  147580. for (i = 0; i < DCTSIZE2; i++) {
  147581. dtbl[i] = (DCTELEM)
  147582. DESCALE(MULTIPLY16V16((INT32) qtbl->quantval[i],
  147583. (INT32) aanscales[i]),
  147584. CONST_BITS-3);
  147585. }
  147586. }
  147587. break;
  147588. #endif
  147589. #ifdef DCT_FLOAT_SUPPORTED
  147590. case JDCT_FLOAT:
  147591. {
  147592. FAST_FLOAT * fdtbl;
  147593. int row, col;
  147594. static const double aanscalefactor[DCTSIZE] = {
  147595. 1.0, 1.387039845, 1.306562965, 1.175875602,
  147596. 1.0, 0.785694958, 0.541196100, 0.275899379
  147597. };
  147598. if (fdct->float_divisors[qtblno] == NULL) {
  147599. fdct->float_divisors[qtblno] = (FAST_FLOAT *)
  147600. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  147601. DCTSIZE2 * SIZEOF(FAST_FLOAT));
  147602. }
  147603. fdtbl = fdct->float_divisors[qtblno];
  147604. i = 0;
  147605. for (row = 0; row < DCTSIZE; row++) {
  147606. for (col = 0; col < DCTSIZE; col++) {
  147607. fdtbl[i] = (FAST_FLOAT)
  147608. (1.0 / (((double) qtbl->quantval[i] *
  147609. aanscalefactor[row] * aanscalefactor[col] * 8.0)));
  147610. i++;
  147611. }
  147612. }
  147613. }
  147614. break;
  147615. #endif
  147616. default:
  147617. ERREXIT(cinfo, JERR_NOT_COMPILED);
  147618. break;
  147619. }
  147620. }
  147621. }
  147622. METHODDEF(void)
  147623. forward_DCT (j_compress_ptr cinfo, jpeg_component_info * compptr,
  147624. JSAMPARRAY sample_data, JBLOCKROW coef_blocks,
  147625. JDIMENSION start_row, JDIMENSION start_col,
  147626. JDIMENSION num_blocks)
  147627. {
  147628. my_fdct_ptr fdct = (my_fdct_ptr) cinfo->fdct;
  147629. forward_DCT_method_ptr do_dct = fdct->do_dct;
  147630. DCTELEM * divisors = fdct->divisors[compptr->quant_tbl_no];
  147631. DCTELEM workspace[DCTSIZE2]; /* work area for FDCT subroutine */
  147632. JDIMENSION bi;
  147633. sample_data += start_row; /* fold in the vertical offset once */
  147634. for (bi = 0; bi < num_blocks; bi++, start_col += DCTSIZE) {
  147635. { register DCTELEM *workspaceptr;
  147636. register JSAMPROW elemptr;
  147637. register int elemr;
  147638. workspaceptr = workspace;
  147639. for (elemr = 0; elemr < DCTSIZE; elemr++) {
  147640. elemptr = sample_data[elemr] + start_col;
  147641. #if DCTSIZE == 8 /* unroll the inner loop */
  147642. *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
  147643. *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
  147644. *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
  147645. *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
  147646. *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
  147647. *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
  147648. *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
  147649. *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
  147650. #else
  147651. { register int elemc;
  147652. for (elemc = DCTSIZE; elemc > 0; elemc--) {
  147653. *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
  147654. }
  147655. }
  147656. #endif
  147657. }
  147658. }
  147659. (*do_dct) (workspace);
  147660. { register DCTELEM temp, qval;
  147661. register int i;
  147662. register JCOEFPTR output_ptr = coef_blocks[bi];
  147663. for (i = 0; i < DCTSIZE2; i++) {
  147664. qval = divisors[i];
  147665. temp = workspace[i];
  147666. #ifdef FAST_DIVIDE
  147667. #define DIVIDE_BY(a,b) a /= b
  147668. #else
  147669. #define DIVIDE_BY(a,b) if (a >= b) a /= b; else a = 0
  147670. #endif
  147671. if (temp < 0) {
  147672. temp = -temp;
  147673. temp += qval>>1; /* for rounding */
  147674. DIVIDE_BY(temp, qval);
  147675. temp = -temp;
  147676. } else {
  147677. temp += qval>>1; /* for rounding */
  147678. DIVIDE_BY(temp, qval);
  147679. }
  147680. output_ptr[i] = (JCOEF) temp;
  147681. }
  147682. }
  147683. }
  147684. }
  147685. #ifdef DCT_FLOAT_SUPPORTED
  147686. METHODDEF(void)
  147687. forward_DCT_float (j_compress_ptr cinfo, jpeg_component_info * compptr,
  147688. JSAMPARRAY sample_data, JBLOCKROW coef_blocks,
  147689. JDIMENSION start_row, JDIMENSION start_col,
  147690. JDIMENSION num_blocks)
  147691. {
  147692. my_fdct_ptr fdct = (my_fdct_ptr) cinfo->fdct;
  147693. float_DCT_method_ptr do_dct = fdct->do_float_dct;
  147694. FAST_FLOAT * divisors = fdct->float_divisors[compptr->quant_tbl_no];
  147695. FAST_FLOAT workspace[DCTSIZE2]; /* work area for FDCT subroutine */
  147696. JDIMENSION bi;
  147697. sample_data += start_row; /* fold in the vertical offset once */
  147698. for (bi = 0; bi < num_blocks; bi++, start_col += DCTSIZE) {
  147699. { register FAST_FLOAT *workspaceptr;
  147700. register JSAMPROW elemptr;
  147701. register int elemr;
  147702. workspaceptr = workspace;
  147703. for (elemr = 0; elemr < DCTSIZE; elemr++) {
  147704. elemptr = sample_data[elemr] + start_col;
  147705. #if DCTSIZE == 8 /* unroll the inner loop */
  147706. *workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
  147707. *workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
  147708. *workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
  147709. *workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
  147710. *workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
  147711. *workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
  147712. *workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
  147713. *workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
  147714. #else
  147715. { register int elemc;
  147716. for (elemc = DCTSIZE; elemc > 0; elemc--) {
  147717. *workspaceptr++ = (FAST_FLOAT)
  147718. (GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
  147719. }
  147720. }
  147721. #endif
  147722. }
  147723. }
  147724. (*do_dct) (workspace);
  147725. { register FAST_FLOAT temp;
  147726. register int i;
  147727. register JCOEFPTR output_ptr = coef_blocks[bi];
  147728. for (i = 0; i < DCTSIZE2; i++) {
  147729. temp = workspace[i] * divisors[i];
  147730. output_ptr[i] = (JCOEF) ((int) (temp + (FAST_FLOAT) 16384.5) - 16384);
  147731. }
  147732. }
  147733. }
  147734. }
  147735. #endif /* DCT_FLOAT_SUPPORTED */
  147736. GLOBAL(void)
  147737. jinit_forward_dct (j_compress_ptr cinfo)
  147738. {
  147739. my_fdct_ptr fdct;
  147740. int i;
  147741. fdct = (my_fdct_ptr)
  147742. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  147743. SIZEOF(my_fdct_controller));
  147744. cinfo->fdct = (struct jpeg_forward_dct *) fdct;
  147745. fdct->pub.start_pass = start_pass_fdctmgr;
  147746. switch (cinfo->dct_method) {
  147747. #ifdef DCT_ISLOW_SUPPORTED
  147748. case JDCT_ISLOW:
  147749. fdct->pub.forward_DCT = forward_DCT;
  147750. fdct->do_dct = jpeg_fdct_islow;
  147751. break;
  147752. #endif
  147753. #ifdef DCT_IFAST_SUPPORTED
  147754. case JDCT_IFAST:
  147755. fdct->pub.forward_DCT = forward_DCT;
  147756. fdct->do_dct = jpeg_fdct_ifast;
  147757. break;
  147758. #endif
  147759. #ifdef DCT_FLOAT_SUPPORTED
  147760. case JDCT_FLOAT:
  147761. fdct->pub.forward_DCT = forward_DCT_float;
  147762. fdct->do_float_dct = jpeg_fdct_float;
  147763. break;
  147764. #endif
  147765. default:
  147766. ERREXIT(cinfo, JERR_NOT_COMPILED);
  147767. break;
  147768. }
  147769. for (i = 0; i < NUM_QUANT_TBLS; i++) {
  147770. fdct->divisors[i] = NULL;
  147771. #ifdef DCT_FLOAT_SUPPORTED
  147772. fdct->float_divisors[i] = NULL;
  147773. #endif
  147774. }
  147775. }
  147776. /********* End of inlined file: jcdctmgr.c *********/
  147777. #undef CONST_BITS
  147778. /********* Start of inlined file: jchuff.c *********/
  147779. #define JPEG_INTERNALS
  147780. /********* Start of inlined file: jchuff.h *********/
  147781. #ifndef _jchuff_h_
  147782. #define _jchuff_h_
  147783. #if BITS_IN_JSAMPLE == 8
  147784. #define MAX_COEF_BITS 10
  147785. #else
  147786. #define MAX_COEF_BITS 14
  147787. #endif
  147788. typedef struct {
  147789. unsigned int ehufco[256]; /* code for each symbol */
  147790. char ehufsi[256]; /* length of code for each symbol */
  147791. } c_derived_tbl;
  147792. #ifdef NEED_SHORT_EXTERNAL_NAMES
  147793. #define jpeg_make_c_derived_tbl jMkCDerived
  147794. #define jpeg_gen_optimal_table jGenOptTbl
  147795. #endif /* NEED_SHORT_EXTERNAL_NAMES */
  147796. EXTERN(void) jpeg_make_c_derived_tbl
  147797. JPP((j_compress_ptr cinfo, boolean isDC, int tblno,
  147798. c_derived_tbl ** pdtbl));
  147799. EXTERN(void) jpeg_gen_optimal_table
  147800. JPP((j_compress_ptr cinfo, JHUFF_TBL * htbl, long freq[]));
  147801. #endif
  147802. /********* End of inlined file: jchuff.h *********/
  147803. typedef struct {
  147804. INT32 put_buffer; /* current bit-accumulation buffer */
  147805. int put_bits; /* # of bits now in it */
  147806. int last_dc_val[MAX_COMPS_IN_SCAN]; /* last DC coef for each component */
  147807. } savable_state;
  147808. #ifndef NO_STRUCT_ASSIGN
  147809. #define ASSIGN_STATE(dest,src) ((dest) = (src))
  147810. #else
  147811. #if MAX_COMPS_IN_SCAN == 4
  147812. #define ASSIGN_STATE(dest,src) \
  147813. ((dest).put_buffer = (src).put_buffer, \
  147814. (dest).put_bits = (src).put_bits, \
  147815. (dest).last_dc_val[0] = (src).last_dc_val[0], \
  147816. (dest).last_dc_val[1] = (src).last_dc_val[1], \
  147817. (dest).last_dc_val[2] = (src).last_dc_val[2], \
  147818. (dest).last_dc_val[3] = (src).last_dc_val[3])
  147819. #endif
  147820. #endif
  147821. typedef struct {
  147822. struct jpeg_entropy_encoder pub; /* public fields */
  147823. savable_state saved; /* Bit buffer & DC state at start of MCU */
  147824. unsigned int restarts_to_go; /* MCUs left in this restart interval */
  147825. int next_restart_num; /* next restart number to write (0-7) */
  147826. c_derived_tbl * dc_derived_tbls[NUM_HUFF_TBLS];
  147827. c_derived_tbl * ac_derived_tbls[NUM_HUFF_TBLS];
  147828. #ifdef ENTROPY_OPT_SUPPORTED /* Statistics tables for optimization */
  147829. long * dc_count_ptrs[NUM_HUFF_TBLS];
  147830. long * ac_count_ptrs[NUM_HUFF_TBLS];
  147831. #endif
  147832. } huff_entropy_encoder;
  147833. typedef huff_entropy_encoder * huff_entropy_ptr;
  147834. typedef struct {
  147835. JOCTET * next_output_byte; /* => next byte to write in buffer */
  147836. size_t free_in_buffer; /* # of byte spaces remaining in buffer */
  147837. savable_state cur; /* Current bit buffer & DC state */
  147838. j_compress_ptr cinfo; /* dump_buffer needs access to this */
  147839. } working_state;
  147840. METHODDEF(boolean) encode_mcu_huff JPP((j_compress_ptr cinfo,
  147841. JBLOCKROW *MCU_data));
  147842. METHODDEF(void) finish_pass_huff JPP((j_compress_ptr cinfo));
  147843. #ifdef ENTROPY_OPT_SUPPORTED
  147844. METHODDEF(boolean) encode_mcu_gather JPP((j_compress_ptr cinfo,
  147845. JBLOCKROW *MCU_data));
  147846. METHODDEF(void) finish_pass_gather JPP((j_compress_ptr cinfo));
  147847. #endif
  147848. METHODDEF(void)
  147849. start_pass_huff (j_compress_ptr cinfo, boolean gather_statistics)
  147850. {
  147851. huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy;
  147852. int ci, dctbl, actbl;
  147853. jpeg_component_info * compptr;
  147854. if (gather_statistics) {
  147855. #ifdef ENTROPY_OPT_SUPPORTED
  147856. entropy->pub.encode_mcu = encode_mcu_gather;
  147857. entropy->pub.finish_pass = finish_pass_gather;
  147858. #else
  147859. ERREXIT(cinfo, JERR_NOT_COMPILED);
  147860. #endif
  147861. } else {
  147862. entropy->pub.encode_mcu = encode_mcu_huff;
  147863. entropy->pub.finish_pass = finish_pass_huff;
  147864. }
  147865. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  147866. compptr = cinfo->cur_comp_info[ci];
  147867. dctbl = compptr->dc_tbl_no;
  147868. actbl = compptr->ac_tbl_no;
  147869. if (gather_statistics) {
  147870. #ifdef ENTROPY_OPT_SUPPORTED
  147871. if (dctbl < 0 || dctbl >= NUM_HUFF_TBLS)
  147872. ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, dctbl);
  147873. if (actbl < 0 || actbl >= NUM_HUFF_TBLS)
  147874. ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, actbl);
  147875. if (entropy->dc_count_ptrs[dctbl] == NULL)
  147876. entropy->dc_count_ptrs[dctbl] = (long *)
  147877. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  147878. 257 * SIZEOF(long));
  147879. MEMZERO(entropy->dc_count_ptrs[dctbl], 257 * SIZEOF(long));
  147880. if (entropy->ac_count_ptrs[actbl] == NULL)
  147881. entropy->ac_count_ptrs[actbl] = (long *)
  147882. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  147883. 257 * SIZEOF(long));
  147884. MEMZERO(entropy->ac_count_ptrs[actbl], 257 * SIZEOF(long));
  147885. #endif
  147886. } else {
  147887. jpeg_make_c_derived_tbl(cinfo, TRUE, dctbl,
  147888. & entropy->dc_derived_tbls[dctbl]);
  147889. jpeg_make_c_derived_tbl(cinfo, FALSE, actbl,
  147890. & entropy->ac_derived_tbls[actbl]);
  147891. }
  147892. entropy->saved.last_dc_val[ci] = 0;
  147893. }
  147894. entropy->saved.put_buffer = 0;
  147895. entropy->saved.put_bits = 0;
  147896. entropy->restarts_to_go = cinfo->restart_interval;
  147897. entropy->next_restart_num = 0;
  147898. }
  147899. GLOBAL(void)
  147900. jpeg_make_c_derived_tbl (j_compress_ptr cinfo, boolean isDC, int tblno,
  147901. c_derived_tbl ** pdtbl)
  147902. {
  147903. JHUFF_TBL *htbl;
  147904. c_derived_tbl *dtbl;
  147905. int p, i, l, lastp, si, maxsymbol;
  147906. char huffsize[257];
  147907. unsigned int huffcode[257];
  147908. unsigned int code;
  147909. if (tblno < 0 || tblno >= NUM_HUFF_TBLS)
  147910. ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, tblno);
  147911. htbl =
  147912. isDC ? cinfo->dc_huff_tbl_ptrs[tblno] : cinfo->ac_huff_tbl_ptrs[tblno];
  147913. if (htbl == NULL)
  147914. ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, tblno);
  147915. if (*pdtbl == NULL)
  147916. *pdtbl = (c_derived_tbl *)
  147917. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  147918. SIZEOF(c_derived_tbl));
  147919. dtbl = *pdtbl;
  147920. p = 0;
  147921. for (l = 1; l <= 16; l++) {
  147922. i = (int) htbl->bits[l];
  147923. if (i < 0 || p + i > 256) /* protect against table overrun */
  147924. ERREXIT(cinfo, JERR_BAD_HUFF_TABLE);
  147925. while (i--)
  147926. huffsize[p++] = (char) l;
  147927. }
  147928. huffsize[p] = 0;
  147929. lastp = p;
  147930. code = 0;
  147931. si = huffsize[0];
  147932. p = 0;
  147933. while (huffsize[p]) {
  147934. while (((int) huffsize[p]) == si) {
  147935. huffcode[p++] = code;
  147936. code++;
  147937. }
  147938. if (((INT32) code) >= (((INT32) 1) << si))
  147939. ERREXIT(cinfo, JERR_BAD_HUFF_TABLE);
  147940. code <<= 1;
  147941. si++;
  147942. }
  147943. MEMZERO(dtbl->ehufsi, SIZEOF(dtbl->ehufsi));
  147944. maxsymbol = isDC ? 15 : 255;
  147945. for (p = 0; p < lastp; p++) {
  147946. i = htbl->huffval[p];
  147947. if (i < 0 || i > maxsymbol || dtbl->ehufsi[i])
  147948. ERREXIT(cinfo, JERR_BAD_HUFF_TABLE);
  147949. dtbl->ehufco[i] = huffcode[p];
  147950. dtbl->ehufsi[i] = huffsize[p];
  147951. }
  147952. }
  147953. #define emit_byte(state,val,action) \
  147954. { *(state)->next_output_byte++ = (JOCTET) (val); \
  147955. if (--(state)->free_in_buffer == 0) \
  147956. if (! dump_buffer(state)) \
  147957. { action; } }
  147958. LOCAL(boolean)
  147959. dump_buffer (working_state * state)
  147960. {
  147961. struct jpeg_destination_mgr * dest = state->cinfo->dest;
  147962. if (! (*dest->empty_output_buffer) (state->cinfo))
  147963. return FALSE;
  147964. state->next_output_byte = dest->next_output_byte;
  147965. state->free_in_buffer = dest->free_in_buffer;
  147966. return TRUE;
  147967. }
  147968. INLINE
  147969. LOCAL(boolean)
  147970. emit_bits (working_state * state, unsigned int code, int size)
  147971. {
  147972. register INT32 put_buffer = (INT32) code;
  147973. register int put_bits = state->cur.put_bits;
  147974. if (size == 0)
  147975. ERREXIT(state->cinfo, JERR_HUFF_MISSING_CODE);
  147976. put_buffer &= (((INT32) 1)<<size) - 1; /* mask off any extra bits in code */
  147977. put_bits += size; /* new number of bits in buffer */
  147978. put_buffer <<= 24 - put_bits; /* align incoming bits */
  147979. put_buffer |= state->cur.put_buffer; /* and merge with old buffer contents */
  147980. while (put_bits >= 8) {
  147981. int c = (int) ((put_buffer >> 16) & 0xFF);
  147982. emit_byte(state, c, return FALSE);
  147983. if (c == 0xFF) { /* need to stuff a zero byte? */
  147984. emit_byte(state, 0, return FALSE);
  147985. }
  147986. put_buffer <<= 8;
  147987. put_bits -= 8;
  147988. }
  147989. state->cur.put_buffer = put_buffer; /* update state variables */
  147990. state->cur.put_bits = put_bits;
  147991. return TRUE;
  147992. }
  147993. LOCAL(boolean)
  147994. flush_bits (working_state * state)
  147995. {
  147996. if (! emit_bits(state, 0x7F, 7)) /* fill any partial byte with ones */
  147997. return FALSE;
  147998. state->cur.put_buffer = 0; /* and reset bit-buffer to empty */
  147999. state->cur.put_bits = 0;
  148000. return TRUE;
  148001. }
  148002. LOCAL(boolean)
  148003. encode_one_block (working_state * state, JCOEFPTR block, int last_dc_val,
  148004. c_derived_tbl *dctbl, c_derived_tbl *actbl)
  148005. {
  148006. register int temp, temp2;
  148007. register int nbits;
  148008. register int k, r, i;
  148009. temp = temp2 = block[0] - last_dc_val;
  148010. if (temp < 0) {
  148011. temp = -temp; /* temp is abs value of input */
  148012. temp2--;
  148013. }
  148014. nbits = 0;
  148015. while (temp) {
  148016. nbits++;
  148017. temp >>= 1;
  148018. }
  148019. if (nbits > MAX_COEF_BITS+1)
  148020. ERREXIT(state->cinfo, JERR_BAD_DCT_COEF);
  148021. if (! emit_bits(state, dctbl->ehufco[nbits], dctbl->ehufsi[nbits]))
  148022. return FALSE;
  148023. if (nbits) /* emit_bits rejects calls with size 0 */
  148024. if (! emit_bits(state, (unsigned int) temp2, nbits))
  148025. return FALSE;
  148026. r = 0; /* r = run length of zeros */
  148027. for (k = 1; k < DCTSIZE2; k++) {
  148028. if ((temp = block[jpeg_natural_order[k]]) == 0) {
  148029. r++;
  148030. } else {
  148031. while (r > 15) {
  148032. if (! emit_bits(state, actbl->ehufco[0xF0], actbl->ehufsi[0xF0]))
  148033. return FALSE;
  148034. r -= 16;
  148035. }
  148036. temp2 = temp;
  148037. if (temp < 0) {
  148038. temp = -temp; /* temp is abs value of input */
  148039. temp2--;
  148040. }
  148041. nbits = 1; /* there must be at least one 1 bit */
  148042. while ((temp >>= 1))
  148043. nbits++;
  148044. if (nbits > MAX_COEF_BITS)
  148045. ERREXIT(state->cinfo, JERR_BAD_DCT_COEF);
  148046. i = (r << 4) + nbits;
  148047. if (! emit_bits(state, actbl->ehufco[i], actbl->ehufsi[i]))
  148048. return FALSE;
  148049. if (! emit_bits(state, (unsigned int) temp2, nbits))
  148050. return FALSE;
  148051. r = 0;
  148052. }
  148053. }
  148054. if (r > 0)
  148055. if (! emit_bits(state, actbl->ehufco[0], actbl->ehufsi[0]))
  148056. return FALSE;
  148057. return TRUE;
  148058. }
  148059. LOCAL(boolean)
  148060. emit_restart (working_state * state, int restart_num)
  148061. {
  148062. int ci;
  148063. if (! flush_bits(state))
  148064. return FALSE;
  148065. emit_byte(state, 0xFF, return FALSE);
  148066. emit_byte(state, JPEG_RST0 + restart_num, return FALSE);
  148067. for (ci = 0; ci < state->cinfo->comps_in_scan; ci++)
  148068. state->cur.last_dc_val[ci] = 0;
  148069. return TRUE;
  148070. }
  148071. METHODDEF(boolean)
  148072. encode_mcu_huff (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
  148073. {
  148074. huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy;
  148075. working_state state;
  148076. int blkn, ci;
  148077. jpeg_component_info * compptr;
  148078. state.next_output_byte = cinfo->dest->next_output_byte;
  148079. state.free_in_buffer = cinfo->dest->free_in_buffer;
  148080. ASSIGN_STATE(state.cur, entropy->saved);
  148081. state.cinfo = cinfo;
  148082. if (cinfo->restart_interval) {
  148083. if (entropy->restarts_to_go == 0)
  148084. if (! emit_restart(&state, entropy->next_restart_num))
  148085. return FALSE;
  148086. }
  148087. for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
  148088. ci = cinfo->MCU_membership[blkn];
  148089. compptr = cinfo->cur_comp_info[ci];
  148090. if (! encode_one_block(&state,
  148091. MCU_data[blkn][0], state.cur.last_dc_val[ci],
  148092. entropy->dc_derived_tbls[compptr->dc_tbl_no],
  148093. entropy->ac_derived_tbls[compptr->ac_tbl_no]))
  148094. return FALSE;
  148095. state.cur.last_dc_val[ci] = MCU_data[blkn][0][0];
  148096. }
  148097. cinfo->dest->next_output_byte = state.next_output_byte;
  148098. cinfo->dest->free_in_buffer = state.free_in_buffer;
  148099. ASSIGN_STATE(entropy->saved, state.cur);
  148100. if (cinfo->restart_interval) {
  148101. if (entropy->restarts_to_go == 0) {
  148102. entropy->restarts_to_go = cinfo->restart_interval;
  148103. entropy->next_restart_num++;
  148104. entropy->next_restart_num &= 7;
  148105. }
  148106. entropy->restarts_to_go--;
  148107. }
  148108. return TRUE;
  148109. }
  148110. METHODDEF(void)
  148111. finish_pass_huff (j_compress_ptr cinfo)
  148112. {
  148113. huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy;
  148114. working_state state;
  148115. state.next_output_byte = cinfo->dest->next_output_byte;
  148116. state.free_in_buffer = cinfo->dest->free_in_buffer;
  148117. ASSIGN_STATE(state.cur, entropy->saved);
  148118. state.cinfo = cinfo;
  148119. if (! flush_bits(&state))
  148120. ERREXIT(cinfo, JERR_CANT_SUSPEND);
  148121. cinfo->dest->next_output_byte = state.next_output_byte;
  148122. cinfo->dest->free_in_buffer = state.free_in_buffer;
  148123. ASSIGN_STATE(entropy->saved, state.cur);
  148124. }
  148125. #ifdef ENTROPY_OPT_SUPPORTED
  148126. LOCAL(void)
  148127. htest_one_block (j_compress_ptr cinfo, JCOEFPTR block, int last_dc_val,
  148128. long dc_counts[], long ac_counts[])
  148129. {
  148130. register int temp;
  148131. register int nbits;
  148132. register int k, r;
  148133. temp = block[0] - last_dc_val;
  148134. if (temp < 0)
  148135. temp = -temp;
  148136. nbits = 0;
  148137. while (temp) {
  148138. nbits++;
  148139. temp >>= 1;
  148140. }
  148141. if (nbits > MAX_COEF_BITS+1)
  148142. ERREXIT(cinfo, JERR_BAD_DCT_COEF);
  148143. dc_counts[nbits]++;
  148144. r = 0; /* r = run length of zeros */
  148145. for (k = 1; k < DCTSIZE2; k++) {
  148146. if ((temp = block[jpeg_natural_order[k]]) == 0) {
  148147. r++;
  148148. } else {
  148149. while (r > 15) {
  148150. ac_counts[0xF0]++;
  148151. r -= 16;
  148152. }
  148153. if (temp < 0)
  148154. temp = -temp;
  148155. nbits = 1; /* there must be at least one 1 bit */
  148156. while ((temp >>= 1))
  148157. nbits++;
  148158. if (nbits > MAX_COEF_BITS)
  148159. ERREXIT(cinfo, JERR_BAD_DCT_COEF);
  148160. ac_counts[(r << 4) + nbits]++;
  148161. r = 0;
  148162. }
  148163. }
  148164. if (r > 0)
  148165. ac_counts[0]++;
  148166. }
  148167. METHODDEF(boolean)
  148168. encode_mcu_gather (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
  148169. {
  148170. huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy;
  148171. int blkn, ci;
  148172. jpeg_component_info * compptr;
  148173. if (cinfo->restart_interval) {
  148174. if (entropy->restarts_to_go == 0) {
  148175. for (ci = 0; ci < cinfo->comps_in_scan; ci++)
  148176. entropy->saved.last_dc_val[ci] = 0;
  148177. entropy->restarts_to_go = cinfo->restart_interval;
  148178. }
  148179. entropy->restarts_to_go--;
  148180. }
  148181. for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
  148182. ci = cinfo->MCU_membership[blkn];
  148183. compptr = cinfo->cur_comp_info[ci];
  148184. htest_one_block(cinfo, MCU_data[blkn][0], entropy->saved.last_dc_val[ci],
  148185. entropy->dc_count_ptrs[compptr->dc_tbl_no],
  148186. entropy->ac_count_ptrs[compptr->ac_tbl_no]);
  148187. entropy->saved.last_dc_val[ci] = MCU_data[blkn][0][0];
  148188. }
  148189. return TRUE;
  148190. }
  148191. GLOBAL(void)
  148192. jpeg_gen_optimal_table (j_compress_ptr cinfo, JHUFF_TBL * htbl, long freq[])
  148193. {
  148194. #define MAX_CLEN 32 /* assumed maximum initial code length */
  148195. UINT8 bits[MAX_CLEN+1]; /* bits[k] = # of symbols with code length k */
  148196. int codesize[257]; /* codesize[k] = code length of symbol k */
  148197. int others[257]; /* next symbol in current branch of tree */
  148198. int c1, c2;
  148199. int p, i, j;
  148200. long v;
  148201. MEMZERO(bits, SIZEOF(bits));
  148202. MEMZERO(codesize, SIZEOF(codesize));
  148203. for (i = 0; i < 257; i++)
  148204. others[i] = -1; /* init links to empty */
  148205. freq[256] = 1; /* make sure 256 has a nonzero count */
  148206. for (;;) {
  148207. c1 = -1;
  148208. v = 1000000000L;
  148209. for (i = 0; i <= 256; i++) {
  148210. if (freq[i] && freq[i] <= v) {
  148211. v = freq[i];
  148212. c1 = i;
  148213. }
  148214. }
  148215. c2 = -1;
  148216. v = 1000000000L;
  148217. for (i = 0; i <= 256; i++) {
  148218. if (freq[i] && freq[i] <= v && i != c1) {
  148219. v = freq[i];
  148220. c2 = i;
  148221. }
  148222. }
  148223. if (c2 < 0)
  148224. break;
  148225. freq[c1] += freq[c2];
  148226. freq[c2] = 0;
  148227. codesize[c1]++;
  148228. while (others[c1] >= 0) {
  148229. c1 = others[c1];
  148230. codesize[c1]++;
  148231. }
  148232. others[c1] = c2; /* chain c2 onto c1's tree branch */
  148233. codesize[c2]++;
  148234. while (others[c2] >= 0) {
  148235. c2 = others[c2];
  148236. codesize[c2]++;
  148237. }
  148238. }
  148239. for (i = 0; i <= 256; i++) {
  148240. if (codesize[i]) {
  148241. if (codesize[i] > MAX_CLEN)
  148242. ERREXIT(cinfo, JERR_HUFF_CLEN_OVERFLOW);
  148243. bits[codesize[i]]++;
  148244. }
  148245. }
  148246. for (i = MAX_CLEN; i > 16; i--) {
  148247. while (bits[i] > 0) {
  148248. j = i - 2; /* find length of new prefix to be used */
  148249. while (bits[j] == 0)
  148250. j--;
  148251. bits[i] -= 2; /* remove two symbols */
  148252. bits[i-1]++; /* one goes in this length */
  148253. bits[j+1] += 2; /* two new symbols in this length */
  148254. bits[j]--; /* symbol of this length is now a prefix */
  148255. }
  148256. }
  148257. while (bits[i] == 0) /* find largest codelength still in use */
  148258. i--;
  148259. bits[i]--;
  148260. MEMCOPY(htbl->bits, bits, SIZEOF(htbl->bits));
  148261. p = 0;
  148262. for (i = 1; i <= MAX_CLEN; i++) {
  148263. for (j = 0; j <= 255; j++) {
  148264. if (codesize[j] == i) {
  148265. htbl->huffval[p] = (UINT8) j;
  148266. p++;
  148267. }
  148268. }
  148269. }
  148270. htbl->sent_table = FALSE;
  148271. }
  148272. METHODDEF(void)
  148273. finish_pass_gather (j_compress_ptr cinfo)
  148274. {
  148275. huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy;
  148276. int ci, dctbl, actbl;
  148277. jpeg_component_info * compptr;
  148278. JHUFF_TBL **htblptr;
  148279. boolean did_dc[NUM_HUFF_TBLS];
  148280. boolean did_ac[NUM_HUFF_TBLS];
  148281. MEMZERO(did_dc, SIZEOF(did_dc));
  148282. MEMZERO(did_ac, SIZEOF(did_ac));
  148283. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  148284. compptr = cinfo->cur_comp_info[ci];
  148285. dctbl = compptr->dc_tbl_no;
  148286. actbl = compptr->ac_tbl_no;
  148287. if (! did_dc[dctbl]) {
  148288. htblptr = & cinfo->dc_huff_tbl_ptrs[dctbl];
  148289. if (*htblptr == NULL)
  148290. *htblptr = jpeg_alloc_huff_table((j_common_ptr) cinfo);
  148291. jpeg_gen_optimal_table(cinfo, *htblptr, entropy->dc_count_ptrs[dctbl]);
  148292. did_dc[dctbl] = TRUE;
  148293. }
  148294. if (! did_ac[actbl]) {
  148295. htblptr = & cinfo->ac_huff_tbl_ptrs[actbl];
  148296. if (*htblptr == NULL)
  148297. *htblptr = jpeg_alloc_huff_table((j_common_ptr) cinfo);
  148298. jpeg_gen_optimal_table(cinfo, *htblptr, entropy->ac_count_ptrs[actbl]);
  148299. did_ac[actbl] = TRUE;
  148300. }
  148301. }
  148302. }
  148303. #endif /* ENTROPY_OPT_SUPPORTED */
  148304. GLOBAL(void)
  148305. jinit_huff_encoder (j_compress_ptr cinfo)
  148306. {
  148307. huff_entropy_ptr entropy;
  148308. int i;
  148309. entropy = (huff_entropy_ptr)
  148310. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  148311. SIZEOF(huff_entropy_encoder));
  148312. cinfo->entropy = (struct jpeg_entropy_encoder *) entropy;
  148313. entropy->pub.start_pass = start_pass_huff;
  148314. for (i = 0; i < NUM_HUFF_TBLS; i++) {
  148315. entropy->dc_derived_tbls[i] = entropy->ac_derived_tbls[i] = NULL;
  148316. #ifdef ENTROPY_OPT_SUPPORTED
  148317. entropy->dc_count_ptrs[i] = entropy->ac_count_ptrs[i] = NULL;
  148318. #endif
  148319. }
  148320. }
  148321. /********* End of inlined file: jchuff.c *********/
  148322. #undef emit_byte
  148323. /********* Start of inlined file: jcinit.c *********/
  148324. #define JPEG_INTERNALS
  148325. GLOBAL(void)
  148326. jinit_compress_master (j_compress_ptr cinfo)
  148327. {
  148328. jinit_c_master_control(cinfo, FALSE /* full compression */);
  148329. if (! cinfo->raw_data_in) {
  148330. jinit_color_converter(cinfo);
  148331. jinit_downsampler(cinfo);
  148332. jinit_c_prep_controller(cinfo, FALSE /* never need full buffer here */);
  148333. }
  148334. jinit_forward_dct(cinfo);
  148335. if (cinfo->arith_code) {
  148336. ERREXIT(cinfo, JERR_ARITH_NOTIMPL);
  148337. } else {
  148338. if (cinfo->progressive_mode) {
  148339. #ifdef C_PROGRESSIVE_SUPPORTED
  148340. jinit_phuff_encoder(cinfo);
  148341. #else
  148342. ERREXIT(cinfo, JERR_NOT_COMPILED);
  148343. #endif
  148344. } else
  148345. jinit_huff_encoder(cinfo);
  148346. }
  148347. jinit_c_coef_controller(cinfo,
  148348. (boolean) (cinfo->num_scans > 1 || cinfo->optimize_coding));
  148349. jinit_c_main_controller(cinfo, FALSE /* never need full buffer here */);
  148350. jinit_marker_writer(cinfo);
  148351. (*cinfo->mem->realize_virt_arrays) ((j_common_ptr) cinfo);
  148352. (*cinfo->marker->write_file_header) (cinfo);
  148353. }
  148354. /********* End of inlined file: jcinit.c *********/
  148355. /********* Start of inlined file: jcmainct.c *********/
  148356. #define JPEG_INTERNALS
  148357. #undef FULL_MAIN_BUFFER_SUPPORTED
  148358. typedef struct {
  148359. struct jpeg_c_main_controller pub; /* public fields */
  148360. JDIMENSION cur_iMCU_row; /* number of current iMCU row */
  148361. JDIMENSION rowgroup_ctr; /* counts row groups received in iMCU row */
  148362. boolean suspended; /* remember if we suspended output */
  148363. J_BUF_MODE pass_mode; /* current operating mode */
  148364. JSAMPARRAY buffer[MAX_COMPONENTS];
  148365. #ifdef FULL_MAIN_BUFFER_SUPPORTED
  148366. jvirt_sarray_ptr whole_image[MAX_COMPONENTS];
  148367. #endif
  148368. } my_main_controller;
  148369. typedef my_main_controller * my_main_ptr;
  148370. METHODDEF(void) process_data_simple_main
  148371. JPP((j_compress_ptr cinfo, JSAMPARRAY input_buf,
  148372. JDIMENSION *in_row_ctr, JDIMENSION in_rows_avail));
  148373. #ifdef FULL_MAIN_BUFFER_SUPPORTED
  148374. METHODDEF(void) process_data_buffer_main
  148375. JPP((j_compress_ptr cinfo, JSAMPARRAY input_buf,
  148376. JDIMENSION *in_row_ctr, JDIMENSION in_rows_avail));
  148377. #endif
  148378. METHODDEF(void)
  148379. start_pass_main (j_compress_ptr cinfo, J_BUF_MODE pass_mode)
  148380. {
  148381. my_main_ptr main_ = (my_main_ptr) cinfo->main;
  148382. if (cinfo->raw_data_in)
  148383. return;
  148384. main_->cur_iMCU_row = 0; /* initialize counters */
  148385. main_->rowgroup_ctr = 0;
  148386. main_->suspended = FALSE;
  148387. main_->pass_mode = pass_mode; /* save mode for use by process_data */
  148388. switch (pass_mode) {
  148389. case JBUF_PASS_THRU:
  148390. #ifdef FULL_MAIN_BUFFER_SUPPORTED
  148391. if (main_->whole_image[0] != NULL)
  148392. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  148393. #endif
  148394. main_->pub.process_data = process_data_simple_main;
  148395. break;
  148396. #ifdef FULL_MAIN_BUFFER_SUPPORTED
  148397. case JBUF_SAVE_SOURCE:
  148398. case JBUF_CRANK_DEST:
  148399. case JBUF_SAVE_AND_PASS:
  148400. if (main_->whole_image[0] == NULL)
  148401. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  148402. main_->pub.process_data = process_data_buffer_main;
  148403. break;
  148404. #endif
  148405. default:
  148406. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  148407. break;
  148408. }
  148409. }
  148410. METHODDEF(void)
  148411. process_data_simple_main (j_compress_ptr cinfo,
  148412. JSAMPARRAY input_buf, JDIMENSION *in_row_ctr,
  148413. JDIMENSION in_rows_avail)
  148414. {
  148415. my_main_ptr main_ = (my_main_ptr) cinfo->main;
  148416. while (main_->cur_iMCU_row < cinfo->total_iMCU_rows) {
  148417. if (main_->rowgroup_ctr < DCTSIZE)
  148418. (*cinfo->prep->pre_process_data) (cinfo,
  148419. input_buf, in_row_ctr, in_rows_avail,
  148420. main_->buffer, &main_->rowgroup_ctr,
  148421. (JDIMENSION) DCTSIZE);
  148422. if (main_->rowgroup_ctr != DCTSIZE)
  148423. return;
  148424. if (! (*cinfo->coef->compress_data) (cinfo, main_->buffer)) {
  148425. if (! main_->suspended) {
  148426. (*in_row_ctr)--;
  148427. main_->suspended = TRUE;
  148428. }
  148429. return;
  148430. }
  148431. if (main_->suspended) {
  148432. (*in_row_ctr)++;
  148433. main_->suspended = FALSE;
  148434. }
  148435. main_->rowgroup_ctr = 0;
  148436. main_->cur_iMCU_row++;
  148437. }
  148438. }
  148439. #ifdef FULL_MAIN_BUFFER_SUPPORTED
  148440. METHODDEF(void)
  148441. process_data_buffer_main (j_compress_ptr cinfo,
  148442. JSAMPARRAY input_buf, JDIMENSION *in_row_ctr,
  148443. JDIMENSION in_rows_avail)
  148444. {
  148445. my_main_ptr main = (my_main_ptr) cinfo->main;
  148446. int ci;
  148447. jpeg_component_info *compptr;
  148448. boolean writing = (main->pass_mode != JBUF_CRANK_DEST);
  148449. while (main->cur_iMCU_row < cinfo->total_iMCU_rows) {
  148450. if (main->rowgroup_ctr == 0) {
  148451. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  148452. ci++, compptr++) {
  148453. main->buffer[ci] = (*cinfo->mem->access_virt_sarray)
  148454. ((j_common_ptr) cinfo, main->whole_image[ci],
  148455. main->cur_iMCU_row * (compptr->v_samp_factor * DCTSIZE),
  148456. (JDIMENSION) (compptr->v_samp_factor * DCTSIZE), writing);
  148457. }
  148458. if (! writing) {
  148459. *in_row_ctr += cinfo->max_v_samp_factor * DCTSIZE;
  148460. main->rowgroup_ctr = DCTSIZE;
  148461. }
  148462. }
  148463. if (writing) {
  148464. (*cinfo->prep->pre_process_data) (cinfo,
  148465. input_buf, in_row_ctr, in_rows_avail,
  148466. main->buffer, &main->rowgroup_ctr,
  148467. (JDIMENSION) DCTSIZE);
  148468. if (main->rowgroup_ctr < DCTSIZE)
  148469. return;
  148470. }
  148471. if (main->pass_mode != JBUF_SAVE_SOURCE) {
  148472. if (! (*cinfo->coef->compress_data) (cinfo, main->buffer)) {
  148473. if (! main->suspended) {
  148474. (*in_row_ctr)--;
  148475. main->suspended = TRUE;
  148476. }
  148477. return;
  148478. }
  148479. if (main->suspended) {
  148480. (*in_row_ctr)++;
  148481. main->suspended = FALSE;
  148482. }
  148483. }
  148484. main->rowgroup_ctr = 0;
  148485. main->cur_iMCU_row++;
  148486. }
  148487. }
  148488. #endif /* FULL_MAIN_BUFFER_SUPPORTED */
  148489. GLOBAL(void)
  148490. jinit_c_main_controller (j_compress_ptr cinfo, boolean need_full_buffer)
  148491. {
  148492. my_main_ptr main_;
  148493. int ci;
  148494. jpeg_component_info *compptr;
  148495. main_ = (my_main_ptr)
  148496. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  148497. SIZEOF(my_main_controller));
  148498. cinfo->main = (struct jpeg_c_main_controller *) main_;
  148499. main_->pub.start_pass = start_pass_main;
  148500. if (cinfo->raw_data_in)
  148501. return;
  148502. if (need_full_buffer) {
  148503. #ifdef FULL_MAIN_BUFFER_SUPPORTED
  148504. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  148505. ci++, compptr++) {
  148506. main->whole_image[ci] = (*cinfo->mem->request_virt_sarray)
  148507. ((j_common_ptr) cinfo, JPOOL_IMAGE, FALSE,
  148508. compptr->width_in_blocks * DCTSIZE,
  148509. (JDIMENSION) jround_up((long) compptr->height_in_blocks,
  148510. (long) compptr->v_samp_factor) * DCTSIZE,
  148511. (JDIMENSION) (compptr->v_samp_factor * DCTSIZE));
  148512. }
  148513. #else
  148514. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  148515. #endif
  148516. } else {
  148517. #ifdef FULL_MAIN_BUFFER_SUPPORTED
  148518. main_->whole_image[0] = NULL; /* flag for no virtual arrays */
  148519. #endif
  148520. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  148521. ci++, compptr++) {
  148522. main_->buffer[ci] = (*cinfo->mem->alloc_sarray)
  148523. ((j_common_ptr) cinfo, JPOOL_IMAGE,
  148524. compptr->width_in_blocks * DCTSIZE,
  148525. (JDIMENSION) (compptr->v_samp_factor * DCTSIZE));
  148526. }
  148527. }
  148528. }
  148529. /********* End of inlined file: jcmainct.c *********/
  148530. /********* Start of inlined file: jcmarker.c *********/
  148531. #define JPEG_INTERNALS
  148532. typedef struct {
  148533. struct jpeg_marker_writer pub; /* public fields */
  148534. unsigned int last_restart_interval; /* last DRI value emitted; 0 after SOI */
  148535. } my_marker_writer;
  148536. typedef my_marker_writer * my_marker_ptr;
  148537. LOCAL(void)
  148538. emit_byte (j_compress_ptr cinfo, int val)
  148539. {
  148540. struct jpeg_destination_mgr * dest = cinfo->dest;
  148541. *(dest->next_output_byte)++ = (JOCTET) val;
  148542. if (--dest->free_in_buffer == 0) {
  148543. if (! (*dest->empty_output_buffer) (cinfo))
  148544. ERREXIT(cinfo, JERR_CANT_SUSPEND);
  148545. }
  148546. }
  148547. LOCAL(void)
  148548. emit_marker (j_compress_ptr cinfo, JPEG_MARKER mark)
  148549. {
  148550. emit_byte(cinfo, 0xFF);
  148551. emit_byte(cinfo, (int) mark);
  148552. }
  148553. LOCAL(void)
  148554. emit_2bytes (j_compress_ptr cinfo, int value)
  148555. {
  148556. emit_byte(cinfo, (value >> 8) & 0xFF);
  148557. emit_byte(cinfo, value & 0xFF);
  148558. }
  148559. LOCAL(int)
  148560. emit_dqt (j_compress_ptr cinfo, int index)
  148561. {
  148562. JQUANT_TBL * qtbl = cinfo->quant_tbl_ptrs[index];
  148563. int prec;
  148564. int i;
  148565. if (qtbl == NULL)
  148566. ERREXIT1(cinfo, JERR_NO_QUANT_TABLE, index);
  148567. prec = 0;
  148568. for (i = 0; i < DCTSIZE2; i++) {
  148569. if (qtbl->quantval[i] > 255)
  148570. prec = 1;
  148571. }
  148572. if (! qtbl->sent_table) {
  148573. emit_marker(cinfo, M_DQT);
  148574. emit_2bytes(cinfo, prec ? DCTSIZE2*2 + 1 + 2 : DCTSIZE2 + 1 + 2);
  148575. emit_byte(cinfo, index + (prec<<4));
  148576. for (i = 0; i < DCTSIZE2; i++) {
  148577. unsigned int qval = qtbl->quantval[jpeg_natural_order[i]];
  148578. if (prec)
  148579. emit_byte(cinfo, (int) (qval >> 8));
  148580. emit_byte(cinfo, (int) (qval & 0xFF));
  148581. }
  148582. qtbl->sent_table = TRUE;
  148583. }
  148584. return prec;
  148585. }
  148586. LOCAL(void)
  148587. emit_dht (j_compress_ptr cinfo, int index, boolean is_ac)
  148588. {
  148589. JHUFF_TBL * htbl;
  148590. int length, i;
  148591. if (is_ac) {
  148592. htbl = cinfo->ac_huff_tbl_ptrs[index];
  148593. index += 0x10; /* output index has AC bit set */
  148594. } else {
  148595. htbl = cinfo->dc_huff_tbl_ptrs[index];
  148596. }
  148597. if (htbl == NULL)
  148598. ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, index);
  148599. if (! htbl->sent_table) {
  148600. emit_marker(cinfo, M_DHT);
  148601. length = 0;
  148602. for (i = 1; i <= 16; i++)
  148603. length += htbl->bits[i];
  148604. emit_2bytes(cinfo, length + 2 + 1 + 16);
  148605. emit_byte(cinfo, index);
  148606. for (i = 1; i <= 16; i++)
  148607. emit_byte(cinfo, htbl->bits[i]);
  148608. for (i = 0; i < length; i++)
  148609. emit_byte(cinfo, htbl->huffval[i]);
  148610. htbl->sent_table = TRUE;
  148611. }
  148612. }
  148613. LOCAL(void)
  148614. emit_dac (j_compress_ptr cinfo)
  148615. {
  148616. #ifdef C_ARITH_CODING_SUPPORTED
  148617. char dc_in_use[NUM_ARITH_TBLS];
  148618. char ac_in_use[NUM_ARITH_TBLS];
  148619. int length, i;
  148620. jpeg_component_info *compptr;
  148621. for (i = 0; i < NUM_ARITH_TBLS; i++)
  148622. dc_in_use[i] = ac_in_use[i] = 0;
  148623. for (i = 0; i < cinfo->comps_in_scan; i++) {
  148624. compptr = cinfo->cur_comp_info[i];
  148625. dc_in_use[compptr->dc_tbl_no] = 1;
  148626. ac_in_use[compptr->ac_tbl_no] = 1;
  148627. }
  148628. length = 0;
  148629. for (i = 0; i < NUM_ARITH_TBLS; i++)
  148630. length += dc_in_use[i] + ac_in_use[i];
  148631. emit_marker(cinfo, M_DAC);
  148632. emit_2bytes(cinfo, length*2 + 2);
  148633. for (i = 0; i < NUM_ARITH_TBLS; i++) {
  148634. if (dc_in_use[i]) {
  148635. emit_byte(cinfo, i);
  148636. emit_byte(cinfo, cinfo->arith_dc_L[i] + (cinfo->arith_dc_U[i]<<4));
  148637. }
  148638. if (ac_in_use[i]) {
  148639. emit_byte(cinfo, i + 0x10);
  148640. emit_byte(cinfo, cinfo->arith_ac_K[i]);
  148641. }
  148642. }
  148643. #endif /* C_ARITH_CODING_SUPPORTED */
  148644. }
  148645. LOCAL(void)
  148646. emit_dri (j_compress_ptr cinfo)
  148647. {
  148648. emit_marker(cinfo, M_DRI);
  148649. emit_2bytes(cinfo, 4); /* fixed length */
  148650. emit_2bytes(cinfo, (int) cinfo->restart_interval);
  148651. }
  148652. LOCAL(void)
  148653. emit_sof (j_compress_ptr cinfo, JPEG_MARKER code)
  148654. {
  148655. int ci;
  148656. jpeg_component_info *compptr;
  148657. emit_marker(cinfo, code);
  148658. emit_2bytes(cinfo, 3 * cinfo->num_components + 2 + 5 + 1); /* length */
  148659. if ((long) cinfo->image_height > 65535L ||
  148660. (long) cinfo->image_width > 65535L)
  148661. ERREXIT1(cinfo, JERR_IMAGE_TOO_BIG, (unsigned int) 65535);
  148662. emit_byte(cinfo, cinfo->data_precision);
  148663. emit_2bytes(cinfo, (int) cinfo->image_height);
  148664. emit_2bytes(cinfo, (int) cinfo->image_width);
  148665. emit_byte(cinfo, cinfo->num_components);
  148666. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  148667. ci++, compptr++) {
  148668. emit_byte(cinfo, compptr->component_id);
  148669. emit_byte(cinfo, (compptr->h_samp_factor << 4) + compptr->v_samp_factor);
  148670. emit_byte(cinfo, compptr->quant_tbl_no);
  148671. }
  148672. }
  148673. LOCAL(void)
  148674. emit_sos (j_compress_ptr cinfo)
  148675. {
  148676. int i, td, ta;
  148677. jpeg_component_info *compptr;
  148678. emit_marker(cinfo, M_SOS);
  148679. emit_2bytes(cinfo, 2 * cinfo->comps_in_scan + 2 + 1 + 3); /* length */
  148680. emit_byte(cinfo, cinfo->comps_in_scan);
  148681. for (i = 0; i < cinfo->comps_in_scan; i++) {
  148682. compptr = cinfo->cur_comp_info[i];
  148683. emit_byte(cinfo, compptr->component_id);
  148684. td = compptr->dc_tbl_no;
  148685. ta = compptr->ac_tbl_no;
  148686. if (cinfo->progressive_mode) {
  148687. if (cinfo->Ss == 0) {
  148688. ta = 0; /* DC scan */
  148689. if (cinfo->Ah != 0 && !cinfo->arith_code)
  148690. td = 0; /* no DC table either */
  148691. } else {
  148692. td = 0; /* AC scan */
  148693. }
  148694. }
  148695. emit_byte(cinfo, (td << 4) + ta);
  148696. }
  148697. emit_byte(cinfo, cinfo->Ss);
  148698. emit_byte(cinfo, cinfo->Se);
  148699. emit_byte(cinfo, (cinfo->Ah << 4) + cinfo->Al);
  148700. }
  148701. LOCAL(void)
  148702. emit_jfif_app0 (j_compress_ptr cinfo)
  148703. {
  148704. emit_marker(cinfo, M_APP0);
  148705. emit_2bytes(cinfo, 2 + 4 + 1 + 2 + 1 + 2 + 2 + 1 + 1); /* length */
  148706. emit_byte(cinfo, 0x4A); /* Identifier: ASCII "JFIF" */
  148707. emit_byte(cinfo, 0x46);
  148708. emit_byte(cinfo, 0x49);
  148709. emit_byte(cinfo, 0x46);
  148710. emit_byte(cinfo, 0);
  148711. emit_byte(cinfo, cinfo->JFIF_major_version); /* Version fields */
  148712. emit_byte(cinfo, cinfo->JFIF_minor_version);
  148713. emit_byte(cinfo, cinfo->density_unit); /* Pixel size information */
  148714. emit_2bytes(cinfo, (int) cinfo->X_density);
  148715. emit_2bytes(cinfo, (int) cinfo->Y_density);
  148716. emit_byte(cinfo, 0); /* No thumbnail image */
  148717. emit_byte(cinfo, 0);
  148718. }
  148719. LOCAL(void)
  148720. emit_adobe_app14 (j_compress_ptr cinfo)
  148721. {
  148722. emit_marker(cinfo, M_APP14);
  148723. emit_2bytes(cinfo, 2 + 5 + 2 + 2 + 2 + 1); /* length */
  148724. emit_byte(cinfo, 0x41); /* Identifier: ASCII "Adobe" */
  148725. emit_byte(cinfo, 0x64);
  148726. emit_byte(cinfo, 0x6F);
  148727. emit_byte(cinfo, 0x62);
  148728. emit_byte(cinfo, 0x65);
  148729. emit_2bytes(cinfo, 100); /* Version */
  148730. emit_2bytes(cinfo, 0); /* Flags0 */
  148731. emit_2bytes(cinfo, 0); /* Flags1 */
  148732. switch (cinfo->jpeg_color_space) {
  148733. case JCS_YCbCr:
  148734. emit_byte(cinfo, 1); /* Color transform = 1 */
  148735. break;
  148736. case JCS_YCCK:
  148737. emit_byte(cinfo, 2); /* Color transform = 2 */
  148738. break;
  148739. default:
  148740. emit_byte(cinfo, 0); /* Color transform = 0 */
  148741. break;
  148742. }
  148743. }
  148744. METHODDEF(void)
  148745. write_marker_header (j_compress_ptr cinfo, int marker, unsigned int datalen)
  148746. {
  148747. if (datalen > (unsigned int) 65533) /* safety check */
  148748. ERREXIT(cinfo, JERR_BAD_LENGTH);
  148749. emit_marker(cinfo, (JPEG_MARKER) marker);
  148750. emit_2bytes(cinfo, (int) (datalen + 2)); /* total length */
  148751. }
  148752. METHODDEF(void)
  148753. write_marker_byte (j_compress_ptr cinfo, int val)
  148754. {
  148755. emit_byte(cinfo, val);
  148756. }
  148757. METHODDEF(void)
  148758. write_file_header (j_compress_ptr cinfo)
  148759. {
  148760. my_marker_ptr marker = (my_marker_ptr) cinfo->marker;
  148761. emit_marker(cinfo, M_SOI); /* first the SOI */
  148762. marker->last_restart_interval = 0;
  148763. if (cinfo->write_JFIF_header) /* next an optional JFIF APP0 */
  148764. emit_jfif_app0(cinfo);
  148765. if (cinfo->write_Adobe_marker) /* next an optional Adobe APP14 */
  148766. emit_adobe_app14(cinfo);
  148767. }
  148768. METHODDEF(void)
  148769. write_frame_header (j_compress_ptr cinfo)
  148770. {
  148771. int ci, prec;
  148772. boolean is_baseline;
  148773. jpeg_component_info *compptr;
  148774. prec = 0;
  148775. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  148776. ci++, compptr++) {
  148777. prec += emit_dqt(cinfo, compptr->quant_tbl_no);
  148778. }
  148779. if (cinfo->arith_code || cinfo->progressive_mode ||
  148780. cinfo->data_precision != 8) {
  148781. is_baseline = FALSE;
  148782. } else {
  148783. is_baseline = TRUE;
  148784. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  148785. ci++, compptr++) {
  148786. if (compptr->dc_tbl_no > 1 || compptr->ac_tbl_no > 1)
  148787. is_baseline = FALSE;
  148788. }
  148789. if (prec && is_baseline) {
  148790. is_baseline = FALSE;
  148791. TRACEMS(cinfo, 0, JTRC_16BIT_TABLES);
  148792. }
  148793. }
  148794. if (cinfo->arith_code) {
  148795. emit_sof(cinfo, M_SOF9); /* SOF code for arithmetic coding */
  148796. } else {
  148797. if (cinfo->progressive_mode)
  148798. emit_sof(cinfo, M_SOF2); /* SOF code for progressive Huffman */
  148799. else if (is_baseline)
  148800. emit_sof(cinfo, M_SOF0); /* SOF code for baseline implementation */
  148801. else
  148802. emit_sof(cinfo, M_SOF1); /* SOF code for non-baseline Huffman file */
  148803. }
  148804. }
  148805. METHODDEF(void)
  148806. write_scan_header (j_compress_ptr cinfo)
  148807. {
  148808. my_marker_ptr marker = (my_marker_ptr) cinfo->marker;
  148809. int i;
  148810. jpeg_component_info *compptr;
  148811. if (cinfo->arith_code) {
  148812. emit_dac(cinfo);
  148813. } else {
  148814. for (i = 0; i < cinfo->comps_in_scan; i++) {
  148815. compptr = cinfo->cur_comp_info[i];
  148816. if (cinfo->progressive_mode) {
  148817. if (cinfo->Ss == 0) {
  148818. if (cinfo->Ah == 0) /* DC needs no table for refinement scan */
  148819. emit_dht(cinfo, compptr->dc_tbl_no, FALSE);
  148820. } else {
  148821. emit_dht(cinfo, compptr->ac_tbl_no, TRUE);
  148822. }
  148823. } else {
  148824. emit_dht(cinfo, compptr->dc_tbl_no, FALSE);
  148825. emit_dht(cinfo, compptr->ac_tbl_no, TRUE);
  148826. }
  148827. }
  148828. }
  148829. if (cinfo->restart_interval != marker->last_restart_interval) {
  148830. emit_dri(cinfo);
  148831. marker->last_restart_interval = cinfo->restart_interval;
  148832. }
  148833. emit_sos(cinfo);
  148834. }
  148835. METHODDEF(void)
  148836. write_file_trailer (j_compress_ptr cinfo)
  148837. {
  148838. emit_marker(cinfo, M_EOI);
  148839. }
  148840. METHODDEF(void)
  148841. write_tables_only (j_compress_ptr cinfo)
  148842. {
  148843. int i;
  148844. emit_marker(cinfo, M_SOI);
  148845. for (i = 0; i < NUM_QUANT_TBLS; i++) {
  148846. if (cinfo->quant_tbl_ptrs[i] != NULL)
  148847. (void) emit_dqt(cinfo, i);
  148848. }
  148849. if (! cinfo->arith_code) {
  148850. for (i = 0; i < NUM_HUFF_TBLS; i++) {
  148851. if (cinfo->dc_huff_tbl_ptrs[i] != NULL)
  148852. emit_dht(cinfo, i, FALSE);
  148853. if (cinfo->ac_huff_tbl_ptrs[i] != NULL)
  148854. emit_dht(cinfo, i, TRUE);
  148855. }
  148856. }
  148857. emit_marker(cinfo, M_EOI);
  148858. }
  148859. GLOBAL(void)
  148860. jinit_marker_writer (j_compress_ptr cinfo)
  148861. {
  148862. my_marker_ptr marker;
  148863. marker = (my_marker_ptr)
  148864. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  148865. SIZEOF(my_marker_writer));
  148866. cinfo->marker = (struct jpeg_marker_writer *) marker;
  148867. marker->pub.write_file_header = write_file_header;
  148868. marker->pub.write_frame_header = write_frame_header;
  148869. marker->pub.write_scan_header = write_scan_header;
  148870. marker->pub.write_file_trailer = write_file_trailer;
  148871. marker->pub.write_tables_only = write_tables_only;
  148872. marker->pub.write_marker_header = write_marker_header;
  148873. marker->pub.write_marker_byte = write_marker_byte;
  148874. marker->last_restart_interval = 0;
  148875. }
  148876. /********* End of inlined file: jcmarker.c *********/
  148877. /********* Start of inlined file: jcmaster.c *********/
  148878. #define JPEG_INTERNALS
  148879. typedef enum {
  148880. main_pass, /* input data, also do first output step */
  148881. huff_opt_pass, /* Huffman code optimization pass */
  148882. output_pass /* data output pass */
  148883. } c_pass_type;
  148884. typedef struct {
  148885. struct jpeg_comp_master pub; /* public fields */
  148886. c_pass_type pass_type; /* the type of the current pass */
  148887. int pass_number; /* # of passes completed */
  148888. int total_passes; /* total # of passes needed */
  148889. int scan_number; /* current index in scan_info[] */
  148890. } my_comp_master;
  148891. typedef my_comp_master * my_master_ptr;
  148892. LOCAL(void)
  148893. initial_setup (j_compress_ptr cinfo)
  148894. {
  148895. int ci;
  148896. jpeg_component_info *compptr;
  148897. long samplesperrow;
  148898. JDIMENSION jd_samplesperrow;
  148899. if (cinfo->image_height <= 0 || cinfo->image_width <= 0
  148900. || cinfo->num_components <= 0 || cinfo->input_components <= 0)
  148901. ERREXIT(cinfo, JERR_EMPTY_IMAGE);
  148902. if ((long) cinfo->image_height > (long) JPEG_MAX_DIMENSION ||
  148903. (long) cinfo->image_width > (long) JPEG_MAX_DIMENSION)
  148904. ERREXIT1(cinfo, JERR_IMAGE_TOO_BIG, (unsigned int) JPEG_MAX_DIMENSION);
  148905. samplesperrow = (long) cinfo->image_width * (long) cinfo->input_components;
  148906. jd_samplesperrow = (JDIMENSION) samplesperrow;
  148907. if ((long) jd_samplesperrow != samplesperrow)
  148908. ERREXIT(cinfo, JERR_WIDTH_OVERFLOW);
  148909. if (cinfo->data_precision != BITS_IN_JSAMPLE)
  148910. ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
  148911. if (cinfo->num_components > MAX_COMPONENTS)
  148912. ERREXIT2(cinfo, JERR_COMPONENT_COUNT, cinfo->num_components,
  148913. MAX_COMPONENTS);
  148914. cinfo->max_h_samp_factor = 1;
  148915. cinfo->max_v_samp_factor = 1;
  148916. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  148917. ci++, compptr++) {
  148918. if (compptr->h_samp_factor<=0 || compptr->h_samp_factor>MAX_SAMP_FACTOR ||
  148919. compptr->v_samp_factor<=0 || compptr->v_samp_factor>MAX_SAMP_FACTOR)
  148920. ERREXIT(cinfo, JERR_BAD_SAMPLING);
  148921. cinfo->max_h_samp_factor = MAX(cinfo->max_h_samp_factor,
  148922. compptr->h_samp_factor);
  148923. cinfo->max_v_samp_factor = MAX(cinfo->max_v_samp_factor,
  148924. compptr->v_samp_factor);
  148925. }
  148926. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  148927. ci++, compptr++) {
  148928. compptr->component_index = ci;
  148929. compptr->DCT_scaled_size = DCTSIZE;
  148930. compptr->width_in_blocks = (JDIMENSION)
  148931. jdiv_round_up((long) cinfo->image_width * (long) compptr->h_samp_factor,
  148932. (long) (cinfo->max_h_samp_factor * DCTSIZE));
  148933. compptr->height_in_blocks = (JDIMENSION)
  148934. jdiv_round_up((long) cinfo->image_height * (long) compptr->v_samp_factor,
  148935. (long) (cinfo->max_v_samp_factor * DCTSIZE));
  148936. compptr->downsampled_width = (JDIMENSION)
  148937. jdiv_round_up((long) cinfo->image_width * (long) compptr->h_samp_factor,
  148938. (long) cinfo->max_h_samp_factor);
  148939. compptr->downsampled_height = (JDIMENSION)
  148940. jdiv_round_up((long) cinfo->image_height * (long) compptr->v_samp_factor,
  148941. (long) cinfo->max_v_samp_factor);
  148942. compptr->component_needed = TRUE;
  148943. }
  148944. cinfo->total_iMCU_rows = (JDIMENSION)
  148945. jdiv_round_up((long) cinfo->image_height,
  148946. (long) (cinfo->max_v_samp_factor*DCTSIZE));
  148947. }
  148948. #ifdef C_MULTISCAN_FILES_SUPPORTED
  148949. LOCAL(void)
  148950. validate_script (j_compress_ptr cinfo)
  148951. {
  148952. const jpeg_scan_info * scanptr;
  148953. int scanno, ncomps, ci, coefi, thisi;
  148954. int Ss, Se, Ah, Al;
  148955. boolean component_sent[MAX_COMPONENTS];
  148956. #ifdef C_PROGRESSIVE_SUPPORTED
  148957. int * last_bitpos_ptr;
  148958. int last_bitpos[MAX_COMPONENTS][DCTSIZE2];
  148959. #endif
  148960. if (cinfo->num_scans <= 0)
  148961. ERREXIT1(cinfo, JERR_BAD_SCAN_SCRIPT, 0);
  148962. scanptr = cinfo->scan_info;
  148963. if (scanptr->Ss != 0 || scanptr->Se != DCTSIZE2-1) {
  148964. #ifdef C_PROGRESSIVE_SUPPORTED
  148965. cinfo->progressive_mode = TRUE;
  148966. last_bitpos_ptr = & last_bitpos[0][0];
  148967. for (ci = 0; ci < cinfo->num_components; ci++)
  148968. for (coefi = 0; coefi < DCTSIZE2; coefi++)
  148969. *last_bitpos_ptr++ = -1;
  148970. #else
  148971. ERREXIT(cinfo, JERR_NOT_COMPILED);
  148972. #endif
  148973. } else {
  148974. cinfo->progressive_mode = FALSE;
  148975. for (ci = 0; ci < cinfo->num_components; ci++)
  148976. component_sent[ci] = FALSE;
  148977. }
  148978. for (scanno = 1; scanno <= cinfo->num_scans; scanptr++, scanno++) {
  148979. ncomps = scanptr->comps_in_scan;
  148980. if (ncomps <= 0 || ncomps > MAX_COMPS_IN_SCAN)
  148981. ERREXIT2(cinfo, JERR_COMPONENT_COUNT, ncomps, MAX_COMPS_IN_SCAN);
  148982. for (ci = 0; ci < ncomps; ci++) {
  148983. thisi = scanptr->component_index[ci];
  148984. if (thisi < 0 || thisi >= cinfo->num_components)
  148985. ERREXIT1(cinfo, JERR_BAD_SCAN_SCRIPT, scanno);
  148986. if (ci > 0 && thisi <= scanptr->component_index[ci-1])
  148987. ERREXIT1(cinfo, JERR_BAD_SCAN_SCRIPT, scanno);
  148988. }
  148989. Ss = scanptr->Ss;
  148990. Se = scanptr->Se;
  148991. Ah = scanptr->Ah;
  148992. Al = scanptr->Al;
  148993. if (cinfo->progressive_mode) {
  148994. #ifdef C_PROGRESSIVE_SUPPORTED
  148995. #if BITS_IN_JSAMPLE == 8
  148996. #define MAX_AH_AL 10
  148997. #else
  148998. #define MAX_AH_AL 13
  148999. #endif
  149000. if (Ss < 0 || Ss >= DCTSIZE2 || Se < Ss || Se >= DCTSIZE2 ||
  149001. Ah < 0 || Ah > MAX_AH_AL || Al < 0 || Al > MAX_AH_AL)
  149002. ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno);
  149003. if (Ss == 0) {
  149004. if (Se != 0) /* DC and AC together not OK */
  149005. ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno);
  149006. } else {
  149007. if (ncomps != 1) /* AC scans must be for only one component */
  149008. ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno);
  149009. }
  149010. for (ci = 0; ci < ncomps; ci++) {
  149011. last_bitpos_ptr = & last_bitpos[scanptr->component_index[ci]][0];
  149012. if (Ss != 0 && last_bitpos_ptr[0] < 0) /* AC without prior DC scan */
  149013. ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno);
  149014. for (coefi = Ss; coefi <= Se; coefi++) {
  149015. if (last_bitpos_ptr[coefi] < 0) {
  149016. if (Ah != 0)
  149017. ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno);
  149018. } else {
  149019. if (Ah != last_bitpos_ptr[coefi] || Al != Ah-1)
  149020. ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno);
  149021. }
  149022. last_bitpos_ptr[coefi] = Al;
  149023. }
  149024. }
  149025. #endif
  149026. } else {
  149027. if (Ss != 0 || Se != DCTSIZE2-1 || Ah != 0 || Al != 0)
  149028. ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno);
  149029. for (ci = 0; ci < ncomps; ci++) {
  149030. thisi = scanptr->component_index[ci];
  149031. if (component_sent[thisi])
  149032. ERREXIT1(cinfo, JERR_BAD_SCAN_SCRIPT, scanno);
  149033. component_sent[thisi] = TRUE;
  149034. }
  149035. }
  149036. }
  149037. if (cinfo->progressive_mode) {
  149038. #ifdef C_PROGRESSIVE_SUPPORTED
  149039. for (ci = 0; ci < cinfo->num_components; ci++) {
  149040. if (last_bitpos[ci][0] < 0)
  149041. ERREXIT(cinfo, JERR_MISSING_DATA);
  149042. }
  149043. #endif
  149044. } else {
  149045. for (ci = 0; ci < cinfo->num_components; ci++) {
  149046. if (! component_sent[ci])
  149047. ERREXIT(cinfo, JERR_MISSING_DATA);
  149048. }
  149049. }
  149050. }
  149051. #endif /* C_MULTISCAN_FILES_SUPPORTED */
  149052. LOCAL(void)
  149053. select_scan_parameters (j_compress_ptr cinfo)
  149054. {
  149055. int ci;
  149056. #ifdef C_MULTISCAN_FILES_SUPPORTED
  149057. if (cinfo->scan_info != NULL) {
  149058. my_master_ptr master = (my_master_ptr) cinfo->master;
  149059. const jpeg_scan_info * scanptr = cinfo->scan_info + master->scan_number;
  149060. cinfo->comps_in_scan = scanptr->comps_in_scan;
  149061. for (ci = 0; ci < scanptr->comps_in_scan; ci++) {
  149062. cinfo->cur_comp_info[ci] =
  149063. &cinfo->comp_info[scanptr->component_index[ci]];
  149064. }
  149065. cinfo->Ss = scanptr->Ss;
  149066. cinfo->Se = scanptr->Se;
  149067. cinfo->Ah = scanptr->Ah;
  149068. cinfo->Al = scanptr->Al;
  149069. }
  149070. else
  149071. #endif
  149072. {
  149073. if (cinfo->num_components > MAX_COMPS_IN_SCAN)
  149074. ERREXIT2(cinfo, JERR_COMPONENT_COUNT, cinfo->num_components,
  149075. MAX_COMPS_IN_SCAN);
  149076. cinfo->comps_in_scan = cinfo->num_components;
  149077. for (ci = 0; ci < cinfo->num_components; ci++) {
  149078. cinfo->cur_comp_info[ci] = &cinfo->comp_info[ci];
  149079. }
  149080. cinfo->Ss = 0;
  149081. cinfo->Se = DCTSIZE2-1;
  149082. cinfo->Ah = 0;
  149083. cinfo->Al = 0;
  149084. }
  149085. }
  149086. LOCAL(void)
  149087. per_scan_setup (j_compress_ptr cinfo)
  149088. {
  149089. int ci, mcublks, tmp;
  149090. jpeg_component_info *compptr;
  149091. if (cinfo->comps_in_scan == 1) {
  149092. compptr = cinfo->cur_comp_info[0];
  149093. cinfo->MCUs_per_row = compptr->width_in_blocks;
  149094. cinfo->MCU_rows_in_scan = compptr->height_in_blocks;
  149095. compptr->MCU_width = 1;
  149096. compptr->MCU_height = 1;
  149097. compptr->MCU_blocks = 1;
  149098. compptr->MCU_sample_width = DCTSIZE;
  149099. compptr->last_col_width = 1;
  149100. tmp = (int) (compptr->height_in_blocks % compptr->v_samp_factor);
  149101. if (tmp == 0) tmp = compptr->v_samp_factor;
  149102. compptr->last_row_height = tmp;
  149103. cinfo->blocks_in_MCU = 1;
  149104. cinfo->MCU_membership[0] = 0;
  149105. } else {
  149106. if (cinfo->comps_in_scan <= 0 || cinfo->comps_in_scan > MAX_COMPS_IN_SCAN)
  149107. ERREXIT2(cinfo, JERR_COMPONENT_COUNT, cinfo->comps_in_scan,
  149108. MAX_COMPS_IN_SCAN);
  149109. cinfo->MCUs_per_row = (JDIMENSION)
  149110. jdiv_round_up((long) cinfo->image_width,
  149111. (long) (cinfo->max_h_samp_factor*DCTSIZE));
  149112. cinfo->MCU_rows_in_scan = (JDIMENSION)
  149113. jdiv_round_up((long) cinfo->image_height,
  149114. (long) (cinfo->max_v_samp_factor*DCTSIZE));
  149115. cinfo->blocks_in_MCU = 0;
  149116. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  149117. compptr = cinfo->cur_comp_info[ci];
  149118. compptr->MCU_width = compptr->h_samp_factor;
  149119. compptr->MCU_height = compptr->v_samp_factor;
  149120. compptr->MCU_blocks = compptr->MCU_width * compptr->MCU_height;
  149121. compptr->MCU_sample_width = compptr->MCU_width * DCTSIZE;
  149122. tmp = (int) (compptr->width_in_blocks % compptr->MCU_width);
  149123. if (tmp == 0) tmp = compptr->MCU_width;
  149124. compptr->last_col_width = tmp;
  149125. tmp = (int) (compptr->height_in_blocks % compptr->MCU_height);
  149126. if (tmp == 0) tmp = compptr->MCU_height;
  149127. compptr->last_row_height = tmp;
  149128. mcublks = compptr->MCU_blocks;
  149129. if (cinfo->blocks_in_MCU + mcublks > C_MAX_BLOCKS_IN_MCU)
  149130. ERREXIT(cinfo, JERR_BAD_MCU_SIZE);
  149131. while (mcublks-- > 0) {
  149132. cinfo->MCU_membership[cinfo->blocks_in_MCU++] = ci;
  149133. }
  149134. }
  149135. }
  149136. if (cinfo->restart_in_rows > 0) {
  149137. long nominal = (long) cinfo->restart_in_rows * (long) cinfo->MCUs_per_row;
  149138. cinfo->restart_interval = (unsigned int) MIN(nominal, 65535L);
  149139. }
  149140. }
  149141. METHODDEF(void)
  149142. prepare_for_pass (j_compress_ptr cinfo)
  149143. {
  149144. my_master_ptr master = (my_master_ptr) cinfo->master;
  149145. switch (master->pass_type) {
  149146. case main_pass:
  149147. select_scan_parameters(cinfo);
  149148. per_scan_setup(cinfo);
  149149. if (! cinfo->raw_data_in) {
  149150. (*cinfo->cconvert->start_pass) (cinfo);
  149151. (*cinfo->downsample->start_pass) (cinfo);
  149152. (*cinfo->prep->start_pass) (cinfo, JBUF_PASS_THRU);
  149153. }
  149154. (*cinfo->fdct->start_pass) (cinfo);
  149155. (*cinfo->entropy->start_pass) (cinfo, cinfo->optimize_coding);
  149156. (*cinfo->coef->start_pass) (cinfo,
  149157. (master->total_passes > 1 ?
  149158. JBUF_SAVE_AND_PASS : JBUF_PASS_THRU));
  149159. (*cinfo->main->start_pass) (cinfo, JBUF_PASS_THRU);
  149160. if (cinfo->optimize_coding) {
  149161. master->pub.call_pass_startup = FALSE;
  149162. } else {
  149163. master->pub.call_pass_startup = TRUE;
  149164. }
  149165. break;
  149166. #ifdef ENTROPY_OPT_SUPPORTED
  149167. case huff_opt_pass:
  149168. select_scan_parameters(cinfo);
  149169. per_scan_setup(cinfo);
  149170. if (cinfo->Ss != 0 || cinfo->Ah == 0 || cinfo->arith_code) {
  149171. (*cinfo->entropy->start_pass) (cinfo, TRUE);
  149172. (*cinfo->coef->start_pass) (cinfo, JBUF_CRANK_DEST);
  149173. master->pub.call_pass_startup = FALSE;
  149174. break;
  149175. }
  149176. master->pass_type = output_pass;
  149177. master->pass_number++;
  149178. #endif
  149179. case output_pass:
  149180. if (! cinfo->optimize_coding) {
  149181. select_scan_parameters(cinfo);
  149182. per_scan_setup(cinfo);
  149183. }
  149184. (*cinfo->entropy->start_pass) (cinfo, FALSE);
  149185. (*cinfo->coef->start_pass) (cinfo, JBUF_CRANK_DEST);
  149186. if (master->scan_number == 0)
  149187. (*cinfo->marker->write_frame_header) (cinfo);
  149188. (*cinfo->marker->write_scan_header) (cinfo);
  149189. master->pub.call_pass_startup = FALSE;
  149190. break;
  149191. default:
  149192. ERREXIT(cinfo, JERR_NOT_COMPILED);
  149193. }
  149194. master->pub.is_last_pass = (master->pass_number == master->total_passes-1);
  149195. if (cinfo->progress != NULL) {
  149196. cinfo->progress->completed_passes = master->pass_number;
  149197. cinfo->progress->total_passes = master->total_passes;
  149198. }
  149199. }
  149200. METHODDEF(void)
  149201. pass_startup (j_compress_ptr cinfo)
  149202. {
  149203. cinfo->master->call_pass_startup = FALSE; /* reset flag so call only once */
  149204. (*cinfo->marker->write_frame_header) (cinfo);
  149205. (*cinfo->marker->write_scan_header) (cinfo);
  149206. }
  149207. METHODDEF(void)
  149208. finish_pass_master (j_compress_ptr cinfo)
  149209. {
  149210. my_master_ptr master = (my_master_ptr) cinfo->master;
  149211. (*cinfo->entropy->finish_pass) (cinfo);
  149212. switch (master->pass_type) {
  149213. case main_pass:
  149214. master->pass_type = output_pass;
  149215. if (! cinfo->optimize_coding)
  149216. master->scan_number++;
  149217. break;
  149218. case huff_opt_pass:
  149219. master->pass_type = output_pass;
  149220. break;
  149221. case output_pass:
  149222. if (cinfo->optimize_coding)
  149223. master->pass_type = huff_opt_pass;
  149224. master->scan_number++;
  149225. break;
  149226. }
  149227. master->pass_number++;
  149228. }
  149229. GLOBAL(void)
  149230. jinit_c_master_control (j_compress_ptr cinfo, boolean transcode_only)
  149231. {
  149232. my_master_ptr master;
  149233. master = (my_master_ptr)
  149234. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  149235. SIZEOF(my_comp_master));
  149236. cinfo->master = (struct jpeg_comp_master *) master;
  149237. master->pub.prepare_for_pass = prepare_for_pass;
  149238. master->pub.pass_startup = pass_startup;
  149239. master->pub.finish_pass = finish_pass_master;
  149240. master->pub.is_last_pass = FALSE;
  149241. initial_setup(cinfo);
  149242. if (cinfo->scan_info != NULL) {
  149243. #ifdef C_MULTISCAN_FILES_SUPPORTED
  149244. validate_script(cinfo);
  149245. #else
  149246. ERREXIT(cinfo, JERR_NOT_COMPILED);
  149247. #endif
  149248. } else {
  149249. cinfo->progressive_mode = FALSE;
  149250. cinfo->num_scans = 1;
  149251. }
  149252. if (cinfo->progressive_mode) /* TEMPORARY HACK ??? */
  149253. cinfo->optimize_coding = TRUE; /* assume default tables no good for progressive mode */
  149254. if (transcode_only) {
  149255. if (cinfo->optimize_coding)
  149256. master->pass_type = huff_opt_pass;
  149257. else
  149258. master->pass_type = output_pass;
  149259. } else {
  149260. master->pass_type = main_pass;
  149261. }
  149262. master->scan_number = 0;
  149263. master->pass_number = 0;
  149264. if (cinfo->optimize_coding)
  149265. master->total_passes = cinfo->num_scans * 2;
  149266. else
  149267. master->total_passes = cinfo->num_scans;
  149268. }
  149269. /********* End of inlined file: jcmaster.c *********/
  149270. /********* Start of inlined file: jcomapi.c *********/
  149271. #define JPEG_INTERNALS
  149272. GLOBAL(void)
  149273. jpeg_abort (j_common_ptr cinfo)
  149274. {
  149275. int pool;
  149276. if (cinfo->mem == NULL)
  149277. return;
  149278. for (pool = JPOOL_NUMPOOLS-1; pool > JPOOL_PERMANENT; pool--) {
  149279. (*cinfo->mem->free_pool) (cinfo, pool);
  149280. }
  149281. if (cinfo->is_decompressor) {
  149282. cinfo->global_state = DSTATE_START;
  149283. ((j_decompress_ptr) cinfo)->marker_list = NULL;
  149284. } else {
  149285. cinfo->global_state = CSTATE_START;
  149286. }
  149287. }
  149288. GLOBAL(void)
  149289. jpeg_destroy (j_common_ptr cinfo)
  149290. {
  149291. if (cinfo->mem != NULL)
  149292. (*cinfo->mem->self_destruct) (cinfo);
  149293. cinfo->mem = NULL; /* be safe if jpeg_destroy is called twice */
  149294. cinfo->global_state = 0; /* mark it destroyed */
  149295. }
  149296. GLOBAL(JQUANT_TBL *)
  149297. jpeg_alloc_quant_table (j_common_ptr cinfo)
  149298. {
  149299. JQUANT_TBL *tbl;
  149300. tbl = (JQUANT_TBL *)
  149301. (*cinfo->mem->alloc_small) (cinfo, JPOOL_PERMANENT, SIZEOF(JQUANT_TBL));
  149302. tbl->sent_table = FALSE; /* make sure this is false in any new table */
  149303. return tbl;
  149304. }
  149305. GLOBAL(JHUFF_TBL *)
  149306. jpeg_alloc_huff_table (j_common_ptr cinfo)
  149307. {
  149308. JHUFF_TBL *tbl;
  149309. tbl = (JHUFF_TBL *)
  149310. (*cinfo->mem->alloc_small) (cinfo, JPOOL_PERMANENT, SIZEOF(JHUFF_TBL));
  149311. tbl->sent_table = FALSE; /* make sure this is false in any new table */
  149312. return tbl;
  149313. }
  149314. /********* End of inlined file: jcomapi.c *********/
  149315. /********* Start of inlined file: jcparam.c *********/
  149316. #define JPEG_INTERNALS
  149317. GLOBAL(void)
  149318. jpeg_add_quant_table (j_compress_ptr cinfo, int which_tbl,
  149319. const unsigned int *basic_table,
  149320. int scale_factor, boolean force_baseline)
  149321. {
  149322. JQUANT_TBL ** qtblptr;
  149323. int i;
  149324. long temp;
  149325. if (cinfo->global_state != CSTATE_START)
  149326. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  149327. if (which_tbl < 0 || which_tbl >= NUM_QUANT_TBLS)
  149328. ERREXIT1(cinfo, JERR_DQT_INDEX, which_tbl);
  149329. qtblptr = & cinfo->quant_tbl_ptrs[which_tbl];
  149330. if (*qtblptr == NULL)
  149331. *qtblptr = jpeg_alloc_quant_table((j_common_ptr) cinfo);
  149332. for (i = 0; i < DCTSIZE2; i++) {
  149333. temp = ((long) basic_table[i] * scale_factor + 50L) / 100L;
  149334. if (temp <= 0L) temp = 1L;
  149335. if (temp > 32767L) temp = 32767L; /* max quantizer needed for 12 bits */
  149336. if (force_baseline && temp > 255L)
  149337. temp = 255L; /* limit to baseline range if requested */
  149338. (*qtblptr)->quantval[i] = (UINT16) temp;
  149339. }
  149340. (*qtblptr)->sent_table = FALSE;
  149341. }
  149342. GLOBAL(void)
  149343. jpeg_set_linear_quality (j_compress_ptr cinfo, int scale_factor,
  149344. boolean force_baseline)
  149345. {
  149346. static const unsigned int std_luminance_quant_tbl[DCTSIZE2] = {
  149347. 16, 11, 10, 16, 24, 40, 51, 61,
  149348. 12, 12, 14, 19, 26, 58, 60, 55,
  149349. 14, 13, 16, 24, 40, 57, 69, 56,
  149350. 14, 17, 22, 29, 51, 87, 80, 62,
  149351. 18, 22, 37, 56, 68, 109, 103, 77,
  149352. 24, 35, 55, 64, 81, 104, 113, 92,
  149353. 49, 64, 78, 87, 103, 121, 120, 101,
  149354. 72, 92, 95, 98, 112, 100, 103, 99
  149355. };
  149356. static const unsigned int std_chrominance_quant_tbl[DCTSIZE2] = {
  149357. 17, 18, 24, 47, 99, 99, 99, 99,
  149358. 18, 21, 26, 66, 99, 99, 99, 99,
  149359. 24, 26, 56, 99, 99, 99, 99, 99,
  149360. 47, 66, 99, 99, 99, 99, 99, 99,
  149361. 99, 99, 99, 99, 99, 99, 99, 99,
  149362. 99, 99, 99, 99, 99, 99, 99, 99,
  149363. 99, 99, 99, 99, 99, 99, 99, 99,
  149364. 99, 99, 99, 99, 99, 99, 99, 99
  149365. };
  149366. jpeg_add_quant_table(cinfo, 0, std_luminance_quant_tbl,
  149367. scale_factor, force_baseline);
  149368. jpeg_add_quant_table(cinfo, 1, std_chrominance_quant_tbl,
  149369. scale_factor, force_baseline);
  149370. }
  149371. GLOBAL(int)
  149372. jpeg_quality_scaling (int quality)
  149373. {
  149374. if (quality <= 0) quality = 1;
  149375. if (quality > 100) quality = 100;
  149376. if (quality < 50)
  149377. quality = 5000 / quality;
  149378. else
  149379. quality = 200 - quality*2;
  149380. return quality;
  149381. }
  149382. GLOBAL(void)
  149383. jpeg_set_quality (j_compress_ptr cinfo, int quality, boolean force_baseline)
  149384. {
  149385. quality = jpeg_quality_scaling(quality);
  149386. jpeg_set_linear_quality(cinfo, quality, force_baseline);
  149387. }
  149388. LOCAL(void)
  149389. add_huff_table (j_compress_ptr cinfo,
  149390. JHUFF_TBL **htblptr, const UINT8 *bits, const UINT8 *val)
  149391. {
  149392. int nsymbols, len;
  149393. if (*htblptr == NULL)
  149394. *htblptr = jpeg_alloc_huff_table((j_common_ptr) cinfo);
  149395. MEMCOPY((*htblptr)->bits, bits, SIZEOF((*htblptr)->bits));
  149396. nsymbols = 0;
  149397. for (len = 1; len <= 16; len++)
  149398. nsymbols += bits[len];
  149399. if (nsymbols < 1 || nsymbols > 256)
  149400. ERREXIT(cinfo, JERR_BAD_HUFF_TABLE);
  149401. MEMCOPY((*htblptr)->huffval, val, nsymbols * SIZEOF(UINT8));
  149402. (*htblptr)->sent_table = FALSE;
  149403. }
  149404. LOCAL(void)
  149405. std_huff_tables (j_compress_ptr cinfo)
  149406. {
  149407. static const UINT8 bits_dc_luminance[17] =
  149408. { /* 0-base */ 0, 0, 1, 5, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0 };
  149409. static const UINT8 val_dc_luminance[] =
  149410. { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 };
  149411. static const UINT8 bits_dc_chrominance[17] =
  149412. { /* 0-base */ 0, 0, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0 };
  149413. static const UINT8 val_dc_chrominance[] =
  149414. { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 };
  149415. static const UINT8 bits_ac_luminance[17] =
  149416. { /* 0-base */ 0, 0, 2, 1, 3, 3, 2, 4, 3, 5, 5, 4, 4, 0, 0, 1, 0x7d };
  149417. static const UINT8 val_ac_luminance[] =
  149418. { 0x01, 0x02, 0x03, 0x00, 0x04, 0x11, 0x05, 0x12,
  149419. 0x21, 0x31, 0x41, 0x06, 0x13, 0x51, 0x61, 0x07,
  149420. 0x22, 0x71, 0x14, 0x32, 0x81, 0x91, 0xa1, 0x08,
  149421. 0x23, 0x42, 0xb1, 0xc1, 0x15, 0x52, 0xd1, 0xf0,
  149422. 0x24, 0x33, 0x62, 0x72, 0x82, 0x09, 0x0a, 0x16,
  149423. 0x17, 0x18, 0x19, 0x1a, 0x25, 0x26, 0x27, 0x28,
  149424. 0x29, 0x2a, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39,
  149425. 0x3a, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49,
  149426. 0x4a, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59,
  149427. 0x5a, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69,
  149428. 0x6a, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79,
  149429. 0x7a, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89,
  149430. 0x8a, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98,
  149431. 0x99, 0x9a, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7,
  149432. 0xa8, 0xa9, 0xaa, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6,
  149433. 0xb7, 0xb8, 0xb9, 0xba, 0xc2, 0xc3, 0xc4, 0xc5,
  149434. 0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xd2, 0xd3, 0xd4,
  149435. 0xd5, 0xd6, 0xd7, 0xd8, 0xd9, 0xda, 0xe1, 0xe2,
  149436. 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9, 0xea,
  149437. 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8,
  149438. 0xf9, 0xfa };
  149439. static const UINT8 bits_ac_chrominance[17] =
  149440. { /* 0-base */ 0, 0, 2, 1, 2, 4, 4, 3, 4, 7, 5, 4, 4, 0, 1, 2, 0x77 };
  149441. static const UINT8 val_ac_chrominance[] =
  149442. { 0x00, 0x01, 0x02, 0x03, 0x11, 0x04, 0x05, 0x21,
  149443. 0x31, 0x06, 0x12, 0x41, 0x51, 0x07, 0x61, 0x71,
  149444. 0x13, 0x22, 0x32, 0x81, 0x08, 0x14, 0x42, 0x91,
  149445. 0xa1, 0xb1, 0xc1, 0x09, 0x23, 0x33, 0x52, 0xf0,
  149446. 0x15, 0x62, 0x72, 0xd1, 0x0a, 0x16, 0x24, 0x34,
  149447. 0xe1, 0x25, 0xf1, 0x17, 0x18, 0x19, 0x1a, 0x26,
  149448. 0x27, 0x28, 0x29, 0x2a, 0x35, 0x36, 0x37, 0x38,
  149449. 0x39, 0x3a, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48,
  149450. 0x49, 0x4a, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58,
  149451. 0x59, 0x5a, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68,
  149452. 0x69, 0x6a, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78,
  149453. 0x79, 0x7a, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87,
  149454. 0x88, 0x89, 0x8a, 0x92, 0x93, 0x94, 0x95, 0x96,
  149455. 0x97, 0x98, 0x99, 0x9a, 0xa2, 0xa3, 0xa4, 0xa5,
  149456. 0xa6, 0xa7, 0xa8, 0xa9, 0xaa, 0xb2, 0xb3, 0xb4,
  149457. 0xb5, 0xb6, 0xb7, 0xb8, 0xb9, 0xba, 0xc2, 0xc3,
  149458. 0xc4, 0xc5, 0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xd2,
  149459. 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 0xd8, 0xd9, 0xda,
  149460. 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9,
  149461. 0xea, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8,
  149462. 0xf9, 0xfa };
  149463. add_huff_table(cinfo, &cinfo->dc_huff_tbl_ptrs[0],
  149464. bits_dc_luminance, val_dc_luminance);
  149465. add_huff_table(cinfo, &cinfo->ac_huff_tbl_ptrs[0],
  149466. bits_ac_luminance, val_ac_luminance);
  149467. add_huff_table(cinfo, &cinfo->dc_huff_tbl_ptrs[1],
  149468. bits_dc_chrominance, val_dc_chrominance);
  149469. add_huff_table(cinfo, &cinfo->ac_huff_tbl_ptrs[1],
  149470. bits_ac_chrominance, val_ac_chrominance);
  149471. }
  149472. GLOBAL(void)
  149473. jpeg_set_defaults (j_compress_ptr cinfo)
  149474. {
  149475. int i;
  149476. if (cinfo->global_state != CSTATE_START)
  149477. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  149478. if (cinfo->comp_info == NULL)
  149479. cinfo->comp_info = (jpeg_component_info *)
  149480. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
  149481. MAX_COMPONENTS * SIZEOF(jpeg_component_info));
  149482. cinfo->data_precision = BITS_IN_JSAMPLE;
  149483. jpeg_set_quality(cinfo, 75, TRUE);
  149484. std_huff_tables(cinfo);
  149485. for (i = 0; i < NUM_ARITH_TBLS; i++) {
  149486. cinfo->arith_dc_L[i] = 0;
  149487. cinfo->arith_dc_U[i] = 1;
  149488. cinfo->arith_ac_K[i] = 5;
  149489. }
  149490. cinfo->scan_info = NULL;
  149491. cinfo->num_scans = 0;
  149492. cinfo->raw_data_in = FALSE;
  149493. cinfo->arith_code = FALSE;
  149494. cinfo->optimize_coding = FALSE;
  149495. if (cinfo->data_precision > 8)
  149496. cinfo->optimize_coding = TRUE;
  149497. cinfo->CCIR601_sampling = FALSE;
  149498. cinfo->smoothing_factor = 0;
  149499. cinfo->dct_method = JDCT_DEFAULT;
  149500. cinfo->restart_interval = 0;
  149501. cinfo->restart_in_rows = 0;
  149502. cinfo->JFIF_major_version = 1; /* Default JFIF version = 1.01 */
  149503. cinfo->JFIF_minor_version = 1;
  149504. cinfo->density_unit = 0; /* Pixel size is unknown by default */
  149505. cinfo->X_density = 1; /* Pixel aspect ratio is square by default */
  149506. cinfo->Y_density = 1;
  149507. jpeg_default_colorspace(cinfo);
  149508. }
  149509. GLOBAL(void)
  149510. jpeg_default_colorspace (j_compress_ptr cinfo)
  149511. {
  149512. switch (cinfo->in_color_space) {
  149513. case JCS_GRAYSCALE:
  149514. jpeg_set_colorspace(cinfo, JCS_GRAYSCALE);
  149515. break;
  149516. case JCS_RGB:
  149517. jpeg_set_colorspace(cinfo, JCS_YCbCr);
  149518. break;
  149519. case JCS_YCbCr:
  149520. jpeg_set_colorspace(cinfo, JCS_YCbCr);
  149521. break;
  149522. case JCS_CMYK:
  149523. jpeg_set_colorspace(cinfo, JCS_CMYK); /* By default, no translation */
  149524. break;
  149525. case JCS_YCCK:
  149526. jpeg_set_colorspace(cinfo, JCS_YCCK);
  149527. break;
  149528. case JCS_UNKNOWN:
  149529. jpeg_set_colorspace(cinfo, JCS_UNKNOWN);
  149530. break;
  149531. default:
  149532. ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
  149533. }
  149534. }
  149535. GLOBAL(void)
  149536. jpeg_set_colorspace (j_compress_ptr cinfo, J_COLOR_SPACE colorspace)
  149537. {
  149538. jpeg_component_info * compptr;
  149539. int ci;
  149540. #define SET_COMP(index,id,hsamp,vsamp,quant,dctbl,actbl) \
  149541. (compptr = &cinfo->comp_info[index], \
  149542. compptr->component_id = (id), \
  149543. compptr->h_samp_factor = (hsamp), \
  149544. compptr->v_samp_factor = (vsamp), \
  149545. compptr->quant_tbl_no = (quant), \
  149546. compptr->dc_tbl_no = (dctbl), \
  149547. compptr->ac_tbl_no = (actbl) )
  149548. if (cinfo->global_state != CSTATE_START)
  149549. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  149550. cinfo->jpeg_color_space = colorspace;
  149551. cinfo->write_JFIF_header = FALSE; /* No marker for non-JFIF colorspaces */
  149552. cinfo->write_Adobe_marker = FALSE; /* write no Adobe marker by default */
  149553. switch (colorspace) {
  149554. case JCS_GRAYSCALE:
  149555. cinfo->write_JFIF_header = TRUE; /* Write a JFIF marker */
  149556. cinfo->num_components = 1;
  149557. SET_COMP(0, 1, 1,1, 0, 0,0);
  149558. break;
  149559. case JCS_RGB:
  149560. cinfo->write_Adobe_marker = TRUE; /* write Adobe marker to flag RGB */
  149561. cinfo->num_components = 3;
  149562. SET_COMP(0, 0x52 /* 'R' */, 1,1, 0, 0,0);
  149563. SET_COMP(1, 0x47 /* 'G' */, 1,1, 0, 0,0);
  149564. SET_COMP(2, 0x42 /* 'B' */, 1,1, 0, 0,0);
  149565. break;
  149566. case JCS_YCbCr:
  149567. cinfo->write_JFIF_header = TRUE; /* Write a JFIF marker */
  149568. cinfo->num_components = 3;
  149569. SET_COMP(0, 1, 2,2, 0, 0,0);
  149570. SET_COMP(1, 2, 1,1, 1, 1,1);
  149571. SET_COMP(2, 3, 1,1, 1, 1,1);
  149572. break;
  149573. case JCS_CMYK:
  149574. cinfo->write_Adobe_marker = TRUE; /* write Adobe marker to flag CMYK */
  149575. cinfo->num_components = 4;
  149576. SET_COMP(0, 0x43 /* 'C' */, 1,1, 0, 0,0);
  149577. SET_COMP(1, 0x4D /* 'M' */, 1,1, 0, 0,0);
  149578. SET_COMP(2, 0x59 /* 'Y' */, 1,1, 0, 0,0);
  149579. SET_COMP(3, 0x4B /* 'K' */, 1,1, 0, 0,0);
  149580. break;
  149581. case JCS_YCCK:
  149582. cinfo->write_Adobe_marker = TRUE; /* write Adobe marker to flag YCCK */
  149583. cinfo->num_components = 4;
  149584. SET_COMP(0, 1, 2,2, 0, 0,0);
  149585. SET_COMP(1, 2, 1,1, 1, 1,1);
  149586. SET_COMP(2, 3, 1,1, 1, 1,1);
  149587. SET_COMP(3, 4, 2,2, 0, 0,0);
  149588. break;
  149589. case JCS_UNKNOWN:
  149590. cinfo->num_components = cinfo->input_components;
  149591. if (cinfo->num_components < 1 || cinfo->num_components > MAX_COMPONENTS)
  149592. ERREXIT2(cinfo, JERR_COMPONENT_COUNT, cinfo->num_components,
  149593. MAX_COMPONENTS);
  149594. for (ci = 0; ci < cinfo->num_components; ci++) {
  149595. SET_COMP(ci, ci, 1,1, 0, 0,0);
  149596. }
  149597. break;
  149598. default:
  149599. ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
  149600. }
  149601. }
  149602. #ifdef C_PROGRESSIVE_SUPPORTED
  149603. LOCAL(jpeg_scan_info *)
  149604. fill_a_scan (jpeg_scan_info * scanptr, int ci,
  149605. int Ss, int Se, int Ah, int Al)
  149606. {
  149607. scanptr->comps_in_scan = 1;
  149608. scanptr->component_index[0] = ci;
  149609. scanptr->Ss = Ss;
  149610. scanptr->Se = Se;
  149611. scanptr->Ah = Ah;
  149612. scanptr->Al = Al;
  149613. scanptr++;
  149614. return scanptr;
  149615. }
  149616. LOCAL(jpeg_scan_info *)
  149617. fill_scans (jpeg_scan_info * scanptr, int ncomps,
  149618. int Ss, int Se, int Ah, int Al)
  149619. {
  149620. int ci;
  149621. for (ci = 0; ci < ncomps; ci++) {
  149622. scanptr->comps_in_scan = 1;
  149623. scanptr->component_index[0] = ci;
  149624. scanptr->Ss = Ss;
  149625. scanptr->Se = Se;
  149626. scanptr->Ah = Ah;
  149627. scanptr->Al = Al;
  149628. scanptr++;
  149629. }
  149630. return scanptr;
  149631. }
  149632. LOCAL(jpeg_scan_info *)
  149633. fill_dc_scans (jpeg_scan_info * scanptr, int ncomps, int Ah, int Al)
  149634. {
  149635. int ci;
  149636. if (ncomps <= MAX_COMPS_IN_SCAN) {
  149637. scanptr->comps_in_scan = ncomps;
  149638. for (ci = 0; ci < ncomps; ci++)
  149639. scanptr->component_index[ci] = ci;
  149640. scanptr->Ss = scanptr->Se = 0;
  149641. scanptr->Ah = Ah;
  149642. scanptr->Al = Al;
  149643. scanptr++;
  149644. } else {
  149645. scanptr = fill_scans(scanptr, ncomps, 0, 0, Ah, Al);
  149646. }
  149647. return scanptr;
  149648. }
  149649. GLOBAL(void)
  149650. jpeg_simple_progression (j_compress_ptr cinfo)
  149651. {
  149652. int ncomps = cinfo->num_components;
  149653. int nscans;
  149654. jpeg_scan_info * scanptr;
  149655. if (cinfo->global_state != CSTATE_START)
  149656. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  149657. if (ncomps == 3 && cinfo->jpeg_color_space == JCS_YCbCr) {
  149658. nscans = 10;
  149659. } else {
  149660. if (ncomps > MAX_COMPS_IN_SCAN)
  149661. nscans = 6 * ncomps; /* 2 DC + 4 AC scans per component */
  149662. else
  149663. nscans = 2 + 4 * ncomps; /* 2 DC scans; 4 AC scans per component */
  149664. }
  149665. if (cinfo->script_space == NULL || cinfo->script_space_size < nscans) {
  149666. cinfo->script_space_size = MAX(nscans, 10);
  149667. cinfo->script_space = (jpeg_scan_info *)
  149668. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
  149669. cinfo->script_space_size * SIZEOF(jpeg_scan_info));
  149670. }
  149671. scanptr = cinfo->script_space;
  149672. cinfo->scan_info = scanptr;
  149673. cinfo->num_scans = nscans;
  149674. if (ncomps == 3 && cinfo->jpeg_color_space == JCS_YCbCr) {
  149675. scanptr = fill_dc_scans(scanptr, ncomps, 0, 1);
  149676. scanptr = fill_a_scan(scanptr, 0, 1, 5, 0, 2);
  149677. scanptr = fill_a_scan(scanptr, 2, 1, 63, 0, 1);
  149678. scanptr = fill_a_scan(scanptr, 1, 1, 63, 0, 1);
  149679. scanptr = fill_a_scan(scanptr, 0, 6, 63, 0, 2);
  149680. scanptr = fill_a_scan(scanptr, 0, 1, 63, 2, 1);
  149681. scanptr = fill_dc_scans(scanptr, ncomps, 1, 0);
  149682. scanptr = fill_a_scan(scanptr, 2, 1, 63, 1, 0);
  149683. scanptr = fill_a_scan(scanptr, 1, 1, 63, 1, 0);
  149684. scanptr = fill_a_scan(scanptr, 0, 1, 63, 1, 0);
  149685. } else {
  149686. scanptr = fill_dc_scans(scanptr, ncomps, 0, 1);
  149687. scanptr = fill_scans(scanptr, ncomps, 1, 5, 0, 2);
  149688. scanptr = fill_scans(scanptr, ncomps, 6, 63, 0, 2);
  149689. scanptr = fill_scans(scanptr, ncomps, 1, 63, 2, 1);
  149690. scanptr = fill_dc_scans(scanptr, ncomps, 1, 0);
  149691. scanptr = fill_scans(scanptr, ncomps, 1, 63, 1, 0);
  149692. }
  149693. }
  149694. #endif /* C_PROGRESSIVE_SUPPORTED */
  149695. /********* End of inlined file: jcparam.c *********/
  149696. /********* Start of inlined file: jcphuff.c *********/
  149697. #define JPEG_INTERNALS
  149698. #ifdef C_PROGRESSIVE_SUPPORTED
  149699. typedef struct {
  149700. struct jpeg_entropy_encoder pub; /* public fields */
  149701. boolean gather_statistics;
  149702. JOCTET * next_output_byte; /* => next byte to write in buffer */
  149703. size_t free_in_buffer; /* # of byte spaces remaining in buffer */
  149704. INT32 put_buffer; /* current bit-accumulation buffer */
  149705. int put_bits; /* # of bits now in it */
  149706. j_compress_ptr cinfo; /* link to cinfo (needed for dump_buffer) */
  149707. int last_dc_val[MAX_COMPS_IN_SCAN]; /* last DC coef for each component */
  149708. int ac_tbl_no; /* the table number of the single component */
  149709. unsigned int EOBRUN; /* run length of EOBs */
  149710. unsigned int BE; /* # of buffered correction bits before MCU */
  149711. char * bit_buffer; /* buffer for correction bits (1 per char) */
  149712. unsigned int restarts_to_go; /* MCUs left in this restart interval */
  149713. int next_restart_num; /* next restart number to write (0-7) */
  149714. c_derived_tbl * derived_tbls[NUM_HUFF_TBLS];
  149715. long * count_ptrs[NUM_HUFF_TBLS];
  149716. } phuff_entropy_encoder;
  149717. typedef phuff_entropy_encoder * phuff_entropy_ptr;
  149718. #define MAX_CORR_BITS 1000 /* Max # of correction bits I can buffer */
  149719. #ifdef RIGHT_SHIFT_IS_UNSIGNED
  149720. #define ISHIFT_TEMPS int ishift_temp;
  149721. #define IRIGHT_SHIFT(x,shft) \
  149722. ((ishift_temp = (x)) < 0 ? \
  149723. (ishift_temp >> (shft)) | ((~0) << (16-(shft))) : \
  149724. (ishift_temp >> (shft)))
  149725. #else
  149726. #define ISHIFT_TEMPS
  149727. #define IRIGHT_SHIFT(x,shft) ((x) >> (shft))
  149728. #endif
  149729. METHODDEF(boolean) encode_mcu_DC_first JPP((j_compress_ptr cinfo,
  149730. JBLOCKROW *MCU_data));
  149731. METHODDEF(boolean) encode_mcu_AC_first JPP((j_compress_ptr cinfo,
  149732. JBLOCKROW *MCU_data));
  149733. METHODDEF(boolean) encode_mcu_DC_refine JPP((j_compress_ptr cinfo,
  149734. JBLOCKROW *MCU_data));
  149735. METHODDEF(boolean) encode_mcu_AC_refine JPP((j_compress_ptr cinfo,
  149736. JBLOCKROW *MCU_data));
  149737. METHODDEF(void) finish_pass_phuff JPP((j_compress_ptr cinfo));
  149738. METHODDEF(void) finish_pass_gather_phuff JPP((j_compress_ptr cinfo));
  149739. METHODDEF(void)
  149740. start_pass_phuff (j_compress_ptr cinfo, boolean gather_statistics)
  149741. {
  149742. phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy;
  149743. boolean is_DC_band;
  149744. int ci, tbl;
  149745. jpeg_component_info * compptr;
  149746. entropy->cinfo = cinfo;
  149747. entropy->gather_statistics = gather_statistics;
  149748. is_DC_band = (cinfo->Ss == 0);
  149749. if (cinfo->Ah == 0) {
  149750. if (is_DC_band)
  149751. entropy->pub.encode_mcu = encode_mcu_DC_first;
  149752. else
  149753. entropy->pub.encode_mcu = encode_mcu_AC_first;
  149754. } else {
  149755. if (is_DC_band)
  149756. entropy->pub.encode_mcu = encode_mcu_DC_refine;
  149757. else {
  149758. entropy->pub.encode_mcu = encode_mcu_AC_refine;
  149759. if (entropy->bit_buffer == NULL)
  149760. entropy->bit_buffer = (char *)
  149761. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  149762. MAX_CORR_BITS * SIZEOF(char));
  149763. }
  149764. }
  149765. if (gather_statistics)
  149766. entropy->pub.finish_pass = finish_pass_gather_phuff;
  149767. else
  149768. entropy->pub.finish_pass = finish_pass_phuff;
  149769. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  149770. compptr = cinfo->cur_comp_info[ci];
  149771. entropy->last_dc_val[ci] = 0;
  149772. if (is_DC_band) {
  149773. if (cinfo->Ah != 0) /* DC refinement needs no table */
  149774. continue;
  149775. tbl = compptr->dc_tbl_no;
  149776. } else {
  149777. entropy->ac_tbl_no = tbl = compptr->ac_tbl_no;
  149778. }
  149779. if (gather_statistics) {
  149780. if (tbl < 0 || tbl >= NUM_HUFF_TBLS)
  149781. ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, tbl);
  149782. if (entropy->count_ptrs[tbl] == NULL)
  149783. entropy->count_ptrs[tbl] = (long *)
  149784. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  149785. 257 * SIZEOF(long));
  149786. MEMZERO(entropy->count_ptrs[tbl], 257 * SIZEOF(long));
  149787. } else {
  149788. jpeg_make_c_derived_tbl(cinfo, is_DC_band, tbl,
  149789. & entropy->derived_tbls[tbl]);
  149790. }
  149791. }
  149792. entropy->EOBRUN = 0;
  149793. entropy->BE = 0;
  149794. entropy->put_buffer = 0;
  149795. entropy->put_bits = 0;
  149796. entropy->restarts_to_go = cinfo->restart_interval;
  149797. entropy->next_restart_num = 0;
  149798. }
  149799. #define emit_byte(entropy,val) \
  149800. { *(entropy)->next_output_byte++ = (JOCTET) (val); \
  149801. if (--(entropy)->free_in_buffer == 0) \
  149802. dump_buffer_p(entropy); }
  149803. LOCAL(void)
  149804. dump_buffer_p (phuff_entropy_ptr entropy)
  149805. {
  149806. struct jpeg_destination_mgr * dest = entropy->cinfo->dest;
  149807. if (! (*dest->empty_output_buffer) (entropy->cinfo))
  149808. ERREXIT(entropy->cinfo, JERR_CANT_SUSPEND);
  149809. entropy->next_output_byte = dest->next_output_byte;
  149810. entropy->free_in_buffer = dest->free_in_buffer;
  149811. }
  149812. INLINE
  149813. LOCAL(void)
  149814. emit_bits_p (phuff_entropy_ptr entropy, unsigned int code, int size)
  149815. {
  149816. register INT32 put_buffer = (INT32) code;
  149817. register int put_bits = entropy->put_bits;
  149818. if (size == 0)
  149819. ERREXIT(entropy->cinfo, JERR_HUFF_MISSING_CODE);
  149820. if (entropy->gather_statistics)
  149821. return; /* do nothing if we're only getting stats */
  149822. put_buffer &= (((INT32) 1)<<size) - 1; /* mask off any extra bits in code */
  149823. put_bits += size; /* new number of bits in buffer */
  149824. put_buffer <<= 24 - put_bits; /* align incoming bits */
  149825. put_buffer |= entropy->put_buffer; /* and merge with old buffer contents */
  149826. while (put_bits >= 8) {
  149827. int c = (int) ((put_buffer >> 16) & 0xFF);
  149828. emit_byte(entropy, c);
  149829. if (c == 0xFF) { /* need to stuff a zero byte? */
  149830. emit_byte(entropy, 0);
  149831. }
  149832. put_buffer <<= 8;
  149833. put_bits -= 8;
  149834. }
  149835. entropy->put_buffer = put_buffer; /* update variables */
  149836. entropy->put_bits = put_bits;
  149837. }
  149838. LOCAL(void)
  149839. flush_bits_p (phuff_entropy_ptr entropy)
  149840. {
  149841. emit_bits_p(entropy, 0x7F, 7); /* fill any partial byte with ones */
  149842. entropy->put_buffer = 0; /* and reset bit-buffer to empty */
  149843. entropy->put_bits = 0;
  149844. }
  149845. INLINE
  149846. LOCAL(void)
  149847. emit_symbol (phuff_entropy_ptr entropy, int tbl_no, int symbol)
  149848. {
  149849. if (entropy->gather_statistics)
  149850. entropy->count_ptrs[tbl_no][symbol]++;
  149851. else {
  149852. c_derived_tbl * tbl = entropy->derived_tbls[tbl_no];
  149853. emit_bits_p(entropy, tbl->ehufco[symbol], tbl->ehufsi[symbol]);
  149854. }
  149855. }
  149856. LOCAL(void)
  149857. emit_buffered_bits (phuff_entropy_ptr entropy, char * bufstart,
  149858. unsigned int nbits)
  149859. {
  149860. if (entropy->gather_statistics)
  149861. return; /* no real work */
  149862. while (nbits > 0) {
  149863. emit_bits_p(entropy, (unsigned int) (*bufstart), 1);
  149864. bufstart++;
  149865. nbits--;
  149866. }
  149867. }
  149868. LOCAL(void)
  149869. emit_eobrun (phuff_entropy_ptr entropy)
  149870. {
  149871. register int temp, nbits;
  149872. if (entropy->EOBRUN > 0) { /* if there is any pending EOBRUN */
  149873. temp = entropy->EOBRUN;
  149874. nbits = 0;
  149875. while ((temp >>= 1))
  149876. nbits++;
  149877. if (nbits > 14)
  149878. ERREXIT(entropy->cinfo, JERR_HUFF_MISSING_CODE);
  149879. emit_symbol(entropy, entropy->ac_tbl_no, nbits << 4);
  149880. if (nbits)
  149881. emit_bits_p(entropy, entropy->EOBRUN, nbits);
  149882. entropy->EOBRUN = 0;
  149883. emit_buffered_bits(entropy, entropy->bit_buffer, entropy->BE);
  149884. entropy->BE = 0;
  149885. }
  149886. }
  149887. LOCAL(void)
  149888. emit_restart_p (phuff_entropy_ptr entropy, int restart_num)
  149889. {
  149890. int ci;
  149891. emit_eobrun(entropy);
  149892. if (! entropy->gather_statistics) {
  149893. flush_bits_p(entropy);
  149894. emit_byte(entropy, 0xFF);
  149895. emit_byte(entropy, JPEG_RST0 + restart_num);
  149896. }
  149897. if (entropy->cinfo->Ss == 0) {
  149898. for (ci = 0; ci < entropy->cinfo->comps_in_scan; ci++)
  149899. entropy->last_dc_val[ci] = 0;
  149900. } else {
  149901. entropy->EOBRUN = 0;
  149902. entropy->BE = 0;
  149903. }
  149904. }
  149905. METHODDEF(boolean)
  149906. encode_mcu_DC_first (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
  149907. {
  149908. phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy;
  149909. register int temp, temp2;
  149910. register int nbits;
  149911. int blkn, ci;
  149912. int Al = cinfo->Al;
  149913. JBLOCKROW block;
  149914. jpeg_component_info * compptr;
  149915. ISHIFT_TEMPS
  149916. entropy->next_output_byte = cinfo->dest->next_output_byte;
  149917. entropy->free_in_buffer = cinfo->dest->free_in_buffer;
  149918. if (cinfo->restart_interval)
  149919. if (entropy->restarts_to_go == 0)
  149920. emit_restart_p(entropy, entropy->next_restart_num);
  149921. for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
  149922. block = MCU_data[blkn];
  149923. ci = cinfo->MCU_membership[blkn];
  149924. compptr = cinfo->cur_comp_info[ci];
  149925. temp2 = IRIGHT_SHIFT((int) ((*block)[0]), Al);
  149926. temp = temp2 - entropy->last_dc_val[ci];
  149927. entropy->last_dc_val[ci] = temp2;
  149928. temp2 = temp;
  149929. if (temp < 0) {
  149930. temp = -temp; /* temp is abs value of input */
  149931. temp2--;
  149932. }
  149933. nbits = 0;
  149934. while (temp) {
  149935. nbits++;
  149936. temp >>= 1;
  149937. }
  149938. if (nbits > MAX_COEF_BITS+1)
  149939. ERREXIT(cinfo, JERR_BAD_DCT_COEF);
  149940. emit_symbol(entropy, compptr->dc_tbl_no, nbits);
  149941. if (nbits) /* emit_bits rejects calls with size 0 */
  149942. emit_bits_p(entropy, (unsigned int) temp2, nbits);
  149943. }
  149944. cinfo->dest->next_output_byte = entropy->next_output_byte;
  149945. cinfo->dest->free_in_buffer = entropy->free_in_buffer;
  149946. if (cinfo->restart_interval) {
  149947. if (entropy->restarts_to_go == 0) {
  149948. entropy->restarts_to_go = cinfo->restart_interval;
  149949. entropy->next_restart_num++;
  149950. entropy->next_restart_num &= 7;
  149951. }
  149952. entropy->restarts_to_go--;
  149953. }
  149954. return TRUE;
  149955. }
  149956. METHODDEF(boolean)
  149957. encode_mcu_AC_first (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
  149958. {
  149959. phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy;
  149960. register int temp, temp2;
  149961. register int nbits;
  149962. register int r, k;
  149963. int Se = cinfo->Se;
  149964. int Al = cinfo->Al;
  149965. JBLOCKROW block;
  149966. entropy->next_output_byte = cinfo->dest->next_output_byte;
  149967. entropy->free_in_buffer = cinfo->dest->free_in_buffer;
  149968. if (cinfo->restart_interval)
  149969. if (entropy->restarts_to_go == 0)
  149970. emit_restart_p(entropy, entropy->next_restart_num);
  149971. block = MCU_data[0];
  149972. r = 0; /* r = run length of zeros */
  149973. for (k = cinfo->Ss; k <= Se; k++) {
  149974. if ((temp = (*block)[jpeg_natural_order[k]]) == 0) {
  149975. r++;
  149976. continue;
  149977. }
  149978. if (temp < 0) {
  149979. temp = -temp; /* temp is abs value of input */
  149980. temp >>= Al; /* apply the point transform */
  149981. temp2 = ~temp;
  149982. } else {
  149983. temp >>= Al; /* apply the point transform */
  149984. temp2 = temp;
  149985. }
  149986. if (temp == 0) {
  149987. r++;
  149988. continue;
  149989. }
  149990. if (entropy->EOBRUN > 0)
  149991. emit_eobrun(entropy);
  149992. while (r > 15) {
  149993. emit_symbol(entropy, entropy->ac_tbl_no, 0xF0);
  149994. r -= 16;
  149995. }
  149996. nbits = 1; /* there must be at least one 1 bit */
  149997. while ((temp >>= 1))
  149998. nbits++;
  149999. if (nbits > MAX_COEF_BITS)
  150000. ERREXIT(cinfo, JERR_BAD_DCT_COEF);
  150001. emit_symbol(entropy, entropy->ac_tbl_no, (r << 4) + nbits);
  150002. emit_bits_p(entropy, (unsigned int) temp2, nbits);
  150003. r = 0; /* reset zero run length */
  150004. }
  150005. if (r > 0) { /* If there are trailing zeroes, */
  150006. entropy->EOBRUN++; /* count an EOB */
  150007. if (entropy->EOBRUN == 0x7FFF)
  150008. emit_eobrun(entropy); /* force it out to avoid overflow */
  150009. }
  150010. cinfo->dest->next_output_byte = entropy->next_output_byte;
  150011. cinfo->dest->free_in_buffer = entropy->free_in_buffer;
  150012. if (cinfo->restart_interval) {
  150013. if (entropy->restarts_to_go == 0) {
  150014. entropy->restarts_to_go = cinfo->restart_interval;
  150015. entropy->next_restart_num++;
  150016. entropy->next_restart_num &= 7;
  150017. }
  150018. entropy->restarts_to_go--;
  150019. }
  150020. return TRUE;
  150021. }
  150022. METHODDEF(boolean)
  150023. encode_mcu_DC_refine (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
  150024. {
  150025. phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy;
  150026. register int temp;
  150027. int blkn;
  150028. int Al = cinfo->Al;
  150029. JBLOCKROW block;
  150030. entropy->next_output_byte = cinfo->dest->next_output_byte;
  150031. entropy->free_in_buffer = cinfo->dest->free_in_buffer;
  150032. if (cinfo->restart_interval)
  150033. if (entropy->restarts_to_go == 0)
  150034. emit_restart_p(entropy, entropy->next_restart_num);
  150035. for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
  150036. block = MCU_data[blkn];
  150037. temp = (*block)[0];
  150038. emit_bits_p(entropy, (unsigned int) (temp >> Al), 1);
  150039. }
  150040. cinfo->dest->next_output_byte = entropy->next_output_byte;
  150041. cinfo->dest->free_in_buffer = entropy->free_in_buffer;
  150042. if (cinfo->restart_interval) {
  150043. if (entropy->restarts_to_go == 0) {
  150044. entropy->restarts_to_go = cinfo->restart_interval;
  150045. entropy->next_restart_num++;
  150046. entropy->next_restart_num &= 7;
  150047. }
  150048. entropy->restarts_to_go--;
  150049. }
  150050. return TRUE;
  150051. }
  150052. METHODDEF(boolean)
  150053. encode_mcu_AC_refine (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
  150054. {
  150055. phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy;
  150056. register int temp;
  150057. register int r, k;
  150058. int EOB;
  150059. char *BR_buffer;
  150060. unsigned int BR;
  150061. int Se = cinfo->Se;
  150062. int Al = cinfo->Al;
  150063. JBLOCKROW block;
  150064. int absvalues[DCTSIZE2];
  150065. entropy->next_output_byte = cinfo->dest->next_output_byte;
  150066. entropy->free_in_buffer = cinfo->dest->free_in_buffer;
  150067. if (cinfo->restart_interval)
  150068. if (entropy->restarts_to_go == 0)
  150069. emit_restart_p(entropy, entropy->next_restart_num);
  150070. block = MCU_data[0];
  150071. EOB = 0;
  150072. for (k = cinfo->Ss; k <= Se; k++) {
  150073. temp = (*block)[jpeg_natural_order[k]];
  150074. if (temp < 0)
  150075. temp = -temp; /* temp is abs value of input */
  150076. temp >>= Al; /* apply the point transform */
  150077. absvalues[k] = temp; /* save abs value for main pass */
  150078. if (temp == 1)
  150079. EOB = k; /* EOB = index of last newly-nonzero coef */
  150080. }
  150081. r = 0; /* r = run length of zeros */
  150082. BR = 0; /* BR = count of buffered bits added now */
  150083. BR_buffer = entropy->bit_buffer + entropy->BE; /* Append bits to buffer */
  150084. for (k = cinfo->Ss; k <= Se; k++) {
  150085. if ((temp = absvalues[k]) == 0) {
  150086. r++;
  150087. continue;
  150088. }
  150089. while (r > 15 && k <= EOB) {
  150090. emit_eobrun(entropy);
  150091. emit_symbol(entropy, entropy->ac_tbl_no, 0xF0);
  150092. r -= 16;
  150093. emit_buffered_bits(entropy, BR_buffer, BR);
  150094. BR_buffer = entropy->bit_buffer; /* BE bits are gone now */
  150095. BR = 0;
  150096. }
  150097. if (temp > 1) {
  150098. BR_buffer[BR++] = (char) (temp & 1);
  150099. continue;
  150100. }
  150101. emit_eobrun(entropy);
  150102. emit_symbol(entropy, entropy->ac_tbl_no, (r << 4) + 1);
  150103. temp = ((*block)[jpeg_natural_order[k]] < 0) ? 0 : 1;
  150104. emit_bits_p(entropy, (unsigned int) temp, 1);
  150105. emit_buffered_bits(entropy, BR_buffer, BR);
  150106. BR_buffer = entropy->bit_buffer; /* BE bits are gone now */
  150107. BR = 0;
  150108. r = 0; /* reset zero run length */
  150109. }
  150110. if (r > 0 || BR > 0) { /* If there are trailing zeroes, */
  150111. entropy->EOBRUN++; /* count an EOB */
  150112. entropy->BE += BR; /* concat my correction bits to older ones */
  150113. if (entropy->EOBRUN == 0x7FFF || entropy->BE > (MAX_CORR_BITS-DCTSIZE2+1))
  150114. emit_eobrun(entropy);
  150115. }
  150116. cinfo->dest->next_output_byte = entropy->next_output_byte;
  150117. cinfo->dest->free_in_buffer = entropy->free_in_buffer;
  150118. if (cinfo->restart_interval) {
  150119. if (entropy->restarts_to_go == 0) {
  150120. entropy->restarts_to_go = cinfo->restart_interval;
  150121. entropy->next_restart_num++;
  150122. entropy->next_restart_num &= 7;
  150123. }
  150124. entropy->restarts_to_go--;
  150125. }
  150126. return TRUE;
  150127. }
  150128. METHODDEF(void)
  150129. finish_pass_phuff (j_compress_ptr cinfo)
  150130. {
  150131. phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy;
  150132. entropy->next_output_byte = cinfo->dest->next_output_byte;
  150133. entropy->free_in_buffer = cinfo->dest->free_in_buffer;
  150134. emit_eobrun(entropy);
  150135. flush_bits_p(entropy);
  150136. cinfo->dest->next_output_byte = entropy->next_output_byte;
  150137. cinfo->dest->free_in_buffer = entropy->free_in_buffer;
  150138. }
  150139. METHODDEF(void)
  150140. finish_pass_gather_phuff (j_compress_ptr cinfo)
  150141. {
  150142. phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy;
  150143. boolean is_DC_band;
  150144. int ci, tbl;
  150145. jpeg_component_info * compptr;
  150146. JHUFF_TBL **htblptr;
  150147. boolean did[NUM_HUFF_TBLS];
  150148. emit_eobrun(entropy);
  150149. is_DC_band = (cinfo->Ss == 0);
  150150. MEMZERO(did, SIZEOF(did));
  150151. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  150152. compptr = cinfo->cur_comp_info[ci];
  150153. if (is_DC_band) {
  150154. if (cinfo->Ah != 0) /* DC refinement needs no table */
  150155. continue;
  150156. tbl = compptr->dc_tbl_no;
  150157. } else {
  150158. tbl = compptr->ac_tbl_no;
  150159. }
  150160. if (! did[tbl]) {
  150161. if (is_DC_band)
  150162. htblptr = & cinfo->dc_huff_tbl_ptrs[tbl];
  150163. else
  150164. htblptr = & cinfo->ac_huff_tbl_ptrs[tbl];
  150165. if (*htblptr == NULL)
  150166. *htblptr = jpeg_alloc_huff_table((j_common_ptr) cinfo);
  150167. jpeg_gen_optimal_table(cinfo, *htblptr, entropy->count_ptrs[tbl]);
  150168. did[tbl] = TRUE;
  150169. }
  150170. }
  150171. }
  150172. GLOBAL(void)
  150173. jinit_phuff_encoder (j_compress_ptr cinfo)
  150174. {
  150175. phuff_entropy_ptr entropy;
  150176. int i;
  150177. entropy = (phuff_entropy_ptr)
  150178. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  150179. SIZEOF(phuff_entropy_encoder));
  150180. cinfo->entropy = (struct jpeg_entropy_encoder *) entropy;
  150181. entropy->pub.start_pass = start_pass_phuff;
  150182. for (i = 0; i < NUM_HUFF_TBLS; i++) {
  150183. entropy->derived_tbls[i] = NULL;
  150184. entropy->count_ptrs[i] = NULL;
  150185. }
  150186. entropy->bit_buffer = NULL; /* needed only in AC refinement scan */
  150187. }
  150188. #endif /* C_PROGRESSIVE_SUPPORTED */
  150189. /********* End of inlined file: jcphuff.c *********/
  150190. /********* Start of inlined file: jcprepct.c *********/
  150191. #define JPEG_INTERNALS
  150192. #ifdef INPUT_SMOOTHING_SUPPORTED
  150193. #define CONTEXT_ROWS_SUPPORTED
  150194. #endif
  150195. typedef struct {
  150196. struct jpeg_c_prep_controller pub; /* public fields */
  150197. JSAMPARRAY color_buf[MAX_COMPONENTS];
  150198. JDIMENSION rows_to_go; /* counts rows remaining in source image */
  150199. int next_buf_row; /* index of next row to store in color_buf */
  150200. #ifdef CONTEXT_ROWS_SUPPORTED /* only needed for context case */
  150201. int this_row_group; /* starting row index of group to process */
  150202. int next_buf_stop; /* downsample when we reach this index */
  150203. #endif
  150204. } my_prep_controller;
  150205. typedef my_prep_controller * my_prep_ptr;
  150206. METHODDEF(void)
  150207. start_pass_prep (j_compress_ptr cinfo, J_BUF_MODE pass_mode)
  150208. {
  150209. my_prep_ptr prep = (my_prep_ptr) cinfo->prep;
  150210. if (pass_mode != JBUF_PASS_THRU)
  150211. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  150212. prep->rows_to_go = cinfo->image_height;
  150213. prep->next_buf_row = 0;
  150214. #ifdef CONTEXT_ROWS_SUPPORTED
  150215. prep->this_row_group = 0;
  150216. prep->next_buf_stop = 2 * cinfo->max_v_samp_factor;
  150217. #endif
  150218. }
  150219. LOCAL(void)
  150220. expand_bottom_edge (JSAMPARRAY image_data, JDIMENSION num_cols,
  150221. int input_rows, int output_rows)
  150222. {
  150223. register int row;
  150224. for (row = input_rows; row < output_rows; row++) {
  150225. jcopy_sample_rows(image_data, input_rows-1, image_data, row,
  150226. 1, num_cols);
  150227. }
  150228. }
  150229. METHODDEF(void)
  150230. pre_process_data (j_compress_ptr cinfo,
  150231. JSAMPARRAY input_buf, JDIMENSION *in_row_ctr,
  150232. JDIMENSION in_rows_avail,
  150233. JSAMPIMAGE output_buf, JDIMENSION *out_row_group_ctr,
  150234. JDIMENSION out_row_groups_avail)
  150235. {
  150236. my_prep_ptr prep = (my_prep_ptr) cinfo->prep;
  150237. int numrows, ci;
  150238. JDIMENSION inrows;
  150239. jpeg_component_info * compptr;
  150240. while (*in_row_ctr < in_rows_avail &&
  150241. *out_row_group_ctr < out_row_groups_avail) {
  150242. inrows = in_rows_avail - *in_row_ctr;
  150243. numrows = cinfo->max_v_samp_factor - prep->next_buf_row;
  150244. numrows = (int) MIN((JDIMENSION) numrows, inrows);
  150245. (*cinfo->cconvert->color_convert) (cinfo, input_buf + *in_row_ctr,
  150246. prep->color_buf,
  150247. (JDIMENSION) prep->next_buf_row,
  150248. numrows);
  150249. *in_row_ctr += numrows;
  150250. prep->next_buf_row += numrows;
  150251. prep->rows_to_go -= numrows;
  150252. if (prep->rows_to_go == 0 &&
  150253. prep->next_buf_row < cinfo->max_v_samp_factor) {
  150254. for (ci = 0; ci < cinfo->num_components; ci++) {
  150255. expand_bottom_edge(prep->color_buf[ci], cinfo->image_width,
  150256. prep->next_buf_row, cinfo->max_v_samp_factor);
  150257. }
  150258. prep->next_buf_row = cinfo->max_v_samp_factor;
  150259. }
  150260. if (prep->next_buf_row == cinfo->max_v_samp_factor) {
  150261. (*cinfo->downsample->downsample) (cinfo,
  150262. prep->color_buf, (JDIMENSION) 0,
  150263. output_buf, *out_row_group_ctr);
  150264. prep->next_buf_row = 0;
  150265. (*out_row_group_ctr)++;
  150266. }
  150267. if (prep->rows_to_go == 0 &&
  150268. *out_row_group_ctr < out_row_groups_avail) {
  150269. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  150270. ci++, compptr++) {
  150271. expand_bottom_edge(output_buf[ci],
  150272. compptr->width_in_blocks * DCTSIZE,
  150273. (int) (*out_row_group_ctr * compptr->v_samp_factor),
  150274. (int) (out_row_groups_avail * compptr->v_samp_factor));
  150275. }
  150276. *out_row_group_ctr = out_row_groups_avail;
  150277. break; /* can exit outer loop without test */
  150278. }
  150279. }
  150280. }
  150281. #ifdef CONTEXT_ROWS_SUPPORTED
  150282. METHODDEF(void)
  150283. pre_process_context (j_compress_ptr cinfo,
  150284. JSAMPARRAY input_buf, JDIMENSION *in_row_ctr,
  150285. JDIMENSION in_rows_avail,
  150286. JSAMPIMAGE output_buf, JDIMENSION *out_row_group_ctr,
  150287. JDIMENSION out_row_groups_avail)
  150288. {
  150289. my_prep_ptr prep = (my_prep_ptr) cinfo->prep;
  150290. int numrows, ci;
  150291. int buf_height = cinfo->max_v_samp_factor * 3;
  150292. JDIMENSION inrows;
  150293. while (*out_row_group_ctr < out_row_groups_avail) {
  150294. if (*in_row_ctr < in_rows_avail) {
  150295. inrows = in_rows_avail - *in_row_ctr;
  150296. numrows = prep->next_buf_stop - prep->next_buf_row;
  150297. numrows = (int) MIN((JDIMENSION) numrows, inrows);
  150298. (*cinfo->cconvert->color_convert) (cinfo, input_buf + *in_row_ctr,
  150299. prep->color_buf,
  150300. (JDIMENSION) prep->next_buf_row,
  150301. numrows);
  150302. if (prep->rows_to_go == cinfo->image_height) {
  150303. for (ci = 0; ci < cinfo->num_components; ci++) {
  150304. int row;
  150305. for (row = 1; row <= cinfo->max_v_samp_factor; row++) {
  150306. jcopy_sample_rows(prep->color_buf[ci], 0,
  150307. prep->color_buf[ci], -row,
  150308. 1, cinfo->image_width);
  150309. }
  150310. }
  150311. }
  150312. *in_row_ctr += numrows;
  150313. prep->next_buf_row += numrows;
  150314. prep->rows_to_go -= numrows;
  150315. } else {
  150316. if (prep->rows_to_go != 0)
  150317. break;
  150318. if (prep->next_buf_row < prep->next_buf_stop) {
  150319. for (ci = 0; ci < cinfo->num_components; ci++) {
  150320. expand_bottom_edge(prep->color_buf[ci], cinfo->image_width,
  150321. prep->next_buf_row, prep->next_buf_stop);
  150322. }
  150323. prep->next_buf_row = prep->next_buf_stop;
  150324. }
  150325. }
  150326. if (prep->next_buf_row == prep->next_buf_stop) {
  150327. (*cinfo->downsample->downsample) (cinfo,
  150328. prep->color_buf,
  150329. (JDIMENSION) prep->this_row_group,
  150330. output_buf, *out_row_group_ctr);
  150331. (*out_row_group_ctr)++;
  150332. prep->this_row_group += cinfo->max_v_samp_factor;
  150333. if (prep->this_row_group >= buf_height)
  150334. prep->this_row_group = 0;
  150335. if (prep->next_buf_row >= buf_height)
  150336. prep->next_buf_row = 0;
  150337. prep->next_buf_stop = prep->next_buf_row + cinfo->max_v_samp_factor;
  150338. }
  150339. }
  150340. }
  150341. LOCAL(void)
  150342. create_context_buffer (j_compress_ptr cinfo)
  150343. {
  150344. my_prep_ptr prep = (my_prep_ptr) cinfo->prep;
  150345. int rgroup_height = cinfo->max_v_samp_factor;
  150346. int ci, i;
  150347. jpeg_component_info * compptr;
  150348. JSAMPARRAY true_buffer, fake_buffer;
  150349. fake_buffer = (JSAMPARRAY)
  150350. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  150351. (cinfo->num_components * 5 * rgroup_height) *
  150352. SIZEOF(JSAMPROW));
  150353. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  150354. ci++, compptr++) {
  150355. true_buffer = (*cinfo->mem->alloc_sarray)
  150356. ((j_common_ptr) cinfo, JPOOL_IMAGE,
  150357. (JDIMENSION) (((long) compptr->width_in_blocks * DCTSIZE *
  150358. cinfo->max_h_samp_factor) / compptr->h_samp_factor),
  150359. (JDIMENSION) (3 * rgroup_height));
  150360. MEMCOPY(fake_buffer + rgroup_height, true_buffer,
  150361. 3 * rgroup_height * SIZEOF(JSAMPROW));
  150362. for (i = 0; i < rgroup_height; i++) {
  150363. fake_buffer[i] = true_buffer[2 * rgroup_height + i];
  150364. fake_buffer[4 * rgroup_height + i] = true_buffer[i];
  150365. }
  150366. prep->color_buf[ci] = fake_buffer + rgroup_height;
  150367. fake_buffer += 5 * rgroup_height; /* point to space for next component */
  150368. }
  150369. }
  150370. #endif /* CONTEXT_ROWS_SUPPORTED */
  150371. GLOBAL(void)
  150372. jinit_c_prep_controller (j_compress_ptr cinfo, boolean need_full_buffer)
  150373. {
  150374. my_prep_ptr prep;
  150375. int ci;
  150376. jpeg_component_info * compptr;
  150377. if (need_full_buffer) /* safety check */
  150378. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  150379. prep = (my_prep_ptr)
  150380. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  150381. SIZEOF(my_prep_controller));
  150382. cinfo->prep = (struct jpeg_c_prep_controller *) prep;
  150383. prep->pub.start_pass = start_pass_prep;
  150384. if (cinfo->downsample->need_context_rows) {
  150385. #ifdef CONTEXT_ROWS_SUPPORTED
  150386. prep->pub.pre_process_data = pre_process_context;
  150387. create_context_buffer(cinfo);
  150388. #else
  150389. ERREXIT(cinfo, JERR_NOT_COMPILED);
  150390. #endif
  150391. } else {
  150392. prep->pub.pre_process_data = pre_process_data;
  150393. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  150394. ci++, compptr++) {
  150395. prep->color_buf[ci] = (*cinfo->mem->alloc_sarray)
  150396. ((j_common_ptr) cinfo, JPOOL_IMAGE,
  150397. (JDIMENSION) (((long) compptr->width_in_blocks * DCTSIZE *
  150398. cinfo->max_h_samp_factor) / compptr->h_samp_factor),
  150399. (JDIMENSION) cinfo->max_v_samp_factor);
  150400. }
  150401. }
  150402. }
  150403. /********* End of inlined file: jcprepct.c *********/
  150404. /********* Start of inlined file: jcsample.c *********/
  150405. #define JPEG_INTERNALS
  150406. typedef JMETHOD(void, downsample1_ptr,
  150407. (j_compress_ptr cinfo, jpeg_component_info * compptr,
  150408. JSAMPARRAY input_data, JSAMPARRAY output_data));
  150409. typedef struct {
  150410. struct jpeg_downsampler pub; /* public fields */
  150411. downsample1_ptr methods[MAX_COMPONENTS];
  150412. } my_downsampler;
  150413. typedef my_downsampler * my_downsample_ptr;
  150414. METHODDEF(void)
  150415. start_pass_downsample (j_compress_ptr cinfo)
  150416. {
  150417. }
  150418. LOCAL(void)
  150419. expand_right_edge (JSAMPARRAY image_data, int num_rows,
  150420. JDIMENSION input_cols, JDIMENSION output_cols)
  150421. {
  150422. register JSAMPROW ptr;
  150423. register JSAMPLE pixval;
  150424. register int count;
  150425. int row;
  150426. int numcols = (int) (output_cols - input_cols);
  150427. if (numcols > 0) {
  150428. for (row = 0; row < num_rows; row++) {
  150429. ptr = image_data[row] + input_cols;
  150430. pixval = ptr[-1]; /* don't need GETJSAMPLE() here */
  150431. for (count = numcols; count > 0; count--)
  150432. *ptr++ = pixval;
  150433. }
  150434. }
  150435. }
  150436. METHODDEF(void)
  150437. sep_downsample (j_compress_ptr cinfo,
  150438. JSAMPIMAGE input_buf, JDIMENSION in_row_index,
  150439. JSAMPIMAGE output_buf, JDIMENSION out_row_group_index)
  150440. {
  150441. my_downsample_ptr downsample = (my_downsample_ptr) cinfo->downsample;
  150442. int ci;
  150443. jpeg_component_info * compptr;
  150444. JSAMPARRAY in_ptr, out_ptr;
  150445. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  150446. ci++, compptr++) {
  150447. in_ptr = input_buf[ci] + in_row_index;
  150448. out_ptr = output_buf[ci] + (out_row_group_index * compptr->v_samp_factor);
  150449. (*downsample->methods[ci]) (cinfo, compptr, in_ptr, out_ptr);
  150450. }
  150451. }
  150452. METHODDEF(void)
  150453. int_downsample (j_compress_ptr cinfo, jpeg_component_info * compptr,
  150454. JSAMPARRAY input_data, JSAMPARRAY output_data)
  150455. {
  150456. int inrow, outrow, h_expand, v_expand, numpix, numpix2, h, v;
  150457. JDIMENSION outcol, outcol_h; /* outcol_h == outcol*h_expand */
  150458. JDIMENSION output_cols = compptr->width_in_blocks * DCTSIZE;
  150459. JSAMPROW inptr, outptr;
  150460. INT32 outvalue;
  150461. h_expand = cinfo->max_h_samp_factor / compptr->h_samp_factor;
  150462. v_expand = cinfo->max_v_samp_factor / compptr->v_samp_factor;
  150463. numpix = h_expand * v_expand;
  150464. numpix2 = numpix/2;
  150465. expand_right_edge(input_data, cinfo->max_v_samp_factor,
  150466. cinfo->image_width, output_cols * h_expand);
  150467. inrow = 0;
  150468. for (outrow = 0; outrow < compptr->v_samp_factor; outrow++) {
  150469. outptr = output_data[outrow];
  150470. for (outcol = 0, outcol_h = 0; outcol < output_cols;
  150471. outcol++, outcol_h += h_expand) {
  150472. outvalue = 0;
  150473. for (v = 0; v < v_expand; v++) {
  150474. inptr = input_data[inrow+v] + outcol_h;
  150475. for (h = 0; h < h_expand; h++) {
  150476. outvalue += (INT32) GETJSAMPLE(*inptr++);
  150477. }
  150478. }
  150479. *outptr++ = (JSAMPLE) ((outvalue + numpix2) / numpix);
  150480. }
  150481. inrow += v_expand;
  150482. }
  150483. }
  150484. METHODDEF(void)
  150485. fullsize_downsample (j_compress_ptr cinfo, jpeg_component_info * compptr,
  150486. JSAMPARRAY input_data, JSAMPARRAY output_data)
  150487. {
  150488. jcopy_sample_rows(input_data, 0, output_data, 0,
  150489. cinfo->max_v_samp_factor, cinfo->image_width);
  150490. expand_right_edge(output_data, cinfo->max_v_samp_factor,
  150491. cinfo->image_width, compptr->width_in_blocks * DCTSIZE);
  150492. }
  150493. METHODDEF(void)
  150494. h2v1_downsample (j_compress_ptr cinfo, jpeg_component_info * compptr,
  150495. JSAMPARRAY input_data, JSAMPARRAY output_data)
  150496. {
  150497. int outrow;
  150498. JDIMENSION outcol;
  150499. JDIMENSION output_cols = compptr->width_in_blocks * DCTSIZE;
  150500. register JSAMPROW inptr, outptr;
  150501. register int bias;
  150502. expand_right_edge(input_data, cinfo->max_v_samp_factor,
  150503. cinfo->image_width, output_cols * 2);
  150504. for (outrow = 0; outrow < compptr->v_samp_factor; outrow++) {
  150505. outptr = output_data[outrow];
  150506. inptr = input_data[outrow];
  150507. bias = 0; /* bias = 0,1,0,1,... for successive samples */
  150508. for (outcol = 0; outcol < output_cols; outcol++) {
  150509. *outptr++ = (JSAMPLE) ((GETJSAMPLE(*inptr) + GETJSAMPLE(inptr[1])
  150510. + bias) >> 1);
  150511. bias ^= 1; /* 0=>1, 1=>0 */
  150512. inptr += 2;
  150513. }
  150514. }
  150515. }
  150516. METHODDEF(void)
  150517. h2v2_downsample (j_compress_ptr cinfo, jpeg_component_info * compptr,
  150518. JSAMPARRAY input_data, JSAMPARRAY output_data)
  150519. {
  150520. int inrow, outrow;
  150521. JDIMENSION outcol;
  150522. JDIMENSION output_cols = compptr->width_in_blocks * DCTSIZE;
  150523. register JSAMPROW inptr0, inptr1, outptr;
  150524. register int bias;
  150525. expand_right_edge(input_data, cinfo->max_v_samp_factor,
  150526. cinfo->image_width, output_cols * 2);
  150527. inrow = 0;
  150528. for (outrow = 0; outrow < compptr->v_samp_factor; outrow++) {
  150529. outptr = output_data[outrow];
  150530. inptr0 = input_data[inrow];
  150531. inptr1 = input_data[inrow+1];
  150532. bias = 1; /* bias = 1,2,1,2,... for successive samples */
  150533. for (outcol = 0; outcol < output_cols; outcol++) {
  150534. *outptr++ = (JSAMPLE) ((GETJSAMPLE(*inptr0) + GETJSAMPLE(inptr0[1]) +
  150535. GETJSAMPLE(*inptr1) + GETJSAMPLE(inptr1[1])
  150536. + bias) >> 2);
  150537. bias ^= 3; /* 1=>2, 2=>1 */
  150538. inptr0 += 2; inptr1 += 2;
  150539. }
  150540. inrow += 2;
  150541. }
  150542. }
  150543. #ifdef INPUT_SMOOTHING_SUPPORTED
  150544. METHODDEF(void)
  150545. h2v2_smooth_downsample (j_compress_ptr cinfo, jpeg_component_info * compptr,
  150546. JSAMPARRAY input_data, JSAMPARRAY output_data)
  150547. {
  150548. int inrow, outrow;
  150549. JDIMENSION colctr;
  150550. JDIMENSION output_cols = compptr->width_in_blocks * DCTSIZE;
  150551. register JSAMPROW inptr0, inptr1, above_ptr, below_ptr, outptr;
  150552. INT32 membersum, neighsum, memberscale, neighscale;
  150553. expand_right_edge(input_data - 1, cinfo->max_v_samp_factor + 2,
  150554. cinfo->image_width, output_cols * 2);
  150555. memberscale = 16384 - cinfo->smoothing_factor * 80; /* scaled (1-5*SF)/4 */
  150556. neighscale = cinfo->smoothing_factor * 16; /* scaled SF/4 */
  150557. inrow = 0;
  150558. for (outrow = 0; outrow < compptr->v_samp_factor; outrow++) {
  150559. outptr = output_data[outrow];
  150560. inptr0 = input_data[inrow];
  150561. inptr1 = input_data[inrow+1];
  150562. above_ptr = input_data[inrow-1];
  150563. below_ptr = input_data[inrow+2];
  150564. membersum = GETJSAMPLE(*inptr0) + GETJSAMPLE(inptr0[1]) +
  150565. GETJSAMPLE(*inptr1) + GETJSAMPLE(inptr1[1]);
  150566. neighsum = GETJSAMPLE(*above_ptr) + GETJSAMPLE(above_ptr[1]) +
  150567. GETJSAMPLE(*below_ptr) + GETJSAMPLE(below_ptr[1]) +
  150568. GETJSAMPLE(*inptr0) + GETJSAMPLE(inptr0[2]) +
  150569. GETJSAMPLE(*inptr1) + GETJSAMPLE(inptr1[2]);
  150570. neighsum += neighsum;
  150571. neighsum += GETJSAMPLE(*above_ptr) + GETJSAMPLE(above_ptr[2]) +
  150572. GETJSAMPLE(*below_ptr) + GETJSAMPLE(below_ptr[2]);
  150573. membersum = membersum * memberscale + neighsum * neighscale;
  150574. *outptr++ = (JSAMPLE) ((membersum + 32768) >> 16);
  150575. inptr0 += 2; inptr1 += 2; above_ptr += 2; below_ptr += 2;
  150576. for (colctr = output_cols - 2; colctr > 0; colctr--) {
  150577. membersum = GETJSAMPLE(*inptr0) + GETJSAMPLE(inptr0[1]) +
  150578. GETJSAMPLE(*inptr1) + GETJSAMPLE(inptr1[1]);
  150579. neighsum = GETJSAMPLE(*above_ptr) + GETJSAMPLE(above_ptr[1]) +
  150580. GETJSAMPLE(*below_ptr) + GETJSAMPLE(below_ptr[1]) +
  150581. GETJSAMPLE(inptr0[-1]) + GETJSAMPLE(inptr0[2]) +
  150582. GETJSAMPLE(inptr1[-1]) + GETJSAMPLE(inptr1[2]);
  150583. neighsum += neighsum;
  150584. neighsum += GETJSAMPLE(above_ptr[-1]) + GETJSAMPLE(above_ptr[2]) +
  150585. GETJSAMPLE(below_ptr[-1]) + GETJSAMPLE(below_ptr[2]);
  150586. membersum = membersum * memberscale + neighsum * neighscale;
  150587. *outptr++ = (JSAMPLE) ((membersum + 32768) >> 16);
  150588. inptr0 += 2; inptr1 += 2; above_ptr += 2; below_ptr += 2;
  150589. }
  150590. membersum = GETJSAMPLE(*inptr0) + GETJSAMPLE(inptr0[1]) +
  150591. GETJSAMPLE(*inptr1) + GETJSAMPLE(inptr1[1]);
  150592. neighsum = GETJSAMPLE(*above_ptr) + GETJSAMPLE(above_ptr[1]) +
  150593. GETJSAMPLE(*below_ptr) + GETJSAMPLE(below_ptr[1]) +
  150594. GETJSAMPLE(inptr0[-1]) + GETJSAMPLE(inptr0[1]) +
  150595. GETJSAMPLE(inptr1[-1]) + GETJSAMPLE(inptr1[1]);
  150596. neighsum += neighsum;
  150597. neighsum += GETJSAMPLE(above_ptr[-1]) + GETJSAMPLE(above_ptr[1]) +
  150598. GETJSAMPLE(below_ptr[-1]) + GETJSAMPLE(below_ptr[1]);
  150599. membersum = membersum * memberscale + neighsum * neighscale;
  150600. *outptr = (JSAMPLE) ((membersum + 32768) >> 16);
  150601. inrow += 2;
  150602. }
  150603. }
  150604. METHODDEF(void)
  150605. fullsize_smooth_downsample (j_compress_ptr cinfo, jpeg_component_info *compptr,
  150606. JSAMPARRAY input_data, JSAMPARRAY output_data)
  150607. {
  150608. int outrow;
  150609. JDIMENSION colctr;
  150610. JDIMENSION output_cols = compptr->width_in_blocks * DCTSIZE;
  150611. register JSAMPROW inptr, above_ptr, below_ptr, outptr;
  150612. INT32 membersum, neighsum, memberscale, neighscale;
  150613. int colsum, lastcolsum, nextcolsum;
  150614. expand_right_edge(input_data - 1, cinfo->max_v_samp_factor + 2,
  150615. cinfo->image_width, output_cols);
  150616. memberscale = 65536L - cinfo->smoothing_factor * 512L; /* scaled 1-8*SF */
  150617. neighscale = cinfo->smoothing_factor * 64; /* scaled SF */
  150618. for (outrow = 0; outrow < compptr->v_samp_factor; outrow++) {
  150619. outptr = output_data[outrow];
  150620. inptr = input_data[outrow];
  150621. above_ptr = input_data[outrow-1];
  150622. below_ptr = input_data[outrow+1];
  150623. colsum = GETJSAMPLE(*above_ptr++) + GETJSAMPLE(*below_ptr++) +
  150624. GETJSAMPLE(*inptr);
  150625. membersum = GETJSAMPLE(*inptr++);
  150626. nextcolsum = GETJSAMPLE(*above_ptr) + GETJSAMPLE(*below_ptr) +
  150627. GETJSAMPLE(*inptr);
  150628. neighsum = colsum + (colsum - membersum) + nextcolsum;
  150629. membersum = membersum * memberscale + neighsum * neighscale;
  150630. *outptr++ = (JSAMPLE) ((membersum + 32768) >> 16);
  150631. lastcolsum = colsum; colsum = nextcolsum;
  150632. for (colctr = output_cols - 2; colctr > 0; colctr--) {
  150633. membersum = GETJSAMPLE(*inptr++);
  150634. above_ptr++; below_ptr++;
  150635. nextcolsum = GETJSAMPLE(*above_ptr) + GETJSAMPLE(*below_ptr) +
  150636. GETJSAMPLE(*inptr);
  150637. neighsum = lastcolsum + (colsum - membersum) + nextcolsum;
  150638. membersum = membersum * memberscale + neighsum * neighscale;
  150639. *outptr++ = (JSAMPLE) ((membersum + 32768) >> 16);
  150640. lastcolsum = colsum; colsum = nextcolsum;
  150641. }
  150642. membersum = GETJSAMPLE(*inptr);
  150643. neighsum = lastcolsum + (colsum - membersum) + colsum;
  150644. membersum = membersum * memberscale + neighsum * neighscale;
  150645. *outptr = (JSAMPLE) ((membersum + 32768) >> 16);
  150646. }
  150647. }
  150648. #endif /* INPUT_SMOOTHING_SUPPORTED */
  150649. GLOBAL(void)
  150650. jinit_downsampler (j_compress_ptr cinfo)
  150651. {
  150652. my_downsample_ptr downsample;
  150653. int ci;
  150654. jpeg_component_info * compptr;
  150655. boolean smoothok = TRUE;
  150656. downsample = (my_downsample_ptr)
  150657. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  150658. SIZEOF(my_downsampler));
  150659. cinfo->downsample = (struct jpeg_downsampler *) downsample;
  150660. downsample->pub.start_pass = start_pass_downsample;
  150661. downsample->pub.downsample = sep_downsample;
  150662. downsample->pub.need_context_rows = FALSE;
  150663. if (cinfo->CCIR601_sampling)
  150664. ERREXIT(cinfo, JERR_CCIR601_NOTIMPL);
  150665. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  150666. ci++, compptr++) {
  150667. if (compptr->h_samp_factor == cinfo->max_h_samp_factor &&
  150668. compptr->v_samp_factor == cinfo->max_v_samp_factor) {
  150669. #ifdef INPUT_SMOOTHING_SUPPORTED
  150670. if (cinfo->smoothing_factor) {
  150671. downsample->methods[ci] = fullsize_smooth_downsample;
  150672. downsample->pub.need_context_rows = TRUE;
  150673. } else
  150674. #endif
  150675. downsample->methods[ci] = fullsize_downsample;
  150676. } else if (compptr->h_samp_factor * 2 == cinfo->max_h_samp_factor &&
  150677. compptr->v_samp_factor == cinfo->max_v_samp_factor) {
  150678. smoothok = FALSE;
  150679. downsample->methods[ci] = h2v1_downsample;
  150680. } else if (compptr->h_samp_factor * 2 == cinfo->max_h_samp_factor &&
  150681. compptr->v_samp_factor * 2 == cinfo->max_v_samp_factor) {
  150682. #ifdef INPUT_SMOOTHING_SUPPORTED
  150683. if (cinfo->smoothing_factor) {
  150684. downsample->methods[ci] = h2v2_smooth_downsample;
  150685. downsample->pub.need_context_rows = TRUE;
  150686. } else
  150687. #endif
  150688. downsample->methods[ci] = h2v2_downsample;
  150689. } else if ((cinfo->max_h_samp_factor % compptr->h_samp_factor) == 0 &&
  150690. (cinfo->max_v_samp_factor % compptr->v_samp_factor) == 0) {
  150691. smoothok = FALSE;
  150692. downsample->methods[ci] = int_downsample;
  150693. } else
  150694. ERREXIT(cinfo, JERR_FRACT_SAMPLE_NOTIMPL);
  150695. }
  150696. #ifdef INPUT_SMOOTHING_SUPPORTED
  150697. if (cinfo->smoothing_factor && !smoothok)
  150698. TRACEMS(cinfo, 0, JTRC_SMOOTH_NOTIMPL);
  150699. #endif
  150700. }
  150701. /********* End of inlined file: jcsample.c *********/
  150702. /********* Start of inlined file: jctrans.c *********/
  150703. #define JPEG_INTERNALS
  150704. LOCAL(void) transencode_master_selection
  150705. JPP((j_compress_ptr cinfo, jvirt_barray_ptr * coef_arrays));
  150706. LOCAL(void) transencode_coef_controller
  150707. JPP((j_compress_ptr cinfo, jvirt_barray_ptr * coef_arrays));
  150708. GLOBAL(void)
  150709. jpeg_write_coefficients (j_compress_ptr cinfo, jvirt_barray_ptr * coef_arrays)
  150710. {
  150711. if (cinfo->global_state != CSTATE_START)
  150712. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  150713. jpeg_suppress_tables(cinfo, FALSE);
  150714. (*cinfo->err->reset_error_mgr) ((j_common_ptr) cinfo);
  150715. (*cinfo->dest->init_destination) (cinfo);
  150716. transencode_master_selection(cinfo, coef_arrays);
  150717. cinfo->next_scanline = 0; /* so jpeg_write_marker works */
  150718. cinfo->global_state = CSTATE_WRCOEFS;
  150719. }
  150720. GLOBAL(void)
  150721. jpeg_copy_critical_parameters (j_decompress_ptr srcinfo,
  150722. j_compress_ptr dstinfo)
  150723. {
  150724. JQUANT_TBL ** qtblptr;
  150725. jpeg_component_info *incomp, *outcomp;
  150726. JQUANT_TBL *c_quant, *slot_quant;
  150727. int tblno, ci, coefi;
  150728. if (dstinfo->global_state != CSTATE_START)
  150729. ERREXIT1(dstinfo, JERR_BAD_STATE, dstinfo->global_state);
  150730. dstinfo->image_width = srcinfo->image_width;
  150731. dstinfo->image_height = srcinfo->image_height;
  150732. dstinfo->input_components = srcinfo->num_components;
  150733. dstinfo->in_color_space = srcinfo->jpeg_color_space;
  150734. jpeg_set_defaults(dstinfo);
  150735. jpeg_set_colorspace(dstinfo, srcinfo->jpeg_color_space);
  150736. dstinfo->data_precision = srcinfo->data_precision;
  150737. dstinfo->CCIR601_sampling = srcinfo->CCIR601_sampling;
  150738. for (tblno = 0; tblno < NUM_QUANT_TBLS; tblno++) {
  150739. if (srcinfo->quant_tbl_ptrs[tblno] != NULL) {
  150740. qtblptr = & dstinfo->quant_tbl_ptrs[tblno];
  150741. if (*qtblptr == NULL)
  150742. *qtblptr = jpeg_alloc_quant_table((j_common_ptr) dstinfo);
  150743. MEMCOPY((*qtblptr)->quantval,
  150744. srcinfo->quant_tbl_ptrs[tblno]->quantval,
  150745. SIZEOF((*qtblptr)->quantval));
  150746. (*qtblptr)->sent_table = FALSE;
  150747. }
  150748. }
  150749. dstinfo->num_components = srcinfo->num_components;
  150750. if (dstinfo->num_components < 1 || dstinfo->num_components > MAX_COMPONENTS)
  150751. ERREXIT2(dstinfo, JERR_COMPONENT_COUNT, dstinfo->num_components,
  150752. MAX_COMPONENTS);
  150753. for (ci = 0, incomp = srcinfo->comp_info, outcomp = dstinfo->comp_info;
  150754. ci < dstinfo->num_components; ci++, incomp++, outcomp++) {
  150755. outcomp->component_id = incomp->component_id;
  150756. outcomp->h_samp_factor = incomp->h_samp_factor;
  150757. outcomp->v_samp_factor = incomp->v_samp_factor;
  150758. outcomp->quant_tbl_no = incomp->quant_tbl_no;
  150759. tblno = outcomp->quant_tbl_no;
  150760. if (tblno < 0 || tblno >= NUM_QUANT_TBLS ||
  150761. srcinfo->quant_tbl_ptrs[tblno] == NULL)
  150762. ERREXIT1(dstinfo, JERR_NO_QUANT_TABLE, tblno);
  150763. slot_quant = srcinfo->quant_tbl_ptrs[tblno];
  150764. c_quant = incomp->quant_table;
  150765. if (c_quant != NULL) {
  150766. for (coefi = 0; coefi < DCTSIZE2; coefi++) {
  150767. if (c_quant->quantval[coefi] != slot_quant->quantval[coefi])
  150768. ERREXIT1(dstinfo, JERR_MISMATCHED_QUANT_TABLE, tblno);
  150769. }
  150770. }
  150771. }
  150772. if (srcinfo->saw_JFIF_marker) {
  150773. if (srcinfo->JFIF_major_version == 1) {
  150774. dstinfo->JFIF_major_version = srcinfo->JFIF_major_version;
  150775. dstinfo->JFIF_minor_version = srcinfo->JFIF_minor_version;
  150776. }
  150777. dstinfo->density_unit = srcinfo->density_unit;
  150778. dstinfo->X_density = srcinfo->X_density;
  150779. dstinfo->Y_density = srcinfo->Y_density;
  150780. }
  150781. }
  150782. LOCAL(void)
  150783. transencode_master_selection (j_compress_ptr cinfo,
  150784. jvirt_barray_ptr * coef_arrays)
  150785. {
  150786. cinfo->input_components = 1;
  150787. jinit_c_master_control(cinfo, TRUE /* transcode only */);
  150788. if (cinfo->arith_code) {
  150789. ERREXIT(cinfo, JERR_ARITH_NOTIMPL);
  150790. } else {
  150791. if (cinfo->progressive_mode) {
  150792. #ifdef C_PROGRESSIVE_SUPPORTED
  150793. jinit_phuff_encoder(cinfo);
  150794. #else
  150795. ERREXIT(cinfo, JERR_NOT_COMPILED);
  150796. #endif
  150797. } else
  150798. jinit_huff_encoder(cinfo);
  150799. }
  150800. transencode_coef_controller(cinfo, coef_arrays);
  150801. jinit_marker_writer(cinfo);
  150802. (*cinfo->mem->realize_virt_arrays) ((j_common_ptr) cinfo);
  150803. (*cinfo->marker->write_file_header) (cinfo);
  150804. }
  150805. typedef struct {
  150806. struct jpeg_c_coef_controller pub; /* public fields */
  150807. JDIMENSION iMCU_row_num; /* iMCU row # within image */
  150808. JDIMENSION mcu_ctr; /* counts MCUs processed in current row */
  150809. int MCU_vert_offset; /* counts MCU rows within iMCU row */
  150810. int MCU_rows_per_iMCU_row; /* number of such rows needed */
  150811. jvirt_barray_ptr * whole_image;
  150812. JBLOCKROW dummy_buffer[C_MAX_BLOCKS_IN_MCU];
  150813. } my_coef_controller2;
  150814. typedef my_coef_controller2 * my_coef_ptr2;
  150815. LOCAL(void)
  150816. start_iMCU_row2 (j_compress_ptr cinfo)
  150817. {
  150818. my_coef_ptr2 coef = (my_coef_ptr2) cinfo->coef;
  150819. if (cinfo->comps_in_scan > 1) {
  150820. coef->MCU_rows_per_iMCU_row = 1;
  150821. } else {
  150822. if (coef->iMCU_row_num < (cinfo->total_iMCU_rows-1))
  150823. coef->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor;
  150824. else
  150825. coef->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height;
  150826. }
  150827. coef->mcu_ctr = 0;
  150828. coef->MCU_vert_offset = 0;
  150829. }
  150830. METHODDEF(void)
  150831. start_pass_coef2 (j_compress_ptr cinfo, J_BUF_MODE pass_mode)
  150832. {
  150833. my_coef_ptr2 coef = (my_coef_ptr2) cinfo->coef;
  150834. if (pass_mode != JBUF_CRANK_DEST)
  150835. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  150836. coef->iMCU_row_num = 0;
  150837. start_iMCU_row2(cinfo);
  150838. }
  150839. METHODDEF(boolean)
  150840. compress_output2 (j_compress_ptr cinfo, JSAMPIMAGE input_buf)
  150841. {
  150842. my_coef_ptr2 coef = (my_coef_ptr2) cinfo->coef;
  150843. JDIMENSION MCU_col_num; /* index of current MCU within row */
  150844. JDIMENSION last_MCU_col = cinfo->MCUs_per_row - 1;
  150845. JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
  150846. int blkn, ci, xindex, yindex, yoffset, blockcnt;
  150847. JDIMENSION start_col;
  150848. JBLOCKARRAY buffer[MAX_COMPS_IN_SCAN];
  150849. JBLOCKROW MCU_buffer[C_MAX_BLOCKS_IN_MCU];
  150850. JBLOCKROW buffer_ptr;
  150851. jpeg_component_info *compptr;
  150852. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  150853. compptr = cinfo->cur_comp_info[ci];
  150854. buffer[ci] = (*cinfo->mem->access_virt_barray)
  150855. ((j_common_ptr) cinfo, coef->whole_image[compptr->component_index],
  150856. coef->iMCU_row_num * compptr->v_samp_factor,
  150857. (JDIMENSION) compptr->v_samp_factor, FALSE);
  150858. }
  150859. for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row;
  150860. yoffset++) {
  150861. for (MCU_col_num = coef->mcu_ctr; MCU_col_num < cinfo->MCUs_per_row;
  150862. MCU_col_num++) {
  150863. blkn = 0; /* index of current DCT block within MCU */
  150864. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  150865. compptr = cinfo->cur_comp_info[ci];
  150866. start_col = MCU_col_num * compptr->MCU_width;
  150867. blockcnt = (MCU_col_num < last_MCU_col) ? compptr->MCU_width
  150868. : compptr->last_col_width;
  150869. for (yindex = 0; yindex < compptr->MCU_height; yindex++) {
  150870. if (coef->iMCU_row_num < last_iMCU_row ||
  150871. yindex+yoffset < compptr->last_row_height) {
  150872. buffer_ptr = buffer[ci][yindex+yoffset] + start_col;
  150873. for (xindex = 0; xindex < blockcnt; xindex++)
  150874. MCU_buffer[blkn++] = buffer_ptr++;
  150875. } else {
  150876. xindex = 0;
  150877. }
  150878. for (; xindex < compptr->MCU_width; xindex++) {
  150879. MCU_buffer[blkn] = coef->dummy_buffer[blkn];
  150880. MCU_buffer[blkn][0][0] = MCU_buffer[blkn-1][0][0];
  150881. blkn++;
  150882. }
  150883. }
  150884. }
  150885. if (! (*cinfo->entropy->encode_mcu) (cinfo, MCU_buffer)) {
  150886. coef->MCU_vert_offset = yoffset;
  150887. coef->mcu_ctr = MCU_col_num;
  150888. return FALSE;
  150889. }
  150890. }
  150891. coef->mcu_ctr = 0;
  150892. }
  150893. coef->iMCU_row_num++;
  150894. start_iMCU_row2(cinfo);
  150895. return TRUE;
  150896. }
  150897. LOCAL(void)
  150898. transencode_coef_controller (j_compress_ptr cinfo,
  150899. jvirt_barray_ptr * coef_arrays)
  150900. {
  150901. my_coef_ptr2 coef;
  150902. JBLOCKROW buffer;
  150903. int i;
  150904. coef = (my_coef_ptr2)
  150905. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  150906. SIZEOF(my_coef_controller2));
  150907. cinfo->coef = (struct jpeg_c_coef_controller *) coef;
  150908. coef->pub.start_pass = start_pass_coef2;
  150909. coef->pub.compress_data = compress_output2;
  150910. coef->whole_image = coef_arrays;
  150911. buffer = (JBLOCKROW)
  150912. (*cinfo->mem->alloc_large) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  150913. C_MAX_BLOCKS_IN_MCU * SIZEOF(JBLOCK));
  150914. jzero_far((void FAR *) buffer, C_MAX_BLOCKS_IN_MCU * SIZEOF(JBLOCK));
  150915. for (i = 0; i < C_MAX_BLOCKS_IN_MCU; i++) {
  150916. coef->dummy_buffer[i] = buffer + i;
  150917. }
  150918. }
  150919. /********* End of inlined file: jctrans.c *********/
  150920. /********* Start of inlined file: jdapistd.c *********/
  150921. #define JPEG_INTERNALS
  150922. LOCAL(boolean) output_pass_setup JPP((j_decompress_ptr cinfo));
  150923. GLOBAL(boolean)
  150924. jpeg_start_decompress (j_decompress_ptr cinfo)
  150925. {
  150926. if (cinfo->global_state == DSTATE_READY) {
  150927. jinit_master_decompress(cinfo);
  150928. if (cinfo->buffered_image) {
  150929. cinfo->global_state = DSTATE_BUFIMAGE;
  150930. return TRUE;
  150931. }
  150932. cinfo->global_state = DSTATE_PRELOAD;
  150933. }
  150934. if (cinfo->global_state == DSTATE_PRELOAD) {
  150935. if (cinfo->inputctl->has_multiple_scans) {
  150936. #ifdef D_MULTISCAN_FILES_SUPPORTED
  150937. for (;;) {
  150938. int retcode;
  150939. if (cinfo->progress != NULL)
  150940. (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);
  150941. retcode = (*cinfo->inputctl->consume_input) (cinfo);
  150942. if (retcode == JPEG_SUSPENDED)
  150943. return FALSE;
  150944. if (retcode == JPEG_REACHED_EOI)
  150945. break;
  150946. if (cinfo->progress != NULL &&
  150947. (retcode == JPEG_ROW_COMPLETED || retcode == JPEG_REACHED_SOS)) {
  150948. if (++cinfo->progress->pass_counter >= cinfo->progress->pass_limit) {
  150949. cinfo->progress->pass_limit += (long) cinfo->total_iMCU_rows;
  150950. }
  150951. }
  150952. }
  150953. #else
  150954. ERREXIT(cinfo, JERR_NOT_COMPILED);
  150955. #endif /* D_MULTISCAN_FILES_SUPPORTED */
  150956. }
  150957. cinfo->output_scan_number = cinfo->input_scan_number;
  150958. } else if (cinfo->global_state != DSTATE_PRESCAN)
  150959. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  150960. return output_pass_setup(cinfo);
  150961. }
  150962. LOCAL(boolean)
  150963. output_pass_setup (j_decompress_ptr cinfo)
  150964. {
  150965. if (cinfo->global_state != DSTATE_PRESCAN) {
  150966. (*cinfo->master->prepare_for_output_pass) (cinfo);
  150967. cinfo->output_scanline = 0;
  150968. cinfo->global_state = DSTATE_PRESCAN;
  150969. }
  150970. while (cinfo->master->is_dummy_pass) {
  150971. #ifdef QUANT_2PASS_SUPPORTED
  150972. while (cinfo->output_scanline < cinfo->output_height) {
  150973. JDIMENSION last_scanline;
  150974. if (cinfo->progress != NULL) {
  150975. cinfo->progress->pass_counter = (long) cinfo->output_scanline;
  150976. cinfo->progress->pass_limit = (long) cinfo->output_height;
  150977. (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);
  150978. }
  150979. last_scanline = cinfo->output_scanline;
  150980. (*cinfo->main->process_data) (cinfo, (JSAMPARRAY) NULL,
  150981. &cinfo->output_scanline, (JDIMENSION) 0);
  150982. if (cinfo->output_scanline == last_scanline)
  150983. return FALSE; /* No progress made, must suspend */
  150984. }
  150985. (*cinfo->master->finish_output_pass) (cinfo);
  150986. (*cinfo->master->prepare_for_output_pass) (cinfo);
  150987. cinfo->output_scanline = 0;
  150988. #else
  150989. ERREXIT(cinfo, JERR_NOT_COMPILED);
  150990. #endif /* QUANT_2PASS_SUPPORTED */
  150991. }
  150992. cinfo->global_state = cinfo->raw_data_out ? DSTATE_RAW_OK : DSTATE_SCANNING;
  150993. return TRUE;
  150994. }
  150995. GLOBAL(JDIMENSION)
  150996. jpeg_read_scanlines (j_decompress_ptr cinfo, JSAMPARRAY scanlines,
  150997. JDIMENSION max_lines)
  150998. {
  150999. JDIMENSION row_ctr;
  151000. if (cinfo->global_state != DSTATE_SCANNING)
  151001. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  151002. if (cinfo->output_scanline >= cinfo->output_height) {
  151003. WARNMS(cinfo, JWRN_TOO_MUCH_DATA);
  151004. return 0;
  151005. }
  151006. if (cinfo->progress != NULL) {
  151007. cinfo->progress->pass_counter = (long) cinfo->output_scanline;
  151008. cinfo->progress->pass_limit = (long) cinfo->output_height;
  151009. (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);
  151010. }
  151011. row_ctr = 0;
  151012. (*cinfo->main->process_data) (cinfo, scanlines, &row_ctr, max_lines);
  151013. cinfo->output_scanline += row_ctr;
  151014. return row_ctr;
  151015. }
  151016. GLOBAL(JDIMENSION)
  151017. jpeg_read_raw_data (j_decompress_ptr cinfo, JSAMPIMAGE data,
  151018. JDIMENSION max_lines)
  151019. {
  151020. JDIMENSION lines_per_iMCU_row;
  151021. if (cinfo->global_state != DSTATE_RAW_OK)
  151022. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  151023. if (cinfo->output_scanline >= cinfo->output_height) {
  151024. WARNMS(cinfo, JWRN_TOO_MUCH_DATA);
  151025. return 0;
  151026. }
  151027. if (cinfo->progress != NULL) {
  151028. cinfo->progress->pass_counter = (long) cinfo->output_scanline;
  151029. cinfo->progress->pass_limit = (long) cinfo->output_height;
  151030. (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);
  151031. }
  151032. lines_per_iMCU_row = cinfo->max_v_samp_factor * cinfo->min_DCT_scaled_size;
  151033. if (max_lines < lines_per_iMCU_row)
  151034. ERREXIT(cinfo, JERR_BUFFER_SIZE);
  151035. if (! (*cinfo->coef->decompress_data) (cinfo, data))
  151036. return 0; /* suspension forced, can do nothing more */
  151037. cinfo->output_scanline += lines_per_iMCU_row;
  151038. return lines_per_iMCU_row;
  151039. }
  151040. #ifdef D_MULTISCAN_FILES_SUPPORTED
  151041. GLOBAL(boolean)
  151042. jpeg_start_output (j_decompress_ptr cinfo, int scan_number)
  151043. {
  151044. if (cinfo->global_state != DSTATE_BUFIMAGE &&
  151045. cinfo->global_state != DSTATE_PRESCAN)
  151046. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  151047. if (scan_number <= 0)
  151048. scan_number = 1;
  151049. if (cinfo->inputctl->eoi_reached &&
  151050. scan_number > cinfo->input_scan_number)
  151051. scan_number = cinfo->input_scan_number;
  151052. cinfo->output_scan_number = scan_number;
  151053. return output_pass_setup(cinfo);
  151054. }
  151055. GLOBAL(boolean)
  151056. jpeg_finish_output (j_decompress_ptr cinfo)
  151057. {
  151058. if ((cinfo->global_state == DSTATE_SCANNING ||
  151059. cinfo->global_state == DSTATE_RAW_OK) && cinfo->buffered_image) {
  151060. (*cinfo->master->finish_output_pass) (cinfo);
  151061. cinfo->global_state = DSTATE_BUFPOST;
  151062. } else if (cinfo->global_state != DSTATE_BUFPOST) {
  151063. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  151064. }
  151065. while (cinfo->input_scan_number <= cinfo->output_scan_number &&
  151066. ! cinfo->inputctl->eoi_reached) {
  151067. if ((*cinfo->inputctl->consume_input) (cinfo) == JPEG_SUSPENDED)
  151068. return FALSE; /* Suspend, come back later */
  151069. }
  151070. cinfo->global_state = DSTATE_BUFIMAGE;
  151071. return TRUE;
  151072. }
  151073. #endif /* D_MULTISCAN_FILES_SUPPORTED */
  151074. /********* End of inlined file: jdapistd.c *********/
  151075. /********* Start of inlined file: jdapimin.c *********/
  151076. #define JPEG_INTERNALS
  151077. GLOBAL(void)
  151078. jpeg_CreateDecompress (j_decompress_ptr cinfo, int version, size_t structsize)
  151079. {
  151080. int i;
  151081. cinfo->mem = NULL; /* so jpeg_destroy knows mem mgr not called */
  151082. if (version != JPEG_LIB_VERSION)
  151083. ERREXIT2(cinfo, JERR_BAD_LIB_VERSION, JPEG_LIB_VERSION, version);
  151084. if (structsize != SIZEOF(struct jpeg_decompress_struct))
  151085. ERREXIT2(cinfo, JERR_BAD_STRUCT_SIZE,
  151086. (int) SIZEOF(struct jpeg_decompress_struct), (int) structsize);
  151087. {
  151088. struct jpeg_error_mgr * err = cinfo->err;
  151089. void * client_data = cinfo->client_data; /* ignore Purify complaint here */
  151090. MEMZERO(cinfo, SIZEOF(struct jpeg_decompress_struct));
  151091. cinfo->err = err;
  151092. cinfo->client_data = client_data;
  151093. }
  151094. cinfo->is_decompressor = TRUE;
  151095. jinit_memory_mgr((j_common_ptr) cinfo);
  151096. cinfo->progress = NULL;
  151097. cinfo->src = NULL;
  151098. for (i = 0; i < NUM_QUANT_TBLS; i++)
  151099. cinfo->quant_tbl_ptrs[i] = NULL;
  151100. for (i = 0; i < NUM_HUFF_TBLS; i++) {
  151101. cinfo->dc_huff_tbl_ptrs[i] = NULL;
  151102. cinfo->ac_huff_tbl_ptrs[i] = NULL;
  151103. }
  151104. cinfo->marker_list = NULL;
  151105. jinit_marker_reader(cinfo);
  151106. jinit_input_controller(cinfo);
  151107. cinfo->global_state = DSTATE_START;
  151108. }
  151109. GLOBAL(void)
  151110. jpeg_destroy_decompress (j_decompress_ptr cinfo)
  151111. {
  151112. jpeg_destroy((j_common_ptr) cinfo); /* use common routine */
  151113. }
  151114. GLOBAL(void)
  151115. jpeg_abort_decompress (j_decompress_ptr cinfo)
  151116. {
  151117. jpeg_abort((j_common_ptr) cinfo); /* use common routine */
  151118. }
  151119. LOCAL(void)
  151120. default_decompress_parms (j_decompress_ptr cinfo)
  151121. {
  151122. switch (cinfo->num_components) {
  151123. case 1:
  151124. cinfo->jpeg_color_space = JCS_GRAYSCALE;
  151125. cinfo->out_color_space = JCS_GRAYSCALE;
  151126. break;
  151127. case 3:
  151128. if (cinfo->saw_JFIF_marker) {
  151129. cinfo->jpeg_color_space = JCS_YCbCr; /* JFIF implies YCbCr */
  151130. } else if (cinfo->saw_Adobe_marker) {
  151131. switch (cinfo->Adobe_transform) {
  151132. case 0:
  151133. cinfo->jpeg_color_space = JCS_RGB;
  151134. break;
  151135. case 1:
  151136. cinfo->jpeg_color_space = JCS_YCbCr;
  151137. break;
  151138. default:
  151139. WARNMS1(cinfo, JWRN_ADOBE_XFORM, cinfo->Adobe_transform);
  151140. cinfo->jpeg_color_space = JCS_YCbCr; /* assume it's YCbCr */
  151141. break;
  151142. }
  151143. } else {
  151144. int cid0 = cinfo->comp_info[0].component_id;
  151145. int cid1 = cinfo->comp_info[1].component_id;
  151146. int cid2 = cinfo->comp_info[2].component_id;
  151147. if (cid0 == 1 && cid1 == 2 && cid2 == 3)
  151148. cinfo->jpeg_color_space = JCS_YCbCr; /* assume JFIF w/out marker */
  151149. else if (cid0 == 82 && cid1 == 71 && cid2 == 66)
  151150. cinfo->jpeg_color_space = JCS_RGB; /* ASCII 'R', 'G', 'B' */
  151151. else {
  151152. TRACEMS3(cinfo, 1, JTRC_UNKNOWN_IDS, cid0, cid1, cid2);
  151153. cinfo->jpeg_color_space = JCS_YCbCr; /* assume it's YCbCr */
  151154. }
  151155. }
  151156. cinfo->out_color_space = JCS_RGB;
  151157. break;
  151158. case 4:
  151159. if (cinfo->saw_Adobe_marker) {
  151160. switch (cinfo->Adobe_transform) {
  151161. case 0:
  151162. cinfo->jpeg_color_space = JCS_CMYK;
  151163. break;
  151164. case 2:
  151165. cinfo->jpeg_color_space = JCS_YCCK;
  151166. break;
  151167. default:
  151168. WARNMS1(cinfo, JWRN_ADOBE_XFORM, cinfo->Adobe_transform);
  151169. cinfo->jpeg_color_space = JCS_YCCK; /* assume it's YCCK */
  151170. break;
  151171. }
  151172. } else {
  151173. cinfo->jpeg_color_space = JCS_CMYK;
  151174. }
  151175. cinfo->out_color_space = JCS_CMYK;
  151176. break;
  151177. default:
  151178. cinfo->jpeg_color_space = JCS_UNKNOWN;
  151179. cinfo->out_color_space = JCS_UNKNOWN;
  151180. break;
  151181. }
  151182. cinfo->scale_num = 1; /* 1:1 scaling */
  151183. cinfo->scale_denom = 1;
  151184. cinfo->output_gamma = 1.0;
  151185. cinfo->buffered_image = FALSE;
  151186. cinfo->raw_data_out = FALSE;
  151187. cinfo->dct_method = JDCT_DEFAULT;
  151188. cinfo->do_fancy_upsampling = TRUE;
  151189. cinfo->do_block_smoothing = TRUE;
  151190. cinfo->quantize_colors = FALSE;
  151191. cinfo->dither_mode = JDITHER_FS;
  151192. #ifdef QUANT_2PASS_SUPPORTED
  151193. cinfo->two_pass_quantize = TRUE;
  151194. #else
  151195. cinfo->two_pass_quantize = FALSE;
  151196. #endif
  151197. cinfo->desired_number_of_colors = 256;
  151198. cinfo->colormap = NULL;
  151199. cinfo->enable_1pass_quant = FALSE;
  151200. cinfo->enable_external_quant = FALSE;
  151201. cinfo->enable_2pass_quant = FALSE;
  151202. }
  151203. GLOBAL(int)
  151204. jpeg_read_header (j_decompress_ptr cinfo, boolean require_image)
  151205. {
  151206. int retcode;
  151207. if (cinfo->global_state != DSTATE_START &&
  151208. cinfo->global_state != DSTATE_INHEADER)
  151209. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  151210. retcode = jpeg_consume_input(cinfo);
  151211. switch (retcode) {
  151212. case JPEG_REACHED_SOS:
  151213. retcode = JPEG_HEADER_OK;
  151214. break;
  151215. case JPEG_REACHED_EOI:
  151216. if (require_image) /* Complain if application wanted an image */
  151217. ERREXIT(cinfo, JERR_NO_IMAGE);
  151218. jpeg_abort((j_common_ptr) cinfo); /* sets state = DSTATE_START */
  151219. retcode = JPEG_HEADER_TABLES_ONLY;
  151220. break;
  151221. case JPEG_SUSPENDED:
  151222. break;
  151223. }
  151224. return retcode;
  151225. }
  151226. GLOBAL(int)
  151227. jpeg_consume_input (j_decompress_ptr cinfo)
  151228. {
  151229. int retcode = JPEG_SUSPENDED;
  151230. switch (cinfo->global_state) {
  151231. case DSTATE_START:
  151232. (*cinfo->inputctl->reset_input_controller) (cinfo);
  151233. (*cinfo->src->init_source) (cinfo);
  151234. cinfo->global_state = DSTATE_INHEADER;
  151235. case DSTATE_INHEADER:
  151236. retcode = (*cinfo->inputctl->consume_input) (cinfo);
  151237. if (retcode == JPEG_REACHED_SOS) { /* Found SOS, prepare to decompress */
  151238. default_decompress_parms(cinfo);
  151239. cinfo->global_state = DSTATE_READY;
  151240. }
  151241. break;
  151242. case DSTATE_READY:
  151243. retcode = JPEG_REACHED_SOS;
  151244. break;
  151245. case DSTATE_PRELOAD:
  151246. case DSTATE_PRESCAN:
  151247. case DSTATE_SCANNING:
  151248. case DSTATE_RAW_OK:
  151249. case DSTATE_BUFIMAGE:
  151250. case DSTATE_BUFPOST:
  151251. case DSTATE_STOPPING:
  151252. retcode = (*cinfo->inputctl->consume_input) (cinfo);
  151253. break;
  151254. default:
  151255. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  151256. }
  151257. return retcode;
  151258. }
  151259. GLOBAL(boolean)
  151260. jpeg_input_complete (j_decompress_ptr cinfo)
  151261. {
  151262. if (cinfo->global_state < DSTATE_START ||
  151263. cinfo->global_state > DSTATE_STOPPING)
  151264. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  151265. return cinfo->inputctl->eoi_reached;
  151266. }
  151267. GLOBAL(boolean)
  151268. jpeg_has_multiple_scans (j_decompress_ptr cinfo)
  151269. {
  151270. if (cinfo->global_state < DSTATE_READY ||
  151271. cinfo->global_state > DSTATE_STOPPING)
  151272. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  151273. return cinfo->inputctl->has_multiple_scans;
  151274. }
  151275. GLOBAL(boolean)
  151276. jpeg_finish_decompress (j_decompress_ptr cinfo)
  151277. {
  151278. if ((cinfo->global_state == DSTATE_SCANNING ||
  151279. cinfo->global_state == DSTATE_RAW_OK) && ! cinfo->buffered_image) {
  151280. if (cinfo->output_scanline < cinfo->output_height)
  151281. ERREXIT(cinfo, JERR_TOO_LITTLE_DATA);
  151282. (*cinfo->master->finish_output_pass) (cinfo);
  151283. cinfo->global_state = DSTATE_STOPPING;
  151284. } else if (cinfo->global_state == DSTATE_BUFIMAGE) {
  151285. cinfo->global_state = DSTATE_STOPPING;
  151286. } else if (cinfo->global_state != DSTATE_STOPPING) {
  151287. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  151288. }
  151289. while (! cinfo->inputctl->eoi_reached) {
  151290. if ((*cinfo->inputctl->consume_input) (cinfo) == JPEG_SUSPENDED)
  151291. return FALSE; /* Suspend, come back later */
  151292. }
  151293. (*cinfo->src->term_source) (cinfo);
  151294. jpeg_abort((j_common_ptr) cinfo);
  151295. return TRUE;
  151296. }
  151297. /********* End of inlined file: jdapimin.c *********/
  151298. /********* Start of inlined file: jdatasrc.c *********/
  151299. /********* Start of inlined file: jerror.h *********/
  151300. #ifndef JMESSAGE
  151301. #ifndef JERROR_H
  151302. #define JMAKE_ENUM_LIST
  151303. #else
  151304. #define JMESSAGE(code,string)
  151305. #endif /* JERROR_H */
  151306. #endif /* JMESSAGE */
  151307. #ifdef JMAKE_ENUM_LIST
  151308. typedef enum {
  151309. #define JMESSAGE(code,string) code ,
  151310. #endif /* JMAKE_ENUM_LIST */
  151311. JMESSAGE(JMSG_NOMESSAGE, "Bogus message code %d") /* Must be first entry! */
  151312. JMESSAGE(JERR_ARITH_NOTIMPL,
  151313. "Sorry, there are legal restrictions on arithmetic coding")
  151314. JMESSAGE(JERR_BAD_ALIGN_TYPE, "ALIGN_TYPE is wrong, please fix")
  151315. JMESSAGE(JERR_BAD_ALLOC_CHUNK, "MAX_ALLOC_CHUNK is wrong, please fix")
  151316. JMESSAGE(JERR_BAD_BUFFER_MODE, "Bogus buffer control mode")
  151317. JMESSAGE(JERR_BAD_COMPONENT_ID, "Invalid component ID %d in SOS")
  151318. JMESSAGE(JERR_BAD_DCT_COEF, "DCT coefficient out of range")
  151319. JMESSAGE(JERR_BAD_DCTSIZE, "IDCT output block size %d not supported")
  151320. JMESSAGE(JERR_BAD_HUFF_TABLE, "Bogus Huffman table definition")
  151321. JMESSAGE(JERR_BAD_IN_COLORSPACE, "Bogus input colorspace")
  151322. JMESSAGE(JERR_BAD_J_COLORSPACE, "Bogus JPEG colorspace")
  151323. JMESSAGE(JERR_BAD_LENGTH, "Bogus marker length")
  151324. JMESSAGE(JERR_BAD_LIB_VERSION,
  151325. "Wrong JPEG library version: library is %d, caller expects %d")
  151326. JMESSAGE(JERR_BAD_MCU_SIZE, "Sampling factors too large for interleaved scan")
  151327. JMESSAGE(JERR_BAD_POOL_ID, "Invalid memory pool code %d")
  151328. JMESSAGE(JERR_BAD_PRECISION, "Unsupported JPEG data precision %d")
  151329. JMESSAGE(JERR_BAD_PROGRESSION,
  151330. "Invalid progressive parameters Ss=%d Se=%d Ah=%d Al=%d")
  151331. JMESSAGE(JERR_BAD_PROG_SCRIPT,
  151332. "Invalid progressive parameters at scan script entry %d")
  151333. JMESSAGE(JERR_BAD_SAMPLING, "Bogus sampling factors")
  151334. JMESSAGE(JERR_BAD_SCAN_SCRIPT, "Invalid scan script at entry %d")
  151335. JMESSAGE(JERR_BAD_STATE, "Improper call to JPEG library in state %d")
  151336. JMESSAGE(JERR_BAD_STRUCT_SIZE,
  151337. "JPEG parameter struct mismatch: library thinks size is %u, caller expects %u")
  151338. JMESSAGE(JERR_BAD_VIRTUAL_ACCESS, "Bogus virtual array access")
  151339. JMESSAGE(JERR_BUFFER_SIZE, "Buffer passed to JPEG library is too small")
  151340. JMESSAGE(JERR_CANT_SUSPEND, "Suspension not allowed here")
  151341. JMESSAGE(JERR_CCIR601_NOTIMPL, "CCIR601 sampling not implemented yet")
  151342. JMESSAGE(JERR_COMPONENT_COUNT, "Too many color components: %d, max %d")
  151343. JMESSAGE(JERR_CONVERSION_NOTIMPL, "Unsupported color conversion request")
  151344. JMESSAGE(JERR_DAC_INDEX, "Bogus DAC index %d")
  151345. JMESSAGE(JERR_DAC_VALUE, "Bogus DAC value 0x%x")
  151346. JMESSAGE(JERR_DHT_INDEX, "Bogus DHT index %d")
  151347. JMESSAGE(JERR_DQT_INDEX, "Bogus DQT index %d")
  151348. JMESSAGE(JERR_EMPTY_IMAGE, "Empty JPEG image (DNL not supported)")
  151349. JMESSAGE(JERR_EMS_READ, "Read from EMS failed")
  151350. JMESSAGE(JERR_EMS_WRITE, "Write to EMS failed")
  151351. JMESSAGE(JERR_EOI_EXPECTED, "Didn't expect more than one scan")
  151352. JMESSAGE(JERR_FILE_READ, "Input file read error")
  151353. JMESSAGE(JERR_FILE_WRITE, "Output file write error --- out of disk space?")
  151354. JMESSAGE(JERR_FRACT_SAMPLE_NOTIMPL, "Fractional sampling not implemented yet")
  151355. JMESSAGE(JERR_HUFF_CLEN_OVERFLOW, "Huffman code size table overflow")
  151356. JMESSAGE(JERR_HUFF_MISSING_CODE, "Missing Huffman code table entry")
  151357. JMESSAGE(JERR_IMAGE_TOO_BIG, "Maximum supported image dimension is %u pixels")
  151358. JMESSAGE(JERR_INPUT_EMPTY, "Empty input file")
  151359. JMESSAGE(JERR_INPUT_EOF, "Premature end of input file")
  151360. JMESSAGE(JERR_MISMATCHED_QUANT_TABLE,
  151361. "Cannot transcode due to multiple use of quantization table %d")
  151362. JMESSAGE(JERR_MISSING_DATA, "Scan script does not transmit all data")
  151363. JMESSAGE(JERR_MODE_CHANGE, "Invalid color quantization mode change")
  151364. JMESSAGE(JERR_NOTIMPL, "Not implemented yet")
  151365. JMESSAGE(JERR_NOT_COMPILED, "Requested feature was omitted at compile time")
  151366. JMESSAGE(JERR_NO_BACKING_STORE, "Backing store not supported")
  151367. JMESSAGE(JERR_NO_HUFF_TABLE, "Huffman table 0x%02x was not defined")
  151368. JMESSAGE(JERR_NO_IMAGE, "JPEG datastream contains no image")
  151369. JMESSAGE(JERR_NO_QUANT_TABLE, "Quantization table 0x%02x was not defined")
  151370. JMESSAGE(JERR_NO_SOI, "Not a JPEG file: starts with 0x%02x 0x%02x")
  151371. JMESSAGE(JERR_OUT_OF_MEMORY, "Insufficient memory (case %d)")
  151372. JMESSAGE(JERR_QUANT_COMPONENTS,
  151373. "Cannot quantize more than %d color components")
  151374. JMESSAGE(JERR_QUANT_FEW_COLORS, "Cannot quantize to fewer than %d colors")
  151375. JMESSAGE(JERR_QUANT_MANY_COLORS, "Cannot quantize to more than %d colors")
  151376. JMESSAGE(JERR_SOF_DUPLICATE, "Invalid JPEG file structure: two SOF markers")
  151377. JMESSAGE(JERR_SOF_NO_SOS, "Invalid JPEG file structure: missing SOS marker")
  151378. JMESSAGE(JERR_SOF_UNSUPPORTED, "Unsupported JPEG process: SOF type 0x%02x")
  151379. JMESSAGE(JERR_SOI_DUPLICATE, "Invalid JPEG file structure: two SOI markers")
  151380. JMESSAGE(JERR_SOS_NO_SOF, "Invalid JPEG file structure: SOS before SOF")
  151381. JMESSAGE(JERR_TFILE_CREATE, "Failed to create temporary file %s")
  151382. JMESSAGE(JERR_TFILE_READ, "Read failed on temporary file")
  151383. JMESSAGE(JERR_TFILE_SEEK, "Seek failed on temporary file")
  151384. JMESSAGE(JERR_TFILE_WRITE,
  151385. "Write failed on temporary file --- out of disk space?")
  151386. JMESSAGE(JERR_TOO_LITTLE_DATA, "Application transferred too few scanlines")
  151387. JMESSAGE(JERR_UNKNOWN_MARKER, "Unsupported marker type 0x%02x")
  151388. JMESSAGE(JERR_VIRTUAL_BUG, "Virtual array controller messed up")
  151389. JMESSAGE(JERR_WIDTH_OVERFLOW, "Image too wide for this implementation")
  151390. JMESSAGE(JERR_XMS_READ, "Read from XMS failed")
  151391. JMESSAGE(JERR_XMS_WRITE, "Write to XMS failed")
  151392. JMESSAGE(JMSG_COPYRIGHT, JCOPYRIGHT)
  151393. JMESSAGE(JMSG_VERSION, JVERSION)
  151394. JMESSAGE(JTRC_16BIT_TABLES,
  151395. "Caution: quantization tables are too coarse for baseline JPEG")
  151396. JMESSAGE(JTRC_ADOBE,
  151397. "Adobe APP14 marker: version %d, flags 0x%04x 0x%04x, transform %d")
  151398. JMESSAGE(JTRC_APP0, "Unknown APP0 marker (not JFIF), length %u")
  151399. JMESSAGE(JTRC_APP14, "Unknown APP14 marker (not Adobe), length %u")
  151400. JMESSAGE(JTRC_DAC, "Define Arithmetic Table 0x%02x: 0x%02x")
  151401. JMESSAGE(JTRC_DHT, "Define Huffman Table 0x%02x")
  151402. JMESSAGE(JTRC_DQT, "Define Quantization Table %d precision %d")
  151403. JMESSAGE(JTRC_DRI, "Define Restart Interval %u")
  151404. JMESSAGE(JTRC_EMS_CLOSE, "Freed EMS handle %u")
  151405. JMESSAGE(JTRC_EMS_OPEN, "Obtained EMS handle %u")
  151406. JMESSAGE(JTRC_EOI, "End Of Image")
  151407. JMESSAGE(JTRC_HUFFBITS, " %3d %3d %3d %3d %3d %3d %3d %3d")
  151408. JMESSAGE(JTRC_JFIF, "JFIF APP0 marker: version %d.%02d, density %dx%d %d")
  151409. JMESSAGE(JTRC_JFIF_BADTHUMBNAILSIZE,
  151410. "Warning: thumbnail image size does not match data length %u")
  151411. JMESSAGE(JTRC_JFIF_EXTENSION,
  151412. "JFIF extension marker: type 0x%02x, length %u")
  151413. JMESSAGE(JTRC_JFIF_THUMBNAIL, " with %d x %d thumbnail image")
  151414. JMESSAGE(JTRC_MISC_MARKER, "Miscellaneous marker 0x%02x, length %u")
  151415. JMESSAGE(JTRC_PARMLESS_MARKER, "Unexpected marker 0x%02x")
  151416. JMESSAGE(JTRC_QUANTVALS, " %4u %4u %4u %4u %4u %4u %4u %4u")
  151417. JMESSAGE(JTRC_QUANT_3_NCOLORS, "Quantizing to %d = %d*%d*%d colors")
  151418. JMESSAGE(JTRC_QUANT_NCOLORS, "Quantizing to %d colors")
  151419. JMESSAGE(JTRC_QUANT_SELECTED, "Selected %d colors for quantization")
  151420. JMESSAGE(JTRC_RECOVERY_ACTION, "At marker 0x%02x, recovery action %d")
  151421. JMESSAGE(JTRC_RST, "RST%d")
  151422. JMESSAGE(JTRC_SMOOTH_NOTIMPL,
  151423. "Smoothing not supported with nonstandard sampling ratios")
  151424. JMESSAGE(JTRC_SOF, "Start Of Frame 0x%02x: width=%u, height=%u, components=%d")
  151425. JMESSAGE(JTRC_SOF_COMPONENT, " Component %d: %dhx%dv q=%d")
  151426. JMESSAGE(JTRC_SOI, "Start of Image")
  151427. JMESSAGE(JTRC_SOS, "Start Of Scan: %d components")
  151428. JMESSAGE(JTRC_SOS_COMPONENT, " Component %d: dc=%d ac=%d")
  151429. JMESSAGE(JTRC_SOS_PARAMS, " Ss=%d, Se=%d, Ah=%d, Al=%d")
  151430. JMESSAGE(JTRC_TFILE_CLOSE, "Closed temporary file %s")
  151431. JMESSAGE(JTRC_TFILE_OPEN, "Opened temporary file %s")
  151432. JMESSAGE(JTRC_THUMB_JPEG,
  151433. "JFIF extension marker: JPEG-compressed thumbnail image, length %u")
  151434. JMESSAGE(JTRC_THUMB_PALETTE,
  151435. "JFIF extension marker: palette thumbnail image, length %u")
  151436. JMESSAGE(JTRC_THUMB_RGB,
  151437. "JFIF extension marker: RGB thumbnail image, length %u")
  151438. JMESSAGE(JTRC_UNKNOWN_IDS,
  151439. "Unrecognized component IDs %d %d %d, assuming YCbCr")
  151440. JMESSAGE(JTRC_XMS_CLOSE, "Freed XMS handle %u")
  151441. JMESSAGE(JTRC_XMS_OPEN, "Obtained XMS handle %u")
  151442. JMESSAGE(JWRN_ADOBE_XFORM, "Unknown Adobe color transform code %d")
  151443. JMESSAGE(JWRN_BOGUS_PROGRESSION,
  151444. "Inconsistent progression sequence for component %d coefficient %d")
  151445. JMESSAGE(JWRN_EXTRANEOUS_DATA,
  151446. "Corrupt JPEG data: %u extraneous bytes before marker 0x%02x")
  151447. JMESSAGE(JWRN_HIT_MARKER, "Corrupt JPEG data: premature end of data segment")
  151448. JMESSAGE(JWRN_HUFF_BAD_CODE, "Corrupt JPEG data: bad Huffman code")
  151449. JMESSAGE(JWRN_JFIF_MAJOR, "Warning: unknown JFIF revision number %d.%02d")
  151450. JMESSAGE(JWRN_JPEG_EOF, "Premature end of JPEG file")
  151451. JMESSAGE(JWRN_MUST_RESYNC,
  151452. "Corrupt JPEG data: found marker 0x%02x instead of RST%d")
  151453. JMESSAGE(JWRN_NOT_SEQUENTIAL, "Invalid SOS parameters for sequential JPEG")
  151454. JMESSAGE(JWRN_TOO_MUCH_DATA, "Application transferred too many scanlines")
  151455. #ifdef JMAKE_ENUM_LIST
  151456. JMSG_LASTMSGCODE
  151457. } J_MESSAGE_CODE;
  151458. #undef JMAKE_ENUM_LIST
  151459. #endif /* JMAKE_ENUM_LIST */
  151460. #undef JMESSAGE
  151461. #ifndef JERROR_H
  151462. #define JERROR_H
  151463. #define ERREXIT(cinfo,code) \
  151464. ((cinfo)->err->msg_code = (code), \
  151465. (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
  151466. #define ERREXIT1(cinfo,code,p1) \
  151467. ((cinfo)->err->msg_code = (code), \
  151468. (cinfo)->err->msg_parm.i[0] = (p1), \
  151469. (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
  151470. #define ERREXIT2(cinfo,code,p1,p2) \
  151471. ((cinfo)->err->msg_code = (code), \
  151472. (cinfo)->err->msg_parm.i[0] = (p1), \
  151473. (cinfo)->err->msg_parm.i[1] = (p2), \
  151474. (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
  151475. #define ERREXIT3(cinfo,code,p1,p2,p3) \
  151476. ((cinfo)->err->msg_code = (code), \
  151477. (cinfo)->err->msg_parm.i[0] = (p1), \
  151478. (cinfo)->err->msg_parm.i[1] = (p2), \
  151479. (cinfo)->err->msg_parm.i[2] = (p3), \
  151480. (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
  151481. #define ERREXIT4(cinfo,code,p1,p2,p3,p4) \
  151482. ((cinfo)->err->msg_code = (code), \
  151483. (cinfo)->err->msg_parm.i[0] = (p1), \
  151484. (cinfo)->err->msg_parm.i[1] = (p2), \
  151485. (cinfo)->err->msg_parm.i[2] = (p3), \
  151486. (cinfo)->err->msg_parm.i[3] = (p4), \
  151487. (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
  151488. #define ERREXITS(cinfo,code,str) \
  151489. ((cinfo)->err->msg_code = (code), \
  151490. strncpy((cinfo)->err->msg_parm.s, (str), JMSG_STR_PARM_MAX), \
  151491. (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
  151492. #define MAKESTMT(stuff) do { stuff } while (0)
  151493. #define WARNMS(cinfo,code) \
  151494. ((cinfo)->err->msg_code = (code), \
  151495. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), -1))
  151496. #define WARNMS1(cinfo,code,p1) \
  151497. ((cinfo)->err->msg_code = (code), \
  151498. (cinfo)->err->msg_parm.i[0] = (p1), \
  151499. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), -1))
  151500. #define WARNMS2(cinfo,code,p1,p2) \
  151501. ((cinfo)->err->msg_code = (code), \
  151502. (cinfo)->err->msg_parm.i[0] = (p1), \
  151503. (cinfo)->err->msg_parm.i[1] = (p2), \
  151504. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), -1))
  151505. #define TRACEMS(cinfo,lvl,code) \
  151506. ((cinfo)->err->msg_code = (code), \
  151507. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)))
  151508. #define TRACEMS1(cinfo,lvl,code,p1) \
  151509. ((cinfo)->err->msg_code = (code), \
  151510. (cinfo)->err->msg_parm.i[0] = (p1), \
  151511. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)))
  151512. #define TRACEMS2(cinfo,lvl,code,p1,p2) \
  151513. ((cinfo)->err->msg_code = (code), \
  151514. (cinfo)->err->msg_parm.i[0] = (p1), \
  151515. (cinfo)->err->msg_parm.i[1] = (p2), \
  151516. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)))
  151517. #define TRACEMS3(cinfo,lvl,code,p1,p2,p3) \
  151518. MAKESTMT(int * _mp = (cinfo)->err->msg_parm.i; \
  151519. _mp[0] = (p1); _mp[1] = (p2); _mp[2] = (p3); \
  151520. (cinfo)->err->msg_code = (code); \
  151521. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)); )
  151522. #define TRACEMS4(cinfo,lvl,code,p1,p2,p3,p4) \
  151523. MAKESTMT(int * _mp = (cinfo)->err->msg_parm.i; \
  151524. _mp[0] = (p1); _mp[1] = (p2); _mp[2] = (p3); _mp[3] = (p4); \
  151525. (cinfo)->err->msg_code = (code); \
  151526. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)); )
  151527. #define TRACEMS5(cinfo,lvl,code,p1,p2,p3,p4,p5) \
  151528. MAKESTMT(int * _mp = (cinfo)->err->msg_parm.i; \
  151529. _mp[0] = (p1); _mp[1] = (p2); _mp[2] = (p3); _mp[3] = (p4); \
  151530. _mp[4] = (p5); \
  151531. (cinfo)->err->msg_code = (code); \
  151532. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)); )
  151533. #define TRACEMS8(cinfo,lvl,code,p1,p2,p3,p4,p5,p6,p7,p8) \
  151534. MAKESTMT(int * _mp = (cinfo)->err->msg_parm.i; \
  151535. _mp[0] = (p1); _mp[1] = (p2); _mp[2] = (p3); _mp[3] = (p4); \
  151536. _mp[4] = (p5); _mp[5] = (p6); _mp[6] = (p7); _mp[7] = (p8); \
  151537. (cinfo)->err->msg_code = (code); \
  151538. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)); )
  151539. #define TRACEMSS(cinfo,lvl,code,str) \
  151540. ((cinfo)->err->msg_code = (code), \
  151541. strncpy((cinfo)->err->msg_parm.s, (str), JMSG_STR_PARM_MAX), \
  151542. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)))
  151543. #endif /* JERROR_H */
  151544. /********* End of inlined file: jerror.h *********/
  151545. typedef struct {
  151546. struct jpeg_source_mgr pub; /* public fields */
  151547. FILE * infile; /* source stream */
  151548. JOCTET * buffer; /* start of buffer */
  151549. boolean start_of_file; /* have we gotten any data yet? */
  151550. } my_source_mgr;
  151551. typedef my_source_mgr * my_src_ptr;
  151552. #define INPUT_BUF_SIZE 4096 /* choose an efficiently fread'able size */
  151553. METHODDEF(void)
  151554. init_source (j_decompress_ptr cinfo)
  151555. {
  151556. my_src_ptr src = (my_src_ptr) cinfo->src;
  151557. src->start_of_file = TRUE;
  151558. }
  151559. METHODDEF(boolean)
  151560. fill_input_buffer (j_decompress_ptr cinfo)
  151561. {
  151562. my_src_ptr src = (my_src_ptr) cinfo->src;
  151563. size_t nbytes;
  151564. nbytes = JFREAD(src->infile, src->buffer, INPUT_BUF_SIZE);
  151565. if (nbytes <= 0) {
  151566. if (src->start_of_file) /* Treat empty input file as fatal error */
  151567. ERREXIT(cinfo, JERR_INPUT_EMPTY);
  151568. WARNMS(cinfo, JWRN_JPEG_EOF);
  151569. src->buffer[0] = (JOCTET) 0xFF;
  151570. src->buffer[1] = (JOCTET) JPEG_EOI;
  151571. nbytes = 2;
  151572. }
  151573. src->pub.next_input_byte = src->buffer;
  151574. src->pub.bytes_in_buffer = nbytes;
  151575. src->start_of_file = FALSE;
  151576. return TRUE;
  151577. }
  151578. METHODDEF(void)
  151579. skip_input_data (j_decompress_ptr cinfo, long num_bytes)
  151580. {
  151581. my_src_ptr src = (my_src_ptr) cinfo->src;
  151582. if (num_bytes > 0) {
  151583. while (num_bytes > (long) src->pub.bytes_in_buffer) {
  151584. num_bytes -= (long) src->pub.bytes_in_buffer;
  151585. (void) fill_input_buffer(cinfo);
  151586. }
  151587. src->pub.next_input_byte += (size_t) num_bytes;
  151588. src->pub.bytes_in_buffer -= (size_t) num_bytes;
  151589. }
  151590. }
  151591. METHODDEF(void)
  151592. term_source (j_decompress_ptr cinfo)
  151593. {
  151594. }
  151595. GLOBAL(void)
  151596. jpeg_stdio_src (j_decompress_ptr cinfo, FILE * infile)
  151597. {
  151598. my_src_ptr src;
  151599. if (cinfo->src == NULL) { /* first time for this JPEG object? */
  151600. cinfo->src = (struct jpeg_source_mgr *)
  151601. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
  151602. SIZEOF(my_source_mgr));
  151603. src = (my_src_ptr) cinfo->src;
  151604. src->buffer = (JOCTET *)
  151605. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
  151606. INPUT_BUF_SIZE * SIZEOF(JOCTET));
  151607. }
  151608. src = (my_src_ptr) cinfo->src;
  151609. src->pub.init_source = init_source;
  151610. src->pub.fill_input_buffer = fill_input_buffer;
  151611. src->pub.skip_input_data = skip_input_data;
  151612. src->pub.resync_to_restart = jpeg_resync_to_restart; /* use default method */
  151613. src->pub.term_source = term_source;
  151614. src->infile = infile;
  151615. src->pub.bytes_in_buffer = 0; /* forces fill_input_buffer on first read */
  151616. src->pub.next_input_byte = NULL; /* until buffer loaded */
  151617. }
  151618. /********* End of inlined file: jdatasrc.c *********/
  151619. /********* Start of inlined file: jdcoefct.c *********/
  151620. #define JPEG_INTERNALS
  151621. #ifndef D_PROGRESSIVE_SUPPORTED
  151622. #undef BLOCK_SMOOTHING_SUPPORTED
  151623. #endif
  151624. typedef struct {
  151625. struct jpeg_d_coef_controller pub; /* public fields */
  151626. JDIMENSION MCU_ctr; /* counts MCUs processed in current row */
  151627. int MCU_vert_offset; /* counts MCU rows within iMCU row */
  151628. int MCU_rows_per_iMCU_row; /* number of such rows needed */
  151629. JBLOCKROW MCU_buffer[D_MAX_BLOCKS_IN_MCU];
  151630. #ifdef D_MULTISCAN_FILES_SUPPORTED
  151631. jvirt_barray_ptr whole_image[MAX_COMPONENTS];
  151632. #endif
  151633. #ifdef BLOCK_SMOOTHING_SUPPORTED
  151634. int * coef_bits_latch;
  151635. #define SAVED_COEFS 6 /* we save coef_bits[0..5] */
  151636. #endif
  151637. } my_coef_controller3;
  151638. typedef my_coef_controller3 * my_coef_ptr3;
  151639. METHODDEF(int) decompress_onepass
  151640. JPP((j_decompress_ptr cinfo, JSAMPIMAGE output_buf));
  151641. #ifdef D_MULTISCAN_FILES_SUPPORTED
  151642. METHODDEF(int) decompress_data
  151643. JPP((j_decompress_ptr cinfo, JSAMPIMAGE output_buf));
  151644. #endif
  151645. #ifdef BLOCK_SMOOTHING_SUPPORTED
  151646. LOCAL(boolean) smoothing_ok JPP((j_decompress_ptr cinfo));
  151647. METHODDEF(int) decompress_smooth_data
  151648. JPP((j_decompress_ptr cinfo, JSAMPIMAGE output_buf));
  151649. #endif
  151650. LOCAL(void)
  151651. start_iMCU_row3 (j_decompress_ptr cinfo)
  151652. {
  151653. my_coef_ptr3 coef = (my_coef_ptr3) cinfo->coef;
  151654. if (cinfo->comps_in_scan > 1) {
  151655. coef->MCU_rows_per_iMCU_row = 1;
  151656. } else {
  151657. if (cinfo->input_iMCU_row < (cinfo->total_iMCU_rows-1))
  151658. coef->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor;
  151659. else
  151660. coef->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height;
  151661. }
  151662. coef->MCU_ctr = 0;
  151663. coef->MCU_vert_offset = 0;
  151664. }
  151665. METHODDEF(void)
  151666. start_input_pass (j_decompress_ptr cinfo)
  151667. {
  151668. cinfo->input_iMCU_row = 0;
  151669. start_iMCU_row3(cinfo);
  151670. }
  151671. METHODDEF(void)
  151672. start_output_pass (j_decompress_ptr cinfo)
  151673. {
  151674. #ifdef BLOCK_SMOOTHING_SUPPORTED
  151675. my_coef_ptr3 coef = (my_coef_ptr3) cinfo->coef;
  151676. if (coef->pub.coef_arrays != NULL) {
  151677. if (cinfo->do_block_smoothing && smoothing_ok(cinfo))
  151678. coef->pub.decompress_data = decompress_smooth_data;
  151679. else
  151680. coef->pub.decompress_data = decompress_data;
  151681. }
  151682. #endif
  151683. cinfo->output_iMCU_row = 0;
  151684. }
  151685. METHODDEF(int)
  151686. decompress_onepass (j_decompress_ptr cinfo, JSAMPIMAGE output_buf)
  151687. {
  151688. my_coef_ptr3 coef = (my_coef_ptr3) cinfo->coef;
  151689. JDIMENSION MCU_col_num; /* index of current MCU within row */
  151690. JDIMENSION last_MCU_col = cinfo->MCUs_per_row - 1;
  151691. JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
  151692. int blkn, ci, xindex, yindex, yoffset, useful_width;
  151693. JSAMPARRAY output_ptr;
  151694. JDIMENSION start_col, output_col;
  151695. jpeg_component_info *compptr;
  151696. inverse_DCT_method_ptr inverse_DCT;
  151697. for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row;
  151698. yoffset++) {
  151699. for (MCU_col_num = coef->MCU_ctr; MCU_col_num <= last_MCU_col;
  151700. MCU_col_num++) {
  151701. jzero_far((void FAR *) coef->MCU_buffer[0],
  151702. (size_t) (cinfo->blocks_in_MCU * SIZEOF(JBLOCK)));
  151703. if (! (*cinfo->entropy->decode_mcu) (cinfo, coef->MCU_buffer)) {
  151704. coef->MCU_vert_offset = yoffset;
  151705. coef->MCU_ctr = MCU_col_num;
  151706. return JPEG_SUSPENDED;
  151707. }
  151708. blkn = 0; /* index of current DCT block within MCU */
  151709. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  151710. compptr = cinfo->cur_comp_info[ci];
  151711. if (! compptr->component_needed) {
  151712. blkn += compptr->MCU_blocks;
  151713. continue;
  151714. }
  151715. inverse_DCT = cinfo->idct->inverse_DCT[compptr->component_index];
  151716. useful_width = (MCU_col_num < last_MCU_col) ? compptr->MCU_width
  151717. : compptr->last_col_width;
  151718. output_ptr = output_buf[compptr->component_index] +
  151719. yoffset * compptr->DCT_scaled_size;
  151720. start_col = MCU_col_num * compptr->MCU_sample_width;
  151721. for (yindex = 0; yindex < compptr->MCU_height; yindex++) {
  151722. if (cinfo->input_iMCU_row < last_iMCU_row ||
  151723. yoffset+yindex < compptr->last_row_height) {
  151724. output_col = start_col;
  151725. for (xindex = 0; xindex < useful_width; xindex++) {
  151726. (*inverse_DCT) (cinfo, compptr,
  151727. (JCOEFPTR) coef->MCU_buffer[blkn+xindex],
  151728. output_ptr, output_col);
  151729. output_col += compptr->DCT_scaled_size;
  151730. }
  151731. }
  151732. blkn += compptr->MCU_width;
  151733. output_ptr += compptr->DCT_scaled_size;
  151734. }
  151735. }
  151736. }
  151737. coef->MCU_ctr = 0;
  151738. }
  151739. cinfo->output_iMCU_row++;
  151740. if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
  151741. start_iMCU_row3(cinfo);
  151742. return JPEG_ROW_COMPLETED;
  151743. }
  151744. (*cinfo->inputctl->finish_input_pass) (cinfo);
  151745. return JPEG_SCAN_COMPLETED;
  151746. }
  151747. METHODDEF(int)
  151748. dummy_consume_data (j_decompress_ptr cinfo)
  151749. {
  151750. return JPEG_SUSPENDED; /* Always indicate nothing was done */
  151751. }
  151752. #ifdef D_MULTISCAN_FILES_SUPPORTED
  151753. METHODDEF(int)
  151754. consume_data (j_decompress_ptr cinfo)
  151755. {
  151756. my_coef_ptr3 coef = (my_coef_ptr3) cinfo->coef;
  151757. JDIMENSION MCU_col_num; /* index of current MCU within row */
  151758. int blkn, ci, xindex, yindex, yoffset;
  151759. JDIMENSION start_col;
  151760. JBLOCKARRAY buffer[MAX_COMPS_IN_SCAN];
  151761. JBLOCKROW buffer_ptr;
  151762. jpeg_component_info *compptr;
  151763. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  151764. compptr = cinfo->cur_comp_info[ci];
  151765. buffer[ci] = (*cinfo->mem->access_virt_barray)
  151766. ((j_common_ptr) cinfo, coef->whole_image[compptr->component_index],
  151767. cinfo->input_iMCU_row * compptr->v_samp_factor,
  151768. (JDIMENSION) compptr->v_samp_factor, TRUE);
  151769. }
  151770. for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row;
  151771. yoffset++) {
  151772. for (MCU_col_num = coef->MCU_ctr; MCU_col_num < cinfo->MCUs_per_row;
  151773. MCU_col_num++) {
  151774. blkn = 0; /* index of current DCT block within MCU */
  151775. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  151776. compptr = cinfo->cur_comp_info[ci];
  151777. start_col = MCU_col_num * compptr->MCU_width;
  151778. for (yindex = 0; yindex < compptr->MCU_height; yindex++) {
  151779. buffer_ptr = buffer[ci][yindex+yoffset] + start_col;
  151780. for (xindex = 0; xindex < compptr->MCU_width; xindex++) {
  151781. coef->MCU_buffer[blkn++] = buffer_ptr++;
  151782. }
  151783. }
  151784. }
  151785. if (! (*cinfo->entropy->decode_mcu) (cinfo, coef->MCU_buffer)) {
  151786. coef->MCU_vert_offset = yoffset;
  151787. coef->MCU_ctr = MCU_col_num;
  151788. return JPEG_SUSPENDED;
  151789. }
  151790. }
  151791. coef->MCU_ctr = 0;
  151792. }
  151793. if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
  151794. start_iMCU_row3(cinfo);
  151795. return JPEG_ROW_COMPLETED;
  151796. }
  151797. (*cinfo->inputctl->finish_input_pass) (cinfo);
  151798. return JPEG_SCAN_COMPLETED;
  151799. }
  151800. METHODDEF(int)
  151801. decompress_data (j_decompress_ptr cinfo, JSAMPIMAGE output_buf)
  151802. {
  151803. my_coef_ptr3 coef = (my_coef_ptr3) cinfo->coef;
  151804. JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
  151805. JDIMENSION block_num;
  151806. int ci, block_row, block_rows;
  151807. JBLOCKARRAY buffer;
  151808. JBLOCKROW buffer_ptr;
  151809. JSAMPARRAY output_ptr;
  151810. JDIMENSION output_col;
  151811. jpeg_component_info *compptr;
  151812. inverse_DCT_method_ptr inverse_DCT;
  151813. while (cinfo->input_scan_number < cinfo->output_scan_number ||
  151814. (cinfo->input_scan_number == cinfo->output_scan_number &&
  151815. cinfo->input_iMCU_row <= cinfo->output_iMCU_row)) {
  151816. if ((*cinfo->inputctl->consume_input)(cinfo) == JPEG_SUSPENDED)
  151817. return JPEG_SUSPENDED;
  151818. }
  151819. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  151820. ci++, compptr++) {
  151821. if (! compptr->component_needed)
  151822. continue;
  151823. buffer = (*cinfo->mem->access_virt_barray)
  151824. ((j_common_ptr) cinfo, coef->whole_image[ci],
  151825. cinfo->output_iMCU_row * compptr->v_samp_factor,
  151826. (JDIMENSION) compptr->v_samp_factor, FALSE);
  151827. if (cinfo->output_iMCU_row < last_iMCU_row)
  151828. block_rows = compptr->v_samp_factor;
  151829. else {
  151830. block_rows = (int) (compptr->height_in_blocks % compptr->v_samp_factor);
  151831. if (block_rows == 0) block_rows = compptr->v_samp_factor;
  151832. }
  151833. inverse_DCT = cinfo->idct->inverse_DCT[ci];
  151834. output_ptr = output_buf[ci];
  151835. for (block_row = 0; block_row < block_rows; block_row++) {
  151836. buffer_ptr = buffer[block_row];
  151837. output_col = 0;
  151838. for (block_num = 0; block_num < compptr->width_in_blocks; block_num++) {
  151839. (*inverse_DCT) (cinfo, compptr, (JCOEFPTR) buffer_ptr,
  151840. output_ptr, output_col);
  151841. buffer_ptr++;
  151842. output_col += compptr->DCT_scaled_size;
  151843. }
  151844. output_ptr += compptr->DCT_scaled_size;
  151845. }
  151846. }
  151847. if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows)
  151848. return JPEG_ROW_COMPLETED;
  151849. return JPEG_SCAN_COMPLETED;
  151850. }
  151851. #endif /* D_MULTISCAN_FILES_SUPPORTED */
  151852. #ifdef BLOCK_SMOOTHING_SUPPORTED
  151853. #define Q01_POS 1
  151854. #define Q10_POS 8
  151855. #define Q20_POS 16
  151856. #define Q11_POS 9
  151857. #define Q02_POS 2
  151858. LOCAL(boolean)
  151859. smoothing_ok (j_decompress_ptr cinfo)
  151860. {
  151861. my_coef_ptr3 coef = (my_coef_ptr3) cinfo->coef;
  151862. boolean smoothing_useful = FALSE;
  151863. int ci, coefi;
  151864. jpeg_component_info *compptr;
  151865. JQUANT_TBL * qtable;
  151866. int * coef_bits;
  151867. int * coef_bits_latch;
  151868. if (! cinfo->progressive_mode || cinfo->coef_bits == NULL)
  151869. return FALSE;
  151870. if (coef->coef_bits_latch == NULL)
  151871. coef->coef_bits_latch = (int *)
  151872. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  151873. cinfo->num_components *
  151874. (SAVED_COEFS * SIZEOF(int)));
  151875. coef_bits_latch = coef->coef_bits_latch;
  151876. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  151877. ci++, compptr++) {
  151878. if ((qtable = compptr->quant_table) == NULL)
  151879. return FALSE;
  151880. if (qtable->quantval[0] == 0 ||
  151881. qtable->quantval[Q01_POS] == 0 ||
  151882. qtable->quantval[Q10_POS] == 0 ||
  151883. qtable->quantval[Q20_POS] == 0 ||
  151884. qtable->quantval[Q11_POS] == 0 ||
  151885. qtable->quantval[Q02_POS] == 0)
  151886. return FALSE;
  151887. coef_bits = cinfo->coef_bits[ci];
  151888. if (coef_bits[0] < 0)
  151889. return FALSE;
  151890. for (coefi = 1; coefi <= 5; coefi++) {
  151891. coef_bits_latch[coefi] = coef_bits[coefi];
  151892. if (coef_bits[coefi] != 0)
  151893. smoothing_useful = TRUE;
  151894. }
  151895. coef_bits_latch += SAVED_COEFS;
  151896. }
  151897. return smoothing_useful;
  151898. }
  151899. METHODDEF(int)
  151900. decompress_smooth_data (j_decompress_ptr cinfo, JSAMPIMAGE output_buf)
  151901. {
  151902. my_coef_ptr3 coef = (my_coef_ptr3) cinfo->coef;
  151903. JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
  151904. JDIMENSION block_num, last_block_column;
  151905. int ci, block_row, block_rows, access_rows;
  151906. JBLOCKARRAY buffer;
  151907. JBLOCKROW buffer_ptr, prev_block_row, next_block_row;
  151908. JSAMPARRAY output_ptr;
  151909. JDIMENSION output_col;
  151910. jpeg_component_info *compptr;
  151911. inverse_DCT_method_ptr inverse_DCT;
  151912. boolean first_row, last_row;
  151913. JBLOCK workspace;
  151914. int *coef_bits;
  151915. JQUANT_TBL *quanttbl;
  151916. INT32 Q00,Q01,Q02,Q10,Q11,Q20, num;
  151917. int DC1,DC2,DC3,DC4,DC5,DC6,DC7,DC8,DC9;
  151918. int Al, pred;
  151919. while (cinfo->input_scan_number <= cinfo->output_scan_number &&
  151920. ! cinfo->inputctl->eoi_reached) {
  151921. if (cinfo->input_scan_number == cinfo->output_scan_number) {
  151922. JDIMENSION delta = (cinfo->Ss == 0) ? 1 : 0;
  151923. if (cinfo->input_iMCU_row > cinfo->output_iMCU_row+delta)
  151924. break;
  151925. }
  151926. if ((*cinfo->inputctl->consume_input)(cinfo) == JPEG_SUSPENDED)
  151927. return JPEG_SUSPENDED;
  151928. }
  151929. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  151930. ci++, compptr++) {
  151931. if (! compptr->component_needed)
  151932. continue;
  151933. if (cinfo->output_iMCU_row < last_iMCU_row) {
  151934. block_rows = compptr->v_samp_factor;
  151935. access_rows = block_rows * 2; /* this and next iMCU row */
  151936. last_row = FALSE;
  151937. } else {
  151938. block_rows = (int) (compptr->height_in_blocks % compptr->v_samp_factor);
  151939. if (block_rows == 0) block_rows = compptr->v_samp_factor;
  151940. access_rows = block_rows; /* this iMCU row only */
  151941. last_row = TRUE;
  151942. }
  151943. if (cinfo->output_iMCU_row > 0) {
  151944. access_rows += compptr->v_samp_factor; /* prior iMCU row too */
  151945. buffer = (*cinfo->mem->access_virt_barray)
  151946. ((j_common_ptr) cinfo, coef->whole_image[ci],
  151947. (cinfo->output_iMCU_row - 1) * compptr->v_samp_factor,
  151948. (JDIMENSION) access_rows, FALSE);
  151949. buffer += compptr->v_samp_factor; /* point to current iMCU row */
  151950. first_row = FALSE;
  151951. } else {
  151952. buffer = (*cinfo->mem->access_virt_barray)
  151953. ((j_common_ptr) cinfo, coef->whole_image[ci],
  151954. (JDIMENSION) 0, (JDIMENSION) access_rows, FALSE);
  151955. first_row = TRUE;
  151956. }
  151957. coef_bits = coef->coef_bits_latch + (ci * SAVED_COEFS);
  151958. quanttbl = compptr->quant_table;
  151959. Q00 = quanttbl->quantval[0];
  151960. Q01 = quanttbl->quantval[Q01_POS];
  151961. Q10 = quanttbl->quantval[Q10_POS];
  151962. Q20 = quanttbl->quantval[Q20_POS];
  151963. Q11 = quanttbl->quantval[Q11_POS];
  151964. Q02 = quanttbl->quantval[Q02_POS];
  151965. inverse_DCT = cinfo->idct->inverse_DCT[ci];
  151966. output_ptr = output_buf[ci];
  151967. for (block_row = 0; block_row < block_rows; block_row++) {
  151968. buffer_ptr = buffer[block_row];
  151969. if (first_row && block_row == 0)
  151970. prev_block_row = buffer_ptr;
  151971. else
  151972. prev_block_row = buffer[block_row-1];
  151973. if (last_row && block_row == block_rows-1)
  151974. next_block_row = buffer_ptr;
  151975. else
  151976. next_block_row = buffer[block_row+1];
  151977. DC1 = DC2 = DC3 = (int) prev_block_row[0][0];
  151978. DC4 = DC5 = DC6 = (int) buffer_ptr[0][0];
  151979. DC7 = DC8 = DC9 = (int) next_block_row[0][0];
  151980. output_col = 0;
  151981. last_block_column = compptr->width_in_blocks - 1;
  151982. for (block_num = 0; block_num <= last_block_column; block_num++) {
  151983. jcopy_block_row(buffer_ptr, (JBLOCKROW) workspace, (JDIMENSION) 1);
  151984. if (block_num < last_block_column) {
  151985. DC3 = (int) prev_block_row[1][0];
  151986. DC6 = (int) buffer_ptr[1][0];
  151987. DC9 = (int) next_block_row[1][0];
  151988. }
  151989. if ((Al=coef_bits[1]) != 0 && workspace[1] == 0) {
  151990. num = 36 * Q00 * (DC4 - DC6);
  151991. if (num >= 0) {
  151992. pred = (int) (((Q01<<7) + num) / (Q01<<8));
  151993. if (Al > 0 && pred >= (1<<Al))
  151994. pred = (1<<Al)-1;
  151995. } else {
  151996. pred = (int) (((Q01<<7) - num) / (Q01<<8));
  151997. if (Al > 0 && pred >= (1<<Al))
  151998. pred = (1<<Al)-1;
  151999. pred = -pred;
  152000. }
  152001. workspace[1] = (JCOEF) pred;
  152002. }
  152003. if ((Al=coef_bits[2]) != 0 && workspace[8] == 0) {
  152004. num = 36 * Q00 * (DC2 - DC8);
  152005. if (num >= 0) {
  152006. pred = (int) (((Q10<<7) + num) / (Q10<<8));
  152007. if (Al > 0 && pred >= (1<<Al))
  152008. pred = (1<<Al)-1;
  152009. } else {
  152010. pred = (int) (((Q10<<7) - num) / (Q10<<8));
  152011. if (Al > 0 && pred >= (1<<Al))
  152012. pred = (1<<Al)-1;
  152013. pred = -pred;
  152014. }
  152015. workspace[8] = (JCOEF) pred;
  152016. }
  152017. if ((Al=coef_bits[3]) != 0 && workspace[16] == 0) {
  152018. num = 9 * Q00 * (DC2 + DC8 - 2*DC5);
  152019. if (num >= 0) {
  152020. pred = (int) (((Q20<<7) + num) / (Q20<<8));
  152021. if (Al > 0 && pred >= (1<<Al))
  152022. pred = (1<<Al)-1;
  152023. } else {
  152024. pred = (int) (((Q20<<7) - num) / (Q20<<8));
  152025. if (Al > 0 && pred >= (1<<Al))
  152026. pred = (1<<Al)-1;
  152027. pred = -pred;
  152028. }
  152029. workspace[16] = (JCOEF) pred;
  152030. }
  152031. if ((Al=coef_bits[4]) != 0 && workspace[9] == 0) {
  152032. num = 5 * Q00 * (DC1 - DC3 - DC7 + DC9);
  152033. if (num >= 0) {
  152034. pred = (int) (((Q11<<7) + num) / (Q11<<8));
  152035. if (Al > 0 && pred >= (1<<Al))
  152036. pred = (1<<Al)-1;
  152037. } else {
  152038. pred = (int) (((Q11<<7) - num) / (Q11<<8));
  152039. if (Al > 0 && pred >= (1<<Al))
  152040. pred = (1<<Al)-1;
  152041. pred = -pred;
  152042. }
  152043. workspace[9] = (JCOEF) pred;
  152044. }
  152045. if ((Al=coef_bits[5]) != 0 && workspace[2] == 0) {
  152046. num = 9 * Q00 * (DC4 + DC6 - 2*DC5);
  152047. if (num >= 0) {
  152048. pred = (int) (((Q02<<7) + num) / (Q02<<8));
  152049. if (Al > 0 && pred >= (1<<Al))
  152050. pred = (1<<Al)-1;
  152051. } else {
  152052. pred = (int) (((Q02<<7) - num) / (Q02<<8));
  152053. if (Al > 0 && pred >= (1<<Al))
  152054. pred = (1<<Al)-1;
  152055. pred = -pred;
  152056. }
  152057. workspace[2] = (JCOEF) pred;
  152058. }
  152059. (*inverse_DCT) (cinfo, compptr, (JCOEFPTR) workspace,
  152060. output_ptr, output_col);
  152061. DC1 = DC2; DC2 = DC3;
  152062. DC4 = DC5; DC5 = DC6;
  152063. DC7 = DC8; DC8 = DC9;
  152064. buffer_ptr++, prev_block_row++, next_block_row++;
  152065. output_col += compptr->DCT_scaled_size;
  152066. }
  152067. output_ptr += compptr->DCT_scaled_size;
  152068. }
  152069. }
  152070. if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows)
  152071. return JPEG_ROW_COMPLETED;
  152072. return JPEG_SCAN_COMPLETED;
  152073. }
  152074. #endif /* BLOCK_SMOOTHING_SUPPORTED */
  152075. GLOBAL(void)
  152076. jinit_d_coef_controller (j_decompress_ptr cinfo, boolean need_full_buffer)
  152077. {
  152078. my_coef_ptr3 coef;
  152079. coef = (my_coef_ptr3)
  152080. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  152081. SIZEOF(my_coef_controller3));
  152082. cinfo->coef = (struct jpeg_d_coef_controller *) coef;
  152083. coef->pub.start_input_pass = start_input_pass;
  152084. coef->pub.start_output_pass = start_output_pass;
  152085. #ifdef BLOCK_SMOOTHING_SUPPORTED
  152086. coef->coef_bits_latch = NULL;
  152087. #endif
  152088. if (need_full_buffer) {
  152089. #ifdef D_MULTISCAN_FILES_SUPPORTED
  152090. int ci, access_rows;
  152091. jpeg_component_info *compptr;
  152092. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  152093. ci++, compptr++) {
  152094. access_rows = compptr->v_samp_factor;
  152095. #ifdef BLOCK_SMOOTHING_SUPPORTED
  152096. if (cinfo->progressive_mode)
  152097. access_rows *= 3;
  152098. #endif
  152099. coef->whole_image[ci] = (*cinfo->mem->request_virt_barray)
  152100. ((j_common_ptr) cinfo, JPOOL_IMAGE, TRUE,
  152101. (JDIMENSION) jround_up((long) compptr->width_in_blocks,
  152102. (long) compptr->h_samp_factor),
  152103. (JDIMENSION) jround_up((long) compptr->height_in_blocks,
  152104. (long) compptr->v_samp_factor),
  152105. (JDIMENSION) access_rows);
  152106. }
  152107. coef->pub.consume_data = consume_data;
  152108. coef->pub.decompress_data = decompress_data;
  152109. coef->pub.coef_arrays = coef->whole_image; /* link to virtual arrays */
  152110. #else
  152111. ERREXIT(cinfo, JERR_NOT_COMPILED);
  152112. #endif
  152113. } else {
  152114. JBLOCKROW buffer;
  152115. int i;
  152116. buffer = (JBLOCKROW)
  152117. (*cinfo->mem->alloc_large) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  152118. D_MAX_BLOCKS_IN_MCU * SIZEOF(JBLOCK));
  152119. for (i = 0; i < D_MAX_BLOCKS_IN_MCU; i++) {
  152120. coef->MCU_buffer[i] = buffer + i;
  152121. }
  152122. coef->pub.consume_data = dummy_consume_data;
  152123. coef->pub.decompress_data = decompress_onepass;
  152124. coef->pub.coef_arrays = NULL; /* flag for no virtual arrays */
  152125. }
  152126. }
  152127. /********* End of inlined file: jdcoefct.c *********/
  152128. #undef FIX
  152129. /********* Start of inlined file: jdcolor.c *********/
  152130. #define JPEG_INTERNALS
  152131. typedef struct {
  152132. struct jpeg_color_deconverter pub; /* public fields */
  152133. int * Cr_r_tab; /* => table for Cr to R conversion */
  152134. int * Cb_b_tab; /* => table for Cb to B conversion */
  152135. INT32 * Cr_g_tab; /* => table for Cr to G conversion */
  152136. INT32 * Cb_g_tab; /* => table for Cb to G conversion */
  152137. } my_color_deconverter2;
  152138. typedef my_color_deconverter2 * my_cconvert_ptr2;
  152139. #define SCALEBITS 16 /* speediest right-shift on some machines */
  152140. #define ONE_HALF ((INT32) 1 << (SCALEBITS-1))
  152141. #define FIX(x) ((INT32) ((x) * (1L<<SCALEBITS) + 0.5))
  152142. LOCAL(void)
  152143. build_ycc_rgb_table (j_decompress_ptr cinfo)
  152144. {
  152145. my_cconvert_ptr2 cconvert = (my_cconvert_ptr2) cinfo->cconvert;
  152146. int i;
  152147. INT32 x;
  152148. SHIFT_TEMPS
  152149. cconvert->Cr_r_tab = (int *)
  152150. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  152151. (MAXJSAMPLE+1) * SIZEOF(int));
  152152. cconvert->Cb_b_tab = (int *)
  152153. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  152154. (MAXJSAMPLE+1) * SIZEOF(int));
  152155. cconvert->Cr_g_tab = (INT32 *)
  152156. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  152157. (MAXJSAMPLE+1) * SIZEOF(INT32));
  152158. cconvert->Cb_g_tab = (INT32 *)
  152159. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  152160. (MAXJSAMPLE+1) * SIZEOF(INT32));
  152161. for (i = 0, x = -CENTERJSAMPLE; i <= MAXJSAMPLE; i++, x++) {
  152162. cconvert->Cr_r_tab[i] = (int)
  152163. RIGHT_SHIFT(FIX(1.40200) * x + ONE_HALF, SCALEBITS);
  152164. cconvert->Cb_b_tab[i] = (int)
  152165. RIGHT_SHIFT(FIX(1.77200) * x + ONE_HALF, SCALEBITS);
  152166. cconvert->Cr_g_tab[i] = (- FIX(0.71414)) * x;
  152167. cconvert->Cb_g_tab[i] = (- FIX(0.34414)) * x + ONE_HALF;
  152168. }
  152169. }
  152170. METHODDEF(void)
  152171. ycc_rgb_convert (j_decompress_ptr cinfo,
  152172. JSAMPIMAGE input_buf, JDIMENSION input_row,
  152173. JSAMPARRAY output_buf, int num_rows)
  152174. {
  152175. my_cconvert_ptr2 cconvert = (my_cconvert_ptr2) cinfo->cconvert;
  152176. register int y, cb, cr;
  152177. register JSAMPROW outptr;
  152178. register JSAMPROW inptr0, inptr1, inptr2;
  152179. register JDIMENSION col;
  152180. JDIMENSION num_cols = cinfo->output_width;
  152181. register JSAMPLE * range_limit = cinfo->sample_range_limit;
  152182. register int * Crrtab = cconvert->Cr_r_tab;
  152183. register int * Cbbtab = cconvert->Cb_b_tab;
  152184. register INT32 * Crgtab = cconvert->Cr_g_tab;
  152185. register INT32 * Cbgtab = cconvert->Cb_g_tab;
  152186. SHIFT_TEMPS
  152187. while (--num_rows >= 0) {
  152188. inptr0 = input_buf[0][input_row];
  152189. inptr1 = input_buf[1][input_row];
  152190. inptr2 = input_buf[2][input_row];
  152191. input_row++;
  152192. outptr = *output_buf++;
  152193. for (col = 0; col < num_cols; col++) {
  152194. y = GETJSAMPLE(inptr0[col]);
  152195. cb = GETJSAMPLE(inptr1[col]);
  152196. cr = GETJSAMPLE(inptr2[col]);
  152197. outptr[RGB_RED] = range_limit[y + Crrtab[cr]];
  152198. outptr[RGB_GREEN] = range_limit[y +
  152199. ((int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr],
  152200. SCALEBITS))];
  152201. outptr[RGB_BLUE] = range_limit[y + Cbbtab[cb]];
  152202. outptr += RGB_PIXELSIZE;
  152203. }
  152204. }
  152205. }
  152206. METHODDEF(void)
  152207. null_convert2 (j_decompress_ptr cinfo,
  152208. JSAMPIMAGE input_buf, JDIMENSION input_row,
  152209. JSAMPARRAY output_buf, int num_rows)
  152210. {
  152211. register JSAMPROW inptr, outptr;
  152212. register JDIMENSION count;
  152213. register int num_components = cinfo->num_components;
  152214. JDIMENSION num_cols = cinfo->output_width;
  152215. int ci;
  152216. while (--num_rows >= 0) {
  152217. for (ci = 0; ci < num_components; ci++) {
  152218. inptr = input_buf[ci][input_row];
  152219. outptr = output_buf[0] + ci;
  152220. for (count = num_cols; count > 0; count--) {
  152221. *outptr = *inptr++; /* needn't bother with GETJSAMPLE() here */
  152222. outptr += num_components;
  152223. }
  152224. }
  152225. input_row++;
  152226. output_buf++;
  152227. }
  152228. }
  152229. METHODDEF(void)
  152230. grayscale_convert2 (j_decompress_ptr cinfo,
  152231. JSAMPIMAGE input_buf, JDIMENSION input_row,
  152232. JSAMPARRAY output_buf, int num_rows)
  152233. {
  152234. jcopy_sample_rows(input_buf[0], (int) input_row, output_buf, 0,
  152235. num_rows, cinfo->output_width);
  152236. }
  152237. METHODDEF(void)
  152238. gray_rgb_convert (j_decompress_ptr cinfo,
  152239. JSAMPIMAGE input_buf, JDIMENSION input_row,
  152240. JSAMPARRAY output_buf, int num_rows)
  152241. {
  152242. register JSAMPROW inptr, outptr;
  152243. register JDIMENSION col;
  152244. JDIMENSION num_cols = cinfo->output_width;
  152245. while (--num_rows >= 0) {
  152246. inptr = input_buf[0][input_row++];
  152247. outptr = *output_buf++;
  152248. for (col = 0; col < num_cols; col++) {
  152249. outptr[RGB_RED] = outptr[RGB_GREEN] = outptr[RGB_BLUE] = inptr[col];
  152250. outptr += RGB_PIXELSIZE;
  152251. }
  152252. }
  152253. }
  152254. METHODDEF(void)
  152255. ycck_cmyk_convert (j_decompress_ptr cinfo,
  152256. JSAMPIMAGE input_buf, JDIMENSION input_row,
  152257. JSAMPARRAY output_buf, int num_rows)
  152258. {
  152259. my_cconvert_ptr2 cconvert = (my_cconvert_ptr2) cinfo->cconvert;
  152260. register int y, cb, cr;
  152261. register JSAMPROW outptr;
  152262. register JSAMPROW inptr0, inptr1, inptr2, inptr3;
  152263. register JDIMENSION col;
  152264. JDIMENSION num_cols = cinfo->output_width;
  152265. register JSAMPLE * range_limit = cinfo->sample_range_limit;
  152266. register int * Crrtab = cconvert->Cr_r_tab;
  152267. register int * Cbbtab = cconvert->Cb_b_tab;
  152268. register INT32 * Crgtab = cconvert->Cr_g_tab;
  152269. register INT32 * Cbgtab = cconvert->Cb_g_tab;
  152270. SHIFT_TEMPS
  152271. while (--num_rows >= 0) {
  152272. inptr0 = input_buf[0][input_row];
  152273. inptr1 = input_buf[1][input_row];
  152274. inptr2 = input_buf[2][input_row];
  152275. inptr3 = input_buf[3][input_row];
  152276. input_row++;
  152277. outptr = *output_buf++;
  152278. for (col = 0; col < num_cols; col++) {
  152279. y = GETJSAMPLE(inptr0[col]);
  152280. cb = GETJSAMPLE(inptr1[col]);
  152281. cr = GETJSAMPLE(inptr2[col]);
  152282. outptr[0] = range_limit[MAXJSAMPLE - (y + Crrtab[cr])]; /* red */
  152283. outptr[1] = range_limit[MAXJSAMPLE - (y + /* green */
  152284. ((int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr],
  152285. SCALEBITS)))];
  152286. outptr[2] = range_limit[MAXJSAMPLE - (y + Cbbtab[cb])]; /* blue */
  152287. outptr[3] = inptr3[col]; /* don't need GETJSAMPLE here */
  152288. outptr += 4;
  152289. }
  152290. }
  152291. }
  152292. METHODDEF(void)
  152293. start_pass_dcolor (j_decompress_ptr cinfo)
  152294. {
  152295. }
  152296. GLOBAL(void)
  152297. jinit_color_deconverter (j_decompress_ptr cinfo)
  152298. {
  152299. my_cconvert_ptr2 cconvert;
  152300. int ci;
  152301. cconvert = (my_cconvert_ptr2)
  152302. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  152303. SIZEOF(my_color_deconverter2));
  152304. cinfo->cconvert = (struct jpeg_color_deconverter *) cconvert;
  152305. cconvert->pub.start_pass = start_pass_dcolor;
  152306. switch (cinfo->jpeg_color_space) {
  152307. case JCS_GRAYSCALE:
  152308. if (cinfo->num_components != 1)
  152309. ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
  152310. break;
  152311. case JCS_RGB:
  152312. case JCS_YCbCr:
  152313. if (cinfo->num_components != 3)
  152314. ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
  152315. break;
  152316. case JCS_CMYK:
  152317. case JCS_YCCK:
  152318. if (cinfo->num_components != 4)
  152319. ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
  152320. break;
  152321. default: /* JCS_UNKNOWN can be anything */
  152322. if (cinfo->num_components < 1)
  152323. ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
  152324. break;
  152325. }
  152326. switch (cinfo->out_color_space) {
  152327. case JCS_GRAYSCALE:
  152328. cinfo->out_color_components = 1;
  152329. if (cinfo->jpeg_color_space == JCS_GRAYSCALE ||
  152330. cinfo->jpeg_color_space == JCS_YCbCr) {
  152331. cconvert->pub.color_convert = grayscale_convert2;
  152332. for (ci = 1; ci < cinfo->num_components; ci++)
  152333. cinfo->comp_info[ci].component_needed = FALSE;
  152334. } else
  152335. ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
  152336. break;
  152337. case JCS_RGB:
  152338. cinfo->out_color_components = RGB_PIXELSIZE;
  152339. if (cinfo->jpeg_color_space == JCS_YCbCr) {
  152340. cconvert->pub.color_convert = ycc_rgb_convert;
  152341. build_ycc_rgb_table(cinfo);
  152342. } else if (cinfo->jpeg_color_space == JCS_GRAYSCALE) {
  152343. cconvert->pub.color_convert = gray_rgb_convert;
  152344. } else if (cinfo->jpeg_color_space == JCS_RGB && RGB_PIXELSIZE == 3) {
  152345. cconvert->pub.color_convert = null_convert2;
  152346. } else
  152347. ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
  152348. break;
  152349. case JCS_CMYK:
  152350. cinfo->out_color_components = 4;
  152351. if (cinfo->jpeg_color_space == JCS_YCCK) {
  152352. cconvert->pub.color_convert = ycck_cmyk_convert;
  152353. build_ycc_rgb_table(cinfo);
  152354. } else if (cinfo->jpeg_color_space == JCS_CMYK) {
  152355. cconvert->pub.color_convert = null_convert2;
  152356. } else
  152357. ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
  152358. break;
  152359. default:
  152360. if (cinfo->out_color_space == cinfo->jpeg_color_space) {
  152361. cinfo->out_color_components = cinfo->num_components;
  152362. cconvert->pub.color_convert = null_convert2;
  152363. } else /* unsupported non-null conversion */
  152364. ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
  152365. break;
  152366. }
  152367. if (cinfo->quantize_colors)
  152368. cinfo->output_components = 1; /* single colormapped output component */
  152369. else
  152370. cinfo->output_components = cinfo->out_color_components;
  152371. }
  152372. /********* End of inlined file: jdcolor.c *********/
  152373. #undef FIX
  152374. /********* Start of inlined file: jddctmgr.c *********/
  152375. #define JPEG_INTERNALS
  152376. typedef struct {
  152377. struct jpeg_inverse_dct pub; /* public fields */
  152378. int cur_method[MAX_COMPONENTS];
  152379. } my_idct_controller;
  152380. typedef my_idct_controller * my_idct_ptr;
  152381. typedef union {
  152382. ISLOW_MULT_TYPE islow_array[DCTSIZE2];
  152383. #ifdef DCT_IFAST_SUPPORTED
  152384. IFAST_MULT_TYPE ifast_array[DCTSIZE2];
  152385. #endif
  152386. #ifdef DCT_FLOAT_SUPPORTED
  152387. FLOAT_MULT_TYPE float_array[DCTSIZE2];
  152388. #endif
  152389. } multiplier_table;
  152390. #ifdef DCT_ISLOW_SUPPORTED
  152391. #define PROVIDE_ISLOW_TABLES
  152392. #else
  152393. #ifdef IDCT_SCALING_SUPPORTED
  152394. #define PROVIDE_ISLOW_TABLES
  152395. #endif
  152396. #endif
  152397. METHODDEF(void)
  152398. start_pass (j_decompress_ptr cinfo)
  152399. {
  152400. my_idct_ptr idct = (my_idct_ptr) cinfo->idct;
  152401. int ci, i;
  152402. jpeg_component_info *compptr;
  152403. int method = 0;
  152404. inverse_DCT_method_ptr method_ptr = NULL;
  152405. JQUANT_TBL * qtbl;
  152406. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  152407. ci++, compptr++) {
  152408. switch (compptr->DCT_scaled_size) {
  152409. #ifdef IDCT_SCALING_SUPPORTED
  152410. case 1:
  152411. method_ptr = jpeg_idct_1x1;
  152412. method = JDCT_ISLOW; /* jidctred uses islow-style table */
  152413. break;
  152414. case 2:
  152415. method_ptr = jpeg_idct_2x2;
  152416. method = JDCT_ISLOW; /* jidctred uses islow-style table */
  152417. break;
  152418. case 4:
  152419. method_ptr = jpeg_idct_4x4;
  152420. method = JDCT_ISLOW; /* jidctred uses islow-style table */
  152421. break;
  152422. #endif
  152423. case DCTSIZE:
  152424. switch (cinfo->dct_method) {
  152425. #ifdef DCT_ISLOW_SUPPORTED
  152426. case JDCT_ISLOW:
  152427. method_ptr = jpeg_idct_islow;
  152428. method = JDCT_ISLOW;
  152429. break;
  152430. #endif
  152431. #ifdef DCT_IFAST_SUPPORTED
  152432. case JDCT_IFAST:
  152433. method_ptr = jpeg_idct_ifast;
  152434. method = JDCT_IFAST;
  152435. break;
  152436. #endif
  152437. #ifdef DCT_FLOAT_SUPPORTED
  152438. case JDCT_FLOAT:
  152439. method_ptr = jpeg_idct_float;
  152440. method = JDCT_FLOAT;
  152441. break;
  152442. #endif
  152443. default:
  152444. ERREXIT(cinfo, JERR_NOT_COMPILED);
  152445. break;
  152446. }
  152447. break;
  152448. default:
  152449. ERREXIT1(cinfo, JERR_BAD_DCTSIZE, compptr->DCT_scaled_size);
  152450. break;
  152451. }
  152452. idct->pub.inverse_DCT[ci] = method_ptr;
  152453. if (! compptr->component_needed || idct->cur_method[ci] == method)
  152454. continue;
  152455. qtbl = compptr->quant_table;
  152456. if (qtbl == NULL) /* happens if no data yet for component */
  152457. continue;
  152458. idct->cur_method[ci] = method;
  152459. switch (method) {
  152460. #ifdef PROVIDE_ISLOW_TABLES
  152461. case JDCT_ISLOW:
  152462. {
  152463. ISLOW_MULT_TYPE * ismtbl = (ISLOW_MULT_TYPE *) compptr->dct_table;
  152464. for (i = 0; i < DCTSIZE2; i++) {
  152465. ismtbl[i] = (ISLOW_MULT_TYPE) qtbl->quantval[i];
  152466. }
  152467. }
  152468. break;
  152469. #endif
  152470. #ifdef DCT_IFAST_SUPPORTED
  152471. case JDCT_IFAST:
  152472. {
  152473. IFAST_MULT_TYPE * ifmtbl = (IFAST_MULT_TYPE *) compptr->dct_table;
  152474. #define CONST_BITS 14
  152475. static const INT16 aanscales[DCTSIZE2] = {
  152476. 16384, 22725, 21407, 19266, 16384, 12873, 8867, 4520,
  152477. 22725, 31521, 29692, 26722, 22725, 17855, 12299, 6270,
  152478. 21407, 29692, 27969, 25172, 21407, 16819, 11585, 5906,
  152479. 19266, 26722, 25172, 22654, 19266, 15137, 10426, 5315,
  152480. 16384, 22725, 21407, 19266, 16384, 12873, 8867, 4520,
  152481. 12873, 17855, 16819, 15137, 12873, 10114, 6967, 3552,
  152482. 8867, 12299, 11585, 10426, 8867, 6967, 4799, 2446,
  152483. 4520, 6270, 5906, 5315, 4520, 3552, 2446, 1247
  152484. };
  152485. SHIFT_TEMPS
  152486. for (i = 0; i < DCTSIZE2; i++) {
  152487. ifmtbl[i] = (IFAST_MULT_TYPE)
  152488. DESCALE(MULTIPLY16V16((INT32) qtbl->quantval[i],
  152489. (INT32) aanscales[i]),
  152490. CONST_BITS-IFAST_SCALE_BITS);
  152491. }
  152492. }
  152493. break;
  152494. #endif
  152495. #ifdef DCT_FLOAT_SUPPORTED
  152496. case JDCT_FLOAT:
  152497. {
  152498. FLOAT_MULT_TYPE * fmtbl = (FLOAT_MULT_TYPE *) compptr->dct_table;
  152499. int row, col;
  152500. static const double aanscalefactor[DCTSIZE] = {
  152501. 1.0, 1.387039845, 1.306562965, 1.175875602,
  152502. 1.0, 0.785694958, 0.541196100, 0.275899379
  152503. };
  152504. i = 0;
  152505. for (row = 0; row < DCTSIZE; row++) {
  152506. for (col = 0; col < DCTSIZE; col++) {
  152507. fmtbl[i] = (FLOAT_MULT_TYPE)
  152508. ((double) qtbl->quantval[i] *
  152509. aanscalefactor[row] * aanscalefactor[col]);
  152510. i++;
  152511. }
  152512. }
  152513. }
  152514. break;
  152515. #endif
  152516. default:
  152517. ERREXIT(cinfo, JERR_NOT_COMPILED);
  152518. break;
  152519. }
  152520. }
  152521. }
  152522. GLOBAL(void)
  152523. jinit_inverse_dct (j_decompress_ptr cinfo)
  152524. {
  152525. my_idct_ptr idct;
  152526. int ci;
  152527. jpeg_component_info *compptr;
  152528. idct = (my_idct_ptr)
  152529. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  152530. SIZEOF(my_idct_controller));
  152531. cinfo->idct = (struct jpeg_inverse_dct *) idct;
  152532. idct->pub.start_pass = start_pass;
  152533. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  152534. ci++, compptr++) {
  152535. compptr->dct_table =
  152536. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  152537. SIZEOF(multiplier_table));
  152538. MEMZERO(compptr->dct_table, SIZEOF(multiplier_table));
  152539. idct->cur_method[ci] = -1;
  152540. }
  152541. }
  152542. /********* End of inlined file: jddctmgr.c *********/
  152543. #undef CONST_BITS
  152544. #undef ASSIGN_STATE
  152545. /********* Start of inlined file: jdhuff.c *********/
  152546. #define JPEG_INTERNALS
  152547. /********* Start of inlined file: jdhuff.h *********/
  152548. #ifndef __jdhuff_h__
  152549. #define __jdhuff_h__
  152550. #ifdef NEED_SHORT_EXTERNAL_NAMES
  152551. #define jpeg_make_d_derived_tbl jMkDDerived
  152552. #define jpeg_fill_bit_buffer jFilBitBuf
  152553. #define jpeg_huff_decode jHufDecode
  152554. #endif /* NEED_SHORT_EXTERNAL_NAMES */
  152555. #define HUFF_LOOKAHEAD 8 /* # of bits of lookahead */
  152556. typedef struct {
  152557. INT32 maxcode[18]; /* largest code of length k (-1 if none) */
  152558. INT32 valoffset[17]; /* huffval[] offset for codes of length k */
  152559. JHUFF_TBL *pub;
  152560. int look_nbits[1<<HUFF_LOOKAHEAD]; /* # bits, or 0 if too long */
  152561. UINT8 look_sym[1<<HUFF_LOOKAHEAD]; /* symbol, or unused */
  152562. } d_derived_tbl;
  152563. EXTERN(void) jpeg_make_d_derived_tbl
  152564. JPP((j_decompress_ptr cinfo, boolean isDC, int tblno,
  152565. d_derived_tbl ** pdtbl));
  152566. typedef INT32 bit_buf_type; /* type of bit-extraction buffer */
  152567. #define BIT_BUF_SIZE 32 /* size of buffer in bits */
  152568. typedef struct { /* Bitreading state saved across MCUs */
  152569. bit_buf_type get_buffer; /* current bit-extraction buffer */
  152570. int bits_left; /* # of unused bits in it */
  152571. } bitread_perm_state;
  152572. typedef struct { /* Bitreading working state within an MCU */
  152573. const JOCTET * next_input_byte; /* => next byte to read from source */
  152574. size_t bytes_in_buffer; /* # of bytes remaining in source buffer */
  152575. bit_buf_type get_buffer; /* current bit-extraction buffer */
  152576. int bits_left; /* # of unused bits in it */
  152577. j_decompress_ptr cinfo; /* back link to decompress master record */
  152578. } bitread_working_state;
  152579. #define BITREAD_STATE_VARS \
  152580. register bit_buf_type get_buffer; \
  152581. register int bits_left; \
  152582. bitread_working_state br_state
  152583. #define BITREAD_LOAD_STATE(cinfop,permstate) \
  152584. br_state.cinfo = cinfop; \
  152585. br_state.next_input_byte = cinfop->src->next_input_byte; \
  152586. br_state.bytes_in_buffer = cinfop->src->bytes_in_buffer; \
  152587. get_buffer = permstate.get_buffer; \
  152588. bits_left = permstate.bits_left;
  152589. #define BITREAD_SAVE_STATE(cinfop,permstate) \
  152590. cinfop->src->next_input_byte = br_state.next_input_byte; \
  152591. cinfop->src->bytes_in_buffer = br_state.bytes_in_buffer; \
  152592. permstate.get_buffer = get_buffer; \
  152593. permstate.bits_left = bits_left
  152594. #define CHECK_BIT_BUFFER(state,nbits,action) \
  152595. { if (bits_left < (nbits)) { \
  152596. if (! jpeg_fill_bit_buffer(&(state),get_buffer,bits_left,nbits)) \
  152597. { action; } \
  152598. get_buffer = (state).get_buffer; bits_left = (state).bits_left; } }
  152599. #define GET_BITS(nbits) \
  152600. (((int) (get_buffer >> (bits_left -= (nbits)))) & ((1<<(nbits))-1))
  152601. #define PEEK_BITS(nbits) \
  152602. (((int) (get_buffer >> (bits_left - (nbits)))) & ((1<<(nbits))-1))
  152603. #define DROP_BITS(nbits) \
  152604. (bits_left -= (nbits))
  152605. EXTERN(boolean) jpeg_fill_bit_buffer
  152606. JPP((bitread_working_state * state, register bit_buf_type get_buffer,
  152607. register int bits_left, int nbits));
  152608. #define HUFF_DECODE(result,state,htbl,failaction,slowlabel) \
  152609. { register int nb, look; \
  152610. if (bits_left < HUFF_LOOKAHEAD) { \
  152611. if (! jpeg_fill_bit_buffer(&state,get_buffer,bits_left, 0)) {failaction;} \
  152612. get_buffer = state.get_buffer; bits_left = state.bits_left; \
  152613. if (bits_left < HUFF_LOOKAHEAD) { \
  152614. nb = 1; goto slowlabel; \
  152615. } \
  152616. } \
  152617. look = PEEK_BITS(HUFF_LOOKAHEAD); \
  152618. if ((nb = htbl->look_nbits[look]) != 0) { \
  152619. DROP_BITS(nb); \
  152620. result = htbl->look_sym[look]; \
  152621. } else { \
  152622. nb = HUFF_LOOKAHEAD+1; \
  152623. slowlabel: \
  152624. if ((result=jpeg_huff_decode(&state,get_buffer,bits_left,htbl,nb)) < 0) \
  152625. { failaction; } \
  152626. get_buffer = state.get_buffer; bits_left = state.bits_left; \
  152627. } \
  152628. }
  152629. EXTERN(int) jpeg_huff_decode
  152630. JPP((bitread_working_state * state, register bit_buf_type get_buffer,
  152631. register int bits_left, d_derived_tbl * htbl, int min_bits));
  152632. #endif
  152633. /********* End of inlined file: jdhuff.h *********/
  152634. typedef struct {
  152635. int last_dc_val[MAX_COMPS_IN_SCAN]; /* last DC coef for each component */
  152636. } savable_state2;
  152637. #ifndef NO_STRUCT_ASSIGN
  152638. #define ASSIGN_STATE(dest,src) ((dest) = (src))
  152639. #else
  152640. #if MAX_COMPS_IN_SCAN == 4
  152641. #define ASSIGN_STATE(dest,src) \
  152642. ((dest).last_dc_val[0] = (src).last_dc_val[0], \
  152643. (dest).last_dc_val[1] = (src).last_dc_val[1], \
  152644. (dest).last_dc_val[2] = (src).last_dc_val[2], \
  152645. (dest).last_dc_val[3] = (src).last_dc_val[3])
  152646. #endif
  152647. #endif
  152648. typedef struct {
  152649. struct jpeg_entropy_decoder pub; /* public fields */
  152650. bitread_perm_state bitstate; /* Bit buffer at start of MCU */
  152651. savable_state2 saved; /* Other state at start of MCU */
  152652. unsigned int restarts_to_go; /* MCUs left in this restart interval */
  152653. d_derived_tbl * dc_derived_tbls[NUM_HUFF_TBLS];
  152654. d_derived_tbl * ac_derived_tbls[NUM_HUFF_TBLS];
  152655. d_derived_tbl * dc_cur_tbls[D_MAX_BLOCKS_IN_MCU];
  152656. d_derived_tbl * ac_cur_tbls[D_MAX_BLOCKS_IN_MCU];
  152657. boolean dc_needed[D_MAX_BLOCKS_IN_MCU];
  152658. boolean ac_needed[D_MAX_BLOCKS_IN_MCU];
  152659. } huff_entropy_decoder2;
  152660. typedef huff_entropy_decoder2 * huff_entropy_ptr2;
  152661. METHODDEF(void)
  152662. start_pass_huff_decoder (j_decompress_ptr cinfo)
  152663. {
  152664. huff_entropy_ptr2 entropy = (huff_entropy_ptr2) cinfo->entropy;
  152665. int ci, blkn, dctbl, actbl;
  152666. jpeg_component_info * compptr;
  152667. if (cinfo->Ss != 0 || cinfo->Se != DCTSIZE2-1 ||
  152668. cinfo->Ah != 0 || cinfo->Al != 0)
  152669. WARNMS(cinfo, JWRN_NOT_SEQUENTIAL);
  152670. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  152671. compptr = cinfo->cur_comp_info[ci];
  152672. dctbl = compptr->dc_tbl_no;
  152673. actbl = compptr->ac_tbl_no;
  152674. jpeg_make_d_derived_tbl(cinfo, TRUE, dctbl,
  152675. & entropy->dc_derived_tbls[dctbl]);
  152676. jpeg_make_d_derived_tbl(cinfo, FALSE, actbl,
  152677. & entropy->ac_derived_tbls[actbl]);
  152678. entropy->saved.last_dc_val[ci] = 0;
  152679. }
  152680. for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
  152681. ci = cinfo->MCU_membership[blkn];
  152682. compptr = cinfo->cur_comp_info[ci];
  152683. entropy->dc_cur_tbls[blkn] = entropy->dc_derived_tbls[compptr->dc_tbl_no];
  152684. entropy->ac_cur_tbls[blkn] = entropy->ac_derived_tbls[compptr->ac_tbl_no];
  152685. if (compptr->component_needed) {
  152686. entropy->dc_needed[blkn] = TRUE;
  152687. entropy->ac_needed[blkn] = (compptr->DCT_scaled_size > 1);
  152688. } else {
  152689. entropy->dc_needed[blkn] = entropy->ac_needed[blkn] = FALSE;
  152690. }
  152691. }
  152692. entropy->bitstate.bits_left = 0;
  152693. entropy->bitstate.get_buffer = 0; /* unnecessary, but keeps Purify quiet */
  152694. entropy->pub.insufficient_data = FALSE;
  152695. entropy->restarts_to_go = cinfo->restart_interval;
  152696. }
  152697. GLOBAL(void)
  152698. jpeg_make_d_derived_tbl (j_decompress_ptr cinfo, boolean isDC, int tblno,
  152699. d_derived_tbl ** pdtbl)
  152700. {
  152701. JHUFF_TBL *htbl;
  152702. d_derived_tbl *dtbl;
  152703. int p, i, l, si, numsymbols;
  152704. int lookbits, ctr;
  152705. char huffsize[257];
  152706. unsigned int huffcode[257];
  152707. unsigned int code;
  152708. if (tblno < 0 || tblno >= NUM_HUFF_TBLS)
  152709. ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, tblno);
  152710. htbl =
  152711. isDC ? cinfo->dc_huff_tbl_ptrs[tblno] : cinfo->ac_huff_tbl_ptrs[tblno];
  152712. if (htbl == NULL)
  152713. ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, tblno);
  152714. if (*pdtbl == NULL)
  152715. *pdtbl = (d_derived_tbl *)
  152716. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  152717. SIZEOF(d_derived_tbl));
  152718. dtbl = *pdtbl;
  152719. dtbl->pub = htbl; /* fill in back link */
  152720. p = 0;
  152721. for (l = 1; l <= 16; l++) {
  152722. i = (int) htbl->bits[l];
  152723. if (i < 0 || p + i > 256) /* protect against table overrun */
  152724. ERREXIT(cinfo, JERR_BAD_HUFF_TABLE);
  152725. while (i--)
  152726. huffsize[p++] = (char) l;
  152727. }
  152728. huffsize[p] = 0;
  152729. numsymbols = p;
  152730. code = 0;
  152731. si = huffsize[0];
  152732. p = 0;
  152733. while (huffsize[p]) {
  152734. while (((int) huffsize[p]) == si) {
  152735. huffcode[p++] = code;
  152736. code++;
  152737. }
  152738. if (((INT32) code) >= (((INT32) 1) << si))
  152739. ERREXIT(cinfo, JERR_BAD_HUFF_TABLE);
  152740. code <<= 1;
  152741. si++;
  152742. }
  152743. p = 0;
  152744. for (l = 1; l <= 16; l++) {
  152745. if (htbl->bits[l]) {
  152746. dtbl->valoffset[l] = (INT32) p - (INT32) huffcode[p];
  152747. p += htbl->bits[l];
  152748. dtbl->maxcode[l] = huffcode[p-1]; /* maximum code of length l */
  152749. } else {
  152750. dtbl->maxcode[l] = -1; /* -1 if no codes of this length */
  152751. }
  152752. }
  152753. dtbl->maxcode[17] = 0xFFFFFL; /* ensures jpeg_huff_decode terminates */
  152754. MEMZERO(dtbl->look_nbits, SIZEOF(dtbl->look_nbits));
  152755. p = 0;
  152756. for (l = 1; l <= HUFF_LOOKAHEAD; l++) {
  152757. for (i = 1; i <= (int) htbl->bits[l]; i++, p++) {
  152758. lookbits = huffcode[p] << (HUFF_LOOKAHEAD-l);
  152759. for (ctr = 1 << (HUFF_LOOKAHEAD-l); ctr > 0; ctr--) {
  152760. dtbl->look_nbits[lookbits] = l;
  152761. dtbl->look_sym[lookbits] = htbl->huffval[p];
  152762. lookbits++;
  152763. }
  152764. }
  152765. }
  152766. if (isDC) {
  152767. for (i = 0; i < numsymbols; i++) {
  152768. int sym = htbl->huffval[i];
  152769. if (sym < 0 || sym > 15)
  152770. ERREXIT(cinfo, JERR_BAD_HUFF_TABLE);
  152771. }
  152772. }
  152773. }
  152774. #ifdef SLOW_SHIFT_32
  152775. #define MIN_GET_BITS 15 /* minimum allowable value */
  152776. #else
  152777. #define MIN_GET_BITS (BIT_BUF_SIZE-7)
  152778. #endif
  152779. GLOBAL(boolean)
  152780. jpeg_fill_bit_buffer (bitread_working_state * state,
  152781. register bit_buf_type get_buffer, register int bits_left,
  152782. int nbits)
  152783. {
  152784. register const JOCTET * next_input_byte = state->next_input_byte;
  152785. register size_t bytes_in_buffer = state->bytes_in_buffer;
  152786. j_decompress_ptr cinfo = state->cinfo;
  152787. if (cinfo->unread_marker == 0) { /* cannot advance past a marker */
  152788. while (bits_left < MIN_GET_BITS) {
  152789. register int c;
  152790. if (bytes_in_buffer == 0) {
  152791. if (! (*cinfo->src->fill_input_buffer) (cinfo))
  152792. return FALSE;
  152793. next_input_byte = cinfo->src->next_input_byte;
  152794. bytes_in_buffer = cinfo->src->bytes_in_buffer;
  152795. }
  152796. bytes_in_buffer--;
  152797. c = GETJOCTET(*next_input_byte++);
  152798. if (c == 0xFF) {
  152799. do {
  152800. if (bytes_in_buffer == 0) {
  152801. if (! (*cinfo->src->fill_input_buffer) (cinfo))
  152802. return FALSE;
  152803. next_input_byte = cinfo->src->next_input_byte;
  152804. bytes_in_buffer = cinfo->src->bytes_in_buffer;
  152805. }
  152806. bytes_in_buffer--;
  152807. c = GETJOCTET(*next_input_byte++);
  152808. } while (c == 0xFF);
  152809. if (c == 0) {
  152810. c = 0xFF;
  152811. } else {
  152812. cinfo->unread_marker = c;
  152813. goto no_more_bytes;
  152814. }
  152815. }
  152816. get_buffer = (get_buffer << 8) | c;
  152817. bits_left += 8;
  152818. } /* end while */
  152819. } else {
  152820. no_more_bytes:
  152821. if (nbits > bits_left) {
  152822. if (! cinfo->entropy->insufficient_data) {
  152823. WARNMS(cinfo, JWRN_HIT_MARKER);
  152824. cinfo->entropy->insufficient_data = TRUE;
  152825. }
  152826. get_buffer <<= MIN_GET_BITS - bits_left;
  152827. bits_left = MIN_GET_BITS;
  152828. }
  152829. }
  152830. state->next_input_byte = next_input_byte;
  152831. state->bytes_in_buffer = bytes_in_buffer;
  152832. state->get_buffer = get_buffer;
  152833. state->bits_left = bits_left;
  152834. return TRUE;
  152835. }
  152836. GLOBAL(int)
  152837. jpeg_huff_decode (bitread_working_state * state,
  152838. register bit_buf_type get_buffer, register int bits_left,
  152839. d_derived_tbl * htbl, int min_bits)
  152840. {
  152841. register int l = min_bits;
  152842. register INT32 code;
  152843. CHECK_BIT_BUFFER(*state, l, return -1);
  152844. code = GET_BITS(l);
  152845. while (code > htbl->maxcode[l]) {
  152846. code <<= 1;
  152847. CHECK_BIT_BUFFER(*state, 1, return -1);
  152848. code |= GET_BITS(1);
  152849. l++;
  152850. }
  152851. state->get_buffer = get_buffer;
  152852. state->bits_left = bits_left;
  152853. if (l > 16) {
  152854. WARNMS(state->cinfo, JWRN_HUFF_BAD_CODE);
  152855. return 0; /* fake a zero as the safest result */
  152856. }
  152857. return htbl->pub->huffval[ (int) (code + htbl->valoffset[l]) ];
  152858. }
  152859. LOCAL(boolean)
  152860. process_restart (j_decompress_ptr cinfo)
  152861. {
  152862. huff_entropy_ptr2 entropy = (huff_entropy_ptr2) cinfo->entropy;
  152863. int ci;
  152864. cinfo->marker->discarded_bytes += entropy->bitstate.bits_left / 8;
  152865. entropy->bitstate.bits_left = 0;
  152866. if (! (*cinfo->marker->read_restart_marker) (cinfo))
  152867. return FALSE;
  152868. for (ci = 0; ci < cinfo->comps_in_scan; ci++)
  152869. entropy->saved.last_dc_val[ci] = 0;
  152870. entropy->restarts_to_go = cinfo->restart_interval;
  152871. if (cinfo->unread_marker == 0)
  152872. entropy->pub.insufficient_data = FALSE;
  152873. return TRUE;
  152874. }
  152875. METHODDEF(boolean)
  152876. decode_mcu (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
  152877. {
  152878. huff_entropy_ptr2 entropy = (huff_entropy_ptr2) cinfo->entropy;
  152879. int blkn;
  152880. BITREAD_STATE_VARS;
  152881. savable_state2 state;
  152882. if (cinfo->restart_interval) {
  152883. if (entropy->restarts_to_go == 0)
  152884. if (! process_restart(cinfo))
  152885. return FALSE;
  152886. }
  152887. if (! entropy->pub.insufficient_data) {
  152888. BITREAD_LOAD_STATE(cinfo,entropy->bitstate);
  152889. ASSIGN_STATE(state, entropy->saved);
  152890. for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
  152891. JBLOCKROW block = MCU_data[blkn];
  152892. d_derived_tbl * dctbl = entropy->dc_cur_tbls[blkn];
  152893. d_derived_tbl * actbl = entropy->ac_cur_tbls[blkn];
  152894. register int s, k, r;
  152895. HUFF_DECODE(s, br_state, dctbl, return FALSE, label1);
  152896. if (s) {
  152897. CHECK_BIT_BUFFER(br_state, s, return FALSE);
  152898. r = GET_BITS(s);
  152899. s = HUFF_EXTEND(r, s);
  152900. }
  152901. if (entropy->dc_needed[blkn]) {
  152902. int ci = cinfo->MCU_membership[blkn];
  152903. s += state.last_dc_val[ci];
  152904. state.last_dc_val[ci] = s;
  152905. (*block)[0] = (JCOEF) s;
  152906. }
  152907. if (entropy->ac_needed[blkn]) {
  152908. for (k = 1; k < DCTSIZE2; k++) {
  152909. HUFF_DECODE(s, br_state, actbl, return FALSE, label2);
  152910. r = s >> 4;
  152911. s &= 15;
  152912. if (s) {
  152913. k += r;
  152914. CHECK_BIT_BUFFER(br_state, s, return FALSE);
  152915. r = GET_BITS(s);
  152916. s = HUFF_EXTEND(r, s);
  152917. (*block)[jpeg_natural_order[k]] = (JCOEF) s;
  152918. } else {
  152919. if (r != 15)
  152920. break;
  152921. k += 15;
  152922. }
  152923. }
  152924. } else {
  152925. for (k = 1; k < DCTSIZE2; k++) {
  152926. HUFF_DECODE(s, br_state, actbl, return FALSE, label3);
  152927. r = s >> 4;
  152928. s &= 15;
  152929. if (s) {
  152930. k += r;
  152931. CHECK_BIT_BUFFER(br_state, s, return FALSE);
  152932. DROP_BITS(s);
  152933. } else {
  152934. if (r != 15)
  152935. break;
  152936. k += 15;
  152937. }
  152938. }
  152939. }
  152940. }
  152941. BITREAD_SAVE_STATE(cinfo,entropy->bitstate);
  152942. ASSIGN_STATE(entropy->saved, state);
  152943. }
  152944. entropy->restarts_to_go--;
  152945. return TRUE;
  152946. }
  152947. GLOBAL(void)
  152948. jinit_huff_decoder (j_decompress_ptr cinfo)
  152949. {
  152950. huff_entropy_ptr2 entropy;
  152951. int i;
  152952. entropy = (huff_entropy_ptr2)
  152953. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  152954. SIZEOF(huff_entropy_decoder2));
  152955. cinfo->entropy = (struct jpeg_entropy_decoder *) entropy;
  152956. entropy->pub.start_pass = start_pass_huff_decoder;
  152957. entropy->pub.decode_mcu = decode_mcu;
  152958. for (i = 0; i < NUM_HUFF_TBLS; i++) {
  152959. entropy->dc_derived_tbls[i] = entropy->ac_derived_tbls[i] = NULL;
  152960. }
  152961. }
  152962. /********* End of inlined file: jdhuff.c *********/
  152963. /********* Start of inlined file: jdinput.c *********/
  152964. #define JPEG_INTERNALS
  152965. typedef struct {
  152966. struct jpeg_input_controller pub; /* public fields */
  152967. boolean inheaders; /* TRUE until first SOS is reached */
  152968. } my_input_controller;
  152969. typedef my_input_controller * my_inputctl_ptr;
  152970. METHODDEF(int) consume_markers JPP((j_decompress_ptr cinfo));
  152971. LOCAL(void)
  152972. initial_setup2 (j_decompress_ptr cinfo)
  152973. {
  152974. int ci;
  152975. jpeg_component_info *compptr;
  152976. if ((long) cinfo->image_height > (long) JPEG_MAX_DIMENSION ||
  152977. (long) cinfo->image_width > (long) JPEG_MAX_DIMENSION)
  152978. ERREXIT1(cinfo, JERR_IMAGE_TOO_BIG, (unsigned int) JPEG_MAX_DIMENSION);
  152979. if (cinfo->data_precision != BITS_IN_JSAMPLE)
  152980. ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
  152981. if (cinfo->num_components > MAX_COMPONENTS)
  152982. ERREXIT2(cinfo, JERR_COMPONENT_COUNT, cinfo->num_components,
  152983. MAX_COMPONENTS);
  152984. cinfo->max_h_samp_factor = 1;
  152985. cinfo->max_v_samp_factor = 1;
  152986. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  152987. ci++, compptr++) {
  152988. if (compptr->h_samp_factor<=0 || compptr->h_samp_factor>MAX_SAMP_FACTOR ||
  152989. compptr->v_samp_factor<=0 || compptr->v_samp_factor>MAX_SAMP_FACTOR)
  152990. ERREXIT(cinfo, JERR_BAD_SAMPLING);
  152991. cinfo->max_h_samp_factor = MAX(cinfo->max_h_samp_factor,
  152992. compptr->h_samp_factor);
  152993. cinfo->max_v_samp_factor = MAX(cinfo->max_v_samp_factor,
  152994. compptr->v_samp_factor);
  152995. }
  152996. cinfo->min_DCT_scaled_size = DCTSIZE;
  152997. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  152998. ci++, compptr++) {
  152999. compptr->DCT_scaled_size = DCTSIZE;
  153000. compptr->width_in_blocks = (JDIMENSION)
  153001. jdiv_round_up((long) cinfo->image_width * (long) compptr->h_samp_factor,
  153002. (long) (cinfo->max_h_samp_factor * DCTSIZE));
  153003. compptr->height_in_blocks = (JDIMENSION)
  153004. jdiv_round_up((long) cinfo->image_height * (long) compptr->v_samp_factor,
  153005. (long) (cinfo->max_v_samp_factor * DCTSIZE));
  153006. compptr->downsampled_width = (JDIMENSION)
  153007. jdiv_round_up((long) cinfo->image_width * (long) compptr->h_samp_factor,
  153008. (long) cinfo->max_h_samp_factor);
  153009. compptr->downsampled_height = (JDIMENSION)
  153010. jdiv_round_up((long) cinfo->image_height * (long) compptr->v_samp_factor,
  153011. (long) cinfo->max_v_samp_factor);
  153012. compptr->component_needed = TRUE;
  153013. compptr->quant_table = NULL;
  153014. }
  153015. cinfo->total_iMCU_rows = (JDIMENSION)
  153016. jdiv_round_up((long) cinfo->image_height,
  153017. (long) (cinfo->max_v_samp_factor*DCTSIZE));
  153018. if (cinfo->comps_in_scan < cinfo->num_components || cinfo->progressive_mode)
  153019. cinfo->inputctl->has_multiple_scans = TRUE;
  153020. else
  153021. cinfo->inputctl->has_multiple_scans = FALSE;
  153022. }
  153023. LOCAL(void)
  153024. per_scan_setup2 (j_decompress_ptr cinfo)
  153025. {
  153026. int ci, mcublks, tmp;
  153027. jpeg_component_info *compptr;
  153028. if (cinfo->comps_in_scan == 1) {
  153029. compptr = cinfo->cur_comp_info[0];
  153030. cinfo->MCUs_per_row = compptr->width_in_blocks;
  153031. cinfo->MCU_rows_in_scan = compptr->height_in_blocks;
  153032. compptr->MCU_width = 1;
  153033. compptr->MCU_height = 1;
  153034. compptr->MCU_blocks = 1;
  153035. compptr->MCU_sample_width = compptr->DCT_scaled_size;
  153036. compptr->last_col_width = 1;
  153037. tmp = (int) (compptr->height_in_blocks % compptr->v_samp_factor);
  153038. if (tmp == 0) tmp = compptr->v_samp_factor;
  153039. compptr->last_row_height = tmp;
  153040. cinfo->blocks_in_MCU = 1;
  153041. cinfo->MCU_membership[0] = 0;
  153042. } else {
  153043. if (cinfo->comps_in_scan <= 0 || cinfo->comps_in_scan > MAX_COMPS_IN_SCAN)
  153044. ERREXIT2(cinfo, JERR_COMPONENT_COUNT, cinfo->comps_in_scan,
  153045. MAX_COMPS_IN_SCAN);
  153046. cinfo->MCUs_per_row = (JDIMENSION)
  153047. jdiv_round_up((long) cinfo->image_width,
  153048. (long) (cinfo->max_h_samp_factor*DCTSIZE));
  153049. cinfo->MCU_rows_in_scan = (JDIMENSION)
  153050. jdiv_round_up((long) cinfo->image_height,
  153051. (long) (cinfo->max_v_samp_factor*DCTSIZE));
  153052. cinfo->blocks_in_MCU = 0;
  153053. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  153054. compptr = cinfo->cur_comp_info[ci];
  153055. compptr->MCU_width = compptr->h_samp_factor;
  153056. compptr->MCU_height = compptr->v_samp_factor;
  153057. compptr->MCU_blocks = compptr->MCU_width * compptr->MCU_height;
  153058. compptr->MCU_sample_width = compptr->MCU_width * compptr->DCT_scaled_size;
  153059. tmp = (int) (compptr->width_in_blocks % compptr->MCU_width);
  153060. if (tmp == 0) tmp = compptr->MCU_width;
  153061. compptr->last_col_width = tmp;
  153062. tmp = (int) (compptr->height_in_blocks % compptr->MCU_height);
  153063. if (tmp == 0) tmp = compptr->MCU_height;
  153064. compptr->last_row_height = tmp;
  153065. mcublks = compptr->MCU_blocks;
  153066. if (cinfo->blocks_in_MCU + mcublks > D_MAX_BLOCKS_IN_MCU)
  153067. ERREXIT(cinfo, JERR_BAD_MCU_SIZE);
  153068. while (mcublks-- > 0) {
  153069. cinfo->MCU_membership[cinfo->blocks_in_MCU++] = ci;
  153070. }
  153071. }
  153072. }
  153073. }
  153074. LOCAL(void)
  153075. latch_quant_tables (j_decompress_ptr cinfo)
  153076. {
  153077. int ci, qtblno;
  153078. jpeg_component_info *compptr;
  153079. JQUANT_TBL * qtbl;
  153080. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  153081. compptr = cinfo->cur_comp_info[ci];
  153082. if (compptr->quant_table != NULL)
  153083. continue;
  153084. qtblno = compptr->quant_tbl_no;
  153085. if (qtblno < 0 || qtblno >= NUM_QUANT_TBLS ||
  153086. cinfo->quant_tbl_ptrs[qtblno] == NULL)
  153087. ERREXIT1(cinfo, JERR_NO_QUANT_TABLE, qtblno);
  153088. qtbl = (JQUANT_TBL *)
  153089. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  153090. SIZEOF(JQUANT_TBL));
  153091. MEMCOPY(qtbl, cinfo->quant_tbl_ptrs[qtblno], SIZEOF(JQUANT_TBL));
  153092. compptr->quant_table = qtbl;
  153093. }
  153094. }
  153095. METHODDEF(void)
  153096. start_input_pass2 (j_decompress_ptr cinfo)
  153097. {
  153098. per_scan_setup2(cinfo);
  153099. latch_quant_tables(cinfo);
  153100. (*cinfo->entropy->start_pass) (cinfo);
  153101. (*cinfo->coef->start_input_pass) (cinfo);
  153102. cinfo->inputctl->consume_input = cinfo->coef->consume_data;
  153103. }
  153104. METHODDEF(void)
  153105. finish_input_pass (j_decompress_ptr cinfo)
  153106. {
  153107. cinfo->inputctl->consume_input = consume_markers;
  153108. }
  153109. METHODDEF(int)
  153110. consume_markers (j_decompress_ptr cinfo)
  153111. {
  153112. my_inputctl_ptr inputctl = (my_inputctl_ptr) cinfo->inputctl;
  153113. int val;
  153114. if (inputctl->pub.eoi_reached) /* After hitting EOI, read no further */
  153115. return JPEG_REACHED_EOI;
  153116. val = (*cinfo->marker->read_markers) (cinfo);
  153117. switch (val) {
  153118. case JPEG_REACHED_SOS: /* Found SOS */
  153119. if (inputctl->inheaders) { /* 1st SOS */
  153120. initial_setup2(cinfo);
  153121. inputctl->inheaders = FALSE;
  153122. } else { /* 2nd or later SOS marker */
  153123. if (! inputctl->pub.has_multiple_scans)
  153124. ERREXIT(cinfo, JERR_EOI_EXPECTED); /* Oops, I wasn't expecting this! */
  153125. start_input_pass2(cinfo);
  153126. }
  153127. break;
  153128. case JPEG_REACHED_EOI: /* Found EOI */
  153129. inputctl->pub.eoi_reached = TRUE;
  153130. if (inputctl->inheaders) { /* Tables-only datastream, apparently */
  153131. if (cinfo->marker->saw_SOF)
  153132. ERREXIT(cinfo, JERR_SOF_NO_SOS);
  153133. } else {
  153134. if (cinfo->output_scan_number > cinfo->input_scan_number)
  153135. cinfo->output_scan_number = cinfo->input_scan_number;
  153136. }
  153137. break;
  153138. case JPEG_SUSPENDED:
  153139. break;
  153140. }
  153141. return val;
  153142. }
  153143. METHODDEF(void)
  153144. reset_input_controller (j_decompress_ptr cinfo)
  153145. {
  153146. my_inputctl_ptr inputctl = (my_inputctl_ptr) cinfo->inputctl;
  153147. inputctl->pub.consume_input = consume_markers;
  153148. inputctl->pub.has_multiple_scans = FALSE; /* "unknown" would be better */
  153149. inputctl->pub.eoi_reached = FALSE;
  153150. inputctl->inheaders = TRUE;
  153151. (*cinfo->err->reset_error_mgr) ((j_common_ptr) cinfo);
  153152. (*cinfo->marker->reset_marker_reader) (cinfo);
  153153. cinfo->coef_bits = NULL;
  153154. }
  153155. GLOBAL(void)
  153156. jinit_input_controller (j_decompress_ptr cinfo)
  153157. {
  153158. my_inputctl_ptr inputctl;
  153159. inputctl = (my_inputctl_ptr)
  153160. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
  153161. SIZEOF(my_input_controller));
  153162. cinfo->inputctl = (struct jpeg_input_controller *) inputctl;
  153163. inputctl->pub.consume_input = consume_markers;
  153164. inputctl->pub.reset_input_controller = reset_input_controller;
  153165. inputctl->pub.start_input_pass = start_input_pass2;
  153166. inputctl->pub.finish_input_pass = finish_input_pass;
  153167. inputctl->pub.has_multiple_scans = FALSE; /* "unknown" would be better */
  153168. inputctl->pub.eoi_reached = FALSE;
  153169. inputctl->inheaders = TRUE;
  153170. }
  153171. /********* End of inlined file: jdinput.c *********/
  153172. /********* Start of inlined file: jdmainct.c *********/
  153173. #define JPEG_INTERNALS
  153174. typedef struct {
  153175. struct jpeg_d_main_controller pub; /* public fields */
  153176. JSAMPARRAY buffer[MAX_COMPONENTS];
  153177. boolean buffer_full; /* Have we gotten an iMCU row from decoder? */
  153178. JDIMENSION rowgroup_ctr; /* counts row groups output to postprocessor */
  153179. JSAMPIMAGE xbuffer[2]; /* pointers to weird pointer lists */
  153180. int whichptr; /* indicates which pointer set is now in use */
  153181. int context_state; /* process_data state machine status */
  153182. JDIMENSION rowgroups_avail; /* row groups available to postprocessor */
  153183. JDIMENSION iMCU_row_ctr; /* counts iMCU rows to detect image top/bot */
  153184. } my_main_controller4;
  153185. typedef my_main_controller4 * my_main_ptr4;
  153186. #define CTX_PREPARE_FOR_IMCU 0 /* need to prepare for MCU row */
  153187. #define CTX_PROCESS_IMCU 1 /* feeding iMCU to postprocessor */
  153188. #define CTX_POSTPONED_ROW 2 /* feeding postponed row group */
  153189. METHODDEF(void) process_data_simple_main2
  153190. JPP((j_decompress_ptr cinfo, JSAMPARRAY output_buf,
  153191. JDIMENSION *out_row_ctr, JDIMENSION out_rows_avail));
  153192. METHODDEF(void) process_data_context_main
  153193. JPP((j_decompress_ptr cinfo, JSAMPARRAY output_buf,
  153194. JDIMENSION *out_row_ctr, JDIMENSION out_rows_avail));
  153195. #ifdef QUANT_2PASS_SUPPORTED
  153196. METHODDEF(void) process_data_crank_post
  153197. JPP((j_decompress_ptr cinfo, JSAMPARRAY output_buf,
  153198. JDIMENSION *out_row_ctr, JDIMENSION out_rows_avail));
  153199. #endif
  153200. LOCAL(void)
  153201. alloc_funny_pointers (j_decompress_ptr cinfo)
  153202. {
  153203. my_main_ptr4 main_ = (my_main_ptr4) cinfo->main;
  153204. int ci, rgroup;
  153205. int M = cinfo->min_DCT_scaled_size;
  153206. jpeg_component_info *compptr;
  153207. JSAMPARRAY xbuf;
  153208. main_->xbuffer[0] = (JSAMPIMAGE)
  153209. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  153210. cinfo->num_components * 2 * SIZEOF(JSAMPARRAY));
  153211. main_->xbuffer[1] = main_->xbuffer[0] + cinfo->num_components;
  153212. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  153213. ci++, compptr++) {
  153214. rgroup = (compptr->v_samp_factor * compptr->DCT_scaled_size) /
  153215. cinfo->min_DCT_scaled_size; /* height of a row group of component */
  153216. xbuf = (JSAMPARRAY)
  153217. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  153218. 2 * (rgroup * (M + 4)) * SIZEOF(JSAMPROW));
  153219. xbuf += rgroup; /* want one row group at negative offsets */
  153220. main_->xbuffer[0][ci] = xbuf;
  153221. xbuf += rgroup * (M + 4);
  153222. main_->xbuffer[1][ci] = xbuf;
  153223. }
  153224. }
  153225. LOCAL(void)
  153226. make_funny_pointers (j_decompress_ptr cinfo)
  153227. {
  153228. my_main_ptr4 main_ = (my_main_ptr4) cinfo->main;
  153229. int ci, i, rgroup;
  153230. int M = cinfo->min_DCT_scaled_size;
  153231. jpeg_component_info *compptr;
  153232. JSAMPARRAY buf, xbuf0, xbuf1;
  153233. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  153234. ci++, compptr++) {
  153235. rgroup = (compptr->v_samp_factor * compptr->DCT_scaled_size) /
  153236. cinfo->min_DCT_scaled_size; /* height of a row group of component */
  153237. xbuf0 = main_->xbuffer[0][ci];
  153238. xbuf1 = main_->xbuffer[1][ci];
  153239. buf = main_->buffer[ci];
  153240. for (i = 0; i < rgroup * (M + 2); i++) {
  153241. xbuf0[i] = xbuf1[i] = buf[i];
  153242. }
  153243. for (i = 0; i < rgroup * 2; i++) {
  153244. xbuf1[rgroup*(M-2) + i] = buf[rgroup*M + i];
  153245. xbuf1[rgroup*M + i] = buf[rgroup*(M-2) + i];
  153246. }
  153247. for (i = 0; i < rgroup; i++) {
  153248. xbuf0[i - rgroup] = xbuf0[0];
  153249. }
  153250. }
  153251. }
  153252. LOCAL(void)
  153253. set_wraparound_pointers (j_decompress_ptr cinfo)
  153254. {
  153255. my_main_ptr4 main_ = (my_main_ptr4) cinfo->main;
  153256. int ci, i, rgroup;
  153257. int M = cinfo->min_DCT_scaled_size;
  153258. jpeg_component_info *compptr;
  153259. JSAMPARRAY xbuf0, xbuf1;
  153260. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  153261. ci++, compptr++) {
  153262. rgroup = (compptr->v_samp_factor * compptr->DCT_scaled_size) /
  153263. cinfo->min_DCT_scaled_size; /* height of a row group of component */
  153264. xbuf0 = main_->xbuffer[0][ci];
  153265. xbuf1 = main_->xbuffer[1][ci];
  153266. for (i = 0; i < rgroup; i++) {
  153267. xbuf0[i - rgroup] = xbuf0[rgroup*(M+1) + i];
  153268. xbuf1[i - rgroup] = xbuf1[rgroup*(M+1) + i];
  153269. xbuf0[rgroup*(M+2) + i] = xbuf0[i];
  153270. xbuf1[rgroup*(M+2) + i] = xbuf1[i];
  153271. }
  153272. }
  153273. }
  153274. LOCAL(void)
  153275. set_bottom_pointers (j_decompress_ptr cinfo)
  153276. {
  153277. my_main_ptr4 main_ = (my_main_ptr4) cinfo->main;
  153278. int ci, i, rgroup, iMCUheight, rows_left;
  153279. jpeg_component_info *compptr;
  153280. JSAMPARRAY xbuf;
  153281. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  153282. ci++, compptr++) {
  153283. iMCUheight = compptr->v_samp_factor * compptr->DCT_scaled_size;
  153284. rgroup = iMCUheight / cinfo->min_DCT_scaled_size;
  153285. rows_left = (int) (compptr->downsampled_height % (JDIMENSION) iMCUheight);
  153286. if (rows_left == 0) rows_left = iMCUheight;
  153287. if (ci == 0) {
  153288. main_->rowgroups_avail = (JDIMENSION) ((rows_left-1) / rgroup + 1);
  153289. }
  153290. xbuf = main_->xbuffer[main_->whichptr][ci];
  153291. for (i = 0; i < rgroup * 2; i++) {
  153292. xbuf[rows_left + i] = xbuf[rows_left-1];
  153293. }
  153294. }
  153295. }
  153296. METHODDEF(void)
  153297. start_pass_main2 (j_decompress_ptr cinfo, J_BUF_MODE pass_mode)
  153298. {
  153299. my_main_ptr4 main_ = (my_main_ptr4) cinfo->main;
  153300. switch (pass_mode) {
  153301. case JBUF_PASS_THRU:
  153302. if (cinfo->upsample->need_context_rows) {
  153303. main_->pub.process_data = process_data_context_main;
  153304. make_funny_pointers(cinfo); /* Create the xbuffer[] lists */
  153305. main_->whichptr = 0; /* Read first iMCU row into xbuffer[0] */
  153306. main_->context_state = CTX_PREPARE_FOR_IMCU;
  153307. main_->iMCU_row_ctr = 0;
  153308. } else {
  153309. main_->pub.process_data = process_data_simple_main2;
  153310. }
  153311. main_->buffer_full = FALSE; /* Mark buffer empty */
  153312. main_->rowgroup_ctr = 0;
  153313. break;
  153314. #ifdef QUANT_2PASS_SUPPORTED
  153315. case JBUF_CRANK_DEST:
  153316. main_->pub.process_data = process_data_crank_post;
  153317. break;
  153318. #endif
  153319. default:
  153320. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  153321. break;
  153322. }
  153323. }
  153324. METHODDEF(void)
  153325. process_data_simple_main2 (j_decompress_ptr cinfo,
  153326. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  153327. JDIMENSION out_rows_avail)
  153328. {
  153329. my_main_ptr4 main_ = (my_main_ptr4) cinfo->main;
  153330. JDIMENSION rowgroups_avail;
  153331. if (! main_->buffer_full) {
  153332. if (! (*cinfo->coef->decompress_data) (cinfo, main_->buffer))
  153333. return; /* suspension forced, can do nothing more */
  153334. main_->buffer_full = TRUE; /* OK, we have an iMCU row to work with */
  153335. }
  153336. rowgroups_avail = (JDIMENSION) cinfo->min_DCT_scaled_size;
  153337. (*cinfo->post->post_process_data) (cinfo, main_->buffer,
  153338. &main_->rowgroup_ctr, rowgroups_avail,
  153339. output_buf, out_row_ctr, out_rows_avail);
  153340. if (main_->rowgroup_ctr >= rowgroups_avail) {
  153341. main_->buffer_full = FALSE;
  153342. main_->rowgroup_ctr = 0;
  153343. }
  153344. }
  153345. METHODDEF(void)
  153346. process_data_context_main (j_decompress_ptr cinfo,
  153347. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  153348. JDIMENSION out_rows_avail)
  153349. {
  153350. my_main_ptr4 main_ = (my_main_ptr4) cinfo->main;
  153351. if (! main_->buffer_full) {
  153352. if (! (*cinfo->coef->decompress_data) (cinfo,
  153353. main_->xbuffer[main_->whichptr]))
  153354. return; /* suspension forced, can do nothing more */
  153355. main_->buffer_full = TRUE; /* OK, we have an iMCU row to work with */
  153356. main_->iMCU_row_ctr++; /* count rows received */
  153357. }
  153358. switch (main_->context_state) {
  153359. case CTX_POSTPONED_ROW:
  153360. (*cinfo->post->post_process_data) (cinfo, main_->xbuffer[main_->whichptr],
  153361. &main_->rowgroup_ctr, main_->rowgroups_avail,
  153362. output_buf, out_row_ctr, out_rows_avail);
  153363. if (main_->rowgroup_ctr < main_->rowgroups_avail)
  153364. return; /* Need to suspend */
  153365. main_->context_state = CTX_PREPARE_FOR_IMCU;
  153366. if (*out_row_ctr >= out_rows_avail)
  153367. return; /* Postprocessor exactly filled output buf */
  153368. case CTX_PREPARE_FOR_IMCU:
  153369. main_->rowgroup_ctr = 0;
  153370. main_->rowgroups_avail = (JDIMENSION) (cinfo->min_DCT_scaled_size - 1);
  153371. if (main_->iMCU_row_ctr == cinfo->total_iMCU_rows)
  153372. set_bottom_pointers(cinfo);
  153373. main_->context_state = CTX_PROCESS_IMCU;
  153374. case CTX_PROCESS_IMCU:
  153375. (*cinfo->post->post_process_data) (cinfo, main_->xbuffer[main_->whichptr],
  153376. &main_->rowgroup_ctr, main_->rowgroups_avail,
  153377. output_buf, out_row_ctr, out_rows_avail);
  153378. if (main_->rowgroup_ctr < main_->rowgroups_avail)
  153379. return; /* Need to suspend */
  153380. if (main_->iMCU_row_ctr == 1)
  153381. set_wraparound_pointers(cinfo);
  153382. main_->whichptr ^= 1; /* 0=>1 or 1=>0 */
  153383. main_->buffer_full = FALSE;
  153384. main_->rowgroup_ctr = (JDIMENSION) (cinfo->min_DCT_scaled_size + 1);
  153385. main_->rowgroups_avail = (JDIMENSION) (cinfo->min_DCT_scaled_size + 2);
  153386. main_->context_state = CTX_POSTPONED_ROW;
  153387. }
  153388. }
  153389. #ifdef QUANT_2PASS_SUPPORTED
  153390. METHODDEF(void)
  153391. process_data_crank_post (j_decompress_ptr cinfo,
  153392. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  153393. JDIMENSION out_rows_avail)
  153394. {
  153395. (*cinfo->post->post_process_data) (cinfo, (JSAMPIMAGE) NULL,
  153396. (JDIMENSION *) NULL, (JDIMENSION) 0,
  153397. output_buf, out_row_ctr, out_rows_avail);
  153398. }
  153399. #endif /* QUANT_2PASS_SUPPORTED */
  153400. GLOBAL(void)
  153401. jinit_d_main_controller (j_decompress_ptr cinfo, boolean need_full_buffer)
  153402. {
  153403. my_main_ptr4 main_;
  153404. int ci, rgroup, ngroups;
  153405. jpeg_component_info *compptr;
  153406. main_ = (my_main_ptr4)
  153407. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  153408. SIZEOF(my_main_controller4));
  153409. cinfo->main = (struct jpeg_d_main_controller *) main_;
  153410. main_->pub.start_pass = start_pass_main2;
  153411. if (need_full_buffer) /* shouldn't happen */
  153412. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  153413. if (cinfo->upsample->need_context_rows) {
  153414. if (cinfo->min_DCT_scaled_size < 2) /* unsupported, see comments above */
  153415. ERREXIT(cinfo, JERR_NOTIMPL);
  153416. alloc_funny_pointers(cinfo); /* Alloc space for xbuffer[] lists */
  153417. ngroups = cinfo->min_DCT_scaled_size + 2;
  153418. } else {
  153419. ngroups = cinfo->min_DCT_scaled_size;
  153420. }
  153421. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  153422. ci++, compptr++) {
  153423. rgroup = (compptr->v_samp_factor * compptr->DCT_scaled_size) /
  153424. cinfo->min_DCT_scaled_size; /* height of a row group of component */
  153425. main_->buffer[ci] = (*cinfo->mem->alloc_sarray)
  153426. ((j_common_ptr) cinfo, JPOOL_IMAGE,
  153427. compptr->width_in_blocks * compptr->DCT_scaled_size,
  153428. (JDIMENSION) (rgroup * ngroups));
  153429. }
  153430. }
  153431. /********* End of inlined file: jdmainct.c *********/
  153432. /********* Start of inlined file: jdmarker.c *********/
  153433. #define JPEG_INTERNALS
  153434. typedef struct {
  153435. struct jpeg_marker_reader pub; /* public fields */
  153436. jpeg_marker_parser_method process_COM;
  153437. jpeg_marker_parser_method process_APPn[16];
  153438. unsigned int length_limit_COM;
  153439. unsigned int length_limit_APPn[16];
  153440. jpeg_saved_marker_ptr cur_marker; /* NULL if not processing a marker */
  153441. unsigned int bytes_read; /* data bytes read so far in marker */
  153442. } my_marker_reader;
  153443. typedef my_marker_reader * my_marker_ptr2;
  153444. #define INPUT_VARS(cinfo) \
  153445. struct jpeg_source_mgr * datasrc = (cinfo)->src; \
  153446. const JOCTET * next_input_byte = datasrc->next_input_byte; \
  153447. size_t bytes_in_buffer = datasrc->bytes_in_buffer
  153448. #define INPUT_SYNC(cinfo) \
  153449. ( datasrc->next_input_byte = next_input_byte, \
  153450. datasrc->bytes_in_buffer = bytes_in_buffer )
  153451. #define INPUT_RELOAD(cinfo) \
  153452. ( next_input_byte = datasrc->next_input_byte, \
  153453. bytes_in_buffer = datasrc->bytes_in_buffer )
  153454. #define MAKE_BYTE_AVAIL(cinfo,action) \
  153455. if (bytes_in_buffer == 0) { \
  153456. if (! (*datasrc->fill_input_buffer) (cinfo)) \
  153457. { action; } \
  153458. INPUT_RELOAD(cinfo); \
  153459. }
  153460. #define INPUT_BYTE(cinfo,V,action) \
  153461. MAKESTMT( MAKE_BYTE_AVAIL(cinfo,action); \
  153462. bytes_in_buffer--; \
  153463. V = GETJOCTET(*next_input_byte++); )
  153464. #define INPUT_2BYTES(cinfo,V,action) \
  153465. MAKESTMT( MAKE_BYTE_AVAIL(cinfo,action); \
  153466. bytes_in_buffer--; \
  153467. V = ((unsigned int) GETJOCTET(*next_input_byte++)) << 8; \
  153468. MAKE_BYTE_AVAIL(cinfo,action); \
  153469. bytes_in_buffer--; \
  153470. V += GETJOCTET(*next_input_byte++); )
  153471. LOCAL(boolean)
  153472. get_soi (j_decompress_ptr cinfo)
  153473. {
  153474. int i;
  153475. TRACEMS(cinfo, 1, JTRC_SOI);
  153476. if (cinfo->marker->saw_SOI)
  153477. ERREXIT(cinfo, JERR_SOI_DUPLICATE);
  153478. for (i = 0; i < NUM_ARITH_TBLS; i++) {
  153479. cinfo->arith_dc_L[i] = 0;
  153480. cinfo->arith_dc_U[i] = 1;
  153481. cinfo->arith_ac_K[i] = 5;
  153482. }
  153483. cinfo->restart_interval = 0;
  153484. cinfo->jpeg_color_space = JCS_UNKNOWN;
  153485. cinfo->CCIR601_sampling = FALSE; /* Assume non-CCIR sampling??? */
  153486. cinfo->saw_JFIF_marker = FALSE;
  153487. cinfo->JFIF_major_version = 1; /* set default JFIF APP0 values */
  153488. cinfo->JFIF_minor_version = 1;
  153489. cinfo->density_unit = 0;
  153490. cinfo->X_density = 1;
  153491. cinfo->Y_density = 1;
  153492. cinfo->saw_Adobe_marker = FALSE;
  153493. cinfo->Adobe_transform = 0;
  153494. cinfo->marker->saw_SOI = TRUE;
  153495. return TRUE;
  153496. }
  153497. LOCAL(boolean)
  153498. get_sof (j_decompress_ptr cinfo, boolean is_prog, boolean is_arith)
  153499. {
  153500. INT32 length;
  153501. int c, ci;
  153502. jpeg_component_info * compptr;
  153503. INPUT_VARS(cinfo);
  153504. cinfo->progressive_mode = is_prog;
  153505. cinfo->arith_code = is_arith;
  153506. INPUT_2BYTES(cinfo, length, return FALSE);
  153507. INPUT_BYTE(cinfo, cinfo->data_precision, return FALSE);
  153508. INPUT_2BYTES(cinfo, cinfo->image_height, return FALSE);
  153509. INPUT_2BYTES(cinfo, cinfo->image_width, return FALSE);
  153510. INPUT_BYTE(cinfo, cinfo->num_components, return FALSE);
  153511. length -= 8;
  153512. TRACEMS4(cinfo, 1, JTRC_SOF, cinfo->unread_marker,
  153513. (int) cinfo->image_width, (int) cinfo->image_height,
  153514. cinfo->num_components);
  153515. if (cinfo->marker->saw_SOF)
  153516. ERREXIT(cinfo, JERR_SOF_DUPLICATE);
  153517. if (cinfo->image_height <= 0 || cinfo->image_width <= 0
  153518. || cinfo->num_components <= 0)
  153519. ERREXIT(cinfo, JERR_EMPTY_IMAGE);
  153520. if (length != (cinfo->num_components * 3))
  153521. ERREXIT(cinfo, JERR_BAD_LENGTH);
  153522. if (cinfo->comp_info == NULL) /* do only once, even if suspend */
  153523. cinfo->comp_info = (jpeg_component_info *) (*cinfo->mem->alloc_small)
  153524. ((j_common_ptr) cinfo, JPOOL_IMAGE,
  153525. cinfo->num_components * SIZEOF(jpeg_component_info));
  153526. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  153527. ci++, compptr++) {
  153528. compptr->component_index = ci;
  153529. INPUT_BYTE(cinfo, compptr->component_id, return FALSE);
  153530. INPUT_BYTE(cinfo, c, return FALSE);
  153531. compptr->h_samp_factor = (c >> 4) & 15;
  153532. compptr->v_samp_factor = (c ) & 15;
  153533. INPUT_BYTE(cinfo, compptr->quant_tbl_no, return FALSE);
  153534. TRACEMS4(cinfo, 1, JTRC_SOF_COMPONENT,
  153535. compptr->component_id, compptr->h_samp_factor,
  153536. compptr->v_samp_factor, compptr->quant_tbl_no);
  153537. }
  153538. cinfo->marker->saw_SOF = TRUE;
  153539. INPUT_SYNC(cinfo);
  153540. return TRUE;
  153541. }
  153542. LOCAL(boolean)
  153543. get_sos (j_decompress_ptr cinfo)
  153544. {
  153545. INT32 length;
  153546. int i, ci, n, c, cc;
  153547. jpeg_component_info * compptr;
  153548. INPUT_VARS(cinfo);
  153549. if (! cinfo->marker->saw_SOF)
  153550. ERREXIT(cinfo, JERR_SOS_NO_SOF);
  153551. INPUT_2BYTES(cinfo, length, return FALSE);
  153552. INPUT_BYTE(cinfo, n, return FALSE); /* Number of components */
  153553. TRACEMS1(cinfo, 1, JTRC_SOS, n);
  153554. if (length != (n * 2 + 6) || n < 1 || n > MAX_COMPS_IN_SCAN)
  153555. ERREXIT(cinfo, JERR_BAD_LENGTH);
  153556. cinfo->comps_in_scan = n;
  153557. for (i = 0; i < n; i++) {
  153558. INPUT_BYTE(cinfo, cc, return FALSE);
  153559. INPUT_BYTE(cinfo, c, return FALSE);
  153560. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  153561. ci++, compptr++) {
  153562. if (cc == compptr->component_id)
  153563. goto id_found;
  153564. }
  153565. ERREXIT1(cinfo, JERR_BAD_COMPONENT_ID, cc);
  153566. id_found:
  153567. cinfo->cur_comp_info[i] = compptr;
  153568. compptr->dc_tbl_no = (c >> 4) & 15;
  153569. compptr->ac_tbl_no = (c ) & 15;
  153570. TRACEMS3(cinfo, 1, JTRC_SOS_COMPONENT, cc,
  153571. compptr->dc_tbl_no, compptr->ac_tbl_no);
  153572. }
  153573. INPUT_BYTE(cinfo, c, return FALSE);
  153574. cinfo->Ss = c;
  153575. INPUT_BYTE(cinfo, c, return FALSE);
  153576. cinfo->Se = c;
  153577. INPUT_BYTE(cinfo, c, return FALSE);
  153578. cinfo->Ah = (c >> 4) & 15;
  153579. cinfo->Al = (c ) & 15;
  153580. TRACEMS4(cinfo, 1, JTRC_SOS_PARAMS, cinfo->Ss, cinfo->Se,
  153581. cinfo->Ah, cinfo->Al);
  153582. cinfo->marker->next_restart_num = 0;
  153583. cinfo->input_scan_number++;
  153584. INPUT_SYNC(cinfo);
  153585. return TRUE;
  153586. }
  153587. #ifdef D_ARITH_CODING_SUPPORTED
  153588. LOCAL(boolean)
  153589. get_dac (j_decompress_ptr cinfo)
  153590. {
  153591. INT32 length;
  153592. int index, val;
  153593. INPUT_VARS(cinfo);
  153594. INPUT_2BYTES(cinfo, length, return FALSE);
  153595. length -= 2;
  153596. while (length > 0) {
  153597. INPUT_BYTE(cinfo, index, return FALSE);
  153598. INPUT_BYTE(cinfo, val, return FALSE);
  153599. length -= 2;
  153600. TRACEMS2(cinfo, 1, JTRC_DAC, index, val);
  153601. if (index < 0 || index >= (2*NUM_ARITH_TBLS))
  153602. ERREXIT1(cinfo, JERR_DAC_INDEX, index);
  153603. if (index >= NUM_ARITH_TBLS) { /* define AC table */
  153604. cinfo->arith_ac_K[index-NUM_ARITH_TBLS] = (UINT8) val;
  153605. } else { /* define DC table */
  153606. cinfo->arith_dc_L[index] = (UINT8) (val & 0x0F);
  153607. cinfo->arith_dc_U[index] = (UINT8) (val >> 4);
  153608. if (cinfo->arith_dc_L[index] > cinfo->arith_dc_U[index])
  153609. ERREXIT1(cinfo, JERR_DAC_VALUE, val);
  153610. }
  153611. }
  153612. if (length != 0)
  153613. ERREXIT(cinfo, JERR_BAD_LENGTH);
  153614. INPUT_SYNC(cinfo);
  153615. return TRUE;
  153616. }
  153617. #else /* ! D_ARITH_CODING_SUPPORTED */
  153618. #define get_dac(cinfo) skip_variable(cinfo)
  153619. #endif /* D_ARITH_CODING_SUPPORTED */
  153620. LOCAL(boolean)
  153621. get_dht (j_decompress_ptr cinfo)
  153622. {
  153623. INT32 length;
  153624. UINT8 bits[17];
  153625. UINT8 huffval[256];
  153626. int i, index, count;
  153627. JHUFF_TBL **htblptr;
  153628. INPUT_VARS(cinfo);
  153629. INPUT_2BYTES(cinfo, length, return FALSE);
  153630. length -= 2;
  153631. while (length > 16) {
  153632. INPUT_BYTE(cinfo, index, return FALSE);
  153633. TRACEMS1(cinfo, 1, JTRC_DHT, index);
  153634. bits[0] = 0;
  153635. count = 0;
  153636. for (i = 1; i <= 16; i++) {
  153637. INPUT_BYTE(cinfo, bits[i], return FALSE);
  153638. count += bits[i];
  153639. }
  153640. length -= 1 + 16;
  153641. TRACEMS8(cinfo, 2, JTRC_HUFFBITS,
  153642. bits[1], bits[2], bits[3], bits[4],
  153643. bits[5], bits[6], bits[7], bits[8]);
  153644. TRACEMS8(cinfo, 2, JTRC_HUFFBITS,
  153645. bits[9], bits[10], bits[11], bits[12],
  153646. bits[13], bits[14], bits[15], bits[16]);
  153647. if (count > 256 || ((INT32) count) > length)
  153648. ERREXIT(cinfo, JERR_BAD_HUFF_TABLE);
  153649. for (i = 0; i < count; i++)
  153650. INPUT_BYTE(cinfo, huffval[i], return FALSE);
  153651. length -= count;
  153652. if (index & 0x10) { /* AC table definition */
  153653. index -= 0x10;
  153654. htblptr = &cinfo->ac_huff_tbl_ptrs[index];
  153655. } else { /* DC table definition */
  153656. htblptr = &cinfo->dc_huff_tbl_ptrs[index];
  153657. }
  153658. if (index < 0 || index >= NUM_HUFF_TBLS)
  153659. ERREXIT1(cinfo, JERR_DHT_INDEX, index);
  153660. if (*htblptr == NULL)
  153661. *htblptr = jpeg_alloc_huff_table((j_common_ptr) cinfo);
  153662. MEMCOPY((*htblptr)->bits, bits, SIZEOF((*htblptr)->bits));
  153663. MEMCOPY((*htblptr)->huffval, huffval, SIZEOF((*htblptr)->huffval));
  153664. }
  153665. if (length != 0)
  153666. ERREXIT(cinfo, JERR_BAD_LENGTH);
  153667. INPUT_SYNC(cinfo);
  153668. return TRUE;
  153669. }
  153670. LOCAL(boolean)
  153671. get_dqt (j_decompress_ptr cinfo)
  153672. {
  153673. INT32 length;
  153674. int n, i, prec;
  153675. unsigned int tmp;
  153676. JQUANT_TBL *quant_ptr;
  153677. INPUT_VARS(cinfo);
  153678. INPUT_2BYTES(cinfo, length, return FALSE);
  153679. length -= 2;
  153680. while (length > 0) {
  153681. INPUT_BYTE(cinfo, n, return FALSE);
  153682. prec = n >> 4;
  153683. n &= 0x0F;
  153684. TRACEMS2(cinfo, 1, JTRC_DQT, n, prec);
  153685. if (n >= NUM_QUANT_TBLS)
  153686. ERREXIT1(cinfo, JERR_DQT_INDEX, n);
  153687. if (cinfo->quant_tbl_ptrs[n] == NULL)
  153688. cinfo->quant_tbl_ptrs[n] = jpeg_alloc_quant_table((j_common_ptr) cinfo);
  153689. quant_ptr = cinfo->quant_tbl_ptrs[n];
  153690. for (i = 0; i < DCTSIZE2; i++) {
  153691. if (prec)
  153692. INPUT_2BYTES(cinfo, tmp, return FALSE);
  153693. else
  153694. INPUT_BYTE(cinfo, tmp, return FALSE);
  153695. quant_ptr->quantval[jpeg_natural_order[i]] = (UINT16) tmp;
  153696. }
  153697. if (cinfo->err->trace_level >= 2) {
  153698. for (i = 0; i < DCTSIZE2; i += 8) {
  153699. TRACEMS8(cinfo, 2, JTRC_QUANTVALS,
  153700. quant_ptr->quantval[i], quant_ptr->quantval[i+1],
  153701. quant_ptr->quantval[i+2], quant_ptr->quantval[i+3],
  153702. quant_ptr->quantval[i+4], quant_ptr->quantval[i+5],
  153703. quant_ptr->quantval[i+6], quant_ptr->quantval[i+7]);
  153704. }
  153705. }
  153706. length -= DCTSIZE2+1;
  153707. if (prec) length -= DCTSIZE2;
  153708. }
  153709. if (length != 0)
  153710. ERREXIT(cinfo, JERR_BAD_LENGTH);
  153711. INPUT_SYNC(cinfo);
  153712. return TRUE;
  153713. }
  153714. LOCAL(boolean)
  153715. get_dri (j_decompress_ptr cinfo)
  153716. {
  153717. INT32 length;
  153718. unsigned int tmp;
  153719. INPUT_VARS(cinfo);
  153720. INPUT_2BYTES(cinfo, length, return FALSE);
  153721. if (length != 4)
  153722. ERREXIT(cinfo, JERR_BAD_LENGTH);
  153723. INPUT_2BYTES(cinfo, tmp, return FALSE);
  153724. TRACEMS1(cinfo, 1, JTRC_DRI, tmp);
  153725. cinfo->restart_interval = tmp;
  153726. INPUT_SYNC(cinfo);
  153727. return TRUE;
  153728. }
  153729. #define APP0_DATA_LEN 14 /* Length of interesting data in APP0 */
  153730. #define APP14_DATA_LEN 12 /* Length of interesting data in APP14 */
  153731. #define APPN_DATA_LEN 14 /* Must be the largest of the above!! */
  153732. LOCAL(void)
  153733. examine_app0 (j_decompress_ptr cinfo, JOCTET FAR * data,
  153734. unsigned int datalen, INT32 remaining)
  153735. {
  153736. INT32 totallen = (INT32) datalen + remaining;
  153737. if (datalen >= APP0_DATA_LEN &&
  153738. GETJOCTET(data[0]) == 0x4A &&
  153739. GETJOCTET(data[1]) == 0x46 &&
  153740. GETJOCTET(data[2]) == 0x49 &&
  153741. GETJOCTET(data[3]) == 0x46 &&
  153742. GETJOCTET(data[4]) == 0) {
  153743. cinfo->saw_JFIF_marker = TRUE;
  153744. cinfo->JFIF_major_version = GETJOCTET(data[5]);
  153745. cinfo->JFIF_minor_version = GETJOCTET(data[6]);
  153746. cinfo->density_unit = GETJOCTET(data[7]);
  153747. cinfo->X_density = (GETJOCTET(data[8]) << 8) + GETJOCTET(data[9]);
  153748. cinfo->Y_density = (GETJOCTET(data[10]) << 8) + GETJOCTET(data[11]);
  153749. if (cinfo->JFIF_major_version != 1)
  153750. WARNMS2(cinfo, JWRN_JFIF_MAJOR,
  153751. cinfo->JFIF_major_version, cinfo->JFIF_minor_version);
  153752. TRACEMS5(cinfo, 1, JTRC_JFIF,
  153753. cinfo->JFIF_major_version, cinfo->JFIF_minor_version,
  153754. cinfo->X_density, cinfo->Y_density, cinfo->density_unit);
  153755. if (GETJOCTET(data[12]) | GETJOCTET(data[13]))
  153756. TRACEMS2(cinfo, 1, JTRC_JFIF_THUMBNAIL,
  153757. GETJOCTET(data[12]), GETJOCTET(data[13]));
  153758. totallen -= APP0_DATA_LEN;
  153759. if (totallen !=
  153760. ((INT32)GETJOCTET(data[12]) * (INT32)GETJOCTET(data[13]) * (INT32) 3))
  153761. TRACEMS1(cinfo, 1, JTRC_JFIF_BADTHUMBNAILSIZE, (int) totallen);
  153762. } else if (datalen >= 6 &&
  153763. GETJOCTET(data[0]) == 0x4A &&
  153764. GETJOCTET(data[1]) == 0x46 &&
  153765. GETJOCTET(data[2]) == 0x58 &&
  153766. GETJOCTET(data[3]) == 0x58 &&
  153767. GETJOCTET(data[4]) == 0) {
  153768. switch (GETJOCTET(data[5])) {
  153769. case 0x10:
  153770. TRACEMS1(cinfo, 1, JTRC_THUMB_JPEG, (int) totallen);
  153771. break;
  153772. case 0x11:
  153773. TRACEMS1(cinfo, 1, JTRC_THUMB_PALETTE, (int) totallen);
  153774. break;
  153775. case 0x13:
  153776. TRACEMS1(cinfo, 1, JTRC_THUMB_RGB, (int) totallen);
  153777. break;
  153778. default:
  153779. TRACEMS2(cinfo, 1, JTRC_JFIF_EXTENSION,
  153780. GETJOCTET(data[5]), (int) totallen);
  153781. break;
  153782. }
  153783. } else {
  153784. TRACEMS1(cinfo, 1, JTRC_APP0, (int) totallen);
  153785. }
  153786. }
  153787. LOCAL(void)
  153788. examine_app14 (j_decompress_ptr cinfo, JOCTET FAR * data,
  153789. unsigned int datalen, INT32 remaining)
  153790. {
  153791. unsigned int version, flags0, flags1, transform;
  153792. if (datalen >= APP14_DATA_LEN &&
  153793. GETJOCTET(data[0]) == 0x41 &&
  153794. GETJOCTET(data[1]) == 0x64 &&
  153795. GETJOCTET(data[2]) == 0x6F &&
  153796. GETJOCTET(data[3]) == 0x62 &&
  153797. GETJOCTET(data[4]) == 0x65) {
  153798. version = (GETJOCTET(data[5]) << 8) + GETJOCTET(data[6]);
  153799. flags0 = (GETJOCTET(data[7]) << 8) + GETJOCTET(data[8]);
  153800. flags1 = (GETJOCTET(data[9]) << 8) + GETJOCTET(data[10]);
  153801. transform = GETJOCTET(data[11]);
  153802. TRACEMS4(cinfo, 1, JTRC_ADOBE, version, flags0, flags1, transform);
  153803. cinfo->saw_Adobe_marker = TRUE;
  153804. cinfo->Adobe_transform = (UINT8) transform;
  153805. } else {
  153806. TRACEMS1(cinfo, 1, JTRC_APP14, (int) (datalen + remaining));
  153807. }
  153808. }
  153809. METHODDEF(boolean)
  153810. get_interesting_appn (j_decompress_ptr cinfo)
  153811. {
  153812. INT32 length;
  153813. JOCTET b[APPN_DATA_LEN];
  153814. unsigned int i, numtoread;
  153815. INPUT_VARS(cinfo);
  153816. INPUT_2BYTES(cinfo, length, return FALSE);
  153817. length -= 2;
  153818. if (length >= APPN_DATA_LEN)
  153819. numtoread = APPN_DATA_LEN;
  153820. else if (length > 0)
  153821. numtoread = (unsigned int) length;
  153822. else
  153823. numtoread = 0;
  153824. for (i = 0; i < numtoread; i++)
  153825. INPUT_BYTE(cinfo, b[i], return FALSE);
  153826. length -= numtoread;
  153827. switch (cinfo->unread_marker) {
  153828. case M_APP0:
  153829. examine_app0(cinfo, (JOCTET FAR *) b, numtoread, length);
  153830. break;
  153831. case M_APP14:
  153832. examine_app14(cinfo, (JOCTET FAR *) b, numtoread, length);
  153833. break;
  153834. default:
  153835. ERREXIT1(cinfo, JERR_UNKNOWN_MARKER, cinfo->unread_marker);
  153836. break;
  153837. }
  153838. INPUT_SYNC(cinfo);
  153839. if (length > 0)
  153840. (*cinfo->src->skip_input_data) (cinfo, (long) length);
  153841. return TRUE;
  153842. }
  153843. #ifdef SAVE_MARKERS_SUPPORTED
  153844. METHODDEF(boolean)
  153845. save_marker (j_decompress_ptr cinfo)
  153846. {
  153847. my_marker_ptr2 marker = (my_marker_ptr2) cinfo->marker;
  153848. jpeg_saved_marker_ptr cur_marker = marker->cur_marker;
  153849. unsigned int bytes_read, data_length;
  153850. JOCTET FAR * data;
  153851. INT32 length = 0;
  153852. INPUT_VARS(cinfo);
  153853. if (cur_marker == NULL) {
  153854. INPUT_2BYTES(cinfo, length, return FALSE);
  153855. length -= 2;
  153856. if (length >= 0) { /* watch out for bogus length word */
  153857. unsigned int limit;
  153858. if (cinfo->unread_marker == (int) M_COM)
  153859. limit = marker->length_limit_COM;
  153860. else
  153861. limit = marker->length_limit_APPn[cinfo->unread_marker - (int) M_APP0];
  153862. if ((unsigned int) length < limit)
  153863. limit = (unsigned int) length;
  153864. cur_marker = (jpeg_saved_marker_ptr)
  153865. (*cinfo->mem->alloc_large) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  153866. SIZEOF(struct jpeg_marker_struct) + limit);
  153867. cur_marker->next = NULL;
  153868. cur_marker->marker = (UINT8) cinfo->unread_marker;
  153869. cur_marker->original_length = (unsigned int) length;
  153870. cur_marker->data_length = limit;
  153871. data = cur_marker->data = (JOCTET FAR *) (cur_marker + 1);
  153872. marker->cur_marker = cur_marker;
  153873. marker->bytes_read = 0;
  153874. bytes_read = 0;
  153875. data_length = limit;
  153876. } else {
  153877. bytes_read = data_length = 0;
  153878. data = NULL;
  153879. }
  153880. } else {
  153881. bytes_read = marker->bytes_read;
  153882. data_length = cur_marker->data_length;
  153883. data = cur_marker->data + bytes_read;
  153884. }
  153885. while (bytes_read < data_length) {
  153886. INPUT_SYNC(cinfo); /* move the restart point to here */
  153887. marker->bytes_read = bytes_read;
  153888. MAKE_BYTE_AVAIL(cinfo, return FALSE);
  153889. while (bytes_read < data_length && bytes_in_buffer > 0) {
  153890. *data++ = *next_input_byte++;
  153891. bytes_in_buffer--;
  153892. bytes_read++;
  153893. }
  153894. }
  153895. if (cur_marker != NULL) { /* will be NULL if bogus length word */
  153896. if (cinfo->marker_list == NULL) {
  153897. cinfo->marker_list = cur_marker;
  153898. } else {
  153899. jpeg_saved_marker_ptr prev = cinfo->marker_list;
  153900. while (prev->next != NULL)
  153901. prev = prev->next;
  153902. prev->next = cur_marker;
  153903. }
  153904. data = cur_marker->data;
  153905. length = cur_marker->original_length - data_length;
  153906. }
  153907. marker->cur_marker = NULL;
  153908. switch (cinfo->unread_marker) {
  153909. case M_APP0:
  153910. examine_app0(cinfo, data, data_length, length);
  153911. break;
  153912. case M_APP14:
  153913. examine_app14(cinfo, data, data_length, length);
  153914. break;
  153915. default:
  153916. TRACEMS2(cinfo, 1, JTRC_MISC_MARKER, cinfo->unread_marker,
  153917. (int) (data_length + length));
  153918. break;
  153919. }
  153920. INPUT_SYNC(cinfo); /* do before skip_input_data */
  153921. if (length > 0)
  153922. (*cinfo->src->skip_input_data) (cinfo, (long) length);
  153923. return TRUE;
  153924. }
  153925. #endif /* SAVE_MARKERS_SUPPORTED */
  153926. METHODDEF(boolean)
  153927. skip_variable (j_decompress_ptr cinfo)
  153928. {
  153929. INT32 length;
  153930. INPUT_VARS(cinfo);
  153931. INPUT_2BYTES(cinfo, length, return FALSE);
  153932. length -= 2;
  153933. TRACEMS2(cinfo, 1, JTRC_MISC_MARKER, cinfo->unread_marker, (int) length);
  153934. INPUT_SYNC(cinfo); /* do before skip_input_data */
  153935. if (length > 0)
  153936. (*cinfo->src->skip_input_data) (cinfo, (long) length);
  153937. return TRUE;
  153938. }
  153939. LOCAL(boolean)
  153940. next_marker (j_decompress_ptr cinfo)
  153941. {
  153942. int c;
  153943. INPUT_VARS(cinfo);
  153944. for (;;) {
  153945. INPUT_BYTE(cinfo, c, return FALSE);
  153946. while (c != 0xFF) {
  153947. cinfo->marker->discarded_bytes++;
  153948. INPUT_SYNC(cinfo);
  153949. INPUT_BYTE(cinfo, c, return FALSE);
  153950. }
  153951. do {
  153952. INPUT_BYTE(cinfo, c, return FALSE);
  153953. } while (c == 0xFF);
  153954. if (c != 0)
  153955. break; /* found a valid marker, exit loop */
  153956. cinfo->marker->discarded_bytes += 2;
  153957. INPUT_SYNC(cinfo);
  153958. }
  153959. if (cinfo->marker->discarded_bytes != 0) {
  153960. WARNMS2(cinfo, JWRN_EXTRANEOUS_DATA, cinfo->marker->discarded_bytes, c);
  153961. cinfo->marker->discarded_bytes = 0;
  153962. }
  153963. cinfo->unread_marker = c;
  153964. INPUT_SYNC(cinfo);
  153965. return TRUE;
  153966. }
  153967. LOCAL(boolean)
  153968. first_marker (j_decompress_ptr cinfo)
  153969. {
  153970. int c, c2;
  153971. INPUT_VARS(cinfo);
  153972. INPUT_BYTE(cinfo, c, return FALSE);
  153973. INPUT_BYTE(cinfo, c2, return FALSE);
  153974. if (c != 0xFF || c2 != (int) M_SOI)
  153975. ERREXIT2(cinfo, JERR_NO_SOI, c, c2);
  153976. cinfo->unread_marker = c2;
  153977. INPUT_SYNC(cinfo);
  153978. return TRUE;
  153979. }
  153980. METHODDEF(int)
  153981. read_markers (j_decompress_ptr cinfo)
  153982. {
  153983. for (;;) {
  153984. if (cinfo->unread_marker == 0) {
  153985. if (! cinfo->marker->saw_SOI) {
  153986. if (! first_marker(cinfo))
  153987. return JPEG_SUSPENDED;
  153988. } else {
  153989. if (! next_marker(cinfo))
  153990. return JPEG_SUSPENDED;
  153991. }
  153992. }
  153993. switch (cinfo->unread_marker) {
  153994. case M_SOI:
  153995. if (! get_soi(cinfo))
  153996. return JPEG_SUSPENDED;
  153997. break;
  153998. case M_SOF0: /* Baseline */
  153999. case M_SOF1: /* Extended sequential, Huffman */
  154000. if (! get_sof(cinfo, FALSE, FALSE))
  154001. return JPEG_SUSPENDED;
  154002. break;
  154003. case M_SOF2: /* Progressive, Huffman */
  154004. if (! get_sof(cinfo, TRUE, FALSE))
  154005. return JPEG_SUSPENDED;
  154006. break;
  154007. case M_SOF9: /* Extended sequential, arithmetic */
  154008. if (! get_sof(cinfo, FALSE, TRUE))
  154009. return JPEG_SUSPENDED;
  154010. break;
  154011. case M_SOF10: /* Progressive, arithmetic */
  154012. if (! get_sof(cinfo, TRUE, TRUE))
  154013. return JPEG_SUSPENDED;
  154014. break;
  154015. case M_SOF3: /* Lossless, Huffman */
  154016. case M_SOF5: /* Differential sequential, Huffman */
  154017. case M_SOF6: /* Differential progressive, Huffman */
  154018. case M_SOF7: /* Differential lossless, Huffman */
  154019. case M_JPG: /* Reserved for JPEG extensions */
  154020. case M_SOF11: /* Lossless, arithmetic */
  154021. case M_SOF13: /* Differential sequential, arithmetic */
  154022. case M_SOF14: /* Differential progressive, arithmetic */
  154023. case M_SOF15: /* Differential lossless, arithmetic */
  154024. ERREXIT1(cinfo, JERR_SOF_UNSUPPORTED, cinfo->unread_marker);
  154025. break;
  154026. case M_SOS:
  154027. if (! get_sos(cinfo))
  154028. return JPEG_SUSPENDED;
  154029. cinfo->unread_marker = 0; /* processed the marker */
  154030. return JPEG_REACHED_SOS;
  154031. case M_EOI:
  154032. TRACEMS(cinfo, 1, JTRC_EOI);
  154033. cinfo->unread_marker = 0; /* processed the marker */
  154034. return JPEG_REACHED_EOI;
  154035. case M_DAC:
  154036. if (! get_dac(cinfo))
  154037. return JPEG_SUSPENDED;
  154038. break;
  154039. case M_DHT:
  154040. if (! get_dht(cinfo))
  154041. return JPEG_SUSPENDED;
  154042. break;
  154043. case M_DQT:
  154044. if (! get_dqt(cinfo))
  154045. return JPEG_SUSPENDED;
  154046. break;
  154047. case M_DRI:
  154048. if (! get_dri(cinfo))
  154049. return JPEG_SUSPENDED;
  154050. break;
  154051. case M_APP0:
  154052. case M_APP1:
  154053. case M_APP2:
  154054. case M_APP3:
  154055. case M_APP4:
  154056. case M_APP5:
  154057. case M_APP6:
  154058. case M_APP7:
  154059. case M_APP8:
  154060. case M_APP9:
  154061. case M_APP10:
  154062. case M_APP11:
  154063. case M_APP12:
  154064. case M_APP13:
  154065. case M_APP14:
  154066. case M_APP15:
  154067. if (! (*((my_marker_ptr2) cinfo->marker)->process_APPn[
  154068. cinfo->unread_marker - (int) M_APP0]) (cinfo))
  154069. return JPEG_SUSPENDED;
  154070. break;
  154071. case M_COM:
  154072. if (! (*((my_marker_ptr2) cinfo->marker)->process_COM) (cinfo))
  154073. return JPEG_SUSPENDED;
  154074. break;
  154075. case M_RST0: /* these are all parameterless */
  154076. case M_RST1:
  154077. case M_RST2:
  154078. case M_RST3:
  154079. case M_RST4:
  154080. case M_RST5:
  154081. case M_RST6:
  154082. case M_RST7:
  154083. case M_TEM:
  154084. TRACEMS1(cinfo, 1, JTRC_PARMLESS_MARKER, cinfo->unread_marker);
  154085. break;
  154086. case M_DNL: /* Ignore DNL ... perhaps the wrong thing */
  154087. if (! skip_variable(cinfo))
  154088. return JPEG_SUSPENDED;
  154089. break;
  154090. default: /* must be DHP, EXP, JPGn, or RESn */
  154091. ERREXIT1(cinfo, JERR_UNKNOWN_MARKER, cinfo->unread_marker);
  154092. break;
  154093. }
  154094. cinfo->unread_marker = 0;
  154095. } /* end loop */
  154096. }
  154097. METHODDEF(boolean)
  154098. read_restart_marker (j_decompress_ptr cinfo)
  154099. {
  154100. if (cinfo->unread_marker == 0) {
  154101. if (! next_marker(cinfo))
  154102. return FALSE;
  154103. }
  154104. if (cinfo->unread_marker ==
  154105. ((int) M_RST0 + cinfo->marker->next_restart_num)) {
  154106. TRACEMS1(cinfo, 3, JTRC_RST, cinfo->marker->next_restart_num);
  154107. cinfo->unread_marker = 0;
  154108. } else {
  154109. if (! (*cinfo->src->resync_to_restart) (cinfo,
  154110. cinfo->marker->next_restart_num))
  154111. return FALSE;
  154112. }
  154113. cinfo->marker->next_restart_num = (cinfo->marker->next_restart_num + 1) & 7;
  154114. return TRUE;
  154115. }
  154116. GLOBAL(boolean)
  154117. jpeg_resync_to_restart (j_decompress_ptr cinfo, int desired)
  154118. {
  154119. int marker = cinfo->unread_marker;
  154120. int action = 1;
  154121. WARNMS2(cinfo, JWRN_MUST_RESYNC, marker, desired);
  154122. for (;;) {
  154123. if (marker < (int) M_SOF0)
  154124. action = 2; /* invalid marker */
  154125. else if (marker < (int) M_RST0 || marker > (int) M_RST7)
  154126. action = 3; /* valid non-restart marker */
  154127. else {
  154128. if (marker == ((int) M_RST0 + ((desired+1) & 7)) ||
  154129. marker == ((int) M_RST0 + ((desired+2) & 7)))
  154130. action = 3; /* one of the next two expected restarts */
  154131. else if (marker == ((int) M_RST0 + ((desired-1) & 7)) ||
  154132. marker == ((int) M_RST0 + ((desired-2) & 7)))
  154133. action = 2; /* a prior restart, so advance */
  154134. else
  154135. action = 1; /* desired restart or too far away */
  154136. }
  154137. TRACEMS2(cinfo, 4, JTRC_RECOVERY_ACTION, marker, action);
  154138. switch (action) {
  154139. case 1:
  154140. cinfo->unread_marker = 0;
  154141. return TRUE;
  154142. case 2:
  154143. if (! next_marker(cinfo))
  154144. return FALSE;
  154145. marker = cinfo->unread_marker;
  154146. break;
  154147. case 3:
  154148. return TRUE;
  154149. }
  154150. } /* end loop */
  154151. }
  154152. METHODDEF(void)
  154153. reset_marker_reader (j_decompress_ptr cinfo)
  154154. {
  154155. my_marker_ptr2 marker = (my_marker_ptr2) cinfo->marker;
  154156. cinfo->comp_info = NULL; /* until allocated by get_sof */
  154157. cinfo->input_scan_number = 0; /* no SOS seen yet */
  154158. cinfo->unread_marker = 0; /* no pending marker */
  154159. marker->pub.saw_SOI = FALSE; /* set internal state too */
  154160. marker->pub.saw_SOF = FALSE;
  154161. marker->pub.discarded_bytes = 0;
  154162. marker->cur_marker = NULL;
  154163. }
  154164. GLOBAL(void)
  154165. jinit_marker_reader (j_decompress_ptr cinfo)
  154166. {
  154167. my_marker_ptr2 marker;
  154168. int i;
  154169. marker = (my_marker_ptr2)
  154170. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
  154171. SIZEOF(my_marker_reader));
  154172. cinfo->marker = (struct jpeg_marker_reader *) marker;
  154173. marker->pub.reset_marker_reader = reset_marker_reader;
  154174. marker->pub.read_markers = read_markers;
  154175. marker->pub.read_restart_marker = read_restart_marker;
  154176. marker->process_COM = skip_variable;
  154177. marker->length_limit_COM = 0;
  154178. for (i = 0; i < 16; i++) {
  154179. marker->process_APPn[i] = skip_variable;
  154180. marker->length_limit_APPn[i] = 0;
  154181. }
  154182. marker->process_APPn[0] = get_interesting_appn;
  154183. marker->process_APPn[14] = get_interesting_appn;
  154184. reset_marker_reader(cinfo);
  154185. }
  154186. #ifdef SAVE_MARKERS_SUPPORTED
  154187. GLOBAL(void)
  154188. jpeg_save_markers (j_decompress_ptr cinfo, int marker_code,
  154189. unsigned int length_limit)
  154190. {
  154191. my_marker_ptr2 marker = (my_marker_ptr2) cinfo->marker;
  154192. long maxlength;
  154193. jpeg_marker_parser_method processor;
  154194. maxlength = cinfo->mem->max_alloc_chunk - SIZEOF(struct jpeg_marker_struct);
  154195. if (((long) length_limit) > maxlength)
  154196. length_limit = (unsigned int) maxlength;
  154197. if (length_limit) {
  154198. processor = save_marker;
  154199. if (marker_code == (int) M_APP0 && length_limit < APP0_DATA_LEN)
  154200. length_limit = APP0_DATA_LEN;
  154201. else if (marker_code == (int) M_APP14 && length_limit < APP14_DATA_LEN)
  154202. length_limit = APP14_DATA_LEN;
  154203. } else {
  154204. processor = skip_variable;
  154205. if (marker_code == (int) M_APP0 || marker_code == (int) M_APP14)
  154206. processor = get_interesting_appn;
  154207. }
  154208. if (marker_code == (int) M_COM) {
  154209. marker->process_COM = processor;
  154210. marker->length_limit_COM = length_limit;
  154211. } else if (marker_code >= (int) M_APP0 && marker_code <= (int) M_APP15) {
  154212. marker->process_APPn[marker_code - (int) M_APP0] = processor;
  154213. marker->length_limit_APPn[marker_code - (int) M_APP0] = length_limit;
  154214. } else
  154215. ERREXIT1(cinfo, JERR_UNKNOWN_MARKER, marker_code);
  154216. }
  154217. #endif /* SAVE_MARKERS_SUPPORTED */
  154218. GLOBAL(void)
  154219. jpeg_set_marker_processor (j_decompress_ptr cinfo, int marker_code,
  154220. jpeg_marker_parser_method routine)
  154221. {
  154222. my_marker_ptr2 marker = (my_marker_ptr2) cinfo->marker;
  154223. if (marker_code == (int) M_COM)
  154224. marker->process_COM = routine;
  154225. else if (marker_code >= (int) M_APP0 && marker_code <= (int) M_APP15)
  154226. marker->process_APPn[marker_code - (int) M_APP0] = routine;
  154227. else
  154228. ERREXIT1(cinfo, JERR_UNKNOWN_MARKER, marker_code);
  154229. }
  154230. /********* End of inlined file: jdmarker.c *********/
  154231. /********* Start of inlined file: jdmaster.c *********/
  154232. #define JPEG_INTERNALS
  154233. typedef struct {
  154234. struct jpeg_decomp_master pub; /* public fields */
  154235. int pass_number; /* # of passes completed */
  154236. boolean using_merged_upsample; /* TRUE if using merged upsample/cconvert */
  154237. struct jpeg_color_quantizer * quantizer_1pass;
  154238. struct jpeg_color_quantizer * quantizer_2pass;
  154239. } my_decomp_master;
  154240. typedef my_decomp_master * my_master_ptr6;
  154241. LOCAL(boolean)
  154242. use_merged_upsample (j_decompress_ptr cinfo)
  154243. {
  154244. #ifdef UPSAMPLE_MERGING_SUPPORTED
  154245. if (cinfo->do_fancy_upsampling || cinfo->CCIR601_sampling)
  154246. return FALSE;
  154247. if (cinfo->jpeg_color_space != JCS_YCbCr || cinfo->num_components != 3 ||
  154248. cinfo->out_color_space != JCS_RGB ||
  154249. cinfo->out_color_components != RGB_PIXELSIZE)
  154250. return FALSE;
  154251. if (cinfo->comp_info[0].h_samp_factor != 2 ||
  154252. cinfo->comp_info[1].h_samp_factor != 1 ||
  154253. cinfo->comp_info[2].h_samp_factor != 1 ||
  154254. cinfo->comp_info[0].v_samp_factor > 2 ||
  154255. cinfo->comp_info[1].v_samp_factor != 1 ||
  154256. cinfo->comp_info[2].v_samp_factor != 1)
  154257. return FALSE;
  154258. if (cinfo->comp_info[0].DCT_scaled_size != cinfo->min_DCT_scaled_size ||
  154259. cinfo->comp_info[1].DCT_scaled_size != cinfo->min_DCT_scaled_size ||
  154260. cinfo->comp_info[2].DCT_scaled_size != cinfo->min_DCT_scaled_size)
  154261. return FALSE;
  154262. return TRUE; /* by golly, it'll work... */
  154263. #else
  154264. return FALSE;
  154265. #endif
  154266. }
  154267. GLOBAL(void)
  154268. jpeg_calc_output_dimensions (j_decompress_ptr cinfo)
  154269. {
  154270. #ifdef IDCT_SCALING_SUPPORTED
  154271. int ci;
  154272. jpeg_component_info *compptr;
  154273. #endif
  154274. if (cinfo->global_state != DSTATE_READY)
  154275. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  154276. #ifdef IDCT_SCALING_SUPPORTED
  154277. if (cinfo->scale_num * 8 <= cinfo->scale_denom) {
  154278. cinfo->output_width = (JDIMENSION)
  154279. jdiv_round_up((long) cinfo->image_width, 8L);
  154280. cinfo->output_height = (JDIMENSION)
  154281. jdiv_round_up((long) cinfo->image_height, 8L);
  154282. cinfo->min_DCT_scaled_size = 1;
  154283. } else if (cinfo->scale_num * 4 <= cinfo->scale_denom) {
  154284. cinfo->output_width = (JDIMENSION)
  154285. jdiv_round_up((long) cinfo->image_width, 4L);
  154286. cinfo->output_height = (JDIMENSION)
  154287. jdiv_round_up((long) cinfo->image_height, 4L);
  154288. cinfo->min_DCT_scaled_size = 2;
  154289. } else if (cinfo->scale_num * 2 <= cinfo->scale_denom) {
  154290. cinfo->output_width = (JDIMENSION)
  154291. jdiv_round_up((long) cinfo->image_width, 2L);
  154292. cinfo->output_height = (JDIMENSION)
  154293. jdiv_round_up((long) cinfo->image_height, 2L);
  154294. cinfo->min_DCT_scaled_size = 4;
  154295. } else {
  154296. cinfo->output_width = cinfo->image_width;
  154297. cinfo->output_height = cinfo->image_height;
  154298. cinfo->min_DCT_scaled_size = DCTSIZE;
  154299. }
  154300. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  154301. ci++, compptr++) {
  154302. int ssize = cinfo->min_DCT_scaled_size;
  154303. while (ssize < DCTSIZE &&
  154304. (compptr->h_samp_factor * ssize * 2 <=
  154305. cinfo->max_h_samp_factor * cinfo->min_DCT_scaled_size) &&
  154306. (compptr->v_samp_factor * ssize * 2 <=
  154307. cinfo->max_v_samp_factor * cinfo->min_DCT_scaled_size)) {
  154308. ssize = ssize * 2;
  154309. }
  154310. compptr->DCT_scaled_size = ssize;
  154311. }
  154312. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  154313. ci++, compptr++) {
  154314. compptr->downsampled_width = (JDIMENSION)
  154315. jdiv_round_up((long) cinfo->image_width *
  154316. (long) (compptr->h_samp_factor * compptr->DCT_scaled_size),
  154317. (long) (cinfo->max_h_samp_factor * DCTSIZE));
  154318. compptr->downsampled_height = (JDIMENSION)
  154319. jdiv_round_up((long) cinfo->image_height *
  154320. (long) (compptr->v_samp_factor * compptr->DCT_scaled_size),
  154321. (long) (cinfo->max_v_samp_factor * DCTSIZE));
  154322. }
  154323. #else /* !IDCT_SCALING_SUPPORTED */
  154324. cinfo->output_width = cinfo->image_width;
  154325. cinfo->output_height = cinfo->image_height;
  154326. #endif /* IDCT_SCALING_SUPPORTED */
  154327. switch (cinfo->out_color_space) {
  154328. case JCS_GRAYSCALE:
  154329. cinfo->out_color_components = 1;
  154330. break;
  154331. case JCS_RGB:
  154332. #if RGB_PIXELSIZE != 3
  154333. cinfo->out_color_components = RGB_PIXELSIZE;
  154334. break;
  154335. #endif /* else share code with YCbCr */
  154336. case JCS_YCbCr:
  154337. cinfo->out_color_components = 3;
  154338. break;
  154339. case JCS_CMYK:
  154340. case JCS_YCCK:
  154341. cinfo->out_color_components = 4;
  154342. break;
  154343. default: /* else must be same colorspace as in file */
  154344. cinfo->out_color_components = cinfo->num_components;
  154345. break;
  154346. }
  154347. cinfo->output_components = (cinfo->quantize_colors ? 1 :
  154348. cinfo->out_color_components);
  154349. if (use_merged_upsample(cinfo))
  154350. cinfo->rec_outbuf_height = cinfo->max_v_samp_factor;
  154351. else
  154352. cinfo->rec_outbuf_height = 1;
  154353. }
  154354. LOCAL(void)
  154355. prepare_range_limit_table (j_decompress_ptr cinfo)
  154356. {
  154357. JSAMPLE * table;
  154358. int i;
  154359. table = (JSAMPLE *)
  154360. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  154361. (5 * (MAXJSAMPLE+1) + CENTERJSAMPLE) * SIZEOF(JSAMPLE));
  154362. table += (MAXJSAMPLE+1); /* allow negative subscripts of simple table */
  154363. cinfo->sample_range_limit = table;
  154364. MEMZERO(table - (MAXJSAMPLE+1), (MAXJSAMPLE+1) * SIZEOF(JSAMPLE));
  154365. for (i = 0; i <= MAXJSAMPLE; i++)
  154366. table[i] = (JSAMPLE) i;
  154367. table += CENTERJSAMPLE; /* Point to where post-IDCT table starts */
  154368. for (i = CENTERJSAMPLE; i < 2*(MAXJSAMPLE+1); i++)
  154369. table[i] = MAXJSAMPLE;
  154370. MEMZERO(table + (2 * (MAXJSAMPLE+1)),
  154371. (2 * (MAXJSAMPLE+1) - CENTERJSAMPLE) * SIZEOF(JSAMPLE));
  154372. MEMCOPY(table + (4 * (MAXJSAMPLE+1) - CENTERJSAMPLE),
  154373. cinfo->sample_range_limit, CENTERJSAMPLE * SIZEOF(JSAMPLE));
  154374. }
  154375. LOCAL(void)
  154376. master_selection (j_decompress_ptr cinfo)
  154377. {
  154378. my_master_ptr6 master = (my_master_ptr6) cinfo->master;
  154379. boolean use_c_buffer;
  154380. long samplesperrow;
  154381. JDIMENSION jd_samplesperrow;
  154382. jpeg_calc_output_dimensions(cinfo);
  154383. prepare_range_limit_table(cinfo);
  154384. samplesperrow = (long) cinfo->output_width * (long) cinfo->out_color_components;
  154385. jd_samplesperrow = (JDIMENSION) samplesperrow;
  154386. if ((long) jd_samplesperrow != samplesperrow)
  154387. ERREXIT(cinfo, JERR_WIDTH_OVERFLOW);
  154388. master->pass_number = 0;
  154389. master->using_merged_upsample = use_merged_upsample(cinfo);
  154390. master->quantizer_1pass = NULL;
  154391. master->quantizer_2pass = NULL;
  154392. if (! cinfo->quantize_colors || ! cinfo->buffered_image) {
  154393. cinfo->enable_1pass_quant = FALSE;
  154394. cinfo->enable_external_quant = FALSE;
  154395. cinfo->enable_2pass_quant = FALSE;
  154396. }
  154397. if (cinfo->quantize_colors) {
  154398. if (cinfo->raw_data_out)
  154399. ERREXIT(cinfo, JERR_NOTIMPL);
  154400. if (cinfo->out_color_components != 3) {
  154401. cinfo->enable_1pass_quant = TRUE;
  154402. cinfo->enable_external_quant = FALSE;
  154403. cinfo->enable_2pass_quant = FALSE;
  154404. cinfo->colormap = NULL;
  154405. } else if (cinfo->colormap != NULL) {
  154406. cinfo->enable_external_quant = TRUE;
  154407. } else if (cinfo->two_pass_quantize) {
  154408. cinfo->enable_2pass_quant = TRUE;
  154409. } else {
  154410. cinfo->enable_1pass_quant = TRUE;
  154411. }
  154412. if (cinfo->enable_1pass_quant) {
  154413. #ifdef QUANT_1PASS_SUPPORTED
  154414. jinit_1pass_quantizer(cinfo);
  154415. master->quantizer_1pass = cinfo->cquantize;
  154416. #else
  154417. ERREXIT(cinfo, JERR_NOT_COMPILED);
  154418. #endif
  154419. }
  154420. if (cinfo->enable_2pass_quant || cinfo->enable_external_quant) {
  154421. #ifdef QUANT_2PASS_SUPPORTED
  154422. jinit_2pass_quantizer(cinfo);
  154423. master->quantizer_2pass = cinfo->cquantize;
  154424. #else
  154425. ERREXIT(cinfo, JERR_NOT_COMPILED);
  154426. #endif
  154427. }
  154428. }
  154429. if (! cinfo->raw_data_out) {
  154430. if (master->using_merged_upsample) {
  154431. #ifdef UPSAMPLE_MERGING_SUPPORTED
  154432. jinit_merged_upsampler(cinfo); /* does color conversion too */
  154433. #else
  154434. ERREXIT(cinfo, JERR_NOT_COMPILED);
  154435. #endif
  154436. } else {
  154437. jinit_color_deconverter(cinfo);
  154438. jinit_upsampler(cinfo);
  154439. }
  154440. jinit_d_post_controller(cinfo, cinfo->enable_2pass_quant);
  154441. }
  154442. jinit_inverse_dct(cinfo);
  154443. if (cinfo->arith_code) {
  154444. ERREXIT(cinfo, JERR_ARITH_NOTIMPL);
  154445. } else {
  154446. if (cinfo->progressive_mode) {
  154447. #ifdef D_PROGRESSIVE_SUPPORTED
  154448. jinit_phuff_decoder(cinfo);
  154449. #else
  154450. ERREXIT(cinfo, JERR_NOT_COMPILED);
  154451. #endif
  154452. } else
  154453. jinit_huff_decoder(cinfo);
  154454. }
  154455. use_c_buffer = cinfo->inputctl->has_multiple_scans || cinfo->buffered_image;
  154456. jinit_d_coef_controller(cinfo, use_c_buffer);
  154457. if (! cinfo->raw_data_out)
  154458. jinit_d_main_controller(cinfo, FALSE /* never need full buffer here */);
  154459. (*cinfo->mem->realize_virt_arrays) ((j_common_ptr) cinfo);
  154460. (*cinfo->inputctl->start_input_pass) (cinfo);
  154461. #ifdef D_MULTISCAN_FILES_SUPPORTED
  154462. if (cinfo->progress != NULL && ! cinfo->buffered_image &&
  154463. cinfo->inputctl->has_multiple_scans) {
  154464. int nscans;
  154465. if (cinfo->progressive_mode) {
  154466. nscans = 2 + 3 * cinfo->num_components;
  154467. } else {
  154468. nscans = cinfo->num_components;
  154469. }
  154470. cinfo->progress->pass_counter = 0L;
  154471. cinfo->progress->pass_limit = (long) cinfo->total_iMCU_rows * nscans;
  154472. cinfo->progress->completed_passes = 0;
  154473. cinfo->progress->total_passes = (cinfo->enable_2pass_quant ? 3 : 2);
  154474. master->pass_number++;
  154475. }
  154476. #endif /* D_MULTISCAN_FILES_SUPPORTED */
  154477. }
  154478. METHODDEF(void)
  154479. prepare_for_output_pass (j_decompress_ptr cinfo)
  154480. {
  154481. my_master_ptr6 master = (my_master_ptr6) cinfo->master;
  154482. if (master->pub.is_dummy_pass) {
  154483. #ifdef QUANT_2PASS_SUPPORTED
  154484. master->pub.is_dummy_pass = FALSE;
  154485. (*cinfo->cquantize->start_pass) (cinfo, FALSE);
  154486. (*cinfo->post->start_pass) (cinfo, JBUF_CRANK_DEST);
  154487. (*cinfo->main->start_pass) (cinfo, JBUF_CRANK_DEST);
  154488. #else
  154489. ERREXIT(cinfo, JERR_NOT_COMPILED);
  154490. #endif /* QUANT_2PASS_SUPPORTED */
  154491. } else {
  154492. if (cinfo->quantize_colors && cinfo->colormap == NULL) {
  154493. if (cinfo->two_pass_quantize && cinfo->enable_2pass_quant) {
  154494. cinfo->cquantize = master->quantizer_2pass;
  154495. master->pub.is_dummy_pass = TRUE;
  154496. } else if (cinfo->enable_1pass_quant) {
  154497. cinfo->cquantize = master->quantizer_1pass;
  154498. } else {
  154499. ERREXIT(cinfo, JERR_MODE_CHANGE);
  154500. }
  154501. }
  154502. (*cinfo->idct->start_pass) (cinfo);
  154503. (*cinfo->coef->start_output_pass) (cinfo);
  154504. if (! cinfo->raw_data_out) {
  154505. if (! master->using_merged_upsample)
  154506. (*cinfo->cconvert->start_pass) (cinfo);
  154507. (*cinfo->upsample->start_pass) (cinfo);
  154508. if (cinfo->quantize_colors)
  154509. (*cinfo->cquantize->start_pass) (cinfo, master->pub.is_dummy_pass);
  154510. (*cinfo->post->start_pass) (cinfo,
  154511. (master->pub.is_dummy_pass ? JBUF_SAVE_AND_PASS : JBUF_PASS_THRU));
  154512. (*cinfo->main->start_pass) (cinfo, JBUF_PASS_THRU);
  154513. }
  154514. }
  154515. if (cinfo->progress != NULL) {
  154516. cinfo->progress->completed_passes = master->pass_number;
  154517. cinfo->progress->total_passes = master->pass_number +
  154518. (master->pub.is_dummy_pass ? 2 : 1);
  154519. if (cinfo->buffered_image && ! cinfo->inputctl->eoi_reached) {
  154520. cinfo->progress->total_passes += (cinfo->enable_2pass_quant ? 2 : 1);
  154521. }
  154522. }
  154523. }
  154524. METHODDEF(void)
  154525. finish_output_pass (j_decompress_ptr cinfo)
  154526. {
  154527. my_master_ptr6 master = (my_master_ptr6) cinfo->master;
  154528. if (cinfo->quantize_colors)
  154529. (*cinfo->cquantize->finish_pass) (cinfo);
  154530. master->pass_number++;
  154531. }
  154532. #ifdef D_MULTISCAN_FILES_SUPPORTED
  154533. GLOBAL(void)
  154534. jpeg_new_colormap (j_decompress_ptr cinfo)
  154535. {
  154536. my_master_ptr6 master = (my_master_ptr6) cinfo->master;
  154537. if (cinfo->global_state != DSTATE_BUFIMAGE)
  154538. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  154539. if (cinfo->quantize_colors && cinfo->enable_external_quant &&
  154540. cinfo->colormap != NULL) {
  154541. cinfo->cquantize = master->quantizer_2pass;
  154542. (*cinfo->cquantize->new_color_map) (cinfo);
  154543. master->pub.is_dummy_pass = FALSE; /* just in case */
  154544. } else
  154545. ERREXIT(cinfo, JERR_MODE_CHANGE);
  154546. }
  154547. #endif /* D_MULTISCAN_FILES_SUPPORTED */
  154548. GLOBAL(void)
  154549. jinit_master_decompress (j_decompress_ptr cinfo)
  154550. {
  154551. my_master_ptr6 master;
  154552. master = (my_master_ptr6)
  154553. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  154554. SIZEOF(my_decomp_master));
  154555. cinfo->master = (struct jpeg_decomp_master *) master;
  154556. master->pub.prepare_for_output_pass = prepare_for_output_pass;
  154557. master->pub.finish_output_pass = finish_output_pass;
  154558. master->pub.is_dummy_pass = FALSE;
  154559. master_selection(cinfo);
  154560. }
  154561. /********* End of inlined file: jdmaster.c *********/
  154562. #undef FIX
  154563. /********* Start of inlined file: jdmerge.c *********/
  154564. #define JPEG_INTERNALS
  154565. #ifdef UPSAMPLE_MERGING_SUPPORTED
  154566. typedef struct {
  154567. struct jpeg_upsampler pub; /* public fields */
  154568. JMETHOD(void, upmethod, (j_decompress_ptr cinfo,
  154569. JSAMPIMAGE input_buf, JDIMENSION in_row_group_ctr,
  154570. JSAMPARRAY output_buf));
  154571. int * Cr_r_tab; /* => table for Cr to R conversion */
  154572. int * Cb_b_tab; /* => table for Cb to B conversion */
  154573. INT32 * Cr_g_tab; /* => table for Cr to G conversion */
  154574. INT32 * Cb_g_tab; /* => table for Cb to G conversion */
  154575. JSAMPROW spare_row;
  154576. boolean spare_full; /* T if spare buffer is occupied */
  154577. JDIMENSION out_row_width; /* samples per output row */
  154578. JDIMENSION rows_to_go; /* counts rows remaining in image */
  154579. } my_upsampler;
  154580. typedef my_upsampler * my_upsample_ptr;
  154581. #define SCALEBITS 16 /* speediest right-shift on some machines */
  154582. #define ONE_HALF ((INT32) 1 << (SCALEBITS-1))
  154583. #define FIX(x) ((INT32) ((x) * (1L<<SCALEBITS) + 0.5))
  154584. LOCAL(void)
  154585. build_ycc_rgb_table2 (j_decompress_ptr cinfo)
  154586. {
  154587. my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample;
  154588. int i;
  154589. INT32 x;
  154590. SHIFT_TEMPS
  154591. upsample->Cr_r_tab = (int *)
  154592. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  154593. (MAXJSAMPLE+1) * SIZEOF(int));
  154594. upsample->Cb_b_tab = (int *)
  154595. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  154596. (MAXJSAMPLE+1) * SIZEOF(int));
  154597. upsample->Cr_g_tab = (INT32 *)
  154598. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  154599. (MAXJSAMPLE+1) * SIZEOF(INT32));
  154600. upsample->Cb_g_tab = (INT32 *)
  154601. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  154602. (MAXJSAMPLE+1) * SIZEOF(INT32));
  154603. for (i = 0, x = -CENTERJSAMPLE; i <= MAXJSAMPLE; i++, x++) {
  154604. upsample->Cr_r_tab[i] = (int)
  154605. RIGHT_SHIFT(FIX(1.40200) * x + ONE_HALF, SCALEBITS);
  154606. upsample->Cb_b_tab[i] = (int)
  154607. RIGHT_SHIFT(FIX(1.77200) * x + ONE_HALF, SCALEBITS);
  154608. upsample->Cr_g_tab[i] = (- FIX(0.71414)) * x;
  154609. upsample->Cb_g_tab[i] = (- FIX(0.34414)) * x + ONE_HALF;
  154610. }
  154611. }
  154612. METHODDEF(void)
  154613. start_pass_merged_upsample (j_decompress_ptr cinfo)
  154614. {
  154615. my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample;
  154616. upsample->spare_full = FALSE;
  154617. upsample->rows_to_go = cinfo->output_height;
  154618. }
  154619. METHODDEF(void)
  154620. merged_2v_upsample (j_decompress_ptr cinfo,
  154621. JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,
  154622. JDIMENSION in_row_groups_avail,
  154623. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  154624. JDIMENSION out_rows_avail)
  154625. {
  154626. my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample;
  154627. JSAMPROW work_ptrs[2];
  154628. JDIMENSION num_rows; /* number of rows returned to caller */
  154629. if (upsample->spare_full) {
  154630. jcopy_sample_rows(& upsample->spare_row, 0, output_buf + *out_row_ctr, 0,
  154631. 1, upsample->out_row_width);
  154632. num_rows = 1;
  154633. upsample->spare_full = FALSE;
  154634. } else {
  154635. num_rows = 2;
  154636. if (num_rows > upsample->rows_to_go)
  154637. num_rows = upsample->rows_to_go;
  154638. out_rows_avail -= *out_row_ctr;
  154639. if (num_rows > out_rows_avail)
  154640. num_rows = out_rows_avail;
  154641. work_ptrs[0] = output_buf[*out_row_ctr];
  154642. if (num_rows > 1) {
  154643. work_ptrs[1] = output_buf[*out_row_ctr + 1];
  154644. } else {
  154645. work_ptrs[1] = upsample->spare_row;
  154646. upsample->spare_full = TRUE;
  154647. }
  154648. (*upsample->upmethod) (cinfo, input_buf, *in_row_group_ctr, work_ptrs);
  154649. }
  154650. *out_row_ctr += num_rows;
  154651. upsample->rows_to_go -= num_rows;
  154652. if (! upsample->spare_full)
  154653. (*in_row_group_ctr)++;
  154654. }
  154655. METHODDEF(void)
  154656. merged_1v_upsample (j_decompress_ptr cinfo,
  154657. JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,
  154658. JDIMENSION in_row_groups_avail,
  154659. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  154660. JDIMENSION out_rows_avail)
  154661. {
  154662. my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample;
  154663. (*upsample->upmethod) (cinfo, input_buf, *in_row_group_ctr,
  154664. output_buf + *out_row_ctr);
  154665. (*out_row_ctr)++;
  154666. (*in_row_group_ctr)++;
  154667. }
  154668. METHODDEF(void)
  154669. h2v1_merged_upsample (j_decompress_ptr cinfo,
  154670. JSAMPIMAGE input_buf, JDIMENSION in_row_group_ctr,
  154671. JSAMPARRAY output_buf)
  154672. {
  154673. my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample;
  154674. register int y, cred, cgreen, cblue;
  154675. int cb, cr;
  154676. register JSAMPROW outptr;
  154677. JSAMPROW inptr0, inptr1, inptr2;
  154678. JDIMENSION col;
  154679. register JSAMPLE * range_limit = cinfo->sample_range_limit;
  154680. int * Crrtab = upsample->Cr_r_tab;
  154681. int * Cbbtab = upsample->Cb_b_tab;
  154682. INT32 * Crgtab = upsample->Cr_g_tab;
  154683. INT32 * Cbgtab = upsample->Cb_g_tab;
  154684. SHIFT_TEMPS
  154685. inptr0 = input_buf[0][in_row_group_ctr];
  154686. inptr1 = input_buf[1][in_row_group_ctr];
  154687. inptr2 = input_buf[2][in_row_group_ctr];
  154688. outptr = output_buf[0];
  154689. for (col = cinfo->output_width >> 1; col > 0; col--) {
  154690. cb = GETJSAMPLE(*inptr1++);
  154691. cr = GETJSAMPLE(*inptr2++);
  154692. cred = Crrtab[cr];
  154693. cgreen = (int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS);
  154694. cblue = Cbbtab[cb];
  154695. y = GETJSAMPLE(*inptr0++);
  154696. outptr[RGB_RED] = range_limit[y + cred];
  154697. outptr[RGB_GREEN] = range_limit[y + cgreen];
  154698. outptr[RGB_BLUE] = range_limit[y + cblue];
  154699. outptr += RGB_PIXELSIZE;
  154700. y = GETJSAMPLE(*inptr0++);
  154701. outptr[RGB_RED] = range_limit[y + cred];
  154702. outptr[RGB_GREEN] = range_limit[y + cgreen];
  154703. outptr[RGB_BLUE] = range_limit[y + cblue];
  154704. outptr += RGB_PIXELSIZE;
  154705. }
  154706. if (cinfo->output_width & 1) {
  154707. cb = GETJSAMPLE(*inptr1);
  154708. cr = GETJSAMPLE(*inptr2);
  154709. cred = Crrtab[cr];
  154710. cgreen = (int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS);
  154711. cblue = Cbbtab[cb];
  154712. y = GETJSAMPLE(*inptr0);
  154713. outptr[RGB_RED] = range_limit[y + cred];
  154714. outptr[RGB_GREEN] = range_limit[y + cgreen];
  154715. outptr[RGB_BLUE] = range_limit[y + cblue];
  154716. }
  154717. }
  154718. METHODDEF(void)
  154719. h2v2_merged_upsample (j_decompress_ptr cinfo,
  154720. JSAMPIMAGE input_buf, JDIMENSION in_row_group_ctr,
  154721. JSAMPARRAY output_buf)
  154722. {
  154723. my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample;
  154724. register int y, cred, cgreen, cblue;
  154725. int cb, cr;
  154726. register JSAMPROW outptr0, outptr1;
  154727. JSAMPROW inptr00, inptr01, inptr1, inptr2;
  154728. JDIMENSION col;
  154729. register JSAMPLE * range_limit = cinfo->sample_range_limit;
  154730. int * Crrtab = upsample->Cr_r_tab;
  154731. int * Cbbtab = upsample->Cb_b_tab;
  154732. INT32 * Crgtab = upsample->Cr_g_tab;
  154733. INT32 * Cbgtab = upsample->Cb_g_tab;
  154734. SHIFT_TEMPS
  154735. inptr00 = input_buf[0][in_row_group_ctr*2];
  154736. inptr01 = input_buf[0][in_row_group_ctr*2 + 1];
  154737. inptr1 = input_buf[1][in_row_group_ctr];
  154738. inptr2 = input_buf[2][in_row_group_ctr];
  154739. outptr0 = output_buf[0];
  154740. outptr1 = output_buf[1];
  154741. for (col = cinfo->output_width >> 1; col > 0; col--) {
  154742. cb = GETJSAMPLE(*inptr1++);
  154743. cr = GETJSAMPLE(*inptr2++);
  154744. cred = Crrtab[cr];
  154745. cgreen = (int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS);
  154746. cblue = Cbbtab[cb];
  154747. y = GETJSAMPLE(*inptr00++);
  154748. outptr0[RGB_RED] = range_limit[y + cred];
  154749. outptr0[RGB_GREEN] = range_limit[y + cgreen];
  154750. outptr0[RGB_BLUE] = range_limit[y + cblue];
  154751. outptr0 += RGB_PIXELSIZE;
  154752. y = GETJSAMPLE(*inptr00++);
  154753. outptr0[RGB_RED] = range_limit[y + cred];
  154754. outptr0[RGB_GREEN] = range_limit[y + cgreen];
  154755. outptr0[RGB_BLUE] = range_limit[y + cblue];
  154756. outptr0 += RGB_PIXELSIZE;
  154757. y = GETJSAMPLE(*inptr01++);
  154758. outptr1[RGB_RED] = range_limit[y + cred];
  154759. outptr1[RGB_GREEN] = range_limit[y + cgreen];
  154760. outptr1[RGB_BLUE] = range_limit[y + cblue];
  154761. outptr1 += RGB_PIXELSIZE;
  154762. y = GETJSAMPLE(*inptr01++);
  154763. outptr1[RGB_RED] = range_limit[y + cred];
  154764. outptr1[RGB_GREEN] = range_limit[y + cgreen];
  154765. outptr1[RGB_BLUE] = range_limit[y + cblue];
  154766. outptr1 += RGB_PIXELSIZE;
  154767. }
  154768. if (cinfo->output_width & 1) {
  154769. cb = GETJSAMPLE(*inptr1);
  154770. cr = GETJSAMPLE(*inptr2);
  154771. cred = Crrtab[cr];
  154772. cgreen = (int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS);
  154773. cblue = Cbbtab[cb];
  154774. y = GETJSAMPLE(*inptr00);
  154775. outptr0[RGB_RED] = range_limit[y + cred];
  154776. outptr0[RGB_GREEN] = range_limit[y + cgreen];
  154777. outptr0[RGB_BLUE] = range_limit[y + cblue];
  154778. y = GETJSAMPLE(*inptr01);
  154779. outptr1[RGB_RED] = range_limit[y + cred];
  154780. outptr1[RGB_GREEN] = range_limit[y + cgreen];
  154781. outptr1[RGB_BLUE] = range_limit[y + cblue];
  154782. }
  154783. }
  154784. GLOBAL(void)
  154785. jinit_merged_upsampler (j_decompress_ptr cinfo)
  154786. {
  154787. my_upsample_ptr upsample;
  154788. upsample = (my_upsample_ptr)
  154789. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  154790. SIZEOF(my_upsampler));
  154791. cinfo->upsample = (struct jpeg_upsampler *) upsample;
  154792. upsample->pub.start_pass = start_pass_merged_upsample;
  154793. upsample->pub.need_context_rows = FALSE;
  154794. upsample->out_row_width = cinfo->output_width * cinfo->out_color_components;
  154795. if (cinfo->max_v_samp_factor == 2) {
  154796. upsample->pub.upsample = merged_2v_upsample;
  154797. upsample->upmethod = h2v2_merged_upsample;
  154798. upsample->spare_row = (JSAMPROW)
  154799. (*cinfo->mem->alloc_large) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  154800. (size_t) (upsample->out_row_width * SIZEOF(JSAMPLE)));
  154801. } else {
  154802. upsample->pub.upsample = merged_1v_upsample;
  154803. upsample->upmethod = h2v1_merged_upsample;
  154804. upsample->spare_row = NULL;
  154805. }
  154806. build_ycc_rgb_table2(cinfo);
  154807. }
  154808. #endif /* UPSAMPLE_MERGING_SUPPORTED */
  154809. /********* End of inlined file: jdmerge.c *********/
  154810. #undef ASSIGN_STATE
  154811. /********* Start of inlined file: jdphuff.c *********/
  154812. #define JPEG_INTERNALS
  154813. #ifdef D_PROGRESSIVE_SUPPORTED
  154814. typedef struct {
  154815. unsigned int EOBRUN; /* remaining EOBs in EOBRUN */
  154816. int last_dc_val[MAX_COMPS_IN_SCAN]; /* last DC coef for each component */
  154817. } savable_state3;
  154818. #ifndef NO_STRUCT_ASSIGN
  154819. #define ASSIGN_STATE(dest,src) ((dest) = (src))
  154820. #else
  154821. #if MAX_COMPS_IN_SCAN == 4
  154822. #define ASSIGN_STATE(dest,src) \
  154823. ((dest).EOBRUN = (src).EOBRUN, \
  154824. (dest).last_dc_val[0] = (src).last_dc_val[0], \
  154825. (dest).last_dc_val[1] = (src).last_dc_val[1], \
  154826. (dest).last_dc_val[2] = (src).last_dc_val[2], \
  154827. (dest).last_dc_val[3] = (src).last_dc_val[3])
  154828. #endif
  154829. #endif
  154830. typedef struct {
  154831. struct jpeg_entropy_decoder pub; /* public fields */
  154832. bitread_perm_state bitstate; /* Bit buffer at start of MCU */
  154833. savable_state3 saved; /* Other state at start of MCU */
  154834. unsigned int restarts_to_go; /* MCUs left in this restart interval */
  154835. d_derived_tbl * derived_tbls[NUM_HUFF_TBLS];
  154836. d_derived_tbl * ac_derived_tbl; /* active table during an AC scan */
  154837. } phuff_entropy_decoder;
  154838. typedef phuff_entropy_decoder * phuff_entropy_ptr2;
  154839. METHODDEF(boolean) decode_mcu_DC_first JPP((j_decompress_ptr cinfo,
  154840. JBLOCKROW *MCU_data));
  154841. METHODDEF(boolean) decode_mcu_AC_first JPP((j_decompress_ptr cinfo,
  154842. JBLOCKROW *MCU_data));
  154843. METHODDEF(boolean) decode_mcu_DC_refine JPP((j_decompress_ptr cinfo,
  154844. JBLOCKROW *MCU_data));
  154845. METHODDEF(boolean) decode_mcu_AC_refine JPP((j_decompress_ptr cinfo,
  154846. JBLOCKROW *MCU_data));
  154847. METHODDEF(void)
  154848. start_pass_phuff_decoder (j_decompress_ptr cinfo)
  154849. {
  154850. phuff_entropy_ptr2 entropy = (phuff_entropy_ptr2) cinfo->entropy;
  154851. boolean is_DC_band, bad;
  154852. int ci, coefi, tbl;
  154853. int *coef_bit_ptr;
  154854. jpeg_component_info * compptr;
  154855. is_DC_band = (cinfo->Ss == 0);
  154856. bad = FALSE;
  154857. if (is_DC_band) {
  154858. if (cinfo->Se != 0)
  154859. bad = TRUE;
  154860. } else {
  154861. if (cinfo->Ss > cinfo->Se || cinfo->Se >= DCTSIZE2)
  154862. bad = TRUE;
  154863. if (cinfo->comps_in_scan != 1)
  154864. bad = TRUE;
  154865. }
  154866. if (cinfo->Ah != 0) {
  154867. if (cinfo->Al != cinfo->Ah-1)
  154868. bad = TRUE;
  154869. }
  154870. if (cinfo->Al > 13) /* need not check for < 0 */
  154871. bad = TRUE;
  154872. if (bad)
  154873. ERREXIT4(cinfo, JERR_BAD_PROGRESSION,
  154874. cinfo->Ss, cinfo->Se, cinfo->Ah, cinfo->Al);
  154875. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  154876. int cindex = cinfo->cur_comp_info[ci]->component_index;
  154877. coef_bit_ptr = & cinfo->coef_bits[cindex][0];
  154878. if (!is_DC_band && coef_bit_ptr[0] < 0) /* AC without prior DC scan */
  154879. WARNMS2(cinfo, JWRN_BOGUS_PROGRESSION, cindex, 0);
  154880. for (coefi = cinfo->Ss; coefi <= cinfo->Se; coefi++) {
  154881. int expected = (coef_bit_ptr[coefi] < 0) ? 0 : coef_bit_ptr[coefi];
  154882. if (cinfo->Ah != expected)
  154883. WARNMS2(cinfo, JWRN_BOGUS_PROGRESSION, cindex, coefi);
  154884. coef_bit_ptr[coefi] = cinfo->Al;
  154885. }
  154886. }
  154887. if (cinfo->Ah == 0) {
  154888. if (is_DC_band)
  154889. entropy->pub.decode_mcu = decode_mcu_DC_first;
  154890. else
  154891. entropy->pub.decode_mcu = decode_mcu_AC_first;
  154892. } else {
  154893. if (is_DC_band)
  154894. entropy->pub.decode_mcu = decode_mcu_DC_refine;
  154895. else
  154896. entropy->pub.decode_mcu = decode_mcu_AC_refine;
  154897. }
  154898. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  154899. compptr = cinfo->cur_comp_info[ci];
  154900. if (is_DC_band) {
  154901. if (cinfo->Ah == 0) { /* DC refinement needs no table */
  154902. tbl = compptr->dc_tbl_no;
  154903. jpeg_make_d_derived_tbl(cinfo, TRUE, tbl,
  154904. & entropy->derived_tbls[tbl]);
  154905. }
  154906. } else {
  154907. tbl = compptr->ac_tbl_no;
  154908. jpeg_make_d_derived_tbl(cinfo, FALSE, tbl,
  154909. & entropy->derived_tbls[tbl]);
  154910. entropy->ac_derived_tbl = entropy->derived_tbls[tbl];
  154911. }
  154912. entropy->saved.last_dc_val[ci] = 0;
  154913. }
  154914. entropy->bitstate.bits_left = 0;
  154915. entropy->bitstate.get_buffer = 0; /* unnecessary, but keeps Purify quiet */
  154916. entropy->pub.insufficient_data = FALSE;
  154917. entropy->saved.EOBRUN = 0;
  154918. entropy->restarts_to_go = cinfo->restart_interval;
  154919. }
  154920. LOCAL(boolean)
  154921. process_restartp (j_decompress_ptr cinfo)
  154922. {
  154923. phuff_entropy_ptr2 entropy = (phuff_entropy_ptr2) cinfo->entropy;
  154924. int ci;
  154925. cinfo->marker->discarded_bytes += entropy->bitstate.bits_left / 8;
  154926. entropy->bitstate.bits_left = 0;
  154927. if (! (*cinfo->marker->read_restart_marker) (cinfo))
  154928. return FALSE;
  154929. for (ci = 0; ci < cinfo->comps_in_scan; ci++)
  154930. entropy->saved.last_dc_val[ci] = 0;
  154931. entropy->saved.EOBRUN = 0;
  154932. entropy->restarts_to_go = cinfo->restart_interval;
  154933. if (cinfo->unread_marker == 0)
  154934. entropy->pub.insufficient_data = FALSE;
  154935. return TRUE;
  154936. }
  154937. METHODDEF(boolean)
  154938. decode_mcu_DC_first (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
  154939. {
  154940. phuff_entropy_ptr2 entropy = (phuff_entropy_ptr2) cinfo->entropy;
  154941. int Al = cinfo->Al;
  154942. register int s, r;
  154943. int blkn, ci;
  154944. JBLOCKROW block;
  154945. BITREAD_STATE_VARS;
  154946. savable_state3 state;
  154947. d_derived_tbl * tbl;
  154948. jpeg_component_info * compptr;
  154949. if (cinfo->restart_interval) {
  154950. if (entropy->restarts_to_go == 0)
  154951. if (! process_restartp(cinfo))
  154952. return FALSE;
  154953. }
  154954. if (! entropy->pub.insufficient_data) {
  154955. BITREAD_LOAD_STATE(cinfo,entropy->bitstate);
  154956. ASSIGN_STATE(state, entropy->saved);
  154957. for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
  154958. block = MCU_data[blkn];
  154959. ci = cinfo->MCU_membership[blkn];
  154960. compptr = cinfo->cur_comp_info[ci];
  154961. tbl = entropy->derived_tbls[compptr->dc_tbl_no];
  154962. HUFF_DECODE(s, br_state, tbl, return FALSE, label1);
  154963. if (s) {
  154964. CHECK_BIT_BUFFER(br_state, s, return FALSE);
  154965. r = GET_BITS(s);
  154966. s = HUFF_EXTEND(r, s);
  154967. }
  154968. s += state.last_dc_val[ci];
  154969. state.last_dc_val[ci] = s;
  154970. (*block)[0] = (JCOEF) (s << Al);
  154971. }
  154972. BITREAD_SAVE_STATE(cinfo,entropy->bitstate);
  154973. ASSIGN_STATE(entropy->saved, state);
  154974. }
  154975. entropy->restarts_to_go--;
  154976. return TRUE;
  154977. }
  154978. METHODDEF(boolean)
  154979. decode_mcu_AC_first (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
  154980. {
  154981. phuff_entropy_ptr2 entropy = (phuff_entropy_ptr2) cinfo->entropy;
  154982. int Se = cinfo->Se;
  154983. int Al = cinfo->Al;
  154984. register int s, k, r;
  154985. unsigned int EOBRUN;
  154986. JBLOCKROW block;
  154987. BITREAD_STATE_VARS;
  154988. d_derived_tbl * tbl;
  154989. if (cinfo->restart_interval) {
  154990. if (entropy->restarts_to_go == 0)
  154991. if (! process_restartp(cinfo))
  154992. return FALSE;
  154993. }
  154994. if (! entropy->pub.insufficient_data) {
  154995. EOBRUN = entropy->saved.EOBRUN; /* only part of saved state we need */
  154996. if (EOBRUN > 0) /* if it's a band of zeroes... */
  154997. EOBRUN--; /* ...process it now (we do nothing) */
  154998. else {
  154999. BITREAD_LOAD_STATE(cinfo,entropy->bitstate);
  155000. block = MCU_data[0];
  155001. tbl = entropy->ac_derived_tbl;
  155002. for (k = cinfo->Ss; k <= Se; k++) {
  155003. HUFF_DECODE(s, br_state, tbl, return FALSE, label2);
  155004. r = s >> 4;
  155005. s &= 15;
  155006. if (s) {
  155007. k += r;
  155008. CHECK_BIT_BUFFER(br_state, s, return FALSE);
  155009. r = GET_BITS(s);
  155010. s = HUFF_EXTEND(r, s);
  155011. (*block)[jpeg_natural_order[k]] = (JCOEF) (s << Al);
  155012. } else {
  155013. if (r == 15) { /* ZRL */
  155014. k += 15; /* skip 15 zeroes in band */
  155015. } else { /* EOBr, run length is 2^r + appended bits */
  155016. EOBRUN = 1 << r;
  155017. if (r) { /* EOBr, r > 0 */
  155018. CHECK_BIT_BUFFER(br_state, r, return FALSE);
  155019. r = GET_BITS(r);
  155020. EOBRUN += r;
  155021. }
  155022. EOBRUN--; /* this band is processed at this moment */
  155023. break; /* force end-of-band */
  155024. }
  155025. }
  155026. }
  155027. BITREAD_SAVE_STATE(cinfo,entropy->bitstate);
  155028. }
  155029. entropy->saved.EOBRUN = EOBRUN; /* only part of saved state we need */
  155030. }
  155031. entropy->restarts_to_go--;
  155032. return TRUE;
  155033. }
  155034. METHODDEF(boolean)
  155035. decode_mcu_DC_refine (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
  155036. {
  155037. phuff_entropy_ptr2 entropy = (phuff_entropy_ptr2) cinfo->entropy;
  155038. int p1 = 1 << cinfo->Al; /* 1 in the bit position being coded */
  155039. int blkn;
  155040. JBLOCKROW block;
  155041. BITREAD_STATE_VARS;
  155042. if (cinfo->restart_interval) {
  155043. if (entropy->restarts_to_go == 0)
  155044. if (! process_restartp(cinfo))
  155045. return FALSE;
  155046. }
  155047. BITREAD_LOAD_STATE(cinfo,entropy->bitstate);
  155048. for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
  155049. block = MCU_data[blkn];
  155050. CHECK_BIT_BUFFER(br_state, 1, return FALSE);
  155051. if (GET_BITS(1))
  155052. (*block)[0] |= p1;
  155053. }
  155054. BITREAD_SAVE_STATE(cinfo,entropy->bitstate);
  155055. entropy->restarts_to_go--;
  155056. return TRUE;
  155057. }
  155058. METHODDEF(boolean)
  155059. decode_mcu_AC_refine (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
  155060. {
  155061. phuff_entropy_ptr2 entropy = (phuff_entropy_ptr2) cinfo->entropy;
  155062. int Se = cinfo->Se;
  155063. int p1 = 1 << cinfo->Al; /* 1 in the bit position being coded */
  155064. int m1 = (-1) << cinfo->Al; /* -1 in the bit position being coded */
  155065. register int s, k, r;
  155066. unsigned int EOBRUN;
  155067. JBLOCKROW block;
  155068. JCOEFPTR thiscoef;
  155069. BITREAD_STATE_VARS;
  155070. d_derived_tbl * tbl;
  155071. int num_newnz;
  155072. int newnz_pos[DCTSIZE2];
  155073. if (cinfo->restart_interval) {
  155074. if (entropy->restarts_to_go == 0)
  155075. if (! process_restartp(cinfo))
  155076. return FALSE;
  155077. }
  155078. if (! entropy->pub.insufficient_data) {
  155079. BITREAD_LOAD_STATE(cinfo,entropy->bitstate);
  155080. EOBRUN = entropy->saved.EOBRUN; /* only part of saved state we need */
  155081. block = MCU_data[0];
  155082. tbl = entropy->ac_derived_tbl;
  155083. num_newnz = 0;
  155084. k = cinfo->Ss;
  155085. if (EOBRUN == 0) {
  155086. for (; k <= Se; k++) {
  155087. HUFF_DECODE(s, br_state, tbl, goto undoit, label3);
  155088. r = s >> 4;
  155089. s &= 15;
  155090. if (s) {
  155091. if (s != 1) /* size of new coef should always be 1 */
  155092. WARNMS(cinfo, JWRN_HUFF_BAD_CODE);
  155093. CHECK_BIT_BUFFER(br_state, 1, goto undoit);
  155094. if (GET_BITS(1))
  155095. s = p1; /* newly nonzero coef is positive */
  155096. else
  155097. s = m1; /* newly nonzero coef is negative */
  155098. } else {
  155099. if (r != 15) {
  155100. EOBRUN = 1 << r; /* EOBr, run length is 2^r + appended bits */
  155101. if (r) {
  155102. CHECK_BIT_BUFFER(br_state, r, goto undoit);
  155103. r = GET_BITS(r);
  155104. EOBRUN += r;
  155105. }
  155106. break; /* rest of block is handled by EOB logic */
  155107. }
  155108. }
  155109. do {
  155110. thiscoef = *block + jpeg_natural_order[k];
  155111. if (*thiscoef != 0) {
  155112. CHECK_BIT_BUFFER(br_state, 1, goto undoit);
  155113. if (GET_BITS(1)) {
  155114. if ((*thiscoef & p1) == 0) { /* do nothing if already set it */
  155115. if (*thiscoef >= 0)
  155116. *thiscoef += p1;
  155117. else
  155118. *thiscoef += m1;
  155119. }
  155120. }
  155121. } else {
  155122. if (--r < 0)
  155123. break; /* reached target zero coefficient */
  155124. }
  155125. k++;
  155126. } while (k <= Se);
  155127. if (s) {
  155128. int pos = jpeg_natural_order[k];
  155129. (*block)[pos] = (JCOEF) s;
  155130. newnz_pos[num_newnz++] = pos;
  155131. }
  155132. }
  155133. }
  155134. if (EOBRUN > 0) {
  155135. for (; k <= Se; k++) {
  155136. thiscoef = *block + jpeg_natural_order[k];
  155137. if (*thiscoef != 0) {
  155138. CHECK_BIT_BUFFER(br_state, 1, goto undoit);
  155139. if (GET_BITS(1)) {
  155140. if ((*thiscoef & p1) == 0) { /* do nothing if already changed it */
  155141. if (*thiscoef >= 0)
  155142. *thiscoef += p1;
  155143. else
  155144. *thiscoef += m1;
  155145. }
  155146. }
  155147. }
  155148. }
  155149. EOBRUN--;
  155150. }
  155151. BITREAD_SAVE_STATE(cinfo,entropy->bitstate);
  155152. entropy->saved.EOBRUN = EOBRUN; /* only part of saved state we need */
  155153. }
  155154. entropy->restarts_to_go--;
  155155. return TRUE;
  155156. undoit:
  155157. while (num_newnz > 0)
  155158. (*block)[newnz_pos[--num_newnz]] = 0;
  155159. return FALSE;
  155160. }
  155161. GLOBAL(void)
  155162. jinit_phuff_decoder (j_decompress_ptr cinfo)
  155163. {
  155164. phuff_entropy_ptr2 entropy;
  155165. int *coef_bit_ptr;
  155166. int ci, i;
  155167. entropy = (phuff_entropy_ptr2)
  155168. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  155169. SIZEOF(phuff_entropy_decoder));
  155170. cinfo->entropy = (struct jpeg_entropy_decoder *) entropy;
  155171. entropy->pub.start_pass = start_pass_phuff_decoder;
  155172. for (i = 0; i < NUM_HUFF_TBLS; i++) {
  155173. entropy->derived_tbls[i] = NULL;
  155174. }
  155175. cinfo->coef_bits = (int (*)[DCTSIZE2])
  155176. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  155177. cinfo->num_components*DCTSIZE2*SIZEOF(int));
  155178. coef_bit_ptr = & cinfo->coef_bits[0][0];
  155179. for (ci = 0; ci < cinfo->num_components; ci++)
  155180. for (i = 0; i < DCTSIZE2; i++)
  155181. *coef_bit_ptr++ = -1;
  155182. }
  155183. #endif /* D_PROGRESSIVE_SUPPORTED */
  155184. /********* End of inlined file: jdphuff.c *********/
  155185. /********* Start of inlined file: jdpostct.c *********/
  155186. #define JPEG_INTERNALS
  155187. typedef struct {
  155188. struct jpeg_d_post_controller pub; /* public fields */
  155189. jvirt_sarray_ptr whole_image; /* virtual array, or NULL if one-pass */
  155190. JSAMPARRAY buffer; /* strip buffer, or current strip of virtual */
  155191. JDIMENSION strip_height; /* buffer size in rows */
  155192. JDIMENSION starting_row; /* row # of first row in current strip */
  155193. JDIMENSION next_row; /* index of next row to fill/empty in strip */
  155194. } my_post_controller;
  155195. typedef my_post_controller * my_post_ptr;
  155196. METHODDEF(void) post_process_1pass
  155197. JPP((j_decompress_ptr cinfo,
  155198. JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,
  155199. JDIMENSION in_row_groups_avail,
  155200. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  155201. JDIMENSION out_rows_avail));
  155202. #ifdef QUANT_2PASS_SUPPORTED
  155203. METHODDEF(void) post_process_prepass
  155204. JPP((j_decompress_ptr cinfo,
  155205. JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,
  155206. JDIMENSION in_row_groups_avail,
  155207. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  155208. JDIMENSION out_rows_avail));
  155209. METHODDEF(void) post_process_2pass
  155210. JPP((j_decompress_ptr cinfo,
  155211. JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,
  155212. JDIMENSION in_row_groups_avail,
  155213. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  155214. JDIMENSION out_rows_avail));
  155215. #endif
  155216. METHODDEF(void)
  155217. start_pass_dpost (j_decompress_ptr cinfo, J_BUF_MODE pass_mode)
  155218. {
  155219. my_post_ptr post = (my_post_ptr) cinfo->post;
  155220. switch (pass_mode) {
  155221. case JBUF_PASS_THRU:
  155222. if (cinfo->quantize_colors) {
  155223. post->pub.post_process_data = post_process_1pass;
  155224. if (post->buffer == NULL) {
  155225. post->buffer = (*cinfo->mem->access_virt_sarray)
  155226. ((j_common_ptr) cinfo, post->whole_image,
  155227. (JDIMENSION) 0, post->strip_height, TRUE);
  155228. }
  155229. } else {
  155230. post->pub.post_process_data = cinfo->upsample->upsample;
  155231. }
  155232. break;
  155233. #ifdef QUANT_2PASS_SUPPORTED
  155234. case JBUF_SAVE_AND_PASS:
  155235. if (post->whole_image == NULL)
  155236. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  155237. post->pub.post_process_data = post_process_prepass;
  155238. break;
  155239. case JBUF_CRANK_DEST:
  155240. if (post->whole_image == NULL)
  155241. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  155242. post->pub.post_process_data = post_process_2pass;
  155243. break;
  155244. #endif /* QUANT_2PASS_SUPPORTED */
  155245. default:
  155246. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  155247. break;
  155248. }
  155249. post->starting_row = post->next_row = 0;
  155250. }
  155251. METHODDEF(void)
  155252. post_process_1pass (j_decompress_ptr cinfo,
  155253. JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,
  155254. JDIMENSION in_row_groups_avail,
  155255. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  155256. JDIMENSION out_rows_avail)
  155257. {
  155258. my_post_ptr post = (my_post_ptr) cinfo->post;
  155259. JDIMENSION num_rows, max_rows;
  155260. max_rows = out_rows_avail - *out_row_ctr;
  155261. if (max_rows > post->strip_height)
  155262. max_rows = post->strip_height;
  155263. num_rows = 0;
  155264. (*cinfo->upsample->upsample) (cinfo,
  155265. input_buf, in_row_group_ctr, in_row_groups_avail,
  155266. post->buffer, &num_rows, max_rows);
  155267. (*cinfo->cquantize->color_quantize) (cinfo,
  155268. post->buffer, output_buf + *out_row_ctr, (int) num_rows);
  155269. *out_row_ctr += num_rows;
  155270. }
  155271. #ifdef QUANT_2PASS_SUPPORTED
  155272. METHODDEF(void)
  155273. post_process_prepass (j_decompress_ptr cinfo,
  155274. JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,
  155275. JDIMENSION in_row_groups_avail,
  155276. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  155277. JDIMENSION out_rows_avail)
  155278. {
  155279. my_post_ptr post = (my_post_ptr) cinfo->post;
  155280. JDIMENSION old_next_row, num_rows;
  155281. if (post->next_row == 0) {
  155282. post->buffer = (*cinfo->mem->access_virt_sarray)
  155283. ((j_common_ptr) cinfo, post->whole_image,
  155284. post->starting_row, post->strip_height, TRUE);
  155285. }
  155286. old_next_row = post->next_row;
  155287. (*cinfo->upsample->upsample) (cinfo,
  155288. input_buf, in_row_group_ctr, in_row_groups_avail,
  155289. post->buffer, &post->next_row, post->strip_height);
  155290. if (post->next_row > old_next_row) {
  155291. num_rows = post->next_row - old_next_row;
  155292. (*cinfo->cquantize->color_quantize) (cinfo, post->buffer + old_next_row,
  155293. (JSAMPARRAY) NULL, (int) num_rows);
  155294. *out_row_ctr += num_rows;
  155295. }
  155296. if (post->next_row >= post->strip_height) {
  155297. post->starting_row += post->strip_height;
  155298. post->next_row = 0;
  155299. }
  155300. }
  155301. METHODDEF(void)
  155302. post_process_2pass (j_decompress_ptr cinfo,
  155303. JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,
  155304. JDIMENSION in_row_groups_avail,
  155305. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  155306. JDIMENSION out_rows_avail)
  155307. {
  155308. my_post_ptr post = (my_post_ptr) cinfo->post;
  155309. JDIMENSION num_rows, max_rows;
  155310. if (post->next_row == 0) {
  155311. post->buffer = (*cinfo->mem->access_virt_sarray)
  155312. ((j_common_ptr) cinfo, post->whole_image,
  155313. post->starting_row, post->strip_height, FALSE);
  155314. }
  155315. num_rows = post->strip_height - post->next_row; /* available in strip */
  155316. max_rows = out_rows_avail - *out_row_ctr; /* available in output area */
  155317. if (num_rows > max_rows)
  155318. num_rows = max_rows;
  155319. max_rows = cinfo->output_height - post->starting_row;
  155320. if (num_rows > max_rows)
  155321. num_rows = max_rows;
  155322. (*cinfo->cquantize->color_quantize) (cinfo,
  155323. post->buffer + post->next_row, output_buf + *out_row_ctr,
  155324. (int) num_rows);
  155325. *out_row_ctr += num_rows;
  155326. post->next_row += num_rows;
  155327. if (post->next_row >= post->strip_height) {
  155328. post->starting_row += post->strip_height;
  155329. post->next_row = 0;
  155330. }
  155331. }
  155332. #endif /* QUANT_2PASS_SUPPORTED */
  155333. GLOBAL(void)
  155334. jinit_d_post_controller (j_decompress_ptr cinfo, boolean need_full_buffer)
  155335. {
  155336. my_post_ptr post;
  155337. post = (my_post_ptr)
  155338. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  155339. SIZEOF(my_post_controller));
  155340. cinfo->post = (struct jpeg_d_post_controller *) post;
  155341. post->pub.start_pass = start_pass_dpost;
  155342. post->whole_image = NULL; /* flag for no virtual arrays */
  155343. post->buffer = NULL; /* flag for no strip buffer */
  155344. if (cinfo->quantize_colors) {
  155345. post->strip_height = (JDIMENSION) cinfo->max_v_samp_factor;
  155346. if (need_full_buffer) {
  155347. #ifdef QUANT_2PASS_SUPPORTED
  155348. post->whole_image = (*cinfo->mem->request_virt_sarray)
  155349. ((j_common_ptr) cinfo, JPOOL_IMAGE, FALSE,
  155350. cinfo->output_width * cinfo->out_color_components,
  155351. (JDIMENSION) jround_up((long) cinfo->output_height,
  155352. (long) post->strip_height),
  155353. post->strip_height);
  155354. #else
  155355. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  155356. #endif /* QUANT_2PASS_SUPPORTED */
  155357. } else {
  155358. post->buffer = (*cinfo->mem->alloc_sarray)
  155359. ((j_common_ptr) cinfo, JPOOL_IMAGE,
  155360. cinfo->output_width * cinfo->out_color_components,
  155361. post->strip_height);
  155362. }
  155363. }
  155364. }
  155365. /********* End of inlined file: jdpostct.c *********/
  155366. #undef FIX
  155367. /********* Start of inlined file: jdsample.c *********/
  155368. #define JPEG_INTERNALS
  155369. typedef JMETHOD(void, upsample1_ptr,
  155370. (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  155371. JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr));
  155372. typedef struct {
  155373. struct jpeg_upsampler pub; /* public fields */
  155374. JSAMPARRAY color_buf[MAX_COMPONENTS];
  155375. upsample1_ptr methods[MAX_COMPONENTS];
  155376. int next_row_out; /* counts rows emitted from color_buf */
  155377. JDIMENSION rows_to_go; /* counts rows remaining in image */
  155378. int rowgroup_height[MAX_COMPONENTS];
  155379. UINT8 h_expand[MAX_COMPONENTS];
  155380. UINT8 v_expand[MAX_COMPONENTS];
  155381. } my_upsampler2;
  155382. typedef my_upsampler2 * my_upsample_ptr2;
  155383. METHODDEF(void)
  155384. start_pass_upsample (j_decompress_ptr cinfo)
  155385. {
  155386. my_upsample_ptr2 upsample = (my_upsample_ptr2) cinfo->upsample;
  155387. upsample->next_row_out = cinfo->max_v_samp_factor;
  155388. upsample->rows_to_go = cinfo->output_height;
  155389. }
  155390. METHODDEF(void)
  155391. sep_upsample (j_decompress_ptr cinfo,
  155392. JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,
  155393. JDIMENSION in_row_groups_avail,
  155394. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  155395. JDIMENSION out_rows_avail)
  155396. {
  155397. my_upsample_ptr2 upsample = (my_upsample_ptr2) cinfo->upsample;
  155398. int ci;
  155399. jpeg_component_info * compptr;
  155400. JDIMENSION num_rows;
  155401. if (upsample->next_row_out >= cinfo->max_v_samp_factor) {
  155402. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  155403. ci++, compptr++) {
  155404. (*upsample->methods[ci]) (cinfo, compptr,
  155405. input_buf[ci] + (*in_row_group_ctr * upsample->rowgroup_height[ci]),
  155406. upsample->color_buf + ci);
  155407. }
  155408. upsample->next_row_out = 0;
  155409. }
  155410. num_rows = (JDIMENSION) (cinfo->max_v_samp_factor - upsample->next_row_out);
  155411. if (num_rows > upsample->rows_to_go)
  155412. num_rows = upsample->rows_to_go;
  155413. out_rows_avail -= *out_row_ctr;
  155414. if (num_rows > out_rows_avail)
  155415. num_rows = out_rows_avail;
  155416. (*cinfo->cconvert->color_convert) (cinfo, upsample->color_buf,
  155417. (JDIMENSION) upsample->next_row_out,
  155418. output_buf + *out_row_ctr,
  155419. (int) num_rows);
  155420. *out_row_ctr += num_rows;
  155421. upsample->rows_to_go -= num_rows;
  155422. upsample->next_row_out += num_rows;
  155423. if (upsample->next_row_out >= cinfo->max_v_samp_factor)
  155424. (*in_row_group_ctr)++;
  155425. }
  155426. METHODDEF(void)
  155427. fullsize_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  155428. JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr)
  155429. {
  155430. *output_data_ptr = input_data;
  155431. }
  155432. METHODDEF(void)
  155433. noop_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  155434. JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr)
  155435. {
  155436. *output_data_ptr = NULL; /* safety check */
  155437. }
  155438. METHODDEF(void)
  155439. int_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  155440. JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr)
  155441. {
  155442. my_upsample_ptr2 upsample = (my_upsample_ptr2) cinfo->upsample;
  155443. JSAMPARRAY output_data = *output_data_ptr;
  155444. register JSAMPROW inptr, outptr;
  155445. register JSAMPLE invalue;
  155446. register int h;
  155447. JSAMPROW outend;
  155448. int h_expand, v_expand;
  155449. int inrow, outrow;
  155450. h_expand = upsample->h_expand[compptr->component_index];
  155451. v_expand = upsample->v_expand[compptr->component_index];
  155452. inrow = outrow = 0;
  155453. while (outrow < cinfo->max_v_samp_factor) {
  155454. inptr = input_data[inrow];
  155455. outptr = output_data[outrow];
  155456. outend = outptr + cinfo->output_width;
  155457. while (outptr < outend) {
  155458. invalue = *inptr++; /* don't need GETJSAMPLE() here */
  155459. for (h = h_expand; h > 0; h--) {
  155460. *outptr++ = invalue;
  155461. }
  155462. }
  155463. if (v_expand > 1) {
  155464. jcopy_sample_rows(output_data, outrow, output_data, outrow+1,
  155465. v_expand-1, cinfo->output_width);
  155466. }
  155467. inrow++;
  155468. outrow += v_expand;
  155469. }
  155470. }
  155471. METHODDEF(void)
  155472. h2v1_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  155473. JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr)
  155474. {
  155475. JSAMPARRAY output_data = *output_data_ptr;
  155476. register JSAMPROW inptr, outptr;
  155477. register JSAMPLE invalue;
  155478. JSAMPROW outend;
  155479. int inrow;
  155480. for (inrow = 0; inrow < cinfo->max_v_samp_factor; inrow++) {
  155481. inptr = input_data[inrow];
  155482. outptr = output_data[inrow];
  155483. outend = outptr + cinfo->output_width;
  155484. while (outptr < outend) {
  155485. invalue = *inptr++; /* don't need GETJSAMPLE() here */
  155486. *outptr++ = invalue;
  155487. *outptr++ = invalue;
  155488. }
  155489. }
  155490. }
  155491. METHODDEF(void)
  155492. h2v2_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  155493. JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr)
  155494. {
  155495. JSAMPARRAY output_data = *output_data_ptr;
  155496. register JSAMPROW inptr, outptr;
  155497. register JSAMPLE invalue;
  155498. JSAMPROW outend;
  155499. int inrow, outrow;
  155500. inrow = outrow = 0;
  155501. while (outrow < cinfo->max_v_samp_factor) {
  155502. inptr = input_data[inrow];
  155503. outptr = output_data[outrow];
  155504. outend = outptr + cinfo->output_width;
  155505. while (outptr < outend) {
  155506. invalue = *inptr++; /* don't need GETJSAMPLE() here */
  155507. *outptr++ = invalue;
  155508. *outptr++ = invalue;
  155509. }
  155510. jcopy_sample_rows(output_data, outrow, output_data, outrow+1,
  155511. 1, cinfo->output_width);
  155512. inrow++;
  155513. outrow += 2;
  155514. }
  155515. }
  155516. METHODDEF(void)
  155517. h2v1_fancy_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  155518. JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr)
  155519. {
  155520. JSAMPARRAY output_data = *output_data_ptr;
  155521. register JSAMPROW inptr, outptr;
  155522. register int invalue;
  155523. register JDIMENSION colctr;
  155524. int inrow;
  155525. for (inrow = 0; inrow < cinfo->max_v_samp_factor; inrow++) {
  155526. inptr = input_data[inrow];
  155527. outptr = output_data[inrow];
  155528. invalue = GETJSAMPLE(*inptr++);
  155529. *outptr++ = (JSAMPLE) invalue;
  155530. *outptr++ = (JSAMPLE) ((invalue * 3 + GETJSAMPLE(*inptr) + 2) >> 2);
  155531. for (colctr = compptr->downsampled_width - 2; colctr > 0; colctr--) {
  155532. invalue = GETJSAMPLE(*inptr++) * 3;
  155533. *outptr++ = (JSAMPLE) ((invalue + GETJSAMPLE(inptr[-2]) + 1) >> 2);
  155534. *outptr++ = (JSAMPLE) ((invalue + GETJSAMPLE(*inptr) + 2) >> 2);
  155535. }
  155536. invalue = GETJSAMPLE(*inptr);
  155537. *outptr++ = (JSAMPLE) ((invalue * 3 + GETJSAMPLE(inptr[-1]) + 1) >> 2);
  155538. *outptr++ = (JSAMPLE) invalue;
  155539. }
  155540. }
  155541. METHODDEF(void)
  155542. h2v2_fancy_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  155543. JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr)
  155544. {
  155545. JSAMPARRAY output_data = *output_data_ptr;
  155546. register JSAMPROW inptr0, inptr1, outptr;
  155547. #if BITS_IN_JSAMPLE == 8
  155548. register int thiscolsum, lastcolsum, nextcolsum;
  155549. #else
  155550. register INT32 thiscolsum, lastcolsum, nextcolsum;
  155551. #endif
  155552. register JDIMENSION colctr;
  155553. int inrow, outrow, v;
  155554. inrow = outrow = 0;
  155555. while (outrow < cinfo->max_v_samp_factor) {
  155556. for (v = 0; v < 2; v++) {
  155557. inptr0 = input_data[inrow];
  155558. if (v == 0) /* next nearest is row above */
  155559. inptr1 = input_data[inrow-1];
  155560. else /* next nearest is row below */
  155561. inptr1 = input_data[inrow+1];
  155562. outptr = output_data[outrow++];
  155563. thiscolsum = GETJSAMPLE(*inptr0++) * 3 + GETJSAMPLE(*inptr1++);
  155564. nextcolsum = GETJSAMPLE(*inptr0++) * 3 + GETJSAMPLE(*inptr1++);
  155565. *outptr++ = (JSAMPLE) ((thiscolsum * 4 + 8) >> 4);
  155566. *outptr++ = (JSAMPLE) ((thiscolsum * 3 + nextcolsum + 7) >> 4);
  155567. lastcolsum = thiscolsum; thiscolsum = nextcolsum;
  155568. for (colctr = compptr->downsampled_width - 2; colctr > 0; colctr--) {
  155569. nextcolsum = GETJSAMPLE(*inptr0++) * 3 + GETJSAMPLE(*inptr1++);
  155570. *outptr++ = (JSAMPLE) ((thiscolsum * 3 + lastcolsum + 8) >> 4);
  155571. *outptr++ = (JSAMPLE) ((thiscolsum * 3 + nextcolsum + 7) >> 4);
  155572. lastcolsum = thiscolsum; thiscolsum = nextcolsum;
  155573. }
  155574. *outptr++ = (JSAMPLE) ((thiscolsum * 3 + lastcolsum + 8) >> 4);
  155575. *outptr++ = (JSAMPLE) ((thiscolsum * 4 + 7) >> 4);
  155576. }
  155577. inrow++;
  155578. }
  155579. }
  155580. GLOBAL(void)
  155581. jinit_upsampler (j_decompress_ptr cinfo)
  155582. {
  155583. my_upsample_ptr2 upsample;
  155584. int ci;
  155585. jpeg_component_info * compptr;
  155586. boolean need_buffer, do_fancy;
  155587. int h_in_group, v_in_group, h_out_group, v_out_group;
  155588. upsample = (my_upsample_ptr2)
  155589. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  155590. SIZEOF(my_upsampler2));
  155591. cinfo->upsample = (struct jpeg_upsampler *) upsample;
  155592. upsample->pub.start_pass = start_pass_upsample;
  155593. upsample->pub.upsample = sep_upsample;
  155594. upsample->pub.need_context_rows = FALSE; /* until we find out differently */
  155595. if (cinfo->CCIR601_sampling) /* this isn't supported */
  155596. ERREXIT(cinfo, JERR_CCIR601_NOTIMPL);
  155597. do_fancy = cinfo->do_fancy_upsampling && cinfo->min_DCT_scaled_size > 1;
  155598. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  155599. ci++, compptr++) {
  155600. h_in_group = (compptr->h_samp_factor * compptr->DCT_scaled_size) /
  155601. cinfo->min_DCT_scaled_size;
  155602. v_in_group = (compptr->v_samp_factor * compptr->DCT_scaled_size) /
  155603. cinfo->min_DCT_scaled_size;
  155604. h_out_group = cinfo->max_h_samp_factor;
  155605. v_out_group = cinfo->max_v_samp_factor;
  155606. upsample->rowgroup_height[ci] = v_in_group; /* save for use later */
  155607. need_buffer = TRUE;
  155608. if (! compptr->component_needed) {
  155609. upsample->methods[ci] = noop_upsample;
  155610. need_buffer = FALSE;
  155611. } else if (h_in_group == h_out_group && v_in_group == v_out_group) {
  155612. upsample->methods[ci] = fullsize_upsample;
  155613. need_buffer = FALSE;
  155614. } else if (h_in_group * 2 == h_out_group &&
  155615. v_in_group == v_out_group) {
  155616. if (do_fancy && compptr->downsampled_width > 2)
  155617. upsample->methods[ci] = h2v1_fancy_upsample;
  155618. else
  155619. upsample->methods[ci] = h2v1_upsample;
  155620. } else if (h_in_group * 2 == h_out_group &&
  155621. v_in_group * 2 == v_out_group) {
  155622. if (do_fancy && compptr->downsampled_width > 2) {
  155623. upsample->methods[ci] = h2v2_fancy_upsample;
  155624. upsample->pub.need_context_rows = TRUE;
  155625. } else
  155626. upsample->methods[ci] = h2v2_upsample;
  155627. } else if ((h_out_group % h_in_group) == 0 &&
  155628. (v_out_group % v_in_group) == 0) {
  155629. upsample->methods[ci] = int_upsample;
  155630. upsample->h_expand[ci] = (UINT8) (h_out_group / h_in_group);
  155631. upsample->v_expand[ci] = (UINT8) (v_out_group / v_in_group);
  155632. } else
  155633. ERREXIT(cinfo, JERR_FRACT_SAMPLE_NOTIMPL);
  155634. if (need_buffer) {
  155635. upsample->color_buf[ci] = (*cinfo->mem->alloc_sarray)
  155636. ((j_common_ptr) cinfo, JPOOL_IMAGE,
  155637. (JDIMENSION) jround_up((long) cinfo->output_width,
  155638. (long) cinfo->max_h_samp_factor),
  155639. (JDIMENSION) cinfo->max_v_samp_factor);
  155640. }
  155641. }
  155642. }
  155643. /********* End of inlined file: jdsample.c *********/
  155644. /********* Start of inlined file: jdtrans.c *********/
  155645. #define JPEG_INTERNALS
  155646. LOCAL(void) transdecode_master_selection JPP((j_decompress_ptr cinfo));
  155647. GLOBAL(jvirt_barray_ptr *)
  155648. jpeg_read_coefficients (j_decompress_ptr cinfo)
  155649. {
  155650. if (cinfo->global_state == DSTATE_READY) {
  155651. transdecode_master_selection(cinfo);
  155652. cinfo->global_state = DSTATE_RDCOEFS;
  155653. }
  155654. if (cinfo->global_state == DSTATE_RDCOEFS) {
  155655. for (;;) {
  155656. int retcode;
  155657. if (cinfo->progress != NULL)
  155658. (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);
  155659. retcode = (*cinfo->inputctl->consume_input) (cinfo);
  155660. if (retcode == JPEG_SUSPENDED)
  155661. return NULL;
  155662. if (retcode == JPEG_REACHED_EOI)
  155663. break;
  155664. if (cinfo->progress != NULL &&
  155665. (retcode == JPEG_ROW_COMPLETED || retcode == JPEG_REACHED_SOS)) {
  155666. if (++cinfo->progress->pass_counter >= cinfo->progress->pass_limit) {
  155667. cinfo->progress->pass_limit += (long) cinfo->total_iMCU_rows;
  155668. }
  155669. }
  155670. }
  155671. cinfo->global_state = DSTATE_STOPPING;
  155672. }
  155673. if ((cinfo->global_state == DSTATE_STOPPING ||
  155674. cinfo->global_state == DSTATE_BUFIMAGE) && cinfo->buffered_image) {
  155675. return cinfo->coef->coef_arrays;
  155676. }
  155677. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  155678. return NULL; /* keep compiler happy */
  155679. }
  155680. LOCAL(void)
  155681. transdecode_master_selection (j_decompress_ptr cinfo)
  155682. {
  155683. cinfo->buffered_image = TRUE;
  155684. if (cinfo->arith_code) {
  155685. ERREXIT(cinfo, JERR_ARITH_NOTIMPL);
  155686. } else {
  155687. if (cinfo->progressive_mode) {
  155688. #ifdef D_PROGRESSIVE_SUPPORTED
  155689. jinit_phuff_decoder(cinfo);
  155690. #else
  155691. ERREXIT(cinfo, JERR_NOT_COMPILED);
  155692. #endif
  155693. } else
  155694. jinit_huff_decoder(cinfo);
  155695. }
  155696. jinit_d_coef_controller(cinfo, TRUE);
  155697. (*cinfo->mem->realize_virt_arrays) ((j_common_ptr) cinfo);
  155698. (*cinfo->inputctl->start_input_pass) (cinfo);
  155699. if (cinfo->progress != NULL) {
  155700. int nscans;
  155701. if (cinfo->progressive_mode) {
  155702. nscans = 2 + 3 * cinfo->num_components;
  155703. } else if (cinfo->inputctl->has_multiple_scans) {
  155704. nscans = cinfo->num_components;
  155705. } else {
  155706. nscans = 1;
  155707. }
  155708. cinfo->progress->pass_counter = 0L;
  155709. cinfo->progress->pass_limit = (long) cinfo->total_iMCU_rows * nscans;
  155710. cinfo->progress->completed_passes = 0;
  155711. cinfo->progress->total_passes = 1;
  155712. }
  155713. }
  155714. /********* End of inlined file: jdtrans.c *********/
  155715. /********* Start of inlined file: jfdctflt.c *********/
  155716. #define JPEG_INTERNALS
  155717. #ifdef DCT_FLOAT_SUPPORTED
  155718. #if DCTSIZE != 8
  155719. Sorry, this code only copes with 8x8 DCTs. /* deliberate syntax err */
  155720. #endif
  155721. GLOBAL(void)
  155722. jpeg_fdct_float (FAST_FLOAT * data)
  155723. {
  155724. FAST_FLOAT tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;
  155725. FAST_FLOAT tmp10, tmp11, tmp12, tmp13;
  155726. FAST_FLOAT z1, z2, z3, z4, z5, z11, z13;
  155727. FAST_FLOAT *dataptr;
  155728. int ctr;
  155729. dataptr = data;
  155730. for (ctr = DCTSIZE-1; ctr >= 0; ctr--) {
  155731. tmp0 = dataptr[0] + dataptr[7];
  155732. tmp7 = dataptr[0] - dataptr[7];
  155733. tmp1 = dataptr[1] + dataptr[6];
  155734. tmp6 = dataptr[1] - dataptr[6];
  155735. tmp2 = dataptr[2] + dataptr[5];
  155736. tmp5 = dataptr[2] - dataptr[5];
  155737. tmp3 = dataptr[3] + dataptr[4];
  155738. tmp4 = dataptr[3] - dataptr[4];
  155739. tmp10 = tmp0 + tmp3; /* phase 2 */
  155740. tmp13 = tmp0 - tmp3;
  155741. tmp11 = tmp1 + tmp2;
  155742. tmp12 = tmp1 - tmp2;
  155743. dataptr[0] = tmp10 + tmp11; /* phase 3 */
  155744. dataptr[4] = tmp10 - tmp11;
  155745. z1 = (tmp12 + tmp13) * ((FAST_FLOAT) 0.707106781); /* c4 */
  155746. dataptr[2] = tmp13 + z1; /* phase 5 */
  155747. dataptr[6] = tmp13 - z1;
  155748. tmp10 = tmp4 + tmp5; /* phase 2 */
  155749. tmp11 = tmp5 + tmp6;
  155750. tmp12 = tmp6 + tmp7;
  155751. z5 = (tmp10 - tmp12) * ((FAST_FLOAT) 0.382683433); /* c6 */
  155752. z2 = ((FAST_FLOAT) 0.541196100) * tmp10 + z5; /* c2-c6 */
  155753. z4 = ((FAST_FLOAT) 1.306562965) * tmp12 + z5; /* c2+c6 */
  155754. z3 = tmp11 * ((FAST_FLOAT) 0.707106781); /* c4 */
  155755. z11 = tmp7 + z3; /* phase 5 */
  155756. z13 = tmp7 - z3;
  155757. dataptr[5] = z13 + z2; /* phase 6 */
  155758. dataptr[3] = z13 - z2;
  155759. dataptr[1] = z11 + z4;
  155760. dataptr[7] = z11 - z4;
  155761. dataptr += DCTSIZE; /* advance pointer to next row */
  155762. }
  155763. dataptr = data;
  155764. for (ctr = DCTSIZE-1; ctr >= 0; ctr--) {
  155765. tmp0 = dataptr[DCTSIZE*0] + dataptr[DCTSIZE*7];
  155766. tmp7 = dataptr[DCTSIZE*0] - dataptr[DCTSIZE*7];
  155767. tmp1 = dataptr[DCTSIZE*1] + dataptr[DCTSIZE*6];
  155768. tmp6 = dataptr[DCTSIZE*1] - dataptr[DCTSIZE*6];
  155769. tmp2 = dataptr[DCTSIZE*2] + dataptr[DCTSIZE*5];
  155770. tmp5 = dataptr[DCTSIZE*2] - dataptr[DCTSIZE*5];
  155771. tmp3 = dataptr[DCTSIZE*3] + dataptr[DCTSIZE*4];
  155772. tmp4 = dataptr[DCTSIZE*3] - dataptr[DCTSIZE*4];
  155773. tmp10 = tmp0 + tmp3; /* phase 2 */
  155774. tmp13 = tmp0 - tmp3;
  155775. tmp11 = tmp1 + tmp2;
  155776. tmp12 = tmp1 - tmp2;
  155777. dataptr[DCTSIZE*0] = tmp10 + tmp11; /* phase 3 */
  155778. dataptr[DCTSIZE*4] = tmp10 - tmp11;
  155779. z1 = (tmp12 + tmp13) * ((FAST_FLOAT) 0.707106781); /* c4 */
  155780. dataptr[DCTSIZE*2] = tmp13 + z1; /* phase 5 */
  155781. dataptr[DCTSIZE*6] = tmp13 - z1;
  155782. tmp10 = tmp4 + tmp5; /* phase 2 */
  155783. tmp11 = tmp5 + tmp6;
  155784. tmp12 = tmp6 + tmp7;
  155785. z5 = (tmp10 - tmp12) * ((FAST_FLOAT) 0.382683433); /* c6 */
  155786. z2 = ((FAST_FLOAT) 0.541196100) * tmp10 + z5; /* c2-c6 */
  155787. z4 = ((FAST_FLOAT) 1.306562965) * tmp12 + z5; /* c2+c6 */
  155788. z3 = tmp11 * ((FAST_FLOAT) 0.707106781); /* c4 */
  155789. z11 = tmp7 + z3; /* phase 5 */
  155790. z13 = tmp7 - z3;
  155791. dataptr[DCTSIZE*5] = z13 + z2; /* phase 6 */
  155792. dataptr[DCTSIZE*3] = z13 - z2;
  155793. dataptr[DCTSIZE*1] = z11 + z4;
  155794. dataptr[DCTSIZE*7] = z11 - z4;
  155795. dataptr++; /* advance pointer to next column */
  155796. }
  155797. }
  155798. #endif /* DCT_FLOAT_SUPPORTED */
  155799. /********* End of inlined file: jfdctflt.c *********/
  155800. /********* Start of inlined file: jfdctint.c *********/
  155801. #define JPEG_INTERNALS
  155802. #ifdef DCT_ISLOW_SUPPORTED
  155803. #if DCTSIZE != 8
  155804. Sorry, this code only copes with 8x8 DCTs. /* deliberate syntax err */
  155805. #endif
  155806. #if BITS_IN_JSAMPLE == 8
  155807. #define CONST_BITS 13
  155808. #define PASS1_BITS 2
  155809. #else
  155810. #define CONST_BITS 13
  155811. #define PASS1_BITS 1 /* lose a little precision to avoid overflow */
  155812. #endif
  155813. #if CONST_BITS == 13
  155814. #define FIX_0_298631336 ((INT32) 2446) /* FIX(0.298631336) */
  155815. #define FIX_0_390180644 ((INT32) 3196) /* FIX(0.390180644) */
  155816. #define FIX_0_541196100 ((INT32) 4433) /* FIX(0.541196100) */
  155817. #define FIX_0_765366865 ((INT32) 6270) /* FIX(0.765366865) */
  155818. #define FIX_0_899976223 ((INT32) 7373) /* FIX(0.899976223) */
  155819. #define FIX_1_175875602 ((INT32) 9633) /* FIX(1.175875602) */
  155820. #define FIX_1_501321110 ((INT32) 12299) /* FIX(1.501321110) */
  155821. #define FIX_1_847759065 ((INT32) 15137) /* FIX(1.847759065) */
  155822. #define FIX_1_961570560 ((INT32) 16069) /* FIX(1.961570560) */
  155823. #define FIX_2_053119869 ((INT32) 16819) /* FIX(2.053119869) */
  155824. #define FIX_2_562915447 ((INT32) 20995) /* FIX(2.562915447) */
  155825. #define FIX_3_072711026 ((INT32) 25172) /* FIX(3.072711026) */
  155826. #else
  155827. #define FIX_0_298631336 FIX(0.298631336)
  155828. #define FIX_0_390180644 FIX(0.390180644)
  155829. #define FIX_0_541196100 FIX(0.541196100)
  155830. #define FIX_0_765366865 FIX(0.765366865)
  155831. #define FIX_0_899976223 FIX(0.899976223)
  155832. #define FIX_1_175875602 FIX(1.175875602)
  155833. #define FIX_1_501321110 FIX(1.501321110)
  155834. #define FIX_1_847759065 FIX(1.847759065)
  155835. #define FIX_1_961570560 FIX(1.961570560)
  155836. #define FIX_2_053119869 FIX(2.053119869)
  155837. #define FIX_2_562915447 FIX(2.562915447)
  155838. #define FIX_3_072711026 FIX(3.072711026)
  155839. #endif
  155840. #if BITS_IN_JSAMPLE == 8
  155841. #define MULTIPLY(var,const) MULTIPLY16C16(var,const)
  155842. #else
  155843. #define MULTIPLY(var,const) ((var) * (const))
  155844. #endif
  155845. GLOBAL(void)
  155846. jpeg_fdct_islow (DCTELEM * data)
  155847. {
  155848. INT32 tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;
  155849. INT32 tmp10, tmp11, tmp12, tmp13;
  155850. INT32 z1, z2, z3, z4, z5;
  155851. DCTELEM *dataptr;
  155852. int ctr;
  155853. SHIFT_TEMPS
  155854. dataptr = data;
  155855. for (ctr = DCTSIZE-1; ctr >= 0; ctr--) {
  155856. tmp0 = dataptr[0] + dataptr[7];
  155857. tmp7 = dataptr[0] - dataptr[7];
  155858. tmp1 = dataptr[1] + dataptr[6];
  155859. tmp6 = dataptr[1] - dataptr[6];
  155860. tmp2 = dataptr[2] + dataptr[5];
  155861. tmp5 = dataptr[2] - dataptr[5];
  155862. tmp3 = dataptr[3] + dataptr[4];
  155863. tmp4 = dataptr[3] - dataptr[4];
  155864. tmp10 = tmp0 + tmp3;
  155865. tmp13 = tmp0 - tmp3;
  155866. tmp11 = tmp1 + tmp2;
  155867. tmp12 = tmp1 - tmp2;
  155868. dataptr[0] = (DCTELEM) ((tmp10 + tmp11) << PASS1_BITS);
  155869. dataptr[4] = (DCTELEM) ((tmp10 - tmp11) << PASS1_BITS);
  155870. z1 = MULTIPLY(tmp12 + tmp13, FIX_0_541196100);
  155871. dataptr[2] = (DCTELEM) DESCALE(z1 + MULTIPLY(tmp13, FIX_0_765366865),
  155872. CONST_BITS-PASS1_BITS);
  155873. dataptr[6] = (DCTELEM) DESCALE(z1 + MULTIPLY(tmp12, - FIX_1_847759065),
  155874. CONST_BITS-PASS1_BITS);
  155875. z1 = tmp4 + tmp7;
  155876. z2 = tmp5 + tmp6;
  155877. z3 = tmp4 + tmp6;
  155878. z4 = tmp5 + tmp7;
  155879. z5 = MULTIPLY(z3 + z4, FIX_1_175875602); /* sqrt(2) * c3 */
  155880. tmp4 = MULTIPLY(tmp4, FIX_0_298631336); /* sqrt(2) * (-c1+c3+c5-c7) */
  155881. tmp5 = MULTIPLY(tmp5, FIX_2_053119869); /* sqrt(2) * ( c1+c3-c5+c7) */
  155882. tmp6 = MULTIPLY(tmp6, FIX_3_072711026); /* sqrt(2) * ( c1+c3+c5-c7) */
  155883. tmp7 = MULTIPLY(tmp7, FIX_1_501321110); /* sqrt(2) * ( c1+c3-c5-c7) */
  155884. z1 = MULTIPLY(z1, - FIX_0_899976223); /* sqrt(2) * (c7-c3) */
  155885. z2 = MULTIPLY(z2, - FIX_2_562915447); /* sqrt(2) * (-c1-c3) */
  155886. z3 = MULTIPLY(z3, - FIX_1_961570560); /* sqrt(2) * (-c3-c5) */
  155887. z4 = MULTIPLY(z4, - FIX_0_390180644); /* sqrt(2) * (c5-c3) */
  155888. z3 += z5;
  155889. z4 += z5;
  155890. dataptr[7] = (DCTELEM) DESCALE(tmp4 + z1 + z3, CONST_BITS-PASS1_BITS);
  155891. dataptr[5] = (DCTELEM) DESCALE(tmp5 + z2 + z4, CONST_BITS-PASS1_BITS);
  155892. dataptr[3] = (DCTELEM) DESCALE(tmp6 + z2 + z3, CONST_BITS-PASS1_BITS);
  155893. dataptr[1] = (DCTELEM) DESCALE(tmp7 + z1 + z4, CONST_BITS-PASS1_BITS);
  155894. dataptr += DCTSIZE; /* advance pointer to next row */
  155895. }
  155896. dataptr = data;
  155897. for (ctr = DCTSIZE-1; ctr >= 0; ctr--) {
  155898. tmp0 = dataptr[DCTSIZE*0] + dataptr[DCTSIZE*7];
  155899. tmp7 = dataptr[DCTSIZE*0] - dataptr[DCTSIZE*7];
  155900. tmp1 = dataptr[DCTSIZE*1] + dataptr[DCTSIZE*6];
  155901. tmp6 = dataptr[DCTSIZE*1] - dataptr[DCTSIZE*6];
  155902. tmp2 = dataptr[DCTSIZE*2] + dataptr[DCTSIZE*5];
  155903. tmp5 = dataptr[DCTSIZE*2] - dataptr[DCTSIZE*5];
  155904. tmp3 = dataptr[DCTSIZE*3] + dataptr[DCTSIZE*4];
  155905. tmp4 = dataptr[DCTSIZE*3] - dataptr[DCTSIZE*4];
  155906. tmp10 = tmp0 + tmp3;
  155907. tmp13 = tmp0 - tmp3;
  155908. tmp11 = tmp1 + tmp2;
  155909. tmp12 = tmp1 - tmp2;
  155910. dataptr[DCTSIZE*0] = (DCTELEM) DESCALE(tmp10 + tmp11, PASS1_BITS);
  155911. dataptr[DCTSIZE*4] = (DCTELEM) DESCALE(tmp10 - tmp11, PASS1_BITS);
  155912. z1 = MULTIPLY(tmp12 + tmp13, FIX_0_541196100);
  155913. dataptr[DCTSIZE*2] = (DCTELEM) DESCALE(z1 + MULTIPLY(tmp13, FIX_0_765366865),
  155914. CONST_BITS+PASS1_BITS);
  155915. dataptr[DCTSIZE*6] = (DCTELEM) DESCALE(z1 + MULTIPLY(tmp12, - FIX_1_847759065),
  155916. CONST_BITS+PASS1_BITS);
  155917. z1 = tmp4 + tmp7;
  155918. z2 = tmp5 + tmp6;
  155919. z3 = tmp4 + tmp6;
  155920. z4 = tmp5 + tmp7;
  155921. z5 = MULTIPLY(z3 + z4, FIX_1_175875602); /* sqrt(2) * c3 */
  155922. tmp4 = MULTIPLY(tmp4, FIX_0_298631336); /* sqrt(2) * (-c1+c3+c5-c7) */
  155923. tmp5 = MULTIPLY(tmp5, FIX_2_053119869); /* sqrt(2) * ( c1+c3-c5+c7) */
  155924. tmp6 = MULTIPLY(tmp6, FIX_3_072711026); /* sqrt(2) * ( c1+c3+c5-c7) */
  155925. tmp7 = MULTIPLY(tmp7, FIX_1_501321110); /* sqrt(2) * ( c1+c3-c5-c7) */
  155926. z1 = MULTIPLY(z1, - FIX_0_899976223); /* sqrt(2) * (c7-c3) */
  155927. z2 = MULTIPLY(z2, - FIX_2_562915447); /* sqrt(2) * (-c1-c3) */
  155928. z3 = MULTIPLY(z3, - FIX_1_961570560); /* sqrt(2) * (-c3-c5) */
  155929. z4 = MULTIPLY(z4, - FIX_0_390180644); /* sqrt(2) * (c5-c3) */
  155930. z3 += z5;
  155931. z4 += z5;
  155932. dataptr[DCTSIZE*7] = (DCTELEM) DESCALE(tmp4 + z1 + z3,
  155933. CONST_BITS+PASS1_BITS);
  155934. dataptr[DCTSIZE*5] = (DCTELEM) DESCALE(tmp5 + z2 + z4,
  155935. CONST_BITS+PASS1_BITS);
  155936. dataptr[DCTSIZE*3] = (DCTELEM) DESCALE(tmp6 + z2 + z3,
  155937. CONST_BITS+PASS1_BITS);
  155938. dataptr[DCTSIZE*1] = (DCTELEM) DESCALE(tmp7 + z1 + z4,
  155939. CONST_BITS+PASS1_BITS);
  155940. dataptr++; /* advance pointer to next column */
  155941. }
  155942. }
  155943. #endif /* DCT_ISLOW_SUPPORTED */
  155944. /********* End of inlined file: jfdctint.c *********/
  155945. #undef CONST_BITS
  155946. #undef MULTIPLY
  155947. #undef FIX_0_541196100
  155948. /********* Start of inlined file: jfdctfst.c *********/
  155949. #define JPEG_INTERNALS
  155950. #ifdef DCT_IFAST_SUPPORTED
  155951. #if DCTSIZE != 8
  155952. Sorry, this code only copes with 8x8 DCTs. /* deliberate syntax err */
  155953. #endif
  155954. #define CONST_BITS 8
  155955. #if CONST_BITS == 8
  155956. #define FIX_0_382683433 ((INT32) 98) /* FIX(0.382683433) */
  155957. #define FIX_0_541196100 ((INT32) 139) /* FIX(0.541196100) */
  155958. #define FIX_0_707106781 ((INT32) 181) /* FIX(0.707106781) */
  155959. #define FIX_1_306562965 ((INT32) 334) /* FIX(1.306562965) */
  155960. #else
  155961. #define FIX_0_382683433 FIX(0.382683433)
  155962. #define FIX_0_541196100 FIX(0.541196100)
  155963. #define FIX_0_707106781 FIX(0.707106781)
  155964. #define FIX_1_306562965 FIX(1.306562965)
  155965. #endif
  155966. #ifndef USE_ACCURATE_ROUNDING
  155967. #undef DESCALE
  155968. #define DESCALE(x,n) RIGHT_SHIFT(x, n)
  155969. #endif
  155970. #define MULTIPLY(var,const) ((DCTELEM) DESCALE((var) * (const), CONST_BITS))
  155971. GLOBAL(void)
  155972. jpeg_fdct_ifast (DCTELEM * data)
  155973. {
  155974. DCTELEM tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;
  155975. DCTELEM tmp10, tmp11, tmp12, tmp13;
  155976. DCTELEM z1, z2, z3, z4, z5, z11, z13;
  155977. DCTELEM *dataptr;
  155978. int ctr;
  155979. SHIFT_TEMPS
  155980. dataptr = data;
  155981. for (ctr = DCTSIZE-1; ctr >= 0; ctr--) {
  155982. tmp0 = dataptr[0] + dataptr[7];
  155983. tmp7 = dataptr[0] - dataptr[7];
  155984. tmp1 = dataptr[1] + dataptr[6];
  155985. tmp6 = dataptr[1] - dataptr[6];
  155986. tmp2 = dataptr[2] + dataptr[5];
  155987. tmp5 = dataptr[2] - dataptr[5];
  155988. tmp3 = dataptr[3] + dataptr[4];
  155989. tmp4 = dataptr[3] - dataptr[4];
  155990. tmp10 = tmp0 + tmp3; /* phase 2 */
  155991. tmp13 = tmp0 - tmp3;
  155992. tmp11 = tmp1 + tmp2;
  155993. tmp12 = tmp1 - tmp2;
  155994. dataptr[0] = tmp10 + tmp11; /* phase 3 */
  155995. dataptr[4] = tmp10 - tmp11;
  155996. z1 = MULTIPLY(tmp12 + tmp13, FIX_0_707106781); /* c4 */
  155997. dataptr[2] = tmp13 + z1; /* phase 5 */
  155998. dataptr[6] = tmp13 - z1;
  155999. tmp10 = tmp4 + tmp5; /* phase 2 */
  156000. tmp11 = tmp5 + tmp6;
  156001. tmp12 = tmp6 + tmp7;
  156002. z5 = MULTIPLY(tmp10 - tmp12, FIX_0_382683433); /* c6 */
  156003. z2 = MULTIPLY(tmp10, FIX_0_541196100) + z5; /* c2-c6 */
  156004. z4 = MULTIPLY(tmp12, FIX_1_306562965) + z5; /* c2+c6 */
  156005. z3 = MULTIPLY(tmp11, FIX_0_707106781); /* c4 */
  156006. z11 = tmp7 + z3; /* phase 5 */
  156007. z13 = tmp7 - z3;
  156008. dataptr[5] = z13 + z2; /* phase 6 */
  156009. dataptr[3] = z13 - z2;
  156010. dataptr[1] = z11 + z4;
  156011. dataptr[7] = z11 - z4;
  156012. dataptr += DCTSIZE; /* advance pointer to next row */
  156013. }
  156014. dataptr = data;
  156015. for (ctr = DCTSIZE-1; ctr >= 0; ctr--) {
  156016. tmp0 = dataptr[DCTSIZE*0] + dataptr[DCTSIZE*7];
  156017. tmp7 = dataptr[DCTSIZE*0] - dataptr[DCTSIZE*7];
  156018. tmp1 = dataptr[DCTSIZE*1] + dataptr[DCTSIZE*6];
  156019. tmp6 = dataptr[DCTSIZE*1] - dataptr[DCTSIZE*6];
  156020. tmp2 = dataptr[DCTSIZE*2] + dataptr[DCTSIZE*5];
  156021. tmp5 = dataptr[DCTSIZE*2] - dataptr[DCTSIZE*5];
  156022. tmp3 = dataptr[DCTSIZE*3] + dataptr[DCTSIZE*4];
  156023. tmp4 = dataptr[DCTSIZE*3] - dataptr[DCTSIZE*4];
  156024. tmp10 = tmp0 + tmp3; /* phase 2 */
  156025. tmp13 = tmp0 - tmp3;
  156026. tmp11 = tmp1 + tmp2;
  156027. tmp12 = tmp1 - tmp2;
  156028. dataptr[DCTSIZE*0] = tmp10 + tmp11; /* phase 3 */
  156029. dataptr[DCTSIZE*4] = tmp10 - tmp11;
  156030. z1 = MULTIPLY(tmp12 + tmp13, FIX_0_707106781); /* c4 */
  156031. dataptr[DCTSIZE*2] = tmp13 + z1; /* phase 5 */
  156032. dataptr[DCTSIZE*6] = tmp13 - z1;
  156033. tmp10 = tmp4 + tmp5; /* phase 2 */
  156034. tmp11 = tmp5 + tmp6;
  156035. tmp12 = tmp6 + tmp7;
  156036. z5 = MULTIPLY(tmp10 - tmp12, FIX_0_382683433); /* c6 */
  156037. z2 = MULTIPLY(tmp10, FIX_0_541196100) + z5; /* c2-c6 */
  156038. z4 = MULTIPLY(tmp12, FIX_1_306562965) + z5; /* c2+c6 */
  156039. z3 = MULTIPLY(tmp11, FIX_0_707106781); /* c4 */
  156040. z11 = tmp7 + z3; /* phase 5 */
  156041. z13 = tmp7 - z3;
  156042. dataptr[DCTSIZE*5] = z13 + z2; /* phase 6 */
  156043. dataptr[DCTSIZE*3] = z13 - z2;
  156044. dataptr[DCTSIZE*1] = z11 + z4;
  156045. dataptr[DCTSIZE*7] = z11 - z4;
  156046. dataptr++; /* advance pointer to next column */
  156047. }
  156048. }
  156049. #endif /* DCT_IFAST_SUPPORTED */
  156050. /********* End of inlined file: jfdctfst.c *********/
  156051. #undef FIX_0_541196100
  156052. /********* Start of inlined file: jidctflt.c *********/
  156053. #define JPEG_INTERNALS
  156054. #ifdef DCT_FLOAT_SUPPORTED
  156055. #if DCTSIZE != 8
  156056. Sorry, this code only copes with 8x8 DCTs. /* deliberate syntax err */
  156057. #endif
  156058. #define DEQUANTIZE(coef,quantval) (((FAST_FLOAT) (coef)) * (quantval))
  156059. GLOBAL(void)
  156060. jpeg_idct_float (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  156061. JCOEFPTR coef_block,
  156062. JSAMPARRAY output_buf, JDIMENSION output_col)
  156063. {
  156064. FAST_FLOAT tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;
  156065. FAST_FLOAT tmp10, tmp11, tmp12, tmp13;
  156066. FAST_FLOAT z5, z10, z11, z12, z13;
  156067. JCOEFPTR inptr;
  156068. FLOAT_MULT_TYPE * quantptr;
  156069. FAST_FLOAT * wsptr;
  156070. JSAMPROW outptr;
  156071. JSAMPLE *range_limit = IDCT_range_limit(cinfo);
  156072. int ctr;
  156073. FAST_FLOAT workspace[DCTSIZE2]; /* buffers data between passes */
  156074. SHIFT_TEMPS
  156075. inptr = coef_block;
  156076. quantptr = (FLOAT_MULT_TYPE *) compptr->dct_table;
  156077. wsptr = workspace;
  156078. for (ctr = DCTSIZE; ctr > 0; ctr--) {
  156079. if (inptr[DCTSIZE*1] == 0 && inptr[DCTSIZE*2] == 0 &&
  156080. inptr[DCTSIZE*3] == 0 && inptr[DCTSIZE*4] == 0 &&
  156081. inptr[DCTSIZE*5] == 0 && inptr[DCTSIZE*6] == 0 &&
  156082. inptr[DCTSIZE*7] == 0) {
  156083. FAST_FLOAT dcval = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);
  156084. wsptr[DCTSIZE*0] = dcval;
  156085. wsptr[DCTSIZE*1] = dcval;
  156086. wsptr[DCTSIZE*2] = dcval;
  156087. wsptr[DCTSIZE*3] = dcval;
  156088. wsptr[DCTSIZE*4] = dcval;
  156089. wsptr[DCTSIZE*5] = dcval;
  156090. wsptr[DCTSIZE*6] = dcval;
  156091. wsptr[DCTSIZE*7] = dcval;
  156092. inptr++; /* advance pointers to next column */
  156093. quantptr++;
  156094. wsptr++;
  156095. continue;
  156096. }
  156097. tmp0 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);
  156098. tmp1 = DEQUANTIZE(inptr[DCTSIZE*2], quantptr[DCTSIZE*2]);
  156099. tmp2 = DEQUANTIZE(inptr[DCTSIZE*4], quantptr[DCTSIZE*4]);
  156100. tmp3 = DEQUANTIZE(inptr[DCTSIZE*6], quantptr[DCTSIZE*6]);
  156101. tmp10 = tmp0 + tmp2; /* phase 3 */
  156102. tmp11 = tmp0 - tmp2;
  156103. tmp13 = tmp1 + tmp3; /* phases 5-3 */
  156104. tmp12 = (tmp1 - tmp3) * ((FAST_FLOAT) 1.414213562) - tmp13; /* 2*c4 */
  156105. tmp0 = tmp10 + tmp13; /* phase 2 */
  156106. tmp3 = tmp10 - tmp13;
  156107. tmp1 = tmp11 + tmp12;
  156108. tmp2 = tmp11 - tmp12;
  156109. tmp4 = DEQUANTIZE(inptr[DCTSIZE*1], quantptr[DCTSIZE*1]);
  156110. tmp5 = DEQUANTIZE(inptr[DCTSIZE*3], quantptr[DCTSIZE*3]);
  156111. tmp6 = DEQUANTIZE(inptr[DCTSIZE*5], quantptr[DCTSIZE*5]);
  156112. tmp7 = DEQUANTIZE(inptr[DCTSIZE*7], quantptr[DCTSIZE*7]);
  156113. z13 = tmp6 + tmp5; /* phase 6 */
  156114. z10 = tmp6 - tmp5;
  156115. z11 = tmp4 + tmp7;
  156116. z12 = tmp4 - tmp7;
  156117. tmp7 = z11 + z13; /* phase 5 */
  156118. tmp11 = (z11 - z13) * ((FAST_FLOAT) 1.414213562); /* 2*c4 */
  156119. z5 = (z10 + z12) * ((FAST_FLOAT) 1.847759065); /* 2*c2 */
  156120. tmp10 = ((FAST_FLOAT) 1.082392200) * z12 - z5; /* 2*(c2-c6) */
  156121. tmp12 = ((FAST_FLOAT) -2.613125930) * z10 + z5; /* -2*(c2+c6) */
  156122. tmp6 = tmp12 - tmp7; /* phase 2 */
  156123. tmp5 = tmp11 - tmp6;
  156124. tmp4 = tmp10 + tmp5;
  156125. wsptr[DCTSIZE*0] = tmp0 + tmp7;
  156126. wsptr[DCTSIZE*7] = tmp0 - tmp7;
  156127. wsptr[DCTSIZE*1] = tmp1 + tmp6;
  156128. wsptr[DCTSIZE*6] = tmp1 - tmp6;
  156129. wsptr[DCTSIZE*2] = tmp2 + tmp5;
  156130. wsptr[DCTSIZE*5] = tmp2 - tmp5;
  156131. wsptr[DCTSIZE*4] = tmp3 + tmp4;
  156132. wsptr[DCTSIZE*3] = tmp3 - tmp4;
  156133. inptr++; /* advance pointers to next column */
  156134. quantptr++;
  156135. wsptr++;
  156136. }
  156137. wsptr = workspace;
  156138. for (ctr = 0; ctr < DCTSIZE; ctr++) {
  156139. outptr = output_buf[ctr] + output_col;
  156140. tmp10 = wsptr[0] + wsptr[4];
  156141. tmp11 = wsptr[0] - wsptr[4];
  156142. tmp13 = wsptr[2] + wsptr[6];
  156143. tmp12 = (wsptr[2] - wsptr[6]) * ((FAST_FLOAT) 1.414213562) - tmp13;
  156144. tmp0 = tmp10 + tmp13;
  156145. tmp3 = tmp10 - tmp13;
  156146. tmp1 = tmp11 + tmp12;
  156147. tmp2 = tmp11 - tmp12;
  156148. z13 = wsptr[5] + wsptr[3];
  156149. z10 = wsptr[5] - wsptr[3];
  156150. z11 = wsptr[1] + wsptr[7];
  156151. z12 = wsptr[1] - wsptr[7];
  156152. tmp7 = z11 + z13;
  156153. tmp11 = (z11 - z13) * ((FAST_FLOAT) 1.414213562);
  156154. z5 = (z10 + z12) * ((FAST_FLOAT) 1.847759065); /* 2*c2 */
  156155. tmp10 = ((FAST_FLOAT) 1.082392200) * z12 - z5; /* 2*(c2-c6) */
  156156. tmp12 = ((FAST_FLOAT) -2.613125930) * z10 + z5; /* -2*(c2+c6) */
  156157. tmp6 = tmp12 - tmp7;
  156158. tmp5 = tmp11 - tmp6;
  156159. tmp4 = tmp10 + tmp5;
  156160. outptr[0] = range_limit[(int) DESCALE((INT32) (tmp0 + tmp7), 3)
  156161. & RANGE_MASK];
  156162. outptr[7] = range_limit[(int) DESCALE((INT32) (tmp0 - tmp7), 3)
  156163. & RANGE_MASK];
  156164. outptr[1] = range_limit[(int) DESCALE((INT32) (tmp1 + tmp6), 3)
  156165. & RANGE_MASK];
  156166. outptr[6] = range_limit[(int) DESCALE((INT32) (tmp1 - tmp6), 3)
  156167. & RANGE_MASK];
  156168. outptr[2] = range_limit[(int) DESCALE((INT32) (tmp2 + tmp5), 3)
  156169. & RANGE_MASK];
  156170. outptr[5] = range_limit[(int) DESCALE((INT32) (tmp2 - tmp5), 3)
  156171. & RANGE_MASK];
  156172. outptr[4] = range_limit[(int) DESCALE((INT32) (tmp3 + tmp4), 3)
  156173. & RANGE_MASK];
  156174. outptr[3] = range_limit[(int) DESCALE((INT32) (tmp3 - tmp4), 3)
  156175. & RANGE_MASK];
  156176. wsptr += DCTSIZE; /* advance pointer to next row */
  156177. }
  156178. }
  156179. #endif /* DCT_FLOAT_SUPPORTED */
  156180. /********* End of inlined file: jidctflt.c *********/
  156181. #undef CONST_BITS
  156182. #undef FIX_1_847759065
  156183. #undef MULTIPLY
  156184. #undef DEQUANTIZE
  156185. #undef DESCALE
  156186. /********* Start of inlined file: jidctfst.c *********/
  156187. #define JPEG_INTERNALS
  156188. #ifdef DCT_IFAST_SUPPORTED
  156189. #if DCTSIZE != 8
  156190. Sorry, this code only copes with 8x8 DCTs. /* deliberate syntax err */
  156191. #endif
  156192. #if BITS_IN_JSAMPLE == 8
  156193. #define CONST_BITS 8
  156194. #define PASS1_BITS 2
  156195. #else
  156196. #define CONST_BITS 8
  156197. #define PASS1_BITS 1 /* lose a little precision to avoid overflow */
  156198. #endif
  156199. #if CONST_BITS == 8
  156200. #define FIX_1_082392200 ((INT32) 277) /* FIX(1.082392200) */
  156201. #define FIX_1_414213562 ((INT32) 362) /* FIX(1.414213562) */
  156202. #define FIX_1_847759065 ((INT32) 473) /* FIX(1.847759065) */
  156203. #define FIX_2_613125930 ((INT32) 669) /* FIX(2.613125930) */
  156204. #else
  156205. #define FIX_1_082392200 FIX(1.082392200)
  156206. #define FIX_1_414213562 FIX(1.414213562)
  156207. #define FIX_1_847759065 FIX(1.847759065)
  156208. #define FIX_2_613125930 FIX(2.613125930)
  156209. #endif
  156210. #ifndef USE_ACCURATE_ROUNDING
  156211. #undef DESCALE
  156212. #define DESCALE(x,n) RIGHT_SHIFT(x, n)
  156213. #endif
  156214. #define MULTIPLY(var,const) ((DCTELEM) DESCALE((var) * (const), CONST_BITS))
  156215. #if BITS_IN_JSAMPLE == 8
  156216. #define DEQUANTIZE(coef,quantval) (((IFAST_MULT_TYPE) (coef)) * (quantval))
  156217. #else
  156218. #define DEQUANTIZE(coef,quantval) \
  156219. DESCALE((coef)*(quantval), IFAST_SCALE_BITS-PASS1_BITS)
  156220. #endif
  156221. #ifdef RIGHT_SHIFT_IS_UNSIGNED
  156222. #define ISHIFT_TEMPS DCTELEM ishift_temp;
  156223. #if BITS_IN_JSAMPLE == 8
  156224. #define DCTELEMBITS 16 /* DCTELEM may be 16 or 32 bits */
  156225. #else
  156226. #define DCTELEMBITS 32 /* DCTELEM must be 32 bits */
  156227. #endif
  156228. #define IRIGHT_SHIFT(x,shft) \
  156229. ((ishift_temp = (x)) < 0 ? \
  156230. (ishift_temp >> (shft)) | ((~((DCTELEM) 0)) << (DCTELEMBITS-(shft))) : \
  156231. (ishift_temp >> (shft)))
  156232. #else
  156233. #define ISHIFT_TEMPS
  156234. #define IRIGHT_SHIFT(x,shft) ((x) >> (shft))
  156235. #endif
  156236. #ifdef USE_ACCURATE_ROUNDING
  156237. #define IDESCALE(x,n) ((int) IRIGHT_SHIFT((x) + (1 << ((n)-1)), n))
  156238. #else
  156239. #define IDESCALE(x,n) ((int) IRIGHT_SHIFT(x, n))
  156240. #endif
  156241. GLOBAL(void)
  156242. jpeg_idct_ifast (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  156243. JCOEFPTR coef_block,
  156244. JSAMPARRAY output_buf, JDIMENSION output_col)
  156245. {
  156246. DCTELEM tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;
  156247. DCTELEM tmp10, tmp11, tmp12, tmp13;
  156248. DCTELEM z5, z10, z11, z12, z13;
  156249. JCOEFPTR inptr;
  156250. IFAST_MULT_TYPE * quantptr;
  156251. int * wsptr;
  156252. JSAMPROW outptr;
  156253. JSAMPLE *range_limit = IDCT_range_limit(cinfo);
  156254. int ctr;
  156255. int workspace[DCTSIZE2]; /* buffers data between passes */
  156256. SHIFT_TEMPS /* for DESCALE */
  156257. ISHIFT_TEMPS /* for IDESCALE */
  156258. inptr = coef_block;
  156259. quantptr = (IFAST_MULT_TYPE *) compptr->dct_table;
  156260. wsptr = workspace;
  156261. for (ctr = DCTSIZE; ctr > 0; ctr--) {
  156262. if (inptr[DCTSIZE*1] == 0 && inptr[DCTSIZE*2] == 0 &&
  156263. inptr[DCTSIZE*3] == 0 && inptr[DCTSIZE*4] == 0 &&
  156264. inptr[DCTSIZE*5] == 0 && inptr[DCTSIZE*6] == 0 &&
  156265. inptr[DCTSIZE*7] == 0) {
  156266. int dcval = (int) DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);
  156267. wsptr[DCTSIZE*0] = dcval;
  156268. wsptr[DCTSIZE*1] = dcval;
  156269. wsptr[DCTSIZE*2] = dcval;
  156270. wsptr[DCTSIZE*3] = dcval;
  156271. wsptr[DCTSIZE*4] = dcval;
  156272. wsptr[DCTSIZE*5] = dcval;
  156273. wsptr[DCTSIZE*6] = dcval;
  156274. wsptr[DCTSIZE*7] = dcval;
  156275. inptr++; /* advance pointers to next column */
  156276. quantptr++;
  156277. wsptr++;
  156278. continue;
  156279. }
  156280. tmp0 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);
  156281. tmp1 = DEQUANTIZE(inptr[DCTSIZE*2], quantptr[DCTSIZE*2]);
  156282. tmp2 = DEQUANTIZE(inptr[DCTSIZE*4], quantptr[DCTSIZE*4]);
  156283. tmp3 = DEQUANTIZE(inptr[DCTSIZE*6], quantptr[DCTSIZE*6]);
  156284. tmp10 = tmp0 + tmp2; /* phase 3 */
  156285. tmp11 = tmp0 - tmp2;
  156286. tmp13 = tmp1 + tmp3; /* phases 5-3 */
  156287. tmp12 = MULTIPLY(tmp1 - tmp3, FIX_1_414213562) - tmp13; /* 2*c4 */
  156288. tmp0 = tmp10 + tmp13; /* phase 2 */
  156289. tmp3 = tmp10 - tmp13;
  156290. tmp1 = tmp11 + tmp12;
  156291. tmp2 = tmp11 - tmp12;
  156292. tmp4 = DEQUANTIZE(inptr[DCTSIZE*1], quantptr[DCTSIZE*1]);
  156293. tmp5 = DEQUANTIZE(inptr[DCTSIZE*3], quantptr[DCTSIZE*3]);
  156294. tmp6 = DEQUANTIZE(inptr[DCTSIZE*5], quantptr[DCTSIZE*5]);
  156295. tmp7 = DEQUANTIZE(inptr[DCTSIZE*7], quantptr[DCTSIZE*7]);
  156296. z13 = tmp6 + tmp5; /* phase 6 */
  156297. z10 = tmp6 - tmp5;
  156298. z11 = tmp4 + tmp7;
  156299. z12 = tmp4 - tmp7;
  156300. tmp7 = z11 + z13; /* phase 5 */
  156301. tmp11 = MULTIPLY(z11 - z13, FIX_1_414213562); /* 2*c4 */
  156302. z5 = MULTIPLY(z10 + z12, FIX_1_847759065); /* 2*c2 */
  156303. tmp10 = MULTIPLY(z12, FIX_1_082392200) - z5; /* 2*(c2-c6) */
  156304. tmp12 = MULTIPLY(z10, - FIX_2_613125930) + z5; /* -2*(c2+c6) */
  156305. tmp6 = tmp12 - tmp7; /* phase 2 */
  156306. tmp5 = tmp11 - tmp6;
  156307. tmp4 = tmp10 + tmp5;
  156308. wsptr[DCTSIZE*0] = (int) (tmp0 + tmp7);
  156309. wsptr[DCTSIZE*7] = (int) (tmp0 - tmp7);
  156310. wsptr[DCTSIZE*1] = (int) (tmp1 + tmp6);
  156311. wsptr[DCTSIZE*6] = (int) (tmp1 - tmp6);
  156312. wsptr[DCTSIZE*2] = (int) (tmp2 + tmp5);
  156313. wsptr[DCTSIZE*5] = (int) (tmp2 - tmp5);
  156314. wsptr[DCTSIZE*4] = (int) (tmp3 + tmp4);
  156315. wsptr[DCTSIZE*3] = (int) (tmp3 - tmp4);
  156316. inptr++; /* advance pointers to next column */
  156317. quantptr++;
  156318. wsptr++;
  156319. }
  156320. wsptr = workspace;
  156321. for (ctr = 0; ctr < DCTSIZE; ctr++) {
  156322. outptr = output_buf[ctr] + output_col;
  156323. #ifndef NO_ZERO_ROW_TEST
  156324. if (wsptr[1] == 0 && wsptr[2] == 0 && wsptr[3] == 0 && wsptr[4] == 0 &&
  156325. wsptr[5] == 0 && wsptr[6] == 0 && wsptr[7] == 0) {
  156326. JSAMPLE dcval = range_limit[IDESCALE(wsptr[0], PASS1_BITS+3)
  156327. & RANGE_MASK];
  156328. outptr[0] = dcval;
  156329. outptr[1] = dcval;
  156330. outptr[2] = dcval;
  156331. outptr[3] = dcval;
  156332. outptr[4] = dcval;
  156333. outptr[5] = dcval;
  156334. outptr[6] = dcval;
  156335. outptr[7] = dcval;
  156336. wsptr += DCTSIZE; /* advance pointer to next row */
  156337. continue;
  156338. }
  156339. #endif
  156340. tmp10 = ((DCTELEM) wsptr[0] + (DCTELEM) wsptr[4]);
  156341. tmp11 = ((DCTELEM) wsptr[0] - (DCTELEM) wsptr[4]);
  156342. tmp13 = ((DCTELEM) wsptr[2] + (DCTELEM) wsptr[6]);
  156343. tmp12 = MULTIPLY((DCTELEM) wsptr[2] - (DCTELEM) wsptr[6], FIX_1_414213562)
  156344. - tmp13;
  156345. tmp0 = tmp10 + tmp13;
  156346. tmp3 = tmp10 - tmp13;
  156347. tmp1 = tmp11 + tmp12;
  156348. tmp2 = tmp11 - tmp12;
  156349. z13 = (DCTELEM) wsptr[5] + (DCTELEM) wsptr[3];
  156350. z10 = (DCTELEM) wsptr[5] - (DCTELEM) wsptr[3];
  156351. z11 = (DCTELEM) wsptr[1] + (DCTELEM) wsptr[7];
  156352. z12 = (DCTELEM) wsptr[1] - (DCTELEM) wsptr[7];
  156353. tmp7 = z11 + z13; /* phase 5 */
  156354. tmp11 = MULTIPLY(z11 - z13, FIX_1_414213562); /* 2*c4 */
  156355. z5 = MULTIPLY(z10 + z12, FIX_1_847759065); /* 2*c2 */
  156356. tmp10 = MULTIPLY(z12, FIX_1_082392200) - z5; /* 2*(c2-c6) */
  156357. tmp12 = MULTIPLY(z10, - FIX_2_613125930) + z5; /* -2*(c2+c6) */
  156358. tmp6 = tmp12 - tmp7; /* phase 2 */
  156359. tmp5 = tmp11 - tmp6;
  156360. tmp4 = tmp10 + tmp5;
  156361. outptr[0] = range_limit[IDESCALE(tmp0 + tmp7, PASS1_BITS+3)
  156362. & RANGE_MASK];
  156363. outptr[7] = range_limit[IDESCALE(tmp0 - tmp7, PASS1_BITS+3)
  156364. & RANGE_MASK];
  156365. outptr[1] = range_limit[IDESCALE(tmp1 + tmp6, PASS1_BITS+3)
  156366. & RANGE_MASK];
  156367. outptr[6] = range_limit[IDESCALE(tmp1 - tmp6, PASS1_BITS+3)
  156368. & RANGE_MASK];
  156369. outptr[2] = range_limit[IDESCALE(tmp2 + tmp5, PASS1_BITS+3)
  156370. & RANGE_MASK];
  156371. outptr[5] = range_limit[IDESCALE(tmp2 - tmp5, PASS1_BITS+3)
  156372. & RANGE_MASK];
  156373. outptr[4] = range_limit[IDESCALE(tmp3 + tmp4, PASS1_BITS+3)
  156374. & RANGE_MASK];
  156375. outptr[3] = range_limit[IDESCALE(tmp3 - tmp4, PASS1_BITS+3)
  156376. & RANGE_MASK];
  156377. wsptr += DCTSIZE; /* advance pointer to next row */
  156378. }
  156379. }
  156380. #endif /* DCT_IFAST_SUPPORTED */
  156381. /********* End of inlined file: jidctfst.c *********/
  156382. #undef CONST_BITS
  156383. #undef FIX_1_847759065
  156384. #undef MULTIPLY
  156385. #undef DEQUANTIZE
  156386. /********* Start of inlined file: jidctint.c *********/
  156387. #define JPEG_INTERNALS
  156388. #ifdef DCT_ISLOW_SUPPORTED
  156389. #if DCTSIZE != 8
  156390. Sorry, this code only copes with 8x8 DCTs. /* deliberate syntax err */
  156391. #endif
  156392. #if BITS_IN_JSAMPLE == 8
  156393. #define CONST_BITS 13
  156394. #define PASS1_BITS 2
  156395. #else
  156396. #define CONST_BITS 13
  156397. #define PASS1_BITS 1 /* lose a little precision to avoid overflow */
  156398. #endif
  156399. #if CONST_BITS == 13
  156400. #define FIX_0_298631336 ((INT32) 2446) /* FIX(0.298631336) */
  156401. #define FIX_0_390180644 ((INT32) 3196) /* FIX(0.390180644) */
  156402. #define FIX_0_541196100 ((INT32) 4433) /* FIX(0.541196100) */
  156403. #define FIX_0_765366865 ((INT32) 6270) /* FIX(0.765366865) */
  156404. #define FIX_0_899976223 ((INT32) 7373) /* FIX(0.899976223) */
  156405. #define FIX_1_175875602 ((INT32) 9633) /* FIX(1.175875602) */
  156406. #define FIX_1_501321110 ((INT32) 12299) /* FIX(1.501321110) */
  156407. #define FIX_1_847759065 ((INT32) 15137) /* FIX(1.847759065) */
  156408. #define FIX_1_961570560 ((INT32) 16069) /* FIX(1.961570560) */
  156409. #define FIX_2_053119869 ((INT32) 16819) /* FIX(2.053119869) */
  156410. #define FIX_2_562915447 ((INT32) 20995) /* FIX(2.562915447) */
  156411. #define FIX_3_072711026 ((INT32) 25172) /* FIX(3.072711026) */
  156412. #else
  156413. #define FIX_0_298631336 FIX(0.298631336)
  156414. #define FIX_0_390180644 FIX(0.390180644)
  156415. #define FIX_0_541196100 FIX(0.541196100)
  156416. #define FIX_0_765366865 FIX(0.765366865)
  156417. #define FIX_0_899976223 FIX(0.899976223)
  156418. #define FIX_1_175875602 FIX(1.175875602)
  156419. #define FIX_1_501321110 FIX(1.501321110)
  156420. #define FIX_1_847759065 FIX(1.847759065)
  156421. #define FIX_1_961570560 FIX(1.961570560)
  156422. #define FIX_2_053119869 FIX(2.053119869)
  156423. #define FIX_2_562915447 FIX(2.562915447)
  156424. #define FIX_3_072711026 FIX(3.072711026)
  156425. #endif
  156426. #if BITS_IN_JSAMPLE == 8
  156427. #define MULTIPLY(var,const) MULTIPLY16C16(var,const)
  156428. #else
  156429. #define MULTIPLY(var,const) ((var) * (const))
  156430. #endif
  156431. #define DEQUANTIZE(coef,quantval) (((ISLOW_MULT_TYPE) (coef)) * (quantval))
  156432. GLOBAL(void)
  156433. jpeg_idct_islow (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  156434. JCOEFPTR coef_block,
  156435. JSAMPARRAY output_buf, JDIMENSION output_col)
  156436. {
  156437. INT32 tmp0, tmp1, tmp2, tmp3;
  156438. INT32 tmp10, tmp11, tmp12, tmp13;
  156439. INT32 z1, z2, z3, z4, z5;
  156440. JCOEFPTR inptr;
  156441. ISLOW_MULT_TYPE * quantptr;
  156442. int * wsptr;
  156443. JSAMPROW outptr;
  156444. JSAMPLE *range_limit = IDCT_range_limit(cinfo);
  156445. int ctr;
  156446. int workspace[DCTSIZE2]; /* buffers data between passes */
  156447. SHIFT_TEMPS
  156448. inptr = coef_block;
  156449. quantptr = (ISLOW_MULT_TYPE *) compptr->dct_table;
  156450. wsptr = workspace;
  156451. for (ctr = DCTSIZE; ctr > 0; ctr--) {
  156452. if (inptr[DCTSIZE*1] == 0 && inptr[DCTSIZE*2] == 0 &&
  156453. inptr[DCTSIZE*3] == 0 && inptr[DCTSIZE*4] == 0 &&
  156454. inptr[DCTSIZE*5] == 0 && inptr[DCTSIZE*6] == 0 &&
  156455. inptr[DCTSIZE*7] == 0) {
  156456. int dcval = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]) << PASS1_BITS;
  156457. wsptr[DCTSIZE*0] = dcval;
  156458. wsptr[DCTSIZE*1] = dcval;
  156459. wsptr[DCTSIZE*2] = dcval;
  156460. wsptr[DCTSIZE*3] = dcval;
  156461. wsptr[DCTSIZE*4] = dcval;
  156462. wsptr[DCTSIZE*5] = dcval;
  156463. wsptr[DCTSIZE*6] = dcval;
  156464. wsptr[DCTSIZE*7] = dcval;
  156465. inptr++; /* advance pointers to next column */
  156466. quantptr++;
  156467. wsptr++;
  156468. continue;
  156469. }
  156470. z2 = DEQUANTIZE(inptr[DCTSIZE*2], quantptr[DCTSIZE*2]);
  156471. z3 = DEQUANTIZE(inptr[DCTSIZE*6], quantptr[DCTSIZE*6]);
  156472. z1 = MULTIPLY(z2 + z3, FIX_0_541196100);
  156473. tmp2 = z1 + MULTIPLY(z3, - FIX_1_847759065);
  156474. tmp3 = z1 + MULTIPLY(z2, FIX_0_765366865);
  156475. z2 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);
  156476. z3 = DEQUANTIZE(inptr[DCTSIZE*4], quantptr[DCTSIZE*4]);
  156477. tmp0 = (z2 + z3) << CONST_BITS;
  156478. tmp1 = (z2 - z3) << CONST_BITS;
  156479. tmp10 = tmp0 + tmp3;
  156480. tmp13 = tmp0 - tmp3;
  156481. tmp11 = tmp1 + tmp2;
  156482. tmp12 = tmp1 - tmp2;
  156483. tmp0 = DEQUANTIZE(inptr[DCTSIZE*7], quantptr[DCTSIZE*7]);
  156484. tmp1 = DEQUANTIZE(inptr[DCTSIZE*5], quantptr[DCTSIZE*5]);
  156485. tmp2 = DEQUANTIZE(inptr[DCTSIZE*3], quantptr[DCTSIZE*3]);
  156486. tmp3 = DEQUANTIZE(inptr[DCTSIZE*1], quantptr[DCTSIZE*1]);
  156487. z1 = tmp0 + tmp3;
  156488. z2 = tmp1 + tmp2;
  156489. z3 = tmp0 + tmp2;
  156490. z4 = tmp1 + tmp3;
  156491. z5 = MULTIPLY(z3 + z4, FIX_1_175875602); /* sqrt(2) * c3 */
  156492. tmp0 = MULTIPLY(tmp0, FIX_0_298631336); /* sqrt(2) * (-c1+c3+c5-c7) */
  156493. tmp1 = MULTIPLY(tmp1, FIX_2_053119869); /* sqrt(2) * ( c1+c3-c5+c7) */
  156494. tmp2 = MULTIPLY(tmp2, FIX_3_072711026); /* sqrt(2) * ( c1+c3+c5-c7) */
  156495. tmp3 = MULTIPLY(tmp3, FIX_1_501321110); /* sqrt(2) * ( c1+c3-c5-c7) */
  156496. z1 = MULTIPLY(z1, - FIX_0_899976223); /* sqrt(2) * (c7-c3) */
  156497. z2 = MULTIPLY(z2, - FIX_2_562915447); /* sqrt(2) * (-c1-c3) */
  156498. z3 = MULTIPLY(z3, - FIX_1_961570560); /* sqrt(2) * (-c3-c5) */
  156499. z4 = MULTIPLY(z4, - FIX_0_390180644); /* sqrt(2) * (c5-c3) */
  156500. z3 += z5;
  156501. z4 += z5;
  156502. tmp0 += z1 + z3;
  156503. tmp1 += z2 + z4;
  156504. tmp2 += z2 + z3;
  156505. tmp3 += z1 + z4;
  156506. wsptr[DCTSIZE*0] = (int) DESCALE(tmp10 + tmp3, CONST_BITS-PASS1_BITS);
  156507. wsptr[DCTSIZE*7] = (int) DESCALE(tmp10 - tmp3, CONST_BITS-PASS1_BITS);
  156508. wsptr[DCTSIZE*1] = (int) DESCALE(tmp11 + tmp2, CONST_BITS-PASS1_BITS);
  156509. wsptr[DCTSIZE*6] = (int) DESCALE(tmp11 - tmp2, CONST_BITS-PASS1_BITS);
  156510. wsptr[DCTSIZE*2] = (int) DESCALE(tmp12 + tmp1, CONST_BITS-PASS1_BITS);
  156511. wsptr[DCTSIZE*5] = (int) DESCALE(tmp12 - tmp1, CONST_BITS-PASS1_BITS);
  156512. wsptr[DCTSIZE*3] = (int) DESCALE(tmp13 + tmp0, CONST_BITS-PASS1_BITS);
  156513. wsptr[DCTSIZE*4] = (int) DESCALE(tmp13 - tmp0, CONST_BITS-PASS1_BITS);
  156514. inptr++; /* advance pointers to next column */
  156515. quantptr++;
  156516. wsptr++;
  156517. }
  156518. wsptr = workspace;
  156519. for (ctr = 0; ctr < DCTSIZE; ctr++) {
  156520. outptr = output_buf[ctr] + output_col;
  156521. #ifndef NO_ZERO_ROW_TEST
  156522. if (wsptr[1] == 0 && wsptr[2] == 0 && wsptr[3] == 0 && wsptr[4] == 0 &&
  156523. wsptr[5] == 0 && wsptr[6] == 0 && wsptr[7] == 0) {
  156524. JSAMPLE dcval = range_limit[(int) DESCALE((INT32) wsptr[0], PASS1_BITS+3)
  156525. & RANGE_MASK];
  156526. outptr[0] = dcval;
  156527. outptr[1] = dcval;
  156528. outptr[2] = dcval;
  156529. outptr[3] = dcval;
  156530. outptr[4] = dcval;
  156531. outptr[5] = dcval;
  156532. outptr[6] = dcval;
  156533. outptr[7] = dcval;
  156534. wsptr += DCTSIZE; /* advance pointer to next row */
  156535. continue;
  156536. }
  156537. #endif
  156538. z2 = (INT32) wsptr[2];
  156539. z3 = (INT32) wsptr[6];
  156540. z1 = MULTIPLY(z2 + z3, FIX_0_541196100);
  156541. tmp2 = z1 + MULTIPLY(z3, - FIX_1_847759065);
  156542. tmp3 = z1 + MULTIPLY(z2, FIX_0_765366865);
  156543. tmp0 = ((INT32) wsptr[0] + (INT32) wsptr[4]) << CONST_BITS;
  156544. tmp1 = ((INT32) wsptr[0] - (INT32) wsptr[4]) << CONST_BITS;
  156545. tmp10 = tmp0 + tmp3;
  156546. tmp13 = tmp0 - tmp3;
  156547. tmp11 = tmp1 + tmp2;
  156548. tmp12 = tmp1 - tmp2;
  156549. tmp0 = (INT32) wsptr[7];
  156550. tmp1 = (INT32) wsptr[5];
  156551. tmp2 = (INT32) wsptr[3];
  156552. tmp3 = (INT32) wsptr[1];
  156553. z1 = tmp0 + tmp3;
  156554. z2 = tmp1 + tmp2;
  156555. z3 = tmp0 + tmp2;
  156556. z4 = tmp1 + tmp3;
  156557. z5 = MULTIPLY(z3 + z4, FIX_1_175875602); /* sqrt(2) * c3 */
  156558. tmp0 = MULTIPLY(tmp0, FIX_0_298631336); /* sqrt(2) * (-c1+c3+c5-c7) */
  156559. tmp1 = MULTIPLY(tmp1, FIX_2_053119869); /* sqrt(2) * ( c1+c3-c5+c7) */
  156560. tmp2 = MULTIPLY(tmp2, FIX_3_072711026); /* sqrt(2) * ( c1+c3+c5-c7) */
  156561. tmp3 = MULTIPLY(tmp3, FIX_1_501321110); /* sqrt(2) * ( c1+c3-c5-c7) */
  156562. z1 = MULTIPLY(z1, - FIX_0_899976223); /* sqrt(2) * (c7-c3) */
  156563. z2 = MULTIPLY(z2, - FIX_2_562915447); /* sqrt(2) * (-c1-c3) */
  156564. z3 = MULTIPLY(z3, - FIX_1_961570560); /* sqrt(2) * (-c3-c5) */
  156565. z4 = MULTIPLY(z4, - FIX_0_390180644); /* sqrt(2) * (c5-c3) */
  156566. z3 += z5;
  156567. z4 += z5;
  156568. tmp0 += z1 + z3;
  156569. tmp1 += z2 + z4;
  156570. tmp2 += z2 + z3;
  156571. tmp3 += z1 + z4;
  156572. outptr[0] = range_limit[(int) DESCALE(tmp10 + tmp3,
  156573. CONST_BITS+PASS1_BITS+3)
  156574. & RANGE_MASK];
  156575. outptr[7] = range_limit[(int) DESCALE(tmp10 - tmp3,
  156576. CONST_BITS+PASS1_BITS+3)
  156577. & RANGE_MASK];
  156578. outptr[1] = range_limit[(int) DESCALE(tmp11 + tmp2,
  156579. CONST_BITS+PASS1_BITS+3)
  156580. & RANGE_MASK];
  156581. outptr[6] = range_limit[(int) DESCALE(tmp11 - tmp2,
  156582. CONST_BITS+PASS1_BITS+3)
  156583. & RANGE_MASK];
  156584. outptr[2] = range_limit[(int) DESCALE(tmp12 + tmp1,
  156585. CONST_BITS+PASS1_BITS+3)
  156586. & RANGE_MASK];
  156587. outptr[5] = range_limit[(int) DESCALE(tmp12 - tmp1,
  156588. CONST_BITS+PASS1_BITS+3)
  156589. & RANGE_MASK];
  156590. outptr[3] = range_limit[(int) DESCALE(tmp13 + tmp0,
  156591. CONST_BITS+PASS1_BITS+3)
  156592. & RANGE_MASK];
  156593. outptr[4] = range_limit[(int) DESCALE(tmp13 - tmp0,
  156594. CONST_BITS+PASS1_BITS+3)
  156595. & RANGE_MASK];
  156596. wsptr += DCTSIZE; /* advance pointer to next row */
  156597. }
  156598. }
  156599. #endif /* DCT_ISLOW_SUPPORTED */
  156600. /********* End of inlined file: jidctint.c *********/
  156601. /********* Start of inlined file: jidctred.c *********/
  156602. #define JPEG_INTERNALS
  156603. #ifdef IDCT_SCALING_SUPPORTED
  156604. #if DCTSIZE != 8
  156605. Sorry, this code only copes with 8x8 DCTs. /* deliberate syntax err */
  156606. #endif
  156607. #if BITS_IN_JSAMPLE == 8
  156608. #define CONST_BITS 13
  156609. #define PASS1_BITS 2
  156610. #else
  156611. #define CONST_BITS 13
  156612. #define PASS1_BITS 1 /* lose a little precision to avoid overflow */
  156613. #endif
  156614. #if CONST_BITS == 13
  156615. #define FIX_0_211164243 ((INT32) 1730) /* FIX(0.211164243) */
  156616. #define FIX_0_509795579 ((INT32) 4176) /* FIX(0.509795579) */
  156617. #define FIX_0_601344887 ((INT32) 4926) /* FIX(0.601344887) */
  156618. #define FIX_0_720959822 ((INT32) 5906) /* FIX(0.720959822) */
  156619. #define FIX_0_765366865 ((INT32) 6270) /* FIX(0.765366865) */
  156620. #define FIX_0_850430095 ((INT32) 6967) /* FIX(0.850430095) */
  156621. #define FIX_0_899976223 ((INT32) 7373) /* FIX(0.899976223) */
  156622. #define FIX_1_061594337 ((INT32) 8697) /* FIX(1.061594337) */
  156623. #define FIX_1_272758580 ((INT32) 10426) /* FIX(1.272758580) */
  156624. #define FIX_1_451774981 ((INT32) 11893) /* FIX(1.451774981) */
  156625. #define FIX_1_847759065 ((INT32) 15137) /* FIX(1.847759065) */
  156626. #define FIX_2_172734803 ((INT32) 17799) /* FIX(2.172734803) */
  156627. #define FIX_2_562915447 ((INT32) 20995) /* FIX(2.562915447) */
  156628. #define FIX_3_624509785 ((INT32) 29692) /* FIX(3.624509785) */
  156629. #else
  156630. #define FIX_0_211164243 FIX(0.211164243)
  156631. #define FIX_0_509795579 FIX(0.509795579)
  156632. #define FIX_0_601344887 FIX(0.601344887)
  156633. #define FIX_0_720959822 FIX(0.720959822)
  156634. #define FIX_0_765366865 FIX(0.765366865)
  156635. #define FIX_0_850430095 FIX(0.850430095)
  156636. #define FIX_0_899976223 FIX(0.899976223)
  156637. #define FIX_1_061594337 FIX(1.061594337)
  156638. #define FIX_1_272758580 FIX(1.272758580)
  156639. #define FIX_1_451774981 FIX(1.451774981)
  156640. #define FIX_1_847759065 FIX(1.847759065)
  156641. #define FIX_2_172734803 FIX(2.172734803)
  156642. #define FIX_2_562915447 FIX(2.562915447)
  156643. #define FIX_3_624509785 FIX(3.624509785)
  156644. #endif
  156645. #if BITS_IN_JSAMPLE == 8
  156646. #define MULTIPLY(var,const) MULTIPLY16C16(var,const)
  156647. #else
  156648. #define MULTIPLY(var,const) ((var) * (const))
  156649. #endif
  156650. #define DEQUANTIZE(coef,quantval) (((ISLOW_MULT_TYPE) (coef)) * (quantval))
  156651. GLOBAL(void)
  156652. jpeg_idct_4x4 (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  156653. JCOEFPTR coef_block,
  156654. JSAMPARRAY output_buf, JDIMENSION output_col)
  156655. {
  156656. INT32 tmp0, tmp2, tmp10, tmp12;
  156657. INT32 z1, z2, z3, z4;
  156658. JCOEFPTR inptr;
  156659. ISLOW_MULT_TYPE * quantptr;
  156660. int * wsptr;
  156661. JSAMPROW outptr;
  156662. JSAMPLE *range_limit = IDCT_range_limit(cinfo);
  156663. int ctr;
  156664. int workspace[DCTSIZE*4]; /* buffers data between passes */
  156665. SHIFT_TEMPS
  156666. inptr = coef_block;
  156667. quantptr = (ISLOW_MULT_TYPE *) compptr->dct_table;
  156668. wsptr = workspace;
  156669. for (ctr = DCTSIZE; ctr > 0; inptr++, quantptr++, wsptr++, ctr--) {
  156670. if (ctr == DCTSIZE-4)
  156671. continue;
  156672. if (inptr[DCTSIZE*1] == 0 && inptr[DCTSIZE*2] == 0 &&
  156673. inptr[DCTSIZE*3] == 0 && inptr[DCTSIZE*5] == 0 &&
  156674. inptr[DCTSIZE*6] == 0 && inptr[DCTSIZE*7] == 0) {
  156675. int dcval = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]) << PASS1_BITS;
  156676. wsptr[DCTSIZE*0] = dcval;
  156677. wsptr[DCTSIZE*1] = dcval;
  156678. wsptr[DCTSIZE*2] = dcval;
  156679. wsptr[DCTSIZE*3] = dcval;
  156680. continue;
  156681. }
  156682. tmp0 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);
  156683. tmp0 <<= (CONST_BITS+1);
  156684. z2 = DEQUANTIZE(inptr[DCTSIZE*2], quantptr[DCTSIZE*2]);
  156685. z3 = DEQUANTIZE(inptr[DCTSIZE*6], quantptr[DCTSIZE*6]);
  156686. tmp2 = MULTIPLY(z2, FIX_1_847759065) + MULTIPLY(z3, - FIX_0_765366865);
  156687. tmp10 = tmp0 + tmp2;
  156688. tmp12 = tmp0 - tmp2;
  156689. z1 = DEQUANTIZE(inptr[DCTSIZE*7], quantptr[DCTSIZE*7]);
  156690. z2 = DEQUANTIZE(inptr[DCTSIZE*5], quantptr[DCTSIZE*5]);
  156691. z3 = DEQUANTIZE(inptr[DCTSIZE*3], quantptr[DCTSIZE*3]);
  156692. z4 = DEQUANTIZE(inptr[DCTSIZE*1], quantptr[DCTSIZE*1]);
  156693. tmp0 = MULTIPLY(z1, - FIX_0_211164243) /* sqrt(2) * (c3-c1) */
  156694. + MULTIPLY(z2, FIX_1_451774981) /* sqrt(2) * (c3+c7) */
  156695. + MULTIPLY(z3, - FIX_2_172734803) /* sqrt(2) * (-c1-c5) */
  156696. + MULTIPLY(z4, FIX_1_061594337); /* sqrt(2) * (c5+c7) */
  156697. tmp2 = MULTIPLY(z1, - FIX_0_509795579) /* sqrt(2) * (c7-c5) */
  156698. + MULTIPLY(z2, - FIX_0_601344887) /* sqrt(2) * (c5-c1) */
  156699. + MULTIPLY(z3, FIX_0_899976223) /* sqrt(2) * (c3-c7) */
  156700. + MULTIPLY(z4, FIX_2_562915447); /* sqrt(2) * (c1+c3) */
  156701. wsptr[DCTSIZE*0] = (int) DESCALE(tmp10 + tmp2, CONST_BITS-PASS1_BITS+1);
  156702. wsptr[DCTSIZE*3] = (int) DESCALE(tmp10 - tmp2, CONST_BITS-PASS1_BITS+1);
  156703. wsptr[DCTSIZE*1] = (int) DESCALE(tmp12 + tmp0, CONST_BITS-PASS1_BITS+1);
  156704. wsptr[DCTSIZE*2] = (int) DESCALE(tmp12 - tmp0, CONST_BITS-PASS1_BITS+1);
  156705. }
  156706. wsptr = workspace;
  156707. for (ctr = 0; ctr < 4; ctr++) {
  156708. outptr = output_buf[ctr] + output_col;
  156709. #ifndef NO_ZERO_ROW_TEST
  156710. if (wsptr[1] == 0 && wsptr[2] == 0 && wsptr[3] == 0 &&
  156711. wsptr[5] == 0 && wsptr[6] == 0 && wsptr[7] == 0) {
  156712. JSAMPLE dcval = range_limit[(int) DESCALE((INT32) wsptr[0], PASS1_BITS+3)
  156713. & RANGE_MASK];
  156714. outptr[0] = dcval;
  156715. outptr[1] = dcval;
  156716. outptr[2] = dcval;
  156717. outptr[3] = dcval;
  156718. wsptr += DCTSIZE; /* advance pointer to next row */
  156719. continue;
  156720. }
  156721. #endif
  156722. tmp0 = ((INT32) wsptr[0]) << (CONST_BITS+1);
  156723. tmp2 = MULTIPLY((INT32) wsptr[2], FIX_1_847759065)
  156724. + MULTIPLY((INT32) wsptr[6], - FIX_0_765366865);
  156725. tmp10 = tmp0 + tmp2;
  156726. tmp12 = tmp0 - tmp2;
  156727. z1 = (INT32) wsptr[7];
  156728. z2 = (INT32) wsptr[5];
  156729. z3 = (INT32) wsptr[3];
  156730. z4 = (INT32) wsptr[1];
  156731. tmp0 = MULTIPLY(z1, - FIX_0_211164243) /* sqrt(2) * (c3-c1) */
  156732. + MULTIPLY(z2, FIX_1_451774981) /* sqrt(2) * (c3+c7) */
  156733. + MULTIPLY(z3, - FIX_2_172734803) /* sqrt(2) * (-c1-c5) */
  156734. + MULTIPLY(z4, FIX_1_061594337); /* sqrt(2) * (c5+c7) */
  156735. tmp2 = MULTIPLY(z1, - FIX_0_509795579) /* sqrt(2) * (c7-c5) */
  156736. + MULTIPLY(z2, - FIX_0_601344887) /* sqrt(2) * (c5-c1) */
  156737. + MULTIPLY(z3, FIX_0_899976223) /* sqrt(2) * (c3-c7) */
  156738. + MULTIPLY(z4, FIX_2_562915447); /* sqrt(2) * (c1+c3) */
  156739. outptr[0] = range_limit[(int) DESCALE(tmp10 + tmp2,
  156740. CONST_BITS+PASS1_BITS+3+1)
  156741. & RANGE_MASK];
  156742. outptr[3] = range_limit[(int) DESCALE(tmp10 - tmp2,
  156743. CONST_BITS+PASS1_BITS+3+1)
  156744. & RANGE_MASK];
  156745. outptr[1] = range_limit[(int) DESCALE(tmp12 + tmp0,
  156746. CONST_BITS+PASS1_BITS+3+1)
  156747. & RANGE_MASK];
  156748. outptr[2] = range_limit[(int) DESCALE(tmp12 - tmp0,
  156749. CONST_BITS+PASS1_BITS+3+1)
  156750. & RANGE_MASK];
  156751. wsptr += DCTSIZE; /* advance pointer to next row */
  156752. }
  156753. }
  156754. GLOBAL(void)
  156755. jpeg_idct_2x2 (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  156756. JCOEFPTR coef_block,
  156757. JSAMPARRAY output_buf, JDIMENSION output_col)
  156758. {
  156759. INT32 tmp0, tmp10, z1;
  156760. JCOEFPTR inptr;
  156761. ISLOW_MULT_TYPE * quantptr;
  156762. int * wsptr;
  156763. JSAMPROW outptr;
  156764. JSAMPLE *range_limit = IDCT_range_limit(cinfo);
  156765. int ctr;
  156766. int workspace[DCTSIZE*2]; /* buffers data between passes */
  156767. SHIFT_TEMPS
  156768. inptr = coef_block;
  156769. quantptr = (ISLOW_MULT_TYPE *) compptr->dct_table;
  156770. wsptr = workspace;
  156771. for (ctr = DCTSIZE; ctr > 0; inptr++, quantptr++, wsptr++, ctr--) {
  156772. if (ctr == DCTSIZE-2 || ctr == DCTSIZE-4 || ctr == DCTSIZE-6)
  156773. continue;
  156774. if (inptr[DCTSIZE*1] == 0 && inptr[DCTSIZE*3] == 0 &&
  156775. inptr[DCTSIZE*5] == 0 && inptr[DCTSIZE*7] == 0) {
  156776. int dcval = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]) << PASS1_BITS;
  156777. wsptr[DCTSIZE*0] = dcval;
  156778. wsptr[DCTSIZE*1] = dcval;
  156779. continue;
  156780. }
  156781. z1 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);
  156782. tmp10 = z1 << (CONST_BITS+2);
  156783. z1 = DEQUANTIZE(inptr[DCTSIZE*7], quantptr[DCTSIZE*7]);
  156784. tmp0 = MULTIPLY(z1, - FIX_0_720959822); /* sqrt(2) * (c7-c5+c3-c1) */
  156785. z1 = DEQUANTIZE(inptr[DCTSIZE*5], quantptr[DCTSIZE*5]);
  156786. tmp0 += MULTIPLY(z1, FIX_0_850430095); /* sqrt(2) * (-c1+c3+c5+c7) */
  156787. z1 = DEQUANTIZE(inptr[DCTSIZE*3], quantptr[DCTSIZE*3]);
  156788. tmp0 += MULTIPLY(z1, - FIX_1_272758580); /* sqrt(2) * (-c1+c3-c5-c7) */
  156789. z1 = DEQUANTIZE(inptr[DCTSIZE*1], quantptr[DCTSIZE*1]);
  156790. tmp0 += MULTIPLY(z1, FIX_3_624509785); /* sqrt(2) * (c1+c3+c5+c7) */
  156791. wsptr[DCTSIZE*0] = (int) DESCALE(tmp10 + tmp0, CONST_BITS-PASS1_BITS+2);
  156792. wsptr[DCTSIZE*1] = (int) DESCALE(tmp10 - tmp0, CONST_BITS-PASS1_BITS+2);
  156793. }
  156794. wsptr = workspace;
  156795. for (ctr = 0; ctr < 2; ctr++) {
  156796. outptr = output_buf[ctr] + output_col;
  156797. #ifndef NO_ZERO_ROW_TEST
  156798. if (wsptr[1] == 0 && wsptr[3] == 0 && wsptr[5] == 0 && wsptr[7] == 0) {
  156799. JSAMPLE dcval = range_limit[(int) DESCALE((INT32) wsptr[0], PASS1_BITS+3)
  156800. & RANGE_MASK];
  156801. outptr[0] = dcval;
  156802. outptr[1] = dcval;
  156803. wsptr += DCTSIZE; /* advance pointer to next row */
  156804. continue;
  156805. }
  156806. #endif
  156807. tmp10 = ((INT32) wsptr[0]) << (CONST_BITS+2);
  156808. tmp0 = MULTIPLY((INT32) wsptr[7], - FIX_0_720959822) /* sqrt(2) * (c7-c5+c3-c1) */
  156809. + MULTIPLY((INT32) wsptr[5], FIX_0_850430095) /* sqrt(2) * (-c1+c3+c5+c7) */
  156810. + MULTIPLY((INT32) wsptr[3], - FIX_1_272758580) /* sqrt(2) * (-c1+c3-c5-c7) */
  156811. + MULTIPLY((INT32) wsptr[1], FIX_3_624509785); /* sqrt(2) * (c1+c3+c5+c7) */
  156812. outptr[0] = range_limit[(int) DESCALE(tmp10 + tmp0,
  156813. CONST_BITS+PASS1_BITS+3+2)
  156814. & RANGE_MASK];
  156815. outptr[1] = range_limit[(int) DESCALE(tmp10 - tmp0,
  156816. CONST_BITS+PASS1_BITS+3+2)
  156817. & RANGE_MASK];
  156818. wsptr += DCTSIZE; /* advance pointer to next row */
  156819. }
  156820. }
  156821. GLOBAL(void)
  156822. jpeg_idct_1x1 (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  156823. JCOEFPTR coef_block,
  156824. JSAMPARRAY output_buf, JDIMENSION output_col)
  156825. {
  156826. int dcval;
  156827. ISLOW_MULT_TYPE * quantptr;
  156828. JSAMPLE *range_limit = IDCT_range_limit(cinfo);
  156829. SHIFT_TEMPS
  156830. quantptr = (ISLOW_MULT_TYPE *) compptr->dct_table;
  156831. dcval = DEQUANTIZE(coef_block[0], quantptr[0]);
  156832. dcval = (int) DESCALE((INT32) dcval, 3);
  156833. output_buf[0][output_col] = range_limit[dcval & RANGE_MASK];
  156834. }
  156835. #endif /* IDCT_SCALING_SUPPORTED */
  156836. /********* End of inlined file: jidctred.c *********/
  156837. /********* Start of inlined file: jmemmgr.c *********/
  156838. #define JPEG_INTERNALS
  156839. #define AM_MEMORY_MANAGER /* we define jvirt_Xarray_control structs */
  156840. /********* Start of inlined file: jmemsys.h *********/
  156841. #ifndef __jmemsys_h__
  156842. #define __jmemsys_h__
  156843. #ifdef NEED_SHORT_EXTERNAL_NAMES
  156844. #define jpeg_get_small jGetSmall
  156845. #define jpeg_free_small jFreeSmall
  156846. #define jpeg_get_large jGetLarge
  156847. #define jpeg_free_large jFreeLarge
  156848. #define jpeg_mem_available jMemAvail
  156849. #define jpeg_open_backing_store jOpenBackStore
  156850. #define jpeg_mem_init jMemInit
  156851. #define jpeg_mem_term jMemTerm
  156852. #endif /* NEED_SHORT_EXTERNAL_NAMES */
  156853. EXTERN(void *) jpeg_get_small JPP((j_common_ptr cinfo, size_t sizeofobject));
  156854. EXTERN(void) jpeg_free_small JPP((j_common_ptr cinfo, void * object,
  156855. size_t sizeofobject));
  156856. EXTERN(void FAR *) jpeg_get_large JPP((j_common_ptr cinfo,
  156857. size_t sizeofobject));
  156858. EXTERN(void) jpeg_free_large JPP((j_common_ptr cinfo, void FAR * object,
  156859. size_t sizeofobject));
  156860. #ifndef MAX_ALLOC_CHUNK /* may be overridden in jconfig.h */
  156861. #define MAX_ALLOC_CHUNK 1000000000L
  156862. #endif
  156863. EXTERN(long) jpeg_mem_available JPP((j_common_ptr cinfo,
  156864. long min_bytes_needed,
  156865. long max_bytes_needed,
  156866. long already_allocated));
  156867. #define TEMP_NAME_LENGTH 64 /* max length of a temporary file's name */
  156868. #ifdef USE_MSDOS_MEMMGR /* DOS-specific junk */
  156869. typedef unsigned short XMSH; /* type of extended-memory handles */
  156870. typedef unsigned short EMSH; /* type of expanded-memory handles */
  156871. typedef union {
  156872. short file_handle; /* DOS file handle if it's a temp file */
  156873. XMSH xms_handle; /* handle if it's a chunk of XMS */
  156874. EMSH ems_handle; /* handle if it's a chunk of EMS */
  156875. } handle_union;
  156876. #endif /* USE_MSDOS_MEMMGR */
  156877. #ifdef USE_MAC_MEMMGR /* Mac-specific junk */
  156878. #include <Files.h>
  156879. #endif /* USE_MAC_MEMMGR */
  156880. //typedef struct backing_store_struct * backing_store_ptr;
  156881. typedef struct backing_store_struct {
  156882. JMETHOD(void, read_backing_store, (j_common_ptr cinfo,
  156883. struct backing_store_struct *info,
  156884. void FAR * buffer_address,
  156885. long file_offset, long byte_count));
  156886. JMETHOD(void, write_backing_store, (j_common_ptr cinfo,
  156887. struct backing_store_struct *info,
  156888. void FAR * buffer_address,
  156889. long file_offset, long byte_count));
  156890. JMETHOD(void, close_backing_store, (j_common_ptr cinfo,
  156891. struct backing_store_struct *info));
  156892. #ifdef USE_MSDOS_MEMMGR
  156893. handle_union handle; /* reference to backing-store storage object */
  156894. char temp_name[TEMP_NAME_LENGTH]; /* name if it's a file */
  156895. #else
  156896. #ifdef USE_MAC_MEMMGR
  156897. short temp_file; /* file reference number to temp file */
  156898. FSSpec tempSpec; /* the FSSpec for the temp file */
  156899. char temp_name[TEMP_NAME_LENGTH]; /* name if it's a file */
  156900. #else
  156901. FILE * temp_file; /* stdio reference to temp file */
  156902. char temp_name[TEMP_NAME_LENGTH]; /* name of temp file */
  156903. #endif
  156904. #endif
  156905. } backing_store_info;
  156906. EXTERN(void) jpeg_open_backing_store JPP((j_common_ptr cinfo,
  156907. struct backing_store_struct *info,
  156908. long total_bytes_needed));
  156909. EXTERN(long) jpeg_mem_init JPP((j_common_ptr cinfo));
  156910. EXTERN(void) jpeg_mem_term JPP((j_common_ptr cinfo));
  156911. #endif
  156912. /********* End of inlined file: jmemsys.h *********/
  156913. #ifndef NO_GETENV
  156914. #ifndef HAVE_STDLIB_H /* <stdlib.h> should declare getenv() */
  156915. extern char * getenv JPP((const char * name));
  156916. #endif
  156917. #endif
  156918. #ifndef ALIGN_TYPE /* so can override from jconfig.h */
  156919. #define ALIGN_TYPE double
  156920. #endif
  156921. typedef union small_pool_struct * small_pool_ptr;
  156922. typedef union small_pool_struct {
  156923. struct {
  156924. small_pool_ptr next; /* next in list of pools */
  156925. size_t bytes_used; /* how many bytes already used within pool */
  156926. size_t bytes_left; /* bytes still available in this pool */
  156927. } hdr;
  156928. ALIGN_TYPE dummy; /* included in union to ensure alignment */
  156929. } small_pool_hdr;
  156930. typedef union large_pool_struct FAR * large_pool_ptr;
  156931. typedef union large_pool_struct {
  156932. struct {
  156933. large_pool_ptr next; /* next in list of pools */
  156934. size_t bytes_used; /* how many bytes already used within pool */
  156935. size_t bytes_left; /* bytes still available in this pool */
  156936. } hdr;
  156937. ALIGN_TYPE dummy; /* included in union to ensure alignment */
  156938. } large_pool_hdr;
  156939. typedef struct {
  156940. struct jpeg_memory_mgr pub; /* public fields */
  156941. small_pool_ptr small_list[JPOOL_NUMPOOLS];
  156942. large_pool_ptr large_list[JPOOL_NUMPOOLS];
  156943. jvirt_sarray_ptr virt_sarray_list;
  156944. jvirt_barray_ptr virt_barray_list;
  156945. long total_space_allocated;
  156946. JDIMENSION last_rowsperchunk; /* from most recent alloc_sarray/barray */
  156947. } my_memory_mgr;
  156948. typedef my_memory_mgr * my_mem_ptr;
  156949. struct jvirt_sarray_control {
  156950. JSAMPARRAY mem_buffer; /* => the in-memory buffer */
  156951. JDIMENSION rows_in_array; /* total virtual array height */
  156952. JDIMENSION samplesperrow; /* width of array (and of memory buffer) */
  156953. JDIMENSION maxaccess; /* max rows accessed by access_virt_sarray */
  156954. JDIMENSION rows_in_mem; /* height of memory buffer */
  156955. JDIMENSION rowsperchunk; /* allocation chunk size in mem_buffer */
  156956. JDIMENSION cur_start_row; /* first logical row # in the buffer */
  156957. JDIMENSION first_undef_row; /* row # of first uninitialized row */
  156958. boolean pre_zero; /* pre-zero mode requested? */
  156959. boolean dirty; /* do current buffer contents need written? */
  156960. boolean b_s_open; /* is backing-store data valid? */
  156961. jvirt_sarray_ptr next; /* link to next virtual sarray control block */
  156962. backing_store_info b_s_info; /* System-dependent control info */
  156963. };
  156964. struct jvirt_barray_control {
  156965. JBLOCKARRAY mem_buffer; /* => the in-memory buffer */
  156966. JDIMENSION rows_in_array; /* total virtual array height */
  156967. JDIMENSION blocksperrow; /* width of array (and of memory buffer) */
  156968. JDIMENSION maxaccess; /* max rows accessed by access_virt_barray */
  156969. JDIMENSION rows_in_mem; /* height of memory buffer */
  156970. JDIMENSION rowsperchunk; /* allocation chunk size in mem_buffer */
  156971. JDIMENSION cur_start_row; /* first logical row # in the buffer */
  156972. JDIMENSION first_undef_row; /* row # of first uninitialized row */
  156973. boolean pre_zero; /* pre-zero mode requested? */
  156974. boolean dirty; /* do current buffer contents need written? */
  156975. boolean b_s_open; /* is backing-store data valid? */
  156976. jvirt_barray_ptr next; /* link to next virtual barray control block */
  156977. backing_store_info b_s_info; /* System-dependent control info */
  156978. };
  156979. #ifdef MEM_STATS /* optional extra stuff for statistics */
  156980. LOCAL(void)
  156981. print_mem_stats (j_common_ptr cinfo, int pool_id)
  156982. {
  156983. my_mem_ptr mem = (my_mem_ptr) cinfo->mem;
  156984. small_pool_ptr shdr_ptr;
  156985. large_pool_ptr lhdr_ptr;
  156986. fprintf(stderr, "Freeing pool %d, total space = %ld\n",
  156987. pool_id, mem->total_space_allocated);
  156988. for (lhdr_ptr = mem->large_list[pool_id]; lhdr_ptr != NULL;
  156989. lhdr_ptr = lhdr_ptr->hdr.next) {
  156990. fprintf(stderr, " Large chunk used %ld\n",
  156991. (long) lhdr_ptr->hdr.bytes_used);
  156992. }
  156993. for (shdr_ptr = mem->small_list[pool_id]; shdr_ptr != NULL;
  156994. shdr_ptr = shdr_ptr->hdr.next) {
  156995. fprintf(stderr, " Small chunk used %ld free %ld\n",
  156996. (long) shdr_ptr->hdr.bytes_used,
  156997. (long) shdr_ptr->hdr.bytes_left);
  156998. }
  156999. }
  157000. #endif /* MEM_STATS */
  157001. LOCAL(void)
  157002. out_of_memory (j_common_ptr cinfo, int which)
  157003. {
  157004. #ifdef MEM_STATS
  157005. cinfo->err->trace_level = 2; /* force self_destruct to report stats */
  157006. #endif
  157007. ERREXIT1(cinfo, JERR_OUT_OF_MEMORY, which);
  157008. }
  157009. static const size_t first_pool_slop[JPOOL_NUMPOOLS] =
  157010. {
  157011. 1600, /* first PERMANENT pool */
  157012. 16000 /* first IMAGE pool */
  157013. };
  157014. static const size_t extra_pool_slop[JPOOL_NUMPOOLS] =
  157015. {
  157016. 0, /* additional PERMANENT pools */
  157017. 5000 /* additional IMAGE pools */
  157018. };
  157019. #define MIN_SLOP 50 /* greater than 0 to avoid futile looping */
  157020. METHODDEF(void *)
  157021. alloc_small (j_common_ptr cinfo, int pool_id, size_t sizeofobject)
  157022. {
  157023. my_mem_ptr mem = (my_mem_ptr) cinfo->mem;
  157024. small_pool_ptr hdr_ptr, prev_hdr_ptr;
  157025. char * data_ptr;
  157026. size_t odd_bytes, min_request, slop;
  157027. if (sizeofobject > (size_t) (MAX_ALLOC_CHUNK-SIZEOF(small_pool_hdr)))
  157028. out_of_memory(cinfo, 1); /* request exceeds malloc's ability */
  157029. odd_bytes = sizeofobject % SIZEOF(ALIGN_TYPE);
  157030. if (odd_bytes > 0)
  157031. sizeofobject += SIZEOF(ALIGN_TYPE) - odd_bytes;
  157032. if (pool_id < 0 || pool_id >= JPOOL_NUMPOOLS)
  157033. ERREXIT1(cinfo, JERR_BAD_POOL_ID, pool_id); /* safety check */
  157034. prev_hdr_ptr = NULL;
  157035. hdr_ptr = mem->small_list[pool_id];
  157036. while (hdr_ptr != NULL) {
  157037. if (hdr_ptr->hdr.bytes_left >= sizeofobject)
  157038. break; /* found pool with enough space */
  157039. prev_hdr_ptr = hdr_ptr;
  157040. hdr_ptr = hdr_ptr->hdr.next;
  157041. }
  157042. if (hdr_ptr == NULL) {
  157043. min_request = sizeofobject + SIZEOF(small_pool_hdr);
  157044. if (prev_hdr_ptr == NULL) /* first pool in class? */
  157045. slop = first_pool_slop[pool_id];
  157046. else
  157047. slop = extra_pool_slop[pool_id];
  157048. if (slop > (size_t) (MAX_ALLOC_CHUNK-min_request))
  157049. slop = (size_t) (MAX_ALLOC_CHUNK-min_request);
  157050. for (;;) {
  157051. hdr_ptr = (small_pool_ptr) jpeg_get_small(cinfo, min_request + slop);
  157052. if (hdr_ptr != NULL)
  157053. break;
  157054. slop /= 2;
  157055. if (slop < MIN_SLOP) /* give up when it gets real small */
  157056. out_of_memory(cinfo, 2); /* jpeg_get_small failed */
  157057. }
  157058. mem->total_space_allocated += min_request + slop;
  157059. hdr_ptr->hdr.next = NULL;
  157060. hdr_ptr->hdr.bytes_used = 0;
  157061. hdr_ptr->hdr.bytes_left = sizeofobject + slop;
  157062. if (prev_hdr_ptr == NULL) /* first pool in class? */
  157063. mem->small_list[pool_id] = hdr_ptr;
  157064. else
  157065. prev_hdr_ptr->hdr.next = hdr_ptr;
  157066. }
  157067. data_ptr = (char *) (hdr_ptr + 1); /* point to first data byte in pool */
  157068. data_ptr += hdr_ptr->hdr.bytes_used; /* point to place for object */
  157069. hdr_ptr->hdr.bytes_used += sizeofobject;
  157070. hdr_ptr->hdr.bytes_left -= sizeofobject;
  157071. return (void *) data_ptr;
  157072. }
  157073. METHODDEF(void FAR *)
  157074. alloc_large (j_common_ptr cinfo, int pool_id, size_t sizeofobject)
  157075. {
  157076. my_mem_ptr mem = (my_mem_ptr) cinfo->mem;
  157077. large_pool_ptr hdr_ptr;
  157078. size_t odd_bytes;
  157079. if (sizeofobject > (size_t) (MAX_ALLOC_CHUNK-SIZEOF(large_pool_hdr)))
  157080. out_of_memory(cinfo, 3); /* request exceeds malloc's ability */
  157081. odd_bytes = sizeofobject % SIZEOF(ALIGN_TYPE);
  157082. if (odd_bytes > 0)
  157083. sizeofobject += SIZEOF(ALIGN_TYPE) - odd_bytes;
  157084. if (pool_id < 0 || pool_id >= JPOOL_NUMPOOLS)
  157085. ERREXIT1(cinfo, JERR_BAD_POOL_ID, pool_id); /* safety check */
  157086. hdr_ptr = (large_pool_ptr) jpeg_get_large(cinfo, sizeofobject +
  157087. SIZEOF(large_pool_hdr));
  157088. if (hdr_ptr == NULL)
  157089. out_of_memory(cinfo, 4); /* jpeg_get_large failed */
  157090. mem->total_space_allocated += sizeofobject + SIZEOF(large_pool_hdr);
  157091. hdr_ptr->hdr.next = mem->large_list[pool_id];
  157092. hdr_ptr->hdr.bytes_used = sizeofobject;
  157093. hdr_ptr->hdr.bytes_left = 0;
  157094. mem->large_list[pool_id] = hdr_ptr;
  157095. return (void FAR *) (hdr_ptr + 1); /* point to first data byte in pool */
  157096. }
  157097. METHODDEF(JSAMPARRAY)
  157098. alloc_sarray (j_common_ptr cinfo, int pool_id,
  157099. JDIMENSION samplesperrow, JDIMENSION numrows)
  157100. {
  157101. my_mem_ptr mem = (my_mem_ptr) cinfo->mem;
  157102. JSAMPARRAY result;
  157103. JSAMPROW workspace;
  157104. JDIMENSION rowsperchunk, currow, i;
  157105. long ltemp;
  157106. ltemp = (MAX_ALLOC_CHUNK-SIZEOF(large_pool_hdr)) /
  157107. ((long) samplesperrow * SIZEOF(JSAMPLE));
  157108. if (ltemp <= 0)
  157109. ERREXIT(cinfo, JERR_WIDTH_OVERFLOW);
  157110. if (ltemp < (long) numrows)
  157111. rowsperchunk = (JDIMENSION) ltemp;
  157112. else
  157113. rowsperchunk = numrows;
  157114. mem->last_rowsperchunk = rowsperchunk;
  157115. result = (JSAMPARRAY) alloc_small(cinfo, pool_id,
  157116. (size_t) (numrows * SIZEOF(JSAMPROW)));
  157117. currow = 0;
  157118. while (currow < numrows) {
  157119. rowsperchunk = MIN(rowsperchunk, numrows - currow);
  157120. workspace = (JSAMPROW) alloc_large(cinfo, pool_id,
  157121. (size_t) ((size_t) rowsperchunk * (size_t) samplesperrow
  157122. * SIZEOF(JSAMPLE)));
  157123. for (i = rowsperchunk; i > 0; i--) {
  157124. result[currow++] = workspace;
  157125. workspace += samplesperrow;
  157126. }
  157127. }
  157128. return result;
  157129. }
  157130. METHODDEF(JBLOCKARRAY)
  157131. alloc_barray (j_common_ptr cinfo, int pool_id,
  157132. JDIMENSION blocksperrow, JDIMENSION numrows)
  157133. {
  157134. my_mem_ptr mem = (my_mem_ptr) cinfo->mem;
  157135. JBLOCKARRAY result;
  157136. JBLOCKROW workspace;
  157137. JDIMENSION rowsperchunk, currow, i;
  157138. long ltemp;
  157139. ltemp = (MAX_ALLOC_CHUNK-SIZEOF(large_pool_hdr)) /
  157140. ((long) blocksperrow * SIZEOF(JBLOCK));
  157141. if (ltemp <= 0)
  157142. ERREXIT(cinfo, JERR_WIDTH_OVERFLOW);
  157143. if (ltemp < (long) numrows)
  157144. rowsperchunk = (JDIMENSION) ltemp;
  157145. else
  157146. rowsperchunk = numrows;
  157147. mem->last_rowsperchunk = rowsperchunk;
  157148. result = (JBLOCKARRAY) alloc_small(cinfo, pool_id,
  157149. (size_t) (numrows * SIZEOF(JBLOCKROW)));
  157150. currow = 0;
  157151. while (currow < numrows) {
  157152. rowsperchunk = MIN(rowsperchunk, numrows - currow);
  157153. workspace = (JBLOCKROW) alloc_large(cinfo, pool_id,
  157154. (size_t) ((size_t) rowsperchunk * (size_t) blocksperrow
  157155. * SIZEOF(JBLOCK)));
  157156. for (i = rowsperchunk; i > 0; i--) {
  157157. result[currow++] = workspace;
  157158. workspace += blocksperrow;
  157159. }
  157160. }
  157161. return result;
  157162. }
  157163. METHODDEF(jvirt_sarray_ptr)
  157164. request_virt_sarray (j_common_ptr cinfo, int pool_id, boolean pre_zero,
  157165. JDIMENSION samplesperrow, JDIMENSION numrows,
  157166. JDIMENSION maxaccess)
  157167. {
  157168. my_mem_ptr mem = (my_mem_ptr) cinfo->mem;
  157169. jvirt_sarray_ptr result;
  157170. if (pool_id != JPOOL_IMAGE)
  157171. ERREXIT1(cinfo, JERR_BAD_POOL_ID, pool_id); /* safety check */
  157172. result = (jvirt_sarray_ptr) alloc_small(cinfo, pool_id,
  157173. SIZEOF(struct jvirt_sarray_control));
  157174. result->mem_buffer = NULL; /* marks array not yet realized */
  157175. result->rows_in_array = numrows;
  157176. result->samplesperrow = samplesperrow;
  157177. result->maxaccess = maxaccess;
  157178. result->pre_zero = pre_zero;
  157179. result->b_s_open = FALSE; /* no associated backing-store object */
  157180. result->next = mem->virt_sarray_list; /* add to list of virtual arrays */
  157181. mem->virt_sarray_list = result;
  157182. return result;
  157183. }
  157184. METHODDEF(jvirt_barray_ptr)
  157185. request_virt_barray (j_common_ptr cinfo, int pool_id, boolean pre_zero,
  157186. JDIMENSION blocksperrow, JDIMENSION numrows,
  157187. JDIMENSION maxaccess)
  157188. {
  157189. my_mem_ptr mem = (my_mem_ptr) cinfo->mem;
  157190. jvirt_barray_ptr result;
  157191. if (pool_id != JPOOL_IMAGE)
  157192. ERREXIT1(cinfo, JERR_BAD_POOL_ID, pool_id); /* safety check */
  157193. result = (jvirt_barray_ptr) alloc_small(cinfo, pool_id,
  157194. SIZEOF(struct jvirt_barray_control));
  157195. result->mem_buffer = NULL; /* marks array not yet realized */
  157196. result->rows_in_array = numrows;
  157197. result->blocksperrow = blocksperrow;
  157198. result->maxaccess = maxaccess;
  157199. result->pre_zero = pre_zero;
  157200. result->b_s_open = FALSE; /* no associated backing-store object */
  157201. result->next = mem->virt_barray_list; /* add to list of virtual arrays */
  157202. mem->virt_barray_list = result;
  157203. return result;
  157204. }
  157205. METHODDEF(void)
  157206. realize_virt_arrays (j_common_ptr cinfo)
  157207. {
  157208. my_mem_ptr mem = (my_mem_ptr) cinfo->mem;
  157209. long space_per_minheight, maximum_space, avail_mem;
  157210. long minheights, max_minheights;
  157211. jvirt_sarray_ptr sptr;
  157212. jvirt_barray_ptr bptr;
  157213. space_per_minheight = 0;
  157214. maximum_space = 0;
  157215. for (sptr = mem->virt_sarray_list; sptr != NULL; sptr = sptr->next) {
  157216. if (sptr->mem_buffer == NULL) { /* if not realized yet */
  157217. space_per_minheight += (long) sptr->maxaccess *
  157218. (long) sptr->samplesperrow * SIZEOF(JSAMPLE);
  157219. maximum_space += (long) sptr->rows_in_array *
  157220. (long) sptr->samplesperrow * SIZEOF(JSAMPLE);
  157221. }
  157222. }
  157223. for (bptr = mem->virt_barray_list; bptr != NULL; bptr = bptr->next) {
  157224. if (bptr->mem_buffer == NULL) { /* if not realized yet */
  157225. space_per_minheight += (long) bptr->maxaccess *
  157226. (long) bptr->blocksperrow * SIZEOF(JBLOCK);
  157227. maximum_space += (long) bptr->rows_in_array *
  157228. (long) bptr->blocksperrow * SIZEOF(JBLOCK);
  157229. }
  157230. }
  157231. if (space_per_minheight <= 0)
  157232. return; /* no unrealized arrays, no work */
  157233. avail_mem = jpeg_mem_available(cinfo, space_per_minheight, maximum_space,
  157234. mem->total_space_allocated);
  157235. if (avail_mem >= maximum_space)
  157236. max_minheights = 1000000000L;
  157237. else {
  157238. max_minheights = avail_mem / space_per_minheight;
  157239. if (max_minheights <= 0)
  157240. max_minheights = 1;
  157241. }
  157242. for (sptr = mem->virt_sarray_list; sptr != NULL; sptr = sptr->next) {
  157243. if (sptr->mem_buffer == NULL) { /* if not realized yet */
  157244. minheights = ((long) sptr->rows_in_array - 1L) / sptr->maxaccess + 1L;
  157245. if (minheights <= max_minheights) {
  157246. sptr->rows_in_mem = sptr->rows_in_array;
  157247. } else {
  157248. sptr->rows_in_mem = (JDIMENSION) (max_minheights * sptr->maxaccess);
  157249. jpeg_open_backing_store(cinfo, & sptr->b_s_info,
  157250. (long) sptr->rows_in_array *
  157251. (long) sptr->samplesperrow *
  157252. (long) SIZEOF(JSAMPLE));
  157253. sptr->b_s_open = TRUE;
  157254. }
  157255. sptr->mem_buffer = alloc_sarray(cinfo, JPOOL_IMAGE,
  157256. sptr->samplesperrow, sptr->rows_in_mem);
  157257. sptr->rowsperchunk = mem->last_rowsperchunk;
  157258. sptr->cur_start_row = 0;
  157259. sptr->first_undef_row = 0;
  157260. sptr->dirty = FALSE;
  157261. }
  157262. }
  157263. for (bptr = mem->virt_barray_list; bptr != NULL; bptr = bptr->next) {
  157264. if (bptr->mem_buffer == NULL) { /* if not realized yet */
  157265. minheights = ((long) bptr->rows_in_array - 1L) / bptr->maxaccess + 1L;
  157266. if (minheights <= max_minheights) {
  157267. bptr->rows_in_mem = bptr->rows_in_array;
  157268. } else {
  157269. bptr->rows_in_mem = (JDIMENSION) (max_minheights * bptr->maxaccess);
  157270. jpeg_open_backing_store(cinfo, & bptr->b_s_info,
  157271. (long) bptr->rows_in_array *
  157272. (long) bptr->blocksperrow *
  157273. (long) SIZEOF(JBLOCK));
  157274. bptr->b_s_open = TRUE;
  157275. }
  157276. bptr->mem_buffer = alloc_barray(cinfo, JPOOL_IMAGE,
  157277. bptr->blocksperrow, bptr->rows_in_mem);
  157278. bptr->rowsperchunk = mem->last_rowsperchunk;
  157279. bptr->cur_start_row = 0;
  157280. bptr->first_undef_row = 0;
  157281. bptr->dirty = FALSE;
  157282. }
  157283. }
  157284. }
  157285. LOCAL(void)
  157286. do_sarray_io (j_common_ptr cinfo, jvirt_sarray_ptr ptr, boolean writing)
  157287. {
  157288. long bytesperrow, file_offset, byte_count, rows, thisrow, i;
  157289. bytesperrow = (long) ptr->samplesperrow * SIZEOF(JSAMPLE);
  157290. file_offset = ptr->cur_start_row * bytesperrow;
  157291. for (i = 0; i < (long) ptr->rows_in_mem; i += ptr->rowsperchunk) {
  157292. rows = MIN((long) ptr->rowsperchunk, (long) ptr->rows_in_mem - i);
  157293. thisrow = (long) ptr->cur_start_row + i;
  157294. rows = MIN(rows, (long) ptr->first_undef_row - thisrow);
  157295. rows = MIN(rows, (long) ptr->rows_in_array - thisrow);
  157296. if (rows <= 0) /* this chunk might be past end of file! */
  157297. break;
  157298. byte_count = rows * bytesperrow;
  157299. if (writing)
  157300. (*ptr->b_s_info.write_backing_store) (cinfo, & ptr->b_s_info,
  157301. (void FAR *) ptr->mem_buffer[i],
  157302. file_offset, byte_count);
  157303. else
  157304. (*ptr->b_s_info.read_backing_store) (cinfo, & ptr->b_s_info,
  157305. (void FAR *) ptr->mem_buffer[i],
  157306. file_offset, byte_count);
  157307. file_offset += byte_count;
  157308. }
  157309. }
  157310. LOCAL(void)
  157311. do_barray_io (j_common_ptr cinfo, jvirt_barray_ptr ptr, boolean writing)
  157312. {
  157313. long bytesperrow, file_offset, byte_count, rows, thisrow, i;
  157314. bytesperrow = (long) ptr->blocksperrow * SIZEOF(JBLOCK);
  157315. file_offset = ptr->cur_start_row * bytesperrow;
  157316. for (i = 0; i < (long) ptr->rows_in_mem; i += ptr->rowsperchunk) {
  157317. rows = MIN((long) ptr->rowsperchunk, (long) ptr->rows_in_mem - i);
  157318. thisrow = (long) ptr->cur_start_row + i;
  157319. rows = MIN(rows, (long) ptr->first_undef_row - thisrow);
  157320. rows = MIN(rows, (long) ptr->rows_in_array - thisrow);
  157321. if (rows <= 0) /* this chunk might be past end of file! */
  157322. break;
  157323. byte_count = rows * bytesperrow;
  157324. if (writing)
  157325. (*ptr->b_s_info.write_backing_store) (cinfo, & ptr->b_s_info,
  157326. (void FAR *) ptr->mem_buffer[i],
  157327. file_offset, byte_count);
  157328. else
  157329. (*ptr->b_s_info.read_backing_store) (cinfo, & ptr->b_s_info,
  157330. (void FAR *) ptr->mem_buffer[i],
  157331. file_offset, byte_count);
  157332. file_offset += byte_count;
  157333. }
  157334. }
  157335. METHODDEF(JSAMPARRAY)
  157336. access_virt_sarray (j_common_ptr cinfo, jvirt_sarray_ptr ptr,
  157337. JDIMENSION start_row, JDIMENSION num_rows,
  157338. boolean writable)
  157339. {
  157340. JDIMENSION end_row = start_row + num_rows;
  157341. JDIMENSION undef_row;
  157342. if (end_row > ptr->rows_in_array || num_rows > ptr->maxaccess ||
  157343. ptr->mem_buffer == NULL)
  157344. ERREXIT(cinfo, JERR_BAD_VIRTUAL_ACCESS);
  157345. if (start_row < ptr->cur_start_row ||
  157346. end_row > ptr->cur_start_row+ptr->rows_in_mem) {
  157347. if (! ptr->b_s_open)
  157348. ERREXIT(cinfo, JERR_VIRTUAL_BUG);
  157349. if (ptr->dirty) {
  157350. do_sarray_io(cinfo, ptr, TRUE);
  157351. ptr->dirty = FALSE;
  157352. }
  157353. if (start_row > ptr->cur_start_row) {
  157354. ptr->cur_start_row = start_row;
  157355. } else {
  157356. long ltemp;
  157357. ltemp = (long) end_row - (long) ptr->rows_in_mem;
  157358. if (ltemp < 0)
  157359. ltemp = 0; /* don't fall off front end of file */
  157360. ptr->cur_start_row = (JDIMENSION) ltemp;
  157361. }
  157362. do_sarray_io(cinfo, ptr, FALSE);
  157363. }
  157364. if (ptr->first_undef_row < end_row) {
  157365. if (ptr->first_undef_row < start_row) {
  157366. if (writable) /* writer skipped over a section of array */
  157367. ERREXIT(cinfo, JERR_BAD_VIRTUAL_ACCESS);
  157368. undef_row = start_row; /* but reader is allowed to read ahead */
  157369. } else {
  157370. undef_row = ptr->first_undef_row;
  157371. }
  157372. if (writable)
  157373. ptr->first_undef_row = end_row;
  157374. if (ptr->pre_zero) {
  157375. size_t bytesperrow = (size_t) ptr->samplesperrow * SIZEOF(JSAMPLE);
  157376. undef_row -= ptr->cur_start_row; /* make indexes relative to buffer */
  157377. end_row -= ptr->cur_start_row;
  157378. while (undef_row < end_row) {
  157379. jzero_far((void FAR *) ptr->mem_buffer[undef_row], bytesperrow);
  157380. undef_row++;
  157381. }
  157382. } else {
  157383. if (! writable) /* reader looking at undefined data */
  157384. ERREXIT(cinfo, JERR_BAD_VIRTUAL_ACCESS);
  157385. }
  157386. }
  157387. if (writable)
  157388. ptr->dirty = TRUE;
  157389. return ptr->mem_buffer + (start_row - ptr->cur_start_row);
  157390. }
  157391. METHODDEF(JBLOCKARRAY)
  157392. access_virt_barray (j_common_ptr cinfo, jvirt_barray_ptr ptr,
  157393. JDIMENSION start_row, JDIMENSION num_rows,
  157394. boolean writable)
  157395. {
  157396. JDIMENSION end_row = start_row + num_rows;
  157397. JDIMENSION undef_row;
  157398. if (end_row > ptr->rows_in_array || num_rows > ptr->maxaccess ||
  157399. ptr->mem_buffer == NULL)
  157400. ERREXIT(cinfo, JERR_BAD_VIRTUAL_ACCESS);
  157401. if (start_row < ptr->cur_start_row ||
  157402. end_row > ptr->cur_start_row+ptr->rows_in_mem) {
  157403. if (! ptr->b_s_open)
  157404. ERREXIT(cinfo, JERR_VIRTUAL_BUG);
  157405. if (ptr->dirty) {
  157406. do_barray_io(cinfo, ptr, TRUE);
  157407. ptr->dirty = FALSE;
  157408. }
  157409. if (start_row > ptr->cur_start_row) {
  157410. ptr->cur_start_row = start_row;
  157411. } else {
  157412. long ltemp;
  157413. ltemp = (long) end_row - (long) ptr->rows_in_mem;
  157414. if (ltemp < 0)
  157415. ltemp = 0; /* don't fall off front end of file */
  157416. ptr->cur_start_row = (JDIMENSION) ltemp;
  157417. }
  157418. do_barray_io(cinfo, ptr, FALSE);
  157419. }
  157420. if (ptr->first_undef_row < end_row) {
  157421. if (ptr->first_undef_row < start_row) {
  157422. if (writable) /* writer skipped over a section of array */
  157423. ERREXIT(cinfo, JERR_BAD_VIRTUAL_ACCESS);
  157424. undef_row = start_row; /* but reader is allowed to read ahead */
  157425. } else {
  157426. undef_row = ptr->first_undef_row;
  157427. }
  157428. if (writable)
  157429. ptr->first_undef_row = end_row;
  157430. if (ptr->pre_zero) {
  157431. size_t bytesperrow = (size_t) ptr->blocksperrow * SIZEOF(JBLOCK);
  157432. undef_row -= ptr->cur_start_row; /* make indexes relative to buffer */
  157433. end_row -= ptr->cur_start_row;
  157434. while (undef_row < end_row) {
  157435. jzero_far((void FAR *) ptr->mem_buffer[undef_row], bytesperrow);
  157436. undef_row++;
  157437. }
  157438. } else {
  157439. if (! writable) /* reader looking at undefined data */
  157440. ERREXIT(cinfo, JERR_BAD_VIRTUAL_ACCESS);
  157441. }
  157442. }
  157443. if (writable)
  157444. ptr->dirty = TRUE;
  157445. return ptr->mem_buffer + (start_row - ptr->cur_start_row);
  157446. }
  157447. METHODDEF(void)
  157448. free_pool (j_common_ptr cinfo, int pool_id)
  157449. {
  157450. my_mem_ptr mem = (my_mem_ptr) cinfo->mem;
  157451. small_pool_ptr shdr_ptr;
  157452. large_pool_ptr lhdr_ptr;
  157453. size_t space_freed;
  157454. if (pool_id < 0 || pool_id >= JPOOL_NUMPOOLS)
  157455. ERREXIT1(cinfo, JERR_BAD_POOL_ID, pool_id); /* safety check */
  157456. #ifdef MEM_STATS
  157457. if (cinfo->err->trace_level > 1)
  157458. print_mem_stats(cinfo, pool_id); /* print pool's memory usage statistics */
  157459. #endif
  157460. if (pool_id == JPOOL_IMAGE) {
  157461. jvirt_sarray_ptr sptr;
  157462. jvirt_barray_ptr bptr;
  157463. for (sptr = mem->virt_sarray_list; sptr != NULL; sptr = sptr->next) {
  157464. if (sptr->b_s_open) { /* there may be no backing store */
  157465. sptr->b_s_open = FALSE; /* prevent recursive close if error */
  157466. (*sptr->b_s_info.close_backing_store) (cinfo, & sptr->b_s_info);
  157467. }
  157468. }
  157469. mem->virt_sarray_list = NULL;
  157470. for (bptr = mem->virt_barray_list; bptr != NULL; bptr = bptr->next) {
  157471. if (bptr->b_s_open) { /* there may be no backing store */
  157472. bptr->b_s_open = FALSE; /* prevent recursive close if error */
  157473. (*bptr->b_s_info.close_backing_store) (cinfo, & bptr->b_s_info);
  157474. }
  157475. }
  157476. mem->virt_barray_list = NULL;
  157477. }
  157478. lhdr_ptr = mem->large_list[pool_id];
  157479. mem->large_list[pool_id] = NULL;
  157480. while (lhdr_ptr != NULL) {
  157481. large_pool_ptr next_lhdr_ptr = lhdr_ptr->hdr.next;
  157482. space_freed = lhdr_ptr->hdr.bytes_used +
  157483. lhdr_ptr->hdr.bytes_left +
  157484. SIZEOF(large_pool_hdr);
  157485. jpeg_free_large(cinfo, (void FAR *) lhdr_ptr, space_freed);
  157486. mem->total_space_allocated -= space_freed;
  157487. lhdr_ptr = next_lhdr_ptr;
  157488. }
  157489. shdr_ptr = mem->small_list[pool_id];
  157490. mem->small_list[pool_id] = NULL;
  157491. while (shdr_ptr != NULL) {
  157492. small_pool_ptr next_shdr_ptr = shdr_ptr->hdr.next;
  157493. space_freed = shdr_ptr->hdr.bytes_used +
  157494. shdr_ptr->hdr.bytes_left +
  157495. SIZEOF(small_pool_hdr);
  157496. jpeg_free_small(cinfo, (void *) shdr_ptr, space_freed);
  157497. mem->total_space_allocated -= space_freed;
  157498. shdr_ptr = next_shdr_ptr;
  157499. }
  157500. }
  157501. METHODDEF(void)
  157502. self_destruct (j_common_ptr cinfo)
  157503. {
  157504. int pool;
  157505. for (pool = JPOOL_NUMPOOLS-1; pool >= JPOOL_PERMANENT; pool--) {
  157506. free_pool(cinfo, pool);
  157507. }
  157508. jpeg_free_small(cinfo, (void *) cinfo->mem, SIZEOF(my_memory_mgr));
  157509. cinfo->mem = NULL; /* ensures I will be called only once */
  157510. jpeg_mem_term(cinfo); /* system-dependent cleanup */
  157511. }
  157512. GLOBAL(void)
  157513. jinit_memory_mgr (j_common_ptr cinfo)
  157514. {
  157515. my_mem_ptr mem;
  157516. long max_to_use;
  157517. int pool;
  157518. size_t test_mac;
  157519. cinfo->mem = NULL; /* for safety if init fails */
  157520. if ((SIZEOF(ALIGN_TYPE) & (SIZEOF(ALIGN_TYPE)-1)) != 0)
  157521. ERREXIT(cinfo, JERR_BAD_ALIGN_TYPE);
  157522. test_mac = (size_t) MAX_ALLOC_CHUNK;
  157523. if ((long) test_mac != MAX_ALLOC_CHUNK ||
  157524. (MAX_ALLOC_CHUNK % SIZEOF(ALIGN_TYPE)) != 0)
  157525. ERREXIT(cinfo, JERR_BAD_ALLOC_CHUNK);
  157526. max_to_use = jpeg_mem_init(cinfo); /* system-dependent initialization */
  157527. mem = (my_mem_ptr) jpeg_get_small(cinfo, SIZEOF(my_memory_mgr));
  157528. if (mem == NULL) {
  157529. jpeg_mem_term(cinfo); /* system-dependent cleanup */
  157530. ERREXIT1(cinfo, JERR_OUT_OF_MEMORY, 0);
  157531. }
  157532. mem->pub.alloc_small = alloc_small;
  157533. mem->pub.alloc_large = alloc_large;
  157534. mem->pub.alloc_sarray = alloc_sarray;
  157535. mem->pub.alloc_barray = alloc_barray;
  157536. mem->pub.request_virt_sarray = request_virt_sarray;
  157537. mem->pub.request_virt_barray = request_virt_barray;
  157538. mem->pub.realize_virt_arrays = realize_virt_arrays;
  157539. mem->pub.access_virt_sarray = access_virt_sarray;
  157540. mem->pub.access_virt_barray = access_virt_barray;
  157541. mem->pub.free_pool = free_pool;
  157542. mem->pub.self_destruct = self_destruct;
  157543. mem->pub.max_alloc_chunk = MAX_ALLOC_CHUNK;
  157544. mem->pub.max_memory_to_use = max_to_use;
  157545. for (pool = JPOOL_NUMPOOLS-1; pool >= JPOOL_PERMANENT; pool--) {
  157546. mem->small_list[pool] = NULL;
  157547. mem->large_list[pool] = NULL;
  157548. }
  157549. mem->virt_sarray_list = NULL;
  157550. mem->virt_barray_list = NULL;
  157551. mem->total_space_allocated = SIZEOF(my_memory_mgr);
  157552. cinfo->mem = & mem->pub;
  157553. #ifndef NO_GETENV
  157554. { char * memenv;
  157555. if ((memenv = getenv("JPEGMEM")) != NULL) {
  157556. char ch = 'x';
  157557. if (sscanf(memenv, "%ld%c", &max_to_use, &ch) > 0) {
  157558. if (ch == 'm' || ch == 'M')
  157559. max_to_use *= 1000L;
  157560. mem->pub.max_memory_to_use = max_to_use * 1000L;
  157561. }
  157562. }
  157563. }
  157564. #endif
  157565. }
  157566. /********* End of inlined file: jmemmgr.c *********/
  157567. /********* Start of inlined file: jmemnobs.c *********/
  157568. #define JPEG_INTERNALS
  157569. #ifndef HAVE_STDLIB_H /* <stdlib.h> should declare malloc(),free() */
  157570. extern void * malloc JPP((size_t size));
  157571. extern void free JPP((void *ptr));
  157572. #endif
  157573. GLOBAL(void *)
  157574. jpeg_get_small (j_common_ptr cinfo, size_t sizeofobject)
  157575. {
  157576. return (void *) malloc(sizeofobject);
  157577. }
  157578. GLOBAL(void)
  157579. jpeg_free_small (j_common_ptr cinfo, void * object, size_t sizeofobject)
  157580. {
  157581. free(object);
  157582. }
  157583. GLOBAL(void FAR *)
  157584. jpeg_get_large (j_common_ptr cinfo, size_t sizeofobject)
  157585. {
  157586. return (void FAR *) malloc(sizeofobject);
  157587. }
  157588. GLOBAL(void)
  157589. jpeg_free_large (j_common_ptr cinfo, void FAR * object, size_t sizeofobject)
  157590. {
  157591. free(object);
  157592. }
  157593. GLOBAL(long)
  157594. jpeg_mem_available (j_common_ptr cinfo, long min_bytes_needed,
  157595. long max_bytes_needed, long already_allocated)
  157596. {
  157597. return max_bytes_needed;
  157598. }
  157599. GLOBAL(void)
  157600. jpeg_open_backing_store (j_common_ptr cinfo, struct backing_store_struct *info,
  157601. long total_bytes_needed)
  157602. {
  157603. ERREXIT(cinfo, JERR_NO_BACKING_STORE);
  157604. }
  157605. GLOBAL(long)
  157606. jpeg_mem_init (j_common_ptr cinfo)
  157607. {
  157608. return 0; /* just set max_memory_to_use to 0 */
  157609. }
  157610. GLOBAL(void)
  157611. jpeg_mem_term (j_common_ptr cinfo)
  157612. {
  157613. }
  157614. /********* End of inlined file: jmemnobs.c *********/
  157615. /********* Start of inlined file: jquant1.c *********/
  157616. #define JPEG_INTERNALS
  157617. #ifdef QUANT_1PASS_SUPPORTED
  157618. #define ODITHER_SIZE 16 /* dimension of dither matrix */
  157619. #define ODITHER_CELLS (ODITHER_SIZE*ODITHER_SIZE) /* # cells in matrix */
  157620. #define ODITHER_MASK (ODITHER_SIZE-1) /* mask for wrapping around counters */
  157621. typedef int ODITHER_MATRIX[ODITHER_SIZE][ODITHER_SIZE];
  157622. typedef int (*ODITHER_MATRIX_PTR)[ODITHER_SIZE];
  157623. static const UINT8 base_dither_matrix[ODITHER_SIZE][ODITHER_SIZE] = {
  157624. { 0,192, 48,240, 12,204, 60,252, 3,195, 51,243, 15,207, 63,255 },
  157625. { 128, 64,176,112,140, 76,188,124,131, 67,179,115,143, 79,191,127 },
  157626. { 32,224, 16,208, 44,236, 28,220, 35,227, 19,211, 47,239, 31,223 },
  157627. { 160, 96,144, 80,172,108,156, 92,163, 99,147, 83,175,111,159, 95 },
  157628. { 8,200, 56,248, 4,196, 52,244, 11,203, 59,251, 7,199, 55,247 },
  157629. { 136, 72,184,120,132, 68,180,116,139, 75,187,123,135, 71,183,119 },
  157630. { 40,232, 24,216, 36,228, 20,212, 43,235, 27,219, 39,231, 23,215 },
  157631. { 168,104,152, 88,164,100,148, 84,171,107,155, 91,167,103,151, 87 },
  157632. { 2,194, 50,242, 14,206, 62,254, 1,193, 49,241, 13,205, 61,253 },
  157633. { 130, 66,178,114,142, 78,190,126,129, 65,177,113,141, 77,189,125 },
  157634. { 34,226, 18,210, 46,238, 30,222, 33,225, 17,209, 45,237, 29,221 },
  157635. { 162, 98,146, 82,174,110,158, 94,161, 97,145, 81,173,109,157, 93 },
  157636. { 10,202, 58,250, 6,198, 54,246, 9,201, 57,249, 5,197, 53,245 },
  157637. { 138, 74,186,122,134, 70,182,118,137, 73,185,121,133, 69,181,117 },
  157638. { 42,234, 26,218, 38,230, 22,214, 41,233, 25,217, 37,229, 21,213 },
  157639. { 170,106,154, 90,166,102,150, 86,169,105,153, 89,165,101,149, 85 }
  157640. };
  157641. #if BITS_IN_JSAMPLE == 8
  157642. typedef INT16 FSERROR; /* 16 bits should be enough */
  157643. typedef int LOCFSERROR; /* use 'int' for calculation temps */
  157644. #else
  157645. typedef INT32 FSERROR; /* may need more than 16 bits */
  157646. typedef INT32 LOCFSERROR; /* be sure calculation temps are big enough */
  157647. #endif
  157648. typedef FSERROR FAR *FSERRPTR; /* pointer to error array (in FAR storage!) */
  157649. #define MAX_Q_COMPS 4 /* max components I can handle */
  157650. typedef struct {
  157651. struct jpeg_color_quantizer pub; /* public fields */
  157652. JSAMPARRAY sv_colormap; /* The color map as a 2-D pixel array */
  157653. int sv_actual; /* number of entries in use */
  157654. JSAMPARRAY colorindex; /* Precomputed mapping for speed */
  157655. boolean is_padded; /* is the colorindex padded for odither? */
  157656. int Ncolors[MAX_Q_COMPS]; /* # of values alloced to each component */
  157657. int row_index; /* cur row's vertical index in dither matrix */
  157658. ODITHER_MATRIX_PTR odither[MAX_Q_COMPS]; /* one dither array per component */
  157659. FSERRPTR fserrors[MAX_Q_COMPS]; /* accumulated errors */
  157660. boolean on_odd_row; /* flag to remember which row we are on */
  157661. } my_cquantizer;
  157662. typedef my_cquantizer * my_cquantize_ptr;
  157663. LOCAL(int)
  157664. select_ncolors (j_decompress_ptr cinfo, int Ncolors[])
  157665. {
  157666. int nc = cinfo->out_color_components; /* number of color components */
  157667. int max_colors = cinfo->desired_number_of_colors;
  157668. int total_colors, iroot, i, j;
  157669. boolean changed;
  157670. long temp;
  157671. static const int RGB_order[3] = { RGB_GREEN, RGB_RED, RGB_BLUE };
  157672. iroot = 1;
  157673. do {
  157674. iroot++;
  157675. temp = iroot; /* set temp = iroot ** nc */
  157676. for (i = 1; i < nc; i++)
  157677. temp *= iroot;
  157678. } while (temp <= (long) max_colors); /* repeat till iroot exceeds root */
  157679. iroot--; /* now iroot = floor(root) */
  157680. if (iroot < 2)
  157681. ERREXIT1(cinfo, JERR_QUANT_FEW_COLORS, (int) temp);
  157682. total_colors = 1;
  157683. for (i = 0; i < nc; i++) {
  157684. Ncolors[i] = iroot;
  157685. total_colors *= iroot;
  157686. }
  157687. do {
  157688. changed = FALSE;
  157689. for (i = 0; i < nc; i++) {
  157690. j = (cinfo->out_color_space == JCS_RGB ? RGB_order[i] : i);
  157691. temp = total_colors / Ncolors[j];
  157692. temp *= Ncolors[j]+1; /* done in long arith to avoid oflo */
  157693. if (temp > (long) max_colors)
  157694. break; /* won't fit, done with this pass */
  157695. Ncolors[j]++; /* OK, apply the increment */
  157696. total_colors = (int) temp;
  157697. changed = TRUE;
  157698. }
  157699. } while (changed);
  157700. return total_colors;
  157701. }
  157702. LOCAL(int)
  157703. output_value (j_decompress_ptr cinfo, int ci, int j, int maxj)
  157704. {
  157705. return (int) (((INT32) j * MAXJSAMPLE + maxj/2) / maxj);
  157706. }
  157707. LOCAL(int)
  157708. largest_input_value (j_decompress_ptr cinfo, int ci, int j, int maxj)
  157709. {
  157710. return (int) (((INT32) (2*j + 1) * MAXJSAMPLE + maxj) / (2*maxj));
  157711. }
  157712. LOCAL(void)
  157713. create_colormap (j_decompress_ptr cinfo)
  157714. {
  157715. my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
  157716. JSAMPARRAY colormap; /* Created colormap */
  157717. int total_colors; /* Number of distinct output colors */
  157718. int i,j,k, nci, blksize, blkdist, ptr, val;
  157719. total_colors = select_ncolors(cinfo, cquantize->Ncolors);
  157720. if (cinfo->out_color_components == 3)
  157721. TRACEMS4(cinfo, 1, JTRC_QUANT_3_NCOLORS,
  157722. total_colors, cquantize->Ncolors[0],
  157723. cquantize->Ncolors[1], cquantize->Ncolors[2]);
  157724. else
  157725. TRACEMS1(cinfo, 1, JTRC_QUANT_NCOLORS, total_colors);
  157726. colormap = (*cinfo->mem->alloc_sarray)
  157727. ((j_common_ptr) cinfo, JPOOL_IMAGE,
  157728. (JDIMENSION) total_colors, (JDIMENSION) cinfo->out_color_components);
  157729. blkdist = total_colors;
  157730. for (i = 0; i < cinfo->out_color_components; i++) {
  157731. nci = cquantize->Ncolors[i]; /* # of distinct values for this color */
  157732. blksize = blkdist / nci;
  157733. for (j = 0; j < nci; j++) {
  157734. val = output_value(cinfo, i, j, nci-1);
  157735. for (ptr = j * blksize; ptr < total_colors; ptr += blkdist) {
  157736. for (k = 0; k < blksize; k++)
  157737. colormap[i][ptr+k] = (JSAMPLE) val;
  157738. }
  157739. }
  157740. blkdist = blksize; /* blksize of this color is blkdist of next */
  157741. }
  157742. cquantize->sv_colormap = colormap;
  157743. cquantize->sv_actual = total_colors;
  157744. }
  157745. LOCAL(void)
  157746. create_colorindex (j_decompress_ptr cinfo)
  157747. {
  157748. my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
  157749. JSAMPROW indexptr;
  157750. int i,j,k, nci, blksize, val, pad;
  157751. if (cinfo->dither_mode == JDITHER_ORDERED) {
  157752. pad = MAXJSAMPLE*2;
  157753. cquantize->is_padded = TRUE;
  157754. } else {
  157755. pad = 0;
  157756. cquantize->is_padded = FALSE;
  157757. }
  157758. cquantize->colorindex = (*cinfo->mem->alloc_sarray)
  157759. ((j_common_ptr) cinfo, JPOOL_IMAGE,
  157760. (JDIMENSION) (MAXJSAMPLE+1 + pad),
  157761. (JDIMENSION) cinfo->out_color_components);
  157762. blksize = cquantize->sv_actual;
  157763. for (i = 0; i < cinfo->out_color_components; i++) {
  157764. nci = cquantize->Ncolors[i]; /* # of distinct values for this color */
  157765. blksize = blksize / nci;
  157766. if (pad)
  157767. cquantize->colorindex[i] += MAXJSAMPLE;
  157768. indexptr = cquantize->colorindex[i];
  157769. val = 0;
  157770. k = largest_input_value(cinfo, i, 0, nci-1);
  157771. for (j = 0; j <= MAXJSAMPLE; j++) {
  157772. while (j > k) /* advance val if past boundary */
  157773. k = largest_input_value(cinfo, i, ++val, nci-1);
  157774. indexptr[j] = (JSAMPLE) (val * blksize);
  157775. }
  157776. if (pad)
  157777. for (j = 1; j <= MAXJSAMPLE; j++) {
  157778. indexptr[-j] = indexptr[0];
  157779. indexptr[MAXJSAMPLE+j] = indexptr[MAXJSAMPLE];
  157780. }
  157781. }
  157782. }
  157783. LOCAL(ODITHER_MATRIX_PTR)
  157784. make_odither_array (j_decompress_ptr cinfo, int ncolors)
  157785. {
  157786. ODITHER_MATRIX_PTR odither;
  157787. int j,k;
  157788. INT32 num,den;
  157789. odither = (ODITHER_MATRIX_PTR)
  157790. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  157791. SIZEOF(ODITHER_MATRIX));
  157792. den = 2 * ODITHER_CELLS * ((INT32) (ncolors - 1));
  157793. for (j = 0; j < ODITHER_SIZE; j++) {
  157794. for (k = 0; k < ODITHER_SIZE; k++) {
  157795. num = ((INT32) (ODITHER_CELLS-1 - 2*((int)base_dither_matrix[j][k])))
  157796. * MAXJSAMPLE;
  157797. odither[j][k] = (int) (num<0 ? -((-num)/den) : num/den);
  157798. }
  157799. }
  157800. return odither;
  157801. }
  157802. LOCAL(void)
  157803. create_odither_tables (j_decompress_ptr cinfo)
  157804. {
  157805. my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
  157806. ODITHER_MATRIX_PTR odither;
  157807. int i, j, nci;
  157808. for (i = 0; i < cinfo->out_color_components; i++) {
  157809. nci = cquantize->Ncolors[i]; /* # of distinct values for this color */
  157810. odither = NULL; /* search for matching prior component */
  157811. for (j = 0; j < i; j++) {
  157812. if (nci == cquantize->Ncolors[j]) {
  157813. odither = cquantize->odither[j];
  157814. break;
  157815. }
  157816. }
  157817. if (odither == NULL) /* need a new table? */
  157818. odither = make_odither_array(cinfo, nci);
  157819. cquantize->odither[i] = odither;
  157820. }
  157821. }
  157822. METHODDEF(void)
  157823. color_quantize (j_decompress_ptr cinfo, JSAMPARRAY input_buf,
  157824. JSAMPARRAY output_buf, int num_rows)
  157825. {
  157826. my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
  157827. JSAMPARRAY colorindex = cquantize->colorindex;
  157828. register int pixcode, ci;
  157829. register JSAMPROW ptrin, ptrout;
  157830. int row;
  157831. JDIMENSION col;
  157832. JDIMENSION width = cinfo->output_width;
  157833. register int nc = cinfo->out_color_components;
  157834. for (row = 0; row < num_rows; row++) {
  157835. ptrin = input_buf[row];
  157836. ptrout = output_buf[row];
  157837. for (col = width; col > 0; col--) {
  157838. pixcode = 0;
  157839. for (ci = 0; ci < nc; ci++) {
  157840. pixcode += GETJSAMPLE(colorindex[ci][GETJSAMPLE(*ptrin++)]);
  157841. }
  157842. *ptrout++ = (JSAMPLE) pixcode;
  157843. }
  157844. }
  157845. }
  157846. METHODDEF(void)
  157847. color_quantize3 (j_decompress_ptr cinfo, JSAMPARRAY input_buf,
  157848. JSAMPARRAY output_buf, int num_rows)
  157849. {
  157850. my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
  157851. register int pixcode;
  157852. register JSAMPROW ptrin, ptrout;
  157853. JSAMPROW colorindex0 = cquantize->colorindex[0];
  157854. JSAMPROW colorindex1 = cquantize->colorindex[1];
  157855. JSAMPROW colorindex2 = cquantize->colorindex[2];
  157856. int row;
  157857. JDIMENSION col;
  157858. JDIMENSION width = cinfo->output_width;
  157859. for (row = 0; row < num_rows; row++) {
  157860. ptrin = input_buf[row];
  157861. ptrout = output_buf[row];
  157862. for (col = width; col > 0; col--) {
  157863. pixcode = GETJSAMPLE(colorindex0[GETJSAMPLE(*ptrin++)]);
  157864. pixcode += GETJSAMPLE(colorindex1[GETJSAMPLE(*ptrin++)]);
  157865. pixcode += GETJSAMPLE(colorindex2[GETJSAMPLE(*ptrin++)]);
  157866. *ptrout++ = (JSAMPLE) pixcode;
  157867. }
  157868. }
  157869. }
  157870. METHODDEF(void)
  157871. quantize_ord_dither (j_decompress_ptr cinfo, JSAMPARRAY input_buf,
  157872. JSAMPARRAY output_buf, int num_rows)
  157873. {
  157874. my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
  157875. register JSAMPROW input_ptr;
  157876. register JSAMPROW output_ptr;
  157877. JSAMPROW colorindex_ci;
  157878. int * dither; /* points to active row of dither matrix */
  157879. int row_index, col_index; /* current indexes into dither matrix */
  157880. int nc = cinfo->out_color_components;
  157881. int ci;
  157882. int row;
  157883. JDIMENSION col;
  157884. JDIMENSION width = cinfo->output_width;
  157885. for (row = 0; row < num_rows; row++) {
  157886. jzero_far((void FAR *) output_buf[row],
  157887. (size_t) (width * SIZEOF(JSAMPLE)));
  157888. row_index = cquantize->row_index;
  157889. for (ci = 0; ci < nc; ci++) {
  157890. input_ptr = input_buf[row] + ci;
  157891. output_ptr = output_buf[row];
  157892. colorindex_ci = cquantize->colorindex[ci];
  157893. dither = cquantize->odither[ci][row_index];
  157894. col_index = 0;
  157895. for (col = width; col > 0; col--) {
  157896. *output_ptr += colorindex_ci[GETJSAMPLE(*input_ptr)+dither[col_index]];
  157897. input_ptr += nc;
  157898. output_ptr++;
  157899. col_index = (col_index + 1) & ODITHER_MASK;
  157900. }
  157901. }
  157902. row_index = (row_index + 1) & ODITHER_MASK;
  157903. cquantize->row_index = row_index;
  157904. }
  157905. }
  157906. METHODDEF(void)
  157907. quantize3_ord_dither (j_decompress_ptr cinfo, JSAMPARRAY input_buf,
  157908. JSAMPARRAY output_buf, int num_rows)
  157909. {
  157910. my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
  157911. register int pixcode;
  157912. register JSAMPROW input_ptr;
  157913. register JSAMPROW output_ptr;
  157914. JSAMPROW colorindex0 = cquantize->colorindex[0];
  157915. JSAMPROW colorindex1 = cquantize->colorindex[1];
  157916. JSAMPROW colorindex2 = cquantize->colorindex[2];
  157917. int * dither0; /* points to active row of dither matrix */
  157918. int * dither1;
  157919. int * dither2;
  157920. int row_index, col_index; /* current indexes into dither matrix */
  157921. int row;
  157922. JDIMENSION col;
  157923. JDIMENSION width = cinfo->output_width;
  157924. for (row = 0; row < num_rows; row++) {
  157925. row_index = cquantize->row_index;
  157926. input_ptr = input_buf[row];
  157927. output_ptr = output_buf[row];
  157928. dither0 = cquantize->odither[0][row_index];
  157929. dither1 = cquantize->odither[1][row_index];
  157930. dither2 = cquantize->odither[2][row_index];
  157931. col_index = 0;
  157932. for (col = width; col > 0; col--) {
  157933. pixcode = GETJSAMPLE(colorindex0[GETJSAMPLE(*input_ptr++) +
  157934. dither0[col_index]]);
  157935. pixcode += GETJSAMPLE(colorindex1[GETJSAMPLE(*input_ptr++) +
  157936. dither1[col_index]]);
  157937. pixcode += GETJSAMPLE(colorindex2[GETJSAMPLE(*input_ptr++) +
  157938. dither2[col_index]]);
  157939. *output_ptr++ = (JSAMPLE) pixcode;
  157940. col_index = (col_index + 1) & ODITHER_MASK;
  157941. }
  157942. row_index = (row_index + 1) & ODITHER_MASK;
  157943. cquantize->row_index = row_index;
  157944. }
  157945. }
  157946. METHODDEF(void)
  157947. quantize_fs_dither (j_decompress_ptr cinfo, JSAMPARRAY input_buf,
  157948. JSAMPARRAY output_buf, int num_rows)
  157949. {
  157950. my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
  157951. register LOCFSERROR cur; /* current error or pixel value */
  157952. LOCFSERROR belowerr; /* error for pixel below cur */
  157953. LOCFSERROR bpreverr; /* error for below/prev col */
  157954. LOCFSERROR bnexterr; /* error for below/next col */
  157955. LOCFSERROR delta;
  157956. register FSERRPTR errorptr; /* => fserrors[] at column before current */
  157957. register JSAMPROW input_ptr;
  157958. register JSAMPROW output_ptr;
  157959. JSAMPROW colorindex_ci;
  157960. JSAMPROW colormap_ci;
  157961. int pixcode;
  157962. int nc = cinfo->out_color_components;
  157963. int dir; /* 1 for left-to-right, -1 for right-to-left */
  157964. int dirnc; /* dir * nc */
  157965. int ci;
  157966. int row;
  157967. JDIMENSION col;
  157968. JDIMENSION width = cinfo->output_width;
  157969. JSAMPLE *range_limit = cinfo->sample_range_limit;
  157970. SHIFT_TEMPS
  157971. for (row = 0; row < num_rows; row++) {
  157972. jzero_far((void FAR *) output_buf[row],
  157973. (size_t) (width * SIZEOF(JSAMPLE)));
  157974. for (ci = 0; ci < nc; ci++) {
  157975. input_ptr = input_buf[row] + ci;
  157976. output_ptr = output_buf[row];
  157977. if (cquantize->on_odd_row) {
  157978. input_ptr += (width-1) * nc; /* so point to rightmost pixel */
  157979. output_ptr += width-1;
  157980. dir = -1;
  157981. dirnc = -nc;
  157982. errorptr = cquantize->fserrors[ci] + (width+1); /* => entry after last column */
  157983. } else {
  157984. dir = 1;
  157985. dirnc = nc;
  157986. errorptr = cquantize->fserrors[ci]; /* => entry before first column */
  157987. }
  157988. colorindex_ci = cquantize->colorindex[ci];
  157989. colormap_ci = cquantize->sv_colormap[ci];
  157990. cur = 0;
  157991. belowerr = bpreverr = 0;
  157992. for (col = width; col > 0; col--) {
  157993. cur = RIGHT_SHIFT(cur + errorptr[dir] + 8, 4);
  157994. cur += GETJSAMPLE(*input_ptr);
  157995. cur = GETJSAMPLE(range_limit[cur]);
  157996. pixcode = GETJSAMPLE(colorindex_ci[cur]);
  157997. *output_ptr += (JSAMPLE) pixcode;
  157998. cur -= GETJSAMPLE(colormap_ci[pixcode]);
  157999. bnexterr = cur;
  158000. delta = cur * 2;
  158001. cur += delta; /* form error * 3 */
  158002. errorptr[0] = (FSERROR) (bpreverr + cur);
  158003. cur += delta; /* form error * 5 */
  158004. bpreverr = belowerr + cur;
  158005. belowerr = bnexterr;
  158006. cur += delta; /* form error * 7 */
  158007. input_ptr += dirnc; /* advance input ptr to next column */
  158008. output_ptr += dir; /* advance output ptr to next column */
  158009. errorptr += dir; /* advance errorptr to current column */
  158010. }
  158011. errorptr[0] = (FSERROR) bpreverr; /* unload prev err into array */
  158012. }
  158013. cquantize->on_odd_row = (cquantize->on_odd_row ? FALSE : TRUE);
  158014. }
  158015. }
  158016. LOCAL(void)
  158017. alloc_fs_workspace (j_decompress_ptr cinfo)
  158018. {
  158019. my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
  158020. size_t arraysize;
  158021. int i;
  158022. arraysize = (size_t) ((cinfo->output_width + 2) * SIZEOF(FSERROR));
  158023. for (i = 0; i < cinfo->out_color_components; i++) {
  158024. cquantize->fserrors[i] = (FSERRPTR)
  158025. (*cinfo->mem->alloc_large)((j_common_ptr) cinfo, JPOOL_IMAGE, arraysize);
  158026. }
  158027. }
  158028. METHODDEF(void)
  158029. start_pass_1_quant (j_decompress_ptr cinfo, boolean is_pre_scan)
  158030. {
  158031. my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
  158032. size_t arraysize;
  158033. int i;
  158034. cinfo->colormap = cquantize->sv_colormap;
  158035. cinfo->actual_number_of_colors = cquantize->sv_actual;
  158036. switch (cinfo->dither_mode) {
  158037. case JDITHER_NONE:
  158038. if (cinfo->out_color_components == 3)
  158039. cquantize->pub.color_quantize = color_quantize3;
  158040. else
  158041. cquantize->pub.color_quantize = color_quantize;
  158042. break;
  158043. case JDITHER_ORDERED:
  158044. if (cinfo->out_color_components == 3)
  158045. cquantize->pub.color_quantize = quantize3_ord_dither;
  158046. else
  158047. cquantize->pub.color_quantize = quantize_ord_dither;
  158048. cquantize->row_index = 0; /* initialize state for ordered dither */
  158049. if (! cquantize->is_padded)
  158050. create_colorindex(cinfo);
  158051. if (cquantize->odither[0] == NULL)
  158052. create_odither_tables(cinfo);
  158053. break;
  158054. case JDITHER_FS:
  158055. cquantize->pub.color_quantize = quantize_fs_dither;
  158056. cquantize->on_odd_row = FALSE; /* initialize state for F-S dither */
  158057. if (cquantize->fserrors[0] == NULL)
  158058. alloc_fs_workspace(cinfo);
  158059. arraysize = (size_t) ((cinfo->output_width + 2) * SIZEOF(FSERROR));
  158060. for (i = 0; i < cinfo->out_color_components; i++)
  158061. jzero_far((void FAR *) cquantize->fserrors[i], arraysize);
  158062. break;
  158063. default:
  158064. ERREXIT(cinfo, JERR_NOT_COMPILED);
  158065. break;
  158066. }
  158067. }
  158068. METHODDEF(void)
  158069. finish_pass_1_quant (j_decompress_ptr cinfo)
  158070. {
  158071. }
  158072. METHODDEF(void)
  158073. new_color_map_1_quant (j_decompress_ptr cinfo)
  158074. {
  158075. ERREXIT(cinfo, JERR_MODE_CHANGE);
  158076. }
  158077. GLOBAL(void)
  158078. jinit_1pass_quantizer (j_decompress_ptr cinfo)
  158079. {
  158080. my_cquantize_ptr cquantize;
  158081. cquantize = (my_cquantize_ptr)
  158082. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  158083. SIZEOF(my_cquantizer));
  158084. cinfo->cquantize = (struct jpeg_color_quantizer *) cquantize;
  158085. cquantize->pub.start_pass = start_pass_1_quant;
  158086. cquantize->pub.finish_pass = finish_pass_1_quant;
  158087. cquantize->pub.new_color_map = new_color_map_1_quant;
  158088. cquantize->fserrors[0] = NULL; /* Flag FS workspace not allocated */
  158089. cquantize->odither[0] = NULL; /* Also flag odither arrays not allocated */
  158090. if (cinfo->out_color_components > MAX_Q_COMPS)
  158091. ERREXIT1(cinfo, JERR_QUANT_COMPONENTS, MAX_Q_COMPS);
  158092. if (cinfo->desired_number_of_colors > (MAXJSAMPLE+1))
  158093. ERREXIT1(cinfo, JERR_QUANT_MANY_COLORS, MAXJSAMPLE+1);
  158094. create_colormap(cinfo);
  158095. create_colorindex(cinfo);
  158096. if (cinfo->dither_mode == JDITHER_FS)
  158097. alloc_fs_workspace(cinfo);
  158098. }
  158099. #endif /* QUANT_1PASS_SUPPORTED */
  158100. /********* End of inlined file: jquant1.c *********/
  158101. /********* Start of inlined file: jquant2.c *********/
  158102. #define JPEG_INTERNALS
  158103. #ifdef QUANT_2PASS_SUPPORTED
  158104. #define R_SCALE 2 /* scale R distances by this much */
  158105. #define G_SCALE 3 /* scale G distances by this much */
  158106. #define B_SCALE 1 /* and B by this much */
  158107. #if RGB_RED == 0
  158108. #define C0_SCALE R_SCALE
  158109. #endif
  158110. #if RGB_BLUE == 0
  158111. #define C0_SCALE B_SCALE
  158112. #endif
  158113. #if RGB_GREEN == 1
  158114. #define C1_SCALE G_SCALE
  158115. #endif
  158116. #if RGB_RED == 2
  158117. #define C2_SCALE R_SCALE
  158118. #endif
  158119. #if RGB_BLUE == 2
  158120. #define C2_SCALE B_SCALE
  158121. #endif
  158122. #define MAXNUMCOLORS (MAXJSAMPLE+1) /* maximum size of colormap */
  158123. #define HIST_C0_BITS 5 /* bits of precision in R/B histogram */
  158124. #define HIST_C1_BITS 6 /* bits of precision in G histogram */
  158125. #define HIST_C2_BITS 5 /* bits of precision in B/R histogram */
  158126. #define HIST_C0_ELEMS (1<<HIST_C0_BITS)
  158127. #define HIST_C1_ELEMS (1<<HIST_C1_BITS)
  158128. #define HIST_C2_ELEMS (1<<HIST_C2_BITS)
  158129. #define C0_SHIFT (BITS_IN_JSAMPLE-HIST_C0_BITS)
  158130. #define C1_SHIFT (BITS_IN_JSAMPLE-HIST_C1_BITS)
  158131. #define C2_SHIFT (BITS_IN_JSAMPLE-HIST_C2_BITS)
  158132. typedef UINT16 histcell; /* histogram cell; prefer an unsigned type */
  158133. typedef histcell FAR * histptr; /* for pointers to histogram cells */
  158134. typedef histcell hist1d[HIST_C2_ELEMS]; /* typedefs for the array */
  158135. typedef hist1d FAR * hist2d; /* type for the 2nd-level pointers */
  158136. typedef hist2d * hist3d; /* type for top-level pointer */
  158137. #if BITS_IN_JSAMPLE == 8
  158138. typedef INT16 FSERROR; /* 16 bits should be enough */
  158139. typedef int LOCFSERROR; /* use 'int' for calculation temps */
  158140. #else
  158141. typedef INT32 FSERROR; /* may need more than 16 bits */
  158142. typedef INT32 LOCFSERROR; /* be sure calculation temps are big enough */
  158143. #endif
  158144. typedef FSERROR FAR *FSERRPTR; /* pointer to error array (in FAR storage!) */
  158145. typedef struct {
  158146. struct jpeg_color_quantizer pub; /* public fields */
  158147. JSAMPARRAY sv_colormap; /* colormap allocated at init time */
  158148. int desired; /* desired # of colors = size of colormap */
  158149. hist3d histogram; /* pointer to the histogram */
  158150. boolean needs_zeroed; /* TRUE if next pass must zero histogram */
  158151. FSERRPTR fserrors; /* accumulated errors */
  158152. boolean on_odd_row; /* flag to remember which row we are on */
  158153. int * error_limiter; /* table for clamping the applied error */
  158154. } my_cquantizer2;
  158155. typedef my_cquantizer2 * my_cquantize_ptr2;
  158156. METHODDEF(void)
  158157. prescan_quantize (j_decompress_ptr cinfo, JSAMPARRAY input_buf,
  158158. JSAMPARRAY output_buf, int num_rows)
  158159. {
  158160. my_cquantize_ptr2 cquantize = (my_cquantize_ptr2) cinfo->cquantize;
  158161. register JSAMPROW ptr;
  158162. register histptr histp;
  158163. register hist3d histogram = cquantize->histogram;
  158164. int row;
  158165. JDIMENSION col;
  158166. JDIMENSION width = cinfo->output_width;
  158167. for (row = 0; row < num_rows; row++) {
  158168. ptr = input_buf[row];
  158169. for (col = width; col > 0; col--) {
  158170. histp = & histogram[GETJSAMPLE(ptr[0]) >> C0_SHIFT]
  158171. [GETJSAMPLE(ptr[1]) >> C1_SHIFT]
  158172. [GETJSAMPLE(ptr[2]) >> C2_SHIFT];
  158173. if (++(*histp) <= 0)
  158174. (*histp)--;
  158175. ptr += 3;
  158176. }
  158177. }
  158178. }
  158179. typedef struct {
  158180. int c0min, c0max;
  158181. int c1min, c1max;
  158182. int c2min, c2max;
  158183. INT32 volume;
  158184. long colorcount;
  158185. } box;
  158186. typedef box * boxptr;
  158187. LOCAL(boxptr)
  158188. find_biggest_color_pop (boxptr boxlist, int numboxes)
  158189. {
  158190. register boxptr boxp;
  158191. register int i;
  158192. register long maxc = 0;
  158193. boxptr which = NULL;
  158194. for (i = 0, boxp = boxlist; i < numboxes; i++, boxp++) {
  158195. if (boxp->colorcount > maxc && boxp->volume > 0) {
  158196. which = boxp;
  158197. maxc = boxp->colorcount;
  158198. }
  158199. }
  158200. return which;
  158201. }
  158202. LOCAL(boxptr)
  158203. find_biggest_volume (boxptr boxlist, int numboxes)
  158204. {
  158205. register boxptr boxp;
  158206. register int i;
  158207. register INT32 maxv = 0;
  158208. boxptr which = NULL;
  158209. for (i = 0, boxp = boxlist; i < numboxes; i++, boxp++) {
  158210. if (boxp->volume > maxv) {
  158211. which = boxp;
  158212. maxv = boxp->volume;
  158213. }
  158214. }
  158215. return which;
  158216. }
  158217. LOCAL(void)
  158218. update_box (j_decompress_ptr cinfo, boxptr boxp)
  158219. {
  158220. my_cquantize_ptr2 cquantize = (my_cquantize_ptr2) cinfo->cquantize;
  158221. hist3d histogram = cquantize->histogram;
  158222. histptr histp;
  158223. int c0,c1,c2;
  158224. int c0min,c0max,c1min,c1max,c2min,c2max;
  158225. INT32 dist0,dist1,dist2;
  158226. long ccount;
  158227. c0min = boxp->c0min; c0max = boxp->c0max;
  158228. c1min = boxp->c1min; c1max = boxp->c1max;
  158229. c2min = boxp->c2min; c2max = boxp->c2max;
  158230. if (c0max > c0min)
  158231. for (c0 = c0min; c0 <= c0max; c0++)
  158232. for (c1 = c1min; c1 <= c1max; c1++) {
  158233. histp = & histogram[c0][c1][c2min];
  158234. for (c2 = c2min; c2 <= c2max; c2++)
  158235. if (*histp++ != 0) {
  158236. boxp->c0min = c0min = c0;
  158237. goto have_c0min;
  158238. }
  158239. }
  158240. have_c0min:
  158241. if (c0max > c0min)
  158242. for (c0 = c0max; c0 >= c0min; c0--)
  158243. for (c1 = c1min; c1 <= c1max; c1++) {
  158244. histp = & histogram[c0][c1][c2min];
  158245. for (c2 = c2min; c2 <= c2max; c2++)
  158246. if (*histp++ != 0) {
  158247. boxp->c0max = c0max = c0;
  158248. goto have_c0max;
  158249. }
  158250. }
  158251. have_c0max:
  158252. if (c1max > c1min)
  158253. for (c1 = c1min; c1 <= c1max; c1++)
  158254. for (c0 = c0min; c0 <= c0max; c0++) {
  158255. histp = & histogram[c0][c1][c2min];
  158256. for (c2 = c2min; c2 <= c2max; c2++)
  158257. if (*histp++ != 0) {
  158258. boxp->c1min = c1min = c1;
  158259. goto have_c1min;
  158260. }
  158261. }
  158262. have_c1min:
  158263. if (c1max > c1min)
  158264. for (c1 = c1max; c1 >= c1min; c1--)
  158265. for (c0 = c0min; c0 <= c0max; c0++) {
  158266. histp = & histogram[c0][c1][c2min];
  158267. for (c2 = c2min; c2 <= c2max; c2++)
  158268. if (*histp++ != 0) {
  158269. boxp->c1max = c1max = c1;
  158270. goto have_c1max;
  158271. }
  158272. }
  158273. have_c1max:
  158274. if (c2max > c2min)
  158275. for (c2 = c2min; c2 <= c2max; c2++)
  158276. for (c0 = c0min; c0 <= c0max; c0++) {
  158277. histp = & histogram[c0][c1min][c2];
  158278. for (c1 = c1min; c1 <= c1max; c1++, histp += HIST_C2_ELEMS)
  158279. if (*histp != 0) {
  158280. boxp->c2min = c2min = c2;
  158281. goto have_c2min;
  158282. }
  158283. }
  158284. have_c2min:
  158285. if (c2max > c2min)
  158286. for (c2 = c2max; c2 >= c2min; c2--)
  158287. for (c0 = c0min; c0 <= c0max; c0++) {
  158288. histp = & histogram[c0][c1min][c2];
  158289. for (c1 = c1min; c1 <= c1max; c1++, histp += HIST_C2_ELEMS)
  158290. if (*histp != 0) {
  158291. boxp->c2max = c2max = c2;
  158292. goto have_c2max;
  158293. }
  158294. }
  158295. have_c2max:
  158296. dist0 = ((c0max - c0min) << C0_SHIFT) * C0_SCALE;
  158297. dist1 = ((c1max - c1min) << C1_SHIFT) * C1_SCALE;
  158298. dist2 = ((c2max - c2min) << C2_SHIFT) * C2_SCALE;
  158299. boxp->volume = dist0*dist0 + dist1*dist1 + dist2*dist2;
  158300. ccount = 0;
  158301. for (c0 = c0min; c0 <= c0max; c0++)
  158302. for (c1 = c1min; c1 <= c1max; c1++) {
  158303. histp = & histogram[c0][c1][c2min];
  158304. for (c2 = c2min; c2 <= c2max; c2++, histp++)
  158305. if (*histp != 0) {
  158306. ccount++;
  158307. }
  158308. }
  158309. boxp->colorcount = ccount;
  158310. }
  158311. LOCAL(int)
  158312. median_cut (j_decompress_ptr cinfo, boxptr boxlist, int numboxes,
  158313. int desired_colors)
  158314. {
  158315. int n,lb;
  158316. int c0,c1,c2,cmax;
  158317. register boxptr b1,b2;
  158318. while (numboxes < desired_colors) {
  158319. if (numboxes*2 <= desired_colors) {
  158320. b1 = find_biggest_color_pop(boxlist, numboxes);
  158321. } else {
  158322. b1 = find_biggest_volume(boxlist, numboxes);
  158323. }
  158324. if (b1 == NULL) /* no splittable boxes left! */
  158325. break;
  158326. b2 = &boxlist[numboxes]; /* where new box will go */
  158327. b2->c0max = b1->c0max; b2->c1max = b1->c1max; b2->c2max = b1->c2max;
  158328. b2->c0min = b1->c0min; b2->c1min = b1->c1min; b2->c2min = b1->c2min;
  158329. c0 = ((b1->c0max - b1->c0min) << C0_SHIFT) * C0_SCALE;
  158330. c1 = ((b1->c1max - b1->c1min) << C1_SHIFT) * C1_SCALE;
  158331. c2 = ((b1->c2max - b1->c2min) << C2_SHIFT) * C2_SCALE;
  158332. #if RGB_RED == 0
  158333. cmax = c1; n = 1;
  158334. if (c0 > cmax) { cmax = c0; n = 0; }
  158335. if (c2 > cmax) { n = 2; }
  158336. #else
  158337. cmax = c1; n = 1;
  158338. if (c2 > cmax) { cmax = c2; n = 2; }
  158339. if (c0 > cmax) { n = 0; }
  158340. #endif
  158341. switch (n) {
  158342. case 0:
  158343. lb = (b1->c0max + b1->c0min) / 2;
  158344. b1->c0max = lb;
  158345. b2->c0min = lb+1;
  158346. break;
  158347. case 1:
  158348. lb = (b1->c1max + b1->c1min) / 2;
  158349. b1->c1max = lb;
  158350. b2->c1min = lb+1;
  158351. break;
  158352. case 2:
  158353. lb = (b1->c2max + b1->c2min) / 2;
  158354. b1->c2max = lb;
  158355. b2->c2min = lb+1;
  158356. break;
  158357. }
  158358. update_box(cinfo, b1);
  158359. update_box(cinfo, b2);
  158360. numboxes++;
  158361. }
  158362. return numboxes;
  158363. }
  158364. LOCAL(void)
  158365. compute_color (j_decompress_ptr cinfo, boxptr boxp, int icolor)
  158366. {
  158367. my_cquantize_ptr2 cquantize = (my_cquantize_ptr2) cinfo->cquantize;
  158368. hist3d histogram = cquantize->histogram;
  158369. histptr histp;
  158370. int c0,c1,c2;
  158371. int c0min,c0max,c1min,c1max,c2min,c2max;
  158372. long count;
  158373. long total = 0;
  158374. long c0total = 0;
  158375. long c1total = 0;
  158376. long c2total = 0;
  158377. c0min = boxp->c0min; c0max = boxp->c0max;
  158378. c1min = boxp->c1min; c1max = boxp->c1max;
  158379. c2min = boxp->c2min; c2max = boxp->c2max;
  158380. for (c0 = c0min; c0 <= c0max; c0++)
  158381. for (c1 = c1min; c1 <= c1max; c1++) {
  158382. histp = & histogram[c0][c1][c2min];
  158383. for (c2 = c2min; c2 <= c2max; c2++) {
  158384. if ((count = *histp++) != 0) {
  158385. total += count;
  158386. c0total += ((c0 << C0_SHIFT) + ((1<<C0_SHIFT)>>1)) * count;
  158387. c1total += ((c1 << C1_SHIFT) + ((1<<C1_SHIFT)>>1)) * count;
  158388. c2total += ((c2 << C2_SHIFT) + ((1<<C2_SHIFT)>>1)) * count;
  158389. }
  158390. }
  158391. }
  158392. cinfo->colormap[0][icolor] = (JSAMPLE) ((c0total + (total>>1)) / total);
  158393. cinfo->colormap[1][icolor] = (JSAMPLE) ((c1total + (total>>1)) / total);
  158394. cinfo->colormap[2][icolor] = (JSAMPLE) ((c2total + (total>>1)) / total);
  158395. }
  158396. LOCAL(void)
  158397. select_colors (j_decompress_ptr cinfo, int desired_colors)
  158398. {
  158399. boxptr boxlist;
  158400. int numboxes;
  158401. int i;
  158402. boxlist = (boxptr) (*cinfo->mem->alloc_small)
  158403. ((j_common_ptr) cinfo, JPOOL_IMAGE, desired_colors * SIZEOF(box));
  158404. numboxes = 1;
  158405. boxlist[0].c0min = 0;
  158406. boxlist[0].c0max = MAXJSAMPLE >> C0_SHIFT;
  158407. boxlist[0].c1min = 0;
  158408. boxlist[0].c1max = MAXJSAMPLE >> C1_SHIFT;
  158409. boxlist[0].c2min = 0;
  158410. boxlist[0].c2max = MAXJSAMPLE >> C2_SHIFT;
  158411. update_box(cinfo, & boxlist[0]);
  158412. numboxes = median_cut(cinfo, boxlist, numboxes, desired_colors);
  158413. for (i = 0; i < numboxes; i++)
  158414. compute_color(cinfo, & boxlist[i], i);
  158415. cinfo->actual_number_of_colors = numboxes;
  158416. TRACEMS1(cinfo, 1, JTRC_QUANT_SELECTED, numboxes);
  158417. }
  158418. #define BOX_C0_LOG (HIST_C0_BITS-3)
  158419. #define BOX_C1_LOG (HIST_C1_BITS-3)
  158420. #define BOX_C2_LOG (HIST_C2_BITS-3)
  158421. #define BOX_C0_ELEMS (1<<BOX_C0_LOG) /* # of hist cells in update box */
  158422. #define BOX_C1_ELEMS (1<<BOX_C1_LOG)
  158423. #define BOX_C2_ELEMS (1<<BOX_C2_LOG)
  158424. #define BOX_C0_SHIFT (C0_SHIFT + BOX_C0_LOG)
  158425. #define BOX_C1_SHIFT (C1_SHIFT + BOX_C1_LOG)
  158426. #define BOX_C2_SHIFT (C2_SHIFT + BOX_C2_LOG)
  158427. LOCAL(int)
  158428. find_nearby_colors (j_decompress_ptr cinfo, int minc0, int minc1, int minc2,
  158429. JSAMPLE colorlist[])
  158430. {
  158431. int numcolors = cinfo->actual_number_of_colors;
  158432. int maxc0, maxc1, maxc2;
  158433. int centerc0, centerc1, centerc2;
  158434. int i, x, ncolors;
  158435. INT32 minmaxdist, min_dist, max_dist, tdist;
  158436. INT32 mindist[MAXNUMCOLORS]; /* min distance to colormap entry i */
  158437. maxc0 = minc0 + ((1 << BOX_C0_SHIFT) - (1 << C0_SHIFT));
  158438. centerc0 = (minc0 + maxc0) >> 1;
  158439. maxc1 = minc1 + ((1 << BOX_C1_SHIFT) - (1 << C1_SHIFT));
  158440. centerc1 = (minc1 + maxc1) >> 1;
  158441. maxc2 = minc2 + ((1 << BOX_C2_SHIFT) - (1 << C2_SHIFT));
  158442. centerc2 = (minc2 + maxc2) >> 1;
  158443. minmaxdist = 0x7FFFFFFFL;
  158444. for (i = 0; i < numcolors; i++) {
  158445. x = GETJSAMPLE(cinfo->colormap[0][i]);
  158446. if (x < minc0) {
  158447. tdist = (x - minc0) * C0_SCALE;
  158448. min_dist = tdist*tdist;
  158449. tdist = (x - maxc0) * C0_SCALE;
  158450. max_dist = tdist*tdist;
  158451. } else if (x > maxc0) {
  158452. tdist = (x - maxc0) * C0_SCALE;
  158453. min_dist = tdist*tdist;
  158454. tdist = (x - minc0) * C0_SCALE;
  158455. max_dist = tdist*tdist;
  158456. } else {
  158457. min_dist = 0;
  158458. if (x <= centerc0) {
  158459. tdist = (x - maxc0) * C0_SCALE;
  158460. max_dist = tdist*tdist;
  158461. } else {
  158462. tdist = (x - minc0) * C0_SCALE;
  158463. max_dist = tdist*tdist;
  158464. }
  158465. }
  158466. x = GETJSAMPLE(cinfo->colormap[1][i]);
  158467. if (x < minc1) {
  158468. tdist = (x - minc1) * C1_SCALE;
  158469. min_dist += tdist*tdist;
  158470. tdist = (x - maxc1) * C1_SCALE;
  158471. max_dist += tdist*tdist;
  158472. } else if (x > maxc1) {
  158473. tdist = (x - maxc1) * C1_SCALE;
  158474. min_dist += tdist*tdist;
  158475. tdist = (x - minc1) * C1_SCALE;
  158476. max_dist += tdist*tdist;
  158477. } else {
  158478. if (x <= centerc1) {
  158479. tdist = (x - maxc1) * C1_SCALE;
  158480. max_dist += tdist*tdist;
  158481. } else {
  158482. tdist = (x - minc1) * C1_SCALE;
  158483. max_dist += tdist*tdist;
  158484. }
  158485. }
  158486. x = GETJSAMPLE(cinfo->colormap[2][i]);
  158487. if (x < minc2) {
  158488. tdist = (x - minc2) * C2_SCALE;
  158489. min_dist += tdist*tdist;
  158490. tdist = (x - maxc2) * C2_SCALE;
  158491. max_dist += tdist*tdist;
  158492. } else if (x > maxc2) {
  158493. tdist = (x - maxc2) * C2_SCALE;
  158494. min_dist += tdist*tdist;
  158495. tdist = (x - minc2) * C2_SCALE;
  158496. max_dist += tdist*tdist;
  158497. } else {
  158498. if (x <= centerc2) {
  158499. tdist = (x - maxc2) * C2_SCALE;
  158500. max_dist += tdist*tdist;
  158501. } else {
  158502. tdist = (x - minc2) * C2_SCALE;
  158503. max_dist += tdist*tdist;
  158504. }
  158505. }
  158506. mindist[i] = min_dist; /* save away the results */
  158507. if (max_dist < minmaxdist)
  158508. minmaxdist = max_dist;
  158509. }
  158510. ncolors = 0;
  158511. for (i = 0; i < numcolors; i++) {
  158512. if (mindist[i] <= minmaxdist)
  158513. colorlist[ncolors++] = (JSAMPLE) i;
  158514. }
  158515. return ncolors;
  158516. }
  158517. LOCAL(void)
  158518. find_best_colors (j_decompress_ptr cinfo, int minc0, int minc1, int minc2,
  158519. int numcolors, JSAMPLE colorlist[], JSAMPLE bestcolor[])
  158520. {
  158521. int ic0, ic1, ic2;
  158522. int i, icolor;
  158523. register INT32 * bptr; /* pointer into bestdist[] array */
  158524. JSAMPLE * cptr; /* pointer into bestcolor[] array */
  158525. INT32 dist0, dist1; /* initial distance values */
  158526. register INT32 dist2; /* current distance in inner loop */
  158527. INT32 xx0, xx1; /* distance increments */
  158528. register INT32 xx2;
  158529. INT32 inc0, inc1, inc2; /* initial values for increments */
  158530. INT32 bestdist[BOX_C0_ELEMS * BOX_C1_ELEMS * BOX_C2_ELEMS];
  158531. bptr = bestdist;
  158532. for (i = BOX_C0_ELEMS*BOX_C1_ELEMS*BOX_C2_ELEMS-1; i >= 0; i--)
  158533. *bptr++ = 0x7FFFFFFFL;
  158534. #define STEP_C0 ((1 << C0_SHIFT) * C0_SCALE)
  158535. #define STEP_C1 ((1 << C1_SHIFT) * C1_SCALE)
  158536. #define STEP_C2 ((1 << C2_SHIFT) * C2_SCALE)
  158537. for (i = 0; i < numcolors; i++) {
  158538. icolor = GETJSAMPLE(colorlist[i]);
  158539. inc0 = (minc0 - GETJSAMPLE(cinfo->colormap[0][icolor])) * C0_SCALE;
  158540. dist0 = inc0*inc0;
  158541. inc1 = (minc1 - GETJSAMPLE(cinfo->colormap[1][icolor])) * C1_SCALE;
  158542. dist0 += inc1*inc1;
  158543. inc2 = (minc2 - GETJSAMPLE(cinfo->colormap[2][icolor])) * C2_SCALE;
  158544. dist0 += inc2*inc2;
  158545. inc0 = inc0 * (2 * STEP_C0) + STEP_C0 * STEP_C0;
  158546. inc1 = inc1 * (2 * STEP_C1) + STEP_C1 * STEP_C1;
  158547. inc2 = inc2 * (2 * STEP_C2) + STEP_C2 * STEP_C2;
  158548. bptr = bestdist;
  158549. cptr = bestcolor;
  158550. xx0 = inc0;
  158551. for (ic0 = BOX_C0_ELEMS-1; ic0 >= 0; ic0--) {
  158552. dist1 = dist0;
  158553. xx1 = inc1;
  158554. for (ic1 = BOX_C1_ELEMS-1; ic1 >= 0; ic1--) {
  158555. dist2 = dist1;
  158556. xx2 = inc2;
  158557. for (ic2 = BOX_C2_ELEMS-1; ic2 >= 0; ic2--) {
  158558. if (dist2 < *bptr) {
  158559. *bptr = dist2;
  158560. *cptr = (JSAMPLE) icolor;
  158561. }
  158562. dist2 += xx2;
  158563. xx2 += 2 * STEP_C2 * STEP_C2;
  158564. bptr++;
  158565. cptr++;
  158566. }
  158567. dist1 += xx1;
  158568. xx1 += 2 * STEP_C1 * STEP_C1;
  158569. }
  158570. dist0 += xx0;
  158571. xx0 += 2 * STEP_C0 * STEP_C0;
  158572. }
  158573. }
  158574. }
  158575. LOCAL(void)
  158576. fill_inverse_cmap (j_decompress_ptr cinfo, int c0, int c1, int c2)
  158577. {
  158578. my_cquantize_ptr2 cquantize = (my_cquantize_ptr2) cinfo->cquantize;
  158579. hist3d histogram = cquantize->histogram;
  158580. int minc0, minc1, minc2; /* lower left corner of update box */
  158581. int ic0, ic1, ic2;
  158582. register JSAMPLE * cptr; /* pointer into bestcolor[] array */
  158583. register histptr cachep; /* pointer into main cache array */
  158584. JSAMPLE colorlist[MAXNUMCOLORS];
  158585. int numcolors; /* number of candidate colors */
  158586. JSAMPLE bestcolor[BOX_C0_ELEMS * BOX_C1_ELEMS * BOX_C2_ELEMS];
  158587. c0 >>= BOX_C0_LOG;
  158588. c1 >>= BOX_C1_LOG;
  158589. c2 >>= BOX_C2_LOG;
  158590. minc0 = (c0 << BOX_C0_SHIFT) + ((1 << C0_SHIFT) >> 1);
  158591. minc1 = (c1 << BOX_C1_SHIFT) + ((1 << C1_SHIFT) >> 1);
  158592. minc2 = (c2 << BOX_C2_SHIFT) + ((1 << C2_SHIFT) >> 1);
  158593. numcolors = find_nearby_colors(cinfo, minc0, minc1, minc2, colorlist);
  158594. find_best_colors(cinfo, minc0, minc1, minc2, numcolors, colorlist,
  158595. bestcolor);
  158596. c0 <<= BOX_C0_LOG; /* convert ID back to base cell indexes */
  158597. c1 <<= BOX_C1_LOG;
  158598. c2 <<= BOX_C2_LOG;
  158599. cptr = bestcolor;
  158600. for (ic0 = 0; ic0 < BOX_C0_ELEMS; ic0++) {
  158601. for (ic1 = 0; ic1 < BOX_C1_ELEMS; ic1++) {
  158602. cachep = & histogram[c0+ic0][c1+ic1][c2];
  158603. for (ic2 = 0; ic2 < BOX_C2_ELEMS; ic2++) {
  158604. *cachep++ = (histcell) (GETJSAMPLE(*cptr++) + 1);
  158605. }
  158606. }
  158607. }
  158608. }
  158609. METHODDEF(void)
  158610. pass2_no_dither (j_decompress_ptr cinfo,
  158611. JSAMPARRAY input_buf, JSAMPARRAY output_buf, int num_rows)
  158612. {
  158613. my_cquantize_ptr2 cquantize = (my_cquantize_ptr2) cinfo->cquantize;
  158614. hist3d histogram = cquantize->histogram;
  158615. register JSAMPROW inptr, outptr;
  158616. register histptr cachep;
  158617. register int c0, c1, c2;
  158618. int row;
  158619. JDIMENSION col;
  158620. JDIMENSION width = cinfo->output_width;
  158621. for (row = 0; row < num_rows; row++) {
  158622. inptr = input_buf[row];
  158623. outptr = output_buf[row];
  158624. for (col = width; col > 0; col--) {
  158625. c0 = GETJSAMPLE(*inptr++) >> C0_SHIFT;
  158626. c1 = GETJSAMPLE(*inptr++) >> C1_SHIFT;
  158627. c2 = GETJSAMPLE(*inptr++) >> C2_SHIFT;
  158628. cachep = & histogram[c0][c1][c2];
  158629. if (*cachep == 0)
  158630. fill_inverse_cmap(cinfo, c0,c1,c2);
  158631. *outptr++ = (JSAMPLE) (*cachep - 1);
  158632. }
  158633. }
  158634. }
  158635. METHODDEF(void)
  158636. pass2_fs_dither (j_decompress_ptr cinfo,
  158637. JSAMPARRAY input_buf, JSAMPARRAY output_buf, int num_rows)
  158638. {
  158639. my_cquantize_ptr2 cquantize = (my_cquantize_ptr2) cinfo->cquantize;
  158640. hist3d histogram = cquantize->histogram;
  158641. register LOCFSERROR cur0, cur1, cur2; /* current error or pixel value */
  158642. LOCFSERROR belowerr0, belowerr1, belowerr2; /* error for pixel below cur */
  158643. LOCFSERROR bpreverr0, bpreverr1, bpreverr2; /* error for below/prev col */
  158644. register FSERRPTR errorptr; /* => fserrors[] at column before current */
  158645. JSAMPROW inptr; /* => current input pixel */
  158646. JSAMPROW outptr; /* => current output pixel */
  158647. histptr cachep;
  158648. int dir; /* +1 or -1 depending on direction */
  158649. int dir3; /* 3*dir, for advancing inptr & errorptr */
  158650. int row;
  158651. JDIMENSION col;
  158652. JDIMENSION width = cinfo->output_width;
  158653. JSAMPLE *range_limit = cinfo->sample_range_limit;
  158654. int *error_limit = cquantize->error_limiter;
  158655. JSAMPROW colormap0 = cinfo->colormap[0];
  158656. JSAMPROW colormap1 = cinfo->colormap[1];
  158657. JSAMPROW colormap2 = cinfo->colormap[2];
  158658. SHIFT_TEMPS
  158659. for (row = 0; row < num_rows; row++) {
  158660. inptr = input_buf[row];
  158661. outptr = output_buf[row];
  158662. if (cquantize->on_odd_row) {
  158663. inptr += (width-1) * 3; /* so point to rightmost pixel */
  158664. outptr += width-1;
  158665. dir = -1;
  158666. dir3 = -3;
  158667. errorptr = cquantize->fserrors + (width+1)*3; /* => entry after last column */
  158668. cquantize->on_odd_row = FALSE; /* flip for next time */
  158669. } else {
  158670. dir = 1;
  158671. dir3 = 3;
  158672. errorptr = cquantize->fserrors; /* => entry before first real column */
  158673. cquantize->on_odd_row = TRUE; /* flip for next time */
  158674. }
  158675. cur0 = cur1 = cur2 = 0;
  158676. belowerr0 = belowerr1 = belowerr2 = 0;
  158677. bpreverr0 = bpreverr1 = bpreverr2 = 0;
  158678. for (col = width; col > 0; col--) {
  158679. cur0 = RIGHT_SHIFT(cur0 + errorptr[dir3+0] + 8, 4);
  158680. cur1 = RIGHT_SHIFT(cur1 + errorptr[dir3+1] + 8, 4);
  158681. cur2 = RIGHT_SHIFT(cur2 + errorptr[dir3+2] + 8, 4);
  158682. cur0 = error_limit[cur0];
  158683. cur1 = error_limit[cur1];
  158684. cur2 = error_limit[cur2];
  158685. cur0 += GETJSAMPLE(inptr[0]);
  158686. cur1 += GETJSAMPLE(inptr[1]);
  158687. cur2 += GETJSAMPLE(inptr[2]);
  158688. cur0 = GETJSAMPLE(range_limit[cur0]);
  158689. cur1 = GETJSAMPLE(range_limit[cur1]);
  158690. cur2 = GETJSAMPLE(range_limit[cur2]);
  158691. cachep = & histogram[cur0>>C0_SHIFT][cur1>>C1_SHIFT][cur2>>C2_SHIFT];
  158692. if (*cachep == 0)
  158693. fill_inverse_cmap(cinfo, cur0>>C0_SHIFT,cur1>>C1_SHIFT,cur2>>C2_SHIFT);
  158694. { register int pixcode = *cachep - 1;
  158695. *outptr = (JSAMPLE) pixcode;
  158696. cur0 -= GETJSAMPLE(colormap0[pixcode]);
  158697. cur1 -= GETJSAMPLE(colormap1[pixcode]);
  158698. cur2 -= GETJSAMPLE(colormap2[pixcode]);
  158699. }
  158700. { register LOCFSERROR bnexterr, delta;
  158701. bnexterr = cur0; /* Process component 0 */
  158702. delta = cur0 * 2;
  158703. cur0 += delta; /* form error * 3 */
  158704. errorptr[0] = (FSERROR) (bpreverr0 + cur0);
  158705. cur0 += delta; /* form error * 5 */
  158706. bpreverr0 = belowerr0 + cur0;
  158707. belowerr0 = bnexterr;
  158708. cur0 += delta; /* form error * 7 */
  158709. bnexterr = cur1; /* Process component 1 */
  158710. delta = cur1 * 2;
  158711. cur1 += delta; /* form error * 3 */
  158712. errorptr[1] = (FSERROR) (bpreverr1 + cur1);
  158713. cur1 += delta; /* form error * 5 */
  158714. bpreverr1 = belowerr1 + cur1;
  158715. belowerr1 = bnexterr;
  158716. cur1 += delta; /* form error * 7 */
  158717. bnexterr = cur2; /* Process component 2 */
  158718. delta = cur2 * 2;
  158719. cur2 += delta; /* form error * 3 */
  158720. errorptr[2] = (FSERROR) (bpreverr2 + cur2);
  158721. cur2 += delta; /* form error * 5 */
  158722. bpreverr2 = belowerr2 + cur2;
  158723. belowerr2 = bnexterr;
  158724. cur2 += delta; /* form error * 7 */
  158725. }
  158726. inptr += dir3; /* Advance pixel pointers to next column */
  158727. outptr += dir;
  158728. errorptr += dir3; /* advance errorptr to current column */
  158729. }
  158730. errorptr[0] = (FSERROR) bpreverr0; /* unload prev errs into array */
  158731. errorptr[1] = (FSERROR) bpreverr1;
  158732. errorptr[2] = (FSERROR) bpreverr2;
  158733. }
  158734. }
  158735. LOCAL(void)
  158736. init_error_limit (j_decompress_ptr cinfo)
  158737. {
  158738. my_cquantize_ptr2 cquantize = (my_cquantize_ptr2) cinfo->cquantize;
  158739. int * table;
  158740. int in, out;
  158741. table = (int *) (*cinfo->mem->alloc_small)
  158742. ((j_common_ptr) cinfo, JPOOL_IMAGE, (MAXJSAMPLE*2+1) * SIZEOF(int));
  158743. table += MAXJSAMPLE; /* so can index -MAXJSAMPLE .. +MAXJSAMPLE */
  158744. cquantize->error_limiter = table;
  158745. #define STEPSIZE ((MAXJSAMPLE+1)/16)
  158746. out = 0;
  158747. for (in = 0; in < STEPSIZE; in++, out++) {
  158748. table[in] = out; table[-in] = -out;
  158749. }
  158750. for (; in < STEPSIZE*3; in++, out += (in&1) ? 0 : 1) {
  158751. table[in] = out; table[-in] = -out;
  158752. }
  158753. for (; in <= MAXJSAMPLE; in++) {
  158754. table[in] = out; table[-in] = -out;
  158755. }
  158756. #undef STEPSIZE
  158757. }
  158758. METHODDEF(void)
  158759. finish_pass1 (j_decompress_ptr cinfo)
  158760. {
  158761. my_cquantize_ptr2 cquantize = (my_cquantize_ptr2) cinfo->cquantize;
  158762. cinfo->colormap = cquantize->sv_colormap;
  158763. select_colors(cinfo, cquantize->desired);
  158764. cquantize->needs_zeroed = TRUE;
  158765. }
  158766. METHODDEF(void)
  158767. finish_pass2 (j_decompress_ptr cinfo)
  158768. {
  158769. }
  158770. METHODDEF(void)
  158771. start_pass_2_quant (j_decompress_ptr cinfo, boolean is_pre_scan)
  158772. {
  158773. my_cquantize_ptr2 cquantize = (my_cquantize_ptr2) cinfo->cquantize;
  158774. hist3d histogram = cquantize->histogram;
  158775. int i;
  158776. if (cinfo->dither_mode != JDITHER_NONE)
  158777. cinfo->dither_mode = JDITHER_FS;
  158778. if (is_pre_scan) {
  158779. cquantize->pub.color_quantize = prescan_quantize;
  158780. cquantize->pub.finish_pass = finish_pass1;
  158781. cquantize->needs_zeroed = TRUE; /* Always zero histogram */
  158782. } else {
  158783. if (cinfo->dither_mode == JDITHER_FS)
  158784. cquantize->pub.color_quantize = pass2_fs_dither;
  158785. else
  158786. cquantize->pub.color_quantize = pass2_no_dither;
  158787. cquantize->pub.finish_pass = finish_pass2;
  158788. i = cinfo->actual_number_of_colors;
  158789. if (i < 1)
  158790. ERREXIT1(cinfo, JERR_QUANT_FEW_COLORS, 1);
  158791. if (i > MAXNUMCOLORS)
  158792. ERREXIT1(cinfo, JERR_QUANT_MANY_COLORS, MAXNUMCOLORS);
  158793. if (cinfo->dither_mode == JDITHER_FS) {
  158794. size_t arraysize = (size_t) ((cinfo->output_width + 2) *
  158795. (3 * SIZEOF(FSERROR)));
  158796. if (cquantize->fserrors == NULL)
  158797. cquantize->fserrors = (FSERRPTR) (*cinfo->mem->alloc_large)
  158798. ((j_common_ptr) cinfo, JPOOL_IMAGE, arraysize);
  158799. jzero_far((void FAR *) cquantize->fserrors, arraysize);
  158800. if (cquantize->error_limiter == NULL)
  158801. init_error_limit(cinfo);
  158802. cquantize->on_odd_row = FALSE;
  158803. }
  158804. }
  158805. if (cquantize->needs_zeroed) {
  158806. for (i = 0; i < HIST_C0_ELEMS; i++) {
  158807. jzero_far((void FAR *) histogram[i],
  158808. HIST_C1_ELEMS*HIST_C2_ELEMS * SIZEOF(histcell));
  158809. }
  158810. cquantize->needs_zeroed = FALSE;
  158811. }
  158812. }
  158813. METHODDEF(void)
  158814. new_color_map_2_quant (j_decompress_ptr cinfo)
  158815. {
  158816. my_cquantize_ptr2 cquantize = (my_cquantize_ptr2) cinfo->cquantize;
  158817. cquantize->needs_zeroed = TRUE;
  158818. }
  158819. GLOBAL(void)
  158820. jinit_2pass_quantizer (j_decompress_ptr cinfo)
  158821. {
  158822. my_cquantize_ptr2 cquantize;
  158823. int i;
  158824. cquantize = (my_cquantize_ptr2)
  158825. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  158826. SIZEOF(my_cquantizer2));
  158827. cinfo->cquantize = (struct jpeg_color_quantizer *) cquantize;
  158828. cquantize->pub.start_pass = start_pass_2_quant;
  158829. cquantize->pub.new_color_map = new_color_map_2_quant;
  158830. cquantize->fserrors = NULL; /* flag optional arrays not allocated */
  158831. cquantize->error_limiter = NULL;
  158832. if (cinfo->out_color_components != 3)
  158833. ERREXIT(cinfo, JERR_NOTIMPL);
  158834. cquantize->histogram = (hist3d) (*cinfo->mem->alloc_small)
  158835. ((j_common_ptr) cinfo, JPOOL_IMAGE, HIST_C0_ELEMS * SIZEOF(hist2d));
  158836. for (i = 0; i < HIST_C0_ELEMS; i++) {
  158837. cquantize->histogram[i] = (hist2d) (*cinfo->mem->alloc_large)
  158838. ((j_common_ptr) cinfo, JPOOL_IMAGE,
  158839. HIST_C1_ELEMS*HIST_C2_ELEMS * SIZEOF(histcell));
  158840. }
  158841. cquantize->needs_zeroed = TRUE; /* histogram is garbage now */
  158842. if (cinfo->enable_2pass_quant) {
  158843. int desired = cinfo->desired_number_of_colors;
  158844. if (desired < 8)
  158845. ERREXIT1(cinfo, JERR_QUANT_FEW_COLORS, 8);
  158846. if (desired > MAXNUMCOLORS)
  158847. ERREXIT1(cinfo, JERR_QUANT_MANY_COLORS, MAXNUMCOLORS);
  158848. cquantize->sv_colormap = (*cinfo->mem->alloc_sarray)
  158849. ((j_common_ptr) cinfo,JPOOL_IMAGE, (JDIMENSION) desired, (JDIMENSION) 3);
  158850. cquantize->desired = desired;
  158851. } else
  158852. cquantize->sv_colormap = NULL;
  158853. if (cinfo->dither_mode != JDITHER_NONE)
  158854. cinfo->dither_mode = JDITHER_FS;
  158855. if (cinfo->dither_mode == JDITHER_FS) {
  158856. cquantize->fserrors = (FSERRPTR) (*cinfo->mem->alloc_large)
  158857. ((j_common_ptr) cinfo, JPOOL_IMAGE,
  158858. (size_t) ((cinfo->output_width + 2) * (3 * SIZEOF(FSERROR))));
  158859. init_error_limit(cinfo);
  158860. }
  158861. }
  158862. #endif /* QUANT_2PASS_SUPPORTED */
  158863. /********* End of inlined file: jquant2.c *********/
  158864. /********* Start of inlined file: jutils.c *********/
  158865. #define JPEG_INTERNALS
  158866. #if 0 /* This table is not actually needed in v6a */
  158867. const int jpeg_zigzag_order[DCTSIZE2] = {
  158868. 0, 1, 5, 6, 14, 15, 27, 28,
  158869. 2, 4, 7, 13, 16, 26, 29, 42,
  158870. 3, 8, 12, 17, 25, 30, 41, 43,
  158871. 9, 11, 18, 24, 31, 40, 44, 53,
  158872. 10, 19, 23, 32, 39, 45, 52, 54,
  158873. 20, 22, 33, 38, 46, 51, 55, 60,
  158874. 21, 34, 37, 47, 50, 56, 59, 61,
  158875. 35, 36, 48, 49, 57, 58, 62, 63
  158876. };
  158877. #endif
  158878. const int jpeg_natural_order[DCTSIZE2+16] = {
  158879. 0, 1, 8, 16, 9, 2, 3, 10,
  158880. 17, 24, 32, 25, 18, 11, 4, 5,
  158881. 12, 19, 26, 33, 40, 48, 41, 34,
  158882. 27, 20, 13, 6, 7, 14, 21, 28,
  158883. 35, 42, 49, 56, 57, 50, 43, 36,
  158884. 29, 22, 15, 23, 30, 37, 44, 51,
  158885. 58, 59, 52, 45, 38, 31, 39, 46,
  158886. 53, 60, 61, 54, 47, 55, 62, 63,
  158887. 63, 63, 63, 63, 63, 63, 63, 63, /* extra entries for safety in decoder */
  158888. 63, 63, 63, 63, 63, 63, 63, 63
  158889. };
  158890. GLOBAL(long)
  158891. jdiv_round_up (long a, long b)
  158892. {
  158893. return (a + b - 1L) / b;
  158894. }
  158895. GLOBAL(long)
  158896. jround_up (long a, long b)
  158897. {
  158898. a += b - 1L;
  158899. return a - (a % b);
  158900. }
  158901. #ifndef NEED_FAR_POINTERS /* normal case, same as regular macros */
  158902. #define FMEMCOPY(dest,src,size) MEMCOPY(dest,src,size)
  158903. #define FMEMZERO(target,size) MEMZERO(target,size)
  158904. #else /* 80x86 case, define if we can */
  158905. #ifdef USE_FMEM
  158906. #define FMEMCOPY(dest,src,size) _fmemcpy((void FAR *)(dest), (const void FAR *)(src), (size_t)(size))
  158907. #define FMEMZERO(target,size) _fmemset((void FAR *)(target), 0, (size_t)(size))
  158908. #endif
  158909. #endif
  158910. GLOBAL(void)
  158911. jcopy_sample_rows (JSAMPARRAY input_array, int source_row,
  158912. JSAMPARRAY output_array, int dest_row,
  158913. int num_rows, JDIMENSION num_cols)
  158914. {
  158915. register JSAMPROW inptr, outptr;
  158916. #ifdef FMEMCOPY
  158917. register size_t count = (size_t) (num_cols * SIZEOF(JSAMPLE));
  158918. #else
  158919. register JDIMENSION count;
  158920. #endif
  158921. register int row;
  158922. input_array += source_row;
  158923. output_array += dest_row;
  158924. for (row = num_rows; row > 0; row--) {
  158925. inptr = *input_array++;
  158926. outptr = *output_array++;
  158927. #ifdef FMEMCOPY
  158928. FMEMCOPY(outptr, inptr, count);
  158929. #else
  158930. for (count = num_cols; count > 0; count--)
  158931. *outptr++ = *inptr++; /* needn't bother with GETJSAMPLE() here */
  158932. #endif
  158933. }
  158934. }
  158935. GLOBAL(void)
  158936. jcopy_block_row (JBLOCKROW input_row, JBLOCKROW output_row,
  158937. JDIMENSION num_blocks)
  158938. {
  158939. #ifdef FMEMCOPY
  158940. FMEMCOPY(output_row, input_row, num_blocks * (DCTSIZE2 * SIZEOF(JCOEF)));
  158941. #else
  158942. register JCOEFPTR inptr, outptr;
  158943. register long count;
  158944. inptr = (JCOEFPTR) input_row;
  158945. outptr = (JCOEFPTR) output_row;
  158946. for (count = (long) num_blocks * DCTSIZE2; count > 0; count--) {
  158947. *outptr++ = *inptr++;
  158948. }
  158949. #endif
  158950. }
  158951. GLOBAL(void)
  158952. jzero_far (void FAR * target, size_t bytestozero)
  158953. {
  158954. #ifdef FMEMZERO
  158955. FMEMZERO(target, bytestozero);
  158956. #else
  158957. register char FAR * ptr = (char FAR *) target;
  158958. register size_t count;
  158959. for (count = bytestozero; count > 0; count--) {
  158960. *ptr++ = 0;
  158961. }
  158962. #endif
  158963. }
  158964. /********* End of inlined file: jutils.c *********/
  158965. /********* Start of inlined file: transupp.c *********/
  158966. #define JPEG_INTERNALS
  158967. /********* Start of inlined file: transupp.h *********/
  158968. #ifndef TRANSFORMS_SUPPORTED
  158969. #define TRANSFORMS_SUPPORTED 1 /* 0 disables transform code */
  158970. #endif
  158971. #ifdef NEED_SHORT_EXTERNAL_NAMES
  158972. #define jtransform_request_workspace jTrRequest
  158973. #define jtransform_adjust_parameters jTrAdjust
  158974. #define jtransform_execute_transformation jTrExec
  158975. #define jcopy_markers_setup jCMrkSetup
  158976. #define jcopy_markers_execute jCMrkExec
  158977. #endif /* NEED_SHORT_EXTERNAL_NAMES */
  158978. typedef enum {
  158979. JXFORM_NONE, /* no transformation */
  158980. JXFORM_FLIP_H, /* horizontal flip */
  158981. JXFORM_FLIP_V, /* vertical flip */
  158982. JXFORM_TRANSPOSE, /* transpose across UL-to-LR axis */
  158983. JXFORM_TRANSVERSE, /* transpose across UR-to-LL axis */
  158984. JXFORM_ROT_90, /* 90-degree clockwise rotation */
  158985. JXFORM_ROT_180, /* 180-degree rotation */
  158986. JXFORM_ROT_270 /* 270-degree clockwise (or 90 ccw) */
  158987. } JXFORM_CODE;
  158988. typedef struct {
  158989. JXFORM_CODE transform; /* image transform operator */
  158990. boolean trim; /* if TRUE, trim partial MCUs as needed */
  158991. boolean force_grayscale; /* if TRUE, convert color image to grayscale */
  158992. int num_components; /* # of components in workspace */
  158993. jvirt_barray_ptr * workspace_coef_arrays; /* workspace for transformations */
  158994. } jpeg_transform_info;
  158995. #if TRANSFORMS_SUPPORTED
  158996. EXTERN(void) jtransform_request_workspace
  158997. JPP((j_decompress_ptr srcinfo, jpeg_transform_info *info));
  158998. EXTERN(jvirt_barray_ptr *) jtransform_adjust_parameters
  158999. JPP((j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
  159000. jvirt_barray_ptr *src_coef_arrays,
  159001. jpeg_transform_info *info));
  159002. EXTERN(void) jtransform_execute_transformation
  159003. JPP((j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
  159004. jvirt_barray_ptr *src_coef_arrays,
  159005. jpeg_transform_info *info));
  159006. #endif /* TRANSFORMS_SUPPORTED */
  159007. typedef enum {
  159008. JCOPYOPT_NONE, /* copy no optional markers */
  159009. JCOPYOPT_COMMENTS, /* copy only comment (COM) markers */
  159010. JCOPYOPT_ALL /* copy all optional markers */
  159011. } JCOPY_OPTION;
  159012. #define JCOPYOPT_DEFAULT JCOPYOPT_COMMENTS /* recommended default */
  159013. EXTERN(void) jcopy_markers_setup
  159014. JPP((j_decompress_ptr srcinfo, JCOPY_OPTION option));
  159015. EXTERN(void) jcopy_markers_execute
  159016. JPP((j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
  159017. JCOPY_OPTION option));
  159018. /********* End of inlined file: transupp.h *********/
  159019. #if TRANSFORMS_SUPPORTED
  159020. LOCAL(void)
  159021. do_flip_h (j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
  159022. jvirt_barray_ptr *src_coef_arrays)
  159023. {
  159024. JDIMENSION MCU_cols, comp_width, blk_x, blk_y;
  159025. int ci, k, offset_y;
  159026. JBLOCKARRAY buffer;
  159027. JCOEFPTR ptr1, ptr2;
  159028. JCOEF temp1, temp2;
  159029. jpeg_component_info *compptr;
  159030. MCU_cols = dstinfo->image_width / (dstinfo->max_h_samp_factor * DCTSIZE);
  159031. for (ci = 0; ci < dstinfo->num_components; ci++) {
  159032. compptr = dstinfo->comp_info + ci;
  159033. comp_width = MCU_cols * compptr->h_samp_factor;
  159034. for (blk_y = 0; blk_y < compptr->height_in_blocks;
  159035. blk_y += compptr->v_samp_factor) {
  159036. buffer = (*srcinfo->mem->access_virt_barray)
  159037. ((j_common_ptr) srcinfo, src_coef_arrays[ci], blk_y,
  159038. (JDIMENSION) compptr->v_samp_factor, TRUE);
  159039. for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) {
  159040. for (blk_x = 0; blk_x * 2 < comp_width; blk_x++) {
  159041. ptr1 = buffer[offset_y][blk_x];
  159042. ptr2 = buffer[offset_y][comp_width - blk_x - 1];
  159043. for (k = 0; k < DCTSIZE2; k += 2) {
  159044. temp1 = *ptr1; /* swap even column */
  159045. temp2 = *ptr2;
  159046. *ptr1++ = temp2;
  159047. *ptr2++ = temp1;
  159048. temp1 = *ptr1; /* swap odd column with sign change */
  159049. temp2 = *ptr2;
  159050. *ptr1++ = -temp2;
  159051. *ptr2++ = -temp1;
  159052. }
  159053. }
  159054. }
  159055. }
  159056. }
  159057. }
  159058. LOCAL(void)
  159059. do_flip_v (j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
  159060. jvirt_barray_ptr *src_coef_arrays,
  159061. jvirt_barray_ptr *dst_coef_arrays)
  159062. {
  159063. JDIMENSION MCU_rows, comp_height, dst_blk_x, dst_blk_y;
  159064. int ci, i, j, offset_y;
  159065. JBLOCKARRAY src_buffer, dst_buffer;
  159066. JBLOCKROW src_row_ptr, dst_row_ptr;
  159067. JCOEFPTR src_ptr, dst_ptr;
  159068. jpeg_component_info *compptr;
  159069. MCU_rows = dstinfo->image_height / (dstinfo->max_v_samp_factor * DCTSIZE);
  159070. for (ci = 0; ci < dstinfo->num_components; ci++) {
  159071. compptr = dstinfo->comp_info + ci;
  159072. comp_height = MCU_rows * compptr->v_samp_factor;
  159073. for (dst_blk_y = 0; dst_blk_y < compptr->height_in_blocks;
  159074. dst_blk_y += compptr->v_samp_factor) {
  159075. dst_buffer = (*srcinfo->mem->access_virt_barray)
  159076. ((j_common_ptr) srcinfo, dst_coef_arrays[ci], dst_blk_y,
  159077. (JDIMENSION) compptr->v_samp_factor, TRUE);
  159078. if (dst_blk_y < comp_height) {
  159079. src_buffer = (*srcinfo->mem->access_virt_barray)
  159080. ((j_common_ptr) srcinfo, src_coef_arrays[ci],
  159081. comp_height - dst_blk_y - (JDIMENSION) compptr->v_samp_factor,
  159082. (JDIMENSION) compptr->v_samp_factor, FALSE);
  159083. } else {
  159084. src_buffer = (*srcinfo->mem->access_virt_barray)
  159085. ((j_common_ptr) srcinfo, src_coef_arrays[ci], dst_blk_y,
  159086. (JDIMENSION) compptr->v_samp_factor, FALSE);
  159087. }
  159088. for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) {
  159089. if (dst_blk_y < comp_height) {
  159090. dst_row_ptr = dst_buffer[offset_y];
  159091. src_row_ptr = src_buffer[compptr->v_samp_factor - offset_y - 1];
  159092. for (dst_blk_x = 0; dst_blk_x < compptr->width_in_blocks;
  159093. dst_blk_x++) {
  159094. dst_ptr = dst_row_ptr[dst_blk_x];
  159095. src_ptr = src_row_ptr[dst_blk_x];
  159096. for (i = 0; i < DCTSIZE; i += 2) {
  159097. for (j = 0; j < DCTSIZE; j++)
  159098. *dst_ptr++ = *src_ptr++;
  159099. for (j = 0; j < DCTSIZE; j++)
  159100. *dst_ptr++ = - *src_ptr++;
  159101. }
  159102. }
  159103. } else {
  159104. jcopy_block_row(src_buffer[offset_y], dst_buffer[offset_y],
  159105. compptr->width_in_blocks);
  159106. }
  159107. }
  159108. }
  159109. }
  159110. }
  159111. LOCAL(void)
  159112. do_transpose (j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
  159113. jvirt_barray_ptr *src_coef_arrays,
  159114. jvirt_barray_ptr *dst_coef_arrays)
  159115. {
  159116. JDIMENSION dst_blk_x, dst_blk_y;
  159117. int ci, i, j, offset_x, offset_y;
  159118. JBLOCKARRAY src_buffer, dst_buffer;
  159119. JCOEFPTR src_ptr, dst_ptr;
  159120. jpeg_component_info *compptr;
  159121. for (ci = 0; ci < dstinfo->num_components; ci++) {
  159122. compptr = dstinfo->comp_info + ci;
  159123. for (dst_blk_y = 0; dst_blk_y < compptr->height_in_blocks;
  159124. dst_blk_y += compptr->v_samp_factor) {
  159125. dst_buffer = (*srcinfo->mem->access_virt_barray)
  159126. ((j_common_ptr) srcinfo, dst_coef_arrays[ci], dst_blk_y,
  159127. (JDIMENSION) compptr->v_samp_factor, TRUE);
  159128. for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) {
  159129. for (dst_blk_x = 0; dst_blk_x < compptr->width_in_blocks;
  159130. dst_blk_x += compptr->h_samp_factor) {
  159131. src_buffer = (*srcinfo->mem->access_virt_barray)
  159132. ((j_common_ptr) srcinfo, src_coef_arrays[ci], dst_blk_x,
  159133. (JDIMENSION) compptr->h_samp_factor, FALSE);
  159134. for (offset_x = 0; offset_x < compptr->h_samp_factor; offset_x++) {
  159135. src_ptr = src_buffer[offset_x][dst_blk_y + offset_y];
  159136. dst_ptr = dst_buffer[offset_y][dst_blk_x + offset_x];
  159137. for (i = 0; i < DCTSIZE; i++)
  159138. for (j = 0; j < DCTSIZE; j++)
  159139. dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j];
  159140. }
  159141. }
  159142. }
  159143. }
  159144. }
  159145. }
  159146. LOCAL(void)
  159147. do_rot_90 (j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
  159148. jvirt_barray_ptr *src_coef_arrays,
  159149. jvirt_barray_ptr *dst_coef_arrays)
  159150. {
  159151. JDIMENSION MCU_cols, comp_width, dst_blk_x, dst_blk_y;
  159152. int ci, i, j, offset_x, offset_y;
  159153. JBLOCKARRAY src_buffer, dst_buffer;
  159154. JCOEFPTR src_ptr, dst_ptr;
  159155. jpeg_component_info *compptr;
  159156. MCU_cols = dstinfo->image_width / (dstinfo->max_h_samp_factor * DCTSIZE);
  159157. for (ci = 0; ci < dstinfo->num_components; ci++) {
  159158. compptr = dstinfo->comp_info + ci;
  159159. comp_width = MCU_cols * compptr->h_samp_factor;
  159160. for (dst_blk_y = 0; dst_blk_y < compptr->height_in_blocks;
  159161. dst_blk_y += compptr->v_samp_factor) {
  159162. dst_buffer = (*srcinfo->mem->access_virt_barray)
  159163. ((j_common_ptr) srcinfo, dst_coef_arrays[ci], dst_blk_y,
  159164. (JDIMENSION) compptr->v_samp_factor, TRUE);
  159165. for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) {
  159166. for (dst_blk_x = 0; dst_blk_x < compptr->width_in_blocks;
  159167. dst_blk_x += compptr->h_samp_factor) {
  159168. src_buffer = (*srcinfo->mem->access_virt_barray)
  159169. ((j_common_ptr) srcinfo, src_coef_arrays[ci], dst_blk_x,
  159170. (JDIMENSION) compptr->h_samp_factor, FALSE);
  159171. for (offset_x = 0; offset_x < compptr->h_samp_factor; offset_x++) {
  159172. src_ptr = src_buffer[offset_x][dst_blk_y + offset_y];
  159173. if (dst_blk_x < comp_width) {
  159174. dst_ptr = dst_buffer[offset_y]
  159175. [comp_width - dst_blk_x - offset_x - 1];
  159176. for (i = 0; i < DCTSIZE; i++) {
  159177. for (j = 0; j < DCTSIZE; j++)
  159178. dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j];
  159179. i++;
  159180. for (j = 0; j < DCTSIZE; j++)
  159181. dst_ptr[j*DCTSIZE+i] = -src_ptr[i*DCTSIZE+j];
  159182. }
  159183. } else {
  159184. dst_ptr = dst_buffer[offset_y][dst_blk_x + offset_x];
  159185. for (i = 0; i < DCTSIZE; i++)
  159186. for (j = 0; j < DCTSIZE; j++)
  159187. dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j];
  159188. }
  159189. }
  159190. }
  159191. }
  159192. }
  159193. }
  159194. }
  159195. LOCAL(void)
  159196. do_rot_270 (j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
  159197. jvirt_barray_ptr *src_coef_arrays,
  159198. jvirt_barray_ptr *dst_coef_arrays)
  159199. {
  159200. JDIMENSION MCU_rows, comp_height, dst_blk_x, dst_blk_y;
  159201. int ci, i, j, offset_x, offset_y;
  159202. JBLOCKARRAY src_buffer, dst_buffer;
  159203. JCOEFPTR src_ptr, dst_ptr;
  159204. jpeg_component_info *compptr;
  159205. MCU_rows = dstinfo->image_height / (dstinfo->max_v_samp_factor * DCTSIZE);
  159206. for (ci = 0; ci < dstinfo->num_components; ci++) {
  159207. compptr = dstinfo->comp_info + ci;
  159208. comp_height = MCU_rows * compptr->v_samp_factor;
  159209. for (dst_blk_y = 0; dst_blk_y < compptr->height_in_blocks;
  159210. dst_blk_y += compptr->v_samp_factor) {
  159211. dst_buffer = (*srcinfo->mem->access_virt_barray)
  159212. ((j_common_ptr) srcinfo, dst_coef_arrays[ci], dst_blk_y,
  159213. (JDIMENSION) compptr->v_samp_factor, TRUE);
  159214. for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) {
  159215. for (dst_blk_x = 0; dst_blk_x < compptr->width_in_blocks;
  159216. dst_blk_x += compptr->h_samp_factor) {
  159217. src_buffer = (*srcinfo->mem->access_virt_barray)
  159218. ((j_common_ptr) srcinfo, src_coef_arrays[ci], dst_blk_x,
  159219. (JDIMENSION) compptr->h_samp_factor, FALSE);
  159220. for (offset_x = 0; offset_x < compptr->h_samp_factor; offset_x++) {
  159221. dst_ptr = dst_buffer[offset_y][dst_blk_x + offset_x];
  159222. if (dst_blk_y < comp_height) {
  159223. src_ptr = src_buffer[offset_x]
  159224. [comp_height - dst_blk_y - offset_y - 1];
  159225. for (i = 0; i < DCTSIZE; i++) {
  159226. for (j = 0; j < DCTSIZE; j++) {
  159227. dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j];
  159228. j++;
  159229. dst_ptr[j*DCTSIZE+i] = -src_ptr[i*DCTSIZE+j];
  159230. }
  159231. }
  159232. } else {
  159233. src_ptr = src_buffer[offset_x][dst_blk_y + offset_y];
  159234. for (i = 0; i < DCTSIZE; i++)
  159235. for (j = 0; j < DCTSIZE; j++)
  159236. dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j];
  159237. }
  159238. }
  159239. }
  159240. }
  159241. }
  159242. }
  159243. }
  159244. LOCAL(void)
  159245. do_rot_180 (j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
  159246. jvirt_barray_ptr *src_coef_arrays,
  159247. jvirt_barray_ptr *dst_coef_arrays)
  159248. {
  159249. JDIMENSION MCU_cols, MCU_rows, comp_width, comp_height, dst_blk_x, dst_blk_y;
  159250. int ci, i, j, offset_y;
  159251. JBLOCKARRAY src_buffer, dst_buffer;
  159252. JBLOCKROW src_row_ptr, dst_row_ptr;
  159253. JCOEFPTR src_ptr, dst_ptr;
  159254. jpeg_component_info *compptr;
  159255. MCU_cols = dstinfo->image_width / (dstinfo->max_h_samp_factor * DCTSIZE);
  159256. MCU_rows = dstinfo->image_height / (dstinfo->max_v_samp_factor * DCTSIZE);
  159257. for (ci = 0; ci < dstinfo->num_components; ci++) {
  159258. compptr = dstinfo->comp_info + ci;
  159259. comp_width = MCU_cols * compptr->h_samp_factor;
  159260. comp_height = MCU_rows * compptr->v_samp_factor;
  159261. for (dst_blk_y = 0; dst_blk_y < compptr->height_in_blocks;
  159262. dst_blk_y += compptr->v_samp_factor) {
  159263. dst_buffer = (*srcinfo->mem->access_virt_barray)
  159264. ((j_common_ptr) srcinfo, dst_coef_arrays[ci], dst_blk_y,
  159265. (JDIMENSION) compptr->v_samp_factor, TRUE);
  159266. if (dst_blk_y < comp_height) {
  159267. src_buffer = (*srcinfo->mem->access_virt_barray)
  159268. ((j_common_ptr) srcinfo, src_coef_arrays[ci],
  159269. comp_height - dst_blk_y - (JDIMENSION) compptr->v_samp_factor,
  159270. (JDIMENSION) compptr->v_samp_factor, FALSE);
  159271. } else {
  159272. src_buffer = (*srcinfo->mem->access_virt_barray)
  159273. ((j_common_ptr) srcinfo, src_coef_arrays[ci], dst_blk_y,
  159274. (JDIMENSION) compptr->v_samp_factor, FALSE);
  159275. }
  159276. for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) {
  159277. if (dst_blk_y < comp_height) {
  159278. dst_row_ptr = dst_buffer[offset_y];
  159279. src_row_ptr = src_buffer[compptr->v_samp_factor - offset_y - 1];
  159280. for (dst_blk_x = 0; dst_blk_x < comp_width; dst_blk_x++) {
  159281. dst_ptr = dst_row_ptr[dst_blk_x];
  159282. src_ptr = src_row_ptr[comp_width - dst_blk_x - 1];
  159283. for (i = 0; i < DCTSIZE; i += 2) {
  159284. for (j = 0; j < DCTSIZE; j += 2) {
  159285. *dst_ptr++ = *src_ptr++;
  159286. *dst_ptr++ = - *src_ptr++;
  159287. }
  159288. for (j = 0; j < DCTSIZE; j += 2) {
  159289. *dst_ptr++ = - *src_ptr++;
  159290. *dst_ptr++ = *src_ptr++;
  159291. }
  159292. }
  159293. }
  159294. for (; dst_blk_x < compptr->width_in_blocks; dst_blk_x++) {
  159295. dst_ptr = dst_row_ptr[dst_blk_x];
  159296. src_ptr = src_row_ptr[dst_blk_x];
  159297. for (i = 0; i < DCTSIZE; i += 2) {
  159298. for (j = 0; j < DCTSIZE; j++)
  159299. *dst_ptr++ = *src_ptr++;
  159300. for (j = 0; j < DCTSIZE; j++)
  159301. *dst_ptr++ = - *src_ptr++;
  159302. }
  159303. }
  159304. } else {
  159305. dst_row_ptr = dst_buffer[offset_y];
  159306. src_row_ptr = src_buffer[offset_y];
  159307. for (dst_blk_x = 0; dst_blk_x < comp_width; dst_blk_x++) {
  159308. dst_ptr = dst_row_ptr[dst_blk_x];
  159309. src_ptr = src_row_ptr[comp_width - dst_blk_x - 1];
  159310. for (i = 0; i < DCTSIZE2; i += 2) {
  159311. *dst_ptr++ = *src_ptr++;
  159312. *dst_ptr++ = - *src_ptr++;
  159313. }
  159314. }
  159315. for (; dst_blk_x < compptr->width_in_blocks; dst_blk_x++) {
  159316. dst_ptr = dst_row_ptr[dst_blk_x];
  159317. src_ptr = src_row_ptr[dst_blk_x];
  159318. for (i = 0; i < DCTSIZE2; i++)
  159319. *dst_ptr++ = *src_ptr++;
  159320. }
  159321. }
  159322. }
  159323. }
  159324. }
  159325. }
  159326. LOCAL(void)
  159327. do_transverse (j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
  159328. jvirt_barray_ptr *src_coef_arrays,
  159329. jvirt_barray_ptr *dst_coef_arrays)
  159330. {
  159331. JDIMENSION MCU_cols, MCU_rows, comp_width, comp_height, dst_blk_x, dst_blk_y;
  159332. int ci, i, j, offset_x, offset_y;
  159333. JBLOCKARRAY src_buffer, dst_buffer;
  159334. JCOEFPTR src_ptr, dst_ptr;
  159335. jpeg_component_info *compptr;
  159336. MCU_cols = dstinfo->image_width / (dstinfo->max_h_samp_factor * DCTSIZE);
  159337. MCU_rows = dstinfo->image_height / (dstinfo->max_v_samp_factor * DCTSIZE);
  159338. for (ci = 0; ci < dstinfo->num_components; ci++) {
  159339. compptr = dstinfo->comp_info + ci;
  159340. comp_width = MCU_cols * compptr->h_samp_factor;
  159341. comp_height = MCU_rows * compptr->v_samp_factor;
  159342. for (dst_blk_y = 0; dst_blk_y < compptr->height_in_blocks;
  159343. dst_blk_y += compptr->v_samp_factor) {
  159344. dst_buffer = (*srcinfo->mem->access_virt_barray)
  159345. ((j_common_ptr) srcinfo, dst_coef_arrays[ci], dst_blk_y,
  159346. (JDIMENSION) compptr->v_samp_factor, TRUE);
  159347. for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) {
  159348. for (dst_blk_x = 0; dst_blk_x < compptr->width_in_blocks;
  159349. dst_blk_x += compptr->h_samp_factor) {
  159350. src_buffer = (*srcinfo->mem->access_virt_barray)
  159351. ((j_common_ptr) srcinfo, src_coef_arrays[ci], dst_blk_x,
  159352. (JDIMENSION) compptr->h_samp_factor, FALSE);
  159353. for (offset_x = 0; offset_x < compptr->h_samp_factor; offset_x++) {
  159354. if (dst_blk_y < comp_height) {
  159355. src_ptr = src_buffer[offset_x]
  159356. [comp_height - dst_blk_y - offset_y - 1];
  159357. if (dst_blk_x < comp_width) {
  159358. dst_ptr = dst_buffer[offset_y]
  159359. [comp_width - dst_blk_x - offset_x - 1];
  159360. for (i = 0; i < DCTSIZE; i++) {
  159361. for (j = 0; j < DCTSIZE; j++) {
  159362. dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j];
  159363. j++;
  159364. dst_ptr[j*DCTSIZE+i] = -src_ptr[i*DCTSIZE+j];
  159365. }
  159366. i++;
  159367. for (j = 0; j < DCTSIZE; j++) {
  159368. dst_ptr[j*DCTSIZE+i] = -src_ptr[i*DCTSIZE+j];
  159369. j++;
  159370. dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j];
  159371. }
  159372. }
  159373. } else {
  159374. dst_ptr = dst_buffer[offset_y][dst_blk_x + offset_x];
  159375. for (i = 0; i < DCTSIZE; i++) {
  159376. for (j = 0; j < DCTSIZE; j++) {
  159377. dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j];
  159378. j++;
  159379. dst_ptr[j*DCTSIZE+i] = -src_ptr[i*DCTSIZE+j];
  159380. }
  159381. }
  159382. }
  159383. } else {
  159384. src_ptr = src_buffer[offset_x][dst_blk_y + offset_y];
  159385. if (dst_blk_x < comp_width) {
  159386. dst_ptr = dst_buffer[offset_y]
  159387. [comp_width - dst_blk_x - offset_x - 1];
  159388. for (i = 0; i < DCTSIZE; i++) {
  159389. for (j = 0; j < DCTSIZE; j++)
  159390. dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j];
  159391. i++;
  159392. for (j = 0; j < DCTSIZE; j++)
  159393. dst_ptr[j*DCTSIZE+i] = -src_ptr[i*DCTSIZE+j];
  159394. }
  159395. } else {
  159396. dst_ptr = dst_buffer[offset_y][dst_blk_x + offset_x];
  159397. for (i = 0; i < DCTSIZE; i++)
  159398. for (j = 0; j < DCTSIZE; j++)
  159399. dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j];
  159400. }
  159401. }
  159402. }
  159403. }
  159404. }
  159405. }
  159406. }
  159407. }
  159408. GLOBAL(void)
  159409. jtransform_request_workspace (j_decompress_ptr srcinfo,
  159410. jpeg_transform_info *info)
  159411. {
  159412. jvirt_barray_ptr *coef_arrays = NULL;
  159413. jpeg_component_info *compptr;
  159414. int ci;
  159415. if (info->force_grayscale &&
  159416. srcinfo->jpeg_color_space == JCS_YCbCr &&
  159417. srcinfo->num_components == 3) {
  159418. info->num_components = 1;
  159419. } else {
  159420. info->num_components = srcinfo->num_components;
  159421. }
  159422. switch (info->transform) {
  159423. case JXFORM_NONE:
  159424. case JXFORM_FLIP_H:
  159425. break;
  159426. case JXFORM_FLIP_V:
  159427. case JXFORM_ROT_180:
  159428. coef_arrays = (jvirt_barray_ptr *)
  159429. (*srcinfo->mem->alloc_small) ((j_common_ptr) srcinfo, JPOOL_IMAGE,
  159430. SIZEOF(jvirt_barray_ptr) * info->num_components);
  159431. for (ci = 0; ci < info->num_components; ci++) {
  159432. compptr = srcinfo->comp_info + ci;
  159433. coef_arrays[ci] = (*srcinfo->mem->request_virt_barray)
  159434. ((j_common_ptr) srcinfo, JPOOL_IMAGE, FALSE,
  159435. (JDIMENSION) jround_up((long) compptr->width_in_blocks,
  159436. (long) compptr->h_samp_factor),
  159437. (JDIMENSION) jround_up((long) compptr->height_in_blocks,
  159438. (long) compptr->v_samp_factor),
  159439. (JDIMENSION) compptr->v_samp_factor);
  159440. }
  159441. break;
  159442. case JXFORM_TRANSPOSE:
  159443. case JXFORM_TRANSVERSE:
  159444. case JXFORM_ROT_90:
  159445. case JXFORM_ROT_270:
  159446. coef_arrays = (jvirt_barray_ptr *)
  159447. (*srcinfo->mem->alloc_small) ((j_common_ptr) srcinfo, JPOOL_IMAGE,
  159448. SIZEOF(jvirt_barray_ptr) * info->num_components);
  159449. for (ci = 0; ci < info->num_components; ci++) {
  159450. compptr = srcinfo->comp_info + ci;
  159451. coef_arrays[ci] = (*srcinfo->mem->request_virt_barray)
  159452. ((j_common_ptr) srcinfo, JPOOL_IMAGE, FALSE,
  159453. (JDIMENSION) jround_up((long) compptr->height_in_blocks,
  159454. (long) compptr->v_samp_factor),
  159455. (JDIMENSION) jround_up((long) compptr->width_in_blocks,
  159456. (long) compptr->h_samp_factor),
  159457. (JDIMENSION) compptr->h_samp_factor);
  159458. }
  159459. break;
  159460. }
  159461. info->workspace_coef_arrays = coef_arrays;
  159462. }
  159463. LOCAL(void)
  159464. transpose_critical_parameters (j_compress_ptr dstinfo)
  159465. {
  159466. int tblno, i, j, ci, itemp;
  159467. jpeg_component_info *compptr;
  159468. JQUANT_TBL *qtblptr;
  159469. JDIMENSION dtemp;
  159470. UINT16 qtemp;
  159471. dtemp = dstinfo->image_width;
  159472. dstinfo->image_width = dstinfo->image_height;
  159473. dstinfo->image_height = dtemp;
  159474. for (ci = 0; ci < dstinfo->num_components; ci++) {
  159475. compptr = dstinfo->comp_info + ci;
  159476. itemp = compptr->h_samp_factor;
  159477. compptr->h_samp_factor = compptr->v_samp_factor;
  159478. compptr->v_samp_factor = itemp;
  159479. }
  159480. for (tblno = 0; tblno < NUM_QUANT_TBLS; tblno++) {
  159481. qtblptr = dstinfo->quant_tbl_ptrs[tblno];
  159482. if (qtblptr != NULL) {
  159483. for (i = 0; i < DCTSIZE; i++) {
  159484. for (j = 0; j < i; j++) {
  159485. qtemp = qtblptr->quantval[i*DCTSIZE+j];
  159486. qtblptr->quantval[i*DCTSIZE+j] = qtblptr->quantval[j*DCTSIZE+i];
  159487. qtblptr->quantval[j*DCTSIZE+i] = qtemp;
  159488. }
  159489. }
  159490. }
  159491. }
  159492. }
  159493. LOCAL(void)
  159494. trim_right_edge (j_compress_ptr dstinfo)
  159495. {
  159496. int ci, max_h_samp_factor;
  159497. JDIMENSION MCU_cols;
  159498. max_h_samp_factor = 1;
  159499. for (ci = 0; ci < dstinfo->num_components; ci++) {
  159500. int h_samp_factor = dstinfo->comp_info[ci].h_samp_factor;
  159501. max_h_samp_factor = MAX(max_h_samp_factor, h_samp_factor);
  159502. }
  159503. MCU_cols = dstinfo->image_width / (max_h_samp_factor * DCTSIZE);
  159504. if (MCU_cols > 0) /* can't trim to 0 pixels */
  159505. dstinfo->image_width = MCU_cols * (max_h_samp_factor * DCTSIZE);
  159506. }
  159507. LOCAL(void)
  159508. trim_bottom_edge (j_compress_ptr dstinfo)
  159509. {
  159510. int ci, max_v_samp_factor;
  159511. JDIMENSION MCU_rows;
  159512. max_v_samp_factor = 1;
  159513. for (ci = 0; ci < dstinfo->num_components; ci++) {
  159514. int v_samp_factor = dstinfo->comp_info[ci].v_samp_factor;
  159515. max_v_samp_factor = MAX(max_v_samp_factor, v_samp_factor);
  159516. }
  159517. MCU_rows = dstinfo->image_height / (max_v_samp_factor * DCTSIZE);
  159518. if (MCU_rows > 0) /* can't trim to 0 pixels */
  159519. dstinfo->image_height = MCU_rows * (max_v_samp_factor * DCTSIZE);
  159520. }
  159521. GLOBAL(jvirt_barray_ptr *)
  159522. jtransform_adjust_parameters (j_decompress_ptr srcinfo,
  159523. j_compress_ptr dstinfo,
  159524. jvirt_barray_ptr *src_coef_arrays,
  159525. jpeg_transform_info *info)
  159526. {
  159527. if (info->force_grayscale) {
  159528. if ((dstinfo->jpeg_color_space == JCS_YCbCr &&
  159529. dstinfo->num_components == 3) ||
  159530. (dstinfo->jpeg_color_space == JCS_GRAYSCALE &&
  159531. dstinfo->num_components == 1)) {
  159532. int sv_quant_tbl_no = dstinfo->comp_info[0].quant_tbl_no;
  159533. jpeg_set_colorspace(dstinfo, JCS_GRAYSCALE);
  159534. dstinfo->comp_info[0].quant_tbl_no = sv_quant_tbl_no;
  159535. } else {
  159536. ERREXIT(dstinfo, JERR_CONVERSION_NOTIMPL);
  159537. }
  159538. }
  159539. switch (info->transform) {
  159540. case JXFORM_NONE:
  159541. break;
  159542. case JXFORM_FLIP_H:
  159543. if (info->trim)
  159544. trim_right_edge(dstinfo);
  159545. break;
  159546. case JXFORM_FLIP_V:
  159547. if (info->trim)
  159548. trim_bottom_edge(dstinfo);
  159549. break;
  159550. case JXFORM_TRANSPOSE:
  159551. transpose_critical_parameters(dstinfo);
  159552. break;
  159553. case JXFORM_TRANSVERSE:
  159554. transpose_critical_parameters(dstinfo);
  159555. if (info->trim) {
  159556. trim_right_edge(dstinfo);
  159557. trim_bottom_edge(dstinfo);
  159558. }
  159559. break;
  159560. case JXFORM_ROT_90:
  159561. transpose_critical_parameters(dstinfo);
  159562. if (info->trim)
  159563. trim_right_edge(dstinfo);
  159564. break;
  159565. case JXFORM_ROT_180:
  159566. if (info->trim) {
  159567. trim_right_edge(dstinfo);
  159568. trim_bottom_edge(dstinfo);
  159569. }
  159570. break;
  159571. case JXFORM_ROT_270:
  159572. transpose_critical_parameters(dstinfo);
  159573. if (info->trim)
  159574. trim_bottom_edge(dstinfo);
  159575. break;
  159576. }
  159577. if (info->workspace_coef_arrays != NULL)
  159578. return info->workspace_coef_arrays;
  159579. return src_coef_arrays;
  159580. }
  159581. GLOBAL(void)
  159582. jtransform_execute_transformation (j_decompress_ptr srcinfo,
  159583. j_compress_ptr dstinfo,
  159584. jvirt_barray_ptr *src_coef_arrays,
  159585. jpeg_transform_info *info)
  159586. {
  159587. jvirt_barray_ptr *dst_coef_arrays = info->workspace_coef_arrays;
  159588. switch (info->transform) {
  159589. case JXFORM_NONE:
  159590. break;
  159591. case JXFORM_FLIP_H:
  159592. do_flip_h(srcinfo, dstinfo, src_coef_arrays);
  159593. break;
  159594. case JXFORM_FLIP_V:
  159595. do_flip_v(srcinfo, dstinfo, src_coef_arrays, dst_coef_arrays);
  159596. break;
  159597. case JXFORM_TRANSPOSE:
  159598. do_transpose(srcinfo, dstinfo, src_coef_arrays, dst_coef_arrays);
  159599. break;
  159600. case JXFORM_TRANSVERSE:
  159601. do_transverse(srcinfo, dstinfo, src_coef_arrays, dst_coef_arrays);
  159602. break;
  159603. case JXFORM_ROT_90:
  159604. do_rot_90(srcinfo, dstinfo, src_coef_arrays, dst_coef_arrays);
  159605. break;
  159606. case JXFORM_ROT_180:
  159607. do_rot_180(srcinfo, dstinfo, src_coef_arrays, dst_coef_arrays);
  159608. break;
  159609. case JXFORM_ROT_270:
  159610. do_rot_270(srcinfo, dstinfo, src_coef_arrays, dst_coef_arrays);
  159611. break;
  159612. }
  159613. }
  159614. #endif /* TRANSFORMS_SUPPORTED */
  159615. GLOBAL(void)
  159616. jcopy_markers_setup (j_decompress_ptr srcinfo, JCOPY_OPTION option)
  159617. {
  159618. #ifdef SAVE_MARKERS_SUPPORTED
  159619. int m;
  159620. if (option != JCOPYOPT_NONE) {
  159621. jpeg_save_markers(srcinfo, JPEG_COM, 0xFFFF);
  159622. }
  159623. if (option == JCOPYOPT_ALL) {
  159624. for (m = 0; m < 16; m++)
  159625. jpeg_save_markers(srcinfo, JPEG_APP0 + m, 0xFFFF);
  159626. }
  159627. #endif /* SAVE_MARKERS_SUPPORTED */
  159628. }
  159629. GLOBAL(void)
  159630. jcopy_markers_execute (j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
  159631. JCOPY_OPTION option)
  159632. {
  159633. jpeg_saved_marker_ptr marker;
  159634. for (marker = srcinfo->marker_list; marker != NULL; marker = marker->next) {
  159635. if (dstinfo->write_JFIF_header &&
  159636. marker->marker == JPEG_APP0 &&
  159637. marker->data_length >= 5 &&
  159638. GETJOCTET(marker->data[0]) == 0x4A &&
  159639. GETJOCTET(marker->data[1]) == 0x46 &&
  159640. GETJOCTET(marker->data[2]) == 0x49 &&
  159641. GETJOCTET(marker->data[3]) == 0x46 &&
  159642. GETJOCTET(marker->data[4]) == 0)
  159643. continue; /* reject duplicate JFIF */
  159644. if (dstinfo->write_Adobe_marker &&
  159645. marker->marker == JPEG_APP0+14 &&
  159646. marker->data_length >= 5 &&
  159647. GETJOCTET(marker->data[0]) == 0x41 &&
  159648. GETJOCTET(marker->data[1]) == 0x64 &&
  159649. GETJOCTET(marker->data[2]) == 0x6F &&
  159650. GETJOCTET(marker->data[3]) == 0x62 &&
  159651. GETJOCTET(marker->data[4]) == 0x65)
  159652. continue; /* reject duplicate Adobe */
  159653. #ifdef NEED_FAR_POINTERS
  159654. {
  159655. unsigned int i;
  159656. jpeg_write_m_header(dstinfo, marker->marker, marker->data_length);
  159657. for (i = 0; i < marker->data_length; i++)
  159658. jpeg_write_m_byte(dstinfo, marker->data[i]);
  159659. }
  159660. #else
  159661. jpeg_write_marker(dstinfo, marker->marker,
  159662. marker->data, marker->data_length);
  159663. #endif
  159664. }
  159665. }
  159666. /********* End of inlined file: transupp.c *********/
  159667. }
  159668. #else
  159669. #define JPEG_INTERNALS
  159670. #undef FAR
  159671. #include <jpeglib.h>
  159672. #endif
  159673. }
  159674. #if JUCE_MSVC
  159675. #pragma warning (pop)
  159676. #endif
  159677. BEGIN_JUCE_NAMESPACE
  159678. using namespace jpeglibNamespace;
  159679. #if ! JUCE_MSVC
  159680. using jpeglibNamespace::boolean;
  159681. #endif
  159682. struct JPEGDecodingFailure {};
  159683. static void fatalErrorHandler (j_common_ptr)
  159684. {
  159685. throw JPEGDecodingFailure();
  159686. }
  159687. static void silentErrorCallback1 (j_common_ptr) {}
  159688. static void silentErrorCallback2 (j_common_ptr, int) {}
  159689. static void silentErrorCallback3 (j_common_ptr, char*) {}
  159690. static void setupSilentErrorHandler (struct jpeg_error_mgr& err)
  159691. {
  159692. zerostruct (err);
  159693. err.error_exit = fatalErrorHandler;
  159694. err.emit_message = silentErrorCallback2;
  159695. err.output_message = silentErrorCallback1;
  159696. err.format_message = silentErrorCallback3;
  159697. err.reset_error_mgr = silentErrorCallback1;
  159698. }
  159699. static void dummyCallback1 (j_decompress_ptr)
  159700. {
  159701. }
  159702. static void jpegSkip (j_decompress_ptr decompStruct, long num)
  159703. {
  159704. decompStruct->src->next_input_byte += num;
  159705. num = jmin (num, (long) decompStruct->src->bytes_in_buffer);
  159706. decompStruct->src->bytes_in_buffer -= num;
  159707. }
  159708. static boolean jpegFill (j_decompress_ptr)
  159709. {
  159710. return 0;
  159711. }
  159712. Image* juce_loadJPEGImageFromStream (InputStream& in)
  159713. {
  159714. MemoryBlock mb;
  159715. in.readIntoMemoryBlock (mb);
  159716. Image* image = 0;
  159717. if (mb.getSize() > 16)
  159718. {
  159719. struct jpeg_decompress_struct jpegDecompStruct;
  159720. struct jpeg_error_mgr jerr;
  159721. setupSilentErrorHandler (jerr);
  159722. jpegDecompStruct.err = &jerr;
  159723. jpeg_create_decompress (&jpegDecompStruct);
  159724. jpegDecompStruct.src = (jpeg_source_mgr*)(jpegDecompStruct.mem->alloc_small)
  159725. ((j_common_ptr)(&jpegDecompStruct), JPOOL_PERMANENT, sizeof (jpeg_source_mgr));
  159726. jpegDecompStruct.src->init_source = dummyCallback1;
  159727. jpegDecompStruct.src->fill_input_buffer = jpegFill;
  159728. jpegDecompStruct.src->skip_input_data = jpegSkip;
  159729. jpegDecompStruct.src->resync_to_restart = jpeg_resync_to_restart;
  159730. jpegDecompStruct.src->term_source = dummyCallback1;
  159731. jpegDecompStruct.src->next_input_byte = (const unsigned char*) mb.getData();
  159732. jpegDecompStruct.src->bytes_in_buffer = mb.getSize();
  159733. try
  159734. {
  159735. jpeg_read_header (&jpegDecompStruct, TRUE);
  159736. jpeg_calc_output_dimensions (&jpegDecompStruct);
  159737. const int width = jpegDecompStruct.output_width;
  159738. const int height = jpegDecompStruct.output_height;
  159739. jpegDecompStruct.out_color_space = JCS_RGB;
  159740. JSAMPARRAY buffer
  159741. = (*jpegDecompStruct.mem->alloc_sarray) ((j_common_ptr) &jpegDecompStruct,
  159742. JPOOL_IMAGE,
  159743. width * 3, 1);
  159744. if (jpeg_start_decompress (&jpegDecompStruct))
  159745. {
  159746. image = Image::createNativeImage (Image::RGB, width, height, false);
  159747. const bool hasAlphaChan = image->hasAlphaChannel();
  159748. const Image::BitmapData destData (*image, 0, 0, width, height, true);
  159749. for (int y = 0; y < height; ++y)
  159750. {
  159751. jpeg_read_scanlines (&jpegDecompStruct, buffer, 1);
  159752. const uint8* src = *buffer;
  159753. uint8* dest = destData.getLinePointer (y);
  159754. if (hasAlphaChan)
  159755. {
  159756. for (int i = width; --i >= 0;)
  159757. {
  159758. ((PixelARGB*) dest)->setARGB (0xff, src[0], src[1], src[2]);
  159759. ((PixelARGB*) dest)->premultiply();
  159760. dest += destData.pixelStride;
  159761. src += 3;
  159762. }
  159763. }
  159764. else
  159765. {
  159766. for (int i = width; --i >= 0;)
  159767. {
  159768. ((PixelRGB*) dest)->setARGB (0xff, src[0], src[1], src[2]);
  159769. dest += destData.pixelStride;
  159770. src += 3;
  159771. }
  159772. }
  159773. }
  159774. jpeg_finish_decompress (&jpegDecompStruct);
  159775. in.setPosition (((char*) jpegDecompStruct.src->next_input_byte) - (char*) mb.getData());
  159776. }
  159777. jpeg_destroy_decompress (&jpegDecompStruct);
  159778. }
  159779. catch (...)
  159780. {}
  159781. }
  159782. return image;
  159783. }
  159784. static const int jpegBufferSize = 512;
  159785. struct JuceJpegDest : public jpeg_destination_mgr
  159786. {
  159787. OutputStream* output;
  159788. char* buffer;
  159789. };
  159790. static void jpegWriteInit (j_compress_ptr)
  159791. {
  159792. }
  159793. static void jpegWriteTerminate (j_compress_ptr cinfo)
  159794. {
  159795. JuceJpegDest* const dest = (JuceJpegDest*) cinfo->dest;
  159796. const size_t numToWrite = jpegBufferSize - dest->free_in_buffer;
  159797. dest->output->write (dest->buffer, (int) numToWrite);
  159798. }
  159799. static boolean jpegWriteFlush (j_compress_ptr cinfo)
  159800. {
  159801. JuceJpegDest* const dest = (JuceJpegDest*) cinfo->dest;
  159802. const int numToWrite = jpegBufferSize;
  159803. dest->next_output_byte = (JOCTET*) dest->buffer;
  159804. dest->free_in_buffer = jpegBufferSize;
  159805. return dest->output->write (dest->buffer, numToWrite);
  159806. }
  159807. bool juce_writeJPEGImageToStream (const Image& image,
  159808. OutputStream& out,
  159809. float quality)
  159810. {
  159811. if (image.hasAlphaChannel())
  159812. {
  159813. // this method could fill the background in white and still save the image..
  159814. jassertfalse
  159815. return true;
  159816. }
  159817. struct jpeg_compress_struct jpegCompStruct;
  159818. struct jpeg_error_mgr jerr;
  159819. setupSilentErrorHandler (jerr);
  159820. jpegCompStruct.err = &jerr;
  159821. jpeg_create_compress (&jpegCompStruct);
  159822. JuceJpegDest dest;
  159823. jpegCompStruct.dest = &dest;
  159824. dest.output = &out;
  159825. HeapBlock <char> tempBuffer (jpegBufferSize);
  159826. dest.buffer = (char*) tempBuffer;
  159827. dest.next_output_byte = (JOCTET*) dest.buffer;
  159828. dest.free_in_buffer = jpegBufferSize;
  159829. dest.init_destination = jpegWriteInit;
  159830. dest.empty_output_buffer = jpegWriteFlush;
  159831. dest.term_destination = jpegWriteTerminate;
  159832. jpegCompStruct.image_width = image.getWidth();
  159833. jpegCompStruct.image_height = image.getHeight();
  159834. jpegCompStruct.input_components = 3;
  159835. jpegCompStruct.in_color_space = JCS_RGB;
  159836. jpegCompStruct.write_JFIF_header = 1;
  159837. jpegCompStruct.X_density = 72;
  159838. jpegCompStruct.Y_density = 72;
  159839. jpeg_set_defaults (&jpegCompStruct);
  159840. jpegCompStruct.dct_method = JDCT_FLOAT;
  159841. jpegCompStruct.optimize_coding = 1;
  159842. // jpegCompStruct.smoothing_factor = 10;
  159843. if (quality < 0.0f)
  159844. quality = 0.85f;
  159845. jpeg_set_quality (&jpegCompStruct, jlimit (0, 100, roundToInt (quality * 100.0f)), TRUE);
  159846. jpeg_start_compress (&jpegCompStruct, TRUE);
  159847. const int strideBytes = jpegCompStruct.image_width * jpegCompStruct.input_components;
  159848. JSAMPARRAY buffer = (*jpegCompStruct.mem->alloc_sarray) ((j_common_ptr) &jpegCompStruct,
  159849. JPOOL_IMAGE,
  159850. strideBytes, 1);
  159851. const Image::BitmapData srcData (image, 0, 0, jpegCompStruct.image_width, jpegCompStruct.image_height);
  159852. while (jpegCompStruct.next_scanline < jpegCompStruct.image_height)
  159853. {
  159854. const uint8* src = srcData.getLinePointer (jpegCompStruct.next_scanline);
  159855. uint8* dst = *buffer;
  159856. for (int i = jpegCompStruct.image_width; --i >= 0;)
  159857. {
  159858. *dst++ = ((const PixelRGB*) src)->getRed();
  159859. *dst++ = ((const PixelRGB*) src)->getGreen();
  159860. *dst++ = ((const PixelRGB*) src)->getBlue();
  159861. src += srcData.pixelStride;
  159862. }
  159863. jpeg_write_scanlines (&jpegCompStruct, buffer, 1);
  159864. }
  159865. jpeg_finish_compress (&jpegCompStruct);
  159866. jpeg_destroy_compress (&jpegCompStruct);
  159867. out.flush();
  159868. return true;
  159869. }
  159870. END_JUCE_NAMESPACE
  159871. /********* End of inlined file: juce_JPEGLoader.cpp *********/
  159872. /********* Start of inlined file: juce_PNGLoader.cpp *********/
  159873. #ifdef _MSC_VER
  159874. #pragma warning (push)
  159875. #pragma warning (disable: 4390 4611)
  159876. #endif
  159877. namespace zlibNamespace
  159878. {
  159879. #if JUCE_INCLUDE_ZLIB_CODE
  159880. #undef OS_CODE
  159881. #undef fdopen
  159882. #undef OS_CODE
  159883. #else
  159884. #include <zlib.h>
  159885. #endif
  159886. }
  159887. namespace pnglibNamespace
  159888. {
  159889. using namespace zlibNamespace;
  159890. #if JUCE_INCLUDE_PNGLIB_CODE
  159891. #if _MSC_VER != 1310
  159892. using ::calloc; // (causes conflict in VS.NET 2003)
  159893. using ::malloc;
  159894. using ::free;
  159895. #endif
  159896. extern "C"
  159897. {
  159898. using ::abs;
  159899. #define PNG_INTERNAL
  159900. #define NO_DUMMY_DECL
  159901. #define PNG_SETJMP_NOT_SUPPORTED
  159902. /********* Start of inlined file: png.h *********/
  159903. #ifndef PNG_H
  159904. #define PNG_H
  159905. #define PNG_LIBPNG_VER_STRING "1.2.21"
  159906. #define PNG_HEADER_VERSION_STRING \
  159907. " libpng version 1.2.21 - October 4, 2007\n"
  159908. #define PNG_LIBPNG_VER_SONUM 0
  159909. #define PNG_LIBPNG_VER_DLLNUM 13
  159910. #define PNG_LIBPNG_VER_MAJOR 1
  159911. #define PNG_LIBPNG_VER_MINOR 2
  159912. #define PNG_LIBPNG_VER_RELEASE 21
  159913. #define PNG_LIBPNG_VER_BUILD 0
  159914. #define PNG_LIBPNG_BUILD_ALPHA 1
  159915. #define PNG_LIBPNG_BUILD_BETA 2
  159916. #define PNG_LIBPNG_BUILD_RC 3
  159917. #define PNG_LIBPNG_BUILD_STABLE 4
  159918. #define PNG_LIBPNG_BUILD_RELEASE_STATUS_MASK 7
  159919. #define PNG_LIBPNG_BUILD_PATCH 8 /* Can be OR'ed with
  159920. PNG_LIBPNG_BUILD_STABLE only */
  159921. #define PNG_LIBPNG_BUILD_PRIVATE 16 /* Cannot be OR'ed with
  159922. PNG_LIBPNG_BUILD_SPECIAL */
  159923. #define PNG_LIBPNG_BUILD_SPECIAL 32 /* Cannot be OR'ed with
  159924. PNG_LIBPNG_BUILD_PRIVATE */
  159925. #define PNG_LIBPNG_BUILD_BASE_TYPE PNG_LIBPNG_BUILD_STABLE
  159926. #define PNG_LIBPNG_VER 10221 /* 1.2.21 */
  159927. #ifndef PNG_VERSION_INFO_ONLY
  159928. #endif
  159929. /********* Start of inlined file: pngconf.h *********/
  159930. #ifndef PNGCONF_H
  159931. #define PNGCONF_H
  159932. #define PNG_1_2_X
  159933. // These are some Juce config settings that should remove any unnecessary code bloat..
  159934. #define PNG_NO_STDIO 1
  159935. #define PNG_DEBUG 0
  159936. #define PNG_NO_WARNINGS 1
  159937. #define PNG_NO_ERROR_TEXT 1
  159938. #define PNG_NO_ERROR_NUMBERS 1
  159939. #define PNG_NO_USER_MEM 1
  159940. #define PNG_NO_READ_iCCP 1
  159941. #define PNG_NO_READ_UNKNOWN_CHUNKS 1
  159942. #define PNG_NO_READ_USER_CHUNKS 1
  159943. #define PNG_NO_READ_iTXt 1
  159944. #define PNG_NO_READ_sCAL 1
  159945. #define PNG_NO_READ_sPLT 1
  159946. #define png_error(a, b) png_err(a)
  159947. #define png_warning(a, b)
  159948. #define png_chunk_error(a, b) png_err(a)
  159949. #define png_chunk_warning(a, b)
  159950. #ifdef PNG_USER_CONFIG
  159951. # ifndef PNG_USER_PRIVATEBUILD
  159952. # define PNG_USER_PRIVATEBUILD
  159953. # endif
  159954. #include "pngusr.h"
  159955. #endif
  159956. #ifdef PNG_CONFIGURE_LIBPNG
  159957. #ifdef HAVE_CONFIG_H
  159958. #include "config.h"
  159959. #endif
  159960. #endif
  159961. #ifdef __STDC__
  159962. #ifdef SPECIALBUILD
  159963. # pragma message("PNG_LIBPNG_SPECIALBUILD (and deprecated SPECIALBUILD)\
  159964. are now LIBPNG reserved macros. Use PNG_USER_PRIVATEBUILD instead.")
  159965. #endif
  159966. #ifdef PRIVATEBUILD
  159967. # pragma message("PRIVATEBUILD is deprecated.\
  159968. Use PNG_USER_PRIVATEBUILD instead.")
  159969. # define PNG_USER_PRIVATEBUILD PRIVATEBUILD
  159970. #endif
  159971. #endif /* __STDC__ */
  159972. #ifndef PNG_VERSION_INFO_ONLY
  159973. # define PNG_WARN_UNINITIALIZED_ROW 1
  159974. #ifndef PNG_ZBUF_SIZE
  159975. # define PNG_ZBUF_SIZE 8192
  159976. #endif
  159977. #ifndef PNG_NO_READ_SUPPORTED
  159978. # define PNG_READ_SUPPORTED
  159979. #endif
  159980. #ifndef PNG_NO_WRITE_SUPPORTED
  159981. # define PNG_WRITE_SUPPORTED
  159982. #endif
  159983. #if !defined(PNG_1_0_X) && !defined(PNG_NO_MNG_FEATURES)
  159984. # ifndef PNG_MNG_FEATURES_SUPPORTED
  159985. # define PNG_MNG_FEATURES_SUPPORTED
  159986. # endif
  159987. #endif
  159988. #ifndef PNG_NO_FLOATING_POINT_SUPPORTED
  159989. # ifndef PNG_FLOATING_POINT_SUPPORTED
  159990. # define PNG_FLOATING_POINT_SUPPORTED
  159991. # endif
  159992. #endif
  159993. #if defined(MAXSEG_64K) && !defined(PNG_MAX_MALLOC_64K)
  159994. # define PNG_MAX_MALLOC_64K
  159995. #endif
  159996. #if defined(__CYGWIN__)
  159997. # if defined(ALL_STATIC)
  159998. # if defined(PNG_BUILD_DLL)
  159999. # undef PNG_BUILD_DLL
  160000. # endif
  160001. # if defined(PNG_USE_DLL)
  160002. # undef PNG_USE_DLL
  160003. # endif
  160004. # if defined(PNG_DLL)
  160005. # undef PNG_DLL
  160006. # endif
  160007. # if !defined(PNG_STATIC)
  160008. # define PNG_STATIC
  160009. # endif
  160010. # else
  160011. # if defined (PNG_BUILD_DLL)
  160012. # if defined(PNG_STATIC)
  160013. # undef PNG_STATIC
  160014. # endif
  160015. # if defined(PNG_USE_DLL)
  160016. # undef PNG_USE_DLL
  160017. # endif
  160018. # if !defined(PNG_DLL)
  160019. # define PNG_DLL
  160020. # endif
  160021. # else
  160022. # if defined(PNG_STATIC)
  160023. # if defined(PNG_USE_DLL)
  160024. # undef PNG_USE_DLL
  160025. # endif
  160026. # if defined(PNG_DLL)
  160027. # undef PNG_DLL
  160028. # endif
  160029. # else
  160030. # if !defined(PNG_USE_DLL)
  160031. # define PNG_USE_DLL
  160032. # endif
  160033. # if !defined(PNG_DLL)
  160034. # define PNG_DLL
  160035. # endif
  160036. # endif
  160037. # endif
  160038. # endif
  160039. #endif
  160040. #if defined(_WIN32_WCE)
  160041. # include <windows.h>
  160042. # define PNG_NO_CONSOLE_IO
  160043. # ifdef PNG_DEBUG
  160044. # undef PNG_DEBUG
  160045. # endif
  160046. #endif
  160047. #ifdef PNG_BUILD_DLL
  160048. # ifndef PNG_CONSOLE_IO_SUPPORTED
  160049. # ifndef PNG_NO_CONSOLE_IO
  160050. # define PNG_NO_CONSOLE_IO
  160051. # endif
  160052. # endif
  160053. #endif
  160054. # ifdef PNG_NO_STDIO
  160055. # ifndef PNG_NO_CONSOLE_IO
  160056. # define PNG_NO_CONSOLE_IO
  160057. # endif
  160058. # ifdef PNG_DEBUG
  160059. # if (PNG_DEBUG > 0)
  160060. # include <stdio.h>
  160061. # endif
  160062. # endif
  160063. # else
  160064. # if !defined(_WIN32_WCE)
  160065. # include <stdio.h>
  160066. # endif
  160067. # endif
  160068. #ifndef PNGARG
  160069. #ifdef OF /* zlib prototype munger */
  160070. # define PNGARG(arglist) OF(arglist)
  160071. #else
  160072. #ifdef _NO_PROTO
  160073. # define PNGARG(arglist) ()
  160074. # ifndef PNG_TYPECAST_NULL
  160075. # define PNG_TYPECAST_NULL
  160076. # endif
  160077. #else
  160078. # define PNGARG(arglist) arglist
  160079. #endif /* _NO_PROTO */
  160080. #endif /* OF */
  160081. #endif /* PNGARG */
  160082. #ifndef MACOS
  160083. # if (defined(__MWERKS__) && defined(macintosh)) || defined(applec) || \
  160084. defined(THINK_C) || defined(__SC__) || defined(TARGET_OS_MAC)
  160085. # define MACOS
  160086. # endif
  160087. #endif
  160088. #if !defined(MACOS) && !defined(RISCOS) && !defined(_WIN32_WCE)
  160089. # include <sys/types.h>
  160090. #endif
  160091. #if !defined(PNG_SETJMP_NOT_SUPPORTED) && !defined(PNG_NO_SETJMP_SUPPORTED)
  160092. # define PNG_SETJMP_SUPPORTED
  160093. #endif
  160094. #ifdef PNG_SETJMP_SUPPORTED
  160095. # ifdef __linux__
  160096. # ifdef _BSD_SOURCE
  160097. # define PNG_SAVE_BSD_SOURCE
  160098. # undef _BSD_SOURCE
  160099. # endif
  160100. # ifdef _SETJMP_H
  160101. __png.h__ already includes setjmp.h;
  160102. __dont__ include it again.;
  160103. # endif
  160104. # endif /* __linux__ */
  160105. # include <setjmp.h>
  160106. # ifdef __linux__
  160107. # ifdef PNG_SAVE_BSD_SOURCE
  160108. # define _BSD_SOURCE
  160109. # undef PNG_SAVE_BSD_SOURCE
  160110. # endif
  160111. # endif /* __linux__ */
  160112. #endif /* PNG_SETJMP_SUPPORTED */
  160113. #ifdef BSD
  160114. #if ! JUCE_MAC
  160115. # include <strings.h>
  160116. #endif
  160117. #else
  160118. # include <string.h>
  160119. #endif
  160120. #ifdef PNG_INTERNAL
  160121. #include <stdlib.h>
  160122. #define PNG_EXTERN
  160123. #if defined(PNG_FLOATING_POINT_SUPPORTED)
  160124. # if defined(MACOS)
  160125. # if !defined(__MATH_H__) && !defined(__MATH_H) && !defined(__cmath__)
  160126. # include <fp.h>
  160127. # endif
  160128. # else
  160129. # include <math.h>
  160130. # endif
  160131. # if defined(_AMIGA) && defined(__SASC) && defined(_M68881)
  160132. # include <m68881.h>
  160133. # endif
  160134. #endif
  160135. #if (defined(__MWERKS__) && defined(WIN32)) || defined(__STDC__)
  160136. # define PNG_ALWAYS_EXTERN
  160137. #endif
  160138. #if defined(__TURBOC__) && defined(__MSDOS__)
  160139. # include <mem.h>
  160140. # include <alloc.h>
  160141. #endif
  160142. #if defined(_MSC_VER) && (defined(WIN32) || defined(_Windows) || \
  160143. defined(_WINDOWS) || defined(_WIN32) || defined(__WIN32__))
  160144. # include <malloc.h>
  160145. #endif
  160146. #ifndef PNG_DITHER_RED_BITS
  160147. # define PNG_DITHER_RED_BITS 5
  160148. #endif
  160149. #ifndef PNG_DITHER_GREEN_BITS
  160150. # define PNG_DITHER_GREEN_BITS 5
  160151. #endif
  160152. #ifndef PNG_DITHER_BLUE_BITS
  160153. # define PNG_DITHER_BLUE_BITS 5
  160154. #endif
  160155. #ifndef PNG_MAX_GAMMA_8
  160156. # define PNG_MAX_GAMMA_8 11
  160157. #endif
  160158. #ifndef PNG_GAMMA_THRESHOLD
  160159. # define PNG_GAMMA_THRESHOLD 0.05
  160160. #endif
  160161. #endif /* PNG_INTERNAL */
  160162. #ifndef PNG_NO_CONST
  160163. # define PNG_CONST const
  160164. #else
  160165. # define PNG_CONST
  160166. #endif
  160167. #if defined(PNG_1_0_X) || defined (PNG_1_2_X)
  160168. # ifndef PNG_NO_iTXt_SUPPORTED
  160169. # define PNG_NO_iTXt_SUPPORTED
  160170. # endif
  160171. # ifndef PNG_NO_READ_iTXt
  160172. # define PNG_NO_READ_iTXt
  160173. # endif
  160174. # ifndef PNG_NO_WRITE_iTXt
  160175. # define PNG_NO_WRITE_iTXt
  160176. # endif
  160177. #endif
  160178. #if !defined(PNG_NO_iTXt_SUPPORTED)
  160179. # if !defined(PNG_READ_iTXt_SUPPORTED) && !defined(PNG_NO_READ_iTXt)
  160180. # define PNG_READ_iTXt
  160181. # endif
  160182. # if !defined(PNG_WRITE_iTXt_SUPPORTED) && !defined(PNG_NO_WRITE_iTXt)
  160183. # define PNG_WRITE_iTXt
  160184. # endif
  160185. #endif
  160186. #ifdef PNG_LEGACY_SUPPORTED
  160187. # define PNG_NO_FREE_ME
  160188. # define PNG_NO_READ_UNKNOWN_CHUNKS
  160189. # define PNG_NO_WRITE_UNKNOWN_CHUNKS
  160190. # define PNG_NO_READ_USER_CHUNKS
  160191. # define PNG_NO_READ_iCCP
  160192. # define PNG_NO_WRITE_iCCP
  160193. # define PNG_NO_READ_iTXt
  160194. # define PNG_NO_WRITE_iTXt
  160195. # define PNG_NO_READ_sCAL
  160196. # define PNG_NO_WRITE_sCAL
  160197. # define PNG_NO_READ_sPLT
  160198. # define PNG_NO_WRITE_sPLT
  160199. # define PNG_NO_INFO_IMAGE
  160200. # define PNG_NO_READ_RGB_TO_GRAY
  160201. # define PNG_NO_READ_USER_TRANSFORM
  160202. # define PNG_NO_WRITE_USER_TRANSFORM
  160203. # define PNG_NO_USER_MEM
  160204. # define PNG_NO_READ_EMPTY_PLTE
  160205. # define PNG_NO_MNG_FEATURES
  160206. # define PNG_NO_FIXED_POINT_SUPPORTED
  160207. #endif
  160208. #if !defined(PNG_FLOATING_POINT_SUPPORTED) || \
  160209. !defined(PNG_NO_FIXED_POINT_SUPPORTED)
  160210. # define PNG_FIXED_POINT_SUPPORTED
  160211. #endif
  160212. #ifndef PNG_NO_FREE_ME
  160213. # define PNG_FREE_ME_SUPPORTED
  160214. #endif
  160215. #if defined(PNG_READ_SUPPORTED)
  160216. #if !defined(PNG_READ_TRANSFORMS_NOT_SUPPORTED) && \
  160217. !defined(PNG_NO_READ_TRANSFORMS)
  160218. # define PNG_READ_TRANSFORMS_SUPPORTED
  160219. #endif
  160220. #ifdef PNG_READ_TRANSFORMS_SUPPORTED
  160221. # ifndef PNG_NO_READ_EXPAND
  160222. # define PNG_READ_EXPAND_SUPPORTED
  160223. # endif
  160224. # ifndef PNG_NO_READ_SHIFT
  160225. # define PNG_READ_SHIFT_SUPPORTED
  160226. # endif
  160227. # ifndef PNG_NO_READ_PACK
  160228. # define PNG_READ_PACK_SUPPORTED
  160229. # endif
  160230. # ifndef PNG_NO_READ_BGR
  160231. # define PNG_READ_BGR_SUPPORTED
  160232. # endif
  160233. # ifndef PNG_NO_READ_SWAP
  160234. # define PNG_READ_SWAP_SUPPORTED
  160235. # endif
  160236. # ifndef PNG_NO_READ_PACKSWAP
  160237. # define PNG_READ_PACKSWAP_SUPPORTED
  160238. # endif
  160239. # ifndef PNG_NO_READ_INVERT
  160240. # define PNG_READ_INVERT_SUPPORTED
  160241. # endif
  160242. # ifndef PNG_NO_READ_DITHER
  160243. # define PNG_READ_DITHER_SUPPORTED
  160244. # endif
  160245. # ifndef PNG_NO_READ_BACKGROUND
  160246. # define PNG_READ_BACKGROUND_SUPPORTED
  160247. # endif
  160248. # ifndef PNG_NO_READ_16_TO_8
  160249. # define PNG_READ_16_TO_8_SUPPORTED
  160250. # endif
  160251. # ifndef PNG_NO_READ_FILLER
  160252. # define PNG_READ_FILLER_SUPPORTED
  160253. # endif
  160254. # ifndef PNG_NO_READ_GAMMA
  160255. # define PNG_READ_GAMMA_SUPPORTED
  160256. # endif
  160257. # ifndef PNG_NO_READ_GRAY_TO_RGB
  160258. # define PNG_READ_GRAY_TO_RGB_SUPPORTED
  160259. # endif
  160260. # ifndef PNG_NO_READ_SWAP_ALPHA
  160261. # define PNG_READ_SWAP_ALPHA_SUPPORTED
  160262. # endif
  160263. # ifndef PNG_NO_READ_INVERT_ALPHA
  160264. # define PNG_READ_INVERT_ALPHA_SUPPORTED
  160265. # endif
  160266. # ifndef PNG_NO_READ_STRIP_ALPHA
  160267. # define PNG_READ_STRIP_ALPHA_SUPPORTED
  160268. # endif
  160269. # ifndef PNG_NO_READ_USER_TRANSFORM
  160270. # define PNG_READ_USER_TRANSFORM_SUPPORTED
  160271. # endif
  160272. # ifndef PNG_NO_READ_RGB_TO_GRAY
  160273. # define PNG_READ_RGB_TO_GRAY_SUPPORTED
  160274. # endif
  160275. #endif /* PNG_READ_TRANSFORMS_SUPPORTED */
  160276. #if !defined(PNG_NO_PROGRESSIVE_READ) && \
  160277. !defined(PNG_PROGRESSIVE_READ_SUPPORTED) /* if you don't do progressive */
  160278. # define PNG_PROGRESSIVE_READ_SUPPORTED /* reading. This is not talking */
  160279. #endif /* about interlacing capability! You'll */
  160280. #define PNG_READ_INTERLACING_SUPPORTED /* required in PNG-compliant decoders */
  160281. #ifndef PNG_NO_READ_COMPOSITE_NODIV
  160282. # ifndef PNG_NO_READ_COMPOSITED_NODIV /* libpng-1.0.x misspelling */
  160283. # define PNG_READ_COMPOSITE_NODIV_SUPPORTED /* well tested on Intel, SGI */
  160284. # endif
  160285. #endif
  160286. #if defined(PNG_1_0_X) || defined (PNG_1_2_X)
  160287. #ifndef PNG_NO_READ_EMPTY_PLTE
  160288. # define PNG_READ_EMPTY_PLTE_SUPPORTED
  160289. #endif
  160290. #endif
  160291. #endif /* PNG_READ_SUPPORTED */
  160292. #if defined(PNG_WRITE_SUPPORTED)
  160293. # if !defined(PNG_WRITE_TRANSFORMS_NOT_SUPPORTED) && \
  160294. !defined(PNG_NO_WRITE_TRANSFORMS)
  160295. # define PNG_WRITE_TRANSFORMS_SUPPORTED
  160296. #endif
  160297. #ifdef PNG_WRITE_TRANSFORMS_SUPPORTED
  160298. # ifndef PNG_NO_WRITE_SHIFT
  160299. # define PNG_WRITE_SHIFT_SUPPORTED
  160300. # endif
  160301. # ifndef PNG_NO_WRITE_PACK
  160302. # define PNG_WRITE_PACK_SUPPORTED
  160303. # endif
  160304. # ifndef PNG_NO_WRITE_BGR
  160305. # define PNG_WRITE_BGR_SUPPORTED
  160306. # endif
  160307. # ifndef PNG_NO_WRITE_SWAP
  160308. # define PNG_WRITE_SWAP_SUPPORTED
  160309. # endif
  160310. # ifndef PNG_NO_WRITE_PACKSWAP
  160311. # define PNG_WRITE_PACKSWAP_SUPPORTED
  160312. # endif
  160313. # ifndef PNG_NO_WRITE_INVERT
  160314. # define PNG_WRITE_INVERT_SUPPORTED
  160315. # endif
  160316. # ifndef PNG_NO_WRITE_FILLER
  160317. # define PNG_WRITE_FILLER_SUPPORTED /* same as WRITE_STRIP_ALPHA */
  160318. # endif
  160319. # ifndef PNG_NO_WRITE_SWAP_ALPHA
  160320. # define PNG_WRITE_SWAP_ALPHA_SUPPORTED
  160321. # endif
  160322. # ifndef PNG_NO_WRITE_INVERT_ALPHA
  160323. # define PNG_WRITE_INVERT_ALPHA_SUPPORTED
  160324. # endif
  160325. # ifndef PNG_NO_WRITE_USER_TRANSFORM
  160326. # define PNG_WRITE_USER_TRANSFORM_SUPPORTED
  160327. # endif
  160328. #endif /* PNG_WRITE_TRANSFORMS_SUPPORTED */
  160329. #if !defined(PNG_NO_WRITE_INTERLACING_SUPPORTED) && \
  160330. !defined(PNG_WRITE_INTERLACING_SUPPORTED)
  160331. #define PNG_WRITE_INTERLACING_SUPPORTED /* not required for PNG-compliant
  160332. encoders, but can cause trouble
  160333. if left undefined */
  160334. #endif
  160335. #if !defined(PNG_NO_WRITE_WEIGHTED_FILTER) && \
  160336. !defined(PNG_WRITE_WEIGHTED_FILTER) && \
  160337. defined(PNG_FLOATING_POINT_SUPPORTED)
  160338. # define PNG_WRITE_WEIGHTED_FILTER_SUPPORTED
  160339. #endif
  160340. #ifndef PNG_NO_WRITE_FLUSH
  160341. # define PNG_WRITE_FLUSH_SUPPORTED
  160342. #endif
  160343. #if defined(PNG_1_0_X) || defined (PNG_1_2_X)
  160344. #ifndef PNG_NO_WRITE_EMPTY_PLTE
  160345. # define PNG_WRITE_EMPTY_PLTE_SUPPORTED
  160346. #endif
  160347. #endif
  160348. #endif /* PNG_WRITE_SUPPORTED */
  160349. #ifndef PNG_1_0_X
  160350. # ifndef PNG_NO_ERROR_NUMBERS
  160351. # define PNG_ERROR_NUMBERS_SUPPORTED
  160352. # endif
  160353. #endif /* PNG_1_0_X */
  160354. #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \
  160355. defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED)
  160356. # ifndef PNG_NO_USER_TRANSFORM_PTR
  160357. # define PNG_USER_TRANSFORM_PTR_SUPPORTED
  160358. # endif
  160359. #endif
  160360. #ifndef PNG_NO_STDIO
  160361. # define PNG_TIME_RFC1123_SUPPORTED
  160362. #endif
  160363. #if !defined(PNG_NO_EASY_ACCESS) && !defined(PNG_EASY_ACCESS_SUPPORTED)
  160364. # define PNG_EASY_ACCESS_SUPPORTED
  160365. #endif
  160366. #if defined(PNG_READ_SUPPORTED) && !defined(PNG_NO_OPTIMIZED_CODE)
  160367. # ifndef PNG_OPTIMIZED_CODE_SUPPORTED
  160368. # define PNG_OPTIMIZED_CODE_SUPPORTED
  160369. # endif
  160370. #endif
  160371. #if defined(PNG_READ_SUPPORTED) && !defined(PNG_NO_ASSEMBLER_CODE)
  160372. # ifndef PNG_ASSEMBLER_CODE_SUPPORTED
  160373. # define PNG_ASSEMBLER_CODE_SUPPORTED
  160374. # endif
  160375. # if defined(__GNUC__) && defined(__x86_64__) && (__GNUC__ < 4)
  160376. # if !defined(PNG_MMX_CODE_SUPPORTED) && !defined(PNG_NO_MMX_CODE)
  160377. # define PNG_NO_MMX_CODE
  160378. # endif
  160379. # endif
  160380. # if defined(__APPLE__)
  160381. # if !defined(PNG_MMX_CODE_SUPPORTED) && !defined(PNG_NO_MMX_CODE)
  160382. # define PNG_NO_MMX_CODE
  160383. # endif
  160384. # endif
  160385. # if (defined(__MWERKS__) && ((__MWERKS__ < 0x0900) || macintosh))
  160386. # if !defined(PNG_MMX_CODE_SUPPORTED) && !defined(PNG_NO_MMX_CODE)
  160387. # define PNG_NO_MMX_CODE
  160388. # endif
  160389. # endif
  160390. # if !defined(PNG_MMX_CODE_SUPPORTED) && !defined(PNG_NO_MMX_CODE)
  160391. # define PNG_MMX_CODE_SUPPORTED
  160392. # endif
  160393. #endif
  160394. #if !defined(PNG_1_0_X)
  160395. #if !defined(PNG_NO_USER_MEM) && !defined(PNG_USER_MEM_SUPPORTED)
  160396. # define PNG_USER_MEM_SUPPORTED
  160397. #endif
  160398. #endif /* PNG_1_0_X */
  160399. #if !defined(PNG_1_0_X)
  160400. #ifndef PNG_SET_USER_LIMITS_SUPPORTED
  160401. #if !defined(PNG_NO_SET_USER_LIMITS) && !defined(PNG_SET_USER_LIMITS_SUPPORTED)
  160402. # define PNG_SET_USER_LIMITS_SUPPORTED
  160403. #endif
  160404. #endif
  160405. #endif /* PNG_1_0_X */
  160406. #ifndef PNG_USER_WIDTH_MAX
  160407. # define PNG_USER_WIDTH_MAX 1000000L
  160408. #endif
  160409. #ifndef PNG_USER_HEIGHT_MAX
  160410. # define PNG_USER_HEIGHT_MAX 1000000L
  160411. #endif
  160412. #if defined(PNG_READ_SUPPORTED) && \
  160413. !defined(PNG_READ_ANCILLARY_CHUNKS_NOT_SUPPORTED) && \
  160414. !defined(PNG_NO_READ_ANCILLARY_CHUNKS)
  160415. # define PNG_READ_ANCILLARY_CHUNKS_SUPPORTED
  160416. #endif
  160417. #if defined(PNG_WRITE_SUPPORTED) && \
  160418. !defined(PNG_WRITE_ANCILLARY_CHUNKS_NOT_SUPPORTED) && \
  160419. !defined(PNG_NO_WRITE_ANCILLARY_CHUNKS)
  160420. # define PNG_WRITE_ANCILLARY_CHUNKS_SUPPORTED
  160421. #endif
  160422. #ifdef PNG_READ_ANCILLARY_CHUNKS_SUPPORTED
  160423. #ifdef PNG_NO_READ_TEXT
  160424. # define PNG_NO_READ_iTXt
  160425. # define PNG_NO_READ_tEXt
  160426. # define PNG_NO_READ_zTXt
  160427. #endif
  160428. #ifndef PNG_NO_READ_bKGD
  160429. # define PNG_READ_bKGD_SUPPORTED
  160430. # define PNG_bKGD_SUPPORTED
  160431. #endif
  160432. #ifndef PNG_NO_READ_cHRM
  160433. # define PNG_READ_cHRM_SUPPORTED
  160434. # define PNG_cHRM_SUPPORTED
  160435. #endif
  160436. #ifndef PNG_NO_READ_gAMA
  160437. # define PNG_READ_gAMA_SUPPORTED
  160438. # define PNG_gAMA_SUPPORTED
  160439. #endif
  160440. #ifndef PNG_NO_READ_hIST
  160441. # define PNG_READ_hIST_SUPPORTED
  160442. # define PNG_hIST_SUPPORTED
  160443. #endif
  160444. #ifndef PNG_NO_READ_iCCP
  160445. # define PNG_READ_iCCP_SUPPORTED
  160446. # define PNG_iCCP_SUPPORTED
  160447. #endif
  160448. #ifndef PNG_NO_READ_iTXt
  160449. # ifndef PNG_READ_iTXt_SUPPORTED
  160450. # define PNG_READ_iTXt_SUPPORTED
  160451. # endif
  160452. # ifndef PNG_iTXt_SUPPORTED
  160453. # define PNG_iTXt_SUPPORTED
  160454. # endif
  160455. #endif
  160456. #ifndef PNG_NO_READ_oFFs
  160457. # define PNG_READ_oFFs_SUPPORTED
  160458. # define PNG_oFFs_SUPPORTED
  160459. #endif
  160460. #ifndef PNG_NO_READ_pCAL
  160461. # define PNG_READ_pCAL_SUPPORTED
  160462. # define PNG_pCAL_SUPPORTED
  160463. #endif
  160464. #ifndef PNG_NO_READ_sCAL
  160465. # define PNG_READ_sCAL_SUPPORTED
  160466. # define PNG_sCAL_SUPPORTED
  160467. #endif
  160468. #ifndef PNG_NO_READ_pHYs
  160469. # define PNG_READ_pHYs_SUPPORTED
  160470. # define PNG_pHYs_SUPPORTED
  160471. #endif
  160472. #ifndef PNG_NO_READ_sBIT
  160473. # define PNG_READ_sBIT_SUPPORTED
  160474. # define PNG_sBIT_SUPPORTED
  160475. #endif
  160476. #ifndef PNG_NO_READ_sPLT
  160477. # define PNG_READ_sPLT_SUPPORTED
  160478. # define PNG_sPLT_SUPPORTED
  160479. #endif
  160480. #ifndef PNG_NO_READ_sRGB
  160481. # define PNG_READ_sRGB_SUPPORTED
  160482. # define PNG_sRGB_SUPPORTED
  160483. #endif
  160484. #ifndef PNG_NO_READ_tEXt
  160485. # define PNG_READ_tEXt_SUPPORTED
  160486. # define PNG_tEXt_SUPPORTED
  160487. #endif
  160488. #ifndef PNG_NO_READ_tIME
  160489. # define PNG_READ_tIME_SUPPORTED
  160490. # define PNG_tIME_SUPPORTED
  160491. #endif
  160492. #ifndef PNG_NO_READ_tRNS
  160493. # define PNG_READ_tRNS_SUPPORTED
  160494. # define PNG_tRNS_SUPPORTED
  160495. #endif
  160496. #ifndef PNG_NO_READ_zTXt
  160497. # define PNG_READ_zTXt_SUPPORTED
  160498. # define PNG_zTXt_SUPPORTED
  160499. #endif
  160500. #ifndef PNG_NO_READ_UNKNOWN_CHUNKS
  160501. # define PNG_READ_UNKNOWN_CHUNKS_SUPPORTED
  160502. # ifndef PNG_UNKNOWN_CHUNKS_SUPPORTED
  160503. # define PNG_UNKNOWN_CHUNKS_SUPPORTED
  160504. # endif
  160505. # ifndef PNG_NO_HANDLE_AS_UNKNOWN
  160506. # define PNG_HANDLE_AS_UNKNOWN_SUPPORTED
  160507. # endif
  160508. #endif
  160509. #if !defined(PNG_NO_READ_USER_CHUNKS) && \
  160510. defined(PNG_READ_UNKNOWN_CHUNKS_SUPPORTED)
  160511. # define PNG_READ_USER_CHUNKS_SUPPORTED
  160512. # define PNG_USER_CHUNKS_SUPPORTED
  160513. # ifdef PNG_NO_READ_UNKNOWN_CHUNKS
  160514. # undef PNG_NO_READ_UNKNOWN_CHUNKS
  160515. # endif
  160516. # ifdef PNG_NO_HANDLE_AS_UNKNOWN
  160517. # undef PNG_NO_HANDLE_AS_UNKNOWN
  160518. # endif
  160519. #endif
  160520. #ifndef PNG_NO_READ_OPT_PLTE
  160521. # define PNG_READ_OPT_PLTE_SUPPORTED /* only affects support of the */
  160522. #endif /* optional PLTE chunk in RGB and RGBA images */
  160523. #if defined(PNG_READ_iTXt_SUPPORTED) || defined(PNG_READ_tEXt_SUPPORTED) || \
  160524. defined(PNG_READ_zTXt_SUPPORTED)
  160525. # define PNG_READ_TEXT_SUPPORTED
  160526. # define PNG_TEXT_SUPPORTED
  160527. #endif
  160528. #endif /* PNG_READ_ANCILLARY_CHUNKS_SUPPORTED */
  160529. #ifdef PNG_WRITE_ANCILLARY_CHUNKS_SUPPORTED
  160530. #ifdef PNG_NO_WRITE_TEXT
  160531. # define PNG_NO_WRITE_iTXt
  160532. # define PNG_NO_WRITE_tEXt
  160533. # define PNG_NO_WRITE_zTXt
  160534. #endif
  160535. #ifndef PNG_NO_WRITE_bKGD
  160536. # define PNG_WRITE_bKGD_SUPPORTED
  160537. # ifndef PNG_bKGD_SUPPORTED
  160538. # define PNG_bKGD_SUPPORTED
  160539. # endif
  160540. #endif
  160541. #ifndef PNG_NO_WRITE_cHRM
  160542. # define PNG_WRITE_cHRM_SUPPORTED
  160543. # ifndef PNG_cHRM_SUPPORTED
  160544. # define PNG_cHRM_SUPPORTED
  160545. # endif
  160546. #endif
  160547. #ifndef PNG_NO_WRITE_gAMA
  160548. # define PNG_WRITE_gAMA_SUPPORTED
  160549. # ifndef PNG_gAMA_SUPPORTED
  160550. # define PNG_gAMA_SUPPORTED
  160551. # endif
  160552. #endif
  160553. #ifndef PNG_NO_WRITE_hIST
  160554. # define PNG_WRITE_hIST_SUPPORTED
  160555. # ifndef PNG_hIST_SUPPORTED
  160556. # define PNG_hIST_SUPPORTED
  160557. # endif
  160558. #endif
  160559. #ifndef PNG_NO_WRITE_iCCP
  160560. # define PNG_WRITE_iCCP_SUPPORTED
  160561. # ifndef PNG_iCCP_SUPPORTED
  160562. # define PNG_iCCP_SUPPORTED
  160563. # endif
  160564. #endif
  160565. #ifndef PNG_NO_WRITE_iTXt
  160566. # ifndef PNG_WRITE_iTXt_SUPPORTED
  160567. # define PNG_WRITE_iTXt_SUPPORTED
  160568. # endif
  160569. # ifndef PNG_iTXt_SUPPORTED
  160570. # define PNG_iTXt_SUPPORTED
  160571. # endif
  160572. #endif
  160573. #ifndef PNG_NO_WRITE_oFFs
  160574. # define PNG_WRITE_oFFs_SUPPORTED
  160575. # ifndef PNG_oFFs_SUPPORTED
  160576. # define PNG_oFFs_SUPPORTED
  160577. # endif
  160578. #endif
  160579. #ifndef PNG_NO_WRITE_pCAL
  160580. # define PNG_WRITE_pCAL_SUPPORTED
  160581. # ifndef PNG_pCAL_SUPPORTED
  160582. # define PNG_pCAL_SUPPORTED
  160583. # endif
  160584. #endif
  160585. #ifndef PNG_NO_WRITE_sCAL
  160586. # define PNG_WRITE_sCAL_SUPPORTED
  160587. # ifndef PNG_sCAL_SUPPORTED
  160588. # define PNG_sCAL_SUPPORTED
  160589. # endif
  160590. #endif
  160591. #ifndef PNG_NO_WRITE_pHYs
  160592. # define PNG_WRITE_pHYs_SUPPORTED
  160593. # ifndef PNG_pHYs_SUPPORTED
  160594. # define PNG_pHYs_SUPPORTED
  160595. # endif
  160596. #endif
  160597. #ifndef PNG_NO_WRITE_sBIT
  160598. # define PNG_WRITE_sBIT_SUPPORTED
  160599. # ifndef PNG_sBIT_SUPPORTED
  160600. # define PNG_sBIT_SUPPORTED
  160601. # endif
  160602. #endif
  160603. #ifndef PNG_NO_WRITE_sPLT
  160604. # define PNG_WRITE_sPLT_SUPPORTED
  160605. # ifndef PNG_sPLT_SUPPORTED
  160606. # define PNG_sPLT_SUPPORTED
  160607. # endif
  160608. #endif
  160609. #ifndef PNG_NO_WRITE_sRGB
  160610. # define PNG_WRITE_sRGB_SUPPORTED
  160611. # ifndef PNG_sRGB_SUPPORTED
  160612. # define PNG_sRGB_SUPPORTED
  160613. # endif
  160614. #endif
  160615. #ifndef PNG_NO_WRITE_tEXt
  160616. # define PNG_WRITE_tEXt_SUPPORTED
  160617. # ifndef PNG_tEXt_SUPPORTED
  160618. # define PNG_tEXt_SUPPORTED
  160619. # endif
  160620. #endif
  160621. #ifndef PNG_NO_WRITE_tIME
  160622. # define PNG_WRITE_tIME_SUPPORTED
  160623. # ifndef PNG_tIME_SUPPORTED
  160624. # define PNG_tIME_SUPPORTED
  160625. # endif
  160626. #endif
  160627. #ifndef PNG_NO_WRITE_tRNS
  160628. # define PNG_WRITE_tRNS_SUPPORTED
  160629. # ifndef PNG_tRNS_SUPPORTED
  160630. # define PNG_tRNS_SUPPORTED
  160631. # endif
  160632. #endif
  160633. #ifndef PNG_NO_WRITE_zTXt
  160634. # define PNG_WRITE_zTXt_SUPPORTED
  160635. # ifndef PNG_zTXt_SUPPORTED
  160636. # define PNG_zTXt_SUPPORTED
  160637. # endif
  160638. #endif
  160639. #ifndef PNG_NO_WRITE_UNKNOWN_CHUNKS
  160640. # define PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED
  160641. # ifndef PNG_UNKNOWN_CHUNKS_SUPPORTED
  160642. # define PNG_UNKNOWN_CHUNKS_SUPPORTED
  160643. # endif
  160644. # ifndef PNG_NO_HANDLE_AS_UNKNOWN
  160645. # ifndef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
  160646. # define PNG_HANDLE_AS_UNKNOWN_SUPPORTED
  160647. # endif
  160648. # endif
  160649. #endif
  160650. #if defined(PNG_WRITE_iTXt_SUPPORTED) || defined(PNG_WRITE_tEXt_SUPPORTED) || \
  160651. defined(PNG_WRITE_zTXt_SUPPORTED)
  160652. # define PNG_WRITE_TEXT_SUPPORTED
  160653. # ifndef PNG_TEXT_SUPPORTED
  160654. # define PNG_TEXT_SUPPORTED
  160655. # endif
  160656. #endif
  160657. #endif /* PNG_WRITE_ANCILLARY_CHUNKS_SUPPORTED */
  160658. #ifndef PNG_NO_INFO_IMAGE
  160659. # define PNG_INFO_IMAGE_SUPPORTED
  160660. #endif
  160661. #if defined(PNG_tIME_SUPPORTED)
  160662. # if !defined(_WIN32_WCE)
  160663. # include <time.h>
  160664. # endif
  160665. #endif
  160666. typedef unsigned long png_uint_32;
  160667. typedef long png_int_32;
  160668. typedef unsigned short png_uint_16;
  160669. typedef short png_int_16;
  160670. typedef unsigned char png_byte;
  160671. #ifdef PNG_SIZE_T
  160672. typedef PNG_SIZE_T png_size_t;
  160673. # define png_sizeof(x) png_convert_size(sizeof (x))
  160674. #else
  160675. typedef size_t png_size_t;
  160676. # define png_sizeof(x) sizeof (x)
  160677. #endif
  160678. #ifdef __BORLANDC__
  160679. # if defined(__LARGE__) || defined(__HUGE__) || defined(__COMPACT__)
  160680. # define LDATA 1
  160681. # else
  160682. # define LDATA 0
  160683. # endif
  160684. # if !defined(__WIN32__) && !defined(__FLAT__) && !defined(__CYGWIN__)
  160685. # define PNG_MAX_MALLOC_64K
  160686. # if (LDATA != 1)
  160687. # ifndef FAR
  160688. # define FAR __far
  160689. # endif
  160690. # define USE_FAR_KEYWORD
  160691. # endif /* LDATA != 1 */
  160692. # endif /* __WIN32__, __FLAT__, __CYGWIN__ */
  160693. #endif /* __BORLANDC__ */
  160694. #if defined(FAR)
  160695. # if defined(M_I86MM)
  160696. # define USE_FAR_KEYWORD
  160697. # define FARDATA FAR
  160698. # include <dos.h>
  160699. # endif
  160700. #endif
  160701. #ifndef FAR
  160702. # define FAR
  160703. #endif
  160704. #ifndef FARDATA
  160705. # define FARDATA
  160706. #endif
  160707. typedef png_int_32 png_fixed_point;
  160708. typedef void FAR * png_voidp;
  160709. typedef png_byte FAR * png_bytep;
  160710. typedef png_uint_32 FAR * png_uint_32p;
  160711. typedef png_int_32 FAR * png_int_32p;
  160712. typedef png_uint_16 FAR * png_uint_16p;
  160713. typedef png_int_16 FAR * png_int_16p;
  160714. typedef PNG_CONST char FAR * png_const_charp;
  160715. typedef char FAR * png_charp;
  160716. typedef png_fixed_point FAR * png_fixed_point_p;
  160717. #ifndef PNG_NO_STDIO
  160718. #if defined(_WIN32_WCE)
  160719. typedef HANDLE png_FILE_p;
  160720. #else
  160721. typedef FILE * png_FILE_p;
  160722. #endif
  160723. #endif
  160724. #ifdef PNG_FLOATING_POINT_SUPPORTED
  160725. typedef double FAR * png_doublep;
  160726. #endif
  160727. typedef png_byte FAR * FAR * png_bytepp;
  160728. typedef png_uint_32 FAR * FAR * png_uint_32pp;
  160729. typedef png_int_32 FAR * FAR * png_int_32pp;
  160730. typedef png_uint_16 FAR * FAR * png_uint_16pp;
  160731. typedef png_int_16 FAR * FAR * png_int_16pp;
  160732. typedef PNG_CONST char FAR * FAR * png_const_charpp;
  160733. typedef char FAR * FAR * png_charpp;
  160734. typedef png_fixed_point FAR * FAR * png_fixed_point_pp;
  160735. #ifdef PNG_FLOATING_POINT_SUPPORTED
  160736. typedef double FAR * FAR * png_doublepp;
  160737. #endif
  160738. typedef char FAR * FAR * FAR * png_charppp;
  160739. #if 0
  160740. typedef charf * png_zcharp;
  160741. typedef charf * FAR * png_zcharpp;
  160742. typedef z_stream FAR * png_zstreamp;
  160743. #endif /* (PNG_1_0_X) || defined(PNG_1_2_X) */
  160744. #if !defined(PNG_DLL) && (defined(PNG_BUILD_DLL) || defined(PNG_USE_DLL))
  160745. # define PNG_DLL
  160746. #endif
  160747. #if defined(__CYGWIN__)
  160748. # if !defined(PNG_STATIC)
  160749. # if defined(PNG_USE_GLOBAL_ARRAYS)
  160750. # undef PNG_USE_GLOBAL_ARRAYS
  160751. # endif
  160752. # if !defined(PNG_USE_LOCAL_ARRAYS)
  160753. # define PNG_USE_LOCAL_ARRAYS
  160754. # endif
  160755. # else
  160756. # if defined(PNG_USE_LOCAL_ARRAYS) || defined(PNG_NO_GLOBAL_ARRAYS)
  160757. # if defined(PNG_USE_GLOBAL_ARRAYS)
  160758. # undef PNG_USE_GLOBAL_ARRAYS
  160759. # endif
  160760. # endif
  160761. # endif
  160762. # if !defined(PNG_USE_LOCAL_ARRAYS) && !defined(PNG_USE_GLOBAL_ARRAYS)
  160763. # define PNG_USE_LOCAL_ARRAYS
  160764. # endif
  160765. #endif
  160766. #if !defined(PNG_USE_LOCAL_ARRAYS) && !defined(PNG_USE_GLOBAL_ARRAYS)
  160767. # if defined(PNG_NO_GLOBAL_ARRAYS) || \
  160768. (defined(__GNUC__) && defined(PNG_DLL)) || defined(_MSC_VER)
  160769. # define PNG_USE_LOCAL_ARRAYS
  160770. # else
  160771. # define PNG_USE_GLOBAL_ARRAYS
  160772. # endif
  160773. #endif
  160774. #if defined(__CYGWIN__)
  160775. # undef PNGAPI
  160776. # define PNGAPI __cdecl
  160777. # undef PNG_IMPEXP
  160778. # define PNG_IMPEXP
  160779. #endif
  160780. #if defined(__MINGW32__) && !defined(PNG_MODULEDEF)
  160781. # ifndef PNG_NO_MODULEDEF
  160782. # define PNG_NO_MODULEDEF
  160783. # endif
  160784. #endif
  160785. #if !defined(PNG_IMPEXP) && defined(PNG_BUILD_DLL) && !defined(PNG_NO_MODULEDEF)
  160786. # define PNG_IMPEXP
  160787. #endif
  160788. #if defined(PNG_DLL) || defined(_DLL) || defined(__DLL__ ) || \
  160789. (( defined(_Windows) || defined(_WINDOWS) || \
  160790. defined(WIN32) || defined(_WIN32) || defined(__WIN32__) ))
  160791. # ifndef PNGAPI
  160792. # if defined(__GNUC__) || (defined (_MSC_VER) && (_MSC_VER >= 800))
  160793. # define PNGAPI __cdecl
  160794. # else
  160795. # define PNGAPI _cdecl
  160796. # endif
  160797. # endif
  160798. # if !defined(PNG_IMPEXP) && (!defined(PNG_DLL) || \
  160799. 0 /* WINCOMPILER_WITH_NO_SUPPORT_FOR_DECLIMPEXP */)
  160800. # define PNG_IMPEXP
  160801. # endif
  160802. # if !defined(PNG_IMPEXP)
  160803. # define PNG_EXPORT_TYPE1(type,symbol) PNG_IMPEXP type PNGAPI symbol
  160804. # define PNG_EXPORT_TYPE2(type,symbol) type PNG_IMPEXP PNGAPI symbol
  160805. # if defined(_MSC_VER) || defined(__BORLANDC__)
  160806. # if (_MSC_VER >= 800) || (__BORLANDC__ >= 0x500)
  160807. # define PNG_EXPORT PNG_EXPORT_TYPE1
  160808. # else
  160809. # define PNG_EXPORT PNG_EXPORT_TYPE2
  160810. # if defined(PNG_BUILD_DLL)
  160811. # define PNG_IMPEXP __export
  160812. # else
  160813. # define PNG_IMPEXP /*__import */ /* doesn't exist AFAIK in
  160814. VC++ */
  160815. # endif /* Exists in Borland C++ for
  160816. C++ classes (== huge) */
  160817. # endif
  160818. # endif
  160819. # if !defined(PNG_IMPEXP)
  160820. # if defined(PNG_BUILD_DLL)
  160821. # define PNG_IMPEXP __declspec(dllexport)
  160822. # else
  160823. # define PNG_IMPEXP __declspec(dllimport)
  160824. # endif
  160825. # endif
  160826. # endif /* PNG_IMPEXP */
  160827. #else /* !(DLL || non-cygwin WINDOWS) */
  160828. # if (defined(__IBMC__) || defined(__IBMCPP__)) && defined(__OS2__)
  160829. # ifndef PNGAPI
  160830. # define PNGAPI _System
  160831. # endif
  160832. # else
  160833. # if 0 /* ... other platforms, with other meanings */
  160834. # endif
  160835. # endif
  160836. #endif
  160837. #ifndef PNGAPI
  160838. # define PNGAPI
  160839. #endif
  160840. #ifndef PNG_IMPEXP
  160841. # define PNG_IMPEXP
  160842. #endif
  160843. #ifdef PNG_BUILDSYMS
  160844. # ifndef PNG_EXPORT
  160845. # define PNG_EXPORT(type,symbol) PNG_FUNCTION_EXPORT symbol END
  160846. # endif
  160847. # ifdef PNG_USE_GLOBAL_ARRAYS
  160848. # ifndef PNG_EXPORT_VAR
  160849. # define PNG_EXPORT_VAR(type) PNG_DATA_EXPORT
  160850. # endif
  160851. # endif
  160852. #endif
  160853. #ifndef PNG_EXPORT
  160854. # define PNG_EXPORT(type,symbol) PNG_IMPEXP type PNGAPI symbol
  160855. #endif
  160856. #ifdef PNG_USE_GLOBAL_ARRAYS
  160857. # ifndef PNG_EXPORT_VAR
  160858. # define PNG_EXPORT_VAR(type) extern PNG_IMPEXP type
  160859. # endif
  160860. #endif
  160861. #ifndef PNG_ABORT
  160862. # define PNG_ABORT() abort()
  160863. #endif
  160864. #ifdef PNG_SETJMP_SUPPORTED
  160865. # define png_jmpbuf(png_ptr) ((png_ptr)->jmpbuf)
  160866. #else
  160867. # define png_jmpbuf(png_ptr) \
  160868. (LIBPNG_WAS_COMPILED_WITH__PNG_SETJMP_NOT_SUPPORTED)
  160869. #endif
  160870. #if defined(USE_FAR_KEYWORD) /* memory model independent fns */
  160871. # define CHECK 1
  160872. # define NOCHECK 0
  160873. # define CVT_PTR(ptr) (png_far_to_near(png_ptr,ptr,CHECK))
  160874. # define CVT_PTR_NOCHECK(ptr) (png_far_to_near(png_ptr,ptr,NOCHECK))
  160875. # define png_snprintf _fsnprintf /* Added to v 1.2.19 */
  160876. # define png_strcpy _fstrcpy
  160877. # define png_strncpy _fstrncpy /* Added to v 1.2.6 */
  160878. # define png_strlen _fstrlen
  160879. # define png_memcmp _fmemcmp /* SJT: added */
  160880. # define png_memcpy _fmemcpy
  160881. # define png_memset _fmemset
  160882. #else /* use the usual functions */
  160883. # define CVT_PTR(ptr) (ptr)
  160884. # define CVT_PTR_NOCHECK(ptr) (ptr)
  160885. # ifndef PNG_NO_SNPRINTF
  160886. # ifdef _MSC_VER
  160887. # define png_snprintf _snprintf /* Added to v 1.2.19 */
  160888. # define png_snprintf2 _snprintf
  160889. # define png_snprintf6 _snprintf
  160890. # else
  160891. # define png_snprintf snprintf /* Added to v 1.2.19 */
  160892. # define png_snprintf2 snprintf
  160893. # define png_snprintf6 snprintf
  160894. # endif
  160895. # else
  160896. # define png_snprintf(s1,n,fmt,x1) sprintf(s1,fmt,x1)
  160897. # define png_snprintf2(s1,n,fmt,x1,x2) sprintf(s1,fmt,x1,x2)
  160898. # define png_snprintf6(s1,n,fmt,x1,x2,x3,x4,x5,x6) \
  160899. sprintf(s1,fmt,x1,x2,x3,x4,x5,x6)
  160900. # endif
  160901. # define png_strcpy strcpy
  160902. # define png_strncpy strncpy /* Added to v 1.2.6 */
  160903. # define png_strlen strlen
  160904. # define png_memcmp memcmp /* SJT: added */
  160905. # define png_memcpy memcpy
  160906. # define png_memset memset
  160907. #endif
  160908. #if (PNG_ZBUF_SIZE > 65536L) && defined(PNG_MAX_MALLOC_64K)
  160909. # undef PNG_ZBUF_SIZE
  160910. # define PNG_ZBUF_SIZE 65536L
  160911. #endif
  160912. #endif /* PNG_VERSION_INFO_ONLY */
  160913. #endif /* PNGCONF_H */
  160914. /********* End of inlined file: pngconf.h *********/
  160915. #ifdef _MSC_VER
  160916. #pragma warning (disable: 4996 4100)
  160917. #endif
  160918. #if defined(PNG_USER_PRIVATEBUILD)
  160919. # define PNG_LIBPNG_BUILD_TYPE \
  160920. (PNG_LIBPNG_BUILD_BASE_TYPE | PNG_LIBPNG_BUILD_PRIVATE)
  160921. #else
  160922. # if defined(PNG_LIBPNG_SPECIALBUILD)
  160923. # define PNG_LIBPNG_BUILD_TYPE \
  160924. (PNG_LIBPNG_BUILD_BASE_TYPE | PNG_LIBPNG_BUILD_SPECIAL)
  160925. # else
  160926. # define PNG_LIBPNG_BUILD_TYPE (PNG_LIBPNG_BUILD_BASE_TYPE)
  160927. # endif
  160928. #endif
  160929. #ifndef PNG_VERSION_INFO_ONLY
  160930. #ifdef __cplusplus
  160931. extern "C" {
  160932. #endif /* __cplusplus */
  160933. #ifndef PNG_NO_TYPECAST_NULL
  160934. #define int_p_NULL (int *)NULL
  160935. #define png_bytep_NULL (png_bytep)NULL
  160936. #define png_bytepp_NULL (png_bytepp)NULL
  160937. #define png_doublep_NULL (png_doublep)NULL
  160938. #define png_error_ptr_NULL (png_error_ptr)NULL
  160939. #define png_flush_ptr_NULL (png_flush_ptr)NULL
  160940. #define png_free_ptr_NULL (png_free_ptr)NULL
  160941. #define png_infopp_NULL (png_infopp)NULL
  160942. #define png_malloc_ptr_NULL (png_malloc_ptr)NULL
  160943. #define png_read_status_ptr_NULL (png_read_status_ptr)NULL
  160944. #define png_rw_ptr_NULL (png_rw_ptr)NULL
  160945. #define png_structp_NULL (png_structp)NULL
  160946. #define png_uint_16p_NULL (png_uint_16p)NULL
  160947. #define png_voidp_NULL (png_voidp)NULL
  160948. #define png_write_status_ptr_NULL (png_write_status_ptr)NULL
  160949. #else
  160950. #define int_p_NULL NULL
  160951. #define png_bytep_NULL NULL
  160952. #define png_bytepp_NULL NULL
  160953. #define png_doublep_NULL NULL
  160954. #define png_error_ptr_NULL NULL
  160955. #define png_flush_ptr_NULL NULL
  160956. #define png_free_ptr_NULL NULL
  160957. #define png_infopp_NULL NULL
  160958. #define png_malloc_ptr_NULL NULL
  160959. #define png_read_status_ptr_NULL NULL
  160960. #define png_rw_ptr_NULL NULL
  160961. #define png_structp_NULL NULL
  160962. #define png_uint_16p_NULL NULL
  160963. #define png_voidp_NULL NULL
  160964. #define png_write_status_ptr_NULL NULL
  160965. #endif
  160966. #if !defined(PNG_NO_EXTERN) || defined(PNG_ALWAYS_EXTERN)
  160967. #ifdef PNG_USE_GLOBAL_ARRAYS
  160968. PNG_EXPORT_VAR (PNG_CONST char) png_libpng_ver[18];
  160969. #else
  160970. #define png_libpng_ver png_get_header_ver(NULL)
  160971. #endif
  160972. #ifdef PNG_USE_GLOBAL_ARRAYS
  160973. PNG_EXPORT_VAR (PNG_CONST int FARDATA) png_pass_start[7];
  160974. PNG_EXPORT_VAR (PNG_CONST int FARDATA) png_pass_inc[7];
  160975. PNG_EXPORT_VAR (PNG_CONST int FARDATA) png_pass_ystart[7];
  160976. PNG_EXPORT_VAR (PNG_CONST int FARDATA) png_pass_yinc[7];
  160977. PNG_EXPORT_VAR (PNG_CONST int FARDATA) png_pass_mask[7];
  160978. PNG_EXPORT_VAR (PNG_CONST int FARDATA) png_pass_dsp_mask[7];
  160979. #endif
  160980. #endif /* PNG_NO_EXTERN */
  160981. typedef struct png_color_struct
  160982. {
  160983. png_byte red;
  160984. png_byte green;
  160985. png_byte blue;
  160986. } png_color;
  160987. typedef png_color FAR * png_colorp;
  160988. typedef png_color FAR * FAR * png_colorpp;
  160989. typedef struct png_color_16_struct
  160990. {
  160991. png_byte index; /* used for palette files */
  160992. png_uint_16 red; /* for use in red green blue files */
  160993. png_uint_16 green;
  160994. png_uint_16 blue;
  160995. png_uint_16 gray; /* for use in grayscale files */
  160996. } png_color_16;
  160997. typedef png_color_16 FAR * png_color_16p;
  160998. typedef png_color_16 FAR * FAR * png_color_16pp;
  160999. typedef struct png_color_8_struct
  161000. {
  161001. png_byte red; /* for use in red green blue files */
  161002. png_byte green;
  161003. png_byte blue;
  161004. png_byte gray; /* for use in grayscale files */
  161005. png_byte alpha; /* for alpha channel files */
  161006. } png_color_8;
  161007. typedef png_color_8 FAR * png_color_8p;
  161008. typedef png_color_8 FAR * FAR * png_color_8pp;
  161009. typedef struct png_sPLT_entry_struct
  161010. {
  161011. png_uint_16 red;
  161012. png_uint_16 green;
  161013. png_uint_16 blue;
  161014. png_uint_16 alpha;
  161015. png_uint_16 frequency;
  161016. } png_sPLT_entry;
  161017. typedef png_sPLT_entry FAR * png_sPLT_entryp;
  161018. typedef png_sPLT_entry FAR * FAR * png_sPLT_entrypp;
  161019. typedef struct png_sPLT_struct
  161020. {
  161021. png_charp name; /* palette name */
  161022. png_byte depth; /* depth of palette samples */
  161023. png_sPLT_entryp entries; /* palette entries */
  161024. png_int_32 nentries; /* number of palette entries */
  161025. } png_sPLT_t;
  161026. typedef png_sPLT_t FAR * png_sPLT_tp;
  161027. typedef png_sPLT_t FAR * FAR * png_sPLT_tpp;
  161028. #ifdef PNG_TEXT_SUPPORTED
  161029. typedef struct png_text_struct
  161030. {
  161031. int compression; /* compression value:
  161032. -1: tEXt, none
  161033. 0: zTXt, deflate
  161034. 1: iTXt, none
  161035. 2: iTXt, deflate */
  161036. png_charp key; /* keyword, 1-79 character description of "text" */
  161037. png_charp text; /* comment, may be an empty string (ie "")
  161038. or a NULL pointer */
  161039. png_size_t text_length; /* length of the text string */
  161040. #ifdef PNG_iTXt_SUPPORTED
  161041. png_size_t itxt_length; /* length of the itxt string */
  161042. png_charp lang; /* language code, 0-79 characters
  161043. or a NULL pointer */
  161044. png_charp lang_key; /* keyword translated UTF-8 string, 0 or more
  161045. chars or a NULL pointer */
  161046. #endif
  161047. } png_text;
  161048. typedef png_text FAR * png_textp;
  161049. typedef png_text FAR * FAR * png_textpp;
  161050. #endif
  161051. #define PNG_TEXT_COMPRESSION_NONE_WR -3
  161052. #define PNG_TEXT_COMPRESSION_zTXt_WR -2
  161053. #define PNG_TEXT_COMPRESSION_NONE -1
  161054. #define PNG_TEXT_COMPRESSION_zTXt 0
  161055. #define PNG_ITXT_COMPRESSION_NONE 1
  161056. #define PNG_ITXT_COMPRESSION_zTXt 2
  161057. #define PNG_TEXT_COMPRESSION_LAST 3 /* Not a valid value */
  161058. typedef struct png_time_struct
  161059. {
  161060. png_uint_16 year; /* full year, as in, 1995 */
  161061. png_byte month; /* month of year, 1 - 12 */
  161062. png_byte day; /* day of month, 1 - 31 */
  161063. png_byte hour; /* hour of day, 0 - 23 */
  161064. png_byte minute; /* minute of hour, 0 - 59 */
  161065. png_byte second; /* second of minute, 0 - 60 (for leap seconds) */
  161066. } png_time;
  161067. typedef png_time FAR * png_timep;
  161068. typedef png_time FAR * FAR * png_timepp;
  161069. #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
  161070. typedef struct png_unknown_chunk_t
  161071. {
  161072. png_byte name[5];
  161073. png_byte *data;
  161074. png_size_t size;
  161075. png_byte location; /* mode of operation at read time */
  161076. }
  161077. png_unknown_chunk;
  161078. typedef png_unknown_chunk FAR * png_unknown_chunkp;
  161079. typedef png_unknown_chunk FAR * FAR * png_unknown_chunkpp;
  161080. #endif
  161081. typedef struct png_info_struct
  161082. {
  161083. png_uint_32 width; /* width of image in pixels (from IHDR) */
  161084. png_uint_32 height; /* height of image in pixels (from IHDR) */
  161085. png_uint_32 valid; /* valid chunk data (see PNG_INFO_ below) */
  161086. png_uint_32 rowbytes; /* bytes needed to hold an untransformed row */
  161087. png_colorp palette; /* array of color values (valid & PNG_INFO_PLTE) */
  161088. png_uint_16 num_palette; /* number of color entries in "palette" (PLTE) */
  161089. png_uint_16 num_trans; /* number of transparent palette color (tRNS) */
  161090. png_byte bit_depth; /* 1, 2, 4, 8, or 16 bits/channel (from IHDR) */
  161091. png_byte color_type; /* see PNG_COLOR_TYPE_ below (from IHDR) */
  161092. png_byte compression_type; /* must be PNG_COMPRESSION_TYPE_BASE (IHDR) */
  161093. png_byte filter_type; /* must be PNG_FILTER_TYPE_BASE (from IHDR) */
  161094. png_byte interlace_type; /* One of PNG_INTERLACE_NONE, PNG_INTERLACE_ADAM7 */
  161095. png_byte channels; /* number of data channels per pixel (1, 2, 3, 4) */
  161096. png_byte pixel_depth; /* number of bits per pixel */
  161097. png_byte spare_byte; /* to align the data, and for future use */
  161098. png_byte signature[8]; /* magic bytes read by libpng from start of file */
  161099. #if defined(PNG_gAMA_SUPPORTED) && defined(PNG_FLOATING_POINT_SUPPORTED)
  161100. float gamma; /* gamma value of image, if (valid & PNG_INFO_gAMA) */
  161101. #endif
  161102. #if defined(PNG_sRGB_SUPPORTED)
  161103. png_byte srgb_intent; /* sRGB rendering intent [0, 1, 2, or 3] */
  161104. #endif
  161105. #if defined(PNG_TEXT_SUPPORTED)
  161106. int num_text; /* number of comments read/to write */
  161107. int max_text; /* current size of text array */
  161108. png_textp text; /* array of comments read/to write */
  161109. #endif /* PNG_TEXT_SUPPORTED */
  161110. #if defined(PNG_tIME_SUPPORTED)
  161111. png_time mod_time;
  161112. #endif
  161113. #if defined(PNG_sBIT_SUPPORTED)
  161114. png_color_8 sig_bit; /* significant bits in color channels */
  161115. #endif
  161116. #if defined(PNG_tRNS_SUPPORTED) || defined(PNG_READ_EXPAND_SUPPORTED) || \
  161117. defined(PNG_READ_BACKGROUND_SUPPORTED)
  161118. png_bytep trans; /* transparent values for paletted image */
  161119. png_color_16 trans_values; /* transparent color for non-palette image */
  161120. #endif
  161121. #if defined(PNG_bKGD_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
  161122. png_color_16 background;
  161123. #endif
  161124. #if defined(PNG_oFFs_SUPPORTED)
  161125. png_int_32 x_offset; /* x offset on page */
  161126. png_int_32 y_offset; /* y offset on page */
  161127. png_byte offset_unit_type; /* offset units type */
  161128. #endif
  161129. #if defined(PNG_pHYs_SUPPORTED)
  161130. png_uint_32 x_pixels_per_unit; /* horizontal pixel density */
  161131. png_uint_32 y_pixels_per_unit; /* vertical pixel density */
  161132. png_byte phys_unit_type; /* resolution type (see PNG_RESOLUTION_ below) */
  161133. #endif
  161134. #if defined(PNG_hIST_SUPPORTED)
  161135. png_uint_16p hist;
  161136. #endif
  161137. #ifdef PNG_cHRM_SUPPORTED
  161138. #ifdef PNG_FLOATING_POINT_SUPPORTED
  161139. float x_white;
  161140. float y_white;
  161141. float x_red;
  161142. float y_red;
  161143. float x_green;
  161144. float y_green;
  161145. float x_blue;
  161146. float y_blue;
  161147. #endif
  161148. #endif
  161149. #if defined(PNG_pCAL_SUPPORTED)
  161150. png_charp pcal_purpose; /* pCAL chunk description string */
  161151. png_int_32 pcal_X0; /* minimum value */
  161152. png_int_32 pcal_X1; /* maximum value */
  161153. png_charp pcal_units; /* Latin-1 string giving physical units */
  161154. png_charpp pcal_params; /* ASCII strings containing parameter values */
  161155. png_byte pcal_type; /* equation type (see PNG_EQUATION_ below) */
  161156. png_byte pcal_nparams; /* number of parameters given in pcal_params */
  161157. #endif
  161158. #ifdef PNG_FREE_ME_SUPPORTED
  161159. png_uint_32 free_me; /* flags items libpng is responsible for freeing */
  161160. #endif
  161161. #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
  161162. png_unknown_chunkp unknown_chunks;
  161163. png_size_t unknown_chunks_num;
  161164. #endif
  161165. #if defined(PNG_iCCP_SUPPORTED)
  161166. png_charp iccp_name; /* profile name */
  161167. png_charp iccp_profile; /* International Color Consortium profile data */
  161168. png_uint_32 iccp_proflen; /* ICC profile data length */
  161169. png_byte iccp_compression; /* Always zero */
  161170. #endif
  161171. #if defined(PNG_sPLT_SUPPORTED)
  161172. png_sPLT_tp splt_palettes;
  161173. png_uint_32 splt_palettes_num;
  161174. #endif
  161175. #if defined(PNG_sCAL_SUPPORTED)
  161176. png_byte scal_unit; /* unit of physical scale */
  161177. #ifdef PNG_FLOATING_POINT_SUPPORTED
  161178. double scal_pixel_width; /* width of one pixel */
  161179. double scal_pixel_height; /* height of one pixel */
  161180. #endif
  161181. #ifdef PNG_FIXED_POINT_SUPPORTED
  161182. png_charp scal_s_width; /* string containing height */
  161183. png_charp scal_s_height; /* string containing width */
  161184. #endif
  161185. #endif
  161186. #if defined(PNG_INFO_IMAGE_SUPPORTED)
  161187. png_bytepp row_pointers; /* the image bits */
  161188. #endif
  161189. #if defined(PNG_FIXED_POINT_SUPPORTED) && defined(PNG_gAMA_SUPPORTED)
  161190. png_fixed_point int_gamma; /* gamma of image, if (valid & PNG_INFO_gAMA) */
  161191. #endif
  161192. #if defined(PNG_cHRM_SUPPORTED) && defined(PNG_FIXED_POINT_SUPPORTED)
  161193. png_fixed_point int_x_white;
  161194. png_fixed_point int_y_white;
  161195. png_fixed_point int_x_red;
  161196. png_fixed_point int_y_red;
  161197. png_fixed_point int_x_green;
  161198. png_fixed_point int_y_green;
  161199. png_fixed_point int_x_blue;
  161200. png_fixed_point int_y_blue;
  161201. #endif
  161202. } png_info;
  161203. typedef png_info FAR * png_infop;
  161204. typedef png_info FAR * FAR * png_infopp;
  161205. #define PNG_UINT_31_MAX ((png_uint_32)0x7fffffffL)
  161206. #define PNG_UINT_32_MAX ((png_uint_32)(-1))
  161207. #define PNG_SIZE_MAX ((png_size_t)(-1))
  161208. #if defined(PNG_1_0_X) || defined (PNG_1_2_X)
  161209. #define PNG_MAX_UINT PNG_UINT_31_MAX
  161210. #endif
  161211. #define PNG_COLOR_MASK_PALETTE 1
  161212. #define PNG_COLOR_MASK_COLOR 2
  161213. #define PNG_COLOR_MASK_ALPHA 4
  161214. #define PNG_COLOR_TYPE_GRAY 0
  161215. #define PNG_COLOR_TYPE_PALETTE (PNG_COLOR_MASK_COLOR | PNG_COLOR_MASK_PALETTE)
  161216. #define PNG_COLOR_TYPE_RGB (PNG_COLOR_MASK_COLOR)
  161217. #define PNG_COLOR_TYPE_RGB_ALPHA (PNG_COLOR_MASK_COLOR | PNG_COLOR_MASK_ALPHA)
  161218. #define PNG_COLOR_TYPE_GRAY_ALPHA (PNG_COLOR_MASK_ALPHA)
  161219. #define PNG_COLOR_TYPE_RGBA PNG_COLOR_TYPE_RGB_ALPHA
  161220. #define PNG_COLOR_TYPE_GA PNG_COLOR_TYPE_GRAY_ALPHA
  161221. #define PNG_COMPRESSION_TYPE_BASE 0 /* Deflate method 8, 32K window */
  161222. #define PNG_COMPRESSION_TYPE_DEFAULT PNG_COMPRESSION_TYPE_BASE
  161223. #define PNG_FILTER_TYPE_BASE 0 /* Single row per-byte filtering */
  161224. #define PNG_INTRAPIXEL_DIFFERENCING 64 /* Used only in MNG datastreams */
  161225. #define PNG_FILTER_TYPE_DEFAULT PNG_FILTER_TYPE_BASE
  161226. #define PNG_INTERLACE_NONE 0 /* Non-interlaced image */
  161227. #define PNG_INTERLACE_ADAM7 1 /* Adam7 interlacing */
  161228. #define PNG_INTERLACE_LAST 2 /* Not a valid value */
  161229. #define PNG_OFFSET_PIXEL 0 /* Offset in pixels */
  161230. #define PNG_OFFSET_MICROMETER 1 /* Offset in micrometers (1/10^6 meter) */
  161231. #define PNG_OFFSET_LAST 2 /* Not a valid value */
  161232. #define PNG_EQUATION_LINEAR 0 /* Linear transformation */
  161233. #define PNG_EQUATION_BASE_E 1 /* Exponential base e transform */
  161234. #define PNG_EQUATION_ARBITRARY 2 /* Arbitrary base exponential transform */
  161235. #define PNG_EQUATION_HYPERBOLIC 3 /* Hyperbolic sine transformation */
  161236. #define PNG_EQUATION_LAST 4 /* Not a valid value */
  161237. #define PNG_SCALE_UNKNOWN 0 /* unknown unit (image scale) */
  161238. #define PNG_SCALE_METER 1 /* meters per pixel */
  161239. #define PNG_SCALE_RADIAN 2 /* radians per pixel */
  161240. #define PNG_SCALE_LAST 3 /* Not a valid value */
  161241. #define PNG_RESOLUTION_UNKNOWN 0 /* pixels/unknown unit (aspect ratio) */
  161242. #define PNG_RESOLUTION_METER 1 /* pixels/meter */
  161243. #define PNG_RESOLUTION_LAST 2 /* Not a valid value */
  161244. #define PNG_sRGB_INTENT_PERCEPTUAL 0
  161245. #define PNG_sRGB_INTENT_RELATIVE 1
  161246. #define PNG_sRGB_INTENT_SATURATION 2
  161247. #define PNG_sRGB_INTENT_ABSOLUTE 3
  161248. #define PNG_sRGB_INTENT_LAST 4 /* Not a valid value */
  161249. #define PNG_KEYWORD_MAX_LENGTH 79
  161250. #define PNG_MAX_PALETTE_LENGTH 256
  161251. #define PNG_INFO_gAMA 0x0001
  161252. #define PNG_INFO_sBIT 0x0002
  161253. #define PNG_INFO_cHRM 0x0004
  161254. #define PNG_INFO_PLTE 0x0008
  161255. #define PNG_INFO_tRNS 0x0010
  161256. #define PNG_INFO_bKGD 0x0020
  161257. #define PNG_INFO_hIST 0x0040
  161258. #define PNG_INFO_pHYs 0x0080
  161259. #define PNG_INFO_oFFs 0x0100
  161260. #define PNG_INFO_tIME 0x0200
  161261. #define PNG_INFO_pCAL 0x0400
  161262. #define PNG_INFO_sRGB 0x0800 /* GR-P, 0.96a */
  161263. #define PNG_INFO_iCCP 0x1000 /* ESR, 1.0.6 */
  161264. #define PNG_INFO_sPLT 0x2000 /* ESR, 1.0.6 */
  161265. #define PNG_INFO_sCAL 0x4000 /* ESR, 1.0.6 */
  161266. #define PNG_INFO_IDAT 0x8000L /* ESR, 1.0.6 */
  161267. typedef struct png_row_info_struct
  161268. {
  161269. png_uint_32 width; /* width of row */
  161270. png_uint_32 rowbytes; /* number of bytes in row */
  161271. png_byte color_type; /* color type of row */
  161272. png_byte bit_depth; /* bit depth of row */
  161273. png_byte channels; /* number of channels (1, 2, 3, or 4) */
  161274. png_byte pixel_depth; /* bits per pixel (depth * channels) */
  161275. } png_row_info;
  161276. typedef png_row_info FAR * png_row_infop;
  161277. typedef png_row_info FAR * FAR * png_row_infopp;
  161278. typedef struct png_struct_def png_struct;
  161279. typedef png_struct FAR * png_structp;
  161280. typedef void (PNGAPI *png_error_ptr) PNGARG((png_structp, png_const_charp));
  161281. typedef void (PNGAPI *png_rw_ptr) PNGARG((png_structp, png_bytep, png_size_t));
  161282. typedef void (PNGAPI *png_flush_ptr) PNGARG((png_structp));
  161283. typedef void (PNGAPI *png_read_status_ptr) PNGARG((png_structp, png_uint_32,
  161284. int));
  161285. typedef void (PNGAPI *png_write_status_ptr) PNGARG((png_structp, png_uint_32,
  161286. int));
  161287. #ifdef PNG_PROGRESSIVE_READ_SUPPORTED
  161288. typedef void (PNGAPI *png_progressive_info_ptr) PNGARG((png_structp, png_infop));
  161289. typedef void (PNGAPI *png_progressive_end_ptr) PNGARG((png_structp, png_infop));
  161290. typedef void (PNGAPI *png_progressive_row_ptr) PNGARG((png_structp, png_bytep,
  161291. png_uint_32, int));
  161292. #endif
  161293. #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \
  161294. defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED) || \
  161295. defined(PNG_LEGACY_SUPPORTED)
  161296. typedef void (PNGAPI *png_user_transform_ptr) PNGARG((png_structp,
  161297. png_row_infop, png_bytep));
  161298. #endif
  161299. #if defined(PNG_USER_CHUNKS_SUPPORTED)
  161300. typedef int (PNGAPI *png_user_chunk_ptr) PNGARG((png_structp, png_unknown_chunkp));
  161301. #endif
  161302. #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
  161303. typedef void (PNGAPI *png_unknown_chunk_ptr) PNGARG((png_structp));
  161304. #endif
  161305. #define PNG_TRANSFORM_IDENTITY 0x0000 /* read and write */
  161306. #define PNG_TRANSFORM_STRIP_16 0x0001 /* read only */
  161307. #define PNG_TRANSFORM_STRIP_ALPHA 0x0002 /* read only */
  161308. #define PNG_TRANSFORM_PACKING 0x0004 /* read and write */
  161309. #define PNG_TRANSFORM_PACKSWAP 0x0008 /* read and write */
  161310. #define PNG_TRANSFORM_EXPAND 0x0010 /* read only */
  161311. #define PNG_TRANSFORM_INVERT_MONO 0x0020 /* read and write */
  161312. #define PNG_TRANSFORM_SHIFT 0x0040 /* read and write */
  161313. #define PNG_TRANSFORM_BGR 0x0080 /* read and write */
  161314. #define PNG_TRANSFORM_SWAP_ALPHA 0x0100 /* read and write */
  161315. #define PNG_TRANSFORM_SWAP_ENDIAN 0x0200 /* read and write */
  161316. #define PNG_TRANSFORM_INVERT_ALPHA 0x0400 /* read and write */
  161317. #define PNG_TRANSFORM_STRIP_FILLER 0x0800 /* WRITE only */
  161318. #define PNG_FLAG_MNG_EMPTY_PLTE 0x01
  161319. #define PNG_FLAG_MNG_FILTER_64 0x04
  161320. #define PNG_ALL_MNG_FEATURES 0x05
  161321. typedef png_voidp (*png_malloc_ptr) PNGARG((png_structp, png_size_t));
  161322. typedef void (*png_free_ptr) PNGARG((png_structp, png_voidp));
  161323. struct png_struct_def
  161324. {
  161325. #ifdef PNG_SETJMP_SUPPORTED
  161326. jmp_buf jmpbuf; /* used in png_error */
  161327. #endif
  161328. png_error_ptr error_fn; /* function for printing errors and aborting */
  161329. png_error_ptr warning_fn; /* function for printing warnings */
  161330. png_voidp error_ptr; /* user supplied struct for error functions */
  161331. png_rw_ptr write_data_fn; /* function for writing output data */
  161332. png_rw_ptr read_data_fn; /* function for reading input data */
  161333. png_voidp io_ptr; /* ptr to application struct for I/O functions */
  161334. #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED)
  161335. png_user_transform_ptr read_user_transform_fn; /* user read transform */
  161336. #endif
  161337. #if defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED)
  161338. png_user_transform_ptr write_user_transform_fn; /* user write transform */
  161339. #endif
  161340. #if defined(PNG_USER_TRANSFORM_PTR_SUPPORTED)
  161341. #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \
  161342. defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED)
  161343. png_voidp user_transform_ptr; /* user supplied struct for user transform */
  161344. png_byte user_transform_depth; /* bit depth of user transformed pixels */
  161345. png_byte user_transform_channels; /* channels in user transformed pixels */
  161346. #endif
  161347. #endif
  161348. png_uint_32 mode; /* tells us where we are in the PNG file */
  161349. png_uint_32 flags; /* flags indicating various things to libpng */
  161350. png_uint_32 transformations; /* which transformations to perform */
  161351. z_stream zstream; /* pointer to decompression structure (below) */
  161352. png_bytep zbuf; /* buffer for zlib */
  161353. png_size_t zbuf_size; /* size of zbuf */
  161354. int zlib_level; /* holds zlib compression level */
  161355. int zlib_method; /* holds zlib compression method */
  161356. int zlib_window_bits; /* holds zlib compression window bits */
  161357. int zlib_mem_level; /* holds zlib compression memory level */
  161358. int zlib_strategy; /* holds zlib compression strategy */
  161359. png_uint_32 width; /* width of image in pixels */
  161360. png_uint_32 height; /* height of image in pixels */
  161361. png_uint_32 num_rows; /* number of rows in current pass */
  161362. png_uint_32 usr_width; /* width of row at start of write */
  161363. png_uint_32 rowbytes; /* size of row in bytes */
  161364. png_uint_32 irowbytes; /* size of current interlaced row in bytes */
  161365. png_uint_32 iwidth; /* width of current interlaced row in pixels */
  161366. png_uint_32 row_number; /* current row in interlace pass */
  161367. png_bytep prev_row; /* buffer to save previous (unfiltered) row */
  161368. png_bytep row_buf; /* buffer to save current (unfiltered) row */
  161369. png_bytep sub_row; /* buffer to save "sub" row when filtering */
  161370. png_bytep up_row; /* buffer to save "up" row when filtering */
  161371. png_bytep avg_row; /* buffer to save "avg" row when filtering */
  161372. png_bytep paeth_row; /* buffer to save "Paeth" row when filtering */
  161373. png_row_info row_info; /* used for transformation routines */
  161374. png_uint_32 idat_size; /* current IDAT size for read */
  161375. png_uint_32 crc; /* current chunk CRC value */
  161376. png_colorp palette; /* palette from the input file */
  161377. png_uint_16 num_palette; /* number of color entries in palette */
  161378. png_uint_16 num_trans; /* number of transparency values */
  161379. png_byte chunk_name[5]; /* null-terminated name of current chunk */
  161380. png_byte compression; /* file compression type (always 0) */
  161381. png_byte filter; /* file filter type (always 0) */
  161382. png_byte interlaced; /* PNG_INTERLACE_NONE, PNG_INTERLACE_ADAM7 */
  161383. png_byte pass; /* current interlace pass (0 - 6) */
  161384. png_byte do_filter; /* row filter flags (see PNG_FILTER_ below ) */
  161385. png_byte color_type; /* color type of file */
  161386. png_byte bit_depth; /* bit depth of file */
  161387. png_byte usr_bit_depth; /* bit depth of users row */
  161388. png_byte pixel_depth; /* number of bits per pixel */
  161389. png_byte channels; /* number of channels in file */
  161390. png_byte usr_channels; /* channels at start of write */
  161391. png_byte sig_bytes; /* magic bytes read/written from start of file */
  161392. #if defined(PNG_READ_FILLER_SUPPORTED) || defined(PNG_WRITE_FILLER_SUPPORTED)
  161393. #ifdef PNG_LEGACY_SUPPORTED
  161394. png_byte filler; /* filler byte for pixel expansion */
  161395. #else
  161396. png_uint_16 filler; /* filler bytes for pixel expansion */
  161397. #endif
  161398. #endif
  161399. #if defined(PNG_bKGD_SUPPORTED)
  161400. png_byte background_gamma_type;
  161401. # ifdef PNG_FLOATING_POINT_SUPPORTED
  161402. float background_gamma;
  161403. # endif
  161404. png_color_16 background; /* background color in screen gamma space */
  161405. #if defined(PNG_READ_GAMMA_SUPPORTED)
  161406. png_color_16 background_1; /* background normalized to gamma 1.0 */
  161407. #endif
  161408. #endif /* PNG_bKGD_SUPPORTED */
  161409. #if defined(PNG_WRITE_FLUSH_SUPPORTED)
  161410. png_flush_ptr output_flush_fn;/* Function for flushing output */
  161411. png_uint_32 flush_dist; /* how many rows apart to flush, 0 - no flush */
  161412. png_uint_32 flush_rows; /* number of rows written since last flush */
  161413. #endif
  161414. #if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
  161415. int gamma_shift; /* number of "insignificant" bits 16-bit gamma */
  161416. #ifdef PNG_FLOATING_POINT_SUPPORTED
  161417. float gamma; /* file gamma value */
  161418. float screen_gamma; /* screen gamma value (display_exponent) */
  161419. #endif
  161420. #endif
  161421. #if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
  161422. png_bytep gamma_table; /* gamma table for 8-bit depth files */
  161423. png_bytep gamma_from_1; /* converts from 1.0 to screen */
  161424. png_bytep gamma_to_1; /* converts from file to 1.0 */
  161425. png_uint_16pp gamma_16_table; /* gamma table for 16-bit depth files */
  161426. png_uint_16pp gamma_16_from_1; /* converts from 1.0 to screen */
  161427. png_uint_16pp gamma_16_to_1; /* converts from file to 1.0 */
  161428. #endif
  161429. #if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_sBIT_SUPPORTED)
  161430. png_color_8 sig_bit; /* significant bits in each available channel */
  161431. #endif
  161432. #if defined(PNG_READ_SHIFT_SUPPORTED) || defined(PNG_WRITE_SHIFT_SUPPORTED)
  161433. png_color_8 shift; /* shift for significant bit tranformation */
  161434. #endif
  161435. #if defined(PNG_tRNS_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED) \
  161436. || defined(PNG_READ_EXPAND_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
  161437. png_bytep trans; /* transparency values for paletted files */
  161438. png_color_16 trans_values; /* transparency values for non-paletted files */
  161439. #endif
  161440. png_read_status_ptr read_row_fn; /* called after each row is decoded */
  161441. png_write_status_ptr write_row_fn; /* called after each row is encoded */
  161442. #ifdef PNG_PROGRESSIVE_READ_SUPPORTED
  161443. png_progressive_info_ptr info_fn; /* called after header data fully read */
  161444. png_progressive_row_ptr row_fn; /* called after each prog. row is decoded */
  161445. png_progressive_end_ptr end_fn; /* called after image is complete */
  161446. png_bytep save_buffer_ptr; /* current location in save_buffer */
  161447. png_bytep save_buffer; /* buffer for previously read data */
  161448. png_bytep current_buffer_ptr; /* current location in current_buffer */
  161449. png_bytep current_buffer; /* buffer for recently used data */
  161450. png_uint_32 push_length; /* size of current input chunk */
  161451. png_uint_32 skip_length; /* bytes to skip in input data */
  161452. png_size_t save_buffer_size; /* amount of data now in save_buffer */
  161453. png_size_t save_buffer_max; /* total size of save_buffer */
  161454. png_size_t buffer_size; /* total amount of available input data */
  161455. png_size_t current_buffer_size; /* amount of data now in current_buffer */
  161456. int process_mode; /* what push library is currently doing */
  161457. int cur_palette; /* current push library palette index */
  161458. # if defined(PNG_TEXT_SUPPORTED)
  161459. png_size_t current_text_size; /* current size of text input data */
  161460. png_size_t current_text_left; /* how much text left to read in input */
  161461. png_charp current_text; /* current text chunk buffer */
  161462. png_charp current_text_ptr; /* current location in current_text */
  161463. # endif /* PNG_TEXT_SUPPORTED */
  161464. #endif /* PNG_PROGRESSIVE_READ_SUPPORTED */
  161465. #if defined(__TURBOC__) && !defined(_Windows) && !defined(__FLAT__)
  161466. png_bytepp offset_table_ptr;
  161467. png_bytep offset_table;
  161468. png_uint_16 offset_table_number;
  161469. png_uint_16 offset_table_count;
  161470. png_uint_16 offset_table_count_free;
  161471. #endif
  161472. #if defined(PNG_READ_DITHER_SUPPORTED)
  161473. png_bytep palette_lookup; /* lookup table for dithering */
  161474. png_bytep dither_index; /* index translation for palette files */
  161475. #endif
  161476. #if defined(PNG_READ_DITHER_SUPPORTED) || defined(PNG_hIST_SUPPORTED)
  161477. png_uint_16p hist; /* histogram */
  161478. #endif
  161479. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  161480. png_byte heuristic_method; /* heuristic for row filter selection */
  161481. png_byte num_prev_filters; /* number of weights for previous rows */
  161482. png_bytep prev_filters; /* filter type(s) of previous row(s) */
  161483. png_uint_16p filter_weights; /* weight(s) for previous line(s) */
  161484. png_uint_16p inv_filter_weights; /* 1/weight(s) for previous line(s) */
  161485. png_uint_16p filter_costs; /* relative filter calculation cost */
  161486. png_uint_16p inv_filter_costs; /* 1/relative filter calculation cost */
  161487. #endif
  161488. #if defined(PNG_TIME_RFC1123_SUPPORTED)
  161489. png_charp time_buffer; /* String to hold RFC 1123 time text */
  161490. #endif
  161491. #ifdef PNG_FREE_ME_SUPPORTED
  161492. png_uint_32 free_me; /* flags items libpng is responsible for freeing */
  161493. #endif
  161494. #if defined(PNG_USER_CHUNKS_SUPPORTED)
  161495. png_voidp user_chunk_ptr;
  161496. png_user_chunk_ptr read_user_chunk_fn; /* user read chunk handler */
  161497. #endif
  161498. #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
  161499. int num_chunk_list;
  161500. png_bytep chunk_list;
  161501. #endif
  161502. #if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
  161503. png_byte rgb_to_gray_status;
  161504. png_uint_16 rgb_to_gray_red_coeff;
  161505. png_uint_16 rgb_to_gray_green_coeff;
  161506. png_uint_16 rgb_to_gray_blue_coeff;
  161507. #endif
  161508. #if defined(PNG_MNG_FEATURES_SUPPORTED) || \
  161509. defined(PNG_READ_EMPTY_PLTE_SUPPORTED) || \
  161510. defined(PNG_WRITE_EMPTY_PLTE_SUPPORTED)
  161511. #ifdef PNG_1_0_X
  161512. png_byte mng_features_permitted;
  161513. #else
  161514. png_uint_32 mng_features_permitted;
  161515. #endif /* PNG_1_0_X */
  161516. #endif
  161517. #if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
  161518. png_fixed_point int_gamma;
  161519. #endif
  161520. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  161521. png_byte filter_type;
  161522. #endif
  161523. #if defined(PNG_1_0_X)
  161524. png_uint_32 row_buf_size;
  161525. #endif
  161526. #if defined(PNG_ASSEMBLER_CODE_SUPPORTED)
  161527. # if !defined(PNG_1_0_X)
  161528. # if defined(PNG_MMX_CODE_SUPPORTED)
  161529. png_byte mmx_bitdepth_threshold;
  161530. png_uint_32 mmx_rowbytes_threshold;
  161531. # endif
  161532. png_uint_32 asm_flags;
  161533. # endif
  161534. #endif
  161535. #ifdef PNG_USER_MEM_SUPPORTED
  161536. png_voidp mem_ptr; /* user supplied struct for mem functions */
  161537. png_malloc_ptr malloc_fn; /* function for allocating memory */
  161538. png_free_ptr free_fn; /* function for freeing memory */
  161539. #endif
  161540. png_bytep big_row_buf; /* buffer to save current (unfiltered) row */
  161541. #if defined(PNG_READ_DITHER_SUPPORTED)
  161542. png_bytep dither_sort; /* working sort array */
  161543. png_bytep index_to_palette; /* where the original index currently is */
  161544. png_bytep palette_to_index; /* which original index points to this */
  161545. #endif
  161546. png_byte compression_type;
  161547. #ifdef PNG_SET_USER_LIMITS_SUPPORTED
  161548. png_uint_32 user_width_max;
  161549. png_uint_32 user_height_max;
  161550. #endif
  161551. #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
  161552. png_unknown_chunk unknown_chunk;
  161553. #endif
  161554. };
  161555. typedef png_structp version_1_2_21;
  161556. typedef png_struct FAR * FAR * png_structpp;
  161557. extern PNG_EXPORT(png_uint_32,png_access_version_number) PNGARG((void));
  161558. extern PNG_EXPORT(void,png_set_sig_bytes) PNGARG((png_structp png_ptr,
  161559. int num_bytes));
  161560. extern PNG_EXPORT(int,png_sig_cmp) PNGARG((png_bytep sig, png_size_t start,
  161561. png_size_t num_to_check));
  161562. extern PNG_EXPORT(int,png_check_sig) PNGARG((png_bytep sig, int num));
  161563. extern PNG_EXPORT(png_structp,png_create_read_struct)
  161564. PNGARG((png_const_charp user_png_ver, png_voidp error_ptr,
  161565. png_error_ptr error_fn, png_error_ptr warn_fn));
  161566. extern PNG_EXPORT(png_structp,png_create_write_struct)
  161567. PNGARG((png_const_charp user_png_ver, png_voidp error_ptr,
  161568. png_error_ptr error_fn, png_error_ptr warn_fn));
  161569. #ifdef PNG_WRITE_SUPPORTED
  161570. extern PNG_EXPORT(png_uint_32,png_get_compression_buffer_size)
  161571. PNGARG((png_structp png_ptr));
  161572. #endif
  161573. #ifdef PNG_WRITE_SUPPORTED
  161574. extern PNG_EXPORT(void,png_set_compression_buffer_size)
  161575. PNGARG((png_structp png_ptr, png_uint_32 size));
  161576. #endif
  161577. extern PNG_EXPORT(int,png_reset_zstream) PNGARG((png_structp png_ptr));
  161578. #ifdef PNG_USER_MEM_SUPPORTED
  161579. extern PNG_EXPORT(png_structp,png_create_read_struct_2)
  161580. PNGARG((png_const_charp user_png_ver, png_voidp error_ptr,
  161581. png_error_ptr error_fn, png_error_ptr warn_fn, png_voidp mem_ptr,
  161582. png_malloc_ptr malloc_fn, png_free_ptr free_fn));
  161583. extern PNG_EXPORT(png_structp,png_create_write_struct_2)
  161584. PNGARG((png_const_charp user_png_ver, png_voidp error_ptr,
  161585. png_error_ptr error_fn, png_error_ptr warn_fn, png_voidp mem_ptr,
  161586. png_malloc_ptr malloc_fn, png_free_ptr free_fn));
  161587. #endif
  161588. extern PNG_EXPORT(void,png_write_chunk) PNGARG((png_structp png_ptr,
  161589. png_bytep chunk_name, png_bytep data, png_size_t length));
  161590. extern PNG_EXPORT(void,png_write_chunk_start) PNGARG((png_structp png_ptr,
  161591. png_bytep chunk_name, png_uint_32 length));
  161592. extern PNG_EXPORT(void,png_write_chunk_data) PNGARG((png_structp png_ptr,
  161593. png_bytep data, png_size_t length));
  161594. extern PNG_EXPORT(void,png_write_chunk_end) PNGARG((png_structp png_ptr));
  161595. extern PNG_EXPORT(png_infop,png_create_info_struct)
  161596. PNGARG((png_structp png_ptr));
  161597. #if defined(PNG_1_0_X) || defined (PNG_1_2_X)
  161598. extern PNG_EXPORT(void,png_info_init) PNGARG((png_infop info_ptr));
  161599. #undef png_info_init
  161600. #define png_info_init(info_ptr) png_info_init_3(&info_ptr,\
  161601. png_sizeof(png_info));
  161602. #endif
  161603. extern PNG_EXPORT(void,png_info_init_3) PNGARG((png_infopp info_ptr,
  161604. png_size_t png_info_struct_size));
  161605. extern PNG_EXPORT(void,png_write_info_before_PLTE) PNGARG((png_structp png_ptr,
  161606. png_infop info_ptr));
  161607. extern PNG_EXPORT(void,png_write_info) PNGARG((png_structp png_ptr,
  161608. png_infop info_ptr));
  161609. #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
  161610. extern PNG_EXPORT(void,png_read_info) PNGARG((png_structp png_ptr,
  161611. png_infop info_ptr));
  161612. #endif
  161613. #if defined(PNG_TIME_RFC1123_SUPPORTED)
  161614. extern PNG_EXPORT(png_charp,png_convert_to_rfc1123)
  161615. PNGARG((png_structp png_ptr, png_timep ptime));
  161616. #endif
  161617. #if !defined(_WIN32_WCE)
  161618. #if defined(PNG_WRITE_tIME_SUPPORTED)
  161619. extern PNG_EXPORT(void,png_convert_from_struct_tm) PNGARG((png_timep ptime,
  161620. struct tm FAR * ttime));
  161621. extern PNG_EXPORT(void,png_convert_from_time_t) PNGARG((png_timep ptime,
  161622. time_t ttime));
  161623. #endif /* PNG_WRITE_tIME_SUPPORTED */
  161624. #endif /* _WIN32_WCE */
  161625. #if defined(PNG_READ_EXPAND_SUPPORTED)
  161626. extern PNG_EXPORT(void,png_set_expand) PNGARG((png_structp png_ptr));
  161627. #if !defined(PNG_1_0_X)
  161628. extern PNG_EXPORT(void,png_set_expand_gray_1_2_4_to_8) PNGARG((png_structp
  161629. png_ptr));
  161630. #endif
  161631. extern PNG_EXPORT(void,png_set_palette_to_rgb) PNGARG((png_structp png_ptr));
  161632. extern PNG_EXPORT(void,png_set_tRNS_to_alpha) PNGARG((png_structp png_ptr));
  161633. #if defined(PNG_1_0_X) || defined (PNG_1_2_X)
  161634. extern PNG_EXPORT(void,png_set_gray_1_2_4_to_8) PNGARG((png_structp png_ptr));
  161635. #endif
  161636. #endif
  161637. #if defined(PNG_READ_BGR_SUPPORTED) || defined(PNG_WRITE_BGR_SUPPORTED)
  161638. extern PNG_EXPORT(void,png_set_bgr) PNGARG((png_structp png_ptr));
  161639. #endif
  161640. #if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED)
  161641. extern PNG_EXPORT(void,png_set_gray_to_rgb) PNGARG((png_structp png_ptr));
  161642. #endif
  161643. #if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
  161644. #ifdef PNG_FLOATING_POINT_SUPPORTED
  161645. extern PNG_EXPORT(void,png_set_rgb_to_gray) PNGARG((png_structp png_ptr,
  161646. int error_action, double red, double green ));
  161647. #endif
  161648. extern PNG_EXPORT(void,png_set_rgb_to_gray_fixed) PNGARG((png_structp png_ptr,
  161649. int error_action, png_fixed_point red, png_fixed_point green ));
  161650. extern PNG_EXPORT(png_byte,png_get_rgb_to_gray_status) PNGARG((png_structp
  161651. png_ptr));
  161652. #endif
  161653. extern PNG_EXPORT(void,png_build_grayscale_palette) PNGARG((int bit_depth,
  161654. png_colorp palette));
  161655. #if defined(PNG_READ_STRIP_ALPHA_SUPPORTED)
  161656. extern PNG_EXPORT(void,png_set_strip_alpha) PNGARG((png_structp png_ptr));
  161657. #endif
  161658. #if defined(PNG_READ_SWAP_ALPHA_SUPPORTED) || \
  161659. defined(PNG_WRITE_SWAP_ALPHA_SUPPORTED)
  161660. extern PNG_EXPORT(void,png_set_swap_alpha) PNGARG((png_structp png_ptr));
  161661. #endif
  161662. #if defined(PNG_READ_INVERT_ALPHA_SUPPORTED) || \
  161663. defined(PNG_WRITE_INVERT_ALPHA_SUPPORTED)
  161664. extern PNG_EXPORT(void,png_set_invert_alpha) PNGARG((png_structp png_ptr));
  161665. #endif
  161666. #if defined(PNG_READ_FILLER_SUPPORTED) || defined(PNG_WRITE_FILLER_SUPPORTED)
  161667. extern PNG_EXPORT(void,png_set_filler) PNGARG((png_structp png_ptr,
  161668. png_uint_32 filler, int flags));
  161669. #define PNG_FILLER_BEFORE 0
  161670. #define PNG_FILLER_AFTER 1
  161671. #if !defined(PNG_1_0_X)
  161672. extern PNG_EXPORT(void,png_set_add_alpha) PNGARG((png_structp png_ptr,
  161673. png_uint_32 filler, int flags));
  161674. #endif
  161675. #endif /* PNG_READ_FILLER_SUPPORTED || PNG_WRITE_FILLER_SUPPORTED */
  161676. #if defined(PNG_READ_SWAP_SUPPORTED) || defined(PNG_WRITE_SWAP_SUPPORTED)
  161677. extern PNG_EXPORT(void,png_set_swap) PNGARG((png_structp png_ptr));
  161678. #endif
  161679. #if defined(PNG_READ_PACK_SUPPORTED) || defined(PNG_WRITE_PACK_SUPPORTED)
  161680. extern PNG_EXPORT(void,png_set_packing) PNGARG((png_structp png_ptr));
  161681. #endif
  161682. #if defined(PNG_READ_PACKSWAP_SUPPORTED) || defined(PNG_WRITE_PACKSWAP_SUPPORTED)
  161683. extern PNG_EXPORT(void,png_set_packswap) PNGARG((png_structp png_ptr));
  161684. #endif
  161685. #if defined(PNG_READ_SHIFT_SUPPORTED) || defined(PNG_WRITE_SHIFT_SUPPORTED)
  161686. extern PNG_EXPORT(void,png_set_shift) PNGARG((png_structp png_ptr,
  161687. png_color_8p true_bits));
  161688. #endif
  161689. #if defined(PNG_READ_INTERLACING_SUPPORTED) || \
  161690. defined(PNG_WRITE_INTERLACING_SUPPORTED)
  161691. extern PNG_EXPORT(int,png_set_interlace_handling) PNGARG((png_structp png_ptr));
  161692. #endif
  161693. #if defined(PNG_READ_INVERT_SUPPORTED) || defined(PNG_WRITE_INVERT_SUPPORTED)
  161694. extern PNG_EXPORT(void,png_set_invert_mono) PNGARG((png_structp png_ptr));
  161695. #endif
  161696. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  161697. #ifdef PNG_FLOATING_POINT_SUPPORTED
  161698. extern PNG_EXPORT(void,png_set_background) PNGARG((png_structp png_ptr,
  161699. png_color_16p background_color, int background_gamma_code,
  161700. int need_expand, double background_gamma));
  161701. #endif
  161702. #define PNG_BACKGROUND_GAMMA_UNKNOWN 0
  161703. #define PNG_BACKGROUND_GAMMA_SCREEN 1
  161704. #define PNG_BACKGROUND_GAMMA_FILE 2
  161705. #define PNG_BACKGROUND_GAMMA_UNIQUE 3
  161706. #endif
  161707. #if defined(PNG_READ_16_TO_8_SUPPORTED)
  161708. extern PNG_EXPORT(void,png_set_strip_16) PNGARG((png_structp png_ptr));
  161709. #endif
  161710. #if defined(PNG_READ_DITHER_SUPPORTED)
  161711. extern PNG_EXPORT(void,png_set_dither) PNGARG((png_structp png_ptr,
  161712. png_colorp palette, int num_palette, int maximum_colors,
  161713. png_uint_16p histogram, int full_dither));
  161714. #endif
  161715. #if defined(PNG_READ_GAMMA_SUPPORTED)
  161716. #ifdef PNG_FLOATING_POINT_SUPPORTED
  161717. extern PNG_EXPORT(void,png_set_gamma) PNGARG((png_structp png_ptr,
  161718. double screen_gamma, double default_file_gamma));
  161719. #endif
  161720. #endif
  161721. #if defined(PNG_1_0_X) || defined (PNG_1_2_X)
  161722. #if defined(PNG_READ_EMPTY_PLTE_SUPPORTED) || \
  161723. defined(PNG_WRITE_EMPTY_PLTE_SUPPORTED)
  161724. extern PNG_EXPORT(void,png_permit_empty_plte) PNGARG((png_structp png_ptr,
  161725. int empty_plte_permitted));
  161726. #endif
  161727. #endif
  161728. #if defined(PNG_WRITE_FLUSH_SUPPORTED)
  161729. extern PNG_EXPORT(void,png_set_flush) PNGARG((png_structp png_ptr, int nrows));
  161730. extern PNG_EXPORT(void,png_write_flush) PNGARG((png_structp png_ptr));
  161731. #endif
  161732. extern PNG_EXPORT(void,png_start_read_image) PNGARG((png_structp png_ptr));
  161733. extern PNG_EXPORT(void,png_read_update_info) PNGARG((png_structp png_ptr,
  161734. png_infop info_ptr));
  161735. #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
  161736. extern PNG_EXPORT(void,png_read_rows) PNGARG((png_structp png_ptr,
  161737. png_bytepp row, png_bytepp display_row, png_uint_32 num_rows));
  161738. #endif
  161739. #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
  161740. extern PNG_EXPORT(void,png_read_row) PNGARG((png_structp png_ptr,
  161741. png_bytep row,
  161742. png_bytep display_row));
  161743. #endif
  161744. #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
  161745. extern PNG_EXPORT(void,png_read_image) PNGARG((png_structp png_ptr,
  161746. png_bytepp image));
  161747. #endif
  161748. extern PNG_EXPORT(void,png_write_row) PNGARG((png_structp png_ptr,
  161749. png_bytep row));
  161750. extern PNG_EXPORT(void,png_write_rows) PNGARG((png_structp png_ptr,
  161751. png_bytepp row, png_uint_32 num_rows));
  161752. extern PNG_EXPORT(void,png_write_image) PNGARG((png_structp png_ptr,
  161753. png_bytepp image));
  161754. extern PNG_EXPORT(void,png_write_end) PNGARG((png_structp png_ptr,
  161755. png_infop info_ptr));
  161756. #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
  161757. extern PNG_EXPORT(void,png_read_end) PNGARG((png_structp png_ptr,
  161758. png_infop info_ptr));
  161759. #endif
  161760. extern PNG_EXPORT(void,png_destroy_info_struct) PNGARG((png_structp png_ptr,
  161761. png_infopp info_ptr_ptr));
  161762. extern PNG_EXPORT(void,png_destroy_read_struct) PNGARG((png_structpp
  161763. png_ptr_ptr, png_infopp info_ptr_ptr, png_infopp end_info_ptr_ptr));
  161764. extern void png_read_destroy PNGARG((png_structp png_ptr, png_infop info_ptr,
  161765. png_infop end_info_ptr));
  161766. extern PNG_EXPORT(void,png_destroy_write_struct)
  161767. PNGARG((png_structpp png_ptr_ptr, png_infopp info_ptr_ptr));
  161768. extern void png_write_destroy PNGARG((png_structp png_ptr));
  161769. extern PNG_EXPORT(void,png_set_crc_action) PNGARG((png_structp png_ptr,
  161770. int crit_action, int ancil_action));
  161771. #define PNG_CRC_DEFAULT 0 /* error/quit warn/discard data */
  161772. #define PNG_CRC_ERROR_QUIT 1 /* error/quit error/quit */
  161773. #define PNG_CRC_WARN_DISCARD 2 /* (INVALID) warn/discard data */
  161774. #define PNG_CRC_WARN_USE 3 /* warn/use data warn/use data */
  161775. #define PNG_CRC_QUIET_USE 4 /* quiet/use data quiet/use data */
  161776. #define PNG_CRC_NO_CHANGE 5 /* use current value use current value */
  161777. extern PNG_EXPORT(void,png_set_filter) PNGARG((png_structp png_ptr, int method,
  161778. int filters));
  161779. #define PNG_NO_FILTERS 0x00
  161780. #define PNG_FILTER_NONE 0x08
  161781. #define PNG_FILTER_SUB 0x10
  161782. #define PNG_FILTER_UP 0x20
  161783. #define PNG_FILTER_AVG 0x40
  161784. #define PNG_FILTER_PAETH 0x80
  161785. #define PNG_ALL_FILTERS (PNG_FILTER_NONE | PNG_FILTER_SUB | PNG_FILTER_UP | \
  161786. PNG_FILTER_AVG | PNG_FILTER_PAETH)
  161787. #define PNG_FILTER_VALUE_NONE 0
  161788. #define PNG_FILTER_VALUE_SUB 1
  161789. #define PNG_FILTER_VALUE_UP 2
  161790. #define PNG_FILTER_VALUE_AVG 3
  161791. #define PNG_FILTER_VALUE_PAETH 4
  161792. #define PNG_FILTER_VALUE_LAST 5
  161793. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED) /* EXPERIMENTAL */
  161794. #ifdef PNG_FLOATING_POINT_SUPPORTED
  161795. extern PNG_EXPORT(void,png_set_filter_heuristics) PNGARG((png_structp png_ptr,
  161796. int heuristic_method, int num_weights, png_doublep filter_weights,
  161797. png_doublep filter_costs));
  161798. #endif
  161799. #endif /* PNG_WRITE_WEIGHTED_FILTER_SUPPORTED */
  161800. #define PNG_FILTER_HEURISTIC_DEFAULT 0 /* Currently "UNWEIGHTED" */
  161801. #define PNG_FILTER_HEURISTIC_UNWEIGHTED 1 /* Used by libpng < 0.95 */
  161802. #define PNG_FILTER_HEURISTIC_WEIGHTED 2 /* Experimental feature */
  161803. #define PNG_FILTER_HEURISTIC_LAST 3 /* Not a valid value */
  161804. extern PNG_EXPORT(void,png_set_compression_level) PNGARG((png_structp png_ptr,
  161805. int level));
  161806. extern PNG_EXPORT(void,png_set_compression_mem_level)
  161807. PNGARG((png_structp png_ptr, int mem_level));
  161808. extern PNG_EXPORT(void,png_set_compression_strategy)
  161809. PNGARG((png_structp png_ptr, int strategy));
  161810. extern PNG_EXPORT(void,png_set_compression_window_bits)
  161811. PNGARG((png_structp png_ptr, int window_bits));
  161812. extern PNG_EXPORT(void,png_set_compression_method) PNGARG((png_structp png_ptr,
  161813. int method));
  161814. #if !defined(PNG_NO_STDIO)
  161815. extern PNG_EXPORT(void,png_init_io) PNGARG((png_structp png_ptr, png_FILE_p fp));
  161816. #endif
  161817. extern PNG_EXPORT(void,png_set_error_fn) PNGARG((png_structp png_ptr,
  161818. png_voidp error_ptr, png_error_ptr error_fn, png_error_ptr warning_fn));
  161819. extern PNG_EXPORT(png_voidp,png_get_error_ptr) PNGARG((png_structp png_ptr));
  161820. extern PNG_EXPORT(void,png_set_write_fn) PNGARG((png_structp png_ptr,
  161821. png_voidp io_ptr, png_rw_ptr write_data_fn, png_flush_ptr output_flush_fn));
  161822. extern PNG_EXPORT(void,png_set_read_fn) PNGARG((png_structp png_ptr,
  161823. png_voidp io_ptr, png_rw_ptr read_data_fn));
  161824. extern PNG_EXPORT(png_voidp,png_get_io_ptr) PNGARG((png_structp png_ptr));
  161825. extern PNG_EXPORT(void,png_set_read_status_fn) PNGARG((png_structp png_ptr,
  161826. png_read_status_ptr read_row_fn));
  161827. extern PNG_EXPORT(void,png_set_write_status_fn) PNGARG((png_structp png_ptr,
  161828. png_write_status_ptr write_row_fn));
  161829. #ifdef PNG_USER_MEM_SUPPORTED
  161830. extern PNG_EXPORT(void,png_set_mem_fn) PNGARG((png_structp png_ptr,
  161831. png_voidp mem_ptr, png_malloc_ptr malloc_fn, png_free_ptr free_fn));
  161832. extern PNG_EXPORT(png_voidp,png_get_mem_ptr) PNGARG((png_structp png_ptr));
  161833. #endif
  161834. #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \
  161835. defined(PNG_LEGACY_SUPPORTED)
  161836. extern PNG_EXPORT(void,png_set_read_user_transform_fn) PNGARG((png_structp
  161837. png_ptr, png_user_transform_ptr read_user_transform_fn));
  161838. #endif
  161839. #if defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED) || \
  161840. defined(PNG_LEGACY_SUPPORTED)
  161841. extern PNG_EXPORT(void,png_set_write_user_transform_fn) PNGARG((png_structp
  161842. png_ptr, png_user_transform_ptr write_user_transform_fn));
  161843. #endif
  161844. #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \
  161845. defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED) || \
  161846. defined(PNG_LEGACY_SUPPORTED)
  161847. extern PNG_EXPORT(void,png_set_user_transform_info) PNGARG((png_structp
  161848. png_ptr, png_voidp user_transform_ptr, int user_transform_depth,
  161849. int user_transform_channels));
  161850. extern PNG_EXPORT(png_voidp,png_get_user_transform_ptr)
  161851. PNGARG((png_structp png_ptr));
  161852. #endif
  161853. #ifdef PNG_USER_CHUNKS_SUPPORTED
  161854. extern PNG_EXPORT(void,png_set_read_user_chunk_fn) PNGARG((png_structp png_ptr,
  161855. png_voidp user_chunk_ptr, png_user_chunk_ptr read_user_chunk_fn));
  161856. extern PNG_EXPORT(png_voidp,png_get_user_chunk_ptr) PNGARG((png_structp
  161857. png_ptr));
  161858. #endif
  161859. #ifdef PNG_PROGRESSIVE_READ_SUPPORTED
  161860. extern PNG_EXPORT(void,png_set_progressive_read_fn) PNGARG((png_structp png_ptr,
  161861. png_voidp progressive_ptr,
  161862. png_progressive_info_ptr info_fn, png_progressive_row_ptr row_fn,
  161863. png_progressive_end_ptr end_fn));
  161864. extern PNG_EXPORT(png_voidp,png_get_progressive_ptr)
  161865. PNGARG((png_structp png_ptr));
  161866. extern PNG_EXPORT(void,png_process_data) PNGARG((png_structp png_ptr,
  161867. png_infop info_ptr, png_bytep buffer, png_size_t buffer_size));
  161868. extern PNG_EXPORT(void,png_progressive_combine_row) PNGARG((png_structp png_ptr,
  161869. png_bytep old_row, png_bytep new_row));
  161870. #endif /* PNG_PROGRESSIVE_READ_SUPPORTED */
  161871. extern PNG_EXPORT(png_voidp,png_malloc) PNGARG((png_structp png_ptr,
  161872. png_uint_32 size));
  161873. #if defined(PNG_1_0_X)
  161874. # define png_malloc_warn png_malloc
  161875. #else
  161876. extern PNG_EXPORT(png_voidp,png_malloc_warn) PNGARG((png_structp png_ptr,
  161877. png_uint_32 size));
  161878. #endif
  161879. extern PNG_EXPORT(void,png_free) PNGARG((png_structp png_ptr, png_voidp ptr));
  161880. #if defined(PNG_1_0_X)
  161881. extern PNG_EXPORT(voidpf,png_zalloc) PNGARG((voidpf png_ptr, uInt items,
  161882. uInt size));
  161883. extern PNG_EXPORT(void,png_zfree) PNGARG((voidpf png_ptr, voidpf ptr));
  161884. #endif
  161885. extern PNG_EXPORT(void,png_free_data) PNGARG((png_structp png_ptr,
  161886. png_infop info_ptr, png_uint_32 free_me, int num));
  161887. #ifdef PNG_FREE_ME_SUPPORTED
  161888. extern PNG_EXPORT(void,png_data_freer) PNGARG((png_structp png_ptr,
  161889. png_infop info_ptr, int freer, png_uint_32 mask));
  161890. #endif
  161891. #define PNG_DESTROY_WILL_FREE_DATA 1
  161892. #define PNG_SET_WILL_FREE_DATA 1
  161893. #define PNG_USER_WILL_FREE_DATA 2
  161894. #define PNG_FREE_HIST 0x0008
  161895. #define PNG_FREE_ICCP 0x0010
  161896. #define PNG_FREE_SPLT 0x0020
  161897. #define PNG_FREE_ROWS 0x0040
  161898. #define PNG_FREE_PCAL 0x0080
  161899. #define PNG_FREE_SCAL 0x0100
  161900. #define PNG_FREE_UNKN 0x0200
  161901. #define PNG_FREE_LIST 0x0400
  161902. #define PNG_FREE_PLTE 0x1000
  161903. #define PNG_FREE_TRNS 0x2000
  161904. #define PNG_FREE_TEXT 0x4000
  161905. #define PNG_FREE_ALL 0x7fff
  161906. #define PNG_FREE_MUL 0x4220 /* PNG_FREE_SPLT|PNG_FREE_TEXT|PNG_FREE_UNKN */
  161907. #ifdef PNG_USER_MEM_SUPPORTED
  161908. extern PNG_EXPORT(png_voidp,png_malloc_default) PNGARG((png_structp png_ptr,
  161909. png_uint_32 size));
  161910. extern PNG_EXPORT(void,png_free_default) PNGARG((png_structp png_ptr,
  161911. png_voidp ptr));
  161912. #endif
  161913. extern PNG_EXPORT(png_voidp,png_memcpy_check) PNGARG((png_structp png_ptr,
  161914. png_voidp s1, png_voidp s2, png_uint_32 size));
  161915. extern PNG_EXPORT(png_voidp,png_memset_check) PNGARG((png_structp png_ptr,
  161916. png_voidp s1, int value, png_uint_32 size));
  161917. #if defined(USE_FAR_KEYWORD) /* memory model conversion function */
  161918. extern void *png_far_to_near PNGARG((png_structp png_ptr,png_voidp ptr,
  161919. int check));
  161920. #endif /* USE_FAR_KEYWORD */
  161921. #ifndef PNG_NO_ERROR_TEXT
  161922. extern PNG_EXPORT(void,png_error) PNGARG((png_structp png_ptr,
  161923. png_const_charp error_message));
  161924. extern PNG_EXPORT(void,png_chunk_error) PNGARG((png_structp png_ptr,
  161925. png_const_charp error_message));
  161926. #else
  161927. extern PNG_EXPORT(void,png_err) PNGARG((png_structp png_ptr));
  161928. #endif
  161929. #ifndef PNG_NO_WARNINGS
  161930. extern PNG_EXPORT(void,png_warning) PNGARG((png_structp png_ptr,
  161931. png_const_charp warning_message));
  161932. #ifdef PNG_READ_SUPPORTED
  161933. extern PNG_EXPORT(void,png_chunk_warning) PNGARG((png_structp png_ptr,
  161934. png_const_charp warning_message));
  161935. #endif /* PNG_READ_SUPPORTED */
  161936. #endif /* PNG_NO_WARNINGS */
  161937. extern PNG_EXPORT(png_uint_32,png_get_valid) PNGARG((png_structp png_ptr,
  161938. png_infop info_ptr, png_uint_32 flag));
  161939. extern PNG_EXPORT(png_uint_32,png_get_rowbytes) PNGARG((png_structp png_ptr,
  161940. png_infop info_ptr));
  161941. #if defined(PNG_INFO_IMAGE_SUPPORTED)
  161942. extern PNG_EXPORT(png_bytepp,png_get_rows) PNGARG((png_structp png_ptr,
  161943. png_infop info_ptr));
  161944. extern PNG_EXPORT(void,png_set_rows) PNGARG((png_structp png_ptr,
  161945. png_infop info_ptr, png_bytepp row_pointers));
  161946. #endif
  161947. extern PNG_EXPORT(png_byte,png_get_channels) PNGARG((png_structp png_ptr,
  161948. png_infop info_ptr));
  161949. #ifdef PNG_EASY_ACCESS_SUPPORTED
  161950. extern PNG_EXPORT(png_uint_32, png_get_image_width) PNGARG((png_structp
  161951. png_ptr, png_infop info_ptr));
  161952. extern PNG_EXPORT(png_uint_32, png_get_image_height) PNGARG((png_structp
  161953. png_ptr, png_infop info_ptr));
  161954. extern PNG_EXPORT(png_byte, png_get_bit_depth) PNGARG((png_structp
  161955. png_ptr, png_infop info_ptr));
  161956. extern PNG_EXPORT(png_byte, png_get_color_type) PNGARG((png_structp
  161957. png_ptr, png_infop info_ptr));
  161958. extern PNG_EXPORT(png_byte, png_get_filter_type) PNGARG((png_structp
  161959. png_ptr, png_infop info_ptr));
  161960. extern PNG_EXPORT(png_byte, png_get_interlace_type) PNGARG((png_structp
  161961. png_ptr, png_infop info_ptr));
  161962. extern PNG_EXPORT(png_byte, png_get_compression_type) PNGARG((png_structp
  161963. png_ptr, png_infop info_ptr));
  161964. extern PNG_EXPORT(png_uint_32, png_get_pixels_per_meter) PNGARG((png_structp
  161965. png_ptr, png_infop info_ptr));
  161966. extern PNG_EXPORT(png_uint_32, png_get_x_pixels_per_meter) PNGARG((png_structp
  161967. png_ptr, png_infop info_ptr));
  161968. extern PNG_EXPORT(png_uint_32, png_get_y_pixels_per_meter) PNGARG((png_structp
  161969. png_ptr, png_infop info_ptr));
  161970. #ifdef PNG_FLOATING_POINT_SUPPORTED
  161971. extern PNG_EXPORT(float, png_get_pixel_aspect_ratio) PNGARG((png_structp
  161972. png_ptr, png_infop info_ptr));
  161973. #endif
  161974. extern PNG_EXPORT(png_int_32, png_get_x_offset_pixels) PNGARG((png_structp
  161975. png_ptr, png_infop info_ptr));
  161976. extern PNG_EXPORT(png_int_32, png_get_y_offset_pixels) PNGARG((png_structp
  161977. png_ptr, png_infop info_ptr));
  161978. extern PNG_EXPORT(png_int_32, png_get_x_offset_microns) PNGARG((png_structp
  161979. png_ptr, png_infop info_ptr));
  161980. extern PNG_EXPORT(png_int_32, png_get_y_offset_microns) PNGARG((png_structp
  161981. png_ptr, png_infop info_ptr));
  161982. #endif /* PNG_EASY_ACCESS_SUPPORTED */
  161983. extern PNG_EXPORT(png_bytep,png_get_signature) PNGARG((png_structp png_ptr,
  161984. png_infop info_ptr));
  161985. #if defined(PNG_bKGD_SUPPORTED)
  161986. extern PNG_EXPORT(png_uint_32,png_get_bKGD) PNGARG((png_structp png_ptr,
  161987. png_infop info_ptr, png_color_16p *background));
  161988. #endif
  161989. #if defined(PNG_bKGD_SUPPORTED)
  161990. extern PNG_EXPORT(void,png_set_bKGD) PNGARG((png_structp png_ptr,
  161991. png_infop info_ptr, png_color_16p background));
  161992. #endif
  161993. #if defined(PNG_cHRM_SUPPORTED)
  161994. #ifdef PNG_FLOATING_POINT_SUPPORTED
  161995. extern PNG_EXPORT(png_uint_32,png_get_cHRM) PNGARG((png_structp png_ptr,
  161996. png_infop info_ptr, double *white_x, double *white_y, double *red_x,
  161997. double *red_y, double *green_x, double *green_y, double *blue_x,
  161998. double *blue_y));
  161999. #endif
  162000. #ifdef PNG_FIXED_POINT_SUPPORTED
  162001. extern PNG_EXPORT(png_uint_32,png_get_cHRM_fixed) PNGARG((png_structp png_ptr,
  162002. png_infop info_ptr, png_fixed_point *int_white_x, png_fixed_point
  162003. *int_white_y, png_fixed_point *int_red_x, png_fixed_point *int_red_y,
  162004. png_fixed_point *int_green_x, png_fixed_point *int_green_y, png_fixed_point
  162005. *int_blue_x, png_fixed_point *int_blue_y));
  162006. #endif
  162007. #endif
  162008. #if defined(PNG_cHRM_SUPPORTED)
  162009. #ifdef PNG_FLOATING_POINT_SUPPORTED
  162010. extern PNG_EXPORT(void,png_set_cHRM) PNGARG((png_structp png_ptr,
  162011. png_infop info_ptr, double white_x, double white_y, double red_x,
  162012. double red_y, double green_x, double green_y, double blue_x, double blue_y));
  162013. #endif
  162014. #ifdef PNG_FIXED_POINT_SUPPORTED
  162015. extern PNG_EXPORT(void,png_set_cHRM_fixed) PNGARG((png_structp png_ptr,
  162016. png_infop info_ptr, png_fixed_point int_white_x, png_fixed_point int_white_y,
  162017. png_fixed_point int_red_x, png_fixed_point int_red_y, png_fixed_point
  162018. int_green_x, png_fixed_point int_green_y, png_fixed_point int_blue_x,
  162019. png_fixed_point int_blue_y));
  162020. #endif
  162021. #endif
  162022. #if defined(PNG_gAMA_SUPPORTED)
  162023. #ifdef PNG_FLOATING_POINT_SUPPORTED
  162024. extern PNG_EXPORT(png_uint_32,png_get_gAMA) PNGARG((png_structp png_ptr,
  162025. png_infop info_ptr, double *file_gamma));
  162026. #endif
  162027. extern PNG_EXPORT(png_uint_32,png_get_gAMA_fixed) PNGARG((png_structp png_ptr,
  162028. png_infop info_ptr, png_fixed_point *int_file_gamma));
  162029. #endif
  162030. #if defined(PNG_gAMA_SUPPORTED)
  162031. #ifdef PNG_FLOATING_POINT_SUPPORTED
  162032. extern PNG_EXPORT(void,png_set_gAMA) PNGARG((png_structp png_ptr,
  162033. png_infop info_ptr, double file_gamma));
  162034. #endif
  162035. extern PNG_EXPORT(void,png_set_gAMA_fixed) PNGARG((png_structp png_ptr,
  162036. png_infop info_ptr, png_fixed_point int_file_gamma));
  162037. #endif
  162038. #if defined(PNG_hIST_SUPPORTED)
  162039. extern PNG_EXPORT(png_uint_32,png_get_hIST) PNGARG((png_structp png_ptr,
  162040. png_infop info_ptr, png_uint_16p *hist));
  162041. #endif
  162042. #if defined(PNG_hIST_SUPPORTED)
  162043. extern PNG_EXPORT(void,png_set_hIST) PNGARG((png_structp png_ptr,
  162044. png_infop info_ptr, png_uint_16p hist));
  162045. #endif
  162046. extern PNG_EXPORT(png_uint_32,png_get_IHDR) PNGARG((png_structp png_ptr,
  162047. png_infop info_ptr, png_uint_32 *width, png_uint_32 *height,
  162048. int *bit_depth, int *color_type, int *interlace_method,
  162049. int *compression_method, int *filter_method));
  162050. extern PNG_EXPORT(void,png_set_IHDR) PNGARG((png_structp png_ptr,
  162051. png_infop info_ptr, png_uint_32 width, png_uint_32 height, int bit_depth,
  162052. int color_type, int interlace_method, int compression_method,
  162053. int filter_method));
  162054. #if defined(PNG_oFFs_SUPPORTED)
  162055. extern PNG_EXPORT(png_uint_32,png_get_oFFs) PNGARG((png_structp png_ptr,
  162056. png_infop info_ptr, png_int_32 *offset_x, png_int_32 *offset_y,
  162057. int *unit_type));
  162058. #endif
  162059. #if defined(PNG_oFFs_SUPPORTED)
  162060. extern PNG_EXPORT(void,png_set_oFFs) PNGARG((png_structp png_ptr,
  162061. png_infop info_ptr, png_int_32 offset_x, png_int_32 offset_y,
  162062. int unit_type));
  162063. #endif
  162064. #if defined(PNG_pCAL_SUPPORTED)
  162065. extern PNG_EXPORT(png_uint_32,png_get_pCAL) PNGARG((png_structp png_ptr,
  162066. png_infop info_ptr, png_charp *purpose, png_int_32 *X0, png_int_32 *X1,
  162067. int *type, int *nparams, png_charp *units, png_charpp *params));
  162068. #endif
  162069. #if defined(PNG_pCAL_SUPPORTED)
  162070. extern PNG_EXPORT(void,png_set_pCAL) PNGARG((png_structp png_ptr,
  162071. png_infop info_ptr, png_charp purpose, png_int_32 X0, png_int_32 X1,
  162072. int type, int nparams, png_charp units, png_charpp params));
  162073. #endif
  162074. #if defined(PNG_pHYs_SUPPORTED)
  162075. extern PNG_EXPORT(png_uint_32,png_get_pHYs) PNGARG((png_structp png_ptr,
  162076. png_infop info_ptr, png_uint_32 *res_x, png_uint_32 *res_y, int *unit_type));
  162077. #endif
  162078. #if defined(PNG_pHYs_SUPPORTED)
  162079. extern PNG_EXPORT(void,png_set_pHYs) PNGARG((png_structp png_ptr,
  162080. png_infop info_ptr, png_uint_32 res_x, png_uint_32 res_y, int unit_type));
  162081. #endif
  162082. extern PNG_EXPORT(png_uint_32,png_get_PLTE) PNGARG((png_structp png_ptr,
  162083. png_infop info_ptr, png_colorp *palette, int *num_palette));
  162084. extern PNG_EXPORT(void,png_set_PLTE) PNGARG((png_structp png_ptr,
  162085. png_infop info_ptr, png_colorp palette, int num_palette));
  162086. #if defined(PNG_sBIT_SUPPORTED)
  162087. extern PNG_EXPORT(png_uint_32,png_get_sBIT) PNGARG((png_structp png_ptr,
  162088. png_infop info_ptr, png_color_8p *sig_bit));
  162089. #endif
  162090. #if defined(PNG_sBIT_SUPPORTED)
  162091. extern PNG_EXPORT(void,png_set_sBIT) PNGARG((png_structp png_ptr,
  162092. png_infop info_ptr, png_color_8p sig_bit));
  162093. #endif
  162094. #if defined(PNG_sRGB_SUPPORTED)
  162095. extern PNG_EXPORT(png_uint_32,png_get_sRGB) PNGARG((png_structp png_ptr,
  162096. png_infop info_ptr, int *intent));
  162097. #endif
  162098. #if defined(PNG_sRGB_SUPPORTED)
  162099. extern PNG_EXPORT(void,png_set_sRGB) PNGARG((png_structp png_ptr,
  162100. png_infop info_ptr, int intent));
  162101. extern PNG_EXPORT(void,png_set_sRGB_gAMA_and_cHRM) PNGARG((png_structp png_ptr,
  162102. png_infop info_ptr, int intent));
  162103. #endif
  162104. #if defined(PNG_iCCP_SUPPORTED)
  162105. extern PNG_EXPORT(png_uint_32,png_get_iCCP) PNGARG((png_structp png_ptr,
  162106. png_infop info_ptr, png_charpp name, int *compression_type,
  162107. png_charpp profile, png_uint_32 *proflen));
  162108. #endif
  162109. #if defined(PNG_iCCP_SUPPORTED)
  162110. extern PNG_EXPORT(void,png_set_iCCP) PNGARG((png_structp png_ptr,
  162111. png_infop info_ptr, png_charp name, int compression_type,
  162112. png_charp profile, png_uint_32 proflen));
  162113. #endif
  162114. #if defined(PNG_sPLT_SUPPORTED)
  162115. extern PNG_EXPORT(png_uint_32,png_get_sPLT) PNGARG((png_structp png_ptr,
  162116. png_infop info_ptr, png_sPLT_tpp entries));
  162117. #endif
  162118. #if defined(PNG_sPLT_SUPPORTED)
  162119. extern PNG_EXPORT(void,png_set_sPLT) PNGARG((png_structp png_ptr,
  162120. png_infop info_ptr, png_sPLT_tp entries, int nentries));
  162121. #endif
  162122. #if defined(PNG_TEXT_SUPPORTED)
  162123. extern PNG_EXPORT(png_uint_32,png_get_text) PNGARG((png_structp png_ptr,
  162124. png_infop info_ptr, png_textp *text_ptr, int *num_text));
  162125. #endif
  162126. #if defined(PNG_TEXT_SUPPORTED)
  162127. extern PNG_EXPORT(void,png_set_text) PNGARG((png_structp png_ptr,
  162128. png_infop info_ptr, png_textp text_ptr, int num_text));
  162129. #endif
  162130. #if defined(PNG_tIME_SUPPORTED)
  162131. extern PNG_EXPORT(png_uint_32,png_get_tIME) PNGARG((png_structp png_ptr,
  162132. png_infop info_ptr, png_timep *mod_time));
  162133. #endif
  162134. #if defined(PNG_tIME_SUPPORTED)
  162135. extern PNG_EXPORT(void,png_set_tIME) PNGARG((png_structp png_ptr,
  162136. png_infop info_ptr, png_timep mod_time));
  162137. #endif
  162138. #if defined(PNG_tRNS_SUPPORTED)
  162139. extern PNG_EXPORT(png_uint_32,png_get_tRNS) PNGARG((png_structp png_ptr,
  162140. png_infop info_ptr, png_bytep *trans, int *num_trans,
  162141. png_color_16p *trans_values));
  162142. #endif
  162143. #if defined(PNG_tRNS_SUPPORTED)
  162144. extern PNG_EXPORT(void,png_set_tRNS) PNGARG((png_structp png_ptr,
  162145. png_infop info_ptr, png_bytep trans, int num_trans,
  162146. png_color_16p trans_values));
  162147. #endif
  162148. #if defined(PNG_tRNS_SUPPORTED)
  162149. #endif
  162150. #if defined(PNG_sCAL_SUPPORTED)
  162151. #ifdef PNG_FLOATING_POINT_SUPPORTED
  162152. extern PNG_EXPORT(png_uint_32,png_get_sCAL) PNGARG((png_structp png_ptr,
  162153. png_infop info_ptr, int *unit, double *width, double *height));
  162154. #else
  162155. #ifdef PNG_FIXED_POINT_SUPPORTED
  162156. extern PNG_EXPORT(png_uint_32,png_get_sCAL_s) PNGARG((png_structp png_ptr,
  162157. png_infop info_ptr, int *unit, png_charpp swidth, png_charpp sheight));
  162158. #endif
  162159. #endif
  162160. #endif /* PNG_sCAL_SUPPORTED */
  162161. #if defined(PNG_sCAL_SUPPORTED)
  162162. #ifdef PNG_FLOATING_POINT_SUPPORTED
  162163. extern PNG_EXPORT(void,png_set_sCAL) PNGARG((png_structp png_ptr,
  162164. png_infop info_ptr, int unit, double width, double height));
  162165. #else
  162166. #ifdef PNG_FIXED_POINT_SUPPORTED
  162167. extern PNG_EXPORT(void,png_set_sCAL_s) PNGARG((png_structp png_ptr,
  162168. png_infop info_ptr, int unit, png_charp swidth, png_charp sheight));
  162169. #endif
  162170. #endif
  162171. #endif /* PNG_sCAL_SUPPORTED || PNG_WRITE_sCAL_SUPPORTED */
  162172. #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
  162173. extern PNG_EXPORT(void, png_set_keep_unknown_chunks) PNGARG((png_structp
  162174. png_ptr, int keep, png_bytep chunk_list, int num_chunks));
  162175. extern PNG_EXPORT(void, png_set_unknown_chunks) PNGARG((png_structp png_ptr,
  162176. png_infop info_ptr, png_unknown_chunkp unknowns, int num_unknowns));
  162177. extern PNG_EXPORT(void, png_set_unknown_chunk_location)
  162178. PNGARG((png_structp png_ptr, png_infop info_ptr, int chunk, int location));
  162179. extern PNG_EXPORT(png_uint_32,png_get_unknown_chunks) PNGARG((png_structp
  162180. png_ptr, png_infop info_ptr, png_unknown_chunkpp entries));
  162181. #endif
  162182. #ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
  162183. PNG_EXPORT(int,png_handle_as_unknown) PNGARG((png_structp png_ptr, png_bytep
  162184. chunk_name));
  162185. #endif
  162186. extern PNG_EXPORT(void, png_set_invalid) PNGARG((png_structp png_ptr,
  162187. png_infop info_ptr, int mask));
  162188. #if defined(PNG_INFO_IMAGE_SUPPORTED)
  162189. extern PNG_EXPORT(void, png_read_png) PNGARG((png_structp png_ptr,
  162190. png_infop info_ptr,
  162191. int transforms,
  162192. png_voidp params));
  162193. extern PNG_EXPORT(void, png_write_png) PNGARG((png_structp png_ptr,
  162194. png_infop info_ptr,
  162195. int transforms,
  162196. png_voidp params));
  162197. #endif
  162198. #ifdef PNG_DEBUG
  162199. #if (PNG_DEBUG > 0)
  162200. #if !defined(PNG_DEBUG_FILE) && defined(_MSC_VER)
  162201. #include <crtdbg.h>
  162202. #if (PNG_DEBUG > 1)
  162203. #define png_debug(l,m) _RPT0(_CRT_WARN,m)
  162204. #define png_debug1(l,m,p1) _RPT1(_CRT_WARN,m,p1)
  162205. #define png_debug2(l,m,p1,p2) _RPT2(_CRT_WARN,m,p1,p2)
  162206. #endif
  162207. #else /* PNG_DEBUG_FILE || !_MSC_VER */
  162208. #ifndef PNG_DEBUG_FILE
  162209. #define PNG_DEBUG_FILE stderr
  162210. #endif /* PNG_DEBUG_FILE */
  162211. #if (PNG_DEBUG > 1)
  162212. #define png_debug(l,m) \
  162213. { \
  162214. int num_tabs=l; \
  162215. fprintf(PNG_DEBUG_FILE,"%s"m,(num_tabs==1 ? "\t" : \
  162216. (num_tabs==2 ? "\t\t":(num_tabs>2 ? "\t\t\t":"")))); \
  162217. }
  162218. #define png_debug1(l,m,p1) \
  162219. { \
  162220. int num_tabs=l; \
  162221. fprintf(PNG_DEBUG_FILE,"%s"m,(num_tabs==1 ? "\t" : \
  162222. (num_tabs==2 ? "\t\t":(num_tabs>2 ? "\t\t\t":""))),p1); \
  162223. }
  162224. #define png_debug2(l,m,p1,p2) \
  162225. { \
  162226. int num_tabs=l; \
  162227. fprintf(PNG_DEBUG_FILE,"%s"m,(num_tabs==1 ? "\t" : \
  162228. (num_tabs==2 ? "\t\t":(num_tabs>2 ? "\t\t\t":""))),p1,p2); \
  162229. }
  162230. #endif /* (PNG_DEBUG > 1) */
  162231. #endif /* _MSC_VER */
  162232. #endif /* (PNG_DEBUG > 0) */
  162233. #endif /* PNG_DEBUG */
  162234. #ifndef png_debug
  162235. #define png_debug(l, m)
  162236. #endif
  162237. #ifndef png_debug1
  162238. #define png_debug1(l, m, p1)
  162239. #endif
  162240. #ifndef png_debug2
  162241. #define png_debug2(l, m, p1, p2)
  162242. #endif
  162243. extern PNG_EXPORT(png_charp,png_get_copyright) PNGARG((png_structp png_ptr));
  162244. extern PNG_EXPORT(png_charp,png_get_header_ver) PNGARG((png_structp png_ptr));
  162245. extern PNG_EXPORT(png_charp,png_get_header_version) PNGARG((png_structp png_ptr));
  162246. extern PNG_EXPORT(png_charp,png_get_libpng_ver) PNGARG((png_structp png_ptr));
  162247. #ifdef PNG_MNG_FEATURES_SUPPORTED
  162248. extern PNG_EXPORT(png_uint_32,png_permit_mng_features) PNGARG((png_structp
  162249. png_ptr, png_uint_32 mng_features_permitted));
  162250. #endif
  162251. #define PNG_HANDLE_CHUNK_AS_DEFAULT 0
  162252. #define PNG_HANDLE_CHUNK_NEVER 1
  162253. #define PNG_HANDLE_CHUNK_IF_SAFE 2
  162254. #define PNG_HANDLE_CHUNK_ALWAYS 3
  162255. #if defined(PNG_ASSEMBLER_CODE_SUPPORTED)
  162256. #if defined(PNG_MMX_CODE_SUPPORTED)
  162257. #define PNG_ASM_FLAG_MMX_SUPPORT_COMPILED 0x01 /* not user-settable */
  162258. #define PNG_ASM_FLAG_MMX_SUPPORT_IN_CPU 0x02 /* not user-settable */
  162259. #define PNG_ASM_FLAG_MMX_READ_COMBINE_ROW 0x04
  162260. #define PNG_ASM_FLAG_MMX_READ_INTERLACE 0x08
  162261. #define PNG_ASM_FLAG_MMX_READ_FILTER_SUB 0x10
  162262. #define PNG_ASM_FLAG_MMX_READ_FILTER_UP 0x20
  162263. #define PNG_ASM_FLAG_MMX_READ_FILTER_AVG 0x40
  162264. #define PNG_ASM_FLAG_MMX_READ_FILTER_PAETH 0x80
  162265. #define PNG_ASM_FLAGS_INITIALIZED 0x80000000 /* not user-settable */
  162266. #define PNG_MMX_READ_FLAGS ( PNG_ASM_FLAG_MMX_READ_COMBINE_ROW \
  162267. | PNG_ASM_FLAG_MMX_READ_INTERLACE \
  162268. | PNG_ASM_FLAG_MMX_READ_FILTER_SUB \
  162269. | PNG_ASM_FLAG_MMX_READ_FILTER_UP \
  162270. | PNG_ASM_FLAG_MMX_READ_FILTER_AVG \
  162271. | PNG_ASM_FLAG_MMX_READ_FILTER_PAETH )
  162272. #define PNG_MMX_WRITE_FLAGS ( 0 )
  162273. #define PNG_MMX_FLAGS ( PNG_ASM_FLAG_MMX_SUPPORT_COMPILED \
  162274. | PNG_ASM_FLAG_MMX_SUPPORT_IN_CPU \
  162275. | PNG_MMX_READ_FLAGS \
  162276. | PNG_MMX_WRITE_FLAGS )
  162277. #define PNG_SELECT_READ 1
  162278. #define PNG_SELECT_WRITE 2
  162279. #endif /* PNG_MMX_CODE_SUPPORTED */
  162280. #if !defined(PNG_1_0_X)
  162281. extern PNG_EXPORT(png_uint_32,png_get_mmx_flagmask)
  162282. PNGARG((int flag_select, int *compilerID));
  162283. extern PNG_EXPORT(png_uint_32,png_get_asm_flagmask)
  162284. PNGARG((int flag_select));
  162285. extern PNG_EXPORT(png_uint_32,png_get_asm_flags)
  162286. PNGARG((png_structp png_ptr));
  162287. extern PNG_EXPORT(png_byte,png_get_mmx_bitdepth_threshold)
  162288. PNGARG((png_structp png_ptr));
  162289. extern PNG_EXPORT(png_uint_32,png_get_mmx_rowbytes_threshold)
  162290. PNGARG((png_structp png_ptr));
  162291. extern PNG_EXPORT(void,png_set_asm_flags)
  162292. PNGARG((png_structp png_ptr, png_uint_32 asm_flags));
  162293. extern PNG_EXPORT(void,png_set_mmx_thresholds)
  162294. PNGARG((png_structp png_ptr, png_byte mmx_bitdepth_threshold,
  162295. png_uint_32 mmx_rowbytes_threshold));
  162296. #endif /* PNG_1_0_X */
  162297. #if !defined(PNG_1_0_X)
  162298. extern PNG_EXPORT(int,png_mmx_support) PNGARG((void));
  162299. #endif /* PNG_ASSEMBLER_CODE_SUPPORTED */
  162300. #ifdef PNG_ERROR_NUMBERS_SUPPORTED
  162301. extern PNG_EXPORT(void,png_set_strip_error_numbers) PNGARG((png_structp
  162302. png_ptr, png_uint_32 strip_mode));
  162303. #endif
  162304. #endif /* PNG_1_0_X */
  162305. #ifdef PNG_SET_USER_LIMITS_SUPPORTED
  162306. extern PNG_EXPORT(void,png_set_user_limits) PNGARG((png_structp
  162307. png_ptr, png_uint_32 user_width_max, png_uint_32 user_height_max));
  162308. extern PNG_EXPORT(png_uint_32,png_get_user_width_max) PNGARG((png_structp
  162309. png_ptr));
  162310. extern PNG_EXPORT(png_uint_32,png_get_user_height_max) PNGARG((png_structp
  162311. png_ptr));
  162312. #endif
  162313. #ifdef PNG_READ_COMPOSITE_NODIV_SUPPORTED
  162314. # define png_composite(composite, fg, alpha, bg) \
  162315. { png_uint_16 temp = (png_uint_16)((png_uint_16)(fg) * (png_uint_16)(alpha) \
  162316. + (png_uint_16)(bg)*(png_uint_16)(255 - \
  162317. (png_uint_16)(alpha)) + (png_uint_16)128); \
  162318. (composite) = (png_byte)((temp + (temp >> 8)) >> 8); }
  162319. # define png_composite_16(composite, fg, alpha, bg) \
  162320. { png_uint_32 temp = (png_uint_32)((png_uint_32)(fg) * (png_uint_32)(alpha) \
  162321. + (png_uint_32)(bg)*(png_uint_32)(65535L - \
  162322. (png_uint_32)(alpha)) + (png_uint_32)32768L); \
  162323. (composite) = (png_uint_16)((temp + (temp >> 16)) >> 16); }
  162324. #else /* standard method using integer division */
  162325. # define png_composite(composite, fg, alpha, bg) \
  162326. (composite) = (png_byte)(((png_uint_16)(fg) * (png_uint_16)(alpha) + \
  162327. (png_uint_16)(bg) * (png_uint_16)(255 - (png_uint_16)(alpha)) + \
  162328. (png_uint_16)127) / 255)
  162329. # define png_composite_16(composite, fg, alpha, bg) \
  162330. (composite) = (png_uint_16)(((png_uint_32)(fg) * (png_uint_32)(alpha) + \
  162331. (png_uint_32)(bg)*(png_uint_32)(65535L - (png_uint_32)(alpha)) + \
  162332. (png_uint_32)32767) / (png_uint_32)65535L)
  162333. #endif /* PNG_READ_COMPOSITE_NODIV_SUPPORTED */
  162334. #if defined(PNG_READ_BIG_ENDIAN_SUPPORTED)
  162335. # define png_get_uint_32(buf) ( *((png_uint_32p) (buf)))
  162336. # define png_get_uint_16(buf) ( *((png_uint_16p) (buf)))
  162337. # define png_get_int_32(buf) ( *((png_int_32p) (buf)))
  162338. #else
  162339. extern PNG_EXPORT(png_uint_32,png_get_uint_32) PNGARG((png_bytep buf));
  162340. extern PNG_EXPORT(png_uint_16,png_get_uint_16) PNGARG((png_bytep buf));
  162341. extern PNG_EXPORT(png_int_32,png_get_int_32) PNGARG((png_bytep buf));
  162342. #endif /* !PNG_READ_BIG_ENDIAN_SUPPORTED */
  162343. extern PNG_EXPORT(png_uint_32,png_get_uint_31)
  162344. PNGARG((png_structp png_ptr, png_bytep buf));
  162345. extern PNG_EXPORT(void,png_save_uint_32)
  162346. PNGARG((png_bytep buf, png_uint_32 i));
  162347. extern PNG_EXPORT(void,png_save_int_32)
  162348. PNGARG((png_bytep buf, png_int_32 i));
  162349. extern PNG_EXPORT(void,png_save_uint_16)
  162350. PNGARG((png_bytep buf, unsigned int i));
  162351. #define PNG_HAVE_IHDR 0x01
  162352. #define PNG_HAVE_PLTE 0x02
  162353. #define PNG_HAVE_IDAT 0x04
  162354. #define PNG_AFTER_IDAT 0x08 /* Have complete zlib datastream */
  162355. #define PNG_HAVE_IEND 0x10
  162356. #if defined(PNG_INTERNAL)
  162357. #define PNG_HAVE_gAMA 0x20
  162358. #define PNG_HAVE_cHRM 0x40
  162359. #define PNG_HAVE_sRGB 0x80
  162360. #define PNG_HAVE_CHUNK_HEADER 0x100
  162361. #define PNG_WROTE_tIME 0x200
  162362. #define PNG_WROTE_INFO_BEFORE_PLTE 0x400
  162363. #define PNG_BACKGROUND_IS_GRAY 0x800
  162364. #define PNG_HAVE_PNG_SIGNATURE 0x1000
  162365. #define PNG_HAVE_CHUNK_AFTER_IDAT 0x2000 /* Have another chunk after IDAT */
  162366. #define PNG_BGR 0x0001
  162367. #define PNG_INTERLACE 0x0002
  162368. #define PNG_PACK 0x0004
  162369. #define PNG_SHIFT 0x0008
  162370. #define PNG_SWAP_BYTES 0x0010
  162371. #define PNG_INVERT_MONO 0x0020
  162372. #define PNG_DITHER 0x0040
  162373. #define PNG_BACKGROUND 0x0080
  162374. #define PNG_BACKGROUND_EXPAND 0x0100
  162375. #define PNG_16_TO_8 0x0400
  162376. #define PNG_RGBA 0x0800
  162377. #define PNG_EXPAND 0x1000
  162378. #define PNG_GAMMA 0x2000
  162379. #define PNG_GRAY_TO_RGB 0x4000
  162380. #define PNG_FILLER 0x8000L
  162381. #define PNG_PACKSWAP 0x10000L
  162382. #define PNG_SWAP_ALPHA 0x20000L
  162383. #define PNG_STRIP_ALPHA 0x40000L
  162384. #define PNG_INVERT_ALPHA 0x80000L
  162385. #define PNG_USER_TRANSFORM 0x100000L
  162386. #define PNG_RGB_TO_GRAY_ERR 0x200000L
  162387. #define PNG_RGB_TO_GRAY_WARN 0x400000L
  162388. #define PNG_RGB_TO_GRAY 0x600000L /* two bits, RGB_TO_GRAY_ERR|WARN */
  162389. #define PNG_ADD_ALPHA 0x1000000L /* Added to libpng-1.2.7 */
  162390. #define PNG_EXPAND_tRNS 0x2000000L /* Added to libpng-1.2.9 */
  162391. #define PNG_STRUCT_PNG 0x0001
  162392. #define PNG_STRUCT_INFO 0x0002
  162393. #define PNG_WEIGHT_SHIFT 8
  162394. #define PNG_WEIGHT_FACTOR (1<<(PNG_WEIGHT_SHIFT))
  162395. #define PNG_COST_SHIFT 3
  162396. #define PNG_COST_FACTOR (1<<(PNG_COST_SHIFT))
  162397. #define PNG_FLAG_ZLIB_CUSTOM_STRATEGY 0x0001
  162398. #define PNG_FLAG_ZLIB_CUSTOM_LEVEL 0x0002
  162399. #define PNG_FLAG_ZLIB_CUSTOM_MEM_LEVEL 0x0004
  162400. #define PNG_FLAG_ZLIB_CUSTOM_WINDOW_BITS 0x0008
  162401. #define PNG_FLAG_ZLIB_CUSTOM_METHOD 0x0010
  162402. #define PNG_FLAG_ZLIB_FINISHED 0x0020
  162403. #define PNG_FLAG_ROW_INIT 0x0040
  162404. #define PNG_FLAG_FILLER_AFTER 0x0080
  162405. #define PNG_FLAG_CRC_ANCILLARY_USE 0x0100
  162406. #define PNG_FLAG_CRC_ANCILLARY_NOWARN 0x0200
  162407. #define PNG_FLAG_CRC_CRITICAL_USE 0x0400
  162408. #define PNG_FLAG_CRC_CRITICAL_IGNORE 0x0800
  162409. #define PNG_FLAG_FREE_PLTE 0x1000
  162410. #define PNG_FLAG_FREE_TRNS 0x2000
  162411. #define PNG_FLAG_FREE_HIST 0x4000
  162412. #define PNG_FLAG_KEEP_UNKNOWN_CHUNKS 0x8000L
  162413. #define PNG_FLAG_KEEP_UNSAFE_CHUNKS 0x10000L
  162414. #define PNG_FLAG_LIBRARY_MISMATCH 0x20000L
  162415. #define PNG_FLAG_STRIP_ERROR_NUMBERS 0x40000L
  162416. #define PNG_FLAG_STRIP_ERROR_TEXT 0x80000L
  162417. #define PNG_FLAG_MALLOC_NULL_MEM_OK 0x100000L
  162418. #define PNG_FLAG_ADD_ALPHA 0x200000L /* Added to libpng-1.2.8 */
  162419. #define PNG_FLAG_STRIP_ALPHA 0x400000L /* Added to libpng-1.2.8 */
  162420. #define PNG_FLAG_CRC_ANCILLARY_MASK (PNG_FLAG_CRC_ANCILLARY_USE | \
  162421. PNG_FLAG_CRC_ANCILLARY_NOWARN)
  162422. #define PNG_FLAG_CRC_CRITICAL_MASK (PNG_FLAG_CRC_CRITICAL_USE | \
  162423. PNG_FLAG_CRC_CRITICAL_IGNORE)
  162424. #define PNG_FLAG_CRC_MASK (PNG_FLAG_CRC_ANCILLARY_MASK | \
  162425. PNG_FLAG_CRC_CRITICAL_MASK)
  162426. #define PNG_COLOR_DIST(c1, c2) (abs((int)((c1).red) - (int)((c2).red)) + \
  162427. abs((int)((c1).green) - (int)((c2).green)) + \
  162428. abs((int)((c1).blue) - (int)((c2).blue)))
  162429. #define PNG_ROWBYTES(pixel_bits, width) \
  162430. ((pixel_bits) >= 8 ? \
  162431. ((width) * (((png_uint_32)(pixel_bits)) >> 3)) : \
  162432. (( ((width) * ((png_uint_32)(pixel_bits))) + 7) >> 3) )
  162433. #define PNG_OUT_OF_RANGE(value, ideal, delta) \
  162434. ( (value) < (ideal)-(delta) || (value) > (ideal)+(delta) )
  162435. #if !defined(PNG_NO_EXTERN) || defined(PNG_ALWAYS_EXTERN)
  162436. #ifdef PNG_USE_GLOBAL_ARRAYS
  162437. PNG_EXPORT_VAR (PNG_CONST png_byte FARDATA) png_sig[8];
  162438. #else
  162439. #endif
  162440. #endif /* PNG_NO_EXTERN */
  162441. #define PNG_IHDR png_byte png_IHDR[5] = { 73, 72, 68, 82, '\0'}
  162442. #define PNG_IDAT png_byte png_IDAT[5] = { 73, 68, 65, 84, '\0'}
  162443. #define PNG_IEND png_byte png_IEND[5] = { 73, 69, 78, 68, '\0'}
  162444. #define PNG_PLTE png_byte png_PLTE[5] = { 80, 76, 84, 69, '\0'}
  162445. #define PNG_bKGD png_byte png_bKGD[5] = { 98, 75, 71, 68, '\0'}
  162446. #define PNG_cHRM png_byte png_cHRM[5] = { 99, 72, 82, 77, '\0'}
  162447. #define PNG_gAMA png_byte png_gAMA[5] = {103, 65, 77, 65, '\0'}
  162448. #define PNG_hIST png_byte png_hIST[5] = {104, 73, 83, 84, '\0'}
  162449. #define PNG_iCCP png_byte png_iCCP[5] = {105, 67, 67, 80, '\0'}
  162450. #define PNG_iTXt png_byte png_iTXt[5] = {105, 84, 88, 116, '\0'}
  162451. #define PNG_oFFs png_byte png_oFFs[5] = {111, 70, 70, 115, '\0'}
  162452. #define PNG_pCAL png_byte png_pCAL[5] = {112, 67, 65, 76, '\0'}
  162453. #define PNG_sCAL png_byte png_sCAL[5] = {115, 67, 65, 76, '\0'}
  162454. #define PNG_pHYs png_byte png_pHYs[5] = {112, 72, 89, 115, '\0'}
  162455. #define PNG_sBIT png_byte png_sBIT[5] = {115, 66, 73, 84, '\0'}
  162456. #define PNG_sPLT png_byte png_sPLT[5] = {115, 80, 76, 84, '\0'}
  162457. #define PNG_sRGB png_byte png_sRGB[5] = {115, 82, 71, 66, '\0'}
  162458. #define PNG_tEXt png_byte png_tEXt[5] = {116, 69, 88, 116, '\0'}
  162459. #define PNG_tIME png_byte png_tIME[5] = {116, 73, 77, 69, '\0'}
  162460. #define PNG_tRNS png_byte png_tRNS[5] = {116, 82, 78, 83, '\0'}
  162461. #define PNG_zTXt png_byte png_zTXt[5] = {122, 84, 88, 116, '\0'}
  162462. #ifdef PNG_USE_GLOBAL_ARRAYS
  162463. PNG_EXPORT_VAR (png_byte FARDATA) png_IHDR[5];
  162464. PNG_EXPORT_VAR (png_byte FARDATA) png_IDAT[5];
  162465. PNG_EXPORT_VAR (png_byte FARDATA) png_IEND[5];
  162466. PNG_EXPORT_VAR (png_byte FARDATA) png_PLTE[5];
  162467. PNG_EXPORT_VAR (png_byte FARDATA) png_bKGD[5];
  162468. PNG_EXPORT_VAR (png_byte FARDATA) png_cHRM[5];
  162469. PNG_EXPORT_VAR (png_byte FARDATA) png_gAMA[5];
  162470. PNG_EXPORT_VAR (png_byte FARDATA) png_hIST[5];
  162471. PNG_EXPORT_VAR (png_byte FARDATA) png_iCCP[5];
  162472. PNG_EXPORT_VAR (png_byte FARDATA) png_iTXt[5];
  162473. PNG_EXPORT_VAR (png_byte FARDATA) png_oFFs[5];
  162474. PNG_EXPORT_VAR (png_byte FARDATA) png_pCAL[5];
  162475. PNG_EXPORT_VAR (png_byte FARDATA) png_sCAL[5];
  162476. PNG_EXPORT_VAR (png_byte FARDATA) png_pHYs[5];
  162477. PNG_EXPORT_VAR (png_byte FARDATA) png_sBIT[5];
  162478. PNG_EXPORT_VAR (png_byte FARDATA) png_sPLT[5];
  162479. PNG_EXPORT_VAR (png_byte FARDATA) png_sRGB[5];
  162480. PNG_EXPORT_VAR (png_byte FARDATA) png_tEXt[5];
  162481. PNG_EXPORT_VAR (png_byte FARDATA) png_tIME[5];
  162482. PNG_EXPORT_VAR (png_byte FARDATA) png_tRNS[5];
  162483. PNG_EXPORT_VAR (png_byte FARDATA) png_zTXt[5];
  162484. #endif /* PNG_USE_GLOBAL_ARRAYS */
  162485. #if defined(PNG_1_0_X) || defined (PNG_1_2_X)
  162486. extern PNG_EXPORT(void,png_read_init) PNGARG((png_structp png_ptr));
  162487. #undef png_read_init
  162488. #define png_read_init(png_ptr) png_read_init_3(&png_ptr, \
  162489. PNG_LIBPNG_VER_STRING, png_sizeof(png_struct));
  162490. #endif
  162491. extern PNG_EXPORT(void,png_read_init_3) PNGARG((png_structpp ptr_ptr,
  162492. png_const_charp user_png_ver, png_size_t png_struct_size));
  162493. #if defined(PNG_1_0_X) || defined (PNG_1_2_X)
  162494. extern PNG_EXPORT(void,png_read_init_2) PNGARG((png_structp png_ptr,
  162495. png_const_charp user_png_ver, png_size_t png_struct_size, png_size_t
  162496. png_info_size));
  162497. #endif
  162498. #if defined(PNG_1_0_X) || defined (PNG_1_2_X)
  162499. extern PNG_EXPORT(void,png_write_init) PNGARG((png_structp png_ptr));
  162500. #undef png_write_init
  162501. #define png_write_init(png_ptr) png_write_init_3(&png_ptr, \
  162502. PNG_LIBPNG_VER_STRING, png_sizeof(png_struct));
  162503. #endif
  162504. extern PNG_EXPORT(void,png_write_init_3) PNGARG((png_structpp ptr_ptr,
  162505. png_const_charp user_png_ver, png_size_t png_struct_size));
  162506. extern PNG_EXPORT(void,png_write_init_2) PNGARG((png_structp png_ptr,
  162507. png_const_charp user_png_ver, png_size_t png_struct_size, png_size_t
  162508. png_info_size));
  162509. PNG_EXTERN png_voidp png_create_struct PNGARG((int type));
  162510. PNG_EXTERN void png_destroy_struct PNGARG((png_voidp struct_ptr));
  162511. PNG_EXTERN png_voidp png_create_struct_2 PNGARG((int type, png_malloc_ptr
  162512. malloc_fn, png_voidp mem_ptr));
  162513. PNG_EXTERN void png_destroy_struct_2 PNGARG((png_voidp struct_ptr,
  162514. png_free_ptr free_fn, png_voidp mem_ptr));
  162515. PNG_EXTERN void png_info_destroy PNGARG((png_structp png_ptr,
  162516. png_infop info_ptr));
  162517. #ifndef PNG_1_0_X
  162518. PNG_EXTERN voidpf png_zalloc PNGARG((voidpf png_ptr, uInt items, uInt size));
  162519. PNG_EXTERN void png_zfree PNGARG((voidpf png_ptr, voidpf ptr));
  162520. #ifdef PNG_SIZE_T
  162521. PNG_EXTERN png_size_t PNGAPI png_convert_size PNGARG((size_t size));
  162522. #endif
  162523. PNG_EXTERN void PNGAPI png_default_read_data PNGARG((png_structp png_ptr,
  162524. png_bytep data, png_size_t length));
  162525. #ifdef PNG_PROGRESSIVE_READ_SUPPORTED
  162526. PNG_EXTERN void PNGAPI png_push_fill_buffer PNGARG((png_structp png_ptr,
  162527. png_bytep buffer, png_size_t length));
  162528. #endif
  162529. PNG_EXTERN void PNGAPI png_default_write_data PNGARG((png_structp png_ptr,
  162530. png_bytep data, png_size_t length));
  162531. #if defined(PNG_WRITE_FLUSH_SUPPORTED)
  162532. #if !defined(PNG_NO_STDIO)
  162533. PNG_EXTERN void PNGAPI png_default_flush PNGARG((png_structp png_ptr));
  162534. #endif
  162535. #endif
  162536. #else /* PNG_1_0_X */
  162537. #ifdef PNG_PROGRESSIVE_READ_SUPPORTED
  162538. PNG_EXTERN void png_push_fill_buffer PNGARG((png_structp png_ptr,
  162539. png_bytep buffer, png_size_t length));
  162540. #endif
  162541. #endif /* PNG_1_0_X */
  162542. PNG_EXTERN void png_reset_crc PNGARG((png_structp png_ptr));
  162543. PNG_EXTERN void png_write_data PNGARG((png_structp png_ptr, png_bytep data,
  162544. png_size_t length));
  162545. PNG_EXTERN void png_read_data PNGARG((png_structp png_ptr, png_bytep data,
  162546. png_size_t length));
  162547. PNG_EXTERN void png_crc_read PNGARG((png_structp png_ptr, png_bytep buf,
  162548. png_size_t length));
  162549. #if defined(PNG_zTXt_SUPPORTED) || defined(PNG_iTXt_SUPPORTED) || \
  162550. defined(PNG_iCCP_SUPPORTED) || defined(PNG_sPLT_SUPPORTED)
  162551. PNG_EXTERN png_charp png_decompress_chunk PNGARG((png_structp png_ptr,
  162552. int comp_type, png_charp chunkdata, png_size_t chunklength,
  162553. png_size_t prefix_length, png_size_t *data_length));
  162554. #endif
  162555. PNG_EXTERN int png_crc_finish PNGARG((png_structp png_ptr, png_uint_32 skip));
  162556. PNG_EXTERN int png_crc_error PNGARG((png_structp png_ptr));
  162557. PNG_EXTERN void png_calculate_crc PNGARG((png_structp png_ptr, png_bytep ptr,
  162558. png_size_t length));
  162559. #if defined(PNG_WRITE_FLUSH_SUPPORTED)
  162560. PNG_EXTERN void png_flush PNGARG((png_structp png_ptr));
  162561. #endif
  162562. PNG_EXTERN void png_write_sig PNGARG((png_structp png_ptr));
  162563. PNG_EXTERN void png_write_IHDR PNGARG((png_structp png_ptr, png_uint_32 width,
  162564. png_uint_32 height,
  162565. int bit_depth, int color_type, int compression_method, int filter_method,
  162566. int interlace_method));
  162567. PNG_EXTERN void png_write_PLTE PNGARG((png_structp png_ptr, png_colorp palette,
  162568. png_uint_32 num_pal));
  162569. PNG_EXTERN void png_write_IDAT PNGARG((png_structp png_ptr, png_bytep data,
  162570. png_size_t length));
  162571. PNG_EXTERN void png_write_IEND PNGARG((png_structp png_ptr));
  162572. #if defined(PNG_WRITE_gAMA_SUPPORTED)
  162573. #ifdef PNG_FLOATING_POINT_SUPPORTED
  162574. PNG_EXTERN void png_write_gAMA PNGARG((png_structp png_ptr, double file_gamma));
  162575. #endif
  162576. #ifdef PNG_FIXED_POINT_SUPPORTED
  162577. PNG_EXTERN void png_write_gAMA_fixed PNGARG((png_structp png_ptr, png_fixed_point
  162578. file_gamma));
  162579. #endif
  162580. #endif
  162581. #if defined(PNG_WRITE_sBIT_SUPPORTED)
  162582. PNG_EXTERN void png_write_sBIT PNGARG((png_structp png_ptr, png_color_8p sbit,
  162583. int color_type));
  162584. #endif
  162585. #if defined(PNG_WRITE_cHRM_SUPPORTED)
  162586. #ifdef PNG_FLOATING_POINT_SUPPORTED
  162587. PNG_EXTERN void png_write_cHRM PNGARG((png_structp png_ptr,
  162588. double white_x, double white_y,
  162589. double red_x, double red_y, double green_x, double green_y,
  162590. double blue_x, double blue_y));
  162591. #endif
  162592. #ifdef PNG_FIXED_POINT_SUPPORTED
  162593. PNG_EXTERN void png_write_cHRM_fixed PNGARG((png_structp png_ptr,
  162594. png_fixed_point int_white_x, png_fixed_point int_white_y,
  162595. png_fixed_point int_red_x, png_fixed_point int_red_y, png_fixed_point
  162596. int_green_x, png_fixed_point int_green_y, png_fixed_point int_blue_x,
  162597. png_fixed_point int_blue_y));
  162598. #endif
  162599. #endif
  162600. #if defined(PNG_WRITE_sRGB_SUPPORTED)
  162601. PNG_EXTERN void png_write_sRGB PNGARG((png_structp png_ptr,
  162602. int intent));
  162603. #endif
  162604. #if defined(PNG_WRITE_iCCP_SUPPORTED)
  162605. PNG_EXTERN void png_write_iCCP PNGARG((png_structp png_ptr,
  162606. png_charp name, int compression_type,
  162607. png_charp profile, int proflen));
  162608. #endif
  162609. #if defined(PNG_WRITE_sPLT_SUPPORTED)
  162610. PNG_EXTERN void png_write_sPLT PNGARG((png_structp png_ptr,
  162611. png_sPLT_tp palette));
  162612. #endif
  162613. #if defined(PNG_WRITE_tRNS_SUPPORTED)
  162614. PNG_EXTERN void png_write_tRNS PNGARG((png_structp png_ptr, png_bytep trans,
  162615. png_color_16p values, int number, int color_type));
  162616. #endif
  162617. #if defined(PNG_WRITE_bKGD_SUPPORTED)
  162618. PNG_EXTERN void png_write_bKGD PNGARG((png_structp png_ptr,
  162619. png_color_16p values, int color_type));
  162620. #endif
  162621. #if defined(PNG_WRITE_hIST_SUPPORTED)
  162622. PNG_EXTERN void png_write_hIST PNGARG((png_structp png_ptr, png_uint_16p hist,
  162623. int num_hist));
  162624. #endif
  162625. #if defined(PNG_WRITE_TEXT_SUPPORTED) || defined(PNG_WRITE_pCAL_SUPPORTED) || \
  162626. defined(PNG_WRITE_iCCP_SUPPORTED) || defined(PNG_WRITE_sPLT_SUPPORTED)
  162627. PNG_EXTERN png_size_t png_check_keyword PNGARG((png_structp png_ptr,
  162628. png_charp key, png_charpp new_key));
  162629. #endif
  162630. #if defined(PNG_WRITE_tEXt_SUPPORTED)
  162631. PNG_EXTERN void png_write_tEXt PNGARG((png_structp png_ptr, png_charp key,
  162632. png_charp text, png_size_t text_len));
  162633. #endif
  162634. #if defined(PNG_WRITE_zTXt_SUPPORTED)
  162635. PNG_EXTERN void png_write_zTXt PNGARG((png_structp png_ptr, png_charp key,
  162636. png_charp text, png_size_t text_len, int compression));
  162637. #endif
  162638. #if defined(PNG_WRITE_iTXt_SUPPORTED)
  162639. PNG_EXTERN void png_write_iTXt PNGARG((png_structp png_ptr,
  162640. int compression, png_charp key, png_charp lang, png_charp lang_key,
  162641. png_charp text));
  162642. #endif
  162643. #if defined(PNG_TEXT_SUPPORTED) /* Added at version 1.0.14 and 1.2.4 */
  162644. PNG_EXTERN int png_set_text_2 PNGARG((png_structp png_ptr,
  162645. png_infop info_ptr, png_textp text_ptr, int num_text));
  162646. #endif
  162647. #if defined(PNG_WRITE_oFFs_SUPPORTED)
  162648. PNG_EXTERN void png_write_oFFs PNGARG((png_structp png_ptr,
  162649. png_int_32 x_offset, png_int_32 y_offset, int unit_type));
  162650. #endif
  162651. #if defined(PNG_WRITE_pCAL_SUPPORTED)
  162652. PNG_EXTERN void png_write_pCAL PNGARG((png_structp png_ptr, png_charp purpose,
  162653. png_int_32 X0, png_int_32 X1, int type, int nparams,
  162654. png_charp units, png_charpp params));
  162655. #endif
  162656. #if defined(PNG_WRITE_pHYs_SUPPORTED)
  162657. PNG_EXTERN void png_write_pHYs PNGARG((png_structp png_ptr,
  162658. png_uint_32 x_pixels_per_unit, png_uint_32 y_pixels_per_unit,
  162659. int unit_type));
  162660. #endif
  162661. #if defined(PNG_WRITE_tIME_SUPPORTED)
  162662. PNG_EXTERN void png_write_tIME PNGARG((png_structp png_ptr,
  162663. png_timep mod_time));
  162664. #endif
  162665. #if defined(PNG_WRITE_sCAL_SUPPORTED)
  162666. #if defined(PNG_FLOATING_POINT_SUPPORTED) && !defined(PNG_NO_STDIO)
  162667. PNG_EXTERN void png_write_sCAL PNGARG((png_structp png_ptr,
  162668. int unit, double width, double height));
  162669. #else
  162670. #ifdef PNG_FIXED_POINT_SUPPORTED
  162671. PNG_EXTERN void png_write_sCAL_s PNGARG((png_structp png_ptr,
  162672. int unit, png_charp width, png_charp height));
  162673. #endif
  162674. #endif
  162675. #endif
  162676. PNG_EXTERN void png_write_finish_row PNGARG((png_structp png_ptr));
  162677. PNG_EXTERN void png_write_start_row PNGARG((png_structp png_ptr));
  162678. #if defined(PNG_READ_GAMMA_SUPPORTED)
  162679. PNG_EXTERN void png_build_gamma_table PNGARG((png_structp png_ptr));
  162680. #endif
  162681. PNG_EXTERN void png_combine_row PNGARG((png_structp png_ptr, png_bytep row,
  162682. int mask));
  162683. #if defined(PNG_READ_INTERLACING_SUPPORTED)
  162684. PNG_EXTERN void png_do_read_interlace PNGARG((png_structp png_ptr));
  162685. #endif
  162686. #if defined(PNG_WRITE_INTERLACING_SUPPORTED)
  162687. PNG_EXTERN void png_do_write_interlace PNGARG((png_row_infop row_info,
  162688. png_bytep row, int pass));
  162689. #endif
  162690. PNG_EXTERN void png_read_filter_row PNGARG((png_structp png_ptr,
  162691. png_row_infop row_info, png_bytep row, png_bytep prev_row, int filter));
  162692. PNG_EXTERN void png_write_find_filter PNGARG((png_structp png_ptr,
  162693. png_row_infop row_info));
  162694. PNG_EXTERN void png_write_filtered_row PNGARG((png_structp png_ptr,
  162695. png_bytep filtered_row));
  162696. PNG_EXTERN void png_read_finish_row PNGARG((png_structp png_ptr));
  162697. PNG_EXTERN void png_read_start_row PNGARG((png_structp png_ptr));
  162698. PNG_EXTERN void png_read_transform_info PNGARG((png_structp png_ptr,
  162699. png_infop info_ptr));
  162700. #if defined(PNG_READ_FILLER_SUPPORTED)
  162701. PNG_EXTERN void png_do_read_filler PNGARG((png_row_infop row_info,
  162702. png_bytep row, png_uint_32 filler, png_uint_32 flags));
  162703. #endif
  162704. #if defined(PNG_READ_SWAP_ALPHA_SUPPORTED)
  162705. PNG_EXTERN void png_do_read_swap_alpha PNGARG((png_row_infop row_info,
  162706. png_bytep row));
  162707. #endif
  162708. #if defined(PNG_WRITE_SWAP_ALPHA_SUPPORTED)
  162709. PNG_EXTERN void png_do_write_swap_alpha PNGARG((png_row_infop row_info,
  162710. png_bytep row));
  162711. #endif
  162712. #if defined(PNG_READ_INVERT_ALPHA_SUPPORTED)
  162713. PNG_EXTERN void png_do_read_invert_alpha PNGARG((png_row_infop row_info,
  162714. png_bytep row));
  162715. #endif
  162716. #if defined(PNG_WRITE_INVERT_ALPHA_SUPPORTED)
  162717. PNG_EXTERN void png_do_write_invert_alpha PNGARG((png_row_infop row_info,
  162718. png_bytep row));
  162719. #endif
  162720. #if defined(PNG_WRITE_FILLER_SUPPORTED) || \
  162721. defined(PNG_READ_STRIP_ALPHA_SUPPORTED)
  162722. PNG_EXTERN void png_do_strip_filler PNGARG((png_row_infop row_info,
  162723. png_bytep row, png_uint_32 flags));
  162724. #endif
  162725. #if defined(PNG_READ_SWAP_SUPPORTED) || defined(PNG_WRITE_SWAP_SUPPORTED)
  162726. PNG_EXTERN void png_do_swap PNGARG((png_row_infop row_info, png_bytep row));
  162727. #endif
  162728. #if defined(PNG_READ_PACKSWAP_SUPPORTED) || defined(PNG_WRITE_PACKSWAP_SUPPORTED)
  162729. PNG_EXTERN void png_do_packswap PNGARG((png_row_infop row_info, png_bytep row));
  162730. #endif
  162731. #if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
  162732. PNG_EXTERN int png_do_rgb_to_gray PNGARG((png_structp png_ptr, png_row_infop
  162733. row_info, png_bytep row));
  162734. #endif
  162735. #if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED)
  162736. PNG_EXTERN void png_do_gray_to_rgb PNGARG((png_row_infop row_info,
  162737. png_bytep row));
  162738. #endif
  162739. #if defined(PNG_READ_PACK_SUPPORTED)
  162740. PNG_EXTERN void png_do_unpack PNGARG((png_row_infop row_info, png_bytep row));
  162741. #endif
  162742. #if defined(PNG_READ_SHIFT_SUPPORTED)
  162743. PNG_EXTERN void png_do_unshift PNGARG((png_row_infop row_info, png_bytep row,
  162744. png_color_8p sig_bits));
  162745. #endif
  162746. #if defined(PNG_READ_INVERT_SUPPORTED) || defined(PNG_WRITE_INVERT_SUPPORTED)
  162747. PNG_EXTERN void png_do_invert PNGARG((png_row_infop row_info, png_bytep row));
  162748. #endif
  162749. #if defined(PNG_READ_16_TO_8_SUPPORTED)
  162750. PNG_EXTERN void png_do_chop PNGARG((png_row_infop row_info, png_bytep row));
  162751. #endif
  162752. #if defined(PNG_READ_DITHER_SUPPORTED)
  162753. PNG_EXTERN void png_do_dither PNGARG((png_row_infop row_info,
  162754. png_bytep row, png_bytep palette_lookup, png_bytep dither_lookup));
  162755. # if defined(PNG_CORRECT_PALETTE_SUPPORTED)
  162756. PNG_EXTERN void png_correct_palette PNGARG((png_structp png_ptr,
  162757. png_colorp palette, int num_palette));
  162758. # endif
  162759. #endif
  162760. #if defined(PNG_READ_BGR_SUPPORTED) || defined(PNG_WRITE_BGR_SUPPORTED)
  162761. PNG_EXTERN void png_do_bgr PNGARG((png_row_infop row_info, png_bytep row));
  162762. #endif
  162763. #if defined(PNG_WRITE_PACK_SUPPORTED)
  162764. PNG_EXTERN void png_do_pack PNGARG((png_row_infop row_info,
  162765. png_bytep row, png_uint_32 bit_depth));
  162766. #endif
  162767. #if defined(PNG_WRITE_SHIFT_SUPPORTED)
  162768. PNG_EXTERN void png_do_shift PNGARG((png_row_infop row_info, png_bytep row,
  162769. png_color_8p bit_depth));
  162770. #endif
  162771. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  162772. #if defined(PNG_READ_GAMMA_SUPPORTED)
  162773. PNG_EXTERN void png_do_background PNGARG((png_row_infop row_info, png_bytep row,
  162774. png_color_16p trans_values, png_color_16p background,
  162775. png_color_16p background_1,
  162776. png_bytep gamma_table, png_bytep gamma_from_1, png_bytep gamma_to_1,
  162777. png_uint_16pp gamma_16, png_uint_16pp gamma_16_from_1,
  162778. png_uint_16pp gamma_16_to_1, int gamma_shift));
  162779. #else
  162780. PNG_EXTERN void png_do_background PNGARG((png_row_infop row_info, png_bytep row,
  162781. png_color_16p trans_values, png_color_16p background));
  162782. #endif
  162783. #endif
  162784. #if defined(PNG_READ_GAMMA_SUPPORTED)
  162785. PNG_EXTERN void png_do_gamma PNGARG((png_row_infop row_info, png_bytep row,
  162786. png_bytep gamma_table, png_uint_16pp gamma_16_table,
  162787. int gamma_shift));
  162788. #endif
  162789. #if defined(PNG_READ_EXPAND_SUPPORTED)
  162790. PNG_EXTERN void png_do_expand_palette PNGARG((png_row_infop row_info,
  162791. png_bytep row, png_colorp palette, png_bytep trans, int num_trans));
  162792. PNG_EXTERN void png_do_expand PNGARG((png_row_infop row_info,
  162793. png_bytep row, png_color_16p trans_value));
  162794. #endif
  162795. PNG_EXTERN void png_handle_IHDR PNGARG((png_structp png_ptr, png_infop info_ptr,
  162796. png_uint_32 length));
  162797. PNG_EXTERN void png_handle_PLTE PNGARG((png_structp png_ptr, png_infop info_ptr,
  162798. png_uint_32 length));
  162799. PNG_EXTERN void png_handle_IEND PNGARG((png_structp png_ptr, png_infop info_ptr,
  162800. png_uint_32 length));
  162801. #if defined(PNG_READ_bKGD_SUPPORTED)
  162802. PNG_EXTERN void png_handle_bKGD PNGARG((png_structp png_ptr, png_infop info_ptr,
  162803. png_uint_32 length));
  162804. #endif
  162805. #if defined(PNG_READ_cHRM_SUPPORTED)
  162806. PNG_EXTERN void png_handle_cHRM PNGARG((png_structp png_ptr, png_infop info_ptr,
  162807. png_uint_32 length));
  162808. #endif
  162809. #if defined(PNG_READ_gAMA_SUPPORTED)
  162810. PNG_EXTERN void png_handle_gAMA PNGARG((png_structp png_ptr, png_infop info_ptr,
  162811. png_uint_32 length));
  162812. #endif
  162813. #if defined(PNG_READ_hIST_SUPPORTED)
  162814. PNG_EXTERN void png_handle_hIST PNGARG((png_structp png_ptr, png_infop info_ptr,
  162815. png_uint_32 length));
  162816. #endif
  162817. #if defined(PNG_READ_iCCP_SUPPORTED)
  162818. extern void png_handle_iCCP PNGARG((png_structp png_ptr, png_infop info_ptr,
  162819. png_uint_32 length));
  162820. #endif /* PNG_READ_iCCP_SUPPORTED */
  162821. #if defined(PNG_READ_iTXt_SUPPORTED)
  162822. PNG_EXTERN void png_handle_iTXt PNGARG((png_structp png_ptr, png_infop info_ptr,
  162823. png_uint_32 length));
  162824. #endif
  162825. #if defined(PNG_READ_oFFs_SUPPORTED)
  162826. PNG_EXTERN void png_handle_oFFs PNGARG((png_structp png_ptr, png_infop info_ptr,
  162827. png_uint_32 length));
  162828. #endif
  162829. #if defined(PNG_READ_pCAL_SUPPORTED)
  162830. PNG_EXTERN void png_handle_pCAL PNGARG((png_structp png_ptr, png_infop info_ptr,
  162831. png_uint_32 length));
  162832. #endif
  162833. #if defined(PNG_READ_pHYs_SUPPORTED)
  162834. PNG_EXTERN void png_handle_pHYs PNGARG((png_structp png_ptr, png_infop info_ptr,
  162835. png_uint_32 length));
  162836. #endif
  162837. #if defined(PNG_READ_sBIT_SUPPORTED)
  162838. PNG_EXTERN void png_handle_sBIT PNGARG((png_structp png_ptr, png_infop info_ptr,
  162839. png_uint_32 length));
  162840. #endif
  162841. #if defined(PNG_READ_sCAL_SUPPORTED)
  162842. PNG_EXTERN void png_handle_sCAL PNGARG((png_structp png_ptr, png_infop info_ptr,
  162843. png_uint_32 length));
  162844. #endif
  162845. #if defined(PNG_READ_sPLT_SUPPORTED)
  162846. extern void png_handle_sPLT PNGARG((png_structp png_ptr, png_infop info_ptr,
  162847. png_uint_32 length));
  162848. #endif /* PNG_READ_sPLT_SUPPORTED */
  162849. #if defined(PNG_READ_sRGB_SUPPORTED)
  162850. PNG_EXTERN void png_handle_sRGB PNGARG((png_structp png_ptr, png_infop info_ptr,
  162851. png_uint_32 length));
  162852. #endif
  162853. #if defined(PNG_READ_tEXt_SUPPORTED)
  162854. PNG_EXTERN void png_handle_tEXt PNGARG((png_structp png_ptr, png_infop info_ptr,
  162855. png_uint_32 length));
  162856. #endif
  162857. #if defined(PNG_READ_tIME_SUPPORTED)
  162858. PNG_EXTERN void png_handle_tIME PNGARG((png_structp png_ptr, png_infop info_ptr,
  162859. png_uint_32 length));
  162860. #endif
  162861. #if defined(PNG_READ_tRNS_SUPPORTED)
  162862. PNG_EXTERN void png_handle_tRNS PNGARG((png_structp png_ptr, png_infop info_ptr,
  162863. png_uint_32 length));
  162864. #endif
  162865. #if defined(PNG_READ_zTXt_SUPPORTED)
  162866. PNG_EXTERN void png_handle_zTXt PNGARG((png_structp png_ptr, png_infop info_ptr,
  162867. png_uint_32 length));
  162868. #endif
  162869. PNG_EXTERN void png_handle_unknown PNGARG((png_structp png_ptr,
  162870. png_infop info_ptr, png_uint_32 length));
  162871. PNG_EXTERN void png_check_chunk_name PNGARG((png_structp png_ptr,
  162872. png_bytep chunk_name));
  162873. PNG_EXTERN void png_do_read_transformations PNGARG((png_structp png_ptr));
  162874. PNG_EXTERN void png_do_write_transformations PNGARG((png_structp png_ptr));
  162875. PNG_EXTERN void png_init_read_transformations PNGARG((png_structp png_ptr));
  162876. #ifdef PNG_PROGRESSIVE_READ_SUPPORTED
  162877. PNG_EXTERN void png_push_read_chunk PNGARG((png_structp png_ptr,
  162878. png_infop info_ptr));
  162879. PNG_EXTERN void png_push_read_sig PNGARG((png_structp png_ptr,
  162880. png_infop info_ptr));
  162881. PNG_EXTERN void png_push_check_crc PNGARG((png_structp png_ptr));
  162882. PNG_EXTERN void png_push_crc_skip PNGARG((png_structp png_ptr,
  162883. png_uint_32 length));
  162884. PNG_EXTERN void png_push_crc_finish PNGARG((png_structp png_ptr));
  162885. PNG_EXTERN void png_push_save_buffer PNGARG((png_structp png_ptr));
  162886. PNG_EXTERN void png_push_restore_buffer PNGARG((png_structp png_ptr,
  162887. png_bytep buffer, png_size_t buffer_length));
  162888. PNG_EXTERN void png_push_read_IDAT PNGARG((png_structp png_ptr));
  162889. PNG_EXTERN void png_process_IDAT_data PNGARG((png_structp png_ptr,
  162890. png_bytep buffer, png_size_t buffer_length));
  162891. PNG_EXTERN void png_push_process_row PNGARG((png_structp png_ptr));
  162892. PNG_EXTERN void png_push_handle_unknown PNGARG((png_structp png_ptr,
  162893. png_infop info_ptr, png_uint_32 length));
  162894. PNG_EXTERN void png_push_have_info PNGARG((png_structp png_ptr,
  162895. png_infop info_ptr));
  162896. PNG_EXTERN void png_push_have_end PNGARG((png_structp png_ptr,
  162897. png_infop info_ptr));
  162898. PNG_EXTERN void png_push_have_row PNGARG((png_structp png_ptr, png_bytep row));
  162899. PNG_EXTERN void png_push_read_end PNGARG((png_structp png_ptr,
  162900. png_infop info_ptr));
  162901. PNG_EXTERN void png_process_some_data PNGARG((png_structp png_ptr,
  162902. png_infop info_ptr));
  162903. PNG_EXTERN void png_read_push_finish_row PNGARG((png_structp png_ptr));
  162904. #if defined(PNG_READ_tEXt_SUPPORTED)
  162905. PNG_EXTERN void png_push_handle_tEXt PNGARG((png_structp png_ptr,
  162906. png_infop info_ptr, png_uint_32 length));
  162907. PNG_EXTERN void png_push_read_tEXt PNGARG((png_structp png_ptr,
  162908. png_infop info_ptr));
  162909. #endif
  162910. #if defined(PNG_READ_zTXt_SUPPORTED)
  162911. PNG_EXTERN void png_push_handle_zTXt PNGARG((png_structp png_ptr,
  162912. png_infop info_ptr, png_uint_32 length));
  162913. PNG_EXTERN void png_push_read_zTXt PNGARG((png_structp png_ptr,
  162914. png_infop info_ptr));
  162915. #endif
  162916. #if defined(PNG_READ_iTXt_SUPPORTED)
  162917. PNG_EXTERN void png_push_handle_iTXt PNGARG((png_structp png_ptr,
  162918. png_infop info_ptr, png_uint_32 length));
  162919. PNG_EXTERN void png_push_read_iTXt PNGARG((png_structp png_ptr,
  162920. png_infop info_ptr));
  162921. #endif
  162922. #endif /* PNG_PROGRESSIVE_READ_SUPPORTED */
  162923. #ifdef PNG_MNG_FEATURES_SUPPORTED
  162924. PNG_EXTERN void png_do_read_intrapixel PNGARG((png_row_infop row_info,
  162925. png_bytep row));
  162926. PNG_EXTERN void png_do_write_intrapixel PNGARG((png_row_infop row_info,
  162927. png_bytep row));
  162928. #endif
  162929. #if defined(PNG_ASSEMBLER_CODE_SUPPORTED)
  162930. #if defined(PNG_MMX_CODE_SUPPORTED)
  162931. /* PRIVATE */
  162932. PNG_EXTERN void png_init_mmx_flags PNGARG((png_structp png_ptr));
  162933. #endif
  162934. #endif
  162935. #if defined(PNG_INCH_CONVERSIONS) && defined(PNG_FLOATING_POINT_SUPPORTED)
  162936. PNG_EXTERN png_uint_32 png_get_pixels_per_inch PNGARG((png_structp png_ptr,
  162937. png_infop info_ptr));
  162938. PNG_EXTERN png_uint_32 png_get_x_pixels_per_inch PNGARG((png_structp png_ptr,
  162939. png_infop info_ptr));
  162940. PNG_EXTERN png_uint_32 png_get_y_pixels_per_inch PNGARG((png_structp png_ptr,
  162941. png_infop info_ptr));
  162942. PNG_EXTERN float png_get_x_offset_inches PNGARG((png_structp png_ptr,
  162943. png_infop info_ptr));
  162944. PNG_EXTERN float png_get_y_offset_inches PNGARG((png_structp png_ptr,
  162945. png_infop info_ptr));
  162946. #if defined(PNG_pHYs_SUPPORTED)
  162947. PNG_EXTERN png_uint_32 png_get_pHYs_dpi PNGARG((png_structp png_ptr,
  162948. png_infop info_ptr, png_uint_32 *res_x, png_uint_32 *res_y, int *unit_type));
  162949. #endif /* PNG_pHYs_SUPPORTED */
  162950. #endif /* PNG_INCH_CONVERSIONS && PNG_FLOATING_POINT_SUPPORTED */
  162951. #endif /* PNG_INTERNAL */
  162952. #ifdef __cplusplus
  162953. }
  162954. #endif
  162955. #endif /* PNG_VERSION_INFO_ONLY */
  162956. #endif /* PNG_H */
  162957. /********* End of inlined file: png.h *********/
  162958. #define PNG_NO_EXTERN
  162959. /********* Start of inlined file: png.c *********/
  162960. #define PNG_INTERNAL
  162961. #define PNG_NO_EXTERN
  162962. typedef version_1_2_21 Your_png_h_is_not_version_1_2_21;
  162963. #ifdef PNG_USE_GLOBAL_ARRAYS
  162964. PNG_CONST char png_libpng_ver[18] = PNG_LIBPNG_VER_STRING;
  162965. #ifdef PNG_READ_SUPPORTED
  162966. PNG_CONST png_byte FARDATA png_sig[8] = {137, 80, 78, 71, 13, 10, 26, 10};
  162967. #endif /* PNG_READ_SUPPORTED */
  162968. PNG_IHDR;
  162969. PNG_IDAT;
  162970. PNG_IEND;
  162971. PNG_PLTE;
  162972. PNG_bKGD;
  162973. PNG_cHRM;
  162974. PNG_gAMA;
  162975. PNG_hIST;
  162976. PNG_iCCP;
  162977. PNG_iTXt;
  162978. PNG_oFFs;
  162979. PNG_pCAL;
  162980. PNG_sCAL;
  162981. PNG_pHYs;
  162982. PNG_sBIT;
  162983. PNG_sPLT;
  162984. PNG_sRGB;
  162985. PNG_tEXt;
  162986. PNG_tIME;
  162987. PNG_tRNS;
  162988. PNG_zTXt;
  162989. #ifdef PNG_READ_SUPPORTED
  162990. PNG_CONST int FARDATA png_pass_start[] = {0, 4, 0, 2, 0, 1, 0};
  162991. PNG_CONST int FARDATA png_pass_inc[] = {8, 8, 4, 4, 2, 2, 1};
  162992. PNG_CONST int FARDATA png_pass_ystart[] = {0, 0, 4, 0, 2, 0, 1};
  162993. PNG_CONST int FARDATA png_pass_yinc[] = {8, 8, 8, 4, 4, 2, 2};
  162994. PNG_CONST int FARDATA png_pass_mask[] = {0x80, 0x08, 0x88, 0x22, 0xaa, 0x55, 0xff};
  162995. PNG_CONST int FARDATA png_pass_dsp_mask[]
  162996. = {0xff, 0x0f, 0xff, 0x33, 0xff, 0x55, 0xff};
  162997. #endif /* PNG_READ_SUPPORTED */
  162998. #endif /* PNG_USE_GLOBAL_ARRAYS */
  162999. #ifdef PNG_READ_SUPPORTED
  163000. void PNGAPI
  163001. png_set_sig_bytes(png_structp png_ptr, int num_bytes)
  163002. {
  163003. if(png_ptr == NULL) return;
  163004. png_debug(1, "in png_set_sig_bytes\n");
  163005. if (num_bytes > 8)
  163006. png_error(png_ptr, "Too many bytes for PNG signature.");
  163007. png_ptr->sig_bytes = (png_byte)(num_bytes < 0 ? 0 : num_bytes);
  163008. }
  163009. int PNGAPI
  163010. png_sig_cmp(png_bytep sig, png_size_t start, png_size_t num_to_check)
  163011. {
  163012. png_byte png_signature[8] = {137, 80, 78, 71, 13, 10, 26, 10};
  163013. if (num_to_check > 8)
  163014. num_to_check = 8;
  163015. else if (num_to_check < 1)
  163016. return (-1);
  163017. if (start > 7)
  163018. return (-1);
  163019. if (start + num_to_check > 8)
  163020. num_to_check = 8 - start;
  163021. return ((int)(png_memcmp(&sig[start], &png_signature[start], num_to_check)));
  163022. }
  163023. #if defined(PNG_1_0_X) || defined(PNG_1_2_X)
  163024. int PNGAPI
  163025. png_check_sig(png_bytep sig, int num)
  163026. {
  163027. return ((int)!png_sig_cmp(sig, (png_size_t)0, (png_size_t)num));
  163028. }
  163029. #endif
  163030. #endif /* PNG_READ_SUPPORTED */
  163031. #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
  163032. #ifdef PNG_1_0_X
  163033. voidpf PNGAPI
  163034. #else
  163035. voidpf /* private */
  163036. #endif
  163037. png_zalloc(voidpf png_ptr, uInt items, uInt size)
  163038. {
  163039. png_voidp ptr;
  163040. png_structp p=(png_structp)png_ptr;
  163041. png_uint_32 save_flags=p->flags;
  163042. png_uint_32 num_bytes;
  163043. if(png_ptr == NULL) return (NULL);
  163044. if (items > PNG_UINT_32_MAX/size)
  163045. {
  163046. png_warning (p, "Potential overflow in png_zalloc()");
  163047. return (NULL);
  163048. }
  163049. num_bytes = (png_uint_32)items * size;
  163050. p->flags|=PNG_FLAG_MALLOC_NULL_MEM_OK;
  163051. ptr = (png_voidp)png_malloc((png_structp)png_ptr, num_bytes);
  163052. p->flags=save_flags;
  163053. #if defined(PNG_1_0_X) && !defined(PNG_NO_ZALLOC_ZERO)
  163054. if (ptr == NULL)
  163055. return ((voidpf)ptr);
  163056. if (num_bytes > (png_uint_32)0x8000L)
  163057. {
  163058. png_memset(ptr, 0, (png_size_t)0x8000L);
  163059. png_memset((png_bytep)ptr + (png_size_t)0x8000L, 0,
  163060. (png_size_t)(num_bytes - (png_uint_32)0x8000L));
  163061. }
  163062. else
  163063. {
  163064. png_memset(ptr, 0, (png_size_t)num_bytes);
  163065. }
  163066. #endif
  163067. return ((voidpf)ptr);
  163068. }
  163069. #ifdef PNG_1_0_X
  163070. void PNGAPI
  163071. #else
  163072. void /* private */
  163073. #endif
  163074. png_zfree(voidpf png_ptr, voidpf ptr)
  163075. {
  163076. png_free((png_structp)png_ptr, (png_voidp)ptr);
  163077. }
  163078. void /* PRIVATE */
  163079. png_reset_crc(png_structp png_ptr)
  163080. {
  163081. png_ptr->crc = crc32(0, Z_NULL, 0);
  163082. }
  163083. void /* PRIVATE */
  163084. png_calculate_crc(png_structp png_ptr, png_bytep ptr, png_size_t length)
  163085. {
  163086. int need_crc = 1;
  163087. if (png_ptr->chunk_name[0] & 0x20) /* ancillary */
  163088. {
  163089. if ((png_ptr->flags & PNG_FLAG_CRC_ANCILLARY_MASK) ==
  163090. (PNG_FLAG_CRC_ANCILLARY_USE | PNG_FLAG_CRC_ANCILLARY_NOWARN))
  163091. need_crc = 0;
  163092. }
  163093. else /* critical */
  163094. {
  163095. if (png_ptr->flags & PNG_FLAG_CRC_CRITICAL_IGNORE)
  163096. need_crc = 0;
  163097. }
  163098. if (need_crc)
  163099. png_ptr->crc = crc32(png_ptr->crc, ptr, (uInt)length);
  163100. }
  163101. png_infop PNGAPI
  163102. png_create_info_struct(png_structp png_ptr)
  163103. {
  163104. png_infop info_ptr;
  163105. png_debug(1, "in png_create_info_struct\n");
  163106. if(png_ptr == NULL) return (NULL);
  163107. #ifdef PNG_USER_MEM_SUPPORTED
  163108. info_ptr = (png_infop)png_create_struct_2(PNG_STRUCT_INFO,
  163109. png_ptr->malloc_fn, png_ptr->mem_ptr);
  163110. #else
  163111. info_ptr = (png_infop)png_create_struct(PNG_STRUCT_INFO);
  163112. #endif
  163113. if (info_ptr != NULL)
  163114. png_info_init_3(&info_ptr, png_sizeof(png_info));
  163115. return (info_ptr);
  163116. }
  163117. void PNGAPI
  163118. png_destroy_info_struct(png_structp png_ptr, png_infopp info_ptr_ptr)
  163119. {
  163120. png_infop info_ptr = NULL;
  163121. if(png_ptr == NULL) return;
  163122. png_debug(1, "in png_destroy_info_struct\n");
  163123. if (info_ptr_ptr != NULL)
  163124. info_ptr = *info_ptr_ptr;
  163125. if (info_ptr != NULL)
  163126. {
  163127. png_info_destroy(png_ptr, info_ptr);
  163128. #ifdef PNG_USER_MEM_SUPPORTED
  163129. png_destroy_struct_2((png_voidp)info_ptr, png_ptr->free_fn,
  163130. png_ptr->mem_ptr);
  163131. #else
  163132. png_destroy_struct((png_voidp)info_ptr);
  163133. #endif
  163134. *info_ptr_ptr = NULL;
  163135. }
  163136. }
  163137. #if defined(PNG_1_0_X) || defined(PNG_1_2_X)
  163138. #undef png_info_init
  163139. void PNGAPI
  163140. png_info_init(png_infop info_ptr)
  163141. {
  163142. png_info_init_3(&info_ptr, 0);
  163143. }
  163144. #endif
  163145. void PNGAPI
  163146. png_info_init_3(png_infopp ptr_ptr, png_size_t png_info_struct_size)
  163147. {
  163148. png_infop info_ptr = *ptr_ptr;
  163149. if(info_ptr == NULL) return;
  163150. png_debug(1, "in png_info_init_3\n");
  163151. if(png_sizeof(png_info) > png_info_struct_size)
  163152. {
  163153. png_destroy_struct(info_ptr);
  163154. info_ptr = (png_infop)png_create_struct(PNG_STRUCT_INFO);
  163155. *ptr_ptr = info_ptr;
  163156. }
  163157. png_memset(info_ptr, 0, png_sizeof (png_info));
  163158. }
  163159. #ifdef PNG_FREE_ME_SUPPORTED
  163160. void PNGAPI
  163161. png_data_freer(png_structp png_ptr, png_infop info_ptr,
  163162. int freer, png_uint_32 mask)
  163163. {
  163164. png_debug(1, "in png_data_freer\n");
  163165. if (png_ptr == NULL || info_ptr == NULL)
  163166. return;
  163167. if(freer == PNG_DESTROY_WILL_FREE_DATA)
  163168. info_ptr->free_me |= mask;
  163169. else if(freer == PNG_USER_WILL_FREE_DATA)
  163170. info_ptr->free_me &= ~mask;
  163171. else
  163172. png_warning(png_ptr,
  163173. "Unknown freer parameter in png_data_freer.");
  163174. }
  163175. #endif
  163176. void PNGAPI
  163177. png_free_data(png_structp png_ptr, png_infop info_ptr, png_uint_32 mask,
  163178. int num)
  163179. {
  163180. png_debug(1, "in png_free_data\n");
  163181. if (png_ptr == NULL || info_ptr == NULL)
  163182. return;
  163183. #if defined(PNG_TEXT_SUPPORTED)
  163184. #ifdef PNG_FREE_ME_SUPPORTED
  163185. if ((mask & PNG_FREE_TEXT) & info_ptr->free_me)
  163186. #else
  163187. if (mask & PNG_FREE_TEXT)
  163188. #endif
  163189. {
  163190. if (num != -1)
  163191. {
  163192. if (info_ptr->text && info_ptr->text[num].key)
  163193. {
  163194. png_free(png_ptr, info_ptr->text[num].key);
  163195. info_ptr->text[num].key = NULL;
  163196. }
  163197. }
  163198. else
  163199. {
  163200. int i;
  163201. for (i = 0; i < info_ptr->num_text; i++)
  163202. png_free_data(png_ptr, info_ptr, PNG_FREE_TEXT, i);
  163203. png_free(png_ptr, info_ptr->text);
  163204. info_ptr->text = NULL;
  163205. info_ptr->num_text=0;
  163206. }
  163207. }
  163208. #endif
  163209. #if defined(PNG_tRNS_SUPPORTED)
  163210. #ifdef PNG_FREE_ME_SUPPORTED
  163211. if ((mask & PNG_FREE_TRNS) & info_ptr->free_me)
  163212. #else
  163213. if ((mask & PNG_FREE_TRNS) && (png_ptr->flags & PNG_FLAG_FREE_TRNS))
  163214. #endif
  163215. {
  163216. png_free(png_ptr, info_ptr->trans);
  163217. info_ptr->valid &= ~PNG_INFO_tRNS;
  163218. #ifndef PNG_FREE_ME_SUPPORTED
  163219. png_ptr->flags &= ~PNG_FLAG_FREE_TRNS;
  163220. #endif
  163221. info_ptr->trans = NULL;
  163222. }
  163223. #endif
  163224. #if defined(PNG_sCAL_SUPPORTED)
  163225. #ifdef PNG_FREE_ME_SUPPORTED
  163226. if ((mask & PNG_FREE_SCAL) & info_ptr->free_me)
  163227. #else
  163228. if (mask & PNG_FREE_SCAL)
  163229. #endif
  163230. {
  163231. #if defined(PNG_FIXED_POINT_SUPPORTED) && !defined(PNG_FLOATING_POINT_SUPPORTED)
  163232. png_free(png_ptr, info_ptr->scal_s_width);
  163233. png_free(png_ptr, info_ptr->scal_s_height);
  163234. info_ptr->scal_s_width = NULL;
  163235. info_ptr->scal_s_height = NULL;
  163236. #endif
  163237. info_ptr->valid &= ~PNG_INFO_sCAL;
  163238. }
  163239. #endif
  163240. #if defined(PNG_pCAL_SUPPORTED)
  163241. #ifdef PNG_FREE_ME_SUPPORTED
  163242. if ((mask & PNG_FREE_PCAL) & info_ptr->free_me)
  163243. #else
  163244. if (mask & PNG_FREE_PCAL)
  163245. #endif
  163246. {
  163247. png_free(png_ptr, info_ptr->pcal_purpose);
  163248. png_free(png_ptr, info_ptr->pcal_units);
  163249. info_ptr->pcal_purpose = NULL;
  163250. info_ptr->pcal_units = NULL;
  163251. if (info_ptr->pcal_params != NULL)
  163252. {
  163253. int i;
  163254. for (i = 0; i < (int)info_ptr->pcal_nparams; i++)
  163255. {
  163256. png_free(png_ptr, info_ptr->pcal_params[i]);
  163257. info_ptr->pcal_params[i]=NULL;
  163258. }
  163259. png_free(png_ptr, info_ptr->pcal_params);
  163260. info_ptr->pcal_params = NULL;
  163261. }
  163262. info_ptr->valid &= ~PNG_INFO_pCAL;
  163263. }
  163264. #endif
  163265. #if defined(PNG_iCCP_SUPPORTED)
  163266. #ifdef PNG_FREE_ME_SUPPORTED
  163267. if ((mask & PNG_FREE_ICCP) & info_ptr->free_me)
  163268. #else
  163269. if (mask & PNG_FREE_ICCP)
  163270. #endif
  163271. {
  163272. png_free(png_ptr, info_ptr->iccp_name);
  163273. png_free(png_ptr, info_ptr->iccp_profile);
  163274. info_ptr->iccp_name = NULL;
  163275. info_ptr->iccp_profile = NULL;
  163276. info_ptr->valid &= ~PNG_INFO_iCCP;
  163277. }
  163278. #endif
  163279. #if defined(PNG_sPLT_SUPPORTED)
  163280. #ifdef PNG_FREE_ME_SUPPORTED
  163281. if ((mask & PNG_FREE_SPLT) & info_ptr->free_me)
  163282. #else
  163283. if (mask & PNG_FREE_SPLT)
  163284. #endif
  163285. {
  163286. if (num != -1)
  163287. {
  163288. if(info_ptr->splt_palettes)
  163289. {
  163290. png_free(png_ptr, info_ptr->splt_palettes[num].name);
  163291. png_free(png_ptr, info_ptr->splt_palettes[num].entries);
  163292. info_ptr->splt_palettes[num].name = NULL;
  163293. info_ptr->splt_palettes[num].entries = NULL;
  163294. }
  163295. }
  163296. else
  163297. {
  163298. if(info_ptr->splt_palettes_num)
  163299. {
  163300. int i;
  163301. for (i = 0; i < (int)info_ptr->splt_palettes_num; i++)
  163302. png_free_data(png_ptr, info_ptr, PNG_FREE_SPLT, i);
  163303. png_free(png_ptr, info_ptr->splt_palettes);
  163304. info_ptr->splt_palettes = NULL;
  163305. info_ptr->splt_palettes_num = 0;
  163306. }
  163307. info_ptr->valid &= ~PNG_INFO_sPLT;
  163308. }
  163309. }
  163310. #endif
  163311. #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
  163312. if(png_ptr->unknown_chunk.data)
  163313. {
  163314. png_free(png_ptr, png_ptr->unknown_chunk.data);
  163315. png_ptr->unknown_chunk.data = NULL;
  163316. }
  163317. #ifdef PNG_FREE_ME_SUPPORTED
  163318. if ((mask & PNG_FREE_UNKN) & info_ptr->free_me)
  163319. #else
  163320. if (mask & PNG_FREE_UNKN)
  163321. #endif
  163322. {
  163323. if (num != -1)
  163324. {
  163325. if(info_ptr->unknown_chunks)
  163326. {
  163327. png_free(png_ptr, info_ptr->unknown_chunks[num].data);
  163328. info_ptr->unknown_chunks[num].data = NULL;
  163329. }
  163330. }
  163331. else
  163332. {
  163333. int i;
  163334. if(info_ptr->unknown_chunks_num)
  163335. {
  163336. for (i = 0; i < (int)info_ptr->unknown_chunks_num; i++)
  163337. png_free_data(png_ptr, info_ptr, PNG_FREE_UNKN, i);
  163338. png_free(png_ptr, info_ptr->unknown_chunks);
  163339. info_ptr->unknown_chunks = NULL;
  163340. info_ptr->unknown_chunks_num = 0;
  163341. }
  163342. }
  163343. }
  163344. #endif
  163345. #if defined(PNG_hIST_SUPPORTED)
  163346. #ifdef PNG_FREE_ME_SUPPORTED
  163347. if ((mask & PNG_FREE_HIST) & info_ptr->free_me)
  163348. #else
  163349. if ((mask & PNG_FREE_HIST) && (png_ptr->flags & PNG_FLAG_FREE_HIST))
  163350. #endif
  163351. {
  163352. png_free(png_ptr, info_ptr->hist);
  163353. info_ptr->hist = NULL;
  163354. info_ptr->valid &= ~PNG_INFO_hIST;
  163355. #ifndef PNG_FREE_ME_SUPPORTED
  163356. png_ptr->flags &= ~PNG_FLAG_FREE_HIST;
  163357. #endif
  163358. }
  163359. #endif
  163360. #ifdef PNG_FREE_ME_SUPPORTED
  163361. if ((mask & PNG_FREE_PLTE) & info_ptr->free_me)
  163362. #else
  163363. if ((mask & PNG_FREE_PLTE) && (png_ptr->flags & PNG_FLAG_FREE_PLTE))
  163364. #endif
  163365. {
  163366. png_zfree(png_ptr, info_ptr->palette);
  163367. info_ptr->palette = NULL;
  163368. info_ptr->valid &= ~PNG_INFO_PLTE;
  163369. #ifndef PNG_FREE_ME_SUPPORTED
  163370. png_ptr->flags &= ~PNG_FLAG_FREE_PLTE;
  163371. #endif
  163372. info_ptr->num_palette = 0;
  163373. }
  163374. #if defined(PNG_INFO_IMAGE_SUPPORTED)
  163375. #ifdef PNG_FREE_ME_SUPPORTED
  163376. if ((mask & PNG_FREE_ROWS) & info_ptr->free_me)
  163377. #else
  163378. if (mask & PNG_FREE_ROWS)
  163379. #endif
  163380. {
  163381. if(info_ptr->row_pointers)
  163382. {
  163383. int row;
  163384. for (row = 0; row < (int)info_ptr->height; row++)
  163385. {
  163386. png_free(png_ptr, info_ptr->row_pointers[row]);
  163387. info_ptr->row_pointers[row]=NULL;
  163388. }
  163389. png_free(png_ptr, info_ptr->row_pointers);
  163390. info_ptr->row_pointers=NULL;
  163391. }
  163392. info_ptr->valid &= ~PNG_INFO_IDAT;
  163393. }
  163394. #endif
  163395. #ifdef PNG_FREE_ME_SUPPORTED
  163396. if(num == -1)
  163397. info_ptr->free_me &= ~mask;
  163398. else
  163399. info_ptr->free_me &= ~(mask & ~PNG_FREE_MUL);
  163400. #endif
  163401. }
  163402. void /* PRIVATE */
  163403. png_info_destroy(png_structp png_ptr, png_infop info_ptr)
  163404. {
  163405. png_debug(1, "in png_info_destroy\n");
  163406. png_free_data(png_ptr, info_ptr, PNG_FREE_ALL, -1);
  163407. #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
  163408. if (png_ptr->num_chunk_list)
  163409. {
  163410. png_free(png_ptr, png_ptr->chunk_list);
  163411. png_ptr->chunk_list=NULL;
  163412. png_ptr->num_chunk_list=0;
  163413. }
  163414. #endif
  163415. png_info_init_3(&info_ptr, png_sizeof(png_info));
  163416. }
  163417. #endif /* defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) */
  163418. png_voidp PNGAPI
  163419. png_get_io_ptr(png_structp png_ptr)
  163420. {
  163421. if(png_ptr == NULL) return (NULL);
  163422. return (png_ptr->io_ptr);
  163423. }
  163424. #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
  163425. #if !defined(PNG_NO_STDIO)
  163426. void PNGAPI
  163427. png_init_io(png_structp png_ptr, png_FILE_p fp)
  163428. {
  163429. png_debug(1, "in png_init_io\n");
  163430. if(png_ptr == NULL) return;
  163431. png_ptr->io_ptr = (png_voidp)fp;
  163432. }
  163433. #endif
  163434. #if defined(PNG_TIME_RFC1123_SUPPORTED)
  163435. png_charp PNGAPI
  163436. png_convert_to_rfc1123(png_structp png_ptr, png_timep ptime)
  163437. {
  163438. static PNG_CONST char short_months[12][4] =
  163439. {"Jan", "Feb", "Mar", "Apr", "May", "Jun",
  163440. "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
  163441. if(png_ptr == NULL) return (NULL);
  163442. if (png_ptr->time_buffer == NULL)
  163443. {
  163444. png_ptr->time_buffer = (png_charp)png_malloc(png_ptr, (png_uint_32)(29*
  163445. png_sizeof(char)));
  163446. }
  163447. #if defined(_WIN32_WCE)
  163448. {
  163449. wchar_t time_buf[29];
  163450. wsprintf(time_buf, TEXT("%d %S %d %02d:%02d:%02d +0000"),
  163451. ptime->day % 32, short_months[(ptime->month - 1) % 12],
  163452. ptime->year, ptime->hour % 24, ptime->minute % 60,
  163453. ptime->second % 61);
  163454. WideCharToMultiByte(CP_ACP, 0, time_buf, -1, png_ptr->time_buffer, 29,
  163455. NULL, NULL);
  163456. }
  163457. #else
  163458. #ifdef USE_FAR_KEYWORD
  163459. {
  163460. char near_time_buf[29];
  163461. png_snprintf6(near_time_buf,29,"%d %s %d %02d:%02d:%02d +0000",
  163462. ptime->day % 32, short_months[(ptime->month - 1) % 12],
  163463. ptime->year, ptime->hour % 24, ptime->minute % 60,
  163464. ptime->second % 61);
  163465. png_memcpy(png_ptr->time_buffer, near_time_buf,
  163466. 29*png_sizeof(char));
  163467. }
  163468. #else
  163469. png_snprintf6(png_ptr->time_buffer,29,"%d %s %d %02d:%02d:%02d +0000",
  163470. ptime->day % 32, short_months[(ptime->month - 1) % 12],
  163471. ptime->year, ptime->hour % 24, ptime->minute % 60,
  163472. ptime->second % 61);
  163473. #endif
  163474. #endif /* _WIN32_WCE */
  163475. return ((png_charp)png_ptr->time_buffer);
  163476. }
  163477. #endif /* PNG_TIME_RFC1123_SUPPORTED */
  163478. #endif /* defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) */
  163479. png_charp PNGAPI
  163480. png_get_copyright(png_structp png_ptr)
  163481. {
  163482. png_ptr = png_ptr; /* silence compiler warning about unused png_ptr */
  163483. return ((png_charp) "\n libpng version 1.2.21 - October 4, 2007\n\
  163484. Copyright (c) 1998-2007 Glenn Randers-Pehrson\n\
  163485. Copyright (c) 1996-1997 Andreas Dilger\n\
  163486. Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc.\n");
  163487. }
  163488. png_charp PNGAPI
  163489. png_get_libpng_ver(png_structp png_ptr)
  163490. {
  163491. png_ptr = png_ptr; /* silence compiler warning about unused png_ptr */
  163492. return ((png_charp) PNG_LIBPNG_VER_STRING);
  163493. }
  163494. png_charp PNGAPI
  163495. png_get_header_ver(png_structp png_ptr)
  163496. {
  163497. png_ptr = png_ptr; /* silence compiler warning about unused png_ptr */
  163498. return ((png_charp) PNG_LIBPNG_VER_STRING);
  163499. }
  163500. png_charp PNGAPI
  163501. png_get_header_version(png_structp png_ptr)
  163502. {
  163503. png_ptr = png_ptr; /* silence compiler warning about unused png_ptr */
  163504. return ((png_charp) PNG_HEADER_VERSION_STRING
  163505. #ifndef PNG_READ_SUPPORTED
  163506. " (NO READ SUPPORT)"
  163507. #endif
  163508. "\n");
  163509. }
  163510. #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
  163511. #ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
  163512. int PNGAPI
  163513. png_handle_as_unknown(png_structp png_ptr, png_bytep chunk_name)
  163514. {
  163515. int i;
  163516. png_bytep p;
  163517. if(png_ptr == NULL || chunk_name == NULL || png_ptr->num_chunk_list<=0)
  163518. return 0;
  163519. p=png_ptr->chunk_list+png_ptr->num_chunk_list*5-5;
  163520. for (i = png_ptr->num_chunk_list; i; i--, p-=5)
  163521. if (!png_memcmp(chunk_name, p, 4))
  163522. return ((int)*(p+4));
  163523. return 0;
  163524. }
  163525. #endif
  163526. int PNGAPI
  163527. png_reset_zstream(png_structp png_ptr)
  163528. {
  163529. if (png_ptr == NULL) return Z_STREAM_ERROR;
  163530. return (inflateReset(&png_ptr->zstream));
  163531. }
  163532. #endif /* defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) */
  163533. png_uint_32 PNGAPI
  163534. png_access_version_number(void)
  163535. {
  163536. return((png_uint_32) PNG_LIBPNG_VER);
  163537. }
  163538. #if defined(PNG_READ_SUPPORTED) && defined(PNG_ASSEMBLER_CODE_SUPPORTED)
  163539. #if !defined(PNG_1_0_X)
  163540. int PNGAPI
  163541. png_mmx_support(void)
  163542. {
  163543. return -1;
  163544. }
  163545. #endif /* PNG_1_0_X */
  163546. #endif /* PNG_READ_SUPPORTED && PNG_ASSEMBLER_CODE_SUPPORTED */
  163547. #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
  163548. #ifdef PNG_SIZE_T
  163549. PNG_EXTERN png_size_t PNGAPI png_convert_size PNGARG((size_t size));
  163550. png_size_t PNGAPI
  163551. png_convert_size(size_t size)
  163552. {
  163553. if (size > (png_size_t)-1)
  163554. PNG_ABORT(); /* We haven't got access to png_ptr, so no png_error() */
  163555. return ((png_size_t)size);
  163556. }
  163557. #endif /* PNG_SIZE_T */
  163558. #endif /* defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) */
  163559. /********* End of inlined file: png.c *********/
  163560. /********* Start of inlined file: pngerror.c *********/
  163561. #define PNG_INTERNAL
  163562. #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
  163563. static void /* PRIVATE */
  163564. png_default_error PNGARG((png_structp png_ptr,
  163565. png_const_charp error_message));
  163566. #ifndef PNG_NO_WARNINGS
  163567. static void /* PRIVATE */
  163568. png_default_warning PNGARG((png_structp png_ptr,
  163569. png_const_charp warning_message));
  163570. #endif /* PNG_NO_WARNINGS */
  163571. #ifndef PNG_NO_ERROR_TEXT
  163572. void PNGAPI
  163573. png_error(png_structp png_ptr, png_const_charp error_message)
  163574. {
  163575. #ifdef PNG_ERROR_NUMBERS_SUPPORTED
  163576. char msg[16];
  163577. if (png_ptr != NULL)
  163578. {
  163579. if (png_ptr->flags&
  163580. (PNG_FLAG_STRIP_ERROR_NUMBERS|PNG_FLAG_STRIP_ERROR_TEXT))
  163581. {
  163582. if (*error_message == '#')
  163583. {
  163584. int offset;
  163585. for (offset=1; offset<15; offset++)
  163586. if (*(error_message+offset) == ' ')
  163587. break;
  163588. if (png_ptr->flags&PNG_FLAG_STRIP_ERROR_TEXT)
  163589. {
  163590. int i;
  163591. for (i=0; i<offset-1; i++)
  163592. msg[i]=error_message[i+1];
  163593. msg[i]='\0';
  163594. error_message=msg;
  163595. }
  163596. else
  163597. error_message+=offset;
  163598. }
  163599. else
  163600. {
  163601. if (png_ptr->flags&PNG_FLAG_STRIP_ERROR_TEXT)
  163602. {
  163603. msg[0]='0';
  163604. msg[1]='\0';
  163605. error_message=msg;
  163606. }
  163607. }
  163608. }
  163609. }
  163610. #endif
  163611. if (png_ptr != NULL && png_ptr->error_fn != NULL)
  163612. (*(png_ptr->error_fn))(png_ptr, error_message);
  163613. png_default_error(png_ptr, error_message);
  163614. }
  163615. #else
  163616. void PNGAPI
  163617. png_err(png_structp png_ptr)
  163618. {
  163619. if (png_ptr != NULL && png_ptr->error_fn != NULL)
  163620. (*(png_ptr->error_fn))(png_ptr, '\0');
  163621. png_default_error(png_ptr, '\0');
  163622. }
  163623. #endif /* PNG_NO_ERROR_TEXT */
  163624. #ifndef PNG_NO_WARNINGS
  163625. void PNGAPI
  163626. png_warning(png_structp png_ptr, png_const_charp warning_message)
  163627. {
  163628. int offset = 0;
  163629. if (png_ptr != NULL)
  163630. {
  163631. #ifdef PNG_ERROR_NUMBERS_SUPPORTED
  163632. if (png_ptr->flags&
  163633. (PNG_FLAG_STRIP_ERROR_NUMBERS|PNG_FLAG_STRIP_ERROR_TEXT))
  163634. #endif
  163635. {
  163636. if (*warning_message == '#')
  163637. {
  163638. for (offset=1; offset<15; offset++)
  163639. if (*(warning_message+offset) == ' ')
  163640. break;
  163641. }
  163642. }
  163643. if (png_ptr != NULL && png_ptr->warning_fn != NULL)
  163644. (*(png_ptr->warning_fn))(png_ptr, warning_message+offset);
  163645. }
  163646. else
  163647. png_default_warning(png_ptr, warning_message+offset);
  163648. }
  163649. #endif /* PNG_NO_WARNINGS */
  163650. #define isnonalpha(c) ((c) < 65 || (c) > 122 || ((c) > 90 && (c) < 97))
  163651. #if !defined(PNG_NO_WARNINGS) || !defined(PNG_NO_ERROR_TEXT)
  163652. static void /* PRIVATE */
  163653. png_format_buffer(png_structp png_ptr, png_charp buffer, png_const_charp
  163654. error_message)
  163655. {
  163656. int iout = 0, iin = 0;
  163657. while (iin < 4)
  163658. {
  163659. int c = png_ptr->chunk_name[iin++];
  163660. if (isnonalpha(c))
  163661. {
  163662. buffer[iout++] = '[';
  163663. buffer[iout++] = png_digit[(c & 0xf0) >> 4];
  163664. buffer[iout++] = png_digit[c & 0x0f];
  163665. buffer[iout++] = ']';
  163666. }
  163667. else
  163668. {
  163669. buffer[iout++] = (png_byte)c;
  163670. }
  163671. }
  163672. if (error_message == NULL)
  163673. buffer[iout] = 0;
  163674. else
  163675. {
  163676. buffer[iout++] = ':';
  163677. buffer[iout++] = ' ';
  163678. png_strncpy(buffer+iout, error_message, 63);
  163679. buffer[iout+63] = 0;
  163680. }
  163681. }
  163682. #ifdef PNG_READ_SUPPORTED
  163683. void PNGAPI
  163684. png_chunk_error(png_structp png_ptr, png_const_charp error_message)
  163685. {
  163686. char msg[18+64];
  163687. if (png_ptr == NULL)
  163688. png_error(png_ptr, error_message);
  163689. else
  163690. {
  163691. png_format_buffer(png_ptr, msg, error_message);
  163692. png_error(png_ptr, msg);
  163693. }
  163694. }
  163695. #endif /* PNG_READ_SUPPORTED */
  163696. #endif /* !defined(PNG_NO_WARNINGS) || !defined(PNG_NO_ERROR_TEXT) */
  163697. #ifndef PNG_NO_WARNINGS
  163698. void PNGAPI
  163699. png_chunk_warning(png_structp png_ptr, png_const_charp warning_message)
  163700. {
  163701. char msg[18+64];
  163702. if (png_ptr == NULL)
  163703. png_warning(png_ptr, warning_message);
  163704. else
  163705. {
  163706. png_format_buffer(png_ptr, msg, warning_message);
  163707. png_warning(png_ptr, msg);
  163708. }
  163709. }
  163710. #endif /* PNG_NO_WARNINGS */
  163711. static void /* PRIVATE */
  163712. png_default_error(png_structp png_ptr, png_const_charp error_message)
  163713. {
  163714. #ifndef PNG_NO_CONSOLE_IO
  163715. #ifdef PNG_ERROR_NUMBERS_SUPPORTED
  163716. if (*error_message == '#')
  163717. {
  163718. int offset;
  163719. char error_number[16];
  163720. for (offset=0; offset<15; offset++)
  163721. {
  163722. error_number[offset] = *(error_message+offset+1);
  163723. if (*(error_message+offset) == ' ')
  163724. break;
  163725. }
  163726. if((offset > 1) && (offset < 15))
  163727. {
  163728. error_number[offset-1]='\0';
  163729. fprintf(stderr, "libpng error no. %s: %s\n", error_number,
  163730. error_message+offset);
  163731. }
  163732. else
  163733. fprintf(stderr, "libpng error: %s, offset=%d\n", error_message,offset);
  163734. }
  163735. else
  163736. #endif
  163737. fprintf(stderr, "libpng error: %s\n", error_message);
  163738. #endif
  163739. #ifdef PNG_SETJMP_SUPPORTED
  163740. if (png_ptr)
  163741. {
  163742. # ifdef USE_FAR_KEYWORD
  163743. {
  163744. jmp_buf jmpbuf;
  163745. png_memcpy(jmpbuf, png_ptr->jmpbuf, png_sizeof(jmp_buf));
  163746. longjmp(jmpbuf, 1);
  163747. }
  163748. # else
  163749. longjmp(png_ptr->jmpbuf, 1);
  163750. # endif
  163751. }
  163752. #else
  163753. PNG_ABORT();
  163754. #endif
  163755. #ifdef PNG_NO_CONSOLE_IO
  163756. error_message = error_message; /* make compiler happy */
  163757. #endif
  163758. }
  163759. #ifndef PNG_NO_WARNINGS
  163760. static void /* PRIVATE */
  163761. png_default_warning(png_structp png_ptr, png_const_charp warning_message)
  163762. {
  163763. #ifndef PNG_NO_CONSOLE_IO
  163764. # ifdef PNG_ERROR_NUMBERS_SUPPORTED
  163765. if (*warning_message == '#')
  163766. {
  163767. int offset;
  163768. char warning_number[16];
  163769. for (offset=0; offset<15; offset++)
  163770. {
  163771. warning_number[offset]=*(warning_message+offset+1);
  163772. if (*(warning_message+offset) == ' ')
  163773. break;
  163774. }
  163775. if((offset > 1) && (offset < 15))
  163776. {
  163777. warning_number[offset-1]='\0';
  163778. fprintf(stderr, "libpng warning no. %s: %s\n", warning_number,
  163779. warning_message+offset);
  163780. }
  163781. else
  163782. fprintf(stderr, "libpng warning: %s\n", warning_message);
  163783. }
  163784. else
  163785. # endif
  163786. fprintf(stderr, "libpng warning: %s\n", warning_message);
  163787. #else
  163788. warning_message = warning_message; /* make compiler happy */
  163789. #endif
  163790. png_ptr = png_ptr; /* make compiler happy */
  163791. }
  163792. #endif /* PNG_NO_WARNINGS */
  163793. void PNGAPI
  163794. png_set_error_fn(png_structp png_ptr, png_voidp error_ptr,
  163795. png_error_ptr error_fn, png_error_ptr warning_fn)
  163796. {
  163797. if (png_ptr == NULL)
  163798. return;
  163799. png_ptr->error_ptr = error_ptr;
  163800. png_ptr->error_fn = error_fn;
  163801. png_ptr->warning_fn = warning_fn;
  163802. }
  163803. png_voidp PNGAPI
  163804. png_get_error_ptr(png_structp png_ptr)
  163805. {
  163806. if (png_ptr == NULL)
  163807. return NULL;
  163808. return ((png_voidp)png_ptr->error_ptr);
  163809. }
  163810. #ifdef PNG_ERROR_NUMBERS_SUPPORTED
  163811. void PNGAPI
  163812. png_set_strip_error_numbers(png_structp png_ptr, png_uint_32 strip_mode)
  163813. {
  163814. if(png_ptr != NULL)
  163815. {
  163816. png_ptr->flags &=
  163817. ((~(PNG_FLAG_STRIP_ERROR_NUMBERS|PNG_FLAG_STRIP_ERROR_TEXT))&strip_mode);
  163818. }
  163819. }
  163820. #endif
  163821. #endif /* PNG_READ_SUPPORTED || PNG_WRITE_SUPPORTED */
  163822. /********* End of inlined file: pngerror.c *********/
  163823. /********* Start of inlined file: pngget.c *********/
  163824. #define PNG_INTERNAL
  163825. #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
  163826. png_uint_32 PNGAPI
  163827. png_get_valid(png_structp png_ptr, png_infop info_ptr, png_uint_32 flag)
  163828. {
  163829. if (png_ptr != NULL && info_ptr != NULL)
  163830. return(info_ptr->valid & flag);
  163831. else
  163832. return(0);
  163833. }
  163834. png_uint_32 PNGAPI
  163835. png_get_rowbytes(png_structp png_ptr, png_infop info_ptr)
  163836. {
  163837. if (png_ptr != NULL && info_ptr != NULL)
  163838. return(info_ptr->rowbytes);
  163839. else
  163840. return(0);
  163841. }
  163842. #if defined(PNG_INFO_IMAGE_SUPPORTED)
  163843. png_bytepp PNGAPI
  163844. png_get_rows(png_structp png_ptr, png_infop info_ptr)
  163845. {
  163846. if (png_ptr != NULL && info_ptr != NULL)
  163847. return(info_ptr->row_pointers);
  163848. else
  163849. return(0);
  163850. }
  163851. #endif
  163852. #ifdef PNG_EASY_ACCESS_SUPPORTED
  163853. png_uint_32 PNGAPI
  163854. png_get_image_width(png_structp png_ptr, png_infop info_ptr)
  163855. {
  163856. if (png_ptr != NULL && info_ptr != NULL)
  163857. {
  163858. return info_ptr->width;
  163859. }
  163860. return (0);
  163861. }
  163862. png_uint_32 PNGAPI
  163863. png_get_image_height(png_structp png_ptr, png_infop info_ptr)
  163864. {
  163865. if (png_ptr != NULL && info_ptr != NULL)
  163866. {
  163867. return info_ptr->height;
  163868. }
  163869. return (0);
  163870. }
  163871. png_byte PNGAPI
  163872. png_get_bit_depth(png_structp png_ptr, png_infop info_ptr)
  163873. {
  163874. if (png_ptr != NULL && info_ptr != NULL)
  163875. {
  163876. return info_ptr->bit_depth;
  163877. }
  163878. return (0);
  163879. }
  163880. png_byte PNGAPI
  163881. png_get_color_type(png_structp png_ptr, png_infop info_ptr)
  163882. {
  163883. if (png_ptr != NULL && info_ptr != NULL)
  163884. {
  163885. return info_ptr->color_type;
  163886. }
  163887. return (0);
  163888. }
  163889. png_byte PNGAPI
  163890. png_get_filter_type(png_structp png_ptr, png_infop info_ptr)
  163891. {
  163892. if (png_ptr != NULL && info_ptr != NULL)
  163893. {
  163894. return info_ptr->filter_type;
  163895. }
  163896. return (0);
  163897. }
  163898. png_byte PNGAPI
  163899. png_get_interlace_type(png_structp png_ptr, png_infop info_ptr)
  163900. {
  163901. if (png_ptr != NULL && info_ptr != NULL)
  163902. {
  163903. return info_ptr->interlace_type;
  163904. }
  163905. return (0);
  163906. }
  163907. png_byte PNGAPI
  163908. png_get_compression_type(png_structp png_ptr, png_infop info_ptr)
  163909. {
  163910. if (png_ptr != NULL && info_ptr != NULL)
  163911. {
  163912. return info_ptr->compression_type;
  163913. }
  163914. return (0);
  163915. }
  163916. png_uint_32 PNGAPI
  163917. png_get_x_pixels_per_meter(png_structp png_ptr, png_infop info_ptr)
  163918. {
  163919. if (png_ptr != NULL && info_ptr != NULL)
  163920. #if defined(PNG_pHYs_SUPPORTED)
  163921. if (info_ptr->valid & PNG_INFO_pHYs)
  163922. {
  163923. png_debug1(1, "in %s retrieval function\n", "png_get_x_pixels_per_meter");
  163924. if(info_ptr->phys_unit_type != PNG_RESOLUTION_METER)
  163925. return (0);
  163926. else return (info_ptr->x_pixels_per_unit);
  163927. }
  163928. #else
  163929. return (0);
  163930. #endif
  163931. return (0);
  163932. }
  163933. png_uint_32 PNGAPI
  163934. png_get_y_pixels_per_meter(png_structp png_ptr, png_infop info_ptr)
  163935. {
  163936. if (png_ptr != NULL && info_ptr != NULL)
  163937. #if defined(PNG_pHYs_SUPPORTED)
  163938. if (info_ptr->valid & PNG_INFO_pHYs)
  163939. {
  163940. png_debug1(1, "in %s retrieval function\n", "png_get_y_pixels_per_meter");
  163941. if(info_ptr->phys_unit_type != PNG_RESOLUTION_METER)
  163942. return (0);
  163943. else return (info_ptr->y_pixels_per_unit);
  163944. }
  163945. #else
  163946. return (0);
  163947. #endif
  163948. return (0);
  163949. }
  163950. png_uint_32 PNGAPI
  163951. png_get_pixels_per_meter(png_structp png_ptr, png_infop info_ptr)
  163952. {
  163953. if (png_ptr != NULL && info_ptr != NULL)
  163954. #if defined(PNG_pHYs_SUPPORTED)
  163955. if (info_ptr->valid & PNG_INFO_pHYs)
  163956. {
  163957. png_debug1(1, "in %s retrieval function\n", "png_get_pixels_per_meter");
  163958. if(info_ptr->phys_unit_type != PNG_RESOLUTION_METER ||
  163959. info_ptr->x_pixels_per_unit != info_ptr->y_pixels_per_unit)
  163960. return (0);
  163961. else return (info_ptr->x_pixels_per_unit);
  163962. }
  163963. #else
  163964. return (0);
  163965. #endif
  163966. return (0);
  163967. }
  163968. #ifdef PNG_FLOATING_POINT_SUPPORTED
  163969. float PNGAPI
  163970. png_get_pixel_aspect_ratio(png_structp png_ptr, png_infop info_ptr)
  163971. {
  163972. if (png_ptr != NULL && info_ptr != NULL)
  163973. #if defined(PNG_pHYs_SUPPORTED)
  163974. if (info_ptr->valid & PNG_INFO_pHYs)
  163975. {
  163976. png_debug1(1, "in %s retrieval function\n", "png_get_aspect_ratio");
  163977. if (info_ptr->x_pixels_per_unit == 0)
  163978. return ((float)0.0);
  163979. else
  163980. return ((float)((float)info_ptr->y_pixels_per_unit
  163981. /(float)info_ptr->x_pixels_per_unit));
  163982. }
  163983. #else
  163984. return (0.0);
  163985. #endif
  163986. return ((float)0.0);
  163987. }
  163988. #endif
  163989. png_int_32 PNGAPI
  163990. png_get_x_offset_microns(png_structp png_ptr, png_infop info_ptr)
  163991. {
  163992. if (png_ptr != NULL && info_ptr != NULL)
  163993. #if defined(PNG_oFFs_SUPPORTED)
  163994. if (info_ptr->valid & PNG_INFO_oFFs)
  163995. {
  163996. png_debug1(1, "in %s retrieval function\n", "png_get_x_offset_microns");
  163997. if(info_ptr->offset_unit_type != PNG_OFFSET_MICROMETER)
  163998. return (0);
  163999. else return (info_ptr->x_offset);
  164000. }
  164001. #else
  164002. return (0);
  164003. #endif
  164004. return (0);
  164005. }
  164006. png_int_32 PNGAPI
  164007. png_get_y_offset_microns(png_structp png_ptr, png_infop info_ptr)
  164008. {
  164009. if (png_ptr != NULL && info_ptr != NULL)
  164010. #if defined(PNG_oFFs_SUPPORTED)
  164011. if (info_ptr->valid & PNG_INFO_oFFs)
  164012. {
  164013. png_debug1(1, "in %s retrieval function\n", "png_get_y_offset_microns");
  164014. if(info_ptr->offset_unit_type != PNG_OFFSET_MICROMETER)
  164015. return (0);
  164016. else return (info_ptr->y_offset);
  164017. }
  164018. #else
  164019. return (0);
  164020. #endif
  164021. return (0);
  164022. }
  164023. png_int_32 PNGAPI
  164024. png_get_x_offset_pixels(png_structp png_ptr, png_infop info_ptr)
  164025. {
  164026. if (png_ptr != NULL && info_ptr != NULL)
  164027. #if defined(PNG_oFFs_SUPPORTED)
  164028. if (info_ptr->valid & PNG_INFO_oFFs)
  164029. {
  164030. png_debug1(1, "in %s retrieval function\n", "png_get_x_offset_microns");
  164031. if(info_ptr->offset_unit_type != PNG_OFFSET_PIXEL)
  164032. return (0);
  164033. else return (info_ptr->x_offset);
  164034. }
  164035. #else
  164036. return (0);
  164037. #endif
  164038. return (0);
  164039. }
  164040. png_int_32 PNGAPI
  164041. png_get_y_offset_pixels(png_structp png_ptr, png_infop info_ptr)
  164042. {
  164043. if (png_ptr != NULL && info_ptr != NULL)
  164044. #if defined(PNG_oFFs_SUPPORTED)
  164045. if (info_ptr->valid & PNG_INFO_oFFs)
  164046. {
  164047. png_debug1(1, "in %s retrieval function\n", "png_get_y_offset_microns");
  164048. if(info_ptr->offset_unit_type != PNG_OFFSET_PIXEL)
  164049. return (0);
  164050. else return (info_ptr->y_offset);
  164051. }
  164052. #else
  164053. return (0);
  164054. #endif
  164055. return (0);
  164056. }
  164057. #if defined(PNG_INCH_CONVERSIONS) && defined(PNG_FLOATING_POINT_SUPPORTED)
  164058. png_uint_32 PNGAPI
  164059. png_get_pixels_per_inch(png_structp png_ptr, png_infop info_ptr)
  164060. {
  164061. return ((png_uint_32)((float)png_get_pixels_per_meter(png_ptr, info_ptr)
  164062. *.0254 +.5));
  164063. }
  164064. png_uint_32 PNGAPI
  164065. png_get_x_pixels_per_inch(png_structp png_ptr, png_infop info_ptr)
  164066. {
  164067. return ((png_uint_32)((float)png_get_x_pixels_per_meter(png_ptr, info_ptr)
  164068. *.0254 +.5));
  164069. }
  164070. png_uint_32 PNGAPI
  164071. png_get_y_pixels_per_inch(png_structp png_ptr, png_infop info_ptr)
  164072. {
  164073. return ((png_uint_32)((float)png_get_y_pixels_per_meter(png_ptr, info_ptr)
  164074. *.0254 +.5));
  164075. }
  164076. float PNGAPI
  164077. png_get_x_offset_inches(png_structp png_ptr, png_infop info_ptr)
  164078. {
  164079. return ((float)png_get_x_offset_microns(png_ptr, info_ptr)
  164080. *.00003937);
  164081. }
  164082. float PNGAPI
  164083. png_get_y_offset_inches(png_structp png_ptr, png_infop info_ptr)
  164084. {
  164085. return ((float)png_get_y_offset_microns(png_ptr, info_ptr)
  164086. *.00003937);
  164087. }
  164088. #if defined(PNG_pHYs_SUPPORTED)
  164089. png_uint_32 PNGAPI
  164090. png_get_pHYs_dpi(png_structp png_ptr, png_infop info_ptr,
  164091. png_uint_32 *res_x, png_uint_32 *res_y, int *unit_type)
  164092. {
  164093. png_uint_32 retval = 0;
  164094. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pHYs))
  164095. {
  164096. png_debug1(1, "in %s retrieval function\n", "pHYs");
  164097. if (res_x != NULL)
  164098. {
  164099. *res_x = info_ptr->x_pixels_per_unit;
  164100. retval |= PNG_INFO_pHYs;
  164101. }
  164102. if (res_y != NULL)
  164103. {
  164104. *res_y = info_ptr->y_pixels_per_unit;
  164105. retval |= PNG_INFO_pHYs;
  164106. }
  164107. if (unit_type != NULL)
  164108. {
  164109. *unit_type = (int)info_ptr->phys_unit_type;
  164110. retval |= PNG_INFO_pHYs;
  164111. if(*unit_type == 1)
  164112. {
  164113. if (res_x != NULL) *res_x = (png_uint_32)(*res_x * .0254 + .50);
  164114. if (res_y != NULL) *res_y = (png_uint_32)(*res_y * .0254 + .50);
  164115. }
  164116. }
  164117. }
  164118. return (retval);
  164119. }
  164120. #endif /* PNG_pHYs_SUPPORTED */
  164121. #endif /* PNG_INCH_CONVERSIONS && PNG_FLOATING_POINT_SUPPORTED */
  164122. #endif /* PNG_EASY_ACCESS_SUPPORTED */
  164123. png_byte PNGAPI
  164124. png_get_channels(png_structp png_ptr, png_infop info_ptr)
  164125. {
  164126. if (png_ptr != NULL && info_ptr != NULL)
  164127. return(info_ptr->channels);
  164128. else
  164129. return (0);
  164130. }
  164131. png_bytep PNGAPI
  164132. png_get_signature(png_structp png_ptr, png_infop info_ptr)
  164133. {
  164134. if (png_ptr != NULL && info_ptr != NULL)
  164135. return(info_ptr->signature);
  164136. else
  164137. return (NULL);
  164138. }
  164139. #if defined(PNG_bKGD_SUPPORTED)
  164140. png_uint_32 PNGAPI
  164141. png_get_bKGD(png_structp png_ptr, png_infop info_ptr,
  164142. png_color_16p *background)
  164143. {
  164144. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_bKGD)
  164145. && background != NULL)
  164146. {
  164147. png_debug1(1, "in %s retrieval function\n", "bKGD");
  164148. *background = &(info_ptr->background);
  164149. return (PNG_INFO_bKGD);
  164150. }
  164151. return (0);
  164152. }
  164153. #endif
  164154. #if defined(PNG_cHRM_SUPPORTED)
  164155. #ifdef PNG_FLOATING_POINT_SUPPORTED
  164156. png_uint_32 PNGAPI
  164157. png_get_cHRM(png_structp png_ptr, png_infop info_ptr,
  164158. double *white_x, double *white_y, double *red_x, double *red_y,
  164159. double *green_x, double *green_y, double *blue_x, double *blue_y)
  164160. {
  164161. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_cHRM))
  164162. {
  164163. png_debug1(1, "in %s retrieval function\n", "cHRM");
  164164. if (white_x != NULL)
  164165. *white_x = (double)info_ptr->x_white;
  164166. if (white_y != NULL)
  164167. *white_y = (double)info_ptr->y_white;
  164168. if (red_x != NULL)
  164169. *red_x = (double)info_ptr->x_red;
  164170. if (red_y != NULL)
  164171. *red_y = (double)info_ptr->y_red;
  164172. if (green_x != NULL)
  164173. *green_x = (double)info_ptr->x_green;
  164174. if (green_y != NULL)
  164175. *green_y = (double)info_ptr->y_green;
  164176. if (blue_x != NULL)
  164177. *blue_x = (double)info_ptr->x_blue;
  164178. if (blue_y != NULL)
  164179. *blue_y = (double)info_ptr->y_blue;
  164180. return (PNG_INFO_cHRM);
  164181. }
  164182. return (0);
  164183. }
  164184. #endif
  164185. #ifdef PNG_FIXED_POINT_SUPPORTED
  164186. png_uint_32 PNGAPI
  164187. png_get_cHRM_fixed(png_structp png_ptr, png_infop info_ptr,
  164188. png_fixed_point *white_x, png_fixed_point *white_y, png_fixed_point *red_x,
  164189. png_fixed_point *red_y, png_fixed_point *green_x, png_fixed_point *green_y,
  164190. png_fixed_point *blue_x, png_fixed_point *blue_y)
  164191. {
  164192. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_cHRM))
  164193. {
  164194. png_debug1(1, "in %s retrieval function\n", "cHRM");
  164195. if (white_x != NULL)
  164196. *white_x = info_ptr->int_x_white;
  164197. if (white_y != NULL)
  164198. *white_y = info_ptr->int_y_white;
  164199. if (red_x != NULL)
  164200. *red_x = info_ptr->int_x_red;
  164201. if (red_y != NULL)
  164202. *red_y = info_ptr->int_y_red;
  164203. if (green_x != NULL)
  164204. *green_x = info_ptr->int_x_green;
  164205. if (green_y != NULL)
  164206. *green_y = info_ptr->int_y_green;
  164207. if (blue_x != NULL)
  164208. *blue_x = info_ptr->int_x_blue;
  164209. if (blue_y != NULL)
  164210. *blue_y = info_ptr->int_y_blue;
  164211. return (PNG_INFO_cHRM);
  164212. }
  164213. return (0);
  164214. }
  164215. #endif
  164216. #endif
  164217. #if defined(PNG_gAMA_SUPPORTED)
  164218. #ifdef PNG_FLOATING_POINT_SUPPORTED
  164219. png_uint_32 PNGAPI
  164220. png_get_gAMA(png_structp png_ptr, png_infop info_ptr, double *file_gamma)
  164221. {
  164222. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_gAMA)
  164223. && file_gamma != NULL)
  164224. {
  164225. png_debug1(1, "in %s retrieval function\n", "gAMA");
  164226. *file_gamma = (double)info_ptr->gamma;
  164227. return (PNG_INFO_gAMA);
  164228. }
  164229. return (0);
  164230. }
  164231. #endif
  164232. #ifdef PNG_FIXED_POINT_SUPPORTED
  164233. png_uint_32 PNGAPI
  164234. png_get_gAMA_fixed(png_structp png_ptr, png_infop info_ptr,
  164235. png_fixed_point *int_file_gamma)
  164236. {
  164237. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_gAMA)
  164238. && int_file_gamma != NULL)
  164239. {
  164240. png_debug1(1, "in %s retrieval function\n", "gAMA");
  164241. *int_file_gamma = info_ptr->int_gamma;
  164242. return (PNG_INFO_gAMA);
  164243. }
  164244. return (0);
  164245. }
  164246. #endif
  164247. #endif
  164248. #if defined(PNG_sRGB_SUPPORTED)
  164249. png_uint_32 PNGAPI
  164250. png_get_sRGB(png_structp png_ptr, png_infop info_ptr, int *file_srgb_intent)
  164251. {
  164252. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_sRGB)
  164253. && file_srgb_intent != NULL)
  164254. {
  164255. png_debug1(1, "in %s retrieval function\n", "sRGB");
  164256. *file_srgb_intent = (int)info_ptr->srgb_intent;
  164257. return (PNG_INFO_sRGB);
  164258. }
  164259. return (0);
  164260. }
  164261. #endif
  164262. #if defined(PNG_iCCP_SUPPORTED)
  164263. png_uint_32 PNGAPI
  164264. png_get_iCCP(png_structp png_ptr, png_infop info_ptr,
  164265. png_charpp name, int *compression_type,
  164266. png_charpp profile, png_uint_32 *proflen)
  164267. {
  164268. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_iCCP)
  164269. && name != NULL && profile != NULL && proflen != NULL)
  164270. {
  164271. png_debug1(1, "in %s retrieval function\n", "iCCP");
  164272. *name = info_ptr->iccp_name;
  164273. *profile = info_ptr->iccp_profile;
  164274. *proflen = (int)info_ptr->iccp_proflen;
  164275. *compression_type = (int)info_ptr->iccp_compression;
  164276. return (PNG_INFO_iCCP);
  164277. }
  164278. return (0);
  164279. }
  164280. #endif
  164281. #if defined(PNG_sPLT_SUPPORTED)
  164282. png_uint_32 PNGAPI
  164283. png_get_sPLT(png_structp png_ptr, png_infop info_ptr,
  164284. png_sPLT_tpp spalettes)
  164285. {
  164286. if (png_ptr != NULL && info_ptr != NULL && spalettes != NULL)
  164287. {
  164288. *spalettes = info_ptr->splt_palettes;
  164289. return ((png_uint_32)info_ptr->splt_palettes_num);
  164290. }
  164291. return (0);
  164292. }
  164293. #endif
  164294. #if defined(PNG_hIST_SUPPORTED)
  164295. png_uint_32 PNGAPI
  164296. png_get_hIST(png_structp png_ptr, png_infop info_ptr, png_uint_16p *hist)
  164297. {
  164298. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_hIST)
  164299. && hist != NULL)
  164300. {
  164301. png_debug1(1, "in %s retrieval function\n", "hIST");
  164302. *hist = info_ptr->hist;
  164303. return (PNG_INFO_hIST);
  164304. }
  164305. return (0);
  164306. }
  164307. #endif
  164308. png_uint_32 PNGAPI
  164309. png_get_IHDR(png_structp png_ptr, png_infop info_ptr,
  164310. png_uint_32 *width, png_uint_32 *height, int *bit_depth,
  164311. int *color_type, int *interlace_type, int *compression_type,
  164312. int *filter_type)
  164313. {
  164314. if (png_ptr != NULL && info_ptr != NULL && width != NULL && height != NULL &&
  164315. bit_depth != NULL && color_type != NULL)
  164316. {
  164317. png_debug1(1, "in %s retrieval function\n", "IHDR");
  164318. *width = info_ptr->width;
  164319. *height = info_ptr->height;
  164320. *bit_depth = info_ptr->bit_depth;
  164321. if (info_ptr->bit_depth < 1 || info_ptr->bit_depth > 16)
  164322. png_error(png_ptr, "Invalid bit depth");
  164323. *color_type = info_ptr->color_type;
  164324. if (info_ptr->color_type > 6)
  164325. png_error(png_ptr, "Invalid color type");
  164326. if (compression_type != NULL)
  164327. *compression_type = info_ptr->compression_type;
  164328. if (filter_type != NULL)
  164329. *filter_type = info_ptr->filter_type;
  164330. if (interlace_type != NULL)
  164331. *interlace_type = info_ptr->interlace_type;
  164332. if (*width == 0 || *width > PNG_UINT_31_MAX)
  164333. png_error(png_ptr, "Invalid image width");
  164334. if (*height == 0 || *height > PNG_UINT_31_MAX)
  164335. png_error(png_ptr, "Invalid image height");
  164336. if (info_ptr->width > (PNG_UINT_32_MAX
  164337. >> 3) /* 8-byte RGBA pixels */
  164338. - 64 /* bigrowbuf hack */
  164339. - 1 /* filter byte */
  164340. - 7*8 /* rounding of width to multiple of 8 pixels */
  164341. - 8) /* extra max_pixel_depth pad */
  164342. {
  164343. png_warning(png_ptr,
  164344. "Width too large for libpng to process image data.");
  164345. }
  164346. return (1);
  164347. }
  164348. return (0);
  164349. }
  164350. #if defined(PNG_oFFs_SUPPORTED)
  164351. png_uint_32 PNGAPI
  164352. png_get_oFFs(png_structp png_ptr, png_infop info_ptr,
  164353. png_int_32 *offset_x, png_int_32 *offset_y, int *unit_type)
  164354. {
  164355. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_oFFs)
  164356. && offset_x != NULL && offset_y != NULL && unit_type != NULL)
  164357. {
  164358. png_debug1(1, "in %s retrieval function\n", "oFFs");
  164359. *offset_x = info_ptr->x_offset;
  164360. *offset_y = info_ptr->y_offset;
  164361. *unit_type = (int)info_ptr->offset_unit_type;
  164362. return (PNG_INFO_oFFs);
  164363. }
  164364. return (0);
  164365. }
  164366. #endif
  164367. #if defined(PNG_pCAL_SUPPORTED)
  164368. png_uint_32 PNGAPI
  164369. png_get_pCAL(png_structp png_ptr, png_infop info_ptr,
  164370. png_charp *purpose, png_int_32 *X0, png_int_32 *X1, int *type, int *nparams,
  164371. png_charp *units, png_charpp *params)
  164372. {
  164373. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pCAL)
  164374. && purpose != NULL && X0 != NULL && X1 != NULL && type != NULL &&
  164375. nparams != NULL && units != NULL && params != NULL)
  164376. {
  164377. png_debug1(1, "in %s retrieval function\n", "pCAL");
  164378. *purpose = info_ptr->pcal_purpose;
  164379. *X0 = info_ptr->pcal_X0;
  164380. *X1 = info_ptr->pcal_X1;
  164381. *type = (int)info_ptr->pcal_type;
  164382. *nparams = (int)info_ptr->pcal_nparams;
  164383. *units = info_ptr->pcal_units;
  164384. *params = info_ptr->pcal_params;
  164385. return (PNG_INFO_pCAL);
  164386. }
  164387. return (0);
  164388. }
  164389. #endif
  164390. #if defined(PNG_sCAL_SUPPORTED)
  164391. #ifdef PNG_FLOATING_POINT_SUPPORTED
  164392. png_uint_32 PNGAPI
  164393. png_get_sCAL(png_structp png_ptr, png_infop info_ptr,
  164394. int *unit, double *width, double *height)
  164395. {
  164396. if (png_ptr != NULL && info_ptr != NULL &&
  164397. (info_ptr->valid & PNG_INFO_sCAL))
  164398. {
  164399. *unit = info_ptr->scal_unit;
  164400. *width = info_ptr->scal_pixel_width;
  164401. *height = info_ptr->scal_pixel_height;
  164402. return (PNG_INFO_sCAL);
  164403. }
  164404. return(0);
  164405. }
  164406. #else
  164407. #ifdef PNG_FIXED_POINT_SUPPORTED
  164408. png_uint_32 PNGAPI
  164409. png_get_sCAL_s(png_structp png_ptr, png_infop info_ptr,
  164410. int *unit, png_charpp width, png_charpp height)
  164411. {
  164412. if (png_ptr != NULL && info_ptr != NULL &&
  164413. (info_ptr->valid & PNG_INFO_sCAL))
  164414. {
  164415. *unit = info_ptr->scal_unit;
  164416. *width = info_ptr->scal_s_width;
  164417. *height = info_ptr->scal_s_height;
  164418. return (PNG_INFO_sCAL);
  164419. }
  164420. return(0);
  164421. }
  164422. #endif
  164423. #endif
  164424. #endif
  164425. #if defined(PNG_pHYs_SUPPORTED)
  164426. png_uint_32 PNGAPI
  164427. png_get_pHYs(png_structp png_ptr, png_infop info_ptr,
  164428. png_uint_32 *res_x, png_uint_32 *res_y, int *unit_type)
  164429. {
  164430. png_uint_32 retval = 0;
  164431. if (png_ptr != NULL && info_ptr != NULL &&
  164432. (info_ptr->valid & PNG_INFO_pHYs))
  164433. {
  164434. png_debug1(1, "in %s retrieval function\n", "pHYs");
  164435. if (res_x != NULL)
  164436. {
  164437. *res_x = info_ptr->x_pixels_per_unit;
  164438. retval |= PNG_INFO_pHYs;
  164439. }
  164440. if (res_y != NULL)
  164441. {
  164442. *res_y = info_ptr->y_pixels_per_unit;
  164443. retval |= PNG_INFO_pHYs;
  164444. }
  164445. if (unit_type != NULL)
  164446. {
  164447. *unit_type = (int)info_ptr->phys_unit_type;
  164448. retval |= PNG_INFO_pHYs;
  164449. }
  164450. }
  164451. return (retval);
  164452. }
  164453. #endif
  164454. png_uint_32 PNGAPI
  164455. png_get_PLTE(png_structp png_ptr, png_infop info_ptr, png_colorp *palette,
  164456. int *num_palette)
  164457. {
  164458. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_PLTE)
  164459. && palette != NULL)
  164460. {
  164461. png_debug1(1, "in %s retrieval function\n", "PLTE");
  164462. *palette = info_ptr->palette;
  164463. *num_palette = info_ptr->num_palette;
  164464. png_debug1(3, "num_palette = %d\n", *num_palette);
  164465. return (PNG_INFO_PLTE);
  164466. }
  164467. return (0);
  164468. }
  164469. #if defined(PNG_sBIT_SUPPORTED)
  164470. png_uint_32 PNGAPI
  164471. png_get_sBIT(png_structp png_ptr, png_infop info_ptr, png_color_8p *sig_bit)
  164472. {
  164473. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_sBIT)
  164474. && sig_bit != NULL)
  164475. {
  164476. png_debug1(1, "in %s retrieval function\n", "sBIT");
  164477. *sig_bit = &(info_ptr->sig_bit);
  164478. return (PNG_INFO_sBIT);
  164479. }
  164480. return (0);
  164481. }
  164482. #endif
  164483. #if defined(PNG_TEXT_SUPPORTED)
  164484. png_uint_32 PNGAPI
  164485. png_get_text(png_structp png_ptr, png_infop info_ptr, png_textp *text_ptr,
  164486. int *num_text)
  164487. {
  164488. if (png_ptr != NULL && info_ptr != NULL && info_ptr->num_text > 0)
  164489. {
  164490. png_debug1(1, "in %s retrieval function\n",
  164491. (png_ptr->chunk_name[0] == '\0' ? "text"
  164492. : (png_const_charp)png_ptr->chunk_name));
  164493. if (text_ptr != NULL)
  164494. *text_ptr = info_ptr->text;
  164495. if (num_text != NULL)
  164496. *num_text = info_ptr->num_text;
  164497. return ((png_uint_32)info_ptr->num_text);
  164498. }
  164499. if (num_text != NULL)
  164500. *num_text = 0;
  164501. return(0);
  164502. }
  164503. #endif
  164504. #if defined(PNG_tIME_SUPPORTED)
  164505. png_uint_32 PNGAPI
  164506. png_get_tIME(png_structp png_ptr, png_infop info_ptr, png_timep *mod_time)
  164507. {
  164508. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_tIME)
  164509. && mod_time != NULL)
  164510. {
  164511. png_debug1(1, "in %s retrieval function\n", "tIME");
  164512. *mod_time = &(info_ptr->mod_time);
  164513. return (PNG_INFO_tIME);
  164514. }
  164515. return (0);
  164516. }
  164517. #endif
  164518. #if defined(PNG_tRNS_SUPPORTED)
  164519. png_uint_32 PNGAPI
  164520. png_get_tRNS(png_structp png_ptr, png_infop info_ptr,
  164521. png_bytep *trans, int *num_trans, png_color_16p *trans_values)
  164522. {
  164523. png_uint_32 retval = 0;
  164524. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_tRNS))
  164525. {
  164526. png_debug1(1, "in %s retrieval function\n", "tRNS");
  164527. if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  164528. {
  164529. if (trans != NULL)
  164530. {
  164531. *trans = info_ptr->trans;
  164532. retval |= PNG_INFO_tRNS;
  164533. }
  164534. if (trans_values != NULL)
  164535. *trans_values = &(info_ptr->trans_values);
  164536. }
  164537. else /* if (info_ptr->color_type != PNG_COLOR_TYPE_PALETTE) */
  164538. {
  164539. if (trans_values != NULL)
  164540. {
  164541. *trans_values = &(info_ptr->trans_values);
  164542. retval |= PNG_INFO_tRNS;
  164543. }
  164544. if(trans != NULL)
  164545. *trans = NULL;
  164546. }
  164547. if(num_trans != NULL)
  164548. {
  164549. *num_trans = info_ptr->num_trans;
  164550. retval |= PNG_INFO_tRNS;
  164551. }
  164552. }
  164553. return (retval);
  164554. }
  164555. #endif
  164556. #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
  164557. png_uint_32 PNGAPI
  164558. png_get_unknown_chunks(png_structp png_ptr, png_infop info_ptr,
  164559. png_unknown_chunkpp unknowns)
  164560. {
  164561. if (png_ptr != NULL && info_ptr != NULL && unknowns != NULL)
  164562. {
  164563. *unknowns = info_ptr->unknown_chunks;
  164564. return ((png_uint_32)info_ptr->unknown_chunks_num);
  164565. }
  164566. return (0);
  164567. }
  164568. #endif
  164569. #if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
  164570. png_byte PNGAPI
  164571. png_get_rgb_to_gray_status (png_structp png_ptr)
  164572. {
  164573. return (png_byte)(png_ptr? png_ptr->rgb_to_gray_status : 0);
  164574. }
  164575. #endif
  164576. #if defined(PNG_USER_CHUNKS_SUPPORTED)
  164577. png_voidp PNGAPI
  164578. png_get_user_chunk_ptr(png_structp png_ptr)
  164579. {
  164580. return (png_ptr? png_ptr->user_chunk_ptr : NULL);
  164581. }
  164582. #endif
  164583. #ifdef PNG_WRITE_SUPPORTED
  164584. png_uint_32 PNGAPI
  164585. png_get_compression_buffer_size(png_structp png_ptr)
  164586. {
  164587. return (png_uint_32)(png_ptr? png_ptr->zbuf_size : 0L);
  164588. }
  164589. #endif
  164590. #ifdef PNG_ASSEMBLER_CODE_SUPPORTED
  164591. #ifndef PNG_1_0_X
  164592. png_uint_32 PNGAPI
  164593. png_get_asm_flags (png_structp png_ptr)
  164594. {
  164595. return (png_ptr? 0L: 0L);
  164596. }
  164597. png_uint_32 PNGAPI
  164598. png_get_asm_flagmask (int flag_select)
  164599. {
  164600. flag_select=flag_select;
  164601. return 0L;
  164602. }
  164603. png_uint_32 PNGAPI
  164604. png_get_mmx_flagmask (int flag_select, int *compilerID)
  164605. {
  164606. flag_select=flag_select;
  164607. *compilerID = -1; /* unknown (i.e., no asm/MMX code compiled) */
  164608. return 0L;
  164609. }
  164610. png_byte PNGAPI
  164611. png_get_mmx_bitdepth_threshold (png_structp png_ptr)
  164612. {
  164613. return (png_ptr? 0: 0);
  164614. }
  164615. png_uint_32 PNGAPI
  164616. png_get_mmx_rowbytes_threshold (png_structp png_ptr)
  164617. {
  164618. return (png_ptr? 0L: 0L);
  164619. }
  164620. #endif /* ?PNG_1_0_X */
  164621. #endif /* ?PNG_ASSEMBLER_CODE_SUPPORTED */
  164622. #ifdef PNG_SET_USER_LIMITS_SUPPORTED
  164623. png_uint_32 PNGAPI
  164624. png_get_user_width_max (png_structp png_ptr)
  164625. {
  164626. return (png_ptr? png_ptr->user_width_max : 0);
  164627. }
  164628. png_uint_32 PNGAPI
  164629. png_get_user_height_max (png_structp png_ptr)
  164630. {
  164631. return (png_ptr? png_ptr->user_height_max : 0);
  164632. }
  164633. #endif /* ?PNG_SET_USER_LIMITS_SUPPORTED */
  164634. #endif /* PNG_READ_SUPPORTED || PNG_WRITE_SUPPORTED */
  164635. /********* End of inlined file: pngget.c *********/
  164636. /********* Start of inlined file: pngmem.c *********/
  164637. #define PNG_INTERNAL
  164638. #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
  164639. #if defined(__TURBOC__) && !defined(_Windows) && !defined(__FLAT__)
  164640. png_voidp /* PRIVATE */
  164641. png_create_struct(int type)
  164642. {
  164643. #ifdef PNG_USER_MEM_SUPPORTED
  164644. return (png_create_struct_2(type, png_malloc_ptr_NULL, png_voidp_NULL));
  164645. }
  164646. png_voidp /* PRIVATE */
  164647. png_create_struct_2(int type, png_malloc_ptr malloc_fn, png_voidp mem_ptr)
  164648. {
  164649. #endif /* PNG_USER_MEM_SUPPORTED */
  164650. png_size_t size;
  164651. png_voidp struct_ptr;
  164652. if (type == PNG_STRUCT_INFO)
  164653. size = png_sizeof(png_info);
  164654. else if (type == PNG_STRUCT_PNG)
  164655. size = png_sizeof(png_struct);
  164656. else
  164657. return (png_get_copyright(NULL));
  164658. #ifdef PNG_USER_MEM_SUPPORTED
  164659. if(malloc_fn != NULL)
  164660. {
  164661. png_struct dummy_struct;
  164662. png_structp png_ptr = &dummy_struct;
  164663. png_ptr->mem_ptr=mem_ptr;
  164664. struct_ptr = (*(malloc_fn))(png_ptr, (png_uint_32)size);
  164665. }
  164666. else
  164667. #endif /* PNG_USER_MEM_SUPPORTED */
  164668. struct_ptr = (png_voidp)farmalloc(size);
  164669. if (struct_ptr != NULL)
  164670. png_memset(struct_ptr, 0, size);
  164671. return (struct_ptr);
  164672. }
  164673. void /* PRIVATE */
  164674. png_destroy_struct(png_voidp struct_ptr)
  164675. {
  164676. #ifdef PNG_USER_MEM_SUPPORTED
  164677. png_destroy_struct_2(struct_ptr, png_free_ptr_NULL, png_voidp_NULL);
  164678. }
  164679. void /* PRIVATE */
  164680. png_destroy_struct_2(png_voidp struct_ptr, png_free_ptr free_fn,
  164681. png_voidp mem_ptr)
  164682. {
  164683. #endif
  164684. if (struct_ptr != NULL)
  164685. {
  164686. #ifdef PNG_USER_MEM_SUPPORTED
  164687. if(free_fn != NULL)
  164688. {
  164689. png_struct dummy_struct;
  164690. png_structp png_ptr = &dummy_struct;
  164691. png_ptr->mem_ptr=mem_ptr;
  164692. (*(free_fn))(png_ptr, struct_ptr);
  164693. return;
  164694. }
  164695. #endif /* PNG_USER_MEM_SUPPORTED */
  164696. farfree (struct_ptr);
  164697. }
  164698. }
  164699. png_voidp PNGAPI
  164700. png_malloc(png_structp png_ptr, png_uint_32 size)
  164701. {
  164702. png_voidp ret;
  164703. if (png_ptr == NULL || size == 0)
  164704. return (NULL);
  164705. #ifdef PNG_USER_MEM_SUPPORTED
  164706. if(png_ptr->malloc_fn != NULL)
  164707. ret = ((png_voidp)(*(png_ptr->malloc_fn))(png_ptr, (png_size_t)size));
  164708. else
  164709. ret = (png_malloc_default(png_ptr, size));
  164710. if (ret == NULL && (png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
  164711. png_error(png_ptr, "Out of memory!");
  164712. return (ret);
  164713. }
  164714. png_voidp PNGAPI
  164715. png_malloc_default(png_structp png_ptr, png_uint_32 size)
  164716. {
  164717. png_voidp ret;
  164718. #endif /* PNG_USER_MEM_SUPPORTED */
  164719. if (png_ptr == NULL || size == 0)
  164720. return (NULL);
  164721. #ifdef PNG_MAX_MALLOC_64K
  164722. if (size > (png_uint_32)65536L)
  164723. {
  164724. png_warning(png_ptr, "Cannot Allocate > 64K");
  164725. ret = NULL;
  164726. }
  164727. else
  164728. #endif
  164729. if (size != (size_t)size)
  164730. ret = NULL;
  164731. else if (size == (png_uint_32)65536L)
  164732. {
  164733. if (png_ptr->offset_table == NULL)
  164734. {
  164735. ret = farmalloc(size);
  164736. if (ret == NULL || ((png_size_t)ret & 0xffff))
  164737. {
  164738. int num_blocks;
  164739. png_uint_32 total_size;
  164740. png_bytep table;
  164741. int i;
  164742. png_byte huge * hptr;
  164743. if (ret != NULL)
  164744. {
  164745. farfree(ret);
  164746. ret = NULL;
  164747. }
  164748. if(png_ptr->zlib_window_bits > 14)
  164749. num_blocks = (int)(1 << (png_ptr->zlib_window_bits - 14));
  164750. else
  164751. num_blocks = 1;
  164752. if (png_ptr->zlib_mem_level >= 7)
  164753. num_blocks += (int)(1 << (png_ptr->zlib_mem_level - 7));
  164754. else
  164755. num_blocks++;
  164756. total_size = ((png_uint_32)65536L) * (png_uint_32)num_blocks+16;
  164757. table = farmalloc(total_size);
  164758. if (table == NULL)
  164759. {
  164760. #ifndef PNG_USER_MEM_SUPPORTED
  164761. if ((png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
  164762. png_error(png_ptr, "Out Of Memory."); /* Note "O" and "M" */
  164763. else
  164764. png_warning(png_ptr, "Out Of Memory.");
  164765. #endif
  164766. return (NULL);
  164767. }
  164768. if ((png_size_t)table & 0xfff0)
  164769. {
  164770. #ifndef PNG_USER_MEM_SUPPORTED
  164771. if ((png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
  164772. png_error(png_ptr,
  164773. "Farmalloc didn't return normalized pointer");
  164774. else
  164775. png_warning(png_ptr,
  164776. "Farmalloc didn't return normalized pointer");
  164777. #endif
  164778. return (NULL);
  164779. }
  164780. png_ptr->offset_table = table;
  164781. png_ptr->offset_table_ptr = farmalloc(num_blocks *
  164782. png_sizeof (png_bytep));
  164783. if (png_ptr->offset_table_ptr == NULL)
  164784. {
  164785. #ifndef PNG_USER_MEM_SUPPORTED
  164786. if ((png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
  164787. png_error(png_ptr, "Out Of memory."); /* Note "O" and "M" */
  164788. else
  164789. png_warning(png_ptr, "Out Of memory.");
  164790. #endif
  164791. return (NULL);
  164792. }
  164793. hptr = (png_byte huge *)table;
  164794. if ((png_size_t)hptr & 0xf)
  164795. {
  164796. hptr = (png_byte huge *)((long)(hptr) & 0xfffffff0L);
  164797. hptr = hptr + 16L; /* "hptr += 16L" fails on Turbo C++ 3.0 */
  164798. }
  164799. for (i = 0; i < num_blocks; i++)
  164800. {
  164801. png_ptr->offset_table_ptr[i] = (png_bytep)hptr;
  164802. hptr = hptr + (png_uint_32)65536L; /* "+=" fails on TC++3.0 */
  164803. }
  164804. png_ptr->offset_table_number = num_blocks;
  164805. png_ptr->offset_table_count = 0;
  164806. png_ptr->offset_table_count_free = 0;
  164807. }
  164808. }
  164809. if (png_ptr->offset_table_count >= png_ptr->offset_table_number)
  164810. {
  164811. #ifndef PNG_USER_MEM_SUPPORTED
  164812. if ((png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
  164813. png_error(png_ptr, "Out of Memory."); /* Note "o" and "M" */
  164814. else
  164815. png_warning(png_ptr, "Out of Memory.");
  164816. #endif
  164817. return (NULL);
  164818. }
  164819. ret = png_ptr->offset_table_ptr[png_ptr->offset_table_count++];
  164820. }
  164821. else
  164822. ret = farmalloc(size);
  164823. #ifndef PNG_USER_MEM_SUPPORTED
  164824. if (ret == NULL)
  164825. {
  164826. if ((png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
  164827. png_error(png_ptr, "Out of memory."); /* Note "o" and "m" */
  164828. else
  164829. png_warning(png_ptr, "Out of memory."); /* Note "o" and "m" */
  164830. }
  164831. #endif
  164832. return (ret);
  164833. }
  164834. void PNGAPI
  164835. png_free(png_structp png_ptr, png_voidp ptr)
  164836. {
  164837. if (png_ptr == NULL || ptr == NULL)
  164838. return;
  164839. #ifdef PNG_USER_MEM_SUPPORTED
  164840. if (png_ptr->free_fn != NULL)
  164841. {
  164842. (*(png_ptr->free_fn))(png_ptr, ptr);
  164843. return;
  164844. }
  164845. else png_free_default(png_ptr, ptr);
  164846. }
  164847. void PNGAPI
  164848. png_free_default(png_structp png_ptr, png_voidp ptr)
  164849. {
  164850. #endif /* PNG_USER_MEM_SUPPORTED */
  164851. if(png_ptr == NULL) return;
  164852. if (png_ptr->offset_table != NULL)
  164853. {
  164854. int i;
  164855. for (i = 0; i < png_ptr->offset_table_count; i++)
  164856. {
  164857. if (ptr == png_ptr->offset_table_ptr[i])
  164858. {
  164859. ptr = NULL;
  164860. png_ptr->offset_table_count_free++;
  164861. break;
  164862. }
  164863. }
  164864. if (png_ptr->offset_table_count_free == png_ptr->offset_table_count)
  164865. {
  164866. farfree(png_ptr->offset_table);
  164867. farfree(png_ptr->offset_table_ptr);
  164868. png_ptr->offset_table = NULL;
  164869. png_ptr->offset_table_ptr = NULL;
  164870. }
  164871. }
  164872. if (ptr != NULL)
  164873. {
  164874. farfree(ptr);
  164875. }
  164876. }
  164877. #else /* Not the Borland DOS special memory handler */
  164878. png_voidp /* PRIVATE */
  164879. png_create_struct(int type)
  164880. {
  164881. #ifdef PNG_USER_MEM_SUPPORTED
  164882. return (png_create_struct_2(type, png_malloc_ptr_NULL, png_voidp_NULL));
  164883. }
  164884. png_voidp /* PRIVATE */
  164885. png_create_struct_2(int type, png_malloc_ptr malloc_fn, png_voidp mem_ptr)
  164886. {
  164887. #endif /* PNG_USER_MEM_SUPPORTED */
  164888. png_size_t size;
  164889. png_voidp struct_ptr;
  164890. if (type == PNG_STRUCT_INFO)
  164891. size = png_sizeof(png_info);
  164892. else if (type == PNG_STRUCT_PNG)
  164893. size = png_sizeof(png_struct);
  164894. else
  164895. return (NULL);
  164896. #ifdef PNG_USER_MEM_SUPPORTED
  164897. if(malloc_fn != NULL)
  164898. {
  164899. png_struct dummy_struct;
  164900. png_structp png_ptr = &dummy_struct;
  164901. png_ptr->mem_ptr=mem_ptr;
  164902. struct_ptr = (*(malloc_fn))(png_ptr, size);
  164903. if (struct_ptr != NULL)
  164904. png_memset(struct_ptr, 0, size);
  164905. return (struct_ptr);
  164906. }
  164907. #endif /* PNG_USER_MEM_SUPPORTED */
  164908. #if defined(__TURBOC__) && !defined(__FLAT__)
  164909. struct_ptr = (png_voidp)farmalloc(size);
  164910. #else
  164911. # if defined(_MSC_VER) && defined(MAXSEG_64K)
  164912. struct_ptr = (png_voidp)halloc(size,1);
  164913. # else
  164914. struct_ptr = (png_voidp)malloc(size);
  164915. # endif
  164916. #endif
  164917. if (struct_ptr != NULL)
  164918. png_memset(struct_ptr, 0, size);
  164919. return (struct_ptr);
  164920. }
  164921. void /* PRIVATE */
  164922. png_destroy_struct(png_voidp struct_ptr)
  164923. {
  164924. #ifdef PNG_USER_MEM_SUPPORTED
  164925. png_destroy_struct_2(struct_ptr, png_free_ptr_NULL, png_voidp_NULL);
  164926. }
  164927. void /* PRIVATE */
  164928. png_destroy_struct_2(png_voidp struct_ptr, png_free_ptr free_fn,
  164929. png_voidp mem_ptr)
  164930. {
  164931. #endif /* PNG_USER_MEM_SUPPORTED */
  164932. if (struct_ptr != NULL)
  164933. {
  164934. #ifdef PNG_USER_MEM_SUPPORTED
  164935. if(free_fn != NULL)
  164936. {
  164937. png_struct dummy_struct;
  164938. png_structp png_ptr = &dummy_struct;
  164939. png_ptr->mem_ptr=mem_ptr;
  164940. (*(free_fn))(png_ptr, struct_ptr);
  164941. return;
  164942. }
  164943. #endif /* PNG_USER_MEM_SUPPORTED */
  164944. #if defined(__TURBOC__) && !defined(__FLAT__)
  164945. farfree(struct_ptr);
  164946. #else
  164947. # if defined(_MSC_VER) && defined(MAXSEG_64K)
  164948. hfree(struct_ptr);
  164949. # else
  164950. free(struct_ptr);
  164951. # endif
  164952. #endif
  164953. }
  164954. }
  164955. png_voidp PNGAPI
  164956. png_malloc(png_structp png_ptr, png_uint_32 size)
  164957. {
  164958. png_voidp ret;
  164959. #ifdef PNG_USER_MEM_SUPPORTED
  164960. if (png_ptr == NULL || size == 0)
  164961. return (NULL);
  164962. if(png_ptr->malloc_fn != NULL)
  164963. ret = ((png_voidp)(*(png_ptr->malloc_fn))(png_ptr, (png_size_t)size));
  164964. else
  164965. ret = (png_malloc_default(png_ptr, size));
  164966. if (ret == NULL && (png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
  164967. png_error(png_ptr, "Out of Memory!");
  164968. return (ret);
  164969. }
  164970. png_voidp PNGAPI
  164971. png_malloc_default(png_structp png_ptr, png_uint_32 size)
  164972. {
  164973. png_voidp ret;
  164974. #endif /* PNG_USER_MEM_SUPPORTED */
  164975. if (png_ptr == NULL || size == 0)
  164976. return (NULL);
  164977. #ifdef PNG_MAX_MALLOC_64K
  164978. if (size > (png_uint_32)65536L)
  164979. {
  164980. #ifndef PNG_USER_MEM_SUPPORTED
  164981. if(png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
  164982. png_error(png_ptr, "Cannot Allocate > 64K");
  164983. else
  164984. #endif
  164985. return NULL;
  164986. }
  164987. #endif
  164988. #if defined(__TURBOC__) && !defined(__FLAT__)
  164989. if (size != (unsigned long)size)
  164990. ret = NULL;
  164991. else
  164992. ret = farmalloc(size);
  164993. #else
  164994. # if defined(_MSC_VER) && defined(MAXSEG_64K)
  164995. if (size != (unsigned long)size)
  164996. ret = NULL;
  164997. else
  164998. ret = halloc(size, 1);
  164999. # else
  165000. if (size != (size_t)size)
  165001. ret = NULL;
  165002. else
  165003. ret = malloc((size_t)size);
  165004. # endif
  165005. #endif
  165006. #ifndef PNG_USER_MEM_SUPPORTED
  165007. if (ret == NULL && (png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
  165008. png_error(png_ptr, "Out of Memory");
  165009. #endif
  165010. return (ret);
  165011. }
  165012. void PNGAPI
  165013. png_free(png_structp png_ptr, png_voidp ptr)
  165014. {
  165015. if (png_ptr == NULL || ptr == NULL)
  165016. return;
  165017. #ifdef PNG_USER_MEM_SUPPORTED
  165018. if (png_ptr->free_fn != NULL)
  165019. {
  165020. (*(png_ptr->free_fn))(png_ptr, ptr);
  165021. return;
  165022. }
  165023. else png_free_default(png_ptr, ptr);
  165024. }
  165025. void PNGAPI
  165026. png_free_default(png_structp png_ptr, png_voidp ptr)
  165027. {
  165028. if (png_ptr == NULL || ptr == NULL)
  165029. return;
  165030. #endif /* PNG_USER_MEM_SUPPORTED */
  165031. #if defined(__TURBOC__) && !defined(__FLAT__)
  165032. farfree(ptr);
  165033. #else
  165034. # if defined(_MSC_VER) && defined(MAXSEG_64K)
  165035. hfree(ptr);
  165036. # else
  165037. free(ptr);
  165038. # endif
  165039. #endif
  165040. }
  165041. #endif /* Not Borland DOS special memory handler */
  165042. #if defined(PNG_1_0_X)
  165043. # define png_malloc_warn png_malloc
  165044. #else
  165045. png_voidp PNGAPI
  165046. png_malloc_warn(png_structp png_ptr, png_uint_32 size)
  165047. {
  165048. png_voidp ptr;
  165049. png_uint_32 save_flags;
  165050. if(png_ptr == NULL) return (NULL);
  165051. save_flags=png_ptr->flags;
  165052. png_ptr->flags|=PNG_FLAG_MALLOC_NULL_MEM_OK;
  165053. ptr = (png_voidp)png_malloc((png_structp)png_ptr, size);
  165054. png_ptr->flags=save_flags;
  165055. return(ptr);
  165056. }
  165057. #endif
  165058. png_voidp PNGAPI
  165059. png_memcpy_check (png_structp png_ptr, png_voidp s1, png_voidp s2,
  165060. png_uint_32 length)
  165061. {
  165062. png_size_t size;
  165063. size = (png_size_t)length;
  165064. if ((png_uint_32)size != length)
  165065. png_error(png_ptr,"Overflow in png_memcpy_check.");
  165066. return(png_memcpy (s1, s2, size));
  165067. }
  165068. png_voidp PNGAPI
  165069. png_memset_check (png_structp png_ptr, png_voidp s1, int value,
  165070. png_uint_32 length)
  165071. {
  165072. png_size_t size;
  165073. size = (png_size_t)length;
  165074. if ((png_uint_32)size != length)
  165075. png_error(png_ptr,"Overflow in png_memset_check.");
  165076. return (png_memset (s1, value, size));
  165077. }
  165078. #ifdef PNG_USER_MEM_SUPPORTED
  165079. void PNGAPI
  165080. png_set_mem_fn(png_structp png_ptr, png_voidp mem_ptr, png_malloc_ptr
  165081. malloc_fn, png_free_ptr free_fn)
  165082. {
  165083. if(png_ptr != NULL) {
  165084. png_ptr->mem_ptr = mem_ptr;
  165085. png_ptr->malloc_fn = malloc_fn;
  165086. png_ptr->free_fn = free_fn;
  165087. }
  165088. }
  165089. png_voidp PNGAPI
  165090. png_get_mem_ptr(png_structp png_ptr)
  165091. {
  165092. if(png_ptr == NULL) return (NULL);
  165093. return ((png_voidp)png_ptr->mem_ptr);
  165094. }
  165095. #endif /* PNG_USER_MEM_SUPPORTED */
  165096. #endif /* PNG_READ_SUPPORTED || PNG_WRITE_SUPPORTED */
  165097. /********* End of inlined file: pngmem.c *********/
  165098. /********* Start of inlined file: pngread.c *********/
  165099. #define PNG_INTERNAL
  165100. #if defined(PNG_READ_SUPPORTED)
  165101. png_structp PNGAPI
  165102. png_create_read_struct(png_const_charp user_png_ver, png_voidp error_ptr,
  165103. png_error_ptr error_fn, png_error_ptr warn_fn)
  165104. {
  165105. #ifdef PNG_USER_MEM_SUPPORTED
  165106. return (png_create_read_struct_2(user_png_ver, error_ptr, error_fn,
  165107. warn_fn, png_voidp_NULL, png_malloc_ptr_NULL, png_free_ptr_NULL));
  165108. }
  165109. png_structp PNGAPI
  165110. png_create_read_struct_2(png_const_charp user_png_ver, png_voidp error_ptr,
  165111. png_error_ptr error_fn, png_error_ptr warn_fn, png_voidp mem_ptr,
  165112. png_malloc_ptr malloc_fn, png_free_ptr free_fn)
  165113. {
  165114. #endif /* PNG_USER_MEM_SUPPORTED */
  165115. png_structp png_ptr;
  165116. #ifdef PNG_SETJMP_SUPPORTED
  165117. #ifdef USE_FAR_KEYWORD
  165118. jmp_buf jmpbuf;
  165119. #endif
  165120. #endif
  165121. int i;
  165122. png_debug(1, "in png_create_read_struct\n");
  165123. #ifdef PNG_USER_MEM_SUPPORTED
  165124. png_ptr = (png_structp)png_create_struct_2(PNG_STRUCT_PNG,
  165125. (png_malloc_ptr)malloc_fn, (png_voidp)mem_ptr);
  165126. #else
  165127. png_ptr = (png_structp)png_create_struct(PNG_STRUCT_PNG);
  165128. #endif
  165129. if (png_ptr == NULL)
  165130. return (NULL);
  165131. #ifdef PNG_SET_USER_LIMITS_SUPPORTED
  165132. png_ptr->user_width_max=PNG_USER_WIDTH_MAX;
  165133. png_ptr->user_height_max=PNG_USER_HEIGHT_MAX;
  165134. #endif
  165135. #ifdef PNG_SETJMP_SUPPORTED
  165136. #ifdef USE_FAR_KEYWORD
  165137. if (setjmp(jmpbuf))
  165138. #else
  165139. if (setjmp(png_ptr->jmpbuf))
  165140. #endif
  165141. {
  165142. png_free(png_ptr, png_ptr->zbuf);
  165143. png_ptr->zbuf=NULL;
  165144. #ifdef PNG_USER_MEM_SUPPORTED
  165145. png_destroy_struct_2((png_voidp)png_ptr,
  165146. (png_free_ptr)free_fn, (png_voidp)mem_ptr);
  165147. #else
  165148. png_destroy_struct((png_voidp)png_ptr);
  165149. #endif
  165150. return (NULL);
  165151. }
  165152. #ifdef USE_FAR_KEYWORD
  165153. png_memcpy(png_ptr->jmpbuf,jmpbuf,png_sizeof(jmp_buf));
  165154. #endif
  165155. #endif
  165156. #ifdef PNG_USER_MEM_SUPPORTED
  165157. png_set_mem_fn(png_ptr, mem_ptr, malloc_fn, free_fn);
  165158. #endif
  165159. png_set_error_fn(png_ptr, error_ptr, error_fn, warn_fn);
  165160. i=0;
  165161. do
  165162. {
  165163. if(user_png_ver[i] != png_libpng_ver[i])
  165164. png_ptr->flags |= PNG_FLAG_LIBRARY_MISMATCH;
  165165. } while (png_libpng_ver[i++]);
  165166. if (png_ptr->flags & PNG_FLAG_LIBRARY_MISMATCH)
  165167. {
  165168. if (user_png_ver == NULL || user_png_ver[0] != png_libpng_ver[0] ||
  165169. (user_png_ver[0] == '1' && user_png_ver[2] != png_libpng_ver[2]) ||
  165170. (user_png_ver[0] == '0' && user_png_ver[2] < '9'))
  165171. {
  165172. #if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE)
  165173. char msg[80];
  165174. if (user_png_ver)
  165175. {
  165176. png_snprintf(msg, 80,
  165177. "Application was compiled with png.h from libpng-%.20s",
  165178. user_png_ver);
  165179. png_warning(png_ptr, msg);
  165180. }
  165181. png_snprintf(msg, 80,
  165182. "Application is running with png.c from libpng-%.20s",
  165183. png_libpng_ver);
  165184. png_warning(png_ptr, msg);
  165185. #endif
  165186. #ifdef PNG_ERROR_NUMBERS_SUPPORTED
  165187. png_ptr->flags=0;
  165188. #endif
  165189. png_error(png_ptr,
  165190. "Incompatible libpng version in application and library");
  165191. }
  165192. }
  165193. png_ptr->zbuf_size = PNG_ZBUF_SIZE;
  165194. png_ptr->zbuf = (png_bytep)png_malloc(png_ptr,
  165195. (png_uint_32)png_ptr->zbuf_size);
  165196. png_ptr->zstream.zalloc = png_zalloc;
  165197. png_ptr->zstream.zfree = png_zfree;
  165198. png_ptr->zstream.opaque = (voidpf)png_ptr;
  165199. switch (inflateInit(&png_ptr->zstream))
  165200. {
  165201. case Z_OK: /* Do nothing */ break;
  165202. case Z_MEM_ERROR:
  165203. case Z_STREAM_ERROR: png_error(png_ptr, "zlib memory error"); break;
  165204. case Z_VERSION_ERROR: png_error(png_ptr, "zlib version error"); break;
  165205. default: png_error(png_ptr, "Unknown zlib error");
  165206. }
  165207. png_ptr->zstream.next_out = png_ptr->zbuf;
  165208. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  165209. png_set_read_fn(png_ptr, png_voidp_NULL, png_rw_ptr_NULL);
  165210. #ifdef PNG_SETJMP_SUPPORTED
  165211. #ifdef USE_FAR_KEYWORD
  165212. if (setjmp(jmpbuf))
  165213. PNG_ABORT();
  165214. png_memcpy(png_ptr->jmpbuf,jmpbuf,png_sizeof(jmp_buf));
  165215. #else
  165216. if (setjmp(png_ptr->jmpbuf))
  165217. PNG_ABORT();
  165218. #endif
  165219. #endif
  165220. return (png_ptr);
  165221. }
  165222. #if defined(PNG_1_0_X) || defined(PNG_1_2_X)
  165223. #undef png_read_init
  165224. void PNGAPI
  165225. png_read_init(png_structp png_ptr)
  165226. {
  165227. png_read_init_2(png_ptr, "1.0.6 or earlier", 0, 0);
  165228. }
  165229. void PNGAPI
  165230. png_read_init_2(png_structp png_ptr, png_const_charp user_png_ver,
  165231. png_size_t png_struct_size, png_size_t png_info_size)
  165232. {
  165233. if(png_ptr == NULL) return;
  165234. #if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE)
  165235. if(png_sizeof(png_struct) > png_struct_size ||
  165236. png_sizeof(png_info) > png_info_size)
  165237. {
  165238. char msg[80];
  165239. png_ptr->warning_fn=NULL;
  165240. if (user_png_ver)
  165241. {
  165242. png_snprintf(msg, 80,
  165243. "Application was compiled with png.h from libpng-%.20s",
  165244. user_png_ver);
  165245. png_warning(png_ptr, msg);
  165246. }
  165247. png_snprintf(msg, 80,
  165248. "Application is running with png.c from libpng-%.20s",
  165249. png_libpng_ver);
  165250. png_warning(png_ptr, msg);
  165251. }
  165252. #endif
  165253. if(png_sizeof(png_struct) > png_struct_size)
  165254. {
  165255. png_ptr->error_fn=NULL;
  165256. #ifdef PNG_ERROR_NUMBERS_SUPPORTED
  165257. png_ptr->flags=0;
  165258. #endif
  165259. png_error(png_ptr,
  165260. "The png struct allocated by the application for reading is too small.");
  165261. }
  165262. if(png_sizeof(png_info) > png_info_size)
  165263. {
  165264. png_ptr->error_fn=NULL;
  165265. #ifdef PNG_ERROR_NUMBERS_SUPPORTED
  165266. png_ptr->flags=0;
  165267. #endif
  165268. png_error(png_ptr,
  165269. "The info struct allocated by application for reading is too small.");
  165270. }
  165271. png_read_init_3(&png_ptr, user_png_ver, png_struct_size);
  165272. }
  165273. #endif /* PNG_1_0_X || PNG_1_2_X */
  165274. void PNGAPI
  165275. png_read_init_3(png_structpp ptr_ptr, png_const_charp user_png_ver,
  165276. png_size_t png_struct_size)
  165277. {
  165278. #ifdef PNG_SETJMP_SUPPORTED
  165279. jmp_buf tmp_jmp; /* to save current jump buffer */
  165280. #endif
  165281. int i=0;
  165282. png_structp png_ptr=*ptr_ptr;
  165283. if(png_ptr == NULL) return;
  165284. do
  165285. {
  165286. if(user_png_ver[i] != png_libpng_ver[i])
  165287. {
  165288. #ifdef PNG_LEGACY_SUPPORTED
  165289. png_ptr->flags |= PNG_FLAG_LIBRARY_MISMATCH;
  165290. #else
  165291. png_ptr->warning_fn=NULL;
  165292. png_warning(png_ptr,
  165293. "Application uses deprecated png_read_init() and should be recompiled.");
  165294. break;
  165295. #endif
  165296. }
  165297. } while (png_libpng_ver[i++]);
  165298. png_debug(1, "in png_read_init_3\n");
  165299. #ifdef PNG_SETJMP_SUPPORTED
  165300. png_memcpy(tmp_jmp, png_ptr->jmpbuf, png_sizeof (jmp_buf));
  165301. #endif
  165302. if(png_sizeof(png_struct) > png_struct_size)
  165303. {
  165304. png_destroy_struct(png_ptr);
  165305. *ptr_ptr = (png_structp)png_create_struct(PNG_STRUCT_PNG);
  165306. png_ptr = *ptr_ptr;
  165307. }
  165308. png_memset(png_ptr, 0, png_sizeof (png_struct));
  165309. #ifdef PNG_SETJMP_SUPPORTED
  165310. png_memcpy(png_ptr->jmpbuf, tmp_jmp, png_sizeof (jmp_buf));
  165311. #endif
  165312. #ifdef PNG_SET_USER_LIMITS_SUPPORTED
  165313. png_ptr->user_width_max=PNG_USER_WIDTH_MAX;
  165314. png_ptr->user_height_max=PNG_USER_HEIGHT_MAX;
  165315. #endif
  165316. png_ptr->zbuf_size = PNG_ZBUF_SIZE;
  165317. png_ptr->zbuf = (png_bytep)png_malloc(png_ptr,
  165318. (png_uint_32)png_ptr->zbuf_size);
  165319. png_ptr->zstream.zalloc = png_zalloc;
  165320. png_ptr->zstream.zfree = png_zfree;
  165321. png_ptr->zstream.opaque = (voidpf)png_ptr;
  165322. switch (inflateInit(&png_ptr->zstream))
  165323. {
  165324. case Z_OK: /* Do nothing */ break;
  165325. case Z_MEM_ERROR:
  165326. case Z_STREAM_ERROR: png_error(png_ptr, "zlib memory"); break;
  165327. case Z_VERSION_ERROR: png_error(png_ptr, "zlib version"); break;
  165328. default: png_error(png_ptr, "Unknown zlib error");
  165329. }
  165330. png_ptr->zstream.next_out = png_ptr->zbuf;
  165331. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  165332. png_set_read_fn(png_ptr, png_voidp_NULL, png_rw_ptr_NULL);
  165333. }
  165334. #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
  165335. void PNGAPI
  165336. png_read_info(png_structp png_ptr, png_infop info_ptr)
  165337. {
  165338. if(png_ptr == NULL) return;
  165339. png_debug(1, "in png_read_info\n");
  165340. if (png_ptr->sig_bytes < 8)
  165341. {
  165342. png_size_t num_checked = png_ptr->sig_bytes,
  165343. num_to_check = 8 - num_checked;
  165344. png_read_data(png_ptr, &(info_ptr->signature[num_checked]), num_to_check);
  165345. png_ptr->sig_bytes = 8;
  165346. if (png_sig_cmp(info_ptr->signature, num_checked, num_to_check))
  165347. {
  165348. if (num_checked < 4 &&
  165349. png_sig_cmp(info_ptr->signature, num_checked, num_to_check - 4))
  165350. png_error(png_ptr, "Not a PNG file");
  165351. else
  165352. png_error(png_ptr, "PNG file corrupted by ASCII conversion");
  165353. }
  165354. if (num_checked < 3)
  165355. png_ptr->mode |= PNG_HAVE_PNG_SIGNATURE;
  165356. }
  165357. for(;;)
  165358. {
  165359. #ifdef PNG_USE_LOCAL_ARRAYS
  165360. PNG_CONST PNG_IHDR;
  165361. PNG_CONST PNG_IDAT;
  165362. PNG_CONST PNG_IEND;
  165363. PNG_CONST PNG_PLTE;
  165364. #if defined(PNG_READ_bKGD_SUPPORTED)
  165365. PNG_CONST PNG_bKGD;
  165366. #endif
  165367. #if defined(PNG_READ_cHRM_SUPPORTED)
  165368. PNG_CONST PNG_cHRM;
  165369. #endif
  165370. #if defined(PNG_READ_gAMA_SUPPORTED)
  165371. PNG_CONST PNG_gAMA;
  165372. #endif
  165373. #if defined(PNG_READ_hIST_SUPPORTED)
  165374. PNG_CONST PNG_hIST;
  165375. #endif
  165376. #if defined(PNG_READ_iCCP_SUPPORTED)
  165377. PNG_CONST PNG_iCCP;
  165378. #endif
  165379. #if defined(PNG_READ_iTXt_SUPPORTED)
  165380. PNG_CONST PNG_iTXt;
  165381. #endif
  165382. #if defined(PNG_READ_oFFs_SUPPORTED)
  165383. PNG_CONST PNG_oFFs;
  165384. #endif
  165385. #if defined(PNG_READ_pCAL_SUPPORTED)
  165386. PNG_CONST PNG_pCAL;
  165387. #endif
  165388. #if defined(PNG_READ_pHYs_SUPPORTED)
  165389. PNG_CONST PNG_pHYs;
  165390. #endif
  165391. #if defined(PNG_READ_sBIT_SUPPORTED)
  165392. PNG_CONST PNG_sBIT;
  165393. #endif
  165394. #if defined(PNG_READ_sCAL_SUPPORTED)
  165395. PNG_CONST PNG_sCAL;
  165396. #endif
  165397. #if defined(PNG_READ_sPLT_SUPPORTED)
  165398. PNG_CONST PNG_sPLT;
  165399. #endif
  165400. #if defined(PNG_READ_sRGB_SUPPORTED)
  165401. PNG_CONST PNG_sRGB;
  165402. #endif
  165403. #if defined(PNG_READ_tEXt_SUPPORTED)
  165404. PNG_CONST PNG_tEXt;
  165405. #endif
  165406. #if defined(PNG_READ_tIME_SUPPORTED)
  165407. PNG_CONST PNG_tIME;
  165408. #endif
  165409. #if defined(PNG_READ_tRNS_SUPPORTED)
  165410. PNG_CONST PNG_tRNS;
  165411. #endif
  165412. #if defined(PNG_READ_zTXt_SUPPORTED)
  165413. PNG_CONST PNG_zTXt;
  165414. #endif
  165415. #endif /* PNG_USE_LOCAL_ARRAYS */
  165416. png_byte chunk_length[4];
  165417. png_uint_32 length;
  165418. png_read_data(png_ptr, chunk_length, 4);
  165419. length = png_get_uint_31(png_ptr,chunk_length);
  165420. png_reset_crc(png_ptr);
  165421. png_crc_read(png_ptr, png_ptr->chunk_name, 4);
  165422. png_debug2(0, "Reading %s chunk, length=%lu.\n", png_ptr->chunk_name,
  165423. length);
  165424. if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  165425. if(png_ptr->mode & PNG_AFTER_IDAT)
  165426. png_ptr->mode |= PNG_HAVE_CHUNK_AFTER_IDAT;
  165427. if (!png_memcmp(png_ptr->chunk_name, png_IHDR, 4))
  165428. png_handle_IHDR(png_ptr, info_ptr, length);
  165429. else if (!png_memcmp(png_ptr->chunk_name, png_IEND, 4))
  165430. png_handle_IEND(png_ptr, info_ptr, length);
  165431. #ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
  165432. else if (png_handle_as_unknown(png_ptr, png_ptr->chunk_name))
  165433. {
  165434. if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  165435. png_ptr->mode |= PNG_HAVE_IDAT;
  165436. png_handle_unknown(png_ptr, info_ptr, length);
  165437. if (!png_memcmp(png_ptr->chunk_name, png_PLTE, 4))
  165438. png_ptr->mode |= PNG_HAVE_PLTE;
  165439. else if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  165440. {
  165441. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  165442. png_error(png_ptr, "Missing IHDR before IDAT");
  165443. else if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE &&
  165444. !(png_ptr->mode & PNG_HAVE_PLTE))
  165445. png_error(png_ptr, "Missing PLTE before IDAT");
  165446. break;
  165447. }
  165448. }
  165449. #endif
  165450. else if (!png_memcmp(png_ptr->chunk_name, png_PLTE, 4))
  165451. png_handle_PLTE(png_ptr, info_ptr, length);
  165452. else if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  165453. {
  165454. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  165455. png_error(png_ptr, "Missing IHDR before IDAT");
  165456. else if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE &&
  165457. !(png_ptr->mode & PNG_HAVE_PLTE))
  165458. png_error(png_ptr, "Missing PLTE before IDAT");
  165459. png_ptr->idat_size = length;
  165460. png_ptr->mode |= PNG_HAVE_IDAT;
  165461. break;
  165462. }
  165463. #if defined(PNG_READ_bKGD_SUPPORTED)
  165464. else if (!png_memcmp(png_ptr->chunk_name, png_bKGD, 4))
  165465. png_handle_bKGD(png_ptr, info_ptr, length);
  165466. #endif
  165467. #if defined(PNG_READ_cHRM_SUPPORTED)
  165468. else if (!png_memcmp(png_ptr->chunk_name, png_cHRM, 4))
  165469. png_handle_cHRM(png_ptr, info_ptr, length);
  165470. #endif
  165471. #if defined(PNG_READ_gAMA_SUPPORTED)
  165472. else if (!png_memcmp(png_ptr->chunk_name, png_gAMA, 4))
  165473. png_handle_gAMA(png_ptr, info_ptr, length);
  165474. #endif
  165475. #if defined(PNG_READ_hIST_SUPPORTED)
  165476. else if (!png_memcmp(png_ptr->chunk_name, png_hIST, 4))
  165477. png_handle_hIST(png_ptr, info_ptr, length);
  165478. #endif
  165479. #if defined(PNG_READ_oFFs_SUPPORTED)
  165480. else if (!png_memcmp(png_ptr->chunk_name, png_oFFs, 4))
  165481. png_handle_oFFs(png_ptr, info_ptr, length);
  165482. #endif
  165483. #if defined(PNG_READ_pCAL_SUPPORTED)
  165484. else if (!png_memcmp(png_ptr->chunk_name, png_pCAL, 4))
  165485. png_handle_pCAL(png_ptr, info_ptr, length);
  165486. #endif
  165487. #if defined(PNG_READ_sCAL_SUPPORTED)
  165488. else if (!png_memcmp(png_ptr->chunk_name, png_sCAL, 4))
  165489. png_handle_sCAL(png_ptr, info_ptr, length);
  165490. #endif
  165491. #if defined(PNG_READ_pHYs_SUPPORTED)
  165492. else if (!png_memcmp(png_ptr->chunk_name, png_pHYs, 4))
  165493. png_handle_pHYs(png_ptr, info_ptr, length);
  165494. #endif
  165495. #if defined(PNG_READ_sBIT_SUPPORTED)
  165496. else if (!png_memcmp(png_ptr->chunk_name, png_sBIT, 4))
  165497. png_handle_sBIT(png_ptr, info_ptr, length);
  165498. #endif
  165499. #if defined(PNG_READ_sRGB_SUPPORTED)
  165500. else if (!png_memcmp(png_ptr->chunk_name, png_sRGB, 4))
  165501. png_handle_sRGB(png_ptr, info_ptr, length);
  165502. #endif
  165503. #if defined(PNG_READ_iCCP_SUPPORTED)
  165504. else if (!png_memcmp(png_ptr->chunk_name, png_iCCP, 4))
  165505. png_handle_iCCP(png_ptr, info_ptr, length);
  165506. #endif
  165507. #if defined(PNG_READ_sPLT_SUPPORTED)
  165508. else if (!png_memcmp(png_ptr->chunk_name, png_sPLT, 4))
  165509. png_handle_sPLT(png_ptr, info_ptr, length);
  165510. #endif
  165511. #if defined(PNG_READ_tEXt_SUPPORTED)
  165512. else if (!png_memcmp(png_ptr->chunk_name, png_tEXt, 4))
  165513. png_handle_tEXt(png_ptr, info_ptr, length);
  165514. #endif
  165515. #if defined(PNG_READ_tIME_SUPPORTED)
  165516. else if (!png_memcmp(png_ptr->chunk_name, png_tIME, 4))
  165517. png_handle_tIME(png_ptr, info_ptr, length);
  165518. #endif
  165519. #if defined(PNG_READ_tRNS_SUPPORTED)
  165520. else if (!png_memcmp(png_ptr->chunk_name, png_tRNS, 4))
  165521. png_handle_tRNS(png_ptr, info_ptr, length);
  165522. #endif
  165523. #if defined(PNG_READ_zTXt_SUPPORTED)
  165524. else if (!png_memcmp(png_ptr->chunk_name, png_zTXt, 4))
  165525. png_handle_zTXt(png_ptr, info_ptr, length);
  165526. #endif
  165527. #if defined(PNG_READ_iTXt_SUPPORTED)
  165528. else if (!png_memcmp(png_ptr->chunk_name, png_iTXt, 4))
  165529. png_handle_iTXt(png_ptr, info_ptr, length);
  165530. #endif
  165531. else
  165532. png_handle_unknown(png_ptr, info_ptr, length);
  165533. }
  165534. }
  165535. #endif /* PNG_NO_SEQUENTIAL_READ_SUPPORTED */
  165536. void PNGAPI
  165537. png_read_update_info(png_structp png_ptr, png_infop info_ptr)
  165538. {
  165539. png_debug(1, "in png_read_update_info\n");
  165540. if(png_ptr == NULL) return;
  165541. if (!(png_ptr->flags & PNG_FLAG_ROW_INIT))
  165542. png_read_start_row(png_ptr);
  165543. else
  165544. png_warning(png_ptr,
  165545. "Ignoring extra png_read_update_info() call; row buffer not reallocated");
  165546. png_read_transform_info(png_ptr, info_ptr);
  165547. }
  165548. #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
  165549. void PNGAPI
  165550. png_start_read_image(png_structp png_ptr)
  165551. {
  165552. png_debug(1, "in png_start_read_image\n");
  165553. if(png_ptr == NULL) return;
  165554. if (!(png_ptr->flags & PNG_FLAG_ROW_INIT))
  165555. png_read_start_row(png_ptr);
  165556. }
  165557. #endif /* PNG_NO_SEQUENTIAL_READ_SUPPORTED */
  165558. #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
  165559. void PNGAPI
  165560. png_read_row(png_structp png_ptr, png_bytep row, png_bytep dsp_row)
  165561. {
  165562. #ifdef PNG_USE_LOCAL_ARRAYS
  165563. PNG_CONST PNG_IDAT;
  165564. PNG_CONST int png_pass_dsp_mask[7] = {0xff, 0x0f, 0xff, 0x33, 0xff, 0x55,
  165565. 0xff};
  165566. PNG_CONST int png_pass_mask[7] = {0x80, 0x08, 0x88, 0x22, 0xaa, 0x55, 0xff};
  165567. #endif
  165568. int ret;
  165569. if(png_ptr == NULL) return;
  165570. png_debug2(1, "in png_read_row (row %lu, pass %d)\n",
  165571. png_ptr->row_number, png_ptr->pass);
  165572. if (!(png_ptr->flags & PNG_FLAG_ROW_INIT))
  165573. png_read_start_row(png_ptr);
  165574. if (png_ptr->row_number == 0 && png_ptr->pass == 0)
  165575. {
  165576. #if defined(PNG_WRITE_INVERT_SUPPORTED) && !defined(PNG_READ_INVERT_SUPPORTED)
  165577. if (png_ptr->transformations & PNG_INVERT_MONO)
  165578. png_warning(png_ptr, "PNG_READ_INVERT_SUPPORTED is not defined.");
  165579. #endif
  165580. #if defined(PNG_WRITE_FILLER_SUPPORTED) && !defined(PNG_READ_FILLER_SUPPORTED)
  165581. if (png_ptr->transformations & PNG_FILLER)
  165582. png_warning(png_ptr, "PNG_READ_FILLER_SUPPORTED is not defined.");
  165583. #endif
  165584. #if defined(PNG_WRITE_PACKSWAP_SUPPORTED) && !defined(PNG_READ_PACKSWAP_SUPPORTED)
  165585. if (png_ptr->transformations & PNG_PACKSWAP)
  165586. png_warning(png_ptr, "PNG_READ_PACKSWAP_SUPPORTED is not defined.");
  165587. #endif
  165588. #if defined(PNG_WRITE_PACK_SUPPORTED) && !defined(PNG_READ_PACK_SUPPORTED)
  165589. if (png_ptr->transformations & PNG_PACK)
  165590. png_warning(png_ptr, "PNG_READ_PACK_SUPPORTED is not defined.");
  165591. #endif
  165592. #if defined(PNG_WRITE_SHIFT_SUPPORTED) && !defined(PNG_READ_SHIFT_SUPPORTED)
  165593. if (png_ptr->transformations & PNG_SHIFT)
  165594. png_warning(png_ptr, "PNG_READ_SHIFT_SUPPORTED is not defined.");
  165595. #endif
  165596. #if defined(PNG_WRITE_BGR_SUPPORTED) && !defined(PNG_READ_BGR_SUPPORTED)
  165597. if (png_ptr->transformations & PNG_BGR)
  165598. png_warning(png_ptr, "PNG_READ_BGR_SUPPORTED is not defined.");
  165599. #endif
  165600. #if defined(PNG_WRITE_SWAP_SUPPORTED) && !defined(PNG_READ_SWAP_SUPPORTED)
  165601. if (png_ptr->transformations & PNG_SWAP_BYTES)
  165602. png_warning(png_ptr, "PNG_READ_SWAP_SUPPORTED is not defined.");
  165603. #endif
  165604. }
  165605. #if defined(PNG_READ_INTERLACING_SUPPORTED)
  165606. if (png_ptr->interlaced && (png_ptr->transformations & PNG_INTERLACE))
  165607. {
  165608. switch (png_ptr->pass)
  165609. {
  165610. case 0:
  165611. if (png_ptr->row_number & 0x07)
  165612. {
  165613. if (dsp_row != NULL)
  165614. png_combine_row(png_ptr, dsp_row,
  165615. png_pass_dsp_mask[png_ptr->pass]);
  165616. png_read_finish_row(png_ptr);
  165617. return;
  165618. }
  165619. break;
  165620. case 1:
  165621. if ((png_ptr->row_number & 0x07) || png_ptr->width < 5)
  165622. {
  165623. if (dsp_row != NULL)
  165624. png_combine_row(png_ptr, dsp_row,
  165625. png_pass_dsp_mask[png_ptr->pass]);
  165626. png_read_finish_row(png_ptr);
  165627. return;
  165628. }
  165629. break;
  165630. case 2:
  165631. if ((png_ptr->row_number & 0x07) != 4)
  165632. {
  165633. if (dsp_row != NULL && (png_ptr->row_number & 4))
  165634. png_combine_row(png_ptr, dsp_row,
  165635. png_pass_dsp_mask[png_ptr->pass]);
  165636. png_read_finish_row(png_ptr);
  165637. return;
  165638. }
  165639. break;
  165640. case 3:
  165641. if ((png_ptr->row_number & 3) || png_ptr->width < 3)
  165642. {
  165643. if (dsp_row != NULL)
  165644. png_combine_row(png_ptr, dsp_row,
  165645. png_pass_dsp_mask[png_ptr->pass]);
  165646. png_read_finish_row(png_ptr);
  165647. return;
  165648. }
  165649. break;
  165650. case 4:
  165651. if ((png_ptr->row_number & 3) != 2)
  165652. {
  165653. if (dsp_row != NULL && (png_ptr->row_number & 2))
  165654. png_combine_row(png_ptr, dsp_row,
  165655. png_pass_dsp_mask[png_ptr->pass]);
  165656. png_read_finish_row(png_ptr);
  165657. return;
  165658. }
  165659. break;
  165660. case 5:
  165661. if ((png_ptr->row_number & 1) || png_ptr->width < 2)
  165662. {
  165663. if (dsp_row != NULL)
  165664. png_combine_row(png_ptr, dsp_row,
  165665. png_pass_dsp_mask[png_ptr->pass]);
  165666. png_read_finish_row(png_ptr);
  165667. return;
  165668. }
  165669. break;
  165670. case 6:
  165671. if (!(png_ptr->row_number & 1))
  165672. {
  165673. png_read_finish_row(png_ptr);
  165674. return;
  165675. }
  165676. break;
  165677. }
  165678. }
  165679. #endif
  165680. if (!(png_ptr->mode & PNG_HAVE_IDAT))
  165681. png_error(png_ptr, "Invalid attempt to read row data");
  165682. png_ptr->zstream.next_out = png_ptr->row_buf;
  165683. png_ptr->zstream.avail_out = (uInt)png_ptr->irowbytes;
  165684. do
  165685. {
  165686. if (!(png_ptr->zstream.avail_in))
  165687. {
  165688. while (!png_ptr->idat_size)
  165689. {
  165690. png_byte chunk_length[4];
  165691. png_crc_finish(png_ptr, 0);
  165692. png_read_data(png_ptr, chunk_length, 4);
  165693. png_ptr->idat_size = png_get_uint_31(png_ptr,chunk_length);
  165694. png_reset_crc(png_ptr);
  165695. png_crc_read(png_ptr, png_ptr->chunk_name, 4);
  165696. if (png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  165697. png_error(png_ptr, "Not enough image data");
  165698. }
  165699. png_ptr->zstream.avail_in = (uInt)png_ptr->zbuf_size;
  165700. png_ptr->zstream.next_in = png_ptr->zbuf;
  165701. if (png_ptr->zbuf_size > png_ptr->idat_size)
  165702. png_ptr->zstream.avail_in = (uInt)png_ptr->idat_size;
  165703. png_crc_read(png_ptr, png_ptr->zbuf,
  165704. (png_size_t)png_ptr->zstream.avail_in);
  165705. png_ptr->idat_size -= png_ptr->zstream.avail_in;
  165706. }
  165707. ret = inflate(&png_ptr->zstream, Z_PARTIAL_FLUSH);
  165708. if (ret == Z_STREAM_END)
  165709. {
  165710. if (png_ptr->zstream.avail_out || png_ptr->zstream.avail_in ||
  165711. png_ptr->idat_size)
  165712. png_error(png_ptr, "Extra compressed data");
  165713. png_ptr->mode |= PNG_AFTER_IDAT;
  165714. png_ptr->flags |= PNG_FLAG_ZLIB_FINISHED;
  165715. break;
  165716. }
  165717. if (ret != Z_OK)
  165718. png_error(png_ptr, png_ptr->zstream.msg ? png_ptr->zstream.msg :
  165719. "Decompression error");
  165720. } while (png_ptr->zstream.avail_out);
  165721. png_ptr->row_info.color_type = png_ptr->color_type;
  165722. png_ptr->row_info.width = png_ptr->iwidth;
  165723. png_ptr->row_info.channels = png_ptr->channels;
  165724. png_ptr->row_info.bit_depth = png_ptr->bit_depth;
  165725. png_ptr->row_info.pixel_depth = png_ptr->pixel_depth;
  165726. png_ptr->row_info.rowbytes = PNG_ROWBYTES(png_ptr->row_info.pixel_depth,
  165727. png_ptr->row_info.width);
  165728. if(png_ptr->row_buf[0])
  165729. png_read_filter_row(png_ptr, &(png_ptr->row_info),
  165730. png_ptr->row_buf + 1, png_ptr->prev_row + 1,
  165731. (int)(png_ptr->row_buf[0]));
  165732. png_memcpy_check(png_ptr, png_ptr->prev_row, png_ptr->row_buf,
  165733. png_ptr->rowbytes + 1);
  165734. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  165735. if((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) &&
  165736. (png_ptr->filter_type == PNG_INTRAPIXEL_DIFFERENCING))
  165737. {
  165738. png_do_read_intrapixel(&(png_ptr->row_info), png_ptr->row_buf + 1);
  165739. }
  165740. #endif
  165741. if (png_ptr->transformations || (png_ptr->flags&PNG_FLAG_STRIP_ALPHA))
  165742. png_do_read_transformations(png_ptr);
  165743. #if defined(PNG_READ_INTERLACING_SUPPORTED)
  165744. if (png_ptr->interlaced &&
  165745. (png_ptr->transformations & PNG_INTERLACE))
  165746. {
  165747. if (png_ptr->pass < 6)
  165748. png_do_read_interlace(png_ptr);
  165749. if (dsp_row != NULL)
  165750. png_combine_row(png_ptr, dsp_row,
  165751. png_pass_dsp_mask[png_ptr->pass]);
  165752. if (row != NULL)
  165753. png_combine_row(png_ptr, row,
  165754. png_pass_mask[png_ptr->pass]);
  165755. }
  165756. else
  165757. #endif
  165758. {
  165759. if (row != NULL)
  165760. png_combine_row(png_ptr, row, 0xff);
  165761. if (dsp_row != NULL)
  165762. png_combine_row(png_ptr, dsp_row, 0xff);
  165763. }
  165764. png_read_finish_row(png_ptr);
  165765. if (png_ptr->read_row_fn != NULL)
  165766. (*(png_ptr->read_row_fn))(png_ptr, png_ptr->row_number, png_ptr->pass);
  165767. }
  165768. #endif /* PNG_NO_SEQUENTIAL_READ_SUPPORTED */
  165769. #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
  165770. void PNGAPI
  165771. png_read_rows(png_structp png_ptr, png_bytepp row,
  165772. png_bytepp display_row, png_uint_32 num_rows)
  165773. {
  165774. png_uint_32 i;
  165775. png_bytepp rp;
  165776. png_bytepp dp;
  165777. png_debug(1, "in png_read_rows\n");
  165778. if(png_ptr == NULL) return;
  165779. rp = row;
  165780. dp = display_row;
  165781. if (rp != NULL && dp != NULL)
  165782. for (i = 0; i < num_rows; i++)
  165783. {
  165784. png_bytep rptr = *rp++;
  165785. png_bytep dptr = *dp++;
  165786. png_read_row(png_ptr, rptr, dptr);
  165787. }
  165788. else if(rp != NULL)
  165789. for (i = 0; i < num_rows; i++)
  165790. {
  165791. png_bytep rptr = *rp;
  165792. png_read_row(png_ptr, rptr, png_bytep_NULL);
  165793. rp++;
  165794. }
  165795. else if(dp != NULL)
  165796. for (i = 0; i < num_rows; i++)
  165797. {
  165798. png_bytep dptr = *dp;
  165799. png_read_row(png_ptr, png_bytep_NULL, dptr);
  165800. dp++;
  165801. }
  165802. }
  165803. #endif /* PNG_NO_SEQUENTIAL_READ_SUPPORTED */
  165804. #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
  165805. void PNGAPI
  165806. png_read_image(png_structp png_ptr, png_bytepp image)
  165807. {
  165808. png_uint_32 i,image_height;
  165809. int pass, j;
  165810. png_bytepp rp;
  165811. png_debug(1, "in png_read_image\n");
  165812. if(png_ptr == NULL) return;
  165813. #ifdef PNG_READ_INTERLACING_SUPPORTED
  165814. pass = png_set_interlace_handling(png_ptr);
  165815. #else
  165816. if (png_ptr->interlaced)
  165817. png_error(png_ptr,
  165818. "Cannot read interlaced image -- interlace handler disabled.");
  165819. pass = 1;
  165820. #endif
  165821. image_height=png_ptr->height;
  165822. png_ptr->num_rows = image_height; /* Make sure this is set correctly */
  165823. for (j = 0; j < pass; j++)
  165824. {
  165825. rp = image;
  165826. for (i = 0; i < image_height; i++)
  165827. {
  165828. png_read_row(png_ptr, *rp, png_bytep_NULL);
  165829. rp++;
  165830. }
  165831. }
  165832. }
  165833. #endif /* PNG_NO_SEQUENTIAL_READ_SUPPORTED */
  165834. #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
  165835. void PNGAPI
  165836. png_read_end(png_structp png_ptr, png_infop info_ptr)
  165837. {
  165838. png_byte chunk_length[4];
  165839. png_uint_32 length;
  165840. png_debug(1, "in png_read_end\n");
  165841. if(png_ptr == NULL) return;
  165842. png_crc_finish(png_ptr, 0); /* Finish off CRC from last IDAT chunk */
  165843. do
  165844. {
  165845. #ifdef PNG_USE_LOCAL_ARRAYS
  165846. PNG_CONST PNG_IHDR;
  165847. PNG_CONST PNG_IDAT;
  165848. PNG_CONST PNG_IEND;
  165849. PNG_CONST PNG_PLTE;
  165850. #if defined(PNG_READ_bKGD_SUPPORTED)
  165851. PNG_CONST PNG_bKGD;
  165852. #endif
  165853. #if defined(PNG_READ_cHRM_SUPPORTED)
  165854. PNG_CONST PNG_cHRM;
  165855. #endif
  165856. #if defined(PNG_READ_gAMA_SUPPORTED)
  165857. PNG_CONST PNG_gAMA;
  165858. #endif
  165859. #if defined(PNG_READ_hIST_SUPPORTED)
  165860. PNG_CONST PNG_hIST;
  165861. #endif
  165862. #if defined(PNG_READ_iCCP_SUPPORTED)
  165863. PNG_CONST PNG_iCCP;
  165864. #endif
  165865. #if defined(PNG_READ_iTXt_SUPPORTED)
  165866. PNG_CONST PNG_iTXt;
  165867. #endif
  165868. #if defined(PNG_READ_oFFs_SUPPORTED)
  165869. PNG_CONST PNG_oFFs;
  165870. #endif
  165871. #if defined(PNG_READ_pCAL_SUPPORTED)
  165872. PNG_CONST PNG_pCAL;
  165873. #endif
  165874. #if defined(PNG_READ_pHYs_SUPPORTED)
  165875. PNG_CONST PNG_pHYs;
  165876. #endif
  165877. #if defined(PNG_READ_sBIT_SUPPORTED)
  165878. PNG_CONST PNG_sBIT;
  165879. #endif
  165880. #if defined(PNG_READ_sCAL_SUPPORTED)
  165881. PNG_CONST PNG_sCAL;
  165882. #endif
  165883. #if defined(PNG_READ_sPLT_SUPPORTED)
  165884. PNG_CONST PNG_sPLT;
  165885. #endif
  165886. #if defined(PNG_READ_sRGB_SUPPORTED)
  165887. PNG_CONST PNG_sRGB;
  165888. #endif
  165889. #if defined(PNG_READ_tEXt_SUPPORTED)
  165890. PNG_CONST PNG_tEXt;
  165891. #endif
  165892. #if defined(PNG_READ_tIME_SUPPORTED)
  165893. PNG_CONST PNG_tIME;
  165894. #endif
  165895. #if defined(PNG_READ_tRNS_SUPPORTED)
  165896. PNG_CONST PNG_tRNS;
  165897. #endif
  165898. #if defined(PNG_READ_zTXt_SUPPORTED)
  165899. PNG_CONST PNG_zTXt;
  165900. #endif
  165901. #endif /* PNG_USE_LOCAL_ARRAYS */
  165902. png_read_data(png_ptr, chunk_length, 4);
  165903. length = png_get_uint_31(png_ptr,chunk_length);
  165904. png_reset_crc(png_ptr);
  165905. png_crc_read(png_ptr, png_ptr->chunk_name, 4);
  165906. png_debug1(0, "Reading %s chunk.\n", png_ptr->chunk_name);
  165907. if (!png_memcmp(png_ptr->chunk_name, png_IHDR, 4))
  165908. png_handle_IHDR(png_ptr, info_ptr, length);
  165909. else if (!png_memcmp(png_ptr->chunk_name, png_IEND, 4))
  165910. png_handle_IEND(png_ptr, info_ptr, length);
  165911. #ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
  165912. else if (png_handle_as_unknown(png_ptr, png_ptr->chunk_name))
  165913. {
  165914. if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  165915. {
  165916. if ((length > 0) || (png_ptr->mode & PNG_HAVE_CHUNK_AFTER_IDAT))
  165917. png_error(png_ptr, "Too many IDAT's found");
  165918. }
  165919. png_handle_unknown(png_ptr, info_ptr, length);
  165920. if (!png_memcmp(png_ptr->chunk_name, png_PLTE, 4))
  165921. png_ptr->mode |= PNG_HAVE_PLTE;
  165922. }
  165923. #endif
  165924. else if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  165925. {
  165926. if ((length > 0) || (png_ptr->mode & PNG_HAVE_CHUNK_AFTER_IDAT))
  165927. png_error(png_ptr, "Too many IDAT's found");
  165928. png_crc_finish(png_ptr, length);
  165929. }
  165930. else if (!png_memcmp(png_ptr->chunk_name, png_PLTE, 4))
  165931. png_handle_PLTE(png_ptr, info_ptr, length);
  165932. #if defined(PNG_READ_bKGD_SUPPORTED)
  165933. else if (!png_memcmp(png_ptr->chunk_name, png_bKGD, 4))
  165934. png_handle_bKGD(png_ptr, info_ptr, length);
  165935. #endif
  165936. #if defined(PNG_READ_cHRM_SUPPORTED)
  165937. else if (!png_memcmp(png_ptr->chunk_name, png_cHRM, 4))
  165938. png_handle_cHRM(png_ptr, info_ptr, length);
  165939. #endif
  165940. #if defined(PNG_READ_gAMA_SUPPORTED)
  165941. else if (!png_memcmp(png_ptr->chunk_name, png_gAMA, 4))
  165942. png_handle_gAMA(png_ptr, info_ptr, length);
  165943. #endif
  165944. #if defined(PNG_READ_hIST_SUPPORTED)
  165945. else if (!png_memcmp(png_ptr->chunk_name, png_hIST, 4))
  165946. png_handle_hIST(png_ptr, info_ptr, length);
  165947. #endif
  165948. #if defined(PNG_READ_oFFs_SUPPORTED)
  165949. else if (!png_memcmp(png_ptr->chunk_name, png_oFFs, 4))
  165950. png_handle_oFFs(png_ptr, info_ptr, length);
  165951. #endif
  165952. #if defined(PNG_READ_pCAL_SUPPORTED)
  165953. else if (!png_memcmp(png_ptr->chunk_name, png_pCAL, 4))
  165954. png_handle_pCAL(png_ptr, info_ptr, length);
  165955. #endif
  165956. #if defined(PNG_READ_sCAL_SUPPORTED)
  165957. else if (!png_memcmp(png_ptr->chunk_name, png_sCAL, 4))
  165958. png_handle_sCAL(png_ptr, info_ptr, length);
  165959. #endif
  165960. #if defined(PNG_READ_pHYs_SUPPORTED)
  165961. else if (!png_memcmp(png_ptr->chunk_name, png_pHYs, 4))
  165962. png_handle_pHYs(png_ptr, info_ptr, length);
  165963. #endif
  165964. #if defined(PNG_READ_sBIT_SUPPORTED)
  165965. else if (!png_memcmp(png_ptr->chunk_name, png_sBIT, 4))
  165966. png_handle_sBIT(png_ptr, info_ptr, length);
  165967. #endif
  165968. #if defined(PNG_READ_sRGB_SUPPORTED)
  165969. else if (!png_memcmp(png_ptr->chunk_name, png_sRGB, 4))
  165970. png_handle_sRGB(png_ptr, info_ptr, length);
  165971. #endif
  165972. #if defined(PNG_READ_iCCP_SUPPORTED)
  165973. else if (!png_memcmp(png_ptr->chunk_name, png_iCCP, 4))
  165974. png_handle_iCCP(png_ptr, info_ptr, length);
  165975. #endif
  165976. #if defined(PNG_READ_sPLT_SUPPORTED)
  165977. else if (!png_memcmp(png_ptr->chunk_name, png_sPLT, 4))
  165978. png_handle_sPLT(png_ptr, info_ptr, length);
  165979. #endif
  165980. #if defined(PNG_READ_tEXt_SUPPORTED)
  165981. else if (!png_memcmp(png_ptr->chunk_name, png_tEXt, 4))
  165982. png_handle_tEXt(png_ptr, info_ptr, length);
  165983. #endif
  165984. #if defined(PNG_READ_tIME_SUPPORTED)
  165985. else if (!png_memcmp(png_ptr->chunk_name, png_tIME, 4))
  165986. png_handle_tIME(png_ptr, info_ptr, length);
  165987. #endif
  165988. #if defined(PNG_READ_tRNS_SUPPORTED)
  165989. else if (!png_memcmp(png_ptr->chunk_name, png_tRNS, 4))
  165990. png_handle_tRNS(png_ptr, info_ptr, length);
  165991. #endif
  165992. #if defined(PNG_READ_zTXt_SUPPORTED)
  165993. else if (!png_memcmp(png_ptr->chunk_name, png_zTXt, 4))
  165994. png_handle_zTXt(png_ptr, info_ptr, length);
  165995. #endif
  165996. #if defined(PNG_READ_iTXt_SUPPORTED)
  165997. else if (!png_memcmp(png_ptr->chunk_name, png_iTXt, 4))
  165998. png_handle_iTXt(png_ptr, info_ptr, length);
  165999. #endif
  166000. else
  166001. png_handle_unknown(png_ptr, info_ptr, length);
  166002. } while (!(png_ptr->mode & PNG_HAVE_IEND));
  166003. }
  166004. #endif /* PNG_NO_SEQUENTIAL_READ_SUPPORTED */
  166005. void PNGAPI
  166006. png_destroy_read_struct(png_structpp png_ptr_ptr, png_infopp info_ptr_ptr,
  166007. png_infopp end_info_ptr_ptr)
  166008. {
  166009. png_structp png_ptr = NULL;
  166010. png_infop info_ptr = NULL, end_info_ptr = NULL;
  166011. #ifdef PNG_USER_MEM_SUPPORTED
  166012. png_free_ptr free_fn;
  166013. png_voidp mem_ptr;
  166014. #endif
  166015. png_debug(1, "in png_destroy_read_struct\n");
  166016. if (png_ptr_ptr != NULL)
  166017. png_ptr = *png_ptr_ptr;
  166018. if (info_ptr_ptr != NULL)
  166019. info_ptr = *info_ptr_ptr;
  166020. if (end_info_ptr_ptr != NULL)
  166021. end_info_ptr = *end_info_ptr_ptr;
  166022. #ifdef PNG_USER_MEM_SUPPORTED
  166023. free_fn = png_ptr->free_fn;
  166024. mem_ptr = png_ptr->mem_ptr;
  166025. #endif
  166026. png_read_destroy(png_ptr, info_ptr, end_info_ptr);
  166027. if (info_ptr != NULL)
  166028. {
  166029. #if defined(PNG_TEXT_SUPPORTED)
  166030. png_free_data(png_ptr, info_ptr, PNG_FREE_TEXT, -1);
  166031. #endif
  166032. #ifdef PNG_USER_MEM_SUPPORTED
  166033. png_destroy_struct_2((png_voidp)info_ptr, (png_free_ptr)free_fn,
  166034. (png_voidp)mem_ptr);
  166035. #else
  166036. png_destroy_struct((png_voidp)info_ptr);
  166037. #endif
  166038. *info_ptr_ptr = NULL;
  166039. }
  166040. if (end_info_ptr != NULL)
  166041. {
  166042. #if defined(PNG_READ_TEXT_SUPPORTED)
  166043. png_free_data(png_ptr, end_info_ptr, PNG_FREE_TEXT, -1);
  166044. #endif
  166045. #ifdef PNG_USER_MEM_SUPPORTED
  166046. png_destroy_struct_2((png_voidp)end_info_ptr, (png_free_ptr)free_fn,
  166047. (png_voidp)mem_ptr);
  166048. #else
  166049. png_destroy_struct((png_voidp)end_info_ptr);
  166050. #endif
  166051. *end_info_ptr_ptr = NULL;
  166052. }
  166053. if (png_ptr != NULL)
  166054. {
  166055. #ifdef PNG_USER_MEM_SUPPORTED
  166056. png_destroy_struct_2((png_voidp)png_ptr, (png_free_ptr)free_fn,
  166057. (png_voidp)mem_ptr);
  166058. #else
  166059. png_destroy_struct((png_voidp)png_ptr);
  166060. #endif
  166061. *png_ptr_ptr = NULL;
  166062. }
  166063. }
  166064. void /* PRIVATE */
  166065. png_read_destroy(png_structp png_ptr, png_infop info_ptr, png_infop end_info_ptr)
  166066. {
  166067. #ifdef PNG_SETJMP_SUPPORTED
  166068. jmp_buf tmp_jmp;
  166069. #endif
  166070. png_error_ptr error_fn;
  166071. png_error_ptr warning_fn;
  166072. png_voidp error_ptr;
  166073. #ifdef PNG_USER_MEM_SUPPORTED
  166074. png_free_ptr free_fn;
  166075. #endif
  166076. png_debug(1, "in png_read_destroy\n");
  166077. if (info_ptr != NULL)
  166078. png_info_destroy(png_ptr, info_ptr);
  166079. if (end_info_ptr != NULL)
  166080. png_info_destroy(png_ptr, end_info_ptr);
  166081. png_free(png_ptr, png_ptr->zbuf);
  166082. png_free(png_ptr, png_ptr->big_row_buf);
  166083. png_free(png_ptr, png_ptr->prev_row);
  166084. #if defined(PNG_READ_DITHER_SUPPORTED)
  166085. png_free(png_ptr, png_ptr->palette_lookup);
  166086. png_free(png_ptr, png_ptr->dither_index);
  166087. #endif
  166088. #if defined(PNG_READ_GAMMA_SUPPORTED)
  166089. png_free(png_ptr, png_ptr->gamma_table);
  166090. #endif
  166091. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  166092. png_free(png_ptr, png_ptr->gamma_from_1);
  166093. png_free(png_ptr, png_ptr->gamma_to_1);
  166094. #endif
  166095. #ifdef PNG_FREE_ME_SUPPORTED
  166096. if (png_ptr->free_me & PNG_FREE_PLTE)
  166097. png_zfree(png_ptr, png_ptr->palette);
  166098. png_ptr->free_me &= ~PNG_FREE_PLTE;
  166099. #else
  166100. if (png_ptr->flags & PNG_FLAG_FREE_PLTE)
  166101. png_zfree(png_ptr, png_ptr->palette);
  166102. png_ptr->flags &= ~PNG_FLAG_FREE_PLTE;
  166103. #endif
  166104. #if defined(PNG_tRNS_SUPPORTED) || \
  166105. defined(PNG_READ_EXPAND_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
  166106. #ifdef PNG_FREE_ME_SUPPORTED
  166107. if (png_ptr->free_me & PNG_FREE_TRNS)
  166108. png_free(png_ptr, png_ptr->trans);
  166109. png_ptr->free_me &= ~PNG_FREE_TRNS;
  166110. #else
  166111. if (png_ptr->flags & PNG_FLAG_FREE_TRNS)
  166112. png_free(png_ptr, png_ptr->trans);
  166113. png_ptr->flags &= ~PNG_FLAG_FREE_TRNS;
  166114. #endif
  166115. #endif
  166116. #if defined(PNG_READ_hIST_SUPPORTED)
  166117. #ifdef PNG_FREE_ME_SUPPORTED
  166118. if (png_ptr->free_me & PNG_FREE_HIST)
  166119. png_free(png_ptr, png_ptr->hist);
  166120. png_ptr->free_me &= ~PNG_FREE_HIST;
  166121. #else
  166122. if (png_ptr->flags & PNG_FLAG_FREE_HIST)
  166123. png_free(png_ptr, png_ptr->hist);
  166124. png_ptr->flags &= ~PNG_FLAG_FREE_HIST;
  166125. #endif
  166126. #endif
  166127. #if defined(PNG_READ_GAMMA_SUPPORTED)
  166128. if (png_ptr->gamma_16_table != NULL)
  166129. {
  166130. int i;
  166131. int istop = (1 << (8 - png_ptr->gamma_shift));
  166132. for (i = 0; i < istop; i++)
  166133. {
  166134. png_free(png_ptr, png_ptr->gamma_16_table[i]);
  166135. }
  166136. png_free(png_ptr, png_ptr->gamma_16_table);
  166137. }
  166138. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  166139. if (png_ptr->gamma_16_from_1 != NULL)
  166140. {
  166141. int i;
  166142. int istop = (1 << (8 - png_ptr->gamma_shift));
  166143. for (i = 0; i < istop; i++)
  166144. {
  166145. png_free(png_ptr, png_ptr->gamma_16_from_1[i]);
  166146. }
  166147. png_free(png_ptr, png_ptr->gamma_16_from_1);
  166148. }
  166149. if (png_ptr->gamma_16_to_1 != NULL)
  166150. {
  166151. int i;
  166152. int istop = (1 << (8 - png_ptr->gamma_shift));
  166153. for (i = 0; i < istop; i++)
  166154. {
  166155. png_free(png_ptr, png_ptr->gamma_16_to_1[i]);
  166156. }
  166157. png_free(png_ptr, png_ptr->gamma_16_to_1);
  166158. }
  166159. #endif
  166160. #endif
  166161. #if defined(PNG_TIME_RFC1123_SUPPORTED)
  166162. png_free(png_ptr, png_ptr->time_buffer);
  166163. #endif
  166164. inflateEnd(&png_ptr->zstream);
  166165. #ifdef PNG_PROGRESSIVE_READ_SUPPORTED
  166166. png_free(png_ptr, png_ptr->save_buffer);
  166167. #endif
  166168. #ifdef PNG_PROGRESSIVE_READ_SUPPORTED
  166169. #ifdef PNG_TEXT_SUPPORTED
  166170. png_free(png_ptr, png_ptr->current_text);
  166171. #endif /* PNG_TEXT_SUPPORTED */
  166172. #endif /* PNG_PROGRESSIVE_READ_SUPPORTED */
  166173. #ifdef PNG_SETJMP_SUPPORTED
  166174. png_memcpy(tmp_jmp, png_ptr->jmpbuf, png_sizeof (jmp_buf));
  166175. #endif
  166176. error_fn = png_ptr->error_fn;
  166177. warning_fn = png_ptr->warning_fn;
  166178. error_ptr = png_ptr->error_ptr;
  166179. #ifdef PNG_USER_MEM_SUPPORTED
  166180. free_fn = png_ptr->free_fn;
  166181. #endif
  166182. png_memset(png_ptr, 0, png_sizeof (png_struct));
  166183. png_ptr->error_fn = error_fn;
  166184. png_ptr->warning_fn = warning_fn;
  166185. png_ptr->error_ptr = error_ptr;
  166186. #ifdef PNG_USER_MEM_SUPPORTED
  166187. png_ptr->free_fn = free_fn;
  166188. #endif
  166189. #ifdef PNG_SETJMP_SUPPORTED
  166190. png_memcpy(png_ptr->jmpbuf, tmp_jmp, png_sizeof (jmp_buf));
  166191. #endif
  166192. }
  166193. void PNGAPI
  166194. png_set_read_status_fn(png_structp png_ptr, png_read_status_ptr read_row_fn)
  166195. {
  166196. if(png_ptr == NULL) return;
  166197. png_ptr->read_row_fn = read_row_fn;
  166198. }
  166199. #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
  166200. #if defined(PNG_INFO_IMAGE_SUPPORTED)
  166201. void PNGAPI
  166202. png_read_png(png_structp png_ptr, png_infop info_ptr,
  166203. int transforms,
  166204. voidp params)
  166205. {
  166206. int row;
  166207. if(png_ptr == NULL) return;
  166208. #if defined(PNG_READ_INVERT_ALPHA_SUPPORTED)
  166209. if (transforms & PNG_TRANSFORM_INVERT_ALPHA)
  166210. png_set_invert_alpha(png_ptr);
  166211. #endif
  166212. png_read_info(png_ptr, info_ptr);
  166213. if (info_ptr->height > PNG_UINT_32_MAX/png_sizeof(png_bytep))
  166214. png_error(png_ptr,"Image is too high to process with png_read_png()");
  166215. #if defined(PNG_READ_16_TO_8_SUPPORTED)
  166216. if (transforms & PNG_TRANSFORM_STRIP_16)
  166217. png_set_strip_16(png_ptr);
  166218. #endif
  166219. #if defined(PNG_READ_STRIP_ALPHA_SUPPORTED)
  166220. if (transforms & PNG_TRANSFORM_STRIP_ALPHA)
  166221. png_set_strip_alpha(png_ptr);
  166222. #endif
  166223. #if defined(PNG_READ_PACK_SUPPORTED) && !defined(PNG_READ_EXPAND_SUPPORTED)
  166224. if (transforms & PNG_TRANSFORM_PACKING)
  166225. png_set_packing(png_ptr);
  166226. #endif
  166227. #if defined(PNG_READ_PACKSWAP_SUPPORTED)
  166228. if (transforms & PNG_TRANSFORM_PACKSWAP)
  166229. png_set_packswap(png_ptr);
  166230. #endif
  166231. #if defined(PNG_READ_EXPAND_SUPPORTED)
  166232. if (transforms & PNG_TRANSFORM_EXPAND)
  166233. if ((png_ptr->bit_depth < 8) ||
  166234. (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE) ||
  166235. (png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS)))
  166236. png_set_expand(png_ptr);
  166237. #endif
  166238. #if defined(PNG_READ_INVERT_SUPPORTED)
  166239. if (transforms & PNG_TRANSFORM_INVERT_MONO)
  166240. png_set_invert_mono(png_ptr);
  166241. #endif
  166242. #if defined(PNG_READ_SHIFT_SUPPORTED)
  166243. if ((transforms & PNG_TRANSFORM_SHIFT)
  166244. && png_get_valid(png_ptr, info_ptr, PNG_INFO_sBIT))
  166245. {
  166246. png_color_8p sig_bit;
  166247. png_get_sBIT(png_ptr, info_ptr, &sig_bit);
  166248. png_set_shift(png_ptr, sig_bit);
  166249. }
  166250. #endif
  166251. #if defined(PNG_READ_BGR_SUPPORTED)
  166252. if (transforms & PNG_TRANSFORM_BGR)
  166253. png_set_bgr(png_ptr);
  166254. #endif
  166255. #if defined(PNG_READ_SWAP_ALPHA_SUPPORTED)
  166256. if (transforms & PNG_TRANSFORM_SWAP_ALPHA)
  166257. png_set_swap_alpha(png_ptr);
  166258. #endif
  166259. #if defined(PNG_READ_SWAP_SUPPORTED)
  166260. if (transforms & PNG_TRANSFORM_SWAP_ENDIAN)
  166261. png_set_swap(png_ptr);
  166262. #endif
  166263. png_read_update_info(png_ptr, info_ptr);
  166264. #ifdef PNG_FREE_ME_SUPPORTED
  166265. png_free_data(png_ptr, info_ptr, PNG_FREE_ROWS, 0);
  166266. #endif
  166267. if(info_ptr->row_pointers == NULL)
  166268. {
  166269. info_ptr->row_pointers = (png_bytepp)png_malloc(png_ptr,
  166270. info_ptr->height * png_sizeof(png_bytep));
  166271. #ifdef PNG_FREE_ME_SUPPORTED
  166272. info_ptr->free_me |= PNG_FREE_ROWS;
  166273. #endif
  166274. for (row = 0; row < (int)info_ptr->height; row++)
  166275. {
  166276. info_ptr->row_pointers[row] = (png_bytep)png_malloc(png_ptr,
  166277. png_get_rowbytes(png_ptr, info_ptr));
  166278. }
  166279. }
  166280. png_read_image(png_ptr, info_ptr->row_pointers);
  166281. info_ptr->valid |= PNG_INFO_IDAT;
  166282. png_read_end(png_ptr, info_ptr);
  166283. transforms = transforms; /* quiet compiler warnings */
  166284. params = params;
  166285. }
  166286. #endif /* PNG_INFO_IMAGE_SUPPORTED */
  166287. #endif /* PNG_NO_SEQUENTIAL_READ_SUPPORTED */
  166288. #endif /* PNG_READ_SUPPORTED */
  166289. /********* End of inlined file: pngread.c *********/
  166290. /********* Start of inlined file: pngpread.c *********/
  166291. #define PNG_INTERNAL
  166292. #ifdef PNG_PROGRESSIVE_READ_SUPPORTED
  166293. #define PNG_READ_SIG_MODE 0
  166294. #define PNG_READ_CHUNK_MODE 1
  166295. #define PNG_READ_IDAT_MODE 2
  166296. #define PNG_SKIP_MODE 3
  166297. #define PNG_READ_tEXt_MODE 4
  166298. #define PNG_READ_zTXt_MODE 5
  166299. #define PNG_READ_DONE_MODE 6
  166300. #define PNG_READ_iTXt_MODE 7
  166301. #define PNG_ERROR_MODE 8
  166302. void PNGAPI
  166303. png_process_data(png_structp png_ptr, png_infop info_ptr,
  166304. png_bytep buffer, png_size_t buffer_size)
  166305. {
  166306. if(png_ptr == NULL) return;
  166307. png_push_restore_buffer(png_ptr, buffer, buffer_size);
  166308. while (png_ptr->buffer_size)
  166309. {
  166310. png_process_some_data(png_ptr, info_ptr);
  166311. }
  166312. }
  166313. void /* PRIVATE */
  166314. png_process_some_data(png_structp png_ptr, png_infop info_ptr)
  166315. {
  166316. if(png_ptr == NULL) return;
  166317. switch (png_ptr->process_mode)
  166318. {
  166319. case PNG_READ_SIG_MODE:
  166320. {
  166321. png_push_read_sig(png_ptr, info_ptr);
  166322. break;
  166323. }
  166324. case PNG_READ_CHUNK_MODE:
  166325. {
  166326. png_push_read_chunk(png_ptr, info_ptr);
  166327. break;
  166328. }
  166329. case PNG_READ_IDAT_MODE:
  166330. {
  166331. png_push_read_IDAT(png_ptr);
  166332. break;
  166333. }
  166334. #if defined(PNG_READ_tEXt_SUPPORTED)
  166335. case PNG_READ_tEXt_MODE:
  166336. {
  166337. png_push_read_tEXt(png_ptr, info_ptr);
  166338. break;
  166339. }
  166340. #endif
  166341. #if defined(PNG_READ_zTXt_SUPPORTED)
  166342. case PNG_READ_zTXt_MODE:
  166343. {
  166344. png_push_read_zTXt(png_ptr, info_ptr);
  166345. break;
  166346. }
  166347. #endif
  166348. #if defined(PNG_READ_iTXt_SUPPORTED)
  166349. case PNG_READ_iTXt_MODE:
  166350. {
  166351. png_push_read_iTXt(png_ptr, info_ptr);
  166352. break;
  166353. }
  166354. #endif
  166355. case PNG_SKIP_MODE:
  166356. {
  166357. png_push_crc_finish(png_ptr);
  166358. break;
  166359. }
  166360. default:
  166361. {
  166362. png_ptr->buffer_size = 0;
  166363. break;
  166364. }
  166365. }
  166366. }
  166367. void /* PRIVATE */
  166368. png_push_read_sig(png_structp png_ptr, png_infop info_ptr)
  166369. {
  166370. png_size_t num_checked = png_ptr->sig_bytes,
  166371. num_to_check = 8 - num_checked;
  166372. if (png_ptr->buffer_size < num_to_check)
  166373. {
  166374. num_to_check = png_ptr->buffer_size;
  166375. }
  166376. png_push_fill_buffer(png_ptr, &(info_ptr->signature[num_checked]),
  166377. num_to_check);
  166378. png_ptr->sig_bytes = (png_byte)(png_ptr->sig_bytes+num_to_check);
  166379. if (png_sig_cmp(info_ptr->signature, num_checked, num_to_check))
  166380. {
  166381. if (num_checked < 4 &&
  166382. png_sig_cmp(info_ptr->signature, num_checked, num_to_check - 4))
  166383. png_error(png_ptr, "Not a PNG file");
  166384. else
  166385. png_error(png_ptr, "PNG file corrupted by ASCII conversion");
  166386. }
  166387. else
  166388. {
  166389. if (png_ptr->sig_bytes >= 8)
  166390. {
  166391. png_ptr->process_mode = PNG_READ_CHUNK_MODE;
  166392. }
  166393. }
  166394. }
  166395. void /* PRIVATE */
  166396. png_push_read_chunk(png_structp png_ptr, png_infop info_ptr)
  166397. {
  166398. #ifdef PNG_USE_LOCAL_ARRAYS
  166399. PNG_CONST PNG_IHDR;
  166400. PNG_CONST PNG_IDAT;
  166401. PNG_CONST PNG_IEND;
  166402. PNG_CONST PNG_PLTE;
  166403. #if defined(PNG_READ_bKGD_SUPPORTED)
  166404. PNG_CONST PNG_bKGD;
  166405. #endif
  166406. #if defined(PNG_READ_cHRM_SUPPORTED)
  166407. PNG_CONST PNG_cHRM;
  166408. #endif
  166409. #if defined(PNG_READ_gAMA_SUPPORTED)
  166410. PNG_CONST PNG_gAMA;
  166411. #endif
  166412. #if defined(PNG_READ_hIST_SUPPORTED)
  166413. PNG_CONST PNG_hIST;
  166414. #endif
  166415. #if defined(PNG_READ_iCCP_SUPPORTED)
  166416. PNG_CONST PNG_iCCP;
  166417. #endif
  166418. #if defined(PNG_READ_iTXt_SUPPORTED)
  166419. PNG_CONST PNG_iTXt;
  166420. #endif
  166421. #if defined(PNG_READ_oFFs_SUPPORTED)
  166422. PNG_CONST PNG_oFFs;
  166423. #endif
  166424. #if defined(PNG_READ_pCAL_SUPPORTED)
  166425. PNG_CONST PNG_pCAL;
  166426. #endif
  166427. #if defined(PNG_READ_pHYs_SUPPORTED)
  166428. PNG_CONST PNG_pHYs;
  166429. #endif
  166430. #if defined(PNG_READ_sBIT_SUPPORTED)
  166431. PNG_CONST PNG_sBIT;
  166432. #endif
  166433. #if defined(PNG_READ_sCAL_SUPPORTED)
  166434. PNG_CONST PNG_sCAL;
  166435. #endif
  166436. #if defined(PNG_READ_sRGB_SUPPORTED)
  166437. PNG_CONST PNG_sRGB;
  166438. #endif
  166439. #if defined(PNG_READ_sPLT_SUPPORTED)
  166440. PNG_CONST PNG_sPLT;
  166441. #endif
  166442. #if defined(PNG_READ_tEXt_SUPPORTED)
  166443. PNG_CONST PNG_tEXt;
  166444. #endif
  166445. #if defined(PNG_READ_tIME_SUPPORTED)
  166446. PNG_CONST PNG_tIME;
  166447. #endif
  166448. #if defined(PNG_READ_tRNS_SUPPORTED)
  166449. PNG_CONST PNG_tRNS;
  166450. #endif
  166451. #if defined(PNG_READ_zTXt_SUPPORTED)
  166452. PNG_CONST PNG_zTXt;
  166453. #endif
  166454. #endif /* PNG_USE_LOCAL_ARRAYS */
  166455. if (!(png_ptr->mode & PNG_HAVE_CHUNK_HEADER))
  166456. {
  166457. png_byte chunk_length[4];
  166458. if (png_ptr->buffer_size < 8)
  166459. {
  166460. png_push_save_buffer(png_ptr);
  166461. return;
  166462. }
  166463. png_push_fill_buffer(png_ptr, chunk_length, 4);
  166464. png_ptr->push_length = png_get_uint_31(png_ptr,chunk_length);
  166465. png_reset_crc(png_ptr);
  166466. png_crc_read(png_ptr, png_ptr->chunk_name, 4);
  166467. png_ptr->mode |= PNG_HAVE_CHUNK_HEADER;
  166468. }
  166469. if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  166470. if(png_ptr->mode & PNG_AFTER_IDAT)
  166471. png_ptr->mode |= PNG_HAVE_CHUNK_AFTER_IDAT;
  166472. if (!png_memcmp(png_ptr->chunk_name, png_IHDR, 4))
  166473. {
  166474. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  166475. {
  166476. png_push_save_buffer(png_ptr);
  166477. return;
  166478. }
  166479. png_handle_IHDR(png_ptr, info_ptr, png_ptr->push_length);
  166480. }
  166481. else if (!png_memcmp(png_ptr->chunk_name, png_IEND, 4))
  166482. {
  166483. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  166484. {
  166485. png_push_save_buffer(png_ptr);
  166486. return;
  166487. }
  166488. png_handle_IEND(png_ptr, info_ptr, png_ptr->push_length);
  166489. png_ptr->process_mode = PNG_READ_DONE_MODE;
  166490. png_push_have_end(png_ptr, info_ptr);
  166491. }
  166492. #ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
  166493. else if (png_handle_as_unknown(png_ptr, png_ptr->chunk_name))
  166494. {
  166495. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  166496. {
  166497. png_push_save_buffer(png_ptr);
  166498. return;
  166499. }
  166500. if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  166501. png_ptr->mode |= PNG_HAVE_IDAT;
  166502. png_handle_unknown(png_ptr, info_ptr, png_ptr->push_length);
  166503. if (!png_memcmp(png_ptr->chunk_name, png_PLTE, 4))
  166504. png_ptr->mode |= PNG_HAVE_PLTE;
  166505. else if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  166506. {
  166507. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  166508. png_error(png_ptr, "Missing IHDR before IDAT");
  166509. else if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE &&
  166510. !(png_ptr->mode & PNG_HAVE_PLTE))
  166511. png_error(png_ptr, "Missing PLTE before IDAT");
  166512. }
  166513. }
  166514. #endif
  166515. else if (!png_memcmp(png_ptr->chunk_name, png_PLTE, 4))
  166516. {
  166517. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  166518. {
  166519. png_push_save_buffer(png_ptr);
  166520. return;
  166521. }
  166522. png_handle_PLTE(png_ptr, info_ptr, png_ptr->push_length);
  166523. }
  166524. else if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  166525. {
  166526. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  166527. png_error(png_ptr, "Missing IHDR before IDAT");
  166528. else if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE &&
  166529. !(png_ptr->mode & PNG_HAVE_PLTE))
  166530. png_error(png_ptr, "Missing PLTE before IDAT");
  166531. if (png_ptr->mode & PNG_HAVE_IDAT)
  166532. {
  166533. if (!(png_ptr->mode & PNG_HAVE_CHUNK_AFTER_IDAT))
  166534. if (png_ptr->push_length == 0)
  166535. return;
  166536. if (png_ptr->mode & PNG_AFTER_IDAT)
  166537. png_error(png_ptr, "Too many IDAT's found");
  166538. }
  166539. png_ptr->idat_size = png_ptr->push_length;
  166540. png_ptr->mode |= PNG_HAVE_IDAT;
  166541. png_ptr->process_mode = PNG_READ_IDAT_MODE;
  166542. png_push_have_info(png_ptr, info_ptr);
  166543. png_ptr->zstream.avail_out = (uInt)png_ptr->irowbytes;
  166544. png_ptr->zstream.next_out = png_ptr->row_buf;
  166545. return;
  166546. }
  166547. #if defined(PNG_READ_gAMA_SUPPORTED)
  166548. else if (!png_memcmp(png_ptr->chunk_name, png_gAMA, 4))
  166549. {
  166550. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  166551. {
  166552. png_push_save_buffer(png_ptr);
  166553. return;
  166554. }
  166555. png_handle_gAMA(png_ptr, info_ptr, png_ptr->push_length);
  166556. }
  166557. #endif
  166558. #if defined(PNG_READ_sBIT_SUPPORTED)
  166559. else if (!png_memcmp(png_ptr->chunk_name, png_sBIT, 4))
  166560. {
  166561. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  166562. {
  166563. png_push_save_buffer(png_ptr);
  166564. return;
  166565. }
  166566. png_handle_sBIT(png_ptr, info_ptr, png_ptr->push_length);
  166567. }
  166568. #endif
  166569. #if defined(PNG_READ_cHRM_SUPPORTED)
  166570. else if (!png_memcmp(png_ptr->chunk_name, png_cHRM, 4))
  166571. {
  166572. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  166573. {
  166574. png_push_save_buffer(png_ptr);
  166575. return;
  166576. }
  166577. png_handle_cHRM(png_ptr, info_ptr, png_ptr->push_length);
  166578. }
  166579. #endif
  166580. #if defined(PNG_READ_sRGB_SUPPORTED)
  166581. else if (!png_memcmp(png_ptr->chunk_name, png_sRGB, 4))
  166582. {
  166583. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  166584. {
  166585. png_push_save_buffer(png_ptr);
  166586. return;
  166587. }
  166588. png_handle_sRGB(png_ptr, info_ptr, png_ptr->push_length);
  166589. }
  166590. #endif
  166591. #if defined(PNG_READ_iCCP_SUPPORTED)
  166592. else if (!png_memcmp(png_ptr->chunk_name, png_iCCP, 4))
  166593. {
  166594. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  166595. {
  166596. png_push_save_buffer(png_ptr);
  166597. return;
  166598. }
  166599. png_handle_iCCP(png_ptr, info_ptr, png_ptr->push_length);
  166600. }
  166601. #endif
  166602. #if defined(PNG_READ_sPLT_SUPPORTED)
  166603. else if (!png_memcmp(png_ptr->chunk_name, png_sPLT, 4))
  166604. {
  166605. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  166606. {
  166607. png_push_save_buffer(png_ptr);
  166608. return;
  166609. }
  166610. png_handle_sPLT(png_ptr, info_ptr, png_ptr->push_length);
  166611. }
  166612. #endif
  166613. #if defined(PNG_READ_tRNS_SUPPORTED)
  166614. else if (!png_memcmp(png_ptr->chunk_name, png_tRNS, 4))
  166615. {
  166616. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  166617. {
  166618. png_push_save_buffer(png_ptr);
  166619. return;
  166620. }
  166621. png_handle_tRNS(png_ptr, info_ptr, png_ptr->push_length);
  166622. }
  166623. #endif
  166624. #if defined(PNG_READ_bKGD_SUPPORTED)
  166625. else if (!png_memcmp(png_ptr->chunk_name, png_bKGD, 4))
  166626. {
  166627. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  166628. {
  166629. png_push_save_buffer(png_ptr);
  166630. return;
  166631. }
  166632. png_handle_bKGD(png_ptr, info_ptr, png_ptr->push_length);
  166633. }
  166634. #endif
  166635. #if defined(PNG_READ_hIST_SUPPORTED)
  166636. else if (!png_memcmp(png_ptr->chunk_name, png_hIST, 4))
  166637. {
  166638. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  166639. {
  166640. png_push_save_buffer(png_ptr);
  166641. return;
  166642. }
  166643. png_handle_hIST(png_ptr, info_ptr, png_ptr->push_length);
  166644. }
  166645. #endif
  166646. #if defined(PNG_READ_pHYs_SUPPORTED)
  166647. else if (!png_memcmp(png_ptr->chunk_name, png_pHYs, 4))
  166648. {
  166649. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  166650. {
  166651. png_push_save_buffer(png_ptr);
  166652. return;
  166653. }
  166654. png_handle_pHYs(png_ptr, info_ptr, png_ptr->push_length);
  166655. }
  166656. #endif
  166657. #if defined(PNG_READ_oFFs_SUPPORTED)
  166658. else if (!png_memcmp(png_ptr->chunk_name, png_oFFs, 4))
  166659. {
  166660. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  166661. {
  166662. png_push_save_buffer(png_ptr);
  166663. return;
  166664. }
  166665. png_handle_oFFs(png_ptr, info_ptr, png_ptr->push_length);
  166666. }
  166667. #endif
  166668. #if defined(PNG_READ_pCAL_SUPPORTED)
  166669. else if (!png_memcmp(png_ptr->chunk_name, png_pCAL, 4))
  166670. {
  166671. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  166672. {
  166673. png_push_save_buffer(png_ptr);
  166674. return;
  166675. }
  166676. png_handle_pCAL(png_ptr, info_ptr, png_ptr->push_length);
  166677. }
  166678. #endif
  166679. #if defined(PNG_READ_sCAL_SUPPORTED)
  166680. else if (!png_memcmp(png_ptr->chunk_name, png_sCAL, 4))
  166681. {
  166682. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  166683. {
  166684. png_push_save_buffer(png_ptr);
  166685. return;
  166686. }
  166687. png_handle_sCAL(png_ptr, info_ptr, png_ptr->push_length);
  166688. }
  166689. #endif
  166690. #if defined(PNG_READ_tIME_SUPPORTED)
  166691. else if (!png_memcmp(png_ptr->chunk_name, png_tIME, 4))
  166692. {
  166693. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  166694. {
  166695. png_push_save_buffer(png_ptr);
  166696. return;
  166697. }
  166698. png_handle_tIME(png_ptr, info_ptr, png_ptr->push_length);
  166699. }
  166700. #endif
  166701. #if defined(PNG_READ_tEXt_SUPPORTED)
  166702. else if (!png_memcmp(png_ptr->chunk_name, png_tEXt, 4))
  166703. {
  166704. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  166705. {
  166706. png_push_save_buffer(png_ptr);
  166707. return;
  166708. }
  166709. png_push_handle_tEXt(png_ptr, info_ptr, png_ptr->push_length);
  166710. }
  166711. #endif
  166712. #if defined(PNG_READ_zTXt_SUPPORTED)
  166713. else if (!png_memcmp(png_ptr->chunk_name, png_zTXt, 4))
  166714. {
  166715. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  166716. {
  166717. png_push_save_buffer(png_ptr);
  166718. return;
  166719. }
  166720. png_push_handle_zTXt(png_ptr, info_ptr, png_ptr->push_length);
  166721. }
  166722. #endif
  166723. #if defined(PNG_READ_iTXt_SUPPORTED)
  166724. else if (!png_memcmp(png_ptr->chunk_name, png_iTXt, 4))
  166725. {
  166726. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  166727. {
  166728. png_push_save_buffer(png_ptr);
  166729. return;
  166730. }
  166731. png_push_handle_iTXt(png_ptr, info_ptr, png_ptr->push_length);
  166732. }
  166733. #endif
  166734. else
  166735. {
  166736. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  166737. {
  166738. png_push_save_buffer(png_ptr);
  166739. return;
  166740. }
  166741. png_push_handle_unknown(png_ptr, info_ptr, png_ptr->push_length);
  166742. }
  166743. png_ptr->mode &= ~PNG_HAVE_CHUNK_HEADER;
  166744. }
  166745. void /* PRIVATE */
  166746. png_push_crc_skip(png_structp png_ptr, png_uint_32 skip)
  166747. {
  166748. png_ptr->process_mode = PNG_SKIP_MODE;
  166749. png_ptr->skip_length = skip;
  166750. }
  166751. void /* PRIVATE */
  166752. png_push_crc_finish(png_structp png_ptr)
  166753. {
  166754. if (png_ptr->skip_length && png_ptr->save_buffer_size)
  166755. {
  166756. png_size_t save_size;
  166757. if (png_ptr->skip_length < (png_uint_32)png_ptr->save_buffer_size)
  166758. save_size = (png_size_t)png_ptr->skip_length;
  166759. else
  166760. save_size = png_ptr->save_buffer_size;
  166761. png_calculate_crc(png_ptr, png_ptr->save_buffer_ptr, save_size);
  166762. png_ptr->skip_length -= save_size;
  166763. png_ptr->buffer_size -= save_size;
  166764. png_ptr->save_buffer_size -= save_size;
  166765. png_ptr->save_buffer_ptr += save_size;
  166766. }
  166767. if (png_ptr->skip_length && png_ptr->current_buffer_size)
  166768. {
  166769. png_size_t save_size;
  166770. if (png_ptr->skip_length < (png_uint_32)png_ptr->current_buffer_size)
  166771. save_size = (png_size_t)png_ptr->skip_length;
  166772. else
  166773. save_size = png_ptr->current_buffer_size;
  166774. png_calculate_crc(png_ptr, png_ptr->current_buffer_ptr, save_size);
  166775. png_ptr->skip_length -= save_size;
  166776. png_ptr->buffer_size -= save_size;
  166777. png_ptr->current_buffer_size -= save_size;
  166778. png_ptr->current_buffer_ptr += save_size;
  166779. }
  166780. if (!png_ptr->skip_length)
  166781. {
  166782. if (png_ptr->buffer_size < 4)
  166783. {
  166784. png_push_save_buffer(png_ptr);
  166785. return;
  166786. }
  166787. png_crc_finish(png_ptr, 0);
  166788. png_ptr->process_mode = PNG_READ_CHUNK_MODE;
  166789. }
  166790. }
  166791. void PNGAPI
  166792. png_push_fill_buffer(png_structp png_ptr, png_bytep buffer, png_size_t length)
  166793. {
  166794. png_bytep ptr;
  166795. if(png_ptr == NULL) return;
  166796. ptr = buffer;
  166797. if (png_ptr->save_buffer_size)
  166798. {
  166799. png_size_t save_size;
  166800. if (length < png_ptr->save_buffer_size)
  166801. save_size = length;
  166802. else
  166803. save_size = png_ptr->save_buffer_size;
  166804. png_memcpy(ptr, png_ptr->save_buffer_ptr, save_size);
  166805. length -= save_size;
  166806. ptr += save_size;
  166807. png_ptr->buffer_size -= save_size;
  166808. png_ptr->save_buffer_size -= save_size;
  166809. png_ptr->save_buffer_ptr += save_size;
  166810. }
  166811. if (length && png_ptr->current_buffer_size)
  166812. {
  166813. png_size_t save_size;
  166814. if (length < png_ptr->current_buffer_size)
  166815. save_size = length;
  166816. else
  166817. save_size = png_ptr->current_buffer_size;
  166818. png_memcpy(ptr, png_ptr->current_buffer_ptr, save_size);
  166819. png_ptr->buffer_size -= save_size;
  166820. png_ptr->current_buffer_size -= save_size;
  166821. png_ptr->current_buffer_ptr += save_size;
  166822. }
  166823. }
  166824. void /* PRIVATE */
  166825. png_push_save_buffer(png_structp png_ptr)
  166826. {
  166827. if (png_ptr->save_buffer_size)
  166828. {
  166829. if (png_ptr->save_buffer_ptr != png_ptr->save_buffer)
  166830. {
  166831. png_size_t i,istop;
  166832. png_bytep sp;
  166833. png_bytep dp;
  166834. istop = png_ptr->save_buffer_size;
  166835. for (i = 0, sp = png_ptr->save_buffer_ptr, dp = png_ptr->save_buffer;
  166836. i < istop; i++, sp++, dp++)
  166837. {
  166838. *dp = *sp;
  166839. }
  166840. }
  166841. }
  166842. if (png_ptr->save_buffer_size + png_ptr->current_buffer_size >
  166843. png_ptr->save_buffer_max)
  166844. {
  166845. png_size_t new_max;
  166846. png_bytep old_buffer;
  166847. if (png_ptr->save_buffer_size > PNG_SIZE_MAX -
  166848. (png_ptr->current_buffer_size + 256))
  166849. {
  166850. png_error(png_ptr, "Potential overflow of save_buffer");
  166851. }
  166852. new_max = png_ptr->save_buffer_size + png_ptr->current_buffer_size + 256;
  166853. old_buffer = png_ptr->save_buffer;
  166854. png_ptr->save_buffer = (png_bytep)png_malloc(png_ptr,
  166855. (png_uint_32)new_max);
  166856. png_memcpy(png_ptr->save_buffer, old_buffer, png_ptr->save_buffer_size);
  166857. png_free(png_ptr, old_buffer);
  166858. png_ptr->save_buffer_max = new_max;
  166859. }
  166860. if (png_ptr->current_buffer_size)
  166861. {
  166862. png_memcpy(png_ptr->save_buffer + png_ptr->save_buffer_size,
  166863. png_ptr->current_buffer_ptr, png_ptr->current_buffer_size);
  166864. png_ptr->save_buffer_size += png_ptr->current_buffer_size;
  166865. png_ptr->current_buffer_size = 0;
  166866. }
  166867. png_ptr->save_buffer_ptr = png_ptr->save_buffer;
  166868. png_ptr->buffer_size = 0;
  166869. }
  166870. void /* PRIVATE */
  166871. png_push_restore_buffer(png_structp png_ptr, png_bytep buffer,
  166872. png_size_t buffer_length)
  166873. {
  166874. png_ptr->current_buffer = buffer;
  166875. png_ptr->current_buffer_size = buffer_length;
  166876. png_ptr->buffer_size = buffer_length + png_ptr->save_buffer_size;
  166877. png_ptr->current_buffer_ptr = png_ptr->current_buffer;
  166878. }
  166879. void /* PRIVATE */
  166880. png_push_read_IDAT(png_structp png_ptr)
  166881. {
  166882. #ifdef PNG_USE_LOCAL_ARRAYS
  166883. PNG_CONST PNG_IDAT;
  166884. #endif
  166885. if (!(png_ptr->mode & PNG_HAVE_CHUNK_HEADER))
  166886. {
  166887. png_byte chunk_length[4];
  166888. if (png_ptr->buffer_size < 8)
  166889. {
  166890. png_push_save_buffer(png_ptr);
  166891. return;
  166892. }
  166893. png_push_fill_buffer(png_ptr, chunk_length, 4);
  166894. png_ptr->push_length = png_get_uint_31(png_ptr,chunk_length);
  166895. png_reset_crc(png_ptr);
  166896. png_crc_read(png_ptr, png_ptr->chunk_name, 4);
  166897. png_ptr->mode |= PNG_HAVE_CHUNK_HEADER;
  166898. if (png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  166899. {
  166900. png_ptr->process_mode = PNG_READ_CHUNK_MODE;
  166901. if (!(png_ptr->flags & PNG_FLAG_ZLIB_FINISHED))
  166902. png_error(png_ptr, "Not enough compressed data");
  166903. return;
  166904. }
  166905. png_ptr->idat_size = png_ptr->push_length;
  166906. }
  166907. if (png_ptr->idat_size && png_ptr->save_buffer_size)
  166908. {
  166909. png_size_t save_size;
  166910. if (png_ptr->idat_size < (png_uint_32)png_ptr->save_buffer_size)
  166911. {
  166912. save_size = (png_size_t)png_ptr->idat_size;
  166913. if((png_uint_32)save_size != png_ptr->idat_size)
  166914. png_error(png_ptr, "save_size overflowed in pngpread");
  166915. }
  166916. else
  166917. save_size = png_ptr->save_buffer_size;
  166918. png_calculate_crc(png_ptr, png_ptr->save_buffer_ptr, save_size);
  166919. if (!(png_ptr->flags & PNG_FLAG_ZLIB_FINISHED))
  166920. png_process_IDAT_data(png_ptr, png_ptr->save_buffer_ptr, save_size);
  166921. png_ptr->idat_size -= save_size;
  166922. png_ptr->buffer_size -= save_size;
  166923. png_ptr->save_buffer_size -= save_size;
  166924. png_ptr->save_buffer_ptr += save_size;
  166925. }
  166926. if (png_ptr->idat_size && png_ptr->current_buffer_size)
  166927. {
  166928. png_size_t save_size;
  166929. if (png_ptr->idat_size < (png_uint_32)png_ptr->current_buffer_size)
  166930. {
  166931. save_size = (png_size_t)png_ptr->idat_size;
  166932. if((png_uint_32)save_size != png_ptr->idat_size)
  166933. png_error(png_ptr, "save_size overflowed in pngpread");
  166934. }
  166935. else
  166936. save_size = png_ptr->current_buffer_size;
  166937. png_calculate_crc(png_ptr, png_ptr->current_buffer_ptr, save_size);
  166938. if (!(png_ptr->flags & PNG_FLAG_ZLIB_FINISHED))
  166939. png_process_IDAT_data(png_ptr, png_ptr->current_buffer_ptr, save_size);
  166940. png_ptr->idat_size -= save_size;
  166941. png_ptr->buffer_size -= save_size;
  166942. png_ptr->current_buffer_size -= save_size;
  166943. png_ptr->current_buffer_ptr += save_size;
  166944. }
  166945. if (!png_ptr->idat_size)
  166946. {
  166947. if (png_ptr->buffer_size < 4)
  166948. {
  166949. png_push_save_buffer(png_ptr);
  166950. return;
  166951. }
  166952. png_crc_finish(png_ptr, 0);
  166953. png_ptr->mode &= ~PNG_HAVE_CHUNK_HEADER;
  166954. png_ptr->mode |= PNG_AFTER_IDAT;
  166955. }
  166956. }
  166957. void /* PRIVATE */
  166958. png_process_IDAT_data(png_structp png_ptr, png_bytep buffer,
  166959. png_size_t buffer_length)
  166960. {
  166961. int ret;
  166962. if ((png_ptr->flags & PNG_FLAG_ZLIB_FINISHED) && buffer_length)
  166963. png_error(png_ptr, "Extra compression data");
  166964. png_ptr->zstream.next_in = buffer;
  166965. png_ptr->zstream.avail_in = (uInt)buffer_length;
  166966. for(;;)
  166967. {
  166968. ret = inflate(&png_ptr->zstream, Z_PARTIAL_FLUSH);
  166969. if (ret != Z_OK)
  166970. {
  166971. if (ret == Z_STREAM_END)
  166972. {
  166973. if (png_ptr->zstream.avail_in)
  166974. png_error(png_ptr, "Extra compressed data");
  166975. if (!(png_ptr->zstream.avail_out))
  166976. {
  166977. png_push_process_row(png_ptr);
  166978. }
  166979. png_ptr->mode |= PNG_AFTER_IDAT;
  166980. png_ptr->flags |= PNG_FLAG_ZLIB_FINISHED;
  166981. break;
  166982. }
  166983. else if (ret == Z_BUF_ERROR)
  166984. break;
  166985. else
  166986. png_error(png_ptr, "Decompression Error");
  166987. }
  166988. if (!(png_ptr->zstream.avail_out))
  166989. {
  166990. if ((
  166991. #if defined(PNG_READ_INTERLACING_SUPPORTED)
  166992. png_ptr->interlaced && png_ptr->pass > 6) ||
  166993. (!png_ptr->interlaced &&
  166994. #endif
  166995. png_ptr->row_number == png_ptr->num_rows))
  166996. {
  166997. if (png_ptr->zstream.avail_in)
  166998. {
  166999. png_warning(png_ptr, "Too much data in IDAT chunks");
  167000. }
  167001. png_ptr->flags |= PNG_FLAG_ZLIB_FINISHED;
  167002. break;
  167003. }
  167004. png_push_process_row(png_ptr);
  167005. png_ptr->zstream.avail_out = (uInt)png_ptr->irowbytes;
  167006. png_ptr->zstream.next_out = png_ptr->row_buf;
  167007. }
  167008. else
  167009. break;
  167010. }
  167011. }
  167012. void /* PRIVATE */
  167013. png_push_process_row(png_structp png_ptr)
  167014. {
  167015. png_ptr->row_info.color_type = png_ptr->color_type;
  167016. png_ptr->row_info.width = png_ptr->iwidth;
  167017. png_ptr->row_info.channels = png_ptr->channels;
  167018. png_ptr->row_info.bit_depth = png_ptr->bit_depth;
  167019. png_ptr->row_info.pixel_depth = png_ptr->pixel_depth;
  167020. png_ptr->row_info.rowbytes = PNG_ROWBYTES(png_ptr->row_info.pixel_depth,
  167021. png_ptr->row_info.width);
  167022. png_read_filter_row(png_ptr, &(png_ptr->row_info),
  167023. png_ptr->row_buf + 1, png_ptr->prev_row + 1,
  167024. (int)(png_ptr->row_buf[0]));
  167025. png_memcpy_check(png_ptr, png_ptr->prev_row, png_ptr->row_buf,
  167026. png_ptr->rowbytes + 1);
  167027. if (png_ptr->transformations || (png_ptr->flags&PNG_FLAG_STRIP_ALPHA))
  167028. png_do_read_transformations(png_ptr);
  167029. #if defined(PNG_READ_INTERLACING_SUPPORTED)
  167030. if (png_ptr->interlaced && (png_ptr->transformations & PNG_INTERLACE))
  167031. {
  167032. if (png_ptr->pass < 6)
  167033. png_do_read_interlace(png_ptr);
  167034. switch (png_ptr->pass)
  167035. {
  167036. case 0:
  167037. {
  167038. int i;
  167039. for (i = 0; i < 8 && png_ptr->pass == 0; i++)
  167040. {
  167041. png_push_have_row(png_ptr, png_ptr->row_buf + 1);
  167042. png_read_push_finish_row(png_ptr); /* updates png_ptr->pass */
  167043. }
  167044. if (png_ptr->pass == 2) /* pass 1 might be empty */
  167045. {
  167046. for (i = 0; i < 4 && png_ptr->pass == 2; i++)
  167047. {
  167048. png_push_have_row(png_ptr, png_bytep_NULL);
  167049. png_read_push_finish_row(png_ptr);
  167050. }
  167051. }
  167052. if (png_ptr->pass == 4 && png_ptr->height <= 4)
  167053. {
  167054. for (i = 0; i < 2 && png_ptr->pass == 4; i++)
  167055. {
  167056. png_push_have_row(png_ptr, png_bytep_NULL);
  167057. png_read_push_finish_row(png_ptr);
  167058. }
  167059. }
  167060. if (png_ptr->pass == 6 && png_ptr->height <= 4)
  167061. {
  167062. png_push_have_row(png_ptr, png_bytep_NULL);
  167063. png_read_push_finish_row(png_ptr);
  167064. }
  167065. break;
  167066. }
  167067. case 1:
  167068. {
  167069. int i;
  167070. for (i = 0; i < 8 && png_ptr->pass == 1; i++)
  167071. {
  167072. png_push_have_row(png_ptr, png_ptr->row_buf + 1);
  167073. png_read_push_finish_row(png_ptr);
  167074. }
  167075. if (png_ptr->pass == 2) /* skip top 4 generated rows */
  167076. {
  167077. for (i = 0; i < 4 && png_ptr->pass == 2; i++)
  167078. {
  167079. png_push_have_row(png_ptr, png_bytep_NULL);
  167080. png_read_push_finish_row(png_ptr);
  167081. }
  167082. }
  167083. break;
  167084. }
  167085. case 2:
  167086. {
  167087. int i;
  167088. for (i = 0; i < 4 && png_ptr->pass == 2; i++)
  167089. {
  167090. png_push_have_row(png_ptr, png_ptr->row_buf + 1);
  167091. png_read_push_finish_row(png_ptr);
  167092. }
  167093. for (i = 0; i < 4 && png_ptr->pass == 2; i++)
  167094. {
  167095. png_push_have_row(png_ptr, png_bytep_NULL);
  167096. png_read_push_finish_row(png_ptr);
  167097. }
  167098. if (png_ptr->pass == 4) /* pass 3 might be empty */
  167099. {
  167100. for (i = 0; i < 2 && png_ptr->pass == 4; i++)
  167101. {
  167102. png_push_have_row(png_ptr, png_bytep_NULL);
  167103. png_read_push_finish_row(png_ptr);
  167104. }
  167105. }
  167106. break;
  167107. }
  167108. case 3:
  167109. {
  167110. int i;
  167111. for (i = 0; i < 4 && png_ptr->pass == 3; i++)
  167112. {
  167113. png_push_have_row(png_ptr, png_ptr->row_buf + 1);
  167114. png_read_push_finish_row(png_ptr);
  167115. }
  167116. if (png_ptr->pass == 4) /* skip top two generated rows */
  167117. {
  167118. for (i = 0; i < 2 && png_ptr->pass == 4; i++)
  167119. {
  167120. png_push_have_row(png_ptr, png_bytep_NULL);
  167121. png_read_push_finish_row(png_ptr);
  167122. }
  167123. }
  167124. break;
  167125. }
  167126. case 4:
  167127. {
  167128. int i;
  167129. for (i = 0; i < 2 && png_ptr->pass == 4; i++)
  167130. {
  167131. png_push_have_row(png_ptr, png_ptr->row_buf + 1);
  167132. png_read_push_finish_row(png_ptr);
  167133. }
  167134. for (i = 0; i < 2 && png_ptr->pass == 4; i++)
  167135. {
  167136. png_push_have_row(png_ptr, png_bytep_NULL);
  167137. png_read_push_finish_row(png_ptr);
  167138. }
  167139. if (png_ptr->pass == 6) /* pass 5 might be empty */
  167140. {
  167141. png_push_have_row(png_ptr, png_bytep_NULL);
  167142. png_read_push_finish_row(png_ptr);
  167143. }
  167144. break;
  167145. }
  167146. case 5:
  167147. {
  167148. int i;
  167149. for (i = 0; i < 2 && png_ptr->pass == 5; i++)
  167150. {
  167151. png_push_have_row(png_ptr, png_ptr->row_buf + 1);
  167152. png_read_push_finish_row(png_ptr);
  167153. }
  167154. if (png_ptr->pass == 6) /* skip top generated row */
  167155. {
  167156. png_push_have_row(png_ptr, png_bytep_NULL);
  167157. png_read_push_finish_row(png_ptr);
  167158. }
  167159. break;
  167160. }
  167161. case 6:
  167162. {
  167163. png_push_have_row(png_ptr, png_ptr->row_buf + 1);
  167164. png_read_push_finish_row(png_ptr);
  167165. if (png_ptr->pass != 6)
  167166. break;
  167167. png_push_have_row(png_ptr, png_bytep_NULL);
  167168. png_read_push_finish_row(png_ptr);
  167169. }
  167170. }
  167171. }
  167172. else
  167173. #endif
  167174. {
  167175. png_push_have_row(png_ptr, png_ptr->row_buf + 1);
  167176. png_read_push_finish_row(png_ptr);
  167177. }
  167178. }
  167179. void /* PRIVATE */
  167180. png_read_push_finish_row(png_structp png_ptr)
  167181. {
  167182. #ifdef PNG_USE_LOCAL_ARRAYS
  167183. PNG_CONST int FARDATA png_pass_start[] = {0, 4, 0, 2, 0, 1, 0};
  167184. PNG_CONST int FARDATA png_pass_inc[] = {8, 8, 4, 4, 2, 2, 1};
  167185. PNG_CONST int FARDATA png_pass_ystart[] = {0, 0, 4, 0, 2, 0, 1};
  167186. PNG_CONST int FARDATA png_pass_yinc[] = {8, 8, 8, 4, 4, 2, 2};
  167187. #endif
  167188. png_ptr->row_number++;
  167189. if (png_ptr->row_number < png_ptr->num_rows)
  167190. return;
  167191. if (png_ptr->interlaced)
  167192. {
  167193. png_ptr->row_number = 0;
  167194. png_memset_check(png_ptr, png_ptr->prev_row, 0,
  167195. png_ptr->rowbytes + 1);
  167196. do
  167197. {
  167198. png_ptr->pass++;
  167199. if ((png_ptr->pass == 1 && png_ptr->width < 5) ||
  167200. (png_ptr->pass == 3 && png_ptr->width < 3) ||
  167201. (png_ptr->pass == 5 && png_ptr->width < 2))
  167202. png_ptr->pass++;
  167203. if (png_ptr->pass > 7)
  167204. png_ptr->pass--;
  167205. if (png_ptr->pass >= 7)
  167206. break;
  167207. png_ptr->iwidth = (png_ptr->width +
  167208. png_pass_inc[png_ptr->pass] - 1 -
  167209. png_pass_start[png_ptr->pass]) /
  167210. png_pass_inc[png_ptr->pass];
  167211. png_ptr->irowbytes = PNG_ROWBYTES(png_ptr->pixel_depth,
  167212. png_ptr->iwidth) + 1;
  167213. if (png_ptr->transformations & PNG_INTERLACE)
  167214. break;
  167215. png_ptr->num_rows = (png_ptr->height +
  167216. png_pass_yinc[png_ptr->pass] - 1 -
  167217. png_pass_ystart[png_ptr->pass]) /
  167218. png_pass_yinc[png_ptr->pass];
  167219. } while (png_ptr->iwidth == 0 || png_ptr->num_rows == 0);
  167220. }
  167221. }
  167222. #if defined(PNG_READ_tEXt_SUPPORTED)
  167223. void /* PRIVATE */
  167224. png_push_handle_tEXt(png_structp png_ptr, png_infop info_ptr, png_uint_32
  167225. length)
  167226. {
  167227. if (!(png_ptr->mode & PNG_HAVE_IHDR) || (png_ptr->mode & PNG_HAVE_IEND))
  167228. {
  167229. png_error(png_ptr, "Out of place tEXt");
  167230. info_ptr = info_ptr; /* to quiet some compiler warnings */
  167231. }
  167232. #ifdef PNG_MAX_MALLOC_64K
  167233. png_ptr->skip_length = 0; /* This may not be necessary */
  167234. if (length > (png_uint_32)65535L) /* Can't hold entire string in memory */
  167235. {
  167236. png_warning(png_ptr, "tEXt chunk too large to fit in memory");
  167237. png_ptr->skip_length = length - (png_uint_32)65535L;
  167238. length = (png_uint_32)65535L;
  167239. }
  167240. #endif
  167241. png_ptr->current_text = (png_charp)png_malloc(png_ptr,
  167242. (png_uint_32)(length+1));
  167243. png_ptr->current_text[length] = '\0';
  167244. png_ptr->current_text_ptr = png_ptr->current_text;
  167245. png_ptr->current_text_size = (png_size_t)length;
  167246. png_ptr->current_text_left = (png_size_t)length;
  167247. png_ptr->process_mode = PNG_READ_tEXt_MODE;
  167248. }
  167249. void /* PRIVATE */
  167250. png_push_read_tEXt(png_structp png_ptr, png_infop info_ptr)
  167251. {
  167252. if (png_ptr->buffer_size && png_ptr->current_text_left)
  167253. {
  167254. png_size_t text_size;
  167255. if (png_ptr->buffer_size < png_ptr->current_text_left)
  167256. text_size = png_ptr->buffer_size;
  167257. else
  167258. text_size = png_ptr->current_text_left;
  167259. png_crc_read(png_ptr, (png_bytep)png_ptr->current_text_ptr, text_size);
  167260. png_ptr->current_text_left -= text_size;
  167261. png_ptr->current_text_ptr += text_size;
  167262. }
  167263. if (!(png_ptr->current_text_left))
  167264. {
  167265. png_textp text_ptr;
  167266. png_charp text;
  167267. png_charp key;
  167268. int ret;
  167269. if (png_ptr->buffer_size < 4)
  167270. {
  167271. png_push_save_buffer(png_ptr);
  167272. return;
  167273. }
  167274. png_push_crc_finish(png_ptr);
  167275. #if defined(PNG_MAX_MALLOC_64K)
  167276. if (png_ptr->skip_length)
  167277. return;
  167278. #endif
  167279. key = png_ptr->current_text;
  167280. for (text = key; *text; text++)
  167281. ;
  167282. if (text < key + png_ptr->current_text_size)
  167283. text++;
  167284. text_ptr = (png_textp)png_malloc(png_ptr,
  167285. (png_uint_32)png_sizeof(png_text));
  167286. text_ptr->compression = PNG_TEXT_COMPRESSION_NONE;
  167287. text_ptr->key = key;
  167288. #ifdef PNG_iTXt_SUPPORTED
  167289. text_ptr->lang = NULL;
  167290. text_ptr->lang_key = NULL;
  167291. #endif
  167292. text_ptr->text = text;
  167293. ret = png_set_text_2(png_ptr, info_ptr, text_ptr, 1);
  167294. png_free(png_ptr, key);
  167295. png_free(png_ptr, text_ptr);
  167296. png_ptr->current_text = NULL;
  167297. if (ret)
  167298. png_warning(png_ptr, "Insufficient memory to store text chunk.");
  167299. }
  167300. }
  167301. #endif
  167302. #if defined(PNG_READ_zTXt_SUPPORTED)
  167303. void /* PRIVATE */
  167304. png_push_handle_zTXt(png_structp png_ptr, png_infop info_ptr, png_uint_32
  167305. length)
  167306. {
  167307. if (!(png_ptr->mode & PNG_HAVE_IHDR) || (png_ptr->mode & PNG_HAVE_IEND))
  167308. {
  167309. png_error(png_ptr, "Out of place zTXt");
  167310. info_ptr = info_ptr; /* to quiet some compiler warnings */
  167311. }
  167312. #ifdef PNG_MAX_MALLOC_64K
  167313. if (length > (png_uint_32)65535L)
  167314. {
  167315. png_warning(png_ptr, "zTXt chunk too large to fit in memory");
  167316. png_push_crc_skip(png_ptr, length);
  167317. return;
  167318. }
  167319. #endif
  167320. png_ptr->current_text = (png_charp)png_malloc(png_ptr,
  167321. (png_uint_32)(length+1));
  167322. png_ptr->current_text[length] = '\0';
  167323. png_ptr->current_text_ptr = png_ptr->current_text;
  167324. png_ptr->current_text_size = (png_size_t)length;
  167325. png_ptr->current_text_left = (png_size_t)length;
  167326. png_ptr->process_mode = PNG_READ_zTXt_MODE;
  167327. }
  167328. void /* PRIVATE */
  167329. png_push_read_zTXt(png_structp png_ptr, png_infop info_ptr)
  167330. {
  167331. if (png_ptr->buffer_size && png_ptr->current_text_left)
  167332. {
  167333. png_size_t text_size;
  167334. if (png_ptr->buffer_size < (png_uint_32)png_ptr->current_text_left)
  167335. text_size = png_ptr->buffer_size;
  167336. else
  167337. text_size = png_ptr->current_text_left;
  167338. png_crc_read(png_ptr, (png_bytep)png_ptr->current_text_ptr, text_size);
  167339. png_ptr->current_text_left -= text_size;
  167340. png_ptr->current_text_ptr += text_size;
  167341. }
  167342. if (!(png_ptr->current_text_left))
  167343. {
  167344. png_textp text_ptr;
  167345. png_charp text;
  167346. png_charp key;
  167347. int ret;
  167348. png_size_t text_size, key_size;
  167349. if (png_ptr->buffer_size < 4)
  167350. {
  167351. png_push_save_buffer(png_ptr);
  167352. return;
  167353. }
  167354. png_push_crc_finish(png_ptr);
  167355. key = png_ptr->current_text;
  167356. for (text = key; *text; text++)
  167357. ;
  167358. if (text >= key + png_ptr->current_text_size)
  167359. {
  167360. png_ptr->current_text = NULL;
  167361. png_free(png_ptr, key);
  167362. return;
  167363. }
  167364. text++;
  167365. if (*text != PNG_TEXT_COMPRESSION_zTXt) /* check compression byte */
  167366. {
  167367. png_ptr->current_text = NULL;
  167368. png_free(png_ptr, key);
  167369. return;
  167370. }
  167371. text++;
  167372. png_ptr->zstream.next_in = (png_bytep )text;
  167373. png_ptr->zstream.avail_in = (uInt)(png_ptr->current_text_size -
  167374. (text - key));
  167375. png_ptr->zstream.next_out = png_ptr->zbuf;
  167376. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  167377. key_size = text - key;
  167378. text_size = 0;
  167379. text = NULL;
  167380. ret = Z_STREAM_END;
  167381. while (png_ptr->zstream.avail_in)
  167382. {
  167383. ret = inflate(&png_ptr->zstream, Z_PARTIAL_FLUSH);
  167384. if (ret != Z_OK && ret != Z_STREAM_END)
  167385. {
  167386. inflateReset(&png_ptr->zstream);
  167387. png_ptr->zstream.avail_in = 0;
  167388. png_ptr->current_text = NULL;
  167389. png_free(png_ptr, key);
  167390. png_free(png_ptr, text);
  167391. return;
  167392. }
  167393. if (!(png_ptr->zstream.avail_out) || ret == Z_STREAM_END)
  167394. {
  167395. if (text == NULL)
  167396. {
  167397. text = (png_charp)png_malloc(png_ptr,
  167398. (png_uint_32)(png_ptr->zbuf_size - png_ptr->zstream.avail_out
  167399. + key_size + 1));
  167400. png_memcpy(text + key_size, png_ptr->zbuf,
  167401. png_ptr->zbuf_size - png_ptr->zstream.avail_out);
  167402. png_memcpy(text, key, key_size);
  167403. text_size = key_size + png_ptr->zbuf_size -
  167404. png_ptr->zstream.avail_out;
  167405. *(text + text_size) = '\0';
  167406. }
  167407. else
  167408. {
  167409. png_charp tmp;
  167410. tmp = text;
  167411. text = (png_charp)png_malloc(png_ptr, text_size +
  167412. (png_uint_32)(png_ptr->zbuf_size - png_ptr->zstream.avail_out
  167413. + 1));
  167414. png_memcpy(text, tmp, text_size);
  167415. png_free(png_ptr, tmp);
  167416. png_memcpy(text + text_size, png_ptr->zbuf,
  167417. png_ptr->zbuf_size - png_ptr->zstream.avail_out);
  167418. text_size += png_ptr->zbuf_size - png_ptr->zstream.avail_out;
  167419. *(text + text_size) = '\0';
  167420. }
  167421. if (ret != Z_STREAM_END)
  167422. {
  167423. png_ptr->zstream.next_out = png_ptr->zbuf;
  167424. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  167425. }
  167426. }
  167427. else
  167428. {
  167429. break;
  167430. }
  167431. if (ret == Z_STREAM_END)
  167432. break;
  167433. }
  167434. inflateReset(&png_ptr->zstream);
  167435. png_ptr->zstream.avail_in = 0;
  167436. if (ret != Z_STREAM_END)
  167437. {
  167438. png_ptr->current_text = NULL;
  167439. png_free(png_ptr, key);
  167440. png_free(png_ptr, text);
  167441. return;
  167442. }
  167443. png_ptr->current_text = NULL;
  167444. png_free(png_ptr, key);
  167445. key = text;
  167446. text += key_size;
  167447. text_ptr = (png_textp)png_malloc(png_ptr,
  167448. (png_uint_32)png_sizeof(png_text));
  167449. text_ptr->compression = PNG_TEXT_COMPRESSION_zTXt;
  167450. text_ptr->key = key;
  167451. #ifdef PNG_iTXt_SUPPORTED
  167452. text_ptr->lang = NULL;
  167453. text_ptr->lang_key = NULL;
  167454. #endif
  167455. text_ptr->text = text;
  167456. ret = png_set_text_2(png_ptr, info_ptr, text_ptr, 1);
  167457. png_free(png_ptr, key);
  167458. png_free(png_ptr, text_ptr);
  167459. if (ret)
  167460. png_warning(png_ptr, "Insufficient memory to store text chunk.");
  167461. }
  167462. }
  167463. #endif
  167464. #if defined(PNG_READ_iTXt_SUPPORTED)
  167465. void /* PRIVATE */
  167466. png_push_handle_iTXt(png_structp png_ptr, png_infop info_ptr, png_uint_32
  167467. length)
  167468. {
  167469. if (!(png_ptr->mode & PNG_HAVE_IHDR) || (png_ptr->mode & PNG_HAVE_IEND))
  167470. {
  167471. png_error(png_ptr, "Out of place iTXt");
  167472. info_ptr = info_ptr; /* to quiet some compiler warnings */
  167473. }
  167474. #ifdef PNG_MAX_MALLOC_64K
  167475. png_ptr->skip_length = 0; /* This may not be necessary */
  167476. if (length > (png_uint_32)65535L) /* Can't hold entire string in memory */
  167477. {
  167478. png_warning(png_ptr, "iTXt chunk too large to fit in memory");
  167479. png_ptr->skip_length = length - (png_uint_32)65535L;
  167480. length = (png_uint_32)65535L;
  167481. }
  167482. #endif
  167483. png_ptr->current_text = (png_charp)png_malloc(png_ptr,
  167484. (png_uint_32)(length+1));
  167485. png_ptr->current_text[length] = '\0';
  167486. png_ptr->current_text_ptr = png_ptr->current_text;
  167487. png_ptr->current_text_size = (png_size_t)length;
  167488. png_ptr->current_text_left = (png_size_t)length;
  167489. png_ptr->process_mode = PNG_READ_iTXt_MODE;
  167490. }
  167491. void /* PRIVATE */
  167492. png_push_read_iTXt(png_structp png_ptr, png_infop info_ptr)
  167493. {
  167494. if (png_ptr->buffer_size && png_ptr->current_text_left)
  167495. {
  167496. png_size_t text_size;
  167497. if (png_ptr->buffer_size < png_ptr->current_text_left)
  167498. text_size = png_ptr->buffer_size;
  167499. else
  167500. text_size = png_ptr->current_text_left;
  167501. png_crc_read(png_ptr, (png_bytep)png_ptr->current_text_ptr, text_size);
  167502. png_ptr->current_text_left -= text_size;
  167503. png_ptr->current_text_ptr += text_size;
  167504. }
  167505. if (!(png_ptr->current_text_left))
  167506. {
  167507. png_textp text_ptr;
  167508. png_charp key;
  167509. int comp_flag;
  167510. png_charp lang;
  167511. png_charp lang_key;
  167512. png_charp text;
  167513. int ret;
  167514. if (png_ptr->buffer_size < 4)
  167515. {
  167516. png_push_save_buffer(png_ptr);
  167517. return;
  167518. }
  167519. png_push_crc_finish(png_ptr);
  167520. #if defined(PNG_MAX_MALLOC_64K)
  167521. if (png_ptr->skip_length)
  167522. return;
  167523. #endif
  167524. key = png_ptr->current_text;
  167525. for (lang = key; *lang; lang++)
  167526. ;
  167527. if (lang < key + png_ptr->current_text_size - 3)
  167528. lang++;
  167529. comp_flag = *lang++;
  167530. lang++; /* skip comp_type, always zero */
  167531. for (lang_key = lang; *lang_key; lang_key++)
  167532. ;
  167533. lang_key++; /* skip NUL separator */
  167534. text=lang_key;
  167535. if (lang_key < key + png_ptr->current_text_size - 1)
  167536. {
  167537. for (; *text; text++)
  167538. ;
  167539. }
  167540. if (text < key + png_ptr->current_text_size)
  167541. text++;
  167542. text_ptr = (png_textp)png_malloc(png_ptr,
  167543. (png_uint_32)png_sizeof(png_text));
  167544. text_ptr->compression = comp_flag + 2;
  167545. text_ptr->key = key;
  167546. text_ptr->lang = lang;
  167547. text_ptr->lang_key = lang_key;
  167548. text_ptr->text = text;
  167549. text_ptr->text_length = 0;
  167550. text_ptr->itxt_length = png_strlen(text);
  167551. ret = png_set_text_2(png_ptr, info_ptr, text_ptr, 1);
  167552. png_ptr->current_text = NULL;
  167553. png_free(png_ptr, text_ptr);
  167554. if (ret)
  167555. png_warning(png_ptr, "Insufficient memory to store iTXt chunk.");
  167556. }
  167557. }
  167558. #endif
  167559. void /* PRIVATE */
  167560. png_push_handle_unknown(png_structp png_ptr, png_infop info_ptr, png_uint_32
  167561. length)
  167562. {
  167563. png_uint_32 skip=0;
  167564. png_check_chunk_name(png_ptr, png_ptr->chunk_name);
  167565. if (!(png_ptr->chunk_name[0] & 0x20))
  167566. {
  167567. #if defined(PNG_READ_UNKNOWN_CHUNKS_SUPPORTED)
  167568. if(png_handle_as_unknown(png_ptr, png_ptr->chunk_name) !=
  167569. PNG_HANDLE_CHUNK_ALWAYS
  167570. #if defined(PNG_READ_USER_CHUNKS_SUPPORTED)
  167571. && png_ptr->read_user_chunk_fn == NULL
  167572. #endif
  167573. )
  167574. #endif
  167575. png_chunk_error(png_ptr, "unknown critical chunk");
  167576. info_ptr = info_ptr; /* to quiet some compiler warnings */
  167577. }
  167578. #if defined(PNG_READ_UNKNOWN_CHUNKS_SUPPORTED)
  167579. if (png_ptr->flags & PNG_FLAG_KEEP_UNKNOWN_CHUNKS)
  167580. {
  167581. #ifdef PNG_MAX_MALLOC_64K
  167582. if (length > (png_uint_32)65535L)
  167583. {
  167584. png_warning(png_ptr, "unknown chunk too large to fit in memory");
  167585. skip = length - (png_uint_32)65535L;
  167586. length = (png_uint_32)65535L;
  167587. }
  167588. #endif
  167589. png_strncpy((png_charp)png_ptr->unknown_chunk.name,
  167590. (png_charp)png_ptr->chunk_name, 5);
  167591. png_ptr->unknown_chunk.data = (png_bytep)png_malloc(png_ptr, length);
  167592. png_ptr->unknown_chunk.size = (png_size_t)length;
  167593. png_crc_read(png_ptr, (png_bytep)png_ptr->unknown_chunk.data, length);
  167594. #if defined(PNG_READ_USER_CHUNKS_SUPPORTED)
  167595. if(png_ptr->read_user_chunk_fn != NULL)
  167596. {
  167597. int ret;
  167598. ret = (*(png_ptr->read_user_chunk_fn))
  167599. (png_ptr, &png_ptr->unknown_chunk);
  167600. if (ret < 0)
  167601. png_chunk_error(png_ptr, "error in user chunk");
  167602. if (ret == 0)
  167603. {
  167604. if (!(png_ptr->chunk_name[0] & 0x20))
  167605. if(png_handle_as_unknown(png_ptr, png_ptr->chunk_name) !=
  167606. PNG_HANDLE_CHUNK_ALWAYS)
  167607. png_chunk_error(png_ptr, "unknown critical chunk");
  167608. png_set_unknown_chunks(png_ptr, info_ptr,
  167609. &png_ptr->unknown_chunk, 1);
  167610. }
  167611. }
  167612. #else
  167613. png_set_unknown_chunks(png_ptr, info_ptr, &png_ptr->unknown_chunk, 1);
  167614. #endif
  167615. png_free(png_ptr, png_ptr->unknown_chunk.data);
  167616. png_ptr->unknown_chunk.data = NULL;
  167617. }
  167618. else
  167619. #endif
  167620. skip=length;
  167621. png_push_crc_skip(png_ptr, skip);
  167622. }
  167623. void /* PRIVATE */
  167624. png_push_have_info(png_structp png_ptr, png_infop info_ptr)
  167625. {
  167626. if (png_ptr->info_fn != NULL)
  167627. (*(png_ptr->info_fn))(png_ptr, info_ptr);
  167628. }
  167629. void /* PRIVATE */
  167630. png_push_have_end(png_structp png_ptr, png_infop info_ptr)
  167631. {
  167632. if (png_ptr->end_fn != NULL)
  167633. (*(png_ptr->end_fn))(png_ptr, info_ptr);
  167634. }
  167635. void /* PRIVATE */
  167636. png_push_have_row(png_structp png_ptr, png_bytep row)
  167637. {
  167638. if (png_ptr->row_fn != NULL)
  167639. (*(png_ptr->row_fn))(png_ptr, row, png_ptr->row_number,
  167640. (int)png_ptr->pass);
  167641. }
  167642. void PNGAPI
  167643. png_progressive_combine_row (png_structp png_ptr,
  167644. png_bytep old_row, png_bytep new_row)
  167645. {
  167646. #ifdef PNG_USE_LOCAL_ARRAYS
  167647. PNG_CONST int FARDATA png_pass_dsp_mask[7] =
  167648. {0xff, 0x0f, 0xff, 0x33, 0xff, 0x55, 0xff};
  167649. #endif
  167650. if(png_ptr == NULL) return;
  167651. if (new_row != NULL) /* new_row must == png_ptr->row_buf here. */
  167652. png_combine_row(png_ptr, old_row, png_pass_dsp_mask[png_ptr->pass]);
  167653. }
  167654. void PNGAPI
  167655. png_set_progressive_read_fn(png_structp png_ptr, png_voidp progressive_ptr,
  167656. png_progressive_info_ptr info_fn, png_progressive_row_ptr row_fn,
  167657. png_progressive_end_ptr end_fn)
  167658. {
  167659. if(png_ptr == NULL) return;
  167660. png_ptr->info_fn = info_fn;
  167661. png_ptr->row_fn = row_fn;
  167662. png_ptr->end_fn = end_fn;
  167663. png_set_read_fn(png_ptr, progressive_ptr, png_push_fill_buffer);
  167664. }
  167665. png_voidp PNGAPI
  167666. png_get_progressive_ptr(png_structp png_ptr)
  167667. {
  167668. if(png_ptr == NULL) return (NULL);
  167669. return png_ptr->io_ptr;
  167670. }
  167671. #endif /* PNG_PROGRESSIVE_READ_SUPPORTED */
  167672. /********* End of inlined file: pngpread.c *********/
  167673. /********* Start of inlined file: pngrio.c *********/
  167674. #define PNG_INTERNAL
  167675. #if defined(PNG_READ_SUPPORTED)
  167676. void /* PRIVATE */
  167677. png_read_data(png_structp png_ptr, png_bytep data, png_size_t length)
  167678. {
  167679. png_debug1(4,"reading %d bytes\n", (int)length);
  167680. if (png_ptr->read_data_fn != NULL)
  167681. (*(png_ptr->read_data_fn))(png_ptr, data, length);
  167682. else
  167683. png_error(png_ptr, "Call to NULL read function");
  167684. }
  167685. #if !defined(PNG_NO_STDIO)
  167686. #ifndef USE_FAR_KEYWORD
  167687. void PNGAPI
  167688. png_default_read_data(png_structp png_ptr, png_bytep data, png_size_t length)
  167689. {
  167690. png_size_t check;
  167691. if(png_ptr == NULL) return;
  167692. #if defined(_WIN32_WCE)
  167693. if ( !ReadFile((HANDLE)(png_ptr->io_ptr), data, length, &check, NULL) )
  167694. check = 0;
  167695. #else
  167696. check = (png_size_t)fread(data, (png_size_t)1, length,
  167697. (png_FILE_p)png_ptr->io_ptr);
  167698. #endif
  167699. if (check != length)
  167700. png_error(png_ptr, "Read Error");
  167701. }
  167702. #else
  167703. #define NEAR_BUF_SIZE 1024
  167704. #define MIN(a,b) (a <= b ? a : b)
  167705. static void PNGAPI
  167706. png_default_read_data(png_structp png_ptr, png_bytep data, png_size_t length)
  167707. {
  167708. int check;
  167709. png_byte *n_data;
  167710. png_FILE_p io_ptr;
  167711. if(png_ptr == NULL) return;
  167712. n_data = (png_byte *)CVT_PTR_NOCHECK(data);
  167713. io_ptr = (png_FILE_p)CVT_PTR(png_ptr->io_ptr);
  167714. if ((png_bytep)n_data == data)
  167715. {
  167716. #if defined(_WIN32_WCE)
  167717. if ( !ReadFile((HANDLE)(png_ptr->io_ptr), data, length, &check, NULL) )
  167718. check = 0;
  167719. #else
  167720. check = fread(n_data, 1, length, io_ptr);
  167721. #endif
  167722. }
  167723. else
  167724. {
  167725. png_byte buf[NEAR_BUF_SIZE];
  167726. png_size_t read, remaining, err;
  167727. check = 0;
  167728. remaining = length;
  167729. do
  167730. {
  167731. read = MIN(NEAR_BUF_SIZE, remaining);
  167732. #if defined(_WIN32_WCE)
  167733. if ( !ReadFile((HANDLE)(io_ptr), buf, read, &err, NULL) )
  167734. err = 0;
  167735. #else
  167736. err = fread(buf, (png_size_t)1, read, io_ptr);
  167737. #endif
  167738. png_memcpy(data, buf, read); /* copy far buffer to near buffer */
  167739. if(err != read)
  167740. break;
  167741. else
  167742. check += err;
  167743. data += read;
  167744. remaining -= read;
  167745. }
  167746. while (remaining != 0);
  167747. }
  167748. if ((png_uint_32)check != (png_uint_32)length)
  167749. png_error(png_ptr, "read Error");
  167750. }
  167751. #endif
  167752. #endif
  167753. void PNGAPI
  167754. png_set_read_fn(png_structp png_ptr, png_voidp io_ptr,
  167755. png_rw_ptr read_data_fn)
  167756. {
  167757. if(png_ptr == NULL) return;
  167758. png_ptr->io_ptr = io_ptr;
  167759. #if !defined(PNG_NO_STDIO)
  167760. if (read_data_fn != NULL)
  167761. png_ptr->read_data_fn = read_data_fn;
  167762. else
  167763. png_ptr->read_data_fn = png_default_read_data;
  167764. #else
  167765. png_ptr->read_data_fn = read_data_fn;
  167766. #endif
  167767. if (png_ptr->write_data_fn != NULL)
  167768. {
  167769. png_ptr->write_data_fn = NULL;
  167770. png_warning(png_ptr,
  167771. "It's an error to set both read_data_fn and write_data_fn in the ");
  167772. png_warning(png_ptr,
  167773. "same structure. Resetting write_data_fn to NULL.");
  167774. }
  167775. #if defined(PNG_WRITE_FLUSH_SUPPORTED)
  167776. png_ptr->output_flush_fn = NULL;
  167777. #endif
  167778. }
  167779. #endif /* PNG_READ_SUPPORTED */
  167780. /********* End of inlined file: pngrio.c *********/
  167781. /********* Start of inlined file: pngrtran.c *********/
  167782. #define PNG_INTERNAL
  167783. #if defined(PNG_READ_SUPPORTED)
  167784. void PNGAPI
  167785. png_set_crc_action(png_structp png_ptr, int crit_action, int ancil_action)
  167786. {
  167787. png_debug(1, "in png_set_crc_action\n");
  167788. if(png_ptr == NULL) return;
  167789. switch (crit_action)
  167790. {
  167791. case PNG_CRC_NO_CHANGE: /* leave setting as is */
  167792. break;
  167793. case PNG_CRC_WARN_USE: /* warn/use data */
  167794. png_ptr->flags &= ~PNG_FLAG_CRC_CRITICAL_MASK;
  167795. png_ptr->flags |= PNG_FLAG_CRC_CRITICAL_USE;
  167796. break;
  167797. case PNG_CRC_QUIET_USE: /* quiet/use data */
  167798. png_ptr->flags &= ~PNG_FLAG_CRC_CRITICAL_MASK;
  167799. png_ptr->flags |= PNG_FLAG_CRC_CRITICAL_USE |
  167800. PNG_FLAG_CRC_CRITICAL_IGNORE;
  167801. break;
  167802. case PNG_CRC_WARN_DISCARD: /* not a valid action for critical data */
  167803. png_warning(png_ptr, "Can't discard critical data on CRC error.");
  167804. case PNG_CRC_ERROR_QUIT: /* error/quit */
  167805. case PNG_CRC_DEFAULT:
  167806. default:
  167807. png_ptr->flags &= ~PNG_FLAG_CRC_CRITICAL_MASK;
  167808. break;
  167809. }
  167810. switch (ancil_action)
  167811. {
  167812. case PNG_CRC_NO_CHANGE: /* leave setting as is */
  167813. break;
  167814. case PNG_CRC_WARN_USE: /* warn/use data */
  167815. png_ptr->flags &= ~PNG_FLAG_CRC_ANCILLARY_MASK;
  167816. png_ptr->flags |= PNG_FLAG_CRC_ANCILLARY_USE;
  167817. break;
  167818. case PNG_CRC_QUIET_USE: /* quiet/use data */
  167819. png_ptr->flags &= ~PNG_FLAG_CRC_ANCILLARY_MASK;
  167820. png_ptr->flags |= PNG_FLAG_CRC_ANCILLARY_USE |
  167821. PNG_FLAG_CRC_ANCILLARY_NOWARN;
  167822. break;
  167823. case PNG_CRC_ERROR_QUIT: /* error/quit */
  167824. png_ptr->flags &= ~PNG_FLAG_CRC_ANCILLARY_MASK;
  167825. png_ptr->flags |= PNG_FLAG_CRC_ANCILLARY_NOWARN;
  167826. break;
  167827. case PNG_CRC_WARN_DISCARD: /* warn/discard data */
  167828. case PNG_CRC_DEFAULT:
  167829. default:
  167830. png_ptr->flags &= ~PNG_FLAG_CRC_ANCILLARY_MASK;
  167831. break;
  167832. }
  167833. }
  167834. #if defined(PNG_READ_BACKGROUND_SUPPORTED) && \
  167835. defined(PNG_FLOATING_POINT_SUPPORTED)
  167836. void PNGAPI
  167837. png_set_background(png_structp png_ptr,
  167838. png_color_16p background_color, int background_gamma_code,
  167839. int need_expand, double background_gamma)
  167840. {
  167841. png_debug(1, "in png_set_background\n");
  167842. if(png_ptr == NULL) return;
  167843. if (background_gamma_code == PNG_BACKGROUND_GAMMA_UNKNOWN)
  167844. {
  167845. png_warning(png_ptr, "Application must supply a known background gamma");
  167846. return;
  167847. }
  167848. png_ptr->transformations |= PNG_BACKGROUND;
  167849. png_memcpy(&(png_ptr->background), background_color,
  167850. png_sizeof(png_color_16));
  167851. png_ptr->background_gamma = (float)background_gamma;
  167852. png_ptr->background_gamma_type = (png_byte)(background_gamma_code);
  167853. png_ptr->transformations |= (need_expand ? PNG_BACKGROUND_EXPAND : 0);
  167854. }
  167855. #endif
  167856. #if defined(PNG_READ_16_TO_8_SUPPORTED)
  167857. void PNGAPI
  167858. png_set_strip_16(png_structp png_ptr)
  167859. {
  167860. png_debug(1, "in png_set_strip_16\n");
  167861. if(png_ptr == NULL) return;
  167862. png_ptr->transformations |= PNG_16_TO_8;
  167863. }
  167864. #endif
  167865. #if defined(PNG_READ_STRIP_ALPHA_SUPPORTED)
  167866. void PNGAPI
  167867. png_set_strip_alpha(png_structp png_ptr)
  167868. {
  167869. png_debug(1, "in png_set_strip_alpha\n");
  167870. if(png_ptr == NULL) return;
  167871. png_ptr->flags |= PNG_FLAG_STRIP_ALPHA;
  167872. }
  167873. #endif
  167874. #if defined(PNG_READ_DITHER_SUPPORTED)
  167875. typedef struct png_dsort_struct
  167876. {
  167877. struct png_dsort_struct FAR * next;
  167878. png_byte left;
  167879. png_byte right;
  167880. } png_dsort;
  167881. typedef png_dsort FAR * png_dsortp;
  167882. typedef png_dsort FAR * FAR * png_dsortpp;
  167883. void PNGAPI
  167884. png_set_dither(png_structp png_ptr, png_colorp palette,
  167885. int num_palette, int maximum_colors, png_uint_16p histogram,
  167886. int full_dither)
  167887. {
  167888. png_debug(1, "in png_set_dither\n");
  167889. if(png_ptr == NULL) return;
  167890. png_ptr->transformations |= PNG_DITHER;
  167891. if (!full_dither)
  167892. {
  167893. int i;
  167894. png_ptr->dither_index = (png_bytep)png_malloc(png_ptr,
  167895. (png_uint_32)(num_palette * png_sizeof (png_byte)));
  167896. for (i = 0; i < num_palette; i++)
  167897. png_ptr->dither_index[i] = (png_byte)i;
  167898. }
  167899. if (num_palette > maximum_colors)
  167900. {
  167901. if (histogram != NULL)
  167902. {
  167903. int i;
  167904. png_ptr->dither_sort = (png_bytep)png_malloc(png_ptr,
  167905. (png_uint_32)(num_palette * png_sizeof (png_byte)));
  167906. for (i = 0; i < num_palette; i++)
  167907. png_ptr->dither_sort[i] = (png_byte)i;
  167908. for (i = num_palette - 1; i >= maximum_colors; i--)
  167909. {
  167910. int done; /* to stop early if the list is pre-sorted */
  167911. int j;
  167912. done = 1;
  167913. for (j = 0; j < i; j++)
  167914. {
  167915. if (histogram[png_ptr->dither_sort[j]]
  167916. < histogram[png_ptr->dither_sort[j + 1]])
  167917. {
  167918. png_byte t;
  167919. t = png_ptr->dither_sort[j];
  167920. png_ptr->dither_sort[j] = png_ptr->dither_sort[j + 1];
  167921. png_ptr->dither_sort[j + 1] = t;
  167922. done = 0;
  167923. }
  167924. }
  167925. if (done)
  167926. break;
  167927. }
  167928. if (full_dither)
  167929. {
  167930. int j = num_palette;
  167931. for (i = 0; i < maximum_colors; i++)
  167932. {
  167933. if ((int)png_ptr->dither_sort[i] >= maximum_colors)
  167934. {
  167935. do
  167936. j--;
  167937. while ((int)png_ptr->dither_sort[j] >= maximum_colors);
  167938. palette[i] = palette[j];
  167939. }
  167940. }
  167941. }
  167942. else
  167943. {
  167944. int j = num_palette;
  167945. for (i = 0; i < maximum_colors; i++)
  167946. {
  167947. if ((int)png_ptr->dither_sort[i] >= maximum_colors)
  167948. {
  167949. png_color tmp_color;
  167950. do
  167951. j--;
  167952. while ((int)png_ptr->dither_sort[j] >= maximum_colors);
  167953. tmp_color = palette[j];
  167954. palette[j] = palette[i];
  167955. palette[i] = tmp_color;
  167956. png_ptr->dither_index[j] = (png_byte)i;
  167957. png_ptr->dither_index[i] = (png_byte)j;
  167958. }
  167959. }
  167960. for (i = 0; i < num_palette; i++)
  167961. {
  167962. if ((int)png_ptr->dither_index[i] >= maximum_colors)
  167963. {
  167964. int min_d, k, min_k, d_index;
  167965. d_index = png_ptr->dither_index[i];
  167966. min_d = PNG_COLOR_DIST(palette[d_index], palette[0]);
  167967. for (k = 1, min_k = 0; k < maximum_colors; k++)
  167968. {
  167969. int d;
  167970. d = PNG_COLOR_DIST(palette[d_index], palette[k]);
  167971. if (d < min_d)
  167972. {
  167973. min_d = d;
  167974. min_k = k;
  167975. }
  167976. }
  167977. png_ptr->dither_index[i] = (png_byte)min_k;
  167978. }
  167979. }
  167980. }
  167981. png_free(png_ptr, png_ptr->dither_sort);
  167982. png_ptr->dither_sort=NULL;
  167983. }
  167984. else
  167985. {
  167986. int i;
  167987. int max_d;
  167988. int num_new_palette;
  167989. png_dsortp t;
  167990. png_dsortpp hash;
  167991. t=NULL;
  167992. png_ptr->index_to_palette = (png_bytep)png_malloc(png_ptr,
  167993. (png_uint_32)(num_palette * png_sizeof (png_byte)));
  167994. png_ptr->palette_to_index = (png_bytep)png_malloc(png_ptr,
  167995. (png_uint_32)(num_palette * png_sizeof (png_byte)));
  167996. for (i = 0; i < num_palette; i++)
  167997. {
  167998. png_ptr->index_to_palette[i] = (png_byte)i;
  167999. png_ptr->palette_to_index[i] = (png_byte)i;
  168000. }
  168001. hash = (png_dsortpp)png_malloc(png_ptr, (png_uint_32)(769 *
  168002. png_sizeof (png_dsortp)));
  168003. for (i = 0; i < 769; i++)
  168004. hash[i] = NULL;
  168005. num_new_palette = num_palette;
  168006. max_d = 96;
  168007. while (num_new_palette > maximum_colors)
  168008. {
  168009. for (i = 0; i < num_new_palette - 1; i++)
  168010. {
  168011. int j;
  168012. for (j = i + 1; j < num_new_palette; j++)
  168013. {
  168014. int d;
  168015. d = PNG_COLOR_DIST(palette[i], palette[j]);
  168016. if (d <= max_d)
  168017. {
  168018. t = (png_dsortp)png_malloc_warn(png_ptr,
  168019. (png_uint_32)(png_sizeof(png_dsort)));
  168020. if (t == NULL)
  168021. break;
  168022. t->next = hash[d];
  168023. t->left = (png_byte)i;
  168024. t->right = (png_byte)j;
  168025. hash[d] = t;
  168026. }
  168027. }
  168028. if (t == NULL)
  168029. break;
  168030. }
  168031. if (t != NULL)
  168032. for (i = 0; i <= max_d; i++)
  168033. {
  168034. if (hash[i] != NULL)
  168035. {
  168036. png_dsortp p;
  168037. for (p = hash[i]; p; p = p->next)
  168038. {
  168039. if ((int)png_ptr->index_to_palette[p->left]
  168040. < num_new_palette &&
  168041. (int)png_ptr->index_to_palette[p->right]
  168042. < num_new_palette)
  168043. {
  168044. int j, next_j;
  168045. if (num_new_palette & 0x01)
  168046. {
  168047. j = p->left;
  168048. next_j = p->right;
  168049. }
  168050. else
  168051. {
  168052. j = p->right;
  168053. next_j = p->left;
  168054. }
  168055. num_new_palette--;
  168056. palette[png_ptr->index_to_palette[j]]
  168057. = palette[num_new_palette];
  168058. if (!full_dither)
  168059. {
  168060. int k;
  168061. for (k = 0; k < num_palette; k++)
  168062. {
  168063. if (png_ptr->dither_index[k] ==
  168064. png_ptr->index_to_palette[j])
  168065. png_ptr->dither_index[k] =
  168066. png_ptr->index_to_palette[next_j];
  168067. if ((int)png_ptr->dither_index[k] ==
  168068. num_new_palette)
  168069. png_ptr->dither_index[k] =
  168070. png_ptr->index_to_palette[j];
  168071. }
  168072. }
  168073. png_ptr->index_to_palette[png_ptr->palette_to_index
  168074. [num_new_palette]] = png_ptr->index_to_palette[j];
  168075. png_ptr->palette_to_index[png_ptr->index_to_palette[j]]
  168076. = png_ptr->palette_to_index[num_new_palette];
  168077. png_ptr->index_to_palette[j] = (png_byte)num_new_palette;
  168078. png_ptr->palette_to_index[num_new_palette] = (png_byte)j;
  168079. }
  168080. if (num_new_palette <= maximum_colors)
  168081. break;
  168082. }
  168083. if (num_new_palette <= maximum_colors)
  168084. break;
  168085. }
  168086. }
  168087. for (i = 0; i < 769; i++)
  168088. {
  168089. if (hash[i] != NULL)
  168090. {
  168091. png_dsortp p = hash[i];
  168092. while (p)
  168093. {
  168094. t = p->next;
  168095. png_free(png_ptr, p);
  168096. p = t;
  168097. }
  168098. }
  168099. hash[i] = 0;
  168100. }
  168101. max_d += 96;
  168102. }
  168103. png_free(png_ptr, hash);
  168104. png_free(png_ptr, png_ptr->palette_to_index);
  168105. png_free(png_ptr, png_ptr->index_to_palette);
  168106. png_ptr->palette_to_index=NULL;
  168107. png_ptr->index_to_palette=NULL;
  168108. }
  168109. num_palette = maximum_colors;
  168110. }
  168111. if (png_ptr->palette == NULL)
  168112. {
  168113. png_ptr->palette = palette;
  168114. }
  168115. png_ptr->num_palette = (png_uint_16)num_palette;
  168116. if (full_dither)
  168117. {
  168118. int i;
  168119. png_bytep distance;
  168120. int total_bits = PNG_DITHER_RED_BITS + PNG_DITHER_GREEN_BITS +
  168121. PNG_DITHER_BLUE_BITS;
  168122. int num_red = (1 << PNG_DITHER_RED_BITS);
  168123. int num_green = (1 << PNG_DITHER_GREEN_BITS);
  168124. int num_blue = (1 << PNG_DITHER_BLUE_BITS);
  168125. png_size_t num_entries = ((png_size_t)1 << total_bits);
  168126. png_ptr->palette_lookup = (png_bytep )png_malloc(png_ptr,
  168127. (png_uint_32)(num_entries * png_sizeof (png_byte)));
  168128. png_memset(png_ptr->palette_lookup, 0, num_entries *
  168129. png_sizeof (png_byte));
  168130. distance = (png_bytep)png_malloc(png_ptr, (png_uint_32)(num_entries *
  168131. png_sizeof(png_byte)));
  168132. png_memset(distance, 0xff, num_entries * png_sizeof(png_byte));
  168133. for (i = 0; i < num_palette; i++)
  168134. {
  168135. int ir, ig, ib;
  168136. int r = (palette[i].red >> (8 - PNG_DITHER_RED_BITS));
  168137. int g = (palette[i].green >> (8 - PNG_DITHER_GREEN_BITS));
  168138. int b = (palette[i].blue >> (8 - PNG_DITHER_BLUE_BITS));
  168139. for (ir = 0; ir < num_red; ir++)
  168140. {
  168141. int dr = ((ir > r) ? ir - r : r - ir);
  168142. int index_r = (ir << (PNG_DITHER_BLUE_BITS + PNG_DITHER_GREEN_BITS));
  168143. for (ig = 0; ig < num_green; ig++)
  168144. {
  168145. int dg = ((ig > g) ? ig - g : g - ig);
  168146. int dt = dr + dg;
  168147. int dm = ((dr > dg) ? dr : dg);
  168148. int index_g = index_r | (ig << PNG_DITHER_BLUE_BITS);
  168149. for (ib = 0; ib < num_blue; ib++)
  168150. {
  168151. int d_index = index_g | ib;
  168152. int db = ((ib > b) ? ib - b : b - ib);
  168153. int dmax = ((dm > db) ? dm : db);
  168154. int d = dmax + dt + db;
  168155. if (d < (int)distance[d_index])
  168156. {
  168157. distance[d_index] = (png_byte)d;
  168158. png_ptr->palette_lookup[d_index] = (png_byte)i;
  168159. }
  168160. }
  168161. }
  168162. }
  168163. }
  168164. png_free(png_ptr, distance);
  168165. }
  168166. }
  168167. #endif
  168168. #if defined(PNG_READ_GAMMA_SUPPORTED) && defined(PNG_FLOATING_POINT_SUPPORTED)
  168169. void PNGAPI
  168170. png_set_gamma(png_structp png_ptr, double scrn_gamma, double file_gamma)
  168171. {
  168172. png_debug(1, "in png_set_gamma\n");
  168173. if(png_ptr == NULL) return;
  168174. if ((fabs(scrn_gamma * file_gamma - 1.0) > PNG_GAMMA_THRESHOLD) ||
  168175. (png_ptr->color_type & PNG_COLOR_MASK_ALPHA) ||
  168176. (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE))
  168177. png_ptr->transformations |= PNG_GAMMA;
  168178. png_ptr->gamma = (float)file_gamma;
  168179. png_ptr->screen_gamma = (float)scrn_gamma;
  168180. }
  168181. #endif
  168182. #if defined(PNG_READ_EXPAND_SUPPORTED)
  168183. void PNGAPI
  168184. png_set_expand(png_structp png_ptr)
  168185. {
  168186. png_debug(1, "in png_set_expand\n");
  168187. if(png_ptr == NULL) return;
  168188. png_ptr->transformations |= (PNG_EXPAND | PNG_EXPAND_tRNS);
  168189. #ifdef PNG_WARN_UNINITIALIZED_ROW
  168190. png_ptr->flags &= ~PNG_FLAG_ROW_INIT;
  168191. #endif
  168192. }
  168193. void PNGAPI
  168194. png_set_palette_to_rgb(png_structp png_ptr)
  168195. {
  168196. png_debug(1, "in png_set_palette_to_rgb\n");
  168197. if(png_ptr == NULL) return;
  168198. png_ptr->transformations |= (PNG_EXPAND | PNG_EXPAND_tRNS);
  168199. #ifdef PNG_WARN_UNINITIALIZED_ROW
  168200. png_ptr->flags &= !(PNG_FLAG_ROW_INIT);
  168201. png_ptr->flags &= ~PNG_FLAG_ROW_INIT;
  168202. #endif
  168203. }
  168204. #if !defined(PNG_1_0_X)
  168205. void PNGAPI
  168206. png_set_expand_gray_1_2_4_to_8(png_structp png_ptr)
  168207. {
  168208. png_debug(1, "in png_set_expand_gray_1_2_4_to_8\n");
  168209. if(png_ptr == NULL) return;
  168210. png_ptr->transformations |= PNG_EXPAND;
  168211. #ifdef PNG_WARN_UNINITIALIZED_ROW
  168212. png_ptr->flags &= ~PNG_FLAG_ROW_INIT;
  168213. #endif
  168214. }
  168215. #endif
  168216. #if defined(PNG_1_0_X) || defined(PNG_1_2_X)
  168217. void PNGAPI
  168218. png_set_gray_1_2_4_to_8(png_structp png_ptr)
  168219. {
  168220. png_debug(1, "in png_set_gray_1_2_4_to_8\n");
  168221. if(png_ptr == NULL) return;
  168222. png_ptr->transformations |= (PNG_EXPAND | PNG_EXPAND_tRNS);
  168223. }
  168224. #endif
  168225. void PNGAPI
  168226. png_set_tRNS_to_alpha(png_structp png_ptr)
  168227. {
  168228. png_debug(1, "in png_set_tRNS_to_alpha\n");
  168229. png_ptr->transformations |= (PNG_EXPAND | PNG_EXPAND_tRNS);
  168230. #ifdef PNG_WARN_UNINITIALIZED_ROW
  168231. png_ptr->flags &= ~PNG_FLAG_ROW_INIT;
  168232. #endif
  168233. }
  168234. #endif /* defined(PNG_READ_EXPAND_SUPPORTED) */
  168235. #if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED)
  168236. void PNGAPI
  168237. png_set_gray_to_rgb(png_structp png_ptr)
  168238. {
  168239. png_debug(1, "in png_set_gray_to_rgb\n");
  168240. png_ptr->transformations |= PNG_GRAY_TO_RGB;
  168241. #ifdef PNG_WARN_UNINITIALIZED_ROW
  168242. png_ptr->flags &= ~PNG_FLAG_ROW_INIT;
  168243. #endif
  168244. }
  168245. #endif
  168246. #if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
  168247. #if defined(PNG_FLOATING_POINT_SUPPORTED)
  168248. void PNGAPI
  168249. png_set_rgb_to_gray(png_structp png_ptr, int error_action, double red,
  168250. double green)
  168251. {
  168252. int red_fixed = (int)((float)red*100000.0 + 0.5);
  168253. int green_fixed = (int)((float)green*100000.0 + 0.5);
  168254. if(png_ptr == NULL) return;
  168255. png_set_rgb_to_gray_fixed(png_ptr, error_action, red_fixed, green_fixed);
  168256. }
  168257. #endif
  168258. void PNGAPI
  168259. png_set_rgb_to_gray_fixed(png_structp png_ptr, int error_action,
  168260. png_fixed_point red, png_fixed_point green)
  168261. {
  168262. png_debug(1, "in png_set_rgb_to_gray\n");
  168263. if(png_ptr == NULL) return;
  168264. switch(error_action)
  168265. {
  168266. case 1: png_ptr->transformations |= PNG_RGB_TO_GRAY;
  168267. break;
  168268. case 2: png_ptr->transformations |= PNG_RGB_TO_GRAY_WARN;
  168269. break;
  168270. case 3: png_ptr->transformations |= PNG_RGB_TO_GRAY_ERR;
  168271. }
  168272. if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  168273. #if defined(PNG_READ_EXPAND_SUPPORTED)
  168274. png_ptr->transformations |= PNG_EXPAND;
  168275. #else
  168276. {
  168277. png_warning(png_ptr, "Cannot do RGB_TO_GRAY without EXPAND_SUPPORTED.");
  168278. png_ptr->transformations &= ~PNG_RGB_TO_GRAY;
  168279. }
  168280. #endif
  168281. {
  168282. png_uint_16 red_int, green_int;
  168283. if(red < 0 || green < 0)
  168284. {
  168285. red_int = 6968; /* .212671 * 32768 + .5 */
  168286. green_int = 23434; /* .715160 * 32768 + .5 */
  168287. }
  168288. else if(red + green < 100000L)
  168289. {
  168290. red_int = (png_uint_16)(((png_uint_32)red*32768L)/100000L);
  168291. green_int = (png_uint_16)(((png_uint_32)green*32768L)/100000L);
  168292. }
  168293. else
  168294. {
  168295. png_warning(png_ptr, "ignoring out of range rgb_to_gray coefficients");
  168296. red_int = 6968;
  168297. green_int = 23434;
  168298. }
  168299. png_ptr->rgb_to_gray_red_coeff = red_int;
  168300. png_ptr->rgb_to_gray_green_coeff = green_int;
  168301. png_ptr->rgb_to_gray_blue_coeff = (png_uint_16)(32768-red_int-green_int);
  168302. }
  168303. }
  168304. #endif
  168305. #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \
  168306. defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED) || \
  168307. defined(PNG_LEGACY_SUPPORTED)
  168308. void PNGAPI
  168309. png_set_read_user_transform_fn(png_structp png_ptr, png_user_transform_ptr
  168310. read_user_transform_fn)
  168311. {
  168312. png_debug(1, "in png_set_read_user_transform_fn\n");
  168313. if(png_ptr == NULL) return;
  168314. #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED)
  168315. png_ptr->transformations |= PNG_USER_TRANSFORM;
  168316. png_ptr->read_user_transform_fn = read_user_transform_fn;
  168317. #endif
  168318. #ifdef PNG_LEGACY_SUPPORTED
  168319. if(read_user_transform_fn)
  168320. png_warning(png_ptr,
  168321. "This version of libpng does not support user transforms");
  168322. #endif
  168323. }
  168324. #endif
  168325. void /* PRIVATE */
  168326. png_init_read_transformations(png_structp png_ptr)
  168327. {
  168328. png_debug(1, "in png_init_read_transformations\n");
  168329. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  168330. if(png_ptr != NULL)
  168331. #endif
  168332. {
  168333. #if defined(PNG_READ_BACKGROUND_SUPPORTED) || defined(PNG_READ_SHIFT_SUPPORTED) \
  168334. || defined(PNG_READ_GAMMA_SUPPORTED)
  168335. int color_type = png_ptr->color_type;
  168336. #endif
  168337. #if defined(PNG_READ_EXPAND_SUPPORTED) && defined(PNG_READ_BACKGROUND_SUPPORTED)
  168338. #if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED)
  168339. if ((png_ptr->transformations & PNG_BACKGROUND_EXPAND) &&
  168340. !(color_type & PNG_COLOR_MASK_COLOR))
  168341. {
  168342. png_ptr->mode |= PNG_BACKGROUND_IS_GRAY;
  168343. } else if ((png_ptr->transformations & PNG_BACKGROUND) &&
  168344. !(png_ptr->transformations & PNG_BACKGROUND_EXPAND) &&
  168345. (png_ptr->transformations & PNG_GRAY_TO_RGB) &&
  168346. png_ptr->background.red == png_ptr->background.green &&
  168347. png_ptr->background.red == png_ptr->background.blue)
  168348. {
  168349. png_ptr->mode |= PNG_BACKGROUND_IS_GRAY;
  168350. png_ptr->background.gray = png_ptr->background.red;
  168351. }
  168352. #endif
  168353. if ((png_ptr->transformations & PNG_BACKGROUND_EXPAND) &&
  168354. (png_ptr->transformations & PNG_EXPAND))
  168355. {
  168356. if (!(color_type & PNG_COLOR_MASK_COLOR)) /* i.e., GRAY or GRAY_ALPHA */
  168357. {
  168358. switch (png_ptr->bit_depth)
  168359. {
  168360. case 1:
  168361. png_ptr->background.gray *= (png_uint_16)0xff;
  168362. png_ptr->background.red = png_ptr->background.green
  168363. = png_ptr->background.blue = png_ptr->background.gray;
  168364. if (!(png_ptr->transformations & PNG_EXPAND_tRNS))
  168365. {
  168366. png_ptr->trans_values.gray *= (png_uint_16)0xff;
  168367. png_ptr->trans_values.red = png_ptr->trans_values.green
  168368. = png_ptr->trans_values.blue = png_ptr->trans_values.gray;
  168369. }
  168370. break;
  168371. case 2:
  168372. png_ptr->background.gray *= (png_uint_16)0x55;
  168373. png_ptr->background.red = png_ptr->background.green
  168374. = png_ptr->background.blue = png_ptr->background.gray;
  168375. if (!(png_ptr->transformations & PNG_EXPAND_tRNS))
  168376. {
  168377. png_ptr->trans_values.gray *= (png_uint_16)0x55;
  168378. png_ptr->trans_values.red = png_ptr->trans_values.green
  168379. = png_ptr->trans_values.blue = png_ptr->trans_values.gray;
  168380. }
  168381. break;
  168382. case 4:
  168383. png_ptr->background.gray *= (png_uint_16)0x11;
  168384. png_ptr->background.red = png_ptr->background.green
  168385. = png_ptr->background.blue = png_ptr->background.gray;
  168386. if (!(png_ptr->transformations & PNG_EXPAND_tRNS))
  168387. {
  168388. png_ptr->trans_values.gray *= (png_uint_16)0x11;
  168389. png_ptr->trans_values.red = png_ptr->trans_values.green
  168390. = png_ptr->trans_values.blue = png_ptr->trans_values.gray;
  168391. }
  168392. break;
  168393. case 8:
  168394. case 16:
  168395. png_ptr->background.red = png_ptr->background.green
  168396. = png_ptr->background.blue = png_ptr->background.gray;
  168397. break;
  168398. }
  168399. }
  168400. else if (color_type == PNG_COLOR_TYPE_PALETTE)
  168401. {
  168402. png_ptr->background.red =
  168403. png_ptr->palette[png_ptr->background.index].red;
  168404. png_ptr->background.green =
  168405. png_ptr->palette[png_ptr->background.index].green;
  168406. png_ptr->background.blue =
  168407. png_ptr->palette[png_ptr->background.index].blue;
  168408. #if defined(PNG_READ_INVERT_ALPHA_SUPPORTED)
  168409. if (png_ptr->transformations & PNG_INVERT_ALPHA)
  168410. {
  168411. #if defined(PNG_READ_EXPAND_SUPPORTED)
  168412. if (!(png_ptr->transformations & PNG_EXPAND_tRNS))
  168413. #endif
  168414. {
  168415. int i,istop;
  168416. istop=(int)png_ptr->num_trans;
  168417. for (i=0; i<istop; i++)
  168418. png_ptr->trans[i] = (png_byte)(255 - png_ptr->trans[i]);
  168419. }
  168420. }
  168421. #endif
  168422. }
  168423. }
  168424. #endif
  168425. #if defined(PNG_READ_BACKGROUND_SUPPORTED) && defined(PNG_READ_GAMMA_SUPPORTED)
  168426. png_ptr->background_1 = png_ptr->background;
  168427. #endif
  168428. #if defined(PNG_READ_GAMMA_SUPPORTED) && defined(PNG_FLOATING_POINT_SUPPORTED)
  168429. if ((color_type == PNG_COLOR_TYPE_PALETTE && png_ptr->num_trans != 0)
  168430. && (fabs(png_ptr->screen_gamma * png_ptr->gamma - 1.0)
  168431. < PNG_GAMMA_THRESHOLD))
  168432. {
  168433. int i,k;
  168434. k=0;
  168435. for (i=0; i<png_ptr->num_trans; i++)
  168436. {
  168437. if (png_ptr->trans[i] != 0 && png_ptr->trans[i] != 0xff)
  168438. k=1; /* partial transparency is present */
  168439. }
  168440. if (k == 0)
  168441. png_ptr->transformations &= (~PNG_GAMMA);
  168442. }
  168443. if ((png_ptr->transformations & (PNG_GAMMA | PNG_RGB_TO_GRAY)) &&
  168444. png_ptr->gamma != 0.0)
  168445. {
  168446. png_build_gamma_table(png_ptr);
  168447. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  168448. if (png_ptr->transformations & PNG_BACKGROUND)
  168449. {
  168450. if (color_type == PNG_COLOR_TYPE_PALETTE)
  168451. {
  168452. png_color back, back_1;
  168453. png_colorp palette = png_ptr->palette;
  168454. int num_palette = png_ptr->num_palette;
  168455. int i;
  168456. if (png_ptr->background_gamma_type == PNG_BACKGROUND_GAMMA_FILE)
  168457. {
  168458. back.red = png_ptr->gamma_table[png_ptr->background.red];
  168459. back.green = png_ptr->gamma_table[png_ptr->background.green];
  168460. back.blue = png_ptr->gamma_table[png_ptr->background.blue];
  168461. back_1.red = png_ptr->gamma_to_1[png_ptr->background.red];
  168462. back_1.green = png_ptr->gamma_to_1[png_ptr->background.green];
  168463. back_1.blue = png_ptr->gamma_to_1[png_ptr->background.blue];
  168464. }
  168465. else
  168466. {
  168467. double g, gs;
  168468. switch (png_ptr->background_gamma_type)
  168469. {
  168470. case PNG_BACKGROUND_GAMMA_SCREEN:
  168471. g = (png_ptr->screen_gamma);
  168472. gs = 1.0;
  168473. break;
  168474. case PNG_BACKGROUND_GAMMA_FILE:
  168475. g = 1.0 / (png_ptr->gamma);
  168476. gs = 1.0 / (png_ptr->gamma * png_ptr->screen_gamma);
  168477. break;
  168478. case PNG_BACKGROUND_GAMMA_UNIQUE:
  168479. g = 1.0 / (png_ptr->background_gamma);
  168480. gs = 1.0 / (png_ptr->background_gamma *
  168481. png_ptr->screen_gamma);
  168482. break;
  168483. default:
  168484. g = 1.0; /* back_1 */
  168485. gs = 1.0; /* back */
  168486. }
  168487. if ( fabs(gs - 1.0) < PNG_GAMMA_THRESHOLD)
  168488. {
  168489. back.red = (png_byte)png_ptr->background.red;
  168490. back.green = (png_byte)png_ptr->background.green;
  168491. back.blue = (png_byte)png_ptr->background.blue;
  168492. }
  168493. else
  168494. {
  168495. back.red = (png_byte)(pow(
  168496. (double)png_ptr->background.red/255, gs) * 255.0 + .5);
  168497. back.green = (png_byte)(pow(
  168498. (double)png_ptr->background.green/255, gs) * 255.0 + .5);
  168499. back.blue = (png_byte)(pow(
  168500. (double)png_ptr->background.blue/255, gs) * 255.0 + .5);
  168501. }
  168502. back_1.red = (png_byte)(pow(
  168503. (double)png_ptr->background.red/255, g) * 255.0 + .5);
  168504. back_1.green = (png_byte)(pow(
  168505. (double)png_ptr->background.green/255, g) * 255.0 + .5);
  168506. back_1.blue = (png_byte)(pow(
  168507. (double)png_ptr->background.blue/255, g) * 255.0 + .5);
  168508. }
  168509. for (i = 0; i < num_palette; i++)
  168510. {
  168511. if (i < (int)png_ptr->num_trans && png_ptr->trans[i] != 0xff)
  168512. {
  168513. if (png_ptr->trans[i] == 0)
  168514. {
  168515. palette[i] = back;
  168516. }
  168517. else /* if (png_ptr->trans[i] != 0xff) */
  168518. {
  168519. png_byte v, w;
  168520. v = png_ptr->gamma_to_1[palette[i].red];
  168521. png_composite(w, v, png_ptr->trans[i], back_1.red);
  168522. palette[i].red = png_ptr->gamma_from_1[w];
  168523. v = png_ptr->gamma_to_1[palette[i].green];
  168524. png_composite(w, v, png_ptr->trans[i], back_1.green);
  168525. palette[i].green = png_ptr->gamma_from_1[w];
  168526. v = png_ptr->gamma_to_1[palette[i].blue];
  168527. png_composite(w, v, png_ptr->trans[i], back_1.blue);
  168528. palette[i].blue = png_ptr->gamma_from_1[w];
  168529. }
  168530. }
  168531. else
  168532. {
  168533. palette[i].red = png_ptr->gamma_table[palette[i].red];
  168534. palette[i].green = png_ptr->gamma_table[palette[i].green];
  168535. palette[i].blue = png_ptr->gamma_table[palette[i].blue];
  168536. }
  168537. }
  168538. }
  168539. else
  168540. {
  168541. double m = (double)(((png_uint_32)1 << png_ptr->bit_depth) - 1);
  168542. double g = 1.0;
  168543. double gs = 1.0;
  168544. switch (png_ptr->background_gamma_type)
  168545. {
  168546. case PNG_BACKGROUND_GAMMA_SCREEN:
  168547. g = (png_ptr->screen_gamma);
  168548. gs = 1.0;
  168549. break;
  168550. case PNG_BACKGROUND_GAMMA_FILE:
  168551. g = 1.0 / (png_ptr->gamma);
  168552. gs = 1.0 / (png_ptr->gamma * png_ptr->screen_gamma);
  168553. break;
  168554. case PNG_BACKGROUND_GAMMA_UNIQUE:
  168555. g = 1.0 / (png_ptr->background_gamma);
  168556. gs = 1.0 / (png_ptr->background_gamma *
  168557. png_ptr->screen_gamma);
  168558. break;
  168559. }
  168560. png_ptr->background_1.gray = (png_uint_16)(pow(
  168561. (double)png_ptr->background.gray / m, g) * m + .5);
  168562. png_ptr->background.gray = (png_uint_16)(pow(
  168563. (double)png_ptr->background.gray / m, gs) * m + .5);
  168564. if ((png_ptr->background.red != png_ptr->background.green) ||
  168565. (png_ptr->background.red != png_ptr->background.blue) ||
  168566. (png_ptr->background.red != png_ptr->background.gray))
  168567. {
  168568. png_ptr->background_1.red = (png_uint_16)(pow(
  168569. (double)png_ptr->background.red / m, g) * m + .5);
  168570. png_ptr->background_1.green = (png_uint_16)(pow(
  168571. (double)png_ptr->background.green / m, g) * m + .5);
  168572. png_ptr->background_1.blue = (png_uint_16)(pow(
  168573. (double)png_ptr->background.blue / m, g) * m + .5);
  168574. png_ptr->background.red = (png_uint_16)(pow(
  168575. (double)png_ptr->background.red / m, gs) * m + .5);
  168576. png_ptr->background.green = (png_uint_16)(pow(
  168577. (double)png_ptr->background.green / m, gs) * m + .5);
  168578. png_ptr->background.blue = (png_uint_16)(pow(
  168579. (double)png_ptr->background.blue / m, gs) * m + .5);
  168580. }
  168581. else
  168582. {
  168583. png_ptr->background_1.red = png_ptr->background_1.green
  168584. = png_ptr->background_1.blue = png_ptr->background_1.gray;
  168585. png_ptr->background.red = png_ptr->background.green
  168586. = png_ptr->background.blue = png_ptr->background.gray;
  168587. }
  168588. }
  168589. }
  168590. else
  168591. #endif /* PNG_READ_BACKGROUND_SUPPORTED */
  168592. if (color_type == PNG_COLOR_TYPE_PALETTE)
  168593. {
  168594. png_colorp palette = png_ptr->palette;
  168595. int num_palette = png_ptr->num_palette;
  168596. int i;
  168597. for (i = 0; i < num_palette; i++)
  168598. {
  168599. palette[i].red = png_ptr->gamma_table[palette[i].red];
  168600. palette[i].green = png_ptr->gamma_table[palette[i].green];
  168601. palette[i].blue = png_ptr->gamma_table[palette[i].blue];
  168602. }
  168603. }
  168604. }
  168605. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  168606. else
  168607. #endif
  168608. #endif /* PNG_READ_GAMMA_SUPPORTED && PNG_FLOATING_POINT_SUPPORTED */
  168609. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  168610. if ((png_ptr->transformations & PNG_BACKGROUND) &&
  168611. (color_type == PNG_COLOR_TYPE_PALETTE))
  168612. {
  168613. int i;
  168614. int istop = (int)png_ptr->num_trans;
  168615. png_color back;
  168616. png_colorp palette = png_ptr->palette;
  168617. back.red = (png_byte)png_ptr->background.red;
  168618. back.green = (png_byte)png_ptr->background.green;
  168619. back.blue = (png_byte)png_ptr->background.blue;
  168620. for (i = 0; i < istop; i++)
  168621. {
  168622. if (png_ptr->trans[i] == 0)
  168623. {
  168624. palette[i] = back;
  168625. }
  168626. else if (png_ptr->trans[i] != 0xff)
  168627. {
  168628. png_composite(palette[i].red, palette[i].red,
  168629. png_ptr->trans[i], back.red);
  168630. png_composite(palette[i].green, palette[i].green,
  168631. png_ptr->trans[i], back.green);
  168632. png_composite(palette[i].blue, palette[i].blue,
  168633. png_ptr->trans[i], back.blue);
  168634. }
  168635. }
  168636. }
  168637. #endif /* PNG_READ_BACKGROUND_SUPPORTED */
  168638. #if defined(PNG_READ_SHIFT_SUPPORTED)
  168639. if ((png_ptr->transformations & PNG_SHIFT) &&
  168640. (color_type == PNG_COLOR_TYPE_PALETTE))
  168641. {
  168642. png_uint_16 i;
  168643. png_uint_16 istop = png_ptr->num_palette;
  168644. int sr = 8 - png_ptr->sig_bit.red;
  168645. int sg = 8 - png_ptr->sig_bit.green;
  168646. int sb = 8 - png_ptr->sig_bit.blue;
  168647. if (sr < 0 || sr > 8)
  168648. sr = 0;
  168649. if (sg < 0 || sg > 8)
  168650. sg = 0;
  168651. if (sb < 0 || sb > 8)
  168652. sb = 0;
  168653. for (i = 0; i < istop; i++)
  168654. {
  168655. png_ptr->palette[i].red >>= sr;
  168656. png_ptr->palette[i].green >>= sg;
  168657. png_ptr->palette[i].blue >>= sb;
  168658. }
  168659. }
  168660. #endif /* PNG_READ_SHIFT_SUPPORTED */
  168661. }
  168662. #if !defined(PNG_READ_GAMMA_SUPPORTED) && !defined(PNG_READ_SHIFT_SUPPORTED) \
  168663. && !defined(PNG_READ_BACKGROUND_SUPPORTED)
  168664. if(png_ptr)
  168665. return;
  168666. #endif
  168667. }
  168668. void /* PRIVATE */
  168669. png_read_transform_info(png_structp png_ptr, png_infop info_ptr)
  168670. {
  168671. png_debug(1, "in png_read_transform_info\n");
  168672. #if defined(PNG_READ_EXPAND_SUPPORTED)
  168673. if (png_ptr->transformations & PNG_EXPAND)
  168674. {
  168675. if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  168676. {
  168677. if (png_ptr->num_trans && (png_ptr->transformations & PNG_EXPAND_tRNS))
  168678. info_ptr->color_type = PNG_COLOR_TYPE_RGB_ALPHA;
  168679. else
  168680. info_ptr->color_type = PNG_COLOR_TYPE_RGB;
  168681. info_ptr->bit_depth = 8;
  168682. info_ptr->num_trans = 0;
  168683. }
  168684. else
  168685. {
  168686. if (png_ptr->num_trans)
  168687. {
  168688. if (png_ptr->transformations & PNG_EXPAND_tRNS)
  168689. info_ptr->color_type |= PNG_COLOR_MASK_ALPHA;
  168690. else
  168691. info_ptr->color_type |= PNG_COLOR_MASK_COLOR;
  168692. }
  168693. if (info_ptr->bit_depth < 8)
  168694. info_ptr->bit_depth = 8;
  168695. info_ptr->num_trans = 0;
  168696. }
  168697. }
  168698. #endif
  168699. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  168700. if (png_ptr->transformations & PNG_BACKGROUND)
  168701. {
  168702. info_ptr->color_type &= ~PNG_COLOR_MASK_ALPHA;
  168703. info_ptr->num_trans = 0;
  168704. info_ptr->background = png_ptr->background;
  168705. }
  168706. #endif
  168707. #if defined(PNG_READ_GAMMA_SUPPORTED)
  168708. if (png_ptr->transformations & PNG_GAMMA)
  168709. {
  168710. #ifdef PNG_FLOATING_POINT_SUPPORTED
  168711. info_ptr->gamma = png_ptr->gamma;
  168712. #endif
  168713. #ifdef PNG_FIXED_POINT_SUPPORTED
  168714. info_ptr->int_gamma = png_ptr->int_gamma;
  168715. #endif
  168716. }
  168717. #endif
  168718. #if defined(PNG_READ_16_TO_8_SUPPORTED)
  168719. if ((png_ptr->transformations & PNG_16_TO_8) && (info_ptr->bit_depth == 16))
  168720. info_ptr->bit_depth = 8;
  168721. #endif
  168722. #if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED)
  168723. if (png_ptr->transformations & PNG_GRAY_TO_RGB)
  168724. info_ptr->color_type |= PNG_COLOR_MASK_COLOR;
  168725. #endif
  168726. #if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
  168727. if (png_ptr->transformations & PNG_RGB_TO_GRAY)
  168728. info_ptr->color_type &= ~PNG_COLOR_MASK_COLOR;
  168729. #endif
  168730. #if defined(PNG_READ_DITHER_SUPPORTED)
  168731. if (png_ptr->transformations & PNG_DITHER)
  168732. {
  168733. if (((info_ptr->color_type == PNG_COLOR_TYPE_RGB) ||
  168734. (info_ptr->color_type == PNG_COLOR_TYPE_RGB_ALPHA)) &&
  168735. png_ptr->palette_lookup && info_ptr->bit_depth == 8)
  168736. {
  168737. info_ptr->color_type = PNG_COLOR_TYPE_PALETTE;
  168738. }
  168739. }
  168740. #endif
  168741. #if defined(PNG_READ_PACK_SUPPORTED)
  168742. if ((png_ptr->transformations & PNG_PACK) && (info_ptr->bit_depth < 8))
  168743. info_ptr->bit_depth = 8;
  168744. #endif
  168745. if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  168746. info_ptr->channels = 1;
  168747. else if (info_ptr->color_type & PNG_COLOR_MASK_COLOR)
  168748. info_ptr->channels = 3;
  168749. else
  168750. info_ptr->channels = 1;
  168751. #if defined(PNG_READ_STRIP_ALPHA_SUPPORTED)
  168752. if (png_ptr->flags & PNG_FLAG_STRIP_ALPHA)
  168753. info_ptr->color_type &= ~PNG_COLOR_MASK_ALPHA;
  168754. #endif
  168755. if (info_ptr->color_type & PNG_COLOR_MASK_ALPHA)
  168756. info_ptr->channels++;
  168757. #if defined(PNG_READ_FILLER_SUPPORTED)
  168758. if ((png_ptr->transformations & PNG_FILLER) &&
  168759. ((info_ptr->color_type == PNG_COLOR_TYPE_RGB) ||
  168760. (info_ptr->color_type == PNG_COLOR_TYPE_GRAY)))
  168761. {
  168762. info_ptr->channels++;
  168763. #if !defined(PNG_1_0_X)
  168764. if (png_ptr->transformations & PNG_ADD_ALPHA)
  168765. info_ptr->color_type |= PNG_COLOR_MASK_ALPHA;
  168766. #endif
  168767. }
  168768. #endif
  168769. #if defined(PNG_USER_TRANSFORM_PTR_SUPPORTED) && \
  168770. defined(PNG_READ_USER_TRANSFORM_SUPPORTED)
  168771. if(png_ptr->transformations & PNG_USER_TRANSFORM)
  168772. {
  168773. if(info_ptr->bit_depth < png_ptr->user_transform_depth)
  168774. info_ptr->bit_depth = png_ptr->user_transform_depth;
  168775. if(info_ptr->channels < png_ptr->user_transform_channels)
  168776. info_ptr->channels = png_ptr->user_transform_channels;
  168777. }
  168778. #endif
  168779. info_ptr->pixel_depth = (png_byte)(info_ptr->channels *
  168780. info_ptr->bit_depth);
  168781. info_ptr->rowbytes = PNG_ROWBYTES(info_ptr->pixel_depth,info_ptr->width);
  168782. #if !defined(PNG_READ_EXPAND_SUPPORTED)
  168783. if(png_ptr)
  168784. return;
  168785. #endif
  168786. }
  168787. void /* PRIVATE */
  168788. png_do_read_transformations(png_structp png_ptr)
  168789. {
  168790. png_debug(1, "in png_do_read_transformations\n");
  168791. if (png_ptr->row_buf == NULL)
  168792. {
  168793. #if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE)
  168794. char msg[50];
  168795. png_snprintf2(msg, 50,
  168796. "NULL row buffer for row %ld, pass %d", png_ptr->row_number,
  168797. png_ptr->pass);
  168798. png_error(png_ptr, msg);
  168799. #else
  168800. png_error(png_ptr, "NULL row buffer");
  168801. #endif
  168802. }
  168803. #ifdef PNG_WARN_UNINITIALIZED_ROW
  168804. if (!(png_ptr->flags & PNG_FLAG_ROW_INIT))
  168805. #if (PNG_WARN_UNINITIALIZED_ROW==1)
  168806. png_error(png_ptr, "Uninitialized row");
  168807. #else
  168808. png_warning(png_ptr, "Uninitialized row");
  168809. #endif
  168810. #endif
  168811. #if defined(PNG_READ_EXPAND_SUPPORTED)
  168812. if (png_ptr->transformations & PNG_EXPAND)
  168813. {
  168814. if (png_ptr->row_info.color_type == PNG_COLOR_TYPE_PALETTE)
  168815. {
  168816. png_do_expand_palette(&(png_ptr->row_info), png_ptr->row_buf + 1,
  168817. png_ptr->palette, png_ptr->trans, png_ptr->num_trans);
  168818. }
  168819. else
  168820. {
  168821. if (png_ptr->num_trans &&
  168822. (png_ptr->transformations & PNG_EXPAND_tRNS))
  168823. png_do_expand(&(png_ptr->row_info), png_ptr->row_buf + 1,
  168824. &(png_ptr->trans_values));
  168825. else
  168826. png_do_expand(&(png_ptr->row_info), png_ptr->row_buf + 1,
  168827. NULL);
  168828. }
  168829. }
  168830. #endif
  168831. #if defined(PNG_READ_STRIP_ALPHA_SUPPORTED)
  168832. if (png_ptr->flags & PNG_FLAG_STRIP_ALPHA)
  168833. png_do_strip_filler(&(png_ptr->row_info), png_ptr->row_buf + 1,
  168834. PNG_FLAG_FILLER_AFTER | (png_ptr->flags & PNG_FLAG_STRIP_ALPHA));
  168835. #endif
  168836. #if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
  168837. if (png_ptr->transformations & PNG_RGB_TO_GRAY)
  168838. {
  168839. int rgb_error =
  168840. png_do_rgb_to_gray(png_ptr, &(png_ptr->row_info), png_ptr->row_buf + 1);
  168841. if(rgb_error)
  168842. {
  168843. png_ptr->rgb_to_gray_status=1;
  168844. if((png_ptr->transformations & PNG_RGB_TO_GRAY) ==
  168845. PNG_RGB_TO_GRAY_WARN)
  168846. png_warning(png_ptr, "png_do_rgb_to_gray found nongray pixel");
  168847. if((png_ptr->transformations & PNG_RGB_TO_GRAY) ==
  168848. PNG_RGB_TO_GRAY_ERR)
  168849. png_error(png_ptr, "png_do_rgb_to_gray found nongray pixel");
  168850. }
  168851. }
  168852. #endif
  168853. #if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED)
  168854. if ((png_ptr->transformations & PNG_GRAY_TO_RGB) &&
  168855. !(png_ptr->mode & PNG_BACKGROUND_IS_GRAY))
  168856. png_do_gray_to_rgb(&(png_ptr->row_info), png_ptr->row_buf + 1);
  168857. #endif
  168858. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  168859. if ((png_ptr->transformations & PNG_BACKGROUND) &&
  168860. ((png_ptr->num_trans != 0 ) ||
  168861. (png_ptr->color_type & PNG_COLOR_MASK_ALPHA)))
  168862. png_do_background(&(png_ptr->row_info), png_ptr->row_buf + 1,
  168863. &(png_ptr->trans_values), &(png_ptr->background)
  168864. #if defined(PNG_READ_GAMMA_SUPPORTED)
  168865. , &(png_ptr->background_1),
  168866. png_ptr->gamma_table, png_ptr->gamma_from_1,
  168867. png_ptr->gamma_to_1, png_ptr->gamma_16_table,
  168868. png_ptr->gamma_16_from_1, png_ptr->gamma_16_to_1,
  168869. png_ptr->gamma_shift
  168870. #endif
  168871. );
  168872. #endif
  168873. #if defined(PNG_READ_GAMMA_SUPPORTED)
  168874. if ((png_ptr->transformations & PNG_GAMMA) &&
  168875. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  168876. !((png_ptr->transformations & PNG_BACKGROUND) &&
  168877. ((png_ptr->num_trans != 0) ||
  168878. (png_ptr->color_type & PNG_COLOR_MASK_ALPHA))) &&
  168879. #endif
  168880. (png_ptr->color_type != PNG_COLOR_TYPE_PALETTE))
  168881. png_do_gamma(&(png_ptr->row_info), png_ptr->row_buf + 1,
  168882. png_ptr->gamma_table, png_ptr->gamma_16_table,
  168883. png_ptr->gamma_shift);
  168884. #endif
  168885. #if defined(PNG_READ_16_TO_8_SUPPORTED)
  168886. if (png_ptr->transformations & PNG_16_TO_8)
  168887. png_do_chop(&(png_ptr->row_info), png_ptr->row_buf + 1);
  168888. #endif
  168889. #if defined(PNG_READ_DITHER_SUPPORTED)
  168890. if (png_ptr->transformations & PNG_DITHER)
  168891. {
  168892. png_do_dither((png_row_infop)&(png_ptr->row_info), png_ptr->row_buf + 1,
  168893. png_ptr->palette_lookup, png_ptr->dither_index);
  168894. if(png_ptr->row_info.rowbytes == (png_uint_32)0)
  168895. png_error(png_ptr, "png_do_dither returned rowbytes=0");
  168896. }
  168897. #endif
  168898. #if defined(PNG_READ_INVERT_SUPPORTED)
  168899. if (png_ptr->transformations & PNG_INVERT_MONO)
  168900. png_do_invert(&(png_ptr->row_info), png_ptr->row_buf + 1);
  168901. #endif
  168902. #if defined(PNG_READ_SHIFT_SUPPORTED)
  168903. if (png_ptr->transformations & PNG_SHIFT)
  168904. png_do_unshift(&(png_ptr->row_info), png_ptr->row_buf + 1,
  168905. &(png_ptr->shift));
  168906. #endif
  168907. #if defined(PNG_READ_PACK_SUPPORTED)
  168908. if (png_ptr->transformations & PNG_PACK)
  168909. png_do_unpack(&(png_ptr->row_info), png_ptr->row_buf + 1);
  168910. #endif
  168911. #if defined(PNG_READ_BGR_SUPPORTED)
  168912. if (png_ptr->transformations & PNG_BGR)
  168913. png_do_bgr(&(png_ptr->row_info), png_ptr->row_buf + 1);
  168914. #endif
  168915. #if defined(PNG_READ_PACKSWAP_SUPPORTED)
  168916. if (png_ptr->transformations & PNG_PACKSWAP)
  168917. png_do_packswap(&(png_ptr->row_info), png_ptr->row_buf + 1);
  168918. #endif
  168919. #if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED)
  168920. if ((png_ptr->transformations & PNG_GRAY_TO_RGB) &&
  168921. (png_ptr->mode & PNG_BACKGROUND_IS_GRAY))
  168922. png_do_gray_to_rgb(&(png_ptr->row_info), png_ptr->row_buf + 1);
  168923. #endif
  168924. #if defined(PNG_READ_FILLER_SUPPORTED)
  168925. if (png_ptr->transformations & PNG_FILLER)
  168926. png_do_read_filler(&(png_ptr->row_info), png_ptr->row_buf + 1,
  168927. (png_uint_32)png_ptr->filler, png_ptr->flags);
  168928. #endif
  168929. #if defined(PNG_READ_INVERT_ALPHA_SUPPORTED)
  168930. if (png_ptr->transformations & PNG_INVERT_ALPHA)
  168931. png_do_read_invert_alpha(&(png_ptr->row_info), png_ptr->row_buf + 1);
  168932. #endif
  168933. #if defined(PNG_READ_SWAP_ALPHA_SUPPORTED)
  168934. if (png_ptr->transformations & PNG_SWAP_ALPHA)
  168935. png_do_read_swap_alpha(&(png_ptr->row_info), png_ptr->row_buf + 1);
  168936. #endif
  168937. #if defined(PNG_READ_SWAP_SUPPORTED)
  168938. if (png_ptr->transformations & PNG_SWAP_BYTES)
  168939. png_do_swap(&(png_ptr->row_info), png_ptr->row_buf + 1);
  168940. #endif
  168941. #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED)
  168942. if (png_ptr->transformations & PNG_USER_TRANSFORM)
  168943. {
  168944. if(png_ptr->read_user_transform_fn != NULL)
  168945. (*(png_ptr->read_user_transform_fn)) /* user read transform function */
  168946. (png_ptr, /* png_ptr */
  168947. &(png_ptr->row_info), /* row_info: */
  168948. png_ptr->row_buf + 1); /* start of pixel data for row */
  168949. #if defined(PNG_USER_TRANSFORM_PTR_SUPPORTED)
  168950. if(png_ptr->user_transform_depth)
  168951. png_ptr->row_info.bit_depth = png_ptr->user_transform_depth;
  168952. if(png_ptr->user_transform_channels)
  168953. png_ptr->row_info.channels = png_ptr->user_transform_channels;
  168954. #endif
  168955. png_ptr->row_info.pixel_depth = (png_byte)(png_ptr->row_info.bit_depth *
  168956. png_ptr->row_info.channels);
  168957. png_ptr->row_info.rowbytes = PNG_ROWBYTES(png_ptr->row_info.pixel_depth,
  168958. png_ptr->row_info.width);
  168959. }
  168960. #endif
  168961. }
  168962. #if defined(PNG_READ_PACK_SUPPORTED)
  168963. void /* PRIVATE */
  168964. png_do_unpack(png_row_infop row_info, png_bytep row)
  168965. {
  168966. png_debug(1, "in png_do_unpack\n");
  168967. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  168968. if (row != NULL && row_info != NULL && row_info->bit_depth < 8)
  168969. #else
  168970. if (row_info->bit_depth < 8)
  168971. #endif
  168972. {
  168973. png_uint_32 i;
  168974. png_uint_32 row_width=row_info->width;
  168975. switch (row_info->bit_depth)
  168976. {
  168977. case 1:
  168978. {
  168979. png_bytep sp = row + (png_size_t)((row_width - 1) >> 3);
  168980. png_bytep dp = row + (png_size_t)row_width - 1;
  168981. png_uint_32 shift = 7 - (int)((row_width + 7) & 0x07);
  168982. for (i = 0; i < row_width; i++)
  168983. {
  168984. *dp = (png_byte)((*sp >> shift) & 0x01);
  168985. if (shift == 7)
  168986. {
  168987. shift = 0;
  168988. sp--;
  168989. }
  168990. else
  168991. shift++;
  168992. dp--;
  168993. }
  168994. break;
  168995. }
  168996. case 2:
  168997. {
  168998. png_bytep sp = row + (png_size_t)((row_width - 1) >> 2);
  168999. png_bytep dp = row + (png_size_t)row_width - 1;
  169000. png_uint_32 shift = (int)((3 - ((row_width + 3) & 0x03)) << 1);
  169001. for (i = 0; i < row_width; i++)
  169002. {
  169003. *dp = (png_byte)((*sp >> shift) & 0x03);
  169004. if (shift == 6)
  169005. {
  169006. shift = 0;
  169007. sp--;
  169008. }
  169009. else
  169010. shift += 2;
  169011. dp--;
  169012. }
  169013. break;
  169014. }
  169015. case 4:
  169016. {
  169017. png_bytep sp = row + (png_size_t)((row_width - 1) >> 1);
  169018. png_bytep dp = row + (png_size_t)row_width - 1;
  169019. png_uint_32 shift = (int)((1 - ((row_width + 1) & 0x01)) << 2);
  169020. for (i = 0; i < row_width; i++)
  169021. {
  169022. *dp = (png_byte)((*sp >> shift) & 0x0f);
  169023. if (shift == 4)
  169024. {
  169025. shift = 0;
  169026. sp--;
  169027. }
  169028. else
  169029. shift = 4;
  169030. dp--;
  169031. }
  169032. break;
  169033. }
  169034. }
  169035. row_info->bit_depth = 8;
  169036. row_info->pixel_depth = (png_byte)(8 * row_info->channels);
  169037. row_info->rowbytes = row_width * row_info->channels;
  169038. }
  169039. }
  169040. #endif
  169041. #if defined(PNG_READ_SHIFT_SUPPORTED)
  169042. void /* PRIVATE */
  169043. png_do_unshift(png_row_infop row_info, png_bytep row, png_color_8p sig_bits)
  169044. {
  169045. png_debug(1, "in png_do_unshift\n");
  169046. if (
  169047. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  169048. row != NULL && row_info != NULL && sig_bits != NULL &&
  169049. #endif
  169050. row_info->color_type != PNG_COLOR_TYPE_PALETTE)
  169051. {
  169052. int shift[4];
  169053. int channels = 0;
  169054. int c;
  169055. png_uint_16 value = 0;
  169056. png_uint_32 row_width = row_info->width;
  169057. if (row_info->color_type & PNG_COLOR_MASK_COLOR)
  169058. {
  169059. shift[channels++] = row_info->bit_depth - sig_bits->red;
  169060. shift[channels++] = row_info->bit_depth - sig_bits->green;
  169061. shift[channels++] = row_info->bit_depth - sig_bits->blue;
  169062. }
  169063. else
  169064. {
  169065. shift[channels++] = row_info->bit_depth - sig_bits->gray;
  169066. }
  169067. if (row_info->color_type & PNG_COLOR_MASK_ALPHA)
  169068. {
  169069. shift[channels++] = row_info->bit_depth - sig_bits->alpha;
  169070. }
  169071. for (c = 0; c < channels; c++)
  169072. {
  169073. if (shift[c] <= 0)
  169074. shift[c] = 0;
  169075. else
  169076. value = 1;
  169077. }
  169078. if (!value)
  169079. return;
  169080. switch (row_info->bit_depth)
  169081. {
  169082. case 2:
  169083. {
  169084. png_bytep bp;
  169085. png_uint_32 i;
  169086. png_uint_32 istop = row_info->rowbytes;
  169087. for (bp = row, i = 0; i < istop; i++)
  169088. {
  169089. *bp >>= 1;
  169090. *bp++ &= 0x55;
  169091. }
  169092. break;
  169093. }
  169094. case 4:
  169095. {
  169096. png_bytep bp = row;
  169097. png_uint_32 i;
  169098. png_uint_32 istop = row_info->rowbytes;
  169099. png_byte mask = (png_byte)((((int)0xf0 >> shift[0]) & (int)0xf0) |
  169100. (png_byte)((int)0xf >> shift[0]));
  169101. for (i = 0; i < istop; i++)
  169102. {
  169103. *bp >>= shift[0];
  169104. *bp++ &= mask;
  169105. }
  169106. break;
  169107. }
  169108. case 8:
  169109. {
  169110. png_bytep bp = row;
  169111. png_uint_32 i;
  169112. png_uint_32 istop = row_width * channels;
  169113. for (i = 0; i < istop; i++)
  169114. {
  169115. *bp++ >>= shift[i%channels];
  169116. }
  169117. break;
  169118. }
  169119. case 16:
  169120. {
  169121. png_bytep bp = row;
  169122. png_uint_32 i;
  169123. png_uint_32 istop = channels * row_width;
  169124. for (i = 0; i < istop; i++)
  169125. {
  169126. value = (png_uint_16)((*bp << 8) + *(bp + 1));
  169127. value >>= shift[i%channels];
  169128. *bp++ = (png_byte)(value >> 8);
  169129. *bp++ = (png_byte)(value & 0xff);
  169130. }
  169131. break;
  169132. }
  169133. }
  169134. }
  169135. }
  169136. #endif
  169137. #if defined(PNG_READ_16_TO_8_SUPPORTED)
  169138. void /* PRIVATE */
  169139. png_do_chop(png_row_infop row_info, png_bytep row)
  169140. {
  169141. png_debug(1, "in png_do_chop\n");
  169142. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  169143. if (row != NULL && row_info != NULL && row_info->bit_depth == 16)
  169144. #else
  169145. if (row_info->bit_depth == 16)
  169146. #endif
  169147. {
  169148. png_bytep sp = row;
  169149. png_bytep dp = row;
  169150. png_uint_32 i;
  169151. png_uint_32 istop = row_info->width * row_info->channels;
  169152. for (i = 0; i<istop; i++, sp += 2, dp++)
  169153. {
  169154. #if defined(PNG_READ_16_TO_8_ACCURATE_SCALE_SUPPORTED)
  169155. *dp = *sp + ((((int)(*(sp + 1)) - *sp) > 128) ? 1 : 0);
  169156. #else
  169157. *dp = *sp;
  169158. #endif
  169159. }
  169160. row_info->bit_depth = 8;
  169161. row_info->pixel_depth = (png_byte)(8 * row_info->channels);
  169162. row_info->rowbytes = row_info->width * row_info->channels;
  169163. }
  169164. }
  169165. #endif
  169166. #if defined(PNG_READ_SWAP_ALPHA_SUPPORTED)
  169167. void /* PRIVATE */
  169168. png_do_read_swap_alpha(png_row_infop row_info, png_bytep row)
  169169. {
  169170. png_debug(1, "in png_do_read_swap_alpha\n");
  169171. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  169172. if (row != NULL && row_info != NULL)
  169173. #endif
  169174. {
  169175. png_uint_32 row_width = row_info->width;
  169176. if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  169177. {
  169178. if (row_info->bit_depth == 8)
  169179. {
  169180. png_bytep sp = row + row_info->rowbytes;
  169181. png_bytep dp = sp;
  169182. png_byte save;
  169183. png_uint_32 i;
  169184. for (i = 0; i < row_width; i++)
  169185. {
  169186. save = *(--sp);
  169187. *(--dp) = *(--sp);
  169188. *(--dp) = *(--sp);
  169189. *(--dp) = *(--sp);
  169190. *(--dp) = save;
  169191. }
  169192. }
  169193. else
  169194. {
  169195. png_bytep sp = row + row_info->rowbytes;
  169196. png_bytep dp = sp;
  169197. png_byte save[2];
  169198. png_uint_32 i;
  169199. for (i = 0; i < row_width; i++)
  169200. {
  169201. save[0] = *(--sp);
  169202. save[1] = *(--sp);
  169203. *(--dp) = *(--sp);
  169204. *(--dp) = *(--sp);
  169205. *(--dp) = *(--sp);
  169206. *(--dp) = *(--sp);
  169207. *(--dp) = *(--sp);
  169208. *(--dp) = *(--sp);
  169209. *(--dp) = save[0];
  169210. *(--dp) = save[1];
  169211. }
  169212. }
  169213. }
  169214. else if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
  169215. {
  169216. if (row_info->bit_depth == 8)
  169217. {
  169218. png_bytep sp = row + row_info->rowbytes;
  169219. png_bytep dp = sp;
  169220. png_byte save;
  169221. png_uint_32 i;
  169222. for (i = 0; i < row_width; i++)
  169223. {
  169224. save = *(--sp);
  169225. *(--dp) = *(--sp);
  169226. *(--dp) = save;
  169227. }
  169228. }
  169229. else
  169230. {
  169231. png_bytep sp = row + row_info->rowbytes;
  169232. png_bytep dp = sp;
  169233. png_byte save[2];
  169234. png_uint_32 i;
  169235. for (i = 0; i < row_width; i++)
  169236. {
  169237. save[0] = *(--sp);
  169238. save[1] = *(--sp);
  169239. *(--dp) = *(--sp);
  169240. *(--dp) = *(--sp);
  169241. *(--dp) = save[0];
  169242. *(--dp) = save[1];
  169243. }
  169244. }
  169245. }
  169246. }
  169247. }
  169248. #endif
  169249. #if defined(PNG_READ_INVERT_ALPHA_SUPPORTED)
  169250. void /* PRIVATE */
  169251. png_do_read_invert_alpha(png_row_infop row_info, png_bytep row)
  169252. {
  169253. png_debug(1, "in png_do_read_invert_alpha\n");
  169254. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  169255. if (row != NULL && row_info != NULL)
  169256. #endif
  169257. {
  169258. png_uint_32 row_width = row_info->width;
  169259. if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  169260. {
  169261. if (row_info->bit_depth == 8)
  169262. {
  169263. png_bytep sp = row + row_info->rowbytes;
  169264. png_bytep dp = sp;
  169265. png_uint_32 i;
  169266. for (i = 0; i < row_width; i++)
  169267. {
  169268. *(--dp) = (png_byte)(255 - *(--sp));
  169269. sp-=3;
  169270. dp=sp;
  169271. }
  169272. }
  169273. else
  169274. {
  169275. png_bytep sp = row + row_info->rowbytes;
  169276. png_bytep dp = sp;
  169277. png_uint_32 i;
  169278. for (i = 0; i < row_width; i++)
  169279. {
  169280. *(--dp) = (png_byte)(255 - *(--sp));
  169281. *(--dp) = (png_byte)(255 - *(--sp));
  169282. sp-=6;
  169283. dp=sp;
  169284. }
  169285. }
  169286. }
  169287. else if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
  169288. {
  169289. if (row_info->bit_depth == 8)
  169290. {
  169291. png_bytep sp = row + row_info->rowbytes;
  169292. png_bytep dp = sp;
  169293. png_uint_32 i;
  169294. for (i = 0; i < row_width; i++)
  169295. {
  169296. *(--dp) = (png_byte)(255 - *(--sp));
  169297. *(--dp) = *(--sp);
  169298. }
  169299. }
  169300. else
  169301. {
  169302. png_bytep sp = row + row_info->rowbytes;
  169303. png_bytep dp = sp;
  169304. png_uint_32 i;
  169305. for (i = 0; i < row_width; i++)
  169306. {
  169307. *(--dp) = (png_byte)(255 - *(--sp));
  169308. *(--dp) = (png_byte)(255 - *(--sp));
  169309. sp-=2;
  169310. dp=sp;
  169311. }
  169312. }
  169313. }
  169314. }
  169315. }
  169316. #endif
  169317. #if defined(PNG_READ_FILLER_SUPPORTED)
  169318. void /* PRIVATE */
  169319. png_do_read_filler(png_row_infop row_info, png_bytep row,
  169320. png_uint_32 filler, png_uint_32 flags)
  169321. {
  169322. png_uint_32 i;
  169323. png_uint_32 row_width = row_info->width;
  169324. png_byte hi_filler = (png_byte)((filler>>8) & 0xff);
  169325. png_byte lo_filler = (png_byte)(filler & 0xff);
  169326. png_debug(1, "in png_do_read_filler\n");
  169327. if (
  169328. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  169329. row != NULL && row_info != NULL &&
  169330. #endif
  169331. row_info->color_type == PNG_COLOR_TYPE_GRAY)
  169332. {
  169333. if(row_info->bit_depth == 8)
  169334. {
  169335. if (flags & PNG_FLAG_FILLER_AFTER)
  169336. {
  169337. png_bytep sp = row + (png_size_t)row_width;
  169338. png_bytep dp = sp + (png_size_t)row_width;
  169339. for (i = 1; i < row_width; i++)
  169340. {
  169341. *(--dp) = lo_filler;
  169342. *(--dp) = *(--sp);
  169343. }
  169344. *(--dp) = lo_filler;
  169345. row_info->channels = 2;
  169346. row_info->pixel_depth = 16;
  169347. row_info->rowbytes = row_width * 2;
  169348. }
  169349. else
  169350. {
  169351. png_bytep sp = row + (png_size_t)row_width;
  169352. png_bytep dp = sp + (png_size_t)row_width;
  169353. for (i = 0; i < row_width; i++)
  169354. {
  169355. *(--dp) = *(--sp);
  169356. *(--dp) = lo_filler;
  169357. }
  169358. row_info->channels = 2;
  169359. row_info->pixel_depth = 16;
  169360. row_info->rowbytes = row_width * 2;
  169361. }
  169362. }
  169363. else if(row_info->bit_depth == 16)
  169364. {
  169365. if (flags & PNG_FLAG_FILLER_AFTER)
  169366. {
  169367. png_bytep sp = row + (png_size_t)row_width * 2;
  169368. png_bytep dp = sp + (png_size_t)row_width * 2;
  169369. for (i = 1; i < row_width; i++)
  169370. {
  169371. *(--dp) = hi_filler;
  169372. *(--dp) = lo_filler;
  169373. *(--dp) = *(--sp);
  169374. *(--dp) = *(--sp);
  169375. }
  169376. *(--dp) = hi_filler;
  169377. *(--dp) = lo_filler;
  169378. row_info->channels = 2;
  169379. row_info->pixel_depth = 32;
  169380. row_info->rowbytes = row_width * 4;
  169381. }
  169382. else
  169383. {
  169384. png_bytep sp = row + (png_size_t)row_width * 2;
  169385. png_bytep dp = sp + (png_size_t)row_width * 2;
  169386. for (i = 0; i < row_width; i++)
  169387. {
  169388. *(--dp) = *(--sp);
  169389. *(--dp) = *(--sp);
  169390. *(--dp) = hi_filler;
  169391. *(--dp) = lo_filler;
  169392. }
  169393. row_info->channels = 2;
  169394. row_info->pixel_depth = 32;
  169395. row_info->rowbytes = row_width * 4;
  169396. }
  169397. }
  169398. } /* COLOR_TYPE == GRAY */
  169399. else if (row_info->color_type == PNG_COLOR_TYPE_RGB)
  169400. {
  169401. if(row_info->bit_depth == 8)
  169402. {
  169403. if (flags & PNG_FLAG_FILLER_AFTER)
  169404. {
  169405. png_bytep sp = row + (png_size_t)row_width * 3;
  169406. png_bytep dp = sp + (png_size_t)row_width;
  169407. for (i = 1; i < row_width; i++)
  169408. {
  169409. *(--dp) = lo_filler;
  169410. *(--dp) = *(--sp);
  169411. *(--dp) = *(--sp);
  169412. *(--dp) = *(--sp);
  169413. }
  169414. *(--dp) = lo_filler;
  169415. row_info->channels = 4;
  169416. row_info->pixel_depth = 32;
  169417. row_info->rowbytes = row_width * 4;
  169418. }
  169419. else
  169420. {
  169421. png_bytep sp = row + (png_size_t)row_width * 3;
  169422. png_bytep dp = sp + (png_size_t)row_width;
  169423. for (i = 0; i < row_width; i++)
  169424. {
  169425. *(--dp) = *(--sp);
  169426. *(--dp) = *(--sp);
  169427. *(--dp) = *(--sp);
  169428. *(--dp) = lo_filler;
  169429. }
  169430. row_info->channels = 4;
  169431. row_info->pixel_depth = 32;
  169432. row_info->rowbytes = row_width * 4;
  169433. }
  169434. }
  169435. else if(row_info->bit_depth == 16)
  169436. {
  169437. if (flags & PNG_FLAG_FILLER_AFTER)
  169438. {
  169439. png_bytep sp = row + (png_size_t)row_width * 6;
  169440. png_bytep dp = sp + (png_size_t)row_width * 2;
  169441. for (i = 1; i < row_width; i++)
  169442. {
  169443. *(--dp) = hi_filler;
  169444. *(--dp) = lo_filler;
  169445. *(--dp) = *(--sp);
  169446. *(--dp) = *(--sp);
  169447. *(--dp) = *(--sp);
  169448. *(--dp) = *(--sp);
  169449. *(--dp) = *(--sp);
  169450. *(--dp) = *(--sp);
  169451. }
  169452. *(--dp) = hi_filler;
  169453. *(--dp) = lo_filler;
  169454. row_info->channels = 4;
  169455. row_info->pixel_depth = 64;
  169456. row_info->rowbytes = row_width * 8;
  169457. }
  169458. else
  169459. {
  169460. png_bytep sp = row + (png_size_t)row_width * 6;
  169461. png_bytep dp = sp + (png_size_t)row_width * 2;
  169462. for (i = 0; i < row_width; i++)
  169463. {
  169464. *(--dp) = *(--sp);
  169465. *(--dp) = *(--sp);
  169466. *(--dp) = *(--sp);
  169467. *(--dp) = *(--sp);
  169468. *(--dp) = *(--sp);
  169469. *(--dp) = *(--sp);
  169470. *(--dp) = hi_filler;
  169471. *(--dp) = lo_filler;
  169472. }
  169473. row_info->channels = 4;
  169474. row_info->pixel_depth = 64;
  169475. row_info->rowbytes = row_width * 8;
  169476. }
  169477. }
  169478. } /* COLOR_TYPE == RGB */
  169479. }
  169480. #endif
  169481. #if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED)
  169482. void /* PRIVATE */
  169483. png_do_gray_to_rgb(png_row_infop row_info, png_bytep row)
  169484. {
  169485. png_uint_32 i;
  169486. png_uint_32 row_width = row_info->width;
  169487. png_debug(1, "in png_do_gray_to_rgb\n");
  169488. if (row_info->bit_depth >= 8 &&
  169489. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  169490. row != NULL && row_info != NULL &&
  169491. #endif
  169492. !(row_info->color_type & PNG_COLOR_MASK_COLOR))
  169493. {
  169494. if (row_info->color_type == PNG_COLOR_TYPE_GRAY)
  169495. {
  169496. if (row_info->bit_depth == 8)
  169497. {
  169498. png_bytep sp = row + (png_size_t)row_width - 1;
  169499. png_bytep dp = sp + (png_size_t)row_width * 2;
  169500. for (i = 0; i < row_width; i++)
  169501. {
  169502. *(dp--) = *sp;
  169503. *(dp--) = *sp;
  169504. *(dp--) = *(sp--);
  169505. }
  169506. }
  169507. else
  169508. {
  169509. png_bytep sp = row + (png_size_t)row_width * 2 - 1;
  169510. png_bytep dp = sp + (png_size_t)row_width * 4;
  169511. for (i = 0; i < row_width; i++)
  169512. {
  169513. *(dp--) = *sp;
  169514. *(dp--) = *(sp - 1);
  169515. *(dp--) = *sp;
  169516. *(dp--) = *(sp - 1);
  169517. *(dp--) = *(sp--);
  169518. *(dp--) = *(sp--);
  169519. }
  169520. }
  169521. }
  169522. else if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
  169523. {
  169524. if (row_info->bit_depth == 8)
  169525. {
  169526. png_bytep sp = row + (png_size_t)row_width * 2 - 1;
  169527. png_bytep dp = sp + (png_size_t)row_width * 2;
  169528. for (i = 0; i < row_width; i++)
  169529. {
  169530. *(dp--) = *(sp--);
  169531. *(dp--) = *sp;
  169532. *(dp--) = *sp;
  169533. *(dp--) = *(sp--);
  169534. }
  169535. }
  169536. else
  169537. {
  169538. png_bytep sp = row + (png_size_t)row_width * 4 - 1;
  169539. png_bytep dp = sp + (png_size_t)row_width * 4;
  169540. for (i = 0; i < row_width; i++)
  169541. {
  169542. *(dp--) = *(sp--);
  169543. *(dp--) = *(sp--);
  169544. *(dp--) = *sp;
  169545. *(dp--) = *(sp - 1);
  169546. *(dp--) = *sp;
  169547. *(dp--) = *(sp - 1);
  169548. *(dp--) = *(sp--);
  169549. *(dp--) = *(sp--);
  169550. }
  169551. }
  169552. }
  169553. row_info->channels += (png_byte)2;
  169554. row_info->color_type |= PNG_COLOR_MASK_COLOR;
  169555. row_info->pixel_depth = (png_byte)(row_info->channels *
  169556. row_info->bit_depth);
  169557. row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,row_width);
  169558. }
  169559. }
  169560. #endif
  169561. #if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
  169562. int /* PRIVATE */
  169563. png_do_rgb_to_gray(png_structp png_ptr, png_row_infop row_info, png_bytep row)
  169564. {
  169565. png_uint_32 i;
  169566. png_uint_32 row_width = row_info->width;
  169567. int rgb_error = 0;
  169568. png_debug(1, "in png_do_rgb_to_gray\n");
  169569. if (
  169570. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  169571. row != NULL && row_info != NULL &&
  169572. #endif
  169573. (row_info->color_type & PNG_COLOR_MASK_COLOR))
  169574. {
  169575. png_uint_32 rc = png_ptr->rgb_to_gray_red_coeff;
  169576. png_uint_32 gc = png_ptr->rgb_to_gray_green_coeff;
  169577. png_uint_32 bc = png_ptr->rgb_to_gray_blue_coeff;
  169578. if (row_info->color_type == PNG_COLOR_TYPE_RGB)
  169579. {
  169580. if (row_info->bit_depth == 8)
  169581. {
  169582. #if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
  169583. if (png_ptr->gamma_from_1 != NULL && png_ptr->gamma_to_1 != NULL)
  169584. {
  169585. png_bytep sp = row;
  169586. png_bytep dp = row;
  169587. for (i = 0; i < row_width; i++)
  169588. {
  169589. png_byte red = png_ptr->gamma_to_1[*(sp++)];
  169590. png_byte green = png_ptr->gamma_to_1[*(sp++)];
  169591. png_byte blue = png_ptr->gamma_to_1[*(sp++)];
  169592. if(red != green || red != blue)
  169593. {
  169594. rgb_error |= 1;
  169595. *(dp++) = png_ptr->gamma_from_1[
  169596. (rc*red+gc*green+bc*blue)>>15];
  169597. }
  169598. else
  169599. *(dp++) = *(sp-1);
  169600. }
  169601. }
  169602. else
  169603. #endif
  169604. {
  169605. png_bytep sp = row;
  169606. png_bytep dp = row;
  169607. for (i = 0; i < row_width; i++)
  169608. {
  169609. png_byte red = *(sp++);
  169610. png_byte green = *(sp++);
  169611. png_byte blue = *(sp++);
  169612. if(red != green || red != blue)
  169613. {
  169614. rgb_error |= 1;
  169615. *(dp++) = (png_byte)((rc*red+gc*green+bc*blue)>>15);
  169616. }
  169617. else
  169618. *(dp++) = *(sp-1);
  169619. }
  169620. }
  169621. }
  169622. else /* RGB bit_depth == 16 */
  169623. {
  169624. #if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
  169625. if (png_ptr->gamma_16_to_1 != NULL &&
  169626. png_ptr->gamma_16_from_1 != NULL)
  169627. {
  169628. png_bytep sp = row;
  169629. png_bytep dp = row;
  169630. for (i = 0; i < row_width; i++)
  169631. {
  169632. png_uint_16 red, green, blue, w;
  169633. red = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2;
  169634. green = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2;
  169635. blue = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2;
  169636. if(red == green && red == blue)
  169637. w = red;
  169638. else
  169639. {
  169640. png_uint_16 red_1 = png_ptr->gamma_16_to_1[(red&0xff) >>
  169641. png_ptr->gamma_shift][red>>8];
  169642. png_uint_16 green_1 = png_ptr->gamma_16_to_1[(green&0xff) >>
  169643. png_ptr->gamma_shift][green>>8];
  169644. png_uint_16 blue_1 = png_ptr->gamma_16_to_1[(blue&0xff) >>
  169645. png_ptr->gamma_shift][blue>>8];
  169646. png_uint_16 gray16 = (png_uint_16)((rc*red_1 + gc*green_1
  169647. + bc*blue_1)>>15);
  169648. w = png_ptr->gamma_16_from_1[(gray16&0xff) >>
  169649. png_ptr->gamma_shift][gray16 >> 8];
  169650. rgb_error |= 1;
  169651. }
  169652. *(dp++) = (png_byte)((w>>8) & 0xff);
  169653. *(dp++) = (png_byte)(w & 0xff);
  169654. }
  169655. }
  169656. else
  169657. #endif
  169658. {
  169659. png_bytep sp = row;
  169660. png_bytep dp = row;
  169661. for (i = 0; i < row_width; i++)
  169662. {
  169663. png_uint_16 red, green, blue, gray16;
  169664. red = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2;
  169665. green = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2;
  169666. blue = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2;
  169667. if(red != green || red != blue)
  169668. rgb_error |= 1;
  169669. gray16 = (png_uint_16)((rc*red + gc*green + bc*blue)>>15);
  169670. *(dp++) = (png_byte)((gray16>>8) & 0xff);
  169671. *(dp++) = (png_byte)(gray16 & 0xff);
  169672. }
  169673. }
  169674. }
  169675. }
  169676. if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  169677. {
  169678. if (row_info->bit_depth == 8)
  169679. {
  169680. #if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
  169681. if (png_ptr->gamma_from_1 != NULL && png_ptr->gamma_to_1 != NULL)
  169682. {
  169683. png_bytep sp = row;
  169684. png_bytep dp = row;
  169685. for (i = 0; i < row_width; i++)
  169686. {
  169687. png_byte red = png_ptr->gamma_to_1[*(sp++)];
  169688. png_byte green = png_ptr->gamma_to_1[*(sp++)];
  169689. png_byte blue = png_ptr->gamma_to_1[*(sp++)];
  169690. if(red != green || red != blue)
  169691. rgb_error |= 1;
  169692. *(dp++) = png_ptr->gamma_from_1
  169693. [(rc*red + gc*green + bc*blue)>>15];
  169694. *(dp++) = *(sp++); /* alpha */
  169695. }
  169696. }
  169697. else
  169698. #endif
  169699. {
  169700. png_bytep sp = row;
  169701. png_bytep dp = row;
  169702. for (i = 0; i < row_width; i++)
  169703. {
  169704. png_byte red = *(sp++);
  169705. png_byte green = *(sp++);
  169706. png_byte blue = *(sp++);
  169707. if(red != green || red != blue)
  169708. rgb_error |= 1;
  169709. *(dp++) = (png_byte)((rc*red + gc*green + bc*blue)>>15);
  169710. *(dp++) = *(sp++); /* alpha */
  169711. }
  169712. }
  169713. }
  169714. else /* RGBA bit_depth == 16 */
  169715. {
  169716. #if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
  169717. if (png_ptr->gamma_16_to_1 != NULL &&
  169718. png_ptr->gamma_16_from_1 != NULL)
  169719. {
  169720. png_bytep sp = row;
  169721. png_bytep dp = row;
  169722. for (i = 0; i < row_width; i++)
  169723. {
  169724. png_uint_16 red, green, blue, w;
  169725. red = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2;
  169726. green = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2;
  169727. blue = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2;
  169728. if(red == green && red == blue)
  169729. w = red;
  169730. else
  169731. {
  169732. png_uint_16 red_1 = png_ptr->gamma_16_to_1[(red&0xff) >>
  169733. png_ptr->gamma_shift][red>>8];
  169734. png_uint_16 green_1 = png_ptr->gamma_16_to_1[(green&0xff) >>
  169735. png_ptr->gamma_shift][green>>8];
  169736. png_uint_16 blue_1 = png_ptr->gamma_16_to_1[(blue&0xff) >>
  169737. png_ptr->gamma_shift][blue>>8];
  169738. png_uint_16 gray16 = (png_uint_16)((rc * red_1
  169739. + gc * green_1 + bc * blue_1)>>15);
  169740. w = png_ptr->gamma_16_from_1[(gray16&0xff) >>
  169741. png_ptr->gamma_shift][gray16 >> 8];
  169742. rgb_error |= 1;
  169743. }
  169744. *(dp++) = (png_byte)((w>>8) & 0xff);
  169745. *(dp++) = (png_byte)(w & 0xff);
  169746. *(dp++) = *(sp++); /* alpha */
  169747. *(dp++) = *(sp++);
  169748. }
  169749. }
  169750. else
  169751. #endif
  169752. {
  169753. png_bytep sp = row;
  169754. png_bytep dp = row;
  169755. for (i = 0; i < row_width; i++)
  169756. {
  169757. png_uint_16 red, green, blue, gray16;
  169758. red = (png_uint_16)((*(sp)<<8) | *(sp+1)); sp+=2;
  169759. green = (png_uint_16)((*(sp)<<8) | *(sp+1)); sp+=2;
  169760. blue = (png_uint_16)((*(sp)<<8) | *(sp+1)); sp+=2;
  169761. if(red != green || red != blue)
  169762. rgb_error |= 1;
  169763. gray16 = (png_uint_16)((rc*red + gc*green + bc*blue)>>15);
  169764. *(dp++) = (png_byte)((gray16>>8) & 0xff);
  169765. *(dp++) = (png_byte)(gray16 & 0xff);
  169766. *(dp++) = *(sp++); /* alpha */
  169767. *(dp++) = *(sp++);
  169768. }
  169769. }
  169770. }
  169771. }
  169772. row_info->channels -= (png_byte)2;
  169773. row_info->color_type &= ~PNG_COLOR_MASK_COLOR;
  169774. row_info->pixel_depth = (png_byte)(row_info->channels *
  169775. row_info->bit_depth);
  169776. row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,row_width);
  169777. }
  169778. return rgb_error;
  169779. }
  169780. #endif
  169781. void PNGAPI
  169782. png_build_grayscale_palette(int bit_depth, png_colorp palette)
  169783. {
  169784. int num_palette;
  169785. int color_inc;
  169786. int i;
  169787. int v;
  169788. png_debug(1, "in png_do_build_grayscale_palette\n");
  169789. if (palette == NULL)
  169790. return;
  169791. switch (bit_depth)
  169792. {
  169793. case 1:
  169794. num_palette = 2;
  169795. color_inc = 0xff;
  169796. break;
  169797. case 2:
  169798. num_palette = 4;
  169799. color_inc = 0x55;
  169800. break;
  169801. case 4:
  169802. num_palette = 16;
  169803. color_inc = 0x11;
  169804. break;
  169805. case 8:
  169806. num_palette = 256;
  169807. color_inc = 1;
  169808. break;
  169809. default:
  169810. num_palette = 0;
  169811. color_inc = 0;
  169812. break;
  169813. }
  169814. for (i = 0, v = 0; i < num_palette; i++, v += color_inc)
  169815. {
  169816. palette[i].red = (png_byte)v;
  169817. palette[i].green = (png_byte)v;
  169818. palette[i].blue = (png_byte)v;
  169819. }
  169820. }
  169821. #if defined(PNG_READ_DITHER_SUPPORTED) && defined(PNG_CORRECT_PALETTE_SUPPORTED)
  169822. void /* PRIVATE */
  169823. png_correct_palette(png_structp png_ptr, png_colorp palette,
  169824. int num_palette)
  169825. {
  169826. png_debug(1, "in png_correct_palette\n");
  169827. #if defined(PNG_READ_BACKGROUND_SUPPORTED) && \
  169828. defined(PNG_READ_GAMMA_SUPPORTED) && defined(PNG_FLOATING_POINT_SUPPORTED)
  169829. if (png_ptr->transformations & (PNG_GAMMA | PNG_BACKGROUND))
  169830. {
  169831. png_color back, back_1;
  169832. if (png_ptr->background_gamma_type == PNG_BACKGROUND_GAMMA_FILE)
  169833. {
  169834. back.red = png_ptr->gamma_table[png_ptr->background.red];
  169835. back.green = png_ptr->gamma_table[png_ptr->background.green];
  169836. back.blue = png_ptr->gamma_table[png_ptr->background.blue];
  169837. back_1.red = png_ptr->gamma_to_1[png_ptr->background.red];
  169838. back_1.green = png_ptr->gamma_to_1[png_ptr->background.green];
  169839. back_1.blue = png_ptr->gamma_to_1[png_ptr->background.blue];
  169840. }
  169841. else
  169842. {
  169843. double g;
  169844. g = 1.0 / (png_ptr->background_gamma * png_ptr->screen_gamma);
  169845. if (png_ptr->background_gamma_type == PNG_BACKGROUND_GAMMA_SCREEN ||
  169846. fabs(g - 1.0) < PNG_GAMMA_THRESHOLD)
  169847. {
  169848. back.red = png_ptr->background.red;
  169849. back.green = png_ptr->background.green;
  169850. back.blue = png_ptr->background.blue;
  169851. }
  169852. else
  169853. {
  169854. back.red =
  169855. (png_byte)(pow((double)png_ptr->background.red/255, g) *
  169856. 255.0 + 0.5);
  169857. back.green =
  169858. (png_byte)(pow((double)png_ptr->background.green/255, g) *
  169859. 255.0 + 0.5);
  169860. back.blue =
  169861. (png_byte)(pow((double)png_ptr->background.blue/255, g) *
  169862. 255.0 + 0.5);
  169863. }
  169864. g = 1.0 / png_ptr->background_gamma;
  169865. back_1.red =
  169866. (png_byte)(pow((double)png_ptr->background.red/255, g) *
  169867. 255.0 + 0.5);
  169868. back_1.green =
  169869. (png_byte)(pow((double)png_ptr->background.green/255, g) *
  169870. 255.0 + 0.5);
  169871. back_1.blue =
  169872. (png_byte)(pow((double)png_ptr->background.blue/255, g) *
  169873. 255.0 + 0.5);
  169874. }
  169875. if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  169876. {
  169877. png_uint_32 i;
  169878. for (i = 0; i < (png_uint_32)num_palette; i++)
  169879. {
  169880. if (i < png_ptr->num_trans && png_ptr->trans[i] == 0)
  169881. {
  169882. palette[i] = back;
  169883. }
  169884. else if (i < png_ptr->num_trans && png_ptr->trans[i] != 0xff)
  169885. {
  169886. png_byte v, w;
  169887. v = png_ptr->gamma_to_1[png_ptr->palette[i].red];
  169888. png_composite(w, v, png_ptr->trans[i], back_1.red);
  169889. palette[i].red = png_ptr->gamma_from_1[w];
  169890. v = png_ptr->gamma_to_1[png_ptr->palette[i].green];
  169891. png_composite(w, v, png_ptr->trans[i], back_1.green);
  169892. palette[i].green = png_ptr->gamma_from_1[w];
  169893. v = png_ptr->gamma_to_1[png_ptr->palette[i].blue];
  169894. png_composite(w, v, png_ptr->trans[i], back_1.blue);
  169895. palette[i].blue = png_ptr->gamma_from_1[w];
  169896. }
  169897. else
  169898. {
  169899. palette[i].red = png_ptr->gamma_table[palette[i].red];
  169900. palette[i].green = png_ptr->gamma_table[palette[i].green];
  169901. palette[i].blue = png_ptr->gamma_table[palette[i].blue];
  169902. }
  169903. }
  169904. }
  169905. else
  169906. {
  169907. int i;
  169908. for (i = 0; i < num_palette; i++)
  169909. {
  169910. if (palette[i].red == (png_byte)png_ptr->trans_values.gray)
  169911. {
  169912. palette[i] = back;
  169913. }
  169914. else
  169915. {
  169916. palette[i].red = png_ptr->gamma_table[palette[i].red];
  169917. palette[i].green = png_ptr->gamma_table[palette[i].green];
  169918. palette[i].blue = png_ptr->gamma_table[palette[i].blue];
  169919. }
  169920. }
  169921. }
  169922. }
  169923. else
  169924. #endif
  169925. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169926. if (png_ptr->transformations & PNG_GAMMA)
  169927. {
  169928. int i;
  169929. for (i = 0; i < num_palette; i++)
  169930. {
  169931. palette[i].red = png_ptr->gamma_table[palette[i].red];
  169932. palette[i].green = png_ptr->gamma_table[palette[i].green];
  169933. palette[i].blue = png_ptr->gamma_table[palette[i].blue];
  169934. }
  169935. }
  169936. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  169937. else
  169938. #endif
  169939. #endif
  169940. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  169941. if (png_ptr->transformations & PNG_BACKGROUND)
  169942. {
  169943. if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  169944. {
  169945. png_color back;
  169946. back.red = (png_byte)png_ptr->background.red;
  169947. back.green = (png_byte)png_ptr->background.green;
  169948. back.blue = (png_byte)png_ptr->background.blue;
  169949. for (i = 0; i < (int)png_ptr->num_trans; i++)
  169950. {
  169951. if (png_ptr->trans[i] == 0)
  169952. {
  169953. palette[i].red = back.red;
  169954. palette[i].green = back.green;
  169955. palette[i].blue = back.blue;
  169956. }
  169957. else if (png_ptr->trans[i] != 0xff)
  169958. {
  169959. png_composite(palette[i].red, png_ptr->palette[i].red,
  169960. png_ptr->trans[i], back.red);
  169961. png_composite(palette[i].green, png_ptr->palette[i].green,
  169962. png_ptr->trans[i], back.green);
  169963. png_composite(palette[i].blue, png_ptr->palette[i].blue,
  169964. png_ptr->trans[i], back.blue);
  169965. }
  169966. }
  169967. }
  169968. else /* assume grayscale palette (what else could it be?) */
  169969. {
  169970. int i;
  169971. for (i = 0; i < num_palette; i++)
  169972. {
  169973. if (i == (png_byte)png_ptr->trans_values.gray)
  169974. {
  169975. palette[i].red = (png_byte)png_ptr->background.red;
  169976. palette[i].green = (png_byte)png_ptr->background.green;
  169977. palette[i].blue = (png_byte)png_ptr->background.blue;
  169978. }
  169979. }
  169980. }
  169981. }
  169982. #endif
  169983. }
  169984. #endif
  169985. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  169986. void /* PRIVATE */
  169987. png_do_background(png_row_infop row_info, png_bytep row,
  169988. png_color_16p trans_values, png_color_16p background
  169989. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169990. , png_color_16p background_1,
  169991. png_bytep gamma_table, png_bytep gamma_from_1, png_bytep gamma_to_1,
  169992. png_uint_16pp gamma_16, png_uint_16pp gamma_16_from_1,
  169993. png_uint_16pp gamma_16_to_1, int gamma_shift
  169994. #endif
  169995. )
  169996. {
  169997. png_bytep sp, dp;
  169998. png_uint_32 i;
  169999. png_uint_32 row_width=row_info->width;
  170000. int shift;
  170001. png_debug(1, "in png_do_background\n");
  170002. if (background != NULL &&
  170003. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  170004. row != NULL && row_info != NULL &&
  170005. #endif
  170006. (!(row_info->color_type & PNG_COLOR_MASK_ALPHA) ||
  170007. (row_info->color_type != PNG_COLOR_TYPE_PALETTE && trans_values)))
  170008. {
  170009. switch (row_info->color_type)
  170010. {
  170011. case PNG_COLOR_TYPE_GRAY:
  170012. {
  170013. switch (row_info->bit_depth)
  170014. {
  170015. case 1:
  170016. {
  170017. sp = row;
  170018. shift = 7;
  170019. for (i = 0; i < row_width; i++)
  170020. {
  170021. if ((png_uint_16)((*sp >> shift) & 0x01)
  170022. == trans_values->gray)
  170023. {
  170024. *sp &= (png_byte)((0x7f7f >> (7 - shift)) & 0xff);
  170025. *sp |= (png_byte)(background->gray << shift);
  170026. }
  170027. if (!shift)
  170028. {
  170029. shift = 7;
  170030. sp++;
  170031. }
  170032. else
  170033. shift--;
  170034. }
  170035. break;
  170036. }
  170037. case 2:
  170038. {
  170039. #if defined(PNG_READ_GAMMA_SUPPORTED)
  170040. if (gamma_table != NULL)
  170041. {
  170042. sp = row;
  170043. shift = 6;
  170044. for (i = 0; i < row_width; i++)
  170045. {
  170046. if ((png_uint_16)((*sp >> shift) & 0x03)
  170047. == trans_values->gray)
  170048. {
  170049. *sp &= (png_byte)((0x3f3f >> (6 - shift)) & 0xff);
  170050. *sp |= (png_byte)(background->gray << shift);
  170051. }
  170052. else
  170053. {
  170054. png_byte p = (png_byte)((*sp >> shift) & 0x03);
  170055. png_byte g = (png_byte)((gamma_table [p | (p << 2) |
  170056. (p << 4) | (p << 6)] >> 6) & 0x03);
  170057. *sp &= (png_byte)((0x3f3f >> (6 - shift)) & 0xff);
  170058. *sp |= (png_byte)(g << shift);
  170059. }
  170060. if (!shift)
  170061. {
  170062. shift = 6;
  170063. sp++;
  170064. }
  170065. else
  170066. shift -= 2;
  170067. }
  170068. }
  170069. else
  170070. #endif
  170071. {
  170072. sp = row;
  170073. shift = 6;
  170074. for (i = 0; i < row_width; i++)
  170075. {
  170076. if ((png_uint_16)((*sp >> shift) & 0x03)
  170077. == trans_values->gray)
  170078. {
  170079. *sp &= (png_byte)((0x3f3f >> (6 - shift)) & 0xff);
  170080. *sp |= (png_byte)(background->gray << shift);
  170081. }
  170082. if (!shift)
  170083. {
  170084. shift = 6;
  170085. sp++;
  170086. }
  170087. else
  170088. shift -= 2;
  170089. }
  170090. }
  170091. break;
  170092. }
  170093. case 4:
  170094. {
  170095. #if defined(PNG_READ_GAMMA_SUPPORTED)
  170096. if (gamma_table != NULL)
  170097. {
  170098. sp = row;
  170099. shift = 4;
  170100. for (i = 0; i < row_width; i++)
  170101. {
  170102. if ((png_uint_16)((*sp >> shift) & 0x0f)
  170103. == trans_values->gray)
  170104. {
  170105. *sp &= (png_byte)((0xf0f >> (4 - shift)) & 0xff);
  170106. *sp |= (png_byte)(background->gray << shift);
  170107. }
  170108. else
  170109. {
  170110. png_byte p = (png_byte)((*sp >> shift) & 0x0f);
  170111. png_byte g = (png_byte)((gamma_table[p |
  170112. (p << 4)] >> 4) & 0x0f);
  170113. *sp &= (png_byte)((0xf0f >> (4 - shift)) & 0xff);
  170114. *sp |= (png_byte)(g << shift);
  170115. }
  170116. if (!shift)
  170117. {
  170118. shift = 4;
  170119. sp++;
  170120. }
  170121. else
  170122. shift -= 4;
  170123. }
  170124. }
  170125. else
  170126. #endif
  170127. {
  170128. sp = row;
  170129. shift = 4;
  170130. for (i = 0; i < row_width; i++)
  170131. {
  170132. if ((png_uint_16)((*sp >> shift) & 0x0f)
  170133. == trans_values->gray)
  170134. {
  170135. *sp &= (png_byte)((0xf0f >> (4 - shift)) & 0xff);
  170136. *sp |= (png_byte)(background->gray << shift);
  170137. }
  170138. if (!shift)
  170139. {
  170140. shift = 4;
  170141. sp++;
  170142. }
  170143. else
  170144. shift -= 4;
  170145. }
  170146. }
  170147. break;
  170148. }
  170149. case 8:
  170150. {
  170151. #if defined(PNG_READ_GAMMA_SUPPORTED)
  170152. if (gamma_table != NULL)
  170153. {
  170154. sp = row;
  170155. for (i = 0; i < row_width; i++, sp++)
  170156. {
  170157. if (*sp == trans_values->gray)
  170158. {
  170159. *sp = (png_byte)background->gray;
  170160. }
  170161. else
  170162. {
  170163. *sp = gamma_table[*sp];
  170164. }
  170165. }
  170166. }
  170167. else
  170168. #endif
  170169. {
  170170. sp = row;
  170171. for (i = 0; i < row_width; i++, sp++)
  170172. {
  170173. if (*sp == trans_values->gray)
  170174. {
  170175. *sp = (png_byte)background->gray;
  170176. }
  170177. }
  170178. }
  170179. break;
  170180. }
  170181. case 16:
  170182. {
  170183. #if defined(PNG_READ_GAMMA_SUPPORTED)
  170184. if (gamma_16 != NULL)
  170185. {
  170186. sp = row;
  170187. for (i = 0; i < row_width; i++, sp += 2)
  170188. {
  170189. png_uint_16 v;
  170190. v = (png_uint_16)(((*sp) << 8) + *(sp + 1));
  170191. if (v == trans_values->gray)
  170192. {
  170193. *sp = (png_byte)((background->gray >> 8) & 0xff);
  170194. *(sp + 1) = (png_byte)(background->gray & 0xff);
  170195. }
  170196. else
  170197. {
  170198. v = gamma_16[*(sp + 1) >> gamma_shift][*sp];
  170199. *sp = (png_byte)((v >> 8) & 0xff);
  170200. *(sp + 1) = (png_byte)(v & 0xff);
  170201. }
  170202. }
  170203. }
  170204. else
  170205. #endif
  170206. {
  170207. sp = row;
  170208. for (i = 0; i < row_width; i++, sp += 2)
  170209. {
  170210. png_uint_16 v;
  170211. v = (png_uint_16)(((*sp) << 8) + *(sp + 1));
  170212. if (v == trans_values->gray)
  170213. {
  170214. *sp = (png_byte)((background->gray >> 8) & 0xff);
  170215. *(sp + 1) = (png_byte)(background->gray & 0xff);
  170216. }
  170217. }
  170218. }
  170219. break;
  170220. }
  170221. }
  170222. break;
  170223. }
  170224. case PNG_COLOR_TYPE_RGB:
  170225. {
  170226. if (row_info->bit_depth == 8)
  170227. {
  170228. #if defined(PNG_READ_GAMMA_SUPPORTED)
  170229. if (gamma_table != NULL)
  170230. {
  170231. sp = row;
  170232. for (i = 0; i < row_width; i++, sp += 3)
  170233. {
  170234. if (*sp == trans_values->red &&
  170235. *(sp + 1) == trans_values->green &&
  170236. *(sp + 2) == trans_values->blue)
  170237. {
  170238. *sp = (png_byte)background->red;
  170239. *(sp + 1) = (png_byte)background->green;
  170240. *(sp + 2) = (png_byte)background->blue;
  170241. }
  170242. else
  170243. {
  170244. *sp = gamma_table[*sp];
  170245. *(sp + 1) = gamma_table[*(sp + 1)];
  170246. *(sp + 2) = gamma_table[*(sp + 2)];
  170247. }
  170248. }
  170249. }
  170250. else
  170251. #endif
  170252. {
  170253. sp = row;
  170254. for (i = 0; i < row_width; i++, sp += 3)
  170255. {
  170256. if (*sp == trans_values->red &&
  170257. *(sp + 1) == trans_values->green &&
  170258. *(sp + 2) == trans_values->blue)
  170259. {
  170260. *sp = (png_byte)background->red;
  170261. *(sp + 1) = (png_byte)background->green;
  170262. *(sp + 2) = (png_byte)background->blue;
  170263. }
  170264. }
  170265. }
  170266. }
  170267. else /* if (row_info->bit_depth == 16) */
  170268. {
  170269. #if defined(PNG_READ_GAMMA_SUPPORTED)
  170270. if (gamma_16 != NULL)
  170271. {
  170272. sp = row;
  170273. for (i = 0; i < row_width; i++, sp += 6)
  170274. {
  170275. png_uint_16 r = (png_uint_16)(((*sp) << 8) + *(sp + 1));
  170276. png_uint_16 g = (png_uint_16)(((*(sp+2)) << 8) + *(sp+3));
  170277. png_uint_16 b = (png_uint_16)(((*(sp+4)) << 8) + *(sp+5));
  170278. if (r == trans_values->red && g == trans_values->green &&
  170279. b == trans_values->blue)
  170280. {
  170281. *sp = (png_byte)((background->red >> 8) & 0xff);
  170282. *(sp + 1) = (png_byte)(background->red & 0xff);
  170283. *(sp + 2) = (png_byte)((background->green >> 8) & 0xff);
  170284. *(sp + 3) = (png_byte)(background->green & 0xff);
  170285. *(sp + 4) = (png_byte)((background->blue >> 8) & 0xff);
  170286. *(sp + 5) = (png_byte)(background->blue & 0xff);
  170287. }
  170288. else
  170289. {
  170290. png_uint_16 v = gamma_16[*(sp + 1) >> gamma_shift][*sp];
  170291. *sp = (png_byte)((v >> 8) & 0xff);
  170292. *(sp + 1) = (png_byte)(v & 0xff);
  170293. v = gamma_16[*(sp + 3) >> gamma_shift][*(sp + 2)];
  170294. *(sp + 2) = (png_byte)((v >> 8) & 0xff);
  170295. *(sp + 3) = (png_byte)(v & 0xff);
  170296. v = gamma_16[*(sp + 5) >> gamma_shift][*(sp + 4)];
  170297. *(sp + 4) = (png_byte)((v >> 8) & 0xff);
  170298. *(sp + 5) = (png_byte)(v & 0xff);
  170299. }
  170300. }
  170301. }
  170302. else
  170303. #endif
  170304. {
  170305. sp = row;
  170306. for (i = 0; i < row_width; i++, sp += 6)
  170307. {
  170308. png_uint_16 r = (png_uint_16)(((*sp) << 8) + *(sp+1));
  170309. png_uint_16 g = (png_uint_16)(((*(sp+2)) << 8) + *(sp+3));
  170310. png_uint_16 b = (png_uint_16)(((*(sp+4)) << 8) + *(sp+5));
  170311. if (r == trans_values->red && g == trans_values->green &&
  170312. b == trans_values->blue)
  170313. {
  170314. *sp = (png_byte)((background->red >> 8) & 0xff);
  170315. *(sp + 1) = (png_byte)(background->red & 0xff);
  170316. *(sp + 2) = (png_byte)((background->green >> 8) & 0xff);
  170317. *(sp + 3) = (png_byte)(background->green & 0xff);
  170318. *(sp + 4) = (png_byte)((background->blue >> 8) & 0xff);
  170319. *(sp + 5) = (png_byte)(background->blue & 0xff);
  170320. }
  170321. }
  170322. }
  170323. }
  170324. break;
  170325. }
  170326. case PNG_COLOR_TYPE_GRAY_ALPHA:
  170327. {
  170328. if (row_info->bit_depth == 8)
  170329. {
  170330. #if defined(PNG_READ_GAMMA_SUPPORTED)
  170331. if (gamma_to_1 != NULL && gamma_from_1 != NULL &&
  170332. gamma_table != NULL)
  170333. {
  170334. sp = row;
  170335. dp = row;
  170336. for (i = 0; i < row_width; i++, sp += 2, dp++)
  170337. {
  170338. png_uint_16 a = *(sp + 1);
  170339. if (a == 0xff)
  170340. {
  170341. *dp = gamma_table[*sp];
  170342. }
  170343. else if (a == 0)
  170344. {
  170345. *dp = (png_byte)background->gray;
  170346. }
  170347. else
  170348. {
  170349. png_byte v, w;
  170350. v = gamma_to_1[*sp];
  170351. png_composite(w, v, a, background_1->gray);
  170352. *dp = gamma_from_1[w];
  170353. }
  170354. }
  170355. }
  170356. else
  170357. #endif
  170358. {
  170359. sp = row;
  170360. dp = row;
  170361. for (i = 0; i < row_width; i++, sp += 2, dp++)
  170362. {
  170363. png_byte a = *(sp + 1);
  170364. if (a == 0xff)
  170365. {
  170366. *dp = *sp;
  170367. }
  170368. #if defined(PNG_READ_GAMMA_SUPPORTED)
  170369. else if (a == 0)
  170370. {
  170371. *dp = (png_byte)background->gray;
  170372. }
  170373. else
  170374. {
  170375. png_composite(*dp, *sp, a, background_1->gray);
  170376. }
  170377. #else
  170378. *dp = (png_byte)background->gray;
  170379. #endif
  170380. }
  170381. }
  170382. }
  170383. else /* if (png_ptr->bit_depth == 16) */
  170384. {
  170385. #if defined(PNG_READ_GAMMA_SUPPORTED)
  170386. if (gamma_16 != NULL && gamma_16_from_1 != NULL &&
  170387. gamma_16_to_1 != NULL)
  170388. {
  170389. sp = row;
  170390. dp = row;
  170391. for (i = 0; i < row_width; i++, sp += 4, dp += 2)
  170392. {
  170393. png_uint_16 a = (png_uint_16)(((*(sp+2)) << 8) + *(sp+3));
  170394. if (a == (png_uint_16)0xffff)
  170395. {
  170396. png_uint_16 v;
  170397. v = gamma_16[*(sp + 1) >> gamma_shift][*sp];
  170398. *dp = (png_byte)((v >> 8) & 0xff);
  170399. *(dp + 1) = (png_byte)(v & 0xff);
  170400. }
  170401. #if defined(PNG_READ_GAMMA_SUPPORTED)
  170402. else if (a == 0)
  170403. #else
  170404. else
  170405. #endif
  170406. {
  170407. *dp = (png_byte)((background->gray >> 8) & 0xff);
  170408. *(dp + 1) = (png_byte)(background->gray & 0xff);
  170409. }
  170410. #if defined(PNG_READ_GAMMA_SUPPORTED)
  170411. else
  170412. {
  170413. png_uint_16 g, v, w;
  170414. g = gamma_16_to_1[*(sp + 1) >> gamma_shift][*sp];
  170415. png_composite_16(v, g, a, background_1->gray);
  170416. w = gamma_16_from_1[(v&0xff) >> gamma_shift][v >> 8];
  170417. *dp = (png_byte)((w >> 8) & 0xff);
  170418. *(dp + 1) = (png_byte)(w & 0xff);
  170419. }
  170420. #endif
  170421. }
  170422. }
  170423. else
  170424. #endif
  170425. {
  170426. sp = row;
  170427. dp = row;
  170428. for (i = 0; i < row_width; i++, sp += 4, dp += 2)
  170429. {
  170430. png_uint_16 a = (png_uint_16)(((*(sp+2)) << 8) + *(sp+3));
  170431. if (a == (png_uint_16)0xffff)
  170432. {
  170433. png_memcpy(dp, sp, 2);
  170434. }
  170435. #if defined(PNG_READ_GAMMA_SUPPORTED)
  170436. else if (a == 0)
  170437. #else
  170438. else
  170439. #endif
  170440. {
  170441. *dp = (png_byte)((background->gray >> 8) & 0xff);
  170442. *(dp + 1) = (png_byte)(background->gray & 0xff);
  170443. }
  170444. #if defined(PNG_READ_GAMMA_SUPPORTED)
  170445. else
  170446. {
  170447. png_uint_16 g, v;
  170448. g = (png_uint_16)(((*sp) << 8) + *(sp + 1));
  170449. png_composite_16(v, g, a, background_1->gray);
  170450. *dp = (png_byte)((v >> 8) & 0xff);
  170451. *(dp + 1) = (png_byte)(v & 0xff);
  170452. }
  170453. #endif
  170454. }
  170455. }
  170456. }
  170457. break;
  170458. }
  170459. case PNG_COLOR_TYPE_RGB_ALPHA:
  170460. {
  170461. if (row_info->bit_depth == 8)
  170462. {
  170463. #if defined(PNG_READ_GAMMA_SUPPORTED)
  170464. if (gamma_to_1 != NULL && gamma_from_1 != NULL &&
  170465. gamma_table != NULL)
  170466. {
  170467. sp = row;
  170468. dp = row;
  170469. for (i = 0; i < row_width; i++, sp += 4, dp += 3)
  170470. {
  170471. png_byte a = *(sp + 3);
  170472. if (a == 0xff)
  170473. {
  170474. *dp = gamma_table[*sp];
  170475. *(dp + 1) = gamma_table[*(sp + 1)];
  170476. *(dp + 2) = gamma_table[*(sp + 2)];
  170477. }
  170478. else if (a == 0)
  170479. {
  170480. *dp = (png_byte)background->red;
  170481. *(dp + 1) = (png_byte)background->green;
  170482. *(dp + 2) = (png_byte)background->blue;
  170483. }
  170484. else
  170485. {
  170486. png_byte v, w;
  170487. v = gamma_to_1[*sp];
  170488. png_composite(w, v, a, background_1->red);
  170489. *dp = gamma_from_1[w];
  170490. v = gamma_to_1[*(sp + 1)];
  170491. png_composite(w, v, a, background_1->green);
  170492. *(dp + 1) = gamma_from_1[w];
  170493. v = gamma_to_1[*(sp + 2)];
  170494. png_composite(w, v, a, background_1->blue);
  170495. *(dp + 2) = gamma_from_1[w];
  170496. }
  170497. }
  170498. }
  170499. else
  170500. #endif
  170501. {
  170502. sp = row;
  170503. dp = row;
  170504. for (i = 0; i < row_width; i++, sp += 4, dp += 3)
  170505. {
  170506. png_byte a = *(sp + 3);
  170507. if (a == 0xff)
  170508. {
  170509. *dp = *sp;
  170510. *(dp + 1) = *(sp + 1);
  170511. *(dp + 2) = *(sp + 2);
  170512. }
  170513. else if (a == 0)
  170514. {
  170515. *dp = (png_byte)background->red;
  170516. *(dp + 1) = (png_byte)background->green;
  170517. *(dp + 2) = (png_byte)background->blue;
  170518. }
  170519. else
  170520. {
  170521. png_composite(*dp, *sp, a, background->red);
  170522. png_composite(*(dp + 1), *(sp + 1), a,
  170523. background->green);
  170524. png_composite(*(dp + 2), *(sp + 2), a,
  170525. background->blue);
  170526. }
  170527. }
  170528. }
  170529. }
  170530. else /* if (row_info->bit_depth == 16) */
  170531. {
  170532. #if defined(PNG_READ_GAMMA_SUPPORTED)
  170533. if (gamma_16 != NULL && gamma_16_from_1 != NULL &&
  170534. gamma_16_to_1 != NULL)
  170535. {
  170536. sp = row;
  170537. dp = row;
  170538. for (i = 0; i < row_width; i++, sp += 8, dp += 6)
  170539. {
  170540. png_uint_16 a = (png_uint_16)(((png_uint_16)(*(sp + 6))
  170541. << 8) + (png_uint_16)(*(sp + 7)));
  170542. if (a == (png_uint_16)0xffff)
  170543. {
  170544. png_uint_16 v;
  170545. v = gamma_16[*(sp + 1) >> gamma_shift][*sp];
  170546. *dp = (png_byte)((v >> 8) & 0xff);
  170547. *(dp + 1) = (png_byte)(v & 0xff);
  170548. v = gamma_16[*(sp + 3) >> gamma_shift][*(sp + 2)];
  170549. *(dp + 2) = (png_byte)((v >> 8) & 0xff);
  170550. *(dp + 3) = (png_byte)(v & 0xff);
  170551. v = gamma_16[*(sp + 5) >> gamma_shift][*(sp + 4)];
  170552. *(dp + 4) = (png_byte)((v >> 8) & 0xff);
  170553. *(dp + 5) = (png_byte)(v & 0xff);
  170554. }
  170555. else if (a == 0)
  170556. {
  170557. *dp = (png_byte)((background->red >> 8) & 0xff);
  170558. *(dp + 1) = (png_byte)(background->red & 0xff);
  170559. *(dp + 2) = (png_byte)((background->green >> 8) & 0xff);
  170560. *(dp + 3) = (png_byte)(background->green & 0xff);
  170561. *(dp + 4) = (png_byte)((background->blue >> 8) & 0xff);
  170562. *(dp + 5) = (png_byte)(background->blue & 0xff);
  170563. }
  170564. else
  170565. {
  170566. png_uint_16 v, w, x;
  170567. v = gamma_16_to_1[*(sp + 1) >> gamma_shift][*sp];
  170568. png_composite_16(w, v, a, background_1->red);
  170569. x = gamma_16_from_1[((w&0xff) >> gamma_shift)][w >> 8];
  170570. *dp = (png_byte)((x >> 8) & 0xff);
  170571. *(dp + 1) = (png_byte)(x & 0xff);
  170572. v = gamma_16_to_1[*(sp + 3) >> gamma_shift][*(sp + 2)];
  170573. png_composite_16(w, v, a, background_1->green);
  170574. x = gamma_16_from_1[((w&0xff) >> gamma_shift)][w >> 8];
  170575. *(dp + 2) = (png_byte)((x >> 8) & 0xff);
  170576. *(dp + 3) = (png_byte)(x & 0xff);
  170577. v = gamma_16_to_1[*(sp + 5) >> gamma_shift][*(sp + 4)];
  170578. png_composite_16(w, v, a, background_1->blue);
  170579. x = gamma_16_from_1[(w & 0xff) >> gamma_shift][w >> 8];
  170580. *(dp + 4) = (png_byte)((x >> 8) & 0xff);
  170581. *(dp + 5) = (png_byte)(x & 0xff);
  170582. }
  170583. }
  170584. }
  170585. else
  170586. #endif
  170587. {
  170588. sp = row;
  170589. dp = row;
  170590. for (i = 0; i < row_width; i++, sp += 8, dp += 6)
  170591. {
  170592. png_uint_16 a = (png_uint_16)(((png_uint_16)(*(sp + 6))
  170593. << 8) + (png_uint_16)(*(sp + 7)));
  170594. if (a == (png_uint_16)0xffff)
  170595. {
  170596. png_memcpy(dp, sp, 6);
  170597. }
  170598. else if (a == 0)
  170599. {
  170600. *dp = (png_byte)((background->red >> 8) & 0xff);
  170601. *(dp + 1) = (png_byte)(background->red & 0xff);
  170602. *(dp + 2) = (png_byte)((background->green >> 8) & 0xff);
  170603. *(dp + 3) = (png_byte)(background->green & 0xff);
  170604. *(dp + 4) = (png_byte)((background->blue >> 8) & 0xff);
  170605. *(dp + 5) = (png_byte)(background->blue & 0xff);
  170606. }
  170607. else
  170608. {
  170609. png_uint_16 v;
  170610. png_uint_16 r = (png_uint_16)(((*sp) << 8) + *(sp + 1));
  170611. png_uint_16 g = (png_uint_16)(((*(sp + 2)) << 8)
  170612. + *(sp + 3));
  170613. png_uint_16 b = (png_uint_16)(((*(sp + 4)) << 8)
  170614. + *(sp + 5));
  170615. png_composite_16(v, r, a, background->red);
  170616. *dp = (png_byte)((v >> 8) & 0xff);
  170617. *(dp + 1) = (png_byte)(v & 0xff);
  170618. png_composite_16(v, g, a, background->green);
  170619. *(dp + 2) = (png_byte)((v >> 8) & 0xff);
  170620. *(dp + 3) = (png_byte)(v & 0xff);
  170621. png_composite_16(v, b, a, background->blue);
  170622. *(dp + 4) = (png_byte)((v >> 8) & 0xff);
  170623. *(dp + 5) = (png_byte)(v & 0xff);
  170624. }
  170625. }
  170626. }
  170627. }
  170628. break;
  170629. }
  170630. }
  170631. if (row_info->color_type & PNG_COLOR_MASK_ALPHA)
  170632. {
  170633. row_info->color_type &= ~PNG_COLOR_MASK_ALPHA;
  170634. row_info->channels--;
  170635. row_info->pixel_depth = (png_byte)(row_info->channels *
  170636. row_info->bit_depth);
  170637. row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,row_width);
  170638. }
  170639. }
  170640. }
  170641. #endif
  170642. #if defined(PNG_READ_GAMMA_SUPPORTED)
  170643. void /* PRIVATE */
  170644. png_do_gamma(png_row_infop row_info, png_bytep row,
  170645. png_bytep gamma_table, png_uint_16pp gamma_16_table,
  170646. int gamma_shift)
  170647. {
  170648. png_bytep sp;
  170649. png_uint_32 i;
  170650. png_uint_32 row_width=row_info->width;
  170651. png_debug(1, "in png_do_gamma\n");
  170652. if (
  170653. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  170654. row != NULL && row_info != NULL &&
  170655. #endif
  170656. ((row_info->bit_depth <= 8 && gamma_table != NULL) ||
  170657. (row_info->bit_depth == 16 && gamma_16_table != NULL)))
  170658. {
  170659. switch (row_info->color_type)
  170660. {
  170661. case PNG_COLOR_TYPE_RGB:
  170662. {
  170663. if (row_info->bit_depth == 8)
  170664. {
  170665. sp = row;
  170666. for (i = 0; i < row_width; i++)
  170667. {
  170668. *sp = gamma_table[*sp];
  170669. sp++;
  170670. *sp = gamma_table[*sp];
  170671. sp++;
  170672. *sp = gamma_table[*sp];
  170673. sp++;
  170674. }
  170675. }
  170676. else /* if (row_info->bit_depth == 16) */
  170677. {
  170678. sp = row;
  170679. for (i = 0; i < row_width; i++)
  170680. {
  170681. png_uint_16 v;
  170682. v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp];
  170683. *sp = (png_byte)((v >> 8) & 0xff);
  170684. *(sp + 1) = (png_byte)(v & 0xff);
  170685. sp += 2;
  170686. v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp];
  170687. *sp = (png_byte)((v >> 8) & 0xff);
  170688. *(sp + 1) = (png_byte)(v & 0xff);
  170689. sp += 2;
  170690. v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp];
  170691. *sp = (png_byte)((v >> 8) & 0xff);
  170692. *(sp + 1) = (png_byte)(v & 0xff);
  170693. sp += 2;
  170694. }
  170695. }
  170696. break;
  170697. }
  170698. case PNG_COLOR_TYPE_RGB_ALPHA:
  170699. {
  170700. if (row_info->bit_depth == 8)
  170701. {
  170702. sp = row;
  170703. for (i = 0; i < row_width; i++)
  170704. {
  170705. *sp = gamma_table[*sp];
  170706. sp++;
  170707. *sp = gamma_table[*sp];
  170708. sp++;
  170709. *sp = gamma_table[*sp];
  170710. sp++;
  170711. sp++;
  170712. }
  170713. }
  170714. else /* if (row_info->bit_depth == 16) */
  170715. {
  170716. sp = row;
  170717. for (i = 0; i < row_width; i++)
  170718. {
  170719. png_uint_16 v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp];
  170720. *sp = (png_byte)((v >> 8) & 0xff);
  170721. *(sp + 1) = (png_byte)(v & 0xff);
  170722. sp += 2;
  170723. v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp];
  170724. *sp = (png_byte)((v >> 8) & 0xff);
  170725. *(sp + 1) = (png_byte)(v & 0xff);
  170726. sp += 2;
  170727. v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp];
  170728. *sp = (png_byte)((v >> 8) & 0xff);
  170729. *(sp + 1) = (png_byte)(v & 0xff);
  170730. sp += 4;
  170731. }
  170732. }
  170733. break;
  170734. }
  170735. case PNG_COLOR_TYPE_GRAY_ALPHA:
  170736. {
  170737. if (row_info->bit_depth == 8)
  170738. {
  170739. sp = row;
  170740. for (i = 0; i < row_width; i++)
  170741. {
  170742. *sp = gamma_table[*sp];
  170743. sp += 2;
  170744. }
  170745. }
  170746. else /* if (row_info->bit_depth == 16) */
  170747. {
  170748. sp = row;
  170749. for (i = 0; i < row_width; i++)
  170750. {
  170751. png_uint_16 v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp];
  170752. *sp = (png_byte)((v >> 8) & 0xff);
  170753. *(sp + 1) = (png_byte)(v & 0xff);
  170754. sp += 4;
  170755. }
  170756. }
  170757. break;
  170758. }
  170759. case PNG_COLOR_TYPE_GRAY:
  170760. {
  170761. if (row_info->bit_depth == 2)
  170762. {
  170763. sp = row;
  170764. for (i = 0; i < row_width; i += 4)
  170765. {
  170766. int a = *sp & 0xc0;
  170767. int b = *sp & 0x30;
  170768. int c = *sp & 0x0c;
  170769. int d = *sp & 0x03;
  170770. *sp = (png_byte)(
  170771. ((((int)gamma_table[a|(a>>2)|(a>>4)|(a>>6)]) ) & 0xc0)|
  170772. ((((int)gamma_table[(b<<2)|b|(b>>2)|(b>>4)])>>2) & 0x30)|
  170773. ((((int)gamma_table[(c<<4)|(c<<2)|c|(c>>2)])>>4) & 0x0c)|
  170774. ((((int)gamma_table[(d<<6)|(d<<4)|(d<<2)|d])>>6) ));
  170775. sp++;
  170776. }
  170777. }
  170778. if (row_info->bit_depth == 4)
  170779. {
  170780. sp = row;
  170781. for (i = 0; i < row_width; i += 2)
  170782. {
  170783. int msb = *sp & 0xf0;
  170784. int lsb = *sp & 0x0f;
  170785. *sp = (png_byte)((((int)gamma_table[msb | (msb >> 4)]) & 0xf0)
  170786. | (((int)gamma_table[(lsb << 4) | lsb]) >> 4));
  170787. sp++;
  170788. }
  170789. }
  170790. else if (row_info->bit_depth == 8)
  170791. {
  170792. sp = row;
  170793. for (i = 0; i < row_width; i++)
  170794. {
  170795. *sp = gamma_table[*sp];
  170796. sp++;
  170797. }
  170798. }
  170799. else if (row_info->bit_depth == 16)
  170800. {
  170801. sp = row;
  170802. for (i = 0; i < row_width; i++)
  170803. {
  170804. png_uint_16 v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp];
  170805. *sp = (png_byte)((v >> 8) & 0xff);
  170806. *(sp + 1) = (png_byte)(v & 0xff);
  170807. sp += 2;
  170808. }
  170809. }
  170810. break;
  170811. }
  170812. }
  170813. }
  170814. }
  170815. #endif
  170816. #if defined(PNG_READ_EXPAND_SUPPORTED)
  170817. void /* PRIVATE */
  170818. png_do_expand_palette(png_row_infop row_info, png_bytep row,
  170819. png_colorp palette, png_bytep trans, int num_trans)
  170820. {
  170821. int shift, value;
  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_expand_palette\n");
  170826. if (
  170827. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  170828. row != NULL && row_info != NULL &&
  170829. #endif
  170830. row_info->color_type == PNG_COLOR_TYPE_PALETTE)
  170831. {
  170832. if (row_info->bit_depth < 8)
  170833. {
  170834. switch (row_info->bit_depth)
  170835. {
  170836. case 1:
  170837. {
  170838. sp = row + (png_size_t)((row_width - 1) >> 3);
  170839. dp = row + (png_size_t)row_width - 1;
  170840. shift = 7 - (int)((row_width + 7) & 0x07);
  170841. for (i = 0; i < row_width; i++)
  170842. {
  170843. if ((*sp >> shift) & 0x01)
  170844. *dp = 1;
  170845. else
  170846. *dp = 0;
  170847. if (shift == 7)
  170848. {
  170849. shift = 0;
  170850. sp--;
  170851. }
  170852. else
  170853. shift++;
  170854. dp--;
  170855. }
  170856. break;
  170857. }
  170858. case 2:
  170859. {
  170860. sp = row + (png_size_t)((row_width - 1) >> 2);
  170861. dp = row + (png_size_t)row_width - 1;
  170862. shift = (int)((3 - ((row_width + 3) & 0x03)) << 1);
  170863. for (i = 0; i < row_width; i++)
  170864. {
  170865. value = (*sp >> shift) & 0x03;
  170866. *dp = (png_byte)value;
  170867. if (shift == 6)
  170868. {
  170869. shift = 0;
  170870. sp--;
  170871. }
  170872. else
  170873. shift += 2;
  170874. dp--;
  170875. }
  170876. break;
  170877. }
  170878. case 4:
  170879. {
  170880. sp = row + (png_size_t)((row_width - 1) >> 1);
  170881. dp = row + (png_size_t)row_width - 1;
  170882. shift = (int)((row_width & 0x01) << 2);
  170883. for (i = 0; i < row_width; i++)
  170884. {
  170885. value = (*sp >> shift) & 0x0f;
  170886. *dp = (png_byte)value;
  170887. if (shift == 4)
  170888. {
  170889. shift = 0;
  170890. sp--;
  170891. }
  170892. else
  170893. shift += 4;
  170894. dp--;
  170895. }
  170896. break;
  170897. }
  170898. }
  170899. row_info->bit_depth = 8;
  170900. row_info->pixel_depth = 8;
  170901. row_info->rowbytes = row_width;
  170902. }
  170903. switch (row_info->bit_depth)
  170904. {
  170905. case 8:
  170906. {
  170907. if (trans != NULL)
  170908. {
  170909. sp = row + (png_size_t)row_width - 1;
  170910. dp = row + (png_size_t)(row_width << 2) - 1;
  170911. for (i = 0; i < row_width; i++)
  170912. {
  170913. if ((int)(*sp) >= num_trans)
  170914. *dp-- = 0xff;
  170915. else
  170916. *dp-- = trans[*sp];
  170917. *dp-- = palette[*sp].blue;
  170918. *dp-- = palette[*sp].green;
  170919. *dp-- = palette[*sp].red;
  170920. sp--;
  170921. }
  170922. row_info->bit_depth = 8;
  170923. row_info->pixel_depth = 32;
  170924. row_info->rowbytes = row_width * 4;
  170925. row_info->color_type = 6;
  170926. row_info->channels = 4;
  170927. }
  170928. else
  170929. {
  170930. sp = row + (png_size_t)row_width - 1;
  170931. dp = row + (png_size_t)(row_width * 3) - 1;
  170932. for (i = 0; i < row_width; i++)
  170933. {
  170934. *dp-- = palette[*sp].blue;
  170935. *dp-- = palette[*sp].green;
  170936. *dp-- = palette[*sp].red;
  170937. sp--;
  170938. }
  170939. row_info->bit_depth = 8;
  170940. row_info->pixel_depth = 24;
  170941. row_info->rowbytes = row_width * 3;
  170942. row_info->color_type = 2;
  170943. row_info->channels = 3;
  170944. }
  170945. break;
  170946. }
  170947. }
  170948. }
  170949. }
  170950. void /* PRIVATE */
  170951. png_do_expand(png_row_infop row_info, png_bytep row,
  170952. png_color_16p trans_value)
  170953. {
  170954. int shift, value;
  170955. png_bytep sp, dp;
  170956. png_uint_32 i;
  170957. png_uint_32 row_width=row_info->width;
  170958. png_debug(1, "in png_do_expand\n");
  170959. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  170960. if (row != NULL && row_info != NULL)
  170961. #endif
  170962. {
  170963. if (row_info->color_type == PNG_COLOR_TYPE_GRAY)
  170964. {
  170965. png_uint_16 gray = (png_uint_16)(trans_value ? trans_value->gray : 0);
  170966. if (row_info->bit_depth < 8)
  170967. {
  170968. switch (row_info->bit_depth)
  170969. {
  170970. case 1:
  170971. {
  170972. gray = (png_uint_16)((gray&0x01)*0xff);
  170973. sp = row + (png_size_t)((row_width - 1) >> 3);
  170974. dp = row + (png_size_t)row_width - 1;
  170975. shift = 7 - (int)((row_width + 7) & 0x07);
  170976. for (i = 0; i < row_width; i++)
  170977. {
  170978. if ((*sp >> shift) & 0x01)
  170979. *dp = 0xff;
  170980. else
  170981. *dp = 0;
  170982. if (shift == 7)
  170983. {
  170984. shift = 0;
  170985. sp--;
  170986. }
  170987. else
  170988. shift++;
  170989. dp--;
  170990. }
  170991. break;
  170992. }
  170993. case 2:
  170994. {
  170995. gray = (png_uint_16)((gray&0x03)*0x55);
  170996. sp = row + (png_size_t)((row_width - 1) >> 2);
  170997. dp = row + (png_size_t)row_width - 1;
  170998. shift = (int)((3 - ((row_width + 3) & 0x03)) << 1);
  170999. for (i = 0; i < row_width; i++)
  171000. {
  171001. value = (*sp >> shift) & 0x03;
  171002. *dp = (png_byte)(value | (value << 2) | (value << 4) |
  171003. (value << 6));
  171004. if (shift == 6)
  171005. {
  171006. shift = 0;
  171007. sp--;
  171008. }
  171009. else
  171010. shift += 2;
  171011. dp--;
  171012. }
  171013. break;
  171014. }
  171015. case 4:
  171016. {
  171017. gray = (png_uint_16)((gray&0x0f)*0x11);
  171018. sp = row + (png_size_t)((row_width - 1) >> 1);
  171019. dp = row + (png_size_t)row_width - 1;
  171020. shift = (int)((1 - ((row_width + 1) & 0x01)) << 2);
  171021. for (i = 0; i < row_width; i++)
  171022. {
  171023. value = (*sp >> shift) & 0x0f;
  171024. *dp = (png_byte)(value | (value << 4));
  171025. if (shift == 4)
  171026. {
  171027. shift = 0;
  171028. sp--;
  171029. }
  171030. else
  171031. shift = 4;
  171032. dp--;
  171033. }
  171034. break;
  171035. }
  171036. }
  171037. row_info->bit_depth = 8;
  171038. row_info->pixel_depth = 8;
  171039. row_info->rowbytes = row_width;
  171040. }
  171041. if (trans_value != NULL)
  171042. {
  171043. if (row_info->bit_depth == 8)
  171044. {
  171045. gray = gray & 0xff;
  171046. sp = row + (png_size_t)row_width - 1;
  171047. dp = row + (png_size_t)(row_width << 1) - 1;
  171048. for (i = 0; i < row_width; i++)
  171049. {
  171050. if (*sp == gray)
  171051. *dp-- = 0;
  171052. else
  171053. *dp-- = 0xff;
  171054. *dp-- = *sp--;
  171055. }
  171056. }
  171057. else if (row_info->bit_depth == 16)
  171058. {
  171059. png_byte gray_high = (gray >> 8) & 0xff;
  171060. png_byte gray_low = gray & 0xff;
  171061. sp = row + row_info->rowbytes - 1;
  171062. dp = row + (row_info->rowbytes << 1) - 1;
  171063. for (i = 0; i < row_width; i++)
  171064. {
  171065. if (*(sp-1) == gray_high && *(sp) == gray_low)
  171066. {
  171067. *dp-- = 0;
  171068. *dp-- = 0;
  171069. }
  171070. else
  171071. {
  171072. *dp-- = 0xff;
  171073. *dp-- = 0xff;
  171074. }
  171075. *dp-- = *sp--;
  171076. *dp-- = *sp--;
  171077. }
  171078. }
  171079. row_info->color_type = PNG_COLOR_TYPE_GRAY_ALPHA;
  171080. row_info->channels = 2;
  171081. row_info->pixel_depth = (png_byte)(row_info->bit_depth << 1);
  171082. row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,
  171083. row_width);
  171084. }
  171085. }
  171086. else if (row_info->color_type == PNG_COLOR_TYPE_RGB && trans_value)
  171087. {
  171088. if (row_info->bit_depth == 8)
  171089. {
  171090. png_byte red = trans_value->red & 0xff;
  171091. png_byte green = trans_value->green & 0xff;
  171092. png_byte blue = trans_value->blue & 0xff;
  171093. sp = row + (png_size_t)row_info->rowbytes - 1;
  171094. dp = row + (png_size_t)(row_width << 2) - 1;
  171095. for (i = 0; i < row_width; i++)
  171096. {
  171097. if (*(sp - 2) == red && *(sp - 1) == green && *(sp) == blue)
  171098. *dp-- = 0;
  171099. else
  171100. *dp-- = 0xff;
  171101. *dp-- = *sp--;
  171102. *dp-- = *sp--;
  171103. *dp-- = *sp--;
  171104. }
  171105. }
  171106. else if (row_info->bit_depth == 16)
  171107. {
  171108. png_byte red_high = (trans_value->red >> 8) & 0xff;
  171109. png_byte green_high = (trans_value->green >> 8) & 0xff;
  171110. png_byte blue_high = (trans_value->blue >> 8) & 0xff;
  171111. png_byte red_low = trans_value->red & 0xff;
  171112. png_byte green_low = trans_value->green & 0xff;
  171113. png_byte blue_low = trans_value->blue & 0xff;
  171114. sp = row + row_info->rowbytes - 1;
  171115. dp = row + (png_size_t)(row_width << 3) - 1;
  171116. for (i = 0; i < row_width; i++)
  171117. {
  171118. if (*(sp - 5) == red_high &&
  171119. *(sp - 4) == red_low &&
  171120. *(sp - 3) == green_high &&
  171121. *(sp - 2) == green_low &&
  171122. *(sp - 1) == blue_high &&
  171123. *(sp ) == blue_low)
  171124. {
  171125. *dp-- = 0;
  171126. *dp-- = 0;
  171127. }
  171128. else
  171129. {
  171130. *dp-- = 0xff;
  171131. *dp-- = 0xff;
  171132. }
  171133. *dp-- = *sp--;
  171134. *dp-- = *sp--;
  171135. *dp-- = *sp--;
  171136. *dp-- = *sp--;
  171137. *dp-- = *sp--;
  171138. *dp-- = *sp--;
  171139. }
  171140. }
  171141. row_info->color_type = PNG_COLOR_TYPE_RGB_ALPHA;
  171142. row_info->channels = 4;
  171143. row_info->pixel_depth = (png_byte)(row_info->bit_depth << 2);
  171144. row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,row_width);
  171145. }
  171146. }
  171147. }
  171148. #endif
  171149. #if defined(PNG_READ_DITHER_SUPPORTED)
  171150. void /* PRIVATE */
  171151. png_do_dither(png_row_infop row_info, png_bytep row,
  171152. png_bytep palette_lookup, png_bytep dither_lookup)
  171153. {
  171154. png_bytep sp, dp;
  171155. png_uint_32 i;
  171156. png_uint_32 row_width=row_info->width;
  171157. png_debug(1, "in png_do_dither\n");
  171158. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  171159. if (row != NULL && row_info != NULL)
  171160. #endif
  171161. {
  171162. if (row_info->color_type == PNG_COLOR_TYPE_RGB &&
  171163. palette_lookup && row_info->bit_depth == 8)
  171164. {
  171165. int r, g, b, p;
  171166. sp = row;
  171167. dp = row;
  171168. for (i = 0; i < row_width; i++)
  171169. {
  171170. r = *sp++;
  171171. g = *sp++;
  171172. b = *sp++;
  171173. p = (((r >> (8 - PNG_DITHER_RED_BITS)) &
  171174. ((1 << PNG_DITHER_RED_BITS) - 1)) <<
  171175. (PNG_DITHER_GREEN_BITS + PNG_DITHER_BLUE_BITS)) |
  171176. (((g >> (8 - PNG_DITHER_GREEN_BITS)) &
  171177. ((1 << PNG_DITHER_GREEN_BITS) - 1)) <<
  171178. (PNG_DITHER_BLUE_BITS)) |
  171179. ((b >> (8 - PNG_DITHER_BLUE_BITS)) &
  171180. ((1 << PNG_DITHER_BLUE_BITS) - 1));
  171181. *dp++ = palette_lookup[p];
  171182. }
  171183. row_info->color_type = PNG_COLOR_TYPE_PALETTE;
  171184. row_info->channels = 1;
  171185. row_info->pixel_depth = row_info->bit_depth;
  171186. row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,row_width);
  171187. }
  171188. else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA &&
  171189. palette_lookup != NULL && row_info->bit_depth == 8)
  171190. {
  171191. int r, g, b, p;
  171192. sp = row;
  171193. dp = row;
  171194. for (i = 0; i < row_width; i++)
  171195. {
  171196. r = *sp++;
  171197. g = *sp++;
  171198. b = *sp++;
  171199. sp++;
  171200. p = (((r >> (8 - PNG_DITHER_RED_BITS)) &
  171201. ((1 << PNG_DITHER_RED_BITS) - 1)) <<
  171202. (PNG_DITHER_GREEN_BITS + PNG_DITHER_BLUE_BITS)) |
  171203. (((g >> (8 - PNG_DITHER_GREEN_BITS)) &
  171204. ((1 << PNG_DITHER_GREEN_BITS) - 1)) <<
  171205. (PNG_DITHER_BLUE_BITS)) |
  171206. ((b >> (8 - PNG_DITHER_BLUE_BITS)) &
  171207. ((1 << PNG_DITHER_BLUE_BITS) - 1));
  171208. *dp++ = palette_lookup[p];
  171209. }
  171210. row_info->color_type = PNG_COLOR_TYPE_PALETTE;
  171211. row_info->channels = 1;
  171212. row_info->pixel_depth = row_info->bit_depth;
  171213. row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,row_width);
  171214. }
  171215. else if (row_info->color_type == PNG_COLOR_TYPE_PALETTE &&
  171216. dither_lookup && row_info->bit_depth == 8)
  171217. {
  171218. sp = row;
  171219. for (i = 0; i < row_width; i++, sp++)
  171220. {
  171221. *sp = dither_lookup[*sp];
  171222. }
  171223. }
  171224. }
  171225. }
  171226. #endif
  171227. #ifdef PNG_FLOATING_POINT_SUPPORTED
  171228. #if defined(PNG_READ_GAMMA_SUPPORTED)
  171229. static PNG_CONST int png_gamma_shift[] =
  171230. {0x10, 0x21, 0x42, 0x84, 0x110, 0x248, 0x550, 0xff0, 0x00};
  171231. void /* PRIVATE */
  171232. png_build_gamma_table(png_structp png_ptr)
  171233. {
  171234. png_debug(1, "in png_build_gamma_table\n");
  171235. if (png_ptr->bit_depth <= 8)
  171236. {
  171237. int i;
  171238. double g;
  171239. if (png_ptr->screen_gamma > .000001)
  171240. g = 1.0 / (png_ptr->gamma * png_ptr->screen_gamma);
  171241. else
  171242. g = 1.0;
  171243. png_ptr->gamma_table = (png_bytep)png_malloc(png_ptr,
  171244. (png_uint_32)256);
  171245. for (i = 0; i < 256; i++)
  171246. {
  171247. png_ptr->gamma_table[i] = (png_byte)(pow((double)i / 255.0,
  171248. g) * 255.0 + .5);
  171249. }
  171250. #if defined(PNG_READ_BACKGROUND_SUPPORTED) || \
  171251. defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
  171252. if (png_ptr->transformations & ((PNG_BACKGROUND) | PNG_RGB_TO_GRAY))
  171253. {
  171254. g = 1.0 / (png_ptr->gamma);
  171255. png_ptr->gamma_to_1 = (png_bytep)png_malloc(png_ptr,
  171256. (png_uint_32)256);
  171257. for (i = 0; i < 256; i++)
  171258. {
  171259. png_ptr->gamma_to_1[i] = (png_byte)(pow((double)i / 255.0,
  171260. g) * 255.0 + .5);
  171261. }
  171262. png_ptr->gamma_from_1 = (png_bytep)png_malloc(png_ptr,
  171263. (png_uint_32)256);
  171264. if(png_ptr->screen_gamma > 0.000001)
  171265. g = 1.0 / png_ptr->screen_gamma;
  171266. else
  171267. g = png_ptr->gamma; /* probably doing rgb_to_gray */
  171268. for (i = 0; i < 256; i++)
  171269. {
  171270. png_ptr->gamma_from_1[i] = (png_byte)(pow((double)i / 255.0,
  171271. g) * 255.0 + .5);
  171272. }
  171273. }
  171274. #endif /* PNG_READ_BACKGROUND_SUPPORTED || PNG_RGB_TO_GRAY_SUPPORTED */
  171275. }
  171276. else
  171277. {
  171278. double g;
  171279. int i, j, shift, num;
  171280. int sig_bit;
  171281. png_uint_32 ig;
  171282. if (png_ptr->color_type & PNG_COLOR_MASK_COLOR)
  171283. {
  171284. sig_bit = (int)png_ptr->sig_bit.red;
  171285. if ((int)png_ptr->sig_bit.green > sig_bit)
  171286. sig_bit = png_ptr->sig_bit.green;
  171287. if ((int)png_ptr->sig_bit.blue > sig_bit)
  171288. sig_bit = png_ptr->sig_bit.blue;
  171289. }
  171290. else
  171291. {
  171292. sig_bit = (int)png_ptr->sig_bit.gray;
  171293. }
  171294. if (sig_bit > 0)
  171295. shift = 16 - sig_bit;
  171296. else
  171297. shift = 0;
  171298. if (png_ptr->transformations & PNG_16_TO_8)
  171299. {
  171300. if (shift < (16 - PNG_MAX_GAMMA_8))
  171301. shift = (16 - PNG_MAX_GAMMA_8);
  171302. }
  171303. if (shift > 8)
  171304. shift = 8;
  171305. if (shift < 0)
  171306. shift = 0;
  171307. png_ptr->gamma_shift = (png_byte)shift;
  171308. num = (1 << (8 - shift));
  171309. if (png_ptr->screen_gamma > .000001)
  171310. g = 1.0 / (png_ptr->gamma * png_ptr->screen_gamma);
  171311. else
  171312. g = 1.0;
  171313. png_ptr->gamma_16_table = (png_uint_16pp)png_malloc(png_ptr,
  171314. (png_uint_32)(num * png_sizeof (png_uint_16p)));
  171315. if (png_ptr->transformations & (PNG_16_TO_8 | PNG_BACKGROUND))
  171316. {
  171317. double fin, fout;
  171318. png_uint_32 last, max;
  171319. for (i = 0; i < num; i++)
  171320. {
  171321. png_ptr->gamma_16_table[i] = (png_uint_16p)png_malloc(png_ptr,
  171322. (png_uint_32)(256 * png_sizeof (png_uint_16)));
  171323. }
  171324. g = 1.0 / g;
  171325. last = 0;
  171326. for (i = 0; i < 256; i++)
  171327. {
  171328. fout = ((double)i + 0.5) / 256.0;
  171329. fin = pow(fout, g);
  171330. max = (png_uint_32)(fin * (double)((png_uint_32)num << 8));
  171331. while (last <= max)
  171332. {
  171333. png_ptr->gamma_16_table[(int)(last & (0xff >> shift))]
  171334. [(int)(last >> (8 - shift))] = (png_uint_16)(
  171335. (png_uint_16)i | ((png_uint_16)i << 8));
  171336. last++;
  171337. }
  171338. }
  171339. while (last < ((png_uint_32)num << 8))
  171340. {
  171341. png_ptr->gamma_16_table[(int)(last & (0xff >> shift))]
  171342. [(int)(last >> (8 - shift))] = (png_uint_16)65535L;
  171343. last++;
  171344. }
  171345. }
  171346. else
  171347. {
  171348. for (i = 0; i < num; i++)
  171349. {
  171350. png_ptr->gamma_16_table[i] = (png_uint_16p)png_malloc(png_ptr,
  171351. (png_uint_32)(256 * png_sizeof (png_uint_16)));
  171352. ig = (((png_uint_32)i * (png_uint_32)png_gamma_shift[shift]) >> 4);
  171353. for (j = 0; j < 256; j++)
  171354. {
  171355. png_ptr->gamma_16_table[i][j] =
  171356. (png_uint_16)(pow((double)(ig + ((png_uint_32)j << 8)) /
  171357. 65535.0, g) * 65535.0 + .5);
  171358. }
  171359. }
  171360. }
  171361. #if defined(PNG_READ_BACKGROUND_SUPPORTED) || \
  171362. defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
  171363. if (png_ptr->transformations & (PNG_BACKGROUND | PNG_RGB_TO_GRAY))
  171364. {
  171365. g = 1.0 / (png_ptr->gamma);
  171366. png_ptr->gamma_16_to_1 = (png_uint_16pp)png_malloc(png_ptr,
  171367. (png_uint_32)(num * png_sizeof (png_uint_16p )));
  171368. for (i = 0; i < num; i++)
  171369. {
  171370. png_ptr->gamma_16_to_1[i] = (png_uint_16p)png_malloc(png_ptr,
  171371. (png_uint_32)(256 * png_sizeof (png_uint_16)));
  171372. ig = (((png_uint_32)i *
  171373. (png_uint_32)png_gamma_shift[shift]) >> 4);
  171374. for (j = 0; j < 256; j++)
  171375. {
  171376. png_ptr->gamma_16_to_1[i][j] =
  171377. (png_uint_16)(pow((double)(ig + ((png_uint_32)j << 8)) /
  171378. 65535.0, g) * 65535.0 + .5);
  171379. }
  171380. }
  171381. if(png_ptr->screen_gamma > 0.000001)
  171382. g = 1.0 / png_ptr->screen_gamma;
  171383. else
  171384. g = png_ptr->gamma; /* probably doing rgb_to_gray */
  171385. png_ptr->gamma_16_from_1 = (png_uint_16pp)png_malloc(png_ptr,
  171386. (png_uint_32)(num * png_sizeof (png_uint_16p)));
  171387. for (i = 0; i < num; i++)
  171388. {
  171389. png_ptr->gamma_16_from_1[i] = (png_uint_16p)png_malloc(png_ptr,
  171390. (png_uint_32)(256 * png_sizeof (png_uint_16)));
  171391. ig = (((png_uint_32)i *
  171392. (png_uint_32)png_gamma_shift[shift]) >> 4);
  171393. for (j = 0; j < 256; j++)
  171394. {
  171395. png_ptr->gamma_16_from_1[i][j] =
  171396. (png_uint_16)(pow((double)(ig + ((png_uint_32)j << 8)) /
  171397. 65535.0, g) * 65535.0 + .5);
  171398. }
  171399. }
  171400. }
  171401. #endif /* PNG_READ_BACKGROUND_SUPPORTED || PNG_RGB_TO_GRAY_SUPPORTED */
  171402. }
  171403. }
  171404. #endif
  171405. #endif
  171406. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  171407. void /* PRIVATE */
  171408. png_do_read_intrapixel(png_row_infop row_info, png_bytep row)
  171409. {
  171410. png_debug(1, "in png_do_read_intrapixel\n");
  171411. if (
  171412. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  171413. row != NULL && row_info != NULL &&
  171414. #endif
  171415. (row_info->color_type & PNG_COLOR_MASK_COLOR))
  171416. {
  171417. int bytes_per_pixel;
  171418. png_uint_32 row_width = row_info->width;
  171419. if (row_info->bit_depth == 8)
  171420. {
  171421. png_bytep rp;
  171422. png_uint_32 i;
  171423. if (row_info->color_type == PNG_COLOR_TYPE_RGB)
  171424. bytes_per_pixel = 3;
  171425. else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  171426. bytes_per_pixel = 4;
  171427. else
  171428. return;
  171429. for (i = 0, rp = row; i < row_width; i++, rp += bytes_per_pixel)
  171430. {
  171431. *(rp) = (png_byte)((256 + *rp + *(rp+1))&0xff);
  171432. *(rp+2) = (png_byte)((256 + *(rp+2) + *(rp+1))&0xff);
  171433. }
  171434. }
  171435. else if (row_info->bit_depth == 16)
  171436. {
  171437. png_bytep rp;
  171438. png_uint_32 i;
  171439. if (row_info->color_type == PNG_COLOR_TYPE_RGB)
  171440. bytes_per_pixel = 6;
  171441. else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  171442. bytes_per_pixel = 8;
  171443. else
  171444. return;
  171445. for (i = 0, rp = row; i < row_width; i++, rp += bytes_per_pixel)
  171446. {
  171447. png_uint_32 s0 = (*(rp ) << 8) | *(rp+1);
  171448. png_uint_32 s1 = (*(rp+2) << 8) | *(rp+3);
  171449. png_uint_32 s2 = (*(rp+4) << 8) | *(rp+5);
  171450. png_uint_32 red = (png_uint_32)((s0+s1+65536L) & 0xffffL);
  171451. png_uint_32 blue = (png_uint_32)((s2+s1+65536L) & 0xffffL);
  171452. *(rp ) = (png_byte)((red >> 8) & 0xff);
  171453. *(rp+1) = (png_byte)(red & 0xff);
  171454. *(rp+4) = (png_byte)((blue >> 8) & 0xff);
  171455. *(rp+5) = (png_byte)(blue & 0xff);
  171456. }
  171457. }
  171458. }
  171459. }
  171460. #endif /* PNG_MNG_FEATURES_SUPPORTED */
  171461. #endif /* PNG_READ_SUPPORTED */
  171462. /********* End of inlined file: pngrtran.c *********/
  171463. /********* Start of inlined file: pngrutil.c *********/
  171464. #define PNG_INTERNAL
  171465. #if defined(PNG_READ_SUPPORTED)
  171466. #if defined(_WIN32_WCE) && (_WIN32_WCE<0x500)
  171467. # define WIN32_WCE_OLD
  171468. #endif
  171469. #ifdef PNG_FLOATING_POINT_SUPPORTED
  171470. # if defined(WIN32_WCE_OLD)
  171471. __inline double png_strtod(png_structp png_ptr, PNG_CONST char *nptr, char **endptr)
  171472. {
  171473. double result = 0;
  171474. int len;
  171475. wchar_t *str, *end;
  171476. len = MultiByteToWideChar(CP_ACP, 0, nptr, -1, NULL, 0);
  171477. str = (wchar_t *)png_malloc(png_ptr, len * sizeof(wchar_t));
  171478. if ( NULL != str )
  171479. {
  171480. MultiByteToWideChar(CP_ACP, 0, nptr, -1, str, len);
  171481. result = wcstod(str, &end);
  171482. len = WideCharToMultiByte(CP_ACP, 0, end, -1, NULL, 0, NULL, NULL);
  171483. *endptr = (char *)nptr + (png_strlen(nptr) - len + 1);
  171484. png_free(png_ptr, str);
  171485. }
  171486. return result;
  171487. }
  171488. # else
  171489. # define png_strtod(p,a,b) strtod(a,b)
  171490. # endif
  171491. #endif
  171492. png_uint_32 PNGAPI
  171493. png_get_uint_31(png_structp png_ptr, png_bytep buf)
  171494. {
  171495. png_uint_32 i = png_get_uint_32(buf);
  171496. if (i > PNG_UINT_31_MAX)
  171497. png_error(png_ptr, "PNG unsigned integer out of range.");
  171498. return (i);
  171499. }
  171500. #ifndef PNG_READ_BIG_ENDIAN_SUPPORTED
  171501. png_uint_32 PNGAPI
  171502. png_get_uint_32(png_bytep buf)
  171503. {
  171504. png_uint_32 i = ((png_uint_32)(*buf) << 24) +
  171505. ((png_uint_32)(*(buf + 1)) << 16) +
  171506. ((png_uint_32)(*(buf + 2)) << 8) +
  171507. (png_uint_32)(*(buf + 3));
  171508. return (i);
  171509. }
  171510. png_int_32 PNGAPI
  171511. png_get_int_32(png_bytep buf)
  171512. {
  171513. png_int_32 i = ((png_int_32)(*buf) << 24) +
  171514. ((png_int_32)(*(buf + 1)) << 16) +
  171515. ((png_int_32)(*(buf + 2)) << 8) +
  171516. (png_int_32)(*(buf + 3));
  171517. return (i);
  171518. }
  171519. png_uint_16 PNGAPI
  171520. png_get_uint_16(png_bytep buf)
  171521. {
  171522. png_uint_16 i = (png_uint_16)(((png_uint_16)(*buf) << 8) +
  171523. (png_uint_16)(*(buf + 1)));
  171524. return (i);
  171525. }
  171526. #endif /* PNG_READ_BIG_ENDIAN_SUPPORTED */
  171527. void /* PRIVATE */
  171528. png_crc_read(png_structp png_ptr, png_bytep buf, png_size_t length)
  171529. {
  171530. if(png_ptr == NULL) return;
  171531. png_read_data(png_ptr, buf, length);
  171532. png_calculate_crc(png_ptr, buf, length);
  171533. }
  171534. int /* PRIVATE */
  171535. png_crc_finish(png_structp png_ptr, png_uint_32 skip)
  171536. {
  171537. png_size_t i;
  171538. png_size_t istop = png_ptr->zbuf_size;
  171539. for (i = (png_size_t)skip; i > istop; i -= istop)
  171540. {
  171541. png_crc_read(png_ptr, png_ptr->zbuf, png_ptr->zbuf_size);
  171542. }
  171543. if (i)
  171544. {
  171545. png_crc_read(png_ptr, png_ptr->zbuf, i);
  171546. }
  171547. if (png_crc_error(png_ptr))
  171548. {
  171549. if (((png_ptr->chunk_name[0] & 0x20) && /* Ancillary */
  171550. !(png_ptr->flags & PNG_FLAG_CRC_ANCILLARY_NOWARN)) ||
  171551. (!(png_ptr->chunk_name[0] & 0x20) && /* Critical */
  171552. (png_ptr->flags & PNG_FLAG_CRC_CRITICAL_USE)))
  171553. {
  171554. png_chunk_warning(png_ptr, "CRC error");
  171555. }
  171556. else
  171557. {
  171558. png_chunk_error(png_ptr, "CRC error");
  171559. }
  171560. return (1);
  171561. }
  171562. return (0);
  171563. }
  171564. int /* PRIVATE */
  171565. png_crc_error(png_structp png_ptr)
  171566. {
  171567. png_byte crc_bytes[4];
  171568. png_uint_32 crc;
  171569. int need_crc = 1;
  171570. if (png_ptr->chunk_name[0] & 0x20) /* ancillary */
  171571. {
  171572. if ((png_ptr->flags & PNG_FLAG_CRC_ANCILLARY_MASK) ==
  171573. (PNG_FLAG_CRC_ANCILLARY_USE | PNG_FLAG_CRC_ANCILLARY_NOWARN))
  171574. need_crc = 0;
  171575. }
  171576. else /* critical */
  171577. {
  171578. if (png_ptr->flags & PNG_FLAG_CRC_CRITICAL_IGNORE)
  171579. need_crc = 0;
  171580. }
  171581. png_read_data(png_ptr, crc_bytes, 4);
  171582. if (need_crc)
  171583. {
  171584. crc = png_get_uint_32(crc_bytes);
  171585. return ((int)(crc != png_ptr->crc));
  171586. }
  171587. else
  171588. return (0);
  171589. }
  171590. #if defined(PNG_READ_zTXt_SUPPORTED) || defined(PNG_READ_iTXt_SUPPORTED) || \
  171591. defined(PNG_READ_iCCP_SUPPORTED)
  171592. png_charp /* PRIVATE */
  171593. png_decompress_chunk(png_structp png_ptr, int comp_type,
  171594. png_charp chunkdata, png_size_t chunklength,
  171595. png_size_t prefix_size, png_size_t *newlength)
  171596. {
  171597. static PNG_CONST char msg[] = "Error decoding compressed text";
  171598. png_charp text;
  171599. png_size_t text_size;
  171600. if (comp_type == PNG_COMPRESSION_TYPE_BASE)
  171601. {
  171602. int ret = Z_OK;
  171603. png_ptr->zstream.next_in = (png_bytep)(chunkdata + prefix_size);
  171604. png_ptr->zstream.avail_in = (uInt)(chunklength - prefix_size);
  171605. png_ptr->zstream.next_out = png_ptr->zbuf;
  171606. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  171607. text_size = 0;
  171608. text = NULL;
  171609. while (png_ptr->zstream.avail_in)
  171610. {
  171611. ret = inflate(&png_ptr->zstream, Z_PARTIAL_FLUSH);
  171612. if (ret != Z_OK && ret != Z_STREAM_END)
  171613. {
  171614. if (png_ptr->zstream.msg != NULL)
  171615. png_warning(png_ptr, png_ptr->zstream.msg);
  171616. else
  171617. png_warning(png_ptr, msg);
  171618. inflateReset(&png_ptr->zstream);
  171619. png_ptr->zstream.avail_in = 0;
  171620. if (text == NULL)
  171621. {
  171622. text_size = prefix_size + png_sizeof(msg) + 1;
  171623. text = (png_charp)png_malloc_warn(png_ptr, text_size);
  171624. if (text == NULL)
  171625. {
  171626. png_free(png_ptr,chunkdata);
  171627. png_error(png_ptr,"Not enough memory to decompress chunk");
  171628. }
  171629. png_memcpy(text, chunkdata, prefix_size);
  171630. }
  171631. text[text_size - 1] = 0x00;
  171632. text_size = (png_size_t)(chunklength - (text - chunkdata) - 1);
  171633. text_size = png_sizeof(msg) > text_size ? text_size :
  171634. png_sizeof(msg);
  171635. png_memcpy(text + prefix_size, msg, text_size + 1);
  171636. break;
  171637. }
  171638. if (!png_ptr->zstream.avail_out || ret == Z_STREAM_END)
  171639. {
  171640. if (text == NULL)
  171641. {
  171642. text_size = prefix_size +
  171643. png_ptr->zbuf_size - png_ptr->zstream.avail_out;
  171644. text = (png_charp)png_malloc_warn(png_ptr, text_size + 1);
  171645. if (text == NULL)
  171646. {
  171647. png_free(png_ptr,chunkdata);
  171648. png_error(png_ptr,"Not enough memory to decompress chunk.");
  171649. }
  171650. png_memcpy(text + prefix_size, png_ptr->zbuf,
  171651. text_size - prefix_size);
  171652. png_memcpy(text, chunkdata, prefix_size);
  171653. *(text + text_size) = 0x00;
  171654. }
  171655. else
  171656. {
  171657. png_charp tmp;
  171658. tmp = text;
  171659. text = (png_charp)png_malloc_warn(png_ptr,
  171660. (png_uint_32)(text_size +
  171661. png_ptr->zbuf_size - png_ptr->zstream.avail_out + 1));
  171662. if (text == NULL)
  171663. {
  171664. png_free(png_ptr, tmp);
  171665. png_free(png_ptr, chunkdata);
  171666. png_error(png_ptr,"Not enough memory to decompress chunk..");
  171667. }
  171668. png_memcpy(text, tmp, text_size);
  171669. png_free(png_ptr, tmp);
  171670. png_memcpy(text + text_size, png_ptr->zbuf,
  171671. (png_ptr->zbuf_size - png_ptr->zstream.avail_out));
  171672. text_size += png_ptr->zbuf_size - png_ptr->zstream.avail_out;
  171673. *(text + text_size) = 0x00;
  171674. }
  171675. if (ret == Z_STREAM_END)
  171676. break;
  171677. else
  171678. {
  171679. png_ptr->zstream.next_out = png_ptr->zbuf;
  171680. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  171681. }
  171682. }
  171683. }
  171684. if (ret != Z_STREAM_END)
  171685. {
  171686. #if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE)
  171687. char umsg[52];
  171688. if (ret == Z_BUF_ERROR)
  171689. png_snprintf(umsg, 52,
  171690. "Buffer error in compressed datastream in %s chunk",
  171691. png_ptr->chunk_name);
  171692. else if (ret == Z_DATA_ERROR)
  171693. png_snprintf(umsg, 52,
  171694. "Data error in compressed datastream in %s chunk",
  171695. png_ptr->chunk_name);
  171696. else
  171697. png_snprintf(umsg, 52,
  171698. "Incomplete compressed datastream in %s chunk",
  171699. png_ptr->chunk_name);
  171700. png_warning(png_ptr, umsg);
  171701. #else
  171702. png_warning(png_ptr,
  171703. "Incomplete compressed datastream in chunk other than IDAT");
  171704. #endif
  171705. text_size=prefix_size;
  171706. if (text == NULL)
  171707. {
  171708. text = (png_charp)png_malloc_warn(png_ptr, text_size+1);
  171709. if (text == NULL)
  171710. {
  171711. png_free(png_ptr, chunkdata);
  171712. png_error(png_ptr,"Not enough memory for text.");
  171713. }
  171714. png_memcpy(text, chunkdata, prefix_size);
  171715. }
  171716. *(text + text_size) = 0x00;
  171717. }
  171718. inflateReset(&png_ptr->zstream);
  171719. png_ptr->zstream.avail_in = 0;
  171720. png_free(png_ptr, chunkdata);
  171721. chunkdata = text;
  171722. *newlength=text_size;
  171723. }
  171724. else /* if (comp_type != PNG_COMPRESSION_TYPE_BASE) */
  171725. {
  171726. #if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE)
  171727. char umsg[50];
  171728. png_snprintf(umsg, 50,
  171729. "Unknown zTXt compression type %d", comp_type);
  171730. png_warning(png_ptr, umsg);
  171731. #else
  171732. png_warning(png_ptr, "Unknown zTXt compression type");
  171733. #endif
  171734. *(chunkdata + prefix_size) = 0x00;
  171735. *newlength=prefix_size;
  171736. }
  171737. return chunkdata;
  171738. }
  171739. #endif
  171740. void /* PRIVATE */
  171741. png_handle_IHDR(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  171742. {
  171743. png_byte buf[13];
  171744. png_uint_32 width, height;
  171745. int bit_depth, color_type, compression_type, filter_type;
  171746. int interlace_type;
  171747. png_debug(1, "in png_handle_IHDR\n");
  171748. if (png_ptr->mode & PNG_HAVE_IHDR)
  171749. png_error(png_ptr, "Out of place IHDR");
  171750. if (length != 13)
  171751. png_error(png_ptr, "Invalid IHDR chunk");
  171752. png_ptr->mode |= PNG_HAVE_IHDR;
  171753. png_crc_read(png_ptr, buf, 13);
  171754. png_crc_finish(png_ptr, 0);
  171755. width = png_get_uint_31(png_ptr, buf);
  171756. height = png_get_uint_31(png_ptr, buf + 4);
  171757. bit_depth = buf[8];
  171758. color_type = buf[9];
  171759. compression_type = buf[10];
  171760. filter_type = buf[11];
  171761. interlace_type = buf[12];
  171762. png_ptr->width = width;
  171763. png_ptr->height = height;
  171764. png_ptr->bit_depth = (png_byte)bit_depth;
  171765. png_ptr->interlaced = (png_byte)interlace_type;
  171766. png_ptr->color_type = (png_byte)color_type;
  171767. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  171768. png_ptr->filter_type = (png_byte)filter_type;
  171769. #endif
  171770. png_ptr->compression_type = (png_byte)compression_type;
  171771. switch (png_ptr->color_type)
  171772. {
  171773. case PNG_COLOR_TYPE_GRAY:
  171774. case PNG_COLOR_TYPE_PALETTE:
  171775. png_ptr->channels = 1;
  171776. break;
  171777. case PNG_COLOR_TYPE_RGB:
  171778. png_ptr->channels = 3;
  171779. break;
  171780. case PNG_COLOR_TYPE_GRAY_ALPHA:
  171781. png_ptr->channels = 2;
  171782. break;
  171783. case PNG_COLOR_TYPE_RGB_ALPHA:
  171784. png_ptr->channels = 4;
  171785. break;
  171786. }
  171787. png_ptr->pixel_depth = (png_byte)(png_ptr->bit_depth *
  171788. png_ptr->channels);
  171789. png_ptr->rowbytes = PNG_ROWBYTES(png_ptr->pixel_depth,png_ptr->width);
  171790. png_debug1(3,"bit_depth = %d\n", png_ptr->bit_depth);
  171791. png_debug1(3,"channels = %d\n", png_ptr->channels);
  171792. png_debug1(3,"rowbytes = %lu\n", png_ptr->rowbytes);
  171793. png_set_IHDR(png_ptr, info_ptr, width, height, bit_depth,
  171794. color_type, interlace_type, compression_type, filter_type);
  171795. }
  171796. void /* PRIVATE */
  171797. png_handle_PLTE(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  171798. {
  171799. png_color palette[PNG_MAX_PALETTE_LENGTH];
  171800. int num, i;
  171801. #ifndef PNG_NO_POINTER_INDEXING
  171802. png_colorp pal_ptr;
  171803. #endif
  171804. png_debug(1, "in png_handle_PLTE\n");
  171805. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  171806. png_error(png_ptr, "Missing IHDR before PLTE");
  171807. else if (png_ptr->mode & PNG_HAVE_IDAT)
  171808. {
  171809. png_warning(png_ptr, "Invalid PLTE after IDAT");
  171810. png_crc_finish(png_ptr, length);
  171811. return;
  171812. }
  171813. else if (png_ptr->mode & PNG_HAVE_PLTE)
  171814. png_error(png_ptr, "Duplicate PLTE chunk");
  171815. png_ptr->mode |= PNG_HAVE_PLTE;
  171816. if (!(png_ptr->color_type&PNG_COLOR_MASK_COLOR))
  171817. {
  171818. png_warning(png_ptr,
  171819. "Ignoring PLTE chunk in grayscale PNG");
  171820. png_crc_finish(png_ptr, length);
  171821. return;
  171822. }
  171823. #if !defined(PNG_READ_OPT_PLTE_SUPPORTED)
  171824. if (png_ptr->color_type != PNG_COLOR_TYPE_PALETTE)
  171825. {
  171826. png_crc_finish(png_ptr, length);
  171827. return;
  171828. }
  171829. #endif
  171830. if (length > 3*PNG_MAX_PALETTE_LENGTH || length % 3)
  171831. {
  171832. if (png_ptr->color_type != PNG_COLOR_TYPE_PALETTE)
  171833. {
  171834. png_warning(png_ptr, "Invalid palette chunk");
  171835. png_crc_finish(png_ptr, length);
  171836. return;
  171837. }
  171838. else
  171839. {
  171840. png_error(png_ptr, "Invalid palette chunk");
  171841. }
  171842. }
  171843. num = (int)length / 3;
  171844. #ifndef PNG_NO_POINTER_INDEXING
  171845. for (i = 0, pal_ptr = palette; i < num; i++, pal_ptr++)
  171846. {
  171847. png_byte buf[3];
  171848. png_crc_read(png_ptr, buf, 3);
  171849. pal_ptr->red = buf[0];
  171850. pal_ptr->green = buf[1];
  171851. pal_ptr->blue = buf[2];
  171852. }
  171853. #else
  171854. for (i = 0; i < num; i++)
  171855. {
  171856. png_byte buf[3];
  171857. png_crc_read(png_ptr, buf, 3);
  171858. palette[i].red = buf[0];
  171859. palette[i].green = buf[1];
  171860. palette[i].blue = buf[2];
  171861. }
  171862. #endif
  171863. #if !defined(PNG_READ_OPT_PLTE_SUPPORTED)
  171864. if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  171865. #endif
  171866. {
  171867. png_crc_finish(png_ptr, 0);
  171868. }
  171869. #if !defined(PNG_READ_OPT_PLTE_SUPPORTED)
  171870. else if (png_crc_error(png_ptr)) /* Only if we have a CRC error */
  171871. {
  171872. if (!(png_ptr->flags & PNG_FLAG_CRC_ANCILLARY_USE))
  171873. {
  171874. if (png_ptr->flags & PNG_FLAG_CRC_ANCILLARY_NOWARN)
  171875. {
  171876. png_chunk_error(png_ptr, "CRC error");
  171877. }
  171878. else
  171879. {
  171880. png_chunk_warning(png_ptr, "CRC error");
  171881. return;
  171882. }
  171883. }
  171884. else if (!(png_ptr->flags & PNG_FLAG_CRC_ANCILLARY_NOWARN))
  171885. {
  171886. png_chunk_warning(png_ptr, "CRC error");
  171887. }
  171888. }
  171889. #endif
  171890. png_set_PLTE(png_ptr, info_ptr, palette, num);
  171891. #if defined(PNG_READ_tRNS_SUPPORTED)
  171892. if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  171893. {
  171894. if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_tRNS))
  171895. {
  171896. if (png_ptr->num_trans > (png_uint_16)num)
  171897. {
  171898. png_warning(png_ptr, "Truncating incorrect tRNS chunk length");
  171899. png_ptr->num_trans = (png_uint_16)num;
  171900. }
  171901. if (info_ptr->num_trans > (png_uint_16)num)
  171902. {
  171903. png_warning(png_ptr, "Truncating incorrect info tRNS chunk length");
  171904. info_ptr->num_trans = (png_uint_16)num;
  171905. }
  171906. }
  171907. }
  171908. #endif
  171909. }
  171910. void /* PRIVATE */
  171911. png_handle_IEND(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  171912. {
  171913. png_debug(1, "in png_handle_IEND\n");
  171914. if (!(png_ptr->mode & PNG_HAVE_IHDR) || !(png_ptr->mode & PNG_HAVE_IDAT))
  171915. {
  171916. png_error(png_ptr, "No image in file");
  171917. }
  171918. png_ptr->mode |= (PNG_AFTER_IDAT | PNG_HAVE_IEND);
  171919. if (length != 0)
  171920. {
  171921. png_warning(png_ptr, "Incorrect IEND chunk length");
  171922. }
  171923. png_crc_finish(png_ptr, length);
  171924. info_ptr =info_ptr; /* quiet compiler warnings about unused info_ptr */
  171925. }
  171926. #if defined(PNG_READ_gAMA_SUPPORTED)
  171927. void /* PRIVATE */
  171928. png_handle_gAMA(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  171929. {
  171930. png_fixed_point igamma;
  171931. #ifdef PNG_FLOATING_POINT_SUPPORTED
  171932. float file_gamma;
  171933. #endif
  171934. png_byte buf[4];
  171935. png_debug(1, "in png_handle_gAMA\n");
  171936. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  171937. png_error(png_ptr, "Missing IHDR before gAMA");
  171938. else if (png_ptr->mode & PNG_HAVE_IDAT)
  171939. {
  171940. png_warning(png_ptr, "Invalid gAMA after IDAT");
  171941. png_crc_finish(png_ptr, length);
  171942. return;
  171943. }
  171944. else if (png_ptr->mode & PNG_HAVE_PLTE)
  171945. png_warning(png_ptr, "Out of place gAMA chunk");
  171946. if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_gAMA)
  171947. #if defined(PNG_READ_sRGB_SUPPORTED)
  171948. && !(info_ptr->valid & PNG_INFO_sRGB)
  171949. #endif
  171950. )
  171951. {
  171952. png_warning(png_ptr, "Duplicate gAMA chunk");
  171953. png_crc_finish(png_ptr, length);
  171954. return;
  171955. }
  171956. if (length != 4)
  171957. {
  171958. png_warning(png_ptr, "Incorrect gAMA chunk length");
  171959. png_crc_finish(png_ptr, length);
  171960. return;
  171961. }
  171962. png_crc_read(png_ptr, buf, 4);
  171963. if (png_crc_finish(png_ptr, 0))
  171964. return;
  171965. igamma = (png_fixed_point)png_get_uint_32(buf);
  171966. if (igamma == 0)
  171967. {
  171968. png_warning(png_ptr,
  171969. "Ignoring gAMA chunk with gamma=0");
  171970. return;
  171971. }
  171972. #if defined(PNG_READ_sRGB_SUPPORTED)
  171973. if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_sRGB))
  171974. if (PNG_OUT_OF_RANGE(igamma, 45500L, 500))
  171975. {
  171976. png_warning(png_ptr,
  171977. "Ignoring incorrect gAMA value when sRGB is also present");
  171978. #ifndef PNG_NO_CONSOLE_IO
  171979. fprintf(stderr, "gamma = (%d/100000)\n", (int)igamma);
  171980. #endif
  171981. return;
  171982. }
  171983. #endif /* PNG_READ_sRGB_SUPPORTED */
  171984. #ifdef PNG_FLOATING_POINT_SUPPORTED
  171985. file_gamma = (float)igamma / (float)100000.0;
  171986. # ifdef PNG_READ_GAMMA_SUPPORTED
  171987. png_ptr->gamma = file_gamma;
  171988. # endif
  171989. png_set_gAMA(png_ptr, info_ptr, file_gamma);
  171990. #endif
  171991. #ifdef PNG_FIXED_POINT_SUPPORTED
  171992. png_set_gAMA_fixed(png_ptr, info_ptr, igamma);
  171993. #endif
  171994. }
  171995. #endif
  171996. #if defined(PNG_READ_sBIT_SUPPORTED)
  171997. void /* PRIVATE */
  171998. png_handle_sBIT(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  171999. {
  172000. png_size_t truelen;
  172001. png_byte buf[4];
  172002. png_debug(1, "in png_handle_sBIT\n");
  172003. buf[0] = buf[1] = buf[2] = buf[3] = 0;
  172004. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  172005. png_error(png_ptr, "Missing IHDR before sBIT");
  172006. else if (png_ptr->mode & PNG_HAVE_IDAT)
  172007. {
  172008. png_warning(png_ptr, "Invalid sBIT after IDAT");
  172009. png_crc_finish(png_ptr, length);
  172010. return;
  172011. }
  172012. else if (png_ptr->mode & PNG_HAVE_PLTE)
  172013. {
  172014. png_warning(png_ptr, "Out of place sBIT chunk");
  172015. }
  172016. if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_sBIT))
  172017. {
  172018. png_warning(png_ptr, "Duplicate sBIT chunk");
  172019. png_crc_finish(png_ptr, length);
  172020. return;
  172021. }
  172022. if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  172023. truelen = 3;
  172024. else
  172025. truelen = (png_size_t)png_ptr->channels;
  172026. if (length != truelen || length > 4)
  172027. {
  172028. png_warning(png_ptr, "Incorrect sBIT chunk length");
  172029. png_crc_finish(png_ptr, length);
  172030. return;
  172031. }
  172032. png_crc_read(png_ptr, buf, truelen);
  172033. if (png_crc_finish(png_ptr, 0))
  172034. return;
  172035. if (png_ptr->color_type & PNG_COLOR_MASK_COLOR)
  172036. {
  172037. png_ptr->sig_bit.red = buf[0];
  172038. png_ptr->sig_bit.green = buf[1];
  172039. png_ptr->sig_bit.blue = buf[2];
  172040. png_ptr->sig_bit.alpha = buf[3];
  172041. }
  172042. else
  172043. {
  172044. png_ptr->sig_bit.gray = buf[0];
  172045. png_ptr->sig_bit.red = buf[0];
  172046. png_ptr->sig_bit.green = buf[0];
  172047. png_ptr->sig_bit.blue = buf[0];
  172048. png_ptr->sig_bit.alpha = buf[1];
  172049. }
  172050. png_set_sBIT(png_ptr, info_ptr, &(png_ptr->sig_bit));
  172051. }
  172052. #endif
  172053. #if defined(PNG_READ_cHRM_SUPPORTED)
  172054. void /* PRIVATE */
  172055. png_handle_cHRM(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  172056. {
  172057. png_byte buf[4];
  172058. #ifdef PNG_FLOATING_POINT_SUPPORTED
  172059. float white_x, white_y, red_x, red_y, green_x, green_y, blue_x, blue_y;
  172060. #endif
  172061. png_fixed_point int_x_white, int_y_white, int_x_red, int_y_red, int_x_green,
  172062. int_y_green, int_x_blue, int_y_blue;
  172063. png_uint_32 uint_x, uint_y;
  172064. png_debug(1, "in png_handle_cHRM\n");
  172065. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  172066. png_error(png_ptr, "Missing IHDR before cHRM");
  172067. else if (png_ptr->mode & PNG_HAVE_IDAT)
  172068. {
  172069. png_warning(png_ptr, "Invalid cHRM after IDAT");
  172070. png_crc_finish(png_ptr, length);
  172071. return;
  172072. }
  172073. else if (png_ptr->mode & PNG_HAVE_PLTE)
  172074. png_warning(png_ptr, "Missing PLTE before cHRM");
  172075. if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_cHRM)
  172076. #if defined(PNG_READ_sRGB_SUPPORTED)
  172077. && !(info_ptr->valid & PNG_INFO_sRGB)
  172078. #endif
  172079. )
  172080. {
  172081. png_warning(png_ptr, "Duplicate cHRM chunk");
  172082. png_crc_finish(png_ptr, length);
  172083. return;
  172084. }
  172085. if (length != 32)
  172086. {
  172087. png_warning(png_ptr, "Incorrect cHRM chunk length");
  172088. png_crc_finish(png_ptr, length);
  172089. return;
  172090. }
  172091. png_crc_read(png_ptr, buf, 4);
  172092. uint_x = png_get_uint_32(buf);
  172093. png_crc_read(png_ptr, buf, 4);
  172094. uint_y = png_get_uint_32(buf);
  172095. if (uint_x > 80000L || uint_y > 80000L ||
  172096. uint_x + uint_y > 100000L)
  172097. {
  172098. png_warning(png_ptr, "Invalid cHRM white point");
  172099. png_crc_finish(png_ptr, 24);
  172100. return;
  172101. }
  172102. int_x_white = (png_fixed_point)uint_x;
  172103. int_y_white = (png_fixed_point)uint_y;
  172104. png_crc_read(png_ptr, buf, 4);
  172105. uint_x = png_get_uint_32(buf);
  172106. png_crc_read(png_ptr, buf, 4);
  172107. uint_y = png_get_uint_32(buf);
  172108. if (uint_x + uint_y > 100000L)
  172109. {
  172110. png_warning(png_ptr, "Invalid cHRM red point");
  172111. png_crc_finish(png_ptr, 16);
  172112. return;
  172113. }
  172114. int_x_red = (png_fixed_point)uint_x;
  172115. int_y_red = (png_fixed_point)uint_y;
  172116. png_crc_read(png_ptr, buf, 4);
  172117. uint_x = png_get_uint_32(buf);
  172118. png_crc_read(png_ptr, buf, 4);
  172119. uint_y = png_get_uint_32(buf);
  172120. if (uint_x + uint_y > 100000L)
  172121. {
  172122. png_warning(png_ptr, "Invalid cHRM green point");
  172123. png_crc_finish(png_ptr, 8);
  172124. return;
  172125. }
  172126. int_x_green = (png_fixed_point)uint_x;
  172127. int_y_green = (png_fixed_point)uint_y;
  172128. png_crc_read(png_ptr, buf, 4);
  172129. uint_x = png_get_uint_32(buf);
  172130. png_crc_read(png_ptr, buf, 4);
  172131. uint_y = png_get_uint_32(buf);
  172132. if (uint_x + uint_y > 100000L)
  172133. {
  172134. png_warning(png_ptr, "Invalid cHRM blue point");
  172135. png_crc_finish(png_ptr, 0);
  172136. return;
  172137. }
  172138. int_x_blue = (png_fixed_point)uint_x;
  172139. int_y_blue = (png_fixed_point)uint_y;
  172140. #ifdef PNG_FLOATING_POINT_SUPPORTED
  172141. white_x = (float)int_x_white / (float)100000.0;
  172142. white_y = (float)int_y_white / (float)100000.0;
  172143. red_x = (float)int_x_red / (float)100000.0;
  172144. red_y = (float)int_y_red / (float)100000.0;
  172145. green_x = (float)int_x_green / (float)100000.0;
  172146. green_y = (float)int_y_green / (float)100000.0;
  172147. blue_x = (float)int_x_blue / (float)100000.0;
  172148. blue_y = (float)int_y_blue / (float)100000.0;
  172149. #endif
  172150. #if defined(PNG_READ_sRGB_SUPPORTED)
  172151. if ((info_ptr != NULL) && (info_ptr->valid & PNG_INFO_sRGB))
  172152. {
  172153. if (PNG_OUT_OF_RANGE(int_x_white, 31270, 1000) ||
  172154. PNG_OUT_OF_RANGE(int_y_white, 32900, 1000) ||
  172155. PNG_OUT_OF_RANGE(int_x_red, 64000L, 1000) ||
  172156. PNG_OUT_OF_RANGE(int_y_red, 33000, 1000) ||
  172157. PNG_OUT_OF_RANGE(int_x_green, 30000, 1000) ||
  172158. PNG_OUT_OF_RANGE(int_y_green, 60000L, 1000) ||
  172159. PNG_OUT_OF_RANGE(int_x_blue, 15000, 1000) ||
  172160. PNG_OUT_OF_RANGE(int_y_blue, 6000, 1000))
  172161. {
  172162. png_warning(png_ptr,
  172163. "Ignoring incorrect cHRM value when sRGB is also present");
  172164. #ifndef PNG_NO_CONSOLE_IO
  172165. #ifdef PNG_FLOATING_POINT_SUPPORTED
  172166. fprintf(stderr,"wx=%f, wy=%f, rx=%f, ry=%f\n",
  172167. white_x, white_y, red_x, red_y);
  172168. fprintf(stderr,"gx=%f, gy=%f, bx=%f, by=%f\n",
  172169. green_x, green_y, blue_x, blue_y);
  172170. #else
  172171. fprintf(stderr,"wx=%ld, wy=%ld, rx=%ld, ry=%ld\n",
  172172. int_x_white, int_y_white, int_x_red, int_y_red);
  172173. fprintf(stderr,"gx=%ld, gy=%ld, bx=%ld, by=%ld\n",
  172174. int_x_green, int_y_green, int_x_blue, int_y_blue);
  172175. #endif
  172176. #endif /* PNG_NO_CONSOLE_IO */
  172177. }
  172178. png_crc_finish(png_ptr, 0);
  172179. return;
  172180. }
  172181. #endif /* PNG_READ_sRGB_SUPPORTED */
  172182. #ifdef PNG_FLOATING_POINT_SUPPORTED
  172183. png_set_cHRM(png_ptr, info_ptr,
  172184. white_x, white_y, red_x, red_y, green_x, green_y, blue_x, blue_y);
  172185. #endif
  172186. #ifdef PNG_FIXED_POINT_SUPPORTED
  172187. png_set_cHRM_fixed(png_ptr, info_ptr,
  172188. int_x_white, int_y_white, int_x_red, int_y_red, int_x_green,
  172189. int_y_green, int_x_blue, int_y_blue);
  172190. #endif
  172191. if (png_crc_finish(png_ptr, 0))
  172192. return;
  172193. }
  172194. #endif
  172195. #if defined(PNG_READ_sRGB_SUPPORTED)
  172196. void /* PRIVATE */
  172197. png_handle_sRGB(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  172198. {
  172199. int intent;
  172200. png_byte buf[1];
  172201. png_debug(1, "in png_handle_sRGB\n");
  172202. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  172203. png_error(png_ptr, "Missing IHDR before sRGB");
  172204. else if (png_ptr->mode & PNG_HAVE_IDAT)
  172205. {
  172206. png_warning(png_ptr, "Invalid sRGB after IDAT");
  172207. png_crc_finish(png_ptr, length);
  172208. return;
  172209. }
  172210. else if (png_ptr->mode & PNG_HAVE_PLTE)
  172211. png_warning(png_ptr, "Out of place sRGB chunk");
  172212. if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_sRGB))
  172213. {
  172214. png_warning(png_ptr, "Duplicate sRGB chunk");
  172215. png_crc_finish(png_ptr, length);
  172216. return;
  172217. }
  172218. if (length != 1)
  172219. {
  172220. png_warning(png_ptr, "Incorrect sRGB chunk length");
  172221. png_crc_finish(png_ptr, length);
  172222. return;
  172223. }
  172224. png_crc_read(png_ptr, buf, 1);
  172225. if (png_crc_finish(png_ptr, 0))
  172226. return;
  172227. intent = buf[0];
  172228. if (intent >= PNG_sRGB_INTENT_LAST)
  172229. {
  172230. png_warning(png_ptr, "Unknown sRGB intent");
  172231. return;
  172232. }
  172233. #if defined(PNG_READ_gAMA_SUPPORTED) && defined(PNG_READ_GAMMA_SUPPORTED)
  172234. if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_gAMA))
  172235. {
  172236. png_fixed_point igamma;
  172237. #ifdef PNG_FIXED_POINT_SUPPORTED
  172238. igamma=info_ptr->int_gamma;
  172239. #else
  172240. # ifdef PNG_FLOATING_POINT_SUPPORTED
  172241. igamma=(png_fixed_point)(info_ptr->gamma * 100000.);
  172242. # endif
  172243. #endif
  172244. if (PNG_OUT_OF_RANGE(igamma, 45500L, 500))
  172245. {
  172246. png_warning(png_ptr,
  172247. "Ignoring incorrect gAMA value when sRGB is also present");
  172248. #ifndef PNG_NO_CONSOLE_IO
  172249. # ifdef PNG_FIXED_POINT_SUPPORTED
  172250. fprintf(stderr,"incorrect gamma=(%d/100000)\n",(int)png_ptr->int_gamma);
  172251. # else
  172252. # ifdef PNG_FLOATING_POINT_SUPPORTED
  172253. fprintf(stderr,"incorrect gamma=%f\n",png_ptr->gamma);
  172254. # endif
  172255. # endif
  172256. #endif
  172257. }
  172258. }
  172259. #endif /* PNG_READ_gAMA_SUPPORTED */
  172260. #ifdef PNG_READ_cHRM_SUPPORTED
  172261. #ifdef PNG_FIXED_POINT_SUPPORTED
  172262. if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_cHRM))
  172263. if (PNG_OUT_OF_RANGE(info_ptr->int_x_white, 31270, 1000) ||
  172264. PNG_OUT_OF_RANGE(info_ptr->int_y_white, 32900, 1000) ||
  172265. PNG_OUT_OF_RANGE(info_ptr->int_x_red, 64000L, 1000) ||
  172266. PNG_OUT_OF_RANGE(info_ptr->int_y_red, 33000, 1000) ||
  172267. PNG_OUT_OF_RANGE(info_ptr->int_x_green, 30000, 1000) ||
  172268. PNG_OUT_OF_RANGE(info_ptr->int_y_green, 60000L, 1000) ||
  172269. PNG_OUT_OF_RANGE(info_ptr->int_x_blue, 15000, 1000) ||
  172270. PNG_OUT_OF_RANGE(info_ptr->int_y_blue, 6000, 1000))
  172271. {
  172272. png_warning(png_ptr,
  172273. "Ignoring incorrect cHRM value when sRGB is also present");
  172274. }
  172275. #endif /* PNG_FIXED_POINT_SUPPORTED */
  172276. #endif /* PNG_READ_cHRM_SUPPORTED */
  172277. png_set_sRGB_gAMA_and_cHRM(png_ptr, info_ptr, intent);
  172278. }
  172279. #endif /* PNG_READ_sRGB_SUPPORTED */
  172280. #if defined(PNG_READ_iCCP_SUPPORTED)
  172281. void /* PRIVATE */
  172282. png_handle_iCCP(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  172283. {
  172284. png_charp chunkdata;
  172285. png_byte compression_type;
  172286. png_bytep pC;
  172287. png_charp profile;
  172288. png_uint_32 skip = 0;
  172289. png_uint_32 profile_size, profile_length;
  172290. png_size_t slength, prefix_length, data_length;
  172291. png_debug(1, "in png_handle_iCCP\n");
  172292. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  172293. png_error(png_ptr, "Missing IHDR before iCCP");
  172294. else if (png_ptr->mode & PNG_HAVE_IDAT)
  172295. {
  172296. png_warning(png_ptr, "Invalid iCCP after IDAT");
  172297. png_crc_finish(png_ptr, length);
  172298. return;
  172299. }
  172300. else if (png_ptr->mode & PNG_HAVE_PLTE)
  172301. png_warning(png_ptr, "Out of place iCCP chunk");
  172302. if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_iCCP))
  172303. {
  172304. png_warning(png_ptr, "Duplicate iCCP chunk");
  172305. png_crc_finish(png_ptr, length);
  172306. return;
  172307. }
  172308. #ifdef PNG_MAX_MALLOC_64K
  172309. if (length > (png_uint_32)65535L)
  172310. {
  172311. png_warning(png_ptr, "iCCP chunk too large to fit in memory");
  172312. skip = length - (png_uint_32)65535L;
  172313. length = (png_uint_32)65535L;
  172314. }
  172315. #endif
  172316. chunkdata = (png_charp)png_malloc(png_ptr, length + 1);
  172317. slength = (png_size_t)length;
  172318. png_crc_read(png_ptr, (png_bytep)chunkdata, slength);
  172319. if (png_crc_finish(png_ptr, skip))
  172320. {
  172321. png_free(png_ptr, chunkdata);
  172322. return;
  172323. }
  172324. chunkdata[slength] = 0x00;
  172325. for (profile = chunkdata; *profile; profile++)
  172326. ;
  172327. ++profile;
  172328. if ( profile >= chunkdata + slength - 1)
  172329. {
  172330. png_free(png_ptr, chunkdata);
  172331. png_warning(png_ptr, "Malformed iCCP chunk");
  172332. return;
  172333. }
  172334. compression_type = *profile++;
  172335. if (compression_type)
  172336. {
  172337. png_warning(png_ptr, "Ignoring nonzero compression type in iCCP chunk");
  172338. compression_type=0x00; /* Reset it to zero (libpng-1.0.6 through 1.0.8
  172339. wrote nonzero) */
  172340. }
  172341. prefix_length = profile - chunkdata;
  172342. chunkdata = png_decompress_chunk(png_ptr, compression_type, chunkdata,
  172343. slength, prefix_length, &data_length);
  172344. profile_length = data_length - prefix_length;
  172345. if ( prefix_length > data_length || profile_length < 4)
  172346. {
  172347. png_free(png_ptr, chunkdata);
  172348. png_warning(png_ptr, "Profile size field missing from iCCP chunk");
  172349. return;
  172350. }
  172351. pC = (png_bytep)(chunkdata+prefix_length);
  172352. profile_size = ((*(pC ))<<24) |
  172353. ((*(pC+1))<<16) |
  172354. ((*(pC+2))<< 8) |
  172355. ((*(pC+3)) );
  172356. if(profile_size < profile_length)
  172357. profile_length = profile_size;
  172358. if(profile_size > profile_length)
  172359. {
  172360. png_free(png_ptr, chunkdata);
  172361. png_warning(png_ptr, "Ignoring truncated iCCP profile.");
  172362. return;
  172363. }
  172364. png_set_iCCP(png_ptr, info_ptr, chunkdata, compression_type,
  172365. chunkdata + prefix_length, profile_length);
  172366. png_free(png_ptr, chunkdata);
  172367. }
  172368. #endif /* PNG_READ_iCCP_SUPPORTED */
  172369. #if defined(PNG_READ_sPLT_SUPPORTED)
  172370. void /* PRIVATE */
  172371. png_handle_sPLT(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  172372. {
  172373. png_bytep chunkdata;
  172374. png_bytep entry_start;
  172375. png_sPLT_t new_palette;
  172376. #ifdef PNG_NO_POINTER_INDEXING
  172377. png_sPLT_entryp pp;
  172378. #endif
  172379. int data_length, entry_size, i;
  172380. png_uint_32 skip = 0;
  172381. png_size_t slength;
  172382. png_debug(1, "in png_handle_sPLT\n");
  172383. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  172384. png_error(png_ptr, "Missing IHDR before sPLT");
  172385. else if (png_ptr->mode & PNG_HAVE_IDAT)
  172386. {
  172387. png_warning(png_ptr, "Invalid sPLT after IDAT");
  172388. png_crc_finish(png_ptr, length);
  172389. return;
  172390. }
  172391. #ifdef PNG_MAX_MALLOC_64K
  172392. if (length > (png_uint_32)65535L)
  172393. {
  172394. png_warning(png_ptr, "sPLT chunk too large to fit in memory");
  172395. skip = length - (png_uint_32)65535L;
  172396. length = (png_uint_32)65535L;
  172397. }
  172398. #endif
  172399. chunkdata = (png_bytep)png_malloc(png_ptr, length + 1);
  172400. slength = (png_size_t)length;
  172401. png_crc_read(png_ptr, (png_bytep)chunkdata, slength);
  172402. if (png_crc_finish(png_ptr, skip))
  172403. {
  172404. png_free(png_ptr, chunkdata);
  172405. return;
  172406. }
  172407. chunkdata[slength] = 0x00;
  172408. for (entry_start = chunkdata; *entry_start; entry_start++)
  172409. ;
  172410. ++entry_start;
  172411. if (entry_start > chunkdata + slength - 2)
  172412. {
  172413. png_free(png_ptr, chunkdata);
  172414. png_warning(png_ptr, "malformed sPLT chunk");
  172415. return;
  172416. }
  172417. new_palette.depth = *entry_start++;
  172418. entry_size = (new_palette.depth == 8 ? 6 : 10);
  172419. data_length = (slength - (entry_start - chunkdata));
  172420. if (data_length % entry_size)
  172421. {
  172422. png_free(png_ptr, chunkdata);
  172423. png_warning(png_ptr, "sPLT chunk has bad length");
  172424. return;
  172425. }
  172426. new_palette.nentries = (png_int_32) ( data_length / entry_size);
  172427. if ((png_uint_32) new_palette.nentries > (png_uint_32) (PNG_SIZE_MAX /
  172428. png_sizeof(png_sPLT_entry)))
  172429. {
  172430. png_warning(png_ptr, "sPLT chunk too long");
  172431. return;
  172432. }
  172433. new_palette.entries = (png_sPLT_entryp)png_malloc_warn(
  172434. png_ptr, new_palette.nentries * png_sizeof(png_sPLT_entry));
  172435. if (new_palette.entries == NULL)
  172436. {
  172437. png_warning(png_ptr, "sPLT chunk requires too much memory");
  172438. return;
  172439. }
  172440. #ifndef PNG_NO_POINTER_INDEXING
  172441. for (i = 0; i < new_palette.nentries; i++)
  172442. {
  172443. png_sPLT_entryp pp = new_palette.entries + i;
  172444. if (new_palette.depth == 8)
  172445. {
  172446. pp->red = *entry_start++;
  172447. pp->green = *entry_start++;
  172448. pp->blue = *entry_start++;
  172449. pp->alpha = *entry_start++;
  172450. }
  172451. else
  172452. {
  172453. pp->red = png_get_uint_16(entry_start); entry_start += 2;
  172454. pp->green = png_get_uint_16(entry_start); entry_start += 2;
  172455. pp->blue = png_get_uint_16(entry_start); entry_start += 2;
  172456. pp->alpha = png_get_uint_16(entry_start); entry_start += 2;
  172457. }
  172458. pp->frequency = png_get_uint_16(entry_start); entry_start += 2;
  172459. }
  172460. #else
  172461. pp = new_palette.entries;
  172462. for (i = 0; i < new_palette.nentries; i++)
  172463. {
  172464. if (new_palette.depth == 8)
  172465. {
  172466. pp[i].red = *entry_start++;
  172467. pp[i].green = *entry_start++;
  172468. pp[i].blue = *entry_start++;
  172469. pp[i].alpha = *entry_start++;
  172470. }
  172471. else
  172472. {
  172473. pp[i].red = png_get_uint_16(entry_start); entry_start += 2;
  172474. pp[i].green = png_get_uint_16(entry_start); entry_start += 2;
  172475. pp[i].blue = png_get_uint_16(entry_start); entry_start += 2;
  172476. pp[i].alpha = png_get_uint_16(entry_start); entry_start += 2;
  172477. }
  172478. pp->frequency = png_get_uint_16(entry_start); entry_start += 2;
  172479. }
  172480. #endif
  172481. new_palette.name = (png_charp)chunkdata;
  172482. png_set_sPLT(png_ptr, info_ptr, &new_palette, 1);
  172483. png_free(png_ptr, chunkdata);
  172484. png_free(png_ptr, new_palette.entries);
  172485. }
  172486. #endif /* PNG_READ_sPLT_SUPPORTED */
  172487. #if defined(PNG_READ_tRNS_SUPPORTED)
  172488. void /* PRIVATE */
  172489. png_handle_tRNS(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  172490. {
  172491. png_byte readbuf[PNG_MAX_PALETTE_LENGTH];
  172492. int bit_mask;
  172493. png_debug(1, "in png_handle_tRNS\n");
  172494. bit_mask = (1 << png_ptr->bit_depth) - 1;
  172495. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  172496. png_error(png_ptr, "Missing IHDR before tRNS");
  172497. else if (png_ptr->mode & PNG_HAVE_IDAT)
  172498. {
  172499. png_warning(png_ptr, "Invalid tRNS after IDAT");
  172500. png_crc_finish(png_ptr, length);
  172501. return;
  172502. }
  172503. else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_tRNS))
  172504. {
  172505. png_warning(png_ptr, "Duplicate tRNS chunk");
  172506. png_crc_finish(png_ptr, length);
  172507. return;
  172508. }
  172509. if (png_ptr->color_type == PNG_COLOR_TYPE_GRAY)
  172510. {
  172511. png_byte buf[2];
  172512. if (length != 2)
  172513. {
  172514. png_warning(png_ptr, "Incorrect tRNS chunk length");
  172515. png_crc_finish(png_ptr, length);
  172516. return;
  172517. }
  172518. png_crc_read(png_ptr, buf, 2);
  172519. png_ptr->num_trans = 1;
  172520. png_ptr->trans_values.gray = png_get_uint_16(buf) & bit_mask;
  172521. }
  172522. else if (png_ptr->color_type == PNG_COLOR_TYPE_RGB)
  172523. {
  172524. png_byte buf[6];
  172525. if (length != 6)
  172526. {
  172527. png_warning(png_ptr, "Incorrect tRNS chunk length");
  172528. png_crc_finish(png_ptr, length);
  172529. return;
  172530. }
  172531. png_crc_read(png_ptr, buf, (png_size_t)length);
  172532. png_ptr->num_trans = 1;
  172533. png_ptr->trans_values.red = png_get_uint_16(buf) & bit_mask;
  172534. png_ptr->trans_values.green = png_get_uint_16(buf + 2) & bit_mask;
  172535. png_ptr->trans_values.blue = png_get_uint_16(buf + 4) & bit_mask;
  172536. }
  172537. else if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  172538. {
  172539. if (!(png_ptr->mode & PNG_HAVE_PLTE))
  172540. {
  172541. png_warning(png_ptr, "Missing PLTE before tRNS");
  172542. }
  172543. if (length > (png_uint_32)png_ptr->num_palette ||
  172544. length > PNG_MAX_PALETTE_LENGTH)
  172545. {
  172546. png_warning(png_ptr, "Incorrect tRNS chunk length");
  172547. png_crc_finish(png_ptr, length);
  172548. return;
  172549. }
  172550. if (length == 0)
  172551. {
  172552. png_warning(png_ptr, "Zero length tRNS chunk");
  172553. png_crc_finish(png_ptr, length);
  172554. return;
  172555. }
  172556. png_crc_read(png_ptr, readbuf, (png_size_t)length);
  172557. png_ptr->num_trans = (png_uint_16)length;
  172558. }
  172559. else
  172560. {
  172561. png_warning(png_ptr, "tRNS chunk not allowed with alpha channel");
  172562. png_crc_finish(png_ptr, length);
  172563. return;
  172564. }
  172565. if (png_crc_finish(png_ptr, 0))
  172566. {
  172567. png_ptr->num_trans = 0;
  172568. return;
  172569. }
  172570. png_set_tRNS(png_ptr, info_ptr, readbuf, png_ptr->num_trans,
  172571. &(png_ptr->trans_values));
  172572. }
  172573. #endif
  172574. #if defined(PNG_READ_bKGD_SUPPORTED)
  172575. void /* PRIVATE */
  172576. png_handle_bKGD(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  172577. {
  172578. png_size_t truelen;
  172579. png_byte buf[6];
  172580. png_debug(1, "in png_handle_bKGD\n");
  172581. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  172582. png_error(png_ptr, "Missing IHDR before bKGD");
  172583. else if (png_ptr->mode & PNG_HAVE_IDAT)
  172584. {
  172585. png_warning(png_ptr, "Invalid bKGD after IDAT");
  172586. png_crc_finish(png_ptr, length);
  172587. return;
  172588. }
  172589. else if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE &&
  172590. !(png_ptr->mode & PNG_HAVE_PLTE))
  172591. {
  172592. png_warning(png_ptr, "Missing PLTE before bKGD");
  172593. png_crc_finish(png_ptr, length);
  172594. return;
  172595. }
  172596. else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_bKGD))
  172597. {
  172598. png_warning(png_ptr, "Duplicate bKGD chunk");
  172599. png_crc_finish(png_ptr, length);
  172600. return;
  172601. }
  172602. if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  172603. truelen = 1;
  172604. else if (png_ptr->color_type & PNG_COLOR_MASK_COLOR)
  172605. truelen = 6;
  172606. else
  172607. truelen = 2;
  172608. if (length != truelen)
  172609. {
  172610. png_warning(png_ptr, "Incorrect bKGD chunk length");
  172611. png_crc_finish(png_ptr, length);
  172612. return;
  172613. }
  172614. png_crc_read(png_ptr, buf, truelen);
  172615. if (png_crc_finish(png_ptr, 0))
  172616. return;
  172617. if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  172618. {
  172619. png_ptr->background.index = buf[0];
  172620. if(info_ptr->num_palette)
  172621. {
  172622. if(buf[0] > info_ptr->num_palette)
  172623. {
  172624. png_warning(png_ptr, "Incorrect bKGD chunk index value");
  172625. return;
  172626. }
  172627. png_ptr->background.red =
  172628. (png_uint_16)png_ptr->palette[buf[0]].red;
  172629. png_ptr->background.green =
  172630. (png_uint_16)png_ptr->palette[buf[0]].green;
  172631. png_ptr->background.blue =
  172632. (png_uint_16)png_ptr->palette[buf[0]].blue;
  172633. }
  172634. }
  172635. else if (!(png_ptr->color_type & PNG_COLOR_MASK_COLOR)) /* GRAY */
  172636. {
  172637. png_ptr->background.red =
  172638. png_ptr->background.green =
  172639. png_ptr->background.blue =
  172640. png_ptr->background.gray = png_get_uint_16(buf);
  172641. }
  172642. else
  172643. {
  172644. png_ptr->background.red = png_get_uint_16(buf);
  172645. png_ptr->background.green = png_get_uint_16(buf + 2);
  172646. png_ptr->background.blue = png_get_uint_16(buf + 4);
  172647. }
  172648. png_set_bKGD(png_ptr, info_ptr, &(png_ptr->background));
  172649. }
  172650. #endif
  172651. #if defined(PNG_READ_hIST_SUPPORTED)
  172652. void /* PRIVATE */
  172653. png_handle_hIST(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  172654. {
  172655. unsigned int num, i;
  172656. png_uint_16 readbuf[PNG_MAX_PALETTE_LENGTH];
  172657. png_debug(1, "in png_handle_hIST\n");
  172658. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  172659. png_error(png_ptr, "Missing IHDR before hIST");
  172660. else if (png_ptr->mode & PNG_HAVE_IDAT)
  172661. {
  172662. png_warning(png_ptr, "Invalid hIST after IDAT");
  172663. png_crc_finish(png_ptr, length);
  172664. return;
  172665. }
  172666. else if (!(png_ptr->mode & PNG_HAVE_PLTE))
  172667. {
  172668. png_warning(png_ptr, "Missing PLTE before hIST");
  172669. png_crc_finish(png_ptr, length);
  172670. return;
  172671. }
  172672. else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_hIST))
  172673. {
  172674. png_warning(png_ptr, "Duplicate hIST chunk");
  172675. png_crc_finish(png_ptr, length);
  172676. return;
  172677. }
  172678. num = length / 2 ;
  172679. if (num != (unsigned int) png_ptr->num_palette || num >
  172680. (unsigned int) PNG_MAX_PALETTE_LENGTH)
  172681. {
  172682. png_warning(png_ptr, "Incorrect hIST chunk length");
  172683. png_crc_finish(png_ptr, length);
  172684. return;
  172685. }
  172686. for (i = 0; i < num; i++)
  172687. {
  172688. png_byte buf[2];
  172689. png_crc_read(png_ptr, buf, 2);
  172690. readbuf[i] = png_get_uint_16(buf);
  172691. }
  172692. if (png_crc_finish(png_ptr, 0))
  172693. return;
  172694. png_set_hIST(png_ptr, info_ptr, readbuf);
  172695. }
  172696. #endif
  172697. #if defined(PNG_READ_pHYs_SUPPORTED)
  172698. void /* PRIVATE */
  172699. png_handle_pHYs(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  172700. {
  172701. png_byte buf[9];
  172702. png_uint_32 res_x, res_y;
  172703. int unit_type;
  172704. png_debug(1, "in png_handle_pHYs\n");
  172705. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  172706. png_error(png_ptr, "Missing IHDR before pHYs");
  172707. else if (png_ptr->mode & PNG_HAVE_IDAT)
  172708. {
  172709. png_warning(png_ptr, "Invalid pHYs after IDAT");
  172710. png_crc_finish(png_ptr, length);
  172711. return;
  172712. }
  172713. else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_pHYs))
  172714. {
  172715. png_warning(png_ptr, "Duplicate pHYs chunk");
  172716. png_crc_finish(png_ptr, length);
  172717. return;
  172718. }
  172719. if (length != 9)
  172720. {
  172721. png_warning(png_ptr, "Incorrect pHYs chunk length");
  172722. png_crc_finish(png_ptr, length);
  172723. return;
  172724. }
  172725. png_crc_read(png_ptr, buf, 9);
  172726. if (png_crc_finish(png_ptr, 0))
  172727. return;
  172728. res_x = png_get_uint_32(buf);
  172729. res_y = png_get_uint_32(buf + 4);
  172730. unit_type = buf[8];
  172731. png_set_pHYs(png_ptr, info_ptr, res_x, res_y, unit_type);
  172732. }
  172733. #endif
  172734. #if defined(PNG_READ_oFFs_SUPPORTED)
  172735. void /* PRIVATE */
  172736. png_handle_oFFs(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  172737. {
  172738. png_byte buf[9];
  172739. png_int_32 offset_x, offset_y;
  172740. int unit_type;
  172741. png_debug(1, "in png_handle_oFFs\n");
  172742. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  172743. png_error(png_ptr, "Missing IHDR before oFFs");
  172744. else if (png_ptr->mode & PNG_HAVE_IDAT)
  172745. {
  172746. png_warning(png_ptr, "Invalid oFFs after IDAT");
  172747. png_crc_finish(png_ptr, length);
  172748. return;
  172749. }
  172750. else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_oFFs))
  172751. {
  172752. png_warning(png_ptr, "Duplicate oFFs chunk");
  172753. png_crc_finish(png_ptr, length);
  172754. return;
  172755. }
  172756. if (length != 9)
  172757. {
  172758. png_warning(png_ptr, "Incorrect oFFs chunk length");
  172759. png_crc_finish(png_ptr, length);
  172760. return;
  172761. }
  172762. png_crc_read(png_ptr, buf, 9);
  172763. if (png_crc_finish(png_ptr, 0))
  172764. return;
  172765. offset_x = png_get_int_32(buf);
  172766. offset_y = png_get_int_32(buf + 4);
  172767. unit_type = buf[8];
  172768. png_set_oFFs(png_ptr, info_ptr, offset_x, offset_y, unit_type);
  172769. }
  172770. #endif
  172771. #if defined(PNG_READ_pCAL_SUPPORTED)
  172772. void /* PRIVATE */
  172773. png_handle_pCAL(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  172774. {
  172775. png_charp purpose;
  172776. png_int_32 X0, X1;
  172777. png_byte type, nparams;
  172778. png_charp buf, units, endptr;
  172779. png_charpp params;
  172780. png_size_t slength;
  172781. int i;
  172782. png_debug(1, "in png_handle_pCAL\n");
  172783. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  172784. png_error(png_ptr, "Missing IHDR before pCAL");
  172785. else if (png_ptr->mode & PNG_HAVE_IDAT)
  172786. {
  172787. png_warning(png_ptr, "Invalid pCAL after IDAT");
  172788. png_crc_finish(png_ptr, length);
  172789. return;
  172790. }
  172791. else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_pCAL))
  172792. {
  172793. png_warning(png_ptr, "Duplicate pCAL chunk");
  172794. png_crc_finish(png_ptr, length);
  172795. return;
  172796. }
  172797. png_debug1(2, "Allocating and reading pCAL chunk data (%lu bytes)\n",
  172798. length + 1);
  172799. purpose = (png_charp)png_malloc_warn(png_ptr, length + 1);
  172800. if (purpose == NULL)
  172801. {
  172802. png_warning(png_ptr, "No memory for pCAL purpose.");
  172803. return;
  172804. }
  172805. slength = (png_size_t)length;
  172806. png_crc_read(png_ptr, (png_bytep)purpose, slength);
  172807. if (png_crc_finish(png_ptr, 0))
  172808. {
  172809. png_free(png_ptr, purpose);
  172810. return;
  172811. }
  172812. purpose[slength] = 0x00; /* null terminate the last string */
  172813. png_debug(3, "Finding end of pCAL purpose string\n");
  172814. for (buf = purpose; *buf; buf++)
  172815. ;
  172816. endptr = purpose + slength;
  172817. if (endptr <= buf + 12)
  172818. {
  172819. png_warning(png_ptr, "Invalid pCAL data");
  172820. png_free(png_ptr, purpose);
  172821. return;
  172822. }
  172823. png_debug(3, "Reading pCAL X0, X1, type, nparams, and units\n");
  172824. X0 = png_get_int_32((png_bytep)buf+1);
  172825. X1 = png_get_int_32((png_bytep)buf+5);
  172826. type = buf[9];
  172827. nparams = buf[10];
  172828. units = buf + 11;
  172829. png_debug(3, "Checking pCAL equation type and number of parameters\n");
  172830. if ((type == PNG_EQUATION_LINEAR && nparams != 2) ||
  172831. (type == PNG_EQUATION_BASE_E && nparams != 3) ||
  172832. (type == PNG_EQUATION_ARBITRARY && nparams != 3) ||
  172833. (type == PNG_EQUATION_HYPERBOLIC && nparams != 4))
  172834. {
  172835. png_warning(png_ptr, "Invalid pCAL parameters for equation type");
  172836. png_free(png_ptr, purpose);
  172837. return;
  172838. }
  172839. else if (type >= PNG_EQUATION_LAST)
  172840. {
  172841. png_warning(png_ptr, "Unrecognized equation type for pCAL chunk");
  172842. }
  172843. for (buf = units; *buf; buf++)
  172844. ;
  172845. png_debug(3, "Allocating pCAL parameters array\n");
  172846. params = (png_charpp)png_malloc_warn(png_ptr, (png_uint_32)(nparams
  172847. *png_sizeof(png_charp))) ;
  172848. if (params == NULL)
  172849. {
  172850. png_free(png_ptr, purpose);
  172851. png_warning(png_ptr, "No memory for pCAL params.");
  172852. return;
  172853. }
  172854. for (i = 0; i < (int)nparams; i++)
  172855. {
  172856. buf++; /* Skip the null string terminator from previous parameter. */
  172857. png_debug1(3, "Reading pCAL parameter %d\n", i);
  172858. for (params[i] = buf; buf <= endptr && *buf != 0x00; buf++)
  172859. ;
  172860. if (buf > endptr)
  172861. {
  172862. png_warning(png_ptr, "Invalid pCAL data");
  172863. png_free(png_ptr, purpose);
  172864. png_free(png_ptr, params);
  172865. return;
  172866. }
  172867. }
  172868. png_set_pCAL(png_ptr, info_ptr, purpose, X0, X1, type, nparams,
  172869. units, params);
  172870. png_free(png_ptr, purpose);
  172871. png_free(png_ptr, params);
  172872. }
  172873. #endif
  172874. #if defined(PNG_READ_sCAL_SUPPORTED)
  172875. void /* PRIVATE */
  172876. png_handle_sCAL(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  172877. {
  172878. png_charp buffer, ep;
  172879. #ifdef PNG_FLOATING_POINT_SUPPORTED
  172880. double width, height;
  172881. png_charp vp;
  172882. #else
  172883. #ifdef PNG_FIXED_POINT_SUPPORTED
  172884. png_charp swidth, sheight;
  172885. #endif
  172886. #endif
  172887. png_size_t slength;
  172888. png_debug(1, "in png_handle_sCAL\n");
  172889. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  172890. png_error(png_ptr, "Missing IHDR before sCAL");
  172891. else if (png_ptr->mode & PNG_HAVE_IDAT)
  172892. {
  172893. png_warning(png_ptr, "Invalid sCAL after IDAT");
  172894. png_crc_finish(png_ptr, length);
  172895. return;
  172896. }
  172897. else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_sCAL))
  172898. {
  172899. png_warning(png_ptr, "Duplicate sCAL chunk");
  172900. png_crc_finish(png_ptr, length);
  172901. return;
  172902. }
  172903. png_debug1(2, "Allocating and reading sCAL chunk data (%lu bytes)\n",
  172904. length + 1);
  172905. buffer = (png_charp)png_malloc_warn(png_ptr, length + 1);
  172906. if (buffer == NULL)
  172907. {
  172908. png_warning(png_ptr, "Out of memory while processing sCAL chunk");
  172909. return;
  172910. }
  172911. slength = (png_size_t)length;
  172912. png_crc_read(png_ptr, (png_bytep)buffer, slength);
  172913. if (png_crc_finish(png_ptr, 0))
  172914. {
  172915. png_free(png_ptr, buffer);
  172916. return;
  172917. }
  172918. buffer[slength] = 0x00; /* null terminate the last string */
  172919. ep = buffer + 1; /* skip unit byte */
  172920. #ifdef PNG_FLOATING_POINT_SUPPORTED
  172921. width = png_strtod(png_ptr, ep, &vp);
  172922. if (*vp)
  172923. {
  172924. png_warning(png_ptr, "malformed width string in sCAL chunk");
  172925. return;
  172926. }
  172927. #else
  172928. #ifdef PNG_FIXED_POINT_SUPPORTED
  172929. swidth = (png_charp)png_malloc_warn(png_ptr, png_strlen(ep) + 1);
  172930. if (swidth == NULL)
  172931. {
  172932. png_warning(png_ptr, "Out of memory while processing sCAL chunk width");
  172933. return;
  172934. }
  172935. png_memcpy(swidth, ep, (png_size_t)png_strlen(ep));
  172936. #endif
  172937. #endif
  172938. for (ep = buffer; *ep; ep++)
  172939. ;
  172940. ep++;
  172941. if (buffer + slength < ep)
  172942. {
  172943. png_warning(png_ptr, "Truncated sCAL chunk");
  172944. #if defined(PNG_FIXED_POINT_SUPPORTED) && \
  172945. !defined(PNG_FLOATING_POINT_SUPPORTED)
  172946. png_free(png_ptr, swidth);
  172947. #endif
  172948. png_free(png_ptr, buffer);
  172949. return;
  172950. }
  172951. #ifdef PNG_FLOATING_POINT_SUPPORTED
  172952. height = png_strtod(png_ptr, ep, &vp);
  172953. if (*vp)
  172954. {
  172955. png_warning(png_ptr, "malformed height string in sCAL chunk");
  172956. return;
  172957. }
  172958. #else
  172959. #ifdef PNG_FIXED_POINT_SUPPORTED
  172960. sheight = (png_charp)png_malloc_warn(png_ptr, png_strlen(ep) + 1);
  172961. if (swidth == NULL)
  172962. {
  172963. png_warning(png_ptr, "Out of memory while processing sCAL chunk height");
  172964. return;
  172965. }
  172966. png_memcpy(sheight, ep, (png_size_t)png_strlen(ep));
  172967. #endif
  172968. #endif
  172969. if (buffer + slength < ep
  172970. #ifdef PNG_FLOATING_POINT_SUPPORTED
  172971. || width <= 0. || height <= 0.
  172972. #endif
  172973. )
  172974. {
  172975. png_warning(png_ptr, "Invalid sCAL data");
  172976. png_free(png_ptr, buffer);
  172977. #if defined(PNG_FIXED_POINT_SUPPORTED) && !defined(PNG_FLOATING_POINT_SUPPORTED)
  172978. png_free(png_ptr, swidth);
  172979. png_free(png_ptr, sheight);
  172980. #endif
  172981. return;
  172982. }
  172983. #ifdef PNG_FLOATING_POINT_SUPPORTED
  172984. png_set_sCAL(png_ptr, info_ptr, buffer[0], width, height);
  172985. #else
  172986. #ifdef PNG_FIXED_POINT_SUPPORTED
  172987. png_set_sCAL_s(png_ptr, info_ptr, buffer[0], swidth, sheight);
  172988. #endif
  172989. #endif
  172990. png_free(png_ptr, buffer);
  172991. #if defined(PNG_FIXED_POINT_SUPPORTED) && !defined(PNG_FLOATING_POINT_SUPPORTED)
  172992. png_free(png_ptr, swidth);
  172993. png_free(png_ptr, sheight);
  172994. #endif
  172995. }
  172996. #endif
  172997. #if defined(PNG_READ_tIME_SUPPORTED)
  172998. void /* PRIVATE */
  172999. png_handle_tIME(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  173000. {
  173001. png_byte buf[7];
  173002. png_time mod_time;
  173003. png_debug(1, "in png_handle_tIME\n");
  173004. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  173005. png_error(png_ptr, "Out of place tIME chunk");
  173006. else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_tIME))
  173007. {
  173008. png_warning(png_ptr, "Duplicate tIME chunk");
  173009. png_crc_finish(png_ptr, length);
  173010. return;
  173011. }
  173012. if (png_ptr->mode & PNG_HAVE_IDAT)
  173013. png_ptr->mode |= PNG_AFTER_IDAT;
  173014. if (length != 7)
  173015. {
  173016. png_warning(png_ptr, "Incorrect tIME chunk length");
  173017. png_crc_finish(png_ptr, length);
  173018. return;
  173019. }
  173020. png_crc_read(png_ptr, buf, 7);
  173021. if (png_crc_finish(png_ptr, 0))
  173022. return;
  173023. mod_time.second = buf[6];
  173024. mod_time.minute = buf[5];
  173025. mod_time.hour = buf[4];
  173026. mod_time.day = buf[3];
  173027. mod_time.month = buf[2];
  173028. mod_time.year = png_get_uint_16(buf);
  173029. png_set_tIME(png_ptr, info_ptr, &mod_time);
  173030. }
  173031. #endif
  173032. #if defined(PNG_READ_tEXt_SUPPORTED)
  173033. void /* PRIVATE */
  173034. png_handle_tEXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  173035. {
  173036. png_textp text_ptr;
  173037. png_charp key;
  173038. png_charp text;
  173039. png_uint_32 skip = 0;
  173040. png_size_t slength;
  173041. int ret;
  173042. png_debug(1, "in png_handle_tEXt\n");
  173043. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  173044. png_error(png_ptr, "Missing IHDR before tEXt");
  173045. if (png_ptr->mode & PNG_HAVE_IDAT)
  173046. png_ptr->mode |= PNG_AFTER_IDAT;
  173047. #ifdef PNG_MAX_MALLOC_64K
  173048. if (length > (png_uint_32)65535L)
  173049. {
  173050. png_warning(png_ptr, "tEXt chunk too large to fit in memory");
  173051. skip = length - (png_uint_32)65535L;
  173052. length = (png_uint_32)65535L;
  173053. }
  173054. #endif
  173055. key = (png_charp)png_malloc_warn(png_ptr, length + 1);
  173056. if (key == NULL)
  173057. {
  173058. png_warning(png_ptr, "No memory to process text chunk.");
  173059. return;
  173060. }
  173061. slength = (png_size_t)length;
  173062. png_crc_read(png_ptr, (png_bytep)key, slength);
  173063. if (png_crc_finish(png_ptr, skip))
  173064. {
  173065. png_free(png_ptr, key);
  173066. return;
  173067. }
  173068. key[slength] = 0x00;
  173069. for (text = key; *text; text++)
  173070. ;
  173071. if (text != key + slength)
  173072. text++;
  173073. text_ptr = (png_textp)png_malloc_warn(png_ptr,
  173074. (png_uint_32)png_sizeof(png_text));
  173075. if (text_ptr == NULL)
  173076. {
  173077. png_warning(png_ptr, "Not enough memory to process text chunk.");
  173078. png_free(png_ptr, key);
  173079. return;
  173080. }
  173081. text_ptr->compression = PNG_TEXT_COMPRESSION_NONE;
  173082. text_ptr->key = key;
  173083. #ifdef PNG_iTXt_SUPPORTED
  173084. text_ptr->lang = NULL;
  173085. text_ptr->lang_key = NULL;
  173086. text_ptr->itxt_length = 0;
  173087. #endif
  173088. text_ptr->text = text;
  173089. text_ptr->text_length = png_strlen(text);
  173090. ret=png_set_text_2(png_ptr, info_ptr, text_ptr, 1);
  173091. png_free(png_ptr, key);
  173092. png_free(png_ptr, text_ptr);
  173093. if (ret)
  173094. png_warning(png_ptr, "Insufficient memory to process text chunk.");
  173095. }
  173096. #endif
  173097. #if defined(PNG_READ_zTXt_SUPPORTED)
  173098. void /* PRIVATE */
  173099. png_handle_zTXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  173100. {
  173101. png_textp text_ptr;
  173102. png_charp chunkdata;
  173103. png_charp text;
  173104. int comp_type;
  173105. int ret;
  173106. png_size_t slength, prefix_len, data_len;
  173107. png_debug(1, "in png_handle_zTXt\n");
  173108. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  173109. png_error(png_ptr, "Missing IHDR before zTXt");
  173110. if (png_ptr->mode & PNG_HAVE_IDAT)
  173111. png_ptr->mode |= PNG_AFTER_IDAT;
  173112. #ifdef PNG_MAX_MALLOC_64K
  173113. if (length > (png_uint_32)65535L)
  173114. {
  173115. png_warning(png_ptr,"zTXt chunk too large to fit in memory");
  173116. png_crc_finish(png_ptr, length);
  173117. return;
  173118. }
  173119. #endif
  173120. chunkdata = (png_charp)png_malloc_warn(png_ptr, length + 1);
  173121. if (chunkdata == NULL)
  173122. {
  173123. png_warning(png_ptr,"Out of memory processing zTXt chunk.");
  173124. return;
  173125. }
  173126. slength = (png_size_t)length;
  173127. png_crc_read(png_ptr, (png_bytep)chunkdata, slength);
  173128. if (png_crc_finish(png_ptr, 0))
  173129. {
  173130. png_free(png_ptr, chunkdata);
  173131. return;
  173132. }
  173133. chunkdata[slength] = 0x00;
  173134. for (text = chunkdata; *text; text++)
  173135. ;
  173136. if (text >= chunkdata + slength - 2)
  173137. {
  173138. png_warning(png_ptr, "Truncated zTXt chunk");
  173139. png_free(png_ptr, chunkdata);
  173140. return;
  173141. }
  173142. else
  173143. {
  173144. comp_type = *(++text);
  173145. if (comp_type != PNG_TEXT_COMPRESSION_zTXt)
  173146. {
  173147. png_warning(png_ptr, "Unknown compression type in zTXt chunk");
  173148. comp_type = PNG_TEXT_COMPRESSION_zTXt;
  173149. }
  173150. text++; /* skip the compression_method byte */
  173151. }
  173152. prefix_len = text - chunkdata;
  173153. chunkdata = (png_charp)png_decompress_chunk(png_ptr, comp_type, chunkdata,
  173154. (png_size_t)length, prefix_len, &data_len);
  173155. text_ptr = (png_textp)png_malloc_warn(png_ptr,
  173156. (png_uint_32)png_sizeof(png_text));
  173157. if (text_ptr == NULL)
  173158. {
  173159. png_warning(png_ptr,"Not enough memory to process zTXt chunk.");
  173160. png_free(png_ptr, chunkdata);
  173161. return;
  173162. }
  173163. text_ptr->compression = comp_type;
  173164. text_ptr->key = chunkdata;
  173165. #ifdef PNG_iTXt_SUPPORTED
  173166. text_ptr->lang = NULL;
  173167. text_ptr->lang_key = NULL;
  173168. text_ptr->itxt_length = 0;
  173169. #endif
  173170. text_ptr->text = chunkdata + prefix_len;
  173171. text_ptr->text_length = data_len;
  173172. ret=png_set_text_2(png_ptr, info_ptr, text_ptr, 1);
  173173. png_free(png_ptr, text_ptr);
  173174. png_free(png_ptr, chunkdata);
  173175. if (ret)
  173176. png_error(png_ptr, "Insufficient memory to store zTXt chunk.");
  173177. }
  173178. #endif
  173179. #if defined(PNG_READ_iTXt_SUPPORTED)
  173180. void /* PRIVATE */
  173181. png_handle_iTXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  173182. {
  173183. png_textp text_ptr;
  173184. png_charp chunkdata;
  173185. png_charp key, lang, text, lang_key;
  173186. int comp_flag;
  173187. int comp_type = 0;
  173188. int ret;
  173189. png_size_t slength, prefix_len, data_len;
  173190. png_debug(1, "in png_handle_iTXt\n");
  173191. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  173192. png_error(png_ptr, "Missing IHDR before iTXt");
  173193. if (png_ptr->mode & PNG_HAVE_IDAT)
  173194. png_ptr->mode |= PNG_AFTER_IDAT;
  173195. #ifdef PNG_MAX_MALLOC_64K
  173196. if (length > (png_uint_32)65535L)
  173197. {
  173198. png_warning(png_ptr,"iTXt chunk too large to fit in memory");
  173199. png_crc_finish(png_ptr, length);
  173200. return;
  173201. }
  173202. #endif
  173203. chunkdata = (png_charp)png_malloc_warn(png_ptr, length + 1);
  173204. if (chunkdata == NULL)
  173205. {
  173206. png_warning(png_ptr, "No memory to process iTXt chunk.");
  173207. return;
  173208. }
  173209. slength = (png_size_t)length;
  173210. png_crc_read(png_ptr, (png_bytep)chunkdata, slength);
  173211. if (png_crc_finish(png_ptr, 0))
  173212. {
  173213. png_free(png_ptr, chunkdata);
  173214. return;
  173215. }
  173216. chunkdata[slength] = 0x00;
  173217. for (lang = chunkdata; *lang; lang++)
  173218. ;
  173219. lang++; /* skip NUL separator */
  173220. if (lang >= chunkdata + slength - 3)
  173221. {
  173222. png_warning(png_ptr, "Truncated iTXt chunk");
  173223. png_free(png_ptr, chunkdata);
  173224. return;
  173225. }
  173226. else
  173227. {
  173228. comp_flag = *lang++;
  173229. comp_type = *lang++;
  173230. }
  173231. for (lang_key = lang; *lang_key; lang_key++)
  173232. ;
  173233. lang_key++; /* skip NUL separator */
  173234. if (lang_key >= chunkdata + slength)
  173235. {
  173236. png_warning(png_ptr, "Truncated iTXt chunk");
  173237. png_free(png_ptr, chunkdata);
  173238. return;
  173239. }
  173240. for (text = lang_key; *text; text++)
  173241. ;
  173242. text++; /* skip NUL separator */
  173243. if (text >= chunkdata + slength)
  173244. {
  173245. png_warning(png_ptr, "Malformed iTXt chunk");
  173246. png_free(png_ptr, chunkdata);
  173247. return;
  173248. }
  173249. prefix_len = text - chunkdata;
  173250. key=chunkdata;
  173251. if (comp_flag)
  173252. chunkdata = png_decompress_chunk(png_ptr, comp_type, chunkdata,
  173253. (size_t)length, prefix_len, &data_len);
  173254. else
  173255. data_len=png_strlen(chunkdata + prefix_len);
  173256. text_ptr = (png_textp)png_malloc_warn(png_ptr,
  173257. (png_uint_32)png_sizeof(png_text));
  173258. if (text_ptr == NULL)
  173259. {
  173260. png_warning(png_ptr,"Not enough memory to process iTXt chunk.");
  173261. png_free(png_ptr, chunkdata);
  173262. return;
  173263. }
  173264. text_ptr->compression = (int)comp_flag + 1;
  173265. text_ptr->lang_key = chunkdata+(lang_key-key);
  173266. text_ptr->lang = chunkdata+(lang-key);
  173267. text_ptr->itxt_length = data_len;
  173268. text_ptr->text_length = 0;
  173269. text_ptr->key = chunkdata;
  173270. text_ptr->text = chunkdata + prefix_len;
  173271. ret=png_set_text_2(png_ptr, info_ptr, text_ptr, 1);
  173272. png_free(png_ptr, text_ptr);
  173273. png_free(png_ptr, chunkdata);
  173274. if (ret)
  173275. png_error(png_ptr, "Insufficient memory to store iTXt chunk.");
  173276. }
  173277. #endif
  173278. void /* PRIVATE */
  173279. png_handle_unknown(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  173280. {
  173281. png_uint_32 skip = 0;
  173282. png_debug(1, "in png_handle_unknown\n");
  173283. if (png_ptr->mode & PNG_HAVE_IDAT)
  173284. {
  173285. #ifdef PNG_USE_LOCAL_ARRAYS
  173286. PNG_CONST PNG_IDAT;
  173287. #endif
  173288. if (png_memcmp(png_ptr->chunk_name, png_IDAT, 4)) /* not an IDAT */
  173289. png_ptr->mode |= PNG_AFTER_IDAT;
  173290. }
  173291. png_check_chunk_name(png_ptr, png_ptr->chunk_name);
  173292. if (!(png_ptr->chunk_name[0] & 0x20))
  173293. {
  173294. #if defined(PNG_READ_UNKNOWN_CHUNKS_SUPPORTED)
  173295. if(png_handle_as_unknown(png_ptr, png_ptr->chunk_name) !=
  173296. PNG_HANDLE_CHUNK_ALWAYS
  173297. #if defined(PNG_READ_USER_CHUNKS_SUPPORTED)
  173298. && png_ptr->read_user_chunk_fn == NULL
  173299. #endif
  173300. )
  173301. #endif
  173302. png_chunk_error(png_ptr, "unknown critical chunk");
  173303. }
  173304. #if defined(PNG_READ_UNKNOWN_CHUNKS_SUPPORTED)
  173305. if ((png_ptr->flags & PNG_FLAG_KEEP_UNKNOWN_CHUNKS) ||
  173306. (png_ptr->read_user_chunk_fn != NULL))
  173307. {
  173308. #ifdef PNG_MAX_MALLOC_64K
  173309. if (length > (png_uint_32)65535L)
  173310. {
  173311. png_warning(png_ptr, "unknown chunk too large to fit in memory");
  173312. skip = length - (png_uint_32)65535L;
  173313. length = (png_uint_32)65535L;
  173314. }
  173315. #endif
  173316. png_strncpy((png_charp)png_ptr->unknown_chunk.name,
  173317. (png_charp)png_ptr->chunk_name, 5);
  173318. png_ptr->unknown_chunk.data = (png_bytep)png_malloc(png_ptr, length);
  173319. png_ptr->unknown_chunk.size = (png_size_t)length;
  173320. png_crc_read(png_ptr, (png_bytep)png_ptr->unknown_chunk.data, length);
  173321. #if defined(PNG_READ_USER_CHUNKS_SUPPORTED)
  173322. if(png_ptr->read_user_chunk_fn != NULL)
  173323. {
  173324. int ret;
  173325. ret = (*(png_ptr->read_user_chunk_fn))
  173326. (png_ptr, &png_ptr->unknown_chunk);
  173327. if (ret < 0)
  173328. png_chunk_error(png_ptr, "error in user chunk");
  173329. if (ret == 0)
  173330. {
  173331. if (!(png_ptr->chunk_name[0] & 0x20))
  173332. if(png_handle_as_unknown(png_ptr, png_ptr->chunk_name) !=
  173333. PNG_HANDLE_CHUNK_ALWAYS)
  173334. png_chunk_error(png_ptr, "unknown critical chunk");
  173335. png_set_unknown_chunks(png_ptr, info_ptr,
  173336. &png_ptr->unknown_chunk, 1);
  173337. }
  173338. }
  173339. #else
  173340. png_set_unknown_chunks(png_ptr, info_ptr, &png_ptr->unknown_chunk, 1);
  173341. #endif
  173342. png_free(png_ptr, png_ptr->unknown_chunk.data);
  173343. png_ptr->unknown_chunk.data = NULL;
  173344. }
  173345. else
  173346. #endif
  173347. skip = length;
  173348. png_crc_finish(png_ptr, skip);
  173349. #if !defined(PNG_READ_USER_CHUNKS_SUPPORTED)
  173350. info_ptr = info_ptr; /* quiet compiler warnings about unused info_ptr */
  173351. #endif
  173352. }
  173353. #define isnonalpha(c) ((c) < 65 || (c) > 122 || ((c) > 90 && (c) < 97))
  173354. void /* PRIVATE */
  173355. png_check_chunk_name(png_structp png_ptr, png_bytep chunk_name)
  173356. {
  173357. png_debug(1, "in png_check_chunk_name\n");
  173358. if (isnonalpha(chunk_name[0]) || isnonalpha(chunk_name[1]) ||
  173359. isnonalpha(chunk_name[2]) || isnonalpha(chunk_name[3]))
  173360. {
  173361. png_chunk_error(png_ptr, "invalid chunk type");
  173362. }
  173363. }
  173364. void /* PRIVATE */
  173365. png_combine_row(png_structp png_ptr, png_bytep row, int mask)
  173366. {
  173367. png_debug(1,"in png_combine_row\n");
  173368. if (mask == 0xff)
  173369. {
  173370. png_memcpy(row, png_ptr->row_buf + 1,
  173371. PNG_ROWBYTES(png_ptr->row_info.pixel_depth, png_ptr->width));
  173372. }
  173373. else
  173374. {
  173375. switch (png_ptr->row_info.pixel_depth)
  173376. {
  173377. case 1:
  173378. {
  173379. png_bytep sp = png_ptr->row_buf + 1;
  173380. png_bytep dp = row;
  173381. int s_inc, s_start, s_end;
  173382. int m = 0x80;
  173383. int shift;
  173384. png_uint_32 i;
  173385. png_uint_32 row_width = png_ptr->width;
  173386. #if defined(PNG_READ_PACKSWAP_SUPPORTED)
  173387. if (png_ptr->transformations & PNG_PACKSWAP)
  173388. {
  173389. s_start = 0;
  173390. s_end = 7;
  173391. s_inc = 1;
  173392. }
  173393. else
  173394. #endif
  173395. {
  173396. s_start = 7;
  173397. s_end = 0;
  173398. s_inc = -1;
  173399. }
  173400. shift = s_start;
  173401. for (i = 0; i < row_width; i++)
  173402. {
  173403. if (m & mask)
  173404. {
  173405. int value;
  173406. value = (*sp >> shift) & 0x01;
  173407. *dp &= (png_byte)((0x7f7f >> (7 - shift)) & 0xff);
  173408. *dp |= (png_byte)(value << shift);
  173409. }
  173410. if (shift == s_end)
  173411. {
  173412. shift = s_start;
  173413. sp++;
  173414. dp++;
  173415. }
  173416. else
  173417. shift += s_inc;
  173418. if (m == 1)
  173419. m = 0x80;
  173420. else
  173421. m >>= 1;
  173422. }
  173423. break;
  173424. }
  173425. case 2:
  173426. {
  173427. png_bytep sp = png_ptr->row_buf + 1;
  173428. png_bytep dp = row;
  173429. int s_start, s_end, s_inc;
  173430. int m = 0x80;
  173431. int shift;
  173432. png_uint_32 i;
  173433. png_uint_32 row_width = png_ptr->width;
  173434. int value;
  173435. #if defined(PNG_READ_PACKSWAP_SUPPORTED)
  173436. if (png_ptr->transformations & PNG_PACKSWAP)
  173437. {
  173438. s_start = 0;
  173439. s_end = 6;
  173440. s_inc = 2;
  173441. }
  173442. else
  173443. #endif
  173444. {
  173445. s_start = 6;
  173446. s_end = 0;
  173447. s_inc = -2;
  173448. }
  173449. shift = s_start;
  173450. for (i = 0; i < row_width; i++)
  173451. {
  173452. if (m & mask)
  173453. {
  173454. value = (*sp >> shift) & 0x03;
  173455. *dp &= (png_byte)((0x3f3f >> (6 - shift)) & 0xff);
  173456. *dp |= (png_byte)(value << shift);
  173457. }
  173458. if (shift == s_end)
  173459. {
  173460. shift = s_start;
  173461. sp++;
  173462. dp++;
  173463. }
  173464. else
  173465. shift += s_inc;
  173466. if (m == 1)
  173467. m = 0x80;
  173468. else
  173469. m >>= 1;
  173470. }
  173471. break;
  173472. }
  173473. case 4:
  173474. {
  173475. png_bytep sp = png_ptr->row_buf + 1;
  173476. png_bytep dp = row;
  173477. int s_start, s_end, s_inc;
  173478. int m = 0x80;
  173479. int shift;
  173480. png_uint_32 i;
  173481. png_uint_32 row_width = png_ptr->width;
  173482. int value;
  173483. #if defined(PNG_READ_PACKSWAP_SUPPORTED)
  173484. if (png_ptr->transformations & PNG_PACKSWAP)
  173485. {
  173486. s_start = 0;
  173487. s_end = 4;
  173488. s_inc = 4;
  173489. }
  173490. else
  173491. #endif
  173492. {
  173493. s_start = 4;
  173494. s_end = 0;
  173495. s_inc = -4;
  173496. }
  173497. shift = s_start;
  173498. for (i = 0; i < row_width; i++)
  173499. {
  173500. if (m & mask)
  173501. {
  173502. value = (*sp >> shift) & 0xf;
  173503. *dp &= (png_byte)((0xf0f >> (4 - shift)) & 0xff);
  173504. *dp |= (png_byte)(value << shift);
  173505. }
  173506. if (shift == s_end)
  173507. {
  173508. shift = s_start;
  173509. sp++;
  173510. dp++;
  173511. }
  173512. else
  173513. shift += s_inc;
  173514. if (m == 1)
  173515. m = 0x80;
  173516. else
  173517. m >>= 1;
  173518. }
  173519. break;
  173520. }
  173521. default:
  173522. {
  173523. png_bytep sp = png_ptr->row_buf + 1;
  173524. png_bytep dp = row;
  173525. png_size_t pixel_bytes = (png_ptr->row_info.pixel_depth >> 3);
  173526. png_uint_32 i;
  173527. png_uint_32 row_width = png_ptr->width;
  173528. png_byte m = 0x80;
  173529. for (i = 0; i < row_width; i++)
  173530. {
  173531. if (m & mask)
  173532. {
  173533. png_memcpy(dp, sp, pixel_bytes);
  173534. }
  173535. sp += pixel_bytes;
  173536. dp += pixel_bytes;
  173537. if (m == 1)
  173538. m = 0x80;
  173539. else
  173540. m >>= 1;
  173541. }
  173542. break;
  173543. }
  173544. }
  173545. }
  173546. }
  173547. #ifdef PNG_READ_INTERLACING_SUPPORTED
  173548. void /* PRIVATE */
  173549. png_do_read_interlace(png_structp png_ptr)
  173550. {
  173551. png_row_infop row_info = &(png_ptr->row_info);
  173552. png_bytep row = png_ptr->row_buf + 1;
  173553. int pass = png_ptr->pass;
  173554. png_uint_32 transformations = png_ptr->transformations;
  173555. #ifdef PNG_USE_LOCAL_ARRAYS
  173556. PNG_CONST int png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1};
  173557. #endif
  173558. png_debug(1,"in png_do_read_interlace\n");
  173559. if (row != NULL && row_info != NULL)
  173560. {
  173561. png_uint_32 final_width;
  173562. final_width = row_info->width * png_pass_inc[pass];
  173563. switch (row_info->pixel_depth)
  173564. {
  173565. case 1:
  173566. {
  173567. png_bytep sp = row + (png_size_t)((row_info->width - 1) >> 3);
  173568. png_bytep dp = row + (png_size_t)((final_width - 1) >> 3);
  173569. int sshift, dshift;
  173570. int s_start, s_end, s_inc;
  173571. int jstop = png_pass_inc[pass];
  173572. png_byte v;
  173573. png_uint_32 i;
  173574. int j;
  173575. #if defined(PNG_READ_PACKSWAP_SUPPORTED)
  173576. if (transformations & PNG_PACKSWAP)
  173577. {
  173578. sshift = (int)((row_info->width + 7) & 0x07);
  173579. dshift = (int)((final_width + 7) & 0x07);
  173580. s_start = 7;
  173581. s_end = 0;
  173582. s_inc = -1;
  173583. }
  173584. else
  173585. #endif
  173586. {
  173587. sshift = 7 - (int)((row_info->width + 7) & 0x07);
  173588. dshift = 7 - (int)((final_width + 7) & 0x07);
  173589. s_start = 0;
  173590. s_end = 7;
  173591. s_inc = 1;
  173592. }
  173593. for (i = 0; i < row_info->width; i++)
  173594. {
  173595. v = (png_byte)((*sp >> sshift) & 0x01);
  173596. for (j = 0; j < jstop; j++)
  173597. {
  173598. *dp &= (png_byte)((0x7f7f >> (7 - dshift)) & 0xff);
  173599. *dp |= (png_byte)(v << dshift);
  173600. if (dshift == s_end)
  173601. {
  173602. dshift = s_start;
  173603. dp--;
  173604. }
  173605. else
  173606. dshift += s_inc;
  173607. }
  173608. if (sshift == s_end)
  173609. {
  173610. sshift = s_start;
  173611. sp--;
  173612. }
  173613. else
  173614. sshift += s_inc;
  173615. }
  173616. break;
  173617. }
  173618. case 2:
  173619. {
  173620. png_bytep sp = row + (png_uint_32)((row_info->width - 1) >> 2);
  173621. png_bytep dp = row + (png_uint_32)((final_width - 1) >> 2);
  173622. int sshift, dshift;
  173623. int s_start, s_end, s_inc;
  173624. int jstop = png_pass_inc[pass];
  173625. png_uint_32 i;
  173626. #if defined(PNG_READ_PACKSWAP_SUPPORTED)
  173627. if (transformations & PNG_PACKSWAP)
  173628. {
  173629. sshift = (int)(((row_info->width + 3) & 0x03) << 1);
  173630. dshift = (int)(((final_width + 3) & 0x03) << 1);
  173631. s_start = 6;
  173632. s_end = 0;
  173633. s_inc = -2;
  173634. }
  173635. else
  173636. #endif
  173637. {
  173638. sshift = (int)((3 - ((row_info->width + 3) & 0x03)) << 1);
  173639. dshift = (int)((3 - ((final_width + 3) & 0x03)) << 1);
  173640. s_start = 0;
  173641. s_end = 6;
  173642. s_inc = 2;
  173643. }
  173644. for (i = 0; i < row_info->width; i++)
  173645. {
  173646. png_byte v;
  173647. int j;
  173648. v = (png_byte)((*sp >> sshift) & 0x03);
  173649. for (j = 0; j < jstop; j++)
  173650. {
  173651. *dp &= (png_byte)((0x3f3f >> (6 - dshift)) & 0xff);
  173652. *dp |= (png_byte)(v << dshift);
  173653. if (dshift == s_end)
  173654. {
  173655. dshift = s_start;
  173656. dp--;
  173657. }
  173658. else
  173659. dshift += s_inc;
  173660. }
  173661. if (sshift == s_end)
  173662. {
  173663. sshift = s_start;
  173664. sp--;
  173665. }
  173666. else
  173667. sshift += s_inc;
  173668. }
  173669. break;
  173670. }
  173671. case 4:
  173672. {
  173673. png_bytep sp = row + (png_size_t)((row_info->width - 1) >> 1);
  173674. png_bytep dp = row + (png_size_t)((final_width - 1) >> 1);
  173675. int sshift, dshift;
  173676. int s_start, s_end, s_inc;
  173677. png_uint_32 i;
  173678. int jstop = png_pass_inc[pass];
  173679. #if defined(PNG_READ_PACKSWAP_SUPPORTED)
  173680. if (transformations & PNG_PACKSWAP)
  173681. {
  173682. sshift = (int)(((row_info->width + 1) & 0x01) << 2);
  173683. dshift = (int)(((final_width + 1) & 0x01) << 2);
  173684. s_start = 4;
  173685. s_end = 0;
  173686. s_inc = -4;
  173687. }
  173688. else
  173689. #endif
  173690. {
  173691. sshift = (int)((1 - ((row_info->width + 1) & 0x01)) << 2);
  173692. dshift = (int)((1 - ((final_width + 1) & 0x01)) << 2);
  173693. s_start = 0;
  173694. s_end = 4;
  173695. s_inc = 4;
  173696. }
  173697. for (i = 0; i < row_info->width; i++)
  173698. {
  173699. png_byte v = (png_byte)((*sp >> sshift) & 0xf);
  173700. int j;
  173701. for (j = 0; j < jstop; j++)
  173702. {
  173703. *dp &= (png_byte)((0xf0f >> (4 - dshift)) & 0xff);
  173704. *dp |= (png_byte)(v << dshift);
  173705. if (dshift == s_end)
  173706. {
  173707. dshift = s_start;
  173708. dp--;
  173709. }
  173710. else
  173711. dshift += s_inc;
  173712. }
  173713. if (sshift == s_end)
  173714. {
  173715. sshift = s_start;
  173716. sp--;
  173717. }
  173718. else
  173719. sshift += s_inc;
  173720. }
  173721. break;
  173722. }
  173723. default:
  173724. {
  173725. png_size_t pixel_bytes = (row_info->pixel_depth >> 3);
  173726. png_bytep sp = row + (png_size_t)(row_info->width - 1) * pixel_bytes;
  173727. png_bytep dp = row + (png_size_t)(final_width - 1) * pixel_bytes;
  173728. int jstop = png_pass_inc[pass];
  173729. png_uint_32 i;
  173730. for (i = 0; i < row_info->width; i++)
  173731. {
  173732. png_byte v[8];
  173733. int j;
  173734. png_memcpy(v, sp, pixel_bytes);
  173735. for (j = 0; j < jstop; j++)
  173736. {
  173737. png_memcpy(dp, v, pixel_bytes);
  173738. dp -= pixel_bytes;
  173739. }
  173740. sp -= pixel_bytes;
  173741. }
  173742. break;
  173743. }
  173744. }
  173745. row_info->width = final_width;
  173746. row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,final_width);
  173747. }
  173748. #if !defined(PNG_READ_PACKSWAP_SUPPORTED)
  173749. transformations = transformations; /* silence compiler warning */
  173750. #endif
  173751. }
  173752. #endif /* PNG_READ_INTERLACING_SUPPORTED */
  173753. void /* PRIVATE */
  173754. png_read_filter_row(png_structp png_ptr, png_row_infop row_info, png_bytep row,
  173755. png_bytep prev_row, int filter)
  173756. {
  173757. png_debug(1, "in png_read_filter_row\n");
  173758. png_debug2(2,"row = %lu, filter = %d\n", png_ptr->row_number, filter);
  173759. switch (filter)
  173760. {
  173761. case PNG_FILTER_VALUE_NONE:
  173762. break;
  173763. case PNG_FILTER_VALUE_SUB:
  173764. {
  173765. png_uint_32 i;
  173766. png_uint_32 istop = row_info->rowbytes;
  173767. png_uint_32 bpp = (row_info->pixel_depth + 7) >> 3;
  173768. png_bytep rp = row + bpp;
  173769. png_bytep lp = row;
  173770. for (i = bpp; i < istop; i++)
  173771. {
  173772. *rp = (png_byte)(((int)(*rp) + (int)(*lp++)) & 0xff);
  173773. rp++;
  173774. }
  173775. break;
  173776. }
  173777. case PNG_FILTER_VALUE_UP:
  173778. {
  173779. png_uint_32 i;
  173780. png_uint_32 istop = row_info->rowbytes;
  173781. png_bytep rp = row;
  173782. png_bytep pp = prev_row;
  173783. for (i = 0; i < istop; i++)
  173784. {
  173785. *rp = (png_byte)(((int)(*rp) + (int)(*pp++)) & 0xff);
  173786. rp++;
  173787. }
  173788. break;
  173789. }
  173790. case PNG_FILTER_VALUE_AVG:
  173791. {
  173792. png_uint_32 i;
  173793. png_bytep rp = row;
  173794. png_bytep pp = prev_row;
  173795. png_bytep lp = row;
  173796. png_uint_32 bpp = (row_info->pixel_depth + 7) >> 3;
  173797. png_uint_32 istop = row_info->rowbytes - bpp;
  173798. for (i = 0; i < bpp; i++)
  173799. {
  173800. *rp = (png_byte)(((int)(*rp) +
  173801. ((int)(*pp++) / 2 )) & 0xff);
  173802. rp++;
  173803. }
  173804. for (i = 0; i < istop; i++)
  173805. {
  173806. *rp = (png_byte)(((int)(*rp) +
  173807. (int)(*pp++ + *lp++) / 2 ) & 0xff);
  173808. rp++;
  173809. }
  173810. break;
  173811. }
  173812. case PNG_FILTER_VALUE_PAETH:
  173813. {
  173814. png_uint_32 i;
  173815. png_bytep rp = row;
  173816. png_bytep pp = prev_row;
  173817. png_bytep lp = row;
  173818. png_bytep cp = prev_row;
  173819. png_uint_32 bpp = (row_info->pixel_depth + 7) >> 3;
  173820. png_uint_32 istop=row_info->rowbytes - bpp;
  173821. for (i = 0; i < bpp; i++)
  173822. {
  173823. *rp = (png_byte)(((int)(*rp) + (int)(*pp++)) & 0xff);
  173824. rp++;
  173825. }
  173826. for (i = 0; i < istop; i++) /* use leftover rp,pp */
  173827. {
  173828. int a, b, c, pa, pb, pc, p;
  173829. a = *lp++;
  173830. b = *pp++;
  173831. c = *cp++;
  173832. p = b - c;
  173833. pc = a - c;
  173834. #ifdef PNG_USE_ABS
  173835. pa = abs(p);
  173836. pb = abs(pc);
  173837. pc = abs(p + pc);
  173838. #else
  173839. pa = p < 0 ? -p : p;
  173840. pb = pc < 0 ? -pc : pc;
  173841. pc = (p + pc) < 0 ? -(p + pc) : p + pc;
  173842. #endif
  173843. p = (pa <= pb && pa <=pc) ? a : (pb <= pc) ? b : c;
  173844. *rp = (png_byte)(((int)(*rp) + p) & 0xff);
  173845. rp++;
  173846. }
  173847. break;
  173848. }
  173849. default:
  173850. png_warning(png_ptr, "Ignoring bad adaptive filter type");
  173851. *row=0;
  173852. break;
  173853. }
  173854. }
  173855. void /* PRIVATE */
  173856. png_read_finish_row(png_structp png_ptr)
  173857. {
  173858. #ifdef PNG_USE_LOCAL_ARRAYS
  173859. PNG_CONST int png_pass_start[7] = {0, 4, 0, 2, 0, 1, 0};
  173860. PNG_CONST int png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1};
  173861. PNG_CONST int png_pass_ystart[7] = {0, 0, 4, 0, 2, 0, 1};
  173862. PNG_CONST int png_pass_yinc[7] = {8, 8, 8, 4, 4, 2, 2};
  173863. #endif
  173864. png_debug(1, "in png_read_finish_row\n");
  173865. png_ptr->row_number++;
  173866. if (png_ptr->row_number < png_ptr->num_rows)
  173867. return;
  173868. if (png_ptr->interlaced)
  173869. {
  173870. png_ptr->row_number = 0;
  173871. png_memset_check(png_ptr, png_ptr->prev_row, 0,
  173872. png_ptr->rowbytes + 1);
  173873. do
  173874. {
  173875. png_ptr->pass++;
  173876. if (png_ptr->pass >= 7)
  173877. break;
  173878. png_ptr->iwidth = (png_ptr->width +
  173879. png_pass_inc[png_ptr->pass] - 1 -
  173880. png_pass_start[png_ptr->pass]) /
  173881. png_pass_inc[png_ptr->pass];
  173882. png_ptr->irowbytes = PNG_ROWBYTES(png_ptr->pixel_depth,
  173883. png_ptr->iwidth) + 1;
  173884. if (!(png_ptr->transformations & PNG_INTERLACE))
  173885. {
  173886. png_ptr->num_rows = (png_ptr->height +
  173887. png_pass_yinc[png_ptr->pass] - 1 -
  173888. png_pass_ystart[png_ptr->pass]) /
  173889. png_pass_yinc[png_ptr->pass];
  173890. if (!(png_ptr->num_rows))
  173891. continue;
  173892. }
  173893. else /* if (png_ptr->transformations & PNG_INTERLACE) */
  173894. break;
  173895. } while (png_ptr->iwidth == 0);
  173896. if (png_ptr->pass < 7)
  173897. return;
  173898. }
  173899. if (!(png_ptr->flags & PNG_FLAG_ZLIB_FINISHED))
  173900. {
  173901. #ifdef PNG_USE_LOCAL_ARRAYS
  173902. PNG_CONST PNG_IDAT;
  173903. #endif
  173904. char extra;
  173905. int ret;
  173906. png_ptr->zstream.next_out = (Bytef *)&extra;
  173907. png_ptr->zstream.avail_out = (uInt)1;
  173908. for(;;)
  173909. {
  173910. if (!(png_ptr->zstream.avail_in))
  173911. {
  173912. while (!png_ptr->idat_size)
  173913. {
  173914. png_byte chunk_length[4];
  173915. png_crc_finish(png_ptr, 0);
  173916. png_read_data(png_ptr, chunk_length, 4);
  173917. png_ptr->idat_size = png_get_uint_31(png_ptr, chunk_length);
  173918. png_reset_crc(png_ptr);
  173919. png_crc_read(png_ptr, png_ptr->chunk_name, 4);
  173920. if (png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  173921. png_error(png_ptr, "Not enough image data");
  173922. }
  173923. png_ptr->zstream.avail_in = (uInt)png_ptr->zbuf_size;
  173924. png_ptr->zstream.next_in = png_ptr->zbuf;
  173925. if (png_ptr->zbuf_size > png_ptr->idat_size)
  173926. png_ptr->zstream.avail_in = (uInt)png_ptr->idat_size;
  173927. png_crc_read(png_ptr, png_ptr->zbuf, png_ptr->zstream.avail_in);
  173928. png_ptr->idat_size -= png_ptr->zstream.avail_in;
  173929. }
  173930. ret = inflate(&png_ptr->zstream, Z_PARTIAL_FLUSH);
  173931. if (ret == Z_STREAM_END)
  173932. {
  173933. if (!(png_ptr->zstream.avail_out) || png_ptr->zstream.avail_in ||
  173934. png_ptr->idat_size)
  173935. png_warning(png_ptr, "Extra compressed data");
  173936. png_ptr->mode |= PNG_AFTER_IDAT;
  173937. png_ptr->flags |= PNG_FLAG_ZLIB_FINISHED;
  173938. break;
  173939. }
  173940. if (ret != Z_OK)
  173941. png_error(png_ptr, png_ptr->zstream.msg ? png_ptr->zstream.msg :
  173942. "Decompression Error");
  173943. if (!(png_ptr->zstream.avail_out))
  173944. {
  173945. png_warning(png_ptr, "Extra compressed data.");
  173946. png_ptr->mode |= PNG_AFTER_IDAT;
  173947. png_ptr->flags |= PNG_FLAG_ZLIB_FINISHED;
  173948. break;
  173949. }
  173950. }
  173951. png_ptr->zstream.avail_out = 0;
  173952. }
  173953. if (png_ptr->idat_size || png_ptr->zstream.avail_in)
  173954. png_warning(png_ptr, "Extra compression data");
  173955. inflateReset(&png_ptr->zstream);
  173956. png_ptr->mode |= PNG_AFTER_IDAT;
  173957. }
  173958. void /* PRIVATE */
  173959. png_read_start_row(png_structp png_ptr)
  173960. {
  173961. #ifdef PNG_USE_LOCAL_ARRAYS
  173962. PNG_CONST int png_pass_start[7] = {0, 4, 0, 2, 0, 1, 0};
  173963. PNG_CONST int png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1};
  173964. PNG_CONST int png_pass_ystart[7] = {0, 0, 4, 0, 2, 0, 1};
  173965. PNG_CONST int png_pass_yinc[7] = {8, 8, 8, 4, 4, 2, 2};
  173966. #endif
  173967. int max_pixel_depth;
  173968. png_uint_32 row_bytes;
  173969. png_debug(1, "in png_read_start_row\n");
  173970. png_ptr->zstream.avail_in = 0;
  173971. png_init_read_transformations(png_ptr);
  173972. if (png_ptr->interlaced)
  173973. {
  173974. if (!(png_ptr->transformations & PNG_INTERLACE))
  173975. png_ptr->num_rows = (png_ptr->height + png_pass_yinc[0] - 1 -
  173976. png_pass_ystart[0]) / png_pass_yinc[0];
  173977. else
  173978. png_ptr->num_rows = png_ptr->height;
  173979. png_ptr->iwidth = (png_ptr->width +
  173980. png_pass_inc[png_ptr->pass] - 1 -
  173981. png_pass_start[png_ptr->pass]) /
  173982. png_pass_inc[png_ptr->pass];
  173983. row_bytes = PNG_ROWBYTES(png_ptr->pixel_depth,png_ptr->iwidth) + 1;
  173984. png_ptr->irowbytes = (png_size_t)row_bytes;
  173985. if((png_uint_32)png_ptr->irowbytes != row_bytes)
  173986. png_error(png_ptr, "Rowbytes overflow in png_read_start_row");
  173987. }
  173988. else
  173989. {
  173990. png_ptr->num_rows = png_ptr->height;
  173991. png_ptr->iwidth = png_ptr->width;
  173992. png_ptr->irowbytes = png_ptr->rowbytes + 1;
  173993. }
  173994. max_pixel_depth = png_ptr->pixel_depth;
  173995. #if defined(PNG_READ_PACK_SUPPORTED)
  173996. if ((png_ptr->transformations & PNG_PACK) && png_ptr->bit_depth < 8)
  173997. max_pixel_depth = 8;
  173998. #endif
  173999. #if defined(PNG_READ_EXPAND_SUPPORTED)
  174000. if (png_ptr->transformations & PNG_EXPAND)
  174001. {
  174002. if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  174003. {
  174004. if (png_ptr->num_trans)
  174005. max_pixel_depth = 32;
  174006. else
  174007. max_pixel_depth = 24;
  174008. }
  174009. else if (png_ptr->color_type == PNG_COLOR_TYPE_GRAY)
  174010. {
  174011. if (max_pixel_depth < 8)
  174012. max_pixel_depth = 8;
  174013. if (png_ptr->num_trans)
  174014. max_pixel_depth *= 2;
  174015. }
  174016. else if (png_ptr->color_type == PNG_COLOR_TYPE_RGB)
  174017. {
  174018. if (png_ptr->num_trans)
  174019. {
  174020. max_pixel_depth *= 4;
  174021. max_pixel_depth /= 3;
  174022. }
  174023. }
  174024. }
  174025. #endif
  174026. #if defined(PNG_READ_FILLER_SUPPORTED)
  174027. if (png_ptr->transformations & (PNG_FILLER))
  174028. {
  174029. if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  174030. max_pixel_depth = 32;
  174031. else if (png_ptr->color_type == PNG_COLOR_TYPE_GRAY)
  174032. {
  174033. if (max_pixel_depth <= 8)
  174034. max_pixel_depth = 16;
  174035. else
  174036. max_pixel_depth = 32;
  174037. }
  174038. else if (png_ptr->color_type == PNG_COLOR_TYPE_RGB)
  174039. {
  174040. if (max_pixel_depth <= 32)
  174041. max_pixel_depth = 32;
  174042. else
  174043. max_pixel_depth = 64;
  174044. }
  174045. }
  174046. #endif
  174047. #if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED)
  174048. if (png_ptr->transformations & PNG_GRAY_TO_RGB)
  174049. {
  174050. if (
  174051. #if defined(PNG_READ_EXPAND_SUPPORTED)
  174052. (png_ptr->num_trans && (png_ptr->transformations & PNG_EXPAND)) ||
  174053. #endif
  174054. #if defined(PNG_READ_FILLER_SUPPORTED)
  174055. (png_ptr->transformations & (PNG_FILLER)) ||
  174056. #endif
  174057. png_ptr->color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
  174058. {
  174059. if (max_pixel_depth <= 16)
  174060. max_pixel_depth = 32;
  174061. else
  174062. max_pixel_depth = 64;
  174063. }
  174064. else
  174065. {
  174066. if (max_pixel_depth <= 8)
  174067. {
  174068. if (png_ptr->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  174069. max_pixel_depth = 32;
  174070. else
  174071. max_pixel_depth = 24;
  174072. }
  174073. else if (png_ptr->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  174074. max_pixel_depth = 64;
  174075. else
  174076. max_pixel_depth = 48;
  174077. }
  174078. }
  174079. #endif
  174080. #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) && \
  174081. defined(PNG_USER_TRANSFORM_PTR_SUPPORTED)
  174082. if(png_ptr->transformations & PNG_USER_TRANSFORM)
  174083. {
  174084. int user_pixel_depth=png_ptr->user_transform_depth*
  174085. png_ptr->user_transform_channels;
  174086. if(user_pixel_depth > max_pixel_depth)
  174087. max_pixel_depth=user_pixel_depth;
  174088. }
  174089. #endif
  174090. row_bytes = ((png_ptr->width + 7) & ~((png_uint_32)7));
  174091. row_bytes = PNG_ROWBYTES(max_pixel_depth,row_bytes) +
  174092. 1 + ((max_pixel_depth + 7) >> 3);
  174093. #ifdef PNG_MAX_MALLOC_64K
  174094. if (row_bytes > (png_uint_32)65536L)
  174095. png_error(png_ptr, "This image requires a row greater than 64KB");
  174096. #endif
  174097. png_ptr->big_row_buf = (png_bytep)png_malloc(png_ptr, row_bytes+64);
  174098. png_ptr->row_buf = png_ptr->big_row_buf+32;
  174099. #ifdef PNG_MAX_MALLOC_64K
  174100. if ((png_uint_32)png_ptr->rowbytes + 1 > (png_uint_32)65536L)
  174101. png_error(png_ptr, "This image requires a row greater than 64KB");
  174102. #endif
  174103. if ((png_uint_32)png_ptr->rowbytes > (png_uint_32)(PNG_SIZE_MAX - 1))
  174104. png_error(png_ptr, "Row has too many bytes to allocate in memory.");
  174105. png_ptr->prev_row = (png_bytep)png_malloc(png_ptr, (png_uint_32)(
  174106. png_ptr->rowbytes + 1));
  174107. png_memset_check(png_ptr, png_ptr->prev_row, 0, png_ptr->rowbytes + 1);
  174108. png_debug1(3, "width = %lu,\n", png_ptr->width);
  174109. png_debug1(3, "height = %lu,\n", png_ptr->height);
  174110. png_debug1(3, "iwidth = %lu,\n", png_ptr->iwidth);
  174111. png_debug1(3, "num_rows = %lu\n", png_ptr->num_rows);
  174112. png_debug1(3, "rowbytes = %lu,\n", png_ptr->rowbytes);
  174113. png_debug1(3, "irowbytes = %lu,\n", png_ptr->irowbytes);
  174114. png_ptr->flags |= PNG_FLAG_ROW_INIT;
  174115. }
  174116. #endif /* PNG_READ_SUPPORTED */
  174117. /********* End of inlined file: pngrutil.c *********/
  174118. /********* Start of inlined file: pngset.c *********/
  174119. #define PNG_INTERNAL
  174120. #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
  174121. #if defined(PNG_bKGD_SUPPORTED)
  174122. void PNGAPI
  174123. png_set_bKGD(png_structp png_ptr, png_infop info_ptr, png_color_16p background)
  174124. {
  174125. png_debug1(1, "in %s storage function\n", "bKGD");
  174126. if (png_ptr == NULL || info_ptr == NULL)
  174127. return;
  174128. png_memcpy(&(info_ptr->background), background, png_sizeof(png_color_16));
  174129. info_ptr->valid |= PNG_INFO_bKGD;
  174130. }
  174131. #endif
  174132. #if defined(PNG_cHRM_SUPPORTED)
  174133. #ifdef PNG_FLOATING_POINT_SUPPORTED
  174134. void PNGAPI
  174135. png_set_cHRM(png_structp png_ptr, png_infop info_ptr,
  174136. double white_x, double white_y, double red_x, double red_y,
  174137. double green_x, double green_y, double blue_x, double blue_y)
  174138. {
  174139. png_debug1(1, "in %s storage function\n", "cHRM");
  174140. if (png_ptr == NULL || info_ptr == NULL)
  174141. return;
  174142. if (white_x < 0.0 || white_y < 0.0 ||
  174143. red_x < 0.0 || red_y < 0.0 ||
  174144. green_x < 0.0 || green_y < 0.0 ||
  174145. blue_x < 0.0 || blue_y < 0.0)
  174146. {
  174147. png_warning(png_ptr,
  174148. "Ignoring attempt to set negative chromaticity value");
  174149. return;
  174150. }
  174151. if (white_x > 21474.83 || white_y > 21474.83 ||
  174152. red_x > 21474.83 || red_y > 21474.83 ||
  174153. green_x > 21474.83 || green_y > 21474.83 ||
  174154. blue_x > 21474.83 || blue_y > 21474.83)
  174155. {
  174156. png_warning(png_ptr,
  174157. "Ignoring attempt to set chromaticity value exceeding 21474.83");
  174158. return;
  174159. }
  174160. info_ptr->x_white = (float)white_x;
  174161. info_ptr->y_white = (float)white_y;
  174162. info_ptr->x_red = (float)red_x;
  174163. info_ptr->y_red = (float)red_y;
  174164. info_ptr->x_green = (float)green_x;
  174165. info_ptr->y_green = (float)green_y;
  174166. info_ptr->x_blue = (float)blue_x;
  174167. info_ptr->y_blue = (float)blue_y;
  174168. #ifdef PNG_FIXED_POINT_SUPPORTED
  174169. info_ptr->int_x_white = (png_fixed_point)(white_x*100000.+0.5);
  174170. info_ptr->int_y_white = (png_fixed_point)(white_y*100000.+0.5);
  174171. info_ptr->int_x_red = (png_fixed_point)( red_x*100000.+0.5);
  174172. info_ptr->int_y_red = (png_fixed_point)( red_y*100000.+0.5);
  174173. info_ptr->int_x_green = (png_fixed_point)(green_x*100000.+0.5);
  174174. info_ptr->int_y_green = (png_fixed_point)(green_y*100000.+0.5);
  174175. info_ptr->int_x_blue = (png_fixed_point)( blue_x*100000.+0.5);
  174176. info_ptr->int_y_blue = (png_fixed_point)( blue_y*100000.+0.5);
  174177. #endif
  174178. info_ptr->valid |= PNG_INFO_cHRM;
  174179. }
  174180. #endif
  174181. #ifdef PNG_FIXED_POINT_SUPPORTED
  174182. void PNGAPI
  174183. png_set_cHRM_fixed(png_structp png_ptr, png_infop info_ptr,
  174184. png_fixed_point white_x, png_fixed_point white_y, png_fixed_point red_x,
  174185. png_fixed_point red_y, png_fixed_point green_x, png_fixed_point green_y,
  174186. png_fixed_point blue_x, png_fixed_point blue_y)
  174187. {
  174188. png_debug1(1, "in %s storage function\n", "cHRM");
  174189. if (png_ptr == NULL || info_ptr == NULL)
  174190. return;
  174191. if (white_x < 0 || white_y < 0 ||
  174192. red_x < 0 || red_y < 0 ||
  174193. green_x < 0 || green_y < 0 ||
  174194. blue_x < 0 || blue_y < 0)
  174195. {
  174196. png_warning(png_ptr,
  174197. "Ignoring attempt to set negative chromaticity value");
  174198. return;
  174199. }
  174200. #ifdef PNG_FLOATING_POINT_SUPPORTED
  174201. if (white_x > (double) PNG_UINT_31_MAX ||
  174202. white_y > (double) PNG_UINT_31_MAX ||
  174203. red_x > (double) PNG_UINT_31_MAX ||
  174204. red_y > (double) PNG_UINT_31_MAX ||
  174205. green_x > (double) PNG_UINT_31_MAX ||
  174206. green_y > (double) PNG_UINT_31_MAX ||
  174207. blue_x > (double) PNG_UINT_31_MAX ||
  174208. blue_y > (double) PNG_UINT_31_MAX)
  174209. #else
  174210. if (white_x > (png_fixed_point) PNG_UINT_31_MAX/100000L ||
  174211. white_y > (png_fixed_point) PNG_UINT_31_MAX/100000L ||
  174212. red_x > (png_fixed_point) PNG_UINT_31_MAX/100000L ||
  174213. red_y > (png_fixed_point) PNG_UINT_31_MAX/100000L ||
  174214. green_x > (png_fixed_point) PNG_UINT_31_MAX/100000L ||
  174215. green_y > (png_fixed_point) PNG_UINT_31_MAX/100000L ||
  174216. blue_x > (png_fixed_point) PNG_UINT_31_MAX/100000L ||
  174217. blue_y > (png_fixed_point) PNG_UINT_31_MAX/100000L)
  174218. #endif
  174219. {
  174220. png_warning(png_ptr,
  174221. "Ignoring attempt to set chromaticity value exceeding 21474.83");
  174222. return;
  174223. }
  174224. info_ptr->int_x_white = white_x;
  174225. info_ptr->int_y_white = white_y;
  174226. info_ptr->int_x_red = red_x;
  174227. info_ptr->int_y_red = red_y;
  174228. info_ptr->int_x_green = green_x;
  174229. info_ptr->int_y_green = green_y;
  174230. info_ptr->int_x_blue = blue_x;
  174231. info_ptr->int_y_blue = blue_y;
  174232. #ifdef PNG_FLOATING_POINT_SUPPORTED
  174233. info_ptr->x_white = (float)(white_x/100000.);
  174234. info_ptr->y_white = (float)(white_y/100000.);
  174235. info_ptr->x_red = (float)( red_x/100000.);
  174236. info_ptr->y_red = (float)( red_y/100000.);
  174237. info_ptr->x_green = (float)(green_x/100000.);
  174238. info_ptr->y_green = (float)(green_y/100000.);
  174239. info_ptr->x_blue = (float)( blue_x/100000.);
  174240. info_ptr->y_blue = (float)( blue_y/100000.);
  174241. #endif
  174242. info_ptr->valid |= PNG_INFO_cHRM;
  174243. }
  174244. #endif
  174245. #endif
  174246. #if defined(PNG_gAMA_SUPPORTED)
  174247. #ifdef PNG_FLOATING_POINT_SUPPORTED
  174248. void PNGAPI
  174249. png_set_gAMA(png_structp png_ptr, png_infop info_ptr, double file_gamma)
  174250. {
  174251. double gamma;
  174252. png_debug1(1, "in %s storage function\n", "gAMA");
  174253. if (png_ptr == NULL || info_ptr == NULL)
  174254. return;
  174255. if (file_gamma > 21474.83)
  174256. {
  174257. png_warning(png_ptr, "Limiting gamma to 21474.83");
  174258. gamma=21474.83;
  174259. }
  174260. else
  174261. gamma=file_gamma;
  174262. info_ptr->gamma = (float)gamma;
  174263. #ifdef PNG_FIXED_POINT_SUPPORTED
  174264. info_ptr->int_gamma = (int)(gamma*100000.+.5);
  174265. #endif
  174266. info_ptr->valid |= PNG_INFO_gAMA;
  174267. if(gamma == 0.0)
  174268. png_warning(png_ptr, "Setting gamma=0");
  174269. }
  174270. #endif
  174271. void PNGAPI
  174272. png_set_gAMA_fixed(png_structp png_ptr, png_infop info_ptr, png_fixed_point
  174273. int_gamma)
  174274. {
  174275. png_fixed_point gamma;
  174276. png_debug1(1, "in %s storage function\n", "gAMA");
  174277. if (png_ptr == NULL || info_ptr == NULL)
  174278. return;
  174279. if (int_gamma > (png_fixed_point) PNG_UINT_31_MAX)
  174280. {
  174281. png_warning(png_ptr, "Limiting gamma to 21474.83");
  174282. gamma=PNG_UINT_31_MAX;
  174283. }
  174284. else
  174285. {
  174286. if (int_gamma < 0)
  174287. {
  174288. png_warning(png_ptr, "Setting negative gamma to zero");
  174289. gamma=0;
  174290. }
  174291. else
  174292. gamma=int_gamma;
  174293. }
  174294. #ifdef PNG_FLOATING_POINT_SUPPORTED
  174295. info_ptr->gamma = (float)(gamma/100000.);
  174296. #endif
  174297. #ifdef PNG_FIXED_POINT_SUPPORTED
  174298. info_ptr->int_gamma = gamma;
  174299. #endif
  174300. info_ptr->valid |= PNG_INFO_gAMA;
  174301. if(gamma == 0)
  174302. png_warning(png_ptr, "Setting gamma=0");
  174303. }
  174304. #endif
  174305. #if defined(PNG_hIST_SUPPORTED)
  174306. void PNGAPI
  174307. png_set_hIST(png_structp png_ptr, png_infop info_ptr, png_uint_16p hist)
  174308. {
  174309. int i;
  174310. png_debug1(1, "in %s storage function\n", "hIST");
  174311. if (png_ptr == NULL || info_ptr == NULL)
  174312. return;
  174313. if (info_ptr->num_palette == 0 || info_ptr->num_palette
  174314. > PNG_MAX_PALETTE_LENGTH)
  174315. {
  174316. png_warning(png_ptr,
  174317. "Invalid palette size, hIST allocation skipped.");
  174318. return;
  174319. }
  174320. #ifdef PNG_FREE_ME_SUPPORTED
  174321. png_free_data(png_ptr, info_ptr, PNG_FREE_HIST, 0);
  174322. #endif
  174323. png_ptr->hist = (png_uint_16p)png_malloc_warn(png_ptr,
  174324. (png_uint_32)(PNG_MAX_PALETTE_LENGTH * png_sizeof (png_uint_16)));
  174325. if (png_ptr->hist == NULL)
  174326. {
  174327. png_warning(png_ptr, "Insufficient memory for hIST chunk data.");
  174328. return;
  174329. }
  174330. for (i = 0; i < info_ptr->num_palette; i++)
  174331. png_ptr->hist[i] = hist[i];
  174332. info_ptr->hist = png_ptr->hist;
  174333. info_ptr->valid |= PNG_INFO_hIST;
  174334. #ifdef PNG_FREE_ME_SUPPORTED
  174335. info_ptr->free_me |= PNG_FREE_HIST;
  174336. #else
  174337. png_ptr->flags |= PNG_FLAG_FREE_HIST;
  174338. #endif
  174339. }
  174340. #endif
  174341. void PNGAPI
  174342. png_set_IHDR(png_structp png_ptr, png_infop info_ptr,
  174343. png_uint_32 width, png_uint_32 height, int bit_depth,
  174344. int color_type, int interlace_type, int compression_type,
  174345. int filter_type)
  174346. {
  174347. png_debug1(1, "in %s storage function\n", "IHDR");
  174348. if (png_ptr == NULL || info_ptr == NULL)
  174349. return;
  174350. if (width == 0 || height == 0)
  174351. png_error(png_ptr, "Image width or height is zero in IHDR");
  174352. #ifdef PNG_SET_USER_LIMITS_SUPPORTED
  174353. if (width > png_ptr->user_width_max || height > png_ptr->user_height_max)
  174354. png_error(png_ptr, "image size exceeds user limits in IHDR");
  174355. #else
  174356. if (width > PNG_USER_WIDTH_MAX || height > PNG_USER_HEIGHT_MAX)
  174357. png_error(png_ptr, "image size exceeds user limits in IHDR");
  174358. #endif
  174359. if (width > PNG_UINT_31_MAX || height > PNG_UINT_31_MAX)
  174360. png_error(png_ptr, "Invalid image size in IHDR");
  174361. if ( width > (PNG_UINT_32_MAX
  174362. >> 3) /* 8-byte RGBA pixels */
  174363. - 64 /* bigrowbuf hack */
  174364. - 1 /* filter byte */
  174365. - 7*8 /* rounding of width to multiple of 8 pixels */
  174366. - 8) /* extra max_pixel_depth pad */
  174367. png_warning(png_ptr, "Width is too large for libpng to process pixels");
  174368. if (bit_depth != 1 && bit_depth != 2 && bit_depth != 4 &&
  174369. bit_depth != 8 && bit_depth != 16)
  174370. png_error(png_ptr, "Invalid bit depth in IHDR");
  174371. if (color_type < 0 || color_type == 1 ||
  174372. color_type == 5 || color_type > 6)
  174373. png_error(png_ptr, "Invalid color type in IHDR");
  174374. if (((color_type == PNG_COLOR_TYPE_PALETTE) && bit_depth > 8) ||
  174375. ((color_type == PNG_COLOR_TYPE_RGB ||
  174376. color_type == PNG_COLOR_TYPE_GRAY_ALPHA ||
  174377. color_type == PNG_COLOR_TYPE_RGB_ALPHA) && bit_depth < 8))
  174378. png_error(png_ptr, "Invalid color type/bit depth combination in IHDR");
  174379. if (interlace_type >= PNG_INTERLACE_LAST)
  174380. png_error(png_ptr, "Unknown interlace method in IHDR");
  174381. if (compression_type != PNG_COMPRESSION_TYPE_BASE)
  174382. png_error(png_ptr, "Unknown compression method in IHDR");
  174383. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  174384. if((png_ptr->mode&PNG_HAVE_PNG_SIGNATURE)&&png_ptr->mng_features_permitted)
  174385. png_warning(png_ptr,"MNG features are not allowed in a PNG datastream");
  174386. if(filter_type != PNG_FILTER_TYPE_BASE)
  174387. {
  174388. if(!((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) &&
  174389. (filter_type == PNG_INTRAPIXEL_DIFFERENCING) &&
  174390. ((png_ptr->mode&PNG_HAVE_PNG_SIGNATURE) == 0) &&
  174391. (color_type == PNG_COLOR_TYPE_RGB ||
  174392. color_type == PNG_COLOR_TYPE_RGB_ALPHA)))
  174393. png_error(png_ptr, "Unknown filter method in IHDR");
  174394. if(png_ptr->mode&PNG_HAVE_PNG_SIGNATURE)
  174395. png_warning(png_ptr, "Invalid filter method in IHDR");
  174396. }
  174397. #else
  174398. if(filter_type != PNG_FILTER_TYPE_BASE)
  174399. png_error(png_ptr, "Unknown filter method in IHDR");
  174400. #endif
  174401. info_ptr->width = width;
  174402. info_ptr->height = height;
  174403. info_ptr->bit_depth = (png_byte)bit_depth;
  174404. info_ptr->color_type =(png_byte) color_type;
  174405. info_ptr->compression_type = (png_byte)compression_type;
  174406. info_ptr->filter_type = (png_byte)filter_type;
  174407. info_ptr->interlace_type = (png_byte)interlace_type;
  174408. if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  174409. info_ptr->channels = 1;
  174410. else if (info_ptr->color_type & PNG_COLOR_MASK_COLOR)
  174411. info_ptr->channels = 3;
  174412. else
  174413. info_ptr->channels = 1;
  174414. if (info_ptr->color_type & PNG_COLOR_MASK_ALPHA)
  174415. info_ptr->channels++;
  174416. info_ptr->pixel_depth = (png_byte)(info_ptr->channels * info_ptr->bit_depth);
  174417. if (width > (PNG_UINT_32_MAX
  174418. >> 3) /* 8-byte RGBA pixels */
  174419. - 64 /* bigrowbuf hack */
  174420. - 1 /* filter byte */
  174421. - 7*8 /* rounding of width to multiple of 8 pixels */
  174422. - 8) /* extra max_pixel_depth pad */
  174423. info_ptr->rowbytes = (png_size_t)0;
  174424. else
  174425. info_ptr->rowbytes = PNG_ROWBYTES(info_ptr->pixel_depth,width);
  174426. }
  174427. #if defined(PNG_oFFs_SUPPORTED)
  174428. void PNGAPI
  174429. png_set_oFFs(png_structp png_ptr, png_infop info_ptr,
  174430. png_int_32 offset_x, png_int_32 offset_y, int unit_type)
  174431. {
  174432. png_debug1(1, "in %s storage function\n", "oFFs");
  174433. if (png_ptr == NULL || info_ptr == NULL)
  174434. return;
  174435. info_ptr->x_offset = offset_x;
  174436. info_ptr->y_offset = offset_y;
  174437. info_ptr->offset_unit_type = (png_byte)unit_type;
  174438. info_ptr->valid |= PNG_INFO_oFFs;
  174439. }
  174440. #endif
  174441. #if defined(PNG_pCAL_SUPPORTED)
  174442. void PNGAPI
  174443. png_set_pCAL(png_structp png_ptr, png_infop info_ptr,
  174444. png_charp purpose, png_int_32 X0, png_int_32 X1, int type, int nparams,
  174445. png_charp units, png_charpp params)
  174446. {
  174447. png_uint_32 length;
  174448. int i;
  174449. png_debug1(1, "in %s storage function\n", "pCAL");
  174450. if (png_ptr == NULL || info_ptr == NULL)
  174451. return;
  174452. length = png_strlen(purpose) + 1;
  174453. png_debug1(3, "allocating purpose for info (%lu bytes)\n", length);
  174454. info_ptr->pcal_purpose = (png_charp)png_malloc_warn(png_ptr, length);
  174455. if (info_ptr->pcal_purpose == NULL)
  174456. {
  174457. png_warning(png_ptr, "Insufficient memory for pCAL purpose.");
  174458. return;
  174459. }
  174460. png_memcpy(info_ptr->pcal_purpose, purpose, (png_size_t)length);
  174461. png_debug(3, "storing X0, X1, type, and nparams in info\n");
  174462. info_ptr->pcal_X0 = X0;
  174463. info_ptr->pcal_X1 = X1;
  174464. info_ptr->pcal_type = (png_byte)type;
  174465. info_ptr->pcal_nparams = (png_byte)nparams;
  174466. length = png_strlen(units) + 1;
  174467. png_debug1(3, "allocating units for info (%lu bytes)\n", length);
  174468. info_ptr->pcal_units = (png_charp)png_malloc_warn(png_ptr, length);
  174469. if (info_ptr->pcal_units == NULL)
  174470. {
  174471. png_warning(png_ptr, "Insufficient memory for pCAL units.");
  174472. return;
  174473. }
  174474. png_memcpy(info_ptr->pcal_units, units, (png_size_t)length);
  174475. info_ptr->pcal_params = (png_charpp)png_malloc_warn(png_ptr,
  174476. (png_uint_32)((nparams + 1) * png_sizeof(png_charp)));
  174477. if (info_ptr->pcal_params == NULL)
  174478. {
  174479. png_warning(png_ptr, "Insufficient memory for pCAL params.");
  174480. return;
  174481. }
  174482. info_ptr->pcal_params[nparams] = NULL;
  174483. for (i = 0; i < nparams; i++)
  174484. {
  174485. length = png_strlen(params[i]) + 1;
  174486. png_debug2(3, "allocating parameter %d for info (%lu bytes)\n", i, length);
  174487. info_ptr->pcal_params[i] = (png_charp)png_malloc_warn(png_ptr, length);
  174488. if (info_ptr->pcal_params[i] == NULL)
  174489. {
  174490. png_warning(png_ptr, "Insufficient memory for pCAL parameter.");
  174491. return;
  174492. }
  174493. png_memcpy(info_ptr->pcal_params[i], params[i], (png_size_t)length);
  174494. }
  174495. info_ptr->valid |= PNG_INFO_pCAL;
  174496. #ifdef PNG_FREE_ME_SUPPORTED
  174497. info_ptr->free_me |= PNG_FREE_PCAL;
  174498. #endif
  174499. }
  174500. #endif
  174501. #if defined(PNG_READ_sCAL_SUPPORTED) || defined(PNG_WRITE_sCAL_SUPPORTED)
  174502. #ifdef PNG_FLOATING_POINT_SUPPORTED
  174503. void PNGAPI
  174504. png_set_sCAL(png_structp png_ptr, png_infop info_ptr,
  174505. int unit, double width, double height)
  174506. {
  174507. png_debug1(1, "in %s storage function\n", "sCAL");
  174508. if (png_ptr == NULL || info_ptr == NULL)
  174509. return;
  174510. info_ptr->scal_unit = (png_byte)unit;
  174511. info_ptr->scal_pixel_width = width;
  174512. info_ptr->scal_pixel_height = height;
  174513. info_ptr->valid |= PNG_INFO_sCAL;
  174514. }
  174515. #else
  174516. #ifdef PNG_FIXED_POINT_SUPPORTED
  174517. void PNGAPI
  174518. png_set_sCAL_s(png_structp png_ptr, png_infop info_ptr,
  174519. int unit, png_charp swidth, png_charp sheight)
  174520. {
  174521. png_uint_32 length;
  174522. png_debug1(1, "in %s storage function\n", "sCAL");
  174523. if (png_ptr == NULL || info_ptr == NULL)
  174524. return;
  174525. info_ptr->scal_unit = (png_byte)unit;
  174526. length = png_strlen(swidth) + 1;
  174527. png_debug1(3, "allocating unit for info (%d bytes)\n", length);
  174528. info_ptr->scal_s_width = (png_charp)png_malloc_warn(png_ptr, length);
  174529. if (info_ptr->scal_s_width == NULL)
  174530. {
  174531. png_warning(png_ptr,
  174532. "Memory allocation failed while processing sCAL.");
  174533. }
  174534. png_memcpy(info_ptr->scal_s_width, swidth, (png_size_t)length);
  174535. length = png_strlen(sheight) + 1;
  174536. png_debug1(3, "allocating unit for info (%d bytes)\n", length);
  174537. info_ptr->scal_s_height = (png_charp)png_malloc_warn(png_ptr, length);
  174538. if (info_ptr->scal_s_height == NULL)
  174539. {
  174540. png_free (png_ptr, info_ptr->scal_s_width);
  174541. png_warning(png_ptr,
  174542. "Memory allocation failed while processing sCAL.");
  174543. }
  174544. png_memcpy(info_ptr->scal_s_height, sheight, (png_size_t)length);
  174545. info_ptr->valid |= PNG_INFO_sCAL;
  174546. #ifdef PNG_FREE_ME_SUPPORTED
  174547. info_ptr->free_me |= PNG_FREE_SCAL;
  174548. #endif
  174549. }
  174550. #endif
  174551. #endif
  174552. #endif
  174553. #if defined(PNG_pHYs_SUPPORTED)
  174554. void PNGAPI
  174555. png_set_pHYs(png_structp png_ptr, png_infop info_ptr,
  174556. png_uint_32 res_x, png_uint_32 res_y, int unit_type)
  174557. {
  174558. png_debug1(1, "in %s storage function\n", "pHYs");
  174559. if (png_ptr == NULL || info_ptr == NULL)
  174560. return;
  174561. info_ptr->x_pixels_per_unit = res_x;
  174562. info_ptr->y_pixels_per_unit = res_y;
  174563. info_ptr->phys_unit_type = (png_byte)unit_type;
  174564. info_ptr->valid |= PNG_INFO_pHYs;
  174565. }
  174566. #endif
  174567. void PNGAPI
  174568. png_set_PLTE(png_structp png_ptr, png_infop info_ptr,
  174569. png_colorp palette, int num_palette)
  174570. {
  174571. png_debug1(1, "in %s storage function\n", "PLTE");
  174572. if (png_ptr == NULL || info_ptr == NULL)
  174573. return;
  174574. if (num_palette < 0 || num_palette > PNG_MAX_PALETTE_LENGTH)
  174575. {
  174576. if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  174577. png_error(png_ptr, "Invalid palette length");
  174578. else
  174579. {
  174580. png_warning(png_ptr, "Invalid palette length");
  174581. return;
  174582. }
  174583. }
  174584. #ifdef PNG_FREE_ME_SUPPORTED
  174585. png_free_data(png_ptr, info_ptr, PNG_FREE_PLTE, 0);
  174586. #endif
  174587. png_ptr->palette = (png_colorp)png_malloc(png_ptr,
  174588. PNG_MAX_PALETTE_LENGTH * png_sizeof(png_color));
  174589. png_memset(png_ptr->palette, 0, PNG_MAX_PALETTE_LENGTH *
  174590. png_sizeof(png_color));
  174591. png_memcpy(png_ptr->palette, palette, num_palette * png_sizeof (png_color));
  174592. info_ptr->palette = png_ptr->palette;
  174593. info_ptr->num_palette = png_ptr->num_palette = (png_uint_16)num_palette;
  174594. #ifdef PNG_FREE_ME_SUPPORTED
  174595. info_ptr->free_me |= PNG_FREE_PLTE;
  174596. #else
  174597. png_ptr->flags |= PNG_FLAG_FREE_PLTE;
  174598. #endif
  174599. info_ptr->valid |= PNG_INFO_PLTE;
  174600. }
  174601. #if defined(PNG_sBIT_SUPPORTED)
  174602. void PNGAPI
  174603. png_set_sBIT(png_structp png_ptr, png_infop info_ptr,
  174604. png_color_8p sig_bit)
  174605. {
  174606. png_debug1(1, "in %s storage function\n", "sBIT");
  174607. if (png_ptr == NULL || info_ptr == NULL)
  174608. return;
  174609. png_memcpy(&(info_ptr->sig_bit), sig_bit, png_sizeof (png_color_8));
  174610. info_ptr->valid |= PNG_INFO_sBIT;
  174611. }
  174612. #endif
  174613. #if defined(PNG_sRGB_SUPPORTED)
  174614. void PNGAPI
  174615. png_set_sRGB(png_structp png_ptr, png_infop info_ptr, int intent)
  174616. {
  174617. png_debug1(1, "in %s storage function\n", "sRGB");
  174618. if (png_ptr == NULL || info_ptr == NULL)
  174619. return;
  174620. info_ptr->srgb_intent = (png_byte)intent;
  174621. info_ptr->valid |= PNG_INFO_sRGB;
  174622. }
  174623. void PNGAPI
  174624. png_set_sRGB_gAMA_and_cHRM(png_structp png_ptr, png_infop info_ptr,
  174625. int intent)
  174626. {
  174627. #if defined(PNG_gAMA_SUPPORTED)
  174628. #ifdef PNG_FLOATING_POINT_SUPPORTED
  174629. float file_gamma;
  174630. #endif
  174631. #ifdef PNG_FIXED_POINT_SUPPORTED
  174632. png_fixed_point int_file_gamma;
  174633. #endif
  174634. #endif
  174635. #if defined(PNG_cHRM_SUPPORTED)
  174636. #ifdef PNG_FLOATING_POINT_SUPPORTED
  174637. float white_x, white_y, red_x, red_y, green_x, green_y, blue_x, blue_y;
  174638. #endif
  174639. #ifdef PNG_FIXED_POINT_SUPPORTED
  174640. png_fixed_point int_white_x, int_white_y, int_red_x, int_red_y, int_green_x,
  174641. int_green_y, int_blue_x, int_blue_y;
  174642. #endif
  174643. #endif
  174644. png_debug1(1, "in %s storage function\n", "sRGB_gAMA_and_cHRM");
  174645. if (png_ptr == NULL || info_ptr == NULL)
  174646. return;
  174647. png_set_sRGB(png_ptr, info_ptr, intent);
  174648. #if defined(PNG_gAMA_SUPPORTED)
  174649. #ifdef PNG_FLOATING_POINT_SUPPORTED
  174650. file_gamma = (float).45455;
  174651. png_set_gAMA(png_ptr, info_ptr, file_gamma);
  174652. #endif
  174653. #ifdef PNG_FIXED_POINT_SUPPORTED
  174654. int_file_gamma = 45455L;
  174655. png_set_gAMA_fixed(png_ptr, info_ptr, int_file_gamma);
  174656. #endif
  174657. #endif
  174658. #if defined(PNG_cHRM_SUPPORTED)
  174659. #ifdef PNG_FIXED_POINT_SUPPORTED
  174660. int_white_x = 31270L;
  174661. int_white_y = 32900L;
  174662. int_red_x = 64000L;
  174663. int_red_y = 33000L;
  174664. int_green_x = 30000L;
  174665. int_green_y = 60000L;
  174666. int_blue_x = 15000L;
  174667. int_blue_y = 6000L;
  174668. png_set_cHRM_fixed(png_ptr, info_ptr,
  174669. int_white_x, int_white_y, int_red_x, int_red_y, int_green_x, int_green_y,
  174670. int_blue_x, int_blue_y);
  174671. #endif
  174672. #ifdef PNG_FLOATING_POINT_SUPPORTED
  174673. white_x = (float).3127;
  174674. white_y = (float).3290;
  174675. red_x = (float).64;
  174676. red_y = (float).33;
  174677. green_x = (float).30;
  174678. green_y = (float).60;
  174679. blue_x = (float).15;
  174680. blue_y = (float).06;
  174681. png_set_cHRM(png_ptr, info_ptr,
  174682. white_x, white_y, red_x, red_y, green_x, green_y, blue_x, blue_y);
  174683. #endif
  174684. #endif
  174685. }
  174686. #endif
  174687. #if defined(PNG_iCCP_SUPPORTED)
  174688. void PNGAPI
  174689. png_set_iCCP(png_structp png_ptr, png_infop info_ptr,
  174690. png_charp name, int compression_type,
  174691. png_charp profile, png_uint_32 proflen)
  174692. {
  174693. png_charp new_iccp_name;
  174694. png_charp new_iccp_profile;
  174695. png_debug1(1, "in %s storage function\n", "iCCP");
  174696. if (png_ptr == NULL || info_ptr == NULL || name == NULL || profile == NULL)
  174697. return;
  174698. new_iccp_name = (png_charp)png_malloc_warn(png_ptr, png_strlen(name)+1);
  174699. if (new_iccp_name == NULL)
  174700. {
  174701. png_warning(png_ptr, "Insufficient memory to process iCCP chunk.");
  174702. return;
  174703. }
  174704. png_strncpy(new_iccp_name, name, png_strlen(name)+1);
  174705. new_iccp_profile = (png_charp)png_malloc_warn(png_ptr, proflen);
  174706. if (new_iccp_profile == NULL)
  174707. {
  174708. png_free (png_ptr, new_iccp_name);
  174709. png_warning(png_ptr, "Insufficient memory to process iCCP profile.");
  174710. return;
  174711. }
  174712. png_memcpy(new_iccp_profile, profile, (png_size_t)proflen);
  174713. png_free_data(png_ptr, info_ptr, PNG_FREE_ICCP, 0);
  174714. info_ptr->iccp_proflen = proflen;
  174715. info_ptr->iccp_name = new_iccp_name;
  174716. info_ptr->iccp_profile = new_iccp_profile;
  174717. info_ptr->iccp_compression = (png_byte)compression_type;
  174718. #ifdef PNG_FREE_ME_SUPPORTED
  174719. info_ptr->free_me |= PNG_FREE_ICCP;
  174720. #endif
  174721. info_ptr->valid |= PNG_INFO_iCCP;
  174722. }
  174723. #endif
  174724. #if defined(PNG_TEXT_SUPPORTED)
  174725. void PNGAPI
  174726. png_set_text(png_structp png_ptr, png_infop info_ptr, png_textp text_ptr,
  174727. int num_text)
  174728. {
  174729. int ret;
  174730. ret=png_set_text_2(png_ptr, info_ptr, text_ptr, num_text);
  174731. if (ret)
  174732. png_error(png_ptr, "Insufficient memory to store text");
  174733. }
  174734. int /* PRIVATE */
  174735. png_set_text_2(png_structp png_ptr, png_infop info_ptr, png_textp text_ptr,
  174736. int num_text)
  174737. {
  174738. int i;
  174739. png_debug1(1, "in %s storage function\n", (png_ptr->chunk_name[0] == '\0' ?
  174740. "text" : (png_const_charp)png_ptr->chunk_name));
  174741. if (png_ptr == NULL || info_ptr == NULL || num_text == 0)
  174742. return(0);
  174743. if (info_ptr->num_text + num_text > info_ptr->max_text)
  174744. {
  174745. if (info_ptr->text != NULL)
  174746. {
  174747. png_textp old_text;
  174748. int old_max;
  174749. old_max = info_ptr->max_text;
  174750. info_ptr->max_text = info_ptr->num_text + num_text + 8;
  174751. old_text = info_ptr->text;
  174752. info_ptr->text = (png_textp)png_malloc_warn(png_ptr,
  174753. (png_uint_32)(info_ptr->max_text * png_sizeof (png_text)));
  174754. if (info_ptr->text == NULL)
  174755. {
  174756. png_free(png_ptr, old_text);
  174757. return(1);
  174758. }
  174759. png_memcpy(info_ptr->text, old_text, (png_size_t)(old_max *
  174760. png_sizeof(png_text)));
  174761. png_free(png_ptr, old_text);
  174762. }
  174763. else
  174764. {
  174765. info_ptr->max_text = num_text + 8;
  174766. info_ptr->num_text = 0;
  174767. info_ptr->text = (png_textp)png_malloc_warn(png_ptr,
  174768. (png_uint_32)(info_ptr->max_text * png_sizeof (png_text)));
  174769. if (info_ptr->text == NULL)
  174770. return(1);
  174771. #ifdef PNG_FREE_ME_SUPPORTED
  174772. info_ptr->free_me |= PNG_FREE_TEXT;
  174773. #endif
  174774. }
  174775. png_debug1(3, "allocated %d entries for info_ptr->text\n",
  174776. info_ptr->max_text);
  174777. }
  174778. for (i = 0; i < num_text; i++)
  174779. {
  174780. png_size_t text_length,key_len;
  174781. png_size_t lang_len,lang_key_len;
  174782. png_textp textp = &(info_ptr->text[info_ptr->num_text]);
  174783. if (text_ptr[i].key == NULL)
  174784. continue;
  174785. key_len = png_strlen(text_ptr[i].key);
  174786. if(text_ptr[i].compression <= 0)
  174787. {
  174788. lang_len = 0;
  174789. lang_key_len = 0;
  174790. }
  174791. else
  174792. #ifdef PNG_iTXt_SUPPORTED
  174793. {
  174794. if (text_ptr[i].lang != NULL)
  174795. lang_len = png_strlen(text_ptr[i].lang);
  174796. else
  174797. lang_len = 0;
  174798. if (text_ptr[i].lang_key != NULL)
  174799. lang_key_len = png_strlen(text_ptr[i].lang_key);
  174800. else
  174801. lang_key_len = 0;
  174802. }
  174803. #else
  174804. {
  174805. png_warning(png_ptr, "iTXt chunk not supported.");
  174806. continue;
  174807. }
  174808. #endif
  174809. if (text_ptr[i].text == NULL || text_ptr[i].text[0] == '\0')
  174810. {
  174811. text_length = 0;
  174812. #ifdef PNG_iTXt_SUPPORTED
  174813. if(text_ptr[i].compression > 0)
  174814. textp->compression = PNG_ITXT_COMPRESSION_NONE;
  174815. else
  174816. #endif
  174817. textp->compression = PNG_TEXT_COMPRESSION_NONE;
  174818. }
  174819. else
  174820. {
  174821. text_length = png_strlen(text_ptr[i].text);
  174822. textp->compression = text_ptr[i].compression;
  174823. }
  174824. textp->key = (png_charp)png_malloc_warn(png_ptr,
  174825. (png_uint_32)(key_len + text_length + lang_len + lang_key_len + 4));
  174826. if (textp->key == NULL)
  174827. return(1);
  174828. png_debug2(2, "Allocated %lu bytes at %x in png_set_text\n",
  174829. (png_uint_32)(key_len + lang_len + lang_key_len + text_length + 4),
  174830. (int)textp->key);
  174831. png_memcpy(textp->key, text_ptr[i].key,
  174832. (png_size_t)(key_len));
  174833. *(textp->key+key_len) = '\0';
  174834. #ifdef PNG_iTXt_SUPPORTED
  174835. if (text_ptr[i].compression > 0)
  174836. {
  174837. textp->lang=textp->key + key_len + 1;
  174838. png_memcpy(textp->lang, text_ptr[i].lang, lang_len);
  174839. *(textp->lang+lang_len) = '\0';
  174840. textp->lang_key=textp->lang + lang_len + 1;
  174841. png_memcpy(textp->lang_key, text_ptr[i].lang_key, lang_key_len);
  174842. *(textp->lang_key+lang_key_len) = '\0';
  174843. textp->text=textp->lang_key + lang_key_len + 1;
  174844. }
  174845. else
  174846. #endif
  174847. {
  174848. #ifdef PNG_iTXt_SUPPORTED
  174849. textp->lang=NULL;
  174850. textp->lang_key=NULL;
  174851. #endif
  174852. textp->text=textp->key + key_len + 1;
  174853. }
  174854. if(text_length)
  174855. png_memcpy(textp->text, text_ptr[i].text,
  174856. (png_size_t)(text_length));
  174857. *(textp->text+text_length) = '\0';
  174858. #ifdef PNG_iTXt_SUPPORTED
  174859. if(textp->compression > 0)
  174860. {
  174861. textp->text_length = 0;
  174862. textp->itxt_length = text_length;
  174863. }
  174864. else
  174865. #endif
  174866. {
  174867. textp->text_length = text_length;
  174868. #ifdef PNG_iTXt_SUPPORTED
  174869. textp->itxt_length = 0;
  174870. #endif
  174871. }
  174872. info_ptr->num_text++;
  174873. png_debug1(3, "transferred text chunk %d\n", info_ptr->num_text);
  174874. }
  174875. return(0);
  174876. }
  174877. #endif
  174878. #if defined(PNG_tIME_SUPPORTED)
  174879. void PNGAPI
  174880. png_set_tIME(png_structp png_ptr, png_infop info_ptr, png_timep mod_time)
  174881. {
  174882. png_debug1(1, "in %s storage function\n", "tIME");
  174883. if (png_ptr == NULL || info_ptr == NULL ||
  174884. (png_ptr->mode & PNG_WROTE_tIME))
  174885. return;
  174886. png_memcpy(&(info_ptr->mod_time), mod_time, png_sizeof (png_time));
  174887. info_ptr->valid |= PNG_INFO_tIME;
  174888. }
  174889. #endif
  174890. #if defined(PNG_tRNS_SUPPORTED)
  174891. void PNGAPI
  174892. png_set_tRNS(png_structp png_ptr, png_infop info_ptr,
  174893. png_bytep trans, int num_trans, png_color_16p trans_values)
  174894. {
  174895. png_debug1(1, "in %s storage function\n", "tRNS");
  174896. if (png_ptr == NULL || info_ptr == NULL)
  174897. return;
  174898. if (trans != NULL)
  174899. {
  174900. #ifdef PNG_FREE_ME_SUPPORTED
  174901. png_free_data(png_ptr, info_ptr, PNG_FREE_TRNS, 0);
  174902. #endif
  174903. png_ptr->trans = info_ptr->trans = (png_bytep)png_malloc(png_ptr,
  174904. (png_uint_32)PNG_MAX_PALETTE_LENGTH);
  174905. if (num_trans <= PNG_MAX_PALETTE_LENGTH)
  174906. png_memcpy(info_ptr->trans, trans, (png_size_t)num_trans);
  174907. #ifdef PNG_FREE_ME_SUPPORTED
  174908. info_ptr->free_me |= PNG_FREE_TRNS;
  174909. #else
  174910. png_ptr->flags |= PNG_FLAG_FREE_TRNS;
  174911. #endif
  174912. }
  174913. if (trans_values != NULL)
  174914. {
  174915. png_memcpy(&(info_ptr->trans_values), trans_values,
  174916. png_sizeof(png_color_16));
  174917. if (num_trans == 0)
  174918. num_trans = 1;
  174919. }
  174920. info_ptr->num_trans = (png_uint_16)num_trans;
  174921. info_ptr->valid |= PNG_INFO_tRNS;
  174922. }
  174923. #endif
  174924. #if defined(PNG_sPLT_SUPPORTED)
  174925. void PNGAPI
  174926. png_set_sPLT(png_structp png_ptr,
  174927. png_infop info_ptr, png_sPLT_tp entries, int nentries)
  174928. {
  174929. png_sPLT_tp np;
  174930. int i;
  174931. if (png_ptr == NULL || info_ptr == NULL)
  174932. return;
  174933. np = (png_sPLT_tp)png_malloc_warn(png_ptr,
  174934. (info_ptr->splt_palettes_num + nentries) * png_sizeof(png_sPLT_t));
  174935. if (np == NULL)
  174936. {
  174937. png_warning(png_ptr, "No memory for sPLT palettes.");
  174938. return;
  174939. }
  174940. png_memcpy(np, info_ptr->splt_palettes,
  174941. info_ptr->splt_palettes_num * png_sizeof(png_sPLT_t));
  174942. png_free(png_ptr, info_ptr->splt_palettes);
  174943. info_ptr->splt_palettes=NULL;
  174944. for (i = 0; i < nentries; i++)
  174945. {
  174946. png_sPLT_tp to = np + info_ptr->splt_palettes_num + i;
  174947. png_sPLT_tp from = entries + i;
  174948. to->name = (png_charp)png_malloc_warn(png_ptr,
  174949. png_strlen(from->name) + 1);
  174950. if (to->name == NULL)
  174951. {
  174952. png_warning(png_ptr,
  174953. "Out of memory while processing sPLT chunk");
  174954. }
  174955. png_strncpy(to->name, from->name, png_strlen(from->name)+1);
  174956. to->entries = (png_sPLT_entryp)png_malloc_warn(png_ptr,
  174957. from->nentries * png_sizeof(png_sPLT_entry));
  174958. png_memcpy(to->entries, from->entries,
  174959. from->nentries * png_sizeof(png_sPLT_entry));
  174960. if (to->entries == NULL)
  174961. {
  174962. png_warning(png_ptr,
  174963. "Out of memory while processing sPLT chunk");
  174964. png_free(png_ptr,to->name);
  174965. to->name = NULL;
  174966. }
  174967. to->nentries = from->nentries;
  174968. to->depth = from->depth;
  174969. }
  174970. info_ptr->splt_palettes = np;
  174971. info_ptr->splt_palettes_num += nentries;
  174972. info_ptr->valid |= PNG_INFO_sPLT;
  174973. #ifdef PNG_FREE_ME_SUPPORTED
  174974. info_ptr->free_me |= PNG_FREE_SPLT;
  174975. #endif
  174976. }
  174977. #endif /* PNG_sPLT_SUPPORTED */
  174978. #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
  174979. void PNGAPI
  174980. png_set_unknown_chunks(png_structp png_ptr,
  174981. png_infop info_ptr, png_unknown_chunkp unknowns, int num_unknowns)
  174982. {
  174983. png_unknown_chunkp np;
  174984. int i;
  174985. if (png_ptr == NULL || info_ptr == NULL || num_unknowns == 0)
  174986. return;
  174987. np = (png_unknown_chunkp)png_malloc_warn(png_ptr,
  174988. (info_ptr->unknown_chunks_num + num_unknowns) *
  174989. png_sizeof(png_unknown_chunk));
  174990. if (np == NULL)
  174991. {
  174992. png_warning(png_ptr,
  174993. "Out of memory while processing unknown chunk.");
  174994. return;
  174995. }
  174996. png_memcpy(np, info_ptr->unknown_chunks,
  174997. info_ptr->unknown_chunks_num * png_sizeof(png_unknown_chunk));
  174998. png_free(png_ptr, info_ptr->unknown_chunks);
  174999. info_ptr->unknown_chunks=NULL;
  175000. for (i = 0; i < num_unknowns; i++)
  175001. {
  175002. png_unknown_chunkp to = np + info_ptr->unknown_chunks_num + i;
  175003. png_unknown_chunkp from = unknowns + i;
  175004. png_strncpy((png_charp)to->name, (png_charp)from->name, 5);
  175005. to->data = (png_bytep)png_malloc_warn(png_ptr, from->size);
  175006. if (to->data == NULL)
  175007. {
  175008. png_warning(png_ptr,
  175009. "Out of memory while processing unknown chunk.");
  175010. }
  175011. else
  175012. {
  175013. png_memcpy(to->data, from->data, from->size);
  175014. to->size = from->size;
  175015. to->location = (png_byte)(png_ptr->mode & 0xff);
  175016. }
  175017. }
  175018. info_ptr->unknown_chunks = np;
  175019. info_ptr->unknown_chunks_num += num_unknowns;
  175020. #ifdef PNG_FREE_ME_SUPPORTED
  175021. info_ptr->free_me |= PNG_FREE_UNKN;
  175022. #endif
  175023. }
  175024. void PNGAPI
  175025. png_set_unknown_chunk_location(png_structp png_ptr, png_infop info_ptr,
  175026. int chunk, int location)
  175027. {
  175028. if(png_ptr != NULL && info_ptr != NULL && chunk >= 0 && chunk <
  175029. (int)info_ptr->unknown_chunks_num)
  175030. info_ptr->unknown_chunks[chunk].location = (png_byte)location;
  175031. }
  175032. #endif
  175033. #if defined(PNG_1_0_X) || defined(PNG_1_2_X)
  175034. #if defined(PNG_READ_EMPTY_PLTE_SUPPORTED) || \
  175035. defined(PNG_WRITE_EMPTY_PLTE_SUPPORTED)
  175036. void PNGAPI
  175037. png_permit_empty_plte (png_structp png_ptr, int empty_plte_permitted)
  175038. {
  175039. png_debug(1, "in png_permit_empty_plte, DEPRECATED.\n");
  175040. if (png_ptr == NULL)
  175041. return;
  175042. png_ptr->mng_features_permitted = (png_byte)
  175043. ((png_ptr->mng_features_permitted & (~(PNG_FLAG_MNG_EMPTY_PLTE))) |
  175044. ((empty_plte_permitted & PNG_FLAG_MNG_EMPTY_PLTE)));
  175045. }
  175046. #endif
  175047. #endif
  175048. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  175049. png_uint_32 PNGAPI
  175050. png_permit_mng_features (png_structp png_ptr, png_uint_32 mng_features)
  175051. {
  175052. png_debug(1, "in png_permit_mng_features\n");
  175053. if (png_ptr == NULL)
  175054. return (png_uint_32)0;
  175055. png_ptr->mng_features_permitted =
  175056. (png_byte)(mng_features & PNG_ALL_MNG_FEATURES);
  175057. return (png_uint_32)png_ptr->mng_features_permitted;
  175058. }
  175059. #endif
  175060. #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
  175061. void PNGAPI
  175062. png_set_keep_unknown_chunks(png_structp png_ptr, int keep, png_bytep
  175063. chunk_list, int num_chunks)
  175064. {
  175065. png_bytep new_list, p;
  175066. int i, old_num_chunks;
  175067. if (png_ptr == NULL)
  175068. return;
  175069. if (num_chunks == 0)
  175070. {
  175071. if(keep == PNG_HANDLE_CHUNK_ALWAYS || keep == PNG_HANDLE_CHUNK_IF_SAFE)
  175072. png_ptr->flags |= PNG_FLAG_KEEP_UNKNOWN_CHUNKS;
  175073. else
  175074. png_ptr->flags &= ~PNG_FLAG_KEEP_UNKNOWN_CHUNKS;
  175075. if(keep == PNG_HANDLE_CHUNK_ALWAYS)
  175076. png_ptr->flags |= PNG_FLAG_KEEP_UNSAFE_CHUNKS;
  175077. else
  175078. png_ptr->flags &= ~PNG_FLAG_KEEP_UNSAFE_CHUNKS;
  175079. return;
  175080. }
  175081. if (chunk_list == NULL)
  175082. return;
  175083. old_num_chunks=png_ptr->num_chunk_list;
  175084. new_list=(png_bytep)png_malloc(png_ptr,
  175085. (png_uint_32)(5*(num_chunks+old_num_chunks)));
  175086. if(png_ptr->chunk_list != NULL)
  175087. {
  175088. png_memcpy(new_list, png_ptr->chunk_list,
  175089. (png_size_t)(5*old_num_chunks));
  175090. png_free(png_ptr, png_ptr->chunk_list);
  175091. png_ptr->chunk_list=NULL;
  175092. }
  175093. png_memcpy(new_list+5*old_num_chunks, chunk_list,
  175094. (png_size_t)(5*num_chunks));
  175095. for (p=new_list+5*old_num_chunks+4, i=0; i<num_chunks; i++, p+=5)
  175096. *p=(png_byte)keep;
  175097. png_ptr->num_chunk_list=old_num_chunks+num_chunks;
  175098. png_ptr->chunk_list=new_list;
  175099. #ifdef PNG_FREE_ME_SUPPORTED
  175100. png_ptr->free_me |= PNG_FREE_LIST;
  175101. #endif
  175102. }
  175103. #endif
  175104. #if defined(PNG_READ_USER_CHUNKS_SUPPORTED)
  175105. void PNGAPI
  175106. png_set_read_user_chunk_fn(png_structp png_ptr, png_voidp user_chunk_ptr,
  175107. png_user_chunk_ptr read_user_chunk_fn)
  175108. {
  175109. png_debug(1, "in png_set_read_user_chunk_fn\n");
  175110. if (png_ptr == NULL)
  175111. return;
  175112. png_ptr->read_user_chunk_fn = read_user_chunk_fn;
  175113. png_ptr->user_chunk_ptr = user_chunk_ptr;
  175114. }
  175115. #endif
  175116. #if defined(PNG_INFO_IMAGE_SUPPORTED)
  175117. void PNGAPI
  175118. png_set_rows(png_structp png_ptr, png_infop info_ptr, png_bytepp row_pointers)
  175119. {
  175120. png_debug1(1, "in %s storage function\n", "rows");
  175121. if (png_ptr == NULL || info_ptr == NULL)
  175122. return;
  175123. if(info_ptr->row_pointers && (info_ptr->row_pointers != row_pointers))
  175124. png_free_data(png_ptr, info_ptr, PNG_FREE_ROWS, 0);
  175125. info_ptr->row_pointers = row_pointers;
  175126. if(row_pointers)
  175127. info_ptr->valid |= PNG_INFO_IDAT;
  175128. }
  175129. #endif
  175130. #ifdef PNG_WRITE_SUPPORTED
  175131. void PNGAPI
  175132. png_set_compression_buffer_size(png_structp png_ptr, png_uint_32 size)
  175133. {
  175134. if (png_ptr == NULL)
  175135. return;
  175136. if(png_ptr->zbuf)
  175137. png_free(png_ptr, png_ptr->zbuf);
  175138. png_ptr->zbuf_size = (png_size_t)size;
  175139. png_ptr->zbuf = (png_bytep)png_malloc(png_ptr, size);
  175140. png_ptr->zstream.next_out = png_ptr->zbuf;
  175141. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  175142. }
  175143. #endif
  175144. void PNGAPI
  175145. png_set_invalid(png_structp png_ptr, png_infop info_ptr, int mask)
  175146. {
  175147. if (png_ptr && info_ptr)
  175148. info_ptr->valid &= ~(mask);
  175149. }
  175150. #ifndef PNG_1_0_X
  175151. #ifdef PNG_ASSEMBLER_CODE_SUPPORTED
  175152. void PNGAPI
  175153. png_set_asm_flags (png_structp png_ptr, png_uint_32 asm_flags)
  175154. {
  175155. if (png_ptr != NULL)
  175156. png_ptr->asm_flags = 0;
  175157. }
  175158. void PNGAPI
  175159. png_set_mmx_thresholds (png_structp png_ptr,
  175160. png_byte mmx_bitdepth_threshold,
  175161. png_uint_32 mmx_rowbytes_threshold)
  175162. {
  175163. if (png_ptr == NULL)
  175164. return;
  175165. }
  175166. #endif /* ?PNG_ASSEMBLER_CODE_SUPPORTED */
  175167. #ifdef PNG_SET_USER_LIMITS_SUPPORTED
  175168. void PNGAPI
  175169. png_set_user_limits (png_structp png_ptr, png_uint_32 user_width_max,
  175170. png_uint_32 user_height_max)
  175171. {
  175172. if(png_ptr == NULL) return;
  175173. png_ptr->user_width_max = user_width_max;
  175174. png_ptr->user_height_max = user_height_max;
  175175. }
  175176. #endif /* ?PNG_SET_USER_LIMITS_SUPPORTED */
  175177. #endif /* ?PNG_1_0_X */
  175178. #endif /* PNG_READ_SUPPORTED || PNG_WRITE_SUPPORTED */
  175179. /********* End of inlined file: pngset.c *********/
  175180. /********* Start of inlined file: pngtrans.c *********/
  175181. #define PNG_INTERNAL
  175182. #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
  175183. #if defined(PNG_READ_BGR_SUPPORTED) || defined(PNG_WRITE_BGR_SUPPORTED)
  175184. void PNGAPI
  175185. png_set_bgr(png_structp png_ptr)
  175186. {
  175187. png_debug(1, "in png_set_bgr\n");
  175188. if(png_ptr == NULL) return;
  175189. png_ptr->transformations |= PNG_BGR;
  175190. }
  175191. #endif
  175192. #if defined(PNG_READ_SWAP_SUPPORTED) || defined(PNG_WRITE_SWAP_SUPPORTED)
  175193. void PNGAPI
  175194. png_set_swap(png_structp png_ptr)
  175195. {
  175196. png_debug(1, "in png_set_swap\n");
  175197. if(png_ptr == NULL) return;
  175198. if (png_ptr->bit_depth == 16)
  175199. png_ptr->transformations |= PNG_SWAP_BYTES;
  175200. }
  175201. #endif
  175202. #if defined(PNG_READ_PACK_SUPPORTED) || defined(PNG_WRITE_PACK_SUPPORTED)
  175203. void PNGAPI
  175204. png_set_packing(png_structp png_ptr)
  175205. {
  175206. png_debug(1, "in png_set_packing\n");
  175207. if(png_ptr == NULL) return;
  175208. if (png_ptr->bit_depth < 8)
  175209. {
  175210. png_ptr->transformations |= PNG_PACK;
  175211. png_ptr->usr_bit_depth = 8;
  175212. }
  175213. }
  175214. #endif
  175215. #if defined(PNG_READ_PACKSWAP_SUPPORTED)||defined(PNG_WRITE_PACKSWAP_SUPPORTED)
  175216. void PNGAPI
  175217. png_set_packswap(png_structp png_ptr)
  175218. {
  175219. png_debug(1, "in png_set_packswap\n");
  175220. if(png_ptr == NULL) return;
  175221. if (png_ptr->bit_depth < 8)
  175222. png_ptr->transformations |= PNG_PACKSWAP;
  175223. }
  175224. #endif
  175225. #if defined(PNG_READ_SHIFT_SUPPORTED) || defined(PNG_WRITE_SHIFT_SUPPORTED)
  175226. void PNGAPI
  175227. png_set_shift(png_structp png_ptr, png_color_8p true_bits)
  175228. {
  175229. png_debug(1, "in png_set_shift\n");
  175230. if(png_ptr == NULL) return;
  175231. png_ptr->transformations |= PNG_SHIFT;
  175232. png_ptr->shift = *true_bits;
  175233. }
  175234. #endif
  175235. #if defined(PNG_READ_INTERLACING_SUPPORTED) || \
  175236. defined(PNG_WRITE_INTERLACING_SUPPORTED)
  175237. int PNGAPI
  175238. png_set_interlace_handling(png_structp png_ptr)
  175239. {
  175240. png_debug(1, "in png_set_interlace handling\n");
  175241. if (png_ptr && png_ptr->interlaced)
  175242. {
  175243. png_ptr->transformations |= PNG_INTERLACE;
  175244. return (7);
  175245. }
  175246. return (1);
  175247. }
  175248. #endif
  175249. #if defined(PNG_READ_FILLER_SUPPORTED) || defined(PNG_WRITE_FILLER_SUPPORTED)
  175250. void PNGAPI
  175251. png_set_filler(png_structp png_ptr, png_uint_32 filler, int filler_loc)
  175252. {
  175253. png_debug(1, "in png_set_filler\n");
  175254. if(png_ptr == NULL) return;
  175255. png_ptr->transformations |= PNG_FILLER;
  175256. png_ptr->filler = (png_byte)filler;
  175257. if (filler_loc == PNG_FILLER_AFTER)
  175258. png_ptr->flags |= PNG_FLAG_FILLER_AFTER;
  175259. else
  175260. png_ptr->flags &= ~PNG_FLAG_FILLER_AFTER;
  175261. if (png_ptr->color_type == PNG_COLOR_TYPE_RGB)
  175262. {
  175263. png_ptr->usr_channels = 4;
  175264. }
  175265. if (png_ptr->color_type == PNG_COLOR_TYPE_GRAY && png_ptr->bit_depth >= 8)
  175266. {
  175267. png_ptr->usr_channels = 2;
  175268. }
  175269. }
  175270. #if !defined(PNG_1_0_X)
  175271. void PNGAPI
  175272. png_set_add_alpha(png_structp png_ptr, png_uint_32 filler, int filler_loc)
  175273. {
  175274. png_debug(1, "in png_set_add_alpha\n");
  175275. if(png_ptr == NULL) return;
  175276. png_set_filler(png_ptr, filler, filler_loc);
  175277. png_ptr->transformations |= PNG_ADD_ALPHA;
  175278. }
  175279. #endif
  175280. #endif
  175281. #if defined(PNG_READ_SWAP_ALPHA_SUPPORTED) || \
  175282. defined(PNG_WRITE_SWAP_ALPHA_SUPPORTED)
  175283. void PNGAPI
  175284. png_set_swap_alpha(png_structp png_ptr)
  175285. {
  175286. png_debug(1, "in png_set_swap_alpha\n");
  175287. if(png_ptr == NULL) return;
  175288. png_ptr->transformations |= PNG_SWAP_ALPHA;
  175289. }
  175290. #endif
  175291. #if defined(PNG_READ_INVERT_ALPHA_SUPPORTED) || \
  175292. defined(PNG_WRITE_INVERT_ALPHA_SUPPORTED)
  175293. void PNGAPI
  175294. png_set_invert_alpha(png_structp png_ptr)
  175295. {
  175296. png_debug(1, "in png_set_invert_alpha\n");
  175297. if(png_ptr == NULL) return;
  175298. png_ptr->transformations |= PNG_INVERT_ALPHA;
  175299. }
  175300. #endif
  175301. #if defined(PNG_READ_INVERT_SUPPORTED) || defined(PNG_WRITE_INVERT_SUPPORTED)
  175302. void PNGAPI
  175303. png_set_invert_mono(png_structp png_ptr)
  175304. {
  175305. png_debug(1, "in png_set_invert_mono\n");
  175306. if(png_ptr == NULL) return;
  175307. png_ptr->transformations |= PNG_INVERT_MONO;
  175308. }
  175309. void /* PRIVATE */
  175310. png_do_invert(png_row_infop row_info, png_bytep row)
  175311. {
  175312. png_debug(1, "in png_do_invert\n");
  175313. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  175314. if (row == NULL || row_info == NULL)
  175315. return;
  175316. #endif
  175317. if (row_info->color_type == PNG_COLOR_TYPE_GRAY)
  175318. {
  175319. png_bytep rp = row;
  175320. png_uint_32 i;
  175321. png_uint_32 istop = row_info->rowbytes;
  175322. for (i = 0; i < istop; i++)
  175323. {
  175324. *rp = (png_byte)(~(*rp));
  175325. rp++;
  175326. }
  175327. }
  175328. else if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA &&
  175329. row_info->bit_depth == 8)
  175330. {
  175331. png_bytep rp = row;
  175332. png_uint_32 i;
  175333. png_uint_32 istop = row_info->rowbytes;
  175334. for (i = 0; i < istop; i+=2)
  175335. {
  175336. *rp = (png_byte)(~(*rp));
  175337. rp+=2;
  175338. }
  175339. }
  175340. else if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA &&
  175341. row_info->bit_depth == 16)
  175342. {
  175343. png_bytep rp = row;
  175344. png_uint_32 i;
  175345. png_uint_32 istop = row_info->rowbytes;
  175346. for (i = 0; i < istop; i+=4)
  175347. {
  175348. *rp = (png_byte)(~(*rp));
  175349. *(rp+1) = (png_byte)(~(*(rp+1)));
  175350. rp+=4;
  175351. }
  175352. }
  175353. }
  175354. #endif
  175355. #if defined(PNG_READ_SWAP_SUPPORTED) || defined(PNG_WRITE_SWAP_SUPPORTED)
  175356. void /* PRIVATE */
  175357. png_do_swap(png_row_infop row_info, png_bytep row)
  175358. {
  175359. png_debug(1, "in png_do_swap\n");
  175360. if (
  175361. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  175362. row != NULL && row_info != NULL &&
  175363. #endif
  175364. row_info->bit_depth == 16)
  175365. {
  175366. png_bytep rp = row;
  175367. png_uint_32 i;
  175368. png_uint_32 istop= row_info->width * row_info->channels;
  175369. for (i = 0; i < istop; i++, rp += 2)
  175370. {
  175371. png_byte t = *rp;
  175372. *rp = *(rp + 1);
  175373. *(rp + 1) = t;
  175374. }
  175375. }
  175376. }
  175377. #endif
  175378. #if defined(PNG_READ_PACKSWAP_SUPPORTED)||defined(PNG_WRITE_PACKSWAP_SUPPORTED)
  175379. static PNG_CONST png_byte onebppswaptable[256] = {
  175380. 0x00, 0x80, 0x40, 0xC0, 0x20, 0xA0, 0x60, 0xE0,
  175381. 0x10, 0x90, 0x50, 0xD0, 0x30, 0xB0, 0x70, 0xF0,
  175382. 0x08, 0x88, 0x48, 0xC8, 0x28, 0xA8, 0x68, 0xE8,
  175383. 0x18, 0x98, 0x58, 0xD8, 0x38, 0xB8, 0x78, 0xF8,
  175384. 0x04, 0x84, 0x44, 0xC4, 0x24, 0xA4, 0x64, 0xE4,
  175385. 0x14, 0x94, 0x54, 0xD4, 0x34, 0xB4, 0x74, 0xF4,
  175386. 0x0C, 0x8C, 0x4C, 0xCC, 0x2C, 0xAC, 0x6C, 0xEC,
  175387. 0x1C, 0x9C, 0x5C, 0xDC, 0x3C, 0xBC, 0x7C, 0xFC,
  175388. 0x02, 0x82, 0x42, 0xC2, 0x22, 0xA2, 0x62, 0xE2,
  175389. 0x12, 0x92, 0x52, 0xD2, 0x32, 0xB2, 0x72, 0xF2,
  175390. 0x0A, 0x8A, 0x4A, 0xCA, 0x2A, 0xAA, 0x6A, 0xEA,
  175391. 0x1A, 0x9A, 0x5A, 0xDA, 0x3A, 0xBA, 0x7A, 0xFA,
  175392. 0x06, 0x86, 0x46, 0xC6, 0x26, 0xA6, 0x66, 0xE6,
  175393. 0x16, 0x96, 0x56, 0xD6, 0x36, 0xB6, 0x76, 0xF6,
  175394. 0x0E, 0x8E, 0x4E, 0xCE, 0x2E, 0xAE, 0x6E, 0xEE,
  175395. 0x1E, 0x9E, 0x5E, 0xDE, 0x3E, 0xBE, 0x7E, 0xFE,
  175396. 0x01, 0x81, 0x41, 0xC1, 0x21, 0xA1, 0x61, 0xE1,
  175397. 0x11, 0x91, 0x51, 0xD1, 0x31, 0xB1, 0x71, 0xF1,
  175398. 0x09, 0x89, 0x49, 0xC9, 0x29, 0xA9, 0x69, 0xE9,
  175399. 0x19, 0x99, 0x59, 0xD9, 0x39, 0xB9, 0x79, 0xF9,
  175400. 0x05, 0x85, 0x45, 0xC5, 0x25, 0xA5, 0x65, 0xE5,
  175401. 0x15, 0x95, 0x55, 0xD5, 0x35, 0xB5, 0x75, 0xF5,
  175402. 0x0D, 0x8D, 0x4D, 0xCD, 0x2D, 0xAD, 0x6D, 0xED,
  175403. 0x1D, 0x9D, 0x5D, 0xDD, 0x3D, 0xBD, 0x7D, 0xFD,
  175404. 0x03, 0x83, 0x43, 0xC3, 0x23, 0xA3, 0x63, 0xE3,
  175405. 0x13, 0x93, 0x53, 0xD3, 0x33, 0xB3, 0x73, 0xF3,
  175406. 0x0B, 0x8B, 0x4B, 0xCB, 0x2B, 0xAB, 0x6B, 0xEB,
  175407. 0x1B, 0x9B, 0x5B, 0xDB, 0x3B, 0xBB, 0x7B, 0xFB,
  175408. 0x07, 0x87, 0x47, 0xC7, 0x27, 0xA7, 0x67, 0xE7,
  175409. 0x17, 0x97, 0x57, 0xD7, 0x37, 0xB7, 0x77, 0xF7,
  175410. 0x0F, 0x8F, 0x4F, 0xCF, 0x2F, 0xAF, 0x6F, 0xEF,
  175411. 0x1F, 0x9F, 0x5F, 0xDF, 0x3F, 0xBF, 0x7F, 0xFF
  175412. };
  175413. static PNG_CONST png_byte twobppswaptable[256] = {
  175414. 0x00, 0x40, 0x80, 0xC0, 0x10, 0x50, 0x90, 0xD0,
  175415. 0x20, 0x60, 0xA0, 0xE0, 0x30, 0x70, 0xB0, 0xF0,
  175416. 0x04, 0x44, 0x84, 0xC4, 0x14, 0x54, 0x94, 0xD4,
  175417. 0x24, 0x64, 0xA4, 0xE4, 0x34, 0x74, 0xB4, 0xF4,
  175418. 0x08, 0x48, 0x88, 0xC8, 0x18, 0x58, 0x98, 0xD8,
  175419. 0x28, 0x68, 0xA8, 0xE8, 0x38, 0x78, 0xB8, 0xF8,
  175420. 0x0C, 0x4C, 0x8C, 0xCC, 0x1C, 0x5C, 0x9C, 0xDC,
  175421. 0x2C, 0x6C, 0xAC, 0xEC, 0x3C, 0x7C, 0xBC, 0xFC,
  175422. 0x01, 0x41, 0x81, 0xC1, 0x11, 0x51, 0x91, 0xD1,
  175423. 0x21, 0x61, 0xA1, 0xE1, 0x31, 0x71, 0xB1, 0xF1,
  175424. 0x05, 0x45, 0x85, 0xC5, 0x15, 0x55, 0x95, 0xD5,
  175425. 0x25, 0x65, 0xA5, 0xE5, 0x35, 0x75, 0xB5, 0xF5,
  175426. 0x09, 0x49, 0x89, 0xC9, 0x19, 0x59, 0x99, 0xD9,
  175427. 0x29, 0x69, 0xA9, 0xE9, 0x39, 0x79, 0xB9, 0xF9,
  175428. 0x0D, 0x4D, 0x8D, 0xCD, 0x1D, 0x5D, 0x9D, 0xDD,
  175429. 0x2D, 0x6D, 0xAD, 0xED, 0x3D, 0x7D, 0xBD, 0xFD,
  175430. 0x02, 0x42, 0x82, 0xC2, 0x12, 0x52, 0x92, 0xD2,
  175431. 0x22, 0x62, 0xA2, 0xE2, 0x32, 0x72, 0xB2, 0xF2,
  175432. 0x06, 0x46, 0x86, 0xC6, 0x16, 0x56, 0x96, 0xD6,
  175433. 0x26, 0x66, 0xA6, 0xE6, 0x36, 0x76, 0xB6, 0xF6,
  175434. 0x0A, 0x4A, 0x8A, 0xCA, 0x1A, 0x5A, 0x9A, 0xDA,
  175435. 0x2A, 0x6A, 0xAA, 0xEA, 0x3A, 0x7A, 0xBA, 0xFA,
  175436. 0x0E, 0x4E, 0x8E, 0xCE, 0x1E, 0x5E, 0x9E, 0xDE,
  175437. 0x2E, 0x6E, 0xAE, 0xEE, 0x3E, 0x7E, 0xBE, 0xFE,
  175438. 0x03, 0x43, 0x83, 0xC3, 0x13, 0x53, 0x93, 0xD3,
  175439. 0x23, 0x63, 0xA3, 0xE3, 0x33, 0x73, 0xB3, 0xF3,
  175440. 0x07, 0x47, 0x87, 0xC7, 0x17, 0x57, 0x97, 0xD7,
  175441. 0x27, 0x67, 0xA7, 0xE7, 0x37, 0x77, 0xB7, 0xF7,
  175442. 0x0B, 0x4B, 0x8B, 0xCB, 0x1B, 0x5B, 0x9B, 0xDB,
  175443. 0x2B, 0x6B, 0xAB, 0xEB, 0x3B, 0x7B, 0xBB, 0xFB,
  175444. 0x0F, 0x4F, 0x8F, 0xCF, 0x1F, 0x5F, 0x9F, 0xDF,
  175445. 0x2F, 0x6F, 0xAF, 0xEF, 0x3F, 0x7F, 0xBF, 0xFF
  175446. };
  175447. static PNG_CONST png_byte fourbppswaptable[256] = {
  175448. 0x00, 0x10, 0x20, 0x30, 0x40, 0x50, 0x60, 0x70,
  175449. 0x80, 0x90, 0xA0, 0xB0, 0xC0, 0xD0, 0xE0, 0xF0,
  175450. 0x01, 0x11, 0x21, 0x31, 0x41, 0x51, 0x61, 0x71,
  175451. 0x81, 0x91, 0xA1, 0xB1, 0xC1, 0xD1, 0xE1, 0xF1,
  175452. 0x02, 0x12, 0x22, 0x32, 0x42, 0x52, 0x62, 0x72,
  175453. 0x82, 0x92, 0xA2, 0xB2, 0xC2, 0xD2, 0xE2, 0xF2,
  175454. 0x03, 0x13, 0x23, 0x33, 0x43, 0x53, 0x63, 0x73,
  175455. 0x83, 0x93, 0xA3, 0xB3, 0xC3, 0xD3, 0xE3, 0xF3,
  175456. 0x04, 0x14, 0x24, 0x34, 0x44, 0x54, 0x64, 0x74,
  175457. 0x84, 0x94, 0xA4, 0xB4, 0xC4, 0xD4, 0xE4, 0xF4,
  175458. 0x05, 0x15, 0x25, 0x35, 0x45, 0x55, 0x65, 0x75,
  175459. 0x85, 0x95, 0xA5, 0xB5, 0xC5, 0xD5, 0xE5, 0xF5,
  175460. 0x06, 0x16, 0x26, 0x36, 0x46, 0x56, 0x66, 0x76,
  175461. 0x86, 0x96, 0xA6, 0xB6, 0xC6, 0xD6, 0xE6, 0xF6,
  175462. 0x07, 0x17, 0x27, 0x37, 0x47, 0x57, 0x67, 0x77,
  175463. 0x87, 0x97, 0xA7, 0xB7, 0xC7, 0xD7, 0xE7, 0xF7,
  175464. 0x08, 0x18, 0x28, 0x38, 0x48, 0x58, 0x68, 0x78,
  175465. 0x88, 0x98, 0xA8, 0xB8, 0xC8, 0xD8, 0xE8, 0xF8,
  175466. 0x09, 0x19, 0x29, 0x39, 0x49, 0x59, 0x69, 0x79,
  175467. 0x89, 0x99, 0xA9, 0xB9, 0xC9, 0xD9, 0xE9, 0xF9,
  175468. 0x0A, 0x1A, 0x2A, 0x3A, 0x4A, 0x5A, 0x6A, 0x7A,
  175469. 0x8A, 0x9A, 0xAA, 0xBA, 0xCA, 0xDA, 0xEA, 0xFA,
  175470. 0x0B, 0x1B, 0x2B, 0x3B, 0x4B, 0x5B, 0x6B, 0x7B,
  175471. 0x8B, 0x9B, 0xAB, 0xBB, 0xCB, 0xDB, 0xEB, 0xFB,
  175472. 0x0C, 0x1C, 0x2C, 0x3C, 0x4C, 0x5C, 0x6C, 0x7C,
  175473. 0x8C, 0x9C, 0xAC, 0xBC, 0xCC, 0xDC, 0xEC, 0xFC,
  175474. 0x0D, 0x1D, 0x2D, 0x3D, 0x4D, 0x5D, 0x6D, 0x7D,
  175475. 0x8D, 0x9D, 0xAD, 0xBD, 0xCD, 0xDD, 0xED, 0xFD,
  175476. 0x0E, 0x1E, 0x2E, 0x3E, 0x4E, 0x5E, 0x6E, 0x7E,
  175477. 0x8E, 0x9E, 0xAE, 0xBE, 0xCE, 0xDE, 0xEE, 0xFE,
  175478. 0x0F, 0x1F, 0x2F, 0x3F, 0x4F, 0x5F, 0x6F, 0x7F,
  175479. 0x8F, 0x9F, 0xAF, 0xBF, 0xCF, 0xDF, 0xEF, 0xFF
  175480. };
  175481. void /* PRIVATE */
  175482. png_do_packswap(png_row_infop row_info, png_bytep row)
  175483. {
  175484. png_debug(1, "in png_do_packswap\n");
  175485. if (
  175486. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  175487. row != NULL && row_info != NULL &&
  175488. #endif
  175489. row_info->bit_depth < 8)
  175490. {
  175491. png_bytep rp, end, table;
  175492. end = row + row_info->rowbytes;
  175493. if (row_info->bit_depth == 1)
  175494. table = (png_bytep)onebppswaptable;
  175495. else if (row_info->bit_depth == 2)
  175496. table = (png_bytep)twobppswaptable;
  175497. else if (row_info->bit_depth == 4)
  175498. table = (png_bytep)fourbppswaptable;
  175499. else
  175500. return;
  175501. for (rp = row; rp < end; rp++)
  175502. *rp = table[*rp];
  175503. }
  175504. }
  175505. #endif /* PNG_READ_PACKSWAP_SUPPORTED or PNG_WRITE_PACKSWAP_SUPPORTED */
  175506. #if defined(PNG_WRITE_FILLER_SUPPORTED) || \
  175507. defined(PNG_READ_STRIP_ALPHA_SUPPORTED)
  175508. void /* PRIVATE */
  175509. png_do_strip_filler(png_row_infop row_info, png_bytep row, png_uint_32 flags)
  175510. {
  175511. png_debug(1, "in png_do_strip_filler\n");
  175512. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  175513. if (row != NULL && row_info != NULL)
  175514. #endif
  175515. {
  175516. png_bytep sp=row;
  175517. png_bytep dp=row;
  175518. png_uint_32 row_width=row_info->width;
  175519. png_uint_32 i;
  175520. if ((row_info->color_type == PNG_COLOR_TYPE_RGB ||
  175521. (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA &&
  175522. (flags & PNG_FLAG_STRIP_ALPHA))) &&
  175523. row_info->channels == 4)
  175524. {
  175525. if (row_info->bit_depth == 8)
  175526. {
  175527. if (flags & PNG_FLAG_FILLER_AFTER)
  175528. {
  175529. dp+=3; sp+=4;
  175530. for (i = 1; i < row_width; i++)
  175531. {
  175532. *dp++ = *sp++;
  175533. *dp++ = *sp++;
  175534. *dp++ = *sp++;
  175535. sp++;
  175536. }
  175537. }
  175538. else
  175539. {
  175540. for (i = 0; i < row_width; i++)
  175541. {
  175542. sp++;
  175543. *dp++ = *sp++;
  175544. *dp++ = *sp++;
  175545. *dp++ = *sp++;
  175546. }
  175547. }
  175548. row_info->pixel_depth = 24;
  175549. row_info->rowbytes = row_width * 3;
  175550. }
  175551. else /* if (row_info->bit_depth == 16) */
  175552. {
  175553. if (flags & PNG_FLAG_FILLER_AFTER)
  175554. {
  175555. sp += 8; dp += 6;
  175556. for (i = 1; i < row_width; i++)
  175557. {
  175558. *dp++ = *sp++;
  175559. *dp++ = *sp++;
  175560. *dp++ = *sp++;
  175561. *dp++ = *sp++;
  175562. *dp++ = *sp++;
  175563. *dp++ = *sp++;
  175564. sp += 2;
  175565. }
  175566. }
  175567. else
  175568. {
  175569. for (i = 0; i < row_width; i++)
  175570. {
  175571. sp+=2;
  175572. *dp++ = *sp++;
  175573. *dp++ = *sp++;
  175574. *dp++ = *sp++;
  175575. *dp++ = *sp++;
  175576. *dp++ = *sp++;
  175577. *dp++ = *sp++;
  175578. }
  175579. }
  175580. row_info->pixel_depth = 48;
  175581. row_info->rowbytes = row_width * 6;
  175582. }
  175583. row_info->channels = 3;
  175584. }
  175585. else if ((row_info->color_type == PNG_COLOR_TYPE_GRAY ||
  175586. (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA &&
  175587. (flags & PNG_FLAG_STRIP_ALPHA))) &&
  175588. row_info->channels == 2)
  175589. {
  175590. if (row_info->bit_depth == 8)
  175591. {
  175592. if (flags & PNG_FLAG_FILLER_AFTER)
  175593. {
  175594. for (i = 0; i < row_width; i++)
  175595. {
  175596. *dp++ = *sp++;
  175597. sp++;
  175598. }
  175599. }
  175600. else
  175601. {
  175602. for (i = 0; i < row_width; i++)
  175603. {
  175604. sp++;
  175605. *dp++ = *sp++;
  175606. }
  175607. }
  175608. row_info->pixel_depth = 8;
  175609. row_info->rowbytes = row_width;
  175610. }
  175611. else /* if (row_info->bit_depth == 16) */
  175612. {
  175613. if (flags & PNG_FLAG_FILLER_AFTER)
  175614. {
  175615. sp += 4; dp += 2;
  175616. for (i = 1; i < row_width; i++)
  175617. {
  175618. *dp++ = *sp++;
  175619. *dp++ = *sp++;
  175620. sp += 2;
  175621. }
  175622. }
  175623. else
  175624. {
  175625. for (i = 0; i < row_width; i++)
  175626. {
  175627. sp += 2;
  175628. *dp++ = *sp++;
  175629. *dp++ = *sp++;
  175630. }
  175631. }
  175632. row_info->pixel_depth = 16;
  175633. row_info->rowbytes = row_width * 2;
  175634. }
  175635. row_info->channels = 1;
  175636. }
  175637. if (flags & PNG_FLAG_STRIP_ALPHA)
  175638. row_info->color_type &= ~PNG_COLOR_MASK_ALPHA;
  175639. }
  175640. }
  175641. #endif
  175642. #if defined(PNG_READ_BGR_SUPPORTED) || defined(PNG_WRITE_BGR_SUPPORTED)
  175643. void /* PRIVATE */
  175644. png_do_bgr(png_row_infop row_info, png_bytep row)
  175645. {
  175646. png_debug(1, "in png_do_bgr\n");
  175647. if (
  175648. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  175649. row != NULL && row_info != NULL &&
  175650. #endif
  175651. (row_info->color_type & PNG_COLOR_MASK_COLOR))
  175652. {
  175653. png_uint_32 row_width = row_info->width;
  175654. if (row_info->bit_depth == 8)
  175655. {
  175656. if (row_info->color_type == PNG_COLOR_TYPE_RGB)
  175657. {
  175658. png_bytep rp;
  175659. png_uint_32 i;
  175660. for (i = 0, rp = row; i < row_width; i++, rp += 3)
  175661. {
  175662. png_byte save = *rp;
  175663. *rp = *(rp + 2);
  175664. *(rp + 2) = save;
  175665. }
  175666. }
  175667. else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  175668. {
  175669. png_bytep rp;
  175670. png_uint_32 i;
  175671. for (i = 0, rp = row; i < row_width; i++, rp += 4)
  175672. {
  175673. png_byte save = *rp;
  175674. *rp = *(rp + 2);
  175675. *(rp + 2) = save;
  175676. }
  175677. }
  175678. }
  175679. else if (row_info->bit_depth == 16)
  175680. {
  175681. if (row_info->color_type == PNG_COLOR_TYPE_RGB)
  175682. {
  175683. png_bytep rp;
  175684. png_uint_32 i;
  175685. for (i = 0, rp = row; i < row_width; i++, rp += 6)
  175686. {
  175687. png_byte save = *rp;
  175688. *rp = *(rp + 4);
  175689. *(rp + 4) = save;
  175690. save = *(rp + 1);
  175691. *(rp + 1) = *(rp + 5);
  175692. *(rp + 5) = save;
  175693. }
  175694. }
  175695. else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  175696. {
  175697. png_bytep rp;
  175698. png_uint_32 i;
  175699. for (i = 0, rp = row; i < row_width; i++, rp += 8)
  175700. {
  175701. png_byte save = *rp;
  175702. *rp = *(rp + 4);
  175703. *(rp + 4) = save;
  175704. save = *(rp + 1);
  175705. *(rp + 1) = *(rp + 5);
  175706. *(rp + 5) = save;
  175707. }
  175708. }
  175709. }
  175710. }
  175711. }
  175712. #endif /* PNG_READ_BGR_SUPPORTED or PNG_WRITE_BGR_SUPPORTED */
  175713. #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \
  175714. defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED) || \
  175715. defined(PNG_LEGACY_SUPPORTED)
  175716. void PNGAPI
  175717. png_set_user_transform_info(png_structp png_ptr, png_voidp
  175718. user_transform_ptr, int user_transform_depth, int user_transform_channels)
  175719. {
  175720. png_debug(1, "in png_set_user_transform_info\n");
  175721. if(png_ptr == NULL) return;
  175722. #if defined(PNG_USER_TRANSFORM_PTR_SUPPORTED)
  175723. png_ptr->user_transform_ptr = user_transform_ptr;
  175724. png_ptr->user_transform_depth = (png_byte)user_transform_depth;
  175725. png_ptr->user_transform_channels = (png_byte)user_transform_channels;
  175726. #else
  175727. if(user_transform_ptr || user_transform_depth || user_transform_channels)
  175728. png_warning(png_ptr,
  175729. "This version of libpng does not support user transform info");
  175730. #endif
  175731. }
  175732. #endif
  175733. png_voidp PNGAPI
  175734. png_get_user_transform_ptr(png_structp png_ptr)
  175735. {
  175736. #if defined(PNG_USER_TRANSFORM_PTR_SUPPORTED)
  175737. if (png_ptr == NULL) return (NULL);
  175738. return ((png_voidp)png_ptr->user_transform_ptr);
  175739. #else
  175740. return (NULL);
  175741. #endif
  175742. }
  175743. #endif /* PNG_READ_SUPPORTED || PNG_WRITE_SUPPORTED */
  175744. /********* End of inlined file: pngtrans.c *********/
  175745. /********* Start of inlined file: pngwio.c *********/
  175746. #define PNG_INTERNAL
  175747. #ifdef PNG_WRITE_SUPPORTED
  175748. void /* PRIVATE */
  175749. png_write_data(png_structp png_ptr, png_bytep data, png_size_t length)
  175750. {
  175751. if (png_ptr->write_data_fn != NULL )
  175752. (*(png_ptr->write_data_fn))(png_ptr, data, length);
  175753. else
  175754. png_error(png_ptr, "Call to NULL write function");
  175755. }
  175756. #if !defined(PNG_NO_STDIO)
  175757. #ifndef USE_FAR_KEYWORD
  175758. void PNGAPI
  175759. png_default_write_data(png_structp png_ptr, png_bytep data, png_size_t length)
  175760. {
  175761. png_uint_32 check;
  175762. if(png_ptr == NULL) return;
  175763. #if defined(_WIN32_WCE)
  175764. if ( !WriteFile((HANDLE)(png_ptr->io_ptr), data, length, &check, NULL) )
  175765. check = 0;
  175766. #else
  175767. check = fwrite(data, 1, length, (png_FILE_p)(png_ptr->io_ptr));
  175768. #endif
  175769. if (check != length)
  175770. png_error(png_ptr, "Write Error");
  175771. }
  175772. #else
  175773. #define NEAR_BUF_SIZE 1024
  175774. #define MIN(a,b) (a <= b ? a : b)
  175775. void PNGAPI
  175776. png_default_write_data(png_structp png_ptr, png_bytep data, png_size_t length)
  175777. {
  175778. png_uint_32 check;
  175779. png_byte *near_data; /* Needs to be "png_byte *" instead of "png_bytep" */
  175780. png_FILE_p io_ptr;
  175781. if(png_ptr == NULL) return;
  175782. near_data = (png_byte *)CVT_PTR_NOCHECK(data);
  175783. io_ptr = (png_FILE_p)CVT_PTR(png_ptr->io_ptr);
  175784. if ((png_bytep)near_data == data)
  175785. {
  175786. #if defined(_WIN32_WCE)
  175787. if ( !WriteFile(io_ptr, near_data, length, &check, NULL) )
  175788. check = 0;
  175789. #else
  175790. check = fwrite(near_data, 1, length, io_ptr);
  175791. #endif
  175792. }
  175793. else
  175794. {
  175795. png_byte buf[NEAR_BUF_SIZE];
  175796. png_size_t written, remaining, err;
  175797. check = 0;
  175798. remaining = length;
  175799. do
  175800. {
  175801. written = MIN(NEAR_BUF_SIZE, remaining);
  175802. png_memcpy(buf, data, written); /* copy far buffer to near buffer */
  175803. #if defined(_WIN32_WCE)
  175804. if ( !WriteFile(io_ptr, buf, written, &err, NULL) )
  175805. err = 0;
  175806. #else
  175807. err = fwrite(buf, 1, written, io_ptr);
  175808. #endif
  175809. if (err != written)
  175810. break;
  175811. else
  175812. check += err;
  175813. data += written;
  175814. remaining -= written;
  175815. }
  175816. while (remaining != 0);
  175817. }
  175818. if (check != length)
  175819. png_error(png_ptr, "Write Error");
  175820. }
  175821. #endif
  175822. #endif
  175823. #if defined(PNG_WRITE_FLUSH_SUPPORTED)
  175824. void /* PRIVATE */
  175825. png_flush(png_structp png_ptr)
  175826. {
  175827. if (png_ptr->output_flush_fn != NULL)
  175828. (*(png_ptr->output_flush_fn))(png_ptr);
  175829. }
  175830. #if !defined(PNG_NO_STDIO)
  175831. void PNGAPI
  175832. png_default_flush(png_structp png_ptr)
  175833. {
  175834. #if !defined(_WIN32_WCE)
  175835. png_FILE_p io_ptr;
  175836. #endif
  175837. if(png_ptr == NULL) return;
  175838. #if !defined(_WIN32_WCE)
  175839. io_ptr = (png_FILE_p)CVT_PTR((png_ptr->io_ptr));
  175840. if (io_ptr != NULL)
  175841. fflush(io_ptr);
  175842. #endif
  175843. }
  175844. #endif
  175845. #endif
  175846. void PNGAPI
  175847. png_set_write_fn(png_structp png_ptr, png_voidp io_ptr,
  175848. png_rw_ptr write_data_fn, png_flush_ptr output_flush_fn)
  175849. {
  175850. if(png_ptr == NULL) return;
  175851. png_ptr->io_ptr = io_ptr;
  175852. #if !defined(PNG_NO_STDIO)
  175853. if (write_data_fn != NULL)
  175854. png_ptr->write_data_fn = write_data_fn;
  175855. else
  175856. png_ptr->write_data_fn = png_default_write_data;
  175857. #else
  175858. png_ptr->write_data_fn = write_data_fn;
  175859. #endif
  175860. #if defined(PNG_WRITE_FLUSH_SUPPORTED)
  175861. #if !defined(PNG_NO_STDIO)
  175862. if (output_flush_fn != NULL)
  175863. png_ptr->output_flush_fn = output_flush_fn;
  175864. else
  175865. png_ptr->output_flush_fn = png_default_flush;
  175866. #else
  175867. png_ptr->output_flush_fn = output_flush_fn;
  175868. #endif
  175869. #endif /* PNG_WRITE_FLUSH_SUPPORTED */
  175870. if (png_ptr->read_data_fn != NULL)
  175871. {
  175872. png_ptr->read_data_fn = NULL;
  175873. png_warning(png_ptr,
  175874. "Attempted to set both read_data_fn and write_data_fn in");
  175875. png_warning(png_ptr,
  175876. "the same structure. Resetting read_data_fn to NULL.");
  175877. }
  175878. }
  175879. #if defined(USE_FAR_KEYWORD)
  175880. #if defined(_MSC_VER)
  175881. void *png_far_to_near(png_structp png_ptr,png_voidp ptr, int check)
  175882. {
  175883. void *near_ptr;
  175884. void FAR *far_ptr;
  175885. FP_OFF(near_ptr) = FP_OFF(ptr);
  175886. far_ptr = (void FAR *)near_ptr;
  175887. if(check != 0)
  175888. if(FP_SEG(ptr) != FP_SEG(far_ptr))
  175889. png_error(png_ptr,"segment lost in conversion");
  175890. return(near_ptr);
  175891. }
  175892. # else
  175893. void *png_far_to_near(png_structp png_ptr,png_voidp ptr, int check)
  175894. {
  175895. void *near_ptr;
  175896. void FAR *far_ptr;
  175897. near_ptr = (void FAR *)ptr;
  175898. far_ptr = (void FAR *)near_ptr;
  175899. if(check != 0)
  175900. if(far_ptr != ptr)
  175901. png_error(png_ptr,"segment lost in conversion");
  175902. return(near_ptr);
  175903. }
  175904. # endif
  175905. # endif
  175906. #endif /* PNG_WRITE_SUPPORTED */
  175907. /********* End of inlined file: pngwio.c *********/
  175908. /********* Start of inlined file: pngwrite.c *********/
  175909. #define PNG_INTERNAL
  175910. #ifdef PNG_WRITE_SUPPORTED
  175911. void PNGAPI
  175912. png_write_info_before_PLTE(png_structp png_ptr, png_infop info_ptr)
  175913. {
  175914. png_debug(1, "in png_write_info_before_PLTE\n");
  175915. if (png_ptr == NULL || info_ptr == NULL)
  175916. return;
  175917. if (!(png_ptr->mode & PNG_WROTE_INFO_BEFORE_PLTE))
  175918. {
  175919. png_write_sig(png_ptr); /* write PNG signature */
  175920. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  175921. if((png_ptr->mode&PNG_HAVE_PNG_SIGNATURE)&&(png_ptr->mng_features_permitted))
  175922. {
  175923. png_warning(png_ptr,"MNG features are not allowed in a PNG datastream");
  175924. png_ptr->mng_features_permitted=0;
  175925. }
  175926. #endif
  175927. png_write_IHDR(png_ptr, info_ptr->width, info_ptr->height,
  175928. info_ptr->bit_depth, info_ptr->color_type, info_ptr->compression_type,
  175929. info_ptr->filter_type,
  175930. #if defined(PNG_WRITE_INTERLACING_SUPPORTED)
  175931. info_ptr->interlace_type);
  175932. #else
  175933. 0);
  175934. #endif
  175935. #if defined(PNG_WRITE_gAMA_SUPPORTED)
  175936. if (info_ptr->valid & PNG_INFO_gAMA)
  175937. {
  175938. # ifdef PNG_FLOATING_POINT_SUPPORTED
  175939. png_write_gAMA(png_ptr, info_ptr->gamma);
  175940. #else
  175941. #ifdef PNG_FIXED_POINT_SUPPORTED
  175942. png_write_gAMA_fixed(png_ptr, info_ptr->int_gamma);
  175943. # endif
  175944. #endif
  175945. }
  175946. #endif
  175947. #if defined(PNG_WRITE_sRGB_SUPPORTED)
  175948. if (info_ptr->valid & PNG_INFO_sRGB)
  175949. png_write_sRGB(png_ptr, (int)info_ptr->srgb_intent);
  175950. #endif
  175951. #if defined(PNG_WRITE_iCCP_SUPPORTED)
  175952. if (info_ptr->valid & PNG_INFO_iCCP)
  175953. png_write_iCCP(png_ptr, info_ptr->iccp_name, PNG_COMPRESSION_TYPE_BASE,
  175954. info_ptr->iccp_profile, (int)info_ptr->iccp_proflen);
  175955. #endif
  175956. #if defined(PNG_WRITE_sBIT_SUPPORTED)
  175957. if (info_ptr->valid & PNG_INFO_sBIT)
  175958. png_write_sBIT(png_ptr, &(info_ptr->sig_bit), info_ptr->color_type);
  175959. #endif
  175960. #if defined(PNG_WRITE_cHRM_SUPPORTED)
  175961. if (info_ptr->valid & PNG_INFO_cHRM)
  175962. {
  175963. #ifdef PNG_FLOATING_POINT_SUPPORTED
  175964. png_write_cHRM(png_ptr,
  175965. info_ptr->x_white, info_ptr->y_white,
  175966. info_ptr->x_red, info_ptr->y_red,
  175967. info_ptr->x_green, info_ptr->y_green,
  175968. info_ptr->x_blue, info_ptr->y_blue);
  175969. #else
  175970. # ifdef PNG_FIXED_POINT_SUPPORTED
  175971. png_write_cHRM_fixed(png_ptr,
  175972. info_ptr->int_x_white, info_ptr->int_y_white,
  175973. info_ptr->int_x_red, info_ptr->int_y_red,
  175974. info_ptr->int_x_green, info_ptr->int_y_green,
  175975. info_ptr->int_x_blue, info_ptr->int_y_blue);
  175976. # endif
  175977. #endif
  175978. }
  175979. #endif
  175980. #if defined(PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED)
  175981. if (info_ptr->unknown_chunks_num)
  175982. {
  175983. png_unknown_chunk *up;
  175984. png_debug(5, "writing extra chunks\n");
  175985. for (up = info_ptr->unknown_chunks;
  175986. up < info_ptr->unknown_chunks + info_ptr->unknown_chunks_num;
  175987. up++)
  175988. {
  175989. int keep=png_handle_as_unknown(png_ptr, up->name);
  175990. if (keep != PNG_HANDLE_CHUNK_NEVER &&
  175991. up->location && !(up->location & PNG_HAVE_PLTE) &&
  175992. !(up->location & PNG_HAVE_IDAT) &&
  175993. ((up->name[3] & 0x20) || keep == PNG_HANDLE_CHUNK_ALWAYS ||
  175994. (png_ptr->flags & PNG_FLAG_KEEP_UNSAFE_CHUNKS)))
  175995. {
  175996. png_write_chunk(png_ptr, up->name, up->data, up->size);
  175997. }
  175998. }
  175999. }
  176000. #endif
  176001. png_ptr->mode |= PNG_WROTE_INFO_BEFORE_PLTE;
  176002. }
  176003. }
  176004. void PNGAPI
  176005. png_write_info(png_structp png_ptr, png_infop info_ptr)
  176006. {
  176007. #if defined(PNG_WRITE_TEXT_SUPPORTED) || defined(PNG_WRITE_sPLT_SUPPORTED)
  176008. int i;
  176009. #endif
  176010. png_debug(1, "in png_write_info\n");
  176011. if (png_ptr == NULL || info_ptr == NULL)
  176012. return;
  176013. png_write_info_before_PLTE(png_ptr, info_ptr);
  176014. if (info_ptr->valid & PNG_INFO_PLTE)
  176015. png_write_PLTE(png_ptr, info_ptr->palette,
  176016. (png_uint_32)info_ptr->num_palette);
  176017. else if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  176018. png_error(png_ptr, "Valid palette required for paletted images");
  176019. #if defined(PNG_WRITE_tRNS_SUPPORTED)
  176020. if (info_ptr->valid & PNG_INFO_tRNS)
  176021. {
  176022. #if defined(PNG_WRITE_INVERT_ALPHA_SUPPORTED)
  176023. if ((png_ptr->transformations & PNG_INVERT_ALPHA) &&
  176024. info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  176025. {
  176026. int j;
  176027. for (j=0; j<(int)info_ptr->num_trans; j++)
  176028. info_ptr->trans[j] = (png_byte)(255 - info_ptr->trans[j]);
  176029. }
  176030. #endif
  176031. png_write_tRNS(png_ptr, info_ptr->trans, &(info_ptr->trans_values),
  176032. info_ptr->num_trans, info_ptr->color_type);
  176033. }
  176034. #endif
  176035. #if defined(PNG_WRITE_bKGD_SUPPORTED)
  176036. if (info_ptr->valid & PNG_INFO_bKGD)
  176037. png_write_bKGD(png_ptr, &(info_ptr->background), info_ptr->color_type);
  176038. #endif
  176039. #if defined(PNG_WRITE_hIST_SUPPORTED)
  176040. if (info_ptr->valid & PNG_INFO_hIST)
  176041. png_write_hIST(png_ptr, info_ptr->hist, info_ptr->num_palette);
  176042. #endif
  176043. #if defined(PNG_WRITE_oFFs_SUPPORTED)
  176044. if (info_ptr->valid & PNG_INFO_oFFs)
  176045. png_write_oFFs(png_ptr, info_ptr->x_offset, info_ptr->y_offset,
  176046. info_ptr->offset_unit_type);
  176047. #endif
  176048. #if defined(PNG_WRITE_pCAL_SUPPORTED)
  176049. if (info_ptr->valid & PNG_INFO_pCAL)
  176050. png_write_pCAL(png_ptr, info_ptr->pcal_purpose, info_ptr->pcal_X0,
  176051. info_ptr->pcal_X1, info_ptr->pcal_type, info_ptr->pcal_nparams,
  176052. info_ptr->pcal_units, info_ptr->pcal_params);
  176053. #endif
  176054. #if defined(PNG_WRITE_sCAL_SUPPORTED)
  176055. if (info_ptr->valid & PNG_INFO_sCAL)
  176056. #if defined(PNG_FLOATING_POINT_SUPPORTED) && !defined(PNG_NO_STDIO)
  176057. png_write_sCAL(png_ptr, (int)info_ptr->scal_unit,
  176058. info_ptr->scal_pixel_width, info_ptr->scal_pixel_height);
  176059. #else
  176060. #ifdef PNG_FIXED_POINT_SUPPORTED
  176061. png_write_sCAL_s(png_ptr, (int)info_ptr->scal_unit,
  176062. info_ptr->scal_s_width, info_ptr->scal_s_height);
  176063. #else
  176064. png_warning(png_ptr,
  176065. "png_write_sCAL not supported; sCAL chunk not written.");
  176066. #endif
  176067. #endif
  176068. #endif
  176069. #if defined(PNG_WRITE_pHYs_SUPPORTED)
  176070. if (info_ptr->valid & PNG_INFO_pHYs)
  176071. png_write_pHYs(png_ptr, info_ptr->x_pixels_per_unit,
  176072. info_ptr->y_pixels_per_unit, info_ptr->phys_unit_type);
  176073. #endif
  176074. #if defined(PNG_WRITE_tIME_SUPPORTED)
  176075. if (info_ptr->valid & PNG_INFO_tIME)
  176076. {
  176077. png_write_tIME(png_ptr, &(info_ptr->mod_time));
  176078. png_ptr->mode |= PNG_WROTE_tIME;
  176079. }
  176080. #endif
  176081. #if defined(PNG_WRITE_sPLT_SUPPORTED)
  176082. if (info_ptr->valid & PNG_INFO_sPLT)
  176083. for (i = 0; i < (int)info_ptr->splt_palettes_num; i++)
  176084. png_write_sPLT(png_ptr, info_ptr->splt_palettes + i);
  176085. #endif
  176086. #if defined(PNG_WRITE_TEXT_SUPPORTED)
  176087. for (i = 0; i < info_ptr->num_text; i++)
  176088. {
  176089. png_debug2(2, "Writing header text chunk %d, type %d\n", i,
  176090. info_ptr->text[i].compression);
  176091. if (info_ptr->text[i].compression > 0)
  176092. {
  176093. #if defined(PNG_WRITE_iTXt_SUPPORTED)
  176094. png_write_iTXt(png_ptr,
  176095. info_ptr->text[i].compression,
  176096. info_ptr->text[i].key,
  176097. info_ptr->text[i].lang,
  176098. info_ptr->text[i].lang_key,
  176099. info_ptr->text[i].text);
  176100. #else
  176101. png_warning(png_ptr, "Unable to write international text");
  176102. #endif
  176103. info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_NONE_WR;
  176104. }
  176105. else if (info_ptr->text[i].compression == PNG_TEXT_COMPRESSION_zTXt)
  176106. {
  176107. #if defined(PNG_WRITE_zTXt_SUPPORTED)
  176108. png_write_zTXt(png_ptr, info_ptr->text[i].key,
  176109. info_ptr->text[i].text, 0,
  176110. info_ptr->text[i].compression);
  176111. #else
  176112. png_warning(png_ptr, "Unable to write compressed text");
  176113. #endif
  176114. info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_zTXt_WR;
  176115. }
  176116. else if (info_ptr->text[i].compression == PNG_TEXT_COMPRESSION_NONE)
  176117. {
  176118. #if defined(PNG_WRITE_tEXt_SUPPORTED)
  176119. png_write_tEXt(png_ptr, info_ptr->text[i].key,
  176120. info_ptr->text[i].text,
  176121. 0);
  176122. #else
  176123. png_warning(png_ptr, "Unable to write uncompressed text");
  176124. #endif
  176125. info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_NONE_WR;
  176126. }
  176127. }
  176128. #endif
  176129. #if defined(PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED)
  176130. if (info_ptr->unknown_chunks_num)
  176131. {
  176132. png_unknown_chunk *up;
  176133. png_debug(5, "writing extra chunks\n");
  176134. for (up = info_ptr->unknown_chunks;
  176135. up < info_ptr->unknown_chunks + info_ptr->unknown_chunks_num;
  176136. up++)
  176137. {
  176138. int keep=png_handle_as_unknown(png_ptr, up->name);
  176139. if (keep != PNG_HANDLE_CHUNK_NEVER &&
  176140. up->location && (up->location & PNG_HAVE_PLTE) &&
  176141. !(up->location & PNG_HAVE_IDAT) &&
  176142. ((up->name[3] & 0x20) || keep == PNG_HANDLE_CHUNK_ALWAYS ||
  176143. (png_ptr->flags & PNG_FLAG_KEEP_UNSAFE_CHUNKS)))
  176144. {
  176145. png_write_chunk(png_ptr, up->name, up->data, up->size);
  176146. }
  176147. }
  176148. }
  176149. #endif
  176150. }
  176151. void PNGAPI
  176152. png_write_end(png_structp png_ptr, png_infop info_ptr)
  176153. {
  176154. png_debug(1, "in png_write_end\n");
  176155. if (png_ptr == NULL)
  176156. return;
  176157. if (!(png_ptr->mode & PNG_HAVE_IDAT))
  176158. png_error(png_ptr, "No IDATs written into file");
  176159. if (info_ptr != NULL)
  176160. {
  176161. #if defined(PNG_WRITE_TEXT_SUPPORTED)
  176162. int i; /* local index variable */
  176163. #endif
  176164. #if defined(PNG_WRITE_tIME_SUPPORTED)
  176165. if ((info_ptr->valid & PNG_INFO_tIME) &&
  176166. !(png_ptr->mode & PNG_WROTE_tIME))
  176167. png_write_tIME(png_ptr, &(info_ptr->mod_time));
  176168. #endif
  176169. #if defined(PNG_WRITE_TEXT_SUPPORTED)
  176170. for (i = 0; i < info_ptr->num_text; i++)
  176171. {
  176172. png_debug2(2, "Writing trailer text chunk %d, type %d\n", i,
  176173. info_ptr->text[i].compression);
  176174. if (info_ptr->text[i].compression > 0)
  176175. {
  176176. #if defined(PNG_WRITE_iTXt_SUPPORTED)
  176177. png_write_iTXt(png_ptr,
  176178. info_ptr->text[i].compression,
  176179. info_ptr->text[i].key,
  176180. info_ptr->text[i].lang,
  176181. info_ptr->text[i].lang_key,
  176182. info_ptr->text[i].text);
  176183. #else
  176184. png_warning(png_ptr, "Unable to write international text");
  176185. #endif
  176186. info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_NONE_WR;
  176187. }
  176188. else if (info_ptr->text[i].compression >= PNG_TEXT_COMPRESSION_zTXt)
  176189. {
  176190. #if defined(PNG_WRITE_zTXt_SUPPORTED)
  176191. png_write_zTXt(png_ptr, info_ptr->text[i].key,
  176192. info_ptr->text[i].text, 0,
  176193. info_ptr->text[i].compression);
  176194. #else
  176195. png_warning(png_ptr, "Unable to write compressed text");
  176196. #endif
  176197. info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_zTXt_WR;
  176198. }
  176199. else if (info_ptr->text[i].compression == PNG_TEXT_COMPRESSION_NONE)
  176200. {
  176201. #if defined(PNG_WRITE_tEXt_SUPPORTED)
  176202. png_write_tEXt(png_ptr, info_ptr->text[i].key,
  176203. info_ptr->text[i].text, 0);
  176204. #else
  176205. png_warning(png_ptr, "Unable to write uncompressed text");
  176206. #endif
  176207. info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_NONE_WR;
  176208. }
  176209. }
  176210. #endif
  176211. #if defined(PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED)
  176212. if (info_ptr->unknown_chunks_num)
  176213. {
  176214. png_unknown_chunk *up;
  176215. png_debug(5, "writing extra chunks\n");
  176216. for (up = info_ptr->unknown_chunks;
  176217. up < info_ptr->unknown_chunks + info_ptr->unknown_chunks_num;
  176218. up++)
  176219. {
  176220. int keep=png_handle_as_unknown(png_ptr, up->name);
  176221. if (keep != PNG_HANDLE_CHUNK_NEVER &&
  176222. up->location && (up->location & PNG_AFTER_IDAT) &&
  176223. ((up->name[3] & 0x20) || keep == PNG_HANDLE_CHUNK_ALWAYS ||
  176224. (png_ptr->flags & PNG_FLAG_KEEP_UNSAFE_CHUNKS)))
  176225. {
  176226. png_write_chunk(png_ptr, up->name, up->data, up->size);
  176227. }
  176228. }
  176229. }
  176230. #endif
  176231. }
  176232. png_ptr->mode |= PNG_AFTER_IDAT;
  176233. png_write_IEND(png_ptr);
  176234. }
  176235. #if defined(PNG_WRITE_tIME_SUPPORTED)
  176236. #if !defined(_WIN32_WCE)
  176237. void PNGAPI
  176238. png_convert_from_struct_tm(png_timep ptime, struct tm FAR * ttime)
  176239. {
  176240. png_debug(1, "in png_convert_from_struct_tm\n");
  176241. ptime->year = (png_uint_16)(1900 + ttime->tm_year);
  176242. ptime->month = (png_byte)(ttime->tm_mon + 1);
  176243. ptime->day = (png_byte)ttime->tm_mday;
  176244. ptime->hour = (png_byte)ttime->tm_hour;
  176245. ptime->minute = (png_byte)ttime->tm_min;
  176246. ptime->second = (png_byte)ttime->tm_sec;
  176247. }
  176248. void PNGAPI
  176249. png_convert_from_time_t(png_timep ptime, time_t ttime)
  176250. {
  176251. struct tm *tbuf;
  176252. png_debug(1, "in png_convert_from_time_t\n");
  176253. tbuf = gmtime(&ttime);
  176254. png_convert_from_struct_tm(ptime, tbuf);
  176255. }
  176256. #endif
  176257. #endif
  176258. png_structp PNGAPI
  176259. png_create_write_struct(png_const_charp user_png_ver, png_voidp error_ptr,
  176260. png_error_ptr error_fn, png_error_ptr warn_fn)
  176261. {
  176262. #ifdef PNG_USER_MEM_SUPPORTED
  176263. return (png_create_write_struct_2(user_png_ver, error_ptr, error_fn,
  176264. warn_fn, png_voidp_NULL, png_malloc_ptr_NULL, png_free_ptr_NULL));
  176265. }
  176266. png_structp PNGAPI
  176267. png_create_write_struct_2(png_const_charp user_png_ver, png_voidp error_ptr,
  176268. png_error_ptr error_fn, png_error_ptr warn_fn, png_voidp mem_ptr,
  176269. png_malloc_ptr malloc_fn, png_free_ptr free_fn)
  176270. {
  176271. #endif /* PNG_USER_MEM_SUPPORTED */
  176272. png_structp png_ptr;
  176273. #ifdef PNG_SETJMP_SUPPORTED
  176274. #ifdef USE_FAR_KEYWORD
  176275. jmp_buf jmpbuf;
  176276. #endif
  176277. #endif
  176278. int i;
  176279. png_debug(1, "in png_create_write_struct\n");
  176280. #ifdef PNG_USER_MEM_SUPPORTED
  176281. png_ptr = (png_structp)png_create_struct_2(PNG_STRUCT_PNG,
  176282. (png_malloc_ptr)malloc_fn, (png_voidp)mem_ptr);
  176283. #else
  176284. png_ptr = (png_structp)png_create_struct(PNG_STRUCT_PNG);
  176285. #endif /* PNG_USER_MEM_SUPPORTED */
  176286. if (png_ptr == NULL)
  176287. return (NULL);
  176288. #ifdef PNG_SET_USER_LIMITS_SUPPORTED
  176289. png_ptr->user_width_max=PNG_USER_WIDTH_MAX;
  176290. png_ptr->user_height_max=PNG_USER_HEIGHT_MAX;
  176291. #endif
  176292. #ifdef PNG_SETJMP_SUPPORTED
  176293. #ifdef USE_FAR_KEYWORD
  176294. if (setjmp(jmpbuf))
  176295. #else
  176296. if (setjmp(png_ptr->jmpbuf))
  176297. #endif
  176298. {
  176299. png_free(png_ptr, png_ptr->zbuf);
  176300. png_ptr->zbuf=NULL;
  176301. png_destroy_struct(png_ptr);
  176302. return (NULL);
  176303. }
  176304. #ifdef USE_FAR_KEYWORD
  176305. png_memcpy(png_ptr->jmpbuf,jmpbuf,png_sizeof(jmp_buf));
  176306. #endif
  176307. #endif
  176308. #ifdef PNG_USER_MEM_SUPPORTED
  176309. png_set_mem_fn(png_ptr, mem_ptr, malloc_fn, free_fn);
  176310. #endif /* PNG_USER_MEM_SUPPORTED */
  176311. png_set_error_fn(png_ptr, error_ptr, error_fn, warn_fn);
  176312. i=0;
  176313. do
  176314. {
  176315. if(user_png_ver[i] != png_libpng_ver[i])
  176316. png_ptr->flags |= PNG_FLAG_LIBRARY_MISMATCH;
  176317. } while (png_libpng_ver[i++]);
  176318. if (png_ptr->flags & PNG_FLAG_LIBRARY_MISMATCH)
  176319. {
  176320. if (user_png_ver == NULL || user_png_ver[0] != png_libpng_ver[0] ||
  176321. (user_png_ver[0] == '1' && user_png_ver[2] != png_libpng_ver[2]) ||
  176322. (user_png_ver[0] == '0' && user_png_ver[2] < '9'))
  176323. {
  176324. #if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE)
  176325. char msg[80];
  176326. if (user_png_ver)
  176327. {
  176328. png_snprintf(msg, 80,
  176329. "Application was compiled with png.h from libpng-%.20s",
  176330. user_png_ver);
  176331. png_warning(png_ptr, msg);
  176332. }
  176333. png_snprintf(msg, 80,
  176334. "Application is running with png.c from libpng-%.20s",
  176335. png_libpng_ver);
  176336. png_warning(png_ptr, msg);
  176337. #endif
  176338. #ifdef PNG_ERROR_NUMBERS_SUPPORTED
  176339. png_ptr->flags=0;
  176340. #endif
  176341. png_error(png_ptr,
  176342. "Incompatible libpng version in application and library");
  176343. }
  176344. }
  176345. png_ptr->zbuf_size = PNG_ZBUF_SIZE;
  176346. png_ptr->zbuf = (png_bytep)png_malloc(png_ptr,
  176347. (png_uint_32)png_ptr->zbuf_size);
  176348. png_set_write_fn(png_ptr, png_voidp_NULL, png_rw_ptr_NULL,
  176349. png_flush_ptr_NULL);
  176350. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  176351. png_set_filter_heuristics(png_ptr, PNG_FILTER_HEURISTIC_DEFAULT,
  176352. 1, png_doublep_NULL, png_doublep_NULL);
  176353. #endif
  176354. #ifdef PNG_SETJMP_SUPPORTED
  176355. #ifdef USE_FAR_KEYWORD
  176356. if (setjmp(jmpbuf))
  176357. PNG_ABORT();
  176358. png_memcpy(png_ptr->jmpbuf,jmpbuf,png_sizeof(jmp_buf));
  176359. #else
  176360. if (setjmp(png_ptr->jmpbuf))
  176361. PNG_ABORT();
  176362. #endif
  176363. #endif
  176364. return (png_ptr);
  176365. }
  176366. #if defined(PNG_1_0_X) || defined(PNG_1_2_X)
  176367. #undef png_write_init
  176368. void PNGAPI
  176369. png_write_init(png_structp png_ptr)
  176370. {
  176371. png_write_init_2(png_ptr, "1.0.6 or earlier", 0, 0);
  176372. }
  176373. void PNGAPI
  176374. png_write_init_2(png_structp png_ptr, png_const_charp user_png_ver,
  176375. png_size_t png_struct_size, png_size_t png_info_size)
  176376. {
  176377. if(png_ptr == NULL) return;
  176378. #if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE)
  176379. if(png_sizeof(png_struct) > png_struct_size ||
  176380. png_sizeof(png_info) > png_info_size)
  176381. {
  176382. char msg[80];
  176383. png_ptr->warning_fn=NULL;
  176384. if (user_png_ver)
  176385. {
  176386. png_snprintf(msg, 80,
  176387. "Application was compiled with png.h from libpng-%.20s",
  176388. user_png_ver);
  176389. png_warning(png_ptr, msg);
  176390. }
  176391. png_snprintf(msg, 80,
  176392. "Application is running with png.c from libpng-%.20s",
  176393. png_libpng_ver);
  176394. png_warning(png_ptr, msg);
  176395. }
  176396. #endif
  176397. if(png_sizeof(png_struct) > png_struct_size)
  176398. {
  176399. png_ptr->error_fn=NULL;
  176400. #ifdef PNG_ERROR_NUMBERS_SUPPORTED
  176401. png_ptr->flags=0;
  176402. #endif
  176403. png_error(png_ptr,
  176404. "The png struct allocated by the application for writing is too small.");
  176405. }
  176406. if(png_sizeof(png_info) > png_info_size)
  176407. {
  176408. png_ptr->error_fn=NULL;
  176409. #ifdef PNG_ERROR_NUMBERS_SUPPORTED
  176410. png_ptr->flags=0;
  176411. #endif
  176412. png_error(png_ptr,
  176413. "The info struct allocated by the application for writing is too small.");
  176414. }
  176415. png_write_init_3(&png_ptr, user_png_ver, png_struct_size);
  176416. }
  176417. #endif /* PNG_1_0_X || PNG_1_2_X */
  176418. void PNGAPI
  176419. png_write_init_3(png_structpp ptr_ptr, png_const_charp user_png_ver,
  176420. png_size_t png_struct_size)
  176421. {
  176422. png_structp png_ptr=*ptr_ptr;
  176423. #ifdef PNG_SETJMP_SUPPORTED
  176424. jmp_buf tmp_jmp; /* to save current jump buffer */
  176425. #endif
  176426. int i = 0;
  176427. if (png_ptr == NULL)
  176428. return;
  176429. do
  176430. {
  176431. if (user_png_ver[i] != png_libpng_ver[i])
  176432. {
  176433. #ifdef PNG_LEGACY_SUPPORTED
  176434. png_ptr->flags |= PNG_FLAG_LIBRARY_MISMATCH;
  176435. #else
  176436. png_ptr->warning_fn=NULL;
  176437. png_warning(png_ptr,
  176438. "Application uses deprecated png_write_init() and should be recompiled.");
  176439. break;
  176440. #endif
  176441. }
  176442. } while (png_libpng_ver[i++]);
  176443. png_debug(1, "in png_write_init_3\n");
  176444. #ifdef PNG_SETJMP_SUPPORTED
  176445. png_memcpy(tmp_jmp, png_ptr->jmpbuf, png_sizeof (jmp_buf));
  176446. #endif
  176447. if (png_sizeof(png_struct) > png_struct_size)
  176448. {
  176449. png_destroy_struct(png_ptr);
  176450. png_ptr = (png_structp)png_create_struct(PNG_STRUCT_PNG);
  176451. *ptr_ptr = png_ptr;
  176452. }
  176453. png_memset(png_ptr, 0, png_sizeof (png_struct));
  176454. #ifdef PNG_SET_USER_LIMITS_SUPPORTED
  176455. png_ptr->user_width_max=PNG_USER_WIDTH_MAX;
  176456. png_ptr->user_height_max=PNG_USER_HEIGHT_MAX;
  176457. #endif
  176458. #ifdef PNG_SETJMP_SUPPORTED
  176459. png_memcpy(png_ptr->jmpbuf, tmp_jmp, png_sizeof (jmp_buf));
  176460. #endif
  176461. png_set_write_fn(png_ptr, png_voidp_NULL, png_rw_ptr_NULL,
  176462. png_flush_ptr_NULL);
  176463. png_ptr->zbuf_size = PNG_ZBUF_SIZE;
  176464. png_ptr->zbuf = (png_bytep)png_malloc(png_ptr,
  176465. (png_uint_32)png_ptr->zbuf_size);
  176466. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  176467. png_set_filter_heuristics(png_ptr, PNG_FILTER_HEURISTIC_DEFAULT,
  176468. 1, png_doublep_NULL, png_doublep_NULL);
  176469. #endif
  176470. }
  176471. void PNGAPI
  176472. png_write_rows(png_structp png_ptr, png_bytepp row,
  176473. png_uint_32 num_rows)
  176474. {
  176475. png_uint_32 i; /* row counter */
  176476. png_bytepp rp; /* row pointer */
  176477. png_debug(1, "in png_write_rows\n");
  176478. if (png_ptr == NULL)
  176479. return;
  176480. for (i = 0, rp = row; i < num_rows; i++, rp++)
  176481. {
  176482. png_write_row(png_ptr, *rp);
  176483. }
  176484. }
  176485. void PNGAPI
  176486. png_write_image(png_structp png_ptr, png_bytepp image)
  176487. {
  176488. png_uint_32 i; /* row index */
  176489. int pass, num_pass; /* pass variables */
  176490. png_bytepp rp; /* points to current row */
  176491. if (png_ptr == NULL)
  176492. return;
  176493. png_debug(1, "in png_write_image\n");
  176494. #if defined(PNG_WRITE_INTERLACING_SUPPORTED)
  176495. num_pass = png_set_interlace_handling(png_ptr);
  176496. #else
  176497. num_pass = 1;
  176498. #endif
  176499. for (pass = 0; pass < num_pass; pass++)
  176500. {
  176501. for (i = 0, rp = image; i < png_ptr->height; i++, rp++)
  176502. {
  176503. png_write_row(png_ptr, *rp);
  176504. }
  176505. }
  176506. }
  176507. void PNGAPI
  176508. png_write_row(png_structp png_ptr, png_bytep row)
  176509. {
  176510. if (png_ptr == NULL)
  176511. return;
  176512. png_debug2(1, "in png_write_row (row %ld, pass %d)\n",
  176513. png_ptr->row_number, png_ptr->pass);
  176514. if (png_ptr->row_number == 0 && png_ptr->pass == 0)
  176515. {
  176516. if (!(png_ptr->mode & PNG_WROTE_INFO_BEFORE_PLTE))
  176517. png_error(png_ptr,
  176518. "png_write_info was never called before png_write_row.");
  176519. #if !defined(PNG_WRITE_INVERT_SUPPORTED) && defined(PNG_READ_INVERT_SUPPORTED)
  176520. if (png_ptr->transformations & PNG_INVERT_MONO)
  176521. png_warning(png_ptr, "PNG_WRITE_INVERT_SUPPORTED is not defined.");
  176522. #endif
  176523. #if !defined(PNG_WRITE_FILLER_SUPPORTED) && defined(PNG_READ_FILLER_SUPPORTED)
  176524. if (png_ptr->transformations & PNG_FILLER)
  176525. png_warning(png_ptr, "PNG_WRITE_FILLER_SUPPORTED is not defined.");
  176526. #endif
  176527. #if !defined(PNG_WRITE_PACKSWAP_SUPPORTED) && defined(PNG_READ_PACKSWAP_SUPPORTED)
  176528. if (png_ptr->transformations & PNG_PACKSWAP)
  176529. png_warning(png_ptr, "PNG_WRITE_PACKSWAP_SUPPORTED is not defined.");
  176530. #endif
  176531. #if !defined(PNG_WRITE_PACK_SUPPORTED) && defined(PNG_READ_PACK_SUPPORTED)
  176532. if (png_ptr->transformations & PNG_PACK)
  176533. png_warning(png_ptr, "PNG_WRITE_PACK_SUPPORTED is not defined.");
  176534. #endif
  176535. #if !defined(PNG_WRITE_SHIFT_SUPPORTED) && defined(PNG_READ_SHIFT_SUPPORTED)
  176536. if (png_ptr->transformations & PNG_SHIFT)
  176537. png_warning(png_ptr, "PNG_WRITE_SHIFT_SUPPORTED is not defined.");
  176538. #endif
  176539. #if !defined(PNG_WRITE_BGR_SUPPORTED) && defined(PNG_READ_BGR_SUPPORTED)
  176540. if (png_ptr->transformations & PNG_BGR)
  176541. png_warning(png_ptr, "PNG_WRITE_BGR_SUPPORTED is not defined.");
  176542. #endif
  176543. #if !defined(PNG_WRITE_SWAP_SUPPORTED) && defined(PNG_READ_SWAP_SUPPORTED)
  176544. if (png_ptr->transformations & PNG_SWAP_BYTES)
  176545. png_warning(png_ptr, "PNG_WRITE_SWAP_SUPPORTED is not defined.");
  176546. #endif
  176547. png_write_start_row(png_ptr);
  176548. }
  176549. #if defined(PNG_WRITE_INTERLACING_SUPPORTED)
  176550. if (png_ptr->interlaced && (png_ptr->transformations & PNG_INTERLACE))
  176551. {
  176552. switch (png_ptr->pass)
  176553. {
  176554. case 0:
  176555. if (png_ptr->row_number & 0x07)
  176556. {
  176557. png_write_finish_row(png_ptr);
  176558. return;
  176559. }
  176560. break;
  176561. case 1:
  176562. if ((png_ptr->row_number & 0x07) || png_ptr->width < 5)
  176563. {
  176564. png_write_finish_row(png_ptr);
  176565. return;
  176566. }
  176567. break;
  176568. case 2:
  176569. if ((png_ptr->row_number & 0x07) != 4)
  176570. {
  176571. png_write_finish_row(png_ptr);
  176572. return;
  176573. }
  176574. break;
  176575. case 3:
  176576. if ((png_ptr->row_number & 0x03) || png_ptr->width < 3)
  176577. {
  176578. png_write_finish_row(png_ptr);
  176579. return;
  176580. }
  176581. break;
  176582. case 4:
  176583. if ((png_ptr->row_number & 0x03) != 2)
  176584. {
  176585. png_write_finish_row(png_ptr);
  176586. return;
  176587. }
  176588. break;
  176589. case 5:
  176590. if ((png_ptr->row_number & 0x01) || png_ptr->width < 2)
  176591. {
  176592. png_write_finish_row(png_ptr);
  176593. return;
  176594. }
  176595. break;
  176596. case 6:
  176597. if (!(png_ptr->row_number & 0x01))
  176598. {
  176599. png_write_finish_row(png_ptr);
  176600. return;
  176601. }
  176602. break;
  176603. }
  176604. }
  176605. #endif
  176606. png_ptr->row_info.color_type = png_ptr->color_type;
  176607. png_ptr->row_info.width = png_ptr->usr_width;
  176608. png_ptr->row_info.channels = png_ptr->usr_channels;
  176609. png_ptr->row_info.bit_depth = png_ptr->usr_bit_depth;
  176610. png_ptr->row_info.pixel_depth = (png_byte)(png_ptr->row_info.bit_depth *
  176611. png_ptr->row_info.channels);
  176612. png_ptr->row_info.rowbytes = PNG_ROWBYTES(png_ptr->row_info.pixel_depth,
  176613. png_ptr->row_info.width);
  176614. png_debug1(3, "row_info->color_type = %d\n", png_ptr->row_info.color_type);
  176615. png_debug1(3, "row_info->width = %lu\n", png_ptr->row_info.width);
  176616. png_debug1(3, "row_info->channels = %d\n", png_ptr->row_info.channels);
  176617. png_debug1(3, "row_info->bit_depth = %d\n", png_ptr->row_info.bit_depth);
  176618. png_debug1(3, "row_info->pixel_depth = %d\n", png_ptr->row_info.pixel_depth);
  176619. png_debug1(3, "row_info->rowbytes = %lu\n", png_ptr->row_info.rowbytes);
  176620. png_memcpy_check(png_ptr, png_ptr->row_buf + 1, row,
  176621. png_ptr->row_info.rowbytes);
  176622. #if defined(PNG_WRITE_INTERLACING_SUPPORTED)
  176623. if (png_ptr->interlaced && png_ptr->pass < 6 &&
  176624. (png_ptr->transformations & PNG_INTERLACE))
  176625. {
  176626. png_do_write_interlace(&(png_ptr->row_info),
  176627. png_ptr->row_buf + 1, png_ptr->pass);
  176628. if (!(png_ptr->row_info.width))
  176629. {
  176630. png_write_finish_row(png_ptr);
  176631. return;
  176632. }
  176633. }
  176634. #endif
  176635. if (png_ptr->transformations)
  176636. png_do_write_transformations(png_ptr);
  176637. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  176638. if((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) &&
  176639. (png_ptr->filter_type == PNG_INTRAPIXEL_DIFFERENCING))
  176640. {
  176641. png_do_write_intrapixel(&(png_ptr->row_info), png_ptr->row_buf + 1);
  176642. }
  176643. #endif
  176644. png_write_find_filter(png_ptr, &(png_ptr->row_info));
  176645. if (png_ptr->write_row_fn != NULL)
  176646. (*(png_ptr->write_row_fn))(png_ptr, png_ptr->row_number, png_ptr->pass);
  176647. }
  176648. #if defined(PNG_WRITE_FLUSH_SUPPORTED)
  176649. void PNGAPI
  176650. png_set_flush(png_structp png_ptr, int nrows)
  176651. {
  176652. png_debug(1, "in png_set_flush\n");
  176653. if (png_ptr == NULL)
  176654. return;
  176655. png_ptr->flush_dist = (nrows < 0 ? 0 : nrows);
  176656. }
  176657. void PNGAPI
  176658. png_write_flush(png_structp png_ptr)
  176659. {
  176660. int wrote_IDAT;
  176661. png_debug(1, "in png_write_flush\n");
  176662. if (png_ptr == NULL)
  176663. return;
  176664. if (png_ptr->row_number >= png_ptr->num_rows)
  176665. return;
  176666. do
  176667. {
  176668. int ret;
  176669. ret = deflate(&png_ptr->zstream, Z_SYNC_FLUSH);
  176670. wrote_IDAT = 0;
  176671. if (ret != Z_OK)
  176672. {
  176673. if (png_ptr->zstream.msg != NULL)
  176674. png_error(png_ptr, png_ptr->zstream.msg);
  176675. else
  176676. png_error(png_ptr, "zlib error");
  176677. }
  176678. if (!(png_ptr->zstream.avail_out))
  176679. {
  176680. png_write_IDAT(png_ptr, png_ptr->zbuf,
  176681. png_ptr->zbuf_size);
  176682. png_ptr->zstream.next_out = png_ptr->zbuf;
  176683. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  176684. wrote_IDAT = 1;
  176685. }
  176686. } while(wrote_IDAT == 1);
  176687. if (png_ptr->zbuf_size != png_ptr->zstream.avail_out)
  176688. {
  176689. png_write_IDAT(png_ptr, png_ptr->zbuf,
  176690. png_ptr->zbuf_size - png_ptr->zstream.avail_out);
  176691. png_ptr->zstream.next_out = png_ptr->zbuf;
  176692. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  176693. }
  176694. png_ptr->flush_rows = 0;
  176695. png_flush(png_ptr);
  176696. }
  176697. #endif /* PNG_WRITE_FLUSH_SUPPORTED */
  176698. void PNGAPI
  176699. png_destroy_write_struct(png_structpp png_ptr_ptr, png_infopp info_ptr_ptr)
  176700. {
  176701. png_structp png_ptr = NULL;
  176702. png_infop info_ptr = NULL;
  176703. #ifdef PNG_USER_MEM_SUPPORTED
  176704. png_free_ptr free_fn = NULL;
  176705. png_voidp mem_ptr = NULL;
  176706. #endif
  176707. png_debug(1, "in png_destroy_write_struct\n");
  176708. if (png_ptr_ptr != NULL)
  176709. {
  176710. png_ptr = *png_ptr_ptr;
  176711. #ifdef PNG_USER_MEM_SUPPORTED
  176712. free_fn = png_ptr->free_fn;
  176713. mem_ptr = png_ptr->mem_ptr;
  176714. #endif
  176715. }
  176716. if (info_ptr_ptr != NULL)
  176717. info_ptr = *info_ptr_ptr;
  176718. if (info_ptr != NULL)
  176719. {
  176720. png_free_data(png_ptr, info_ptr, PNG_FREE_ALL, -1);
  176721. #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
  176722. if (png_ptr->num_chunk_list)
  176723. {
  176724. png_free(png_ptr, png_ptr->chunk_list);
  176725. png_ptr->chunk_list=NULL;
  176726. png_ptr->num_chunk_list=0;
  176727. }
  176728. #endif
  176729. #ifdef PNG_USER_MEM_SUPPORTED
  176730. png_destroy_struct_2((png_voidp)info_ptr, (png_free_ptr)free_fn,
  176731. (png_voidp)mem_ptr);
  176732. #else
  176733. png_destroy_struct((png_voidp)info_ptr);
  176734. #endif
  176735. *info_ptr_ptr = NULL;
  176736. }
  176737. if (png_ptr != NULL)
  176738. {
  176739. png_write_destroy(png_ptr);
  176740. #ifdef PNG_USER_MEM_SUPPORTED
  176741. png_destroy_struct_2((png_voidp)png_ptr, (png_free_ptr)free_fn,
  176742. (png_voidp)mem_ptr);
  176743. #else
  176744. png_destroy_struct((png_voidp)png_ptr);
  176745. #endif
  176746. *png_ptr_ptr = NULL;
  176747. }
  176748. }
  176749. void /* PRIVATE */
  176750. png_write_destroy(png_structp png_ptr)
  176751. {
  176752. #ifdef PNG_SETJMP_SUPPORTED
  176753. jmp_buf tmp_jmp; /* save jump buffer */
  176754. #endif
  176755. png_error_ptr error_fn;
  176756. png_error_ptr warning_fn;
  176757. png_voidp error_ptr;
  176758. #ifdef PNG_USER_MEM_SUPPORTED
  176759. png_free_ptr free_fn;
  176760. #endif
  176761. png_debug(1, "in png_write_destroy\n");
  176762. deflateEnd(&png_ptr->zstream);
  176763. png_free(png_ptr, png_ptr->zbuf);
  176764. png_free(png_ptr, png_ptr->row_buf);
  176765. png_free(png_ptr, png_ptr->prev_row);
  176766. png_free(png_ptr, png_ptr->sub_row);
  176767. png_free(png_ptr, png_ptr->up_row);
  176768. png_free(png_ptr, png_ptr->avg_row);
  176769. png_free(png_ptr, png_ptr->paeth_row);
  176770. #if defined(PNG_TIME_RFC1123_SUPPORTED)
  176771. png_free(png_ptr, png_ptr->time_buffer);
  176772. #endif
  176773. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  176774. png_free(png_ptr, png_ptr->prev_filters);
  176775. png_free(png_ptr, png_ptr->filter_weights);
  176776. png_free(png_ptr, png_ptr->inv_filter_weights);
  176777. png_free(png_ptr, png_ptr->filter_costs);
  176778. png_free(png_ptr, png_ptr->inv_filter_costs);
  176779. #endif
  176780. #ifdef PNG_SETJMP_SUPPORTED
  176781. png_memcpy(tmp_jmp, png_ptr->jmpbuf, png_sizeof (jmp_buf));
  176782. #endif
  176783. error_fn = png_ptr->error_fn;
  176784. warning_fn = png_ptr->warning_fn;
  176785. error_ptr = png_ptr->error_ptr;
  176786. #ifdef PNG_USER_MEM_SUPPORTED
  176787. free_fn = png_ptr->free_fn;
  176788. #endif
  176789. png_memset(png_ptr, 0, png_sizeof (png_struct));
  176790. png_ptr->error_fn = error_fn;
  176791. png_ptr->warning_fn = warning_fn;
  176792. png_ptr->error_ptr = error_ptr;
  176793. #ifdef PNG_USER_MEM_SUPPORTED
  176794. png_ptr->free_fn = free_fn;
  176795. #endif
  176796. #ifdef PNG_SETJMP_SUPPORTED
  176797. png_memcpy(png_ptr->jmpbuf, tmp_jmp, png_sizeof (jmp_buf));
  176798. #endif
  176799. }
  176800. void PNGAPI
  176801. png_set_filter(png_structp png_ptr, int method, int filters)
  176802. {
  176803. png_debug(1, "in png_set_filter\n");
  176804. if (png_ptr == NULL)
  176805. return;
  176806. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  176807. if((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) &&
  176808. (method == PNG_INTRAPIXEL_DIFFERENCING))
  176809. method = PNG_FILTER_TYPE_BASE;
  176810. #endif
  176811. if (method == PNG_FILTER_TYPE_BASE)
  176812. {
  176813. switch (filters & (PNG_ALL_FILTERS | 0x07))
  176814. {
  176815. #ifndef PNG_NO_WRITE_FILTER
  176816. case 5:
  176817. case 6:
  176818. case 7: png_warning(png_ptr, "Unknown row filter for method 0");
  176819. #endif /* PNG_NO_WRITE_FILTER */
  176820. case PNG_FILTER_VALUE_NONE:
  176821. png_ptr->do_filter=PNG_FILTER_NONE; break;
  176822. #ifndef PNG_NO_WRITE_FILTER
  176823. case PNG_FILTER_VALUE_SUB:
  176824. png_ptr->do_filter=PNG_FILTER_SUB; break;
  176825. case PNG_FILTER_VALUE_UP:
  176826. png_ptr->do_filter=PNG_FILTER_UP; break;
  176827. case PNG_FILTER_VALUE_AVG:
  176828. png_ptr->do_filter=PNG_FILTER_AVG; break;
  176829. case PNG_FILTER_VALUE_PAETH:
  176830. png_ptr->do_filter=PNG_FILTER_PAETH; break;
  176831. default: png_ptr->do_filter = (png_byte)filters; break;
  176832. #else
  176833. default: png_warning(png_ptr, "Unknown row filter for method 0");
  176834. #endif /* PNG_NO_WRITE_FILTER */
  176835. }
  176836. if (png_ptr->row_buf != NULL)
  176837. {
  176838. #ifndef PNG_NO_WRITE_FILTER
  176839. if ((png_ptr->do_filter & PNG_FILTER_SUB) && png_ptr->sub_row == NULL)
  176840. {
  176841. png_ptr->sub_row = (png_bytep)png_malloc(png_ptr,
  176842. (png_ptr->rowbytes + 1));
  176843. png_ptr->sub_row[0] = PNG_FILTER_VALUE_SUB;
  176844. }
  176845. if ((png_ptr->do_filter & PNG_FILTER_UP) && png_ptr->up_row == NULL)
  176846. {
  176847. if (png_ptr->prev_row == NULL)
  176848. {
  176849. png_warning(png_ptr, "Can't add Up filter after starting");
  176850. png_ptr->do_filter &= ~PNG_FILTER_UP;
  176851. }
  176852. else
  176853. {
  176854. png_ptr->up_row = (png_bytep)png_malloc(png_ptr,
  176855. (png_ptr->rowbytes + 1));
  176856. png_ptr->up_row[0] = PNG_FILTER_VALUE_UP;
  176857. }
  176858. }
  176859. if ((png_ptr->do_filter & PNG_FILTER_AVG) && png_ptr->avg_row == NULL)
  176860. {
  176861. if (png_ptr->prev_row == NULL)
  176862. {
  176863. png_warning(png_ptr, "Can't add Average filter after starting");
  176864. png_ptr->do_filter &= ~PNG_FILTER_AVG;
  176865. }
  176866. else
  176867. {
  176868. png_ptr->avg_row = (png_bytep)png_malloc(png_ptr,
  176869. (png_ptr->rowbytes + 1));
  176870. png_ptr->avg_row[0] = PNG_FILTER_VALUE_AVG;
  176871. }
  176872. }
  176873. if ((png_ptr->do_filter & PNG_FILTER_PAETH) &&
  176874. png_ptr->paeth_row == NULL)
  176875. {
  176876. if (png_ptr->prev_row == NULL)
  176877. {
  176878. png_warning(png_ptr, "Can't add Paeth filter after starting");
  176879. png_ptr->do_filter &= (png_byte)(~PNG_FILTER_PAETH);
  176880. }
  176881. else
  176882. {
  176883. png_ptr->paeth_row = (png_bytep)png_malloc(png_ptr,
  176884. (png_ptr->rowbytes + 1));
  176885. png_ptr->paeth_row[0] = PNG_FILTER_VALUE_PAETH;
  176886. }
  176887. }
  176888. if (png_ptr->do_filter == PNG_NO_FILTERS)
  176889. #endif /* PNG_NO_WRITE_FILTER */
  176890. png_ptr->do_filter = PNG_FILTER_NONE;
  176891. }
  176892. }
  176893. else
  176894. png_error(png_ptr, "Unknown custom filter method");
  176895. }
  176896. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED) /* GRR 970116 */
  176897. void PNGAPI
  176898. png_set_filter_heuristics(png_structp png_ptr, int heuristic_method,
  176899. int num_weights, png_doublep filter_weights,
  176900. png_doublep filter_costs)
  176901. {
  176902. int i;
  176903. png_debug(1, "in png_set_filter_heuristics\n");
  176904. if (png_ptr == NULL)
  176905. return;
  176906. if (heuristic_method >= PNG_FILTER_HEURISTIC_LAST)
  176907. {
  176908. png_warning(png_ptr, "Unknown filter heuristic method");
  176909. return;
  176910. }
  176911. if (heuristic_method == PNG_FILTER_HEURISTIC_DEFAULT)
  176912. {
  176913. heuristic_method = PNG_FILTER_HEURISTIC_UNWEIGHTED;
  176914. }
  176915. if (num_weights < 0 || filter_weights == NULL ||
  176916. heuristic_method == PNG_FILTER_HEURISTIC_UNWEIGHTED)
  176917. {
  176918. num_weights = 0;
  176919. }
  176920. png_ptr->num_prev_filters = (png_byte)num_weights;
  176921. png_ptr->heuristic_method = (png_byte)heuristic_method;
  176922. if (num_weights > 0)
  176923. {
  176924. if (png_ptr->prev_filters == NULL)
  176925. {
  176926. png_ptr->prev_filters = (png_bytep)png_malloc(png_ptr,
  176927. (png_uint_32)(png_sizeof(png_byte) * num_weights));
  176928. for (i = 0; i < num_weights; i++)
  176929. {
  176930. png_ptr->prev_filters[i] = 255;
  176931. }
  176932. }
  176933. if (png_ptr->filter_weights == NULL)
  176934. {
  176935. png_ptr->filter_weights = (png_uint_16p)png_malloc(png_ptr,
  176936. (png_uint_32)(png_sizeof(png_uint_16) * num_weights));
  176937. png_ptr->inv_filter_weights = (png_uint_16p)png_malloc(png_ptr,
  176938. (png_uint_32)(png_sizeof(png_uint_16) * num_weights));
  176939. for (i = 0; i < num_weights; i++)
  176940. {
  176941. png_ptr->inv_filter_weights[i] =
  176942. png_ptr->filter_weights[i] = PNG_WEIGHT_FACTOR;
  176943. }
  176944. }
  176945. for (i = 0; i < num_weights; i++)
  176946. {
  176947. if (filter_weights[i] < 0.0)
  176948. {
  176949. png_ptr->inv_filter_weights[i] =
  176950. png_ptr->filter_weights[i] = PNG_WEIGHT_FACTOR;
  176951. }
  176952. else
  176953. {
  176954. png_ptr->inv_filter_weights[i] =
  176955. (png_uint_16)((double)PNG_WEIGHT_FACTOR*filter_weights[i]+0.5);
  176956. png_ptr->filter_weights[i] =
  176957. (png_uint_16)((double)PNG_WEIGHT_FACTOR/filter_weights[i]+0.5);
  176958. }
  176959. }
  176960. }
  176961. if (png_ptr->filter_costs == NULL)
  176962. {
  176963. png_ptr->filter_costs = (png_uint_16p)png_malloc(png_ptr,
  176964. (png_uint_32)(png_sizeof(png_uint_16) * PNG_FILTER_VALUE_LAST));
  176965. png_ptr->inv_filter_costs = (png_uint_16p)png_malloc(png_ptr,
  176966. (png_uint_32)(png_sizeof(png_uint_16) * PNG_FILTER_VALUE_LAST));
  176967. for (i = 0; i < PNG_FILTER_VALUE_LAST; i++)
  176968. {
  176969. png_ptr->inv_filter_costs[i] =
  176970. png_ptr->filter_costs[i] = PNG_COST_FACTOR;
  176971. }
  176972. }
  176973. for (i = 0; i < PNG_FILTER_VALUE_LAST; i++)
  176974. {
  176975. if (filter_costs == NULL || filter_costs[i] < 0.0)
  176976. {
  176977. png_ptr->inv_filter_costs[i] =
  176978. png_ptr->filter_costs[i] = PNG_COST_FACTOR;
  176979. }
  176980. else if (filter_costs[i] >= 1.0)
  176981. {
  176982. png_ptr->inv_filter_costs[i] =
  176983. (png_uint_16)((double)PNG_COST_FACTOR / filter_costs[i] + 0.5);
  176984. png_ptr->filter_costs[i] =
  176985. (png_uint_16)((double)PNG_COST_FACTOR * filter_costs[i] + 0.5);
  176986. }
  176987. }
  176988. }
  176989. #endif /* PNG_WRITE_WEIGHTED_FILTER_SUPPORTED */
  176990. void PNGAPI
  176991. png_set_compression_level(png_structp png_ptr, int level)
  176992. {
  176993. png_debug(1, "in png_set_compression_level\n");
  176994. if (png_ptr == NULL)
  176995. return;
  176996. png_ptr->flags |= PNG_FLAG_ZLIB_CUSTOM_LEVEL;
  176997. png_ptr->zlib_level = level;
  176998. }
  176999. void PNGAPI
  177000. png_set_compression_mem_level(png_structp png_ptr, int mem_level)
  177001. {
  177002. png_debug(1, "in png_set_compression_mem_level\n");
  177003. if (png_ptr == NULL)
  177004. return;
  177005. png_ptr->flags |= PNG_FLAG_ZLIB_CUSTOM_MEM_LEVEL;
  177006. png_ptr->zlib_mem_level = mem_level;
  177007. }
  177008. void PNGAPI
  177009. png_set_compression_strategy(png_structp png_ptr, int strategy)
  177010. {
  177011. png_debug(1, "in png_set_compression_strategy\n");
  177012. if (png_ptr == NULL)
  177013. return;
  177014. png_ptr->flags |= PNG_FLAG_ZLIB_CUSTOM_STRATEGY;
  177015. png_ptr->zlib_strategy = strategy;
  177016. }
  177017. void PNGAPI
  177018. png_set_compression_window_bits(png_structp png_ptr, int window_bits)
  177019. {
  177020. if (png_ptr == NULL)
  177021. return;
  177022. if (window_bits > 15)
  177023. png_warning(png_ptr, "Only compression windows <= 32k supported by PNG");
  177024. else if (window_bits < 8)
  177025. png_warning(png_ptr, "Only compression windows >= 256 supported by PNG");
  177026. #ifndef WBITS_8_OK
  177027. if (window_bits == 8)
  177028. {
  177029. png_warning(png_ptr, "Compression window is being reset to 512");
  177030. window_bits=9;
  177031. }
  177032. #endif
  177033. png_ptr->flags |= PNG_FLAG_ZLIB_CUSTOM_WINDOW_BITS;
  177034. png_ptr->zlib_window_bits = window_bits;
  177035. }
  177036. void PNGAPI
  177037. png_set_compression_method(png_structp png_ptr, int method)
  177038. {
  177039. png_debug(1, "in png_set_compression_method\n");
  177040. if (png_ptr == NULL)
  177041. return;
  177042. if (method != 8)
  177043. png_warning(png_ptr, "Only compression method 8 is supported by PNG");
  177044. png_ptr->flags |= PNG_FLAG_ZLIB_CUSTOM_METHOD;
  177045. png_ptr->zlib_method = method;
  177046. }
  177047. void PNGAPI
  177048. png_set_write_status_fn(png_structp png_ptr, png_write_status_ptr write_row_fn)
  177049. {
  177050. if (png_ptr == NULL)
  177051. return;
  177052. png_ptr->write_row_fn = write_row_fn;
  177053. }
  177054. #if defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED)
  177055. void PNGAPI
  177056. png_set_write_user_transform_fn(png_structp png_ptr, png_user_transform_ptr
  177057. write_user_transform_fn)
  177058. {
  177059. png_debug(1, "in png_set_write_user_transform_fn\n");
  177060. if (png_ptr == NULL)
  177061. return;
  177062. png_ptr->transformations |= PNG_USER_TRANSFORM;
  177063. png_ptr->write_user_transform_fn = write_user_transform_fn;
  177064. }
  177065. #endif
  177066. #if defined(PNG_INFO_IMAGE_SUPPORTED)
  177067. void PNGAPI
  177068. png_write_png(png_structp png_ptr, png_infop info_ptr,
  177069. int transforms, voidp params)
  177070. {
  177071. if (png_ptr == NULL || info_ptr == NULL)
  177072. return;
  177073. #if defined(PNG_WRITE_INVERT_ALPHA_SUPPORTED)
  177074. if (transforms & PNG_TRANSFORM_INVERT_ALPHA)
  177075. png_set_invert_alpha(png_ptr);
  177076. #endif
  177077. png_write_info(png_ptr, info_ptr);
  177078. #if defined(PNG_WRITE_INVERT_SUPPORTED)
  177079. if (transforms & PNG_TRANSFORM_INVERT_MONO)
  177080. png_set_invert_mono(png_ptr);
  177081. #endif
  177082. #if defined(PNG_WRITE_SHIFT_SUPPORTED)
  177083. if ((transforms & PNG_TRANSFORM_SHIFT)
  177084. && (info_ptr->valid & PNG_INFO_sBIT))
  177085. png_set_shift(png_ptr, &info_ptr->sig_bit);
  177086. #endif
  177087. #if defined(PNG_WRITE_PACK_SUPPORTED)
  177088. if (transforms & PNG_TRANSFORM_PACKING)
  177089. png_set_packing(png_ptr);
  177090. #endif
  177091. #if defined(PNG_WRITE_SWAP_ALPHA_SUPPORTED)
  177092. if (transforms & PNG_TRANSFORM_SWAP_ALPHA)
  177093. png_set_swap_alpha(png_ptr);
  177094. #endif
  177095. #if defined(PNG_WRITE_FILLER_SUPPORTED)
  177096. if (transforms & PNG_TRANSFORM_STRIP_FILLER)
  177097. png_set_filler(png_ptr, 0, PNG_FILLER_BEFORE);
  177098. #endif
  177099. #if defined(PNG_WRITE_BGR_SUPPORTED)
  177100. if (transforms & PNG_TRANSFORM_BGR)
  177101. png_set_bgr(png_ptr);
  177102. #endif
  177103. #if defined(PNG_WRITE_SWAP_SUPPORTED)
  177104. if (transforms & PNG_TRANSFORM_SWAP_ENDIAN)
  177105. png_set_swap(png_ptr);
  177106. #endif
  177107. #if defined(PNG_WRITE_PACKSWAP_SUPPORTED)
  177108. if (transforms & PNG_TRANSFORM_PACKSWAP)
  177109. png_set_packswap(png_ptr);
  177110. #endif
  177111. if (info_ptr->valid & PNG_INFO_IDAT)
  177112. png_write_image(png_ptr, info_ptr->row_pointers);
  177113. png_write_end(png_ptr, info_ptr);
  177114. transforms = transforms; /* quiet compiler warnings */
  177115. params = params;
  177116. }
  177117. #endif
  177118. #endif /* PNG_WRITE_SUPPORTED */
  177119. /********* End of inlined file: pngwrite.c *********/
  177120. /********* Start of inlined file: pngwtran.c *********/
  177121. #define PNG_INTERNAL
  177122. #ifdef PNG_WRITE_SUPPORTED
  177123. void /* PRIVATE */
  177124. png_do_write_transformations(png_structp png_ptr)
  177125. {
  177126. png_debug(1, "in png_do_write_transformations\n");
  177127. if (png_ptr == NULL)
  177128. return;
  177129. #if defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED)
  177130. if (png_ptr->transformations & PNG_USER_TRANSFORM)
  177131. if(png_ptr->write_user_transform_fn != NULL)
  177132. (*(png_ptr->write_user_transform_fn)) /* user write transform function */
  177133. (png_ptr, /* png_ptr */
  177134. &(png_ptr->row_info), /* row_info: */
  177135. png_ptr->row_buf + 1); /* start of pixel data for row */
  177136. #endif
  177137. #if defined(PNG_WRITE_FILLER_SUPPORTED)
  177138. if (png_ptr->transformations & PNG_FILLER)
  177139. png_do_strip_filler(&(png_ptr->row_info), png_ptr->row_buf + 1,
  177140. png_ptr->flags);
  177141. #endif
  177142. #if defined(PNG_WRITE_PACKSWAP_SUPPORTED)
  177143. if (png_ptr->transformations & PNG_PACKSWAP)
  177144. png_do_packswap(&(png_ptr->row_info), png_ptr->row_buf + 1);
  177145. #endif
  177146. #if defined(PNG_WRITE_PACK_SUPPORTED)
  177147. if (png_ptr->transformations & PNG_PACK)
  177148. png_do_pack(&(png_ptr->row_info), png_ptr->row_buf + 1,
  177149. (png_uint_32)png_ptr->bit_depth);
  177150. #endif
  177151. #if defined(PNG_WRITE_SWAP_SUPPORTED)
  177152. if (png_ptr->transformations & PNG_SWAP_BYTES)
  177153. png_do_swap(&(png_ptr->row_info), png_ptr->row_buf + 1);
  177154. #endif
  177155. #if defined(PNG_WRITE_SHIFT_SUPPORTED)
  177156. if (png_ptr->transformations & PNG_SHIFT)
  177157. png_do_shift(&(png_ptr->row_info), png_ptr->row_buf + 1,
  177158. &(png_ptr->shift));
  177159. #endif
  177160. #if defined(PNG_WRITE_SWAP_ALPHA_SUPPORTED)
  177161. if (png_ptr->transformations & PNG_SWAP_ALPHA)
  177162. png_do_write_swap_alpha(&(png_ptr->row_info), png_ptr->row_buf + 1);
  177163. #endif
  177164. #if defined(PNG_WRITE_INVERT_ALPHA_SUPPORTED)
  177165. if (png_ptr->transformations & PNG_INVERT_ALPHA)
  177166. png_do_write_invert_alpha(&(png_ptr->row_info), png_ptr->row_buf + 1);
  177167. #endif
  177168. #if defined(PNG_WRITE_BGR_SUPPORTED)
  177169. if (png_ptr->transformations & PNG_BGR)
  177170. png_do_bgr(&(png_ptr->row_info), png_ptr->row_buf + 1);
  177171. #endif
  177172. #if defined(PNG_WRITE_INVERT_SUPPORTED)
  177173. if (png_ptr->transformations & PNG_INVERT_MONO)
  177174. png_do_invert(&(png_ptr->row_info), png_ptr->row_buf + 1);
  177175. #endif
  177176. }
  177177. #if defined(PNG_WRITE_PACK_SUPPORTED)
  177178. void /* PRIVATE */
  177179. png_do_pack(png_row_infop row_info, png_bytep row, png_uint_32 bit_depth)
  177180. {
  177181. png_debug(1, "in png_do_pack\n");
  177182. if (row_info->bit_depth == 8 &&
  177183. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  177184. row != NULL && row_info != NULL &&
  177185. #endif
  177186. row_info->channels == 1)
  177187. {
  177188. switch ((int)bit_depth)
  177189. {
  177190. case 1:
  177191. {
  177192. png_bytep sp, dp;
  177193. int mask, v;
  177194. png_uint_32 i;
  177195. png_uint_32 row_width = row_info->width;
  177196. sp = row;
  177197. dp = row;
  177198. mask = 0x80;
  177199. v = 0;
  177200. for (i = 0; i < row_width; i++)
  177201. {
  177202. if (*sp != 0)
  177203. v |= mask;
  177204. sp++;
  177205. if (mask > 1)
  177206. mask >>= 1;
  177207. else
  177208. {
  177209. mask = 0x80;
  177210. *dp = (png_byte)v;
  177211. dp++;
  177212. v = 0;
  177213. }
  177214. }
  177215. if (mask != 0x80)
  177216. *dp = (png_byte)v;
  177217. break;
  177218. }
  177219. case 2:
  177220. {
  177221. png_bytep sp, dp;
  177222. int shift, v;
  177223. png_uint_32 i;
  177224. png_uint_32 row_width = row_info->width;
  177225. sp = row;
  177226. dp = row;
  177227. shift = 6;
  177228. v = 0;
  177229. for (i = 0; i < row_width; i++)
  177230. {
  177231. png_byte value;
  177232. value = (png_byte)(*sp & 0x03);
  177233. v |= (value << shift);
  177234. if (shift == 0)
  177235. {
  177236. shift = 6;
  177237. *dp = (png_byte)v;
  177238. dp++;
  177239. v = 0;
  177240. }
  177241. else
  177242. shift -= 2;
  177243. sp++;
  177244. }
  177245. if (shift != 6)
  177246. *dp = (png_byte)v;
  177247. break;
  177248. }
  177249. case 4:
  177250. {
  177251. png_bytep sp, dp;
  177252. int shift, v;
  177253. png_uint_32 i;
  177254. png_uint_32 row_width = row_info->width;
  177255. sp = row;
  177256. dp = row;
  177257. shift = 4;
  177258. v = 0;
  177259. for (i = 0; i < row_width; i++)
  177260. {
  177261. png_byte value;
  177262. value = (png_byte)(*sp & 0x0f);
  177263. v |= (value << shift);
  177264. if (shift == 0)
  177265. {
  177266. shift = 4;
  177267. *dp = (png_byte)v;
  177268. dp++;
  177269. v = 0;
  177270. }
  177271. else
  177272. shift -= 4;
  177273. sp++;
  177274. }
  177275. if (shift != 4)
  177276. *dp = (png_byte)v;
  177277. break;
  177278. }
  177279. }
  177280. row_info->bit_depth = (png_byte)bit_depth;
  177281. row_info->pixel_depth = (png_byte)(bit_depth * row_info->channels);
  177282. row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,
  177283. row_info->width);
  177284. }
  177285. }
  177286. #endif
  177287. #if defined(PNG_WRITE_SHIFT_SUPPORTED)
  177288. void /* PRIVATE */
  177289. png_do_shift(png_row_infop row_info, png_bytep row, png_color_8p bit_depth)
  177290. {
  177291. png_debug(1, "in png_do_shift\n");
  177292. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  177293. if (row != NULL && row_info != NULL &&
  177294. #else
  177295. if (
  177296. #endif
  177297. row_info->color_type != PNG_COLOR_TYPE_PALETTE)
  177298. {
  177299. int shift_start[4], shift_dec[4];
  177300. int channels = 0;
  177301. if (row_info->color_type & PNG_COLOR_MASK_COLOR)
  177302. {
  177303. shift_start[channels] = row_info->bit_depth - bit_depth->red;
  177304. shift_dec[channels] = bit_depth->red;
  177305. channels++;
  177306. shift_start[channels] = row_info->bit_depth - bit_depth->green;
  177307. shift_dec[channels] = bit_depth->green;
  177308. channels++;
  177309. shift_start[channels] = row_info->bit_depth - bit_depth->blue;
  177310. shift_dec[channels] = bit_depth->blue;
  177311. channels++;
  177312. }
  177313. else
  177314. {
  177315. shift_start[channels] = row_info->bit_depth - bit_depth->gray;
  177316. shift_dec[channels] = bit_depth->gray;
  177317. channels++;
  177318. }
  177319. if (row_info->color_type & PNG_COLOR_MASK_ALPHA)
  177320. {
  177321. shift_start[channels] = row_info->bit_depth - bit_depth->alpha;
  177322. shift_dec[channels] = bit_depth->alpha;
  177323. channels++;
  177324. }
  177325. if (row_info->bit_depth < 8)
  177326. {
  177327. png_bytep bp = row;
  177328. png_uint_32 i;
  177329. png_byte mask;
  177330. png_uint_32 row_bytes = row_info->rowbytes;
  177331. if (bit_depth->gray == 1 && row_info->bit_depth == 2)
  177332. mask = 0x55;
  177333. else if (row_info->bit_depth == 4 && bit_depth->gray == 3)
  177334. mask = 0x11;
  177335. else
  177336. mask = 0xff;
  177337. for (i = 0; i < row_bytes; i++, bp++)
  177338. {
  177339. png_uint_16 v;
  177340. int j;
  177341. v = *bp;
  177342. *bp = 0;
  177343. for (j = shift_start[0]; j > -shift_dec[0]; j -= shift_dec[0])
  177344. {
  177345. if (j > 0)
  177346. *bp |= (png_byte)((v << j) & 0xff);
  177347. else
  177348. *bp |= (png_byte)((v >> (-j)) & mask);
  177349. }
  177350. }
  177351. }
  177352. else if (row_info->bit_depth == 8)
  177353. {
  177354. png_bytep bp = row;
  177355. png_uint_32 i;
  177356. png_uint_32 istop = channels * row_info->width;
  177357. for (i = 0; i < istop; i++, bp++)
  177358. {
  177359. png_uint_16 v;
  177360. int j;
  177361. int c = (int)(i%channels);
  177362. v = *bp;
  177363. *bp = 0;
  177364. for (j = shift_start[c]; j > -shift_dec[c]; j -= shift_dec[c])
  177365. {
  177366. if (j > 0)
  177367. *bp |= (png_byte)((v << j) & 0xff);
  177368. else
  177369. *bp |= (png_byte)((v >> (-j)) & 0xff);
  177370. }
  177371. }
  177372. }
  177373. else
  177374. {
  177375. png_bytep bp;
  177376. png_uint_32 i;
  177377. png_uint_32 istop = channels * row_info->width;
  177378. for (bp = row, i = 0; i < istop; i++)
  177379. {
  177380. int c = (int)(i%channels);
  177381. png_uint_16 value, v;
  177382. int j;
  177383. v = (png_uint_16)(((png_uint_16)(*bp) << 8) + *(bp + 1));
  177384. value = 0;
  177385. for (j = shift_start[c]; j > -shift_dec[c]; j -= shift_dec[c])
  177386. {
  177387. if (j > 0)
  177388. value |= (png_uint_16)((v << j) & (png_uint_16)0xffff);
  177389. else
  177390. value |= (png_uint_16)((v >> (-j)) & (png_uint_16)0xffff);
  177391. }
  177392. *bp++ = (png_byte)(value >> 8);
  177393. *bp++ = (png_byte)(value & 0xff);
  177394. }
  177395. }
  177396. }
  177397. }
  177398. #endif
  177399. #if defined(PNG_WRITE_SWAP_ALPHA_SUPPORTED)
  177400. void /* PRIVATE */
  177401. png_do_write_swap_alpha(png_row_infop row_info, png_bytep row)
  177402. {
  177403. png_debug(1, "in png_do_write_swap_alpha\n");
  177404. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  177405. if (row != NULL && row_info != NULL)
  177406. #endif
  177407. {
  177408. if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  177409. {
  177410. if (row_info->bit_depth == 8)
  177411. {
  177412. png_bytep sp, dp;
  177413. png_uint_32 i;
  177414. png_uint_32 row_width = row_info->width;
  177415. for (i = 0, sp = dp = row; i < row_width; i++)
  177416. {
  177417. png_byte save = *(sp++);
  177418. *(dp++) = *(sp++);
  177419. *(dp++) = *(sp++);
  177420. *(dp++) = *(sp++);
  177421. *(dp++) = save;
  177422. }
  177423. }
  177424. else
  177425. {
  177426. png_bytep sp, dp;
  177427. png_uint_32 i;
  177428. png_uint_32 row_width = row_info->width;
  177429. for (i = 0, sp = dp = row; i < row_width; i++)
  177430. {
  177431. png_byte save[2];
  177432. save[0] = *(sp++);
  177433. save[1] = *(sp++);
  177434. *(dp++) = *(sp++);
  177435. *(dp++) = *(sp++);
  177436. *(dp++) = *(sp++);
  177437. *(dp++) = *(sp++);
  177438. *(dp++) = *(sp++);
  177439. *(dp++) = *(sp++);
  177440. *(dp++) = save[0];
  177441. *(dp++) = save[1];
  177442. }
  177443. }
  177444. }
  177445. else if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
  177446. {
  177447. if (row_info->bit_depth == 8)
  177448. {
  177449. png_bytep sp, dp;
  177450. png_uint_32 i;
  177451. png_uint_32 row_width = row_info->width;
  177452. for (i = 0, sp = dp = row; i < row_width; i++)
  177453. {
  177454. png_byte save = *(sp++);
  177455. *(dp++) = *(sp++);
  177456. *(dp++) = save;
  177457. }
  177458. }
  177459. else
  177460. {
  177461. png_bytep sp, dp;
  177462. png_uint_32 i;
  177463. png_uint_32 row_width = row_info->width;
  177464. for (i = 0, sp = dp = row; i < row_width; i++)
  177465. {
  177466. png_byte save[2];
  177467. save[0] = *(sp++);
  177468. save[1] = *(sp++);
  177469. *(dp++) = *(sp++);
  177470. *(dp++) = *(sp++);
  177471. *(dp++) = save[0];
  177472. *(dp++) = save[1];
  177473. }
  177474. }
  177475. }
  177476. }
  177477. }
  177478. #endif
  177479. #if defined(PNG_WRITE_INVERT_ALPHA_SUPPORTED)
  177480. void /* PRIVATE */
  177481. png_do_write_invert_alpha(png_row_infop row_info, png_bytep row)
  177482. {
  177483. png_debug(1, "in png_do_write_invert_alpha\n");
  177484. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  177485. if (row != NULL && row_info != NULL)
  177486. #endif
  177487. {
  177488. if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  177489. {
  177490. if (row_info->bit_depth == 8)
  177491. {
  177492. png_bytep sp, dp;
  177493. png_uint_32 i;
  177494. png_uint_32 row_width = row_info->width;
  177495. for (i = 0, sp = dp = row; i < row_width; i++)
  177496. {
  177497. sp+=3; dp = sp;
  177498. *(dp++) = (png_byte)(255 - *(sp++));
  177499. }
  177500. }
  177501. else
  177502. {
  177503. png_bytep sp, dp;
  177504. png_uint_32 i;
  177505. png_uint_32 row_width = row_info->width;
  177506. for (i = 0, sp = dp = row; i < row_width; i++)
  177507. {
  177508. sp+=6; dp = sp;
  177509. *(dp++) = (png_byte)(255 - *(sp++));
  177510. *(dp++) = (png_byte)(255 - *(sp++));
  177511. }
  177512. }
  177513. }
  177514. else if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
  177515. {
  177516. if (row_info->bit_depth == 8)
  177517. {
  177518. png_bytep sp, dp;
  177519. png_uint_32 i;
  177520. png_uint_32 row_width = row_info->width;
  177521. for (i = 0, sp = dp = row; i < row_width; i++)
  177522. {
  177523. *(dp++) = *(sp++);
  177524. *(dp++) = (png_byte)(255 - *(sp++));
  177525. }
  177526. }
  177527. else
  177528. {
  177529. png_bytep sp, dp;
  177530. png_uint_32 i;
  177531. png_uint_32 row_width = row_info->width;
  177532. for (i = 0, sp = dp = row; i < row_width; i++)
  177533. {
  177534. sp+=2; dp = sp;
  177535. *(dp++) = (png_byte)(255 - *(sp++));
  177536. *(dp++) = (png_byte)(255 - *(sp++));
  177537. }
  177538. }
  177539. }
  177540. }
  177541. }
  177542. #endif
  177543. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  177544. void /* PRIVATE */
  177545. png_do_write_intrapixel(png_row_infop row_info, png_bytep row)
  177546. {
  177547. png_debug(1, "in png_do_write_intrapixel\n");
  177548. if (
  177549. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  177550. row != NULL && row_info != NULL &&
  177551. #endif
  177552. (row_info->color_type & PNG_COLOR_MASK_COLOR))
  177553. {
  177554. int bytes_per_pixel;
  177555. png_uint_32 row_width = row_info->width;
  177556. if (row_info->bit_depth == 8)
  177557. {
  177558. png_bytep rp;
  177559. png_uint_32 i;
  177560. if (row_info->color_type == PNG_COLOR_TYPE_RGB)
  177561. bytes_per_pixel = 3;
  177562. else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  177563. bytes_per_pixel = 4;
  177564. else
  177565. return;
  177566. for (i = 0, rp = row; i < row_width; i++, rp += bytes_per_pixel)
  177567. {
  177568. *(rp) = (png_byte)((*rp - *(rp+1))&0xff);
  177569. *(rp+2) = (png_byte)((*(rp+2) - *(rp+1))&0xff);
  177570. }
  177571. }
  177572. else if (row_info->bit_depth == 16)
  177573. {
  177574. png_bytep rp;
  177575. png_uint_32 i;
  177576. if (row_info->color_type == PNG_COLOR_TYPE_RGB)
  177577. bytes_per_pixel = 6;
  177578. else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  177579. bytes_per_pixel = 8;
  177580. else
  177581. return;
  177582. for (i = 0, rp = row; i < row_width; i++, rp += bytes_per_pixel)
  177583. {
  177584. png_uint_32 s0 = (*(rp ) << 8) | *(rp+1);
  177585. png_uint_32 s1 = (*(rp+2) << 8) | *(rp+3);
  177586. png_uint_32 s2 = (*(rp+4) << 8) | *(rp+5);
  177587. png_uint_32 red = (png_uint_32)((s0-s1) & 0xffffL);
  177588. png_uint_32 blue = (png_uint_32)((s2-s1) & 0xffffL);
  177589. *(rp ) = (png_byte)((red >> 8) & 0xff);
  177590. *(rp+1) = (png_byte)(red & 0xff);
  177591. *(rp+4) = (png_byte)((blue >> 8) & 0xff);
  177592. *(rp+5) = (png_byte)(blue & 0xff);
  177593. }
  177594. }
  177595. }
  177596. }
  177597. #endif /* PNG_MNG_FEATURES_SUPPORTED */
  177598. #endif /* PNG_WRITE_SUPPORTED */
  177599. /********* End of inlined file: pngwtran.c *********/
  177600. /********* Start of inlined file: pngwutil.c *********/
  177601. #define PNG_INTERNAL
  177602. #ifdef PNG_WRITE_SUPPORTED
  177603. void PNGAPI
  177604. png_save_uint_32(png_bytep buf, png_uint_32 i)
  177605. {
  177606. buf[0] = (png_byte)((i >> 24) & 0xff);
  177607. buf[1] = (png_byte)((i >> 16) & 0xff);
  177608. buf[2] = (png_byte)((i >> 8) & 0xff);
  177609. buf[3] = (png_byte)(i & 0xff);
  177610. }
  177611. void PNGAPI
  177612. png_save_int_32(png_bytep buf, png_int_32 i)
  177613. {
  177614. buf[0] = (png_byte)((i >> 24) & 0xff);
  177615. buf[1] = (png_byte)((i >> 16) & 0xff);
  177616. buf[2] = (png_byte)((i >> 8) & 0xff);
  177617. buf[3] = (png_byte)(i & 0xff);
  177618. }
  177619. void PNGAPI
  177620. png_save_uint_16(png_bytep buf, unsigned int i)
  177621. {
  177622. buf[0] = (png_byte)((i >> 8) & 0xff);
  177623. buf[1] = (png_byte)(i & 0xff);
  177624. }
  177625. void PNGAPI
  177626. png_write_chunk(png_structp png_ptr, png_bytep chunk_name,
  177627. png_bytep data, png_size_t length)
  177628. {
  177629. if(png_ptr == NULL) return;
  177630. png_write_chunk_start(png_ptr, chunk_name, (png_uint_32)length);
  177631. png_write_chunk_data(png_ptr, data, length);
  177632. png_write_chunk_end(png_ptr);
  177633. }
  177634. void PNGAPI
  177635. png_write_chunk_start(png_structp png_ptr, png_bytep chunk_name,
  177636. png_uint_32 length)
  177637. {
  177638. png_byte buf[4];
  177639. png_debug2(0, "Writing %s chunk (%lu bytes)\n", chunk_name, length);
  177640. if(png_ptr == NULL) return;
  177641. png_save_uint_32(buf, length);
  177642. png_write_data(png_ptr, buf, (png_size_t)4);
  177643. png_write_data(png_ptr, chunk_name, (png_size_t)4);
  177644. png_reset_crc(png_ptr);
  177645. png_calculate_crc(png_ptr, chunk_name, (png_size_t)4);
  177646. }
  177647. void PNGAPI
  177648. png_write_chunk_data(png_structp png_ptr, png_bytep data, png_size_t length)
  177649. {
  177650. if(png_ptr == NULL) return;
  177651. if (data != NULL && length > 0)
  177652. {
  177653. png_calculate_crc(png_ptr, data, length);
  177654. png_write_data(png_ptr, data, length);
  177655. }
  177656. }
  177657. void PNGAPI
  177658. png_write_chunk_end(png_structp png_ptr)
  177659. {
  177660. png_byte buf[4];
  177661. if(png_ptr == NULL) return;
  177662. png_save_uint_32(buf, png_ptr->crc);
  177663. png_write_data(png_ptr, buf, (png_size_t)4);
  177664. }
  177665. void /* PRIVATE */
  177666. png_write_sig(png_structp png_ptr)
  177667. {
  177668. png_byte png_signature[8] = {137, 80, 78, 71, 13, 10, 26, 10};
  177669. png_write_data(png_ptr, &png_signature[png_ptr->sig_bytes],
  177670. (png_size_t)8 - png_ptr->sig_bytes);
  177671. if(png_ptr->sig_bytes < 3)
  177672. png_ptr->mode |= PNG_HAVE_PNG_SIGNATURE;
  177673. }
  177674. #if defined(PNG_WRITE_TEXT_SUPPORTED) || defined(PNG_WRITE_iCCP_SUPPORTED)
  177675. typedef struct
  177676. {
  177677. char *input; /* the uncompressed input data */
  177678. int input_len; /* its length */
  177679. int num_output_ptr; /* number of output pointers used */
  177680. int max_output_ptr; /* size of output_ptr */
  177681. png_charpp output_ptr; /* array of pointers to output */
  177682. } compression_state;
  177683. static int /* PRIVATE */
  177684. png_text_compress(png_structp png_ptr,
  177685. png_charp text, png_size_t text_len, int compression,
  177686. compression_state *comp)
  177687. {
  177688. int ret;
  177689. comp->num_output_ptr = 0;
  177690. comp->max_output_ptr = 0;
  177691. comp->output_ptr = NULL;
  177692. comp->input = NULL;
  177693. comp->input_len = 0;
  177694. if (compression == PNG_TEXT_COMPRESSION_NONE)
  177695. {
  177696. comp->input = text;
  177697. comp->input_len = text_len;
  177698. return((int)text_len);
  177699. }
  177700. if (compression >= PNG_TEXT_COMPRESSION_LAST)
  177701. {
  177702. #if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE)
  177703. char msg[50];
  177704. png_snprintf(msg, 50, "Unknown compression type %d", compression);
  177705. png_warning(png_ptr, msg);
  177706. #else
  177707. png_warning(png_ptr, "Unknown compression type");
  177708. #endif
  177709. }
  177710. png_ptr->zstream.avail_in = (uInt)text_len;
  177711. png_ptr->zstream.next_in = (Bytef *)text;
  177712. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  177713. png_ptr->zstream.next_out = (Bytef *)png_ptr->zbuf;
  177714. do
  177715. {
  177716. ret = deflate(&png_ptr->zstream, Z_NO_FLUSH);
  177717. if (ret != Z_OK)
  177718. {
  177719. if (png_ptr->zstream.msg != NULL)
  177720. png_error(png_ptr, png_ptr->zstream.msg);
  177721. else
  177722. png_error(png_ptr, "zlib error");
  177723. }
  177724. if (!(png_ptr->zstream.avail_out))
  177725. {
  177726. if (comp->num_output_ptr >= comp->max_output_ptr)
  177727. {
  177728. int old_max;
  177729. old_max = comp->max_output_ptr;
  177730. comp->max_output_ptr = comp->num_output_ptr + 4;
  177731. if (comp->output_ptr != NULL)
  177732. {
  177733. png_charpp old_ptr;
  177734. old_ptr = comp->output_ptr;
  177735. comp->output_ptr = (png_charpp)png_malloc(png_ptr,
  177736. (png_uint_32)(comp->max_output_ptr *
  177737. png_sizeof (png_charpp)));
  177738. png_memcpy(comp->output_ptr, old_ptr, old_max
  177739. * png_sizeof (png_charp));
  177740. png_free(png_ptr, old_ptr);
  177741. }
  177742. else
  177743. comp->output_ptr = (png_charpp)png_malloc(png_ptr,
  177744. (png_uint_32)(comp->max_output_ptr *
  177745. png_sizeof (png_charp)));
  177746. }
  177747. comp->output_ptr[comp->num_output_ptr] = (png_charp)png_malloc(png_ptr,
  177748. (png_uint_32)png_ptr->zbuf_size);
  177749. png_memcpy(comp->output_ptr[comp->num_output_ptr], png_ptr->zbuf,
  177750. png_ptr->zbuf_size);
  177751. comp->num_output_ptr++;
  177752. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  177753. png_ptr->zstream.next_out = png_ptr->zbuf;
  177754. }
  177755. } while (png_ptr->zstream.avail_in);
  177756. do
  177757. {
  177758. ret = deflate(&png_ptr->zstream, Z_FINISH);
  177759. if (ret == Z_OK)
  177760. {
  177761. if (!(png_ptr->zstream.avail_out))
  177762. {
  177763. if (comp->num_output_ptr >= comp->max_output_ptr)
  177764. {
  177765. int old_max;
  177766. old_max = comp->max_output_ptr;
  177767. comp->max_output_ptr = comp->num_output_ptr + 4;
  177768. if (comp->output_ptr != NULL)
  177769. {
  177770. png_charpp old_ptr;
  177771. old_ptr = comp->output_ptr;
  177772. comp->output_ptr = (png_charpp)png_malloc(png_ptr,
  177773. (png_uint_32)(comp->max_output_ptr *
  177774. png_sizeof (png_charpp)));
  177775. png_memcpy(comp->output_ptr, old_ptr,
  177776. old_max * png_sizeof (png_charp));
  177777. png_free(png_ptr, old_ptr);
  177778. }
  177779. else
  177780. comp->output_ptr = (png_charpp)png_malloc(png_ptr,
  177781. (png_uint_32)(comp->max_output_ptr *
  177782. png_sizeof (png_charp)));
  177783. }
  177784. comp->output_ptr[comp->num_output_ptr] =
  177785. (png_charp)png_malloc(png_ptr, (png_uint_32)png_ptr->zbuf_size);
  177786. png_memcpy(comp->output_ptr[comp->num_output_ptr], png_ptr->zbuf,
  177787. png_ptr->zbuf_size);
  177788. comp->num_output_ptr++;
  177789. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  177790. png_ptr->zstream.next_out = png_ptr->zbuf;
  177791. }
  177792. }
  177793. else if (ret != Z_STREAM_END)
  177794. {
  177795. if (png_ptr->zstream.msg != NULL)
  177796. png_error(png_ptr, png_ptr->zstream.msg);
  177797. else
  177798. png_error(png_ptr, "zlib error");
  177799. }
  177800. } while (ret != Z_STREAM_END);
  177801. text_len = png_ptr->zbuf_size * comp->num_output_ptr;
  177802. if (png_ptr->zstream.avail_out < png_ptr->zbuf_size)
  177803. text_len += png_ptr->zbuf_size - (png_size_t)png_ptr->zstream.avail_out;
  177804. return((int)text_len);
  177805. }
  177806. static void /* PRIVATE */
  177807. png_write_compressed_data_out(png_structp png_ptr, compression_state *comp)
  177808. {
  177809. int i;
  177810. if (comp->input)
  177811. {
  177812. png_write_chunk_data(png_ptr, (png_bytep)comp->input,
  177813. (png_size_t)comp->input_len);
  177814. return;
  177815. }
  177816. for (i = 0; i < comp->num_output_ptr; i++)
  177817. {
  177818. png_write_chunk_data(png_ptr,(png_bytep)comp->output_ptr[i],
  177819. png_ptr->zbuf_size);
  177820. png_free(png_ptr, comp->output_ptr[i]);
  177821. comp->output_ptr[i]=NULL;
  177822. }
  177823. if (comp->max_output_ptr != 0)
  177824. png_free(png_ptr, comp->output_ptr);
  177825. comp->output_ptr=NULL;
  177826. if (png_ptr->zstream.avail_out < (png_uint_32)png_ptr->zbuf_size)
  177827. png_write_chunk_data(png_ptr, png_ptr->zbuf,
  177828. png_ptr->zbuf_size - png_ptr->zstream.avail_out);
  177829. deflateReset(&png_ptr->zstream);
  177830. png_ptr->zstream.data_type = Z_BINARY;
  177831. }
  177832. #endif
  177833. void /* PRIVATE */
  177834. png_write_IHDR(png_structp png_ptr, png_uint_32 width, png_uint_32 height,
  177835. int bit_depth, int color_type, int compression_type, int filter_type,
  177836. int interlace_type)
  177837. {
  177838. #ifdef PNG_USE_LOCAL_ARRAYS
  177839. PNG_IHDR;
  177840. #endif
  177841. png_byte buf[13]; /* buffer to store the IHDR info */
  177842. png_debug(1, "in png_write_IHDR\n");
  177843. switch (color_type)
  177844. {
  177845. case PNG_COLOR_TYPE_GRAY:
  177846. switch (bit_depth)
  177847. {
  177848. case 1:
  177849. case 2:
  177850. case 4:
  177851. case 8:
  177852. case 16: png_ptr->channels = 1; break;
  177853. default: png_error(png_ptr,"Invalid bit depth for grayscale image");
  177854. }
  177855. break;
  177856. case PNG_COLOR_TYPE_RGB:
  177857. if (bit_depth != 8 && bit_depth != 16)
  177858. png_error(png_ptr, "Invalid bit depth for RGB image");
  177859. png_ptr->channels = 3;
  177860. break;
  177861. case PNG_COLOR_TYPE_PALETTE:
  177862. switch (bit_depth)
  177863. {
  177864. case 1:
  177865. case 2:
  177866. case 4:
  177867. case 8: png_ptr->channels = 1; break;
  177868. default: png_error(png_ptr, "Invalid bit depth for paletted image");
  177869. }
  177870. break;
  177871. case PNG_COLOR_TYPE_GRAY_ALPHA:
  177872. if (bit_depth != 8 && bit_depth != 16)
  177873. png_error(png_ptr, "Invalid bit depth for grayscale+alpha image");
  177874. png_ptr->channels = 2;
  177875. break;
  177876. case PNG_COLOR_TYPE_RGB_ALPHA:
  177877. if (bit_depth != 8 && bit_depth != 16)
  177878. png_error(png_ptr, "Invalid bit depth for RGBA image");
  177879. png_ptr->channels = 4;
  177880. break;
  177881. default:
  177882. png_error(png_ptr, "Invalid image color type specified");
  177883. }
  177884. if (compression_type != PNG_COMPRESSION_TYPE_BASE)
  177885. {
  177886. png_warning(png_ptr, "Invalid compression type specified");
  177887. compression_type = PNG_COMPRESSION_TYPE_BASE;
  177888. }
  177889. if (
  177890. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  177891. !((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) &&
  177892. ((png_ptr->mode&PNG_HAVE_PNG_SIGNATURE) == 0) &&
  177893. (color_type == PNG_COLOR_TYPE_RGB ||
  177894. color_type == PNG_COLOR_TYPE_RGB_ALPHA) &&
  177895. (filter_type == PNG_INTRAPIXEL_DIFFERENCING)) &&
  177896. #endif
  177897. filter_type != PNG_FILTER_TYPE_BASE)
  177898. {
  177899. png_warning(png_ptr, "Invalid filter type specified");
  177900. filter_type = PNG_FILTER_TYPE_BASE;
  177901. }
  177902. #ifdef PNG_WRITE_INTERLACING_SUPPORTED
  177903. if (interlace_type != PNG_INTERLACE_NONE &&
  177904. interlace_type != PNG_INTERLACE_ADAM7)
  177905. {
  177906. png_warning(png_ptr, "Invalid interlace type specified");
  177907. interlace_type = PNG_INTERLACE_ADAM7;
  177908. }
  177909. #else
  177910. interlace_type=PNG_INTERLACE_NONE;
  177911. #endif
  177912. png_ptr->bit_depth = (png_byte)bit_depth;
  177913. png_ptr->color_type = (png_byte)color_type;
  177914. png_ptr->interlaced = (png_byte)interlace_type;
  177915. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  177916. png_ptr->filter_type = (png_byte)filter_type;
  177917. #endif
  177918. png_ptr->compression_type = (png_byte)compression_type;
  177919. png_ptr->width = width;
  177920. png_ptr->height = height;
  177921. png_ptr->pixel_depth = (png_byte)(bit_depth * png_ptr->channels);
  177922. png_ptr->rowbytes = PNG_ROWBYTES(png_ptr->pixel_depth, width);
  177923. png_ptr->usr_width = png_ptr->width;
  177924. png_ptr->usr_bit_depth = png_ptr->bit_depth;
  177925. png_ptr->usr_channels = png_ptr->channels;
  177926. png_save_uint_32(buf, width);
  177927. png_save_uint_32(buf + 4, height);
  177928. buf[8] = (png_byte)bit_depth;
  177929. buf[9] = (png_byte)color_type;
  177930. buf[10] = (png_byte)compression_type;
  177931. buf[11] = (png_byte)filter_type;
  177932. buf[12] = (png_byte)interlace_type;
  177933. png_write_chunk(png_ptr, png_IHDR, buf, (png_size_t)13);
  177934. png_ptr->zstream.zalloc = png_zalloc;
  177935. png_ptr->zstream.zfree = png_zfree;
  177936. png_ptr->zstream.opaque = (voidpf)png_ptr;
  177937. if (!(png_ptr->do_filter))
  177938. {
  177939. if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE ||
  177940. png_ptr->bit_depth < 8)
  177941. png_ptr->do_filter = PNG_FILTER_NONE;
  177942. else
  177943. png_ptr->do_filter = PNG_ALL_FILTERS;
  177944. }
  177945. if (!(png_ptr->flags & PNG_FLAG_ZLIB_CUSTOM_STRATEGY))
  177946. {
  177947. if (png_ptr->do_filter != PNG_FILTER_NONE)
  177948. png_ptr->zlib_strategy = Z_FILTERED;
  177949. else
  177950. png_ptr->zlib_strategy = Z_DEFAULT_STRATEGY;
  177951. }
  177952. if (!(png_ptr->flags & PNG_FLAG_ZLIB_CUSTOM_LEVEL))
  177953. png_ptr->zlib_level = Z_DEFAULT_COMPRESSION;
  177954. if (!(png_ptr->flags & PNG_FLAG_ZLIB_CUSTOM_MEM_LEVEL))
  177955. png_ptr->zlib_mem_level = 8;
  177956. if (!(png_ptr->flags & PNG_FLAG_ZLIB_CUSTOM_WINDOW_BITS))
  177957. png_ptr->zlib_window_bits = 15;
  177958. if (!(png_ptr->flags & PNG_FLAG_ZLIB_CUSTOM_METHOD))
  177959. png_ptr->zlib_method = 8;
  177960. if (deflateInit2(&png_ptr->zstream, png_ptr->zlib_level,
  177961. png_ptr->zlib_method, png_ptr->zlib_window_bits,
  177962. png_ptr->zlib_mem_level, png_ptr->zlib_strategy) != Z_OK)
  177963. png_error(png_ptr, "zlib failed to initialize compressor");
  177964. png_ptr->zstream.next_out = png_ptr->zbuf;
  177965. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  177966. png_ptr->zstream.data_type = Z_BINARY;
  177967. png_ptr->mode = PNG_HAVE_IHDR;
  177968. }
  177969. void /* PRIVATE */
  177970. png_write_PLTE(png_structp png_ptr, png_colorp palette, png_uint_32 num_pal)
  177971. {
  177972. #ifdef PNG_USE_LOCAL_ARRAYS
  177973. PNG_PLTE;
  177974. #endif
  177975. png_uint_32 i;
  177976. png_colorp pal_ptr;
  177977. png_byte buf[3];
  177978. png_debug(1, "in png_write_PLTE\n");
  177979. if ((
  177980. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  177981. !(png_ptr->mng_features_permitted & PNG_FLAG_MNG_EMPTY_PLTE) &&
  177982. #endif
  177983. num_pal == 0) || num_pal > 256)
  177984. {
  177985. if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  177986. {
  177987. png_error(png_ptr, "Invalid number of colors in palette");
  177988. }
  177989. else
  177990. {
  177991. png_warning(png_ptr, "Invalid number of colors in palette");
  177992. return;
  177993. }
  177994. }
  177995. if (!(png_ptr->color_type&PNG_COLOR_MASK_COLOR))
  177996. {
  177997. png_warning(png_ptr,
  177998. "Ignoring request to write a PLTE chunk in grayscale PNG");
  177999. return;
  178000. }
  178001. png_ptr->num_palette = (png_uint_16)num_pal;
  178002. png_debug1(3, "num_palette = %d\n", png_ptr->num_palette);
  178003. png_write_chunk_start(png_ptr, png_PLTE, num_pal * 3);
  178004. #ifndef PNG_NO_POINTER_INDEXING
  178005. for (i = 0, pal_ptr = palette; i < num_pal; i++, pal_ptr++)
  178006. {
  178007. buf[0] = pal_ptr->red;
  178008. buf[1] = pal_ptr->green;
  178009. buf[2] = pal_ptr->blue;
  178010. png_write_chunk_data(png_ptr, buf, (png_size_t)3);
  178011. }
  178012. #else
  178013. pal_ptr=palette;
  178014. for (i = 0; i < num_pal; i++)
  178015. {
  178016. buf[0] = pal_ptr[i].red;
  178017. buf[1] = pal_ptr[i].green;
  178018. buf[2] = pal_ptr[i].blue;
  178019. png_write_chunk_data(png_ptr, buf, (png_size_t)3);
  178020. }
  178021. #endif
  178022. png_write_chunk_end(png_ptr);
  178023. png_ptr->mode |= PNG_HAVE_PLTE;
  178024. }
  178025. void /* PRIVATE */
  178026. png_write_IDAT(png_structp png_ptr, png_bytep data, png_size_t length)
  178027. {
  178028. #ifdef PNG_USE_LOCAL_ARRAYS
  178029. PNG_IDAT;
  178030. #endif
  178031. png_debug(1, "in png_write_IDAT\n");
  178032. if (!(png_ptr->mode & PNG_HAVE_IDAT) &&
  178033. png_ptr->compression_type == PNG_COMPRESSION_TYPE_BASE)
  178034. {
  178035. unsigned int z_cmf = data[0]; /* zlib compression method and flags */
  178036. if ((z_cmf & 0x0f) == 8 && (z_cmf & 0xf0) <= 0x70)
  178037. {
  178038. if (length >= 2 &&
  178039. png_ptr->height < 16384 && png_ptr->width < 16384)
  178040. {
  178041. png_uint_32 uncompressed_idat_size = png_ptr->height *
  178042. ((png_ptr->width *
  178043. png_ptr->channels * png_ptr->bit_depth + 15) >> 3);
  178044. unsigned int z_cinfo = z_cmf >> 4;
  178045. unsigned int half_z_window_size = 1 << (z_cinfo + 7);
  178046. while (uncompressed_idat_size <= half_z_window_size &&
  178047. half_z_window_size >= 256)
  178048. {
  178049. z_cinfo--;
  178050. half_z_window_size >>= 1;
  178051. }
  178052. z_cmf = (z_cmf & 0x0f) | (z_cinfo << 4);
  178053. if (data[0] != (png_byte)z_cmf)
  178054. {
  178055. data[0] = (png_byte)z_cmf;
  178056. data[1] &= 0xe0;
  178057. data[1] += (png_byte)(0x1f - ((z_cmf << 8) + data[1]) % 0x1f);
  178058. }
  178059. }
  178060. }
  178061. else
  178062. png_error(png_ptr,
  178063. "Invalid zlib compression method or flags in IDAT");
  178064. }
  178065. png_write_chunk(png_ptr, png_IDAT, data, length);
  178066. png_ptr->mode |= PNG_HAVE_IDAT;
  178067. }
  178068. void /* PRIVATE */
  178069. png_write_IEND(png_structp png_ptr)
  178070. {
  178071. #ifdef PNG_USE_LOCAL_ARRAYS
  178072. PNG_IEND;
  178073. #endif
  178074. png_debug(1, "in png_write_IEND\n");
  178075. png_write_chunk(png_ptr, png_IEND, png_bytep_NULL,
  178076. (png_size_t)0);
  178077. png_ptr->mode |= PNG_HAVE_IEND;
  178078. }
  178079. #if defined(PNG_WRITE_gAMA_SUPPORTED)
  178080. #ifdef PNG_FLOATING_POINT_SUPPORTED
  178081. void /* PRIVATE */
  178082. png_write_gAMA(png_structp png_ptr, double file_gamma)
  178083. {
  178084. #ifdef PNG_USE_LOCAL_ARRAYS
  178085. PNG_gAMA;
  178086. #endif
  178087. png_uint_32 igamma;
  178088. png_byte buf[4];
  178089. png_debug(1, "in png_write_gAMA\n");
  178090. igamma = (png_uint_32)(file_gamma * 100000.0 + 0.5);
  178091. png_save_uint_32(buf, igamma);
  178092. png_write_chunk(png_ptr, png_gAMA, buf, (png_size_t)4);
  178093. }
  178094. #endif
  178095. #ifdef PNG_FIXED_POINT_SUPPORTED
  178096. void /* PRIVATE */
  178097. png_write_gAMA_fixed(png_structp png_ptr, png_fixed_point file_gamma)
  178098. {
  178099. #ifdef PNG_USE_LOCAL_ARRAYS
  178100. PNG_gAMA;
  178101. #endif
  178102. png_byte buf[4];
  178103. png_debug(1, "in png_write_gAMA\n");
  178104. png_save_uint_32(buf, (png_uint_32)file_gamma);
  178105. png_write_chunk(png_ptr, png_gAMA, buf, (png_size_t)4);
  178106. }
  178107. #endif
  178108. #endif
  178109. #if defined(PNG_WRITE_sRGB_SUPPORTED)
  178110. void /* PRIVATE */
  178111. png_write_sRGB(png_structp png_ptr, int srgb_intent)
  178112. {
  178113. #ifdef PNG_USE_LOCAL_ARRAYS
  178114. PNG_sRGB;
  178115. #endif
  178116. png_byte buf[1];
  178117. png_debug(1, "in png_write_sRGB\n");
  178118. if(srgb_intent >= PNG_sRGB_INTENT_LAST)
  178119. png_warning(png_ptr,
  178120. "Invalid sRGB rendering intent specified");
  178121. buf[0]=(png_byte)srgb_intent;
  178122. png_write_chunk(png_ptr, png_sRGB, buf, (png_size_t)1);
  178123. }
  178124. #endif
  178125. #if defined(PNG_WRITE_iCCP_SUPPORTED)
  178126. void /* PRIVATE */
  178127. png_write_iCCP(png_structp png_ptr, png_charp name, int compression_type,
  178128. png_charp profile, int profile_len)
  178129. {
  178130. #ifdef PNG_USE_LOCAL_ARRAYS
  178131. PNG_iCCP;
  178132. #endif
  178133. png_size_t name_len;
  178134. png_charp new_name;
  178135. compression_state comp;
  178136. int embedded_profile_len = 0;
  178137. png_debug(1, "in png_write_iCCP\n");
  178138. comp.num_output_ptr = 0;
  178139. comp.max_output_ptr = 0;
  178140. comp.output_ptr = NULL;
  178141. comp.input = NULL;
  178142. comp.input_len = 0;
  178143. if (name == NULL || (name_len = png_check_keyword(png_ptr, name,
  178144. &new_name)) == 0)
  178145. {
  178146. png_warning(png_ptr, "Empty keyword in iCCP chunk");
  178147. return;
  178148. }
  178149. if (compression_type != PNG_COMPRESSION_TYPE_BASE)
  178150. png_warning(png_ptr, "Unknown compression type in iCCP chunk");
  178151. if (profile == NULL)
  178152. profile_len = 0;
  178153. if (profile_len > 3)
  178154. embedded_profile_len =
  178155. ((*( (png_bytep)profile ))<<24) |
  178156. ((*( (png_bytep)profile+1))<<16) |
  178157. ((*( (png_bytep)profile+2))<< 8) |
  178158. ((*( (png_bytep)profile+3)) );
  178159. if (profile_len < embedded_profile_len)
  178160. {
  178161. png_warning(png_ptr,
  178162. "Embedded profile length too large in iCCP chunk");
  178163. return;
  178164. }
  178165. if (profile_len > embedded_profile_len)
  178166. {
  178167. png_warning(png_ptr,
  178168. "Truncating profile to actual length in iCCP chunk");
  178169. profile_len = embedded_profile_len;
  178170. }
  178171. if (profile_len)
  178172. profile_len = png_text_compress(png_ptr, profile, (png_size_t)profile_len,
  178173. PNG_COMPRESSION_TYPE_BASE, &comp);
  178174. png_write_chunk_start(png_ptr, png_iCCP,
  178175. (png_uint_32)name_len+profile_len+2);
  178176. new_name[name_len+1]=0x00;
  178177. png_write_chunk_data(png_ptr, (png_bytep)new_name, name_len + 2);
  178178. if (profile_len)
  178179. png_write_compressed_data_out(png_ptr, &comp);
  178180. png_write_chunk_end(png_ptr);
  178181. png_free(png_ptr, new_name);
  178182. }
  178183. #endif
  178184. #if defined(PNG_WRITE_sPLT_SUPPORTED)
  178185. void /* PRIVATE */
  178186. png_write_sPLT(png_structp png_ptr, png_sPLT_tp spalette)
  178187. {
  178188. #ifdef PNG_USE_LOCAL_ARRAYS
  178189. PNG_sPLT;
  178190. #endif
  178191. png_size_t name_len;
  178192. png_charp new_name;
  178193. png_byte entrybuf[10];
  178194. int entry_size = (spalette->depth == 8 ? 6 : 10);
  178195. int palette_size = entry_size * spalette->nentries;
  178196. png_sPLT_entryp ep;
  178197. #ifdef PNG_NO_POINTER_INDEXING
  178198. int i;
  178199. #endif
  178200. png_debug(1, "in png_write_sPLT\n");
  178201. if (spalette->name == NULL || (name_len = png_check_keyword(png_ptr,
  178202. spalette->name, &new_name))==0)
  178203. {
  178204. png_warning(png_ptr, "Empty keyword in sPLT chunk");
  178205. return;
  178206. }
  178207. png_write_chunk_start(png_ptr, png_sPLT,
  178208. (png_uint_32)(name_len + 2 + palette_size));
  178209. png_write_chunk_data(png_ptr, (png_bytep)new_name, name_len + 1);
  178210. png_write_chunk_data(png_ptr, (png_bytep)&spalette->depth, 1);
  178211. #ifndef PNG_NO_POINTER_INDEXING
  178212. for (ep = spalette->entries; ep<spalette->entries+spalette->nentries; ep++)
  178213. {
  178214. if (spalette->depth == 8)
  178215. {
  178216. entrybuf[0] = (png_byte)ep->red;
  178217. entrybuf[1] = (png_byte)ep->green;
  178218. entrybuf[2] = (png_byte)ep->blue;
  178219. entrybuf[3] = (png_byte)ep->alpha;
  178220. png_save_uint_16(entrybuf + 4, ep->frequency);
  178221. }
  178222. else
  178223. {
  178224. png_save_uint_16(entrybuf + 0, ep->red);
  178225. png_save_uint_16(entrybuf + 2, ep->green);
  178226. png_save_uint_16(entrybuf + 4, ep->blue);
  178227. png_save_uint_16(entrybuf + 6, ep->alpha);
  178228. png_save_uint_16(entrybuf + 8, ep->frequency);
  178229. }
  178230. png_write_chunk_data(png_ptr, entrybuf, (png_size_t)entry_size);
  178231. }
  178232. #else
  178233. ep=spalette->entries;
  178234. for (i=0; i>spalette->nentries; i++)
  178235. {
  178236. if (spalette->depth == 8)
  178237. {
  178238. entrybuf[0] = (png_byte)ep[i].red;
  178239. entrybuf[1] = (png_byte)ep[i].green;
  178240. entrybuf[2] = (png_byte)ep[i].blue;
  178241. entrybuf[3] = (png_byte)ep[i].alpha;
  178242. png_save_uint_16(entrybuf + 4, ep[i].frequency);
  178243. }
  178244. else
  178245. {
  178246. png_save_uint_16(entrybuf + 0, ep[i].red);
  178247. png_save_uint_16(entrybuf + 2, ep[i].green);
  178248. png_save_uint_16(entrybuf + 4, ep[i].blue);
  178249. png_save_uint_16(entrybuf + 6, ep[i].alpha);
  178250. png_save_uint_16(entrybuf + 8, ep[i].frequency);
  178251. }
  178252. png_write_chunk_data(png_ptr, entrybuf, entry_size);
  178253. }
  178254. #endif
  178255. png_write_chunk_end(png_ptr);
  178256. png_free(png_ptr, new_name);
  178257. }
  178258. #endif
  178259. #if defined(PNG_WRITE_sBIT_SUPPORTED)
  178260. void /* PRIVATE */
  178261. png_write_sBIT(png_structp png_ptr, png_color_8p sbit, int color_type)
  178262. {
  178263. #ifdef PNG_USE_LOCAL_ARRAYS
  178264. PNG_sBIT;
  178265. #endif
  178266. png_byte buf[4];
  178267. png_size_t size;
  178268. png_debug(1, "in png_write_sBIT\n");
  178269. if (color_type & PNG_COLOR_MASK_COLOR)
  178270. {
  178271. png_byte maxbits;
  178272. maxbits = (png_byte)(color_type==PNG_COLOR_TYPE_PALETTE ? 8 :
  178273. png_ptr->usr_bit_depth);
  178274. if (sbit->red == 0 || sbit->red > maxbits ||
  178275. sbit->green == 0 || sbit->green > maxbits ||
  178276. sbit->blue == 0 || sbit->blue > maxbits)
  178277. {
  178278. png_warning(png_ptr, "Invalid sBIT depth specified");
  178279. return;
  178280. }
  178281. buf[0] = sbit->red;
  178282. buf[1] = sbit->green;
  178283. buf[2] = sbit->blue;
  178284. size = 3;
  178285. }
  178286. else
  178287. {
  178288. if (sbit->gray == 0 || sbit->gray > png_ptr->usr_bit_depth)
  178289. {
  178290. png_warning(png_ptr, "Invalid sBIT depth specified");
  178291. return;
  178292. }
  178293. buf[0] = sbit->gray;
  178294. size = 1;
  178295. }
  178296. if (color_type & PNG_COLOR_MASK_ALPHA)
  178297. {
  178298. if (sbit->alpha == 0 || sbit->alpha > png_ptr->usr_bit_depth)
  178299. {
  178300. png_warning(png_ptr, "Invalid sBIT depth specified");
  178301. return;
  178302. }
  178303. buf[size++] = sbit->alpha;
  178304. }
  178305. png_write_chunk(png_ptr, png_sBIT, buf, size);
  178306. }
  178307. #endif
  178308. #if defined(PNG_WRITE_cHRM_SUPPORTED)
  178309. #ifdef PNG_FLOATING_POINT_SUPPORTED
  178310. void /* PRIVATE */
  178311. png_write_cHRM(png_structp png_ptr, double white_x, double white_y,
  178312. double red_x, double red_y, double green_x, double green_y,
  178313. double blue_x, double blue_y)
  178314. {
  178315. #ifdef PNG_USE_LOCAL_ARRAYS
  178316. PNG_cHRM;
  178317. #endif
  178318. png_byte buf[32];
  178319. png_uint_32 itemp;
  178320. png_debug(1, "in png_write_cHRM\n");
  178321. if (white_x < 0 || white_x > 0.8 || white_y < 0 || white_y > 0.8 ||
  178322. white_x + white_y > 1.0)
  178323. {
  178324. png_warning(png_ptr, "Invalid cHRM white point specified");
  178325. #if !defined(PNG_NO_CONSOLE_IO)
  178326. fprintf(stderr,"white_x=%f, white_y=%f\n",white_x, white_y);
  178327. #endif
  178328. return;
  178329. }
  178330. itemp = (png_uint_32)(white_x * 100000.0 + 0.5);
  178331. png_save_uint_32(buf, itemp);
  178332. itemp = (png_uint_32)(white_y * 100000.0 + 0.5);
  178333. png_save_uint_32(buf + 4, itemp);
  178334. if (red_x < 0 || red_y < 0 || red_x + red_y > 1.0)
  178335. {
  178336. png_warning(png_ptr, "Invalid cHRM red point specified");
  178337. return;
  178338. }
  178339. itemp = (png_uint_32)(red_x * 100000.0 + 0.5);
  178340. png_save_uint_32(buf + 8, itemp);
  178341. itemp = (png_uint_32)(red_y * 100000.0 + 0.5);
  178342. png_save_uint_32(buf + 12, itemp);
  178343. if (green_x < 0 || green_y < 0 || green_x + green_y > 1.0)
  178344. {
  178345. png_warning(png_ptr, "Invalid cHRM green point specified");
  178346. return;
  178347. }
  178348. itemp = (png_uint_32)(green_x * 100000.0 + 0.5);
  178349. png_save_uint_32(buf + 16, itemp);
  178350. itemp = (png_uint_32)(green_y * 100000.0 + 0.5);
  178351. png_save_uint_32(buf + 20, itemp);
  178352. if (blue_x < 0 || blue_y < 0 || blue_x + blue_y > 1.0)
  178353. {
  178354. png_warning(png_ptr, "Invalid cHRM blue point specified");
  178355. return;
  178356. }
  178357. itemp = (png_uint_32)(blue_x * 100000.0 + 0.5);
  178358. png_save_uint_32(buf + 24, itemp);
  178359. itemp = (png_uint_32)(blue_y * 100000.0 + 0.5);
  178360. png_save_uint_32(buf + 28, itemp);
  178361. png_write_chunk(png_ptr, png_cHRM, buf, (png_size_t)32);
  178362. }
  178363. #endif
  178364. #ifdef PNG_FIXED_POINT_SUPPORTED
  178365. void /* PRIVATE */
  178366. png_write_cHRM_fixed(png_structp png_ptr, png_fixed_point white_x,
  178367. png_fixed_point white_y, png_fixed_point red_x, png_fixed_point red_y,
  178368. png_fixed_point green_x, png_fixed_point green_y, png_fixed_point blue_x,
  178369. png_fixed_point blue_y)
  178370. {
  178371. #ifdef PNG_USE_LOCAL_ARRAYS
  178372. PNG_cHRM;
  178373. #endif
  178374. png_byte buf[32];
  178375. png_debug(1, "in png_write_cHRM\n");
  178376. if (white_x > 80000L || white_y > 80000L || white_x + white_y > 100000L)
  178377. {
  178378. png_warning(png_ptr, "Invalid fixed cHRM white point specified");
  178379. #if !defined(PNG_NO_CONSOLE_IO)
  178380. fprintf(stderr,"white_x=%ld, white_y=%ld\n",white_x, white_y);
  178381. #endif
  178382. return;
  178383. }
  178384. png_save_uint_32(buf, (png_uint_32)white_x);
  178385. png_save_uint_32(buf + 4, (png_uint_32)white_y);
  178386. if (red_x + red_y > 100000L)
  178387. {
  178388. png_warning(png_ptr, "Invalid cHRM fixed red point specified");
  178389. return;
  178390. }
  178391. png_save_uint_32(buf + 8, (png_uint_32)red_x);
  178392. png_save_uint_32(buf + 12, (png_uint_32)red_y);
  178393. if (green_x + green_y > 100000L)
  178394. {
  178395. png_warning(png_ptr, "Invalid fixed cHRM green point specified");
  178396. return;
  178397. }
  178398. png_save_uint_32(buf + 16, (png_uint_32)green_x);
  178399. png_save_uint_32(buf + 20, (png_uint_32)green_y);
  178400. if (blue_x + blue_y > 100000L)
  178401. {
  178402. png_warning(png_ptr, "Invalid fixed cHRM blue point specified");
  178403. return;
  178404. }
  178405. png_save_uint_32(buf + 24, (png_uint_32)blue_x);
  178406. png_save_uint_32(buf + 28, (png_uint_32)blue_y);
  178407. png_write_chunk(png_ptr, png_cHRM, buf, (png_size_t)32);
  178408. }
  178409. #endif
  178410. #endif
  178411. #if defined(PNG_WRITE_tRNS_SUPPORTED)
  178412. void /* PRIVATE */
  178413. png_write_tRNS(png_structp png_ptr, png_bytep trans, png_color_16p tran,
  178414. int num_trans, int color_type)
  178415. {
  178416. #ifdef PNG_USE_LOCAL_ARRAYS
  178417. PNG_tRNS;
  178418. #endif
  178419. png_byte buf[6];
  178420. png_debug(1, "in png_write_tRNS\n");
  178421. if (color_type == PNG_COLOR_TYPE_PALETTE)
  178422. {
  178423. if (num_trans <= 0 || num_trans > (int)png_ptr->num_palette)
  178424. {
  178425. png_warning(png_ptr,"Invalid number of transparent colors specified");
  178426. return;
  178427. }
  178428. png_write_chunk(png_ptr, png_tRNS, trans, (png_size_t)num_trans);
  178429. }
  178430. else if (color_type == PNG_COLOR_TYPE_GRAY)
  178431. {
  178432. if(tran->gray >= (1 << png_ptr->bit_depth))
  178433. {
  178434. png_warning(png_ptr,
  178435. "Ignoring attempt to write tRNS chunk out-of-range for bit_depth");
  178436. return;
  178437. }
  178438. png_save_uint_16(buf, tran->gray);
  178439. png_write_chunk(png_ptr, png_tRNS, buf, (png_size_t)2);
  178440. }
  178441. else if (color_type == PNG_COLOR_TYPE_RGB)
  178442. {
  178443. png_save_uint_16(buf, tran->red);
  178444. png_save_uint_16(buf + 2, tran->green);
  178445. png_save_uint_16(buf + 4, tran->blue);
  178446. if(png_ptr->bit_depth == 8 && (buf[0] | buf[2] | buf[4]))
  178447. {
  178448. png_warning(png_ptr,
  178449. "Ignoring attempt to write 16-bit tRNS chunk when bit_depth is 8");
  178450. return;
  178451. }
  178452. png_write_chunk(png_ptr, png_tRNS, buf, (png_size_t)6);
  178453. }
  178454. else
  178455. {
  178456. png_warning(png_ptr, "Can't write tRNS with an alpha channel");
  178457. }
  178458. }
  178459. #endif
  178460. #if defined(PNG_WRITE_bKGD_SUPPORTED)
  178461. void /* PRIVATE */
  178462. png_write_bKGD(png_structp png_ptr, png_color_16p back, int color_type)
  178463. {
  178464. #ifdef PNG_USE_LOCAL_ARRAYS
  178465. PNG_bKGD;
  178466. #endif
  178467. png_byte buf[6];
  178468. png_debug(1, "in png_write_bKGD\n");
  178469. if (color_type == PNG_COLOR_TYPE_PALETTE)
  178470. {
  178471. if (
  178472. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  178473. (png_ptr->num_palette ||
  178474. (!(png_ptr->mng_features_permitted & PNG_FLAG_MNG_EMPTY_PLTE))) &&
  178475. #endif
  178476. back->index > png_ptr->num_palette)
  178477. {
  178478. png_warning(png_ptr, "Invalid background palette index");
  178479. return;
  178480. }
  178481. buf[0] = back->index;
  178482. png_write_chunk(png_ptr, png_bKGD, buf, (png_size_t)1);
  178483. }
  178484. else if (color_type & PNG_COLOR_MASK_COLOR)
  178485. {
  178486. png_save_uint_16(buf, back->red);
  178487. png_save_uint_16(buf + 2, back->green);
  178488. png_save_uint_16(buf + 4, back->blue);
  178489. if(png_ptr->bit_depth == 8 && (buf[0] | buf[2] | buf[4]))
  178490. {
  178491. png_warning(png_ptr,
  178492. "Ignoring attempt to write 16-bit bKGD chunk when bit_depth is 8");
  178493. return;
  178494. }
  178495. png_write_chunk(png_ptr, png_bKGD, buf, (png_size_t)6);
  178496. }
  178497. else
  178498. {
  178499. if(back->gray >= (1 << png_ptr->bit_depth))
  178500. {
  178501. png_warning(png_ptr,
  178502. "Ignoring attempt to write bKGD chunk out-of-range for bit_depth");
  178503. return;
  178504. }
  178505. png_save_uint_16(buf, back->gray);
  178506. png_write_chunk(png_ptr, png_bKGD, buf, (png_size_t)2);
  178507. }
  178508. }
  178509. #endif
  178510. #if defined(PNG_WRITE_hIST_SUPPORTED)
  178511. void /* PRIVATE */
  178512. png_write_hIST(png_structp png_ptr, png_uint_16p hist, int num_hist)
  178513. {
  178514. #ifdef PNG_USE_LOCAL_ARRAYS
  178515. PNG_hIST;
  178516. #endif
  178517. int i;
  178518. png_byte buf[3];
  178519. png_debug(1, "in png_write_hIST\n");
  178520. if (num_hist > (int)png_ptr->num_palette)
  178521. {
  178522. png_debug2(3, "num_hist = %d, num_palette = %d\n", num_hist,
  178523. png_ptr->num_palette);
  178524. png_warning(png_ptr, "Invalid number of histogram entries specified");
  178525. return;
  178526. }
  178527. png_write_chunk_start(png_ptr, png_hIST, (png_uint_32)(num_hist * 2));
  178528. for (i = 0; i < num_hist; i++)
  178529. {
  178530. png_save_uint_16(buf, hist[i]);
  178531. png_write_chunk_data(png_ptr, buf, (png_size_t)2);
  178532. }
  178533. png_write_chunk_end(png_ptr);
  178534. }
  178535. #endif
  178536. #if defined(PNG_WRITE_TEXT_SUPPORTED) || defined(PNG_WRITE_pCAL_SUPPORTED) || \
  178537. defined(PNG_WRITE_iCCP_SUPPORTED) || defined(PNG_WRITE_sPLT_SUPPORTED)
  178538. png_size_t /* PRIVATE */
  178539. png_check_keyword(png_structp png_ptr, png_charp key, png_charpp new_key)
  178540. {
  178541. png_size_t key_len;
  178542. png_charp kp, dp;
  178543. int kflag;
  178544. int kwarn=0;
  178545. png_debug(1, "in png_check_keyword\n");
  178546. *new_key = NULL;
  178547. if (key == NULL || (key_len = png_strlen(key)) == 0)
  178548. {
  178549. png_warning(png_ptr, "zero length keyword");
  178550. return ((png_size_t)0);
  178551. }
  178552. png_debug1(2, "Keyword to be checked is '%s'\n", key);
  178553. *new_key = (png_charp)png_malloc_warn(png_ptr, (png_uint_32)(key_len + 2));
  178554. if (*new_key == NULL)
  178555. {
  178556. png_warning(png_ptr, "Out of memory while procesing keyword");
  178557. return ((png_size_t)0);
  178558. }
  178559. for (kp = key, dp = *new_key; *kp != '\0'; kp++, dp++)
  178560. {
  178561. if ((png_byte)*kp < 0x20 ||
  178562. ((png_byte)*kp > 0x7E && (png_byte)*kp < 0xA1))
  178563. {
  178564. #if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE)
  178565. char msg[40];
  178566. png_snprintf(msg, 40,
  178567. "invalid keyword character 0x%02X", (png_byte)*kp);
  178568. png_warning(png_ptr, msg);
  178569. #else
  178570. png_warning(png_ptr, "invalid character in keyword");
  178571. #endif
  178572. *dp = ' ';
  178573. }
  178574. else
  178575. {
  178576. *dp = *kp;
  178577. }
  178578. }
  178579. *dp = '\0';
  178580. kp = *new_key + key_len - 1;
  178581. if (*kp == ' ')
  178582. {
  178583. png_warning(png_ptr, "trailing spaces removed from keyword");
  178584. while (*kp == ' ')
  178585. {
  178586. *(kp--) = '\0';
  178587. key_len--;
  178588. }
  178589. }
  178590. kp = *new_key;
  178591. if (*kp == ' ')
  178592. {
  178593. png_warning(png_ptr, "leading spaces removed from keyword");
  178594. while (*kp == ' ')
  178595. {
  178596. kp++;
  178597. key_len--;
  178598. }
  178599. }
  178600. png_debug1(2, "Checking for multiple internal spaces in '%s'\n", kp);
  178601. for (kflag = 0, dp = *new_key; *kp != '\0'; kp++)
  178602. {
  178603. if (*kp == ' ' && kflag == 0)
  178604. {
  178605. *(dp++) = *kp;
  178606. kflag = 1;
  178607. }
  178608. else if (*kp == ' ')
  178609. {
  178610. key_len--;
  178611. kwarn=1;
  178612. }
  178613. else
  178614. {
  178615. *(dp++) = *kp;
  178616. kflag = 0;
  178617. }
  178618. }
  178619. *dp = '\0';
  178620. if(kwarn)
  178621. png_warning(png_ptr, "extra interior spaces removed from keyword");
  178622. if (key_len == 0)
  178623. {
  178624. png_free(png_ptr, *new_key);
  178625. *new_key=NULL;
  178626. png_warning(png_ptr, "Zero length keyword");
  178627. }
  178628. if (key_len > 79)
  178629. {
  178630. png_warning(png_ptr, "keyword length must be 1 - 79 characters");
  178631. new_key[79] = '\0';
  178632. key_len = 79;
  178633. }
  178634. return (key_len);
  178635. }
  178636. #endif
  178637. #if defined(PNG_WRITE_tEXt_SUPPORTED)
  178638. void /* PRIVATE */
  178639. png_write_tEXt(png_structp png_ptr, png_charp key, png_charp text,
  178640. png_size_t text_len)
  178641. {
  178642. #ifdef PNG_USE_LOCAL_ARRAYS
  178643. PNG_tEXt;
  178644. #endif
  178645. png_size_t key_len;
  178646. png_charp new_key;
  178647. png_debug(1, "in png_write_tEXt\n");
  178648. if (key == NULL || (key_len = png_check_keyword(png_ptr, key, &new_key))==0)
  178649. {
  178650. png_warning(png_ptr, "Empty keyword in tEXt chunk");
  178651. return;
  178652. }
  178653. if (text == NULL || *text == '\0')
  178654. text_len = 0;
  178655. else
  178656. text_len = png_strlen(text);
  178657. png_write_chunk_start(png_ptr, png_tEXt, (png_uint_32)key_len+text_len+1);
  178658. png_write_chunk_data(png_ptr, (png_bytep)new_key, key_len + 1);
  178659. if (text_len)
  178660. png_write_chunk_data(png_ptr, (png_bytep)text, text_len);
  178661. png_write_chunk_end(png_ptr);
  178662. png_free(png_ptr, new_key);
  178663. }
  178664. #endif
  178665. #if defined(PNG_WRITE_zTXt_SUPPORTED)
  178666. void /* PRIVATE */
  178667. png_write_zTXt(png_structp png_ptr, png_charp key, png_charp text,
  178668. png_size_t text_len, int compression)
  178669. {
  178670. #ifdef PNG_USE_LOCAL_ARRAYS
  178671. PNG_zTXt;
  178672. #endif
  178673. png_size_t key_len;
  178674. char buf[1];
  178675. png_charp new_key;
  178676. compression_state comp;
  178677. png_debug(1, "in png_write_zTXt\n");
  178678. comp.num_output_ptr = 0;
  178679. comp.max_output_ptr = 0;
  178680. comp.output_ptr = NULL;
  178681. comp.input = NULL;
  178682. comp.input_len = 0;
  178683. if (key == NULL || (key_len = png_check_keyword(png_ptr, key, &new_key))==0)
  178684. {
  178685. png_warning(png_ptr, "Empty keyword in zTXt chunk");
  178686. return;
  178687. }
  178688. if (text == NULL || *text == '\0' || compression==PNG_TEXT_COMPRESSION_NONE)
  178689. {
  178690. png_write_tEXt(png_ptr, new_key, text, (png_size_t)0);
  178691. png_free(png_ptr, new_key);
  178692. return;
  178693. }
  178694. text_len = png_strlen(text);
  178695. text_len = png_text_compress(png_ptr, text, text_len, compression,
  178696. &comp);
  178697. png_write_chunk_start(png_ptr, png_zTXt, (png_uint_32)
  178698. (key_len+text_len+2));
  178699. png_write_chunk_data(png_ptr, (png_bytep)new_key, key_len + 1);
  178700. png_free(png_ptr, new_key);
  178701. buf[0] = (png_byte)compression;
  178702. png_write_chunk_data(png_ptr, (png_bytep)buf, (png_size_t)1);
  178703. png_write_compressed_data_out(png_ptr, &comp);
  178704. png_write_chunk_end(png_ptr);
  178705. }
  178706. #endif
  178707. #if defined(PNG_WRITE_iTXt_SUPPORTED)
  178708. void /* PRIVATE */
  178709. png_write_iTXt(png_structp png_ptr, int compression, png_charp key,
  178710. png_charp lang, png_charp lang_key, png_charp text)
  178711. {
  178712. #ifdef PNG_USE_LOCAL_ARRAYS
  178713. PNG_iTXt;
  178714. #endif
  178715. png_size_t lang_len, key_len, lang_key_len, text_len;
  178716. png_charp new_lang, new_key;
  178717. png_byte cbuf[2];
  178718. compression_state comp;
  178719. png_debug(1, "in png_write_iTXt\n");
  178720. comp.num_output_ptr = 0;
  178721. comp.max_output_ptr = 0;
  178722. comp.output_ptr = NULL;
  178723. comp.input = NULL;
  178724. if (key == NULL || (key_len = png_check_keyword(png_ptr, key, &new_key))==0)
  178725. {
  178726. png_warning(png_ptr, "Empty keyword in iTXt chunk");
  178727. return;
  178728. }
  178729. if (lang == NULL || (lang_len = png_check_keyword(png_ptr, lang, &new_lang))==0)
  178730. {
  178731. png_warning(png_ptr, "Empty language field in iTXt chunk");
  178732. new_lang = NULL;
  178733. lang_len = 0;
  178734. }
  178735. if (lang_key == NULL)
  178736. lang_key_len = 0;
  178737. else
  178738. lang_key_len = png_strlen(lang_key);
  178739. if (text == NULL)
  178740. text_len = 0;
  178741. else
  178742. text_len = png_strlen(text);
  178743. text_len = png_text_compress(png_ptr, text, text_len, compression-2,
  178744. &comp);
  178745. png_write_chunk_start(png_ptr, png_iTXt,
  178746. (png_uint_32)(
  178747. 5 /* comp byte, comp flag, terminators for key, lang and lang_key */
  178748. + key_len
  178749. + lang_len
  178750. + lang_key_len
  178751. + text_len));
  178752. png_write_chunk_data(png_ptr, (png_bytep)new_key, key_len + 1);
  178753. if (compression == PNG_ITXT_COMPRESSION_NONE || \
  178754. compression == PNG_TEXT_COMPRESSION_NONE)
  178755. cbuf[0] = 0;
  178756. else /* compression == PNG_ITXT_COMPRESSION_zTXt */
  178757. cbuf[0] = 1;
  178758. cbuf[1] = 0;
  178759. png_write_chunk_data(png_ptr, cbuf, 2);
  178760. cbuf[0] = 0;
  178761. png_write_chunk_data(png_ptr, (new_lang ? (png_bytep)new_lang : cbuf), lang_len + 1);
  178762. png_write_chunk_data(png_ptr, (lang_key ? (png_bytep)lang_key : cbuf), lang_key_len + 1);
  178763. png_write_compressed_data_out(png_ptr, &comp);
  178764. png_write_chunk_end(png_ptr);
  178765. png_free(png_ptr, new_key);
  178766. if (new_lang)
  178767. png_free(png_ptr, new_lang);
  178768. }
  178769. #endif
  178770. #if defined(PNG_WRITE_oFFs_SUPPORTED)
  178771. void /* PRIVATE */
  178772. png_write_oFFs(png_structp png_ptr, png_int_32 x_offset, png_int_32 y_offset,
  178773. int unit_type)
  178774. {
  178775. #ifdef PNG_USE_LOCAL_ARRAYS
  178776. PNG_oFFs;
  178777. #endif
  178778. png_byte buf[9];
  178779. png_debug(1, "in png_write_oFFs\n");
  178780. if (unit_type >= PNG_OFFSET_LAST)
  178781. png_warning(png_ptr, "Unrecognized unit type for oFFs chunk");
  178782. png_save_int_32(buf, x_offset);
  178783. png_save_int_32(buf + 4, y_offset);
  178784. buf[8] = (png_byte)unit_type;
  178785. png_write_chunk(png_ptr, png_oFFs, buf, (png_size_t)9);
  178786. }
  178787. #endif
  178788. #if defined(PNG_WRITE_pCAL_SUPPORTED)
  178789. void /* PRIVATE */
  178790. png_write_pCAL(png_structp png_ptr, png_charp purpose, png_int_32 X0,
  178791. png_int_32 X1, int type, int nparams, png_charp units, png_charpp params)
  178792. {
  178793. #ifdef PNG_USE_LOCAL_ARRAYS
  178794. PNG_pCAL;
  178795. #endif
  178796. png_size_t purpose_len, units_len, total_len;
  178797. png_uint_32p params_len;
  178798. png_byte buf[10];
  178799. png_charp new_purpose;
  178800. int i;
  178801. png_debug1(1, "in png_write_pCAL (%d parameters)\n", nparams);
  178802. if (type >= PNG_EQUATION_LAST)
  178803. png_warning(png_ptr, "Unrecognized equation type for pCAL chunk");
  178804. purpose_len = png_check_keyword(png_ptr, purpose, &new_purpose) + 1;
  178805. png_debug1(3, "pCAL purpose length = %d\n", (int)purpose_len);
  178806. units_len = png_strlen(units) + (nparams == 0 ? 0 : 1);
  178807. png_debug1(3, "pCAL units length = %d\n", (int)units_len);
  178808. total_len = purpose_len + units_len + 10;
  178809. params_len = (png_uint_32p)png_malloc(png_ptr, (png_uint_32)(nparams
  178810. *png_sizeof(png_uint_32)));
  178811. for (i = 0; i < nparams; i++)
  178812. {
  178813. params_len[i] = png_strlen(params[i]) + (i == nparams - 1 ? 0 : 1);
  178814. png_debug2(3, "pCAL parameter %d length = %lu\n", i, params_len[i]);
  178815. total_len += (png_size_t)params_len[i];
  178816. }
  178817. png_debug1(3, "pCAL total length = %d\n", (int)total_len);
  178818. png_write_chunk_start(png_ptr, png_pCAL, (png_uint_32)total_len);
  178819. png_write_chunk_data(png_ptr, (png_bytep)new_purpose, purpose_len);
  178820. png_save_int_32(buf, X0);
  178821. png_save_int_32(buf + 4, X1);
  178822. buf[8] = (png_byte)type;
  178823. buf[9] = (png_byte)nparams;
  178824. png_write_chunk_data(png_ptr, buf, (png_size_t)10);
  178825. png_write_chunk_data(png_ptr, (png_bytep)units, (png_size_t)units_len);
  178826. png_free(png_ptr, new_purpose);
  178827. for (i = 0; i < nparams; i++)
  178828. {
  178829. png_write_chunk_data(png_ptr, (png_bytep)params[i],
  178830. (png_size_t)params_len[i]);
  178831. }
  178832. png_free(png_ptr, params_len);
  178833. png_write_chunk_end(png_ptr);
  178834. }
  178835. #endif
  178836. #if defined(PNG_WRITE_sCAL_SUPPORTED)
  178837. #if defined(PNG_FLOATING_POINT_SUPPORTED) && !defined(PNG_NO_STDIO)
  178838. void /* PRIVATE */
  178839. png_write_sCAL(png_structp png_ptr, int unit, double width, double height)
  178840. {
  178841. #ifdef PNG_USE_LOCAL_ARRAYS
  178842. PNG_sCAL;
  178843. #endif
  178844. char buf[64];
  178845. png_size_t total_len;
  178846. png_debug(1, "in png_write_sCAL\n");
  178847. buf[0] = (char)unit;
  178848. #if defined(_WIN32_WCE)
  178849. {
  178850. wchar_t wc_buf[32];
  178851. size_t wc_len;
  178852. swprintf(wc_buf, TEXT("%12.12e"), width);
  178853. wc_len = wcslen(wc_buf);
  178854. WideCharToMultiByte(CP_ACP, 0, wc_buf, -1, buf + 1, wc_len, NULL, NULL);
  178855. total_len = wc_len + 2;
  178856. swprintf(wc_buf, TEXT("%12.12e"), height);
  178857. wc_len = wcslen(wc_buf);
  178858. WideCharToMultiByte(CP_ACP, 0, wc_buf, -1, buf + total_len, wc_len,
  178859. NULL, NULL);
  178860. total_len += wc_len;
  178861. }
  178862. #else
  178863. png_snprintf(buf + 1, 63, "%12.12e", width);
  178864. total_len = 1 + png_strlen(buf + 1) + 1;
  178865. png_snprintf(buf + total_len, 64-total_len, "%12.12e", height);
  178866. total_len += png_strlen(buf + total_len);
  178867. #endif
  178868. png_debug1(3, "sCAL total length = %u\n", (unsigned int)total_len);
  178869. png_write_chunk(png_ptr, png_sCAL, (png_bytep)buf, total_len);
  178870. }
  178871. #else
  178872. #ifdef PNG_FIXED_POINT_SUPPORTED
  178873. void /* PRIVATE */
  178874. png_write_sCAL_s(png_structp png_ptr, int unit, png_charp width,
  178875. png_charp height)
  178876. {
  178877. #ifdef PNG_USE_LOCAL_ARRAYS
  178878. PNG_sCAL;
  178879. #endif
  178880. png_byte buf[64];
  178881. png_size_t wlen, hlen, total_len;
  178882. png_debug(1, "in png_write_sCAL_s\n");
  178883. wlen = png_strlen(width);
  178884. hlen = png_strlen(height);
  178885. total_len = wlen + hlen + 2;
  178886. if (total_len > 64)
  178887. {
  178888. png_warning(png_ptr, "Can't write sCAL (buffer too small)");
  178889. return;
  178890. }
  178891. buf[0] = (png_byte)unit;
  178892. png_memcpy(buf + 1, width, wlen + 1); /* append the '\0' here */
  178893. png_memcpy(buf + wlen + 2, height, hlen); /* do NOT append the '\0' here */
  178894. png_debug1(3, "sCAL total length = %u\n", (unsigned int)total_len);
  178895. png_write_chunk(png_ptr, png_sCAL, buf, total_len);
  178896. }
  178897. #endif
  178898. #endif
  178899. #endif
  178900. #if defined(PNG_WRITE_pHYs_SUPPORTED)
  178901. void /* PRIVATE */
  178902. png_write_pHYs(png_structp png_ptr, png_uint_32 x_pixels_per_unit,
  178903. png_uint_32 y_pixels_per_unit,
  178904. int unit_type)
  178905. {
  178906. #ifdef PNG_USE_LOCAL_ARRAYS
  178907. PNG_pHYs;
  178908. #endif
  178909. png_byte buf[9];
  178910. png_debug(1, "in png_write_pHYs\n");
  178911. if (unit_type >= PNG_RESOLUTION_LAST)
  178912. png_warning(png_ptr, "Unrecognized unit type for pHYs chunk");
  178913. png_save_uint_32(buf, x_pixels_per_unit);
  178914. png_save_uint_32(buf + 4, y_pixels_per_unit);
  178915. buf[8] = (png_byte)unit_type;
  178916. png_write_chunk(png_ptr, png_pHYs, buf, (png_size_t)9);
  178917. }
  178918. #endif
  178919. #if defined(PNG_WRITE_tIME_SUPPORTED)
  178920. void /* PRIVATE */
  178921. png_write_tIME(png_structp png_ptr, png_timep mod_time)
  178922. {
  178923. #ifdef PNG_USE_LOCAL_ARRAYS
  178924. PNG_tIME;
  178925. #endif
  178926. png_byte buf[7];
  178927. png_debug(1, "in png_write_tIME\n");
  178928. if (mod_time->month > 12 || mod_time->month < 1 ||
  178929. mod_time->day > 31 || mod_time->day < 1 ||
  178930. mod_time->hour > 23 || mod_time->second > 60)
  178931. {
  178932. png_warning(png_ptr, "Invalid time specified for tIME chunk");
  178933. return;
  178934. }
  178935. png_save_uint_16(buf, mod_time->year);
  178936. buf[2] = mod_time->month;
  178937. buf[3] = mod_time->day;
  178938. buf[4] = mod_time->hour;
  178939. buf[5] = mod_time->minute;
  178940. buf[6] = mod_time->second;
  178941. png_write_chunk(png_ptr, png_tIME, buf, (png_size_t)7);
  178942. }
  178943. #endif
  178944. void /* PRIVATE */
  178945. png_write_start_row(png_structp png_ptr)
  178946. {
  178947. #ifdef PNG_WRITE_INTERLACING_SUPPORTED
  178948. #ifdef PNG_USE_LOCAL_ARRAYS
  178949. int png_pass_start[7] = {0, 4, 0, 2, 0, 1, 0};
  178950. int png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1};
  178951. int png_pass_ystart[7] = {0, 0, 4, 0, 2, 0, 1};
  178952. int png_pass_yinc[7] = {8, 8, 8, 4, 4, 2, 2};
  178953. #endif
  178954. #endif
  178955. png_size_t buf_size;
  178956. png_debug(1, "in png_write_start_row\n");
  178957. buf_size = (png_size_t)(PNG_ROWBYTES(
  178958. png_ptr->usr_channels*png_ptr->usr_bit_depth,png_ptr->width)+1);
  178959. png_ptr->row_buf = (png_bytep)png_malloc(png_ptr, (png_uint_32)buf_size);
  178960. png_ptr->row_buf[0] = PNG_FILTER_VALUE_NONE;
  178961. #ifndef PNG_NO_WRITE_FILTERING
  178962. if (png_ptr->do_filter & PNG_FILTER_SUB)
  178963. {
  178964. png_ptr->sub_row = (png_bytep)png_malloc(png_ptr,
  178965. (png_ptr->rowbytes + 1));
  178966. png_ptr->sub_row[0] = PNG_FILTER_VALUE_SUB;
  178967. }
  178968. if (png_ptr->do_filter & (PNG_FILTER_AVG | PNG_FILTER_UP | PNG_FILTER_PAETH))
  178969. {
  178970. png_ptr->prev_row = (png_bytep)png_malloc(png_ptr, (png_uint_32)buf_size);
  178971. png_memset(png_ptr->prev_row, 0, buf_size);
  178972. if (png_ptr->do_filter & PNG_FILTER_UP)
  178973. {
  178974. png_ptr->up_row = (png_bytep)png_malloc(png_ptr,
  178975. (png_ptr->rowbytes + 1));
  178976. png_ptr->up_row[0] = PNG_FILTER_VALUE_UP;
  178977. }
  178978. if (png_ptr->do_filter & PNG_FILTER_AVG)
  178979. {
  178980. png_ptr->avg_row = (png_bytep)png_malloc(png_ptr,
  178981. (png_ptr->rowbytes + 1));
  178982. png_ptr->avg_row[0] = PNG_FILTER_VALUE_AVG;
  178983. }
  178984. if (png_ptr->do_filter & PNG_FILTER_PAETH)
  178985. {
  178986. png_ptr->paeth_row = (png_bytep)png_malloc(png_ptr,
  178987. (png_ptr->rowbytes + 1));
  178988. png_ptr->paeth_row[0] = PNG_FILTER_VALUE_PAETH;
  178989. }
  178990. #endif /* PNG_NO_WRITE_FILTERING */
  178991. }
  178992. #ifdef PNG_WRITE_INTERLACING_SUPPORTED
  178993. if (png_ptr->interlaced)
  178994. {
  178995. if (!(png_ptr->transformations & PNG_INTERLACE))
  178996. {
  178997. png_ptr->num_rows = (png_ptr->height + png_pass_yinc[0] - 1 -
  178998. png_pass_ystart[0]) / png_pass_yinc[0];
  178999. png_ptr->usr_width = (png_ptr->width + png_pass_inc[0] - 1 -
  179000. png_pass_start[0]) / png_pass_inc[0];
  179001. }
  179002. else
  179003. {
  179004. png_ptr->num_rows = png_ptr->height;
  179005. png_ptr->usr_width = png_ptr->width;
  179006. }
  179007. }
  179008. else
  179009. #endif
  179010. {
  179011. png_ptr->num_rows = png_ptr->height;
  179012. png_ptr->usr_width = png_ptr->width;
  179013. }
  179014. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  179015. png_ptr->zstream.next_out = png_ptr->zbuf;
  179016. }
  179017. void /* PRIVATE */
  179018. png_write_finish_row(png_structp png_ptr)
  179019. {
  179020. #ifdef PNG_WRITE_INTERLACING_SUPPORTED
  179021. #ifdef PNG_USE_LOCAL_ARRAYS
  179022. int png_pass_start[7] = {0, 4, 0, 2, 0, 1, 0};
  179023. int png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1};
  179024. int png_pass_ystart[7] = {0, 0, 4, 0, 2, 0, 1};
  179025. int png_pass_yinc[7] = {8, 8, 8, 4, 4, 2, 2};
  179026. #endif
  179027. #endif
  179028. int ret;
  179029. png_debug(1, "in png_write_finish_row\n");
  179030. png_ptr->row_number++;
  179031. if (png_ptr->row_number < png_ptr->num_rows)
  179032. return;
  179033. #ifdef PNG_WRITE_INTERLACING_SUPPORTED
  179034. if (png_ptr->interlaced)
  179035. {
  179036. png_ptr->row_number = 0;
  179037. if (png_ptr->transformations & PNG_INTERLACE)
  179038. {
  179039. png_ptr->pass++;
  179040. }
  179041. else
  179042. {
  179043. do
  179044. {
  179045. png_ptr->pass++;
  179046. if (png_ptr->pass >= 7)
  179047. break;
  179048. png_ptr->usr_width = (png_ptr->width +
  179049. png_pass_inc[png_ptr->pass] - 1 -
  179050. png_pass_start[png_ptr->pass]) /
  179051. png_pass_inc[png_ptr->pass];
  179052. png_ptr->num_rows = (png_ptr->height +
  179053. png_pass_yinc[png_ptr->pass] - 1 -
  179054. png_pass_ystart[png_ptr->pass]) /
  179055. png_pass_yinc[png_ptr->pass];
  179056. if (png_ptr->transformations & PNG_INTERLACE)
  179057. break;
  179058. } while (png_ptr->usr_width == 0 || png_ptr->num_rows == 0);
  179059. }
  179060. if (png_ptr->pass < 7)
  179061. {
  179062. if (png_ptr->prev_row != NULL)
  179063. png_memset(png_ptr->prev_row, 0,
  179064. (png_size_t)(PNG_ROWBYTES(png_ptr->usr_channels*
  179065. png_ptr->usr_bit_depth,png_ptr->width))+1);
  179066. return;
  179067. }
  179068. }
  179069. #endif
  179070. do
  179071. {
  179072. ret = deflate(&png_ptr->zstream, Z_FINISH);
  179073. if (ret == Z_OK)
  179074. {
  179075. if (!(png_ptr->zstream.avail_out))
  179076. {
  179077. png_write_IDAT(png_ptr, png_ptr->zbuf, png_ptr->zbuf_size);
  179078. png_ptr->zstream.next_out = png_ptr->zbuf;
  179079. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  179080. }
  179081. }
  179082. else if (ret != Z_STREAM_END)
  179083. {
  179084. if (png_ptr->zstream.msg != NULL)
  179085. png_error(png_ptr, png_ptr->zstream.msg);
  179086. else
  179087. png_error(png_ptr, "zlib error");
  179088. }
  179089. } while (ret != Z_STREAM_END);
  179090. if (png_ptr->zstream.avail_out < png_ptr->zbuf_size)
  179091. {
  179092. png_write_IDAT(png_ptr, png_ptr->zbuf, png_ptr->zbuf_size -
  179093. png_ptr->zstream.avail_out);
  179094. }
  179095. deflateReset(&png_ptr->zstream);
  179096. png_ptr->zstream.data_type = Z_BINARY;
  179097. }
  179098. #if defined(PNG_WRITE_INTERLACING_SUPPORTED)
  179099. void /* PRIVATE */
  179100. png_do_write_interlace(png_row_infop row_info, png_bytep row, int pass)
  179101. {
  179102. #ifdef PNG_USE_LOCAL_ARRAYS
  179103. int png_pass_start[7] = {0, 4, 0, 2, 0, 1, 0};
  179104. int png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1};
  179105. #endif
  179106. png_debug(1, "in png_do_write_interlace\n");
  179107. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  179108. if (row != NULL && row_info != NULL && pass < 6)
  179109. #else
  179110. if (pass < 6)
  179111. #endif
  179112. {
  179113. switch (row_info->pixel_depth)
  179114. {
  179115. case 1:
  179116. {
  179117. png_bytep sp;
  179118. png_bytep dp;
  179119. int shift;
  179120. int d;
  179121. int value;
  179122. png_uint_32 i;
  179123. png_uint_32 row_width = row_info->width;
  179124. dp = row;
  179125. d = 0;
  179126. shift = 7;
  179127. for (i = png_pass_start[pass]; i < row_width;
  179128. i += png_pass_inc[pass])
  179129. {
  179130. sp = row + (png_size_t)(i >> 3);
  179131. value = (int)(*sp >> (7 - (int)(i & 0x07))) & 0x01;
  179132. d |= (value << shift);
  179133. if (shift == 0)
  179134. {
  179135. shift = 7;
  179136. *dp++ = (png_byte)d;
  179137. d = 0;
  179138. }
  179139. else
  179140. shift--;
  179141. }
  179142. if (shift != 7)
  179143. *dp = (png_byte)d;
  179144. break;
  179145. }
  179146. case 2:
  179147. {
  179148. png_bytep sp;
  179149. png_bytep dp;
  179150. int shift;
  179151. int d;
  179152. int value;
  179153. png_uint_32 i;
  179154. png_uint_32 row_width = row_info->width;
  179155. dp = row;
  179156. shift = 6;
  179157. d = 0;
  179158. for (i = png_pass_start[pass]; i < row_width;
  179159. i += png_pass_inc[pass])
  179160. {
  179161. sp = row + (png_size_t)(i >> 2);
  179162. value = (*sp >> ((3 - (int)(i & 0x03)) << 1)) & 0x03;
  179163. d |= (value << shift);
  179164. if (shift == 0)
  179165. {
  179166. shift = 6;
  179167. *dp++ = (png_byte)d;
  179168. d = 0;
  179169. }
  179170. else
  179171. shift -= 2;
  179172. }
  179173. if (shift != 6)
  179174. *dp = (png_byte)d;
  179175. break;
  179176. }
  179177. case 4:
  179178. {
  179179. png_bytep sp;
  179180. png_bytep dp;
  179181. int shift;
  179182. int d;
  179183. int value;
  179184. png_uint_32 i;
  179185. png_uint_32 row_width = row_info->width;
  179186. dp = row;
  179187. shift = 4;
  179188. d = 0;
  179189. for (i = png_pass_start[pass]; i < row_width;
  179190. i += png_pass_inc[pass])
  179191. {
  179192. sp = row + (png_size_t)(i >> 1);
  179193. value = (*sp >> ((1 - (int)(i & 0x01)) << 2)) & 0x0f;
  179194. d |= (value << shift);
  179195. if (shift == 0)
  179196. {
  179197. shift = 4;
  179198. *dp++ = (png_byte)d;
  179199. d = 0;
  179200. }
  179201. else
  179202. shift -= 4;
  179203. }
  179204. if (shift != 4)
  179205. *dp = (png_byte)d;
  179206. break;
  179207. }
  179208. default:
  179209. {
  179210. png_bytep sp;
  179211. png_bytep dp;
  179212. png_uint_32 i;
  179213. png_uint_32 row_width = row_info->width;
  179214. png_size_t pixel_bytes;
  179215. dp = row;
  179216. pixel_bytes = (row_info->pixel_depth >> 3);
  179217. for (i = png_pass_start[pass]; i < row_width;
  179218. i += png_pass_inc[pass])
  179219. {
  179220. sp = row + (png_size_t)i * pixel_bytes;
  179221. if (dp != sp)
  179222. png_memcpy(dp, sp, pixel_bytes);
  179223. dp += pixel_bytes;
  179224. }
  179225. break;
  179226. }
  179227. }
  179228. row_info->width = (row_info->width +
  179229. png_pass_inc[pass] - 1 -
  179230. png_pass_start[pass]) /
  179231. png_pass_inc[pass];
  179232. row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,
  179233. row_info->width);
  179234. }
  179235. }
  179236. #endif
  179237. #define PNG_MAXSUM (((png_uint_32)(-1)) >> 1)
  179238. #define PNG_HISHIFT 10
  179239. #define PNG_LOMASK ((png_uint_32)0xffffL)
  179240. #define PNG_HIMASK ((png_uint_32)(~PNG_LOMASK >> PNG_HISHIFT))
  179241. void /* PRIVATE */
  179242. png_write_find_filter(png_structp png_ptr, png_row_infop row_info)
  179243. {
  179244. png_bytep best_row;
  179245. #ifndef PNG_NO_WRITE_FILTER
  179246. png_bytep prev_row, row_buf;
  179247. png_uint_32 mins, bpp;
  179248. png_byte filter_to_do = png_ptr->do_filter;
  179249. png_uint_32 row_bytes = row_info->rowbytes;
  179250. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  179251. int num_p_filters = (int)png_ptr->num_prev_filters;
  179252. #endif
  179253. png_debug(1, "in png_write_find_filter\n");
  179254. bpp = (row_info->pixel_depth + 7) >> 3;
  179255. prev_row = png_ptr->prev_row;
  179256. #endif
  179257. best_row = png_ptr->row_buf;
  179258. #ifndef PNG_NO_WRITE_FILTER
  179259. row_buf = best_row;
  179260. mins = PNG_MAXSUM;
  179261. if ((filter_to_do & PNG_FILTER_NONE) &&
  179262. filter_to_do != PNG_FILTER_NONE)
  179263. {
  179264. png_bytep rp;
  179265. png_uint_32 sum = 0;
  179266. png_uint_32 i;
  179267. int v;
  179268. for (i = 0, rp = row_buf + 1; i < row_bytes; i++, rp++)
  179269. {
  179270. v = *rp;
  179271. sum += (v < 128) ? v : 256 - v;
  179272. }
  179273. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  179274. if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
  179275. {
  179276. png_uint_32 sumhi, sumlo;
  179277. int j;
  179278. sumlo = sum & PNG_LOMASK;
  179279. sumhi = (sum >> PNG_HISHIFT) & PNG_HIMASK; /* Gives us some footroom */
  179280. for (j = 0; j < num_p_filters; j++)
  179281. {
  179282. if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_NONE)
  179283. {
  179284. sumlo = (sumlo * png_ptr->filter_weights[j]) >>
  179285. PNG_WEIGHT_SHIFT;
  179286. sumhi = (sumhi * png_ptr->filter_weights[j]) >>
  179287. PNG_WEIGHT_SHIFT;
  179288. }
  179289. }
  179290. sumlo = (sumlo * png_ptr->filter_costs[PNG_FILTER_VALUE_NONE]) >>
  179291. PNG_COST_SHIFT;
  179292. sumhi = (sumhi * png_ptr->filter_costs[PNG_FILTER_VALUE_NONE]) >>
  179293. PNG_COST_SHIFT;
  179294. if (sumhi > PNG_HIMASK)
  179295. sum = PNG_MAXSUM;
  179296. else
  179297. sum = (sumhi << PNG_HISHIFT) + sumlo;
  179298. }
  179299. #endif
  179300. mins = sum;
  179301. }
  179302. if (filter_to_do == PNG_FILTER_SUB)
  179303. {
  179304. png_bytep rp, lp, dp;
  179305. png_uint_32 i;
  179306. for (i = 0, rp = row_buf + 1, dp = png_ptr->sub_row + 1; i < bpp;
  179307. i++, rp++, dp++)
  179308. {
  179309. *dp = *rp;
  179310. }
  179311. for (lp = row_buf + 1; i < row_bytes;
  179312. i++, rp++, lp++, dp++)
  179313. {
  179314. *dp = (png_byte)(((int)*rp - (int)*lp) & 0xff);
  179315. }
  179316. best_row = png_ptr->sub_row;
  179317. }
  179318. else if (filter_to_do & PNG_FILTER_SUB)
  179319. {
  179320. png_bytep rp, dp, lp;
  179321. png_uint_32 sum = 0, lmins = mins;
  179322. png_uint_32 i;
  179323. int v;
  179324. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  179325. if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
  179326. {
  179327. int j;
  179328. png_uint_32 lmhi, lmlo;
  179329. lmlo = lmins & PNG_LOMASK;
  179330. lmhi = (lmins >> PNG_HISHIFT) & PNG_HIMASK;
  179331. for (j = 0; j < num_p_filters; j++)
  179332. {
  179333. if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_SUB)
  179334. {
  179335. lmlo = (lmlo * png_ptr->inv_filter_weights[j]) >>
  179336. PNG_WEIGHT_SHIFT;
  179337. lmhi = (lmhi * png_ptr->inv_filter_weights[j]) >>
  179338. PNG_WEIGHT_SHIFT;
  179339. }
  179340. }
  179341. lmlo = (lmlo * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_SUB]) >>
  179342. PNG_COST_SHIFT;
  179343. lmhi = (lmhi * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_SUB]) >>
  179344. PNG_COST_SHIFT;
  179345. if (lmhi > PNG_HIMASK)
  179346. lmins = PNG_MAXSUM;
  179347. else
  179348. lmins = (lmhi << PNG_HISHIFT) + lmlo;
  179349. }
  179350. #endif
  179351. for (i = 0, rp = row_buf + 1, dp = png_ptr->sub_row + 1; i < bpp;
  179352. i++, rp++, dp++)
  179353. {
  179354. v = *dp = *rp;
  179355. sum += (v < 128) ? v : 256 - v;
  179356. }
  179357. for (lp = row_buf + 1; i < row_bytes;
  179358. i++, rp++, lp++, dp++)
  179359. {
  179360. v = *dp = (png_byte)(((int)*rp - (int)*lp) & 0xff);
  179361. sum += (v < 128) ? v : 256 - v;
  179362. if (sum > lmins) /* We are already worse, don't continue. */
  179363. break;
  179364. }
  179365. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  179366. if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
  179367. {
  179368. int j;
  179369. png_uint_32 sumhi, sumlo;
  179370. sumlo = sum & PNG_LOMASK;
  179371. sumhi = (sum >> PNG_HISHIFT) & PNG_HIMASK;
  179372. for (j = 0; j < num_p_filters; j++)
  179373. {
  179374. if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_SUB)
  179375. {
  179376. sumlo = (sumlo * png_ptr->inv_filter_weights[j]) >>
  179377. PNG_WEIGHT_SHIFT;
  179378. sumhi = (sumhi * png_ptr->inv_filter_weights[j]) >>
  179379. PNG_WEIGHT_SHIFT;
  179380. }
  179381. }
  179382. sumlo = (sumlo * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_SUB]) >>
  179383. PNG_COST_SHIFT;
  179384. sumhi = (sumhi * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_SUB]) >>
  179385. PNG_COST_SHIFT;
  179386. if (sumhi > PNG_HIMASK)
  179387. sum = PNG_MAXSUM;
  179388. else
  179389. sum = (sumhi << PNG_HISHIFT) + sumlo;
  179390. }
  179391. #endif
  179392. if (sum < mins)
  179393. {
  179394. mins = sum;
  179395. best_row = png_ptr->sub_row;
  179396. }
  179397. }
  179398. if (filter_to_do == PNG_FILTER_UP)
  179399. {
  179400. png_bytep rp, dp, pp;
  179401. png_uint_32 i;
  179402. for (i = 0, rp = row_buf + 1, dp = png_ptr->up_row + 1,
  179403. pp = prev_row + 1; i < row_bytes;
  179404. i++, rp++, pp++, dp++)
  179405. {
  179406. *dp = (png_byte)(((int)*rp - (int)*pp) & 0xff);
  179407. }
  179408. best_row = png_ptr->up_row;
  179409. }
  179410. else if (filter_to_do & PNG_FILTER_UP)
  179411. {
  179412. png_bytep rp, dp, pp;
  179413. png_uint_32 sum = 0, lmins = mins;
  179414. png_uint_32 i;
  179415. int v;
  179416. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  179417. if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
  179418. {
  179419. int j;
  179420. png_uint_32 lmhi, lmlo;
  179421. lmlo = lmins & PNG_LOMASK;
  179422. lmhi = (lmins >> PNG_HISHIFT) & PNG_HIMASK;
  179423. for (j = 0; j < num_p_filters; j++)
  179424. {
  179425. if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_UP)
  179426. {
  179427. lmlo = (lmlo * png_ptr->inv_filter_weights[j]) >>
  179428. PNG_WEIGHT_SHIFT;
  179429. lmhi = (lmhi * png_ptr->inv_filter_weights[j]) >>
  179430. PNG_WEIGHT_SHIFT;
  179431. }
  179432. }
  179433. lmlo = (lmlo * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_UP]) >>
  179434. PNG_COST_SHIFT;
  179435. lmhi = (lmhi * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_UP]) >>
  179436. PNG_COST_SHIFT;
  179437. if (lmhi > PNG_HIMASK)
  179438. lmins = PNG_MAXSUM;
  179439. else
  179440. lmins = (lmhi << PNG_HISHIFT) + lmlo;
  179441. }
  179442. #endif
  179443. for (i = 0, rp = row_buf + 1, dp = png_ptr->up_row + 1,
  179444. pp = prev_row + 1; i < row_bytes; i++)
  179445. {
  179446. v = *dp++ = (png_byte)(((int)*rp++ - (int)*pp++) & 0xff);
  179447. sum += (v < 128) ? v : 256 - v;
  179448. if (sum > lmins) /* We are already worse, don't continue. */
  179449. break;
  179450. }
  179451. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  179452. if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
  179453. {
  179454. int j;
  179455. png_uint_32 sumhi, sumlo;
  179456. sumlo = sum & PNG_LOMASK;
  179457. sumhi = (sum >> PNG_HISHIFT) & PNG_HIMASK;
  179458. for (j = 0; j < num_p_filters; j++)
  179459. {
  179460. if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_UP)
  179461. {
  179462. sumlo = (sumlo * png_ptr->filter_weights[j]) >>
  179463. PNG_WEIGHT_SHIFT;
  179464. sumhi = (sumhi * png_ptr->filter_weights[j]) >>
  179465. PNG_WEIGHT_SHIFT;
  179466. }
  179467. }
  179468. sumlo = (sumlo * png_ptr->filter_costs[PNG_FILTER_VALUE_UP]) >>
  179469. PNG_COST_SHIFT;
  179470. sumhi = (sumhi * png_ptr->filter_costs[PNG_FILTER_VALUE_UP]) >>
  179471. PNG_COST_SHIFT;
  179472. if (sumhi > PNG_HIMASK)
  179473. sum = PNG_MAXSUM;
  179474. else
  179475. sum = (sumhi << PNG_HISHIFT) + sumlo;
  179476. }
  179477. #endif
  179478. if (sum < mins)
  179479. {
  179480. mins = sum;
  179481. best_row = png_ptr->up_row;
  179482. }
  179483. }
  179484. if (filter_to_do == PNG_FILTER_AVG)
  179485. {
  179486. png_bytep rp, dp, pp, lp;
  179487. png_uint_32 i;
  179488. for (i = 0, rp = row_buf + 1, dp = png_ptr->avg_row + 1,
  179489. pp = prev_row + 1; i < bpp; i++)
  179490. {
  179491. *dp++ = (png_byte)(((int)*rp++ - ((int)*pp++ / 2)) & 0xff);
  179492. }
  179493. for (lp = row_buf + 1; i < row_bytes; i++)
  179494. {
  179495. *dp++ = (png_byte)(((int)*rp++ - (((int)*pp++ + (int)*lp++) / 2))
  179496. & 0xff);
  179497. }
  179498. best_row = png_ptr->avg_row;
  179499. }
  179500. else if (filter_to_do & PNG_FILTER_AVG)
  179501. {
  179502. png_bytep rp, dp, pp, lp;
  179503. png_uint_32 sum = 0, lmins = mins;
  179504. png_uint_32 i;
  179505. int v;
  179506. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  179507. if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
  179508. {
  179509. int j;
  179510. png_uint_32 lmhi, lmlo;
  179511. lmlo = lmins & PNG_LOMASK;
  179512. lmhi = (lmins >> PNG_HISHIFT) & PNG_HIMASK;
  179513. for (j = 0; j < num_p_filters; j++)
  179514. {
  179515. if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_AVG)
  179516. {
  179517. lmlo = (lmlo * png_ptr->inv_filter_weights[j]) >>
  179518. PNG_WEIGHT_SHIFT;
  179519. lmhi = (lmhi * png_ptr->inv_filter_weights[j]) >>
  179520. PNG_WEIGHT_SHIFT;
  179521. }
  179522. }
  179523. lmlo = (lmlo * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_AVG]) >>
  179524. PNG_COST_SHIFT;
  179525. lmhi = (lmhi * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_AVG]) >>
  179526. PNG_COST_SHIFT;
  179527. if (lmhi > PNG_HIMASK)
  179528. lmins = PNG_MAXSUM;
  179529. else
  179530. lmins = (lmhi << PNG_HISHIFT) + lmlo;
  179531. }
  179532. #endif
  179533. for (i = 0, rp = row_buf + 1, dp = png_ptr->avg_row + 1,
  179534. pp = prev_row + 1; i < bpp; i++)
  179535. {
  179536. v = *dp++ = (png_byte)(((int)*rp++ - ((int)*pp++ / 2)) & 0xff);
  179537. sum += (v < 128) ? v : 256 - v;
  179538. }
  179539. for (lp = row_buf + 1; i < row_bytes; i++)
  179540. {
  179541. v = *dp++ =
  179542. (png_byte)(((int)*rp++ - (((int)*pp++ + (int)*lp++) / 2)) & 0xff);
  179543. sum += (v < 128) ? v : 256 - v;
  179544. if (sum > lmins) /* We are already worse, don't continue. */
  179545. break;
  179546. }
  179547. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  179548. if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
  179549. {
  179550. int j;
  179551. png_uint_32 sumhi, sumlo;
  179552. sumlo = sum & PNG_LOMASK;
  179553. sumhi = (sum >> PNG_HISHIFT) & PNG_HIMASK;
  179554. for (j = 0; j < num_p_filters; j++)
  179555. {
  179556. if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_NONE)
  179557. {
  179558. sumlo = (sumlo * png_ptr->filter_weights[j]) >>
  179559. PNG_WEIGHT_SHIFT;
  179560. sumhi = (sumhi * png_ptr->filter_weights[j]) >>
  179561. PNG_WEIGHT_SHIFT;
  179562. }
  179563. }
  179564. sumlo = (sumlo * png_ptr->filter_costs[PNG_FILTER_VALUE_AVG]) >>
  179565. PNG_COST_SHIFT;
  179566. sumhi = (sumhi * png_ptr->filter_costs[PNG_FILTER_VALUE_AVG]) >>
  179567. PNG_COST_SHIFT;
  179568. if (sumhi > PNG_HIMASK)
  179569. sum = PNG_MAXSUM;
  179570. else
  179571. sum = (sumhi << PNG_HISHIFT) + sumlo;
  179572. }
  179573. #endif
  179574. if (sum < mins)
  179575. {
  179576. mins = sum;
  179577. best_row = png_ptr->avg_row;
  179578. }
  179579. }
  179580. if (filter_to_do == PNG_FILTER_PAETH)
  179581. {
  179582. png_bytep rp, dp, pp, cp, lp;
  179583. png_uint_32 i;
  179584. for (i = 0, rp = row_buf + 1, dp = png_ptr->paeth_row + 1,
  179585. pp = prev_row + 1; i < bpp; i++)
  179586. {
  179587. *dp++ = (png_byte)(((int)*rp++ - (int)*pp++) & 0xff);
  179588. }
  179589. for (lp = row_buf + 1, cp = prev_row + 1; i < row_bytes; i++)
  179590. {
  179591. int a, b, c, pa, pb, pc, p;
  179592. b = *pp++;
  179593. c = *cp++;
  179594. a = *lp++;
  179595. p = b - c;
  179596. pc = a - c;
  179597. #ifdef PNG_USE_ABS
  179598. pa = abs(p);
  179599. pb = abs(pc);
  179600. pc = abs(p + pc);
  179601. #else
  179602. pa = p < 0 ? -p : p;
  179603. pb = pc < 0 ? -pc : pc;
  179604. pc = (p + pc) < 0 ? -(p + pc) : p + pc;
  179605. #endif
  179606. p = (pa <= pb && pa <=pc) ? a : (pb <= pc) ? b : c;
  179607. *dp++ = (png_byte)(((int)*rp++ - p) & 0xff);
  179608. }
  179609. best_row = png_ptr->paeth_row;
  179610. }
  179611. else if (filter_to_do & PNG_FILTER_PAETH)
  179612. {
  179613. png_bytep rp, dp, pp, cp, lp;
  179614. png_uint_32 sum = 0, lmins = mins;
  179615. png_uint_32 i;
  179616. int v;
  179617. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  179618. if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
  179619. {
  179620. int j;
  179621. png_uint_32 lmhi, lmlo;
  179622. lmlo = lmins & PNG_LOMASK;
  179623. lmhi = (lmins >> PNG_HISHIFT) & PNG_HIMASK;
  179624. for (j = 0; j < num_p_filters; j++)
  179625. {
  179626. if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_PAETH)
  179627. {
  179628. lmlo = (lmlo * png_ptr->inv_filter_weights[j]) >>
  179629. PNG_WEIGHT_SHIFT;
  179630. lmhi = (lmhi * png_ptr->inv_filter_weights[j]) >>
  179631. PNG_WEIGHT_SHIFT;
  179632. }
  179633. }
  179634. lmlo = (lmlo * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_PAETH]) >>
  179635. PNG_COST_SHIFT;
  179636. lmhi = (lmhi * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_PAETH]) >>
  179637. PNG_COST_SHIFT;
  179638. if (lmhi > PNG_HIMASK)
  179639. lmins = PNG_MAXSUM;
  179640. else
  179641. lmins = (lmhi << PNG_HISHIFT) + lmlo;
  179642. }
  179643. #endif
  179644. for (i = 0, rp = row_buf + 1, dp = png_ptr->paeth_row + 1,
  179645. pp = prev_row + 1; i < bpp; i++)
  179646. {
  179647. v = *dp++ = (png_byte)(((int)*rp++ - (int)*pp++) & 0xff);
  179648. sum += (v < 128) ? v : 256 - v;
  179649. }
  179650. for (lp = row_buf + 1, cp = prev_row + 1; i < row_bytes; i++)
  179651. {
  179652. int a, b, c, pa, pb, pc, p;
  179653. b = *pp++;
  179654. c = *cp++;
  179655. a = *lp++;
  179656. #ifndef PNG_SLOW_PAETH
  179657. p = b - c;
  179658. pc = a - c;
  179659. #ifdef PNG_USE_ABS
  179660. pa = abs(p);
  179661. pb = abs(pc);
  179662. pc = abs(p + pc);
  179663. #else
  179664. pa = p < 0 ? -p : p;
  179665. pb = pc < 0 ? -pc : pc;
  179666. pc = (p + pc) < 0 ? -(p + pc) : p + pc;
  179667. #endif
  179668. p = (pa <= pb && pa <=pc) ? a : (pb <= pc) ? b : c;
  179669. #else /* PNG_SLOW_PAETH */
  179670. p = a + b - c;
  179671. pa = abs(p - a);
  179672. pb = abs(p - b);
  179673. pc = abs(p - c);
  179674. if (pa <= pb && pa <= pc)
  179675. p = a;
  179676. else if (pb <= pc)
  179677. p = b;
  179678. else
  179679. p = c;
  179680. #endif /* PNG_SLOW_PAETH */
  179681. v = *dp++ = (png_byte)(((int)*rp++ - p) & 0xff);
  179682. sum += (v < 128) ? v : 256 - v;
  179683. if (sum > lmins) /* We are already worse, don't continue. */
  179684. break;
  179685. }
  179686. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  179687. if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
  179688. {
  179689. int j;
  179690. png_uint_32 sumhi, sumlo;
  179691. sumlo = sum & PNG_LOMASK;
  179692. sumhi = (sum >> PNG_HISHIFT) & PNG_HIMASK;
  179693. for (j = 0; j < num_p_filters; j++)
  179694. {
  179695. if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_PAETH)
  179696. {
  179697. sumlo = (sumlo * png_ptr->filter_weights[j]) >>
  179698. PNG_WEIGHT_SHIFT;
  179699. sumhi = (sumhi * png_ptr->filter_weights[j]) >>
  179700. PNG_WEIGHT_SHIFT;
  179701. }
  179702. }
  179703. sumlo = (sumlo * png_ptr->filter_costs[PNG_FILTER_VALUE_PAETH]) >>
  179704. PNG_COST_SHIFT;
  179705. sumhi = (sumhi * png_ptr->filter_costs[PNG_FILTER_VALUE_PAETH]) >>
  179706. PNG_COST_SHIFT;
  179707. if (sumhi > PNG_HIMASK)
  179708. sum = PNG_MAXSUM;
  179709. else
  179710. sum = (sumhi << PNG_HISHIFT) + sumlo;
  179711. }
  179712. #endif
  179713. if (sum < mins)
  179714. {
  179715. best_row = png_ptr->paeth_row;
  179716. }
  179717. }
  179718. #endif /* PNG_NO_WRITE_FILTER */
  179719. png_write_filtered_row(png_ptr, best_row);
  179720. #ifndef PNG_NO_WRITE_FILTER
  179721. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  179722. if (png_ptr->num_prev_filters > 0)
  179723. {
  179724. int j;
  179725. for (j = 1; j < num_p_filters; j++)
  179726. {
  179727. png_ptr->prev_filters[j] = png_ptr->prev_filters[j - 1];
  179728. }
  179729. png_ptr->prev_filters[j] = best_row[0];
  179730. }
  179731. #endif
  179732. #endif /* PNG_NO_WRITE_FILTER */
  179733. }
  179734. void /* PRIVATE */
  179735. png_write_filtered_row(png_structp png_ptr, png_bytep filtered_row)
  179736. {
  179737. png_debug(1, "in png_write_filtered_row\n");
  179738. png_debug1(2, "filter = %d\n", filtered_row[0]);
  179739. png_ptr->zstream.next_in = filtered_row;
  179740. png_ptr->zstream.avail_in = (uInt)png_ptr->row_info.rowbytes + 1;
  179741. do
  179742. {
  179743. int ret; /* return of zlib */
  179744. ret = deflate(&png_ptr->zstream, Z_NO_FLUSH);
  179745. if (ret != Z_OK)
  179746. {
  179747. if (png_ptr->zstream.msg != NULL)
  179748. png_error(png_ptr, png_ptr->zstream.msg);
  179749. else
  179750. png_error(png_ptr, "zlib error");
  179751. }
  179752. if (!(png_ptr->zstream.avail_out))
  179753. {
  179754. png_write_IDAT(png_ptr, png_ptr->zbuf, png_ptr->zbuf_size);
  179755. png_ptr->zstream.next_out = png_ptr->zbuf;
  179756. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  179757. }
  179758. } while (png_ptr->zstream.avail_in);
  179759. if (png_ptr->prev_row != NULL)
  179760. {
  179761. png_bytep tptr;
  179762. tptr = png_ptr->prev_row;
  179763. png_ptr->prev_row = png_ptr->row_buf;
  179764. png_ptr->row_buf = tptr;
  179765. }
  179766. png_write_finish_row(png_ptr);
  179767. #if defined(PNG_WRITE_FLUSH_SUPPORTED)
  179768. png_ptr->flush_rows++;
  179769. if (png_ptr->flush_dist > 0 &&
  179770. png_ptr->flush_rows >= png_ptr->flush_dist)
  179771. {
  179772. png_write_flush(png_ptr);
  179773. }
  179774. #endif
  179775. }
  179776. #endif /* PNG_WRITE_SUPPORTED */
  179777. /********* End of inlined file: pngwutil.c *********/
  179778. }
  179779. #else
  179780. #define PNG_INTERNAL
  179781. #define PNG_SETJMP_NOT_SUPPORTED
  179782. #include <png.h>
  179783. #include <pngconf.h>
  179784. #endif
  179785. }
  179786. #ifdef _MSC_VER
  179787. #pragma warning (pop)
  179788. #endif
  179789. BEGIN_JUCE_NAMESPACE
  179790. using namespace pnglibNamespace;
  179791. using ::calloc;
  179792. using ::malloc;
  179793. using ::free;
  179794. static void pngReadCallback (png_structp pngReadStruct, png_bytep data, png_size_t length)
  179795. {
  179796. InputStream* const in = (InputStream*) png_get_io_ptr (pngReadStruct);
  179797. in->read (data, (int) length);
  179798. }
  179799. struct PNGErrorStruct {};
  179800. static void pngErrorCallback (png_structp, png_const_charp)
  179801. {
  179802. throw PNGErrorStruct();
  179803. }
  179804. Image* juce_loadPNGImageFromStream (InputStream& in)
  179805. {
  179806. Image* image = 0;
  179807. png_structp pngReadStruct;
  179808. png_infop pngInfoStruct;
  179809. pngReadStruct = png_create_read_struct (PNG_LIBPNG_VER_STRING, 0, 0, 0);
  179810. if (pngReadStruct != 0)
  179811. {
  179812. pngInfoStruct = png_create_info_struct (pngReadStruct);
  179813. if (pngInfoStruct == 0)
  179814. {
  179815. png_destroy_read_struct (&pngReadStruct, 0, 0);
  179816. return 0;
  179817. }
  179818. png_set_error_fn (pngReadStruct, 0, pngErrorCallback, pngErrorCallback);
  179819. // read the header..
  179820. png_set_read_fn (pngReadStruct, &in, pngReadCallback);
  179821. png_uint_32 width, height;
  179822. int bitDepth, colorType, interlaceType;
  179823. png_read_info (pngReadStruct, pngInfoStruct);
  179824. png_get_IHDR (pngReadStruct, pngInfoStruct,
  179825. &width, &height,
  179826. &bitDepth, &colorType,
  179827. &interlaceType, 0, 0);
  179828. if (bitDepth == 16)
  179829. png_set_strip_16 (pngReadStruct);
  179830. if (colorType == PNG_COLOR_TYPE_PALETTE)
  179831. png_set_expand (pngReadStruct);
  179832. if (bitDepth < 8)
  179833. png_set_expand (pngReadStruct);
  179834. if (png_get_valid (pngReadStruct, pngInfoStruct, PNG_INFO_tRNS))
  179835. png_set_expand (pngReadStruct);
  179836. if (colorType == PNG_COLOR_TYPE_GRAY || colorType == PNG_COLOR_TYPE_GRAY_ALPHA)
  179837. png_set_gray_to_rgb (pngReadStruct);
  179838. png_set_add_alpha (pngReadStruct, 0xff, PNG_FILLER_AFTER);
  179839. bool hasAlphaChan = (colorType & PNG_COLOR_MASK_ALPHA) != 0
  179840. || pngInfoStruct->num_trans > 0;
  179841. // Load the image into a temp buffer in the pnglib format..
  179842. HeapBlock <uint8> tempBuffer (height * (width << 2));
  179843. {
  179844. HeapBlock <png_bytep> rows (height);
  179845. for (int y = (int) height; --y >= 0;)
  179846. rows[y] = (png_bytep) (tempBuffer + (width << 2) * y);
  179847. png_read_image (pngReadStruct, rows);
  179848. png_read_end (pngReadStruct, pngInfoStruct);
  179849. }
  179850. png_destroy_read_struct (&pngReadStruct, &pngInfoStruct, 0);
  179851. // now convert the data to a juce image format..
  179852. image = Image::createNativeImage (hasAlphaChan ? Image::ARGB : Image::RGB,
  179853. (int) width, (int) height, hasAlphaChan);
  179854. hasAlphaChan = image->hasAlphaChannel(); // (the native image creator may not give back what we expect)
  179855. const Image::BitmapData destData (*image, 0, 0, (int) width, (int) height, true);
  179856. uint8* srcRow = tempBuffer;
  179857. uint8* destRow = destData.data;
  179858. for (int y = 0; y < (int) height; ++y)
  179859. {
  179860. const uint8* src = srcRow;
  179861. srcRow += (width << 2);
  179862. uint8* dest = destRow;
  179863. destRow += destData.lineStride;
  179864. if (hasAlphaChan)
  179865. {
  179866. for (int i = (int) width; --i >= 0;)
  179867. {
  179868. ((PixelARGB*) dest)->setARGB (src[3], src[0], src[1], src[2]);
  179869. ((PixelARGB*) dest)->premultiply();
  179870. dest += destData.pixelStride;
  179871. src += 4;
  179872. }
  179873. }
  179874. else
  179875. {
  179876. for (int i = (int) width; --i >= 0;)
  179877. {
  179878. ((PixelRGB*) dest)->setARGB (0, src[0], src[1], src[2]);
  179879. dest += destData.pixelStride;
  179880. src += 4;
  179881. }
  179882. }
  179883. }
  179884. }
  179885. return image;
  179886. }
  179887. static void pngWriteDataCallback (png_structp png_ptr, png_bytep data, png_size_t length)
  179888. {
  179889. OutputStream* const out = (OutputStream*) png_ptr->io_ptr;
  179890. const bool ok = out->write (data, (int) length);
  179891. (void) ok;
  179892. jassert (ok);
  179893. }
  179894. bool juce_writePNGImageToStream (const Image& image, OutputStream& out)
  179895. {
  179896. const int width = image.getWidth();
  179897. const int height = image.getHeight();
  179898. png_structp pngWriteStruct = png_create_write_struct (PNG_LIBPNG_VER_STRING, 0, 0, 0);
  179899. if (pngWriteStruct == 0)
  179900. return false;
  179901. png_infop pngInfoStruct = png_create_info_struct (pngWriteStruct);
  179902. if (pngInfoStruct == 0)
  179903. {
  179904. png_destroy_write_struct (&pngWriteStruct, (png_infopp) 0);
  179905. return false;
  179906. }
  179907. png_set_write_fn (pngWriteStruct, &out, pngWriteDataCallback, 0);
  179908. png_set_IHDR (pngWriteStruct, pngInfoStruct, width, height, 8,
  179909. image.hasAlphaChannel() ? PNG_COLOR_TYPE_RGB_ALPHA
  179910. : PNG_COLOR_TYPE_RGB,
  179911. PNG_INTERLACE_NONE,
  179912. PNG_COMPRESSION_TYPE_BASE,
  179913. PNG_FILTER_TYPE_BASE);
  179914. HeapBlock <png_byte> rowData (width * 4);
  179915. png_color_8 sig_bit;
  179916. sig_bit.red = 8;
  179917. sig_bit.green = 8;
  179918. sig_bit.blue = 8;
  179919. sig_bit.alpha = 8;
  179920. png_set_sBIT (pngWriteStruct, pngInfoStruct, &sig_bit);
  179921. png_write_info (pngWriteStruct, pngInfoStruct);
  179922. png_set_shift (pngWriteStruct, &sig_bit);
  179923. png_set_packing (pngWriteStruct);
  179924. const Image::BitmapData srcData (image, 0, 0, width, height);
  179925. for (int y = 0; y < height; ++y)
  179926. {
  179927. uint8* dst = (uint8*) rowData;
  179928. const uint8* src = srcData.getLinePointer (y);
  179929. if (image.hasAlphaChannel())
  179930. {
  179931. for (int i = width; --i >= 0;)
  179932. {
  179933. PixelARGB p (*(const PixelARGB*) src);
  179934. p.unpremultiply();
  179935. *dst++ = p.getRed();
  179936. *dst++ = p.getGreen();
  179937. *dst++ = p.getBlue();
  179938. *dst++ = p.getAlpha();
  179939. src += srcData.pixelStride;
  179940. }
  179941. }
  179942. else
  179943. {
  179944. for (int i = width; --i >= 0;)
  179945. {
  179946. *dst++ = ((const PixelRGB*) src)->getRed();
  179947. *dst++ = ((const PixelRGB*) src)->getGreen();
  179948. *dst++ = ((const PixelRGB*) src)->getBlue();
  179949. src += srcData.pixelStride;
  179950. }
  179951. }
  179952. png_write_rows (pngWriteStruct, &rowData, 1);
  179953. }
  179954. png_write_end (pngWriteStruct, pngInfoStruct);
  179955. png_destroy_write_struct (&pngWriteStruct, &pngInfoStruct);
  179956. out.flush();
  179957. return true;
  179958. }
  179959. END_JUCE_NAMESPACE
  179960. /********* End of inlined file: juce_PNGLoader.cpp *********/
  179961. #endif
  179962. //==============================================================================
  179963. #if JUCE_WINDOWS
  179964. /********* Start of inlined file: juce_win32_NativeCode.cpp *********/
  179965. BEGIN_JUCE_NAMESPACE
  179966. #define JUCE_INCLUDED_FILE 1
  179967. // Now include the actual code files..
  179968. /********* Start of inlined file: juce_win32_DynamicLibraryLoader.cpp *********/
  179969. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  179970. // compiled on its own).
  179971. #if JUCE_INCLUDED_FILE
  179972. /********* Start of inlined file: juce_win32_DynamicLibraryLoader.h *********/
  179973. #ifndef __JUCE_WIN32_DYNAMICLIBRARYLOADER_JUCEHEADER__
  179974. #define __JUCE_WIN32_DYNAMICLIBRARYLOADER_JUCEHEADER__
  179975. #ifndef DOXYGEN
  179976. // use with DynamicLibraryLoader to simplify importing functions
  179977. //
  179978. // functionName: function to import
  179979. // localFunctionName: name you want to use to actually call it (must be different)
  179980. // returnType: the return type
  179981. // object: the DynamicLibraryLoader to use
  179982. // params: list of params (bracketed)
  179983. //
  179984. #define DynamicLibraryImport(functionName, localFunctionName, returnType, object, params) \
  179985. typedef returnType (WINAPI *type##localFunctionName) params; \
  179986. type##localFunctionName localFunctionName \
  179987. = (type##localFunctionName)object.findProcAddress (#functionName);
  179988. // loads and unloads a DLL automatically
  179989. class JUCE_API DynamicLibraryLoader
  179990. {
  179991. public:
  179992. DynamicLibraryLoader (const String& name);
  179993. ~DynamicLibraryLoader();
  179994. void* findProcAddress (const String& functionName);
  179995. private:
  179996. void* libHandle;
  179997. };
  179998. #endif
  179999. #endif // __JUCE_WIN32_DYNAMICLIBRARYLOADER_JUCEHEADER__
  180000. /********* End of inlined file: juce_win32_DynamicLibraryLoader.h *********/
  180001. DynamicLibraryLoader::DynamicLibraryLoader (const String& name)
  180002. {
  180003. libHandle = LoadLibrary (name);
  180004. }
  180005. DynamicLibraryLoader::~DynamicLibraryLoader()
  180006. {
  180007. FreeLibrary ((HMODULE) libHandle);
  180008. }
  180009. void* DynamicLibraryLoader::findProcAddress (const String& functionName)
  180010. {
  180011. return (void*) GetProcAddress ((HMODULE) libHandle, functionName);
  180012. }
  180013. #endif
  180014. /********* End of inlined file: juce_win32_DynamicLibraryLoader.cpp *********/
  180015. /********* Start of inlined file: juce_win32_SystemStats.cpp *********/
  180016. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  180017. // compiled on its own).
  180018. #if JUCE_INCLUDED_FILE
  180019. extern void juce_initialiseThreadEvents();
  180020. void Logger::outputDebugString (const String& text) throw()
  180021. {
  180022. OutputDebugString (text + T("\n"));
  180023. }
  180024. void Logger::outputDebugPrintf (const tchar* format, ...) throw()
  180025. {
  180026. String text;
  180027. va_list args;
  180028. va_start (args, format);
  180029. text.vprintf(format, args);
  180030. outputDebugString (text);
  180031. }
  180032. static int64 hiResTicksPerSecond;
  180033. static double hiResTicksScaleFactor;
  180034. #if JUCE_USE_INTRINSICS
  180035. // CPU info functions using intrinsics...
  180036. #pragma intrinsic (__cpuid)
  180037. #pragma intrinsic (__rdtsc)
  180038. const String SystemStats::getCpuVendor() throw()
  180039. {
  180040. int info [4];
  180041. __cpuid (info, 0);
  180042. char v [12];
  180043. memcpy (v, info + 1, 4);
  180044. memcpy (v + 4, info + 3, 4);
  180045. memcpy (v + 8, info + 2, 4);
  180046. return String (v, 12);
  180047. }
  180048. #else
  180049. // CPU info functions using old fashioned inline asm...
  180050. static void juce_getCpuVendor (char* const v)
  180051. {
  180052. int vendor[4];
  180053. zeromem (vendor, 16);
  180054. #ifdef JUCE_64BIT
  180055. #else
  180056. #ifndef __MINGW32__
  180057. __try
  180058. #endif
  180059. {
  180060. #if JUCE_GCC
  180061. unsigned int dummy = 0;
  180062. __asm__ ("cpuid" : "=a" (dummy), "=b" (vendor[0]), "=c" (vendor[2]),"=d" (vendor[1]) : "a" (0));
  180063. #else
  180064. __asm
  180065. {
  180066. mov eax, 0
  180067. cpuid
  180068. mov [vendor], ebx
  180069. mov [vendor + 4], edx
  180070. mov [vendor + 8], ecx
  180071. }
  180072. #endif
  180073. }
  180074. #ifndef __MINGW32__
  180075. __except (EXCEPTION_EXECUTE_HANDLER)
  180076. {
  180077. *v = 0;
  180078. }
  180079. #endif
  180080. #endif
  180081. memcpy (v, vendor, 16);
  180082. }
  180083. const String SystemStats::getCpuVendor() throw()
  180084. {
  180085. char v [16];
  180086. juce_getCpuVendor (v);
  180087. return String (v, 16);
  180088. }
  180089. #endif
  180090. struct CPUFlags
  180091. {
  180092. bool hasMMX : 1;
  180093. bool hasSSE : 1;
  180094. bool hasSSE2 : 1;
  180095. bool has3DNow : 1;
  180096. };
  180097. static CPUFlags cpuFlags;
  180098. bool SystemStats::hasMMX() throw()
  180099. {
  180100. return cpuFlags.hasMMX;
  180101. }
  180102. bool SystemStats::hasSSE() throw()
  180103. {
  180104. return cpuFlags.hasSSE;
  180105. }
  180106. bool SystemStats::hasSSE2() throw()
  180107. {
  180108. return cpuFlags.hasSSE2;
  180109. }
  180110. bool SystemStats::has3DNow() throw()
  180111. {
  180112. return cpuFlags.has3DNow;
  180113. }
  180114. void SystemStats::initialiseStats() throw()
  180115. {
  180116. juce_initialiseThreadEvents();
  180117. cpuFlags.hasMMX = IsProcessorFeaturePresent (PF_MMX_INSTRUCTIONS_AVAILABLE) != 0;
  180118. cpuFlags.hasSSE = IsProcessorFeaturePresent (PF_XMMI_INSTRUCTIONS_AVAILABLE) != 0;
  180119. cpuFlags.hasSSE2 = IsProcessorFeaturePresent (PF_XMMI64_INSTRUCTIONS_AVAILABLE) != 0;
  180120. #ifdef PF_AMD3D_INSTRUCTIONS_AVAILABLE
  180121. cpuFlags.has3DNow = IsProcessorFeaturePresent (PF_AMD3D_INSTRUCTIONS_AVAILABLE) != 0;
  180122. #else
  180123. cpuFlags.has3DNow = IsProcessorFeaturePresent (PF_3DNOW_INSTRUCTIONS_AVAILABLE) != 0;
  180124. #endif
  180125. LARGE_INTEGER f;
  180126. QueryPerformanceFrequency (&f);
  180127. hiResTicksPerSecond = f.QuadPart;
  180128. hiResTicksScaleFactor = 1000.0 / hiResTicksPerSecond;
  180129. String s (SystemStats::getJUCEVersion());
  180130. #ifdef JUCE_DEBUG
  180131. const MMRESULT res = timeBeginPeriod (1);
  180132. jassert (res == TIMERR_NOERROR);
  180133. #else
  180134. timeBeginPeriod (1);
  180135. #endif
  180136. #if defined (JUCE_DEBUG) && JUCE_MSVC && JUCE_CHECK_MEMORY_LEAKS
  180137. _CrtSetDbgFlag (_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF);
  180138. #endif
  180139. }
  180140. SystemStats::OperatingSystemType SystemStats::getOperatingSystemType() throw()
  180141. {
  180142. OSVERSIONINFO info;
  180143. info.dwOSVersionInfoSize = sizeof (info);
  180144. GetVersionEx (&info);
  180145. if (info.dwPlatformId == VER_PLATFORM_WIN32_NT)
  180146. {
  180147. switch (info.dwMajorVersion)
  180148. {
  180149. case 5: return (info.dwMinorVersion == 0) ? Win2000 : WinXP;
  180150. case 6: return (info.dwMinorVersion == 0) ? WinVista : Windows7;
  180151. default: jassertfalse; break; // !! not a supported OS!
  180152. }
  180153. }
  180154. else if (info.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS)
  180155. {
  180156. jassert (info.dwMinorVersion != 0); // !! still running on Windows 95??
  180157. return Win98;
  180158. }
  180159. return UnknownOS;
  180160. }
  180161. const String SystemStats::getOperatingSystemName() throw()
  180162. {
  180163. const char* name = "Unknown OS";
  180164. switch (getOperatingSystemType())
  180165. {
  180166. case Windows7: name = "Windows 7"; break;
  180167. case WinVista: name = "Windows Vista"; break;
  180168. case WinXP: name = "Windows XP"; break;
  180169. case Win2000: name = "Windows 2000"; break;
  180170. case Win98: name = "Windows 98"; break;
  180171. default: jassertfalse; break; // !! new type of OS?
  180172. }
  180173. return name;
  180174. }
  180175. bool SystemStats::isOperatingSystem64Bit() throw()
  180176. {
  180177. #ifdef _WIN64
  180178. return true;
  180179. #else
  180180. typedef BOOL (WINAPI* LPFN_ISWOW64PROCESS) (HANDLE, PBOOL);
  180181. LPFN_ISWOW64PROCESS fnIsWow64Process = (LPFN_ISWOW64PROCESS) GetProcAddress (GetModuleHandle (L"kernel32"), "IsWow64Process");
  180182. BOOL isWow64 = FALSE;
  180183. return (fnIsWow64Process != 0)
  180184. && fnIsWow64Process (GetCurrentProcess(), &isWow64)
  180185. && (isWow64 != FALSE);
  180186. #endif
  180187. }
  180188. int SystemStats::getMemorySizeInMegabytes() throw()
  180189. {
  180190. MEMORYSTATUSEX mem;
  180191. mem.dwLength = sizeof (mem);
  180192. GlobalMemoryStatusEx (&mem);
  180193. return (int) (mem.ullTotalPhys / (1024 * 1024)) + 1;
  180194. }
  180195. int SystemStats::getNumCpus() throw()
  180196. {
  180197. SYSTEM_INFO systemInfo;
  180198. GetSystemInfo (&systemInfo);
  180199. return systemInfo.dwNumberOfProcessors;
  180200. }
  180201. uint32 juce_millisecondsSinceStartup() throw()
  180202. {
  180203. return (uint32) GetTickCount();
  180204. }
  180205. int64 Time::getHighResolutionTicks() throw()
  180206. {
  180207. LARGE_INTEGER ticks;
  180208. QueryPerformanceCounter (&ticks);
  180209. const int64 mainCounterAsHiResTicks = (GetTickCount() * hiResTicksPerSecond) / 1000;
  180210. const int64 newOffset = mainCounterAsHiResTicks - ticks.QuadPart;
  180211. // fix for a very obscure PCI hardware bug that can make the counter
  180212. // sometimes jump forwards by a few seconds..
  180213. static int64 hiResTicksOffset = 0;
  180214. const int64 offsetDrift = abs64 (newOffset - hiResTicksOffset);
  180215. if (offsetDrift > (hiResTicksPerSecond >> 1))
  180216. hiResTicksOffset = newOffset;
  180217. return ticks.QuadPart + hiResTicksOffset;
  180218. }
  180219. double Time::getMillisecondCounterHiRes() throw()
  180220. {
  180221. return getHighResolutionTicks() * hiResTicksScaleFactor;
  180222. }
  180223. int64 Time::getHighResolutionTicksPerSecond() throw()
  180224. {
  180225. return hiResTicksPerSecond;
  180226. }
  180227. int64 SystemStats::getClockCycleCounter() throw()
  180228. {
  180229. #if JUCE_USE_INTRINSICS
  180230. // MS intrinsics version...
  180231. return __rdtsc();
  180232. #elif JUCE_GCC
  180233. // GNU inline asm version...
  180234. unsigned int hi = 0, lo = 0;
  180235. __asm__ __volatile__ (
  180236. "xor %%eax, %%eax \n\
  180237. xor %%edx, %%edx \n\
  180238. rdtsc \n\
  180239. movl %%eax, %[lo] \n\
  180240. movl %%edx, %[hi]"
  180241. :
  180242. : [hi] "m" (hi),
  180243. [lo] "m" (lo)
  180244. : "cc", "eax", "ebx", "ecx", "edx", "memory");
  180245. return (int64) ((((uint64) hi) << 32) | lo);
  180246. #else
  180247. // MSVC inline asm version...
  180248. unsigned int hi = 0, lo = 0;
  180249. __asm
  180250. {
  180251. xor eax, eax
  180252. xor edx, edx
  180253. rdtsc
  180254. mov lo, eax
  180255. mov hi, edx
  180256. }
  180257. return (int64) ((((uint64) hi) << 32) | lo);
  180258. #endif
  180259. }
  180260. int SystemStats::getCpuSpeedInMegaherz() throw()
  180261. {
  180262. const int64 cycles = SystemStats::getClockCycleCounter();
  180263. const uint32 millis = Time::getMillisecondCounter();
  180264. int lastResult = 0;
  180265. for (;;)
  180266. {
  180267. int n = 1000000;
  180268. while (--n > 0) {}
  180269. const uint32 millisElapsed = Time::getMillisecondCounter() - millis;
  180270. const int64 cyclesNow = SystemStats::getClockCycleCounter();
  180271. if (millisElapsed > 80)
  180272. {
  180273. const int newResult = (int) (((cyclesNow - cycles) / millisElapsed) / 1000);
  180274. if (millisElapsed > 500 || (lastResult == newResult && newResult > 100))
  180275. return newResult;
  180276. lastResult = newResult;
  180277. }
  180278. }
  180279. }
  180280. bool Time::setSystemTimeToThisTime() const throw()
  180281. {
  180282. SYSTEMTIME st;
  180283. st.wDayOfWeek = 0;
  180284. st.wYear = (WORD) getYear();
  180285. st.wMonth = (WORD) (getMonth() + 1);
  180286. st.wDay = (WORD) getDayOfMonth();
  180287. st.wHour = (WORD) getHours();
  180288. st.wMinute = (WORD) getMinutes();
  180289. st.wSecond = (WORD) getSeconds();
  180290. st.wMilliseconds = (WORD) (millisSinceEpoch % 1000);
  180291. // do this twice because of daylight saving conversion problems - the
  180292. // first one sets it up, the second one kicks it in.
  180293. return SetLocalTime (&st) != 0
  180294. && SetLocalTime (&st) != 0;
  180295. }
  180296. int SystemStats::getPageSize() throw()
  180297. {
  180298. SYSTEM_INFO systemInfo;
  180299. GetSystemInfo (&systemInfo);
  180300. return systemInfo.dwPageSize;
  180301. }
  180302. #endif
  180303. /********* End of inlined file: juce_win32_SystemStats.cpp *********/
  180304. /********* Start of inlined file: juce_win32_Threads.cpp *********/
  180305. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  180306. // compiled on its own).
  180307. #if JUCE_INCLUDED_FILE
  180308. #if ! JUCE_ONLY_BUILD_CORE_LIBRARY
  180309. extern HWND juce_messageWindowHandle;
  180310. #endif
  180311. #if ! JUCE_USE_INTRINSICS
  180312. // In newer compilers, the inline versions of these are used (in juce_Atomic.h), but in
  180313. // older ones we have to actually call the ops as win32 functions..
  180314. void Atomic::increment (int32& variable) { InterlockedIncrement (reinterpret_cast <volatile long*> (&variable)); }
  180315. int32 Atomic::incrementAndReturn (int32& variable) { return InterlockedIncrement (reinterpret_cast <volatile long*> (&variable)); }
  180316. void Atomic::decrement (int32& variable) { InterlockedDecrement (reinterpret_cast <volatile long*> (&variable)); }
  180317. int32 Atomic::decrementAndReturn (int32& variable) { return InterlockedDecrement (reinterpret_cast <volatile long*> (&variable)); }
  180318. int32 Atomic::compareAndExchange (int32& destination, int32 newValue, int32 oldValue)
  180319. { return InterlockedCompareExchange (reinterpret_cast <volatile long*> (&destination), newValue, oldValue); }
  180320. #endif
  180321. CriticalSection::CriticalSection() throw()
  180322. {
  180323. // (just to check the MS haven't changed this structure and broken things...)
  180324. #if _MSC_VER >= 1400
  180325. static_jassert (sizeof (CRITICAL_SECTION) <= sizeof (internal));
  180326. #else
  180327. static_jassert (sizeof (CRITICAL_SECTION) <= 24);
  180328. #endif
  180329. InitializeCriticalSection ((CRITICAL_SECTION*) internal);
  180330. }
  180331. CriticalSection::~CriticalSection() throw()
  180332. {
  180333. DeleteCriticalSection ((CRITICAL_SECTION*) internal);
  180334. }
  180335. void CriticalSection::enter() const throw()
  180336. {
  180337. EnterCriticalSection ((CRITICAL_SECTION*) internal);
  180338. }
  180339. bool CriticalSection::tryEnter() const throw()
  180340. {
  180341. return TryEnterCriticalSection ((CRITICAL_SECTION*) internal) != FALSE;
  180342. }
  180343. void CriticalSection::exit() const throw()
  180344. {
  180345. LeaveCriticalSection ((CRITICAL_SECTION*) internal);
  180346. }
  180347. WaitableEvent::WaitableEvent() throw()
  180348. : internal (CreateEvent (0, FALSE, FALSE, 0))
  180349. {
  180350. }
  180351. WaitableEvent::~WaitableEvent() throw()
  180352. {
  180353. CloseHandle (internal);
  180354. }
  180355. bool WaitableEvent::wait (const int timeOutMillisecs) const throw()
  180356. {
  180357. return WaitForSingleObject (internal, timeOutMillisecs) == WAIT_OBJECT_0;
  180358. }
  180359. void WaitableEvent::signal() const throw()
  180360. {
  180361. SetEvent (internal);
  180362. }
  180363. void WaitableEvent::reset() const throw()
  180364. {
  180365. ResetEvent (internal);
  180366. }
  180367. void JUCE_API juce_threadEntryPoint (void*);
  180368. static unsigned int __stdcall threadEntryProc (void* userData)
  180369. {
  180370. #if ! JUCE_ONLY_BUILD_CORE_LIBRARY
  180371. AttachThreadInput (GetWindowThreadProcessId (juce_messageWindowHandle, 0),
  180372. GetCurrentThreadId(), TRUE);
  180373. #endif
  180374. juce_threadEntryPoint (userData);
  180375. _endthreadex (0);
  180376. return 0;
  180377. }
  180378. void juce_CloseThreadHandle (void* handle)
  180379. {
  180380. CloseHandle ((HANDLE) handle);
  180381. }
  180382. void* juce_createThread (void* userData)
  180383. {
  180384. unsigned int threadId;
  180385. return (void*) _beginthreadex (0, 0,
  180386. &threadEntryProc,
  180387. userData,
  180388. 0, &threadId);
  180389. }
  180390. void juce_killThread (void* handle)
  180391. {
  180392. if (handle != 0)
  180393. {
  180394. #ifdef JUCE_DEBUG
  180395. OutputDebugString (_T("** Warning - Forced thread termination **\n"));
  180396. #endif
  180397. TerminateThread (handle, 0);
  180398. }
  180399. }
  180400. void juce_setCurrentThreadName (const String& name)
  180401. {
  180402. #if defined (JUCE_DEBUG) && JUCE_MSVC
  180403. struct
  180404. {
  180405. DWORD dwType;
  180406. LPCSTR szName;
  180407. DWORD dwThreadID;
  180408. DWORD dwFlags;
  180409. } info;
  180410. info.dwType = 0x1000;
  180411. info.szName = name;
  180412. info.dwThreadID = GetCurrentThreadId();
  180413. info.dwFlags = 0;
  180414. #define MS_VC_EXCEPTION 0x406d1388
  180415. __try
  180416. {
  180417. RaiseException (MS_VC_EXCEPTION, 0, sizeof (info) / sizeof (ULONG_PTR), (ULONG_PTR*) &info);
  180418. }
  180419. __except (EXCEPTION_CONTINUE_EXECUTION)
  180420. {}
  180421. #else
  180422. (void) name;
  180423. #endif
  180424. }
  180425. Thread::ThreadID Thread::getCurrentThreadId()
  180426. {
  180427. return (ThreadID) (pointer_sized_int) GetCurrentThreadId();
  180428. }
  180429. // priority 1 to 10 where 5=normal, 1=low
  180430. bool juce_setThreadPriority (void* threadHandle, int priority)
  180431. {
  180432. int pri = THREAD_PRIORITY_TIME_CRITICAL;
  180433. if (priority < 1)
  180434. pri = THREAD_PRIORITY_IDLE;
  180435. else if (priority < 2)
  180436. pri = THREAD_PRIORITY_LOWEST;
  180437. else if (priority < 5)
  180438. pri = THREAD_PRIORITY_BELOW_NORMAL;
  180439. else if (priority < 7)
  180440. pri = THREAD_PRIORITY_NORMAL;
  180441. else if (priority < 9)
  180442. pri = THREAD_PRIORITY_ABOVE_NORMAL;
  180443. else if (priority < 10)
  180444. pri = THREAD_PRIORITY_HIGHEST;
  180445. if (threadHandle == 0)
  180446. threadHandle = GetCurrentThread();
  180447. return SetThreadPriority (threadHandle, pri) != FALSE;
  180448. }
  180449. void Thread::setCurrentThreadAffinityMask (const uint32 affinityMask)
  180450. {
  180451. SetThreadAffinityMask (GetCurrentThread(), affinityMask);
  180452. }
  180453. static HANDLE sleepEvent = 0;
  180454. void juce_initialiseThreadEvents()
  180455. {
  180456. if (sleepEvent == 0)
  180457. #ifdef JUCE_DEBUG
  180458. sleepEvent = CreateEvent (0, 0, 0, _T("Juce Sleep Event"));
  180459. #else
  180460. sleepEvent = CreateEvent (0, 0, 0, 0);
  180461. #endif
  180462. }
  180463. void Thread::yield()
  180464. {
  180465. Sleep (0);
  180466. }
  180467. void JUCE_CALLTYPE Thread::sleep (const int millisecs)
  180468. {
  180469. if (millisecs >= 10)
  180470. {
  180471. Sleep (millisecs);
  180472. }
  180473. else
  180474. {
  180475. jassert (sleepEvent != 0);
  180476. // unlike Sleep() this is guaranteed to return to the current thread after
  180477. // the time expires, so we'll use this for short waits, which are more likely
  180478. // to need to be accurate
  180479. WaitForSingleObject (sleepEvent, millisecs);
  180480. }
  180481. }
  180482. static int lastProcessPriority = -1;
  180483. // called by WindowDriver because Windows does wierd things to process priority
  180484. // when you swap apps, and this forces an update when the app is brought to the front.
  180485. void juce_repeatLastProcessPriority()
  180486. {
  180487. if (lastProcessPriority >= 0) // (avoid changing this if it's not been explicitly set by the app..)
  180488. {
  180489. DWORD p;
  180490. switch (lastProcessPriority)
  180491. {
  180492. case Process::LowPriority:
  180493. p = IDLE_PRIORITY_CLASS;
  180494. break;
  180495. case Process::NormalPriority:
  180496. p = NORMAL_PRIORITY_CLASS;
  180497. break;
  180498. case Process::HighPriority:
  180499. p = HIGH_PRIORITY_CLASS;
  180500. break;
  180501. case Process::RealtimePriority:
  180502. p = REALTIME_PRIORITY_CLASS;
  180503. break;
  180504. default:
  180505. jassertfalse // bad priority value
  180506. return;
  180507. }
  180508. SetPriorityClass (GetCurrentProcess(), p);
  180509. }
  180510. }
  180511. void Process::setPriority (ProcessPriority prior)
  180512. {
  180513. if (lastProcessPriority != (int) prior)
  180514. {
  180515. lastProcessPriority = (int) prior;
  180516. juce_repeatLastProcessPriority();
  180517. }
  180518. }
  180519. bool JUCE_PUBLIC_FUNCTION juce_isRunningUnderDebugger()
  180520. {
  180521. return IsDebuggerPresent() != FALSE;
  180522. }
  180523. bool JUCE_CALLTYPE Process::isRunningUnderDebugger()
  180524. {
  180525. return juce_isRunningUnderDebugger();
  180526. }
  180527. void Process::raisePrivilege()
  180528. {
  180529. jassertfalse // xxx not implemented
  180530. }
  180531. void Process::lowerPrivilege()
  180532. {
  180533. jassertfalse // xxx not implemented
  180534. }
  180535. void Process::terminate()
  180536. {
  180537. #if defined (JUCE_DEBUG) && JUCE_MSVC && JUCE_CHECK_MEMORY_LEAKS
  180538. _CrtDumpMemoryLeaks();
  180539. #endif
  180540. // bullet in the head in case there's a problem shutting down..
  180541. ExitProcess (0);
  180542. }
  180543. void* PlatformUtilities::loadDynamicLibrary (const String& name)
  180544. {
  180545. void* result = 0;
  180546. JUCE_TRY
  180547. {
  180548. result = (void*) LoadLibrary (name);
  180549. }
  180550. JUCE_CATCH_ALL
  180551. return result;
  180552. }
  180553. void PlatformUtilities::freeDynamicLibrary (void* h)
  180554. {
  180555. JUCE_TRY
  180556. {
  180557. if (h != 0)
  180558. FreeLibrary ((HMODULE) h);
  180559. }
  180560. JUCE_CATCH_ALL
  180561. }
  180562. void* PlatformUtilities::getProcedureEntryPoint (void* h, const String& name)
  180563. {
  180564. return (h != 0) ? (void*) GetProcAddress ((HMODULE) h, name)
  180565. : 0;
  180566. }
  180567. InterProcessLock::InterProcessLock (const String& name_)
  180568. : internal (0),
  180569. name (name_),
  180570. reentrancyLevel (0)
  180571. {
  180572. }
  180573. InterProcessLock::~InterProcessLock()
  180574. {
  180575. exit();
  180576. }
  180577. bool InterProcessLock::enter (const int timeOutMillisecs)
  180578. {
  180579. if (reentrancyLevel++ == 0)
  180580. {
  180581. internal = CreateMutex (0, TRUE, "Global\\" + name);
  180582. if (internal != 0 && GetLastError() == ERROR_ALREADY_EXISTS)
  180583. {
  180584. if (timeOutMillisecs == 0
  180585. || WaitForSingleObject (internal, (timeOutMillisecs < 0) ? INFINITE : timeOutMillisecs)
  180586. == WAIT_TIMEOUT)
  180587. {
  180588. ReleaseMutex (internal);
  180589. CloseHandle (internal);
  180590. internal = 0;
  180591. }
  180592. }
  180593. }
  180594. return (internal != 0);
  180595. }
  180596. void InterProcessLock::exit()
  180597. {
  180598. if (--reentrancyLevel == 0 && internal != 0)
  180599. {
  180600. ReleaseMutex (internal);
  180601. CloseHandle (internal);
  180602. internal = 0;
  180603. }
  180604. }
  180605. #endif
  180606. /********* End of inlined file: juce_win32_Threads.cpp *********/
  180607. /********* Start of inlined file: juce_win32_Files.cpp *********/
  180608. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  180609. // compiled on its own).
  180610. #if JUCE_INCLUDED_FILE
  180611. #ifndef CSIDL_MYMUSIC
  180612. #define CSIDL_MYMUSIC 0x000d
  180613. #endif
  180614. #ifndef CSIDL_MYVIDEO
  180615. #define CSIDL_MYVIDEO 0x000e
  180616. #endif
  180617. const tchar File::separator = T('\\');
  180618. const tchar* File::separatorString = T("\\");
  180619. bool juce_fileExists (const String& fileName, const bool dontCountDirectories)
  180620. {
  180621. if (fileName.isEmpty())
  180622. return false;
  180623. const DWORD attr = GetFileAttributes (fileName);
  180624. return dontCountDirectories ? ((attr & FILE_ATTRIBUTE_DIRECTORY) == 0)
  180625. : (attr != 0xffffffff);
  180626. }
  180627. bool juce_isDirectory (const String& fileName)
  180628. {
  180629. const DWORD attr = GetFileAttributes (fileName);
  180630. return (attr != 0xffffffff)
  180631. && ((attr & FILE_ATTRIBUTE_DIRECTORY) != 0);
  180632. }
  180633. bool juce_canWriteToFile (const String& fileName)
  180634. {
  180635. const DWORD attr = GetFileAttributes (fileName);
  180636. return ((attr & FILE_ATTRIBUTE_READONLY) == 0);
  180637. }
  180638. bool juce_setFileReadOnly (const String& fileName, bool isReadOnly)
  180639. {
  180640. DWORD attr = GetFileAttributes (fileName);
  180641. if (attr == 0xffffffff)
  180642. return false;
  180643. if (isReadOnly != juce_canWriteToFile (fileName))
  180644. return true;
  180645. if (isReadOnly)
  180646. attr |= FILE_ATTRIBUTE_READONLY;
  180647. else
  180648. attr &= ~FILE_ATTRIBUTE_READONLY;
  180649. return SetFileAttributes (fileName, attr) != FALSE;
  180650. }
  180651. bool File::isHidden() const
  180652. {
  180653. return (GetFileAttributes (getFullPathName()) & FILE_ATTRIBUTE_HIDDEN) != 0;
  180654. }
  180655. bool juce_deleteFile (const String& fileName)
  180656. {
  180657. if (juce_isDirectory (fileName))
  180658. return RemoveDirectory (fileName) != 0;
  180659. return DeleteFile (fileName) != 0;
  180660. }
  180661. bool File::moveToTrash() const
  180662. {
  180663. if (! exists())
  180664. return true;
  180665. SHFILEOPSTRUCT fos;
  180666. zerostruct (fos);
  180667. // The string we pass in must be double null terminated..
  180668. String doubleNullTermPath (getFullPathName() + " ");
  180669. TCHAR* p = (TCHAR*) (const TCHAR*) doubleNullTermPath;
  180670. p [getFullPathName().length()] = 0;
  180671. fos.wFunc = FO_DELETE;
  180672. fos.hwnd = (HWND) 0;
  180673. fos.pFrom = p;
  180674. fos.pTo = NULL;
  180675. fos.fFlags = FOF_ALLOWUNDO | FOF_NOERRORUI | FOF_SILENT | FOF_NOCONFIRMATION
  180676. | FOF_NOCONFIRMMKDIR | FOF_RENAMEONCOLLISION;
  180677. return SHFileOperation (&fos) == 0;
  180678. }
  180679. bool juce_moveFile (const String& source, const String& dest)
  180680. {
  180681. return MoveFile (source, dest) != 0;
  180682. }
  180683. bool juce_copyFile (const String& source, const String& dest)
  180684. {
  180685. return CopyFile (source, dest, false) != 0;
  180686. }
  180687. void juce_createDirectory (const String& fileName)
  180688. {
  180689. if (! juce_fileExists (fileName, true))
  180690. {
  180691. CreateDirectory (fileName, 0);
  180692. }
  180693. }
  180694. // return 0 if not possible
  180695. void* juce_fileOpen (const String& fileName, bool forWriting)
  180696. {
  180697. HANDLE h;
  180698. if (forWriting)
  180699. {
  180700. h = CreateFile (fileName, GENERIC_WRITE, FILE_SHARE_READ, 0,
  180701. OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0);
  180702. if (h != INVALID_HANDLE_VALUE)
  180703. SetFilePointer (h, 0, 0, FILE_END);
  180704. else
  180705. h = 0;
  180706. }
  180707. else
  180708. {
  180709. h = CreateFile (fileName, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, 0,
  180710. OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_SEQUENTIAL_SCAN, 0);
  180711. if (h == INVALID_HANDLE_VALUE)
  180712. h = 0;
  180713. }
  180714. return (void*) h;
  180715. }
  180716. void juce_fileClose (void* handle)
  180717. {
  180718. CloseHandle (handle);
  180719. }
  180720. int juce_fileRead (void* handle, void* buffer, int size)
  180721. {
  180722. DWORD num = 0;
  180723. ReadFile ((HANDLE) handle, buffer, size, &num, 0);
  180724. return num;
  180725. }
  180726. int juce_fileWrite (void* handle, const void* buffer, int size)
  180727. {
  180728. DWORD num;
  180729. WriteFile ((HANDLE) handle,
  180730. buffer, size,
  180731. &num, 0);
  180732. return num;
  180733. }
  180734. int64 juce_fileSetPosition (void* handle, int64 pos)
  180735. {
  180736. LARGE_INTEGER li;
  180737. li.QuadPart = pos;
  180738. li.LowPart = SetFilePointer ((HANDLE) handle,
  180739. li.LowPart,
  180740. &li.HighPart,
  180741. FILE_BEGIN); // (returns -1 if it fails)
  180742. return li.QuadPart;
  180743. }
  180744. int64 juce_fileGetPosition (void* handle)
  180745. {
  180746. LARGE_INTEGER li;
  180747. li.QuadPart = 0;
  180748. li.LowPart = SetFilePointer ((HANDLE) handle,
  180749. 0, &li.HighPart,
  180750. FILE_CURRENT); // (returns -1 if it fails)
  180751. return jmax ((int64) 0, li.QuadPart);
  180752. }
  180753. void juce_fileFlush (void* handle)
  180754. {
  180755. FlushFileBuffers ((HANDLE) handle);
  180756. }
  180757. int64 juce_getFileSize (const String& fileName)
  180758. {
  180759. WIN32_FILE_ATTRIBUTE_DATA attributes;
  180760. if (GetFileAttributesEx (fileName, GetFileExInfoStandard, &attributes))
  180761. {
  180762. return (((int64) attributes.nFileSizeHigh) << 32)
  180763. | attributes.nFileSizeLow;
  180764. }
  180765. return 0;
  180766. }
  180767. static int64 fileTimeToTime (const FILETIME* const ft)
  180768. {
  180769. // tell me if this fails!
  180770. static_jassert (sizeof (ULARGE_INTEGER) == sizeof (FILETIME));
  180771. #if JUCE_GCC
  180772. return (((const ULARGE_INTEGER*) ft)->QuadPart - 116444736000000000LL) / 10000;
  180773. #else
  180774. return (((const ULARGE_INTEGER*) ft)->QuadPart - 116444736000000000) / 10000;
  180775. #endif
  180776. }
  180777. static void timeToFileTime (const int64 time, FILETIME* const ft)
  180778. {
  180779. #if JUCE_GCC
  180780. ((ULARGE_INTEGER*) ft)->QuadPart = time * 10000 + 116444736000000000LL;
  180781. #else
  180782. ((ULARGE_INTEGER*) ft)->QuadPart = time * 10000 + 116444736000000000;
  180783. #endif
  180784. }
  180785. void juce_getFileTimes (const String& fileName,
  180786. int64& modificationTime,
  180787. int64& accessTime,
  180788. int64& creationTime)
  180789. {
  180790. WIN32_FILE_ATTRIBUTE_DATA attributes;
  180791. if (GetFileAttributesEx (fileName, GetFileExInfoStandard, &attributes))
  180792. {
  180793. modificationTime = fileTimeToTime (&attributes.ftLastWriteTime);
  180794. creationTime = fileTimeToTime (&attributes.ftCreationTime);
  180795. accessTime = fileTimeToTime (&attributes.ftLastAccessTime);
  180796. }
  180797. else
  180798. {
  180799. creationTime = accessTime = modificationTime = 0;
  180800. }
  180801. }
  180802. bool juce_setFileTimes (const String& fileName,
  180803. int64 modificationTime,
  180804. int64 accessTime,
  180805. int64 creationTime)
  180806. {
  180807. FILETIME m, a, c;
  180808. if (modificationTime > 0)
  180809. timeToFileTime (modificationTime, &m);
  180810. if (accessTime > 0)
  180811. timeToFileTime (accessTime, &a);
  180812. if (creationTime > 0)
  180813. timeToFileTime (creationTime, &c);
  180814. void* const h = juce_fileOpen (fileName, true);
  180815. bool ok = false;
  180816. if (h != 0)
  180817. {
  180818. ok = SetFileTime ((HANDLE) h,
  180819. (creationTime > 0) ? &c : 0,
  180820. (accessTime > 0) ? &a : 0,
  180821. (modificationTime > 0) ? &m : 0) != 0;
  180822. juce_fileClose (h);
  180823. }
  180824. return ok;
  180825. }
  180826. // return '\0' separated list of strings
  180827. const StringArray juce_getFileSystemRoots()
  180828. {
  180829. TCHAR buffer [2048];
  180830. buffer[0] = 0;
  180831. buffer[1] = 0;
  180832. GetLogicalDriveStrings (2048, buffer);
  180833. TCHAR* n = buffer;
  180834. StringArray roots;
  180835. while (*n != 0)
  180836. {
  180837. roots.add (String (n));
  180838. while (*n++ != 0)
  180839. {
  180840. }
  180841. }
  180842. roots.sort (true);
  180843. return roots;
  180844. }
  180845. const String juce_getVolumeLabel (const String& filenameOnVolume,
  180846. int& volumeSerialNumber)
  180847. {
  180848. TCHAR n [4];
  180849. n[0] = *(const TCHAR*) filenameOnVolume;
  180850. n[1] = L':';
  180851. n[2] = L'\\';
  180852. n[3] = 0;
  180853. TCHAR dest [64];
  180854. DWORD serialNum;
  180855. if (! GetVolumeInformation (n, dest, 64, (DWORD*) &serialNum, 0, 0, 0, 0))
  180856. {
  180857. dest[0] = 0;
  180858. serialNum = 0;
  180859. }
  180860. volumeSerialNumber = serialNum;
  180861. return String (dest);
  180862. }
  180863. static int64 getDiskSpaceInfo (String fn, const bool total)
  180864. {
  180865. if (fn[1] == T(':'))
  180866. fn = fn.substring (0, 2) + T("\\");
  180867. ULARGE_INTEGER spc, tot, totFree;
  180868. if (GetDiskFreeSpaceEx (fn, &spc, &tot, &totFree))
  180869. return (int64) (total ? tot.QuadPart
  180870. : spc.QuadPart);
  180871. return 0;
  180872. }
  180873. int64 File::getBytesFreeOnVolume() const
  180874. {
  180875. return getDiskSpaceInfo (getFullPathName(), false);
  180876. }
  180877. int64 File::getVolumeTotalSize() const
  180878. {
  180879. return getDiskSpaceInfo (getFullPathName(), true);
  180880. }
  180881. static unsigned int getWindowsDriveType (const String& fileName)
  180882. {
  180883. TCHAR n[4];
  180884. n[0] = *(const TCHAR*) fileName;
  180885. n[1] = L':';
  180886. n[2] = L'\\';
  180887. n[3] = 0;
  180888. return GetDriveType (n);
  180889. }
  180890. bool File::isOnCDRomDrive() const
  180891. {
  180892. return getWindowsDriveType (getFullPathName()) == DRIVE_CDROM;
  180893. }
  180894. bool File::isOnHardDisk() const
  180895. {
  180896. if (fullPath.isEmpty())
  180897. return false;
  180898. const unsigned int n = getWindowsDriveType (getFullPathName());
  180899. if (fullPath.toLowerCase()[0] <= 'b'
  180900. && fullPath[1] == T(':'))
  180901. {
  180902. return n != DRIVE_REMOVABLE;
  180903. }
  180904. else
  180905. {
  180906. return n != DRIVE_CDROM && n != DRIVE_REMOTE;
  180907. }
  180908. }
  180909. bool File::isOnRemovableDrive() const
  180910. {
  180911. if (fullPath.isEmpty())
  180912. return false;
  180913. const unsigned int n = getWindowsDriveType (getFullPathName());
  180914. return n == DRIVE_CDROM
  180915. || n == DRIVE_REMOTE
  180916. || n == DRIVE_REMOVABLE
  180917. || n == DRIVE_RAMDISK;
  180918. }
  180919. #define MAX_PATH_CHARS (MAX_PATH + 256)
  180920. static const File juce_getSpecialFolderPath (int type)
  180921. {
  180922. WCHAR path [MAX_PATH_CHARS];
  180923. if (SHGetSpecialFolderPath (0, path, type, 0))
  180924. return File (String (path));
  180925. return File::nonexistent;
  180926. }
  180927. const File JUCE_CALLTYPE File::getSpecialLocation (const SpecialLocationType type)
  180928. {
  180929. int csidlType = 0;
  180930. switch (type)
  180931. {
  180932. case userHomeDirectory:
  180933. csidlType = CSIDL_PROFILE;
  180934. break;
  180935. case userDocumentsDirectory:
  180936. csidlType = CSIDL_PERSONAL;
  180937. break;
  180938. case userDesktopDirectory:
  180939. csidlType = CSIDL_DESKTOP;
  180940. break;
  180941. case userApplicationDataDirectory:
  180942. csidlType = CSIDL_APPDATA;
  180943. break;
  180944. case commonApplicationDataDirectory:
  180945. csidlType = CSIDL_COMMON_APPDATA;
  180946. break;
  180947. case globalApplicationsDirectory:
  180948. csidlType = CSIDL_PROGRAM_FILES;
  180949. break;
  180950. case userMusicDirectory:
  180951. csidlType = CSIDL_MYMUSIC;
  180952. break;
  180953. case userMoviesDirectory:
  180954. csidlType = CSIDL_MYVIDEO;
  180955. break;
  180956. case tempDirectory:
  180957. {
  180958. WCHAR dest [2048];
  180959. dest[0] = 0;
  180960. GetTempPath (2048, dest);
  180961. return File (String (dest));
  180962. }
  180963. case invokedExecutableFile:
  180964. case currentExecutableFile:
  180965. case currentApplicationFile:
  180966. {
  180967. HINSTANCE moduleHandle = (HINSTANCE) PlatformUtilities::getCurrentModuleInstanceHandle();
  180968. WCHAR dest [MAX_PATH_CHARS];
  180969. dest[0] = 0;
  180970. GetModuleFileName (moduleHandle, dest, MAX_PATH_CHARS);
  180971. return File (String (dest));
  180972. }
  180973. break;
  180974. default:
  180975. jassertfalse // unknown type?
  180976. return File::nonexistent;
  180977. }
  180978. return juce_getSpecialFolderPath (csidlType);
  180979. }
  180980. const File File::getCurrentWorkingDirectory()
  180981. {
  180982. WCHAR dest [MAX_PATH_CHARS];
  180983. dest[0] = 0;
  180984. GetCurrentDirectory (MAX_PATH_CHARS, dest);
  180985. return File (String (dest));
  180986. }
  180987. bool File::setAsCurrentWorkingDirectory() const
  180988. {
  180989. return SetCurrentDirectory (getFullPathName()) != FALSE;
  180990. }
  180991. const String File::getVersion() const
  180992. {
  180993. String result;
  180994. DWORD handle = 0;
  180995. DWORD bufferSize = GetFileVersionInfoSize (getFullPathName(), &handle);
  180996. HeapBlock <char> buffer;
  180997. buffer.calloc (bufferSize);
  180998. if (GetFileVersionInfo (getFullPathName(), 0, bufferSize, buffer))
  180999. {
  181000. VS_FIXEDFILEINFO* vffi;
  181001. UINT len = 0;
  181002. if (VerQueryValue (buffer, _T("\\"), (LPVOID*) &vffi, &len))
  181003. {
  181004. result << (int) HIWORD (vffi->dwFileVersionMS) << "."
  181005. << (int) LOWORD (vffi->dwFileVersionMS) << "."
  181006. << (int) HIWORD (vffi->dwFileVersionLS) << "."
  181007. << (int) LOWORD (vffi->dwFileVersionLS);
  181008. }
  181009. }
  181010. return result;
  181011. }
  181012. const File File::getLinkedTarget() const
  181013. {
  181014. File result (*this);
  181015. String p (getFullPathName());
  181016. if (! exists())
  181017. p += T(".lnk");
  181018. else if (getFileExtension() != T(".lnk"))
  181019. return result;
  181020. ComSmartPtr <IShellLink> shellLink;
  181021. if (SUCCEEDED (shellLink.CoCreateInstance (CLSID_ShellLink, CLSCTX_INPROC_SERVER)))
  181022. {
  181023. ComSmartPtr <IPersistFile> persistFile;
  181024. if (SUCCEEDED (shellLink->QueryInterface (IID_IPersistFile, (LPVOID*) &persistFile)))
  181025. {
  181026. if (SUCCEEDED (persistFile->Load ((const WCHAR*) p, STGM_READ))
  181027. && SUCCEEDED (shellLink->Resolve (0, SLR_ANY_MATCH | SLR_NO_UI)))
  181028. {
  181029. WIN32_FIND_DATA winFindData;
  181030. WCHAR resolvedPath [MAX_PATH];
  181031. if (SUCCEEDED (shellLink->GetPath (resolvedPath, MAX_PATH, &winFindData, SLGP_UNCPRIORITY)))
  181032. result = File (resolvedPath);
  181033. }
  181034. }
  181035. }
  181036. return result;
  181037. }
  181038. template <class FindDataType>
  181039. static void getFindFileInfo (FindDataType& findData,
  181040. String& filename, bool* const isDir, bool* const isHidden,
  181041. int64* const fileSize, Time* const modTime, Time* const creationTime,
  181042. bool* const isReadOnly)
  181043. {
  181044. filename = findData.cFileName;
  181045. if (isDir != 0)
  181046. *isDir = ((findData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0);
  181047. if (isHidden != 0)
  181048. *isHidden = ((findData.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN) != 0);
  181049. if (fileSize != 0)
  181050. *fileSize = findData.nFileSizeLow + (((int64) findData.nFileSizeHigh) << 32);
  181051. if (modTime != 0)
  181052. *modTime = fileTimeToTime (&findData.ftLastWriteTime);
  181053. if (creationTime != 0)
  181054. *creationTime = fileTimeToTime (&findData.ftCreationTime);
  181055. if (isReadOnly != 0)
  181056. *isReadOnly = ((findData.dwFileAttributes & FILE_ATTRIBUTE_READONLY) != 0);
  181057. }
  181058. void* juce_findFileStart (const String& directory, const String& wildCard, String& firstResult,
  181059. bool* isDir, bool* isHidden, int64* fileSize,
  181060. Time* modTime, Time* creationTime, bool* isReadOnly)
  181061. {
  181062. String wc (directory);
  181063. if (! wc.endsWithChar (File::separator))
  181064. wc += File::separator;
  181065. wc += wildCard;
  181066. WIN32_FIND_DATA findData;
  181067. HANDLE h = FindFirstFile (wc, &findData);
  181068. if (h != INVALID_HANDLE_VALUE)
  181069. {
  181070. getFindFileInfo (findData, firstResult, isDir, isHidden, fileSize,
  181071. modTime, creationTime, isReadOnly);
  181072. return h;
  181073. }
  181074. firstResult = String::empty;
  181075. return 0;
  181076. }
  181077. bool juce_findFileNext (void* handle, String& resultFile,
  181078. bool* isDir, bool* isHidden, int64* fileSize,
  181079. Time* modTime, Time* creationTime, bool* isReadOnly)
  181080. {
  181081. WIN32_FIND_DATA findData;
  181082. if (handle != 0 && FindNextFile ((HANDLE) handle, &findData) != 0)
  181083. {
  181084. getFindFileInfo (findData, resultFile, isDir, isHidden, fileSize,
  181085. modTime, creationTime, isReadOnly);
  181086. return true;
  181087. }
  181088. resultFile = String::empty;
  181089. return false;
  181090. }
  181091. void juce_findFileClose (void* handle)
  181092. {
  181093. FindClose (handle);
  181094. }
  181095. bool juce_launchFile (const String& fileName,
  181096. const String& parameters)
  181097. {
  181098. HINSTANCE hInstance = 0;
  181099. JUCE_TRY
  181100. {
  181101. hInstance = ShellExecute (0, 0, fileName, parameters, 0, SW_SHOWDEFAULT);
  181102. }
  181103. JUCE_CATCH_ALL
  181104. return hInstance > (HINSTANCE) 32;
  181105. }
  181106. void File::revealToUser() const
  181107. {
  181108. if (isDirectory())
  181109. startAsProcess();
  181110. else if (getParentDirectory().exists())
  181111. getParentDirectory().startAsProcess();
  181112. }
  181113. struct NamedPipeInternal
  181114. {
  181115. HANDLE pipeH;
  181116. HANDLE cancelEvent;
  181117. bool connected, createdPipe;
  181118. NamedPipeInternal()
  181119. : pipeH (0),
  181120. cancelEvent (0),
  181121. connected (false),
  181122. createdPipe (false)
  181123. {
  181124. cancelEvent = CreateEvent (0, FALSE, FALSE, 0);
  181125. }
  181126. ~NamedPipeInternal()
  181127. {
  181128. disconnect();
  181129. if (pipeH != 0)
  181130. CloseHandle (pipeH);
  181131. CloseHandle (cancelEvent);
  181132. }
  181133. bool connect (const int timeOutMs)
  181134. {
  181135. if (! createdPipe)
  181136. return true;
  181137. if (! connected)
  181138. {
  181139. OVERLAPPED over;
  181140. zerostruct (over);
  181141. over.hEvent = CreateEvent (0, TRUE, FALSE, 0);
  181142. if (ConnectNamedPipe (pipeH, &over))
  181143. {
  181144. connected = false; // yes, you read that right. In overlapped mode it should always return 0.
  181145. }
  181146. else
  181147. {
  181148. const int err = GetLastError();
  181149. if (err == ERROR_IO_PENDING || err == ERROR_PIPE_LISTENING)
  181150. {
  181151. HANDLE handles[] = { over.hEvent, cancelEvent };
  181152. if (WaitForMultipleObjects (2, handles, FALSE,
  181153. timeOutMs >= 0 ? timeOutMs : INFINITE) == WAIT_OBJECT_0)
  181154. connected = true;
  181155. }
  181156. else if (err == ERROR_PIPE_CONNECTED)
  181157. {
  181158. connected = true;
  181159. }
  181160. }
  181161. CloseHandle (over.hEvent);
  181162. }
  181163. return connected;
  181164. }
  181165. void disconnect()
  181166. {
  181167. if (connected)
  181168. {
  181169. DisconnectNamedPipe (pipeH);
  181170. connected = false;
  181171. }
  181172. }
  181173. };
  181174. void NamedPipe::close()
  181175. {
  181176. NamedPipeInternal* const intern = (NamedPipeInternal*) internal;
  181177. delete intern;
  181178. internal = 0;
  181179. }
  181180. bool NamedPipe::openInternal (const String& pipeName, const bool createPipe)
  181181. {
  181182. close();
  181183. NamedPipeInternal* const intern = new NamedPipeInternal();
  181184. String file ("\\\\.\\pipe\\");
  181185. file += pipeName;
  181186. intern->createdPipe = createPipe;
  181187. if (createPipe)
  181188. {
  181189. intern->pipeH = CreateNamedPipe (file, PIPE_ACCESS_DUPLEX | FILE_FLAG_OVERLAPPED, 0,
  181190. PIPE_UNLIMITED_INSTANCES,
  181191. 4096, 4096, 0, NULL);
  181192. }
  181193. else
  181194. {
  181195. intern->pipeH = CreateFile (file, GENERIC_READ | GENERIC_WRITE, 0, 0, OPEN_EXISTING,
  181196. FILE_FLAG_OVERLAPPED, 0);
  181197. }
  181198. if (intern->pipeH != INVALID_HANDLE_VALUE)
  181199. {
  181200. internal = intern;
  181201. return true;
  181202. }
  181203. delete intern;
  181204. return false;
  181205. }
  181206. int NamedPipe::read (void* destBuffer, int maxBytesToRead, int timeOutMilliseconds)
  181207. {
  181208. int bytesRead = -1;
  181209. bool waitAgain = true;
  181210. while (waitAgain && internal != 0)
  181211. {
  181212. NamedPipeInternal* const intern = (NamedPipeInternal*) internal;
  181213. waitAgain = false;
  181214. if (! intern->connect (timeOutMilliseconds))
  181215. break;
  181216. if (maxBytesToRead <= 0)
  181217. return 0;
  181218. OVERLAPPED over;
  181219. zerostruct (over);
  181220. over.hEvent = CreateEvent (0, TRUE, FALSE, 0);
  181221. unsigned long numRead;
  181222. if (ReadFile (intern->pipeH, destBuffer, maxBytesToRead, &numRead, &over))
  181223. {
  181224. bytesRead = (int) numRead;
  181225. }
  181226. else if (GetLastError() == ERROR_IO_PENDING)
  181227. {
  181228. HANDLE handles[] = { over.hEvent, intern->cancelEvent };
  181229. DWORD waitResult = WaitForMultipleObjects (2, handles, FALSE,
  181230. timeOutMilliseconds >= 0 ? timeOutMilliseconds
  181231. : INFINITE);
  181232. if (waitResult != WAIT_OBJECT_0)
  181233. {
  181234. // if the operation timed out, let's cancel it...
  181235. CancelIo (intern->pipeH);
  181236. WaitForSingleObject (over.hEvent, INFINITE); // makes sure cancel is complete
  181237. }
  181238. if (GetOverlappedResult (intern->pipeH, &over, &numRead, FALSE))
  181239. {
  181240. bytesRead = (int) numRead;
  181241. }
  181242. else if (GetLastError() == ERROR_BROKEN_PIPE && intern->createdPipe)
  181243. {
  181244. intern->disconnect();
  181245. waitAgain = true;
  181246. }
  181247. }
  181248. else
  181249. {
  181250. waitAgain = internal != 0;
  181251. Sleep (5);
  181252. }
  181253. CloseHandle (over.hEvent);
  181254. }
  181255. return bytesRead;
  181256. }
  181257. int NamedPipe::write (const void* sourceBuffer, int numBytesToWrite, int timeOutMilliseconds)
  181258. {
  181259. int bytesWritten = -1;
  181260. NamedPipeInternal* const intern = (NamedPipeInternal*) internal;
  181261. if (intern != 0 && intern->connect (timeOutMilliseconds))
  181262. {
  181263. if (numBytesToWrite <= 0)
  181264. return 0;
  181265. OVERLAPPED over;
  181266. zerostruct (over);
  181267. over.hEvent = CreateEvent (0, TRUE, FALSE, 0);
  181268. unsigned long numWritten;
  181269. if (WriteFile (intern->pipeH, sourceBuffer, numBytesToWrite, &numWritten, &over))
  181270. {
  181271. bytesWritten = (int) numWritten;
  181272. }
  181273. else if (GetLastError() == ERROR_IO_PENDING)
  181274. {
  181275. HANDLE handles[] = { over.hEvent, intern->cancelEvent };
  181276. DWORD waitResult;
  181277. waitResult = WaitForMultipleObjects (2, handles, FALSE,
  181278. timeOutMilliseconds >= 0 ? timeOutMilliseconds
  181279. : INFINITE);
  181280. if (waitResult != WAIT_OBJECT_0)
  181281. {
  181282. CancelIo (intern->pipeH);
  181283. WaitForSingleObject (over.hEvent, INFINITE);
  181284. }
  181285. if (GetOverlappedResult (intern->pipeH, &over, &numWritten, FALSE))
  181286. {
  181287. bytesWritten = (int) numWritten;
  181288. }
  181289. else if (GetLastError() == ERROR_BROKEN_PIPE && intern->createdPipe)
  181290. {
  181291. intern->disconnect();
  181292. }
  181293. }
  181294. CloseHandle (over.hEvent);
  181295. }
  181296. return bytesWritten;
  181297. }
  181298. void NamedPipe::cancelPendingReads()
  181299. {
  181300. NamedPipeInternal* const intern = (NamedPipeInternal*) internal;
  181301. if (intern != 0)
  181302. SetEvent (intern->cancelEvent);
  181303. }
  181304. #endif
  181305. /********* End of inlined file: juce_win32_Files.cpp *********/
  181306. /********* Start of inlined file: juce_win32_Network.cpp *********/
  181307. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  181308. // compiled on its own).
  181309. #if JUCE_INCLUDED_FILE
  181310. #ifndef INTERNET_FLAG_NEED_FILE
  181311. #define INTERNET_FLAG_NEED_FILE 0x00000010
  181312. #endif
  181313. bool juce_isOnLine()
  181314. {
  181315. DWORD connectionType;
  181316. return InternetGetConnectedState (&connectionType, 0) != 0
  181317. || (connectionType & (INTERNET_CONNECTION_LAN | INTERNET_CONNECTION_PROXY)) != 0;
  181318. }
  181319. struct ConnectionAndRequestStruct
  181320. {
  181321. HINTERNET connection, request;
  181322. };
  181323. static HINTERNET sessionHandle = 0;
  181324. void* juce_openInternetFile (const String& url,
  181325. const String& headers,
  181326. const MemoryBlock& postData,
  181327. const bool isPost,
  181328. URL::OpenStreamProgressCallback* callback,
  181329. void* callbackContext,
  181330. int timeOutMs)
  181331. {
  181332. if (sessionHandle == 0)
  181333. sessionHandle = InternetOpen (_T("juce"),
  181334. INTERNET_OPEN_TYPE_PRECONFIG,
  181335. 0, 0, 0);
  181336. if (sessionHandle != 0)
  181337. {
  181338. // break up the url..
  181339. TCHAR file[1024], server[1024];
  181340. URL_COMPONENTS uc;
  181341. zerostruct (uc);
  181342. uc.dwStructSize = sizeof (uc);
  181343. uc.dwUrlPathLength = sizeof (file);
  181344. uc.dwHostNameLength = sizeof (server);
  181345. uc.lpszUrlPath = file;
  181346. uc.lpszHostName = server;
  181347. if (InternetCrackUrl (url, 0, 0, &uc))
  181348. {
  181349. if (timeOutMs == 0)
  181350. timeOutMs = 30000;
  181351. else if (timeOutMs < 0)
  181352. timeOutMs = -1;
  181353. InternetSetOption (sessionHandle, INTERNET_OPTION_CONNECT_TIMEOUT, &timeOutMs, sizeof (timeOutMs));
  181354. const bool isFtp = url.startsWithIgnoreCase (T("ftp:"));
  181355. HINTERNET connection = InternetConnect (sessionHandle,
  181356. uc.lpszHostName,
  181357. uc.nPort,
  181358. _T(""), _T(""),
  181359. isFtp ? INTERNET_SERVICE_FTP
  181360. : INTERNET_SERVICE_HTTP,
  181361. 0, 0);
  181362. if (connection != 0)
  181363. {
  181364. if (isFtp)
  181365. {
  181366. HINTERNET request = FtpOpenFile (connection,
  181367. uc.lpszUrlPath,
  181368. GENERIC_READ,
  181369. FTP_TRANSFER_TYPE_BINARY | INTERNET_FLAG_NEED_FILE,
  181370. 0);
  181371. ConnectionAndRequestStruct* const result = new ConnectionAndRequestStruct();
  181372. result->connection = connection;
  181373. result->request = request;
  181374. return result;
  181375. }
  181376. else
  181377. {
  181378. const TCHAR* mimeTypes[] = { _T("*/*"), 0 };
  181379. DWORD flags = INTERNET_FLAG_RELOAD | INTERNET_FLAG_NO_CACHE_WRITE;
  181380. if (url.startsWithIgnoreCase (T("https:")))
  181381. flags |= INTERNET_FLAG_SECURE; // (this flag only seems necessary if the OS is running IE6 -
  181382. // IE7 seems to automatically work out when it's https)
  181383. HINTERNET request = HttpOpenRequest (connection,
  181384. isPost ? _T("POST")
  181385. : _T("GET"),
  181386. uc.lpszUrlPath,
  181387. 0, 0, mimeTypes, flags, 0);
  181388. if (request != 0)
  181389. {
  181390. INTERNET_BUFFERS buffers;
  181391. zerostruct (buffers);
  181392. buffers.dwStructSize = sizeof (INTERNET_BUFFERS);
  181393. buffers.lpcszHeader = (LPCTSTR) headers;
  181394. buffers.dwHeadersLength = headers.length();
  181395. buffers.dwBufferTotal = (DWORD) postData.getSize();
  181396. ConnectionAndRequestStruct* result = 0;
  181397. if (HttpSendRequestEx (request, &buffers, 0, HSR_INITIATE, 0))
  181398. {
  181399. int bytesSent = 0;
  181400. for (;;)
  181401. {
  181402. const int bytesToDo = jmin (1024, (int) postData.getSize() - bytesSent);
  181403. DWORD bytesDone = 0;
  181404. if (bytesToDo > 0
  181405. && ! InternetWriteFile (request,
  181406. ((const char*) postData.getData()) + bytesSent,
  181407. bytesToDo, &bytesDone))
  181408. {
  181409. break;
  181410. }
  181411. if (bytesToDo == 0 || (int) bytesDone < bytesToDo)
  181412. {
  181413. result = new ConnectionAndRequestStruct();
  181414. result->connection = connection;
  181415. result->request = request;
  181416. HttpEndRequest (request, 0, 0, 0);
  181417. return result;
  181418. }
  181419. bytesSent += bytesDone;
  181420. if (callback != 0 && ! callback (callbackContext, bytesSent, postData.getSize()))
  181421. break;
  181422. }
  181423. }
  181424. InternetCloseHandle (request);
  181425. }
  181426. InternetCloseHandle (connection);
  181427. }
  181428. }
  181429. }
  181430. }
  181431. return 0;
  181432. }
  181433. int juce_readFromInternetFile (void* handle, void* buffer, int bytesToRead)
  181434. {
  181435. DWORD bytesRead = 0;
  181436. const ConnectionAndRequestStruct* const crs = (const ConnectionAndRequestStruct*) handle;
  181437. if (crs != 0)
  181438. InternetReadFile (crs->request,
  181439. buffer, bytesToRead,
  181440. &bytesRead);
  181441. return bytesRead;
  181442. }
  181443. int juce_seekInInternetFile (void* handle, int newPosition)
  181444. {
  181445. if (handle != 0)
  181446. {
  181447. const ConnectionAndRequestStruct* const crs = (const ConnectionAndRequestStruct*) handle;
  181448. return InternetSetFilePointer (crs->request,
  181449. newPosition, 0,
  181450. FILE_BEGIN, 0);
  181451. }
  181452. else
  181453. {
  181454. return -1;
  181455. }
  181456. }
  181457. int64 juce_getInternetFileContentLength (void* handle)
  181458. {
  181459. const ConnectionAndRequestStruct* const crs = (const ConnectionAndRequestStruct*) handle;
  181460. if (crs != 0)
  181461. {
  181462. DWORD index = 0;
  181463. DWORD result = 0;
  181464. DWORD size = sizeof (result);
  181465. if (HttpQueryInfo (crs->request,
  181466. HTTP_QUERY_CONTENT_LENGTH | HTTP_QUERY_FLAG_NUMBER,
  181467. &result,
  181468. &size,
  181469. &index))
  181470. {
  181471. return (int64) result;
  181472. }
  181473. }
  181474. return -1;
  181475. }
  181476. void juce_closeInternetFile (void* handle)
  181477. {
  181478. if (handle != 0)
  181479. {
  181480. ConnectionAndRequestStruct* const crs = (ConnectionAndRequestStruct*) handle;
  181481. InternetCloseHandle (crs->request);
  181482. InternetCloseHandle (crs->connection);
  181483. delete crs;
  181484. }
  181485. }
  181486. static int getMACAddressViaGetAdaptersInfo (int64* addresses, int maxNum, const bool littleEndian) throw()
  181487. {
  181488. int numFound = 0;
  181489. DynamicLibraryLoader dll ("iphlpapi.dll");
  181490. DynamicLibraryImport (GetAdaptersInfo, getAdaptersInfo, DWORD, dll, (PIP_ADAPTER_INFO, PULONG))
  181491. if (getAdaptersInfo != 0)
  181492. {
  181493. ULONG len = sizeof (IP_ADAPTER_INFO);
  181494. MemoryBlock mb;
  181495. PIP_ADAPTER_INFO adapterInfo = (PIP_ADAPTER_INFO) mb.getData();
  181496. if (getAdaptersInfo (adapterInfo, &len) == ERROR_BUFFER_OVERFLOW)
  181497. {
  181498. mb.setSize (len);
  181499. adapterInfo = (PIP_ADAPTER_INFO) mb.getData();
  181500. }
  181501. if (getAdaptersInfo (adapterInfo, &len) == NO_ERROR)
  181502. {
  181503. PIP_ADAPTER_INFO adapter = adapterInfo;
  181504. while (adapter != 0)
  181505. {
  181506. int64 mac = 0;
  181507. for (unsigned int i = 0; i < adapter->AddressLength; ++i)
  181508. mac = (mac << 8) | adapter->Address[i];
  181509. if (littleEndian)
  181510. mac = (int64) ByteOrder::swap ((uint64) mac);
  181511. if (numFound < maxNum && mac != 0)
  181512. addresses [numFound++] = mac;
  181513. adapter = adapter->Next;
  181514. }
  181515. }
  181516. }
  181517. return numFound;
  181518. }
  181519. struct ASTAT
  181520. {
  181521. ADAPTER_STATUS adapt;
  181522. NAME_BUFFER NameBuff [30];
  181523. };
  181524. static int getMACAddressesViaNetBios (int64* addresses, int maxNum, const bool littleEndian) throw()
  181525. {
  181526. int numFound = 0;
  181527. DynamicLibraryLoader dll ("netapi32.dll");
  181528. DynamicLibraryImport (Netbios, NetbiosCall, UCHAR, dll, (PNCB))
  181529. if (NetbiosCall != 0)
  181530. {
  181531. NCB ncb;
  181532. zerostruct (ncb);
  181533. ASTAT astat;
  181534. zerostruct (astat);
  181535. LANA_ENUM enums;
  181536. zerostruct (enums);
  181537. ncb.ncb_command = NCBENUM;
  181538. ncb.ncb_buffer = (unsigned char*) &enums;
  181539. ncb.ncb_length = sizeof (LANA_ENUM);
  181540. NetbiosCall (&ncb);
  181541. for (int i = 0; i < enums.length; ++i)
  181542. {
  181543. zerostruct (ncb);
  181544. ncb.ncb_command = NCBRESET;
  181545. ncb.ncb_lana_num = enums.lana[i];
  181546. if (NetbiosCall (&ncb) == 0)
  181547. {
  181548. zerostruct (ncb);
  181549. memcpy (ncb.ncb_callname, "* ", NCBNAMSZ);
  181550. ncb.ncb_command = NCBASTAT;
  181551. ncb.ncb_lana_num = enums.lana[i];
  181552. ncb.ncb_buffer = (unsigned char*) &astat;
  181553. ncb.ncb_length = sizeof (ASTAT);
  181554. if (NetbiosCall (&ncb) == 0)
  181555. {
  181556. if (astat.adapt.adapter_type == 0xfe)
  181557. {
  181558. uint64 mac = 0;
  181559. for (int i = 6; --i >= 0;)
  181560. mac = (mac << 8) | astat.adapt.adapter_address [littleEndian ? i : (5 - i)];
  181561. if (numFound < maxNum && mac != 0)
  181562. addresses [numFound++] = mac;
  181563. }
  181564. }
  181565. }
  181566. }
  181567. }
  181568. return numFound;
  181569. }
  181570. int SystemStats::getMACAddresses (int64* addresses, int maxNum, const bool littleEndian) throw()
  181571. {
  181572. int numFound = getMACAddressViaGetAdaptersInfo (addresses, maxNum, littleEndian);
  181573. if (numFound == 0)
  181574. numFound = getMACAddressesViaNetBios (addresses, maxNum, littleEndian);
  181575. return numFound;
  181576. }
  181577. typedef ULONG (WINAPI *MAPISendMailType) (LHANDLE, ULONG, lpMapiMessage, ::FLAGS, ULONG);
  181578. bool PlatformUtilities::launchEmailWithAttachments (const String& targetEmailAddress,
  181579. const String& emailSubject,
  181580. const String& bodyText,
  181581. const StringArray& filesToAttach)
  181582. {
  181583. HMODULE h = LoadLibraryA ("MAPI32.dll");
  181584. MAPISendMailType mapiSendMail = (MAPISendMailType) GetProcAddress (h, "MAPISendMail");
  181585. bool ok = false;
  181586. if (mapiSendMail != 0)
  181587. {
  181588. MapiMessage message;
  181589. zerostruct (message);
  181590. message.lpszSubject = (LPSTR) (LPCSTR) emailSubject;
  181591. message.lpszNoteText = (LPSTR) (LPCSTR) bodyText;
  181592. MapiRecipDesc recip;
  181593. zerostruct (recip);
  181594. recip.ulRecipClass = MAPI_TO;
  181595. String targetEmailAddress_ (targetEmailAddress);
  181596. if (targetEmailAddress_.isEmpty())
  181597. targetEmailAddress_ = " "; // (Windows Mail can't deal with a blank address)
  181598. recip.lpszName = (LPSTR) (LPCSTR) targetEmailAddress_;
  181599. message.nRecipCount = 1;
  181600. message.lpRecips = &recip;
  181601. MemoryBlock mb (sizeof (MapiFileDesc) * filesToAttach.size());
  181602. mb.fillWith (0);
  181603. MapiFileDesc* files = (MapiFileDesc*) mb.getData();
  181604. message.nFileCount = filesToAttach.size();
  181605. message.lpFiles = files;
  181606. for (int i = 0; i < filesToAttach.size(); ++i)
  181607. {
  181608. files[i].nPosition = (ULONG) -1;
  181609. files[i].lpszPathName = (LPSTR) (LPCSTR) filesToAttach [i];
  181610. }
  181611. ok = (mapiSendMail (0, 0, &message, MAPI_DIALOG | MAPI_LOGON_UI, 0) == SUCCESS_SUCCESS);
  181612. }
  181613. FreeLibrary (h);
  181614. return ok;
  181615. }
  181616. #endif
  181617. /********* End of inlined file: juce_win32_Network.cpp *********/
  181618. /********* Start of inlined file: juce_win32_PlatformUtils.cpp *********/
  181619. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  181620. // compiled on its own).
  181621. #if JUCE_INCLUDED_FILE
  181622. static HKEY findKeyForPath (String name,
  181623. const bool createForWriting,
  181624. String& valueName)
  181625. {
  181626. HKEY rootKey = 0;
  181627. if (name.startsWithIgnoreCase (T("HKEY_CURRENT_USER\\")))
  181628. rootKey = HKEY_CURRENT_USER;
  181629. else if (name.startsWithIgnoreCase (T("HKEY_LOCAL_MACHINE\\")))
  181630. rootKey = HKEY_LOCAL_MACHINE;
  181631. else if (name.startsWithIgnoreCase (T("HKEY_CLASSES_ROOT\\")))
  181632. rootKey = HKEY_CLASSES_ROOT;
  181633. if (rootKey != 0)
  181634. {
  181635. name = name.substring (name.indexOfChar (T('\\')) + 1);
  181636. const int lastSlash = name.lastIndexOfChar (T('\\'));
  181637. valueName = name.substring (lastSlash + 1);
  181638. name = name.substring (0, lastSlash);
  181639. HKEY key;
  181640. DWORD result;
  181641. if (createForWriting)
  181642. {
  181643. if (RegCreateKeyEx (rootKey, name, 0, L"", REG_OPTION_NON_VOLATILE,
  181644. (KEY_WRITE | KEY_QUERY_VALUE), 0, &key, &result) == ERROR_SUCCESS)
  181645. return key;
  181646. }
  181647. else
  181648. {
  181649. if (RegOpenKeyEx (rootKey, name, 0, KEY_READ, &key) == ERROR_SUCCESS)
  181650. return key;
  181651. }
  181652. }
  181653. return 0;
  181654. }
  181655. const String PlatformUtilities::getRegistryValue (const String& regValuePath,
  181656. const String& defaultValue)
  181657. {
  181658. String valueName, result (defaultValue);
  181659. HKEY k = findKeyForPath (regValuePath, false, valueName);
  181660. if (k != 0)
  181661. {
  181662. WCHAR buffer [2048];
  181663. unsigned long bufferSize = sizeof (buffer);
  181664. DWORD type = REG_SZ;
  181665. if (RegQueryValueEx (k, valueName, 0, &type, (LPBYTE) buffer, &bufferSize) == ERROR_SUCCESS)
  181666. {
  181667. if (type == REG_SZ)
  181668. result = buffer;
  181669. else if (type == REG_DWORD)
  181670. result = String ((int) *(DWORD*) buffer);
  181671. }
  181672. RegCloseKey (k);
  181673. }
  181674. return result;
  181675. }
  181676. void PlatformUtilities::setRegistryValue (const String& regValuePath,
  181677. const String& value)
  181678. {
  181679. String valueName;
  181680. HKEY k = findKeyForPath (regValuePath, true, valueName);
  181681. if (k != 0)
  181682. {
  181683. RegSetValueEx (k, valueName, 0, REG_SZ,
  181684. (const BYTE*) (const WCHAR*) value,
  181685. sizeof (WCHAR) * (value.length() + 1));
  181686. RegCloseKey (k);
  181687. }
  181688. }
  181689. bool PlatformUtilities::registryValueExists (const String& regValuePath)
  181690. {
  181691. bool exists = false;
  181692. String valueName;
  181693. HKEY k = findKeyForPath (regValuePath, false, valueName);
  181694. if (k != 0)
  181695. {
  181696. unsigned char buffer [2048];
  181697. unsigned long bufferSize = sizeof (buffer);
  181698. DWORD type = 0;
  181699. if (RegQueryValueEx (k, valueName, 0, &type, buffer, &bufferSize) == ERROR_SUCCESS)
  181700. exists = true;
  181701. RegCloseKey (k);
  181702. }
  181703. return exists;
  181704. }
  181705. void PlatformUtilities::deleteRegistryValue (const String& regValuePath)
  181706. {
  181707. String valueName;
  181708. HKEY k = findKeyForPath (regValuePath, true, valueName);
  181709. if (k != 0)
  181710. {
  181711. RegDeleteValue (k, valueName);
  181712. RegCloseKey (k);
  181713. }
  181714. }
  181715. void PlatformUtilities::deleteRegistryKey (const String& regKeyPath)
  181716. {
  181717. String valueName;
  181718. HKEY k = findKeyForPath (regKeyPath, true, valueName);
  181719. if (k != 0)
  181720. {
  181721. RegDeleteKey (k, valueName);
  181722. RegCloseKey (k);
  181723. }
  181724. }
  181725. void PlatformUtilities::registerFileAssociation (const String& fileExtension,
  181726. const String& symbolicDescription,
  181727. const String& fullDescription,
  181728. const File& targetExecutable,
  181729. int iconResourceNumber)
  181730. {
  181731. setRegistryValue ("HKEY_CLASSES_ROOT\\" + fileExtension + "\\", symbolicDescription);
  181732. const String key ("HKEY_CLASSES_ROOT\\" + symbolicDescription);
  181733. if (iconResourceNumber != 0)
  181734. setRegistryValue (key + "\\DefaultIcon\\",
  181735. targetExecutable.getFullPathName() + "," + String (-iconResourceNumber));
  181736. setRegistryValue (key + "\\", fullDescription);
  181737. setRegistryValue (key + "\\shell\\open\\command\\",
  181738. targetExecutable.getFullPathName() + " %1");
  181739. }
  181740. bool juce_IsRunningInWine()
  181741. {
  181742. HKEY key;
  181743. if (RegOpenKeyEx (HKEY_CURRENT_USER, _T("Software\\Wine"), 0, KEY_READ, &key) == ERROR_SUCCESS)
  181744. {
  181745. RegCloseKey (key);
  181746. return true;
  181747. }
  181748. return false;
  181749. }
  181750. const String JUCE_CALLTYPE PlatformUtilities::getCurrentCommandLineParams() throw()
  181751. {
  181752. String s (::GetCommandLineW());
  181753. StringArray tokens;
  181754. tokens.addTokens (s, true); // tokenise so that we can remove the initial filename argument
  181755. return tokens.joinIntoString (T(" "), 1);
  181756. }
  181757. static void* currentModuleHandle = 0;
  181758. void* PlatformUtilities::getCurrentModuleInstanceHandle() throw()
  181759. {
  181760. if (currentModuleHandle == 0)
  181761. currentModuleHandle = GetModuleHandle (0);
  181762. return currentModuleHandle;
  181763. }
  181764. void PlatformUtilities::setCurrentModuleInstanceHandle (void* const newHandle) throw()
  181765. {
  181766. currentModuleHandle = newHandle;
  181767. }
  181768. void PlatformUtilities::fpuReset()
  181769. {
  181770. #if JUCE_MSVC
  181771. _clearfp();
  181772. #endif
  181773. }
  181774. void PlatformUtilities::beep()
  181775. {
  181776. MessageBeep (MB_OK);
  181777. }
  181778. #endif
  181779. /********* End of inlined file: juce_win32_PlatformUtils.cpp *********/
  181780. #if ! JUCE_ONLY_BUILD_CORE_LIBRARY
  181781. /********* Start of inlined file: juce_win32_Messaging.cpp *********/
  181782. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  181783. // compiled on its own).
  181784. #if JUCE_INCLUDED_FILE
  181785. static const unsigned int specialId = WM_APP + 0x4400;
  181786. static const unsigned int broadcastId = WM_APP + 0x4403;
  181787. static const unsigned int specialCallbackId = WM_APP + 0x4402;
  181788. static const TCHAR* const messageWindowName = _T("JUCEWindow");
  181789. HWND juce_messageWindowHandle = 0;
  181790. extern long improbableWindowNumber; // defined in windowing.cpp
  181791. #ifndef WM_APPCOMMAND
  181792. #define WM_APPCOMMAND 0x0319
  181793. #endif
  181794. static LRESULT CALLBACK juce_MessageWndProc (HWND h,
  181795. const UINT message,
  181796. const WPARAM wParam,
  181797. const LPARAM lParam) throw()
  181798. {
  181799. JUCE_TRY
  181800. {
  181801. if (h == juce_messageWindowHandle)
  181802. {
  181803. if (message == specialCallbackId)
  181804. {
  181805. MessageCallbackFunction* const func = (MessageCallbackFunction*) wParam;
  181806. return (LRESULT) (*func) ((void*) lParam);
  181807. }
  181808. else if (message == specialId)
  181809. {
  181810. // these are trapped early in the dispatch call, but must also be checked
  181811. // here in case there are windows modal dialog boxes doing their own
  181812. // dispatch loop and not calling our version
  181813. MessageManager::getInstance()->deliverMessage ((void*) lParam);
  181814. return 0;
  181815. }
  181816. else if (message == broadcastId)
  181817. {
  181818. const ScopedPointer <String> messageString ((String*) lParam);
  181819. MessageManager::getInstance()->deliverBroadcastMessage (*messageString);
  181820. return 0;
  181821. }
  181822. else if (message == WM_COPYDATA && ((const COPYDATASTRUCT*) lParam)->dwData == broadcastId)
  181823. {
  181824. const String messageString ((const juce_wchar*) ((const COPYDATASTRUCT*) lParam)->lpData,
  181825. ((const COPYDATASTRUCT*) lParam)->cbData / sizeof (juce_wchar));
  181826. PostMessage (juce_messageWindowHandle, broadcastId, 0, (LPARAM) new String (messageString));
  181827. return 0;
  181828. }
  181829. }
  181830. }
  181831. JUCE_CATCH_EXCEPTION
  181832. return DefWindowProc (h, message, wParam, lParam);
  181833. }
  181834. static bool isEventBlockedByModalComps (MSG& m)
  181835. {
  181836. if (Component::getNumCurrentlyModalComponents() == 0
  181837. || GetWindowLong (m.hwnd, GWLP_USERDATA) == improbableWindowNumber)
  181838. return false;
  181839. switch (m.message)
  181840. {
  181841. case WM_MOUSEMOVE:
  181842. case WM_NCMOUSEMOVE:
  181843. case 0x020A: /* WM_MOUSEWHEEL */
  181844. case 0x020E: /* WM_MOUSEHWHEEL */
  181845. case WM_KEYUP:
  181846. case WM_SYSKEYUP:
  181847. case WM_CHAR:
  181848. case WM_APPCOMMAND:
  181849. case WM_LBUTTONUP:
  181850. case WM_MBUTTONUP:
  181851. case WM_RBUTTONUP:
  181852. case WM_MOUSEACTIVATE:
  181853. case WM_NCMOUSEHOVER:
  181854. case WM_MOUSEHOVER:
  181855. return true;
  181856. case WM_NCLBUTTONDOWN:
  181857. case WM_NCLBUTTONDBLCLK:
  181858. case WM_NCRBUTTONDOWN:
  181859. case WM_NCRBUTTONDBLCLK:
  181860. case WM_NCMBUTTONDOWN:
  181861. case WM_NCMBUTTONDBLCLK:
  181862. case WM_LBUTTONDOWN:
  181863. case WM_LBUTTONDBLCLK:
  181864. case WM_MBUTTONDOWN:
  181865. case WM_MBUTTONDBLCLK:
  181866. case WM_RBUTTONDOWN:
  181867. case WM_RBUTTONDBLCLK:
  181868. case WM_KEYDOWN:
  181869. case WM_SYSKEYDOWN:
  181870. {
  181871. Component* const modal = Component::getCurrentlyModalComponent (0);
  181872. if (modal != 0)
  181873. modal->inputAttemptWhenModal();
  181874. return true;
  181875. }
  181876. default:
  181877. break;
  181878. }
  181879. return false;
  181880. }
  181881. bool juce_dispatchNextMessageOnSystemQueue (const bool returnIfNoPendingMessages)
  181882. {
  181883. MSG m;
  181884. if (returnIfNoPendingMessages && ! PeekMessage (&m, (HWND) 0, 0, 0, 0))
  181885. return false;
  181886. if (GetMessage (&m, (HWND) 0, 0, 0) >= 0)
  181887. {
  181888. if (m.message == specialId && m.hwnd == juce_messageWindowHandle)
  181889. {
  181890. MessageManager::getInstance()->deliverMessage ((void*) m.lParam);
  181891. }
  181892. else if (m.message == WM_QUIT)
  181893. {
  181894. if (JUCEApplication::getInstance())
  181895. JUCEApplication::getInstance()->systemRequestedQuit();
  181896. }
  181897. else if (! isEventBlockedByModalComps (m))
  181898. {
  181899. if ((m.message == WM_LBUTTONDOWN || m.message == WM_RBUTTONDOWN)
  181900. && GetWindowLong (m.hwnd, GWLP_USERDATA) != improbableWindowNumber)
  181901. {
  181902. // if it's someone else's window being clicked on, and the focus is
  181903. // currently on a juce window, pass the kb focus over..
  181904. HWND currentFocus = GetFocus();
  181905. if (currentFocus == 0 || GetWindowLong (currentFocus, GWLP_USERDATA) == improbableWindowNumber)
  181906. SetFocus (m.hwnd);
  181907. }
  181908. TranslateMessage (&m);
  181909. DispatchMessage (&m);
  181910. }
  181911. }
  181912. return true;
  181913. }
  181914. bool juce_postMessageToSystemQueue (void* message)
  181915. {
  181916. return PostMessage (juce_messageWindowHandle, specialId, 0, (LPARAM) message) != 0;
  181917. }
  181918. void* MessageManager::callFunctionOnMessageThread (MessageCallbackFunction* callback,
  181919. void* userData)
  181920. {
  181921. if (MessageManager::getInstance()->isThisTheMessageThread())
  181922. {
  181923. return (*callback) (userData);
  181924. }
  181925. else
  181926. {
  181927. // If a thread has a MessageManagerLock and then tries to call this method, it'll
  181928. // deadlock because the message manager is blocked from running, and can't
  181929. // call your function..
  181930. jassert (! MessageManager::getInstance()->currentThreadHasLockedMessageManager());
  181931. return (void*) SendMessage (juce_messageWindowHandle,
  181932. specialCallbackId,
  181933. (WPARAM) callback,
  181934. (LPARAM) userData);
  181935. }
  181936. }
  181937. static BOOL CALLBACK BroadcastEnumWindowProc (HWND hwnd, LPARAM lParam)
  181938. {
  181939. if (hwnd != juce_messageWindowHandle)
  181940. (reinterpret_cast <VoidArray*> (lParam))->add ((void*) hwnd);
  181941. return TRUE;
  181942. }
  181943. void MessageManager::broadcastMessage (const String& value) throw()
  181944. {
  181945. VoidArray windows;
  181946. EnumWindows (&BroadcastEnumWindowProc, (LPARAM) &windows);
  181947. const String localCopy (value);
  181948. COPYDATASTRUCT data;
  181949. data.dwData = broadcastId;
  181950. data.cbData = (localCopy.length() + 1) * sizeof (juce_wchar);
  181951. data.lpData = (void*) (const juce_wchar*) localCopy;
  181952. for (int i = windows.size(); --i >= 0;)
  181953. {
  181954. HWND hwnd = (HWND) windows.getUnchecked(i);
  181955. TCHAR windowName [64]; // no need to read longer strings than this
  181956. GetWindowText (hwnd, windowName, 64);
  181957. windowName [63] = 0;
  181958. if (String (windowName) == String (messageWindowName))
  181959. {
  181960. DWORD_PTR result;
  181961. SendMessageTimeout (hwnd, WM_COPYDATA,
  181962. (WPARAM) juce_messageWindowHandle,
  181963. (LPARAM) &data,
  181964. SMTO_BLOCK | SMTO_ABORTIFHUNG,
  181965. 8000,
  181966. &result);
  181967. }
  181968. }
  181969. }
  181970. static const String getMessageWindowClassName()
  181971. {
  181972. // this name has to be different for each app/dll instance because otherwise
  181973. // poor old Win32 can get a bit confused (even despite it not being a process-global
  181974. // window class).
  181975. static int number = 0;
  181976. if (number == 0)
  181977. number = 0x7fffffff & (int) Time::getHighResolutionTicks();
  181978. return T("JUCEcs_") + String (number);
  181979. }
  181980. void MessageManager::doPlatformSpecificInitialisation()
  181981. {
  181982. OleInitialize (0);
  181983. const String className (getMessageWindowClassName());
  181984. HMODULE hmod = (HMODULE) PlatformUtilities::getCurrentModuleInstanceHandle();
  181985. WNDCLASSEX wc;
  181986. zerostruct (wc);
  181987. wc.cbSize = sizeof (wc);
  181988. wc.lpfnWndProc = (WNDPROC) juce_MessageWndProc;
  181989. wc.cbWndExtra = 4;
  181990. wc.hInstance = hmod;
  181991. wc.lpszClassName = className;
  181992. RegisterClassEx (&wc);
  181993. juce_messageWindowHandle = CreateWindow (wc.lpszClassName,
  181994. messageWindowName,
  181995. 0, 0, 0, 0, 0, 0, 0,
  181996. hmod, 0);
  181997. }
  181998. void MessageManager::doPlatformSpecificShutdown()
  181999. {
  182000. DestroyWindow (juce_messageWindowHandle);
  182001. UnregisterClass (getMessageWindowClassName(), 0);
  182002. OleUninitialize();
  182003. }
  182004. #endif
  182005. /********* End of inlined file: juce_win32_Messaging.cpp *********/
  182006. /********* Start of inlined file: juce_win32_Windowing.cpp *********/
  182007. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  182008. // compiled on its own).
  182009. #if JUCE_INCLUDED_FILE
  182010. #undef GetSystemMetrics // multimon overrides this for some reason and causes a mess..
  182011. // these are in the windows SDK, but need to be repeated here for GCC..
  182012. #ifndef GET_APPCOMMAND_LPARAM
  182013. #define FAPPCOMMAND_MASK 0xF000
  182014. #define GET_APPCOMMAND_LPARAM(lParam) ((short) (HIWORD (lParam) & ~FAPPCOMMAND_MASK))
  182015. #define APPCOMMAND_MEDIA_NEXTTRACK 11
  182016. #define APPCOMMAND_MEDIA_PREVIOUSTRACK 12
  182017. #define APPCOMMAND_MEDIA_STOP 13
  182018. #define APPCOMMAND_MEDIA_PLAY_PAUSE 14
  182019. #define WM_APPCOMMAND 0x0319
  182020. #endif
  182021. extern void juce_repeatLastProcessPriority(); // in juce_win32_Threads.cpp
  182022. extern void juce_CheckCurrentlyFocusedTopLevelWindow(); // in juce_TopLevelWindow.cpp
  182023. extern bool juce_IsRunningInWine();
  182024. #ifndef ULW_ALPHA
  182025. #define ULW_ALPHA 0x00000002
  182026. #endif
  182027. #ifndef AC_SRC_ALPHA
  182028. #define AC_SRC_ALPHA 0x01
  182029. #endif
  182030. #define DEBUG_REPAINT_TIMES 0
  182031. static HPALETTE palette = 0;
  182032. static bool createPaletteIfNeeded = true;
  182033. static bool shouldDeactivateTitleBar = true;
  182034. static HICON createHICONFromImage (const Image& image, const BOOL isIcon, int hotspotX, int hotspotY) throw();
  182035. #define WM_TRAYNOTIFY WM_USER + 100
  182036. using ::abs;
  182037. typedef BOOL (WINAPI* UpdateLayeredWinFunc) (HWND, HDC, POINT*, SIZE*, HDC, POINT*, COLORREF, BLENDFUNCTION*, DWORD);
  182038. static UpdateLayeredWinFunc updateLayeredWindow = 0;
  182039. bool Desktop::canUseSemiTransparentWindows() throw()
  182040. {
  182041. if (updateLayeredWindow == 0)
  182042. {
  182043. if (! juce_IsRunningInWine())
  182044. {
  182045. HMODULE user32Mod = GetModuleHandle (_T("user32.dll"));
  182046. updateLayeredWindow = (UpdateLayeredWinFunc) GetProcAddress (user32Mod, "UpdateLayeredWindow");
  182047. }
  182048. }
  182049. return updateLayeredWindow != 0;
  182050. }
  182051. #undef DefWindowProc
  182052. #define DefWindowProc DefWindowProcW
  182053. const int extendedKeyModifier = 0x10000;
  182054. const int KeyPress::spaceKey = VK_SPACE;
  182055. const int KeyPress::returnKey = VK_RETURN;
  182056. const int KeyPress::escapeKey = VK_ESCAPE;
  182057. const int KeyPress::backspaceKey = VK_BACK;
  182058. const int KeyPress::deleteKey = VK_DELETE | extendedKeyModifier;
  182059. const int KeyPress::insertKey = VK_INSERT | extendedKeyModifier;
  182060. const int KeyPress::tabKey = VK_TAB;
  182061. const int KeyPress::leftKey = VK_LEFT | extendedKeyModifier;
  182062. const int KeyPress::rightKey = VK_RIGHT | extendedKeyModifier;
  182063. const int KeyPress::upKey = VK_UP | extendedKeyModifier;
  182064. const int KeyPress::downKey = VK_DOWN | extendedKeyModifier;
  182065. const int KeyPress::homeKey = VK_HOME | extendedKeyModifier;
  182066. const int KeyPress::endKey = VK_END | extendedKeyModifier;
  182067. const int KeyPress::pageUpKey = VK_PRIOR | extendedKeyModifier;
  182068. const int KeyPress::pageDownKey = VK_NEXT | extendedKeyModifier;
  182069. const int KeyPress::F1Key = VK_F1 | extendedKeyModifier;
  182070. const int KeyPress::F2Key = VK_F2 | extendedKeyModifier;
  182071. const int KeyPress::F3Key = VK_F3 | extendedKeyModifier;
  182072. const int KeyPress::F4Key = VK_F4 | extendedKeyModifier;
  182073. const int KeyPress::F5Key = VK_F5 | extendedKeyModifier;
  182074. const int KeyPress::F6Key = VK_F6 | extendedKeyModifier;
  182075. const int KeyPress::F7Key = VK_F7 | extendedKeyModifier;
  182076. const int KeyPress::F8Key = VK_F8 | extendedKeyModifier;
  182077. const int KeyPress::F9Key = VK_F9 | extendedKeyModifier;
  182078. const int KeyPress::F10Key = VK_F10 | extendedKeyModifier;
  182079. const int KeyPress::F11Key = VK_F11 | extendedKeyModifier;
  182080. const int KeyPress::F12Key = VK_F12 | extendedKeyModifier;
  182081. const int KeyPress::F13Key = VK_F13 | extendedKeyModifier;
  182082. const int KeyPress::F14Key = VK_F14 | extendedKeyModifier;
  182083. const int KeyPress::F15Key = VK_F15 | extendedKeyModifier;
  182084. const int KeyPress::F16Key = VK_F16 | extendedKeyModifier;
  182085. const int KeyPress::numberPad0 = VK_NUMPAD0 | extendedKeyModifier;
  182086. const int KeyPress::numberPad1 = VK_NUMPAD1 | extendedKeyModifier;
  182087. const int KeyPress::numberPad2 = VK_NUMPAD2 | extendedKeyModifier;
  182088. const int KeyPress::numberPad3 = VK_NUMPAD3 | extendedKeyModifier;
  182089. const int KeyPress::numberPad4 = VK_NUMPAD4 | extendedKeyModifier;
  182090. const int KeyPress::numberPad5 = VK_NUMPAD5 | extendedKeyModifier;
  182091. const int KeyPress::numberPad6 = VK_NUMPAD6 | extendedKeyModifier;
  182092. const int KeyPress::numberPad7 = VK_NUMPAD7 | extendedKeyModifier;
  182093. const int KeyPress::numberPad8 = VK_NUMPAD8 | extendedKeyModifier;
  182094. const int KeyPress::numberPad9 = VK_NUMPAD9 | extendedKeyModifier;
  182095. const int KeyPress::numberPadAdd = VK_ADD | extendedKeyModifier;
  182096. const int KeyPress::numberPadSubtract = VK_SUBTRACT | extendedKeyModifier;
  182097. const int KeyPress::numberPadMultiply = VK_MULTIPLY | extendedKeyModifier;
  182098. const int KeyPress::numberPadDivide = VK_DIVIDE | extendedKeyModifier;
  182099. const int KeyPress::numberPadSeparator = VK_SEPARATOR | extendedKeyModifier;
  182100. const int KeyPress::numberPadDecimalPoint = VK_DECIMAL | extendedKeyModifier;
  182101. const int KeyPress::numberPadEquals = 0x92 /*VK_OEM_NEC_EQUAL*/ | extendedKeyModifier;
  182102. const int KeyPress::numberPadDelete = VK_DELETE | extendedKeyModifier;
  182103. const int KeyPress::playKey = 0x30000;
  182104. const int KeyPress::stopKey = 0x30001;
  182105. const int KeyPress::fastForwardKey = 0x30002;
  182106. const int KeyPress::rewindKey = 0x30003;
  182107. class WindowsBitmapImage : public Image
  182108. {
  182109. public:
  182110. HBITMAP hBitmap;
  182111. BITMAPV4HEADER bitmapInfo;
  182112. HDC hdc;
  182113. unsigned char* bitmapData;
  182114. WindowsBitmapImage (const PixelFormat format_,
  182115. const int w, const int h, const bool clearImage)
  182116. : Image (format_, w, h)
  182117. {
  182118. jassert (format_ == RGB || format_ == ARGB);
  182119. pixelStride = (format_ == RGB) ? 3 : 4;
  182120. zerostruct (bitmapInfo);
  182121. bitmapInfo.bV4Size = sizeof (BITMAPV4HEADER);
  182122. bitmapInfo.bV4Width = w;
  182123. bitmapInfo.bV4Height = h;
  182124. bitmapInfo.bV4Planes = 1;
  182125. bitmapInfo.bV4CSType = 1;
  182126. bitmapInfo.bV4BitCount = (unsigned short) (pixelStride * 8);
  182127. if (format_ == ARGB)
  182128. {
  182129. bitmapInfo.bV4AlphaMask = 0xff000000;
  182130. bitmapInfo.bV4RedMask = 0xff0000;
  182131. bitmapInfo.bV4GreenMask = 0xff00;
  182132. bitmapInfo.bV4BlueMask = 0xff;
  182133. bitmapInfo.bV4V4Compression = BI_BITFIELDS;
  182134. }
  182135. else
  182136. {
  182137. bitmapInfo.bV4V4Compression = BI_RGB;
  182138. }
  182139. lineStride = -((w * pixelStride + 3) & ~3);
  182140. HDC dc = GetDC (0);
  182141. hdc = CreateCompatibleDC (dc);
  182142. ReleaseDC (0, dc);
  182143. SetMapMode (hdc, MM_TEXT);
  182144. hBitmap = CreateDIBSection (hdc,
  182145. (BITMAPINFO*) &(bitmapInfo),
  182146. DIB_RGB_COLORS,
  182147. (void**) &bitmapData,
  182148. 0, 0);
  182149. SelectObject (hdc, hBitmap);
  182150. if (format_ == ARGB && clearImage)
  182151. zeromem (bitmapData, abs (h * lineStride));
  182152. imageData = bitmapData - (lineStride * (h - 1));
  182153. }
  182154. ~WindowsBitmapImage()
  182155. {
  182156. DeleteDC (hdc);
  182157. DeleteObject (hBitmap);
  182158. }
  182159. void blitToWindow (HWND hwnd, HDC dc, const bool transparent,
  182160. const int x, const int y,
  182161. const RectangleList& maskedRegion) throw()
  182162. {
  182163. static HDRAWDIB hdd = 0;
  182164. static bool needToCreateDrawDib = true;
  182165. if (needToCreateDrawDib)
  182166. {
  182167. needToCreateDrawDib = false;
  182168. HDC dc = GetDC (0);
  182169. const int n = GetDeviceCaps (dc, BITSPIXEL);
  182170. ReleaseDC (0, dc);
  182171. // only open if we're not palettised
  182172. if (n > 8)
  182173. hdd = DrawDibOpen();
  182174. }
  182175. if (createPaletteIfNeeded)
  182176. {
  182177. HDC dc = GetDC (0);
  182178. const int n = GetDeviceCaps (dc, BITSPIXEL);
  182179. ReleaseDC (0, dc);
  182180. if (n <= 8)
  182181. palette = CreateHalftonePalette (dc);
  182182. createPaletteIfNeeded = false;
  182183. }
  182184. if (palette != 0)
  182185. {
  182186. SelectPalette (dc, palette, FALSE);
  182187. RealizePalette (dc);
  182188. SetStretchBltMode (dc, HALFTONE);
  182189. }
  182190. SetMapMode (dc, MM_TEXT);
  182191. if (transparent)
  182192. {
  182193. POINT p, pos;
  182194. SIZE size;
  182195. RECT windowBounds;
  182196. GetWindowRect (hwnd, &windowBounds);
  182197. p.x = -x;
  182198. p.y = -y;
  182199. pos.x = windowBounds.left;
  182200. pos.y = windowBounds.top;
  182201. size.cx = windowBounds.right - windowBounds.left;
  182202. size.cy = windowBounds.bottom - windowBounds.top;
  182203. BLENDFUNCTION bf;
  182204. bf.AlphaFormat = AC_SRC_ALPHA;
  182205. bf.BlendFlags = 0;
  182206. bf.BlendOp = AC_SRC_OVER;
  182207. bf.SourceConstantAlpha = 0xff;
  182208. if (! maskedRegion.isEmpty())
  182209. {
  182210. for (RectangleList::Iterator i (maskedRegion); i.next();)
  182211. {
  182212. const Rectangle& r = *i.getRectangle();
  182213. ExcludeClipRect (hdc, r.getX(), r.getY(), r.getRight(), r.getBottom());
  182214. }
  182215. }
  182216. updateLayeredWindow (hwnd, 0, &pos, &size, hdc, &p, 0, &bf, ULW_ALPHA);
  182217. }
  182218. else
  182219. {
  182220. int savedDC = 0;
  182221. if (! maskedRegion.isEmpty())
  182222. {
  182223. savedDC = SaveDC (dc);
  182224. for (RectangleList::Iterator i (maskedRegion); i.next();)
  182225. {
  182226. const Rectangle& r = *i.getRectangle();
  182227. ExcludeClipRect (dc, r.getX(), r.getY(), r.getRight(), r.getBottom());
  182228. }
  182229. }
  182230. const int w = getWidth();
  182231. const int h = getHeight();
  182232. if (hdd == 0)
  182233. {
  182234. StretchDIBits (dc,
  182235. x, y, w, h,
  182236. 0, 0, w, h,
  182237. bitmapData, (const BITMAPINFO*) &bitmapInfo,
  182238. DIB_RGB_COLORS, SRCCOPY);
  182239. }
  182240. else
  182241. {
  182242. DrawDibDraw (hdd, dc, x, y, -1, -1,
  182243. (BITMAPINFOHEADER*) &bitmapInfo, bitmapData,
  182244. 0, 0, w, h, 0);
  182245. }
  182246. if (! maskedRegion.isEmpty())
  182247. RestoreDC (dc, savedDC);
  182248. }
  182249. }
  182250. juce_UseDebuggingNewOperator
  182251. private:
  182252. WindowsBitmapImage (const WindowsBitmapImage&);
  182253. const WindowsBitmapImage& operator= (const WindowsBitmapImage&);
  182254. };
  182255. long improbableWindowNumber = 0xf965aa01; // also referenced by messaging.cpp
  182256. static int currentModifiers = 0;
  182257. static int modifiersAtLastCallback = 0;
  182258. static void updateKeyModifiers() throw()
  182259. {
  182260. currentModifiers &= ~(ModifierKeys::shiftModifier
  182261. | ModifierKeys::ctrlModifier
  182262. | ModifierKeys::altModifier);
  182263. if ((GetKeyState (VK_SHIFT) & 0x8000) != 0)
  182264. currentModifiers |= ModifierKeys::shiftModifier;
  182265. if ((GetKeyState (VK_CONTROL) & 0x8000) != 0)
  182266. currentModifiers |= ModifierKeys::ctrlModifier;
  182267. if ((GetKeyState (VK_MENU) & 0x8000) != 0)
  182268. currentModifiers |= ModifierKeys::altModifier;
  182269. if ((GetKeyState (VK_RMENU) & 0x8000) != 0)
  182270. currentModifiers &= ~(ModifierKeys::ctrlModifier | ModifierKeys::altModifier);
  182271. }
  182272. void ModifierKeys::updateCurrentModifiers() throw()
  182273. {
  182274. currentModifierFlags = currentModifiers;
  182275. }
  182276. bool KeyPress::isKeyCurrentlyDown (const int keyCode) throw()
  182277. {
  182278. SHORT k = (SHORT) keyCode;
  182279. if ((keyCode & extendedKeyModifier) == 0
  182280. && (k >= (SHORT) T('a') && k <= (SHORT) T('z')))
  182281. k += (SHORT) T('A') - (SHORT) T('a');
  182282. const SHORT translatedValues[] = { (SHORT) ',', VK_OEM_COMMA,
  182283. (SHORT) '+', VK_OEM_PLUS,
  182284. (SHORT) '-', VK_OEM_MINUS,
  182285. (SHORT) '.', VK_OEM_PERIOD,
  182286. (SHORT) ';', VK_OEM_1,
  182287. (SHORT) ':', VK_OEM_1,
  182288. (SHORT) '/', VK_OEM_2,
  182289. (SHORT) '?', VK_OEM_2,
  182290. (SHORT) '[', VK_OEM_4,
  182291. (SHORT) ']', VK_OEM_6 };
  182292. for (int i = 0; i < numElementsInArray (translatedValues); i += 2)
  182293. if (k == translatedValues [i])
  182294. k = translatedValues [i + 1];
  182295. return (GetKeyState (k) & 0x8000) != 0;
  182296. }
  182297. const ModifierKeys ModifierKeys::getCurrentModifiersRealtime() throw()
  182298. {
  182299. updateKeyModifiers();
  182300. currentModifiers &= ~ModifierKeys::allMouseButtonModifiers;
  182301. if ((GetKeyState (VK_LBUTTON) & 0x8000) != 0)
  182302. currentModifiers |= ModifierKeys::leftButtonModifier;
  182303. if ((GetKeyState (VK_RBUTTON) & 0x8000) != 0)
  182304. currentModifiers |= ModifierKeys::rightButtonModifier;
  182305. if ((GetKeyState (VK_MBUTTON) & 0x8000) != 0)
  182306. currentModifiers |= ModifierKeys::middleButtonModifier;
  182307. return ModifierKeys (currentModifiers);
  182308. }
  182309. static int64 getMouseEventTime() throw()
  182310. {
  182311. static int64 eventTimeOffset = 0;
  182312. static DWORD lastMessageTime = 0;
  182313. const DWORD thisMessageTime = GetMessageTime();
  182314. if (thisMessageTime < lastMessageTime || lastMessageTime == 0)
  182315. {
  182316. lastMessageTime = thisMessageTime;
  182317. eventTimeOffset = Time::currentTimeMillis() - thisMessageTime;
  182318. }
  182319. return eventTimeOffset + thisMessageTime;
  182320. }
  182321. static void* callFunctionIfNotLocked (MessageCallbackFunction* callback, void* userData)
  182322. {
  182323. if (MessageManager::getInstance()->currentThreadHasLockedMessageManager())
  182324. return callback (userData);
  182325. else
  182326. return MessageManager::getInstance()->callFunctionOnMessageThread (callback, userData);
  182327. }
  182328. class Win32ComponentPeer : public ComponentPeer
  182329. {
  182330. public:
  182331. Win32ComponentPeer (Component* const component,
  182332. const int windowStyleFlags)
  182333. : ComponentPeer (component, windowStyleFlags),
  182334. dontRepaint (false),
  182335. fullScreen (false),
  182336. isDragging (false),
  182337. isMouseOver (false),
  182338. hasCreatedCaret (false),
  182339. currentWindowIcon (0),
  182340. taskBarIcon (0),
  182341. dropTarget (0)
  182342. {
  182343. callFunctionIfNotLocked (&createWindowCallback, (void*) this);
  182344. setTitle (component->getName());
  182345. if ((windowStyleFlags & windowHasDropShadow) != 0
  182346. && Desktop::canUseSemiTransparentWindows())
  182347. {
  182348. shadower = component->getLookAndFeel().createDropShadowerForComponent (component);
  182349. if (shadower != 0)
  182350. shadower->setOwner (component);
  182351. }
  182352. else
  182353. {
  182354. shadower = 0;
  182355. }
  182356. }
  182357. ~Win32ComponentPeer()
  182358. {
  182359. setTaskBarIcon (0);
  182360. deleteAndZero (shadower);
  182361. // do this before the next bit to avoid messages arriving for this window
  182362. // before it's destroyed
  182363. SetWindowLongPtr (hwnd, GWLP_USERDATA, 0);
  182364. callFunctionIfNotLocked (&destroyWindowCallback, (void*) hwnd);
  182365. if (currentWindowIcon != 0)
  182366. DestroyIcon (currentWindowIcon);
  182367. if (dropTarget != 0)
  182368. {
  182369. dropTarget->Release();
  182370. dropTarget = 0;
  182371. }
  182372. }
  182373. void* getNativeHandle() const
  182374. {
  182375. return (void*) hwnd;
  182376. }
  182377. void setVisible (bool shouldBeVisible)
  182378. {
  182379. ShowWindow (hwnd, shouldBeVisible ? SW_SHOWNA : SW_HIDE);
  182380. if (shouldBeVisible)
  182381. InvalidateRect (hwnd, 0, 0);
  182382. else
  182383. lastPaintTime = 0;
  182384. }
  182385. void setTitle (const String& title)
  182386. {
  182387. SetWindowText (hwnd, title);
  182388. }
  182389. void setPosition (int x, int y)
  182390. {
  182391. offsetWithinParent (x, y);
  182392. SetWindowPos (hwnd, 0,
  182393. x - windowBorder.getLeft(),
  182394. y - windowBorder.getTop(),
  182395. 0, 0,
  182396. SWP_NOACTIVATE | SWP_NOSIZE | SWP_NOZORDER | SWP_NOOWNERZORDER);
  182397. }
  182398. void repaintNowIfTransparent()
  182399. {
  182400. if (isTransparent() && lastPaintTime > 0 && Time::getMillisecondCounter() > lastPaintTime + 30)
  182401. handlePaintMessage();
  182402. }
  182403. void updateBorderSize()
  182404. {
  182405. WINDOWINFO info;
  182406. info.cbSize = sizeof (info);
  182407. if (GetWindowInfo (hwnd, &info))
  182408. {
  182409. windowBorder = BorderSize (info.rcClient.top - info.rcWindow.top,
  182410. info.rcClient.left - info.rcWindow.left,
  182411. info.rcWindow.bottom - info.rcClient.bottom,
  182412. info.rcWindow.right - info.rcClient.right);
  182413. }
  182414. }
  182415. void setSize (int w, int h)
  182416. {
  182417. SetWindowPos (hwnd, 0, 0, 0,
  182418. w + windowBorder.getLeftAndRight(),
  182419. h + windowBorder.getTopAndBottom(),
  182420. SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOZORDER | SWP_NOOWNERZORDER);
  182421. updateBorderSize();
  182422. repaintNowIfTransparent();
  182423. }
  182424. void setBounds (int x, int y, int w, int h, const bool isNowFullScreen)
  182425. {
  182426. fullScreen = isNowFullScreen;
  182427. offsetWithinParent (x, y);
  182428. SetWindowPos (hwnd, 0,
  182429. x - windowBorder.getLeft(),
  182430. y - windowBorder.getTop(),
  182431. w + windowBorder.getLeftAndRight(),
  182432. h + windowBorder.getTopAndBottom(),
  182433. SWP_NOACTIVATE | SWP_NOZORDER | SWP_NOOWNERZORDER);
  182434. updateBorderSize();
  182435. repaintNowIfTransparent();
  182436. }
  182437. void getBounds (int& x, int& y, int& w, int& h) const
  182438. {
  182439. RECT r;
  182440. GetWindowRect (hwnd, &r);
  182441. x = r.left;
  182442. y = r.top;
  182443. w = r.right - x;
  182444. h = r.bottom - y;
  182445. HWND parentH = GetParent (hwnd);
  182446. if (parentH != 0)
  182447. {
  182448. GetWindowRect (parentH, &r);
  182449. x -= r.left;
  182450. y -= r.top;
  182451. }
  182452. x += windowBorder.getLeft();
  182453. y += windowBorder.getTop();
  182454. w -= windowBorder.getLeftAndRight();
  182455. h -= windowBorder.getTopAndBottom();
  182456. }
  182457. int getScreenX() const
  182458. {
  182459. RECT r;
  182460. GetWindowRect (hwnd, &r);
  182461. return r.left + windowBorder.getLeft();
  182462. }
  182463. int getScreenY() const
  182464. {
  182465. RECT r;
  182466. GetWindowRect (hwnd, &r);
  182467. return r.top + windowBorder.getTop();
  182468. }
  182469. void relativePositionToGlobal (int& x, int& y)
  182470. {
  182471. RECT r;
  182472. GetWindowRect (hwnd, &r);
  182473. x += r.left + windowBorder.getLeft();
  182474. y += r.top + windowBorder.getTop();
  182475. }
  182476. void globalPositionToRelative (int& x, int& y)
  182477. {
  182478. RECT r;
  182479. GetWindowRect (hwnd, &r);
  182480. x -= r.left + windowBorder.getLeft();
  182481. y -= r.top + windowBorder.getTop();
  182482. }
  182483. void setMinimised (bool shouldBeMinimised)
  182484. {
  182485. if (shouldBeMinimised != isMinimised())
  182486. ShowWindow (hwnd, shouldBeMinimised ? SW_MINIMIZE : SW_SHOWNORMAL);
  182487. }
  182488. bool isMinimised() const
  182489. {
  182490. WINDOWPLACEMENT wp;
  182491. wp.length = sizeof (WINDOWPLACEMENT);
  182492. GetWindowPlacement (hwnd, &wp);
  182493. return wp.showCmd == SW_SHOWMINIMIZED;
  182494. }
  182495. void setFullScreen (bool shouldBeFullScreen)
  182496. {
  182497. setMinimised (false);
  182498. if (fullScreen != shouldBeFullScreen)
  182499. {
  182500. fullScreen = shouldBeFullScreen;
  182501. const ComponentDeletionWatcher deletionChecker (component);
  182502. if (! fullScreen)
  182503. {
  182504. const Rectangle boundsCopy (lastNonFullscreenBounds);
  182505. if (hasTitleBar())
  182506. ShowWindow (hwnd, SW_SHOWNORMAL);
  182507. if (! boundsCopy.isEmpty())
  182508. {
  182509. setBounds (boundsCopy.getX(),
  182510. boundsCopy.getY(),
  182511. boundsCopy.getWidth(),
  182512. boundsCopy.getHeight(),
  182513. false);
  182514. }
  182515. }
  182516. else
  182517. {
  182518. if (hasTitleBar())
  182519. ShowWindow (hwnd, SW_SHOWMAXIMIZED);
  182520. else
  182521. SendMessageW (hwnd, WM_SETTINGCHANGE, 0, 0);
  182522. }
  182523. if (! deletionChecker.hasBeenDeleted())
  182524. handleMovedOrResized();
  182525. }
  182526. }
  182527. bool isFullScreen() const
  182528. {
  182529. if (! hasTitleBar())
  182530. return fullScreen;
  182531. WINDOWPLACEMENT wp;
  182532. wp.length = sizeof (wp);
  182533. GetWindowPlacement (hwnd, &wp);
  182534. return wp.showCmd == SW_SHOWMAXIMIZED;
  182535. }
  182536. bool contains (int x, int y, bool trueIfInAChildWindow) const
  182537. {
  182538. RECT r;
  182539. GetWindowRect (hwnd, &r);
  182540. POINT p;
  182541. p.x = x + r.left + windowBorder.getLeft();
  182542. p.y = y + r.top + windowBorder.getTop();
  182543. HWND w = WindowFromPoint (p);
  182544. return w == hwnd || (trueIfInAChildWindow && (IsChild (hwnd, w) != 0));
  182545. }
  182546. const BorderSize getFrameSize() const
  182547. {
  182548. return windowBorder;
  182549. }
  182550. bool setAlwaysOnTop (bool alwaysOnTop)
  182551. {
  182552. const bool oldDeactivate = shouldDeactivateTitleBar;
  182553. shouldDeactivateTitleBar = ((styleFlags & windowIsTemporary) == 0);
  182554. SetWindowPos (hwnd, alwaysOnTop ? HWND_TOPMOST : HWND_NOTOPMOST,
  182555. 0, 0, 0, 0,
  182556. SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE | SWP_NOSENDCHANGING);
  182557. shouldDeactivateTitleBar = oldDeactivate;
  182558. if (shadower != 0)
  182559. shadower->componentBroughtToFront (*component);
  182560. return true;
  182561. }
  182562. void toFront (bool makeActive)
  182563. {
  182564. setMinimised (false);
  182565. const bool oldDeactivate = shouldDeactivateTitleBar;
  182566. shouldDeactivateTitleBar = ((styleFlags & windowIsTemporary) == 0);
  182567. callFunctionIfNotLocked (makeActive ? &toFrontCallback1
  182568. : &toFrontCallback2,
  182569. (void*) hwnd);
  182570. shouldDeactivateTitleBar = oldDeactivate;
  182571. if (! makeActive)
  182572. {
  182573. // in this case a broughttofront call won't have occured, so do it now..
  182574. handleBroughtToFront();
  182575. }
  182576. }
  182577. void toBehind (ComponentPeer* other)
  182578. {
  182579. Win32ComponentPeer* const otherPeer = dynamic_cast <Win32ComponentPeer*> (other);
  182580. jassert (otherPeer != 0); // wrong type of window?
  182581. if (otherPeer != 0)
  182582. {
  182583. setMinimised (false);
  182584. // must be careful not to try to put a topmost window behind a normal one, or win32
  182585. // promotes the normal one to be topmost!
  182586. if (getComponent()->isAlwaysOnTop() == otherPeer->getComponent()->isAlwaysOnTop())
  182587. SetWindowPos (hwnd, otherPeer->hwnd, 0, 0, 0, 0,
  182588. SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE | SWP_NOSENDCHANGING);
  182589. else if (otherPeer->getComponent()->isAlwaysOnTop())
  182590. SetWindowPos (hwnd, HWND_TOP, 0, 0, 0, 0,
  182591. SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE | SWP_NOSENDCHANGING);
  182592. }
  182593. }
  182594. bool isFocused() const
  182595. {
  182596. return callFunctionIfNotLocked (&getFocusCallback, 0) == (void*) hwnd;
  182597. }
  182598. void grabFocus()
  182599. {
  182600. const bool oldDeactivate = shouldDeactivateTitleBar;
  182601. shouldDeactivateTitleBar = ((styleFlags & windowIsTemporary) == 0);
  182602. callFunctionIfNotLocked (&setFocusCallback, (void*) hwnd);
  182603. shouldDeactivateTitleBar = oldDeactivate;
  182604. }
  182605. void textInputRequired (int /*x*/, int /*y*/)
  182606. {
  182607. if (! hasCreatedCaret)
  182608. {
  182609. hasCreatedCaret = true;
  182610. CreateCaret (hwnd, (HBITMAP) 1, 0, 0);
  182611. }
  182612. ShowCaret (hwnd);
  182613. SetCaretPos (0, 0);
  182614. }
  182615. void repaint (int x, int y, int w, int h)
  182616. {
  182617. const RECT r = { x, y, x + w, y + h };
  182618. InvalidateRect (hwnd, &r, FALSE);
  182619. }
  182620. void performAnyPendingRepaintsNow()
  182621. {
  182622. MSG m;
  182623. if (component->isVisible() && PeekMessage (&m, hwnd, WM_PAINT, WM_PAINT, PM_REMOVE))
  182624. DispatchMessage (&m);
  182625. }
  182626. static Win32ComponentPeer* getOwnerOfWindow (HWND h) throw()
  182627. {
  182628. if (h != 0 && GetWindowLongPtr (h, GWLP_USERDATA) == improbableWindowNumber)
  182629. return (Win32ComponentPeer*) (pointer_sized_int) GetWindowLongPtr (h, 8);
  182630. return 0;
  182631. }
  182632. void setTaskBarIcon (const Image* const image)
  182633. {
  182634. if (image != 0)
  182635. {
  182636. HICON hicon = createHICONFromImage (*image, TRUE, 0, 0);
  182637. if (taskBarIcon == 0)
  182638. {
  182639. taskBarIcon = new NOTIFYICONDATA();
  182640. taskBarIcon->cbSize = sizeof (NOTIFYICONDATA);
  182641. taskBarIcon->hWnd = (HWND) hwnd;
  182642. taskBarIcon->uID = (int) (pointer_sized_int) hwnd;
  182643. taskBarIcon->uFlags = NIF_ICON | NIF_MESSAGE | NIF_TIP;
  182644. taskBarIcon->uCallbackMessage = WM_TRAYNOTIFY;
  182645. taskBarIcon->hIcon = hicon;
  182646. taskBarIcon->szTip[0] = 0;
  182647. Shell_NotifyIcon (NIM_ADD, taskBarIcon);
  182648. }
  182649. else
  182650. {
  182651. HICON oldIcon = taskBarIcon->hIcon;
  182652. taskBarIcon->hIcon = hicon;
  182653. taskBarIcon->uFlags = NIF_ICON;
  182654. Shell_NotifyIcon (NIM_MODIFY, taskBarIcon);
  182655. DestroyIcon (oldIcon);
  182656. }
  182657. DestroyIcon (hicon);
  182658. }
  182659. else if (taskBarIcon != 0)
  182660. {
  182661. taskBarIcon->uFlags = 0;
  182662. Shell_NotifyIcon (NIM_DELETE, taskBarIcon);
  182663. DestroyIcon (taskBarIcon->hIcon);
  182664. deleteAndZero (taskBarIcon);
  182665. }
  182666. }
  182667. void setTaskBarIconToolTip (const String& toolTip) const
  182668. {
  182669. if (taskBarIcon != 0)
  182670. {
  182671. taskBarIcon->uFlags = NIF_TIP;
  182672. toolTip.copyToBuffer (taskBarIcon->szTip, sizeof (taskBarIcon->szTip) - 1);
  182673. Shell_NotifyIcon (NIM_MODIFY, taskBarIcon);
  182674. }
  182675. }
  182676. bool isInside (HWND h) const
  182677. {
  182678. return GetAncestor (hwnd, GA_ROOT) == h;
  182679. }
  182680. juce_UseDebuggingNewOperator
  182681. bool dontRepaint;
  182682. private:
  182683. HWND hwnd;
  182684. DropShadower* shadower;
  182685. bool fullScreen, isDragging, isMouseOver, hasCreatedCaret;
  182686. BorderSize windowBorder;
  182687. HICON currentWindowIcon;
  182688. NOTIFYICONDATA* taskBarIcon;
  182689. IDropTarget* dropTarget;
  182690. class TemporaryImage : public Timer
  182691. {
  182692. public:
  182693. TemporaryImage()
  182694. : image (0)
  182695. {
  182696. }
  182697. ~TemporaryImage()
  182698. {
  182699. delete image;
  182700. }
  182701. WindowsBitmapImage* getImage (const bool transparent, const int w, const int h) throw()
  182702. {
  182703. const Image::PixelFormat format = transparent ? Image::ARGB : Image::RGB;
  182704. if (image == 0 || image->getWidth() < w || image->getHeight() < h || image->getFormat() != format)
  182705. {
  182706. delete image;
  182707. image = new WindowsBitmapImage (format, (w + 31) & ~31, (h + 31) & ~31, false);
  182708. }
  182709. startTimer (3000);
  182710. return image;
  182711. }
  182712. void timerCallback()
  182713. {
  182714. stopTimer();
  182715. deleteAndZero (image);
  182716. }
  182717. private:
  182718. WindowsBitmapImage* image;
  182719. TemporaryImage (const TemporaryImage&);
  182720. const TemporaryImage& operator= (const TemporaryImage&);
  182721. };
  182722. TemporaryImage offscreenImageGenerator;
  182723. class WindowClassHolder : public DeletedAtShutdown
  182724. {
  182725. public:
  182726. WindowClassHolder()
  182727. : windowClassName ("JUCE_")
  182728. {
  182729. // this name has to be different for each app/dll instance because otherwise
  182730. // poor old Win32 can get a bit confused (even despite it not being a process-global
  182731. // window class).
  182732. windowClassName << (int) (Time::currentTimeMillis() & 0x7fffffff);
  182733. HINSTANCE moduleHandle = (HINSTANCE) PlatformUtilities::getCurrentModuleInstanceHandle();
  182734. TCHAR moduleFile [1024];
  182735. moduleFile[0] = 0;
  182736. GetModuleFileName (moduleHandle, moduleFile, 1024);
  182737. WORD iconNum = 0;
  182738. WNDCLASSEX wcex;
  182739. wcex.cbSize = sizeof (wcex);
  182740. wcex.style = CS_OWNDC;
  182741. wcex.lpfnWndProc = (WNDPROC) windowProc;
  182742. wcex.lpszClassName = windowClassName;
  182743. wcex.cbClsExtra = 0;
  182744. wcex.cbWndExtra = 32;
  182745. wcex.hInstance = moduleHandle;
  182746. wcex.hIcon = ExtractAssociatedIcon (moduleHandle, moduleFile, &iconNum);
  182747. iconNum = 1;
  182748. wcex.hIconSm = ExtractAssociatedIcon (moduleHandle, moduleFile, &iconNum);
  182749. wcex.hCursor = 0;
  182750. wcex.hbrBackground = 0;
  182751. wcex.lpszMenuName = 0;
  182752. RegisterClassEx (&wcex);
  182753. }
  182754. ~WindowClassHolder()
  182755. {
  182756. if (ComponentPeer::getNumPeers() == 0)
  182757. UnregisterClass (windowClassName, (HINSTANCE) PlatformUtilities::getCurrentModuleInstanceHandle());
  182758. clearSingletonInstance();
  182759. }
  182760. String windowClassName;
  182761. juce_DeclareSingleton_SingleThreaded_Minimal (WindowClassHolder);
  182762. };
  182763. static void* createWindowCallback (void* userData)
  182764. {
  182765. ((Win32ComponentPeer*) userData)->createWindow();
  182766. return 0;
  182767. }
  182768. void createWindow()
  182769. {
  182770. DWORD exstyle = WS_EX_ACCEPTFILES;
  182771. DWORD type = WS_CLIPSIBLINGS | WS_CLIPCHILDREN;
  182772. if (hasTitleBar())
  182773. {
  182774. type |= WS_OVERLAPPED;
  182775. exstyle |= WS_EX_APPWINDOW;
  182776. if ((styleFlags & windowHasCloseButton) != 0)
  182777. {
  182778. type |= WS_SYSMENU;
  182779. }
  182780. else
  182781. {
  182782. // annoyingly, windows won't let you have a min/max button without a close button
  182783. jassert ((styleFlags & (windowHasMinimiseButton | windowHasMaximiseButton)) == 0);
  182784. }
  182785. if ((styleFlags & windowIsResizable) != 0)
  182786. type |= WS_THICKFRAME;
  182787. }
  182788. else
  182789. {
  182790. type |= WS_POPUP | WS_SYSMENU;
  182791. if ((styleFlags & windowAppearsOnTaskbar) == 0)
  182792. exstyle |= WS_EX_TOOLWINDOW;
  182793. else
  182794. exstyle |= WS_EX_APPWINDOW;
  182795. }
  182796. if ((styleFlags & windowHasMinimiseButton) != 0)
  182797. type |= WS_MINIMIZEBOX;
  182798. if ((styleFlags & windowHasMaximiseButton) != 0)
  182799. type |= WS_MAXIMIZEBOX;
  182800. if ((styleFlags & windowIgnoresMouseClicks) != 0)
  182801. exstyle |= WS_EX_TRANSPARENT;
  182802. if ((styleFlags & windowIsSemiTransparent) != 0
  182803. && Desktop::canUseSemiTransparentWindows())
  182804. exstyle |= WS_EX_LAYERED;
  182805. hwnd = CreateWindowEx (exstyle, WindowClassHolder::getInstance()->windowClassName, L"", type, 0, 0, 0, 0, 0, 0, 0, 0);
  182806. if (hwnd != 0)
  182807. {
  182808. SetWindowLongPtr (hwnd, 0, 0);
  182809. SetWindowLongPtr (hwnd, 8, (LONG_PTR) this);
  182810. SetWindowLongPtr (hwnd, GWLP_USERDATA, improbableWindowNumber);
  182811. if (dropTarget == 0)
  182812. dropTarget = new JuceDropTarget (this);
  182813. RegisterDragDrop (hwnd, dropTarget);
  182814. updateBorderSize();
  182815. // Calling this function here is (for some reason) necessary to make Windows
  182816. // correctly enable the menu items that we specify in the wm_initmenu message.
  182817. GetSystemMenu (hwnd, false);
  182818. }
  182819. else
  182820. {
  182821. jassertfalse
  182822. }
  182823. }
  182824. static void* destroyWindowCallback (void* handle)
  182825. {
  182826. RevokeDragDrop ((HWND) handle);
  182827. DestroyWindow ((HWND) handle);
  182828. return 0;
  182829. }
  182830. static void* toFrontCallback1 (void* h)
  182831. {
  182832. SetForegroundWindow ((HWND) h);
  182833. return 0;
  182834. }
  182835. static void* toFrontCallback2 (void* h)
  182836. {
  182837. SetWindowPos ((HWND) h, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE | SWP_NOSENDCHANGING);
  182838. return 0;
  182839. }
  182840. static void* setFocusCallback (void* h)
  182841. {
  182842. SetFocus ((HWND) h);
  182843. return 0;
  182844. }
  182845. static void* getFocusCallback (void*)
  182846. {
  182847. return (void*) GetFocus();
  182848. }
  182849. void offsetWithinParent (int& x, int& y) const
  182850. {
  182851. if (isTransparent())
  182852. {
  182853. HWND parentHwnd = GetParent (hwnd);
  182854. if (parentHwnd != 0)
  182855. {
  182856. RECT parentRect;
  182857. GetWindowRect (parentHwnd, &parentRect);
  182858. x += parentRect.left;
  182859. y += parentRect.top;
  182860. }
  182861. }
  182862. }
  182863. bool isTransparent() const
  182864. {
  182865. return (GetWindowLong (hwnd, GWL_EXSTYLE) & WS_EX_LAYERED) != 0;
  182866. }
  182867. inline bool hasTitleBar() const throw() { return (styleFlags & windowHasTitleBar) != 0; }
  182868. void setIcon (const Image& newIcon)
  182869. {
  182870. HICON hicon = createHICONFromImage (newIcon, TRUE, 0, 0);
  182871. if (hicon != 0)
  182872. {
  182873. SendMessage (hwnd, WM_SETICON, ICON_BIG, (LPARAM) hicon);
  182874. SendMessage (hwnd, WM_SETICON, ICON_SMALL, (LPARAM) hicon);
  182875. if (currentWindowIcon != 0)
  182876. DestroyIcon (currentWindowIcon);
  182877. currentWindowIcon = hicon;
  182878. }
  182879. }
  182880. void handlePaintMessage()
  182881. {
  182882. #if DEBUG_REPAINT_TIMES
  182883. const double paintStart = Time::getMillisecondCounterHiRes();
  182884. #endif
  182885. HRGN rgn = CreateRectRgn (0, 0, 0, 0);
  182886. const int regionType = GetUpdateRgn (hwnd, rgn, false);
  182887. PAINTSTRUCT paintStruct;
  182888. HDC dc = BeginPaint (hwnd, &paintStruct); // Note this can immediately generate a WM_NCPAINT
  182889. // message and become re-entrant, but that's OK
  182890. // if something in a paint handler calls, e.g. a message box, this can become reentrant and
  182891. // corrupt the image it's using to paint into, so do a check here.
  182892. static bool reentrant = false;
  182893. if (reentrant)
  182894. {
  182895. DeleteObject (rgn);
  182896. EndPaint (hwnd, &paintStruct);
  182897. return;
  182898. }
  182899. reentrant = true;
  182900. // this is the rectangle to update..
  182901. int x = paintStruct.rcPaint.left;
  182902. int y = paintStruct.rcPaint.top;
  182903. int w = paintStruct.rcPaint.right - x;
  182904. int h = paintStruct.rcPaint.bottom - y;
  182905. const bool transparent = isTransparent();
  182906. if (transparent)
  182907. {
  182908. // it's not possible to have a transparent window with a title bar at the moment!
  182909. jassert (! hasTitleBar());
  182910. RECT r;
  182911. GetWindowRect (hwnd, &r);
  182912. x = y = 0;
  182913. w = r.right - r.left;
  182914. h = r.bottom - r.top;
  182915. }
  182916. if (w > 0 && h > 0)
  182917. {
  182918. clearMaskedRegion();
  182919. WindowsBitmapImage* const offscreenImage = offscreenImageGenerator.getImage (transparent, w, h);
  182920. RectangleList contextClip;
  182921. bool needToPaintAll = true;
  182922. if (regionType == COMPLEXREGION && ! transparent)
  182923. {
  182924. HRGN clipRgn = CreateRectRgnIndirect (&paintStruct.rcPaint);
  182925. CombineRgn (rgn, rgn, clipRgn, RGN_AND);
  182926. DeleteObject (clipRgn);
  182927. char rgnData [8192];
  182928. const DWORD res = GetRegionData (rgn, sizeof (rgnData), (RGNDATA*) rgnData);
  182929. if (res > 0 && res <= sizeof (rgnData))
  182930. {
  182931. const RGNDATAHEADER* const hdr = &(((const RGNDATA*) rgnData)->rdh);
  182932. if (hdr->iType == RDH_RECTANGLES
  182933. && hdr->rcBound.right - hdr->rcBound.left >= w
  182934. && hdr->rcBound.bottom - hdr->rcBound.top >= h)
  182935. {
  182936. needToPaintAll = false;
  182937. const RECT* rects = (const RECT*) (rgnData + sizeof (RGNDATAHEADER));
  182938. int num = ((RGNDATA*) rgnData)->rdh.nCount;
  182939. while (--num >= 0)
  182940. {
  182941. // (need to move this one pixel to the left because of a win32 bug)
  182942. const int cx = jmax (x, (int) rects->left - 1);
  182943. const int cy = rects->top;
  182944. const int cw = rects->right - cx;
  182945. const int ch = rects->bottom - rects->top;
  182946. if (cx + cw - x <= w && cy + ch - y <= h)
  182947. {
  182948. contextClip.addWithoutMerging (Rectangle (cx - x, cy - y, cw, ch));
  182949. }
  182950. else
  182951. {
  182952. needToPaintAll = true;
  182953. break;
  182954. }
  182955. ++rects;
  182956. }
  182957. }
  182958. }
  182959. }
  182960. if (needToPaintAll)
  182961. {
  182962. contextClip.clear();
  182963. contextClip.addWithoutMerging (Rectangle (0, 0, w, h));
  182964. }
  182965. if (transparent)
  182966. {
  182967. RectangleList::Iterator i (contextClip);
  182968. while (i.next())
  182969. {
  182970. const Rectangle& r = *i.getRectangle();
  182971. offscreenImage->clear (r.getX(), r.getY(), r.getWidth(), r.getHeight());
  182972. }
  182973. }
  182974. // if the component's not opaque, this won't draw properly unless the platform can support this
  182975. jassert (Desktop::canUseSemiTransparentWindows() || component->isOpaque());
  182976. updateCurrentModifiers();
  182977. LowLevelGraphicsSoftwareRenderer context (*offscreenImage);
  182978. context.clipToRectangleList (contextClip);
  182979. context.setOrigin (-x, -y);
  182980. handlePaint (context);
  182981. if (! dontRepaint)
  182982. offscreenImage->blitToWindow (hwnd, dc, transparent, x, y, maskedRegion);
  182983. }
  182984. DeleteObject (rgn);
  182985. EndPaint (hwnd, &paintStruct);
  182986. reentrant = false;
  182987. #ifndef JUCE_GCC //xxx should add this fn for gcc..
  182988. _fpreset(); // because some graphics cards can unmask FP exceptions
  182989. #endif
  182990. lastPaintTime = Time::getMillisecondCounter();
  182991. #if DEBUG_REPAINT_TIMES
  182992. const double elapsed = Time::getMillisecondCounterHiRes() - paintStart;
  182993. Logger::outputDebugString (T("repaint time: ") + String (elapsed, 2));
  182994. #endif
  182995. }
  182996. void doMouseMove (const int x, const int y)
  182997. {
  182998. static uint32 lastMouseTime = 0;
  182999. // this can be set to throttle the mouse-messages to less than a
  183000. // certain number per second, as things can get unresponsive
  183001. // if each drag or move callback has to do a lot of work.
  183002. const int maxMouseMovesPerSecond = 60;
  183003. const int64 mouseEventTime = getMouseEventTime();
  183004. if (! isMouseOver)
  183005. {
  183006. isMouseOver = true;
  183007. TRACKMOUSEEVENT tme;
  183008. tme.cbSize = sizeof (tme);
  183009. tme.dwFlags = TME_LEAVE;
  183010. tme.hwndTrack = hwnd;
  183011. tme.dwHoverTime = 0;
  183012. if (! TrackMouseEvent (&tme))
  183013. {
  183014. jassertfalse;
  183015. }
  183016. updateKeyModifiers();
  183017. handleMouseEnter (x, y, mouseEventTime);
  183018. }
  183019. else if (! isDragging)
  183020. {
  183021. if (((unsigned int) x) < (unsigned int) component->getWidth()
  183022. && ((unsigned int) y) < (unsigned int) component->getHeight())
  183023. {
  183024. RECT r;
  183025. GetWindowRect (hwnd, &r);
  183026. POINT p;
  183027. p.x = x + r.left + windowBorder.getLeft();
  183028. p.y = y + r.top + windowBorder.getTop();
  183029. if (WindowFromPoint (p) == hwnd)
  183030. {
  183031. const uint32 now = Time::getMillisecondCounter();
  183032. if (now > lastMouseTime + 1000 / maxMouseMovesPerSecond)
  183033. {
  183034. lastMouseTime = now;
  183035. handleMouseMove (x, y, mouseEventTime);
  183036. }
  183037. }
  183038. }
  183039. }
  183040. else
  183041. {
  183042. const uint32 now = Time::getMillisecondCounter();
  183043. if (now > lastMouseTime + 1000 / maxMouseMovesPerSecond)
  183044. {
  183045. lastMouseTime = now;
  183046. handleMouseDrag (x, y, mouseEventTime);
  183047. }
  183048. }
  183049. }
  183050. void doMouseDown (const int x, const int y, const WPARAM wParam)
  183051. {
  183052. if (GetCapture() != hwnd)
  183053. SetCapture (hwnd);
  183054. doMouseMove (x, y);
  183055. currentModifiers &= ~ModifierKeys::allMouseButtonModifiers;
  183056. if ((wParam & MK_LBUTTON) != 0)
  183057. currentModifiers |= ModifierKeys::leftButtonModifier;
  183058. if ((wParam & MK_RBUTTON) != 0)
  183059. currentModifiers |= ModifierKeys::rightButtonModifier;
  183060. if ((wParam & MK_MBUTTON) != 0)
  183061. currentModifiers |= ModifierKeys::middleButtonModifier;
  183062. updateKeyModifiers();
  183063. isDragging = true;
  183064. handleMouseDown (x, y, getMouseEventTime());
  183065. }
  183066. void doMouseUp (const int x, const int y, const WPARAM wParam)
  183067. {
  183068. int numButtons = 0;
  183069. if ((wParam & MK_LBUTTON) != 0)
  183070. ++numButtons;
  183071. if ((wParam & MK_RBUTTON) != 0)
  183072. ++numButtons;
  183073. if ((wParam & MK_MBUTTON) != 0)
  183074. ++numButtons;
  183075. const int oldModifiers = currentModifiers;
  183076. // update the currentmodifiers only after the callback, so the callback
  183077. // knows which button was released.
  183078. currentModifiers &= ~ModifierKeys::allMouseButtonModifiers;
  183079. if ((wParam & MK_LBUTTON) != 0)
  183080. currentModifiers |= ModifierKeys::leftButtonModifier;
  183081. if ((wParam & MK_RBUTTON) != 0)
  183082. currentModifiers |= ModifierKeys::rightButtonModifier;
  183083. if ((wParam & MK_MBUTTON) != 0)
  183084. currentModifiers |= ModifierKeys::middleButtonModifier;
  183085. updateKeyModifiers();
  183086. isDragging = false;
  183087. // release the mouse capture if the user's not still got a button down
  183088. if (numButtons == 0 && hwnd == GetCapture())
  183089. ReleaseCapture();
  183090. handleMouseUp (oldModifiers, x, y, getMouseEventTime());
  183091. }
  183092. void doCaptureChanged()
  183093. {
  183094. if (isDragging)
  183095. {
  183096. RECT wr;
  183097. GetWindowRect (hwnd, &wr);
  183098. const DWORD mp = GetMessagePos();
  183099. doMouseUp (GET_X_LPARAM (mp) - wr.left - windowBorder.getLeft(),
  183100. GET_Y_LPARAM (mp) - wr.top - windowBorder.getTop(),
  183101. (WPARAM) getMouseEventTime());
  183102. }
  183103. }
  183104. void doMouseExit()
  183105. {
  183106. if (isMouseOver)
  183107. {
  183108. isMouseOver = false;
  183109. RECT wr;
  183110. GetWindowRect (hwnd, &wr);
  183111. const DWORD mp = GetMessagePos();
  183112. handleMouseExit (GET_X_LPARAM (mp) - wr.left - windowBorder.getLeft(),
  183113. GET_Y_LPARAM (mp) - wr.top - windowBorder.getTop(),
  183114. getMouseEventTime());
  183115. }
  183116. }
  183117. void doMouseWheel (const WPARAM wParam, const bool isVertical)
  183118. {
  183119. updateKeyModifiers();
  183120. const int amount = jlimit (-1000, 1000, (int) (0.75f * (short) HIWORD (wParam)));
  183121. handleMouseWheel (isVertical ? 0 : amount,
  183122. isVertical ? amount : 0,
  183123. getMouseEventTime());
  183124. }
  183125. void sendModifierKeyChangeIfNeeded()
  183126. {
  183127. if (modifiersAtLastCallback != currentModifiers)
  183128. {
  183129. modifiersAtLastCallback = currentModifiers;
  183130. handleModifierKeysChange();
  183131. }
  183132. }
  183133. bool doKeyUp (const WPARAM key)
  183134. {
  183135. updateKeyModifiers();
  183136. switch (key)
  183137. {
  183138. case VK_SHIFT:
  183139. case VK_CONTROL:
  183140. case VK_MENU:
  183141. case VK_CAPITAL:
  183142. case VK_LWIN:
  183143. case VK_RWIN:
  183144. case VK_APPS:
  183145. case VK_NUMLOCK:
  183146. case VK_SCROLL:
  183147. case VK_LSHIFT:
  183148. case VK_RSHIFT:
  183149. case VK_LCONTROL:
  183150. case VK_LMENU:
  183151. case VK_RCONTROL:
  183152. case VK_RMENU:
  183153. sendModifierKeyChangeIfNeeded();
  183154. }
  183155. return handleKeyUpOrDown (false)
  183156. || Component::getCurrentlyModalComponent() != 0;
  183157. }
  183158. bool doKeyDown (const WPARAM key)
  183159. {
  183160. updateKeyModifiers();
  183161. bool used = false;
  183162. switch (key)
  183163. {
  183164. case VK_SHIFT:
  183165. case VK_LSHIFT:
  183166. case VK_RSHIFT:
  183167. case VK_CONTROL:
  183168. case VK_LCONTROL:
  183169. case VK_RCONTROL:
  183170. case VK_MENU:
  183171. case VK_LMENU:
  183172. case VK_RMENU:
  183173. case VK_LWIN:
  183174. case VK_RWIN:
  183175. case VK_CAPITAL:
  183176. case VK_NUMLOCK:
  183177. case VK_SCROLL:
  183178. case VK_APPS:
  183179. sendModifierKeyChangeIfNeeded();
  183180. break;
  183181. case VK_LEFT:
  183182. case VK_RIGHT:
  183183. case VK_UP:
  183184. case VK_DOWN:
  183185. case VK_PRIOR:
  183186. case VK_NEXT:
  183187. case VK_HOME:
  183188. case VK_END:
  183189. case VK_DELETE:
  183190. case VK_INSERT:
  183191. case VK_F1:
  183192. case VK_F2:
  183193. case VK_F3:
  183194. case VK_F4:
  183195. case VK_F5:
  183196. case VK_F6:
  183197. case VK_F7:
  183198. case VK_F8:
  183199. case VK_F9:
  183200. case VK_F10:
  183201. case VK_F11:
  183202. case VK_F12:
  183203. case VK_F13:
  183204. case VK_F14:
  183205. case VK_F15:
  183206. case VK_F16:
  183207. used = handleKeyUpOrDown (true);
  183208. used = handleKeyPress (extendedKeyModifier | (int) key, 0) || used;
  183209. break;
  183210. case VK_ADD:
  183211. case VK_SUBTRACT:
  183212. case VK_MULTIPLY:
  183213. case VK_DIVIDE:
  183214. case VK_SEPARATOR:
  183215. case VK_DECIMAL:
  183216. used = handleKeyUpOrDown (true);
  183217. break;
  183218. default:
  183219. used = handleKeyUpOrDown (true);
  183220. {
  183221. MSG msg;
  183222. if (! PeekMessage (&msg, hwnd, WM_CHAR, WM_DEADCHAR, PM_NOREMOVE))
  183223. {
  183224. // if there isn't a WM_CHAR or WM_DEADCHAR message pending, we need to
  183225. // manually generate the key-press event that matches this key-down.
  183226. const UINT keyChar = MapVirtualKey (key, 2);
  183227. used = handleKeyPress ((int) LOWORD (keyChar), 0) || used;
  183228. }
  183229. }
  183230. break;
  183231. }
  183232. if (Component::getCurrentlyModalComponent() != 0)
  183233. used = true;
  183234. return used;
  183235. }
  183236. bool doKeyChar (int key, const LPARAM flags)
  183237. {
  183238. updateKeyModifiers();
  183239. juce_wchar textChar = (juce_wchar) key;
  183240. const int virtualScanCode = (flags >> 16) & 0xff;
  183241. if (key >= '0' && key <= '9')
  183242. {
  183243. switch (virtualScanCode) // check for a numeric keypad scan-code
  183244. {
  183245. case 0x52:
  183246. case 0x4f:
  183247. case 0x50:
  183248. case 0x51:
  183249. case 0x4b:
  183250. case 0x4c:
  183251. case 0x4d:
  183252. case 0x47:
  183253. case 0x48:
  183254. case 0x49:
  183255. key = (key - '0') + KeyPress::numberPad0;
  183256. break;
  183257. default:
  183258. break;
  183259. }
  183260. }
  183261. else
  183262. {
  183263. // convert the scan code to an unmodified character code..
  183264. const UINT virtualKey = MapVirtualKey (virtualScanCode, 1);
  183265. UINT keyChar = MapVirtualKey (virtualKey, 2);
  183266. keyChar = LOWORD (keyChar);
  183267. if (keyChar != 0)
  183268. key = (int) keyChar;
  183269. // avoid sending junk text characters for some control-key combinations
  183270. if (textChar < ' ' && (currentModifiers & (ModifierKeys::ctrlModifier | ModifierKeys::altModifier)) != 0)
  183271. textChar = 0;
  183272. }
  183273. return handleKeyPress (key, textChar);
  183274. }
  183275. bool doAppCommand (const LPARAM lParam)
  183276. {
  183277. int key = 0;
  183278. switch (GET_APPCOMMAND_LPARAM (lParam))
  183279. {
  183280. case APPCOMMAND_MEDIA_PLAY_PAUSE:
  183281. key = KeyPress::playKey;
  183282. break;
  183283. case APPCOMMAND_MEDIA_STOP:
  183284. key = KeyPress::stopKey;
  183285. break;
  183286. case APPCOMMAND_MEDIA_NEXTTRACK:
  183287. key = KeyPress::fastForwardKey;
  183288. break;
  183289. case APPCOMMAND_MEDIA_PREVIOUSTRACK:
  183290. key = KeyPress::rewindKey;
  183291. break;
  183292. }
  183293. if (key != 0)
  183294. {
  183295. updateKeyModifiers();
  183296. if (hwnd == GetActiveWindow())
  183297. {
  183298. handleKeyPress (key, 0);
  183299. return true;
  183300. }
  183301. }
  183302. return false;
  183303. }
  183304. class JuceDropTarget : public IDropTarget
  183305. {
  183306. public:
  183307. JuceDropTarget (Win32ComponentPeer* const owner_)
  183308. : owner (owner_),
  183309. refCount (1)
  183310. {
  183311. }
  183312. virtual ~JuceDropTarget()
  183313. {
  183314. jassert (refCount == 0);
  183315. }
  183316. HRESULT __stdcall QueryInterface (REFIID id, void __RPC_FAR* __RPC_FAR* result)
  183317. {
  183318. if (id == IID_IUnknown || id == IID_IDropTarget)
  183319. {
  183320. AddRef();
  183321. *result = this;
  183322. return S_OK;
  183323. }
  183324. *result = 0;
  183325. return E_NOINTERFACE;
  183326. }
  183327. ULONG __stdcall AddRef() { return ++refCount; }
  183328. ULONG __stdcall Release() { jassert (refCount > 0); const int r = --refCount; if (r == 0) delete this; return r; }
  183329. HRESULT __stdcall DragEnter (IDataObject* pDataObject, DWORD /*grfKeyState*/, POINTL mousePos, DWORD* pdwEffect)
  183330. {
  183331. updateFileList (pDataObject);
  183332. int x = mousePos.x, y = mousePos.y;
  183333. owner->globalPositionToRelative (x, y);
  183334. owner->handleFileDragMove (files, x, y);
  183335. *pdwEffect = DROPEFFECT_COPY;
  183336. return S_OK;
  183337. }
  183338. HRESULT __stdcall DragLeave()
  183339. {
  183340. owner->handleFileDragExit (files);
  183341. return S_OK;
  183342. }
  183343. HRESULT __stdcall DragOver (DWORD /*grfKeyState*/, POINTL mousePos, DWORD* pdwEffect)
  183344. {
  183345. int x = mousePos.x, y = mousePos.y;
  183346. owner->globalPositionToRelative (x, y);
  183347. owner->handleFileDragMove (files, x, y);
  183348. *pdwEffect = DROPEFFECT_COPY;
  183349. return S_OK;
  183350. }
  183351. HRESULT __stdcall Drop (IDataObject* pDataObject, DWORD /*grfKeyState*/, POINTL mousePos, DWORD* pdwEffect)
  183352. {
  183353. updateFileList (pDataObject);
  183354. int x = mousePos.x, y = mousePos.y;
  183355. owner->globalPositionToRelative (x, y);
  183356. owner->handleFileDragDrop (files, x, y);
  183357. *pdwEffect = DROPEFFECT_COPY;
  183358. return S_OK;
  183359. }
  183360. private:
  183361. Win32ComponentPeer* const owner;
  183362. int refCount;
  183363. StringArray files;
  183364. void updateFileList (IDataObject* const pDataObject)
  183365. {
  183366. files.clear();
  183367. FORMATETC format = { CF_HDROP, 0, DVASPECT_CONTENT, -1, TYMED_HGLOBAL };
  183368. STGMEDIUM medium = { TYMED_HGLOBAL, { 0 }, 0 };
  183369. if (pDataObject->GetData (&format, &medium) == S_OK)
  183370. {
  183371. const SIZE_T totalLen = GlobalSize (medium.hGlobal);
  183372. const LPDROPFILES pDropFiles = (const LPDROPFILES) GlobalLock (medium.hGlobal);
  183373. unsigned int i = 0;
  183374. if (pDropFiles->fWide)
  183375. {
  183376. const WCHAR* const fname = (WCHAR*) (((const char*) pDropFiles) + sizeof (DROPFILES));
  183377. for (;;)
  183378. {
  183379. unsigned int len = 0;
  183380. while (i + len < totalLen && fname [i + len] != 0)
  183381. ++len;
  183382. if (len == 0)
  183383. break;
  183384. files.add (String (fname + i, len));
  183385. i += len + 1;
  183386. }
  183387. }
  183388. else
  183389. {
  183390. const char* const fname = ((const char*) pDropFiles) + sizeof (DROPFILES);
  183391. for (;;)
  183392. {
  183393. unsigned int len = 0;
  183394. while (i + len < totalLen && fname [i + len] != 0)
  183395. ++len;
  183396. if (len == 0)
  183397. break;
  183398. files.add (String (fname + i, len));
  183399. i += len + 1;
  183400. }
  183401. }
  183402. GlobalUnlock (medium.hGlobal);
  183403. }
  183404. }
  183405. JuceDropTarget (const JuceDropTarget&);
  183406. const JuceDropTarget& operator= (const JuceDropTarget&);
  183407. };
  183408. void doSettingChange()
  183409. {
  183410. Desktop::getInstance().refreshMonitorSizes();
  183411. if (fullScreen && ! isMinimised())
  183412. {
  183413. const Rectangle r (component->getParentMonitorArea());
  183414. SetWindowPos (hwnd, 0,
  183415. r.getX(), r.getY(), r.getWidth(), r.getHeight(),
  183416. SWP_NOACTIVATE | SWP_NOOWNERZORDER | SWP_NOZORDER | SWP_NOSENDCHANGING);
  183417. }
  183418. }
  183419. public:
  183420. static LRESULT CALLBACK windowProc (HWND h, UINT message, WPARAM wParam, LPARAM lParam)
  183421. {
  183422. Win32ComponentPeer* const peer = getOwnerOfWindow (h);
  183423. if (peer != 0)
  183424. return peer->peerWindowProc (h, message, wParam, lParam);
  183425. return DefWindowProc (h, message, wParam, lParam);
  183426. }
  183427. private:
  183428. LRESULT peerWindowProc (HWND h, UINT message, WPARAM wParam, LPARAM lParam)
  183429. {
  183430. if (isValidPeer (this))
  183431. {
  183432. switch (message)
  183433. {
  183434. case WM_NCHITTEST:
  183435. if ((styleFlags & windowIgnoresMouseClicks) != 0)
  183436. return HTTRANSPARENT;
  183437. if (hasTitleBar())
  183438. break;
  183439. return HTCLIENT;
  183440. case WM_PAINT:
  183441. handlePaintMessage();
  183442. return 0;
  183443. case WM_NCPAINT:
  183444. if (wParam != 1)
  183445. handlePaintMessage();
  183446. if (hasTitleBar())
  183447. break;
  183448. return 0;
  183449. case WM_ERASEBKGND:
  183450. case WM_NCCALCSIZE:
  183451. if (hasTitleBar())
  183452. break;
  183453. return 1;
  183454. case WM_MOUSEMOVE:
  183455. doMouseMove (GET_X_LPARAM (lParam), GET_Y_LPARAM (lParam));
  183456. return 0;
  183457. case WM_MOUSELEAVE:
  183458. doMouseExit();
  183459. return 0;
  183460. case WM_LBUTTONDOWN:
  183461. case WM_MBUTTONDOWN:
  183462. case WM_RBUTTONDOWN:
  183463. doMouseDown (GET_X_LPARAM (lParam), GET_Y_LPARAM (lParam), wParam);
  183464. return 0;
  183465. case WM_LBUTTONUP:
  183466. case WM_MBUTTONUP:
  183467. case WM_RBUTTONUP:
  183468. doMouseUp (GET_X_LPARAM (lParam), GET_Y_LPARAM (lParam), wParam);
  183469. return 0;
  183470. case WM_CAPTURECHANGED:
  183471. doCaptureChanged();
  183472. return 0;
  183473. case WM_NCMOUSEMOVE:
  183474. if (hasTitleBar())
  183475. break;
  183476. return 0;
  183477. case 0x020A: /* WM_MOUSEWHEEL */
  183478. doMouseWheel (wParam, true);
  183479. return 0;
  183480. case 0x020E: /* WM_MOUSEHWHEEL */
  183481. doMouseWheel (wParam, false);
  183482. return 0;
  183483. case WM_WINDOWPOSCHANGING:
  183484. if ((styleFlags & (windowHasTitleBar | windowIsResizable)) == (windowHasTitleBar | windowIsResizable))
  183485. {
  183486. WINDOWPOS* const wp = (WINDOWPOS*) lParam;
  183487. if ((wp->flags & (SWP_NOMOVE | SWP_NOSIZE)) != (SWP_NOMOVE | SWP_NOSIZE))
  183488. {
  183489. if (constrainer != 0)
  183490. {
  183491. const Rectangle current (component->getX() - windowBorder.getLeft(),
  183492. component->getY() - windowBorder.getTop(),
  183493. component->getWidth() + windowBorder.getLeftAndRight(),
  183494. component->getHeight() + windowBorder.getTopAndBottom());
  183495. constrainer->checkBounds (wp->x, wp->y, wp->cx, wp->cy,
  183496. current,
  183497. Desktop::getInstance().getAllMonitorDisplayAreas().getBounds(),
  183498. wp->y != current.getY() && wp->y + wp->cy == current.getBottom(),
  183499. wp->x != current.getX() && wp->x + wp->cx == current.getRight(),
  183500. wp->y == current.getY() && wp->y + wp->cy != current.getBottom(),
  183501. wp->x == current.getX() && wp->x + wp->cx != current.getRight());
  183502. }
  183503. }
  183504. }
  183505. return 0;
  183506. case WM_WINDOWPOSCHANGED:
  183507. handleMovedOrResized();
  183508. if (dontRepaint)
  183509. break; // needed for non-accelerated openGL windows to draw themselves correctly..
  183510. return 0;
  183511. case WM_KEYDOWN:
  183512. case WM_SYSKEYDOWN:
  183513. if (doKeyDown (wParam))
  183514. return 0;
  183515. break;
  183516. case WM_KEYUP:
  183517. case WM_SYSKEYUP:
  183518. if (doKeyUp (wParam))
  183519. return 0;
  183520. break;
  183521. case WM_CHAR:
  183522. if (doKeyChar ((int) wParam, lParam))
  183523. return 0;
  183524. break;
  183525. case WM_APPCOMMAND:
  183526. if (doAppCommand (lParam))
  183527. return TRUE;
  183528. break;
  183529. case WM_SETFOCUS:
  183530. updateKeyModifiers();
  183531. handleFocusGain();
  183532. break;
  183533. case WM_KILLFOCUS:
  183534. if (hasCreatedCaret)
  183535. {
  183536. hasCreatedCaret = false;
  183537. DestroyCaret();
  183538. }
  183539. handleFocusLoss();
  183540. break;
  183541. case WM_ACTIVATEAPP:
  183542. // Windows does weird things to process priority when you swap apps,
  183543. // so this forces an update when the app is brought to the front
  183544. if (wParam != FALSE)
  183545. juce_repeatLastProcessPriority();
  183546. else
  183547. Desktop::getInstance().setKioskModeComponent (0); // turn kiosk mode off if we lose focus
  183548. juce_CheckCurrentlyFocusedTopLevelWindow();
  183549. modifiersAtLastCallback = -1;
  183550. return 0;
  183551. case WM_ACTIVATE:
  183552. if (LOWORD (wParam) == WA_ACTIVE || LOWORD (wParam) == WA_CLICKACTIVE)
  183553. {
  183554. modifiersAtLastCallback = -1;
  183555. updateKeyModifiers();
  183556. if (isMinimised())
  183557. {
  183558. component->repaint();
  183559. handleMovedOrResized();
  183560. if (! isValidMessageListener())
  183561. return 0;
  183562. }
  183563. if (LOWORD (wParam) == WA_CLICKACTIVE
  183564. && component->isCurrentlyBlockedByAnotherModalComponent())
  183565. {
  183566. int mx, my;
  183567. component->getMouseXYRelative (mx, my);
  183568. Component* const underMouse = component->getComponentAt (mx, my);
  183569. if (underMouse != 0 && underMouse->isCurrentlyBlockedByAnotherModalComponent())
  183570. Component::getCurrentlyModalComponent()->inputAttemptWhenModal();
  183571. return 0;
  183572. }
  183573. handleBroughtToFront();
  183574. if (component->isCurrentlyBlockedByAnotherModalComponent())
  183575. Component::getCurrentlyModalComponent()->toFront (true);
  183576. return 0;
  183577. }
  183578. break;
  183579. case WM_NCACTIVATE:
  183580. // while a temporary window is being shown, prevent Windows from deactivating the
  183581. // title bars of our main windows.
  183582. if (wParam == 0 && ! shouldDeactivateTitleBar)
  183583. wParam = TRUE; // change this and let it get passed to the DefWindowProc.
  183584. break;
  183585. case WM_MOUSEACTIVATE:
  183586. if (! component->getMouseClickGrabsKeyboardFocus())
  183587. return MA_NOACTIVATE;
  183588. break;
  183589. case WM_SHOWWINDOW:
  183590. if (wParam != 0)
  183591. handleBroughtToFront();
  183592. break;
  183593. case WM_CLOSE:
  183594. if (! component->isCurrentlyBlockedByAnotherModalComponent())
  183595. handleUserClosingWindow();
  183596. return 0;
  183597. case WM_QUERYENDSESSION:
  183598. if (JUCEApplication::getInstance() != 0)
  183599. {
  183600. JUCEApplication::getInstance()->systemRequestedQuit();
  183601. return MessageManager::getInstance()->hasStopMessageBeenSent();
  183602. }
  183603. return TRUE;
  183604. case WM_TRAYNOTIFY:
  183605. if (component->isCurrentlyBlockedByAnotherModalComponent())
  183606. {
  183607. if (lParam == WM_LBUTTONDOWN || lParam == WM_RBUTTONDOWN
  183608. || lParam == WM_LBUTTONDBLCLK || lParam == WM_LBUTTONDBLCLK)
  183609. {
  183610. Component* const current = Component::getCurrentlyModalComponent();
  183611. if (current != 0)
  183612. current->inputAttemptWhenModal();
  183613. }
  183614. }
  183615. else
  183616. {
  183617. const int oldModifiers = currentModifiers;
  183618. MouseEvent e (0, 0, ModifierKeys::getCurrentModifiersRealtime(), component,
  183619. getMouseEventTime(), 0, 0, getMouseEventTime(), 1, false);
  183620. if (lParam == WM_LBUTTONDOWN || lParam == WM_LBUTTONDBLCLK)
  183621. e.mods = ModifierKeys (e.mods.getRawFlags() | ModifierKeys::leftButtonModifier);
  183622. else if (lParam == WM_RBUTTONDOWN || lParam == WM_RBUTTONDBLCLK)
  183623. e.mods = ModifierKeys (e.mods.getRawFlags() | ModifierKeys::rightButtonModifier);
  183624. if (lParam == WM_LBUTTONDOWN || lParam == WM_RBUTTONDOWN)
  183625. {
  183626. SetFocus (hwnd);
  183627. SetForegroundWindow (hwnd);
  183628. component->mouseDown (e);
  183629. }
  183630. else if (lParam == WM_LBUTTONUP || lParam == WM_RBUTTONUP)
  183631. {
  183632. e.mods = ModifierKeys (oldModifiers);
  183633. component->mouseUp (e);
  183634. }
  183635. else if (lParam == WM_LBUTTONDBLCLK || lParam == WM_LBUTTONDBLCLK)
  183636. {
  183637. e.mods = ModifierKeys (oldModifiers);
  183638. component->mouseDoubleClick (e);
  183639. }
  183640. else if (lParam == WM_MOUSEMOVE)
  183641. {
  183642. component->mouseMove (e);
  183643. }
  183644. }
  183645. break;
  183646. case WM_SYNCPAINT:
  183647. return 0;
  183648. case WM_PALETTECHANGED:
  183649. InvalidateRect (h, 0, 0);
  183650. break;
  183651. case WM_DISPLAYCHANGE:
  183652. InvalidateRect (h, 0, 0);
  183653. createPaletteIfNeeded = true;
  183654. // intentional fall-through...
  183655. case WM_SETTINGCHANGE: // note the fall-through in the previous case!
  183656. doSettingChange();
  183657. break;
  183658. case WM_INITMENU:
  183659. if (! hasTitleBar())
  183660. {
  183661. if (isFullScreen())
  183662. {
  183663. EnableMenuItem ((HMENU) wParam, SC_RESTORE, MF_BYCOMMAND | MF_ENABLED);
  183664. EnableMenuItem ((HMENU) wParam, SC_MOVE, MF_BYCOMMAND | MF_GRAYED);
  183665. }
  183666. else if (! isMinimised())
  183667. {
  183668. EnableMenuItem ((HMENU) wParam, SC_MAXIMIZE, MF_BYCOMMAND | MF_GRAYED);
  183669. }
  183670. }
  183671. break;
  183672. case WM_SYSCOMMAND:
  183673. switch (wParam & 0xfff0)
  183674. {
  183675. case SC_CLOSE:
  183676. if (sendInputAttemptWhenModalMessage())
  183677. return 0;
  183678. if (hasTitleBar())
  183679. {
  183680. PostMessage (h, WM_CLOSE, 0, 0);
  183681. return 0;
  183682. }
  183683. break;
  183684. case SC_KEYMENU:
  183685. // (NB mustn't call sendInputAttemptWhenModalMessage() here because of very
  183686. // obscure situations that can arise if a modal loop is started from an alt-key
  183687. // keypress).
  183688. if (hasTitleBar() && h == GetCapture())
  183689. ReleaseCapture();
  183690. break;
  183691. case SC_MAXIMIZE:
  183692. if (sendInputAttemptWhenModalMessage())
  183693. return 0;
  183694. setFullScreen (true);
  183695. return 0;
  183696. case SC_MINIMIZE:
  183697. if (sendInputAttemptWhenModalMessage())
  183698. return 0;
  183699. if (! hasTitleBar())
  183700. {
  183701. setMinimised (true);
  183702. return 0;
  183703. }
  183704. break;
  183705. case SC_RESTORE:
  183706. if (sendInputAttemptWhenModalMessage())
  183707. return 0;
  183708. if (hasTitleBar())
  183709. {
  183710. if (isFullScreen())
  183711. {
  183712. setFullScreen (false);
  183713. return 0;
  183714. }
  183715. }
  183716. else
  183717. {
  183718. if (isMinimised())
  183719. setMinimised (false);
  183720. else if (isFullScreen())
  183721. setFullScreen (false);
  183722. return 0;
  183723. }
  183724. break;
  183725. }
  183726. break;
  183727. case WM_NCLBUTTONDOWN:
  183728. case WM_NCRBUTTONDOWN:
  183729. case WM_NCMBUTTONDOWN:
  183730. sendInputAttemptWhenModalMessage();
  183731. break;
  183732. //case WM_IME_STARTCOMPOSITION;
  183733. // return 0;
  183734. case WM_GETDLGCODE:
  183735. return DLGC_WANTALLKEYS;
  183736. default:
  183737. break;
  183738. }
  183739. }
  183740. return DefWindowProc (h, message, wParam, lParam);
  183741. }
  183742. bool sendInputAttemptWhenModalMessage()
  183743. {
  183744. if (component->isCurrentlyBlockedByAnotherModalComponent())
  183745. {
  183746. Component* const current = Component::getCurrentlyModalComponent();
  183747. if (current != 0)
  183748. current->inputAttemptWhenModal();
  183749. return true;
  183750. }
  183751. return false;
  183752. }
  183753. Win32ComponentPeer (const Win32ComponentPeer&);
  183754. const Win32ComponentPeer& operator= (const Win32ComponentPeer&);
  183755. };
  183756. ComponentPeer* Component::createNewPeer (int styleFlags, void* /*nativeWindowToAttachTo*/)
  183757. {
  183758. return new Win32ComponentPeer (this, styleFlags);
  183759. }
  183760. juce_ImplementSingleton_SingleThreaded (Win32ComponentPeer::WindowClassHolder);
  183761. void SystemTrayIconComponent::setIconImage (const Image& newImage)
  183762. {
  183763. Win32ComponentPeer* const wp = dynamic_cast <Win32ComponentPeer*> (getPeer());
  183764. if (wp != 0)
  183765. wp->setTaskBarIcon (&newImage);
  183766. }
  183767. void SystemTrayIconComponent::setIconTooltip (const String& tooltip)
  183768. {
  183769. Win32ComponentPeer* const wp = dynamic_cast <Win32ComponentPeer*> (getPeer());
  183770. if (wp != 0)
  183771. wp->setTaskBarIconToolTip (tooltip);
  183772. }
  183773. void juce_setWindowStyleBit (HWND h, const int styleType, const int feature, const bool bitIsSet) throw()
  183774. {
  183775. DWORD val = GetWindowLong (h, styleType);
  183776. if (bitIsSet)
  183777. val |= feature;
  183778. else
  183779. val &= ~feature;
  183780. SetWindowLongPtr (h, styleType, val);
  183781. SetWindowPos (h, 0, 0, 0, 0, 0,
  183782. SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER
  183783. | SWP_NOOWNERZORDER | SWP_FRAMECHANGED | SWP_NOSENDCHANGING);
  183784. }
  183785. bool Process::isForegroundProcess()
  183786. {
  183787. HWND fg = GetForegroundWindow();
  183788. if (fg == 0)
  183789. return true;
  183790. // when running as a plugin in IE8, the browser UI runs in a different process to the plugin, so
  183791. // process ID isn't a reliable way to check if the foreground window belongs to us - instead, we
  183792. // have to see if any of our windows are children of the foreground window
  183793. fg = GetAncestor (fg, GA_ROOT);
  183794. for (int i = ComponentPeer::getNumPeers(); --i >= 0;)
  183795. {
  183796. Win32ComponentPeer* const wp = dynamic_cast <Win32ComponentPeer*> (ComponentPeer::getPeer (i));
  183797. if (wp != 0 && wp->isInside (fg))
  183798. return true;
  183799. }
  183800. return false;
  183801. }
  183802. bool AlertWindow::showNativeDialogBox (const String& title,
  183803. const String& bodyText,
  183804. bool isOkCancel)
  183805. {
  183806. return MessageBox (0, bodyText, title,
  183807. MB_SETFOREGROUND | (isOkCancel ? MB_OKCANCEL
  183808. : MB_OK)) == IDOK;
  183809. }
  183810. void Desktop::getMousePosition (int& x, int& y) throw()
  183811. {
  183812. POINT mousePos;
  183813. GetCursorPos (&mousePos);
  183814. x = mousePos.x;
  183815. y = mousePos.y;
  183816. }
  183817. void Desktop::setMousePosition (int x, int y) throw()
  183818. {
  183819. SetCursorPos (x, y);
  183820. }
  183821. Image* Image::createNativeImage (const PixelFormat format, const int imageWidth, const int imageHeight, const bool clearImage)
  183822. {
  183823. return new Image (format, imageWidth, imageHeight, clearImage);
  183824. }
  183825. class ScreenSaverDefeater : public Timer,
  183826. public DeletedAtShutdown
  183827. {
  183828. public:
  183829. ScreenSaverDefeater() throw()
  183830. {
  183831. startTimer (10000);
  183832. timerCallback();
  183833. }
  183834. ~ScreenSaverDefeater() {}
  183835. void timerCallback()
  183836. {
  183837. if (Process::isForegroundProcess())
  183838. {
  183839. // simulate a shift key getting pressed..
  183840. INPUT input[2];
  183841. input[0].type = INPUT_KEYBOARD;
  183842. input[0].ki.wVk = VK_SHIFT;
  183843. input[0].ki.dwFlags = 0;
  183844. input[0].ki.dwExtraInfo = 0;
  183845. input[1].type = INPUT_KEYBOARD;
  183846. input[1].ki.wVk = VK_SHIFT;
  183847. input[1].ki.dwFlags = KEYEVENTF_KEYUP;
  183848. input[1].ki.dwExtraInfo = 0;
  183849. SendInput (2, input, sizeof (INPUT));
  183850. }
  183851. }
  183852. };
  183853. static ScreenSaverDefeater* screenSaverDefeater = 0;
  183854. void Desktop::setScreenSaverEnabled (const bool isEnabled) throw()
  183855. {
  183856. if (isEnabled)
  183857. {
  183858. deleteAndZero (screenSaverDefeater);
  183859. }
  183860. else if (screenSaverDefeater == 0)
  183861. {
  183862. screenSaverDefeater = new ScreenSaverDefeater();
  183863. }
  183864. }
  183865. bool Desktop::isScreenSaverEnabled() throw()
  183866. {
  183867. return screenSaverDefeater == 0;
  183868. }
  183869. void juce_setKioskComponent (Component* kioskModeComponent, bool enableOrDisable, bool /*allowMenusAndBars*/)
  183870. {
  183871. if (enableOrDisable)
  183872. kioskModeComponent->setBounds (Desktop::getInstance().getMainMonitorArea (false));
  183873. }
  183874. static BOOL CALLBACK enumMonitorsProc (HMONITOR, HDC, LPRECT r, LPARAM userInfo)
  183875. {
  183876. Array <Rectangle>* const monitorCoords = (Array <Rectangle>*) userInfo;
  183877. monitorCoords->add (Rectangle (r->left, r->top, r->right - r->left, r->bottom - r->top));
  183878. return TRUE;
  183879. }
  183880. void juce_updateMultiMonitorInfo (Array <Rectangle>& monitorCoords, const bool clipToWorkArea)
  183881. {
  183882. EnumDisplayMonitors (0, 0, &enumMonitorsProc, (LPARAM) &monitorCoords);
  183883. // make sure the first in the list is the main monitor
  183884. for (int i = 1; i < monitorCoords.size(); ++i)
  183885. if (monitorCoords[i].getX() == 0 && monitorCoords[i].getY() == 0)
  183886. monitorCoords.swap (i, 0);
  183887. if (monitorCoords.size() == 0)
  183888. {
  183889. RECT r;
  183890. GetWindowRect (GetDesktopWindow(), &r);
  183891. monitorCoords.add (Rectangle (r.left, r.top, r.right - r.left, r.bottom - r.top));
  183892. }
  183893. if (clipToWorkArea)
  183894. {
  183895. // clip the main monitor to the active non-taskbar area
  183896. RECT r;
  183897. SystemParametersInfo (SPI_GETWORKAREA, 0, &r, 0);
  183898. Rectangle& screen = monitorCoords.getReference (0);
  183899. screen.setPosition (jmax (screen.getX(), (int) r.left),
  183900. jmax (screen.getY(), (int) r.top));
  183901. screen.setSize (jmin (screen.getRight(), (int) r.right) - screen.getX(),
  183902. jmin (screen.getBottom(), (int) r.bottom) - screen.getY());
  183903. }
  183904. }
  183905. static Image* createImageFromHBITMAP (HBITMAP bitmap) throw()
  183906. {
  183907. Image* im = 0;
  183908. if (bitmap != 0)
  183909. {
  183910. BITMAP bm;
  183911. if (GetObject (bitmap, sizeof (BITMAP), &bm)
  183912. && bm.bmWidth > 0 && bm.bmHeight > 0)
  183913. {
  183914. HDC tempDC = GetDC (0);
  183915. HDC dc = CreateCompatibleDC (tempDC);
  183916. ReleaseDC (0, tempDC);
  183917. SelectObject (dc, bitmap);
  183918. im = new Image (Image::ARGB, bm.bmWidth, bm.bmHeight, true);
  183919. for (int y = bm.bmHeight; --y >= 0;)
  183920. {
  183921. for (int x = bm.bmWidth; --x >= 0;)
  183922. {
  183923. COLORREF col = GetPixel (dc, x, y);
  183924. im->setPixelAt (x, y, Colour ((uint8) GetRValue (col),
  183925. (uint8) GetGValue (col),
  183926. (uint8) GetBValue (col)));
  183927. }
  183928. }
  183929. DeleteDC (dc);
  183930. }
  183931. }
  183932. return im;
  183933. }
  183934. static Image* createImageFromHICON (HICON icon) throw()
  183935. {
  183936. ICONINFO info;
  183937. if (GetIconInfo (icon, &info))
  183938. {
  183939. Image* const mask = createImageFromHBITMAP (info.hbmMask);
  183940. if (mask == 0)
  183941. return 0;
  183942. Image* const image = createImageFromHBITMAP (info.hbmColor);
  183943. if (image == 0)
  183944. return mask;
  183945. for (int y = image->getHeight(); --y >= 0;)
  183946. {
  183947. for (int x = image->getWidth(); --x >= 0;)
  183948. {
  183949. const float brightness = mask->getPixelAt (x, y).getBrightness();
  183950. if (brightness > 0.0f)
  183951. image->multiplyAlphaAt (x, y, 1.0f - brightness);
  183952. }
  183953. }
  183954. delete mask;
  183955. return image;
  183956. }
  183957. return 0;
  183958. }
  183959. static HICON createHICONFromImage (const Image& image, const BOOL isIcon, int hotspotX, int hotspotY) throw()
  183960. {
  183961. HBITMAP mask = CreateBitmap (image.getWidth(), image.getHeight(), 1, 1, 0);
  183962. ICONINFO info;
  183963. info.fIcon = isIcon;
  183964. info.xHotspot = hotspotX;
  183965. info.yHotspot = hotspotY;
  183966. info.hbmMask = mask;
  183967. HICON hi = 0;
  183968. if (SystemStats::getOperatingSystemType() >= SystemStats::WinXP)
  183969. {
  183970. WindowsBitmapImage bitmap (Image::ARGB, image.getWidth(), image.getHeight(), true);
  183971. Graphics g (bitmap);
  183972. g.drawImageAt (&image, 0, 0);
  183973. info.hbmColor = bitmap.hBitmap;
  183974. hi = CreateIconIndirect (&info);
  183975. }
  183976. else
  183977. {
  183978. HBITMAP colour = CreateCompatibleBitmap (GetDC (0), image.getWidth(), image.getHeight());
  183979. HDC colDC = CreateCompatibleDC (GetDC (0));
  183980. HDC alphaDC = CreateCompatibleDC (GetDC (0));
  183981. SelectObject (colDC, colour);
  183982. SelectObject (alphaDC, mask);
  183983. for (int y = image.getHeight(); --y >= 0;)
  183984. {
  183985. for (int x = image.getWidth(); --x >= 0;)
  183986. {
  183987. const Colour c (image.getPixelAt (x, y));
  183988. SetPixel (colDC, x, y, COLORREF (c.getRed() | (c.getGreen() << 8) | (c.getBlue() << 16)));
  183989. SetPixel (alphaDC, x, y, COLORREF (0xffffff - (c.getAlpha() | (c.getAlpha() << 8) | (c.getAlpha() << 16))));
  183990. }
  183991. }
  183992. DeleteDC (colDC);
  183993. DeleteDC (alphaDC);
  183994. info.hbmColor = colour;
  183995. hi = CreateIconIndirect (&info);
  183996. DeleteObject (colour);
  183997. }
  183998. DeleteObject (mask);
  183999. return hi;
  184000. }
  184001. Image* juce_createIconForFile (const File& file)
  184002. {
  184003. Image* image = 0;
  184004. TCHAR filename [1024];
  184005. file.getFullPathName().copyToBuffer (filename, 1023);
  184006. WORD iconNum = 0;
  184007. HICON icon = ExtractAssociatedIcon ((HINSTANCE) PlatformUtilities::getCurrentModuleInstanceHandle(),
  184008. filename, &iconNum);
  184009. if (icon != 0)
  184010. {
  184011. image = createImageFromHICON (icon);
  184012. DestroyIcon (icon);
  184013. }
  184014. return image;
  184015. }
  184016. void* juce_createMouseCursorFromImage (const Image& image, int hotspotX, int hotspotY) throw()
  184017. {
  184018. const int maxW = GetSystemMetrics (SM_CXCURSOR);
  184019. const int maxH = GetSystemMetrics (SM_CYCURSOR);
  184020. const Image* im = &image;
  184021. Image* newIm = 0;
  184022. if (image.getWidth() > maxW || image.getHeight() > maxH)
  184023. {
  184024. im = newIm = image.createCopy (maxW, maxH);
  184025. hotspotX = (hotspotX * maxW) / image.getWidth();
  184026. hotspotY = (hotspotY * maxH) / image.getHeight();
  184027. }
  184028. void* cursorH = 0;
  184029. const SystemStats::OperatingSystemType os = SystemStats::getOperatingSystemType();
  184030. if (os == SystemStats::WinXP)
  184031. {
  184032. cursorH = (void*) createHICONFromImage (*im, FALSE, hotspotX, hotspotY);
  184033. }
  184034. else
  184035. {
  184036. const int stride = (maxW + 7) >> 3;
  184037. HeapBlock <uint8> andPlane, xorPlane;
  184038. andPlane.calloc (stride * maxH);
  184039. xorPlane.calloc (stride * maxH);
  184040. int index = 0;
  184041. for (int y = 0; y < maxH; ++y)
  184042. {
  184043. for (int x = 0; x < maxW; ++x)
  184044. {
  184045. const unsigned char bit = (unsigned char) (1 << (7 - (x & 7)));
  184046. const Colour pixelColour (im->getPixelAt (x, y));
  184047. if (pixelColour.getAlpha() < 127)
  184048. andPlane [index + (x >> 3)] |= bit;
  184049. else if (pixelColour.getBrightness() >= 0.5f)
  184050. xorPlane [index + (x >> 3)] |= bit;
  184051. }
  184052. index += stride;
  184053. }
  184054. cursorH = CreateCursor (0, hotspotX, hotspotY, maxW, maxH, andPlane, xorPlane);
  184055. }
  184056. delete newIm;
  184057. return cursorH;
  184058. }
  184059. void juce_deleteMouseCursor (void* const cursorHandle, const bool isStandard) throw()
  184060. {
  184061. if (cursorHandle != 0 && ! isStandard)
  184062. DestroyCursor ((HCURSOR) cursorHandle);
  184063. }
  184064. void* juce_createStandardMouseCursor (MouseCursor::StandardCursorType type) throw()
  184065. {
  184066. LPCTSTR cursorName = IDC_ARROW;
  184067. switch (type)
  184068. {
  184069. case MouseCursor::NormalCursor:
  184070. cursorName = IDC_ARROW;
  184071. break;
  184072. case MouseCursor::NoCursor:
  184073. return 0;
  184074. case MouseCursor::DraggingHandCursor:
  184075. {
  184076. static void* dragHandCursor = 0;
  184077. if (dragHandCursor == 0)
  184078. {
  184079. static const unsigned char dragHandData[] =
  184080. { 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,
  184081. 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,
  184082. 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 };
  184083. const ScopedPointer <Image> image (ImageFileFormat::loadFrom ((const char*) dragHandData, sizeof (dragHandData)));
  184084. dragHandCursor = juce_createMouseCursorFromImage (*image, 8, 7);
  184085. }
  184086. return dragHandCursor;
  184087. }
  184088. case MouseCursor::WaitCursor:
  184089. cursorName = IDC_WAIT;
  184090. break;
  184091. case MouseCursor::IBeamCursor:
  184092. cursorName = IDC_IBEAM;
  184093. break;
  184094. case MouseCursor::PointingHandCursor:
  184095. cursorName = MAKEINTRESOURCE(32649);
  184096. break;
  184097. case MouseCursor::LeftRightResizeCursor:
  184098. case MouseCursor::LeftEdgeResizeCursor:
  184099. case MouseCursor::RightEdgeResizeCursor:
  184100. cursorName = IDC_SIZEWE;
  184101. break;
  184102. case MouseCursor::UpDownResizeCursor:
  184103. case MouseCursor::TopEdgeResizeCursor:
  184104. case MouseCursor::BottomEdgeResizeCursor:
  184105. cursorName = IDC_SIZENS;
  184106. break;
  184107. case MouseCursor::TopLeftCornerResizeCursor:
  184108. case MouseCursor::BottomRightCornerResizeCursor:
  184109. cursorName = IDC_SIZENWSE;
  184110. break;
  184111. case MouseCursor::TopRightCornerResizeCursor:
  184112. case MouseCursor::BottomLeftCornerResizeCursor:
  184113. cursorName = IDC_SIZENESW;
  184114. break;
  184115. case MouseCursor::UpDownLeftRightResizeCursor:
  184116. cursorName = IDC_SIZEALL;
  184117. break;
  184118. case MouseCursor::CrosshairCursor:
  184119. cursorName = IDC_CROSS;
  184120. break;
  184121. case MouseCursor::CopyingCursor:
  184122. // can't seem to find one of these in the win32 list..
  184123. break;
  184124. }
  184125. HCURSOR cursorH = LoadCursor (0, cursorName);
  184126. if (cursorH == 0)
  184127. cursorH = LoadCursor (0, IDC_ARROW);
  184128. return (void*) cursorH;
  184129. }
  184130. void MouseCursor::showInWindow (ComponentPeer*) const throw()
  184131. {
  184132. SetCursor ((HCURSOR) getHandle());
  184133. }
  184134. void MouseCursor::showInAllWindows() const throw()
  184135. {
  184136. showInWindow (0);
  184137. }
  184138. class JuceDropSource : public IDropSource
  184139. {
  184140. int refCount;
  184141. public:
  184142. JuceDropSource()
  184143. : refCount (1)
  184144. {
  184145. }
  184146. virtual ~JuceDropSource()
  184147. {
  184148. jassert (refCount == 0);
  184149. }
  184150. HRESULT __stdcall QueryInterface (REFIID id, void __RPC_FAR* __RPC_FAR* result)
  184151. {
  184152. if (id == IID_IUnknown || id == IID_IDropSource)
  184153. {
  184154. AddRef();
  184155. *result = this;
  184156. return S_OK;
  184157. }
  184158. *result = 0;
  184159. return E_NOINTERFACE;
  184160. }
  184161. ULONG __stdcall AddRef() { return ++refCount; }
  184162. ULONG __stdcall Release() { jassert (refCount > 0); const int r = --refCount; if (r == 0) delete this; return r; }
  184163. HRESULT __stdcall QueryContinueDrag (BOOL escapePressed, DWORD keys)
  184164. {
  184165. if (escapePressed)
  184166. return DRAGDROP_S_CANCEL;
  184167. if ((keys & (MK_LBUTTON | MK_RBUTTON)) == 0)
  184168. return DRAGDROP_S_DROP;
  184169. return S_OK;
  184170. }
  184171. HRESULT __stdcall GiveFeedback (DWORD)
  184172. {
  184173. return DRAGDROP_S_USEDEFAULTCURSORS;
  184174. }
  184175. };
  184176. class JuceEnumFormatEtc : public IEnumFORMATETC
  184177. {
  184178. public:
  184179. JuceEnumFormatEtc (const FORMATETC* const format_)
  184180. : refCount (1),
  184181. format (format_),
  184182. index (0)
  184183. {
  184184. }
  184185. virtual ~JuceEnumFormatEtc()
  184186. {
  184187. jassert (refCount == 0);
  184188. }
  184189. HRESULT __stdcall QueryInterface (REFIID id, void __RPC_FAR* __RPC_FAR* result)
  184190. {
  184191. if (id == IID_IUnknown || id == IID_IEnumFORMATETC)
  184192. {
  184193. AddRef();
  184194. *result = this;
  184195. return S_OK;
  184196. }
  184197. *result = 0;
  184198. return E_NOINTERFACE;
  184199. }
  184200. ULONG __stdcall AddRef() { return ++refCount; }
  184201. ULONG __stdcall Release() { jassert (refCount > 0); const int r = --refCount; if (r == 0) delete this; return r; }
  184202. HRESULT __stdcall Clone (IEnumFORMATETC** result)
  184203. {
  184204. if (result == 0)
  184205. return E_POINTER;
  184206. JuceEnumFormatEtc* const newOne = new JuceEnumFormatEtc (format);
  184207. newOne->index = index;
  184208. *result = newOne;
  184209. return S_OK;
  184210. }
  184211. HRESULT __stdcall Next (ULONG celt, LPFORMATETC lpFormatEtc, ULONG* pceltFetched)
  184212. {
  184213. if (pceltFetched != 0)
  184214. *pceltFetched = 0;
  184215. else if (celt != 1)
  184216. return S_FALSE;
  184217. if (index == 0 && celt > 0 && lpFormatEtc != 0)
  184218. {
  184219. copyFormatEtc (lpFormatEtc [0], *format);
  184220. ++index;
  184221. if (pceltFetched != 0)
  184222. *pceltFetched = 1;
  184223. return S_OK;
  184224. }
  184225. return S_FALSE;
  184226. }
  184227. HRESULT __stdcall Skip (ULONG celt)
  184228. {
  184229. if (index + (int) celt >= 1)
  184230. return S_FALSE;
  184231. index += celt;
  184232. return S_OK;
  184233. }
  184234. HRESULT __stdcall Reset()
  184235. {
  184236. index = 0;
  184237. return S_OK;
  184238. }
  184239. private:
  184240. int refCount;
  184241. const FORMATETC* const format;
  184242. int index;
  184243. static void copyFormatEtc (FORMATETC& dest, const FORMATETC& source)
  184244. {
  184245. dest = source;
  184246. if (source.ptd != 0)
  184247. {
  184248. dest.ptd = (DVTARGETDEVICE*) CoTaskMemAlloc (sizeof (DVTARGETDEVICE));
  184249. *(dest.ptd) = *(source.ptd);
  184250. }
  184251. }
  184252. JuceEnumFormatEtc (const JuceEnumFormatEtc&);
  184253. const JuceEnumFormatEtc& operator= (const JuceEnumFormatEtc&);
  184254. };
  184255. class JuceDataObject : public IDataObject
  184256. {
  184257. JuceDropSource* const dropSource;
  184258. const FORMATETC* const format;
  184259. const STGMEDIUM* const medium;
  184260. int refCount;
  184261. JuceDataObject (const JuceDataObject&);
  184262. const JuceDataObject& operator= (const JuceDataObject&);
  184263. public:
  184264. JuceDataObject (JuceDropSource* const dropSource_,
  184265. const FORMATETC* const format_,
  184266. const STGMEDIUM* const medium_)
  184267. : dropSource (dropSource_),
  184268. format (format_),
  184269. medium (medium_),
  184270. refCount (1)
  184271. {
  184272. }
  184273. virtual ~JuceDataObject()
  184274. {
  184275. jassert (refCount == 0);
  184276. }
  184277. HRESULT __stdcall QueryInterface (REFIID id, void __RPC_FAR* __RPC_FAR* result)
  184278. {
  184279. if (id == IID_IUnknown || id == IID_IDataObject)
  184280. {
  184281. AddRef();
  184282. *result = this;
  184283. return S_OK;
  184284. }
  184285. *result = 0;
  184286. return E_NOINTERFACE;
  184287. }
  184288. ULONG __stdcall AddRef() { return ++refCount; }
  184289. ULONG __stdcall Release() { jassert (refCount > 0); const int r = --refCount; if (r == 0) delete this; return r; }
  184290. HRESULT __stdcall GetData (FORMATETC __RPC_FAR* pFormatEtc, STGMEDIUM __RPC_FAR* pMedium)
  184291. {
  184292. if (pFormatEtc->tymed == format->tymed
  184293. && pFormatEtc->cfFormat == format->cfFormat
  184294. && pFormatEtc->dwAspect == format->dwAspect)
  184295. {
  184296. pMedium->tymed = format->tymed;
  184297. pMedium->pUnkForRelease = 0;
  184298. if (format->tymed == TYMED_HGLOBAL)
  184299. {
  184300. const SIZE_T len = GlobalSize (medium->hGlobal);
  184301. void* const src = GlobalLock (medium->hGlobal);
  184302. void* const dst = GlobalAlloc (GMEM_FIXED, len);
  184303. memcpy (dst, src, len);
  184304. GlobalUnlock (medium->hGlobal);
  184305. pMedium->hGlobal = dst;
  184306. return S_OK;
  184307. }
  184308. }
  184309. return DV_E_FORMATETC;
  184310. }
  184311. HRESULT __stdcall QueryGetData (FORMATETC __RPC_FAR* f)
  184312. {
  184313. if (f == 0)
  184314. return E_INVALIDARG;
  184315. if (f->tymed == format->tymed
  184316. && f->cfFormat == format->cfFormat
  184317. && f->dwAspect == format->dwAspect)
  184318. return S_OK;
  184319. return DV_E_FORMATETC;
  184320. }
  184321. HRESULT __stdcall GetCanonicalFormatEtc (FORMATETC __RPC_FAR*, FORMATETC __RPC_FAR* pFormatEtcOut)
  184322. {
  184323. pFormatEtcOut->ptd = 0;
  184324. return E_NOTIMPL;
  184325. }
  184326. HRESULT __stdcall EnumFormatEtc (DWORD direction, IEnumFORMATETC __RPC_FAR *__RPC_FAR *result)
  184327. {
  184328. if (result == 0)
  184329. return E_POINTER;
  184330. if (direction == DATADIR_GET)
  184331. {
  184332. *result = new JuceEnumFormatEtc (format);
  184333. return S_OK;
  184334. }
  184335. *result = 0;
  184336. return E_NOTIMPL;
  184337. }
  184338. HRESULT __stdcall GetDataHere (FORMATETC __RPC_FAR*, STGMEDIUM __RPC_FAR*) { return DATA_E_FORMATETC; }
  184339. HRESULT __stdcall SetData (FORMATETC __RPC_FAR*, STGMEDIUM __RPC_FAR*, BOOL) { return E_NOTIMPL; }
  184340. HRESULT __stdcall DAdvise (FORMATETC __RPC_FAR*, DWORD, IAdviseSink __RPC_FAR*, DWORD __RPC_FAR*) { return OLE_E_ADVISENOTSUPPORTED; }
  184341. HRESULT __stdcall DUnadvise (DWORD) { return E_NOTIMPL; }
  184342. HRESULT __stdcall EnumDAdvise (IEnumSTATDATA __RPC_FAR *__RPC_FAR *) { return OLE_E_ADVISENOTSUPPORTED; }
  184343. };
  184344. static HDROP createHDrop (const StringArray& fileNames) throw()
  184345. {
  184346. int totalChars = 0;
  184347. for (int i = fileNames.size(); --i >= 0;)
  184348. totalChars += fileNames[i].length() + 1;
  184349. HDROP hDrop = (HDROP) GlobalAlloc (GMEM_MOVEABLE | GMEM_ZEROINIT,
  184350. sizeof (DROPFILES)
  184351. + sizeof (WCHAR) * (totalChars + 2));
  184352. if (hDrop != 0)
  184353. {
  184354. LPDROPFILES pDropFiles = (LPDROPFILES) GlobalLock (hDrop);
  184355. pDropFiles->pFiles = sizeof (DROPFILES);
  184356. pDropFiles->fWide = true;
  184357. WCHAR* fname = (WCHAR*) (((char*) pDropFiles) + sizeof (DROPFILES));
  184358. for (int i = 0; i < fileNames.size(); ++i)
  184359. {
  184360. fileNames[i].copyToBuffer (fname, 2048);
  184361. fname += fileNames[i].length() + 1;
  184362. }
  184363. *fname = 0;
  184364. GlobalUnlock (hDrop);
  184365. }
  184366. return hDrop;
  184367. }
  184368. static bool performDragDrop (FORMATETC* const format, STGMEDIUM* const medium, const DWORD whatToDo) throw()
  184369. {
  184370. JuceDropSource* const source = new JuceDropSource();
  184371. JuceDataObject* const data = new JuceDataObject (source, format, medium);
  184372. DWORD effect;
  184373. const HRESULT res = DoDragDrop (data, source, whatToDo, &effect);
  184374. data->Release();
  184375. source->Release();
  184376. return res == DRAGDROP_S_DROP;
  184377. }
  184378. bool DragAndDropContainer::performExternalDragDropOfFiles (const StringArray& files, const bool canMove)
  184379. {
  184380. FORMATETC format = { CF_HDROP, 0, DVASPECT_CONTENT, -1, TYMED_HGLOBAL };
  184381. STGMEDIUM medium = { TYMED_HGLOBAL, { 0 }, 0 };
  184382. medium.hGlobal = createHDrop (files);
  184383. return performDragDrop (&format, &medium, canMove ? (DROPEFFECT_COPY | DROPEFFECT_MOVE)
  184384. : DROPEFFECT_COPY);
  184385. }
  184386. bool DragAndDropContainer::performExternalDragDropOfText (const String& text)
  184387. {
  184388. FORMATETC format = { CF_TEXT, 0, DVASPECT_CONTENT, -1, TYMED_HGLOBAL };
  184389. STGMEDIUM medium = { TYMED_HGLOBAL, { 0 }, 0 };
  184390. const int numChars = text.length();
  184391. medium.hGlobal = GlobalAlloc (GMEM_MOVEABLE | GMEM_ZEROINIT, (numChars + 2) * sizeof (WCHAR));
  184392. char* d = (char*) GlobalLock (medium.hGlobal);
  184393. text.copyToBuffer ((WCHAR*) d, numChars + 1);
  184394. format.cfFormat = CF_UNICODETEXT;
  184395. GlobalUnlock (medium.hGlobal);
  184396. return performDragDrop (&format, &medium, DROPEFFECT_COPY | DROPEFFECT_MOVE);
  184397. }
  184398. #endif
  184399. /********* End of inlined file: juce_win32_Windowing.cpp *********/
  184400. /********* Start of inlined file: juce_win32_Fonts.cpp *********/
  184401. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  184402. // compiled on its own).
  184403. #if JUCE_INCLUDED_FILE
  184404. static int CALLBACK wfontEnum2 (ENUMLOGFONTEXW* lpelfe,
  184405. NEWTEXTMETRICEXW*,
  184406. int type,
  184407. LPARAM lParam)
  184408. {
  184409. if (lpelfe != 0 && (type & RASTER_FONTTYPE) == 0)
  184410. {
  184411. const String fontName (lpelfe->elfLogFont.lfFaceName);
  184412. ((StringArray*) lParam)->addIfNotAlreadyThere (fontName.removeCharacters (T("@")));
  184413. }
  184414. return 1;
  184415. }
  184416. static int CALLBACK wfontEnum1 (ENUMLOGFONTEXW* lpelfe,
  184417. NEWTEXTMETRICEXW*,
  184418. int type,
  184419. LPARAM lParam)
  184420. {
  184421. if (lpelfe != 0 && (type & RASTER_FONTTYPE) == 0)
  184422. {
  184423. LOGFONTW lf;
  184424. zerostruct (lf);
  184425. lf.lfWeight = FW_DONTCARE;
  184426. lf.lfOutPrecision = OUT_OUTLINE_PRECIS;
  184427. lf.lfQuality = DEFAULT_QUALITY;
  184428. lf.lfCharSet = DEFAULT_CHARSET;
  184429. lf.lfClipPrecision = CLIP_DEFAULT_PRECIS;
  184430. lf.lfPitchAndFamily = FF_DONTCARE;
  184431. const String fontName (lpelfe->elfLogFont.lfFaceName);
  184432. fontName.copyToBuffer (lf.lfFaceName, LF_FACESIZE - 1);
  184433. HDC dc = CreateCompatibleDC (0);
  184434. EnumFontFamiliesEx (dc, &lf,
  184435. (FONTENUMPROCW) &wfontEnum2,
  184436. lParam, 0);
  184437. DeleteDC (dc);
  184438. }
  184439. return 1;
  184440. }
  184441. const StringArray Font::findAllTypefaceNames() throw()
  184442. {
  184443. StringArray results;
  184444. HDC dc = CreateCompatibleDC (0);
  184445. {
  184446. LOGFONTW lf;
  184447. zerostruct (lf);
  184448. lf.lfWeight = FW_DONTCARE;
  184449. lf.lfOutPrecision = OUT_OUTLINE_PRECIS;
  184450. lf.lfQuality = DEFAULT_QUALITY;
  184451. lf.lfCharSet = DEFAULT_CHARSET;
  184452. lf.lfClipPrecision = CLIP_DEFAULT_PRECIS;
  184453. lf.lfPitchAndFamily = FF_DONTCARE;
  184454. lf.lfFaceName[0] = 0;
  184455. EnumFontFamiliesEx (dc, &lf,
  184456. (FONTENUMPROCW) &wfontEnum1,
  184457. (LPARAM) &results, 0);
  184458. }
  184459. DeleteDC (dc);
  184460. results.sort (true);
  184461. return results;
  184462. }
  184463. extern bool juce_IsRunningInWine();
  184464. void Font::getPlatformDefaultFontNames (String& defaultSans, String& defaultSerif, String& defaultFixed) throw()
  184465. {
  184466. if (juce_IsRunningInWine())
  184467. {
  184468. // If we're running in Wine, then use fonts that might be available on Linux..
  184469. defaultSans = "Bitstream Vera Sans";
  184470. defaultSerif = "Bitstream Vera Serif";
  184471. defaultFixed = "Bitstream Vera Sans Mono";
  184472. }
  184473. else
  184474. {
  184475. defaultSans = "Verdana";
  184476. defaultSerif = "Times";
  184477. defaultFixed = "Lucida Console";
  184478. }
  184479. }
  184480. class FontDCHolder : private DeletedAtShutdown
  184481. {
  184482. public:
  184483. FontDCHolder() throw()
  184484. : dc (0), numKPs (0), size (0),
  184485. bold (false), italic (false)
  184486. {
  184487. }
  184488. ~FontDCHolder() throw()
  184489. {
  184490. if (dc != 0)
  184491. {
  184492. DeleteDC (dc);
  184493. DeleteObject (fontH);
  184494. }
  184495. clearSingletonInstance();
  184496. }
  184497. juce_DeclareSingleton_SingleThreaded_Minimal (FontDCHolder);
  184498. HDC loadFont (const String& fontName_, const bool bold_, const bool italic_, const int size_) throw()
  184499. {
  184500. if (fontName != fontName_ || bold != bold_ || italic != italic_ || size != size_)
  184501. {
  184502. fontName = fontName_;
  184503. bold = bold_;
  184504. italic = italic_;
  184505. size = size_;
  184506. if (dc != 0)
  184507. {
  184508. DeleteDC (dc);
  184509. DeleteObject (fontH);
  184510. kps.free();
  184511. }
  184512. fontH = 0;
  184513. dc = CreateCompatibleDC (0);
  184514. SetMapperFlags (dc, 0);
  184515. SetMapMode (dc, MM_TEXT);
  184516. LOGFONTW lfw;
  184517. zerostruct (lfw);
  184518. lfw.lfCharSet = DEFAULT_CHARSET;
  184519. lfw.lfClipPrecision = CLIP_DEFAULT_PRECIS;
  184520. lfw.lfOutPrecision = OUT_OUTLINE_PRECIS;
  184521. lfw.lfPitchAndFamily = DEFAULT_PITCH | FF_DONTCARE;
  184522. lfw.lfQuality = PROOF_QUALITY;
  184523. lfw.lfItalic = (BYTE) (italic ? TRUE : FALSE);
  184524. lfw.lfWeight = bold ? FW_BOLD : FW_NORMAL;
  184525. fontName.copyToBuffer (lfw.lfFaceName, LF_FACESIZE - 1);
  184526. lfw.lfHeight = size > 0 ? size : -256;
  184527. HFONT standardSizedFont = CreateFontIndirect (&lfw);
  184528. if (standardSizedFont != 0)
  184529. {
  184530. if (SelectObject (dc, standardSizedFont) != 0)
  184531. {
  184532. fontH = standardSizedFont;
  184533. if (size == 0)
  184534. {
  184535. OUTLINETEXTMETRIC otm;
  184536. if (GetOutlineTextMetrics (dc, sizeof (otm), &otm) != 0)
  184537. {
  184538. lfw.lfHeight = -(int) otm.otmEMSquare;
  184539. fontH = CreateFontIndirect (&lfw);
  184540. SelectObject (dc, fontH);
  184541. DeleteObject (standardSizedFont);
  184542. }
  184543. }
  184544. }
  184545. else
  184546. {
  184547. jassertfalse
  184548. }
  184549. }
  184550. else
  184551. {
  184552. jassertfalse
  184553. }
  184554. }
  184555. return dc;
  184556. }
  184557. KERNINGPAIR* getKerningPairs (int& numKPs_) throw()
  184558. {
  184559. if (kps == 0)
  184560. {
  184561. numKPs = GetKerningPairs (dc, 0, 0);
  184562. kps.calloc (numKPs);
  184563. GetKerningPairs (dc, numKPs, kps);
  184564. }
  184565. numKPs_ = numKPs;
  184566. return kps;
  184567. }
  184568. private:
  184569. HFONT fontH;
  184570. HDC dc;
  184571. String fontName;
  184572. HeapBlock <KERNINGPAIR> kps;
  184573. int numKPs, size;
  184574. bool bold, italic;
  184575. FontDCHolder (const FontDCHolder&);
  184576. const FontDCHolder& operator= (const FontDCHolder&);
  184577. };
  184578. juce_ImplementSingleton_SingleThreaded (FontDCHolder);
  184579. class WindowsTypeface : public CustomTypeface
  184580. {
  184581. public:
  184582. WindowsTypeface (const Font& font)
  184583. {
  184584. HDC dc = FontDCHolder::getInstance()->loadFont (font.getTypefaceName(),
  184585. font.isBold(), font.isItalic(), 0);
  184586. TEXTMETRIC tm;
  184587. tm.tmAscent = tm.tmHeight = 1;
  184588. tm.tmDefaultChar = 0;
  184589. GetTextMetrics (dc, &tm);
  184590. setCharacteristics (font.getTypefaceName(),
  184591. tm.tmAscent / (float) tm.tmHeight,
  184592. font.isBold(), font.isItalic(),
  184593. tm.tmDefaultChar);
  184594. }
  184595. bool loadGlyphIfPossible (const juce_wchar character)
  184596. {
  184597. HDC dc = FontDCHolder::getInstance()->loadFont (name, isBold, isItalic, 0);
  184598. GLYPHMETRICS gm;
  184599. {
  184600. const WCHAR charToTest[] = { (WCHAR) character, 0 };
  184601. WORD index = 0;
  184602. if (GetGlyphIndices (dc, charToTest, 1, &index, GGI_MARK_NONEXISTING_GLYPHS) != GDI_ERROR
  184603. && index == 0xffff)
  184604. {
  184605. return false;
  184606. }
  184607. }
  184608. Path glyphPath;
  184609. TEXTMETRIC tm;
  184610. if (! GetTextMetrics (dc, &tm))
  184611. {
  184612. addGlyph (character, glyphPath, 0);
  184613. return true;
  184614. }
  184615. const float height = (float) tm.tmHeight;
  184616. static const MAT2 identityMatrix = { { 0, 1 }, { 0, 0 }, { 0, 0 }, { 0, 1 } };
  184617. const int bufSize = GetGlyphOutline (dc, character, GGO_NATIVE,
  184618. &gm, 0, 0, &identityMatrix);
  184619. if (bufSize > 0)
  184620. {
  184621. HeapBlock <char> data (bufSize);
  184622. GetGlyphOutline (dc, character, GGO_NATIVE, &gm,
  184623. bufSize, data, &identityMatrix);
  184624. const TTPOLYGONHEADER* pheader = (TTPOLYGONHEADER*) data;
  184625. const float scaleX = 1.0f / height;
  184626. const float scaleY = -1.0f / height;
  184627. while ((char*) pheader < data + bufSize)
  184628. {
  184629. #define remapX(v) (scaleX * (v).x.value)
  184630. #define remapY(v) (scaleY * (v).y.value)
  184631. float x = remapX (pheader->pfxStart);
  184632. float y = remapY (pheader->pfxStart);
  184633. glyphPath.startNewSubPath (x, y);
  184634. const TTPOLYCURVE* curve = (const TTPOLYCURVE*) ((const char*) pheader + sizeof (TTPOLYGONHEADER));
  184635. const char* const curveEnd = ((const char*) pheader) + pheader->cb;
  184636. while ((const char*) curve < curveEnd)
  184637. {
  184638. if (curve->wType == TT_PRIM_LINE)
  184639. {
  184640. for (int i = 0; i < curve->cpfx; ++i)
  184641. {
  184642. x = remapX (curve->apfx [i]);
  184643. y = remapY (curve->apfx [i]);
  184644. glyphPath.lineTo (x, y);
  184645. }
  184646. }
  184647. else if (curve->wType == TT_PRIM_QSPLINE)
  184648. {
  184649. for (int i = 0; i < curve->cpfx - 1; ++i)
  184650. {
  184651. const float x2 = remapX (curve->apfx [i]);
  184652. const float y2 = remapY (curve->apfx [i]);
  184653. float x3, y3;
  184654. if (i < curve->cpfx - 2)
  184655. {
  184656. x3 = 0.5f * (x2 + remapX (curve->apfx [i + 1]));
  184657. y3 = 0.5f * (y2 + remapY (curve->apfx [i + 1]));
  184658. }
  184659. else
  184660. {
  184661. x3 = remapX (curve->apfx [i + 1]);
  184662. y3 = remapY (curve->apfx [i + 1]);
  184663. }
  184664. glyphPath.quadraticTo (x2, y2, x3, y3);
  184665. x = x3;
  184666. y = y3;
  184667. }
  184668. }
  184669. curve = (const TTPOLYCURVE*) &(curve->apfx [curve->cpfx]);
  184670. }
  184671. pheader = (const TTPOLYGONHEADER*) curve;
  184672. glyphPath.closeSubPath();
  184673. }
  184674. }
  184675. addGlyph (character, glyphPath, gm.gmCellIncX / height);
  184676. int numKPs;
  184677. const KERNINGPAIR* const kps = FontDCHolder::getInstance()->getKerningPairs (numKPs);
  184678. for (int i = 0; i < numKPs; ++i)
  184679. {
  184680. if (kps[i].wFirst == character)
  184681. addKerningPair (kps[i].wFirst, kps[i].wSecond,
  184682. kps[i].iKernAmount / height);
  184683. }
  184684. return true;
  184685. }
  184686. };
  184687. const Typeface::Ptr Typeface::createSystemTypefaceFor (const Font& font)
  184688. {
  184689. return new WindowsTypeface (font);
  184690. }
  184691. #endif
  184692. /********* End of inlined file: juce_win32_Fonts.cpp *********/
  184693. /********* Start of inlined file: juce_win32_FileChooser.cpp *********/
  184694. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  184695. // compiled on its own).
  184696. #if JUCE_INCLUDED_FILE
  184697. static const void* defaultDirPath = 0;
  184698. static String returnedString; // need this to get non-existent pathnames from the directory chooser
  184699. static Component* currentExtraFileWin = 0;
  184700. static bool areThereAnyAlwaysOnTopWindows()
  184701. {
  184702. for (int i = Desktop::getInstance().getNumComponents(); --i >= 0;)
  184703. {
  184704. Component* c = Desktop::getInstance().getComponent (i);
  184705. if (c != 0 && c->isAlwaysOnTop() && c->isShowing())
  184706. return true;
  184707. }
  184708. return false;
  184709. }
  184710. static int CALLBACK browseCallbackProc (HWND hWnd, UINT msg, LPARAM lParam, LPARAM /*lpData*/)
  184711. {
  184712. if (msg == BFFM_INITIALIZED)
  184713. {
  184714. SendMessage (hWnd, BFFM_SETSELECTIONW, TRUE, (LPARAM) defaultDirPath);
  184715. }
  184716. else if (msg == BFFM_VALIDATEFAILEDW)
  184717. {
  184718. returnedString = (LPCWSTR) lParam;
  184719. }
  184720. else if (msg == BFFM_VALIDATEFAILEDA)
  184721. {
  184722. returnedString = (const char*) lParam;
  184723. }
  184724. return 0;
  184725. }
  184726. void juce_setWindowStyleBit (HWND h, const int styleType, const int feature, const bool bitIsSet) throw();
  184727. static UINT_PTR CALLBACK openCallback (HWND hdlg, UINT uiMsg, WPARAM /*wParam*/, LPARAM lParam)
  184728. {
  184729. if (currentExtraFileWin != 0)
  184730. {
  184731. if (uiMsg == WM_INITDIALOG)
  184732. {
  184733. HWND dialogH = GetParent (hdlg);
  184734. jassert (dialogH != 0);
  184735. if (dialogH == 0)
  184736. dialogH = hdlg;
  184737. RECT r, cr;
  184738. GetWindowRect (dialogH, &r);
  184739. GetClientRect (dialogH, &cr);
  184740. SetWindowPos (dialogH, 0,
  184741. r.left, r.top,
  184742. currentExtraFileWin->getWidth() + jmax (150, (int) (r.right - r.left)),
  184743. jmax (150, (int) (r.bottom - r.top)),
  184744. SWP_NOACTIVATE | SWP_NOOWNERZORDER | SWP_NOZORDER);
  184745. currentExtraFileWin->setBounds (cr.right, cr.top, currentExtraFileWin->getWidth(), cr.bottom - cr.top);
  184746. currentExtraFileWin->getChildComponent(0)->setBounds (0, 0, currentExtraFileWin->getWidth(), currentExtraFileWin->getHeight());
  184747. SetParent ((HWND) currentExtraFileWin->getWindowHandle(), (HWND) dialogH);
  184748. juce_setWindowStyleBit ((HWND)currentExtraFileWin->getWindowHandle(), GWL_STYLE, WS_CHILD, (dialogH != 0));
  184749. juce_setWindowStyleBit ((HWND)currentExtraFileWin->getWindowHandle(), GWL_STYLE, WS_POPUP, (dialogH == 0));
  184750. }
  184751. else if (uiMsg == WM_NOTIFY)
  184752. {
  184753. LPOFNOTIFY ofn = (LPOFNOTIFY) lParam;
  184754. if (ofn->hdr.code == CDN_SELCHANGE)
  184755. {
  184756. FilePreviewComponent* comp = (FilePreviewComponent*) currentExtraFileWin->getChildComponent(0);
  184757. if (comp != 0)
  184758. {
  184759. TCHAR path [MAX_PATH * 2];
  184760. path[0] = 0;
  184761. CommDlg_OpenSave_GetFilePath (GetParent (hdlg), (LPARAM) &path, MAX_PATH);
  184762. const String fn ((const WCHAR*) path);
  184763. comp->selectedFileChanged (File (fn));
  184764. }
  184765. }
  184766. }
  184767. }
  184768. return 0;
  184769. }
  184770. class FPComponentHolder : public Component
  184771. {
  184772. public:
  184773. FPComponentHolder()
  184774. {
  184775. setVisible (true);
  184776. setOpaque (true);
  184777. }
  184778. ~FPComponentHolder()
  184779. {
  184780. }
  184781. void paint (Graphics& g)
  184782. {
  184783. g.fillAll (Colours::lightgrey);
  184784. }
  184785. private:
  184786. FPComponentHolder (const FPComponentHolder&);
  184787. const FPComponentHolder& operator= (const FPComponentHolder&);
  184788. };
  184789. void FileChooser::showPlatformDialog (Array<File>& results,
  184790. const String& title,
  184791. const File& currentFileOrDirectory,
  184792. const String& filter,
  184793. bool selectsDirectory,
  184794. bool /*selectsFiles*/,
  184795. bool isSaveDialogue,
  184796. bool warnAboutOverwritingExistingFiles,
  184797. bool selectMultipleFiles,
  184798. FilePreviewComponent* extraInfoComponent)
  184799. {
  184800. const int numCharsAvailable = 32768;
  184801. MemoryBlock filenameSpace ((numCharsAvailable + 1) * sizeof (WCHAR), true);
  184802. WCHAR* const fname = (WCHAR*) filenameSpace.getData();
  184803. int fnameIdx = 0;
  184804. JUCE_TRY
  184805. {
  184806. // use a modal window as the parent for this dialog box
  184807. // to block input from other app windows
  184808. const Rectangle mainMon (Desktop::getInstance().getMainMonitorArea());
  184809. Component w (String::empty);
  184810. w.setBounds (mainMon.getX() + mainMon.getWidth() / 4,
  184811. mainMon.getY() + mainMon.getHeight() / 4,
  184812. 0, 0);
  184813. w.setOpaque (true);
  184814. w.setAlwaysOnTop (areThereAnyAlwaysOnTopWindows());
  184815. w.addToDesktop (0);
  184816. if (extraInfoComponent == 0)
  184817. w.enterModalState();
  184818. String initialDir;
  184819. if (currentFileOrDirectory.isDirectory())
  184820. {
  184821. initialDir = currentFileOrDirectory.getFullPathName();
  184822. }
  184823. else
  184824. {
  184825. currentFileOrDirectory.getFileName().copyToBuffer (fname, numCharsAvailable);
  184826. initialDir = currentFileOrDirectory.getParentDirectory().getFullPathName();
  184827. }
  184828. if (currentExtraFileWin->isValidComponent())
  184829. {
  184830. jassertfalse
  184831. return;
  184832. }
  184833. if (selectsDirectory)
  184834. {
  184835. LPITEMIDLIST list = 0;
  184836. filenameSpace.fillWith (0);
  184837. {
  184838. BROWSEINFO bi;
  184839. zerostruct (bi);
  184840. bi.hwndOwner = (HWND) w.getWindowHandle();
  184841. bi.pszDisplayName = fname;
  184842. bi.lpszTitle = title;
  184843. bi.lpfn = browseCallbackProc;
  184844. #ifdef BIF_USENEWUI
  184845. bi.ulFlags = BIF_USENEWUI | BIF_VALIDATE;
  184846. #else
  184847. bi.ulFlags = 0x50;
  184848. #endif
  184849. defaultDirPath = (const WCHAR*) initialDir;
  184850. list = SHBrowseForFolder (&bi);
  184851. if (! SHGetPathFromIDListW (list, fname))
  184852. {
  184853. fname[0] = 0;
  184854. returnedString = String::empty;
  184855. }
  184856. }
  184857. LPMALLOC al;
  184858. if (list != 0 && SUCCEEDED (SHGetMalloc (&al)))
  184859. al->Free (list);
  184860. defaultDirPath = 0;
  184861. if (returnedString.isNotEmpty())
  184862. {
  184863. const String stringFName (fname);
  184864. results.add (File (stringFName).getSiblingFile (returnedString));
  184865. returnedString = String::empty;
  184866. return;
  184867. }
  184868. }
  184869. else
  184870. {
  184871. DWORD flags = OFN_EXPLORER | OFN_PATHMUSTEXIST | OFN_NOCHANGEDIR | OFN_HIDEREADONLY;
  184872. if (warnAboutOverwritingExistingFiles)
  184873. flags |= OFN_OVERWRITEPROMPT;
  184874. if (selectMultipleFiles)
  184875. flags |= OFN_ALLOWMULTISELECT;
  184876. if (extraInfoComponent != 0)
  184877. {
  184878. flags |= OFN_ENABLEHOOK;
  184879. currentExtraFileWin = new FPComponentHolder();
  184880. currentExtraFileWin->addAndMakeVisible (extraInfoComponent);
  184881. currentExtraFileWin->setSize (jlimit (20, 800, extraInfoComponent->getWidth()),
  184882. extraInfoComponent->getHeight());
  184883. currentExtraFileWin->addToDesktop (0);
  184884. currentExtraFileWin->enterModalState();
  184885. }
  184886. {
  184887. WCHAR filters [1024];
  184888. zeromem (filters, sizeof (filters));
  184889. filter.copyToBuffer (filters, 1024);
  184890. filter.copyToBuffer (filters + filter.length() + 1,
  184891. 1022 - filter.length());
  184892. OPENFILENAMEW of;
  184893. zerostruct (of);
  184894. #ifdef OPENFILENAME_SIZE_VERSION_400W
  184895. of.lStructSize = OPENFILENAME_SIZE_VERSION_400W;
  184896. #else
  184897. of.lStructSize = sizeof (of);
  184898. #endif
  184899. of.hwndOwner = (HWND) w.getWindowHandle();
  184900. of.lpstrFilter = filters;
  184901. of.nFilterIndex = 1;
  184902. of.lpstrFile = fname;
  184903. of.nMaxFile = numCharsAvailable;
  184904. of.lpstrInitialDir = initialDir;
  184905. of.lpstrTitle = title;
  184906. of.Flags = flags;
  184907. if (extraInfoComponent != 0)
  184908. of.lpfnHook = &openCallback;
  184909. if (isSaveDialogue)
  184910. {
  184911. if (! GetSaveFileName (&of))
  184912. fname[0] = 0;
  184913. else
  184914. fnameIdx = of.nFileOffset;
  184915. }
  184916. else
  184917. {
  184918. if (! GetOpenFileName (&of))
  184919. fname[0] = 0;
  184920. else
  184921. fnameIdx = of.nFileOffset;
  184922. }
  184923. }
  184924. }
  184925. }
  184926. #if JUCE_CATCH_UNHANDLED_EXCEPTIONS
  184927. catch (...)
  184928. {
  184929. fname[0] = 0;
  184930. }
  184931. #endif
  184932. deleteAndZero (currentExtraFileWin);
  184933. const WCHAR* const files = fname;
  184934. if (selectMultipleFiles && fnameIdx > 0 && files [fnameIdx - 1] == 0)
  184935. {
  184936. const WCHAR* filename = files + fnameIdx;
  184937. while (*filename != 0)
  184938. {
  184939. const String filepath (String (files) + T("\\") + String (filename));
  184940. results.add (File (filepath));
  184941. filename += CharacterFunctions::length (filename) + 1;
  184942. }
  184943. }
  184944. else if (files[0] != 0)
  184945. {
  184946. results.add (File (files));
  184947. }
  184948. }
  184949. #endif
  184950. /********* End of inlined file: juce_win32_FileChooser.cpp *********/
  184951. /********* Start of inlined file: juce_win32_Misc.cpp *********/
  184952. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  184953. // compiled on its own).
  184954. #if JUCE_INCLUDED_FILE
  184955. void SystemClipboard::copyTextToClipboard (const String& text) throw()
  184956. {
  184957. if (OpenClipboard (0) != 0)
  184958. {
  184959. if (EmptyClipboard() != 0)
  184960. {
  184961. const int len = text.length();
  184962. if (len > 0)
  184963. {
  184964. HGLOBAL bufH = GlobalAlloc (GMEM_MOVEABLE | GMEM_DDESHARE,
  184965. (len + 1) * sizeof (wchar_t));
  184966. if (bufH != 0)
  184967. {
  184968. wchar_t* const data = (wchar_t*) GlobalLock (bufH);
  184969. text.copyToBuffer (data, len);
  184970. GlobalUnlock (bufH);
  184971. SetClipboardData (CF_UNICODETEXT, bufH);
  184972. }
  184973. }
  184974. }
  184975. CloseClipboard();
  184976. }
  184977. }
  184978. const String SystemClipboard::getTextFromClipboard() throw()
  184979. {
  184980. String result;
  184981. if (OpenClipboard (0) != 0)
  184982. {
  184983. HANDLE bufH = GetClipboardData (CF_UNICODETEXT);
  184984. if (bufH != 0)
  184985. {
  184986. const wchar_t* const data = (const wchar_t*) GlobalLock (bufH);
  184987. if (data != 0)
  184988. {
  184989. result = String (data, (int) (GlobalSize (bufH) / sizeof (tchar)));
  184990. GlobalUnlock (bufH);
  184991. }
  184992. }
  184993. CloseClipboard();
  184994. }
  184995. return result;
  184996. }
  184997. #endif
  184998. /********* End of inlined file: juce_win32_Misc.cpp *********/
  184999. /********* Start of inlined file: juce_win32_ActiveXComponent.cpp *********/
  185000. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  185001. // compiled on its own).
  185002. #if JUCE_INCLUDED_FILE
  185003. class JuceIStorage : public IStorage
  185004. {
  185005. int refCount;
  185006. public:
  185007. JuceIStorage() : refCount (1) {}
  185008. virtual ~JuceIStorage()
  185009. {
  185010. jassert (refCount == 0);
  185011. }
  185012. HRESULT __stdcall QueryInterface (REFIID id, void __RPC_FAR* __RPC_FAR* result)
  185013. {
  185014. if (id == IID_IUnknown || id == IID_IStorage)
  185015. {
  185016. AddRef();
  185017. *result = this;
  185018. return S_OK;
  185019. }
  185020. *result = 0;
  185021. return E_NOINTERFACE;
  185022. }
  185023. ULONG __stdcall AddRef() { return ++refCount; }
  185024. ULONG __stdcall Release() { const int r = --refCount; if (r == 0) delete this; return r; }
  185025. HRESULT __stdcall CreateStream (const WCHAR*, DWORD, DWORD, DWORD, IStream**) { return E_NOTIMPL; }
  185026. HRESULT __stdcall OpenStream (const WCHAR*, void*, DWORD, DWORD, IStream**) { return E_NOTIMPL; }
  185027. HRESULT __stdcall CreateStorage (const WCHAR*, DWORD, DWORD, DWORD, IStorage**) { return E_NOTIMPL; }
  185028. HRESULT __stdcall OpenStorage (const WCHAR*, IStorage*, DWORD, SNB, DWORD, IStorage**) { return E_NOTIMPL; }
  185029. HRESULT __stdcall CopyTo (DWORD, IID const*, SNB, IStorage*) { return E_NOTIMPL; }
  185030. HRESULT __stdcall MoveElementTo (const OLECHAR*,IStorage*, const OLECHAR*, DWORD) { return E_NOTIMPL; }
  185031. HRESULT __stdcall Commit (DWORD) { return E_NOTIMPL; }
  185032. HRESULT __stdcall Revert() { return E_NOTIMPL; }
  185033. HRESULT __stdcall EnumElements (DWORD, void*, DWORD, IEnumSTATSTG**) { return E_NOTIMPL; }
  185034. HRESULT __stdcall DestroyElement (const OLECHAR*) { return E_NOTIMPL; }
  185035. HRESULT __stdcall RenameElement (const WCHAR*, const WCHAR*) { return E_NOTIMPL; }
  185036. HRESULT __stdcall SetElementTimes (const WCHAR*, FILETIME const*, FILETIME const*, FILETIME const*) { return E_NOTIMPL; }
  185037. HRESULT __stdcall SetClass (REFCLSID) { return S_OK; }
  185038. HRESULT __stdcall SetStateBits (DWORD, DWORD) { return E_NOTIMPL; }
  185039. HRESULT __stdcall Stat (STATSTG*, DWORD) { return E_NOTIMPL; }
  185040. juce_UseDebuggingNewOperator
  185041. };
  185042. class JuceOleInPlaceFrame : public IOleInPlaceFrame
  185043. {
  185044. int refCount;
  185045. HWND window;
  185046. public:
  185047. JuceOleInPlaceFrame (HWND window_)
  185048. : refCount (1),
  185049. window (window_)
  185050. {
  185051. }
  185052. virtual ~JuceOleInPlaceFrame()
  185053. {
  185054. jassert (refCount == 0);
  185055. }
  185056. HRESULT __stdcall QueryInterface (REFIID id, void __RPC_FAR* __RPC_FAR* result)
  185057. {
  185058. if (id == IID_IUnknown || id == IID_IOleInPlaceFrame)
  185059. {
  185060. AddRef();
  185061. *result = this;
  185062. return S_OK;
  185063. }
  185064. *result = 0;
  185065. return E_NOINTERFACE;
  185066. }
  185067. ULONG __stdcall AddRef() { return ++refCount; }
  185068. ULONG __stdcall Release() { const int r = --refCount; if (r == 0) delete this; return r; }
  185069. HRESULT __stdcall GetWindow (HWND* lphwnd) { *lphwnd = window; return S_OK; }
  185070. HRESULT __stdcall ContextSensitiveHelp (BOOL) { return E_NOTIMPL; }
  185071. HRESULT __stdcall GetBorder (LPRECT) { return E_NOTIMPL; }
  185072. HRESULT __stdcall RequestBorderSpace (LPCBORDERWIDTHS) { return E_NOTIMPL; }
  185073. HRESULT __stdcall SetBorderSpace (LPCBORDERWIDTHS) { return E_NOTIMPL; }
  185074. HRESULT __stdcall SetActiveObject (IOleInPlaceActiveObject*, LPCOLESTR) { return S_OK; }
  185075. HRESULT __stdcall InsertMenus (HMENU, LPOLEMENUGROUPWIDTHS) { return E_NOTIMPL; }
  185076. HRESULT __stdcall SetMenu (HMENU, HOLEMENU, HWND) { return S_OK; }
  185077. HRESULT __stdcall RemoveMenus (HMENU) { return E_NOTIMPL; }
  185078. HRESULT __stdcall SetStatusText (LPCOLESTR) { return S_OK; }
  185079. HRESULT __stdcall EnableModeless (BOOL) { return S_OK; }
  185080. HRESULT __stdcall TranslateAccelerator(LPMSG, WORD) { return E_NOTIMPL; }
  185081. juce_UseDebuggingNewOperator
  185082. };
  185083. class JuceIOleInPlaceSite : public IOleInPlaceSite
  185084. {
  185085. int refCount;
  185086. HWND window;
  185087. JuceOleInPlaceFrame* frame;
  185088. public:
  185089. JuceIOleInPlaceSite (HWND window_)
  185090. : refCount (1),
  185091. window (window_)
  185092. {
  185093. frame = new JuceOleInPlaceFrame (window);
  185094. }
  185095. virtual ~JuceIOleInPlaceSite()
  185096. {
  185097. jassert (refCount == 0);
  185098. frame->Release();
  185099. }
  185100. HRESULT __stdcall QueryInterface (REFIID id, void __RPC_FAR* __RPC_FAR* result)
  185101. {
  185102. if (id == IID_IUnknown || id == IID_IOleInPlaceSite)
  185103. {
  185104. AddRef();
  185105. *result = this;
  185106. return S_OK;
  185107. }
  185108. *result = 0;
  185109. return E_NOINTERFACE;
  185110. }
  185111. ULONG __stdcall AddRef() { return ++refCount; }
  185112. ULONG __stdcall Release() { const int r = --refCount; if (r == 0) delete this; return r; }
  185113. HRESULT __stdcall GetWindow (HWND* lphwnd) { *lphwnd = window; return S_OK; }
  185114. HRESULT __stdcall ContextSensitiveHelp (BOOL) { return E_NOTIMPL; }
  185115. HRESULT __stdcall CanInPlaceActivate() { return S_OK; }
  185116. HRESULT __stdcall OnInPlaceActivate() { return S_OK; }
  185117. HRESULT __stdcall OnUIActivate() { return S_OK; }
  185118. HRESULT __stdcall GetWindowContext (LPOLEINPLACEFRAME* lplpFrame, LPOLEINPLACEUIWINDOW* lplpDoc, LPRECT, LPRECT, LPOLEINPLACEFRAMEINFO lpFrameInfo)
  185119. {
  185120. // frame->AddRef(); // MS docs are unclear about whether this is needed, but it seems to lead to a memory leak..
  185121. *lplpFrame = frame;
  185122. *lplpDoc = 0;
  185123. lpFrameInfo->fMDIApp = FALSE;
  185124. lpFrameInfo->hwndFrame = window;
  185125. lpFrameInfo->haccel = 0;
  185126. lpFrameInfo->cAccelEntries = 0;
  185127. return S_OK;
  185128. }
  185129. HRESULT __stdcall Scroll (SIZE) { return E_NOTIMPL; }
  185130. HRESULT __stdcall OnUIDeactivate (BOOL) { return S_OK; }
  185131. HRESULT __stdcall OnInPlaceDeactivate() { return S_OK; }
  185132. HRESULT __stdcall DiscardUndoState() { return E_NOTIMPL; }
  185133. HRESULT __stdcall DeactivateAndUndo() { return E_NOTIMPL; }
  185134. HRESULT __stdcall OnPosRectChange (LPCRECT) { return S_OK; }
  185135. juce_UseDebuggingNewOperator
  185136. };
  185137. class JuceIOleClientSite : public IOleClientSite
  185138. {
  185139. int refCount;
  185140. JuceIOleInPlaceSite* inplaceSite;
  185141. public:
  185142. JuceIOleClientSite (HWND window)
  185143. : refCount (1)
  185144. {
  185145. inplaceSite = new JuceIOleInPlaceSite (window);
  185146. }
  185147. virtual ~JuceIOleClientSite()
  185148. {
  185149. jassert (refCount == 0);
  185150. inplaceSite->Release();
  185151. }
  185152. HRESULT __stdcall QueryInterface (REFIID id, void __RPC_FAR* __RPC_FAR* result)
  185153. {
  185154. if (id == IID_IUnknown || id == IID_IOleClientSite)
  185155. {
  185156. AddRef();
  185157. *result = this;
  185158. return S_OK;
  185159. }
  185160. else if (id == IID_IOleInPlaceSite)
  185161. {
  185162. inplaceSite->AddRef();
  185163. *result = inplaceSite;
  185164. return S_OK;
  185165. }
  185166. *result = 0;
  185167. return E_NOINTERFACE;
  185168. }
  185169. ULONG __stdcall AddRef() { return ++refCount; }
  185170. ULONG __stdcall Release() { const int r = --refCount; if (r == 0) delete this; return r; }
  185171. HRESULT __stdcall SaveObject() { return E_NOTIMPL; }
  185172. HRESULT __stdcall GetMoniker (DWORD, DWORD, IMoniker**) { return E_NOTIMPL; }
  185173. HRESULT __stdcall GetContainer (LPOLECONTAINER* ppContainer) { *ppContainer = 0; return E_NOINTERFACE; }
  185174. HRESULT __stdcall ShowObject() { return S_OK; }
  185175. HRESULT __stdcall OnShowWindow (BOOL) { return E_NOTIMPL; }
  185176. HRESULT __stdcall RequestNewObjectLayout() { return E_NOTIMPL; }
  185177. juce_UseDebuggingNewOperator
  185178. };
  185179. class ActiveXControlData : public ComponentMovementWatcher
  185180. {
  185181. ActiveXControlComponent* const owner;
  185182. bool wasShowing;
  185183. public:
  185184. HWND controlHWND;
  185185. IStorage* storage;
  185186. IOleClientSite* clientSite;
  185187. IOleObject* control;
  185188. ActiveXControlData (HWND hwnd,
  185189. ActiveXControlComponent* const owner_)
  185190. : ComponentMovementWatcher (owner_),
  185191. owner (owner_),
  185192. wasShowing (owner_ != 0 && owner_->isShowing()),
  185193. controlHWND (0),
  185194. storage (new JuceIStorage()),
  185195. clientSite (new JuceIOleClientSite (hwnd)),
  185196. control (0)
  185197. {
  185198. }
  185199. ~ActiveXControlData()
  185200. {
  185201. if (control != 0)
  185202. {
  185203. control->Close (OLECLOSE_NOSAVE);
  185204. control->Release();
  185205. }
  185206. clientSite->Release();
  185207. storage->Release();
  185208. }
  185209. void componentMovedOrResized (bool /*wasMoved*/, bool /*wasResized*/)
  185210. {
  185211. Component* const topComp = owner->getTopLevelComponent();
  185212. if (topComp->getPeer() != 0)
  185213. {
  185214. int x = 0, y = 0;
  185215. owner->relativePositionToOtherComponent (topComp, x, y);
  185216. owner->setControlBounds (Rectangle (x, y, owner->getWidth(), owner->getHeight()));
  185217. }
  185218. }
  185219. void componentPeerChanged()
  185220. {
  185221. const bool isShowingNow = owner->isShowing();
  185222. if (wasShowing != isShowingNow)
  185223. {
  185224. wasShowing = isShowingNow;
  185225. owner->setControlVisible (isShowingNow);
  185226. }
  185227. componentMovedOrResized (true, true);
  185228. }
  185229. void componentVisibilityChanged (Component&)
  185230. {
  185231. componentPeerChanged();
  185232. }
  185233. static bool doesWindowMatch (const ActiveXControlComponent* const ax, HWND hwnd)
  185234. {
  185235. return ((ActiveXControlData*) ax->control) != 0
  185236. && ((ActiveXControlData*) ax->control)->controlHWND == hwnd;
  185237. }
  185238. };
  185239. static VoidArray activeXComps;
  185240. static HWND getHWND (const ActiveXControlComponent* const component)
  185241. {
  185242. HWND hwnd = 0;
  185243. const IID iid = IID_IOleWindow;
  185244. IOleWindow* const window = (IOleWindow*) component->queryInterface (&iid);
  185245. if (window != 0)
  185246. {
  185247. window->GetWindow (&hwnd);
  185248. window->Release();
  185249. }
  185250. return hwnd;
  185251. }
  185252. static void offerActiveXMouseEventToPeer (ComponentPeer* const peer, HWND hwnd, UINT message, LPARAM lParam)
  185253. {
  185254. RECT activeXRect, peerRect;
  185255. GetWindowRect (hwnd, &activeXRect);
  185256. GetWindowRect ((HWND) peer->getNativeHandle(), &peerRect);
  185257. const int mx = GET_X_LPARAM (lParam) + activeXRect.left - peerRect.left;
  185258. const int my = GET_Y_LPARAM (lParam) + activeXRect.top - peerRect.top;
  185259. const int64 mouseEventTime = getMouseEventTime();
  185260. const int oldModifiers = currentModifiers;
  185261. ModifierKeys::getCurrentModifiersRealtime(); // to update the mouse button flags
  185262. switch (message)
  185263. {
  185264. case WM_MOUSEMOVE:
  185265. if (ModifierKeys (currentModifiers).isAnyMouseButtonDown())
  185266. peer->handleMouseDrag (mx, my, mouseEventTime);
  185267. else
  185268. peer->handleMouseMove (mx, my, mouseEventTime);
  185269. break;
  185270. case WM_LBUTTONDOWN:
  185271. case WM_MBUTTONDOWN:
  185272. case WM_RBUTTONDOWN:
  185273. peer->handleMouseDown (mx, my, mouseEventTime);
  185274. break;
  185275. case WM_LBUTTONUP:
  185276. case WM_MBUTTONUP:
  185277. case WM_RBUTTONUP:
  185278. peer->handleMouseUp (oldModifiers, mx, my, mouseEventTime);
  185279. break;
  185280. default:
  185281. break;
  185282. }
  185283. }
  185284. // intercepts events going to an activeX control, so we can sneakily use the mouse events
  185285. static LRESULT CALLBACK activeXHookWndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
  185286. {
  185287. for (int i = activeXComps.size(); --i >= 0;)
  185288. {
  185289. const ActiveXControlComponent* const ax = (const ActiveXControlComponent*) activeXComps.getUnchecked(i);
  185290. if (ActiveXControlData::doesWindowMatch (ax, hwnd))
  185291. {
  185292. switch (message)
  185293. {
  185294. case WM_MOUSEMOVE:
  185295. case WM_LBUTTONDOWN:
  185296. case WM_MBUTTONDOWN:
  185297. case WM_RBUTTONDOWN:
  185298. case WM_LBUTTONUP:
  185299. case WM_MBUTTONUP:
  185300. case WM_RBUTTONUP:
  185301. case WM_LBUTTONDBLCLK:
  185302. case WM_MBUTTONDBLCLK:
  185303. case WM_RBUTTONDBLCLK:
  185304. if (ax->isShowing())
  185305. {
  185306. ComponentPeer* const peer = ax->getPeer();
  185307. if (peer != 0)
  185308. {
  185309. offerActiveXMouseEventToPeer (peer, hwnd, message, lParam);
  185310. if (! ax->areMouseEventsAllowed())
  185311. return 0;
  185312. }
  185313. }
  185314. break;
  185315. default:
  185316. break;
  185317. }
  185318. return CallWindowProc ((WNDPROC) (ax->originalWndProc), hwnd, message, wParam, lParam);
  185319. }
  185320. }
  185321. return DefWindowProc (hwnd, message, wParam, lParam);
  185322. }
  185323. ActiveXControlComponent::ActiveXControlComponent()
  185324. : originalWndProc (0),
  185325. control (0),
  185326. mouseEventsAllowed (true)
  185327. {
  185328. activeXComps.add (this);
  185329. }
  185330. ActiveXControlComponent::~ActiveXControlComponent()
  185331. {
  185332. deleteControl();
  185333. activeXComps.removeValue (this);
  185334. }
  185335. void ActiveXControlComponent::paint (Graphics& g)
  185336. {
  185337. if (control == 0)
  185338. g.fillAll (Colours::lightgrey);
  185339. }
  185340. bool ActiveXControlComponent::createControl (const void* controlIID)
  185341. {
  185342. deleteControl();
  185343. ComponentPeer* const peer = getPeer();
  185344. // the component must have already been added to a real window when you call this!
  185345. jassert (dynamic_cast <Win32ComponentPeer*> (peer) != 0);
  185346. if (dynamic_cast <Win32ComponentPeer*> (peer) != 0)
  185347. {
  185348. int x = 0, y = 0;
  185349. relativePositionToOtherComponent (getTopLevelComponent(), x, y);
  185350. HWND hwnd = (HWND) peer->getNativeHandle();
  185351. ScopedPointer <ActiveXControlData> info (new ActiveXControlData (hwnd, this));
  185352. HRESULT hr;
  185353. if ((hr = OleCreate (*(const IID*) controlIID, IID_IOleObject, 1 /*OLERENDER_DRAW*/, 0,
  185354. info->clientSite, info->storage,
  185355. (void**) &(info->control))) == S_OK)
  185356. {
  185357. info->control->SetHostNames (L"Juce", 0);
  185358. if (OleSetContainedObject (info->control, TRUE) == S_OK)
  185359. {
  185360. RECT rect;
  185361. rect.left = x;
  185362. rect.top = y;
  185363. rect.right = x + getWidth();
  185364. rect.bottom = y + getHeight();
  185365. if (info->control->DoVerb (OLEIVERB_SHOW, 0, info->clientSite, 0, hwnd, &rect) == S_OK)
  185366. {
  185367. control = info.release();
  185368. setControlBounds (Rectangle (x, y, getWidth(), getHeight()));
  185369. ((ActiveXControlData*) control)->controlHWND = getHWND (this);
  185370. if (((ActiveXControlData*) control)->controlHWND != 0)
  185371. {
  185372. originalWndProc = (void*) (pointer_sized_int) GetWindowLongPtr ((HWND) ((ActiveXControlData*) control)->controlHWND, GWLP_WNDPROC);
  185373. SetWindowLongPtr ((HWND) ((ActiveXControlData*) control)->controlHWND, GWLP_WNDPROC, (LONG_PTR) activeXHookWndProc);
  185374. }
  185375. return true;
  185376. }
  185377. }
  185378. }
  185379. }
  185380. return false;
  185381. }
  185382. void ActiveXControlComponent::deleteControl()
  185383. {
  185384. ActiveXControlData* const info = (ActiveXControlData*) control;
  185385. if (info != 0)
  185386. {
  185387. delete info;
  185388. control = 0;
  185389. originalWndProc = 0;
  185390. }
  185391. }
  185392. void* ActiveXControlComponent::queryInterface (const void* iid) const
  185393. {
  185394. ActiveXControlData* const info = (ActiveXControlData*) control;
  185395. void* result = 0;
  185396. if (info != 0 && info->control != 0
  185397. && info->control->QueryInterface (*(const IID*) iid, &result) == S_OK)
  185398. return result;
  185399. return 0;
  185400. }
  185401. void ActiveXControlComponent::setControlBounds (const Rectangle& newBounds) const
  185402. {
  185403. HWND hwnd = ((ActiveXControlData*) control)->controlHWND;
  185404. if (hwnd != 0)
  185405. MoveWindow (hwnd, newBounds.getX(), newBounds.getY(), newBounds.getWidth(), newBounds.getHeight(), TRUE);
  185406. }
  185407. void ActiveXControlComponent::setControlVisible (const bool shouldBeVisible) const
  185408. {
  185409. HWND hwnd = ((ActiveXControlData*) control)->controlHWND;
  185410. if (hwnd != 0)
  185411. ShowWindow (hwnd, shouldBeVisible ? SW_SHOWNA : SW_HIDE);
  185412. }
  185413. void ActiveXControlComponent::setMouseEventsAllowed (const bool eventsCanReachControl)
  185414. {
  185415. mouseEventsAllowed = eventsCanReachControl;
  185416. }
  185417. #endif
  185418. /********* End of inlined file: juce_win32_ActiveXComponent.cpp *********/
  185419. /********* Start of inlined file: juce_win32_QuickTimeMovieComponent.cpp *********/
  185420. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  185421. // compiled on its own).
  185422. #if JUCE_INCLUDED_FILE && JUCE_QUICKTIME
  185423. using namespace QTOLibrary;
  185424. using namespace QTOControlLib;
  185425. bool juce_OpenQuickTimeMovieFromStream (InputStream* input, Movie& movie, Handle& dataHandle);
  185426. static bool isQTAvailable = false;
  185427. struct QTMovieCompInternal
  185428. {
  185429. QTMovieCompInternal()
  185430. : dataHandle (0)
  185431. {
  185432. }
  185433. ~QTMovieCompInternal()
  185434. {
  185435. clearHandle();
  185436. }
  185437. IQTControlPtr qtControlInternal;
  185438. IQTMoviePtr qtMovieInternal;
  185439. Handle dataHandle;
  185440. void clearHandle()
  185441. {
  185442. if (dataHandle != 0)
  185443. {
  185444. DisposeHandle (dataHandle);
  185445. dataHandle = 0;
  185446. }
  185447. }
  185448. };
  185449. #define qtControl (((QTMovieCompInternal*) internal)->qtControlInternal)
  185450. #define qtMovie (((QTMovieCompInternal*) internal)->qtMovieInternal)
  185451. QuickTimeMovieComponent::QuickTimeMovieComponent()
  185452. : movieLoaded (false),
  185453. controllerVisible (true)
  185454. {
  185455. internal = new QTMovieCompInternal();
  185456. setMouseEventsAllowed (false);
  185457. }
  185458. QuickTimeMovieComponent::~QuickTimeMovieComponent()
  185459. {
  185460. closeMovie();
  185461. qtControl = 0;
  185462. deleteControl();
  185463. delete internal;
  185464. internal = 0;
  185465. }
  185466. bool QuickTimeMovieComponent::isQuickTimeAvailable() throw()
  185467. {
  185468. if (! isQTAvailable)
  185469. {
  185470. isQTAvailable = (InitializeQTML (0) == noErr)
  185471. && (EnterMovies() == noErr);
  185472. }
  185473. return isQTAvailable;
  185474. }
  185475. void QuickTimeMovieComponent::createControlIfNeeded()
  185476. {
  185477. if (isShowing() && ! isControlCreated())
  185478. {
  185479. const IID qtIID = __uuidof (QTControl);
  185480. if (createControl (&qtIID))
  185481. {
  185482. const IID qtInterfaceIID = __uuidof (IQTControl);
  185483. qtControl = (IQTControl*) queryInterface (&qtInterfaceIID);
  185484. if (qtControl != 0)
  185485. {
  185486. qtControl->Release(); // it has one ref too many at this point
  185487. qtControl->QuickTimeInitialize();
  185488. qtControl->PutSizing (qtMovieFitsControl);
  185489. if (movieFile != File::nonexistent)
  185490. loadMovie (movieFile, controllerVisible);
  185491. }
  185492. }
  185493. }
  185494. }
  185495. bool QuickTimeMovieComponent::isControlCreated() const
  185496. {
  185497. return isControlOpen();
  185498. }
  185499. bool QuickTimeMovieComponent::loadMovie (InputStream* movieStream,
  185500. const bool isControllerVisible)
  185501. {
  185502. movieFile = File::nonexistent;
  185503. movieLoaded = false;
  185504. qtMovie = 0;
  185505. controllerVisible = isControllerVisible;
  185506. createControlIfNeeded();
  185507. if (isControlCreated())
  185508. {
  185509. if (qtControl != 0)
  185510. {
  185511. qtControl->Put_MovieHandle (0);
  185512. ((QTMovieCompInternal*) internal)->clearHandle();
  185513. Movie movie;
  185514. if (juce_OpenQuickTimeMovieFromStream (movieStream, movie, ((QTMovieCompInternal*) internal)->dataHandle))
  185515. {
  185516. qtControl->Put_MovieHandle ((long) (pointer_sized_int) movie);
  185517. qtMovie = qtControl->GetMovie();
  185518. if (qtMovie != 0)
  185519. qtMovie->PutMovieControllerType (isControllerVisible ? qtMovieControllerTypeStandard
  185520. : qtMovieControllerTypeNone);
  185521. }
  185522. if (movie == 0)
  185523. ((QTMovieCompInternal*) internal)->clearHandle();
  185524. }
  185525. movieLoaded = (qtMovie != 0);
  185526. }
  185527. else
  185528. {
  185529. // You're trying to open a movie when the control hasn't yet been created, probably because
  185530. // you've not yet added this component to a Window and made the whole component hierarchy visible.
  185531. jassertfalse
  185532. }
  185533. delete movieStream;
  185534. return movieLoaded;
  185535. }
  185536. void QuickTimeMovieComponent::closeMovie()
  185537. {
  185538. stop();
  185539. movieFile = File::nonexistent;
  185540. movieLoaded = false;
  185541. qtMovie = 0;
  185542. if (qtControl != 0)
  185543. qtControl->Put_MovieHandle (0);
  185544. ((QTMovieCompInternal*) internal)->clearHandle();
  185545. }
  185546. const File QuickTimeMovieComponent::getCurrentMovieFile() const
  185547. {
  185548. return movieFile;
  185549. }
  185550. bool QuickTimeMovieComponent::isMovieOpen() const
  185551. {
  185552. return movieLoaded;
  185553. }
  185554. double QuickTimeMovieComponent::getMovieDuration() const
  185555. {
  185556. if (qtMovie != 0)
  185557. return qtMovie->GetDuration() / (double) qtMovie->GetTimeScale();
  185558. return 0.0;
  185559. }
  185560. void QuickTimeMovieComponent::getMovieNormalSize (int& width, int& height) const
  185561. {
  185562. if (qtMovie != 0)
  185563. {
  185564. struct QTRECT r = qtMovie->GetNaturalRect();
  185565. width = r.right - r.left;
  185566. height = r.bottom - r.top;
  185567. }
  185568. else
  185569. {
  185570. width = height = 0;
  185571. }
  185572. }
  185573. void QuickTimeMovieComponent::play()
  185574. {
  185575. if (qtMovie != 0)
  185576. qtMovie->Play();
  185577. }
  185578. void QuickTimeMovieComponent::stop()
  185579. {
  185580. if (qtMovie != 0)
  185581. qtMovie->Stop();
  185582. }
  185583. bool QuickTimeMovieComponent::isPlaying() const
  185584. {
  185585. return qtMovie != 0 && qtMovie->GetRate() != 0.0f;
  185586. }
  185587. void QuickTimeMovieComponent::setPosition (const double seconds)
  185588. {
  185589. if (qtMovie != 0)
  185590. qtMovie->PutTime ((long) (seconds * qtMovie->GetTimeScale()));
  185591. }
  185592. double QuickTimeMovieComponent::getPosition() const
  185593. {
  185594. if (qtMovie != 0)
  185595. return qtMovie->GetTime() / (double) qtMovie->GetTimeScale();
  185596. return 0.0;
  185597. }
  185598. void QuickTimeMovieComponent::setSpeed (const float newSpeed)
  185599. {
  185600. if (qtMovie != 0)
  185601. qtMovie->PutRate (newSpeed);
  185602. }
  185603. void QuickTimeMovieComponent::setMovieVolume (const float newVolume)
  185604. {
  185605. if (qtMovie != 0)
  185606. {
  185607. qtMovie->PutAudioVolume (newVolume);
  185608. qtMovie->PutAudioMute (newVolume <= 0);
  185609. }
  185610. }
  185611. float QuickTimeMovieComponent::getMovieVolume() const
  185612. {
  185613. if (qtMovie != 0)
  185614. return qtMovie->GetAudioVolume();
  185615. return 0.0f;
  185616. }
  185617. void QuickTimeMovieComponent::setLooping (const bool shouldLoop)
  185618. {
  185619. if (qtMovie != 0)
  185620. qtMovie->PutLoop (shouldLoop);
  185621. }
  185622. bool QuickTimeMovieComponent::isLooping() const
  185623. {
  185624. return qtMovie != 0 && qtMovie->GetLoop();
  185625. }
  185626. bool QuickTimeMovieComponent::isControllerVisible() const
  185627. {
  185628. return controllerVisible;
  185629. }
  185630. void QuickTimeMovieComponent::parentHierarchyChanged()
  185631. {
  185632. createControlIfNeeded();
  185633. QTCompBaseClass::parentHierarchyChanged();
  185634. }
  185635. void QuickTimeMovieComponent::visibilityChanged()
  185636. {
  185637. createControlIfNeeded();
  185638. QTCompBaseClass::visibilityChanged();
  185639. }
  185640. void QuickTimeMovieComponent::paint (Graphics& g)
  185641. {
  185642. if (! isControlCreated())
  185643. g.fillAll (Colours::black);
  185644. }
  185645. static Handle createHandleDataRef (Handle dataHandle, const char* fileName)
  185646. {
  185647. Handle dataRef = 0;
  185648. OSStatus err = PtrToHand (&dataHandle, &dataRef, sizeof (Handle));
  185649. if (err == noErr)
  185650. {
  185651. Str255 suffix;
  185652. CharacterFunctions::copy ((char*) suffix, fileName, 128);
  185653. StringPtr name = suffix;
  185654. err = PtrAndHand (name, dataRef, name[0] + 1);
  185655. if (err == noErr)
  185656. {
  185657. long atoms[3];
  185658. atoms[0] = EndianU32_NtoB (3 * sizeof (long));
  185659. atoms[1] = EndianU32_NtoB (kDataRefExtensionMacOSFileType);
  185660. atoms[2] = EndianU32_NtoB (MovieFileType);
  185661. err = PtrAndHand (atoms, dataRef, 3 * sizeof (long));
  185662. if (err == noErr)
  185663. return dataRef;
  185664. }
  185665. DisposeHandle (dataRef);
  185666. }
  185667. return 0;
  185668. }
  185669. static CFStringRef juceStringToCFString (const String& s)
  185670. {
  185671. const int len = s.length();
  185672. const juce_wchar* const t = (const juce_wchar*) s;
  185673. HeapBlock <UniChar> temp (len + 2);
  185674. for (int i = 0; i <= len; ++i)
  185675. temp[i] = t[i];
  185676. return CFStringCreateWithCharacters (kCFAllocatorDefault, temp, len);
  185677. }
  185678. static bool openMovie (QTNewMoviePropertyElement* props, int prop, Movie& movie)
  185679. {
  185680. Boolean trueBool = true;
  185681. props[prop].propClass = kQTPropertyClass_MovieInstantiation;
  185682. props[prop].propID = kQTMovieInstantiationPropertyID_DontResolveDataRefs;
  185683. props[prop].propValueSize = sizeof (trueBool);
  185684. props[prop].propValueAddress = &trueBool;
  185685. ++prop;
  185686. props[prop].propClass = kQTPropertyClass_MovieInstantiation;
  185687. props[prop].propID = kQTMovieInstantiationPropertyID_AsyncOK;
  185688. props[prop].propValueSize = sizeof (trueBool);
  185689. props[prop].propValueAddress = &trueBool;
  185690. ++prop;
  185691. Boolean isActive = true;
  185692. props[prop].propClass = kQTPropertyClass_NewMovieProperty;
  185693. props[prop].propID = kQTNewMoviePropertyID_Active;
  185694. props[prop].propValueSize = sizeof (isActive);
  185695. props[prop].propValueAddress = &isActive;
  185696. ++prop;
  185697. MacSetPort (0);
  185698. jassert (prop <= 5);
  185699. OSStatus err = NewMovieFromProperties (prop, props, 0, 0, &movie);
  185700. return err == noErr;
  185701. }
  185702. bool juce_OpenQuickTimeMovieFromStream (InputStream* input, Movie& movie, Handle& dataHandle)
  185703. {
  185704. if (input == 0)
  185705. return false;
  185706. dataHandle = 0;
  185707. bool ok = false;
  185708. QTNewMoviePropertyElement props[5];
  185709. zeromem (props, sizeof (props));
  185710. int prop = 0;
  185711. DataReferenceRecord dr;
  185712. props[prop].propClass = kQTPropertyClass_DataLocation;
  185713. props[prop].propID = kQTDataLocationPropertyID_DataReference;
  185714. props[prop].propValueSize = sizeof (dr);
  185715. props[prop].propValueAddress = (void*) &dr;
  185716. ++prop;
  185717. FileInputStream* const fin = dynamic_cast <FileInputStream*> (input);
  185718. if (fin != 0)
  185719. {
  185720. CFStringRef filePath = juceStringToCFString (fin->getFile().getFullPathName());
  185721. QTNewDataReferenceFromFullPathCFString (filePath, (QTPathStyle) kQTNativeDefaultPathStyle, 0,
  185722. &dr.dataRef, &dr.dataRefType);
  185723. ok = openMovie (props, prop, movie);
  185724. DisposeHandle (dr.dataRef);
  185725. CFRelease (filePath);
  185726. }
  185727. else
  185728. {
  185729. // sanity-check because this currently needs to load the whole stream into memory..
  185730. jassert (input->getTotalLength() < 50 * 1024 * 1024);
  185731. dataHandle = NewHandle ((Size) input->getTotalLength());
  185732. HLock (dataHandle);
  185733. // read the entire stream into memory - this is a pain, but can't get it to work
  185734. // properly using a custom callback to supply the data.
  185735. input->read (*dataHandle, (int) input->getTotalLength());
  185736. HUnlock (dataHandle);
  185737. // different types to get QT to try. (We should really be a bit smarter here by
  185738. // working out in advance which one the stream contains, rather than just trying
  185739. // each one)
  185740. const char* const suffixesToTry[] = { "\04.mov", "\04.mp3",
  185741. "\04.avi", "\04.m4a" };
  185742. for (int i = 0; i < numElementsInArray (suffixesToTry) && ! ok; ++i)
  185743. {
  185744. dr.dataRef = createHandleDataRef (dataHandle, suffixesToTry [i]);
  185745. dr.dataRefType = HandleDataHandlerSubType;
  185746. ok = openMovie (props, prop, movie);
  185747. DisposeHandle (dr.dataRef);
  185748. }
  185749. }
  185750. return ok;
  185751. }
  185752. bool QuickTimeMovieComponent::loadMovie (const File& movieFile_,
  185753. const bool isControllerVisible)
  185754. {
  185755. const bool ok = loadMovie ((InputStream*) movieFile_.createInputStream(), isControllerVisible);
  185756. movieFile = movieFile_;
  185757. return ok;
  185758. }
  185759. bool QuickTimeMovieComponent::loadMovie (const URL& movieURL,
  185760. const bool isControllerVisible)
  185761. {
  185762. return loadMovie ((InputStream*) movieURL.createInputStream (false), isControllerVisible);
  185763. }
  185764. void QuickTimeMovieComponent::goToStart()
  185765. {
  185766. setPosition (0.0);
  185767. }
  185768. void QuickTimeMovieComponent::setBoundsWithCorrectAspectRatio (const Rectangle& spaceToFitWithin,
  185769. const RectanglePlacement& placement)
  185770. {
  185771. int normalWidth, normalHeight;
  185772. getMovieNormalSize (normalWidth, normalHeight);
  185773. if (normalWidth > 0 && normalHeight > 0 && ! spaceToFitWithin.isEmpty())
  185774. {
  185775. double x = 0.0, y = 0.0, w = normalWidth, h = normalHeight;
  185776. placement.applyTo (x, y, w, h,
  185777. spaceToFitWithin.getX(), spaceToFitWithin.getY(),
  185778. spaceToFitWithin.getWidth(), spaceToFitWithin.getHeight());
  185779. if (w > 0 && h > 0)
  185780. {
  185781. setBounds (roundToInt (x), roundToInt (y),
  185782. roundToInt (w), roundToInt (h));
  185783. }
  185784. }
  185785. else
  185786. {
  185787. setBounds (spaceToFitWithin);
  185788. }
  185789. }
  185790. #endif
  185791. /********* End of inlined file: juce_win32_QuickTimeMovieComponent.cpp *********/
  185792. /********* Start of inlined file: juce_win32_WebBrowserComponent.cpp *********/
  185793. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  185794. // compiled on its own).
  185795. #if JUCE_INCLUDED_FILE && JUCE_WEB_BROWSER
  185796. class WebBrowserComponentInternal : public ActiveXControlComponent
  185797. {
  185798. public:
  185799. WebBrowserComponentInternal()
  185800. : browser (0),
  185801. connectionPoint (0),
  185802. adviseCookie (0)
  185803. {
  185804. }
  185805. ~WebBrowserComponentInternal()
  185806. {
  185807. if (connectionPoint != 0)
  185808. connectionPoint->Unadvise (adviseCookie);
  185809. if (browser != 0)
  185810. browser->Release();
  185811. }
  185812. void createBrowser()
  185813. {
  185814. createControl (&CLSID_WebBrowser);
  185815. browser = (IWebBrowser2*) queryInterface (&IID_IWebBrowser2);
  185816. IConnectionPointContainer* connectionPointContainer = (IConnectionPointContainer*) queryInterface (&IID_IConnectionPointContainer);
  185817. if (connectionPointContainer != 0)
  185818. {
  185819. connectionPointContainer->FindConnectionPoint (DIID_DWebBrowserEvents2,
  185820. &connectionPoint);
  185821. if (connectionPoint != 0)
  185822. {
  185823. WebBrowserComponent* const owner = dynamic_cast <WebBrowserComponent*> (getParentComponent());
  185824. jassert (owner != 0);
  185825. EventHandler* handler = new EventHandler (owner);
  185826. connectionPoint->Advise (handler, &adviseCookie);
  185827. }
  185828. }
  185829. }
  185830. void goToURL (const String& url,
  185831. const StringArray* headers,
  185832. const MemoryBlock* postData)
  185833. {
  185834. if (browser != 0)
  185835. {
  185836. LPSAFEARRAY sa = 0;
  185837. VARIANT flags, frame, postDataVar, headersVar; // (_variant_t isn't available in all compilers)
  185838. VariantInit (&flags);
  185839. VariantInit (&frame);
  185840. VariantInit (&postDataVar);
  185841. VariantInit (&headersVar);
  185842. if (headers != 0)
  185843. {
  185844. V_VT (&headersVar) = VT_BSTR;
  185845. V_BSTR (&headersVar) = SysAllocString ((const tchar*) headers->joinIntoString ("\r\n"));
  185846. }
  185847. if (postData != 0 && postData->getSize() > 0)
  185848. {
  185849. LPSAFEARRAY sa = SafeArrayCreateVector (VT_UI1, 0, postData->getSize());
  185850. if (sa != 0)
  185851. {
  185852. void* data = 0;
  185853. SafeArrayAccessData (sa, &data);
  185854. jassert (data != 0);
  185855. if (data != 0)
  185856. {
  185857. postData->copyTo (data, 0, postData->getSize());
  185858. SafeArrayUnaccessData (sa);
  185859. VARIANT postDataVar2;
  185860. VariantInit (&postDataVar2);
  185861. V_VT (&postDataVar2) = VT_ARRAY | VT_UI1;
  185862. V_ARRAY (&postDataVar2) = sa;
  185863. postDataVar = postDataVar2;
  185864. }
  185865. }
  185866. }
  185867. browser->Navigate ((BSTR) (const OLECHAR*) url,
  185868. &flags, &frame,
  185869. &postDataVar, &headersVar);
  185870. if (sa != 0)
  185871. SafeArrayDestroy (sa);
  185872. VariantClear (&flags);
  185873. VariantClear (&frame);
  185874. VariantClear (&postDataVar);
  185875. VariantClear (&headersVar);
  185876. }
  185877. }
  185878. IWebBrowser2* browser;
  185879. juce_UseDebuggingNewOperator
  185880. private:
  185881. IConnectionPoint* connectionPoint;
  185882. DWORD adviseCookie;
  185883. class EventHandler : public IDispatch,
  185884. public ComponentMovementWatcher
  185885. {
  185886. public:
  185887. EventHandler (WebBrowserComponent* owner_)
  185888. : ComponentMovementWatcher (owner_),
  185889. owner (owner_),
  185890. refCount (0)
  185891. {
  185892. }
  185893. ~EventHandler()
  185894. {
  185895. }
  185896. HRESULT __stdcall QueryInterface (REFIID id, void __RPC_FAR* __RPC_FAR* result)
  185897. {
  185898. if (id == IID_IUnknown || id == IID_IDispatch || id == DIID_DWebBrowserEvents2)
  185899. {
  185900. AddRef();
  185901. *result = this;
  185902. return S_OK;
  185903. }
  185904. *result = 0;
  185905. return E_NOINTERFACE;
  185906. }
  185907. ULONG __stdcall AddRef() { return ++refCount; }
  185908. ULONG __stdcall Release() { jassert (refCount > 0); const int r = --refCount; if (r == 0) delete this; return r; }
  185909. HRESULT __stdcall GetTypeInfoCount (UINT __RPC_FAR*) { return E_NOTIMPL; }
  185910. HRESULT __stdcall GetTypeInfo (UINT, LCID, ITypeInfo __RPC_FAR *__RPC_FAR*) { return E_NOTIMPL; }
  185911. HRESULT __stdcall GetIDsOfNames (REFIID, LPOLESTR __RPC_FAR*, UINT, LCID, DISPID __RPC_FAR*) { return E_NOTIMPL; }
  185912. HRESULT __stdcall Invoke (DISPID dispIdMember, REFIID /*riid*/, LCID /*lcid*/,
  185913. WORD /*wFlags*/, DISPPARAMS __RPC_FAR* pDispParams,
  185914. VARIANT __RPC_FAR* /*pVarResult*/, EXCEPINFO __RPC_FAR* /*pExcepInfo*/,
  185915. UINT __RPC_FAR* /*puArgErr*/)
  185916. {
  185917. switch (dispIdMember)
  185918. {
  185919. case DISPID_BEFORENAVIGATE2:
  185920. {
  185921. VARIANT* const vurl = pDispParams->rgvarg[5].pvarVal;
  185922. String url;
  185923. if ((vurl->vt & VT_BYREF) != 0)
  185924. url = *vurl->pbstrVal;
  185925. else
  185926. url = vurl->bstrVal;
  185927. *pDispParams->rgvarg->pboolVal
  185928. = owner->pageAboutToLoad (url) ? VARIANT_FALSE
  185929. : VARIANT_TRUE;
  185930. return S_OK;
  185931. }
  185932. default:
  185933. break;
  185934. }
  185935. return E_NOTIMPL;
  185936. }
  185937. void componentMovedOrResized (bool /*wasMoved*/, bool /*wasResized*/) {}
  185938. void componentPeerChanged() {}
  185939. void componentVisibilityChanged (Component&)
  185940. {
  185941. owner->visibilityChanged();
  185942. }
  185943. juce_UseDebuggingNewOperator
  185944. private:
  185945. WebBrowserComponent* const owner;
  185946. int refCount;
  185947. EventHandler (const EventHandler&);
  185948. const EventHandler& operator= (const EventHandler&);
  185949. };
  185950. };
  185951. WebBrowserComponent::WebBrowserComponent (const bool unloadPageWhenBrowserIsHidden_)
  185952. : browser (0),
  185953. blankPageShown (false),
  185954. unloadPageWhenBrowserIsHidden (unloadPageWhenBrowserIsHidden_)
  185955. {
  185956. setOpaque (true);
  185957. addAndMakeVisible (browser = new WebBrowserComponentInternal());
  185958. }
  185959. WebBrowserComponent::~WebBrowserComponent()
  185960. {
  185961. delete browser;
  185962. }
  185963. void WebBrowserComponent::goToURL (const String& url,
  185964. const StringArray* headers,
  185965. const MemoryBlock* postData)
  185966. {
  185967. lastURL = url;
  185968. lastHeaders.clear();
  185969. if (headers != 0)
  185970. lastHeaders = *headers;
  185971. lastPostData.setSize (0);
  185972. if (postData != 0)
  185973. lastPostData = *postData;
  185974. blankPageShown = false;
  185975. browser->goToURL (url, headers, postData);
  185976. }
  185977. void WebBrowserComponent::stop()
  185978. {
  185979. if (browser->browser != 0)
  185980. browser->browser->Stop();
  185981. }
  185982. void WebBrowserComponent::goBack()
  185983. {
  185984. lastURL = String::empty;
  185985. blankPageShown = false;
  185986. if (browser->browser != 0)
  185987. browser->browser->GoBack();
  185988. }
  185989. void WebBrowserComponent::goForward()
  185990. {
  185991. lastURL = String::empty;
  185992. if (browser->browser != 0)
  185993. browser->browser->GoForward();
  185994. }
  185995. void WebBrowserComponent::refresh()
  185996. {
  185997. if (browser->browser != 0)
  185998. browser->browser->Refresh();
  185999. }
  186000. void WebBrowserComponent::paint (Graphics& g)
  186001. {
  186002. if (browser->browser == 0)
  186003. g.fillAll (Colours::white);
  186004. }
  186005. void WebBrowserComponent::checkWindowAssociation()
  186006. {
  186007. if (isShowing())
  186008. {
  186009. if (browser->browser == 0 && getPeer() != 0)
  186010. {
  186011. browser->createBrowser();
  186012. reloadLastURL();
  186013. }
  186014. else
  186015. {
  186016. if (blankPageShown)
  186017. goBack();
  186018. }
  186019. }
  186020. else
  186021. {
  186022. if (browser != 0 && unloadPageWhenBrowserIsHidden && ! blankPageShown)
  186023. {
  186024. // when the component becomes invisible, some stuff like flash
  186025. // carries on playing audio, so we need to force it onto a blank
  186026. // page to avoid this..
  186027. blankPageShown = true;
  186028. browser->goToURL ("about:blank", 0, 0);
  186029. }
  186030. }
  186031. }
  186032. void WebBrowserComponent::reloadLastURL()
  186033. {
  186034. if (lastURL.isNotEmpty())
  186035. {
  186036. goToURL (lastURL, &lastHeaders, &lastPostData);
  186037. lastURL = String::empty;
  186038. }
  186039. }
  186040. void WebBrowserComponent::parentHierarchyChanged()
  186041. {
  186042. checkWindowAssociation();
  186043. }
  186044. void WebBrowserComponent::resized()
  186045. {
  186046. browser->setSize (getWidth(), getHeight());
  186047. }
  186048. void WebBrowserComponent::visibilityChanged()
  186049. {
  186050. checkWindowAssociation();
  186051. }
  186052. bool WebBrowserComponent::pageAboutToLoad (const String&)
  186053. {
  186054. return true;
  186055. }
  186056. #endif
  186057. /********* End of inlined file: juce_win32_WebBrowserComponent.cpp *********/
  186058. /********* Start of inlined file: juce_win32_OpenGLComponent.cpp *********/
  186059. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  186060. // compiled on its own).
  186061. #if JUCE_INCLUDED_FILE && JUCE_OPENGL
  186062. #define WGL_EXT_FUNCTION_INIT(extType, extFunc) \
  186063. ((extFunc = (extType) wglGetProcAddress (#extFunc)) != 0)
  186064. typedef const char* (WINAPI* PFNWGLGETEXTENSIONSSTRINGARBPROC) (HDC hdc);
  186065. typedef BOOL (WINAPI * PFNWGLGETPIXELFORMATATTRIBIVARBPROC) (HDC hdc, int iPixelFormat, int iLayerPlane, UINT nAttributes, const int *piAttributes, int *piValues);
  186066. typedef BOOL (WINAPI * PFNWGLCHOOSEPIXELFORMATARBPROC) (HDC hdc, const int* piAttribIList, const FLOAT *pfAttribFList, UINT nMaxFormats, int *piFormats, UINT *nNumFormats);
  186067. typedef BOOL (WINAPI * PFNWGLSWAPINTERVALEXTPROC) (int interval);
  186068. typedef int (WINAPI * PFNWGLGETSWAPINTERVALEXTPROC) (void);
  186069. #define WGL_NUMBER_PIXEL_FORMATS_ARB 0x2000
  186070. #define WGL_DRAW_TO_WINDOW_ARB 0x2001
  186071. #define WGL_ACCELERATION_ARB 0x2003
  186072. #define WGL_SWAP_METHOD_ARB 0x2007
  186073. #define WGL_SUPPORT_OPENGL_ARB 0x2010
  186074. #define WGL_PIXEL_TYPE_ARB 0x2013
  186075. #define WGL_DOUBLE_BUFFER_ARB 0x2011
  186076. #define WGL_COLOR_BITS_ARB 0x2014
  186077. #define WGL_RED_BITS_ARB 0x2015
  186078. #define WGL_GREEN_BITS_ARB 0x2017
  186079. #define WGL_BLUE_BITS_ARB 0x2019
  186080. #define WGL_ALPHA_BITS_ARB 0x201B
  186081. #define WGL_DEPTH_BITS_ARB 0x2022
  186082. #define WGL_STENCIL_BITS_ARB 0x2023
  186083. #define WGL_FULL_ACCELERATION_ARB 0x2027
  186084. #define WGL_ACCUM_RED_BITS_ARB 0x201E
  186085. #define WGL_ACCUM_GREEN_BITS_ARB 0x201F
  186086. #define WGL_ACCUM_BLUE_BITS_ARB 0x2020
  186087. #define WGL_ACCUM_ALPHA_BITS_ARB 0x2021
  186088. #define WGL_STEREO_ARB 0x2012
  186089. #define WGL_SAMPLE_BUFFERS_ARB 0x2041
  186090. #define WGL_SAMPLES_ARB 0x2042
  186091. #define WGL_TYPE_RGBA_ARB 0x202B
  186092. static void getWglExtensions (HDC dc, StringArray& result) throw()
  186093. {
  186094. PFNWGLGETEXTENSIONSSTRINGARBPROC wglGetExtensionsStringARB = 0;
  186095. if (WGL_EXT_FUNCTION_INIT (PFNWGLGETEXTENSIONSSTRINGARBPROC, wglGetExtensionsStringARB))
  186096. result.addTokens (String (wglGetExtensionsStringARB (dc)), false);
  186097. else
  186098. jassertfalse // If this fails, it may be because you didn't activate the openGL context
  186099. }
  186100. class WindowedGLContext : public OpenGLContext
  186101. {
  186102. public:
  186103. WindowedGLContext (Component* const component_,
  186104. HGLRC contextToShareWith,
  186105. const OpenGLPixelFormat& pixelFormat)
  186106. : renderContext (0),
  186107. nativeWindow (0),
  186108. dc (0),
  186109. component (component_)
  186110. {
  186111. jassert (component != 0);
  186112. createNativeWindow();
  186113. // Use a default pixel format that should be supported everywhere
  186114. PIXELFORMATDESCRIPTOR pfd;
  186115. zerostruct (pfd);
  186116. pfd.nSize = sizeof (pfd);
  186117. pfd.nVersion = 1;
  186118. pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER;
  186119. pfd.iPixelType = PFD_TYPE_RGBA;
  186120. pfd.cColorBits = 24;
  186121. pfd.cDepthBits = 16;
  186122. const int format = ChoosePixelFormat (dc, &pfd);
  186123. if (format != 0)
  186124. SetPixelFormat (dc, format, &pfd);
  186125. renderContext = wglCreateContext (dc);
  186126. makeActive();
  186127. setPixelFormat (pixelFormat);
  186128. if (contextToShareWith != 0 && renderContext != 0)
  186129. wglShareLists (contextToShareWith, renderContext);
  186130. }
  186131. ~WindowedGLContext()
  186132. {
  186133. makeInactive();
  186134. wglDeleteContext (renderContext);
  186135. ReleaseDC ((HWND) nativeWindow->getNativeHandle(), dc);
  186136. delete nativeWindow;
  186137. }
  186138. bool makeActive() const throw()
  186139. {
  186140. jassert (renderContext != 0);
  186141. return wglMakeCurrent (dc, renderContext) != 0;
  186142. }
  186143. bool makeInactive() const throw()
  186144. {
  186145. return (! isActive()) || (wglMakeCurrent (0, 0) != 0);
  186146. }
  186147. bool isActive() const throw()
  186148. {
  186149. return wglGetCurrentContext() == renderContext;
  186150. }
  186151. const OpenGLPixelFormat getPixelFormat() const
  186152. {
  186153. OpenGLPixelFormat pf;
  186154. makeActive();
  186155. StringArray availableExtensions;
  186156. getWglExtensions (dc, availableExtensions);
  186157. fillInPixelFormatDetails (GetPixelFormat (dc), pf, availableExtensions);
  186158. return pf;
  186159. }
  186160. void* getRawContext() const throw()
  186161. {
  186162. return renderContext;
  186163. }
  186164. bool setPixelFormat (const OpenGLPixelFormat& pixelFormat)
  186165. {
  186166. makeActive();
  186167. PIXELFORMATDESCRIPTOR pfd;
  186168. zerostruct (pfd);
  186169. pfd.nSize = sizeof (pfd);
  186170. pfd.nVersion = 1;
  186171. pfd.dwFlags = PFD_SUPPORT_OPENGL | PFD_DRAW_TO_WINDOW | PFD_DOUBLEBUFFER;
  186172. pfd.iPixelType = PFD_TYPE_RGBA;
  186173. pfd.iLayerType = PFD_MAIN_PLANE;
  186174. pfd.cColorBits = (BYTE) (pixelFormat.redBits + pixelFormat.greenBits + pixelFormat.blueBits);
  186175. pfd.cRedBits = (BYTE) pixelFormat.redBits;
  186176. pfd.cGreenBits = (BYTE) pixelFormat.greenBits;
  186177. pfd.cBlueBits = (BYTE) pixelFormat.blueBits;
  186178. pfd.cAlphaBits = (BYTE) pixelFormat.alphaBits;
  186179. pfd.cDepthBits = (BYTE) pixelFormat.depthBufferBits;
  186180. pfd.cStencilBits = (BYTE) pixelFormat.stencilBufferBits;
  186181. pfd.cAccumBits = (BYTE) (pixelFormat.accumulationBufferRedBits + pixelFormat.accumulationBufferGreenBits
  186182. + pixelFormat.accumulationBufferBlueBits + pixelFormat.accumulationBufferAlphaBits);
  186183. pfd.cAccumRedBits = (BYTE) pixelFormat.accumulationBufferRedBits;
  186184. pfd.cAccumGreenBits = (BYTE) pixelFormat.accumulationBufferGreenBits;
  186185. pfd.cAccumBlueBits = (BYTE) pixelFormat.accumulationBufferBlueBits;
  186186. pfd.cAccumAlphaBits = (BYTE) pixelFormat.accumulationBufferAlphaBits;
  186187. int format = 0;
  186188. PFNWGLCHOOSEPIXELFORMATARBPROC wglChoosePixelFormatARB = 0;
  186189. StringArray availableExtensions;
  186190. getWglExtensions (dc, availableExtensions);
  186191. if (availableExtensions.contains ("WGL_ARB_pixel_format")
  186192. && WGL_EXT_FUNCTION_INIT (PFNWGLCHOOSEPIXELFORMATARBPROC, wglChoosePixelFormatARB))
  186193. {
  186194. int attributes[64];
  186195. int n = 0;
  186196. attributes[n++] = WGL_DRAW_TO_WINDOW_ARB;
  186197. attributes[n++] = GL_TRUE;
  186198. attributes[n++] = WGL_SUPPORT_OPENGL_ARB;
  186199. attributes[n++] = GL_TRUE;
  186200. attributes[n++] = WGL_ACCELERATION_ARB;
  186201. attributes[n++] = WGL_FULL_ACCELERATION_ARB;
  186202. attributes[n++] = WGL_DOUBLE_BUFFER_ARB;
  186203. attributes[n++] = GL_TRUE;
  186204. attributes[n++] = WGL_PIXEL_TYPE_ARB;
  186205. attributes[n++] = WGL_TYPE_RGBA_ARB;
  186206. attributes[n++] = WGL_COLOR_BITS_ARB;
  186207. attributes[n++] = pfd.cColorBits;
  186208. attributes[n++] = WGL_RED_BITS_ARB;
  186209. attributes[n++] = pixelFormat.redBits;
  186210. attributes[n++] = WGL_GREEN_BITS_ARB;
  186211. attributes[n++] = pixelFormat.greenBits;
  186212. attributes[n++] = WGL_BLUE_BITS_ARB;
  186213. attributes[n++] = pixelFormat.blueBits;
  186214. attributes[n++] = WGL_ALPHA_BITS_ARB;
  186215. attributes[n++] = pixelFormat.alphaBits;
  186216. attributes[n++] = WGL_DEPTH_BITS_ARB;
  186217. attributes[n++] = pixelFormat.depthBufferBits;
  186218. if (pixelFormat.stencilBufferBits > 0)
  186219. {
  186220. attributes[n++] = WGL_STENCIL_BITS_ARB;
  186221. attributes[n++] = pixelFormat.stencilBufferBits;
  186222. }
  186223. attributes[n++] = WGL_ACCUM_RED_BITS_ARB;
  186224. attributes[n++] = pixelFormat.accumulationBufferRedBits;
  186225. attributes[n++] = WGL_ACCUM_GREEN_BITS_ARB;
  186226. attributes[n++] = pixelFormat.accumulationBufferGreenBits;
  186227. attributes[n++] = WGL_ACCUM_BLUE_BITS_ARB;
  186228. attributes[n++] = pixelFormat.accumulationBufferBlueBits;
  186229. attributes[n++] = WGL_ACCUM_ALPHA_BITS_ARB;
  186230. attributes[n++] = pixelFormat.accumulationBufferAlphaBits;
  186231. if (availableExtensions.contains ("WGL_ARB_multisample")
  186232. && pixelFormat.fullSceneAntiAliasingNumSamples > 0)
  186233. {
  186234. attributes[n++] = WGL_SAMPLE_BUFFERS_ARB;
  186235. attributes[n++] = 1;
  186236. attributes[n++] = WGL_SAMPLES_ARB;
  186237. attributes[n++] = pixelFormat.fullSceneAntiAliasingNumSamples;
  186238. }
  186239. attributes[n++] = 0;
  186240. UINT formatsCount;
  186241. const BOOL ok = wglChoosePixelFormatARB (dc, attributes, 0, 1, &format, &formatsCount);
  186242. (void) ok;
  186243. jassert (ok);
  186244. }
  186245. else
  186246. {
  186247. format = ChoosePixelFormat (dc, &pfd);
  186248. }
  186249. if (format != 0)
  186250. {
  186251. makeInactive();
  186252. // win32 can't change the pixel format of a window, so need to delete the
  186253. // old one and create a new one..
  186254. jassert (nativeWindow != 0);
  186255. ReleaseDC ((HWND) nativeWindow->getNativeHandle(), dc);
  186256. delete nativeWindow;
  186257. createNativeWindow();
  186258. if (SetPixelFormat (dc, format, &pfd))
  186259. {
  186260. wglDeleteContext (renderContext);
  186261. renderContext = wglCreateContext (dc);
  186262. jassert (renderContext != 0);
  186263. return renderContext != 0;
  186264. }
  186265. }
  186266. return false;
  186267. }
  186268. void updateWindowPosition (int x, int y, int w, int h, int)
  186269. {
  186270. SetWindowPos ((HWND) nativeWindow->getNativeHandle(), 0,
  186271. x, y, w, h,
  186272. SWP_NOACTIVATE | SWP_NOZORDER | SWP_NOOWNERZORDER);
  186273. }
  186274. void repaint()
  186275. {
  186276. int x, y, w, h;
  186277. nativeWindow->getBounds (x, y, w, h);
  186278. nativeWindow->repaint (0, 0, w, h);
  186279. }
  186280. void swapBuffers()
  186281. {
  186282. SwapBuffers (dc);
  186283. }
  186284. bool setSwapInterval (const int numFramesPerSwap)
  186285. {
  186286. makeActive();
  186287. StringArray availableExtensions;
  186288. getWglExtensions (dc, availableExtensions);
  186289. PFNWGLSWAPINTERVALEXTPROC wglSwapIntervalEXT = 0;
  186290. return availableExtensions.contains ("WGL_EXT_swap_control")
  186291. && WGL_EXT_FUNCTION_INIT (PFNWGLSWAPINTERVALEXTPROC, wglSwapIntervalEXT)
  186292. && wglSwapIntervalEXT (numFramesPerSwap) != FALSE;
  186293. }
  186294. int getSwapInterval() const
  186295. {
  186296. makeActive();
  186297. StringArray availableExtensions;
  186298. getWglExtensions (dc, availableExtensions);
  186299. PFNWGLGETSWAPINTERVALEXTPROC wglGetSwapIntervalEXT = 0;
  186300. if (availableExtensions.contains ("WGL_EXT_swap_control")
  186301. && WGL_EXT_FUNCTION_INIT (PFNWGLGETSWAPINTERVALEXTPROC, wglGetSwapIntervalEXT))
  186302. return wglGetSwapIntervalEXT();
  186303. return 0;
  186304. }
  186305. void findAlternativeOpenGLPixelFormats (OwnedArray <OpenGLPixelFormat>& results)
  186306. {
  186307. jassert (isActive());
  186308. StringArray availableExtensions;
  186309. getWglExtensions (dc, availableExtensions);
  186310. PFNWGLGETPIXELFORMATATTRIBIVARBPROC wglGetPixelFormatAttribivARB = 0;
  186311. int numTypes = 0;
  186312. if (availableExtensions.contains("WGL_ARB_pixel_format")
  186313. && WGL_EXT_FUNCTION_INIT (PFNWGLGETPIXELFORMATATTRIBIVARBPROC, wglGetPixelFormatAttribivARB))
  186314. {
  186315. int attributes = WGL_NUMBER_PIXEL_FORMATS_ARB;
  186316. if (! wglGetPixelFormatAttribivARB (dc, 1, 0, 1, &attributes, &numTypes))
  186317. jassertfalse
  186318. }
  186319. else
  186320. {
  186321. numTypes = DescribePixelFormat (dc, 0, 0, 0);
  186322. }
  186323. OpenGLPixelFormat pf;
  186324. for (int i = 0; i < numTypes; ++i)
  186325. {
  186326. if (fillInPixelFormatDetails (i + 1, pf, availableExtensions))
  186327. {
  186328. bool alreadyListed = false;
  186329. for (int j = results.size(); --j >= 0;)
  186330. if (pf == *results.getUnchecked(j))
  186331. alreadyListed = true;
  186332. if (! alreadyListed)
  186333. results.add (new OpenGLPixelFormat (pf));
  186334. }
  186335. }
  186336. }
  186337. void* getNativeWindowHandle() const
  186338. {
  186339. return nativeWindow != 0 ? nativeWindow->getNativeHandle() : 0;
  186340. }
  186341. juce_UseDebuggingNewOperator
  186342. HGLRC renderContext;
  186343. private:
  186344. Win32ComponentPeer* nativeWindow;
  186345. Component* const component;
  186346. HDC dc;
  186347. void createNativeWindow()
  186348. {
  186349. nativeWindow = new Win32ComponentPeer (component, 0);
  186350. nativeWindow->dontRepaint = true;
  186351. nativeWindow->setVisible (true);
  186352. HWND hwnd = (HWND) nativeWindow->getNativeHandle();
  186353. Win32ComponentPeer* const peer = dynamic_cast <Win32ComponentPeer*> (component->getTopLevelComponent()->getPeer());
  186354. if (peer != 0)
  186355. {
  186356. SetParent (hwnd, (HWND) peer->getNativeHandle());
  186357. juce_setWindowStyleBit (hwnd, GWL_STYLE, WS_CHILD, true);
  186358. juce_setWindowStyleBit (hwnd, GWL_STYLE, WS_POPUP, false);
  186359. }
  186360. dc = GetDC (hwnd);
  186361. }
  186362. bool fillInPixelFormatDetails (const int pixelFormatIndex,
  186363. OpenGLPixelFormat& result,
  186364. const StringArray& availableExtensions) const throw()
  186365. {
  186366. PFNWGLGETPIXELFORMATATTRIBIVARBPROC wglGetPixelFormatAttribivARB = 0;
  186367. if (availableExtensions.contains ("WGL_ARB_pixel_format")
  186368. && WGL_EXT_FUNCTION_INIT (PFNWGLGETPIXELFORMATATTRIBIVARBPROC, wglGetPixelFormatAttribivARB))
  186369. {
  186370. int attributes[32];
  186371. int numAttributes = 0;
  186372. attributes[numAttributes++] = WGL_DRAW_TO_WINDOW_ARB;
  186373. attributes[numAttributes++] = WGL_SUPPORT_OPENGL_ARB;
  186374. attributes[numAttributes++] = WGL_ACCELERATION_ARB;
  186375. attributes[numAttributes++] = WGL_DOUBLE_BUFFER_ARB;
  186376. attributes[numAttributes++] = WGL_PIXEL_TYPE_ARB;
  186377. attributes[numAttributes++] = WGL_RED_BITS_ARB;
  186378. attributes[numAttributes++] = WGL_GREEN_BITS_ARB;
  186379. attributes[numAttributes++] = WGL_BLUE_BITS_ARB;
  186380. attributes[numAttributes++] = WGL_ALPHA_BITS_ARB;
  186381. attributes[numAttributes++] = WGL_DEPTH_BITS_ARB;
  186382. attributes[numAttributes++] = WGL_STENCIL_BITS_ARB;
  186383. attributes[numAttributes++] = WGL_ACCUM_RED_BITS_ARB;
  186384. attributes[numAttributes++] = WGL_ACCUM_GREEN_BITS_ARB;
  186385. attributes[numAttributes++] = WGL_ACCUM_BLUE_BITS_ARB;
  186386. attributes[numAttributes++] = WGL_ACCUM_ALPHA_BITS_ARB;
  186387. if (availableExtensions.contains ("WGL_ARB_multisample"))
  186388. attributes[numAttributes++] = WGL_SAMPLES_ARB;
  186389. int values[32];
  186390. zeromem (values, sizeof (values));
  186391. if (wglGetPixelFormatAttribivARB (dc, pixelFormatIndex, 0, numAttributes, attributes, values))
  186392. {
  186393. int n = 0;
  186394. bool isValidFormat = (values[n++] == GL_TRUE); // WGL_DRAW_TO_WINDOW_ARB
  186395. isValidFormat = (values[n++] == GL_TRUE) && isValidFormat; // WGL_SUPPORT_OPENGL_ARB
  186396. isValidFormat = (values[n++] == WGL_FULL_ACCELERATION_ARB) && isValidFormat; // WGL_ACCELERATION_ARB
  186397. isValidFormat = (values[n++] == GL_TRUE) && isValidFormat; // WGL_DOUBLE_BUFFER_ARB:
  186398. isValidFormat = (values[n++] == WGL_TYPE_RGBA_ARB) && isValidFormat; // WGL_PIXEL_TYPE_ARB
  186399. result.redBits = values[n++]; // WGL_RED_BITS_ARB
  186400. result.greenBits = values[n++]; // WGL_GREEN_BITS_ARB
  186401. result.blueBits = values[n++]; // WGL_BLUE_BITS_ARB
  186402. result.alphaBits = values[n++]; // WGL_ALPHA_BITS_ARB
  186403. result.depthBufferBits = values[n++]; // WGL_DEPTH_BITS_ARB
  186404. result.stencilBufferBits = values[n++]; // WGL_STENCIL_BITS_ARB
  186405. result.accumulationBufferRedBits = values[n++]; // WGL_ACCUM_RED_BITS_ARB
  186406. result.accumulationBufferGreenBits = values[n++]; // WGL_ACCUM_GREEN_BITS_ARB
  186407. result.accumulationBufferBlueBits = values[n++]; // WGL_ACCUM_BLUE_BITS_ARB
  186408. result.accumulationBufferAlphaBits = values[n++]; // WGL_ACCUM_ALPHA_BITS_ARB
  186409. result.fullSceneAntiAliasingNumSamples = (uint8) values[n++]; // WGL_SAMPLES_ARB
  186410. return isValidFormat;
  186411. }
  186412. else
  186413. {
  186414. jassertfalse
  186415. }
  186416. }
  186417. else
  186418. {
  186419. PIXELFORMATDESCRIPTOR pfd;
  186420. if (DescribePixelFormat (dc, pixelFormatIndex, sizeof (pfd), &pfd))
  186421. {
  186422. result.redBits = pfd.cRedBits;
  186423. result.greenBits = pfd.cGreenBits;
  186424. result.blueBits = pfd.cBlueBits;
  186425. result.alphaBits = pfd.cAlphaBits;
  186426. result.depthBufferBits = pfd.cDepthBits;
  186427. result.stencilBufferBits = pfd.cStencilBits;
  186428. result.accumulationBufferRedBits = pfd.cAccumRedBits;
  186429. result.accumulationBufferGreenBits = pfd.cAccumGreenBits;
  186430. result.accumulationBufferBlueBits = pfd.cAccumBlueBits;
  186431. result.accumulationBufferAlphaBits = pfd.cAccumAlphaBits;
  186432. result.fullSceneAntiAliasingNumSamples = 0;
  186433. return true;
  186434. }
  186435. else
  186436. {
  186437. jassertfalse
  186438. }
  186439. }
  186440. return false;
  186441. }
  186442. WindowedGLContext (const WindowedGLContext&);
  186443. const WindowedGLContext& operator= (const WindowedGLContext&);
  186444. };
  186445. OpenGLContext* OpenGLContext::createContextForWindow (Component* const component,
  186446. const OpenGLPixelFormat& pixelFormat,
  186447. const OpenGLContext* const contextToShareWith)
  186448. {
  186449. WindowedGLContext* c = new WindowedGLContext (component,
  186450. contextToShareWith != 0 ? (HGLRC) contextToShareWith->getRawContext() : 0,
  186451. pixelFormat);
  186452. if (c->renderContext == 0)
  186453. deleteAndZero (c);
  186454. return c;
  186455. }
  186456. void* OpenGLComponent::getNativeWindowHandle() const
  186457. {
  186458. return context != 0 ? ((WindowedGLContext*) context)->getNativeWindowHandle() : 0;
  186459. }
  186460. void juce_glViewport (const int w, const int h)
  186461. {
  186462. glViewport (0, 0, w, h);
  186463. }
  186464. void OpenGLPixelFormat::getAvailablePixelFormats (Component* component,
  186465. OwnedArray <OpenGLPixelFormat>& results)
  186466. {
  186467. Component tempComp;
  186468. {
  186469. WindowedGLContext wc (component, 0, OpenGLPixelFormat (8, 8, 16, 0));
  186470. wc.makeActive();
  186471. wc.findAlternativeOpenGLPixelFormats (results);
  186472. }
  186473. }
  186474. #endif
  186475. /********* End of inlined file: juce_win32_OpenGLComponent.cpp *********/
  186476. /********* Start of inlined file: juce_win32_AudioCDReader.cpp *********/
  186477. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  186478. // compiled on its own).
  186479. #if JUCE_INCLUDED_FILE
  186480. #if JUCE_USE_CDREADER
  186481. //***************************************************************************
  186482. // %%% TARGET STATUS VALUES %%%
  186483. //***************************************************************************
  186484. #define STATUS_GOOD 0x00 // Status Good
  186485. #define STATUS_CHKCOND 0x02 // Check Condition
  186486. #define STATUS_CONDMET 0x04 // Condition Met
  186487. #define STATUS_BUSY 0x08 // Busy
  186488. #define STATUS_INTERM 0x10 // Intermediate
  186489. #define STATUS_INTCDMET 0x14 // Intermediate-condition met
  186490. #define STATUS_RESCONF 0x18 // Reservation conflict
  186491. #define STATUS_COMTERM 0x22 // Command Terminated
  186492. #define STATUS_QFULL 0x28 // Queue full
  186493. //***************************************************************************
  186494. // %%% SCSI MISCELLANEOUS EQUATES %%%
  186495. //***************************************************************************
  186496. #define MAXLUN 7 // Maximum Logical Unit Id
  186497. #define MAXTARG 7 // Maximum Target Id
  186498. #define MAX_SCSI_LUNS 64 // Maximum Number of SCSI LUNs
  186499. #define MAX_NUM_HA 8 // Maximum Number of SCSI HA's
  186500. //***************************************************************************
  186501. // %%% Commands for all Device Types %%%
  186502. //***************************************************************************
  186503. #define SCSI_CHANGE_DEF 0x40 // Change Definition (Optional)
  186504. #define SCSI_COMPARE 0x39 // Compare (O)
  186505. #define SCSI_COPY 0x18 // Copy (O)
  186506. #define SCSI_COP_VERIFY 0x3A // Copy and Verify (O)
  186507. #define SCSI_INQUIRY 0x12 // Inquiry (MANDATORY)
  186508. #define SCSI_LOG_SELECT 0x4C // Log Select (O)
  186509. #define SCSI_LOG_SENSE 0x4D // Log Sense (O)
  186510. #define SCSI_MODE_SEL6 0x15 // Mode Select 6-byte (Device Specific)
  186511. #define SCSI_MODE_SEL10 0x55 // Mode Select 10-byte (Device Specific)
  186512. #define SCSI_MODE_SEN6 0x1A // Mode Sense 6-byte (Device Specific)
  186513. #define SCSI_MODE_SEN10 0x5A // Mode Sense 10-byte (Device Specific)
  186514. #define SCSI_READ_BUFF 0x3C // Read Buffer (O)
  186515. #define SCSI_REQ_SENSE 0x03 // Request Sense (MANDATORY)
  186516. #define SCSI_SEND_DIAG 0x1D // Send Diagnostic (O)
  186517. #define SCSI_TST_U_RDY 0x00 // Test Unit Ready (MANDATORY)
  186518. #define SCSI_WRITE_BUFF 0x3B // Write Buffer (O)
  186519. //***************************************************************************
  186520. // %%% Commands Unique to Direct Access Devices %%%
  186521. //***************************************************************************
  186522. #define SCSI_COMPARE 0x39 // Compare (O)
  186523. #define SCSI_FORMAT 0x04 // Format Unit (MANDATORY)
  186524. #define SCSI_LCK_UN_CAC 0x36 // Lock Unlock Cache (O)
  186525. #define SCSI_PREFETCH 0x34 // Prefetch (O)
  186526. #define SCSI_MED_REMOVL 0x1E // Prevent/Allow medium Removal (O)
  186527. #define SCSI_READ6 0x08 // Read 6-byte (MANDATORY)
  186528. #define SCSI_READ10 0x28 // Read 10-byte (MANDATORY)
  186529. #define SCSI_RD_CAPAC 0x25 // Read Capacity (MANDATORY)
  186530. #define SCSI_RD_DEFECT 0x37 // Read Defect Data (O)
  186531. #define SCSI_READ_LONG 0x3E // Read Long (O)
  186532. #define SCSI_REASS_BLK 0x07 // Reassign Blocks (O)
  186533. #define SCSI_RCV_DIAG 0x1C // Receive Diagnostic Results (O)
  186534. #define SCSI_RELEASE 0x17 // Release Unit (MANDATORY)
  186535. #define SCSI_REZERO 0x01 // Rezero Unit (O)
  186536. #define SCSI_SRCH_DAT_E 0x31 // Search Data Equal (O)
  186537. #define SCSI_SRCH_DAT_H 0x30 // Search Data High (O)
  186538. #define SCSI_SRCH_DAT_L 0x32 // Search Data Low (O)
  186539. #define SCSI_SEEK6 0x0B // Seek 6-Byte (O)
  186540. #define SCSI_SEEK10 0x2B // Seek 10-Byte (O)
  186541. #define SCSI_SEND_DIAG 0x1D // Send Diagnostics (MANDATORY)
  186542. #define SCSI_SET_LIMIT 0x33 // Set Limits (O)
  186543. #define SCSI_START_STP 0x1B // Start/Stop Unit (O)
  186544. #define SCSI_SYNC_CACHE 0x35 // Synchronize Cache (O)
  186545. #define SCSI_VERIFY 0x2F // Verify (O)
  186546. #define SCSI_WRITE6 0x0A // Write 6-Byte (MANDATORY)
  186547. #define SCSI_WRITE10 0x2A // Write 10-Byte (MANDATORY)
  186548. #define SCSI_WRT_VERIFY 0x2E // Write and Verify (O)
  186549. #define SCSI_WRITE_LONG 0x3F // Write Long (O)
  186550. #define SCSI_WRITE_SAME 0x41 // Write Same (O)
  186551. //***************************************************************************
  186552. // %%% Commands Unique to Sequential Access Devices %%%
  186553. //***************************************************************************
  186554. #define SCSI_ERASE 0x19 // Erase (MANDATORY)
  186555. #define SCSI_LOAD_UN 0x1b // Load/Unload (O)
  186556. #define SCSI_LOCATE 0x2B // Locate (O)
  186557. #define SCSI_RD_BLK_LIM 0x05 // Read Block Limits (MANDATORY)
  186558. #define SCSI_READ_POS 0x34 // Read Position (O)
  186559. #define SCSI_READ_REV 0x0F // Read Reverse (O)
  186560. #define SCSI_REC_BF_DAT 0x14 // Recover Buffer Data (O)
  186561. #define SCSI_RESERVE 0x16 // Reserve Unit (MANDATORY)
  186562. #define SCSI_REWIND 0x01 // Rewind (MANDATORY)
  186563. #define SCSI_SPACE 0x11 // Space (MANDATORY)
  186564. #define SCSI_VERIFY_T 0x13 // Verify (Tape) (O)
  186565. #define SCSI_WRT_FILE 0x10 // Write Filemarks (MANDATORY)
  186566. //***************************************************************************
  186567. // %%% Commands Unique to Printer Devices %%%
  186568. //***************************************************************************
  186569. #define SCSI_PRINT 0x0A // Print (MANDATORY)
  186570. #define SCSI_SLEW_PNT 0x0B // Slew and Print (O)
  186571. #define SCSI_STOP_PNT 0x1B // Stop Print (O)
  186572. #define SCSI_SYNC_BUFF 0x10 // Synchronize Buffer (O)
  186573. //***************************************************************************
  186574. // %%% Commands Unique to Processor Devices %%%
  186575. //***************************************************************************
  186576. #define SCSI_RECEIVE 0x08 // Receive (O)
  186577. #define SCSI_SEND 0x0A // Send (O)
  186578. //***************************************************************************
  186579. // %%% Commands Unique to Write-Once Devices %%%
  186580. //***************************************************************************
  186581. #define SCSI_MEDIUM_SCN 0x38 // Medium Scan (O)
  186582. #define SCSI_SRCHDATE10 0x31 // Search Data Equal 10-Byte (O)
  186583. #define SCSI_SRCHDATE12 0xB1 // Search Data Equal 12-Byte (O)
  186584. #define SCSI_SRCHDATH10 0x30 // Search Data High 10-Byte (O)
  186585. #define SCSI_SRCHDATH12 0xB0 // Search Data High 12-Byte (O)
  186586. #define SCSI_SRCHDATL10 0x32 // Search Data Low 10-Byte (O)
  186587. #define SCSI_SRCHDATL12 0xB2 // Search Data Low 12-Byte (O)
  186588. #define SCSI_SET_LIM_10 0x33 // Set Limits 10-Byte (O)
  186589. #define SCSI_SET_LIM_12 0xB3 // Set Limits 10-Byte (O)
  186590. #define SCSI_VERIFY10 0x2F // Verify 10-Byte (O)
  186591. #define SCSI_VERIFY12 0xAF // Verify 12-Byte (O)
  186592. #define SCSI_WRITE12 0xAA // Write 12-Byte (O)
  186593. #define SCSI_WRT_VER10 0x2E // Write and Verify 10-Byte (O)
  186594. #define SCSI_WRT_VER12 0xAE // Write and Verify 12-Byte (O)
  186595. //***************************************************************************
  186596. // %%% Commands Unique to CD-ROM Devices %%%
  186597. //***************************************************************************
  186598. #define SCSI_PLAYAUD_10 0x45 // Play Audio 10-Byte (O)
  186599. #define SCSI_PLAYAUD_12 0xA5 // Play Audio 12-Byte 12-Byte (O)
  186600. #define SCSI_PLAYAUDMSF 0x47 // Play Audio MSF (O)
  186601. #define SCSI_PLAYA_TKIN 0x48 // Play Audio Track/Index (O)
  186602. #define SCSI_PLYTKREL10 0x49 // Play Track Relative 10-Byte (O)
  186603. #define SCSI_PLYTKREL12 0xA9 // Play Track Relative 12-Byte (O)
  186604. #define SCSI_READCDCAP 0x25 // Read CD-ROM Capacity (MANDATORY)
  186605. #define SCSI_READHEADER 0x44 // Read Header (O)
  186606. #define SCSI_SUBCHANNEL 0x42 // Read Subchannel (O)
  186607. #define SCSI_READ_TOC 0x43 // Read TOC (O)
  186608. //***************************************************************************
  186609. // %%% Commands Unique to Scanner Devices %%%
  186610. //***************************************************************************
  186611. #define SCSI_GETDBSTAT 0x34 // Get Data Buffer Status (O)
  186612. #define SCSI_GETWINDOW 0x25 // Get Window (O)
  186613. #define SCSI_OBJECTPOS 0x31 // Object Postion (O)
  186614. #define SCSI_SCAN 0x1B // Scan (O)
  186615. #define SCSI_SETWINDOW 0x24 // Set Window (MANDATORY)
  186616. //***************************************************************************
  186617. // %%% Commands Unique to Optical Memory Devices %%%
  186618. //***************************************************************************
  186619. #define SCSI_UpdateBlk 0x3D // Update Block (O)
  186620. //***************************************************************************
  186621. // %%% Commands Unique to Medium Changer Devices %%%
  186622. //***************************************************************************
  186623. #define SCSI_EXCHMEDIUM 0xA6 // Exchange Medium (O)
  186624. #define SCSI_INITELSTAT 0x07 // Initialize Element Status (O)
  186625. #define SCSI_POSTOELEM 0x2B // Position to Element (O)
  186626. #define SCSI_REQ_VE_ADD 0xB5 // Request Volume Element Address (O)
  186627. #define SCSI_SENDVOLTAG 0xB6 // Send Volume Tag (O)
  186628. //***************************************************************************
  186629. // %%% Commands Unique to Communication Devices %%%
  186630. //***************************************************************************
  186631. #define SCSI_GET_MSG_6 0x08 // Get Message 6-Byte (MANDATORY)
  186632. #define SCSI_GET_MSG_10 0x28 // Get Message 10-Byte (O)
  186633. #define SCSI_GET_MSG_12 0xA8 // Get Message 12-Byte (O)
  186634. #define SCSI_SND_MSG_6 0x0A // Send Message 6-Byte (MANDATORY)
  186635. #define SCSI_SND_MSG_10 0x2A // Send Message 10-Byte (O)
  186636. #define SCSI_SND_MSG_12 0xAA // Send Message 12-Byte (O)
  186637. //***************************************************************************
  186638. // %%% Request Sense Data Format %%%
  186639. //***************************************************************************
  186640. typedef struct {
  186641. BYTE ErrorCode; // Error Code (70H or 71H)
  186642. BYTE SegmentNum; // Number of current segment descriptor
  186643. BYTE SenseKey; // Sense Key(See bit definitions too)
  186644. BYTE InfoByte0; // Information MSB
  186645. BYTE InfoByte1; // Information MID
  186646. BYTE InfoByte2; // Information MID
  186647. BYTE InfoByte3; // Information LSB
  186648. BYTE AddSenLen; // Additional Sense Length
  186649. BYTE ComSpecInf0; // Command Specific Information MSB
  186650. BYTE ComSpecInf1; // Command Specific Information MID
  186651. BYTE ComSpecInf2; // Command Specific Information MID
  186652. BYTE ComSpecInf3; // Command Specific Information LSB
  186653. BYTE AddSenseCode; // Additional Sense Code
  186654. BYTE AddSenQual; // Additional Sense Code Qualifier
  186655. BYTE FieldRepUCode; // Field Replaceable Unit Code
  186656. BYTE SenKeySpec15; // Sense Key Specific 15th byte
  186657. BYTE SenKeySpec16; // Sense Key Specific 16th byte
  186658. BYTE SenKeySpec17; // Sense Key Specific 17th byte
  186659. BYTE AddSenseBytes; // Additional Sense Bytes
  186660. } SENSE_DATA_FMT;
  186661. //***************************************************************************
  186662. // %%% REQUEST SENSE ERROR CODE %%%
  186663. //***************************************************************************
  186664. #define SERROR_CURRENT 0x70 // Current Errors
  186665. #define SERROR_DEFERED 0x71 // Deferred Errors
  186666. //***************************************************************************
  186667. // %%% REQUEST SENSE BIT DEFINITIONS %%%
  186668. //***************************************************************************
  186669. #define SENSE_VALID 0x80 // Byte 0 Bit 7
  186670. #define SENSE_FILEMRK 0x80 // Byte 2 Bit 7
  186671. #define SENSE_EOM 0x40 // Byte 2 Bit 6
  186672. #define SENSE_ILI 0x20 // Byte 2 Bit 5
  186673. //***************************************************************************
  186674. // %%% REQUEST SENSE SENSE KEY DEFINITIONS %%%
  186675. //***************************************************************************
  186676. #define KEY_NOSENSE 0x00 // No Sense
  186677. #define KEY_RECERROR 0x01 // Recovered Error
  186678. #define KEY_NOTREADY 0x02 // Not Ready
  186679. #define KEY_MEDIUMERR 0x03 // Medium Error
  186680. #define KEY_HARDERROR 0x04 // Hardware Error
  186681. #define KEY_ILLGLREQ 0x05 // Illegal Request
  186682. #define KEY_UNITATT 0x06 // Unit Attention
  186683. #define KEY_DATAPROT 0x07 // Data Protect
  186684. #define KEY_BLANKCHK 0x08 // Blank Check
  186685. #define KEY_VENDSPEC 0x09 // Vendor Specific
  186686. #define KEY_COPYABORT 0x0A // Copy Abort
  186687. #define KEY_EQUAL 0x0C // Equal (Search)
  186688. #define KEY_VOLOVRFLW 0x0D // Volume Overflow
  186689. #define KEY_MISCOMP 0x0E // Miscompare (Search)
  186690. #define KEY_RESERVED 0x0F // Reserved
  186691. //***************************************************************************
  186692. // %%% PERIPHERAL DEVICE TYPE DEFINITIONS %%%
  186693. //***************************************************************************
  186694. #define DTYPE_DASD 0x00 // Disk Device
  186695. #define DTYPE_SEQD 0x01 // Tape Device
  186696. #define DTYPE_PRNT 0x02 // Printer
  186697. #define DTYPE_PROC 0x03 // Processor
  186698. #define DTYPE_WORM 0x04 // Write-once read-multiple
  186699. #define DTYPE_CROM 0x05 // CD-ROM device
  186700. #define DTYPE_SCAN 0x06 // Scanner device
  186701. #define DTYPE_OPTI 0x07 // Optical memory device
  186702. #define DTYPE_JUKE 0x08 // Medium Changer device
  186703. #define DTYPE_COMM 0x09 // Communications device
  186704. #define DTYPE_RESL 0x0A // Reserved (low)
  186705. #define DTYPE_RESH 0x1E // Reserved (high)
  186706. #define DTYPE_UNKNOWN 0x1F // Unknown or no device type
  186707. //***************************************************************************
  186708. // %%% ANSI APPROVED VERSION DEFINITIONS %%%
  186709. //***************************************************************************
  186710. #define ANSI_MAYBE 0x0 // Device may or may not be ANSI approved stand
  186711. #define ANSI_SCSI1 0x1 // Device complies to ANSI X3.131-1986 (SCSI-1)
  186712. #define ANSI_SCSI2 0x2 // Device complies to SCSI-2
  186713. #define ANSI_RESLO 0x3 // Reserved (low)
  186714. #define ANSI_RESHI 0x7 // Reserved (high)
  186715. typedef struct
  186716. {
  186717. USHORT Length;
  186718. UCHAR ScsiStatus;
  186719. UCHAR PathId;
  186720. UCHAR TargetId;
  186721. UCHAR Lun;
  186722. UCHAR CdbLength;
  186723. UCHAR SenseInfoLength;
  186724. UCHAR DataIn;
  186725. ULONG DataTransferLength;
  186726. ULONG TimeOutValue;
  186727. ULONG DataBufferOffset;
  186728. ULONG SenseInfoOffset;
  186729. UCHAR Cdb[16];
  186730. } SCSI_PASS_THROUGH, *PSCSI_PASS_THROUGH;
  186731. typedef struct
  186732. {
  186733. USHORT Length;
  186734. UCHAR ScsiStatus;
  186735. UCHAR PathId;
  186736. UCHAR TargetId;
  186737. UCHAR Lun;
  186738. UCHAR CdbLength;
  186739. UCHAR SenseInfoLength;
  186740. UCHAR DataIn;
  186741. ULONG DataTransferLength;
  186742. ULONG TimeOutValue;
  186743. PVOID DataBuffer;
  186744. ULONG SenseInfoOffset;
  186745. UCHAR Cdb[16];
  186746. } SCSI_PASS_THROUGH_DIRECT, *PSCSI_PASS_THROUGH_DIRECT;
  186747. typedef struct
  186748. {
  186749. SCSI_PASS_THROUGH_DIRECT spt;
  186750. ULONG Filler;
  186751. UCHAR ucSenseBuf[32];
  186752. } SCSI_PASS_THROUGH_DIRECT_WITH_BUFFER, *PSCSI_PASS_THROUGH_DIRECT_WITH_BUFFER;
  186753. typedef struct
  186754. {
  186755. ULONG Length;
  186756. UCHAR PortNumber;
  186757. UCHAR PathId;
  186758. UCHAR TargetId;
  186759. UCHAR Lun;
  186760. } SCSI_ADDRESS, *PSCSI_ADDRESS;
  186761. #define METHOD_BUFFERED 0
  186762. #define METHOD_IN_DIRECT 1
  186763. #define METHOD_OUT_DIRECT 2
  186764. #define METHOD_NEITHER 3
  186765. #define FILE_ANY_ACCESS 0
  186766. #ifndef FILE_READ_ACCESS
  186767. #define FILE_READ_ACCESS (0x0001)
  186768. #endif
  186769. #ifndef FILE_WRITE_ACCESS
  186770. #define FILE_WRITE_ACCESS (0x0002)
  186771. #endif
  186772. #define IOCTL_SCSI_BASE 0x00000004
  186773. #define SCSI_IOCTL_DATA_OUT 0
  186774. #define SCSI_IOCTL_DATA_IN 1
  186775. #define SCSI_IOCTL_DATA_UNSPECIFIED 2
  186776. #define CTL_CODE2( DevType, Function, Method, Access ) ( \
  186777. ((DevType) << 16) | ((Access) << 14) | ((Function) << 2) | (Method) \
  186778. )
  186779. #define IOCTL_SCSI_PASS_THROUGH CTL_CODE2( IOCTL_SCSI_BASE, 0x0401, METHOD_BUFFERED, FILE_READ_ACCESS | FILE_WRITE_ACCESS )
  186780. #define IOCTL_SCSI_GET_CAPABILITIES CTL_CODE2( IOCTL_SCSI_BASE, 0x0404, METHOD_BUFFERED, FILE_ANY_ACCESS)
  186781. #define IOCTL_SCSI_PASS_THROUGH_DIRECT CTL_CODE2( IOCTL_SCSI_BASE, 0x0405, METHOD_BUFFERED, FILE_READ_ACCESS | FILE_WRITE_ACCESS )
  186782. #define IOCTL_SCSI_GET_ADDRESS CTL_CODE2( IOCTL_SCSI_BASE, 0x0406, METHOD_BUFFERED, FILE_ANY_ACCESS )
  186783. #define SENSE_LEN 14
  186784. #define SRB_DIR_SCSI 0x00
  186785. #define SRB_POSTING 0x01
  186786. #define SRB_ENABLE_RESIDUAL_COUNT 0x04
  186787. #define SRB_DIR_IN 0x08
  186788. #define SRB_DIR_OUT 0x10
  186789. #define SRB_EVENT_NOTIFY 0x40
  186790. #define RESIDUAL_COUNT_SUPPORTED 0x02
  186791. #define MAX_SRB_TIMEOUT 1080001u
  186792. #define DEFAULT_SRB_TIMEOUT 1080001u
  186793. #define SC_HA_INQUIRY 0x00
  186794. #define SC_GET_DEV_TYPE 0x01
  186795. #define SC_EXEC_SCSI_CMD 0x02
  186796. #define SC_ABORT_SRB 0x03
  186797. #define SC_RESET_DEV 0x04
  186798. #define SC_SET_HA_PARMS 0x05
  186799. #define SC_GET_DISK_INFO 0x06
  186800. #define SC_RESCAN_SCSI_BUS 0x07
  186801. #define SC_GETSET_TIMEOUTS 0x08
  186802. #define SS_PENDING 0x00
  186803. #define SS_COMP 0x01
  186804. #define SS_ABORTED 0x02
  186805. #define SS_ABORT_FAIL 0x03
  186806. #define SS_ERR 0x04
  186807. #define SS_INVALID_CMD 0x80
  186808. #define SS_INVALID_HA 0x81
  186809. #define SS_NO_DEVICE 0x82
  186810. #define SS_INVALID_SRB 0xE0
  186811. #define SS_OLD_MANAGER 0xE1
  186812. #define SS_BUFFER_ALIGN 0xE1
  186813. #define SS_ILLEGAL_MODE 0xE2
  186814. #define SS_NO_ASPI 0xE3
  186815. #define SS_FAILED_INIT 0xE4
  186816. #define SS_ASPI_IS_BUSY 0xE5
  186817. #define SS_BUFFER_TO_BIG 0xE6
  186818. #define SS_BUFFER_TOO_BIG 0xE6
  186819. #define SS_MISMATCHED_COMPONENTS 0xE7
  186820. #define SS_NO_ADAPTERS 0xE8
  186821. #define SS_INSUFFICIENT_RESOURCES 0xE9
  186822. #define SS_ASPI_IS_SHUTDOWN 0xEA
  186823. #define SS_BAD_INSTALL 0xEB
  186824. #define HASTAT_OK 0x00
  186825. #define HASTAT_SEL_TO 0x11
  186826. #define HASTAT_DO_DU 0x12
  186827. #define HASTAT_BUS_FREE 0x13
  186828. #define HASTAT_PHASE_ERR 0x14
  186829. #define HASTAT_TIMEOUT 0x09
  186830. #define HASTAT_COMMAND_TIMEOUT 0x0B
  186831. #define HASTAT_MESSAGE_REJECT 0x0D
  186832. #define HASTAT_BUS_RESET 0x0E
  186833. #define HASTAT_PARITY_ERROR 0x0F
  186834. #define HASTAT_REQUEST_SENSE_FAILED 0x10
  186835. #define PACKED
  186836. #pragma pack(1)
  186837. typedef struct
  186838. {
  186839. BYTE SRB_Cmd;
  186840. BYTE SRB_Status;
  186841. BYTE SRB_HaID;
  186842. BYTE SRB_Flags;
  186843. DWORD SRB_Hdr_Rsvd;
  186844. BYTE HA_Count;
  186845. BYTE HA_SCSI_ID;
  186846. BYTE HA_ManagerId[16];
  186847. BYTE HA_Identifier[16];
  186848. BYTE HA_Unique[16];
  186849. WORD HA_Rsvd1;
  186850. BYTE pad[20];
  186851. } PACKED SRB_HAInquiry, *PSRB_HAInquiry, FAR *LPSRB_HAInquiry;
  186852. typedef struct
  186853. {
  186854. BYTE SRB_Cmd;
  186855. BYTE SRB_Status;
  186856. BYTE SRB_HaID;
  186857. BYTE SRB_Flags;
  186858. DWORD SRB_Hdr_Rsvd;
  186859. BYTE SRB_Target;
  186860. BYTE SRB_Lun;
  186861. BYTE SRB_DeviceType;
  186862. BYTE SRB_Rsvd1;
  186863. BYTE pad[68];
  186864. } PACKED SRB_GDEVBlock, *PSRB_GDEVBlock, FAR *LPSRB_GDEVBlock;
  186865. typedef struct
  186866. {
  186867. BYTE SRB_Cmd;
  186868. BYTE SRB_Status;
  186869. BYTE SRB_HaID;
  186870. BYTE SRB_Flags;
  186871. DWORD SRB_Hdr_Rsvd;
  186872. BYTE SRB_Target;
  186873. BYTE SRB_Lun;
  186874. WORD SRB_Rsvd1;
  186875. DWORD SRB_BufLen;
  186876. BYTE FAR *SRB_BufPointer;
  186877. BYTE SRB_SenseLen;
  186878. BYTE SRB_CDBLen;
  186879. BYTE SRB_HaStat;
  186880. BYTE SRB_TargStat;
  186881. VOID FAR *SRB_PostProc;
  186882. BYTE SRB_Rsvd2[20];
  186883. BYTE CDBByte[16];
  186884. BYTE SenseArea[SENSE_LEN+2];
  186885. } PACKED SRB_ExecSCSICmd, *PSRB_ExecSCSICmd, FAR *LPSRB_ExecSCSICmd;
  186886. typedef struct
  186887. {
  186888. BYTE SRB_Cmd;
  186889. BYTE SRB_Status;
  186890. BYTE SRB_HaId;
  186891. BYTE SRB_Flags;
  186892. DWORD SRB_Hdr_Rsvd;
  186893. } PACKED SRB, *PSRB, FAR *LPSRB;
  186894. #pragma pack()
  186895. struct CDDeviceInfo
  186896. {
  186897. char vendor[9];
  186898. char productId[17];
  186899. char rev[5];
  186900. char vendorSpec[21];
  186901. BYTE ha;
  186902. BYTE tgt;
  186903. BYTE lun;
  186904. char scsiDriveLetter; // will be 0 if not using scsi
  186905. };
  186906. class CDReadBuffer
  186907. {
  186908. public:
  186909. int startFrame;
  186910. int numFrames;
  186911. int dataStartOffset;
  186912. int dataLength;
  186913. BYTE* buffer;
  186914. int bufferSize;
  186915. int index;
  186916. bool wantsIndex;
  186917. CDReadBuffer (const int numberOfFrames)
  186918. : startFrame (0),
  186919. numFrames (0),
  186920. dataStartOffset (0),
  186921. dataLength (0),
  186922. index (0),
  186923. wantsIndex (false)
  186924. {
  186925. bufferSize = 2352 * numberOfFrames;
  186926. buffer = (BYTE*) malloc (bufferSize);
  186927. }
  186928. ~CDReadBuffer()
  186929. {
  186930. free (buffer);
  186931. }
  186932. bool isZero() const
  186933. {
  186934. BYTE* p = buffer + dataStartOffset;
  186935. for (int i = dataLength; --i >= 0;)
  186936. if (*p++ != 0)
  186937. return false;
  186938. return true;
  186939. }
  186940. };
  186941. class CDDeviceHandle;
  186942. class CDController
  186943. {
  186944. public:
  186945. CDController();
  186946. virtual ~CDController();
  186947. virtual bool read (CDReadBuffer* t) = 0;
  186948. virtual void shutDown();
  186949. bool readAudio (CDReadBuffer* t, CDReadBuffer* overlapBuffer = 0);
  186950. int getLastIndex();
  186951. public:
  186952. bool initialised;
  186953. CDDeviceHandle* deviceInfo;
  186954. int framesToCheck, framesOverlap;
  186955. void prepare (SRB_ExecSCSICmd& s);
  186956. void perform (SRB_ExecSCSICmd& s);
  186957. void setPaused (bool paused);
  186958. };
  186959. #pragma pack(1)
  186960. struct TOCTRACK
  186961. {
  186962. BYTE rsvd;
  186963. BYTE ADR;
  186964. BYTE trackNumber;
  186965. BYTE rsvd2;
  186966. BYTE addr[4];
  186967. };
  186968. struct TOC
  186969. {
  186970. WORD tocLen;
  186971. BYTE firstTrack;
  186972. BYTE lastTrack;
  186973. TOCTRACK tracks[100];
  186974. };
  186975. #pragma pack()
  186976. enum
  186977. {
  186978. READTYPE_ANY = 0,
  186979. READTYPE_ATAPI1 = 1,
  186980. READTYPE_ATAPI2 = 2,
  186981. READTYPE_READ6 = 3,
  186982. READTYPE_READ10 = 4,
  186983. READTYPE_READ_D8 = 5,
  186984. READTYPE_READ_D4 = 6,
  186985. READTYPE_READ_D4_1 = 7,
  186986. READTYPE_READ10_2 = 8
  186987. };
  186988. class CDDeviceHandle
  186989. {
  186990. public:
  186991. CDDeviceHandle (const CDDeviceInfo* const device)
  186992. : scsiHandle (0),
  186993. readType (READTYPE_ANY),
  186994. controller (0)
  186995. {
  186996. memcpy (&info, device, sizeof (info));
  186997. }
  186998. ~CDDeviceHandle()
  186999. {
  187000. if (controller != 0)
  187001. {
  187002. controller->shutDown();
  187003. delete controller;
  187004. }
  187005. if (scsiHandle != 0)
  187006. CloseHandle (scsiHandle);
  187007. }
  187008. bool readTOC (TOC* lpToc, bool useMSF);
  187009. bool readAudio (CDReadBuffer* buffer, CDReadBuffer* overlapBuffer = 0);
  187010. void openDrawer (bool shouldBeOpen);
  187011. CDDeviceInfo info;
  187012. HANDLE scsiHandle;
  187013. BYTE readType;
  187014. private:
  187015. CDController* controller;
  187016. bool testController (const int readType,
  187017. CDController* const newController,
  187018. CDReadBuffer* const bufferToUse);
  187019. };
  187020. DWORD (*fGetASPI32SupportInfo)(void);
  187021. DWORD (*fSendASPI32Command)(LPSRB);
  187022. static HINSTANCE winAspiLib = 0;
  187023. static bool usingScsi = false;
  187024. static bool initialised = false;
  187025. static bool InitialiseCDRipper()
  187026. {
  187027. if (! initialised)
  187028. {
  187029. initialised = true;
  187030. OSVERSIONINFO info;
  187031. info.dwOSVersionInfoSize = sizeof (info);
  187032. GetVersionEx (&info);
  187033. usingScsi = (info.dwPlatformId == VER_PLATFORM_WIN32_NT) && (info.dwMajorVersion > 4);
  187034. if (! usingScsi)
  187035. {
  187036. fGetASPI32SupportInfo = 0;
  187037. fSendASPI32Command = 0;
  187038. winAspiLib = LoadLibrary (_T("WNASPI32.DLL"));
  187039. if (winAspiLib != 0)
  187040. {
  187041. fGetASPI32SupportInfo = (DWORD(*)(void)) GetProcAddress (winAspiLib, "GetASPI32SupportInfo");
  187042. fSendASPI32Command = (DWORD(*)(LPSRB)) GetProcAddress (winAspiLib, "SendASPI32Command");
  187043. if (fGetASPI32SupportInfo == 0 || fSendASPI32Command == 0)
  187044. return false;
  187045. }
  187046. else
  187047. {
  187048. usingScsi = true;
  187049. }
  187050. }
  187051. }
  187052. return true;
  187053. }
  187054. static void DeinitialiseCDRipper()
  187055. {
  187056. if (winAspiLib != 0)
  187057. {
  187058. fGetASPI32SupportInfo = 0;
  187059. fSendASPI32Command = 0;
  187060. FreeLibrary (winAspiLib);
  187061. winAspiLib = 0;
  187062. }
  187063. initialised = false;
  187064. }
  187065. static HANDLE CreateSCSIDeviceHandle (char driveLetter)
  187066. {
  187067. TCHAR devicePath[8];
  187068. devicePath[0] = '\\';
  187069. devicePath[1] = '\\';
  187070. devicePath[2] = '.';
  187071. devicePath[3] = '\\';
  187072. devicePath[4] = driveLetter;
  187073. devicePath[5] = ':';
  187074. devicePath[6] = 0;
  187075. OSVERSIONINFO info;
  187076. info.dwOSVersionInfoSize = sizeof (info);
  187077. GetVersionEx (&info);
  187078. DWORD flags = GENERIC_READ;
  187079. if ((info.dwPlatformId == VER_PLATFORM_WIN32_NT) && (info.dwMajorVersion > 4))
  187080. flags = GENERIC_READ | GENERIC_WRITE;
  187081. HANDLE h = CreateFile (devicePath, flags, FILE_SHARE_WRITE | FILE_SHARE_READ, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
  187082. if (h == INVALID_HANDLE_VALUE)
  187083. {
  187084. flags ^= GENERIC_WRITE;
  187085. h = CreateFile (devicePath, flags, FILE_SHARE_WRITE | FILE_SHARE_READ, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
  187086. }
  187087. return h;
  187088. }
  187089. static DWORD performScsiPassThroughCommand (const LPSRB_ExecSCSICmd srb,
  187090. const char driveLetter,
  187091. HANDLE& deviceHandle,
  187092. const bool retryOnFailure = true)
  187093. {
  187094. SCSI_PASS_THROUGH_DIRECT_WITH_BUFFER s;
  187095. zerostruct (s);
  187096. s.spt.Length = sizeof (SCSI_PASS_THROUGH);
  187097. s.spt.CdbLength = srb->SRB_CDBLen;
  187098. s.spt.DataIn = (BYTE) ((srb->SRB_Flags & SRB_DIR_IN)
  187099. ? SCSI_IOCTL_DATA_IN
  187100. : ((srb->SRB_Flags & SRB_DIR_OUT)
  187101. ? SCSI_IOCTL_DATA_OUT
  187102. : SCSI_IOCTL_DATA_UNSPECIFIED));
  187103. s.spt.DataTransferLength = srb->SRB_BufLen;
  187104. s.spt.TimeOutValue = 5;
  187105. s.spt.DataBuffer = srb->SRB_BufPointer;
  187106. s.spt.SenseInfoOffset = offsetof (SCSI_PASS_THROUGH_DIRECT_WITH_BUFFER, ucSenseBuf);
  187107. memcpy (s.spt.Cdb, srb->CDBByte, srb->SRB_CDBLen);
  187108. srb->SRB_Status = SS_ERR;
  187109. srb->SRB_TargStat = 0x0004;
  187110. DWORD bytesReturned = 0;
  187111. if (DeviceIoControl (deviceHandle, IOCTL_SCSI_PASS_THROUGH_DIRECT,
  187112. &s, sizeof (s),
  187113. &s, sizeof (s),
  187114. &bytesReturned, 0) != 0)
  187115. {
  187116. srb->SRB_Status = SS_COMP;
  187117. }
  187118. else if (retryOnFailure)
  187119. {
  187120. const DWORD error = GetLastError();
  187121. if ((error == ERROR_MEDIA_CHANGED) || (error == ERROR_INVALID_HANDLE))
  187122. {
  187123. if (error != ERROR_INVALID_HANDLE)
  187124. CloseHandle (deviceHandle);
  187125. deviceHandle = CreateSCSIDeviceHandle (driveLetter);
  187126. return performScsiPassThroughCommand (srb, driveLetter, deviceHandle, false);
  187127. }
  187128. }
  187129. return srb->SRB_Status;
  187130. }
  187131. // Controller types..
  187132. class ControllerType1 : public CDController
  187133. {
  187134. public:
  187135. ControllerType1() {}
  187136. ~ControllerType1() {}
  187137. bool read (CDReadBuffer* rb)
  187138. {
  187139. if (rb->numFrames * 2352 > rb->bufferSize)
  187140. return false;
  187141. SRB_ExecSCSICmd s;
  187142. prepare (s);
  187143. s.SRB_Flags = SRB_DIR_IN | SRB_EVENT_NOTIFY;
  187144. s.SRB_BufLen = rb->bufferSize;
  187145. s.SRB_BufPointer = rb->buffer;
  187146. s.SRB_CDBLen = 12;
  187147. s.CDBByte[0] = 0xBE;
  187148. s.CDBByte[3] = (BYTE)((rb->startFrame >> 16) & 0xFF);
  187149. s.CDBByte[4] = (BYTE)((rb->startFrame >> 8) & 0xFF);
  187150. s.CDBByte[5] = (BYTE)(rb->startFrame & 0xFF);
  187151. s.CDBByte[8] = (BYTE)(rb->numFrames & 0xFF);
  187152. s.CDBByte[9] = (BYTE)((deviceInfo->readType == READTYPE_ATAPI1) ? 0x10 : 0xF0);
  187153. perform (s);
  187154. if (s.SRB_Status != SS_COMP)
  187155. return false;
  187156. rb->dataLength = rb->numFrames * 2352;
  187157. rb->dataStartOffset = 0;
  187158. return true;
  187159. }
  187160. };
  187161. class ControllerType2 : public CDController
  187162. {
  187163. public:
  187164. ControllerType2() {}
  187165. ~ControllerType2() {}
  187166. void shutDown()
  187167. {
  187168. if (initialised)
  187169. {
  187170. BYTE bufPointer[] = { 0, 0, 0, 8, 83, 0, 0, 0, 0, 0, 8, 0 };
  187171. SRB_ExecSCSICmd s;
  187172. prepare (s);
  187173. s.SRB_Flags = SRB_EVENT_NOTIFY | SRB_ENABLE_RESIDUAL_COUNT;
  187174. s.SRB_BufLen = 0x0C;
  187175. s.SRB_BufPointer = bufPointer;
  187176. s.SRB_CDBLen = 6;
  187177. s.CDBByte[0] = 0x15;
  187178. s.CDBByte[4] = 0x0C;
  187179. perform (s);
  187180. }
  187181. }
  187182. bool init()
  187183. {
  187184. SRB_ExecSCSICmd s;
  187185. s.SRB_Status = SS_ERR;
  187186. if (deviceInfo->readType == READTYPE_READ10_2)
  187187. {
  187188. BYTE bufPointer1[] = { 0, 0, 0, 8, 0, 0, 0, 0, 0, 0, 9, 48, 35, 6, 0, 0, 0, 0, 0, 128 };
  187189. BYTE bufPointer2[] = { 0, 0, 0, 8, 0, 0, 0, 0, 0, 0, 9, 48, 1, 6, 32, 7, 0, 0, 0, 0 };
  187190. for (int i = 0; i < 2; ++i)
  187191. {
  187192. prepare (s);
  187193. s.SRB_Flags = SRB_EVENT_NOTIFY;
  187194. s.SRB_BufLen = 0x14;
  187195. s.SRB_BufPointer = (i == 0) ? bufPointer1 : bufPointer2;
  187196. s.SRB_CDBLen = 6;
  187197. s.CDBByte[0] = 0x15;
  187198. s.CDBByte[1] = 0x10;
  187199. s.CDBByte[4] = 0x14;
  187200. perform (s);
  187201. if (s.SRB_Status != SS_COMP)
  187202. return false;
  187203. }
  187204. }
  187205. else
  187206. {
  187207. BYTE bufPointer[] = { 0, 0, 0, 8, 0, 0, 0, 0, 0, 0, 9, 48 };
  187208. prepare (s);
  187209. s.SRB_Flags = SRB_EVENT_NOTIFY;
  187210. s.SRB_BufLen = 0x0C;
  187211. s.SRB_BufPointer = bufPointer;
  187212. s.SRB_CDBLen = 6;
  187213. s.CDBByte[0] = 0x15;
  187214. s.CDBByte[4] = 0x0C;
  187215. perform (s);
  187216. }
  187217. return s.SRB_Status == SS_COMP;
  187218. }
  187219. bool read (CDReadBuffer* rb)
  187220. {
  187221. if (rb->numFrames * 2352 > rb->bufferSize)
  187222. return false;
  187223. if (!initialised)
  187224. {
  187225. initialised = init();
  187226. if (!initialised)
  187227. return false;
  187228. }
  187229. SRB_ExecSCSICmd s;
  187230. prepare (s);
  187231. s.SRB_Flags = SRB_DIR_IN | SRB_EVENT_NOTIFY;
  187232. s.SRB_BufLen = rb->bufferSize;
  187233. s.SRB_BufPointer = rb->buffer;
  187234. s.SRB_CDBLen = 10;
  187235. s.CDBByte[0] = 0x28;
  187236. s.CDBByte[1] = (BYTE)(deviceInfo->info.lun << 5);
  187237. s.CDBByte[3] = (BYTE)((rb->startFrame >> 16) & 0xFF);
  187238. s.CDBByte[4] = (BYTE)((rb->startFrame >> 8) & 0xFF);
  187239. s.CDBByte[5] = (BYTE)(rb->startFrame & 0xFF);
  187240. s.CDBByte[8] = (BYTE)(rb->numFrames & 0xFF);
  187241. perform (s);
  187242. if (s.SRB_Status != SS_COMP)
  187243. return false;
  187244. rb->dataLength = rb->numFrames * 2352;
  187245. rb->dataStartOffset = 0;
  187246. return true;
  187247. }
  187248. };
  187249. class ControllerType3 : public CDController
  187250. {
  187251. public:
  187252. ControllerType3() {}
  187253. ~ControllerType3() {}
  187254. bool read (CDReadBuffer* rb)
  187255. {
  187256. if (rb->numFrames * 2352 > rb->bufferSize)
  187257. return false;
  187258. if (!initialised)
  187259. {
  187260. setPaused (false);
  187261. initialised = true;
  187262. }
  187263. SRB_ExecSCSICmd s;
  187264. prepare (s);
  187265. s.SRB_Flags = SRB_DIR_IN | SRB_EVENT_NOTIFY;
  187266. s.SRB_BufLen = rb->numFrames * 2352;
  187267. s.SRB_BufPointer = rb->buffer;
  187268. s.SRB_CDBLen = 12;
  187269. s.CDBByte[0] = 0xD8;
  187270. s.CDBByte[3] = (BYTE)((rb->startFrame >> 16) & 0xFF);
  187271. s.CDBByte[4] = (BYTE)((rb->startFrame >> 8) & 0xFF);
  187272. s.CDBByte[5] = (BYTE)(rb->startFrame & 0xFF);
  187273. s.CDBByte[9] = (BYTE)(rb->numFrames & 0xFF);
  187274. perform (s);
  187275. if (s.SRB_Status != SS_COMP)
  187276. return false;
  187277. rb->dataLength = rb->numFrames * 2352;
  187278. rb->dataStartOffset = 0;
  187279. return true;
  187280. }
  187281. };
  187282. class ControllerType4 : public CDController
  187283. {
  187284. public:
  187285. ControllerType4() {}
  187286. ~ControllerType4() {}
  187287. bool selectD4Mode()
  187288. {
  187289. BYTE bufPointer[12] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9, 48 };
  187290. SRB_ExecSCSICmd s;
  187291. prepare (s);
  187292. s.SRB_Flags = SRB_EVENT_NOTIFY;
  187293. s.SRB_CDBLen = 6;
  187294. s.SRB_BufLen = 12;
  187295. s.SRB_BufPointer = bufPointer;
  187296. s.CDBByte[0] = 0x15;
  187297. s.CDBByte[1] = 0x10;
  187298. s.CDBByte[4] = 0x08;
  187299. perform (s);
  187300. return s.SRB_Status == SS_COMP;
  187301. }
  187302. bool read (CDReadBuffer* rb)
  187303. {
  187304. if (rb->numFrames * 2352 > rb->bufferSize)
  187305. return false;
  187306. if (!initialised)
  187307. {
  187308. setPaused (true);
  187309. if (deviceInfo->readType == READTYPE_READ_D4_1)
  187310. selectD4Mode();
  187311. initialised = true;
  187312. }
  187313. SRB_ExecSCSICmd s;
  187314. prepare (s);
  187315. s.SRB_Flags = SRB_DIR_IN | SRB_EVENT_NOTIFY;
  187316. s.SRB_BufLen = rb->bufferSize;
  187317. s.SRB_BufPointer = rb->buffer;
  187318. s.SRB_CDBLen = 10;
  187319. s.CDBByte[0] = 0xD4;
  187320. s.CDBByte[3] = (BYTE)((rb->startFrame >> 16) & 0xFF);
  187321. s.CDBByte[4] = (BYTE)((rb->startFrame >> 8) & 0xFF);
  187322. s.CDBByte[5] = (BYTE)(rb->startFrame & 0xFF);
  187323. s.CDBByte[8] = (BYTE)(rb->numFrames & 0xFF);
  187324. perform (s);
  187325. if (s.SRB_Status != SS_COMP)
  187326. return false;
  187327. rb->dataLength = rb->numFrames * 2352;
  187328. rb->dataStartOffset = 0;
  187329. return true;
  187330. }
  187331. };
  187332. CDController::CDController() : initialised (false)
  187333. {
  187334. }
  187335. CDController::~CDController()
  187336. {
  187337. }
  187338. void CDController::prepare (SRB_ExecSCSICmd& s)
  187339. {
  187340. zerostruct (s);
  187341. s.SRB_Cmd = SC_EXEC_SCSI_CMD;
  187342. s.SRB_HaID = deviceInfo->info.ha;
  187343. s.SRB_Target = deviceInfo->info.tgt;
  187344. s.SRB_Lun = deviceInfo->info.lun;
  187345. s.SRB_SenseLen = SENSE_LEN;
  187346. }
  187347. void CDController::perform (SRB_ExecSCSICmd& s)
  187348. {
  187349. HANDLE event = CreateEvent (0, TRUE, FALSE, 0);
  187350. s.SRB_PostProc = (void*)event;
  187351. ResetEvent (event);
  187352. DWORD status = (usingScsi) ? performScsiPassThroughCommand ((LPSRB_ExecSCSICmd)&s,
  187353. deviceInfo->info.scsiDriveLetter,
  187354. deviceInfo->scsiHandle)
  187355. : fSendASPI32Command ((LPSRB)&s);
  187356. if (status == SS_PENDING)
  187357. WaitForSingleObject (event, 4000);
  187358. CloseHandle (event);
  187359. }
  187360. void CDController::setPaused (bool paused)
  187361. {
  187362. SRB_ExecSCSICmd s;
  187363. prepare (s);
  187364. s.SRB_Flags = SRB_EVENT_NOTIFY;
  187365. s.SRB_CDBLen = 10;
  187366. s.CDBByte[0] = 0x4B;
  187367. s.CDBByte[8] = (BYTE) (paused ? 0 : 1);
  187368. perform (s);
  187369. }
  187370. void CDController::shutDown()
  187371. {
  187372. }
  187373. bool CDController::readAudio (CDReadBuffer* rb, CDReadBuffer* overlapBuffer)
  187374. {
  187375. if (overlapBuffer != 0)
  187376. {
  187377. const bool canDoJitter = (overlapBuffer->bufferSize >= 2352 * framesToCheck);
  187378. const bool doJitter = canDoJitter && ! overlapBuffer->isZero();
  187379. if (doJitter
  187380. && overlapBuffer->startFrame > 0
  187381. && overlapBuffer->numFrames > 0
  187382. && overlapBuffer->dataLength > 0)
  187383. {
  187384. const int numFrames = rb->numFrames;
  187385. if (overlapBuffer->startFrame == (rb->startFrame - framesToCheck))
  187386. {
  187387. rb->startFrame -= framesOverlap;
  187388. if (framesToCheck < framesOverlap
  187389. && numFrames + framesOverlap <= rb->bufferSize / 2352)
  187390. rb->numFrames += framesOverlap;
  187391. }
  187392. else
  187393. {
  187394. overlapBuffer->dataLength = 0;
  187395. overlapBuffer->startFrame = 0;
  187396. overlapBuffer->numFrames = 0;
  187397. }
  187398. }
  187399. if (! read (rb))
  187400. return false;
  187401. if (doJitter)
  187402. {
  187403. const int checkLen = framesToCheck * 2352;
  187404. const int maxToCheck = rb->dataLength - checkLen;
  187405. if (overlapBuffer->dataLength == 0 || overlapBuffer->isZero())
  187406. return true;
  187407. BYTE* const p = overlapBuffer->buffer + overlapBuffer->dataStartOffset;
  187408. bool found = false;
  187409. for (int i = 0; i < maxToCheck; ++i)
  187410. {
  187411. if (!memcmp (p, rb->buffer + i, checkLen))
  187412. {
  187413. i += checkLen;
  187414. rb->dataStartOffset = i;
  187415. rb->dataLength -= i;
  187416. rb->startFrame = overlapBuffer->startFrame + framesToCheck;
  187417. found = true;
  187418. break;
  187419. }
  187420. }
  187421. rb->numFrames = rb->dataLength / 2352;
  187422. rb->dataLength = 2352 * rb->numFrames;
  187423. if (!found)
  187424. return false;
  187425. }
  187426. if (canDoJitter)
  187427. {
  187428. memcpy (overlapBuffer->buffer,
  187429. rb->buffer + rb->dataStartOffset + 2352 * (rb->numFrames - framesToCheck),
  187430. 2352 * framesToCheck);
  187431. overlapBuffer->startFrame = rb->startFrame + rb->numFrames - framesToCheck;
  187432. overlapBuffer->numFrames = framesToCheck;
  187433. overlapBuffer->dataLength = 2352 * framesToCheck;
  187434. overlapBuffer->dataStartOffset = 0;
  187435. }
  187436. else
  187437. {
  187438. overlapBuffer->startFrame = 0;
  187439. overlapBuffer->numFrames = 0;
  187440. overlapBuffer->dataLength = 0;
  187441. }
  187442. return true;
  187443. }
  187444. else
  187445. {
  187446. return read (rb);
  187447. }
  187448. }
  187449. int CDController::getLastIndex()
  187450. {
  187451. char qdata[100];
  187452. SRB_ExecSCSICmd s;
  187453. prepare (s);
  187454. s.SRB_Flags = SRB_DIR_IN | SRB_EVENT_NOTIFY;
  187455. s.SRB_BufLen = sizeof (qdata);
  187456. s.SRB_BufPointer = (BYTE*)qdata;
  187457. s.SRB_CDBLen = 12;
  187458. s.CDBByte[0] = 0x42;
  187459. s.CDBByte[1] = (BYTE)(deviceInfo->info.lun << 5);
  187460. s.CDBByte[2] = 64;
  187461. s.CDBByte[3] = 1; // get current position
  187462. s.CDBByte[7] = 0;
  187463. s.CDBByte[8] = (BYTE)sizeof (qdata);
  187464. perform (s);
  187465. if (s.SRB_Status == SS_COMP)
  187466. return qdata[7];
  187467. return 0;
  187468. }
  187469. bool CDDeviceHandle::readTOC (TOC* lpToc, bool useMSF)
  187470. {
  187471. HANDLE event = CreateEvent (0, TRUE, FALSE, 0);
  187472. SRB_ExecSCSICmd s;
  187473. zerostruct (s);
  187474. s.SRB_Cmd = SC_EXEC_SCSI_CMD;
  187475. s.SRB_HaID = info.ha;
  187476. s.SRB_Target = info.tgt;
  187477. s.SRB_Lun = info.lun;
  187478. s.SRB_Flags = SRB_DIR_IN | SRB_EVENT_NOTIFY;
  187479. s.SRB_BufLen = 0x324;
  187480. s.SRB_BufPointer = (BYTE*)lpToc;
  187481. s.SRB_SenseLen = 0x0E;
  187482. s.SRB_CDBLen = 0x0A;
  187483. s.SRB_PostProc = (void*)event;
  187484. s.CDBByte[0] = 0x43;
  187485. s.CDBByte[1] = (BYTE)(useMSF ? 0x02 : 0x00);
  187486. s.CDBByte[7] = 0x03;
  187487. s.CDBByte[8] = 0x24;
  187488. ResetEvent (event);
  187489. DWORD status = (usingScsi) ? performScsiPassThroughCommand ((LPSRB_ExecSCSICmd)&s, info.scsiDriveLetter, scsiHandle)
  187490. : fSendASPI32Command ((LPSRB)&s);
  187491. if (status == SS_PENDING)
  187492. WaitForSingleObject (event, 4000);
  187493. CloseHandle (event);
  187494. return (s.SRB_Status == SS_COMP);
  187495. }
  187496. bool CDDeviceHandle::readAudio (CDReadBuffer* const buffer,
  187497. CDReadBuffer* const overlapBuffer)
  187498. {
  187499. if (controller == 0)
  187500. {
  187501. testController (READTYPE_ATAPI2, new ControllerType1(), buffer)
  187502. || testController (READTYPE_ATAPI1, new ControllerType1(), buffer)
  187503. || testController (READTYPE_READ10_2, new ControllerType2(), buffer)
  187504. || testController (READTYPE_READ10, new ControllerType2(), buffer)
  187505. || testController (READTYPE_READ_D8, new ControllerType3(), buffer)
  187506. || testController (READTYPE_READ_D4, new ControllerType4(), buffer)
  187507. || testController (READTYPE_READ_D4_1, new ControllerType4(), buffer);
  187508. }
  187509. buffer->index = 0;
  187510. if ((controller != 0)
  187511. && controller->readAudio (buffer, overlapBuffer))
  187512. {
  187513. if (buffer->wantsIndex)
  187514. buffer->index = controller->getLastIndex();
  187515. return true;
  187516. }
  187517. return false;
  187518. }
  187519. void CDDeviceHandle::openDrawer (bool shouldBeOpen)
  187520. {
  187521. if (shouldBeOpen)
  187522. {
  187523. if (controller != 0)
  187524. {
  187525. controller->shutDown();
  187526. delete controller;
  187527. controller = 0;
  187528. }
  187529. if (scsiHandle != 0)
  187530. {
  187531. CloseHandle (scsiHandle);
  187532. scsiHandle = 0;
  187533. }
  187534. }
  187535. SRB_ExecSCSICmd s;
  187536. zerostruct (s);
  187537. s.SRB_Cmd = SC_EXEC_SCSI_CMD;
  187538. s.SRB_HaID = info.ha;
  187539. s.SRB_Target = info.tgt;
  187540. s.SRB_Lun = info.lun;
  187541. s.SRB_SenseLen = SENSE_LEN;
  187542. s.SRB_Flags = SRB_DIR_IN | SRB_EVENT_NOTIFY;
  187543. s.SRB_BufLen = 0;
  187544. s.SRB_BufPointer = 0;
  187545. s.SRB_CDBLen = 12;
  187546. s.CDBByte[0] = 0x1b;
  187547. s.CDBByte[1] = (BYTE)(info.lun << 5);
  187548. s.CDBByte[4] = (BYTE)((shouldBeOpen) ? 2 : 3);
  187549. HANDLE event = CreateEvent (0, TRUE, FALSE, 0);
  187550. s.SRB_PostProc = (void*)event;
  187551. ResetEvent (event);
  187552. DWORD status = (usingScsi) ? performScsiPassThroughCommand ((LPSRB_ExecSCSICmd)&s, info.scsiDriveLetter, scsiHandle)
  187553. : fSendASPI32Command ((LPSRB)&s);
  187554. if (status == SS_PENDING)
  187555. WaitForSingleObject (event, 4000);
  187556. CloseHandle (event);
  187557. }
  187558. bool CDDeviceHandle::testController (const int type,
  187559. CDController* const newController,
  187560. CDReadBuffer* const rb)
  187561. {
  187562. controller = newController;
  187563. readType = (BYTE)type;
  187564. controller->deviceInfo = this;
  187565. controller->framesToCheck = 1;
  187566. controller->framesOverlap = 3;
  187567. bool passed = false;
  187568. memset (rb->buffer, 0xcd, rb->bufferSize);
  187569. if (controller->read (rb))
  187570. {
  187571. passed = true;
  187572. int* p = (int*) (rb->buffer + rb->dataStartOffset);
  187573. int wrong = 0;
  187574. for (int i = rb->dataLength / 4; --i >= 0;)
  187575. {
  187576. if (*p++ == (int) 0xcdcdcdcd)
  187577. {
  187578. if (++wrong == 4)
  187579. {
  187580. passed = false;
  187581. break;
  187582. }
  187583. }
  187584. else
  187585. {
  187586. wrong = 0;
  187587. }
  187588. }
  187589. }
  187590. if (! passed)
  187591. {
  187592. controller->shutDown();
  187593. delete controller;
  187594. controller = 0;
  187595. }
  187596. return passed;
  187597. }
  187598. static void GetAspiDeviceInfo (CDDeviceInfo* dev, BYTE ha, BYTE tgt, BYTE lun)
  187599. {
  187600. HANDLE event = CreateEvent (0, TRUE, FALSE, 0);
  187601. const int bufSize = 128;
  187602. BYTE buffer[bufSize];
  187603. zeromem (buffer, bufSize);
  187604. SRB_ExecSCSICmd s;
  187605. zerostruct (s);
  187606. s.SRB_Cmd = SC_EXEC_SCSI_CMD;
  187607. s.SRB_HaID = ha;
  187608. s.SRB_Target = tgt;
  187609. s.SRB_Lun = lun;
  187610. s.SRB_Flags = SRB_DIR_IN | SRB_EVENT_NOTIFY;
  187611. s.SRB_BufLen = bufSize;
  187612. s.SRB_BufPointer = buffer;
  187613. s.SRB_SenseLen = SENSE_LEN;
  187614. s.SRB_CDBLen = 6;
  187615. s.SRB_PostProc = (void*)event;
  187616. s.CDBByte[0] = SCSI_INQUIRY;
  187617. s.CDBByte[4] = 100;
  187618. ResetEvent (event);
  187619. if (fSendASPI32Command ((LPSRB)&s) == SS_PENDING)
  187620. WaitForSingleObject (event, 4000);
  187621. CloseHandle (event);
  187622. if (s.SRB_Status == SS_COMP)
  187623. {
  187624. memcpy (dev->vendor, &buffer[8], 8);
  187625. memcpy (dev->productId, &buffer[16], 16);
  187626. memcpy (dev->rev, &buffer[32], 4);
  187627. memcpy (dev->vendorSpec, &buffer[36], 20);
  187628. }
  187629. }
  187630. static int FindCDDevices (CDDeviceInfo* const list,
  187631. int maxItems)
  187632. {
  187633. int count = 0;
  187634. if (usingScsi)
  187635. {
  187636. for (char driveLetter = 'b'; driveLetter <= 'z'; ++driveLetter)
  187637. {
  187638. TCHAR drivePath[8];
  187639. drivePath[0] = driveLetter;
  187640. drivePath[1] = ':';
  187641. drivePath[2] = '\\';
  187642. drivePath[3] = 0;
  187643. if (GetDriveType (drivePath) == DRIVE_CDROM)
  187644. {
  187645. HANDLE h = CreateSCSIDeviceHandle (driveLetter);
  187646. if (h != INVALID_HANDLE_VALUE)
  187647. {
  187648. BYTE buffer[100], passThroughStruct[1024];
  187649. zeromem (buffer, sizeof (buffer));
  187650. zeromem (passThroughStruct, sizeof (passThroughStruct));
  187651. PSCSI_PASS_THROUGH_DIRECT_WITH_BUFFER p = (PSCSI_PASS_THROUGH_DIRECT_WITH_BUFFER)passThroughStruct;
  187652. p->spt.Length = sizeof (SCSI_PASS_THROUGH);
  187653. p->spt.CdbLength = 6;
  187654. p->spt.SenseInfoLength = 24;
  187655. p->spt.DataIn = SCSI_IOCTL_DATA_IN;
  187656. p->spt.DataTransferLength = 100;
  187657. p->spt.TimeOutValue = 2;
  187658. p->spt.DataBuffer = buffer;
  187659. p->spt.SenseInfoOffset = offsetof (SCSI_PASS_THROUGH_DIRECT_WITH_BUFFER, ucSenseBuf);
  187660. p->spt.Cdb[0] = 0x12;
  187661. p->spt.Cdb[4] = 100;
  187662. DWORD bytesReturned = 0;
  187663. if (DeviceIoControl (h, IOCTL_SCSI_PASS_THROUGH_DIRECT,
  187664. p, sizeof (SCSI_PASS_THROUGH_DIRECT_WITH_BUFFER),
  187665. p, sizeof (SCSI_PASS_THROUGH_DIRECT_WITH_BUFFER),
  187666. &bytesReturned, 0) != 0)
  187667. {
  187668. zeromem (&list[count], sizeof (CDDeviceInfo));
  187669. list[count].scsiDriveLetter = driveLetter;
  187670. memcpy (list[count].vendor, &buffer[8], 8);
  187671. memcpy (list[count].productId, &buffer[16], 16);
  187672. memcpy (list[count].rev, &buffer[32], 4);
  187673. memcpy (list[count].vendorSpec, &buffer[36], 20);
  187674. zeromem (passThroughStruct, sizeof (passThroughStruct));
  187675. PSCSI_ADDRESS scsiAddr = (PSCSI_ADDRESS)passThroughStruct;
  187676. scsiAddr->Length = sizeof (SCSI_ADDRESS);
  187677. if (DeviceIoControl (h, IOCTL_SCSI_GET_ADDRESS,
  187678. 0, 0, scsiAddr, sizeof (SCSI_ADDRESS),
  187679. &bytesReturned, 0) != 0)
  187680. {
  187681. list[count].ha = scsiAddr->PortNumber;
  187682. list[count].tgt = scsiAddr->TargetId;
  187683. list[count].lun = scsiAddr->Lun;
  187684. ++count;
  187685. }
  187686. }
  187687. CloseHandle (h);
  187688. }
  187689. }
  187690. }
  187691. }
  187692. else
  187693. {
  187694. const DWORD d = fGetASPI32SupportInfo();
  187695. BYTE status = HIBYTE (LOWORD (d));
  187696. if (status != SS_COMP || status == SS_NO_ADAPTERS)
  187697. return 0;
  187698. const int numAdapters = LOBYTE (LOWORD (d));
  187699. for (BYTE ha = 0; ha < numAdapters; ++ha)
  187700. {
  187701. SRB_HAInquiry s;
  187702. zerostruct (s);
  187703. s.SRB_Cmd = SC_HA_INQUIRY;
  187704. s.SRB_HaID = ha;
  187705. fSendASPI32Command ((LPSRB)&s);
  187706. if (s.SRB_Status == SS_COMP)
  187707. {
  187708. maxItems = (int)s.HA_Unique[3];
  187709. if (maxItems == 0)
  187710. maxItems = 8;
  187711. for (BYTE tgt = 0; tgt < maxItems; ++tgt)
  187712. {
  187713. for (BYTE lun = 0; lun < 8; ++lun)
  187714. {
  187715. SRB_GDEVBlock sb;
  187716. zerostruct (sb);
  187717. sb.SRB_Cmd = SC_GET_DEV_TYPE;
  187718. sb.SRB_HaID = ha;
  187719. sb.SRB_Target = tgt;
  187720. sb.SRB_Lun = lun;
  187721. fSendASPI32Command ((LPSRB) &sb);
  187722. if (sb.SRB_Status == SS_COMP
  187723. && sb.SRB_DeviceType == DTYPE_CROM)
  187724. {
  187725. zeromem (&list[count], sizeof (CDDeviceInfo));
  187726. list[count].ha = ha;
  187727. list[count].tgt = tgt;
  187728. list[count].lun = lun;
  187729. GetAspiDeviceInfo (&(list[count]), ha, tgt, lun);
  187730. ++count;
  187731. }
  187732. }
  187733. }
  187734. }
  187735. }
  187736. }
  187737. return count;
  187738. }
  187739. static int ripperUsers = 0;
  187740. static bool initialisedOk = false;
  187741. class DeinitialiseTimer : private Timer,
  187742. private DeletedAtShutdown
  187743. {
  187744. DeinitialiseTimer (const DeinitialiseTimer&);
  187745. const DeinitialiseTimer& operator= (const DeinitialiseTimer&);
  187746. public:
  187747. DeinitialiseTimer()
  187748. {
  187749. startTimer (4000);
  187750. }
  187751. ~DeinitialiseTimer()
  187752. {
  187753. if (--ripperUsers == 0)
  187754. DeinitialiseCDRipper();
  187755. }
  187756. void timerCallback()
  187757. {
  187758. delete this;
  187759. }
  187760. juce_UseDebuggingNewOperator
  187761. };
  187762. static void incUserCount()
  187763. {
  187764. if (ripperUsers++ == 0)
  187765. initialisedOk = InitialiseCDRipper();
  187766. }
  187767. static void decUserCount()
  187768. {
  187769. new DeinitialiseTimer();
  187770. }
  187771. struct CDDeviceWrapper
  187772. {
  187773. CDDeviceHandle* cdH;
  187774. CDReadBuffer* overlapBuffer;
  187775. bool jitter;
  187776. };
  187777. static int getAddressOf (const TOCTRACK* const t)
  187778. {
  187779. return (((DWORD)t->addr[0]) << 24) + (((DWORD)t->addr[1]) << 16) +
  187780. (((DWORD)t->addr[2]) << 8) + ((DWORD)t->addr[3]);
  187781. }
  187782. static int getMSFAddressOf (const TOCTRACK* const t)
  187783. {
  187784. return 60 * t->addr[1] + t->addr[2];
  187785. }
  187786. static const int samplesPerFrame = 44100 / 75;
  187787. static const int bytesPerFrame = samplesPerFrame * 4;
  187788. const StringArray AudioCDReader::getAvailableCDNames()
  187789. {
  187790. StringArray results;
  187791. incUserCount();
  187792. if (initialisedOk)
  187793. {
  187794. CDDeviceInfo list[8];
  187795. const int num = FindCDDevices (list, 8);
  187796. decUserCount();
  187797. for (int i = 0; i < num; ++i)
  187798. {
  187799. String s;
  187800. if (list[i].scsiDriveLetter > 0)
  187801. s << String::charToString (list[i].scsiDriveLetter).toUpperCase() << T(": ");
  187802. s << String (list[i].vendor).trim()
  187803. << T(" ") << String (list[i].productId).trim()
  187804. << T(" ") << String (list[i].rev).trim();
  187805. results.add (s);
  187806. }
  187807. }
  187808. return results;
  187809. }
  187810. static CDDeviceHandle* openHandle (const CDDeviceInfo* const device)
  187811. {
  187812. SRB_GDEVBlock s;
  187813. zerostruct (s);
  187814. s.SRB_Cmd = SC_GET_DEV_TYPE;
  187815. s.SRB_HaID = device->ha;
  187816. s.SRB_Target = device->tgt;
  187817. s.SRB_Lun = device->lun;
  187818. if (usingScsi)
  187819. {
  187820. HANDLE h = CreateSCSIDeviceHandle (device->scsiDriveLetter);
  187821. if (h != INVALID_HANDLE_VALUE)
  187822. {
  187823. CDDeviceHandle* cdh = new CDDeviceHandle (device);
  187824. cdh->scsiHandle = h;
  187825. return cdh;
  187826. }
  187827. }
  187828. else
  187829. {
  187830. if (fSendASPI32Command ((LPSRB)&s) == SS_COMP
  187831. && s.SRB_DeviceType == DTYPE_CROM)
  187832. {
  187833. return new CDDeviceHandle (device);
  187834. }
  187835. }
  187836. return 0;
  187837. }
  187838. AudioCDReader* AudioCDReader::createReaderForCD (const int deviceIndex)
  187839. {
  187840. incUserCount();
  187841. if (initialisedOk)
  187842. {
  187843. CDDeviceInfo list[8];
  187844. const int num = FindCDDevices (list, 8);
  187845. if (((unsigned int) deviceIndex) < (unsigned int) num)
  187846. {
  187847. CDDeviceHandle* const handle = openHandle (&(list[deviceIndex]));
  187848. if (handle != 0)
  187849. {
  187850. CDDeviceWrapper* const d = new CDDeviceWrapper();
  187851. d->cdH = handle;
  187852. d->overlapBuffer = new CDReadBuffer(3);
  187853. return new AudioCDReader (d);
  187854. }
  187855. }
  187856. }
  187857. decUserCount();
  187858. return 0;
  187859. }
  187860. AudioCDReader::AudioCDReader (void* handle_)
  187861. : AudioFormatReader (0, T("CD Audio")),
  187862. handle (handle_),
  187863. indexingEnabled (false),
  187864. lastIndex (0),
  187865. firstFrameInBuffer (0),
  187866. samplesInBuffer (0)
  187867. {
  187868. jassert (handle_ != 0);
  187869. refreshTrackLengths();
  187870. sampleRate = 44100.0;
  187871. bitsPerSample = 16;
  187872. lengthInSamples = getPositionOfTrackStart (numTracks);
  187873. numChannels = 2;
  187874. usesFloatingPointData = false;
  187875. buffer.setSize (4 * bytesPerFrame, true);
  187876. }
  187877. AudioCDReader::~AudioCDReader()
  187878. {
  187879. CDDeviceWrapper* const device = (CDDeviceWrapper*)handle;
  187880. delete device->cdH;
  187881. delete device->overlapBuffer;
  187882. delete device;
  187883. decUserCount();
  187884. }
  187885. bool AudioCDReader::readSamples (int** destSamples, int numDestChannels, int startOffsetInDestBuffer,
  187886. int64 startSampleInFile, int numSamples)
  187887. {
  187888. CDDeviceWrapper* const device = (CDDeviceWrapper*) handle;
  187889. bool ok = true;
  187890. while (numSamples > 0)
  187891. {
  187892. const int bufferStartSample = firstFrameInBuffer * samplesPerFrame;
  187893. const int bufferEndSample = bufferStartSample + samplesInBuffer;
  187894. if (startSampleInFile >= bufferStartSample
  187895. && startSampleInFile < bufferEndSample)
  187896. {
  187897. const int toDo = (int) jmin ((int64) numSamples, bufferEndSample - startSampleInFile);
  187898. int* const l = destSamples[0] + startOffsetInDestBuffer;
  187899. int* const r = numDestChannels > 1 ? (destSamples[1] + startOffsetInDestBuffer) : 0;
  187900. const short* src = (const short*) buffer.getData();
  187901. src += 2 * (startSampleInFile - bufferStartSample);
  187902. for (int i = 0; i < toDo; ++i)
  187903. {
  187904. l[i] = src [i << 1] << 16;
  187905. if (r != 0)
  187906. r[i] = src [(i << 1) + 1] << 16;
  187907. }
  187908. startOffsetInDestBuffer += toDo;
  187909. startSampleInFile += toDo;
  187910. numSamples -= toDo;
  187911. }
  187912. else
  187913. {
  187914. const int framesInBuffer = buffer.getSize() / bytesPerFrame;
  187915. const int frameNeeded = (int) (startSampleInFile / samplesPerFrame);
  187916. if (firstFrameInBuffer + framesInBuffer != frameNeeded)
  187917. {
  187918. device->overlapBuffer->dataLength = 0;
  187919. device->overlapBuffer->startFrame = 0;
  187920. device->overlapBuffer->numFrames = 0;
  187921. device->jitter = false;
  187922. }
  187923. firstFrameInBuffer = frameNeeded;
  187924. lastIndex = 0;
  187925. CDReadBuffer readBuffer (framesInBuffer + 4);
  187926. readBuffer.wantsIndex = indexingEnabled;
  187927. int i;
  187928. for (i = 5; --i >= 0;)
  187929. {
  187930. readBuffer.startFrame = frameNeeded;
  187931. readBuffer.numFrames = framesInBuffer;
  187932. if (device->cdH->readAudio (&readBuffer, (device->jitter) ? device->overlapBuffer : 0))
  187933. break;
  187934. else
  187935. device->overlapBuffer->dataLength = 0;
  187936. }
  187937. if (i >= 0)
  187938. {
  187939. memcpy ((char*) buffer.getData(),
  187940. readBuffer.buffer + readBuffer.dataStartOffset,
  187941. readBuffer.dataLength);
  187942. samplesInBuffer = readBuffer.dataLength >> 2;
  187943. lastIndex = readBuffer.index;
  187944. }
  187945. else
  187946. {
  187947. int* l = destSamples[0] + startOffsetInDestBuffer;
  187948. int* r = numDestChannels > 1 ? (destSamples[1] + startOffsetInDestBuffer) : 0;
  187949. while (--numSamples >= 0)
  187950. {
  187951. *l++ = 0;
  187952. if (r != 0)
  187953. *r++ = 0;
  187954. }
  187955. // sometimes the read fails for just the very last couple of blocks, so
  187956. // we'll ignore and errors in the last half-second of the disk..
  187957. ok = startSampleInFile > (trackStarts [numTracks] - 20000);
  187958. break;
  187959. }
  187960. }
  187961. }
  187962. return ok;
  187963. }
  187964. bool AudioCDReader::isCDStillPresent() const
  187965. {
  187966. TOC toc;
  187967. zerostruct (toc);
  187968. return ((CDDeviceWrapper*)handle)->cdH->readTOC (&toc, false);
  187969. }
  187970. int AudioCDReader::getNumTracks() const
  187971. {
  187972. return numTracks;
  187973. }
  187974. int AudioCDReader::getPositionOfTrackStart (int trackNum) const
  187975. {
  187976. return (trackNum >= 0 && trackNum <= numTracks) ? trackStarts [trackNum] * samplesPerFrame
  187977. : 0;
  187978. }
  187979. void AudioCDReader::refreshTrackLengths()
  187980. {
  187981. zeromem (trackStarts, sizeof (trackStarts));
  187982. zeromem (audioTracks, sizeof (audioTracks));
  187983. TOC toc;
  187984. zerostruct (toc);
  187985. if (((CDDeviceWrapper*)handle)->cdH->readTOC (&toc, false))
  187986. {
  187987. numTracks = 1 + toc.lastTrack - toc.firstTrack;
  187988. for (int i = 0; i <= numTracks; ++i)
  187989. {
  187990. trackStarts[i] = getAddressOf (&toc.tracks[i]);
  187991. audioTracks[i] = ((toc.tracks[i].ADR & 4) == 0);
  187992. }
  187993. }
  187994. else
  187995. {
  187996. numTracks = 0;
  187997. }
  187998. }
  187999. bool AudioCDReader::isTrackAudio (int trackNum) const
  188000. {
  188001. return (trackNum >= 0 && trackNum <= numTracks) ? audioTracks [trackNum]
  188002. : false;
  188003. }
  188004. void AudioCDReader::enableIndexScanning (bool b)
  188005. {
  188006. indexingEnabled = b;
  188007. }
  188008. int AudioCDReader::getLastIndex() const
  188009. {
  188010. return lastIndex;
  188011. }
  188012. const int framesPerIndexRead = 4;
  188013. int AudioCDReader::getIndexAt (int samplePos)
  188014. {
  188015. CDDeviceWrapper* const device = (CDDeviceWrapper*) handle;
  188016. const int frameNeeded = samplePos / samplesPerFrame;
  188017. device->overlapBuffer->dataLength = 0;
  188018. device->overlapBuffer->startFrame = 0;
  188019. device->overlapBuffer->numFrames = 0;
  188020. device->jitter = false;
  188021. firstFrameInBuffer = 0;
  188022. lastIndex = 0;
  188023. CDReadBuffer readBuffer (4 + framesPerIndexRead);
  188024. readBuffer.wantsIndex = true;
  188025. int i;
  188026. for (i = 5; --i >= 0;)
  188027. {
  188028. readBuffer.startFrame = frameNeeded;
  188029. readBuffer.numFrames = framesPerIndexRead;
  188030. if (device->cdH->readAudio (&readBuffer, (false) ? device->overlapBuffer : 0))
  188031. break;
  188032. }
  188033. if (i >= 0)
  188034. return readBuffer.index;
  188035. return -1;
  188036. }
  188037. const Array <int> AudioCDReader::findIndexesInTrack (const int trackNumber)
  188038. {
  188039. Array <int> indexes;
  188040. const int trackStart = getPositionOfTrackStart (trackNumber);
  188041. const int trackEnd = getPositionOfTrackStart (trackNumber + 1);
  188042. bool needToScan = true;
  188043. if (trackEnd - trackStart > 20 * 44100)
  188044. {
  188045. // check the end of the track for indexes before scanning the whole thing
  188046. needToScan = false;
  188047. int pos = jmax (trackStart, trackEnd - 44100 * 5);
  188048. bool seenAnIndex = false;
  188049. while (pos <= trackEnd - samplesPerFrame)
  188050. {
  188051. const int index = getIndexAt (pos);
  188052. if (index == 0)
  188053. {
  188054. // lead-out, so skip back a bit if we've not found any indexes yet..
  188055. if (seenAnIndex)
  188056. break;
  188057. pos -= 44100 * 5;
  188058. if (pos < trackStart)
  188059. break;
  188060. }
  188061. else
  188062. {
  188063. if (index > 0)
  188064. seenAnIndex = true;
  188065. if (index > 1)
  188066. {
  188067. needToScan = true;
  188068. break;
  188069. }
  188070. pos += samplesPerFrame * framesPerIndexRead;
  188071. }
  188072. }
  188073. }
  188074. if (needToScan)
  188075. {
  188076. CDDeviceWrapper* const device = (CDDeviceWrapper*) handle;
  188077. int pos = trackStart;
  188078. int last = -1;
  188079. while (pos < trackEnd - samplesPerFrame * 10)
  188080. {
  188081. const int frameNeeded = pos / samplesPerFrame;
  188082. device->overlapBuffer->dataLength = 0;
  188083. device->overlapBuffer->startFrame = 0;
  188084. device->overlapBuffer->numFrames = 0;
  188085. device->jitter = false;
  188086. firstFrameInBuffer = 0;
  188087. CDReadBuffer readBuffer (4);
  188088. readBuffer.wantsIndex = true;
  188089. int i;
  188090. for (i = 5; --i >= 0;)
  188091. {
  188092. readBuffer.startFrame = frameNeeded;
  188093. readBuffer.numFrames = framesPerIndexRead;
  188094. if (device->cdH->readAudio (&readBuffer, (false) ? device->overlapBuffer : 0))
  188095. break;
  188096. }
  188097. if (i < 0)
  188098. break;
  188099. if (readBuffer.index > last && readBuffer.index > 1)
  188100. {
  188101. last = readBuffer.index;
  188102. indexes.add (pos);
  188103. }
  188104. pos += samplesPerFrame * framesPerIndexRead;
  188105. }
  188106. indexes.removeValue (trackStart);
  188107. }
  188108. return indexes;
  188109. }
  188110. int AudioCDReader::getCDDBId()
  188111. {
  188112. refreshTrackLengths();
  188113. if (numTracks > 0)
  188114. {
  188115. TOC toc;
  188116. zerostruct (toc);
  188117. if (((CDDeviceWrapper*) handle)->cdH->readTOC (&toc, true))
  188118. {
  188119. int n = 0;
  188120. for (int i = numTracks; --i >= 0;)
  188121. {
  188122. int j = getMSFAddressOf (&toc.tracks[i]);
  188123. while (j > 0)
  188124. {
  188125. n += (j % 10);
  188126. j /= 10;
  188127. }
  188128. }
  188129. if (n != 0)
  188130. {
  188131. const int t = getMSFAddressOf (&toc.tracks[numTracks])
  188132. - getMSFAddressOf (&toc.tracks[0]);
  188133. return ((n % 0xff) << 24) | (t << 8) | numTracks;
  188134. }
  188135. }
  188136. }
  188137. return 0;
  188138. }
  188139. void AudioCDReader::ejectDisk()
  188140. {
  188141. ((CDDeviceWrapper*) handle)->cdH->openDrawer (true);
  188142. }
  188143. #endif
  188144. #if JUCE_USE_CDBURNER
  188145. static IDiscRecorder* enumCDBurners (StringArray* list, int indexToOpen, IDiscMaster** master)
  188146. {
  188147. CoInitialize (0);
  188148. IDiscMaster* dm;
  188149. IDiscRecorder* result = 0;
  188150. if (SUCCEEDED (CoCreateInstance (CLSID_MSDiscMasterObj, 0,
  188151. CLSCTX_INPROC_SERVER | CLSCTX_LOCAL_SERVER,
  188152. IID_IDiscMaster,
  188153. (void**) &dm)))
  188154. {
  188155. if (SUCCEEDED (dm->Open()))
  188156. {
  188157. IEnumDiscRecorders* drEnum = 0;
  188158. if (SUCCEEDED (dm->EnumDiscRecorders (&drEnum)))
  188159. {
  188160. IDiscRecorder* dr = 0;
  188161. DWORD dummy;
  188162. int index = 0;
  188163. while (drEnum->Next (1, &dr, &dummy) == S_OK)
  188164. {
  188165. if (indexToOpen == index)
  188166. {
  188167. result = dr;
  188168. break;
  188169. }
  188170. else if (list != 0)
  188171. {
  188172. BSTR path;
  188173. if (SUCCEEDED (dr->GetPath (&path)))
  188174. list->add ((const WCHAR*) path);
  188175. }
  188176. ++index;
  188177. dr->Release();
  188178. }
  188179. drEnum->Release();
  188180. }
  188181. if (master == 0)
  188182. dm->Close();
  188183. }
  188184. if (master != 0)
  188185. *master = dm;
  188186. else
  188187. dm->Release();
  188188. }
  188189. return result;
  188190. }
  188191. const StringArray AudioCDBurner::findAvailableDevices()
  188192. {
  188193. StringArray devs;
  188194. enumCDBurners (&devs, -1, 0);
  188195. return devs;
  188196. }
  188197. AudioCDBurner* AudioCDBurner::openDevice (const int deviceIndex)
  188198. {
  188199. AudioCDBurner* b = new AudioCDBurner (deviceIndex);
  188200. if (b->internal == 0)
  188201. deleteAndZero (b);
  188202. return b;
  188203. }
  188204. class CDBurnerInfo : public IDiscMasterProgressEvents
  188205. {
  188206. public:
  188207. CDBurnerInfo()
  188208. : refCount (1),
  188209. progress (0),
  188210. shouldCancel (false),
  188211. listener (0)
  188212. {
  188213. }
  188214. ~CDBurnerInfo()
  188215. {
  188216. }
  188217. HRESULT __stdcall QueryInterface (REFIID id, void __RPC_FAR* __RPC_FAR* result)
  188218. {
  188219. if (result == 0)
  188220. return E_POINTER;
  188221. if (id == IID_IUnknown || id == IID_IDiscMasterProgressEvents)
  188222. {
  188223. AddRef();
  188224. *result = this;
  188225. return S_OK;
  188226. }
  188227. *result = 0;
  188228. return E_NOINTERFACE;
  188229. }
  188230. ULONG __stdcall AddRef() { return ++refCount; }
  188231. ULONG __stdcall Release() { jassert (refCount > 0); const int r = --refCount; if (r == 0) delete this; return r; }
  188232. HRESULT __stdcall QueryCancel (boolean* pbCancel)
  188233. {
  188234. if (listener != 0 && ! shouldCancel)
  188235. shouldCancel = listener->audioCDBurnProgress (progress);
  188236. *pbCancel = shouldCancel;
  188237. return S_OK;
  188238. }
  188239. HRESULT __stdcall NotifyBlockProgress (long nCompleted, long nTotal)
  188240. {
  188241. progress = nCompleted / (float) nTotal;
  188242. shouldCancel = listener != 0 && listener->audioCDBurnProgress (progress);
  188243. return E_NOTIMPL;
  188244. }
  188245. HRESULT __stdcall NotifyPnPActivity (void) { return E_NOTIMPL; }
  188246. HRESULT __stdcall NotifyAddProgress (long /*nCompletedSteps*/, long /*nTotalSteps*/) { return E_NOTIMPL; }
  188247. HRESULT __stdcall NotifyTrackProgress (long /*nCurrentTrack*/, long /*nTotalTracks*/) { return E_NOTIMPL; }
  188248. HRESULT __stdcall NotifyPreparingBurn (long /*nEstimatedSeconds*/) { return E_NOTIMPL; }
  188249. HRESULT __stdcall NotifyClosingDisc (long /*nEstimatedSeconds*/) { return E_NOTIMPL; }
  188250. HRESULT __stdcall NotifyBurnComplete (HRESULT /*status*/) { return E_NOTIMPL; }
  188251. HRESULT __stdcall NotifyEraseComplete (HRESULT /*status*/) { return E_NOTIMPL; }
  188252. IDiscMaster* discMaster;
  188253. IDiscRecorder* discRecorder;
  188254. IRedbookDiscMaster* redbook;
  188255. AudioCDBurner::BurnProgressListener* listener;
  188256. float progress;
  188257. bool shouldCancel;
  188258. private:
  188259. int refCount;
  188260. };
  188261. AudioCDBurner::AudioCDBurner (const int deviceIndex)
  188262. : internal (0)
  188263. {
  188264. IDiscMaster* discMaster;
  188265. IDiscRecorder* dr = enumCDBurners (0, deviceIndex, &discMaster);
  188266. if (dr != 0)
  188267. {
  188268. IRedbookDiscMaster* redbook;
  188269. HRESULT hr = discMaster->SetActiveDiscMasterFormat (IID_IRedbookDiscMaster, (void**) &redbook);
  188270. hr = discMaster->SetActiveDiscRecorder (dr);
  188271. CDBurnerInfo* const info = new CDBurnerInfo();
  188272. internal = info;
  188273. info->discMaster = discMaster;
  188274. info->discRecorder = dr;
  188275. info->redbook = redbook;
  188276. }
  188277. }
  188278. AudioCDBurner::~AudioCDBurner()
  188279. {
  188280. CDBurnerInfo* const info = (CDBurnerInfo*) internal;
  188281. if (info != 0)
  188282. {
  188283. info->discRecorder->Close();
  188284. info->redbook->Release();
  188285. info->discRecorder->Release();
  188286. info->discMaster->Release();
  188287. info->Release();
  188288. }
  188289. }
  188290. bool AudioCDBurner::isDiskPresent() const
  188291. {
  188292. CDBurnerInfo* const info = (CDBurnerInfo*) internal;
  188293. HRESULT hr = info->discRecorder->OpenExclusive();
  188294. long type, flags;
  188295. hr = info->discRecorder->QueryMediaType (&type, &flags);
  188296. info->discRecorder->Close();
  188297. return hr == S_OK && type != 0 && (flags & MEDIA_WRITABLE) != 0;
  188298. }
  188299. int AudioCDBurner::getNumAvailableAudioBlocks() const
  188300. {
  188301. CDBurnerInfo* const info = (CDBurnerInfo*) internal;
  188302. long blocksFree = 0;
  188303. info->redbook->GetAvailableAudioTrackBlocks (&blocksFree);
  188304. return blocksFree;
  188305. }
  188306. const String AudioCDBurner::burn (AudioCDBurner::BurnProgressListener* listener,
  188307. const bool ejectDiscAfterwards,
  188308. const bool performFakeBurnForTesting)
  188309. {
  188310. CDBurnerInfo* const info = (CDBurnerInfo*) internal;
  188311. info->listener = listener;
  188312. info->progress = 0;
  188313. info->shouldCancel = false;
  188314. UINT_PTR cookie;
  188315. HRESULT hr = info->discMaster->ProgressAdvise (info, &cookie);
  188316. hr = info->discMaster->RecordDisc (performFakeBurnForTesting,
  188317. ejectDiscAfterwards);
  188318. String error;
  188319. if (hr != S_OK)
  188320. {
  188321. const char* e = "Couldn't open or write to the CD device";
  188322. if (hr == IMAPI_E_USERABORT)
  188323. e = "User cancelled the write operation";
  188324. else if (hr == IMAPI_E_MEDIUM_NOTPRESENT || hr == IMAPI_E_TRACKOPEN)
  188325. e = "No Disk present";
  188326. error = e;
  188327. }
  188328. info->discMaster->ProgressUnadvise (cookie);
  188329. info->listener = 0;
  188330. return error;
  188331. }
  188332. bool AudioCDBurner::addAudioTrack (AudioSource* source, int numSamples)
  188333. {
  188334. if (source == 0)
  188335. return false;
  188336. CDBurnerInfo* const info = (CDBurnerInfo*) internal;
  188337. long bytesPerBlock;
  188338. HRESULT hr = info->redbook->GetAudioBlockSize (&bytesPerBlock);
  188339. const int samplesPerBlock = bytesPerBlock / 4;
  188340. bool ok = true;
  188341. hr = info->redbook->CreateAudioTrack ((long) numSamples / (bytesPerBlock * 4));
  188342. HeapBlock <byte> buffer (bytesPerBlock);
  188343. AudioSampleBuffer sourceBuffer (2, samplesPerBlock);
  188344. int samplesDone = 0;
  188345. source->prepareToPlay (samplesPerBlock, 44100.0);
  188346. while (ok)
  188347. {
  188348. {
  188349. AudioSourceChannelInfo info;
  188350. info.buffer = &sourceBuffer;
  188351. info.numSamples = samplesPerBlock;
  188352. info.startSample = 0;
  188353. sourceBuffer.clear();
  188354. source->getNextAudioBlock (info);
  188355. }
  188356. zeromem (buffer, bytesPerBlock);
  188357. AudioDataConverters::convertFloatToInt16LE (sourceBuffer.getSampleData (0, 0),
  188358. buffer, samplesPerBlock, 4);
  188359. AudioDataConverters::convertFloatToInt16LE (sourceBuffer.getSampleData (1, 0),
  188360. buffer + 2, samplesPerBlock, 4);
  188361. hr = info->redbook->AddAudioTrackBlocks (buffer, bytesPerBlock);
  188362. if (hr != S_OK)
  188363. ok = false;
  188364. samplesDone += samplesPerBlock;
  188365. if (samplesDone >= numSamples)
  188366. break;
  188367. }
  188368. hr = info->redbook->CloseAudioTrack();
  188369. delete source;
  188370. return ok && hr == S_OK;
  188371. }
  188372. #endif
  188373. #endif
  188374. /********* End of inlined file: juce_win32_AudioCDReader.cpp *********/
  188375. /********* Start of inlined file: juce_win32_Midi.cpp *********/
  188376. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  188377. // compiled on its own).
  188378. #if JUCE_INCLUDED_FILE
  188379. static const int midiBufferSize = 1024 * 10;
  188380. static const int numInHeaders = 32;
  188381. static const int inBufferSize = 256;
  188382. static Array <void*, CriticalSection> activeMidiThreads;
  188383. using ::free;
  188384. class MidiInThread : public Thread
  188385. {
  188386. public:
  188387. MidiInThread (MidiInput* const input_,
  188388. MidiInputCallback* const callback_)
  188389. : Thread ("Juce Midi"),
  188390. hIn (0),
  188391. input (input_),
  188392. callback (callback_),
  188393. isStarted (false),
  188394. startTime (0),
  188395. pendingLength(0)
  188396. {
  188397. for (int i = numInHeaders; --i >= 0;)
  188398. {
  188399. zeromem (&hdr[i], sizeof (MIDIHDR));
  188400. hdr[i].lpData = inData[i];
  188401. hdr[i].dwBufferLength = inBufferSize;
  188402. }
  188403. };
  188404. ~MidiInThread()
  188405. {
  188406. stop();
  188407. if (hIn != 0)
  188408. {
  188409. int count = 5;
  188410. while (--count >= 0)
  188411. {
  188412. if (midiInClose (hIn) == MMSYSERR_NOERROR)
  188413. break;
  188414. Sleep (20);
  188415. }
  188416. }
  188417. }
  188418. void handle (const uint32 message, const uint32 timeStamp) throw()
  188419. {
  188420. const int byte = message & 0xff;
  188421. if (byte < 0x80)
  188422. return;
  188423. const int numBytes = MidiMessage::getMessageLengthFromFirstByte ((uint8) byte);
  188424. const double time = timeStampToTime (timeStamp);
  188425. lock.enter();
  188426. if (pendingLength < midiBufferSize - 12)
  188427. {
  188428. char* const p = pending + pendingLength;
  188429. *(double*) p = time;
  188430. *(uint32*) (p + 8) = numBytes;
  188431. *(uint32*) (p + 12) = message;
  188432. pendingLength += 12 + numBytes;
  188433. }
  188434. else
  188435. {
  188436. jassertfalse // midi buffer overflow! You might need to increase the size..
  188437. }
  188438. lock.exit();
  188439. notify();
  188440. }
  188441. void handleSysEx (MIDIHDR* const hdr, const uint32 timeStamp) throw()
  188442. {
  188443. const int num = hdr->dwBytesRecorded;
  188444. if (num > 0)
  188445. {
  188446. const double time = timeStampToTime (timeStamp);
  188447. lock.enter();
  188448. if (pendingLength < midiBufferSize - (8 + num))
  188449. {
  188450. char* const p = pending + pendingLength;
  188451. *(double*) p = time;
  188452. *(uint32*) (p + 8) = num;
  188453. memcpy (p + 12, hdr->lpData, num);
  188454. pendingLength += 12 + num;
  188455. }
  188456. else
  188457. {
  188458. jassertfalse // midi buffer overflow! You might need to increase the size..
  188459. }
  188460. lock.exit();
  188461. notify();
  188462. }
  188463. }
  188464. void writeBlock (const int i) throw()
  188465. {
  188466. hdr[i].dwBytesRecorded = 0;
  188467. MMRESULT res = midiInPrepareHeader (hIn, &hdr[i], sizeof (MIDIHDR));
  188468. jassert (res == MMSYSERR_NOERROR);
  188469. res = midiInAddBuffer (hIn, &hdr[i], sizeof (MIDIHDR));
  188470. jassert (res == MMSYSERR_NOERROR);
  188471. }
  188472. void run()
  188473. {
  188474. MemoryBlock pendingCopy (64);
  188475. while (! threadShouldExit())
  188476. {
  188477. for (int i = 0; i < numInHeaders; ++i)
  188478. {
  188479. if ((hdr[i].dwFlags & WHDR_DONE) != 0)
  188480. {
  188481. MMRESULT res = midiInUnprepareHeader (hIn, &hdr[i], sizeof (MIDIHDR));
  188482. (void) res;
  188483. jassert (res == MMSYSERR_NOERROR);
  188484. writeBlock (i);
  188485. }
  188486. }
  188487. lock.enter();
  188488. int len = pendingLength;
  188489. if (len > 0)
  188490. {
  188491. pendingCopy.ensureSize (len);
  188492. pendingCopy.copyFrom (pending, 0, len);
  188493. pendingLength = 0;
  188494. }
  188495. lock.exit();
  188496. //xxx needs to figure out if blocks are broken up or not
  188497. if (len == 0)
  188498. {
  188499. wait (500);
  188500. }
  188501. else
  188502. {
  188503. const char* p = (const char*) pendingCopy.getData();
  188504. while (len > 0)
  188505. {
  188506. const double time = *(const double*) p;
  188507. const int messageLen = *(const int*) (p + 8);
  188508. const MidiMessage message ((const uint8*) (p + 12), messageLen, time);
  188509. callback->handleIncomingMidiMessage (input, message);
  188510. p += 12 + messageLen;
  188511. len -= 12 + messageLen;
  188512. }
  188513. }
  188514. }
  188515. }
  188516. void start() throw()
  188517. {
  188518. jassert (hIn != 0);
  188519. if (hIn != 0 && ! isStarted)
  188520. {
  188521. stop();
  188522. activeMidiThreads.addIfNotAlreadyThere (this);
  188523. int i;
  188524. for (i = 0; i < numInHeaders; ++i)
  188525. writeBlock (i);
  188526. startTime = Time::getMillisecondCounter();
  188527. MMRESULT res = midiInStart (hIn);
  188528. jassert (res == MMSYSERR_NOERROR);
  188529. if (res == MMSYSERR_NOERROR)
  188530. {
  188531. isStarted = true;
  188532. pendingLength = 0;
  188533. startThread (6);
  188534. }
  188535. }
  188536. }
  188537. void stop() throw()
  188538. {
  188539. if (isStarted)
  188540. {
  188541. stopThread (5000);
  188542. midiInReset (hIn);
  188543. midiInStop (hIn);
  188544. activeMidiThreads.removeValue (this);
  188545. lock.enter();
  188546. lock.exit();
  188547. for (int i = numInHeaders; --i >= 0;)
  188548. {
  188549. if ((hdr[i].dwFlags & WHDR_DONE) != 0)
  188550. {
  188551. int c = 10;
  188552. while (--c >= 0 && midiInUnprepareHeader (hIn, &hdr[i], sizeof (MIDIHDR)) == MIDIERR_STILLPLAYING)
  188553. Sleep (20);
  188554. jassert (c >= 0);
  188555. }
  188556. }
  188557. isStarted = false;
  188558. pendingLength = 0;
  188559. }
  188560. }
  188561. juce_UseDebuggingNewOperator
  188562. HMIDIIN hIn;
  188563. private:
  188564. MidiInput* input;
  188565. MidiInputCallback* callback;
  188566. bool isStarted;
  188567. uint32 startTime;
  188568. CriticalSection lock;
  188569. MIDIHDR hdr [numInHeaders];
  188570. char inData [numInHeaders] [inBufferSize];
  188571. int pendingLength;
  188572. char pending [midiBufferSize];
  188573. double timeStampToTime (uint32 timeStamp) throw()
  188574. {
  188575. timeStamp += startTime;
  188576. const uint32 now = Time::getMillisecondCounter();
  188577. if (timeStamp > now)
  188578. {
  188579. if (timeStamp > now + 2)
  188580. --startTime;
  188581. timeStamp = now;
  188582. }
  188583. return 0.001 * timeStamp;
  188584. }
  188585. MidiInThread (const MidiInThread&);
  188586. const MidiInThread& operator= (const MidiInThread&);
  188587. };
  188588. static void CALLBACK midiInCallback (HMIDIIN,
  188589. UINT uMsg,
  188590. DWORD_PTR dwInstance,
  188591. DWORD_PTR midiMessage,
  188592. DWORD_PTR timeStamp)
  188593. {
  188594. MidiInThread* const thread = (MidiInThread*) dwInstance;
  188595. if (thread != 0 && activeMidiThreads.contains (thread))
  188596. {
  188597. if (uMsg == MIM_DATA)
  188598. thread->handle ((uint32) midiMessage, (uint32) timeStamp);
  188599. else if (uMsg == MIM_LONGDATA)
  188600. thread->handleSysEx ((MIDIHDR*) midiMessage, (uint32) timeStamp);
  188601. }
  188602. }
  188603. const StringArray MidiInput::getDevices()
  188604. {
  188605. StringArray s;
  188606. const int num = midiInGetNumDevs();
  188607. for (int i = 0; i < num; ++i)
  188608. {
  188609. MIDIINCAPS mc;
  188610. zerostruct (mc);
  188611. if (midiInGetDevCaps (i, &mc, sizeof (mc)) == MMSYSERR_NOERROR)
  188612. s.add (String (mc.szPname, sizeof (mc.szPname)));
  188613. }
  188614. return s;
  188615. }
  188616. int MidiInput::getDefaultDeviceIndex()
  188617. {
  188618. return 0;
  188619. }
  188620. MidiInput* MidiInput::openDevice (const int index, MidiInputCallback* const callback)
  188621. {
  188622. if (callback == 0)
  188623. return 0;
  188624. UINT deviceId = MIDI_MAPPER;
  188625. int n = 0;
  188626. String name;
  188627. const int num = midiInGetNumDevs();
  188628. for (int i = 0; i < num; ++i)
  188629. {
  188630. MIDIINCAPS mc;
  188631. zerostruct (mc);
  188632. if (midiInGetDevCaps (i, &mc, sizeof (mc)) == MMSYSERR_NOERROR)
  188633. {
  188634. if (index == n)
  188635. {
  188636. deviceId = i;
  188637. name = String (mc.szPname, sizeof (mc.szPname));
  188638. break;
  188639. }
  188640. ++n;
  188641. }
  188642. }
  188643. ScopedPointer <MidiInput> in (new MidiInput (name));
  188644. ScopedPointer <MidiInThread> thread (new MidiInThread (in, callback));
  188645. HMIDIIN h;
  188646. HRESULT err = midiInOpen (&h, deviceId,
  188647. (DWORD_PTR) &midiInCallback,
  188648. (DWORD_PTR) (MidiInThread*) thread,
  188649. CALLBACK_FUNCTION);
  188650. if (err == MMSYSERR_NOERROR)
  188651. {
  188652. thread->hIn = h;
  188653. in->internal = (void*) thread.release();
  188654. return in.release();
  188655. }
  188656. return 0;
  188657. }
  188658. MidiInput::MidiInput (const String& name_)
  188659. : name (name_),
  188660. internal (0)
  188661. {
  188662. }
  188663. MidiInput::~MidiInput()
  188664. {
  188665. if (internal != 0)
  188666. {
  188667. MidiInThread* const thread = (MidiInThread*) internal;
  188668. delete thread;
  188669. }
  188670. }
  188671. void MidiInput::start()
  188672. {
  188673. ((MidiInThread*) internal)->start();
  188674. }
  188675. void MidiInput::stop()
  188676. {
  188677. ((MidiInThread*) internal)->stop();
  188678. }
  188679. struct MidiOutHandle
  188680. {
  188681. int refCount;
  188682. UINT deviceId;
  188683. HMIDIOUT handle;
  188684. juce_UseDebuggingNewOperator
  188685. };
  188686. static Array <MidiOutHandle*> midiOutputHandles;
  188687. const StringArray MidiOutput::getDevices()
  188688. {
  188689. StringArray s;
  188690. const int num = midiOutGetNumDevs();
  188691. for (int i = 0; i < num; ++i)
  188692. {
  188693. MIDIOUTCAPS mc;
  188694. zerostruct (mc);
  188695. if (midiOutGetDevCaps (i, &mc, sizeof (mc)) == MMSYSERR_NOERROR)
  188696. s.add (String (mc.szPname, sizeof (mc.szPname)));
  188697. }
  188698. return s;
  188699. }
  188700. int MidiOutput::getDefaultDeviceIndex()
  188701. {
  188702. const int num = midiOutGetNumDevs();
  188703. int n = 0;
  188704. for (int i = 0; i < num; ++i)
  188705. {
  188706. MIDIOUTCAPS mc;
  188707. zerostruct (mc);
  188708. if (midiOutGetDevCaps (i, &mc, sizeof (mc)) == MMSYSERR_NOERROR)
  188709. {
  188710. if ((mc.wTechnology & MOD_MAPPER) != 0)
  188711. return n;
  188712. ++n;
  188713. }
  188714. }
  188715. return 0;
  188716. }
  188717. MidiOutput* MidiOutput::openDevice (int index)
  188718. {
  188719. UINT deviceId = MIDI_MAPPER;
  188720. const int num = midiOutGetNumDevs();
  188721. int i, n = 0;
  188722. for (i = 0; i < num; ++i)
  188723. {
  188724. MIDIOUTCAPS mc;
  188725. zerostruct (mc);
  188726. if (midiOutGetDevCaps (i, &mc, sizeof (mc)) == MMSYSERR_NOERROR)
  188727. {
  188728. // use the microsoft sw synth as a default - best not to allow deviceId
  188729. // to be MIDI_MAPPER, or else device sharing breaks
  188730. if (String (mc.szPname, sizeof (mc.szPname)).containsIgnoreCase (T("microsoft")))
  188731. deviceId = i;
  188732. if (index == n)
  188733. {
  188734. deviceId = i;
  188735. break;
  188736. }
  188737. ++n;
  188738. }
  188739. }
  188740. for (i = midiOutputHandles.size(); --i >= 0;)
  188741. {
  188742. MidiOutHandle* const han = midiOutputHandles.getUnchecked(i);
  188743. if (han != 0 && han->deviceId == deviceId)
  188744. {
  188745. han->refCount++;
  188746. MidiOutput* const out = new MidiOutput();
  188747. out->internal = (void*) han;
  188748. return out;
  188749. }
  188750. }
  188751. for (i = 4; --i >= 0;)
  188752. {
  188753. HMIDIOUT h = 0;
  188754. MMRESULT res = midiOutOpen (&h, deviceId, 0, 0, CALLBACK_NULL);
  188755. if (res == MMSYSERR_NOERROR)
  188756. {
  188757. MidiOutHandle* const han = new MidiOutHandle();
  188758. han->deviceId = deviceId;
  188759. han->refCount = 1;
  188760. han->handle = h;
  188761. midiOutputHandles.add (han);
  188762. MidiOutput* const out = new MidiOutput();
  188763. out->internal = (void*) han;
  188764. return out;
  188765. }
  188766. else if (res == MMSYSERR_ALLOCATED)
  188767. {
  188768. Sleep (100);
  188769. }
  188770. else
  188771. {
  188772. break;
  188773. }
  188774. }
  188775. return 0;
  188776. }
  188777. MidiOutput::~MidiOutput()
  188778. {
  188779. MidiOutHandle* const h = (MidiOutHandle*) internal;
  188780. if (midiOutputHandles.contains (h) && --(h->refCount) == 0)
  188781. {
  188782. midiOutClose (h->handle);
  188783. midiOutputHandles.removeValue (h);
  188784. delete h;
  188785. }
  188786. }
  188787. void MidiOutput::reset()
  188788. {
  188789. const MidiOutHandle* const h = (MidiOutHandle*) internal;
  188790. midiOutReset (h->handle);
  188791. }
  188792. bool MidiOutput::getVolume (float& leftVol,
  188793. float& rightVol)
  188794. {
  188795. const MidiOutHandle* const handle = (const MidiOutHandle*) internal;
  188796. DWORD n;
  188797. if (midiOutGetVolume (handle->handle, &n) == MMSYSERR_NOERROR)
  188798. {
  188799. const unsigned short* const nn = (const unsigned short*) &n;
  188800. rightVol = nn[0] / (float) 0xffff;
  188801. leftVol = nn[1] / (float) 0xffff;
  188802. return true;
  188803. }
  188804. else
  188805. {
  188806. rightVol = leftVol = 1.0f;
  188807. return false;
  188808. }
  188809. }
  188810. void MidiOutput::setVolume (float leftVol,
  188811. float rightVol)
  188812. {
  188813. const MidiOutHandle* const handle = (MidiOutHandle*) internal;
  188814. DWORD n;
  188815. unsigned short* const nn = (unsigned short*) &n;
  188816. nn[0] = (unsigned short) jlimit (0, 0xffff, (int)(rightVol * 0xffff));
  188817. nn[1] = (unsigned short) jlimit (0, 0xffff, (int)(leftVol * 0xffff));
  188818. midiOutSetVolume (handle->handle, n);
  188819. }
  188820. void MidiOutput::sendMessageNow (const MidiMessage& message)
  188821. {
  188822. const MidiOutHandle* const handle = (const MidiOutHandle*) internal;
  188823. if (message.getRawDataSize() > 3
  188824. || message.isSysEx())
  188825. {
  188826. MIDIHDR h;
  188827. zerostruct (h);
  188828. h.lpData = (char*) message.getRawData();
  188829. h.dwBufferLength = message.getRawDataSize();
  188830. h.dwBytesRecorded = message.getRawDataSize();
  188831. if (midiOutPrepareHeader (handle->handle, &h, sizeof (MIDIHDR)) == MMSYSERR_NOERROR)
  188832. {
  188833. MMRESULT res = midiOutLongMsg (handle->handle, &h, sizeof (MIDIHDR));
  188834. if (res == MMSYSERR_NOERROR)
  188835. {
  188836. while ((h.dwFlags & MHDR_DONE) == 0)
  188837. Sleep (1);
  188838. int count = 500; // 1 sec timeout
  188839. while (--count >= 0)
  188840. {
  188841. res = midiOutUnprepareHeader (handle->handle, &h, sizeof (MIDIHDR));
  188842. if (res == MIDIERR_STILLPLAYING)
  188843. Sleep (2);
  188844. else
  188845. break;
  188846. }
  188847. }
  188848. }
  188849. }
  188850. else
  188851. {
  188852. midiOutShortMsg (handle->handle,
  188853. *(unsigned int*) message.getRawData());
  188854. }
  188855. }
  188856. #endif
  188857. /********* End of inlined file: juce_win32_Midi.cpp *********/
  188858. /********* Start of inlined file: juce_win32_ASIO.cpp *********/
  188859. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  188860. // compiled on its own).
  188861. #if JUCE_INCLUDED_FILE && JUCE_ASIO
  188862. #undef WINDOWS
  188863. // #define ASIO_DEBUGGING
  188864. #ifdef ASIO_DEBUGGING
  188865. #define log(a) { Logger::writeToLog (a); DBG (a) }
  188866. #else
  188867. #define log(a) {}
  188868. #endif
  188869. #ifdef ASIO_DEBUGGING
  188870. static void logError (const String& context, long error)
  188871. {
  188872. String err ("unknown error");
  188873. if (error == ASE_NotPresent)
  188874. err = "Not Present";
  188875. else if (error == ASE_HWMalfunction)
  188876. err = "Hardware Malfunction";
  188877. else if (error == ASE_InvalidParameter)
  188878. err = "Invalid Parameter";
  188879. else if (error == ASE_InvalidMode)
  188880. err = "Invalid Mode";
  188881. else if (error == ASE_SPNotAdvancing)
  188882. err = "Sample position not advancing";
  188883. else if (error == ASE_NoClock)
  188884. err = "No Clock";
  188885. else if (error == ASE_NoMemory)
  188886. err = "Out of memory";
  188887. log (T("!!error: ") + context + T(" - ") + err);
  188888. }
  188889. #else
  188890. #define logError(a, b) {}
  188891. #endif
  188892. class ASIOAudioIODevice;
  188893. static ASIOAudioIODevice* volatile currentASIODev[3] = { 0, 0, 0 };
  188894. static const int maxASIOChannels = 160;
  188895. class JUCE_API ASIOAudioIODevice : public AudioIODevice,
  188896. private Timer
  188897. {
  188898. public:
  188899. Component ourWindow;
  188900. ASIOAudioIODevice (const String& name_, const CLSID classId_, const int slotNumber,
  188901. const String& optionalDllForDirectLoading_)
  188902. : AudioIODevice (name_, T("ASIO")),
  188903. asioObject (0),
  188904. classId (classId_),
  188905. optionalDllForDirectLoading (optionalDllForDirectLoading_),
  188906. currentBitDepth (16),
  188907. currentSampleRate (0),
  188908. isOpen_ (false),
  188909. isStarted (false),
  188910. postOutput (true),
  188911. insideControlPanelModalLoop (false),
  188912. shouldUsePreferredSize (false)
  188913. {
  188914. name = name_;
  188915. ourWindow.addToDesktop (0);
  188916. windowHandle = ourWindow.getWindowHandle();
  188917. jassert (currentASIODev [slotNumber] == 0);
  188918. currentASIODev [slotNumber] = this;
  188919. openDevice();
  188920. }
  188921. ~ASIOAudioIODevice()
  188922. {
  188923. for (int i = 0; i < numElementsInArray (currentASIODev); ++i)
  188924. if (currentASIODev[i] == this)
  188925. currentASIODev[i] = 0;
  188926. close();
  188927. log ("ASIO - exiting");
  188928. removeCurrentDriver();
  188929. }
  188930. void updateSampleRates()
  188931. {
  188932. // find a list of sample rates..
  188933. const double possibleSampleRates[] = { 44100.0, 48000.0, 88200.0, 96000.0, 176400.0, 192000.0 };
  188934. sampleRates.clear();
  188935. if (asioObject != 0)
  188936. {
  188937. for (int index = 0; index < numElementsInArray (possibleSampleRates); ++index)
  188938. {
  188939. const long err = asioObject->canSampleRate (possibleSampleRates[index]);
  188940. if (err == 0)
  188941. {
  188942. sampleRates.add ((int) possibleSampleRates[index]);
  188943. log (T("rate: ") + String ((int) possibleSampleRates[index]));
  188944. }
  188945. else if (err != ASE_NoClock)
  188946. {
  188947. logError (T("CanSampleRate"), err);
  188948. }
  188949. }
  188950. if (sampleRates.size() == 0)
  188951. {
  188952. double cr = 0;
  188953. const long err = asioObject->getSampleRate (&cr);
  188954. log (T("No sample rates supported - current rate: ") + String ((int) cr));
  188955. if (err == 0)
  188956. sampleRates.add ((int) cr);
  188957. }
  188958. }
  188959. }
  188960. const StringArray getOutputChannelNames()
  188961. {
  188962. return outputChannelNames;
  188963. }
  188964. const StringArray getInputChannelNames()
  188965. {
  188966. return inputChannelNames;
  188967. }
  188968. int getNumSampleRates()
  188969. {
  188970. return sampleRates.size();
  188971. }
  188972. double getSampleRate (int index)
  188973. {
  188974. return sampleRates [index];
  188975. }
  188976. int getNumBufferSizesAvailable()
  188977. {
  188978. return bufferSizes.size();
  188979. }
  188980. int getBufferSizeSamples (int index)
  188981. {
  188982. return bufferSizes [index];
  188983. }
  188984. int getDefaultBufferSize()
  188985. {
  188986. return preferredSize;
  188987. }
  188988. const String open (const BitArray& inputChannels,
  188989. const BitArray& outputChannels,
  188990. double sr,
  188991. int bufferSizeSamples)
  188992. {
  188993. close();
  188994. currentCallback = 0;
  188995. if (bufferSizeSamples <= 0)
  188996. shouldUsePreferredSize = true;
  188997. if (asioObject == 0 || ! isASIOOpen)
  188998. {
  188999. log ("Warning: device not open");
  189000. const String err (openDevice());
  189001. if (asioObject == 0 || ! isASIOOpen)
  189002. return err;
  189003. }
  189004. isStarted = false;
  189005. bufferIndex = -1;
  189006. long err = 0;
  189007. long newPreferredSize = 0;
  189008. // if the preferred size has just changed, assume it's a control panel thing and use it as the new value.
  189009. minSize = 0;
  189010. maxSize = 0;
  189011. newPreferredSize = 0;
  189012. granularity = 0;
  189013. if (asioObject->getBufferSize (&minSize, &maxSize, &newPreferredSize, &granularity) == 0)
  189014. {
  189015. if (preferredSize != 0 && newPreferredSize != 0 && newPreferredSize != preferredSize)
  189016. shouldUsePreferredSize = true;
  189017. preferredSize = newPreferredSize;
  189018. }
  189019. // unfortunate workaround for certain manufacturers whose drivers crash horribly if you make
  189020. // dynamic changes to the buffer size...
  189021. shouldUsePreferredSize = shouldUsePreferredSize
  189022. || getName().containsIgnoreCase (T("Digidesign"));
  189023. if (shouldUsePreferredSize)
  189024. {
  189025. log ("Using preferred size for buffer..");
  189026. if ((err = asioObject->getBufferSize (&minSize, &maxSize, &preferredSize, &granularity)) == 0)
  189027. {
  189028. bufferSizeSamples = preferredSize;
  189029. }
  189030. else
  189031. {
  189032. bufferSizeSamples = 1024;
  189033. logError ("GetBufferSize1", err);
  189034. }
  189035. shouldUsePreferredSize = false;
  189036. }
  189037. int sampleRate = roundDoubleToInt (sr);
  189038. currentSampleRate = sampleRate;
  189039. currentBlockSizeSamples = bufferSizeSamples;
  189040. currentChansOut.clear();
  189041. currentChansIn.clear();
  189042. zeromem (inBuffers, sizeof (inBuffers));
  189043. zeromem (outBuffers, sizeof (outBuffers));
  189044. updateSampleRates();
  189045. if (sampleRate == 0 || (sampleRates.size() > 0 && ! sampleRates.contains (sampleRate)))
  189046. sampleRate = sampleRates[0];
  189047. jassert (sampleRate != 0);
  189048. if (sampleRate == 0)
  189049. sampleRate = 44100;
  189050. long numSources = 32;
  189051. ASIOClockSource clocks[32];
  189052. zeromem (clocks, sizeof (clocks));
  189053. asioObject->getClockSources (clocks, &numSources);
  189054. bool isSourceSet = false;
  189055. // careful not to remove this loop because it does more than just logging!
  189056. int i;
  189057. for (i = 0; i < numSources; ++i)
  189058. {
  189059. String s ("clock: ");
  189060. s += clocks[i].name;
  189061. if (clocks[i].isCurrentSource)
  189062. {
  189063. isSourceSet = true;
  189064. s << " (cur)";
  189065. }
  189066. log (s);
  189067. }
  189068. if (numSources > 1 && ! isSourceSet)
  189069. {
  189070. log ("setting clock source");
  189071. asioObject->setClockSource (clocks[0].index);
  189072. Thread::sleep (20);
  189073. }
  189074. else
  189075. {
  189076. if (numSources == 0)
  189077. {
  189078. log ("ASIO - no clock sources!");
  189079. }
  189080. }
  189081. double cr = 0;
  189082. err = asioObject->getSampleRate (&cr);
  189083. if (err == 0)
  189084. {
  189085. currentSampleRate = cr;
  189086. }
  189087. else
  189088. {
  189089. logError ("GetSampleRate", err);
  189090. currentSampleRate = 0;
  189091. }
  189092. error = String::empty;
  189093. needToReset = false;
  189094. isReSync = false;
  189095. err = 0;
  189096. bool buffersCreated = false;
  189097. if (currentSampleRate != sampleRate)
  189098. {
  189099. log (T("ASIO samplerate: ") + String (currentSampleRate) + T(" to ") + String (sampleRate));
  189100. err = asioObject->setSampleRate (sampleRate);
  189101. if (err == ASE_NoClock && numSources > 0)
  189102. {
  189103. log ("trying to set a clock source..");
  189104. Thread::sleep (10);
  189105. err = asioObject->setClockSource (clocks[0].index);
  189106. if (err != 0)
  189107. {
  189108. logError ("SetClock", err);
  189109. }
  189110. Thread::sleep (10);
  189111. err = asioObject->setSampleRate (sampleRate);
  189112. }
  189113. }
  189114. if (err == 0)
  189115. {
  189116. currentSampleRate = sampleRate;
  189117. if (needToReset)
  189118. {
  189119. if (isReSync)
  189120. {
  189121. log ("Resync request");
  189122. }
  189123. log ("! Resetting ASIO after sample rate change");
  189124. removeCurrentDriver();
  189125. loadDriver();
  189126. const String error (initDriver());
  189127. if (error.isNotEmpty())
  189128. {
  189129. log (T("ASIOInit: ") + error);
  189130. }
  189131. needToReset = false;
  189132. isReSync = false;
  189133. }
  189134. numActiveInputChans = 0;
  189135. numActiveOutputChans = 0;
  189136. ASIOBufferInfo* info = bufferInfos;
  189137. int i;
  189138. for (i = 0; i < totalNumInputChans; ++i)
  189139. {
  189140. if (inputChannels[i])
  189141. {
  189142. currentChansIn.setBit (i);
  189143. info->isInput = 1;
  189144. info->channelNum = i;
  189145. info->buffers[0] = info->buffers[1] = 0;
  189146. ++info;
  189147. ++numActiveInputChans;
  189148. }
  189149. }
  189150. for (i = 0; i < totalNumOutputChans; ++i)
  189151. {
  189152. if (outputChannels[i])
  189153. {
  189154. currentChansOut.setBit (i);
  189155. info->isInput = 0;
  189156. info->channelNum = i;
  189157. info->buffers[0] = info->buffers[1] = 0;
  189158. ++info;
  189159. ++numActiveOutputChans;
  189160. }
  189161. }
  189162. const int totalBuffers = numActiveInputChans + numActiveOutputChans;
  189163. callbacks.sampleRateDidChange = &sampleRateChangedCallback;
  189164. if (currentASIODev[0] == this)
  189165. {
  189166. callbacks.bufferSwitch = &bufferSwitchCallback0;
  189167. callbacks.asioMessage = &asioMessagesCallback0;
  189168. callbacks.bufferSwitchTimeInfo = &bufferSwitchTimeInfoCallback0;
  189169. }
  189170. else if (currentASIODev[1] == this)
  189171. {
  189172. callbacks.bufferSwitch = &bufferSwitchCallback1;
  189173. callbacks.asioMessage = &asioMessagesCallback1;
  189174. callbacks.bufferSwitchTimeInfo = &bufferSwitchTimeInfoCallback1;
  189175. }
  189176. else if (currentASIODev[2] == this)
  189177. {
  189178. callbacks.bufferSwitch = &bufferSwitchCallback2;
  189179. callbacks.asioMessage = &asioMessagesCallback2;
  189180. callbacks.bufferSwitchTimeInfo = &bufferSwitchTimeInfoCallback2;
  189181. }
  189182. else
  189183. {
  189184. jassertfalse
  189185. }
  189186. log ("disposing buffers");
  189187. err = asioObject->disposeBuffers();
  189188. log (T("creating buffers: ") + String (totalBuffers) + T(", ") + String (currentBlockSizeSamples));
  189189. err = asioObject->createBuffers (bufferInfos,
  189190. totalBuffers,
  189191. currentBlockSizeSamples,
  189192. &callbacks);
  189193. if (err != 0)
  189194. {
  189195. currentBlockSizeSamples = preferredSize;
  189196. logError ("create buffers 2", err);
  189197. asioObject->disposeBuffers();
  189198. err = asioObject->createBuffers (bufferInfos,
  189199. totalBuffers,
  189200. currentBlockSizeSamples,
  189201. &callbacks);
  189202. }
  189203. if (err == 0)
  189204. {
  189205. buffersCreated = true;
  189206. tempBuffer.calloc (totalBuffers * currentBlockSizeSamples + 32);
  189207. int n = 0;
  189208. Array <int> types;
  189209. currentBitDepth = 16;
  189210. for (i = 0; i < jmin ((int) totalNumInputChans, maxASIOChannels); ++i)
  189211. {
  189212. if (inputChannels[i])
  189213. {
  189214. inBuffers[n] = tempBuffer + (currentBlockSizeSamples * n);
  189215. ASIOChannelInfo channelInfo;
  189216. zerostruct (channelInfo);
  189217. channelInfo.channel = i;
  189218. channelInfo.isInput = 1;
  189219. asioObject->getChannelInfo (&channelInfo);
  189220. types.addIfNotAlreadyThere (channelInfo.type);
  189221. typeToFormatParameters (channelInfo.type,
  189222. inputChannelBitDepths[n],
  189223. inputChannelBytesPerSample[n],
  189224. inputChannelIsFloat[n],
  189225. inputChannelLittleEndian[n]);
  189226. currentBitDepth = jmax (currentBitDepth, inputChannelBitDepths[n]);
  189227. ++n;
  189228. }
  189229. }
  189230. jassert (numActiveInputChans == n);
  189231. n = 0;
  189232. for (i = 0; i < jmin ((int) totalNumOutputChans, maxASIOChannels); ++i)
  189233. {
  189234. if (outputChannels[i])
  189235. {
  189236. outBuffers[n] = tempBuffer + (currentBlockSizeSamples * (numActiveInputChans + n));
  189237. ASIOChannelInfo channelInfo;
  189238. zerostruct (channelInfo);
  189239. channelInfo.channel = i;
  189240. channelInfo.isInput = 0;
  189241. asioObject->getChannelInfo (&channelInfo);
  189242. types.addIfNotAlreadyThere (channelInfo.type);
  189243. typeToFormatParameters (channelInfo.type,
  189244. outputChannelBitDepths[n],
  189245. outputChannelBytesPerSample[n],
  189246. outputChannelIsFloat[n],
  189247. outputChannelLittleEndian[n]);
  189248. currentBitDepth = jmax (currentBitDepth, outputChannelBitDepths[n]);
  189249. ++n;
  189250. }
  189251. }
  189252. jassert (numActiveOutputChans == n);
  189253. for (i = types.size(); --i >= 0;)
  189254. {
  189255. log (T("channel format: ") + String (types[i]));
  189256. }
  189257. jassert (n <= totalBuffers);
  189258. for (i = 0; i < numActiveOutputChans; ++i)
  189259. {
  189260. const int size = currentBlockSizeSamples * (outputChannelBitDepths[i] >> 3);
  189261. if (bufferInfos [numActiveInputChans + i].buffers[0] == 0
  189262. || bufferInfos [numActiveInputChans + i].buffers[1] == 0)
  189263. {
  189264. log ("!! Null buffers");
  189265. }
  189266. else
  189267. {
  189268. zeromem (bufferInfos[numActiveInputChans + i].buffers[0], size);
  189269. zeromem (bufferInfos[numActiveInputChans + i].buffers[1], size);
  189270. }
  189271. }
  189272. inputLatency = outputLatency = 0;
  189273. if (asioObject->getLatencies (&inputLatency, &outputLatency) != 0)
  189274. {
  189275. log ("ASIO - no latencies");
  189276. }
  189277. else
  189278. {
  189279. log (T("ASIO latencies: ")
  189280. + String ((int) outputLatency)
  189281. + T(", ")
  189282. + String ((int) inputLatency));
  189283. }
  189284. isOpen_ = true;
  189285. log ("starting ASIO");
  189286. calledback = false;
  189287. err = asioObject->start();
  189288. if (err != 0)
  189289. {
  189290. isOpen_ = false;
  189291. log ("ASIO - stop on failure");
  189292. Thread::sleep (10);
  189293. asioObject->stop();
  189294. error = "Can't start device";
  189295. Thread::sleep (10);
  189296. }
  189297. else
  189298. {
  189299. int count = 300;
  189300. while (--count > 0 && ! calledback)
  189301. Thread::sleep (10);
  189302. isStarted = true;
  189303. if (! calledback)
  189304. {
  189305. error = "Device didn't start correctly";
  189306. log ("ASIO didn't callback - stopping..");
  189307. asioObject->stop();
  189308. }
  189309. }
  189310. }
  189311. else
  189312. {
  189313. error = "Can't create i/o buffers";
  189314. }
  189315. }
  189316. else
  189317. {
  189318. error = "Can't set sample rate: ";
  189319. error << sampleRate;
  189320. }
  189321. if (error.isNotEmpty())
  189322. {
  189323. logError (error, err);
  189324. if (asioObject != 0 && buffersCreated)
  189325. asioObject->disposeBuffers();
  189326. Thread::sleep (20);
  189327. isStarted = false;
  189328. isOpen_ = false;
  189329. close();
  189330. }
  189331. needToReset = false;
  189332. isReSync = false;
  189333. return error;
  189334. }
  189335. void close()
  189336. {
  189337. error = String::empty;
  189338. stopTimer();
  189339. stop();
  189340. if (isASIOOpen && isOpen_)
  189341. {
  189342. const ScopedLock sl (callbackLock);
  189343. isOpen_ = false;
  189344. isStarted = false;
  189345. needToReset = false;
  189346. isReSync = false;
  189347. log ("ASIO - stopping");
  189348. if (asioObject != 0)
  189349. {
  189350. Thread::sleep (20);
  189351. asioObject->stop();
  189352. Thread::sleep (10);
  189353. asioObject->disposeBuffers();
  189354. }
  189355. Thread::sleep (10);
  189356. }
  189357. }
  189358. bool isOpen()
  189359. {
  189360. return isOpen_ || insideControlPanelModalLoop;
  189361. }
  189362. int getCurrentBufferSizeSamples()
  189363. {
  189364. return currentBlockSizeSamples;
  189365. }
  189366. double getCurrentSampleRate()
  189367. {
  189368. return currentSampleRate;
  189369. }
  189370. const BitArray getActiveOutputChannels() const
  189371. {
  189372. return currentChansOut;
  189373. }
  189374. const BitArray getActiveInputChannels() const
  189375. {
  189376. return currentChansIn;
  189377. }
  189378. int getCurrentBitDepth()
  189379. {
  189380. return currentBitDepth;
  189381. }
  189382. int getOutputLatencyInSamples()
  189383. {
  189384. return outputLatency + currentBlockSizeSamples / 4;
  189385. }
  189386. int getInputLatencyInSamples()
  189387. {
  189388. return inputLatency + currentBlockSizeSamples / 4;
  189389. }
  189390. void start (AudioIODeviceCallback* callback)
  189391. {
  189392. if (callback != 0)
  189393. {
  189394. callback->audioDeviceAboutToStart (this);
  189395. const ScopedLock sl (callbackLock);
  189396. currentCallback = callback;
  189397. }
  189398. }
  189399. void stop()
  189400. {
  189401. AudioIODeviceCallback* const lastCallback = currentCallback;
  189402. {
  189403. const ScopedLock sl (callbackLock);
  189404. currentCallback = 0;
  189405. }
  189406. if (lastCallback != 0)
  189407. lastCallback->audioDeviceStopped();
  189408. }
  189409. bool isPlaying()
  189410. {
  189411. return isASIOOpen && (currentCallback != 0);
  189412. }
  189413. const String getLastError()
  189414. {
  189415. return error;
  189416. }
  189417. bool hasControlPanel() const
  189418. {
  189419. return true;
  189420. }
  189421. bool showControlPanel()
  189422. {
  189423. log ("ASIO - showing control panel");
  189424. Component modalWindow (String::empty);
  189425. modalWindow.setOpaque (true);
  189426. modalWindow.addToDesktop (0);
  189427. modalWindow.enterModalState();
  189428. bool done = false;
  189429. JUCE_TRY
  189430. {
  189431. // are there are devices that need to be closed before showing their control panel?
  189432. // close();
  189433. insideControlPanelModalLoop = true;
  189434. const uint32 started = Time::getMillisecondCounter();
  189435. if (asioObject != 0)
  189436. {
  189437. asioObject->controlPanel();
  189438. const int spent = (int) Time::getMillisecondCounter() - (int) started;
  189439. log (T("spent: ") + String (spent));
  189440. if (spent > 300)
  189441. {
  189442. shouldUsePreferredSize = true;
  189443. done = true;
  189444. }
  189445. }
  189446. }
  189447. JUCE_CATCH_ALL
  189448. insideControlPanelModalLoop = false;
  189449. return done;
  189450. }
  189451. void resetRequest() throw()
  189452. {
  189453. needToReset = true;
  189454. }
  189455. void resyncRequest() throw()
  189456. {
  189457. needToReset = true;
  189458. isReSync = true;
  189459. }
  189460. void timerCallback()
  189461. {
  189462. if (! insideControlPanelModalLoop)
  189463. {
  189464. stopTimer();
  189465. // used to cause a reset
  189466. log ("! ASIO restart request!");
  189467. if (isOpen_)
  189468. {
  189469. AudioIODeviceCallback* const oldCallback = currentCallback;
  189470. close();
  189471. open (BitArray (currentChansIn), BitArray (currentChansOut),
  189472. currentSampleRate, currentBlockSizeSamples);
  189473. if (oldCallback != 0)
  189474. start (oldCallback);
  189475. }
  189476. }
  189477. else
  189478. {
  189479. startTimer (100);
  189480. }
  189481. }
  189482. juce_UseDebuggingNewOperator
  189483. private:
  189484. IASIO* volatile asioObject;
  189485. ASIOCallbacks callbacks;
  189486. void* windowHandle;
  189487. CLSID classId;
  189488. const String optionalDllForDirectLoading;
  189489. String error;
  189490. long totalNumInputChans, totalNumOutputChans;
  189491. StringArray inputChannelNames, outputChannelNames;
  189492. Array<int> sampleRates, bufferSizes;
  189493. long inputLatency, outputLatency;
  189494. long minSize, maxSize, preferredSize, granularity;
  189495. int volatile currentBlockSizeSamples;
  189496. int volatile currentBitDepth;
  189497. double volatile currentSampleRate;
  189498. BitArray currentChansOut, currentChansIn;
  189499. AudioIODeviceCallback* volatile currentCallback;
  189500. CriticalSection callbackLock;
  189501. ASIOBufferInfo bufferInfos [maxASIOChannels];
  189502. float* inBuffers [maxASIOChannels];
  189503. float* outBuffers [maxASIOChannels];
  189504. int inputChannelBitDepths [maxASIOChannels];
  189505. int outputChannelBitDepths [maxASIOChannels];
  189506. int inputChannelBytesPerSample [maxASIOChannels];
  189507. int outputChannelBytesPerSample [maxASIOChannels];
  189508. bool inputChannelIsFloat [maxASIOChannels];
  189509. bool outputChannelIsFloat [maxASIOChannels];
  189510. bool inputChannelLittleEndian [maxASIOChannels];
  189511. bool outputChannelLittleEndian [maxASIOChannels];
  189512. WaitableEvent event1;
  189513. HeapBlock <float> tempBuffer;
  189514. int volatile bufferIndex, numActiveInputChans, numActiveOutputChans;
  189515. bool isOpen_, isStarted;
  189516. bool volatile isASIOOpen;
  189517. bool volatile calledback;
  189518. bool volatile littleEndian, postOutput, needToReset, isReSync;
  189519. bool volatile insideControlPanelModalLoop;
  189520. bool volatile shouldUsePreferredSize;
  189521. void removeCurrentDriver()
  189522. {
  189523. if (asioObject != 0)
  189524. {
  189525. asioObject->Release();
  189526. asioObject = 0;
  189527. }
  189528. }
  189529. bool loadDriver()
  189530. {
  189531. removeCurrentDriver();
  189532. JUCE_TRY
  189533. {
  189534. if (CoCreateInstance (classId, 0, CLSCTX_INPROC_SERVER,
  189535. classId, (void**) &asioObject) == S_OK)
  189536. {
  189537. return true;
  189538. }
  189539. // If a class isn't registered but we have a path for it, we can fallback to
  189540. // doing a direct load of the COM object (only available via the juce_createASIOAudioIODeviceForGUID function).
  189541. if (optionalDllForDirectLoading.isNotEmpty())
  189542. {
  189543. HMODULE h = LoadLibrary (optionalDllForDirectLoading);
  189544. if (h != 0)
  189545. {
  189546. typedef HRESULT (CALLBACK* DllGetClassObjectFunc) (REFCLSID clsid, REFIID iid, LPVOID* ppv);
  189547. DllGetClassObjectFunc dllGetClassObject = (DllGetClassObjectFunc) GetProcAddress (h, "DllGetClassObject");
  189548. if (dllGetClassObject != 0)
  189549. {
  189550. IClassFactory* classFactory = 0;
  189551. HRESULT hr = dllGetClassObject (classId, IID_IClassFactory, (void**) &classFactory);
  189552. if (classFactory != 0)
  189553. {
  189554. hr = classFactory->CreateInstance (0, classId, (void**) &asioObject);
  189555. classFactory->Release();
  189556. }
  189557. return asioObject != 0;
  189558. }
  189559. }
  189560. }
  189561. }
  189562. JUCE_CATCH_ALL
  189563. asioObject = 0;
  189564. return false;
  189565. }
  189566. const String initDriver()
  189567. {
  189568. if (asioObject != 0)
  189569. {
  189570. char buffer [256];
  189571. zeromem (buffer, sizeof (buffer));
  189572. if (! asioObject->init (windowHandle))
  189573. {
  189574. asioObject->getErrorMessage (buffer);
  189575. return String (buffer, sizeof (buffer) - 1);
  189576. }
  189577. // just in case any daft drivers expect this to be called..
  189578. asioObject->getDriverName (buffer);
  189579. return String::empty;
  189580. }
  189581. return "No Driver";
  189582. }
  189583. const String openDevice()
  189584. {
  189585. // use this in case the driver starts opening dialog boxes..
  189586. Component modalWindow (String::empty);
  189587. modalWindow.setOpaque (true);
  189588. modalWindow.addToDesktop (0);
  189589. modalWindow.enterModalState();
  189590. // open the device and get its info..
  189591. log (T("opening ASIO device: ") + getName());
  189592. needToReset = false;
  189593. isReSync = false;
  189594. outputChannelNames.clear();
  189595. inputChannelNames.clear();
  189596. bufferSizes.clear();
  189597. sampleRates.clear();
  189598. isASIOOpen = false;
  189599. isOpen_ = false;
  189600. totalNumInputChans = 0;
  189601. totalNumOutputChans = 0;
  189602. numActiveInputChans = 0;
  189603. numActiveOutputChans = 0;
  189604. currentCallback = 0;
  189605. error = String::empty;
  189606. if (getName().isEmpty())
  189607. return error;
  189608. long err = 0;
  189609. if (loadDriver())
  189610. {
  189611. if ((error = initDriver()).isEmpty())
  189612. {
  189613. numActiveInputChans = 0;
  189614. numActiveOutputChans = 0;
  189615. totalNumInputChans = 0;
  189616. totalNumOutputChans = 0;
  189617. if (asioObject != 0
  189618. && (err = asioObject->getChannels (&totalNumInputChans, &totalNumOutputChans)) == 0)
  189619. {
  189620. log (String ((int) totalNumInputChans) + T(" in, ") + String ((int) totalNumOutputChans) + T(" out"));
  189621. if ((err = asioObject->getBufferSize (&minSize, &maxSize, &preferredSize, &granularity)) == 0)
  189622. {
  189623. // find a list of buffer sizes..
  189624. log (String ((int) minSize) + T(" ") + String ((int) maxSize) + T(" ") + String ((int)preferredSize) + T(" ") + String ((int)granularity));
  189625. if (granularity >= 0)
  189626. {
  189627. granularity = jmax (1, (int) granularity);
  189628. for (int i = jmax ((int) minSize, (int) granularity); i < jmin (6400, (int) maxSize); i += granularity)
  189629. bufferSizes.addIfNotAlreadyThere (granularity * (i / granularity));
  189630. }
  189631. else if (granularity < 0)
  189632. {
  189633. for (int i = 0; i < 18; ++i)
  189634. {
  189635. const int s = (1 << i);
  189636. if (s >= minSize && s <= maxSize)
  189637. bufferSizes.add (s);
  189638. }
  189639. }
  189640. if (! bufferSizes.contains (preferredSize))
  189641. bufferSizes.insert (0, preferredSize);
  189642. double currentRate = 0;
  189643. asioObject->getSampleRate (&currentRate);
  189644. if (currentRate <= 0.0 || currentRate > 192001.0)
  189645. {
  189646. log ("setting sample rate");
  189647. err = asioObject->setSampleRate (44100.0);
  189648. if (err != 0)
  189649. {
  189650. logError ("setting sample rate", err);
  189651. }
  189652. asioObject->getSampleRate (&currentRate);
  189653. }
  189654. currentSampleRate = currentRate;
  189655. postOutput = (asioObject->outputReady() == 0);
  189656. if (postOutput)
  189657. {
  189658. log ("ASIO outputReady = ok");
  189659. }
  189660. updateSampleRates();
  189661. // ..because cubase does it at this point
  189662. inputLatency = outputLatency = 0;
  189663. if (asioObject->getLatencies (&inputLatency, &outputLatency) != 0)
  189664. {
  189665. log ("ASIO - no latencies");
  189666. }
  189667. log (String ("latencies: ")
  189668. + String ((int) inputLatency)
  189669. + T(", ") + String ((int) outputLatency));
  189670. // create some dummy buffers now.. because cubase does..
  189671. numActiveInputChans = 0;
  189672. numActiveOutputChans = 0;
  189673. ASIOBufferInfo* info = bufferInfos;
  189674. int i, numChans = 0;
  189675. for (i = 0; i < jmin (2, (int) totalNumInputChans); ++i)
  189676. {
  189677. info->isInput = 1;
  189678. info->channelNum = i;
  189679. info->buffers[0] = info->buffers[1] = 0;
  189680. ++info;
  189681. ++numChans;
  189682. }
  189683. const int outputBufferIndex = numChans;
  189684. for (i = 0; i < jmin (2, (int) totalNumOutputChans); ++i)
  189685. {
  189686. info->isInput = 0;
  189687. info->channelNum = i;
  189688. info->buffers[0] = info->buffers[1] = 0;
  189689. ++info;
  189690. ++numChans;
  189691. }
  189692. callbacks.sampleRateDidChange = &sampleRateChangedCallback;
  189693. if (currentASIODev[0] == this)
  189694. {
  189695. callbacks.bufferSwitch = &bufferSwitchCallback0;
  189696. callbacks.asioMessage = &asioMessagesCallback0;
  189697. callbacks.bufferSwitchTimeInfo = &bufferSwitchTimeInfoCallback0;
  189698. }
  189699. else if (currentASIODev[1] == this)
  189700. {
  189701. callbacks.bufferSwitch = &bufferSwitchCallback1;
  189702. callbacks.asioMessage = &asioMessagesCallback1;
  189703. callbacks.bufferSwitchTimeInfo = &bufferSwitchTimeInfoCallback1;
  189704. }
  189705. else if (currentASIODev[2] == this)
  189706. {
  189707. callbacks.bufferSwitch = &bufferSwitchCallback2;
  189708. callbacks.asioMessage = &asioMessagesCallback2;
  189709. callbacks.bufferSwitchTimeInfo = &bufferSwitchTimeInfoCallback2;
  189710. }
  189711. else
  189712. {
  189713. jassertfalse
  189714. }
  189715. log (T("creating buffers (dummy): ") + String (numChans)
  189716. + T(", ") + String ((int) preferredSize));
  189717. if (preferredSize > 0)
  189718. {
  189719. err = asioObject->createBuffers (bufferInfos, numChans, preferredSize, &callbacks);
  189720. if (err != 0)
  189721. {
  189722. logError ("dummy buffers", err);
  189723. }
  189724. }
  189725. long newInps = 0, newOuts = 0;
  189726. asioObject->getChannels (&newInps, &newOuts);
  189727. if (totalNumInputChans != newInps || totalNumOutputChans != newOuts)
  189728. {
  189729. totalNumInputChans = newInps;
  189730. totalNumOutputChans = newOuts;
  189731. log (String ((int) totalNumInputChans) + T(" in; ")
  189732. + String ((int) totalNumOutputChans) + T(" out"));
  189733. }
  189734. updateSampleRates();
  189735. ASIOChannelInfo channelInfo;
  189736. channelInfo.type = 0;
  189737. for (i = 0; i < totalNumInputChans; ++i)
  189738. {
  189739. zerostruct (channelInfo);
  189740. channelInfo.channel = i;
  189741. channelInfo.isInput = 1;
  189742. asioObject->getChannelInfo (&channelInfo);
  189743. inputChannelNames.add (String (channelInfo.name));
  189744. }
  189745. for (i = 0; i < totalNumOutputChans; ++i)
  189746. {
  189747. zerostruct (channelInfo);
  189748. channelInfo.channel = i;
  189749. channelInfo.isInput = 0;
  189750. asioObject->getChannelInfo (&channelInfo);
  189751. outputChannelNames.add (String (channelInfo.name));
  189752. typeToFormatParameters (channelInfo.type,
  189753. outputChannelBitDepths[i],
  189754. outputChannelBytesPerSample[i],
  189755. outputChannelIsFloat[i],
  189756. outputChannelLittleEndian[i]);
  189757. if (i < 2)
  189758. {
  189759. // clear the channels that are used with the dummy stuff
  189760. const int bytesPerBuffer = preferredSize * (outputChannelBitDepths[i] >> 3);
  189761. zeromem (bufferInfos [outputBufferIndex + i].buffers[0], bytesPerBuffer);
  189762. zeromem (bufferInfos [outputBufferIndex + i].buffers[1], bytesPerBuffer);
  189763. }
  189764. }
  189765. outputChannelNames.trim();
  189766. inputChannelNames.trim();
  189767. outputChannelNames.appendNumbersToDuplicates (false, true);
  189768. inputChannelNames.appendNumbersToDuplicates (false, true);
  189769. // start and stop because cubase does it..
  189770. asioObject->getLatencies (&inputLatency, &outputLatency);
  189771. if ((err = asioObject->start()) != 0)
  189772. {
  189773. // ignore an error here, as it might start later after setting other stuff up
  189774. logError ("ASIO start", err);
  189775. }
  189776. Thread::sleep (100);
  189777. asioObject->stop();
  189778. }
  189779. else
  189780. {
  189781. error = "Can't detect buffer sizes";
  189782. }
  189783. }
  189784. else
  189785. {
  189786. error = "Can't detect asio channels";
  189787. }
  189788. }
  189789. }
  189790. else
  189791. {
  189792. error = "No such device";
  189793. }
  189794. if (error.isNotEmpty())
  189795. {
  189796. logError (error, err);
  189797. if (asioObject != 0)
  189798. asioObject->disposeBuffers();
  189799. removeCurrentDriver();
  189800. isASIOOpen = false;
  189801. }
  189802. else
  189803. {
  189804. isASIOOpen = true;
  189805. log ("ASIO device open");
  189806. }
  189807. isOpen_ = false;
  189808. needToReset = false;
  189809. isReSync = false;
  189810. return error;
  189811. }
  189812. void callback (const long index) throw()
  189813. {
  189814. if (isStarted)
  189815. {
  189816. bufferIndex = index;
  189817. processBuffer();
  189818. }
  189819. else
  189820. {
  189821. if (postOutput && (asioObject != 0))
  189822. asioObject->outputReady();
  189823. }
  189824. calledback = true;
  189825. }
  189826. void processBuffer() throw()
  189827. {
  189828. const ASIOBufferInfo* const infos = bufferInfos;
  189829. const int bi = bufferIndex;
  189830. const ScopedLock sl (callbackLock);
  189831. if (needToReset)
  189832. {
  189833. needToReset = false;
  189834. if (isReSync)
  189835. {
  189836. log ("! ASIO resync");
  189837. isReSync = false;
  189838. }
  189839. else
  189840. {
  189841. startTimer (20);
  189842. }
  189843. }
  189844. if (bi >= 0)
  189845. {
  189846. const int samps = currentBlockSizeSamples;
  189847. if (currentCallback != 0)
  189848. {
  189849. int i;
  189850. for (i = 0; i < numActiveInputChans; ++i)
  189851. {
  189852. float* const dst = inBuffers[i];
  189853. jassert (dst != 0);
  189854. const char* const src = (const char*) (infos[i].buffers[bi]);
  189855. if (inputChannelIsFloat[i])
  189856. {
  189857. memcpy (dst, src, samps * sizeof (float));
  189858. }
  189859. else
  189860. {
  189861. jassert (dst == tempBuffer + (samps * i));
  189862. switch (inputChannelBitDepths[i])
  189863. {
  189864. case 16:
  189865. convertInt16ToFloat (src, dst, inputChannelBytesPerSample[i],
  189866. samps, inputChannelLittleEndian[i]);
  189867. break;
  189868. case 24:
  189869. convertInt24ToFloat (src, dst, inputChannelBytesPerSample[i],
  189870. samps, inputChannelLittleEndian[i]);
  189871. break;
  189872. case 32:
  189873. convertInt32ToFloat (src, dst, inputChannelBytesPerSample[i],
  189874. samps, inputChannelLittleEndian[i]);
  189875. break;
  189876. case 64:
  189877. jassertfalse
  189878. break;
  189879. }
  189880. }
  189881. }
  189882. currentCallback->audioDeviceIOCallback ((const float**) inBuffers,
  189883. numActiveInputChans,
  189884. outBuffers,
  189885. numActiveOutputChans,
  189886. samps);
  189887. for (i = 0; i < numActiveOutputChans; ++i)
  189888. {
  189889. float* const src = outBuffers[i];
  189890. jassert (src != 0);
  189891. char* const dst = (char*) (infos [numActiveInputChans + i].buffers[bi]);
  189892. if (outputChannelIsFloat[i])
  189893. {
  189894. memcpy (dst, src, samps * sizeof (float));
  189895. }
  189896. else
  189897. {
  189898. jassert (src == tempBuffer + (samps * (numActiveInputChans + i)));
  189899. switch (outputChannelBitDepths[i])
  189900. {
  189901. case 16:
  189902. convertFloatToInt16 (src, dst, outputChannelBytesPerSample[i],
  189903. samps, outputChannelLittleEndian[i]);
  189904. break;
  189905. case 24:
  189906. convertFloatToInt24 (src, dst, outputChannelBytesPerSample[i],
  189907. samps, outputChannelLittleEndian[i]);
  189908. break;
  189909. case 32:
  189910. convertFloatToInt32 (src, dst, outputChannelBytesPerSample[i],
  189911. samps, outputChannelLittleEndian[i]);
  189912. break;
  189913. case 64:
  189914. jassertfalse
  189915. break;
  189916. }
  189917. }
  189918. }
  189919. }
  189920. else
  189921. {
  189922. for (int i = 0; i < numActiveOutputChans; ++i)
  189923. {
  189924. const int bytesPerBuffer = samps * (outputChannelBitDepths[i] >> 3);
  189925. zeromem (infos[numActiveInputChans + i].buffers[bi], bytesPerBuffer);
  189926. }
  189927. }
  189928. }
  189929. if (postOutput)
  189930. asioObject->outputReady();
  189931. }
  189932. static ASIOTime* bufferSwitchTimeInfoCallback0 (ASIOTime*, long index, long) throw()
  189933. {
  189934. if (currentASIODev[0] != 0)
  189935. currentASIODev[0]->callback (index);
  189936. return 0;
  189937. }
  189938. static ASIOTime* bufferSwitchTimeInfoCallback1 (ASIOTime*, long index, long) throw()
  189939. {
  189940. if (currentASIODev[1] != 0)
  189941. currentASIODev[1]->callback (index);
  189942. return 0;
  189943. }
  189944. static ASIOTime* bufferSwitchTimeInfoCallback2 (ASIOTime*, long index, long) throw()
  189945. {
  189946. if (currentASIODev[2] != 0)
  189947. currentASIODev[2]->callback (index);
  189948. return 0;
  189949. }
  189950. static void bufferSwitchCallback0 (long index, long) throw()
  189951. {
  189952. if (currentASIODev[0] != 0)
  189953. currentASIODev[0]->callback (index);
  189954. }
  189955. static void bufferSwitchCallback1 (long index, long) throw()
  189956. {
  189957. if (currentASIODev[1] != 0)
  189958. currentASIODev[1]->callback (index);
  189959. }
  189960. static void bufferSwitchCallback2 (long index, long) throw()
  189961. {
  189962. if (currentASIODev[2] != 0)
  189963. currentASIODev[2]->callback (index);
  189964. }
  189965. static long asioMessagesCallback0 (long selector, long value, void*, double*) throw()
  189966. {
  189967. return asioMessagesCallback (selector, value, 0);
  189968. }
  189969. static long asioMessagesCallback1 (long selector, long value, void*, double*) throw()
  189970. {
  189971. return asioMessagesCallback (selector, value, 1);
  189972. }
  189973. static long asioMessagesCallback2 (long selector, long value, void*, double*) throw()
  189974. {
  189975. return asioMessagesCallback (selector, value, 2);
  189976. }
  189977. static long asioMessagesCallback (long selector, long value, const int deviceIndex) throw()
  189978. {
  189979. switch (selector)
  189980. {
  189981. case kAsioSelectorSupported:
  189982. if (value == kAsioResetRequest
  189983. || value == kAsioEngineVersion
  189984. || value == kAsioResyncRequest
  189985. || value == kAsioLatenciesChanged
  189986. || value == kAsioSupportsInputMonitor)
  189987. return 1;
  189988. break;
  189989. case kAsioBufferSizeChange:
  189990. break;
  189991. case kAsioResetRequest:
  189992. if (currentASIODev[deviceIndex] != 0)
  189993. currentASIODev[deviceIndex]->resetRequest();
  189994. return 1;
  189995. case kAsioResyncRequest:
  189996. if (currentASIODev[deviceIndex] != 0)
  189997. currentASIODev[deviceIndex]->resyncRequest();
  189998. return 1;
  189999. case kAsioLatenciesChanged:
  190000. return 1;
  190001. case kAsioEngineVersion:
  190002. return 2;
  190003. case kAsioSupportsTimeInfo:
  190004. case kAsioSupportsTimeCode:
  190005. return 0;
  190006. }
  190007. return 0;
  190008. }
  190009. static void sampleRateChangedCallback (ASIOSampleRate) throw()
  190010. {
  190011. }
  190012. static void convertInt16ToFloat (const char* src,
  190013. float* dest,
  190014. const int srcStrideBytes,
  190015. int numSamples,
  190016. const bool littleEndian) throw()
  190017. {
  190018. const double g = 1.0 / 32768.0;
  190019. if (littleEndian)
  190020. {
  190021. while (--numSamples >= 0)
  190022. {
  190023. *dest++ = (float) (g * (short) ByteOrder::littleEndianShort (src));
  190024. src += srcStrideBytes;
  190025. }
  190026. }
  190027. else
  190028. {
  190029. while (--numSamples >= 0)
  190030. {
  190031. *dest++ = (float) (g * (short) ByteOrder::bigEndianShort (src));
  190032. src += srcStrideBytes;
  190033. }
  190034. }
  190035. }
  190036. static void convertFloatToInt16 (const float* src,
  190037. char* dest,
  190038. const int dstStrideBytes,
  190039. int numSamples,
  190040. const bool littleEndian) throw()
  190041. {
  190042. const double maxVal = (double) 0x7fff;
  190043. if (littleEndian)
  190044. {
  190045. while (--numSamples >= 0)
  190046. {
  190047. *(uint16*) dest = ByteOrder::swapIfBigEndian ((uint16) (short) roundDoubleToInt (jlimit (-maxVal, maxVal, maxVal * *src++)));
  190048. dest += dstStrideBytes;
  190049. }
  190050. }
  190051. else
  190052. {
  190053. while (--numSamples >= 0)
  190054. {
  190055. *(uint16*) dest = ByteOrder::swapIfLittleEndian ((uint16) (short) roundDoubleToInt (jlimit (-maxVal, maxVal, maxVal * *src++)));
  190056. dest += dstStrideBytes;
  190057. }
  190058. }
  190059. }
  190060. static void convertInt24ToFloat (const char* src,
  190061. float* dest,
  190062. const int srcStrideBytes,
  190063. int numSamples,
  190064. const bool littleEndian) throw()
  190065. {
  190066. const double g = 1.0 / 0x7fffff;
  190067. if (littleEndian)
  190068. {
  190069. while (--numSamples >= 0)
  190070. {
  190071. *dest++ = (float) (g * ByteOrder::littleEndian24Bit (src));
  190072. src += srcStrideBytes;
  190073. }
  190074. }
  190075. else
  190076. {
  190077. while (--numSamples >= 0)
  190078. {
  190079. *dest++ = (float) (g * ByteOrder::bigEndian24Bit (src));
  190080. src += srcStrideBytes;
  190081. }
  190082. }
  190083. }
  190084. static void convertFloatToInt24 (const float* src,
  190085. char* dest,
  190086. const int dstStrideBytes,
  190087. int numSamples,
  190088. const bool littleEndian) throw()
  190089. {
  190090. const double maxVal = (double) 0x7fffff;
  190091. if (littleEndian)
  190092. {
  190093. while (--numSamples >= 0)
  190094. {
  190095. ByteOrder::littleEndian24BitToChars ((uint32) roundDoubleToInt (jlimit (-maxVal, maxVal, maxVal * *src++)), dest);
  190096. dest += dstStrideBytes;
  190097. }
  190098. }
  190099. else
  190100. {
  190101. while (--numSamples >= 0)
  190102. {
  190103. ByteOrder::bigEndian24BitToChars ((uint32) roundDoubleToInt (jlimit (-maxVal, maxVal, maxVal * *src++)), dest);
  190104. dest += dstStrideBytes;
  190105. }
  190106. }
  190107. }
  190108. static void convertInt32ToFloat (const char* src,
  190109. float* dest,
  190110. const int srcStrideBytes,
  190111. int numSamples,
  190112. const bool littleEndian) throw()
  190113. {
  190114. const double g = 1.0 / 0x7fffffff;
  190115. if (littleEndian)
  190116. {
  190117. while (--numSamples >= 0)
  190118. {
  190119. *dest++ = (float) (g * (int) ByteOrder::littleEndianInt (src));
  190120. src += srcStrideBytes;
  190121. }
  190122. }
  190123. else
  190124. {
  190125. while (--numSamples >= 0)
  190126. {
  190127. *dest++ = (float) (g * (int) ByteOrder::bigEndianInt (src));
  190128. src += srcStrideBytes;
  190129. }
  190130. }
  190131. }
  190132. static void convertFloatToInt32 (const float* src,
  190133. char* dest,
  190134. const int dstStrideBytes,
  190135. int numSamples,
  190136. const bool littleEndian) throw()
  190137. {
  190138. const double maxVal = (double) 0x7fffffff;
  190139. if (littleEndian)
  190140. {
  190141. while (--numSamples >= 0)
  190142. {
  190143. *(uint32*) dest = ByteOrder::swapIfBigEndian ((uint32) roundDoubleToInt (jlimit (-maxVal, maxVal, maxVal * *src++)));
  190144. dest += dstStrideBytes;
  190145. }
  190146. }
  190147. else
  190148. {
  190149. while (--numSamples >= 0)
  190150. {
  190151. *(uint32*) dest = ByteOrder::swapIfLittleEndian ((uint32) roundDoubleToInt (jlimit (-maxVal, maxVal, maxVal * *src++)));
  190152. dest += dstStrideBytes;
  190153. }
  190154. }
  190155. }
  190156. static void typeToFormatParameters (const long type,
  190157. int& bitDepth,
  190158. int& byteStride,
  190159. bool& formatIsFloat,
  190160. bool& littleEndian) throw()
  190161. {
  190162. bitDepth = 0;
  190163. littleEndian = false;
  190164. formatIsFloat = false;
  190165. switch (type)
  190166. {
  190167. case ASIOSTInt16MSB:
  190168. case ASIOSTInt16LSB:
  190169. case ASIOSTInt32MSB16:
  190170. case ASIOSTInt32LSB16:
  190171. bitDepth = 16; break;
  190172. case ASIOSTFloat32MSB:
  190173. case ASIOSTFloat32LSB:
  190174. formatIsFloat = true;
  190175. bitDepth = 32; break;
  190176. case ASIOSTInt32MSB:
  190177. case ASIOSTInt32LSB:
  190178. bitDepth = 32; break;
  190179. case ASIOSTInt24MSB:
  190180. case ASIOSTInt24LSB:
  190181. case ASIOSTInt32MSB24:
  190182. case ASIOSTInt32LSB24:
  190183. case ASIOSTInt32MSB18:
  190184. case ASIOSTInt32MSB20:
  190185. case ASIOSTInt32LSB18:
  190186. case ASIOSTInt32LSB20:
  190187. bitDepth = 24; break;
  190188. case ASIOSTFloat64MSB:
  190189. case ASIOSTFloat64LSB:
  190190. default:
  190191. bitDepth = 64;
  190192. break;
  190193. }
  190194. switch (type)
  190195. {
  190196. case ASIOSTInt16MSB:
  190197. case ASIOSTInt32MSB16:
  190198. case ASIOSTFloat32MSB:
  190199. case ASIOSTFloat64MSB:
  190200. case ASIOSTInt32MSB:
  190201. case ASIOSTInt32MSB18:
  190202. case ASIOSTInt32MSB20:
  190203. case ASIOSTInt32MSB24:
  190204. case ASIOSTInt24MSB:
  190205. littleEndian = false; break;
  190206. case ASIOSTInt16LSB:
  190207. case ASIOSTInt32LSB16:
  190208. case ASIOSTFloat32LSB:
  190209. case ASIOSTFloat64LSB:
  190210. case ASIOSTInt32LSB:
  190211. case ASIOSTInt32LSB18:
  190212. case ASIOSTInt32LSB20:
  190213. case ASIOSTInt32LSB24:
  190214. case ASIOSTInt24LSB:
  190215. littleEndian = true; break;
  190216. default:
  190217. break;
  190218. }
  190219. switch (type)
  190220. {
  190221. case ASIOSTInt16LSB:
  190222. case ASIOSTInt16MSB:
  190223. byteStride = 2; break;
  190224. case ASIOSTInt24LSB:
  190225. case ASIOSTInt24MSB:
  190226. byteStride = 3; break;
  190227. case ASIOSTInt32MSB16:
  190228. case ASIOSTInt32LSB16:
  190229. case ASIOSTInt32MSB:
  190230. case ASIOSTInt32MSB18:
  190231. case ASIOSTInt32MSB20:
  190232. case ASIOSTInt32MSB24:
  190233. case ASIOSTInt32LSB:
  190234. case ASIOSTInt32LSB18:
  190235. case ASIOSTInt32LSB20:
  190236. case ASIOSTInt32LSB24:
  190237. case ASIOSTFloat32LSB:
  190238. case ASIOSTFloat32MSB:
  190239. byteStride = 4; break;
  190240. case ASIOSTFloat64MSB:
  190241. case ASIOSTFloat64LSB:
  190242. byteStride = 8; break;
  190243. default:
  190244. break;
  190245. }
  190246. }
  190247. };
  190248. class ASIOAudioIODeviceType : public AudioIODeviceType
  190249. {
  190250. public:
  190251. ASIOAudioIODeviceType()
  190252. : AudioIODeviceType (T("ASIO")),
  190253. hasScanned (false)
  190254. {
  190255. CoInitialize (0);
  190256. }
  190257. ~ASIOAudioIODeviceType()
  190258. {
  190259. }
  190260. void scanForDevices()
  190261. {
  190262. hasScanned = true;
  190263. deviceNames.clear();
  190264. classIds.clear();
  190265. HKEY hk = 0;
  190266. int index = 0;
  190267. if (RegOpenKeyA (HKEY_LOCAL_MACHINE, "software\\asio", &hk) == ERROR_SUCCESS)
  190268. {
  190269. for (;;)
  190270. {
  190271. char name [256];
  190272. if (RegEnumKeyA (hk, index++, name, 256) == ERROR_SUCCESS)
  190273. {
  190274. addDriverInfo (name, hk);
  190275. }
  190276. else
  190277. {
  190278. break;
  190279. }
  190280. }
  190281. RegCloseKey (hk);
  190282. }
  190283. }
  190284. const StringArray getDeviceNames (const bool /*wantInputNames*/) const
  190285. {
  190286. jassert (hasScanned); // need to call scanForDevices() before doing this
  190287. return deviceNames;
  190288. }
  190289. int getDefaultDeviceIndex (const bool) const
  190290. {
  190291. jassert (hasScanned); // need to call scanForDevices() before doing this
  190292. for (int i = deviceNames.size(); --i >= 0;)
  190293. if (deviceNames[i].containsIgnoreCase (T("asio4all")))
  190294. return i; // asio4all is a safe choice for a default..
  190295. #if JUCE_DEBUG
  190296. if (deviceNames.size() > 1 && deviceNames[0].containsIgnoreCase (T("digidesign")))
  190297. return 1; // (the digi m-box driver crashes the app when you run
  190298. // it in the debugger, which can be a bit annoying)
  190299. #endif
  190300. return 0;
  190301. }
  190302. static int findFreeSlot()
  190303. {
  190304. for (int i = 0; i < numElementsInArray (currentASIODev); ++i)
  190305. if (currentASIODev[i] == 0)
  190306. return i;
  190307. jassertfalse; // unfortunately you can only have a finite number
  190308. // of ASIO devices open at the same time..
  190309. return -1;
  190310. }
  190311. int getIndexOfDevice (AudioIODevice* d, const bool /*asInput*/) const
  190312. {
  190313. jassert (hasScanned); // need to call scanForDevices() before doing this
  190314. return d == 0 ? -1 : deviceNames.indexOf (d->getName());
  190315. }
  190316. bool hasSeparateInputsAndOutputs() const { return false; }
  190317. AudioIODevice* createDevice (const String& outputDeviceName,
  190318. const String& inputDeviceName)
  190319. {
  190320. // ASIO can't open two different devices for input and output - they must be the same one.
  190321. jassert (inputDeviceName == outputDeviceName || outputDeviceName.isEmpty() || inputDeviceName.isEmpty());
  190322. jassert (hasScanned); // need to call scanForDevices() before doing this
  190323. const int index = deviceNames.indexOf (outputDeviceName.isNotEmpty() ? outputDeviceName
  190324. : inputDeviceName);
  190325. if (index >= 0)
  190326. {
  190327. const int freeSlot = findFreeSlot();
  190328. if (freeSlot >= 0)
  190329. return new ASIOAudioIODevice (outputDeviceName, *(classIds [index]), freeSlot, String::empty);
  190330. }
  190331. return 0;
  190332. }
  190333. juce_UseDebuggingNewOperator
  190334. private:
  190335. StringArray deviceNames;
  190336. OwnedArray <CLSID> classIds;
  190337. bool hasScanned;
  190338. static bool checkClassIsOk (const String& classId)
  190339. {
  190340. HKEY hk = 0;
  190341. bool ok = false;
  190342. if (RegOpenKeyA (HKEY_CLASSES_ROOT, "clsid", &hk) == ERROR_SUCCESS)
  190343. {
  190344. int index = 0;
  190345. for (;;)
  190346. {
  190347. char buf [512];
  190348. if (RegEnumKeyA (hk, index++, buf, 512) == ERROR_SUCCESS)
  190349. {
  190350. if (classId.equalsIgnoreCase (buf))
  190351. {
  190352. HKEY subKey, pathKey;
  190353. if (RegOpenKeyExA (hk, buf, 0, KEY_READ, &subKey) == ERROR_SUCCESS)
  190354. {
  190355. if (RegOpenKeyExA (subKey, "InprocServer32", 0, KEY_READ, &pathKey) == ERROR_SUCCESS)
  190356. {
  190357. char pathName [600];
  190358. DWORD dtype = REG_SZ;
  190359. DWORD dsize = sizeof (pathName);
  190360. if (RegQueryValueExA (pathKey, 0, 0, &dtype,
  190361. (LPBYTE) pathName, &dsize) == ERROR_SUCCESS)
  190362. {
  190363. OFSTRUCT of;
  190364. zerostruct (of);
  190365. of.cBytes = sizeof (of);
  190366. ok = (OpenFile (String (pathName), &of, OF_EXIST) != 0);
  190367. }
  190368. RegCloseKey (pathKey);
  190369. }
  190370. RegCloseKey (subKey);
  190371. }
  190372. break;
  190373. }
  190374. }
  190375. else
  190376. {
  190377. break;
  190378. }
  190379. }
  190380. RegCloseKey (hk);
  190381. }
  190382. return ok;
  190383. }
  190384. void addDriverInfo (const String& keyName, HKEY hk)
  190385. {
  190386. HKEY subKey;
  190387. if (RegOpenKeyExA (hk, keyName, 0, KEY_READ, &subKey) == ERROR_SUCCESS)
  190388. {
  190389. char buf [256];
  190390. DWORD dtype = REG_SZ;
  190391. DWORD dsize = sizeof (buf);
  190392. zeromem (buf, dsize);
  190393. if (RegQueryValueExA (subKey, "clsid", 0, &dtype, (LPBYTE) buf, &dsize) == ERROR_SUCCESS)
  190394. {
  190395. if (dsize > 0 && checkClassIsOk (buf))
  190396. {
  190397. wchar_t classIdStr [130];
  190398. MultiByteToWideChar (CP_ACP, 0, buf, -1, classIdStr, 128);
  190399. String deviceName;
  190400. CLSID classId;
  190401. if (CLSIDFromString ((LPOLESTR) classIdStr, &classId) == S_OK)
  190402. {
  190403. dtype = REG_SZ;
  190404. dsize = sizeof (buf);
  190405. if (RegQueryValueExA (subKey, "description", 0, &dtype, (LPBYTE) buf, &dsize) == ERROR_SUCCESS)
  190406. deviceName = buf;
  190407. else
  190408. deviceName = keyName;
  190409. log (T("found ") + deviceName);
  190410. deviceNames.add (deviceName);
  190411. classIds.add (new CLSID (classId));
  190412. }
  190413. }
  190414. RegCloseKey (subKey);
  190415. }
  190416. }
  190417. }
  190418. ASIOAudioIODeviceType (const ASIOAudioIODeviceType&);
  190419. const ASIOAudioIODeviceType& operator= (const ASIOAudioIODeviceType&);
  190420. };
  190421. AudioIODeviceType* juce_createAudioIODeviceType_ASIO()
  190422. {
  190423. return new ASIOAudioIODeviceType();
  190424. }
  190425. AudioIODevice* juce_createASIOAudioIODeviceForGUID (const String& name,
  190426. void* guid,
  190427. const String& optionalDllForDirectLoading)
  190428. {
  190429. const int freeSlot = ASIOAudioIODeviceType::findFreeSlot();
  190430. if (freeSlot < 0)
  190431. return 0;
  190432. return new ASIOAudioIODevice (name, *(CLSID*) guid, freeSlot, optionalDllForDirectLoading);
  190433. }
  190434. #undef log
  190435. #endif
  190436. /********* End of inlined file: juce_win32_ASIO.cpp *********/
  190437. /********* Start of inlined file: juce_win32_DirectSound.cpp *********/
  190438. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  190439. // compiled on its own).
  190440. #if JUCE_INCLUDED_FILE && JUCE_DIRECTSOUND
  190441. END_JUCE_NAMESPACE
  190442. extern "C"
  190443. {
  190444. // Declare just the minimum number of interfaces for the DSound objects that we need..
  190445. typedef struct typeDSBUFFERDESC
  190446. {
  190447. DWORD dwSize;
  190448. DWORD dwFlags;
  190449. DWORD dwBufferBytes;
  190450. DWORD dwReserved;
  190451. LPWAVEFORMATEX lpwfxFormat;
  190452. GUID guid3DAlgorithm;
  190453. } DSBUFFERDESC;
  190454. struct IDirectSoundBuffer;
  190455. #undef INTERFACE
  190456. #define INTERFACE IDirectSound
  190457. DECLARE_INTERFACE_(IDirectSound, IUnknown)
  190458. {
  190459. STDMETHOD(QueryInterface) (THIS_ REFIID, LPVOID*) PURE;
  190460. STDMETHOD_(ULONG,AddRef) (THIS) PURE;
  190461. STDMETHOD_(ULONG,Release) (THIS) PURE;
  190462. STDMETHOD(CreateSoundBuffer) (THIS_ DSBUFFERDESC*, IDirectSoundBuffer**, LPUNKNOWN) PURE;
  190463. STDMETHOD(GetCaps) (THIS_ void*) PURE;
  190464. STDMETHOD(DuplicateSoundBuffer) (THIS_ IDirectSoundBuffer*, IDirectSoundBuffer**) PURE;
  190465. STDMETHOD(SetCooperativeLevel) (THIS_ HWND, DWORD) PURE;
  190466. STDMETHOD(Compact) (THIS) PURE;
  190467. STDMETHOD(GetSpeakerConfig) (THIS_ LPDWORD) PURE;
  190468. STDMETHOD(SetSpeakerConfig) (THIS_ DWORD) PURE;
  190469. STDMETHOD(Initialize) (THIS_ const GUID*) PURE;
  190470. };
  190471. #undef INTERFACE
  190472. #define INTERFACE IDirectSoundBuffer
  190473. DECLARE_INTERFACE_(IDirectSoundBuffer, IUnknown)
  190474. {
  190475. STDMETHOD(QueryInterface) (THIS_ REFIID, LPVOID*) PURE;
  190476. STDMETHOD_(ULONG,AddRef) (THIS) PURE;
  190477. STDMETHOD_(ULONG,Release) (THIS) PURE;
  190478. STDMETHOD(GetCaps) (THIS_ void*) PURE;
  190479. STDMETHOD(GetCurrentPosition) (THIS_ LPDWORD, LPDWORD) PURE;
  190480. STDMETHOD(GetFormat) (THIS_ LPWAVEFORMATEX, DWORD, LPDWORD) PURE;
  190481. STDMETHOD(GetVolume) (THIS_ LPLONG) PURE;
  190482. STDMETHOD(GetPan) (THIS_ LPLONG) PURE;
  190483. STDMETHOD(GetFrequency) (THIS_ LPDWORD) PURE;
  190484. STDMETHOD(GetStatus) (THIS_ LPDWORD) PURE;
  190485. STDMETHOD(Initialize) (THIS_ IDirectSound*, DSBUFFERDESC*) PURE;
  190486. STDMETHOD(Lock) (THIS_ DWORD, DWORD, LPVOID*, LPDWORD, LPVOID*, LPDWORD, DWORD) PURE;
  190487. STDMETHOD(Play) (THIS_ DWORD, DWORD, DWORD) PURE;
  190488. STDMETHOD(SetCurrentPosition) (THIS_ DWORD) PURE;
  190489. STDMETHOD(SetFormat) (THIS_ const WAVEFORMATEX*) PURE;
  190490. STDMETHOD(SetVolume) (THIS_ LONG) PURE;
  190491. STDMETHOD(SetPan) (THIS_ LONG) PURE;
  190492. STDMETHOD(SetFrequency) (THIS_ DWORD) PURE;
  190493. STDMETHOD(Stop) (THIS) PURE;
  190494. STDMETHOD(Unlock) (THIS_ LPVOID, DWORD, LPVOID, DWORD) PURE;
  190495. STDMETHOD(Restore) (THIS) PURE;
  190496. };
  190497. typedef struct typeDSCBUFFERDESC
  190498. {
  190499. DWORD dwSize;
  190500. DWORD dwFlags;
  190501. DWORD dwBufferBytes;
  190502. DWORD dwReserved;
  190503. LPWAVEFORMATEX lpwfxFormat;
  190504. } DSCBUFFERDESC;
  190505. struct IDirectSoundCaptureBuffer;
  190506. #undef INTERFACE
  190507. #define INTERFACE IDirectSoundCapture
  190508. DECLARE_INTERFACE_(IDirectSoundCapture, IUnknown)
  190509. {
  190510. STDMETHOD(QueryInterface) (THIS_ REFIID, LPVOID*) PURE;
  190511. STDMETHOD_(ULONG,AddRef) (THIS) PURE;
  190512. STDMETHOD_(ULONG,Release) (THIS) PURE;
  190513. STDMETHOD(CreateCaptureBuffer) (THIS_ DSCBUFFERDESC*, IDirectSoundCaptureBuffer**, LPUNKNOWN) PURE;
  190514. STDMETHOD(GetCaps) (THIS_ void*) PURE;
  190515. STDMETHOD(Initialize) (THIS_ const GUID*) PURE;
  190516. };
  190517. #undef INTERFACE
  190518. #define INTERFACE IDirectSoundCaptureBuffer
  190519. DECLARE_INTERFACE_(IDirectSoundCaptureBuffer, IUnknown)
  190520. {
  190521. STDMETHOD(QueryInterface) (THIS_ REFIID, LPVOID*) PURE;
  190522. STDMETHOD_(ULONG,AddRef) (THIS) PURE;
  190523. STDMETHOD_(ULONG,Release) (THIS) PURE;
  190524. STDMETHOD(GetCaps) (THIS_ void*) PURE;
  190525. STDMETHOD(GetCurrentPosition) (THIS_ LPDWORD, LPDWORD) PURE;
  190526. STDMETHOD(GetFormat) (THIS_ LPWAVEFORMATEX, DWORD, LPDWORD) PURE;
  190527. STDMETHOD(GetStatus) (THIS_ LPDWORD) PURE;
  190528. STDMETHOD(Initialize) (THIS_ IDirectSoundCapture*, DSCBUFFERDESC*) PURE;
  190529. STDMETHOD(Lock) (THIS_ DWORD, DWORD, LPVOID*, LPDWORD, LPVOID*, LPDWORD, DWORD) PURE;
  190530. STDMETHOD(Start) (THIS_ DWORD) PURE;
  190531. STDMETHOD(Stop) (THIS) PURE;
  190532. STDMETHOD(Unlock) (THIS_ LPVOID, DWORD, LPVOID, DWORD) PURE;
  190533. };
  190534. };
  190535. BEGIN_JUCE_NAMESPACE
  190536. static const String getDSErrorMessage (HRESULT hr)
  190537. {
  190538. const char* result = 0;
  190539. switch (hr)
  190540. {
  190541. case MAKE_HRESULT(1, 0x878, 10):
  190542. result = "Device already allocated";
  190543. break;
  190544. case MAKE_HRESULT(1, 0x878, 30):
  190545. result = "Control unavailable";
  190546. break;
  190547. case E_INVALIDARG:
  190548. result = "Invalid parameter";
  190549. break;
  190550. case MAKE_HRESULT(1, 0x878, 50):
  190551. result = "Invalid call";
  190552. break;
  190553. case E_FAIL:
  190554. result = "Generic error";
  190555. break;
  190556. case MAKE_HRESULT(1, 0x878, 70):
  190557. result = "Priority level error";
  190558. break;
  190559. case E_OUTOFMEMORY:
  190560. result = "Out of memory";
  190561. break;
  190562. case MAKE_HRESULT(1, 0x878, 100):
  190563. result = "Bad format";
  190564. break;
  190565. case E_NOTIMPL:
  190566. result = "Unsupported function";
  190567. break;
  190568. case MAKE_HRESULT(1, 0x878, 120):
  190569. result = "No driver";
  190570. break;
  190571. case MAKE_HRESULT(1, 0x878, 130):
  190572. result = "Already initialised";
  190573. break;
  190574. case CLASS_E_NOAGGREGATION:
  190575. result = "No aggregation";
  190576. break;
  190577. case MAKE_HRESULT(1, 0x878, 150):
  190578. result = "Buffer lost";
  190579. break;
  190580. case MAKE_HRESULT(1, 0x878, 160):
  190581. result = "Another app has priority";
  190582. break;
  190583. case MAKE_HRESULT(1, 0x878, 170):
  190584. result = "Uninitialised";
  190585. break;
  190586. case E_NOINTERFACE:
  190587. result = "No interface";
  190588. break;
  190589. case S_OK:
  190590. result = "No error";
  190591. break;
  190592. default:
  190593. return "Unknown error: " + String ((int) hr);
  190594. }
  190595. return result;
  190596. }
  190597. #define DS_DEBUGGING 1
  190598. #ifdef DS_DEBUGGING
  190599. #define CATCH JUCE_CATCH_EXCEPTION
  190600. #undef log
  190601. #define log(a) Logger::writeToLog(a);
  190602. #undef logError
  190603. #define logError(a) logDSError(a, __LINE__);
  190604. static void logDSError (HRESULT hr, int lineNum)
  190605. {
  190606. if (hr != S_OK)
  190607. {
  190608. String error ("DS error at line ");
  190609. error << lineNum << T(" - ") << getDSErrorMessage (hr);
  190610. log (error);
  190611. }
  190612. }
  190613. #else
  190614. #define CATCH JUCE_CATCH_ALL
  190615. #define log(a)
  190616. #define logError(a)
  190617. #endif
  190618. #define DSOUND_FUNCTION(functionName, params) \
  190619. typedef HRESULT (WINAPI *type##functionName) params; \
  190620. static type##functionName ds##functionName = 0;
  190621. #define DSOUND_FUNCTION_LOAD(functionName) \
  190622. ds##functionName = (type##functionName) GetProcAddress (h, #functionName); \
  190623. jassert (ds##functionName != 0);
  190624. typedef BOOL (CALLBACK *LPDSENUMCALLBACKW) (LPGUID, LPCWSTR, LPCWSTR, LPVOID);
  190625. typedef BOOL (CALLBACK *LPDSENUMCALLBACKA) (LPGUID, LPCSTR, LPCSTR, LPVOID);
  190626. DSOUND_FUNCTION (DirectSoundCreate, (const GUID*, IDirectSound**, LPUNKNOWN))
  190627. DSOUND_FUNCTION (DirectSoundCaptureCreate, (const GUID*, IDirectSoundCapture**, LPUNKNOWN))
  190628. DSOUND_FUNCTION (DirectSoundEnumerateW, (LPDSENUMCALLBACKW, LPVOID))
  190629. DSOUND_FUNCTION (DirectSoundCaptureEnumerateW, (LPDSENUMCALLBACKW, LPVOID))
  190630. static void initialiseDSoundFunctions()
  190631. {
  190632. if (dsDirectSoundCreate == 0)
  190633. {
  190634. HMODULE h = LoadLibraryA ("dsound.dll");
  190635. DSOUND_FUNCTION_LOAD (DirectSoundCreate)
  190636. DSOUND_FUNCTION_LOAD (DirectSoundCaptureCreate)
  190637. DSOUND_FUNCTION_LOAD (DirectSoundEnumerateW)
  190638. DSOUND_FUNCTION_LOAD (DirectSoundCaptureEnumerateW)
  190639. }
  190640. }
  190641. class DSoundInternalOutChannel
  190642. {
  190643. String name;
  190644. LPGUID guid;
  190645. int sampleRate, bufferSizeSamples;
  190646. float* leftBuffer;
  190647. float* rightBuffer;
  190648. IDirectSound* pDirectSound;
  190649. IDirectSoundBuffer* pOutputBuffer;
  190650. DWORD writeOffset;
  190651. int totalBytesPerBuffer;
  190652. int bytesPerBuffer;
  190653. unsigned int lastPlayCursor;
  190654. public:
  190655. int bitDepth;
  190656. bool doneFlag;
  190657. DSoundInternalOutChannel (const String& name_,
  190658. LPGUID guid_,
  190659. int rate,
  190660. int bufferSize,
  190661. float* left,
  190662. float* right)
  190663. : name (name_),
  190664. guid (guid_),
  190665. sampleRate (rate),
  190666. bufferSizeSamples (bufferSize),
  190667. leftBuffer (left),
  190668. rightBuffer (right),
  190669. pDirectSound (0),
  190670. pOutputBuffer (0),
  190671. bitDepth (16)
  190672. {
  190673. }
  190674. ~DSoundInternalOutChannel()
  190675. {
  190676. close();
  190677. }
  190678. void close()
  190679. {
  190680. HRESULT hr;
  190681. if (pOutputBuffer != 0)
  190682. {
  190683. JUCE_TRY
  190684. {
  190685. log (T("closing dsound out: ") + name);
  190686. hr = pOutputBuffer->Stop();
  190687. logError (hr);
  190688. }
  190689. CATCH
  190690. JUCE_TRY
  190691. {
  190692. hr = pOutputBuffer->Release();
  190693. logError (hr);
  190694. }
  190695. CATCH
  190696. pOutputBuffer = 0;
  190697. }
  190698. if (pDirectSound != 0)
  190699. {
  190700. JUCE_TRY
  190701. {
  190702. hr = pDirectSound->Release();
  190703. logError (hr);
  190704. }
  190705. CATCH
  190706. pDirectSound = 0;
  190707. }
  190708. }
  190709. const String open()
  190710. {
  190711. log (T("opening dsound out device: ") + name
  190712. + T(" rate=") + String (sampleRate)
  190713. + T(" bits=") + String (bitDepth)
  190714. + T(" buf=") + String (bufferSizeSamples));
  190715. pDirectSound = 0;
  190716. pOutputBuffer = 0;
  190717. writeOffset = 0;
  190718. String error;
  190719. HRESULT hr = E_NOINTERFACE;
  190720. if (dsDirectSoundCreate != 0)
  190721. hr = dsDirectSoundCreate (guid, &pDirectSound, 0);
  190722. if (hr == S_OK)
  190723. {
  190724. bytesPerBuffer = (bufferSizeSamples * (bitDepth >> 2)) & ~15;
  190725. totalBytesPerBuffer = (3 * bytesPerBuffer) & ~15;
  190726. const int numChannels = 2;
  190727. hr = pDirectSound->SetCooperativeLevel (GetDesktopWindow(), 2 /* DSSCL_PRIORITY */);
  190728. logError (hr);
  190729. if (hr == S_OK)
  190730. {
  190731. IDirectSoundBuffer* pPrimaryBuffer;
  190732. DSBUFFERDESC primaryDesc;
  190733. zerostruct (primaryDesc);
  190734. primaryDesc.dwSize = sizeof (DSBUFFERDESC);
  190735. primaryDesc.dwFlags = 1 /* DSBCAPS_PRIMARYBUFFER */;
  190736. primaryDesc.dwBufferBytes = 0;
  190737. primaryDesc.lpwfxFormat = 0;
  190738. log ("opening dsound out step 2");
  190739. hr = pDirectSound->CreateSoundBuffer (&primaryDesc, &pPrimaryBuffer, 0);
  190740. logError (hr);
  190741. if (hr == S_OK)
  190742. {
  190743. WAVEFORMATEX wfFormat;
  190744. wfFormat.wFormatTag = WAVE_FORMAT_PCM;
  190745. wfFormat.nChannels = (unsigned short) numChannels;
  190746. wfFormat.nSamplesPerSec = sampleRate;
  190747. wfFormat.wBitsPerSample = (unsigned short) bitDepth;
  190748. wfFormat.nBlockAlign = (unsigned short) (wfFormat.nChannels * wfFormat.wBitsPerSample / 8);
  190749. wfFormat.nAvgBytesPerSec = wfFormat.nSamplesPerSec * wfFormat.nBlockAlign;
  190750. wfFormat.cbSize = 0;
  190751. hr = pPrimaryBuffer->SetFormat (&wfFormat);
  190752. logError (hr);
  190753. if (hr == S_OK)
  190754. {
  190755. DSBUFFERDESC secondaryDesc;
  190756. zerostruct (secondaryDesc);
  190757. secondaryDesc.dwSize = sizeof (DSBUFFERDESC);
  190758. secondaryDesc.dwFlags = 0x8000 /* DSBCAPS_GLOBALFOCUS */
  190759. | 0x10000 /* DSBCAPS_GETCURRENTPOSITION2 */;
  190760. secondaryDesc.dwBufferBytes = totalBytesPerBuffer;
  190761. secondaryDesc.lpwfxFormat = &wfFormat;
  190762. hr = pDirectSound->CreateSoundBuffer (&secondaryDesc, &pOutputBuffer, 0);
  190763. logError (hr);
  190764. if (hr == S_OK)
  190765. {
  190766. log ("opening dsound out step 3");
  190767. DWORD dwDataLen;
  190768. unsigned char* pDSBuffData;
  190769. hr = pOutputBuffer->Lock (0, totalBytesPerBuffer,
  190770. (LPVOID*) &pDSBuffData, &dwDataLen, 0, 0, 0);
  190771. logError (hr);
  190772. if (hr == S_OK)
  190773. {
  190774. zeromem (pDSBuffData, dwDataLen);
  190775. hr = pOutputBuffer->Unlock (pDSBuffData, dwDataLen, 0, 0);
  190776. if (hr == S_OK)
  190777. {
  190778. hr = pOutputBuffer->SetCurrentPosition (0);
  190779. if (hr == S_OK)
  190780. {
  190781. hr = pOutputBuffer->Play (0, 0, 1 /* DSBPLAY_LOOPING */);
  190782. if (hr == S_OK)
  190783. return String::empty;
  190784. }
  190785. }
  190786. }
  190787. }
  190788. }
  190789. }
  190790. }
  190791. }
  190792. error = getDSErrorMessage (hr);
  190793. close();
  190794. return error;
  190795. }
  190796. void synchronisePosition()
  190797. {
  190798. if (pOutputBuffer != 0)
  190799. {
  190800. DWORD playCursor;
  190801. pOutputBuffer->GetCurrentPosition (&playCursor, &writeOffset);
  190802. }
  190803. }
  190804. bool service()
  190805. {
  190806. if (pOutputBuffer == 0)
  190807. return true;
  190808. DWORD playCursor, writeCursor;
  190809. for (;;)
  190810. {
  190811. HRESULT hr = pOutputBuffer->GetCurrentPosition (&playCursor, &writeCursor);
  190812. if (hr == MAKE_HRESULT (1, 0x878, 150)) // DSERR_BUFFERLOST
  190813. {
  190814. pOutputBuffer->Restore();
  190815. continue;
  190816. }
  190817. if (hr == S_OK)
  190818. break;
  190819. logError (hr);
  190820. jassertfalse
  190821. return true;
  190822. }
  190823. int playWriteGap = writeCursor - playCursor;
  190824. if (playWriteGap < 0)
  190825. playWriteGap += totalBytesPerBuffer;
  190826. int bytesEmpty = playCursor - writeOffset;
  190827. if (bytesEmpty < 0)
  190828. bytesEmpty += totalBytesPerBuffer;
  190829. if (bytesEmpty > (totalBytesPerBuffer - playWriteGap))
  190830. {
  190831. writeOffset = writeCursor;
  190832. bytesEmpty = totalBytesPerBuffer - playWriteGap;
  190833. }
  190834. if (bytesEmpty >= bytesPerBuffer)
  190835. {
  190836. LPBYTE lpbuf1 = 0;
  190837. LPBYTE lpbuf2 = 0;
  190838. DWORD dwSize1 = 0;
  190839. DWORD dwSize2 = 0;
  190840. HRESULT hr = pOutputBuffer->Lock (writeOffset,
  190841. bytesPerBuffer,
  190842. (void**) &lpbuf1, &dwSize1,
  190843. (void**) &lpbuf2, &dwSize2, 0);
  190844. if (hr == MAKE_HRESULT (1, 0x878, 150)) // DSERR_BUFFERLOST
  190845. {
  190846. pOutputBuffer->Restore();
  190847. hr = pOutputBuffer->Lock (writeOffset,
  190848. bytesPerBuffer,
  190849. (void**) &lpbuf1, &dwSize1,
  190850. (void**) &lpbuf2, &dwSize2, 0);
  190851. }
  190852. if (hr == S_OK)
  190853. {
  190854. if (bitDepth == 16)
  190855. {
  190856. const float gainL = 32767.0f;
  190857. const float gainR = 32767.0f;
  190858. int* dest = (int*)lpbuf1;
  190859. const float* left = leftBuffer;
  190860. const float* right = rightBuffer;
  190861. int samples1 = dwSize1 >> 2;
  190862. int samples2 = dwSize2 >> 2;
  190863. if (left == 0)
  190864. {
  190865. while (--samples1 >= 0)
  190866. {
  190867. int r = roundToInt (gainR * *right++);
  190868. if (r < -32768)
  190869. r = -32768;
  190870. else if (r > 32767)
  190871. r = 32767;
  190872. *dest++ = (r << 16);
  190873. }
  190874. dest = (int*)lpbuf2;
  190875. while (--samples2 >= 0)
  190876. {
  190877. int r = roundToInt (gainR * *right++);
  190878. if (r < -32768)
  190879. r = -32768;
  190880. else if (r > 32767)
  190881. r = 32767;
  190882. *dest++ = (r << 16);
  190883. }
  190884. }
  190885. else if (right == 0)
  190886. {
  190887. while (--samples1 >= 0)
  190888. {
  190889. int l = roundToInt (gainL * *left++);
  190890. if (l < -32768)
  190891. l = -32768;
  190892. else if (l > 32767)
  190893. l = 32767;
  190894. l &= 0xffff;
  190895. *dest++ = l;
  190896. }
  190897. dest = (int*)lpbuf2;
  190898. while (--samples2 >= 0)
  190899. {
  190900. int l = roundToInt (gainL * *left++);
  190901. if (l < -32768)
  190902. l = -32768;
  190903. else if (l > 32767)
  190904. l = 32767;
  190905. l &= 0xffff;
  190906. *dest++ = l;
  190907. }
  190908. }
  190909. else
  190910. {
  190911. while (--samples1 >= 0)
  190912. {
  190913. int l = roundToInt (gainL * *left++);
  190914. if (l < -32768)
  190915. l = -32768;
  190916. else if (l > 32767)
  190917. l = 32767;
  190918. l &= 0xffff;
  190919. int r = roundToInt (gainR * *right++);
  190920. if (r < -32768)
  190921. r = -32768;
  190922. else if (r > 32767)
  190923. r = 32767;
  190924. *dest++ = (r << 16) | l;
  190925. }
  190926. dest = (int*)lpbuf2;
  190927. while (--samples2 >= 0)
  190928. {
  190929. int l = roundToInt (gainL * *left++);
  190930. if (l < -32768)
  190931. l = -32768;
  190932. else if (l > 32767)
  190933. l = 32767;
  190934. l &= 0xffff;
  190935. int r = roundToInt (gainR * *right++);
  190936. if (r < -32768)
  190937. r = -32768;
  190938. else if (r > 32767)
  190939. r = 32767;
  190940. *dest++ = (r << 16) | l;
  190941. }
  190942. }
  190943. }
  190944. else
  190945. {
  190946. jassertfalse
  190947. }
  190948. writeOffset = (writeOffset + dwSize1 + dwSize2) % totalBytesPerBuffer;
  190949. pOutputBuffer->Unlock (lpbuf1, dwSize1, lpbuf2, dwSize2);
  190950. }
  190951. else
  190952. {
  190953. jassertfalse
  190954. logError (hr);
  190955. }
  190956. bytesEmpty -= bytesPerBuffer;
  190957. return true;
  190958. }
  190959. else
  190960. {
  190961. return false;
  190962. }
  190963. }
  190964. };
  190965. struct DSoundInternalInChannel
  190966. {
  190967. String name;
  190968. LPGUID guid;
  190969. int sampleRate, bufferSizeSamples;
  190970. float* leftBuffer;
  190971. float* rightBuffer;
  190972. IDirectSound* pDirectSound;
  190973. IDirectSoundCapture* pDirectSoundCapture;
  190974. IDirectSoundCaptureBuffer* pInputBuffer;
  190975. public:
  190976. unsigned int readOffset;
  190977. int bytesPerBuffer, totalBytesPerBuffer;
  190978. int bitDepth;
  190979. bool doneFlag;
  190980. DSoundInternalInChannel (const String& name_,
  190981. LPGUID guid_,
  190982. int rate,
  190983. int bufferSize,
  190984. float* left,
  190985. float* right)
  190986. : name (name_),
  190987. guid (guid_),
  190988. sampleRate (rate),
  190989. bufferSizeSamples (bufferSize),
  190990. leftBuffer (left),
  190991. rightBuffer (right),
  190992. pDirectSound (0),
  190993. pDirectSoundCapture (0),
  190994. pInputBuffer (0),
  190995. bitDepth (16)
  190996. {
  190997. }
  190998. ~DSoundInternalInChannel()
  190999. {
  191000. close();
  191001. }
  191002. void close()
  191003. {
  191004. HRESULT hr;
  191005. if (pInputBuffer != 0)
  191006. {
  191007. JUCE_TRY
  191008. {
  191009. log (T("closing dsound in: ") + name);
  191010. hr = pInputBuffer->Stop();
  191011. logError (hr);
  191012. }
  191013. CATCH
  191014. JUCE_TRY
  191015. {
  191016. hr = pInputBuffer->Release();
  191017. logError (hr);
  191018. }
  191019. CATCH
  191020. pInputBuffer = 0;
  191021. }
  191022. if (pDirectSoundCapture != 0)
  191023. {
  191024. JUCE_TRY
  191025. {
  191026. hr = pDirectSoundCapture->Release();
  191027. logError (hr);
  191028. }
  191029. CATCH
  191030. pDirectSoundCapture = 0;
  191031. }
  191032. if (pDirectSound != 0)
  191033. {
  191034. JUCE_TRY
  191035. {
  191036. hr = pDirectSound->Release();
  191037. logError (hr);
  191038. }
  191039. CATCH
  191040. pDirectSound = 0;
  191041. }
  191042. }
  191043. const String open()
  191044. {
  191045. log (T("opening dsound in device: ") + name
  191046. + T(" rate=") + String (sampleRate) + T(" bits=") + String (bitDepth) + T(" buf=") + String (bufferSizeSamples));
  191047. pDirectSound = 0;
  191048. pDirectSoundCapture = 0;
  191049. pInputBuffer = 0;
  191050. readOffset = 0;
  191051. totalBytesPerBuffer = 0;
  191052. String error;
  191053. HRESULT hr = E_NOINTERFACE;
  191054. if (dsDirectSoundCaptureCreate != 0)
  191055. hr = dsDirectSoundCaptureCreate (guid, &pDirectSoundCapture, 0);
  191056. logError (hr);
  191057. if (hr == S_OK)
  191058. {
  191059. const int numChannels = 2;
  191060. bytesPerBuffer = (bufferSizeSamples * (bitDepth >> 2)) & ~15;
  191061. totalBytesPerBuffer = (3 * bytesPerBuffer) & ~15;
  191062. WAVEFORMATEX wfFormat;
  191063. wfFormat.wFormatTag = WAVE_FORMAT_PCM;
  191064. wfFormat.nChannels = (unsigned short)numChannels;
  191065. wfFormat.nSamplesPerSec = sampleRate;
  191066. wfFormat.wBitsPerSample = (unsigned short)bitDepth;
  191067. wfFormat.nBlockAlign = (unsigned short)(wfFormat.nChannels * (wfFormat.wBitsPerSample / 8));
  191068. wfFormat.nAvgBytesPerSec = wfFormat.nSamplesPerSec * wfFormat.nBlockAlign;
  191069. wfFormat.cbSize = 0;
  191070. DSCBUFFERDESC captureDesc;
  191071. zerostruct (captureDesc);
  191072. captureDesc.dwSize = sizeof (DSCBUFFERDESC);
  191073. captureDesc.dwFlags = 0;
  191074. captureDesc.dwBufferBytes = totalBytesPerBuffer;
  191075. captureDesc.lpwfxFormat = &wfFormat;
  191076. log (T("opening dsound in step 2"));
  191077. hr = pDirectSoundCapture->CreateCaptureBuffer (&captureDesc, &pInputBuffer, 0);
  191078. logError (hr);
  191079. if (hr == S_OK)
  191080. {
  191081. hr = pInputBuffer->Start (1 /* DSCBSTART_LOOPING */);
  191082. logError (hr);
  191083. if (hr == S_OK)
  191084. return String::empty;
  191085. }
  191086. }
  191087. error = getDSErrorMessage (hr);
  191088. close();
  191089. return error;
  191090. }
  191091. void synchronisePosition()
  191092. {
  191093. if (pInputBuffer != 0)
  191094. {
  191095. DWORD capturePos;
  191096. pInputBuffer->GetCurrentPosition (&capturePos, (DWORD*)&readOffset);
  191097. }
  191098. }
  191099. bool service()
  191100. {
  191101. if (pInputBuffer == 0)
  191102. return true;
  191103. DWORD capturePos, readPos;
  191104. HRESULT hr = pInputBuffer->GetCurrentPosition (&capturePos, &readPos);
  191105. logError (hr);
  191106. if (hr != S_OK)
  191107. return true;
  191108. int bytesFilled = readPos - readOffset;
  191109. if (bytesFilled < 0)
  191110. bytesFilled += totalBytesPerBuffer;
  191111. if (bytesFilled >= bytesPerBuffer)
  191112. {
  191113. LPBYTE lpbuf1 = 0;
  191114. LPBYTE lpbuf2 = 0;
  191115. DWORD dwsize1 = 0;
  191116. DWORD dwsize2 = 0;
  191117. HRESULT hr = pInputBuffer->Lock (readOffset,
  191118. bytesPerBuffer,
  191119. (void**) &lpbuf1, &dwsize1,
  191120. (void**) &lpbuf2, &dwsize2, 0);
  191121. if (hr == S_OK)
  191122. {
  191123. if (bitDepth == 16)
  191124. {
  191125. const float g = 1.0f / 32768.0f;
  191126. float* destL = leftBuffer;
  191127. float* destR = rightBuffer;
  191128. int samples1 = dwsize1 >> 2;
  191129. int samples2 = dwsize2 >> 2;
  191130. const short* src = (const short*)lpbuf1;
  191131. if (destL == 0)
  191132. {
  191133. while (--samples1 >= 0)
  191134. {
  191135. ++src;
  191136. *destR++ = *src++ * g;
  191137. }
  191138. src = (const short*)lpbuf2;
  191139. while (--samples2 >= 0)
  191140. {
  191141. ++src;
  191142. *destR++ = *src++ * g;
  191143. }
  191144. }
  191145. else if (destR == 0)
  191146. {
  191147. while (--samples1 >= 0)
  191148. {
  191149. *destL++ = *src++ * g;
  191150. ++src;
  191151. }
  191152. src = (const short*)lpbuf2;
  191153. while (--samples2 >= 0)
  191154. {
  191155. *destL++ = *src++ * g;
  191156. ++src;
  191157. }
  191158. }
  191159. else
  191160. {
  191161. while (--samples1 >= 0)
  191162. {
  191163. *destL++ = *src++ * g;
  191164. *destR++ = *src++ * g;
  191165. }
  191166. src = (const short*)lpbuf2;
  191167. while (--samples2 >= 0)
  191168. {
  191169. *destL++ = *src++ * g;
  191170. *destR++ = *src++ * g;
  191171. }
  191172. }
  191173. }
  191174. else
  191175. {
  191176. jassertfalse
  191177. }
  191178. readOffset = (readOffset + dwsize1 + dwsize2) % totalBytesPerBuffer;
  191179. pInputBuffer->Unlock (lpbuf1, dwsize1, lpbuf2, dwsize2);
  191180. }
  191181. else
  191182. {
  191183. logError (hr);
  191184. jassertfalse
  191185. }
  191186. bytesFilled -= bytesPerBuffer;
  191187. return true;
  191188. }
  191189. else
  191190. {
  191191. return false;
  191192. }
  191193. }
  191194. };
  191195. class DSoundAudioIODevice : public AudioIODevice,
  191196. public Thread
  191197. {
  191198. public:
  191199. DSoundAudioIODevice (const String& deviceName,
  191200. const int outputDeviceIndex_,
  191201. const int inputDeviceIndex_)
  191202. : AudioIODevice (deviceName, "DirectSound"),
  191203. Thread ("Juce DSound"),
  191204. isOpen_ (false),
  191205. isStarted (false),
  191206. outputDeviceIndex (outputDeviceIndex_),
  191207. inputDeviceIndex (inputDeviceIndex_),
  191208. numInputBuffers (0),
  191209. numOutputBuffers (0),
  191210. totalSamplesOut (0),
  191211. sampleRate (0.0),
  191212. inputBuffers (0),
  191213. outputBuffers (0),
  191214. callback (0),
  191215. bufferSizeSamples (0)
  191216. {
  191217. if (outputDeviceIndex_ >= 0)
  191218. {
  191219. outChannels.add (TRANS("Left"));
  191220. outChannels.add (TRANS("Right"));
  191221. }
  191222. if (inputDeviceIndex_ >= 0)
  191223. {
  191224. inChannels.add (TRANS("Left"));
  191225. inChannels.add (TRANS("Right"));
  191226. }
  191227. }
  191228. ~DSoundAudioIODevice()
  191229. {
  191230. close();
  191231. }
  191232. const StringArray getOutputChannelNames()
  191233. {
  191234. return outChannels;
  191235. }
  191236. const StringArray getInputChannelNames()
  191237. {
  191238. return inChannels;
  191239. }
  191240. int getNumSampleRates()
  191241. {
  191242. return 4;
  191243. }
  191244. double getSampleRate (int index)
  191245. {
  191246. const double samps[] = { 44100.0, 48000.0, 88200.0, 96000.0 };
  191247. return samps [jlimit (0, 3, index)];
  191248. }
  191249. int getNumBufferSizesAvailable()
  191250. {
  191251. return 50;
  191252. }
  191253. int getBufferSizeSamples (int index)
  191254. {
  191255. int n = 64;
  191256. for (int i = 0; i < index; ++i)
  191257. n += (n < 512) ? 32
  191258. : ((n < 1024) ? 64
  191259. : ((n < 2048) ? 128 : 256));
  191260. return n;
  191261. }
  191262. int getDefaultBufferSize()
  191263. {
  191264. return 2560;
  191265. }
  191266. const String open (const BitArray& inputChannels,
  191267. const BitArray& outputChannels,
  191268. double sampleRate,
  191269. int bufferSizeSamples)
  191270. {
  191271. lastError = openDevice (inputChannels, outputChannels, sampleRate, bufferSizeSamples);
  191272. isOpen_ = lastError.isEmpty();
  191273. return lastError;
  191274. }
  191275. void close()
  191276. {
  191277. stop();
  191278. if (isOpen_)
  191279. {
  191280. closeDevice();
  191281. isOpen_ = false;
  191282. }
  191283. }
  191284. bool isOpen()
  191285. {
  191286. return isOpen_ && isThreadRunning();
  191287. }
  191288. int getCurrentBufferSizeSamples()
  191289. {
  191290. return bufferSizeSamples;
  191291. }
  191292. double getCurrentSampleRate()
  191293. {
  191294. return sampleRate;
  191295. }
  191296. int getCurrentBitDepth()
  191297. {
  191298. int i, bits = 256;
  191299. for (i = inChans.size(); --i >= 0;)
  191300. bits = jmin (bits, inChans[i]->bitDepth);
  191301. for (i = outChans.size(); --i >= 0;)
  191302. bits = jmin (bits, outChans[i]->bitDepth);
  191303. if (bits > 32)
  191304. bits = 16;
  191305. return bits;
  191306. }
  191307. const BitArray getActiveOutputChannels() const
  191308. {
  191309. return enabledOutputs;
  191310. }
  191311. const BitArray getActiveInputChannels() const
  191312. {
  191313. return enabledInputs;
  191314. }
  191315. int getOutputLatencyInSamples()
  191316. {
  191317. return (int) (getCurrentBufferSizeSamples() * 1.5);
  191318. }
  191319. int getInputLatencyInSamples()
  191320. {
  191321. return getOutputLatencyInSamples();
  191322. }
  191323. void start (AudioIODeviceCallback* call)
  191324. {
  191325. if (isOpen_ && call != 0 && ! isStarted)
  191326. {
  191327. if (! isThreadRunning())
  191328. {
  191329. // something gone wrong and the thread's stopped..
  191330. isOpen_ = false;
  191331. return;
  191332. }
  191333. call->audioDeviceAboutToStart (this);
  191334. const ScopedLock sl (startStopLock);
  191335. callback = call;
  191336. isStarted = true;
  191337. }
  191338. }
  191339. void stop()
  191340. {
  191341. if (isStarted)
  191342. {
  191343. AudioIODeviceCallback* const callbackLocal = callback;
  191344. {
  191345. const ScopedLock sl (startStopLock);
  191346. isStarted = false;
  191347. }
  191348. if (callbackLocal != 0)
  191349. callbackLocal->audioDeviceStopped();
  191350. }
  191351. }
  191352. bool isPlaying()
  191353. {
  191354. return isStarted && isOpen_ && isThreadRunning();
  191355. }
  191356. const String getLastError()
  191357. {
  191358. return lastError;
  191359. }
  191360. juce_UseDebuggingNewOperator
  191361. StringArray inChannels, outChannels;
  191362. int outputDeviceIndex, inputDeviceIndex;
  191363. private:
  191364. bool isOpen_;
  191365. bool isStarted;
  191366. String lastError;
  191367. OwnedArray <DSoundInternalInChannel> inChans;
  191368. OwnedArray <DSoundInternalOutChannel> outChans;
  191369. WaitableEvent startEvent;
  191370. int numInputBuffers, numOutputBuffers, bufferSizeSamples;
  191371. int volatile totalSamplesOut;
  191372. int64 volatile lastBlockTime;
  191373. double sampleRate;
  191374. BitArray enabledInputs, enabledOutputs;
  191375. HeapBlock <float*> inputBuffers, outputBuffers;
  191376. AudioIODeviceCallback* callback;
  191377. CriticalSection startStopLock;
  191378. DSoundAudioIODevice (const DSoundAudioIODevice&);
  191379. const DSoundAudioIODevice& operator= (const DSoundAudioIODevice&);
  191380. const String openDevice (const BitArray& inputChannels,
  191381. const BitArray& outputChannels,
  191382. double sampleRate_,
  191383. int bufferSizeSamples_);
  191384. void closeDevice()
  191385. {
  191386. isStarted = false;
  191387. stopThread (5000);
  191388. inChans.clear();
  191389. outChans.clear();
  191390. int i;
  191391. for (i = 0; i < numInputBuffers; ++i)
  191392. juce_free (inputBuffers[i]);
  191393. inputBuffers.free();
  191394. numInputBuffers = 0;
  191395. for (i = 0; i < numOutputBuffers; ++i)
  191396. juce_free (outputBuffers[i]);
  191397. outputBuffers.free();
  191398. numOutputBuffers = 0;
  191399. }
  191400. void resync()
  191401. {
  191402. if (! threadShouldExit())
  191403. {
  191404. sleep (5);
  191405. int i;
  191406. for (i = 0; i < outChans.size(); ++i)
  191407. outChans.getUnchecked(i)->synchronisePosition();
  191408. for (i = 0; i < inChans.size(); ++i)
  191409. inChans.getUnchecked(i)->synchronisePosition();
  191410. }
  191411. }
  191412. public:
  191413. void run()
  191414. {
  191415. while (! threadShouldExit())
  191416. {
  191417. if (wait (100))
  191418. break;
  191419. }
  191420. const int latencyMs = (int) (bufferSizeSamples * 1000.0 / sampleRate);
  191421. const int maxTimeMS = jmax (5, 3 * latencyMs);
  191422. while (! threadShouldExit())
  191423. {
  191424. int numToDo = 0;
  191425. uint32 startTime = Time::getMillisecondCounter();
  191426. int i;
  191427. for (i = inChans.size(); --i >= 0;)
  191428. {
  191429. inChans.getUnchecked(i)->doneFlag = false;
  191430. ++numToDo;
  191431. }
  191432. for (i = outChans.size(); --i >= 0;)
  191433. {
  191434. outChans.getUnchecked(i)->doneFlag = false;
  191435. ++numToDo;
  191436. }
  191437. if (numToDo > 0)
  191438. {
  191439. const int maxCount = 3;
  191440. int count = maxCount;
  191441. for (;;)
  191442. {
  191443. for (i = inChans.size(); --i >= 0;)
  191444. {
  191445. DSoundInternalInChannel* const in = inChans.getUnchecked(i);
  191446. if ((! in->doneFlag) && in->service())
  191447. {
  191448. in->doneFlag = true;
  191449. --numToDo;
  191450. }
  191451. }
  191452. for (i = outChans.size(); --i >= 0;)
  191453. {
  191454. DSoundInternalOutChannel* const out = outChans.getUnchecked(i);
  191455. if ((! out->doneFlag) && out->service())
  191456. {
  191457. out->doneFlag = true;
  191458. --numToDo;
  191459. }
  191460. }
  191461. if (numToDo <= 0)
  191462. break;
  191463. if (Time::getMillisecondCounter() > startTime + maxTimeMS)
  191464. {
  191465. resync();
  191466. break;
  191467. }
  191468. if (--count <= 0)
  191469. {
  191470. Sleep (1);
  191471. count = maxCount;
  191472. }
  191473. if (threadShouldExit())
  191474. return;
  191475. }
  191476. }
  191477. else
  191478. {
  191479. sleep (1);
  191480. }
  191481. const ScopedLock sl (startStopLock);
  191482. if (isStarted)
  191483. {
  191484. JUCE_TRY
  191485. {
  191486. callback->audioDeviceIOCallback ((const float**) inputBuffers,
  191487. numInputBuffers,
  191488. outputBuffers,
  191489. numOutputBuffers,
  191490. bufferSizeSamples);
  191491. }
  191492. JUCE_CATCH_EXCEPTION
  191493. totalSamplesOut += bufferSizeSamples;
  191494. }
  191495. else
  191496. {
  191497. for (i = 0; i < numOutputBuffers; ++i)
  191498. if (outputBuffers[i] != 0)
  191499. zeromem (outputBuffers[i], bufferSizeSamples * sizeof (float));
  191500. totalSamplesOut = 0;
  191501. sleep (1);
  191502. }
  191503. }
  191504. }
  191505. };
  191506. class DSoundAudioIODeviceType : public AudioIODeviceType
  191507. {
  191508. public:
  191509. DSoundAudioIODeviceType()
  191510. : AudioIODeviceType (T("DirectSound")),
  191511. hasScanned (false)
  191512. {
  191513. initialiseDSoundFunctions();
  191514. }
  191515. ~DSoundAudioIODeviceType()
  191516. {
  191517. }
  191518. void scanForDevices()
  191519. {
  191520. hasScanned = true;
  191521. outputDeviceNames.clear();
  191522. outputGuids.clear();
  191523. inputDeviceNames.clear();
  191524. inputGuids.clear();
  191525. if (dsDirectSoundEnumerateW != 0)
  191526. {
  191527. dsDirectSoundEnumerateW (outputEnumProcW, this);
  191528. dsDirectSoundCaptureEnumerateW (inputEnumProcW, this);
  191529. }
  191530. }
  191531. const StringArray getDeviceNames (const bool wantInputNames) const
  191532. {
  191533. jassert (hasScanned); // need to call scanForDevices() before doing this
  191534. return wantInputNames ? inputDeviceNames
  191535. : outputDeviceNames;
  191536. }
  191537. int getDefaultDeviceIndex (const bool /*forInput*/) const
  191538. {
  191539. jassert (hasScanned); // need to call scanForDevices() before doing this
  191540. return 0;
  191541. }
  191542. int getIndexOfDevice (AudioIODevice* device, const bool asInput) const
  191543. {
  191544. jassert (hasScanned); // need to call scanForDevices() before doing this
  191545. DSoundAudioIODevice* const d = dynamic_cast <DSoundAudioIODevice*> (device);
  191546. if (d == 0)
  191547. return -1;
  191548. return asInput ? d->inputDeviceIndex
  191549. : d->outputDeviceIndex;
  191550. }
  191551. bool hasSeparateInputsAndOutputs() const { return true; }
  191552. AudioIODevice* createDevice (const String& outputDeviceName,
  191553. const String& inputDeviceName)
  191554. {
  191555. jassert (hasScanned); // need to call scanForDevices() before doing this
  191556. const int outputIndex = outputDeviceNames.indexOf (outputDeviceName);
  191557. const int inputIndex = inputDeviceNames.indexOf (inputDeviceName);
  191558. if (outputIndex >= 0 || inputIndex >= 0)
  191559. return new DSoundAudioIODevice (outputDeviceName.isNotEmpty() ? outputDeviceName
  191560. : inputDeviceName,
  191561. outputIndex, inputIndex);
  191562. return 0;
  191563. }
  191564. juce_UseDebuggingNewOperator
  191565. StringArray outputDeviceNames;
  191566. OwnedArray <GUID> outputGuids;
  191567. StringArray inputDeviceNames;
  191568. OwnedArray <GUID> inputGuids;
  191569. private:
  191570. bool hasScanned;
  191571. BOOL outputEnumProc (LPGUID lpGUID, String desc)
  191572. {
  191573. desc = desc.trim();
  191574. if (desc.isNotEmpty())
  191575. {
  191576. const String origDesc (desc);
  191577. int n = 2;
  191578. while (outputDeviceNames.contains (desc))
  191579. desc = origDesc + T(" (") + String (n++) + T(")");
  191580. outputDeviceNames.add (desc);
  191581. if (lpGUID != 0)
  191582. outputGuids.add (new GUID (*lpGUID));
  191583. else
  191584. outputGuids.add (0);
  191585. }
  191586. return TRUE;
  191587. }
  191588. static BOOL CALLBACK outputEnumProcW (LPGUID lpGUID, LPCWSTR description, LPCWSTR, LPVOID object)
  191589. {
  191590. return ((DSoundAudioIODeviceType*) object)
  191591. ->outputEnumProc (lpGUID, String (description));
  191592. }
  191593. static BOOL CALLBACK outputEnumProcA (LPGUID lpGUID, LPCTSTR description, LPCTSTR, LPVOID object)
  191594. {
  191595. return ((DSoundAudioIODeviceType*) object)
  191596. ->outputEnumProc (lpGUID, String (description));
  191597. }
  191598. BOOL CALLBACK inputEnumProc (LPGUID lpGUID, String desc)
  191599. {
  191600. desc = desc.trim();
  191601. if (desc.isNotEmpty())
  191602. {
  191603. const String origDesc (desc);
  191604. int n = 2;
  191605. while (inputDeviceNames.contains (desc))
  191606. desc = origDesc + T(" (") + String (n++) + T(")");
  191607. inputDeviceNames.add (desc);
  191608. if (lpGUID != 0)
  191609. inputGuids.add (new GUID (*lpGUID));
  191610. else
  191611. inputGuids.add (0);
  191612. }
  191613. return TRUE;
  191614. }
  191615. static BOOL CALLBACK inputEnumProcW (LPGUID lpGUID, LPCWSTR description, LPCWSTR, LPVOID object)
  191616. {
  191617. return ((DSoundAudioIODeviceType*) object)
  191618. ->inputEnumProc (lpGUID, String (description));
  191619. }
  191620. static BOOL CALLBACK inputEnumProcA (LPGUID lpGUID, LPCTSTR description, LPCTSTR, LPVOID object)
  191621. {
  191622. return ((DSoundAudioIODeviceType*) object)
  191623. ->inputEnumProc (lpGUID, String (description));
  191624. }
  191625. DSoundAudioIODeviceType (const DSoundAudioIODeviceType&);
  191626. const DSoundAudioIODeviceType& operator= (const DSoundAudioIODeviceType&);
  191627. };
  191628. const String DSoundAudioIODevice::openDevice (const BitArray& inputChannels,
  191629. const BitArray& outputChannels,
  191630. double sampleRate_,
  191631. int bufferSizeSamples_)
  191632. {
  191633. closeDevice();
  191634. totalSamplesOut = 0;
  191635. sampleRate = sampleRate_;
  191636. if (bufferSizeSamples_ <= 0)
  191637. bufferSizeSamples_ = 960; // use as a default size if none is set.
  191638. bufferSizeSamples = bufferSizeSamples_ & ~7;
  191639. DSoundAudioIODeviceType dlh;
  191640. dlh.scanForDevices();
  191641. enabledInputs = inputChannels;
  191642. enabledInputs.setRange (inChannels.size(),
  191643. enabledInputs.getHighestBit() + 1 - inChannels.size(),
  191644. false);
  191645. numInputBuffers = enabledInputs.countNumberOfSetBits();
  191646. inputBuffers.calloc (numInputBuffers + 2);
  191647. int i, numIns = 0;
  191648. for (i = 0; i <= enabledInputs.getHighestBit(); i += 2)
  191649. {
  191650. float* left = 0;
  191651. float* right = 0;
  191652. if (enabledInputs[i])
  191653. left = inputBuffers[numIns++] = (float*) juce_calloc ((bufferSizeSamples + 16) * sizeof (float));
  191654. if (enabledInputs[i + 1])
  191655. right = inputBuffers[numIns++] = (float*) juce_calloc ((bufferSizeSamples + 16) * sizeof (float));
  191656. if (left != 0 || right != 0)
  191657. inChans.add (new DSoundInternalInChannel (dlh.inputDeviceNames [inputDeviceIndex],
  191658. dlh.inputGuids [inputDeviceIndex],
  191659. (int) sampleRate, bufferSizeSamples,
  191660. left, right));
  191661. }
  191662. enabledOutputs = outputChannels;
  191663. enabledOutputs.setRange (outChannels.size(),
  191664. enabledOutputs.getHighestBit() + 1 - outChannels.size(),
  191665. false);
  191666. numOutputBuffers = enabledOutputs.countNumberOfSetBits();
  191667. outputBuffers.calloc (numOutputBuffers + 2);
  191668. int numOuts = 0;
  191669. for (i = 0; i <= enabledOutputs.getHighestBit(); i += 2)
  191670. {
  191671. float* left = 0;
  191672. float* right = 0;
  191673. if (enabledOutputs[i])
  191674. left = outputBuffers[numOuts++] = (float*) juce_calloc ((bufferSizeSamples + 16) * sizeof (float));
  191675. if (enabledOutputs[i + 1])
  191676. right = outputBuffers[numOuts++] = (float*) juce_calloc ((bufferSizeSamples + 16) * sizeof (float));
  191677. if (left != 0 || right != 0)
  191678. outChans.add (new DSoundInternalOutChannel (dlh.outputDeviceNames[outputDeviceIndex],
  191679. dlh.outputGuids [outputDeviceIndex],
  191680. (int) sampleRate, bufferSizeSamples,
  191681. left, right));
  191682. }
  191683. String error;
  191684. // boost our priority while opening the devices to try to get better sync between them
  191685. const int oldThreadPri = GetThreadPriority (GetCurrentThread());
  191686. const int oldProcPri = GetPriorityClass (GetCurrentProcess());
  191687. SetThreadPriority (GetCurrentThread(), THREAD_PRIORITY_TIME_CRITICAL);
  191688. SetPriorityClass (GetCurrentProcess(), REALTIME_PRIORITY_CLASS);
  191689. for (i = 0; i < outChans.size(); ++i)
  191690. {
  191691. error = outChans[i]->open();
  191692. if (error.isNotEmpty())
  191693. {
  191694. error = T("Error opening ") + dlh.outputDeviceNames[i]
  191695. + T(": \"") + error + T("\"");
  191696. break;
  191697. }
  191698. }
  191699. if (error.isEmpty())
  191700. {
  191701. for (i = 0; i < inChans.size(); ++i)
  191702. {
  191703. error = inChans[i]->open();
  191704. if (error.isNotEmpty())
  191705. {
  191706. error = T("Error opening ") + dlh.inputDeviceNames[i]
  191707. + T(": \"") + error + T("\"");
  191708. break;
  191709. }
  191710. }
  191711. }
  191712. if (error.isEmpty())
  191713. {
  191714. totalSamplesOut = 0;
  191715. for (i = 0; i < outChans.size(); ++i)
  191716. outChans.getUnchecked(i)->synchronisePosition();
  191717. for (i = 0; i < inChans.size(); ++i)
  191718. inChans.getUnchecked(i)->synchronisePosition();
  191719. startThread (9);
  191720. sleep (10);
  191721. notify();
  191722. }
  191723. else
  191724. {
  191725. log (error);
  191726. }
  191727. SetThreadPriority (GetCurrentThread(), oldThreadPri);
  191728. SetPriorityClass (GetCurrentProcess(), oldProcPri);
  191729. return error;
  191730. }
  191731. AudioIODeviceType* juce_createAudioIODeviceType_DirectSound()
  191732. {
  191733. return new DSoundAudioIODeviceType();
  191734. }
  191735. #undef log
  191736. #endif
  191737. /********* End of inlined file: juce_win32_DirectSound.cpp *********/
  191738. /********* Start of inlined file: juce_win32_WASAPI.cpp *********/
  191739. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  191740. // compiled on its own).
  191741. #if JUCE_INCLUDED_FILE && JUCE_WASAPI
  191742. #if 1
  191743. const String getAudioErrorDesc (HRESULT hr)
  191744. {
  191745. const char* e = 0;
  191746. switch (hr)
  191747. {
  191748. case E_POINTER: e = "E_POINTER"; break;
  191749. case E_INVALIDARG: e = "E_INVALIDARG"; break;
  191750. case AUDCLNT_E_NOT_INITIALIZED: e = "AUDCLNT_E_NOT_INITIALIZED"; break;
  191751. case AUDCLNT_E_ALREADY_INITIALIZED: e = "AUDCLNT_E_ALREADY_INITIALIZED"; break;
  191752. case AUDCLNT_E_WRONG_ENDPOINT_TYPE: e = "AUDCLNT_E_WRONG_ENDPOINT_TYPE"; break;
  191753. case AUDCLNT_E_DEVICE_INVALIDATED: e = "AUDCLNT_E_DEVICE_INVALIDATED"; break;
  191754. case AUDCLNT_E_NOT_STOPPED: e = "AUDCLNT_E_NOT_STOPPED"; break;
  191755. case AUDCLNT_E_BUFFER_TOO_LARGE: e = "AUDCLNT_E_BUFFER_TOO_LARGE"; break;
  191756. case AUDCLNT_E_OUT_OF_ORDER: e = "AUDCLNT_E_OUT_OF_ORDER"; break;
  191757. case AUDCLNT_E_UNSUPPORTED_FORMAT: e = "AUDCLNT_E_UNSUPPORTED_FORMAT"; break;
  191758. case AUDCLNT_E_INVALID_SIZE: e = "AUDCLNT_E_INVALID_SIZE"; break;
  191759. case AUDCLNT_E_DEVICE_IN_USE: e = "AUDCLNT_E_DEVICE_IN_USE"; break;
  191760. case AUDCLNT_E_BUFFER_OPERATION_PENDING: e = "AUDCLNT_E_BUFFER_OPERATION_PENDING"; break;
  191761. case AUDCLNT_E_THREAD_NOT_REGISTERED: e = "AUDCLNT_E_THREAD_NOT_REGISTERED"; break;
  191762. case AUDCLNT_E_EXCLUSIVE_MODE_NOT_ALLOWED: e = "AUDCLNT_E_EXCLUSIVE_MODE_NOT_ALLOWED"; break;
  191763. case AUDCLNT_E_ENDPOINT_CREATE_FAILED: e = "AUDCLNT_E_ENDPOINT_CREATE_FAILED"; break;
  191764. case AUDCLNT_E_SERVICE_NOT_RUNNING: e = "AUDCLNT_E_SERVICE_NOT_RUNNING"; break;
  191765. case AUDCLNT_E_EVENTHANDLE_NOT_EXPECTED: e = "AUDCLNT_E_EVENTHANDLE_NOT_EXPECTED"; break;
  191766. case AUDCLNT_E_EXCLUSIVE_MODE_ONLY: e = "AUDCLNT_E_EXCLUSIVE_MODE_ONLY"; break;
  191767. case AUDCLNT_E_BUFDURATION_PERIOD_NOT_EQUAL: e = "AUDCLNT_E_BUFDURATION_PERIOD_NOT_EQUAL"; break;
  191768. case AUDCLNT_E_EVENTHANDLE_NOT_SET: e = "AUDCLNT_E_EVENTHANDLE_NOT_SET"; break;
  191769. case AUDCLNT_E_INCORRECT_BUFFER_SIZE: e = "AUDCLNT_E_INCORRECT_BUFFER_SIZE"; break;
  191770. case AUDCLNT_E_BUFFER_SIZE_ERROR: e = "AUDCLNT_E_BUFFER_SIZE_ERROR"; break;
  191771. case AUDCLNT_S_BUFFER_EMPTY: e = "AUDCLNT_S_BUFFER_EMPTY"; break;
  191772. case AUDCLNT_S_THREAD_ALREADY_REGISTERED: e = "AUDCLNT_S_THREAD_ALREADY_REGISTERED"; break;
  191773. default: return String::toHexString ((int) hr);
  191774. }
  191775. return e;
  191776. }
  191777. #define logFailure(hr) { if (FAILED (hr)) { DBG ("WASAPI FAIL! " + getAudioErrorDesc (hr)); jassertfalse } }
  191778. #define OK(a) wasapi_checkResult(a)
  191779. static bool wasapi_checkResult (HRESULT hr)
  191780. {
  191781. logFailure (hr);
  191782. return SUCCEEDED (hr);
  191783. }
  191784. #else
  191785. #define logFailure(hr) {}
  191786. #define OK(a) SUCCEEDED(a)
  191787. #endif
  191788. static const String wasapi_getDeviceID (IMMDevice* const device)
  191789. {
  191790. String s;
  191791. WCHAR* deviceId = 0;
  191792. if (OK (device->GetId (&deviceId)))
  191793. {
  191794. s = String (deviceId);
  191795. CoTaskMemFree (deviceId);
  191796. }
  191797. return s;
  191798. }
  191799. static EDataFlow wasapi_getDataFlow (IMMDevice* const device)
  191800. {
  191801. EDataFlow flow = eRender;
  191802. ComSmartPtr <IMMEndpoint> endPoint;
  191803. if (OK (device->QueryInterface (__uuidof (IMMEndpoint), (void**) &endPoint)))
  191804. (void) OK (endPoint->GetDataFlow (&flow));
  191805. return flow;
  191806. }
  191807. static int wasapi_refTimeToSamples (const REFERENCE_TIME& t, const double sampleRate) throw()
  191808. {
  191809. return roundDoubleToInt (sampleRate * ((double) t) * 0.0000001);
  191810. }
  191811. static void wasapi_copyWavFormat (WAVEFORMATEXTENSIBLE& dest, const WAVEFORMATEX* const src) throw()
  191812. {
  191813. memcpy (&dest, src, src->wFormatTag == WAVE_FORMAT_EXTENSIBLE ? sizeof (WAVEFORMATEXTENSIBLE)
  191814. : sizeof (WAVEFORMATEX));
  191815. }
  191816. class WASAPIDeviceBase
  191817. {
  191818. public:
  191819. WASAPIDeviceBase (const ComSmartPtr <IMMDevice>& device_)
  191820. : device (device_),
  191821. sampleRate (0),
  191822. numChannels (0),
  191823. actualNumChannels (0),
  191824. defaultSampleRate (0),
  191825. minBufferSize (0),
  191826. defaultBufferSize (0),
  191827. latencySamples (0)
  191828. {
  191829. clientEvent = CreateEvent (0, false, false, _T("JuceWASAPI"));
  191830. ComSmartPtr <IAudioClient> tempClient (createClient());
  191831. if (tempClient == 0)
  191832. return;
  191833. REFERENCE_TIME defaultPeriod, minPeriod;
  191834. if (! OK (tempClient->GetDevicePeriod (&defaultPeriod, &minPeriod)))
  191835. return;
  191836. WAVEFORMATEX* mixFormat = 0;
  191837. if (! OK (tempClient->GetMixFormat (&mixFormat)))
  191838. return;
  191839. WAVEFORMATEXTENSIBLE format;
  191840. wasapi_copyWavFormat (format, mixFormat);
  191841. CoTaskMemFree (mixFormat);
  191842. actualNumChannels = numChannels = format.Format.nChannels;
  191843. defaultSampleRate = format.Format.nSamplesPerSec;
  191844. minBufferSize = wasapi_refTimeToSamples (minPeriod, defaultSampleRate);
  191845. defaultBufferSize = wasapi_refTimeToSamples (defaultPeriod, defaultSampleRate);
  191846. FloatElementComparator<double> comparator;
  191847. rates.addSorted (comparator, defaultSampleRate);
  191848. static const double ratesToTest[] = { 44100.0, 48000.0, 88200.0, 96000.0 };
  191849. for (int i = 0; i < numElementsInArray (ratesToTest); ++i)
  191850. {
  191851. if (ratesToTest[i] == defaultSampleRate)
  191852. continue;
  191853. format.Format.nSamplesPerSec = roundDoubleToInt (ratesToTest[i]);
  191854. if (SUCCEEDED (tempClient->IsFormatSupported (AUDCLNT_SHAREMODE_SHARED, (WAVEFORMATEX*) &format, 0)))
  191855. if (! rates.contains (ratesToTest[i]))
  191856. rates.addSorted (comparator, ratesToTest[i]);
  191857. }
  191858. }
  191859. ~WASAPIDeviceBase()
  191860. {
  191861. device = 0;
  191862. CloseHandle (clientEvent);
  191863. }
  191864. bool isOk() const throw() { return defaultBufferSize > 0 && defaultSampleRate > 0; }
  191865. bool openClient (const double newSampleRate, const BitArray& newChannels)
  191866. {
  191867. sampleRate = newSampleRate;
  191868. channels = newChannels;
  191869. channels.setRange (actualNumChannels, channels.getHighestBit() + 1 - actualNumChannels, false);
  191870. numChannels = channels.getHighestBit() + 1;
  191871. if (numChannels == 0)
  191872. return true;
  191873. client = createClient();
  191874. if (client != 0
  191875. && (tryInitialisingWithFormat (true, 4) || tryInitialisingWithFormat (false, 4)
  191876. || tryInitialisingWithFormat (false, 3) || tryInitialisingWithFormat (false, 2)))
  191877. {
  191878. channelMaps.clear();
  191879. for (int i = 0; i <= channels.getHighestBit(); ++i)
  191880. if (channels[i])
  191881. channelMaps.add (i);
  191882. REFERENCE_TIME latency;
  191883. if (OK (client->GetStreamLatency (&latency)))
  191884. latencySamples = wasapi_refTimeToSamples (latency, sampleRate);
  191885. (void) OK (client->GetBufferSize (&actualBufferSize));
  191886. return OK (client->SetEventHandle (clientEvent));
  191887. }
  191888. return false;
  191889. }
  191890. void closeClient()
  191891. {
  191892. if (client != 0)
  191893. client->Stop();
  191894. client = 0;
  191895. ResetEvent (clientEvent);
  191896. }
  191897. ComSmartPtr <IMMDevice> device;
  191898. ComSmartPtr <IAudioClient> client;
  191899. double sampleRate, defaultSampleRate;
  191900. int numChannels, actualNumChannels;
  191901. int minBufferSize, defaultBufferSize, latencySamples;
  191902. Array <double> rates;
  191903. HANDLE clientEvent;
  191904. BitArray channels;
  191905. AudioDataConverters::DataFormat dataFormat;
  191906. Array <int> channelMaps;
  191907. UINT32 actualBufferSize;
  191908. int bytesPerSample;
  191909. private:
  191910. const ComSmartPtr <IAudioClient> createClient()
  191911. {
  191912. ComSmartPtr <IAudioClient> client;
  191913. if (device != 0)
  191914. {
  191915. HRESULT hr = device->Activate (__uuidof (IAudioClient), CLSCTX_INPROC_SERVER, 0, (void**) &client);
  191916. logFailure (hr);
  191917. }
  191918. return client;
  191919. }
  191920. bool tryInitialisingWithFormat (const bool useFloat, const int bytesPerSampleToTry)
  191921. {
  191922. WAVEFORMATEXTENSIBLE format;
  191923. zerostruct (format);
  191924. if (numChannels <= 2 && bytesPerSampleToTry <= 2)
  191925. {
  191926. format.Format.wFormatTag = WAVE_FORMAT_PCM;
  191927. }
  191928. else
  191929. {
  191930. format.Format.wFormatTag = WAVE_FORMAT_EXTENSIBLE;
  191931. format.Format.cbSize = sizeof (WAVEFORMATEXTENSIBLE) - sizeof (WAVEFORMATEX);
  191932. }
  191933. format.Format.nSamplesPerSec = roundDoubleToInt (sampleRate);
  191934. format.Format.nChannels = (WORD) numChannels;
  191935. format.Format.wBitsPerSample = (WORD) (8 * bytesPerSampleToTry);
  191936. format.Format.nAvgBytesPerSec = (DWORD) (format.Format.nSamplesPerSec * numChannels * bytesPerSampleToTry);
  191937. format.Format.nBlockAlign = (WORD) (numChannels * bytesPerSampleToTry);
  191938. format.SubFormat = useFloat ? KSDATAFORMAT_SUBTYPE_IEEE_FLOAT : KSDATAFORMAT_SUBTYPE_PCM;
  191939. format.Samples.wValidBitsPerSample = format.Format.wBitsPerSample;
  191940. switch (numChannels)
  191941. {
  191942. case 1: format.dwChannelMask = SPEAKER_FRONT_CENTER; break;
  191943. case 2: format.dwChannelMask = SPEAKER_FRONT_LEFT | SPEAKER_FRONT_RIGHT; break;
  191944. case 4: format.dwChannelMask = SPEAKER_FRONT_LEFT | SPEAKER_FRONT_RIGHT | SPEAKER_BACK_LEFT | SPEAKER_BACK_RIGHT; break;
  191945. case 6: format.dwChannelMask = SPEAKER_FRONT_LEFT | SPEAKER_FRONT_RIGHT | SPEAKER_FRONT_CENTER | SPEAKER_LOW_FREQUENCY | SPEAKER_BACK_LEFT | SPEAKER_BACK_RIGHT; break;
  191946. 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;
  191947. default: break;
  191948. }
  191949. WAVEFORMATEXTENSIBLE* nearestFormat = 0;
  191950. HRESULT hr = client->IsFormatSupported (AUDCLNT_SHAREMODE_SHARED, (WAVEFORMATEX*) &format, (WAVEFORMATEX**) &nearestFormat);
  191951. logFailure (hr);
  191952. if (hr == S_FALSE && format.Format.nSamplesPerSec == nearestFormat->Format.nSamplesPerSec)
  191953. {
  191954. wasapi_copyWavFormat (format, (WAVEFORMATEX*) nearestFormat);
  191955. hr = S_OK;
  191956. }
  191957. CoTaskMemFree (nearestFormat);
  191958. GUID session;
  191959. if (hr == S_OK
  191960. && OK (client->Initialize (AUDCLNT_SHAREMODE_SHARED, AUDCLNT_STREAMFLAGS_EVENTCALLBACK,
  191961. 0, 0, (WAVEFORMATEX*) &format, &session)))
  191962. {
  191963. actualNumChannels = format.Format.nChannels;
  191964. const bool isFloat = format.Format.wFormatTag == WAVE_FORMAT_EXTENSIBLE && format.SubFormat == KSDATAFORMAT_SUBTYPE_IEEE_FLOAT;
  191965. bytesPerSample = format.Format.wBitsPerSample / 8;
  191966. dataFormat = isFloat ? AudioDataConverters::float32LE
  191967. : (bytesPerSample == 4 ? AudioDataConverters::int32LE
  191968. : ((bytesPerSample == 3 ? AudioDataConverters::int24LE
  191969. : AudioDataConverters::int16LE)));
  191970. return true;
  191971. }
  191972. return false;
  191973. }
  191974. };
  191975. class WASAPIInputDevice : public WASAPIDeviceBase
  191976. {
  191977. public:
  191978. WASAPIInputDevice (const ComSmartPtr <IMMDevice>& device_)
  191979. : WASAPIDeviceBase (device_),
  191980. reservoir (1, 1)
  191981. {
  191982. }
  191983. ~WASAPIInputDevice()
  191984. {
  191985. close();
  191986. }
  191987. bool open (const double newSampleRate, const BitArray& newChannels)
  191988. {
  191989. reservoirSize = 0;
  191990. reservoirCapacity = 16384;
  191991. reservoir.setSize (actualNumChannels * reservoirCapacity * sizeof (float));
  191992. return openClient (newSampleRate, newChannels)
  191993. && (numChannels == 0 || OK (client->GetService (__uuidof (IAudioCaptureClient), (void**) &captureClient)));
  191994. }
  191995. void close()
  191996. {
  191997. closeClient();
  191998. captureClient = 0;
  191999. reservoir.setSize (0);
  192000. }
  192001. void copyBuffers (float** destBuffers, int numDestBuffers, int bufferSize, Thread& thread)
  192002. {
  192003. if (numChannels <= 0)
  192004. return;
  192005. int offset = 0;
  192006. while (bufferSize > 0)
  192007. {
  192008. if (reservoirSize > 0) // There's stuff in the reservoir, so use that...
  192009. {
  192010. const int samplesToDo = jmin (bufferSize, (int) reservoirSize);
  192011. for (int i = 0; i < numDestBuffers; ++i)
  192012. {
  192013. float* const dest = destBuffers[i] + offset;
  192014. const int srcChan = channelMaps.getUnchecked(i);
  192015. switch (dataFormat)
  192016. {
  192017. case AudioDataConverters::float32LE:
  192018. AudioDataConverters::convertFloat32LEToFloat (((uint8*) reservoir.getData()) + 4 * srcChan, dest, samplesToDo, 4 * actualNumChannels);
  192019. break;
  192020. case AudioDataConverters::int32LE:
  192021. AudioDataConverters::convertInt32LEToFloat (((uint8*) reservoir.getData()) + 4 * srcChan, dest, samplesToDo, 4 * actualNumChannels);
  192022. break;
  192023. case AudioDataConverters::int24LE:
  192024. AudioDataConverters::convertInt24LEToFloat (((uint8*) reservoir.getData()) + 3 * srcChan, dest, samplesToDo, 3 * actualNumChannels);
  192025. break;
  192026. case AudioDataConverters::int16LE:
  192027. AudioDataConverters::convertInt16LEToFloat (((uint8*) reservoir.getData()) + 2 * srcChan, dest, samplesToDo, 2 * actualNumChannels);
  192028. break;
  192029. default: jassertfalse; break;
  192030. }
  192031. }
  192032. bufferSize -= samplesToDo;
  192033. offset += samplesToDo;
  192034. reservoirSize -= samplesToDo;
  192035. }
  192036. else
  192037. {
  192038. UINT32 packetLength = 0;
  192039. if (! OK (captureClient->GetNextPacketSize (&packetLength)))
  192040. break;
  192041. if (packetLength == 0)
  192042. {
  192043. if (thread.threadShouldExit())
  192044. break;
  192045. Thread::sleep (1);
  192046. continue;
  192047. }
  192048. uint8* inputData = 0;
  192049. UINT32 numSamplesAvailable;
  192050. DWORD flags;
  192051. if (OK (captureClient->GetBuffer (&inputData, &numSamplesAvailable, &flags, 0, 0)))
  192052. {
  192053. const int samplesToDo = jmin (bufferSize, (int) numSamplesAvailable);
  192054. for (int i = 0; i < numDestBuffers; ++i)
  192055. {
  192056. float* const dest = destBuffers[i] + offset;
  192057. const int srcChan = channelMaps.getUnchecked(i);
  192058. switch (dataFormat)
  192059. {
  192060. case AudioDataConverters::float32LE:
  192061. AudioDataConverters::convertFloat32LEToFloat (inputData + 4 * srcChan, dest, samplesToDo, 4 * actualNumChannels);
  192062. break;
  192063. case AudioDataConverters::int32LE:
  192064. AudioDataConverters::convertInt32LEToFloat (inputData + 4 * srcChan, dest, samplesToDo, 4 * actualNumChannels);
  192065. break;
  192066. case AudioDataConverters::int24LE:
  192067. AudioDataConverters::convertInt24LEToFloat (inputData + 3 * srcChan, dest, samplesToDo, 3 * actualNumChannels);
  192068. break;
  192069. case AudioDataConverters::int16LE:
  192070. AudioDataConverters::convertInt16LEToFloat (inputData + 2 * srcChan, dest, samplesToDo, 2 * actualNumChannels);
  192071. break;
  192072. default: jassertfalse; break;
  192073. }
  192074. }
  192075. bufferSize -= samplesToDo;
  192076. offset += samplesToDo;
  192077. if (samplesToDo < numSamplesAvailable)
  192078. {
  192079. reservoirSize = jmin ((int) (numSamplesAvailable - samplesToDo), reservoirCapacity);
  192080. memcpy ((uint8*) reservoir.getData(), inputData + bytesPerSample * actualNumChannels * samplesToDo,
  192081. bytesPerSample * actualNumChannels * reservoirSize);
  192082. }
  192083. captureClient->ReleaseBuffer (numSamplesAvailable);
  192084. }
  192085. }
  192086. }
  192087. }
  192088. ComSmartPtr <IAudioCaptureClient> captureClient;
  192089. MemoryBlock reservoir;
  192090. int reservoirSize, reservoirCapacity;
  192091. };
  192092. class WASAPIOutputDevice : public WASAPIDeviceBase
  192093. {
  192094. public:
  192095. WASAPIOutputDevice (const ComSmartPtr <IMMDevice>& device_)
  192096. : WASAPIDeviceBase (device_)
  192097. {
  192098. }
  192099. ~WASAPIOutputDevice()
  192100. {
  192101. close();
  192102. }
  192103. bool open (const double newSampleRate, const BitArray& newChannels)
  192104. {
  192105. return openClient (newSampleRate, newChannels)
  192106. && (numChannels == 0 || OK (client->GetService (__uuidof (IAudioRenderClient), (void**) &renderClient)));
  192107. }
  192108. void close()
  192109. {
  192110. closeClient();
  192111. renderClient = 0;
  192112. }
  192113. void copyBuffers (const float** const srcBuffers, const int numSrcBuffers, int bufferSize, Thread& thread)
  192114. {
  192115. if (numChannels <= 0)
  192116. return;
  192117. int offset = 0;
  192118. while (bufferSize > 0)
  192119. {
  192120. UINT32 padding = 0;
  192121. if (! OK (client->GetCurrentPadding (&padding)))
  192122. return;
  192123. const int samplesToDo = jmin ((int) (actualBufferSize - padding), bufferSize);
  192124. if (samplesToDo <= 0)
  192125. {
  192126. if (thread.threadShouldExit())
  192127. break;
  192128. Thread::sleep (0);
  192129. continue;
  192130. }
  192131. uint8* outputData = 0;
  192132. if (OK (renderClient->GetBuffer (samplesToDo, &outputData)))
  192133. {
  192134. for (int i = 0; i < numSrcBuffers; ++i)
  192135. {
  192136. const float* const source = srcBuffers[i] + offset;
  192137. const int destChan = channelMaps.getUnchecked(i);
  192138. switch (dataFormat)
  192139. {
  192140. case AudioDataConverters::float32LE:
  192141. AudioDataConverters::convertFloatToFloat32LE (source, outputData + 4 * destChan, samplesToDo, 4 * actualNumChannels);
  192142. break;
  192143. case AudioDataConverters::int32LE:
  192144. AudioDataConverters::convertFloatToInt32LE (source, outputData + 4 * destChan, samplesToDo, 4 * actualNumChannels);
  192145. break;
  192146. case AudioDataConverters::int24LE:
  192147. AudioDataConverters::convertFloatToInt24LE (source, outputData + 3 * destChan, samplesToDo, 3 * actualNumChannels);
  192148. break;
  192149. case AudioDataConverters::int16LE:
  192150. AudioDataConverters::convertFloatToInt16LE (source, outputData + 2 * destChan, samplesToDo, 2 * actualNumChannels);
  192151. break;
  192152. default: jassertfalse; break;
  192153. }
  192154. }
  192155. renderClient->ReleaseBuffer (samplesToDo, 0);
  192156. offset += samplesToDo;
  192157. bufferSize -= samplesToDo;
  192158. }
  192159. }
  192160. }
  192161. ComSmartPtr <IAudioRenderClient> renderClient;
  192162. };
  192163. class WASAPIAudioIODevice : public AudioIODevice,
  192164. public Thread
  192165. {
  192166. public:
  192167. WASAPIAudioIODevice (const String& deviceName,
  192168. const String& outputDeviceId_,
  192169. const String& inputDeviceId_)
  192170. : AudioIODevice (deviceName, "Windows Audio"),
  192171. Thread ("Juce WASAPI"),
  192172. isOpen_ (false),
  192173. isStarted (false),
  192174. outputDevice (0),
  192175. outputDeviceId (outputDeviceId_),
  192176. inputDevice (0),
  192177. inputDeviceId (inputDeviceId_),
  192178. currentBufferSizeSamples (0),
  192179. currentSampleRate (0),
  192180. callback (0)
  192181. {
  192182. }
  192183. ~WASAPIAudioIODevice()
  192184. {
  192185. close();
  192186. deleteAndZero (inputDevice);
  192187. deleteAndZero (outputDevice);
  192188. }
  192189. bool initialise()
  192190. {
  192191. double defaultSampleRateIn = 0, defaultSampleRateOut = 0;
  192192. int minBufferSizeIn = 0, defaultBufferSizeIn = 0, minBufferSizeOut = 0, defaultBufferSizeOut = 0;
  192193. latencyIn = latencyOut = 0;
  192194. Array <double> ratesIn, ratesOut;
  192195. if (createDevices())
  192196. {
  192197. jassert (inputDevice != 0 || outputDevice != 0);
  192198. if (inputDevice != 0 && outputDevice != 0)
  192199. {
  192200. defaultSampleRate = jmin (inputDevice->defaultSampleRate, outputDevice->defaultSampleRate);
  192201. minBufferSize = jmin (inputDevice->minBufferSize, outputDevice->minBufferSize);
  192202. defaultBufferSize = jmax (inputDevice->defaultBufferSize, outputDevice->defaultBufferSize);
  192203. sampleRates = inputDevice->rates;
  192204. sampleRates.removeValuesNotIn (outputDevice->rates);
  192205. }
  192206. else
  192207. {
  192208. WASAPIDeviceBase* const d = inputDevice != 0 ? (WASAPIDeviceBase*) inputDevice : (WASAPIDeviceBase*) outputDevice;
  192209. defaultSampleRate = d->defaultSampleRate;
  192210. minBufferSize = d->minBufferSize;
  192211. defaultBufferSize = d->defaultBufferSize;
  192212. sampleRates = d->rates;
  192213. }
  192214. IntegerElementComparator<int> comparator;
  192215. bufferSizes.addSorted (comparator, defaultBufferSize);
  192216. if (minBufferSize != defaultBufferSize)
  192217. bufferSizes.addSorted (comparator, minBufferSize);
  192218. int n = 64;
  192219. for (int i = 0; i < 40; ++i)
  192220. {
  192221. if (n >= minBufferSize && n <= 2048 && ! bufferSizes.contains (n))
  192222. bufferSizes.addSorted (comparator, n);
  192223. n += (n < 512) ? 32 : (n < 1024 ? 64 : 128);
  192224. }
  192225. return true;
  192226. }
  192227. return false;
  192228. }
  192229. const StringArray getOutputChannelNames()
  192230. {
  192231. StringArray outChannels;
  192232. if (outputDevice != 0)
  192233. for (int i = 1; i <= outputDevice->actualNumChannels; ++i)
  192234. outChannels.add ("Output channel " + String (i));
  192235. return outChannels;
  192236. }
  192237. const StringArray getInputChannelNames()
  192238. {
  192239. StringArray inChannels;
  192240. if (inputDevice != 0)
  192241. for (int i = 1; i <= inputDevice->actualNumChannels; ++i)
  192242. inChannels.add ("Input channel " + String (i));
  192243. return inChannels;
  192244. }
  192245. int getNumSampleRates() { return sampleRates.size(); }
  192246. double getSampleRate (int index) { return sampleRates [index]; }
  192247. int getNumBufferSizesAvailable() { return bufferSizes.size(); }
  192248. int getBufferSizeSamples (int index) { return bufferSizes [index]; }
  192249. int getDefaultBufferSize() { return defaultBufferSize; }
  192250. int getCurrentBufferSizeSamples() { return currentBufferSizeSamples; }
  192251. double getCurrentSampleRate() { return currentSampleRate; }
  192252. int getCurrentBitDepth() { return 32; }
  192253. int getOutputLatencyInSamples() { return latencyOut; }
  192254. int getInputLatencyInSamples() { return latencyIn; }
  192255. const BitArray getActiveOutputChannels() const { return outputDevice != 0 ? outputDevice->channels : BitArray(); }
  192256. const BitArray getActiveInputChannels() const { return inputDevice != 0 ? inputDevice->channels : BitArray(); }
  192257. const String getLastError() { return lastError; }
  192258. const String open (const BitArray& inputChannels, const BitArray& outputChannels,
  192259. double sampleRate, int bufferSizeSamples)
  192260. {
  192261. close();
  192262. lastError = String::empty;
  192263. if (sampleRates.size() == 0 && inputDevice != 0 && outputDevice != 0)
  192264. {
  192265. lastError = "The input and output devices don't share a common sample rate!";
  192266. return lastError;
  192267. }
  192268. currentBufferSizeSamples = bufferSizeSamples <= 0 ? defaultBufferSize : jmax (bufferSizeSamples, minBufferSize);
  192269. currentSampleRate = sampleRate > 0 ? sampleRate : defaultSampleRate;
  192270. if (inputDevice != 0 && ! inputDevice->open (currentSampleRate, inputChannels))
  192271. {
  192272. lastError = "Couldn't open the input device!";
  192273. return lastError;
  192274. }
  192275. if (outputDevice != 0 && ! outputDevice->open (currentSampleRate, outputChannels))
  192276. {
  192277. close();
  192278. lastError = "Couldn't open the output device!";
  192279. return lastError;
  192280. }
  192281. if (inputDevice != 0)
  192282. ResetEvent (inputDevice->clientEvent);
  192283. if (outputDevice != 0)
  192284. ResetEvent (outputDevice->clientEvent);
  192285. startThread (8);
  192286. Thread::sleep (5);
  192287. if (inputDevice != 0 && inputDevice->client != 0)
  192288. {
  192289. latencyIn = inputDevice->latencySamples + inputDevice->actualBufferSize + inputDevice->minBufferSize;
  192290. HRESULT hr = inputDevice->client->Start();
  192291. logFailure (hr); //xxx handle this
  192292. }
  192293. if (outputDevice != 0 && outputDevice->client != 0)
  192294. {
  192295. latencyOut = outputDevice->latencySamples + outputDevice->actualBufferSize + outputDevice->minBufferSize;
  192296. HRESULT hr = outputDevice->client->Start();
  192297. logFailure (hr); //xxx handle this
  192298. }
  192299. isOpen_ = true;
  192300. return lastError;
  192301. }
  192302. void close()
  192303. {
  192304. stop();
  192305. if (inputDevice != 0)
  192306. SetEvent (inputDevice->clientEvent);
  192307. if (outputDevice != 0)
  192308. SetEvent (outputDevice->clientEvent);
  192309. stopThread (5000);
  192310. if (inputDevice != 0)
  192311. inputDevice->close();
  192312. if (outputDevice != 0)
  192313. outputDevice->close();
  192314. isOpen_ = false;
  192315. }
  192316. bool isOpen() { return isOpen_ && isThreadRunning(); }
  192317. bool isPlaying() { return isStarted && isOpen_ && isThreadRunning(); }
  192318. void start (AudioIODeviceCallback* call)
  192319. {
  192320. if (isOpen_ && call != 0 && ! isStarted)
  192321. {
  192322. if (! isThreadRunning())
  192323. {
  192324. // something's gone wrong and the thread's stopped..
  192325. isOpen_ = false;
  192326. return;
  192327. }
  192328. call->audioDeviceAboutToStart (this);
  192329. const ScopedLock sl (startStopLock);
  192330. callback = call;
  192331. isStarted = true;
  192332. }
  192333. }
  192334. void stop()
  192335. {
  192336. if (isStarted)
  192337. {
  192338. AudioIODeviceCallback* const callbackLocal = callback;
  192339. {
  192340. const ScopedLock sl (startStopLock);
  192341. isStarted = false;
  192342. }
  192343. if (callbackLocal != 0)
  192344. callbackLocal->audioDeviceStopped();
  192345. }
  192346. }
  192347. void setMMThreadPriority()
  192348. {
  192349. DynamicLibraryLoader dll ("avrt.dll");
  192350. DynamicLibraryImport (AvSetMmThreadCharacteristics, avSetMmThreadCharacteristics, HANDLE, dll, (LPCTSTR, LPDWORD))
  192351. DynamicLibraryImport (AvSetMmThreadPriority, avSetMmThreadPriority, HANDLE, dll, (HANDLE, AVRT_PRIORITY))
  192352. if (avSetMmThreadCharacteristics != 0 && avSetMmThreadPriority != 0)
  192353. {
  192354. DWORD dummy = 0;
  192355. HANDLE h = avSetMmThreadCharacteristics (_T("Pro Audio"), &dummy);
  192356. if (h != 0)
  192357. avSetMmThreadPriority (h, AVRT_PRIORITY_NORMAL);
  192358. }
  192359. }
  192360. void run()
  192361. {
  192362. setMMThreadPriority();
  192363. const int bufferSize = currentBufferSizeSamples;
  192364. HANDLE events[2];
  192365. int numEvents = 0;
  192366. if (inputDevice != 0)
  192367. events [numEvents++] = inputDevice->clientEvent;
  192368. if (outputDevice != 0)
  192369. events [numEvents++] = outputDevice->clientEvent;
  192370. const int numInputBuffers = getActiveInputChannels().countNumberOfSetBits();
  192371. const int numOutputBuffers = getActiveOutputChannels().countNumberOfSetBits();
  192372. AudioSampleBuffer ins (jmax (1, numInputBuffers), bufferSize + 32);
  192373. AudioSampleBuffer outs (jmax (1, numOutputBuffers), bufferSize + 32);
  192374. float** const inputBuffers = ins.getArrayOfChannels();
  192375. float** const outputBuffers = outs.getArrayOfChannels();
  192376. ins.clear();
  192377. while (! threadShouldExit())
  192378. {
  192379. const DWORD result = WaitForMultipleObjects (numEvents, events, true, 1000);
  192380. if (result == WAIT_TIMEOUT)
  192381. continue;
  192382. if (threadShouldExit())
  192383. break;
  192384. if (inputDevice != 0)
  192385. inputDevice->copyBuffers (inputBuffers, numInputBuffers, bufferSize, *this);
  192386. // Make the callback..
  192387. {
  192388. const ScopedLock sl (startStopLock);
  192389. if (isStarted)
  192390. {
  192391. JUCE_TRY
  192392. {
  192393. callback->audioDeviceIOCallback ((const float**) inputBuffers,
  192394. numInputBuffers,
  192395. outputBuffers,
  192396. numOutputBuffers,
  192397. bufferSize);
  192398. }
  192399. JUCE_CATCH_EXCEPTION
  192400. }
  192401. else
  192402. {
  192403. outs.clear();
  192404. }
  192405. }
  192406. if (outputDevice != 0)
  192407. outputDevice->copyBuffers ((const float**) outputBuffers, numOutputBuffers, bufferSize, *this);
  192408. }
  192409. }
  192410. juce_UseDebuggingNewOperator
  192411. String outputDeviceId, inputDeviceId;
  192412. String lastError;
  192413. private:
  192414. // Device stats...
  192415. WASAPIInputDevice* inputDevice;
  192416. WASAPIOutputDevice* outputDevice;
  192417. double defaultSampleRate;
  192418. int minBufferSize, defaultBufferSize;
  192419. int latencyIn, latencyOut;
  192420. Array <double> sampleRates;
  192421. Array <int> bufferSizes;
  192422. // Active state...
  192423. bool isOpen_, isStarted;
  192424. int currentBufferSizeSamples;
  192425. double currentSampleRate;
  192426. AudioIODeviceCallback* callback;
  192427. CriticalSection startStopLock;
  192428. bool createDevices()
  192429. {
  192430. ComSmartPtr <IMMDeviceEnumerator> enumerator;
  192431. if (! OK (enumerator.CoCreateInstance (__uuidof (MMDeviceEnumerator), CLSCTX_INPROC_SERVER)))
  192432. return false;
  192433. ComSmartPtr <IMMDeviceCollection> deviceCollection;
  192434. if (! OK (enumerator->EnumAudioEndpoints (eAll, DEVICE_STATE_ACTIVE, &deviceCollection)))
  192435. return false;
  192436. UINT32 numDevices = 0;
  192437. if (! OK (deviceCollection->GetCount (&numDevices)))
  192438. return false;
  192439. for (UINT32 i = 0; i < numDevices; ++i)
  192440. {
  192441. ComSmartPtr <IMMDevice> device;
  192442. if (! OK (deviceCollection->Item (i, &device)))
  192443. continue;
  192444. const String deviceId (wasapi_getDeviceID (device));
  192445. if (deviceId.isEmpty())
  192446. continue;
  192447. const EDataFlow flow = wasapi_getDataFlow (device);
  192448. if (deviceId == inputDeviceId && flow == eCapture)
  192449. inputDevice = new WASAPIInputDevice (device);
  192450. else if (deviceId == outputDeviceId && flow == eRender)
  192451. outputDevice = new WASAPIOutputDevice (device);
  192452. }
  192453. return (outputDeviceId.isEmpty() || (outputDevice != 0 && outputDevice->isOk()))
  192454. && (inputDeviceId.isEmpty() || (inputDevice != 0 && inputDevice->isOk()));
  192455. }
  192456. WASAPIAudioIODevice (const WASAPIAudioIODevice&);
  192457. const WASAPIAudioIODevice& operator= (const WASAPIAudioIODevice&);
  192458. };
  192459. class WASAPIAudioIODeviceType : public AudioIODeviceType
  192460. {
  192461. public:
  192462. WASAPIAudioIODeviceType()
  192463. : AudioIODeviceType (T("Windows Audio")),
  192464. hasScanned (false)
  192465. {
  192466. }
  192467. ~WASAPIAudioIODeviceType()
  192468. {
  192469. }
  192470. void scanForDevices()
  192471. {
  192472. hasScanned = true;
  192473. outputDeviceNames.clear();
  192474. inputDeviceNames.clear();
  192475. outputDeviceIds.clear();
  192476. inputDeviceIds.clear();
  192477. ComSmartPtr <IMMDeviceEnumerator> enumerator;
  192478. if (! OK (enumerator.CoCreateInstance (__uuidof (MMDeviceEnumerator), CLSCTX_INPROC_SERVER)))
  192479. return;
  192480. const String defaultRenderer = getDefaultEndpoint (enumerator, false);
  192481. const String defaultCapture = getDefaultEndpoint (enumerator, true);
  192482. ComSmartPtr <IMMDeviceCollection> deviceCollection;
  192483. UINT32 numDevices = 0;
  192484. if (! (OK (enumerator->EnumAudioEndpoints (eAll, DEVICE_STATE_ACTIVE, &deviceCollection))
  192485. && OK (deviceCollection->GetCount (&numDevices))))
  192486. return;
  192487. for (UINT32 i = 0; i < numDevices; ++i)
  192488. {
  192489. ComSmartPtr <IMMDevice> device;
  192490. if (! OK (deviceCollection->Item (i, &device)))
  192491. continue;
  192492. const String deviceId (wasapi_getDeviceID (device));
  192493. DWORD state = 0;
  192494. if (! OK (device->GetState (&state)))
  192495. continue;
  192496. if (state != DEVICE_STATE_ACTIVE)
  192497. continue;
  192498. String name;
  192499. {
  192500. ComSmartPtr <IPropertyStore> properties;
  192501. if (! OK (device->OpenPropertyStore (STGM_READ, &properties)))
  192502. continue;
  192503. PROPVARIANT value;
  192504. PropVariantInit (&value);
  192505. if (OK (properties->GetValue (PKEY_Device_FriendlyName, &value)))
  192506. name = value.pwszVal;
  192507. PropVariantClear (&value);
  192508. }
  192509. const EDataFlow flow = wasapi_getDataFlow (device);
  192510. if (flow == eRender)
  192511. {
  192512. const int index = (deviceId == defaultRenderer) ? 0 : -1;
  192513. outputDeviceIds.insert (index, deviceId);
  192514. outputDeviceNames.insert (index, name);
  192515. }
  192516. else if (flow == eCapture)
  192517. {
  192518. const int index = (deviceId == defaultCapture) ? 0 : -1;
  192519. inputDeviceIds.insert (index, deviceId);
  192520. inputDeviceNames.insert (index, name);
  192521. }
  192522. }
  192523. inputDeviceNames.appendNumbersToDuplicates (false, false);
  192524. outputDeviceNames.appendNumbersToDuplicates (false, false);
  192525. }
  192526. const StringArray getDeviceNames (const bool wantInputNames) const
  192527. {
  192528. jassert (hasScanned); // need to call scanForDevices() before doing this
  192529. return wantInputNames ? inputDeviceNames
  192530. : outputDeviceNames;
  192531. }
  192532. int getDefaultDeviceIndex (const bool /*forInput*/) const
  192533. {
  192534. jassert (hasScanned); // need to call scanForDevices() before doing this
  192535. return 0;
  192536. }
  192537. int getIndexOfDevice (AudioIODevice* device, const bool asInput) const
  192538. {
  192539. jassert (hasScanned); // need to call scanForDevices() before doing this
  192540. WASAPIAudioIODevice* const d = dynamic_cast <WASAPIAudioIODevice*> (device);
  192541. return d == 0 ? -1 : (asInput ? inputDeviceIds.indexOf (d->inputDeviceId)
  192542. : outputDeviceIds.indexOf (d->outputDeviceId));
  192543. }
  192544. bool hasSeparateInputsAndOutputs() const { return true; }
  192545. AudioIODevice* createDevice (const String& outputDeviceName,
  192546. const String& inputDeviceName)
  192547. {
  192548. jassert (hasScanned); // need to call scanForDevices() before doing this
  192549. WASAPIAudioIODevice* d = 0;
  192550. const int outputIndex = outputDeviceNames.indexOf (outputDeviceName);
  192551. const int inputIndex = inputDeviceNames.indexOf (inputDeviceName);
  192552. if (outputIndex >= 0 || inputIndex >= 0)
  192553. {
  192554. d = new WASAPIAudioIODevice (outputDeviceName.isNotEmpty() ? outputDeviceName
  192555. : inputDeviceName,
  192556. outputDeviceIds [outputIndex],
  192557. inputDeviceIds [inputIndex]);
  192558. if (! d->initialise())
  192559. deleteAndZero (d);
  192560. }
  192561. return d;
  192562. }
  192563. juce_UseDebuggingNewOperator
  192564. StringArray outputDeviceNames, outputDeviceIds;
  192565. StringArray inputDeviceNames, inputDeviceIds;
  192566. private:
  192567. bool hasScanned;
  192568. static const String getDefaultEndpoint (IMMDeviceEnumerator* const enumerator, const bool forCapture)
  192569. {
  192570. String s;
  192571. IMMDevice* dev = 0;
  192572. if (OK (enumerator->GetDefaultAudioEndpoint (forCapture ? eCapture : eRender,
  192573. eMultimedia, &dev)))
  192574. {
  192575. WCHAR* deviceId = 0;
  192576. if (OK (dev->GetId (&deviceId)))
  192577. {
  192578. s = String (deviceId);
  192579. CoTaskMemFree (deviceId);
  192580. }
  192581. dev->Release();
  192582. }
  192583. return s;
  192584. }
  192585. WASAPIAudioIODeviceType (const WASAPIAudioIODeviceType&);
  192586. const WASAPIAudioIODeviceType& operator= (const WASAPIAudioIODeviceType&);
  192587. };
  192588. AudioIODeviceType* juce_createAudioIODeviceType_WASAPI()
  192589. {
  192590. return new WASAPIAudioIODeviceType();
  192591. }
  192592. #undef logFailure
  192593. #undef OK
  192594. #endif
  192595. /********* End of inlined file: juce_win32_WASAPI.cpp *********/
  192596. /********* Start of inlined file: juce_win32_CameraDevice.cpp *********/
  192597. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  192598. // compiled on its own).
  192599. #if JUCE_INCLUDED_FILE && JUCE_USE_CAMERA
  192600. class DShowCameraDeviceInteral : public ChangeBroadcaster
  192601. {
  192602. public:
  192603. DShowCameraDeviceInteral (CameraDevice* const owner_,
  192604. const ComSmartPtr <ICaptureGraphBuilder2>& captureGraphBuilder_,
  192605. const ComSmartPtr <IBaseFilter>& filter_,
  192606. int minWidth, int minHeight,
  192607. int maxWidth, int maxHeight)
  192608. : owner (owner_),
  192609. captureGraphBuilder (captureGraphBuilder_),
  192610. filter (filter_),
  192611. ok (false),
  192612. imageNeedsFlipping (false),
  192613. width (0),
  192614. height (0),
  192615. activeUsers (0),
  192616. recordNextFrameTime (false),
  192617. activeImage (0),
  192618. loadingImage (0)
  192619. {
  192620. HRESULT hr = graphBuilder.CoCreateInstance (CLSID_FilterGraph, CLSCTX_INPROC);
  192621. if (FAILED (hr))
  192622. return;
  192623. hr = captureGraphBuilder->SetFiltergraph (graphBuilder);
  192624. if (FAILED (hr))
  192625. return;
  192626. hr = graphBuilder->QueryInterface (IID_IMediaControl, (void**) &mediaControl);
  192627. if (FAILED (hr))
  192628. return;
  192629. {
  192630. ComSmartPtr <IAMStreamConfig> streamConfig;
  192631. hr = captureGraphBuilder->FindInterface (&PIN_CATEGORY_CAPTURE,
  192632. 0,
  192633. filter,
  192634. IID_IAMStreamConfig,
  192635. (void**) &streamConfig);
  192636. if (streamConfig != 0)
  192637. {
  192638. getVideoSizes (streamConfig);
  192639. if (! selectVideoSize (streamConfig, minWidth, minHeight, maxWidth, maxHeight))
  192640. return;
  192641. }
  192642. }
  192643. hr = graphBuilder->AddFilter (filter, _T("Video Capture"));
  192644. if (FAILED (hr))
  192645. return;
  192646. hr = smartTee.CoCreateInstance (CLSID_SmartTee, CLSCTX_INPROC_SERVER);
  192647. if (FAILED (hr))
  192648. return;
  192649. hr = graphBuilder->AddFilter (smartTee, _T("Smart Tee"));
  192650. if (FAILED (hr))
  192651. return;
  192652. if (! connectFilters (filter, smartTee))
  192653. return;
  192654. ComSmartPtr <IBaseFilter> sampleGrabberBase;
  192655. hr = sampleGrabberBase.CoCreateInstance (CLSID_SampleGrabber, CLSCTX_INPROC_SERVER);
  192656. if (FAILED (hr))
  192657. return;
  192658. hr = sampleGrabberBase->QueryInterface (IID_ISampleGrabber, (void**) &sampleGrabber);
  192659. if (FAILED (hr))
  192660. return;
  192661. AM_MEDIA_TYPE mt;
  192662. zerostruct (mt);
  192663. mt.majortype = MEDIATYPE_Video;
  192664. mt.subtype = MEDIASUBTYPE_RGB24;
  192665. mt.formattype = FORMAT_VideoInfo;
  192666. sampleGrabber->SetMediaType (&mt);
  192667. callback = new GrabberCallback (*this);
  192668. sampleGrabber->SetCallback (callback, 1);
  192669. hr = graphBuilder->AddFilter (sampleGrabberBase, _T("Sample Grabber"));
  192670. if (FAILED (hr))
  192671. return;
  192672. ComSmartPtr <IPin> grabberInputPin;
  192673. if (! (getPin (smartTee, PINDIR_OUTPUT, &smartTeeCaptureOutputPin, "capture")
  192674. && getPin (smartTee, PINDIR_OUTPUT, &smartTeePreviewOutputPin, "preview")
  192675. && getPin (sampleGrabberBase, PINDIR_INPUT, &grabberInputPin)))
  192676. return;
  192677. hr = graphBuilder->Connect (smartTeePreviewOutputPin, grabberInputPin);
  192678. if (FAILED (hr))
  192679. return;
  192680. zerostruct (mt);
  192681. hr = sampleGrabber->GetConnectedMediaType (&mt);
  192682. VIDEOINFOHEADER* pVih = (VIDEOINFOHEADER*) (mt.pbFormat);
  192683. width = pVih->bmiHeader.biWidth;
  192684. height = pVih->bmiHeader.biHeight;
  192685. ComSmartPtr <IBaseFilter> nullFilter;
  192686. hr = nullFilter.CoCreateInstance (CLSID_NullRenderer, CLSCTX_INPROC_SERVER);
  192687. hr = graphBuilder->AddFilter (nullFilter, _T("Null Renderer"));
  192688. if (connectFilters (sampleGrabberBase, nullFilter)
  192689. && addGraphToRot())
  192690. {
  192691. activeImage = new Image (Image::RGB, width, height, true);
  192692. loadingImage = new Image (Image::RGB, width, height, true);
  192693. ok = true;
  192694. }
  192695. }
  192696. ~DShowCameraDeviceInteral()
  192697. {
  192698. if (mediaControl != 0)
  192699. mediaControl->Stop();
  192700. removeGraphFromRot();
  192701. for (int i = viewerComps.size(); --i >= 0;)
  192702. ((DShowCaptureViewerComp*) viewerComps.getUnchecked(i))->ownerDeleted();
  192703. callback = 0;
  192704. graphBuilder = 0;
  192705. sampleGrabber = 0;
  192706. mediaControl = 0;
  192707. filter = 0;
  192708. captureGraphBuilder = 0;
  192709. smartTee = 0;
  192710. smartTeePreviewOutputPin = 0;
  192711. smartTeeCaptureOutputPin = 0;
  192712. mux = 0;
  192713. fileWriter = 0;
  192714. delete activeImage;
  192715. delete loadingImage;
  192716. }
  192717. void addUser()
  192718. {
  192719. if (ok && activeUsers++ == 0)
  192720. mediaControl->Run();
  192721. }
  192722. void removeUser()
  192723. {
  192724. if (ok && --activeUsers == 0)
  192725. mediaControl->Stop();
  192726. }
  192727. void handleFrame (double /*time*/, BYTE* buffer, long /*bufferSize*/)
  192728. {
  192729. if (recordNextFrameTime)
  192730. {
  192731. const double defaultCameraLatency = 0.1;
  192732. firstRecordedTime = Time::getCurrentTime() - RelativeTime (defaultCameraLatency);
  192733. recordNextFrameTime = false;
  192734. ComSmartPtr <IPin> pin;
  192735. if (getPin (filter, PINDIR_OUTPUT, &pin))
  192736. {
  192737. ComSmartPtr <IAMPushSource> pushSource;
  192738. HRESULT hr = pin->QueryInterface (IID_IAMPushSource, (void**) &pushSource);
  192739. if (pushSource != 0)
  192740. {
  192741. REFERENCE_TIME latency = 0;
  192742. hr = pushSource->GetLatency (&latency);
  192743. firstRecordedTime = firstRecordedTime - RelativeTime ((double) latency);
  192744. }
  192745. }
  192746. }
  192747. imageSwapLock.enter();
  192748. const int lineStride = width * 3;
  192749. const Image::BitmapData destData (*loadingImage, 0, 0, width, height, true);
  192750. for (int i = 0; i < height; ++i)
  192751. memcpy (destData.getLinePointer ((height - 1) - i),
  192752. buffer + lineStride * i,
  192753. lineStride);
  192754. imageNeedsFlipping = true;
  192755. imageSwapLock.exit();
  192756. callListeners (*loadingImage);
  192757. sendChangeMessage (this);
  192758. }
  192759. void drawCurrentImage (Graphics& g, int x, int y, int w, int h)
  192760. {
  192761. if (imageNeedsFlipping)
  192762. {
  192763. imageSwapLock.enter();
  192764. swapVariables (loadingImage, activeImage);
  192765. imageNeedsFlipping = false;
  192766. imageSwapLock.exit();
  192767. }
  192768. RectanglePlacement rp (RectanglePlacement::centred);
  192769. double dx = 0, dy = 0, dw = width, dh = height;
  192770. rp.applyTo (dx, dy, dw, dh, x, y, w, h);
  192771. const int rx = roundToInt (dx), ry = roundToInt (dy);
  192772. const int rw = roundToInt (dw), rh = roundToInt (dh);
  192773. g.saveState();
  192774. g.excludeClipRegion (rx, ry, rw, rh);
  192775. g.fillAll (Colours::black);
  192776. g.restoreState();
  192777. g.drawImage (activeImage, rx, ry, rw, rh, 0, 0, width, height);
  192778. }
  192779. bool createFileCaptureFilter (const File& file)
  192780. {
  192781. removeFileCaptureFilter();
  192782. file.deleteFile();
  192783. mediaControl->Stop();
  192784. firstRecordedTime = Time();
  192785. recordNextFrameTime = true;
  192786. HRESULT hr = mux.CoCreateInstance (CLSID_AviDest, CLSCTX_INPROC_SERVER);
  192787. if (SUCCEEDED (hr))
  192788. {
  192789. hr = graphBuilder->AddFilter (mux, _T("AVI Mux"));
  192790. if (SUCCEEDED (hr))
  192791. {
  192792. fileWriter.CoCreateInstance (CLSID_FileWriter, CLSCTX_INPROC_SERVER);
  192793. if (SUCCEEDED (hr))
  192794. {
  192795. ComSmartPtr <IFileSinkFilter> fileSink;
  192796. hr = fileWriter->QueryInterface (IID_IFileSinkFilter, (void**) &fileSink);
  192797. if (SUCCEEDED (hr))
  192798. {
  192799. AM_MEDIA_TYPE mt;
  192800. zerostruct (mt);
  192801. mt.majortype = MEDIATYPE_Stream;
  192802. mt.subtype = MEDIASUBTYPE_Avi;
  192803. mt.formattype = FORMAT_VideoInfo;
  192804. hr = fileSink->SetFileName (file.getFullPathName(), &mt);
  192805. if (SUCCEEDED (hr))
  192806. {
  192807. hr = graphBuilder->AddFilter (fileWriter, _T("File Writer"));
  192808. if (SUCCEEDED (hr))
  192809. {
  192810. ComSmartPtr <IPin> muxInputPin, muxOutputPin, writerInput;
  192811. if (getPin (mux, PINDIR_INPUT, &muxInputPin)
  192812. && getPin (mux, PINDIR_OUTPUT, &muxOutputPin)
  192813. && getPin (fileWriter, PINDIR_INPUT, &writerInput))
  192814. {
  192815. hr = graphBuilder->Connect (smartTeeCaptureOutputPin, muxInputPin);
  192816. if (SUCCEEDED (hr))
  192817. {
  192818. hr = graphBuilder->Connect (muxOutputPin, writerInput);
  192819. if (SUCCEEDED (hr))
  192820. {
  192821. if (ok && activeUsers > 0)
  192822. mediaControl->Run();
  192823. return true;
  192824. }
  192825. }
  192826. }
  192827. }
  192828. }
  192829. }
  192830. }
  192831. }
  192832. }
  192833. removeFileCaptureFilter();
  192834. if (ok && activeUsers > 0)
  192835. mediaControl->Run();
  192836. return false;
  192837. }
  192838. void removeFileCaptureFilter()
  192839. {
  192840. mediaControl->Stop();
  192841. if (mux != 0)
  192842. {
  192843. graphBuilder->RemoveFilter (mux);
  192844. mux = 0;
  192845. }
  192846. if (fileWriter != 0)
  192847. {
  192848. graphBuilder->RemoveFilter (fileWriter);
  192849. fileWriter = 0;
  192850. }
  192851. if (ok && activeUsers > 0)
  192852. mediaControl->Run();
  192853. }
  192854. void addListener (CameraImageListener* listenerToAdd)
  192855. {
  192856. const ScopedLock sl (listenerLock);
  192857. if (listeners.size() == 0)
  192858. addUser();
  192859. listeners.addIfNotAlreadyThere (listenerToAdd);
  192860. }
  192861. void removeListener (CameraImageListener* listenerToRemove)
  192862. {
  192863. const ScopedLock sl (listenerLock);
  192864. listeners.removeValue (listenerToRemove);
  192865. if (listeners.size() == 0)
  192866. removeUser();
  192867. }
  192868. void callListeners (Image& image)
  192869. {
  192870. const ScopedLock sl (listenerLock);
  192871. for (int i = listeners.size(); --i >= 0;)
  192872. {
  192873. CameraImageListener* l = (CameraImageListener*) listeners[i];
  192874. if (l != 0)
  192875. l->imageReceived (image);
  192876. }
  192877. }
  192878. class DShowCaptureViewerComp : public Component,
  192879. public ChangeListener
  192880. {
  192881. public:
  192882. DShowCaptureViewerComp (DShowCameraDeviceInteral* const owner_)
  192883. : owner (owner_)
  192884. {
  192885. setOpaque (true);
  192886. owner->addChangeListener (this);
  192887. owner->addUser();
  192888. owner->viewerComps.add (this);
  192889. setSize (owner_->width, owner_->height);
  192890. }
  192891. ~DShowCaptureViewerComp()
  192892. {
  192893. if (owner != 0)
  192894. {
  192895. owner->viewerComps.removeValue (this);
  192896. owner->removeUser();
  192897. owner->removeChangeListener (this);
  192898. }
  192899. }
  192900. void ownerDeleted()
  192901. {
  192902. owner = 0;
  192903. }
  192904. void paint (Graphics& g)
  192905. {
  192906. g.setColour (Colours::black);
  192907. g.setImageResamplingQuality (Graphics::lowResamplingQuality);
  192908. if (owner != 0)
  192909. owner->drawCurrentImage (g, 0, 0, getWidth(), getHeight());
  192910. else
  192911. g.fillAll (Colours::black);
  192912. }
  192913. void changeListenerCallback (void*)
  192914. {
  192915. repaint();
  192916. }
  192917. private:
  192918. DShowCameraDeviceInteral* owner;
  192919. };
  192920. bool ok;
  192921. int width, height;
  192922. Time firstRecordedTime;
  192923. VoidArray viewerComps;
  192924. private:
  192925. CameraDevice* const owner;
  192926. ComSmartPtr <ICaptureGraphBuilder2> captureGraphBuilder;
  192927. ComSmartPtr <IBaseFilter> filter;
  192928. ComSmartPtr <IBaseFilter> smartTee;
  192929. ComSmartPtr <IGraphBuilder> graphBuilder;
  192930. ComSmartPtr <ISampleGrabber> sampleGrabber;
  192931. ComSmartPtr <IMediaControl> mediaControl;
  192932. ComSmartPtr <IPin> smartTeePreviewOutputPin;
  192933. ComSmartPtr <IPin> smartTeeCaptureOutputPin;
  192934. ComSmartPtr <IBaseFilter> mux, fileWriter;
  192935. int activeUsers;
  192936. Array <int> widths, heights;
  192937. DWORD graphRegistrationID;
  192938. CriticalSection imageSwapLock;
  192939. bool imageNeedsFlipping;
  192940. Image* loadingImage;
  192941. Image* activeImage;
  192942. bool recordNextFrameTime;
  192943. void getVideoSizes (IAMStreamConfig* const streamConfig)
  192944. {
  192945. widths.clear();
  192946. heights.clear();
  192947. int count = 0, size = 0;
  192948. streamConfig->GetNumberOfCapabilities (&count, &size);
  192949. if (size == sizeof (VIDEO_STREAM_CONFIG_CAPS))
  192950. {
  192951. for (int i = 0; i < count; ++i)
  192952. {
  192953. VIDEO_STREAM_CONFIG_CAPS scc;
  192954. AM_MEDIA_TYPE* config;
  192955. HRESULT hr = streamConfig->GetStreamCaps (i, &config, (BYTE*) &scc);
  192956. if (SUCCEEDED (hr))
  192957. {
  192958. const int w = scc.InputSize.cx;
  192959. const int h = scc.InputSize.cy;
  192960. bool duplicate = false;
  192961. for (int j = widths.size(); --j >= 0;)
  192962. {
  192963. if (w == widths.getUnchecked (j) && h == heights.getUnchecked (j))
  192964. {
  192965. duplicate = true;
  192966. break;
  192967. }
  192968. }
  192969. if (! duplicate)
  192970. {
  192971. DBG ("Camera capture size: " + String (w) + ", " + String (h));
  192972. widths.add (w);
  192973. heights.add (h);
  192974. }
  192975. deleteMediaType (config);
  192976. }
  192977. }
  192978. }
  192979. }
  192980. bool selectVideoSize (IAMStreamConfig* const streamConfig,
  192981. const int minWidth, const int minHeight,
  192982. const int maxWidth, const int maxHeight)
  192983. {
  192984. int count = 0, size = 0;
  192985. streamConfig->GetNumberOfCapabilities (&count, &size);
  192986. if (size == sizeof (VIDEO_STREAM_CONFIG_CAPS))
  192987. {
  192988. for (int i = 0; i < count; ++i)
  192989. {
  192990. VIDEO_STREAM_CONFIG_CAPS scc;
  192991. AM_MEDIA_TYPE* config;
  192992. HRESULT hr = streamConfig->GetStreamCaps (i, &config, (BYTE*) &scc);
  192993. if (SUCCEEDED (hr))
  192994. {
  192995. if (scc.InputSize.cx >= minWidth
  192996. && scc.InputSize.cy >= minHeight
  192997. && scc.InputSize.cx <= maxWidth
  192998. && scc.InputSize.cy <= maxHeight)
  192999. {
  193000. hr = streamConfig->SetFormat (config);
  193001. deleteMediaType (config);
  193002. return SUCCEEDED (hr);
  193003. }
  193004. deleteMediaType (config);
  193005. }
  193006. }
  193007. }
  193008. return false;
  193009. }
  193010. static bool getPin (IBaseFilter* filter, const PIN_DIRECTION wantedDirection, IPin** result, const char* pinName = 0)
  193011. {
  193012. ComSmartPtr <IEnumPins> enumerator;
  193013. ComSmartPtr <IPin> pin;
  193014. filter->EnumPins (&enumerator);
  193015. while (enumerator->Next (1, &pin, 0) == S_OK)
  193016. {
  193017. PIN_DIRECTION dir;
  193018. pin->QueryDirection (&dir);
  193019. if (wantedDirection == dir)
  193020. {
  193021. PIN_INFO info;
  193022. zerostruct (info);
  193023. pin->QueryPinInfo (&info);
  193024. if (pinName == 0 || String (pinName).equalsIgnoreCase (String (info.achName)))
  193025. {
  193026. pin.p->AddRef();
  193027. *result = pin;
  193028. return true;
  193029. }
  193030. }
  193031. }
  193032. return false;
  193033. }
  193034. bool connectFilters (IBaseFilter* const first, IBaseFilter* const second) const
  193035. {
  193036. ComSmartPtr <IPin> in, out;
  193037. return getPin (first, PINDIR_OUTPUT, &out)
  193038. && getPin (second, PINDIR_INPUT, &in)
  193039. && SUCCEEDED (graphBuilder->Connect (out, in));
  193040. }
  193041. bool addGraphToRot()
  193042. {
  193043. ComSmartPtr <IRunningObjectTable> rot;
  193044. if (FAILED (GetRunningObjectTable (0, &rot)))
  193045. return false;
  193046. ComSmartPtr <IMoniker> moniker;
  193047. WCHAR buffer[128];
  193048. HRESULT hr = CreateItemMoniker (_T("!"), buffer, &moniker);
  193049. if (FAILED (hr))
  193050. return false;
  193051. graphRegistrationID = 0;
  193052. return SUCCEEDED (rot->Register (0, graphBuilder, moniker, &graphRegistrationID));
  193053. }
  193054. void removeGraphFromRot()
  193055. {
  193056. ComSmartPtr <IRunningObjectTable> rot;
  193057. if (SUCCEEDED (GetRunningObjectTable (0, &rot)))
  193058. rot->Revoke (graphRegistrationID);
  193059. }
  193060. static void deleteMediaType (AM_MEDIA_TYPE* const pmt)
  193061. {
  193062. if (pmt->cbFormat != 0)
  193063. CoTaskMemFree ((PVOID) pmt->pbFormat);
  193064. if (pmt->pUnk != 0)
  193065. pmt->pUnk->Release();
  193066. CoTaskMemFree (pmt);
  193067. }
  193068. class GrabberCallback : public ISampleGrabberCB
  193069. {
  193070. public:
  193071. GrabberCallback (DShowCameraDeviceInteral& owner_)
  193072. : owner (owner_)
  193073. {
  193074. }
  193075. HRESULT __stdcall QueryInterface (REFIID id, void** result)
  193076. {
  193077. if (id == IID_IUnknown)
  193078. *result = dynamic_cast <IUnknown*> (this);
  193079. else if (id == IID_ISampleGrabberCB)
  193080. *result = dynamic_cast <ISampleGrabberCB*> (this);
  193081. else
  193082. {
  193083. *result = 0;
  193084. return E_NOINTERFACE;
  193085. }
  193086. AddRef();
  193087. return S_OK;
  193088. }
  193089. ULONG __stdcall AddRef() { return ++refCount; }
  193090. ULONG __stdcall Release() { const int r = --refCount; if (r == 0) delete this; return r; }
  193091. STDMETHODIMP SampleCB (double /*SampleTime*/, IMediaSample* /*pSample*/)
  193092. {
  193093. return E_FAIL;
  193094. }
  193095. STDMETHODIMP BufferCB (double time, BYTE* buffer, long bufferSize)
  193096. {
  193097. owner.handleFrame (time, buffer, bufferSize);
  193098. return S_OK;
  193099. }
  193100. private:
  193101. int refCount;
  193102. DShowCameraDeviceInteral& owner;
  193103. GrabberCallback (const GrabberCallback&);
  193104. const GrabberCallback& operator= (const GrabberCallback&);
  193105. };
  193106. ComSmartPtr <GrabberCallback> callback;
  193107. VoidArray listeners;
  193108. CriticalSection listenerLock;
  193109. DShowCameraDeviceInteral (const DShowCameraDeviceInteral&);
  193110. const DShowCameraDeviceInteral& operator= (const DShowCameraDeviceInteral&);
  193111. };
  193112. CameraDevice::CameraDevice (const String& name_, int /*index*/)
  193113. : name (name_)
  193114. {
  193115. isRecording = false;
  193116. }
  193117. CameraDevice::~CameraDevice()
  193118. {
  193119. stopRecording();
  193120. delete (DShowCameraDeviceInteral*) internal;
  193121. internal = 0;
  193122. }
  193123. Component* CameraDevice::createViewerComponent()
  193124. {
  193125. return new DShowCameraDeviceInteral::DShowCaptureViewerComp ((DShowCameraDeviceInteral*) internal);
  193126. }
  193127. const String CameraDevice::getFileExtension()
  193128. {
  193129. return ".avi";
  193130. }
  193131. void CameraDevice::startRecordingToFile (const File& file)
  193132. {
  193133. stopRecording();
  193134. DShowCameraDeviceInteral* const d = (DShowCameraDeviceInteral*) internal;
  193135. d->addUser();
  193136. isRecording = d->createFileCaptureFilter (file);
  193137. }
  193138. const Time CameraDevice::getTimeOfFirstRecordedFrame() const
  193139. {
  193140. DShowCameraDeviceInteral* const d = (DShowCameraDeviceInteral*) internal;
  193141. return d->firstRecordedTime;
  193142. }
  193143. void CameraDevice::stopRecording()
  193144. {
  193145. if (isRecording)
  193146. {
  193147. DShowCameraDeviceInteral* const d = (DShowCameraDeviceInteral*) internal;
  193148. d->removeFileCaptureFilter();
  193149. d->removeUser();
  193150. isRecording = false;
  193151. }
  193152. }
  193153. void CameraDevice::addListener (CameraImageListener* listenerToAdd)
  193154. {
  193155. DShowCameraDeviceInteral* const d = (DShowCameraDeviceInteral*) internal;
  193156. if (listenerToAdd != 0)
  193157. d->addListener (listenerToAdd);
  193158. }
  193159. void CameraDevice::removeListener (CameraImageListener* listenerToRemove)
  193160. {
  193161. DShowCameraDeviceInteral* const d = (DShowCameraDeviceInteral*) internal;
  193162. if (listenerToRemove != 0)
  193163. d->removeListener (listenerToRemove);
  193164. }
  193165. static ComSmartPtr <IBaseFilter> enumerateCameras (StringArray* const names,
  193166. const int deviceIndexToOpen,
  193167. String& name)
  193168. {
  193169. int index = 0;
  193170. ComSmartPtr <IBaseFilter> result;
  193171. ComSmartPtr <ICreateDevEnum> pDevEnum;
  193172. HRESULT hr = pDevEnum.CoCreateInstance (CLSID_SystemDeviceEnum, CLSCTX_INPROC);
  193173. if (SUCCEEDED (hr))
  193174. {
  193175. ComSmartPtr <IEnumMoniker> enumerator;
  193176. hr = pDevEnum->CreateClassEnumerator (CLSID_VideoInputDeviceCategory, &enumerator, 0);
  193177. if (SUCCEEDED (hr) && enumerator != 0)
  193178. {
  193179. ComSmartPtr <IBaseFilter> captureFilter;
  193180. ComSmartPtr <IMoniker> moniker;
  193181. ULONG fetched;
  193182. while (enumerator->Next (1, &moniker, &fetched) == S_OK)
  193183. {
  193184. hr = moniker->BindToObject (0, 0, IID_IBaseFilter, (void**) &captureFilter);
  193185. if (SUCCEEDED (hr))
  193186. {
  193187. ComSmartPtr <IPropertyBag> propertyBag;
  193188. hr = moniker->BindToStorage (0, 0, IID_IPropertyBag, (void**) &propertyBag);
  193189. if (SUCCEEDED (hr))
  193190. {
  193191. VARIANT var;
  193192. var.vt = VT_BSTR;
  193193. hr = propertyBag->Read (_T("FriendlyName"), &var, 0);
  193194. propertyBag = 0;
  193195. if (SUCCEEDED (hr))
  193196. {
  193197. if (names != 0)
  193198. names->add (var.bstrVal);
  193199. if (index == deviceIndexToOpen)
  193200. {
  193201. name = var.bstrVal;
  193202. result = captureFilter;
  193203. captureFilter = 0;
  193204. break;
  193205. }
  193206. ++index;
  193207. }
  193208. moniker = 0;
  193209. }
  193210. captureFilter = 0;
  193211. }
  193212. }
  193213. }
  193214. }
  193215. return result;
  193216. }
  193217. const StringArray CameraDevice::getAvailableDevices()
  193218. {
  193219. StringArray devs;
  193220. String dummy;
  193221. enumerateCameras (&devs, -1, dummy);
  193222. return devs;
  193223. }
  193224. CameraDevice* CameraDevice::openDevice (int index,
  193225. int minWidth, int minHeight,
  193226. int maxWidth, int maxHeight)
  193227. {
  193228. ComSmartPtr <ICaptureGraphBuilder2> captureGraphBuilder;
  193229. HRESULT hr = captureGraphBuilder.CoCreateInstance (CLSID_CaptureGraphBuilder2, CLSCTX_INPROC);
  193230. if (SUCCEEDED (hr))
  193231. {
  193232. String name;
  193233. const ComSmartPtr <IBaseFilter> filter (enumerateCameras (0, index, name));
  193234. if (filter != 0)
  193235. {
  193236. CameraDevice* const cam = new CameraDevice (name, index);
  193237. DShowCameraDeviceInteral* const intern
  193238. = new DShowCameraDeviceInteral (cam, captureGraphBuilder, filter,
  193239. minWidth, minHeight, maxWidth, maxHeight);
  193240. cam->internal = intern;
  193241. if (intern->ok)
  193242. return cam;
  193243. else
  193244. delete cam;
  193245. }
  193246. }
  193247. return 0;
  193248. }
  193249. #endif
  193250. /********* End of inlined file: juce_win32_CameraDevice.cpp *********/
  193251. #endif
  193252. // Auto-link the other win32 libs that are needed by library calls..
  193253. #if (JUCE_AMALGAMATED_TEMPLATE || defined (JUCE_DLL_BUILD)) && JUCE_MSVC && ! DONT_AUTOLINK_TO_WIN32_LIBRARIES
  193254. /********* Start of inlined file: juce_win32_AutoLinkLibraries.h *********/
  193255. // Auto-links to various win32 libs that are needed by library calls..
  193256. #pragma comment(lib, "kernel32.lib")
  193257. #pragma comment(lib, "user32.lib")
  193258. #pragma comment(lib, "shell32.lib")
  193259. #pragma comment(lib, "gdi32.lib")
  193260. #pragma comment(lib, "vfw32.lib")
  193261. #pragma comment(lib, "comdlg32.lib")
  193262. #pragma comment(lib, "winmm.lib")
  193263. #pragma comment(lib, "wininet.lib")
  193264. #pragma comment(lib, "ole32.lib")
  193265. #pragma comment(lib, "advapi32.lib")
  193266. #pragma comment(lib, "ws2_32.lib")
  193267. #pragma comment(lib, "comsupp.lib")
  193268. #pragma comment(lib, "version.lib")
  193269. #if JUCE_OPENGL
  193270. #pragma comment(lib, "OpenGL32.Lib")
  193271. #pragma comment(lib, "GlU32.Lib")
  193272. #endif
  193273. #if JUCE_QUICKTIME
  193274. #pragma comment (lib, "QTMLClient.lib")
  193275. #endif
  193276. #if JUCE_USE_CAMERA
  193277. #pragma comment (lib, "Strmiids.lib")
  193278. #endif
  193279. /********* End of inlined file: juce_win32_AutoLinkLibraries.h *********/
  193280. #endif
  193281. END_JUCE_NAMESPACE
  193282. /********* End of inlined file: juce_win32_NativeCode.cpp *********/
  193283. #endif
  193284. #if JUCE_LINUX
  193285. /********* Start of inlined file: juce_linux_NativeCode.cpp *********/
  193286. BEGIN_JUCE_NAMESPACE
  193287. #if defined (CPU_ISSET) && ! defined (SUPPORT_AFFINITIES)
  193288. #define SUPPORT_AFFINITIES 1
  193289. #endif
  193290. #define JUCE_INCLUDED_FILE 1
  193291. // Now include the actual code files..
  193292. /********* Start of inlined file: juce_posix_SharedCode.h *********/
  193293. CriticalSection::CriticalSection() throw()
  193294. {
  193295. pthread_mutexattr_t atts;
  193296. pthread_mutexattr_init (&atts);
  193297. pthread_mutexattr_settype (&atts, PTHREAD_MUTEX_RECURSIVE);
  193298. pthread_mutex_init (&internal, &atts);
  193299. }
  193300. CriticalSection::~CriticalSection() throw()
  193301. {
  193302. pthread_mutex_destroy (&internal);
  193303. }
  193304. void CriticalSection::enter() const throw()
  193305. {
  193306. pthread_mutex_lock (&internal);
  193307. }
  193308. bool CriticalSection::tryEnter() const throw()
  193309. {
  193310. return pthread_mutex_trylock (&internal) == 0;
  193311. }
  193312. void CriticalSection::exit() const throw()
  193313. {
  193314. pthread_mutex_unlock (&internal);
  193315. }
  193316. struct EventStruct
  193317. {
  193318. pthread_cond_t condition;
  193319. pthread_mutex_t mutex;
  193320. bool triggered;
  193321. };
  193322. WaitableEvent::WaitableEvent() throw()
  193323. {
  193324. EventStruct* const es = new EventStruct();
  193325. es->triggered = false;
  193326. pthread_cond_init (&es->condition, 0);
  193327. pthread_mutex_init (&es->mutex, 0);
  193328. internal = es;
  193329. }
  193330. WaitableEvent::~WaitableEvent() throw()
  193331. {
  193332. EventStruct* const es = (EventStruct*) internal;
  193333. pthread_cond_destroy (&es->condition);
  193334. pthread_mutex_destroy (&es->mutex);
  193335. delete es;
  193336. }
  193337. bool WaitableEvent::wait (const int timeOutMillisecs) const throw()
  193338. {
  193339. EventStruct* const es = (EventStruct*) internal;
  193340. pthread_mutex_lock (&es->mutex);
  193341. if (timeOutMillisecs < 0)
  193342. {
  193343. while (! es->triggered)
  193344. pthread_cond_wait (&es->condition, &es->mutex);
  193345. }
  193346. else
  193347. {
  193348. while (! es->triggered)
  193349. {
  193350. struct timeval t;
  193351. gettimeofday (&t, 0);
  193352. struct timespec time;
  193353. time.tv_sec = t.tv_sec + (timeOutMillisecs / 1000);
  193354. time.tv_nsec = (t.tv_usec + ((timeOutMillisecs % 1000) * 1000)) * 1000;
  193355. if (time.tv_nsec >= 1000000000)
  193356. {
  193357. time.tv_nsec -= 1000000000;
  193358. time.tv_sec++;
  193359. }
  193360. if (pthread_cond_timedwait (&es->condition, &es->mutex, &time) == ETIMEDOUT)
  193361. {
  193362. pthread_mutex_unlock (&es->mutex);
  193363. return false;
  193364. }
  193365. }
  193366. }
  193367. es->triggered = false;
  193368. pthread_mutex_unlock (&es->mutex);
  193369. return true;
  193370. }
  193371. void WaitableEvent::signal() const throw()
  193372. {
  193373. EventStruct* const es = (EventStruct*) internal;
  193374. pthread_mutex_lock (&es->mutex);
  193375. es->triggered = true;
  193376. pthread_cond_broadcast (&es->condition);
  193377. pthread_mutex_unlock (&es->mutex);
  193378. }
  193379. void WaitableEvent::reset() const throw()
  193380. {
  193381. EventStruct* const es = (EventStruct*) internal;
  193382. pthread_mutex_lock (&es->mutex);
  193383. es->triggered = false;
  193384. pthread_mutex_unlock (&es->mutex);
  193385. }
  193386. void JUCE_CALLTYPE Thread::sleep (int millisecs)
  193387. {
  193388. struct timespec time;
  193389. time.tv_sec = millisecs / 1000;
  193390. time.tv_nsec = (millisecs % 1000) * 1000000;
  193391. nanosleep (&time, 0);
  193392. }
  193393. const tchar File::separator = T('/');
  193394. const tchar* File::separatorString = T("/");
  193395. bool juce_copyFile (const String& s, const String& d);
  193396. static bool juce_stat (const String& fileName, struct stat& info)
  193397. {
  193398. return fileName.isNotEmpty()
  193399. && (stat (fileName.toUTF8(), &info) == 0);
  193400. }
  193401. bool juce_isDirectory (const String& fileName)
  193402. {
  193403. struct stat info;
  193404. return fileName.isEmpty()
  193405. || (juce_stat (fileName, info)
  193406. && ((info.st_mode & S_IFDIR) != 0));
  193407. }
  193408. bool juce_fileExists (const String& fileName, const bool dontCountDirectories)
  193409. {
  193410. if (fileName.isEmpty())
  193411. return false;
  193412. const char* const fileNameUTF8 = fileName.toUTF8();
  193413. bool exists = access (fileNameUTF8, F_OK) == 0;
  193414. if (exists && dontCountDirectories)
  193415. {
  193416. struct stat info;
  193417. const int res = stat (fileNameUTF8, &info);
  193418. if (res == 0 && (info.st_mode & S_IFDIR) != 0)
  193419. exists = false;
  193420. }
  193421. return exists;
  193422. }
  193423. int64 juce_getFileSize (const String& fileName)
  193424. {
  193425. struct stat info;
  193426. return juce_stat (fileName, info) ? info.st_size : 0;
  193427. }
  193428. bool juce_canWriteToFile (const String& fileName)
  193429. {
  193430. return access (fileName.toUTF8(), W_OK) == 0;
  193431. }
  193432. bool juce_deleteFile (const String& fileName)
  193433. {
  193434. if (juce_isDirectory (fileName))
  193435. return rmdir ((const char*) fileName.toUTF8()) == 0;
  193436. else
  193437. return remove ((const char*) fileName.toUTF8()) == 0;
  193438. }
  193439. bool juce_moveFile (const String& source, const String& dest)
  193440. {
  193441. if (rename (source.toUTF8(), dest.toUTF8()) == 0)
  193442. return true;
  193443. if (juce_canWriteToFile (source)
  193444. && juce_copyFile (source, dest))
  193445. {
  193446. if (juce_deleteFile (source))
  193447. return true;
  193448. juce_deleteFile (dest);
  193449. }
  193450. return false;
  193451. }
  193452. void juce_createDirectory (const String& fileName)
  193453. {
  193454. mkdir (fileName.toUTF8(), 0777);
  193455. }
  193456. void* juce_fileOpen (const String& fileName, bool forWriting)
  193457. {
  193458. int flags = O_RDONLY;
  193459. if (forWriting)
  193460. {
  193461. if (juce_fileExists (fileName, false))
  193462. {
  193463. const int f = open ((const char*) fileName.toUTF8(), O_RDWR, 00644);
  193464. if (f != -1)
  193465. lseek (f, 0, SEEK_END);
  193466. return (void*) f;
  193467. }
  193468. else
  193469. {
  193470. flags = O_RDWR + O_CREAT;
  193471. }
  193472. }
  193473. return (void*) open ((const char*) fileName.toUTF8(), flags, 00644);
  193474. }
  193475. void juce_fileClose (void* handle)
  193476. {
  193477. if (handle != 0)
  193478. close ((int) (pointer_sized_int) handle);
  193479. }
  193480. int juce_fileRead (void* handle, void* buffer, int size)
  193481. {
  193482. if (handle != 0)
  193483. return (int) read ((int) (pointer_sized_int) handle, buffer, size);
  193484. return 0;
  193485. }
  193486. int juce_fileWrite (void* handle, const void* buffer, int size)
  193487. {
  193488. if (handle != 0)
  193489. return (int) write ((int) (pointer_sized_int) handle, buffer, size);
  193490. return 0;
  193491. }
  193492. int64 juce_fileSetPosition (void* handle, int64 pos)
  193493. {
  193494. if (handle != 0 && lseek ((int) (pointer_sized_int) handle, pos, SEEK_SET) == pos)
  193495. return pos;
  193496. return -1;
  193497. }
  193498. int64 juce_fileGetPosition (void* handle)
  193499. {
  193500. if (handle != 0)
  193501. return lseek ((int) (pointer_sized_int) handle, 0, SEEK_CUR);
  193502. else
  193503. return -1;
  193504. }
  193505. void juce_fileFlush (void* handle)
  193506. {
  193507. if (handle != 0)
  193508. fsync ((int) (pointer_sized_int) handle);
  193509. }
  193510. const File juce_getExecutableFile()
  193511. {
  193512. Dl_info exeInfo;
  193513. dladdr ((const void*) juce_getExecutableFile, &exeInfo);
  193514. return File (exeInfo.dli_fname);
  193515. }
  193516. // if this file doesn't exist, find a parent of it that does..
  193517. static bool doStatFS (const File* file, struct statfs& result)
  193518. {
  193519. File f (*file);
  193520. for (int i = 5; --i >= 0;)
  193521. {
  193522. if (f.exists())
  193523. break;
  193524. f = f.getParentDirectory();
  193525. }
  193526. return statfs (f.getFullPathName().toUTF8(), &result) == 0;
  193527. }
  193528. int64 File::getBytesFreeOnVolume() const
  193529. {
  193530. struct statfs buf;
  193531. if (doStatFS (this, buf))
  193532. return (int64) buf.f_bsize * (int64) buf.f_bavail; // Note: this returns space available to non-super user
  193533. return 0;
  193534. }
  193535. int64 File::getVolumeTotalSize() const
  193536. {
  193537. struct statfs buf;
  193538. if (doStatFS (this, buf))
  193539. return (int64) buf.f_bsize * (int64) buf.f_blocks;
  193540. return 0;
  193541. }
  193542. const String juce_getVolumeLabel (const String& filenameOnVolume,
  193543. int& volumeSerialNumber)
  193544. {
  193545. volumeSerialNumber = 0;
  193546. #if JUCE_MAC
  193547. struct VolAttrBuf
  193548. {
  193549. u_int32_t length;
  193550. attrreference_t mountPointRef;
  193551. char mountPointSpace [MAXPATHLEN];
  193552. } attrBuf;
  193553. struct attrlist attrList;
  193554. zerostruct (attrList);
  193555. attrList.bitmapcount = ATTR_BIT_MAP_COUNT;
  193556. attrList.volattr = ATTR_VOL_INFO | ATTR_VOL_NAME;
  193557. File f (filenameOnVolume);
  193558. for (;;)
  193559. {
  193560. if (getattrlist ((const char*) f.getFullPathName().toUTF8(),
  193561. &attrList, &attrBuf, sizeof(attrBuf), 0) == 0)
  193562. {
  193563. return String::fromUTF8 (((const uint8*) &attrBuf.mountPointRef) + attrBuf.mountPointRef.attr_dataoffset,
  193564. (int) attrBuf.mountPointRef.attr_length);
  193565. }
  193566. const File parent (f.getParentDirectory());
  193567. if (f == parent)
  193568. break;
  193569. f = parent;
  193570. }
  193571. #endif
  193572. return String::empty;
  193573. }
  193574. void juce_runSystemCommand (const String& command)
  193575. {
  193576. int result = system ((const char*) command.toUTF8());
  193577. (void) result;
  193578. }
  193579. const String juce_getOutputFromCommand (const String& command)
  193580. {
  193581. // slight bodge here, as we just pipe the output into a temp file and read it...
  193582. const File tempFile (File::getSpecialLocation (File::tempDirectory)
  193583. .getNonexistentChildFile (String::toHexString (Random::getSystemRandom().nextInt()), ".tmp", false));
  193584. juce_runSystemCommand (command + " > " + tempFile.getFullPathName());
  193585. String result (tempFile.loadFileAsString());
  193586. tempFile.deleteFile();
  193587. return result;
  193588. }
  193589. InterProcessLock::InterProcessLock (const String& name_)
  193590. : internal (0),
  193591. name (name_),
  193592. reentrancyLevel (0)
  193593. {
  193594. #if JUCE_MAC
  193595. // (don't use getSpecialLocation() to avoid the temp folder being different for each app)
  193596. const File temp (File (T("~/Library/Caches/Juce")).getChildFile (name));
  193597. #else
  193598. const File temp (File::getSpecialLocation (File::tempDirectory).getChildFile (name));
  193599. #endif
  193600. temp.create();
  193601. internal = open (temp.getFullPathName().toUTF8(), O_RDWR);
  193602. }
  193603. InterProcessLock::~InterProcessLock()
  193604. {
  193605. while (reentrancyLevel > 0)
  193606. this->exit();
  193607. close (internal);
  193608. }
  193609. bool InterProcessLock::enter (const int timeOutMillisecs)
  193610. {
  193611. if (internal == 0)
  193612. return false;
  193613. if (reentrancyLevel != 0)
  193614. return true;
  193615. const int64 endTime = Time::currentTimeMillis() + timeOutMillisecs;
  193616. struct flock fl;
  193617. zerostruct (fl);
  193618. fl.l_whence = SEEK_SET;
  193619. fl.l_type = F_WRLCK;
  193620. for (;;)
  193621. {
  193622. const int result = fcntl (internal, F_SETLK, &fl);
  193623. if (result >= 0)
  193624. {
  193625. ++reentrancyLevel;
  193626. return true;
  193627. }
  193628. if (errno != EINTR)
  193629. {
  193630. if (timeOutMillisecs == 0
  193631. || (timeOutMillisecs > 0 && Time::currentTimeMillis() >= endTime))
  193632. break;
  193633. Thread::sleep (10);
  193634. }
  193635. }
  193636. return false;
  193637. }
  193638. void InterProcessLock::exit()
  193639. {
  193640. if (reentrancyLevel > 0 && internal != 0)
  193641. {
  193642. --reentrancyLevel;
  193643. struct flock fl;
  193644. zerostruct (fl);
  193645. fl.l_whence = SEEK_SET;
  193646. fl.l_type = F_UNLCK;
  193647. for (;;)
  193648. {
  193649. const int result = fcntl (internal, F_SETLKW, &fl);
  193650. if (result >= 0 || errno != EINTR)
  193651. break;
  193652. }
  193653. }
  193654. }
  193655. /********* End of inlined file: juce_posix_SharedCode.h *********/
  193656. /********* Start of inlined file: juce_linux_Files.cpp *********/
  193657. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  193658. // compiled on its own).
  193659. #if JUCE_INCLUDED_FILE
  193660. #define U_ISOFS_SUPER_MAGIC (short) 0x9660 // linux/iso_fs.h
  193661. #define U_MSDOS_SUPER_MAGIC (short) 0x4d44 // linux/msdos_fs.h
  193662. #define U_NFS_SUPER_MAGIC (short) 0x6969 // linux/nfs_fs.h
  193663. #define U_SMB_SUPER_MAGIC (short) 0x517B // linux/smb_fs.h
  193664. void juce_getFileTimes (const String& fileName,
  193665. int64& modificationTime,
  193666. int64& accessTime,
  193667. int64& creationTime)
  193668. {
  193669. modificationTime = 0;
  193670. accessTime = 0;
  193671. creationTime = 0;
  193672. struct stat info;
  193673. const int res = stat (fileName.toUTF8(), &info);
  193674. if (res == 0)
  193675. {
  193676. modificationTime = (int64) info.st_mtime * 1000;
  193677. accessTime = (int64) info.st_atime * 1000;
  193678. creationTime = (int64) info.st_ctime * 1000;
  193679. }
  193680. }
  193681. bool juce_setFileTimes (const String& fileName,
  193682. int64 modificationTime,
  193683. int64 accessTime,
  193684. int64 creationTime)
  193685. {
  193686. struct utimbuf times;
  193687. times.actime = (time_t) (accessTime / 1000);
  193688. times.modtime = (time_t) (modificationTime / 1000);
  193689. return utime (fileName.toUTF8(), &times) == 0;
  193690. }
  193691. bool juce_setFileReadOnly (const String& fileName, bool isReadOnly)
  193692. {
  193693. struct stat info;
  193694. const int res = stat (fileName.toUTF8(), &info);
  193695. if (res != 0)
  193696. return false;
  193697. info.st_mode &= 0777; // Just permissions
  193698. if( isReadOnly )
  193699. info.st_mode &= ~(S_IWUSR | S_IWGRP | S_IWOTH);
  193700. else
  193701. // Give everybody write permission?
  193702. info.st_mode |= S_IWUSR | S_IWGRP | S_IWOTH;
  193703. return chmod (fileName.toUTF8(), info.st_mode) == 0;
  193704. }
  193705. bool juce_copyFile (const String& s, const String& d)
  193706. {
  193707. const File source (s), dest (d);
  193708. FileInputStream* in = source.createInputStream();
  193709. bool ok = false;
  193710. if (in != 0)
  193711. {
  193712. if (dest.deleteFile())
  193713. {
  193714. FileOutputStream* const out = dest.createOutputStream();
  193715. if (out != 0)
  193716. {
  193717. const int bytesCopied = out->writeFromInputStream (*in, -1);
  193718. delete out;
  193719. ok = (bytesCopied == source.getSize());
  193720. if (! ok)
  193721. dest.deleteFile();
  193722. }
  193723. }
  193724. delete in;
  193725. }
  193726. return ok;
  193727. }
  193728. const StringArray juce_getFileSystemRoots()
  193729. {
  193730. StringArray s;
  193731. s.add (T("/"));
  193732. return s;
  193733. }
  193734. bool File::isOnCDRomDrive() const
  193735. {
  193736. struct statfs buf;
  193737. if (statfs (getFullPathName().toUTF8(), &buf) == 0)
  193738. return (buf.f_type == U_ISOFS_SUPER_MAGIC);
  193739. // Assume not if this fails for some reason
  193740. return false;
  193741. }
  193742. bool File::isOnHardDisk() const
  193743. {
  193744. struct statfs buf;
  193745. if (statfs (getFullPathName().toUTF8(), &buf) == 0)
  193746. {
  193747. switch (buf.f_type)
  193748. {
  193749. case U_ISOFS_SUPER_MAGIC: // CD-ROM
  193750. case U_MSDOS_SUPER_MAGIC: // Probably floppy (but could be mounted FAT filesystem)
  193751. case U_NFS_SUPER_MAGIC: // Network NFS
  193752. case U_SMB_SUPER_MAGIC: // Network Samba
  193753. return false;
  193754. default:
  193755. // Assume anything else is a hard-disk (but note it could
  193756. // be a RAM disk. There isn't a good way of determining
  193757. // this for sure)
  193758. return true;
  193759. }
  193760. }
  193761. // Assume so if this fails for some reason
  193762. return true;
  193763. }
  193764. bool File::isOnRemovableDrive() const
  193765. {
  193766. jassertfalse // xxx not implemented for linux!
  193767. return false;
  193768. }
  193769. bool File::isHidden() const
  193770. {
  193771. return getFileName().startsWithChar (T('.'));
  193772. }
  193773. const char* juce_Argv0 = 0; // referenced from juce_Application.cpp
  193774. const File File::getSpecialLocation (const SpecialLocationType type)
  193775. {
  193776. switch (type)
  193777. {
  193778. case userHomeDirectory:
  193779. {
  193780. const char* homeDir = getenv ("HOME");
  193781. if (homeDir == 0)
  193782. {
  193783. struct passwd* const pw = getpwuid (getuid());
  193784. if (pw != 0)
  193785. homeDir = pw->pw_dir;
  193786. }
  193787. return File (String::fromUTF8 ((const uint8*) homeDir));
  193788. }
  193789. case userDocumentsDirectory:
  193790. case userMusicDirectory:
  193791. case userMoviesDirectory:
  193792. case userApplicationDataDirectory:
  193793. return File ("~");
  193794. case userDesktopDirectory:
  193795. return File ("~/Desktop");
  193796. case commonApplicationDataDirectory:
  193797. return File ("/var");
  193798. case globalApplicationsDirectory:
  193799. return File ("/usr");
  193800. case tempDirectory:
  193801. {
  193802. File tmp ("/var/tmp");
  193803. if (! tmp.isDirectory())
  193804. {
  193805. tmp = T("/tmp");
  193806. if (! tmp.isDirectory())
  193807. tmp = File::getCurrentWorkingDirectory();
  193808. }
  193809. return tmp;
  193810. }
  193811. case invokedExecutableFile:
  193812. if (juce_Argv0 != 0)
  193813. return File (String::fromUTF8 ((const uint8*) juce_Argv0));
  193814. // deliberate fall-through...
  193815. case currentExecutableFile:
  193816. case currentApplicationFile:
  193817. return juce_getExecutableFile();
  193818. default:
  193819. jassertfalse // unknown type?
  193820. break;
  193821. }
  193822. return File::nonexistent;
  193823. }
  193824. const File File::getCurrentWorkingDirectory()
  193825. {
  193826. char buf [2048];
  193827. return File (String::fromUTF8 ((const uint8*) getcwd (buf, sizeof (buf))));
  193828. }
  193829. bool File::setAsCurrentWorkingDirectory() const
  193830. {
  193831. return chdir (getFullPathName().toUTF8()) == 0;
  193832. }
  193833. const String File::getVersion() const
  193834. {
  193835. return String::empty; // xxx not yet implemented
  193836. }
  193837. const File File::getLinkedTarget() const
  193838. {
  193839. char buffer [4096];
  193840. size_t numChars = readlink ((const char*) getFullPathName().toUTF8(),
  193841. buffer, sizeof (buffer));
  193842. if (numChars > 0 && numChars <= sizeof (buffer))
  193843. return File (String::fromUTF8 ((const uint8*) buffer, (int) numChars));
  193844. return *this;
  193845. }
  193846. bool File::moveToTrash() const
  193847. {
  193848. if (! exists())
  193849. return true;
  193850. File trashCan (T("~/.Trash"));
  193851. if (! trashCan.isDirectory())
  193852. trashCan = T("~/.local/share/Trash/files");
  193853. if (! trashCan.isDirectory())
  193854. return false;
  193855. return moveFileTo (trashCan.getNonexistentChildFile (getFileNameWithoutExtension(),
  193856. getFileExtension()));
  193857. }
  193858. struct FindFileStruct
  193859. {
  193860. String parentDir, wildCard;
  193861. DIR* dir;
  193862. bool getNextMatch (String& result, bool* const isDir, bool* const isHidden, int64* const fileSize,
  193863. Time* const modTime, Time* const creationTime, bool* const isReadOnly)
  193864. {
  193865. const char* const wildcardUTF8 = wildCard.toUTF8();
  193866. for (;;)
  193867. {
  193868. struct dirent* const de = readdir (dir);
  193869. if (de == 0)
  193870. break;
  193871. if (fnmatch (wildcardUTF8, de->d_name, FNM_CASEFOLD) == 0)
  193872. {
  193873. result = String::fromUTF8 ((const uint8*) de->d_name);
  193874. const String path (parentDir + result);
  193875. if (isDir != 0 || fileSize != 0)
  193876. {
  193877. struct stat info;
  193878. const bool statOk = (stat (path.toUTF8(), &info) == 0);
  193879. if (isDir != 0)
  193880. *isDir = path.isEmpty() || (statOk && ((info.st_mode & S_IFDIR) != 0));
  193881. if (isHidden != 0)
  193882. *isHidden = (de->d_name[0] == '.');
  193883. if (fileSize != 0)
  193884. *fileSize = statOk ? info.st_size : 0;
  193885. }
  193886. if (modTime != 0 || creationTime != 0)
  193887. {
  193888. int64 m, a, c;
  193889. juce_getFileTimes (path, m, a, c);
  193890. if (modTime != 0)
  193891. *modTime = m;
  193892. if (creationTime != 0)
  193893. *creationTime = c;
  193894. }
  193895. if (isReadOnly != 0)
  193896. *isReadOnly = ! juce_canWriteToFile (path);
  193897. return true;
  193898. }
  193899. }
  193900. return false;
  193901. }
  193902. };
  193903. // returns 0 on failure
  193904. void* juce_findFileStart (const String& directory, const String& wildCard, String& firstResultFile,
  193905. bool* isDir, bool* isHidden, int64* fileSize, Time* modTime,
  193906. Time* creationTime, bool* isReadOnly)
  193907. {
  193908. DIR* d = opendir (directory.toUTF8());
  193909. if (d != 0)
  193910. {
  193911. FindFileStruct* ff = new FindFileStruct();
  193912. ff->parentDir = directory;
  193913. if (!ff->parentDir.endsWithChar (File::separator))
  193914. ff->parentDir += File::separator;
  193915. ff->wildCard = wildCard;
  193916. if (wildCard == T("*.*"))
  193917. ff->wildCard = T("*");
  193918. ff->dir = d;
  193919. if (ff->getNextMatch (firstResultFile, isDir, isHidden, fileSize, modTime, creationTime, isReadOnly))
  193920. {
  193921. return ff;
  193922. }
  193923. else
  193924. {
  193925. firstResultFile = String::empty;
  193926. isDir = false;
  193927. isHidden = false;
  193928. closedir (d);
  193929. delete ff;
  193930. }
  193931. }
  193932. return 0;
  193933. }
  193934. bool juce_findFileNext (void* handle, String& resultFile,
  193935. bool* isDir, bool* isHidden, int64* fileSize, Time* modTime, Time* creationTime, bool* isReadOnly)
  193936. {
  193937. FindFileStruct* const ff = (FindFileStruct*) handle;
  193938. if (ff != 0)
  193939. return ff->getNextMatch (resultFile, isDir, isHidden, fileSize, modTime, creationTime, isReadOnly);
  193940. return false;
  193941. }
  193942. void juce_findFileClose (void* handle)
  193943. {
  193944. FindFileStruct* const ff = (FindFileStruct*) handle;
  193945. if (ff != 0)
  193946. {
  193947. closedir (ff->dir);
  193948. delete ff;
  193949. }
  193950. }
  193951. bool juce_launchFile (const String& fileName,
  193952. const String& parameters)
  193953. {
  193954. String cmdString (fileName.replace (T(" "), T("\\ "),false));
  193955. cmdString << " " << parameters;
  193956. if (URL::isProbablyAWebsiteURL (fileName)
  193957. || cmdString.startsWithIgnoreCase (T("file:"))
  193958. || URL::isProbablyAnEmailAddress (fileName))
  193959. {
  193960. // create a command that tries to launch a bunch of likely browsers
  193961. const char* const browserNames[] = { "xdg-open", "/etc/alternatives/x-www-browser", "firefox", "mozilla", "konqueror", "opera" };
  193962. StringArray cmdLines;
  193963. for (int i = 0; i < numElementsInArray (browserNames); ++i)
  193964. cmdLines.add (String (browserNames[i]) + T(" ") + cmdString.trim().quoted());
  193965. cmdString = cmdLines.joinIntoString (T(" || "));
  193966. }
  193967. const char* const argv[4] = { "/bin/sh", "-c", (const char*) cmdString.toUTF8(), 0 };
  193968. const int cpid = fork();
  193969. if (cpid == 0)
  193970. {
  193971. setsid();
  193972. // Child process
  193973. execve (argv[0], (char**) argv, environ);
  193974. exit (0);
  193975. }
  193976. return cpid >= 0;
  193977. }
  193978. void File::revealToUser() const
  193979. {
  193980. if (isDirectory())
  193981. startAsProcess();
  193982. else if (getParentDirectory().exists())
  193983. getParentDirectory().startAsProcess();
  193984. }
  193985. #endif
  193986. /********* End of inlined file: juce_linux_Files.cpp *********/
  193987. /********* Start of inlined file: juce_posix_NamedPipe.cpp *********/
  193988. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  193989. // compiled on its own).
  193990. #if JUCE_INCLUDED_FILE
  193991. struct NamedPipeInternal
  193992. {
  193993. String pipeInName, pipeOutName;
  193994. int pipeIn, pipeOut;
  193995. bool volatile createdPipe, blocked, stopReadOperation;
  193996. static void signalHandler (int) {}
  193997. };
  193998. void NamedPipe::cancelPendingReads()
  193999. {
  194000. while (internal != 0 && ((NamedPipeInternal*) internal)->blocked)
  194001. {
  194002. NamedPipeInternal* const intern = (NamedPipeInternal*) internal;
  194003. intern->stopReadOperation = true;
  194004. char buffer [1] = { 0 };
  194005. int bytesWritten = (int) ::write (intern->pipeIn, buffer, 1);
  194006. (void) bytesWritten;
  194007. int timeout = 2000;
  194008. while (intern->blocked && --timeout >= 0)
  194009. Thread::sleep (2);
  194010. intern->stopReadOperation = false;
  194011. }
  194012. }
  194013. void NamedPipe::close()
  194014. {
  194015. NamedPipeInternal* const intern = (NamedPipeInternal*) internal;
  194016. if (intern != 0)
  194017. {
  194018. internal = 0;
  194019. if (intern->pipeIn != -1)
  194020. ::close (intern->pipeIn);
  194021. if (intern->pipeOut != -1)
  194022. ::close (intern->pipeOut);
  194023. if (intern->createdPipe)
  194024. {
  194025. unlink (intern->pipeInName);
  194026. unlink (intern->pipeOutName);
  194027. }
  194028. delete intern;
  194029. }
  194030. }
  194031. bool NamedPipe::openInternal (const String& pipeName, const bool createPipe)
  194032. {
  194033. close();
  194034. NamedPipeInternal* const intern = new NamedPipeInternal();
  194035. internal = intern;
  194036. intern->createdPipe = createPipe;
  194037. intern->blocked = false;
  194038. intern->stopReadOperation = false;
  194039. signal (SIGPIPE, NamedPipeInternal::signalHandler);
  194040. siginterrupt (SIGPIPE, 1);
  194041. const String pipePath (T("/tmp/") + File::createLegalFileName (pipeName));
  194042. intern->pipeInName = pipePath + T("_in");
  194043. intern->pipeOutName = pipePath + T("_out");
  194044. intern->pipeIn = -1;
  194045. intern->pipeOut = -1;
  194046. if (createPipe)
  194047. {
  194048. if ((mkfifo (intern->pipeInName, 0666) && errno != EEXIST)
  194049. || (mkfifo (intern->pipeOutName, 0666) && errno != EEXIST))
  194050. {
  194051. delete intern;
  194052. internal = 0;
  194053. return false;
  194054. }
  194055. }
  194056. return true;
  194057. }
  194058. int NamedPipe::read (void* destBuffer, int maxBytesToRead, int /*timeOutMilliseconds*/)
  194059. {
  194060. int bytesRead = -1;
  194061. NamedPipeInternal* const intern = (NamedPipeInternal*) internal;
  194062. if (intern != 0)
  194063. {
  194064. intern->blocked = true;
  194065. if (intern->pipeIn == -1)
  194066. {
  194067. if (intern->createdPipe)
  194068. intern->pipeIn = ::open (intern->pipeInName, O_RDWR);
  194069. else
  194070. intern->pipeIn = ::open (intern->pipeOutName, O_RDWR);
  194071. if (intern->pipeIn == -1)
  194072. {
  194073. intern->blocked = false;
  194074. return -1;
  194075. }
  194076. }
  194077. bytesRead = 0;
  194078. char* p = (char*) destBuffer;
  194079. while (bytesRead < maxBytesToRead)
  194080. {
  194081. const int bytesThisTime = maxBytesToRead - bytesRead;
  194082. const int numRead = (int) ::read (intern->pipeIn, p, bytesThisTime);
  194083. if (numRead <= 0 || intern->stopReadOperation)
  194084. {
  194085. bytesRead = -1;
  194086. break;
  194087. }
  194088. bytesRead += numRead;
  194089. p += bytesRead;
  194090. }
  194091. intern->blocked = false;
  194092. }
  194093. return bytesRead;
  194094. }
  194095. int NamedPipe::write (const void* sourceBuffer, int numBytesToWrite, int timeOutMilliseconds)
  194096. {
  194097. int bytesWritten = -1;
  194098. NamedPipeInternal* const intern = (NamedPipeInternal*) internal;
  194099. if (intern != 0)
  194100. {
  194101. if (intern->pipeOut == -1)
  194102. {
  194103. if (intern->createdPipe)
  194104. intern->pipeOut = ::open (intern->pipeOutName, O_WRONLY);
  194105. else
  194106. intern->pipeOut = ::open (intern->pipeInName, O_WRONLY);
  194107. if (intern->pipeOut == -1)
  194108. {
  194109. return -1;
  194110. }
  194111. }
  194112. const char* p = (const char*) sourceBuffer;
  194113. bytesWritten = 0;
  194114. const uint32 timeOutTime = Time::getMillisecondCounter() + timeOutMilliseconds;
  194115. while (bytesWritten < numBytesToWrite
  194116. && (timeOutMilliseconds < 0 || Time::getMillisecondCounter() < timeOutTime))
  194117. {
  194118. const int bytesThisTime = numBytesToWrite - bytesWritten;
  194119. const int numWritten = (int) ::write (intern->pipeOut, p, bytesThisTime);
  194120. if (numWritten <= 0)
  194121. {
  194122. bytesWritten = -1;
  194123. break;
  194124. }
  194125. bytesWritten += numWritten;
  194126. p += bytesWritten;
  194127. }
  194128. }
  194129. return bytesWritten;
  194130. }
  194131. #endif
  194132. /********* End of inlined file: juce_posix_NamedPipe.cpp *********/
  194133. /********* Start of inlined file: juce_linux_Network.cpp *********/
  194134. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  194135. // compiled on its own).
  194136. #if JUCE_INCLUDED_FILE
  194137. int SystemStats::getMACAddresses (int64* addresses, int maxNum, const bool littleEndian) throw()
  194138. {
  194139. int numResults = 0;
  194140. const int s = socket (AF_INET, SOCK_DGRAM, 0);
  194141. if (s != -1)
  194142. {
  194143. char buf [1024];
  194144. struct ifconf ifc;
  194145. ifc.ifc_len = sizeof (buf);
  194146. ifc.ifc_buf = buf;
  194147. ioctl (s, SIOCGIFCONF, &ifc);
  194148. for (unsigned int i = 0; i < ifc.ifc_len / sizeof (struct ifreq); ++i)
  194149. {
  194150. struct ifreq ifr;
  194151. strcpy (ifr.ifr_name, ifc.ifc_req[i].ifr_name);
  194152. if (ioctl (s, SIOCGIFFLAGS, &ifr) == 0
  194153. && (ifr.ifr_flags & IFF_LOOPBACK) == 0
  194154. && ioctl (s, SIOCGIFHWADDR, &ifr) == 0
  194155. && numResults < maxNum)
  194156. {
  194157. int64 a = 0;
  194158. for (int j = 6; --j >= 0;)
  194159. a = (a << 8) | (uint8) ifr.ifr_hwaddr.sa_data [littleEndian ? j : (5 - j)];
  194160. *addresses++ = a;
  194161. ++numResults;
  194162. }
  194163. }
  194164. close (s);
  194165. }
  194166. return numResults;
  194167. }
  194168. bool PlatformUtilities::launchEmailWithAttachments (const String& targetEmailAddress,
  194169. const String& emailSubject,
  194170. const String& bodyText,
  194171. const StringArray& filesToAttach)
  194172. {
  194173. jassertfalse // xxx todo
  194174. return false;
  194175. }
  194176. class JUCE_HTTPSocketStream
  194177. {
  194178. public:
  194179. JUCE_HTTPSocketStream()
  194180. : readPosition (0),
  194181. socketHandle (-1),
  194182. levelsOfRedirection (0),
  194183. timeoutSeconds (15)
  194184. {
  194185. }
  194186. ~JUCE_HTTPSocketStream()
  194187. {
  194188. closeSocket();
  194189. }
  194190. bool open (const String& url,
  194191. const String& headers,
  194192. const MemoryBlock& postData,
  194193. const bool isPost,
  194194. URL::OpenStreamProgressCallback* callback,
  194195. void* callbackContext,
  194196. int timeOutMs)
  194197. {
  194198. closeSocket();
  194199. uint32 timeOutTime = Time::getMillisecondCounter();
  194200. if (timeOutMs == 0)
  194201. timeOutTime += 60000;
  194202. else if (timeOutMs < 0)
  194203. timeOutTime = 0xffffffff;
  194204. else
  194205. timeOutTime += timeOutMs;
  194206. String hostName, hostPath;
  194207. int hostPort;
  194208. if (! decomposeURL (url, hostName, hostPath, hostPort))
  194209. return false;
  194210. const struct hostent* host = 0;
  194211. int port = 0;
  194212. String proxyName, proxyPath;
  194213. int proxyPort = 0;
  194214. String proxyURL (getenv ("http_proxy"));
  194215. if (proxyURL.startsWithIgnoreCase (T("http://")))
  194216. {
  194217. if (! decomposeURL (proxyURL, proxyName, proxyPath, proxyPort))
  194218. return false;
  194219. host = gethostbyname ((const char*) proxyName.toUTF8());
  194220. port = proxyPort;
  194221. }
  194222. else
  194223. {
  194224. host = gethostbyname ((const char*) hostName.toUTF8());
  194225. port = hostPort;
  194226. }
  194227. if (host == 0)
  194228. return false;
  194229. struct sockaddr_in address;
  194230. zerostruct (address);
  194231. memcpy ((void*) &address.sin_addr, (const void*) host->h_addr, host->h_length);
  194232. address.sin_family = host->h_addrtype;
  194233. address.sin_port = htons (port);
  194234. socketHandle = socket (host->h_addrtype, SOCK_STREAM, 0);
  194235. if (socketHandle == -1)
  194236. return false;
  194237. int receiveBufferSize = 16384;
  194238. setsockopt (socketHandle, SOL_SOCKET, SO_RCVBUF, (char*) &receiveBufferSize, sizeof (receiveBufferSize));
  194239. setsockopt (socketHandle, SOL_SOCKET, SO_KEEPALIVE, 0, 0);
  194240. #if JUCE_MAC
  194241. setsockopt (socketHandle, SOL_SOCKET, SO_NOSIGPIPE, 0, 0);
  194242. #endif
  194243. if (connect (socketHandle, (struct sockaddr*) &address, sizeof (address)) == -1)
  194244. {
  194245. closeSocket();
  194246. return false;
  194247. }
  194248. const MemoryBlock requestHeader (createRequestHeader (hostName, hostPort,
  194249. proxyName, proxyPort,
  194250. hostPath, url,
  194251. headers, postData,
  194252. isPost));
  194253. size_t totalHeaderSent = 0;
  194254. while (totalHeaderSent < requestHeader.getSize())
  194255. {
  194256. if (Time::getMillisecondCounter() > timeOutTime)
  194257. {
  194258. closeSocket();
  194259. return false;
  194260. }
  194261. const int numToSend = jmin (1024, (int) (requestHeader.getSize() - totalHeaderSent));
  194262. if (send (socketHandle,
  194263. ((const char*) requestHeader.getData()) + totalHeaderSent,
  194264. numToSend, 0)
  194265. != numToSend)
  194266. {
  194267. closeSocket();
  194268. return false;
  194269. }
  194270. totalHeaderSent += numToSend;
  194271. if (callback != 0 && ! callback (callbackContext, totalHeaderSent, requestHeader.getSize()))
  194272. {
  194273. closeSocket();
  194274. return false;
  194275. }
  194276. }
  194277. const String responseHeader (readResponse (timeOutTime));
  194278. if (responseHeader.isNotEmpty())
  194279. {
  194280. //DBG (responseHeader);
  194281. StringArray lines;
  194282. lines.addLines (responseHeader);
  194283. // NB - using charToString() here instead of just T(" "), because that was
  194284. // causing a mysterious gcc internal compiler error...
  194285. const int statusCode = responseHeader.fromFirstOccurrenceOf (String::charToString (T(' ')), false, false)
  194286. .substring (0, 3).getIntValue();
  194287. //int contentLength = findHeaderItem (lines, T("Content-Length:")).getIntValue();
  194288. //bool isChunked = findHeaderItem (lines, T("Transfer-Encoding:")).equalsIgnoreCase ("chunked");
  194289. String location (findHeaderItem (lines, T("Location:")));
  194290. if (statusCode >= 300 && statusCode < 400
  194291. && location.isNotEmpty())
  194292. {
  194293. if (! location.startsWithIgnoreCase (T("http://")))
  194294. location = T("http://") + location;
  194295. if (levelsOfRedirection++ < 3)
  194296. return open (location, headers, postData, isPost, callback, callbackContext, timeOutMs);
  194297. }
  194298. else
  194299. {
  194300. levelsOfRedirection = 0;
  194301. return true;
  194302. }
  194303. }
  194304. closeSocket();
  194305. return false;
  194306. }
  194307. int read (void* buffer, int bytesToRead)
  194308. {
  194309. fd_set readbits;
  194310. FD_ZERO (&readbits);
  194311. FD_SET (socketHandle, &readbits);
  194312. struct timeval tv;
  194313. tv.tv_sec = timeoutSeconds;
  194314. tv.tv_usec = 0;
  194315. if (select (socketHandle + 1, &readbits, 0, 0, &tv) <= 0)
  194316. return 0; // (timeout)
  194317. const int bytesRead = jmax (0, (int) recv (socketHandle, buffer, bytesToRead, MSG_WAITALL));
  194318. readPosition += bytesRead;
  194319. return bytesRead;
  194320. }
  194321. int readPosition;
  194322. juce_UseDebuggingNewOperator
  194323. private:
  194324. int socketHandle, levelsOfRedirection;
  194325. const int timeoutSeconds;
  194326. void closeSocket()
  194327. {
  194328. if (socketHandle >= 0)
  194329. close (socketHandle);
  194330. socketHandle = -1;
  194331. }
  194332. const MemoryBlock createRequestHeader (const String& hostName,
  194333. const int hostPort,
  194334. const String& proxyName,
  194335. const int proxyPort,
  194336. const String& hostPath,
  194337. const String& originalURL,
  194338. const String& headers,
  194339. const MemoryBlock& postData,
  194340. const bool isPost)
  194341. {
  194342. String header (isPost ? "POST " : "GET ");
  194343. if (proxyName.isEmpty())
  194344. {
  194345. header << hostPath << " HTTP/1.0\r\nHost: "
  194346. << hostName << ':' << hostPort;
  194347. }
  194348. else
  194349. {
  194350. header << originalURL << " HTTP/1.0\r\nHost: "
  194351. << proxyName << ':' << proxyPort;
  194352. }
  194353. header << "\r\nUser-Agent: JUCE/"
  194354. << JUCE_MAJOR_VERSION << '.' << JUCE_MINOR_VERSION
  194355. << "\r\nConnection: Close\r\nContent-Length: "
  194356. << postData.getSize() << "\r\n"
  194357. << headers << "\r\n";
  194358. MemoryBlock mb;
  194359. mb.append (header.toUTF8(), (int) strlen (header.toUTF8()));
  194360. mb.append (postData.getData(), postData.getSize());
  194361. return mb;
  194362. }
  194363. const String readResponse (const uint32 timeOutTime)
  194364. {
  194365. int bytesRead = 0, numConsecutiveLFs = 0;
  194366. MemoryBlock buffer (1024, true);
  194367. while (numConsecutiveLFs < 2 && bytesRead < 32768
  194368. && Time::getMillisecondCounter() <= timeOutTime)
  194369. {
  194370. fd_set readbits;
  194371. FD_ZERO (&readbits);
  194372. FD_SET (socketHandle, &readbits);
  194373. struct timeval tv;
  194374. tv.tv_sec = timeoutSeconds;
  194375. tv.tv_usec = 0;
  194376. if (select (socketHandle + 1, &readbits, 0, 0, &tv) <= 0)
  194377. return String::empty; // (timeout)
  194378. buffer.ensureSize (bytesRead + 8, true);
  194379. char* const dest = (char*) buffer.getData() + bytesRead;
  194380. if (recv (socketHandle, dest, 1, 0) == -1)
  194381. return String::empty;
  194382. const char lastByte = *dest;
  194383. ++bytesRead;
  194384. if (lastByte == '\n')
  194385. ++numConsecutiveLFs;
  194386. else if (lastByte != '\r')
  194387. numConsecutiveLFs = 0;
  194388. }
  194389. const String header (String::fromUTF8 ((const uint8*) buffer.getData()));
  194390. if (header.startsWithIgnoreCase (T("HTTP/")))
  194391. return header.trimEnd();
  194392. return String::empty;
  194393. }
  194394. static bool decomposeURL (const String& url,
  194395. String& host, String& path, int& port)
  194396. {
  194397. if (! url.startsWithIgnoreCase (T("http://")))
  194398. return false;
  194399. const int nextSlash = url.indexOfChar (7, '/');
  194400. int nextColon = url.indexOfChar (7, ':');
  194401. if (nextColon > nextSlash && nextSlash > 0)
  194402. nextColon = -1;
  194403. if (nextColon >= 0)
  194404. {
  194405. host = url.substring (7, nextColon);
  194406. if (nextSlash >= 0)
  194407. port = url.substring (nextColon + 1, nextSlash).getIntValue();
  194408. else
  194409. port = url.substring (nextColon + 1).getIntValue();
  194410. }
  194411. else
  194412. {
  194413. port = 80;
  194414. if (nextSlash >= 0)
  194415. host = url.substring (7, nextSlash);
  194416. else
  194417. host = url.substring (7);
  194418. }
  194419. if (nextSlash >= 0)
  194420. path = url.substring (nextSlash);
  194421. else
  194422. path = T("/");
  194423. return true;
  194424. }
  194425. static const String findHeaderItem (const StringArray& lines, const String& itemName)
  194426. {
  194427. for (int i = 0; i < lines.size(); ++i)
  194428. if (lines[i].startsWithIgnoreCase (itemName))
  194429. return lines[i].substring (itemName.length()).trim();
  194430. return String::empty;
  194431. }
  194432. };
  194433. bool juce_isOnLine()
  194434. {
  194435. return true;
  194436. }
  194437. void* juce_openInternetFile (const String& url,
  194438. const String& headers,
  194439. const MemoryBlock& postData,
  194440. const bool isPost,
  194441. URL::OpenStreamProgressCallback* callback,
  194442. void* callbackContext,
  194443. int timeOutMs)
  194444. {
  194445. JUCE_HTTPSocketStream* const s = new JUCE_HTTPSocketStream();
  194446. if (s->open (url, headers, postData, isPost,
  194447. callback, callbackContext, timeOutMs))
  194448. return s;
  194449. delete s;
  194450. return 0;
  194451. }
  194452. void juce_closeInternetFile (void* handle)
  194453. {
  194454. JUCE_HTTPSocketStream* const s = (JUCE_HTTPSocketStream*) handle;
  194455. if (s != 0)
  194456. delete s;
  194457. }
  194458. int juce_readFromInternetFile (void* handle, void* buffer, int bytesToRead)
  194459. {
  194460. JUCE_HTTPSocketStream* const s = (JUCE_HTTPSocketStream*) handle;
  194461. if (s != 0)
  194462. return s->read (buffer, bytesToRead);
  194463. return 0;
  194464. }
  194465. int64 juce_getInternetFileContentLength (void* handle)
  194466. {
  194467. JUCE_HTTPSocketStream* const s = (JUCE_HTTPSocketStream*) handle;
  194468. if (s != 0)
  194469. {
  194470. //xxx todo
  194471. jassertfalse
  194472. }
  194473. return -1;
  194474. }
  194475. int juce_seekInInternetFile (void* handle, int newPosition)
  194476. {
  194477. JUCE_HTTPSocketStream* const s = (JUCE_HTTPSocketStream*) handle;
  194478. if (s != 0)
  194479. return s->readPosition;
  194480. return 0;
  194481. }
  194482. #endif
  194483. /********* End of inlined file: juce_linux_Network.cpp *********/
  194484. /********* Start of inlined file: juce_linux_SystemStats.cpp *********/
  194485. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  194486. // compiled on its own).
  194487. #if JUCE_INCLUDED_FILE
  194488. void Logger::outputDebugString (const String& text) throw()
  194489. {
  194490. fputs (text.toUTF8(), stdout);
  194491. fputs ("\n", stdout);
  194492. }
  194493. void Logger::outputDebugPrintf (const tchar* format, ...) throw()
  194494. {
  194495. String text;
  194496. va_list args;
  194497. va_start (args, format);
  194498. text.vprintf(format, args);
  194499. outputDebugString(text);
  194500. }
  194501. SystemStats::OperatingSystemType SystemStats::getOperatingSystemType() throw()
  194502. {
  194503. return Linux;
  194504. }
  194505. const String SystemStats::getOperatingSystemName() throw()
  194506. {
  194507. return T("Linux");
  194508. }
  194509. bool SystemStats::isOperatingSystem64Bit() throw()
  194510. {
  194511. #if JUCE_64BIT
  194512. return true;
  194513. #else
  194514. //xxx not sure how to find this out?..
  194515. return false;
  194516. #endif
  194517. }
  194518. static const String getCpuInfo (const char* key, bool lastOne = false) throw()
  194519. {
  194520. String info;
  194521. char buf [256];
  194522. FILE* f = fopen ("/proc/cpuinfo", "r");
  194523. while (f != 0 && fgets (buf, sizeof(buf), f))
  194524. {
  194525. if (strncmp (buf, key, strlen (key)) == 0)
  194526. {
  194527. char* p = buf;
  194528. while (*p && *p != '\n')
  194529. ++p;
  194530. if (*p != 0)
  194531. *p = 0;
  194532. p = buf;
  194533. while (*p != 0 && *p != ':')
  194534. ++p;
  194535. if (*p != 0 && *(p + 1) != 0)
  194536. info = p + 2;
  194537. if (! lastOne)
  194538. break;
  194539. }
  194540. }
  194541. fclose (f);
  194542. return info;
  194543. }
  194544. bool SystemStats::hasMMX() throw()
  194545. {
  194546. return getCpuInfo ("flags").contains (T("mmx"));
  194547. }
  194548. bool SystemStats::hasSSE() throw()
  194549. {
  194550. return getCpuInfo ("flags").contains (T("sse"));
  194551. }
  194552. bool SystemStats::hasSSE2() throw()
  194553. {
  194554. return getCpuInfo ("flags").contains (T("sse2"));
  194555. }
  194556. bool SystemStats::has3DNow() throw()
  194557. {
  194558. return getCpuInfo ("flags").contains (T("3dnow"));
  194559. }
  194560. const String SystemStats::getCpuVendor() throw()
  194561. {
  194562. return getCpuInfo ("vendor_id");
  194563. }
  194564. int SystemStats::getCpuSpeedInMegaherz() throw()
  194565. {
  194566. const String speed (getCpuInfo ("cpu MHz"));
  194567. return (int) (speed.getFloatValue() + 0.5f);
  194568. }
  194569. int SystemStats::getMemorySizeInMegabytes() throw()
  194570. {
  194571. struct sysinfo sysi;
  194572. if (sysinfo (&sysi) == 0)
  194573. return (sysi.totalram * sysi.mem_unit / (1024 * 1024));
  194574. return 0;
  194575. }
  194576. uint32 juce_millisecondsSinceStartup() throw()
  194577. {
  194578. static unsigned int calibrate = 0;
  194579. static bool calibrated = false;
  194580. timeval t;
  194581. unsigned int ret = 0;
  194582. if (! gettimeofday (&t, 0))
  194583. {
  194584. if (! calibrated)
  194585. {
  194586. struct sysinfo sysi;
  194587. if (sysinfo (&sysi) == 0)
  194588. // Safe to assume system was not brought up earlier than 1970!
  194589. calibrate = t.tv_sec - sysi.uptime;
  194590. calibrated = true;
  194591. }
  194592. ret = 1000 * (t.tv_sec - calibrate) + (t.tv_usec / 1000);
  194593. }
  194594. return ret;
  194595. }
  194596. double Time::getMillisecondCounterHiRes() throw()
  194597. {
  194598. return getHighResolutionTicks() * 0.001;
  194599. }
  194600. int64 Time::getHighResolutionTicks() throw()
  194601. {
  194602. timeval t;
  194603. if (gettimeofday (&t, 0))
  194604. return 0;
  194605. return ((int64) t.tv_sec * (int64) 1000000) + (int64) t.tv_usec;
  194606. }
  194607. int64 Time::getHighResolutionTicksPerSecond() throw()
  194608. {
  194609. // Microseconds
  194610. return 1000000;
  194611. }
  194612. bool Time::setSystemTimeToThisTime() const throw()
  194613. {
  194614. timeval t;
  194615. t.tv_sec = millisSinceEpoch % 1000000;
  194616. t.tv_usec = millisSinceEpoch - t.tv_sec;
  194617. return settimeofday (&t, NULL) ? false : true;
  194618. }
  194619. int SystemStats::getPageSize() throw()
  194620. {
  194621. static int systemPageSize = 0;
  194622. if (systemPageSize == 0)
  194623. systemPageSize = sysconf (_SC_PAGESIZE);
  194624. return systemPageSize;
  194625. }
  194626. int SystemStats::getNumCpus() throw()
  194627. {
  194628. const int lastCpu = getCpuInfo ("processor", true).getIntValue();
  194629. return lastCpu + 1;
  194630. }
  194631. void SystemStats::initialiseStats() throw()
  194632. {
  194633. // Process starts off as root when running suid
  194634. Process::lowerPrivilege();
  194635. String s (SystemStats::getJUCEVersion());
  194636. }
  194637. void PlatformUtilities::fpuReset()
  194638. {
  194639. }
  194640. #endif
  194641. /********* End of inlined file: juce_linux_SystemStats.cpp *********/
  194642. /********* Start of inlined file: juce_linux_Threads.cpp *********/
  194643. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  194644. // compiled on its own).
  194645. #if JUCE_INCLUDED_FILE
  194646. void JUCE_API juce_threadEntryPoint (void*);
  194647. void* threadEntryProc (void* value)
  194648. {
  194649. // New threads start off as root when running suid
  194650. Process::lowerPrivilege();
  194651. juce_threadEntryPoint (value);
  194652. return 0;
  194653. }
  194654. void* juce_createThread (void* userData)
  194655. {
  194656. pthread_t handle = 0;
  194657. if (pthread_create (&handle, 0, threadEntryProc, userData) == 0)
  194658. {
  194659. pthread_detach (handle);
  194660. return (void*)handle;
  194661. }
  194662. return 0;
  194663. }
  194664. void juce_killThread (void* handle)
  194665. {
  194666. if (handle != 0)
  194667. pthread_cancel ((pthread_t)handle);
  194668. }
  194669. void juce_setCurrentThreadName (const String& /*name*/)
  194670. {
  194671. }
  194672. Thread::ThreadID Thread::getCurrentThreadId()
  194673. {
  194674. return (ThreadID) pthread_self();
  194675. }
  194676. // priority 1 to 10 where 5=normal, 1=low. If the handle is 0, sets the
  194677. // priority of the current thread
  194678. bool juce_setThreadPriority (void* handle, int priority)
  194679. {
  194680. struct sched_param param;
  194681. int policy, maxp, minp, pri;
  194682. if (handle == 0)
  194683. handle = (void*) pthread_self();
  194684. if (pthread_getschedparam ((pthread_t) handle, &policy, &param) == 0
  194685. && policy != SCHED_OTHER)
  194686. {
  194687. minp = sched_get_priority_min(policy);
  194688. maxp = sched_get_priority_max(policy);
  194689. pri = ((maxp - minp) / 2) * (priority - 1) / 9;
  194690. if (param.__sched_priority >= (minp + (maxp - minp) / 2))
  194691. // Realtime process priority
  194692. param.__sched_priority = minp + ((maxp - minp) / 2) + pri;
  194693. else
  194694. // High process priority
  194695. param.__sched_priority = minp + pri;
  194696. param.sched_priority = jlimit (1, 127, 1 + (priority * 126) / 11);
  194697. return pthread_setschedparam ((pthread_t) handle, policy, &param) == 0;
  194698. }
  194699. return false;
  194700. }
  194701. void Thread::setCurrentThreadAffinityMask (const uint32 affinityMask)
  194702. {
  194703. #if SUPPORT_AFFINITIES
  194704. cpu_set_t affinity;
  194705. CPU_ZERO (&affinity);
  194706. for (int i = 0; i < 32; ++i)
  194707. if ((affinityMask & (1 << i)) != 0)
  194708. CPU_SET (i, &affinity);
  194709. sched_setaffinity (getpid(), sizeof (cpu_set_t), &affinity);
  194710. sched_yield();
  194711. #else
  194712. /* affinities aren't supported because either the appropriate header files weren't found,
  194713. or the SUPPORT_AFFINITIES macro was turned off in linuxheaders.h
  194714. */
  194715. jassertfalse
  194716. #endif
  194717. }
  194718. void Thread::yield()
  194719. {
  194720. sched_yield();
  194721. }
  194722. // sets the process to 0=low priority, 1=normal, 2=high, 3=realtime
  194723. void Process::setPriority (ProcessPriority prior)
  194724. {
  194725. struct sched_param param;
  194726. int policy, maxp, minp;
  194727. const int p = (int) prior;
  194728. if (p <= 1)
  194729. policy = SCHED_OTHER;
  194730. else
  194731. policy = SCHED_RR;
  194732. minp = sched_get_priority_min (policy);
  194733. maxp = sched_get_priority_max (policy);
  194734. if (p < 2)
  194735. param.__sched_priority = 0;
  194736. else if (p == 2 )
  194737. // Set to middle of lower realtime priority range
  194738. param.__sched_priority = minp + (maxp - minp) / 4;
  194739. else
  194740. // Set to middle of higher realtime priority range
  194741. param.__sched_priority = minp + (3 * (maxp - minp) / 4);
  194742. pthread_setschedparam (pthread_self(), policy, &param);
  194743. }
  194744. void Process::terminate()
  194745. {
  194746. exit (0);
  194747. }
  194748. bool JUCE_PUBLIC_FUNCTION juce_isRunningUnderDebugger()
  194749. {
  194750. static char testResult = 0;
  194751. if (testResult == 0)
  194752. {
  194753. testResult = (char) ptrace (PT_TRACE_ME, 0, 0, 0);
  194754. if (testResult >= 0)
  194755. {
  194756. ptrace (PT_DETACH, 0, (caddr_t) 1, 0);
  194757. testResult = 1;
  194758. }
  194759. }
  194760. return testResult < 0;
  194761. }
  194762. bool JUCE_CALLTYPE Process::isRunningUnderDebugger()
  194763. {
  194764. return juce_isRunningUnderDebugger();
  194765. }
  194766. void Process::raisePrivilege()
  194767. {
  194768. // If running suid root, change effective user
  194769. // to root
  194770. if (geteuid() != 0 && getuid() == 0)
  194771. {
  194772. setreuid (geteuid(), getuid());
  194773. setregid (getegid(), getgid());
  194774. }
  194775. }
  194776. void Process::lowerPrivilege()
  194777. {
  194778. // If runing suid root, change effective user
  194779. // back to real user
  194780. if (geteuid() == 0 && getuid() != 0)
  194781. {
  194782. setreuid (geteuid(), getuid());
  194783. setregid (getegid(), getgid());
  194784. }
  194785. }
  194786. #if ! JUCE_ONLY_BUILD_CORE_LIBRARY
  194787. void* PlatformUtilities::loadDynamicLibrary (const String& name)
  194788. {
  194789. return dlopen ((const char*) name.toUTF8(), RTLD_LOCAL | RTLD_NOW);
  194790. }
  194791. void PlatformUtilities::freeDynamicLibrary (void* handle)
  194792. {
  194793. dlclose(handle);
  194794. }
  194795. void* PlatformUtilities::getProcedureEntryPoint (void* libraryHandle, const String& procedureName)
  194796. {
  194797. return dlsym (libraryHandle, (const char*) procedureName);
  194798. }
  194799. #endif
  194800. #endif
  194801. /********* End of inlined file: juce_linux_Threads.cpp *********/
  194802. #if ! JUCE_ONLY_BUILD_CORE_LIBRARY
  194803. /********* Start of inlined file: juce_linux_Clipboard.cpp *********/
  194804. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  194805. // compiled on its own).
  194806. #if JUCE_INCLUDED_FILE
  194807. #ifdef JUCE_DEBUG
  194808. #define JUCE_DEBUG_XERRORS 1
  194809. #endif
  194810. extern Display* display;
  194811. extern Window juce_messageWindowHandle;
  194812. static String localClipboardContent;
  194813. static Atom atom_UTF8_STRING;
  194814. static Atom atom_CLIPBOARD;
  194815. static Atom atom_TARGETS;
  194816. static void initSelectionAtoms()
  194817. {
  194818. static bool isInitialised = false;
  194819. if (! isInitialised)
  194820. {
  194821. atom_UTF8_STRING = XInternAtom (display, "UTF8_STRING", False);
  194822. atom_CLIPBOARD = XInternAtom (display, "CLIPBOARD", False);
  194823. atom_TARGETS = XInternAtom (display, "TARGETS", False);
  194824. }
  194825. }
  194826. // Read the content of a window property as either a locale-dependent string or an utf8 string
  194827. // works only for strings shorter than 1000000 bytes
  194828. static String juce_readWindowProperty (Window window, Atom prop,
  194829. Atom fmt, // XA_STRING or UTF8_STRING
  194830. bool deleteAfterReading)
  194831. {
  194832. String returnData;
  194833. uint8 *clipData;
  194834. Atom actualType;
  194835. int actualFormat;
  194836. unsigned long numItems, bytesLeft;
  194837. if (XGetWindowProperty (display, window, prop,
  194838. 0L /* offset */, 1000000 /* length (max) */, False,
  194839. AnyPropertyType /* format */,
  194840. &actualType, &actualFormat, &numItems, &bytesLeft,
  194841. &clipData) == Success)
  194842. {
  194843. if (actualType == atom_UTF8_STRING && actualFormat == 8)
  194844. {
  194845. returnData = String::fromUTF8 (clipData, numItems);
  194846. }
  194847. else if (actualType == XA_STRING && actualFormat == 8)
  194848. {
  194849. returnData = String ((const char*) clipData, numItems);
  194850. }
  194851. if (clipData != 0)
  194852. XFree (clipData);
  194853. jassert (bytesLeft == 0 || numItems == 1000000);
  194854. }
  194855. if (deleteAfterReading)
  194856. XDeleteProperty (display, window, prop);
  194857. return returnData;
  194858. }
  194859. // Send a SelectionRequest to the window owning the selection and waits for its answer (with a timeout) */
  194860. static bool juce_requestSelectionContent (String &selection_content, Atom selection, Atom requested_format)
  194861. {
  194862. Atom property_name = XInternAtom (display, "JUCE_SEL", false);
  194863. // The selection owner will be asked to set the JUCE_SEL property on the
  194864. // juce_messageWindowHandle with the selection content
  194865. XConvertSelection (display, selection, requested_format, property_name,
  194866. juce_messageWindowHandle, CurrentTime);
  194867. int timeoutMs = 200; // will wait at most for 200 ms
  194868. do
  194869. {
  194870. XEvent event;
  194871. if (XCheckTypedWindowEvent (display, juce_messageWindowHandle, SelectionNotify, &event))
  194872. {
  194873. if (event.xselection.property == property_name)
  194874. {
  194875. jassert (event.xselection.requestor == juce_messageWindowHandle);
  194876. selection_content = juce_readWindowProperty (event.xselection.requestor,
  194877. event.xselection.property,
  194878. requested_format, true);
  194879. return true;
  194880. }
  194881. else
  194882. {
  194883. return false; // the format we asked for was denied.. (event.xselection.property == None)
  194884. }
  194885. }
  194886. // not very elegant.. we could do a select() or something like that...
  194887. // however clipboard content requesting is inherently slow on x11, it
  194888. // often takes 50ms or more so...
  194889. Thread::sleep (4);
  194890. timeoutMs -= 4;
  194891. }
  194892. while (timeoutMs > 0);
  194893. DBG("timeout for juce_requestSelectionContent");
  194894. return false;
  194895. }
  194896. // Called from the event loop in juce_linux_Messaging in response to SelectionRequest events
  194897. void juce_handleSelectionRequest (XSelectionRequestEvent &evt)
  194898. {
  194899. initSelectionAtoms();
  194900. // the selection content is sent to the target window as a window property
  194901. XSelectionEvent reply;
  194902. reply.type = SelectionNotify;
  194903. reply.display = evt.display;
  194904. reply.requestor = evt.requestor;
  194905. reply.selection = evt.selection;
  194906. reply.target = evt.target;
  194907. reply.property = None; // == "fail"
  194908. reply.time = evt.time;
  194909. HeapBlock <char> data;
  194910. int propertyFormat = 0, numDataItems = 0;
  194911. if (evt.selection == XA_PRIMARY || evt.selection == atom_CLIPBOARD)
  194912. {
  194913. if (evt.target == XA_STRING)
  194914. {
  194915. // format data according to system locale
  194916. numDataItems = localClipboardContent.length();
  194917. data.calloc (numDataItems + 2);
  194918. localClipboardContent.copyToBuffer ((char*) data, numDataItems + 1);
  194919. propertyFormat = 8; // bits/item
  194920. }
  194921. else if (evt.target == atom_UTF8_STRING)
  194922. {
  194923. // translate to utf8
  194924. numDataItems = localClipboardContent.copyToUTF8 (0);
  194925. data.calloc (numDataItems + 2);
  194926. localClipboardContent.copyToUTF8 (data, numDataItems + 1);
  194927. propertyFormat = 8; // bits/item
  194928. }
  194929. else if (evt.target == atom_TARGETS)
  194930. {
  194931. // another application wants to know what we are able to send
  194932. numDataItems = 2;
  194933. propertyFormat = 32; // atoms are 32-bit
  194934. data.calloc (numDataItems * 4);
  194935. ((Atom*) data)[0] = atom_UTF8_STRING;
  194936. ((Atom*) data)[1] = XA_STRING;
  194937. }
  194938. }
  194939. else
  194940. {
  194941. DBG ("requested unsupported clipboard");
  194942. }
  194943. if (data != 0)
  194944. {
  194945. const int maxReasonableSelectionSize = 1000000;
  194946. // for very big chunks of data, we should use the "INCR" protocol , which is a pain in the *ss
  194947. if (evt.property != None && numDataItems < maxReasonableSelectionSize)
  194948. {
  194949. XChangeProperty (evt.display, evt.requestor,
  194950. evt.property, evt.target,
  194951. propertyFormat /* 8 or 32 */, PropModeReplace,
  194952. (const unsigned char*) data, numDataItems);
  194953. reply.property = evt.property; // " == success"
  194954. }
  194955. }
  194956. XSendEvent (evt.display, evt.requestor, 0, NoEventMask, (XEvent*) &reply);
  194957. }
  194958. void SystemClipboard::copyTextToClipboard (const String& clipText) throw()
  194959. {
  194960. initSelectionAtoms();
  194961. localClipboardContent = clipText;
  194962. XSetSelectionOwner (display, XA_PRIMARY, juce_messageWindowHandle, CurrentTime);
  194963. XSetSelectionOwner (display, atom_CLIPBOARD, juce_messageWindowHandle, CurrentTime);
  194964. }
  194965. const String SystemClipboard::getTextFromClipboard() throw()
  194966. {
  194967. initSelectionAtoms();
  194968. String content;
  194969. Atom selection = XA_PRIMARY;
  194970. Window selectionOwner = None;
  194971. if ((selectionOwner = XGetSelectionOwner (display, selection)) == None)
  194972. {
  194973. selection = atom_CLIPBOARD;
  194974. selectionOwner = XGetSelectionOwner (display, selection);
  194975. }
  194976. if (selectionOwner != None)
  194977. {
  194978. if (selectionOwner == juce_messageWindowHandle)
  194979. {
  194980. content = localClipboardContent;
  194981. }
  194982. else
  194983. {
  194984. // first try: we want an utf8 string
  194985. bool ok = juce_requestSelectionContent (content, selection, atom_UTF8_STRING);
  194986. if (! ok)
  194987. {
  194988. // second chance, ask for a good old locale-dependent string ..
  194989. ok = juce_requestSelectionContent (content, selection, XA_STRING);
  194990. }
  194991. }
  194992. }
  194993. return content;
  194994. }
  194995. #endif
  194996. /********* End of inlined file: juce_linux_Clipboard.cpp *********/
  194997. /********* Start of inlined file: juce_linux_Messaging.cpp *********/
  194998. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  194999. // compiled on its own).
  195000. #if JUCE_INCLUDED_FILE
  195001. #ifdef JUCE_DEBUG
  195002. #define JUCE_DEBUG_XERRORS 1
  195003. #endif
  195004. Display* display = 0; // This is also referenced from WindowDriver.cpp
  195005. Window juce_messageWindowHandle = None;
  195006. #define SpecialAtom "JUCESpecialAtom"
  195007. #define BroadcastAtom "JUCEBroadcastAtom"
  195008. #define SpecialCallbackAtom "JUCESpecialCallbackAtom"
  195009. static Atom specialId;
  195010. static Atom broadcastId;
  195011. static Atom specialCallbackId;
  195012. // This is referenced from Windowing.cpp
  195013. XContext improbableNumber;
  195014. // Defined in Windowing.cpp
  195015. extern void juce_windowMessageReceive (XEvent* event);
  195016. // Defined in Clipboard.cpp
  195017. extern void juce_handleSelectionRequest (XSelectionRequestEvent &evt);
  195018. ScopedXLock::ScopedXLock() { XLockDisplay (display); }
  195019. ScopedXLock::~ScopedXLock() { XUnlockDisplay (display); }
  195020. class InternalMessageQueue
  195021. {
  195022. public:
  195023. InternalMessageQueue()
  195024. : bytesInSocket (0)
  195025. {
  195026. int ret = ::socketpair (AF_LOCAL, SOCK_STREAM, 0, fd);
  195027. (void) ret; jassert (ret == 0);
  195028. setNonBlocking (fd[0]);
  195029. setNonBlocking (fd[1]);
  195030. }
  195031. ~InternalMessageQueue()
  195032. {
  195033. close (fd[0]);
  195034. close (fd[1]);
  195035. }
  195036. void postMessage (Message* msg)
  195037. {
  195038. const int maxBytesInSocketQueue = 128;
  195039. ScopedLock sl (lock);
  195040. queue.add (msg);
  195041. if (bytesInSocket < maxBytesInSocketQueue)
  195042. {
  195043. ++bytesInSocket;
  195044. ScopedUnlock ul (lock);
  195045. const unsigned char x = 0xff;
  195046. size_t bytesWritten = write (fd[0], &x, 1);
  195047. (void) bytesWritten;
  195048. }
  195049. }
  195050. bool isEmpty() const
  195051. {
  195052. ScopedLock sl (lock);
  195053. return queue.size() == 0;
  195054. }
  195055. Message* popNextMessage()
  195056. {
  195057. ScopedLock sl (lock);
  195058. if (bytesInSocket > 0)
  195059. {
  195060. --bytesInSocket;
  195061. ScopedUnlock ul (lock);
  195062. unsigned char x;
  195063. size_t numBytes = read (fd[1], &x, 1);
  195064. (void) numBytes;
  195065. }
  195066. Message* m = queue[0];
  195067. queue.remove (0, false /* deleteObject */);
  195068. return m;
  195069. }
  195070. int getWaitHandle() const { return fd[1]; }
  195071. private:
  195072. CriticalSection lock;
  195073. OwnedArray <Message> queue;
  195074. int fd[2];
  195075. int bytesInSocket;
  195076. static bool setNonBlocking (int handle)
  195077. {
  195078. int socketFlags = fcntl (handle, F_GETFL, 0);
  195079. if (socketFlags == -1)
  195080. return false;
  195081. socketFlags |= O_NONBLOCK;
  195082. return fcntl (handle, F_SETFL, socketFlags) == 0;
  195083. }
  195084. };
  195085. struct MessageThreadFuncCall
  195086. {
  195087. enum { uniqueID = 0x73774623 };
  195088. MessageCallbackFunction* func;
  195089. void* parameter;
  195090. void* result;
  195091. CriticalSection lock;
  195092. WaitableEvent event;
  195093. };
  195094. static InternalMessageQueue* juce_internalMessageQueue = 0;
  195095. // error handling in X11
  195096. static bool errorOccurred = false;
  195097. static bool keyboardBreakOccurred = false;
  195098. static XErrorHandler oldErrorHandler = (XErrorHandler) 0;
  195099. static XIOErrorHandler oldIOErrorHandler = (XIOErrorHandler) 0;
  195100. // Usually happens when client-server connection is broken
  195101. static int ioErrorHandler (Display* display)
  195102. {
  195103. DBG (T("ERROR: connection to X server broken.. terminating."));
  195104. errorOccurred = true;
  195105. if (JUCEApplication::getInstance() != 0)
  195106. Process::terminate();
  195107. return 0;
  195108. }
  195109. // A protocol error has occurred
  195110. static int errorHandler (Display* display, XErrorEvent* event)
  195111. {
  195112. #ifdef JUCE_DEBUG_XERRORS
  195113. char errorStr[64] = { 0 };
  195114. char requestStr[64] = { 0 };
  195115. XGetErrorText (display, event->error_code, errorStr, 64);
  195116. XGetErrorDatabaseText (display,
  195117. "XRequest",
  195118. (const char*) String (event->request_code),
  195119. "Unknown",
  195120. requestStr,
  195121. 64);
  195122. DBG (T("ERROR: X returned ") + String (errorStr) + T(" for operation ") + String (requestStr));
  195123. #endif
  195124. return 0;
  195125. }
  195126. // Breakin from keyboard
  195127. static void signalHandler (int sig)
  195128. {
  195129. if (sig == SIGINT)
  195130. {
  195131. keyboardBreakOccurred = true;
  195132. return;
  195133. }
  195134. static bool reentrant = false;
  195135. if (! reentrant)
  195136. {
  195137. reentrant = true;
  195138. // Illegal instruction
  195139. fflush (stdout);
  195140. Logger::outputDebugString ("ERROR: Program executed illegal instruction.. terminating");
  195141. errorOccurred = true;
  195142. if (JUCEApplication::getInstance() != 0)
  195143. Process::terminate();
  195144. }
  195145. else
  195146. {
  195147. if (JUCEApplication::getInstance() != 0)
  195148. exit(0);
  195149. }
  195150. }
  195151. void MessageManager::doPlatformSpecificInitialisation()
  195152. {
  195153. // Initialise xlib for multiple thread support
  195154. static bool initThreadCalled = false;
  195155. if (! initThreadCalled)
  195156. {
  195157. if (! XInitThreads())
  195158. {
  195159. // This is fatal! Print error and closedown
  195160. Logger::outputDebugString ("Failed to initialise xlib thread support.");
  195161. if (JUCEApplication::getInstance() != 0)
  195162. Process::terminate();
  195163. return;
  195164. }
  195165. initThreadCalled = true;
  195166. }
  195167. // This is called if the client/server connection is broken
  195168. oldIOErrorHandler = XSetIOErrorHandler (ioErrorHandler);
  195169. // This is called if a protocol error occurs
  195170. oldErrorHandler = XSetErrorHandler (errorHandler);
  195171. // Install signal handler for break-in
  195172. struct sigaction saction;
  195173. sigset_t maskSet;
  195174. sigemptyset (&maskSet);
  195175. saction.sa_handler = signalHandler;
  195176. saction.sa_mask = maskSet;
  195177. saction.sa_flags = 0;
  195178. sigaction (SIGINT, &saction, NULL);
  195179. #ifndef _DEBUG
  195180. // Setup signal handlers for various fatal errors
  195181. sigaction (SIGILL, &saction, NULL);
  195182. sigaction (SIGBUS, &saction, NULL);
  195183. sigaction (SIGFPE, &saction, NULL);
  195184. sigaction (SIGSEGV, &saction, NULL);
  195185. sigaction (SIGSYS, &saction, NULL);
  195186. #endif
  195187. // Create the internal message queue
  195188. juce_internalMessageQueue = new InternalMessageQueue();
  195189. // Try to connect to a display
  195190. String displayName (getenv ("DISPLAY"));
  195191. if (displayName.isEmpty())
  195192. displayName = T(":0.0");
  195193. display = XOpenDisplay (displayName);
  195194. if (display == 0)
  195195. {
  195196. // This is not fatal! we can run headless.
  195197. return;
  195198. }
  195199. // Get defaults for various properties
  195200. int screen = DefaultScreen (display);
  195201. Window root = RootWindow (display, screen);
  195202. Visual* visual = DefaultVisual (display, screen);
  195203. // Create atoms for our ClientMessages (these cannot be deleted)
  195204. specialId = XInternAtom (display, SpecialAtom, false);
  195205. broadcastId = XInternAtom (display, BroadcastAtom, false);
  195206. specialCallbackId = XInternAtom (display, SpecialCallbackAtom, false);
  195207. // Create a context to store user data associated with Windows we
  195208. // create in WindowDriver
  195209. improbableNumber = XUniqueContext();
  195210. // We're only interested in client messages for this window
  195211. // which are always sent
  195212. XSetWindowAttributes swa;
  195213. swa.event_mask = NoEventMask;
  195214. // Create our message window (this will never be mapped)
  195215. juce_messageWindowHandle = XCreateWindow (display, root,
  195216. 0, 0, 1, 1, 0, 0, InputOnly,
  195217. visual, CWEventMask, &swa);
  195218. }
  195219. void MessageManager::doPlatformSpecificShutdown()
  195220. {
  195221. deleteAndZero (juce_internalMessageQueue);
  195222. if (display != 0 && ! errorOccurred)
  195223. {
  195224. XDestroyWindow (display, juce_messageWindowHandle);
  195225. XCloseDisplay (display);
  195226. // reset pointers
  195227. juce_messageWindowHandle = 0;
  195228. display = 0;
  195229. // Restore original error handlers
  195230. XSetIOErrorHandler (oldIOErrorHandler);
  195231. oldIOErrorHandler = 0;
  195232. XSetErrorHandler (oldErrorHandler);
  195233. oldErrorHandler = 0;
  195234. }
  195235. }
  195236. bool juce_postMessageToSystemQueue (void* message)
  195237. {
  195238. if (errorOccurred)
  195239. return false;
  195240. juce_internalMessageQueue->postMessage ((Message*) message);
  195241. return true;
  195242. }
  195243. void MessageManager::broadcastMessage (const String& value) throw()
  195244. {
  195245. }
  195246. void* MessageManager::callFunctionOnMessageThread (MessageCallbackFunction* func,
  195247. void* parameter)
  195248. {
  195249. if (errorOccurred)
  195250. return 0;
  195251. if (! isThisTheMessageThread())
  195252. {
  195253. MessageThreadFuncCall messageCallContext;
  195254. messageCallContext.func = func;
  195255. messageCallContext.parameter = parameter;
  195256. juce_internalMessageQueue->postMessage (new Message (MessageThreadFuncCall::uniqueID,
  195257. 0, 0, &messageCallContext));
  195258. // Wait for it to complete before continuing
  195259. messageCallContext.event.wait();
  195260. return messageCallContext.result;
  195261. }
  195262. else
  195263. {
  195264. // Just call the function directly
  195265. return func (parameter);
  195266. }
  195267. }
  195268. // Wait for an event (either XEvent, or an internal Message)
  195269. static bool juce_sleepUntilEvent (const int timeoutMs)
  195270. {
  195271. if (! juce_internalMessageQueue->isEmpty())
  195272. return true;
  195273. if (display != 0)
  195274. {
  195275. ScopedXLock xlock;
  195276. if (XPending (display))
  195277. return true;
  195278. }
  195279. struct timeval tv;
  195280. tv.tv_sec = 0;
  195281. tv.tv_usec = timeoutMs * 1000;
  195282. int fd0 = juce_internalMessageQueue->getWaitHandle();
  195283. int fdmax = fd0;
  195284. fd_set readset;
  195285. FD_ZERO (&readset);
  195286. FD_SET (fd0, &readset);
  195287. if (display != 0)
  195288. {
  195289. ScopedXLock xlock;
  195290. int fd1 = XConnectionNumber (display);
  195291. FD_SET (fd1, &readset);
  195292. fdmax = jmax (fd0, fd1);
  195293. }
  195294. const int ret = select (fdmax + 1, &readset, 0, 0, &tv);
  195295. return (ret > 0); // ret <= 0 if error or timeout
  195296. }
  195297. // Handle next XEvent (if any)
  195298. static bool juce_dispatchNextXEvent()
  195299. {
  195300. if (display == 0)
  195301. return false;
  195302. XEvent evt;
  195303. {
  195304. ScopedXLock xlock;
  195305. if (! XPending (display))
  195306. return false;
  195307. XNextEvent (display, &evt);
  195308. }
  195309. if (evt.type == SelectionRequest && evt.xany.window == juce_messageWindowHandle)
  195310. {
  195311. juce_handleSelectionRequest (evt.xselectionrequest);
  195312. }
  195313. else if (evt.xany.window != juce_messageWindowHandle)
  195314. {
  195315. juce_windowMessageReceive (&evt);
  195316. }
  195317. return true;
  195318. }
  195319. // Handle next internal Message (if any)
  195320. static bool juce_dispatchNextInternalMessage()
  195321. {
  195322. ScopedPointer <Message> msg (juce_internalMessageQueue->popNextMessage());
  195323. if (msg == 0)
  195324. return false;
  195325. if (msg->intParameter1 == MessageThreadFuncCall::uniqueID)
  195326. {
  195327. // Handle callback message
  195328. MessageThreadFuncCall* const call = (MessageThreadFuncCall*) msg->pointerParameter;
  195329. call->result = (*(call->func)) (call->parameter);
  195330. call->event.signal();
  195331. }
  195332. else
  195333. {
  195334. // Handle "normal" messages
  195335. MessageManager::getInstance()->deliverMessage (msg.release());
  195336. }
  195337. return true;
  195338. }
  195339. // this function expects that it will NEVER be called simultaneously for two concurrent threads
  195340. bool juce_dispatchNextMessageOnSystemQueue (bool returnIfNoPendingMessages)
  195341. {
  195342. for (;;)
  195343. {
  195344. if (errorOccurred)
  195345. break;
  195346. if (keyboardBreakOccurred)
  195347. {
  195348. errorOccurred = true;
  195349. if (JUCEApplication::getInstance() != 0)
  195350. Process::terminate();
  195351. break;
  195352. }
  195353. static int totalEventCount = 0;
  195354. ++totalEventCount;
  195355. // The purpose here is to give either priority to XEvents or
  195356. // to internal messages This is necessary to keep a "good"
  195357. // behaviour when the cpu is overloaded
  195358. if (totalEventCount & 1)
  195359. {
  195360. if (juce_dispatchNextXEvent() || juce_dispatchNextInternalMessage())
  195361. return true;
  195362. }
  195363. else
  195364. {
  195365. if (juce_dispatchNextInternalMessage() || juce_dispatchNextXEvent())
  195366. return true;
  195367. }
  195368. if (returnIfNoPendingMessages) // early exit
  195369. break;
  195370. // the timeout is to be on the safe side, but it does not seem to be useful
  195371. juce_sleepUntilEvent (2000);
  195372. }
  195373. return false;
  195374. }
  195375. #endif
  195376. /********* End of inlined file: juce_linux_Messaging.cpp *********/
  195377. /********* Start of inlined file: juce_linux_Fonts.cpp *********/
  195378. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  195379. // compiled on its own).
  195380. #if JUCE_INCLUDED_FILE
  195381. class FreeTypeFontFace
  195382. {
  195383. public:
  195384. enum FontStyle
  195385. {
  195386. Plain = 0,
  195387. Bold = 1,
  195388. Italic = 2
  195389. };
  195390. struct FontNameIndex
  195391. {
  195392. String fileName;
  195393. int faceIndex;
  195394. };
  195395. FreeTypeFontFace (const String& familyName) throw()
  195396. : hasSerif (false),
  195397. monospaced (false)
  195398. {
  195399. family = familyName;
  195400. }
  195401. void setFileName (const String& name, const int faceIndex, FontStyle style) throw()
  195402. {
  195403. if (names [(int) style].fileName.isEmpty())
  195404. {
  195405. names [(int) style].fileName = name;
  195406. names [(int) style].faceIndex = faceIndex;
  195407. }
  195408. }
  195409. const String& getFamilyName() const throw() { return family; }
  195410. const String& getFileName (const int style, int& faceIndex) const throw()
  195411. {
  195412. faceIndex = names[style].faceIndex;
  195413. return names[style].fileName;
  195414. }
  195415. void setMonospaced (bool mono) throw() { monospaced = mono; }
  195416. bool getMonospaced() const throw() { return monospaced; }
  195417. void setSerif (const bool serif) throw() { hasSerif = serif; }
  195418. bool getSerif() const throw() { return hasSerif; }
  195419. private:
  195420. String family;
  195421. FontNameIndex names[4];
  195422. bool hasSerif, monospaced;
  195423. };
  195424. class FreeTypeInterface : public DeletedAtShutdown
  195425. {
  195426. public:
  195427. FreeTypeInterface() throw()
  195428. : lastFace (0),
  195429. lastBold (false),
  195430. lastItalic (false)
  195431. {
  195432. if (FT_Init_FreeType (&ftLib) != 0)
  195433. {
  195434. ftLib = 0;
  195435. DBG (T("Failed to initialize FreeType"));
  195436. }
  195437. StringArray fontDirs;
  195438. fontDirs.addTokens (String (getenv ("JUCE_FONT_PATH")), T(";,"), 0);
  195439. fontDirs.removeEmptyStrings (true);
  195440. if (fontDirs.size() == 0)
  195441. {
  195442. XmlDocument fontsConfig (File ("/etc/fonts/fonts.conf"));
  195443. XmlElement* const fontsInfo = fontsConfig.getDocumentElement();
  195444. if (fontsInfo != 0)
  195445. {
  195446. forEachXmlChildElementWithTagName (*fontsInfo, e, T("dir"))
  195447. {
  195448. fontDirs.add (e->getAllSubText().trim());
  195449. }
  195450. delete fontsInfo;
  195451. }
  195452. }
  195453. if (fontDirs.size() == 0)
  195454. fontDirs.add ("/usr/X11R6/lib/X11/fonts");
  195455. for (int i = 0; i < fontDirs.size(); ++i)
  195456. enumerateFaces (fontDirs[i]);
  195457. }
  195458. ~FreeTypeInterface() throw()
  195459. {
  195460. if (lastFace != 0)
  195461. FT_Done_Face (lastFace);
  195462. if (ftLib != 0)
  195463. FT_Done_FreeType (ftLib);
  195464. clearSingletonInstance();
  195465. }
  195466. FreeTypeFontFace* findOrCreate (const String& familyName,
  195467. const bool create = false) throw()
  195468. {
  195469. for (int i = 0; i < faces.size(); i++)
  195470. if (faces[i]->getFamilyName() == familyName)
  195471. return faces[i];
  195472. if (! create)
  195473. return NULL;
  195474. FreeTypeFontFace* newFace = new FreeTypeFontFace (familyName);
  195475. faces.add (newFace);
  195476. return newFace;
  195477. }
  195478. // Enumerate all font faces available in a given directory
  195479. void enumerateFaces (const String& path) throw()
  195480. {
  195481. File dirPath (path);
  195482. if (path.isEmpty() || ! dirPath.isDirectory())
  195483. return;
  195484. DirectoryIterator di (dirPath, true);
  195485. while (di.next())
  195486. {
  195487. File possible (di.getFile());
  195488. if (possible.hasFileExtension (T("ttf"))
  195489. || possible.hasFileExtension (T("pfb"))
  195490. || possible.hasFileExtension (T("pcf")))
  195491. {
  195492. FT_Face face;
  195493. int faceIndex = 0;
  195494. int numFaces = 0;
  195495. do
  195496. {
  195497. if (FT_New_Face (ftLib,
  195498. possible.getFullPathName(),
  195499. faceIndex,
  195500. &face) == 0)
  195501. {
  195502. if (faceIndex == 0)
  195503. numFaces = face->num_faces;
  195504. if ((face->face_flags & FT_FACE_FLAG_SCALABLE) != 0)
  195505. {
  195506. FreeTypeFontFace* const newFace = findOrCreate (face->family_name, true);
  195507. int style = (int) FreeTypeFontFace::Plain;
  195508. if ((face->style_flags & FT_STYLE_FLAG_BOLD) != 0)
  195509. style |= (int) FreeTypeFontFace::Bold;
  195510. if ((face->style_flags & FT_STYLE_FLAG_ITALIC) != 0)
  195511. style |= (int) FreeTypeFontFace::Italic;
  195512. newFace->setFileName (possible.getFullPathName(), faceIndex, (FreeTypeFontFace::FontStyle) style);
  195513. newFace->setMonospaced ((face->face_flags & FT_FACE_FLAG_FIXED_WIDTH) != 0);
  195514. // Surely there must be a better way to do this?
  195515. const String name (face->family_name);
  195516. newFace->setSerif (! (name.containsIgnoreCase (T("Sans"))
  195517. || name.containsIgnoreCase (T("Verdana"))
  195518. || name.containsIgnoreCase (T("Arial"))));
  195519. }
  195520. FT_Done_Face (face);
  195521. }
  195522. ++faceIndex;
  195523. }
  195524. while (faceIndex < numFaces);
  195525. }
  195526. }
  195527. }
  195528. // Create a FreeType face object for a given font
  195529. FT_Face createFT_Face (const String& fontName,
  195530. const bool bold,
  195531. const bool italic) throw()
  195532. {
  195533. FT_Face face = 0;
  195534. if (fontName == lastFontName && bold == lastBold && italic == lastItalic)
  195535. {
  195536. face = lastFace;
  195537. }
  195538. else
  195539. {
  195540. if (lastFace != 0)
  195541. {
  195542. FT_Done_Face (lastFace);
  195543. lastFace = 0;
  195544. }
  195545. lastFontName = fontName;
  195546. lastBold = bold;
  195547. lastItalic = italic;
  195548. FreeTypeFontFace* const ftFace = findOrCreate (fontName);
  195549. if (ftFace != 0)
  195550. {
  195551. int style = (int) FreeTypeFontFace::Plain;
  195552. if (bold)
  195553. style |= (int) FreeTypeFontFace::Bold;
  195554. if (italic)
  195555. style |= (int) FreeTypeFontFace::Italic;
  195556. int faceIndex;
  195557. String fileName (ftFace->getFileName (style, faceIndex));
  195558. if (fileName.isEmpty())
  195559. {
  195560. style ^= (int) FreeTypeFontFace::Bold;
  195561. fileName = ftFace->getFileName (style, faceIndex);
  195562. if (fileName.isEmpty())
  195563. {
  195564. style ^= (int) FreeTypeFontFace::Bold;
  195565. style ^= (int) FreeTypeFontFace::Italic;
  195566. fileName = ftFace->getFileName (style, faceIndex);
  195567. if (! fileName.length())
  195568. {
  195569. style ^= (int) FreeTypeFontFace::Bold;
  195570. fileName = ftFace->getFileName (style, faceIndex);
  195571. }
  195572. }
  195573. }
  195574. if (! FT_New_Face (ftLib, (const char*) fileName, faceIndex, &lastFace))
  195575. {
  195576. face = lastFace;
  195577. // If there isn't a unicode charmap then select the first one.
  195578. if (FT_Select_Charmap (face, ft_encoding_unicode))
  195579. FT_Set_Charmap (face, face->charmaps[0]);
  195580. }
  195581. }
  195582. }
  195583. return face;
  195584. }
  195585. bool addGlyph (FT_Face face, CustomTypeface& dest, uint32 character) throw()
  195586. {
  195587. const unsigned int glyphIndex = FT_Get_Char_Index (face, character);
  195588. const float height = (float) (face->ascender - face->descender);
  195589. const float scaleX = 1.0f / height;
  195590. const float scaleY = -1.0f / height;
  195591. Path destShape;
  195592. #define CONVERTX(val) (scaleX * (val).x)
  195593. #define CONVERTY(val) (scaleY * (val).y)
  195594. if (FT_Load_Glyph (face, glyphIndex, FT_LOAD_NO_SCALE | FT_LOAD_NO_BITMAP | FT_LOAD_IGNORE_TRANSFORM) != 0
  195595. || face->glyph->format != ft_glyph_format_outline)
  195596. {
  195597. return false;
  195598. }
  195599. const FT_Outline* const outline = &face->glyph->outline;
  195600. const short* const contours = outline->contours;
  195601. const char* const tags = outline->tags;
  195602. FT_Vector* const points = outline->points;
  195603. for (int c = 0; c < outline->n_contours; c++)
  195604. {
  195605. const int startPoint = (c == 0) ? 0 : contours [c - 1] + 1;
  195606. const int endPoint = contours[c];
  195607. for (int p = startPoint; p <= endPoint; p++)
  195608. {
  195609. const float x = CONVERTX (points[p]);
  195610. const float y = CONVERTY (points[p]);
  195611. if (p == startPoint)
  195612. {
  195613. if (FT_CURVE_TAG (tags[p]) == FT_Curve_Tag_Conic)
  195614. {
  195615. float x2 = CONVERTX (points [endPoint]);
  195616. float y2 = CONVERTY (points [endPoint]);
  195617. if (FT_CURVE_TAG (tags[endPoint]) != FT_Curve_Tag_On)
  195618. {
  195619. x2 = (x + x2) * 0.5f;
  195620. y2 = (y + y2) * 0.5f;
  195621. }
  195622. destShape.startNewSubPath (x2, y2);
  195623. }
  195624. else
  195625. {
  195626. destShape.startNewSubPath (x, y);
  195627. }
  195628. }
  195629. if (FT_CURVE_TAG (tags[p]) == FT_Curve_Tag_On)
  195630. {
  195631. if (p != startPoint)
  195632. destShape.lineTo (x, y);
  195633. }
  195634. else if (FT_CURVE_TAG (tags[p]) == FT_Curve_Tag_Conic)
  195635. {
  195636. const int nextIndex = (p == endPoint) ? startPoint : p + 1;
  195637. float x2 = CONVERTX (points [nextIndex]);
  195638. float y2 = CONVERTY (points [nextIndex]);
  195639. if (FT_CURVE_TAG (tags [nextIndex]) == FT_Curve_Tag_Conic)
  195640. {
  195641. x2 = (x + x2) * 0.5f;
  195642. y2 = (y + y2) * 0.5f;
  195643. }
  195644. else
  195645. {
  195646. ++p;
  195647. }
  195648. destShape.quadraticTo (x, y, x2, y2);
  195649. }
  195650. else if (FT_CURVE_TAG (tags[p]) == FT_Curve_Tag_Cubic)
  195651. {
  195652. if (p >= endPoint)
  195653. return false;
  195654. const int next1 = p + 1;
  195655. const int next2 = (p == (endPoint - 1)) ? startPoint : p + 2;
  195656. const float x2 = CONVERTX (points [next1]);
  195657. const float y2 = CONVERTY (points [next1]);
  195658. const float x3 = CONVERTX (points [next2]);
  195659. const float y3 = CONVERTY (points [next2]);
  195660. if (FT_CURVE_TAG (tags[next1]) != FT_Curve_Tag_Cubic
  195661. || FT_CURVE_TAG (tags[next2]) != FT_Curve_Tag_On)
  195662. return false;
  195663. destShape.cubicTo (x, y, x2, y2, x3, y3);
  195664. p += 2;
  195665. }
  195666. }
  195667. destShape.closeSubPath();
  195668. }
  195669. dest.addGlyph (character, destShape, face->glyph->metrics.horiAdvance / height);
  195670. if ((face->face_flags & FT_FACE_FLAG_KERNING) != 0)
  195671. addKerning (face, dest, character, glyphIndex);
  195672. return true;
  195673. }
  195674. void addKerning (FT_Face face, CustomTypeface& dest, const uint32 character, const uint32 glyphIndex) throw()
  195675. {
  195676. const float height = (float) (face->ascender - face->descender);
  195677. uint32 rightGlyphIndex;
  195678. uint32 rightCharCode = FT_Get_First_Char (face, &rightGlyphIndex);
  195679. while (rightGlyphIndex != 0)
  195680. {
  195681. FT_Vector kerning;
  195682. if (FT_Get_Kerning (face, glyphIndex, rightGlyphIndex, ft_kerning_unscaled, &kerning) == 0)
  195683. {
  195684. if (kerning.x != 0)
  195685. dest.addKerningPair (character, rightCharCode, kerning.x / height);
  195686. }
  195687. rightCharCode = FT_Get_Next_Char (face, rightCharCode, &rightGlyphIndex);
  195688. }
  195689. }
  195690. // Add a glyph to a font
  195691. bool addGlyphToFont (const uint32 character,
  195692. const tchar* fontName, bool bold, bool italic,
  195693. CustomTypeface& dest) throw()
  195694. {
  195695. FT_Face face = createFT_Face (fontName, bold, italic);
  195696. if (face != 0)
  195697. return addGlyph (face, dest, character);
  195698. return false;
  195699. }
  195700. void getFamilyNames (StringArray& familyNames) const throw()
  195701. {
  195702. for (int i = 0; i < faces.size(); i++)
  195703. familyNames.add (faces[i]->getFamilyName());
  195704. }
  195705. void getMonospacedNames (StringArray& monoSpaced) const throw()
  195706. {
  195707. for (int i = 0; i < faces.size(); i++)
  195708. if (faces[i]->getMonospaced())
  195709. monoSpaced.add (faces[i]->getFamilyName());
  195710. }
  195711. void getSerifNames (StringArray& serif) const throw()
  195712. {
  195713. for (int i = 0; i < faces.size(); i++)
  195714. if (faces[i]->getSerif())
  195715. serif.add (faces[i]->getFamilyName());
  195716. }
  195717. void getSansSerifNames (StringArray& sansSerif) const throw()
  195718. {
  195719. for (int i = 0; i < faces.size(); i++)
  195720. if (! faces[i]->getSerif())
  195721. sansSerif.add (faces[i]->getFamilyName());
  195722. }
  195723. juce_DeclareSingleton_SingleThreaded_Minimal (FreeTypeInterface)
  195724. private:
  195725. FT_Library ftLib;
  195726. FT_Face lastFace;
  195727. String lastFontName;
  195728. bool lastBold, lastItalic;
  195729. OwnedArray<FreeTypeFontFace> faces;
  195730. };
  195731. juce_ImplementSingleton_SingleThreaded (FreeTypeInterface)
  195732. class FreetypeTypeface : public CustomTypeface
  195733. {
  195734. public:
  195735. FreetypeTypeface (const Font& font)
  195736. {
  195737. FT_Face face = FreeTypeInterface::getInstance()
  195738. ->createFT_Face (font.getTypefaceName(), font.isBold(), font.isItalic());
  195739. if (face == 0)
  195740. {
  195741. #ifdef JUCE_DEBUG
  195742. String msg (T("Failed to create typeface: "));
  195743. msg << font.getTypefaceName() << " " << (font.isBold() ? 'B' : ' ') << (font.isItalic() ? 'I' : ' ');
  195744. DBG (msg);
  195745. #endif
  195746. }
  195747. else
  195748. {
  195749. setCharacteristics (font.getTypefaceName(),
  195750. face->ascender / (float) (face->ascender - face->descender),
  195751. font.isBold(), font.isItalic(),
  195752. L' ');
  195753. }
  195754. }
  195755. bool loadGlyphIfPossible (const juce_wchar character)
  195756. {
  195757. return FreeTypeInterface::getInstance()
  195758. ->addGlyphToFont (character, name, isBold, isItalic, *this);
  195759. }
  195760. };
  195761. const Typeface::Ptr Typeface::createSystemTypefaceFor (const Font& font)
  195762. {
  195763. return new FreetypeTypeface (font);
  195764. }
  195765. const StringArray Font::findAllTypefaceNames() throw()
  195766. {
  195767. StringArray s;
  195768. FreeTypeInterface::getInstance()->getFamilyNames (s);
  195769. s.sort (true);
  195770. return s;
  195771. }
  195772. static const String pickBestFont (const StringArray& names,
  195773. const char* const choicesString)
  195774. {
  195775. StringArray choices;
  195776. choices.addTokens (String (choicesString), T(","), 0);
  195777. choices.trim();
  195778. choices.removeEmptyStrings();
  195779. int i, j;
  195780. for (j = 0; j < choices.size(); ++j)
  195781. if (names.contains (choices[j], true))
  195782. return choices[j];
  195783. for (j = 0; j < choices.size(); ++j)
  195784. for (i = 0; i < names.size(); i++)
  195785. if (names[i].startsWithIgnoreCase (choices[j]))
  195786. return names[i];
  195787. for (j = 0; j < choices.size(); ++j)
  195788. for (i = 0; i < names.size(); i++)
  195789. if (names[i].containsIgnoreCase (choices[j]))
  195790. return names[i];
  195791. return names[0];
  195792. }
  195793. static const String linux_getDefaultSansSerifFontName()
  195794. {
  195795. StringArray allFonts;
  195796. FreeTypeInterface::getInstance()->getSansSerifNames (allFonts);
  195797. return pickBestFont (allFonts, "Verdana, Bitstream Vera Sans, Luxi Sans, Sans");
  195798. }
  195799. static const String linux_getDefaultSerifFontName()
  195800. {
  195801. StringArray allFonts;
  195802. FreeTypeInterface::getInstance()->getSerifNames (allFonts);
  195803. return pickBestFont (allFonts, "Bitstream Vera Serif, Times, Nimbus Roman, Serif");
  195804. }
  195805. static const String linux_getDefaultMonospacedFontName()
  195806. {
  195807. StringArray allFonts;
  195808. FreeTypeInterface::getInstance()->getMonospacedNames (allFonts);
  195809. return pickBestFont (allFonts, "Bitstream Vera Sans Mono, Courier, Sans Mono, Mono");
  195810. }
  195811. void Font::getPlatformDefaultFontNames (String& defaultSans, String& defaultSerif, String& defaultFixed) throw()
  195812. {
  195813. defaultSans = linux_getDefaultSansSerifFontName();
  195814. defaultSerif = linux_getDefaultSerifFontName();
  195815. defaultFixed = linux_getDefaultMonospacedFontName();
  195816. }
  195817. #endif
  195818. /********* End of inlined file: juce_linux_Fonts.cpp *********/
  195819. /********* Start of inlined file: juce_linux_Windowing.cpp *********/
  195820. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  195821. // compiled on its own).
  195822. #if JUCE_INCLUDED_FILE
  195823. #define TAKE_FOCUS 0
  195824. #define DELETE_WINDOW 1
  195825. #define SYSTEM_TRAY_REQUEST_DOCK 0
  195826. #define SYSTEM_TRAY_BEGIN_MESSAGE 1
  195827. #define SYSTEM_TRAY_CANCEL_MESSAGE 2
  195828. static const int repaintTimerPeriod = 1000 / 100; // 100 fps maximum
  195829. static Atom wm_ChangeState = None;
  195830. static Atom wm_State = None;
  195831. static Atom wm_Protocols = None;
  195832. static Atom wm_ProtocolList [2] = { None, None };
  195833. static Atom wm_ActiveWin = None;
  195834. #define ourDndVersion 3
  195835. static Atom XA_XdndAware = None;
  195836. static Atom XA_XdndEnter = None;
  195837. static Atom XA_XdndLeave = None;
  195838. static Atom XA_XdndPosition = None;
  195839. static Atom XA_XdndStatus = None;
  195840. static Atom XA_XdndDrop = None;
  195841. static Atom XA_XdndFinished = None;
  195842. static Atom XA_XdndSelection = None;
  195843. static Atom XA_XdndProxy = None;
  195844. static Atom XA_XdndTypeList = None;
  195845. static Atom XA_XdndActionList = None;
  195846. static Atom XA_XdndActionDescription = None;
  195847. static Atom XA_XdndActionCopy = None;
  195848. static Atom XA_XdndActionMove = None;
  195849. static Atom XA_XdndActionLink = None;
  195850. static Atom XA_XdndActionAsk = None;
  195851. static Atom XA_XdndActionPrivate = None;
  195852. static Atom XA_JXSelectionWindowProperty = None;
  195853. static Atom XA_MimeTextPlain = None;
  195854. static Atom XA_MimeTextUriList = None;
  195855. static Atom XA_MimeRootDrop = None;
  195856. static XErrorHandler oldHandler = 0;
  195857. static int trappedErrorCode = 0;
  195858. extern "C" int errorTrapHandler (Display* dpy, XErrorEvent* err)
  195859. {
  195860. trappedErrorCode = err->error_code;
  195861. return 0;
  195862. }
  195863. static void trapErrors()
  195864. {
  195865. trappedErrorCode = 0;
  195866. oldHandler = XSetErrorHandler (errorTrapHandler);
  195867. }
  195868. static bool untrapErrors()
  195869. {
  195870. XSetErrorHandler (oldHandler);
  195871. return (trappedErrorCode == 0);
  195872. }
  195873. static bool isActiveApplication = false;
  195874. bool Process::isForegroundProcess()
  195875. {
  195876. return isActiveApplication;
  195877. }
  195878. // These are defined in juce_linux_Messaging.cpp
  195879. extern Display* display;
  195880. extern XContext improbableNumber;
  195881. static const int eventMask = NoEventMask | KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask
  195882. | EnterWindowMask | LeaveWindowMask | PointerMotionMask | KeymapStateMask
  195883. | ExposureMask | StructureNotifyMask | FocusChangeMask;
  195884. static int pointerMap[5];
  195885. static int lastMousePosX = 0, lastMousePosY = 0;
  195886. enum MouseButtons
  195887. {
  195888. NoButton = 0,
  195889. LeftButton = 1,
  195890. MiddleButton = 2,
  195891. RightButton = 3,
  195892. WheelUp = 4,
  195893. WheelDown = 5
  195894. };
  195895. static void getMousePos (int& x, int& y, int& mouseMods) throw()
  195896. {
  195897. Window root, child;
  195898. int winx, winy;
  195899. unsigned int mask;
  195900. mouseMods = 0;
  195901. ScopedXLock xlock;
  195902. if (XQueryPointer (display,
  195903. RootWindow (display, DefaultScreen (display)),
  195904. &root, &child,
  195905. &x, &y, &winx, &winy, &mask) == False)
  195906. {
  195907. // Pointer not on the default screen
  195908. x = y = -1;
  195909. }
  195910. else
  195911. {
  195912. if ((mask & Button1Mask) != 0)
  195913. mouseMods |= ModifierKeys::leftButtonModifier;
  195914. if ((mask & Button2Mask) != 0)
  195915. mouseMods |= ModifierKeys::middleButtonModifier;
  195916. if ((mask & Button3Mask) != 0)
  195917. mouseMods |= ModifierKeys::rightButtonModifier;
  195918. }
  195919. }
  195920. static int AltMask = 0;
  195921. static int NumLockMask = 0;
  195922. static bool numLock = 0;
  195923. static bool capsLock = 0;
  195924. static char keyStates [32];
  195925. static void updateKeyStates (const int keycode, const bool press) throw()
  195926. {
  195927. const int keybyte = keycode >> 3;
  195928. const int keybit = (1 << (keycode & 7));
  195929. if (press)
  195930. keyStates [keybyte] |= keybit;
  195931. else
  195932. keyStates [keybyte] &= ~keybit;
  195933. }
  195934. static bool keyDown (const int keycode) throw()
  195935. {
  195936. const int keybyte = keycode >> 3;
  195937. const int keybit = (1 << (keycode & 7));
  195938. return (keyStates [keybyte] & keybit) != 0;
  195939. }
  195940. static const int extendedKeyModifier = 0x10000000;
  195941. bool KeyPress::isKeyCurrentlyDown (const int keyCode) throw()
  195942. {
  195943. int keysym;
  195944. if (keyCode & extendedKeyModifier)
  195945. {
  195946. keysym = 0xff00 | (keyCode & 0xff);
  195947. }
  195948. else
  195949. {
  195950. keysym = keyCode;
  195951. if (keysym == (XK_Tab & 0xff)
  195952. || keysym == (XK_Return & 0xff)
  195953. || keysym == (XK_Escape & 0xff)
  195954. || keysym == (XK_BackSpace & 0xff))
  195955. {
  195956. keysym |= 0xff00;
  195957. }
  195958. }
  195959. ScopedXLock xlock;
  195960. return keyDown (XKeysymToKeycode (display, keysym));
  195961. }
  195962. // Alt and Num lock are not defined by standard X
  195963. // modifier constants: check what they're mapped to
  195964. static void getModifierMapping() throw()
  195965. {
  195966. ScopedXLock xlock;
  195967. const int altLeftCode = XKeysymToKeycode (display, XK_Alt_L);
  195968. const int numLockCode = XKeysymToKeycode (display, XK_Num_Lock);
  195969. AltMask = 0;
  195970. NumLockMask = 0;
  195971. XModifierKeymap* mapping = XGetModifierMapping (display);
  195972. if (mapping)
  195973. {
  195974. for (int i = 0; i < 8; i++)
  195975. {
  195976. if (mapping->modifiermap [i << 1] == altLeftCode)
  195977. AltMask = 1 << i;
  195978. else if (mapping->modifiermap [i << 1] == numLockCode)
  195979. NumLockMask = 1 << i;
  195980. }
  195981. XFreeModifiermap (mapping);
  195982. }
  195983. }
  195984. static int currentModifiers = 0;
  195985. void ModifierKeys::updateCurrentModifiers() throw()
  195986. {
  195987. currentModifierFlags = currentModifiers;
  195988. }
  195989. const ModifierKeys ModifierKeys::getCurrentModifiersRealtime() throw()
  195990. {
  195991. int x, y, mouseMods;
  195992. getMousePos (x, y, mouseMods);
  195993. currentModifiers &= ~ModifierKeys::allMouseButtonModifiers;
  195994. currentModifiers |= mouseMods;
  195995. return ModifierKeys (currentModifiers);
  195996. }
  195997. static void updateKeyModifiers (const int status) throw()
  195998. {
  195999. currentModifiers &= ~(ModifierKeys::shiftModifier
  196000. | ModifierKeys::ctrlModifier
  196001. | ModifierKeys::altModifier);
  196002. if (status & ShiftMask)
  196003. currentModifiers |= ModifierKeys::shiftModifier;
  196004. if (status & ControlMask)
  196005. currentModifiers |= ModifierKeys::ctrlModifier;
  196006. if (status & AltMask)
  196007. currentModifiers |= ModifierKeys::altModifier;
  196008. numLock = ((status & NumLockMask) != 0);
  196009. capsLock = ((status & LockMask) != 0);
  196010. }
  196011. static bool updateKeyModifiersFromSym (KeySym sym, const bool press) throw()
  196012. {
  196013. int modifier = 0;
  196014. bool isModifier = true;
  196015. switch (sym)
  196016. {
  196017. case XK_Shift_L:
  196018. case XK_Shift_R:
  196019. modifier = ModifierKeys::shiftModifier;
  196020. break;
  196021. case XK_Control_L:
  196022. case XK_Control_R:
  196023. modifier = ModifierKeys::ctrlModifier;
  196024. break;
  196025. case XK_Alt_L:
  196026. case XK_Alt_R:
  196027. modifier = ModifierKeys::altModifier;
  196028. break;
  196029. case XK_Num_Lock:
  196030. if (press)
  196031. numLock = ! numLock;
  196032. break;
  196033. case XK_Caps_Lock:
  196034. if (press)
  196035. capsLock = ! capsLock;
  196036. break;
  196037. case XK_Scroll_Lock:
  196038. break;
  196039. default:
  196040. isModifier = false;
  196041. break;
  196042. }
  196043. if (modifier != 0)
  196044. {
  196045. if (press)
  196046. currentModifiers |= modifier;
  196047. else
  196048. currentModifiers &= ~modifier;
  196049. }
  196050. return isModifier;
  196051. }
  196052. #if JUCE_USE_XSHM
  196053. static bool isShmAvailable() throw()
  196054. {
  196055. ScopedXLock xlock;
  196056. static bool isChecked = false;
  196057. static bool isAvailable = false;
  196058. if (! isChecked)
  196059. {
  196060. isChecked = true;
  196061. int major, minor;
  196062. Bool pixmaps;
  196063. if (XShmQueryVersion (display, &major, &minor, &pixmaps))
  196064. {
  196065. trapErrors();
  196066. XShmSegmentInfo segmentInfo;
  196067. zerostruct (segmentInfo);
  196068. XImage* xImage = XShmCreateImage (display, DefaultVisual (display, DefaultScreen (display)),
  196069. 24, ZPixmap, 0, &segmentInfo, 50, 50);
  196070. if ((segmentInfo.shmid = shmget (IPC_PRIVATE,
  196071. xImage->bytes_per_line * xImage->height,
  196072. IPC_CREAT | 0777)) >= 0)
  196073. {
  196074. segmentInfo.shmaddr = (char*) shmat (segmentInfo.shmid, 0, 0);
  196075. if (segmentInfo.shmaddr != (void*) -1)
  196076. {
  196077. segmentInfo.readOnly = False;
  196078. xImage->data = segmentInfo.shmaddr;
  196079. XSync (display, False);
  196080. if (XShmAttach (display, &segmentInfo) != 0)
  196081. {
  196082. XSync (display, False);
  196083. XShmDetach (display, &segmentInfo);
  196084. isAvailable = true;
  196085. }
  196086. }
  196087. XFlush (display);
  196088. XDestroyImage (xImage);
  196089. shmdt (segmentInfo.shmaddr);
  196090. }
  196091. shmctl (segmentInfo.shmid, IPC_RMID, 0);
  196092. isAvailable &= untrapErrors();
  196093. }
  196094. }
  196095. return isAvailable;
  196096. }
  196097. #endif
  196098. static Pixmap juce_createColourPixmapFromImage (Display* display, const Image& image)
  196099. {
  196100. ScopedXLock xlock;
  196101. const int width = image.getWidth();
  196102. const int height = image.getHeight();
  196103. HeapBlock <uint32> colour (width * height);
  196104. int index = 0;
  196105. for (int y = 0; y < height; ++y)
  196106. for (int x = 0; x < width; ++x)
  196107. colour[index++] = image.getPixelAt (x, y).getARGB();
  196108. XImage* ximage = XCreateImage (display, CopyFromParent, 24, ZPixmap,
  196109. 0, (char*) colour, width, height, 32, 0);
  196110. Pixmap pixmap = XCreatePixmap (display, DefaultRootWindow (display),
  196111. width, height, 24);
  196112. GC gc = XCreateGC (display, pixmap, 0, 0);
  196113. XPutImage (display, pixmap, gc, ximage, 0, 0, 0, 0, width, height);
  196114. XFreeGC (display, gc);
  196115. return pixmap;
  196116. }
  196117. static Pixmap juce_createMaskPixmapFromImage (Display* display, const Image& image)
  196118. {
  196119. ScopedXLock xlock;
  196120. const int width = image.getWidth();
  196121. const int height = image.getHeight();
  196122. const int stride = (width + 7) >> 3;
  196123. HeapBlock <uint8> mask;
  196124. mask.calloc (stride * height);
  196125. const bool msbfirst = (BitmapBitOrder (display) == MSBFirst);
  196126. for (int y = 0; y < height; ++y)
  196127. {
  196128. for (int x = 0; x < width; ++x)
  196129. {
  196130. const uint8 bit = (uint8) (1 << (msbfirst ? (7 - (x & 7)) : (x & 7)));
  196131. const int offset = y * stride + (x >> 3);
  196132. if (image.getPixelAt (x, y).getAlpha() >= 128)
  196133. mask[offset] |= bit;
  196134. }
  196135. }
  196136. return XCreatePixmapFromBitmapData (display, DefaultRootWindow (display),
  196137. (char*) mask, width, height, 1, 0, 1);
  196138. }
  196139. class XBitmapImage : public Image
  196140. {
  196141. public:
  196142. XBitmapImage (const PixelFormat format_, const int w, const int h,
  196143. const bool clearImage, const bool is16Bit_)
  196144. : Image (format_, w, h),
  196145. is16Bit (is16Bit_)
  196146. {
  196147. jassert (format_ == RGB || format_ == ARGB);
  196148. pixelStride = (format_ == RGB) ? 3 : 4;
  196149. lineStride = ((w * pixelStride + 3) & ~3);
  196150. ScopedXLock xlock;
  196151. Visual* const visual = DefaultVisual (display, DefaultScreen (display));
  196152. #if JUCE_USE_XSHM
  196153. usingXShm = false;
  196154. if ((! is16Bit) && isShmAvailable())
  196155. {
  196156. zerostruct (segmentInfo);
  196157. xImage = XShmCreateImage (display, visual, 24, ZPixmap, 0, &segmentInfo, w, h);
  196158. if (xImage != 0)
  196159. {
  196160. if ((segmentInfo.shmid = shmget (IPC_PRIVATE,
  196161. xImage->bytes_per_line * xImage->height,
  196162. IPC_CREAT | 0777)) >= 0)
  196163. {
  196164. segmentInfo.shmaddr = (char*) shmat (segmentInfo.shmid, 0, 0);
  196165. if (segmentInfo.shmaddr != (void*) -1)
  196166. {
  196167. segmentInfo.readOnly = False;
  196168. xImage->data = segmentInfo.shmaddr;
  196169. imageData = (uint8*) segmentInfo.shmaddr;
  196170. XSync (display, False);
  196171. if (XShmAttach (display, &segmentInfo) != 0)
  196172. {
  196173. XSync (display, False);
  196174. usingXShm = true;
  196175. }
  196176. else
  196177. {
  196178. jassertfalse
  196179. }
  196180. }
  196181. else
  196182. {
  196183. shmctl (segmentInfo.shmid, IPC_RMID, 0);
  196184. }
  196185. }
  196186. }
  196187. }
  196188. if (! usingXShm)
  196189. #endif
  196190. {
  196191. imageDataAllocated.malloc (lineStride * h);
  196192. imageData = imageDataAllocated;
  196193. if (format_ == ARGB && clearImage)
  196194. zeromem (imageData, h * lineStride);
  196195. xImage = (XImage*) juce_calloc (sizeof (XImage));
  196196. xImage->width = w;
  196197. xImage->height = h;
  196198. xImage->xoffset = 0;
  196199. xImage->format = ZPixmap;
  196200. xImage->data = (char*) imageData;
  196201. xImage->byte_order = ImageByteOrder (display);
  196202. xImage->bitmap_unit = BitmapUnit (display);
  196203. xImage->bitmap_bit_order = BitmapBitOrder (display);
  196204. xImage->bitmap_pad = 32;
  196205. xImage->depth = pixelStride * 8;
  196206. xImage->bytes_per_line = lineStride;
  196207. xImage->bits_per_pixel = pixelStride * 8;
  196208. xImage->red_mask = 0x00FF0000;
  196209. xImage->green_mask = 0x0000FF00;
  196210. xImage->blue_mask = 0x000000FF;
  196211. if (is16Bit)
  196212. {
  196213. const int pixelStride = 2;
  196214. const int lineStride = ((w * pixelStride + 3) & ~3);
  196215. imageData16Bit.malloc (lineStride * h);
  196216. xImage->data = imageData16Bit;
  196217. xImage->bitmap_pad = 16;
  196218. xImage->depth = pixelStride * 8;
  196219. xImage->bytes_per_line = lineStride;
  196220. xImage->bits_per_pixel = pixelStride * 8;
  196221. xImage->red_mask = visual->red_mask;
  196222. xImage->green_mask = visual->green_mask;
  196223. xImage->blue_mask = visual->blue_mask;
  196224. }
  196225. if (! XInitImage (xImage))
  196226. {
  196227. jassertfalse
  196228. }
  196229. }
  196230. }
  196231. ~XBitmapImage()
  196232. {
  196233. ScopedXLock xlock;
  196234. #if JUCE_USE_XSHM
  196235. if (usingXShm)
  196236. {
  196237. XShmDetach (display, &segmentInfo);
  196238. XFlush (display);
  196239. XDestroyImage (xImage);
  196240. shmdt (segmentInfo.shmaddr);
  196241. shmctl (segmentInfo.shmid, IPC_RMID, 0);
  196242. }
  196243. else
  196244. #endif
  196245. {
  196246. xImage->data = 0;
  196247. XDestroyImage (xImage);
  196248. }
  196249. }
  196250. void blitToWindow (Window window, int dx, int dy, int dw, int dh, int sx, int sy)
  196251. {
  196252. ScopedXLock xlock;
  196253. static GC gc = 0;
  196254. if (gc == 0)
  196255. gc = DefaultGC (display, DefaultScreen (display));
  196256. if (is16Bit)
  196257. {
  196258. const uint32 rMask = xImage->red_mask;
  196259. const uint32 rShiftL = jmax (0, getShiftNeeded (rMask));
  196260. const uint32 rShiftR = jmax (0, -getShiftNeeded (rMask));
  196261. const uint32 gMask = xImage->green_mask;
  196262. const uint32 gShiftL = jmax (0, getShiftNeeded (gMask));
  196263. const uint32 gShiftR = jmax (0, -getShiftNeeded (gMask));
  196264. const uint32 bMask = xImage->blue_mask;
  196265. const uint32 bShiftL = jmax (0, getShiftNeeded (bMask));
  196266. const uint32 bShiftR = jmax (0, -getShiftNeeded (bMask));
  196267. const Image::BitmapData srcData (*this, 0, 0, getWidth(), getHeight());
  196268. for (int y = sy; y < sy + dh; ++y)
  196269. {
  196270. const uint8* p = srcData.getPixelPointer (sx, y);
  196271. for (int x = sx; x < sx + dw; ++x)
  196272. {
  196273. const PixelRGB* const pixel = (const PixelRGB*) p;
  196274. p += srcData.pixelStride;
  196275. XPutPixel (xImage, x, y,
  196276. (((((uint32) pixel->getRed()) << rShiftL) >> rShiftR) & rMask)
  196277. | (((((uint32) pixel->getGreen()) << gShiftL) >> gShiftR) & gMask)
  196278. | (((((uint32) pixel->getBlue()) << bShiftL) >> bShiftR) & bMask));
  196279. }
  196280. }
  196281. }
  196282. // blit results to screen.
  196283. #if JUCE_USE_XSHM
  196284. if (usingXShm)
  196285. XShmPutImage (display, (::Drawable) window, gc, xImage, sx, sy, dx, dy, dw, dh, True);
  196286. else
  196287. #endif
  196288. XPutImage (display, (::Drawable) window, gc, xImage, sx, sy, dx, dy, dw, dh);
  196289. }
  196290. juce_UseDebuggingNewOperator
  196291. private:
  196292. XImage* xImage;
  196293. const bool is16Bit;
  196294. HeapBlock <char> imageData16Bit;
  196295. #if JUCE_USE_XSHM
  196296. XShmSegmentInfo segmentInfo;
  196297. bool usingXShm;
  196298. #endif
  196299. static int getShiftNeeded (const uint32 mask) throw()
  196300. {
  196301. for (int i = 32; --i >= 0;)
  196302. if (((mask >> i) & 1) != 0)
  196303. return i - 7;
  196304. jassertfalse
  196305. return 0;
  196306. }
  196307. };
  196308. #define checkMessageManagerIsLocked jassert (MessageManager::getInstance()->currentThreadHasLockedMessageManager());
  196309. class LinuxComponentPeer : public ComponentPeer
  196310. {
  196311. public:
  196312. LinuxComponentPeer (Component* const component, const int windowStyleFlags)
  196313. : ComponentPeer (component, windowStyleFlags),
  196314. windowH (0),
  196315. parentWindow (0),
  196316. wx (0),
  196317. wy (0),
  196318. ww (0),
  196319. wh (0),
  196320. taskbarImage (0),
  196321. fullScreen (false),
  196322. entered (false),
  196323. mapped (false)
  196324. {
  196325. // it's dangerous to create a window on a thread other than the message thread..
  196326. checkMessageManagerIsLocked
  196327. repainter = new LinuxRepaintManager (this);
  196328. createWindow();
  196329. setTitle (component->getName());
  196330. }
  196331. ~LinuxComponentPeer()
  196332. {
  196333. // it's dangerous to delete a window on a thread other than the message thread..
  196334. checkMessageManagerIsLocked
  196335. deleteTaskBarIcon();
  196336. deleteIconPixmaps();
  196337. destroyWindow();
  196338. windowH = 0;
  196339. }
  196340. void* getNativeHandle() const
  196341. {
  196342. return (void*) windowH;
  196343. }
  196344. static LinuxComponentPeer* getPeerFor (Window windowHandle) throw()
  196345. {
  196346. XPointer peer = 0;
  196347. ScopedXLock xlock;
  196348. if (! XFindContext (display, (XID) windowHandle, improbableNumber, &peer))
  196349. {
  196350. if (peer != 0 && ! ((LinuxComponentPeer*) peer)->isValidMessageListener())
  196351. peer = 0;
  196352. }
  196353. return (LinuxComponentPeer*) peer;
  196354. }
  196355. void setVisible (bool shouldBeVisible)
  196356. {
  196357. ScopedXLock xlock;
  196358. if (shouldBeVisible)
  196359. XMapWindow (display, windowH);
  196360. else
  196361. XUnmapWindow (display, windowH);
  196362. }
  196363. void setTitle (const String& title)
  196364. {
  196365. setWindowTitle (windowH, title);
  196366. }
  196367. void setPosition (int x, int y)
  196368. {
  196369. setBounds (x, y, ww, wh, false);
  196370. }
  196371. void setSize (int w, int h)
  196372. {
  196373. setBounds (wx, wy, w, h, false);
  196374. }
  196375. void setBounds (int x, int y, int w, int h, const bool isNowFullScreen)
  196376. {
  196377. fullScreen = isNowFullScreen;
  196378. if (windowH != 0)
  196379. {
  196380. const ComponentDeletionWatcher deletionChecker (component);
  196381. wx = x;
  196382. wy = y;
  196383. ww = jmax (1, w);
  196384. wh = jmax (1, h);
  196385. ScopedXLock xlock;
  196386. // Make sure the Window manager does what we want
  196387. XSizeHints* hints = XAllocSizeHints();
  196388. hints->flags = USSize | USPosition;
  196389. hints->width = ww;
  196390. hints->height = wh;
  196391. hints->x = wx;
  196392. hints->y = wy;
  196393. if ((getStyleFlags() & (windowHasTitleBar | windowIsResizable)) == windowHasTitleBar)
  196394. {
  196395. hints->min_width = hints->max_width = hints->width;
  196396. hints->min_height = hints->max_height = hints->height;
  196397. hints->flags |= PMinSize | PMaxSize;
  196398. }
  196399. XSetWMNormalHints (display, windowH, hints);
  196400. XFree (hints);
  196401. XMoveResizeWindow (display, windowH,
  196402. wx - windowBorder.getLeft(),
  196403. wy - windowBorder.getTop(), ww, wh);
  196404. if (! deletionChecker.hasBeenDeleted())
  196405. {
  196406. updateBorderSize();
  196407. handleMovedOrResized();
  196408. }
  196409. }
  196410. }
  196411. void getBounds (int& x, int& y, int& w, int& h) const
  196412. {
  196413. x = wx;
  196414. y = wy;
  196415. w = ww;
  196416. h = wh;
  196417. }
  196418. int getScreenX() const
  196419. {
  196420. return wx;
  196421. }
  196422. int getScreenY() const
  196423. {
  196424. return wy;
  196425. }
  196426. void relativePositionToGlobal (int& x, int& y)
  196427. {
  196428. x += wx;
  196429. y += wy;
  196430. }
  196431. void globalPositionToRelative (int& x, int& y)
  196432. {
  196433. x -= wx;
  196434. y -= wy;
  196435. }
  196436. void setMinimised (bool shouldBeMinimised)
  196437. {
  196438. if (shouldBeMinimised)
  196439. {
  196440. Window root = RootWindow (display, DefaultScreen (display));
  196441. XClientMessageEvent clientMsg;
  196442. clientMsg.display = display;
  196443. clientMsg.window = windowH;
  196444. clientMsg.type = ClientMessage;
  196445. clientMsg.format = 32;
  196446. clientMsg.message_type = wm_ChangeState;
  196447. clientMsg.data.l[0] = IconicState;
  196448. ScopedXLock xlock;
  196449. XSendEvent (display, root, false,
  196450. SubstructureRedirectMask | SubstructureNotifyMask,
  196451. (XEvent*) &clientMsg);
  196452. }
  196453. else
  196454. {
  196455. setVisible (true);
  196456. }
  196457. }
  196458. bool isMinimised() const
  196459. {
  196460. bool minimised = false;
  196461. unsigned char* stateProp;
  196462. unsigned long nitems, bytesLeft;
  196463. Atom actualType;
  196464. int actualFormat;
  196465. ScopedXLock xlock;
  196466. if (XGetWindowProperty (display, windowH, wm_State, 0, 64, False,
  196467. wm_State, &actualType, &actualFormat, &nitems, &bytesLeft,
  196468. &stateProp) == Success
  196469. && actualType == wm_State
  196470. && actualFormat == 32
  196471. && nitems > 0)
  196472. {
  196473. if (((unsigned long*) stateProp)[0] == IconicState)
  196474. minimised = true;
  196475. XFree (stateProp);
  196476. }
  196477. return minimised;
  196478. }
  196479. void setFullScreen (const bool shouldBeFullScreen)
  196480. {
  196481. Rectangle r (lastNonFullscreenBounds); // (get a copy of this before de-minimising)
  196482. setMinimised (false);
  196483. if (fullScreen != shouldBeFullScreen)
  196484. {
  196485. if (shouldBeFullScreen)
  196486. r = Desktop::getInstance().getMainMonitorArea();
  196487. if (! r.isEmpty())
  196488. setBounds (r.getX(), r.getY(), r.getWidth(), r.getHeight(), shouldBeFullScreen);
  196489. getComponent()->repaint();
  196490. }
  196491. }
  196492. bool isFullScreen() const
  196493. {
  196494. return fullScreen;
  196495. }
  196496. bool isChildWindowOf (Window possibleParent) const
  196497. {
  196498. Window* windowList = 0;
  196499. uint32 windowListSize = 0;
  196500. Window parent, root;
  196501. ScopedXLock xlock;
  196502. if (XQueryTree (display, windowH, &root, &parent, &windowList, &windowListSize) != 0)
  196503. {
  196504. if (windowList != 0)
  196505. XFree (windowList);
  196506. return parent == possibleParent;
  196507. }
  196508. return false;
  196509. }
  196510. bool isFrontWindow() const
  196511. {
  196512. Window* windowList = 0;
  196513. uint32 windowListSize = 0;
  196514. bool result = false;
  196515. ScopedXLock xlock;
  196516. Window parent, root = RootWindow (display, DefaultScreen (display));
  196517. if (XQueryTree (display, root, &root, &parent, &windowList, &windowListSize) != 0)
  196518. {
  196519. for (int i = windowListSize; --i >= 0;)
  196520. {
  196521. LinuxComponentPeer* const peer = LinuxComponentPeer::getPeerFor (windowList[i]);
  196522. if (peer != 0)
  196523. {
  196524. result = (peer == this);
  196525. break;
  196526. }
  196527. }
  196528. }
  196529. if (windowList != 0)
  196530. XFree (windowList);
  196531. return result;
  196532. }
  196533. bool contains (int x, int y, bool trueIfInAChildWindow) const
  196534. {
  196535. jassert (x >= 0 && y >= 0 && x < ww && y < wh); // should only be called for points that are actually inside the bounds
  196536. if (((unsigned int) x) >= (unsigned int) ww
  196537. || ((unsigned int) y) >= (unsigned int) wh)
  196538. return false;
  196539. bool inFront = false;
  196540. for (int i = 0; i < Desktop::getInstance().getNumComponents(); ++i)
  196541. {
  196542. Component* const c = Desktop::getInstance().getComponent (i);
  196543. if (inFront)
  196544. {
  196545. if (c->contains (x + wx - c->getScreenX(),
  196546. y + wy - c->getScreenY()))
  196547. {
  196548. return false;
  196549. }
  196550. }
  196551. else if (c == getComponent())
  196552. {
  196553. inFront = true;
  196554. }
  196555. }
  196556. if (trueIfInAChildWindow)
  196557. return true;
  196558. ::Window root, child;
  196559. unsigned int bw, depth;
  196560. int wx, wy, w, h;
  196561. ScopedXLock xlock;
  196562. if (! XGetGeometry (display, (::Drawable) windowH, &root,
  196563. &wx, &wy, (unsigned int*) &w, (unsigned int*) &h,
  196564. &bw, &depth))
  196565. {
  196566. return false;
  196567. }
  196568. if (! XTranslateCoordinates (display, windowH, windowH, x, y, &wx, &wy, &child))
  196569. return false;
  196570. return child == None;
  196571. }
  196572. const BorderSize getFrameSize() const
  196573. {
  196574. return BorderSize();
  196575. }
  196576. bool setAlwaysOnTop (bool alwaysOnTop)
  196577. {
  196578. if (windowH != 0)
  196579. {
  196580. const bool wasVisible = component->isVisible();
  196581. if (wasVisible)
  196582. setVisible (false); // doesn't always seem to work if the window is visible when this is done..
  196583. {
  196584. ScopedXLock xlock;
  196585. XSetWindowAttributes swa;
  196586. swa.override_redirect = alwaysOnTop ? True : False;
  196587. XChangeWindowAttributes (display, windowH, CWOverrideRedirect, &swa);
  196588. }
  196589. if (wasVisible)
  196590. setVisible (true);
  196591. }
  196592. return true;
  196593. }
  196594. void toFront (bool makeActive)
  196595. {
  196596. if (makeActive)
  196597. {
  196598. setVisible (true);
  196599. grabFocus();
  196600. }
  196601. XEvent ev;
  196602. ev.xclient.type = ClientMessage;
  196603. ev.xclient.serial = 0;
  196604. ev.xclient.send_event = True;
  196605. ev.xclient.message_type = wm_ActiveWin;
  196606. ev.xclient.window = windowH;
  196607. ev.xclient.format = 32;
  196608. ev.xclient.data.l[0] = 2;
  196609. ev.xclient.data.l[1] = CurrentTime;
  196610. ev.xclient.data.l[2] = 0;
  196611. ev.xclient.data.l[3] = 0;
  196612. ev.xclient.data.l[4] = 0;
  196613. {
  196614. ScopedXLock xlock;
  196615. XSendEvent (display, RootWindow (display, DefaultScreen (display)),
  196616. False,
  196617. SubstructureRedirectMask | SubstructureNotifyMask,
  196618. &ev);
  196619. XWindowAttributes attr;
  196620. XGetWindowAttributes (display, windowH, &attr);
  196621. if (attr.override_redirect)
  196622. XRaiseWindow (display, windowH);
  196623. XSync (display, False);
  196624. }
  196625. handleBroughtToFront();
  196626. }
  196627. void toBehind (ComponentPeer* other)
  196628. {
  196629. LinuxComponentPeer* const otherPeer = dynamic_cast <LinuxComponentPeer*> (other);
  196630. jassert (otherPeer != 0); // wrong type of window?
  196631. if (otherPeer != 0)
  196632. {
  196633. setMinimised (false);
  196634. Window newStack[] = { otherPeer->windowH, windowH };
  196635. ScopedXLock xlock;
  196636. XRestackWindows (display, newStack, 2);
  196637. }
  196638. }
  196639. bool isFocused() const
  196640. {
  196641. int revert;
  196642. Window focusedWindow = 0;
  196643. ScopedXLock xlock;
  196644. XGetInputFocus (display, &focusedWindow, &revert);
  196645. return focusedWindow == windowH;
  196646. }
  196647. void grabFocus()
  196648. {
  196649. XWindowAttributes atts;
  196650. ScopedXLock xlock;
  196651. if (windowH != 0
  196652. && XGetWindowAttributes (display, windowH, &atts)
  196653. && atts.map_state == IsViewable
  196654. && ! isFocused())
  196655. {
  196656. XSetInputFocus (display, windowH, RevertToParent, CurrentTime);
  196657. isActiveApplication = true;
  196658. }
  196659. }
  196660. void textInputRequired (int /*x*/, int /*y*/)
  196661. {
  196662. }
  196663. void repaint (int x, int y, int w, int h)
  196664. {
  196665. if (Rectangle::intersectRectangles (x, y, w, h,
  196666. 0, 0,
  196667. getComponent()->getWidth(),
  196668. getComponent()->getHeight()))
  196669. {
  196670. repainter->repaint (x, y, w, h);
  196671. }
  196672. }
  196673. void performAnyPendingRepaintsNow()
  196674. {
  196675. repainter->performAnyPendingRepaintsNow();
  196676. }
  196677. void setIcon (const Image& newIcon)
  196678. {
  196679. const int dataSize = newIcon.getWidth() * newIcon.getHeight() + 2;
  196680. HeapBlock <unsigned long> data (dataSize);
  196681. int index = 0;
  196682. data[index++] = newIcon.getWidth();
  196683. data[index++] = newIcon.getHeight();
  196684. for (int y = 0; y < newIcon.getHeight(); ++y)
  196685. for (int x = 0; x < newIcon.getWidth(); ++x)
  196686. data[index++] = newIcon.getPixelAt (x, y).getARGB();
  196687. ScopedXLock xlock;
  196688. XChangeProperty (display, windowH,
  196689. XInternAtom (display, "_NET_WM_ICON", False),
  196690. XA_CARDINAL, 32, PropModeReplace,
  196691. (unsigned char*) data, dataSize);
  196692. deleteIconPixmaps();
  196693. XWMHints* wmHints = XGetWMHints (display, windowH);
  196694. if (wmHints == 0)
  196695. wmHints = XAllocWMHints();
  196696. wmHints->flags |= IconPixmapHint | IconMaskHint;
  196697. wmHints->icon_pixmap = juce_createColourPixmapFromImage (display, newIcon);
  196698. wmHints->icon_mask = juce_createMaskPixmapFromImage (display, newIcon);
  196699. XSetWMHints (display, windowH, wmHints);
  196700. XFree (wmHints);
  196701. XSync (display, False);
  196702. }
  196703. void deleteIconPixmaps()
  196704. {
  196705. ScopedXLock xlock;
  196706. XWMHints* wmHints = XGetWMHints (display, windowH);
  196707. if (wmHints != 0)
  196708. {
  196709. if ((wmHints->flags & IconPixmapHint) != 0)
  196710. {
  196711. wmHints->flags &= ~IconPixmapHint;
  196712. XFreePixmap (display, wmHints->icon_pixmap);
  196713. }
  196714. if ((wmHints->flags & IconMaskHint) != 0)
  196715. {
  196716. wmHints->flags &= ~IconMaskHint;
  196717. XFreePixmap (display, wmHints->icon_mask);
  196718. }
  196719. XSetWMHints (display, windowH, wmHints);
  196720. XFree (wmHints);
  196721. }
  196722. }
  196723. void handleWindowMessage (XEvent* event)
  196724. {
  196725. switch (event->xany.type)
  196726. {
  196727. case 2: // 'KeyPress'
  196728. {
  196729. ScopedXLock xlock;
  196730. XKeyEvent* const keyEvent = (XKeyEvent*) &event->xkey;
  196731. updateKeyStates (keyEvent->keycode, true);
  196732. char utf8 [64];
  196733. zeromem (utf8, sizeof (utf8));
  196734. KeySym sym;
  196735. XLookupString (keyEvent, utf8, sizeof (utf8), &sym, 0);
  196736. const juce_wchar unicodeChar = *(const juce_wchar*) String::fromUTF8 ((const uint8*) utf8, sizeof (utf8) - 1);
  196737. int keyCode = (int) unicodeChar;
  196738. if (keyCode < 0x20)
  196739. keyCode = XKeycodeToKeysym (display, keyEvent->keycode,
  196740. (currentModifiers & ModifierKeys::shiftModifier) != 0 ? 1 : 0);
  196741. const int oldMods = currentModifiers;
  196742. bool keyPressed = false;
  196743. const bool keyDownChange = (sym != NoSymbol) && ! updateKeyModifiersFromSym (sym, true);
  196744. if ((sym & 0xff00) == 0xff00)
  196745. {
  196746. // Translate keypad
  196747. if (sym == XK_KP_Divide)
  196748. keyCode = XK_slash;
  196749. else if (sym == XK_KP_Multiply)
  196750. keyCode = XK_asterisk;
  196751. else if (sym == XK_KP_Subtract)
  196752. keyCode = XK_hyphen;
  196753. else if (sym == XK_KP_Add)
  196754. keyCode = XK_plus;
  196755. else if (sym == XK_KP_Enter)
  196756. keyCode = XK_Return;
  196757. else if (sym == XK_KP_Decimal)
  196758. keyCode = numLock ? XK_period : XK_Delete;
  196759. else if (sym == XK_KP_0)
  196760. keyCode = numLock ? XK_0 : XK_Insert;
  196761. else if (sym == XK_KP_1)
  196762. keyCode = numLock ? XK_1 : XK_End;
  196763. else if (sym == XK_KP_2)
  196764. keyCode = numLock ? XK_2 : XK_Down;
  196765. else if (sym == XK_KP_3)
  196766. keyCode = numLock ? XK_3 : XK_Page_Down;
  196767. else if (sym == XK_KP_4)
  196768. keyCode = numLock ? XK_4 : XK_Left;
  196769. else if (sym == XK_KP_5)
  196770. keyCode = XK_5;
  196771. else if (sym == XK_KP_6)
  196772. keyCode = numLock ? XK_6 : XK_Right;
  196773. else if (sym == XK_KP_7)
  196774. keyCode = numLock ? XK_7 : XK_Home;
  196775. else if (sym == XK_KP_8)
  196776. keyCode = numLock ? XK_8 : XK_Up;
  196777. else if (sym == XK_KP_9)
  196778. keyCode = numLock ? XK_9 : XK_Page_Up;
  196779. switch (sym)
  196780. {
  196781. case XK_Left:
  196782. case XK_Right:
  196783. case XK_Up:
  196784. case XK_Down:
  196785. case XK_Page_Up:
  196786. case XK_Page_Down:
  196787. case XK_End:
  196788. case XK_Home:
  196789. case XK_Delete:
  196790. case XK_Insert:
  196791. keyPressed = true;
  196792. keyCode = (sym & 0xff) | extendedKeyModifier;
  196793. break;
  196794. case XK_Tab:
  196795. case XK_Return:
  196796. case XK_Escape:
  196797. case XK_BackSpace:
  196798. keyPressed = true;
  196799. keyCode &= 0xff;
  196800. break;
  196801. default:
  196802. {
  196803. if (sym >= XK_F1 && sym <= XK_F16)
  196804. {
  196805. keyPressed = true;
  196806. keyCode = (sym & 0xff) | extendedKeyModifier;
  196807. }
  196808. break;
  196809. }
  196810. }
  196811. }
  196812. if (utf8[0] != 0 || ((sym & 0xff00) == 0 && sym >= 8))
  196813. keyPressed = true;
  196814. if (oldMods != currentModifiers)
  196815. handleModifierKeysChange();
  196816. if (keyDownChange)
  196817. handleKeyUpOrDown (true);
  196818. if (keyPressed)
  196819. handleKeyPress (keyCode, unicodeChar);
  196820. break;
  196821. }
  196822. case KeyRelease:
  196823. {
  196824. const XKeyEvent* const keyEvent = (const XKeyEvent*) &event->xkey;
  196825. updateKeyStates (keyEvent->keycode, false);
  196826. ScopedXLock xlock;
  196827. KeySym sym = XKeycodeToKeysym (display, keyEvent->keycode, 0);
  196828. const int oldMods = currentModifiers;
  196829. const bool keyDownChange = (sym != NoSymbol) && ! updateKeyModifiersFromSym (sym, false);
  196830. if (oldMods != currentModifiers)
  196831. handleModifierKeysChange();
  196832. if (keyDownChange)
  196833. handleKeyUpOrDown (false);
  196834. break;
  196835. }
  196836. case ButtonPress:
  196837. {
  196838. const XButtonPressedEvent* const buttonPressEvent = (const XButtonPressedEvent*) &event->xbutton;
  196839. bool buttonMsg = false;
  196840. bool wheelUpMsg = false;
  196841. bool wheelDownMsg = false;
  196842. const int map = pointerMap [buttonPressEvent->button - Button1];
  196843. if (map == LeftButton)
  196844. {
  196845. currentModifiers |= ModifierKeys::leftButtonModifier;
  196846. buttonMsg = true;
  196847. }
  196848. else if (map == RightButton)
  196849. {
  196850. currentModifiers |= ModifierKeys::rightButtonModifier;
  196851. buttonMsg = true;
  196852. }
  196853. else if (map == MiddleButton)
  196854. {
  196855. currentModifiers |= ModifierKeys::middleButtonModifier;
  196856. buttonMsg = true;
  196857. }
  196858. else if (map == WheelUp)
  196859. {
  196860. wheelUpMsg = true;
  196861. }
  196862. else if (map == WheelDown)
  196863. {
  196864. wheelDownMsg = true;
  196865. }
  196866. updateKeyModifiers (buttonPressEvent->state);
  196867. if (buttonMsg)
  196868. {
  196869. toFront (true);
  196870. handleMouseDown (buttonPressEvent->x, buttonPressEvent->y,
  196871. getEventTime (buttonPressEvent->time));
  196872. }
  196873. else if (wheelUpMsg || wheelDownMsg)
  196874. {
  196875. handleMouseWheel (0, wheelDownMsg ? -84 : 84,
  196876. getEventTime (buttonPressEvent->time));
  196877. }
  196878. lastMousePosX = lastMousePosY = 0x100000;
  196879. break;
  196880. }
  196881. case ButtonRelease:
  196882. {
  196883. const XButtonReleasedEvent* const buttonRelEvent = (const XButtonReleasedEvent*) &event->xbutton;
  196884. const int oldModifiers = currentModifiers;
  196885. const int map = pointerMap [buttonRelEvent->button - Button1];
  196886. if (map == LeftButton)
  196887. currentModifiers &= ~ModifierKeys::leftButtonModifier;
  196888. else if (map == RightButton)
  196889. currentModifiers &= ~ModifierKeys::rightButtonModifier;
  196890. else if (map == MiddleButton)
  196891. currentModifiers &= ~ModifierKeys::middleButtonModifier;
  196892. updateKeyModifiers (buttonRelEvent->state);
  196893. handleMouseUp (oldModifiers,
  196894. buttonRelEvent->x, buttonRelEvent->y,
  196895. getEventTime (buttonRelEvent->time));
  196896. lastMousePosX = lastMousePosY = 0x100000;
  196897. break;
  196898. }
  196899. case MotionNotify:
  196900. {
  196901. const XPointerMovedEvent* const movedEvent = (const XPointerMovedEvent*) &event->xmotion;
  196902. updateKeyModifiers (movedEvent->state);
  196903. int x, y, mouseMods;
  196904. getMousePos (x, y, mouseMods);
  196905. if (lastMousePosX != x || lastMousePosY != y)
  196906. {
  196907. lastMousePosX = x;
  196908. lastMousePosY = y;
  196909. if (parentWindow != 0 && (styleFlags & windowHasTitleBar) == 0)
  196910. {
  196911. Window wRoot = 0, wParent = 0;
  196912. Window* wChild = 0;
  196913. unsigned int numChildren;
  196914. {
  196915. ScopedXLock xlock;
  196916. XQueryTree (display, windowH, &wRoot, &wParent, &wChild, &numChildren);
  196917. }
  196918. if (wParent != 0
  196919. && wParent != windowH
  196920. && wParent != wRoot)
  196921. {
  196922. parentWindow = wParent;
  196923. updateBounds();
  196924. x -= getScreenX();
  196925. y -= getScreenY();
  196926. }
  196927. else
  196928. {
  196929. parentWindow = 0;
  196930. x -= getScreenX();
  196931. y -= getScreenY();
  196932. }
  196933. }
  196934. else
  196935. {
  196936. x -= getScreenX();
  196937. y -= getScreenY();
  196938. }
  196939. if ((currentModifiers & ModifierKeys::allMouseButtonModifiers) == 0)
  196940. handleMouseMove (x, y, getEventTime (movedEvent->time));
  196941. else
  196942. handleMouseDrag (x, y, getEventTime (movedEvent->time));
  196943. }
  196944. break;
  196945. }
  196946. case EnterNotify:
  196947. {
  196948. lastMousePosX = lastMousePosY = 0x100000;
  196949. const XEnterWindowEvent* const enterEvent = (const XEnterWindowEvent*) &event->xcrossing;
  196950. if ((currentModifiers & ModifierKeys::allMouseButtonModifiers) == 0
  196951. && ! entered)
  196952. {
  196953. updateKeyModifiers (enterEvent->state);
  196954. handleMouseEnter (enterEvent->x, enterEvent->y, getEventTime (enterEvent->time));
  196955. entered = true;
  196956. }
  196957. break;
  196958. }
  196959. case LeaveNotify:
  196960. {
  196961. const XLeaveWindowEvent* const leaveEvent = (const XLeaveWindowEvent*) &event->xcrossing;
  196962. // Suppress the normal leave if we've got a pointer grab, or if
  196963. // it's a bogus one caused by clicking a mouse button when running
  196964. // in a Window manager
  196965. if (((currentModifiers & ModifierKeys::allMouseButtonModifiers) == 0
  196966. && leaveEvent->mode == NotifyNormal)
  196967. || leaveEvent->mode == NotifyUngrab)
  196968. {
  196969. updateKeyModifiers (leaveEvent->state);
  196970. handleMouseExit (leaveEvent->x, leaveEvent->y, getEventTime (leaveEvent->time));
  196971. entered = false;
  196972. }
  196973. break;
  196974. }
  196975. case FocusIn:
  196976. {
  196977. isActiveApplication = true;
  196978. if (isFocused())
  196979. handleFocusGain();
  196980. break;
  196981. }
  196982. case FocusOut:
  196983. {
  196984. isActiveApplication = false;
  196985. if (! isFocused())
  196986. handleFocusLoss();
  196987. break;
  196988. }
  196989. case Expose:
  196990. {
  196991. // Batch together all pending expose events
  196992. XExposeEvent* exposeEvent = (XExposeEvent*) &event->xexpose;
  196993. XEvent nextEvent;
  196994. ScopedXLock xlock;
  196995. if (exposeEvent->window != windowH)
  196996. {
  196997. Window child;
  196998. XTranslateCoordinates (display, exposeEvent->window, windowH,
  196999. exposeEvent->x, exposeEvent->y, &exposeEvent->x, &exposeEvent->y,
  197000. &child);
  197001. }
  197002. repaint (exposeEvent->x, exposeEvent->y,
  197003. exposeEvent->width, exposeEvent->height);
  197004. while (XEventsQueued (display, QueuedAfterFlush) > 0)
  197005. {
  197006. XPeekEvent (display, (XEvent*) &nextEvent);
  197007. if (nextEvent.type != Expose || nextEvent.xany.window != event->xany.window)
  197008. break;
  197009. XNextEvent (display, (XEvent*) &nextEvent);
  197010. XExposeEvent* nextExposeEvent = (XExposeEvent*) &nextEvent.xexpose;
  197011. repaint (nextExposeEvent->x, nextExposeEvent->y,
  197012. nextExposeEvent->width, nextExposeEvent->height);
  197013. }
  197014. break;
  197015. }
  197016. case CirculateNotify:
  197017. case CreateNotify:
  197018. case DestroyNotify:
  197019. // Think we can ignore these
  197020. break;
  197021. case ConfigureNotify:
  197022. {
  197023. updateBounds();
  197024. updateBorderSize();
  197025. handleMovedOrResized();
  197026. // if the native title bar is dragged, need to tell any active menus, etc.
  197027. if ((styleFlags & windowHasTitleBar) != 0
  197028. && component->isCurrentlyBlockedByAnotherModalComponent())
  197029. {
  197030. Component* const currentModalComp = Component::getCurrentlyModalComponent();
  197031. if (currentModalComp != 0)
  197032. currentModalComp->inputAttemptWhenModal();
  197033. }
  197034. XConfigureEvent* const confEvent = (XConfigureEvent*) &event->xconfigure;
  197035. if (confEvent->window == windowH
  197036. && confEvent->above != 0
  197037. && isFrontWindow())
  197038. {
  197039. handleBroughtToFront();
  197040. }
  197041. break;
  197042. }
  197043. case ReparentNotify:
  197044. case GravityNotify:
  197045. {
  197046. parentWindow = 0;
  197047. Window wRoot = 0;
  197048. Window* wChild = 0;
  197049. unsigned int numChildren;
  197050. {
  197051. ScopedXLock xlock;
  197052. XQueryTree (display, windowH, &wRoot, &parentWindow, &wChild, &numChildren);
  197053. }
  197054. if (parentWindow == windowH || parentWindow == wRoot)
  197055. parentWindow = 0;
  197056. updateBounds();
  197057. updateBorderSize();
  197058. handleMovedOrResized();
  197059. break;
  197060. }
  197061. case MapNotify:
  197062. mapped = true;
  197063. handleBroughtToFront();
  197064. break;
  197065. case UnmapNotify:
  197066. mapped = false;
  197067. break;
  197068. case MappingNotify:
  197069. {
  197070. XMappingEvent* mappingEvent = (XMappingEvent*) &event->xmapping;
  197071. if (mappingEvent->request != MappingPointer)
  197072. {
  197073. // Deal with modifier/keyboard mapping
  197074. ScopedXLock xlock;
  197075. XRefreshKeyboardMapping (mappingEvent);
  197076. getModifierMapping();
  197077. }
  197078. break;
  197079. }
  197080. case ClientMessage:
  197081. {
  197082. const XClientMessageEvent* const clientMsg = (const XClientMessageEvent*) &event->xclient;
  197083. if (clientMsg->message_type == wm_Protocols && clientMsg->format == 32)
  197084. {
  197085. const Atom atom = (Atom) clientMsg->data.l[0];
  197086. if (atom == wm_ProtocolList [TAKE_FOCUS])
  197087. {
  197088. XWindowAttributes atts;
  197089. ScopedXLock xlock;
  197090. if (clientMsg->window != 0
  197091. && XGetWindowAttributes (display, clientMsg->window, &atts))
  197092. {
  197093. if (atts.map_state == IsViewable)
  197094. XSetInputFocus (display, clientMsg->window, RevertToParent, clientMsg->data.l[1]);
  197095. }
  197096. }
  197097. else if (atom == wm_ProtocolList [DELETE_WINDOW])
  197098. {
  197099. handleUserClosingWindow();
  197100. }
  197101. }
  197102. else if (clientMsg->message_type == XA_XdndEnter)
  197103. {
  197104. handleDragAndDropEnter (clientMsg);
  197105. }
  197106. else if (clientMsg->message_type == XA_XdndLeave)
  197107. {
  197108. resetDragAndDrop();
  197109. }
  197110. else if (clientMsg->message_type == XA_XdndPosition)
  197111. {
  197112. handleDragAndDropPosition (clientMsg);
  197113. }
  197114. else if (clientMsg->message_type == XA_XdndDrop)
  197115. {
  197116. handleDragAndDropDrop (clientMsg);
  197117. }
  197118. else if (clientMsg->message_type == XA_XdndStatus)
  197119. {
  197120. handleDragAndDropStatus (clientMsg);
  197121. }
  197122. else if (clientMsg->message_type == XA_XdndFinished)
  197123. {
  197124. resetDragAndDrop();
  197125. }
  197126. break;
  197127. }
  197128. case SelectionNotify:
  197129. handleDragAndDropSelection (event);
  197130. break;
  197131. case SelectionClear:
  197132. case SelectionRequest:
  197133. break;
  197134. default:
  197135. #if JUCE_USE_XSHM
  197136. {
  197137. ScopedXLock xlock;
  197138. if (event->xany.type == XShmGetEventBase (display))
  197139. repainter->notifyPaintCompleted();
  197140. }
  197141. #endif
  197142. break;
  197143. }
  197144. }
  197145. void showMouseCursor (Cursor cursor) throw()
  197146. {
  197147. ScopedXLock xlock;
  197148. XDefineCursor (display, windowH, cursor);
  197149. }
  197150. void setTaskBarIcon (const Image& image)
  197151. {
  197152. ScopedXLock xlock;
  197153. deleteTaskBarIcon();
  197154. taskbarImage = image.createCopy();
  197155. Screen* const screen = XDefaultScreenOfDisplay (display);
  197156. const int screenNumber = XScreenNumberOfScreen (screen);
  197157. String screenAtom ("_NET_SYSTEM_TRAY_S");
  197158. screenAtom << screenNumber;
  197159. Atom selectionAtom = XInternAtom (display, (const char*) screenAtom, false);
  197160. XGrabServer (display);
  197161. Window managerWin = XGetSelectionOwner (display, selectionAtom);
  197162. if (managerWin != None)
  197163. XSelectInput (display, managerWin, StructureNotifyMask);
  197164. XUngrabServer (display);
  197165. XFlush (display);
  197166. if (managerWin != None)
  197167. {
  197168. XEvent ev;
  197169. zerostruct (ev);
  197170. ev.xclient.type = ClientMessage;
  197171. ev.xclient.window = managerWin;
  197172. ev.xclient.message_type = XInternAtom (display, "_NET_SYSTEM_TRAY_OPCODE", False);
  197173. ev.xclient.format = 32;
  197174. ev.xclient.data.l[0] = CurrentTime;
  197175. ev.xclient.data.l[1] = SYSTEM_TRAY_REQUEST_DOCK;
  197176. ev.xclient.data.l[2] = windowH;
  197177. ev.xclient.data.l[3] = 0;
  197178. ev.xclient.data.l[4] = 0;
  197179. XSendEvent (display, managerWin, False, NoEventMask, &ev);
  197180. XSync (display, False);
  197181. }
  197182. // For older KDE's ...
  197183. long atomData = 1;
  197184. Atom trayAtom = XInternAtom (display, "KWM_DOCKWINDOW", false);
  197185. XChangeProperty (display, windowH, trayAtom, trayAtom, 32, PropModeReplace, (unsigned char*) &atomData, 1);
  197186. // For more recent KDE's...
  197187. trayAtom = XInternAtom (display, "_KDE_NET_WM_SYSTEM_TRAY_WINDOW_FOR", false);
  197188. XChangeProperty (display, windowH, trayAtom, XA_WINDOW, 32, PropModeReplace, (unsigned char*) &windowH, 1);
  197189. // a minimum size must be specified for GNOME and Xfce, otherwise the icon is displayed with a width of 1
  197190. XSizeHints* hints = XAllocSizeHints();
  197191. hints->flags = PMinSize;
  197192. hints->min_width = 22;
  197193. hints->min_height = 22;
  197194. XSetWMNormalHints (display, windowH, hints);
  197195. XFree (hints);
  197196. }
  197197. void deleteTaskBarIcon()
  197198. {
  197199. deleteAndZero (taskbarImage);
  197200. }
  197201. const Image* getTaskbarIcon() const throw() { return taskbarImage; }
  197202. juce_UseDebuggingNewOperator
  197203. bool dontRepaint;
  197204. private:
  197205. class LinuxRepaintManager : public Timer
  197206. {
  197207. public:
  197208. LinuxRepaintManager (LinuxComponentPeer* const peer_)
  197209. : peer (peer_),
  197210. lastTimeImageUsed (0)
  197211. {
  197212. #if JUCE_USE_XSHM
  197213. shmCompletedDrawing = true;
  197214. useARGBImagesForRendering = isShmAvailable();
  197215. if (useARGBImagesForRendering)
  197216. {
  197217. ScopedXLock xlock;
  197218. XShmSegmentInfo segmentinfo;
  197219. XImage* const testImage
  197220. = XShmCreateImage (display, DefaultVisual (display, DefaultScreen (display)),
  197221. 24, ZPixmap, 0, &segmentinfo, 64, 64);
  197222. useARGBImagesForRendering = (testImage->bits_per_pixel == 32);
  197223. XDestroyImage (testImage);
  197224. }
  197225. #endif
  197226. }
  197227. ~LinuxRepaintManager()
  197228. {
  197229. }
  197230. void timerCallback()
  197231. {
  197232. #if JUCE_USE_XSHM
  197233. if (! shmCompletedDrawing)
  197234. return;
  197235. #endif
  197236. if (! regionsNeedingRepaint.isEmpty())
  197237. {
  197238. stopTimer();
  197239. performAnyPendingRepaintsNow();
  197240. }
  197241. else if (Time::getApproximateMillisecondCounter() > lastTimeImageUsed + 3000)
  197242. {
  197243. stopTimer();
  197244. image = 0;
  197245. }
  197246. }
  197247. void repaint (int x, int y, int w, int h)
  197248. {
  197249. if (! isTimerRunning())
  197250. startTimer (repaintTimerPeriod);
  197251. regionsNeedingRepaint.add (x, y, w, h);
  197252. }
  197253. void performAnyPendingRepaintsNow()
  197254. {
  197255. #if JUCE_USE_XSHM
  197256. if (! shmCompletedDrawing)
  197257. {
  197258. startTimer (repaintTimerPeriod);
  197259. return;
  197260. }
  197261. #endif
  197262. peer->clearMaskedRegion();
  197263. RectangleList originalRepaintRegion (regionsNeedingRepaint);
  197264. regionsNeedingRepaint.clear();
  197265. const Rectangle totalArea (originalRepaintRegion.getBounds());
  197266. if (! totalArea.isEmpty())
  197267. {
  197268. #if JUCE_USE_XSHM
  197269. shmCompletedDrawing = false;
  197270. #endif
  197271. if (image == 0 || image->getWidth() < totalArea.getWidth()
  197272. || image->getHeight() < totalArea.getHeight())
  197273. {
  197274. #if JUCE_USE_XSHM
  197275. image = new XBitmapImage (useARGBImagesForRendering ? Image::ARGB
  197276. : Image::RGB,
  197277. #else
  197278. image = new XBitmapImage (Image::RGB,
  197279. #endif
  197280. (totalArea.getWidth() + 31) & ~31,
  197281. (totalArea.getHeight() + 31) & ~31,
  197282. false,
  197283. peer->depthIs16Bit);
  197284. }
  197285. startTimer (repaintTimerPeriod);
  197286. LowLevelGraphicsSoftwareRenderer context (*image);
  197287. context.setOrigin (-totalArea.getX(), -totalArea.getY());
  197288. if (context.clipToRectangleList (originalRepaintRegion))
  197289. peer->handlePaint (context);
  197290. if (! peer->maskedRegion.isEmpty())
  197291. originalRepaintRegion.subtract (peer->maskedRegion);
  197292. for (RectangleList::Iterator i (originalRepaintRegion); i.next();)
  197293. {
  197294. const Rectangle& r = *i.getRectangle();
  197295. image->blitToWindow (peer->windowH,
  197296. r.getX(), r.getY(), r.getWidth(), r.getHeight(),
  197297. r.getX() - totalArea.getX(), r.getY() - totalArea.getY());
  197298. }
  197299. }
  197300. lastTimeImageUsed = Time::getApproximateMillisecondCounter();
  197301. startTimer (repaintTimerPeriod);
  197302. }
  197303. #if JUCE_USE_XSHM
  197304. void notifyPaintCompleted() { shmCompletedDrawing = true; }
  197305. #endif
  197306. private:
  197307. LinuxComponentPeer* const peer;
  197308. ScopedPointer <XBitmapImage> image;
  197309. uint32 lastTimeImageUsed;
  197310. RectangleList regionsNeedingRepaint;
  197311. #if JUCE_USE_XSHM
  197312. bool useARGBImagesForRendering, shmCompletedDrawing;
  197313. #endif
  197314. LinuxRepaintManager (const LinuxRepaintManager&);
  197315. const LinuxRepaintManager& operator= (const LinuxRepaintManager&);
  197316. };
  197317. ScopedPointer <LinuxRepaintManager> repainter;
  197318. friend class LinuxRepaintManager;
  197319. Window windowH, parentWindow;
  197320. int wx, wy, ww, wh;
  197321. Image* taskbarImage;
  197322. bool fullScreen, entered, mapped, depthIs16Bit;
  197323. BorderSize windowBorder;
  197324. struct MotifWmHints
  197325. {
  197326. unsigned long flags;
  197327. unsigned long functions;
  197328. unsigned long decorations;
  197329. long input_mode;
  197330. unsigned long status;
  197331. };
  197332. void removeWindowDecorations (Window wndH)
  197333. {
  197334. Atom hints = XInternAtom (display, "_MOTIF_WM_HINTS", True);
  197335. if (hints != None)
  197336. {
  197337. MotifWmHints motifHints;
  197338. zerostruct (motifHints);
  197339. motifHints.flags = 2; /* MWM_HINTS_DECORATIONS */
  197340. motifHints.decorations = 0;
  197341. ScopedXLock xlock;
  197342. XChangeProperty (display, wndH, hints, hints, 32, PropModeReplace,
  197343. (unsigned char*) &motifHints, 4);
  197344. }
  197345. hints = XInternAtom (display, "_WIN_HINTS", True);
  197346. if (hints != None)
  197347. {
  197348. long gnomeHints = 0;
  197349. ScopedXLock xlock;
  197350. XChangeProperty (display, wndH, hints, hints, 32, PropModeReplace,
  197351. (unsigned char*) &gnomeHints, 1);
  197352. }
  197353. hints = XInternAtom (display, "KWM_WIN_DECORATION", True);
  197354. if (hints != None)
  197355. {
  197356. long kwmHints = 2; /*KDE_tinyDecoration*/
  197357. ScopedXLock xlock;
  197358. XChangeProperty (display, wndH, hints, hints, 32, PropModeReplace,
  197359. (unsigned char*) &kwmHints, 1);
  197360. }
  197361. hints = XInternAtom (display, "_NET_WM_WINDOW_TYPE", True);
  197362. if (hints != None)
  197363. {
  197364. ScopedXLock xlock;
  197365. int netHints [2];
  197366. int numHints = 0;
  197367. if ((styleFlags & windowIsTemporary) != 0)
  197368. netHints [numHints] = XInternAtom (display, "_NET_WM_WINDOW_TYPE_MENU", True);
  197369. else
  197370. netHints [numHints] = XInternAtom (display, "_NET_WM_WINDOW_TYPE_NORMAL", True);
  197371. if (netHints [numHints] != 0)
  197372. ++numHints;
  197373. netHints[numHints] = XInternAtom (display, "_KDE_NET_WM_WINDOW_TYPE_OVERRIDE", True);
  197374. if (netHints [numHints] != 0)
  197375. ++numHints;
  197376. XChangeProperty (display, wndH, hints, XA_ATOM, 32, PropModeReplace,
  197377. (unsigned char*) &netHints, numHints);
  197378. }
  197379. }
  197380. void addWindowButtons (Window wndH)
  197381. {
  197382. ScopedXLock xlock;
  197383. Atom hints = XInternAtom (display, "_MOTIF_WM_HINTS", True);
  197384. if (hints != None)
  197385. {
  197386. MotifWmHints motifHints;
  197387. zerostruct (motifHints);
  197388. motifHints.flags = 1 | 2; /* MWM_HINTS_FUNCTIONS | MWM_HINTS_DECORATIONS */
  197389. motifHints.decorations = 2 /* MWM_DECOR_BORDER */ | 8 /* MWM_DECOR_TITLE */ | 16; /* MWM_DECOR_MENU */
  197390. motifHints.functions = 4 /* MWM_FUNC_MOVE */;
  197391. if ((styleFlags & windowHasCloseButton) != 0)
  197392. motifHints.functions |= 32; /* MWM_FUNC_CLOSE */
  197393. if ((styleFlags & windowHasMinimiseButton) != 0)
  197394. {
  197395. motifHints.functions |= 8; /* MWM_FUNC_MINIMIZE */
  197396. motifHints.decorations |= 0x20; /* MWM_DECOR_MINIMIZE */
  197397. }
  197398. if ((styleFlags & windowHasMaximiseButton) != 0)
  197399. {
  197400. motifHints.functions |= 0x10; /* MWM_FUNC_MAXIMIZE */
  197401. motifHints.decorations |= 0x40; /* MWM_DECOR_MAXIMIZE */
  197402. }
  197403. if ((styleFlags & windowIsResizable) != 0)
  197404. {
  197405. motifHints.functions |= 2; /* MWM_FUNC_RESIZE */
  197406. motifHints.decorations |= 0x4; /* MWM_DECOR_RESIZEH */
  197407. }
  197408. XChangeProperty (display, wndH, hints, hints, 32, 0, (unsigned char*) &motifHints, 5);
  197409. }
  197410. hints = XInternAtom (display, "_NET_WM_ALLOWED_ACTIONS", True);
  197411. if (hints != None)
  197412. {
  197413. int netHints [6];
  197414. int num = 0;
  197415. netHints [num++] = XInternAtom (display, "_NET_WM_ACTION_RESIZE", (styleFlags & windowIsResizable) ? True : False);
  197416. netHints [num++] = XInternAtom (display, "_NET_WM_ACTION_FULLSCREEN", (styleFlags & windowHasMaximiseButton) ? True : False);
  197417. netHints [num++] = XInternAtom (display, "_NET_WM_ACTION_MINIMIZE", (styleFlags & windowHasMinimiseButton) ? True : False);
  197418. netHints [num++] = XInternAtom (display, "_NET_WM_ACTION_CLOSE", (styleFlags & windowHasCloseButton) ? True : False);
  197419. XChangeProperty (display, wndH, hints, XA_ATOM, 32, PropModeReplace,
  197420. (unsigned char*) &netHints, num);
  197421. }
  197422. }
  197423. void createWindow()
  197424. {
  197425. ScopedXLock xlock;
  197426. static bool atomsInitialised = false;
  197427. if (! atomsInitialised)
  197428. {
  197429. atomsInitialised = true;
  197430. wm_Protocols = XInternAtom (display, "WM_PROTOCOLS", 1);
  197431. wm_ProtocolList [TAKE_FOCUS] = XInternAtom (display, "WM_TAKE_FOCUS", 1);
  197432. wm_ProtocolList [DELETE_WINDOW] = XInternAtom (display, "WM_DELETE_WINDOW", 1);
  197433. wm_ChangeState = XInternAtom (display, "WM_CHANGE_STATE", 1);
  197434. wm_State = XInternAtom (display, "WM_STATE", 1);
  197435. wm_ActiveWin = XInternAtom (display, "_NET_ACTIVE_WINDOW", False);
  197436. XA_XdndAware = XInternAtom (display, "XdndAware", 0);
  197437. XA_XdndEnter = XInternAtom (display, "XdndEnter", 0);
  197438. XA_XdndLeave = XInternAtom (display, "XdndLeave", 0);
  197439. XA_XdndPosition = XInternAtom (display, "XdndPosition", 0);
  197440. XA_XdndStatus = XInternAtom (display, "XdndStatus", 0);
  197441. XA_XdndDrop = XInternAtom (display, "XdndDrop", 0);
  197442. XA_XdndFinished = XInternAtom (display, "XdndFinished", 0);
  197443. XA_XdndSelection = XInternAtom (display, "XdndSelection", 0);
  197444. XA_XdndProxy = XInternAtom (display, "XdndProxy", 0);
  197445. XA_XdndTypeList = XInternAtom (display, "XdndTypeList", 0);
  197446. XA_XdndActionList = XInternAtom (display, "XdndActionList", 0);
  197447. XA_XdndActionCopy = XInternAtom (display, "XdndActionCopy", 0);
  197448. XA_XdndActionMove = XInternAtom (display, "XdndActionMove", 0);
  197449. XA_XdndActionLink = XInternAtom (display, "XdndActionLink", 0);
  197450. XA_XdndActionAsk = XInternAtom (display, "XdndActionAsk", 0);
  197451. XA_XdndActionPrivate = XInternAtom (display, "XdndActionPrivate", 0);
  197452. XA_XdndActionDescription = XInternAtom (display, "XdndActionDescription", 0);
  197453. XA_JXSelectionWindowProperty = XInternAtom (display, "JXSelectionWindowProperty", 0);
  197454. XA_MimeTextPlain = XInternAtom (display, "text/plain", 0);
  197455. XA_MimeTextUriList = XInternAtom (display, "text/uri-list", 0);
  197456. XA_MimeRootDrop = XInternAtom (display, "application/x-rootwindow-drop", 0);
  197457. }
  197458. resetDragAndDrop();
  197459. XA_OtherMime = XA_MimeTextPlain; // xxx why??
  197460. allowedMimeTypeAtoms [0] = XA_MimeTextPlain;
  197461. allowedMimeTypeAtoms [1] = XA_OtherMime;
  197462. allowedMimeTypeAtoms [2] = XA_MimeTextUriList;
  197463. allowedActions [0] = XA_XdndActionMove;
  197464. allowedActions [1] = XA_XdndActionCopy;
  197465. allowedActions [2] = XA_XdndActionLink;
  197466. allowedActions [3] = XA_XdndActionAsk;
  197467. allowedActions [4] = XA_XdndActionPrivate;
  197468. // Get defaults for various properties
  197469. const int screen = DefaultScreen (display);
  197470. Window root = RootWindow (display, screen);
  197471. // Attempt to create a 24-bit window on the default screen. If this is not
  197472. // possible then exit
  197473. XVisualInfo desiredVisual;
  197474. desiredVisual.screen = screen;
  197475. desiredVisual.depth = 24;
  197476. depthIs16Bit = false;
  197477. int numVisuals;
  197478. XVisualInfo* visuals = XGetVisualInfo (display, VisualScreenMask | VisualDepthMask,
  197479. &desiredVisual, &numVisuals);
  197480. if (numVisuals < 1 || visuals == 0)
  197481. {
  197482. XFree (visuals);
  197483. desiredVisual.depth = 16;
  197484. visuals = XGetVisualInfo (display, VisualScreenMask | VisualDepthMask,
  197485. &desiredVisual, &numVisuals);
  197486. if (numVisuals < 1 || visuals == 0)
  197487. {
  197488. Logger::outputDebugString ("ERROR: System doesn't support 24 or 16 bit RGB display.\n");
  197489. Process::terminate();
  197490. }
  197491. depthIs16Bit = true;
  197492. }
  197493. XFree (visuals);
  197494. // Set up the window attributes
  197495. XSetWindowAttributes swa;
  197496. swa.border_pixel = 0;
  197497. swa.background_pixmap = None;
  197498. swa.colormap = DefaultColormap (display, screen);
  197499. swa.override_redirect = getComponent()->isAlwaysOnTop() ? True : False;
  197500. swa.event_mask = eventMask;
  197501. Window wndH = XCreateWindow (display, root,
  197502. 0, 0, 1, 1,
  197503. 0, 0, InputOutput, (Visual*) CopyFromParent,
  197504. CWBorderPixel | CWColormap | CWBackPixmap | CWEventMask | CWOverrideRedirect,
  197505. &swa);
  197506. XGrabButton (display, AnyButton, AnyModifier, wndH, False,
  197507. ButtonPressMask | ButtonReleaseMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask,
  197508. GrabModeAsync, GrabModeAsync, None, None);
  197509. // Set the window context to identify the window handle object
  197510. if (XSaveContext (display, (XID) wndH, improbableNumber, (XPointer) this))
  197511. {
  197512. // Failed
  197513. jassertfalse
  197514. Logger::outputDebugString ("Failed to create context information for window.\n");
  197515. XDestroyWindow (display, wndH);
  197516. wndH = 0;
  197517. }
  197518. // Set window manager hints
  197519. XWMHints* wmHints = XAllocWMHints();
  197520. wmHints->flags = InputHint | StateHint;
  197521. wmHints->input = True; // Locally active input model
  197522. wmHints->initial_state = NormalState;
  197523. XSetWMHints (display, wndH, wmHints);
  197524. XFree (wmHints);
  197525. if ((styleFlags & windowIsSemiTransparent) != 0)
  197526. {
  197527. //xxx
  197528. }
  197529. if ((styleFlags & windowAppearsOnTaskbar) != 0)
  197530. {
  197531. //xxx
  197532. }
  197533. //XSetTransientForHint (display, wndH, RootWindow (display, DefaultScreen (display)));
  197534. if ((styleFlags & windowHasTitleBar) == 0)
  197535. removeWindowDecorations (wndH);
  197536. else
  197537. addWindowButtons (wndH);
  197538. // Set window manager protocols
  197539. XChangeProperty (display, wndH, wm_Protocols, XA_ATOM, 32, PropModeReplace,
  197540. (unsigned char*) wm_ProtocolList, 2);
  197541. // Set drag and drop flags
  197542. XChangeProperty (display, wndH, XA_XdndTypeList, XA_ATOM, 32, PropModeReplace,
  197543. (const unsigned char*) allowedMimeTypeAtoms, numElementsInArray (allowedMimeTypeAtoms));
  197544. XChangeProperty (display, wndH, XA_XdndActionList, XA_ATOM, 32, PropModeReplace,
  197545. (const unsigned char*) allowedActions, numElementsInArray (allowedActions));
  197546. XChangeProperty (display, wndH, XA_XdndActionDescription, XA_STRING, 8, PropModeReplace,
  197547. (const unsigned char*) "", 0);
  197548. unsigned long dndVersion = ourDndVersion;
  197549. XChangeProperty (display, wndH, XA_XdndAware, XA_ATOM, 32, PropModeReplace,
  197550. (const unsigned char*) &dndVersion, 1);
  197551. // Set window name
  197552. setWindowTitle (wndH, getComponent()->getName());
  197553. // Initialise the pointer and keyboard mapping
  197554. // This is not the same as the logical pointer mapping the X server uses:
  197555. // we don't mess with this.
  197556. static bool mappingInitialised = false;
  197557. if (! mappingInitialised)
  197558. {
  197559. mappingInitialised = true;
  197560. const int numButtons = XGetPointerMapping (display, 0, 0);
  197561. if (numButtons == 2)
  197562. {
  197563. pointerMap[0] = LeftButton;
  197564. pointerMap[1] = RightButton;
  197565. pointerMap[2] = pointerMap[3] = pointerMap[4] = NoButton;
  197566. }
  197567. else if (numButtons >= 3)
  197568. {
  197569. pointerMap[0] = LeftButton;
  197570. pointerMap[1] = MiddleButton;
  197571. pointerMap[2] = RightButton;
  197572. if (numButtons >= 5)
  197573. {
  197574. pointerMap[3] = WheelUp;
  197575. pointerMap[4] = WheelDown;
  197576. }
  197577. }
  197578. getModifierMapping();
  197579. }
  197580. windowH = wndH;
  197581. }
  197582. void destroyWindow()
  197583. {
  197584. ScopedXLock xlock;
  197585. XPointer handlePointer;
  197586. if (! XFindContext (display, (XID) windowH, improbableNumber, &handlePointer))
  197587. XDeleteContext (display, (XID) windowH, improbableNumber);
  197588. XDestroyWindow (display, windowH);
  197589. // Wait for it to complete and then remove any events for this
  197590. // window from the event queue.
  197591. XSync (display, false);
  197592. XEvent event;
  197593. while (XCheckWindowEvent (display, windowH, eventMask, &event) == True)
  197594. {}
  197595. }
  197596. static int64 getEventTime (::Time t) throw()
  197597. {
  197598. static int64 eventTimeOffset = 0x12345678;
  197599. const int64 thisMessageTime = t;
  197600. if (eventTimeOffset == 0x12345678)
  197601. eventTimeOffset = Time::currentTimeMillis() - thisMessageTime;
  197602. return eventTimeOffset + thisMessageTime;
  197603. }
  197604. static void setWindowTitle (Window xwin, const char* const title) throw()
  197605. {
  197606. XTextProperty nameProperty;
  197607. char* strings[] = { (char*) title };
  197608. ScopedXLock xlock;
  197609. if (XStringListToTextProperty (strings, 1, &nameProperty))
  197610. {
  197611. XSetWMName (display, xwin, &nameProperty);
  197612. XSetWMIconName (display, xwin, &nameProperty);
  197613. XFree (nameProperty.value);
  197614. }
  197615. }
  197616. void updateBorderSize()
  197617. {
  197618. if ((styleFlags & windowHasTitleBar) == 0)
  197619. {
  197620. windowBorder = BorderSize (0);
  197621. }
  197622. else if (windowBorder.getTopAndBottom() == 0 && windowBorder.getLeftAndRight() == 0)
  197623. {
  197624. ScopedXLock xlock;
  197625. Atom hints = XInternAtom (display, "_NET_FRAME_EXTENTS", True);
  197626. if (hints != None)
  197627. {
  197628. unsigned char* data = 0;
  197629. unsigned long nitems, bytesLeft;
  197630. Atom actualType;
  197631. int actualFormat;
  197632. if (XGetWindowProperty (display, windowH, hints, 0, 4, False,
  197633. XA_CARDINAL, &actualType, &actualFormat, &nitems, &bytesLeft,
  197634. &data) == Success)
  197635. {
  197636. const unsigned long* const sizes = (const unsigned long*) data;
  197637. if (actualFormat == 32)
  197638. windowBorder = BorderSize ((int) sizes[2], (int) sizes[0],
  197639. (int) sizes[3], (int) sizes[1]);
  197640. XFree (data);
  197641. }
  197642. }
  197643. }
  197644. }
  197645. void updateBounds()
  197646. {
  197647. jassert (windowH != 0);
  197648. if (windowH != 0)
  197649. {
  197650. Window root, child;
  197651. unsigned int bw, depth;
  197652. ScopedXLock xlock;
  197653. if (! XGetGeometry (display, (::Drawable) windowH, &root,
  197654. &wx, &wy, (unsigned int*) &ww, (unsigned int*) &wh,
  197655. &bw, &depth))
  197656. {
  197657. wx = wy = ww = wh = 0;
  197658. }
  197659. else if (! XTranslateCoordinates (display, windowH, root, 0, 0, &wx, &wy, &child))
  197660. {
  197661. wx = wy = 0;
  197662. }
  197663. }
  197664. }
  197665. void resetDragAndDrop()
  197666. {
  197667. dragAndDropFiles.clear();
  197668. lastDropX = lastDropY = -1;
  197669. dragAndDropCurrentMimeType = 0;
  197670. dragAndDropSourceWindow = 0;
  197671. srcMimeTypeAtomList.clear();
  197672. }
  197673. void sendDragAndDropMessage (XClientMessageEvent& msg)
  197674. {
  197675. msg.type = ClientMessage;
  197676. msg.display = display;
  197677. msg.window = dragAndDropSourceWindow;
  197678. msg.format = 32;
  197679. msg.data.l[0] = windowH;
  197680. ScopedXLock xlock;
  197681. XSendEvent (display, dragAndDropSourceWindow, False, 0, (XEvent*) &msg);
  197682. }
  197683. void sendDragAndDropStatus (const bool acceptDrop, Atom dropAction)
  197684. {
  197685. XClientMessageEvent msg;
  197686. zerostruct (msg);
  197687. msg.message_type = XA_XdndStatus;
  197688. msg.data.l[1] = (acceptDrop ? 1 : 0) | 2; // 2 indicates that we want to receive position messages
  197689. msg.data.l[4] = dropAction;
  197690. sendDragAndDropMessage (msg);
  197691. }
  197692. void sendDragAndDropLeave()
  197693. {
  197694. XClientMessageEvent msg;
  197695. zerostruct (msg);
  197696. msg.message_type = XA_XdndLeave;
  197697. sendDragAndDropMessage (msg);
  197698. }
  197699. void sendDragAndDropFinish()
  197700. {
  197701. XClientMessageEvent msg;
  197702. zerostruct (msg);
  197703. msg.message_type = XA_XdndFinished;
  197704. sendDragAndDropMessage (msg);
  197705. }
  197706. void handleDragAndDropStatus (const XClientMessageEvent* const clientMsg)
  197707. {
  197708. if ((clientMsg->data.l[1] & 1) == 0)
  197709. {
  197710. sendDragAndDropLeave();
  197711. if (dragAndDropFiles.size() > 0)
  197712. handleFileDragExit (dragAndDropFiles);
  197713. dragAndDropFiles.clear();
  197714. }
  197715. }
  197716. void handleDragAndDropPosition (const XClientMessageEvent* const clientMsg)
  197717. {
  197718. if (dragAndDropSourceWindow == 0)
  197719. return;
  197720. dragAndDropSourceWindow = clientMsg->data.l[0];
  197721. const int dropX = ((int) clientMsg->data.l[2] >> 16) - getScreenX();
  197722. const int dropY = ((int) clientMsg->data.l[2] & 0xffff) - getScreenY();
  197723. if (lastDropX != dropX || lastDropY != dropY)
  197724. {
  197725. lastDropX = dropX;
  197726. lastDropY = dropY;
  197727. dragAndDropTimestamp = clientMsg->data.l[3];
  197728. Atom targetAction = XA_XdndActionCopy;
  197729. for (int i = numElementsInArray (allowedActions); --i >= 0;)
  197730. {
  197731. if ((Atom) clientMsg->data.l[4] == allowedActions[i])
  197732. {
  197733. targetAction = allowedActions[i];
  197734. break;
  197735. }
  197736. }
  197737. sendDragAndDropStatus (true, targetAction);
  197738. if (dragAndDropFiles.size() == 0)
  197739. updateDraggedFileList (clientMsg);
  197740. if (dragAndDropFiles.size() > 0)
  197741. handleFileDragMove (dragAndDropFiles, dropX, dropY);
  197742. }
  197743. }
  197744. void handleDragAndDropDrop (const XClientMessageEvent* const clientMsg)
  197745. {
  197746. if (dragAndDropFiles.size() == 0)
  197747. updateDraggedFileList (clientMsg);
  197748. const StringArray files (dragAndDropFiles);
  197749. const int lastX = lastDropX, lastY = lastDropY;
  197750. sendDragAndDropFinish();
  197751. resetDragAndDrop();
  197752. if (files.size() > 0)
  197753. handleFileDragDrop (files, lastX, lastY);
  197754. }
  197755. void handleDragAndDropEnter (const XClientMessageEvent* const clientMsg)
  197756. {
  197757. dragAndDropFiles.clear();
  197758. srcMimeTypeAtomList.clear();
  197759. dragAndDropCurrentMimeType = 0;
  197760. const int dndCurrentVersion = (int) (clientMsg->data.l[1] & 0xff000000) >> 24;
  197761. if (dndCurrentVersion < 3 || dndCurrentVersion > ourDndVersion)
  197762. {
  197763. dragAndDropSourceWindow = 0;
  197764. return;
  197765. }
  197766. dragAndDropSourceWindow = clientMsg->data.l[0];
  197767. if ((clientMsg->data.l[1] & 1) != 0)
  197768. {
  197769. Atom actual;
  197770. int format;
  197771. unsigned long count = 0, remaining = 0;
  197772. unsigned char* data = 0;
  197773. ScopedXLock xlock;
  197774. XGetWindowProperty (display, dragAndDropSourceWindow, XA_XdndTypeList,
  197775. 0, 0x8000000L, False, XA_ATOM, &actual, &format,
  197776. &count, &remaining, &data);
  197777. if (data != 0)
  197778. {
  197779. if (actual == XA_ATOM && format == 32 && count != 0)
  197780. {
  197781. const unsigned long* const types = (const unsigned long*) data;
  197782. for (unsigned int i = 0; i < count; ++i)
  197783. if (types[i] != None)
  197784. srcMimeTypeAtomList.add (types[i]);
  197785. }
  197786. XFree (data);
  197787. }
  197788. }
  197789. if (srcMimeTypeAtomList.size() == 0)
  197790. {
  197791. for (int i = 2; i < 5; ++i)
  197792. if (clientMsg->data.l[i] != None)
  197793. srcMimeTypeAtomList.add (clientMsg->data.l[i]);
  197794. if (srcMimeTypeAtomList.size() == 0)
  197795. {
  197796. dragAndDropSourceWindow = 0;
  197797. return;
  197798. }
  197799. }
  197800. for (int i = 0; i < srcMimeTypeAtomList.size() && dragAndDropCurrentMimeType == 0; ++i)
  197801. for (int j = 0; j < numElementsInArray (allowedMimeTypeAtoms); ++j)
  197802. if (srcMimeTypeAtomList[i] == allowedMimeTypeAtoms[j])
  197803. dragAndDropCurrentMimeType = allowedMimeTypeAtoms[j];
  197804. handleDragAndDropPosition (clientMsg);
  197805. }
  197806. void handleDragAndDropSelection (const XEvent* const evt)
  197807. {
  197808. dragAndDropFiles.clear();
  197809. if (evt->xselection.property != 0)
  197810. {
  197811. StringArray lines;
  197812. {
  197813. MemoryBlock dropData;
  197814. for (;;)
  197815. {
  197816. Atom actual;
  197817. uint8* data = 0;
  197818. unsigned long count = 0, remaining = 0;
  197819. int format = 0;
  197820. ScopedXLock xlock;
  197821. if (XGetWindowProperty (display, evt->xany.window, evt->xselection.property,
  197822. dropData.getSize() / 4, 65536, 1, AnyPropertyType, &actual,
  197823. &format, &count, &remaining, &data) == Success)
  197824. {
  197825. dropData.append (data, count * format / 8);
  197826. XFree (data);
  197827. if (remaining == 0)
  197828. break;
  197829. }
  197830. else
  197831. {
  197832. XFree (data);
  197833. break;
  197834. }
  197835. }
  197836. lines.addLines (dropData.toString());
  197837. }
  197838. for (int i = 0; i < lines.size(); ++i)
  197839. dragAndDropFiles.add (URL::removeEscapeChars (lines[i].fromFirstOccurrenceOf (T("file://"), false, true)));
  197840. dragAndDropFiles.trim();
  197841. dragAndDropFiles.removeEmptyStrings();
  197842. }
  197843. }
  197844. void updateDraggedFileList (const XClientMessageEvent* const clientMsg)
  197845. {
  197846. dragAndDropFiles.clear();
  197847. if (dragAndDropSourceWindow != None
  197848. && dragAndDropCurrentMimeType != 0)
  197849. {
  197850. dragAndDropTimestamp = clientMsg->data.l[2];
  197851. ScopedXLock xlock;
  197852. XConvertSelection (display,
  197853. XA_XdndSelection,
  197854. dragAndDropCurrentMimeType,
  197855. XA_JXSelectionWindowProperty,
  197856. windowH,
  197857. dragAndDropTimestamp);
  197858. }
  197859. }
  197860. StringArray dragAndDropFiles;
  197861. int dragAndDropTimestamp, lastDropX, lastDropY;
  197862. Atom XA_OtherMime, dragAndDropCurrentMimeType;
  197863. Window dragAndDropSourceWindow;
  197864. unsigned int allowedActions [5];
  197865. unsigned int allowedMimeTypeAtoms [3];
  197866. Array <Atom> srcMimeTypeAtomList;
  197867. };
  197868. void juce_setKioskComponent (Component* kioskModeComponent, bool enableOrDisable, bool allowMenusAndBars)
  197869. {
  197870. if (enableOrDisable)
  197871. kioskModeComponent->setBounds (Desktop::getInstance().getMainMonitorArea (false));
  197872. }
  197873. ComponentPeer* Component::createNewPeer (int styleFlags, void* /*nativeWindowToAttachTo*/)
  197874. {
  197875. return new LinuxComponentPeer (this, styleFlags);
  197876. }
  197877. // (this callback is hooked up in the messaging code)
  197878. void juce_windowMessageReceive (XEvent* event)
  197879. {
  197880. if (event->xany.window != None)
  197881. {
  197882. LinuxComponentPeer* const peer = LinuxComponentPeer::getPeerFor (event->xany.window);
  197883. if (ComponentPeer::isValidPeer (peer))
  197884. peer->handleWindowMessage (event);
  197885. }
  197886. else
  197887. {
  197888. switch (event->xany.type)
  197889. {
  197890. case KeymapNotify:
  197891. {
  197892. const XKeymapEvent* const keymapEvent = (const XKeymapEvent*) &event->xkeymap;
  197893. memcpy (keyStates, keymapEvent->key_vector, 32);
  197894. break;
  197895. }
  197896. default:
  197897. break;
  197898. }
  197899. }
  197900. }
  197901. void juce_updateMultiMonitorInfo (Array <Rectangle>& monitorCoords, const bool /*clipToWorkArea*/)
  197902. {
  197903. if (display == 0)
  197904. return;
  197905. #if JUCE_USE_XINERAMA
  197906. int major_opcode, first_event, first_error;
  197907. ScopedXLock xlock;
  197908. if (XQueryExtension (display, "XINERAMA", &major_opcode, &first_event, &first_error))
  197909. {
  197910. typedef Bool (*tXineramaIsActive) (Display*);
  197911. typedef XineramaScreenInfo* (*tXineramaQueryScreens) (Display*, int*);
  197912. static tXineramaIsActive xXineramaIsActive = 0;
  197913. static tXineramaQueryScreens xXineramaQueryScreens = 0;
  197914. if (xXineramaIsActive == 0 || xXineramaQueryScreens == 0)
  197915. {
  197916. void* h = dlopen ("libXinerama.so", RTLD_GLOBAL | RTLD_NOW);
  197917. if (h != 0)
  197918. {
  197919. xXineramaIsActive = (tXineramaIsActive) dlsym (h, "XineramaIsActive");
  197920. xXineramaQueryScreens = (tXineramaQueryScreens) dlsym (h, "XineramaQueryScreens");
  197921. }
  197922. }
  197923. if (xXineramaIsActive != 0
  197924. && xXineramaQueryScreens != 0
  197925. && xXineramaIsActive (display))
  197926. {
  197927. int numMonitors = 0;
  197928. XineramaScreenInfo* const screens = xXineramaQueryScreens (display, &numMonitors);
  197929. if (screens != 0)
  197930. {
  197931. for (int i = numMonitors; --i >= 0;)
  197932. {
  197933. int index = screens[i].screen_number;
  197934. if (index >= 0)
  197935. {
  197936. while (monitorCoords.size() < index)
  197937. monitorCoords.add (Rectangle (0, 0, 0, 0));
  197938. monitorCoords.set (index, Rectangle (screens[i].x_org,
  197939. screens[i].y_org,
  197940. screens[i].width,
  197941. screens[i].height));
  197942. }
  197943. }
  197944. XFree (screens);
  197945. }
  197946. }
  197947. }
  197948. if (monitorCoords.size() == 0)
  197949. #endif
  197950. {
  197951. Atom hints = XInternAtom (display, "_NET_WORKAREA", True);
  197952. if (hints != None)
  197953. {
  197954. const int numMonitors = ScreenCount (display);
  197955. for (int i = 0; i < numMonitors; ++i)
  197956. {
  197957. Window root = RootWindow (display, i);
  197958. unsigned long nitems, bytesLeft;
  197959. Atom actualType;
  197960. int actualFormat;
  197961. unsigned char* data = 0;
  197962. if (XGetWindowProperty (display, root, hints, 0, 4, False,
  197963. XA_CARDINAL, &actualType, &actualFormat, &nitems, &bytesLeft,
  197964. &data) == Success)
  197965. {
  197966. const long* const position = (const long*) data;
  197967. if (actualType == XA_CARDINAL && actualFormat == 32 && nitems == 4)
  197968. monitorCoords.add (Rectangle (position[0], position[1],
  197969. position[2], position[3]));
  197970. XFree (data);
  197971. }
  197972. }
  197973. }
  197974. if (monitorCoords.size() == 0)
  197975. {
  197976. monitorCoords.add (Rectangle (0, 0,
  197977. DisplayWidth (display, DefaultScreen (display)),
  197978. DisplayHeight (display, DefaultScreen (display))));
  197979. }
  197980. }
  197981. }
  197982. bool Desktop::canUseSemiTransparentWindows() throw()
  197983. {
  197984. return false;
  197985. }
  197986. void Desktop::getMousePosition (int& x, int& y) throw()
  197987. {
  197988. int mouseMods;
  197989. getMousePos (x, y, mouseMods);
  197990. }
  197991. void Desktop::setMousePosition (int x, int y) throw()
  197992. {
  197993. ScopedXLock xlock;
  197994. Window root = RootWindow (display, DefaultScreen (display));
  197995. XWarpPointer (display, None, root, 0, 0, 0, 0, x, y);
  197996. }
  197997. static bool screenSaverAllowed = true;
  197998. void Desktop::setScreenSaverEnabled (const bool isEnabled) throw()
  197999. {
  198000. if (screenSaverAllowed != isEnabled)
  198001. {
  198002. screenSaverAllowed = isEnabled;
  198003. typedef void (*tXScreenSaverSuspend) (Display*, Bool);
  198004. static tXScreenSaverSuspend xScreenSaverSuspend = 0;
  198005. if (xScreenSaverSuspend == 0)
  198006. {
  198007. void* h = dlopen ("libXss.so", RTLD_GLOBAL | RTLD_NOW);
  198008. if (h != 0)
  198009. xScreenSaverSuspend = (tXScreenSaverSuspend) dlsym (h, "XScreenSaverSuspend");
  198010. }
  198011. ScopedXLock xlock;
  198012. if (xScreenSaverSuspend != 0)
  198013. xScreenSaverSuspend (display, ! isEnabled);
  198014. }
  198015. }
  198016. bool Desktop::isScreenSaverEnabled() throw()
  198017. {
  198018. return screenSaverAllowed;
  198019. }
  198020. void* juce_createMouseCursorFromImage (const Image& image, int hotspotX, int hotspotY) throw()
  198021. {
  198022. ScopedXLock xlock;
  198023. Window root = RootWindow (display, DefaultScreen (display));
  198024. const unsigned int imageW = image.getWidth();
  198025. const unsigned int imageH = image.getHeight();
  198026. unsigned int cursorW, cursorH;
  198027. if (! XQueryBestCursor (display, root, imageW, imageH, &cursorW, &cursorH))
  198028. return 0;
  198029. Image im (Image::ARGB, cursorW, cursorH, true);
  198030. Graphics g (im);
  198031. if (imageW > cursorW || imageH > cursorH)
  198032. {
  198033. hotspotX = (hotspotX * cursorW) / imageW;
  198034. hotspotY = (hotspotY * cursorH) / imageH;
  198035. g.drawImageWithin (&image, 0, 0, imageW, imageH,
  198036. RectanglePlacement::xLeft | RectanglePlacement::yTop | RectanglePlacement::onlyReduceInSize,
  198037. false);
  198038. }
  198039. else
  198040. {
  198041. g.drawImageAt (&image, 0, 0);
  198042. }
  198043. const int stride = (cursorW + 7) >> 3;
  198044. HeapBlock <uint8> maskPlane, sourcePlane;
  198045. maskPlane.calloc (stride * cursorH);
  198046. sourcePlane.calloc (stride * cursorH);
  198047. const bool msbfirst = (BitmapBitOrder (display) == MSBFirst);
  198048. for (int y = cursorH; --y >= 0;)
  198049. {
  198050. for (int x = cursorW; --x >= 0;)
  198051. {
  198052. const uint8 mask = (uint8) (1 << (msbfirst ? (7 - (x & 7)) : (x & 7)));
  198053. const int offset = y * stride + (x >> 3);
  198054. const Colour c (im.getPixelAt (x, y));
  198055. if (c.getAlpha() >= 128)
  198056. maskPlane[offset] |= mask;
  198057. if (c.getBrightness() >= 0.5f)
  198058. sourcePlane[offset] |= mask;
  198059. }
  198060. }
  198061. Pixmap sourcePixmap = XCreatePixmapFromBitmapData (display, root, (char*) sourcePlane, cursorW, cursorH, 0xffff, 0, 1);
  198062. Pixmap maskPixmap = XCreatePixmapFromBitmapData (display, root, (char*) maskPlane, cursorW, cursorH, 0xffff, 0, 1);
  198063. XColor white, black;
  198064. black.red = black.green = black.blue = 0;
  198065. white.red = white.green = white.blue = 0xffff;
  198066. void* result = (void*) XCreatePixmapCursor (display, sourcePixmap, maskPixmap, &white, &black, hotspotX, hotspotY);
  198067. XFreePixmap (display, sourcePixmap);
  198068. XFreePixmap (display, maskPixmap);
  198069. return result;
  198070. }
  198071. void juce_deleteMouseCursor (void* const cursorHandle, const bool) throw()
  198072. {
  198073. ScopedXLock xlock;
  198074. if (cursorHandle != None)
  198075. XFreeCursor (display, (Cursor) cursorHandle);
  198076. }
  198077. void* juce_createStandardMouseCursor (MouseCursor::StandardCursorType type) throw()
  198078. {
  198079. unsigned int shape;
  198080. switch (type)
  198081. {
  198082. case MouseCursor::NoCursor:
  198083. {
  198084. const Image im (Image::ARGB, 16, 16, true);
  198085. return juce_createMouseCursorFromImage (im, 0, 0);
  198086. }
  198087. case MouseCursor::NormalCursor:
  198088. return (void*) None; // Use parent cursor
  198089. case MouseCursor::DraggingHandCursor:
  198090. {
  198091. static unsigned char dragHandData[] = {71,73,70,56,57,97,16,0,16,0,145,2,0,0,0,0,255,255,255,0,
  198092. 0,0,0,0,0,33,249,4,1,0,0,2,0,44,0,0,0,0,16,0,
  198093. 16,0,0,2,52,148,47,0,200,185,16,130,90,12,74,139,107,84,123,39,
  198094. 132,117,151,116,132,146,248,60,209,138,98,22,203,114,34,236,37,52,77,217,
  198095. 247,154,191,119,110,240,193,128,193,95,163,56,60,234,98,135,2,0,59 };
  198096. const int dragHandDataSize = 99;
  198097. const ScopedPointer <Image> im (ImageFileFormat::loadFrom ((const char*) dragHandData, dragHandDataSize));
  198098. return juce_createMouseCursorFromImage (*im, 8, 7);
  198099. }
  198100. case MouseCursor::CopyingCursor:
  198101. {
  198102. static unsigned char copyCursorData[] = {71,73,70,56,57,97,21,0,21,0,145,0,0,0,0,0,255,255,255,0,
  198103. 128,128,255,255,255,33,249,4,1,0,0,3,0,44,0,0,0,0,21,0,
  198104. 21,0,0,2,72,4,134,169,171,16,199,98,11,79,90,71,161,93,56,111,
  198105. 78,133,218,215,137,31,82,154,100,200,86,91,202,142,12,108,212,87,235,174,
  198106. 15,54,214,126,237,226,37,96,59,141,16,37,18,201,142,157,230,204,51,112,
  198107. 252,114,147,74,83,5,50,68,147,208,217,16,71,149,252,124,5,0,59,0,0 };
  198108. const int copyCursorSize = 119;
  198109. const ScopedPointer <Image> im (ImageFileFormat::loadFrom ((const char*) copyCursorData, copyCursorSize));
  198110. return juce_createMouseCursorFromImage (*im, 1, 3);
  198111. }
  198112. case MouseCursor::WaitCursor:
  198113. shape = XC_watch;
  198114. break;
  198115. case MouseCursor::IBeamCursor:
  198116. shape = XC_xterm;
  198117. break;
  198118. case MouseCursor::PointingHandCursor:
  198119. shape = XC_hand2;
  198120. break;
  198121. case MouseCursor::LeftRightResizeCursor:
  198122. shape = XC_sb_h_double_arrow;
  198123. break;
  198124. case MouseCursor::UpDownResizeCursor:
  198125. shape = XC_sb_v_double_arrow;
  198126. break;
  198127. case MouseCursor::UpDownLeftRightResizeCursor:
  198128. shape = XC_fleur;
  198129. break;
  198130. case MouseCursor::TopEdgeResizeCursor:
  198131. shape = XC_top_side;
  198132. break;
  198133. case MouseCursor::BottomEdgeResizeCursor:
  198134. shape = XC_bottom_side;
  198135. break;
  198136. case MouseCursor::LeftEdgeResizeCursor:
  198137. shape = XC_left_side;
  198138. break;
  198139. case MouseCursor::RightEdgeResizeCursor:
  198140. shape = XC_right_side;
  198141. break;
  198142. case MouseCursor::TopLeftCornerResizeCursor:
  198143. shape = XC_top_left_corner;
  198144. break;
  198145. case MouseCursor::TopRightCornerResizeCursor:
  198146. shape = XC_top_right_corner;
  198147. break;
  198148. case MouseCursor::BottomLeftCornerResizeCursor:
  198149. shape = XC_bottom_left_corner;
  198150. break;
  198151. case MouseCursor::BottomRightCornerResizeCursor:
  198152. shape = XC_bottom_right_corner;
  198153. break;
  198154. case MouseCursor::CrosshairCursor:
  198155. shape = XC_crosshair;
  198156. break;
  198157. default:
  198158. return (void*) None; // Use parent cursor
  198159. }
  198160. ScopedXLock xlock;
  198161. return (void*) XCreateFontCursor (display, shape);
  198162. }
  198163. void MouseCursor::showInWindow (ComponentPeer* peer) const throw()
  198164. {
  198165. LinuxComponentPeer* const lp = dynamic_cast <LinuxComponentPeer*> (peer);
  198166. if (lp != 0)
  198167. lp->showMouseCursor ((Cursor) getHandle());
  198168. }
  198169. void MouseCursor::showInAllWindows() const throw()
  198170. {
  198171. for (int i = ComponentPeer::getNumPeers(); --i >= 0;)
  198172. showInWindow (ComponentPeer::getPeer (i));
  198173. }
  198174. Image* juce_createIconForFile (const File& file)
  198175. {
  198176. return 0;
  198177. }
  198178. Image* Image::createNativeImage (const PixelFormat format, const int imageWidth, const int imageHeight, const bool clearImage)
  198179. {
  198180. return new Image (format, imageWidth, imageHeight, clearImage);
  198181. }
  198182. #if JUCE_OPENGL
  198183. class WindowedGLContext : public OpenGLContext
  198184. {
  198185. public:
  198186. WindowedGLContext (Component* const component,
  198187. const OpenGLPixelFormat& pixelFormat_,
  198188. GLXContext sharedContext)
  198189. : renderContext (0),
  198190. embeddedWindow (0),
  198191. pixelFormat (pixelFormat_)
  198192. {
  198193. jassert (component != 0);
  198194. LinuxComponentPeer* const peer = dynamic_cast <LinuxComponentPeer*> (component->getTopLevelComponent()->getPeer());
  198195. if (peer == 0)
  198196. return;
  198197. ScopedXLock xlock;
  198198. XSync (display, False);
  198199. GLint attribs [64];
  198200. int n = 0;
  198201. attribs[n++] = GLX_RGBA;
  198202. attribs[n++] = GLX_DOUBLEBUFFER;
  198203. attribs[n++] = GLX_RED_SIZE;
  198204. attribs[n++] = pixelFormat.redBits;
  198205. attribs[n++] = GLX_GREEN_SIZE;
  198206. attribs[n++] = pixelFormat.greenBits;
  198207. attribs[n++] = GLX_BLUE_SIZE;
  198208. attribs[n++] = pixelFormat.blueBits;
  198209. attribs[n++] = GLX_ALPHA_SIZE;
  198210. attribs[n++] = pixelFormat.alphaBits;
  198211. attribs[n++] = GLX_DEPTH_SIZE;
  198212. attribs[n++] = pixelFormat.depthBufferBits;
  198213. attribs[n++] = GLX_STENCIL_SIZE;
  198214. attribs[n++] = pixelFormat.stencilBufferBits;
  198215. attribs[n++] = GLX_ACCUM_RED_SIZE;
  198216. attribs[n++] = pixelFormat.accumulationBufferRedBits;
  198217. attribs[n++] = GLX_ACCUM_GREEN_SIZE;
  198218. attribs[n++] = pixelFormat.accumulationBufferGreenBits;
  198219. attribs[n++] = GLX_ACCUM_BLUE_SIZE;
  198220. attribs[n++] = pixelFormat.accumulationBufferBlueBits;
  198221. attribs[n++] = GLX_ACCUM_ALPHA_SIZE;
  198222. attribs[n++] = pixelFormat.accumulationBufferAlphaBits;
  198223. // xxx not sure how to do fullSceneAntiAliasingNumSamples on linux..
  198224. attribs[n++] = None;
  198225. XVisualInfo* const bestVisual = glXChooseVisual (display, DefaultScreen (display), attribs);
  198226. if (bestVisual == 0)
  198227. return;
  198228. renderContext = glXCreateContext (display, bestVisual, sharedContext, GL_TRUE);
  198229. Window windowH = (Window) peer->getNativeHandle();
  198230. Colormap colourMap = XCreateColormap (display, windowH, bestVisual->visual, AllocNone);
  198231. XSetWindowAttributes swa;
  198232. swa.colormap = colourMap;
  198233. swa.border_pixel = 0;
  198234. swa.event_mask = ExposureMask | StructureNotifyMask;
  198235. embeddedWindow = XCreateWindow (display, windowH,
  198236. 0, 0, 1, 1, 0,
  198237. bestVisual->depth,
  198238. InputOutput,
  198239. bestVisual->visual,
  198240. CWBorderPixel | CWColormap | CWEventMask,
  198241. &swa);
  198242. XSaveContext (display, (XID) embeddedWindow, improbableNumber, (XPointer) peer);
  198243. XMapWindow (display, embeddedWindow);
  198244. XFreeColormap (display, colourMap);
  198245. XFree (bestVisual);
  198246. XSync (display, False);
  198247. }
  198248. ~WindowedGLContext()
  198249. {
  198250. makeInactive();
  198251. ScopedXLock xlock;
  198252. glXDestroyContext (display, renderContext);
  198253. XUnmapWindow (display, embeddedWindow);
  198254. XDestroyWindow (display, embeddedWindow);
  198255. }
  198256. bool makeActive() const throw()
  198257. {
  198258. jassert (renderContext != 0);
  198259. ScopedXLock xlock;
  198260. return glXMakeCurrent (display, embeddedWindow, renderContext)
  198261. && XSync (display, False);
  198262. }
  198263. bool makeInactive() const throw()
  198264. {
  198265. ScopedXLock xlock;
  198266. return (! isActive()) || glXMakeCurrent (display, None, 0);
  198267. }
  198268. bool isActive() const throw()
  198269. {
  198270. ScopedXLock xlock;
  198271. return glXGetCurrentContext() == renderContext;
  198272. }
  198273. const OpenGLPixelFormat getPixelFormat() const
  198274. {
  198275. return pixelFormat;
  198276. }
  198277. void* getRawContext() const throw()
  198278. {
  198279. return renderContext;
  198280. }
  198281. void updateWindowPosition (int x, int y, int w, int h, int)
  198282. {
  198283. ScopedXLock xlock;
  198284. XMoveResizeWindow (display, embeddedWindow,
  198285. x, y, jmax (1, w), jmax (1, h));
  198286. }
  198287. void swapBuffers()
  198288. {
  198289. ScopedXLock xlock;
  198290. glXSwapBuffers (display, embeddedWindow);
  198291. }
  198292. bool setSwapInterval (const int numFramesPerSwap)
  198293. {
  198294. // xxx needs doing..
  198295. return false;
  198296. }
  198297. int getSwapInterval() const
  198298. {
  198299. // xxx needs doing..
  198300. return 0;
  198301. }
  198302. void repaint()
  198303. {
  198304. }
  198305. juce_UseDebuggingNewOperator
  198306. GLXContext renderContext;
  198307. private:
  198308. Window embeddedWindow;
  198309. OpenGLPixelFormat pixelFormat;
  198310. WindowedGLContext (const WindowedGLContext&);
  198311. const WindowedGLContext& operator= (const WindowedGLContext&);
  198312. };
  198313. OpenGLContext* OpenGLContext::createContextForWindow (Component* const component,
  198314. const OpenGLPixelFormat& pixelFormat,
  198315. const OpenGLContext* const contextToShareWith)
  198316. {
  198317. WindowedGLContext* c = new WindowedGLContext (component, pixelFormat,
  198318. contextToShareWith != 0 ? (GLXContext) contextToShareWith->getRawContext() : 0);
  198319. if (c->renderContext == 0)
  198320. deleteAndZero (c);
  198321. return c;
  198322. }
  198323. void juce_glViewport (const int w, const int h)
  198324. {
  198325. glViewport (0, 0, w, h);
  198326. }
  198327. void OpenGLPixelFormat::getAvailablePixelFormats (Component* component,
  198328. OwnedArray <OpenGLPixelFormat>& results)
  198329. {
  198330. results.add (new OpenGLPixelFormat()); // xxx
  198331. }
  198332. #endif
  198333. bool DragAndDropContainer::performExternalDragDropOfFiles (const StringArray& files, const bool canMoveFiles)
  198334. {
  198335. jassertfalse // not implemented!
  198336. return false;
  198337. }
  198338. bool DragAndDropContainer::performExternalDragDropOfText (const String& text)
  198339. {
  198340. jassertfalse // not implemented!
  198341. return false;
  198342. }
  198343. void SystemTrayIconComponent::setIconImage (const Image& newImage)
  198344. {
  198345. if (! isOnDesktop ())
  198346. addToDesktop (0);
  198347. LinuxComponentPeer* const wp = dynamic_cast <LinuxComponentPeer*> (getPeer());
  198348. if (wp != 0)
  198349. {
  198350. wp->setTaskBarIcon (newImage);
  198351. setVisible (true);
  198352. toFront (false);
  198353. repaint();
  198354. }
  198355. }
  198356. void SystemTrayIconComponent::paint (Graphics& g)
  198357. {
  198358. LinuxComponentPeer* const wp = dynamic_cast <LinuxComponentPeer*> (getPeer());
  198359. if (wp != 0)
  198360. {
  198361. const Image* const image = wp->getTaskbarIcon();
  198362. if (image != 0)
  198363. {
  198364. g.drawImageWithin (image, 0, 0, getWidth(), getHeight(),
  198365. RectanglePlacement::xLeft | RectanglePlacement::yTop | RectanglePlacement::onlyReduceInSize,
  198366. false);
  198367. }
  198368. }
  198369. }
  198370. void SystemTrayIconComponent::setIconTooltip (const String& tooltip)
  198371. {
  198372. // xxx not yet implemented!
  198373. }
  198374. void PlatformUtilities::beep()
  198375. {
  198376. std::cout << "\a" << std::flush;
  198377. }
  198378. bool AlertWindow::showNativeDialogBox (const String& title,
  198379. const String& bodyText,
  198380. bool isOkCancel)
  198381. {
  198382. // xxx this is supposed to pop up an alert!
  198383. Logger::outputDebugString (title + ": " + bodyText);
  198384. // use a non-native one for the time being..
  198385. if (isOkCancel)
  198386. return AlertWindow::showOkCancelBox (AlertWindow::NoIcon, title, bodyText);
  198387. else
  198388. AlertWindow::showMessageBox (AlertWindow::NoIcon, title, bodyText);
  198389. return true;
  198390. }
  198391. const int KeyPress::spaceKey = XK_space & 0xff;
  198392. const int KeyPress::returnKey = XK_Return & 0xff;
  198393. const int KeyPress::escapeKey = XK_Escape & 0xff;
  198394. const int KeyPress::backspaceKey = XK_BackSpace & 0xff;
  198395. const int KeyPress::leftKey = (XK_Left & 0xff) | extendedKeyModifier;
  198396. const int KeyPress::rightKey = (XK_Right & 0xff) | extendedKeyModifier;
  198397. const int KeyPress::upKey = (XK_Up & 0xff) | extendedKeyModifier;
  198398. const int KeyPress::downKey = (XK_Down & 0xff) | extendedKeyModifier;
  198399. const int KeyPress::pageUpKey = (XK_Page_Up & 0xff) | extendedKeyModifier;
  198400. const int KeyPress::pageDownKey = (XK_Page_Down & 0xff) | extendedKeyModifier;
  198401. const int KeyPress::endKey = (XK_End & 0xff) | extendedKeyModifier;
  198402. const int KeyPress::homeKey = (XK_Home & 0xff) | extendedKeyModifier;
  198403. const int KeyPress::insertKey = (XK_Insert & 0xff) | extendedKeyModifier;
  198404. const int KeyPress::deleteKey = (XK_Delete & 0xff) | extendedKeyModifier;
  198405. const int KeyPress::tabKey = XK_Tab & 0xff;
  198406. const int KeyPress::F1Key = (XK_F1 & 0xff) | extendedKeyModifier;
  198407. const int KeyPress::F2Key = (XK_F2 & 0xff) | extendedKeyModifier;
  198408. const int KeyPress::F3Key = (XK_F3 & 0xff) | extendedKeyModifier;
  198409. const int KeyPress::F4Key = (XK_F4 & 0xff) | extendedKeyModifier;
  198410. const int KeyPress::F5Key = (XK_F5 & 0xff) | extendedKeyModifier;
  198411. const int KeyPress::F6Key = (XK_F6 & 0xff) | extendedKeyModifier;
  198412. const int KeyPress::F7Key = (XK_F7 & 0xff) | extendedKeyModifier;
  198413. const int KeyPress::F8Key = (XK_F8 & 0xff) | extendedKeyModifier;
  198414. const int KeyPress::F9Key = (XK_F9 & 0xff) | extendedKeyModifier;
  198415. const int KeyPress::F10Key = (XK_F10 & 0xff) | extendedKeyModifier;
  198416. const int KeyPress::F11Key = (XK_F11 & 0xff) | extendedKeyModifier;
  198417. const int KeyPress::F12Key = (XK_F12 & 0xff) | extendedKeyModifier;
  198418. const int KeyPress::F13Key = (XK_F13 & 0xff) | extendedKeyModifier;
  198419. const int KeyPress::F14Key = (XK_F14 & 0xff) | extendedKeyModifier;
  198420. const int KeyPress::F15Key = (XK_F15 & 0xff) | extendedKeyModifier;
  198421. const int KeyPress::F16Key = (XK_F16 & 0xff) | extendedKeyModifier;
  198422. const int KeyPress::numberPad0 = (XK_KP_0 & 0xff) | extendedKeyModifier;
  198423. const int KeyPress::numberPad1 = (XK_KP_1 & 0xff) | extendedKeyModifier;
  198424. const int KeyPress::numberPad2 = (XK_KP_2 & 0xff) | extendedKeyModifier;
  198425. const int KeyPress::numberPad3 = (XK_KP_3 & 0xff) | extendedKeyModifier;
  198426. const int KeyPress::numberPad4 = (XK_KP_4 & 0xff) | extendedKeyModifier;
  198427. const int KeyPress::numberPad5 = (XK_KP_5 & 0xff) | extendedKeyModifier;
  198428. const int KeyPress::numberPad6 = (XK_KP_6 & 0xff) | extendedKeyModifier;
  198429. const int KeyPress::numberPad7 = (XK_KP_7 & 0xff)| extendedKeyModifier;
  198430. const int KeyPress::numberPad8 = (XK_KP_8 & 0xff)| extendedKeyModifier;
  198431. const int KeyPress::numberPad9 = (XK_KP_9 & 0xff)| extendedKeyModifier;
  198432. const int KeyPress::numberPadAdd = (XK_KP_Add & 0xff)| extendedKeyModifier;
  198433. const int KeyPress::numberPadSubtract = (XK_KP_Subtract & 0xff)| extendedKeyModifier;
  198434. const int KeyPress::numberPadMultiply = (XK_KP_Multiply & 0xff)| extendedKeyModifier;
  198435. const int KeyPress::numberPadDivide = (XK_KP_Divide & 0xff)| extendedKeyModifier;
  198436. const int KeyPress::numberPadSeparator = (XK_KP_Separator & 0xff)| extendedKeyModifier;
  198437. const int KeyPress::numberPadDecimalPoint = (XK_KP_Decimal & 0xff)| extendedKeyModifier;
  198438. const int KeyPress::numberPadEquals = (XK_KP_Equal & 0xff)| extendedKeyModifier;
  198439. const int KeyPress::numberPadDelete = (XK_KP_Delete & 0xff)| extendedKeyModifier;
  198440. const int KeyPress::playKey = (0xffeeff00) | extendedKeyModifier;
  198441. const int KeyPress::stopKey = (0xffeeff01) | extendedKeyModifier;
  198442. const int KeyPress::fastForwardKey = (0xffeeff02) | extendedKeyModifier;
  198443. const int KeyPress::rewindKey = (0xffeeff03) | extendedKeyModifier;
  198444. #endif
  198445. /********* End of inlined file: juce_linux_Windowing.cpp *********/
  198446. /********* Start of inlined file: juce_linux_Audio.cpp *********/
  198447. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  198448. // compiled on its own).
  198449. #if JUCE_INCLUDED_FILE && JUCE_ALSA
  198450. static const int maxNumChans = 64;
  198451. static void getDeviceSampleRates (snd_pcm_t* handle, Array <int>& rates)
  198452. {
  198453. const int ratesToTry[] = { 22050, 32000, 44100, 48000, 88200, 96000, 176400, 192000, 0 };
  198454. snd_pcm_hw_params_t* hwParams;
  198455. snd_pcm_hw_params_alloca (&hwParams);
  198456. for (int i = 0; ratesToTry[i] != 0; ++i)
  198457. {
  198458. if (snd_pcm_hw_params_any (handle, hwParams) >= 0
  198459. && snd_pcm_hw_params_test_rate (handle, hwParams, ratesToTry[i], 0) == 0)
  198460. {
  198461. rates.addIfNotAlreadyThere (ratesToTry[i]);
  198462. }
  198463. }
  198464. }
  198465. static void getDeviceNumChannels (snd_pcm_t* handle, unsigned int* minChans, unsigned int* maxChans)
  198466. {
  198467. snd_pcm_hw_params_t *params;
  198468. snd_pcm_hw_params_alloca (&params);
  198469. if (snd_pcm_hw_params_any (handle, params) >= 0)
  198470. {
  198471. snd_pcm_hw_params_get_channels_min (params, minChans);
  198472. snd_pcm_hw_params_get_channels_max (params, maxChans);
  198473. }
  198474. }
  198475. static void getDeviceProperties (const String& id,
  198476. unsigned int& minChansOut,
  198477. unsigned int& maxChansOut,
  198478. unsigned int& minChansIn,
  198479. unsigned int& maxChansIn,
  198480. Array <int>& rates)
  198481. {
  198482. if (id.isEmpty())
  198483. return;
  198484. snd_ctl_t* handle;
  198485. if (snd_ctl_open (&handle, id.upToLastOccurrenceOf (T(","), false, false), SND_CTL_NONBLOCK) >= 0)
  198486. {
  198487. snd_pcm_info_t* info;
  198488. snd_pcm_info_alloca (&info);
  198489. snd_pcm_info_set_stream (info, SND_PCM_STREAM_PLAYBACK);
  198490. snd_pcm_info_set_device (info, id.fromLastOccurrenceOf (T(","), false, false).getIntValue());
  198491. snd_pcm_info_set_subdevice (info, 0);
  198492. if (snd_ctl_pcm_info (handle, info) >= 0)
  198493. {
  198494. snd_pcm_t* pcmHandle;
  198495. if (snd_pcm_open (&pcmHandle, id, SND_PCM_STREAM_PLAYBACK, SND_PCM_ASYNC | SND_PCM_NONBLOCK ) >= 0)
  198496. {
  198497. getDeviceNumChannels (pcmHandle, &minChansOut, &maxChansOut);
  198498. getDeviceSampleRates (pcmHandle, rates);
  198499. snd_pcm_close (pcmHandle);
  198500. }
  198501. }
  198502. snd_pcm_info_set_stream (info, SND_PCM_STREAM_CAPTURE);
  198503. if (snd_ctl_pcm_info (handle, info) >= 0)
  198504. {
  198505. snd_pcm_t* pcmHandle;
  198506. if (snd_pcm_open (&pcmHandle, id, SND_PCM_STREAM_CAPTURE, SND_PCM_ASYNC | SND_PCM_NONBLOCK ) >= 0)
  198507. {
  198508. getDeviceNumChannels (pcmHandle, &minChansIn, &maxChansIn);
  198509. if (rates.size() == 0)
  198510. getDeviceSampleRates (pcmHandle, rates);
  198511. snd_pcm_close (pcmHandle);
  198512. }
  198513. }
  198514. snd_ctl_close (handle);
  198515. }
  198516. }
  198517. class ALSADevice
  198518. {
  198519. public:
  198520. ALSADevice (const String& id,
  198521. const bool forInput)
  198522. : handle (0),
  198523. bitDepth (16),
  198524. numChannelsRunning (0),
  198525. isInput (forInput),
  198526. sampleFormat (AudioDataConverters::int16LE)
  198527. {
  198528. failed (snd_pcm_open (&handle, id,
  198529. forInput ? SND_PCM_STREAM_CAPTURE : SND_PCM_STREAM_PLAYBACK,
  198530. SND_PCM_ASYNC));
  198531. }
  198532. ~ALSADevice()
  198533. {
  198534. if (handle != 0)
  198535. snd_pcm_close (handle);
  198536. }
  198537. bool setParameters (unsigned int sampleRate, int numChannels, int bufferSize)
  198538. {
  198539. if (handle == 0)
  198540. return false;
  198541. snd_pcm_hw_params_t* hwParams;
  198542. snd_pcm_hw_params_alloca (&hwParams);
  198543. if (failed (snd_pcm_hw_params_any (handle, hwParams)))
  198544. return false;
  198545. if (snd_pcm_hw_params_set_access (handle, hwParams, SND_PCM_ACCESS_RW_NONINTERLEAVED) >= 0)
  198546. isInterleaved = false;
  198547. else if (snd_pcm_hw_params_set_access (handle, hwParams, SND_PCM_ACCESS_RW_INTERLEAVED) >= 0)
  198548. isInterleaved = true;
  198549. else
  198550. {
  198551. jassertfalse
  198552. return false;
  198553. }
  198554. const int formatsToTry[] = { SND_PCM_FORMAT_FLOAT_LE, 32, AudioDataConverters::float32LE,
  198555. SND_PCM_FORMAT_FLOAT_BE, 32, AudioDataConverters::float32BE,
  198556. SND_PCM_FORMAT_S32_LE, 32, AudioDataConverters::int32LE,
  198557. SND_PCM_FORMAT_S32_BE, 32, AudioDataConverters::int32BE,
  198558. SND_PCM_FORMAT_S24_3LE, 24, AudioDataConverters::int24LE,
  198559. SND_PCM_FORMAT_S24_3BE, 24, AudioDataConverters::int24BE,
  198560. SND_PCM_FORMAT_S16_LE, 16, AudioDataConverters::int16LE,
  198561. SND_PCM_FORMAT_S16_BE, 16, AudioDataConverters::int16BE };
  198562. bitDepth = 0;
  198563. for (int i = 0; i < numElementsInArray (formatsToTry); i += 3)
  198564. {
  198565. if (snd_pcm_hw_params_set_format (handle, hwParams, (_snd_pcm_format) formatsToTry [i]) >= 0)
  198566. {
  198567. bitDepth = formatsToTry [i + 1];
  198568. sampleFormat = (AudioDataConverters::DataFormat) formatsToTry [i + 2];
  198569. break;
  198570. }
  198571. }
  198572. if (bitDepth == 0)
  198573. {
  198574. error = "device doesn't support a compatible PCM format";
  198575. DBG (T("ALSA error: ") + error + T("\n"));
  198576. return false;
  198577. }
  198578. int dir = 0;
  198579. unsigned int periods = 4;
  198580. snd_pcm_uframes_t samplesPerPeriod = bufferSize;
  198581. if (failed (snd_pcm_hw_params_set_rate_near (handle, hwParams, &sampleRate, 0))
  198582. || failed (snd_pcm_hw_params_set_channels (handle, hwParams, numChannels))
  198583. || failed (snd_pcm_hw_params_set_periods_near (handle, hwParams, &periods, &dir))
  198584. || failed (snd_pcm_hw_params_set_period_size_near (handle, hwParams, &samplesPerPeriod, &dir))
  198585. || failed (snd_pcm_hw_params (handle, hwParams)))
  198586. {
  198587. return false;
  198588. }
  198589. snd_pcm_sw_params_t* swParams;
  198590. snd_pcm_sw_params_alloca (&swParams);
  198591. snd_pcm_uframes_t boundary;
  198592. if (failed (snd_pcm_sw_params_current (handle, swParams))
  198593. || failed (snd_pcm_sw_params_get_boundary (swParams, &boundary))
  198594. || failed (snd_pcm_sw_params_set_silence_threshold (handle, swParams, 0))
  198595. || failed (snd_pcm_sw_params_set_silence_size (handle, swParams, boundary))
  198596. || failed (snd_pcm_sw_params_set_start_threshold (handle, swParams, samplesPerPeriod))
  198597. || failed (snd_pcm_sw_params_set_stop_threshold (handle, swParams, boundary))
  198598. || failed (snd_pcm_sw_params (handle, swParams)))
  198599. {
  198600. return false;
  198601. }
  198602. numChannelsRunning = numChannels;
  198603. return true;
  198604. }
  198605. bool write (float** const data, const int numSamples)
  198606. {
  198607. if (isInterleaved)
  198608. {
  198609. scratch.ensureSize (sizeof (float) * numSamples * numChannelsRunning, false);
  198610. float* interleaved = (float*) scratch;
  198611. AudioDataConverters::interleaveSamples ((const float**) data, interleaved, numSamples, numChannelsRunning);
  198612. AudioDataConverters::convertFloatToFormat (sampleFormat, interleaved, interleaved, numSamples * numChannelsRunning);
  198613. snd_pcm_sframes_t num = snd_pcm_writei (handle, (void*) interleaved, numSamples);
  198614. if (failed (num) && num != -EPIPE && num != -ESTRPIPE)
  198615. return false;
  198616. }
  198617. else
  198618. {
  198619. for (int i = 0; i < numChannelsRunning; ++i)
  198620. if (data[i] != 0)
  198621. AudioDataConverters::convertFloatToFormat (sampleFormat, data[i], data[i], numSamples);
  198622. snd_pcm_sframes_t num = snd_pcm_writen (handle, (void**) data, numSamples);
  198623. if (failed (num))
  198624. {
  198625. if (num == -EPIPE)
  198626. {
  198627. if (failed (snd_pcm_prepare (handle)))
  198628. return false;
  198629. }
  198630. else if (num != -ESTRPIPE)
  198631. return false;
  198632. }
  198633. }
  198634. return true;
  198635. }
  198636. bool read (float** const data, const int numSamples)
  198637. {
  198638. if (isInterleaved)
  198639. {
  198640. scratch.ensureSize (sizeof (float) * numSamples * numChannelsRunning, false);
  198641. float* interleaved = (float*) scratch;
  198642. snd_pcm_sframes_t num = snd_pcm_readi (handle, (void*) interleaved, numSamples);
  198643. if (failed (num))
  198644. {
  198645. if (num == -EPIPE)
  198646. {
  198647. if (failed (snd_pcm_prepare (handle)))
  198648. return false;
  198649. }
  198650. else if (num != -ESTRPIPE)
  198651. return false;
  198652. }
  198653. AudioDataConverters::convertFormatToFloat (sampleFormat, interleaved, interleaved, numSamples * numChannelsRunning);
  198654. AudioDataConverters::deinterleaveSamples (interleaved, data, numSamples, numChannelsRunning);
  198655. }
  198656. else
  198657. {
  198658. snd_pcm_sframes_t num = snd_pcm_readn (handle, (void**) data, numSamples);
  198659. if (failed (num) && num != -EPIPE && num != -ESTRPIPE)
  198660. return false;
  198661. for (int i = 0; i < numChannelsRunning; ++i)
  198662. if (data[i] != 0)
  198663. AudioDataConverters::convertFormatToFloat (sampleFormat, data[i], data[i], numSamples);
  198664. }
  198665. return true;
  198666. }
  198667. juce_UseDebuggingNewOperator
  198668. snd_pcm_t* handle;
  198669. String error;
  198670. int bitDepth, numChannelsRunning;
  198671. private:
  198672. const bool isInput;
  198673. bool isInterleaved;
  198674. MemoryBlock scratch;
  198675. AudioDataConverters::DataFormat sampleFormat;
  198676. bool failed (const int errorNum)
  198677. {
  198678. if (errorNum >= 0)
  198679. return false;
  198680. error = snd_strerror (errorNum);
  198681. DBG (T("ALSA error: ") + error + T("\n"));
  198682. return true;
  198683. }
  198684. };
  198685. class ALSAThread : public Thread
  198686. {
  198687. public:
  198688. ALSAThread (const String& inputId_,
  198689. const String& outputId_)
  198690. : Thread ("Juce ALSA"),
  198691. sampleRate (0),
  198692. bufferSize (0),
  198693. callback (0),
  198694. inputId (inputId_),
  198695. outputId (outputId_),
  198696. outputDevice (0),
  198697. inputDevice (0),
  198698. numCallbacks (0),
  198699. totalNumInputChannels (0),
  198700. totalNumOutputChannels (0)
  198701. {
  198702. zeromem (outputChannelData, sizeof (outputChannelData));
  198703. zeromem (outputChannelDataForCallback, sizeof (outputChannelDataForCallback));
  198704. zeromem (inputChannelData, sizeof (inputChannelData));
  198705. zeromem (inputChannelDataForCallback, sizeof (inputChannelDataForCallback));
  198706. initialiseRatesAndChannels();
  198707. }
  198708. ~ALSAThread()
  198709. {
  198710. close();
  198711. }
  198712. void open (BitArray inputChannels,
  198713. BitArray outputChannels,
  198714. const double sampleRate_,
  198715. const int bufferSize_)
  198716. {
  198717. close();
  198718. error = String::empty;
  198719. sampleRate = sampleRate_;
  198720. bufferSize = bufferSize_;
  198721. currentInputChans.clear();
  198722. currentOutputChans.clear();
  198723. if (inputChannels.getHighestBit() >= 0)
  198724. {
  198725. for (int i = 0; i <= jmax (inputChannels.getHighestBit(), (int) minChansIn); ++i)
  198726. {
  198727. inputChannelData [i] = (float*) juce_calloc (sizeof (float) * bufferSize);
  198728. if (inputChannels[i])
  198729. {
  198730. inputChannelDataForCallback [totalNumInputChannels++] = inputChannelData [i];
  198731. currentInputChans.setBit (i);
  198732. }
  198733. }
  198734. }
  198735. if (outputChannels.getHighestBit() >= 0)
  198736. {
  198737. for (int i = 0; i <= jmax (outputChannels.getHighestBit(), (int) minChansOut); ++i)
  198738. {
  198739. outputChannelData [i] = (float*) juce_calloc (sizeof (float) * bufferSize);
  198740. if (outputChannels[i])
  198741. {
  198742. outputChannelDataForCallback [totalNumOutputChannels++] = outputChannelData [i];
  198743. currentOutputChans.setBit (i);
  198744. }
  198745. }
  198746. }
  198747. if (totalNumOutputChannels > 0 && outputId.isNotEmpty())
  198748. {
  198749. outputDevice = new ALSADevice (outputId, false);
  198750. if (outputDevice->error.isNotEmpty())
  198751. {
  198752. error = outputDevice->error;
  198753. deleteAndZero (outputDevice);
  198754. return;
  198755. }
  198756. currentOutputChans.setRange (0, minChansOut, true);
  198757. if (! outputDevice->setParameters ((unsigned int) sampleRate,
  198758. jlimit ((int) minChansOut, (int) maxChansOut, currentOutputChans.getHighestBit() + 1),
  198759. bufferSize))
  198760. {
  198761. error = outputDevice->error;
  198762. deleteAndZero (outputDevice);
  198763. return;
  198764. }
  198765. }
  198766. if (totalNumInputChannels > 0 && inputId.isNotEmpty())
  198767. {
  198768. inputDevice = new ALSADevice (inputId, true);
  198769. if (inputDevice->error.isNotEmpty())
  198770. {
  198771. error = inputDevice->error;
  198772. deleteAndZero (inputDevice);
  198773. return;
  198774. }
  198775. currentInputChans.setRange (0, minChansIn, true);
  198776. if (! inputDevice->setParameters ((unsigned int) sampleRate,
  198777. jlimit ((int) minChansIn, (int) maxChansIn, currentInputChans.getHighestBit() + 1),
  198778. bufferSize))
  198779. {
  198780. error = inputDevice->error;
  198781. deleteAndZero (inputDevice);
  198782. return;
  198783. }
  198784. }
  198785. if (outputDevice == 0 && inputDevice == 0)
  198786. {
  198787. error = "no channels";
  198788. return;
  198789. }
  198790. if (outputDevice != 0 && inputDevice != 0)
  198791. {
  198792. snd_pcm_link (outputDevice->handle, inputDevice->handle);
  198793. }
  198794. if (inputDevice != 0 && failed (snd_pcm_prepare (inputDevice->handle)))
  198795. return;
  198796. if (outputDevice != 0 && failed (snd_pcm_prepare (outputDevice->handle)))
  198797. return;
  198798. startThread (9);
  198799. int count = 1000;
  198800. while (numCallbacks == 0)
  198801. {
  198802. sleep (5);
  198803. if (--count < 0 || ! isThreadRunning())
  198804. {
  198805. error = "device didn't start";
  198806. break;
  198807. }
  198808. }
  198809. }
  198810. void close()
  198811. {
  198812. stopThread (6000);
  198813. deleteAndZero (inputDevice);
  198814. deleteAndZero (outputDevice);
  198815. for (int i = 0; i < maxNumChans; ++i)
  198816. {
  198817. juce_free (inputChannelData [i]);
  198818. juce_free (outputChannelData [i]);
  198819. }
  198820. zeromem (outputChannelData, sizeof (outputChannelData));
  198821. zeromem (outputChannelDataForCallback, sizeof (outputChannelDataForCallback));
  198822. zeromem (inputChannelData, sizeof (inputChannelData));
  198823. zeromem (inputChannelDataForCallback, sizeof (inputChannelDataForCallback));
  198824. totalNumOutputChannels = 0;
  198825. totalNumInputChannels = 0;
  198826. numCallbacks = 0;
  198827. }
  198828. void setCallback (AudioIODeviceCallback* const newCallback) throw()
  198829. {
  198830. const ScopedLock sl (callbackLock);
  198831. callback = newCallback;
  198832. }
  198833. void run()
  198834. {
  198835. while (! threadShouldExit())
  198836. {
  198837. if (inputDevice != 0)
  198838. {
  198839. if (! inputDevice->read (inputChannelData, bufferSize))
  198840. {
  198841. DBG ("ALSA: read failure");
  198842. break;
  198843. }
  198844. }
  198845. if (threadShouldExit())
  198846. break;
  198847. {
  198848. const ScopedLock sl (callbackLock);
  198849. ++numCallbacks;
  198850. if (callback != 0)
  198851. {
  198852. callback->audioDeviceIOCallback ((const float**) inputChannelDataForCallback,
  198853. totalNumInputChannels,
  198854. outputChannelDataForCallback,
  198855. totalNumOutputChannels,
  198856. bufferSize);
  198857. }
  198858. else
  198859. {
  198860. for (int i = 0; i < totalNumOutputChannels; ++i)
  198861. zeromem (outputChannelDataForCallback[i], sizeof (float) * bufferSize);
  198862. }
  198863. }
  198864. if (outputDevice != 0)
  198865. {
  198866. failed (snd_pcm_wait (outputDevice->handle, 2000));
  198867. if (threadShouldExit())
  198868. break;
  198869. failed (snd_pcm_avail_update (outputDevice->handle));
  198870. if (! outputDevice->write (outputChannelData, bufferSize))
  198871. {
  198872. DBG ("ALSA: write failure");
  198873. break;
  198874. }
  198875. }
  198876. }
  198877. }
  198878. int getBitDepth() const throw()
  198879. {
  198880. if (outputDevice != 0)
  198881. return outputDevice->bitDepth;
  198882. if (inputDevice != 0)
  198883. return inputDevice->bitDepth;
  198884. return 16;
  198885. }
  198886. juce_UseDebuggingNewOperator
  198887. String error;
  198888. double sampleRate;
  198889. int bufferSize;
  198890. BitArray currentInputChans, currentOutputChans;
  198891. Array <int> sampleRates;
  198892. StringArray channelNamesOut, channelNamesIn;
  198893. AudioIODeviceCallback* callback;
  198894. private:
  198895. const String inputId, outputId;
  198896. ALSADevice* outputDevice;
  198897. ALSADevice* inputDevice;
  198898. int numCallbacks;
  198899. CriticalSection callbackLock;
  198900. float* outputChannelData [maxNumChans];
  198901. float* outputChannelDataForCallback [maxNumChans];
  198902. int totalNumInputChannels;
  198903. float* inputChannelData [maxNumChans];
  198904. float* inputChannelDataForCallback [maxNumChans];
  198905. int totalNumOutputChannels;
  198906. unsigned int minChansOut, maxChansOut;
  198907. unsigned int minChansIn, maxChansIn;
  198908. bool failed (const int errorNum) throw()
  198909. {
  198910. if (errorNum >= 0)
  198911. return false;
  198912. error = snd_strerror (errorNum);
  198913. DBG (T("ALSA error: ") + error + T("\n"));
  198914. return true;
  198915. }
  198916. void initialiseRatesAndChannels() throw()
  198917. {
  198918. sampleRates.clear();
  198919. channelNamesOut.clear();
  198920. channelNamesIn.clear();
  198921. minChansOut = 0;
  198922. maxChansOut = 0;
  198923. minChansIn = 0;
  198924. maxChansIn = 0;
  198925. unsigned int dummy = 0;
  198926. getDeviceProperties (inputId, dummy, dummy, minChansIn, maxChansIn, sampleRates);
  198927. getDeviceProperties (outputId, minChansOut, maxChansOut, dummy, dummy, sampleRates);
  198928. unsigned int i;
  198929. for (i = 0; i < maxChansOut; ++i)
  198930. channelNamesOut.add (T("channel ") + String ((int) i + 1));
  198931. for (i = 0; i < maxChansIn; ++i)
  198932. channelNamesIn.add (T("channel ") + String ((int) i + 1));
  198933. }
  198934. };
  198935. class ALSAAudioIODevice : public AudioIODevice
  198936. {
  198937. public:
  198938. ALSAAudioIODevice (const String& deviceName,
  198939. const String& inputId_,
  198940. const String& outputId_)
  198941. : AudioIODevice (deviceName, T("ALSA")),
  198942. inputId (inputId_),
  198943. outputId (outputId_),
  198944. isOpen_ (false),
  198945. isStarted (false),
  198946. internal (0)
  198947. {
  198948. internal = new ALSAThread (inputId, outputId);
  198949. }
  198950. ~ALSAAudioIODevice()
  198951. {
  198952. delete internal;
  198953. }
  198954. const StringArray getOutputChannelNames()
  198955. {
  198956. return internal->channelNamesOut;
  198957. }
  198958. const StringArray getInputChannelNames()
  198959. {
  198960. return internal->channelNamesIn;
  198961. }
  198962. int getNumSampleRates()
  198963. {
  198964. return internal->sampleRates.size();
  198965. }
  198966. double getSampleRate (int index)
  198967. {
  198968. return internal->sampleRates [index];
  198969. }
  198970. int getNumBufferSizesAvailable()
  198971. {
  198972. return 50;
  198973. }
  198974. int getBufferSizeSamples (int index)
  198975. {
  198976. int n = 16;
  198977. for (int i = 0; i < index; ++i)
  198978. n += n < 64 ? 16
  198979. : (n < 512 ? 32
  198980. : (n < 1024 ? 64
  198981. : (n < 2048 ? 128 : 256)));
  198982. return n;
  198983. }
  198984. int getDefaultBufferSize()
  198985. {
  198986. return 512;
  198987. }
  198988. const String open (const BitArray& inputChannels,
  198989. const BitArray& outputChannels,
  198990. double sampleRate,
  198991. int bufferSizeSamples)
  198992. {
  198993. close();
  198994. if (bufferSizeSamples <= 0)
  198995. bufferSizeSamples = getDefaultBufferSize();
  198996. if (sampleRate <= 0)
  198997. {
  198998. for (int i = 0; i < getNumSampleRates(); ++i)
  198999. {
  199000. if (getSampleRate (i) >= 44100)
  199001. {
  199002. sampleRate = getSampleRate (i);
  199003. break;
  199004. }
  199005. }
  199006. }
  199007. internal->open (inputChannels, outputChannels,
  199008. sampleRate, bufferSizeSamples);
  199009. isOpen_ = internal->error.isEmpty();
  199010. return internal->error;
  199011. }
  199012. void close()
  199013. {
  199014. stop();
  199015. internal->close();
  199016. isOpen_ = false;
  199017. }
  199018. bool isOpen()
  199019. {
  199020. return isOpen_;
  199021. }
  199022. int getCurrentBufferSizeSamples()
  199023. {
  199024. return internal->bufferSize;
  199025. }
  199026. double getCurrentSampleRate()
  199027. {
  199028. return internal->sampleRate;
  199029. }
  199030. int getCurrentBitDepth()
  199031. {
  199032. return internal->getBitDepth();
  199033. }
  199034. const BitArray getActiveOutputChannels() const
  199035. {
  199036. return internal->currentOutputChans;
  199037. }
  199038. const BitArray getActiveInputChannels() const
  199039. {
  199040. return internal->currentInputChans;
  199041. }
  199042. int getOutputLatencyInSamples()
  199043. {
  199044. return 0;
  199045. }
  199046. int getInputLatencyInSamples()
  199047. {
  199048. return 0;
  199049. }
  199050. void start (AudioIODeviceCallback* callback)
  199051. {
  199052. if (! isOpen_)
  199053. callback = 0;
  199054. internal->setCallback (callback);
  199055. if (callback != 0)
  199056. callback->audioDeviceAboutToStart (this);
  199057. isStarted = (callback != 0);
  199058. }
  199059. void stop()
  199060. {
  199061. AudioIODeviceCallback* const oldCallback = internal->callback;
  199062. start (0);
  199063. if (oldCallback != 0)
  199064. oldCallback->audioDeviceStopped();
  199065. }
  199066. bool isPlaying()
  199067. {
  199068. return isStarted && internal->error.isEmpty();
  199069. }
  199070. const String getLastError()
  199071. {
  199072. return internal->error;
  199073. }
  199074. String inputId, outputId;
  199075. private:
  199076. bool isOpen_, isStarted;
  199077. ALSAThread* internal;
  199078. };
  199079. class ALSAAudioIODeviceType : public AudioIODeviceType
  199080. {
  199081. public:
  199082. ALSAAudioIODeviceType()
  199083. : AudioIODeviceType (T("ALSA")),
  199084. hasScanned (false)
  199085. {
  199086. }
  199087. ~ALSAAudioIODeviceType()
  199088. {
  199089. }
  199090. void scanForDevices()
  199091. {
  199092. if (hasScanned)
  199093. return;
  199094. hasScanned = true;
  199095. inputNames.clear();
  199096. inputIds.clear();
  199097. outputNames.clear();
  199098. outputIds.clear();
  199099. snd_ctl_t* handle;
  199100. snd_ctl_card_info_t* info;
  199101. snd_ctl_card_info_alloca (&info);
  199102. int cardNum = -1;
  199103. while (outputIds.size() + inputIds.size() <= 32)
  199104. {
  199105. snd_card_next (&cardNum);
  199106. if (cardNum < 0)
  199107. break;
  199108. if (snd_ctl_open (&handle, T("hw:") + String (cardNum), SND_CTL_NONBLOCK) >= 0)
  199109. {
  199110. if (snd_ctl_card_info (handle, info) >= 0)
  199111. {
  199112. String cardId (snd_ctl_card_info_get_id (info));
  199113. if (cardId.removeCharacters (T("0123456789")).isEmpty())
  199114. cardId = String (cardNum);
  199115. int device = -1;
  199116. for (;;)
  199117. {
  199118. if (snd_ctl_pcm_next_device (handle, &device) < 0 || device < 0)
  199119. break;
  199120. String id, name;
  199121. id << "hw:" << cardId << ',' << device;
  199122. bool isInput, isOutput;
  199123. if (testDevice (id, isInput, isOutput))
  199124. {
  199125. name << snd_ctl_card_info_get_name (info);
  199126. if (name.isEmpty())
  199127. name = id;
  199128. if (isInput)
  199129. {
  199130. inputNames.add (name);
  199131. inputIds.add (id);
  199132. }
  199133. if (isOutput)
  199134. {
  199135. outputNames.add (name);
  199136. outputIds.add (id);
  199137. }
  199138. }
  199139. }
  199140. }
  199141. snd_ctl_close (handle);
  199142. }
  199143. }
  199144. inputNames.appendNumbersToDuplicates (false, true);
  199145. outputNames.appendNumbersToDuplicates (false, true);
  199146. }
  199147. const StringArray getDeviceNames (const bool wantInputNames) const
  199148. {
  199149. jassert (hasScanned); // need to call scanForDevices() before doing this
  199150. return wantInputNames ? inputNames : outputNames;
  199151. }
  199152. int getDefaultDeviceIndex (const bool forInput) const
  199153. {
  199154. jassert (hasScanned); // need to call scanForDevices() before doing this
  199155. return 0;
  199156. }
  199157. bool hasSeparateInputsAndOutputs() const { return true; }
  199158. int getIndexOfDevice (AudioIODevice* device, const bool asInput) const
  199159. {
  199160. jassert (hasScanned); // need to call scanForDevices() before doing this
  199161. ALSAAudioIODevice* const d = dynamic_cast <ALSAAudioIODevice*> (device);
  199162. if (d == 0)
  199163. return -1;
  199164. return asInput ? inputIds.indexOf (d->inputId)
  199165. : outputIds.indexOf (d->outputId);
  199166. }
  199167. AudioIODevice* createDevice (const String& outputDeviceName,
  199168. const String& inputDeviceName)
  199169. {
  199170. jassert (hasScanned); // need to call scanForDevices() before doing this
  199171. const int inputIndex = inputNames.indexOf (inputDeviceName);
  199172. const int outputIndex = outputNames.indexOf (outputDeviceName);
  199173. String deviceName (outputIndex >= 0 ? outputDeviceName
  199174. : inputDeviceName);
  199175. if (inputIndex >= 0 || outputIndex >= 0)
  199176. return new ALSAAudioIODevice (deviceName,
  199177. inputIds [inputIndex],
  199178. outputIds [outputIndex]);
  199179. return 0;
  199180. }
  199181. juce_UseDebuggingNewOperator
  199182. private:
  199183. StringArray inputNames, outputNames, inputIds, outputIds;
  199184. bool hasScanned;
  199185. static bool testDevice (const String& id, bool& isInput, bool& isOutput)
  199186. {
  199187. unsigned int minChansOut = 0, maxChansOut = 0;
  199188. unsigned int minChansIn = 0, maxChansIn = 0;
  199189. Array <int> rates;
  199190. getDeviceProperties (id, minChansOut, maxChansOut, minChansIn, maxChansIn, rates);
  199191. DBG (T("ALSA device: ") + id
  199192. + T(" outs=") + String ((int) minChansOut) + T("-") + String ((int) maxChansOut)
  199193. + T(" ins=") + String ((int) minChansIn) + T("-") + String ((int) maxChansIn)
  199194. + T(" rates=") + String (rates.size()));
  199195. isInput = maxChansIn > 0;
  199196. isOutput = maxChansOut > 0;
  199197. return (isInput || isOutput) && rates.size() > 0;
  199198. }
  199199. ALSAAudioIODeviceType (const ALSAAudioIODeviceType&);
  199200. const ALSAAudioIODeviceType& operator= (const ALSAAudioIODeviceType&);
  199201. };
  199202. AudioIODeviceType* juce_createAudioIODeviceType_ALSA()
  199203. {
  199204. return new ALSAAudioIODeviceType();
  199205. }
  199206. #endif
  199207. /********* End of inlined file: juce_linux_Audio.cpp *********/
  199208. /********* Start of inlined file: juce_linux_JackAudio.cpp *********/
  199209. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  199210. // compiled on its own).
  199211. #ifdef JUCE_INCLUDED_FILE
  199212. #if JUCE_JACK
  199213. static void* juce_libjack_handle = 0;
  199214. void* juce_load_jack_function (const char* const name)
  199215. {
  199216. if (juce_libjack_handle == 0)
  199217. return 0;
  199218. return dlsym (juce_libjack_handle, name);
  199219. }
  199220. #define JUCE_DECL_JACK_FUNCTION(return_type, fn_name, argument_types, arguments) \
  199221. typedef return_type (*fn_name##_ptr_t)argument_types; \
  199222. return_type fn_name argument_types { \
  199223. static fn_name##_ptr_t fn = 0; \
  199224. if (fn == 0) { fn = (fn_name##_ptr_t)juce_load_jack_function(#fn_name); } \
  199225. if (fn) return (*fn)arguments; \
  199226. else return 0; \
  199227. }
  199228. #define JUCE_DECL_VOID_JACK_FUNCTION(fn_name, argument_types, arguments) \
  199229. typedef void (*fn_name##_ptr_t)argument_types; \
  199230. void fn_name argument_types { \
  199231. static fn_name##_ptr_t fn = 0; \
  199232. if (fn == 0) { fn = (fn_name##_ptr_t)juce_load_jack_function(#fn_name); } \
  199233. if (fn) (*fn)arguments; \
  199234. }
  199235. 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));
  199236. JUCE_DECL_JACK_FUNCTION (int, jack_client_close, (jack_client_t *client), (client));
  199237. JUCE_DECL_JACK_FUNCTION (int, jack_activate, (jack_client_t* client), (client));
  199238. JUCE_DECL_JACK_FUNCTION (int, jack_deactivate, (jack_client_t* client), (client));
  199239. JUCE_DECL_JACK_FUNCTION (jack_nframes_t, jack_get_buffer_size, (jack_client_t* client), (client));
  199240. JUCE_DECL_JACK_FUNCTION (jack_nframes_t, jack_get_sample_rate, (jack_client_t* client), (client));
  199241. JUCE_DECL_VOID_JACK_FUNCTION (jack_on_shutdown, (jack_client_t* client, void (*function)(void* arg), void* arg), (client, function, arg));
  199242. JUCE_DECL_JACK_FUNCTION (void* , jack_port_get_buffer, (jack_port_t* port, jack_nframes_t nframes), (port, nframes));
  199243. JUCE_DECL_JACK_FUNCTION (jack_nframes_t, jack_port_get_total_latency, (jack_client_t* client, jack_port_t* port), (client, port));
  199244. 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));
  199245. JUCE_DECL_VOID_JACK_FUNCTION (jack_set_error_function, (void (*func)(const char*)), (func));
  199246. JUCE_DECL_JACK_FUNCTION (int, jack_set_process_callback, (jack_client_t* client, JackProcessCallback process_callback, void* arg), (client, process_callback, arg));
  199247. 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));
  199248. JUCE_DECL_JACK_FUNCTION (int, jack_connect, (jack_client_t* client, const char* source_port, const char* destination_port), (client, source_port, destination_port));
  199249. JUCE_DECL_JACK_FUNCTION (const char*, jack_port_name, (const jack_port_t* port), (port));
  199250. JUCE_DECL_JACK_FUNCTION (int, jack_set_port_connect_callback, (jack_client_t* client, JackPortConnectCallback connect_callback, void* arg), (client, connect_callback, arg));
  199251. JUCE_DECL_JACK_FUNCTION (jack_port_t* , jack_port_by_id, (jack_client_t* client, jack_port_id_t port_id), (client, port_id));
  199252. JUCE_DECL_JACK_FUNCTION (int, jack_port_connected, (const jack_port_t* port), (port));
  199253. JUCE_DECL_JACK_FUNCTION (int, jack_port_connected_to, (const jack_port_t* port, const char* port_name), (port, port_name));
  199254. #if JUCE_DEBUG
  199255. #define JACK_LOGGING_ENABLED 1
  199256. #endif
  199257. #if JACK_LOGGING_ENABLED
  199258. static void jack_Log (const String& s)
  199259. {
  199260. puts (s);
  199261. }
  199262. static void dumpJackErrorMessage (const jack_status_t status) throw()
  199263. {
  199264. if (status & JackServerFailed || status & JackServerError)
  199265. jack_Log ("Unable to connect to JACK server");
  199266. if (status & JackVersionError)
  199267. jack_Log ("Client's protocol version does not match");
  199268. if (status & JackInvalidOption)
  199269. jack_Log ("The operation contained an invalid or unsupported option");
  199270. if (status & JackNameNotUnique)
  199271. jack_Log ("The desired client name was not unique");
  199272. if (status & JackNoSuchClient)
  199273. jack_Log ("Requested client does not exist");
  199274. if (status & JackInitFailure)
  199275. jack_Log ("Unable to initialize client");
  199276. }
  199277. #else
  199278. #define dumpJackErrorMessage(a) {}
  199279. #define jack_Log(...) {}
  199280. #endif
  199281. #ifndef JUCE_JACK_CLIENT_NAME
  199282. #define JUCE_JACK_CLIENT_NAME "JuceJack"
  199283. #endif
  199284. class JackAudioIODevice : public AudioIODevice
  199285. {
  199286. public:
  199287. JackAudioIODevice (const String& deviceName,
  199288. const String& inputId_,
  199289. const String& outputId_)
  199290. : AudioIODevice (deviceName, T("JACK")),
  199291. inputId (inputId_),
  199292. outputId (outputId_),
  199293. isOpen_ (false),
  199294. callback (0),
  199295. totalNumberOfInputChannels (0),
  199296. totalNumberOfOutputChannels (0)
  199297. {
  199298. jassert (deviceName.isNotEmpty());
  199299. jack_status_t status;
  199300. client = JUCE_NAMESPACE::jack_client_open (JUCE_JACK_CLIENT_NAME, JackNoStartServer, &status);
  199301. if (client == 0)
  199302. {
  199303. dumpJackErrorMessage (status);
  199304. }
  199305. else
  199306. {
  199307. JUCE_NAMESPACE::jack_set_error_function (errorCallback);
  199308. // open input ports
  199309. const StringArray inputChannels (getInputChannelNames());
  199310. for (int i = 0; i < inputChannels.size(); i++)
  199311. {
  199312. String inputName;
  199313. inputName << "in_" << (++totalNumberOfInputChannels);
  199314. inputPorts.add (JUCE_NAMESPACE::jack_port_register (client, (const char*) inputName,
  199315. JACK_DEFAULT_AUDIO_TYPE, JackPortIsInput, 0));
  199316. }
  199317. // open output ports
  199318. const StringArray outputChannels (getOutputChannelNames());
  199319. for (int i = 0; i < outputChannels.size (); i++)
  199320. {
  199321. String outputName;
  199322. outputName << "out_" << (++totalNumberOfOutputChannels);
  199323. outputPorts.add (JUCE_NAMESPACE::jack_port_register (client, (const char*) outputName,
  199324. JACK_DEFAULT_AUDIO_TYPE, JackPortIsOutput, 0));
  199325. }
  199326. inChans.calloc (totalNumberOfInputChannels + 2);
  199327. outChans.calloc (totalNumberOfOutputChannels + 2);
  199328. }
  199329. }
  199330. ~JackAudioIODevice()
  199331. {
  199332. close();
  199333. if (client != 0)
  199334. {
  199335. JUCE_NAMESPACE::jack_client_close (client);
  199336. client = 0;
  199337. }
  199338. }
  199339. const StringArray getChannelNames (bool forInput) const
  199340. {
  199341. StringArray names;
  199342. const char** const ports = JUCE_NAMESPACE::jack_get_ports (client, 0, 0, /* JackPortIsPhysical | */
  199343. forInput ? JackPortIsInput : JackPortIsOutput);
  199344. if (ports != 0)
  199345. {
  199346. int j = 0;
  199347. while (ports[j] != 0)
  199348. {
  199349. const String portName (ports [j++]);
  199350. if (portName.upToFirstOccurrenceOf (T(":"), false, false) == getName())
  199351. names.add (portName.fromFirstOccurrenceOf (T(":"), false, false));
  199352. }
  199353. free (ports);
  199354. }
  199355. return names;
  199356. }
  199357. const StringArray getOutputChannelNames() { return getChannelNames (false); }
  199358. const StringArray getInputChannelNames() { return getChannelNames (true); }
  199359. int getNumSampleRates() { return client != 0 ? 1 : 0; }
  199360. double getSampleRate (int index) { return client != 0 ? JUCE_NAMESPACE::jack_get_sample_rate (client) : 0; }
  199361. int getNumBufferSizesAvailable() { return client != 0 ? 1 : 0; }
  199362. int getBufferSizeSamples (int index) { return getDefaultBufferSize(); }
  199363. int getDefaultBufferSize() { return client != 0 ? JUCE_NAMESPACE::jack_get_buffer_size (client) : 0; }
  199364. const String open (const BitArray& inputChannels, const BitArray& outputChannels,
  199365. double sampleRate, int bufferSizeSamples)
  199366. {
  199367. if (client == 0)
  199368. {
  199369. lastError = T("No JACK client running");
  199370. return lastError;
  199371. }
  199372. lastError = String::empty;
  199373. close();
  199374. JUCE_NAMESPACE::jack_set_process_callback (client, processCallback, this);
  199375. JUCE_NAMESPACE::jack_on_shutdown (client, shutdownCallback, this);
  199376. JUCE_NAMESPACE::jack_activate (client);
  199377. isOpen_ = true;
  199378. if (! inputChannels.isEmpty())
  199379. {
  199380. const char** const ports = JUCE_NAMESPACE::jack_get_ports (client, 0, 0, /* JackPortIsPhysical | */ JackPortIsOutput);
  199381. if (ports != 0)
  199382. {
  199383. const int numInputChannels = inputChannels.getHighestBit () + 1;
  199384. for (int i = 0; i < numInputChannels; ++i)
  199385. {
  199386. const String portName (ports[i]);
  199387. if (inputChannels[i] && portName.upToFirstOccurrenceOf (T(":"), false, false) == getName())
  199388. {
  199389. int error = JUCE_NAMESPACE::jack_connect (client, ports[i], JUCE_NAMESPACE::jack_port_name ((jack_port_t*) inputPorts[i]));
  199390. if (error != 0)
  199391. jack_Log ("Cannot connect input port " + String (i) + " (" + String (ports[i]) + "), error " + String (error));
  199392. }
  199393. }
  199394. free (ports);
  199395. }
  199396. }
  199397. if (! outputChannels.isEmpty())
  199398. {
  199399. const char** const ports = JUCE_NAMESPACE::jack_get_ports (client, 0, 0, /* JackPortIsPhysical | */ JackPortIsInput);
  199400. if (ports != 0)
  199401. {
  199402. const int numOutputChannels = outputChannels.getHighestBit () + 1;
  199403. for (int i = 0; i < numOutputChannels; ++i)
  199404. {
  199405. const String portName (ports[i]);
  199406. if (outputChannels[i] && portName.upToFirstOccurrenceOf (T(":"), false, false) == getName())
  199407. {
  199408. int error = JUCE_NAMESPACE::jack_connect (client, JUCE_NAMESPACE::jack_port_name ((jack_port_t*) outputPorts[i]), ports[i]);
  199409. if (error != 0)
  199410. jack_Log ("Cannot connect output port " + String (i) + " (" + String (ports[i]) + "), error " + String (error));
  199411. }
  199412. }
  199413. free (ports);
  199414. }
  199415. }
  199416. return lastError;
  199417. }
  199418. void close()
  199419. {
  199420. stop();
  199421. if (client != 0)
  199422. {
  199423. JUCE_NAMESPACE::jack_deactivate (client);
  199424. JUCE_NAMESPACE::jack_set_process_callback (client, processCallback, 0);
  199425. JUCE_NAMESPACE::jack_on_shutdown (client, shutdownCallback, 0);
  199426. }
  199427. isOpen_ = false;
  199428. }
  199429. void start (AudioIODeviceCallback* newCallback)
  199430. {
  199431. if (isOpen_ && newCallback != callback)
  199432. {
  199433. if (newCallback != 0)
  199434. newCallback->audioDeviceAboutToStart (this);
  199435. AudioIODeviceCallback* const oldCallback = callback;
  199436. {
  199437. const ScopedLock sl (callbackLock);
  199438. callback = newCallback;
  199439. }
  199440. if (oldCallback != 0)
  199441. oldCallback->audioDeviceStopped();
  199442. }
  199443. }
  199444. void stop()
  199445. {
  199446. start (0);
  199447. }
  199448. bool isOpen() { return isOpen_; }
  199449. bool isPlaying() { return callback != 0; }
  199450. int getCurrentBufferSizeSamples() { return getBufferSizeSamples (0); }
  199451. double getCurrentSampleRate() { return getSampleRate (0); }
  199452. int getCurrentBitDepth() { return 32; }
  199453. const String getLastError() { return lastError; }
  199454. const BitArray getActiveOutputChannels() const
  199455. {
  199456. BitArray outputBits;
  199457. for (int i = 0; i < outputPorts.size(); i++)
  199458. if (JUCE_NAMESPACE::jack_port_connected ((jack_port_t*) outputPorts [i]))
  199459. outputBits.setBit (i);
  199460. return outputBits;
  199461. }
  199462. const BitArray getActiveInputChannels() const
  199463. {
  199464. BitArray inputBits;
  199465. for (int i = 0; i < inputPorts.size(); i++)
  199466. if (JUCE_NAMESPACE::jack_port_connected ((jack_port_t*) inputPorts [i]))
  199467. inputBits.setBit (i);
  199468. return inputBits;
  199469. }
  199470. int getOutputLatencyInSamples()
  199471. {
  199472. int latency = 0;
  199473. for (int i = 0; i < outputPorts.size(); i++)
  199474. latency = jmax (latency, (int) JUCE_NAMESPACE::jack_port_get_total_latency (client, (jack_port_t*) outputPorts [i]));
  199475. return latency;
  199476. }
  199477. int getInputLatencyInSamples()
  199478. {
  199479. int latency = 0;
  199480. for (int i = 0; i < inputPorts.size(); i++)
  199481. latency = jmax (latency, (int) JUCE_NAMESPACE::jack_port_get_total_latency (client, (jack_port_t*) inputPorts [i]));
  199482. return latency;
  199483. }
  199484. String inputId, outputId;
  199485. private:
  199486. void process (const int numSamples)
  199487. {
  199488. int i, numActiveInChans = 0, numActiveOutChans = 0;
  199489. for (i = 0; i < totalNumberOfInputChannels; ++i)
  199490. {
  199491. jack_default_audio_sample_t* in
  199492. = (jack_default_audio_sample_t*) JUCE_NAMESPACE::jack_port_get_buffer ((jack_port_t*) inputPorts.getUnchecked(i), numSamples);
  199493. if (in != 0)
  199494. inChans [numActiveInChans++] = (float*) in;
  199495. }
  199496. for (i = 0; i < totalNumberOfOutputChannels; ++i)
  199497. {
  199498. jack_default_audio_sample_t* out
  199499. = (jack_default_audio_sample_t*) JUCE_NAMESPACE::jack_port_get_buffer ((jack_port_t*) outputPorts.getUnchecked(i), numSamples);
  199500. if (out != 0)
  199501. outChans [numActiveOutChans++] = (float*) out;
  199502. }
  199503. const ScopedLock sl (callbackLock);
  199504. if (callback != 0)
  199505. {
  199506. callback->audioDeviceIOCallback ((const float**) inChans, numActiveInChans,
  199507. outChans, numActiveOutChans, numSamples);
  199508. }
  199509. else
  199510. {
  199511. for (i = 0; i < numActiveOutChans; ++i)
  199512. zeromem (outChans[i], sizeof (float) * numSamples);
  199513. }
  199514. }
  199515. static int processCallback (jack_nframes_t nframes, void* callbackArgument)
  199516. {
  199517. if (callbackArgument != 0)
  199518. ((JackAudioIODevice*) callbackArgument)->process (nframes);
  199519. return 0;
  199520. }
  199521. static void threadInitCallback (void* callbackArgument)
  199522. {
  199523. jack_Log ("JackAudioIODevice::initialise");
  199524. }
  199525. static void shutdownCallback (void* callbackArgument)
  199526. {
  199527. jack_Log ("JackAudioIODevice::shutdown");
  199528. JackAudioIODevice* device = (JackAudioIODevice*) callbackArgument;
  199529. if (device != 0)
  199530. {
  199531. device->client = 0;
  199532. device->close();
  199533. }
  199534. }
  199535. static void errorCallback (const char* msg)
  199536. {
  199537. jack_Log ("JackAudioIODevice::errorCallback " + String (msg));
  199538. }
  199539. bool isOpen_;
  199540. jack_client_t* client;
  199541. String lastError;
  199542. AudioIODeviceCallback* callback;
  199543. CriticalSection callbackLock;
  199544. HeapBlock <float*> inChans, outChans;
  199545. int totalNumberOfInputChannels;
  199546. int totalNumberOfOutputChannels;
  199547. VoidArray inputPorts, outputPorts;
  199548. };
  199549. class JackAudioIODeviceType : public AudioIODeviceType
  199550. {
  199551. public:
  199552. JackAudioIODeviceType()
  199553. : AudioIODeviceType (T("JACK")),
  199554. hasScanned (false)
  199555. {
  199556. }
  199557. ~JackAudioIODeviceType()
  199558. {
  199559. }
  199560. void scanForDevices()
  199561. {
  199562. hasScanned = true;
  199563. inputNames.clear();
  199564. inputIds.clear();
  199565. outputNames.clear();
  199566. outputIds.clear();
  199567. if (juce_libjack_handle == 0)
  199568. {
  199569. juce_libjack_handle = dlopen ("libjack.so", RTLD_LAZY);
  199570. if (juce_libjack_handle == 0)
  199571. return;
  199572. }
  199573. // open a dummy client
  199574. jack_status_t status;
  199575. jack_client_t* client = JUCE_NAMESPACE::jack_client_open ("JuceJackDummy", JackNoStartServer, &status);
  199576. if (client == 0)
  199577. {
  199578. dumpJackErrorMessage (status);
  199579. }
  199580. else
  199581. {
  199582. // scan for output devices
  199583. const char** ports = JUCE_NAMESPACE::jack_get_ports (client, 0, 0, /* JackPortIsPhysical | */ JackPortIsOutput);
  199584. if (ports != 0)
  199585. {
  199586. int j = 0;
  199587. while (ports[j] != 0)
  199588. {
  199589. String clientName (ports[j]);
  199590. clientName = clientName.upToFirstOccurrenceOf (T(":"), false, false);
  199591. if (clientName != String (JUCE_JACK_CLIENT_NAME)
  199592. && ! inputNames.contains (clientName))
  199593. {
  199594. inputNames.add (clientName);
  199595. inputIds.add (ports [j]);
  199596. }
  199597. ++j;
  199598. }
  199599. free (ports);
  199600. }
  199601. // scan for input devices
  199602. ports = JUCE_NAMESPACE::jack_get_ports (client, 0, 0, /* JackPortIsPhysical | */ JackPortIsInput);
  199603. if (ports != 0)
  199604. {
  199605. int j = 0;
  199606. while (ports[j] != 0)
  199607. {
  199608. String clientName (ports[j]);
  199609. clientName = clientName.upToFirstOccurrenceOf (T(":"), false, false);
  199610. if (clientName != String (JUCE_JACK_CLIENT_NAME)
  199611. && ! outputNames.contains (clientName))
  199612. {
  199613. outputNames.add (clientName);
  199614. outputIds.add (ports [j]);
  199615. }
  199616. ++j;
  199617. }
  199618. free (ports);
  199619. }
  199620. JUCE_NAMESPACE::jack_client_close (client);
  199621. }
  199622. }
  199623. const StringArray getDeviceNames (const bool wantInputNames) const
  199624. {
  199625. jassert (hasScanned); // need to call scanForDevices() before doing this
  199626. return wantInputNames ? inputNames : outputNames;
  199627. }
  199628. int getDefaultDeviceIndex (const bool forInput) const
  199629. {
  199630. jassert (hasScanned); // need to call scanForDevices() before doing this
  199631. return 0;
  199632. }
  199633. bool hasSeparateInputsAndOutputs() const { return true; }
  199634. int getIndexOfDevice (AudioIODevice* device, const bool asInput) const
  199635. {
  199636. jassert (hasScanned); // need to call scanForDevices() before doing this
  199637. JackAudioIODevice* const d = dynamic_cast <JackAudioIODevice*> (device);
  199638. if (d == 0)
  199639. return -1;
  199640. return asInput ? inputIds.indexOf (d->inputId)
  199641. : outputIds.indexOf (d->outputId);
  199642. }
  199643. AudioIODevice* createDevice (const String& outputDeviceName,
  199644. const String& inputDeviceName)
  199645. {
  199646. jassert (hasScanned); // need to call scanForDevices() before doing this
  199647. const int inputIndex = inputNames.indexOf (inputDeviceName);
  199648. const int outputIndex = outputNames.indexOf (outputDeviceName);
  199649. if (inputIndex >= 0 || outputIndex >= 0)
  199650. return new JackAudioIODevice (outputIndex >= 0 ? outputDeviceName
  199651. : inputDeviceName,
  199652. inputIds [inputIndex],
  199653. outputIds [outputIndex]);
  199654. return 0;
  199655. }
  199656. juce_UseDebuggingNewOperator
  199657. private:
  199658. StringArray inputNames, outputNames, inputIds, outputIds;
  199659. bool hasScanned;
  199660. JackAudioIODeviceType (const JackAudioIODeviceType&);
  199661. const JackAudioIODeviceType& operator= (const JackAudioIODeviceType&);
  199662. };
  199663. AudioIODeviceType* juce_createAudioIODeviceType_JACK()
  199664. {
  199665. return new JackAudioIODeviceType();
  199666. }
  199667. #else // if JACK is turned off..
  199668. AudioIODeviceType* juce_createAudioIODeviceType_JACK() { return 0; }
  199669. #endif
  199670. #endif
  199671. /********* End of inlined file: juce_linux_JackAudio.cpp *********/
  199672. /********* Start of inlined file: juce_linux_Midi.cpp *********/
  199673. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  199674. // compiled on its own).
  199675. #if JUCE_INCLUDED_FILE
  199676. #if JUCE_ALSA
  199677. static snd_seq_t* iterateDevices (const bool forInput,
  199678. StringArray& deviceNamesFound,
  199679. const int deviceIndexToOpen)
  199680. {
  199681. snd_seq_t* returnedHandle = 0;
  199682. snd_seq_t* seqHandle;
  199683. if (snd_seq_open (&seqHandle, "default", forInput ? SND_SEQ_OPEN_INPUT
  199684. : SND_SEQ_OPEN_OUTPUT, 0) == 0)
  199685. {
  199686. snd_seq_system_info_t* systemInfo;
  199687. snd_seq_client_info_t* clientInfo;
  199688. if (snd_seq_system_info_malloc (&systemInfo) == 0)
  199689. {
  199690. if (snd_seq_system_info (seqHandle, systemInfo) == 0
  199691. && snd_seq_client_info_malloc (&clientInfo) == 0)
  199692. {
  199693. int numClients = snd_seq_system_info_get_cur_clients (systemInfo);
  199694. while (--numClients >= 0 && returnedHandle == 0)
  199695. {
  199696. if (snd_seq_query_next_client (seqHandle, clientInfo) == 0)
  199697. {
  199698. snd_seq_port_info_t* portInfo;
  199699. if (snd_seq_port_info_malloc (&portInfo) == 0)
  199700. {
  199701. int numPorts = snd_seq_client_info_get_num_ports (clientInfo);
  199702. const int client = snd_seq_client_info_get_client (clientInfo);
  199703. snd_seq_port_info_set_client (portInfo, client);
  199704. snd_seq_port_info_set_port (portInfo, -1);
  199705. while (--numPorts >= 0)
  199706. {
  199707. if (snd_seq_query_next_port (seqHandle, portInfo) == 0
  199708. && (snd_seq_port_info_get_capability (portInfo)
  199709. & (forInput ? SND_SEQ_PORT_CAP_READ
  199710. : SND_SEQ_PORT_CAP_WRITE)) != 0)
  199711. {
  199712. deviceNamesFound.add (snd_seq_client_info_get_name (clientInfo));
  199713. if (deviceNamesFound.size() == deviceIndexToOpen + 1)
  199714. {
  199715. const int sourcePort = snd_seq_port_info_get_port (portInfo);
  199716. const int sourceClient = snd_seq_client_info_get_client (clientInfo);
  199717. if (sourcePort != -1)
  199718. {
  199719. snd_seq_set_client_name (seqHandle,
  199720. forInput ? "Juce Midi Input"
  199721. : "Juce Midi Output");
  199722. const int portId
  199723. = snd_seq_create_simple_port (seqHandle,
  199724. forInput ? "Juce Midi In Port"
  199725. : "Juce Midi Out Port",
  199726. forInput ? (SND_SEQ_PORT_CAP_WRITE | SND_SEQ_PORT_CAP_SUBS_WRITE)
  199727. : (SND_SEQ_PORT_CAP_READ | SND_SEQ_PORT_CAP_SUBS_READ),
  199728. SND_SEQ_PORT_TYPE_MIDI_GENERIC);
  199729. snd_seq_connect_from (seqHandle, portId, sourceClient, sourcePort);
  199730. returnedHandle = seqHandle;
  199731. }
  199732. }
  199733. }
  199734. }
  199735. snd_seq_port_info_free (portInfo);
  199736. }
  199737. }
  199738. }
  199739. snd_seq_client_info_free (clientInfo);
  199740. }
  199741. snd_seq_system_info_free (systemInfo);
  199742. }
  199743. if (returnedHandle == 0)
  199744. snd_seq_close (seqHandle);
  199745. }
  199746. deviceNamesFound.appendNumbersToDuplicates (true, true);
  199747. return returnedHandle;
  199748. }
  199749. static snd_seq_t* createDevice (const bool forInput,
  199750. const String& deviceNameToOpen)
  199751. {
  199752. snd_seq_t* seqHandle = 0;
  199753. if (snd_seq_open (&seqHandle, "default", forInput ? SND_SEQ_OPEN_INPUT
  199754. : SND_SEQ_OPEN_OUTPUT, 0) == 0)
  199755. {
  199756. snd_seq_set_client_name (seqHandle,
  199757. (const char*) (forInput ? (deviceNameToOpen + T(" Input"))
  199758. : (deviceNameToOpen + T(" Output"))));
  199759. const int portId
  199760. = snd_seq_create_simple_port (seqHandle,
  199761. forInput ? "in"
  199762. : "out",
  199763. forInput ? (SND_SEQ_PORT_CAP_WRITE | SND_SEQ_PORT_CAP_SUBS_WRITE)
  199764. : (SND_SEQ_PORT_CAP_READ | SND_SEQ_PORT_CAP_SUBS_READ),
  199765. forInput ? SND_SEQ_PORT_TYPE_APPLICATION
  199766. : SND_SEQ_PORT_TYPE_MIDI_GENERIC);
  199767. if (portId < 0)
  199768. {
  199769. snd_seq_close (seqHandle);
  199770. seqHandle = 0;
  199771. }
  199772. }
  199773. return seqHandle;
  199774. }
  199775. class MidiOutputDevice
  199776. {
  199777. public:
  199778. MidiOutputDevice (MidiOutput* const midiOutput_,
  199779. snd_seq_t* const seqHandle_)
  199780. :
  199781. midiOutput (midiOutput_),
  199782. seqHandle (seqHandle_),
  199783. maxEventSize (16 * 1024)
  199784. {
  199785. jassert (seqHandle != 0 && midiOutput != 0);
  199786. snd_midi_event_new (maxEventSize, &midiParser);
  199787. }
  199788. ~MidiOutputDevice()
  199789. {
  199790. snd_midi_event_free (midiParser);
  199791. snd_seq_close (seqHandle);
  199792. }
  199793. void sendMessageNow (const MidiMessage& message)
  199794. {
  199795. if (message.getRawDataSize() > maxEventSize)
  199796. {
  199797. maxEventSize = message.getRawDataSize();
  199798. snd_midi_event_free (midiParser);
  199799. snd_midi_event_new (maxEventSize, &midiParser);
  199800. }
  199801. snd_seq_event_t event;
  199802. snd_seq_ev_clear (&event);
  199803. snd_midi_event_encode (midiParser,
  199804. message.getRawData(),
  199805. message.getRawDataSize(),
  199806. &event);
  199807. snd_midi_event_reset_encode (midiParser);
  199808. snd_seq_ev_set_source (&event, 0);
  199809. snd_seq_ev_set_subs (&event);
  199810. snd_seq_ev_set_direct (&event);
  199811. snd_seq_event_output (seqHandle, &event);
  199812. snd_seq_drain_output (seqHandle);
  199813. }
  199814. juce_UseDebuggingNewOperator
  199815. private:
  199816. MidiOutput* const midiOutput;
  199817. snd_seq_t* const seqHandle;
  199818. snd_midi_event_t* midiParser;
  199819. int maxEventSize;
  199820. };
  199821. const StringArray MidiOutput::getDevices()
  199822. {
  199823. StringArray devices;
  199824. iterateDevices (false, devices, -1);
  199825. return devices;
  199826. }
  199827. int MidiOutput::getDefaultDeviceIndex()
  199828. {
  199829. return 0;
  199830. }
  199831. MidiOutput* MidiOutput::openDevice (int deviceIndex)
  199832. {
  199833. MidiOutput* newDevice = 0;
  199834. StringArray devices;
  199835. snd_seq_t* const handle = iterateDevices (false, devices, deviceIndex);
  199836. if (handle != 0)
  199837. {
  199838. newDevice = new MidiOutput();
  199839. newDevice->internal = new MidiOutputDevice (newDevice, handle);
  199840. }
  199841. return newDevice;
  199842. }
  199843. MidiOutput* MidiOutput::createNewDevice (const String& deviceName)
  199844. {
  199845. MidiOutput* newDevice = 0;
  199846. snd_seq_t* const handle = createDevice (false, deviceName);
  199847. if (handle != 0)
  199848. {
  199849. newDevice = new MidiOutput();
  199850. newDevice->internal = new MidiOutputDevice (newDevice, handle);
  199851. }
  199852. return newDevice;
  199853. }
  199854. MidiOutput::~MidiOutput()
  199855. {
  199856. MidiOutputDevice* const device = (MidiOutputDevice*) internal;
  199857. delete device;
  199858. }
  199859. void MidiOutput::reset()
  199860. {
  199861. }
  199862. bool MidiOutput::getVolume (float& leftVol, float& rightVol)
  199863. {
  199864. return false;
  199865. }
  199866. void MidiOutput::setVolume (float leftVol, float rightVol)
  199867. {
  199868. }
  199869. void MidiOutput::sendMessageNow (const MidiMessage& message)
  199870. {
  199871. ((MidiOutputDevice*) internal)->sendMessageNow (message);
  199872. }
  199873. class MidiInputThread : public Thread
  199874. {
  199875. public:
  199876. MidiInputThread (MidiInput* const midiInput_,
  199877. snd_seq_t* const seqHandle_,
  199878. MidiInputCallback* const callback_)
  199879. : Thread (T("Juce MIDI Input")),
  199880. midiInput (midiInput_),
  199881. seqHandle (seqHandle_),
  199882. callback (callback_)
  199883. {
  199884. jassert (seqHandle != 0 && callback != 0 && midiInput != 0);
  199885. }
  199886. ~MidiInputThread()
  199887. {
  199888. snd_seq_close (seqHandle);
  199889. }
  199890. void run()
  199891. {
  199892. const int maxEventSize = 16 * 1024;
  199893. snd_midi_event_t* midiParser;
  199894. if (snd_midi_event_new (maxEventSize, &midiParser) >= 0)
  199895. {
  199896. HeapBlock <uint8> buffer (maxEventSize);
  199897. const int numPfds = snd_seq_poll_descriptors_count (seqHandle, POLLIN);
  199898. struct pollfd* const pfd = (struct pollfd*) alloca (numPfds * sizeof (struct pollfd));
  199899. snd_seq_poll_descriptors (seqHandle, pfd, numPfds, POLLIN);
  199900. while (! threadShouldExit())
  199901. {
  199902. if (poll (pfd, numPfds, 500) > 0)
  199903. {
  199904. snd_seq_event_t* inputEvent = 0;
  199905. snd_seq_nonblock (seqHandle, 1);
  199906. do
  199907. {
  199908. if (snd_seq_event_input (seqHandle, &inputEvent) >= 0)
  199909. {
  199910. // xxx what about SYSEXes that are too big for the buffer?
  199911. const int numBytes = snd_midi_event_decode (midiParser, buffer, maxEventSize, inputEvent);
  199912. snd_midi_event_reset_decode (midiParser);
  199913. if (numBytes > 0)
  199914. {
  199915. const MidiMessage message ((const uint8*) buffer,
  199916. numBytes,
  199917. Time::getMillisecondCounter() * 0.001);
  199918. callback->handleIncomingMidiMessage (midiInput, message);
  199919. }
  199920. snd_seq_free_event (inputEvent);
  199921. }
  199922. }
  199923. while (snd_seq_event_input_pending (seqHandle, 0) > 0);
  199924. snd_seq_free_event (inputEvent);
  199925. }
  199926. }
  199927. snd_midi_event_free (midiParser);
  199928. }
  199929. };
  199930. juce_UseDebuggingNewOperator
  199931. private:
  199932. MidiInput* const midiInput;
  199933. snd_seq_t* const seqHandle;
  199934. MidiInputCallback* const callback;
  199935. };
  199936. MidiInput::MidiInput (const String& name_)
  199937. : name (name_),
  199938. internal (0)
  199939. {
  199940. }
  199941. MidiInput::~MidiInput()
  199942. {
  199943. stop();
  199944. MidiInputThread* const thread = (MidiInputThread*) internal;
  199945. delete thread;
  199946. }
  199947. void MidiInput::start()
  199948. {
  199949. ((MidiInputThread*) internal)->startThread();
  199950. }
  199951. void MidiInput::stop()
  199952. {
  199953. ((MidiInputThread*) internal)->stopThread (3000);
  199954. }
  199955. int MidiInput::getDefaultDeviceIndex()
  199956. {
  199957. return 0;
  199958. }
  199959. const StringArray MidiInput::getDevices()
  199960. {
  199961. StringArray devices;
  199962. iterateDevices (true, devices, -1);
  199963. return devices;
  199964. }
  199965. MidiInput* MidiInput::openDevice (int deviceIndex, MidiInputCallback* callback)
  199966. {
  199967. MidiInput* newDevice = 0;
  199968. StringArray devices;
  199969. snd_seq_t* const handle = iterateDevices (true, devices, deviceIndex);
  199970. if (handle != 0)
  199971. {
  199972. newDevice = new MidiInput (devices [deviceIndex]);
  199973. newDevice->internal = new MidiInputThread (newDevice, handle, callback);
  199974. }
  199975. return newDevice;
  199976. }
  199977. MidiInput* MidiInput::createNewDevice (const String& deviceName, MidiInputCallback* callback)
  199978. {
  199979. MidiInput* newDevice = 0;
  199980. snd_seq_t* const handle = createDevice (true, deviceName);
  199981. if (handle != 0)
  199982. {
  199983. newDevice = new MidiInput (deviceName);
  199984. newDevice->internal = new MidiInputThread (newDevice, handle, callback);
  199985. }
  199986. return newDevice;
  199987. }
  199988. #else
  199989. // (These are just stub functions if ALSA is unavailable...)
  199990. const StringArray MidiOutput::getDevices() { return StringArray(); }
  199991. int MidiOutput::getDefaultDeviceIndex() { return 0; }
  199992. MidiOutput* MidiOutput::openDevice (int) { return 0; }
  199993. MidiOutput* MidiOutput::createNewDevice (const String&) { return 0; }
  199994. MidiOutput::~MidiOutput() {}
  199995. void MidiOutput::reset() {}
  199996. bool MidiOutput::getVolume (float&, float&) { return false; }
  199997. void MidiOutput::setVolume (float, float) {}
  199998. void MidiOutput::sendMessageNow (const MidiMessage&) {}
  199999. MidiInput::MidiInput (const String& name_) : name (name_), internal (0) {}
  200000. MidiInput::~MidiInput() {}
  200001. void MidiInput::start() {}
  200002. void MidiInput::stop() {}
  200003. int MidiInput::getDefaultDeviceIndex() { return 0; }
  200004. const StringArray MidiInput::getDevices() { return StringArray(); }
  200005. MidiInput* MidiInput::openDevice (int, MidiInputCallback*) { return 0; }
  200006. MidiInput* MidiInput::createNewDevice (const String&, MidiInputCallback*) { return 0; }
  200007. #endif
  200008. #endif
  200009. /********* End of inlined file: juce_linux_Midi.cpp *********/
  200010. /********* Start of inlined file: juce_linux_AudioCDReader.cpp *********/
  200011. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  200012. // compiled on its own).
  200013. #if JUCE_INCLUDED_FILE && JUCE_USE_CDREADER
  200014. AudioCDReader::AudioCDReader()
  200015. : AudioFormatReader (0, T("CD Audio"))
  200016. {
  200017. }
  200018. const StringArray AudioCDReader::getAvailableCDNames()
  200019. {
  200020. StringArray names;
  200021. return names;
  200022. }
  200023. AudioCDReader* AudioCDReader::createReaderForCD (const int index)
  200024. {
  200025. return 0;
  200026. }
  200027. AudioCDReader::~AudioCDReader()
  200028. {
  200029. }
  200030. void AudioCDReader::refreshTrackLengths()
  200031. {
  200032. }
  200033. bool AudioCDReader::readSamples (int** destSamples, int numDestChannels, int startOffsetInDestBuffer,
  200034. int64 startSampleInFile, int numSamples)
  200035. {
  200036. return false;
  200037. }
  200038. bool AudioCDReader::isCDStillPresent() const
  200039. {
  200040. return false;
  200041. }
  200042. int AudioCDReader::getNumTracks() const
  200043. {
  200044. return 0;
  200045. }
  200046. int AudioCDReader::getPositionOfTrackStart (int trackNum) const
  200047. {
  200048. return 0;
  200049. }
  200050. bool AudioCDReader::isTrackAudio (int trackNum) const
  200051. {
  200052. return false;
  200053. }
  200054. void AudioCDReader::enableIndexScanning (bool b)
  200055. {
  200056. }
  200057. int AudioCDReader::getLastIndex() const
  200058. {
  200059. return 0;
  200060. }
  200061. const Array<int> AudioCDReader::findIndexesInTrack (const int trackNumber)
  200062. {
  200063. return Array<int>();
  200064. }
  200065. int AudioCDReader::getCDDBId()
  200066. {
  200067. return 0;
  200068. }
  200069. #endif
  200070. /********* End of inlined file: juce_linux_AudioCDReader.cpp *********/
  200071. /********* Start of inlined file: juce_linux_FileChooser.cpp *********/
  200072. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  200073. // compiled on its own).
  200074. #if JUCE_INCLUDED_FILE
  200075. void FileChooser::showPlatformDialog (Array<File>& results,
  200076. const String& title,
  200077. const File& file,
  200078. const String& filters,
  200079. bool isDirectory,
  200080. bool selectsFiles,
  200081. bool isSave,
  200082. bool warnAboutOverwritingExistingFiles,
  200083. bool selectMultipleFiles,
  200084. FilePreviewComponent* previewComponent)
  200085. {
  200086. const tchar* const separator = T(":");
  200087. String command ("zenity --file-selection");
  200088. if (title.isNotEmpty())
  200089. command << " --title=\"" << title << "\"";
  200090. if (file != File::nonexistent)
  200091. command << " --filename=\"" << file.getFullPathName () << "\"";
  200092. if (isDirectory)
  200093. command << " --directory";
  200094. if (isSave)
  200095. command << " --save";
  200096. if (selectMultipleFiles)
  200097. command << " --multiple --separator=\"" << separator << "\"";
  200098. command << " 2>&1";
  200099. MemoryOutputStream result;
  200100. int status = -1;
  200101. FILE* stream = popen ((const char*) command.toUTF8(), "r");
  200102. if (stream != 0)
  200103. {
  200104. for (;;)
  200105. {
  200106. char buffer [1024];
  200107. const int bytesRead = fread (buffer, 1, sizeof (buffer), stream);
  200108. if (bytesRead <= 0)
  200109. break;
  200110. result.write (buffer, bytesRead);
  200111. }
  200112. status = pclose (stream);
  200113. }
  200114. if (status == 0)
  200115. {
  200116. String resultString (String::fromUTF8 ((const uint8*) result.getData(), result.getDataSize()));
  200117. StringArray tokens;
  200118. if (selectMultipleFiles)
  200119. tokens.addTokens (resultString, separator, 0);
  200120. else
  200121. tokens.add (resultString);
  200122. for (int i = 0; i < tokens.size(); i++)
  200123. results.add (File (tokens[i]));
  200124. return;
  200125. }
  200126. //xxx ain't got one!
  200127. jassertfalse
  200128. }
  200129. #endif
  200130. /********* End of inlined file: juce_linux_FileChooser.cpp *********/
  200131. /********* Start of inlined file: juce_linux_WebBrowserComponent.cpp *********/
  200132. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  200133. // compiled on its own).
  200134. #if JUCE_INCLUDED_FILE && JUCE_WEB_BROWSER
  200135. WebBrowserComponent::WebBrowserComponent (const bool unloadPageWhenBrowserIsHidden_)
  200136. : browser (0),
  200137. blankPageShown (false),
  200138. unloadPageWhenBrowserIsHidden (unloadPageWhenBrowserIsHidden_)
  200139. {
  200140. setOpaque (true);
  200141. }
  200142. WebBrowserComponent::~WebBrowserComponent()
  200143. {
  200144. }
  200145. void WebBrowserComponent::goToURL (const String& url,
  200146. const StringArray* headers,
  200147. const MemoryBlock* postData)
  200148. {
  200149. lastURL = url;
  200150. lastHeaders.clear();
  200151. if (headers != 0)
  200152. lastHeaders = *headers;
  200153. lastPostData.setSize (0);
  200154. if (postData != 0)
  200155. lastPostData = *postData;
  200156. blankPageShown = false;
  200157. }
  200158. void WebBrowserComponent::stop()
  200159. {
  200160. }
  200161. void WebBrowserComponent::goBack()
  200162. {
  200163. lastURL = String::empty;
  200164. blankPageShown = false;
  200165. }
  200166. void WebBrowserComponent::goForward()
  200167. {
  200168. lastURL = String::empty;
  200169. }
  200170. void WebBrowserComponent::refresh()
  200171. {
  200172. }
  200173. void WebBrowserComponent::paint (Graphics& g)
  200174. {
  200175. g.fillAll (Colours::white);
  200176. }
  200177. void WebBrowserComponent::checkWindowAssociation()
  200178. {
  200179. }
  200180. void WebBrowserComponent::reloadLastURL()
  200181. {
  200182. if (lastURL.isNotEmpty())
  200183. {
  200184. goToURL (lastURL, &lastHeaders, &lastPostData);
  200185. lastURL = String::empty;
  200186. }
  200187. }
  200188. void WebBrowserComponent::parentHierarchyChanged()
  200189. {
  200190. checkWindowAssociation();
  200191. }
  200192. void WebBrowserComponent::resized()
  200193. {
  200194. }
  200195. void WebBrowserComponent::visibilityChanged()
  200196. {
  200197. checkWindowAssociation();
  200198. }
  200199. bool WebBrowserComponent::pageAboutToLoad (const String& url)
  200200. {
  200201. return true;
  200202. }
  200203. #endif
  200204. /********* End of inlined file: juce_linux_WebBrowserComponent.cpp *********/
  200205. #endif
  200206. END_JUCE_NAMESPACE
  200207. /********* End of inlined file: juce_linux_NativeCode.cpp *********/
  200208. #endif
  200209. #if JUCE_MAC || JUCE_IPHONE
  200210. /********* Start of inlined file: juce_mac_NativeCode.mm *********/
  200211. BEGIN_JUCE_NAMESPACE
  200212. #undef Point
  200213. #define JUCE_INCLUDED_FILE 1
  200214. // Now include the actual code files..
  200215. /********* Start of inlined file: juce_mac_ObjCSuffix.h *********/
  200216. #ifndef JUCE_ObjCExtraSuffix
  200217. #define JUCE_ObjCExtraSuffix 3
  200218. #endif
  200219. #define appendMacro1(a, b, c, d) a ## _ ## b ## _ ## c ## _ ## d
  200220. #define appendMacro2(a, b, c, d) appendMacro1(a, b, c, d)
  200221. #define MakeObjCClassName(rootName) appendMacro2 (rootName, JUCE_MAJOR_VERSION, JUCE_MINOR_VERSION, JUCE_ObjCExtraSuffix)
  200222. /********* End of inlined file: juce_mac_ObjCSuffix.h *********/
  200223. /********* Start of inlined file: juce_mac_Strings.mm *********/
  200224. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  200225. // compiled on its own).
  200226. #if JUCE_INCLUDED_FILE
  200227. static const String nsStringToJuce (NSString* s)
  200228. {
  200229. return String::fromUTF8 ((uint8*) [s UTF8String]);
  200230. }
  200231. static NSString* juceStringToNS (const String& s)
  200232. {
  200233. return [NSString stringWithUTF8String: (const char*) s.toUTF8()];
  200234. }
  200235. static const String convertUTF16ToString (const UniChar* utf16)
  200236. {
  200237. String s;
  200238. while (*utf16 != 0)
  200239. s += (juce_wchar) *utf16++;
  200240. return s;
  200241. }
  200242. const String PlatformUtilities::cfStringToJuceString (CFStringRef cfString)
  200243. {
  200244. String result;
  200245. if (cfString != 0)
  200246. {
  200247. #if JUCE_STRINGS_ARE_UNICODE
  200248. CFRange range = { 0, CFStringGetLength (cfString) };
  200249. HeapBlock <UniChar> u (range.length + 1);
  200250. CFStringGetCharacters (cfString, range, u);
  200251. u[range.length] = 0;
  200252. result = convertUTF16ToString (u);
  200253. #else
  200254. const int len = CFStringGetLength (cfString);
  200255. HeapBlock <char> buffer (len + 1);
  200256. CFStringGetCString (cfString, buffer, len + 1, CFStringGetSystemEncoding());
  200257. result = buffer;
  200258. #endif
  200259. }
  200260. return result;
  200261. }
  200262. CFStringRef PlatformUtilities::juceStringToCFString (const String& s)
  200263. {
  200264. #if JUCE_STRINGS_ARE_UNICODE
  200265. const int len = s.length();
  200266. const juce_wchar* t = (const juce_wchar*) s;
  200267. HeapBlock <UniChar> temp (len + 2);
  200268. for (int i = 0; i <= len; ++i)
  200269. temp[i] = t[i];
  200270. return CFStringCreateWithCharacters (kCFAllocatorDefault, temp, len);
  200271. #else
  200272. return CFStringCreateWithCString (kCFAllocatorDefault,
  200273. (const char*) s,
  200274. CFStringGetSystemEncoding());
  200275. #endif
  200276. }
  200277. const String PlatformUtilities::convertToPrecomposedUnicode (const String& s)
  200278. {
  200279. #if JUCE_IPHONE
  200280. const ScopedAutoReleasePool pool;
  200281. return nsStringToJuce ([juceStringToNS (s) precomposedStringWithCanonicalMapping]);
  200282. #else
  200283. UnicodeMapping map;
  200284. map.unicodeEncoding = CreateTextEncoding (kTextEncodingUnicodeDefault,
  200285. kUnicodeNoSubset,
  200286. kTextEncodingDefaultFormat);
  200287. map.otherEncoding = CreateTextEncoding (kTextEncodingUnicodeDefault,
  200288. kUnicodeCanonicalCompVariant,
  200289. kTextEncodingDefaultFormat);
  200290. map.mappingVersion = kUnicodeUseLatestMapping;
  200291. UnicodeToTextInfo conversionInfo = 0;
  200292. String result;
  200293. if (CreateUnicodeToTextInfo (&map, &conversionInfo) == noErr)
  200294. {
  200295. const int len = s.length();
  200296. HeapBlock <UniChar> tempIn, tempOut;
  200297. tempIn.calloc (len + 2);
  200298. tempOut.calloc (len + 2);
  200299. for (int i = 0; i <= len; ++i)
  200300. tempIn[i] = s[i];
  200301. ByteCount bytesRead = 0;
  200302. ByteCount outputBufferSize = 0;
  200303. if (ConvertFromUnicodeToText (conversionInfo,
  200304. len * sizeof (UniChar), tempIn,
  200305. kUnicodeDefaultDirectionMask,
  200306. 0, 0, 0, 0,
  200307. len * sizeof (UniChar), &bytesRead,
  200308. &outputBufferSize, tempOut) == noErr)
  200309. {
  200310. result.preallocateStorage (bytesRead / sizeof (UniChar) + 2);
  200311. tchar* t = const_cast <tchar*> ((const tchar*) result);
  200312. unsigned int i;
  200313. for (i = 0; i < bytesRead / sizeof (UniChar); ++i)
  200314. t[i] = (tchar) tempOut[i];
  200315. t[i] = 0;
  200316. }
  200317. DisposeUnicodeToTextInfo (&conversionInfo);
  200318. }
  200319. return result;
  200320. #endif
  200321. }
  200322. #if ! JUCE_ONLY_BUILD_CORE_LIBRARY
  200323. void SystemClipboard::copyTextToClipboard (const String& text) throw()
  200324. {
  200325. #if JUCE_IPHONE
  200326. [[UIPasteboard generalPasteboard] setValue: juceStringToNS (text)
  200327. forPasteboardType: @"public.text"];
  200328. #else
  200329. [[NSPasteboard generalPasteboard] declareTypes: [NSArray arrayWithObject: NSStringPboardType]
  200330. owner: nil];
  200331. [[NSPasteboard generalPasteboard] setString: juceStringToNS (text)
  200332. forType: NSStringPboardType];
  200333. #endif
  200334. }
  200335. const String SystemClipboard::getTextFromClipboard() throw()
  200336. {
  200337. #if JUCE_IPHONE
  200338. NSString* text = [[UIPasteboard generalPasteboard] valueForPasteboardType: @"public.text"];
  200339. #else
  200340. NSString* text = [[NSPasteboard generalPasteboard] stringForType: NSStringPboardType];
  200341. #endif
  200342. return text == 0 ? String::empty
  200343. : nsStringToJuce (text);
  200344. }
  200345. #endif
  200346. #endif
  200347. /********* End of inlined file: juce_mac_Strings.mm *********/
  200348. /********* Start of inlined file: juce_mac_SystemStats.mm *********/
  200349. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  200350. // compiled on its own).
  200351. #if JUCE_INCLUDED_FILE
  200352. static int64 highResTimerFrequency = 0;
  200353. static double highResTimerToMillisecRatio = 0;
  200354. #if JUCE_INTEL
  200355. static void juce_getCpuVendor (char* const v) throw()
  200356. {
  200357. int vendor[4];
  200358. zerostruct (vendor);
  200359. int dummy = 0;
  200360. asm ("mov %%ebx, %%esi \n\t"
  200361. "cpuid \n\t"
  200362. "xchg %%esi, %%ebx"
  200363. : "=a" (dummy), "=S" (vendor[0]), "=c" (vendor[2]), "=d" (vendor[1]) : "a" (0));
  200364. memcpy (v, vendor, 16);
  200365. }
  200366. static unsigned int getCPUIDWord (unsigned int& familyModel, unsigned int& extFeatures)
  200367. {
  200368. unsigned int cpu = 0;
  200369. unsigned int ext = 0;
  200370. unsigned int family = 0;
  200371. unsigned int dummy = 0;
  200372. asm ("mov %%ebx, %%esi \n\t"
  200373. "cpuid \n\t"
  200374. "xchg %%esi, %%ebx"
  200375. : "=a" (family), "=S" (ext), "=c" (dummy), "=d" (cpu) : "a" (1));
  200376. familyModel = family;
  200377. extFeatures = ext;
  200378. return cpu;
  200379. }
  200380. struct CPUFlags
  200381. {
  200382. bool hasMMX : 1;
  200383. bool hasSSE : 1;
  200384. bool hasSSE2 : 1;
  200385. bool has3DNow : 1;
  200386. };
  200387. static CPUFlags cpuFlags;
  200388. #endif
  200389. void SystemStats::initialiseStats() throw()
  200390. {
  200391. static bool initialised = false;
  200392. if (! initialised)
  200393. {
  200394. initialised = true;
  200395. #if JUCE_MAC
  200396. // extremely annoying: adding this line stops the apple menu items from working. Of
  200397. // course, not adding it means that carbon windows (e.g. in plugins) won't get
  200398. // any events.
  200399. //NSApplicationLoad();
  200400. [NSApplication sharedApplication];
  200401. #endif
  200402. #if JUCE_INTEL
  200403. {
  200404. unsigned int familyModel, extFeatures;
  200405. const unsigned int features = getCPUIDWord (familyModel, extFeatures);
  200406. cpuFlags.hasMMX = ((features & (1 << 23)) != 0);
  200407. cpuFlags.hasSSE = ((features & (1 << 25)) != 0);
  200408. cpuFlags.hasSSE2 = ((features & (1 << 26)) != 0);
  200409. cpuFlags.has3DNow = ((extFeatures & (1 << 31)) != 0);
  200410. }
  200411. #endif
  200412. mach_timebase_info_data_t timebase;
  200413. (void) mach_timebase_info (&timebase);
  200414. highResTimerFrequency = (int64) (1.0e9 * timebase.denom / timebase.numer);
  200415. highResTimerToMillisecRatio = timebase.numer / (1.0e6 * timebase.denom);
  200416. String s (SystemStats::getJUCEVersion());
  200417. rlimit lim;
  200418. getrlimit (RLIMIT_NOFILE, &lim);
  200419. lim.rlim_cur = lim.rlim_max = RLIM_INFINITY;
  200420. setrlimit (RLIMIT_NOFILE, &lim);
  200421. }
  200422. }
  200423. SystemStats::OperatingSystemType SystemStats::getOperatingSystemType() throw()
  200424. {
  200425. return MacOSX;
  200426. }
  200427. const String SystemStats::getOperatingSystemName() throw()
  200428. {
  200429. return T("Mac OS X");
  200430. }
  200431. bool SystemStats::isOperatingSystem64Bit() throw()
  200432. {
  200433. #if JUCE_64BIT
  200434. return true;
  200435. #else
  200436. //xxx not sure how to find this out?..
  200437. return false;
  200438. #endif
  200439. }
  200440. int SystemStats::getMemorySizeInMegabytes() throw()
  200441. {
  200442. uint64 mem = 0;
  200443. size_t memSize = sizeof (mem);
  200444. int mib[] = { CTL_HW, HW_MEMSIZE };
  200445. sysctl (mib, 2, &mem, &memSize, 0, 0);
  200446. return (int) (mem / (1024 * 1024));
  200447. }
  200448. bool SystemStats::hasMMX() throw()
  200449. {
  200450. #if JUCE_INTEL
  200451. return cpuFlags.hasMMX;
  200452. #else
  200453. return false;
  200454. #endif
  200455. }
  200456. bool SystemStats::hasSSE() throw()
  200457. {
  200458. #if JUCE_INTEL
  200459. return cpuFlags.hasSSE;
  200460. #else
  200461. return false;
  200462. #endif
  200463. }
  200464. bool SystemStats::hasSSE2() throw()
  200465. {
  200466. #if JUCE_INTEL
  200467. return cpuFlags.hasSSE2;
  200468. #else
  200469. return false;
  200470. #endif
  200471. }
  200472. bool SystemStats::has3DNow() throw()
  200473. {
  200474. #if JUCE_INTEL
  200475. return cpuFlags.has3DNow;
  200476. #else
  200477. return false;
  200478. #endif
  200479. }
  200480. const String SystemStats::getCpuVendor() throw()
  200481. {
  200482. #if JUCE_INTEL
  200483. char v [16];
  200484. juce_getCpuVendor (v);
  200485. return String (v, 16);
  200486. #else
  200487. return String::empty;
  200488. #endif
  200489. }
  200490. int SystemStats::getCpuSpeedInMegaherz() throw()
  200491. {
  200492. uint64 speedHz = 0;
  200493. size_t speedSize = sizeof (speedHz);
  200494. int mib[] = { CTL_HW, HW_CPU_FREQ };
  200495. sysctl (mib, 2, &speedHz, &speedSize, 0, 0);
  200496. #if JUCE_BIG_ENDIAN
  200497. if (speedSize == 4)
  200498. speedHz >>= 32;
  200499. #endif
  200500. return (int) (speedHz / 1000000);
  200501. }
  200502. int SystemStats::getNumCpus() throw()
  200503. {
  200504. #if JUCE_IPHONE || (MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5)
  200505. return (int) [[NSProcessInfo processInfo] activeProcessorCount];
  200506. #else
  200507. return MPProcessors();
  200508. #endif
  200509. }
  200510. uint32 juce_millisecondsSinceStartup() throw()
  200511. {
  200512. return (uint32) (mach_absolute_time() * highResTimerToMillisecRatio);
  200513. }
  200514. double Time::getMillisecondCounterHiRes() throw()
  200515. {
  200516. return mach_absolute_time() * highResTimerToMillisecRatio;
  200517. }
  200518. int64 Time::getHighResolutionTicks() throw()
  200519. {
  200520. return (int64) mach_absolute_time();
  200521. }
  200522. int64 Time::getHighResolutionTicksPerSecond() throw()
  200523. {
  200524. return highResTimerFrequency;
  200525. }
  200526. int64 SystemStats::getClockCycleCounter() throw()
  200527. {
  200528. return (int64) mach_absolute_time();
  200529. }
  200530. bool Time::setSystemTimeToThisTime() const throw()
  200531. {
  200532. jassertfalse
  200533. return false;
  200534. }
  200535. int SystemStats::getPageSize() throw()
  200536. {
  200537. return (int) NSPageSize();
  200538. }
  200539. void PlatformUtilities::fpuReset()
  200540. {
  200541. }
  200542. #endif
  200543. /********* End of inlined file: juce_mac_SystemStats.mm *********/
  200544. /********* Start of inlined file: juce_mac_Network.mm *********/
  200545. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  200546. // compiled on its own).
  200547. #if JUCE_INCLUDED_FILE
  200548. int SystemStats::getMACAddresses (int64* addresses, int maxNum, const bool littleEndian) throw()
  200549. {
  200550. #ifndef IFT_ETHER
  200551. #define IFT_ETHER 6
  200552. #endif
  200553. ifaddrs* addrs = 0;
  200554. int numResults = 0;
  200555. if (getifaddrs (&addrs) == 0)
  200556. {
  200557. const ifaddrs* cursor = addrs;
  200558. while (cursor != 0 && numResults < maxNum)
  200559. {
  200560. if (cursor->ifa_addr->sa_family == AF_LINK)
  200561. {
  200562. const sockaddr_dl* const sadd = (const sockaddr_dl*) cursor->ifa_addr;
  200563. if (sadd->sdl_type == IFT_ETHER)
  200564. {
  200565. const uint8* const addr = ((const uint8*) sadd->sdl_data) + sadd->sdl_nlen;
  200566. uint64 a = 0;
  200567. for (int i = 6; --i >= 0;)
  200568. a = (a << 8) | addr [littleEndian ? i : (5 - i)];
  200569. *addresses++ = (int64) a;
  200570. ++numResults;
  200571. }
  200572. }
  200573. cursor = cursor->ifa_next;
  200574. }
  200575. freeifaddrs (addrs);
  200576. }
  200577. return numResults;
  200578. }
  200579. bool PlatformUtilities::launchEmailWithAttachments (const String& targetEmailAddress,
  200580. const String& emailSubject,
  200581. const String& bodyText,
  200582. const StringArray& filesToAttach)
  200583. {
  200584. #if JUCE_IPHONE
  200585. //xxx probably need to use MFMailComposeViewController
  200586. jassertfalse
  200587. return false;
  200588. #else
  200589. const ScopedAutoReleasePool pool;
  200590. String script;
  200591. script << "tell application \"Mail\"\r\n"
  200592. "set newMessage to make new outgoing message with properties {subject:\""
  200593. << emailSubject.replace (T("\""), T("\\\""))
  200594. << "\", content:\""
  200595. << bodyText.replace (T("\""), T("\\\""))
  200596. << "\" & return & return}\r\n"
  200597. "tell newMessage\r\n"
  200598. "set visible to true\r\n"
  200599. "set sender to \"sdfsdfsdfewf\"\r\n"
  200600. "make new to recipient at end of to recipients with properties {address:\""
  200601. << targetEmailAddress
  200602. << "\"}\r\n";
  200603. for (int i = 0; i < filesToAttach.size(); ++i)
  200604. {
  200605. script << "tell content\r\n"
  200606. "make new attachment with properties {file name:\""
  200607. << filesToAttach[i].replace (T("\""), T("\\\""))
  200608. << "\"} at after the last paragraph\r\n"
  200609. "end tell\r\n";
  200610. }
  200611. script << "end tell\r\n"
  200612. "end tell\r\n";
  200613. NSAppleScript* s = [[NSAppleScript alloc]
  200614. initWithSource: juceStringToNS (script)];
  200615. NSDictionary* error = 0;
  200616. const bool ok = [s executeAndReturnError: &error] != nil;
  200617. [s release];
  200618. return ok;
  200619. #endif
  200620. }
  200621. END_JUCE_NAMESPACE
  200622. using namespace JUCE_NAMESPACE;
  200623. #define JuceURLConnection MakeObjCClassName(JuceURLConnection)
  200624. @interface JuceURLConnection : NSObject
  200625. {
  200626. @public
  200627. NSURLRequest* request;
  200628. NSURLConnection* connection;
  200629. NSMutableData* data;
  200630. Thread* runLoopThread;
  200631. bool initialised, hasFailed, hasFinished;
  200632. int position;
  200633. int64 contentLength;
  200634. NSLock* dataLock;
  200635. }
  200636. - (JuceURLConnection*) initWithRequest: (NSURLRequest*) req withCallback: (URL::OpenStreamProgressCallback*) callback withContext: (void*) context;
  200637. - (void) dealloc;
  200638. - (void) connection: (NSURLConnection*) connection didReceiveResponse: (NSURLResponse*) response;
  200639. - (void) connection: (NSURLConnection*) connection didFailWithError: (NSError*) error;
  200640. - (void) connection: (NSURLConnection*) connection didReceiveData: (NSData*) data;
  200641. - (void) connectionDidFinishLoading: (NSURLConnection*) connection;
  200642. - (BOOL) isOpen;
  200643. - (int) read: (char*) dest numBytes: (int) num;
  200644. - (int) readPosition;
  200645. - (void) stop;
  200646. - (void) createConnection;
  200647. @end
  200648. class JuceURLConnectionMessageThread : public Thread
  200649. {
  200650. JuceURLConnection* owner;
  200651. public:
  200652. JuceURLConnectionMessageThread (JuceURLConnection* owner_)
  200653. : Thread (T("http connection")),
  200654. owner (owner_)
  200655. {
  200656. }
  200657. ~JuceURLConnectionMessageThread()
  200658. {
  200659. stopThread (10000);
  200660. }
  200661. void run()
  200662. {
  200663. [owner createConnection];
  200664. while (! threadShouldExit())
  200665. {
  200666. const ScopedAutoReleasePool pool;
  200667. [[NSRunLoop currentRunLoop] runUntilDate: [NSDate dateWithTimeIntervalSinceNow: 0.01]];
  200668. }
  200669. }
  200670. };
  200671. @implementation JuceURLConnection
  200672. - (JuceURLConnection*) initWithRequest: (NSURLRequest*) req
  200673. withCallback: (URL::OpenStreamProgressCallback*) callback
  200674. withContext: (void*) context;
  200675. {
  200676. [super init];
  200677. request = req;
  200678. [request retain];
  200679. data = [[NSMutableData data] retain];
  200680. dataLock = [[NSLock alloc] init];
  200681. connection = 0;
  200682. initialised = false;
  200683. hasFailed = false;
  200684. hasFinished = false;
  200685. contentLength = -1;
  200686. runLoopThread = new JuceURLConnectionMessageThread (self);
  200687. runLoopThread->startThread();
  200688. while (runLoopThread->isThreadRunning() && ! initialised)
  200689. {
  200690. if (callback != 0)
  200691. callback (context, -1, (int) [[request HTTPBody] length]);
  200692. Thread::sleep (1);
  200693. }
  200694. return self;
  200695. }
  200696. - (void) dealloc
  200697. {
  200698. [self stop];
  200699. delete runLoopThread;
  200700. [connection release];
  200701. [data release];
  200702. [dataLock release];
  200703. [request release];
  200704. [super dealloc];
  200705. }
  200706. - (void) createConnection
  200707. {
  200708. connection = [[NSURLConnection alloc] initWithRequest: request
  200709. delegate: [self retain]];
  200710. if (connection == nil)
  200711. runLoopThread->signalThreadShouldExit();
  200712. }
  200713. - (void) connection: (NSURLConnection*) connection didReceiveResponse: (NSURLResponse*) response
  200714. {
  200715. [dataLock lock];
  200716. [data setLength: 0];
  200717. [dataLock unlock];
  200718. initialised = true;
  200719. contentLength = [response expectedContentLength];
  200720. }
  200721. - (void) connection: (NSURLConnection*) connection didFailWithError: (NSError*) error
  200722. {
  200723. DBG (nsStringToJuce ([error description]));
  200724. hasFailed = true;
  200725. initialised = true;
  200726. runLoopThread->signalThreadShouldExit();
  200727. }
  200728. - (void) connection: (NSURLConnection*) connection didReceiveData: (NSData*) newData
  200729. {
  200730. [dataLock lock];
  200731. [data appendData: newData];
  200732. [dataLock unlock];
  200733. initialised = true;
  200734. }
  200735. - (void) connectionDidFinishLoading: (NSURLConnection*) connection
  200736. {
  200737. hasFinished = true;
  200738. initialised = true;
  200739. runLoopThread->signalThreadShouldExit();
  200740. }
  200741. - (BOOL) isOpen
  200742. {
  200743. return connection != 0 && ! hasFailed;
  200744. }
  200745. - (int) readPosition
  200746. {
  200747. return position;
  200748. }
  200749. - (int) read: (char*) dest numBytes: (int) numNeeded
  200750. {
  200751. int numDone = 0;
  200752. while (numNeeded > 0)
  200753. {
  200754. int available = jmin (numNeeded, (int) [data length]);
  200755. if (available > 0)
  200756. {
  200757. [dataLock lock];
  200758. [data getBytes: dest length: available];
  200759. [data replaceBytesInRange: NSMakeRange (0, available) withBytes: nil length: 0];
  200760. [dataLock unlock];
  200761. numDone += available;
  200762. numNeeded -= available;
  200763. dest += available;
  200764. }
  200765. else
  200766. {
  200767. if (hasFailed || hasFinished)
  200768. break;
  200769. Thread::sleep (1);
  200770. }
  200771. }
  200772. position += numDone;
  200773. return numDone;
  200774. }
  200775. - (void) stop
  200776. {
  200777. [connection cancel];
  200778. runLoopThread->stopThread (10000);
  200779. }
  200780. @end
  200781. BEGIN_JUCE_NAMESPACE
  200782. bool juce_isOnLine()
  200783. {
  200784. return true;
  200785. }
  200786. void* juce_openInternetFile (const String& url,
  200787. const String& headers,
  200788. const MemoryBlock& postData,
  200789. const bool isPost,
  200790. URL::OpenStreamProgressCallback* callback,
  200791. void* callbackContext,
  200792. int timeOutMs)
  200793. {
  200794. const ScopedAutoReleasePool pool;
  200795. NSMutableURLRequest* req = [NSMutableURLRequest
  200796. requestWithURL: [NSURL URLWithString: juceStringToNS (url)]
  200797. cachePolicy: NSURLRequestUseProtocolCachePolicy
  200798. timeoutInterval: timeOutMs <= 0 ? 60.0 : (timeOutMs / 1000.0)];
  200799. if (req == nil)
  200800. return 0;
  200801. [req setHTTPMethod: isPost ? @"POST" : @"GET"];
  200802. //[req setCachePolicy: NSURLRequestReloadIgnoringLocalAndRemoteCacheData];
  200803. StringArray headerLines;
  200804. headerLines.addLines (headers);
  200805. headerLines.removeEmptyStrings (true);
  200806. for (int i = 0; i < headerLines.size(); ++i)
  200807. {
  200808. const String key (headerLines[i].upToFirstOccurrenceOf (T(":"), false, false).trim());
  200809. const String value (headerLines[i].fromFirstOccurrenceOf (T(":"), false, false).trim());
  200810. if (key.isNotEmpty() && value.isNotEmpty())
  200811. [req addValue: juceStringToNS (value) forHTTPHeaderField: juceStringToNS (key)];
  200812. }
  200813. if (isPost && postData.getSize() > 0)
  200814. {
  200815. [req setHTTPBody: [NSData dataWithBytes: postData.getData()
  200816. length: postData.getSize()]];
  200817. }
  200818. JuceURLConnection* const s = [[JuceURLConnection alloc] initWithRequest: req
  200819. withCallback: callback
  200820. withContext: callbackContext];
  200821. if ([s isOpen])
  200822. return s;
  200823. [s release];
  200824. return 0;
  200825. }
  200826. void juce_closeInternetFile (void* handle)
  200827. {
  200828. JuceURLConnection* const s = (JuceURLConnection*) handle;
  200829. if (s != 0)
  200830. {
  200831. const ScopedAutoReleasePool pool;
  200832. [s stop];
  200833. [s release];
  200834. }
  200835. }
  200836. int juce_readFromInternetFile (void* handle, void* buffer, int bytesToRead)
  200837. {
  200838. JuceURLConnection* const s = (JuceURLConnection*) handle;
  200839. if (s != 0)
  200840. {
  200841. const ScopedAutoReleasePool pool;
  200842. return [s read: (char*) buffer numBytes: bytesToRead];
  200843. }
  200844. return 0;
  200845. }
  200846. int64 juce_getInternetFileContentLength (void* handle)
  200847. {
  200848. JuceURLConnection* const s = (JuceURLConnection*) handle;
  200849. if (s != 0)
  200850. return s->contentLength;
  200851. return -1;
  200852. }
  200853. int juce_seekInInternetFile (void* handle, int newPosition)
  200854. {
  200855. JuceURLConnection* const s = (JuceURLConnection*) handle;
  200856. if (s != 0)
  200857. return [s readPosition];
  200858. return 0;
  200859. }
  200860. #endif
  200861. /********* End of inlined file: juce_mac_Network.mm *********/
  200862. /********* Start of inlined file: juce_posix_NamedPipe.cpp *********/
  200863. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  200864. // compiled on its own).
  200865. #if JUCE_INCLUDED_FILE
  200866. struct NamedPipeInternal
  200867. {
  200868. String pipeInName, pipeOutName;
  200869. int pipeIn, pipeOut;
  200870. bool volatile createdPipe, blocked, stopReadOperation;
  200871. static void signalHandler (int) {}
  200872. };
  200873. void NamedPipe::cancelPendingReads()
  200874. {
  200875. while (internal != 0 && ((NamedPipeInternal*) internal)->blocked)
  200876. {
  200877. NamedPipeInternal* const intern = (NamedPipeInternal*) internal;
  200878. intern->stopReadOperation = true;
  200879. char buffer [1] = { 0 };
  200880. int bytesWritten = (int) ::write (intern->pipeIn, buffer, 1);
  200881. (void) bytesWritten;
  200882. int timeout = 2000;
  200883. while (intern->blocked && --timeout >= 0)
  200884. Thread::sleep (2);
  200885. intern->stopReadOperation = false;
  200886. }
  200887. }
  200888. void NamedPipe::close()
  200889. {
  200890. NamedPipeInternal* const intern = (NamedPipeInternal*) internal;
  200891. if (intern != 0)
  200892. {
  200893. internal = 0;
  200894. if (intern->pipeIn != -1)
  200895. ::close (intern->pipeIn);
  200896. if (intern->pipeOut != -1)
  200897. ::close (intern->pipeOut);
  200898. if (intern->createdPipe)
  200899. {
  200900. unlink (intern->pipeInName);
  200901. unlink (intern->pipeOutName);
  200902. }
  200903. delete intern;
  200904. }
  200905. }
  200906. bool NamedPipe::openInternal (const String& pipeName, const bool createPipe)
  200907. {
  200908. close();
  200909. NamedPipeInternal* const intern = new NamedPipeInternal();
  200910. internal = intern;
  200911. intern->createdPipe = createPipe;
  200912. intern->blocked = false;
  200913. intern->stopReadOperation = false;
  200914. signal (SIGPIPE, NamedPipeInternal::signalHandler);
  200915. siginterrupt (SIGPIPE, 1);
  200916. const String pipePath (T("/tmp/") + File::createLegalFileName (pipeName));
  200917. intern->pipeInName = pipePath + T("_in");
  200918. intern->pipeOutName = pipePath + T("_out");
  200919. intern->pipeIn = -1;
  200920. intern->pipeOut = -1;
  200921. if (createPipe)
  200922. {
  200923. if ((mkfifo (intern->pipeInName, 0666) && errno != EEXIST)
  200924. || (mkfifo (intern->pipeOutName, 0666) && errno != EEXIST))
  200925. {
  200926. delete intern;
  200927. internal = 0;
  200928. return false;
  200929. }
  200930. }
  200931. return true;
  200932. }
  200933. int NamedPipe::read (void* destBuffer, int maxBytesToRead, int /*timeOutMilliseconds*/)
  200934. {
  200935. int bytesRead = -1;
  200936. NamedPipeInternal* const intern = (NamedPipeInternal*) internal;
  200937. if (intern != 0)
  200938. {
  200939. intern->blocked = true;
  200940. if (intern->pipeIn == -1)
  200941. {
  200942. if (intern->createdPipe)
  200943. intern->pipeIn = ::open (intern->pipeInName, O_RDWR);
  200944. else
  200945. intern->pipeIn = ::open (intern->pipeOutName, O_RDWR);
  200946. if (intern->pipeIn == -1)
  200947. {
  200948. intern->blocked = false;
  200949. return -1;
  200950. }
  200951. }
  200952. bytesRead = 0;
  200953. char* p = (char*) destBuffer;
  200954. while (bytesRead < maxBytesToRead)
  200955. {
  200956. const int bytesThisTime = maxBytesToRead - bytesRead;
  200957. const int numRead = (int) ::read (intern->pipeIn, p, bytesThisTime);
  200958. if (numRead <= 0 || intern->stopReadOperation)
  200959. {
  200960. bytesRead = -1;
  200961. break;
  200962. }
  200963. bytesRead += numRead;
  200964. p += bytesRead;
  200965. }
  200966. intern->blocked = false;
  200967. }
  200968. return bytesRead;
  200969. }
  200970. int NamedPipe::write (const void* sourceBuffer, int numBytesToWrite, int timeOutMilliseconds)
  200971. {
  200972. int bytesWritten = -1;
  200973. NamedPipeInternal* const intern = (NamedPipeInternal*) internal;
  200974. if (intern != 0)
  200975. {
  200976. if (intern->pipeOut == -1)
  200977. {
  200978. if (intern->createdPipe)
  200979. intern->pipeOut = ::open (intern->pipeOutName, O_WRONLY);
  200980. else
  200981. intern->pipeOut = ::open (intern->pipeInName, O_WRONLY);
  200982. if (intern->pipeOut == -1)
  200983. {
  200984. return -1;
  200985. }
  200986. }
  200987. const char* p = (const char*) sourceBuffer;
  200988. bytesWritten = 0;
  200989. const uint32 timeOutTime = Time::getMillisecondCounter() + timeOutMilliseconds;
  200990. while (bytesWritten < numBytesToWrite
  200991. && (timeOutMilliseconds < 0 || Time::getMillisecondCounter() < timeOutTime))
  200992. {
  200993. const int bytesThisTime = numBytesToWrite - bytesWritten;
  200994. const int numWritten = (int) ::write (intern->pipeOut, p, bytesThisTime);
  200995. if (numWritten <= 0)
  200996. {
  200997. bytesWritten = -1;
  200998. break;
  200999. }
  201000. bytesWritten += numWritten;
  201001. p += bytesWritten;
  201002. }
  201003. }
  201004. return bytesWritten;
  201005. }
  201006. #endif
  201007. /********* End of inlined file: juce_posix_NamedPipe.cpp *********/
  201008. /********* Start of inlined file: juce_mac_Threads.mm *********/
  201009. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  201010. // compiled on its own).
  201011. #if JUCE_INCLUDED_FILE
  201012. void JUCE_API juce_threadEntryPoint (void*);
  201013. void* threadEntryProc (void* userData)
  201014. {
  201015. const ScopedAutoReleasePool pool;
  201016. juce_threadEntryPoint (userData);
  201017. return 0;
  201018. }
  201019. void* juce_createThread (void* userData)
  201020. {
  201021. pthread_t handle = 0;
  201022. if (pthread_create (&handle, 0, threadEntryProc, userData) == 0)
  201023. {
  201024. pthread_detach (handle);
  201025. return (void*) handle;
  201026. }
  201027. return 0;
  201028. }
  201029. void juce_killThread (void* handle)
  201030. {
  201031. if (handle != 0)
  201032. pthread_cancel ((pthread_t) handle);
  201033. }
  201034. void juce_setCurrentThreadName (const String& /*name*/)
  201035. {
  201036. }
  201037. Thread::ThreadID Thread::getCurrentThreadId()
  201038. {
  201039. return (ThreadID) pthread_self();
  201040. }
  201041. bool juce_setThreadPriority (void* handle, int priority)
  201042. {
  201043. if (handle == 0)
  201044. handle = (void*) pthread_self();
  201045. struct sched_param param;
  201046. int policy;
  201047. pthread_getschedparam ((pthread_t) handle, &policy, &param);
  201048. param.sched_priority = jlimit (1, 127, 1 + (priority * 126) / 11);
  201049. return pthread_setschedparam ((pthread_t) handle, policy, &param) == 0;
  201050. }
  201051. void Thread::yield()
  201052. {
  201053. sched_yield();
  201054. }
  201055. void Thread::setCurrentThreadAffinityMask (const uint32 affinityMask)
  201056. {
  201057. // xxx
  201058. jassertfalse
  201059. }
  201060. bool Process::isForegroundProcess()
  201061. {
  201062. #if JUCE_MAC
  201063. return [NSApp isActive];
  201064. #else
  201065. return true; // xxx change this if more than one app is ever possible on the iPhone!
  201066. #endif
  201067. }
  201068. void Process::raisePrivilege()
  201069. {
  201070. jassertfalse
  201071. }
  201072. void Process::lowerPrivilege()
  201073. {
  201074. jassertfalse
  201075. }
  201076. void Process::terminate()
  201077. {
  201078. exit (0);
  201079. }
  201080. void Process::setPriority (ProcessPriority p)
  201081. {
  201082. // xxx
  201083. }
  201084. #endif
  201085. /********* End of inlined file: juce_mac_Threads.mm *********/
  201086. /********* Start of inlined file: juce_posix_SharedCode.h *********/
  201087. CriticalSection::CriticalSection() throw()
  201088. {
  201089. pthread_mutexattr_t atts;
  201090. pthread_mutexattr_init (&atts);
  201091. pthread_mutexattr_settype (&atts, PTHREAD_MUTEX_RECURSIVE);
  201092. pthread_mutex_init (&internal, &atts);
  201093. }
  201094. CriticalSection::~CriticalSection() throw()
  201095. {
  201096. pthread_mutex_destroy (&internal);
  201097. }
  201098. void CriticalSection::enter() const throw()
  201099. {
  201100. pthread_mutex_lock (&internal);
  201101. }
  201102. bool CriticalSection::tryEnter() const throw()
  201103. {
  201104. return pthread_mutex_trylock (&internal) == 0;
  201105. }
  201106. void CriticalSection::exit() const throw()
  201107. {
  201108. pthread_mutex_unlock (&internal);
  201109. }
  201110. struct EventStruct
  201111. {
  201112. pthread_cond_t condition;
  201113. pthread_mutex_t mutex;
  201114. bool triggered;
  201115. };
  201116. WaitableEvent::WaitableEvent() throw()
  201117. {
  201118. EventStruct* const es = new EventStruct();
  201119. es->triggered = false;
  201120. pthread_cond_init (&es->condition, 0);
  201121. pthread_mutex_init (&es->mutex, 0);
  201122. internal = es;
  201123. }
  201124. WaitableEvent::~WaitableEvent() throw()
  201125. {
  201126. EventStruct* const es = (EventStruct*) internal;
  201127. pthread_cond_destroy (&es->condition);
  201128. pthread_mutex_destroy (&es->mutex);
  201129. delete es;
  201130. }
  201131. bool WaitableEvent::wait (const int timeOutMillisecs) const throw()
  201132. {
  201133. EventStruct* const es = (EventStruct*) internal;
  201134. pthread_mutex_lock (&es->mutex);
  201135. if (timeOutMillisecs < 0)
  201136. {
  201137. while (! es->triggered)
  201138. pthread_cond_wait (&es->condition, &es->mutex);
  201139. }
  201140. else
  201141. {
  201142. while (! es->triggered)
  201143. {
  201144. struct timeval t;
  201145. gettimeofday (&t, 0);
  201146. struct timespec time;
  201147. time.tv_sec = t.tv_sec + (timeOutMillisecs / 1000);
  201148. time.tv_nsec = (t.tv_usec + ((timeOutMillisecs % 1000) * 1000)) * 1000;
  201149. if (time.tv_nsec >= 1000000000)
  201150. {
  201151. time.tv_nsec -= 1000000000;
  201152. time.tv_sec++;
  201153. }
  201154. if (pthread_cond_timedwait (&es->condition, &es->mutex, &time) == ETIMEDOUT)
  201155. {
  201156. pthread_mutex_unlock (&es->mutex);
  201157. return false;
  201158. }
  201159. }
  201160. }
  201161. es->triggered = false;
  201162. pthread_mutex_unlock (&es->mutex);
  201163. return true;
  201164. }
  201165. void WaitableEvent::signal() const throw()
  201166. {
  201167. EventStruct* const es = (EventStruct*) internal;
  201168. pthread_mutex_lock (&es->mutex);
  201169. es->triggered = true;
  201170. pthread_cond_broadcast (&es->condition);
  201171. pthread_mutex_unlock (&es->mutex);
  201172. }
  201173. void WaitableEvent::reset() const throw()
  201174. {
  201175. EventStruct* const es = (EventStruct*) internal;
  201176. pthread_mutex_lock (&es->mutex);
  201177. es->triggered = false;
  201178. pthread_mutex_unlock (&es->mutex);
  201179. }
  201180. void JUCE_CALLTYPE Thread::sleep (int millisecs)
  201181. {
  201182. struct timespec time;
  201183. time.tv_sec = millisecs / 1000;
  201184. time.tv_nsec = (millisecs % 1000) * 1000000;
  201185. nanosleep (&time, 0);
  201186. }
  201187. const tchar File::separator = T('/');
  201188. const tchar* File::separatorString = T("/");
  201189. bool juce_copyFile (const String& s, const String& d);
  201190. static bool juce_stat (const String& fileName, struct stat& info)
  201191. {
  201192. return fileName.isNotEmpty()
  201193. && (stat (fileName.toUTF8(), &info) == 0);
  201194. }
  201195. bool juce_isDirectory (const String& fileName)
  201196. {
  201197. struct stat info;
  201198. return fileName.isEmpty()
  201199. || (juce_stat (fileName, info)
  201200. && ((info.st_mode & S_IFDIR) != 0));
  201201. }
  201202. bool juce_fileExists (const String& fileName, const bool dontCountDirectories)
  201203. {
  201204. if (fileName.isEmpty())
  201205. return false;
  201206. const char* const fileNameUTF8 = fileName.toUTF8();
  201207. bool exists = access (fileNameUTF8, F_OK) == 0;
  201208. if (exists && dontCountDirectories)
  201209. {
  201210. struct stat info;
  201211. const int res = stat (fileNameUTF8, &info);
  201212. if (res == 0 && (info.st_mode & S_IFDIR) != 0)
  201213. exists = false;
  201214. }
  201215. return exists;
  201216. }
  201217. int64 juce_getFileSize (const String& fileName)
  201218. {
  201219. struct stat info;
  201220. return juce_stat (fileName, info) ? info.st_size : 0;
  201221. }
  201222. bool juce_canWriteToFile (const String& fileName)
  201223. {
  201224. return access (fileName.toUTF8(), W_OK) == 0;
  201225. }
  201226. bool juce_deleteFile (const String& fileName)
  201227. {
  201228. if (juce_isDirectory (fileName))
  201229. return rmdir ((const char*) fileName.toUTF8()) == 0;
  201230. else
  201231. return remove ((const char*) fileName.toUTF8()) == 0;
  201232. }
  201233. bool juce_moveFile (const String& source, const String& dest)
  201234. {
  201235. if (rename (source.toUTF8(), dest.toUTF8()) == 0)
  201236. return true;
  201237. if (juce_canWriteToFile (source)
  201238. && juce_copyFile (source, dest))
  201239. {
  201240. if (juce_deleteFile (source))
  201241. return true;
  201242. juce_deleteFile (dest);
  201243. }
  201244. return false;
  201245. }
  201246. void juce_createDirectory (const String& fileName)
  201247. {
  201248. mkdir (fileName.toUTF8(), 0777);
  201249. }
  201250. void* juce_fileOpen (const String& fileName, bool forWriting)
  201251. {
  201252. int flags = O_RDONLY;
  201253. if (forWriting)
  201254. {
  201255. if (juce_fileExists (fileName, false))
  201256. {
  201257. const int f = open ((const char*) fileName.toUTF8(), O_RDWR, 00644);
  201258. if (f != -1)
  201259. lseek (f, 0, SEEK_END);
  201260. return (void*) f;
  201261. }
  201262. else
  201263. {
  201264. flags = O_RDWR + O_CREAT;
  201265. }
  201266. }
  201267. return (void*) open ((const char*) fileName.toUTF8(), flags, 00644);
  201268. }
  201269. void juce_fileClose (void* handle)
  201270. {
  201271. if (handle != 0)
  201272. close ((int) (pointer_sized_int) handle);
  201273. }
  201274. int juce_fileRead (void* handle, void* buffer, int size)
  201275. {
  201276. if (handle != 0)
  201277. return (int) read ((int) (pointer_sized_int) handle, buffer, size);
  201278. return 0;
  201279. }
  201280. int juce_fileWrite (void* handle, const void* buffer, int size)
  201281. {
  201282. if (handle != 0)
  201283. return (int) write ((int) (pointer_sized_int) handle, buffer, size);
  201284. return 0;
  201285. }
  201286. int64 juce_fileSetPosition (void* handle, int64 pos)
  201287. {
  201288. if (handle != 0 && lseek ((int) (pointer_sized_int) handle, pos, SEEK_SET) == pos)
  201289. return pos;
  201290. return -1;
  201291. }
  201292. int64 juce_fileGetPosition (void* handle)
  201293. {
  201294. if (handle != 0)
  201295. return lseek ((int) (pointer_sized_int) handle, 0, SEEK_CUR);
  201296. else
  201297. return -1;
  201298. }
  201299. void juce_fileFlush (void* handle)
  201300. {
  201301. if (handle != 0)
  201302. fsync ((int) (pointer_sized_int) handle);
  201303. }
  201304. const File juce_getExecutableFile()
  201305. {
  201306. Dl_info exeInfo;
  201307. dladdr ((const void*) juce_getExecutableFile, &exeInfo);
  201308. return File (exeInfo.dli_fname);
  201309. }
  201310. // if this file doesn't exist, find a parent of it that does..
  201311. static bool doStatFS (const File* file, struct statfs& result)
  201312. {
  201313. File f (*file);
  201314. for (int i = 5; --i >= 0;)
  201315. {
  201316. if (f.exists())
  201317. break;
  201318. f = f.getParentDirectory();
  201319. }
  201320. return statfs (f.getFullPathName().toUTF8(), &result) == 0;
  201321. }
  201322. int64 File::getBytesFreeOnVolume() const
  201323. {
  201324. struct statfs buf;
  201325. if (doStatFS (this, buf))
  201326. return (int64) buf.f_bsize * (int64) buf.f_bavail; // Note: this returns space available to non-super user
  201327. return 0;
  201328. }
  201329. int64 File::getVolumeTotalSize() const
  201330. {
  201331. struct statfs buf;
  201332. if (doStatFS (this, buf))
  201333. return (int64) buf.f_bsize * (int64) buf.f_blocks;
  201334. return 0;
  201335. }
  201336. const String juce_getVolumeLabel (const String& filenameOnVolume,
  201337. int& volumeSerialNumber)
  201338. {
  201339. volumeSerialNumber = 0;
  201340. #if JUCE_MAC
  201341. struct VolAttrBuf
  201342. {
  201343. u_int32_t length;
  201344. attrreference_t mountPointRef;
  201345. char mountPointSpace [MAXPATHLEN];
  201346. } attrBuf;
  201347. struct attrlist attrList;
  201348. zerostruct (attrList);
  201349. attrList.bitmapcount = ATTR_BIT_MAP_COUNT;
  201350. attrList.volattr = ATTR_VOL_INFO | ATTR_VOL_NAME;
  201351. File f (filenameOnVolume);
  201352. for (;;)
  201353. {
  201354. if (getattrlist ((const char*) f.getFullPathName().toUTF8(),
  201355. &attrList, &attrBuf, sizeof(attrBuf), 0) == 0)
  201356. {
  201357. return String::fromUTF8 (((const uint8*) &attrBuf.mountPointRef) + attrBuf.mountPointRef.attr_dataoffset,
  201358. (int) attrBuf.mountPointRef.attr_length);
  201359. }
  201360. const File parent (f.getParentDirectory());
  201361. if (f == parent)
  201362. break;
  201363. f = parent;
  201364. }
  201365. #endif
  201366. return String::empty;
  201367. }
  201368. void juce_runSystemCommand (const String& command)
  201369. {
  201370. int result = system ((const char*) command.toUTF8());
  201371. (void) result;
  201372. }
  201373. const String juce_getOutputFromCommand (const String& command)
  201374. {
  201375. // slight bodge here, as we just pipe the output into a temp file and read it...
  201376. const File tempFile (File::getSpecialLocation (File::tempDirectory)
  201377. .getNonexistentChildFile (String::toHexString (Random::getSystemRandom().nextInt()), ".tmp", false));
  201378. juce_runSystemCommand (command + " > " + tempFile.getFullPathName());
  201379. String result (tempFile.loadFileAsString());
  201380. tempFile.deleteFile();
  201381. return result;
  201382. }
  201383. InterProcessLock::InterProcessLock (const String& name_)
  201384. : internal (0),
  201385. name (name_),
  201386. reentrancyLevel (0)
  201387. {
  201388. #if JUCE_MAC
  201389. // (don't use getSpecialLocation() to avoid the temp folder being different for each app)
  201390. const File temp (File (T("~/Library/Caches/Juce")).getChildFile (name));
  201391. #else
  201392. const File temp (File::getSpecialLocation (File::tempDirectory).getChildFile (name));
  201393. #endif
  201394. temp.create();
  201395. internal = open (temp.getFullPathName().toUTF8(), O_RDWR);
  201396. }
  201397. InterProcessLock::~InterProcessLock()
  201398. {
  201399. while (reentrancyLevel > 0)
  201400. this->exit();
  201401. close (internal);
  201402. }
  201403. bool InterProcessLock::enter (const int timeOutMillisecs)
  201404. {
  201405. if (internal == 0)
  201406. return false;
  201407. if (reentrancyLevel != 0)
  201408. return true;
  201409. const int64 endTime = Time::currentTimeMillis() + timeOutMillisecs;
  201410. struct flock fl;
  201411. zerostruct (fl);
  201412. fl.l_whence = SEEK_SET;
  201413. fl.l_type = F_WRLCK;
  201414. for (;;)
  201415. {
  201416. const int result = fcntl (internal, F_SETLK, &fl);
  201417. if (result >= 0)
  201418. {
  201419. ++reentrancyLevel;
  201420. return true;
  201421. }
  201422. if (errno != EINTR)
  201423. {
  201424. if (timeOutMillisecs == 0
  201425. || (timeOutMillisecs > 0 && Time::currentTimeMillis() >= endTime))
  201426. break;
  201427. Thread::sleep (10);
  201428. }
  201429. }
  201430. return false;
  201431. }
  201432. void InterProcessLock::exit()
  201433. {
  201434. if (reentrancyLevel > 0 && internal != 0)
  201435. {
  201436. --reentrancyLevel;
  201437. struct flock fl;
  201438. zerostruct (fl);
  201439. fl.l_whence = SEEK_SET;
  201440. fl.l_type = F_UNLCK;
  201441. for (;;)
  201442. {
  201443. const int result = fcntl (internal, F_SETLKW, &fl);
  201444. if (result >= 0 || errno != EINTR)
  201445. break;
  201446. }
  201447. }
  201448. }
  201449. /********* End of inlined file: juce_posix_SharedCode.h *********/
  201450. /********* Start of inlined file: juce_mac_Files.mm *********/
  201451. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  201452. // compiled on its own).
  201453. #if JUCE_INCLUDED_FILE
  201454. void juce_getFileTimes (const String& fileName,
  201455. int64& modificationTime,
  201456. int64& accessTime,
  201457. int64& creationTime)
  201458. {
  201459. modificationTime = 0;
  201460. accessTime = 0;
  201461. creationTime = 0;
  201462. struct stat info;
  201463. const int res = stat (fileName.toUTF8(), &info);
  201464. if (res == 0)
  201465. {
  201466. modificationTime = (int64) info.st_mtime * 1000;
  201467. accessTime = (int64) info.st_atime * 1000;
  201468. creationTime = (int64) info.st_ctime * 1000;
  201469. }
  201470. }
  201471. bool juce_setFileTimes (const String& fileName,
  201472. int64 modificationTime,
  201473. int64 accessTime,
  201474. int64 creationTime)
  201475. {
  201476. struct utimbuf times;
  201477. times.actime = (time_t) (accessTime / 1000);
  201478. times.modtime = (time_t) (modificationTime / 1000);
  201479. return utime (fileName.toUTF8(), &times) == 0;
  201480. }
  201481. bool juce_setFileReadOnly (const String& fileName, bool isReadOnly)
  201482. {
  201483. struct stat info;
  201484. const int res = stat (fileName.toUTF8(), &info);
  201485. if (res != 0)
  201486. return false;
  201487. info.st_mode &= 0777; // Just permissions
  201488. if (isReadOnly)
  201489. info.st_mode &= ~(S_IWUSR | S_IWGRP | S_IWOTH);
  201490. else
  201491. // Give everybody write permission?
  201492. info.st_mode |= S_IWUSR | S_IWGRP | S_IWOTH;
  201493. return chmod (fileName.toUTF8(), info.st_mode) == 0;
  201494. }
  201495. bool juce_copyFile (const String& src, const String& dst)
  201496. {
  201497. const ScopedAutoReleasePool pool;
  201498. NSFileManager* fm = [NSFileManager defaultManager];
  201499. return [fm fileExistsAtPath: juceStringToNS (src)]
  201500. #if defined (MAC_OS_X_VERSION_10_6) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
  201501. && [fm copyItemAtPath: juceStringToNS (src)
  201502. toPath: juceStringToNS (dst)
  201503. error: nil];
  201504. #else
  201505. && [fm copyPath: juceStringToNS (src)
  201506. toPath: juceStringToNS (dst)
  201507. handler: nil];
  201508. #endif
  201509. }
  201510. const StringArray juce_getFileSystemRoots()
  201511. {
  201512. StringArray s;
  201513. s.add (T("/"));
  201514. return s;
  201515. }
  201516. static bool isFileOnDriveType (const File* const f, const char** types)
  201517. {
  201518. struct statfs buf;
  201519. if (doStatFS (f, buf))
  201520. {
  201521. const String type (buf.f_fstypename);
  201522. while (*types != 0)
  201523. if (type.equalsIgnoreCase (*types++))
  201524. return true;
  201525. }
  201526. return false;
  201527. }
  201528. bool File::isOnCDRomDrive() const
  201529. {
  201530. static const char* const cdTypes[] = { "cd9660", "cdfs", "cddafs", "udf", 0 };
  201531. return isFileOnDriveType (this, (const char**) cdTypes);
  201532. }
  201533. bool File::isOnHardDisk() const
  201534. {
  201535. static const char* const nonHDTypes[] = { "nfs", "smbfs", "ramfs", 0 };
  201536. return ! (isOnCDRomDrive() || isFileOnDriveType (this, (const char**) nonHDTypes));
  201537. }
  201538. bool File::isOnRemovableDrive() const
  201539. {
  201540. #if JUCE_IPHONE
  201541. return false; // xxx is this possible?
  201542. #else
  201543. const ScopedAutoReleasePool pool;
  201544. BOOL removable = false;
  201545. [[NSWorkspace sharedWorkspace]
  201546. getFileSystemInfoForPath: juceStringToNS (getFullPathName())
  201547. isRemovable: &removable
  201548. isWritable: nil
  201549. isUnmountable: nil
  201550. description: nil
  201551. type: nil];
  201552. return removable;
  201553. #endif
  201554. }
  201555. static bool juce_isHiddenFile (const String& path)
  201556. {
  201557. #if JUCE_IPHONE
  201558. return File (path).getFileName().startsWithChar (T('.'));
  201559. #else
  201560. FSRef ref;
  201561. if (! PlatformUtilities::makeFSRefFromPath (&ref, path))
  201562. return false;
  201563. FSCatalogInfo info;
  201564. FSGetCatalogInfo (&ref, kFSCatInfoNodeFlags | kFSCatInfoFinderInfo, &info, 0, 0, 0);
  201565. if ((info.nodeFlags & kFSNodeIsDirectoryBit) != 0)
  201566. return (((FolderInfo*) &info.finderInfo)->finderFlags & kIsInvisible) != 0;
  201567. return (((FileInfo*) &info.finderInfo)->finderFlags & kIsInvisible) != 0;
  201568. #endif
  201569. }
  201570. bool File::isHidden() const
  201571. {
  201572. return juce_isHiddenFile (getFullPathName());
  201573. }
  201574. const char* juce_Argv0 = 0; // referenced from juce_Application.cpp
  201575. const File File::getSpecialLocation (const SpecialLocationType type)
  201576. {
  201577. const ScopedAutoReleasePool pool;
  201578. String resultPath;
  201579. switch (type)
  201580. {
  201581. case userHomeDirectory:
  201582. resultPath = nsStringToJuce (NSHomeDirectory());
  201583. break;
  201584. case userDocumentsDirectory:
  201585. resultPath = "~/Documents";
  201586. break;
  201587. case userDesktopDirectory:
  201588. resultPath = "~/Desktop";
  201589. break;
  201590. case userApplicationDataDirectory:
  201591. resultPath = "~/Library";
  201592. break;
  201593. case commonApplicationDataDirectory:
  201594. resultPath = "/Library";
  201595. break;
  201596. case globalApplicationsDirectory:
  201597. resultPath = "/Applications";
  201598. break;
  201599. case userMusicDirectory:
  201600. resultPath = "~/Music";
  201601. break;
  201602. case userMoviesDirectory:
  201603. resultPath = "~/Movies";
  201604. break;
  201605. case tempDirectory:
  201606. {
  201607. File tmp (T("~/Library/Caches/") + juce_getExecutableFile().getFileNameWithoutExtension());
  201608. tmp.createDirectory();
  201609. return tmp.getFullPathName();
  201610. }
  201611. case invokedExecutableFile:
  201612. if (juce_Argv0 != 0)
  201613. return File (String::fromUTF8 ((const uint8*) juce_Argv0));
  201614. // deliberate fall-through...
  201615. case currentExecutableFile:
  201616. return juce_getExecutableFile();
  201617. case currentApplicationFile:
  201618. {
  201619. const File exe (juce_getExecutableFile());
  201620. const File parent (exe.getParentDirectory());
  201621. return parent.getFullPathName().endsWithIgnoreCase (T("Contents/MacOS"))
  201622. ? parent.getParentDirectory().getParentDirectory()
  201623. : exe;
  201624. }
  201625. default:
  201626. jassertfalse // unknown type?
  201627. break;
  201628. }
  201629. if (resultPath != 0)
  201630. return File (PlatformUtilities::convertToPrecomposedUnicode (resultPath));
  201631. return File::nonexistent;
  201632. }
  201633. const File File::getCurrentWorkingDirectory()
  201634. {
  201635. char buf [2048];
  201636. getcwd (buf, sizeof(buf));
  201637. return File (PlatformUtilities::convertToPrecomposedUnicode (buf));
  201638. }
  201639. bool File::setAsCurrentWorkingDirectory() const
  201640. {
  201641. return chdir (getFullPathName().toUTF8()) == 0;
  201642. }
  201643. const String File::getVersion() const
  201644. {
  201645. const ScopedAutoReleasePool pool;
  201646. String result;
  201647. NSBundle* bundle = [NSBundle bundleWithPath: juceStringToNS (getFullPathName())];
  201648. if (bundle != 0)
  201649. {
  201650. NSDictionary* info = [bundle infoDictionary];
  201651. if (info != 0)
  201652. {
  201653. NSString* name = [info valueForKey: @"CFBundleShortVersionString"];
  201654. if (name != nil)
  201655. result = nsStringToJuce (name);
  201656. }
  201657. }
  201658. return result;
  201659. }
  201660. const File File::getLinkedTarget() const
  201661. {
  201662. #if JUCE_IPHONE || (defined (MAC_OS_X_VERSION_10_5) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5)
  201663. NSString* dest = [[NSFileManager defaultManager] destinationOfSymbolicLinkAtPath: juceStringToNS (getFullPathName()) error: nil];
  201664. #else
  201665. NSString* dest = [[NSFileManager defaultManager] pathContentOfSymbolicLinkAtPath: juceStringToNS (getFullPathName())];
  201666. #endif
  201667. if (dest != nil)
  201668. return File (nsStringToJuce (dest));
  201669. return *this;
  201670. }
  201671. bool File::moveToTrash() const
  201672. {
  201673. if (! exists())
  201674. return true;
  201675. #if JUCE_IPHONE
  201676. return deleteFile(); //xxx is there a trashcan on the iPhone?
  201677. #else
  201678. const ScopedAutoReleasePool pool;
  201679. NSString* p = juceStringToNS (getFullPathName());
  201680. return [[NSWorkspace sharedWorkspace]
  201681. performFileOperation: NSWorkspaceRecycleOperation
  201682. source: [p stringByDeletingLastPathComponent]
  201683. destination: @""
  201684. files: [NSArray arrayWithObject: [p lastPathComponent]]
  201685. tag: nil ];
  201686. #endif
  201687. }
  201688. struct FindFileStruct
  201689. {
  201690. NSDirectoryEnumerator* enumerator;
  201691. String parentDir, wildCard;
  201692. };
  201693. bool juce_findFileNext (void* handle, String& resultFile,
  201694. bool* isDir, bool* isHidden, int64* fileSize, Time* modTime, Time* creationTime, bool* isReadOnly)
  201695. {
  201696. ScopedAutoReleasePool pool;
  201697. FindFileStruct* ff = (FindFileStruct*) handle;
  201698. NSString* file;
  201699. const char* const wildcardUTF8 = ff->wildCard.toUTF8();
  201700. for (;;)
  201701. {
  201702. if (ff == 0 || (file = [ff->enumerator nextObject]) == 0)
  201703. return false;
  201704. [ff->enumerator skipDescendents];
  201705. resultFile = nsStringToJuce (file);
  201706. if (fnmatch (wildcardUTF8, resultFile.toUTF8(), FNM_CASEFOLD) != 0)
  201707. continue;
  201708. const String path (ff->parentDir + resultFile);
  201709. if (isDir != 0 || fileSize != 0)
  201710. {
  201711. struct stat info;
  201712. const bool statOk = juce_stat (path, info);
  201713. if (isDir != 0)
  201714. *isDir = statOk && ((info.st_mode & S_IFDIR) != 0);
  201715. if (isHidden != 0)
  201716. *isHidden = juce_isHiddenFile (path);
  201717. if (fileSize != 0)
  201718. *fileSize = statOk ? info.st_size : 0;
  201719. }
  201720. if (modTime != 0 || creationTime != 0)
  201721. {
  201722. int64 m, a, c;
  201723. juce_getFileTimes (path, m, a, c);
  201724. if (modTime != 0)
  201725. *modTime = m;
  201726. if (creationTime != 0)
  201727. *creationTime = c;
  201728. }
  201729. if (isReadOnly != 0)
  201730. *isReadOnly = ! juce_canWriteToFile (path);
  201731. return true;
  201732. }
  201733. }
  201734. void* juce_findFileStart (const String& directory, const String& wildCard, String& firstResultFile,
  201735. bool* isDir, bool* isHidden, int64* fileSize, Time* modTime,
  201736. Time* creationTime, bool* isReadOnly)
  201737. {
  201738. ScopedAutoReleasePool pool;
  201739. NSDirectoryEnumerator* e = [[NSFileManager defaultManager] enumeratorAtPath: juceStringToNS (directory)];
  201740. if (e != 0)
  201741. {
  201742. ScopedPointer <FindFileStruct> ff (new FindFileStruct());
  201743. ff->enumerator = [e retain];
  201744. ff->parentDir = directory;
  201745. ff->wildCard = wildCard;
  201746. if (! ff->parentDir.endsWithChar (File::separator))
  201747. ff->parentDir += File::separator;
  201748. if (juce_findFileNext (ff, firstResultFile, isDir, isHidden, fileSize, modTime, creationTime, isReadOnly))
  201749. return ff.release();
  201750. [e release];
  201751. }
  201752. return 0;
  201753. }
  201754. void juce_findFileClose (void* handle)
  201755. {
  201756. ScopedAutoReleasePool pool;
  201757. ScopedPointer <FindFileStruct> ff ((FindFileStruct*) handle);
  201758. [ff->enumerator release];
  201759. }
  201760. bool juce_launchExecutable (const String& pathAndArguments)
  201761. {
  201762. const char* const argv[4] = { "/bin/sh", "-c", (const char*) pathAndArguments, 0 };
  201763. const int cpid = fork();
  201764. if (cpid == 0)
  201765. {
  201766. // Child process
  201767. if (execve (argv[0], (char**) argv, 0) < 0)
  201768. exit (0);
  201769. }
  201770. else
  201771. {
  201772. if (cpid < 0)
  201773. return false;
  201774. }
  201775. return true;
  201776. }
  201777. bool juce_launchFile (const String& fileName, const String& parameters)
  201778. {
  201779. #if JUCE_IPHONE
  201780. return [[UIApplication sharedApplication] openURL: [NSURL fileURLWithPath: juceStringToNS (fileName)]];
  201781. #else
  201782. const ScopedAutoReleasePool pool;
  201783. if (parameters.isEmpty())
  201784. {
  201785. return [[NSWorkspace sharedWorkspace] openFile: juceStringToNS (fileName)]
  201786. || [[NSWorkspace sharedWorkspace] openURL: [NSURL URLWithString: juceStringToNS (fileName)]];
  201787. }
  201788. bool ok = false;
  201789. FSRef ref;
  201790. if (PlatformUtilities::makeFSRefFromPath (&ref, fileName))
  201791. {
  201792. if (PlatformUtilities::isBundle (fileName))
  201793. {
  201794. NSMutableArray* urls = [NSMutableArray array];
  201795. StringArray docs;
  201796. docs.addTokens (parameters, true);
  201797. for (int i = 0; i < docs.size(); ++i)
  201798. [urls addObject: juceStringToNS (docs[i])];
  201799. ok = [[NSWorkspace sharedWorkspace] openURLs: urls
  201800. withAppBundleIdentifier: [[NSBundle bundleWithPath: juceStringToNS (fileName)] bundleIdentifier]
  201801. options: 0
  201802. additionalEventParamDescriptor: nil
  201803. launchIdentifiers: nil];
  201804. }
  201805. else
  201806. {
  201807. ok = juce_launchExecutable (T("\"") + fileName + T("\" ") + parameters);
  201808. }
  201809. }
  201810. return ok;
  201811. #endif
  201812. }
  201813. void File::revealToUser() const
  201814. {
  201815. #if ! JUCE_IPHONE
  201816. if (exists())
  201817. [[NSWorkspace sharedWorkspace] selectFile: juceStringToNS (getFullPathName()) inFileViewerRootedAtPath: @""];
  201818. else if (getParentDirectory().exists())
  201819. getParentDirectory().revealToUser();
  201820. #endif
  201821. }
  201822. #if ! JUCE_IPHONE
  201823. bool PlatformUtilities::makeFSRefFromPath (FSRef* destFSRef, const String& path)
  201824. {
  201825. return FSPathMakeRef ((const UInt8*) path.toUTF8(), destFSRef, 0) == noErr;
  201826. }
  201827. const String PlatformUtilities::makePathFromFSRef (FSRef* file)
  201828. {
  201829. uint8 path [2048];
  201830. zeromem (path, sizeof (path));
  201831. String result;
  201832. if (FSRefMakePath (file, (UInt8*) path, sizeof (path) - 1) == noErr)
  201833. result = String::fromUTF8 (path);
  201834. return PlatformUtilities::convertToPrecomposedUnicode (result);
  201835. }
  201836. #endif
  201837. OSType PlatformUtilities::getTypeOfFile (const String& filename)
  201838. {
  201839. const ScopedAutoReleasePool pool;
  201840. #if JUCE_IPHONE || (defined (MAC_OS_X_VERSION_10_5) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5)
  201841. NSDictionary* fileDict = [[NSFileManager defaultManager] attributesOfItemAtPath: juceStringToNS (filename) error: nil];
  201842. #else
  201843. NSDictionary* fileDict = [[NSFileManager defaultManager] fileAttributesAtPath: juceStringToNS (filename) traverseLink: NO];
  201844. #endif
  201845. //return (OSType) [fileDict objectForKey: NSFileHFSTypeCode];
  201846. return [fileDict fileHFSTypeCode];
  201847. }
  201848. bool PlatformUtilities::isBundle (const String& filename)
  201849. {
  201850. #if JUCE_IPHONE
  201851. return false; // xxx can't find a sensible way to do this without trying to open the bundle..
  201852. #else
  201853. const ScopedAutoReleasePool pool;
  201854. return [[NSWorkspace sharedWorkspace] isFilePackageAtPath: juceStringToNS (filename)];
  201855. #endif
  201856. }
  201857. #endif
  201858. /********* End of inlined file: juce_mac_Files.mm *********/
  201859. #if JUCE_IPHONE
  201860. /********* Start of inlined file: juce_iphone_MiscUtilities.mm *********/
  201861. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  201862. // compiled on its own).
  201863. #if JUCE_INCLUDED_FILE
  201864. static JUCEApplication* juce_intialisingApp;
  201865. END_JUCE_NAMESPACE
  201866. @interface JuceAppStartupDelegate : NSObject <UIApplicationDelegate>
  201867. {
  201868. }
  201869. - (void) applicationDidFinishLaunching: (UIApplication*) application;
  201870. - (void) applicationWillResignActive: (UIApplication*) application;
  201871. @end
  201872. @implementation JuceAppStartupDelegate
  201873. - (void) applicationDidFinishLaunching: (UIApplication*) application
  201874. {
  201875. String dummy;
  201876. if (! juce_intialisingApp->initialiseApp (dummy))
  201877. exit (0);
  201878. }
  201879. - (void) applicationWillResignActive: (UIApplication*) application
  201880. {
  201881. JUCEApplication::shutdownAppAndClearUp();
  201882. }
  201883. @end
  201884. BEGIN_JUCE_NAMESPACE
  201885. int juce_IPhoneMain (int argc, char* argv[], JUCEApplication* app)
  201886. {
  201887. juce_intialisingApp = app;
  201888. return UIApplicationMain (argc, argv, nil, @"JuceAppStartupDelegate");
  201889. }
  201890. ScopedAutoReleasePool::ScopedAutoReleasePool()
  201891. {
  201892. pool = [[NSAutoreleasePool alloc] init];
  201893. }
  201894. ScopedAutoReleasePool::~ScopedAutoReleasePool()
  201895. {
  201896. [((NSAutoreleasePool*) pool) release];
  201897. }
  201898. void PlatformUtilities::beep()
  201899. {
  201900. //xxx
  201901. //AudioServicesPlaySystemSound ();
  201902. }
  201903. void PlatformUtilities::addItemToDock (const File& file)
  201904. {
  201905. }
  201906. #if ! JUCE_ONLY_BUILD_CORE_LIBRARY
  201907. END_JUCE_NAMESPACE
  201908. @interface JuceAlertBoxDelegate : NSObject
  201909. {
  201910. @public
  201911. bool clickedOk;
  201912. }
  201913. - (void) alertView: (UIAlertView*) alertView clickedButtonAtIndex: (NSInteger) buttonIndex;
  201914. @end
  201915. @implementation JuceAlertBoxDelegate
  201916. - (void) alertView: (UIAlertView*) alertView clickedButtonAtIndex: (NSInteger) buttonIndex
  201917. {
  201918. clickedOk = (buttonIndex == 0);
  201919. alertView.hidden = true;
  201920. }
  201921. @end
  201922. BEGIN_JUCE_NAMESPACE
  201923. // (This function is used directly by other bits of code)
  201924. bool juce_iPhoneShowModalAlert (const String& title,
  201925. const String& bodyText,
  201926. NSString* okButtonText,
  201927. NSString* cancelButtonText)
  201928. {
  201929. const ScopedAutoReleasePool pool;
  201930. JuceAlertBoxDelegate* callback = [[JuceAlertBoxDelegate alloc] init];
  201931. UIAlertView* alert = [[UIAlertView alloc] initWithTitle: juceStringToNS (title)
  201932. message: juceStringToNS (bodyText)
  201933. delegate: callback
  201934. cancelButtonTitle: okButtonText
  201935. otherButtonTitles: cancelButtonText, nil];
  201936. [alert retain];
  201937. [alert show];
  201938. while (! alert.hidden && alert.superview != nil)
  201939. [[NSRunLoop mainRunLoop] runUntilDate: [NSDate dateWithTimeIntervalSinceNow: 0.01]];
  201940. const bool result = callback->clickedOk;
  201941. [alert release];
  201942. [callback release];
  201943. return result;
  201944. }
  201945. bool AlertWindow::showNativeDialogBox (const String& title,
  201946. const String& bodyText,
  201947. bool isOkCancel)
  201948. {
  201949. return juce_iPhoneShowModalAlert (title, bodyText,
  201950. @"OK",
  201951. isOkCancel ? @"Cancel" : nil);
  201952. }
  201953. bool DragAndDropContainer::performExternalDragDropOfFiles (const StringArray& files, const bool canMoveFiles)
  201954. {
  201955. jassertfalse // no such thing on the iphone!
  201956. return false;
  201957. }
  201958. bool DragAndDropContainer::performExternalDragDropOfText (const String& text)
  201959. {
  201960. jassertfalse // no such thing on the iphone!
  201961. return false;
  201962. }
  201963. void Desktop::setScreenSaverEnabled (const bool isEnabled) throw()
  201964. {
  201965. [[UIApplication sharedApplication] setIdleTimerDisabled: ! isEnabled];
  201966. }
  201967. bool Desktop::isScreenSaverEnabled() throw()
  201968. {
  201969. return ! [[UIApplication sharedApplication] isIdleTimerDisabled];
  201970. }
  201971. void juce_updateMultiMonitorInfo (Array <Rectangle>& monitorCoords, const bool clipToWorkArea)
  201972. {
  201973. const ScopedAutoReleasePool pool;
  201974. monitorCoords.clear();
  201975. CGRect r = clipToWorkArea ? [[UIScreen mainScreen] applicationFrame]
  201976. : [[UIScreen mainScreen] bounds];
  201977. monitorCoords.add (Rectangle ((int) r.origin.x,
  201978. (int) r.origin.y,
  201979. (int) r.size.width,
  201980. (int) r.size.height));
  201981. }
  201982. #endif
  201983. #endif
  201984. /********* End of inlined file: juce_iphone_MiscUtilities.mm *********/
  201985. #else
  201986. /********* Start of inlined file: juce_mac_MiscUtilities.mm *********/
  201987. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  201988. // compiled on its own).
  201989. #if JUCE_INCLUDED_FILE
  201990. ScopedAutoReleasePool::ScopedAutoReleasePool()
  201991. {
  201992. pool = [[NSAutoreleasePool alloc] init];
  201993. }
  201994. ScopedAutoReleasePool::~ScopedAutoReleasePool()
  201995. {
  201996. [((NSAutoreleasePool*) pool) release];
  201997. }
  201998. void PlatformUtilities::beep()
  201999. {
  202000. NSBeep();
  202001. }
  202002. void PlatformUtilities::addItemToDock (const File& file)
  202003. {
  202004. // check that it's not already there...
  202005. if (! juce_getOutputFromCommand ("defaults read com.apple.dock persistent-apps")
  202006. .containsIgnoreCase (file.getFullPathName()))
  202007. {
  202008. 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>"
  202009. + file.getFullPathName() + "</string><key>_CFURLStringType</key><integer>0</integer></dict></dict></dict>\"");
  202010. juce_runSystemCommand ("osascript -e \"tell application \\\"Dock\\\" to quit\"");
  202011. }
  202012. }
  202013. int PlatformUtilities::getOSXMinorVersionNumber()
  202014. {
  202015. SInt32 versionMinor = 0;
  202016. OSErr err = Gestalt (gestaltSystemVersionMinor, &versionMinor);
  202017. (void) err;
  202018. jassert (err == noErr);
  202019. return (int) versionMinor;
  202020. }
  202021. #if ! JUCE_ONLY_BUILD_CORE_LIBRARY
  202022. bool AlertWindow::showNativeDialogBox (const String& title,
  202023. const String& bodyText,
  202024. bool isOkCancel)
  202025. {
  202026. const ScopedAutoReleasePool pool;
  202027. return NSRunAlertPanel (juceStringToNS (title),
  202028. juceStringToNS (bodyText),
  202029. @"Ok",
  202030. isOkCancel ? @"Cancel" : nil,
  202031. nil) == NSAlertDefaultReturn;
  202032. }
  202033. bool DragAndDropContainer::performExternalDragDropOfFiles (const StringArray& files, const bool canMoveFiles)
  202034. {
  202035. if (files.size() == 0)
  202036. return false;
  202037. Component* sourceComp = Component::getComponentUnderMouse();
  202038. if (sourceComp == 0)
  202039. {
  202040. jassertfalse // this method must be called in response to a
  202041. // component's mouseDrag event!
  202042. return false;
  202043. }
  202044. const ScopedAutoReleasePool pool;
  202045. NSView* view = (NSView*) sourceComp->getWindowHandle();
  202046. if (view == 0)
  202047. return false;
  202048. NSPasteboard* pboard = [NSPasteboard pasteboardWithName: NSDragPboard];
  202049. [pboard declareTypes: [NSArray arrayWithObject: NSFilenamesPboardType]
  202050. owner: nil];
  202051. NSMutableArray* filesArray = [NSMutableArray arrayWithCapacity: 4];
  202052. for (int i = 0; i < files.size(); ++i)
  202053. [filesArray addObject: juceStringToNS (files[i])];
  202054. [pboard setPropertyList: filesArray
  202055. forType: NSFilenamesPboardType];
  202056. NSPoint dragPosition = [view convertPoint: [[[view window] currentEvent] locationInWindow]
  202057. fromView: nil];
  202058. dragPosition.x -= 16;
  202059. dragPosition.y -= 16;
  202060. [view dragImage: [[NSWorkspace sharedWorkspace] iconForFile: juceStringToNS (files[0])]
  202061. at: dragPosition
  202062. offset: NSMakeSize (0, 0)
  202063. event: [[view window] currentEvent]
  202064. pasteboard: pboard
  202065. source: view
  202066. slideBack: YES];
  202067. return true;
  202068. }
  202069. bool DragAndDropContainer::performExternalDragDropOfText (const String& text)
  202070. {
  202071. jassertfalse // not implemented!
  202072. return false;
  202073. }
  202074. bool Desktop::canUseSemiTransparentWindows() throw()
  202075. {
  202076. return true;
  202077. }
  202078. void Desktop::getMousePosition (int& x, int& y) throw()
  202079. {
  202080. const ScopedAutoReleasePool pool;
  202081. const NSPoint p ([NSEvent mouseLocation]);
  202082. x = roundToInt (p.x);
  202083. y = roundToInt ([[[NSScreen screens] objectAtIndex: 0] frame].size.height - p.y);
  202084. }
  202085. void Desktop::setMousePosition (int x, int y) throw()
  202086. {
  202087. // this rubbish needs to be done around the warp call, to avoid causing a
  202088. // bizarre glitch..
  202089. CGAssociateMouseAndMouseCursorPosition (false);
  202090. CGWarpMouseCursorPosition (CGPointMake (x, y));
  202091. CGAssociateMouseAndMouseCursorPosition (true);
  202092. }
  202093. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
  202094. class ScreenSaverDefeater : public Timer,
  202095. public DeletedAtShutdown
  202096. {
  202097. public:
  202098. ScreenSaverDefeater() throw()
  202099. {
  202100. startTimer (10000);
  202101. timerCallback();
  202102. }
  202103. ~ScreenSaverDefeater() {}
  202104. void timerCallback()
  202105. {
  202106. if (Process::isForegroundProcess())
  202107. UpdateSystemActivity (UsrActivity);
  202108. }
  202109. };
  202110. static ScreenSaverDefeater* screenSaverDefeater = 0;
  202111. void Desktop::setScreenSaverEnabled (const bool isEnabled) throw()
  202112. {
  202113. if (isEnabled)
  202114. {
  202115. deleteAndZero (screenSaverDefeater);
  202116. }
  202117. else if (screenSaverDefeater == 0)
  202118. {
  202119. screenSaverDefeater = new ScreenSaverDefeater();
  202120. }
  202121. }
  202122. bool Desktop::isScreenSaverEnabled() throw()
  202123. {
  202124. return screenSaverDefeater == 0;
  202125. }
  202126. #else
  202127. static IOPMAssertionID screenSaverDisablerID = 0;
  202128. void Desktop::setScreenSaverEnabled (const bool isEnabled) throw()
  202129. {
  202130. if (isEnabled)
  202131. {
  202132. if (screenSaverDisablerID != 0)
  202133. {
  202134. IOPMAssertionRelease (screenSaverDisablerID);
  202135. screenSaverDisablerID = 0;
  202136. }
  202137. }
  202138. else
  202139. {
  202140. if (screenSaverDisablerID == 0)
  202141. {
  202142. #if defined (MAC_OS_X_VERSION_10_6) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
  202143. IOPMAssertionCreateWithName (kIOPMAssertionTypeNoIdleSleep, kIOPMAssertionLevelOn,
  202144. CFSTR ("Juce"), &screenSaverDisablerID);
  202145. #else
  202146. IOPMAssertionCreate (kIOPMAssertionTypeNoIdleSleep, kIOPMAssertionLevelOn,
  202147. &screenSaverDisablerID);
  202148. #endif
  202149. }
  202150. }
  202151. }
  202152. bool Desktop::isScreenSaverEnabled() throw()
  202153. {
  202154. return screenSaverDisablerID == 0;
  202155. }
  202156. #endif
  202157. void juce_updateMultiMonitorInfo (Array <Rectangle>& monitorCoords, const bool clipToWorkArea)
  202158. {
  202159. const ScopedAutoReleasePool pool;
  202160. monitorCoords.clear();
  202161. NSArray* screens = [NSScreen screens];
  202162. const CGFloat mainScreenBottom = [[[NSScreen screens] objectAtIndex: 0] frame].size.height;
  202163. for (unsigned int i = 0; i < [screens count]; ++i)
  202164. {
  202165. NSScreen* s = (NSScreen*) [screens objectAtIndex: i];
  202166. NSRect r = clipToWorkArea ? [s visibleFrame]
  202167. : [s frame];
  202168. monitorCoords.add (Rectangle ((int) r.origin.x,
  202169. (int) (mainScreenBottom - (r.origin.y + r.size.height)),
  202170. (int) r.size.width,
  202171. (int) r.size.height));
  202172. }
  202173. jassert (monitorCoords.size() > 0);
  202174. }
  202175. #endif
  202176. #endif
  202177. /********* End of inlined file: juce_mac_MiscUtilities.mm *********/
  202178. #endif
  202179. /********* Start of inlined file: juce_mac_Debugging.mm *********/
  202180. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  202181. // compiled on its own).
  202182. #if JUCE_INCLUDED_FILE
  202183. void Logger::outputDebugString (const String& text) throw()
  202184. {
  202185. std::cerr << (const char*) text.toUTF8() << std::endl;
  202186. }
  202187. void Logger::outputDebugPrintf (const tchar* format, ...) throw()
  202188. {
  202189. String text;
  202190. va_list args;
  202191. va_start (args, format);
  202192. text.vprintf (format, args);
  202193. outputDebugString (text);
  202194. }
  202195. bool JUCE_PUBLIC_FUNCTION juce_isRunningUnderDebugger()
  202196. {
  202197. static char testResult = 0;
  202198. if (testResult == 0)
  202199. {
  202200. struct kinfo_proc info;
  202201. int m[] = { CTL_KERN, KERN_PROC, KERN_PROC_PID, getpid() };
  202202. size_t sz = sizeof (info);
  202203. sysctl (m, 4, &info, &sz, 0, 0);
  202204. testResult = ((info.kp_proc.p_flag & P_TRACED) != 0) ? 1 : -1;
  202205. }
  202206. return testResult > 0;
  202207. }
  202208. bool JUCE_CALLTYPE Process::isRunningUnderDebugger()
  202209. {
  202210. return juce_isRunningUnderDebugger();
  202211. }
  202212. #endif
  202213. /********* End of inlined file: juce_mac_Debugging.mm *********/
  202214. #if ! JUCE_ONLY_BUILD_CORE_LIBRARY
  202215. #if JUCE_IPHONE
  202216. /********* Start of inlined file: juce_mac_Fonts.mm *********/
  202217. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  202218. // compiled on its own).
  202219. #if JUCE_INCLUDED_FILE
  202220. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
  202221. #define SUPPORT_10_4_FONTS 1
  202222. #define NEW_CGFONT_FUNCTIONS_UNAVAILABLE (CGFontCreateWithFontName == 0)
  202223. #if MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_5
  202224. #define SUPPORT_ONLY_10_4_FONTS 1
  202225. #endif
  202226. END_JUCE_NAMESPACE
  202227. @interface NSFont (PrivateHack)
  202228. - (NSGlyph) _defaultGlyphForChar: (unichar) theChar;
  202229. @end
  202230. BEGIN_JUCE_NAMESPACE
  202231. #endif
  202232. class MacTypeface : public Typeface
  202233. {
  202234. public:
  202235. MacTypeface (const Font& font)
  202236. : Typeface (font.getTypefaceName())
  202237. {
  202238. const ScopedAutoReleasePool pool;
  202239. renderingTransform = CGAffineTransformIdentity;
  202240. bool needsItalicTransform = false;
  202241. #if JUCE_IPHONE
  202242. NSString* fontName = juceStringToNS (font.getTypefaceName());
  202243. if (font.isItalic() || font.isBold())
  202244. {
  202245. NSArray* familyFonts = [UIFont fontNamesForFamilyName: juceStringToNS (font.getTypefaceName())];
  202246. for (NSString* i in familyFonts)
  202247. {
  202248. const String fn (nsStringToJuce (i));
  202249. const String afterDash (fn.fromFirstOccurrenceOf (T("-"), false, false));
  202250. const bool probablyBold = afterDash.containsIgnoreCase (T("bold")) || fn.endsWithIgnoreCase (T("bold"));
  202251. const bool probablyItalic = afterDash.containsIgnoreCase (T("oblique"))
  202252. || afterDash.containsIgnoreCase (T("italic"))
  202253. || fn.endsWithIgnoreCase (T("oblique"))
  202254. || fn.endsWithIgnoreCase (T("italic"));
  202255. if (probablyBold == font.isBold()
  202256. && probablyItalic == font.isItalic())
  202257. {
  202258. fontName = i;
  202259. needsItalicTransform = false;
  202260. break;
  202261. }
  202262. else if (probablyBold && (! probablyItalic) && probablyBold == font.isBold())
  202263. {
  202264. fontName = i;
  202265. needsItalicTransform = true; // not ideal, so carry on in case we find a better one
  202266. }
  202267. }
  202268. if (needsItalicTransform)
  202269. renderingTransform.c = 0.15f;
  202270. }
  202271. fontRef = CGFontCreateWithFontName ((CFStringRef) fontName);
  202272. const int ascender = abs (CGFontGetAscent (fontRef));
  202273. const float totalHeight = ascender + abs (CGFontGetDescent (fontRef));
  202274. ascent = ascender / totalHeight;
  202275. unitsToHeightScaleFactor = 1.0f / totalHeight;
  202276. fontHeightToCGSizeFactor = CGFontGetUnitsPerEm (fontRef) / totalHeight;
  202277. #else
  202278. nsFont = [NSFont fontWithName: juceStringToNS (font.getTypefaceName()) size: 1024];
  202279. if (font.isItalic())
  202280. {
  202281. NSFont* newFont = [[NSFontManager sharedFontManager] convertFont: nsFont
  202282. toHaveTrait: NSItalicFontMask];
  202283. if (newFont == nsFont)
  202284. needsItalicTransform = true; // couldn't find a proper italic version, so fake it with a transform..
  202285. nsFont = newFont;
  202286. }
  202287. if (font.isBold())
  202288. nsFont = [[NSFontManager sharedFontManager] convertFont: nsFont toHaveTrait: NSBoldFontMask];
  202289. [nsFont retain];
  202290. ascent = fabsf ((float) [nsFont ascender]);
  202291. float totalSize = ascent + fabsf ((float) [nsFont descender]);
  202292. ascent /= totalSize;
  202293. pathTransform = AffineTransform::identity.scale (1.0f / totalSize, 1.0f / totalSize);
  202294. if (needsItalicTransform)
  202295. {
  202296. pathTransform = pathTransform.sheared (-0.15f, 0.0f);
  202297. renderingTransform.c = 0.15f;
  202298. }
  202299. #if SUPPORT_ONLY_10_4_FONTS
  202300. ATSFontRef atsFont = ATSFontFindFromName ((CFStringRef) [nsFont fontName], kATSOptionFlagsDefault);
  202301. if (atsFont == 0)
  202302. atsFont = ATSFontFindFromPostScriptName ((CFStringRef) [nsFont fontName], kATSOptionFlagsDefault);
  202303. fontRef = CGFontCreateWithPlatformFont ((void*) &atsFont);
  202304. const float totalHeight = fabsf ([nsFont ascender]) + fabsf([nsFont descender]);
  202305. unitsToHeightScaleFactor = 1.0f / totalHeight;
  202306. fontHeightToCGSizeFactor = 1024.0f / totalHeight;
  202307. #else
  202308. #if SUPPORT_10_4_FONTS
  202309. if (NEW_CGFONT_FUNCTIONS_UNAVAILABLE)
  202310. {
  202311. ATSFontRef atsFont = ATSFontFindFromName ((CFStringRef) [nsFont fontName], kATSOptionFlagsDefault);
  202312. if (atsFont == 0)
  202313. atsFont = ATSFontFindFromPostScriptName ((CFStringRef) [nsFont fontName], kATSOptionFlagsDefault);
  202314. fontRef = CGFontCreateWithPlatformFont ((void*) &atsFont);
  202315. const float totalHeight = fabsf ([nsFont ascender]) + fabsf([nsFont descender]);
  202316. unitsToHeightScaleFactor = 1.0f / totalHeight;
  202317. fontHeightToCGSizeFactor = 1024.0f / totalHeight;
  202318. }
  202319. else
  202320. #endif
  202321. {
  202322. fontRef = CGFontCreateWithFontName ((CFStringRef) [nsFont fontName]);
  202323. const int totalHeight = abs (CGFontGetAscent (fontRef)) + abs (CGFontGetDescent (fontRef));
  202324. unitsToHeightScaleFactor = 1.0f / totalHeight;
  202325. fontHeightToCGSizeFactor = CGFontGetUnitsPerEm (fontRef) / (float) totalHeight;
  202326. }
  202327. #endif
  202328. #endif
  202329. }
  202330. ~MacTypeface()
  202331. {
  202332. #if ! JUCE_IPHONE
  202333. [nsFont release];
  202334. #endif
  202335. if (fontRef != 0)
  202336. CGFontRelease (fontRef);
  202337. }
  202338. float getAscent() const
  202339. {
  202340. return ascent;
  202341. }
  202342. float getDescent() const
  202343. {
  202344. return 1.0f - ascent;
  202345. }
  202346. float getStringWidth (const String& text)
  202347. {
  202348. if (fontRef == 0 || text.isEmpty())
  202349. return 0;
  202350. const int length = text.length();
  202351. HeapBlock <CGGlyph> glyphs;
  202352. createGlyphsForString (text, length, glyphs);
  202353. float x = 0;
  202354. #if SUPPORT_ONLY_10_4_FONTS
  202355. HeapBlock <NSSize> advances (length);
  202356. [nsFont getAdvancements: advances forGlyphs: (NSGlyph*) glyphs count: length];
  202357. for (int i = 0; i < length; ++i)
  202358. x += advances[i].width;
  202359. #else
  202360. #if SUPPORT_10_4_FONTS
  202361. if (NEW_CGFONT_FUNCTIONS_UNAVAILABLE)
  202362. {
  202363. HeapBlock <NSSize> advances (length);
  202364. [nsFont getAdvancements: advances forGlyphs: (NSGlyph*) glyphs count: length];
  202365. for (int i = 0; i < length; ++i)
  202366. x += advances[i].width;
  202367. }
  202368. else
  202369. #endif
  202370. {
  202371. HeapBlock <int> advances (length);
  202372. if (CGFontGetGlyphAdvances (fontRef, glyphs, length, advances))
  202373. for (int i = 0; i < length; ++i)
  202374. x += advances[i];
  202375. }
  202376. #endif
  202377. return x * unitsToHeightScaleFactor;
  202378. }
  202379. void getGlyphPositions (const String& text, Array <int>& resultGlyphs, Array <float>& xOffsets)
  202380. {
  202381. xOffsets.add (0);
  202382. if (fontRef == 0 || text.isEmpty())
  202383. return;
  202384. const int length = text.length();
  202385. HeapBlock <CGGlyph> glyphs;
  202386. createGlyphsForString (text, length, glyphs);
  202387. #if SUPPORT_ONLY_10_4_FONTS
  202388. HeapBlock <NSSize> advances (length);
  202389. [nsFont getAdvancements: advances forGlyphs: (NSGlyph*) glyphs count: length];
  202390. int x = 0;
  202391. for (int i = 0; i < length; ++i)
  202392. {
  202393. x += advances[i].width;
  202394. xOffsets.add (x * unitsToHeightScaleFactor);
  202395. resultGlyphs.add (((NSGlyph*) glyphs)[i]);
  202396. }
  202397. #else
  202398. #if SUPPORT_10_4_FONTS
  202399. if (NEW_CGFONT_FUNCTIONS_UNAVAILABLE)
  202400. {
  202401. HeapBlock <NSSize> advances (length);
  202402. [nsFont getAdvancements: advances forGlyphs: (NSGlyph*) glyphs count: length];
  202403. float x = 0;
  202404. for (int i = 0; i < length; ++i)
  202405. {
  202406. x += advances[i].width;
  202407. xOffsets.add (x * unitsToHeightScaleFactor);
  202408. resultGlyphs.add (((NSGlyph*) glyphs)[i]);
  202409. }
  202410. }
  202411. else
  202412. #endif
  202413. {
  202414. HeapBlock <int> advances (length);
  202415. if (CGFontGetGlyphAdvances (fontRef, glyphs, length, advances))
  202416. {
  202417. int x = 0;
  202418. for (int i = 0; i < length; ++i)
  202419. {
  202420. x += advances [i];
  202421. xOffsets.add (x * unitsToHeightScaleFactor);
  202422. resultGlyphs.add (glyphs[i]);
  202423. }
  202424. }
  202425. }
  202426. #endif
  202427. }
  202428. bool getOutlineForGlyph (int glyphNumber, Path& path)
  202429. {
  202430. #if JUCE_IPHONE
  202431. return false;
  202432. #else
  202433. if (nsFont == 0)
  202434. return false;
  202435. // we might need to apply a transform to the path, so it mustn't have anything else in it
  202436. jassert (path.isEmpty());
  202437. const ScopedAutoReleasePool pool;
  202438. NSBezierPath* bez = [NSBezierPath bezierPath];
  202439. [bez moveToPoint: NSMakePoint (0, 0)];
  202440. [bez appendBezierPathWithGlyph: (NSGlyph) glyphNumber
  202441. inFont: nsFont];
  202442. for (int i = 0; i < [bez elementCount]; ++i)
  202443. {
  202444. NSPoint p[3];
  202445. switch ([bez elementAtIndex: i associatedPoints: p])
  202446. {
  202447. case NSMoveToBezierPathElement:
  202448. path.startNewSubPath ((float) p[0].x, (float) -p[0].y);
  202449. break;
  202450. case NSLineToBezierPathElement:
  202451. path.lineTo ((float) p[0].x, (float) -p[0].y);
  202452. break;
  202453. case NSCurveToBezierPathElement:
  202454. 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);
  202455. break;
  202456. case NSClosePathBezierPathElement:
  202457. path.closeSubPath();
  202458. break;
  202459. default:
  202460. jassertfalse
  202461. break;
  202462. }
  202463. }
  202464. path.applyTransform (pathTransform);
  202465. return true;
  202466. #endif
  202467. }
  202468. juce_UseDebuggingNewOperator
  202469. CGFontRef fontRef;
  202470. float fontHeightToCGSizeFactor;
  202471. CGAffineTransform renderingTransform;
  202472. private:
  202473. float ascent, unitsToHeightScaleFactor;
  202474. #if JUCE_IPHONE
  202475. #else
  202476. NSFont* nsFont;
  202477. AffineTransform pathTransform;
  202478. #endif
  202479. void createGlyphsForString (const juce_wchar* const text, const int length, HeapBlock <CGGlyph>& glyphs)
  202480. {
  202481. #if SUPPORT_10_4_FONTS
  202482. #if ! SUPPORT_ONLY_10_4_FONTS
  202483. if (NEW_CGFONT_FUNCTIONS_UNAVAILABLE)
  202484. #endif
  202485. {
  202486. glyphs.malloc (sizeof (NSGlyph) * length, 1);
  202487. NSGlyph* const g = (NSGlyph*) glyphs;
  202488. for (int i = 0; i < length; ++i)
  202489. g[i] = (NSGlyph) [nsFont _defaultGlyphForChar: text[i]];
  202490. return;
  202491. }
  202492. #endif
  202493. #if ! SUPPORT_ONLY_10_4_FONTS
  202494. if (charToGlyphMapper == 0)
  202495. charToGlyphMapper = new CharToGlyphMapper (fontRef);
  202496. glyphs.malloc (length);
  202497. for (int i = 0; i < length; ++i)
  202498. glyphs[i] = (CGGlyph) charToGlyphMapper->getGlyphForCharacter (text[i]);
  202499. #endif
  202500. }
  202501. #if ! SUPPORT_ONLY_10_4_FONTS
  202502. // Reads a CGFontRef's character map table to convert unicode into glyph numbers
  202503. class CharToGlyphMapper
  202504. {
  202505. public:
  202506. CharToGlyphMapper (CGFontRef fontRef)
  202507. : segCount (0), endCode (0), startCode (0), idDelta (0),
  202508. idRangeOffset (0), glyphIndexes (0)
  202509. {
  202510. CFDataRef cmapTable = CGFontCopyTableForTag (fontRef, 'cmap');
  202511. if (cmapTable != 0)
  202512. {
  202513. const int numSubtables = getValue16 (cmapTable, 2);
  202514. for (int i = 0; i < numSubtables; ++i)
  202515. {
  202516. if (getValue16 (cmapTable, i * 8 + 4) == 0) // check for platform ID of 0
  202517. {
  202518. const int offset = getValue32 (cmapTable, i * 8 + 8);
  202519. if (getValue16 (cmapTable, offset) == 4) // check that it's format 4..
  202520. {
  202521. const int length = getValue16 (cmapTable, offset + 2);
  202522. const int segCountX2 = getValue16 (cmapTable, offset + 6);
  202523. segCount = segCountX2 / 2;
  202524. const int endCodeOffset = offset + 14;
  202525. const int startCodeOffset = endCodeOffset + 2 + segCountX2;
  202526. const int idDeltaOffset = startCodeOffset + segCountX2;
  202527. const int idRangeOffsetOffset = idDeltaOffset + segCountX2;
  202528. const int glyphIndexesOffset = idRangeOffsetOffset + segCountX2;
  202529. endCode = CFDataCreate (kCFAllocatorDefault, CFDataGetBytePtr (cmapTable) + endCodeOffset, segCountX2);
  202530. startCode = CFDataCreate (kCFAllocatorDefault, CFDataGetBytePtr (cmapTable) + startCodeOffset, segCountX2);
  202531. idDelta = CFDataCreate (kCFAllocatorDefault, CFDataGetBytePtr (cmapTable) + idDeltaOffset, segCountX2);
  202532. idRangeOffset = CFDataCreate (kCFAllocatorDefault, CFDataGetBytePtr (cmapTable) + idRangeOffsetOffset, segCountX2);
  202533. glyphIndexes = CFDataCreate (kCFAllocatorDefault, CFDataGetBytePtr (cmapTable) + glyphIndexesOffset, offset + length - glyphIndexesOffset);
  202534. }
  202535. break;
  202536. }
  202537. }
  202538. CFRelease (cmapTable);
  202539. }
  202540. }
  202541. ~CharToGlyphMapper()
  202542. {
  202543. if (endCode != 0)
  202544. {
  202545. CFRelease (endCode);
  202546. CFRelease (startCode);
  202547. CFRelease (idDelta);
  202548. CFRelease (idRangeOffset);
  202549. CFRelease (glyphIndexes);
  202550. }
  202551. }
  202552. int getGlyphForCharacter (const juce_wchar c) const
  202553. {
  202554. for (int i = 0; i < segCount; ++i)
  202555. {
  202556. if (getValue16 (endCode, i * 2) >= c)
  202557. {
  202558. const int start = getValue16 (startCode, i * 2);
  202559. if (start > c)
  202560. break;
  202561. const int delta = getValue16 (idDelta, i * 2);
  202562. const int rangeOffset = getValue16 (idRangeOffset, i * 2);
  202563. if (rangeOffset == 0)
  202564. return delta + c;
  202565. else
  202566. return getValue16 (glyphIndexes, 2 * ((rangeOffset / 2) + (c - start) - (segCount - i)));
  202567. }
  202568. }
  202569. // If we failed to find it "properly", this dodgy fall-back seems to do the trick for most fonts!
  202570. return jmax (-1, c - 29);
  202571. }
  202572. private:
  202573. int segCount;
  202574. CFDataRef endCode, startCode, idDelta, idRangeOffset, glyphIndexes;
  202575. static uint16 getValue16 (CFDataRef data, const int index)
  202576. {
  202577. return CFSwapInt16BigToHost (*(UInt16*) (CFDataGetBytePtr (data) + index));
  202578. }
  202579. static uint32 getValue32 (CFDataRef data, const int index)
  202580. {
  202581. return CFSwapInt32BigToHost (*(UInt32*) (CFDataGetBytePtr (data) + index));
  202582. }
  202583. };
  202584. ScopedPointer <CharToGlyphMapper> charToGlyphMapper;
  202585. #endif
  202586. };
  202587. const Typeface::Ptr Typeface::createSystemTypefaceFor (const Font& font)
  202588. {
  202589. return new MacTypeface (font);
  202590. }
  202591. const StringArray Font::findAllTypefaceNames() throw()
  202592. {
  202593. StringArray names;
  202594. const ScopedAutoReleasePool pool;
  202595. #if JUCE_IPHONE
  202596. NSArray* fonts = [UIFont familyNames];
  202597. #else
  202598. NSArray* fonts = [[NSFontManager sharedFontManager] availableFontFamilies];
  202599. #endif
  202600. for (unsigned int i = 0; i < [fonts count]; ++i)
  202601. names.add (nsStringToJuce ((NSString*) [fonts objectAtIndex: i]));
  202602. names.sort (true);
  202603. return names;
  202604. }
  202605. void Font::getPlatformDefaultFontNames (String& defaultSans, String& defaultSerif, String& defaultFixed) throw()
  202606. {
  202607. #if JUCE_IPHONE
  202608. defaultSans = "Helvetica";
  202609. defaultSerif = "Times New Roman";
  202610. defaultFixed = "Courier New";
  202611. #else
  202612. defaultSans = "Lucida Grande";
  202613. defaultSerif = "Times New Roman";
  202614. defaultFixed = "Monaco";
  202615. #endif
  202616. }
  202617. #endif
  202618. /********* End of inlined file: juce_mac_Fonts.mm *********/
  202619. /********* Start of inlined file: juce_mac_CoreGraphicsContext.mm *********/
  202620. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  202621. // compiled on its own).
  202622. #if JUCE_INCLUDED_FILE
  202623. class CoreGraphicsImage : public Image
  202624. {
  202625. public:
  202626. CoreGraphicsImage (const PixelFormat format_,
  202627. const int imageWidth_,
  202628. const int imageHeight_,
  202629. const bool clearImage)
  202630. : Image (format_, imageWidth_, imageHeight_, clearImage)
  202631. {
  202632. CGColorSpaceRef colourSpace = format == Image::SingleChannel ? CGColorSpaceCreateDeviceGray()
  202633. : CGColorSpaceCreateDeviceRGB();
  202634. context = CGBitmapContextCreate (imageData, imageWidth, imageHeight, 8, lineStride,
  202635. colourSpace, getCGImageFlags (*this));
  202636. CGColorSpaceRelease (colourSpace);
  202637. }
  202638. ~CoreGraphicsImage()
  202639. {
  202640. CGContextRelease (context);
  202641. }
  202642. LowLevelGraphicsContext* createLowLevelContext();
  202643. static CGImageRef createImage (const Image& juceImage, const bool forAlpha, CGColorSpaceRef colourSpace)
  202644. {
  202645. const CoreGraphicsImage* nativeImage = dynamic_cast <const CoreGraphicsImage*> (&juceImage);
  202646. if (nativeImage != 0 && (juceImage.getFormat() == Image::SingleChannel || ! forAlpha))
  202647. {
  202648. return CGBitmapContextCreateImage (nativeImage->context);
  202649. }
  202650. else
  202651. {
  202652. const Image::BitmapData srcData (juceImage, 0, 0, juceImage.getWidth(), juceImage.getHeight());
  202653. CGDataProviderRef provider = CGDataProviderCreateWithData (0, srcData.data, srcData.lineStride * srcData.pixelStride, 0);
  202654. CGImageRef imageRef = CGImageCreate (srcData.width, srcData.height,
  202655. 8, srcData.pixelStride * 8, srcData.lineStride,
  202656. colourSpace, getCGImageFlags (juceImage), provider,
  202657. 0, true, kCGRenderingIntentDefault);
  202658. CGDataProviderRelease (provider);
  202659. return imageRef;
  202660. }
  202661. }
  202662. #if JUCE_MAC
  202663. static NSImage* createNSImage (const Image& image)
  202664. {
  202665. const ScopedAutoReleasePool pool;
  202666. NSImage* im = [[NSImage alloc] init];
  202667. [im setSize: NSMakeSize (image.getWidth(), image.getHeight())];
  202668. [im lockFocus];
  202669. CGColorSpaceRef colourSpace = CGColorSpaceCreateDeviceRGB();
  202670. CGImageRef imageRef = createImage (image, false, colourSpace);
  202671. CGColorSpaceRelease (colourSpace);
  202672. CGContextRef cg = (CGContextRef) [[NSGraphicsContext currentContext] graphicsPort];
  202673. CGContextDrawImage (cg, CGRectMake (0, 0, image.getWidth(), image.getHeight()), imageRef);
  202674. CGImageRelease (imageRef);
  202675. [im unlockFocus];
  202676. return im;
  202677. }
  202678. #endif
  202679. CGContextRef context;
  202680. private:
  202681. static CGBitmapInfo getCGImageFlags (const Image& image)
  202682. {
  202683. #if JUCE_BIG_ENDIAN
  202684. return image.getFormat() == Image::ARGB ? (kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Big) : kCGBitmapByteOrderDefault;
  202685. #else
  202686. return image.getFormat() == Image::ARGB ? (kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Little) : kCGBitmapByteOrderDefault;
  202687. #endif
  202688. }
  202689. };
  202690. Image* Image::createNativeImage (const PixelFormat format, const int imageWidth, const int imageHeight, const bool clearImage)
  202691. {
  202692. #if USE_COREGRAPHICS_RENDERING
  202693. return new CoreGraphicsImage (format == RGB ? ARGB : format, imageWidth, imageHeight, clearImage);
  202694. #else
  202695. return new Image (format, imageWidth, imageHeight, clearImage);
  202696. #endif
  202697. }
  202698. class CoreGraphicsContext : public LowLevelGraphicsContext
  202699. {
  202700. public:
  202701. CoreGraphicsContext (CGContextRef context_, const float flipHeight_)
  202702. : context (context_),
  202703. flipHeight (flipHeight_),
  202704. numGradientLookupEntries (0)
  202705. {
  202706. CGContextRetain (context);
  202707. CGContextSaveGState(context);
  202708. CGContextSetShouldSmoothFonts (context, true);
  202709. CGContextSetShouldAntialias (context, true);
  202710. CGContextSetBlendMode (context, kCGBlendModeNormal);
  202711. rgbColourSpace = CGColorSpaceCreateDeviceRGB();
  202712. greyColourSpace = CGColorSpaceCreateDeviceGray();
  202713. gradientCallbacks.version = 0;
  202714. gradientCallbacks.evaluate = gradientCallback;
  202715. gradientCallbacks.releaseInfo = 0;
  202716. state = new SavedState();
  202717. }
  202718. ~CoreGraphicsContext()
  202719. {
  202720. CGContextRestoreGState (context);
  202721. CGContextRelease (context);
  202722. CGColorSpaceRelease (rgbColourSpace);
  202723. CGColorSpaceRelease (greyColourSpace);
  202724. }
  202725. bool isVectorDevice() const { return false; }
  202726. void setOrigin (int x, int y)
  202727. {
  202728. CGContextTranslateCTM (context, x, -y);
  202729. }
  202730. bool clipToRectangle (const Rectangle& r)
  202731. {
  202732. CGContextClipToRect (context, CGRectMake (r.getX(), flipHeight - r.getBottom(), r.getWidth(), r.getHeight()));
  202733. return ! isClipEmpty();
  202734. }
  202735. bool clipToRectangleList (const RectangleList& clipRegion)
  202736. {
  202737. if (clipRegion.isEmpty())
  202738. {
  202739. CGContextClipToRect (context, CGRectMake (0, 0, 0, 0));
  202740. return false;
  202741. }
  202742. else
  202743. {
  202744. const int numRects = clipRegion.getNumRectangles();
  202745. HeapBlock <CGRect> rects (numRects);
  202746. for (int i = 0; i < numRects; ++i)
  202747. {
  202748. const Rectangle& r = clipRegion.getRectangle(i);
  202749. rects[i] = CGRectMake (r.getX(), flipHeight - r.getBottom(), r.getWidth(), r.getHeight());
  202750. }
  202751. CGContextClipToRects (context, rects, numRects);
  202752. return ! isClipEmpty();
  202753. }
  202754. }
  202755. void excludeClipRectangle (const Rectangle& r)
  202756. {
  202757. RectangleList remaining (getClipBounds());
  202758. remaining.subtract (r);
  202759. clipToRectangleList (remaining);
  202760. }
  202761. void clipToPath (const Path& path, const AffineTransform& transform)
  202762. {
  202763. createPath (path, transform);
  202764. CGContextClip (context);
  202765. }
  202766. void clipToImageAlpha (const Image& sourceImage, const Rectangle& srcClip, const AffineTransform& transform)
  202767. {
  202768. if (! transform.isSingularity())
  202769. {
  202770. Image* singleChannelImage = createAlphaChannelImage (sourceImage);
  202771. CGImageRef image = CoreGraphicsImage::createImage (*singleChannelImage, true, greyColourSpace);
  202772. flip();
  202773. AffineTransform t (AffineTransform::scale (1.0f, -1.0f).translated (0, sourceImage.getHeight()).followedBy (transform));
  202774. applyTransform (t);
  202775. CGRect r = CGRectMake (0, 0, sourceImage.getWidth(), sourceImage.getHeight());
  202776. CGContextClipToMask (context, r, image);
  202777. applyTransform (t.inverted());
  202778. flip();
  202779. CGImageRelease (image);
  202780. deleteAlphaChannelImage (sourceImage, singleChannelImage);
  202781. }
  202782. }
  202783. bool clipRegionIntersects (const Rectangle& r)
  202784. {
  202785. return getClipBounds().intersects (r);
  202786. }
  202787. const Rectangle getClipBounds() const
  202788. {
  202789. CGRect bounds = CGRectIntegral (CGContextGetClipBoundingBox (context));
  202790. return Rectangle (roundToInt (bounds.origin.x),
  202791. roundToInt (flipHeight - (bounds.origin.y + bounds.size.height)),
  202792. roundToInt (bounds.size.width),
  202793. roundToInt (bounds.size.height));
  202794. }
  202795. bool isClipEmpty() const
  202796. {
  202797. return CGRectIsEmpty (CGContextGetClipBoundingBox (context));
  202798. }
  202799. void saveState()
  202800. {
  202801. CGContextSaveGState (context);
  202802. stateStack.add (new SavedState (*state));
  202803. }
  202804. void restoreState()
  202805. {
  202806. CGContextRestoreGState (context);
  202807. SavedState* const top = stateStack.getLast();
  202808. if (top != 0)
  202809. {
  202810. state = top;
  202811. stateStack.removeLast (1, false);
  202812. }
  202813. else
  202814. {
  202815. jassertfalse // trying to pop with an empty stack!
  202816. }
  202817. }
  202818. void setFill (const FillType& fillType)
  202819. {
  202820. state->fillType = fillType;
  202821. if (fillType.isColour())
  202822. {
  202823. CGContextSetRGBFillColor (context, fillType.colour.getFloatRed(), fillType.colour.getFloatGreen(),
  202824. fillType.colour.getFloatBlue(), fillType.colour.getFloatAlpha());
  202825. CGContextSetAlpha (context, 1.0f);
  202826. }
  202827. }
  202828. void setOpacity (float newOpacity)
  202829. {
  202830. state->fillType.setOpacity (newOpacity);
  202831. setFill (state->fillType);
  202832. }
  202833. void setInterpolationQuality (Graphics::ResamplingQuality quality)
  202834. {
  202835. CGContextSetInterpolationQuality (context, quality == Graphics::lowResamplingQuality
  202836. ? kCGInterpolationLow
  202837. : kCGInterpolationHigh);
  202838. }
  202839. void fillRect (const Rectangle& r, const bool replaceExistingContents)
  202840. {
  202841. CGRect cgRect = CGRectMake (r.getX(), flipHeight - r.getBottom(), r.getWidth(), r.getHeight());
  202842. if (replaceExistingContents)
  202843. {
  202844. #if MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_5
  202845. CGContextClearRect (context, cgRect);
  202846. #else
  202847. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
  202848. if (CGContextDrawLinearGradient == 0) // (just a way of checking whether we're running in 10.5 or later)
  202849. CGContextClearRect (context, cgRect);
  202850. else
  202851. #endif
  202852. CGContextSetBlendMode (context, kCGBlendModeCopy);
  202853. #endif
  202854. fillRect (r, false);
  202855. CGContextSetBlendMode (context, kCGBlendModeNormal);
  202856. }
  202857. else
  202858. {
  202859. if (state->fillType.isColour())
  202860. {
  202861. CGContextFillRect (context, cgRect);
  202862. }
  202863. else if (state->fillType.isGradient())
  202864. {
  202865. CGContextSaveGState (context);
  202866. CGContextClipToRect (context, cgRect);
  202867. drawGradient();
  202868. CGContextRestoreGState (context);
  202869. }
  202870. else
  202871. {
  202872. CGContextSaveGState (context);
  202873. CGContextClipToRect (context, cgRect);
  202874. drawImage (*(state->fillType.image), state->fillType.image->getBounds(), state->fillType.transform, true);
  202875. CGContextRestoreGState (context);
  202876. }
  202877. }
  202878. }
  202879. void fillPath (const Path& path, const AffineTransform& transform)
  202880. {
  202881. CGContextSaveGState (context);
  202882. if (state->fillType.isColour())
  202883. {
  202884. flip();
  202885. applyTransform (transform);
  202886. createPath (path);
  202887. if (path.isUsingNonZeroWinding())
  202888. CGContextFillPath (context);
  202889. else
  202890. CGContextEOFillPath (context);
  202891. }
  202892. else
  202893. {
  202894. createPath (path, transform);
  202895. if (path.isUsingNonZeroWinding())
  202896. CGContextClip (context);
  202897. else
  202898. CGContextEOClip (context);
  202899. if (state->fillType.isGradient())
  202900. drawGradient();
  202901. else
  202902. drawImage (*(state->fillType.image), state->fillType.image->getBounds(), state->fillType.transform, true);
  202903. }
  202904. CGContextRestoreGState (context);
  202905. }
  202906. void drawImage (const Image& sourceImage, const Rectangle& srcClip,
  202907. const AffineTransform& transform, const bool fillEntireClipAsTiles)
  202908. {
  202909. jassert (sourceImage.getBounds().contains (srcClip));
  202910. CGImageRef fullImage = CoreGraphicsImage::createImage (sourceImage, false, rgbColourSpace);
  202911. CGImageRef image = fullImage;
  202912. if (srcClip != sourceImage.getBounds())
  202913. {
  202914. image = CGImageCreateWithImageInRect (fullImage, CGRectMake (srcClip.getX(), srcClip.getY(),
  202915. srcClip.getWidth(), srcClip.getHeight()));
  202916. CGImageRelease (fullImage);
  202917. }
  202918. CGContextSaveGState (context);
  202919. CGContextSetAlpha (context, state->fillType.getOpacity());
  202920. flip();
  202921. applyTransform (AffineTransform::scale (1.0f, -1.0f).translated (0, srcClip.getHeight()).followedBy (transform));
  202922. CGRect imageRect = CGRectMake (0, 0, srcClip.getWidth(), srcClip.getHeight());
  202923. if (fillEntireClipAsTiles)
  202924. {
  202925. #if JUCE_IPHONE || (MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5)
  202926. CGContextDrawTiledImage (context, imageRect, image);
  202927. #else
  202928. #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
  202929. if (CGContextDrawTiledImage != 0)
  202930. CGContextDrawTiledImage (context, imageRect, image);
  202931. else
  202932. #endif
  202933. {
  202934. // Fallback to manually doing a tiled fill on 10.4
  202935. CGRect clip = CGRectIntegral (CGContextGetClipBoundingBox (context));
  202936. const int iw = srcClip.getWidth();
  202937. const int ih = srcClip.getHeight();
  202938. int x = 0, y = 0;
  202939. while (x > clip.origin.x) x -= iw;
  202940. while (y > clip.origin.y) y -= ih;
  202941. const int right = (int) (clip.origin.x + clip.size.width);
  202942. const int bottom = (int) (clip.origin.y + clip.size.height);
  202943. while (y < bottom)
  202944. {
  202945. for (int x2 = x; x2 < right; x2 += iw)
  202946. CGContextDrawImage (context, CGRectMake (x2, y, iw, ih), image);
  202947. y += ih;
  202948. }
  202949. }
  202950. #endif
  202951. }
  202952. else
  202953. {
  202954. CGContextDrawImage (context, imageRect, image);
  202955. }
  202956. CGImageRelease (image); // (This causes a memory bug in iPhone sim 3.0 - try upgrading to a later version if you hit this)
  202957. CGContextRestoreGState (context);
  202958. }
  202959. void drawLine (double x1, double y1, double x2, double y2)
  202960. {
  202961. CGContextSetLineCap (context, kCGLineCapSquare);
  202962. CGContextSetLineWidth (context, 1.0f);
  202963. CGContextSetRGBStrokeColor (context,
  202964. state->fillType.colour.getFloatRed(), state->fillType.colour.getFloatGreen(),
  202965. state->fillType.colour.getFloatBlue(), state->fillType.colour.getFloatAlpha());
  202966. CGPoint line[] = { { (float) x1 + 0.5f, flipHeight - ((float) y1 + 0.5f) },
  202967. { (float) x2 + 0.5f, flipHeight - ((float) y2 + 0.5f) } };
  202968. CGContextStrokeLineSegments (context, line, 1);
  202969. }
  202970. void drawVerticalLine (const int x, double top, double bottom)
  202971. {
  202972. #if MAC_OS_X_VERSION_MIN_REQUIRED > MAC_OS_X_VERSION_10_5
  202973. CGContextFillRect (context, CGRectMake (x, flipHeight - (float) bottom, 1.0f, (float) (bottom - top)));
  202974. #else
  202975. // On Leopard, unless both co-ordinates are non-integer, it disables anti-aliasing, so nudge
  202976. // the x co-ord slightly to trick it..
  202977. CGContextFillRect (context, CGRectMake (x + 1.0f / 256.0f, flipHeight - (float) bottom, 1.0f + 1.0f / 256.0f, (float) (bottom - top)));
  202978. #endif
  202979. }
  202980. void drawHorizontalLine (const int y, double left, double right)
  202981. {
  202982. #if MAC_OS_X_VERSION_MIN_REQUIRED > MAC_OS_X_VERSION_10_5
  202983. CGContextFillRect (context, CGRectMake ((float) left, flipHeight - (y + 1.0f), (float) (right - left), 1.0f));
  202984. #else
  202985. // On Leopard, unless both co-ordinates are non-integer, it disables anti-aliasing, so nudge
  202986. // the x co-ord slightly to trick it..
  202987. CGContextFillRect (context, CGRectMake ((float) left, flipHeight - (y + (1.0f + 1.0f / 256.0f)), (float) (right - left), 1.0f + 1.0f / 256.0f));
  202988. #endif
  202989. }
  202990. void setFont (const Font& newFont)
  202991. {
  202992. if (state->font != newFont)
  202993. {
  202994. state->fontRef = 0;
  202995. state->font = newFont;
  202996. MacTypeface* mf = dynamic_cast <MacTypeface*> ((Typeface*) state->font.getTypeface());
  202997. if (mf != 0)
  202998. {
  202999. state->fontRef = mf->fontRef;
  203000. CGContextSetFont (context, state->fontRef);
  203001. CGContextSetFontSize (context, state->font.getHeight() * mf->fontHeightToCGSizeFactor);
  203002. state->fontTransform = mf->renderingTransform;
  203003. state->fontTransform.a *= state->font.getHorizontalScale();
  203004. CGContextSetTextMatrix (context, state->fontTransform);
  203005. }
  203006. }
  203007. }
  203008. const Font getFont()
  203009. {
  203010. return state->font;
  203011. }
  203012. void drawGlyph (int glyphNumber, const AffineTransform& transform)
  203013. {
  203014. if (state->fontRef != 0 && state->fillType.isColour())
  203015. {
  203016. if (transform.isOnlyTranslation())
  203017. {
  203018. CGGlyph g = glyphNumber;
  203019. CGContextShowGlyphsAtPoint (context, transform.getTranslationX(),
  203020. flipHeight - roundToInt (transform.getTranslationY()), &g, 1);
  203021. }
  203022. else
  203023. {
  203024. CGContextSaveGState (context);
  203025. flip();
  203026. applyTransform (transform);
  203027. CGAffineTransform t = state->fontTransform;
  203028. t.d = -t.d;
  203029. CGContextSetTextMatrix (context, t);
  203030. CGGlyph g = glyphNumber;
  203031. CGContextShowGlyphsAtPoint (context, 0, 0, &g, 1);
  203032. CGContextSetTextMatrix (context, state->fontTransform);
  203033. CGContextRestoreGState (context);
  203034. }
  203035. }
  203036. else
  203037. {
  203038. Path p;
  203039. Font& f = state->font;
  203040. f.getTypeface()->getOutlineForGlyph (glyphNumber, p);
  203041. fillPath (p, AffineTransform::scale (f.getHeight() * f.getHorizontalScale(), f.getHeight())
  203042. .followedBy (transform));
  203043. }
  203044. }
  203045. private:
  203046. CGContextRef context;
  203047. const float flipHeight;
  203048. CGColorSpaceRef rgbColourSpace, greyColourSpace;
  203049. CGFunctionCallbacks gradientCallbacks;
  203050. struct SavedState
  203051. {
  203052. SavedState()
  203053. : font (1.0f), fontRef (0), fontTransform (CGAffineTransformIdentity)
  203054. {
  203055. }
  203056. SavedState (const SavedState& other)
  203057. : fillType (other.fillType), font (other.font), fontRef (other.fontRef),
  203058. fontTransform (other.fontTransform)
  203059. {
  203060. }
  203061. ~SavedState()
  203062. {
  203063. }
  203064. FillType fillType;
  203065. Font font;
  203066. CGFontRef fontRef;
  203067. CGAffineTransform fontTransform;
  203068. };
  203069. ScopedPointer <SavedState> state;
  203070. OwnedArray <SavedState> stateStack;
  203071. HeapBlock <PixelARGB> gradientLookupTable;
  203072. int numGradientLookupEntries;
  203073. static void gradientCallback (void* info, const CGFloat* inData, CGFloat* outData)
  203074. {
  203075. const CoreGraphicsContext* const g = (const CoreGraphicsContext*) info;
  203076. const int index = roundToInt (g->numGradientLookupEntries * inData[0]);
  203077. PixelARGB colour (g->gradientLookupTable [jlimit (0, g->numGradientLookupEntries, index)]);
  203078. colour.unpremultiply();
  203079. outData[0] = colour.getRed() / 255.0f;
  203080. outData[1] = colour.getGreen() / 255.0f;
  203081. outData[2] = colour.getBlue() / 255.0f;
  203082. outData[3] = colour.getAlpha() / 255.0f;
  203083. }
  203084. CGShadingRef createGradient (const AffineTransform& transform, ColourGradient gradient)
  203085. {
  203086. numGradientLookupEntries = gradient.createLookupTable (transform, gradientLookupTable);
  203087. --numGradientLookupEntries;
  203088. CGShadingRef result = 0;
  203089. CGFunctionRef function = CGFunctionCreate ((void*) this, 1, 0, 4, 0, &gradientCallbacks);
  203090. CGPoint p1 (CGPointMake (gradient.x1, gradient.y1));
  203091. if (gradient.isRadial)
  203092. {
  203093. result = CGShadingCreateRadial (rgbColourSpace, p1, 0,
  203094. p1, hypotf (gradient.x1 - gradient.x2, gradient.y1 - gradient.y2),
  203095. function, true, true);
  203096. }
  203097. else
  203098. {
  203099. result = CGShadingCreateAxial (rgbColourSpace, p1,
  203100. CGPointMake (gradient.x2, gradient.y2),
  203101. function, true, true);
  203102. }
  203103. CGFunctionRelease (function);
  203104. return result;
  203105. }
  203106. void drawGradient()
  203107. {
  203108. flip();
  203109. applyTransform (state->fillType.transform);
  203110. CGContextSetInterpolationQuality (context, kCGInterpolationDefault); // (This is required for 10.4, where there's a crash if
  203111. // you draw a gradient with high quality interp enabled).
  203112. CGShadingRef shading = createGradient (state->fillType.transform, *(state->fillType.gradient));
  203113. CGContextSetAlpha (context, state->fillType.getOpacity());
  203114. CGContextDrawShading (context, shading);
  203115. CGShadingRelease (shading);
  203116. }
  203117. void createPath (const Path& path) const
  203118. {
  203119. CGContextBeginPath (context);
  203120. Path::Iterator i (path);
  203121. while (i.next())
  203122. {
  203123. switch (i.elementType)
  203124. {
  203125. case Path::Iterator::startNewSubPath:
  203126. CGContextMoveToPoint (context, i.x1, i.y1);
  203127. break;
  203128. case Path::Iterator::lineTo:
  203129. CGContextAddLineToPoint (context, i.x1, i.y1);
  203130. break;
  203131. case Path::Iterator::quadraticTo:
  203132. CGContextAddQuadCurveToPoint (context, i.x1, i.y1, i.x2, i.y2);
  203133. break;
  203134. case Path::Iterator::cubicTo:
  203135. CGContextAddCurveToPoint (context, i.x1, i.y1, i.x2, i.y2, i.x3, i.y3);
  203136. break;
  203137. case Path::Iterator::closePath:
  203138. CGContextClosePath (context); break;
  203139. default:
  203140. jassertfalse
  203141. break;
  203142. }
  203143. }
  203144. }
  203145. void createPath (const Path& path, const AffineTransform& transform) const
  203146. {
  203147. CGContextBeginPath (context);
  203148. Path::Iterator i (path);
  203149. while (i.next())
  203150. {
  203151. switch (i.elementType)
  203152. {
  203153. case Path::Iterator::startNewSubPath:
  203154. transform.transformPoint (i.x1, i.y1);
  203155. CGContextMoveToPoint (context, i.x1, flipHeight - i.y1);
  203156. break;
  203157. case Path::Iterator::lineTo:
  203158. transform.transformPoint (i.x1, i.y1);
  203159. CGContextAddLineToPoint (context, i.x1, flipHeight - i.y1);
  203160. break;
  203161. case Path::Iterator::quadraticTo:
  203162. transform.transformPoint (i.x1, i.y1);
  203163. transform.transformPoint (i.x2, i.y2);
  203164. CGContextAddQuadCurveToPoint (context, i.x1, flipHeight - i.y1, i.x2, flipHeight - i.y2);
  203165. break;
  203166. case Path::Iterator::cubicTo:
  203167. transform.transformPoint (i.x1, i.y1);
  203168. transform.transformPoint (i.x2, i.y2);
  203169. transform.transformPoint (i.x3, i.y3);
  203170. CGContextAddCurveToPoint (context, i.x1, flipHeight - i.y1, i.x2, flipHeight - i.y2, i.x3, flipHeight - i.y3);
  203171. break;
  203172. case Path::Iterator::closePath:
  203173. CGContextClosePath (context); break;
  203174. default:
  203175. jassertfalse
  203176. break;
  203177. }
  203178. }
  203179. }
  203180. static Image* createAlphaChannelImage (const Image& im)
  203181. {
  203182. if (im.getFormat() == Image::SingleChannel)
  203183. return const_cast <Image*> (&im);
  203184. return im.createCopyOfAlphaChannel();
  203185. }
  203186. static void deleteAlphaChannelImage (const Image& im, Image* const alphaIm)
  203187. {
  203188. if (im.getFormat() != Image::SingleChannel)
  203189. delete alphaIm;
  203190. }
  203191. void flip() const
  203192. {
  203193. CGContextConcatCTM (context, CGAffineTransformMake (1, 0, 0, -1, 0, flipHeight));
  203194. }
  203195. void applyTransform (const AffineTransform& transform) const
  203196. {
  203197. CGAffineTransform t;
  203198. t.a = transform.mat00;
  203199. t.b = transform.mat10;
  203200. t.c = transform.mat01;
  203201. t.d = transform.mat11;
  203202. t.tx = transform.mat02;
  203203. t.ty = transform.mat12;
  203204. CGContextConcatCTM (context, t);
  203205. }
  203206. float flipY (float y) const
  203207. {
  203208. return flipHeight - y;
  203209. }
  203210. };
  203211. LowLevelGraphicsContext* CoreGraphicsImage::createLowLevelContext()
  203212. {
  203213. return new CoreGraphicsContext (context, imageHeight);
  203214. }
  203215. #endif
  203216. /********* End of inlined file: juce_mac_CoreGraphicsContext.mm *********/
  203217. /********* Start of inlined file: juce_iphone_UIViewComponentPeer.mm *********/
  203218. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  203219. // compiled on its own).
  203220. #if JUCE_INCLUDED_FILE
  203221. class UIViewComponentPeer;
  203222. END_JUCE_NAMESPACE
  203223. #define JuceUIView MakeObjCClassName(JuceUIView)
  203224. @interface JuceUIView : UIView
  203225. {
  203226. @public
  203227. UIViewComponentPeer* owner;
  203228. }
  203229. - (JuceUIView*) initWithOwner: (UIViewComponentPeer*) owner withFrame: (CGRect) frame;
  203230. - (void) dealloc;
  203231. - (void) drawRect: (CGRect) r;
  203232. - (void) touchesBegan: (NSSet*) touches withEvent: (UIEvent*) event;
  203233. - (void) touchesMoved: (NSSet*) touches withEvent: (UIEvent*) event;
  203234. - (void) touchesEnded: (NSSet*) touches withEvent: (UIEvent*) event;
  203235. - (void) touchesCancelled: (NSSet*) touches withEvent: (UIEvent*) event;
  203236. - (BOOL) becomeFirstResponder;
  203237. - (BOOL) resignFirstResponder;
  203238. - (BOOL) canBecomeFirstResponder;
  203239. - (void) asyncRepaint: (id) rect;
  203240. @end
  203241. #define JuceUIWindow MakeObjCClassName(JuceUIWindow)
  203242. @interface JuceUIWindow : UIWindow
  203243. {
  203244. @private
  203245. UIViewComponentPeer* owner;
  203246. bool isZooming;
  203247. }
  203248. - (void) setOwner: (UIViewComponentPeer*) owner;
  203249. - (void) becomeKeyWindow;
  203250. @end
  203251. BEGIN_JUCE_NAMESPACE
  203252. class UIViewComponentPeer : public ComponentPeer
  203253. {
  203254. public:
  203255. UIViewComponentPeer (Component* const component,
  203256. const int windowStyleFlags,
  203257. UIView* viewToAttachTo);
  203258. ~UIViewComponentPeer();
  203259. void* getNativeHandle() const;
  203260. void setVisible (bool shouldBeVisible);
  203261. void setTitle (const String& title);
  203262. void setPosition (int x, int y);
  203263. void setSize (int w, int h);
  203264. void setBounds (int x, int y, int w, int h, const bool isNowFullScreen);
  203265. void getBounds (int& x, int& y, int& w, int& h, const bool global) const;
  203266. void getBounds (int& x, int& y, int& w, int& h) const;
  203267. int getScreenX() const;
  203268. int getScreenY() const;
  203269. void relativePositionToGlobal (int& x, int& y);
  203270. void globalPositionToRelative (int& x, int& y);
  203271. void setMinimised (bool shouldBeMinimised);
  203272. bool isMinimised() const;
  203273. void setFullScreen (bool shouldBeFullScreen);
  203274. bool isFullScreen() const;
  203275. bool contains (int x, int y, bool trueIfInAChildWindow) const;
  203276. const BorderSize getFrameSize() const;
  203277. bool setAlwaysOnTop (bool alwaysOnTop);
  203278. void toFront (bool makeActiveWindow);
  203279. void toBehind (ComponentPeer* other);
  203280. void setIcon (const Image& newIcon);
  203281. virtual void drawRect (CGRect r);
  203282. virtual bool canBecomeKeyWindow();
  203283. virtual bool windowShouldClose();
  203284. virtual void redirectMovedOrResized();
  203285. virtual CGRect constrainRect (CGRect r);
  203286. virtual void viewFocusGain();
  203287. virtual void viewFocusLoss();
  203288. bool isFocused() const;
  203289. void grabFocus();
  203290. void textInputRequired (int x, int y);
  203291. void repaint (int x, int y, int w, int h);
  203292. void performAnyPendingRepaintsNow();
  203293. juce_UseDebuggingNewOperator
  203294. UIWindow* window;
  203295. JuceUIView* view;
  203296. bool isSharedWindow, fullScreen, insideDrawRect;
  203297. };
  203298. END_JUCE_NAMESPACE
  203299. @implementation JuceUIView
  203300. - (JuceUIView*) initWithOwner: (UIViewComponentPeer*) owner_
  203301. withFrame: (CGRect) frame
  203302. {
  203303. [super initWithFrame: frame];
  203304. owner = owner_;
  203305. return self;
  203306. }
  203307. - (void) dealloc
  203308. {
  203309. [super dealloc];
  203310. }
  203311. - (void) drawRect: (CGRect) r
  203312. {
  203313. if (owner != 0)
  203314. owner->drawRect (r);
  203315. }
  203316. bool KeyPress::isKeyCurrentlyDown (const int keyCode) throw()
  203317. {
  203318. return false;
  203319. }
  203320. static int currentModifiers = 0;
  203321. const ModifierKeys ModifierKeys::getCurrentModifiersRealtime() throw()
  203322. {
  203323. return ModifierKeys (currentModifiers);
  203324. }
  203325. void ModifierKeys::updateCurrentModifiers() throw()
  203326. {
  203327. currentModifierFlags = currentModifiers;
  203328. }
  203329. static int getModifierForButtonNumber (const int num)
  203330. {
  203331. return num == 0 ? ModifierKeys::leftButtonModifier
  203332. : (num == 1 ? ModifierKeys::rightButtonModifier
  203333. : (num == 2 ? ModifierKeys::middleButtonModifier : 0));
  203334. }
  203335. static int64 getMouseTime (UIEvent* e)
  203336. {
  203337. return (Time::currentTimeMillis() - Time::getMillisecondCounter())
  203338. + (int64) ([e timestamp] * 1000.0);
  203339. }
  203340. int juce_lastMouseX = 0, juce_lastMouseY = 0;
  203341. - (void) touchesBegan: (NSSet*) touches withEvent: (UIEvent*) event
  203342. {
  203343. if (owner == 0)
  203344. return;
  203345. NSArray* const t = [[event touchesForView: self] allObjects];
  203346. switch ([t count])
  203347. {
  203348. case 1: // One finger..
  203349. {
  203350. CGPoint p = [[t objectAtIndex: 0] locationInView: self];
  203351. currentModifiers |= getModifierForButtonNumber (0);
  203352. int x, y, w, h;
  203353. owner->getBounds (x, y, w, h, true);
  203354. juce_lastMouseX = x + (int) p.x;
  203355. juce_lastMouseY = y + (int) p.y;
  203356. owner->handleMouseMove ((int) p.x, (int) p.y, getMouseTime (event));
  203357. if (owner != 0)
  203358. owner->handleMouseDown ((int) p.x, (int) p.y, getMouseTime (event));
  203359. }
  203360. default:
  203361. //xxx multi-touch..
  203362. break;
  203363. }
  203364. }
  203365. - (void) touchesMoved: (NSSet*) touches withEvent: (UIEvent*) event
  203366. {
  203367. if (owner == 0)
  203368. return;
  203369. NSArray* const t = [[event touchesForView: self] allObjects];
  203370. switch ([t count])
  203371. {
  203372. case 1: // One finger..
  203373. {
  203374. CGPoint p = [[t objectAtIndex: 0] locationInView: self];
  203375. int x, y, w, h;
  203376. owner->getBounds (x, y, w, h, true);
  203377. juce_lastMouseX = x + (int) p.x;
  203378. juce_lastMouseY = y + (int) p.y;
  203379. owner->handleMouseDrag ((int) p.x, (int) p.y, getMouseTime (event));
  203380. }
  203381. default:
  203382. //xxx multi-touch..
  203383. break;
  203384. }
  203385. }
  203386. - (void) touchesEnded: (NSSet*) touches withEvent: (UIEvent*) event
  203387. {
  203388. if (owner == 0)
  203389. return;
  203390. NSArray* const t = [[event touchesForView: self] allObjects];
  203391. switch ([t count])
  203392. {
  203393. case 1: // One finger..
  203394. {
  203395. CGPoint p = [[t objectAtIndex: 0] locationInView: self];
  203396. int x, y, w, h;
  203397. owner->getBounds (x, y, w, h, true);
  203398. juce_lastMouseX = x + (int) p.x;
  203399. juce_lastMouseY = y + (int) p.y;
  203400. const int oldMods = currentModifiers;
  203401. currentModifiers &= ~getModifierForButtonNumber (0);
  203402. owner->handleMouseUp (oldMods, (int) p.x, (int) p.y, getMouseTime (event));
  203403. }
  203404. default:
  203405. //xxx multi-touch..
  203406. break;
  203407. }
  203408. }
  203409. - (void) touchesCancelled: (NSSet*) touches withEvent: (UIEvent*) event
  203410. {
  203411. [self touchesEnded: touches withEvent: event];
  203412. }
  203413. - (BOOL) becomeFirstResponder
  203414. {
  203415. if (owner != 0)
  203416. owner->viewFocusGain();
  203417. return true;
  203418. }
  203419. - (BOOL) resignFirstResponder
  203420. {
  203421. if (owner != 0)
  203422. owner->viewFocusLoss();
  203423. return true;
  203424. }
  203425. - (BOOL) canBecomeFirstResponder
  203426. {
  203427. return owner != 0 && owner->canBecomeKeyWindow();
  203428. }
  203429. - (void) asyncRepaint: (id) rect
  203430. {
  203431. CGRect* r = (CGRect*) [((NSData*) rect) bytes];
  203432. [self setNeedsDisplayInRect: *r];
  203433. }
  203434. @end
  203435. @implementation JuceUIWindow
  203436. - (void) setOwner: (UIViewComponentPeer*) owner_
  203437. {
  203438. owner = owner_;
  203439. isZooming = false;
  203440. }
  203441. - (void) becomeKeyWindow
  203442. {
  203443. [super becomeKeyWindow];
  203444. if (owner != 0)
  203445. owner->grabFocus();
  203446. }
  203447. @end
  203448. BEGIN_JUCE_NAMESPACE
  203449. UIViewComponentPeer::UIViewComponentPeer (Component* const component,
  203450. const int windowStyleFlags,
  203451. UIView* viewToAttachTo)
  203452. : ComponentPeer (component, windowStyleFlags),
  203453. window (0),
  203454. view (0),
  203455. isSharedWindow (viewToAttachTo != 0),
  203456. fullScreen (false),
  203457. insideDrawRect (false)
  203458. {
  203459. CGRect r;
  203460. r.origin.x = 0;
  203461. r.origin.y = 0;
  203462. r.size.width = (float) component->getWidth();
  203463. r.size.height = (float) component->getHeight();
  203464. view = [[JuceUIView alloc] initWithOwner: this withFrame: r];
  203465. if (isSharedWindow)
  203466. {
  203467. window = [viewToAttachTo window];
  203468. [viewToAttachTo addSubview: view];
  203469. setVisible (component->isVisible());
  203470. }
  203471. else
  203472. {
  203473. r.origin.x = (float) component->getX();
  203474. r.origin.y = (float) component->getY();
  203475. r.origin.y = [[UIScreen mainScreen] bounds].size.height - (r.origin.y + r.size.height);
  203476. window = [[JuceUIWindow alloc] init];
  203477. window.frame = r;
  203478. window.opaque = component->isOpaque();
  203479. view.opaque = component->isOpaque();
  203480. window.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent: 0];
  203481. view.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent: 0];
  203482. [((JuceUIWindow*) window) setOwner: this];
  203483. if (component->isAlwaysOnTop())
  203484. window.windowLevel = UIWindowLevelAlert;
  203485. [window addSubview: view];
  203486. view.frame = CGRectMake (0, 0, r.size.width, r.size.height);
  203487. view.hidden = ! component->isVisible();
  203488. window.hidden = ! component->isVisible();
  203489. }
  203490. setTitle (component->getName());
  203491. }
  203492. UIViewComponentPeer::~UIViewComponentPeer()
  203493. {
  203494. view->owner = 0;
  203495. [view removeFromSuperview];
  203496. [view release];
  203497. if (! isSharedWindow)
  203498. {
  203499. [((JuceUIWindow*) window) setOwner: 0];
  203500. [window release];
  203501. }
  203502. }
  203503. void* UIViewComponentPeer::getNativeHandle() const
  203504. {
  203505. return view;
  203506. }
  203507. void UIViewComponentPeer::setVisible (bool shouldBeVisible)
  203508. {
  203509. view.hidden = ! shouldBeVisible;
  203510. if (! isSharedWindow)
  203511. window.hidden = ! shouldBeVisible;
  203512. }
  203513. void UIViewComponentPeer::setTitle (const String& title)
  203514. {
  203515. // xxx is this possible?
  203516. }
  203517. void UIViewComponentPeer::setPosition (int x, int y)
  203518. {
  203519. setBounds (x, y, component->getWidth(), component->getHeight(), false);
  203520. }
  203521. void UIViewComponentPeer::setSize (int w, int h)
  203522. {
  203523. setBounds (component->getX(), component->getY(), w, h, false);
  203524. }
  203525. void UIViewComponentPeer::setBounds (int x, int y, int w, int h, const bool isNowFullScreen)
  203526. {
  203527. fullScreen = isNowFullScreen;
  203528. w = jmax (0, w);
  203529. h = jmax (0, h);
  203530. CGRect r;
  203531. r.origin.x = (float) x;
  203532. r.origin.y = (float) y;
  203533. r.size.width = (float) w;
  203534. r.size.height = (float) h;
  203535. if (isSharedWindow)
  203536. {
  203537. //r.origin.y = [[view superview] frame].size.height - (r.origin.y + r.size.height);
  203538. if ([view frame].size.width != r.size.width
  203539. || [view frame].size.height != r.size.height)
  203540. [view setNeedsDisplay];
  203541. view.frame = r;
  203542. }
  203543. else
  203544. {
  203545. window.frame = r;
  203546. view.frame = CGRectMake (0, 0, r.size.width, r.size.height);
  203547. }
  203548. }
  203549. void UIViewComponentPeer::getBounds (int& x, int& y, int& w, int& h, const bool global) const
  203550. {
  203551. CGRect r = [view frame];
  203552. if (global && [view window] != 0)
  203553. {
  203554. r = [view convertRect: r toView: nil];
  203555. CGRect wr = [[view window] frame];
  203556. r.origin.x += wr.origin.x;
  203557. r.origin.y += wr.origin.y;
  203558. }
  203559. x = (int) r.origin.x;
  203560. y = (int) r.origin.y;
  203561. w = (int) r.size.width;
  203562. h = (int) r.size.height;
  203563. }
  203564. void UIViewComponentPeer::getBounds (int& x, int& y, int& w, int& h) const
  203565. {
  203566. getBounds (x, y, w, h, ! isSharedWindow);
  203567. }
  203568. int UIViewComponentPeer::getScreenX() const
  203569. {
  203570. int x, y, w, h;
  203571. getBounds (x, y, w, h, true);
  203572. return x;
  203573. }
  203574. int UIViewComponentPeer::getScreenY() const
  203575. {
  203576. int x, y, w, h;
  203577. getBounds (x, y, w, h, true);
  203578. return y;
  203579. }
  203580. void UIViewComponentPeer::relativePositionToGlobal (int& x, int& y)
  203581. {
  203582. int wx, wy, ww, wh;
  203583. getBounds (wx, wy, ww, wh, true);
  203584. x += wx;
  203585. y += wy;
  203586. }
  203587. void UIViewComponentPeer::globalPositionToRelative (int& x, int& y)
  203588. {
  203589. int wx, wy, ww, wh;
  203590. getBounds (wx, wy, ww, wh, true);
  203591. x -= wx;
  203592. y -= wy;
  203593. }
  203594. CGRect UIViewComponentPeer::constrainRect (CGRect r)
  203595. {
  203596. if (constrainer != 0)
  203597. {
  203598. CGRect current = [window frame];
  203599. current.origin.y = [[UIScreen mainScreen] bounds].size.height - current.origin.y - current.size.height;
  203600. r.origin.y = [[UIScreen mainScreen] bounds].size.height - r.origin.y - r.size.height;
  203601. int x = (int) r.origin.x;
  203602. int y = (int) r.origin.y;
  203603. int w = (int) r.size.width;
  203604. int h = (int) r.size.height;
  203605. Rectangle original ((int) current.origin.x, (int) current.origin.y,
  203606. (int) current.size.width, (int) current.size.height);
  203607. constrainer->checkBounds (x, y, w, h,
  203608. original,
  203609. Desktop::getInstance().getAllMonitorDisplayAreas().getBounds(),
  203610. y != original.getY() && y + h == original.getBottom(),
  203611. x != original.getX() && x + w == original.getRight(),
  203612. y == original.getY() && y + h != original.getBottom(),
  203613. x == original.getX() && x + w != original.getRight());
  203614. r.origin.x = x;
  203615. r.origin.y = [[UIScreen mainScreen] bounds].size.height - r.size.height - y;
  203616. r.size.width = w;
  203617. r.size.height = h;
  203618. }
  203619. return r;
  203620. }
  203621. void UIViewComponentPeer::setMinimised (bool shouldBeMinimised)
  203622. {
  203623. // xxx
  203624. }
  203625. bool UIViewComponentPeer::isMinimised() const
  203626. {
  203627. return false;
  203628. }
  203629. void UIViewComponentPeer::setFullScreen (bool shouldBeFullScreen)
  203630. {
  203631. if (! isSharedWindow)
  203632. {
  203633. Rectangle r (lastNonFullscreenBounds);
  203634. setMinimised (false);
  203635. if (fullScreen != shouldBeFullScreen)
  203636. {
  203637. if (shouldBeFullScreen)
  203638. r = Desktop::getInstance().getMainMonitorArea();
  203639. // (can't call the component's setBounds method because that'll reset our fullscreen flag)
  203640. if (r != getComponent()->getBounds() && ! r.isEmpty())
  203641. setBounds (r.getX(), r.getY(), r.getWidth(), r.getHeight(), shouldBeFullScreen);
  203642. }
  203643. }
  203644. }
  203645. bool UIViewComponentPeer::isFullScreen() const
  203646. {
  203647. return fullScreen;
  203648. }
  203649. bool UIViewComponentPeer::contains (int x, int y, bool trueIfInAChildWindow) const
  203650. {
  203651. if (((unsigned int) x) >= (unsigned int) component->getWidth()
  203652. || ((unsigned int) y) >= (unsigned int) component->getHeight())
  203653. return false;
  203654. CGPoint p;
  203655. p.x = (float) x;
  203656. p.y = (float) y;
  203657. UIView* v = [view hitTest: p withEvent: nil];
  203658. if (trueIfInAChildWindow)
  203659. return v != nil;
  203660. return v == view;
  203661. }
  203662. const BorderSize UIViewComponentPeer::getFrameSize() const
  203663. {
  203664. BorderSize b;
  203665. if (! isSharedWindow)
  203666. {
  203667. CGRect v = [view convertRect: [view frame] toView: nil];
  203668. CGRect w = [window frame];
  203669. b.setTop ((int) (w.size.height - (v.origin.y + v.size.height)));
  203670. b.setBottom ((int) v.origin.y);
  203671. b.setLeft ((int) v.origin.x);
  203672. b.setRight ((int) (w.size.width - (v.origin.x + v.size.width)));
  203673. }
  203674. return b;
  203675. }
  203676. bool UIViewComponentPeer::setAlwaysOnTop (bool alwaysOnTop)
  203677. {
  203678. if (! isSharedWindow)
  203679. window.windowLevel = alwaysOnTop ? UIWindowLevelAlert : UIWindowLevelNormal;
  203680. return true;
  203681. }
  203682. void UIViewComponentPeer::toFront (bool makeActiveWindow)
  203683. {
  203684. if (isSharedWindow)
  203685. [[view superview] bringSubviewToFront: view];
  203686. if (window != 0 && component->isVisible())
  203687. [window makeKeyAndVisible];
  203688. }
  203689. void UIViewComponentPeer::toBehind (ComponentPeer* other)
  203690. {
  203691. UIViewComponentPeer* o = (UIViewComponentPeer*) other;
  203692. if (isSharedWindow)
  203693. {
  203694. [[view superview] insertSubview: view belowSubview: o->view];
  203695. }
  203696. else
  203697. {
  203698. jassertfalse // don't know how to do this
  203699. }
  203700. }
  203701. void UIViewComponentPeer::setIcon (const Image& /*newIcon*/)
  203702. {
  203703. // to do..
  203704. }
  203705. static UIViewComponentPeer* currentlyFocusedPeer = 0;
  203706. void UIViewComponentPeer::viewFocusGain()
  203707. {
  203708. if (currentlyFocusedPeer != this)
  203709. {
  203710. if (ComponentPeer::isValidPeer (currentlyFocusedPeer))
  203711. currentlyFocusedPeer->handleFocusLoss();
  203712. currentlyFocusedPeer = this;
  203713. handleFocusGain();
  203714. }
  203715. }
  203716. void UIViewComponentPeer::viewFocusLoss()
  203717. {
  203718. if (currentlyFocusedPeer == this)
  203719. {
  203720. currentlyFocusedPeer = 0;
  203721. handleFocusLoss();
  203722. }
  203723. }
  203724. void juce_HandleProcessFocusChange()
  203725. {
  203726. if (UIViewComponentPeer::isValidPeer (currentlyFocusedPeer))
  203727. {
  203728. if (Process::isForegroundProcess())
  203729. {
  203730. currentlyFocusedPeer->handleFocusGain();
  203731. ComponentPeer::bringModalComponentToFront();
  203732. }
  203733. else
  203734. {
  203735. currentlyFocusedPeer->handleFocusLoss();
  203736. // turn kiosk mode off if we lose focus..
  203737. Desktop::getInstance().setKioskModeComponent (0);
  203738. }
  203739. }
  203740. }
  203741. bool UIViewComponentPeer::isFocused() const
  203742. {
  203743. return isSharedWindow ? this == currentlyFocusedPeer
  203744. : (window != 0 && [window isKeyWindow]);
  203745. }
  203746. void UIViewComponentPeer::grabFocus()
  203747. {
  203748. if (window != 0)
  203749. {
  203750. [window makeKeyWindow];
  203751. viewFocusGain();
  203752. }
  203753. }
  203754. void UIViewComponentPeer::textInputRequired (int /*x*/, int /*y*/)
  203755. {
  203756. }
  203757. void UIViewComponentPeer::drawRect (CGRect r)
  203758. {
  203759. if (r.size.width < 1.0f || r.size.height < 1.0f)
  203760. return;
  203761. CGContextRef cg = UIGraphicsGetCurrentContext();
  203762. if (! component->isOpaque())
  203763. CGContextClearRect (cg, CGContextGetClipBoundingBox (cg));
  203764. CGContextConcatCTM (cg, CGAffineTransformMake (1, 0, 0, -1, 0, view.bounds.size.height));
  203765. CoreGraphicsContext g (cg, view.bounds.size.height);
  203766. insideDrawRect = true;
  203767. handlePaint (g);
  203768. insideDrawRect = false;
  203769. }
  203770. bool UIViewComponentPeer::canBecomeKeyWindow()
  203771. {
  203772. return (getStyleFlags() & JUCE_NAMESPACE::ComponentPeer::windowIgnoresKeyPresses) == 0;
  203773. }
  203774. bool UIViewComponentPeer::windowShouldClose()
  203775. {
  203776. if (! isValidPeer (this))
  203777. return YES;
  203778. handleUserClosingWindow();
  203779. return NO;
  203780. }
  203781. void UIViewComponentPeer::redirectMovedOrResized()
  203782. {
  203783. handleMovedOrResized();
  203784. }
  203785. void juce_setKioskComponent (Component* kioskModeComponent, bool enableOrDisable, bool allowMenusAndBars)
  203786. {
  203787. }
  203788. class AsyncRepaintMessage : public CallbackMessage
  203789. {
  203790. public:
  203791. UIViewComponentPeer* const peer;
  203792. const Rectangle rect;
  203793. AsyncRepaintMessage (UIViewComponentPeer* const peer_, const Rectangle& rect_)
  203794. : peer (peer_), rect (rect_)
  203795. {
  203796. }
  203797. void messageCallback()
  203798. {
  203799. if (ComponentPeer::isValidPeer (peer))
  203800. peer->repaint (rect.getX(), rect.getY(), rect.getWidth(), rect.getHeight());
  203801. }
  203802. };
  203803. void UIViewComponentPeer::repaint (int x, int y, int w, int h)
  203804. {
  203805. if (insideDrawRect || ! MessageManager::getInstance()->isThisTheMessageThread())
  203806. {
  203807. (new AsyncRepaintMessage (this, Rectangle (x, y, w, h)))->post();
  203808. }
  203809. else
  203810. {
  203811. [view setNeedsDisplayInRect: CGRectMake ((float) x, (float) y, (float) w, (float) h)];
  203812. }
  203813. }
  203814. void UIViewComponentPeer::performAnyPendingRepaintsNow()
  203815. {
  203816. }
  203817. ComponentPeer* Component::createNewPeer (int styleFlags, void* windowToAttachTo)
  203818. {
  203819. return new UIViewComponentPeer (this, styleFlags, (UIView*) windowToAttachTo);
  203820. }
  203821. Image* juce_createIconForFile (const File& file)
  203822. {
  203823. return 0;
  203824. }
  203825. bool Desktop::canUseSemiTransparentWindows() throw()
  203826. {
  203827. return true;
  203828. }
  203829. void Desktop::getMousePosition (int& x, int& y) throw()
  203830. {
  203831. x = juce_lastMouseX;
  203832. y = juce_lastMouseY;
  203833. }
  203834. void Desktop::setMousePosition (int x, int y) throw()
  203835. {
  203836. }
  203837. const int KeyPress::spaceKey = ' ';
  203838. const int KeyPress::returnKey = 0x0d;
  203839. const int KeyPress::escapeKey = 0x1b;
  203840. const int KeyPress::backspaceKey = 0x7f;
  203841. const int KeyPress::leftKey = 0x1000;
  203842. const int KeyPress::rightKey = 0x1001;
  203843. const int KeyPress::upKey = 0x1002;
  203844. const int KeyPress::downKey = 0x1003;
  203845. const int KeyPress::pageUpKey = 0x1004;
  203846. const int KeyPress::pageDownKey = 0x1005;
  203847. const int KeyPress::endKey = 0x1006;
  203848. const int KeyPress::homeKey = 0x1007;
  203849. const int KeyPress::deleteKey = 0x1008;
  203850. const int KeyPress::insertKey = -1;
  203851. const int KeyPress::tabKey = 9;
  203852. const int KeyPress::F1Key = 0x2001;
  203853. const int KeyPress::F2Key = 0x2002;
  203854. const int KeyPress::F3Key = 0x2003;
  203855. const int KeyPress::F4Key = 0x2004;
  203856. const int KeyPress::F5Key = 0x2005;
  203857. const int KeyPress::F6Key = 0x2006;
  203858. const int KeyPress::F7Key = 0x2007;
  203859. const int KeyPress::F8Key = 0x2008;
  203860. const int KeyPress::F9Key = 0x2009;
  203861. const int KeyPress::F10Key = 0x200a;
  203862. const int KeyPress::F11Key = 0x200b;
  203863. const int KeyPress::F12Key = 0x200c;
  203864. const int KeyPress::F13Key = 0x200d;
  203865. const int KeyPress::F14Key = 0x200e;
  203866. const int KeyPress::F15Key = 0x200f;
  203867. const int KeyPress::F16Key = 0x2010;
  203868. const int KeyPress::numberPad0 = 0x30020;
  203869. const int KeyPress::numberPad1 = 0x30021;
  203870. const int KeyPress::numberPad2 = 0x30022;
  203871. const int KeyPress::numberPad3 = 0x30023;
  203872. const int KeyPress::numberPad4 = 0x30024;
  203873. const int KeyPress::numberPad5 = 0x30025;
  203874. const int KeyPress::numberPad6 = 0x30026;
  203875. const int KeyPress::numberPad7 = 0x30027;
  203876. const int KeyPress::numberPad8 = 0x30028;
  203877. const int KeyPress::numberPad9 = 0x30029;
  203878. const int KeyPress::numberPadAdd = 0x3002a;
  203879. const int KeyPress::numberPadSubtract = 0x3002b;
  203880. const int KeyPress::numberPadMultiply = 0x3002c;
  203881. const int KeyPress::numberPadDivide = 0x3002d;
  203882. const int KeyPress::numberPadSeparator = 0x3002e;
  203883. const int KeyPress::numberPadDecimalPoint = 0x3002f;
  203884. const int KeyPress::numberPadEquals = 0x30030;
  203885. const int KeyPress::numberPadDelete = 0x30031;
  203886. const int KeyPress::playKey = 0x30000;
  203887. const int KeyPress::stopKey = 0x30001;
  203888. const int KeyPress::fastForwardKey = 0x30002;
  203889. const int KeyPress::rewindKey = 0x30003;
  203890. #endif
  203891. /********* End of inlined file: juce_iphone_UIViewComponentPeer.mm *********/
  203892. /********* Start of inlined file: juce_iphone_MessageManager.mm *********/
  203893. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  203894. // compiled on its own).
  203895. #if JUCE_INCLUDED_FILE
  203896. struct CallbackMessagePayload
  203897. {
  203898. MessageCallbackFunction* function;
  203899. void* parameter;
  203900. void* volatile result;
  203901. bool volatile hasBeenExecuted;
  203902. };
  203903. END_JUCE_NAMESPACE
  203904. using namespace JUCE_NAMESPACE;
  203905. @interface JuceAppDelegate : NSObject <UIApplicationDelegate>
  203906. {
  203907. }
  203908. - (JuceAppDelegate*) init;
  203909. - (void) dealloc;
  203910. - (BOOL) application: (UIApplication*) application handleOpenURL: (NSURL*) url;
  203911. - (void) applicationDidBecomeActive: (NSNotification*) aNotification;
  203912. - (void) applicationDidResignActive: (NSNotification*) aNotification;
  203913. - (void) applicationWillUnhide: (NSNotification*) aNotification;
  203914. - (void) customEvent: (id) data;
  203915. - (void) performCallback: (id) info;
  203916. @end
  203917. @implementation JuceAppDelegate
  203918. - (JuceAppDelegate*) init
  203919. {
  203920. [super init];
  203921. [[UIApplication sharedApplication] setDelegate: self];
  203922. return self;
  203923. }
  203924. - (void) dealloc
  203925. {
  203926. [[UIApplication sharedApplication] setDelegate: nil];
  203927. [super dealloc];
  203928. }
  203929. - (BOOL) application: (UIApplication*) application handleOpenURL: (NSURL*) url
  203930. {
  203931. if (JUCEApplication::getInstance() != 0)
  203932. {
  203933. JUCEApplication::getInstance()->anotherInstanceStarted (nsStringToJuce ([url absoluteString]));
  203934. return YES;
  203935. }
  203936. return NO;
  203937. }
  203938. - (void) applicationDidBecomeActive: (NSNotification*) aNotification
  203939. {
  203940. juce_HandleProcessFocusChange();
  203941. }
  203942. - (void) applicationDidResignActive: (NSNotification*) aNotification
  203943. {
  203944. juce_HandleProcessFocusChange();
  203945. }
  203946. - (void) applicationWillUnhide: (NSNotification*) aNotification
  203947. {
  203948. juce_HandleProcessFocusChange();
  203949. }
  203950. - (void) customEvent: (id) n
  203951. {
  203952. NSData* data = (NSData*) n;
  203953. void* message = 0;
  203954. [data getBytes: &message length: sizeof (message)];
  203955. [data release];
  203956. if (message != 0)
  203957. MessageManager::getInstance()->deliverMessage (message);
  203958. }
  203959. - (void) performCallback: (id) info
  203960. {
  203961. if ([info isKindOfClass: [NSData class]])
  203962. {
  203963. CallbackMessagePayload* pl = (CallbackMessagePayload*) [((NSData*) info) bytes];
  203964. if (pl != 0)
  203965. {
  203966. pl->result = (*pl->function) (pl->parameter);
  203967. pl->hasBeenExecuted = true;
  203968. }
  203969. }
  203970. else
  203971. {
  203972. jassertfalse // should never get here!
  203973. }
  203974. }
  203975. @end
  203976. BEGIN_JUCE_NAMESPACE
  203977. static JuceAppDelegate* juceAppDelegate = 0;
  203978. void MessageManager::runDispatchLoop()
  203979. {
  203980. jassert (isThisTheMessageThread()); // must only be called by the message thread
  203981. runDispatchLoopUntil (-1);
  203982. }
  203983. void MessageManager::stopDispatchLoop()
  203984. {
  203985. exit (0); // iPhone apps get no mercy..
  203986. }
  203987. bool MessageManager::runDispatchLoopUntil (int millisecondsToRunFor)
  203988. {
  203989. const ScopedAutoReleasePool pool;
  203990. jassert (isThisTheMessageThread()); // must only be called by the message thread
  203991. uint32 endTime = Time::getMillisecondCounter() + millisecondsToRunFor;
  203992. NSDate* endDate = [NSDate dateWithTimeIntervalSinceNow: millisecondsToRunFor * 0.001];
  203993. while (! quitMessagePosted)
  203994. {
  203995. const ScopedAutoReleasePool pool;
  203996. [[NSRunLoop currentRunLoop] runMode: NSDefaultRunLoopMode
  203997. beforeDate: endDate];
  203998. if (millisecondsToRunFor >= 0 && Time::getMillisecondCounter() >= endTime)
  203999. break;
  204000. }
  204001. return ! quitMessagePosted;
  204002. }
  204003. static CFRunLoopRef runLoop = 0;
  204004. static CFRunLoopSourceRef runLoopSource = 0;
  204005. static Array <void*, CriticalSection>* pendingMessages = 0;
  204006. static void runLoopSourceCallback (void*)
  204007. {
  204008. if (pendingMessages != 0)
  204009. {
  204010. int numDispatched = 0;
  204011. do
  204012. {
  204013. void* const nextMessage = pendingMessages->remove (0);
  204014. if (nextMessage == 0)
  204015. return;
  204016. const ScopedAutoReleasePool pool;
  204017. MessageManager::getInstance()->deliverMessage (nextMessage);
  204018. } while (++numDispatched <= 4);
  204019. CFRunLoopSourceSignal (runLoopSource);
  204020. CFRunLoopWakeUp (runLoop);
  204021. }
  204022. }
  204023. void MessageManager::doPlatformSpecificInitialisation()
  204024. {
  204025. pendingMessages = new Array <void*, CriticalSection>();
  204026. runLoop = CFRunLoopGetCurrent();
  204027. CFRunLoopSourceContext sourceContext;
  204028. zerostruct (sourceContext);
  204029. sourceContext.perform = runLoopSourceCallback;
  204030. runLoopSource = CFRunLoopSourceCreate (kCFAllocatorDefault, 1, &sourceContext);
  204031. CFRunLoopAddSource (runLoop, runLoopSource, kCFRunLoopCommonModes);
  204032. if (juceAppDelegate == 0)
  204033. juceAppDelegate = [[JuceAppDelegate alloc] init];
  204034. }
  204035. void MessageManager::doPlatformSpecificShutdown()
  204036. {
  204037. CFRunLoopSourceInvalidate (runLoopSource);
  204038. CFRelease (runLoopSource);
  204039. runLoopSource = 0;
  204040. if (pendingMessages != 0)
  204041. {
  204042. while (pendingMessages->size() > 0)
  204043. delete ((Message*) pendingMessages->remove(0));
  204044. deleteAndZero (pendingMessages);
  204045. }
  204046. if (juceAppDelegate != 0)
  204047. {
  204048. [[NSRunLoop currentRunLoop] cancelPerformSelectorsWithTarget: juceAppDelegate];
  204049. [juceAppDelegate release];
  204050. juceAppDelegate = 0;
  204051. }
  204052. }
  204053. bool juce_postMessageToSystemQueue (void* message)
  204054. {
  204055. if (pendingMessages != 0)
  204056. {
  204057. pendingMessages->add (message);
  204058. CFRunLoopSourceSignal (runLoopSource);
  204059. CFRunLoopWakeUp (runLoop);
  204060. }
  204061. return true;
  204062. }
  204063. void MessageManager::broadcastMessage (const String& value) throw()
  204064. {
  204065. }
  204066. void* MessageManager::callFunctionOnMessageThread (MessageCallbackFunction* callback,
  204067. void* data)
  204068. {
  204069. if (isThisTheMessageThread())
  204070. {
  204071. return (*callback) (data);
  204072. }
  204073. else
  204074. {
  204075. // If a thread has a MessageManagerLock and then tries to call this method, it'll
  204076. // deadlock because the message manager is blocked from running, so can never
  204077. // call your function..
  204078. jassert (! MessageManager::getInstance()->currentThreadHasLockedMessageManager());
  204079. const ScopedAutoReleasePool pool;
  204080. CallbackMessagePayload cmp;
  204081. cmp.function = callback;
  204082. cmp.parameter = data;
  204083. cmp.result = 0;
  204084. cmp.hasBeenExecuted = false;
  204085. [juceAppDelegate performSelectorOnMainThread: @selector (performCallback:)
  204086. withObject: [NSData dataWithBytesNoCopy: &cmp
  204087. length: sizeof (cmp)
  204088. freeWhenDone: NO]
  204089. waitUntilDone: YES];
  204090. return cmp.result;
  204091. }
  204092. }
  204093. #endif
  204094. /********* End of inlined file: juce_iphone_MessageManager.mm *********/
  204095. /********* Start of inlined file: juce_mac_FileChooser.mm *********/
  204096. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  204097. // compiled on its own).
  204098. #if JUCE_INCLUDED_FILE
  204099. #if JUCE_MAC
  204100. END_JUCE_NAMESPACE
  204101. using namespace JUCE_NAMESPACE;
  204102. #define JuceFileChooserDelegate MakeObjCClassName(JuceFileChooserDelegate)
  204103. #if defined (MAC_OS_X_VERSION_10_6) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
  204104. @interface JuceFileChooserDelegate : NSObject <NSOpenSavePanelDelegate>
  204105. #else
  204106. @interface JuceFileChooserDelegate : NSObject
  204107. #endif
  204108. {
  204109. StringArray* filters;
  204110. }
  204111. - (JuceFileChooserDelegate*) initWithFilters: (StringArray*) filters_;
  204112. - (void) dealloc;
  204113. - (BOOL) panel: (id) sender shouldShowFilename: (NSString*) filename;
  204114. @end
  204115. @implementation JuceFileChooserDelegate
  204116. - (JuceFileChooserDelegate*) initWithFilters: (StringArray*) filters_
  204117. {
  204118. [super init];
  204119. filters = filters_;
  204120. return self;
  204121. }
  204122. - (void) dealloc
  204123. {
  204124. delete filters;
  204125. [super dealloc];
  204126. }
  204127. - (BOOL) panel: (id) sender shouldShowFilename: (NSString*) filename
  204128. {
  204129. const String fname (nsStringToJuce (filename));
  204130. for (int i = filters->size(); --i >= 0;)
  204131. if (fname.matchesWildcard ((*filters)[i], true))
  204132. return true;
  204133. return File (fname).isDirectory();
  204134. }
  204135. @end
  204136. BEGIN_JUCE_NAMESPACE
  204137. void FileChooser::showPlatformDialog (Array<File>& results,
  204138. const String& title,
  204139. const File& currentFileOrDirectory,
  204140. const String& filter,
  204141. bool selectsDirectory,
  204142. bool selectsFiles,
  204143. bool isSaveDialogue,
  204144. bool warnAboutOverwritingExistingFiles,
  204145. bool selectMultipleFiles,
  204146. FilePreviewComponent* extraInfoComponent)
  204147. {
  204148. const ScopedAutoReleasePool pool;
  204149. StringArray* filters = new StringArray();
  204150. filters->addTokens (filter.replaceCharacters (T(",:"), T(";;")), T(";"), 0);
  204151. filters->trim();
  204152. filters->removeEmptyStrings();
  204153. JuceFileChooserDelegate* delegate = [[JuceFileChooserDelegate alloc] initWithFilters: filters];
  204154. [delegate autorelease];
  204155. NSSavePanel* panel = isSaveDialogue ? [NSSavePanel savePanel]
  204156. : [NSOpenPanel openPanel];
  204157. [panel setTitle: juceStringToNS (title)];
  204158. if (! isSaveDialogue)
  204159. {
  204160. NSOpenPanel* openPanel = (NSOpenPanel*) panel;
  204161. [openPanel setCanChooseDirectories: selectsDirectory];
  204162. [openPanel setCanChooseFiles: selectsFiles];
  204163. [openPanel setAllowsMultipleSelection: selectMultipleFiles];
  204164. }
  204165. [panel setDelegate: delegate];
  204166. String directory, filename;
  204167. if (currentFileOrDirectory.isDirectory())
  204168. {
  204169. directory = currentFileOrDirectory.getFullPathName();
  204170. }
  204171. else
  204172. {
  204173. directory = currentFileOrDirectory.getParentDirectory().getFullPathName();
  204174. filename = currentFileOrDirectory.getFileName();
  204175. }
  204176. if ([panel runModalForDirectory: juceStringToNS (directory)
  204177. file: juceStringToNS (filename)]
  204178. == NSOKButton)
  204179. {
  204180. if (isSaveDialogue)
  204181. {
  204182. results.add (File (nsStringToJuce ([panel filename])));
  204183. }
  204184. else
  204185. {
  204186. NSOpenPanel* openPanel = (NSOpenPanel*) panel;
  204187. NSArray* urls = [openPanel filenames];
  204188. for (unsigned int i = 0; i < [urls count]; ++i)
  204189. {
  204190. NSString* f = [urls objectAtIndex: i];
  204191. results.add (File (nsStringToJuce (f)));
  204192. }
  204193. }
  204194. }
  204195. [panel setDelegate: nil];
  204196. }
  204197. #else
  204198. void FileChooser::showPlatformDialog (Array<File>& results,
  204199. const String& title,
  204200. const File& currentFileOrDirectory,
  204201. const String& filter,
  204202. bool selectsDirectory,
  204203. bool selectsFiles,
  204204. bool isSaveDialogue,
  204205. bool warnAboutOverwritingExistingFiles,
  204206. bool selectMultipleFiles,
  204207. FilePreviewComponent* extraInfoComponent)
  204208. {
  204209. const ScopedAutoReleasePool pool;
  204210. jassertfalse //xxx to do
  204211. }
  204212. #endif
  204213. #endif
  204214. /********* End of inlined file: juce_mac_FileChooser.mm *********/
  204215. /********* Start of inlined file: juce_mac_OpenGLComponent.mm *********/
  204216. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  204217. // compiled on its own).
  204218. #if JUCE_INCLUDED_FILE && JUCE_OPENGL
  204219. #if JUCE_MAC
  204220. END_JUCE_NAMESPACE
  204221. #define ThreadSafeNSOpenGLView MakeObjCClassName(ThreadSafeNSOpenGLView)
  204222. @interface ThreadSafeNSOpenGLView : NSOpenGLView
  204223. {
  204224. CriticalSection* contextLock;
  204225. bool needsUpdate;
  204226. }
  204227. - (id) initWithFrame: (NSRect) frameRect pixelFormat: (NSOpenGLPixelFormat*) format;
  204228. - (bool) makeActive;
  204229. - (void) makeInactive;
  204230. - (void) reshape;
  204231. @end
  204232. @implementation ThreadSafeNSOpenGLView
  204233. - (id) initWithFrame: (NSRect) frameRect
  204234. pixelFormat: (NSOpenGLPixelFormat*) format
  204235. {
  204236. contextLock = new CriticalSection();
  204237. self = [super initWithFrame: frameRect pixelFormat: format];
  204238. if (self != nil)
  204239. [[NSNotificationCenter defaultCenter] addObserver: self
  204240. selector: @selector (_surfaceNeedsUpdate:)
  204241. name: NSViewGlobalFrameDidChangeNotification
  204242. object: self];
  204243. return self;
  204244. }
  204245. - (void) dealloc
  204246. {
  204247. [[NSNotificationCenter defaultCenter] removeObserver: self];
  204248. delete contextLock;
  204249. [super dealloc];
  204250. }
  204251. - (bool) makeActive
  204252. {
  204253. const ScopedLock sl (*contextLock);
  204254. if ([self openGLContext] == 0)
  204255. return false;
  204256. [[self openGLContext] makeCurrentContext];
  204257. if (needsUpdate)
  204258. {
  204259. [super update];
  204260. needsUpdate = false;
  204261. }
  204262. return true;
  204263. }
  204264. - (void) makeInactive
  204265. {
  204266. const ScopedLock sl (*contextLock);
  204267. [NSOpenGLContext clearCurrentContext];
  204268. }
  204269. - (void) _surfaceNeedsUpdate: (NSNotification*) notification
  204270. {
  204271. const ScopedLock sl (*contextLock);
  204272. needsUpdate = true;
  204273. }
  204274. - (void) update
  204275. {
  204276. const ScopedLock sl (*contextLock);
  204277. needsUpdate = true;
  204278. }
  204279. - (void) reshape
  204280. {
  204281. const ScopedLock sl (*contextLock);
  204282. needsUpdate = true;
  204283. }
  204284. @end
  204285. BEGIN_JUCE_NAMESPACE
  204286. class WindowedGLContext : public OpenGLContext
  204287. {
  204288. public:
  204289. WindowedGLContext (Component* const component,
  204290. const OpenGLPixelFormat& pixelFormat_,
  204291. NSOpenGLContext* sharedContext)
  204292. : renderContext (0),
  204293. pixelFormat (pixelFormat_)
  204294. {
  204295. jassert (component != 0);
  204296. NSOpenGLPixelFormatAttribute attribs [64];
  204297. int n = 0;
  204298. attribs[n++] = NSOpenGLPFADoubleBuffer;
  204299. attribs[n++] = NSOpenGLPFAAccelerated;
  204300. attribs[n++] = NSOpenGLPFAMPSafe; // NSOpenGLPFAAccelerated, NSOpenGLPFAMultiScreen, NSOpenGLPFASingleRenderer
  204301. attribs[n++] = NSOpenGLPFAColorSize;
  204302. attribs[n++] = (NSOpenGLPixelFormatAttribute) jmax (pixelFormat.redBits,
  204303. pixelFormat.greenBits,
  204304. pixelFormat.blueBits);
  204305. attribs[n++] = NSOpenGLPFAAlphaSize;
  204306. attribs[n++] = (NSOpenGLPixelFormatAttribute) pixelFormat.alphaBits;
  204307. attribs[n++] = NSOpenGLPFADepthSize;
  204308. attribs[n++] = (NSOpenGLPixelFormatAttribute) pixelFormat.depthBufferBits;
  204309. attribs[n++] = NSOpenGLPFAStencilSize;
  204310. attribs[n++] = (NSOpenGLPixelFormatAttribute) pixelFormat.stencilBufferBits;
  204311. attribs[n++] = NSOpenGLPFAAccumSize;
  204312. attribs[n++] = (NSOpenGLPixelFormatAttribute) jmax (pixelFormat.accumulationBufferRedBits,
  204313. pixelFormat.accumulationBufferGreenBits,
  204314. pixelFormat.accumulationBufferBlueBits,
  204315. pixelFormat.accumulationBufferAlphaBits);
  204316. // xxx not sure how to do fullSceneAntiAliasingNumSamples..
  204317. attribs[n++] = NSOpenGLPFASampleBuffers;
  204318. attribs[n++] = (NSOpenGLPixelFormatAttribute) 1;
  204319. attribs[n++] = NSOpenGLPFAClosestPolicy;
  204320. attribs[n++] = NSOpenGLPFANoRecovery;
  204321. attribs[n++] = (NSOpenGLPixelFormatAttribute) 0;
  204322. NSOpenGLPixelFormat* format
  204323. = [[NSOpenGLPixelFormat alloc] initWithAttributes: attribs];
  204324. view = [[ThreadSafeNSOpenGLView alloc] initWithFrame: NSMakeRect (0, 0, 100.0f, 100.0f)
  204325. pixelFormat: format];
  204326. renderContext = [[[NSOpenGLContext alloc] initWithFormat: format
  204327. shareContext: sharedContext] autorelease];
  204328. const GLint swapInterval = 1;
  204329. [renderContext setValues: &swapInterval forParameter: NSOpenGLCPSwapInterval];
  204330. [view setOpenGLContext: renderContext];
  204331. [renderContext setView: view];
  204332. [format release];
  204333. viewHolder = new NSViewComponentInternal (view, component);
  204334. }
  204335. ~WindowedGLContext()
  204336. {
  204337. makeInactive();
  204338. [renderContext clearDrawable];
  204339. viewHolder = 0;
  204340. }
  204341. bool makeActive() const throw()
  204342. {
  204343. jassert (renderContext != 0);
  204344. [view makeActive];
  204345. return isActive();
  204346. }
  204347. bool makeInactive() const throw()
  204348. {
  204349. [view makeInactive];
  204350. return true;
  204351. }
  204352. bool isActive() const throw()
  204353. {
  204354. return [NSOpenGLContext currentContext] == renderContext;
  204355. }
  204356. const OpenGLPixelFormat getPixelFormat() const { return pixelFormat; }
  204357. void* getRawContext() const throw() { return renderContext; }
  204358. void updateWindowPosition (int x, int y, int w, int h, int outerWindowHeight)
  204359. {
  204360. }
  204361. void swapBuffers()
  204362. {
  204363. [renderContext flushBuffer];
  204364. }
  204365. bool setSwapInterval (const int numFramesPerSwap)
  204366. {
  204367. [renderContext setValues: (const GLint*) &numFramesPerSwap
  204368. forParameter: NSOpenGLCPSwapInterval];
  204369. return true;
  204370. }
  204371. int getSwapInterval() const
  204372. {
  204373. GLint numFrames = 0;
  204374. [renderContext getValues: &numFrames
  204375. forParameter: NSOpenGLCPSwapInterval];
  204376. return numFrames;
  204377. }
  204378. void repaint()
  204379. {
  204380. // we need to invalidate the juce view that holds this gl view, to make it
  204381. // cause a repaint callback
  204382. NSView* v = (NSView*) viewHolder->view;
  204383. NSRect r = [v frame];
  204384. // bit of a bodge here.. if we only invalidate the area of the gl component,
  204385. // it's completely covered by the NSOpenGLView, so the OS throws away the
  204386. // repaint message, thus never causing our paint() callback, and never repainting
  204387. // the comp. So invalidating just a little bit around the edge helps..
  204388. [[v superview] setNeedsDisplayInRect: NSInsetRect (r, -2.0f, -2.0f)];
  204389. }
  204390. void* getNativeWindowHandle() const { return viewHolder->view; }
  204391. juce_UseDebuggingNewOperator
  204392. NSOpenGLContext* renderContext;
  204393. ThreadSafeNSOpenGLView* view;
  204394. private:
  204395. OpenGLPixelFormat pixelFormat;
  204396. ScopedPointer <NSViewComponentInternal> viewHolder;
  204397. WindowedGLContext (const WindowedGLContext&);
  204398. const WindowedGLContext& operator= (const WindowedGLContext&);
  204399. };
  204400. OpenGLContext* OpenGLContext::createContextForWindow (Component* const component,
  204401. const OpenGLPixelFormat& pixelFormat,
  204402. const OpenGLContext* const contextToShareWith)
  204403. {
  204404. ScopedPointer <WindowedGLContext> c (new WindowedGLContext (component, pixelFormat,
  204405. contextToShareWith != 0 ? (NSOpenGLContext*) contextToShareWith->getRawContext() : 0));
  204406. return (c->renderContext != 0) ? c.release() : 0;
  204407. }
  204408. void* OpenGLComponent::getNativeWindowHandle() const
  204409. {
  204410. return context != 0 ? ((WindowedGLContext*) context)->getNativeWindowHandle()
  204411. : 0;
  204412. }
  204413. void juce_glViewport (const int w, const int h)
  204414. {
  204415. glViewport (0, 0, w, h);
  204416. }
  204417. void OpenGLPixelFormat::getAvailablePixelFormats (Component* /*component*/,
  204418. OwnedArray <OpenGLPixelFormat>& results)
  204419. {
  204420. /* GLint attribs [64];
  204421. int n = 0;
  204422. attribs[n++] = AGL_RGBA;
  204423. attribs[n++] = AGL_DOUBLEBUFFER;
  204424. attribs[n++] = AGL_ACCELERATED;
  204425. attribs[n++] = AGL_NO_RECOVERY;
  204426. attribs[n++] = AGL_NONE;
  204427. AGLPixelFormat p = aglChoosePixelFormat (0, 0, attribs);
  204428. while (p != 0)
  204429. {
  204430. OpenGLPixelFormat* const pf = new OpenGLPixelFormat();
  204431. pf->redBits = getAGLAttribute (p, AGL_RED_SIZE);
  204432. pf->greenBits = getAGLAttribute (p, AGL_GREEN_SIZE);
  204433. pf->blueBits = getAGLAttribute (p, AGL_BLUE_SIZE);
  204434. pf->alphaBits = getAGLAttribute (p, AGL_ALPHA_SIZE);
  204435. pf->depthBufferBits = getAGLAttribute (p, AGL_DEPTH_SIZE);
  204436. pf->stencilBufferBits = getAGLAttribute (p, AGL_STENCIL_SIZE);
  204437. pf->accumulationBufferRedBits = getAGLAttribute (p, AGL_ACCUM_RED_SIZE);
  204438. pf->accumulationBufferGreenBits = getAGLAttribute (p, AGL_ACCUM_GREEN_SIZE);
  204439. pf->accumulationBufferBlueBits = getAGLAttribute (p, AGL_ACCUM_BLUE_SIZE);
  204440. pf->accumulationBufferAlphaBits = getAGLAttribute (p, AGL_ACCUM_ALPHA_SIZE);
  204441. results.add (pf);
  204442. p = aglNextPixelFormat (p);
  204443. }*/
  204444. //jassertfalse //xxx can't see how you do this in cocoa!
  204445. }
  204446. #else
  204447. OpenGLContext* OpenGLContext::createContextForWindow (Component* const component,
  204448. const OpenGLPixelFormat& pixelFormat,
  204449. const OpenGLContext* const contextToShareWith)
  204450. {
  204451. return 0;
  204452. }
  204453. void juce_glViewport (const int w, const int h)
  204454. {
  204455. //glViewport (0, 0, w, h);
  204456. }
  204457. #endif
  204458. #endif
  204459. /********* End of inlined file: juce_mac_OpenGLComponent.mm *********/
  204460. /********* Start of inlined file: juce_mac_MouseCursor.mm *********/
  204461. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  204462. // compiled on its own).
  204463. #if JUCE_INCLUDED_FILE
  204464. #if JUCE_MAC
  204465. void* juce_createMouseCursorFromImage (const Image& image, int hotspotX, int hotspotY) throw()
  204466. {
  204467. NSImage* im = CoreGraphicsImage::createNSImage (image);
  204468. NSCursor* c = [[NSCursor alloc] initWithImage: im
  204469. hotSpot: NSMakePoint (hotspotX, hotspotY)];
  204470. [im release];
  204471. return (void*) c;
  204472. }
  204473. static void* juce_cursorFromData (const unsigned char* data, const size_t size, float hx, float hy) throw()
  204474. {
  204475. ScopedPointer <Image> im (ImageFileFormat::loadFrom ((const char*) data, (int) size));
  204476. jassert (im != 0);
  204477. if (im == 0)
  204478. return 0;
  204479. return juce_createMouseCursorFromImage (*im,
  204480. (int) (hx * im->getWidth()),
  204481. (int) (hy * im->getHeight()));
  204482. }
  204483. static void* juce_cursorFromWebKitFile (const char* filename, float hx, float hy)
  204484. {
  204485. File f ("/System/Library/Frameworks/WebKit.framework/Frameworks/WebCore.framework/Resources");
  204486. MemoryBlock mb;
  204487. if (f.getChildFile (filename).loadFileAsData (mb))
  204488. return juce_cursorFromData ((const unsigned char*) mb.getData(), mb.getSize(), hx, hy);
  204489. return 0;
  204490. }
  204491. void* juce_createStandardMouseCursor (MouseCursor::StandardCursorType type) throw()
  204492. {
  204493. const ScopedAutoReleasePool pool;
  204494. NSCursor* c = 0;
  204495. switch (type)
  204496. {
  204497. case MouseCursor::NormalCursor:
  204498. c = [NSCursor arrowCursor];
  204499. break;
  204500. case MouseCursor::NoCursor:
  204501. {
  204502. Image blank (Image::ARGB, 8, 8, true);
  204503. return juce_createMouseCursorFromImage (blank, 0, 0);
  204504. }
  204505. case MouseCursor::DraggingHandCursor:
  204506. c = [NSCursor openHandCursor];
  204507. break;
  204508. case MouseCursor::CopyingCursor:
  204509. return juce_cursorFromWebKitFile ("copyCursor.png", 0, 0);
  204510. case MouseCursor::WaitCursor:
  204511. c = [NSCursor arrowCursor]; // avoid this on the mac, let the OS provide the beachball
  204512. break;
  204513. //return juce_cursorFromWebKitFile ("waitCursor.png", 0.5f, 0.5f);
  204514. case MouseCursor::IBeamCursor:
  204515. c = [NSCursor IBeamCursor];
  204516. break;
  204517. case MouseCursor::PointingHandCursor:
  204518. c = [NSCursor pointingHandCursor];
  204519. break;
  204520. case MouseCursor::LeftRightResizeCursor:
  204521. c = [NSCursor resizeLeftRightCursor];
  204522. break;
  204523. case MouseCursor::LeftEdgeResizeCursor:
  204524. c = [NSCursor resizeLeftCursor];
  204525. break;
  204526. case MouseCursor::RightEdgeResizeCursor:
  204527. c = [NSCursor resizeRightCursor];
  204528. break;
  204529. case MouseCursor::UpDownResizeCursor:
  204530. case MouseCursor::TopEdgeResizeCursor:
  204531. case MouseCursor::BottomEdgeResizeCursor:
  204532. return juce_cursorFromWebKitFile ("northSouthResizeCursor.png", 0.5f, 0.5f);
  204533. case MouseCursor::TopLeftCornerResizeCursor:
  204534. case MouseCursor::BottomRightCornerResizeCursor:
  204535. return juce_cursorFromWebKitFile ("northWestSouthEastResizeCursor.png", 0.5f, 0.5f);
  204536. case MouseCursor::TopRightCornerResizeCursor:
  204537. case MouseCursor::BottomLeftCornerResizeCursor:
  204538. return juce_cursorFromWebKitFile ("northEastSouthWestResizeCursor.png", 0.5f, 0.5f);
  204539. case MouseCursor::UpDownLeftRightResizeCursor:
  204540. return juce_cursorFromWebKitFile ("moveCursor.png", 0.5f, 0.5f);
  204541. case MouseCursor::CrosshairCursor:
  204542. c = [NSCursor crosshairCursor];
  204543. break;
  204544. }
  204545. [c retain];
  204546. return (void*) c;
  204547. }
  204548. void juce_deleteMouseCursor (void* const cursorHandle, const bool isStandard) throw()
  204549. {
  204550. NSCursor* c = (NSCursor*) cursorHandle;
  204551. [c release];
  204552. }
  204553. void MouseCursor::showInAllWindows() const throw()
  204554. {
  204555. showInWindow (0);
  204556. }
  204557. void MouseCursor::showInWindow (ComponentPeer*) const throw()
  204558. {
  204559. NSCursor* const c = (NSCursor*) getHandle();
  204560. [c set];
  204561. }
  204562. #else
  204563. void* juce_createMouseCursorFromImage (const Image& image, int hotspotX, int hotspotY) throw() { return 0; }
  204564. void* juce_createStandardMouseCursor (MouseCursor::StandardCursorType type) throw() { return 0; }
  204565. void juce_deleteMouseCursor (void* const cursorHandle, const bool isStandard) throw() {}
  204566. void MouseCursor::showInAllWindows() const throw() {}
  204567. void MouseCursor::showInWindow (ComponentPeer*) const throw() {}
  204568. #endif
  204569. #endif
  204570. /********* End of inlined file: juce_mac_MouseCursor.mm *********/
  204571. /********* Start of inlined file: juce_mac_WebBrowserComponent.mm *********/
  204572. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  204573. // compiled on its own).
  204574. #if JUCE_INCLUDED_FILE && JUCE_WEB_BROWSER
  204575. #if JUCE_MAC
  204576. END_JUCE_NAMESPACE
  204577. #define DownloadClickDetector MakeObjCClassName(DownloadClickDetector)
  204578. @interface DownloadClickDetector : NSObject
  204579. {
  204580. JUCE_NAMESPACE::WebBrowserComponent* ownerComponent;
  204581. }
  204582. - (DownloadClickDetector*) initWithWebBrowserOwner: (JUCE_NAMESPACE::WebBrowserComponent*) ownerComponent;
  204583. - (void) webView: (WebView*) webView decidePolicyForNavigationAction: (NSDictionary*) actionInformation
  204584. request: (NSURLRequest*) request
  204585. frame: (WebFrame*) frame
  204586. decisionListener: (id<WebPolicyDecisionListener>) listener;
  204587. @end
  204588. @implementation DownloadClickDetector
  204589. - (DownloadClickDetector*) initWithWebBrowserOwner: (JUCE_NAMESPACE::WebBrowserComponent*) ownerComponent_
  204590. {
  204591. [super init];
  204592. ownerComponent = ownerComponent_;
  204593. return self;
  204594. }
  204595. - (void) webView: (WebView*) sender decidePolicyForNavigationAction: (NSDictionary*) actionInformation
  204596. request: (NSURLRequest*) request
  204597. frame: (WebFrame*) frame
  204598. decisionListener: (id <WebPolicyDecisionListener>) listener
  204599. {
  204600. NSURL* url = [actionInformation valueForKey: @"WebActionOriginalURLKey"];
  204601. if (ownerComponent->pageAboutToLoad (nsStringToJuce ([url absoluteString])))
  204602. [listener use];
  204603. else
  204604. [listener ignore];
  204605. }
  204606. @end
  204607. BEGIN_JUCE_NAMESPACE
  204608. class WebBrowserComponentInternal : public NSViewComponent
  204609. {
  204610. public:
  204611. WebBrowserComponentInternal (WebBrowserComponent* owner)
  204612. {
  204613. webView = [[WebView alloc] initWithFrame: NSMakeRect (0, 0, 100.0f, 100.0f)
  204614. frameName: @""
  204615. groupName: @""];
  204616. setView (webView);
  204617. clickListener = [[DownloadClickDetector alloc] initWithWebBrowserOwner: owner];
  204618. [webView setPolicyDelegate: clickListener];
  204619. }
  204620. ~WebBrowserComponentInternal()
  204621. {
  204622. [webView setPolicyDelegate: nil];
  204623. [clickListener release];
  204624. setView (0);
  204625. }
  204626. void goToURL (const String& url,
  204627. const StringArray* headers,
  204628. const MemoryBlock* postData)
  204629. {
  204630. NSMutableURLRequest* r
  204631. = [NSMutableURLRequest requestWithURL: [NSURL URLWithString: juceStringToNS (url)]
  204632. cachePolicy: NSURLRequestUseProtocolCachePolicy
  204633. timeoutInterval: 30.0];
  204634. if (postData != 0 && postData->getSize() > 0)
  204635. {
  204636. [r setHTTPMethod: @"POST"];
  204637. [r setHTTPBody: [NSData dataWithBytes: postData->getData()
  204638. length: postData->getSize()]];
  204639. }
  204640. if (headers != 0)
  204641. {
  204642. for (int i = 0; i < headers->size(); ++i)
  204643. {
  204644. const String headerName ((*headers)[i].upToFirstOccurrenceOf (T(":"), false, false).trim());
  204645. const String headerValue ((*headers)[i].fromFirstOccurrenceOf (T(":"), false, false).trim());
  204646. [r setValue: juceStringToNS (headerValue)
  204647. forHTTPHeaderField: juceStringToNS (headerName)];
  204648. }
  204649. }
  204650. stop();
  204651. [[webView mainFrame] loadRequest: r];
  204652. }
  204653. void goBack()
  204654. {
  204655. [webView goBack];
  204656. }
  204657. void goForward()
  204658. {
  204659. [webView goForward];
  204660. }
  204661. void stop()
  204662. {
  204663. [webView stopLoading: nil];
  204664. }
  204665. void refresh()
  204666. {
  204667. [webView reload: nil];
  204668. }
  204669. private:
  204670. WebView* webView;
  204671. DownloadClickDetector* clickListener;
  204672. };
  204673. WebBrowserComponent::WebBrowserComponent (const bool unloadPageWhenBrowserIsHidden_)
  204674. : browser (0),
  204675. blankPageShown (false),
  204676. unloadPageWhenBrowserIsHidden (unloadPageWhenBrowserIsHidden_)
  204677. {
  204678. setOpaque (true);
  204679. addAndMakeVisible (browser = new WebBrowserComponentInternal (this));
  204680. }
  204681. WebBrowserComponent::~WebBrowserComponent()
  204682. {
  204683. deleteAndZero (browser);
  204684. }
  204685. void WebBrowserComponent::goToURL (const String& url,
  204686. const StringArray* headers,
  204687. const MemoryBlock* postData)
  204688. {
  204689. lastURL = url;
  204690. lastHeaders.clear();
  204691. if (headers != 0)
  204692. lastHeaders = *headers;
  204693. lastPostData.setSize (0);
  204694. if (postData != 0)
  204695. lastPostData = *postData;
  204696. blankPageShown = false;
  204697. browser->goToURL (url, headers, postData);
  204698. }
  204699. void WebBrowserComponent::stop()
  204700. {
  204701. browser->stop();
  204702. }
  204703. void WebBrowserComponent::goBack()
  204704. {
  204705. lastURL = String::empty;
  204706. blankPageShown = false;
  204707. browser->goBack();
  204708. }
  204709. void WebBrowserComponent::goForward()
  204710. {
  204711. lastURL = String::empty;
  204712. browser->goForward();
  204713. }
  204714. void WebBrowserComponent::refresh()
  204715. {
  204716. browser->refresh();
  204717. }
  204718. void WebBrowserComponent::paint (Graphics& g)
  204719. {
  204720. }
  204721. void WebBrowserComponent::checkWindowAssociation()
  204722. {
  204723. if (isShowing())
  204724. {
  204725. if (blankPageShown)
  204726. goBack();
  204727. }
  204728. else
  204729. {
  204730. if (unloadPageWhenBrowserIsHidden && ! blankPageShown)
  204731. {
  204732. // when the component becomes invisible, some stuff like flash
  204733. // carries on playing audio, so we need to force it onto a blank
  204734. // page to avoid this, (and send it back when it's made visible again).
  204735. blankPageShown = true;
  204736. browser->goToURL ("about:blank", 0, 0);
  204737. }
  204738. }
  204739. }
  204740. void WebBrowserComponent::reloadLastURL()
  204741. {
  204742. if (lastURL.isNotEmpty())
  204743. {
  204744. goToURL (lastURL, &lastHeaders, &lastPostData);
  204745. lastURL = String::empty;
  204746. }
  204747. }
  204748. void WebBrowserComponent::parentHierarchyChanged()
  204749. {
  204750. checkWindowAssociation();
  204751. }
  204752. void WebBrowserComponent::resized()
  204753. {
  204754. browser->setSize (getWidth(), getHeight());
  204755. }
  204756. void WebBrowserComponent::visibilityChanged()
  204757. {
  204758. checkWindowAssociation();
  204759. }
  204760. bool WebBrowserComponent::pageAboutToLoad (const String& url)
  204761. {
  204762. return true;
  204763. }
  204764. #else
  204765. WebBrowserComponent::WebBrowserComponent (const bool unloadPageWhenBrowserIsHidden_)
  204766. {
  204767. }
  204768. WebBrowserComponent::~WebBrowserComponent()
  204769. {
  204770. }
  204771. void WebBrowserComponent::goToURL (const String& url,
  204772. const StringArray* headers,
  204773. const MemoryBlock* postData)
  204774. {
  204775. }
  204776. void WebBrowserComponent::stop()
  204777. {
  204778. }
  204779. void WebBrowserComponent::goBack()
  204780. {
  204781. }
  204782. void WebBrowserComponent::goForward()
  204783. {
  204784. }
  204785. void WebBrowserComponent::refresh()
  204786. {
  204787. }
  204788. void WebBrowserComponent::paint (Graphics& g)
  204789. {
  204790. }
  204791. void WebBrowserComponent::checkWindowAssociation()
  204792. {
  204793. }
  204794. void WebBrowserComponent::reloadLastURL()
  204795. {
  204796. }
  204797. void WebBrowserComponent::parentHierarchyChanged()
  204798. {
  204799. }
  204800. void WebBrowserComponent::resized()
  204801. {
  204802. }
  204803. void WebBrowserComponent::visibilityChanged()
  204804. {
  204805. }
  204806. bool WebBrowserComponent::pageAboutToLoad (const String& url)
  204807. {
  204808. return true;
  204809. }
  204810. #endif
  204811. #endif
  204812. /********* End of inlined file: juce_mac_WebBrowserComponent.mm *********/
  204813. /********* Start of inlined file: juce_iphone_Audio.cpp *********/
  204814. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  204815. // compiled on its own).
  204816. #if JUCE_INCLUDED_FILE
  204817. class IPhoneAudioIODevice : public AudioIODevice
  204818. {
  204819. public:
  204820. IPhoneAudioIODevice (const String& deviceName)
  204821. : AudioIODevice (deviceName, T("Audio")),
  204822. audioUnit (0),
  204823. isRunning (false),
  204824. callback (0),
  204825. actualBufferSize (0),
  204826. floatData (1, 2)
  204827. {
  204828. numInputChannels = 2;
  204829. numOutputChannels = 2;
  204830. preferredBufferSize = 0;
  204831. AudioSessionInitialize (0, 0, interruptionListenerStatic, this);
  204832. updateDeviceInfo();
  204833. }
  204834. ~IPhoneAudioIODevice()
  204835. {
  204836. close();
  204837. }
  204838. const StringArray getOutputChannelNames()
  204839. {
  204840. StringArray s;
  204841. s.add ("Left");
  204842. s.add ("Right");
  204843. return s;
  204844. }
  204845. const StringArray getInputChannelNames()
  204846. {
  204847. StringArray s;
  204848. if (audioInputIsAvailable)
  204849. {
  204850. s.add ("Left");
  204851. s.add ("Right");
  204852. }
  204853. return s;
  204854. }
  204855. int getNumSampleRates()
  204856. {
  204857. return 1;
  204858. }
  204859. double getSampleRate (int index)
  204860. {
  204861. return sampleRate;
  204862. }
  204863. int getNumBufferSizesAvailable()
  204864. {
  204865. return 1;
  204866. }
  204867. int getBufferSizeSamples (int index)
  204868. {
  204869. return getDefaultBufferSize();
  204870. }
  204871. int getDefaultBufferSize()
  204872. {
  204873. return 1024;
  204874. }
  204875. const String open (const BitArray& inputChannels,
  204876. const BitArray& outputChannels,
  204877. double sampleRate,
  204878. int bufferSize)
  204879. {
  204880. close();
  204881. lastError = String::empty;
  204882. preferredBufferSize = (bufferSize <= 0) ? getDefaultBufferSize() : bufferSize;
  204883. // xxx set up channel mapping
  204884. activeOutputChans = outputChannels;
  204885. activeOutputChans.setRange (2, activeOutputChans.getHighestBit(), false);
  204886. numOutputChannels = activeOutputChans.countNumberOfSetBits();
  204887. monoOutputChannelNumber = activeOutputChans.findNextSetBit (0);
  204888. activeInputChans = inputChannels;
  204889. activeInputChans.setRange (2, activeInputChans.getHighestBit(), false);
  204890. numInputChannels = activeInputChans.countNumberOfSetBits();
  204891. monoInputChannelNumber = activeInputChans.findNextSetBit (0);
  204892. AudioSessionSetActive (true);
  204893. UInt32 audioCategory = kAudioSessionCategory_PlayAndRecord;
  204894. AudioSessionSetProperty (kAudioSessionProperty_AudioCategory, sizeof (audioCategory), &audioCategory);
  204895. AudioSessionAddPropertyListener (kAudioSessionProperty_AudioRouteChange, propertyChangedStatic, this);
  204896. fixAudioRouteIfSetToReceiver();
  204897. updateDeviceInfo();
  204898. Float32 bufferDuration = preferredBufferSize / sampleRate;
  204899. AudioSessionSetProperty (kAudioSessionProperty_PreferredHardwareIOBufferDuration, sizeof (bufferDuration), &bufferDuration);
  204900. actualBufferSize = preferredBufferSize;
  204901. prepareFloatBuffers();
  204902. isRunning = true;
  204903. propertyChanged (0, 0, 0); // creates and starts the AU
  204904. lastError = audioUnit != 0 ? String::empty
  204905. : T("Couldn't open the device");
  204906. return lastError;
  204907. }
  204908. void close()
  204909. {
  204910. if (isRunning)
  204911. {
  204912. isRunning = false;
  204913. AudioSessionSetActive (false);
  204914. if (audioUnit != 0)
  204915. {
  204916. AudioComponentInstanceDispose (audioUnit);
  204917. audioUnit = 0;
  204918. }
  204919. }
  204920. }
  204921. bool isOpen()
  204922. {
  204923. return isRunning;
  204924. }
  204925. int getCurrentBufferSizeSamples()
  204926. {
  204927. return actualBufferSize;
  204928. }
  204929. double getCurrentSampleRate()
  204930. {
  204931. return sampleRate;
  204932. }
  204933. int getCurrentBitDepth()
  204934. {
  204935. return 16;
  204936. }
  204937. const BitArray getActiveOutputChannels() const
  204938. {
  204939. return activeOutputChans;
  204940. }
  204941. const BitArray getActiveInputChannels() const
  204942. {
  204943. return activeInputChans;
  204944. }
  204945. int getOutputLatencyInSamples()
  204946. {
  204947. return 0; //xxx
  204948. }
  204949. int getInputLatencyInSamples()
  204950. {
  204951. return 0; //xxx
  204952. }
  204953. void start (AudioIODeviceCallback* callback_)
  204954. {
  204955. if (isRunning && callback != callback_)
  204956. {
  204957. if (callback_ != 0)
  204958. callback_->audioDeviceAboutToStart (this);
  204959. callbackLock.enter();
  204960. callback = callback_;
  204961. callbackLock.exit();
  204962. }
  204963. }
  204964. void stop()
  204965. {
  204966. if (isRunning)
  204967. {
  204968. callbackLock.enter();
  204969. AudioIODeviceCallback* const lastCallback = callback;
  204970. callback = 0;
  204971. callbackLock.exit();
  204972. if (lastCallback != 0)
  204973. lastCallback->audioDeviceStopped();
  204974. }
  204975. }
  204976. bool isPlaying()
  204977. {
  204978. return isRunning && callback != 0;
  204979. }
  204980. const String getLastError()
  204981. {
  204982. return lastError;
  204983. }
  204984. private:
  204985. CriticalSection callbackLock;
  204986. Float64 sampleRate;
  204987. int numInputChannels, numOutputChannels;
  204988. int preferredBufferSize;
  204989. int actualBufferSize;
  204990. bool isRunning;
  204991. String lastError;
  204992. AudioStreamBasicDescription format;
  204993. AudioUnit audioUnit;
  204994. UInt32 audioInputIsAvailable;
  204995. AudioIODeviceCallback* callback;
  204996. BitArray activeOutputChans, activeInputChans;
  204997. AudioSampleBuffer floatData;
  204998. float* inputChannels[3];
  204999. float* outputChannels[3];
  205000. bool monoInputChannelNumber, monoOutputChannelNumber;
  205001. void prepareFloatBuffers()
  205002. {
  205003. floatData.setSize (numInputChannels + numOutputChannels, actualBufferSize);
  205004. zerostruct (inputChannels);
  205005. zerostruct (outputChannels);
  205006. for (int i = 0; i < numInputChannels; ++i)
  205007. inputChannels[i] = floatData.getSampleData (i);
  205008. for (int i = 0; i < numOutputChannels; ++i)
  205009. outputChannels[i] = floatData.getSampleData (i + numInputChannels);
  205010. }
  205011. OSStatus process (AudioUnitRenderActionFlags* ioActionFlags, const AudioTimeStamp* inTimeStamp,
  205012. UInt32 inBusNumber, UInt32 inNumberFrames, AudioBufferList* ioData)
  205013. {
  205014. OSStatus err = noErr;
  205015. if (audioInputIsAvailable)
  205016. err = AudioUnitRender (audioUnit, ioActionFlags, inTimeStamp, 1, inNumberFrames, ioData);
  205017. const ScopedLock sl (callbackLock);
  205018. if (callback != 0)
  205019. {
  205020. if (audioInputIsAvailable && numInputChannels > 0)
  205021. {
  205022. short* shortData = (short*) ioData->mBuffers[0].mData;
  205023. if (numInputChannels >= 2)
  205024. {
  205025. for (UInt32 i = 0; i < inNumberFrames; ++i)
  205026. {
  205027. inputChannels[0][i] = *shortData++ * (1.0f / 32768.0f);
  205028. inputChannels[1][i] = *shortData++ * (1.0f / 32768.0f);
  205029. }
  205030. }
  205031. else
  205032. {
  205033. if (monoInputChannelNumber > 0)
  205034. ++shortData;
  205035. for (UInt32 i = 0; i < inNumberFrames; ++i)
  205036. {
  205037. inputChannels[0][i] = *shortData++ * (1.0f / 32768.0f);
  205038. ++shortData;
  205039. }
  205040. }
  205041. }
  205042. else
  205043. {
  205044. for (int i = numInputChannels; --i >= 0;)
  205045. zeromem (inputChannels[i], sizeof (float) * inNumberFrames);
  205046. }
  205047. callback->audioDeviceIOCallback ((const float**) inputChannels, numInputChannels,
  205048. outputChannels, numOutputChannels,
  205049. (int) inNumberFrames);
  205050. short* shortData = (short*) ioData->mBuffers[0].mData;
  205051. int n = 0;
  205052. if (numOutputChannels >= 2)
  205053. {
  205054. for (UInt32 i = 0; i < inNumberFrames; ++i)
  205055. {
  205056. shortData [n++] = (short) (outputChannels[0][i] * 32767.0f);
  205057. shortData [n++] = (short) (outputChannels[1][i] * 32767.0f);
  205058. }
  205059. }
  205060. else if (numOutputChannels == 1)
  205061. {
  205062. for (UInt32 i = 0; i < inNumberFrames; ++i)
  205063. {
  205064. const short s = (short) (outputChannels[monoOutputChannelNumber][i] * 32767.0f);
  205065. shortData [n++] = s;
  205066. shortData [n++] = s;
  205067. }
  205068. }
  205069. else
  205070. {
  205071. zeromem (ioData->mBuffers[0].mData, 2 * sizeof (short) * inNumberFrames);
  205072. }
  205073. }
  205074. else
  205075. {
  205076. zeromem (ioData->mBuffers[0].mData, 2 * sizeof (short) * inNumberFrames);
  205077. }
  205078. return err;
  205079. }
  205080. void updateDeviceInfo()
  205081. {
  205082. UInt32 size = sizeof (sampleRate);
  205083. AudioSessionGetProperty (kAudioSessionProperty_CurrentHardwareSampleRate, &size, &sampleRate);
  205084. size = sizeof (audioInputIsAvailable);
  205085. AudioSessionGetProperty (kAudioSessionProperty_AudioInputAvailable, &size, &audioInputIsAvailable);
  205086. }
  205087. void propertyChanged (AudioSessionPropertyID inID, UInt32 inDataSize, const void* inPropertyValue)
  205088. {
  205089. if (! isRunning)
  205090. return;
  205091. if (inPropertyValue != 0)
  205092. {
  205093. CFDictionaryRef routeChangeDictionary = (CFDictionaryRef) inPropertyValue;
  205094. CFNumberRef routeChangeReasonRef = (CFNumberRef) CFDictionaryGetValue (routeChangeDictionary,
  205095. CFSTR (kAudioSession_AudioRouteChangeKey_Reason));
  205096. SInt32 routeChangeReason;
  205097. CFNumberGetValue (routeChangeReasonRef, kCFNumberSInt32Type, &routeChangeReason);
  205098. if (routeChangeReason == kAudioSessionRouteChangeReason_OldDeviceUnavailable)
  205099. fixAudioRouteIfSetToReceiver();
  205100. }
  205101. updateDeviceInfo();
  205102. createAudioUnit();
  205103. AudioSessionSetActive (true);
  205104. if (audioUnit != 0)
  205105. {
  205106. UInt32 formatSize = sizeof (format);
  205107. AudioUnitGetProperty (audioUnit, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Output, 1, &format, &formatSize);
  205108. Float32 bufferDuration = preferredBufferSize / sampleRate;
  205109. UInt32 bufferDurationSize = sizeof (bufferDuration);
  205110. AudioSessionGetProperty (kAudioSessionProperty_CurrentHardwareIOBufferDuration, &bufferDurationSize, &bufferDurationSize);
  205111. actualBufferSize = (int) (sampleRate * bufferDuration + 0.5);
  205112. AudioOutputUnitStart (audioUnit);
  205113. }
  205114. }
  205115. void interruptionListener (UInt32 inInterruption)
  205116. {
  205117. if (inInterruption == kAudioSessionEndInterruption)
  205118. {
  205119. isRunning = true;
  205120. AudioSessionSetActive (true);
  205121. AudioOutputUnitStart (audioUnit);
  205122. }
  205123. }
  205124. static OSStatus processStatic (void* inRefCon, AudioUnitRenderActionFlags* ioActionFlags, const AudioTimeStamp* inTimeStamp,
  205125. UInt32 inBusNumber, UInt32 inNumberFrames, AudioBufferList* ioData)
  205126. {
  205127. return ((IPhoneAudioIODevice*) inRefCon)->process (ioActionFlags, inTimeStamp, inBusNumber, inNumberFrames, ioData);
  205128. }
  205129. static void propertyChangedStatic (void* inClientData, AudioSessionPropertyID inID, UInt32 inDataSize, const void* inPropertyValue)
  205130. {
  205131. ((IPhoneAudioIODevice*) inClientData)->propertyChanged (inID, inDataSize, inPropertyValue);
  205132. }
  205133. static void interruptionListenerStatic (void* inClientData, UInt32 inInterruption)
  205134. {
  205135. ((IPhoneAudioIODevice*) inClientData)->interruptionListener (inInterruption);
  205136. }
  205137. void resetFormat (const int numChannels)
  205138. {
  205139. memset (&format, 0, sizeof (format));
  205140. format.mFormatID = kAudioFormatLinearPCM;
  205141. format.mFormatFlags = kLinearPCMFormatFlagIsSignedInteger | kLinearPCMFormatFlagIsPacked;
  205142. format.mBitsPerChannel = 8 * sizeof (short);
  205143. format.mChannelsPerFrame = 2;
  205144. format.mFramesPerPacket = 1;
  205145. format.mBytesPerFrame = format.mBytesPerPacket = 2 * sizeof (short);
  205146. }
  205147. bool createAudioUnit()
  205148. {
  205149. if (audioUnit != 0)
  205150. {
  205151. AudioComponentInstanceDispose (audioUnit);
  205152. audioUnit = 0;
  205153. }
  205154. resetFormat (2);
  205155. AudioComponentDescription desc;
  205156. desc.componentType = kAudioUnitType_Output;
  205157. desc.componentSubType = kAudioUnitSubType_RemoteIO;
  205158. desc.componentManufacturer = kAudioUnitManufacturer_Apple;
  205159. desc.componentFlags = 0;
  205160. desc.componentFlagsMask = 0;
  205161. AudioComponent comp = AudioComponentFindNext (0, &desc);
  205162. AudioComponentInstanceNew (comp, &audioUnit);
  205163. if (audioUnit == 0)
  205164. return false;
  205165. const UInt32 one = 1;
  205166. AudioUnitSetProperty (audioUnit, kAudioOutputUnitProperty_EnableIO, kAudioUnitScope_Input, 1, &one, sizeof (one));
  205167. AudioChannelLayout layout;
  205168. layout.mChannelBitmap = 0;
  205169. layout.mNumberChannelDescriptions = 0;
  205170. layout.mChannelLayoutTag = kAudioChannelLayoutTag_Stereo;
  205171. AudioUnitSetProperty (audioUnit, kAudioUnitProperty_AudioChannelLayout, kAudioUnitScope_Input, 0, &layout, sizeof (layout));
  205172. AudioUnitSetProperty (audioUnit, kAudioUnitProperty_AudioChannelLayout, kAudioUnitScope_Output, 0, &layout, sizeof (layout));
  205173. AURenderCallbackStruct inputProc;
  205174. inputProc.inputProc = processStatic;
  205175. inputProc.inputProcRefCon = this;
  205176. AudioUnitSetProperty (audioUnit, kAudioUnitProperty_SetRenderCallback, kAudioUnitScope_Input, 0, &inputProc, sizeof (inputProc));
  205177. AudioUnitSetProperty (audioUnit, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Input, 0, &format, sizeof (format));
  205178. AudioUnitSetProperty (audioUnit, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Output, 1, &format, sizeof (format));
  205179. AudioUnitInitialize (audioUnit);
  205180. return true;
  205181. }
  205182. // If the routing is set to go through the receiver (i.e. the speaker, but quiet), this re-routes it
  205183. // to make it loud. Needed because by default when using an input + output, the output is kept quiet.
  205184. static void fixAudioRouteIfSetToReceiver()
  205185. {
  205186. CFStringRef audioRoute = 0;
  205187. UInt32 propertySize = sizeof (audioRoute);
  205188. if (AudioSessionGetProperty (kAudioSessionProperty_AudioRoute, &propertySize, &audioRoute) == noErr)
  205189. {
  205190. NSString* route = (NSString*) audioRoute;
  205191. //DBG ("audio route: " + nsStringToJuce (route));
  205192. if ([route hasPrefix: @"Receiver"])
  205193. {
  205194. UInt32 audioRouteOverride = kAudioSessionOverrideAudioRoute_Speaker;
  205195. AudioSessionSetProperty (kAudioSessionProperty_OverrideAudioRoute, sizeof (audioRouteOverride), &audioRouteOverride);
  205196. }
  205197. CFRelease (audioRoute);
  205198. }
  205199. }
  205200. IPhoneAudioIODevice (const IPhoneAudioIODevice&);
  205201. const IPhoneAudioIODevice& operator= (const IPhoneAudioIODevice&);
  205202. };
  205203. class IPhoneAudioIODeviceType : public AudioIODeviceType
  205204. {
  205205. public:
  205206. IPhoneAudioIODeviceType()
  205207. : AudioIODeviceType (T("iPhone Audio"))
  205208. {
  205209. }
  205210. ~IPhoneAudioIODeviceType()
  205211. {
  205212. }
  205213. void scanForDevices()
  205214. {
  205215. }
  205216. const StringArray getDeviceNames (const bool wantInputNames) const
  205217. {
  205218. StringArray s;
  205219. s.add ("iPhone Audio");
  205220. return s;
  205221. }
  205222. int getDefaultDeviceIndex (const bool forInput) const
  205223. {
  205224. return 0;
  205225. }
  205226. int getIndexOfDevice (AudioIODevice* device, const bool asInput) const
  205227. {
  205228. return device != 0 ? 0 : -1;
  205229. }
  205230. bool hasSeparateInputsAndOutputs() const { return false; }
  205231. AudioIODevice* createDevice (const String& outputDeviceName,
  205232. const String& inputDeviceName)
  205233. {
  205234. if (outputDeviceName.isNotEmpty() || inputDeviceName.isNotEmpty())
  205235. {
  205236. return new IPhoneAudioIODevice (outputDeviceName.isNotEmpty() ? outputDeviceName
  205237. : inputDeviceName);
  205238. }
  205239. return 0;
  205240. }
  205241. juce_UseDebuggingNewOperator
  205242. private:
  205243. IPhoneAudioIODeviceType (const IPhoneAudioIODeviceType&);
  205244. const IPhoneAudioIODeviceType& operator= (const IPhoneAudioIODeviceType&);
  205245. };
  205246. AudioIODeviceType* juce_createAudioIODeviceType_iPhoneAudio()
  205247. {
  205248. return new IPhoneAudioIODeviceType();
  205249. }
  205250. #endif
  205251. /********* End of inlined file: juce_iphone_Audio.cpp *********/
  205252. /********* Start of inlined file: juce_mac_CoreMidi.cpp *********/
  205253. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  205254. // compiled on its own).
  205255. #if JUCE_INCLUDED_FILE
  205256. #if JUCE_MAC
  205257. #undef log
  205258. #define log(a) Logger::writeToLog(a)
  205259. static bool logAnyErrorsMidi (const OSStatus err, const int lineNum)
  205260. {
  205261. if (err == noErr)
  205262. return true;
  205263. log (T("CoreMidi error: ") + String (lineNum) + T(" - ") + String::toHexString ((int)err));
  205264. jassertfalse
  205265. return false;
  205266. }
  205267. #undef OK
  205268. #define OK(a) logAnyErrorsMidi(a, __LINE__)
  205269. static const String getEndpointName (MIDIEndpointRef endpoint, bool isExternal)
  205270. {
  205271. String result;
  205272. CFStringRef str = 0;
  205273. MIDIObjectGetStringProperty (endpoint, kMIDIPropertyName, &str);
  205274. if (str != 0)
  205275. {
  205276. result = PlatformUtilities::cfStringToJuceString (str);
  205277. CFRelease (str);
  205278. str = 0;
  205279. }
  205280. MIDIEntityRef entity = 0;
  205281. MIDIEndpointGetEntity (endpoint, &entity);
  205282. if (entity == 0)
  205283. return result; // probably virtual
  205284. if (result.isEmpty())
  205285. {
  205286. // endpoint name has zero length - try the entity
  205287. MIDIObjectGetStringProperty (entity, kMIDIPropertyName, &str);
  205288. if (str != 0)
  205289. {
  205290. result += PlatformUtilities::cfStringToJuceString (str);
  205291. CFRelease (str);
  205292. str = 0;
  205293. }
  205294. }
  205295. // now consider the device's name
  205296. MIDIDeviceRef device = 0;
  205297. MIDIEntityGetDevice (entity, &device);
  205298. if (device == 0)
  205299. return result;
  205300. MIDIObjectGetStringProperty (device, kMIDIPropertyName, &str);
  205301. if (str != 0)
  205302. {
  205303. const String s (PlatformUtilities::cfStringToJuceString (str));
  205304. CFRelease (str);
  205305. // if an external device has only one entity, throw away
  205306. // the endpoint name and just use the device name
  205307. if (isExternal && MIDIDeviceGetNumberOfEntities (device) < 2)
  205308. {
  205309. result = s;
  205310. }
  205311. else if (! result.startsWithIgnoreCase (s))
  205312. {
  205313. // prepend the device name to the entity name
  205314. result = (s + T(" ") + result).trimEnd();
  205315. }
  205316. }
  205317. return result;
  205318. }
  205319. static const String getConnectedEndpointName (MIDIEndpointRef endpoint)
  205320. {
  205321. String result;
  205322. // Does the endpoint have connections?
  205323. CFDataRef connections = 0;
  205324. int numConnections = 0;
  205325. MIDIObjectGetDataProperty (endpoint, kMIDIPropertyConnectionUniqueID, &connections);
  205326. if (connections != 0)
  205327. {
  205328. numConnections = (int) (CFDataGetLength (connections) / sizeof (MIDIUniqueID));
  205329. if (numConnections > 0)
  205330. {
  205331. const SInt32* pid = reinterpret_cast <const SInt32*> (CFDataGetBytePtr (connections));
  205332. for (int i = 0; i < numConnections; ++i, ++pid)
  205333. {
  205334. MIDIUniqueID uid = EndianS32_BtoN (*pid);
  205335. MIDIObjectRef connObject;
  205336. MIDIObjectType connObjectType;
  205337. OSStatus err = MIDIObjectFindByUniqueID (uid, &connObject, &connObjectType);
  205338. if (err == noErr)
  205339. {
  205340. String s;
  205341. if (connObjectType == kMIDIObjectType_ExternalSource
  205342. || connObjectType == kMIDIObjectType_ExternalDestination)
  205343. {
  205344. // Connected to an external device's endpoint (10.3 and later).
  205345. s = getEndpointName (static_cast <MIDIEndpointRef> (connObject), true);
  205346. }
  205347. else
  205348. {
  205349. // Connected to an external device (10.2) (or something else, catch-all)
  205350. CFStringRef str = 0;
  205351. MIDIObjectGetStringProperty (connObject, kMIDIPropertyName, &str);
  205352. if (str != 0)
  205353. {
  205354. s = PlatformUtilities::cfStringToJuceString (str);
  205355. CFRelease (str);
  205356. }
  205357. }
  205358. if (s.isNotEmpty())
  205359. {
  205360. if (result.isNotEmpty())
  205361. result += (", ");
  205362. result += s;
  205363. }
  205364. }
  205365. }
  205366. }
  205367. CFRelease (connections);
  205368. }
  205369. if (result.isNotEmpty())
  205370. return result;
  205371. // Here, either the endpoint had no connections, or we failed to obtain names for any of them.
  205372. return getEndpointName (endpoint, false);
  205373. }
  205374. const StringArray MidiOutput::getDevices()
  205375. {
  205376. StringArray s;
  205377. const ItemCount num = MIDIGetNumberOfDestinations();
  205378. for (ItemCount i = 0; i < num; ++i)
  205379. {
  205380. MIDIEndpointRef dest = MIDIGetDestination (i);
  205381. if (dest != 0)
  205382. {
  205383. String name (getConnectedEndpointName (dest));
  205384. if (name.isEmpty())
  205385. name = "<error>";
  205386. s.add (name);
  205387. }
  205388. else
  205389. {
  205390. s.add ("<error>");
  205391. }
  205392. }
  205393. return s;
  205394. }
  205395. int MidiOutput::getDefaultDeviceIndex()
  205396. {
  205397. return 0;
  205398. }
  205399. static MIDIClientRef globalMidiClient;
  205400. static bool hasGlobalClientBeenCreated = false;
  205401. static bool makeSureClientExists()
  205402. {
  205403. if (! hasGlobalClientBeenCreated)
  205404. {
  205405. String name (T("JUCE"));
  205406. if (JUCEApplication::getInstance() != 0)
  205407. name = JUCEApplication::getInstance()->getApplicationName();
  205408. CFStringRef appName = PlatformUtilities::juceStringToCFString (name);
  205409. hasGlobalClientBeenCreated = OK (MIDIClientCreate (appName, 0, 0, &globalMidiClient));
  205410. CFRelease (appName);
  205411. }
  205412. return hasGlobalClientBeenCreated;
  205413. }
  205414. class MidiPortAndEndpoint
  205415. {
  205416. public:
  205417. MidiPortAndEndpoint (MIDIPortRef port_, MIDIEndpointRef endPoint_)
  205418. : port (port_), endPoint (endPoint_)
  205419. {
  205420. }
  205421. ~MidiPortAndEndpoint()
  205422. {
  205423. if (port != 0)
  205424. MIDIPortDispose (port);
  205425. if (port == 0 && endPoint != 0) // if port == 0, it means we created the endpoint, so it's safe to delete it
  205426. MIDIEndpointDispose (endPoint);
  205427. }
  205428. MIDIPortRef port;
  205429. MIDIEndpointRef endPoint;
  205430. };
  205431. MidiOutput* MidiOutput::openDevice (int index)
  205432. {
  205433. MidiOutput* mo = 0;
  205434. if (((unsigned int) index) < (unsigned int) MIDIGetNumberOfDestinations())
  205435. {
  205436. MIDIEndpointRef endPoint = MIDIGetDestination (index);
  205437. CFStringRef pname;
  205438. if (OK (MIDIObjectGetStringProperty (endPoint, kMIDIPropertyName, &pname)))
  205439. {
  205440. log (T("CoreMidi - opening out: ") + PlatformUtilities::cfStringToJuceString (pname));
  205441. if (makeSureClientExists())
  205442. {
  205443. MIDIPortRef port;
  205444. if (OK (MIDIOutputPortCreate (globalMidiClient, pname, &port)))
  205445. {
  205446. mo = new MidiOutput();
  205447. mo->internal = (void*) new MidiPortAndEndpoint (port, endPoint);
  205448. }
  205449. }
  205450. CFRelease (pname);
  205451. }
  205452. }
  205453. return mo;
  205454. }
  205455. MidiOutput* MidiOutput::createNewDevice (const String& deviceName)
  205456. {
  205457. MidiOutput* mo = 0;
  205458. if (makeSureClientExists())
  205459. {
  205460. MIDIEndpointRef endPoint;
  205461. CFStringRef name = PlatformUtilities::juceStringToCFString (deviceName);
  205462. if (OK (MIDISourceCreate (globalMidiClient, name, &endPoint)))
  205463. {
  205464. mo = new MidiOutput();
  205465. mo->internal = (void*) new MidiPortAndEndpoint (0, endPoint);
  205466. }
  205467. CFRelease (name);
  205468. }
  205469. return mo;
  205470. }
  205471. MidiOutput::~MidiOutput()
  205472. {
  205473. delete (MidiPortAndEndpoint*) internal;
  205474. }
  205475. void MidiOutput::reset()
  205476. {
  205477. }
  205478. bool MidiOutput::getVolume (float& leftVol, float& rightVol)
  205479. {
  205480. return false;
  205481. }
  205482. void MidiOutput::setVolume (float leftVol, float rightVol)
  205483. {
  205484. }
  205485. void MidiOutput::sendMessageNow (const MidiMessage& message)
  205486. {
  205487. MidiPortAndEndpoint* const mpe = (MidiPortAndEndpoint*) internal;
  205488. if (message.isSysEx())
  205489. {
  205490. const int maxPacketSize = 256;
  205491. int pos = 0, bytesLeft = message.getRawDataSize();
  205492. const int numPackets = (bytesLeft + maxPacketSize - 1) / maxPacketSize;
  205493. HeapBlock <MIDIPacketList> packets;
  205494. packets.malloc (32 * numPackets + message.getRawDataSize(), 1);
  205495. packets->numPackets = numPackets;
  205496. MIDIPacket* p = packets->packet;
  205497. for (int i = 0; i < numPackets; ++i)
  205498. {
  205499. p->timeStamp = 0;
  205500. p->length = jmin (maxPacketSize, bytesLeft);
  205501. memcpy (p->data, message.getRawData() + pos, p->length);
  205502. pos += p->length;
  205503. bytesLeft -= p->length;
  205504. p = MIDIPacketNext (p);
  205505. }
  205506. if (mpe->port != 0)
  205507. MIDISend (mpe->port, mpe->endPoint, packets);
  205508. else
  205509. MIDIReceived (mpe->endPoint, packets);
  205510. }
  205511. else
  205512. {
  205513. MIDIPacketList packets;
  205514. packets.numPackets = 1;
  205515. packets.packet[0].timeStamp = 0;
  205516. packets.packet[0].length = message.getRawDataSize();
  205517. *(int*) (packets.packet[0].data) = *(const int*) message.getRawData();
  205518. if (mpe->port != 0)
  205519. MIDISend (mpe->port, mpe->endPoint, &packets);
  205520. else
  205521. MIDIReceived (mpe->endPoint, &packets);
  205522. }
  205523. }
  205524. const StringArray MidiInput::getDevices()
  205525. {
  205526. StringArray s;
  205527. const ItemCount num = MIDIGetNumberOfSources();
  205528. for (ItemCount i = 0; i < num; ++i)
  205529. {
  205530. MIDIEndpointRef source = MIDIGetSource (i);
  205531. if (source != 0)
  205532. {
  205533. String name (getConnectedEndpointName (source));
  205534. if (name.isEmpty())
  205535. name = "<error>";
  205536. s.add (name);
  205537. }
  205538. else
  205539. {
  205540. s.add ("<error>");
  205541. }
  205542. }
  205543. return s;
  205544. }
  205545. int MidiInput::getDefaultDeviceIndex()
  205546. {
  205547. return 0;
  205548. }
  205549. struct MidiPortAndCallback
  205550. {
  205551. MidiInput* input;
  205552. MidiPortAndEndpoint* portAndEndpoint;
  205553. MidiInputCallback* callback;
  205554. MemoryBlock pendingData;
  205555. int pendingBytes;
  205556. double pendingDataTime;
  205557. bool active;
  205558. };
  205559. static CriticalSection callbackLock;
  205560. static VoidArray activeCallbacks;
  205561. static void processSysex (MidiPortAndCallback* const mpc, const uint8*& d, int& size, const double time)
  205562. {
  205563. if (*d == 0xf0)
  205564. {
  205565. mpc->pendingBytes = 0;
  205566. mpc->pendingDataTime = time;
  205567. }
  205568. mpc->pendingData.ensureSize (mpc->pendingBytes + size, false);
  205569. uint8* totalMessage = (uint8*) mpc->pendingData.getData();
  205570. uint8* dest = totalMessage + mpc->pendingBytes;
  205571. while (size > 0)
  205572. {
  205573. if (mpc->pendingBytes > 0 && *d >= 0x80)
  205574. {
  205575. if (*d >= 0xfa || *d == 0xf8)
  205576. {
  205577. mpc->callback->handleIncomingMidiMessage (mpc->input, MidiMessage (*d, time));
  205578. ++d;
  205579. --size;
  205580. }
  205581. else
  205582. {
  205583. if (*d == 0xf7)
  205584. {
  205585. *dest++ = *d++;
  205586. mpc->pendingBytes++;
  205587. --size;
  205588. }
  205589. break;
  205590. }
  205591. }
  205592. else
  205593. {
  205594. *dest++ = *d++;
  205595. mpc->pendingBytes++;
  205596. --size;
  205597. }
  205598. }
  205599. if (totalMessage [mpc->pendingBytes - 1] == 0xf7)
  205600. {
  205601. mpc->callback->handleIncomingMidiMessage (mpc->input, MidiMessage (totalMessage,
  205602. mpc->pendingBytes,
  205603. mpc->pendingDataTime));
  205604. mpc->pendingBytes = 0;
  205605. }
  205606. else
  205607. {
  205608. mpc->callback->handlePartialSysexMessage (mpc->input,
  205609. totalMessage,
  205610. mpc->pendingBytes,
  205611. mpc->pendingDataTime);
  205612. }
  205613. }
  205614. static void midiInputProc (const MIDIPacketList* pktlist,
  205615. void* readProcRefCon,
  205616. void* srcConnRefCon)
  205617. {
  205618. double time = Time::getMillisecondCounterHiRes() * 0.001;
  205619. const double originalTime = time;
  205620. MidiPortAndCallback* const mpc = (MidiPortAndCallback*) readProcRefCon;
  205621. const ScopedLock sl (callbackLock);
  205622. if (activeCallbacks.contains (mpc) && mpc->active)
  205623. {
  205624. const MIDIPacket* packet = &pktlist->packet[0];
  205625. for (unsigned int i = 0; i < pktlist->numPackets; ++i)
  205626. {
  205627. const uint8* d = (const uint8*) (packet->data);
  205628. int size = packet->length;
  205629. while (size > 0)
  205630. {
  205631. time = originalTime;
  205632. if (mpc->pendingBytes > 0 || d[0] == 0xf0)
  205633. {
  205634. processSysex (mpc, d, size, time);
  205635. }
  205636. else
  205637. {
  205638. int used = 0;
  205639. const MidiMessage m (d, size, used, 0, time);
  205640. if (used <= 0)
  205641. {
  205642. jassertfalse // malformed midi message
  205643. break;
  205644. }
  205645. else
  205646. {
  205647. mpc->callback->handleIncomingMidiMessage (mpc->input, m);
  205648. }
  205649. size -= used;
  205650. d += used;
  205651. }
  205652. }
  205653. packet = MIDIPacketNext (packet);
  205654. }
  205655. }
  205656. }
  205657. MidiInput* MidiInput::openDevice (int index, MidiInputCallback* callback)
  205658. {
  205659. MidiInput* mi = 0;
  205660. if (((unsigned int) index) < (unsigned int) MIDIGetNumberOfSources())
  205661. {
  205662. MIDIEndpointRef endPoint = MIDIGetSource (index);
  205663. if (endPoint != 0)
  205664. {
  205665. CFStringRef pname;
  205666. if (OK (MIDIObjectGetStringProperty (endPoint, kMIDIPropertyName, &pname)))
  205667. {
  205668. log (T("CoreMidi - opening inp: ") + PlatformUtilities::cfStringToJuceString (pname));
  205669. if (makeSureClientExists())
  205670. {
  205671. MIDIPortRef port;
  205672. ScopedPointer <MidiPortAndCallback> mpc (new MidiPortAndCallback());
  205673. mpc->active = false;
  205674. if (OK (MIDIInputPortCreate (globalMidiClient, pname, midiInputProc, mpc, &port)))
  205675. {
  205676. if (OK (MIDIPortConnectSource (port, endPoint, 0)))
  205677. {
  205678. mpc->portAndEndpoint = new MidiPortAndEndpoint (port, endPoint);
  205679. mpc->callback = callback;
  205680. mpc->pendingBytes = 0;
  205681. mpc->pendingData.ensureSize (128);
  205682. mi = new MidiInput (getDevices() [index]);
  205683. mpc->input = mi;
  205684. mi->internal = (void*) mpc;
  205685. const ScopedLock sl (callbackLock);
  205686. activeCallbacks.add (mpc.release());
  205687. }
  205688. else
  205689. {
  205690. OK (MIDIPortDispose (port));
  205691. }
  205692. }
  205693. }
  205694. }
  205695. CFRelease (pname);
  205696. }
  205697. }
  205698. return mi;
  205699. }
  205700. MidiInput* MidiInput::createNewDevice (const String& deviceName, MidiInputCallback* callback)
  205701. {
  205702. MidiInput* mi = 0;
  205703. if (makeSureClientExists())
  205704. {
  205705. ScopedPointer <MidiPortAndCallback> mpc (new MidiPortAndCallback());
  205706. mpc->active = false;
  205707. MIDIEndpointRef endPoint;
  205708. CFStringRef name = PlatformUtilities::juceStringToCFString(deviceName);
  205709. if (OK (MIDIDestinationCreate (globalMidiClient, name, midiInputProc, mpc, &endPoint)))
  205710. {
  205711. mpc->portAndEndpoint = new MidiPortAndEndpoint (0, endPoint);
  205712. mpc->callback = callback;
  205713. mpc->pendingBytes = 0;
  205714. mpc->pendingData.ensureSize (128);
  205715. mi = new MidiInput (deviceName);
  205716. mpc->input = mi;
  205717. mi->internal = (void*) mpc;
  205718. const ScopedLock sl (callbackLock);
  205719. activeCallbacks.add (mpc.release());
  205720. }
  205721. CFRelease (name);
  205722. }
  205723. return mi;
  205724. }
  205725. MidiInput::MidiInput (const String& name_)
  205726. : name (name_)
  205727. {
  205728. }
  205729. MidiInput::~MidiInput()
  205730. {
  205731. MidiPortAndCallback* const mpc = (MidiPortAndCallback*) internal;
  205732. mpc->active = false;
  205733. callbackLock.enter();
  205734. activeCallbacks.removeValue (mpc);
  205735. callbackLock.exit();
  205736. if (mpc->portAndEndpoint->port != 0)
  205737. OK (MIDIPortDisconnectSource (mpc->portAndEndpoint->port, mpc->portAndEndpoint->endPoint));
  205738. delete mpc->portAndEndpoint;
  205739. delete mpc;
  205740. }
  205741. void MidiInput::start()
  205742. {
  205743. MidiPortAndCallback* const mpc = (MidiPortAndCallback*) internal;
  205744. const ScopedLock sl (callbackLock);
  205745. mpc->active = true;
  205746. }
  205747. void MidiInput::stop()
  205748. {
  205749. MidiPortAndCallback* const mpc = (MidiPortAndCallback*) internal;
  205750. const ScopedLock sl (callbackLock);
  205751. mpc->active = false;
  205752. }
  205753. #undef log
  205754. #else
  205755. MidiOutput::~MidiOutput()
  205756. {
  205757. }
  205758. void MidiOutput::reset()
  205759. {
  205760. }
  205761. bool MidiOutput::getVolume (float& leftVol, float& rightVol)
  205762. {
  205763. return false;
  205764. }
  205765. void MidiOutput::setVolume (float leftVol, float rightVol)
  205766. {
  205767. }
  205768. void MidiOutput::sendMessageNow (const MidiMessage& message)
  205769. {
  205770. }
  205771. const StringArray MidiOutput::getDevices()
  205772. {
  205773. return StringArray();
  205774. }
  205775. MidiOutput* MidiOutput::openDevice (int index)
  205776. {
  205777. return 0;
  205778. }
  205779. const StringArray MidiInput::getDevices()
  205780. {
  205781. return StringArray();
  205782. }
  205783. MidiInput* MidiInput::openDevice (int index, MidiInputCallback* callback)
  205784. {
  205785. return 0;
  205786. }
  205787. #endif
  205788. #endif
  205789. /********* End of inlined file: juce_mac_CoreMidi.cpp *********/
  205790. #else
  205791. /********* Start of inlined file: juce_mac_Fonts.mm *********/
  205792. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  205793. // compiled on its own).
  205794. #if JUCE_INCLUDED_FILE
  205795. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
  205796. #define SUPPORT_10_4_FONTS 1
  205797. #define NEW_CGFONT_FUNCTIONS_UNAVAILABLE (CGFontCreateWithFontName == 0)
  205798. #if MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_5
  205799. #define SUPPORT_ONLY_10_4_FONTS 1
  205800. #endif
  205801. END_JUCE_NAMESPACE
  205802. @interface NSFont (PrivateHack)
  205803. - (NSGlyph) _defaultGlyphForChar: (unichar) theChar;
  205804. @end
  205805. BEGIN_JUCE_NAMESPACE
  205806. #endif
  205807. class MacTypeface : public Typeface
  205808. {
  205809. public:
  205810. MacTypeface (const Font& font)
  205811. : Typeface (font.getTypefaceName())
  205812. {
  205813. const ScopedAutoReleasePool pool;
  205814. renderingTransform = CGAffineTransformIdentity;
  205815. bool needsItalicTransform = false;
  205816. #if JUCE_IPHONE
  205817. NSString* fontName = juceStringToNS (font.getTypefaceName());
  205818. if (font.isItalic() || font.isBold())
  205819. {
  205820. NSArray* familyFonts = [UIFont fontNamesForFamilyName: juceStringToNS (font.getTypefaceName())];
  205821. for (NSString* i in familyFonts)
  205822. {
  205823. const String fn (nsStringToJuce (i));
  205824. const String afterDash (fn.fromFirstOccurrenceOf (T("-"), false, false));
  205825. const bool probablyBold = afterDash.containsIgnoreCase (T("bold")) || fn.endsWithIgnoreCase (T("bold"));
  205826. const bool probablyItalic = afterDash.containsIgnoreCase (T("oblique"))
  205827. || afterDash.containsIgnoreCase (T("italic"))
  205828. || fn.endsWithIgnoreCase (T("oblique"))
  205829. || fn.endsWithIgnoreCase (T("italic"));
  205830. if (probablyBold == font.isBold()
  205831. && probablyItalic == font.isItalic())
  205832. {
  205833. fontName = i;
  205834. needsItalicTransform = false;
  205835. break;
  205836. }
  205837. else if (probablyBold && (! probablyItalic) && probablyBold == font.isBold())
  205838. {
  205839. fontName = i;
  205840. needsItalicTransform = true; // not ideal, so carry on in case we find a better one
  205841. }
  205842. }
  205843. if (needsItalicTransform)
  205844. renderingTransform.c = 0.15f;
  205845. }
  205846. fontRef = CGFontCreateWithFontName ((CFStringRef) fontName);
  205847. const int ascender = abs (CGFontGetAscent (fontRef));
  205848. const float totalHeight = ascender + abs (CGFontGetDescent (fontRef));
  205849. ascent = ascender / totalHeight;
  205850. unitsToHeightScaleFactor = 1.0f / totalHeight;
  205851. fontHeightToCGSizeFactor = CGFontGetUnitsPerEm (fontRef) / totalHeight;
  205852. #else
  205853. nsFont = [NSFont fontWithName: juceStringToNS (font.getTypefaceName()) size: 1024];
  205854. if (font.isItalic())
  205855. {
  205856. NSFont* newFont = [[NSFontManager sharedFontManager] convertFont: nsFont
  205857. toHaveTrait: NSItalicFontMask];
  205858. if (newFont == nsFont)
  205859. needsItalicTransform = true; // couldn't find a proper italic version, so fake it with a transform..
  205860. nsFont = newFont;
  205861. }
  205862. if (font.isBold())
  205863. nsFont = [[NSFontManager sharedFontManager] convertFont: nsFont toHaveTrait: NSBoldFontMask];
  205864. [nsFont retain];
  205865. ascent = fabsf ((float) [nsFont ascender]);
  205866. float totalSize = ascent + fabsf ((float) [nsFont descender]);
  205867. ascent /= totalSize;
  205868. pathTransform = AffineTransform::identity.scale (1.0f / totalSize, 1.0f / totalSize);
  205869. if (needsItalicTransform)
  205870. {
  205871. pathTransform = pathTransform.sheared (-0.15f, 0.0f);
  205872. renderingTransform.c = 0.15f;
  205873. }
  205874. #if SUPPORT_ONLY_10_4_FONTS
  205875. ATSFontRef atsFont = ATSFontFindFromName ((CFStringRef) [nsFont fontName], kATSOptionFlagsDefault);
  205876. if (atsFont == 0)
  205877. atsFont = ATSFontFindFromPostScriptName ((CFStringRef) [nsFont fontName], kATSOptionFlagsDefault);
  205878. fontRef = CGFontCreateWithPlatformFont ((void*) &atsFont);
  205879. const float totalHeight = fabsf ([nsFont ascender]) + fabsf([nsFont descender]);
  205880. unitsToHeightScaleFactor = 1.0f / totalHeight;
  205881. fontHeightToCGSizeFactor = 1024.0f / totalHeight;
  205882. #else
  205883. #if SUPPORT_10_4_FONTS
  205884. if (NEW_CGFONT_FUNCTIONS_UNAVAILABLE)
  205885. {
  205886. ATSFontRef atsFont = ATSFontFindFromName ((CFStringRef) [nsFont fontName], kATSOptionFlagsDefault);
  205887. if (atsFont == 0)
  205888. atsFont = ATSFontFindFromPostScriptName ((CFStringRef) [nsFont fontName], kATSOptionFlagsDefault);
  205889. fontRef = CGFontCreateWithPlatformFont ((void*) &atsFont);
  205890. const float totalHeight = fabsf ([nsFont ascender]) + fabsf([nsFont descender]);
  205891. unitsToHeightScaleFactor = 1.0f / totalHeight;
  205892. fontHeightToCGSizeFactor = 1024.0f / totalHeight;
  205893. }
  205894. else
  205895. #endif
  205896. {
  205897. fontRef = CGFontCreateWithFontName ((CFStringRef) [nsFont fontName]);
  205898. const int totalHeight = abs (CGFontGetAscent (fontRef)) + abs (CGFontGetDescent (fontRef));
  205899. unitsToHeightScaleFactor = 1.0f / totalHeight;
  205900. fontHeightToCGSizeFactor = CGFontGetUnitsPerEm (fontRef) / (float) totalHeight;
  205901. }
  205902. #endif
  205903. #endif
  205904. }
  205905. ~MacTypeface()
  205906. {
  205907. #if ! JUCE_IPHONE
  205908. [nsFont release];
  205909. #endif
  205910. if (fontRef != 0)
  205911. CGFontRelease (fontRef);
  205912. }
  205913. float getAscent() const
  205914. {
  205915. return ascent;
  205916. }
  205917. float getDescent() const
  205918. {
  205919. return 1.0f - ascent;
  205920. }
  205921. float getStringWidth (const String& text)
  205922. {
  205923. if (fontRef == 0 || text.isEmpty())
  205924. return 0;
  205925. const int length = text.length();
  205926. HeapBlock <CGGlyph> glyphs;
  205927. createGlyphsForString (text, length, glyphs);
  205928. float x = 0;
  205929. #if SUPPORT_ONLY_10_4_FONTS
  205930. HeapBlock <NSSize> advances (length);
  205931. [nsFont getAdvancements: advances forGlyphs: (NSGlyph*) glyphs count: length];
  205932. for (int i = 0; i < length; ++i)
  205933. x += advances[i].width;
  205934. #else
  205935. #if SUPPORT_10_4_FONTS
  205936. if (NEW_CGFONT_FUNCTIONS_UNAVAILABLE)
  205937. {
  205938. HeapBlock <NSSize> advances (length);
  205939. [nsFont getAdvancements: advances forGlyphs: (NSGlyph*) glyphs count: length];
  205940. for (int i = 0; i < length; ++i)
  205941. x += advances[i].width;
  205942. }
  205943. else
  205944. #endif
  205945. {
  205946. HeapBlock <int> advances (length);
  205947. if (CGFontGetGlyphAdvances (fontRef, glyphs, length, advances))
  205948. for (int i = 0; i < length; ++i)
  205949. x += advances[i];
  205950. }
  205951. #endif
  205952. return x * unitsToHeightScaleFactor;
  205953. }
  205954. void getGlyphPositions (const String& text, Array <int>& resultGlyphs, Array <float>& xOffsets)
  205955. {
  205956. xOffsets.add (0);
  205957. if (fontRef == 0 || text.isEmpty())
  205958. return;
  205959. const int length = text.length();
  205960. HeapBlock <CGGlyph> glyphs;
  205961. createGlyphsForString (text, length, glyphs);
  205962. #if SUPPORT_ONLY_10_4_FONTS
  205963. HeapBlock <NSSize> advances (length);
  205964. [nsFont getAdvancements: advances forGlyphs: (NSGlyph*) glyphs count: length];
  205965. int x = 0;
  205966. for (int i = 0; i < length; ++i)
  205967. {
  205968. x += advances[i].width;
  205969. xOffsets.add (x * unitsToHeightScaleFactor);
  205970. resultGlyphs.add (((NSGlyph*) glyphs)[i]);
  205971. }
  205972. #else
  205973. #if SUPPORT_10_4_FONTS
  205974. if (NEW_CGFONT_FUNCTIONS_UNAVAILABLE)
  205975. {
  205976. HeapBlock <NSSize> advances (length);
  205977. [nsFont getAdvancements: advances forGlyphs: (NSGlyph*) glyphs count: length];
  205978. float x = 0;
  205979. for (int i = 0; i < length; ++i)
  205980. {
  205981. x += advances[i].width;
  205982. xOffsets.add (x * unitsToHeightScaleFactor);
  205983. resultGlyphs.add (((NSGlyph*) glyphs)[i]);
  205984. }
  205985. }
  205986. else
  205987. #endif
  205988. {
  205989. HeapBlock <int> advances (length);
  205990. if (CGFontGetGlyphAdvances (fontRef, glyphs, length, advances))
  205991. {
  205992. int x = 0;
  205993. for (int i = 0; i < length; ++i)
  205994. {
  205995. x += advances [i];
  205996. xOffsets.add (x * unitsToHeightScaleFactor);
  205997. resultGlyphs.add (glyphs[i]);
  205998. }
  205999. }
  206000. }
  206001. #endif
  206002. }
  206003. bool getOutlineForGlyph (int glyphNumber, Path& path)
  206004. {
  206005. #if JUCE_IPHONE
  206006. return false;
  206007. #else
  206008. if (nsFont == 0)
  206009. return false;
  206010. // we might need to apply a transform to the path, so it mustn't have anything else in it
  206011. jassert (path.isEmpty());
  206012. const ScopedAutoReleasePool pool;
  206013. NSBezierPath* bez = [NSBezierPath bezierPath];
  206014. [bez moveToPoint: NSMakePoint (0, 0)];
  206015. [bez appendBezierPathWithGlyph: (NSGlyph) glyphNumber
  206016. inFont: nsFont];
  206017. for (int i = 0; i < [bez elementCount]; ++i)
  206018. {
  206019. NSPoint p[3];
  206020. switch ([bez elementAtIndex: i associatedPoints: p])
  206021. {
  206022. case NSMoveToBezierPathElement:
  206023. path.startNewSubPath ((float) p[0].x, (float) -p[0].y);
  206024. break;
  206025. case NSLineToBezierPathElement:
  206026. path.lineTo ((float) p[0].x, (float) -p[0].y);
  206027. break;
  206028. case NSCurveToBezierPathElement:
  206029. 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);
  206030. break;
  206031. case NSClosePathBezierPathElement:
  206032. path.closeSubPath();
  206033. break;
  206034. default:
  206035. jassertfalse
  206036. break;
  206037. }
  206038. }
  206039. path.applyTransform (pathTransform);
  206040. return true;
  206041. #endif
  206042. }
  206043. juce_UseDebuggingNewOperator
  206044. CGFontRef fontRef;
  206045. float fontHeightToCGSizeFactor;
  206046. CGAffineTransform renderingTransform;
  206047. private:
  206048. float ascent, unitsToHeightScaleFactor;
  206049. #if JUCE_IPHONE
  206050. #else
  206051. NSFont* nsFont;
  206052. AffineTransform pathTransform;
  206053. #endif
  206054. void createGlyphsForString (const juce_wchar* const text, const int length, HeapBlock <CGGlyph>& glyphs)
  206055. {
  206056. #if SUPPORT_10_4_FONTS
  206057. #if ! SUPPORT_ONLY_10_4_FONTS
  206058. if (NEW_CGFONT_FUNCTIONS_UNAVAILABLE)
  206059. #endif
  206060. {
  206061. glyphs.malloc (sizeof (NSGlyph) * length, 1);
  206062. NSGlyph* const g = (NSGlyph*) glyphs;
  206063. for (int i = 0; i < length; ++i)
  206064. g[i] = (NSGlyph) [nsFont _defaultGlyphForChar: text[i]];
  206065. return;
  206066. }
  206067. #endif
  206068. #if ! SUPPORT_ONLY_10_4_FONTS
  206069. if (charToGlyphMapper == 0)
  206070. charToGlyphMapper = new CharToGlyphMapper (fontRef);
  206071. glyphs.malloc (length);
  206072. for (int i = 0; i < length; ++i)
  206073. glyphs[i] = (CGGlyph) charToGlyphMapper->getGlyphForCharacter (text[i]);
  206074. #endif
  206075. }
  206076. #if ! SUPPORT_ONLY_10_4_FONTS
  206077. // Reads a CGFontRef's character map table to convert unicode into glyph numbers
  206078. class CharToGlyphMapper
  206079. {
  206080. public:
  206081. CharToGlyphMapper (CGFontRef fontRef)
  206082. : segCount (0), endCode (0), startCode (0), idDelta (0),
  206083. idRangeOffset (0), glyphIndexes (0)
  206084. {
  206085. CFDataRef cmapTable = CGFontCopyTableForTag (fontRef, 'cmap');
  206086. if (cmapTable != 0)
  206087. {
  206088. const int numSubtables = getValue16 (cmapTable, 2);
  206089. for (int i = 0; i < numSubtables; ++i)
  206090. {
  206091. if (getValue16 (cmapTable, i * 8 + 4) == 0) // check for platform ID of 0
  206092. {
  206093. const int offset = getValue32 (cmapTable, i * 8 + 8);
  206094. if (getValue16 (cmapTable, offset) == 4) // check that it's format 4..
  206095. {
  206096. const int length = getValue16 (cmapTable, offset + 2);
  206097. const int segCountX2 = getValue16 (cmapTable, offset + 6);
  206098. segCount = segCountX2 / 2;
  206099. const int endCodeOffset = offset + 14;
  206100. const int startCodeOffset = endCodeOffset + 2 + segCountX2;
  206101. const int idDeltaOffset = startCodeOffset + segCountX2;
  206102. const int idRangeOffsetOffset = idDeltaOffset + segCountX2;
  206103. const int glyphIndexesOffset = idRangeOffsetOffset + segCountX2;
  206104. endCode = CFDataCreate (kCFAllocatorDefault, CFDataGetBytePtr (cmapTable) + endCodeOffset, segCountX2);
  206105. startCode = CFDataCreate (kCFAllocatorDefault, CFDataGetBytePtr (cmapTable) + startCodeOffset, segCountX2);
  206106. idDelta = CFDataCreate (kCFAllocatorDefault, CFDataGetBytePtr (cmapTable) + idDeltaOffset, segCountX2);
  206107. idRangeOffset = CFDataCreate (kCFAllocatorDefault, CFDataGetBytePtr (cmapTable) + idRangeOffsetOffset, segCountX2);
  206108. glyphIndexes = CFDataCreate (kCFAllocatorDefault, CFDataGetBytePtr (cmapTable) + glyphIndexesOffset, offset + length - glyphIndexesOffset);
  206109. }
  206110. break;
  206111. }
  206112. }
  206113. CFRelease (cmapTable);
  206114. }
  206115. }
  206116. ~CharToGlyphMapper()
  206117. {
  206118. if (endCode != 0)
  206119. {
  206120. CFRelease (endCode);
  206121. CFRelease (startCode);
  206122. CFRelease (idDelta);
  206123. CFRelease (idRangeOffset);
  206124. CFRelease (glyphIndexes);
  206125. }
  206126. }
  206127. int getGlyphForCharacter (const juce_wchar c) const
  206128. {
  206129. for (int i = 0; i < segCount; ++i)
  206130. {
  206131. if (getValue16 (endCode, i * 2) >= c)
  206132. {
  206133. const int start = getValue16 (startCode, i * 2);
  206134. if (start > c)
  206135. break;
  206136. const int delta = getValue16 (idDelta, i * 2);
  206137. const int rangeOffset = getValue16 (idRangeOffset, i * 2);
  206138. if (rangeOffset == 0)
  206139. return delta + c;
  206140. else
  206141. return getValue16 (glyphIndexes, 2 * ((rangeOffset / 2) + (c - start) - (segCount - i)));
  206142. }
  206143. }
  206144. // If we failed to find it "properly", this dodgy fall-back seems to do the trick for most fonts!
  206145. return jmax (-1, c - 29);
  206146. }
  206147. private:
  206148. int segCount;
  206149. CFDataRef endCode, startCode, idDelta, idRangeOffset, glyphIndexes;
  206150. static uint16 getValue16 (CFDataRef data, const int index)
  206151. {
  206152. return CFSwapInt16BigToHost (*(UInt16*) (CFDataGetBytePtr (data) + index));
  206153. }
  206154. static uint32 getValue32 (CFDataRef data, const int index)
  206155. {
  206156. return CFSwapInt32BigToHost (*(UInt32*) (CFDataGetBytePtr (data) + index));
  206157. }
  206158. };
  206159. ScopedPointer <CharToGlyphMapper> charToGlyphMapper;
  206160. #endif
  206161. };
  206162. const Typeface::Ptr Typeface::createSystemTypefaceFor (const Font& font)
  206163. {
  206164. return new MacTypeface (font);
  206165. }
  206166. const StringArray Font::findAllTypefaceNames() throw()
  206167. {
  206168. StringArray names;
  206169. const ScopedAutoReleasePool pool;
  206170. #if JUCE_IPHONE
  206171. NSArray* fonts = [UIFont familyNames];
  206172. #else
  206173. NSArray* fonts = [[NSFontManager sharedFontManager] availableFontFamilies];
  206174. #endif
  206175. for (unsigned int i = 0; i < [fonts count]; ++i)
  206176. names.add (nsStringToJuce ((NSString*) [fonts objectAtIndex: i]));
  206177. names.sort (true);
  206178. return names;
  206179. }
  206180. void Font::getPlatformDefaultFontNames (String& defaultSans, String& defaultSerif, String& defaultFixed) throw()
  206181. {
  206182. #if JUCE_IPHONE
  206183. defaultSans = "Helvetica";
  206184. defaultSerif = "Times New Roman";
  206185. defaultFixed = "Courier New";
  206186. #else
  206187. defaultSans = "Lucida Grande";
  206188. defaultSerif = "Times New Roman";
  206189. defaultFixed = "Monaco";
  206190. #endif
  206191. }
  206192. #endif
  206193. /********* End of inlined file: juce_mac_Fonts.mm *********/
  206194. // (must go before juce_mac_CoreGraphicsContext.mm)
  206195. /********* Start of inlined file: juce_mac_CoreGraphicsContext.mm *********/
  206196. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  206197. // compiled on its own).
  206198. #if JUCE_INCLUDED_FILE
  206199. class CoreGraphicsImage : public Image
  206200. {
  206201. public:
  206202. CoreGraphicsImage (const PixelFormat format_,
  206203. const int imageWidth_,
  206204. const int imageHeight_,
  206205. const bool clearImage)
  206206. : Image (format_, imageWidth_, imageHeight_, clearImage)
  206207. {
  206208. CGColorSpaceRef colourSpace = format == Image::SingleChannel ? CGColorSpaceCreateDeviceGray()
  206209. : CGColorSpaceCreateDeviceRGB();
  206210. context = CGBitmapContextCreate (imageData, imageWidth, imageHeight, 8, lineStride,
  206211. colourSpace, getCGImageFlags (*this));
  206212. CGColorSpaceRelease (colourSpace);
  206213. }
  206214. ~CoreGraphicsImage()
  206215. {
  206216. CGContextRelease (context);
  206217. }
  206218. LowLevelGraphicsContext* createLowLevelContext();
  206219. static CGImageRef createImage (const Image& juceImage, const bool forAlpha, CGColorSpaceRef colourSpace)
  206220. {
  206221. const CoreGraphicsImage* nativeImage = dynamic_cast <const CoreGraphicsImage*> (&juceImage);
  206222. if (nativeImage != 0 && (juceImage.getFormat() == Image::SingleChannel || ! forAlpha))
  206223. {
  206224. return CGBitmapContextCreateImage (nativeImage->context);
  206225. }
  206226. else
  206227. {
  206228. const Image::BitmapData srcData (juceImage, 0, 0, juceImage.getWidth(), juceImage.getHeight());
  206229. CGDataProviderRef provider = CGDataProviderCreateWithData (0, srcData.data, srcData.lineStride * srcData.pixelStride, 0);
  206230. CGImageRef imageRef = CGImageCreate (srcData.width, srcData.height,
  206231. 8, srcData.pixelStride * 8, srcData.lineStride,
  206232. colourSpace, getCGImageFlags (juceImage), provider,
  206233. 0, true, kCGRenderingIntentDefault);
  206234. CGDataProviderRelease (provider);
  206235. return imageRef;
  206236. }
  206237. }
  206238. #if JUCE_MAC
  206239. static NSImage* createNSImage (const Image& image)
  206240. {
  206241. const ScopedAutoReleasePool pool;
  206242. NSImage* im = [[NSImage alloc] init];
  206243. [im setSize: NSMakeSize (image.getWidth(), image.getHeight())];
  206244. [im lockFocus];
  206245. CGColorSpaceRef colourSpace = CGColorSpaceCreateDeviceRGB();
  206246. CGImageRef imageRef = createImage (image, false, colourSpace);
  206247. CGColorSpaceRelease (colourSpace);
  206248. CGContextRef cg = (CGContextRef) [[NSGraphicsContext currentContext] graphicsPort];
  206249. CGContextDrawImage (cg, CGRectMake (0, 0, image.getWidth(), image.getHeight()), imageRef);
  206250. CGImageRelease (imageRef);
  206251. [im unlockFocus];
  206252. return im;
  206253. }
  206254. #endif
  206255. CGContextRef context;
  206256. private:
  206257. static CGBitmapInfo getCGImageFlags (const Image& image)
  206258. {
  206259. #if JUCE_BIG_ENDIAN
  206260. return image.getFormat() == Image::ARGB ? (kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Big) : kCGBitmapByteOrderDefault;
  206261. #else
  206262. return image.getFormat() == Image::ARGB ? (kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Little) : kCGBitmapByteOrderDefault;
  206263. #endif
  206264. }
  206265. };
  206266. Image* Image::createNativeImage (const PixelFormat format, const int imageWidth, const int imageHeight, const bool clearImage)
  206267. {
  206268. #if USE_COREGRAPHICS_RENDERING
  206269. return new CoreGraphicsImage (format == RGB ? ARGB : format, imageWidth, imageHeight, clearImage);
  206270. #else
  206271. return new Image (format, imageWidth, imageHeight, clearImage);
  206272. #endif
  206273. }
  206274. class CoreGraphicsContext : public LowLevelGraphicsContext
  206275. {
  206276. public:
  206277. CoreGraphicsContext (CGContextRef context_, const float flipHeight_)
  206278. : context (context_),
  206279. flipHeight (flipHeight_),
  206280. numGradientLookupEntries (0)
  206281. {
  206282. CGContextRetain (context);
  206283. CGContextSaveGState(context);
  206284. CGContextSetShouldSmoothFonts (context, true);
  206285. CGContextSetShouldAntialias (context, true);
  206286. CGContextSetBlendMode (context, kCGBlendModeNormal);
  206287. rgbColourSpace = CGColorSpaceCreateDeviceRGB();
  206288. greyColourSpace = CGColorSpaceCreateDeviceGray();
  206289. gradientCallbacks.version = 0;
  206290. gradientCallbacks.evaluate = gradientCallback;
  206291. gradientCallbacks.releaseInfo = 0;
  206292. state = new SavedState();
  206293. }
  206294. ~CoreGraphicsContext()
  206295. {
  206296. CGContextRestoreGState (context);
  206297. CGContextRelease (context);
  206298. CGColorSpaceRelease (rgbColourSpace);
  206299. CGColorSpaceRelease (greyColourSpace);
  206300. }
  206301. bool isVectorDevice() const { return false; }
  206302. void setOrigin (int x, int y)
  206303. {
  206304. CGContextTranslateCTM (context, x, -y);
  206305. }
  206306. bool clipToRectangle (const Rectangle& r)
  206307. {
  206308. CGContextClipToRect (context, CGRectMake (r.getX(), flipHeight - r.getBottom(), r.getWidth(), r.getHeight()));
  206309. return ! isClipEmpty();
  206310. }
  206311. bool clipToRectangleList (const RectangleList& clipRegion)
  206312. {
  206313. if (clipRegion.isEmpty())
  206314. {
  206315. CGContextClipToRect (context, CGRectMake (0, 0, 0, 0));
  206316. return false;
  206317. }
  206318. else
  206319. {
  206320. const int numRects = clipRegion.getNumRectangles();
  206321. HeapBlock <CGRect> rects (numRects);
  206322. for (int i = 0; i < numRects; ++i)
  206323. {
  206324. const Rectangle& r = clipRegion.getRectangle(i);
  206325. rects[i] = CGRectMake (r.getX(), flipHeight - r.getBottom(), r.getWidth(), r.getHeight());
  206326. }
  206327. CGContextClipToRects (context, rects, numRects);
  206328. return ! isClipEmpty();
  206329. }
  206330. }
  206331. void excludeClipRectangle (const Rectangle& r)
  206332. {
  206333. RectangleList remaining (getClipBounds());
  206334. remaining.subtract (r);
  206335. clipToRectangleList (remaining);
  206336. }
  206337. void clipToPath (const Path& path, const AffineTransform& transform)
  206338. {
  206339. createPath (path, transform);
  206340. CGContextClip (context);
  206341. }
  206342. void clipToImageAlpha (const Image& sourceImage, const Rectangle& srcClip, const AffineTransform& transform)
  206343. {
  206344. if (! transform.isSingularity())
  206345. {
  206346. Image* singleChannelImage = createAlphaChannelImage (sourceImage);
  206347. CGImageRef image = CoreGraphicsImage::createImage (*singleChannelImage, true, greyColourSpace);
  206348. flip();
  206349. AffineTransform t (AffineTransform::scale (1.0f, -1.0f).translated (0, sourceImage.getHeight()).followedBy (transform));
  206350. applyTransform (t);
  206351. CGRect r = CGRectMake (0, 0, sourceImage.getWidth(), sourceImage.getHeight());
  206352. CGContextClipToMask (context, r, image);
  206353. applyTransform (t.inverted());
  206354. flip();
  206355. CGImageRelease (image);
  206356. deleteAlphaChannelImage (sourceImage, singleChannelImage);
  206357. }
  206358. }
  206359. bool clipRegionIntersects (const Rectangle& r)
  206360. {
  206361. return getClipBounds().intersects (r);
  206362. }
  206363. const Rectangle getClipBounds() const
  206364. {
  206365. CGRect bounds = CGRectIntegral (CGContextGetClipBoundingBox (context));
  206366. return Rectangle (roundToInt (bounds.origin.x),
  206367. roundToInt (flipHeight - (bounds.origin.y + bounds.size.height)),
  206368. roundToInt (bounds.size.width),
  206369. roundToInt (bounds.size.height));
  206370. }
  206371. bool isClipEmpty() const
  206372. {
  206373. return CGRectIsEmpty (CGContextGetClipBoundingBox (context));
  206374. }
  206375. void saveState()
  206376. {
  206377. CGContextSaveGState (context);
  206378. stateStack.add (new SavedState (*state));
  206379. }
  206380. void restoreState()
  206381. {
  206382. CGContextRestoreGState (context);
  206383. SavedState* const top = stateStack.getLast();
  206384. if (top != 0)
  206385. {
  206386. state = top;
  206387. stateStack.removeLast (1, false);
  206388. }
  206389. else
  206390. {
  206391. jassertfalse // trying to pop with an empty stack!
  206392. }
  206393. }
  206394. void setFill (const FillType& fillType)
  206395. {
  206396. state->fillType = fillType;
  206397. if (fillType.isColour())
  206398. {
  206399. CGContextSetRGBFillColor (context, fillType.colour.getFloatRed(), fillType.colour.getFloatGreen(),
  206400. fillType.colour.getFloatBlue(), fillType.colour.getFloatAlpha());
  206401. CGContextSetAlpha (context, 1.0f);
  206402. }
  206403. }
  206404. void setOpacity (float newOpacity)
  206405. {
  206406. state->fillType.setOpacity (newOpacity);
  206407. setFill (state->fillType);
  206408. }
  206409. void setInterpolationQuality (Graphics::ResamplingQuality quality)
  206410. {
  206411. CGContextSetInterpolationQuality (context, quality == Graphics::lowResamplingQuality
  206412. ? kCGInterpolationLow
  206413. : kCGInterpolationHigh);
  206414. }
  206415. void fillRect (const Rectangle& r, const bool replaceExistingContents)
  206416. {
  206417. CGRect cgRect = CGRectMake (r.getX(), flipHeight - r.getBottom(), r.getWidth(), r.getHeight());
  206418. if (replaceExistingContents)
  206419. {
  206420. #if MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_5
  206421. CGContextClearRect (context, cgRect);
  206422. #else
  206423. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
  206424. if (CGContextDrawLinearGradient == 0) // (just a way of checking whether we're running in 10.5 or later)
  206425. CGContextClearRect (context, cgRect);
  206426. else
  206427. #endif
  206428. CGContextSetBlendMode (context, kCGBlendModeCopy);
  206429. #endif
  206430. fillRect (r, false);
  206431. CGContextSetBlendMode (context, kCGBlendModeNormal);
  206432. }
  206433. else
  206434. {
  206435. if (state->fillType.isColour())
  206436. {
  206437. CGContextFillRect (context, cgRect);
  206438. }
  206439. else if (state->fillType.isGradient())
  206440. {
  206441. CGContextSaveGState (context);
  206442. CGContextClipToRect (context, cgRect);
  206443. drawGradient();
  206444. CGContextRestoreGState (context);
  206445. }
  206446. else
  206447. {
  206448. CGContextSaveGState (context);
  206449. CGContextClipToRect (context, cgRect);
  206450. drawImage (*(state->fillType.image), state->fillType.image->getBounds(), state->fillType.transform, true);
  206451. CGContextRestoreGState (context);
  206452. }
  206453. }
  206454. }
  206455. void fillPath (const Path& path, const AffineTransform& transform)
  206456. {
  206457. CGContextSaveGState (context);
  206458. if (state->fillType.isColour())
  206459. {
  206460. flip();
  206461. applyTransform (transform);
  206462. createPath (path);
  206463. if (path.isUsingNonZeroWinding())
  206464. CGContextFillPath (context);
  206465. else
  206466. CGContextEOFillPath (context);
  206467. }
  206468. else
  206469. {
  206470. createPath (path, transform);
  206471. if (path.isUsingNonZeroWinding())
  206472. CGContextClip (context);
  206473. else
  206474. CGContextEOClip (context);
  206475. if (state->fillType.isGradient())
  206476. drawGradient();
  206477. else
  206478. drawImage (*(state->fillType.image), state->fillType.image->getBounds(), state->fillType.transform, true);
  206479. }
  206480. CGContextRestoreGState (context);
  206481. }
  206482. void drawImage (const Image& sourceImage, const Rectangle& srcClip,
  206483. const AffineTransform& transform, const bool fillEntireClipAsTiles)
  206484. {
  206485. jassert (sourceImage.getBounds().contains (srcClip));
  206486. CGImageRef fullImage = CoreGraphicsImage::createImage (sourceImage, false, rgbColourSpace);
  206487. CGImageRef image = fullImage;
  206488. if (srcClip != sourceImage.getBounds())
  206489. {
  206490. image = CGImageCreateWithImageInRect (fullImage, CGRectMake (srcClip.getX(), srcClip.getY(),
  206491. srcClip.getWidth(), srcClip.getHeight()));
  206492. CGImageRelease (fullImage);
  206493. }
  206494. CGContextSaveGState (context);
  206495. CGContextSetAlpha (context, state->fillType.getOpacity());
  206496. flip();
  206497. applyTransform (AffineTransform::scale (1.0f, -1.0f).translated (0, srcClip.getHeight()).followedBy (transform));
  206498. CGRect imageRect = CGRectMake (0, 0, srcClip.getWidth(), srcClip.getHeight());
  206499. if (fillEntireClipAsTiles)
  206500. {
  206501. #if JUCE_IPHONE || (MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5)
  206502. CGContextDrawTiledImage (context, imageRect, image);
  206503. #else
  206504. #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
  206505. if (CGContextDrawTiledImage != 0)
  206506. CGContextDrawTiledImage (context, imageRect, image);
  206507. else
  206508. #endif
  206509. {
  206510. // Fallback to manually doing a tiled fill on 10.4
  206511. CGRect clip = CGRectIntegral (CGContextGetClipBoundingBox (context));
  206512. const int iw = srcClip.getWidth();
  206513. const int ih = srcClip.getHeight();
  206514. int x = 0, y = 0;
  206515. while (x > clip.origin.x) x -= iw;
  206516. while (y > clip.origin.y) y -= ih;
  206517. const int right = (int) (clip.origin.x + clip.size.width);
  206518. const int bottom = (int) (clip.origin.y + clip.size.height);
  206519. while (y < bottom)
  206520. {
  206521. for (int x2 = x; x2 < right; x2 += iw)
  206522. CGContextDrawImage (context, CGRectMake (x2, y, iw, ih), image);
  206523. y += ih;
  206524. }
  206525. }
  206526. #endif
  206527. }
  206528. else
  206529. {
  206530. CGContextDrawImage (context, imageRect, image);
  206531. }
  206532. CGImageRelease (image); // (This causes a memory bug in iPhone sim 3.0 - try upgrading to a later version if you hit this)
  206533. CGContextRestoreGState (context);
  206534. }
  206535. void drawLine (double x1, double y1, double x2, double y2)
  206536. {
  206537. CGContextSetLineCap (context, kCGLineCapSquare);
  206538. CGContextSetLineWidth (context, 1.0f);
  206539. CGContextSetRGBStrokeColor (context,
  206540. state->fillType.colour.getFloatRed(), state->fillType.colour.getFloatGreen(),
  206541. state->fillType.colour.getFloatBlue(), state->fillType.colour.getFloatAlpha());
  206542. CGPoint line[] = { { (float) x1 + 0.5f, flipHeight - ((float) y1 + 0.5f) },
  206543. { (float) x2 + 0.5f, flipHeight - ((float) y2 + 0.5f) } };
  206544. CGContextStrokeLineSegments (context, line, 1);
  206545. }
  206546. void drawVerticalLine (const int x, double top, double bottom)
  206547. {
  206548. #if MAC_OS_X_VERSION_MIN_REQUIRED > MAC_OS_X_VERSION_10_5
  206549. CGContextFillRect (context, CGRectMake (x, flipHeight - (float) bottom, 1.0f, (float) (bottom - top)));
  206550. #else
  206551. // On Leopard, unless both co-ordinates are non-integer, it disables anti-aliasing, so nudge
  206552. // the x co-ord slightly to trick it..
  206553. CGContextFillRect (context, CGRectMake (x + 1.0f / 256.0f, flipHeight - (float) bottom, 1.0f + 1.0f / 256.0f, (float) (bottom - top)));
  206554. #endif
  206555. }
  206556. void drawHorizontalLine (const int y, double left, double right)
  206557. {
  206558. #if MAC_OS_X_VERSION_MIN_REQUIRED > MAC_OS_X_VERSION_10_5
  206559. CGContextFillRect (context, CGRectMake ((float) left, flipHeight - (y + 1.0f), (float) (right - left), 1.0f));
  206560. #else
  206561. // On Leopard, unless both co-ordinates are non-integer, it disables anti-aliasing, so nudge
  206562. // the x co-ord slightly to trick it..
  206563. CGContextFillRect (context, CGRectMake ((float) left, flipHeight - (y + (1.0f + 1.0f / 256.0f)), (float) (right - left), 1.0f + 1.0f / 256.0f));
  206564. #endif
  206565. }
  206566. void setFont (const Font& newFont)
  206567. {
  206568. if (state->font != newFont)
  206569. {
  206570. state->fontRef = 0;
  206571. state->font = newFont;
  206572. MacTypeface* mf = dynamic_cast <MacTypeface*> ((Typeface*) state->font.getTypeface());
  206573. if (mf != 0)
  206574. {
  206575. state->fontRef = mf->fontRef;
  206576. CGContextSetFont (context, state->fontRef);
  206577. CGContextSetFontSize (context, state->font.getHeight() * mf->fontHeightToCGSizeFactor);
  206578. state->fontTransform = mf->renderingTransform;
  206579. state->fontTransform.a *= state->font.getHorizontalScale();
  206580. CGContextSetTextMatrix (context, state->fontTransform);
  206581. }
  206582. }
  206583. }
  206584. const Font getFont()
  206585. {
  206586. return state->font;
  206587. }
  206588. void drawGlyph (int glyphNumber, const AffineTransform& transform)
  206589. {
  206590. if (state->fontRef != 0 && state->fillType.isColour())
  206591. {
  206592. if (transform.isOnlyTranslation())
  206593. {
  206594. CGGlyph g = glyphNumber;
  206595. CGContextShowGlyphsAtPoint (context, transform.getTranslationX(),
  206596. flipHeight - roundToInt (transform.getTranslationY()), &g, 1);
  206597. }
  206598. else
  206599. {
  206600. CGContextSaveGState (context);
  206601. flip();
  206602. applyTransform (transform);
  206603. CGAffineTransform t = state->fontTransform;
  206604. t.d = -t.d;
  206605. CGContextSetTextMatrix (context, t);
  206606. CGGlyph g = glyphNumber;
  206607. CGContextShowGlyphsAtPoint (context, 0, 0, &g, 1);
  206608. CGContextSetTextMatrix (context, state->fontTransform);
  206609. CGContextRestoreGState (context);
  206610. }
  206611. }
  206612. else
  206613. {
  206614. Path p;
  206615. Font& f = state->font;
  206616. f.getTypeface()->getOutlineForGlyph (glyphNumber, p);
  206617. fillPath (p, AffineTransform::scale (f.getHeight() * f.getHorizontalScale(), f.getHeight())
  206618. .followedBy (transform));
  206619. }
  206620. }
  206621. private:
  206622. CGContextRef context;
  206623. const float flipHeight;
  206624. CGColorSpaceRef rgbColourSpace, greyColourSpace;
  206625. CGFunctionCallbacks gradientCallbacks;
  206626. struct SavedState
  206627. {
  206628. SavedState()
  206629. : font (1.0f), fontRef (0), fontTransform (CGAffineTransformIdentity)
  206630. {
  206631. }
  206632. SavedState (const SavedState& other)
  206633. : fillType (other.fillType), font (other.font), fontRef (other.fontRef),
  206634. fontTransform (other.fontTransform)
  206635. {
  206636. }
  206637. ~SavedState()
  206638. {
  206639. }
  206640. FillType fillType;
  206641. Font font;
  206642. CGFontRef fontRef;
  206643. CGAffineTransform fontTransform;
  206644. };
  206645. ScopedPointer <SavedState> state;
  206646. OwnedArray <SavedState> stateStack;
  206647. HeapBlock <PixelARGB> gradientLookupTable;
  206648. int numGradientLookupEntries;
  206649. static void gradientCallback (void* info, const CGFloat* inData, CGFloat* outData)
  206650. {
  206651. const CoreGraphicsContext* const g = (const CoreGraphicsContext*) info;
  206652. const int index = roundToInt (g->numGradientLookupEntries * inData[0]);
  206653. PixelARGB colour (g->gradientLookupTable [jlimit (0, g->numGradientLookupEntries, index)]);
  206654. colour.unpremultiply();
  206655. outData[0] = colour.getRed() / 255.0f;
  206656. outData[1] = colour.getGreen() / 255.0f;
  206657. outData[2] = colour.getBlue() / 255.0f;
  206658. outData[3] = colour.getAlpha() / 255.0f;
  206659. }
  206660. CGShadingRef createGradient (const AffineTransform& transform, ColourGradient gradient)
  206661. {
  206662. numGradientLookupEntries = gradient.createLookupTable (transform, gradientLookupTable);
  206663. --numGradientLookupEntries;
  206664. CGShadingRef result = 0;
  206665. CGFunctionRef function = CGFunctionCreate ((void*) this, 1, 0, 4, 0, &gradientCallbacks);
  206666. CGPoint p1 (CGPointMake (gradient.x1, gradient.y1));
  206667. if (gradient.isRadial)
  206668. {
  206669. result = CGShadingCreateRadial (rgbColourSpace, p1, 0,
  206670. p1, hypotf (gradient.x1 - gradient.x2, gradient.y1 - gradient.y2),
  206671. function, true, true);
  206672. }
  206673. else
  206674. {
  206675. result = CGShadingCreateAxial (rgbColourSpace, p1,
  206676. CGPointMake (gradient.x2, gradient.y2),
  206677. function, true, true);
  206678. }
  206679. CGFunctionRelease (function);
  206680. return result;
  206681. }
  206682. void drawGradient()
  206683. {
  206684. flip();
  206685. applyTransform (state->fillType.transform);
  206686. CGContextSetInterpolationQuality (context, kCGInterpolationDefault); // (This is required for 10.4, where there's a crash if
  206687. // you draw a gradient with high quality interp enabled).
  206688. CGShadingRef shading = createGradient (state->fillType.transform, *(state->fillType.gradient));
  206689. CGContextSetAlpha (context, state->fillType.getOpacity());
  206690. CGContextDrawShading (context, shading);
  206691. CGShadingRelease (shading);
  206692. }
  206693. void createPath (const Path& path) const
  206694. {
  206695. CGContextBeginPath (context);
  206696. Path::Iterator i (path);
  206697. while (i.next())
  206698. {
  206699. switch (i.elementType)
  206700. {
  206701. case Path::Iterator::startNewSubPath:
  206702. CGContextMoveToPoint (context, i.x1, i.y1);
  206703. break;
  206704. case Path::Iterator::lineTo:
  206705. CGContextAddLineToPoint (context, i.x1, i.y1);
  206706. break;
  206707. case Path::Iterator::quadraticTo:
  206708. CGContextAddQuadCurveToPoint (context, i.x1, i.y1, i.x2, i.y2);
  206709. break;
  206710. case Path::Iterator::cubicTo:
  206711. CGContextAddCurveToPoint (context, i.x1, i.y1, i.x2, i.y2, i.x3, i.y3);
  206712. break;
  206713. case Path::Iterator::closePath:
  206714. CGContextClosePath (context); break;
  206715. default:
  206716. jassertfalse
  206717. break;
  206718. }
  206719. }
  206720. }
  206721. void createPath (const Path& path, const AffineTransform& transform) const
  206722. {
  206723. CGContextBeginPath (context);
  206724. Path::Iterator i (path);
  206725. while (i.next())
  206726. {
  206727. switch (i.elementType)
  206728. {
  206729. case Path::Iterator::startNewSubPath:
  206730. transform.transformPoint (i.x1, i.y1);
  206731. CGContextMoveToPoint (context, i.x1, flipHeight - i.y1);
  206732. break;
  206733. case Path::Iterator::lineTo:
  206734. transform.transformPoint (i.x1, i.y1);
  206735. CGContextAddLineToPoint (context, i.x1, flipHeight - i.y1);
  206736. break;
  206737. case Path::Iterator::quadraticTo:
  206738. transform.transformPoint (i.x1, i.y1);
  206739. transform.transformPoint (i.x2, i.y2);
  206740. CGContextAddQuadCurveToPoint (context, i.x1, flipHeight - i.y1, i.x2, flipHeight - i.y2);
  206741. break;
  206742. case Path::Iterator::cubicTo:
  206743. transform.transformPoint (i.x1, i.y1);
  206744. transform.transformPoint (i.x2, i.y2);
  206745. transform.transformPoint (i.x3, i.y3);
  206746. CGContextAddCurveToPoint (context, i.x1, flipHeight - i.y1, i.x2, flipHeight - i.y2, i.x3, flipHeight - i.y3);
  206747. break;
  206748. case Path::Iterator::closePath:
  206749. CGContextClosePath (context); break;
  206750. default:
  206751. jassertfalse
  206752. break;
  206753. }
  206754. }
  206755. }
  206756. static Image* createAlphaChannelImage (const Image& im)
  206757. {
  206758. if (im.getFormat() == Image::SingleChannel)
  206759. return const_cast <Image*> (&im);
  206760. return im.createCopyOfAlphaChannel();
  206761. }
  206762. static void deleteAlphaChannelImage (const Image& im, Image* const alphaIm)
  206763. {
  206764. if (im.getFormat() != Image::SingleChannel)
  206765. delete alphaIm;
  206766. }
  206767. void flip() const
  206768. {
  206769. CGContextConcatCTM (context, CGAffineTransformMake (1, 0, 0, -1, 0, flipHeight));
  206770. }
  206771. void applyTransform (const AffineTransform& transform) const
  206772. {
  206773. CGAffineTransform t;
  206774. t.a = transform.mat00;
  206775. t.b = transform.mat10;
  206776. t.c = transform.mat01;
  206777. t.d = transform.mat11;
  206778. t.tx = transform.mat02;
  206779. t.ty = transform.mat12;
  206780. CGContextConcatCTM (context, t);
  206781. }
  206782. float flipY (float y) const
  206783. {
  206784. return flipHeight - y;
  206785. }
  206786. };
  206787. LowLevelGraphicsContext* CoreGraphicsImage::createLowLevelContext()
  206788. {
  206789. return new CoreGraphicsContext (context, imageHeight);
  206790. }
  206791. #endif
  206792. /********* End of inlined file: juce_mac_CoreGraphicsContext.mm *********/
  206793. /********* Start of inlined file: juce_mac_NSViewComponentPeer.mm *********/
  206794. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  206795. // compiled on its own).
  206796. #if JUCE_INCLUDED_FILE
  206797. class NSViewComponentPeer;
  206798. END_JUCE_NAMESPACE
  206799. #define JuceNSView MakeObjCClassName(JuceNSView)
  206800. @interface JuceNSView : NSView
  206801. {
  206802. @public
  206803. NSViewComponentPeer* owner;
  206804. NSNotificationCenter* notificationCenter;
  206805. }
  206806. - (JuceNSView*) initWithOwner: (NSViewComponentPeer*) owner withFrame: (NSRect) frame;
  206807. - (void) dealloc;
  206808. - (BOOL) isOpaque;
  206809. - (void) drawRect: (NSRect) r;
  206810. - (void) mouseDown: (NSEvent*) ev;
  206811. - (void) asyncMouseDown: (NSEvent*) ev;
  206812. - (void) mouseUp: (NSEvent*) ev;
  206813. - (void) asyncMouseUp: (NSEvent*) ev;
  206814. - (void) mouseDragged: (NSEvent*) ev;
  206815. - (void) mouseMoved: (NSEvent*) ev;
  206816. - (void) mouseEntered: (NSEvent*) ev;
  206817. - (void) mouseExited: (NSEvent*) ev;
  206818. - (void) rightMouseDown: (NSEvent*) ev;
  206819. - (void) rightMouseDragged: (NSEvent*) ev;
  206820. - (void) rightMouseUp: (NSEvent*) ev;
  206821. - (void) otherMouseDown: (NSEvent*) ev;
  206822. - (void) otherMouseDragged: (NSEvent*) ev;
  206823. - (void) otherMouseUp: (NSEvent*) ev;
  206824. - (void) scrollWheel: (NSEvent*) ev;
  206825. - (BOOL) acceptsFirstMouse: (NSEvent*) ev;
  206826. - (void) frameChanged: (NSNotification*) n;
  206827. - (void) viewDidMoveToWindow;
  206828. - (void) keyDown: (NSEvent*) ev;
  206829. - (void) keyUp: (NSEvent*) ev;
  206830. - (void) flagsChanged: (NSEvent*) ev;
  206831. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
  206832. - (BOOL) performKeyEquivalent: (NSEvent*) ev;
  206833. #endif
  206834. - (BOOL) becomeFirstResponder;
  206835. - (BOOL) resignFirstResponder;
  206836. - (BOOL) acceptsFirstResponder;
  206837. - (void) asyncRepaint: (id) rect;
  206838. - (NSArray*) getSupportedDragTypes;
  206839. - (BOOL) sendDragCallback: (int) type sender: (id <NSDraggingInfo>) sender;
  206840. - (NSDragOperation) draggingEntered: (id <NSDraggingInfo>) sender;
  206841. - (NSDragOperation) draggingUpdated: (id <NSDraggingInfo>) sender;
  206842. - (void) draggingEnded: (id <NSDraggingInfo>) sender;
  206843. - (void) draggingExited: (id <NSDraggingInfo>) sender;
  206844. - (BOOL) prepareForDragOperation: (id <NSDraggingInfo>) sender;
  206845. - (BOOL) performDragOperation: (id <NSDraggingInfo>) sender;
  206846. - (void) concludeDragOperation: (id <NSDraggingInfo>) sender;
  206847. @end
  206848. #define JuceNSWindow MakeObjCClassName(JuceNSWindow)
  206849. #if defined (MAC_OS_X_VERSION_10_6) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
  206850. @interface JuceNSWindow : NSWindow <NSWindowDelegate>
  206851. #else
  206852. @interface JuceNSWindow : NSWindow
  206853. #endif
  206854. {
  206855. @private
  206856. NSViewComponentPeer* owner;
  206857. bool isZooming;
  206858. }
  206859. - (void) setOwner: (NSViewComponentPeer*) owner;
  206860. - (BOOL) canBecomeKeyWindow;
  206861. - (void) becomeKeyWindow;
  206862. - (BOOL) windowShouldClose: (id) window;
  206863. - (NSRect) constrainFrameRect: (NSRect) frameRect toScreen: (NSScreen*) screen;
  206864. - (NSSize) windowWillResize: (NSWindow*) window toSize: (NSSize) proposedFrameSize;
  206865. - (void) zoom: (id) sender;
  206866. @end
  206867. BEGIN_JUCE_NAMESPACE
  206868. class NSViewComponentPeer : public ComponentPeer
  206869. {
  206870. public:
  206871. NSViewComponentPeer (Component* const component,
  206872. const int windowStyleFlags,
  206873. NSView* viewToAttachTo);
  206874. ~NSViewComponentPeer();
  206875. void* getNativeHandle() const;
  206876. void setVisible (bool shouldBeVisible);
  206877. void setTitle (const String& title);
  206878. void setPosition (int x, int y);
  206879. void setSize (int w, int h);
  206880. void setBounds (int x, int y, int w, int h, const bool isNowFullScreen);
  206881. void getBounds (int& x, int& y, int& w, int& h, const bool global) const;
  206882. void getBounds (int& x, int& y, int& w, int& h) const;
  206883. int getScreenX() const;
  206884. int getScreenY() const;
  206885. void relativePositionToGlobal (int& x, int& y);
  206886. void globalPositionToRelative (int& x, int& y);
  206887. void setMinimised (bool shouldBeMinimised);
  206888. bool isMinimised() const;
  206889. void setFullScreen (bool shouldBeFullScreen);
  206890. bool isFullScreen() const;
  206891. bool contains (int x, int y, bool trueIfInAChildWindow) const;
  206892. const BorderSize getFrameSize() const;
  206893. bool setAlwaysOnTop (bool alwaysOnTop);
  206894. void toFront (bool makeActiveWindow);
  206895. void toBehind (ComponentPeer* other);
  206896. void setIcon (const Image& newIcon);
  206897. const StringArray getAvailableRenderingEngines() throw();
  206898. int getCurrentRenderingEngine() throw();
  206899. void setCurrentRenderingEngine (int index) throw();
  206900. virtual void redirectMouseDown (NSEvent* ev);
  206901. virtual void redirectMouseUp (NSEvent* ev);
  206902. virtual void redirectMouseDrag (NSEvent* ev);
  206903. virtual void redirectMouseMove (NSEvent* ev);
  206904. virtual void redirectMouseEnter (NSEvent* ev);
  206905. virtual void redirectMouseExit (NSEvent* ev);
  206906. virtual void redirectMouseWheel (NSEvent* ev);
  206907. bool handleKeyEvent (NSEvent* ev, bool isKeyDown);
  206908. virtual bool redirectKeyDown (NSEvent* ev);
  206909. virtual bool redirectKeyUp (NSEvent* ev);
  206910. virtual void redirectModKeyChange (NSEvent* ev);
  206911. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
  206912. virtual bool redirectPerformKeyEquivalent (NSEvent* ev);
  206913. #endif
  206914. virtual BOOL sendDragCallback (int type, id <NSDraggingInfo> sender);
  206915. virtual bool isOpaque();
  206916. virtual void drawRect (NSRect r);
  206917. virtual bool canBecomeKeyWindow();
  206918. virtual bool windowShouldClose();
  206919. virtual void redirectMovedOrResized();
  206920. virtual void viewMovedToWindow();
  206921. virtual NSRect constrainRect (NSRect r);
  206922. static void showArrowCursorIfNeeded();
  206923. virtual void viewFocusGain();
  206924. virtual void viewFocusLoss();
  206925. bool isFocused() const;
  206926. void grabFocus();
  206927. void textInputRequired (int x, int y);
  206928. void repaint (int x, int y, int w, int h);
  206929. void performAnyPendingRepaintsNow();
  206930. juce_UseDebuggingNewOperator
  206931. NSWindow* window;
  206932. JuceNSView* view;
  206933. bool isSharedWindow, fullScreen, insideDrawRect, usingCoreGraphics, recursiveToFrontCall;
  206934. };
  206935. END_JUCE_NAMESPACE
  206936. @implementation JuceNSView
  206937. - (JuceNSView*) initWithOwner: (NSViewComponentPeer*) owner_
  206938. withFrame: (NSRect) frame
  206939. {
  206940. [super initWithFrame: frame];
  206941. owner = owner_;
  206942. notificationCenter = [NSNotificationCenter defaultCenter];
  206943. [notificationCenter addObserver: self
  206944. selector: @selector (frameChanged:)
  206945. name: NSViewFrameDidChangeNotification
  206946. object: self];
  206947. if (! owner_->isSharedWindow)
  206948. {
  206949. [notificationCenter addObserver: self
  206950. selector: @selector (frameChanged:)
  206951. name: NSWindowDidMoveNotification
  206952. object: owner_->window];
  206953. }
  206954. [self registerForDraggedTypes: [self getSupportedDragTypes]];
  206955. return self;
  206956. }
  206957. - (void) dealloc
  206958. {
  206959. [notificationCenter removeObserver: self];
  206960. [super dealloc];
  206961. }
  206962. - (void) drawRect: (NSRect) r
  206963. {
  206964. if (owner != 0)
  206965. owner->drawRect (r);
  206966. }
  206967. - (BOOL) isOpaque
  206968. {
  206969. return owner == 0 || owner->isOpaque();
  206970. }
  206971. - (void) mouseDown: (NSEvent*) ev
  206972. {
  206973. // In some host situations, the host will stop modal loops from working
  206974. // correctly if they're called from a mouse event, so we'll trigger
  206975. // the event asynchronously..
  206976. if (JUCEApplication::getInstance() == 0)
  206977. [self performSelectorOnMainThread: @selector (asyncMouseDown:)
  206978. withObject: ev
  206979. waitUntilDone: NO];
  206980. else
  206981. [self asyncMouseDown: ev];
  206982. }
  206983. - (void) asyncMouseDown: (NSEvent*) ev
  206984. {
  206985. if (owner != 0)
  206986. owner->redirectMouseDown (ev);
  206987. }
  206988. - (void) mouseUp: (NSEvent*) ev
  206989. {
  206990. // In some host situations, the host will stop modal loops from working
  206991. // correctly if they're called from a mouse event, so we'll trigger
  206992. // the event asynchronously..
  206993. if (JUCEApplication::getInstance() == 0)
  206994. [self performSelectorOnMainThread: @selector (asyncMouseUp:)
  206995. withObject: ev
  206996. waitUntilDone: NO];
  206997. else
  206998. [self asyncMouseUp: ev];
  206999. }
  207000. - (void) asyncMouseUp: (NSEvent*) ev
  207001. {
  207002. if (owner != 0)
  207003. owner->redirectMouseUp (ev);
  207004. }
  207005. - (void) mouseDragged: (NSEvent*) ev
  207006. {
  207007. if (owner != 0)
  207008. owner->redirectMouseDrag (ev);
  207009. }
  207010. - (void) mouseMoved: (NSEvent*) ev
  207011. {
  207012. if (owner != 0)
  207013. owner->redirectMouseMove (ev);
  207014. }
  207015. - (void) mouseEntered: (NSEvent*) ev
  207016. {
  207017. if (owner != 0)
  207018. owner->redirectMouseEnter (ev);
  207019. }
  207020. - (void) mouseExited: (NSEvent*) ev
  207021. {
  207022. if (owner != 0)
  207023. owner->redirectMouseExit (ev);
  207024. }
  207025. - (void) rightMouseDown: (NSEvent*) ev
  207026. {
  207027. [self mouseDown: ev];
  207028. }
  207029. - (void) rightMouseDragged: (NSEvent*) ev
  207030. {
  207031. [self mouseDragged: ev];
  207032. }
  207033. - (void) rightMouseUp: (NSEvent*) ev
  207034. {
  207035. [self mouseUp: ev];
  207036. }
  207037. - (void) otherMouseDown: (NSEvent*) ev
  207038. {
  207039. [self mouseDown: ev];
  207040. }
  207041. - (void) otherMouseDragged: (NSEvent*) ev
  207042. {
  207043. [self mouseDragged: ev];
  207044. }
  207045. - (void) otherMouseUp: (NSEvent*) ev
  207046. {
  207047. [self mouseUp: ev];
  207048. }
  207049. - (void) scrollWheel: (NSEvent*) ev
  207050. {
  207051. if (owner != 0)
  207052. owner->redirectMouseWheel (ev);
  207053. }
  207054. - (BOOL) acceptsFirstMouse: (NSEvent*) ev
  207055. {
  207056. return YES;
  207057. }
  207058. - (void) frameChanged: (NSNotification*) n
  207059. {
  207060. if (owner != 0)
  207061. owner->redirectMovedOrResized();
  207062. }
  207063. - (void) viewDidMoveToWindow
  207064. {
  207065. if (owner != 0)
  207066. owner->viewMovedToWindow();
  207067. }
  207068. - (void) asyncRepaint: (id) rect
  207069. {
  207070. NSRect* r = (NSRect*) [((NSData*) rect) bytes];
  207071. [self setNeedsDisplayInRect: *r];
  207072. }
  207073. - (void) keyDown: (NSEvent*) ev
  207074. {
  207075. if (owner == 0 || ! owner->redirectKeyDown (ev))
  207076. [super keyDown: ev];
  207077. }
  207078. - (void) keyUp: (NSEvent*) ev
  207079. {
  207080. if (owner == 0 || ! owner->redirectKeyUp (ev))
  207081. [super keyUp: ev];
  207082. }
  207083. - (void) flagsChanged: (NSEvent*) ev
  207084. {
  207085. if (owner != 0)
  207086. owner->redirectModKeyChange (ev);
  207087. }
  207088. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
  207089. - (BOOL) performKeyEquivalent: (NSEvent*) ev
  207090. {
  207091. if (owner != 0 && owner->redirectPerformKeyEquivalent (ev))
  207092. return true;
  207093. return [super performKeyEquivalent: ev];
  207094. }
  207095. #endif
  207096. - (BOOL) becomeFirstResponder
  207097. {
  207098. if (owner != 0)
  207099. owner->viewFocusGain();
  207100. return true;
  207101. }
  207102. - (BOOL) resignFirstResponder
  207103. {
  207104. if (owner != 0)
  207105. owner->viewFocusLoss();
  207106. return true;
  207107. }
  207108. - (BOOL) acceptsFirstResponder
  207109. {
  207110. return owner != 0 && owner->canBecomeKeyWindow();
  207111. }
  207112. - (NSArray*) getSupportedDragTypes
  207113. {
  207114. return [NSArray arrayWithObjects: NSFilenamesPboardType, /*NSFilesPromisePboardType, NSStringPboardType,*/ nil];
  207115. }
  207116. - (BOOL) sendDragCallback: (int) type sender: (id <NSDraggingInfo>) sender
  207117. {
  207118. return owner != 0 && owner->sendDragCallback (type, sender);
  207119. }
  207120. - (NSDragOperation) draggingEntered: (id <NSDraggingInfo>) sender
  207121. {
  207122. if ([self sendDragCallback: 0 sender: sender])
  207123. return NSDragOperationCopy | NSDragOperationMove | NSDragOperationGeneric;
  207124. else
  207125. return NSDragOperationNone;
  207126. }
  207127. - (NSDragOperation) draggingUpdated: (id <NSDraggingInfo>) sender
  207128. {
  207129. if ([self sendDragCallback: 0 sender: sender])
  207130. return NSDragOperationCopy | NSDragOperationMove | NSDragOperationGeneric;
  207131. else
  207132. return NSDragOperationNone;
  207133. }
  207134. - (void) draggingEnded: (id <NSDraggingInfo>) sender
  207135. {
  207136. [self sendDragCallback: 1 sender: sender];
  207137. }
  207138. - (void) draggingExited: (id <NSDraggingInfo>) sender
  207139. {
  207140. [self sendDragCallback: 1 sender: sender];
  207141. }
  207142. - (BOOL) prepareForDragOperation: (id <NSDraggingInfo>) sender
  207143. {
  207144. return YES;
  207145. }
  207146. - (BOOL) performDragOperation: (id <NSDraggingInfo>) sender
  207147. {
  207148. return [self sendDragCallback: 2 sender: sender];
  207149. }
  207150. - (void) concludeDragOperation: (id <NSDraggingInfo>) sender
  207151. {
  207152. }
  207153. @end
  207154. @implementation JuceNSWindow
  207155. - (void) setOwner: (NSViewComponentPeer*) owner_
  207156. {
  207157. owner = owner_;
  207158. isZooming = false;
  207159. }
  207160. - (BOOL) canBecomeKeyWindow
  207161. {
  207162. return owner != 0 && owner->canBecomeKeyWindow();
  207163. }
  207164. - (void) becomeKeyWindow
  207165. {
  207166. [super becomeKeyWindow];
  207167. if (owner != 0)
  207168. owner->grabFocus();
  207169. }
  207170. - (BOOL) windowShouldClose: (id) window
  207171. {
  207172. return owner == 0 || owner->windowShouldClose();
  207173. }
  207174. - (NSRect) constrainFrameRect: (NSRect) frameRect toScreen: (NSScreen*) screen
  207175. {
  207176. if (owner != 0)
  207177. frameRect = owner->constrainRect (frameRect);
  207178. return frameRect;
  207179. }
  207180. - (NSSize) windowWillResize: (NSWindow*) window toSize: (NSSize) proposedFrameSize
  207181. {
  207182. if (isZooming)
  207183. return proposedFrameSize;
  207184. NSRect frameRect = [self frame];
  207185. frameRect.origin.y -= proposedFrameSize.height - frameRect.size.height;
  207186. frameRect.size = proposedFrameSize;
  207187. if (owner != 0)
  207188. frameRect = owner->constrainRect (frameRect);
  207189. return frameRect.size;
  207190. }
  207191. - (void) zoom: (id) sender
  207192. {
  207193. isZooming = true;
  207194. [super zoom: sender];
  207195. isZooming = false;
  207196. }
  207197. - (void) windowWillMove: (NSNotification*) notification
  207198. {
  207199. if (JUCE_NAMESPACE::Component::getCurrentlyModalComponent() != 0
  207200. && owner->getComponent()->isCurrentlyBlockedByAnotherModalComponent()
  207201. && (owner->getStyleFlags() & JUCE_NAMESPACE::ComponentPeer::windowHasTitleBar) != 0)
  207202. JUCE_NAMESPACE::Component::getCurrentlyModalComponent()->inputAttemptWhenModal();
  207203. }
  207204. @end
  207205. BEGIN_JUCE_NAMESPACE
  207206. static ComponentPeer* currentlyFocusedPeer = 0;
  207207. static VoidArray keysCurrentlyDown;
  207208. bool KeyPress::isKeyCurrentlyDown (const int keyCode) throw()
  207209. {
  207210. if (keysCurrentlyDown.contains ((void*) keyCode))
  207211. return true;
  207212. if (keyCode >= 'A' && keyCode <= 'Z'
  207213. && keysCurrentlyDown.contains ((void*) (int) CharacterFunctions::toLowerCase ((tchar) keyCode)))
  207214. return true;
  207215. if (keyCode >= 'a' && keyCode <= 'z'
  207216. && keysCurrentlyDown.contains ((void*) (int) CharacterFunctions::toUpperCase ((tchar) keyCode)))
  207217. return true;
  207218. return false;
  207219. }
  207220. static int getKeyCodeFromEvent (NSEvent* ev)
  207221. {
  207222. const String unmodified (nsStringToJuce ([ev charactersIgnoringModifiers]));
  207223. int keyCode = unmodified[0];
  207224. if (keyCode == 0x19) // (backwards-tab)
  207225. keyCode = '\t';
  207226. else if (keyCode == 0x03) // (enter)
  207227. keyCode = '\r';
  207228. return keyCode;
  207229. }
  207230. static int currentModifiers = 0;
  207231. static void updateModifiers (NSEvent* e)
  207232. {
  207233. int m = currentModifiers & ~(ModifierKeys::shiftModifier | ModifierKeys::ctrlModifier
  207234. | ModifierKeys::altModifier | ModifierKeys::commandModifier);
  207235. if (([e modifierFlags] & NSShiftKeyMask) != 0)
  207236. m |= ModifierKeys::shiftModifier;
  207237. if (([e modifierFlags] & NSControlKeyMask) != 0)
  207238. m |= ModifierKeys::ctrlModifier;
  207239. if (([e modifierFlags] & NSAlternateKeyMask) != 0)
  207240. m |= ModifierKeys::altModifier;
  207241. if (([e modifierFlags] & NSCommandKeyMask) != 0)
  207242. m |= ModifierKeys::commandModifier;
  207243. currentModifiers = m;
  207244. }
  207245. static void updateKeysDown (NSEvent* ev, bool isKeyDown)
  207246. {
  207247. updateModifiers (ev);
  207248. int keyCode = getKeyCodeFromEvent (ev);
  207249. if (keyCode != 0)
  207250. {
  207251. if (isKeyDown)
  207252. keysCurrentlyDown.addIfNotAlreadyThere ((void*) keyCode);
  207253. else
  207254. keysCurrentlyDown.removeValue ((void*) keyCode);
  207255. }
  207256. }
  207257. const ModifierKeys ModifierKeys::getCurrentModifiersRealtime() throw()
  207258. {
  207259. return ModifierKeys (currentModifiers);
  207260. }
  207261. void ModifierKeys::updateCurrentModifiers() throw()
  207262. {
  207263. currentModifierFlags = currentModifiers;
  207264. }
  207265. static int64 getMouseTime (NSEvent* e)
  207266. {
  207267. return (Time::currentTimeMillis() - Time::getMillisecondCounter())
  207268. + (int64) ([e timestamp] * 1000.0);
  207269. }
  207270. static void getMousePos (NSEvent* e, NSView* view, int& x, int& y)
  207271. {
  207272. NSPoint p = [view convertPoint: [e locationInWindow] fromView: nil];
  207273. x = roundToInt (p.x);
  207274. y = roundToInt ([view frame].size.height - p.y);
  207275. }
  207276. static int getModifierForButtonNumber (const NSInteger num)
  207277. {
  207278. return num == 0 ? ModifierKeys::leftButtonModifier
  207279. : (num == 1 ? ModifierKeys::rightButtonModifier
  207280. : (num == 2 ? ModifierKeys::middleButtonModifier : 0));
  207281. }
  207282. NSViewComponentPeer::NSViewComponentPeer (Component* const component_,
  207283. const int windowStyleFlags,
  207284. NSView* viewToAttachTo)
  207285. : ComponentPeer (component_, windowStyleFlags),
  207286. window (0),
  207287. view (0),
  207288. isSharedWindow (viewToAttachTo != 0),
  207289. fullScreen (false),
  207290. insideDrawRect (false),
  207291. #if USE_COREGRAPHICS_RENDERING
  207292. usingCoreGraphics (true),
  207293. #else
  207294. usingCoreGraphics (false),
  207295. #endif
  207296. recursiveToFrontCall (false)
  207297. {
  207298. NSRect r;
  207299. r.origin.x = 0;
  207300. r.origin.y = 0;
  207301. r.size.width = (float) component->getWidth();
  207302. r.size.height = (float) component->getHeight();
  207303. view = [[JuceNSView alloc] initWithOwner: this withFrame: r];
  207304. [view setPostsFrameChangedNotifications: YES];
  207305. if (isSharedWindow)
  207306. {
  207307. window = [viewToAttachTo window];
  207308. [viewToAttachTo addSubview: view];
  207309. setVisible (component->isVisible());
  207310. }
  207311. else
  207312. {
  207313. r.origin.x = (float) component->getX();
  207314. r.origin.y = (float) component->getY();
  207315. r.origin.y = [[[NSScreen screens] objectAtIndex: 0] frame].size.height - (r.origin.y + r.size.height);
  207316. unsigned int style = 0;
  207317. if ((windowStyleFlags & windowHasTitleBar) == 0)
  207318. style = NSBorderlessWindowMask;
  207319. else
  207320. style = NSTitledWindowMask;
  207321. if ((windowStyleFlags & windowHasMinimiseButton) != 0)
  207322. style |= NSMiniaturizableWindowMask;
  207323. if ((windowStyleFlags & windowHasCloseButton) != 0)
  207324. style |= NSClosableWindowMask;
  207325. if ((windowStyleFlags & windowIsResizable) != 0)
  207326. style |= NSResizableWindowMask;
  207327. window = [[JuceNSWindow alloc] initWithContentRect: r
  207328. styleMask: style
  207329. backing: NSBackingStoreBuffered
  207330. defer: YES];
  207331. [((JuceNSWindow*) window) setOwner: this];
  207332. [window orderOut: nil];
  207333. [window setDelegate: (JuceNSWindow*) window];
  207334. [window setOpaque: component->isOpaque()];
  207335. [window setHasShadow: ((windowStyleFlags & windowHasDropShadow) != 0)];
  207336. if (component->isAlwaysOnTop())
  207337. [window setLevel: NSFloatingWindowLevel];
  207338. [window setContentView: view];
  207339. [window setAutodisplay: YES];
  207340. [window setAcceptsMouseMovedEvents: YES];
  207341. // We'll both retain and also release this on closing because plugin hosts can unexpectedly
  207342. // close the window for us, and also tend to get cause trouble if setReleasedWhenClosed is NO.
  207343. [window setReleasedWhenClosed: YES];
  207344. [window retain];
  207345. [window setExcludedFromWindowsMenu: (windowStyleFlags & windowIsTemporary) != 0];
  207346. [window setIgnoresMouseEvents: (windowStyleFlags & windowIgnoresMouseClicks) != 0];
  207347. }
  207348. setTitle (component->getName());
  207349. }
  207350. NSViewComponentPeer::~NSViewComponentPeer()
  207351. {
  207352. view->owner = 0;
  207353. [view removeFromSuperview];
  207354. [view release];
  207355. if (! isSharedWindow)
  207356. {
  207357. [((JuceNSWindow*) window) setOwner: 0];
  207358. [window close];
  207359. [window release];
  207360. }
  207361. }
  207362. void* NSViewComponentPeer::getNativeHandle() const
  207363. {
  207364. return view;
  207365. }
  207366. void NSViewComponentPeer::setVisible (bool shouldBeVisible)
  207367. {
  207368. if (isSharedWindow)
  207369. {
  207370. [view setHidden: ! shouldBeVisible];
  207371. }
  207372. else
  207373. {
  207374. if (shouldBeVisible)
  207375. {
  207376. [window orderFront: nil];
  207377. handleBroughtToFront();
  207378. }
  207379. else
  207380. {
  207381. [window orderOut: nil];
  207382. }
  207383. }
  207384. }
  207385. void NSViewComponentPeer::setTitle (const String& title)
  207386. {
  207387. const ScopedAutoReleasePool pool;
  207388. if (! isSharedWindow)
  207389. [window setTitle: juceStringToNS (title)];
  207390. }
  207391. void NSViewComponentPeer::setPosition (int x, int y)
  207392. {
  207393. setBounds (x, y, component->getWidth(), component->getHeight(), false);
  207394. }
  207395. void NSViewComponentPeer::setSize (int w, int h)
  207396. {
  207397. setBounds (component->getX(), component->getY(), w, h, false);
  207398. }
  207399. void NSViewComponentPeer::setBounds (int x, int y, int w, int h, const bool isNowFullScreen)
  207400. {
  207401. fullScreen = isNowFullScreen;
  207402. w = jmax (0, w);
  207403. h = jmax (0, h);
  207404. NSRect r;
  207405. r.origin.x = (float) x;
  207406. r.origin.y = (float) y;
  207407. r.size.width = (float) w;
  207408. r.size.height = (float) h;
  207409. if (isSharedWindow)
  207410. {
  207411. r.origin.y = [[view superview] frame].size.height - (r.origin.y + r.size.height);
  207412. if ([view frame].size.width != r.size.width
  207413. || [view frame].size.height != r.size.height)
  207414. [view setNeedsDisplay: true];
  207415. [view setFrame: r];
  207416. }
  207417. else
  207418. {
  207419. r.origin.y = [[[NSScreen screens] objectAtIndex: 0] frame].size.height - (r.origin.y + r.size.height);
  207420. [window setFrame: [window frameRectForContentRect: r]
  207421. display: true];
  207422. }
  207423. }
  207424. void NSViewComponentPeer::getBounds (int& x, int& y, int& w, int& h, const bool global) const
  207425. {
  207426. NSRect r = [view frame];
  207427. if (global && [view window] != 0)
  207428. {
  207429. r = [view convertRect: r toView: nil];
  207430. NSRect wr = [[view window] frame];
  207431. r.origin.x += wr.origin.x;
  207432. r.origin.y += wr.origin.y;
  207433. y = (int) ([[[NSScreen screens] objectAtIndex:0] frame].size.height - r.origin.y - r.size.height);
  207434. }
  207435. else
  207436. {
  207437. y = (int) ([[view superview] frame].size.height - r.origin.y - r.size.height);
  207438. }
  207439. x = (int) r.origin.x;
  207440. w = (int) r.size.width;
  207441. h = (int) r.size.height;
  207442. }
  207443. void NSViewComponentPeer::getBounds (int& x, int& y, int& w, int& h) const
  207444. {
  207445. getBounds (x, y, w, h, ! isSharedWindow);
  207446. }
  207447. int NSViewComponentPeer::getScreenX() const
  207448. {
  207449. int x, y, w, h;
  207450. getBounds (x, y, w, h, true);
  207451. return x;
  207452. }
  207453. int NSViewComponentPeer::getScreenY() const
  207454. {
  207455. int x, y, w, h;
  207456. getBounds (x, y, w, h, true);
  207457. return y;
  207458. }
  207459. void NSViewComponentPeer::relativePositionToGlobal (int& x, int& y)
  207460. {
  207461. int wx, wy, ww, wh;
  207462. getBounds (wx, wy, ww, wh, true);
  207463. x += wx;
  207464. y += wy;
  207465. }
  207466. void NSViewComponentPeer::globalPositionToRelative (int& x, int& y)
  207467. {
  207468. int wx, wy, ww, wh;
  207469. getBounds (wx, wy, ww, wh, true);
  207470. x -= wx;
  207471. y -= wy;
  207472. }
  207473. NSRect NSViewComponentPeer::constrainRect (NSRect r)
  207474. {
  207475. if (constrainer != 0)
  207476. {
  207477. NSRect current = [window frame];
  207478. current.origin.y = [[[NSScreen screens] objectAtIndex: 0] frame].size.height - current.origin.y - current.size.height;
  207479. r.origin.y = [[[NSScreen screens] objectAtIndex: 0] frame].size.height - r.origin.y - r.size.height;
  207480. int x = (int) r.origin.x;
  207481. int y = (int) r.origin.y;
  207482. int w = (int) r.size.width;
  207483. int h = (int) r.size.height;
  207484. Rectangle original ((int) current.origin.x, (int) current.origin.y,
  207485. (int) current.size.width, (int) current.size.height);
  207486. constrainer->checkBounds (x, y, w, h,
  207487. original,
  207488. Desktop::getInstance().getAllMonitorDisplayAreas().getBounds(),
  207489. y != original.getY() && y + h == original.getBottom(),
  207490. x != original.getX() && x + w == original.getRight(),
  207491. y == original.getY() && y + h != original.getBottom(),
  207492. x == original.getX() && x + w != original.getRight());
  207493. r.origin.x = x;
  207494. r.origin.y = [[[NSScreen screens] objectAtIndex: 0] frame].size.height - r.size.height - y;
  207495. r.size.width = w;
  207496. r.size.height = h;
  207497. }
  207498. return r;
  207499. }
  207500. void NSViewComponentPeer::setMinimised (bool shouldBeMinimised)
  207501. {
  207502. if (! isSharedWindow)
  207503. {
  207504. if (shouldBeMinimised)
  207505. [window miniaturize: nil];
  207506. else
  207507. [window deminiaturize: nil];
  207508. }
  207509. }
  207510. bool NSViewComponentPeer::isMinimised() const
  207511. {
  207512. return window != 0 && [window isMiniaturized];
  207513. }
  207514. void NSViewComponentPeer::setFullScreen (bool shouldBeFullScreen)
  207515. {
  207516. if (! isSharedWindow)
  207517. {
  207518. Rectangle r (lastNonFullscreenBounds);
  207519. setMinimised (false);
  207520. if (fullScreen != shouldBeFullScreen)
  207521. {
  207522. if (shouldBeFullScreen && (getStyleFlags() & windowHasTitleBar) != 0)
  207523. {
  207524. fullScreen = true;
  207525. [window performZoom: nil];
  207526. }
  207527. else
  207528. {
  207529. if (shouldBeFullScreen)
  207530. r = Desktop::getInstance().getMainMonitorArea();
  207531. // (can't call the component's setBounds method because that'll reset our fullscreen flag)
  207532. if (r != getComponent()->getBounds() && ! r.isEmpty())
  207533. setBounds (r.getX(), r.getY(), r.getWidth(), r.getHeight(), shouldBeFullScreen);
  207534. }
  207535. }
  207536. }
  207537. }
  207538. bool NSViewComponentPeer::isFullScreen() const
  207539. {
  207540. return fullScreen;
  207541. }
  207542. bool NSViewComponentPeer::contains (int x, int y, bool trueIfInAChildWindow) const
  207543. {
  207544. if (((unsigned int) x) >= (unsigned int) component->getWidth()
  207545. || ((unsigned int) y) >= (unsigned int) component->getHeight())
  207546. return false;
  207547. NSPoint p;
  207548. p.x = (float) x;
  207549. p.y = (float) y;
  207550. NSView* v = [view hitTest: p];
  207551. if (trueIfInAChildWindow)
  207552. return v != nil;
  207553. return v == view;
  207554. }
  207555. const BorderSize NSViewComponentPeer::getFrameSize() const
  207556. {
  207557. BorderSize b;
  207558. if (! isSharedWindow)
  207559. {
  207560. NSRect v = [view convertRect: [view frame] toView: nil];
  207561. NSRect w = [window frame];
  207562. b.setTop ((int) (w.size.height - (v.origin.y + v.size.height)));
  207563. b.setBottom ((int) v.origin.y);
  207564. b.setLeft ((int) v.origin.x);
  207565. b.setRight ((int) (w.size.width - (v.origin.x + v.size.width)));
  207566. }
  207567. return b;
  207568. }
  207569. bool NSViewComponentPeer::setAlwaysOnTop (bool alwaysOnTop)
  207570. {
  207571. if (! isSharedWindow)
  207572. {
  207573. [window setLevel: alwaysOnTop ? NSFloatingWindowLevel
  207574. : NSNormalWindowLevel];
  207575. }
  207576. return true;
  207577. }
  207578. void NSViewComponentPeer::toFront (bool makeActiveWindow)
  207579. {
  207580. if (isSharedWindow)
  207581. {
  207582. [[view superview] addSubview: view
  207583. positioned: NSWindowAbove
  207584. relativeTo: nil];
  207585. }
  207586. if (window != 0 && component->isVisible())
  207587. {
  207588. if (makeActiveWindow)
  207589. [window makeKeyAndOrderFront: nil];
  207590. else
  207591. [window orderFront: nil];
  207592. if (! recursiveToFrontCall)
  207593. {
  207594. recursiveToFrontCall = true;
  207595. handleBroughtToFront();
  207596. recursiveToFrontCall = false;
  207597. }
  207598. }
  207599. }
  207600. void NSViewComponentPeer::toBehind (ComponentPeer* other)
  207601. {
  207602. NSViewComponentPeer* o = (NSViewComponentPeer*) other;
  207603. if (isSharedWindow)
  207604. {
  207605. [[view superview] addSubview: view
  207606. positioned: NSWindowBelow
  207607. relativeTo: o->view];
  207608. }
  207609. else
  207610. {
  207611. [window orderWindow: NSWindowBelow
  207612. relativeTo: o->window != 0 ? [o->window windowNumber]
  207613. : nil ];
  207614. }
  207615. }
  207616. void NSViewComponentPeer::setIcon (const Image& /*newIcon*/)
  207617. {
  207618. // to do..
  207619. }
  207620. void NSViewComponentPeer::viewFocusGain()
  207621. {
  207622. if (currentlyFocusedPeer != this)
  207623. {
  207624. if (ComponentPeer::isValidPeer (currentlyFocusedPeer))
  207625. currentlyFocusedPeer->handleFocusLoss();
  207626. currentlyFocusedPeer = this;
  207627. handleFocusGain();
  207628. }
  207629. }
  207630. void NSViewComponentPeer::viewFocusLoss()
  207631. {
  207632. if (currentlyFocusedPeer == this)
  207633. {
  207634. currentlyFocusedPeer = 0;
  207635. handleFocusLoss();
  207636. }
  207637. }
  207638. void juce_HandleProcessFocusChange()
  207639. {
  207640. keysCurrentlyDown.clear();
  207641. if (NSViewComponentPeer::isValidPeer (currentlyFocusedPeer))
  207642. {
  207643. if (Process::isForegroundProcess())
  207644. {
  207645. currentlyFocusedPeer->handleFocusGain();
  207646. ComponentPeer::bringModalComponentToFront();
  207647. }
  207648. else
  207649. {
  207650. currentlyFocusedPeer->handleFocusLoss();
  207651. // turn kiosk mode off if we lose focus..
  207652. Desktop::getInstance().setKioskModeComponent (0);
  207653. }
  207654. }
  207655. }
  207656. bool NSViewComponentPeer::isFocused() const
  207657. {
  207658. return isSharedWindow ? this == currentlyFocusedPeer
  207659. : (window != 0 && [window isKeyWindow]);
  207660. }
  207661. void NSViewComponentPeer::grabFocus()
  207662. {
  207663. if (window != 0)
  207664. {
  207665. [window makeKeyWindow];
  207666. [window makeFirstResponder: view];
  207667. viewFocusGain();
  207668. }
  207669. }
  207670. void NSViewComponentPeer::textInputRequired (int /*x*/, int /*y*/)
  207671. {
  207672. }
  207673. bool NSViewComponentPeer::handleKeyEvent (NSEvent* ev, bool isKeyDown)
  207674. {
  207675. String unicode (nsStringToJuce ([ev characters]));
  207676. String unmodified (nsStringToJuce ([ev charactersIgnoringModifiers]));
  207677. int keyCode = getKeyCodeFromEvent (ev);
  207678. //DBG ("unicode: " + unicode + " " + String::toHexString ((int) unicode[0]));
  207679. //DBG ("unmodified: " + unmodified + " " + String::toHexString ((int) unmodified[0]));
  207680. if (unicode.isNotEmpty() || keyCode != 0)
  207681. {
  207682. if (isKeyDown)
  207683. {
  207684. bool used = false;
  207685. while (unicode.length() > 0)
  207686. {
  207687. juce_wchar textCharacter = unicode[0];
  207688. unicode = unicode.substring (1);
  207689. if (([ev modifierFlags] & NSCommandKeyMask) != 0)
  207690. textCharacter = 0;
  207691. used = handleKeyUpOrDown (true) || used;
  207692. used = handleKeyPress (keyCode, textCharacter) || used;
  207693. }
  207694. return used;
  207695. }
  207696. else
  207697. {
  207698. if (handleKeyUpOrDown (false))
  207699. return true;
  207700. }
  207701. }
  207702. return false;
  207703. }
  207704. bool NSViewComponentPeer::redirectKeyDown (NSEvent* ev)
  207705. {
  207706. updateKeysDown (ev, true);
  207707. bool used = handleKeyEvent (ev, true);
  207708. if (([ev modifierFlags] & NSCommandKeyMask) != 0)
  207709. {
  207710. // for command keys, the key-up event is thrown away, so simulate one..
  207711. updateKeysDown (ev, false);
  207712. used = (isValidPeer (this) && handleKeyEvent (ev, false)) || used;
  207713. }
  207714. // (If we're running modally, don't allow unused keystrokes to be passed
  207715. // along to other blocked views..)
  207716. if (Component::getCurrentlyModalComponent() != 0)
  207717. used = true;
  207718. return used;
  207719. }
  207720. bool NSViewComponentPeer::redirectKeyUp (NSEvent* ev)
  207721. {
  207722. updateKeysDown (ev, false);
  207723. return handleKeyEvent (ev, false)
  207724. || Component::getCurrentlyModalComponent() != 0;
  207725. }
  207726. void NSViewComponentPeer::redirectModKeyChange (NSEvent* ev)
  207727. {
  207728. updateModifiers (ev);
  207729. handleModifierKeysChange();
  207730. }
  207731. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
  207732. bool NSViewComponentPeer::redirectPerformKeyEquivalent (NSEvent* ev)
  207733. {
  207734. if ([ev type] == NSKeyDown)
  207735. return redirectKeyDown (ev);
  207736. else if ([ev type] == NSKeyUp)
  207737. return redirectKeyUp (ev);
  207738. return false;
  207739. }
  207740. #endif
  207741. void NSViewComponentPeer::redirectMouseDown (NSEvent* ev)
  207742. {
  207743. updateModifiers (ev);
  207744. currentModifiers |= getModifierForButtonNumber ([ev buttonNumber]);
  207745. int x, y;
  207746. getMousePos (ev, view, x, y);
  207747. handleMouseDown (x, y, getMouseTime (ev));
  207748. }
  207749. void NSViewComponentPeer::redirectMouseUp (NSEvent* ev)
  207750. {
  207751. const int oldMods = currentModifiers;
  207752. updateModifiers (ev);
  207753. currentModifiers &= ~getModifierForButtonNumber ([ev buttonNumber]);
  207754. int x, y;
  207755. getMousePos (ev, view, x, y);
  207756. handleMouseUp (oldMods, x, y, getMouseTime (ev));
  207757. showArrowCursorIfNeeded();
  207758. }
  207759. void NSViewComponentPeer::redirectMouseDrag (NSEvent* ev)
  207760. {
  207761. updateModifiers (ev);
  207762. currentModifiers |= getModifierForButtonNumber ([ev buttonNumber]);
  207763. int x, y;
  207764. getMousePos (ev, view, x, y);
  207765. handleMouseDrag (x, y, getMouseTime (ev));
  207766. }
  207767. void NSViewComponentPeer::redirectMouseMove (NSEvent* ev)
  207768. {
  207769. updateModifiers (ev);
  207770. int x, y;
  207771. getMousePos (ev, view, x, y);
  207772. handleMouseMove (x, y, getMouseTime (ev));
  207773. showArrowCursorIfNeeded();
  207774. }
  207775. void NSViewComponentPeer::redirectMouseEnter (NSEvent* ev)
  207776. {
  207777. updateModifiers (ev);
  207778. int x, y;
  207779. getMousePos (ev, view, x, y);
  207780. handleMouseEnter (x, y, getMouseTime (ev));
  207781. }
  207782. void NSViewComponentPeer::redirectMouseExit (NSEvent* ev)
  207783. {
  207784. updateModifiers (ev);
  207785. int x, y;
  207786. getMousePos (ev, view, x, y);
  207787. handleMouseExit (x, y, getMouseTime (ev));
  207788. }
  207789. void NSViewComponentPeer::redirectMouseWheel (NSEvent* ev)
  207790. {
  207791. updateModifiers (ev);
  207792. handleMouseWheel (roundToInt ([ev deltaX] * 10.0f),
  207793. roundToInt ([ev deltaY] * 10.0f),
  207794. getMouseTime (ev));
  207795. }
  207796. void NSViewComponentPeer::showArrowCursorIfNeeded()
  207797. {
  207798. if (Component::getComponentUnderMouse() == 0)
  207799. {
  207800. int mx, my;
  207801. Desktop::getInstance().getMousePosition (mx, my);
  207802. if (Desktop::getInstance().findComponentAt (mx, my) == 0)
  207803. [[NSCursor arrowCursor] set];
  207804. }
  207805. }
  207806. BOOL NSViewComponentPeer::sendDragCallback (int type, id <NSDraggingInfo> sender)
  207807. {
  207808. NSString* bestType
  207809. = [[sender draggingPasteboard] availableTypeFromArray: [view getSupportedDragTypes]];
  207810. if (bestType == nil)
  207811. return false;
  207812. NSPoint p = [view convertPoint: [sender draggingLocation] fromView: nil];
  207813. int x = (int) p.x;
  207814. int y = (int) ([view frame].size.height - p.y);
  207815. StringArray files;
  207816. id list = [[sender draggingPasteboard] propertyListForType: bestType];
  207817. if (list == nil)
  207818. return false;
  207819. if ([list isKindOfClass: [NSArray class]])
  207820. {
  207821. NSArray* items = (NSArray*) list;
  207822. for (unsigned int i = 0; i < [items count]; ++i)
  207823. files.add (nsStringToJuce ((NSString*) [items objectAtIndex: i]));
  207824. }
  207825. if (files.size() == 0)
  207826. return false;
  207827. if (type == 0)
  207828. handleFileDragMove (files, x, y);
  207829. else if (type == 1)
  207830. handleFileDragExit (files);
  207831. else if (type == 2)
  207832. handleFileDragDrop (files, x, y);
  207833. return true;
  207834. }
  207835. bool NSViewComponentPeer::isOpaque()
  207836. {
  207837. if (! getComponent()->isValidComponent())
  207838. return true;
  207839. return getComponent()->isOpaque();
  207840. }
  207841. void NSViewComponentPeer::drawRect (NSRect r)
  207842. {
  207843. if (r.size.width < 1.0f || r.size.height < 1.0f)
  207844. return;
  207845. CGContextRef cg = (CGContextRef) [[NSGraphicsContext currentContext] graphicsPort];
  207846. if (! component->isOpaque())
  207847. CGContextClearRect (cg, CGContextGetClipBoundingBox (cg));
  207848. #if USE_COREGRAPHICS_RENDERING
  207849. if (usingCoreGraphics)
  207850. {
  207851. CoreGraphicsContext context (cg, (float) [view frame].size.height);
  207852. insideDrawRect = true;
  207853. handlePaint (context);
  207854. insideDrawRect = false;
  207855. }
  207856. else
  207857. #endif
  207858. {
  207859. Image temp (getComponent()->isOpaque() ? Image::RGB : Image::ARGB,
  207860. (int) (r.size.width + 0.5f),
  207861. (int) (r.size.height + 0.5f),
  207862. ! getComponent()->isOpaque());
  207863. LowLevelGraphicsSoftwareRenderer context (temp);
  207864. context.setOrigin (-roundToInt (r.origin.x),
  207865. -roundToInt ([view frame].size.height - (r.origin.y + r.size.height)));
  207866. const NSRect* rects = 0;
  207867. NSInteger numRects = 0;
  207868. [view getRectsBeingDrawn: &rects count: &numRects];
  207869. RectangleList clip;
  207870. for (int i = 0; i < numRects; ++i)
  207871. {
  207872. clip.addWithoutMerging (Rectangle (roundToInt (rects[i].origin.x),
  207873. roundToInt ([view frame].size.height - (rects[i].origin.y + rects[i].size.height)),
  207874. roundToInt (rects[i].size.width),
  207875. roundToInt (rects[i].size.height)));
  207876. }
  207877. if (context.clipToRectangleList (clip))
  207878. {
  207879. insideDrawRect = true;
  207880. handlePaint (context);
  207881. insideDrawRect = false;
  207882. CGColorSpaceRef colourSpace = CGColorSpaceCreateDeviceRGB();
  207883. CGImageRef image = CoreGraphicsImage::createImage (temp, false, colourSpace);
  207884. CGColorSpaceRelease (colourSpace);
  207885. CGContextDrawImage (cg, CGRectMake (r.origin.x, r.origin.y, temp.getWidth(), temp.getHeight()), image);
  207886. CGImageRelease (image);
  207887. }
  207888. }
  207889. }
  207890. const StringArray NSViewComponentPeer::getAvailableRenderingEngines() throw()
  207891. {
  207892. StringArray s;
  207893. s.add ("Software Renderer");
  207894. #if USE_COREGRAPHICS_RENDERING
  207895. s.add ("CoreGraphics Renderer");
  207896. #endif
  207897. return s;
  207898. }
  207899. int NSViewComponentPeer::getCurrentRenderingEngine() throw()
  207900. {
  207901. return usingCoreGraphics ? 1 : 0;
  207902. }
  207903. void NSViewComponentPeer::setCurrentRenderingEngine (int index) throw()
  207904. {
  207905. #if USE_COREGRAPHICS_RENDERING
  207906. if (usingCoreGraphics != (index > 0))
  207907. {
  207908. usingCoreGraphics = index > 0;
  207909. [view setNeedsDisplay: true];
  207910. }
  207911. #endif
  207912. }
  207913. bool NSViewComponentPeer::canBecomeKeyWindow()
  207914. {
  207915. return (getStyleFlags() & JUCE_NAMESPACE::ComponentPeer::windowIgnoresKeyPresses) == 0;
  207916. }
  207917. bool NSViewComponentPeer::windowShouldClose()
  207918. {
  207919. if (! isValidPeer (this))
  207920. return YES;
  207921. handleUserClosingWindow();
  207922. return NO;
  207923. }
  207924. void NSViewComponentPeer::redirectMovedOrResized()
  207925. {
  207926. handleMovedOrResized();
  207927. }
  207928. void NSViewComponentPeer::viewMovedToWindow()
  207929. {
  207930. if (isSharedWindow)
  207931. window = [view window];
  207932. }
  207933. void juce_setKioskComponent (Component* kioskModeComponent, bool enableOrDisable, bool allowMenusAndBars)
  207934. {
  207935. // Very annoyingly, this function has to use the old SetSystemUIMode function,
  207936. // which is in Carbon.framework. But, because there's no Cocoa equivalent, it
  207937. // is apparently still available in 64-bit apps..
  207938. if (enableOrDisable)
  207939. {
  207940. SetSystemUIMode (kUIModeAllSuppressed, allowMenusAndBars ? kUIOptionAutoShowMenuBar : 0);
  207941. kioskModeComponent->setBounds (Desktop::getInstance().getMainMonitorArea (false));
  207942. }
  207943. else
  207944. {
  207945. SetSystemUIMode (kUIModeNormal, 0);
  207946. }
  207947. }
  207948. class AsyncRepaintMessage : public CallbackMessage
  207949. {
  207950. public:
  207951. NSViewComponentPeer* const peer;
  207952. const Rectangle rect;
  207953. AsyncRepaintMessage (NSViewComponentPeer* const peer_, const Rectangle& rect_)
  207954. : peer (peer_), rect (rect_)
  207955. {
  207956. }
  207957. void messageCallback()
  207958. {
  207959. if (ComponentPeer::isValidPeer (peer))
  207960. peer->repaint (rect.getX(), rect.getY(), rect.getWidth(), rect.getHeight());
  207961. }
  207962. };
  207963. void NSViewComponentPeer::repaint (int x, int y, int w, int h)
  207964. {
  207965. if (insideDrawRect)
  207966. {
  207967. (new AsyncRepaintMessage (this, Rectangle (x, y, w, h)))->post();
  207968. }
  207969. else
  207970. {
  207971. [view setNeedsDisplayInRect: NSMakeRect ((float) x, (float) ([view frame].size.height - (y + h)),
  207972. (float) w, (float) h)];
  207973. }
  207974. }
  207975. void NSViewComponentPeer::performAnyPendingRepaintsNow()
  207976. {
  207977. [view displayIfNeeded];
  207978. }
  207979. ComponentPeer* Component::createNewPeer (int styleFlags, void* windowToAttachTo)
  207980. {
  207981. return new NSViewComponentPeer (this, styleFlags, (NSView*) windowToAttachTo);
  207982. }
  207983. Image* juce_createIconForFile (const File& file)
  207984. {
  207985. const ScopedAutoReleasePool pool;
  207986. NSImage* image = [[NSWorkspace sharedWorkspace] iconForFile: juceStringToNS (file.getFullPathName())];
  207987. CoreGraphicsImage* result = new CoreGraphicsImage (Image::ARGB, (int) [image size].width, (int) [image size].height, true);
  207988. [NSGraphicsContext saveGraphicsState];
  207989. [NSGraphicsContext setCurrentContext: [NSGraphicsContext graphicsContextWithGraphicsPort: result->context flipped: false]];
  207990. [image drawAtPoint: NSMakePoint (0, 0)
  207991. fromRect: NSMakeRect (0, 0, [image size].width, [image size].height)
  207992. operation: NSCompositeSourceOver fraction: 1.0f];
  207993. [[NSGraphicsContext currentContext] flushGraphics];
  207994. [NSGraphicsContext restoreGraphicsState];
  207995. return result;
  207996. }
  207997. const int KeyPress::spaceKey = ' ';
  207998. const int KeyPress::returnKey = 0x0d;
  207999. const int KeyPress::escapeKey = 0x1b;
  208000. const int KeyPress::backspaceKey = 0x7f;
  208001. const int KeyPress::leftKey = NSLeftArrowFunctionKey;
  208002. const int KeyPress::rightKey = NSRightArrowFunctionKey;
  208003. const int KeyPress::upKey = NSUpArrowFunctionKey;
  208004. const int KeyPress::downKey = NSDownArrowFunctionKey;
  208005. const int KeyPress::pageUpKey = NSPageUpFunctionKey;
  208006. const int KeyPress::pageDownKey = NSPageDownFunctionKey;
  208007. const int KeyPress::endKey = NSEndFunctionKey;
  208008. const int KeyPress::homeKey = NSHomeFunctionKey;
  208009. const int KeyPress::deleteKey = NSDeleteFunctionKey;
  208010. const int KeyPress::insertKey = -1;
  208011. const int KeyPress::tabKey = 9;
  208012. const int KeyPress::F1Key = NSF1FunctionKey;
  208013. const int KeyPress::F2Key = NSF2FunctionKey;
  208014. const int KeyPress::F3Key = NSF3FunctionKey;
  208015. const int KeyPress::F4Key = NSF4FunctionKey;
  208016. const int KeyPress::F5Key = NSF5FunctionKey;
  208017. const int KeyPress::F6Key = NSF6FunctionKey;
  208018. const int KeyPress::F7Key = NSF7FunctionKey;
  208019. const int KeyPress::F8Key = NSF8FunctionKey;
  208020. const int KeyPress::F9Key = NSF9FunctionKey;
  208021. const int KeyPress::F10Key = NSF10FunctionKey;
  208022. const int KeyPress::F11Key = NSF1FunctionKey;
  208023. const int KeyPress::F12Key = NSF12FunctionKey;
  208024. const int KeyPress::F13Key = NSF13FunctionKey;
  208025. const int KeyPress::F14Key = NSF14FunctionKey;
  208026. const int KeyPress::F15Key = NSF15FunctionKey;
  208027. const int KeyPress::F16Key = NSF16FunctionKey;
  208028. const int KeyPress::numberPad0 = 0x30020;
  208029. const int KeyPress::numberPad1 = 0x30021;
  208030. const int KeyPress::numberPad2 = 0x30022;
  208031. const int KeyPress::numberPad3 = 0x30023;
  208032. const int KeyPress::numberPad4 = 0x30024;
  208033. const int KeyPress::numberPad5 = 0x30025;
  208034. const int KeyPress::numberPad6 = 0x30026;
  208035. const int KeyPress::numberPad7 = 0x30027;
  208036. const int KeyPress::numberPad8 = 0x30028;
  208037. const int KeyPress::numberPad9 = 0x30029;
  208038. const int KeyPress::numberPadAdd = 0x3002a;
  208039. const int KeyPress::numberPadSubtract = 0x3002b;
  208040. const int KeyPress::numberPadMultiply = 0x3002c;
  208041. const int KeyPress::numberPadDivide = 0x3002d;
  208042. const int KeyPress::numberPadSeparator = 0x3002e;
  208043. const int KeyPress::numberPadDecimalPoint = 0x3002f;
  208044. const int KeyPress::numberPadEquals = 0x30030;
  208045. const int KeyPress::numberPadDelete = 0x30031;
  208046. const int KeyPress::playKey = 0x30000;
  208047. const int KeyPress::stopKey = 0x30001;
  208048. const int KeyPress::fastForwardKey = 0x30002;
  208049. const int KeyPress::rewindKey = 0x30003;
  208050. #endif
  208051. /********* End of inlined file: juce_mac_NSViewComponentPeer.mm *********/
  208052. /********* Start of inlined file: juce_mac_MouseCursor.mm *********/
  208053. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  208054. // compiled on its own).
  208055. #if JUCE_INCLUDED_FILE
  208056. #if JUCE_MAC
  208057. void* juce_createMouseCursorFromImage (const Image& image, int hotspotX, int hotspotY) throw()
  208058. {
  208059. NSImage* im = CoreGraphicsImage::createNSImage (image);
  208060. NSCursor* c = [[NSCursor alloc] initWithImage: im
  208061. hotSpot: NSMakePoint (hotspotX, hotspotY)];
  208062. [im release];
  208063. return (void*) c;
  208064. }
  208065. static void* juce_cursorFromData (const unsigned char* data, const size_t size, float hx, float hy) throw()
  208066. {
  208067. ScopedPointer <Image> im (ImageFileFormat::loadFrom ((const char*) data, (int) size));
  208068. jassert (im != 0);
  208069. if (im == 0)
  208070. return 0;
  208071. return juce_createMouseCursorFromImage (*im,
  208072. (int) (hx * im->getWidth()),
  208073. (int) (hy * im->getHeight()));
  208074. }
  208075. static void* juce_cursorFromWebKitFile (const char* filename, float hx, float hy)
  208076. {
  208077. File f ("/System/Library/Frameworks/WebKit.framework/Frameworks/WebCore.framework/Resources");
  208078. MemoryBlock mb;
  208079. if (f.getChildFile (filename).loadFileAsData (mb))
  208080. return juce_cursorFromData ((const unsigned char*) mb.getData(), mb.getSize(), hx, hy);
  208081. return 0;
  208082. }
  208083. void* juce_createStandardMouseCursor (MouseCursor::StandardCursorType type) throw()
  208084. {
  208085. const ScopedAutoReleasePool pool;
  208086. NSCursor* c = 0;
  208087. switch (type)
  208088. {
  208089. case MouseCursor::NormalCursor:
  208090. c = [NSCursor arrowCursor];
  208091. break;
  208092. case MouseCursor::NoCursor:
  208093. {
  208094. Image blank (Image::ARGB, 8, 8, true);
  208095. return juce_createMouseCursorFromImage (blank, 0, 0);
  208096. }
  208097. case MouseCursor::DraggingHandCursor:
  208098. c = [NSCursor openHandCursor];
  208099. break;
  208100. case MouseCursor::CopyingCursor:
  208101. return juce_cursorFromWebKitFile ("copyCursor.png", 0, 0);
  208102. case MouseCursor::WaitCursor:
  208103. c = [NSCursor arrowCursor]; // avoid this on the mac, let the OS provide the beachball
  208104. break;
  208105. //return juce_cursorFromWebKitFile ("waitCursor.png", 0.5f, 0.5f);
  208106. case MouseCursor::IBeamCursor:
  208107. c = [NSCursor IBeamCursor];
  208108. break;
  208109. case MouseCursor::PointingHandCursor:
  208110. c = [NSCursor pointingHandCursor];
  208111. break;
  208112. case MouseCursor::LeftRightResizeCursor:
  208113. c = [NSCursor resizeLeftRightCursor];
  208114. break;
  208115. case MouseCursor::LeftEdgeResizeCursor:
  208116. c = [NSCursor resizeLeftCursor];
  208117. break;
  208118. case MouseCursor::RightEdgeResizeCursor:
  208119. c = [NSCursor resizeRightCursor];
  208120. break;
  208121. case MouseCursor::UpDownResizeCursor:
  208122. case MouseCursor::TopEdgeResizeCursor:
  208123. case MouseCursor::BottomEdgeResizeCursor:
  208124. return juce_cursorFromWebKitFile ("northSouthResizeCursor.png", 0.5f, 0.5f);
  208125. case MouseCursor::TopLeftCornerResizeCursor:
  208126. case MouseCursor::BottomRightCornerResizeCursor:
  208127. return juce_cursorFromWebKitFile ("northWestSouthEastResizeCursor.png", 0.5f, 0.5f);
  208128. case MouseCursor::TopRightCornerResizeCursor:
  208129. case MouseCursor::BottomLeftCornerResizeCursor:
  208130. return juce_cursorFromWebKitFile ("northEastSouthWestResizeCursor.png", 0.5f, 0.5f);
  208131. case MouseCursor::UpDownLeftRightResizeCursor:
  208132. return juce_cursorFromWebKitFile ("moveCursor.png", 0.5f, 0.5f);
  208133. case MouseCursor::CrosshairCursor:
  208134. c = [NSCursor crosshairCursor];
  208135. break;
  208136. }
  208137. [c retain];
  208138. return (void*) c;
  208139. }
  208140. void juce_deleteMouseCursor (void* const cursorHandle, const bool isStandard) throw()
  208141. {
  208142. NSCursor* c = (NSCursor*) cursorHandle;
  208143. [c release];
  208144. }
  208145. void MouseCursor::showInAllWindows() const throw()
  208146. {
  208147. showInWindow (0);
  208148. }
  208149. void MouseCursor::showInWindow (ComponentPeer*) const throw()
  208150. {
  208151. NSCursor* const c = (NSCursor*) getHandle();
  208152. [c set];
  208153. }
  208154. #else
  208155. void* juce_createMouseCursorFromImage (const Image& image, int hotspotX, int hotspotY) throw() { return 0; }
  208156. void* juce_createStandardMouseCursor (MouseCursor::StandardCursorType type) throw() { return 0; }
  208157. void juce_deleteMouseCursor (void* const cursorHandle, const bool isStandard) throw() {}
  208158. void MouseCursor::showInAllWindows() const throw() {}
  208159. void MouseCursor::showInWindow (ComponentPeer*) const throw() {}
  208160. #endif
  208161. #endif
  208162. /********* End of inlined file: juce_mac_MouseCursor.mm *********/
  208163. /********* Start of inlined file: juce_mac_NSViewComponent.mm *********/
  208164. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  208165. // compiled on its own).
  208166. #if JUCE_INCLUDED_FILE
  208167. class NSViewComponentInternal : public ComponentMovementWatcher
  208168. {
  208169. Component* const owner;
  208170. NSViewComponentPeer* currentPeer;
  208171. bool wasShowing;
  208172. public:
  208173. NSView* const view;
  208174. NSViewComponentInternal (NSView* const view_, Component* const owner_)
  208175. : ComponentMovementWatcher (owner_),
  208176. owner (owner_),
  208177. currentPeer (0),
  208178. wasShowing (false),
  208179. view (view_)
  208180. {
  208181. [view_ retain];
  208182. if (owner_->isShowing())
  208183. componentPeerChanged();
  208184. }
  208185. ~NSViewComponentInternal()
  208186. {
  208187. [view removeFromSuperview];
  208188. [view release];
  208189. }
  208190. void componentMovedOrResized (Component& comp, bool wasMoved, bool wasResized)
  208191. {
  208192. ComponentMovementWatcher::componentMovedOrResized (comp, wasMoved, wasResized);
  208193. // The ComponentMovementWatcher version of this method avoids calling
  208194. // us when the top-level comp is resized, but for an NSView we need to know this
  208195. // because with inverted co-ords, we need to update the position even if the
  208196. // top-left pos hasn't changed
  208197. if (comp.isOnDesktop() && wasResized)
  208198. componentMovedOrResized (wasMoved, wasResized);
  208199. }
  208200. void componentMovedOrResized (bool /*wasMoved*/, bool /*wasResized*/)
  208201. {
  208202. Component* const topComp = owner->getTopLevelComponent();
  208203. if (topComp->getPeer() != 0)
  208204. {
  208205. int x = 0, y = 0;
  208206. owner->relativePositionToOtherComponent (topComp, x, y);
  208207. NSRect r;
  208208. r.origin.x = (float) x;
  208209. r.origin.y = (float) y;
  208210. r.size.width = (float) owner->getWidth();
  208211. r.size.height = (float) owner->getHeight();
  208212. r.origin.y = [[view superview] frame].size.height - (r.origin.y + r.size.height);
  208213. [view setFrame: r];
  208214. }
  208215. }
  208216. void componentPeerChanged()
  208217. {
  208218. NSViewComponentPeer* const peer = dynamic_cast <NSViewComponentPeer*> (owner->getPeer());
  208219. if (currentPeer != peer)
  208220. {
  208221. [view removeFromSuperview];
  208222. currentPeer = peer;
  208223. if (peer != 0)
  208224. {
  208225. [peer->view addSubview: view];
  208226. componentMovedOrResized (false, false);
  208227. }
  208228. }
  208229. [view setHidden: ! owner->isShowing()];
  208230. }
  208231. void componentVisibilityChanged (Component&)
  208232. {
  208233. componentPeerChanged();
  208234. }
  208235. juce_UseDebuggingNewOperator
  208236. private:
  208237. NSViewComponentInternal (const NSViewComponentInternal&);
  208238. const NSViewComponentInternal& operator= (const NSViewComponentInternal&);
  208239. };
  208240. NSViewComponent::NSViewComponent()
  208241. {
  208242. }
  208243. NSViewComponent::~NSViewComponent()
  208244. {
  208245. }
  208246. void NSViewComponent::setView (void* view)
  208247. {
  208248. if (view != getView())
  208249. {
  208250. if (view != 0)
  208251. info = new NSViewComponentInternal ((NSView*) view, this);
  208252. else
  208253. info = 0;
  208254. }
  208255. }
  208256. void* NSViewComponent::getView() const
  208257. {
  208258. return info == 0 ? 0 : info->view;
  208259. }
  208260. void NSViewComponent::paint (Graphics& g)
  208261. {
  208262. }
  208263. #endif
  208264. /********* End of inlined file: juce_mac_NSViewComponent.mm *********/
  208265. /********* Start of inlined file: juce_mac_AppleRemote.mm *********/
  208266. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  208267. // compiled on its own).
  208268. #if JUCE_INCLUDED_FILE
  208269. AppleRemoteDevice::AppleRemoteDevice()
  208270. : device (0),
  208271. queue (0),
  208272. remoteId (0)
  208273. {
  208274. }
  208275. AppleRemoteDevice::~AppleRemoteDevice()
  208276. {
  208277. stop();
  208278. }
  208279. static io_object_t getAppleRemoteDevice()
  208280. {
  208281. CFMutableDictionaryRef dict = IOServiceMatching ("AppleIRController");
  208282. io_iterator_t iter = 0;
  208283. io_object_t iod = 0;
  208284. if (IOServiceGetMatchingServices (kIOMasterPortDefault, dict, &iter) == kIOReturnSuccess
  208285. && iter != 0)
  208286. {
  208287. iod = IOIteratorNext (iter);
  208288. }
  208289. IOObjectRelease (iter);
  208290. return iod;
  208291. }
  208292. static bool createAppleRemoteInterface (io_object_t iod, void** device)
  208293. {
  208294. jassert (*device == 0);
  208295. io_name_t classname;
  208296. if (IOObjectGetClass (iod, classname) == kIOReturnSuccess)
  208297. {
  208298. IOCFPlugInInterface** cfPlugInInterface = 0;
  208299. SInt32 score = 0;
  208300. if (IOCreatePlugInInterfaceForService (iod,
  208301. kIOHIDDeviceUserClientTypeID,
  208302. kIOCFPlugInInterfaceID,
  208303. &cfPlugInInterface,
  208304. &score) == kIOReturnSuccess)
  208305. {
  208306. HRESULT hr = (*cfPlugInInterface)->QueryInterface (cfPlugInInterface,
  208307. CFUUIDGetUUIDBytes (kIOHIDDeviceInterfaceID),
  208308. device);
  208309. (void) hr;
  208310. (*cfPlugInInterface)->Release (cfPlugInInterface);
  208311. }
  208312. }
  208313. return *device != 0;
  208314. }
  208315. bool AppleRemoteDevice::start (const bool inExclusiveMode)
  208316. {
  208317. if (queue != 0)
  208318. return true;
  208319. stop();
  208320. bool result = false;
  208321. io_object_t iod = getAppleRemoteDevice();
  208322. if (iod != 0)
  208323. {
  208324. if (createAppleRemoteInterface (iod, &device) && open (inExclusiveMode))
  208325. result = true;
  208326. else
  208327. stop();
  208328. IOObjectRelease (iod);
  208329. }
  208330. return result;
  208331. }
  208332. void AppleRemoteDevice::stop()
  208333. {
  208334. if (queue != 0)
  208335. {
  208336. (*(IOHIDQueueInterface**) queue)->stop ((IOHIDQueueInterface**) queue);
  208337. (*(IOHIDQueueInterface**) queue)->dispose ((IOHIDQueueInterface**) queue);
  208338. (*(IOHIDQueueInterface**) queue)->Release ((IOHIDQueueInterface**) queue);
  208339. queue = 0;
  208340. }
  208341. if (device != 0)
  208342. {
  208343. (*(IOHIDDeviceInterface**) device)->close ((IOHIDDeviceInterface**) device);
  208344. (*(IOHIDDeviceInterface**) device)->Release ((IOHIDDeviceInterface**) device);
  208345. device = 0;
  208346. }
  208347. }
  208348. bool AppleRemoteDevice::isActive() const
  208349. {
  208350. return queue != 0;
  208351. }
  208352. static void appleRemoteQueueCallback (void* const target, const IOReturn result, void*, void*)
  208353. {
  208354. if (result == kIOReturnSuccess)
  208355. ((AppleRemoteDevice*) target)->handleCallbackInternal();
  208356. }
  208357. bool AppleRemoteDevice::open (const bool openInExclusiveMode)
  208358. {
  208359. Array <int> cookies;
  208360. CFArrayRef elements;
  208361. IOHIDDeviceInterface122** const device122 = (IOHIDDeviceInterface122**) device;
  208362. if ((*device122)->copyMatchingElements (device122, 0, &elements) != kIOReturnSuccess)
  208363. return false;
  208364. for (int i = 0; i < CFArrayGetCount (elements); ++i)
  208365. {
  208366. CFDictionaryRef element = (CFDictionaryRef) CFArrayGetValueAtIndex (elements, i);
  208367. // get the cookie
  208368. CFTypeRef object = CFDictionaryGetValue (element, CFSTR (kIOHIDElementCookieKey));
  208369. if (object == 0 || CFGetTypeID (object) != CFNumberGetTypeID())
  208370. continue;
  208371. long number;
  208372. if (! CFNumberGetValue ((CFNumberRef) object, kCFNumberLongType, &number))
  208373. continue;
  208374. cookies.add ((int) number);
  208375. }
  208376. CFRelease (elements);
  208377. if ((*(IOHIDDeviceInterface**) device)
  208378. ->open ((IOHIDDeviceInterface**) device,
  208379. openInExclusiveMode ? kIOHIDOptionsTypeSeizeDevice
  208380. : kIOHIDOptionsTypeNone) == KERN_SUCCESS)
  208381. {
  208382. queue = (*(IOHIDDeviceInterface**) device)->allocQueue ((IOHIDDeviceInterface**) device);
  208383. if (queue != 0)
  208384. {
  208385. (*(IOHIDQueueInterface**) queue)->create ((IOHIDQueueInterface**) queue, 0, 12);
  208386. for (int i = 0; i < cookies.size(); ++i)
  208387. {
  208388. IOHIDElementCookie cookie = (IOHIDElementCookie) cookies.getUnchecked(i);
  208389. (*(IOHIDQueueInterface**) queue)->addElement ((IOHIDQueueInterface**) queue, cookie, 0);
  208390. }
  208391. CFRunLoopSourceRef eventSource;
  208392. if ((*(IOHIDQueueInterface**) queue)
  208393. ->createAsyncEventSource ((IOHIDQueueInterface**) queue, &eventSource) == KERN_SUCCESS)
  208394. {
  208395. if ((*(IOHIDQueueInterface**) queue)->setEventCallout ((IOHIDQueueInterface**) queue,
  208396. appleRemoteQueueCallback, this, 0) == KERN_SUCCESS)
  208397. {
  208398. CFRunLoopAddSource (CFRunLoopGetCurrent(), eventSource, kCFRunLoopDefaultMode);
  208399. (*(IOHIDQueueInterface**) queue)->start ((IOHIDQueueInterface**) queue);
  208400. return true;
  208401. }
  208402. }
  208403. }
  208404. }
  208405. return false;
  208406. }
  208407. void AppleRemoteDevice::handleCallbackInternal()
  208408. {
  208409. int totalValues = 0;
  208410. AbsoluteTime nullTime = { 0, 0 };
  208411. char cookies [12];
  208412. int numCookies = 0;
  208413. while (numCookies < numElementsInArray (cookies))
  208414. {
  208415. IOHIDEventStruct e;
  208416. if ((*(IOHIDQueueInterface**) queue)->getNextEvent ((IOHIDQueueInterface**) queue, &e, nullTime, 0) != kIOReturnSuccess)
  208417. break;
  208418. if ((int) e.elementCookie == 19)
  208419. {
  208420. remoteId = e.value;
  208421. buttonPressed (switched, false);
  208422. }
  208423. else
  208424. {
  208425. totalValues += e.value;
  208426. cookies [numCookies++] = (char) (pointer_sized_int) e.elementCookie;
  208427. }
  208428. }
  208429. cookies [numCookies++] = 0;
  208430. //DBG (String::toHexString ((uint8*) cookies, numCookies, 1) + " " + String (totalValues));
  208431. static const char buttonPatterns[] =
  208432. {
  208433. 0x1f, 0x14, 0x12, 0x1f, 0x14, 0x12, 0,
  208434. 0x1f, 0x15, 0x12, 0x1f, 0x15, 0x12, 0,
  208435. 0x1f, 0x1d, 0x1c, 0x12, 0,
  208436. 0x1f, 0x1e, 0x1c, 0x12, 0,
  208437. 0x1f, 0x16, 0x12, 0x1f, 0x16, 0x12, 0,
  208438. 0x1f, 0x17, 0x12, 0x1f, 0x17, 0x12, 0,
  208439. 0x1f, 0x12, 0x04, 0x02, 0,
  208440. 0x1f, 0x12, 0x03, 0x02, 0,
  208441. 0x1f, 0x12, 0x1f, 0x12, 0,
  208442. 0x23, 0x1f, 0x12, 0x23, 0x1f, 0x12, 0,
  208443. 19, 0
  208444. };
  208445. int buttonNum = (int) menuButton;
  208446. int i = 0;
  208447. while (i < numElementsInArray (buttonPatterns))
  208448. {
  208449. if (strcmp (cookies, buttonPatterns + i) == 0)
  208450. {
  208451. buttonPressed ((ButtonType) buttonNum, totalValues > 0);
  208452. break;
  208453. }
  208454. i += (int) strlen (buttonPatterns + i) + 1;
  208455. ++buttonNum;
  208456. }
  208457. }
  208458. #endif
  208459. /********* End of inlined file: juce_mac_AppleRemote.mm *********/
  208460. /********* Start of inlined file: juce_mac_OpenGLComponent.mm *********/
  208461. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  208462. // compiled on its own).
  208463. #if JUCE_INCLUDED_FILE && JUCE_OPENGL
  208464. #if JUCE_MAC
  208465. END_JUCE_NAMESPACE
  208466. #define ThreadSafeNSOpenGLView MakeObjCClassName(ThreadSafeNSOpenGLView)
  208467. @interface ThreadSafeNSOpenGLView : NSOpenGLView
  208468. {
  208469. CriticalSection* contextLock;
  208470. bool needsUpdate;
  208471. }
  208472. - (id) initWithFrame: (NSRect) frameRect pixelFormat: (NSOpenGLPixelFormat*) format;
  208473. - (bool) makeActive;
  208474. - (void) makeInactive;
  208475. - (void) reshape;
  208476. @end
  208477. @implementation ThreadSafeNSOpenGLView
  208478. - (id) initWithFrame: (NSRect) frameRect
  208479. pixelFormat: (NSOpenGLPixelFormat*) format
  208480. {
  208481. contextLock = new CriticalSection();
  208482. self = [super initWithFrame: frameRect pixelFormat: format];
  208483. if (self != nil)
  208484. [[NSNotificationCenter defaultCenter] addObserver: self
  208485. selector: @selector (_surfaceNeedsUpdate:)
  208486. name: NSViewGlobalFrameDidChangeNotification
  208487. object: self];
  208488. return self;
  208489. }
  208490. - (void) dealloc
  208491. {
  208492. [[NSNotificationCenter defaultCenter] removeObserver: self];
  208493. delete contextLock;
  208494. [super dealloc];
  208495. }
  208496. - (bool) makeActive
  208497. {
  208498. const ScopedLock sl (*contextLock);
  208499. if ([self openGLContext] == 0)
  208500. return false;
  208501. [[self openGLContext] makeCurrentContext];
  208502. if (needsUpdate)
  208503. {
  208504. [super update];
  208505. needsUpdate = false;
  208506. }
  208507. return true;
  208508. }
  208509. - (void) makeInactive
  208510. {
  208511. const ScopedLock sl (*contextLock);
  208512. [NSOpenGLContext clearCurrentContext];
  208513. }
  208514. - (void) _surfaceNeedsUpdate: (NSNotification*) notification
  208515. {
  208516. const ScopedLock sl (*contextLock);
  208517. needsUpdate = true;
  208518. }
  208519. - (void) update
  208520. {
  208521. const ScopedLock sl (*contextLock);
  208522. needsUpdate = true;
  208523. }
  208524. - (void) reshape
  208525. {
  208526. const ScopedLock sl (*contextLock);
  208527. needsUpdate = true;
  208528. }
  208529. @end
  208530. BEGIN_JUCE_NAMESPACE
  208531. class WindowedGLContext : public OpenGLContext
  208532. {
  208533. public:
  208534. WindowedGLContext (Component* const component,
  208535. const OpenGLPixelFormat& pixelFormat_,
  208536. NSOpenGLContext* sharedContext)
  208537. : renderContext (0),
  208538. pixelFormat (pixelFormat_)
  208539. {
  208540. jassert (component != 0);
  208541. NSOpenGLPixelFormatAttribute attribs [64];
  208542. int n = 0;
  208543. attribs[n++] = NSOpenGLPFADoubleBuffer;
  208544. attribs[n++] = NSOpenGLPFAAccelerated;
  208545. attribs[n++] = NSOpenGLPFAMPSafe; // NSOpenGLPFAAccelerated, NSOpenGLPFAMultiScreen, NSOpenGLPFASingleRenderer
  208546. attribs[n++] = NSOpenGLPFAColorSize;
  208547. attribs[n++] = (NSOpenGLPixelFormatAttribute) jmax (pixelFormat.redBits,
  208548. pixelFormat.greenBits,
  208549. pixelFormat.blueBits);
  208550. attribs[n++] = NSOpenGLPFAAlphaSize;
  208551. attribs[n++] = (NSOpenGLPixelFormatAttribute) pixelFormat.alphaBits;
  208552. attribs[n++] = NSOpenGLPFADepthSize;
  208553. attribs[n++] = (NSOpenGLPixelFormatAttribute) pixelFormat.depthBufferBits;
  208554. attribs[n++] = NSOpenGLPFAStencilSize;
  208555. attribs[n++] = (NSOpenGLPixelFormatAttribute) pixelFormat.stencilBufferBits;
  208556. attribs[n++] = NSOpenGLPFAAccumSize;
  208557. attribs[n++] = (NSOpenGLPixelFormatAttribute) jmax (pixelFormat.accumulationBufferRedBits,
  208558. pixelFormat.accumulationBufferGreenBits,
  208559. pixelFormat.accumulationBufferBlueBits,
  208560. pixelFormat.accumulationBufferAlphaBits);
  208561. // xxx not sure how to do fullSceneAntiAliasingNumSamples..
  208562. attribs[n++] = NSOpenGLPFASampleBuffers;
  208563. attribs[n++] = (NSOpenGLPixelFormatAttribute) 1;
  208564. attribs[n++] = NSOpenGLPFAClosestPolicy;
  208565. attribs[n++] = NSOpenGLPFANoRecovery;
  208566. attribs[n++] = (NSOpenGLPixelFormatAttribute) 0;
  208567. NSOpenGLPixelFormat* format
  208568. = [[NSOpenGLPixelFormat alloc] initWithAttributes: attribs];
  208569. view = [[ThreadSafeNSOpenGLView alloc] initWithFrame: NSMakeRect (0, 0, 100.0f, 100.0f)
  208570. pixelFormat: format];
  208571. renderContext = [[[NSOpenGLContext alloc] initWithFormat: format
  208572. shareContext: sharedContext] autorelease];
  208573. const GLint swapInterval = 1;
  208574. [renderContext setValues: &swapInterval forParameter: NSOpenGLCPSwapInterval];
  208575. [view setOpenGLContext: renderContext];
  208576. [renderContext setView: view];
  208577. [format release];
  208578. viewHolder = new NSViewComponentInternal (view, component);
  208579. }
  208580. ~WindowedGLContext()
  208581. {
  208582. makeInactive();
  208583. [renderContext clearDrawable];
  208584. viewHolder = 0;
  208585. }
  208586. bool makeActive() const throw()
  208587. {
  208588. jassert (renderContext != 0);
  208589. [view makeActive];
  208590. return isActive();
  208591. }
  208592. bool makeInactive() const throw()
  208593. {
  208594. [view makeInactive];
  208595. return true;
  208596. }
  208597. bool isActive() const throw()
  208598. {
  208599. return [NSOpenGLContext currentContext] == renderContext;
  208600. }
  208601. const OpenGLPixelFormat getPixelFormat() const { return pixelFormat; }
  208602. void* getRawContext() const throw() { return renderContext; }
  208603. void updateWindowPosition (int x, int y, int w, int h, int outerWindowHeight)
  208604. {
  208605. }
  208606. void swapBuffers()
  208607. {
  208608. [renderContext flushBuffer];
  208609. }
  208610. bool setSwapInterval (const int numFramesPerSwap)
  208611. {
  208612. [renderContext setValues: (const GLint*) &numFramesPerSwap
  208613. forParameter: NSOpenGLCPSwapInterval];
  208614. return true;
  208615. }
  208616. int getSwapInterval() const
  208617. {
  208618. GLint numFrames = 0;
  208619. [renderContext getValues: &numFrames
  208620. forParameter: NSOpenGLCPSwapInterval];
  208621. return numFrames;
  208622. }
  208623. void repaint()
  208624. {
  208625. // we need to invalidate the juce view that holds this gl view, to make it
  208626. // cause a repaint callback
  208627. NSView* v = (NSView*) viewHolder->view;
  208628. NSRect r = [v frame];
  208629. // bit of a bodge here.. if we only invalidate the area of the gl component,
  208630. // it's completely covered by the NSOpenGLView, so the OS throws away the
  208631. // repaint message, thus never causing our paint() callback, and never repainting
  208632. // the comp. So invalidating just a little bit around the edge helps..
  208633. [[v superview] setNeedsDisplayInRect: NSInsetRect (r, -2.0f, -2.0f)];
  208634. }
  208635. void* getNativeWindowHandle() const { return viewHolder->view; }
  208636. juce_UseDebuggingNewOperator
  208637. NSOpenGLContext* renderContext;
  208638. ThreadSafeNSOpenGLView* view;
  208639. private:
  208640. OpenGLPixelFormat pixelFormat;
  208641. ScopedPointer <NSViewComponentInternal> viewHolder;
  208642. WindowedGLContext (const WindowedGLContext&);
  208643. const WindowedGLContext& operator= (const WindowedGLContext&);
  208644. };
  208645. OpenGLContext* OpenGLContext::createContextForWindow (Component* const component,
  208646. const OpenGLPixelFormat& pixelFormat,
  208647. const OpenGLContext* const contextToShareWith)
  208648. {
  208649. ScopedPointer <WindowedGLContext> c (new WindowedGLContext (component, pixelFormat,
  208650. contextToShareWith != 0 ? (NSOpenGLContext*) contextToShareWith->getRawContext() : 0));
  208651. return (c->renderContext != 0) ? c.release() : 0;
  208652. }
  208653. void* OpenGLComponent::getNativeWindowHandle() const
  208654. {
  208655. return context != 0 ? ((WindowedGLContext*) context)->getNativeWindowHandle()
  208656. : 0;
  208657. }
  208658. void juce_glViewport (const int w, const int h)
  208659. {
  208660. glViewport (0, 0, w, h);
  208661. }
  208662. void OpenGLPixelFormat::getAvailablePixelFormats (Component* /*component*/,
  208663. OwnedArray <OpenGLPixelFormat>& results)
  208664. {
  208665. /* GLint attribs [64];
  208666. int n = 0;
  208667. attribs[n++] = AGL_RGBA;
  208668. attribs[n++] = AGL_DOUBLEBUFFER;
  208669. attribs[n++] = AGL_ACCELERATED;
  208670. attribs[n++] = AGL_NO_RECOVERY;
  208671. attribs[n++] = AGL_NONE;
  208672. AGLPixelFormat p = aglChoosePixelFormat (0, 0, attribs);
  208673. while (p != 0)
  208674. {
  208675. OpenGLPixelFormat* const pf = new OpenGLPixelFormat();
  208676. pf->redBits = getAGLAttribute (p, AGL_RED_SIZE);
  208677. pf->greenBits = getAGLAttribute (p, AGL_GREEN_SIZE);
  208678. pf->blueBits = getAGLAttribute (p, AGL_BLUE_SIZE);
  208679. pf->alphaBits = getAGLAttribute (p, AGL_ALPHA_SIZE);
  208680. pf->depthBufferBits = getAGLAttribute (p, AGL_DEPTH_SIZE);
  208681. pf->stencilBufferBits = getAGLAttribute (p, AGL_STENCIL_SIZE);
  208682. pf->accumulationBufferRedBits = getAGLAttribute (p, AGL_ACCUM_RED_SIZE);
  208683. pf->accumulationBufferGreenBits = getAGLAttribute (p, AGL_ACCUM_GREEN_SIZE);
  208684. pf->accumulationBufferBlueBits = getAGLAttribute (p, AGL_ACCUM_BLUE_SIZE);
  208685. pf->accumulationBufferAlphaBits = getAGLAttribute (p, AGL_ACCUM_ALPHA_SIZE);
  208686. results.add (pf);
  208687. p = aglNextPixelFormat (p);
  208688. }*/
  208689. //jassertfalse //xxx can't see how you do this in cocoa!
  208690. }
  208691. #else
  208692. OpenGLContext* OpenGLContext::createContextForWindow (Component* const component,
  208693. const OpenGLPixelFormat& pixelFormat,
  208694. const OpenGLContext* const contextToShareWith)
  208695. {
  208696. return 0;
  208697. }
  208698. void juce_glViewport (const int w, const int h)
  208699. {
  208700. //glViewport (0, 0, w, h);
  208701. }
  208702. #endif
  208703. #endif
  208704. /********* End of inlined file: juce_mac_OpenGLComponent.mm *********/
  208705. /********* Start of inlined file: juce_mac_MainMenu.mm *********/
  208706. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  208707. // compiled on its own).
  208708. #if JUCE_INCLUDED_FILE
  208709. class JuceMainMenuHandler;
  208710. END_JUCE_NAMESPACE
  208711. using namespace JUCE_NAMESPACE;
  208712. #define JuceMenuCallback MakeObjCClassName(JuceMenuCallback)
  208713. #if defined (MAC_OS_X_VERSION_10_6) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
  208714. @interface JuceMenuCallback : NSObject <NSMenuDelegate>
  208715. #else
  208716. @interface JuceMenuCallback : NSObject
  208717. #endif
  208718. {
  208719. JuceMainMenuHandler* owner;
  208720. }
  208721. - (JuceMenuCallback*) initWithOwner: (JuceMainMenuHandler*) owner_;
  208722. - (void) dealloc;
  208723. - (void) menuItemInvoked: (id) menu;
  208724. - (void) menuNeedsUpdate: (NSMenu*) menu;
  208725. @end
  208726. BEGIN_JUCE_NAMESPACE
  208727. class JuceMainMenuHandler : private MenuBarModelListener,
  208728. private DeletedAtShutdown
  208729. {
  208730. public:
  208731. static JuceMainMenuHandler* instance;
  208732. JuceMainMenuHandler()
  208733. : currentModel (0),
  208734. lastUpdateTime (0)
  208735. {
  208736. callback = [[JuceMenuCallback alloc] initWithOwner: this];
  208737. }
  208738. ~JuceMainMenuHandler()
  208739. {
  208740. setMenu (0);
  208741. jassert (instance == this);
  208742. instance = 0;
  208743. [callback release];
  208744. }
  208745. void setMenu (MenuBarModel* const newMenuBarModel)
  208746. {
  208747. if (currentModel != newMenuBarModel)
  208748. {
  208749. if (currentModel != 0)
  208750. currentModel->removeListener (this);
  208751. currentModel = newMenuBarModel;
  208752. if (currentModel != 0)
  208753. currentModel->addListener (this);
  208754. menuBarItemsChanged (0);
  208755. }
  208756. }
  208757. void addSubMenu (NSMenu* parent, const PopupMenu& child,
  208758. const String& name, const int menuId, const int tag)
  208759. {
  208760. NSMenuItem* item = [parent addItemWithTitle: juceStringToNS (name)
  208761. action: nil
  208762. keyEquivalent: @""];
  208763. [item setTag: tag];
  208764. NSMenu* sub = createMenu (child, name, menuId, tag);
  208765. [parent setSubmenu: sub forItem: item];
  208766. [sub setAutoenablesItems: false];
  208767. [sub release];
  208768. }
  208769. void updateSubMenu (NSMenuItem* parentItem, const PopupMenu& menuToCopy,
  208770. const String& name, const int menuId, const int tag)
  208771. {
  208772. [parentItem setTag: tag];
  208773. NSMenu* menu = [parentItem submenu];
  208774. [menu setTitle: juceStringToNS (name)];
  208775. while ([menu numberOfItems] > 0)
  208776. [menu removeItemAtIndex: 0];
  208777. PopupMenu::MenuItemIterator iter (menuToCopy);
  208778. while (iter.next())
  208779. addMenuItem (iter, menu, menuId, tag);
  208780. [menu setAutoenablesItems: false];
  208781. [menu update];
  208782. }
  208783. void menuBarItemsChanged (MenuBarModel*)
  208784. {
  208785. lastUpdateTime = Time::getMillisecondCounter();
  208786. StringArray menuNames;
  208787. if (currentModel != 0)
  208788. menuNames = currentModel->getMenuBarNames();
  208789. NSMenu* menuBar = [NSApp mainMenu];
  208790. while ([menuBar numberOfItems] > 1 + menuNames.size())
  208791. [menuBar removeItemAtIndex: [menuBar numberOfItems] - 1];
  208792. int menuId = 1;
  208793. for (int i = 0; i < menuNames.size(); ++i)
  208794. {
  208795. const PopupMenu menu (currentModel->getMenuForIndex (i, menuNames [i]));
  208796. if (i >= [menuBar numberOfItems] - 1)
  208797. addSubMenu (menuBar, menu, menuNames[i], menuId, i);
  208798. else
  208799. updateSubMenu ([menuBar itemAtIndex: 1 + i], menu, menuNames[i], menuId, i);
  208800. }
  208801. }
  208802. static void flashMenuBar (NSMenu* menu)
  208803. {
  208804. [menu retain];
  208805. const unichar f35Key = NSF35FunctionKey;
  208806. NSString* f35String = [NSString stringWithCharacters: &f35Key length: 1];
  208807. NSMenuItem* item = [[NSMenuItem alloc] initWithTitle: @"x"
  208808. action: nil
  208809. keyEquivalent: f35String];
  208810. [item setTarget: nil];
  208811. [menu insertItem: item atIndex: [menu numberOfItems]];
  208812. [item release];
  208813. NSEvent* f35Event = [NSEvent keyEventWithType: NSKeyDown
  208814. location: NSZeroPoint
  208815. modifierFlags: NSCommandKeyMask
  208816. timestamp: 0
  208817. windowNumber: 0
  208818. context: [NSGraphicsContext currentContext]
  208819. characters: f35String
  208820. charactersIgnoringModifiers: f35String
  208821. isARepeat: NO
  208822. keyCode: 0];
  208823. [menu performKeyEquivalent: f35Event];
  208824. if ([menu indexOfItem: item] >= 0)
  208825. [menu removeItem: item]; // (this throws if the item isn't actually in the menu)
  208826. [menu release];
  208827. }
  208828. static NSMenuItem* findMenuItem (NSMenu* const menu, const ApplicationCommandTarget::InvocationInfo& info)
  208829. {
  208830. for (NSInteger i = [menu numberOfItems]; --i >= 0;)
  208831. {
  208832. NSMenuItem* m = [menu itemAtIndex: i];
  208833. if ([m tag] == info.commandID)
  208834. return m;
  208835. if ([m submenu] != 0)
  208836. {
  208837. NSMenuItem* found = findMenuItem ([m submenu], info);
  208838. if (found != 0)
  208839. return found;
  208840. }
  208841. }
  208842. return 0;
  208843. }
  208844. void menuCommandInvoked (MenuBarModel*, const ApplicationCommandTarget::InvocationInfo& info)
  208845. {
  208846. NSMenuItem* item = findMenuItem ([NSApp mainMenu], info);
  208847. if (item != 0)
  208848. flashMenuBar ([item menu]);
  208849. }
  208850. void updateMenus()
  208851. {
  208852. if (Time::getMillisecondCounter() > lastUpdateTime + 500)
  208853. menuBarItemsChanged (0);
  208854. }
  208855. void invoke (const int commandId, ApplicationCommandManager* const commandManager, const int topLevelIndex) const
  208856. {
  208857. if (currentModel != 0)
  208858. {
  208859. if (commandManager != 0)
  208860. {
  208861. ApplicationCommandTarget::InvocationInfo info (commandId);
  208862. info.invocationMethod = ApplicationCommandTarget::InvocationInfo::fromMenu;
  208863. commandManager->invoke (info, true);
  208864. }
  208865. currentModel->menuItemSelected (commandId, topLevelIndex);
  208866. }
  208867. }
  208868. MenuBarModel* currentModel;
  208869. uint32 lastUpdateTime;
  208870. void addMenuItem (PopupMenu::MenuItemIterator& iter, NSMenu* menuToAddTo,
  208871. const int topLevelMenuId, const int topLevelIndex)
  208872. {
  208873. NSString* text = juceStringToNS (iter.itemName.upToFirstOccurrenceOf (T("<end>"), false, true));
  208874. if (text == 0)
  208875. text = @"";
  208876. if (iter.isSeparator)
  208877. {
  208878. [menuToAddTo addItem: [NSMenuItem separatorItem]];
  208879. }
  208880. else if (iter.isSectionHeader)
  208881. {
  208882. NSMenuItem* item = [menuToAddTo addItemWithTitle: text
  208883. action: nil
  208884. keyEquivalent: @""];
  208885. [item setEnabled: false];
  208886. }
  208887. else if (iter.subMenu != 0)
  208888. {
  208889. NSMenuItem* item = [menuToAddTo addItemWithTitle: text
  208890. action: nil
  208891. keyEquivalent: @""];
  208892. [item setTag: iter.itemId];
  208893. [item setEnabled: iter.isEnabled];
  208894. NSMenu* sub = createMenu (*iter.subMenu, iter.itemName, topLevelMenuId, topLevelIndex);
  208895. [sub setDelegate: nil];
  208896. [menuToAddTo setSubmenu: sub forItem: item];
  208897. [sub release];
  208898. }
  208899. else
  208900. {
  208901. NSMenuItem* item = [menuToAddTo addItemWithTitle: text
  208902. action: @selector (menuItemInvoked:)
  208903. keyEquivalent: @""];
  208904. [item setTag: iter.itemId];
  208905. [item setEnabled: iter.isEnabled];
  208906. [item setState: iter.isTicked ? NSOnState : NSOffState];
  208907. [item setTarget: (id) callback];
  208908. NSMutableArray* info = [NSMutableArray arrayWithObject: [NSNumber numberWithUnsignedLongLong: (pointer_sized_int) (void*) iter.commandManager]];
  208909. [info addObject: [NSNumber numberWithInt: topLevelIndex]];
  208910. [item setRepresentedObject: info];
  208911. if (iter.commandManager != 0)
  208912. {
  208913. const Array <KeyPress> keyPresses (iter.commandManager->getKeyMappings()
  208914. ->getKeyPressesAssignedToCommand (iter.itemId));
  208915. if (keyPresses.size() > 0)
  208916. {
  208917. const KeyPress& kp = keyPresses.getReference(0);
  208918. juce_wchar key = kp.getTextCharacter();
  208919. if (kp.getKeyCode() == KeyPress::backspaceKey)
  208920. key = NSBackspaceCharacter;
  208921. else if (kp.getKeyCode() == KeyPress::deleteKey)
  208922. key = NSDeleteCharacter;
  208923. else if (key == 0)
  208924. key = (juce_wchar) kp.getKeyCode();
  208925. unsigned int mods = 0;
  208926. if (kp.getModifiers().isShiftDown())
  208927. mods |= NSShiftKeyMask;
  208928. if (kp.getModifiers().isCtrlDown())
  208929. mods |= NSControlKeyMask;
  208930. if (kp.getModifiers().isAltDown())
  208931. mods |= NSAlternateKeyMask;
  208932. if (kp.getModifiers().isCommandDown())
  208933. mods |= NSCommandKeyMask;
  208934. [item setKeyEquivalent: juceStringToNS (String::charToString (key))];
  208935. [item setKeyEquivalentModifierMask: mods];
  208936. }
  208937. }
  208938. }
  208939. }
  208940. JuceMenuCallback* callback;
  208941. private:
  208942. NSMenu* createMenu (const PopupMenu menu,
  208943. const String& menuName,
  208944. const int topLevelMenuId,
  208945. const int topLevelIndex)
  208946. {
  208947. NSMenu* m = [[NSMenu alloc] initWithTitle: juceStringToNS (menuName)];
  208948. [m setAutoenablesItems: false];
  208949. [m setDelegate: callback];
  208950. PopupMenu::MenuItemIterator iter (menu);
  208951. while (iter.next())
  208952. addMenuItem (iter, m, topLevelMenuId, topLevelIndex);
  208953. [m update];
  208954. return m;
  208955. }
  208956. };
  208957. JuceMainMenuHandler* JuceMainMenuHandler::instance = 0;
  208958. END_JUCE_NAMESPACE
  208959. @implementation JuceMenuCallback
  208960. - (JuceMenuCallback*) initWithOwner: (JuceMainMenuHandler*) owner_
  208961. {
  208962. [super init];
  208963. owner = owner_;
  208964. return self;
  208965. }
  208966. - (void) dealloc
  208967. {
  208968. [super dealloc];
  208969. }
  208970. - (void) menuItemInvoked: (id) menu
  208971. {
  208972. NSMenuItem* item = (NSMenuItem*) menu;
  208973. if ([[item representedObject] isKindOfClass: [NSArray class]])
  208974. {
  208975. // 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
  208976. // our own components, which may have wanted to intercept it. So, rather than dispatching directly, we'll feed it back
  208977. // into the focused component and let it trigger the menu item indirectly.
  208978. NSEvent* e = [NSApp currentEvent];
  208979. if ([e type] == NSKeyDown || [e type] == NSKeyUp)
  208980. {
  208981. if (JUCE_NAMESPACE::Component::getCurrentlyFocusedComponent()->isValidComponent())
  208982. {
  208983. JUCE_NAMESPACE::NSViewComponentPeer* peer = dynamic_cast <JUCE_NAMESPACE::NSViewComponentPeer*> (JUCE_NAMESPACE::Component::getCurrentlyFocusedComponent()->getPeer());
  208984. if (peer != 0)
  208985. {
  208986. if ([e type] == NSKeyDown)
  208987. peer->redirectKeyDown (e);
  208988. else
  208989. peer->redirectKeyUp (e);
  208990. return;
  208991. }
  208992. }
  208993. }
  208994. NSArray* info = (NSArray*) [item representedObject];
  208995. owner->invoke ((int) [item tag],
  208996. (ApplicationCommandManager*) (pointer_sized_int)
  208997. [((NSNumber*) [info objectAtIndex: 0]) unsignedLongLongValue],
  208998. (int) [((NSNumber*) [info objectAtIndex: 1]) intValue]);
  208999. }
  209000. }
  209001. - (void) menuNeedsUpdate: (NSMenu*) menu;
  209002. {
  209003. if (JuceMainMenuHandler::instance != 0)
  209004. JuceMainMenuHandler::instance->updateMenus();
  209005. }
  209006. @end
  209007. BEGIN_JUCE_NAMESPACE
  209008. static NSMenu* createStandardAppMenu (NSMenu* menu, const String& appName,
  209009. const PopupMenu* extraItems)
  209010. {
  209011. if (extraItems != 0 && JuceMainMenuHandler::instance != 0 && extraItems->getNumItems() > 0)
  209012. {
  209013. PopupMenu::MenuItemIterator iter (*extraItems);
  209014. while (iter.next())
  209015. JuceMainMenuHandler::instance->addMenuItem (iter, menu, 0, -1);
  209016. [menu addItem: [NSMenuItem separatorItem]];
  209017. }
  209018. NSMenuItem* item;
  209019. // Services...
  209020. item = [[NSMenuItem alloc] initWithTitle: NSLocalizedString (@"Services", nil)
  209021. action: nil keyEquivalent: @""];
  209022. [menu addItem: item];
  209023. [item release];
  209024. NSMenu* servicesMenu = [[NSMenu alloc] initWithTitle: @"Services"];
  209025. [menu setSubmenu: servicesMenu forItem: item];
  209026. [NSApp setServicesMenu: servicesMenu];
  209027. [servicesMenu release];
  209028. [menu addItem: [NSMenuItem separatorItem]];
  209029. // Hide + Show stuff...
  209030. item = [[NSMenuItem alloc] initWithTitle: juceStringToNS ("Hide " + appName)
  209031. action: @selector (hide:) keyEquivalent: @"h"];
  209032. [item setTarget: NSApp];
  209033. [menu addItem: item];
  209034. [item release];
  209035. item = [[NSMenuItem alloc] initWithTitle: NSLocalizedString (@"Hide Others", nil)
  209036. action: @selector (hideOtherApplications:) keyEquivalent: @"h"];
  209037. [item setKeyEquivalentModifierMask: NSCommandKeyMask | NSAlternateKeyMask];
  209038. [item setTarget: NSApp];
  209039. [menu addItem: item];
  209040. [item release];
  209041. item = [[NSMenuItem alloc] initWithTitle: NSLocalizedString (@"Show All", nil)
  209042. action: @selector (unhideAllApplications:) keyEquivalent: @""];
  209043. [item setTarget: NSApp];
  209044. [menu addItem: item];
  209045. [item release];
  209046. [menu addItem: [NSMenuItem separatorItem]];
  209047. // Quit item....
  209048. item = [[NSMenuItem alloc] initWithTitle: juceStringToNS ("Quit " + appName)
  209049. action: @selector (terminate:) keyEquivalent: @"q"];
  209050. [item setTarget: NSApp];
  209051. [menu addItem: item];
  209052. [item release];
  209053. return menu;
  209054. }
  209055. // Since our app has no NIB, this initialises a standard app menu...
  209056. static void rebuildMainMenu (const PopupMenu* extraItems)
  209057. {
  209058. // this can't be used in a plugin!
  209059. jassert (JUCEApplication::getInstance() != 0);
  209060. if (JUCEApplication::getInstance() != 0)
  209061. {
  209062. const ScopedAutoReleasePool pool;
  209063. NSMenu* mainMenu = [[NSMenu alloc] initWithTitle: @"MainMenu"];
  209064. NSMenuItem* item = [mainMenu addItemWithTitle: @"Apple" action: nil keyEquivalent: @""];
  209065. NSMenu* appMenu = [[NSMenu alloc] initWithTitle: @"Apple"];
  209066. [NSApp performSelector: @selector (setAppleMenu:) withObject: appMenu];
  209067. [mainMenu setSubmenu: appMenu forItem: item];
  209068. [NSApp setMainMenu: mainMenu];
  209069. createStandardAppMenu (appMenu, JUCEApplication::getInstance()->getApplicationName(), extraItems);
  209070. [appMenu release];
  209071. [mainMenu release];
  209072. }
  209073. }
  209074. void MenuBarModel::setMacMainMenu (MenuBarModel* newMenuBarModel,
  209075. const PopupMenu* extraAppleMenuItems)
  209076. {
  209077. if (getMacMainMenu() != newMenuBarModel)
  209078. {
  209079. const ScopedAutoReleasePool pool;
  209080. if (newMenuBarModel == 0)
  209081. {
  209082. delete JuceMainMenuHandler::instance;
  209083. jassert (JuceMainMenuHandler::instance == 0); // should be zeroed in the destructor
  209084. jassert (extraAppleMenuItems == 0); // you can't specify some extra items without also supplying a model
  209085. extraAppleMenuItems = 0;
  209086. }
  209087. else
  209088. {
  209089. if (JuceMainMenuHandler::instance == 0)
  209090. JuceMainMenuHandler::instance = new JuceMainMenuHandler();
  209091. JuceMainMenuHandler::instance->setMenu (newMenuBarModel);
  209092. }
  209093. }
  209094. rebuildMainMenu (extraAppleMenuItems);
  209095. if (newMenuBarModel != 0)
  209096. newMenuBarModel->menuItemsChanged();
  209097. }
  209098. MenuBarModel* MenuBarModel::getMacMainMenu()
  209099. {
  209100. return JuceMainMenuHandler::instance != 0
  209101. ? JuceMainMenuHandler::instance->currentModel : 0;
  209102. }
  209103. void initialiseMainMenu()
  209104. {
  209105. if (JUCEApplication::getInstance() != 0) // only needed in an app
  209106. rebuildMainMenu (0);
  209107. }
  209108. #endif
  209109. /********* End of inlined file: juce_mac_MainMenu.mm *********/
  209110. /********* Start of inlined file: juce_mac_FileChooser.mm *********/
  209111. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  209112. // compiled on its own).
  209113. #if JUCE_INCLUDED_FILE
  209114. #if JUCE_MAC
  209115. END_JUCE_NAMESPACE
  209116. using namespace JUCE_NAMESPACE;
  209117. #define JuceFileChooserDelegate MakeObjCClassName(JuceFileChooserDelegate)
  209118. #if defined (MAC_OS_X_VERSION_10_6) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
  209119. @interface JuceFileChooserDelegate : NSObject <NSOpenSavePanelDelegate>
  209120. #else
  209121. @interface JuceFileChooserDelegate : NSObject
  209122. #endif
  209123. {
  209124. StringArray* filters;
  209125. }
  209126. - (JuceFileChooserDelegate*) initWithFilters: (StringArray*) filters_;
  209127. - (void) dealloc;
  209128. - (BOOL) panel: (id) sender shouldShowFilename: (NSString*) filename;
  209129. @end
  209130. @implementation JuceFileChooserDelegate
  209131. - (JuceFileChooserDelegate*) initWithFilters: (StringArray*) filters_
  209132. {
  209133. [super init];
  209134. filters = filters_;
  209135. return self;
  209136. }
  209137. - (void) dealloc
  209138. {
  209139. delete filters;
  209140. [super dealloc];
  209141. }
  209142. - (BOOL) panel: (id) sender shouldShowFilename: (NSString*) filename
  209143. {
  209144. const String fname (nsStringToJuce (filename));
  209145. for (int i = filters->size(); --i >= 0;)
  209146. if (fname.matchesWildcard ((*filters)[i], true))
  209147. return true;
  209148. return File (fname).isDirectory();
  209149. }
  209150. @end
  209151. BEGIN_JUCE_NAMESPACE
  209152. void FileChooser::showPlatformDialog (Array<File>& results,
  209153. const String& title,
  209154. const File& currentFileOrDirectory,
  209155. const String& filter,
  209156. bool selectsDirectory,
  209157. bool selectsFiles,
  209158. bool isSaveDialogue,
  209159. bool warnAboutOverwritingExistingFiles,
  209160. bool selectMultipleFiles,
  209161. FilePreviewComponent* extraInfoComponent)
  209162. {
  209163. const ScopedAutoReleasePool pool;
  209164. StringArray* filters = new StringArray();
  209165. filters->addTokens (filter.replaceCharacters (T(",:"), T(";;")), T(";"), 0);
  209166. filters->trim();
  209167. filters->removeEmptyStrings();
  209168. JuceFileChooserDelegate* delegate = [[JuceFileChooserDelegate alloc] initWithFilters: filters];
  209169. [delegate autorelease];
  209170. NSSavePanel* panel = isSaveDialogue ? [NSSavePanel savePanel]
  209171. : [NSOpenPanel openPanel];
  209172. [panel setTitle: juceStringToNS (title)];
  209173. if (! isSaveDialogue)
  209174. {
  209175. NSOpenPanel* openPanel = (NSOpenPanel*) panel;
  209176. [openPanel setCanChooseDirectories: selectsDirectory];
  209177. [openPanel setCanChooseFiles: selectsFiles];
  209178. [openPanel setAllowsMultipleSelection: selectMultipleFiles];
  209179. }
  209180. [panel setDelegate: delegate];
  209181. String directory, filename;
  209182. if (currentFileOrDirectory.isDirectory())
  209183. {
  209184. directory = currentFileOrDirectory.getFullPathName();
  209185. }
  209186. else
  209187. {
  209188. directory = currentFileOrDirectory.getParentDirectory().getFullPathName();
  209189. filename = currentFileOrDirectory.getFileName();
  209190. }
  209191. if ([panel runModalForDirectory: juceStringToNS (directory)
  209192. file: juceStringToNS (filename)]
  209193. == NSOKButton)
  209194. {
  209195. if (isSaveDialogue)
  209196. {
  209197. results.add (File (nsStringToJuce ([panel filename])));
  209198. }
  209199. else
  209200. {
  209201. NSOpenPanel* openPanel = (NSOpenPanel*) panel;
  209202. NSArray* urls = [openPanel filenames];
  209203. for (unsigned int i = 0; i < [urls count]; ++i)
  209204. {
  209205. NSString* f = [urls objectAtIndex: i];
  209206. results.add (File (nsStringToJuce (f)));
  209207. }
  209208. }
  209209. }
  209210. [panel setDelegate: nil];
  209211. }
  209212. #else
  209213. void FileChooser::showPlatformDialog (Array<File>& results,
  209214. const String& title,
  209215. const File& currentFileOrDirectory,
  209216. const String& filter,
  209217. bool selectsDirectory,
  209218. bool selectsFiles,
  209219. bool isSaveDialogue,
  209220. bool warnAboutOverwritingExistingFiles,
  209221. bool selectMultipleFiles,
  209222. FilePreviewComponent* extraInfoComponent)
  209223. {
  209224. const ScopedAutoReleasePool pool;
  209225. jassertfalse //xxx to do
  209226. }
  209227. #endif
  209228. #endif
  209229. /********* End of inlined file: juce_mac_FileChooser.mm *********/
  209230. /********* Start of inlined file: juce_mac_QuickTimeMovieComponent.mm *********/
  209231. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  209232. // compiled on its own).
  209233. #if JUCE_INCLUDED_FILE && JUCE_QUICKTIME
  209234. #define theMovie ((QTMovie*) movie)
  209235. QuickTimeMovieComponent::QuickTimeMovieComponent()
  209236. : movie (0)
  209237. {
  209238. setOpaque (true);
  209239. setVisible (true);
  209240. QTMovieView* view = [[QTMovieView alloc] initWithFrame: NSMakeRect (0, 0, 100.0f, 100.0f)];
  209241. setView (view);
  209242. }
  209243. QuickTimeMovieComponent::~QuickTimeMovieComponent()
  209244. {
  209245. closeMovie();
  209246. setView (0);
  209247. }
  209248. bool QuickTimeMovieComponent::isQuickTimeAvailable() throw()
  209249. {
  209250. return true;
  209251. }
  209252. static QTMovie* openMovieFromStream (InputStream* movieStream, File& movieFile)
  209253. {
  209254. // unfortunately, QTMovie objects can only be created on the main thread..
  209255. jassert (MessageManager::getInstance()->isThisTheMessageThread());
  209256. QTMovie* movie = 0;
  209257. FileInputStream* const fin = dynamic_cast <FileInputStream*> (movieStream);
  209258. if (fin != 0)
  209259. {
  209260. movieFile = fin->getFile();
  209261. movie = [QTMovie movieWithFile: juceStringToNS (movieFile.getFullPathName())
  209262. error: nil];
  209263. }
  209264. else
  209265. {
  209266. MemoryBlock temp;
  209267. movieStream->readIntoMemoryBlock (temp);
  209268. const char* const suffixesToTry[] = { ".mov", ".mp3", ".avi", ".m4a" };
  209269. for (int i = 0; i < numElementsInArray (suffixesToTry); ++i)
  209270. {
  209271. movie = [QTMovie movieWithDataReference: [QTDataReference dataReferenceWithReferenceToData: [NSData dataWithBytes: temp.getData()
  209272. length: temp.getSize()]
  209273. name: [NSString stringWithUTF8String: suffixesToTry[i]]
  209274. MIMEType: @""]
  209275. error: nil];
  209276. if (movie != 0)
  209277. break;
  209278. }
  209279. }
  209280. return movie;
  209281. }
  209282. bool QuickTimeMovieComponent::loadMovie (const File& movieFile_,
  209283. const bool isControllerVisible_)
  209284. {
  209285. return loadMovie ((InputStream*) movieFile_.createInputStream(), isControllerVisible_);
  209286. }
  209287. bool QuickTimeMovieComponent::loadMovie (InputStream* movieStream,
  209288. const bool controllerVisible_)
  209289. {
  209290. closeMovie();
  209291. if (getPeer() == 0)
  209292. {
  209293. // To open a movie, this component must be visible inside a functioning window, so that
  209294. // the QT control can be assigned to the window.
  209295. jassertfalse
  209296. return false;
  209297. }
  209298. movie = openMovieFromStream (movieStream, movieFile);
  209299. [theMovie retain];
  209300. QTMovieView* view = (QTMovieView*) getView();
  209301. [view setMovie: theMovie];
  209302. [view setControllerVisible: controllerVisible_];
  209303. setLooping (looping);
  209304. return movie != nil;
  209305. }
  209306. bool QuickTimeMovieComponent::loadMovie (const URL& movieURL,
  209307. const bool isControllerVisible_)
  209308. {
  209309. // unfortunately, QTMovie objects can only be created on the main thread..
  209310. jassert (MessageManager::getInstance()->isThisTheMessageThread());
  209311. closeMovie();
  209312. if (getPeer() == 0)
  209313. {
  209314. // To open a movie, this component must be visible inside a functioning window, so that
  209315. // the QT control can be assigned to the window.
  209316. jassertfalse
  209317. return false;
  209318. }
  209319. NSURL* url = [NSURL URLWithString: juceStringToNS (movieURL.toString (true))];
  209320. NSError* err;
  209321. if ([QTMovie canInitWithURL: url])
  209322. movie = [QTMovie movieWithURL: url error: &err];
  209323. [theMovie retain];
  209324. QTMovieView* view = (QTMovieView*) getView();
  209325. [view setMovie: theMovie];
  209326. [view setControllerVisible: controllerVisible];
  209327. setLooping (looping);
  209328. return movie != nil;
  209329. }
  209330. void QuickTimeMovieComponent::closeMovie()
  209331. {
  209332. stop();
  209333. QTMovieView* view = (QTMovieView*) getView();
  209334. [view setMovie: nil];
  209335. [theMovie release];
  209336. movie = 0;
  209337. movieFile = File::nonexistent;
  209338. }
  209339. bool QuickTimeMovieComponent::isMovieOpen() const
  209340. {
  209341. return movie != nil;
  209342. }
  209343. const File QuickTimeMovieComponent::getCurrentMovieFile() const
  209344. {
  209345. return movieFile;
  209346. }
  209347. void QuickTimeMovieComponent::play()
  209348. {
  209349. [theMovie play];
  209350. }
  209351. void QuickTimeMovieComponent::stop()
  209352. {
  209353. [theMovie stop];
  209354. }
  209355. bool QuickTimeMovieComponent::isPlaying() const
  209356. {
  209357. return movie != 0 && [theMovie rate] != 0;
  209358. }
  209359. void QuickTimeMovieComponent::setPosition (const double seconds)
  209360. {
  209361. if (movie != 0)
  209362. {
  209363. QTTime t;
  209364. t.timeValue = (uint64) (100000.0 * seconds);
  209365. t.timeScale = 100000;
  209366. t.flags = 0;
  209367. [theMovie setCurrentTime: t];
  209368. }
  209369. }
  209370. double QuickTimeMovieComponent::getPosition() const
  209371. {
  209372. if (movie == 0)
  209373. return 0.0;
  209374. QTTime t = [theMovie currentTime];
  209375. return t.timeValue / (double) t.timeScale;
  209376. }
  209377. void QuickTimeMovieComponent::setSpeed (const float newSpeed)
  209378. {
  209379. [theMovie setRate: newSpeed];
  209380. }
  209381. double QuickTimeMovieComponent::getMovieDuration() const
  209382. {
  209383. if (movie == 0)
  209384. return 0.0;
  209385. QTTime t = [theMovie duration];
  209386. return t.timeValue / (double) t.timeScale;
  209387. }
  209388. void QuickTimeMovieComponent::setLooping (const bool shouldLoop)
  209389. {
  209390. looping = shouldLoop;
  209391. [theMovie setAttribute: [NSNumber numberWithBool: shouldLoop]
  209392. forKey: QTMovieLoopsAttribute];
  209393. }
  209394. bool QuickTimeMovieComponent::isLooping() const
  209395. {
  209396. return looping;
  209397. }
  209398. void QuickTimeMovieComponent::setMovieVolume (const float newVolume)
  209399. {
  209400. [theMovie setVolume: newVolume];
  209401. }
  209402. float QuickTimeMovieComponent::getMovieVolume() const
  209403. {
  209404. return movie != 0 ? [theMovie volume] : 0.0f;
  209405. }
  209406. void QuickTimeMovieComponent::getMovieNormalSize (int& width, int& height) const
  209407. {
  209408. width = 0;
  209409. height = 0;
  209410. if (movie != 0)
  209411. {
  209412. NSSize s = [[theMovie attributeForKey: QTMovieNaturalSizeAttribute] sizeValue];
  209413. width = (int) s.width;
  209414. height = (int) s.height;
  209415. }
  209416. }
  209417. void QuickTimeMovieComponent::paint (Graphics& g)
  209418. {
  209419. if (movie == 0)
  209420. g.fillAll (Colours::black);
  209421. }
  209422. bool QuickTimeMovieComponent::isControllerVisible() const
  209423. {
  209424. return controllerVisible;
  209425. }
  209426. void QuickTimeMovieComponent::goToStart()
  209427. {
  209428. setPosition (0.0);
  209429. }
  209430. void QuickTimeMovieComponent::setBoundsWithCorrectAspectRatio (const Rectangle& spaceToFitWithin,
  209431. const RectanglePlacement& placement)
  209432. {
  209433. int normalWidth, normalHeight;
  209434. getMovieNormalSize (normalWidth, normalHeight);
  209435. if (normalWidth > 0 && normalHeight > 0 && ! spaceToFitWithin.isEmpty())
  209436. {
  209437. double x = 0.0, y = 0.0, w = normalWidth, h = normalHeight;
  209438. placement.applyTo (x, y, w, h,
  209439. spaceToFitWithin.getX(), spaceToFitWithin.getY(),
  209440. spaceToFitWithin.getWidth(), spaceToFitWithin.getHeight());
  209441. if (w > 0 && h > 0)
  209442. {
  209443. setBounds (roundToInt (x), roundToInt (y),
  209444. roundToInt (w), roundToInt (h));
  209445. }
  209446. }
  209447. else
  209448. {
  209449. setBounds (spaceToFitWithin);
  209450. }
  209451. }
  209452. #if ! (JUCE_MAC && JUCE_64BIT)
  209453. bool juce_OpenQuickTimeMovieFromStream (InputStream* movieStream, Movie& result, Handle& dataHandle)
  209454. {
  209455. if (movieStream == 0)
  209456. return false;
  209457. File file;
  209458. QTMovie* movie = openMovieFromStream (movieStream, file);
  209459. if (movie != nil)
  209460. result = [movie quickTimeMovie];
  209461. return movie != nil;
  209462. }
  209463. #endif
  209464. #endif
  209465. /********* End of inlined file: juce_mac_QuickTimeMovieComponent.mm *********/
  209466. /********* Start of inlined file: juce_mac_AudioCDBurner.mm *********/
  209467. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  209468. // compiled on its own).
  209469. #if JUCE_INCLUDED_FILE && JUCE_USE_CDBURNER
  209470. END_JUCE_NAMESPACE
  209471. #define OpenDiskDevice MakeObjCClassName(OpenDiskDevice)
  209472. @interface OpenDiskDevice : NSObject
  209473. {
  209474. DRDevice* device;
  209475. NSMutableArray* tracks;
  209476. }
  209477. - (OpenDiskDevice*) initWithDevice: (DRDevice*) device;
  209478. - (void) dealloc;
  209479. - (bool) isDiskPresent;
  209480. - (int) getNumAvailableAudioBlocks;
  209481. - (void) addSourceTrack: (JUCE_NAMESPACE::AudioSource*) source numSamples: (int) numSamples_;
  209482. - (void) burn: (JUCE_NAMESPACE::AudioCDBurner::BurnProgressListener*) listener errorString: (JUCE_NAMESPACE::String*) error
  209483. ejectAfterwards: (bool) shouldEject isFake: (bool) peformFakeBurnForTesting;
  209484. @end
  209485. #define AudioTrackProducer MakeObjCClassName(AudioTrackProducer)
  209486. @interface AudioTrackProducer : NSObject
  209487. {
  209488. JUCE_NAMESPACE::AudioSource* source;
  209489. int readPosition, lengthInFrames;
  209490. }
  209491. - (AudioTrackProducer*) init: (int) lengthInFrames;
  209492. - (AudioTrackProducer*) initWithAudioSource: (JUCE_NAMESPACE::AudioSource*) source numSamples: (int) lengthInSamples;
  209493. - (void) dealloc;
  209494. - (void) setupTrackProperties: (DRTrack*) track;
  209495. - (void) cleanupTrackAfterBurn: (DRTrack*) track;
  209496. - (BOOL) cleanupTrackAfterVerification:(DRTrack*)track;
  209497. - (uint64_t) estimateLengthOfTrack:(DRTrack*)track;
  209498. - (BOOL) prepareTrack:(DRTrack*)track forBurn:(DRBurn*)burn
  209499. toMedia:(NSDictionary*)mediaInfo;
  209500. - (BOOL) prepareTrackForVerification:(DRTrack*)track;
  209501. - (uint32_t) produceDataForTrack:(DRTrack*)track intoBuffer:(char*)buffer
  209502. length:(uint32_t)bufferLength atAddress:(uint64_t)address
  209503. blockSize:(uint32_t)blockSize ioFlags:(uint32_t*)flags;
  209504. - (uint32_t) producePreGapForTrack:(DRTrack*)track
  209505. intoBuffer:(char*)buffer length:(uint32_t)bufferLength
  209506. atAddress:(uint64_t)address blockSize:(uint32_t)blockSize
  209507. ioFlags:(uint32_t*)flags;
  209508. - (BOOL) verifyDataForTrack:(DRTrack*)track inBuffer:(const char*)buffer
  209509. length:(uint32_t)bufferLength atAddress:(uint64_t)address
  209510. blockSize:(uint32_t)blockSize ioFlags:(uint32_t*)flags;
  209511. - (uint32_t) producePreGapForTrack:(DRTrack*)track
  209512. intoBuffer:(char*)buffer length:(uint32_t)bufferLength
  209513. atAddress:(uint64_t)address blockSize:(uint32_t)blockSize
  209514. ioFlags:(uint32_t*)flags;
  209515. @end
  209516. @implementation OpenDiskDevice
  209517. - (OpenDiskDevice*) initWithDevice: (DRDevice*) device_
  209518. {
  209519. [super init];
  209520. device = device_;
  209521. tracks = [[NSMutableArray alloc] init];
  209522. return self;
  209523. }
  209524. - (void) dealloc
  209525. {
  209526. [tracks release];
  209527. [super dealloc];
  209528. }
  209529. - (bool) isDiskPresent
  209530. {
  209531. return [device isValid]
  209532. && [[[device status] objectForKey: DRDeviceMediaStateKey]
  209533. isEqualTo: DRDeviceMediaStateMediaPresent];
  209534. }
  209535. - (int) getNumAvailableAudioBlocks
  209536. {
  209537. return [[[[device status] objectForKey: DRDeviceMediaInfoKey]
  209538. objectForKey: DRDeviceMediaBlocksFreeKey] intValue];
  209539. }
  209540. - (void) addSourceTrack: (JUCE_NAMESPACE::AudioSource*) source_ numSamples: (int) numSamples_
  209541. {
  209542. AudioTrackProducer* p = [[AudioTrackProducer alloc] initWithAudioSource: source_ numSamples: numSamples_];
  209543. DRTrack* t = [[DRTrack alloc] initWithProducer: p];
  209544. [p setupTrackProperties: t];
  209545. [tracks addObject: t];
  209546. [t release];
  209547. [p release];
  209548. }
  209549. - (void) burn: (JUCE_NAMESPACE::AudioCDBurner::BurnProgressListener*) listener errorString: (JUCE_NAMESPACE::String*) error
  209550. ejectAfterwards: (bool) shouldEject isFake: (bool) peformFakeBurnForTesting
  209551. {
  209552. DRBurn* burn = [DRBurn burnForDevice: device];
  209553. if (! [device acquireExclusiveAccess])
  209554. {
  209555. *error = "Couldn't open or write to the CD device";
  209556. return;
  209557. }
  209558. [device acquireMediaReservation];
  209559. NSMutableDictionary* d = [[burn properties] mutableCopy];
  209560. [d autorelease];
  209561. [d setObject: [NSNumber numberWithBool: peformFakeBurnForTesting] forKey: DRBurnTestingKey];
  209562. [d setObject: [NSNumber numberWithBool: false] forKey: DRBurnVerifyDiscKey];
  209563. [d setObject: (shouldEject ? DRBurnCompletionActionEject : DRBurnCompletionActionMount)
  209564. forKey: DRBurnCompletionActionKey];
  209565. [burn setProperties: d];
  209566. [burn writeLayout: tracks];
  209567. for (;;)
  209568. {
  209569. JUCE_NAMESPACE::Thread::sleep (300);
  209570. float progress = [[[burn status] objectForKey: DRStatusPercentCompleteKey] floatValue];
  209571. if (listener != 0 && listener->audioCDBurnProgress (progress))
  209572. {
  209573. [burn abort];
  209574. *error = "User cancelled the write operation";
  209575. break;
  209576. }
  209577. if ([[[burn status] objectForKey: DRStatusStateKey] isEqualTo: DRStatusStateFailed])
  209578. {
  209579. *error = "Write operation failed";
  209580. break;
  209581. }
  209582. else if ([[[burn status] objectForKey: DRStatusStateKey] isEqualTo: DRStatusStateDone])
  209583. {
  209584. break;
  209585. }
  209586. NSString* err = (NSString*) [[[burn status] objectForKey: DRErrorStatusKey]
  209587. objectForKey: DRErrorStatusErrorStringKey];
  209588. if ([err length] > 0)
  209589. {
  209590. *error = JUCE_NAMESPACE::String::fromUTF8 ((JUCE_NAMESPACE::uint8*) [err UTF8String]);
  209591. break;
  209592. }
  209593. }
  209594. [device releaseMediaReservation];
  209595. [device releaseExclusiveAccess];
  209596. }
  209597. @end
  209598. @implementation AudioTrackProducer
  209599. - (AudioTrackProducer*) init: (int) lengthInFrames_
  209600. {
  209601. lengthInFrames = lengthInFrames_;
  209602. readPosition = 0;
  209603. return self;
  209604. }
  209605. - (void) setupTrackProperties: (DRTrack*) track
  209606. {
  209607. NSMutableDictionary* p = [[track properties] mutableCopy];
  209608. [p setObject:[DRMSF msfWithFrames: lengthInFrames] forKey: DRTrackLengthKey];
  209609. [p setObject:[NSNumber numberWithUnsignedShort:2352] forKey: DRBlockSizeKey];
  209610. [p setObject:[NSNumber numberWithInt:0] forKey: DRDataFormKey];
  209611. [p setObject:[NSNumber numberWithInt:0] forKey: DRBlockTypeKey];
  209612. [p setObject:[NSNumber numberWithInt:0] forKey: DRTrackModeKey];
  209613. [p setObject:[NSNumber numberWithInt:0] forKey: DRSessionFormatKey];
  209614. [track setProperties: p];
  209615. [p release];
  209616. }
  209617. - (AudioTrackProducer*) initWithAudioSource: (JUCE_NAMESPACE::AudioSource*) source_ numSamples: (int) lengthInSamples
  209618. {
  209619. AudioTrackProducer* s = [self init: (lengthInSamples + 587) / 588];
  209620. if (s != nil)
  209621. s->source = source_;
  209622. return s;
  209623. }
  209624. - (void) dealloc
  209625. {
  209626. if (source != 0)
  209627. {
  209628. source->releaseResources();
  209629. delete source;
  209630. }
  209631. [super dealloc];
  209632. }
  209633. - (void) cleanupTrackAfterBurn: (DRTrack*) track
  209634. {
  209635. }
  209636. - (BOOL) cleanupTrackAfterVerification: (DRTrack*) track
  209637. {
  209638. return true;
  209639. }
  209640. - (uint64_t) estimateLengthOfTrack: (DRTrack*) track
  209641. {
  209642. return lengthInFrames;
  209643. }
  209644. - (BOOL) prepareTrack: (DRTrack*) track forBurn: (DRBurn*) burn
  209645. toMedia: (NSDictionary*) mediaInfo
  209646. {
  209647. if (source != 0)
  209648. source->prepareToPlay (44100 / 75, 44100);
  209649. readPosition = 0;
  209650. return true;
  209651. }
  209652. - (BOOL) prepareTrackForVerification: (DRTrack*) track
  209653. {
  209654. if (source != 0)
  209655. source->prepareToPlay (44100 / 75, 44100);
  209656. return true;
  209657. }
  209658. - (uint32_t) produceDataForTrack: (DRTrack*) track intoBuffer: (char*) buffer
  209659. length: (uint32_t) bufferLength atAddress: (uint64_t) address
  209660. blockSize: (uint32_t) blockSize ioFlags: (uint32_t*) flags
  209661. {
  209662. if (source != 0)
  209663. {
  209664. const int numSamples = JUCE_NAMESPACE::jmin ((int) bufferLength / 4, (lengthInFrames * (44100 / 75)) - readPosition);
  209665. if (numSamples > 0)
  209666. {
  209667. JUCE_NAMESPACE::AudioSampleBuffer tempBuffer (2, numSamples);
  209668. JUCE_NAMESPACE::AudioSourceChannelInfo info;
  209669. info.buffer = &tempBuffer;
  209670. info.startSample = 0;
  209671. info.numSamples = numSamples;
  209672. source->getNextAudioBlock (info);
  209673. JUCE_NAMESPACE::AudioDataConverters::convertFloatToInt16LE (tempBuffer.getSampleData (0),
  209674. buffer, numSamples, 4);
  209675. JUCE_NAMESPACE::AudioDataConverters::convertFloatToInt16LE (tempBuffer.getSampleData (1),
  209676. buffer + 2, numSamples, 4);
  209677. readPosition += numSamples;
  209678. }
  209679. return numSamples * 4;
  209680. }
  209681. return 0;
  209682. }
  209683. - (uint32_t) producePreGapForTrack: (DRTrack*) track
  209684. intoBuffer: (char*) buffer length: (uint32_t) bufferLength
  209685. atAddress: (uint64_t) address blockSize: (uint32_t) blockSize
  209686. ioFlags: (uint32_t*) flags
  209687. {
  209688. zeromem (buffer, bufferLength);
  209689. return bufferLength;
  209690. }
  209691. - (BOOL) verifyDataForTrack: (DRTrack*) track inBuffer: (const char*) buffer
  209692. length: (uint32_t) bufferLength atAddress: (uint64_t) address
  209693. blockSize: (uint32_t) blockSize ioFlags: (uint32_t*) flags
  209694. {
  209695. return true;
  209696. }
  209697. @end
  209698. BEGIN_JUCE_NAMESPACE
  209699. AudioCDBurner::AudioCDBurner (const int deviceIndex)
  209700. : internal (0)
  209701. {
  209702. OpenDiskDevice* dev = [[OpenDiskDevice alloc] initWithDevice: [[DRDevice devices] objectAtIndex: deviceIndex]];
  209703. internal = (void*) dev;
  209704. }
  209705. AudioCDBurner::~AudioCDBurner()
  209706. {
  209707. OpenDiskDevice* dev = (OpenDiskDevice*) internal;
  209708. if (dev != 0)
  209709. [dev release];
  209710. }
  209711. AudioCDBurner* AudioCDBurner::openDevice (const int deviceIndex)
  209712. {
  209713. ScopedPointer <AudioCDBurner> b (new AudioCDBurner (deviceIndex));
  209714. if (b->internal == 0)
  209715. b = 0;
  209716. return b.release();
  209717. }
  209718. static NSArray* findDiskBurnerDevices()
  209719. {
  209720. NSMutableArray* results = [NSMutableArray array];
  209721. NSArray* devs = [DRDevice devices];
  209722. if (devs != 0)
  209723. {
  209724. int num = [devs count];
  209725. int i;
  209726. for (i = 0; i < num; ++i)
  209727. {
  209728. NSDictionary* dic = [[devs objectAtIndex: i] info];
  209729. NSString* name = [dic valueForKey: DRDeviceProductNameKey];
  209730. if (name != nil)
  209731. [results addObject: name];
  209732. }
  209733. }
  209734. return results;
  209735. }
  209736. const StringArray AudioCDBurner::findAvailableDevices()
  209737. {
  209738. NSArray* names = findDiskBurnerDevices();
  209739. StringArray s;
  209740. for (unsigned int i = 0; i < [names count]; ++i)
  209741. s.add (String::fromUTF8 ((JUCE_NAMESPACE::uint8*) [[names objectAtIndex: i] UTF8String]));
  209742. return s;
  209743. }
  209744. bool AudioCDBurner::isDiskPresent() const
  209745. {
  209746. OpenDiskDevice* dev = (OpenDiskDevice*) internal;
  209747. return dev != 0 && [dev isDiskPresent];
  209748. }
  209749. int AudioCDBurner::getNumAvailableAudioBlocks() const
  209750. {
  209751. OpenDiskDevice* dev = (OpenDiskDevice*) internal;
  209752. return [dev getNumAvailableAudioBlocks];
  209753. }
  209754. bool AudioCDBurner::addAudioTrack (AudioSource* source, int numSamps)
  209755. {
  209756. OpenDiskDevice* dev = (OpenDiskDevice*) internal;
  209757. if (dev != 0)
  209758. {
  209759. [dev addSourceTrack: source numSamples: numSamps];
  209760. return true;
  209761. }
  209762. return false;
  209763. }
  209764. const String AudioCDBurner::burn (JUCE_NAMESPACE::AudioCDBurner::BurnProgressListener* listener,
  209765. const bool ejectDiscAfterwards,
  209766. const bool peformFakeBurnForTesting)
  209767. {
  209768. String error ("Couldn't open or write to the CD device");
  209769. OpenDiskDevice* dev = (OpenDiskDevice*) internal;
  209770. if (dev != 0)
  209771. {
  209772. error = String::empty;
  209773. [dev burn: listener
  209774. errorString: &error
  209775. ejectAfterwards: ejectDiscAfterwards
  209776. isFake: peformFakeBurnForTesting];
  209777. }
  209778. return error;
  209779. }
  209780. void AudioCDReader::ejectDisk()
  209781. {
  209782. const ScopedAutoReleasePool p;
  209783. [[NSWorkspace sharedWorkspace] unmountAndEjectDeviceAtPath: juceStringToNS (volumeDir.getFullPathName())];
  209784. }
  209785. #endif
  209786. /********* End of inlined file: juce_mac_AudioCDBurner.mm *********/
  209787. /********* Start of inlined file: juce_mac_MessageManager.mm *********/
  209788. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  209789. // compiled on its own).
  209790. #if JUCE_INCLUDED_FILE
  209791. struct CallbackMessagePayload
  209792. {
  209793. MessageCallbackFunction* function;
  209794. void* parameter;
  209795. void* volatile result;
  209796. bool volatile hasBeenExecuted;
  209797. };
  209798. class AppDelegateRedirector
  209799. {
  209800. public:
  209801. AppDelegateRedirector()
  209802. {
  209803. #if MAC_OS_X_VERSION_MIN_REQUIRED > MAC_OS_X_VERSION_10_4
  209804. runLoop = CFRunLoopGetMain();
  209805. #else
  209806. runLoop = CFRunLoopGetCurrent();
  209807. #endif
  209808. CFRunLoopSourceContext sourceContext;
  209809. zerostruct (sourceContext);
  209810. sourceContext.info = this;
  209811. sourceContext.perform = runLoopSourceCallback;
  209812. runLoopSource = CFRunLoopSourceCreate (kCFAllocatorDefault, 1, &sourceContext);
  209813. CFRunLoopAddSource (runLoop, runLoopSource, kCFRunLoopCommonModes);
  209814. }
  209815. virtual ~AppDelegateRedirector()
  209816. {
  209817. CFRunLoopRemoveSource (runLoop, runLoopSource, kCFRunLoopCommonModes);
  209818. CFRunLoopSourceInvalidate (runLoopSource);
  209819. CFRelease (runLoopSource);
  209820. while (messages.size() > 0)
  209821. delete ((Message*) messages.remove(0));
  209822. }
  209823. virtual NSApplicationTerminateReply shouldTerminate()
  209824. {
  209825. if (JUCEApplication::getInstance() != 0)
  209826. {
  209827. JUCEApplication::getInstance()->systemRequestedQuit();
  209828. return NSTerminateCancel;
  209829. }
  209830. return NSTerminateNow;
  209831. }
  209832. virtual BOOL openFile (const NSString* filename)
  209833. {
  209834. if (JUCEApplication::getInstance() != 0)
  209835. {
  209836. JUCEApplication::getInstance()->anotherInstanceStarted (nsStringToJuce (filename));
  209837. return YES;
  209838. }
  209839. return NO;
  209840. }
  209841. virtual void openFiles (NSArray* filenames)
  209842. {
  209843. StringArray files;
  209844. for (unsigned int i = 0; i < [filenames count]; ++i)
  209845. {
  209846. String filename (nsStringToJuce ((NSString*) [filenames objectAtIndex: i]));
  209847. if (filename.containsChar (T(' ')))
  209848. filename = filename.quoted('"');
  209849. files.add (filename);
  209850. }
  209851. if (files.size() > 0 && JUCEApplication::getInstance() != 0)
  209852. {
  209853. JUCEApplication::getInstance()->anotherInstanceStarted (files.joinIntoString (T(" ")));
  209854. }
  209855. }
  209856. virtual void focusChanged()
  209857. {
  209858. juce_HandleProcessFocusChange();
  209859. }
  209860. virtual void performCallback (CallbackMessagePayload* pl)
  209861. {
  209862. pl->result = (*pl->function) (pl->parameter);
  209863. pl->hasBeenExecuted = true;
  209864. }
  209865. virtual void deleteSelf()
  209866. {
  209867. delete this;
  209868. }
  209869. void postMessage (void* m)
  209870. {
  209871. messages.add (m);
  209872. CFRunLoopSourceSignal (runLoopSource);
  209873. CFRunLoopWakeUp (runLoop);
  209874. }
  209875. private:
  209876. CFRunLoopRef runLoop;
  209877. CFRunLoopSourceRef runLoopSource;
  209878. Array <void*, CriticalSection> messages;
  209879. void runLoopCallback()
  209880. {
  209881. int numDispatched = 0;
  209882. do
  209883. {
  209884. void* const nextMessage = messages.remove (0);
  209885. if (nextMessage == 0)
  209886. return;
  209887. const ScopedAutoReleasePool pool;
  209888. MessageManager::getInstance()->deliverMessage (nextMessage);
  209889. } while (++numDispatched <= 4);
  209890. CFRunLoopSourceSignal (runLoopSource);
  209891. CFRunLoopWakeUp (runLoop);
  209892. }
  209893. static void runLoopSourceCallback (void* info)
  209894. {
  209895. ((AppDelegateRedirector*) info)->runLoopCallback();
  209896. }
  209897. };
  209898. END_JUCE_NAMESPACE
  209899. using namespace JUCE_NAMESPACE;
  209900. #define JuceAppDelegate MakeObjCClassName(JuceAppDelegate)
  209901. @interface JuceAppDelegate : NSObject
  209902. {
  209903. @private
  209904. id oldDelegate;
  209905. @public
  209906. AppDelegateRedirector* redirector;
  209907. }
  209908. - (JuceAppDelegate*) init;
  209909. - (void) dealloc;
  209910. - (BOOL) application: (NSApplication*) theApplication openFile: (NSString*) filename;
  209911. - (void) application: (NSApplication*) sender openFiles: (NSArray*) filenames;
  209912. - (NSApplicationTerminateReply) applicationShouldTerminate: (NSApplication*) app;
  209913. - (void) applicationDidBecomeActive: (NSNotification*) aNotification;
  209914. - (void) applicationDidResignActive: (NSNotification*) aNotification;
  209915. - (void) applicationWillUnhide: (NSNotification*) aNotification;
  209916. - (void) performCallback: (id) info;
  209917. - (void) dummyMethod;
  209918. @end
  209919. @implementation JuceAppDelegate
  209920. - (JuceAppDelegate*) init
  209921. {
  209922. [super init];
  209923. redirector = new AppDelegateRedirector();
  209924. NSNotificationCenter* center = [NSNotificationCenter defaultCenter];
  209925. if (JUCEApplication::getInstance() != 0)
  209926. {
  209927. oldDelegate = [NSApp delegate];
  209928. [NSApp setDelegate: self];
  209929. }
  209930. else
  209931. {
  209932. oldDelegate = 0;
  209933. [center addObserver: self selector: @selector (applicationDidResignActive:)
  209934. name: NSApplicationDidResignActiveNotification object: NSApp];
  209935. [center addObserver: self selector: @selector (applicationDidBecomeActive:)
  209936. name: NSApplicationDidBecomeActiveNotification object: NSApp];
  209937. [center addObserver: self selector: @selector (applicationWillUnhide:)
  209938. name: NSApplicationWillUnhideNotification object: NSApp];
  209939. }
  209940. return self;
  209941. }
  209942. - (void) dealloc
  209943. {
  209944. if (oldDelegate != 0)
  209945. [NSApp setDelegate: oldDelegate];
  209946. redirector->deleteSelf();
  209947. [super dealloc];
  209948. }
  209949. - (NSApplicationTerminateReply) applicationShouldTerminate: (NSApplication*) app
  209950. {
  209951. return redirector->shouldTerminate();
  209952. }
  209953. - (BOOL) application: (NSApplication*) app openFile: (NSString*) filename
  209954. {
  209955. return redirector->openFile (filename);
  209956. }
  209957. - (void) application: (NSApplication*) sender openFiles: (NSArray*) filenames
  209958. {
  209959. return redirector->openFiles (filenames);
  209960. }
  209961. - (void) applicationDidBecomeActive: (NSNotification*) aNotification
  209962. {
  209963. redirector->focusChanged();
  209964. }
  209965. - (void) applicationDidResignActive: (NSNotification*) aNotification
  209966. {
  209967. redirector->focusChanged();
  209968. }
  209969. - (void) applicationWillUnhide: (NSNotification*) aNotification
  209970. {
  209971. redirector->focusChanged();
  209972. }
  209973. - (void) performCallback: (id) info
  209974. {
  209975. if ([info isKindOfClass: [NSData class]])
  209976. {
  209977. CallbackMessagePayload* pl = (CallbackMessagePayload*) [((NSData*) info) bytes];
  209978. if (pl != 0)
  209979. redirector->performCallback (pl);
  209980. }
  209981. else
  209982. {
  209983. jassertfalse // should never get here!
  209984. }
  209985. }
  209986. - (void) dummyMethod {} // (used as a way of running a dummy thread)
  209987. @end
  209988. BEGIN_JUCE_NAMESPACE
  209989. static JuceAppDelegate* juceAppDelegate = 0;
  209990. void MessageManager::runDispatchLoop()
  209991. {
  209992. if (! quitMessagePosted) // check that the quit message wasn't already posted..
  209993. {
  209994. const ScopedAutoReleasePool pool;
  209995. // must only be called by the message thread!
  209996. jassert (isThisTheMessageThread());
  209997. #if JUCE_CATCH_UNHANDLED_EXCEPTIONS
  209998. @try
  209999. {
  210000. [NSApp run];
  210001. }
  210002. @catch (NSException* e)
  210003. {
  210004. // An AppKit exception will kill the app, but at least this provides a chance to log it.,
  210005. std::runtime_error ex (std::string ("NSException: ") + [[e name] UTF8String] + ", Reason:" + [[e reason] UTF8String]);
  210006. JUCEApplication::sendUnhandledException (&ex, __FILE__, __LINE__);
  210007. }
  210008. @finally
  210009. {
  210010. }
  210011. #else
  210012. [NSApp run];
  210013. #endif
  210014. }
  210015. }
  210016. void MessageManager::stopDispatchLoop()
  210017. {
  210018. quitMessagePosted = true;
  210019. [NSApp stop: nil];
  210020. [NSApp activateIgnoringOtherApps: YES]; // (if the app is inactive, it sits there and ignores the quit request until the next time it gets activated)
  210021. [NSEvent startPeriodicEventsAfterDelay: 0 withPeriod: 0.1];
  210022. }
  210023. static bool isEventBlockedByModalComps (NSEvent* e)
  210024. {
  210025. if (Component::getNumCurrentlyModalComponents() == 0)
  210026. return false;
  210027. NSWindow* const w = [e window];
  210028. if (w == 0 || [w worksWhenModal])
  210029. return false;
  210030. bool isKey = false, isInputAttempt = false;
  210031. switch ([e type])
  210032. {
  210033. case NSKeyDown:
  210034. case NSKeyUp:
  210035. isKey = isInputAttempt = true;
  210036. break;
  210037. case NSLeftMouseDown:
  210038. case NSRightMouseDown:
  210039. case NSOtherMouseDown:
  210040. isInputAttempt = true;
  210041. break;
  210042. case NSLeftMouseDragged:
  210043. case NSRightMouseDragged:
  210044. case NSLeftMouseUp:
  210045. case NSRightMouseUp:
  210046. case NSOtherMouseUp:
  210047. case NSOtherMouseDragged:
  210048. if (Component::getComponentUnderMouse() != 0)
  210049. return false;
  210050. break;
  210051. case NSMouseMoved:
  210052. case NSMouseEntered:
  210053. case NSMouseExited:
  210054. case NSCursorUpdate:
  210055. case NSScrollWheel:
  210056. case NSTabletPoint:
  210057. case NSTabletProximity:
  210058. break;
  210059. default:
  210060. return false;
  210061. }
  210062. for (int i = ComponentPeer::getNumPeers(); --i >= 0;)
  210063. {
  210064. ComponentPeer* const peer = ComponentPeer::getPeer (i);
  210065. NSView* const compView = (NSView*) peer->getNativeHandle();
  210066. if ([compView window] == w)
  210067. {
  210068. if (isKey)
  210069. {
  210070. if (compView == [w firstResponder])
  210071. return false;
  210072. }
  210073. else
  210074. {
  210075. if (NSPointInRect ([compView convertPoint: [e locationInWindow] fromView: nil],
  210076. [compView bounds]))
  210077. return false;
  210078. }
  210079. }
  210080. }
  210081. if (isInputAttempt)
  210082. {
  210083. if (! [NSApp isActive])
  210084. [NSApp activateIgnoringOtherApps: YES];
  210085. Component* const modal = Component::getCurrentlyModalComponent (0);
  210086. if (modal != 0)
  210087. modal->inputAttemptWhenModal();
  210088. }
  210089. return true;
  210090. }
  210091. bool MessageManager::runDispatchLoopUntil (int millisecondsToRunFor)
  210092. {
  210093. const ScopedAutoReleasePool pool;
  210094. jassert (isThisTheMessageThread()); // must only be called by the message thread
  210095. uint32 endTime = Time::getMillisecondCounter() + millisecondsToRunFor;
  210096. while (! quitMessagePosted)
  210097. {
  210098. const ScopedAutoReleasePool pool2;
  210099. CFRunLoopRunInMode (kCFRunLoopDefaultMode, 0.001, true);
  210100. NSEvent* e = [NSApp nextEventMatchingMask: NSAnyEventMask
  210101. untilDate: [NSDate dateWithTimeIntervalSinceNow: 0.001]
  210102. inMode: NSDefaultRunLoopMode
  210103. dequeue: YES];
  210104. if (e != 0 && ! isEventBlockedByModalComps (e))
  210105. [NSApp sendEvent: e];
  210106. if (Time::getMillisecondCounter() >= endTime)
  210107. break;
  210108. }
  210109. return ! quitMessagePosted;
  210110. }
  210111. void MessageManager::doPlatformSpecificInitialisation()
  210112. {
  210113. if (juceAppDelegate == 0)
  210114. juceAppDelegate = [[JuceAppDelegate alloc] init];
  210115. // This launches a dummy thread, which forces Cocoa to initialise NSThreads
  210116. // correctly (needed prior to 10.5)
  210117. if (! [NSThread isMultiThreaded])
  210118. [NSThread detachNewThreadSelector: @selector (dummyMethod)
  210119. toTarget: juceAppDelegate
  210120. withObject: nil];
  210121. initialiseMainMenu();
  210122. }
  210123. void MessageManager::doPlatformSpecificShutdown()
  210124. {
  210125. if (juceAppDelegate != 0)
  210126. {
  210127. [[NSRunLoop currentRunLoop] cancelPerformSelectorsWithTarget: juceAppDelegate];
  210128. [[NSNotificationCenter defaultCenter] removeObserver: juceAppDelegate];
  210129. [juceAppDelegate release];
  210130. juceAppDelegate = 0;
  210131. }
  210132. }
  210133. bool juce_postMessageToSystemQueue (void* message)
  210134. {
  210135. juceAppDelegate->redirector->postMessage (message);
  210136. return true;
  210137. }
  210138. void MessageManager::broadcastMessage (const String& value) throw()
  210139. {
  210140. }
  210141. void* MessageManager::callFunctionOnMessageThread (MessageCallbackFunction* callback,
  210142. void* data)
  210143. {
  210144. if (isThisTheMessageThread())
  210145. {
  210146. return (*callback) (data);
  210147. }
  210148. else
  210149. {
  210150. // If a thread has a MessageManagerLock and then tries to call this method, it'll
  210151. // deadlock because the message manager is blocked from running, so can never
  210152. // call your function..
  210153. jassert (! MessageManager::getInstance()->currentThreadHasLockedMessageManager());
  210154. const ScopedAutoReleasePool pool;
  210155. CallbackMessagePayload cmp;
  210156. cmp.function = callback;
  210157. cmp.parameter = data;
  210158. cmp.result = 0;
  210159. cmp.hasBeenExecuted = false;
  210160. [juceAppDelegate performSelectorOnMainThread: @selector (performCallback:)
  210161. withObject: [NSData dataWithBytesNoCopy: &cmp
  210162. length: sizeof (cmp)
  210163. freeWhenDone: NO]
  210164. waitUntilDone: YES];
  210165. return cmp.result;
  210166. }
  210167. }
  210168. #endif
  210169. /********* End of inlined file: juce_mac_MessageManager.mm *********/
  210170. /********* Start of inlined file: juce_mac_WebBrowserComponent.mm *********/
  210171. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  210172. // compiled on its own).
  210173. #if JUCE_INCLUDED_FILE && JUCE_WEB_BROWSER
  210174. #if JUCE_MAC
  210175. END_JUCE_NAMESPACE
  210176. #define DownloadClickDetector MakeObjCClassName(DownloadClickDetector)
  210177. @interface DownloadClickDetector : NSObject
  210178. {
  210179. JUCE_NAMESPACE::WebBrowserComponent* ownerComponent;
  210180. }
  210181. - (DownloadClickDetector*) initWithWebBrowserOwner: (JUCE_NAMESPACE::WebBrowserComponent*) ownerComponent;
  210182. - (void) webView: (WebView*) webView decidePolicyForNavigationAction: (NSDictionary*) actionInformation
  210183. request: (NSURLRequest*) request
  210184. frame: (WebFrame*) frame
  210185. decisionListener: (id<WebPolicyDecisionListener>) listener;
  210186. @end
  210187. @implementation DownloadClickDetector
  210188. - (DownloadClickDetector*) initWithWebBrowserOwner: (JUCE_NAMESPACE::WebBrowserComponent*) ownerComponent_
  210189. {
  210190. [super init];
  210191. ownerComponent = ownerComponent_;
  210192. return self;
  210193. }
  210194. - (void) webView: (WebView*) sender decidePolicyForNavigationAction: (NSDictionary*) actionInformation
  210195. request: (NSURLRequest*) request
  210196. frame: (WebFrame*) frame
  210197. decisionListener: (id <WebPolicyDecisionListener>) listener
  210198. {
  210199. NSURL* url = [actionInformation valueForKey: @"WebActionOriginalURLKey"];
  210200. if (ownerComponent->pageAboutToLoad (nsStringToJuce ([url absoluteString])))
  210201. [listener use];
  210202. else
  210203. [listener ignore];
  210204. }
  210205. @end
  210206. BEGIN_JUCE_NAMESPACE
  210207. class WebBrowserComponentInternal : public NSViewComponent
  210208. {
  210209. public:
  210210. WebBrowserComponentInternal (WebBrowserComponent* owner)
  210211. {
  210212. webView = [[WebView alloc] initWithFrame: NSMakeRect (0, 0, 100.0f, 100.0f)
  210213. frameName: @""
  210214. groupName: @""];
  210215. setView (webView);
  210216. clickListener = [[DownloadClickDetector alloc] initWithWebBrowserOwner: owner];
  210217. [webView setPolicyDelegate: clickListener];
  210218. }
  210219. ~WebBrowserComponentInternal()
  210220. {
  210221. [webView setPolicyDelegate: nil];
  210222. [clickListener release];
  210223. setView (0);
  210224. }
  210225. void goToURL (const String& url,
  210226. const StringArray* headers,
  210227. const MemoryBlock* postData)
  210228. {
  210229. NSMutableURLRequest* r
  210230. = [NSMutableURLRequest requestWithURL: [NSURL URLWithString: juceStringToNS (url)]
  210231. cachePolicy: NSURLRequestUseProtocolCachePolicy
  210232. timeoutInterval: 30.0];
  210233. if (postData != 0 && postData->getSize() > 0)
  210234. {
  210235. [r setHTTPMethod: @"POST"];
  210236. [r setHTTPBody: [NSData dataWithBytes: postData->getData()
  210237. length: postData->getSize()]];
  210238. }
  210239. if (headers != 0)
  210240. {
  210241. for (int i = 0; i < headers->size(); ++i)
  210242. {
  210243. const String headerName ((*headers)[i].upToFirstOccurrenceOf (T(":"), false, false).trim());
  210244. const String headerValue ((*headers)[i].fromFirstOccurrenceOf (T(":"), false, false).trim());
  210245. [r setValue: juceStringToNS (headerValue)
  210246. forHTTPHeaderField: juceStringToNS (headerName)];
  210247. }
  210248. }
  210249. stop();
  210250. [[webView mainFrame] loadRequest: r];
  210251. }
  210252. void goBack()
  210253. {
  210254. [webView goBack];
  210255. }
  210256. void goForward()
  210257. {
  210258. [webView goForward];
  210259. }
  210260. void stop()
  210261. {
  210262. [webView stopLoading: nil];
  210263. }
  210264. void refresh()
  210265. {
  210266. [webView reload: nil];
  210267. }
  210268. private:
  210269. WebView* webView;
  210270. DownloadClickDetector* clickListener;
  210271. };
  210272. WebBrowserComponent::WebBrowserComponent (const bool unloadPageWhenBrowserIsHidden_)
  210273. : browser (0),
  210274. blankPageShown (false),
  210275. unloadPageWhenBrowserIsHidden (unloadPageWhenBrowserIsHidden_)
  210276. {
  210277. setOpaque (true);
  210278. addAndMakeVisible (browser = new WebBrowserComponentInternal (this));
  210279. }
  210280. WebBrowserComponent::~WebBrowserComponent()
  210281. {
  210282. deleteAndZero (browser);
  210283. }
  210284. void WebBrowserComponent::goToURL (const String& url,
  210285. const StringArray* headers,
  210286. const MemoryBlock* postData)
  210287. {
  210288. lastURL = url;
  210289. lastHeaders.clear();
  210290. if (headers != 0)
  210291. lastHeaders = *headers;
  210292. lastPostData.setSize (0);
  210293. if (postData != 0)
  210294. lastPostData = *postData;
  210295. blankPageShown = false;
  210296. browser->goToURL (url, headers, postData);
  210297. }
  210298. void WebBrowserComponent::stop()
  210299. {
  210300. browser->stop();
  210301. }
  210302. void WebBrowserComponent::goBack()
  210303. {
  210304. lastURL = String::empty;
  210305. blankPageShown = false;
  210306. browser->goBack();
  210307. }
  210308. void WebBrowserComponent::goForward()
  210309. {
  210310. lastURL = String::empty;
  210311. browser->goForward();
  210312. }
  210313. void WebBrowserComponent::refresh()
  210314. {
  210315. browser->refresh();
  210316. }
  210317. void WebBrowserComponent::paint (Graphics& g)
  210318. {
  210319. }
  210320. void WebBrowserComponent::checkWindowAssociation()
  210321. {
  210322. if (isShowing())
  210323. {
  210324. if (blankPageShown)
  210325. goBack();
  210326. }
  210327. else
  210328. {
  210329. if (unloadPageWhenBrowserIsHidden && ! blankPageShown)
  210330. {
  210331. // when the component becomes invisible, some stuff like flash
  210332. // carries on playing audio, so we need to force it onto a blank
  210333. // page to avoid this, (and send it back when it's made visible again).
  210334. blankPageShown = true;
  210335. browser->goToURL ("about:blank", 0, 0);
  210336. }
  210337. }
  210338. }
  210339. void WebBrowserComponent::reloadLastURL()
  210340. {
  210341. if (lastURL.isNotEmpty())
  210342. {
  210343. goToURL (lastURL, &lastHeaders, &lastPostData);
  210344. lastURL = String::empty;
  210345. }
  210346. }
  210347. void WebBrowserComponent::parentHierarchyChanged()
  210348. {
  210349. checkWindowAssociation();
  210350. }
  210351. void WebBrowserComponent::resized()
  210352. {
  210353. browser->setSize (getWidth(), getHeight());
  210354. }
  210355. void WebBrowserComponent::visibilityChanged()
  210356. {
  210357. checkWindowAssociation();
  210358. }
  210359. bool WebBrowserComponent::pageAboutToLoad (const String& url)
  210360. {
  210361. return true;
  210362. }
  210363. #else
  210364. WebBrowserComponent::WebBrowserComponent (const bool unloadPageWhenBrowserIsHidden_)
  210365. {
  210366. }
  210367. WebBrowserComponent::~WebBrowserComponent()
  210368. {
  210369. }
  210370. void WebBrowserComponent::goToURL (const String& url,
  210371. const StringArray* headers,
  210372. const MemoryBlock* postData)
  210373. {
  210374. }
  210375. void WebBrowserComponent::stop()
  210376. {
  210377. }
  210378. void WebBrowserComponent::goBack()
  210379. {
  210380. }
  210381. void WebBrowserComponent::goForward()
  210382. {
  210383. }
  210384. void WebBrowserComponent::refresh()
  210385. {
  210386. }
  210387. void WebBrowserComponent::paint (Graphics& g)
  210388. {
  210389. }
  210390. void WebBrowserComponent::checkWindowAssociation()
  210391. {
  210392. }
  210393. void WebBrowserComponent::reloadLastURL()
  210394. {
  210395. }
  210396. void WebBrowserComponent::parentHierarchyChanged()
  210397. {
  210398. }
  210399. void WebBrowserComponent::resized()
  210400. {
  210401. }
  210402. void WebBrowserComponent::visibilityChanged()
  210403. {
  210404. }
  210405. bool WebBrowserComponent::pageAboutToLoad (const String& url)
  210406. {
  210407. return true;
  210408. }
  210409. #endif
  210410. #endif
  210411. /********* End of inlined file: juce_mac_WebBrowserComponent.mm *********/
  210412. /********* Start of inlined file: juce_mac_CoreAudio.cpp *********/
  210413. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  210414. // compiled on its own).
  210415. #if JUCE_INCLUDED_FILE
  210416. #ifndef JUCE_COREAUDIO_ERROR_LOGGING_ENABLED
  210417. #define JUCE_COREAUDIO_ERROR_LOGGING_ENABLED 1
  210418. #endif
  210419. #undef log
  210420. #if JUCE_COREAUDIO_LOGGING_ENABLED
  210421. #define log(a) Logger::writeToLog (a)
  210422. #else
  210423. #define log(a)
  210424. #endif
  210425. #undef OK
  210426. #if JUCE_COREAUDIO_ERROR_LOGGING_ENABLED
  210427. static bool logAnyErrors_CoreAudio (const OSStatus err, const int lineNum)
  210428. {
  210429. if (err == noErr)
  210430. return true;
  210431. Logger::writeToLog (T("CoreAudio error: ") + String (lineNum) + T(" - ") + String::toHexString ((int)err));
  210432. jassertfalse
  210433. return false;
  210434. }
  210435. #define OK(a) logAnyErrors_CoreAudio (a, __LINE__)
  210436. #else
  210437. #define OK(a) (a == noErr)
  210438. #endif
  210439. class CoreAudioInternal : public Timer
  210440. {
  210441. public:
  210442. CoreAudioInternal (AudioDeviceID id)
  210443. : inputLatency (0),
  210444. outputLatency (0),
  210445. callback (0),
  210446. #if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5
  210447. audioProcID (0),
  210448. #endif
  210449. inputDevice (0),
  210450. isSlaveDevice (false),
  210451. deviceID (id),
  210452. started (false),
  210453. sampleRate (0),
  210454. bufferSize (512),
  210455. numInputChans (0),
  210456. numOutputChans (0),
  210457. callbacksAllowed (true),
  210458. numInputChannelInfos (0),
  210459. numOutputChannelInfos (0)
  210460. {
  210461. jassert (deviceID != 0);
  210462. updateDetailsFromDevice();
  210463. AudioObjectPropertyAddress pa;
  210464. pa.mSelector = kAudioObjectPropertySelectorWildcard;
  210465. pa.mScope = kAudioObjectPropertyScopeWildcard;
  210466. pa.mElement = kAudioObjectPropertyElementWildcard;
  210467. AudioObjectAddPropertyListener (deviceID, &pa, deviceListenerProc, this);
  210468. }
  210469. ~CoreAudioInternal()
  210470. {
  210471. AudioObjectPropertyAddress pa;
  210472. pa.mSelector = kAudioObjectPropertySelectorWildcard;
  210473. pa.mScope = kAudioObjectPropertyScopeWildcard;
  210474. pa.mElement = kAudioObjectPropertyElementWildcard;
  210475. AudioObjectRemovePropertyListener (deviceID, &pa, deviceListenerProc, this);
  210476. stop (false);
  210477. delete inputDevice;
  210478. }
  210479. void allocateTempBuffers()
  210480. {
  210481. const int tempBufSize = bufferSize + 4;
  210482. audioBuffer.calloc ((numInputChans + numOutputChans) * tempBufSize);
  210483. tempInputBuffers.calloc (numInputChans + 2);
  210484. tempOutputBuffers.calloc (numOutputChans + 2);
  210485. int i, count = 0;
  210486. for (i = 0; i < numInputChans; ++i)
  210487. tempInputBuffers[i] = audioBuffer + count++ * tempBufSize;
  210488. for (i = 0; i < numOutputChans; ++i)
  210489. tempOutputBuffers[i] = audioBuffer + count++ * tempBufSize;
  210490. }
  210491. // returns the number of actual available channels
  210492. void fillInChannelInfo (const bool input)
  210493. {
  210494. int chanNum = 0;
  210495. UInt32 size;
  210496. AudioObjectPropertyAddress pa;
  210497. pa.mSelector = kAudioDevicePropertyStreamConfiguration;
  210498. pa.mScope = input ? kAudioDevicePropertyScopeInput : kAudioDevicePropertyScopeOutput;
  210499. pa.mElement = kAudioObjectPropertyElementMaster;
  210500. if (OK (AudioObjectGetPropertyDataSize (deviceID, &pa, 0, 0, &size)))
  210501. {
  210502. HeapBlock <AudioBufferList> bufList;
  210503. bufList.calloc (size, 1);
  210504. if (OK (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &size, bufList)))
  210505. {
  210506. const int numStreams = bufList->mNumberBuffers;
  210507. for (int i = 0; i < numStreams; ++i)
  210508. {
  210509. const AudioBuffer& b = bufList->mBuffers[i];
  210510. for (unsigned int j = 0; j < b.mNumberChannels; ++j)
  210511. {
  210512. String name;
  210513. {
  210514. uint8 channelName [256];
  210515. zerostruct (channelName);
  210516. UInt32 nameSize = sizeof (channelName);
  210517. UInt32 channelNum = chanNum + 1;
  210518. pa.mSelector = kAudioDevicePropertyChannelName;
  210519. if (AudioObjectGetPropertyData (deviceID, &pa, sizeof (channelNum), &channelNum, &nameSize, channelName) == noErr)
  210520. name = String::fromUTF8 (channelName, nameSize);
  210521. }
  210522. if (input)
  210523. {
  210524. if (activeInputChans[chanNum])
  210525. {
  210526. inputChannelInfo [numInputChannelInfos].streamNum = i;
  210527. inputChannelInfo [numInputChannelInfos].dataOffsetSamples = j;
  210528. inputChannelInfo [numInputChannelInfos].dataStrideSamples = b.mNumberChannels;
  210529. ++numInputChannelInfos;
  210530. }
  210531. if (name.isEmpty())
  210532. name << "Input " << (chanNum + 1);
  210533. inChanNames.add (name);
  210534. }
  210535. else
  210536. {
  210537. if (activeOutputChans[chanNum])
  210538. {
  210539. outputChannelInfo [numOutputChannelInfos].streamNum = i;
  210540. outputChannelInfo [numOutputChannelInfos].dataOffsetSamples = j;
  210541. outputChannelInfo [numOutputChannelInfos].dataStrideSamples = b.mNumberChannels;
  210542. ++numOutputChannelInfos;
  210543. }
  210544. if (name.isEmpty())
  210545. name << "Output " << (chanNum + 1);
  210546. outChanNames.add (name);
  210547. }
  210548. ++chanNum;
  210549. }
  210550. }
  210551. }
  210552. }
  210553. }
  210554. void updateDetailsFromDevice()
  210555. {
  210556. stopTimer();
  210557. if (deviceID == 0)
  210558. return;
  210559. const ScopedLock sl (callbackLock);
  210560. Float64 sr;
  210561. UInt32 size = sizeof (Float64);
  210562. AudioObjectPropertyAddress pa;
  210563. pa.mSelector = kAudioDevicePropertyNominalSampleRate;
  210564. pa.mScope = kAudioObjectPropertyScopeWildcard;
  210565. pa.mElement = kAudioObjectPropertyElementMaster;
  210566. if (OK (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &size, &sr)))
  210567. sampleRate = sr;
  210568. UInt32 framesPerBuf;
  210569. size = sizeof (framesPerBuf);
  210570. pa.mSelector = kAudioDevicePropertyBufferFrameSize;
  210571. if (OK (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &size, &framesPerBuf)))
  210572. {
  210573. bufferSize = framesPerBuf;
  210574. allocateTempBuffers();
  210575. }
  210576. bufferSizes.clear();
  210577. pa.mSelector = kAudioDevicePropertyBufferFrameSizeRange;
  210578. if (OK (AudioObjectGetPropertyDataSize (deviceID, &pa, 0, 0, &size)))
  210579. {
  210580. HeapBlock <AudioValueRange> ranges;
  210581. ranges.calloc (size, 1);
  210582. if (OK (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &size, ranges)))
  210583. {
  210584. bufferSizes.add ((int) ranges[0].mMinimum);
  210585. for (int i = 32; i < 8192; i += 32)
  210586. {
  210587. for (int j = size / (int) sizeof (AudioValueRange); --j >= 0;)
  210588. {
  210589. if (i >= ranges[j].mMinimum && i <= ranges[j].mMaximum)
  210590. {
  210591. bufferSizes.addIfNotAlreadyThere (i);
  210592. break;
  210593. }
  210594. }
  210595. }
  210596. if (bufferSize > 0)
  210597. bufferSizes.addIfNotAlreadyThere (bufferSize);
  210598. }
  210599. }
  210600. if (bufferSizes.size() == 0 && bufferSize > 0)
  210601. bufferSizes.add (bufferSize);
  210602. sampleRates.clear();
  210603. const double possibleRates[] = { 44100.0, 48000.0, 88200.0, 96000.0, 176400.0, 192000.0 };
  210604. String rates;
  210605. pa.mSelector = kAudioDevicePropertyAvailableNominalSampleRates;
  210606. if (OK (AudioObjectGetPropertyDataSize (deviceID, &pa, 0, 0, &size)))
  210607. {
  210608. HeapBlock <AudioValueRange> ranges;
  210609. ranges.calloc (size, 1);
  210610. if (OK (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &size, ranges)))
  210611. {
  210612. for (int i = 0; i < numElementsInArray (possibleRates); ++i)
  210613. {
  210614. bool ok = false;
  210615. for (int j = size / (int) sizeof (AudioValueRange); --j >= 0;)
  210616. if (possibleRates[i] >= ranges[j].mMinimum - 2 && possibleRates[i] <= ranges[j].mMaximum + 2)
  210617. ok = true;
  210618. if (ok)
  210619. {
  210620. sampleRates.add (possibleRates[i]);
  210621. rates << possibleRates[i] << T(" ");
  210622. }
  210623. }
  210624. }
  210625. }
  210626. if (sampleRates.size() == 0 && sampleRate > 0)
  210627. {
  210628. sampleRates.add (sampleRate);
  210629. rates << sampleRate;
  210630. }
  210631. log (T("sr: ") + rates);
  210632. inputLatency = 0;
  210633. outputLatency = 0;
  210634. UInt32 lat;
  210635. size = sizeof (lat);
  210636. pa.mSelector = kAudioDevicePropertyLatency;
  210637. pa.mScope = kAudioDevicePropertyScopeInput;
  210638. //if (AudioDeviceGetProperty (deviceID, 0, true, kAudioDevicePropertyLatency, &size, &lat) == noErr)
  210639. if (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &size, &lat) == noErr)
  210640. inputLatency = (int) lat;
  210641. pa.mScope = kAudioDevicePropertyScopeOutput;
  210642. size = sizeof (lat);
  210643. if (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &size, &lat) == noErr)
  210644. outputLatency = (int) lat;
  210645. log (T("lat: ") + String (inputLatency) + T(" ") + String (outputLatency));
  210646. inChanNames.clear();
  210647. outChanNames.clear();
  210648. inputChannelInfo.calloc (numInputChans + 2);
  210649. numInputChannelInfos = 0;
  210650. outputChannelInfo.calloc (numOutputChans + 2);
  210651. numOutputChannelInfos = 0;
  210652. fillInChannelInfo (true);
  210653. fillInChannelInfo (false);
  210654. }
  210655. const StringArray getSources (bool input)
  210656. {
  210657. StringArray s;
  210658. HeapBlock <OSType> types;
  210659. const int num = getAllDataSourcesForDevice (deviceID, input, types);
  210660. for (int i = 0; i < num; ++i)
  210661. {
  210662. AudioValueTranslation avt;
  210663. char buffer[256];
  210664. avt.mInputData = (void*) &(types[i]);
  210665. avt.mInputDataSize = sizeof (UInt32);
  210666. avt.mOutputData = buffer;
  210667. avt.mOutputDataSize = 256;
  210668. UInt32 transSize = sizeof (avt);
  210669. AudioObjectPropertyAddress pa;
  210670. pa.mSelector = kAudioDevicePropertyDataSourceNameForID;
  210671. pa.mScope = input ? kAudioDevicePropertyScopeInput : kAudioDevicePropertyScopeOutput;
  210672. pa.mElement = kAudioObjectPropertyElementMaster;
  210673. if (OK (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &transSize, &avt)))
  210674. {
  210675. DBG (buffer);
  210676. s.add (buffer);
  210677. }
  210678. }
  210679. return s;
  210680. }
  210681. int getCurrentSourceIndex (bool input) const
  210682. {
  210683. OSType currentSourceID = 0;
  210684. UInt32 size = sizeof (currentSourceID);
  210685. int result = -1;
  210686. AudioObjectPropertyAddress pa;
  210687. pa.mSelector = kAudioDevicePropertyDataSource;
  210688. pa.mScope = input ? kAudioDevicePropertyScopeInput : kAudioDevicePropertyScopeOutput;
  210689. pa.mElement = kAudioObjectPropertyElementMaster;
  210690. if (deviceID != 0)
  210691. {
  210692. if (OK (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &size, &currentSourceID)))
  210693. {
  210694. HeapBlock <OSType> types;
  210695. const int num = getAllDataSourcesForDevice (deviceID, input, types);
  210696. for (int i = 0; i < num; ++i)
  210697. {
  210698. if (types[num] == currentSourceID)
  210699. {
  210700. result = i;
  210701. break;
  210702. }
  210703. }
  210704. }
  210705. }
  210706. return result;
  210707. }
  210708. void setCurrentSourceIndex (int index, bool input)
  210709. {
  210710. if (deviceID != 0)
  210711. {
  210712. HeapBlock <OSType> types;
  210713. const int num = getAllDataSourcesForDevice (deviceID, input, types);
  210714. if (((unsigned int) index) < (unsigned int) num)
  210715. {
  210716. AudioObjectPropertyAddress pa;
  210717. pa.mSelector = kAudioDevicePropertyDataSource;
  210718. pa.mScope = input ? kAudioDevicePropertyScopeInput : kAudioDevicePropertyScopeOutput;
  210719. pa.mElement = kAudioObjectPropertyElementMaster;
  210720. OSType typeId = types[index];
  210721. OK (AudioObjectSetPropertyData (deviceID, &pa, 0, 0, sizeof (typeId), &typeId));
  210722. }
  210723. }
  210724. }
  210725. const String reopen (const BitArray& inputChannels,
  210726. const BitArray& outputChannels,
  210727. double newSampleRate,
  210728. int bufferSizeSamples)
  210729. {
  210730. String error;
  210731. log ("CoreAudio reopen");
  210732. callbacksAllowed = false;
  210733. stopTimer();
  210734. stop (false);
  210735. activeInputChans = inputChannels;
  210736. activeInputChans.setRange (inChanNames.size(),
  210737. activeInputChans.getHighestBit() + 1 - inChanNames.size(),
  210738. false);
  210739. activeOutputChans = outputChannels;
  210740. activeOutputChans.setRange (outChanNames.size(),
  210741. activeOutputChans.getHighestBit() + 1 - outChanNames.size(),
  210742. false);
  210743. numInputChans = activeInputChans.countNumberOfSetBits();
  210744. numOutputChans = activeOutputChans.countNumberOfSetBits();
  210745. // set sample rate
  210746. AudioObjectPropertyAddress pa;
  210747. pa.mSelector = kAudioDevicePropertyNominalSampleRate;
  210748. pa.mScope = kAudioObjectPropertyScopeWildcard;
  210749. pa.mElement = kAudioObjectPropertyElementMaster;
  210750. Float64 sr = newSampleRate;
  210751. if (! OK (AudioObjectSetPropertyData (deviceID, &pa, 0, 0, sizeof (sr), &sr)))
  210752. {
  210753. error = "Couldn't change sample rate";
  210754. }
  210755. else
  210756. {
  210757. // change buffer size
  210758. UInt32 framesPerBuf = bufferSizeSamples;
  210759. pa.mSelector = kAudioDevicePropertyBufferFrameSize;
  210760. if (! OK (AudioObjectSetPropertyData (deviceID, &pa, 0, 0, sizeof (framesPerBuf), &framesPerBuf)))
  210761. {
  210762. error = "Couldn't change buffer size";
  210763. }
  210764. else
  210765. {
  210766. // Annoyingly, after changing the rate and buffer size, some devices fail to
  210767. // correctly report their new settings until some random time in the future, so
  210768. // after calling updateDetailsFromDevice, we need to manually bodge these values
  210769. // to make sure we're using the correct numbers..
  210770. updateDetailsFromDevice();
  210771. sampleRate = newSampleRate;
  210772. bufferSize = bufferSizeSamples;
  210773. if (sampleRates.size() == 0)
  210774. error = "Device has no available sample-rates";
  210775. else if (bufferSizes.size() == 0)
  210776. error = "Device has no available buffer-sizes";
  210777. else if (inputDevice != 0)
  210778. error = inputDevice->reopen (inputChannels,
  210779. outputChannels,
  210780. newSampleRate,
  210781. bufferSizeSamples);
  210782. }
  210783. }
  210784. callbacksAllowed = true;
  210785. return error;
  210786. }
  210787. bool start (AudioIODeviceCallback* cb)
  210788. {
  210789. if (! started)
  210790. {
  210791. callback = 0;
  210792. if (deviceID != 0)
  210793. {
  210794. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
  210795. if (OK (AudioDeviceAddIOProc (deviceID, audioIOProc, (void*) this)))
  210796. #else
  210797. if (OK (AudioDeviceCreateIOProcID (deviceID, audioIOProc, (void*) this, &audioProcID)))
  210798. #endif
  210799. {
  210800. if (OK (AudioDeviceStart (deviceID, audioIOProc)))
  210801. {
  210802. started = true;
  210803. }
  210804. else
  210805. {
  210806. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
  210807. OK (AudioDeviceRemoveIOProc (deviceID, audioIOProc));
  210808. #else
  210809. OK (AudioDeviceDestroyIOProcID (deviceID, audioProcID));
  210810. audioProcID = 0;
  210811. #endif
  210812. }
  210813. }
  210814. }
  210815. }
  210816. if (started)
  210817. {
  210818. const ScopedLock sl (callbackLock);
  210819. callback = cb;
  210820. }
  210821. if (inputDevice != 0)
  210822. return started && inputDevice->start (cb);
  210823. else
  210824. return started;
  210825. }
  210826. void stop (bool leaveInterruptRunning)
  210827. {
  210828. callbackLock.enter();
  210829. callback = 0;
  210830. callbackLock.exit();
  210831. if (started
  210832. && (deviceID != 0)
  210833. && ! leaveInterruptRunning)
  210834. {
  210835. OK (AudioDeviceStop (deviceID, audioIOProc));
  210836. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
  210837. OK (AudioDeviceRemoveIOProc (deviceID, audioIOProc));
  210838. #else
  210839. OK (AudioDeviceDestroyIOProcID (deviceID, audioProcID));
  210840. audioProcID = 0;
  210841. #endif
  210842. started = false;
  210843. callbackLock.enter();
  210844. callbackLock.exit();
  210845. // wait until it's definately stopped calling back..
  210846. for (int i = 40; --i >= 0;)
  210847. {
  210848. Thread::sleep (50);
  210849. UInt32 running = 0;
  210850. UInt32 size = sizeof (running);
  210851. AudioObjectPropertyAddress pa;
  210852. pa.mSelector = kAudioDevicePropertyDeviceIsRunning;
  210853. pa.mScope = kAudioObjectPropertyScopeWildcard;
  210854. pa.mElement = kAudioObjectPropertyElementMaster;
  210855. OK (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &size, &running));
  210856. if (running == 0)
  210857. break;
  210858. }
  210859. callbackLock.enter();
  210860. callbackLock.exit();
  210861. }
  210862. if (inputDevice != 0)
  210863. inputDevice->stop (leaveInterruptRunning);
  210864. }
  210865. double getSampleRate() const
  210866. {
  210867. return sampleRate;
  210868. }
  210869. int getBufferSize() const
  210870. {
  210871. return bufferSize;
  210872. }
  210873. void audioCallback (const AudioBufferList* inInputData,
  210874. AudioBufferList* outOutputData)
  210875. {
  210876. int i;
  210877. const ScopedLock sl (callbackLock);
  210878. if (callback != 0)
  210879. {
  210880. if (inputDevice == 0)
  210881. {
  210882. for (i = numInputChans; --i >= 0;)
  210883. {
  210884. const CallbackDetailsForChannel& info = inputChannelInfo[i];
  210885. float* dest = tempInputBuffers [i];
  210886. const float* src = ((const float*) inInputData->mBuffers[info.streamNum].mData)
  210887. + info.dataOffsetSamples;
  210888. const int stride = info.dataStrideSamples;
  210889. if (stride != 0) // if this is zero, info is invalid
  210890. {
  210891. for (int j = bufferSize; --j >= 0;)
  210892. {
  210893. *dest++ = *src;
  210894. src += stride;
  210895. }
  210896. }
  210897. }
  210898. }
  210899. if (! isSlaveDevice)
  210900. {
  210901. if (inputDevice == 0)
  210902. {
  210903. callback->audioDeviceIOCallback ((const float**) tempInputBuffers,
  210904. numInputChans,
  210905. tempOutputBuffers,
  210906. numOutputChans,
  210907. bufferSize);
  210908. }
  210909. else
  210910. {
  210911. jassert (inputDevice->bufferSize == bufferSize);
  210912. // Sometimes the two linked devices seem to get their callbacks in
  210913. // parallel, so we need to lock both devices to stop the input data being
  210914. // changed while inside our callback..
  210915. const ScopedLock sl2 (inputDevice->callbackLock);
  210916. callback->audioDeviceIOCallback ((const float**) inputDevice->tempInputBuffers,
  210917. inputDevice->numInputChans,
  210918. tempOutputBuffers,
  210919. numOutputChans,
  210920. bufferSize);
  210921. }
  210922. for (i = numOutputChans; --i >= 0;)
  210923. {
  210924. const CallbackDetailsForChannel& info = outputChannelInfo[i];
  210925. const float* src = tempOutputBuffers [i];
  210926. float* dest = ((float*) outOutputData->mBuffers[info.streamNum].mData)
  210927. + info.dataOffsetSamples;
  210928. const int stride = info.dataStrideSamples;
  210929. if (stride != 0) // if this is zero, info is invalid
  210930. {
  210931. for (int j = bufferSize; --j >= 0;)
  210932. {
  210933. *dest = *src++;
  210934. dest += stride;
  210935. }
  210936. }
  210937. }
  210938. }
  210939. }
  210940. else
  210941. {
  210942. for (i = jmin (numOutputChans, numOutputChannelInfos); --i >= 0;)
  210943. {
  210944. const CallbackDetailsForChannel& info = outputChannelInfo[i];
  210945. float* dest = ((float*) outOutputData->mBuffers[info.streamNum].mData)
  210946. + info.dataOffsetSamples;
  210947. const int stride = info.dataStrideSamples;
  210948. if (stride != 0) // if this is zero, info is invalid
  210949. {
  210950. for (int j = bufferSize; --j >= 0;)
  210951. {
  210952. *dest = 0.0f;
  210953. dest += stride;
  210954. }
  210955. }
  210956. }
  210957. }
  210958. }
  210959. // called by callbacks
  210960. void deviceDetailsChanged()
  210961. {
  210962. if (callbacksAllowed)
  210963. startTimer (100);
  210964. }
  210965. void timerCallback()
  210966. {
  210967. stopTimer();
  210968. log ("CoreAudio device changed callback");
  210969. const double oldSampleRate = sampleRate;
  210970. const int oldBufferSize = bufferSize;
  210971. updateDetailsFromDevice();
  210972. if (oldBufferSize != bufferSize || oldSampleRate != sampleRate)
  210973. {
  210974. callbacksAllowed = false;
  210975. stop (false);
  210976. updateDetailsFromDevice();
  210977. callbacksAllowed = true;
  210978. }
  210979. }
  210980. CoreAudioInternal* getRelatedDevice() const
  210981. {
  210982. UInt32 size = 0;
  210983. ScopedPointer <CoreAudioInternal> result;
  210984. AudioObjectPropertyAddress pa;
  210985. pa.mSelector = kAudioDevicePropertyRelatedDevices;
  210986. pa.mScope = kAudioObjectPropertyScopeWildcard;
  210987. pa.mElement = kAudioObjectPropertyElementMaster;
  210988. if (deviceID != 0
  210989. && AudioObjectGetPropertyDataSize (deviceID, &pa, 0, 0, &size) == noErr
  210990. && size > 0)
  210991. {
  210992. HeapBlock <AudioDeviceID> devs;
  210993. devs.calloc (size, 1);
  210994. if (OK (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &size, devs)))
  210995. {
  210996. for (unsigned int i = 0; i < size / sizeof (AudioDeviceID); ++i)
  210997. {
  210998. if (devs[i] != deviceID && devs[i] != 0)
  210999. {
  211000. result = new CoreAudioInternal (devs[i]);
  211001. const bool thisIsInput = inChanNames.size() > 0 && outChanNames.size() == 0;
  211002. const bool otherIsInput = result->inChanNames.size() > 0 && result->outChanNames.size() == 0;
  211003. if (thisIsInput != otherIsInput
  211004. || (inChanNames.size() + outChanNames.size() == 0)
  211005. || (result->inChanNames.size() + result->outChanNames.size()) == 0)
  211006. break;
  211007. result = 0;
  211008. }
  211009. }
  211010. }
  211011. }
  211012. return result.release();
  211013. }
  211014. juce_UseDebuggingNewOperator
  211015. int inputLatency, outputLatency;
  211016. BitArray activeInputChans, activeOutputChans;
  211017. StringArray inChanNames, outChanNames;
  211018. Array <double> sampleRates;
  211019. Array <int> bufferSizes;
  211020. AudioIODeviceCallback* callback;
  211021. #if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5
  211022. AudioDeviceIOProcID audioProcID;
  211023. #endif
  211024. CoreAudioInternal* inputDevice;
  211025. bool isSlaveDevice;
  211026. private:
  211027. CriticalSection callbackLock;
  211028. AudioDeviceID deviceID;
  211029. bool started;
  211030. double sampleRate;
  211031. int bufferSize;
  211032. HeapBlock <float> audioBuffer;
  211033. int numInputChans, numOutputChans;
  211034. bool callbacksAllowed;
  211035. struct CallbackDetailsForChannel
  211036. {
  211037. int streamNum;
  211038. int dataOffsetSamples;
  211039. int dataStrideSamples;
  211040. };
  211041. int numInputChannelInfos, numOutputChannelInfos;
  211042. HeapBlock <CallbackDetailsForChannel> inputChannelInfo, outputChannelInfo;
  211043. HeapBlock <float*> tempInputBuffers, tempOutputBuffers;
  211044. CoreAudioInternal (const CoreAudioInternal&);
  211045. const CoreAudioInternal& operator= (const CoreAudioInternal&);
  211046. static OSStatus audioIOProc (AudioDeviceID inDevice,
  211047. const AudioTimeStamp* inNow,
  211048. const AudioBufferList* inInputData,
  211049. const AudioTimeStamp* inInputTime,
  211050. AudioBufferList* outOutputData,
  211051. const AudioTimeStamp* inOutputTime,
  211052. void* device)
  211053. {
  211054. ((CoreAudioInternal*) device)->audioCallback (inInputData, outOutputData);
  211055. return noErr;
  211056. }
  211057. static OSStatus deviceListenerProc (AudioDeviceID /*inDevice*/, UInt32 /*inLine*/, const AudioObjectPropertyAddress* pa, void* inClientData)
  211058. {
  211059. CoreAudioInternal* const intern = (CoreAudioInternal*) inClientData;
  211060. switch (pa->mSelector)
  211061. {
  211062. case kAudioDevicePropertyBufferSize:
  211063. case kAudioDevicePropertyBufferFrameSize:
  211064. case kAudioDevicePropertyNominalSampleRate:
  211065. case kAudioDevicePropertyStreamFormat:
  211066. case kAudioDevicePropertyDeviceIsAlive:
  211067. intern->deviceDetailsChanged();
  211068. break;
  211069. case kAudioDevicePropertyBufferSizeRange:
  211070. case kAudioDevicePropertyVolumeScalar:
  211071. case kAudioDevicePropertyMute:
  211072. case kAudioDevicePropertyPlayThru:
  211073. case kAudioDevicePropertyDataSource:
  211074. case kAudioDevicePropertyDeviceIsRunning:
  211075. break;
  211076. }
  211077. return noErr;
  211078. }
  211079. static int getAllDataSourcesForDevice (AudioDeviceID deviceID, const bool input, HeapBlock <OSType>& types)
  211080. {
  211081. AudioObjectPropertyAddress pa;
  211082. pa.mSelector = kAudioDevicePropertyDataSources;
  211083. pa.mScope = kAudioObjectPropertyScopeWildcard;
  211084. pa.mElement = kAudioObjectPropertyElementMaster;
  211085. UInt32 size = 0;
  211086. if (deviceID != 0
  211087. && OK (AudioObjectGetPropertyDataSize (deviceID, &pa, 0, 0, &size)))
  211088. {
  211089. types.calloc (size, 1);
  211090. if (OK (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &size, types)))
  211091. return size / (int) sizeof (OSType);
  211092. }
  211093. return 0;
  211094. }
  211095. };
  211096. class CoreAudioIODevice : public AudioIODevice
  211097. {
  211098. public:
  211099. CoreAudioIODevice (const String& deviceName,
  211100. AudioDeviceID inputDeviceId,
  211101. const int inputIndex_,
  211102. AudioDeviceID outputDeviceId,
  211103. const int outputIndex_)
  211104. : AudioIODevice (deviceName, "CoreAudio"),
  211105. inputIndex (inputIndex_),
  211106. outputIndex (outputIndex_),
  211107. isOpen_ (false),
  211108. isStarted (false)
  211109. {
  211110. internal = 0;
  211111. CoreAudioInternal* device = 0;
  211112. if (outputDeviceId == 0 || outputDeviceId == inputDeviceId)
  211113. {
  211114. jassert (inputDeviceId != 0);
  211115. device = new CoreAudioInternal (inputDeviceId);
  211116. }
  211117. else
  211118. {
  211119. device = new CoreAudioInternal (outputDeviceId);
  211120. if (inputDeviceId != 0)
  211121. {
  211122. CoreAudioInternal* secondDevice = new CoreAudioInternal (inputDeviceId);
  211123. device->inputDevice = secondDevice;
  211124. secondDevice->isSlaveDevice = true;
  211125. }
  211126. }
  211127. internal = device;
  211128. AudioObjectPropertyAddress pa;
  211129. pa.mSelector = kAudioObjectPropertySelectorWildcard;
  211130. pa.mScope = kAudioObjectPropertyScopeWildcard;
  211131. pa.mElement = kAudioObjectPropertyElementWildcard;
  211132. AudioObjectAddPropertyListener (kAudioObjectSystemObject, &pa, hardwareListenerProc, internal);
  211133. }
  211134. ~CoreAudioIODevice()
  211135. {
  211136. AudioObjectPropertyAddress pa;
  211137. pa.mSelector = kAudioObjectPropertySelectorWildcard;
  211138. pa.mScope = kAudioObjectPropertyScopeWildcard;
  211139. pa.mElement = kAudioObjectPropertyElementWildcard;
  211140. AudioObjectRemovePropertyListener (kAudioObjectSystemObject, &pa, hardwareListenerProc, internal);
  211141. delete internal;
  211142. }
  211143. const StringArray getOutputChannelNames()
  211144. {
  211145. return internal->outChanNames;
  211146. }
  211147. const StringArray getInputChannelNames()
  211148. {
  211149. if (internal->inputDevice != 0)
  211150. return internal->inputDevice->inChanNames;
  211151. else
  211152. return internal->inChanNames;
  211153. }
  211154. int getNumSampleRates()
  211155. {
  211156. return internal->sampleRates.size();
  211157. }
  211158. double getSampleRate (int index)
  211159. {
  211160. return internal->sampleRates [index];
  211161. }
  211162. int getNumBufferSizesAvailable()
  211163. {
  211164. return internal->bufferSizes.size();
  211165. }
  211166. int getBufferSizeSamples (int index)
  211167. {
  211168. return internal->bufferSizes [index];
  211169. }
  211170. int getDefaultBufferSize()
  211171. {
  211172. for (int i = 0; i < getNumBufferSizesAvailable(); ++i)
  211173. if (getBufferSizeSamples(i) >= 512)
  211174. return getBufferSizeSamples(i);
  211175. return 512;
  211176. }
  211177. const String open (const BitArray& inputChannels,
  211178. const BitArray& outputChannels,
  211179. double sampleRate,
  211180. int bufferSizeSamples)
  211181. {
  211182. isOpen_ = true;
  211183. if (bufferSizeSamples <= 0)
  211184. bufferSizeSamples = getDefaultBufferSize();
  211185. lastError = internal->reopen (inputChannels, outputChannels, sampleRate, bufferSizeSamples);
  211186. isOpen_ = lastError.isEmpty();
  211187. return lastError;
  211188. }
  211189. void close()
  211190. {
  211191. isOpen_ = false;
  211192. internal->stop (false);
  211193. }
  211194. bool isOpen()
  211195. {
  211196. return isOpen_;
  211197. }
  211198. int getCurrentBufferSizeSamples()
  211199. {
  211200. return internal != 0 ? internal->getBufferSize() : 512;
  211201. }
  211202. double getCurrentSampleRate()
  211203. {
  211204. return internal != 0 ? internal->getSampleRate() : 0;
  211205. }
  211206. int getCurrentBitDepth()
  211207. {
  211208. return 32; // no way to find out, so just assume it's high..
  211209. }
  211210. const BitArray getActiveOutputChannels() const
  211211. {
  211212. return internal != 0 ? internal->activeOutputChans : BitArray();
  211213. }
  211214. const BitArray getActiveInputChannels() const
  211215. {
  211216. BitArray chans;
  211217. if (internal != 0)
  211218. {
  211219. chans = internal->activeInputChans;
  211220. if (internal->inputDevice != 0)
  211221. chans.orWith (internal->inputDevice->activeInputChans);
  211222. }
  211223. return chans;
  211224. }
  211225. int getOutputLatencyInSamples()
  211226. {
  211227. if (internal == 0)
  211228. return 0;
  211229. // this seems like a good guess at getting the latency right - comparing
  211230. // this with a round-trip measurement, it gets it to within a few millisecs
  211231. // for the built-in mac soundcard
  211232. return internal->outputLatency + internal->getBufferSize() * 2;
  211233. }
  211234. int getInputLatencyInSamples()
  211235. {
  211236. if (internal == 0)
  211237. return 0;
  211238. return internal->inputLatency + internal->getBufferSize() * 2;
  211239. }
  211240. void start (AudioIODeviceCallback* callback)
  211241. {
  211242. if (internal != 0 && ! isStarted)
  211243. {
  211244. if (callback != 0)
  211245. callback->audioDeviceAboutToStart (this);
  211246. isStarted = true;
  211247. internal->start (callback);
  211248. }
  211249. }
  211250. void stop()
  211251. {
  211252. if (isStarted && internal != 0)
  211253. {
  211254. AudioIODeviceCallback* const lastCallback = internal->callback;
  211255. isStarted = false;
  211256. internal->stop (true);
  211257. if (lastCallback != 0)
  211258. lastCallback->audioDeviceStopped();
  211259. }
  211260. }
  211261. bool isPlaying()
  211262. {
  211263. if (internal->callback == 0)
  211264. isStarted = false;
  211265. return isStarted;
  211266. }
  211267. const String getLastError()
  211268. {
  211269. return lastError;
  211270. }
  211271. int inputIndex, outputIndex;
  211272. juce_UseDebuggingNewOperator
  211273. private:
  211274. CoreAudioInternal* internal;
  211275. bool isOpen_, isStarted;
  211276. String lastError;
  211277. static OSStatus hardwareListenerProc (AudioDeviceID /*inDevice*/, UInt32 /*inLine*/, const AudioObjectPropertyAddress* pa, void* inClientData)
  211278. {
  211279. CoreAudioInternal* const intern = (CoreAudioInternal*) inClientData;
  211280. switch (pa->mSelector)
  211281. {
  211282. case kAudioHardwarePropertyDevices:
  211283. intern->deviceDetailsChanged();
  211284. break;
  211285. case kAudioHardwarePropertyDefaultOutputDevice:
  211286. case kAudioHardwarePropertyDefaultInputDevice:
  211287. case kAudioHardwarePropertyDefaultSystemOutputDevice:
  211288. break;
  211289. }
  211290. return noErr;
  211291. }
  211292. CoreAudioIODevice (const CoreAudioIODevice&);
  211293. const CoreAudioIODevice& operator= (const CoreAudioIODevice&);
  211294. };
  211295. class CoreAudioIODeviceType : public AudioIODeviceType
  211296. {
  211297. public:
  211298. CoreAudioIODeviceType()
  211299. : AudioIODeviceType (T("CoreAudio")),
  211300. hasScanned (false)
  211301. {
  211302. }
  211303. ~CoreAudioIODeviceType()
  211304. {
  211305. }
  211306. void scanForDevices()
  211307. {
  211308. hasScanned = true;
  211309. inputDeviceNames.clear();
  211310. outputDeviceNames.clear();
  211311. inputIds.clear();
  211312. outputIds.clear();
  211313. UInt32 size;
  211314. AudioObjectPropertyAddress pa;
  211315. pa.mSelector = kAudioHardwarePropertyDevices;
  211316. pa.mScope = kAudioObjectPropertyScopeWildcard;
  211317. pa.mElement = kAudioObjectPropertyElementMaster;
  211318. if (OK (AudioObjectGetPropertyDataSize (kAudioObjectSystemObject, &pa, 0, 0, &size)))
  211319. {
  211320. HeapBlock <AudioDeviceID> devs;
  211321. devs.calloc (size, 1);
  211322. if (OK (AudioObjectGetPropertyData (kAudioObjectSystemObject, &pa, 0, 0, &size, devs)))
  211323. {
  211324. static bool alreadyLogged = false;
  211325. const int num = size / (int) sizeof (AudioDeviceID);
  211326. for (int i = 0; i < num; ++i)
  211327. {
  211328. char name [1024];
  211329. size = sizeof (name);
  211330. pa.mSelector = kAudioDevicePropertyDeviceName;
  211331. if (OK (AudioObjectGetPropertyData (devs[i], &pa, 0, 0, &size, name)))
  211332. {
  211333. const String nameString (String::fromUTF8 ((const uint8*) name, (int) strlen (name)));
  211334. if (! alreadyLogged)
  211335. log (T("CoreAudio device: ") + nameString);
  211336. const int numIns = getNumChannels (devs[i], true);
  211337. const int numOuts = getNumChannels (devs[i], false);
  211338. if (numIns > 0)
  211339. {
  211340. inputDeviceNames.add (nameString);
  211341. inputIds.add (devs[i]);
  211342. }
  211343. if (numOuts > 0)
  211344. {
  211345. outputDeviceNames.add (nameString);
  211346. outputIds.add (devs[i]);
  211347. }
  211348. }
  211349. }
  211350. alreadyLogged = true;
  211351. }
  211352. }
  211353. inputDeviceNames.appendNumbersToDuplicates (false, true);
  211354. outputDeviceNames.appendNumbersToDuplicates (false, true);
  211355. }
  211356. const StringArray getDeviceNames (const bool wantInputNames) const
  211357. {
  211358. jassert (hasScanned); // need to call scanForDevices() before doing this
  211359. if (wantInputNames)
  211360. return inputDeviceNames;
  211361. else
  211362. return outputDeviceNames;
  211363. }
  211364. int getDefaultDeviceIndex (const bool forInput) const
  211365. {
  211366. jassert (hasScanned); // need to call scanForDevices() before doing this
  211367. AudioDeviceID deviceID;
  211368. UInt32 size = sizeof (deviceID);
  211369. // if they're asking for any input channels at all, use the default input, so we
  211370. // get the built-in mic rather than the built-in output with no inputs..
  211371. AudioObjectPropertyAddress pa;
  211372. pa.mSelector = forInput ? kAudioHardwarePropertyDefaultInputDevice : kAudioHardwarePropertyDefaultOutputDevice;
  211373. pa.mScope = kAudioObjectPropertyScopeWildcard;
  211374. pa.mElement = kAudioObjectPropertyElementMaster;
  211375. if (AudioObjectGetPropertyData (kAudioObjectSystemObject, &pa, 0, 0, &size, &deviceID) == noErr)
  211376. {
  211377. if (forInput)
  211378. {
  211379. for (int i = inputIds.size(); --i >= 0;)
  211380. if (inputIds[i] == deviceID)
  211381. return i;
  211382. }
  211383. else
  211384. {
  211385. for (int i = outputIds.size(); --i >= 0;)
  211386. if (outputIds[i] == deviceID)
  211387. return i;
  211388. }
  211389. }
  211390. return 0;
  211391. }
  211392. int getIndexOfDevice (AudioIODevice* device, const bool asInput) const
  211393. {
  211394. jassert (hasScanned); // need to call scanForDevices() before doing this
  211395. CoreAudioIODevice* const d = dynamic_cast <CoreAudioIODevice*> (device);
  211396. if (d == 0)
  211397. return -1;
  211398. return asInput ? d->inputIndex
  211399. : d->outputIndex;
  211400. }
  211401. bool hasSeparateInputsAndOutputs() const { return true; }
  211402. AudioIODevice* createDevice (const String& outputDeviceName,
  211403. const String& inputDeviceName)
  211404. {
  211405. jassert (hasScanned); // need to call scanForDevices() before doing this
  211406. const int inputIndex = inputDeviceNames.indexOf (inputDeviceName);
  211407. const int outputIndex = outputDeviceNames.indexOf (outputDeviceName);
  211408. String deviceName (outputDeviceName);
  211409. if (deviceName.isEmpty())
  211410. deviceName = inputDeviceName;
  211411. if (index >= 0)
  211412. return new CoreAudioIODevice (deviceName,
  211413. inputIds [inputIndex],
  211414. inputIndex,
  211415. outputIds [outputIndex],
  211416. outputIndex);
  211417. return 0;
  211418. }
  211419. juce_UseDebuggingNewOperator
  211420. private:
  211421. StringArray inputDeviceNames, outputDeviceNames;
  211422. Array <AudioDeviceID> inputIds, outputIds;
  211423. bool hasScanned;
  211424. static int getNumChannels (AudioDeviceID deviceID, bool input)
  211425. {
  211426. int total = 0;
  211427. UInt32 size;
  211428. AudioObjectPropertyAddress pa;
  211429. pa.mSelector = kAudioDevicePropertyStreamConfiguration;
  211430. pa.mScope = input ? kAudioDevicePropertyScopeInput : kAudioDevicePropertyScopeOutput;
  211431. pa.mElement = kAudioObjectPropertyElementMaster;
  211432. if (OK (AudioObjectGetPropertyDataSize (deviceID, &pa, 0, 0, &size)))
  211433. {
  211434. HeapBlock <AudioBufferList> bufList;
  211435. bufList.calloc (size, 1);
  211436. if (OK (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &size, bufList)))
  211437. {
  211438. const int numStreams = bufList->mNumberBuffers;
  211439. for (int i = 0; i < numStreams; ++i)
  211440. {
  211441. const AudioBuffer& b = bufList->mBuffers[i];
  211442. total += b.mNumberChannels;
  211443. }
  211444. }
  211445. }
  211446. return total;
  211447. }
  211448. CoreAudioIODeviceType (const CoreAudioIODeviceType&);
  211449. const CoreAudioIODeviceType& operator= (const CoreAudioIODeviceType&);
  211450. };
  211451. AudioIODeviceType* juce_createAudioIODeviceType_CoreAudio()
  211452. {
  211453. return new CoreAudioIODeviceType();
  211454. }
  211455. #undef log
  211456. #endif
  211457. /********* End of inlined file: juce_mac_CoreAudio.cpp *********/
  211458. /********* Start of inlined file: juce_mac_CoreMidi.cpp *********/
  211459. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  211460. // compiled on its own).
  211461. #if JUCE_INCLUDED_FILE
  211462. #if JUCE_MAC
  211463. #undef log
  211464. #define log(a) Logger::writeToLog(a)
  211465. static bool logAnyErrorsMidi (const OSStatus err, const int lineNum)
  211466. {
  211467. if (err == noErr)
  211468. return true;
  211469. log (T("CoreMidi error: ") + String (lineNum) + T(" - ") + String::toHexString ((int)err));
  211470. jassertfalse
  211471. return false;
  211472. }
  211473. #undef OK
  211474. #define OK(a) logAnyErrorsMidi(a, __LINE__)
  211475. static const String getEndpointName (MIDIEndpointRef endpoint, bool isExternal)
  211476. {
  211477. String result;
  211478. CFStringRef str = 0;
  211479. MIDIObjectGetStringProperty (endpoint, kMIDIPropertyName, &str);
  211480. if (str != 0)
  211481. {
  211482. result = PlatformUtilities::cfStringToJuceString (str);
  211483. CFRelease (str);
  211484. str = 0;
  211485. }
  211486. MIDIEntityRef entity = 0;
  211487. MIDIEndpointGetEntity (endpoint, &entity);
  211488. if (entity == 0)
  211489. return result; // probably virtual
  211490. if (result.isEmpty())
  211491. {
  211492. // endpoint name has zero length - try the entity
  211493. MIDIObjectGetStringProperty (entity, kMIDIPropertyName, &str);
  211494. if (str != 0)
  211495. {
  211496. result += PlatformUtilities::cfStringToJuceString (str);
  211497. CFRelease (str);
  211498. str = 0;
  211499. }
  211500. }
  211501. // now consider the device's name
  211502. MIDIDeviceRef device = 0;
  211503. MIDIEntityGetDevice (entity, &device);
  211504. if (device == 0)
  211505. return result;
  211506. MIDIObjectGetStringProperty (device, kMIDIPropertyName, &str);
  211507. if (str != 0)
  211508. {
  211509. const String s (PlatformUtilities::cfStringToJuceString (str));
  211510. CFRelease (str);
  211511. // if an external device has only one entity, throw away
  211512. // the endpoint name and just use the device name
  211513. if (isExternal && MIDIDeviceGetNumberOfEntities (device) < 2)
  211514. {
  211515. result = s;
  211516. }
  211517. else if (! result.startsWithIgnoreCase (s))
  211518. {
  211519. // prepend the device name to the entity name
  211520. result = (s + T(" ") + result).trimEnd();
  211521. }
  211522. }
  211523. return result;
  211524. }
  211525. static const String getConnectedEndpointName (MIDIEndpointRef endpoint)
  211526. {
  211527. String result;
  211528. // Does the endpoint have connections?
  211529. CFDataRef connections = 0;
  211530. int numConnections = 0;
  211531. MIDIObjectGetDataProperty (endpoint, kMIDIPropertyConnectionUniqueID, &connections);
  211532. if (connections != 0)
  211533. {
  211534. numConnections = (int) (CFDataGetLength (connections) / sizeof (MIDIUniqueID));
  211535. if (numConnections > 0)
  211536. {
  211537. const SInt32* pid = reinterpret_cast <const SInt32*> (CFDataGetBytePtr (connections));
  211538. for (int i = 0; i < numConnections; ++i, ++pid)
  211539. {
  211540. MIDIUniqueID uid = EndianS32_BtoN (*pid);
  211541. MIDIObjectRef connObject;
  211542. MIDIObjectType connObjectType;
  211543. OSStatus err = MIDIObjectFindByUniqueID (uid, &connObject, &connObjectType);
  211544. if (err == noErr)
  211545. {
  211546. String s;
  211547. if (connObjectType == kMIDIObjectType_ExternalSource
  211548. || connObjectType == kMIDIObjectType_ExternalDestination)
  211549. {
  211550. // Connected to an external device's endpoint (10.3 and later).
  211551. s = getEndpointName (static_cast <MIDIEndpointRef> (connObject), true);
  211552. }
  211553. else
  211554. {
  211555. // Connected to an external device (10.2) (or something else, catch-all)
  211556. CFStringRef str = 0;
  211557. MIDIObjectGetStringProperty (connObject, kMIDIPropertyName, &str);
  211558. if (str != 0)
  211559. {
  211560. s = PlatformUtilities::cfStringToJuceString (str);
  211561. CFRelease (str);
  211562. }
  211563. }
  211564. if (s.isNotEmpty())
  211565. {
  211566. if (result.isNotEmpty())
  211567. result += (", ");
  211568. result += s;
  211569. }
  211570. }
  211571. }
  211572. }
  211573. CFRelease (connections);
  211574. }
  211575. if (result.isNotEmpty())
  211576. return result;
  211577. // Here, either the endpoint had no connections, or we failed to obtain names for any of them.
  211578. return getEndpointName (endpoint, false);
  211579. }
  211580. const StringArray MidiOutput::getDevices()
  211581. {
  211582. StringArray s;
  211583. const ItemCount num = MIDIGetNumberOfDestinations();
  211584. for (ItemCount i = 0; i < num; ++i)
  211585. {
  211586. MIDIEndpointRef dest = MIDIGetDestination (i);
  211587. if (dest != 0)
  211588. {
  211589. String name (getConnectedEndpointName (dest));
  211590. if (name.isEmpty())
  211591. name = "<error>";
  211592. s.add (name);
  211593. }
  211594. else
  211595. {
  211596. s.add ("<error>");
  211597. }
  211598. }
  211599. return s;
  211600. }
  211601. int MidiOutput::getDefaultDeviceIndex()
  211602. {
  211603. return 0;
  211604. }
  211605. static MIDIClientRef globalMidiClient;
  211606. static bool hasGlobalClientBeenCreated = false;
  211607. static bool makeSureClientExists()
  211608. {
  211609. if (! hasGlobalClientBeenCreated)
  211610. {
  211611. String name (T("JUCE"));
  211612. if (JUCEApplication::getInstance() != 0)
  211613. name = JUCEApplication::getInstance()->getApplicationName();
  211614. CFStringRef appName = PlatformUtilities::juceStringToCFString (name);
  211615. hasGlobalClientBeenCreated = OK (MIDIClientCreate (appName, 0, 0, &globalMidiClient));
  211616. CFRelease (appName);
  211617. }
  211618. return hasGlobalClientBeenCreated;
  211619. }
  211620. class MidiPortAndEndpoint
  211621. {
  211622. public:
  211623. MidiPortAndEndpoint (MIDIPortRef port_, MIDIEndpointRef endPoint_)
  211624. : port (port_), endPoint (endPoint_)
  211625. {
  211626. }
  211627. ~MidiPortAndEndpoint()
  211628. {
  211629. if (port != 0)
  211630. MIDIPortDispose (port);
  211631. if (port == 0 && endPoint != 0) // if port == 0, it means we created the endpoint, so it's safe to delete it
  211632. MIDIEndpointDispose (endPoint);
  211633. }
  211634. MIDIPortRef port;
  211635. MIDIEndpointRef endPoint;
  211636. };
  211637. MidiOutput* MidiOutput::openDevice (int index)
  211638. {
  211639. MidiOutput* mo = 0;
  211640. if (((unsigned int) index) < (unsigned int) MIDIGetNumberOfDestinations())
  211641. {
  211642. MIDIEndpointRef endPoint = MIDIGetDestination (index);
  211643. CFStringRef pname;
  211644. if (OK (MIDIObjectGetStringProperty (endPoint, kMIDIPropertyName, &pname)))
  211645. {
  211646. log (T("CoreMidi - opening out: ") + PlatformUtilities::cfStringToJuceString (pname));
  211647. if (makeSureClientExists())
  211648. {
  211649. MIDIPortRef port;
  211650. if (OK (MIDIOutputPortCreate (globalMidiClient, pname, &port)))
  211651. {
  211652. mo = new MidiOutput();
  211653. mo->internal = (void*) new MidiPortAndEndpoint (port, endPoint);
  211654. }
  211655. }
  211656. CFRelease (pname);
  211657. }
  211658. }
  211659. return mo;
  211660. }
  211661. MidiOutput* MidiOutput::createNewDevice (const String& deviceName)
  211662. {
  211663. MidiOutput* mo = 0;
  211664. if (makeSureClientExists())
  211665. {
  211666. MIDIEndpointRef endPoint;
  211667. CFStringRef name = PlatformUtilities::juceStringToCFString (deviceName);
  211668. if (OK (MIDISourceCreate (globalMidiClient, name, &endPoint)))
  211669. {
  211670. mo = new MidiOutput();
  211671. mo->internal = (void*) new MidiPortAndEndpoint (0, endPoint);
  211672. }
  211673. CFRelease (name);
  211674. }
  211675. return mo;
  211676. }
  211677. MidiOutput::~MidiOutput()
  211678. {
  211679. delete (MidiPortAndEndpoint*) internal;
  211680. }
  211681. void MidiOutput::reset()
  211682. {
  211683. }
  211684. bool MidiOutput::getVolume (float& leftVol, float& rightVol)
  211685. {
  211686. return false;
  211687. }
  211688. void MidiOutput::setVolume (float leftVol, float rightVol)
  211689. {
  211690. }
  211691. void MidiOutput::sendMessageNow (const MidiMessage& message)
  211692. {
  211693. MidiPortAndEndpoint* const mpe = (MidiPortAndEndpoint*) internal;
  211694. if (message.isSysEx())
  211695. {
  211696. const int maxPacketSize = 256;
  211697. int pos = 0, bytesLeft = message.getRawDataSize();
  211698. const int numPackets = (bytesLeft + maxPacketSize - 1) / maxPacketSize;
  211699. HeapBlock <MIDIPacketList> packets;
  211700. packets.malloc (32 * numPackets + message.getRawDataSize(), 1);
  211701. packets->numPackets = numPackets;
  211702. MIDIPacket* p = packets->packet;
  211703. for (int i = 0; i < numPackets; ++i)
  211704. {
  211705. p->timeStamp = 0;
  211706. p->length = jmin (maxPacketSize, bytesLeft);
  211707. memcpy (p->data, message.getRawData() + pos, p->length);
  211708. pos += p->length;
  211709. bytesLeft -= p->length;
  211710. p = MIDIPacketNext (p);
  211711. }
  211712. if (mpe->port != 0)
  211713. MIDISend (mpe->port, mpe->endPoint, packets);
  211714. else
  211715. MIDIReceived (mpe->endPoint, packets);
  211716. }
  211717. else
  211718. {
  211719. MIDIPacketList packets;
  211720. packets.numPackets = 1;
  211721. packets.packet[0].timeStamp = 0;
  211722. packets.packet[0].length = message.getRawDataSize();
  211723. *(int*) (packets.packet[0].data) = *(const int*) message.getRawData();
  211724. if (mpe->port != 0)
  211725. MIDISend (mpe->port, mpe->endPoint, &packets);
  211726. else
  211727. MIDIReceived (mpe->endPoint, &packets);
  211728. }
  211729. }
  211730. const StringArray MidiInput::getDevices()
  211731. {
  211732. StringArray s;
  211733. const ItemCount num = MIDIGetNumberOfSources();
  211734. for (ItemCount i = 0; i < num; ++i)
  211735. {
  211736. MIDIEndpointRef source = MIDIGetSource (i);
  211737. if (source != 0)
  211738. {
  211739. String name (getConnectedEndpointName (source));
  211740. if (name.isEmpty())
  211741. name = "<error>";
  211742. s.add (name);
  211743. }
  211744. else
  211745. {
  211746. s.add ("<error>");
  211747. }
  211748. }
  211749. return s;
  211750. }
  211751. int MidiInput::getDefaultDeviceIndex()
  211752. {
  211753. return 0;
  211754. }
  211755. struct MidiPortAndCallback
  211756. {
  211757. MidiInput* input;
  211758. MidiPortAndEndpoint* portAndEndpoint;
  211759. MidiInputCallback* callback;
  211760. MemoryBlock pendingData;
  211761. int pendingBytes;
  211762. double pendingDataTime;
  211763. bool active;
  211764. };
  211765. static CriticalSection callbackLock;
  211766. static VoidArray activeCallbacks;
  211767. static void processSysex (MidiPortAndCallback* const mpc, const uint8*& d, int& size, const double time)
  211768. {
  211769. if (*d == 0xf0)
  211770. {
  211771. mpc->pendingBytes = 0;
  211772. mpc->pendingDataTime = time;
  211773. }
  211774. mpc->pendingData.ensureSize (mpc->pendingBytes + size, false);
  211775. uint8* totalMessage = (uint8*) mpc->pendingData.getData();
  211776. uint8* dest = totalMessage + mpc->pendingBytes;
  211777. while (size > 0)
  211778. {
  211779. if (mpc->pendingBytes > 0 && *d >= 0x80)
  211780. {
  211781. if (*d >= 0xfa || *d == 0xf8)
  211782. {
  211783. mpc->callback->handleIncomingMidiMessage (mpc->input, MidiMessage (*d, time));
  211784. ++d;
  211785. --size;
  211786. }
  211787. else
  211788. {
  211789. if (*d == 0xf7)
  211790. {
  211791. *dest++ = *d++;
  211792. mpc->pendingBytes++;
  211793. --size;
  211794. }
  211795. break;
  211796. }
  211797. }
  211798. else
  211799. {
  211800. *dest++ = *d++;
  211801. mpc->pendingBytes++;
  211802. --size;
  211803. }
  211804. }
  211805. if (totalMessage [mpc->pendingBytes - 1] == 0xf7)
  211806. {
  211807. mpc->callback->handleIncomingMidiMessage (mpc->input, MidiMessage (totalMessage,
  211808. mpc->pendingBytes,
  211809. mpc->pendingDataTime));
  211810. mpc->pendingBytes = 0;
  211811. }
  211812. else
  211813. {
  211814. mpc->callback->handlePartialSysexMessage (mpc->input,
  211815. totalMessage,
  211816. mpc->pendingBytes,
  211817. mpc->pendingDataTime);
  211818. }
  211819. }
  211820. static void midiInputProc (const MIDIPacketList* pktlist,
  211821. void* readProcRefCon,
  211822. void* srcConnRefCon)
  211823. {
  211824. double time = Time::getMillisecondCounterHiRes() * 0.001;
  211825. const double originalTime = time;
  211826. MidiPortAndCallback* const mpc = (MidiPortAndCallback*) readProcRefCon;
  211827. const ScopedLock sl (callbackLock);
  211828. if (activeCallbacks.contains (mpc) && mpc->active)
  211829. {
  211830. const MIDIPacket* packet = &pktlist->packet[0];
  211831. for (unsigned int i = 0; i < pktlist->numPackets; ++i)
  211832. {
  211833. const uint8* d = (const uint8*) (packet->data);
  211834. int size = packet->length;
  211835. while (size > 0)
  211836. {
  211837. time = originalTime;
  211838. if (mpc->pendingBytes > 0 || d[0] == 0xf0)
  211839. {
  211840. processSysex (mpc, d, size, time);
  211841. }
  211842. else
  211843. {
  211844. int used = 0;
  211845. const MidiMessage m (d, size, used, 0, time);
  211846. if (used <= 0)
  211847. {
  211848. jassertfalse // malformed midi message
  211849. break;
  211850. }
  211851. else
  211852. {
  211853. mpc->callback->handleIncomingMidiMessage (mpc->input, m);
  211854. }
  211855. size -= used;
  211856. d += used;
  211857. }
  211858. }
  211859. packet = MIDIPacketNext (packet);
  211860. }
  211861. }
  211862. }
  211863. MidiInput* MidiInput::openDevice (int index, MidiInputCallback* callback)
  211864. {
  211865. MidiInput* mi = 0;
  211866. if (((unsigned int) index) < (unsigned int) MIDIGetNumberOfSources())
  211867. {
  211868. MIDIEndpointRef endPoint = MIDIGetSource (index);
  211869. if (endPoint != 0)
  211870. {
  211871. CFStringRef pname;
  211872. if (OK (MIDIObjectGetStringProperty (endPoint, kMIDIPropertyName, &pname)))
  211873. {
  211874. log (T("CoreMidi - opening inp: ") + PlatformUtilities::cfStringToJuceString (pname));
  211875. if (makeSureClientExists())
  211876. {
  211877. MIDIPortRef port;
  211878. ScopedPointer <MidiPortAndCallback> mpc (new MidiPortAndCallback());
  211879. mpc->active = false;
  211880. if (OK (MIDIInputPortCreate (globalMidiClient, pname, midiInputProc, mpc, &port)))
  211881. {
  211882. if (OK (MIDIPortConnectSource (port, endPoint, 0)))
  211883. {
  211884. mpc->portAndEndpoint = new MidiPortAndEndpoint (port, endPoint);
  211885. mpc->callback = callback;
  211886. mpc->pendingBytes = 0;
  211887. mpc->pendingData.ensureSize (128);
  211888. mi = new MidiInput (getDevices() [index]);
  211889. mpc->input = mi;
  211890. mi->internal = (void*) mpc;
  211891. const ScopedLock sl (callbackLock);
  211892. activeCallbacks.add (mpc.release());
  211893. }
  211894. else
  211895. {
  211896. OK (MIDIPortDispose (port));
  211897. }
  211898. }
  211899. }
  211900. }
  211901. CFRelease (pname);
  211902. }
  211903. }
  211904. return mi;
  211905. }
  211906. MidiInput* MidiInput::createNewDevice (const String& deviceName, MidiInputCallback* callback)
  211907. {
  211908. MidiInput* mi = 0;
  211909. if (makeSureClientExists())
  211910. {
  211911. ScopedPointer <MidiPortAndCallback> mpc (new MidiPortAndCallback());
  211912. mpc->active = false;
  211913. MIDIEndpointRef endPoint;
  211914. CFStringRef name = PlatformUtilities::juceStringToCFString(deviceName);
  211915. if (OK (MIDIDestinationCreate (globalMidiClient, name, midiInputProc, mpc, &endPoint)))
  211916. {
  211917. mpc->portAndEndpoint = new MidiPortAndEndpoint (0, endPoint);
  211918. mpc->callback = callback;
  211919. mpc->pendingBytes = 0;
  211920. mpc->pendingData.ensureSize (128);
  211921. mi = new MidiInput (deviceName);
  211922. mpc->input = mi;
  211923. mi->internal = (void*) mpc;
  211924. const ScopedLock sl (callbackLock);
  211925. activeCallbacks.add (mpc.release());
  211926. }
  211927. CFRelease (name);
  211928. }
  211929. return mi;
  211930. }
  211931. MidiInput::MidiInput (const String& name_)
  211932. : name (name_)
  211933. {
  211934. }
  211935. MidiInput::~MidiInput()
  211936. {
  211937. MidiPortAndCallback* const mpc = (MidiPortAndCallback*) internal;
  211938. mpc->active = false;
  211939. callbackLock.enter();
  211940. activeCallbacks.removeValue (mpc);
  211941. callbackLock.exit();
  211942. if (mpc->portAndEndpoint->port != 0)
  211943. OK (MIDIPortDisconnectSource (mpc->portAndEndpoint->port, mpc->portAndEndpoint->endPoint));
  211944. delete mpc->portAndEndpoint;
  211945. delete mpc;
  211946. }
  211947. void MidiInput::start()
  211948. {
  211949. MidiPortAndCallback* const mpc = (MidiPortAndCallback*) internal;
  211950. const ScopedLock sl (callbackLock);
  211951. mpc->active = true;
  211952. }
  211953. void MidiInput::stop()
  211954. {
  211955. MidiPortAndCallback* const mpc = (MidiPortAndCallback*) internal;
  211956. const ScopedLock sl (callbackLock);
  211957. mpc->active = false;
  211958. }
  211959. #undef log
  211960. #else
  211961. MidiOutput::~MidiOutput()
  211962. {
  211963. }
  211964. void MidiOutput::reset()
  211965. {
  211966. }
  211967. bool MidiOutput::getVolume (float& leftVol, float& rightVol)
  211968. {
  211969. return false;
  211970. }
  211971. void MidiOutput::setVolume (float leftVol, float rightVol)
  211972. {
  211973. }
  211974. void MidiOutput::sendMessageNow (const MidiMessage& message)
  211975. {
  211976. }
  211977. const StringArray MidiOutput::getDevices()
  211978. {
  211979. return StringArray();
  211980. }
  211981. MidiOutput* MidiOutput::openDevice (int index)
  211982. {
  211983. return 0;
  211984. }
  211985. const StringArray MidiInput::getDevices()
  211986. {
  211987. return StringArray();
  211988. }
  211989. MidiInput* MidiInput::openDevice (int index, MidiInputCallback* callback)
  211990. {
  211991. return 0;
  211992. }
  211993. #endif
  211994. #endif
  211995. /********* End of inlined file: juce_mac_CoreMidi.cpp *********/
  211996. /********* Start of inlined file: juce_mac_CameraDevice.mm *********/
  211997. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  211998. // compiled on its own).
  211999. #if JUCE_INCLUDED_FILE && JUCE_QUICKTIME && JUCE_USE_CAMERA
  212000. #define QTCaptureCallbackDelegate MakeObjCClassName(QTCaptureCallbackDelegate)
  212001. class QTCameraDeviceInteral;
  212002. END_JUCE_NAMESPACE
  212003. @interface QTCaptureCallbackDelegate : NSObject
  212004. {
  212005. @public
  212006. CameraDevice* owner;
  212007. QTCameraDeviceInteral* internal;
  212008. Time* firstRecordedTime;
  212009. }
  212010. - (QTCaptureCallbackDelegate*) initWithOwner: (CameraDevice*) owner internalDev: (QTCameraDeviceInteral*) d;
  212011. - (void) dealloc;
  212012. - (void) captureOutput: (QTCaptureOutput*) captureOutput
  212013. didOutputVideoFrame: (CVImageBufferRef) videoFrame
  212014. withSampleBuffer: (QTSampleBuffer*) sampleBuffer
  212015. fromConnection: (QTCaptureConnection*) connection;
  212016. - (void) captureOutput: (QTCaptureFileOutput*) captureOutput
  212017. didOutputSampleBuffer: (QTSampleBuffer*) sampleBuffer
  212018. fromConnection: (QTCaptureConnection*) connection;
  212019. @end
  212020. BEGIN_JUCE_NAMESPACE
  212021. class QTCameraDeviceInteral
  212022. {
  212023. public:
  212024. QTCameraDeviceInteral (CameraDevice* owner, int index)
  212025. {
  212026. const ScopedAutoReleasePool pool;
  212027. session = [[QTCaptureSession alloc] init];
  212028. NSArray* devs = [QTCaptureDevice inputDevicesWithMediaType: QTMediaTypeVideo];
  212029. device = (QTCaptureDevice*) [devs objectAtIndex: index];
  212030. input = 0;
  212031. audioInput = 0;
  212032. audioDevice = 0;
  212033. fileOutput = 0;
  212034. imageOutput = 0;
  212035. callbackDelegate = [[QTCaptureCallbackDelegate alloc] initWithOwner: owner
  212036. internalDev: this];
  212037. NSError* err = 0;
  212038. [device retain];
  212039. [device open: &err];
  212040. if (err == 0)
  212041. {
  212042. input = [[QTCaptureDeviceInput alloc] initWithDevice: device];
  212043. audioInput = [[QTCaptureDeviceInput alloc] initWithDevice: device];
  212044. [session addInput: input error: &err];
  212045. if (err == 0)
  212046. {
  212047. resetFile();
  212048. imageOutput = [[QTCaptureDecompressedVideoOutput alloc] init];
  212049. [imageOutput setDelegate: callbackDelegate];
  212050. if (err == 0)
  212051. {
  212052. [session startRunning];
  212053. return;
  212054. }
  212055. }
  212056. }
  212057. openingError = nsStringToJuce ([err description]);
  212058. DBG (openingError);
  212059. }
  212060. ~QTCameraDeviceInteral()
  212061. {
  212062. [session stopRunning];
  212063. [session removeOutput: imageOutput];
  212064. [session release];
  212065. [input release];
  212066. [device release];
  212067. [audioDevice release];
  212068. [audioInput release];
  212069. [fileOutput release];
  212070. [imageOutput release];
  212071. [callbackDelegate release];
  212072. }
  212073. void resetFile()
  212074. {
  212075. [fileOutput recordToOutputFileURL: nil];
  212076. [session removeOutput: fileOutput];
  212077. [fileOutput release];
  212078. fileOutput = [[QTCaptureMovieFileOutput alloc] init];
  212079. [session removeInput: audioInput];
  212080. [audioInput release];
  212081. audioInput = 0;
  212082. [audioDevice release];
  212083. audioDevice = 0;
  212084. [fileOutput setDelegate: callbackDelegate];
  212085. }
  212086. void addDefaultAudioInput()
  212087. {
  212088. NSError* err = nil;
  212089. audioDevice = [QTCaptureDevice defaultInputDeviceWithMediaType: QTMediaTypeSound];
  212090. if ([audioDevice open: &err])
  212091. [audioDevice retain];
  212092. else
  212093. audioDevice = nil;
  212094. if (audioDevice != 0)
  212095. {
  212096. audioInput = [[QTCaptureDeviceInput alloc] initWithDevice: audioDevice];
  212097. [session addInput: audioInput error: &err];
  212098. }
  212099. }
  212100. void addListener (CameraImageListener* listenerToAdd)
  212101. {
  212102. const ScopedLock sl (listenerLock);
  212103. if (listeners.size() == 0)
  212104. [session addOutput: imageOutput error: nil];
  212105. listeners.addIfNotAlreadyThere (listenerToAdd);
  212106. }
  212107. void removeListener (CameraImageListener* listenerToRemove)
  212108. {
  212109. const ScopedLock sl (listenerLock);
  212110. listeners.removeValue (listenerToRemove);
  212111. if (listeners.size() == 0)
  212112. [session removeOutput: imageOutput];
  212113. }
  212114. void callListeners (CIImage* frame, int w, int h)
  212115. {
  212116. CoreGraphicsImage image (Image::ARGB, w, h, false);
  212117. CIContext* cic = [CIContext contextWithCGContext: image.context options: nil];
  212118. [cic drawImage: frame inRect: CGRectMake (0, 0, w, h) fromRect: CGRectMake (0, 0, w, h)];
  212119. CGContextFlush (image.context);
  212120. const ScopedLock sl (listenerLock);
  212121. for (int i = listeners.size(); --i >= 0;)
  212122. {
  212123. CameraImageListener* l = (CameraImageListener*) listeners[i];
  212124. if (l != 0)
  212125. l->imageReceived (image);
  212126. }
  212127. }
  212128. QTCaptureDevice* device;
  212129. QTCaptureDeviceInput* input;
  212130. QTCaptureDevice* audioDevice;
  212131. QTCaptureDeviceInput* audioInput;
  212132. QTCaptureSession* session;
  212133. QTCaptureMovieFileOutput* fileOutput;
  212134. QTCaptureDecompressedVideoOutput* imageOutput;
  212135. QTCaptureCallbackDelegate* callbackDelegate;
  212136. String openingError;
  212137. VoidArray listeners;
  212138. CriticalSection listenerLock;
  212139. };
  212140. END_JUCE_NAMESPACE
  212141. @implementation QTCaptureCallbackDelegate
  212142. - (QTCaptureCallbackDelegate*) initWithOwner: (CameraDevice*) owner_
  212143. internalDev: (QTCameraDeviceInteral*) d
  212144. {
  212145. [super init];
  212146. owner = owner_;
  212147. internal = d;
  212148. firstRecordedTime = 0;
  212149. return self;
  212150. }
  212151. - (void) dealloc
  212152. {
  212153. delete firstRecordedTime;
  212154. [super dealloc];
  212155. }
  212156. - (void) captureOutput: (QTCaptureOutput*) captureOutput
  212157. didOutputVideoFrame: (CVImageBufferRef) videoFrame
  212158. withSampleBuffer: (QTSampleBuffer*) sampleBuffer
  212159. fromConnection: (QTCaptureConnection*) connection
  212160. {
  212161. if (internal->listeners.size() > 0)
  212162. {
  212163. const ScopedAutoReleasePool pool;
  212164. internal->callListeners ([CIImage imageWithCVImageBuffer: videoFrame],
  212165. CVPixelBufferGetWidth (videoFrame),
  212166. CVPixelBufferGetHeight (videoFrame));
  212167. }
  212168. }
  212169. - (void) captureOutput: (QTCaptureFileOutput*) captureOutput
  212170. didOutputSampleBuffer: (QTSampleBuffer*) sampleBuffer
  212171. fromConnection: (QTCaptureConnection*) connection
  212172. {
  212173. if (firstRecordedTime == 0)
  212174. {
  212175. const Time now (Time::getCurrentTime());
  212176. firstRecordedTime = new Time (now - RelativeTime (0.1));
  212177. }
  212178. }
  212179. @end
  212180. BEGIN_JUCE_NAMESPACE
  212181. class QTCaptureViewerComp : public NSViewComponent
  212182. {
  212183. public:
  212184. QTCaptureViewerComp (CameraDevice* const cameraDevice, QTCameraDeviceInteral* const internal)
  212185. {
  212186. const ScopedAutoReleasePool pool;
  212187. captureView = [[QTCaptureView alloc] init];
  212188. [captureView setCaptureSession: internal->session];
  212189. setSize (640, 480); // xxx need to somehow get the movie size - how?
  212190. setView (captureView);
  212191. }
  212192. ~QTCaptureViewerComp()
  212193. {
  212194. setView (0);
  212195. [captureView setCaptureSession: nil];
  212196. [captureView release];
  212197. }
  212198. QTCaptureView* captureView;
  212199. };
  212200. CameraDevice::CameraDevice (const String& name_, int index)
  212201. : name (name_)
  212202. {
  212203. isRecording = false;
  212204. QTCameraDeviceInteral* d = new QTCameraDeviceInteral (this, index);
  212205. internal = d;
  212206. }
  212207. CameraDevice::~CameraDevice()
  212208. {
  212209. stopRecording();
  212210. delete (QTCameraDeviceInteral*) internal;
  212211. internal = 0;
  212212. }
  212213. Component* CameraDevice::createViewerComponent()
  212214. {
  212215. return new QTCaptureViewerComp (this, (QTCameraDeviceInteral*) internal);
  212216. }
  212217. const String CameraDevice::getFileExtension()
  212218. {
  212219. return ".mov";
  212220. }
  212221. void CameraDevice::startRecordingToFile (const File& file)
  212222. {
  212223. stopRecording();
  212224. QTCameraDeviceInteral* const d = (QTCameraDeviceInteral*) internal;
  212225. deleteAndZero (d->callbackDelegate->firstRecordedTime);
  212226. file.deleteFile();
  212227. // In some versions of QT (e.g. on 10.5), if you record video without audio, the speed comes
  212228. // out wrong, so we'll put some audio in there too..,
  212229. d->addDefaultAudioInput();
  212230. [d->session addOutput: d->fileOutput error: nil];
  212231. NSEnumerator* connectionEnumerator = [[d->fileOutput connections] objectEnumerator];
  212232. for (;;)
  212233. {
  212234. QTCaptureConnection* connection = [connectionEnumerator nextObject];
  212235. if (connection == 0)
  212236. break;
  212237. QTCompressionOptions* options = 0;
  212238. NSString* mediaType = [connection mediaType];
  212239. if ([mediaType isEqualToString: QTMediaTypeVideo])
  212240. options = [QTCompressionOptions compressionOptionsWithIdentifier: @"QTCompressionOptionsSD480SizeH264Video"];
  212241. else if ([mediaType isEqualToString: QTMediaTypeSound])
  212242. options = [QTCompressionOptions compressionOptionsWithIdentifier: @"QTCompressionOptionsHighQualityAACAudio"];
  212243. [d->fileOutput setCompressionOptions: options forConnection: connection];
  212244. }
  212245. [d->fileOutput recordToOutputFileURL: [NSURL fileURLWithPath: juceStringToNS (file.getFullPathName())]];
  212246. isRecording = true;
  212247. }
  212248. const Time CameraDevice::getTimeOfFirstRecordedFrame() const
  212249. {
  212250. QTCameraDeviceInteral* const d = (QTCameraDeviceInteral*) internal;
  212251. if (d->callbackDelegate->firstRecordedTime != 0)
  212252. return *d->callbackDelegate->firstRecordedTime;
  212253. return Time();
  212254. }
  212255. void CameraDevice::stopRecording()
  212256. {
  212257. if (isRecording)
  212258. {
  212259. QTCameraDeviceInteral* const d = (QTCameraDeviceInteral*) internal;
  212260. d->resetFile();
  212261. isRecording = false;
  212262. }
  212263. }
  212264. void CameraDevice::addListener (CameraImageListener* listenerToAdd)
  212265. {
  212266. QTCameraDeviceInteral* const d = (QTCameraDeviceInteral*) internal;
  212267. if (listenerToAdd != 0)
  212268. d->addListener (listenerToAdd);
  212269. }
  212270. void CameraDevice::removeListener (CameraImageListener* listenerToRemove)
  212271. {
  212272. QTCameraDeviceInteral* const d = (QTCameraDeviceInteral*) internal;
  212273. if (listenerToRemove != 0)
  212274. d->removeListener (listenerToRemove);
  212275. }
  212276. const StringArray CameraDevice::getAvailableDevices()
  212277. {
  212278. const ScopedAutoReleasePool pool;
  212279. StringArray results;
  212280. NSArray* devs = [QTCaptureDevice inputDevicesWithMediaType: QTMediaTypeVideo];
  212281. for (int i = 0; i < [devs count]; ++i)
  212282. {
  212283. QTCaptureDevice* dev = (QTCaptureDevice*) [devs objectAtIndex: i];
  212284. results.add (nsStringToJuce ([dev localizedDisplayName]));
  212285. }
  212286. return results;
  212287. }
  212288. CameraDevice* CameraDevice::openDevice (int index,
  212289. int minWidth, int minHeight,
  212290. int maxWidth, int maxHeight)
  212291. {
  212292. ScopedPointer <CameraDevice> d (new CameraDevice (getAvailableDevices() [index], index));
  212293. if (((QTCameraDeviceInteral*) (d->internal))->openingError.isEmpty())
  212294. return d.release();
  212295. return 0;
  212296. }
  212297. #endif
  212298. /********* End of inlined file: juce_mac_CameraDevice.mm *********/
  212299. #endif
  212300. #endif
  212301. END_JUCE_NAMESPACE
  212302. /********* End of inlined file: juce_mac_NativeCode.mm *********/
  212303. #endif